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