cc3000 driver with expanded buffers.

Fork of cc3000_hostdriver_mbedsocket by Martin Kojtal

Committer:
heroic
Date:
Wed May 07 02:53:08 2014 +0000
Revision:
57:8caf996d7b6a
Parent:
56:9ab991c1d2db
Yet more debugging.

Who changed what in which revision?

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