TI's CC3100. A test demo with very little testing done!

Dependencies:   mbed

Fork of cc3100_Test_Demo2 by 高 杨

Committer:
gaoyang
Date:
Sun Jul 30 06:32:08 2017 +0000
Revision:
9:b8da46b97970
Parent:
7:0687d16b9781
DAS

Who changed what in which revision?

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