Martin Kojtal / cc3000_hostdriver_mbedsocket Featured

Dependents:   cc3000_hello_world_demo cc3000_simple_socket_demo cc3000_ntp_demo cc3000_ping_demo ... more

Committer:
SolderSplashLabs
Date:
Wed Oct 02 21:57:28 2013 +0000
Revision:
18:7e22775eadb9
Parent:
0:615c697c33b0
Child:
20:30b6ed7bf8fd
Websocket demo showed that if gethostbyname failed and returned 0.0.0.0 it still went ahead. Added checking to the gethostbyname call in Endpoint.cpp

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Kojto 0:615c697c33b0 1 /*****************************************************************************
Kojto 0:615c697c33b0 2 *
Kojto 0:615c697c33b0 3 * C++ interface/implementation created by Martin Kojtal (0xc0170). Thanks to
Kojto 0:615c697c33b0 4 * Jim Carver and Frank Vannieuwkerke for their inital cc3000 mbed port and
Kojto 0:615c697c33b0 5 * provided help.
Kojto 0:615c697c33b0 6 *
Kojto 0:615c697c33b0 7 * This version of "host driver" uses CC3000 Host Driver Implementation. Thus
Kojto 0:615c697c33b0 8 * read the following copyright:
Kojto 0:615c697c33b0 9 *
Kojto 0:615c697c33b0 10 * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
Kojto 0:615c697c33b0 11 *
Kojto 0:615c697c33b0 12 * Redistribution and use in source and binary forms, with or without
Kojto 0:615c697c33b0 13 * modification, are permitted provided that the following conditions
Kojto 0:615c697c33b0 14 * are met:
Kojto 0:615c697c33b0 15 *
Kojto 0:615c697c33b0 16 * Redistributions of source code must retain the above copyright
Kojto 0:615c697c33b0 17 * notice, this list of conditions and the following disclaimer.
Kojto 0:615c697c33b0 18 *
Kojto 0:615c697c33b0 19 * Redistributions in binary form must reproduce the above copyright
Kojto 0:615c697c33b0 20 * notice, this list of conditions and the following disclaimer in the
Kojto 0:615c697c33b0 21 * documentation and/or other materials provided with the
Kojto 0:615c697c33b0 22 * distribution.
Kojto 0:615c697c33b0 23 *
Kojto 0:615c697c33b0 24 * Neither the name of Texas Instruments Incorporated nor the names of
Kojto 0:615c697c33b0 25 * its contributors may be used to endorse or promote products derived
Kojto 0:615c697c33b0 26 * from this software without specific prior written permission.
Kojto 0:615c697c33b0 27 *
Kojto 0:615c697c33b0 28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Kojto 0:615c697c33b0 29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Kojto 0:615c697c33b0 30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
Kojto 0:615c697c33b0 31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
Kojto 0:615c697c33b0 32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
Kojto 0:615c697c33b0 33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
Kojto 0:615c697c33b0 34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
Kojto 0:615c697c33b0 35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
Kojto 0:615c697c33b0 36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Kojto 0:615c697c33b0 37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Kojto 0:615c697c33b0 38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Kojto 0:615c697c33b0 39 *
Kojto 0:615c697c33b0 40 *****************************************************************************/
Kojto 0:615c697c33b0 41 #include "cc3000.h"
Kojto 0:615c697c33b0 42
Kojto 0:615c697c33b0 43 namespace mbed_cc3000 {
Kojto 0:615c697c33b0 44
Kojto 0:615c697c33b0 45 cc3000_wlan::cc3000_wlan(cc3000_simple_link &simple_link, cc3000_event &event, cc3000_spi &spi, cc3000_hci &hci) :
Kojto 0:615c697c33b0 46 _simple_link(simple_link), _event(event), _spi(spi), _hci(hci) {
Kojto 0:615c697c33b0 47
Kojto 0:615c697c33b0 48 }
Kojto 0:615c697c33b0 49
Kojto 0:615c697c33b0 50 cc3000_wlan::~cc3000_wlan() {
Kojto 0:615c697c33b0 51
Kojto 0:615c697c33b0 52 }
Kojto 0:615c697c33b0 53
Kojto 0:615c697c33b0 54 void cc3000_wlan::simpleLink_init_start(uint16_t patches_available_host) {
Kojto 0:615c697c33b0 55 uint8_t *ptr;
Kojto 0:615c697c33b0 56 uint8_t *args;
Kojto 0:615c697c33b0 57
Kojto 0:615c697c33b0 58 ptr = _simple_link.get_transmit_buffer();
Kojto 0:615c697c33b0 59 args = (uint8_t *)(ptr + HEADERS_SIZE_CMD);
Kojto 0:615c697c33b0 60
Kojto 0:615c697c33b0 61 UINT8_TO_STREAM(args, ((patches_available_host) ? SL_PATCHES_REQUEST_FORCE_HOST : SL_PATCHES_REQUEST_DEFAULT));
Kojto 0:615c697c33b0 62
Kojto 0:615c697c33b0 63 // IRQ Line asserted - send HCI_CMND_SIMPLE_LINK_START to CC3000
Kojto 0:615c697c33b0 64 _hci.command_send(HCI_CMND_SIMPLE_LINK_START, ptr, WLAN_SL_INIT_START_PARAMS_LEN);
Kojto 0:615c697c33b0 65 _event.simplelink_wait_event(HCI_CMND_SIMPLE_LINK_START, 0);
Kojto 0:615c697c33b0 66 }
Kojto 0:615c697c33b0 67
Kojto 0:615c697c33b0 68 void cc3000_wlan::start(uint16_t patches_available_host) {
Kojto 0:615c697c33b0 69 uint32_t spi_irq_state;
Kojto 0:615c697c33b0 70
Kojto 0:615c697c33b0 71 _simple_link.set_sent_packets(0);
Kojto 0:615c697c33b0 72 _simple_link.set_number_of_released_packets(0);
Kojto 0:615c697c33b0 73 _simple_link.set_op_code(0);
Kojto 0:615c697c33b0 74 _simple_link.set_number_free_buffers(0);
Kojto 0:615c697c33b0 75 _simple_link.set_buffer_length(0);
Kojto 0:615c697c33b0 76 _simple_link.set_buffer_size(0);
Kojto 0:615c697c33b0 77 _simple_link.set_pending_data(0);
Kojto 0:615c697c33b0 78 _simple_link.set_transmit_error(0);
Kojto 0:615c697c33b0 79 _simple_link.set_data_received_flag(0);
Kojto 0:615c697c33b0 80 _simple_link.set_buffer_size(0);
Kojto 0:615c697c33b0 81
Kojto 0:615c697c33b0 82 // init spi
Kojto 0:615c697c33b0 83 _spi.open();
Kojto 0:615c697c33b0 84 // Check the IRQ line
Kojto 0:615c697c33b0 85 spi_irq_state = _spi.wlan_irq_read();
Kojto 0:615c697c33b0 86 // ASIC 1273 chip enable: toggle WLAN EN line
Kojto 0:615c697c33b0 87 _spi.write_wlan_en(WLAN_ENABLE);
Kojto 0:615c697c33b0 88
Kojto 0:615c697c33b0 89 if (spi_irq_state)
Kojto 0:615c697c33b0 90 {
Kojto 0:615c697c33b0 91 // wait till the IRQ line goes low
Kojto 0:615c697c33b0 92 while(_spi.wlan_irq_read() != 0)
Kojto 0:615c697c33b0 93 {
Kojto 0:615c697c33b0 94 }
Kojto 0:615c697c33b0 95 }
Kojto 0:615c697c33b0 96 else
Kojto 0:615c697c33b0 97 {
Kojto 0:615c697c33b0 98 // wait till the IRQ line goes high and then low
Kojto 0:615c697c33b0 99 while(_spi.wlan_irq_read() == 0)
Kojto 0:615c697c33b0 100 {
Kojto 0:615c697c33b0 101 }
Kojto 0:615c697c33b0 102 while(_spi.wlan_irq_read() != 0)
Kojto 0:615c697c33b0 103 {
Kojto 0:615c697c33b0 104 }
Kojto 0:615c697c33b0 105 }
Kojto 0:615c697c33b0 106 simpleLink_init_start(patches_available_host);
Kojto 0:615c697c33b0 107
Kojto 0:615c697c33b0 108 // Read Buffer's size and finish
Kojto 0:615c697c33b0 109 _hci.command_send(HCI_CMND_READ_BUFFER_SIZE, _simple_link.get_transmit_buffer(), 0);
Kojto 0:615c697c33b0 110 _event.simplelink_wait_event(HCI_CMND_READ_BUFFER_SIZE, 0);
Kojto 0:615c697c33b0 111 }
Kojto 0:615c697c33b0 112
Kojto 0:615c697c33b0 113
Kojto 0:615c697c33b0 114 void cc3000_wlan::stop() {
Kojto 0:615c697c33b0 115 // ASIC 1273 chip disable
Kojto 0:615c697c33b0 116 _spi.write_wlan_en( WLAN_DISABLE );
Kojto 0:615c697c33b0 117
Kojto 0:615c697c33b0 118 // Wait till IRQ line goes high...
Kojto 0:615c697c33b0 119 while(_spi.wlan_irq_read() == 0)
Kojto 0:615c697c33b0 120 {
Kojto 0:615c697c33b0 121 }
Kojto 0:615c697c33b0 122
Kojto 0:615c697c33b0 123 // Free the used by WLAN Driver memory
Kojto 0:615c697c33b0 124 if (_simple_link.get_transmit_buffer())
Kojto 0:615c697c33b0 125 {
Kojto 0:615c697c33b0 126 _simple_link.set_transmit_buffer(0);
Kojto 0:615c697c33b0 127 }
Kojto 0:615c697c33b0 128
Kojto 0:615c697c33b0 129 _spi.close();
Kojto 0:615c697c33b0 130 }
Kojto 0:615c697c33b0 131
Kojto 0:615c697c33b0 132
Kojto 0:615c697c33b0 133 int32_t cc3000_wlan::disconnect() {
Kojto 0:615c697c33b0 134 int32_t ret;
Kojto 0:615c697c33b0 135 uint8_t *ptr;
Kojto 0:615c697c33b0 136
Kojto 0:615c697c33b0 137 ret = EFAIL;
Kojto 0:615c697c33b0 138 ptr = _simple_link.get_transmit_buffer();
Kojto 0:615c697c33b0 139
Kojto 0:615c697c33b0 140 _hci.command_send(HCI_CMND_WLAN_DISCONNECT, ptr, 0);
Kojto 0:615c697c33b0 141
Kojto 0:615c697c33b0 142 // Wait for command complete event
Kojto 0:615c697c33b0 143 _event.simplelink_wait_event(HCI_CMND_WLAN_DISCONNECT, &ret);
Kojto 0:615c697c33b0 144 errno = ret;
Kojto 0:615c697c33b0 145
Kojto 0:615c697c33b0 146 return(ret);
Kojto 0:615c697c33b0 147 }
Kojto 0:615c697c33b0 148
Kojto 0:615c697c33b0 149
Kojto 0:615c697c33b0 150 int32_t cc3000_wlan::ioctl_set_connection_policy(uint32_t should_connect_to_open_ap,
Kojto 0:615c697c33b0 151 uint32_t use_fast_connect,
Kojto 0:615c697c33b0 152 uint32_t use_profiles) {
Kojto 0:615c697c33b0 153 int32_t ret;
Kojto 0:615c697c33b0 154 uint8_t *ptr;
Kojto 0:615c697c33b0 155 uint8_t *args;
Kojto 0:615c697c33b0 156
Kojto 0:615c697c33b0 157 ret = EFAIL;
Kojto 0:615c697c33b0 158 ptr = _simple_link.get_transmit_buffer();
Kojto 0:615c697c33b0 159 args = (uint8_t *)(ptr + HEADERS_SIZE_CMD);
Kojto 0:615c697c33b0 160
Kojto 0:615c697c33b0 161 // Fill in HCI packet structure
Kojto 0:615c697c33b0 162 args = UINT32_TO_STREAM(args, should_connect_to_open_ap);
Kojto 0:615c697c33b0 163 args = UINT32_TO_STREAM(args, use_fast_connect);
Kojto 0:615c697c33b0 164 args = UINT32_TO_STREAM(args, use_profiles);
Kojto 0:615c697c33b0 165
Kojto 0:615c697c33b0 166 // Initiate a HCI command
Kojto 0:615c697c33b0 167 _hci.command_send(HCI_CMND_WLAN_IOCTL_SET_CONNECTION_POLICY, ptr, WLAN_SET_CONNECTION_POLICY_PARAMS_LEN);
Kojto 0:615c697c33b0 168
Kojto 0:615c697c33b0 169 // Wait for command complete event
Kojto 0:615c697c33b0 170 _event.simplelink_wait_event(HCI_CMND_WLAN_IOCTL_SET_CONNECTION_POLICY, &ret);
Kojto 0:615c697c33b0 171
Kojto 0:615c697c33b0 172 return(ret);
Kojto 0:615c697c33b0 173 }
Kojto 0:615c697c33b0 174
Kojto 0:615c697c33b0 175
Kojto 0:615c697c33b0 176 int32_t cc3000_wlan::ioctl_del_profile(uint32_t index) {
Kojto 0:615c697c33b0 177 int32_t ret;
Kojto 0:615c697c33b0 178 uint8_t *ptr;
Kojto 0:615c697c33b0 179 uint8_t *args;
Kojto 0:615c697c33b0 180
Kojto 0:615c697c33b0 181 ptr = _simple_link.get_transmit_buffer();
Kojto 0:615c697c33b0 182 args = (uint8_t *)(ptr + HEADERS_SIZE_CMD);
Kojto 0:615c697c33b0 183
Kojto 0:615c697c33b0 184 // Fill in HCI packet structure
Kojto 0:615c697c33b0 185 args = UINT32_TO_STREAM(args, index);
Kojto 0:615c697c33b0 186 ret = EFAIL;
Kojto 0:615c697c33b0 187
Kojto 0:615c697c33b0 188 // Initiate a HCI command
Kojto 0:615c697c33b0 189 _hci.command_send(HCI_CMND_WLAN_IOCTL_DEL_PROFILE, ptr, WLAN_DEL_PROFILE_PARAMS_LEN);
Kojto 0:615c697c33b0 190
Kojto 0:615c697c33b0 191 // Wait for command complete event
Kojto 0:615c697c33b0 192 _event.simplelink_wait_event(HCI_CMND_WLAN_IOCTL_DEL_PROFILE, &ret);
Kojto 0:615c697c33b0 193
Kojto 0:615c697c33b0 194 return(ret);
Kojto 0:615c697c33b0 195 }
Kojto 0:615c697c33b0 196
Kojto 0:615c697c33b0 197 int32_t cc3000_wlan::set_event_mask(uint32_t mask) {
Kojto 0:615c697c33b0 198 int32_t ret;
Kojto 0:615c697c33b0 199 uint8_t *ptr;
Kojto 0:615c697c33b0 200 uint8_t *args;
Kojto 0:615c697c33b0 201
Kojto 0:615c697c33b0 202
Kojto 0:615c697c33b0 203 if ((mask & HCI_EVNT_WLAN_TX_COMPLETE) == HCI_EVNT_WLAN_TX_COMPLETE)
Kojto 0:615c697c33b0 204 {
Kojto 0:615c697c33b0 205 _simple_link.set_tx_complete_signal(0);
Kojto 0:615c697c33b0 206
Kojto 0:615c697c33b0 207 // Since an event is a virtual event - i.e. it is not coming from CC3000
Kojto 0:615c697c33b0 208 // there is no need to send anything to the device if it was an only event
Kojto 0:615c697c33b0 209 if (mask == HCI_EVNT_WLAN_TX_COMPLETE)
Kojto 0:615c697c33b0 210 {
Kojto 0:615c697c33b0 211 return 0;
Kojto 0:615c697c33b0 212 }
Kojto 0:615c697c33b0 213
Kojto 0:615c697c33b0 214 mask &= ~HCI_EVNT_WLAN_TX_COMPLETE;
Kojto 0:615c697c33b0 215 mask |= HCI_EVNT_WLAN_UNSOL_BASE;
Kojto 0:615c697c33b0 216 }
Kojto 0:615c697c33b0 217 else
Kojto 0:615c697c33b0 218 {
Kojto 0:615c697c33b0 219 _simple_link.set_tx_complete_signal(1);
Kojto 0:615c697c33b0 220 }
Kojto 0:615c697c33b0 221
Kojto 0:615c697c33b0 222 ret = EFAIL;
Kojto 0:615c697c33b0 223 ptr = _simple_link.get_transmit_buffer();
Kojto 0:615c697c33b0 224 args = (uint8_t *)(ptr + HEADERS_SIZE_CMD);
Kojto 0:615c697c33b0 225
Kojto 0:615c697c33b0 226 // Fill in HCI packet structure
Kojto 0:615c697c33b0 227 args = UINT32_TO_STREAM(args, mask);
Kojto 0:615c697c33b0 228
Kojto 0:615c697c33b0 229 // Initiate a HCI command
Kojto 0:615c697c33b0 230 _hci.command_send(HCI_CMND_EVENT_MASK, ptr, WLAN_SET_MASK_PARAMS_LEN);
Kojto 0:615c697c33b0 231
Kojto 0:615c697c33b0 232 // Wait for command complete event
Kojto 0:615c697c33b0 233 _event.simplelink_wait_event(HCI_CMND_EVENT_MASK, &ret);
Kojto 0:615c697c33b0 234
Kojto 0:615c697c33b0 235 return(ret);
Kojto 0:615c697c33b0 236 }
Kojto 0:615c697c33b0 237
Kojto 0:615c697c33b0 238
Kojto 0:615c697c33b0 239 int32_t cc3000_wlan::smart_config_start(uint32_t encrypted_flag) {
Kojto 0:615c697c33b0 240 int32_t ret;
Kojto 0:615c697c33b0 241 uint8_t *ptr;
Kojto 0:615c697c33b0 242 uint8_t *args;
Kojto 0:615c697c33b0 243
Kojto 0:615c697c33b0 244 ret = EFAIL;
Kojto 0:615c697c33b0 245 ptr = _simple_link.get_transmit_buffer();
Kojto 0:615c697c33b0 246 args = (uint8_t *)(ptr + HEADERS_SIZE_CMD);
Kojto 0:615c697c33b0 247
Kojto 0:615c697c33b0 248 // Fill in HCI packet structure
Kojto 0:615c697c33b0 249 args = UINT32_TO_STREAM(args, encrypted_flag);
Kojto 0:615c697c33b0 250 ret = EFAIL;
Kojto 0:615c697c33b0 251
Kojto 0:615c697c33b0 252 _hci.command_send(HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_START, ptr, WLAN_SMART_CONFIG_START_PARAMS_LEN);
Kojto 0:615c697c33b0 253
Kojto 0:615c697c33b0 254 // Wait for command complete event
Kojto 0:615c697c33b0 255 _event.simplelink_wait_event(HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_START, &ret);
Kojto 0:615c697c33b0 256
Kojto 0:615c697c33b0 257 return(ret);
Kojto 0:615c697c33b0 258 }
Kojto 0:615c697c33b0 259
Kojto 0:615c697c33b0 260
Kojto 0:615c697c33b0 261 int32_t cc3000_wlan::smart_config_stop(void) {
Kojto 0:615c697c33b0 262 int32_t ret;
Kojto 0:615c697c33b0 263 uint8_t *ptr;
Kojto 0:615c697c33b0 264
Kojto 0:615c697c33b0 265 ret = EFAIL;
Kojto 0:615c697c33b0 266 ptr = _simple_link.get_transmit_buffer();
Kojto 0:615c697c33b0 267
Kojto 0:615c697c33b0 268 _hci.command_send(HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_STOP, ptr, 0);
Kojto 0:615c697c33b0 269
Kojto 0:615c697c33b0 270 // Wait for command complete event
Kojto 0:615c697c33b0 271 _event.simplelink_wait_event(HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_STOP, &ret);
Kojto 0:615c697c33b0 272
Kojto 0:615c697c33b0 273 return(ret);
Kojto 0:615c697c33b0 274 }
Kojto 0:615c697c33b0 275
Kojto 0:615c697c33b0 276 int32_t cc3000_wlan::smart_config_set_prefix(uint8_t *new_prefix) {
Kojto 0:615c697c33b0 277 int32_t ret;
Kojto 0:615c697c33b0 278 uint8_t *ptr;
Kojto 0:615c697c33b0 279 uint8_t *args;
Kojto 0:615c697c33b0 280
Kojto 0:615c697c33b0 281 ret = EFAIL;
Kojto 0:615c697c33b0 282 ptr = _simple_link.get_transmit_buffer();
Kojto 0:615c697c33b0 283 args = (ptr + HEADERS_SIZE_CMD);
Kojto 0:615c697c33b0 284
Kojto 0:615c697c33b0 285 if (new_prefix == NULL)
Kojto 0:615c697c33b0 286 return ret;
Kojto 0:615c697c33b0 287 else // with the new Smart Config, prefix must be TTT
Kojto 0:615c697c33b0 288 {
Kojto 0:615c697c33b0 289 *new_prefix = 'T';
Kojto 0:615c697c33b0 290 *(new_prefix + 1) = 'T';
Kojto 0:615c697c33b0 291 *(new_prefix + 2) = 'T';
Kojto 0:615c697c33b0 292 }
Kojto 0:615c697c33b0 293
Kojto 0:615c697c33b0 294 ARRAY_TO_STREAM(args, new_prefix, SL_SIMPLE_CONFIG_PREFIX_LENGTH);
Kojto 0:615c697c33b0 295
Kojto 0:615c697c33b0 296 _hci.command_send(HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_SET_PREFIX, ptr, SL_SIMPLE_CONFIG_PREFIX_LENGTH);
Kojto 0:615c697c33b0 297
Kojto 0:615c697c33b0 298 // Wait for command complete event
Kojto 0:615c697c33b0 299 _event.simplelink_wait_event(HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_SET_PREFIX, &ret);
Kojto 0:615c697c33b0 300
Kojto 0:615c697c33b0 301 return(ret);
Kojto 0:615c697c33b0 302 }
Kojto 0:615c697c33b0 303
Kojto 0:615c697c33b0 304 #ifndef CC3000_TINY_DRIVER
Kojto 0:615c697c33b0 305 int32_t cc3000_wlan::connect(uint32_t sec_type, const uint8_t *ssid, int32_t ssid_len, uint8_t *bssid,
Kojto 0:615c697c33b0 306 uint8_t *key, int32_t key_len) {
Kojto 0:615c697c33b0 307 int32_t ret;
Kojto 0:615c697c33b0 308 uint8_t *ptr;
Kojto 0:615c697c33b0 309 uint8_t *args;
Kojto 0:615c697c33b0 310 uint8_t bssid_zero[] = {0, 0, 0, 0, 0, 0};
Kojto 0:615c697c33b0 311
Kojto 0:615c697c33b0 312 ret = EFAIL;
Kojto 0:615c697c33b0 313 ptr = _simple_link.get_transmit_buffer();
Kojto 0:615c697c33b0 314 args = (ptr + HEADERS_SIZE_CMD);
Kojto 0:615c697c33b0 315
Kojto 0:615c697c33b0 316 // Fill in command buffer
Kojto 0:615c697c33b0 317 args = UINT32_TO_STREAM(args, 0x0000001c);
Kojto 0:615c697c33b0 318 args = UINT32_TO_STREAM(args, ssid_len);
Kojto 0:615c697c33b0 319 args = UINT32_TO_STREAM(args, sec_type);
Kojto 0:615c697c33b0 320 args = UINT32_TO_STREAM(args, 0x00000010 + ssid_len);
Kojto 0:615c697c33b0 321 args = UINT32_TO_STREAM(args, key_len);
Kojto 0:615c697c33b0 322 args = UINT16_TO_STREAM(args, 0);
Kojto 0:615c697c33b0 323
Kojto 0:615c697c33b0 324 // padding shall be zeroed
Kojto 0:615c697c33b0 325 if(bssid)
Kojto 0:615c697c33b0 326 {
Kojto 0:615c697c33b0 327 ARRAY_TO_STREAM(args, bssid, ETH_ALEN);
Kojto 0:615c697c33b0 328 }
Kojto 0:615c697c33b0 329 else
Kojto 0:615c697c33b0 330 {
Kojto 0:615c697c33b0 331 ARRAY_TO_STREAM(args, bssid_zero, ETH_ALEN);
Kojto 0:615c697c33b0 332 }
Kojto 0:615c697c33b0 333
Kojto 0:615c697c33b0 334 ARRAY_TO_STREAM(args, ssid, ssid_len);
Kojto 0:615c697c33b0 335
Kojto 0:615c697c33b0 336 if(key_len && key)
Kojto 0:615c697c33b0 337 {
Kojto 0:615c697c33b0 338 ARRAY_TO_STREAM(args, key, key_len);
Kojto 0:615c697c33b0 339 }
Kojto 0:615c697c33b0 340
Kojto 0:615c697c33b0 341 // Initiate a HCI command
Kojto 0:615c697c33b0 342 _hci.command_send(HCI_CMND_WLAN_CONNECT, ptr, WLAN_CONNECT_PARAM_LEN + ssid_len + key_len - 1);
Kojto 0:615c697c33b0 343
Kojto 0:615c697c33b0 344 // Wait for command complete event
Kojto 0:615c697c33b0 345 _event.simplelink_wait_event(HCI_CMND_WLAN_CONNECT, &ret);
Kojto 0:615c697c33b0 346 errno = ret;
Kojto 0:615c697c33b0 347
Kojto 0:615c697c33b0 348 return(ret);
Kojto 0:615c697c33b0 349 }
Kojto 0:615c697c33b0 350
Kojto 0:615c697c33b0 351 int32_t cc3000_wlan::add_profile(uint32_t sec_type,
Kojto 0:615c697c33b0 352 uint8_t* ssid,
Kojto 0:615c697c33b0 353 uint32_t ssid_length,
Kojto 0:615c697c33b0 354 uint8_t *b_ssid,
Kojto 0:615c697c33b0 355 uint32_t priority,
Kojto 0:615c697c33b0 356 uint32_t pairwise_cipher_or_tx_key_len,
Kojto 0:615c697c33b0 357 uint32_t group_cipher_tx_key_index,
Kojto 0:615c697c33b0 358 uint32_t key_mgmt,
Kojto 0:615c697c33b0 359 uint8_t* pf_or_key,
Kojto 0:615c697c33b0 360 uint32_t pass_phrase_len) {
Kojto 0:615c697c33b0 361 uint16_t arg_len = 0x00;
Kojto 0:615c697c33b0 362 int32_t ret;
Kojto 0:615c697c33b0 363 uint8_t *ptr;
Kojto 0:615c697c33b0 364 int32_t i = 0;
Kojto 0:615c697c33b0 365 uint8_t *args;
Kojto 0:615c697c33b0 366 uint8_t bssid_zero[] = {0, 0, 0, 0, 0, 0};
Kojto 0:615c697c33b0 367
Kojto 0:615c697c33b0 368 ptr = _simple_link.get_transmit_buffer();
Kojto 0:615c697c33b0 369 args = (ptr + HEADERS_SIZE_CMD);
Kojto 0:615c697c33b0 370
Kojto 0:615c697c33b0 371 args = UINT32_TO_STREAM(args, sec_type);
Kojto 0:615c697c33b0 372
Kojto 0:615c697c33b0 373 // Setup arguments in accordance with the security type
Kojto 0:615c697c33b0 374 switch (sec_type)
Kojto 0:615c697c33b0 375 {
Kojto 0:615c697c33b0 376 //OPEN
Kojto 0:615c697c33b0 377 case WLAN_SEC_UNSEC:
Kojto 0:615c697c33b0 378 {
Kojto 0:615c697c33b0 379 args = UINT32_TO_STREAM(args, 0x00000014);
Kojto 0:615c697c33b0 380 args = UINT32_TO_STREAM(args, ssid_length);
Kojto 0:615c697c33b0 381 args = UINT16_TO_STREAM(args, 0);
Kojto 0:615c697c33b0 382 if(b_ssid)
Kojto 0:615c697c33b0 383 {
Kojto 0:615c697c33b0 384 ARRAY_TO_STREAM(args, b_ssid, ETH_ALEN);
Kojto 0:615c697c33b0 385 }
Kojto 0:615c697c33b0 386 else
Kojto 0:615c697c33b0 387 {
Kojto 0:615c697c33b0 388 ARRAY_TO_STREAM(args, bssid_zero, ETH_ALEN);
Kojto 0:615c697c33b0 389 }
Kojto 0:615c697c33b0 390 args = UINT32_TO_STREAM(args, priority);
Kojto 0:615c697c33b0 391 ARRAY_TO_STREAM(args, ssid, ssid_length);
Kojto 0:615c697c33b0 392
Kojto 0:615c697c33b0 393 arg_len = WLAN_ADD_PROFILE_NOSEC_PARAM_LEN + ssid_length;
Kojto 0:615c697c33b0 394 }
Kojto 0:615c697c33b0 395 break;
Kojto 0:615c697c33b0 396
Kojto 0:615c697c33b0 397 //WEP
Kojto 0:615c697c33b0 398 case WLAN_SEC_WEP:
Kojto 0:615c697c33b0 399 {
Kojto 0:615c697c33b0 400 args = UINT32_TO_STREAM(args, 0x00000020);
Kojto 0:615c697c33b0 401 args = UINT32_TO_STREAM(args, ssid_length);
Kojto 0:615c697c33b0 402 args = UINT16_TO_STREAM(args, 0);
Kojto 0:615c697c33b0 403 if(b_ssid)
Kojto 0:615c697c33b0 404 {
Kojto 0:615c697c33b0 405 ARRAY_TO_STREAM(args, b_ssid, ETH_ALEN);
Kojto 0:615c697c33b0 406 }
Kojto 0:615c697c33b0 407 else
Kojto 0:615c697c33b0 408 {
Kojto 0:615c697c33b0 409 ARRAY_TO_STREAM(args, bssid_zero, ETH_ALEN);
Kojto 0:615c697c33b0 410 }
Kojto 0:615c697c33b0 411 args = UINT32_TO_STREAM(args, priority);
Kojto 0:615c697c33b0 412 args = UINT32_TO_STREAM(args, 0x0000000C + ssid_length);
Kojto 0:615c697c33b0 413 args = UINT32_TO_STREAM(args, pairwise_cipher_or_tx_key_len);
Kojto 0:615c697c33b0 414 args = UINT32_TO_STREAM(args, group_cipher_tx_key_index);
Kojto 0:615c697c33b0 415 ARRAY_TO_STREAM(args, ssid, ssid_length);
Kojto 0:615c697c33b0 416
Kojto 0:615c697c33b0 417 for(i = 0; i < 4; i++)
Kojto 0:615c697c33b0 418 {
Kojto 0:615c697c33b0 419 uint8_t *p = &pf_or_key[i * pairwise_cipher_or_tx_key_len];
Kojto 0:615c697c33b0 420
Kojto 0:615c697c33b0 421 ARRAY_TO_STREAM(args, p, pairwise_cipher_or_tx_key_len);
Kojto 0:615c697c33b0 422 }
Kojto 0:615c697c33b0 423
Kojto 0:615c697c33b0 424 arg_len = WLAN_ADD_PROFILE_WEP_PARAM_LEN + ssid_length +
Kojto 0:615c697c33b0 425 pairwise_cipher_or_tx_key_len * 4;
Kojto 0:615c697c33b0 426
Kojto 0:615c697c33b0 427 }
Kojto 0:615c697c33b0 428 break;
Kojto 0:615c697c33b0 429
Kojto 0:615c697c33b0 430 //WPA
Kojto 0:615c697c33b0 431 //WPA2
Kojto 0:615c697c33b0 432 case WLAN_SEC_WPA:
Kojto 0:615c697c33b0 433 case WLAN_SEC_WPA2:
Kojto 0:615c697c33b0 434 {
Kojto 0:615c697c33b0 435 args = UINT32_TO_STREAM(args, 0x00000028);
Kojto 0:615c697c33b0 436 args = UINT32_TO_STREAM(args, ssid_length);
Kojto 0:615c697c33b0 437 args = UINT16_TO_STREAM(args, 0);
Kojto 0:615c697c33b0 438 if(b_ssid)
Kojto 0:615c697c33b0 439 {
Kojto 0:615c697c33b0 440 ARRAY_TO_STREAM(args, b_ssid, ETH_ALEN);
Kojto 0:615c697c33b0 441 }
Kojto 0:615c697c33b0 442 else
Kojto 0:615c697c33b0 443 {
Kojto 0:615c697c33b0 444 ARRAY_TO_STREAM(args, bssid_zero, ETH_ALEN);
Kojto 0:615c697c33b0 445 }
Kojto 0:615c697c33b0 446 args = UINT32_TO_STREAM(args, priority);
Kojto 0:615c697c33b0 447 args = UINT32_TO_STREAM(args, pairwise_cipher_or_tx_key_len);
Kojto 0:615c697c33b0 448 args = UINT32_TO_STREAM(args, group_cipher_tx_key_index);
Kojto 0:615c697c33b0 449 args = UINT32_TO_STREAM(args, key_mgmt);
Kojto 0:615c697c33b0 450 args = UINT32_TO_STREAM(args, 0x00000008 + ssid_length);
Kojto 0:615c697c33b0 451 args = UINT32_TO_STREAM(args, pass_phrase_len);
Kojto 0:615c697c33b0 452 ARRAY_TO_STREAM(args, ssid, ssid_length);
Kojto 0:615c697c33b0 453 ARRAY_TO_STREAM(args, pf_or_key, pass_phrase_len);
Kojto 0:615c697c33b0 454
Kojto 0:615c697c33b0 455 arg_len = WLAN_ADD_PROFILE_WPA_PARAM_LEN + ssid_length + pass_phrase_len;
Kojto 0:615c697c33b0 456 }
Kojto 0:615c697c33b0 457
Kojto 0:615c697c33b0 458 break;
Kojto 0:615c697c33b0 459 }
Kojto 0:615c697c33b0 460
Kojto 0:615c697c33b0 461 // Initiate a HCI command
Kojto 0:615c697c33b0 462 _hci.command_send(HCI_CMND_WLAN_IOCTL_ADD_PROFILE, ptr, arg_len);
Kojto 0:615c697c33b0 463
Kojto 0:615c697c33b0 464 // Wait for command complete event
Kojto 0:615c697c33b0 465 _event.simplelink_wait_event(HCI_CMND_WLAN_IOCTL_ADD_PROFILE, &ret);
Kojto 0:615c697c33b0 466
Kojto 0:615c697c33b0 467 return(ret);
Kojto 0:615c697c33b0 468 }
Kojto 0:615c697c33b0 469
Kojto 0:615c697c33b0 470 int32_t cc3000_wlan::ioctl_get_scan_results(uint32_t scan_timeout, uint8_t *results) {
Kojto 0:615c697c33b0 471 uint8_t *ptr;
Kojto 0:615c697c33b0 472 uint8_t *args;
Kojto 0:615c697c33b0 473
Kojto 0:615c697c33b0 474 ptr = _simple_link.get_transmit_buffer();
Kojto 0:615c697c33b0 475 args = (ptr + HEADERS_SIZE_CMD);
Kojto 0:615c697c33b0 476
Kojto 0:615c697c33b0 477 // Fill in temporary command buffer
Kojto 0:615c697c33b0 478 args = UINT32_TO_STREAM(args, scan_timeout);
Kojto 0:615c697c33b0 479
Kojto 0:615c697c33b0 480 // Initiate a HCI command
Kojto 0:615c697c33b0 481 _hci.command_send(HCI_CMND_WLAN_IOCTL_GET_SCAN_RESULTS, ptr, WLAN_GET_SCAN_RESULTS_PARAMS_LEN);
Kojto 0:615c697c33b0 482
Kojto 0:615c697c33b0 483 // Wait for command complete event
Kojto 0:615c697c33b0 484 _event.simplelink_wait_event(HCI_CMND_WLAN_IOCTL_GET_SCAN_RESULTS, results);
Kojto 0:615c697c33b0 485
Kojto 0:615c697c33b0 486 return(0);
Kojto 0:615c697c33b0 487 }
Kojto 0:615c697c33b0 488
Kojto 0:615c697c33b0 489 int32_t cc3000_wlan::ioctl_set_scan_params(uint32_t enable,
Kojto 0:615c697c33b0 490 uint32_t min_dwell_time,
Kojto 0:615c697c33b0 491 uint32_t max_dwell_time,
Kojto 0:615c697c33b0 492 uint32_t num_probe_requests,
Kojto 0:615c697c33b0 493 uint32_t channel_mask,
Kojto 0:615c697c33b0 494 int32_t rssi_threshold,
Kojto 0:615c697c33b0 495 uint32_t snr_threshold,
Kojto 0:615c697c33b0 496 uint32_t default_tx_power,
Kojto 0:615c697c33b0 497 uint32_t *interval_list) {
Kojto 0:615c697c33b0 498 uint32_t uiRes;
Kojto 0:615c697c33b0 499 uint8_t *ptr;
Kojto 0:615c697c33b0 500 uint8_t *args;
Kojto 0:615c697c33b0 501
Kojto 0:615c697c33b0 502 ptr = _simple_link.get_transmit_buffer();
Kojto 0:615c697c33b0 503 args = (ptr + HEADERS_SIZE_CMD);
Kojto 0:615c697c33b0 504
Kojto 0:615c697c33b0 505 // Fill in temporary command buffer
Kojto 0:615c697c33b0 506 args = UINT32_TO_STREAM(args, 36);
Kojto 0:615c697c33b0 507 args = UINT32_TO_STREAM(args, enable);
Kojto 0:615c697c33b0 508 args = UINT32_TO_STREAM(args, min_dwell_time);
Kojto 0:615c697c33b0 509 args = UINT32_TO_STREAM(args, max_dwell_time);
Kojto 0:615c697c33b0 510 args = UINT32_TO_STREAM(args, num_probe_requests);
Kojto 0:615c697c33b0 511 args = UINT32_TO_STREAM(args, channel_mask);
Kojto 0:615c697c33b0 512 args = UINT32_TO_STREAM(args, rssi_threshold);
Kojto 0:615c697c33b0 513 args = UINT32_TO_STREAM(args, snr_threshold);
Kojto 0:615c697c33b0 514 args = UINT32_TO_STREAM(args, default_tx_power);
Kojto 0:615c697c33b0 515 ARRAY_TO_STREAM(args, interval_list, sizeof(uint32_t) * SL_SET_SCAN_PARAMS_INTERVAL_LIST_SIZE);
Kojto 0:615c697c33b0 516
Kojto 0:615c697c33b0 517 // Initiate a HCI command
Kojto 0:615c697c33b0 518 _hci.command_send(HCI_CMND_WLAN_IOCTL_SET_SCANPARAM, ptr, WLAN_SET_SCAN_PARAMS_LEN);
Kojto 0:615c697c33b0 519
Kojto 0:615c697c33b0 520 // Wait for command complete event
Kojto 0:615c697c33b0 521 _event.simplelink_wait_event(HCI_CMND_WLAN_IOCTL_SET_SCANPARAM, &uiRes);
Kojto 0:615c697c33b0 522
Kojto 0:615c697c33b0 523 return(uiRes);
Kojto 0:615c697c33b0 524 }
Kojto 0:615c697c33b0 525
Kojto 0:615c697c33b0 526 int32_t cc3000_wlan::ioctl_statusget(void) {
Kojto 0:615c697c33b0 527 int32_t ret;
Kojto 0:615c697c33b0 528 uint8_t *ptr;
Kojto 0:615c697c33b0 529
Kojto 0:615c697c33b0 530 ret = EFAIL;
Kojto 0:615c697c33b0 531 ptr = _simple_link.get_transmit_buffer();
Kojto 0:615c697c33b0 532
Kojto 0:615c697c33b0 533 _hci.command_send(HCI_CMND_WLAN_IOCTL_STATUSGET,ptr, 0);
Kojto 0:615c697c33b0 534
Kojto 0:615c697c33b0 535 // Wait for command complete event
Kojto 0:615c697c33b0 536 _event.simplelink_wait_event(HCI_CMND_WLAN_IOCTL_STATUSGET, &ret);
Kojto 0:615c697c33b0 537
Kojto 0:615c697c33b0 538 return(ret);
Kojto 0:615c697c33b0 539 }
Kojto 0:615c697c33b0 540
Kojto 0:615c697c33b0 541 #else
Kojto 0:615c697c33b0 542 int32_t cc3000_wlan::wlan_add_profile(uint32_t sec_type,
Kojto 0:615c697c33b0 543 uint8_t *ssid,
Kojto 0:615c697c33b0 544 uint32_t ssid_length,
Kojto 0:615c697c33b0 545 uint8_t *b_ssid,
Kojto 0:615c697c33b0 546 uint32_t priority,
Kojto 0:615c697c33b0 547 uint32_t pairwise_cipher_or_tx_key_len,
Kojto 0:615c697c33b0 548 uint32_t group_cipher_tx_key_index,
Kojto 0:615c697c33b0 549 uint32_t key_mgmt,
Kojto 0:615c697c33b0 550 uint8_t* pf_or_key,
Kojto 0:615c697c33b0 551 uint32_t pass_phrase_length)
Kojto 0:615c697c33b0 552 {
Kojto 0:615c697c33b0 553 return -1;
Kojto 0:615c697c33b0 554 }
Kojto 0:615c697c33b0 555
Kojto 0:615c697c33b0 556 int32_t cc3000_wlan::connect(const uint8_t *ssid, int32_t ssid_len) {
Kojto 0:615c697c33b0 557 int32_t ret;
Kojto 0:615c697c33b0 558 uint8_t *ptr;
Kojto 0:615c697c33b0 559 uint8_t *args;
Kojto 0:615c697c33b0 560 uint8_t bssid_zero[] = {0, 0, 0, 0, 0, 0};
Kojto 0:615c697c33b0 561
Kojto 0:615c697c33b0 562 ret = EFAIL;
Kojto 0:615c697c33b0 563 ptr = _simple_link.get_transmit_buffer();
Kojto 0:615c697c33b0 564 args = (ptr + HEADERS_SIZE_CMD);
Kojto 0:615c697c33b0 565
Kojto 0:615c697c33b0 566 // Fill in command buffer
Kojto 0:615c697c33b0 567 args = UINT32_TO_STREAM(args, 0x0000001c);
Kojto 0:615c697c33b0 568 args = UINT32_TO_STREAM(args, ssid_len);
Kojto 0:615c697c33b0 569 args = UINT32_TO_STREAM(args, 0);
Kojto 0:615c697c33b0 570 args = UINT32_TO_STREAM(args, 0x00000010 + ssid_len);
Kojto 0:615c697c33b0 571 args = UINT32_TO_STREAM(args, 0);
Kojto 0:615c697c33b0 572 args = UINT16_TO_STREAM(args, 0);
Kojto 0:615c697c33b0 573
Kojto 0:615c697c33b0 574 // padding shall be zeroed
Kojto 0:615c697c33b0 575 ARRAY_TO_STREAM(args, bssid_zero, ETH_ALEN);
Kojto 0:615c697c33b0 576 ARRAY_TO_STREAM(args, ssid, ssid_len);
Kojto 0:615c697c33b0 577
Kojto 0:615c697c33b0 578 // Initiate a HCI command
Kojto 0:615c697c33b0 579 _hci.command_send(HCI_CMND_WLAN_CONNECT, ptr, WLAN_CONNECT_PARAM_LEN + ssid_len - 1);
Kojto 0:615c697c33b0 580
Kojto 0:615c697c33b0 581 // Wait for command complete event
Kojto 0:615c697c33b0 582 _event.simplelink_wait_event(HCI_CMND_WLAN_CONNECT, &ret);
Kojto 0:615c697c33b0 583 errno = ret;
Kojto 0:615c697c33b0 584
Kojto 0:615c697c33b0 585 return(ret);
Kojto 0:615c697c33b0 586 }
Kojto 0:615c697c33b0 587 #endif
Kojto 0:615c697c33b0 588
Kojto 0:615c697c33b0 589
Kojto 0:615c697c33b0 590
Kojto 0:615c697c33b0 591 #ifndef CC3000_UNENCRYPTED_SMART_CONFIG
Kojto 0:615c697c33b0 592 int32_t cc3000_wlan::smart_config_process(void) {
Kojto 0:615c697c33b0 593 int32_t returnValue;
Kojto 0:615c697c33b0 594 uint32_t ssidLen, keyLen;
Kojto 0:615c697c33b0 595 uint8_t *decKeyPtr;
Kojto 0:615c697c33b0 596 uint8_t *ssidPtr;
Kojto 0:615c697c33b0 597
Kojto 0:615c697c33b0 598 // read the key from EEPROM - fileID 12
Kojto 0:615c697c33b0 599 returnValue = aes_read_key(key);
Kojto 0:615c697c33b0 600
Kojto 0:615c697c33b0 601 if (returnValue != 0)
Kojto 0:615c697c33b0 602 return returnValue;
Kojto 0:615c697c33b0 603
Kojto 0:615c697c33b0 604 // read the received data from fileID #13 and parse it according to the followings:
Kojto 0:615c697c33b0 605 // 1) SSID LEN - not encrypted
Kojto 0:615c697c33b0 606 // 2) SSID - not encrypted
Kojto 0:615c697c33b0 607 // 3) KEY LEN - not encrypted. always 32 bytes long
Kojto 0:615c697c33b0 608 // 4) Security type - not encrypted
Kojto 0:615c697c33b0 609 // 5) KEY - encrypted together with true key length as the first byte in KEY
Kojto 0:615c697c33b0 610 // to elaborate, there are two corner cases:
Kojto 0:615c697c33b0 611 // 1) the KEY is 32 bytes long. In this case, the first byte does not represent KEY length
Kojto 0:615c697c33b0 612 // 2) the KEY is 31 bytes long. In this case, the first byte represent KEY length and equals 31
Kojto 0:615c697c33b0 613 returnValue = nvmem_read(NVMEM_SHARED_MEM_FILEID, SMART_CONFIG_PROFILE_SIZE, 0, profileArray);
Kojto 0:615c697c33b0 614
Kojto 0:615c697c33b0 615 if (returnValue != 0)
Kojto 0:615c697c33b0 616 return returnValue;
Kojto 0:615c697c33b0 617
Kojto 0:615c697c33b0 618 ssidPtr = &profileArray[1];
Kojto 0:615c697c33b0 619
Kojto 0:615c697c33b0 620 ssidLen = profileArray[0];
Kojto 0:615c697c33b0 621
Kojto 0:615c697c33b0 622 decKeyPtr = &profileArray[profileArray[0] + 3];
Kojto 0:615c697c33b0 623
Kojto 0:615c697c33b0 624 aes_decrypt(decKeyPtr, key);
Kojto 0:615c697c33b0 625 if (profileArray[profileArray[0] + 1] > 16)
Kojto 0:615c697c33b0 626 aes_decrypt((uint8_t *)(decKeyPtr + 16), key);
Kojto 0:615c697c33b0 627
Kojto 0:615c697c33b0 628 if (*(uint8_t *)(decKeyPtr +31) != 0)
Kojto 0:615c697c33b0 629 {
Kojto 0:615c697c33b0 630 if (*decKeyPtr == 31)
Kojto 0:615c697c33b0 631 {
Kojto 0:615c697c33b0 632 keyLen = 31;
Kojto 0:615c697c33b0 633 decKeyPtr++;
Kojto 0:615c697c33b0 634 }
Kojto 0:615c697c33b0 635 else
Kojto 0:615c697c33b0 636 {
Kojto 0:615c697c33b0 637 keyLen = 32;
Kojto 0:615c697c33b0 638 }
Kojto 0:615c697c33b0 639 }
Kojto 0:615c697c33b0 640 else
Kojto 0:615c697c33b0 641 {
Kojto 0:615c697c33b0 642 keyLen = *decKeyPtr;
Kojto 0:615c697c33b0 643 decKeyPtr++;
Kojto 0:615c697c33b0 644 }
Kojto 0:615c697c33b0 645
Kojto 0:615c697c33b0 646 // add a profile
Kojto 0:615c697c33b0 647 switch (profileArray[profileArray[0] + 2])
Kojto 0:615c697c33b0 648 {
Kojto 0:615c697c33b0 649 case WLAN_SEC_UNSEC://None
Kojto 0:615c697c33b0 650 {
Kojto 0:615c697c33b0 651 returnValue = wlan_add_profile(profileArray[profileArray[0] + 2], // security type
Kojto 0:615c697c33b0 652 ssidPtr, // SSID
Kojto 0:615c697c33b0 653 ssidLen, // SSID length
Kojto 0:615c697c33b0 654 NULL, // BSSID
Kojto 0:615c697c33b0 655 1, // Priority
Kojto 0:615c697c33b0 656 0, 0, 0, 0, 0);
Kojto 0:615c697c33b0 657
Kojto 0:615c697c33b0 658 break;
Kojto 0:615c697c33b0 659 }
Kojto 0:615c697c33b0 660
Kojto 0:615c697c33b0 661 case WLAN_SEC_WEP://WEP
Kojto 0:615c697c33b0 662 {
Kojto 0:615c697c33b0 663 returnValue = wlan_add_profile(profileArray[profileArray[0] + 2], // security type
Kojto 0:615c697c33b0 664 ssidPtr, // SSID
Kojto 0:615c697c33b0 665 ssidLen, // SSID length
Kojto 0:615c697c33b0 666 NULL, // BSSID
Kojto 0:615c697c33b0 667 1, // Priority
Kojto 0:615c697c33b0 668 keyLen, // KEY length
Kojto 0:615c697c33b0 669 0, // KEY index
Kojto 0:615c697c33b0 670 0,
Kojto 0:615c697c33b0 671 decKeyPtr, // KEY
Kojto 0:615c697c33b0 672 0);
Kojto 0:615c697c33b0 673
Kojto 0:615c697c33b0 674 break;
Kojto 0:615c697c33b0 675 }
Kojto 0:615c697c33b0 676
Kojto 0:615c697c33b0 677 case WLAN_SEC_WPA: //WPA
Kojto 0:615c697c33b0 678 case WLAN_SEC_WPA2: //WPA2
Kojto 0:615c697c33b0 679 {
Kojto 0:615c697c33b0 680 returnValue = wlan_add_profile(WLAN_SEC_WPA2, // security type
Kojto 0:615c697c33b0 681 ssidPtr,
Kojto 0:615c697c33b0 682 ssidLen,
Kojto 0:615c697c33b0 683 NULL, // BSSID
Kojto 0:615c697c33b0 684 1, // Priority
Kojto 0:615c697c33b0 685 0x18, // PairwiseCipher
Kojto 0:615c697c33b0 686 0x1e, // GroupCipher
Kojto 0:615c697c33b0 687 2, // KEY management
Kojto 0:615c697c33b0 688 decKeyPtr, // KEY
Kojto 0:615c697c33b0 689 keyLen); // KEY length
Kojto 0:615c697c33b0 690
Kojto 0:615c697c33b0 691 break;
Kojto 0:615c697c33b0 692 }
Kojto 0:615c697c33b0 693 }
Kojto 0:615c697c33b0 694
Kojto 0:615c697c33b0 695 return returnValue;
Kojto 0:615c697c33b0 696 }
Kojto 0:615c697c33b0 697 #endif
Kojto 0:615c697c33b0 698
Kojto 0:615c697c33b0 699 }