David Fletcher / Mbed 2 deprecated cc3100_Test_Demo

Dependencies:   mbed

Revision:
0:e89ba455dbcf
Child:
1:c73566c6788a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/G_functions/fPtr_func.cpp	Tue Feb 10 12:09:29 2015 +0000
@@ -0,0 +1,746 @@
+/*
+ *  - CC31xx/CC32xx Host Driver Implementation
+ *
+ * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions
+ *  are met:
+ *
+ *    Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ *    Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the
+ *    distribution.
+ *
+ *    Neither the name of Texas Instruments Incorporated nor the names of
+ *    its contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+*/
+//#include "mbed.h"
+#include "cc3100_simplelink.h"
+//#include "cc3100_sl_common.h"
+//#include "cc3100_protocol.h"
+
+//#include "cc3100_driver.h"
+//#include "cc3100_nonos.h"
+//#include "cc3100_netapp.h"
+#include "cc3100.h"
+#include "fPtr_func.h"
+
+    
+using namespace mbed_cc3100;    
+    
+cc3100_driver *_driver;
+cc3100_nonos  *_nonos;
+cc3100_netapp *_netapp;
+cc3100        *_cc3100_;
+
+#ifdef __cplusplus
+extern "C" {
+#endif    
+
+/*!
+    \brief This function handles ping report events
+
+    \param[in]      pPingReport holds the ping report statistics
+
+    \return         None
+
+    \note
+
+    \warning
+*/
+void SimpleLinkPingReport(SlPingReport_t *pPingReport)
+{
+    _cc3100_->SET_STATUS_BIT(g_Status, STATUS_BIT_PING_DONE);
+
+    if(pPingReport == NULL)
+        printf(" [PING REPORT] NULL Pointer Error\r\n");
+
+    g_PingPacketsRecv = pPingReport->PacketsReceived;
+}
+
+
+/*******************************************************************************/
+/*   _sl_HandleAsync_Accept */
+/*******************************************************************************/
+void _sl_HandleAsync_Accept(void *pVoidBuf)
+{
+    //printf("_sl_HandleAsync_Accept\r\n");
+    _SocketAddrResponse_u *pMsgArgs = (_SocketAddrResponse_u *)_SL_RESP_ARGS_START(pVoidBuf);
+
+    OSI_RET_OK_CHECK(_nonos->sl_LockObjLock(&g_pCB->ProtectionLockObj, NON_OS_LOCK_OBJ_UNLOCK_VALUE, NON_OS_LOCK_OBJ_LOCK_VALUE, SL_OS_WAIT_FOREVER));
+
+    VERIFY_PROTOCOL(( pMsgArgs->IpV4.sd & BSD_SOCKET_ID_MASK) <= SL_MAX_SOCKETS);
+    VERIFY_SOCKET_CB(NULL != g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs);
+
+    memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs,sizeof(_SocketAddrResponse_u));
+    OSI_RET_OK_CHECK(_nonos->sl_SyncObjSignal(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj, NON_OS_SYNC_OBJ_SIGNAL_VALUE));
+
+    OSI_RET_OK_CHECK(_nonos->sl_LockObjUnlock(&g_pCB->ProtectionLockObj, NON_OS_LOCK_OBJ_UNLOCK_VALUE));
+    return;
+}
+
+/*******************************************************************************/
+/*   _sl_HandleAsync_Connect */
+/*******************************************************************************/
+void _sl_HandleAsync_Connect(void *pVoidBuf)
+{
+    //printf("_sl_HandleAsync_Connect\r\n");
+    _SocketResponse_t *pMsgArgs = (_SocketResponse_t *)_SL_RESP_ARGS_START(pVoidBuf);
+
+    OSI_RET_OK_CHECK(_nonos->sl_LockObjLock(&g_pCB->ProtectionLockObj, NON_OS_LOCK_OBJ_UNLOCK_VALUE, NON_OS_LOCK_OBJ_LOCK_VALUE, SL_OS_WAIT_FOREVER));
+
+    VERIFY_PROTOCOL((pMsgArgs->sd & BSD_SOCKET_ID_MASK) <= SL_MAX_SOCKETS);
+    VERIFY_SOCKET_CB(NULL != g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs);
+
+    ((_SocketResponse_t *)(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs))->sd = pMsgArgs->sd;
+    ((_SocketResponse_t *)(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs))->statusOrLen = pMsgArgs->statusOrLen;
+
+    OSI_RET_OK_CHECK(_nonos->sl_SyncObjSignal(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj, NON_OS_SYNC_OBJ_SIGNAL_VALUE));
+    OSI_RET_OK_CHECK(_nonos->sl_LockObjUnlock(&g_pCB->ProtectionLockObj, NON_OS_LOCK_OBJ_UNLOCK_VALUE));
+    return;
+}
+
+/*******************************************************************************/
+/*   _sl_HandleAsync_Select */
+/*******************************************************************************/
+void _sl_HandleAsync_Select(void *pVoidBuf)
+{
+    //printf("_sl_HandleAsync_Select\r\n");
+    _SelectAsyncResponse_t *pMsgArgs = (_SelectAsyncResponse_t *)_SL_RESP_ARGS_START(pVoidBuf);
+
+    OSI_RET_OK_CHECK(_nonos->sl_LockObjLock(&g_pCB->ProtectionLockObj, NON_OS_LOCK_OBJ_UNLOCK_VALUE, NON_OS_LOCK_OBJ_LOCK_VALUE, SL_OS_WAIT_FOREVER));
+
+    VERIFY_SOCKET_CB(NULL != g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs);
+
+    memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs, sizeof(_SelectAsyncResponse_t));
+    OSI_RET_OK_CHECK(_nonos->sl_SyncObjSignal(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj, NON_OS_SYNC_OBJ_SIGNAL_VALUE));
+
+    OSI_RET_OK_CHECK(_nonos->sl_LockObjUnlock(&g_pCB->ProtectionLockObj, NON_OS_LOCK_OBJ_UNLOCK_VALUE));
+    return;
+}
+
+/******************************************************************************/
+/*  _sl_HandleAsync_DnsGetHostByName */
+/******************************************************************************/
+void _sl_HandleAsync_DnsGetHostByName(void *pVoidBuf)
+{
+    //printf("_sl_HandleAsync_DnsGetHostByName\r\n");
+    _GetHostByNameIPv4AsyncResponse_t *pMsgArgs = (_GetHostByNameIPv4AsyncResponse_t *)_SL_RESP_ARGS_START(pVoidBuf);
+
+    OSI_RET_OK_CHECK(_nonos->sl_LockObjLock(&g_pCB->ProtectionLockObj, NON_OS_LOCK_OBJ_UNLOCK_VALUE, NON_OS_LOCK_OBJ_LOCK_VALUE, SL_OS_WAIT_FOREVER));
+
+    VERIFY_SOCKET_CB(NULL != g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs);
+
+    /*IPv6 */
+    if(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].AdditionalData & SL_NETAPP_FAMILY_MASK) {
+        memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs, sizeof(_GetHostByNameIPv6AsyncResponse_t));
+    }
+    /*IPv4 */
+    else {
+        memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs, sizeof(_GetHostByNameIPv4AsyncResponse_t));
+    }
+    OSI_RET_OK_CHECK(_nonos->sl_SyncObjSignal(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj, NON_OS_SYNC_OBJ_SIGNAL_VALUE));
+
+    OSI_RET_OK_CHECK(_nonos->sl_LockObjUnlock(&g_pCB->ProtectionLockObj, NON_OS_LOCK_OBJ_UNLOCK_VALUE));
+    return;
+}
+
+/******************************************************************************/
+
+/******************************************************************************
+    _sl_HandleAsync_DnsGetHostByService
+
+    CALLER          NWP - Async event on sl_DnsGetHostByService with IPv4 Family
+
+
+    DESCRIPTION:
+
+                    Async event on sl_DnsGetHostByService command with IPv4 Family.
+                    Return service attributes like IP address, port and text according to service name.
+                    The user sets a service name Full/Part (see example below), and should get the:
+                    1. IP of the service
+                    2. The port of service.
+                    3. The text of service.
+
+                    Hence it can make a connection to the specific service and use it.
+                    It is similar to get host by name method.
+
+                    It is done by a single shot query with PTR type on the service name.
+
+
+
+                    Note:
+                    1. The return's attributes are belonged to first service that is found.
+                    It can be other services with the same service name will response to
+                    the query. The results of these responses are saved in the peer cache of the NWP, and
+                    should be read by another API.
+
+
+        PARAMETERS:
+
+                  pVoidBuf - is point to opcode of the event.
+                  it contains the outputs that are given to the user
+
+                  outputs description:
+
+                   1.out_pAddr[]                    - output: Contain the IP address of the service.
+                   2.out_pPort                      - output: Contain the port of the service.
+                   3.inout_TextLen                  - Input:  Contain the max length of the text that the user wants to get.
+                                                              it means that if the test of service is bigger that its value than
+                                                              the text is cut to inout_TextLen value.
+                                                      Output: Contain the length of the text that is returned. Can be full text or part
+                                                              of the text (see above).
+
+                   4.out_pText                      - Contain the text of the service (full or part see above- inout_TextLen description).
+
+  *
+
+
+    RETURNS:        success or fail.
+
+******************************************************************************/
+void _sl_HandleAsync_DnsGetHostByService(void *pVoidBuf)
+{
+    //printf("_sl_HandleAsync_DnsGetHostByService\r\n");
+    _GetHostByServiceAsyncResponse_t* Res;
+    uint16_t TextLen;
+    uint16_t UserTextLen;
+
+    /*pVoidBuf - is point to opcode of the event.*/
+
+    /*set pMsgArgs to point to the attribute of the event.*/
+    _GetHostByServiceIPv4AsyncResponse_t *pMsgArgs = (_GetHostByServiceIPv4AsyncResponse_t *)_SL_RESP_ARGS_START(pVoidBuf);
+
+    VERIFY_SOCKET_CB(NULL != g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs);
+
+    /*IPv6*/
+    if(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].AdditionalData & SL_NETAPP_FAMILY_MASK) {
+        return;
+    }
+    /*IPv4*/
+    else {
+        /*************************************************************************************************
+
+        1. Copy the attribute part of the evnt to the attribute part of the response
+        memcpy(g_pCB->GetHostByServiceCB.pAsyncRsp, pMsgArgs, sizeof(_GetHostByServiceIPv4AsyncResponse_t));
+
+        set to TextLen the text length of the service.*/
+        TextLen = pMsgArgs->TextLen;
+
+        /*Res pointed to mDNS global object struct */
+        Res = (_GetHostByServiceAsyncResponse_t*)g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs;
+
+
+
+        /*It is 4 bytes so we avoid from memcpy*/
+        Res->out_pAddr[0]   = pMsgArgs->Address;
+        Res->out_pPort[0]   = pMsgArgs->Port;
+        Res->Status         = pMsgArgs->Status;
+
+        /*set to TextLen the text length of the user (input fromthe user).*/
+        UserTextLen = Res->inout_TextLen[0];
+
+        /*Cut the service text if the user requested for smaller text.*/
+        UserTextLen = (TextLen <= UserTextLen) ? TextLen : UserTextLen;
+        Res->inout_TextLen[0] = UserTextLen ;
+
+        /**************************************************************************************************
+
+        2. Copy the payload part of the evnt (the text) to the payload part of the response
+        the lenght of the copy is according to the text length in the attribute part. */
+
+
+        memcpy(Res->out_pText          ,
+                  (int8_t *)(& pMsgArgs[1]),   /* & pMsgArgs[1] -> 1st byte after the fixed header = 1st byte of variable text.*/
+                  UserTextLen);
+
+
+        /**************************************************************************************************/
+
+        OSI_RET_OK_CHECK(_nonos->sl_SyncObjSignal(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj, NON_OS_SYNC_OBJ_SIGNAL_VALUE));
+        return;
+    }
+}
+
+/*****************************************************************************/
+/*  _sl_HandleAsync_PingResponse */
+/*****************************************************************************/
+void _sl_HandleAsync_PingResponse(void *pVoidBuf)
+{
+    //printf("_sl_HandleAsync_PingResponse\r\n");
+    _PingReportResponse_t *pMsgArgs  = (_PingReportResponse_t *)_SL_RESP_ARGS_START(pVoidBuf);
+    SlPingReport_t pingReport;
+
+    if(pPingCallBackFunc) {
+        _netapp->CopyPingResultsToReport(pMsgArgs,&pingReport);
+        pPingCallBackFunc(&pingReport);
+    } else {
+
+        OSI_RET_OK_CHECK(_nonos->sl_LockObjLock(&g_pCB->ProtectionLockObj, NON_OS_LOCK_OBJ_UNLOCK_VALUE,NON_OS_LOCK_OBJ_LOCK_VALUE, SL_OS_WAIT_FOREVER));
+        VERIFY_SOCKET_CB(NULL != g_pCB->PingCB.PingAsync.pAsyncRsp);
+
+        if (NULL != g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs) {
+            memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs, sizeof(_PingReportResponse_t));
+            OSI_RET_OK_CHECK(_nonos->sl_SyncObjSignal(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj, NON_OS_SYNC_OBJ_SIGNAL_VALUE));
+        }
+        OSI_RET_OK_CHECK(_nonos->sl_LockObjUnlock(&g_pCB->ProtectionLockObj, NON_OS_LOCK_OBJ_UNLOCK_VALUE));
+    }
+    return;
+}
+
+/* ******************************************************************************/
+/*  _SlDrvMsgReadSpawnCtx                                                       */
+/* ******************************************************************************/
+_SlReturnVal_t _SlDrvMsgReadSpawnCtx(void *pValue)
+{
+    //printf("_SlDrvMsgReadSpawnCtx\r\n");
+
+#ifdef SL_POLLING_MODE_USED
+    int16_t retCode = OSI_OK;
+    /*  for polling based systems */
+    do {
+        retCode = sl_LockObjLock(&g_pCB->GlobalLockObj, 0);
+        if ( OSI_OK != retCode ) {
+            if (TRUE == g_pCB->IsCmdRespWaited) {
+                OSI_RET_OK_CHECK( sl_SyncObjSignal(&g_pCB->CmdSyncObj) );
+                return SL_RET_CODE_OK;
+                //return;
+            }
+        }
+
+    } while (OSI_OK != retCode);
+
+#else
+    
+    OSI_RET_OK_CHECK(_nonos->sl_LockObjLock(&g_pCB->GlobalLockObj, NON_OS_LOCK_OBJ_UNLOCK_VALUE, NON_OS_LOCK_OBJ_LOCK_VALUE, SL_OS_WAIT_FOREVER) );
+    
+#endif
+    
+    g_pCB->FunctionParams.AsyncExt.pAsyncBuf = NULL;/*  buffer must be allocated by _SlDrvMsgRead */
+    g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler= NULL;
+    g_pCB->FunctionParams.AsyncExt.RxMsgClass = CMD_RESP_CLASS;/* init to illegal value and verify it's overwritten with the valid one */
+
+    /*  Messages might have been read by CmdResp context. Therefore after */
+    /*  getting LockObj, check again where the Pending Rx Msg is still present. */
+    if(FALSE == (_driver->_SL_PENDING_RX_MSG(g_pCB))) {
+        OSI_RET_OK_CHECK(_nonos->sl_LockObjUnlock(&g_pCB->GlobalLockObj, NON_OS_LOCK_OBJ_UNLOCK_VALUE));
+        return SL_RET_CODE_OK;
+        //return;
+    }
+   
+    VERIFY_RET_OK(_driver->_SlDrvMsgRead());
+
+    g_pCB->RxDoneCnt++;
+
+    switch(g_pCB->FunctionParams.AsyncExt.RxMsgClass) {
+        case ASYNC_EVT_CLASS:
+            /*  If got here and protected by LockObj a message is waiting  */
+            /*  to be read */
+            VERIFY_PROTOCOL(NULL != g_pCB->FunctionParams.AsyncExt.pAsyncBuf);
+
+            _driver->_SlAsyncEventGenericHandler();
+
+#if (SL_MEMORY_MGMT == SL_MEMORY_MGMT_STATIC)
+            g_pCB->FunctionParams.AsyncExt.pAsyncBuf = NULL;
+#else
+            free(g_pCB->FunctionParams.AsyncExt.pAsyncBuf);
+#endif
+            break;
+        case DUMMY_MSG_CLASS:
+        case RECV_RESP_CLASS:
+            /* These types are legal in this context. Do nothing */
+            break;
+        case CMD_RESP_CLASS:
+            /* Command response is illegal in this context. */
+            /* No 'break' here: Assert! */
+        default:
+            VERIFY_PROTOCOL(0);
+    }
+
+    OSI_RET_OK_CHECK(_nonos->sl_LockObjUnlock(&g_pCB->GlobalLockObj, NON_OS_LOCK_OBJ_UNLOCK_VALUE));
+
+    return(SL_RET_CODE_OK);   
+    //return;
+}
+
+/***************************************************************************
+_sl_HandleAsync_Stop - handles stop signalling to
+a waiting object
+****************************************************************************/
+void _sl_HandleAsync_Stop(void *pVoidBuf)
+{
+    //printf("_SlDrvNetAppEventHandler\r\n");
+    _BasicResponse_t *pMsgArgs = (_BasicResponse_t *)_SL_RESP_ARGS_START(pVoidBuf);
+
+    VERIFY_SOCKET_CB(NULL != g_pCB->StopCB.pAsyncRsp);
+
+    OSI_RET_OK_CHECK(_nonos->sl_LockObjLock(&g_pCB->ProtectionLockObj, NON_OS_LOCK_OBJ_UNLOCK_VALUE,NON_OS_LOCK_OBJ_LOCK_VALUE, SL_OS_WAIT_FOREVER));
+
+    memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs, sizeof(_BasicResponse_t));
+    OSI_RET_OK_CHECK(_nonos->sl_SyncObjSignal(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj, NON_OS_SYNC_OBJ_SIGNAL_VALUE));
+    OSI_RET_OK_CHECK(_nonos->sl_LockObjUnlock(&g_pCB->ProtectionLockObj, NON_OS_LOCK_OBJ_UNLOCK_VALUE));
+    return;
+}
+
+/******************************************************************************
+_SlDrvDeviceEventHandler - handles internally device async events
+******************************************************************************/
+void _SlDrvDeviceEventHandler(void *pArgs)
+{
+    //printf("_SlDrvDeviceEventHandler\r\n");
+    _SlResponseHeader_t *pHdr = (_SlResponseHeader_t *)pArgs;
+    //printf("Debug pHdr->GenHeader.Opcode 0x%X\r\n",pHdr->GenHeader.Opcode);
+    switch(pHdr->GenHeader.Opcode) {
+        case SL_OPCODE_DEVICE_INITCOMPLETE:
+            _cc3100_->_sl_HandleAsync_InitComplete(pHdr);
+            //printf("_SlDrvDeviceEventHandler 2\r\n");
+            break;
+        case SL_OPCODE_DEVICE_STOP_ASYNC_RESPONSE:
+            _sl_HandleAsync_Stop(pHdr);
+            //printf("_SlDrvDeviceEventHandler 3\r\n");
+            break;
+        case  SL_OPCODE_DEVICE_DEVICEASYNCFATALERROR:
+#ifdef sl_GeneralEvtHdlr
+        {
+            _BasicResponse_t *pMsgArgs = (_BasicResponse_t *)_SL_RESP_ARGS_START(pHdr);
+            SlDeviceEvent_t devHandler;
+            devHandler.Event = SL_DEVICE_FATAL_ERROR_EVENT;
+            devHandler.EventData.deviceEvent.status = pMsgArgs->status & 0xFF;
+            devHandler.EventData.deviceEvent.sender = (SlErrorSender_e)((pMsgArgs->status >> 8) & 0xFF);
+            SimpleLinkGeneralEventHandler(&devHandler);
+            //printf("_SlDrvDeviceEventHandler 4\r\n");
+        }
+#endif
+        break;
+        default:
+            //SL_ERROR_TRACE2(MSG_306, "ASSERT: _SlDrvDeviceEventHandler : invalid opcode = 0x%x = %i", pHdr->GenHeader.Opcode, pHdr->GenHeader.Opcode);
+            printf("ASSERT: _SlDrvDeviceEventHandler : invalid opcode = 0x%x = %i", pHdr->GenHeader.Opcode, pHdr->GenHeader.Opcode);
+            VERIFY_PROTOCOL(0);
+    }
+}
+
+/*****************************************************************************/
+/* _SlDrvNetAppEventHandler */
+/*****************************************************************************/
+void _SlDrvNetAppEventHandler(void *pArgs)
+{
+    //printf("_SlDrvNetAppEventHandler\r\n");
+    _SlResponseHeader_t *pHdr = (_SlResponseHeader_t *)pArgs;
+#ifdef sl_HttpServerCallback
+    SlHttpServerEvent_t     httpServerEvent;
+    SlHttpServerResponse_t  httpServerResponse;
+#endif
+    switch(pHdr->GenHeader.Opcode) {
+        case SL_OPCODE_NETAPP_DNSGETHOSTBYNAMEASYNCRESPONSE:
+        case SL_OPCODE_NETAPP_DNSGETHOSTBYNAMEASYNCRESPONSE_V6:
+            _sl_HandleAsync_DnsGetHostByName(pArgs);
+            break;
+        case SL_OPCODE_NETAPP_MDNSGETHOSTBYSERVICEASYNCRESPONSE:
+        case SL_OPCODE_NETAPP_MDNSGETHOSTBYSERVICEASYNCRESPONSE_V6:
+            _sl_HandleAsync_DnsGetHostByService(pArgs);
+            break;
+        case SL_OPCODE_NETAPP_PINGREPORTREQUESTRESPONSE:
+            _sl_HandleAsync_PingResponse(pArgs);
+            break;
+        case SL_OPCODE_NETAPP_HTTPGETTOKENVALUE: {
+#ifdef sl_HttpServerCallback
+            uint8_t *pTokenName;
+            slHttpServerData_t Token_value;
+            sl_NetAppHttpServerGetToken_t *httpGetToken = (sl_NetAppHttpServerGetToken_t *)_SL_RESP_ARGS_START(pHdr);
+            pTokenName = (uint8_t *)((sl_NetAppHttpServerGetToken_t *)httpGetToken + 1);
+
+            httpServerResponse.Response = SL_NETAPP_HTTPSETTOKENVALUE;
+            httpServerResponse.ResponseData.token_value.len = MAX_TOKEN_VALUE_LEN;
+            httpServerResponse.ResponseData.token_value.data = (uint8_t *)_SL_RESP_ARGS_START(pHdr) + MAX_TOKEN_NAME_LEN; //Reuse the async buffer for getting the token value response from the user
+
+            httpServerEvent.Event = SL_NETAPP_HTTPGETTOKENVALUE_EVENT;
+            httpServerEvent.EventData.httpTokenName.len = httpGetToken->token_name_len;
+            httpServerEvent.EventData.httpTokenName.data = pTokenName;
+
+            Token_value.token_name =  pTokenName;
+
+            SimpleLinkHttpServerCallback(&httpServerEvent, &httpServerResponse);
+
+            Token_value.value_len = httpServerResponse.ResponseData.token_value.len;
+            Token_value.name_len = httpServerEvent.EventData.httpTokenName.len;
+
+            Token_value.token_value = httpServerResponse.ResponseData.token_value.data;
+
+
+            _netapp->sl_NetAppSendTokenValue(&Token_value);
+#endif
+        }
+        break;
+
+        case SL_OPCODE_NETAPP_HTTPPOSTTOKENVALUE: {
+#ifdef sl_HttpServerCallback
+            uint8_t *pPostParams;
+
+            sl_NetAppHttpServerPostToken_t *httpPostTokenArgs = (sl_NetAppHttpServerPostToken_t *)_SL_RESP_ARGS_START(pHdr);
+            pPostParams = (uint8_t *)((sl_NetAppHttpServerPostToken_t *)httpPostTokenArgs + 1);
+
+            httpServerEvent.Event = SL_NETAPP_HTTPPOSTTOKENVALUE_EVENT;
+
+            httpServerEvent.EventData.httpPostData.action.len = httpPostTokenArgs->post_action_len;
+            httpServerEvent.EventData.httpPostData.action.data = pPostParams;
+            pPostParams+=httpPostTokenArgs->post_action_len;
+
+            httpServerEvent.EventData.httpPostData.token_name.len = httpPostTokenArgs->token_name_len;
+            httpServerEvent.EventData.httpPostData.token_name.data = pPostParams;
+            pPostParams+=httpPostTokenArgs->token_name_len;
+
+            httpServerEvent.EventData.httpPostData.token_value.len = httpPostTokenArgs->token_value_len;
+            httpServerEvent.EventData.httpPostData.token_value.data = pPostParams;
+
+            httpServerResponse.Response = SL_NETAPP_RESPONSE_NONE;
+
+
+            SimpleLinkHttpServerCallback(&httpServerEvent, &httpServerResponse);
+#endif
+        }
+        break;
+        default:
+            SL_ERROR_TRACE2(MSG_305, "ASSERT: _SlDrvNetAppEventHandler : invalid opcode = 0x%x = %i", pHdr->GenHeader.Opcode, pHdr->GenHeader.Opcode);
+            VERIFY_PROTOCOL(0);
+    }
+}
+
+/*
+ * ASYNCHRONOUS EVENT HANDLERS -- Start
+ */
+
+/*!
+    \brief This function handles WLAN events
+
+    \param[in]      pWlanEvent is the event passed to the handler
+
+    \return         None
+
+    \note
+
+    \warning
+*/
+#if (defined(sl_WlanEvtHdlr))
+void SimpleLinkWlanEventHandler(SlWlanEvent_t *pWlanEvent)
+{
+    
+    //printf("Debug SimpleLinkWlanEventHandler\r\n");
+    if(pWlanEvent == NULL)
+        printf(" [WLAN EVENT] NULL Pointer Error \n\r");
+
+    switch(pWlanEvent->Event) {
+        case SL_WLAN_CONNECT_EVENT: {
+            _cc3100_->SET_STATUS_BIT(g_Status, STATUS_BIT_CONNECTION);
+
+            /*
+             * Information about the connected AP (like name, MAC etc) will be
+             * available in 'slWlanConnectAsyncResponse_t' - Applications
+             * can use it if required
+             *
+             * slWlanConnectAsyncResponse_t *pEventData = NULL;
+             * pEventData = &pWlanEvent->EventData.STAandP2PModeWlanConnected;
+             *
+             */
+        }
+        break;
+
+        case SL_WLAN_DISCONNECT_EVENT: {
+            slWlanConnectAsyncResponse_t*  pEventData = NULL;
+
+            _cc3100_->CLR_STATUS_BIT(g_Status, STATUS_BIT_CONNECTION);
+            _cc3100_->CLR_STATUS_BIT(g_Status, STATUS_BIT_IP_ACQUIRED);
+
+            pEventData = &pWlanEvent->EventData.STAandP2PModeDisconnected;
+
+            /* If the user has initiated 'Disconnect' request, 'reason_code' is SL_USER_INITIATED_DISCONNECTION */
+            if(SL_USER_INITIATED_DISCONNECTION == pEventData->reason_code) {
+                printf(" Device disconnected from the AP on application's request \n\r");
+            } else {
+                printf(" Device disconnected from the AP on an ERROR..!! \n\r");
+            }
+        }
+        break;
+
+        case SL_WLAN_STA_CONNECTED_EVENT: {
+            _cc3100_->SET_STATUS_BIT(g_Status, STATUS_BIT_STA_CONNECTED);
+        }
+        break;
+
+        case SL_WLAN_STA_DISCONNECTED_EVENT: {
+            _cc3100_->CLR_STATUS_BIT(g_Status, STATUS_BIT_STA_CONNECTED);
+            _cc3100_->CLR_STATUS_BIT(g_Status, STATUS_BIT_IP_LEASED);
+        }
+        break;
+
+        default: {
+            printf(" [WLAN EVENT] Unexpected event \n\r");
+        }
+        break;
+    }
+}
+#endif
+
+/*!
+    \brief This function handles events for IP address acquisition via DHCP
+           indication
+
+    \param[in]      pNetAppEvent is the event passed to the handler
+
+    \return         None
+
+    \note
+
+    \warning
+*/
+#if (defined(sl_NetAppEvtHdlr))
+void SimpleLinkNetAppEventHandler(SlNetAppEvent_t *pNetAppEvent)
+{
+    
+    if(pNetAppEvent == NULL){
+        printf(" [NETAPP EVENT] NULL Pointer Error \n\r");
+    }
+    
+    switch(pNetAppEvent->Event) {
+        case SL_NETAPP_IPV4_IPACQUIRED_EVENT: {
+            
+            //printf("SL_NETAPP_IPV4_IPACQUIRED_EVENT \n\r");
+            SlIpV4AcquiredAsync_t *pEventData = NULL;
+            //printf("g_Status 2 = 0x%X\r\n",_cc3100_->g_Status);
+            _cc3100_->SET_STATUS_BIT(g_Status, STATUS_BIT_IP_ACQUIRED);
+            //printf("g_Status 2 = 0x%X\r\n",_cc3100_->g_Status);
+            
+            pEventData = &pNetAppEvent->EventData.ipAcquiredV4;
+            
+            g_GatewayIP = pEventData->gateway;
+            //printf("g_GatewayIP =  = 0x%X\r\n",pEventData->gateway);
+            //printf("Debug 4 SL_NETAPP_IPV4_IPACQUIRED_EVENT \n\r");
+        }
+        break;
+
+        case SL_NETAPP_IP_LEASED_EVENT: {
+            //printf("SL_NETAPP_IP_LEASED_EVENT \n\r");
+            g_StationIP = pNetAppEvent->EventData.ipLeased.ip_address;
+            //_cc3100_->g_Status = 0;
+            _cc3100_->SET_STATUS_BIT(g_Status, STATUS_BIT_IP_LEASED);
+            //printf("g_Status 3 = 0x%X\r\n",_cc3100_->g_Status);
+            
+        }
+        break;
+
+        default: {
+            printf(" [NETAPP EVENT] Unexpected event \n\r");
+        }
+        break;
+    }
+}
+#endif 
+
+/*!
+    \brief This function handles socket events indication
+
+    \param[in]      pSock is the event passed to the handler
+
+    \return         None
+*/
+#if (defined(sl_SockEvtHdlr))
+void SimpleLinkSockEventHandler(SlSockEvent_t *pSock)
+{
+    if(pSock == NULL)
+        printf(" [SOCK EVENT] NULL Pointer Error \n\r");
+    
+    switch( pSock->Event )
+    {
+        case SL_SOCKET_TX_FAILED_EVENT:
+            /*
+             * TX Failed
+             *
+             * Information about the socket descriptor and status will be
+             * available in 'SlSockEventData_t' - Applications can use it if
+             * required
+             *
+             * SlSockEventData_t *pEventData = NULL;
+             * pEventData = & pSock->EventData;
+             */
+            switch( pSock->EventData.status )
+            {
+                case SL_ECLOSE:
+                    printf(" [SOCK EVENT] Close socket operation, failed to transmit all queued packets\n\r");
+                    break;
+                default:
+                    printf(" [SOCK EVENT] Unexpected event \n\r");
+                    break;
+            }
+            break;
+
+        default:
+            printf(" [SOCK EVENT] Unexpected event \n\r");
+            break;
+    }
+}
+#endif
+
+/*!
+    \brief This function handles callback for the HTTP server events
+
+    \param[in]      pHttpEvent - Contains the relevant event information
+    \param[in]      pHttpResponse - Should be filled by the user with the
+                    relevant response information
+
+    \return         None
+
+    \note
+
+    \warning
+*/
+#if (defined(sl_HttpServerCallback))
+void SimpleLinkHttpServerCallback(SlHttpServerEvent_t *pHttpEvent, SlHttpServerResponse_t *pHttpResponse)
+{
+    /*
+     * This application doesn't work with HTTP server - Hence these
+     * events are not handled here
+     */
+    printf(" [HTTP EVENT] Unexpected event \n\r");
+}
+#endif
+/*!
+    \brief This function handles general error events indication
+
+    \param[in]      pDevEvent is the event passed to the handler
+
+    \return         None
+*/
+#if (defined(sl_GeneralEvtHdlr))
+void SimpleLinkGeneralEventHandler(SlDeviceEvent_t *pDevEvent)
+{
+    /*
+     * Most of the general errors are not FATAL are are to be handled
+     * appropriately by the application
+     */
+    printf(" [GENERAL EVENT] \n\r");
+}
+#endif
+
+#ifdef  __cplusplus
+}
+#endif /*  __cplusplus */
+
+//}//namespace