cc3000 driver with expanded buffers.

Fork of cc3000_hostdriver_mbedsocket by Martin Kojtal

Committer:
heroic
Date:
Tue May 06 20:37:02 2014 +0000
Revision:
54:cae3dfc6df20
Parent:
45:50ab13d8f2dc
Child:
55:3d640d25a7ec
Debug HCI with LED.

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
heroic 54:cae3dfc6df20 201 DigitalOut led1(p3);
heroic 54:cae3dfc6df20 202
Kojto 20:30b6ed7bf8fd 203 uint8_t *cc3000_event::hci_event_handler(void *ret_param, uint8_t *from, uint8_t *fromlen) {
Kojto 20:30b6ed7bf8fd 204 uint8_t *received_data, argument_size;
Kojto 20:30b6ed7bf8fd 205 uint16_t length;
Kojto 20:30b6ed7bf8fd 206 uint8_t *pucReceivedParams;
Kojto 20:30b6ed7bf8fd 207 uint16_t received_op_code = 0;
Kojto 20:30b6ed7bf8fd 208 uint32_t return_value;
Kojto 20:30b6ed7bf8fd 209 uint8_t * RecvParams;
Kojto 20:30b6ed7bf8fd 210 uint8_t *RetParams;
heroic 54:cae3dfc6df20 211 led1=0;
Kojto 20:30b6ed7bf8fd 212 while (1)
heroic 54:cae3dfc6df20 213 {
Kojto 20:30b6ed7bf8fd 214 if (_simple_link.get_data_received_flag() != 0)
Kojto 20:30b6ed7bf8fd 215 {
Kojto 20:30b6ed7bf8fd 216 received_data = _simple_link.get_received_data();
Kojto 20:30b6ed7bf8fd 217 if (*received_data == HCI_TYPE_EVNT)
Kojto 20:30b6ed7bf8fd 218 {
Kojto 20:30b6ed7bf8fd 219 // Event Received
Kojto 20:30b6ed7bf8fd 220 STREAM_TO_UINT16((uint8_t *)received_data, HCI_EVENT_OPCODE_OFFSET,received_op_code);
Kojto 20:30b6ed7bf8fd 221 pucReceivedParams = received_data + HCI_EVENT_HEADER_SIZE;
Kojto 20:30b6ed7bf8fd 222 RecvParams = pucReceivedParams;
Kojto 20:30b6ed7bf8fd 223 RetParams = (uint8_t *)ret_param;
Kojto 20:30b6ed7bf8fd 224
Kojto 20:30b6ed7bf8fd 225 // unsolicited event received - finish handling
Kojto 20:30b6ed7bf8fd 226 if (hci_unsol_event_handler((uint8_t *)received_data) == 0)
Kojto 20:30b6ed7bf8fd 227 {
Kojto 20:30b6ed7bf8fd 228 STREAM_TO_UINT8(received_data, HCI_DATA_LENGTH_OFFSET, length);
Kojto 20:30b6ed7bf8fd 229
Kojto 20:30b6ed7bf8fd 230 hci_event_debug_print( received_op_code );
Kojto 20:30b6ed7bf8fd 231
Kojto 20:30b6ed7bf8fd 232 switch(received_op_code)
Kojto 20:30b6ed7bf8fd 233 {
Kojto 20:30b6ed7bf8fd 234 case HCI_CMND_READ_BUFFER_SIZE:
Kojto 20:30b6ed7bf8fd 235 {
Kojto 20:30b6ed7bf8fd 236 uint16_t temp = _simple_link.get_number_free_buffers();
Kojto 20:30b6ed7bf8fd 237 STREAM_TO_UINT8((uint8_t *)pucReceivedParams, 0, temp);
Kojto 20:30b6ed7bf8fd 238 _simple_link.set_number_free_buffers(temp);
Kojto 20:30b6ed7bf8fd 239
Kojto 20:30b6ed7bf8fd 240 temp = _simple_link.get_buffer_length();
Kojto 20:30b6ed7bf8fd 241 STREAM_TO_UINT16((uint8_t *)pucReceivedParams, 1, temp);
Kojto 20:30b6ed7bf8fd 242 _simple_link.set_buffer_length(temp);
Kojto 20:30b6ed7bf8fd 243 }
Kojto 20:30b6ed7bf8fd 244 break;
Kojto 20:30b6ed7bf8fd 245
Kojto 20:30b6ed7bf8fd 246 case HCI_CMND_WLAN_CONFIGURE_PATCH:
Kojto 20:30b6ed7bf8fd 247 case HCI_NETAPP_DHCP:
Kojto 20:30b6ed7bf8fd 248 case HCI_NETAPP_PING_SEND:
Kojto 20:30b6ed7bf8fd 249 case HCI_NETAPP_PING_STOP:
Kojto 20:30b6ed7bf8fd 250 case HCI_NETAPP_ARP_FLUSH:
Kojto 20:30b6ed7bf8fd 251 case HCI_NETAPP_SET_DEBUG_LEVEL:
Kojto 20:30b6ed7bf8fd 252 case HCI_NETAPP_SET_TIMERS:
Kojto 20:30b6ed7bf8fd 253 case HCI_EVNT_NVMEM_READ:
Kojto 20:30b6ed7bf8fd 254 case HCI_EVNT_NVMEM_CREATE_ENTRY:
Kojto 20:30b6ed7bf8fd 255 case HCI_CMND_NVMEM_WRITE_PATCH:
Kojto 20:30b6ed7bf8fd 256 case HCI_NETAPP_PING_REPORT:
Kojto 20:30b6ed7bf8fd 257 case HCI_EVNT_MDNS_ADVERTISE:
Kojto 20:30b6ed7bf8fd 258
Kojto 20:30b6ed7bf8fd 259 STREAM_TO_UINT8(received_data, HCI_EVENT_STATUS_OFFSET, *(uint8_t *)ret_param);
Kojto 20:30b6ed7bf8fd 260 break;
Kojto 20:30b6ed7bf8fd 261
Kojto 20:30b6ed7bf8fd 262 case HCI_CMND_SETSOCKOPT:
Kojto 20:30b6ed7bf8fd 263 case HCI_CMND_WLAN_CONNECT:
Kojto 20:30b6ed7bf8fd 264 case HCI_CMND_WLAN_IOCTL_STATUSGET:
Kojto 20:30b6ed7bf8fd 265 case HCI_EVNT_WLAN_IOCTL_ADD_PROFILE:
Kojto 20:30b6ed7bf8fd 266 case HCI_CMND_WLAN_IOCTL_DEL_PROFILE:
Kojto 20:30b6ed7bf8fd 267 case HCI_CMND_WLAN_IOCTL_SET_CONNECTION_POLICY:
Kojto 20:30b6ed7bf8fd 268 case HCI_CMND_WLAN_IOCTL_SET_SCANPARAM:
Kojto 20:30b6ed7bf8fd 269 case HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_START:
Kojto 20:30b6ed7bf8fd 270 case HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_STOP:
Kojto 20:30b6ed7bf8fd 271 case HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_SET_PREFIX:
Kojto 20:30b6ed7bf8fd 272 case HCI_CMND_EVENT_MASK:
Kojto 20:30b6ed7bf8fd 273 case HCI_EVNT_WLAN_DISCONNECT:
Kojto 20:30b6ed7bf8fd 274 case HCI_EVNT_SOCKET:
Kojto 20:30b6ed7bf8fd 275 case HCI_EVNT_BIND:
Kojto 20:30b6ed7bf8fd 276 case HCI_CMND_LISTEN:
Kojto 20:30b6ed7bf8fd 277 case HCI_EVNT_CLOSE_SOCKET:
Kojto 20:30b6ed7bf8fd 278 case HCI_EVNT_CONNECT:
Kojto 20:30b6ed7bf8fd 279 case HCI_EVNT_NVMEM_WRITE:
Kojto 20:30b6ed7bf8fd 280
Kojto 20:30b6ed7bf8fd 281 STREAM_TO_UINT32((uint8_t *)pucReceivedParams,0, *(uint32_t *)ret_param);
Kojto 20:30b6ed7bf8fd 282 break;
Kojto 20:30b6ed7bf8fd 283
Kojto 20:30b6ed7bf8fd 284 case HCI_EVNT_READ_SP_VERSION:
Kojto 20:30b6ed7bf8fd 285
Kojto 20:30b6ed7bf8fd 286 STREAM_TO_UINT8(received_data, HCI_EVENT_STATUS_OFFSET, *(uint8_t *)ret_param);
Kojto 20:30b6ed7bf8fd 287 ret_param = ((uint8_t *)ret_param) + 1;
Kojto 20:30b6ed7bf8fd 288 STREAM_TO_UINT32((uint8_t *)pucReceivedParams, 0, return_value);
Kojto 20:30b6ed7bf8fd 289 UINT32_TO_STREAM((uint8_t *)ret_param, return_value);
Kojto 20:30b6ed7bf8fd 290 break;
Kojto 20:30b6ed7bf8fd 291
Kojto 20:30b6ed7bf8fd 292 case HCI_EVNT_BSD_GETHOSTBYNAME:
Kojto 20:30b6ed7bf8fd 293
Kojto 20:30b6ed7bf8fd 294 STREAM_TO_UINT32((uint8_t *)pucReceivedParams,GET_HOST_BY_NAME_RETVAL_OFFSET,*(uint32_t *)ret_param);
Kojto 20:30b6ed7bf8fd 295 ret_param = ((uint8_t *)ret_param) + 4;
Kojto 20:30b6ed7bf8fd 296 STREAM_TO_UINT32((uint8_t *)pucReceivedParams,GET_HOST_BY_NAME_ADDR_OFFSET,*(uint32_t *)ret_param);
Kojto 20:30b6ed7bf8fd 297 break;
Kojto 20:30b6ed7bf8fd 298
Kojto 20:30b6ed7bf8fd 299 case HCI_EVNT_ACCEPT:
Kojto 20:30b6ed7bf8fd 300 {
Kojto 20:30b6ed7bf8fd 301 STREAM_TO_UINT32((uint8_t *)pucReceivedParams,ACCEPT_SD_OFFSET,*(uint32_t *)ret_param);
Kojto 20:30b6ed7bf8fd 302 ret_param = ((uint8_t *)ret_param) + 4;
Kojto 20:30b6ed7bf8fd 303 STREAM_TO_UINT32((uint8_t *)pucReceivedParams,ACCEPT_RETURN_STATUS_OFFSET,*(uint32_t *)ret_param);
Kojto 20:30b6ed7bf8fd 304 ret_param = ((uint8_t *)ret_param) + 4;
Kojto 20:30b6ed7bf8fd 305
Kojto 20:30b6ed7bf8fd 306 //This argument returns in network order
Kojto 20:30b6ed7bf8fd 307 memcpy((uint8_t *)ret_param, pucReceivedParams + ACCEPT_ADDRESS__OFFSET, sizeof(sockaddr));
Kojto 20:30b6ed7bf8fd 308 break;
Kojto 20:30b6ed7bf8fd 309 }
Kojto 20:30b6ed7bf8fd 310
Kojto 20:30b6ed7bf8fd 311 case HCI_EVNT_RECV:
Kojto 20:30b6ed7bf8fd 312 case HCI_EVNT_RECVFROM:
Kojto 20:30b6ed7bf8fd 313 {
Kojto 20:30b6ed7bf8fd 314 STREAM_TO_UINT32((uint8_t *)pucReceivedParams,SL_RECEIVE_SD_OFFSET ,*(uint32_t *)ret_param);
Kojto 20:30b6ed7bf8fd 315 ret_param = ((uint8_t *)ret_param) + 4;
Kojto 20:30b6ed7bf8fd 316 STREAM_TO_UINT32((uint8_t *)pucReceivedParams,SL_RECEIVE_NUM_BYTES_OFFSET,*(uint32_t *)ret_param);
Kojto 20:30b6ed7bf8fd 317 ret_param = ((uint8_t *)ret_param) + 4;
Kojto 20:30b6ed7bf8fd 318 STREAM_TO_UINT32((uint8_t *)pucReceivedParams,SL_RECEIVE__FLAGS__OFFSET,*(uint32_t *)ret_param);
Kojto 20:30b6ed7bf8fd 319
Kojto 20:30b6ed7bf8fd 320 if(((tBsdReadReturnParams *)ret_param)->iNumberOfBytes == ERROR_SOCKET_INACTIVE)
Kojto 20:30b6ed7bf8fd 321 {
Kojto 20:30b6ed7bf8fd 322 set_socket_active_status(((tBsdReadReturnParams *)ret_param)->iSocketDescriptor,SOCKET_STATUS_INACTIVE);
Kojto 20:30b6ed7bf8fd 323 }
Kojto 20:30b6ed7bf8fd 324 break;
Kojto 20:30b6ed7bf8fd 325 }
Kojto 20:30b6ed7bf8fd 326
Kojto 20:30b6ed7bf8fd 327 case HCI_EVNT_SEND:
Kojto 20:30b6ed7bf8fd 328 case HCI_EVNT_SENDTO:
Kojto 20:30b6ed7bf8fd 329 {
Kojto 20:30b6ed7bf8fd 330 STREAM_TO_UINT32((uint8_t *)pucReceivedParams,SL_RECEIVE_SD_OFFSET ,*(uint32_t *)ret_param);
Kojto 20:30b6ed7bf8fd 331 ret_param = ((uint8_t *)ret_param) + 4;
Kojto 20:30b6ed7bf8fd 332 STREAM_TO_UINT32((uint8_t *)pucReceivedParams,SL_RECEIVE_NUM_BYTES_OFFSET,*(uint32_t *)ret_param);
Kojto 20:30b6ed7bf8fd 333 ret_param = ((uint8_t *)ret_param) + 4;
Kojto 20:30b6ed7bf8fd 334
Kojto 20:30b6ed7bf8fd 335 break;
Kojto 20:30b6ed7bf8fd 336 }
Kojto 20:30b6ed7bf8fd 337
Kojto 20:30b6ed7bf8fd 338 case HCI_EVNT_SELECT:
Kojto 20:30b6ed7bf8fd 339 {
Kojto 20:30b6ed7bf8fd 340 STREAM_TO_UINT32((uint8_t *)pucReceivedParams,SELECT_STATUS_OFFSET,*(uint32_t *)ret_param);
Kojto 20:30b6ed7bf8fd 341 ret_param = ((uint8_t *)ret_param) + 4;
Kojto 20:30b6ed7bf8fd 342 STREAM_TO_UINT32((uint8_t *)pucReceivedParams,SELECT_READFD_OFFSET,*(uint32_t *)ret_param);
Kojto 20:30b6ed7bf8fd 343 ret_param = ((uint8_t *)ret_param) + 4;
Kojto 20:30b6ed7bf8fd 344 STREAM_TO_UINT32((uint8_t *)pucReceivedParams,SELECT_WRITEFD_OFFSET,*(uint32_t *)ret_param);
Kojto 20:30b6ed7bf8fd 345 ret_param = ((uint8_t *)ret_param) + 4;
Kojto 20:30b6ed7bf8fd 346 STREAM_TO_UINT32((uint8_t *)pucReceivedParams,SELECT_EXFD_OFFSET,*(uint32_t *)ret_param);
Kojto 20:30b6ed7bf8fd 347 break;
Kojto 20:30b6ed7bf8fd 348 }
Kojto 20:30b6ed7bf8fd 349
Kojto 20:30b6ed7bf8fd 350 case HCI_CMND_GETSOCKOPT:
Kojto 20:30b6ed7bf8fd 351
Kojto 20:30b6ed7bf8fd 352 STREAM_TO_UINT8(received_data, HCI_EVENT_STATUS_OFFSET,((tBsdGetSockOptReturnParams *)ret_param)->iStatus);
Kojto 20:30b6ed7bf8fd 353 //This argument returns in network order
Kojto 20:30b6ed7bf8fd 354 memcpy((uint8_t *)ret_param, pucReceivedParams, 4);
Kojto 20:30b6ed7bf8fd 355 break;
Kojto 20:30b6ed7bf8fd 356
Kojto 20:30b6ed7bf8fd 357 case HCI_CMND_WLAN_IOCTL_GET_SCAN_RESULTS:
Kojto 20:30b6ed7bf8fd 358
Kojto 20:30b6ed7bf8fd 359 STREAM_TO_UINT32((uint8_t *)pucReceivedParams,GET_SCAN_RESULTS_TABlE_COUNT_OFFSET,*(uint32_t *)ret_param);
Kojto 20:30b6ed7bf8fd 360 ret_param = ((uint8_t *)ret_param) + 4;
Kojto 20:30b6ed7bf8fd 361 STREAM_TO_UINT32((uint8_t *)pucReceivedParams,GET_SCAN_RESULTS_SCANRESULT_STATUS_OFFSET,*(uint32_t *)ret_param);
Kojto 20:30b6ed7bf8fd 362 ret_param = ((uint8_t *)ret_param) + 4;
Kojto 20:30b6ed7bf8fd 363 STREAM_TO_UINT16((uint8_t *)pucReceivedParams,GET_SCAN_RESULTS_ISVALID_TO_SSIDLEN_OFFSET,*(uint32_t *)ret_param);
Kojto 20:30b6ed7bf8fd 364 ret_param = ((uint8_t *)ret_param) + 2;
Kojto 20:30b6ed7bf8fd 365 STREAM_TO_UINT16((uint8_t *)pucReceivedParams,GET_SCAN_RESULTS_FRAME_TIME_OFFSET,*(uint32_t *)ret_param);
Kojto 20:30b6ed7bf8fd 366 ret_param = ((uint8_t *)ret_param) + 2;
Kojto 20:30b6ed7bf8fd 367 memcpy((uint8_t *)ret_param, (uint8_t *)(pucReceivedParams + GET_SCAN_RESULTS_FRAME_TIME_OFFSET + 2), GET_SCAN_RESULTS_SSID_MAC_LENGTH);
Kojto 20:30b6ed7bf8fd 368 break;
Kojto 20:30b6ed7bf8fd 369
Kojto 20:30b6ed7bf8fd 370 case HCI_CMND_SIMPLE_LINK_START:
Kojto 20:30b6ed7bf8fd 371 break;
Kojto 20:30b6ed7bf8fd 372
Kojto 20:30b6ed7bf8fd 373 case HCI_NETAPP_IPCONFIG:
Kojto 20:30b6ed7bf8fd 374
Kojto 20:30b6ed7bf8fd 375 //Read IP address
Kojto 20:30b6ed7bf8fd 376 STREAM_TO_STREAM(RecvParams,RetParams,NETAPP_IPCONFIG_IP_LENGTH);
Kojto 20:30b6ed7bf8fd 377 RecvParams += 4;
Kojto 20:30b6ed7bf8fd 378
Kojto 20:30b6ed7bf8fd 379 //Read subnet
Kojto 20:30b6ed7bf8fd 380 STREAM_TO_STREAM(RecvParams,RetParams,NETAPP_IPCONFIG_IP_LENGTH);
Kojto 20:30b6ed7bf8fd 381 RecvParams += 4;
Kojto 20:30b6ed7bf8fd 382
Kojto 20:30b6ed7bf8fd 383 //Read default GW
Kojto 20:30b6ed7bf8fd 384 STREAM_TO_STREAM(RecvParams,RetParams,NETAPP_IPCONFIG_IP_LENGTH);
Kojto 20:30b6ed7bf8fd 385 RecvParams += 4;
Kojto 20:30b6ed7bf8fd 386
Kojto 20:30b6ed7bf8fd 387 //Read DHCP server
Kojto 20:30b6ed7bf8fd 388 STREAM_TO_STREAM(RecvParams,RetParams,NETAPP_IPCONFIG_IP_LENGTH);
Kojto 20:30b6ed7bf8fd 389 RecvParams += 4;
Kojto 20:30b6ed7bf8fd 390
Kojto 20:30b6ed7bf8fd 391 //Read DNS server
Kojto 20:30b6ed7bf8fd 392 STREAM_TO_STREAM(RecvParams,RetParams,NETAPP_IPCONFIG_IP_LENGTH);
Kojto 20:30b6ed7bf8fd 393 RecvParams += 4;
Kojto 20:30b6ed7bf8fd 394
Kojto 20:30b6ed7bf8fd 395 //Read Mac address
Kojto 20:30b6ed7bf8fd 396 STREAM_TO_STREAM(RecvParams,RetParams,NETAPP_IPCONFIG_MAC_LENGTH);
Kojto 20:30b6ed7bf8fd 397 RecvParams += 6;
Kojto 20:30b6ed7bf8fd 398
Kojto 20:30b6ed7bf8fd 399 //Read SSID
Kojto 20:30b6ed7bf8fd 400 STREAM_TO_STREAM(RecvParams,RetParams,NETAPP_IPCONFIG_SSID_LENGTH);
SolderSplashLabs 38:1d374a7f0c0d 401 break;
Kojto 44:960b73df5981 402
SolderSplashLabs 38:1d374a7f0c0d 403 default :
SolderSplashLabs 38:1d374a7f0c0d 404 DBG_HCI("UNKNOWN Event Received : 0x%04X ", received_op_code);
SolderSplashLabs 38:1d374a7f0c0d 405 break;
Kojto 20:30b6ed7bf8fd 406 }
Kojto 44:960b73df5981 407
Kojto 20:30b6ed7bf8fd 408 }
Kojto 20:30b6ed7bf8fd 409 if (received_op_code == _simple_link.get_op_code())
Kojto 20:30b6ed7bf8fd 410 {
Kojto 20:30b6ed7bf8fd 411 _simple_link.set_op_code(0);
Kojto 20:30b6ed7bf8fd 412 }
Kojto 20:30b6ed7bf8fd 413 }
Kojto 20:30b6ed7bf8fd 414 else
Kojto 20:30b6ed7bf8fd 415 {
Kojto 20:30b6ed7bf8fd 416 pucReceivedParams = received_data;
Kojto 20:30b6ed7bf8fd 417 STREAM_TO_UINT8((uint8_t *)received_data, HCI_PACKET_ARGSIZE_OFFSET, argument_size);
Kojto 20:30b6ed7bf8fd 418
Kojto 20:30b6ed7bf8fd 419 STREAM_TO_UINT16((uint8_t *)received_data, HCI_PACKET_LENGTH_OFFSET, length);
Kojto 20:30b6ed7bf8fd 420
Kojto 20:30b6ed7bf8fd 421 // Data received: note that the only case where from and from length
Kojto 20:30b6ed7bf8fd 422 // are not null is in recv from, so fill the args accordingly
Kojto 20:30b6ed7bf8fd 423 if (from)
Kojto 20:30b6ed7bf8fd 424 {
Kojto 20:30b6ed7bf8fd 425 STREAM_TO_UINT32((uint8_t *)(received_data + HCI_DATA_HEADER_SIZE), BSD_RECV_FROM_FROMLEN_OFFSET, *(uint32_t *)fromlen);
Kojto 20:30b6ed7bf8fd 426 memcpy(from, (received_data + HCI_DATA_HEADER_SIZE + BSD_RECV_FROM_FROM_OFFSET) ,*fromlen);
Kojto 20:30b6ed7bf8fd 427 }
Kojto 20:30b6ed7bf8fd 428
Kojto 20:30b6ed7bf8fd 429 memcpy(ret_param, pucReceivedParams + HCI_DATA_HEADER_SIZE + argument_size, length - argument_size);
Kojto 20:30b6ed7bf8fd 430
Kojto 20:30b6ed7bf8fd 431 _simple_link.set_pending_data(0);
Kojto 20:30b6ed7bf8fd 432 }
Kojto 20:30b6ed7bf8fd 433
Kojto 20:30b6ed7bf8fd 434 _simple_link.set_data_received_flag(0);
Kojto 20:30b6ed7bf8fd 435 _spi.wlan_irq_enable();
Kojto 20:30b6ed7bf8fd 436
Kojto 20:30b6ed7bf8fd 437 // Since we are going to TX - we need to handle this event after the ResumeSPi since we need interrupts
Kojto 20:30b6ed7bf8fd 438 if ((*received_data == HCI_TYPE_EVNT) && (received_op_code == HCI_EVNT_PATCHES_REQ))
Kojto 20:30b6ed7bf8fd 439 {
Kojto 20:30b6ed7bf8fd 440 hci_unsol_handle_patch_request((uint8_t *)received_data);
Kojto 20:30b6ed7bf8fd 441 }
Kojto 20:30b6ed7bf8fd 442 if ((_simple_link.get_op_code() == 0) && (_simple_link.get_pending_data() == 0))
Kojto 20:30b6ed7bf8fd 443 {
heroic 54:cae3dfc6df20 444 led1=1;
Kojto 20:30b6ed7bf8fd 445 return NULL;
Kojto 20:30b6ed7bf8fd 446 }
Kojto 20:30b6ed7bf8fd 447 }
Kojto 20:30b6ed7bf8fd 448 }
Kojto 20:30b6ed7bf8fd 449 }
Kojto 20:30b6ed7bf8fd 450
Kojto 20:30b6ed7bf8fd 451 int32_t cc3000_event::hci_unsol_event_handler(uint8_t *event_hdr) {
Kojto 20:30b6ed7bf8fd 452 uint8_t *data = NULL;
Kojto 20:30b6ed7bf8fd 453 int32_t event_type;
Kojto 20:30b6ed7bf8fd 454 uint32_t number_of_released_packets;
Kojto 20:30b6ed7bf8fd 455 uint32_t number_of_sent_packets;
Kojto 20:30b6ed7bf8fd 456
Kojto 20:30b6ed7bf8fd 457 STREAM_TO_UINT16(event_hdr, HCI_EVENT_OPCODE_OFFSET,event_type);
Kojto 20:30b6ed7bf8fd 458
Kojto 20:30b6ed7bf8fd 459 if (event_type & HCI_EVNT_UNSOL_BASE) {
Kojto 20:30b6ed7bf8fd 460 switch(event_type) {
Kojto 20:30b6ed7bf8fd 461 case HCI_EVNT_DATA_UNSOL_FREE_BUFF:
Kojto 20:30b6ed7bf8fd 462 {
Kojto 20:30b6ed7bf8fd 463 hci_event_unsol_flowcontrol_handler(event_hdr);
Kojto 20:30b6ed7bf8fd 464
Kojto 20:30b6ed7bf8fd 465 number_of_released_packets = _simple_link.get_released_packets();
Kojto 20:30b6ed7bf8fd 466 number_of_sent_packets = _simple_link.get_sent_packets();
Kojto 20:30b6ed7bf8fd 467
Kojto 20:30b6ed7bf8fd 468 if (number_of_released_packets == number_of_sent_packets)
Kojto 20:30b6ed7bf8fd 469 {
Kojto 20:30b6ed7bf8fd 470 if (_simple_link.get_tx_complete_signal())
Kojto 20:30b6ed7bf8fd 471 {
Kojto 20:30b6ed7bf8fd 472 //tWlanCB func_pointer = (tWlanCB)_simple_link.get_func_pointer(WLAN_CB);
Kojto 20:30b6ed7bf8fd 473 _cc3000.usync_callback(HCI_EVENT_CC3000_CAN_SHUT_DOWN, NULL, 0);
Kojto 20:30b6ed7bf8fd 474 }
Kojto 20:30b6ed7bf8fd 475 }
Kojto 20:30b6ed7bf8fd 476 return 1;
Kojto 20:30b6ed7bf8fd 477 }
Kojto 20:30b6ed7bf8fd 478 }
Kojto 20:30b6ed7bf8fd 479 }
Kojto 20:30b6ed7bf8fd 480
Kojto 20:30b6ed7bf8fd 481 if (event_type & HCI_EVNT_WLAN_UNSOL_BASE) {
Kojto 20:30b6ed7bf8fd 482 switch(event_type) {
Kojto 20:30b6ed7bf8fd 483 case HCI_EVNT_WLAN_KEEPALIVE:
Kojto 20:30b6ed7bf8fd 484 case HCI_EVNT_WLAN_UNSOL_CONNECT:
Kojto 20:30b6ed7bf8fd 485 case HCI_EVNT_WLAN_UNSOL_DISCONNECT:
Kojto 20:30b6ed7bf8fd 486 case HCI_EVNT_WLAN_UNSOL_INIT:
Kojto 20:30b6ed7bf8fd 487 case HCI_EVNT_WLAN_ASYNC_SIMPLE_CONFIG_DONE:
Kojto 45:50ab13d8f2dc 488 _cc3000.usync_callback(event_type, 0, 0);
Kojto 20:30b6ed7bf8fd 489 break;
Kojto 20:30b6ed7bf8fd 490 case HCI_EVNT_WLAN_UNSOL_DHCP:
Kojto 20:30b6ed7bf8fd 491 {
Kojto 20:30b6ed7bf8fd 492 uint8_t params[NETAPP_IPCONFIG_MAC_OFFSET + 1]; // extra byte is for the status
Kojto 20:30b6ed7bf8fd 493 uint8_t *recParams = params;
Kojto 20:30b6ed7bf8fd 494 data = (uint8_t *)(event_hdr) + HCI_EVENT_HEADER_SIZE;
Kojto 20:30b6ed7bf8fd 495
Kojto 20:30b6ed7bf8fd 496 //Read IP address
Kojto 20:30b6ed7bf8fd 497 STREAM_TO_STREAM(data,recParams,NETAPP_IPCONFIG_IP_LENGTH);
Kojto 20:30b6ed7bf8fd 498 data += 4;
Kojto 20:30b6ed7bf8fd 499 //Read subnet
Kojto 20:30b6ed7bf8fd 500 STREAM_TO_STREAM(data,recParams,NETAPP_IPCONFIG_IP_LENGTH);
Kojto 20:30b6ed7bf8fd 501 data += 4;
Kojto 20:30b6ed7bf8fd 502 //Read default GW
Kojto 20:30b6ed7bf8fd 503 STREAM_TO_STREAM(data,recParams,NETAPP_IPCONFIG_IP_LENGTH);
Kojto 20:30b6ed7bf8fd 504 data += 4;
Kojto 20:30b6ed7bf8fd 505 //Read DHCP server
Kojto 20:30b6ed7bf8fd 506 STREAM_TO_STREAM(data,recParams,NETAPP_IPCONFIG_IP_LENGTH);
Kojto 20:30b6ed7bf8fd 507 data += 4;
Kojto 20:30b6ed7bf8fd 508 //Read DNS server
Kojto 20:30b6ed7bf8fd 509 STREAM_TO_STREAM(data,recParams,NETAPP_IPCONFIG_IP_LENGTH);
Kojto 20:30b6ed7bf8fd 510 // read the status
Kojto 20:30b6ed7bf8fd 511 STREAM_TO_UINT8(event_hdr, HCI_EVENT_STATUS_OFFSET, *recParams);
Kojto 20:30b6ed7bf8fd 512
Kojto 45:50ab13d8f2dc 513 _cc3000.usync_callback(event_type, (uint8_t *)params, sizeof(params));
Kojto 45:50ab13d8f2dc 514
Kojto 20:30b6ed7bf8fd 515 break;
Kojto 20:30b6ed7bf8fd 516 }
Kojto 20:30b6ed7bf8fd 517 case HCI_EVNT_WLAN_ASYNC_PING_REPORT:
Kojto 20:30b6ed7bf8fd 518 {
Kojto 20:30b6ed7bf8fd 519 netapp_pingreport_args_t params;
Kojto 20:30b6ed7bf8fd 520 data = (uint8_t *)(event_hdr) + HCI_EVENT_HEADER_SIZE;
Kojto 20:30b6ed7bf8fd 521 STREAM_TO_UINT32(data, NETAPP_PING_PACKETS_SENT_OFFSET, params.packets_sent);
Kojto 20:30b6ed7bf8fd 522 STREAM_TO_UINT32(data, NETAPP_PING_PACKETS_RCVD_OFFSET, params.packets_received);
Kojto 20:30b6ed7bf8fd 523 STREAM_TO_UINT32(data, NETAPP_PING_MIN_RTT_OFFSET, params.min_round_time);
Kojto 20:30b6ed7bf8fd 524 STREAM_TO_UINT32(data, NETAPP_PING_MAX_RTT_OFFSET, params.max_round_time);
Kojto 20:30b6ed7bf8fd 525 STREAM_TO_UINT32(data, NETAPP_PING_AVG_RTT_OFFSET, params.avg_round_time);
Kojto 20:30b6ed7bf8fd 526
Kojto 45:50ab13d8f2dc 527 _cc3000.usync_callback(event_type, (uint8_t *)&params, sizeof(params));
Kojto 20:30b6ed7bf8fd 528 break;
Kojto 20:30b6ed7bf8fd 529 }
Kojto 20:30b6ed7bf8fd 530 case HCI_EVNT_BSD_TCP_CLOSE_WAIT:
Kojto 20:30b6ed7bf8fd 531 {
Kojto 45:50ab13d8f2dc 532 _cc3000.usync_callback(event_type, NULL, 0);
Kojto 20:30b6ed7bf8fd 533 break;
Kojto 20:30b6ed7bf8fd 534 }
Kojto 20:30b6ed7bf8fd 535
Kojto 20:30b6ed7bf8fd 536 //'default' case which means "event not supported"
Kojto 20:30b6ed7bf8fd 537 default:
Kojto 20:30b6ed7bf8fd 538 return (0);
Kojto 20:30b6ed7bf8fd 539 }
Kojto 20:30b6ed7bf8fd 540 return(1);
Kojto 20:30b6ed7bf8fd 541 }
Kojto 20:30b6ed7bf8fd 542
Kojto 20:30b6ed7bf8fd 543 if ((event_type == HCI_EVNT_SEND) || (event_type == HCI_EVNT_SENDTO) || (event_type == HCI_EVNT_WRITE)) {
Kojto 20:30b6ed7bf8fd 544 uint8_t *pArg;
Kojto 20:30b6ed7bf8fd 545 int32_t status;
Kojto 20:30b6ed7bf8fd 546 pArg = M_BSD_RESP_PARAMS_OFFSET(event_hdr);
Kojto 20:30b6ed7bf8fd 547 STREAM_TO_UINT32(pArg, BSD_RSP_PARAMS_STATUS_OFFSET,status);
Kojto 20:30b6ed7bf8fd 548 if (ERROR_SOCKET_INACTIVE == status) {
Kojto 20:30b6ed7bf8fd 549 // The only synchronous event that can come from SL device in form of
Kojto 20:30b6ed7bf8fd 550 // command complete is "Command Complete" on data sent, in case SL device
Kojto 20:30b6ed7bf8fd 551 // was unable to transmit
Kojto 20:30b6ed7bf8fd 552 int32_t transmit_error = _simple_link.get_transmit_error();
Kojto 20:30b6ed7bf8fd 553 STREAM_TO_UINT8(event_hdr, HCI_EVENT_STATUS_OFFSET, transmit_error);
Kojto 20:30b6ed7bf8fd 554 _simple_link.set_transmit_error(transmit_error);
Kojto 20:30b6ed7bf8fd 555 update_socket_active_status(M_BSD_RESP_PARAMS_OFFSET(event_hdr));
Kojto 20:30b6ed7bf8fd 556 return (1);
Kojto 20:30b6ed7bf8fd 557 }
Kojto 20:30b6ed7bf8fd 558 else {
Kojto 20:30b6ed7bf8fd 559 return (0);
Kojto 20:30b6ed7bf8fd 560 }
Kojto 20:30b6ed7bf8fd 561 }
Kojto 20:30b6ed7bf8fd 562 return(0);
Kojto 20:30b6ed7bf8fd 563 }
Kojto 20:30b6ed7bf8fd 564
Kojto 20:30b6ed7bf8fd 565 int32_t cc3000_event::hci_unsolicited_event_handler(void) {
Kojto 20:30b6ed7bf8fd 566 uint32_t res = 0;
Kojto 20:30b6ed7bf8fd 567 uint8_t *received_data;
Kojto 20:30b6ed7bf8fd 568
Kojto 20:30b6ed7bf8fd 569 if (_simple_link.get_data_received_flag() != 0) {
Kojto 20:30b6ed7bf8fd 570 received_data = (_simple_link.get_received_data());
Kojto 20:30b6ed7bf8fd 571
Kojto 20:30b6ed7bf8fd 572 if (*received_data == HCI_TYPE_EVNT) {
Kojto 20:30b6ed7bf8fd 573 // unsolicited event received - finish handling
Kojto 20:30b6ed7bf8fd 574 if (hci_unsol_event_handler((uint8_t *)received_data) == 1) {
Kojto 20:30b6ed7bf8fd 575 // An unsolicited event was received:
Kojto 20:30b6ed7bf8fd 576 // release the buffer and clean the event received
Kojto 20:30b6ed7bf8fd 577 _simple_link.set_data_received_flag(0);
Kojto 20:30b6ed7bf8fd 578
Kojto 20:30b6ed7bf8fd 579 res = 1;
Kojto 20:30b6ed7bf8fd 580 _spi.wlan_irq_enable();
Kojto 20:30b6ed7bf8fd 581 }
Kojto 20:30b6ed7bf8fd 582 }
Kojto 20:30b6ed7bf8fd 583 }
Kojto 20:30b6ed7bf8fd 584 return res;
Kojto 20:30b6ed7bf8fd 585 }
Kojto 20:30b6ed7bf8fd 586
Kojto 20:30b6ed7bf8fd 587 void cc3000_event::set_socket_active_status(int32_t sd, int32_t status) {
Kojto 45:50ab13d8f2dc 588 if (M_IS_VALID_SD(sd) && M_IS_VALID_STATUS(status)) {
Kojto 20:30b6ed7bf8fd 589 socket_active_status &= ~(1 << sd); /* clean socket's mask */
Kojto 20:30b6ed7bf8fd 590 socket_active_status |= (status << sd); /* set new socket's mask */
Kojto 20:30b6ed7bf8fd 591 }
Kojto 20:30b6ed7bf8fd 592 }
Kojto 20:30b6ed7bf8fd 593
Kojto 20:30b6ed7bf8fd 594 int32_t cc3000_event::hci_event_unsol_flowcontrol_handler(uint8_t *event) {
Kojto 20:30b6ed7bf8fd 595 int32_t temp, value;
Kojto 20:30b6ed7bf8fd 596 uint16_t i;
Kojto 20:30b6ed7bf8fd 597 uint16_t pusNumberOfHandles=0;
Kojto 20:30b6ed7bf8fd 598 uint8_t *pReadPayload;
Kojto 20:30b6ed7bf8fd 599
Kojto 20:30b6ed7bf8fd 600 STREAM_TO_UINT16((uint8_t *)event,HCI_EVENT_HEADER_SIZE,pusNumberOfHandles);
Kojto 20:30b6ed7bf8fd 601 pReadPayload = ((uint8_t *)event + HCI_EVENT_HEADER_SIZE + sizeof(pusNumberOfHandles));
Kojto 20:30b6ed7bf8fd 602 temp = 0;
Kojto 20:30b6ed7bf8fd 603
Kojto 20:30b6ed7bf8fd 604 for(i = 0; i < pusNumberOfHandles; i++) {
Kojto 20:30b6ed7bf8fd 605 STREAM_TO_UINT16(pReadPayload, FLOW_CONTROL_EVENT_FREE_BUFFS_OFFSET, value);
Kojto 20:30b6ed7bf8fd 606 temp += value;
Kojto 20:30b6ed7bf8fd 607 pReadPayload += FLOW_CONTROL_EVENT_SIZE;
Kojto 20:30b6ed7bf8fd 608 }
Kojto 20:30b6ed7bf8fd 609
Kojto 20:30b6ed7bf8fd 610 _simple_link.set_number_free_buffers(_simple_link.get_number_free_buffers() + temp);
Kojto 20:30b6ed7bf8fd 611 _simple_link.set_number_of_released_packets(_simple_link.get_released_packets() + temp);
Kojto 20:30b6ed7bf8fd 612
Kojto 20:30b6ed7bf8fd 613 return(ESUCCESS);
Kojto 20:30b6ed7bf8fd 614 }
Kojto 20:30b6ed7bf8fd 615
Kojto 20:30b6ed7bf8fd 616 int32_t cc3000_event::get_socket_active_status(int32_t sd) {
Kojto 45:50ab13d8f2dc 617 if (M_IS_VALID_SD(sd)) {
Kojto 20:30b6ed7bf8fd 618 return (socket_active_status & (1 << sd)) ? SOCKET_STATUS_INACTIVE : SOCKET_STATUS_ACTIVE;
Kojto 20:30b6ed7bf8fd 619 } else {
Kojto 20:30b6ed7bf8fd 620 return SOCKET_STATUS_INACTIVE;
Kojto 20:30b6ed7bf8fd 621 }
Kojto 20:30b6ed7bf8fd 622 }
Kojto 20:30b6ed7bf8fd 623
Kojto 20:30b6ed7bf8fd 624 void cc3000_event::update_socket_active_status(uint8_t *resp_params) {
Kojto 20:30b6ed7bf8fd 625 int32_t status, sd;
Kojto 20:30b6ed7bf8fd 626
Kojto 20:30b6ed7bf8fd 627 STREAM_TO_UINT32(resp_params, BSD_RSP_PARAMS_SOCKET_OFFSET,sd);
Kojto 20:30b6ed7bf8fd 628 STREAM_TO_UINT32(resp_params, BSD_RSP_PARAMS_STATUS_OFFSET,status);
Kojto 20:30b6ed7bf8fd 629
Kojto 45:50ab13d8f2dc 630 if (ERROR_SOCKET_INACTIVE == status) {
Kojto 20:30b6ed7bf8fd 631 set_socket_active_status(sd, SOCKET_STATUS_INACTIVE);
Kojto 20:30b6ed7bf8fd 632 }
Kojto 20:30b6ed7bf8fd 633 }
Kojto 20:30b6ed7bf8fd 634
Kojto 20:30b6ed7bf8fd 635 void cc3000_event::simplelink_wait_event(uint16_t op_code, void *ret_param) {
Kojto 20:30b6ed7bf8fd 636 // In the blocking implementation the control to caller will be returned only
Kojto 20:30b6ed7bf8fd 637 // after the end of current transaction
Kojto 20:30b6ed7bf8fd 638 _simple_link.set_op_code(op_code);
Kojto 20:30b6ed7bf8fd 639 hci_event_handler(ret_param, 0, 0);
Kojto 20:30b6ed7bf8fd 640 }
Kojto 20:30b6ed7bf8fd 641
Kojto 20:30b6ed7bf8fd 642 void cc3000_event::simplelink_wait_data(uint8_t *pBuf, uint8_t *from, uint8_t *fromlen) {
Kojto 20:30b6ed7bf8fd 643 // In the blocking implementation the control to caller will be returned only
Kojto 20:30b6ed7bf8fd 644 // after the end of current transaction, i.e. only after data will be received
Kojto 20:30b6ed7bf8fd 645 _simple_link.set_pending_data(1);
Kojto 20:30b6ed7bf8fd 646 hci_event_handler(pBuf, from, fromlen);
Kojto 20:30b6ed7bf8fd 647 }
Kojto 20:30b6ed7bf8fd 648
Kojto 20:30b6ed7bf8fd 649
Kojto 45:50ab13d8f2dc 650 } // end of cc3000