Implementation of the WifiPlusClick hardware module.

Dependents:   WifiPlusKlickExample

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Wifi.h Source File

Wifi.h

00001 /* Copyright (c) 2013 Henry Leinen (henry[dot]leinen [at] online [dot] de)
00002  *
00003  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
00004  * and associated documentation files (the "Software"), to deal in the Software without restriction,
00005  * including without limitation the rights to use, copy, modify, merge, publish, distribute,
00006  * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
00007  * furnished to do so, subject to the following conditions:
00008  *
00009  * The above copyright notice and this permission notice shall be included in all copies or
00010  * substantial portions of the Software.
00011  *
00012  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
00013  * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00014  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
00015  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00016  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00017  */
00018 #ifndef __WIFI_H__
00019 #define __WIFI_H__
00020 
00021 #include "mbed.h"
00022 
00023 typedef enum {
00024     //  Control Messages
00025     RESET_MSG   = 170,  /*!< RESET_MSG */
00026     GET_VERSION_MSG = 23, /*!< GET_VERSION_MSG */
00027     GPIO_MSG = 172,
00028     //  Network Configuration Messages
00029     SET_IP_ADDRESS_MSG = 41,
00030     SET_NETWORK_MASK_MSG = 42,
00031     SET_GATEWAY_IP_ADDRESS_MSG = 44,
00032     GET_NETWORK_STATUS_MSG = 48,
00033     SET_MACADDRESS_MSG = 49,
00034     SET_ARP_TIME_MSG = 173,
00035     //  Wi-Fi General Configuration Messages
00036     SET_CP_NETWORK_MODE_MSG = 55,
00037     SET_CP_SSID_MSG = 57,
00038     SET_REGIONAL_DOMAIN_MSG = 56,
00039     SET_CHANNEL_LIST_MSG = 58,
00040     SET_LIST_RETRY_COUNT_MSG = 59,
00041     //  Wi-Fi Power Management Messages
00042     SET_POWER_SAVE_MODE_MSG = 102,
00043     //  Wi-Fi Security Configuration Messages
00044     SET_CP_SECURITY_OPEN_MSG = 65,
00045     SET_CP_SECURITY_WEP40_MSG = 66,
00046     SET_CP_SECURITY_WEP104_MSG = 67,
00047     SET_CP_SECURITY_WPA_MSG = 68,
00048     GET_CP_WPAKEY_MSG = 71,
00049     //  Wi-Fi Scanning Messages
00050     SCAN_START_MSG = 80,
00051     SCAN_GET_RESULTS_MSG = 81,
00052     //  Wi-Fi Connection Messages
00053     WIFI_CONNECT_MSG = 90,
00054     WIFI_DISCONNECT_MSG = 91,
00055     //  ICMP (Ping) Messages
00056     PING_SEND_MSG = 121,
00057     //  Socket Messages
00058     SOCKET_CREATE_MSG = 110,
00059     SOCKET_CLOSE_MSG = 111,
00060     SOCKET_BIND_MSG = 112,
00061     SOCKET_CONNECT_MSG = 113,
00062     SOCKET_LISTEN_MSG = 114,
00063     SOCKET_ACCEPT_MSG = 115,
00064     SOCKET_SEND_MSG = 116,
00065     SOCKET_RECV_MSG = 117,
00066     SOCKET_SEND_TO_MSG = 118,
00067     SOCKET_RECV_FROM_MSG = 119,
00068     SOCKET_ALLOCATE_MSG = 122,
00069 
00070 } CMD_MSG_t;
00071 
00072 
00073 typedef enum {
00074     ACK_MSG = 0,
00075     EVENT_MSG = 1,
00076     
00077     //  Control Message Responses
00078     GPIO_RESPONSE_MSG = 50,
00079     //  Network Configuration Message Responses
00080     NETWORK_STATUS_RESPONSE_MSG = 48,
00081     //  Wi-Fi Security Configuration Message Responses
00082     WPAKEY_RESPONSE_MSG = 0x31,
00083     //  Wi-Fi Scanning Message Responses
00084     SCAN_RESULT_MSG = 22,
00085     //  Socket Message Responses
00086     SOCKET_CREATE_RESPONSE_MSG = 23,
00087     SOCKET_BIND_RESPONSE_MSG = 24,
00088     SOCKET_CONNECT_RESPONSE_MSG = 25,
00089     SOCKET_LISTEN_RESPONSE_MSG = 26,
00090     SOCKET_ACCEPT_RESPONSE_MSG = 27,
00091     SOCKET_SEND_RESPONSE_MSG = 28,
00092     SOCKET_RECV_RESPONSE_MSG = 29,
00093     SOCKET_SEND_TO_RESPONSE_MSG = 30,
00094     SOCKET_RECV_FROM_RESPONSE_MSG = 31,
00095     SOCKET_ALLOCATE_RESPONSE_MSG = 32,
00096         
00097 } RSP_MSG_t;
00098 
00099 typedef enum {
00100     Event_IP_Address_Assigned = 16,
00101     Event_WiFi_Connection_Status_Changed = 8,
00102     Event_WiFi_Scan_Results_Ready = 9,
00103     Event_Ping_Response = 26,
00104     Event_Error_Event = 255,
00105     Event_Startup_Event = 27,
00106     
00107 } EVT_MSG_t;
00108 
00109 
00110 typedef enum {
00111     GPIO0 = 0,
00112     GPIO1,
00113     GPIO2,
00114     GPIO3,
00115     GPIO4,
00116     GPIO5,
00117     GPIO6,
00118     GPIO7
00119 } GPIO_IDX_t;
00120 
00121 typedef enum {
00122     GPIO_OP_OUTPUT_LOW = 0,
00123     GPIO_OP_OUTPUT_HIGH = 1,
00124     GPIO_OP_READ_INPUT=2
00125 } GPIO_OP_t;
00126 
00127 typedef enum {
00128     GPIO_RES_OUTPUT_LOW = 0,
00129     GPIO_RES_OUTPUT_HIGH= 1,
00130     GPIO_RES_INPUT_LOW  = 2,
00131     GPIO_RES_INPUT_HIGH = 3,
00132     GPIO_RES_INVALID_INDEX= 255
00133 } GPIO_RES_t;
00134 
00135 typedef struct {
00136     union {
00137         struct {
00138             char o1, o2, o3, o4;
00139         };
00140         char o[4];
00141     } sin_addr;
00142     operator char* () { return (char*)this; }
00143 } IPADDRESS_t;
00144 
00145 typedef enum {
00146     NoFailure=0,
00147     
00148     JoinFailure=2,
00149     AuthenticationFailure,
00150     AssociationFailure,
00151     WEPHandshakeFailure,
00152     PSKCalculationFailure,
00153     PSKHandshakeFailure,
00154     AdHocJoinFailure,
00155     SecurityMismatchFailure,
00156     NoSuitableAPFoundFailure,
00157     RetryForeverNotSupportedFailure,
00158     
00159     BeaconTimeOut=21,
00160     DeauthReceivedDE,
00161     DisassociateReceived
00162 } CONN_ERROR_t;
00163 
00164 typedef enum {
00165     NotConnected_StaticIP = 0,
00166     Connected_StaticIP = 1,
00167     NotConnected_DHCP = 2,
00168     Connected_DHCP = 3
00169 } NET_STAT_t;
00170 
00171 typedef enum {
00172     INFRASTRUCTURE = 1,
00173     ADHOC = 2
00174 } NETW_MODE_t;
00175 
00176 typedef enum {
00177     NoError = 0,
00178     BaudRateGeneratorError = 60,
00179     InvalidConnectionProfileError = 61,
00180     WiFiAlreadyConnectedError = 62,
00181     WiFiAlreadyDisconnectedError = 63,
00182     CloseSocketFailedError = 64,
00183     SocketSendToTimeOutError = 65,
00184     ScanIndexOutOfRangeError = 66,
00185     ICMPPingFloodError = 67,
00186     ICMPPingInUseError = 68,
00187     SocketRecvFromError = 69,
00188     SerialTransmitBufferAllocationError = 71,
00189     GeneralAssertError = 72,
00190     InvalidPowersaveModeError = 73,
00191     BusyInHibernateModeError = 74,
00192     BusyInScanModeError = 75,
00193     Unknown = 0xFFFF
00194 }  ERR_t;
00195 
00196 typedef enum {
00197     WPA_PSK = 3,
00198     WPA_PASSPHRASE = 4,
00199     WPA2_PSK = 5,
00200     WPA2_PASSPHRASE = 6,
00201     WPA_OR_WPA2_PSK = 7,
00202     WPA_OR_WPA2_PASSPHRASE = 8
00203 } WPA_SECURITY_t;
00204 
00205 typedef __packed struct {
00206     char IE:1;
00207     char res:3;
00208     char Privacy:1;
00209     char Preamble:1;
00210     char WPA:1;
00211     char WPA2:1;
00212 } AP_CONFIG_t;
00213 
00214 typedef enum {
00215     FCC = 0,
00216     IC,
00217     ETSI,
00218     SPAIN,
00219     FRANCE,
00220     JAPANA,
00221     JAPANB
00222 } DOMAIN_COUNTRY_CODE_t;
00223 
00224 typedef enum {
00225     HIBERNATE = 1,          // Radio off
00226     PSPOLL_AP_SUGGESTED_DTIM = 2,  
00227     PSPOLL_SELF_SET_DTIM = 3,
00228     FULLY_POWERED = 4
00229 } POWERSAVE_MODE_t;
00230 
00231 typedef enum {
00232     InvalidSocketHandle=254,
00233     UnknownSocketType=255
00234 } SOCKET_HANDLE_t;
00235 
00236 typedef enum {
00237     UDP=0,
00238     TCP=1
00239 } SOCKET_TYPE_t;
00240 
00241 
00242 
00243 /** Class Wifi encapsulates communication and access to Wifi Plus Click module. */
00244 /*!\copyright { Henry Leinen } */
00245 class Wifi
00246 {
00247 public:
00248     typedef enum {
00249         Idle,                  
00250         Header1_received,           
00251         Header2_received,           
00252         MessageType_low_received,
00253         MessageType_high_received,
00254         DataLen_low_received,
00255         Data_receiving,
00256         Awaiting_trailer
00257     } RX_STATE_t;
00258 
00259 protected:
00260     Serial          m_wifi;
00261     DigitalOut      m_reset;
00262     char*           m_buffer;
00263     
00264     bool            m_msgReceived;
00265     RSP_MSG_t       m_msgResponse;
00266     short           m_msgDataLen;
00267     bool            m_ackReceived;
00268 
00269 //  Event data
00270     IPADDRESS_t     m_ipAddress;
00271     bool            m_bWifiConnected;
00272     CONN_ERROR_t    m_WifiConnectionError;
00273     
00274     ERR_t           m_lastError;
00275 
00276     bool            m_bScanResultsReady;
00277     char            m_NumLastScanResults;
00278     
00279 public:
00280     static Wifi*     _Wifi;
00281     static Wifi*    getInstance()
00282     {
00283         if (_Wifi==NULL) {
00284             error("NOWIFI");
00285         }
00286         return _Wifi;
00287     }
00288                 
00289 public:
00290     Wifi(PinName tx, PinName rx, PinName rst);
00291 
00292     bool AwaitScanResults(int timeout) {
00293         Timer t;
00294         t.start();
00295         while(t.read() < timeout) {
00296             if (m_bScanResultsReady) {
00297                 return true;
00298             }
00299         }
00300         return false;
00301     }
00302 
00303     bool AwaitConnected(int timeout, ERR_t *err = NULL) {
00304         Timer t;
00305         t.start();
00306         while(t.read() < timeout) {
00307             if (m_bWifiConnected) {
00308                 return true;
00309             }
00310             wait(0.1);
00311         }
00312         if (err)
00313             *err = m_lastError;
00314         return false;
00315     }        
00316     
00317     bool AwaitDisconnected(int timeout, ERR_t *err = NULL) {
00318         Timer t;
00319         t.start();
00320         while(t.read() < timeout) {
00321             if (!m_bWifiConnected) {
00322                 return true;
00323             }
00324             wait(0.1);
00325         }
00326         if (err)
00327             *err = m_lastError;
00328         return false;
00329     }
00330     
00331     void Reset();
00332 
00333     /** Function to reset the Wifi Plus Click Device. PLEASE NOTE, it will loose all its current settings
00334       * @returns true if successful or false otherwise 
00335       */
00336     bool ResetMsg();
00337     /** Function retrieves the software and radio version of the Wifi Plus Click Board.
00338       * @param sw_ver_lo : receives the low WiComm Socket Version number
00339       * @param sw_ver_hi : recevies the high WiComm Socket Version number
00340       * @param rad_ver_lo: receives the low Radio version number
00341       * @param rad_ver_hi: receives the high Radio version number
00342       * @returns true if successful or false otherwise
00343       */
00344     bool GetVersionMsg(char &sw_ver_lo, char &sw_ver_hi, char &rad_ver_lo, char &rad_ver_hi);
00345     /** Function will set a GPIO pin to a specific output level or will set it to input.
00346       * The function will return the result of the operation.
00347       * @param pin : Reference to the GPIO pin of interest
00348       * @param operation: the operation to perform on the GPIO pin. Set to specific output level or read as input
00349       * @param result : a reference to a variable which receives the actual status of the GPIO pin
00350       */
00351     bool GpioMsg(GPIO_IDX_t pin, GPIO_OP_t operation, GPIO_RES_t &result);
00352     
00353     /** Function to set the IP address of the Wifi Plus Click device.
00354       * @param bUseDHCP : set to true if DHCP shall be used, or set to false if you want to specify a static IP address
00355       * @param IPAddress: pointer to an IP address.
00356       *                   Please note that the IP adress will only be used if bUseDHCP is set to false
00357       * @returns : true if successfull, or false otherwise. The function will not check for any asynchroneous result.
00358       */
00359     bool SetIpAddress(bool bUseDHCP, IPADDRESS_t *IPAddress);
00360     /** Function to set the network mask of the Wifi Plus Click device.
00361       * @param NetworkMask : the Network mask to use.
00362       * @returns : true if successfull, or false otherwise.
00363       */
00364     bool SetSubnetMask(IPADDRESS_t *NetworkMask);
00365     /** Function to set the gateway ip address to use. If the gateway ip address is set to 0.0.0.0 the Wifi Plus Click will not use
00366       * a gateway.
00367       * @param IPAddress : Pointer to an IPADDRESS specifying the IP Address of the gateway to use. 
00368       * @returns : true if successfull, or false otherwise.
00369       */
00370     bool SetGatewayIpAddress(IPADDRESS_t *IPAddress);
00371     /** Function to retrieve the current network status of the Wifi Plus Click device.
00372       * @param MacAddress : pointer to an array of 6 Bytes to retrieve the MAC Address. Set to NULL if not required.
00373       * @param IPAddress  : pointer to an IPADDRESS_t structure which receives the IP address. Set to NULL if not required.
00374       * @oaram NetworkMask : pointer to an IPADDRESS_t structure which receives the network mask. Set to NULL if not requried.
00375       * @param GatewayAddress : pointer to an IPADDRESS_t structure which receives the gateway address. Set to NULL if no required.
00376       * @param stat : will receive the actual status.
00377       * @returns : true if successfull, or false otherwise.
00378       */
00379     bool GetNetworkStatus(char *MacAddress, IPADDRESS_t *IPAddress, IPADDRESS_t *NetworkMask, IPADDRESS_t *GatewayAddress, NET_STAT_t &stat);
00380     /** Function to set the MAC Address of the device. This command should only be used during initialization
00381       * @param MacAddress : the MAC address to use.
00382       * @returns : true if successfull, or false otherwise.
00383       */
00384     bool SetMACAddress(char MacAddress[6]);
00385     /** Function to set the address resolution time from 1 to 65535 seconds.
00386       * @param ARPTime : either 0 to disable ARP or time in seconds.
00387       * @returns : true if successfull, or false otherwise.
00388       */
00389     bool SetARPTime(unsigned short ARPTime);
00390     /** Function to set the network mode for one of two available profiles.
00391       * @param Profile : can be profile number one or 2
00392       * @param NetMode : can be either INFRASTRUCTURE or ADHOC
00393       * @returns : true if successfull, or false otherwise.
00394       */
00395     bool SetNetworkMode(char Profile, NETW_MODE_t NetMode);
00396     /** Function to set the SSID for one of two profiles.
00397       * @param Profile : can be profile number one or two.
00398       * @param ssid : a string descibing the ssid.
00399       * @returns : true if successfull, or false otherwise.
00400       */
00401     bool SetSSID(char Profile, const char* ssid);
00402     /** Function switches device into one of 3 power saving modes, or sets it into awake mode.
00403       * @param pwrsave : specifies which powersaving mode to set.
00404       * @param DTIM_Listen : if pwrsave is in mode PSPOLL_SELF_DTIM uses this value as the DTIM listen interval. Value is given in units of 100ms.
00405       * @returns : true if successfull, or false otherwise
00406       */
00407     bool SetPowerSaveMode(POWERSAVE_MODE_t pwrsave, short DTIM_Listen);
00408     /** Function to set the regional domain for all CPs.
00409       * @param dcode : domain country code valid for all CPs.
00410       * @returns : true if successfull, or false otherwise.
00411       */
00412     bool SetRegionalDomain(DOMAIN_COUNTRY_CODE_t dcode);
00413     /** Function to set the channels on which to scan.
00414       * @param numListItems : the number of channels given in the list.
00415       * @param ListItems : array consisting of numListItems channel numbers.
00416       * @returns : true if successfull, or false otherwise
00417       */
00418     bool SetChannelList(char numListItems, char ListItems[]);
00419     /** Function to specify the connection managaer retry count. There are separate values for infrastructure and ad hoc mode.
00420       * Please note that a number of 0 means no retries and 255 means retry forever.
00421       * @param infrastructureRetryCount : number of retries in infrastructure mode
00422       * @param adhocRetryCount : number of retries in ad-hoc mode.
00423       * @returns : true if successfull, or false otherwise
00424       */
00425     bool SetRetryCount(char infrastructureRetryCount=255, char adhocRetryCount=5);
00426     /** Function to set the Security mode to OPN 
00427       * @param Profile : can be profile number one or two.
00428       * @returns : true if successfull, or false otherwise.
00429       */
00430     bool SetSecurityOpen(char Profile);
00431     /** Function to set the WEP40 security mode.
00432       * @param Profile : can be profile number one or two.
00433       * @param bShareKey : set to true for shared key, or false for open key
00434       * @param DefaultWEPKeyIdx : the index (0-3) into the key array
00435       * @param SecurityKeys : array or 4 security keys with 5 bytes each
00436       * @returns : true if successfull, or false otherwise
00437       */
00438     bool SetSecurityWEP40(char Profile, bool bSharedKey, char DefaultWEPKeyIdx, char SecurityKeys[20]);
00439     /** Function to set the WEP104 security mode.
00440       * @param Profile : can be profile number one or two.
00441       * @param bShareKey : set to true for shared key, or false for open key
00442       * @param DefaultWEPKeyIdx : the index (0-3) into the key array
00443       * @param SecurityKeys : array or 4 security keys with 13 bytes each
00444       * @returns : true if successfull, or false otherwise
00445       */
00446     bool SetSecurityWEP104(char Profile, bool bSharedKey, char DefaultWEPKeyIdx, char SecurityKeys[52]);
00447     /** Function to set the WPA security mode.
00448       * @param Profile : can be profile number one or two.
00449       * @param sec : can be one of the define security types.
00450       * @param len : length of the security key or passphrase.
00451       * @param secKeyOrPSK : security key or passphrase.
00452       * @returns : true if successfull, or false otherwise.
00453       */
00454     bool SetSecurityWPA(char Profile, WPA_SECURITY_t sec, int len, const char* secKeyOrPSK);
00455     /** Function to retrieve the WPA Key from the Wifi Plus Click device for a selected profile.
00456       * @param Profile : can be profile number one or two.
00457       * @param Key : will receive the key.
00458       * @returns : true if successfull, or false otherwise.
00459       */
00460     bool GetWPAKey(char Profile, char Key[32]);
00461     /** Function to initiate the scan on one or both Profiles using the settings downloaded to the Wifi Plus Click.
00462       * Please NOTE that the device will only accept the REBOOT message while a scan is active. A scan can only be
00463       * started if the device is not connected.
00464       * @param Profile : can be profile number one or two.
00465       * @returns : true if successfull, or false otherwise.
00466       */
00467     bool ScanStartMsg(char Profile);
00468     /** Function to retrieve a specific scan result. Will only work after scan has been started and finished.
00469       * @param index : specify the result item to return. When this index is too high the function returns with a false return value.
00470       * @param ssid : will receive the SSID of the item.
00471       * @param apCfg : will receive the access points configuration.
00472       * @param beaconInterval : will receive the beacon interval time.
00473       * @param ATIMWindow : will receive the ATIM Window.
00474       * @param RSSI : will receive the RSSI level.
00475       * @param bssType : will receive information about the BSS type (INFRASTRUCTURE oR ADHOC).
00476       * @param channelNo : will receive on which channel the AP transmits.
00477       * @returns : true if successfull, false otherwise.
00478       */
00479     bool ScanGetResults(char index, char ssid[32], AP_CONFIG_t &apCfg, short &beaconInterval, short &ATIMWindow, char &RSSI, NETW_MODE_t &bssType, char &channelNo);
00480     
00481     /** Function to connect using the specified profile and the settings previously downloaded to the device. Please Note that the connection
00482       * state will be transmitted asynchroneously be the device. You need to monitor the connected state.
00483       * @param Profile : can be profile number one or two.
00484       * @returns : true if successfully submitted, or false otherwise.
00485       */
00486     bool Connect(char Profile);
00487     /** Function to disconnect from any connected AP.
00488       * @returns : true if successful, or false otherwise.
00489       */
00490     bool Disconnect();
00491     
00492     
00493     /** @name Socket Functions
00494         In the following section, all socket relevant functions are contained.
00495        */
00496     ///@{
00497     
00498     /** Function to allocate the internal memory of the device and the number of sockets (which in total is limited to 8).
00499       * @param nTCPSvr : Number of server sockets to allocate.
00500       * @param nTCPClnt: Number of client sockets to allocate.
00501       * @param TCPSvrRxBuf : Size (in bytes) to allocate for the receive buffer for each server socket.
00502       * @param TCPSvrTxBuf : Size (in bytes) to allocate for the transmit buffer for each server socket.
00503       * @param TCPClntRxBuf: Size (in bytes) to allocate for the receive buffer for each client socket.
00504       * @param TCPClntTxBuf: Size (in bytes) to allocate for the transmit buffer for each client socket.
00505       * @returns : true if successful, or false otherwise. Can return false if the requestet internal memory exceededs the total of 8192 internal byte orif the maximum number of
00506       * 8 sockets is exceeded.
00507       */
00508     bool SocketAllocate(char nTCPSvr, char nTCPClnt, unsigned short TCPSvrRxBuf, unsigned short TCPSvrTxBuf, unsigned short TCPClntRxBuf, unsigned short TCPClntTxBuf);
00509     
00510     /** Function to create a new socket object of the given type.
00511       * @param sockType : Specifies the type of socket to create (UDP or TCP).
00512       * @returns : Either a valid socket handle or InvalidSocketHandle or UnknownSocketType.
00513       */
00514     SOCKET_HANDLE_t SocketCreate( SOCKET_TYPE_t sockType );
00515     /** Function to close a previously created socket.
00516       * @param hSock: Valid socket handle, which has been created by a previous call to SocketCreate.
00517       * @returns : true if successful, or false if an error occured
00518       */
00519     bool SocketClose(SOCKET_HANDLE_t hSock);
00520     /** Function to bind to a specific port using the given socket.
00521       * @param hSock : Valid socket handle.
00522       * @param Port  : local port to bind to.
00523       * @returns : true if successfull, or false otherwise.
00524       */
00525     bool SocketBind(SOCKET_HANDLE_t hSock, int Port);
00526     /** Function to prepare the a number of sockets for accepting remote connections 
00527       * @param hSock : Valid socket handle.
00528       * @param Backlog : Number of sockets to set in listening mode, will receive the number of new unassigned backlog count
00529       * @return : true if successfull, or false otherwise.
00530       */
00531     bool SocketListen(SOCKET_HANDLE_t hSock, int &Backlog);
00532     /** Function to accept a new remote connection. Will work asynchroneously, means if no new connection was accepted, will return immediately.
00533       * @param hSock : Valid socket handle.
00534       * @param client : reference to a variable which receives the new socket handle of the connection socket or InvalidSocketHandle if no connection could be made at this time.
00535       * @param remotePort : receives the remote port of the remote connection.
00536       * @param remoteAddress : receives the remote address of the remote connection.
00537       * @returns : true if successfull, or false otherwise. PLEASE NOTE that even if no connection was made, the return result may be true.
00538       */
00539     bool SocketAccept(SOCKET_HANDLE_t hSock, SOCKET_HANDLE_t &client, int &remotePort, IPADDRESS_t &remoteAddress);
00540     /** Function to connect the socket to a remote socket specified by IpAddress and Port.
00541       * @param hSock : Valid socket handle.
00542       * @param IpAddress : valid IP Address of the remote host to connect with.
00543       * @param Port : Port of the remote host to connect with.
00544       * @returns : true if a connection has been made successfully or false otherwise. 
00545       */
00546     SOCKET_HANDLE_t SocketConnect(SOCKET_HANDLE_t hSock, IPADDRESS_t *IpAddress, int Port);    
00547     /** Function to send data on the connected socket
00548       * @param hSock : Valid socket handle.
00549       * @param data : Pointer to a buffer containing the data to send.
00550       * @param length : Number of bytes in the buffer to send.
00551       * @returns : Number of bytes actually sent over the connection.
00552       */
00553     int SocketSend(SOCKET_HANDLE_t hSock, char* data, int length);
00554     /** Function to receive data from the connected socket.
00555       * @param hSock : Valid socket handle of a socket which is already connected.
00556       * @param data : Pointer to a valid buffer which shall receive the data.
00557       * @param length : Maximum number of bytes which can be received and stored in the provided buffer.
00558       * @returns : Number of bytes actually received over the connection or -1 if a fault occured.
00559       */
00560     int SocketRecv(SOCKET_HANDLE_t hSock, char* data, int length);
00561     /** Function to send data over a connectionless socket.
00562       * @param hSock : Valid socket handle.
00563       * @param remoteAddress : The ip address of the remote destination to send the data to.
00564       * @param remotePort : The port of the remote destination to send the data to.
00565       * @param data : Pointer to a buffer which contains the data to send.
00566       * @param length : The number of bytes to sent to the specified address.
00567       * @returns : Number of bytes actually sent or -1 if a fault occured.
00568       */
00569     int SocketSendTo(SOCKET_HANDLE_t hSock, IPADDRESS_t* remoteAddress, int remotePort, char *data, int length);
00570     /** Function to receive data over a connectionless socket.
00571       * @param hSock : Valid socket handle.
00572       * @param remoteAddress : The ip address of the remote origin from where to receive the data.
00573       * @param remotePort : Point to receive the port of the remote origin from where to receive the data or NULL if not needed.
00574       * @param data : Pointer to a buffer which will receive the data.
00575       * @param length : Number of bytes to receive and which fit into the provided buffer.
00576       * @returns : Number of bytes actually received or -1 if a fault occured.
00577       */
00578     int SocketRecvFrom(SOCKET_HANDLE_t hSock, IPADDRESS_t *remoteAddress, int *remotePort, char *data, int length);
00579     
00580     ///@}
00581     
00582     
00583     /** This is the main cyclic function, which needs to be called as often as possible.
00584      * The function will check if a new message has been received and will decode and dispatch it.
00585      */        
00586     void Poll();
00587     
00588     
00589     int gethostbyname(const char* host, IPADDRESS_t *IpAddress);
00590     int convert(const char *hostip, IPADDRESS_t *IpAddress);
00591 protected:    
00592     void SendCommand(CMD_MSG_t cmd, int msgLen1, char *pData1, int msgLen2 = 0, char* pData2 = NULL);
00593     void rx_int();
00594     
00595     void SubmitResponse(RSP_MSG_t rsp, int msgLen);
00596     bool WaitMessage(RSP_MSG_t msg, int timeout);
00597     bool WaitEvent(EVT_MSG_t evt, int timeout);
00598     bool WaitAck(int timeout);
00599 };
00600 
00601 #endif //__WIFI_H__