cc3000 hostdriver with the mbed socket interface. Hacked TCP Classes for better control of non-blocking sockets.
Fork of cc3000_hostdriver_mbedsocket by
cc3000_wlan.cpp@49:f2ffd6301ec5, 2014-10-31 (annotated)
- Committer:
- mfurseman
- Date:
- Fri Oct 31 19:44:52 2014 +0000
- Revision:
- 49:f2ffd6301ec5
- Parent:
- 45:50ab13d8f2dc
Hacked _closed_sockets to public and used it for socket
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 | |
Kojto | 20:30b6ed7bf8fd | 43 | namespace mbed_cc3000 { |
Kojto | 20:30b6ed7bf8fd | 44 | |
Kojto | 20:30b6ed7bf8fd | 45 | cc3000_wlan::cc3000_wlan(cc3000_simple_link &simple_link, cc3000_event &event, cc3000_spi &spi, cc3000_hci &hci) : |
Kojto | 20:30b6ed7bf8fd | 46 | _simple_link(simple_link), _event(event), _spi(spi), _hci(hci) { |
Kojto | 20:30b6ed7bf8fd | 47 | |
Kojto | 20:30b6ed7bf8fd | 48 | } |
Kojto | 20:30b6ed7bf8fd | 49 | |
Kojto | 20:30b6ed7bf8fd | 50 | cc3000_wlan::~cc3000_wlan() { |
Kojto | 20:30b6ed7bf8fd | 51 | |
Kojto | 20:30b6ed7bf8fd | 52 | } |
Kojto | 20:30b6ed7bf8fd | 53 | |
Kojto | 20:30b6ed7bf8fd | 54 | void cc3000_wlan::simpleLink_init_start(uint16_t patches_available_host) { |
Kojto | 20:30b6ed7bf8fd | 55 | uint8_t *ptr; |
Kojto | 20:30b6ed7bf8fd | 56 | uint8_t *args; |
Kojto | 20:30b6ed7bf8fd | 57 | |
Kojto | 20:30b6ed7bf8fd | 58 | ptr = _simple_link.get_transmit_buffer(); |
Kojto | 20:30b6ed7bf8fd | 59 | args = (uint8_t *)(ptr + HEADERS_SIZE_CMD); |
Kojto | 20:30b6ed7bf8fd | 60 | |
Kojto | 20:30b6ed7bf8fd | 61 | UINT8_TO_STREAM(args, ((patches_available_host) ? SL_PATCHES_REQUEST_FORCE_HOST : SL_PATCHES_REQUEST_DEFAULT)); |
Kojto | 20:30b6ed7bf8fd | 62 | |
Kojto | 20:30b6ed7bf8fd | 63 | // IRQ Line asserted - send HCI_CMND_SIMPLE_LINK_START to CC3000 |
Kojto | 20:30b6ed7bf8fd | 64 | _hci.command_send(HCI_CMND_SIMPLE_LINK_START, ptr, WLAN_SL_INIT_START_PARAMS_LEN); |
Kojto | 20:30b6ed7bf8fd | 65 | _event.simplelink_wait_event(HCI_CMND_SIMPLE_LINK_START, 0); |
Kojto | 20:30b6ed7bf8fd | 66 | } |
Kojto | 20:30b6ed7bf8fd | 67 | |
Kojto | 20:30b6ed7bf8fd | 68 | void cc3000_wlan::start(uint16_t patches_available_host) { |
Kojto | 20:30b6ed7bf8fd | 69 | uint32_t spi_irq_state; |
Kojto | 20:30b6ed7bf8fd | 70 | |
Kojto | 20:30b6ed7bf8fd | 71 | _simple_link.set_sent_packets(0); |
Kojto | 20:30b6ed7bf8fd | 72 | _simple_link.set_number_of_released_packets(0); |
Kojto | 20:30b6ed7bf8fd | 73 | _simple_link.set_op_code(0); |
Kojto | 20:30b6ed7bf8fd | 74 | _simple_link.set_number_free_buffers(0); |
Kojto | 20:30b6ed7bf8fd | 75 | _simple_link.set_buffer_length(0); |
Kojto | 20:30b6ed7bf8fd | 76 | _simple_link.set_buffer_size(0); |
Kojto | 20:30b6ed7bf8fd | 77 | _simple_link.set_pending_data(0); |
Kojto | 20:30b6ed7bf8fd | 78 | _simple_link.set_transmit_error(0); |
Kojto | 20:30b6ed7bf8fd | 79 | _simple_link.set_data_received_flag(0); |
Kojto | 20:30b6ed7bf8fd | 80 | _simple_link.set_buffer_size(0); |
Kojto | 20:30b6ed7bf8fd | 81 | |
Kojto | 20:30b6ed7bf8fd | 82 | // init spi |
Kojto | 20:30b6ed7bf8fd | 83 | _spi.open(); |
Kojto | 20:30b6ed7bf8fd | 84 | // Check the IRQ line |
Kojto | 20:30b6ed7bf8fd | 85 | spi_irq_state = _spi.wlan_irq_read(); |
Kojto | 20:30b6ed7bf8fd | 86 | // ASIC 1273 chip enable: toggle WLAN EN line |
Kojto | 34:1ad18123bf11 | 87 | _spi.set_wlan_en(WLAN_ENABLE); |
Kojto | 20:30b6ed7bf8fd | 88 | |
Kojto | 45:50ab13d8f2dc | 89 | if (spi_irq_state) { |
Kojto | 20:30b6ed7bf8fd | 90 | // wait till the IRQ line goes low |
Kojto | 45:50ab13d8f2dc | 91 | while(_spi.wlan_irq_read() != 0); |
Kojto | 45:50ab13d8f2dc | 92 | } else { |
Kojto | 20:30b6ed7bf8fd | 93 | // wait till the IRQ line goes high and then low |
Kojto | 45:50ab13d8f2dc | 94 | while(_spi.wlan_irq_read() == 0); |
Kojto | 45:50ab13d8f2dc | 95 | while(_spi.wlan_irq_read() != 0); |
Kojto | 20:30b6ed7bf8fd | 96 | } |
Kojto | 20:30b6ed7bf8fd | 97 | simpleLink_init_start(patches_available_host); |
Kojto | 20:30b6ed7bf8fd | 98 | |
Kojto | 20:30b6ed7bf8fd | 99 | // Read Buffer's size and finish |
Kojto | 20:30b6ed7bf8fd | 100 | _hci.command_send(HCI_CMND_READ_BUFFER_SIZE, _simple_link.get_transmit_buffer(), 0); |
Kojto | 20:30b6ed7bf8fd | 101 | _event.simplelink_wait_event(HCI_CMND_READ_BUFFER_SIZE, 0); |
Kojto | 20:30b6ed7bf8fd | 102 | } |
Kojto | 20:30b6ed7bf8fd | 103 | |
Kojto | 20:30b6ed7bf8fd | 104 | |
Kojto | 20:30b6ed7bf8fd | 105 | void cc3000_wlan::stop() { |
Kojto | 20:30b6ed7bf8fd | 106 | // ASIC 1273 chip disable |
Kojto | 45:50ab13d8f2dc | 107 | _spi.set_wlan_en(WLAN_DISABLE); |
Kojto | 20:30b6ed7bf8fd | 108 | |
Kojto | 45:50ab13d8f2dc | 109 | // Wait till IRQ line goes high |
Kojto | 45:50ab13d8f2dc | 110 | while(_spi.wlan_irq_read() == 0); |
Kojto | 20:30b6ed7bf8fd | 111 | |
Kojto | 20:30b6ed7bf8fd | 112 | _spi.close(); |
Kojto | 20:30b6ed7bf8fd | 113 | } |
Kojto | 20:30b6ed7bf8fd | 114 | |
Kojto | 20:30b6ed7bf8fd | 115 | |
Kojto | 20:30b6ed7bf8fd | 116 | int32_t cc3000_wlan::disconnect() { |
Kojto | 20:30b6ed7bf8fd | 117 | int32_t ret; |
Kojto | 20:30b6ed7bf8fd | 118 | uint8_t *ptr; |
Kojto | 20:30b6ed7bf8fd | 119 | |
Kojto | 20:30b6ed7bf8fd | 120 | ret = EFAIL; |
Kojto | 20:30b6ed7bf8fd | 121 | ptr = _simple_link.get_transmit_buffer(); |
Kojto | 20:30b6ed7bf8fd | 122 | |
Kojto | 20:30b6ed7bf8fd | 123 | _hci.command_send(HCI_CMND_WLAN_DISCONNECT, ptr, 0); |
Kojto | 20:30b6ed7bf8fd | 124 | |
Kojto | 20:30b6ed7bf8fd | 125 | // Wait for command complete event |
Kojto | 20:30b6ed7bf8fd | 126 | _event.simplelink_wait_event(HCI_CMND_WLAN_DISCONNECT, &ret); |
Kojto | 20:30b6ed7bf8fd | 127 | errno = ret; |
Kojto | 20:30b6ed7bf8fd | 128 | |
Kojto | 45:50ab13d8f2dc | 129 | return ret; |
Kojto | 20:30b6ed7bf8fd | 130 | } |
Kojto | 20:30b6ed7bf8fd | 131 | |
Kojto | 20:30b6ed7bf8fd | 132 | |
Kojto | 20:30b6ed7bf8fd | 133 | int32_t cc3000_wlan::ioctl_set_connection_policy(uint32_t should_connect_to_open_ap, |
Kojto | 20:30b6ed7bf8fd | 134 | uint32_t use_fast_connect, |
Kojto | 20:30b6ed7bf8fd | 135 | uint32_t use_profiles) { |
Kojto | 20:30b6ed7bf8fd | 136 | int32_t ret; |
Kojto | 20:30b6ed7bf8fd | 137 | uint8_t *ptr; |
Kojto | 20:30b6ed7bf8fd | 138 | uint8_t *args; |
Kojto | 20:30b6ed7bf8fd | 139 | |
Kojto | 20:30b6ed7bf8fd | 140 | ret = EFAIL; |
Kojto | 20:30b6ed7bf8fd | 141 | ptr = _simple_link.get_transmit_buffer(); |
Kojto | 20:30b6ed7bf8fd | 142 | args = (uint8_t *)(ptr + HEADERS_SIZE_CMD); |
Kojto | 20:30b6ed7bf8fd | 143 | |
Kojto | 20:30b6ed7bf8fd | 144 | // Fill in HCI packet structure |
Kojto | 20:30b6ed7bf8fd | 145 | args = UINT32_TO_STREAM(args, should_connect_to_open_ap); |
Kojto | 20:30b6ed7bf8fd | 146 | args = UINT32_TO_STREAM(args, use_fast_connect); |
Kojto | 20:30b6ed7bf8fd | 147 | args = UINT32_TO_STREAM(args, use_profiles); |
Kojto | 20:30b6ed7bf8fd | 148 | |
Kojto | 20:30b6ed7bf8fd | 149 | // Initiate a HCI command |
Kojto | 20:30b6ed7bf8fd | 150 | _hci.command_send(HCI_CMND_WLAN_IOCTL_SET_CONNECTION_POLICY, ptr, WLAN_SET_CONNECTION_POLICY_PARAMS_LEN); |
Kojto | 20:30b6ed7bf8fd | 151 | |
Kojto | 20:30b6ed7bf8fd | 152 | // Wait for command complete event |
Kojto | 20:30b6ed7bf8fd | 153 | _event.simplelink_wait_event(HCI_CMND_WLAN_IOCTL_SET_CONNECTION_POLICY, &ret); |
Kojto | 20:30b6ed7bf8fd | 154 | |
Kojto | 45:50ab13d8f2dc | 155 | return ret; |
Kojto | 20:30b6ed7bf8fd | 156 | } |
Kojto | 20:30b6ed7bf8fd | 157 | |
Kojto | 20:30b6ed7bf8fd | 158 | |
Kojto | 20:30b6ed7bf8fd | 159 | int32_t cc3000_wlan::ioctl_del_profile(uint32_t index) { |
Kojto | 20:30b6ed7bf8fd | 160 | int32_t ret; |
Kojto | 20:30b6ed7bf8fd | 161 | uint8_t *ptr; |
Kojto | 20:30b6ed7bf8fd | 162 | uint8_t *args; |
Kojto | 20:30b6ed7bf8fd | 163 | |
Kojto | 20:30b6ed7bf8fd | 164 | ptr = _simple_link.get_transmit_buffer(); |
Kojto | 20:30b6ed7bf8fd | 165 | args = (uint8_t *)(ptr + HEADERS_SIZE_CMD); |
Kojto | 20:30b6ed7bf8fd | 166 | |
Kojto | 20:30b6ed7bf8fd | 167 | // Fill in HCI packet structure |
Kojto | 20:30b6ed7bf8fd | 168 | args = UINT32_TO_STREAM(args, index); |
Kojto | 20:30b6ed7bf8fd | 169 | ret = EFAIL; |
Kojto | 20:30b6ed7bf8fd | 170 | |
Kojto | 20:30b6ed7bf8fd | 171 | // Initiate a HCI command |
Kojto | 20:30b6ed7bf8fd | 172 | _hci.command_send(HCI_CMND_WLAN_IOCTL_DEL_PROFILE, ptr, WLAN_DEL_PROFILE_PARAMS_LEN); |
Kojto | 20:30b6ed7bf8fd | 173 | |
Kojto | 20:30b6ed7bf8fd | 174 | // Wait for command complete event |
Kojto | 20:30b6ed7bf8fd | 175 | _event.simplelink_wait_event(HCI_CMND_WLAN_IOCTL_DEL_PROFILE, &ret); |
Kojto | 20:30b6ed7bf8fd | 176 | |
Kojto | 45:50ab13d8f2dc | 177 | return ret; |
Kojto | 20:30b6ed7bf8fd | 178 | } |
Kojto | 20:30b6ed7bf8fd | 179 | |
Kojto | 20:30b6ed7bf8fd | 180 | int32_t cc3000_wlan::set_event_mask(uint32_t mask) { |
Kojto | 20:30b6ed7bf8fd | 181 | int32_t ret; |
Kojto | 20:30b6ed7bf8fd | 182 | uint8_t *ptr; |
Kojto | 20:30b6ed7bf8fd | 183 | uint8_t *args; |
Kojto | 20:30b6ed7bf8fd | 184 | |
Kojto | 20:30b6ed7bf8fd | 185 | |
Kojto | 45:50ab13d8f2dc | 186 | if ((mask & HCI_EVNT_WLAN_TX_COMPLETE) == HCI_EVNT_WLAN_TX_COMPLETE) { |
Kojto | 20:30b6ed7bf8fd | 187 | _simple_link.set_tx_complete_signal(0); |
Kojto | 20:30b6ed7bf8fd | 188 | |
Kojto | 20:30b6ed7bf8fd | 189 | // Since an event is a virtual event - i.e. it is not coming from CC3000 |
Kojto | 20:30b6ed7bf8fd | 190 | // there is no need to send anything to the device if it was an only event |
Kojto | 45:50ab13d8f2dc | 191 | if (mask == HCI_EVNT_WLAN_TX_COMPLETE) { |
Kojto | 20:30b6ed7bf8fd | 192 | return 0; |
Kojto | 20:30b6ed7bf8fd | 193 | } |
Kojto | 20:30b6ed7bf8fd | 194 | |
Kojto | 20:30b6ed7bf8fd | 195 | mask &= ~HCI_EVNT_WLAN_TX_COMPLETE; |
Kojto | 20:30b6ed7bf8fd | 196 | mask |= HCI_EVNT_WLAN_UNSOL_BASE; |
Kojto | 45:50ab13d8f2dc | 197 | } else { |
Kojto | 20:30b6ed7bf8fd | 198 | _simple_link.set_tx_complete_signal(1); |
Kojto | 20:30b6ed7bf8fd | 199 | } |
Kojto | 20:30b6ed7bf8fd | 200 | |
Kojto | 20:30b6ed7bf8fd | 201 | ret = EFAIL; |
Kojto | 20:30b6ed7bf8fd | 202 | ptr = _simple_link.get_transmit_buffer(); |
Kojto | 20:30b6ed7bf8fd | 203 | args = (uint8_t *)(ptr + HEADERS_SIZE_CMD); |
Kojto | 20:30b6ed7bf8fd | 204 | |
Kojto | 20:30b6ed7bf8fd | 205 | // Fill in HCI packet structure |
Kojto | 20:30b6ed7bf8fd | 206 | args = UINT32_TO_STREAM(args, mask); |
Kojto | 20:30b6ed7bf8fd | 207 | |
Kojto | 20:30b6ed7bf8fd | 208 | // Initiate a HCI command |
Kojto | 20:30b6ed7bf8fd | 209 | _hci.command_send(HCI_CMND_EVENT_MASK, ptr, WLAN_SET_MASK_PARAMS_LEN); |
Kojto | 20:30b6ed7bf8fd | 210 | |
Kojto | 20:30b6ed7bf8fd | 211 | // Wait for command complete event |
Kojto | 20:30b6ed7bf8fd | 212 | _event.simplelink_wait_event(HCI_CMND_EVENT_MASK, &ret); |
Kojto | 20:30b6ed7bf8fd | 213 | |
Kojto | 45:50ab13d8f2dc | 214 | return ret; |
Kojto | 20:30b6ed7bf8fd | 215 | } |
Kojto | 20:30b6ed7bf8fd | 216 | |
Kojto | 20:30b6ed7bf8fd | 217 | |
Kojto | 20:30b6ed7bf8fd | 218 | int32_t cc3000_wlan::smart_config_start(uint32_t encrypted_flag) { |
Kojto | 20:30b6ed7bf8fd | 219 | int32_t ret; |
Kojto | 20:30b6ed7bf8fd | 220 | uint8_t *ptr; |
Kojto | 20:30b6ed7bf8fd | 221 | uint8_t *args; |
Kojto | 20:30b6ed7bf8fd | 222 | |
Kojto | 20:30b6ed7bf8fd | 223 | ret = EFAIL; |
Kojto | 20:30b6ed7bf8fd | 224 | ptr = _simple_link.get_transmit_buffer(); |
Kojto | 20:30b6ed7bf8fd | 225 | args = (uint8_t *)(ptr + HEADERS_SIZE_CMD); |
Kojto | 20:30b6ed7bf8fd | 226 | |
Kojto | 20:30b6ed7bf8fd | 227 | // Fill in HCI packet structure |
Kojto | 20:30b6ed7bf8fd | 228 | args = UINT32_TO_STREAM(args, encrypted_flag); |
Kojto | 20:30b6ed7bf8fd | 229 | ret = EFAIL; |
Kojto | 20:30b6ed7bf8fd | 230 | |
Kojto | 20:30b6ed7bf8fd | 231 | _hci.command_send(HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_START, ptr, WLAN_SMART_CONFIG_START_PARAMS_LEN); |
Kojto | 20:30b6ed7bf8fd | 232 | |
Kojto | 20:30b6ed7bf8fd | 233 | // Wait for command complete event |
Kojto | 20:30b6ed7bf8fd | 234 | _event.simplelink_wait_event(HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_START, &ret); |
Kojto | 20:30b6ed7bf8fd | 235 | |
Kojto | 45:50ab13d8f2dc | 236 | return ret; |
Kojto | 20:30b6ed7bf8fd | 237 | } |
Kojto | 20:30b6ed7bf8fd | 238 | |
Kojto | 20:30b6ed7bf8fd | 239 | |
Kojto | 20:30b6ed7bf8fd | 240 | int32_t cc3000_wlan::smart_config_stop(void) { |
Kojto | 20:30b6ed7bf8fd | 241 | int32_t ret; |
Kojto | 20:30b6ed7bf8fd | 242 | uint8_t *ptr; |
Kojto | 20:30b6ed7bf8fd | 243 | |
Kojto | 20:30b6ed7bf8fd | 244 | ret = EFAIL; |
Kojto | 20:30b6ed7bf8fd | 245 | ptr = _simple_link.get_transmit_buffer(); |
Kojto | 20:30b6ed7bf8fd | 246 | |
Kojto | 20:30b6ed7bf8fd | 247 | _hci.command_send(HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_STOP, ptr, 0); |
Kojto | 20:30b6ed7bf8fd | 248 | |
Kojto | 20:30b6ed7bf8fd | 249 | // Wait for command complete event |
Kojto | 20:30b6ed7bf8fd | 250 | _event.simplelink_wait_event(HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_STOP, &ret); |
Kojto | 20:30b6ed7bf8fd | 251 | |
Kojto | 45:50ab13d8f2dc | 252 | return ret; |
Kojto | 20:30b6ed7bf8fd | 253 | } |
Kojto | 20:30b6ed7bf8fd | 254 | |
Kojto | 20:30b6ed7bf8fd | 255 | int32_t cc3000_wlan::smart_config_set_prefix(uint8_t *new_prefix) { |
Kojto | 20:30b6ed7bf8fd | 256 | int32_t ret; |
Kojto | 20:30b6ed7bf8fd | 257 | uint8_t *ptr; |
Kojto | 20:30b6ed7bf8fd | 258 | uint8_t *args; |
Kojto | 20:30b6ed7bf8fd | 259 | |
Kojto | 20:30b6ed7bf8fd | 260 | ret = EFAIL; |
Kojto | 20:30b6ed7bf8fd | 261 | ptr = _simple_link.get_transmit_buffer(); |
Kojto | 20:30b6ed7bf8fd | 262 | args = (ptr + HEADERS_SIZE_CMD); |
Kojto | 20:30b6ed7bf8fd | 263 | |
Kojto | 45:50ab13d8f2dc | 264 | if (new_prefix == NULL) { |
Kojto | 20:30b6ed7bf8fd | 265 | return ret; |
Kojto | 45:50ab13d8f2dc | 266 | } else { |
Kojto | 45:50ab13d8f2dc | 267 | // with the new Smart Config, prefix must be TTT |
Kojto | 20:30b6ed7bf8fd | 268 | *new_prefix = 'T'; |
Kojto | 20:30b6ed7bf8fd | 269 | *(new_prefix + 1) = 'T'; |
Kojto | 20:30b6ed7bf8fd | 270 | *(new_prefix + 2) = 'T'; |
Kojto | 20:30b6ed7bf8fd | 271 | } |
Kojto | 20:30b6ed7bf8fd | 272 | |
Kojto | 20:30b6ed7bf8fd | 273 | ARRAY_TO_STREAM(args, new_prefix, SL_SIMPLE_CONFIG_PREFIX_LENGTH); |
Kojto | 20:30b6ed7bf8fd | 274 | |
Kojto | 20:30b6ed7bf8fd | 275 | _hci.command_send(HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_SET_PREFIX, ptr, SL_SIMPLE_CONFIG_PREFIX_LENGTH); |
Kojto | 20:30b6ed7bf8fd | 276 | |
Kojto | 20:30b6ed7bf8fd | 277 | // Wait for command complete event |
Kojto | 20:30b6ed7bf8fd | 278 | _event.simplelink_wait_event(HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_SET_PREFIX, &ret); |
Kojto | 20:30b6ed7bf8fd | 279 | |
Kojto | 45:50ab13d8f2dc | 280 | return ret; |
Kojto | 20:30b6ed7bf8fd | 281 | } |
Kojto | 20:30b6ed7bf8fd | 282 | |
Kojto | 20:30b6ed7bf8fd | 283 | #ifndef CC3000_TINY_DRIVER |
Kojto | 20:30b6ed7bf8fd | 284 | int32_t cc3000_wlan::connect(uint32_t sec_type, const uint8_t *ssid, int32_t ssid_len, uint8_t *bssid, |
Kojto | 20:30b6ed7bf8fd | 285 | uint8_t *key, int32_t key_len) { |
Kojto | 20:30b6ed7bf8fd | 286 | int32_t ret; |
Kojto | 20:30b6ed7bf8fd | 287 | uint8_t *ptr; |
Kojto | 20:30b6ed7bf8fd | 288 | uint8_t *args; |
Kojto | 20:30b6ed7bf8fd | 289 | uint8_t bssid_zero[] = {0, 0, 0, 0, 0, 0}; |
Kojto | 20:30b6ed7bf8fd | 290 | |
Kojto | 20:30b6ed7bf8fd | 291 | ret = EFAIL; |
Kojto | 20:30b6ed7bf8fd | 292 | ptr = _simple_link.get_transmit_buffer(); |
Kojto | 20:30b6ed7bf8fd | 293 | args = (ptr + HEADERS_SIZE_CMD); |
Kojto | 20:30b6ed7bf8fd | 294 | |
Kojto | 20:30b6ed7bf8fd | 295 | // Fill in command buffer |
Kojto | 20:30b6ed7bf8fd | 296 | args = UINT32_TO_STREAM(args, 0x0000001c); |
Kojto | 20:30b6ed7bf8fd | 297 | args = UINT32_TO_STREAM(args, ssid_len); |
Kojto | 20:30b6ed7bf8fd | 298 | args = UINT32_TO_STREAM(args, sec_type); |
Kojto | 20:30b6ed7bf8fd | 299 | args = UINT32_TO_STREAM(args, 0x00000010 + ssid_len); |
Kojto | 20:30b6ed7bf8fd | 300 | args = UINT32_TO_STREAM(args, key_len); |
Kojto | 20:30b6ed7bf8fd | 301 | args = UINT16_TO_STREAM(args, 0); |
Kojto | 20:30b6ed7bf8fd | 302 | |
Kojto | 20:30b6ed7bf8fd | 303 | // padding shall be zeroed |
Kojto | 45:50ab13d8f2dc | 304 | if (bssid) { |
Kojto | 20:30b6ed7bf8fd | 305 | ARRAY_TO_STREAM(args, bssid, ETH_ALEN); |
Kojto | 45:50ab13d8f2dc | 306 | } else { |
Kojto | 20:30b6ed7bf8fd | 307 | ARRAY_TO_STREAM(args, bssid_zero, ETH_ALEN); |
Kojto | 20:30b6ed7bf8fd | 308 | } |
Kojto | 20:30b6ed7bf8fd | 309 | |
Kojto | 20:30b6ed7bf8fd | 310 | ARRAY_TO_STREAM(args, ssid, ssid_len); |
Kojto | 20:30b6ed7bf8fd | 311 | |
Kojto | 45:50ab13d8f2dc | 312 | if (key_len && key) { |
Kojto | 20:30b6ed7bf8fd | 313 | ARRAY_TO_STREAM(args, key, key_len); |
Kojto | 20:30b6ed7bf8fd | 314 | } |
Kojto | 20:30b6ed7bf8fd | 315 | |
Kojto | 20:30b6ed7bf8fd | 316 | // Initiate a HCI command |
Kojto | 20:30b6ed7bf8fd | 317 | _hci.command_send(HCI_CMND_WLAN_CONNECT, ptr, WLAN_CONNECT_PARAM_LEN + ssid_len + key_len - 1); |
Kojto | 20:30b6ed7bf8fd | 318 | |
Kojto | 20:30b6ed7bf8fd | 319 | // Wait for command complete event |
Kojto | 20:30b6ed7bf8fd | 320 | _event.simplelink_wait_event(HCI_CMND_WLAN_CONNECT, &ret); |
Kojto | 20:30b6ed7bf8fd | 321 | errno = ret; |
Kojto | 20:30b6ed7bf8fd | 322 | |
Kojto | 45:50ab13d8f2dc | 323 | return ret; |
Kojto | 20:30b6ed7bf8fd | 324 | } |
Kojto | 20:30b6ed7bf8fd | 325 | |
Kojto | 20:30b6ed7bf8fd | 326 | int32_t cc3000_wlan::add_profile(uint32_t sec_type, |
Kojto | 20:30b6ed7bf8fd | 327 | uint8_t* ssid, |
Kojto | 20:30b6ed7bf8fd | 328 | uint32_t ssid_length, |
Kojto | 20:30b6ed7bf8fd | 329 | uint8_t *b_ssid, |
Kojto | 20:30b6ed7bf8fd | 330 | uint32_t priority, |
Kojto | 20:30b6ed7bf8fd | 331 | uint32_t pairwise_cipher_or_tx_key_len, |
Kojto | 20:30b6ed7bf8fd | 332 | uint32_t group_cipher_tx_key_index, |
Kojto | 20:30b6ed7bf8fd | 333 | uint32_t key_mgmt, |
Kojto | 20:30b6ed7bf8fd | 334 | uint8_t* pf_or_key, |
Kojto | 20:30b6ed7bf8fd | 335 | uint32_t pass_phrase_len) { |
Kojto | 20:30b6ed7bf8fd | 336 | uint16_t arg_len = 0x00; |
Kojto | 20:30b6ed7bf8fd | 337 | int32_t ret; |
Kojto | 20:30b6ed7bf8fd | 338 | uint8_t *ptr; |
Kojto | 20:30b6ed7bf8fd | 339 | int32_t i = 0; |
Kojto | 20:30b6ed7bf8fd | 340 | uint8_t *args; |
Kojto | 20:30b6ed7bf8fd | 341 | uint8_t bssid_zero[] = {0, 0, 0, 0, 0, 0}; |
Kojto | 20:30b6ed7bf8fd | 342 | |
Kojto | 20:30b6ed7bf8fd | 343 | ptr = _simple_link.get_transmit_buffer(); |
Kojto | 20:30b6ed7bf8fd | 344 | args = (ptr + HEADERS_SIZE_CMD); |
Kojto | 20:30b6ed7bf8fd | 345 | |
Kojto | 20:30b6ed7bf8fd | 346 | args = UINT32_TO_STREAM(args, sec_type); |
Kojto | 20:30b6ed7bf8fd | 347 | |
Kojto | 20:30b6ed7bf8fd | 348 | // Setup arguments in accordance with the security type |
Kojto | 20:30b6ed7bf8fd | 349 | switch (sec_type) |
Kojto | 20:30b6ed7bf8fd | 350 | { |
Kojto | 20:30b6ed7bf8fd | 351 | //OPEN |
Kojto | 45:50ab13d8f2dc | 352 | case WLAN_SEC_UNSEC: |
Kojto | 20:30b6ed7bf8fd | 353 | { |
Kojto | 20:30b6ed7bf8fd | 354 | args = UINT32_TO_STREAM(args, 0x00000014); |
Kojto | 20:30b6ed7bf8fd | 355 | args = UINT32_TO_STREAM(args, ssid_length); |
Kojto | 20:30b6ed7bf8fd | 356 | args = UINT16_TO_STREAM(args, 0); |
Kojto | 45:50ab13d8f2dc | 357 | if(b_ssid) { |
Kojto | 20:30b6ed7bf8fd | 358 | ARRAY_TO_STREAM(args, b_ssid, ETH_ALEN); |
Kojto | 45:50ab13d8f2dc | 359 | } else { |
Kojto | 20:30b6ed7bf8fd | 360 | ARRAY_TO_STREAM(args, bssid_zero, ETH_ALEN); |
Kojto | 20:30b6ed7bf8fd | 361 | } |
Kojto | 20:30b6ed7bf8fd | 362 | args = UINT32_TO_STREAM(args, priority); |
Kojto | 20:30b6ed7bf8fd | 363 | ARRAY_TO_STREAM(args, ssid, ssid_length); |
Kojto | 20:30b6ed7bf8fd | 364 | |
Kojto | 20:30b6ed7bf8fd | 365 | arg_len = WLAN_ADD_PROFILE_NOSEC_PARAM_LEN + ssid_length; |
Kojto | 20:30b6ed7bf8fd | 366 | } |
Kojto | 20:30b6ed7bf8fd | 367 | break; |
Kojto | 20:30b6ed7bf8fd | 368 | |
Kojto | 20:30b6ed7bf8fd | 369 | //WEP |
Kojto | 45:50ab13d8f2dc | 370 | case WLAN_SEC_WEP: |
Kojto | 20:30b6ed7bf8fd | 371 | { |
Kojto | 20:30b6ed7bf8fd | 372 | args = UINT32_TO_STREAM(args, 0x00000020); |
Kojto | 20:30b6ed7bf8fd | 373 | args = UINT32_TO_STREAM(args, ssid_length); |
Kojto | 20:30b6ed7bf8fd | 374 | args = UINT16_TO_STREAM(args, 0); |
Kojto | 45:50ab13d8f2dc | 375 | if (b_ssid) { |
Kojto | 20:30b6ed7bf8fd | 376 | ARRAY_TO_STREAM(args, b_ssid, ETH_ALEN); |
Kojto | 45:50ab13d8f2dc | 377 | } else { |
Kojto | 20:30b6ed7bf8fd | 378 | ARRAY_TO_STREAM(args, bssid_zero, ETH_ALEN); |
Kojto | 20:30b6ed7bf8fd | 379 | } |
Kojto | 20:30b6ed7bf8fd | 380 | args = UINT32_TO_STREAM(args, priority); |
Kojto | 20:30b6ed7bf8fd | 381 | args = UINT32_TO_STREAM(args, 0x0000000C + ssid_length); |
Kojto | 20:30b6ed7bf8fd | 382 | args = UINT32_TO_STREAM(args, pairwise_cipher_or_tx_key_len); |
Kojto | 20:30b6ed7bf8fd | 383 | args = UINT32_TO_STREAM(args, group_cipher_tx_key_index); |
Kojto | 20:30b6ed7bf8fd | 384 | ARRAY_TO_STREAM(args, ssid, ssid_length); |
Kojto | 20:30b6ed7bf8fd | 385 | |
Kojto | 45:50ab13d8f2dc | 386 | for(i = 0; i < 4; i++) { |
Kojto | 20:30b6ed7bf8fd | 387 | uint8_t *p = &pf_or_key[i * pairwise_cipher_or_tx_key_len]; |
Kojto | 20:30b6ed7bf8fd | 388 | |
Kojto | 20:30b6ed7bf8fd | 389 | ARRAY_TO_STREAM(args, p, pairwise_cipher_or_tx_key_len); |
Kojto | 20:30b6ed7bf8fd | 390 | } |
Kojto | 20:30b6ed7bf8fd | 391 | |
Kojto | 20:30b6ed7bf8fd | 392 | arg_len = WLAN_ADD_PROFILE_WEP_PARAM_LEN + ssid_length + |
Kojto | 20:30b6ed7bf8fd | 393 | pairwise_cipher_or_tx_key_len * 4; |
Kojto | 20:30b6ed7bf8fd | 394 | |
Kojto | 20:30b6ed7bf8fd | 395 | } |
Kojto | 20:30b6ed7bf8fd | 396 | break; |
Kojto | 20:30b6ed7bf8fd | 397 | |
Kojto | 20:30b6ed7bf8fd | 398 | //WPA |
Kojto | 20:30b6ed7bf8fd | 399 | //WPA2 |
Kojto | 45:50ab13d8f2dc | 400 | case WLAN_SEC_WPA: |
Kojto | 45:50ab13d8f2dc | 401 | case WLAN_SEC_WPA2: |
Kojto | 20:30b6ed7bf8fd | 402 | { |
Kojto | 20:30b6ed7bf8fd | 403 | args = UINT32_TO_STREAM(args, 0x00000028); |
Kojto | 20:30b6ed7bf8fd | 404 | args = UINT32_TO_STREAM(args, ssid_length); |
Kojto | 20:30b6ed7bf8fd | 405 | args = UINT16_TO_STREAM(args, 0); |
Kojto | 45:50ab13d8f2dc | 406 | if (b_ssid) { |
Kojto | 20:30b6ed7bf8fd | 407 | ARRAY_TO_STREAM(args, b_ssid, ETH_ALEN); |
Kojto | 45:50ab13d8f2dc | 408 | } else { |
Kojto | 20:30b6ed7bf8fd | 409 | ARRAY_TO_STREAM(args, bssid_zero, ETH_ALEN); |
Kojto | 20:30b6ed7bf8fd | 410 | } |
Kojto | 20:30b6ed7bf8fd | 411 | args = UINT32_TO_STREAM(args, priority); |
Kojto | 20:30b6ed7bf8fd | 412 | args = UINT32_TO_STREAM(args, pairwise_cipher_or_tx_key_len); |
Kojto | 20:30b6ed7bf8fd | 413 | args = UINT32_TO_STREAM(args, group_cipher_tx_key_index); |
Kojto | 20:30b6ed7bf8fd | 414 | args = UINT32_TO_STREAM(args, key_mgmt); |
Kojto | 20:30b6ed7bf8fd | 415 | args = UINT32_TO_STREAM(args, 0x00000008 + ssid_length); |
Kojto | 20:30b6ed7bf8fd | 416 | args = UINT32_TO_STREAM(args, pass_phrase_len); |
Kojto | 20:30b6ed7bf8fd | 417 | ARRAY_TO_STREAM(args, ssid, ssid_length); |
Kojto | 20:30b6ed7bf8fd | 418 | ARRAY_TO_STREAM(args, pf_or_key, pass_phrase_len); |
Kojto | 20:30b6ed7bf8fd | 419 | |
Kojto | 20:30b6ed7bf8fd | 420 | arg_len = WLAN_ADD_PROFILE_WPA_PARAM_LEN + ssid_length + pass_phrase_len; |
Kojto | 20:30b6ed7bf8fd | 421 | } |
Kojto | 20:30b6ed7bf8fd | 422 | |
Kojto | 20:30b6ed7bf8fd | 423 | break; |
Kojto | 20:30b6ed7bf8fd | 424 | } |
Kojto | 20:30b6ed7bf8fd | 425 | |
Kojto | 20:30b6ed7bf8fd | 426 | // Initiate a HCI command |
Kojto | 20:30b6ed7bf8fd | 427 | _hci.command_send(HCI_CMND_WLAN_IOCTL_ADD_PROFILE, ptr, arg_len); |
Kojto | 20:30b6ed7bf8fd | 428 | |
Kojto | 20:30b6ed7bf8fd | 429 | // Wait for command complete event |
Kojto | 20:30b6ed7bf8fd | 430 | _event.simplelink_wait_event(HCI_CMND_WLAN_IOCTL_ADD_PROFILE, &ret); |
Kojto | 20:30b6ed7bf8fd | 431 | |
Kojto | 45:50ab13d8f2dc | 432 | return ret; |
Kojto | 20:30b6ed7bf8fd | 433 | } |
Kojto | 20:30b6ed7bf8fd | 434 | |
Kojto | 20:30b6ed7bf8fd | 435 | int32_t cc3000_wlan::ioctl_get_scan_results(uint32_t scan_timeout, uint8_t *results) { |
Kojto | 20:30b6ed7bf8fd | 436 | uint8_t *ptr; |
Kojto | 20:30b6ed7bf8fd | 437 | uint8_t *args; |
Kojto | 20:30b6ed7bf8fd | 438 | |
Kojto | 20:30b6ed7bf8fd | 439 | ptr = _simple_link.get_transmit_buffer(); |
Kojto | 20:30b6ed7bf8fd | 440 | args = (ptr + HEADERS_SIZE_CMD); |
Kojto | 20:30b6ed7bf8fd | 441 | |
Kojto | 20:30b6ed7bf8fd | 442 | // Fill in temporary command buffer |
Kojto | 20:30b6ed7bf8fd | 443 | args = UINT32_TO_STREAM(args, scan_timeout); |
Kojto | 20:30b6ed7bf8fd | 444 | |
Kojto | 20:30b6ed7bf8fd | 445 | // Initiate a HCI command |
Kojto | 20:30b6ed7bf8fd | 446 | _hci.command_send(HCI_CMND_WLAN_IOCTL_GET_SCAN_RESULTS, ptr, WLAN_GET_SCAN_RESULTS_PARAMS_LEN); |
Kojto | 20:30b6ed7bf8fd | 447 | |
Kojto | 20:30b6ed7bf8fd | 448 | // Wait for command complete event |
Kojto | 20:30b6ed7bf8fd | 449 | _event.simplelink_wait_event(HCI_CMND_WLAN_IOCTL_GET_SCAN_RESULTS, results); |
Kojto | 20:30b6ed7bf8fd | 450 | |
Kojto | 45:50ab13d8f2dc | 451 | return 0; |
Kojto | 20:30b6ed7bf8fd | 452 | } |
Kojto | 20:30b6ed7bf8fd | 453 | |
Kojto | 20:30b6ed7bf8fd | 454 | int32_t cc3000_wlan::ioctl_set_scan_params(uint32_t enable, |
Kojto | 20:30b6ed7bf8fd | 455 | uint32_t min_dwell_time, |
Kojto | 20:30b6ed7bf8fd | 456 | uint32_t max_dwell_time, |
Kojto | 20:30b6ed7bf8fd | 457 | uint32_t num_probe_requests, |
Kojto | 20:30b6ed7bf8fd | 458 | uint32_t channel_mask, |
Kojto | 20:30b6ed7bf8fd | 459 | int32_t rssi_threshold, |
Kojto | 20:30b6ed7bf8fd | 460 | uint32_t snr_threshold, |
Kojto | 20:30b6ed7bf8fd | 461 | uint32_t default_tx_power, |
Kojto | 20:30b6ed7bf8fd | 462 | uint32_t *interval_list) { |
Kojto | 20:30b6ed7bf8fd | 463 | uint32_t uiRes; |
Kojto | 20:30b6ed7bf8fd | 464 | uint8_t *ptr; |
Kojto | 20:30b6ed7bf8fd | 465 | uint8_t *args; |
Kojto | 20:30b6ed7bf8fd | 466 | |
Kojto | 20:30b6ed7bf8fd | 467 | ptr = _simple_link.get_transmit_buffer(); |
Kojto | 20:30b6ed7bf8fd | 468 | args = (ptr + HEADERS_SIZE_CMD); |
Kojto | 20:30b6ed7bf8fd | 469 | |
Kojto | 20:30b6ed7bf8fd | 470 | // Fill in temporary command buffer |
Kojto | 20:30b6ed7bf8fd | 471 | args = UINT32_TO_STREAM(args, 36); |
Kojto | 20:30b6ed7bf8fd | 472 | args = UINT32_TO_STREAM(args, enable); |
Kojto | 20:30b6ed7bf8fd | 473 | args = UINT32_TO_STREAM(args, min_dwell_time); |
Kojto | 20:30b6ed7bf8fd | 474 | args = UINT32_TO_STREAM(args, max_dwell_time); |
Kojto | 20:30b6ed7bf8fd | 475 | args = UINT32_TO_STREAM(args, num_probe_requests); |
Kojto | 20:30b6ed7bf8fd | 476 | args = UINT32_TO_STREAM(args, channel_mask); |
Kojto | 20:30b6ed7bf8fd | 477 | args = UINT32_TO_STREAM(args, rssi_threshold); |
Kojto | 20:30b6ed7bf8fd | 478 | args = UINT32_TO_STREAM(args, snr_threshold); |
Kojto | 20:30b6ed7bf8fd | 479 | args = UINT32_TO_STREAM(args, default_tx_power); |
Kojto | 20:30b6ed7bf8fd | 480 | ARRAY_TO_STREAM(args, interval_list, sizeof(uint32_t) * SL_SET_SCAN_PARAMS_INTERVAL_LIST_SIZE); |
Kojto | 20:30b6ed7bf8fd | 481 | |
Kojto | 20:30b6ed7bf8fd | 482 | // Initiate a HCI command |
Kojto | 20:30b6ed7bf8fd | 483 | _hci.command_send(HCI_CMND_WLAN_IOCTL_SET_SCANPARAM, ptr, WLAN_SET_SCAN_PARAMS_LEN); |
Kojto | 20:30b6ed7bf8fd | 484 | |
Kojto | 20:30b6ed7bf8fd | 485 | // Wait for command complete event |
Kojto | 20:30b6ed7bf8fd | 486 | _event.simplelink_wait_event(HCI_CMND_WLAN_IOCTL_SET_SCANPARAM, &uiRes); |
Kojto | 20:30b6ed7bf8fd | 487 | |
Kojto | 20:30b6ed7bf8fd | 488 | return(uiRes); |
Kojto | 20:30b6ed7bf8fd | 489 | } |
Kojto | 20:30b6ed7bf8fd | 490 | |
Kojto | 20:30b6ed7bf8fd | 491 | int32_t cc3000_wlan::ioctl_statusget(void) { |
Kojto | 20:30b6ed7bf8fd | 492 | int32_t ret; |
Kojto | 20:30b6ed7bf8fd | 493 | uint8_t *ptr; |
Kojto | 20:30b6ed7bf8fd | 494 | |
Kojto | 20:30b6ed7bf8fd | 495 | ret = EFAIL; |
Kojto | 20:30b6ed7bf8fd | 496 | ptr = _simple_link.get_transmit_buffer(); |
Kojto | 20:30b6ed7bf8fd | 497 | |
Kojto | 20:30b6ed7bf8fd | 498 | _hci.command_send(HCI_CMND_WLAN_IOCTL_STATUSGET,ptr, 0); |
Kojto | 20:30b6ed7bf8fd | 499 | |
Kojto | 20:30b6ed7bf8fd | 500 | // Wait for command complete event |
Kojto | 20:30b6ed7bf8fd | 501 | _event.simplelink_wait_event(HCI_CMND_WLAN_IOCTL_STATUSGET, &ret); |
Kojto | 20:30b6ed7bf8fd | 502 | |
Kojto | 45:50ab13d8f2dc | 503 | return ret; |
Kojto | 20:30b6ed7bf8fd | 504 | } |
Kojto | 20:30b6ed7bf8fd | 505 | |
Kojto | 20:30b6ed7bf8fd | 506 | #else |
Kojto | 45:50ab13d8f2dc | 507 | int32_t cc3000_wlan::add_profile(uint32_t sec_type, |
Kojto | 20:30b6ed7bf8fd | 508 | uint8_t *ssid, |
Kojto | 20:30b6ed7bf8fd | 509 | uint32_t ssid_length, |
Kojto | 20:30b6ed7bf8fd | 510 | uint8_t *b_ssid, |
Kojto | 20:30b6ed7bf8fd | 511 | uint32_t priority, |
Kojto | 20:30b6ed7bf8fd | 512 | uint32_t pairwise_cipher_or_tx_key_len, |
Kojto | 20:30b6ed7bf8fd | 513 | uint32_t group_cipher_tx_key_index, |
Kojto | 20:30b6ed7bf8fd | 514 | uint32_t key_mgmt, |
Kojto | 20:30b6ed7bf8fd | 515 | uint8_t* pf_or_key, |
Kojto | 20:30b6ed7bf8fd | 516 | uint32_t pass_phrase_length) |
Kojto | 20:30b6ed7bf8fd | 517 | { |
Kojto | 20:30b6ed7bf8fd | 518 | return -1; |
Kojto | 20:30b6ed7bf8fd | 519 | } |
Kojto | 20:30b6ed7bf8fd | 520 | |
Kojto | 20:30b6ed7bf8fd | 521 | int32_t cc3000_wlan::connect(const uint8_t *ssid, int32_t ssid_len) { |
Kojto | 20:30b6ed7bf8fd | 522 | int32_t ret; |
Kojto | 20:30b6ed7bf8fd | 523 | uint8_t *ptr; |
Kojto | 20:30b6ed7bf8fd | 524 | uint8_t *args; |
Kojto | 20:30b6ed7bf8fd | 525 | uint8_t bssid_zero[] = {0, 0, 0, 0, 0, 0}; |
Kojto | 20:30b6ed7bf8fd | 526 | |
Kojto | 20:30b6ed7bf8fd | 527 | ret = EFAIL; |
Kojto | 20:30b6ed7bf8fd | 528 | ptr = _simple_link.get_transmit_buffer(); |
Kojto | 20:30b6ed7bf8fd | 529 | args = (ptr + HEADERS_SIZE_CMD); |
Kojto | 20:30b6ed7bf8fd | 530 | |
Kojto | 20:30b6ed7bf8fd | 531 | // Fill in command buffer |
Kojto | 20:30b6ed7bf8fd | 532 | args = UINT32_TO_STREAM(args, 0x0000001c); |
Kojto | 20:30b6ed7bf8fd | 533 | args = UINT32_TO_STREAM(args, ssid_len); |
Kojto | 20:30b6ed7bf8fd | 534 | args = UINT32_TO_STREAM(args, 0); |
Kojto | 20:30b6ed7bf8fd | 535 | args = UINT32_TO_STREAM(args, 0x00000010 + ssid_len); |
Kojto | 20:30b6ed7bf8fd | 536 | args = UINT32_TO_STREAM(args, 0); |
Kojto | 20:30b6ed7bf8fd | 537 | args = UINT16_TO_STREAM(args, 0); |
Kojto | 20:30b6ed7bf8fd | 538 | |
Kojto | 20:30b6ed7bf8fd | 539 | // padding shall be zeroed |
Kojto | 20:30b6ed7bf8fd | 540 | ARRAY_TO_STREAM(args, bssid_zero, ETH_ALEN); |
Kojto | 20:30b6ed7bf8fd | 541 | ARRAY_TO_STREAM(args, ssid, ssid_len); |
Kojto | 20:30b6ed7bf8fd | 542 | |
Kojto | 20:30b6ed7bf8fd | 543 | // Initiate a HCI command |
Kojto | 20:30b6ed7bf8fd | 544 | _hci.command_send(HCI_CMND_WLAN_CONNECT, ptr, WLAN_CONNECT_PARAM_LEN + ssid_len - 1); |
Kojto | 20:30b6ed7bf8fd | 545 | |
Kojto | 20:30b6ed7bf8fd | 546 | // Wait for command complete event |
Kojto | 20:30b6ed7bf8fd | 547 | _event.simplelink_wait_event(HCI_CMND_WLAN_CONNECT, &ret); |
Kojto | 20:30b6ed7bf8fd | 548 | errno = ret; |
Kojto | 20:30b6ed7bf8fd | 549 | |
Kojto | 45:50ab13d8f2dc | 550 | return ret; |
Kojto | 20:30b6ed7bf8fd | 551 | } |
Kojto | 20:30b6ed7bf8fd | 552 | #endif |
Kojto | 20:30b6ed7bf8fd | 553 | |
Kojto | 20:30b6ed7bf8fd | 554 | |
Kojto | 20:30b6ed7bf8fd | 555 | |
Kojto | 20:30b6ed7bf8fd | 556 | #ifndef CC3000_UNENCRYPTED_SMART_CONFIG |
Kojto | 20:30b6ed7bf8fd | 557 | int32_t cc3000_wlan::smart_config_process(void) { |
Kojto | 20:30b6ed7bf8fd | 558 | int32_t returnValue; |
Kojto | 20:30b6ed7bf8fd | 559 | uint32_t ssidLen, keyLen; |
Kojto | 20:30b6ed7bf8fd | 560 | uint8_t *decKeyPtr; |
Kojto | 20:30b6ed7bf8fd | 561 | uint8_t *ssidPtr; |
Kojto | 20:30b6ed7bf8fd | 562 | |
Kojto | 20:30b6ed7bf8fd | 563 | // read the key from EEPROM - fileID 12 |
Kojto | 20:30b6ed7bf8fd | 564 | returnValue = aes_read_key(key); |
Kojto | 20:30b6ed7bf8fd | 565 | |
Kojto | 20:30b6ed7bf8fd | 566 | if (returnValue != 0) |
Kojto | 20:30b6ed7bf8fd | 567 | return returnValue; |
Kojto | 20:30b6ed7bf8fd | 568 | |
Kojto | 20:30b6ed7bf8fd | 569 | // read the received data from fileID #13 and parse it according to the followings: |
Kojto | 20:30b6ed7bf8fd | 570 | // 1) SSID LEN - not encrypted |
Kojto | 20:30b6ed7bf8fd | 571 | // 2) SSID - not encrypted |
Kojto | 20:30b6ed7bf8fd | 572 | // 3) KEY LEN - not encrypted. always 32 bytes long |
Kojto | 20:30b6ed7bf8fd | 573 | // 4) Security type - not encrypted |
Kojto | 20:30b6ed7bf8fd | 574 | // 5) KEY - encrypted together with true key length as the first byte in KEY |
Kojto | 20:30b6ed7bf8fd | 575 | // to elaborate, there are two corner cases: |
Kojto | 20:30b6ed7bf8fd | 576 | // 1) the KEY is 32 bytes long. In this case, the first byte does not represent KEY length |
Kojto | 20:30b6ed7bf8fd | 577 | // 2) the KEY is 31 bytes long. In this case, the first byte represent KEY length and equals 31 |
Kojto | 20:30b6ed7bf8fd | 578 | returnValue = nvmem_read(NVMEM_SHARED_MEM_FILEID, SMART_CONFIG_PROFILE_SIZE, 0, profileArray); |
Kojto | 20:30b6ed7bf8fd | 579 | |
Kojto | 20:30b6ed7bf8fd | 580 | if (returnValue != 0) |
Kojto | 20:30b6ed7bf8fd | 581 | return returnValue; |
Kojto | 20:30b6ed7bf8fd | 582 | |
Kojto | 20:30b6ed7bf8fd | 583 | ssidPtr = &profileArray[1]; |
Kojto | 20:30b6ed7bf8fd | 584 | |
Kojto | 20:30b6ed7bf8fd | 585 | ssidLen = profileArray[0]; |
Kojto | 20:30b6ed7bf8fd | 586 | |
Kojto | 20:30b6ed7bf8fd | 587 | decKeyPtr = &profileArray[profileArray[0] + 3]; |
Kojto | 20:30b6ed7bf8fd | 588 | |
Kojto | 20:30b6ed7bf8fd | 589 | aes_decrypt(decKeyPtr, key); |
Kojto | 20:30b6ed7bf8fd | 590 | if (profileArray[profileArray[0] + 1] > 16) |
Kojto | 20:30b6ed7bf8fd | 591 | aes_decrypt((uint8_t *)(decKeyPtr + 16), key); |
Kojto | 20:30b6ed7bf8fd | 592 | |
Kojto | 45:50ab13d8f2dc | 593 | if (*(uint8_t *)(decKeyPtr +31) != 0) { |
Kojto | 45:50ab13d8f2dc | 594 | if (*decKeyPtr == 31) { |
Kojto | 20:30b6ed7bf8fd | 595 | keyLen = 31; |
Kojto | 20:30b6ed7bf8fd | 596 | decKeyPtr++; |
Kojto | 45:50ab13d8f2dc | 597 | } else { |
Kojto | 20:30b6ed7bf8fd | 598 | keyLen = 32; |
Kojto | 20:30b6ed7bf8fd | 599 | } |
Kojto | 45:50ab13d8f2dc | 600 | } else { |
Kojto | 20:30b6ed7bf8fd | 601 | keyLen = *decKeyPtr; |
Kojto | 20:30b6ed7bf8fd | 602 | decKeyPtr++; |
Kojto | 20:30b6ed7bf8fd | 603 | } |
Kojto | 20:30b6ed7bf8fd | 604 | |
Kojto | 20:30b6ed7bf8fd | 605 | // add a profile |
Kojto | 20:30b6ed7bf8fd | 606 | switch (profileArray[profileArray[0] + 2]) |
Kojto | 20:30b6ed7bf8fd | 607 | { |
Kojto | 20:30b6ed7bf8fd | 608 | case WLAN_SEC_UNSEC://None |
Kojto | 20:30b6ed7bf8fd | 609 | { |
Kojto | 20:30b6ed7bf8fd | 610 | returnValue = wlan_add_profile(profileArray[profileArray[0] + 2], // security type |
Kojto | 20:30b6ed7bf8fd | 611 | ssidPtr, // SSID |
Kojto | 20:30b6ed7bf8fd | 612 | ssidLen, // SSID length |
Kojto | 20:30b6ed7bf8fd | 613 | NULL, // BSSID |
Kojto | 20:30b6ed7bf8fd | 614 | 1, // Priority |
Kojto | 20:30b6ed7bf8fd | 615 | 0, 0, 0, 0, 0); |
Kojto | 20:30b6ed7bf8fd | 616 | |
Kojto | 20:30b6ed7bf8fd | 617 | break; |
Kojto | 20:30b6ed7bf8fd | 618 | } |
Kojto | 20:30b6ed7bf8fd | 619 | |
Kojto | 20:30b6ed7bf8fd | 620 | case WLAN_SEC_WEP://WEP |
Kojto | 20:30b6ed7bf8fd | 621 | { |
Kojto | 20:30b6ed7bf8fd | 622 | returnValue = wlan_add_profile(profileArray[profileArray[0] + 2], // security type |
Kojto | 20:30b6ed7bf8fd | 623 | ssidPtr, // SSID |
Kojto | 20:30b6ed7bf8fd | 624 | ssidLen, // SSID length |
Kojto | 20:30b6ed7bf8fd | 625 | NULL, // BSSID |
Kojto | 20:30b6ed7bf8fd | 626 | 1, // Priority |
Kojto | 20:30b6ed7bf8fd | 627 | keyLen, // KEY length |
Kojto | 20:30b6ed7bf8fd | 628 | 0, // KEY index |
Kojto | 20:30b6ed7bf8fd | 629 | 0, |
Kojto | 20:30b6ed7bf8fd | 630 | decKeyPtr, // KEY |
Kojto | 20:30b6ed7bf8fd | 631 | 0); |
Kojto | 20:30b6ed7bf8fd | 632 | |
Kojto | 20:30b6ed7bf8fd | 633 | break; |
Kojto | 20:30b6ed7bf8fd | 634 | } |
Kojto | 20:30b6ed7bf8fd | 635 | |
Kojto | 20:30b6ed7bf8fd | 636 | case WLAN_SEC_WPA: //WPA |
Kojto | 20:30b6ed7bf8fd | 637 | case WLAN_SEC_WPA2: //WPA2 |
Kojto | 20:30b6ed7bf8fd | 638 | { |
Kojto | 20:30b6ed7bf8fd | 639 | returnValue = wlan_add_profile(WLAN_SEC_WPA2, // security type |
Kojto | 20:30b6ed7bf8fd | 640 | ssidPtr, |
Kojto | 20:30b6ed7bf8fd | 641 | ssidLen, |
Kojto | 20:30b6ed7bf8fd | 642 | NULL, // BSSID |
Kojto | 20:30b6ed7bf8fd | 643 | 1, // Priority |
Kojto | 20:30b6ed7bf8fd | 644 | 0x18, // PairwiseCipher |
Kojto | 20:30b6ed7bf8fd | 645 | 0x1e, // GroupCipher |
Kojto | 20:30b6ed7bf8fd | 646 | 2, // KEY management |
Kojto | 20:30b6ed7bf8fd | 647 | decKeyPtr, // KEY |
Kojto | 20:30b6ed7bf8fd | 648 | keyLen); // KEY length |
Kojto | 20:30b6ed7bf8fd | 649 | |
Kojto | 20:30b6ed7bf8fd | 650 | break; |
Kojto | 20:30b6ed7bf8fd | 651 | } |
Kojto | 20:30b6ed7bf8fd | 652 | } |
Kojto | 20:30b6ed7bf8fd | 653 | |
Kojto | 20:30b6ed7bf8fd | 654 | return returnValue; |
Kojto | 20:30b6ed7bf8fd | 655 | } |
Kojto | 20:30b6ed7bf8fd | 656 | #endif |
Kojto | 20:30b6ed7bf8fd | 657 | |
Kojto | 20:30b6ed7bf8fd | 658 | } |