Implementation of the WifiPlusClick hardware module.

Dependents:   WifiPlusKlickExample

WifiPlusClick Libary

Overview

http://www.mikroe.com/img/development-tools/accessory-boards/click/wifi-plus/wifi_plus_click_main.png

This library implements the functionality exposed by a WifiPlusClick module from MikroElektronika (http://www.mikroe.com/click/wifi-plus/).

The WifiPlusClick module is an easy to handle module which provides access to up to 8 simultaneous socket objects - which is an an important aspect when you want to implement your own web server.

When I first started with the more commonly used Wifly module, I found out that the Wifly module does not reliably serve webpages which include other resources like images, JavaScript files or CSS files. The root cause seems to be the limitation that Wifly is only able to handle a single socket at this time. So I searched for an alternative and found this (actually cheaper) alternative :

WifiPlusClick HW Module

This module comes with its own limitations. The WifiPlusClick Module interface does not allow to use broadcasting or multicasting on UDP sockets. There are some additional limitations, but I think these are not so important. The following functionality is provided by the module and my library implementation :

  1. Wifi functionality
    1. Connections using AD-HOC or INFRASTRUCTURE mode
    2. List all available Wifi beacons
    3. WEP and WPA/WPA2 security modes including binary and ASCII keys
    4. reading binary WPA key after successfull Connection to speed up connection time
  2. Socket functionality
    1. UDP sockets
    2. TCP sockets

Limitations

I found the following limitations:

  1. UDP sockets cannot use multicasting or broadcasting
  2. set_option functionality is not provided by the HW
  3. 8 sockets can be configured with 1024 bytes of buffer each or 1 socket with 8192 bytes of buffer.

Sample application

Here is my sample application which you can use as a starting point.

Import programWifiPlusKlickExample

Example application of the WifiPlusClick library for use of WifiPlusClick HW Module from Mikroe.com

NOTE

The implementation of the Sockets in this library is still not completely tested. I only tested the TCP part of the sockets. Please let me know what your experiences are when using the library. I will be working on a multithreaded version of this library...

Committer:
leihen
Date:
Mon Jul 29 15:15:21 2013 +0000
Revision:
0:2a179bd4cc02
Initial Version of the WifiPlusClick Library.
; Tested in INFRASTRUCTURE mode only.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
leihen 0:2a179bd4cc02 1 /* Copyright (c) 2013 Henry Leinen (henry[dot]leinen [at] online [dot] de)
leihen 0:2a179bd4cc02 2 *
leihen 0:2a179bd4cc02 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
leihen 0:2a179bd4cc02 4 * and associated documentation files (the "Software"), to deal in the Software without restriction,
leihen 0:2a179bd4cc02 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
leihen 0:2a179bd4cc02 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
leihen 0:2a179bd4cc02 7 * furnished to do so, subject to the following conditions:
leihen 0:2a179bd4cc02 8 *
leihen 0:2a179bd4cc02 9 * The above copyright notice and this permission notice shall be included in all copies or
leihen 0:2a179bd4cc02 10 * substantial portions of the Software.
leihen 0:2a179bd4cc02 11 *
leihen 0:2a179bd4cc02 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
leihen 0:2a179bd4cc02 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
leihen 0:2a179bd4cc02 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
leihen 0:2a179bd4cc02 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
leihen 0:2a179bd4cc02 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
leihen 0:2a179bd4cc02 17 */
leihen 0:2a179bd4cc02 18 #ifndef __WIFI_H__
leihen 0:2a179bd4cc02 19 #define __WIFI_H__
leihen 0:2a179bd4cc02 20
leihen 0:2a179bd4cc02 21 #include "mbed.h"
leihen 0:2a179bd4cc02 22
leihen 0:2a179bd4cc02 23 typedef enum {
leihen 0:2a179bd4cc02 24 // Control Messages
leihen 0:2a179bd4cc02 25 RESET_MSG = 170, /*!< RESET_MSG */
leihen 0:2a179bd4cc02 26 GET_VERSION_MSG = 23, /*!< GET_VERSION_MSG */
leihen 0:2a179bd4cc02 27 GPIO_MSG = 172,
leihen 0:2a179bd4cc02 28 // Network Configuration Messages
leihen 0:2a179bd4cc02 29 SET_IP_ADDRESS_MSG = 41,
leihen 0:2a179bd4cc02 30 SET_NETWORK_MASK_MSG = 42,
leihen 0:2a179bd4cc02 31 SET_GATEWAY_IP_ADDRESS_MSG = 44,
leihen 0:2a179bd4cc02 32 GET_NETWORK_STATUS_MSG = 48,
leihen 0:2a179bd4cc02 33 SET_MACADDRESS_MSG = 49,
leihen 0:2a179bd4cc02 34 SET_ARP_TIME_MSG = 173,
leihen 0:2a179bd4cc02 35 // Wi-Fi General Configuration Messages
leihen 0:2a179bd4cc02 36 SET_CP_NETWORK_MODE_MSG = 55,
leihen 0:2a179bd4cc02 37 SET_CP_SSID_MSG = 57,
leihen 0:2a179bd4cc02 38 SET_REGIONAL_DOMAIN_MSG = 56,
leihen 0:2a179bd4cc02 39 SET_CHANNEL_LIST_MSG = 58,
leihen 0:2a179bd4cc02 40 SET_LIST_RETRY_COUNT_MSG = 59,
leihen 0:2a179bd4cc02 41 // Wi-Fi Power Management Messages
leihen 0:2a179bd4cc02 42 SET_POWER_SAVE_MODE_MSG = 102,
leihen 0:2a179bd4cc02 43 // Wi-Fi Security Configuration Messages
leihen 0:2a179bd4cc02 44 SET_CP_SECURITY_OPEN_MSG = 65,
leihen 0:2a179bd4cc02 45 SET_CP_SECURITY_WEP40_MSG = 66,
leihen 0:2a179bd4cc02 46 SET_CP_SECURITY_WEP104_MSG = 67,
leihen 0:2a179bd4cc02 47 SET_CP_SECURITY_WPA_MSG = 68,
leihen 0:2a179bd4cc02 48 GET_CP_WPAKEY_MSG = 71,
leihen 0:2a179bd4cc02 49 // Wi-Fi Scanning Messages
leihen 0:2a179bd4cc02 50 SCAN_START_MSG = 80,
leihen 0:2a179bd4cc02 51 SCAN_GET_RESULTS_MSG = 81,
leihen 0:2a179bd4cc02 52 // Wi-Fi Connection Messages
leihen 0:2a179bd4cc02 53 WIFI_CONNECT_MSG = 90,
leihen 0:2a179bd4cc02 54 WIFI_DISCONNECT_MSG = 91,
leihen 0:2a179bd4cc02 55 // ICMP (Ping) Messages
leihen 0:2a179bd4cc02 56 PING_SEND_MSG = 121,
leihen 0:2a179bd4cc02 57 // Socket Messages
leihen 0:2a179bd4cc02 58 SOCKET_CREATE_MSG = 110,
leihen 0:2a179bd4cc02 59 SOCKET_CLOSE_MSG = 111,
leihen 0:2a179bd4cc02 60 SOCKET_BIND_MSG = 112,
leihen 0:2a179bd4cc02 61 SOCKET_CONNECT_MSG = 113,
leihen 0:2a179bd4cc02 62 SOCKET_LISTEN_MSG = 114,
leihen 0:2a179bd4cc02 63 SOCKET_ACCEPT_MSG = 115,
leihen 0:2a179bd4cc02 64 SOCKET_SEND_MSG = 116,
leihen 0:2a179bd4cc02 65 SOCKET_RECV_MSG = 117,
leihen 0:2a179bd4cc02 66 SOCKET_SEND_TO_MSG = 118,
leihen 0:2a179bd4cc02 67 SOCKET_RECV_FROM_MSG = 119,
leihen 0:2a179bd4cc02 68 SOCKET_ALLOCATE_MSG = 122,
leihen 0:2a179bd4cc02 69
leihen 0:2a179bd4cc02 70 } CMD_MSG_t;
leihen 0:2a179bd4cc02 71
leihen 0:2a179bd4cc02 72
leihen 0:2a179bd4cc02 73 typedef enum {
leihen 0:2a179bd4cc02 74 ACK_MSG = 0,
leihen 0:2a179bd4cc02 75 EVENT_MSG = 1,
leihen 0:2a179bd4cc02 76
leihen 0:2a179bd4cc02 77 // Control Message Responses
leihen 0:2a179bd4cc02 78 GPIO_RESPONSE_MSG = 50,
leihen 0:2a179bd4cc02 79 // Network Configuration Message Responses
leihen 0:2a179bd4cc02 80 NETWORK_STATUS_RESPONSE_MSG = 48,
leihen 0:2a179bd4cc02 81 // Wi-Fi Security Configuration Message Responses
leihen 0:2a179bd4cc02 82 WPAKEY_RESPONSE_MSG = 0x31,
leihen 0:2a179bd4cc02 83 // Wi-Fi Scanning Message Responses
leihen 0:2a179bd4cc02 84 SCAN_RESULT_MSG = 22,
leihen 0:2a179bd4cc02 85 // Socket Message Responses
leihen 0:2a179bd4cc02 86 SOCKET_CREATE_RESPONSE_MSG = 23,
leihen 0:2a179bd4cc02 87 SOCKET_BIND_RESPONSE_MSG = 24,
leihen 0:2a179bd4cc02 88 SOCKET_CONNECT_RESPONSE_MSG = 25,
leihen 0:2a179bd4cc02 89 SOCKET_LISTEN_RESPONSE_MSG = 26,
leihen 0:2a179bd4cc02 90 SOCKET_ACCEPT_RESPONSE_MSG = 27,
leihen 0:2a179bd4cc02 91 SOCKET_SEND_RESPONSE_MSG = 28,
leihen 0:2a179bd4cc02 92 SOCKET_RECV_RESPONSE_MSG = 29,
leihen 0:2a179bd4cc02 93 SOCKET_SEND_TO_RESPONSE_MSG = 30,
leihen 0:2a179bd4cc02 94 SOCKET_RECV_FROM_RESPONSE_MSG = 31,
leihen 0:2a179bd4cc02 95 SOCKET_ALLOCATE_RESPONSE_MSG = 32,
leihen 0:2a179bd4cc02 96
leihen 0:2a179bd4cc02 97 } RSP_MSG_t;
leihen 0:2a179bd4cc02 98
leihen 0:2a179bd4cc02 99 typedef enum {
leihen 0:2a179bd4cc02 100 Event_IP_Address_Assigned = 16,
leihen 0:2a179bd4cc02 101 Event_WiFi_Connection_Status_Changed = 8,
leihen 0:2a179bd4cc02 102 Event_WiFi_Scan_Results_Ready = 9,
leihen 0:2a179bd4cc02 103 Event_Ping_Response = 26,
leihen 0:2a179bd4cc02 104 Event_Error_Event = 255,
leihen 0:2a179bd4cc02 105 Event_Startup_Event = 27,
leihen 0:2a179bd4cc02 106
leihen 0:2a179bd4cc02 107 } EVT_MSG_t;
leihen 0:2a179bd4cc02 108
leihen 0:2a179bd4cc02 109
leihen 0:2a179bd4cc02 110 typedef enum {
leihen 0:2a179bd4cc02 111 GPIO0 = 0,
leihen 0:2a179bd4cc02 112 GPIO1,
leihen 0:2a179bd4cc02 113 GPIO2,
leihen 0:2a179bd4cc02 114 GPIO3,
leihen 0:2a179bd4cc02 115 GPIO4,
leihen 0:2a179bd4cc02 116 GPIO5,
leihen 0:2a179bd4cc02 117 GPIO6,
leihen 0:2a179bd4cc02 118 GPIO7
leihen 0:2a179bd4cc02 119 } GPIO_IDX_t;
leihen 0:2a179bd4cc02 120
leihen 0:2a179bd4cc02 121 typedef enum {
leihen 0:2a179bd4cc02 122 GPIO_OP_OUTPUT_LOW = 0,
leihen 0:2a179bd4cc02 123 GPIO_OP_OUTPUT_HIGH = 1,
leihen 0:2a179bd4cc02 124 GPIO_OP_READ_INPUT=2
leihen 0:2a179bd4cc02 125 } GPIO_OP_t;
leihen 0:2a179bd4cc02 126
leihen 0:2a179bd4cc02 127 typedef enum {
leihen 0:2a179bd4cc02 128 GPIO_RES_OUTPUT_LOW = 0,
leihen 0:2a179bd4cc02 129 GPIO_RES_OUTPUT_HIGH= 1,
leihen 0:2a179bd4cc02 130 GPIO_RES_INPUT_LOW = 2,
leihen 0:2a179bd4cc02 131 GPIO_RES_INPUT_HIGH = 3,
leihen 0:2a179bd4cc02 132 GPIO_RES_INVALID_INDEX= 255
leihen 0:2a179bd4cc02 133 } GPIO_RES_t;
leihen 0:2a179bd4cc02 134
leihen 0:2a179bd4cc02 135 typedef struct {
leihen 0:2a179bd4cc02 136 union {
leihen 0:2a179bd4cc02 137 struct {
leihen 0:2a179bd4cc02 138 char o1, o2, o3, o4;
leihen 0:2a179bd4cc02 139 };
leihen 0:2a179bd4cc02 140 char o[4];
leihen 0:2a179bd4cc02 141 } sin_addr;
leihen 0:2a179bd4cc02 142 operator char* () { return (char*)this; }
leihen 0:2a179bd4cc02 143 } IPADDRESS_t;
leihen 0:2a179bd4cc02 144
leihen 0:2a179bd4cc02 145 typedef enum {
leihen 0:2a179bd4cc02 146 NoFailure=0,
leihen 0:2a179bd4cc02 147
leihen 0:2a179bd4cc02 148 JoinFailure=2,
leihen 0:2a179bd4cc02 149 AuthenticationFailure,
leihen 0:2a179bd4cc02 150 AssociationFailure,
leihen 0:2a179bd4cc02 151 WEPHandshakeFailure,
leihen 0:2a179bd4cc02 152 PSKCalculationFailure,
leihen 0:2a179bd4cc02 153 PSKHandshakeFailure,
leihen 0:2a179bd4cc02 154 AdHocJoinFailure,
leihen 0:2a179bd4cc02 155 SecurityMismatchFailure,
leihen 0:2a179bd4cc02 156 NoSuitableAPFoundFailure,
leihen 0:2a179bd4cc02 157 RetryForeverNotSupportedFailure,
leihen 0:2a179bd4cc02 158
leihen 0:2a179bd4cc02 159 BeaconTimeOut=21,
leihen 0:2a179bd4cc02 160 DeauthReceivedDE,
leihen 0:2a179bd4cc02 161 DisassociateReceived
leihen 0:2a179bd4cc02 162 } CONN_ERROR_t;
leihen 0:2a179bd4cc02 163
leihen 0:2a179bd4cc02 164 typedef enum {
leihen 0:2a179bd4cc02 165 NotConnected_StaticIP = 0,
leihen 0:2a179bd4cc02 166 Connected_StaticIP = 1,
leihen 0:2a179bd4cc02 167 NotConnected_DHCP = 2,
leihen 0:2a179bd4cc02 168 Connected_DHCP = 3
leihen 0:2a179bd4cc02 169 } NET_STAT_t;
leihen 0:2a179bd4cc02 170
leihen 0:2a179bd4cc02 171 typedef enum {
leihen 0:2a179bd4cc02 172 INFRASTRUCTURE = 1,
leihen 0:2a179bd4cc02 173 ADHOC = 2
leihen 0:2a179bd4cc02 174 } NETW_MODE_t;
leihen 0:2a179bd4cc02 175
leihen 0:2a179bd4cc02 176 typedef enum {
leihen 0:2a179bd4cc02 177 NoError = 0,
leihen 0:2a179bd4cc02 178 BaudRateGeneratorError = 60,
leihen 0:2a179bd4cc02 179 InvalidConnectionProfileError = 61,
leihen 0:2a179bd4cc02 180 WiFiAlreadyConnectedError = 62,
leihen 0:2a179bd4cc02 181 WiFiAlreadyDisconnectedError = 63,
leihen 0:2a179bd4cc02 182 CloseSocketFailedError = 64,
leihen 0:2a179bd4cc02 183 SocketSendToTimeOutError = 65,
leihen 0:2a179bd4cc02 184 ScanIndexOutOfRangeError = 66,
leihen 0:2a179bd4cc02 185 ICMPPingFloodError = 67,
leihen 0:2a179bd4cc02 186 ICMPPingInUseError = 68,
leihen 0:2a179bd4cc02 187 SocketRecvFromError = 69,
leihen 0:2a179bd4cc02 188 SerialTransmitBufferAllocationError = 71,
leihen 0:2a179bd4cc02 189 GeneralAssertError = 72,
leihen 0:2a179bd4cc02 190 InvalidPowersaveModeError = 73,
leihen 0:2a179bd4cc02 191 BusyInHibernateModeError = 74,
leihen 0:2a179bd4cc02 192 BusyInScanModeError = 75,
leihen 0:2a179bd4cc02 193 Unknown = 0xFFFF
leihen 0:2a179bd4cc02 194 } ERR_t;
leihen 0:2a179bd4cc02 195
leihen 0:2a179bd4cc02 196 typedef enum {
leihen 0:2a179bd4cc02 197 WPA_PSK = 3,
leihen 0:2a179bd4cc02 198 WPA_PASSPHRASE = 4,
leihen 0:2a179bd4cc02 199 WPA2_PSK = 5,
leihen 0:2a179bd4cc02 200 WPA2_PASSPHRASE = 6,
leihen 0:2a179bd4cc02 201 WPA_OR_WPA2_PSK = 7,
leihen 0:2a179bd4cc02 202 WPA_OR_WPA2_PASSPHRASE = 8
leihen 0:2a179bd4cc02 203 } WPA_SECURITY_t;
leihen 0:2a179bd4cc02 204
leihen 0:2a179bd4cc02 205 typedef __packed struct {
leihen 0:2a179bd4cc02 206 char IE:1;
leihen 0:2a179bd4cc02 207 char res:3;
leihen 0:2a179bd4cc02 208 char Privacy:1;
leihen 0:2a179bd4cc02 209 char Preamble:1;
leihen 0:2a179bd4cc02 210 char WPA:1;
leihen 0:2a179bd4cc02 211 char WPA2:1;
leihen 0:2a179bd4cc02 212 } AP_CONFIG_t;
leihen 0:2a179bd4cc02 213
leihen 0:2a179bd4cc02 214 typedef enum {
leihen 0:2a179bd4cc02 215 FCC = 0,
leihen 0:2a179bd4cc02 216 IC,
leihen 0:2a179bd4cc02 217 ETSI,
leihen 0:2a179bd4cc02 218 SPAIN,
leihen 0:2a179bd4cc02 219 FRANCE,
leihen 0:2a179bd4cc02 220 JAPANA,
leihen 0:2a179bd4cc02 221 JAPANB
leihen 0:2a179bd4cc02 222 } DOMAIN_COUNTRY_CODE_t;
leihen 0:2a179bd4cc02 223
leihen 0:2a179bd4cc02 224 typedef enum {
leihen 0:2a179bd4cc02 225 HIBERNATE = 1, // Radio off
leihen 0:2a179bd4cc02 226 PSPOLL_AP_SUGGESTED_DTIM = 2,
leihen 0:2a179bd4cc02 227 PSPOLL_SELF_SET_DTIM = 3,
leihen 0:2a179bd4cc02 228 FULLY_POWERED = 4
leihen 0:2a179bd4cc02 229 } POWERSAVE_MODE_t;
leihen 0:2a179bd4cc02 230
leihen 0:2a179bd4cc02 231 typedef enum {
leihen 0:2a179bd4cc02 232 InvalidSocketHandle=254,
leihen 0:2a179bd4cc02 233 UnknownSocketType=255
leihen 0:2a179bd4cc02 234 } SOCKET_HANDLE_t;
leihen 0:2a179bd4cc02 235
leihen 0:2a179bd4cc02 236 typedef enum {
leihen 0:2a179bd4cc02 237 UDP=0,
leihen 0:2a179bd4cc02 238 TCP=1
leihen 0:2a179bd4cc02 239 } SOCKET_TYPE_t;
leihen 0:2a179bd4cc02 240
leihen 0:2a179bd4cc02 241
leihen 0:2a179bd4cc02 242
leihen 0:2a179bd4cc02 243 /** Class Wifi encapsulates communication and access to Wifi Plus Click module. */
leihen 0:2a179bd4cc02 244 /*!\copyright { Henry Leinen } */
leihen 0:2a179bd4cc02 245 class Wifi
leihen 0:2a179bd4cc02 246 {
leihen 0:2a179bd4cc02 247 public:
leihen 0:2a179bd4cc02 248 typedef enum {
leihen 0:2a179bd4cc02 249 Idle,
leihen 0:2a179bd4cc02 250 Header1_received,
leihen 0:2a179bd4cc02 251 Header2_received,
leihen 0:2a179bd4cc02 252 MessageType_low_received,
leihen 0:2a179bd4cc02 253 MessageType_high_received,
leihen 0:2a179bd4cc02 254 DataLen_low_received,
leihen 0:2a179bd4cc02 255 Data_receiving,
leihen 0:2a179bd4cc02 256 Awaiting_trailer
leihen 0:2a179bd4cc02 257 } RX_STATE_t;
leihen 0:2a179bd4cc02 258
leihen 0:2a179bd4cc02 259 protected:
leihen 0:2a179bd4cc02 260 Serial m_wifi;
leihen 0:2a179bd4cc02 261 DigitalOut m_reset;
leihen 0:2a179bd4cc02 262 char* m_buffer;
leihen 0:2a179bd4cc02 263
leihen 0:2a179bd4cc02 264 bool m_msgReceived;
leihen 0:2a179bd4cc02 265 RSP_MSG_t m_msgResponse;
leihen 0:2a179bd4cc02 266 short m_msgDataLen;
leihen 0:2a179bd4cc02 267 bool m_ackReceived;
leihen 0:2a179bd4cc02 268
leihen 0:2a179bd4cc02 269 // Event data
leihen 0:2a179bd4cc02 270 IPADDRESS_t m_ipAddress;
leihen 0:2a179bd4cc02 271 bool m_bWifiConnected;
leihen 0:2a179bd4cc02 272 CONN_ERROR_t m_WifiConnectionError;
leihen 0:2a179bd4cc02 273
leihen 0:2a179bd4cc02 274 ERR_t m_lastError;
leihen 0:2a179bd4cc02 275
leihen 0:2a179bd4cc02 276 bool m_bScanResultsReady;
leihen 0:2a179bd4cc02 277 char m_NumLastScanResults;
leihen 0:2a179bd4cc02 278
leihen 0:2a179bd4cc02 279 public:
leihen 0:2a179bd4cc02 280 static Wifi* _Wifi;
leihen 0:2a179bd4cc02 281 static Wifi* getInstance()
leihen 0:2a179bd4cc02 282 {
leihen 0:2a179bd4cc02 283 if (_Wifi==NULL) {
leihen 0:2a179bd4cc02 284 error("NOWIFI");
leihen 0:2a179bd4cc02 285 }
leihen 0:2a179bd4cc02 286 return _Wifi;
leihen 0:2a179bd4cc02 287 }
leihen 0:2a179bd4cc02 288
leihen 0:2a179bd4cc02 289 public:
leihen 0:2a179bd4cc02 290 Wifi(PinName tx, PinName rx, PinName rst);
leihen 0:2a179bd4cc02 291
leihen 0:2a179bd4cc02 292 bool AwaitScanResults(int timeout) {
leihen 0:2a179bd4cc02 293 Timer t;
leihen 0:2a179bd4cc02 294 t.start();
leihen 0:2a179bd4cc02 295 while(t.read() < timeout) {
leihen 0:2a179bd4cc02 296 if (m_bScanResultsReady) {
leihen 0:2a179bd4cc02 297 return true;
leihen 0:2a179bd4cc02 298 }
leihen 0:2a179bd4cc02 299 }
leihen 0:2a179bd4cc02 300 return false;
leihen 0:2a179bd4cc02 301 }
leihen 0:2a179bd4cc02 302
leihen 0:2a179bd4cc02 303 bool AwaitConnected(int timeout, ERR_t *err = NULL) {
leihen 0:2a179bd4cc02 304 Timer t;
leihen 0:2a179bd4cc02 305 t.start();
leihen 0:2a179bd4cc02 306 while(t.read() < timeout) {
leihen 0:2a179bd4cc02 307 if (m_bWifiConnected) {
leihen 0:2a179bd4cc02 308 return true;
leihen 0:2a179bd4cc02 309 }
leihen 0:2a179bd4cc02 310 wait(0.1);
leihen 0:2a179bd4cc02 311 }
leihen 0:2a179bd4cc02 312 if (err)
leihen 0:2a179bd4cc02 313 *err = m_lastError;
leihen 0:2a179bd4cc02 314 return false;
leihen 0:2a179bd4cc02 315 }
leihen 0:2a179bd4cc02 316
leihen 0:2a179bd4cc02 317 bool AwaitDisconnected(int timeout, ERR_t *err = NULL) {
leihen 0:2a179bd4cc02 318 Timer t;
leihen 0:2a179bd4cc02 319 t.start();
leihen 0:2a179bd4cc02 320 while(t.read() < timeout) {
leihen 0:2a179bd4cc02 321 if (!m_bWifiConnected) {
leihen 0:2a179bd4cc02 322 return true;
leihen 0:2a179bd4cc02 323 }
leihen 0:2a179bd4cc02 324 wait(0.1);
leihen 0:2a179bd4cc02 325 }
leihen 0:2a179bd4cc02 326 if (err)
leihen 0:2a179bd4cc02 327 *err = m_lastError;
leihen 0:2a179bd4cc02 328 return false;
leihen 0:2a179bd4cc02 329 }
leihen 0:2a179bd4cc02 330
leihen 0:2a179bd4cc02 331 void Reset();
leihen 0:2a179bd4cc02 332
leihen 0:2a179bd4cc02 333 /** Function to reset the Wifi Plus Click Device. PLEASE NOTE, it will loose all its current settings
leihen 0:2a179bd4cc02 334 * @returns true if successful or false otherwise
leihen 0:2a179bd4cc02 335 */
leihen 0:2a179bd4cc02 336 bool ResetMsg();
leihen 0:2a179bd4cc02 337 /** Function retrieves the software and radio version of the Wifi Plus Click Board.
leihen 0:2a179bd4cc02 338 * @param sw_ver_lo : receives the low WiComm Socket Version number
leihen 0:2a179bd4cc02 339 * @param sw_ver_hi : recevies the high WiComm Socket Version number
leihen 0:2a179bd4cc02 340 * @param rad_ver_lo: receives the low Radio version number
leihen 0:2a179bd4cc02 341 * @param rad_ver_hi: receives the high Radio version number
leihen 0:2a179bd4cc02 342 * @returns true if successful or false otherwise
leihen 0:2a179bd4cc02 343 */
leihen 0:2a179bd4cc02 344 bool GetVersionMsg(char &sw_ver_lo, char &sw_ver_hi, char &rad_ver_lo, char &rad_ver_hi);
leihen 0:2a179bd4cc02 345 /** Function will set a GPIO pin to a specific output level or will set it to input.
leihen 0:2a179bd4cc02 346 * The function will return the result of the operation.
leihen 0:2a179bd4cc02 347 * @param pin : Reference to the GPIO pin of interest
leihen 0:2a179bd4cc02 348 * @param operation: the operation to perform on the GPIO pin. Set to specific output level or read as input
leihen 0:2a179bd4cc02 349 * @param result : a reference to a variable which receives the actual status of the GPIO pin
leihen 0:2a179bd4cc02 350 */
leihen 0:2a179bd4cc02 351 bool GpioMsg(GPIO_IDX_t pin, GPIO_OP_t operation, GPIO_RES_t &result);
leihen 0:2a179bd4cc02 352
leihen 0:2a179bd4cc02 353 /** Function to set the IP address of the Wifi Plus Click device.
leihen 0:2a179bd4cc02 354 * @param bUseDHCP : set to true if DHCP shall be used, or set to false if you want to specify a static IP address
leihen 0:2a179bd4cc02 355 * @param IPAddress: pointer to an IP address.
leihen 0:2a179bd4cc02 356 * Please note that the IP adress will only be used if bUseDHCP is set to false
leihen 0:2a179bd4cc02 357 * @returns : true if successfull, or false otherwise. The function will not check for any asynchroneous result.
leihen 0:2a179bd4cc02 358 */
leihen 0:2a179bd4cc02 359 bool SetIpAddress(bool bUseDHCP, IPADDRESS_t *IPAddress);
leihen 0:2a179bd4cc02 360 /** Function to set the network mask of the Wifi Plus Click device.
leihen 0:2a179bd4cc02 361 * @param NetworkMask : the Network mask to use.
leihen 0:2a179bd4cc02 362 * @returns : true if successfull, or false otherwise.
leihen 0:2a179bd4cc02 363 */
leihen 0:2a179bd4cc02 364 bool SetSubnetMask(IPADDRESS_t *NetworkMask);
leihen 0:2a179bd4cc02 365 /** 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
leihen 0:2a179bd4cc02 366 * a gateway.
leihen 0:2a179bd4cc02 367 * @param IPAddress : Pointer to an IPADDRESS specifying the IP Address of the gateway to use.
leihen 0:2a179bd4cc02 368 * @returns : true if successfull, or false otherwise.
leihen 0:2a179bd4cc02 369 */
leihen 0:2a179bd4cc02 370 bool SetGatewayIpAddress(IPADDRESS_t *IPAddress);
leihen 0:2a179bd4cc02 371 /** Function to retrieve the current network status of the Wifi Plus Click device.
leihen 0:2a179bd4cc02 372 * @param MacAddress : pointer to an array of 6 Bytes to retrieve the MAC Address. Set to NULL if not required.
leihen 0:2a179bd4cc02 373 * @param IPAddress : pointer to an IPADDRESS_t structure which receives the IP address. Set to NULL if not required.
leihen 0:2a179bd4cc02 374 * @oaram NetworkMask : pointer to an IPADDRESS_t structure which receives the network mask. Set to NULL if not requried.
leihen 0:2a179bd4cc02 375 * @param GatewayAddress : pointer to an IPADDRESS_t structure which receives the gateway address. Set to NULL if no required.
leihen 0:2a179bd4cc02 376 * @param stat : will receive the actual status.
leihen 0:2a179bd4cc02 377 * @returns : true if successfull, or false otherwise.
leihen 0:2a179bd4cc02 378 */
leihen 0:2a179bd4cc02 379 bool GetNetworkStatus(char *MacAddress, IPADDRESS_t *IPAddress, IPADDRESS_t *NetworkMask, IPADDRESS_t *GatewayAddress, NET_STAT_t &stat);
leihen 0:2a179bd4cc02 380 /** Function to set the MAC Address of the device. This command should only be used during initialization
leihen 0:2a179bd4cc02 381 * @param MacAddress : the MAC address to use.
leihen 0:2a179bd4cc02 382 * @returns : true if successfull, or false otherwise.
leihen 0:2a179bd4cc02 383 */
leihen 0:2a179bd4cc02 384 bool SetMACAddress(char MacAddress[6]);
leihen 0:2a179bd4cc02 385 /** Function to set the address resolution time from 1 to 65535 seconds.
leihen 0:2a179bd4cc02 386 * @param ARPTime : either 0 to disable ARP or time in seconds.
leihen 0:2a179bd4cc02 387 * @returns : true if successfull, or false otherwise.
leihen 0:2a179bd4cc02 388 */
leihen 0:2a179bd4cc02 389 bool SetARPTime(unsigned short ARPTime);
leihen 0:2a179bd4cc02 390 /** Function to set the network mode for one of two available profiles.
leihen 0:2a179bd4cc02 391 * @param Profile : can be profile number one or 2
leihen 0:2a179bd4cc02 392 * @param NetMode : can be either INFRASTRUCTURE or ADHOC
leihen 0:2a179bd4cc02 393 * @returns : true if successfull, or false otherwise.
leihen 0:2a179bd4cc02 394 */
leihen 0:2a179bd4cc02 395 bool SetNetworkMode(char Profile, NETW_MODE_t NetMode);
leihen 0:2a179bd4cc02 396 /** Function to set the SSID for one of two profiles.
leihen 0:2a179bd4cc02 397 * @param Profile : can be profile number one or two.
leihen 0:2a179bd4cc02 398 * @param ssid : a string descibing the ssid.
leihen 0:2a179bd4cc02 399 * @returns : true if successfull, or false otherwise.
leihen 0:2a179bd4cc02 400 */
leihen 0:2a179bd4cc02 401 bool SetSSID(char Profile, const char* ssid);
leihen 0:2a179bd4cc02 402 /** Function switches device into one of 3 power saving modes, or sets it into awake mode.
leihen 0:2a179bd4cc02 403 * @param pwrsave : specifies which powersaving mode to set.
leihen 0:2a179bd4cc02 404 * @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.
leihen 0:2a179bd4cc02 405 * @returns : true if successfull, or false otherwise
leihen 0:2a179bd4cc02 406 */
leihen 0:2a179bd4cc02 407 bool SetPowerSaveMode(POWERSAVE_MODE_t pwrsave, short DTIM_Listen);
leihen 0:2a179bd4cc02 408 /** Function to set the regional domain for all CPs.
leihen 0:2a179bd4cc02 409 * @param dcode : domain country code valid for all CPs.
leihen 0:2a179bd4cc02 410 * @returns : true if successfull, or false otherwise.
leihen 0:2a179bd4cc02 411 */
leihen 0:2a179bd4cc02 412 bool SetRegionalDomain(DOMAIN_COUNTRY_CODE_t dcode);
leihen 0:2a179bd4cc02 413 /** Function to set the channels on which to scan.
leihen 0:2a179bd4cc02 414 * @param numListItems : the number of channels given in the list.
leihen 0:2a179bd4cc02 415 * @param ListItems : array consisting of numListItems channel numbers.
leihen 0:2a179bd4cc02 416 * @returns : true if successfull, or false otherwise
leihen 0:2a179bd4cc02 417 */
leihen 0:2a179bd4cc02 418 bool SetChannelList(char numListItems, char ListItems[]);
leihen 0:2a179bd4cc02 419 /** Function to specify the connection managaer retry count. There are separate values for infrastructure and ad hoc mode.
leihen 0:2a179bd4cc02 420 * Please note that a number of 0 means no retries and 255 means retry forever.
leihen 0:2a179bd4cc02 421 * @param infrastructureRetryCount : number of retries in infrastructure mode
leihen 0:2a179bd4cc02 422 * @param adhocRetryCount : number of retries in ad-hoc mode.
leihen 0:2a179bd4cc02 423 * @returns : true if successfull, or false otherwise
leihen 0:2a179bd4cc02 424 */
leihen 0:2a179bd4cc02 425 bool SetRetryCount(char infrastructureRetryCount=255, char adhocRetryCount=5);
leihen 0:2a179bd4cc02 426 /** Function to set the Security mode to OPN
leihen 0:2a179bd4cc02 427 * @param Profile : can be profile number one or two.
leihen 0:2a179bd4cc02 428 * @returns : true if successfull, or false otherwise.
leihen 0:2a179bd4cc02 429 */
leihen 0:2a179bd4cc02 430 bool SetSecurityOpen(char Profile);
leihen 0:2a179bd4cc02 431 /** Function to set the WEP40 security mode.
leihen 0:2a179bd4cc02 432 * @param Profile : can be profile number one or two.
leihen 0:2a179bd4cc02 433 * @param bShareKey : set to true for shared key, or false for open key
leihen 0:2a179bd4cc02 434 * @param DefaultWEPKeyIdx : the index (0-3) into the key array
leihen 0:2a179bd4cc02 435 * @param SecurityKeys : array or 4 security keys with 5 bytes each
leihen 0:2a179bd4cc02 436 * @returns : true if successfull, or false otherwise
leihen 0:2a179bd4cc02 437 */
leihen 0:2a179bd4cc02 438 bool SetSecurityWEP40(char Profile, bool bSharedKey, char DefaultWEPKeyIdx, char SecurityKeys[20]);
leihen 0:2a179bd4cc02 439 /** Function to set the WEP104 security mode.
leihen 0:2a179bd4cc02 440 * @param Profile : can be profile number one or two.
leihen 0:2a179bd4cc02 441 * @param bShareKey : set to true for shared key, or false for open key
leihen 0:2a179bd4cc02 442 * @param DefaultWEPKeyIdx : the index (0-3) into the key array
leihen 0:2a179bd4cc02 443 * @param SecurityKeys : array or 4 security keys with 13 bytes each
leihen 0:2a179bd4cc02 444 * @returns : true if successfull, or false otherwise
leihen 0:2a179bd4cc02 445 */
leihen 0:2a179bd4cc02 446 bool SetSecurityWEP104(char Profile, bool bSharedKey, char DefaultWEPKeyIdx, char SecurityKeys[52]);
leihen 0:2a179bd4cc02 447 /** Function to set the WPA security mode.
leihen 0:2a179bd4cc02 448 * @param Profile : can be profile number one or two.
leihen 0:2a179bd4cc02 449 * @param sec : can be one of the define security types.
leihen 0:2a179bd4cc02 450 * @param len : length of the security key or passphrase.
leihen 0:2a179bd4cc02 451 * @param secKeyOrPSK : security key or passphrase.
leihen 0:2a179bd4cc02 452 * @returns : true if successfull, or false otherwise.
leihen 0:2a179bd4cc02 453 */
leihen 0:2a179bd4cc02 454 bool SetSecurityWPA(char Profile, WPA_SECURITY_t sec, int len, const char* secKeyOrPSK);
leihen 0:2a179bd4cc02 455 /** Function to retrieve the WPA Key from the Wifi Plus Click device for a selected profile.
leihen 0:2a179bd4cc02 456 * @param Profile : can be profile number one or two.
leihen 0:2a179bd4cc02 457 * @param Key : will receive the key.
leihen 0:2a179bd4cc02 458 * @returns : true if successfull, or false otherwise.
leihen 0:2a179bd4cc02 459 */
leihen 0:2a179bd4cc02 460 bool GetWPAKey(char Profile, char Key[32]);
leihen 0:2a179bd4cc02 461 /** Function to initiate the scan on one or both Profiles using the settings downloaded to the Wifi Plus Click.
leihen 0:2a179bd4cc02 462 * Please NOTE that the device will only accept the REBOOT message while a scan is active. A scan can only be
leihen 0:2a179bd4cc02 463 * started if the device is not connected.
leihen 0:2a179bd4cc02 464 * @param Profile : can be profile number one or two.
leihen 0:2a179bd4cc02 465 * @returns : true if successfull, or false otherwise.
leihen 0:2a179bd4cc02 466 */
leihen 0:2a179bd4cc02 467 bool ScanStartMsg(char Profile);
leihen 0:2a179bd4cc02 468 /** Function to retrieve a specific scan result. Will only work after scan has been started and finished.
leihen 0:2a179bd4cc02 469 * @param index : specify the result item to return. When this index is too high the function returns with a false return value.
leihen 0:2a179bd4cc02 470 * @param ssid : will receive the SSID of the item.
leihen 0:2a179bd4cc02 471 * @param apCfg : will receive the access points configuration.
leihen 0:2a179bd4cc02 472 * @param beaconInterval : will receive the beacon interval time.
leihen 0:2a179bd4cc02 473 * @param ATIMWindow : will receive the ATIM Window.
leihen 0:2a179bd4cc02 474 * @param RSSI : will receive the RSSI level.
leihen 0:2a179bd4cc02 475 * @param bssType : will receive information about the BSS type (INFRASTRUCTURE oR ADHOC).
leihen 0:2a179bd4cc02 476 * @param channelNo : will receive on which channel the AP transmits.
leihen 0:2a179bd4cc02 477 * @returns : true if successfull, false otherwise.
leihen 0:2a179bd4cc02 478 */
leihen 0:2a179bd4cc02 479 bool ScanGetResults(char index, char ssid[32], AP_CONFIG_t &apCfg, short &beaconInterval, short &ATIMWindow, char &RSSI, NETW_MODE_t &bssType, char &channelNo);
leihen 0:2a179bd4cc02 480
leihen 0:2a179bd4cc02 481 /** Function to connect using the specified profile and the settings previously downloaded to the device. Please Note that the connection
leihen 0:2a179bd4cc02 482 * state will be transmitted asynchroneously be the device. You need to monitor the connected state.
leihen 0:2a179bd4cc02 483 * @param Profile : can be profile number one or two.
leihen 0:2a179bd4cc02 484 * @returns : true if successfully submitted, or false otherwise.
leihen 0:2a179bd4cc02 485 */
leihen 0:2a179bd4cc02 486 bool Connect(char Profile);
leihen 0:2a179bd4cc02 487 /** Function to disconnect from any connected AP.
leihen 0:2a179bd4cc02 488 * @returns : true if successful, or false otherwise.
leihen 0:2a179bd4cc02 489 */
leihen 0:2a179bd4cc02 490 bool Disconnect();
leihen 0:2a179bd4cc02 491
leihen 0:2a179bd4cc02 492
leihen 0:2a179bd4cc02 493 /** @name Socket Functions
leihen 0:2a179bd4cc02 494 In the following section, all socket relevant functions are contained.
leihen 0:2a179bd4cc02 495 */
leihen 0:2a179bd4cc02 496 ///@{
leihen 0:2a179bd4cc02 497
leihen 0:2a179bd4cc02 498 /** Function to allocate the internal memory of the device and the number of sockets (which in total is limited to 8).
leihen 0:2a179bd4cc02 499 * @param nTCPSvr : Number of server sockets to allocate.
leihen 0:2a179bd4cc02 500 * @param nTCPClnt: Number of client sockets to allocate.
leihen 0:2a179bd4cc02 501 * @param TCPSvrRxBuf : Size (in bytes) to allocate for the receive buffer for each server socket.
leihen 0:2a179bd4cc02 502 * @param TCPSvrTxBuf : Size (in bytes) to allocate for the transmit buffer for each server socket.
leihen 0:2a179bd4cc02 503 * @param TCPClntRxBuf: Size (in bytes) to allocate for the receive buffer for each client socket.
leihen 0:2a179bd4cc02 504 * @param TCPClntTxBuf: Size (in bytes) to allocate for the transmit buffer for each client socket.
leihen 0:2a179bd4cc02 505 * @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
leihen 0:2a179bd4cc02 506 * 8 sockets is exceeded.
leihen 0:2a179bd4cc02 507 */
leihen 0:2a179bd4cc02 508 bool SocketAllocate(char nTCPSvr, char nTCPClnt, unsigned short TCPSvrRxBuf, unsigned short TCPSvrTxBuf, unsigned short TCPClntRxBuf, unsigned short TCPClntTxBuf);
leihen 0:2a179bd4cc02 509
leihen 0:2a179bd4cc02 510 /** Function to create a new socket object of the given type.
leihen 0:2a179bd4cc02 511 * @param sockType : Specifies the type of socket to create (UDP or TCP).
leihen 0:2a179bd4cc02 512 * @returns : Either a valid socket handle or InvalidSocketHandle or UnknownSocketType.
leihen 0:2a179bd4cc02 513 */
leihen 0:2a179bd4cc02 514 SOCKET_HANDLE_t SocketCreate( SOCKET_TYPE_t sockType );
leihen 0:2a179bd4cc02 515 /** Function to close a previously created socket.
leihen 0:2a179bd4cc02 516 * @param hSock: Valid socket handle, which has been created by a previous call to SocketCreate.
leihen 0:2a179bd4cc02 517 * @returns : true if successful, or false if an error occured
leihen 0:2a179bd4cc02 518 */
leihen 0:2a179bd4cc02 519 bool SocketClose(SOCKET_HANDLE_t hSock);
leihen 0:2a179bd4cc02 520 /** Function to bind to a specific port using the given socket.
leihen 0:2a179bd4cc02 521 * @param hSock : Valid socket handle.
leihen 0:2a179bd4cc02 522 * @param Port : local port to bind to.
leihen 0:2a179bd4cc02 523 * @returns : true if successfull, or false otherwise.
leihen 0:2a179bd4cc02 524 */
leihen 0:2a179bd4cc02 525 bool SocketBind(SOCKET_HANDLE_t hSock, int Port);
leihen 0:2a179bd4cc02 526 /** Function to prepare the a number of sockets for accepting remote connections
leihen 0:2a179bd4cc02 527 * @param hSock : Valid socket handle.
leihen 0:2a179bd4cc02 528 * @param Backlog : Number of sockets to set in listening mode, will receive the number of new unassigned backlog count
leihen 0:2a179bd4cc02 529 * @return : true if successfull, or false otherwise.
leihen 0:2a179bd4cc02 530 */
leihen 0:2a179bd4cc02 531 bool SocketListen(SOCKET_HANDLE_t hSock, int &Backlog);
leihen 0:2a179bd4cc02 532 /** Function to accept a new remote connection. Will work asynchroneously, means if no new connection was accepted, will return immediately.
leihen 0:2a179bd4cc02 533 * @param hSock : Valid socket handle.
leihen 0:2a179bd4cc02 534 * @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.
leihen 0:2a179bd4cc02 535 * @param remotePort : receives the remote port of the remote connection.
leihen 0:2a179bd4cc02 536 * @param remoteAddress : receives the remote address of the remote connection.
leihen 0:2a179bd4cc02 537 * @returns : true if successfull, or false otherwise. PLEASE NOTE that even if no connection was made, the return result may be true.
leihen 0:2a179bd4cc02 538 */
leihen 0:2a179bd4cc02 539 bool SocketAccept(SOCKET_HANDLE_t hSock, SOCKET_HANDLE_t &client, int &remotePort, IPADDRESS_t &remoteAddress);
leihen 0:2a179bd4cc02 540 /** Function to connect the socket to a remote socket specified by IpAddress and Port.
leihen 0:2a179bd4cc02 541 * @param hSock : Valid socket handle.
leihen 0:2a179bd4cc02 542 * @param IpAddress : valid IP Address of the remote host to connect with.
leihen 0:2a179bd4cc02 543 * @param Port : Port of the remote host to connect with.
leihen 0:2a179bd4cc02 544 * @returns : true if a connection has been made successfully or false otherwise.
leihen 0:2a179bd4cc02 545 */
leihen 0:2a179bd4cc02 546 SOCKET_HANDLE_t SocketConnect(SOCKET_HANDLE_t hSock, IPADDRESS_t *IpAddress, int Port);
leihen 0:2a179bd4cc02 547 /** Function to send data on the connected socket
leihen 0:2a179bd4cc02 548 * @param hSock : Valid socket handle.
leihen 0:2a179bd4cc02 549 * @param data : Pointer to a buffer containing the data to send.
leihen 0:2a179bd4cc02 550 * @param length : Number of bytes in the buffer to send.
leihen 0:2a179bd4cc02 551 * @returns : Number of bytes actually sent over the connection.
leihen 0:2a179bd4cc02 552 */
leihen 0:2a179bd4cc02 553 int SocketSend(SOCKET_HANDLE_t hSock, char* data, int length);
leihen 0:2a179bd4cc02 554 /** Function to receive data from the connected socket.
leihen 0:2a179bd4cc02 555 * @param hSock : Valid socket handle of a socket which is already connected.
leihen 0:2a179bd4cc02 556 * @param data : Pointer to a valid buffer which shall receive the data.
leihen 0:2a179bd4cc02 557 * @param length : Maximum number of bytes which can be received and stored in the provided buffer.
leihen 0:2a179bd4cc02 558 * @returns : Number of bytes actually received over the connection or -1 if a fault occured.
leihen 0:2a179bd4cc02 559 */
leihen 0:2a179bd4cc02 560 int SocketRecv(SOCKET_HANDLE_t hSock, char* data, int length);
leihen 0:2a179bd4cc02 561 /** Function to send data over a connectionless socket.
leihen 0:2a179bd4cc02 562 * @param hSock : Valid socket handle.
leihen 0:2a179bd4cc02 563 * @param remoteAddress : The ip address of the remote destination to send the data to.
leihen 0:2a179bd4cc02 564 * @param remotePort : The port of the remote destination to send the data to.
leihen 0:2a179bd4cc02 565 * @param data : Pointer to a buffer which contains the data to send.
leihen 0:2a179bd4cc02 566 * @param length : The number of bytes to sent to the specified address.
leihen 0:2a179bd4cc02 567 * @returns : Number of bytes actually sent or -1 if a fault occured.
leihen 0:2a179bd4cc02 568 */
leihen 0:2a179bd4cc02 569 int SocketSendTo(SOCKET_HANDLE_t hSock, IPADDRESS_t* remoteAddress, int remotePort, char *data, int length);
leihen 0:2a179bd4cc02 570 /** Function to receive data over a connectionless socket.
leihen 0:2a179bd4cc02 571 * @param hSock : Valid socket handle.
leihen 0:2a179bd4cc02 572 * @param remoteAddress : The ip address of the remote origin from where to receive the data.
leihen 0:2a179bd4cc02 573 * @param remotePort : Point to receive the port of the remote origin from where to receive the data or NULL if not needed.
leihen 0:2a179bd4cc02 574 * @param data : Pointer to a buffer which will receive the data.
leihen 0:2a179bd4cc02 575 * @param length : Number of bytes to receive and which fit into the provided buffer.
leihen 0:2a179bd4cc02 576 * @returns : Number of bytes actually received or -1 if a fault occured.
leihen 0:2a179bd4cc02 577 */
leihen 0:2a179bd4cc02 578 int SocketRecvFrom(SOCKET_HANDLE_t hSock, IPADDRESS_t *remoteAddress, int *remotePort, char *data, int length);
leihen 0:2a179bd4cc02 579
leihen 0:2a179bd4cc02 580 ///@}
leihen 0:2a179bd4cc02 581
leihen 0:2a179bd4cc02 582
leihen 0:2a179bd4cc02 583 /** This is the main cyclic function, which needs to be called as often as possible.
leihen 0:2a179bd4cc02 584 * The function will check if a new message has been received and will decode and dispatch it.
leihen 0:2a179bd4cc02 585 */
leihen 0:2a179bd4cc02 586 void Poll();
leihen 0:2a179bd4cc02 587
leihen 0:2a179bd4cc02 588
leihen 0:2a179bd4cc02 589 int gethostbyname(const char* host, IPADDRESS_t *IpAddress);
leihen 0:2a179bd4cc02 590 int convert(const char *hostip, IPADDRESS_t *IpAddress);
leihen 0:2a179bd4cc02 591 protected:
leihen 0:2a179bd4cc02 592 void SendCommand(CMD_MSG_t cmd, int msgLen1, char *pData1, int msgLen2 = 0, char* pData2 = NULL);
leihen 0:2a179bd4cc02 593 void rx_int();
leihen 0:2a179bd4cc02 594
leihen 0:2a179bd4cc02 595 void SubmitResponse(RSP_MSG_t rsp, int msgLen);
leihen 0:2a179bd4cc02 596 bool WaitMessage(RSP_MSG_t msg, int timeout);
leihen 0:2a179bd4cc02 597 bool WaitEvent(EVT_MSG_t evt, int timeout);
leihen 0:2a179bd4cc02 598 bool WaitAck(int timeout);
leihen 0:2a179bd4cc02 599 };
leihen 0:2a179bd4cc02 600
leihen 0:2a179bd4cc02 601 #endif //__WIFI_H__