Update revision to use TI's mqtt and Freertos.

Dependencies:   mbed client server

Fork of cc3100_Test_mqtt_CM3 by David Fletcher

Committer:
dflet
Date:
Thu Sep 03 14:02:37 2015 +0000
Revision:
3:a8c249046181
SPI Mode change 1 to 0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dflet 3:a8c249046181 1 /*
dflet 3:a8c249046181 2 * - CC31xx/CC32xx Host Driver Implementation
dflet 3:a8c249046181 3 *
dflet 3:a8c249046181 4 * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
dflet 3:a8c249046181 5 *
dflet 3:a8c249046181 6 *
dflet 3:a8c249046181 7 * Redistribution and use in source and binary forms, with or without
dflet 3:a8c249046181 8 * modification, are permitted provided that the following conditions
dflet 3:a8c249046181 9 * are met:
dflet 3:a8c249046181 10 *
dflet 3:a8c249046181 11 * Redistributions of source code must retain the above copyright
dflet 3:a8c249046181 12 * notice, this list of conditions and the following disclaimer.
dflet 3:a8c249046181 13 *
dflet 3:a8c249046181 14 * Redistributions in binary form must reproduce the above copyright
dflet 3:a8c249046181 15 * notice, this list of conditions and the following disclaimer in the
dflet 3:a8c249046181 16 * documentation and/or other materials provided with the
dflet 3:a8c249046181 17 * distribution.
dflet 3:a8c249046181 18 *
dflet 3:a8c249046181 19 * Neither the name of Texas Instruments Incorporated nor the names of
dflet 3:a8c249046181 20 * its contributors may be used to endorse or promote products derived
dflet 3:a8c249046181 21 * from this software without specific prior written permission.
dflet 3:a8c249046181 22 *
dflet 3:a8c249046181 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
dflet 3:a8c249046181 24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
dflet 3:a8c249046181 25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
dflet 3:a8c249046181 26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
dflet 3:a8c249046181 27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
dflet 3:a8c249046181 28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
dflet 3:a8c249046181 29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
dflet 3:a8c249046181 30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
dflet 3:a8c249046181 31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
dflet 3:a8c249046181 32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
dflet 3:a8c249046181 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dflet 3:a8c249046181 34 *
dflet 3:a8c249046181 35 */
dflet 3:a8c249046181 36
dflet 3:a8c249046181 37 #include "simplelink_V2/cc3100_simplelink.h"
dflet 3:a8c249046181 38
dflet 3:a8c249046181 39 #include "simplelink_V2/cc3100.h"
dflet 3:a8c249046181 40 #include "simplelink_V2/cc3100_driver.h"
dflet 3:a8c249046181 41 #include "simplelink_V2/G_functions/fPtr_func.h"
dflet 3:a8c249046181 42 #include "simplelink_V2/cc3100_nonos.h"
dflet 3:a8c249046181 43 #include "cli_uart.h"
dflet 3:a8c249046181 44 #include "myBoardInit.h"
dflet 3:a8c249046181 45
dflet 3:a8c249046181 46 #include "cc3100_trace.h"
dflet 3:a8c249046181 47
dflet 3:a8c249046181 48 using namespace mbed_cc3100;
dflet 3:a8c249046181 49
dflet 3:a8c249046181 50 #if (THIS_BOARD == MBED_BOARD_LPC1768)
dflet 3:a8c249046181 51 cc3100 _cc3100_(p16, p17, p9, p10, p8, SPI(p5, p6, p7));//LPC1768 irq, nHib, cs, mosi, miso, sck
dflet 3:a8c249046181 52 #elif (THIS_BOARD == LPCXpresso4337)
dflet 3:a8c249046181 53 cc3100 _cc3100_(P2_12, P2_9, P2_2, P3_5, P1_2, SPI(P1_4, P1_3, PF_4));//LPCXpresso4337 irq, nHib, cs, mosi, miso, sck
dflet 3:a8c249046181 54 #endif
dflet 3:a8c249046181 55
dflet 3:a8c249046181 56 #ifdef __cplusplus
dflet 3:a8c249046181 57 extern "C" {
dflet 3:a8c249046181 58 #endif
dflet 3:a8c249046181 59
dflet 3:a8c249046181 60 #define PRINT_BUF_LEN 128
dflet 3:a8c249046181 61 extern int8_t print_buf[PRINT_BUF_LEN];
dflet 3:a8c249046181 62
dflet 3:a8c249046181 63 /* General Events handling*/
dflet 3:a8c249046181 64 #if defined (EXT_LIB_REGISTERED_GENERAL_EVENTS)
dflet 3:a8c249046181 65
dflet 3:a8c249046181 66 typedef _SlEventPropogationStatus_e (*general_callback) (SlDeviceEvent_t *);
dflet 3:a8c249046181 67
dflet 3:a8c249046181 68 static const general_callback general_callbacks[] =
dflet 3:a8c249046181 69 {
dflet 3:a8c249046181 70 #ifdef SlExtLib1GeneralEventHandler
dflet 3:a8c249046181 71 SlExtLib1GeneralEventHandler,
dflet 3:a8c249046181 72 #endif
dflet 3:a8c249046181 73
dflet 3:a8c249046181 74 #ifdef SlExtLib2GeneralEventHandler
dflet 3:a8c249046181 75 SlExtLib2GeneralEventHandler,
dflet 3:a8c249046181 76 #endif
dflet 3:a8c249046181 77
dflet 3:a8c249046181 78 #ifdef SlExtLib3GeneralEventHandler
dflet 3:a8c249046181 79 SlExtLib3GeneralEventHandler,
dflet 3:a8c249046181 80 #endif
dflet 3:a8c249046181 81
dflet 3:a8c249046181 82 #ifdef SlExtLib4GeneralEventHandler
dflet 3:a8c249046181 83 SlExtLib4GeneralEventHandler,
dflet 3:a8c249046181 84 #endif
dflet 3:a8c249046181 85
dflet 3:a8c249046181 86 #ifdef SlExtLib5GeneralEventHandler
dflet 3:a8c249046181 87 SlExtLib5GeneralEventHandler,
dflet 3:a8c249046181 88 #endif
dflet 3:a8c249046181 89 };
dflet 3:a8c249046181 90
dflet 3:a8c249046181 91 #undef _SlDrvHandleGeneralEvents
dflet 3:a8c249046181 92
dflet 3:a8c249046181 93 /********************************************************************
dflet 3:a8c249046181 94 _SlDrvHandleGeneralEvents
dflet 3:a8c249046181 95 Iterates through all the general(device) event handlers which are
dflet 3:a8c249046181 96 registered by the external libs/user application.
dflet 3:a8c249046181 97 *********************************************************************/
dflet 3:a8c249046181 98 void _SlDrvHandleGeneralEvents(SlDeviceEvent_t *slGeneralEvent)
dflet 3:a8c249046181 99 {
dflet 3:a8c249046181 100 uint8_t i;
dflet 3:a8c249046181 101
dflet 3:a8c249046181 102 /* Iterate over all the extenal libs handlers */
dflet 3:a8c249046181 103 for ( i = 0 ; i < sizeof(general_callbacks)/sizeof(general_callbacks[0]) ; i++ )
dflet 3:a8c249046181 104 {
dflet 3:a8c249046181 105 if (EVENT_PROPAGATION_BLOCK == general_callbacks[i](slGeneralEvent) )
dflet 3:a8c249046181 106 {
dflet 3:a8c249046181 107 /* exit immediately and do not call the user specific handler as well */
dflet 3:a8c249046181 108 return;
dflet 3:a8c249046181 109 }
dflet 3:a8c249046181 110 }
dflet 3:a8c249046181 111
dflet 3:a8c249046181 112 /* At last call the Application specific handler if registered */
dflet 3:a8c249046181 113 #ifdef sl_GeneralEvtHdlr
dflet 3:a8c249046181 114 sl_GeneralEvtHdlr(slGeneralEvent);
dflet 3:a8c249046181 115 #endif
dflet 3:a8c249046181 116
dflet 3:a8c249046181 117 }
dflet 3:a8c249046181 118 #endif
dflet 3:a8c249046181 119
dflet 3:a8c249046181 120
dflet 3:a8c249046181 121
dflet 3:a8c249046181 122 /* WLAN Events handling*/
dflet 3:a8c249046181 123
dflet 3:a8c249046181 124 #if defined (EXT_LIB_REGISTERED_WLAN_EVENTS)
dflet 3:a8c249046181 125
dflet 3:a8c249046181 126 typedef _SlEventPropogationStatus_e (*wlan_callback) (SlWlanEvent_t *);
dflet 3:a8c249046181 127
dflet 3:a8c249046181 128 static wlan_callback wlan_callbacks[] =
dflet 3:a8c249046181 129 {
dflet 3:a8c249046181 130 #ifdef SlExtLib1WlanEventHandler
dflet 3:a8c249046181 131 SlExtLib1WlanEventHandler,
dflet 3:a8c249046181 132 #endif
dflet 3:a8c249046181 133
dflet 3:a8c249046181 134 #ifdef SlExtLib2WlanEventHandler
dflet 3:a8c249046181 135 SlExtLib2WlanEventHandler,
dflet 3:a8c249046181 136 #endif
dflet 3:a8c249046181 137
dflet 3:a8c249046181 138 #ifdef SlExtLib3WlanEventHandler
dflet 3:a8c249046181 139 SlExtLib3WlanEventHandler,
dflet 3:a8c249046181 140 #endif
dflet 3:a8c249046181 141
dflet 3:a8c249046181 142 #ifdef SlExtLib4WlanEventHandler
dflet 3:a8c249046181 143 SlExtLib4WlanEventHandler,
dflet 3:a8c249046181 144 #endif
dflet 3:a8c249046181 145
dflet 3:a8c249046181 146 #ifdef SlExtLib5WlanEventHandler
dflet 3:a8c249046181 147 SlExtLib5WlanEventHandler,
dflet 3:a8c249046181 148 #endif
dflet 3:a8c249046181 149 };
dflet 3:a8c249046181 150
dflet 3:a8c249046181 151 #undef _SlDrvHandleWlanEvents
dflet 3:a8c249046181 152
dflet 3:a8c249046181 153 /***********************************************************
dflet 3:a8c249046181 154 _SlDrvHandleWlanEvents
dflet 3:a8c249046181 155 Iterates through all the wlan event handlers which are
dflet 3:a8c249046181 156 registered by the external libs/user application.
dflet 3:a8c249046181 157 ************************************************************/
dflet 3:a8c249046181 158 void _SlDrvHandleWlanEvents(SlWlanEvent_t *slWlanEvent)
dflet 3:a8c249046181 159 {
dflet 3:a8c249046181 160 uint8_t i;
dflet 3:a8c249046181 161
dflet 3:a8c249046181 162 /* Iterate over all the extenal libs handlers */
dflet 3:a8c249046181 163 for ( i = 0 ; i < sizeof(wlan_callbacks)/sizeof(wlan_callbacks[0]) ; i++ )
dflet 3:a8c249046181 164 {
dflet 3:a8c249046181 165 if ( EVENT_PROPAGATION_BLOCK == wlan_callbacks[i](slWlanEvent) )
dflet 3:a8c249046181 166 {
dflet 3:a8c249046181 167 /* exit immediately and do not call the user specific handler as well */
dflet 3:a8c249046181 168 return;
dflet 3:a8c249046181 169 }
dflet 3:a8c249046181 170 }
dflet 3:a8c249046181 171
dflet 3:a8c249046181 172 /* At last call the Application specific handler if registered */
dflet 3:a8c249046181 173 #ifdef sl_WlanEvtHdlr
dflet 3:a8c249046181 174 sl_WlanEvtHdlr(slWlanEvent);
dflet 3:a8c249046181 175 #endif
dflet 3:a8c249046181 176
dflet 3:a8c249046181 177 }
dflet 3:a8c249046181 178 #endif
dflet 3:a8c249046181 179
dflet 3:a8c249046181 180
dflet 3:a8c249046181 181 /* NetApp Events handling */
dflet 3:a8c249046181 182 #if defined (EXT_LIB_REGISTERED_NETAPP_EVENTS)
dflet 3:a8c249046181 183
dflet 3:a8c249046181 184 typedef _SlEventPropogationStatus_e (*netApp_callback) (SlNetAppEvent_t *);
dflet 3:a8c249046181 185
dflet 3:a8c249046181 186 static const netApp_callback netApp_callbacks[] =
dflet 3:a8c249046181 187 {
dflet 3:a8c249046181 188 #ifdef SlExtLib1NetAppEventHandler
dflet 3:a8c249046181 189 SlExtLib1NetAppEventHandler,
dflet 3:a8c249046181 190 #endif
dflet 3:a8c249046181 191
dflet 3:a8c249046181 192 #ifdef SlExtLib2NetAppEventHandler
dflet 3:a8c249046181 193 SlExtLib2NetAppEventHandler,
dflet 3:a8c249046181 194 #endif
dflet 3:a8c249046181 195
dflet 3:a8c249046181 196 #ifdef SlExtLib3NetAppEventHandler
dflet 3:a8c249046181 197 SlExtLib3NetAppEventHandler,
dflet 3:a8c249046181 198 #endif
dflet 3:a8c249046181 199
dflet 3:a8c249046181 200 #ifdef SlExtLib4NetAppEventHandler
dflet 3:a8c249046181 201 SlExtLib4NetAppEventHandler,
dflet 3:a8c249046181 202 #endif
dflet 3:a8c249046181 203
dflet 3:a8c249046181 204 #ifdef SlExtLib5NetAppEventHandler
dflet 3:a8c249046181 205 SlExtLib5NetAppEventHandler,
dflet 3:a8c249046181 206 #endif
dflet 3:a8c249046181 207 };
dflet 3:a8c249046181 208
dflet 3:a8c249046181 209 #undef _SlDrvHandleNetAppEvents
dflet 3:a8c249046181 210
dflet 3:a8c249046181 211 /************************************************************
dflet 3:a8c249046181 212 _SlDrvHandleNetAppEvents
dflet 3:a8c249046181 213 Iterates through all the net app event handlers which are
dflet 3:a8c249046181 214 registered by the external libs/user application.
dflet 3:a8c249046181 215 ************************************************************/
dflet 3:a8c249046181 216 void _SlDrvHandleNetAppEvents(SlNetAppEvent_t *slNetAppEvent)
dflet 3:a8c249046181 217 {
dflet 3:a8c249046181 218 uint8_t i;
dflet 3:a8c249046181 219
dflet 3:a8c249046181 220 /* Iterate over all the extenal libs handlers */
dflet 3:a8c249046181 221 for ( i = 0 ; i < sizeof(netApp_callbacks)/sizeof(netApp_callbacks[0]) ; i++ )
dflet 3:a8c249046181 222 {
dflet 3:a8c249046181 223 if (EVENT_PROPAGATION_BLOCK == netApp_callbacks[i](slNetAppEvent) )
dflet 3:a8c249046181 224 {
dflet 3:a8c249046181 225 /* exit immediately and do not call the user specific handler as well */
dflet 3:a8c249046181 226 return;
dflet 3:a8c249046181 227 }
dflet 3:a8c249046181 228 }
dflet 3:a8c249046181 229
dflet 3:a8c249046181 230 /* At last call the Application specific handler if registered */
dflet 3:a8c249046181 231 #ifdef sl_NetAppEvtHdlr
dflet 3:a8c249046181 232 sl_NetAppEvtHdlr(slNetAppEvent);
dflet 3:a8c249046181 233 #endif
dflet 3:a8c249046181 234
dflet 3:a8c249046181 235 }
dflet 3:a8c249046181 236 #endif
dflet 3:a8c249046181 237
dflet 3:a8c249046181 238
dflet 3:a8c249046181 239 /* Http Server Events handling */
dflet 3:a8c249046181 240 #if defined (EXT_LIB_REGISTERED_HTTP_SERVER_EVENTS)
dflet 3:a8c249046181 241
dflet 3:a8c249046181 242 typedef _SlEventPropogationStatus_e (*httpServer_callback) (SlHttpServerEvent_t*, SlHttpServerResponse_t*);
dflet 3:a8c249046181 243
dflet 3:a8c249046181 244 static const httpServer_callback httpServer_callbacks[] =
dflet 3:a8c249046181 245 {
dflet 3:a8c249046181 246 #ifdef SlExtLib1HttpServerEventHandler
dflet 3:a8c249046181 247 SlExtLib1HttpServerEventHandler,
dflet 3:a8c249046181 248 #endif
dflet 3:a8c249046181 249
dflet 3:a8c249046181 250 #ifdef SlExtLib2HttpServerEventHandler
dflet 3:a8c249046181 251 SlExtLib2HttpServerEventHandler,
dflet 3:a8c249046181 252 #endif
dflet 3:a8c249046181 253
dflet 3:a8c249046181 254 #ifdef SlExtLib3HttpServerEventHandler
dflet 3:a8c249046181 255 SlExtLib3HttpServerEventHandler,
dflet 3:a8c249046181 256 #endif
dflet 3:a8c249046181 257
dflet 3:a8c249046181 258 #ifdef SlExtLib4HttpServerEventHandler
dflet 3:a8c249046181 259 SlExtLib4HttpServerEventHandler,
dflet 3:a8c249046181 260 #endif
dflet 3:a8c249046181 261
dflet 3:a8c249046181 262 #ifdef SlExtLib5HttpServerEventHandler
dflet 3:a8c249046181 263 SlExtLib5HttpServerEventHandler,
dflet 3:a8c249046181 264 #endif
dflet 3:a8c249046181 265 };
dflet 3:a8c249046181 266
dflet 3:a8c249046181 267 #undef _SlDrvHandleHttpServerEvents
dflet 3:a8c249046181 268
dflet 3:a8c249046181 269 /*******************************************************************
dflet 3:a8c249046181 270 _SlDrvHandleHttpServerEvents
dflet 3:a8c249046181 271 Iterates through all the http server event handlers which are
dflet 3:a8c249046181 272 registered by the external libs/user application.
dflet 3:a8c249046181 273 ********************************************************************/
dflet 3:a8c249046181 274 void _SlDrvHandleHttpServerEvents(SlHttpServerEvent_t *slHttpServerEvent, SlHttpServerResponse_t *slHttpServerResponse)
dflet 3:a8c249046181 275 {
dflet 3:a8c249046181 276 _u8 i;
dflet 3:a8c249046181 277
dflet 3:a8c249046181 278 /* Iterate over all the external libs handlers */
dflet 3:a8c249046181 279 for ( i = 0 ; i < sizeof(httpServer_callbacks)/sizeof(httpServer_callbacks[0]) ; i++ )
dflet 3:a8c249046181 280 {
dflet 3:a8c249046181 281 if ( EVENT_PROPAGATION_BLOCK == httpServer_callbacks[i](slHttpServerEvent, slHttpServerResponse) )
dflet 3:a8c249046181 282 {
dflet 3:a8c249046181 283 /* exit immediately and do not call the user specific handler as well */
dflet 3:a8c249046181 284 return;
dflet 3:a8c249046181 285 }
dflet 3:a8c249046181 286 }
dflet 3:a8c249046181 287
dflet 3:a8c249046181 288 /* At last call the Application specific handler if registered */
dflet 3:a8c249046181 289 #ifdef sl_HttpServerCallback
dflet 3:a8c249046181 290 sl_HttpServerCallback(slHttpServerEvent, slHttpServerResponse);
dflet 3:a8c249046181 291 #endif
dflet 3:a8c249046181 292
dflet 3:a8c249046181 293 }
dflet 3:a8c249046181 294 #endif
dflet 3:a8c249046181 295
dflet 3:a8c249046181 296
dflet 3:a8c249046181 297 /* Socket Events */
dflet 3:a8c249046181 298 #if defined (EXT_LIB_REGISTERED_SOCK_EVENTS)
dflet 3:a8c249046181 299
dflet 3:a8c249046181 300 typedef _SlEventPropogationStatus_e (*sock_callback) (SlSockEvent_t *);
dflet 3:a8c249046181 301
dflet 3:a8c249046181 302 static const sock_callback sock_callbacks[] =
dflet 3:a8c249046181 303 {
dflet 3:a8c249046181 304 #ifdef SlExtLib1SockEventHandler
dflet 3:a8c249046181 305 SlExtLib1SockEventHandler,
dflet 3:a8c249046181 306 #endif
dflet 3:a8c249046181 307
dflet 3:a8c249046181 308 #ifdef SlExtLib2SockEventHandler
dflet 3:a8c249046181 309 SlExtLib2SockEventHandler,
dflet 3:a8c249046181 310 #endif
dflet 3:a8c249046181 311
dflet 3:a8c249046181 312 #ifdef SlExtLib3SockEventHandler
dflet 3:a8c249046181 313 SlExtLib3SockEventHandler,
dflet 3:a8c249046181 314 #endif
dflet 3:a8c249046181 315
dflet 3:a8c249046181 316 #ifdef SlExtLib4SockEventHandler
dflet 3:a8c249046181 317 SlExtLib4SockEventHandler,
dflet 3:a8c249046181 318 #endif
dflet 3:a8c249046181 319
dflet 3:a8c249046181 320 #ifdef SlExtLib5SockEventHandler
dflet 3:a8c249046181 321 SlExtLib5SockEventHandler,
dflet 3:a8c249046181 322 #endif
dflet 3:a8c249046181 323 };
dflet 3:a8c249046181 324
dflet 3:a8c249046181 325 /*************************************************************
dflet 3:a8c249046181 326 _SlDrvHandleSockEvents
dflet 3:a8c249046181 327 Iterates through all the socket event handlers which are
dflet 3:a8c249046181 328 registered by the external libs/user application.
dflet 3:a8c249046181 329 **************************************************************/
dflet 3:a8c249046181 330 void _SlDrvHandleSockEvents(SlSockEvent_t *slSockEvent)
dflet 3:a8c249046181 331 {
dflet 3:a8c249046181 332 uint8_t i;
dflet 3:a8c249046181 333
dflet 3:a8c249046181 334 /* Iterate over all the external libs handlers */
dflet 3:a8c249046181 335 for ( i = 0 ; i < sizeof(sock_callbacks)/sizeof(sock_callbacks[0]) ; i++ )
dflet 3:a8c249046181 336 {
dflet 3:a8c249046181 337 if ( EVENT_PROPAGATION_BLOCK == sock_callbacks[i](slSockEvent) )
dflet 3:a8c249046181 338 {
dflet 3:a8c249046181 339 /* exit immediately and do not call the user specific handler as well */
dflet 3:a8c249046181 340 return;
dflet 3:a8c249046181 341 }
dflet 3:a8c249046181 342 }
dflet 3:a8c249046181 343
dflet 3:a8c249046181 344 /* At last call the Application specific handler if registered */
dflet 3:a8c249046181 345 #ifdef sl_SockEvtHdlr
dflet 3:a8c249046181 346 sl_SockEvtHdlr(slSockEvent);
dflet 3:a8c249046181 347 #endif
dflet 3:a8c249046181 348
dflet 3:a8c249046181 349 }
dflet 3:a8c249046181 350
dflet 3:a8c249046181 351 #endif
dflet 3:a8c249046181 352
dflet 3:a8c249046181 353 /*!
dflet 3:a8c249046181 354 \brief This function handles ping report events
dflet 3:a8c249046181 355
dflet 3:a8c249046181 356 \param[in] pPingReport holds the ping report statistics
dflet 3:a8c249046181 357
dflet 3:a8c249046181 358 \return None
dflet 3:a8c249046181 359
dflet 3:a8c249046181 360 \note
dflet 3:a8c249046181 361
dflet 3:a8c249046181 362 \warning
dflet 3:a8c249046181 363 */
dflet 3:a8c249046181 364 void SimpleLinkPingReport(SlPingReport_t *pPingReport)
dflet 3:a8c249046181 365 {
dflet 3:a8c249046181 366 _cc3100_.SET_STATUS_BIT(g_Status, STATUS_BIT_PING_DONE);
dflet 3:a8c249046181 367
dflet 3:a8c249046181 368 if(pPingReport == NULL)
dflet 3:a8c249046181 369 Uart_Write((uint8_t*)" [PING REPORT] NULL Pointer Error\r\n");
dflet 3:a8c249046181 370
dflet 3:a8c249046181 371 g_PingPacketsRecv = pPingReport->PacketsReceived;
dflet 3:a8c249046181 372 }
dflet 3:a8c249046181 373
dflet 3:a8c249046181 374
dflet 3:a8c249046181 375 /*******************************************************************************/
dflet 3:a8c249046181 376 /* _sl_HandleAsync_Accept */
dflet 3:a8c249046181 377 /*******************************************************************************/
dflet 3:a8c249046181 378 #ifndef SL_TINY_EXT
dflet 3:a8c249046181 379 void _sl_HandleAsync_Accept(void *pVoidBuf)
dflet 3:a8c249046181 380 {
dflet 3:a8c249046181 381 _SocketAddrResponse_u *pMsgArgs = (_SocketAddrResponse_u *)_SL_RESP_ARGS_START(pVoidBuf);
dflet 3:a8c249046181 382
dflet 3:a8c249046181 383 _cc3100_._driver._SlDrvProtectionObjLockWaitForever();
dflet 3:a8c249046181 384
dflet 3:a8c249046181 385 VERIFY_PROTOCOL(( pMsgArgs->IpV4.sd & BSD_SOCKET_ID_MASK) <= SL_MAX_SOCKETS);
dflet 3:a8c249046181 386 VERIFY_SOCKET_CB(NULL != g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs);
dflet 3:a8c249046181 387
dflet 3:a8c249046181 388 memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs,sizeof(_SocketAddrResponse_u));
dflet 3:a8c249046181 389 _cc3100_._driver._SlDrvSyncObjSignal(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj);
dflet 3:a8c249046181 390
dflet 3:a8c249046181 391 _cc3100_._driver._SlDrvProtectionObjUnLock();
dflet 3:a8c249046181 392 return;
dflet 3:a8c249046181 393 }
dflet 3:a8c249046181 394
dflet 3:a8c249046181 395 /*******************************************************************************/
dflet 3:a8c249046181 396 /* _sl_HandleAsync_Connect */
dflet 3:a8c249046181 397 /*******************************************************************************/
dflet 3:a8c249046181 398 void _sl_HandleAsync_Connect(void *pVoidBuf)
dflet 3:a8c249046181 399 {
dflet 3:a8c249046181 400 _SocketResponse_t *pMsgArgs = (_SocketResponse_t *)_SL_RESP_ARGS_START(pVoidBuf);
dflet 3:a8c249046181 401
dflet 3:a8c249046181 402 _cc3100_._driver._SlDrvProtectionObjLockWaitForever();
dflet 3:a8c249046181 403
dflet 3:a8c249046181 404 VERIFY_PROTOCOL((pMsgArgs->sd & BSD_SOCKET_ID_MASK) <= SL_MAX_SOCKETS);
dflet 3:a8c249046181 405 VERIFY_SOCKET_CB(NULL != g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs);
dflet 3:a8c249046181 406
dflet 3:a8c249046181 407 ((_SocketResponse_t *)(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs))->sd = pMsgArgs->sd;
dflet 3:a8c249046181 408 ((_SocketResponse_t *)(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs))->statusOrLen = pMsgArgs->statusOrLen;
dflet 3:a8c249046181 409
dflet 3:a8c249046181 410 _cc3100_._driver._SlDrvSyncObjSignal(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj);
dflet 3:a8c249046181 411 _cc3100_._driver._SlDrvProtectionObjUnLock();
dflet 3:a8c249046181 412 return;
dflet 3:a8c249046181 413 }
dflet 3:a8c249046181 414
dflet 3:a8c249046181 415 /*******************************************************************************/
dflet 3:a8c249046181 416 /* _sl_HandleAsync_Select */
dflet 3:a8c249046181 417 /*******************************************************************************/
dflet 3:a8c249046181 418 void _sl_HandleAsync_Select(void *pVoidBuf)
dflet 3:a8c249046181 419 {
dflet 3:a8c249046181 420 _SelectAsyncResponse_t *pMsgArgs = (_SelectAsyncResponse_t *)_SL_RESP_ARGS_START(pVoidBuf);
dflet 3:a8c249046181 421
dflet 3:a8c249046181 422 _cc3100_._driver._SlDrvProtectionObjLockWaitForever();
dflet 3:a8c249046181 423
dflet 3:a8c249046181 424 VERIFY_SOCKET_CB(NULL != g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs);
dflet 3:a8c249046181 425
dflet 3:a8c249046181 426 memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs, sizeof(_SelectAsyncResponse_t));
dflet 3:a8c249046181 427
dflet 3:a8c249046181 428 _cc3100_._driver._SlDrvSyncObjSignal(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj);
dflet 3:a8c249046181 429 _cc3100_._driver._SlDrvProtectionObjUnLock();
dflet 3:a8c249046181 430
dflet 3:a8c249046181 431 return;
dflet 3:a8c249046181 432 }
dflet 3:a8c249046181 433
dflet 3:a8c249046181 434 #endif
dflet 3:a8c249046181 435
dflet 3:a8c249046181 436 /******************************************************************************/
dflet 3:a8c249046181 437 /* _sl_HandleAsync_DnsGetHostByName */
dflet 3:a8c249046181 438 /******************************************************************************/
dflet 3:a8c249046181 439 void _sl_HandleAsync_DnsGetHostByName(void *pVoidBuf)
dflet 3:a8c249046181 440 {
dflet 3:a8c249046181 441 _GetHostByNameIPv4AsyncResponse_t *pMsgArgs = (_GetHostByNameIPv4AsyncResponse_t *)_SL_RESP_ARGS_START(pVoidBuf);
dflet 3:a8c249046181 442
dflet 3:a8c249046181 443 _cc3100_._driver._SlDrvProtectionObjLockWaitForever();
dflet 3:a8c249046181 444
dflet 3:a8c249046181 445 VERIFY_SOCKET_CB(NULL != g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs);
dflet 3:a8c249046181 446
dflet 3:a8c249046181 447 /*IPv6 */
dflet 3:a8c249046181 448 if(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].AdditionalData & SL_NETAPP_FAMILY_MASK) {
dflet 3:a8c249046181 449 memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs, sizeof(_GetHostByNameIPv6AsyncResponse_t));
dflet 3:a8c249046181 450 }
dflet 3:a8c249046181 451 /*IPv4 */
dflet 3:a8c249046181 452 else
dflet 3:a8c249046181 453 {
dflet 3:a8c249046181 454 memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs, sizeof(_GetHostByNameIPv4AsyncResponse_t));
dflet 3:a8c249046181 455 }
dflet 3:a8c249046181 456
dflet 3:a8c249046181 457 _cc3100_._driver._SlDrvSyncObjSignal(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj);
dflet 3:a8c249046181 458 _cc3100_._driver._SlDrvProtectionObjUnLock();
dflet 3:a8c249046181 459
dflet 3:a8c249046181 460 return;
dflet 3:a8c249046181 461 }
dflet 3:a8c249046181 462
dflet 3:a8c249046181 463 /******************************************************************************/
dflet 3:a8c249046181 464
dflet 3:a8c249046181 465 /******************************************************************************
dflet 3:a8c249046181 466 _sl_HandleAsync_DnsGetHostByService
dflet 3:a8c249046181 467
dflet 3:a8c249046181 468 CALLER NWP - Async event on sl_DnsGetHostByService with IPv4 Family
dflet 3:a8c249046181 469
dflet 3:a8c249046181 470
dflet 3:a8c249046181 471 DESCRIPTION:
dflet 3:a8c249046181 472
dflet 3:a8c249046181 473 Async event on sl_DnsGetHostByService command with IPv4 Family.
dflet 3:a8c249046181 474 Return service attributes like IP address, port and text according to service name.
dflet 3:a8c249046181 475 The user sets a service name Full/Part (see example below), and should get the:
dflet 3:a8c249046181 476 1. IP of the service
dflet 3:a8c249046181 477 2. The port of service.
dflet 3:a8c249046181 478 3. The text of service.
dflet 3:a8c249046181 479
dflet 3:a8c249046181 480 Hence it can make a connection to the specific service and use it.
dflet 3:a8c249046181 481 It is similar to get host by name method.
dflet 3:a8c249046181 482
dflet 3:a8c249046181 483 It is done by a single shot query with PTR type on the service name.
dflet 3:a8c249046181 484
dflet 3:a8c249046181 485
dflet 3:a8c249046181 486
dflet 3:a8c249046181 487 Note:
dflet 3:a8c249046181 488 1. The return's attributes are belonged to first service that is found.
dflet 3:a8c249046181 489 It can be other services with the same service name will response to
dflet 3:a8c249046181 490 the query. The results of these responses are saved in the peer cache of the NWP, and
dflet 3:a8c249046181 491 should be read by another API.
dflet 3:a8c249046181 492
dflet 3:a8c249046181 493
dflet 3:a8c249046181 494 PARAMETERS:
dflet 3:a8c249046181 495
dflet 3:a8c249046181 496 pVoidBuf - is point to opcode of the event.
dflet 3:a8c249046181 497 it contains the outputs that are given to the user
dflet 3:a8c249046181 498
dflet 3:a8c249046181 499 outputs description:
dflet 3:a8c249046181 500
dflet 3:a8c249046181 501 1.out_pAddr[] - output: Contain the IP address of the service.
dflet 3:a8c249046181 502 2.out_pPort - output: Contain the port of the service.
dflet 3:a8c249046181 503 3.inout_TextLen - Input: Contain the max length of the text that the user wants to get.
dflet 3:a8c249046181 504 it means that if the test of service is bigger that its value than
dflet 3:a8c249046181 505 the text is cut to inout_TextLen value.
dflet 3:a8c249046181 506 Output: Contain the length of the text that is returned. Can be full text or part
dflet 3:a8c249046181 507 of the text (see above).
dflet 3:a8c249046181 508
dflet 3:a8c249046181 509 4.out_pText - Contain the text of the service (full or part see above- inout_TextLen description).
dflet 3:a8c249046181 510
dflet 3:a8c249046181 511 *
dflet 3:a8c249046181 512
dflet 3:a8c249046181 513
dflet 3:a8c249046181 514 RETURNS: success or fail.
dflet 3:a8c249046181 515
dflet 3:a8c249046181 516 ******************************************************************************/
dflet 3:a8c249046181 517 #ifndef SL_TINY_EXT
dflet 3:a8c249046181 518 void _sl_HandleAsync_DnsGetHostByService(void *pVoidBuf)
dflet 3:a8c249046181 519 {
dflet 3:a8c249046181 520 _GetHostByServiceAsyncResponse_t* Res;
dflet 3:a8c249046181 521 uint16_t TextLen;
dflet 3:a8c249046181 522 uint16_t UserTextLen;
dflet 3:a8c249046181 523
dflet 3:a8c249046181 524 /*pVoidBuf - is point to opcode of the event.*/
dflet 3:a8c249046181 525
dflet 3:a8c249046181 526 /*set pMsgArgs to point to the attribute of the event.*/
dflet 3:a8c249046181 527 _GetHostByServiceIPv4AsyncResponse_t *pMsgArgs = (_GetHostByServiceIPv4AsyncResponse_t *)_SL_RESP_ARGS_START(pVoidBuf);
dflet 3:a8c249046181 528
dflet 3:a8c249046181 529 VERIFY_SOCKET_CB(NULL != g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs);
dflet 3:a8c249046181 530
dflet 3:a8c249046181 531 /*IPv6*/
dflet 3:a8c249046181 532 if(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].AdditionalData & SL_NETAPP_FAMILY_MASK) {
dflet 3:a8c249046181 533 return;
dflet 3:a8c249046181 534 }
dflet 3:a8c249046181 535 /*IPv4*/
dflet 3:a8c249046181 536 else {
dflet 3:a8c249046181 537 /*************************************************************************************************
dflet 3:a8c249046181 538
dflet 3:a8c249046181 539 1. Copy the attribute part of the evnt to the attribute part of the response
dflet 3:a8c249046181 540 memcpy(g_pCB->GetHostByServiceCB.pAsyncRsp, pMsgArgs, sizeof(_GetHostByServiceIPv4AsyncResponse_t));
dflet 3:a8c249046181 541
dflet 3:a8c249046181 542 set to TextLen the text length of the service.*/
dflet 3:a8c249046181 543 TextLen = pMsgArgs->TextLen;
dflet 3:a8c249046181 544
dflet 3:a8c249046181 545 /*Res pointed to mDNS global object struct */
dflet 3:a8c249046181 546 Res = (_GetHostByServiceAsyncResponse_t*)g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs;
dflet 3:a8c249046181 547
dflet 3:a8c249046181 548
dflet 3:a8c249046181 549
dflet 3:a8c249046181 550 /*It is 4 bytes so we avoid from memcpy*/
dflet 3:a8c249046181 551 Res->out_pAddr[0] = pMsgArgs->Address;
dflet 3:a8c249046181 552 Res->out_pPort[0] = pMsgArgs->Port;
dflet 3:a8c249046181 553 Res->Status = pMsgArgs->Status;
dflet 3:a8c249046181 554
dflet 3:a8c249046181 555 /*set to TextLen the text length of the user (input fromthe user).*/
dflet 3:a8c249046181 556 UserTextLen = Res->inout_TextLen[0];
dflet 3:a8c249046181 557
dflet 3:a8c249046181 558 /*Cut the service text if the user requested for smaller text.*/
dflet 3:a8c249046181 559 UserTextLen = (TextLen <= UserTextLen) ? TextLen : UserTextLen;
dflet 3:a8c249046181 560 Res->inout_TextLen[0] = UserTextLen ;
dflet 3:a8c249046181 561
dflet 3:a8c249046181 562 /**************************************************************************************************
dflet 3:a8c249046181 563
dflet 3:a8c249046181 564 2. Copy the payload part of the evnt (the text) to the payload part of the response
dflet 3:a8c249046181 565 the lenght of the copy is according to the text length in the attribute part. */
dflet 3:a8c249046181 566
dflet 3:a8c249046181 567
dflet 3:a8c249046181 568 memcpy(Res->out_pText,
dflet 3:a8c249046181 569 (int8_t *)(& pMsgArgs[1]), /* & pMsgArgs[1] -> 1st byte after the fixed header = 1st byte of variable text.*/
dflet 3:a8c249046181 570 UserTextLen);
dflet 3:a8c249046181 571
dflet 3:a8c249046181 572
dflet 3:a8c249046181 573 /**************************************************************************************************/
dflet 3:a8c249046181 574 _cc3100_._driver._SlDrvSyncObjSignal(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj);
dflet 3:a8c249046181 575 return;
dflet 3:a8c249046181 576 }
dflet 3:a8c249046181 577 }
dflet 3:a8c249046181 578 #endif
dflet 3:a8c249046181 579
dflet 3:a8c249046181 580 /*****************************************************************************/
dflet 3:a8c249046181 581 /* _sl_HandleAsync_PingResponse */
dflet 3:a8c249046181 582 /*****************************************************************************/
dflet 3:a8c249046181 583 #ifndef SL_TINY_EXT
dflet 3:a8c249046181 584 void _sl_HandleAsync_PingResponse(void *pVoidBuf)
dflet 3:a8c249046181 585 {
dflet 3:a8c249046181 586 _PingReportResponse_t *pMsgArgs = (_PingReportResponse_t *)_SL_RESP_ARGS_START(pVoidBuf);
dflet 3:a8c249046181 587 SlPingReport_t pingReport;
dflet 3:a8c249046181 588
dflet 3:a8c249046181 589 if(pPingCallBackFunc) {
dflet 3:a8c249046181 590 _cc3100_._netapp.CopyPingResultsToReport(pMsgArgs,&pingReport);
dflet 3:a8c249046181 591 pPingCallBackFunc(&pingReport);
dflet 3:a8c249046181 592 } else {
dflet 3:a8c249046181 593
dflet 3:a8c249046181 594 _cc3100_._driver._SlDrvProtectionObjLockWaitForever();
dflet 3:a8c249046181 595 VERIFY_SOCKET_CB(NULL != g_pCB->PingCB.PingAsync.pAsyncRsp);
dflet 3:a8c249046181 596
dflet 3:a8c249046181 597 if (NULL != g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs) {
dflet 3:a8c249046181 598 memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs, sizeof(_PingReportResponse_t));
dflet 3:a8c249046181 599 _cc3100_._driver._SlDrvSyncObjSignal(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj);
dflet 3:a8c249046181 600 }
dflet 3:a8c249046181 601 _cc3100_._driver._SlDrvProtectionObjUnLock();
dflet 3:a8c249046181 602 }
dflet 3:a8c249046181 603 return;
dflet 3:a8c249046181 604 }
dflet 3:a8c249046181 605 #endif
dflet 3:a8c249046181 606
dflet 3:a8c249046181 607 /* ******************************************************************************/
dflet 3:a8c249046181 608 /* _SlDrvMsgReadSpawnCtx */
dflet 3:a8c249046181 609 /* ******************************************************************************/
dflet 3:a8c249046181 610
dflet 3:a8c249046181 611 _SlReturnVal_t _SlDrvMsgReadSpawnCtx(void *pValue)
dflet 3:a8c249046181 612 {
dflet 3:a8c249046181 613 // Uart_Write((uint8_t*)"\n\r _SlDrvMsgReadSpawnCtx \n\r");
dflet 3:a8c249046181 614 #ifdef SL_POLLING_MODE_USED
dflet 3:a8c249046181 615 int16_t retCode = OSI_OK;
dflet 3:a8c249046181 616 // for polling based systems
dflet 3:a8c249046181 617 do {
dflet 3:a8c249046181 618 retCode = _cc3100_->_nonos.sl_LockObjLock(&g_pCB->GlobalLockObj, 0);
dflet 3:a8c249046181 619 if ( OSI_OK != retCode ) {
dflet 3:a8c249046181 620 if (TRUE == g_pCB->IsCmdRespWaited) {
dflet 3:a8c249046181 621 OSI_RET_OK_CHECK( _cc3100_->_nonos.sl_SyncObjSignal(&g_pCB->CmdSyncObj) );
dflet 3:a8c249046181 622 return SL_RET_CODE_OK;
dflet 3:a8c249046181 623 }
dflet 3:a8c249046181 624 }
dflet 3:a8c249046181 625
dflet 3:a8c249046181 626 } while (OSI_OK != retCode);
dflet 3:a8c249046181 627
dflet 3:a8c249046181 628 #else
dflet 3:a8c249046181 629
dflet 3:a8c249046181 630 // OSI_RET_OK_CHECK(_cc3100_->_nonos.sl_LockObjLock(&g_pCB->GlobalLockObj, NON_OS_LOCK_OBJ_UNLOCK_VALUE, NON_OS_LOCK_OBJ_LOCK_VALUE, SL_OS_WAIT_FOREVER) );
dflet 3:a8c249046181 631 _cc3100_._driver._SlDrvObjLockWaitForever(&g_pCB->GlobalLockObj);
dflet 3:a8c249046181 632
dflet 3:a8c249046181 633 #endif
dflet 3:a8c249046181 634
dflet 3:a8c249046181 635 g_pCB->FunctionParams.AsyncExt.pAsyncBuf = NULL;// buffer must be allocated by _SlDrvMsgRead
dflet 3:a8c249046181 636 g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler= NULL;
dflet 3:a8c249046181 637 g_pCB->FunctionParams.AsyncExt.RxMsgClass = CMD_RESP_CLASS;// init to illegal value and verify it's overwritten with the valid one
dflet 3:a8c249046181 638
dflet 3:a8c249046181 639 // Messages might have been read by CmdResp context. Therefore after
dflet 3:a8c249046181 640 // getting LockObj, check again where the Pending Rx Msg is still present.
dflet 3:a8c249046181 641 if(FALSE == (_cc3100_._driver._SL_PENDING_RX_MSG(g_pCB))) {
dflet 3:a8c249046181 642 _cc3100_._driver._SlDrvObjUnLock(&g_pCB->GlobalLockObj);
dflet 3:a8c249046181 643 // OSI_RET_OK_CHECK(_cc3100_->_nonos.sl_LockObjUnlock(&g_pCB->GlobalLockObj, NON_OS_LOCK_OBJ_UNLOCK_VALUE));
dflet 3:a8c249046181 644 return SL_RET_CODE_OK;
dflet 3:a8c249046181 645 }
dflet 3:a8c249046181 646
dflet 3:a8c249046181 647 VERIFY_RET_OK(_cc3100_._driver._SlDrvMsgRead());
dflet 3:a8c249046181 648
dflet 3:a8c249046181 649 g_pCB->RxDoneCnt++;
dflet 3:a8c249046181 650
dflet 3:a8c249046181 651 switch(g_pCB->FunctionParams.AsyncExt.RxMsgClass) {
dflet 3:a8c249046181 652 case ASYNC_EVT_CLASS:
dflet 3:a8c249046181 653 // If got here and protected by LockObj a message is waiting
dflet 3:a8c249046181 654 // to be read
dflet 3:a8c249046181 655 VERIFY_PROTOCOL(NULL != g_pCB->FunctionParams.AsyncExt.pAsyncBuf);
dflet 3:a8c249046181 656
dflet 3:a8c249046181 657 _cc3100_._driver._SlAsyncEventGenericHandler();
dflet 3:a8c249046181 658
dflet 3:a8c249046181 659 #if (SL_MEMORY_MGMT == SL_MEMORY_MGMT_STATIC)
dflet 3:a8c249046181 660 g_pCB->FunctionParams.AsyncExt.pAsyncBuf = NULL;
dflet 3:a8c249046181 661 #else
dflet 3:a8c249046181 662 free(g_pCB->FunctionParams.AsyncExt.pAsyncBuf);
dflet 3:a8c249046181 663 #endif
dflet 3:a8c249046181 664 break;
dflet 3:a8c249046181 665 case DUMMY_MSG_CLASS:
dflet 3:a8c249046181 666 case RECV_RESP_CLASS:
dflet 3:a8c249046181 667 // These types are legal in this context. Do nothing
dflet 3:a8c249046181 668 break;
dflet 3:a8c249046181 669 case CMD_RESP_CLASS:
dflet 3:a8c249046181 670 // Command response is illegal in this context.
dflet 3:a8c249046181 671 // No 'break' here: Assert!
dflet 3:a8c249046181 672 default:
dflet 3:a8c249046181 673 VERIFY_PROTOCOL(0);
dflet 3:a8c249046181 674 }
dflet 3:a8c249046181 675
dflet 3:a8c249046181 676 _cc3100_._driver._SlDrvObjUnLock(&g_pCB->GlobalLockObj);
dflet 3:a8c249046181 677 // OSI_RET_OK_CHECK(_cc3100_->_nonos.sl_LockObjUnlock(&g_pCB->GlobalLockObj, NON_OS_LOCK_OBJ_UNLOCK_VALUE));
dflet 3:a8c249046181 678
dflet 3:a8c249046181 679 return(SL_RET_CODE_OK);
dflet 3:a8c249046181 680
dflet 3:a8c249046181 681 }
dflet 3:a8c249046181 682
dflet 3:a8c249046181 683 /***************************************************************************
dflet 3:a8c249046181 684 _sl_HandleAsync_Stop - handles stop signalling to
dflet 3:a8c249046181 685 a waiting object
dflet 3:a8c249046181 686 ****************************************************************************/
dflet 3:a8c249046181 687 void _sl_HandleAsync_Stop(void *pVoidBuf)
dflet 3:a8c249046181 688 {
dflet 3:a8c249046181 689 _BasicResponse_t *pMsgArgs = (_BasicResponse_t *)_SL_RESP_ARGS_START(pVoidBuf);
dflet 3:a8c249046181 690
dflet 3:a8c249046181 691 VERIFY_SOCKET_CB(NULL != g_pCB->StopCB.pAsyncRsp);
dflet 3:a8c249046181 692
dflet 3:a8c249046181 693 _cc3100_._driver._SlDrvProtectionObjLockWaitForever();
dflet 3:a8c249046181 694
dflet 3:a8c249046181 695 memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs, sizeof(_BasicResponse_t));
dflet 3:a8c249046181 696 _cc3100_._driver._SlDrvSyncObjSignal(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj);
dflet 3:a8c249046181 697 _cc3100_._driver._SlDrvProtectionObjUnLock();
dflet 3:a8c249046181 698 return;
dflet 3:a8c249046181 699 }
dflet 3:a8c249046181 700
dflet 3:a8c249046181 701 /******************************************************************************
dflet 3:a8c249046181 702 _SlDrvDeviceEventHandler - handles internally device async events
dflet 3:a8c249046181 703 ******************************************************************************/
dflet 3:a8c249046181 704 void _SlDrvDeviceEventHandler(void *pArgs)
dflet 3:a8c249046181 705 {
dflet 3:a8c249046181 706 _SlResponseHeader_t *pHdr = (_SlResponseHeader_t *)pArgs;
dflet 3:a8c249046181 707
dflet 3:a8c249046181 708 switch(pHdr->GenHeader.Opcode) {
dflet 3:a8c249046181 709 case SL_OPCODE_DEVICE_INITCOMPLETE:
dflet 3:a8c249046181 710 _cc3100_._sl_HandleAsync_InitComplete(pHdr);
dflet 3:a8c249046181 711
dflet 3:a8c249046181 712 break;
dflet 3:a8c249046181 713 case SL_OPCODE_DEVICE_STOP_ASYNC_RESPONSE:
dflet 3:a8c249046181 714 _sl_HandleAsync_Stop(pHdr);
dflet 3:a8c249046181 715
dflet 3:a8c249046181 716 break;
dflet 3:a8c249046181 717
dflet 3:a8c249046181 718
dflet 3:a8c249046181 719 case SL_OPCODE_DEVICE_ABORT:
dflet 3:a8c249046181 720 {
dflet 3:a8c249046181 721 #if defined (sl_GeneralEvtHdlr) || defined(EXT_LIB_REGISTERED_GENERAL_EVENTS)
dflet 3:a8c249046181 722 SlDeviceEvent_t devHandler;
dflet 3:a8c249046181 723 devHandler.Event = SL_DEVICE_ABORT_ERROR_EVENT;
dflet 3:a8c249046181 724 devHandler.EventData.deviceReport.AbortType = *((uint32_t*)pArgs + 2);
dflet 3:a8c249046181 725 devHandler.EventData.deviceReport.AbortData = *((uint32_t*)pArgs + 3);
dflet 3:a8c249046181 726 _SlDrvHandleGeneralEvents(&devHandler);
dflet 3:a8c249046181 727 #endif
dflet 3:a8c249046181 728 }
dflet 3:a8c249046181 729 break;
dflet 3:a8c249046181 730 case SL_OPCODE_DEVICE_DEVICEASYNCFATALERROR:
dflet 3:a8c249046181 731 #if defined (sl_GeneralEvtHdlr) || defined(EXT_LIB_REGISTERED_GENERAL_EVENTS)
dflet 3:a8c249046181 732 {
dflet 3:a8c249046181 733 _BasicResponse_t *pMsgArgs = (_BasicResponse_t *)_SL_RESP_ARGS_START(pHdr);
dflet 3:a8c249046181 734 SlDeviceEvent_t devHandler;
dflet 3:a8c249046181 735 devHandler.Event = SL_DEVICE_FATAL_ERROR_EVENT;
dflet 3:a8c249046181 736 devHandler.EventData.deviceEvent.status = pMsgArgs->status & 0xFF;
dflet 3:a8c249046181 737 devHandler.EventData.deviceEvent.sender = (SlErrorSender_e)((pMsgArgs->status >> 8) & 0xFF);
dflet 3:a8c249046181 738 _SlDrvHandleGeneralEvents(&devHandler);
dflet 3:a8c249046181 739 }
dflet 3:a8c249046181 740 #endif
dflet 3:a8c249046181 741 break;
dflet 3:a8c249046181 742 default:
dflet 3:a8c249046181 743 SL_ERROR_TRACE2(MSG_306, "ASSERT: _SlDrvDeviceEventHandler : invalid opcode = 0x%x = %i", pHdr->GenHeader.Opcode, pHdr->GenHeader.Opcode);
dflet 3:a8c249046181 744 //printf("ASSERT: _SlDrvDeviceEventHandler : invalid opcode = 0x%x = %i", pHdr->GenHeader.Opcode, pHdr->GenHeader.Opcode);
dflet 3:a8c249046181 745
dflet 3:a8c249046181 746 }
dflet 3:a8c249046181 747 }
dflet 3:a8c249046181 748
dflet 3:a8c249046181 749 /*****************************************************************************/
dflet 3:a8c249046181 750 /* _SlDrvNetAppEventHandler */
dflet 3:a8c249046181 751 /*****************************************************************************/
dflet 3:a8c249046181 752 void _SlDrvNetAppEventHandler(void *pArgs)
dflet 3:a8c249046181 753 {
dflet 3:a8c249046181 754 _SlResponseHeader_t *pHdr = (_SlResponseHeader_t *)pArgs;
dflet 3:a8c249046181 755 #if defined(sl_HttpServerCallback) || defined(EXT_LIB_REGISTERED_HTTP_SERVER_EVENTS)
dflet 3:a8c249046181 756 SlHttpServerEvent_t httpServerEvent;
dflet 3:a8c249046181 757 SlHttpServerResponse_t httpServerResponse;
dflet 3:a8c249046181 758 #endif
dflet 3:a8c249046181 759 switch(pHdr->GenHeader.Opcode) {
dflet 3:a8c249046181 760 case SL_OPCODE_NETAPP_DNSGETHOSTBYNAMEASYNCRESPONSE:
dflet 3:a8c249046181 761 case SL_OPCODE_NETAPP_DNSGETHOSTBYNAMEASYNCRESPONSE_V6:
dflet 3:a8c249046181 762 _sl_HandleAsync_DnsGetHostByName(pArgs);
dflet 3:a8c249046181 763 break;
dflet 3:a8c249046181 764 #ifndef SL_TINY_EXT
dflet 3:a8c249046181 765 case SL_OPCODE_NETAPP_MDNSGETHOSTBYSERVICEASYNCRESPONSE:
dflet 3:a8c249046181 766 case SL_OPCODE_NETAPP_MDNSGETHOSTBYSERVICEASYNCRESPONSE_V6:
dflet 3:a8c249046181 767 _sl_HandleAsync_DnsGetHostByService(pArgs);
dflet 3:a8c249046181 768 break;
dflet 3:a8c249046181 769 case SL_OPCODE_NETAPP_PINGREPORTREQUESTRESPONSE:
dflet 3:a8c249046181 770 _sl_HandleAsync_PingResponse(pArgs);
dflet 3:a8c249046181 771 break;
dflet 3:a8c249046181 772 #endif
dflet 3:a8c249046181 773
dflet 3:a8c249046181 774 #if defined(sl_HttpServerCallback) || defined(EXT_LIB_REGISTERED_HTTP_SERVER_EVENTS)
dflet 3:a8c249046181 775 case SL_OPCODE_NETAPP_HTTPGETTOKENVALUE: {
dflet 3:a8c249046181 776
dflet 3:a8c249046181 777 uint8_t *pTokenName;
dflet 3:a8c249046181 778 slHttpServerData_t Token_value;
dflet 3:a8c249046181 779 sl_NetAppHttpServerGetToken_t *httpGetToken = (sl_NetAppHttpServerGetToken_t *)_SL_RESP_ARGS_START(pHdr);
dflet 3:a8c249046181 780 pTokenName = (uint8_t *)((sl_NetAppHttpServerGetToken_t *)httpGetToken + 1);
dflet 3:a8c249046181 781
dflet 3:a8c249046181 782 httpServerResponse.Response = SL_NETAPP_HTTPSETTOKENVALUE;
dflet 3:a8c249046181 783 httpServerResponse.ResponseData.token_value.len = MAX_TOKEN_VALUE_LEN;
dflet 3:a8c249046181 784
dflet 3:a8c249046181 785 /* Reuse the async buffer for getting the token value response from the user */
dflet 3:a8c249046181 786 httpServerResponse.ResponseData.token_value.data = (uint8_t *)_SL_RESP_ARGS_START(pHdr) + MAX_TOKEN_NAME_LEN;
dflet 3:a8c249046181 787 httpServerEvent.Event = SL_NETAPP_HTTPGETTOKENVALUE_EVENT;
dflet 3:a8c249046181 788
dflet 3:a8c249046181 789 httpServerEvent.EventData.httpTokenName.len = httpGetToken->token_name_len;
dflet 3:a8c249046181 790 httpServerEvent.EventData.httpTokenName.data = pTokenName;
dflet 3:a8c249046181 791
dflet 3:a8c249046181 792 Token_value.token_name = pTokenName;
dflet 3:a8c249046181 793
dflet 3:a8c249046181 794 _SlDrvHandleHttpServerEvents (&httpServerEvent, &httpServerResponse);
dflet 3:a8c249046181 795
dflet 3:a8c249046181 796 Token_value.value_len = httpServerResponse.ResponseData.token_value.len;
dflet 3:a8c249046181 797 Token_value.name_len = httpServerEvent.EventData.httpTokenName.len;
dflet 3:a8c249046181 798
dflet 3:a8c249046181 799 Token_value.token_value = httpServerResponse.ResponseData.token_value.data;
dflet 3:a8c249046181 800
dflet 3:a8c249046181 801
dflet 3:a8c249046181 802 _cc3100_._netapp.sl_NetAppSendTokenValue(&Token_value);
dflet 3:a8c249046181 803 #endif
dflet 3:a8c249046181 804 }
dflet 3:a8c249046181 805 break;
dflet 3:a8c249046181 806
dflet 3:a8c249046181 807 case SL_OPCODE_NETAPP_HTTPPOSTTOKENVALUE: {
dflet 3:a8c249046181 808 #ifdef sl_HttpServerCallback
dflet 3:a8c249046181 809 uint8_t *pPostParams;
dflet 3:a8c249046181 810
dflet 3:a8c249046181 811 sl_NetAppHttpServerPostToken_t *httpPostTokenArgs = (sl_NetAppHttpServerPostToken_t *)_SL_RESP_ARGS_START(pHdr);
dflet 3:a8c249046181 812 pPostParams = (uint8_t *)((sl_NetAppHttpServerPostToken_t *)httpPostTokenArgs + 1);
dflet 3:a8c249046181 813
dflet 3:a8c249046181 814 httpServerEvent.Event = SL_NETAPP_HTTPPOSTTOKENVALUE_EVENT;
dflet 3:a8c249046181 815
dflet 3:a8c249046181 816 httpServerEvent.EventData.httpPostData.action.len = httpPostTokenArgs->post_action_len;
dflet 3:a8c249046181 817 httpServerEvent.EventData.httpPostData.action.data = pPostParams;
dflet 3:a8c249046181 818 pPostParams+=httpPostTokenArgs->post_action_len;
dflet 3:a8c249046181 819
dflet 3:a8c249046181 820 httpServerEvent.EventData.httpPostData.token_name.len = httpPostTokenArgs->token_name_len;
dflet 3:a8c249046181 821 httpServerEvent.EventData.httpPostData.token_name.data = pPostParams;
dflet 3:a8c249046181 822 pPostParams+=httpPostTokenArgs->token_name_len;
dflet 3:a8c249046181 823
dflet 3:a8c249046181 824 httpServerEvent.EventData.httpPostData.token_value.len = httpPostTokenArgs->token_value_len;
dflet 3:a8c249046181 825 httpServerEvent.EventData.httpPostData.token_value.data = pPostParams;
dflet 3:a8c249046181 826
dflet 3:a8c249046181 827 httpServerResponse.Response = SL_NETAPP_RESPONSE_NONE;
dflet 3:a8c249046181 828
dflet 3:a8c249046181 829
dflet 3:a8c249046181 830 _SlDrvHandleHttpServerEvents (&httpServerEvent, &httpServerResponse);
dflet 3:a8c249046181 831 }
dflet 3:a8c249046181 832 break;
dflet 3:a8c249046181 833 #endif
dflet 3:a8c249046181 834 default:
dflet 3:a8c249046181 835 SL_ERROR_TRACE2(MSG_305, "ASSERT: _SlDrvNetAppEventHandler : invalid opcode = 0x%x = %i", pHdr->GenHeader.Opcode, pHdr->GenHeader.Opcode);
dflet 3:a8c249046181 836 VERIFY_PROTOCOL(0);
dflet 3:a8c249046181 837 }
dflet 3:a8c249046181 838 }
dflet 3:a8c249046181 839
dflet 3:a8c249046181 840 /*
dflet 3:a8c249046181 841 * ASYNCHRONOUS EVENT HANDLERS -- Start
dflet 3:a8c249046181 842 */
dflet 3:a8c249046181 843
dflet 3:a8c249046181 844 /*!
dflet 3:a8c249046181 845 \brief This function handles WLAN events
dflet 3:a8c249046181 846
dflet 3:a8c249046181 847 \param[in] pWlanEvent is the event passed to the handler
dflet 3:a8c249046181 848
dflet 3:a8c249046181 849 \return None
dflet 3:a8c249046181 850
dflet 3:a8c249046181 851 \note
dflet 3:a8c249046181 852
dflet 3:a8c249046181 853 \warning
dflet 3:a8c249046181 854 */
dflet 3:a8c249046181 855 #if (defined(sl_WlanEvtHdlr))
dflet 3:a8c249046181 856 void SimpleLinkWlanEventHandler(SlWlanEvent_t *pWlanEvent)
dflet 3:a8c249046181 857 {
dflet 3:a8c249046181 858 unsigned char g_ucConnectionSSID[32+1]; //Connection SSID
dflet 3:a8c249046181 859 unsigned char g_ucConnectionBSSID[6]; //Connection BSSID
dflet 3:a8c249046181 860
dflet 3:a8c249046181 861 if(pWlanEvent == NULL)
dflet 3:a8c249046181 862 Uart_Write((uint8_t*)" [WLAN EVENT] NULL Pointer Error \n\r");
dflet 3:a8c249046181 863
dflet 3:a8c249046181 864 switch(pWlanEvent->Event) {
dflet 3:a8c249046181 865 case SL_WLAN_CONNECT_EVENT: {
dflet 3:a8c249046181 866 _cc3100_.SET_STATUS_BIT(g_Status, STATUS_BIT_CONNECTION);
dflet 3:a8c249046181 867
dflet 3:a8c249046181 868 // Copy new connection SSID and BSSID to global parameters
dflet 3:a8c249046181 869 memcpy(g_ucConnectionSSID,pWlanEvent->EventData.
dflet 3:a8c249046181 870 STAandP2PModeWlanConnected.ssid_name,
dflet 3:a8c249046181 871 pWlanEvent->EventData.STAandP2PModeWlanConnected.ssid_len);
dflet 3:a8c249046181 872 memcpy(g_ucConnectionBSSID,
dflet 3:a8c249046181 873 pWlanEvent->EventData.STAandP2PModeWlanConnected.bssid,
dflet 3:a8c249046181 874 SL_BSSID_LENGTH);
dflet 3:a8c249046181 875
dflet 3:a8c249046181 876 memset(print_buf, 0x00, PRINT_BUF_LEN);
dflet 3:a8c249046181 877 sprintf((char*) print_buf, "[WLAN EVENT] STA Connected to the AP: %s ,""BSSID: %x:%x:%x:%x:%x:%x\n\r",
dflet 3:a8c249046181 878 g_ucConnectionSSID,g_ucConnectionBSSID[0],
dflet 3:a8c249046181 879 g_ucConnectionBSSID[1],g_ucConnectionBSSID[2],
dflet 3:a8c249046181 880 g_ucConnectionBSSID[3],g_ucConnectionBSSID[4],
dflet 3:a8c249046181 881 g_ucConnectionBSSID[5]);
dflet 3:a8c249046181 882 Uart_Write((uint8_t *) print_buf);
dflet 3:a8c249046181 883 /*
dflet 3:a8c249046181 884 * Information about the connected AP (like name, MAC etc) will be
dflet 3:a8c249046181 885 * available in 'slWlanConnectAsyncResponse_t' - Applications
dflet 3:a8c249046181 886 * can use it if required
dflet 3:a8c249046181 887 *
dflet 3:a8c249046181 888 * slWlanConnectAsyncResponse_t *pEventData = NULL;
dflet 3:a8c249046181 889 * pEventData = &pWlanEvent->EventData.STAandP2PModeWlanConnected;
dflet 3:a8c249046181 890 *
dflet 3:a8c249046181 891 */
dflet 3:a8c249046181 892 }
dflet 3:a8c249046181 893 break;
dflet 3:a8c249046181 894
dflet 3:a8c249046181 895 case SL_WLAN_DISCONNECT_EVENT: {
dflet 3:a8c249046181 896 slWlanConnectAsyncResponse_t* pEventData = NULL;
dflet 3:a8c249046181 897
dflet 3:a8c249046181 898 _cc3100_.CLR_STATUS_BIT(g_Status, STATUS_BIT_CONNECTION);
dflet 3:a8c249046181 899 _cc3100_.CLR_STATUS_BIT(g_Status, STATUS_BIT_IP_ACQUIRED);
dflet 3:a8c249046181 900
dflet 3:a8c249046181 901 pEventData = &pWlanEvent->EventData.STAandP2PModeDisconnected;
dflet 3:a8c249046181 902
dflet 3:a8c249046181 903 /* If the user has initiated 'Disconnect' request, 'reason_code' is SL_USER_INITIATED_DISCONNECTION */
dflet 3:a8c249046181 904 if(SL_USER_INITIATED_DISCONNECTION == pEventData->reason_code) {
dflet 3:a8c249046181 905 memset(print_buf, 0x00, PRINT_BUF_LEN);
dflet 3:a8c249046181 906 sprintf((char*) print_buf, "[WLAN EVENT]Device disconnected from the AP: %s,"
dflet 3:a8c249046181 907 "BSSID: %x:%x:%x:%x:%x:%x on application's request \n\r",
dflet 3:a8c249046181 908 g_ucConnectionSSID,g_ucConnectionBSSID[0],
dflet 3:a8c249046181 909 g_ucConnectionBSSID[1],g_ucConnectionBSSID[2],
dflet 3:a8c249046181 910 g_ucConnectionBSSID[3],g_ucConnectionBSSID[4],
dflet 3:a8c249046181 911 g_ucConnectionBSSID[5]);
dflet 3:a8c249046181 912 Uart_Write((uint8_t *) print_buf);
dflet 3:a8c249046181 913 } else {
dflet 3:a8c249046181 914 memset(print_buf, 0x00, PRINT_BUF_LEN);
dflet 3:a8c249046181 915 sprintf((char*) print_buf, "[WLAN ERROR]Device disconnected from the AP AP: %s,"
dflet 3:a8c249046181 916 "BSSID: %x:%x:%x:%x:%x:%x on an ERROR..!! \n\r",
dflet 3:a8c249046181 917 g_ucConnectionSSID,g_ucConnectionBSSID[0],
dflet 3:a8c249046181 918 g_ucConnectionBSSID[1],g_ucConnectionBSSID[2],
dflet 3:a8c249046181 919 g_ucConnectionBSSID[3],g_ucConnectionBSSID[4],
dflet 3:a8c249046181 920 g_ucConnectionBSSID[5]);
dflet 3:a8c249046181 921 Uart_Write((uint8_t *) print_buf);
dflet 3:a8c249046181 922 }
dflet 3:a8c249046181 923 memset(g_ucConnectionSSID,0,sizeof(g_ucConnectionSSID));
dflet 3:a8c249046181 924 memset(g_ucConnectionBSSID,0,sizeof(g_ucConnectionBSSID));
dflet 3:a8c249046181 925 }
dflet 3:a8c249046181 926 break;
dflet 3:a8c249046181 927
dflet 3:a8c249046181 928 case SL_WLAN_STA_CONNECTED_EVENT: {
dflet 3:a8c249046181 929 _cc3100_.SET_STATUS_BIT(g_Status, STATUS_BIT_STA_CONNECTED);
dflet 3:a8c249046181 930 }
dflet 3:a8c249046181 931 break;
dflet 3:a8c249046181 932
dflet 3:a8c249046181 933 case SL_WLAN_STA_DISCONNECTED_EVENT: {
dflet 3:a8c249046181 934 _cc3100_.CLR_STATUS_BIT(g_Status, STATUS_BIT_STA_CONNECTED);
dflet 3:a8c249046181 935 _cc3100_.CLR_STATUS_BIT(g_Status, STATUS_BIT_IP_LEASED);
dflet 3:a8c249046181 936 }
dflet 3:a8c249046181 937 break;
dflet 3:a8c249046181 938
dflet 3:a8c249046181 939 default: {
dflet 3:a8c249046181 940 memset(print_buf, 0x00, PRINT_BUF_LEN);
dflet 3:a8c249046181 941 sprintf((char*) print_buf, "[WLAN EVENT] Unexpected event [0x%x]\n\r",pWlanEvent->Event);
dflet 3:a8c249046181 942 Uart_Write((uint8_t *) print_buf);
dflet 3:a8c249046181 943 }
dflet 3:a8c249046181 944 break;
dflet 3:a8c249046181 945 }
dflet 3:a8c249046181 946 }
dflet 3:a8c249046181 947 #endif
dflet 3:a8c249046181 948
dflet 3:a8c249046181 949 /*!
dflet 3:a8c249046181 950 \brief This function handles events for IP address acquisition via DHCP
dflet 3:a8c249046181 951 indication
dflet 3:a8c249046181 952
dflet 3:a8c249046181 953 \param[in] pNetAppEvent is the event passed to the handler
dflet 3:a8c249046181 954
dflet 3:a8c249046181 955 \return None
dflet 3:a8c249046181 956
dflet 3:a8c249046181 957 \note
dflet 3:a8c249046181 958
dflet 3:a8c249046181 959 \warning
dflet 3:a8c249046181 960 */
dflet 3:a8c249046181 961 #if (defined(sl_NetAppEvtHdlr))
dflet 3:a8c249046181 962 void SimpleLinkNetAppEventHandler(SlNetAppEvent_t *pNetAppEvent)
dflet 3:a8c249046181 963 {
dflet 3:a8c249046181 964
dflet 3:a8c249046181 965 if(pNetAppEvent == NULL){
dflet 3:a8c249046181 966 Uart_Write((uint8_t *)" [NETAPP EVENT] NULL Pointer Error \n\r");
dflet 3:a8c249046181 967 }
dflet 3:a8c249046181 968
dflet 3:a8c249046181 969 switch(pNetAppEvent->Event) {
dflet 3:a8c249046181 970 case SL_NETAPP_IPV4_IPACQUIRED_EVENT: {
dflet 3:a8c249046181 971 SlIpV4AcquiredAsync_t *pEventData = NULL;
dflet 3:a8c249046181 972 _cc3100_.SET_STATUS_BIT(g_Status, STATUS_BIT_IP_ACQUIRED);
dflet 3:a8c249046181 973 pEventData = &pNetAppEvent->EventData.ipAcquiredV4;
dflet 3:a8c249046181 974 g_GatewayIP = pEventData->gateway;
dflet 3:a8c249046181 975
dflet 3:a8c249046181 976 memset(print_buf, 0x00, PRINT_BUF_LEN);
dflet 3:a8c249046181 977 sprintf((char*) print_buf, "[NETAPP EVENT] IP Acquired: IP=%d.%d.%d.%d , ""Gateway=%d.%d.%d.%d\n\r",
dflet 3:a8c249046181 978 _cc3100_._netcfg.SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.ip,3),
dflet 3:a8c249046181 979 _cc3100_._netcfg.SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.ip,2),
dflet 3:a8c249046181 980 _cc3100_._netcfg.SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.ip,1),
dflet 3:a8c249046181 981 _cc3100_._netcfg.SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.ip,0),
dflet 3:a8c249046181 982 _cc3100_._netcfg.SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.gateway,3),
dflet 3:a8c249046181 983 _cc3100_._netcfg.SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.gateway,2),
dflet 3:a8c249046181 984 _cc3100_._netcfg.SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.gateway,1),
dflet 3:a8c249046181 985 _cc3100_._netcfg.SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.gateway,0));
dflet 3:a8c249046181 986 Uart_Write((uint8_t *) print_buf);
dflet 3:a8c249046181 987
dflet 3:a8c249046181 988 }
dflet 3:a8c249046181 989 break;
dflet 3:a8c249046181 990
dflet 3:a8c249046181 991 case SL_NETAPP_IP_LEASED_EVENT: {
dflet 3:a8c249046181 992 g_StationIP = pNetAppEvent->EventData.ipLeased.ip_address;
dflet 3:a8c249046181 993 _cc3100_.SET_STATUS_BIT(g_Status, STATUS_BIT_IP_LEASED);
dflet 3:a8c249046181 994
dflet 3:a8c249046181 995 }
dflet 3:a8c249046181 996 break;
dflet 3:a8c249046181 997
dflet 3:a8c249046181 998 default: {
dflet 3:a8c249046181 999 memset(print_buf, 0x00, PRINT_BUF_LEN);
dflet 3:a8c249046181 1000 sprintf((char*) print_buf, "[NETAPP EVENT] Unexpected event [0x%x] \n\r",pNetAppEvent->Event);
dflet 3:a8c249046181 1001 Uart_Write((uint8_t *) print_buf);
dflet 3:a8c249046181 1002 }
dflet 3:a8c249046181 1003 break;
dflet 3:a8c249046181 1004 }
dflet 3:a8c249046181 1005 }
dflet 3:a8c249046181 1006 #endif
dflet 3:a8c249046181 1007
dflet 3:a8c249046181 1008 /*!
dflet 3:a8c249046181 1009 \brief This function handles socket events indication
dflet 3:a8c249046181 1010
dflet 3:a8c249046181 1011 \param[in] pSock is the event passed to the handler
dflet 3:a8c249046181 1012
dflet 3:a8c249046181 1013 \return None
dflet 3:a8c249046181 1014 */
dflet 3:a8c249046181 1015 #if (defined(sl_SockEvtHdlr))
dflet 3:a8c249046181 1016 void SimpleLinkSockEventHandler(SlSockEvent_t *pSock)
dflet 3:a8c249046181 1017 {
dflet 3:a8c249046181 1018 if(pSock == NULL)
dflet 3:a8c249046181 1019 Uart_Write((uint8_t *)" [SOCK EVENT] NULL Pointer Error \n\r");
dflet 3:a8c249046181 1020
dflet 3:a8c249046181 1021 switch( pSock->Event )
dflet 3:a8c249046181 1022 {
dflet 3:a8c249046181 1023 case SL_SOCKET_TX_FAILED_EVENT:
dflet 3:a8c249046181 1024 /*
dflet 3:a8c249046181 1025 * TX Failed
dflet 3:a8c249046181 1026 *
dflet 3:a8c249046181 1027 * Information about the socket descriptor and status will be
dflet 3:a8c249046181 1028 * available in 'SlSockEventData_t' - Applications can use it if
dflet 3:a8c249046181 1029 * required
dflet 3:a8c249046181 1030 *
dflet 3:a8c249046181 1031 * SlSockEventData_t *pEventData = NULL;
dflet 3:a8c249046181 1032 * pEventData = & pSock->EventData;
dflet 3:a8c249046181 1033 */
dflet 3:a8c249046181 1034
dflet 3:a8c249046181 1035 switch( pSock->socketAsyncEvent.SockTxFailData.status )
dflet 3:a8c249046181 1036 {
dflet 3:a8c249046181 1037 case SL_ECLOSE:
dflet 3:a8c249046181 1038 Uart_Write((uint8_t *)" [SOCK EVENT] Close socket operation, failed to transmit all queued packets\n\r");
dflet 3:a8c249046181 1039 break;
dflet 3:a8c249046181 1040 default:
dflet 3:a8c249046181 1041 memset(print_buf, 0x00, PRINT_BUF_LEN);
dflet 3:a8c249046181 1042 sprintf((char*) print_buf, "[SOCK ERROR] - TX FAILED : socket %d , reason""(%d) \n\n", pSock->socketAsyncEvent.SockTxFailData.sd, pSock->socketAsyncEvent.SockTxFailData.status);
dflet 3:a8c249046181 1043 Uart_Write((uint8_t *) print_buf);
dflet 3:a8c249046181 1044 break;
dflet 3:a8c249046181 1045 }
dflet 3:a8c249046181 1046 break;
dflet 3:a8c249046181 1047
dflet 3:a8c249046181 1048 default:
dflet 3:a8c249046181 1049 memset(print_buf, 0x00, PRINT_BUF_LEN);
dflet 3:a8c249046181 1050 sprintf((char*) print_buf, "[SOCK EVENT] - Unexpected Event [%x0x]\n\n",pSock->Event);
dflet 3:a8c249046181 1051 Uart_Write((uint8_t *) print_buf);
dflet 3:a8c249046181 1052 break;
dflet 3:a8c249046181 1053 }
dflet 3:a8c249046181 1054 }
dflet 3:a8c249046181 1055 #endif
dflet 3:a8c249046181 1056
dflet 3:a8c249046181 1057 /*!
dflet 3:a8c249046181 1058 \brief This function handles callback for the HTTP server events
dflet 3:a8c249046181 1059
dflet 3:a8c249046181 1060 \param[in] pHttpEvent - Contains the relevant event information
dflet 3:a8c249046181 1061 \param[in] pHttpResponse - Should be filled by the user with the
dflet 3:a8c249046181 1062 relevant response information
dflet 3:a8c249046181 1063
dflet 3:a8c249046181 1064 \return None
dflet 3:a8c249046181 1065
dflet 3:a8c249046181 1066 \note
dflet 3:a8c249046181 1067
dflet 3:a8c249046181 1068 \warning
dflet 3:a8c249046181 1069 */
dflet 3:a8c249046181 1070 #if (defined(sl_HttpServerCallback))
dflet 3:a8c249046181 1071 void SimpleLinkHttpServerCallback(SlHttpServerEvent_t *pHttpEvent, SlHttpServerResponse_t *pHttpResponse)
dflet 3:a8c249046181 1072 {
dflet 3:a8c249046181 1073 /*
dflet 3:a8c249046181 1074 * This application doesn't work with HTTP server - Hence these
dflet 3:a8c249046181 1075 * events are not handled here
dflet 3:a8c249046181 1076 */
dflet 3:a8c249046181 1077 Uart_Write((uint8_t *)" [HTTP EVENT] Unexpected event \n\r");
dflet 3:a8c249046181 1078 }
dflet 3:a8c249046181 1079 #endif
dflet 3:a8c249046181 1080 /*!
dflet 3:a8c249046181 1081 \brief This function handles general error events indication
dflet 3:a8c249046181 1082
dflet 3:a8c249046181 1083 \param[in] pDevEvent is the event passed to the handler
dflet 3:a8c249046181 1084
dflet 3:a8c249046181 1085 \return None
dflet 3:a8c249046181 1086 */
dflet 3:a8c249046181 1087 #if (defined(sl_GeneralEvtHdlr))
dflet 3:a8c249046181 1088 void SimpleLinkGeneralEventHandler(SlDeviceEvent_t *pDevEvent)
dflet 3:a8c249046181 1089 {
dflet 3:a8c249046181 1090 /*
dflet 3:a8c249046181 1091 * Most of the general errors are not FATAL are are to be handled
dflet 3:a8c249046181 1092 * appropriately by the application
dflet 3:a8c249046181 1093 */
dflet 3:a8c249046181 1094 memset(print_buf, 0x00, PRINT_BUF_LEN);
dflet 3:a8c249046181 1095 sprintf((char*) print_buf, "[GENERAL EVENT] - ID=[%d] Sender=[%d]\n\n", pDevEvent->EventData.deviceEvent.status, pDevEvent->EventData.deviceEvent.sender);
dflet 3:a8c249046181 1096 Uart_Write((uint8_t *) print_buf);
dflet 3:a8c249046181 1097 }
dflet 3:a8c249046181 1098 #endif
dflet 3:a8c249046181 1099
dflet 3:a8c249046181 1100 #ifdef __cplusplus
dflet 3:a8c249046181 1101 }
dflet 3:a8c249046181 1102 #endif /* __cplusplus */
dflet 3:a8c249046181 1103
dflet 3:a8c249046181 1104 //}//namespace