cc3000 driver with expanded buffers.

Fork of cc3000_hostdriver_mbedsocket by Martin Kojtal

Committer:
Kojto
Date:
Wed Oct 02 20:29:31 2013 +0200
Revision:
17:14b6a3a2b622
Parent:
14:28c8bbbea025
Child:
20:30b6ed7bf8fd
Child:
23:fed7f64dd520
Hci print internal, Endpoint - unix ending lines

- hci internal print function
- endpoint correction with ending lines (was PC)

Who changed what in which revision?

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