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