version_2.0

Dependents:   cc3000_ping_demo_try_2

Fork of cc3000_hostdriver_mbedsocket by Martin Kojtal

Committer:
SolderSplashLabs
Date:
Thu Oct 03 21:00:00 2013 +0000
Revision:
23:fed7f64dd520
Parent:
17:14b6a3a2b622
Child:
26:456f73ed2a75
Added separate debug messages and VT100 formatting

Who changed what in which revision?

UserRevisionLine numberNew contents of line
SolderSplashLabs 23:fed7f64dd520 1 /*****************************************************************************
SolderSplashLabs 23:fed7f64dd520 2 *
SolderSplashLabs 23:fed7f64dd520 3 * C++ interface/implementation created by Martin Kojtal (0xc0170). Thanks to
SolderSplashLabs 23:fed7f64dd520 4 * Jim Carver and Frank Vannieuwkerke for their inital cc3000 mbed port and
SolderSplashLabs 23:fed7f64dd520 5 * provided help.
SolderSplashLabs 23:fed7f64dd520 6 *
SolderSplashLabs 23:fed7f64dd520 7 * This version of "host driver" uses CC3000 Host Driver Implementation. Thus
SolderSplashLabs 23:fed7f64dd520 8 * read the following copyright:
SolderSplashLabs 23:fed7f64dd520 9 *
SolderSplashLabs 23:fed7f64dd520 10 * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
SolderSplashLabs 23:fed7f64dd520 11 *
SolderSplashLabs 23:fed7f64dd520 12 * Redistribution and use in source and binary forms, with or without
SolderSplashLabs 23:fed7f64dd520 13 * modification, are permitted provided that the following conditions
SolderSplashLabs 23:fed7f64dd520 14 * are met:
SolderSplashLabs 23:fed7f64dd520 15 *
SolderSplashLabs 23:fed7f64dd520 16 * Redistributions of source code must retain the above copyright
SolderSplashLabs 23:fed7f64dd520 17 * notice, this list of conditions and the following disclaimer.
SolderSplashLabs 23:fed7f64dd520 18 *
SolderSplashLabs 23:fed7f64dd520 19 * Redistributions in binary form must reproduce the above copyright
SolderSplashLabs 23:fed7f64dd520 20 * notice, this list of conditions and the following disclaimer in the
SolderSplashLabs 23:fed7f64dd520 21 * documentation and/or other materials provided with the
SolderSplashLabs 23:fed7f64dd520 22 * distribution.
SolderSplashLabs 23:fed7f64dd520 23 *
SolderSplashLabs 23:fed7f64dd520 24 * Neither the name of Texas Instruments Incorporated nor the names of
SolderSplashLabs 23:fed7f64dd520 25 * its contributors may be used to endorse or promote products derived
SolderSplashLabs 23:fed7f64dd520 26 * from this software without specific prior written permission.
SolderSplashLabs 23:fed7f64dd520 27 *
SolderSplashLabs 23:fed7f64dd520 28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
SolderSplashLabs 23:fed7f64dd520 29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
SolderSplashLabs 23:fed7f64dd520 30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
SolderSplashLabs 23:fed7f64dd520 31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
SolderSplashLabs 23:fed7f64dd520 32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SolderSplashLabs 23:fed7f64dd520 33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
SolderSplashLabs 23:fed7f64dd520 34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
SolderSplashLabs 23:fed7f64dd520 35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
SolderSplashLabs 23:fed7f64dd520 36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
SolderSplashLabs 23:fed7f64dd520 37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
SolderSplashLabs 23:fed7f64dd520 38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
SolderSplashLabs 23:fed7f64dd520 39 *
SolderSplashLabs 23:fed7f64dd520 40 *****************************************************************************/
SolderSplashLabs 23:fed7f64dd520 41 #include "cc3000.h"
SolderSplashLabs 23:fed7f64dd520 42 #include "cc3000_event.h"
SolderSplashLabs 23:fed7f64dd520 43 #include "cc3000_netapp.h"
SolderSplashLabs 23:fed7f64dd520 44
SolderSplashLabs 23:fed7f64dd520 45 namespace mbed_cc3000 {
SolderSplashLabs 23:fed7f64dd520 46
SolderSplashLabs 23:fed7f64dd520 47 #ifdef CC3000_DEBUG_HCI_RX
SolderSplashLabs 23:fed7f64dd520 48 const char *HCI_EVENT_STR[] =
SolderSplashLabs 23:fed7f64dd520 49 {
SolderSplashLabs 23:fed7f64dd520 50 "Socket",
SolderSplashLabs 23:fed7f64dd520 51 "Bind",
SolderSplashLabs 23:fed7f64dd520 52 "Send",
SolderSplashLabs 23:fed7f64dd520 53 "Recv",
SolderSplashLabs 23:fed7f64dd520 54 "Accept",
SolderSplashLabs 23:fed7f64dd520 55 "Listen",
SolderSplashLabs 23:fed7f64dd520 56 "Connect",
SolderSplashLabs 23:fed7f64dd520 57 "BSD Select",
SolderSplashLabs 23:fed7f64dd520 58 "Set Socket Options",
SolderSplashLabs 23:fed7f64dd520 59 "Get Socket Options",
SolderSplashLabs 23:fed7f64dd520 60 "Close Socket",
SolderSplashLabs 23:fed7f64dd520 61 "Unknown",
SolderSplashLabs 23:fed7f64dd520 62 "Recv From",
SolderSplashLabs 23:fed7f64dd520 63 "Write",
SolderSplashLabs 23:fed7f64dd520 64 "Send To",
SolderSplashLabs 23:fed7f64dd520 65 "Get Hostname",
SolderSplashLabs 23:fed7f64dd520 66 "mDNS Advertise"
SolderSplashLabs 23:fed7f64dd520 67 };
SolderSplashLabs 23:fed7f64dd520 68
SolderSplashLabs 23:fed7f64dd520 69 const char *HCI_NETAPP_STR[] =
SolderSplashLabs 23:fed7f64dd520 70 {
SolderSplashLabs 23:fed7f64dd520 71 "DHCP",
SolderSplashLabs 23:fed7f64dd520 72 "Ping Sent",
SolderSplashLabs 23:fed7f64dd520 73 "Ping Report",
SolderSplashLabs 23:fed7f64dd520 74 "Ping Stop",
SolderSplashLabs 23:fed7f64dd520 75 "IP Config",
SolderSplashLabs 23:fed7f64dd520 76 "ARP Flush",
SolderSplashLabs 23:fed7f64dd520 77 "Unknown",
SolderSplashLabs 23:fed7f64dd520 78 "Set Debug level",
SolderSplashLabs 23:fed7f64dd520 79 "Set Timers"
SolderSplashLabs 23:fed7f64dd520 80 };
SolderSplashLabs 23:fed7f64dd520 81
SolderSplashLabs 23:fed7f64dd520 82 // from 0-7
SolderSplashLabs 23:fed7f64dd520 83 const char *HCI_MISC_STR[] =
SolderSplashLabs 23:fed7f64dd520 84 {
SolderSplashLabs 23:fed7f64dd520 85 "BASE - Error?",
SolderSplashLabs 23:fed7f64dd520 86 "Connecting",
SolderSplashLabs 23:fed7f64dd520 87 "Disconnect",
SolderSplashLabs 23:fed7f64dd520 88 "Scan Param",
SolderSplashLabs 23:fed7f64dd520 89 "Connect Policy",
SolderSplashLabs 23:fed7f64dd520 90 "Add Profile",
SolderSplashLabs 23:fed7f64dd520 91 "Del Profile",
SolderSplashLabs 23:fed7f64dd520 92 "Get Scan Res",
SolderSplashLabs 23:fed7f64dd520 93 "Event Mask",
SolderSplashLabs 23:fed7f64dd520 94 "Status Req",
SolderSplashLabs 23:fed7f64dd520 95 "Config Start",
SolderSplashLabs 23:fed7f64dd520 96 "Config Stop",
SolderSplashLabs 23:fed7f64dd520 97 "Config Set Prefix",
SolderSplashLabs 23:fed7f64dd520 98 "Config Patch",
SolderSplashLabs 23:fed7f64dd520 99 };
SolderSplashLabs 23:fed7f64dd520 100 #endif
SolderSplashLabs 23:fed7f64dd520 101
SolderSplashLabs 23:fed7f64dd520 102 cc3000_event::cc3000_event(cc3000_simple_link &simplelink, cc3000_hci &hci, cc3000_spi &spi, cc3000 &cc3000)
SolderSplashLabs 23:fed7f64dd520 103 : socket_active_status(SOCKET_STATUS_INIT_VAL), _simple_link(simplelink), _hci(hci), _spi(spi), _cc3000(cc3000) {
SolderSplashLabs 23:fed7f64dd520 104
SolderSplashLabs 23:fed7f64dd520 105 }
SolderSplashLabs 23:fed7f64dd520 106
SolderSplashLabs 23:fed7f64dd520 107 cc3000_event::~cc3000_event() {
SolderSplashLabs 23:fed7f64dd520 108
SolderSplashLabs 23:fed7f64dd520 109 }
SolderSplashLabs 23:fed7f64dd520 110
SolderSplashLabs 23:fed7f64dd520 111 /* TODO removed buffer, set it in init */
SolderSplashLabs 23:fed7f64dd520 112 void cc3000_event::received_handler(uint8_t *buffer) {
SolderSplashLabs 23:fed7f64dd520 113 _simple_link.set_data_received_flag(1);
SolderSplashLabs 23:fed7f64dd520 114 _simple_link.set_received_data(buffer);
SolderSplashLabs 23:fed7f64dd520 115
SolderSplashLabs 23:fed7f64dd520 116 hci_unsolicited_event_handler();
SolderSplashLabs 23:fed7f64dd520 117 }
SolderSplashLabs 23:fed7f64dd520 118
SolderSplashLabs 23:fed7f64dd520 119 void cc3000_event::hci_unsol_handle_patch_request(uint8_t *event_hdr) {
SolderSplashLabs 23:fed7f64dd520 120 uint8_t *params = (uint8_t *)(event_hdr) + HCI_EVENT_HEADER_SIZE;
SolderSplashLabs 23:fed7f64dd520 121 uint32_t length = 0;
SolderSplashLabs 23:fed7f64dd520 122 uint8_t *patch;
SolderSplashLabs 23:fed7f64dd520 123
SolderSplashLabs 23:fed7f64dd520 124 switch (*params)
SolderSplashLabs 23:fed7f64dd520 125 {
SolderSplashLabs 23:fed7f64dd520 126 case HCI_EVENT_PATCHES_DRV_REQ:
SolderSplashLabs 23:fed7f64dd520 127 {
SolderSplashLabs 23:fed7f64dd520 128 tDriverPatches func_pointer = (tDriverPatches)_simple_link.get_func_pointer(DRIVER_PATCHES);
SolderSplashLabs 23:fed7f64dd520 129 if (func_pointer)
SolderSplashLabs 23:fed7f64dd520 130 {
SolderSplashLabs 23:fed7f64dd520 131 patch = func_pointer(&length);
SolderSplashLabs 23:fed7f64dd520 132 if (patch)
SolderSplashLabs 23:fed7f64dd520 133 {
SolderSplashLabs 23:fed7f64dd520 134 _hci.patch_send(HCI_EVENT_PATCHES_DRV_REQ, _simple_link.get_transmit_buffer(), patch, length);
SolderSplashLabs 23:fed7f64dd520 135 return;
SolderSplashLabs 23:fed7f64dd520 136 }
SolderSplashLabs 23:fed7f64dd520 137 }
SolderSplashLabs 23:fed7f64dd520 138
SolderSplashLabs 23:fed7f64dd520 139 // Send 0 length Patches response event
SolderSplashLabs 23:fed7f64dd520 140 _hci.patch_send(HCI_EVENT_PATCHES_DRV_REQ, _simple_link.get_transmit_buffer(), 0, 0);
SolderSplashLabs 23:fed7f64dd520 141 break;
SolderSplashLabs 23:fed7f64dd520 142 }
SolderSplashLabs 23:fed7f64dd520 143 case HCI_EVENT_PATCHES_FW_REQ:
SolderSplashLabs 23:fed7f64dd520 144 {
SolderSplashLabs 23:fed7f64dd520 145 tFWPatches func_pointer = (tFWPatches)_simple_link.get_func_pointer(FW_PATCHES);
SolderSplashLabs 23:fed7f64dd520 146 if (func_pointer)
SolderSplashLabs 23:fed7f64dd520 147 {
SolderSplashLabs 23:fed7f64dd520 148 patch = func_pointer(&length);
SolderSplashLabs 23:fed7f64dd520 149 // Build and send a patch
SolderSplashLabs 23:fed7f64dd520 150 if (patch)
SolderSplashLabs 23:fed7f64dd520 151 {
SolderSplashLabs 23:fed7f64dd520 152 _hci.patch_send(HCI_EVENT_PATCHES_FW_REQ, _simple_link.get_transmit_buffer(), patch, length);
SolderSplashLabs 23:fed7f64dd520 153 return;
SolderSplashLabs 23:fed7f64dd520 154 }
SolderSplashLabs 23:fed7f64dd520 155 }
SolderSplashLabs 23:fed7f64dd520 156 // Send 0 length Patches response event
SolderSplashLabs 23:fed7f64dd520 157 _hci.patch_send(HCI_EVENT_PATCHES_FW_REQ, _simple_link.get_transmit_buffer(), 0, 0);
SolderSplashLabs 23:fed7f64dd520 158 break;
SolderSplashLabs 23:fed7f64dd520 159 }
SolderSplashLabs 23:fed7f64dd520 160 case HCI_EVENT_PATCHES_BOOTLOAD_REQ:
SolderSplashLabs 23:fed7f64dd520 161 {
SolderSplashLabs 23:fed7f64dd520 162 tBootLoaderPatches func_pointer = (tBootLoaderPatches)_simple_link.get_func_pointer(BOOTLOADER_PATCHES);
SolderSplashLabs 23:fed7f64dd520 163 if (func_pointer)
SolderSplashLabs 23:fed7f64dd520 164 {
SolderSplashLabs 23:fed7f64dd520 165 patch = func_pointer(&length);
SolderSplashLabs 23:fed7f64dd520 166 if (patch)
SolderSplashLabs 23:fed7f64dd520 167 {
SolderSplashLabs 23:fed7f64dd520 168 _hci.patch_send(HCI_EVENT_PATCHES_BOOTLOAD_REQ, _simple_link.get_transmit_buffer(), patch, length);
SolderSplashLabs 23:fed7f64dd520 169 return;
SolderSplashLabs 23:fed7f64dd520 170 }
SolderSplashLabs 23:fed7f64dd520 171 }
SolderSplashLabs 23:fed7f64dd520 172 // Send 0 length Patches response event
SolderSplashLabs 23:fed7f64dd520 173 _hci.patch_send(HCI_EVENT_PATCHES_BOOTLOAD_REQ, _simple_link.get_transmit_buffer(), 0, 0);
SolderSplashLabs 23:fed7f64dd520 174 break;
SolderSplashLabs 23:fed7f64dd520 175 }
SolderSplashLabs 23:fed7f64dd520 176 }
SolderSplashLabs 23:fed7f64dd520 177 }
SolderSplashLabs 23:fed7f64dd520 178
SolderSplashLabs 23:fed7f64dd520 179 static void hci_event_debug_print(uint16_t hciEventNo)
SolderSplashLabs 23:fed7f64dd520 180 {
SolderSplashLabs 23:fed7f64dd520 181 #ifdef CC3000_DEBUG_HCI_RX
SolderSplashLabs 23:fed7f64dd520 182 if ((hciEventNo > HCI_CMND_SOCKET_BASE) && ( hciEventNo <= HCI_CMND_MDNS_ADVERTISE))
SolderSplashLabs 23:fed7f64dd520 183 {
SolderSplashLabs 23:fed7f64dd520 184 DBG_HCI("Event Received : 0x%04X - %s", hciEventNo, HCI_EVENT_STR[hciEventNo-HCI_CMND_SOCKET]);
SolderSplashLabs 23:fed7f64dd520 185 }
SolderSplashLabs 23:fed7f64dd520 186 else if ((hciEventNo > HCI_CMND_NETAPP_BASE) && ( hciEventNo <= HCI_NETAPP_SET_TIMERS))
SolderSplashLabs 23:fed7f64dd520 187 {
SolderSplashLabs 23:fed7f64dd520 188 DBG_HCI("Event Received : 0x%04X - %s", hciEventNo, HCI_NETAPP_STR[hciEventNo-HCI_NETAPP_DHCP]);
SolderSplashLabs 23:fed7f64dd520 189 }
SolderSplashLabs 23:fed7f64dd520 190 else if (hciEventNo < HCI_CMND_WLAN_CONFIGURE_PATCH+1)
SolderSplashLabs 23:fed7f64dd520 191 {
SolderSplashLabs 23:fed7f64dd520 192 DBG_HCI("Event Received : 0x%04X - %s", hciEventNo, HCI_MISC_STR[hciEventNo]);
SolderSplashLabs 23:fed7f64dd520 193 }
SolderSplashLabs 23:fed7f64dd520 194 else
SolderSplashLabs 23:fed7f64dd520 195 {
SolderSplashLabs 23:fed7f64dd520 196 DBG_HCI("Event Received : 0x%04X", hciEventNo);
SolderSplashLabs 23:fed7f64dd520 197 }
SolderSplashLabs 23:fed7f64dd520 198 #endif
SolderSplashLabs 23:fed7f64dd520 199 }
SolderSplashLabs 23:fed7f64dd520 200
SolderSplashLabs 23:fed7f64dd520 201 uint8_t *cc3000_event::hci_event_handler(void *ret_param, uint8_t *from, uint8_t *fromlen) {
SolderSplashLabs 23:fed7f64dd520 202 uint8_t *received_data, argument_size;
SolderSplashLabs 23:fed7f64dd520 203 uint16_t length;
SolderSplashLabs 23:fed7f64dd520 204 uint8_t *pucReceivedParams;
SolderSplashLabs 23:fed7f64dd520 205 uint16_t received_op_code = 0;
SolderSplashLabs 23:fed7f64dd520 206 uint32_t return_value;
SolderSplashLabs 23:fed7f64dd520 207 uint8_t * RecvParams;
SolderSplashLabs 23:fed7f64dd520 208 uint8_t *RetParams;
SolderSplashLabs 23:fed7f64dd520 209
SolderSplashLabs 23:fed7f64dd520 210 while (1)
SolderSplashLabs 23:fed7f64dd520 211 {
SolderSplashLabs 23:fed7f64dd520 212 if (_simple_link.get_data_received_flag() != 0)
SolderSplashLabs 23:fed7f64dd520 213 {
SolderSplashLabs 23:fed7f64dd520 214 received_data = _simple_link.get_received_data();
SolderSplashLabs 23:fed7f64dd520 215 if (*received_data == HCI_TYPE_EVNT)
SolderSplashLabs 23:fed7f64dd520 216 {
SolderSplashLabs 23:fed7f64dd520 217 // Event Received
SolderSplashLabs 23:fed7f64dd520 218 STREAM_TO_UINT16((uint8_t *)received_data, HCI_EVENT_OPCODE_OFFSET,received_op_code);
SolderSplashLabs 23:fed7f64dd520 219 pucReceivedParams = received_data + HCI_EVENT_HEADER_SIZE;
SolderSplashLabs 23:fed7f64dd520 220 RecvParams = pucReceivedParams;
SolderSplashLabs 23:fed7f64dd520 221 RetParams = (uint8_t *)ret_param;
SolderSplashLabs 23:fed7f64dd520 222
SolderSplashLabs 23:fed7f64dd520 223 // unsolicited event received - finish handling
SolderSplashLabs 23:fed7f64dd520 224 if (hci_unsol_event_handler((uint8_t *)received_data) == 0)
SolderSplashLabs 23:fed7f64dd520 225 {
SolderSplashLabs 23:fed7f64dd520 226 STREAM_TO_UINT8(received_data, HCI_DATA_LENGTH_OFFSET, length);
SolderSplashLabs 23:fed7f64dd520 227
SolderSplashLabs 23:fed7f64dd520 228 hci_event_debug_print( received_op_code );
SolderSplashLabs 23:fed7f64dd520 229
SolderSplashLabs 23:fed7f64dd520 230 switch(received_op_code)
SolderSplashLabs 23:fed7f64dd520 231 {
SolderSplashLabs 23:fed7f64dd520 232 case HCI_CMND_READ_BUFFER_SIZE:
SolderSplashLabs 23:fed7f64dd520 233 {
SolderSplashLabs 23:fed7f64dd520 234 uint16_t temp = _simple_link.get_number_free_buffers();
SolderSplashLabs 23:fed7f64dd520 235 STREAM_TO_UINT8((uint8_t *)pucReceivedParams, 0, temp);
SolderSplashLabs 23:fed7f64dd520 236 _simple_link.set_number_free_buffers(temp);
SolderSplashLabs 23:fed7f64dd520 237
SolderSplashLabs 23:fed7f64dd520 238 temp = _simple_link.get_buffer_length();
SolderSplashLabs 23:fed7f64dd520 239 STREAM_TO_UINT16((uint8_t *)pucReceivedParams, 1, temp);
SolderSplashLabs 23:fed7f64dd520 240 _simple_link.set_buffer_length(temp);
SolderSplashLabs 23:fed7f64dd520 241 }
SolderSplashLabs 23:fed7f64dd520 242 break;
SolderSplashLabs 23:fed7f64dd520 243
SolderSplashLabs 23:fed7f64dd520 244 case HCI_CMND_WLAN_CONFIGURE_PATCH:
SolderSplashLabs 23:fed7f64dd520 245 case HCI_NETAPP_DHCP:
SolderSplashLabs 23:fed7f64dd520 246 case HCI_NETAPP_PING_SEND:
SolderSplashLabs 23:fed7f64dd520 247 case HCI_NETAPP_PING_STOP:
SolderSplashLabs 23:fed7f64dd520 248 case HCI_NETAPP_ARP_FLUSH:
SolderSplashLabs 23:fed7f64dd520 249 case HCI_NETAPP_SET_DEBUG_LEVEL:
SolderSplashLabs 23:fed7f64dd520 250 case HCI_NETAPP_SET_TIMERS:
SolderSplashLabs 23:fed7f64dd520 251 case HCI_EVNT_NVMEM_READ:
SolderSplashLabs 23:fed7f64dd520 252 case HCI_EVNT_NVMEM_CREATE_ENTRY:
SolderSplashLabs 23:fed7f64dd520 253 case HCI_CMND_NVMEM_WRITE_PATCH:
SolderSplashLabs 23:fed7f64dd520 254 case HCI_NETAPP_PING_REPORT:
SolderSplashLabs 23:fed7f64dd520 255 case HCI_EVNT_MDNS_ADVERTISE:
SolderSplashLabs 23:fed7f64dd520 256
SolderSplashLabs 23:fed7f64dd520 257 STREAM_TO_UINT8(received_data, HCI_EVENT_STATUS_OFFSET, *(uint8_t *)ret_param);
SolderSplashLabs 23:fed7f64dd520 258 break;
SolderSplashLabs 23:fed7f64dd520 259
SolderSplashLabs 23:fed7f64dd520 260 case HCI_CMND_SETSOCKOPT:
SolderSplashLabs 23:fed7f64dd520 261 case HCI_CMND_WLAN_CONNECT:
SolderSplashLabs 23:fed7f64dd520 262 case HCI_CMND_WLAN_IOCTL_STATUSGET:
SolderSplashLabs 23:fed7f64dd520 263 case HCI_EVNT_WLAN_IOCTL_ADD_PROFILE:
SolderSplashLabs 23:fed7f64dd520 264 case HCI_CMND_WLAN_IOCTL_DEL_PROFILE:
SolderSplashLabs 23:fed7f64dd520 265 case HCI_CMND_WLAN_IOCTL_SET_CONNECTION_POLICY:
SolderSplashLabs 23:fed7f64dd520 266 case HCI_CMND_WLAN_IOCTL_SET_SCANPARAM:
SolderSplashLabs 23:fed7f64dd520 267 case HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_START:
SolderSplashLabs 23:fed7f64dd520 268 case HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_STOP:
SolderSplashLabs 23:fed7f64dd520 269 case HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_SET_PREFIX:
SolderSplashLabs 23:fed7f64dd520 270 case HCI_CMND_EVENT_MASK:
SolderSplashLabs 23:fed7f64dd520 271 case HCI_EVNT_WLAN_DISCONNECT:
SolderSplashLabs 23:fed7f64dd520 272 case HCI_EVNT_SOCKET:
SolderSplashLabs 23:fed7f64dd520 273 case HCI_EVNT_BIND:
SolderSplashLabs 23:fed7f64dd520 274 case HCI_CMND_LISTEN:
SolderSplashLabs 23:fed7f64dd520 275 case HCI_EVNT_CLOSE_SOCKET:
SolderSplashLabs 23:fed7f64dd520 276 case HCI_EVNT_CONNECT:
SolderSplashLabs 23:fed7f64dd520 277 case HCI_EVNT_NVMEM_WRITE:
SolderSplashLabs 23:fed7f64dd520 278
SolderSplashLabs 23:fed7f64dd520 279 STREAM_TO_UINT32((uint8_t *)pucReceivedParams,0, *(uint32_t *)ret_param);
SolderSplashLabs 23:fed7f64dd520 280 break;
SolderSplashLabs 23:fed7f64dd520 281
SolderSplashLabs 23:fed7f64dd520 282 case HCI_EVNT_READ_SP_VERSION:
SolderSplashLabs 23:fed7f64dd520 283
SolderSplashLabs 23:fed7f64dd520 284 STREAM_TO_UINT8(received_data, HCI_EVENT_STATUS_OFFSET, *(uint8_t *)ret_param);
SolderSplashLabs 23:fed7f64dd520 285 ret_param = ((uint8_t *)ret_param) + 1;
SolderSplashLabs 23:fed7f64dd520 286 STREAM_TO_UINT32((uint8_t *)pucReceivedParams, 0, return_value);
SolderSplashLabs 23:fed7f64dd520 287 UINT32_TO_STREAM((uint8_t *)ret_param, return_value);
SolderSplashLabs 23:fed7f64dd520 288 break;
SolderSplashLabs 23:fed7f64dd520 289
SolderSplashLabs 23:fed7f64dd520 290 case HCI_EVNT_BSD_GETHOSTBYNAME:
SolderSplashLabs 23:fed7f64dd520 291
SolderSplashLabs 23:fed7f64dd520 292 STREAM_TO_UINT32((uint8_t *)pucReceivedParams,GET_HOST_BY_NAME_RETVAL_OFFSET,*(uint32_t *)ret_param);
SolderSplashLabs 23:fed7f64dd520 293 ret_param = ((uint8_t *)ret_param) + 4;
SolderSplashLabs 23:fed7f64dd520 294 STREAM_TO_UINT32((uint8_t *)pucReceivedParams,GET_HOST_BY_NAME_ADDR_OFFSET,*(uint32_t *)ret_param);
SolderSplashLabs 23:fed7f64dd520 295 break;
SolderSplashLabs 23:fed7f64dd520 296
SolderSplashLabs 23:fed7f64dd520 297 case HCI_EVNT_ACCEPT:
SolderSplashLabs 23:fed7f64dd520 298 {
SolderSplashLabs 23:fed7f64dd520 299 STREAM_TO_UINT32((uint8_t *)pucReceivedParams,ACCEPT_SD_OFFSET,*(uint32_t *)ret_param);
SolderSplashLabs 23:fed7f64dd520 300 ret_param = ((uint8_t *)ret_param) + 4;
SolderSplashLabs 23:fed7f64dd520 301 STREAM_TO_UINT32((uint8_t *)pucReceivedParams,ACCEPT_RETURN_STATUS_OFFSET,*(uint32_t *)ret_param);
SolderSplashLabs 23:fed7f64dd520 302 ret_param = ((uint8_t *)ret_param) + 4;
SolderSplashLabs 23:fed7f64dd520 303
SolderSplashLabs 23:fed7f64dd520 304 //This argument returns in network order
SolderSplashLabs 23:fed7f64dd520 305 memcpy((uint8_t *)ret_param, pucReceivedParams + ACCEPT_ADDRESS__OFFSET, sizeof(sockaddr));
SolderSplashLabs 23:fed7f64dd520 306 break;
SolderSplashLabs 23:fed7f64dd520 307 }
SolderSplashLabs 23:fed7f64dd520 308
SolderSplashLabs 23:fed7f64dd520 309 case HCI_EVNT_RECV:
SolderSplashLabs 23:fed7f64dd520 310 case HCI_EVNT_RECVFROM:
SolderSplashLabs 23:fed7f64dd520 311 {
SolderSplashLabs 23:fed7f64dd520 312 STREAM_TO_UINT32((uint8_t *)pucReceivedParams,SL_RECEIVE_SD_OFFSET ,*(uint32_t *)ret_param);
SolderSplashLabs 23:fed7f64dd520 313 ret_param = ((uint8_t *)ret_param) + 4;
SolderSplashLabs 23:fed7f64dd520 314 STREAM_TO_UINT32((uint8_t *)pucReceivedParams,SL_RECEIVE_NUM_BYTES_OFFSET,*(uint32_t *)ret_param);
SolderSplashLabs 23:fed7f64dd520 315 ret_param = ((uint8_t *)ret_param) + 4;
SolderSplashLabs 23:fed7f64dd520 316 STREAM_TO_UINT32((uint8_t *)pucReceivedParams,SL_RECEIVE__FLAGS__OFFSET,*(uint32_t *)ret_param);
SolderSplashLabs 23:fed7f64dd520 317
SolderSplashLabs 23:fed7f64dd520 318 if(((tBsdReadReturnParams *)ret_param)->iNumberOfBytes == ERROR_SOCKET_INACTIVE)
SolderSplashLabs 23:fed7f64dd520 319 {
SolderSplashLabs 23:fed7f64dd520 320 set_socket_active_status(((tBsdReadReturnParams *)ret_param)->iSocketDescriptor,SOCKET_STATUS_INACTIVE);
SolderSplashLabs 23:fed7f64dd520 321 }
SolderSplashLabs 23:fed7f64dd520 322 break;
SolderSplashLabs 23:fed7f64dd520 323 }
SolderSplashLabs 23:fed7f64dd520 324
SolderSplashLabs 23:fed7f64dd520 325 case HCI_EVNT_SEND:
SolderSplashLabs 23:fed7f64dd520 326 case HCI_EVNT_SENDTO:
SolderSplashLabs 23:fed7f64dd520 327 {
SolderSplashLabs 23:fed7f64dd520 328 STREAM_TO_UINT32((uint8_t *)pucReceivedParams,SL_RECEIVE_SD_OFFSET ,*(uint32_t *)ret_param);
SolderSplashLabs 23:fed7f64dd520 329 ret_param = ((uint8_t *)ret_param) + 4;
SolderSplashLabs 23:fed7f64dd520 330 STREAM_TO_UINT32((uint8_t *)pucReceivedParams,SL_RECEIVE_NUM_BYTES_OFFSET,*(uint32_t *)ret_param);
SolderSplashLabs 23:fed7f64dd520 331 ret_param = ((uint8_t *)ret_param) + 4;
SolderSplashLabs 23:fed7f64dd520 332
SolderSplashLabs 23:fed7f64dd520 333 break;
SolderSplashLabs 23:fed7f64dd520 334 }
SolderSplashLabs 23:fed7f64dd520 335
SolderSplashLabs 23:fed7f64dd520 336 case HCI_EVNT_SELECT:
SolderSplashLabs 23:fed7f64dd520 337 {
SolderSplashLabs 23:fed7f64dd520 338 STREAM_TO_UINT32((uint8_t *)pucReceivedParams,SELECT_STATUS_OFFSET,*(uint32_t *)ret_param);
SolderSplashLabs 23:fed7f64dd520 339 ret_param = ((uint8_t *)ret_param) + 4;
SolderSplashLabs 23:fed7f64dd520 340 STREAM_TO_UINT32((uint8_t *)pucReceivedParams,SELECT_READFD_OFFSET,*(uint32_t *)ret_param);
SolderSplashLabs 23:fed7f64dd520 341 ret_param = ((uint8_t *)ret_param) + 4;
SolderSplashLabs 23:fed7f64dd520 342 STREAM_TO_UINT32((uint8_t *)pucReceivedParams,SELECT_WRITEFD_OFFSET,*(uint32_t *)ret_param);
SolderSplashLabs 23:fed7f64dd520 343 ret_param = ((uint8_t *)ret_param) + 4;
SolderSplashLabs 23:fed7f64dd520 344 STREAM_TO_UINT32((uint8_t *)pucReceivedParams,SELECT_EXFD_OFFSET,*(uint32_t *)ret_param);
SolderSplashLabs 23:fed7f64dd520 345 break;
SolderSplashLabs 23:fed7f64dd520 346 }
SolderSplashLabs 23:fed7f64dd520 347
SolderSplashLabs 23:fed7f64dd520 348 case HCI_CMND_GETSOCKOPT:
SolderSplashLabs 23:fed7f64dd520 349
SolderSplashLabs 23:fed7f64dd520 350 STREAM_TO_UINT8(received_data, HCI_EVENT_STATUS_OFFSET,((tBsdGetSockOptReturnParams *)ret_param)->iStatus);
SolderSplashLabs 23:fed7f64dd520 351 //This argument returns in network order
SolderSplashLabs 23:fed7f64dd520 352 memcpy((uint8_t *)ret_param, pucReceivedParams, 4);
SolderSplashLabs 23:fed7f64dd520 353 break;
SolderSplashLabs 23:fed7f64dd520 354
SolderSplashLabs 23:fed7f64dd520 355 case HCI_CMND_WLAN_IOCTL_GET_SCAN_RESULTS:
SolderSplashLabs 23:fed7f64dd520 356
SolderSplashLabs 23:fed7f64dd520 357 STREAM_TO_UINT32((uint8_t *)pucReceivedParams,GET_SCAN_RESULTS_TABlE_COUNT_OFFSET,*(uint32_t *)ret_param);
SolderSplashLabs 23:fed7f64dd520 358 ret_param = ((uint8_t *)ret_param) + 4;
SolderSplashLabs 23:fed7f64dd520 359 STREAM_TO_UINT32((uint8_t *)pucReceivedParams,GET_SCAN_RESULTS_SCANRESULT_STATUS_OFFSET,*(uint32_t *)ret_param);
SolderSplashLabs 23:fed7f64dd520 360 ret_param = ((uint8_t *)ret_param) + 4;
SolderSplashLabs 23:fed7f64dd520 361 STREAM_TO_UINT16((uint8_t *)pucReceivedParams,GET_SCAN_RESULTS_ISVALID_TO_SSIDLEN_OFFSET,*(uint32_t *)ret_param);
SolderSplashLabs 23:fed7f64dd520 362 ret_param = ((uint8_t *)ret_param) + 2;
SolderSplashLabs 23:fed7f64dd520 363 STREAM_TO_UINT16((uint8_t *)pucReceivedParams,GET_SCAN_RESULTS_FRAME_TIME_OFFSET,*(uint32_t *)ret_param);
SolderSplashLabs 23:fed7f64dd520 364 ret_param = ((uint8_t *)ret_param) + 2;
SolderSplashLabs 23:fed7f64dd520 365 memcpy((uint8_t *)ret_param, (uint8_t *)(pucReceivedParams + GET_SCAN_RESULTS_FRAME_TIME_OFFSET + 2), GET_SCAN_RESULTS_SSID_MAC_LENGTH);
SolderSplashLabs 23:fed7f64dd520 366 break;
SolderSplashLabs 23:fed7f64dd520 367
SolderSplashLabs 23:fed7f64dd520 368 case HCI_CMND_SIMPLE_LINK_START:
SolderSplashLabs 23:fed7f64dd520 369 break;
SolderSplashLabs 23:fed7f64dd520 370
SolderSplashLabs 23:fed7f64dd520 371 case HCI_NETAPP_IPCONFIG:
SolderSplashLabs 23:fed7f64dd520 372
SolderSplashLabs 23:fed7f64dd520 373 //Read IP address
SolderSplashLabs 23:fed7f64dd520 374 STREAM_TO_STREAM(RecvParams,RetParams,NETAPP_IPCONFIG_IP_LENGTH);
SolderSplashLabs 23:fed7f64dd520 375 RecvParams += 4;
SolderSplashLabs 23:fed7f64dd520 376
SolderSplashLabs 23:fed7f64dd520 377 //Read subnet
SolderSplashLabs 23:fed7f64dd520 378 STREAM_TO_STREAM(RecvParams,RetParams,NETAPP_IPCONFIG_IP_LENGTH);
SolderSplashLabs 23:fed7f64dd520 379 RecvParams += 4;
SolderSplashLabs 23:fed7f64dd520 380
SolderSplashLabs 23:fed7f64dd520 381 //Read default GW
SolderSplashLabs 23:fed7f64dd520 382 STREAM_TO_STREAM(RecvParams,RetParams,NETAPP_IPCONFIG_IP_LENGTH);
SolderSplashLabs 23:fed7f64dd520 383 RecvParams += 4;
SolderSplashLabs 23:fed7f64dd520 384
SolderSplashLabs 23:fed7f64dd520 385 //Read DHCP server
SolderSplashLabs 23:fed7f64dd520 386 STREAM_TO_STREAM(RecvParams,RetParams,NETAPP_IPCONFIG_IP_LENGTH);
SolderSplashLabs 23:fed7f64dd520 387 RecvParams += 4;
SolderSplashLabs 23:fed7f64dd520 388
SolderSplashLabs 23:fed7f64dd520 389 //Read DNS server
SolderSplashLabs 23:fed7f64dd520 390 STREAM_TO_STREAM(RecvParams,RetParams,NETAPP_IPCONFIG_IP_LENGTH);
SolderSplashLabs 23:fed7f64dd520 391 RecvParams += 4;
SolderSplashLabs 23:fed7f64dd520 392
SolderSplashLabs 23:fed7f64dd520 393 //Read Mac address
SolderSplashLabs 23:fed7f64dd520 394 STREAM_TO_STREAM(RecvParams,RetParams,NETAPP_IPCONFIG_MAC_LENGTH);
SolderSplashLabs 23:fed7f64dd520 395 RecvParams += 6;
SolderSplashLabs 23:fed7f64dd520 396
SolderSplashLabs 23:fed7f64dd520 397 //Read SSID
SolderSplashLabs 23:fed7f64dd520 398 STREAM_TO_STREAM(RecvParams,RetParams,NETAPP_IPCONFIG_SSID_LENGTH);
SolderSplashLabs 23:fed7f64dd520 399
SolderSplashLabs 23:fed7f64dd520 400 }
SolderSplashLabs 23:fed7f64dd520 401 }
SolderSplashLabs 23:fed7f64dd520 402 if (received_op_code == _simple_link.get_op_code())
SolderSplashLabs 23:fed7f64dd520 403 {
SolderSplashLabs 23:fed7f64dd520 404 _simple_link.set_op_code(0);
SolderSplashLabs 23:fed7f64dd520 405 }
SolderSplashLabs 23:fed7f64dd520 406 }
SolderSplashLabs 23:fed7f64dd520 407 else
SolderSplashLabs 23:fed7f64dd520 408 {
SolderSplashLabs 23:fed7f64dd520 409 pucReceivedParams = received_data;
SolderSplashLabs 23:fed7f64dd520 410 STREAM_TO_UINT8((uint8_t *)received_data, HCI_PACKET_ARGSIZE_OFFSET, argument_size);
SolderSplashLabs 23:fed7f64dd520 411
SolderSplashLabs 23:fed7f64dd520 412 STREAM_TO_UINT16((uint8_t *)received_data, HCI_PACKET_LENGTH_OFFSET, length);
SolderSplashLabs 23:fed7f64dd520 413
SolderSplashLabs 23:fed7f64dd520 414 // Data received: note that the only case where from and from length
SolderSplashLabs 23:fed7f64dd520 415 // are not null is in recv from, so fill the args accordingly
SolderSplashLabs 23:fed7f64dd520 416 if (from)
SolderSplashLabs 23:fed7f64dd520 417 {
SolderSplashLabs 23:fed7f64dd520 418 STREAM_TO_UINT32((uint8_t *)(received_data + HCI_DATA_HEADER_SIZE), BSD_RECV_FROM_FROMLEN_OFFSET, *(uint32_t *)fromlen);
SolderSplashLabs 23:fed7f64dd520 419 memcpy(from, (received_data + HCI_DATA_HEADER_SIZE + BSD_RECV_FROM_FROM_OFFSET) ,*fromlen);
SolderSplashLabs 23:fed7f64dd520 420 }
SolderSplashLabs 23:fed7f64dd520 421
SolderSplashLabs 23:fed7f64dd520 422 memcpy(ret_param, pucReceivedParams + HCI_DATA_HEADER_SIZE + argument_size, length - argument_size);
SolderSplashLabs 23:fed7f64dd520 423
SolderSplashLabs 23:fed7f64dd520 424 _simple_link.set_pending_data(0);
SolderSplashLabs 23:fed7f64dd520 425 }
SolderSplashLabs 23:fed7f64dd520 426
SolderSplashLabs 23:fed7f64dd520 427 _simple_link.set_data_received_flag(0);
SolderSplashLabs 23:fed7f64dd520 428
SolderSplashLabs 23:fed7f64dd520 429 //tWlanInterruptEnable func_pointer = (tWlanInterruptEnable)_simple_link.get_func_pointer(WLAN_INTERRUPT_ENABLE);
SolderSplashLabs 23:fed7f64dd520 430 //func_pointer();
SolderSplashLabs 23:fed7f64dd520 431 _spi.wlan_irq_enable();
SolderSplashLabs 23:fed7f64dd520 432
SolderSplashLabs 23:fed7f64dd520 433 // Since we are going to TX - we need to handle this event after the ResumeSPi since we need interrupts
SolderSplashLabs 23:fed7f64dd520 434 if ((*received_data == HCI_TYPE_EVNT) && (received_op_code == HCI_EVNT_PATCHES_REQ))
SolderSplashLabs 23:fed7f64dd520 435 {
SolderSplashLabs 23:fed7f64dd520 436 hci_unsol_handle_patch_request((uint8_t *)received_data);
SolderSplashLabs 23:fed7f64dd520 437 }
SolderSplashLabs 23:fed7f64dd520 438 if ((_simple_link.get_op_code() == 0) && (_simple_link.get_pending_data() == 0))
SolderSplashLabs 23:fed7f64dd520 439 {
SolderSplashLabs 23:fed7f64dd520 440 return NULL;
SolderSplashLabs 23:fed7f64dd520 441 }
SolderSplashLabs 23:fed7f64dd520 442 }
SolderSplashLabs 23:fed7f64dd520 443 }
SolderSplashLabs 23:fed7f64dd520 444 }
SolderSplashLabs 23:fed7f64dd520 445
SolderSplashLabs 23:fed7f64dd520 446 int32_t cc3000_event::hci_unsol_event_handler(uint8_t *event_hdr) {
SolderSplashLabs 23:fed7f64dd520 447 uint8_t *data = NULL;
SolderSplashLabs 23:fed7f64dd520 448 int32_t event_type;
SolderSplashLabs 23:fed7f64dd520 449 uint32_t number_of_released_packets;
SolderSplashLabs 23:fed7f64dd520 450 uint32_t number_of_sent_packets;
SolderSplashLabs 23:fed7f64dd520 451
SolderSplashLabs 23:fed7f64dd520 452 STREAM_TO_UINT16(event_hdr, HCI_EVENT_OPCODE_OFFSET,event_type);
SolderSplashLabs 23:fed7f64dd520 453
SolderSplashLabs 23:fed7f64dd520 454 if (event_type & HCI_EVNT_UNSOL_BASE) {
SolderSplashLabs 23:fed7f64dd520 455 switch(event_type) {
SolderSplashLabs 23:fed7f64dd520 456 case HCI_EVNT_DATA_UNSOL_FREE_BUFF:
SolderSplashLabs 23:fed7f64dd520 457 {
SolderSplashLabs 23:fed7f64dd520 458 hci_event_unsol_flowcontrol_handler(event_hdr);
SolderSplashLabs 23:fed7f64dd520 459
SolderSplashLabs 23:fed7f64dd520 460 number_of_released_packets = _simple_link.get_released_packets();
SolderSplashLabs 23:fed7f64dd520 461 number_of_sent_packets = _simple_link.get_sent_packets();
SolderSplashLabs 23:fed7f64dd520 462
SolderSplashLabs 23:fed7f64dd520 463 if (number_of_released_packets == number_of_sent_packets)
SolderSplashLabs 23:fed7f64dd520 464 {
SolderSplashLabs 23:fed7f64dd520 465 if (_simple_link.get_tx_complete_signal())
SolderSplashLabs 23:fed7f64dd520 466 {
SolderSplashLabs 23:fed7f64dd520 467 //tWlanCB func_pointer = (tWlanCB)_simple_link.get_func_pointer(WLAN_CB);
SolderSplashLabs 23:fed7f64dd520 468 _cc3000.usync_callback(HCI_EVENT_CC3000_CAN_SHUT_DOWN, NULL, 0);
SolderSplashLabs 23:fed7f64dd520 469 }
SolderSplashLabs 23:fed7f64dd520 470 }
SolderSplashLabs 23:fed7f64dd520 471 return 1;
SolderSplashLabs 23:fed7f64dd520 472 }
SolderSplashLabs 23:fed7f64dd520 473 }
SolderSplashLabs 23:fed7f64dd520 474 }
SolderSplashLabs 23:fed7f64dd520 475
SolderSplashLabs 23:fed7f64dd520 476 if (event_type & HCI_EVNT_WLAN_UNSOL_BASE) {
SolderSplashLabs 23:fed7f64dd520 477 switch(event_type) {
SolderSplashLabs 23:fed7f64dd520 478 case HCI_EVNT_WLAN_KEEPALIVE:
SolderSplashLabs 23:fed7f64dd520 479 case HCI_EVNT_WLAN_UNSOL_CONNECT:
SolderSplashLabs 23:fed7f64dd520 480 case HCI_EVNT_WLAN_UNSOL_DISCONNECT:
SolderSplashLabs 23:fed7f64dd520 481 case HCI_EVNT_WLAN_UNSOL_INIT:
SolderSplashLabs 23:fed7f64dd520 482 case HCI_EVNT_WLAN_ASYNC_SIMPLE_CONFIG_DONE:
SolderSplashLabs 23:fed7f64dd520 483 // {
SolderSplashLabs 23:fed7f64dd520 484 // tWlanCB func_pointer = (tWlanCB)_simple_link.get_func_pointer(WLAN_CB);
SolderSplashLabs 23:fed7f64dd520 485 // if( func_pointer )
SolderSplashLabs 23:fed7f64dd520 486 // {
SolderSplashLabs 23:fed7f64dd520 487 // func_pointer(event_type, 0, 0);
SolderSplashLabs 23:fed7f64dd520 488 // }
SolderSplashLabs 23:fed7f64dd520 489 _cc3000.usync_callback(event_type, 0, 0);
SolderSplashLabs 23:fed7f64dd520 490 break;
SolderSplashLabs 23:fed7f64dd520 491 // }
SolderSplashLabs 23:fed7f64dd520 492 case HCI_EVNT_WLAN_UNSOL_DHCP:
SolderSplashLabs 23:fed7f64dd520 493 {
SolderSplashLabs 23:fed7f64dd520 494 uint8_t params[NETAPP_IPCONFIG_MAC_OFFSET + 1]; // extra byte is for the status
SolderSplashLabs 23:fed7f64dd520 495 uint8_t *recParams = params;
SolderSplashLabs 23:fed7f64dd520 496 data = (uint8_t *)(event_hdr) + HCI_EVENT_HEADER_SIZE;
SolderSplashLabs 23:fed7f64dd520 497
SolderSplashLabs 23:fed7f64dd520 498 //Read IP address
SolderSplashLabs 23:fed7f64dd520 499 STREAM_TO_STREAM(data,recParams,NETAPP_IPCONFIG_IP_LENGTH);
SolderSplashLabs 23:fed7f64dd520 500 data += 4;
SolderSplashLabs 23:fed7f64dd520 501 //Read subnet
SolderSplashLabs 23:fed7f64dd520 502 STREAM_TO_STREAM(data,recParams,NETAPP_IPCONFIG_IP_LENGTH);
SolderSplashLabs 23:fed7f64dd520 503 data += 4;
SolderSplashLabs 23:fed7f64dd520 504 //Read default GW
SolderSplashLabs 23:fed7f64dd520 505 STREAM_TO_STREAM(data,recParams,NETAPP_IPCONFIG_IP_LENGTH);
SolderSplashLabs 23:fed7f64dd520 506 data += 4;
SolderSplashLabs 23:fed7f64dd520 507 //Read DHCP server
SolderSplashLabs 23:fed7f64dd520 508 STREAM_TO_STREAM(data,recParams,NETAPP_IPCONFIG_IP_LENGTH);
SolderSplashLabs 23:fed7f64dd520 509 data += 4;
SolderSplashLabs 23:fed7f64dd520 510 //Read DNS server
SolderSplashLabs 23:fed7f64dd520 511 STREAM_TO_STREAM(data,recParams,NETAPP_IPCONFIG_IP_LENGTH);
SolderSplashLabs 23:fed7f64dd520 512 // read the status
SolderSplashLabs 23:fed7f64dd520 513 STREAM_TO_UINT8(event_hdr, HCI_EVENT_STATUS_OFFSET, *recParams);
SolderSplashLabs 23:fed7f64dd520 514
SolderSplashLabs 23:fed7f64dd520 515 // tWlanCB func_pointer = (tWlanCB)_simple_link.get_func_pointer(WLAN_CB);
SolderSplashLabs 23:fed7f64dd520 516 // if( func_pointer )
SolderSplashLabs 23:fed7f64dd520 517 // {
SolderSplashLabs 23:fed7f64dd520 518 _cc3000.usync_callback(event_type, (uint8_t *)params, sizeof(params));
SolderSplashLabs 23:fed7f64dd520 519 // }
SolderSplashLabs 23:fed7f64dd520 520 break;
SolderSplashLabs 23:fed7f64dd520 521 }
SolderSplashLabs 23:fed7f64dd520 522 case HCI_EVNT_WLAN_ASYNC_PING_REPORT:
SolderSplashLabs 23:fed7f64dd520 523 {
SolderSplashLabs 23:fed7f64dd520 524 netapp_pingreport_args_t params;
SolderSplashLabs 23:fed7f64dd520 525 data = (uint8_t *)(event_hdr) + HCI_EVENT_HEADER_SIZE;
SolderSplashLabs 23:fed7f64dd520 526 STREAM_TO_UINT32(data, NETAPP_PING_PACKETS_SENT_OFFSET, params.packets_sent);
SolderSplashLabs 23:fed7f64dd520 527 STREAM_TO_UINT32(data, NETAPP_PING_PACKETS_RCVD_OFFSET, params.packets_received);
SolderSplashLabs 23:fed7f64dd520 528 STREAM_TO_UINT32(data, NETAPP_PING_MIN_RTT_OFFSET, params.min_round_time);
SolderSplashLabs 23:fed7f64dd520 529 STREAM_TO_UINT32(data, NETAPP_PING_MAX_RTT_OFFSET, params.max_round_time);
SolderSplashLabs 23:fed7f64dd520 530 STREAM_TO_UINT32(data, NETAPP_PING_AVG_RTT_OFFSET, params.avg_round_time);
SolderSplashLabs 23:fed7f64dd520 531
SolderSplashLabs 23:fed7f64dd520 532 // tWlanCB func_pointer = (tWlanCB)_simple_link.get_func_pointer(WLAN_CB);
SolderSplashLabs 23:fed7f64dd520 533 // if (func_pointer)
SolderSplashLabs 23:fed7f64dd520 534 // {
SolderSplashLabs 23:fed7f64dd520 535 _cc3000.usync_callback(event_type, (uint8_t *)&params, sizeof(params));
SolderSplashLabs 23:fed7f64dd520 536 // }
SolderSplashLabs 23:fed7f64dd520 537 break;
SolderSplashLabs 23:fed7f64dd520 538 }
SolderSplashLabs 23:fed7f64dd520 539 case HCI_EVNT_BSD_TCP_CLOSE_WAIT:
SolderSplashLabs 23:fed7f64dd520 540 {
SolderSplashLabs 23:fed7f64dd520 541 // tWlanCB func_pointer = (tWlanCB)_simple_link.get_func_pointer(WLAN_CB);
SolderSplashLabs 23:fed7f64dd520 542 // if (func_pointer)
SolderSplashLabs 23:fed7f64dd520 543 // {
SolderSplashLabs 23:fed7f64dd520 544 _cc3000.usync_callback(event_type, NULL, 0);
SolderSplashLabs 23:fed7f64dd520 545 // }
SolderSplashLabs 23:fed7f64dd520 546 break;
SolderSplashLabs 23:fed7f64dd520 547 }
SolderSplashLabs 23:fed7f64dd520 548
SolderSplashLabs 23:fed7f64dd520 549 //'default' case which means "event not supported"
SolderSplashLabs 23:fed7f64dd520 550 default:
SolderSplashLabs 23:fed7f64dd520 551 return (0);
SolderSplashLabs 23:fed7f64dd520 552 }
SolderSplashLabs 23:fed7f64dd520 553 return(1);
SolderSplashLabs 23:fed7f64dd520 554 }
SolderSplashLabs 23:fed7f64dd520 555
SolderSplashLabs 23:fed7f64dd520 556 if ((event_type == HCI_EVNT_SEND) || (event_type == HCI_EVNT_SENDTO) || (event_type == HCI_EVNT_WRITE)) {
SolderSplashLabs 23:fed7f64dd520 557 uint8_t *pArg;
SolderSplashLabs 23:fed7f64dd520 558 int32_t status;
SolderSplashLabs 23:fed7f64dd520 559 pArg = M_BSD_RESP_PARAMS_OFFSET(event_hdr);
SolderSplashLabs 23:fed7f64dd520 560 STREAM_TO_UINT32(pArg, BSD_RSP_PARAMS_STATUS_OFFSET,status);
SolderSplashLabs 23:fed7f64dd520 561 if (ERROR_SOCKET_INACTIVE == status) {
SolderSplashLabs 23:fed7f64dd520 562 // The only synchronous event that can come from SL device in form of
SolderSplashLabs 23:fed7f64dd520 563 // command complete is "Command Complete" on data sent, in case SL device
SolderSplashLabs 23:fed7f64dd520 564 // was unable to transmit
SolderSplashLabs 23:fed7f64dd520 565 int32_t transmit_error = _simple_link.get_transmit_error();
SolderSplashLabs 23:fed7f64dd520 566 STREAM_TO_UINT8(event_hdr, HCI_EVENT_STATUS_OFFSET, transmit_error);
SolderSplashLabs 23:fed7f64dd520 567 _simple_link.set_transmit_error(transmit_error);
SolderSplashLabs 23:fed7f64dd520 568 update_socket_active_status(M_BSD_RESP_PARAMS_OFFSET(event_hdr));
SolderSplashLabs 23:fed7f64dd520 569 return (1);
SolderSplashLabs 23:fed7f64dd520 570 }
SolderSplashLabs 23:fed7f64dd520 571 else {
SolderSplashLabs 23:fed7f64dd520 572 return (0);
SolderSplashLabs 23:fed7f64dd520 573 }
SolderSplashLabs 23:fed7f64dd520 574 }
SolderSplashLabs 23:fed7f64dd520 575 return(0);
SolderSplashLabs 23:fed7f64dd520 576 }
SolderSplashLabs 23:fed7f64dd520 577
SolderSplashLabs 23:fed7f64dd520 578 int32_t cc3000_event::hci_unsolicited_event_handler(void) {
SolderSplashLabs 23:fed7f64dd520 579 uint32_t res = 0;
SolderSplashLabs 23:fed7f64dd520 580 uint8_t *received_data;
SolderSplashLabs 23:fed7f64dd520 581
SolderSplashLabs 23:fed7f64dd520 582 if (_simple_link.get_data_received_flag() != 0) {
SolderSplashLabs 23:fed7f64dd520 583 received_data = (_simple_link.get_received_data());
SolderSplashLabs 23:fed7f64dd520 584
SolderSplashLabs 23:fed7f64dd520 585 if (*received_data == HCI_TYPE_EVNT) {
SolderSplashLabs 23:fed7f64dd520 586 // unsolicited event received - finish handling
SolderSplashLabs 23:fed7f64dd520 587 if (hci_unsol_event_handler((uint8_t *)received_data) == 1) {
SolderSplashLabs 23:fed7f64dd520 588 // An unsolicited event was received:
SolderSplashLabs 23:fed7f64dd520 589 // release the buffer and clean the event received
SolderSplashLabs 23:fed7f64dd520 590 _simple_link.set_data_received_flag(0);
SolderSplashLabs 23:fed7f64dd520 591
SolderSplashLabs 23:fed7f64dd520 592 res = 1;
SolderSplashLabs 23:fed7f64dd520 593 _spi.wlan_irq_enable();
SolderSplashLabs 23:fed7f64dd520 594 }
SolderSplashLabs 23:fed7f64dd520 595 }
SolderSplashLabs 23:fed7f64dd520 596 }
SolderSplashLabs 23:fed7f64dd520 597 return res;
SolderSplashLabs 23:fed7f64dd520 598 }
SolderSplashLabs 23:fed7f64dd520 599
SolderSplashLabs 23:fed7f64dd520 600 void cc3000_event::set_socket_active_status(int32_t sd, int32_t status) {
SolderSplashLabs 23:fed7f64dd520 601 if (M_IS_VALID_SD(sd) && M_IS_VALID_STATUS(status))
SolderSplashLabs 23:fed7f64dd520 602 {
SolderSplashLabs 23:fed7f64dd520 603 socket_active_status &= ~(1 << sd); /* clean socket's mask */
SolderSplashLabs 23:fed7f64dd520 604 socket_active_status |= (status << sd); /* set new socket's mask */
SolderSplashLabs 23:fed7f64dd520 605 }
SolderSplashLabs 23:fed7f64dd520 606 }
SolderSplashLabs 23:fed7f64dd520 607
SolderSplashLabs 23:fed7f64dd520 608 int32_t cc3000_event::hci_event_unsol_flowcontrol_handler(uint8_t *event) {
SolderSplashLabs 23:fed7f64dd520 609 int32_t temp, value;
SolderSplashLabs 23:fed7f64dd520 610 uint16_t i;
SolderSplashLabs 23:fed7f64dd520 611 uint16_t pusNumberOfHandles=0;
SolderSplashLabs 23:fed7f64dd520 612 uint8_t *pReadPayload;
SolderSplashLabs 23:fed7f64dd520 613
SolderSplashLabs 23:fed7f64dd520 614 STREAM_TO_UINT16((uint8_t *)event,HCI_EVENT_HEADER_SIZE,pusNumberOfHandles);
SolderSplashLabs 23:fed7f64dd520 615 pReadPayload = ((uint8_t *)event + HCI_EVENT_HEADER_SIZE + sizeof(pusNumberOfHandles));
SolderSplashLabs 23:fed7f64dd520 616 temp = 0;
SolderSplashLabs 23:fed7f64dd520 617
SolderSplashLabs 23:fed7f64dd520 618 for(i = 0; i < pusNumberOfHandles; i++) {
SolderSplashLabs 23:fed7f64dd520 619 STREAM_TO_UINT16(pReadPayload, FLOW_CONTROL_EVENT_FREE_BUFFS_OFFSET, value);
SolderSplashLabs 23:fed7f64dd520 620 temp += value;
SolderSplashLabs 23:fed7f64dd520 621 pReadPayload += FLOW_CONTROL_EVENT_SIZE;
SolderSplashLabs 23:fed7f64dd520 622 }
SolderSplashLabs 23:fed7f64dd520 623
SolderSplashLabs 23:fed7f64dd520 624 _simple_link.set_number_free_buffers(_simple_link.get_number_free_buffers() + temp);
SolderSplashLabs 23:fed7f64dd520 625 _simple_link.set_number_of_released_packets(_simple_link.get_released_packets() + temp);
SolderSplashLabs 23:fed7f64dd520 626
SolderSplashLabs 23:fed7f64dd520 627 return(ESUCCESS);
SolderSplashLabs 23:fed7f64dd520 628 }
SolderSplashLabs 23:fed7f64dd520 629
SolderSplashLabs 23:fed7f64dd520 630 int32_t cc3000_event::get_socket_active_status(int32_t sd) {
SolderSplashLabs 23:fed7f64dd520 631 if(M_IS_VALID_SD(sd)) {
SolderSplashLabs 23:fed7f64dd520 632 return (socket_active_status & (1 << sd)) ? SOCKET_STATUS_INACTIVE : SOCKET_STATUS_ACTIVE;
SolderSplashLabs 23:fed7f64dd520 633 } else {
SolderSplashLabs 23:fed7f64dd520 634 return SOCKET_STATUS_INACTIVE;
SolderSplashLabs 23:fed7f64dd520 635 }
SolderSplashLabs 23:fed7f64dd520 636 }
SolderSplashLabs 23:fed7f64dd520 637
SolderSplashLabs 23:fed7f64dd520 638 void cc3000_event::update_socket_active_status(uint8_t *resp_params) {
SolderSplashLabs 23:fed7f64dd520 639 int32_t status, sd;
SolderSplashLabs 23:fed7f64dd520 640
SolderSplashLabs 23:fed7f64dd520 641 STREAM_TO_UINT32(resp_params, BSD_RSP_PARAMS_SOCKET_OFFSET,sd);
SolderSplashLabs 23:fed7f64dd520 642 STREAM_TO_UINT32(resp_params, BSD_RSP_PARAMS_STATUS_OFFSET,status);
SolderSplashLabs 23:fed7f64dd520 643
SolderSplashLabs 23:fed7f64dd520 644 if(ERROR_SOCKET_INACTIVE == status) {
SolderSplashLabs 23:fed7f64dd520 645 set_socket_active_status(sd, SOCKET_STATUS_INACTIVE);
SolderSplashLabs 23:fed7f64dd520 646 }
SolderSplashLabs 23:fed7f64dd520 647 }
SolderSplashLabs 23:fed7f64dd520 648
SolderSplashLabs 23:fed7f64dd520 649 void cc3000_event::simplelink_wait_event(uint16_t op_code, void *ret_param) {
SolderSplashLabs 23:fed7f64dd520 650 // In the blocking implementation the control to caller will be returned only
SolderSplashLabs 23:fed7f64dd520 651 // after the end of current transaction
SolderSplashLabs 23:fed7f64dd520 652 _simple_link.set_op_code(op_code);
SolderSplashLabs 23:fed7f64dd520 653 hci_event_handler(ret_param, 0, 0);
SolderSplashLabs 23:fed7f64dd520 654 }
SolderSplashLabs 23:fed7f64dd520 655
SolderSplashLabs 23:fed7f64dd520 656 void cc3000_event::simplelink_wait_data(uint8_t *pBuf, uint8_t *from, uint8_t *fromlen) {
SolderSplashLabs 23:fed7f64dd520 657 // In the blocking implementation the control to caller will be returned only
SolderSplashLabs 23:fed7f64dd520 658 // after the end of current transaction, i.e. only after data will be received
SolderSplashLabs 23:fed7f64dd520 659 _simple_link.set_pending_data(1);
SolderSplashLabs 23:fed7f64dd520 660 hci_event_handler(pBuf, from, fromlen);
SolderSplashLabs 23:fed7f64dd520 661 }
SolderSplashLabs 23:fed7f64dd520 662
SolderSplashLabs 23:fed7f64dd520 663
SolderSplashLabs 23:fed7f64dd520 664 } /* end of cc3000 namespace */