A Port of TI's Webserver for the CC3000

Dependencies:   mbed

Committer:
dflet
Date:
Mon Sep 16 18:37:14 2013 +0000
Revision:
2:e6a185df9e4c
Parent:
0:6ad60d78b315
ADC and Leds now work on board and config.html page.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dflet 0:6ad60d78b315 1 /*****************************************************************************
dflet 0:6ad60d78b315 2 *
dflet 0:6ad60d78b315 3 * wlan.c - CC3000 Host Driver Implementation.
dflet 0:6ad60d78b315 4 * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
dflet 0:6ad60d78b315 5 *
dflet 0:6ad60d78b315 6 * Redistribution and use in source and binary forms, with or without
dflet 0:6ad60d78b315 7 * modification, are permitted provided that the following conditions
dflet 0:6ad60d78b315 8 * are met:
dflet 0:6ad60d78b315 9 *
dflet 0:6ad60d78b315 10 * Redistributions of source code must retain the above copyright
dflet 0:6ad60d78b315 11 * notice, this list of conditions and the following disclaimer.
dflet 0:6ad60d78b315 12 *
dflet 0:6ad60d78b315 13 * Redistributions in binary form must reproduce the above copyright
dflet 0:6ad60d78b315 14 * notice, this list of conditions and the following disclaimer in the
dflet 0:6ad60d78b315 15 * documentation and/or other materials provided with the
dflet 0:6ad60d78b315 16 * distribution.
dflet 0:6ad60d78b315 17 *
dflet 0:6ad60d78b315 18 * Neither the name of Texas Instruments Incorporated nor the names of
dflet 0:6ad60d78b315 19 * its contributors may be used to endorse or promote products derived
dflet 0:6ad60d78b315 20 * from this software without specific prior written permission.
dflet 0:6ad60d78b315 21 *
dflet 0:6ad60d78b315 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
dflet 0:6ad60d78b315 23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
dflet 0:6ad60d78b315 24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
dflet 0:6ad60d78b315 25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
dflet 0:6ad60d78b315 26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
dflet 0:6ad60d78b315 27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
dflet 0:6ad60d78b315 28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
dflet 0:6ad60d78b315 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
dflet 0:6ad60d78b315 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
dflet 0:6ad60d78b315 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
dflet 0:6ad60d78b315 32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dflet 0:6ad60d78b315 33 *
dflet 0:6ad60d78b315 34 *****************************************************************************/
dflet 0:6ad60d78b315 35
dflet 0:6ad60d78b315 36 //*****************************************************************************
dflet 0:6ad60d78b315 37 //
dflet 0:6ad60d78b315 38 //! \addtogroup wlan_api
dflet 0:6ad60d78b315 39 //! @{
dflet 0:6ad60d78b315 40 //
dflet 0:6ad60d78b315 41 //*****************************************************************************
dflet 0:6ad60d78b315 42 #include <string.h>
dflet 0:6ad60d78b315 43 #include "wlan.h"
dflet 0:6ad60d78b315 44 #include "hci.h"
dflet 0:6ad60d78b315 45 #include "spi.h"
dflet 0:6ad60d78b315 46 #include "socket.h"
dflet 0:6ad60d78b315 47 #include "nvmem.h"
dflet 0:6ad60d78b315 48 #include "security.h"
dflet 0:6ad60d78b315 49 #include "evnt_handler.h"
dflet 0:6ad60d78b315 50
dflet 0:6ad60d78b315 51
dflet 0:6ad60d78b315 52 volatile sSimplLinkInformation tSLInformation;
dflet 0:6ad60d78b315 53
dflet 0:6ad60d78b315 54 #define SMART_CONFIG_PROFILE_SIZE 67 // 67 = 32 (max ssid) + 32 (max key) + 1 (SSID length) + 1 (security type) + 1 (key length)
dflet 0:6ad60d78b315 55
dflet 0:6ad60d78b315 56 #ifndef CC3000_UNENCRYPTED_SMART_CONFIG
dflet 0:6ad60d78b315 57 unsigned char key[AES128_KEY_SIZE];
dflet 0:6ad60d78b315 58 unsigned char profileArray[SMART_CONFIG_PROFILE_SIZE];
dflet 0:6ad60d78b315 59 #endif //CC3000_UNENCRYPTED_SMART_CONFIG
dflet 0:6ad60d78b315 60
dflet 0:6ad60d78b315 61 /* patches type */
dflet 0:6ad60d78b315 62 #define PATCHES_HOST_TYPE_WLAN_DRIVER 0x01
dflet 0:6ad60d78b315 63 #define PATCHES_HOST_TYPE_WLAN_FW 0x02
dflet 0:6ad60d78b315 64 #define PATCHES_HOST_TYPE_BOOTLOADER 0x03
dflet 0:6ad60d78b315 65
dflet 0:6ad60d78b315 66 #define SL_SET_SCAN_PARAMS_INTERVAL_LIST_SIZE (16)
dflet 0:6ad60d78b315 67 #define SL_SIMPLE_CONFIG_PREFIX_LENGTH (3)
dflet 0:6ad60d78b315 68 #define ETH_ALEN (6)
dflet 0:6ad60d78b315 69 #define MAXIMAL_SSID_LENGTH (32)
dflet 0:6ad60d78b315 70
dflet 0:6ad60d78b315 71 #define SL_PATCHES_REQUEST_DEFAULT (0)
dflet 0:6ad60d78b315 72 #define SL_PATCHES_REQUEST_FORCE_HOST (1)
dflet 0:6ad60d78b315 73 #define SL_PATCHES_REQUEST_FORCE_NONE (2)
dflet 0:6ad60d78b315 74
dflet 0:6ad60d78b315 75
dflet 0:6ad60d78b315 76 #define WLAN_SEC_UNSEC (0)
dflet 0:6ad60d78b315 77 #define WLAN_SEC_WEP (1)
dflet 0:6ad60d78b315 78 #define WLAN_SEC_WPA (2)
dflet 0:6ad60d78b315 79 #define WLAN_SEC_WPA2 (3)
dflet 0:6ad60d78b315 80
dflet 0:6ad60d78b315 81
dflet 0:6ad60d78b315 82 #define WLAN_SL_INIT_START_PARAMS_LEN (1)
dflet 0:6ad60d78b315 83 #define WLAN_PATCH_PARAMS_LENGTH (8)
dflet 0:6ad60d78b315 84 #define WLAN_SET_CONNECTION_POLICY_PARAMS_LEN (12)
dflet 0:6ad60d78b315 85 #define WLAN_DEL_PROFILE_PARAMS_LEN (4)
dflet 0:6ad60d78b315 86 #define WLAN_SET_MASK_PARAMS_LEN (4)
dflet 0:6ad60d78b315 87 #define WLAN_SET_SCAN_PARAMS_LEN (100)
dflet 0:6ad60d78b315 88 #define WLAN_GET_SCAN_RESULTS_PARAMS_LEN (4)
dflet 0:6ad60d78b315 89 #define WLAN_ADD_PROFILE_NOSEC_PARAM_LEN (24)
dflet 0:6ad60d78b315 90 #define WLAN_ADD_PROFILE_WEP_PARAM_LEN (36)
dflet 0:6ad60d78b315 91 #define WLAN_ADD_PROFILE_WPA_PARAM_LEN (44)
dflet 0:6ad60d78b315 92 #define WLAN_CONNECT_PARAM_LEN (29)
dflet 0:6ad60d78b315 93 #define WLAN_SMART_CONFIG_START_PARAMS_LEN (4)
dflet 0:6ad60d78b315 94
dflet 0:6ad60d78b315 95
dflet 0:6ad60d78b315 96
dflet 0:6ad60d78b315 97
dflet 0:6ad60d78b315 98 //*****************************************************************************
dflet 0:6ad60d78b315 99 //
dflet 0:6ad60d78b315 100 //! SimpleLink_Init_Start
dflet 0:6ad60d78b315 101 //!
dflet 0:6ad60d78b315 102 //! @param usPatchesAvailableAtHost flag to indicate if patches available
dflet 0:6ad60d78b315 103 //! from host or from EEPROM. Due to the
dflet 0:6ad60d78b315 104 //! fact the patches are burn to the EEPROM
dflet 0:6ad60d78b315 105 //! using the patch programmer utility, the
dflet 0:6ad60d78b315 106 //! patches will be available from the EEPROM
dflet 0:6ad60d78b315 107 //! and not from the host.
dflet 0:6ad60d78b315 108 //!
dflet 0:6ad60d78b315 109 //! @return none
dflet 0:6ad60d78b315 110 //!
dflet 0:6ad60d78b315 111 //! @brief Send HCI_CMND_SIMPLE_LINK_START to CC3000
dflet 0:6ad60d78b315 112 //
dflet 0:6ad60d78b315 113 //*****************************************************************************
dflet 0:6ad60d78b315 114 static void SimpleLink_Init_Start(unsigned short usPatchesAvailableAtHost)
dflet 0:6ad60d78b315 115 {
dflet 0:6ad60d78b315 116 unsigned char *ptr;
dflet 0:6ad60d78b315 117 unsigned char *args;
dflet 0:6ad60d78b315 118
dflet 0:6ad60d78b315 119 ptr = tSLInformation.pucTxCommandBuffer;
dflet 0:6ad60d78b315 120 args = (unsigned char *)(ptr + HEADERS_SIZE_CMD);
dflet 0:6ad60d78b315 121
dflet 0:6ad60d78b315 122 UINT8_TO_STREAM(args, ((usPatchesAvailableAtHost) ? SL_PATCHES_REQUEST_FORCE_HOST : SL_PATCHES_REQUEST_DEFAULT));
dflet 0:6ad60d78b315 123
dflet 0:6ad60d78b315 124 // IRQ Line asserted - send HCI_CMND_SIMPLE_LINK_START to CC3000
dflet 0:6ad60d78b315 125 hci_command_send(HCI_CMND_SIMPLE_LINK_START, ptr, WLAN_SL_INIT_START_PARAMS_LEN);
dflet 0:6ad60d78b315 126
dflet 0:6ad60d78b315 127 SimpleLinkWaitEvent(HCI_CMND_SIMPLE_LINK_START, 0);
dflet 0:6ad60d78b315 128 }
dflet 0:6ad60d78b315 129
dflet 0:6ad60d78b315 130
dflet 0:6ad60d78b315 131
dflet 0:6ad60d78b315 132 //*****************************************************************************
dflet 0:6ad60d78b315 133 //
dflet 0:6ad60d78b315 134 //! wlan_init
dflet 0:6ad60d78b315 135 //!
dflet 0:6ad60d78b315 136 //! @param sWlanCB Asynchronous events callback.
dflet 0:6ad60d78b315 137 //! 0 no event call back.
dflet 0:6ad60d78b315 138 //! -call back parameters:
dflet 0:6ad60d78b315 139 //! 1) event_type: HCI_EVNT_WLAN_UNSOL_CONNECT connect event,
dflet 0:6ad60d78b315 140 //! HCI_EVNT_WLAN_UNSOL_DISCONNECT disconnect event,
dflet 0:6ad60d78b315 141 //! HCI_EVNT_WLAN_ASYNC_SIMPLE_CONFIG_DONE config done,
dflet 0:6ad60d78b315 142 //! HCI_EVNT_WLAN_UNSOL_DHCP dhcp report,
dflet 0:6ad60d78b315 143 //! HCI_EVNT_WLAN_ASYNC_PING_REPORT ping report OR
dflet 0:6ad60d78b315 144 //! HCI_EVNT_WLAN_KEEPALIVE keepalive.
dflet 0:6ad60d78b315 145 //! 2) data: pointer to extra data that received by the event
dflet 0:6ad60d78b315 146 //! (NULL no data).
dflet 0:6ad60d78b315 147 //! 3) length: data length.
dflet 0:6ad60d78b315 148 //! -Events with extra data:
dflet 0:6ad60d78b315 149 //! HCI_EVNT_WLAN_UNSOL_DHCP: 4 bytes IP, 4 bytes Mask,
dflet 0:6ad60d78b315 150 //! 4 bytes default gateway, 4 bytes DHCP server and 4 bytes
dflet 0:6ad60d78b315 151 //! for DNS server.
dflet 0:6ad60d78b315 152 //! HCI_EVNT_WLAN_ASYNC_PING_REPORT: 4 bytes Packets sent,
dflet 0:6ad60d78b315 153 //! 4 bytes Packets received, 4 bytes Min round time,
dflet 0:6ad60d78b315 154 //! 4 bytes Max round time and 4 bytes for Avg round time.
dflet 0:6ad60d78b315 155 //!
dflet 0:6ad60d78b315 156 //! @param sFWPatches 0 no patch or pointer to FW patches
dflet 0:6ad60d78b315 157 //! @param sDriverPatches 0 no patch or pointer to driver patches
dflet 0:6ad60d78b315 158 //! @param sBootLoaderPatches 0 no patch or pointer to bootloader patches
dflet 0:6ad60d78b315 159 //! @param sReadWlanInterruptPin init callback. the callback read wlan
dflet 0:6ad60d78b315 160 //! interrupt status.
dflet 0:6ad60d78b315 161 //! @param sWlanInterruptEnable init callback. the callback enable wlan
dflet 0:6ad60d78b315 162 //! interrupt.
dflet 0:6ad60d78b315 163 //! @param sWlanInterruptDisable init callback. the callback disable wlan
dflet 0:6ad60d78b315 164 //! interrupt.
dflet 0:6ad60d78b315 165 //! @param sWriteWlanPin init callback. the callback write value
dflet 0:6ad60d78b315 166 //! to device pin.
dflet 0:6ad60d78b315 167 //!
dflet 0:6ad60d78b315 168 //! @return none
dflet 0:6ad60d78b315 169 //!
dflet 0:6ad60d78b315 170 //! @sa wlan_set_event_mask , wlan_start , wlan_stop
dflet 0:6ad60d78b315 171 //!
dflet 0:6ad60d78b315 172 //! @brief Initialize wlan driver
dflet 0:6ad60d78b315 173 //!
dflet 0:6ad60d78b315 174 //! @warning This function must be called before ANY other wlan driver function
dflet 0:6ad60d78b315 175 //
dflet 0:6ad60d78b315 176 //*****************************************************************************
dflet 0:6ad60d78b315 177
dflet 0:6ad60d78b315 178 void wlan_init( tWlanCB sWlanCB,
dflet 0:6ad60d78b315 179 tFWPatches sFWPatches,
dflet 0:6ad60d78b315 180 tDriverPatches sDriverPatches,
dflet 0:6ad60d78b315 181 tBootLoaderPatches sBootLoaderPatches,
dflet 0:6ad60d78b315 182 tWlanReadInteruptPin sReadWlanInterruptPin,
dflet 0:6ad60d78b315 183 tWlanInterruptEnable sWlanInterruptEnable,
dflet 0:6ad60d78b315 184 tWlanInterruptDisable sWlanInterruptDisable,
dflet 0:6ad60d78b315 185 tWriteWlanPin sWriteWlanPin)
dflet 0:6ad60d78b315 186 {
dflet 0:6ad60d78b315 187
dflet 0:6ad60d78b315 188 tSLInformation.sFWPatches = sFWPatches;
dflet 0:6ad60d78b315 189 tSLInformation.sDriverPatches = sDriverPatches;
dflet 0:6ad60d78b315 190 tSLInformation.sBootLoaderPatches = sBootLoaderPatches;
dflet 0:6ad60d78b315 191
dflet 0:6ad60d78b315 192 // init io callback
dflet 0:6ad60d78b315 193 tSLInformation.ReadWlanInterruptPin = sReadWlanInterruptPin;
dflet 0:6ad60d78b315 194 tSLInformation.WlanInterruptEnable = sWlanInterruptEnable;
dflet 0:6ad60d78b315 195 tSLInformation.WlanInterruptDisable = sWlanInterruptDisable;
dflet 0:6ad60d78b315 196 tSLInformation.WriteWlanPin = sWriteWlanPin;
dflet 0:6ad60d78b315 197
dflet 0:6ad60d78b315 198 //init asynchronous events callback
dflet 0:6ad60d78b315 199 tSLInformation.sWlanCB= sWlanCB;
dflet 0:6ad60d78b315 200
dflet 0:6ad60d78b315 201 // By default TX Complete events are routed to host too
dflet 0:6ad60d78b315 202 tSLInformation.InformHostOnTxComplete = 1;
dflet 0:6ad60d78b315 203 }
dflet 0:6ad60d78b315 204
dflet 0:6ad60d78b315 205 //*****************************************************************************
dflet 0:6ad60d78b315 206 //
dflet 0:6ad60d78b315 207 //! SpiReceiveHandler
dflet 0:6ad60d78b315 208 //!
dflet 0:6ad60d78b315 209 //! @param pvBuffer - pointer to the received data buffer
dflet 0:6ad60d78b315 210 //! The function triggers Received event/data processing
dflet 0:6ad60d78b315 211 //!
dflet 0:6ad60d78b315 212 //! @param Pointer to the received data
dflet 0:6ad60d78b315 213 //! @return none
dflet 0:6ad60d78b315 214 //!
dflet 0:6ad60d78b315 215 //! @brief The function triggers Received event/data processing. It is
dflet 0:6ad60d78b315 216 //! called from the SPI library to receive the data
dflet 0:6ad60d78b315 217 //
dflet 0:6ad60d78b315 218 //*****************************************************************************
dflet 0:6ad60d78b315 219 void SpiReceiveHandler(void *pvBuffer)
dflet 0:6ad60d78b315 220 {
dflet 0:6ad60d78b315 221 tSLInformation.usEventOrDataReceived = 1;
dflet 0:6ad60d78b315 222 tSLInformation.pucReceivedData = (unsigned char *)pvBuffer;
dflet 0:6ad60d78b315 223
dflet 0:6ad60d78b315 224 hci_unsolicited_event_handler();
dflet 0:6ad60d78b315 225 }
dflet 0:6ad60d78b315 226
dflet 0:6ad60d78b315 227
dflet 0:6ad60d78b315 228 //*****************************************************************************
dflet 0:6ad60d78b315 229 //
dflet 0:6ad60d78b315 230 //! wlan_start
dflet 0:6ad60d78b315 231 //!
dflet 0:6ad60d78b315 232 //! @param usPatchesAvailableAtHost - flag to indicate if patches available
dflet 0:6ad60d78b315 233 //! from host or from EEPROM. Due to the
dflet 0:6ad60d78b315 234 //! fact the patches are burn to the EEPROM
dflet 0:6ad60d78b315 235 //! using the patch programmer utility, the
dflet 0:6ad60d78b315 236 //! patches will be available from the EEPROM
dflet 0:6ad60d78b315 237 //! and not from the host.
dflet 0:6ad60d78b315 238 //!
dflet 0:6ad60d78b315 239 //! @return none
dflet 0:6ad60d78b315 240 //!
dflet 0:6ad60d78b315 241 //! @brief Start WLAN device. This function asserts the enable pin of
dflet 0:6ad60d78b315 242 //! the device (WLAN_EN), starting the HW initialization process.
dflet 0:6ad60d78b315 243 //! The function blocked until device Initialization is completed.
dflet 0:6ad60d78b315 244 //! Function also configure patches (FW, driver or bootloader)
dflet 0:6ad60d78b315 245 //! and calls appropriate device callbacks.
dflet 0:6ad60d78b315 246 //!
dflet 0:6ad60d78b315 247 //! @Note Prior calling the function wlan_init shall be called.
dflet 0:6ad60d78b315 248 //! @Warning This function must be called after wlan_init and before any
dflet 0:6ad60d78b315 249 //! other wlan API
dflet 0:6ad60d78b315 250 //! @sa wlan_init , wlan_stop
dflet 0:6ad60d78b315 251 //!
dflet 0:6ad60d78b315 252 //
dflet 0:6ad60d78b315 253 //*****************************************************************************
dflet 0:6ad60d78b315 254
dflet 0:6ad60d78b315 255 void
dflet 0:6ad60d78b315 256 wlan_start(unsigned short usPatchesAvailableAtHost)
dflet 0:6ad60d78b315 257 {
dflet 0:6ad60d78b315 258
dflet 0:6ad60d78b315 259 unsigned long ulSpiIRQState;
dflet 0:6ad60d78b315 260
dflet 0:6ad60d78b315 261 tSLInformation.NumberOfSentPackets = 0;
dflet 0:6ad60d78b315 262 tSLInformation.NumberOfReleasedPackets = 0;
dflet 0:6ad60d78b315 263 tSLInformation.usRxEventOpcode = 0;
dflet 0:6ad60d78b315 264 tSLInformation.usNumberOfFreeBuffers = 0;
dflet 0:6ad60d78b315 265 tSLInformation.usSlBufferLength = 0;
dflet 0:6ad60d78b315 266 tSLInformation.usBufferSize = 0;
dflet 0:6ad60d78b315 267 tSLInformation.usRxDataPending = 0;
dflet 0:6ad60d78b315 268 tSLInformation.slTransmitDataError = 0;
dflet 0:6ad60d78b315 269 tSLInformation.usEventOrDataReceived = 0;
dflet 0:6ad60d78b315 270 tSLInformation.pucReceivedData = 0;
dflet 0:6ad60d78b315 271
dflet 0:6ad60d78b315 272 // Allocate the memory for the RX/TX data transactions
dflet 0:6ad60d78b315 273 tSLInformation.pucTxCommandBuffer = (unsigned char *)wlan_tx_buffer;
dflet 0:6ad60d78b315 274
dflet 0:6ad60d78b315 275 // init spi
dflet 0:6ad60d78b315 276 SpiOpen(SpiReceiveHandler);
dflet 0:6ad60d78b315 277
dflet 0:6ad60d78b315 278 // Check the IRQ line
dflet 0:6ad60d78b315 279 ulSpiIRQState = tSLInformation.ReadWlanInterruptPin();
dflet 0:6ad60d78b315 280
dflet 0:6ad60d78b315 281 // ASIC 1273 chip enable: toggle WLAN EN line
dflet 0:6ad60d78b315 282 tSLInformation.WriteWlanPin( WLAN_ENABLE );
dflet 0:6ad60d78b315 283
dflet 0:6ad60d78b315 284 if (ulSpiIRQState)
dflet 0:6ad60d78b315 285 {
dflet 0:6ad60d78b315 286 // wait till the IRQ line goes low
dflet 0:6ad60d78b315 287 while(tSLInformation.ReadWlanInterruptPin() != 0)
dflet 0:6ad60d78b315 288 {
dflet 0:6ad60d78b315 289 }
dflet 0:6ad60d78b315 290 }
dflet 0:6ad60d78b315 291 else
dflet 0:6ad60d78b315 292 {
dflet 0:6ad60d78b315 293 // wait till the IRQ line goes high and than low
dflet 0:6ad60d78b315 294 while(tSLInformation.ReadWlanInterruptPin() == 0)
dflet 0:6ad60d78b315 295 {
dflet 0:6ad60d78b315 296 }
dflet 0:6ad60d78b315 297
dflet 0:6ad60d78b315 298 while(tSLInformation.ReadWlanInterruptPin() != 0)
dflet 0:6ad60d78b315 299 {
dflet 0:6ad60d78b315 300 }
dflet 0:6ad60d78b315 301 }
dflet 0:6ad60d78b315 302
dflet 0:6ad60d78b315 303 SimpleLink_Init_Start(usPatchesAvailableAtHost);
dflet 0:6ad60d78b315 304
dflet 0:6ad60d78b315 305 // Read Buffer's size and finish
dflet 0:6ad60d78b315 306 hci_command_send(HCI_CMND_READ_BUFFER_SIZE, tSLInformation.pucTxCommandBuffer, 0);
dflet 0:6ad60d78b315 307 SimpleLinkWaitEvent(HCI_CMND_READ_BUFFER_SIZE, 0);
dflet 0:6ad60d78b315 308 }
dflet 0:6ad60d78b315 309
dflet 0:6ad60d78b315 310
dflet 0:6ad60d78b315 311 //*****************************************************************************
dflet 0:6ad60d78b315 312 //
dflet 0:6ad60d78b315 313 //! wlan_stop
dflet 0:6ad60d78b315 314 //!
dflet 0:6ad60d78b315 315 //! @param none
dflet 0:6ad60d78b315 316 //!
dflet 0:6ad60d78b315 317 //! @return none
dflet 0:6ad60d78b315 318 //!
dflet 0:6ad60d78b315 319 //! @brief Stop WLAN device by putting it into reset state.
dflet 0:6ad60d78b315 320 //!
dflet 0:6ad60d78b315 321 //! @sa wlan_start
dflet 0:6ad60d78b315 322 //
dflet 0:6ad60d78b315 323 //*****************************************************************************
dflet 0:6ad60d78b315 324
dflet 0:6ad60d78b315 325 void
dflet 0:6ad60d78b315 326 wlan_stop(void)
dflet 0:6ad60d78b315 327 {
dflet 0:6ad60d78b315 328 // ASIC 1273 chip disable
dflet 0:6ad60d78b315 329 tSLInformation.WriteWlanPin( WLAN_DISABLE );
dflet 0:6ad60d78b315 330
dflet 0:6ad60d78b315 331 // Wait till IRQ line goes high...
dflet 0:6ad60d78b315 332 while(tSLInformation.ReadWlanInterruptPin() == 0)
dflet 0:6ad60d78b315 333 {
dflet 0:6ad60d78b315 334 }
dflet 0:6ad60d78b315 335
dflet 0:6ad60d78b315 336 // Free the used by WLAN Driver memory
dflet 0:6ad60d78b315 337 if (tSLInformation.pucTxCommandBuffer)
dflet 0:6ad60d78b315 338 {
dflet 0:6ad60d78b315 339 tSLInformation.pucTxCommandBuffer = 0;
dflet 0:6ad60d78b315 340 }
dflet 0:6ad60d78b315 341
dflet 0:6ad60d78b315 342 SpiClose();
dflet 0:6ad60d78b315 343 }
dflet 0:6ad60d78b315 344
dflet 0:6ad60d78b315 345
dflet 0:6ad60d78b315 346 //*****************************************************************************
dflet 0:6ad60d78b315 347 //
dflet 0:6ad60d78b315 348 //! wlan_connect
dflet 0:6ad60d78b315 349 //!
dflet 0:6ad60d78b315 350 //! @param sec_type security options:
dflet 0:6ad60d78b315 351 //! WLAN_SEC_UNSEC,
dflet 0:6ad60d78b315 352 //! WLAN_SEC_WEP (ASCII support only),
dflet 0:6ad60d78b315 353 //! WLAN_SEC_WPA or WLAN_SEC_WPA2
dflet 0:6ad60d78b315 354 //! @param ssid up to 32 bytes and is ASCII SSID of the AP
dflet 0:6ad60d78b315 355 //! @param ssid_len length of the SSID
dflet 0:6ad60d78b315 356 //! @param bssid 6 bytes specified the AP bssid
dflet 0:6ad60d78b315 357 //! @param key up to 16 bytes specified the AP security key
dflet 0:6ad60d78b315 358 //! @param key_len key length
dflet 0:6ad60d78b315 359 //!
dflet 0:6ad60d78b315 360 //! @return On success, zero is returned. On error, negative is returned.
dflet 0:6ad60d78b315 361 //! Note that even though a zero is returned on success to trigger
dflet 0:6ad60d78b315 362 //! connection operation, it does not mean that CCC3000 is already
dflet 0:6ad60d78b315 363 //! connected. An asynchronous "Connected" event is generated when
dflet 0:6ad60d78b315 364 //! actual association process finishes and CC3000 is connected to
dflet 0:6ad60d78b315 365 //! the AP. If DHCP is set, An asynchronous "DHCP" event is
dflet 0:6ad60d78b315 366 //! generated when DHCP process is finish.
dflet 0:6ad60d78b315 367 //!
dflet 0:6ad60d78b315 368 //!
dflet 0:6ad60d78b315 369 //! @brief Connect to AP
dflet 0:6ad60d78b315 370 //! @warning Please Note that when connection to AP configured with security
dflet 0:6ad60d78b315 371 //! type WEP, please confirm that the key is set as ASCII and not
dflet 0:6ad60d78b315 372 //! as HEX.
dflet 0:6ad60d78b315 373 //! @sa wlan_disconnect
dflet 0:6ad60d78b315 374 //
dflet 0:6ad60d78b315 375 //*****************************************************************************
dflet 0:6ad60d78b315 376
dflet 0:6ad60d78b315 377 #ifndef CC3000_TINY_DRIVER
dflet 0:6ad60d78b315 378 long
dflet 0:6ad60d78b315 379 wlan_connect(unsigned long ulSecType, char *ssid, long ssid_len,
dflet 0:6ad60d78b315 380 unsigned char *bssid, unsigned char *key, long key_len)
dflet 0:6ad60d78b315 381 {
dflet 0:6ad60d78b315 382 long ret;
dflet 0:6ad60d78b315 383 unsigned char *ptr;
dflet 0:6ad60d78b315 384 unsigned char *args;
dflet 0:6ad60d78b315 385 unsigned char bssid_zero[] = {0, 0, 0, 0, 0, 0};
dflet 0:6ad60d78b315 386
dflet 0:6ad60d78b315 387 ret = EFAIL;
dflet 0:6ad60d78b315 388 ptr = tSLInformation.pucTxCommandBuffer;
dflet 0:6ad60d78b315 389 args = (ptr + HEADERS_SIZE_CMD);
dflet 0:6ad60d78b315 390
dflet 0:6ad60d78b315 391 // Fill in command buffer
dflet 0:6ad60d78b315 392 args = UINT32_TO_STREAM(args, 0x0000001c);
dflet 0:6ad60d78b315 393 args = UINT32_TO_STREAM(args, ssid_len);
dflet 0:6ad60d78b315 394 args = UINT32_TO_STREAM(args, ulSecType);
dflet 0:6ad60d78b315 395 args = UINT32_TO_STREAM(args, 0x00000010 + ssid_len);
dflet 0:6ad60d78b315 396 args = UINT32_TO_STREAM(args, key_len);
dflet 0:6ad60d78b315 397 args = UINT16_TO_STREAM(args, 0);
dflet 0:6ad60d78b315 398
dflet 0:6ad60d78b315 399 // padding shall be zeroed
dflet 0:6ad60d78b315 400 if(bssid)
dflet 0:6ad60d78b315 401 {
dflet 0:6ad60d78b315 402 ARRAY_TO_STREAM(args, bssid, ETH_ALEN);
dflet 0:6ad60d78b315 403 }
dflet 0:6ad60d78b315 404 else
dflet 0:6ad60d78b315 405 {
dflet 0:6ad60d78b315 406 ARRAY_TO_STREAM(args, bssid_zero, ETH_ALEN);
dflet 0:6ad60d78b315 407 }
dflet 0:6ad60d78b315 408
dflet 0:6ad60d78b315 409 ARRAY_TO_STREAM(args, ssid, ssid_len);
dflet 0:6ad60d78b315 410
dflet 0:6ad60d78b315 411 if(key_len && key)
dflet 0:6ad60d78b315 412 {
dflet 0:6ad60d78b315 413 ARRAY_TO_STREAM(args, key, key_len);
dflet 0:6ad60d78b315 414 }
dflet 0:6ad60d78b315 415
dflet 0:6ad60d78b315 416 // Initiate a HCI command
dflet 0:6ad60d78b315 417 hci_command_send(HCI_CMND_WLAN_CONNECT, ptr, WLAN_CONNECT_PARAM_LEN +
dflet 0:6ad60d78b315 418 ssid_len + key_len - 1);
dflet 0:6ad60d78b315 419
dflet 0:6ad60d78b315 420 // Wait for command complete event
dflet 0:6ad60d78b315 421 SimpleLinkWaitEvent(HCI_CMND_WLAN_CONNECT, &ret);
dflet 0:6ad60d78b315 422 errno = ret;
dflet 0:6ad60d78b315 423
dflet 0:6ad60d78b315 424 return(ret);
dflet 0:6ad60d78b315 425 }
dflet 0:6ad60d78b315 426 #else
dflet 0:6ad60d78b315 427 long
dflet 0:6ad60d78b315 428 wlan_connect(char *ssid, long ssid_len)
dflet 0:6ad60d78b315 429 {
dflet 0:6ad60d78b315 430 long ret;
dflet 0:6ad60d78b315 431 unsigned char *ptr;
dflet 0:6ad60d78b315 432 unsigned char *args;
dflet 0:6ad60d78b315 433 unsigned char bssid_zero[] = {0, 0, 0, 0, 0, 0};
dflet 0:6ad60d78b315 434
dflet 0:6ad60d78b315 435 ret = EFAIL;
dflet 0:6ad60d78b315 436 ptr = tSLInformation.pucTxCommandBuffer;
dflet 0:6ad60d78b315 437 args = (ptr + HEADERS_SIZE_CMD);
dflet 0:6ad60d78b315 438
dflet 0:6ad60d78b315 439 // Fill in command buffer
dflet 0:6ad60d78b315 440 args = UINT32_TO_STREAM(args, 0x0000001c);
dflet 0:6ad60d78b315 441 args = UINT32_TO_STREAM(args, ssid_len);
dflet 0:6ad60d78b315 442 args = UINT32_TO_STREAM(args, 0);
dflet 0:6ad60d78b315 443 args = UINT32_TO_STREAM(args, 0x00000010 + ssid_len);
dflet 0:6ad60d78b315 444 args = UINT32_TO_STREAM(args, 0);
dflet 0:6ad60d78b315 445 args = UINT16_TO_STREAM(args, 0);
dflet 0:6ad60d78b315 446
dflet 0:6ad60d78b315 447 // padding shall be zeroed
dflet 0:6ad60d78b315 448 ARRAY_TO_STREAM(args, bssid_zero, ETH_ALEN);
dflet 0:6ad60d78b315 449 ARRAY_TO_STREAM(args, ssid, ssid_len);
dflet 0:6ad60d78b315 450
dflet 0:6ad60d78b315 451 // Initiate a HCI command
dflet 0:6ad60d78b315 452 hci_command_send(HCI_CMND_WLAN_CONNECT, ptr, WLAN_CONNECT_PARAM_LEN +
dflet 0:6ad60d78b315 453 ssid_len - 1);
dflet 0:6ad60d78b315 454
dflet 0:6ad60d78b315 455 // Wait for command complete event
dflet 0:6ad60d78b315 456 SimpleLinkWaitEvent(HCI_CMND_WLAN_CONNECT, &ret);
dflet 0:6ad60d78b315 457 errno = ret;
dflet 0:6ad60d78b315 458
dflet 0:6ad60d78b315 459 return(ret);
dflet 0:6ad60d78b315 460 }
dflet 0:6ad60d78b315 461 #endif
dflet 0:6ad60d78b315 462
dflet 0:6ad60d78b315 463 //*****************************************************************************
dflet 0:6ad60d78b315 464 //
dflet 0:6ad60d78b315 465 //! wlan_disconnect
dflet 0:6ad60d78b315 466 //!
dflet 0:6ad60d78b315 467 //! @return 0 disconnected done, other CC3000 already disconnected
dflet 0:6ad60d78b315 468 //!
dflet 0:6ad60d78b315 469 //! @brief Disconnect connection from AP.
dflet 0:6ad60d78b315 470 //!
dflet 0:6ad60d78b315 471 //! @sa wlan_connect
dflet 0:6ad60d78b315 472 //
dflet 0:6ad60d78b315 473 //*****************************************************************************
dflet 0:6ad60d78b315 474
dflet 0:6ad60d78b315 475 long
dflet 0:6ad60d78b315 476 wlan_disconnect()
dflet 0:6ad60d78b315 477 {
dflet 0:6ad60d78b315 478 long ret;
dflet 0:6ad60d78b315 479 unsigned char *ptr;
dflet 0:6ad60d78b315 480
dflet 0:6ad60d78b315 481 ret = EFAIL;
dflet 0:6ad60d78b315 482 ptr = tSLInformation.pucTxCommandBuffer;
dflet 0:6ad60d78b315 483
dflet 0:6ad60d78b315 484 hci_command_send(HCI_CMND_WLAN_DISCONNECT, ptr, 0);
dflet 0:6ad60d78b315 485
dflet 0:6ad60d78b315 486 // Wait for command complete event
dflet 0:6ad60d78b315 487 SimpleLinkWaitEvent(HCI_CMND_WLAN_DISCONNECT, &ret);
dflet 0:6ad60d78b315 488 errno = ret;
dflet 0:6ad60d78b315 489
dflet 0:6ad60d78b315 490 return(ret);
dflet 0:6ad60d78b315 491 }
dflet 0:6ad60d78b315 492
dflet 0:6ad60d78b315 493 //*****************************************************************************
dflet 0:6ad60d78b315 494 //
dflet 0:6ad60d78b315 495 //! wlan_ioctl_set_connection_policy
dflet 0:6ad60d78b315 496 //!
dflet 0:6ad60d78b315 497 //! @param should_connect_to_open_ap enable(1), disable(0) connect to any
dflet 0:6ad60d78b315 498 //! available AP. This parameter corresponds to the configuration of
dflet 0:6ad60d78b315 499 //! item # 3 in the brief description.
dflet 0:6ad60d78b315 500 //! @param should_use_fast_connect enable(1), disable(0). if enabled, tries
dflet 0:6ad60d78b315 501 //! to connect to the last connected AP. This parameter corresponds
dflet 0:6ad60d78b315 502 //! to the configuration of item # 1 in the brief description.
dflet 0:6ad60d78b315 503 //! @param auto_start enable(1), disable(0) auto connect
dflet 0:6ad60d78b315 504 //! after reset and periodically reconnect if needed. This
dflet 0:6ad60d78b315 505 //! configuration configures option 2 in the above description.
dflet 0:6ad60d78b315 506 //!
dflet 0:6ad60d78b315 507 //! @return On success, zero is returned. On error, -1 is returned
dflet 0:6ad60d78b315 508 //!
dflet 0:6ad60d78b315 509 //! @brief When auto is enabled, the device tries to connect according
dflet 0:6ad60d78b315 510 //! the following policy:
dflet 0:6ad60d78b315 511 //! 1) If fast connect is enabled and last connection is valid,
dflet 0:6ad60d78b315 512 //! the device will try to connect to it without the scanning
dflet 0:6ad60d78b315 513 //! procedure (fast). The last connection will be marked as
dflet 0:6ad60d78b315 514 //! invalid, due to adding/removing profile.
dflet 0:6ad60d78b315 515 //! 2) If profile exists, the device will try to connect it
dflet 0:6ad60d78b315 516 //! (Up to seven profiles).
dflet 0:6ad60d78b315 517 //! 3) If fast and profiles are not found, and open mode is
dflet 0:6ad60d78b315 518 //! enabled, the device will try to connect to any AP.
dflet 0:6ad60d78b315 519 //! * Note that the policy settings are stored in the CC3000 NVMEM.
dflet 0:6ad60d78b315 520 //!
dflet 0:6ad60d78b315 521 //! @sa wlan_add_profile , wlan_ioctl_del_profile
dflet 0:6ad60d78b315 522 //
dflet 0:6ad60d78b315 523 //*****************************************************************************
dflet 0:6ad60d78b315 524
dflet 0:6ad60d78b315 525 long
dflet 0:6ad60d78b315 526 wlan_ioctl_set_connection_policy(unsigned long should_connect_to_open_ap,
dflet 0:6ad60d78b315 527 unsigned long ulShouldUseFastConnect,
dflet 0:6ad60d78b315 528 unsigned long ulUseProfiles)
dflet 0:6ad60d78b315 529 {
dflet 0:6ad60d78b315 530 long ret;
dflet 0:6ad60d78b315 531 unsigned char *ptr;
dflet 0:6ad60d78b315 532 unsigned char *args;
dflet 0:6ad60d78b315 533
dflet 0:6ad60d78b315 534 ret = EFAIL;
dflet 0:6ad60d78b315 535 ptr = tSLInformation.pucTxCommandBuffer;
dflet 0:6ad60d78b315 536 args = (unsigned char *)(ptr + HEADERS_SIZE_CMD);
dflet 0:6ad60d78b315 537
dflet 0:6ad60d78b315 538 // Fill in HCI packet structure
dflet 0:6ad60d78b315 539 args = UINT32_TO_STREAM(args, should_connect_to_open_ap);
dflet 0:6ad60d78b315 540 args = UINT32_TO_STREAM(args, ulShouldUseFastConnect);
dflet 0:6ad60d78b315 541 args = UINT32_TO_STREAM(args, ulUseProfiles);
dflet 0:6ad60d78b315 542
dflet 0:6ad60d78b315 543 // Initiate a HCI command
dflet 0:6ad60d78b315 544 hci_command_send(HCI_CMND_WLAN_IOCTL_SET_CONNECTION_POLICY,
dflet 0:6ad60d78b315 545 ptr, WLAN_SET_CONNECTION_POLICY_PARAMS_LEN);
dflet 0:6ad60d78b315 546
dflet 0:6ad60d78b315 547 // Wait for command complete event
dflet 0:6ad60d78b315 548 SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_SET_CONNECTION_POLICY, &ret);
dflet 0:6ad60d78b315 549
dflet 0:6ad60d78b315 550 return(ret);
dflet 0:6ad60d78b315 551 }
dflet 0:6ad60d78b315 552
dflet 0:6ad60d78b315 553 //*****************************************************************************
dflet 0:6ad60d78b315 554 //
dflet 0:6ad60d78b315 555 //! wlan_add_profile
dflet 0:6ad60d78b315 556 //!
dflet 0:6ad60d78b315 557 //! @param ulSecType WLAN_SEC_UNSEC,WLAN_SEC_WEP,WLAN_SEC_WPA,WLAN_SEC_WPA2
dflet 0:6ad60d78b315 558 //! @param ucSsid ssid SSID up to 32 bytes
dflet 0:6ad60d78b315 559 //! @param ulSsidLen ssid length
dflet 0:6ad60d78b315 560 //! @param ucBssid bssid 6 bytes
dflet 0:6ad60d78b315 561 //! @param ulPriority ulPriority profile priority. Lowest priority:0.
dflet 0:6ad60d78b315 562 //! @param ulPairwiseCipher_Or_TxKeyLen key length for WEP security
dflet 0:6ad60d78b315 563 //! @param ulGroupCipher_TxKeyIndex key index
dflet 0:6ad60d78b315 564 //! @param ulKeyMgmt KEY management
dflet 0:6ad60d78b315 565 //! @param ucPf_OrKey security key
dflet 0:6ad60d78b315 566 //! @param ulPassPhraseLen security key length for WPA\WPA2
dflet 0:6ad60d78b315 567 //!
dflet 0:6ad60d78b315 568 //! @return On success, zero is returned. On error, -1 is returned
dflet 0:6ad60d78b315 569 //!
dflet 0:6ad60d78b315 570 //! @brief When auto start is enabled, the device connects to
dflet 0:6ad60d78b315 571 //! station from the profiles table. Up to 7 profiles are supported.
dflet 0:6ad60d78b315 572 //! If several profiles configured the device choose the highest
dflet 0:6ad60d78b315 573 //! priority profile, within each priority group, device will choose
dflet 0:6ad60d78b315 574 //! profile based on security policy, signal strength, etc
dflet 0:6ad60d78b315 575 //! parameters. All the profiles are stored in CC3000 NVMEM.
dflet 0:6ad60d78b315 576 //!
dflet 0:6ad60d78b315 577 //! @sa wlan_ioctl_del_profile
dflet 0:6ad60d78b315 578 //
dflet 0:6ad60d78b315 579 //*****************************************************************************
dflet 0:6ad60d78b315 580
dflet 0:6ad60d78b315 581 #ifndef CC3000_TINY_DRIVER
dflet 0:6ad60d78b315 582 long
dflet 0:6ad60d78b315 583 wlan_add_profile(unsigned long ulSecType,
dflet 0:6ad60d78b315 584 unsigned char* ucSsid,
dflet 0:6ad60d78b315 585 unsigned long ulSsidLen,
dflet 0:6ad60d78b315 586 unsigned char *ucBssid,
dflet 0:6ad60d78b315 587 unsigned long ulPriority,
dflet 0:6ad60d78b315 588 unsigned long ulPairwiseCipher_Or_TxKeyLen,
dflet 0:6ad60d78b315 589 unsigned long ulGroupCipher_TxKeyIndex,
dflet 0:6ad60d78b315 590 unsigned long ulKeyMgmt,
dflet 0:6ad60d78b315 591 unsigned char* ucPf_OrKey,
dflet 0:6ad60d78b315 592 unsigned long ulPassPhraseLen)
dflet 0:6ad60d78b315 593 {
dflet 0:6ad60d78b315 594 unsigned short arg_len;
dflet 0:6ad60d78b315 595 long ret;
dflet 0:6ad60d78b315 596 unsigned char *ptr;
dflet 0:6ad60d78b315 597 long i = 0;
dflet 0:6ad60d78b315 598 unsigned char *args;
dflet 0:6ad60d78b315 599 unsigned char bssid_zero[] = {0, 0, 0, 0, 0, 0};
dflet 0:6ad60d78b315 600
dflet 0:6ad60d78b315 601 ptr = tSLInformation.pucTxCommandBuffer;
dflet 0:6ad60d78b315 602 args = (ptr + HEADERS_SIZE_CMD);
dflet 0:6ad60d78b315 603
dflet 0:6ad60d78b315 604 args = UINT32_TO_STREAM(args, ulSecType);
dflet 0:6ad60d78b315 605
dflet 0:6ad60d78b315 606 // Setup arguments in accordance with the security type
dflet 0:6ad60d78b315 607 switch (ulSecType)
dflet 0:6ad60d78b315 608 {
dflet 0:6ad60d78b315 609 //OPEN
dflet 0:6ad60d78b315 610 case WLAN_SEC_UNSEC:
dflet 0:6ad60d78b315 611 {
dflet 0:6ad60d78b315 612 args = UINT32_TO_STREAM(args, 0x00000014);
dflet 0:6ad60d78b315 613 args = UINT32_TO_STREAM(args, ulSsidLen);
dflet 0:6ad60d78b315 614 args = UINT16_TO_STREAM(args, 0);
dflet 0:6ad60d78b315 615 if(ucBssid)
dflet 0:6ad60d78b315 616 {
dflet 0:6ad60d78b315 617 ARRAY_TO_STREAM(args, ucBssid, ETH_ALEN);
dflet 0:6ad60d78b315 618 }
dflet 0:6ad60d78b315 619 else
dflet 0:6ad60d78b315 620 {
dflet 0:6ad60d78b315 621 ARRAY_TO_STREAM(args, bssid_zero, ETH_ALEN);
dflet 0:6ad60d78b315 622 }
dflet 0:6ad60d78b315 623 args = UINT32_TO_STREAM(args, ulPriority);
dflet 0:6ad60d78b315 624 ARRAY_TO_STREAM(args, ucSsid, ulSsidLen);
dflet 0:6ad60d78b315 625
dflet 0:6ad60d78b315 626 arg_len = WLAN_ADD_PROFILE_NOSEC_PARAM_LEN + ulSsidLen;
dflet 0:6ad60d78b315 627 }
dflet 0:6ad60d78b315 628 break;
dflet 0:6ad60d78b315 629
dflet 0:6ad60d78b315 630 //WEP
dflet 0:6ad60d78b315 631 case WLAN_SEC_WEP:
dflet 0:6ad60d78b315 632 {
dflet 0:6ad60d78b315 633 args = UINT32_TO_STREAM(args, 0x00000020);
dflet 0:6ad60d78b315 634 args = UINT32_TO_STREAM(args, ulSsidLen);
dflet 0:6ad60d78b315 635 args = UINT16_TO_STREAM(args, 0);
dflet 0:6ad60d78b315 636 if(ucBssid)
dflet 0:6ad60d78b315 637 {
dflet 0:6ad60d78b315 638 ARRAY_TO_STREAM(args, ucBssid, ETH_ALEN);
dflet 0:6ad60d78b315 639 }
dflet 0:6ad60d78b315 640 else
dflet 0:6ad60d78b315 641 {
dflet 0:6ad60d78b315 642 ARRAY_TO_STREAM(args, bssid_zero, ETH_ALEN);
dflet 0:6ad60d78b315 643 }
dflet 0:6ad60d78b315 644 args = UINT32_TO_STREAM(args, ulPriority);
dflet 0:6ad60d78b315 645 args = UINT32_TO_STREAM(args, 0x0000000C + ulSsidLen);
dflet 0:6ad60d78b315 646 args = UINT32_TO_STREAM(args, ulPairwiseCipher_Or_TxKeyLen);
dflet 0:6ad60d78b315 647 args = UINT32_TO_STREAM(args, ulGroupCipher_TxKeyIndex);
dflet 0:6ad60d78b315 648 ARRAY_TO_STREAM(args, ucSsid, ulSsidLen);
dflet 0:6ad60d78b315 649
dflet 0:6ad60d78b315 650 for(i = 0; i < 4; i++)
dflet 0:6ad60d78b315 651 {
dflet 0:6ad60d78b315 652 unsigned char *p = &ucPf_OrKey[i * ulPairwiseCipher_Or_TxKeyLen];
dflet 0:6ad60d78b315 653
dflet 0:6ad60d78b315 654 ARRAY_TO_STREAM(args, p, ulPairwiseCipher_Or_TxKeyLen);
dflet 0:6ad60d78b315 655 }
dflet 0:6ad60d78b315 656
dflet 0:6ad60d78b315 657 arg_len = WLAN_ADD_PROFILE_WEP_PARAM_LEN + ulSsidLen +
dflet 0:6ad60d78b315 658 ulPairwiseCipher_Or_TxKeyLen * 4;
dflet 0:6ad60d78b315 659
dflet 0:6ad60d78b315 660 }
dflet 0:6ad60d78b315 661 break;
dflet 0:6ad60d78b315 662
dflet 0:6ad60d78b315 663 //WPA
dflet 0:6ad60d78b315 664 //WPA2
dflet 0:6ad60d78b315 665 case WLAN_SEC_WPA:
dflet 0:6ad60d78b315 666 case WLAN_SEC_WPA2:
dflet 0:6ad60d78b315 667 {
dflet 0:6ad60d78b315 668 args = UINT32_TO_STREAM(args, 0x00000028);
dflet 0:6ad60d78b315 669 args = UINT32_TO_STREAM(args, ulSsidLen);
dflet 0:6ad60d78b315 670 args = UINT16_TO_STREAM(args, 0);
dflet 0:6ad60d78b315 671 if(ucBssid)
dflet 0:6ad60d78b315 672 {
dflet 0:6ad60d78b315 673 ARRAY_TO_STREAM(args, ucBssid, ETH_ALEN);
dflet 0:6ad60d78b315 674 }
dflet 0:6ad60d78b315 675 else
dflet 0:6ad60d78b315 676 {
dflet 0:6ad60d78b315 677 ARRAY_TO_STREAM(args, bssid_zero, ETH_ALEN);
dflet 0:6ad60d78b315 678 }
dflet 0:6ad60d78b315 679 args = UINT32_TO_STREAM(args, ulPriority);
dflet 0:6ad60d78b315 680 args = UINT32_TO_STREAM(args, ulPairwiseCipher_Or_TxKeyLen);
dflet 0:6ad60d78b315 681 args = UINT32_TO_STREAM(args, ulGroupCipher_TxKeyIndex);
dflet 0:6ad60d78b315 682 args = UINT32_TO_STREAM(args, ulKeyMgmt);
dflet 0:6ad60d78b315 683 args = UINT32_TO_STREAM(args, 0x00000008 + ulSsidLen);
dflet 0:6ad60d78b315 684 args = UINT32_TO_STREAM(args, ulPassPhraseLen);
dflet 0:6ad60d78b315 685 ARRAY_TO_STREAM(args, ucSsid, ulSsidLen);
dflet 0:6ad60d78b315 686 ARRAY_TO_STREAM(args, ucPf_OrKey, ulPassPhraseLen);
dflet 0:6ad60d78b315 687
dflet 0:6ad60d78b315 688 arg_len = WLAN_ADD_PROFILE_WPA_PARAM_LEN + ulSsidLen + ulPassPhraseLen;
dflet 0:6ad60d78b315 689 }
dflet 0:6ad60d78b315 690
dflet 0:6ad60d78b315 691 break;
dflet 0:6ad60d78b315 692 }
dflet 0:6ad60d78b315 693
dflet 0:6ad60d78b315 694 // Initiate a HCI command
dflet 0:6ad60d78b315 695 hci_command_send(HCI_CMND_WLAN_IOCTL_ADD_PROFILE,
dflet 0:6ad60d78b315 696 ptr, arg_len);
dflet 0:6ad60d78b315 697
dflet 0:6ad60d78b315 698 // Wait for command complete event
dflet 0:6ad60d78b315 699 SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_ADD_PROFILE, &ret);
dflet 0:6ad60d78b315 700
dflet 0:6ad60d78b315 701 return(ret);
dflet 0:6ad60d78b315 702 }
dflet 0:6ad60d78b315 703 #else
dflet 0:6ad60d78b315 704 long
dflet 0:6ad60d78b315 705 wlan_add_profile(unsigned long ulSecType,
dflet 0:6ad60d78b315 706 unsigned char* ucSsid,
dflet 0:6ad60d78b315 707 unsigned long ulSsidLen,
dflet 0:6ad60d78b315 708 unsigned char *ucBssid,
dflet 0:6ad60d78b315 709 unsigned long ulPriority,
dflet 0:6ad60d78b315 710 unsigned long ulPairwiseCipher_Or_TxKeyLen,
dflet 0:6ad60d78b315 711 unsigned long ulGroupCipher_TxKeyIndex,
dflet 0:6ad60d78b315 712 unsigned long ulKeyMgmt,
dflet 0:6ad60d78b315 713 unsigned char* ucPf_OrKey,
dflet 0:6ad60d78b315 714 unsigned long ulPassPhraseLen)
dflet 0:6ad60d78b315 715 {
dflet 0:6ad60d78b315 716 return -1;
dflet 0:6ad60d78b315 717 }
dflet 0:6ad60d78b315 718 #endif
dflet 0:6ad60d78b315 719
dflet 0:6ad60d78b315 720 //*****************************************************************************
dflet 0:6ad60d78b315 721 //
dflet 0:6ad60d78b315 722 //! wlan_ioctl_del_profile
dflet 0:6ad60d78b315 723 //!
dflet 0:6ad60d78b315 724 //! @param index number of profile to delete
dflet 0:6ad60d78b315 725 //!
dflet 0:6ad60d78b315 726 //! @return On success, zero is returned. On error, -1 is returned
dflet 0:6ad60d78b315 727 //!
dflet 0:6ad60d78b315 728 //! @brief Delete WLAN profile
dflet 0:6ad60d78b315 729 //!
dflet 0:6ad60d78b315 730 //! @Note In order to delete all stored profile, set index to 255.
dflet 0:6ad60d78b315 731 //!
dflet 0:6ad60d78b315 732 //! @sa wlan_add_profile
dflet 0:6ad60d78b315 733 //
dflet 0:6ad60d78b315 734 //*****************************************************************************
dflet 0:6ad60d78b315 735
dflet 0:6ad60d78b315 736 long
dflet 0:6ad60d78b315 737 wlan_ioctl_del_profile(unsigned long ulIndex)
dflet 0:6ad60d78b315 738 {
dflet 0:6ad60d78b315 739 long ret;
dflet 0:6ad60d78b315 740 unsigned char *ptr;
dflet 0:6ad60d78b315 741 unsigned char *args;
dflet 0:6ad60d78b315 742
dflet 0:6ad60d78b315 743 ptr = tSLInformation.pucTxCommandBuffer;
dflet 0:6ad60d78b315 744 args = (unsigned char *)(ptr + HEADERS_SIZE_CMD);
dflet 0:6ad60d78b315 745
dflet 0:6ad60d78b315 746 // Fill in HCI packet structure
dflet 0:6ad60d78b315 747 args = UINT32_TO_STREAM(args, ulIndex);
dflet 0:6ad60d78b315 748 ret = EFAIL;
dflet 0:6ad60d78b315 749
dflet 0:6ad60d78b315 750 // Initiate a HCI command
dflet 0:6ad60d78b315 751 hci_command_send(HCI_CMND_WLAN_IOCTL_DEL_PROFILE,
dflet 0:6ad60d78b315 752 ptr, WLAN_DEL_PROFILE_PARAMS_LEN);
dflet 0:6ad60d78b315 753
dflet 0:6ad60d78b315 754 // Wait for command complete event
dflet 0:6ad60d78b315 755 SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_DEL_PROFILE, &ret);
dflet 0:6ad60d78b315 756
dflet 0:6ad60d78b315 757 return(ret);
dflet 0:6ad60d78b315 758 }
dflet 0:6ad60d78b315 759
dflet 0:6ad60d78b315 760 //*****************************************************************************
dflet 0:6ad60d78b315 761 //
dflet 0:6ad60d78b315 762 //! wlan_ioctl_get_scan_results
dflet 0:6ad60d78b315 763 //!
dflet 0:6ad60d78b315 764 //! @param[in] scan_timeout parameter not supported
dflet 0:6ad60d78b315 765 //! @param[out] ucResults scan results (_wlan_full_scan_results_args_t)
dflet 0:6ad60d78b315 766 //!
dflet 0:6ad60d78b315 767 //! @return On success, zero is returned. On error, -1 is returned
dflet 0:6ad60d78b315 768 //!
dflet 0:6ad60d78b315 769 //! @brief Gets entry from scan result table.
dflet 0:6ad60d78b315 770 //! The scan results are returned one by one, and each entry
dflet 0:6ad60d78b315 771 //! represents a single AP found in the area. The following is a
dflet 0:6ad60d78b315 772 //! format of the scan result:
dflet 0:6ad60d78b315 773 //! - 4 Bytes: number of networks found
dflet 0:6ad60d78b315 774 //! - 4 Bytes: The status of the scan: 0 - aged results,
dflet 0:6ad60d78b315 775 //! 1 - results valid, 2 - no results
dflet 0:6ad60d78b315 776 //! - 42 bytes: Result entry, where the bytes are arranged as follows:
dflet 0:6ad60d78b315 777 //!
dflet 0:6ad60d78b315 778 //! - 1 bit isValid - is result valid or not
dflet 0:6ad60d78b315 779 //! - 7 bits rssi - RSSI value;
dflet 0:6ad60d78b315 780 //! - 2 bits: securityMode - security mode of the AP:
dflet 0:6ad60d78b315 781 //! 0 - Open, 1 - WEP, 2 WPA, 3 WPA2
dflet 0:6ad60d78b315 782 //! - 6 bits: SSID name length
dflet 0:6ad60d78b315 783 //! - 2 bytes: the time at which the entry has entered into
dflet 0:6ad60d78b315 784 //! scans result table
dflet 0:6ad60d78b315 785 //! - 32 bytes: SSID name
dflet 0:6ad60d78b315 786 //! - 6 bytes: BSSID
dflet 0:6ad60d78b315 787 //!
dflet 0:6ad60d78b315 788 //! @Note scan_timeout, is not supported on this version.
dflet 0:6ad60d78b315 789 //!
dflet 0:6ad60d78b315 790 //! @sa wlan_ioctl_set_scan_params
dflet 0:6ad60d78b315 791 //
dflet 0:6ad60d78b315 792 //*****************************************************************************
dflet 0:6ad60d78b315 793
dflet 0:6ad60d78b315 794 #ifndef CC3000_TINY_DRIVER
dflet 0:6ad60d78b315 795 long
dflet 0:6ad60d78b315 796 wlan_ioctl_get_scan_results(unsigned long ulScanTimeout,
dflet 0:6ad60d78b315 797 unsigned char *ucResults)
dflet 0:6ad60d78b315 798 {
dflet 0:6ad60d78b315 799 unsigned char *ptr;
dflet 0:6ad60d78b315 800 unsigned char *args;
dflet 0:6ad60d78b315 801
dflet 0:6ad60d78b315 802 ptr = tSLInformation.pucTxCommandBuffer;
dflet 0:6ad60d78b315 803 args = (ptr + HEADERS_SIZE_CMD);
dflet 0:6ad60d78b315 804
dflet 0:6ad60d78b315 805 // Fill in temporary command buffer
dflet 0:6ad60d78b315 806 args = UINT32_TO_STREAM(args, ulScanTimeout);
dflet 0:6ad60d78b315 807
dflet 0:6ad60d78b315 808 // Initiate a HCI command
dflet 0:6ad60d78b315 809 hci_command_send(HCI_CMND_WLAN_IOCTL_GET_SCAN_RESULTS,
dflet 0:6ad60d78b315 810 ptr, WLAN_GET_SCAN_RESULTS_PARAMS_LEN);
dflet 0:6ad60d78b315 811
dflet 0:6ad60d78b315 812 // Wait for command complete event
dflet 0:6ad60d78b315 813 SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_GET_SCAN_RESULTS, ucResults);
dflet 0:6ad60d78b315 814
dflet 0:6ad60d78b315 815 return(0);
dflet 0:6ad60d78b315 816 }
dflet 0:6ad60d78b315 817 #endif
dflet 0:6ad60d78b315 818
dflet 0:6ad60d78b315 819 //*****************************************************************************
dflet 0:6ad60d78b315 820 //
dflet 0:6ad60d78b315 821 //! wlan_ioctl_set_scan_params
dflet 0:6ad60d78b315 822 //!
dflet 0:6ad60d78b315 823 //! @param uiEnable - start/stop application scan:
dflet 0:6ad60d78b315 824 //! 1 = start scan with default interval value of 10 min.
dflet 0:6ad60d78b315 825 //! in order to set a different scan interval value apply the value
dflet 0:6ad60d78b315 826 //! in milliseconds. minimum 1 second. 0=stop). Wlan reset
dflet 0:6ad60d78b315 827 //! (wlan_stop() wlan_start()) is needed when changing scan interval
dflet 0:6ad60d78b315 828 //! value. Saved: No
dflet 0:6ad60d78b315 829 //! @param uiMinDwellTime minimum dwell time value to be used for each
dflet 0:6ad60d78b315 830 //! channel, in milliseconds. Saved: yes
dflet 0:6ad60d78b315 831 //! Recommended Value: 100 (Default: 20)
dflet 0:6ad60d78b315 832 //! @param uiMaxDwellTime maximum dwell time value to be used for each
dflet 0:6ad60d78b315 833 //! channel, in milliseconds. Saved: yes
dflet 0:6ad60d78b315 834 //! Recommended Value: 100 (Default: 30)
dflet 0:6ad60d78b315 835 //! @param uiNumOfProbeRequests max probe request between dwell time.
dflet 0:6ad60d78b315 836 //! Saved: yes. Recommended Value: 5 (Default:2)
dflet 0:6ad60d78b315 837 //! @param uiChannelMask bitwise, up to 13 channels (0x1fff).
dflet 0:6ad60d78b315 838 //! Saved: yes. Default: 0x7ff
dflet 0:6ad60d78b315 839 //! @param uiRSSIThreshold RSSI threshold. Saved: yes (Default: -80)
dflet 0:6ad60d78b315 840 //! @param uiSNRThreshold NSR threshold. Saved: yes (Default: 0)
dflet 0:6ad60d78b315 841 //! @param uiDefaultTxPower probe Tx power. Saved: yes (Default: 205)
dflet 0:6ad60d78b315 842 //! @param aiIntervalList pointer to array with 16 entries (16 channels)
dflet 0:6ad60d78b315 843 //! each entry (unsigned long) holds timeout between periodic scan
dflet 0:6ad60d78b315 844 //! (connection scan) - in millisecond. Saved: yes. Default 2000ms.
dflet 0:6ad60d78b315 845 //!
dflet 0:6ad60d78b315 846 //! @return On success, zero is returned. On error, -1 is returned
dflet 0:6ad60d78b315 847 //!
dflet 0:6ad60d78b315 848 //! @brief start and stop scan procedure. Set scan parameters.
dflet 0:6ad60d78b315 849 //!
dflet 0:6ad60d78b315 850 //! @Note uiDefaultTxPower, is not supported on this version.
dflet 0:6ad60d78b315 851 //!
dflet 0:6ad60d78b315 852 //! @sa wlan_ioctl_get_scan_results
dflet 0:6ad60d78b315 853 //
dflet 0:6ad60d78b315 854 //*****************************************************************************
dflet 0:6ad60d78b315 855
dflet 0:6ad60d78b315 856 #ifndef CC3000_TINY_DRIVER
dflet 0:6ad60d78b315 857 long
dflet 0:6ad60d78b315 858 wlan_ioctl_set_scan_params(unsigned long uiEnable, unsigned long uiMinDwellTime,
dflet 0:6ad60d78b315 859 unsigned long uiMaxDwellTime,
dflet 0:6ad60d78b315 860 unsigned long uiNumOfProbeRequests,
dflet 0:6ad60d78b315 861 unsigned long uiChannelMask,long iRSSIThreshold,
dflet 0:6ad60d78b315 862 unsigned long uiSNRThreshold,
dflet 0:6ad60d78b315 863 unsigned long uiDefaultTxPower,
dflet 0:6ad60d78b315 864 unsigned long *aiIntervalList)
dflet 0:6ad60d78b315 865 {
dflet 0:6ad60d78b315 866 unsigned long uiRes;
dflet 0:6ad60d78b315 867 unsigned char *ptr;
dflet 0:6ad60d78b315 868 unsigned char *args;
dflet 0:6ad60d78b315 869
dflet 0:6ad60d78b315 870 ptr = tSLInformation.pucTxCommandBuffer;
dflet 0:6ad60d78b315 871 args = (ptr + HEADERS_SIZE_CMD);
dflet 0:6ad60d78b315 872
dflet 0:6ad60d78b315 873 // Fill in temporary command buffer
dflet 0:6ad60d78b315 874 args = UINT32_TO_STREAM(args, 36);
dflet 0:6ad60d78b315 875 args = UINT32_TO_STREAM(args, uiEnable);
dflet 0:6ad60d78b315 876 args = UINT32_TO_STREAM(args, uiMinDwellTime);
dflet 0:6ad60d78b315 877 args = UINT32_TO_STREAM(args, uiMaxDwellTime);
dflet 0:6ad60d78b315 878 args = UINT32_TO_STREAM(args, uiNumOfProbeRequests);
dflet 0:6ad60d78b315 879 args = UINT32_TO_STREAM(args, uiChannelMask);
dflet 0:6ad60d78b315 880 args = UINT32_TO_STREAM(args, iRSSIThreshold);
dflet 0:6ad60d78b315 881 args = UINT32_TO_STREAM(args, uiSNRThreshold);
dflet 0:6ad60d78b315 882 args = UINT32_TO_STREAM(args, uiDefaultTxPower);
dflet 0:6ad60d78b315 883 ARRAY_TO_STREAM(args, aiIntervalList, sizeof(unsigned long) *
dflet 0:6ad60d78b315 884 SL_SET_SCAN_PARAMS_INTERVAL_LIST_SIZE);
dflet 0:6ad60d78b315 885
dflet 0:6ad60d78b315 886 // Initiate a HCI command
dflet 0:6ad60d78b315 887 hci_command_send(HCI_CMND_WLAN_IOCTL_SET_SCANPARAM,
dflet 0:6ad60d78b315 888 ptr, WLAN_SET_SCAN_PARAMS_LEN);
dflet 0:6ad60d78b315 889
dflet 0:6ad60d78b315 890 // Wait for command complete event
dflet 0:6ad60d78b315 891 SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_SET_SCANPARAM, &uiRes);
dflet 0:6ad60d78b315 892
dflet 0:6ad60d78b315 893 return(uiRes);
dflet 0:6ad60d78b315 894 }
dflet 0:6ad60d78b315 895 #endif
dflet 0:6ad60d78b315 896
dflet 0:6ad60d78b315 897 //*****************************************************************************
dflet 0:6ad60d78b315 898 //
dflet 0:6ad60d78b315 899 //! wlan_set_event_mask
dflet 0:6ad60d78b315 900 //!
dflet 0:6ad60d78b315 901 //! @param mask mask option:
dflet 0:6ad60d78b315 902 //! HCI_EVNT_WLAN_UNSOL_CONNECT connect event
dflet 0:6ad60d78b315 903 //! HCI_EVNT_WLAN_UNSOL_DISCONNECT disconnect event
dflet 0:6ad60d78b315 904 //! HCI_EVNT_WLAN_ASYNC_SIMPLE_CONFIG_DONE smart config done
dflet 0:6ad60d78b315 905 //! HCI_EVNT_WLAN_UNSOL_INIT init done
dflet 0:6ad60d78b315 906 //! HCI_EVNT_WLAN_UNSOL_DHCP dhcp event report
dflet 0:6ad60d78b315 907 //! HCI_EVNT_WLAN_ASYNC_PING_REPORT ping report
dflet 0:6ad60d78b315 908 //! HCI_EVNT_WLAN_KEEPALIVE keepalive
dflet 0:6ad60d78b315 909 //! HCI_EVNT_WLAN_TX_COMPLETE - disable information on end of transmission
dflet 0:6ad60d78b315 910 //! Saved: no.
dflet 0:6ad60d78b315 911 //!
dflet 0:6ad60d78b315 912 //! @return On success, zero is returned. On error, -1 is returned
dflet 0:6ad60d78b315 913 //!
dflet 0:6ad60d78b315 914 //! @brief Mask event according to bit mask. In case that event is
dflet 0:6ad60d78b315 915 //! masked (1), the device will not send the masked event to host.
dflet 0:6ad60d78b315 916 //
dflet 0:6ad60d78b315 917 //*****************************************************************************
dflet 0:6ad60d78b315 918
dflet 0:6ad60d78b315 919 long
dflet 0:6ad60d78b315 920 wlan_set_event_mask(unsigned long ulMask)
dflet 0:6ad60d78b315 921 {
dflet 0:6ad60d78b315 922 long ret;
dflet 0:6ad60d78b315 923 unsigned char *ptr;
dflet 0:6ad60d78b315 924 unsigned char *args;
dflet 0:6ad60d78b315 925
dflet 0:6ad60d78b315 926
dflet 0:6ad60d78b315 927 if ((ulMask & HCI_EVNT_WLAN_TX_COMPLETE) == HCI_EVNT_WLAN_TX_COMPLETE)
dflet 0:6ad60d78b315 928 {
dflet 0:6ad60d78b315 929 tSLInformation.InformHostOnTxComplete = 0;
dflet 0:6ad60d78b315 930
dflet 0:6ad60d78b315 931 // Since an event is a virtual event - i.e. it is not coming from CC3000
dflet 0:6ad60d78b315 932 // there is no need to send anything to the device if it was an only event
dflet 0:6ad60d78b315 933 if (ulMask == HCI_EVNT_WLAN_TX_COMPLETE)
dflet 0:6ad60d78b315 934 {
dflet 0:6ad60d78b315 935 return 0;
dflet 0:6ad60d78b315 936 }
dflet 0:6ad60d78b315 937
dflet 0:6ad60d78b315 938 ulMask &= ~HCI_EVNT_WLAN_TX_COMPLETE;
dflet 0:6ad60d78b315 939 ulMask |= HCI_EVNT_WLAN_UNSOL_BASE;
dflet 0:6ad60d78b315 940 }
dflet 0:6ad60d78b315 941 else
dflet 0:6ad60d78b315 942 {
dflet 0:6ad60d78b315 943 tSLInformation.InformHostOnTxComplete = 1;
dflet 0:6ad60d78b315 944 }
dflet 0:6ad60d78b315 945
dflet 0:6ad60d78b315 946 ret = EFAIL;
dflet 0:6ad60d78b315 947 ptr = tSLInformation.pucTxCommandBuffer;
dflet 0:6ad60d78b315 948 args = (unsigned char *)(ptr + HEADERS_SIZE_CMD);
dflet 0:6ad60d78b315 949
dflet 0:6ad60d78b315 950 // Fill in HCI packet structure
dflet 0:6ad60d78b315 951 args = UINT32_TO_STREAM(args, ulMask);
dflet 0:6ad60d78b315 952
dflet 0:6ad60d78b315 953 // Initiate a HCI command
dflet 0:6ad60d78b315 954 hci_command_send(HCI_CMND_EVENT_MASK,
dflet 0:6ad60d78b315 955 ptr, WLAN_SET_MASK_PARAMS_LEN);
dflet 0:6ad60d78b315 956
dflet 0:6ad60d78b315 957 // Wait for command complete event
dflet 0:6ad60d78b315 958 SimpleLinkWaitEvent(HCI_CMND_EVENT_MASK, &ret);
dflet 0:6ad60d78b315 959
dflet 0:6ad60d78b315 960 return(ret);
dflet 0:6ad60d78b315 961 }
dflet 0:6ad60d78b315 962
dflet 0:6ad60d78b315 963 //*****************************************************************************
dflet 0:6ad60d78b315 964 //
dflet 0:6ad60d78b315 965 //! wlan_ioctl_statusget
dflet 0:6ad60d78b315 966 //!
dflet 0:6ad60d78b315 967 //! @param none
dflet 0:6ad60d78b315 968 //!
dflet 0:6ad60d78b315 969 //! @return WLAN_STATUS_DISCONNECTED, WLAN_STATUS_SCANING,
dflet 0:6ad60d78b315 970 //! STATUS_CONNECTING or WLAN_STATUS_CONNECTED
dflet 0:6ad60d78b315 971 //!
dflet 0:6ad60d78b315 972 //! @brief get wlan status: disconnected, scanning, connecting or connected
dflet 0:6ad60d78b315 973 //
dflet 0:6ad60d78b315 974 //*****************************************************************************
dflet 0:6ad60d78b315 975
dflet 0:6ad60d78b315 976 #ifndef CC3000_TINY_DRIVER
dflet 0:6ad60d78b315 977 long
dflet 0:6ad60d78b315 978 wlan_ioctl_statusget(void)
dflet 0:6ad60d78b315 979 {
dflet 0:6ad60d78b315 980 long ret;
dflet 0:6ad60d78b315 981 unsigned char *ptr;
dflet 0:6ad60d78b315 982
dflet 0:6ad60d78b315 983 ret = EFAIL;
dflet 0:6ad60d78b315 984 ptr = tSLInformation.pucTxCommandBuffer;
dflet 0:6ad60d78b315 985
dflet 0:6ad60d78b315 986 hci_command_send(HCI_CMND_WLAN_IOCTL_STATUSGET,
dflet 0:6ad60d78b315 987 ptr, 0);
dflet 0:6ad60d78b315 988
dflet 0:6ad60d78b315 989 // Wait for command complete event
dflet 0:6ad60d78b315 990 SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_STATUSGET, &ret);
dflet 0:6ad60d78b315 991
dflet 0:6ad60d78b315 992 return(ret);
dflet 0:6ad60d78b315 993 }
dflet 0:6ad60d78b315 994 #endif
dflet 0:6ad60d78b315 995
dflet 0:6ad60d78b315 996 //*****************************************************************************
dflet 0:6ad60d78b315 997 //
dflet 0:6ad60d78b315 998 //! wlan_smart_config_start
dflet 0:6ad60d78b315 999 //!
dflet 0:6ad60d78b315 1000 //! @param algoEncryptedFlag indicates whether the information is encrypted
dflet 0:6ad60d78b315 1001 //!
dflet 0:6ad60d78b315 1002 //! @return On success, zero is returned. On error, -1 is returned
dflet 0:6ad60d78b315 1003 //!
dflet 0:6ad60d78b315 1004 //! @brief Start to acquire device profile. The device acquire its own
dflet 0:6ad60d78b315 1005 //! profile, if profile message is found. The acquired AP information
dflet 0:6ad60d78b315 1006 //! is stored in CC3000 EEPROM only in case AES128 encryption is used.
dflet 0:6ad60d78b315 1007 //! In case AES128 encryption is not used, a profile is created by
dflet 0:6ad60d78b315 1008 //! CC3000 internally.
dflet 0:6ad60d78b315 1009 //!
dflet 0:6ad60d78b315 1010 //! @Note An asynchronous event - Smart Config Done will be generated as soon
dflet 0:6ad60d78b315 1011 //! as the process finishes successfully.
dflet 0:6ad60d78b315 1012 //!
dflet 0:6ad60d78b315 1013 //! @sa wlan_smart_config_set_prefix , wlan_smart_config_stop
dflet 0:6ad60d78b315 1014 //
dflet 0:6ad60d78b315 1015 //*****************************************************************************
dflet 0:6ad60d78b315 1016
dflet 0:6ad60d78b315 1017 long
dflet 0:6ad60d78b315 1018 wlan_smart_config_start(unsigned long algoEncryptedFlag)
dflet 0:6ad60d78b315 1019 {
dflet 0:6ad60d78b315 1020 long ret;
dflet 0:6ad60d78b315 1021 unsigned char *ptr;
dflet 0:6ad60d78b315 1022 unsigned char *args;
dflet 0:6ad60d78b315 1023
dflet 0:6ad60d78b315 1024 ret = EFAIL;
dflet 0:6ad60d78b315 1025 ptr = tSLInformation.pucTxCommandBuffer;
dflet 0:6ad60d78b315 1026 args = (unsigned char *)(ptr + HEADERS_SIZE_CMD);
dflet 0:6ad60d78b315 1027
dflet 0:6ad60d78b315 1028 // Fill in HCI packet structure
dflet 0:6ad60d78b315 1029 args = UINT32_TO_STREAM(args, algoEncryptedFlag);
dflet 0:6ad60d78b315 1030 ret = EFAIL;
dflet 0:6ad60d78b315 1031
dflet 0:6ad60d78b315 1032 hci_command_send(HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_START, ptr,
dflet 0:6ad60d78b315 1033 WLAN_SMART_CONFIG_START_PARAMS_LEN);
dflet 0:6ad60d78b315 1034
dflet 0:6ad60d78b315 1035 // Wait for command complete event
dflet 0:6ad60d78b315 1036 SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_START, &ret);
dflet 0:6ad60d78b315 1037
dflet 0:6ad60d78b315 1038 return(ret);
dflet 0:6ad60d78b315 1039 }
dflet 0:6ad60d78b315 1040
dflet 0:6ad60d78b315 1041 //*****************************************************************************
dflet 0:6ad60d78b315 1042 //
dflet 0:6ad60d78b315 1043 //! wlan_smart_config_stop
dflet 0:6ad60d78b315 1044 //!
dflet 0:6ad60d78b315 1045 //! @param algoEncryptedFlag indicates whether the information is encrypted
dflet 0:6ad60d78b315 1046 //!
dflet 0:6ad60d78b315 1047 //! @return On success, zero is returned. On error, -1 is returned
dflet 0:6ad60d78b315 1048 //!
dflet 0:6ad60d78b315 1049 //! @brief Stop the acquire profile procedure
dflet 0:6ad60d78b315 1050 //!
dflet 0:6ad60d78b315 1051 //! @sa wlan_smart_config_start , wlan_smart_config_set_prefix
dflet 0:6ad60d78b315 1052 //
dflet 0:6ad60d78b315 1053 //*****************************************************************************
dflet 0:6ad60d78b315 1054
dflet 0:6ad60d78b315 1055 long
dflet 0:6ad60d78b315 1056 wlan_smart_config_stop(void)
dflet 0:6ad60d78b315 1057 {
dflet 0:6ad60d78b315 1058 long ret;
dflet 0:6ad60d78b315 1059 unsigned char *ptr;
dflet 0:6ad60d78b315 1060
dflet 0:6ad60d78b315 1061 ret = EFAIL;
dflet 0:6ad60d78b315 1062 ptr = tSLInformation.pucTxCommandBuffer;
dflet 0:6ad60d78b315 1063
dflet 0:6ad60d78b315 1064 hci_command_send(HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_STOP, ptr, 0);
dflet 0:6ad60d78b315 1065
dflet 0:6ad60d78b315 1066 // Wait for command complete event
dflet 0:6ad60d78b315 1067 SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_STOP, &ret);
dflet 0:6ad60d78b315 1068
dflet 0:6ad60d78b315 1069 return(ret);
dflet 0:6ad60d78b315 1070 }
dflet 0:6ad60d78b315 1071
dflet 0:6ad60d78b315 1072 //*****************************************************************************
dflet 0:6ad60d78b315 1073 //
dflet 0:6ad60d78b315 1074 //! wlan_smart_config_set_prefix
dflet 0:6ad60d78b315 1075 //!
dflet 0:6ad60d78b315 1076 //! @param newPrefix 3 bytes identify the SSID prefix for the Smart Config.
dflet 0:6ad60d78b315 1077 //!
dflet 0:6ad60d78b315 1078 //! @return On success, zero is returned. On error, -1 is returned
dflet 0:6ad60d78b315 1079 //!
dflet 0:6ad60d78b315 1080 //! @brief Configure station ssid prefix. The prefix is used internally
dflet 0:6ad60d78b315 1081 //! in CC3000. It should always be TTT.
dflet 0:6ad60d78b315 1082 //!
dflet 0:6ad60d78b315 1083 //! @Note The prefix is stored in CC3000 NVMEM
dflet 0:6ad60d78b315 1084 //!
dflet 0:6ad60d78b315 1085 //! @sa wlan_smart_config_start , wlan_smart_config_stop
dflet 0:6ad60d78b315 1086 //
dflet 0:6ad60d78b315 1087 //*****************************************************************************
dflet 0:6ad60d78b315 1088
dflet 0:6ad60d78b315 1089 long
dflet 0:6ad60d78b315 1090 wlan_smart_config_set_prefix(char* cNewPrefix)
dflet 0:6ad60d78b315 1091 {
dflet 0:6ad60d78b315 1092 long ret;
dflet 0:6ad60d78b315 1093 unsigned char *ptr;
dflet 0:6ad60d78b315 1094 unsigned char *args;
dflet 0:6ad60d78b315 1095
dflet 0:6ad60d78b315 1096 ret = EFAIL;
dflet 0:6ad60d78b315 1097 ptr = tSLInformation.pucTxCommandBuffer;
dflet 0:6ad60d78b315 1098 args = (ptr + HEADERS_SIZE_CMD);
dflet 0:6ad60d78b315 1099
dflet 0:6ad60d78b315 1100 if (cNewPrefix == NULL)
dflet 0:6ad60d78b315 1101 return ret;
dflet 0:6ad60d78b315 1102 else // with the new Smart Config, prefix must be TTT
dflet 0:6ad60d78b315 1103 {
dflet 0:6ad60d78b315 1104 *cNewPrefix = 'T';
dflet 0:6ad60d78b315 1105 *(cNewPrefix + 1) = 'T';
dflet 0:6ad60d78b315 1106 *(cNewPrefix + 2) = 'T';
dflet 0:6ad60d78b315 1107 }
dflet 0:6ad60d78b315 1108
dflet 0:6ad60d78b315 1109 ARRAY_TO_STREAM(args, cNewPrefix, SL_SIMPLE_CONFIG_PREFIX_LENGTH);
dflet 0:6ad60d78b315 1110
dflet 0:6ad60d78b315 1111 hci_command_send(HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_SET_PREFIX, ptr,
dflet 0:6ad60d78b315 1112 SL_SIMPLE_CONFIG_PREFIX_LENGTH);
dflet 0:6ad60d78b315 1113
dflet 0:6ad60d78b315 1114 // Wait for command complete event
dflet 0:6ad60d78b315 1115 SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_SET_PREFIX, &ret);
dflet 0:6ad60d78b315 1116
dflet 0:6ad60d78b315 1117 return(ret);
dflet 0:6ad60d78b315 1118 }
dflet 0:6ad60d78b315 1119
dflet 0:6ad60d78b315 1120 //*****************************************************************************
dflet 0:6ad60d78b315 1121 //
dflet 0:6ad60d78b315 1122 //! wlan_smart_config_process
dflet 0:6ad60d78b315 1123 //!
dflet 0:6ad60d78b315 1124 //! @param none
dflet 0:6ad60d78b315 1125 //!
dflet 0:6ad60d78b315 1126 //! @return On success, zero is returned. On error, -1 is returned
dflet 0:6ad60d78b315 1127 //!
dflet 0:6ad60d78b315 1128 //! @brief process the acquired data and store it as a profile. The acquired
dflet 0:6ad60d78b315 1129 //! AP information is stored in CC3000 EEPROM encrypted.
dflet 0:6ad60d78b315 1130 //! The encrypted data is decrypted and stored as a profile.
dflet 0:6ad60d78b315 1131 //! behavior is as defined by connection policy.
dflet 0:6ad60d78b315 1132 //
dflet 0:6ad60d78b315 1133 //*****************************************************************************
dflet 0:6ad60d78b315 1134
dflet 0:6ad60d78b315 1135
dflet 0:6ad60d78b315 1136 #ifndef CC3000_UNENCRYPTED_SMART_CONFIG
dflet 0:6ad60d78b315 1137 long
dflet 0:6ad60d78b315 1138 wlan_smart_config_process()
dflet 0:6ad60d78b315 1139 {
dflet 0:6ad60d78b315 1140 signed long returnValue;
dflet 0:6ad60d78b315 1141 unsigned long ssidLen, keyLen;
dflet 0:6ad60d78b315 1142 unsigned char *decKeyPtr;
dflet 0:6ad60d78b315 1143 unsigned char *ssidPtr;
dflet 0:6ad60d78b315 1144
dflet 0:6ad60d78b315 1145 // read the key from EEPROM - fileID 12
dflet 0:6ad60d78b315 1146 returnValue = aes_read_key(key);
dflet 0:6ad60d78b315 1147
dflet 0:6ad60d78b315 1148 if (returnValue != 0)
dflet 0:6ad60d78b315 1149 return returnValue;
dflet 0:6ad60d78b315 1150
dflet 0:6ad60d78b315 1151 // read the received data from fileID #13 and parse it according to the followings:
dflet 0:6ad60d78b315 1152 // 1) SSID LEN - not encrypted
dflet 0:6ad60d78b315 1153 // 2) SSID - not encrypted
dflet 0:6ad60d78b315 1154 // 3) KEY LEN - not encrypted. always 32 bytes long
dflet 0:6ad60d78b315 1155 // 4) Security type - not encrypted
dflet 0:6ad60d78b315 1156 // 5) KEY - encrypted together with true key length as the first byte in KEY
dflet 0:6ad60d78b315 1157 // to elaborate, there are two corner cases:
dflet 0:6ad60d78b315 1158 // 1) the KEY is 32 bytes long. In this case, the first byte does not represent KEY length
dflet 0:6ad60d78b315 1159 // 2) the KEY is 31 bytes long. In this case, the first byte represent KEY length and equals 31
dflet 0:6ad60d78b315 1160 returnValue = nvmem_read(NVMEM_SHARED_MEM_FILEID, SMART_CONFIG_PROFILE_SIZE, 0, profileArray);
dflet 0:6ad60d78b315 1161
dflet 0:6ad60d78b315 1162 if (returnValue != 0)
dflet 0:6ad60d78b315 1163 return returnValue;
dflet 0:6ad60d78b315 1164
dflet 0:6ad60d78b315 1165 ssidPtr = &profileArray[1];
dflet 0:6ad60d78b315 1166
dflet 0:6ad60d78b315 1167 ssidLen = profileArray[0];
dflet 0:6ad60d78b315 1168
dflet 0:6ad60d78b315 1169 decKeyPtr = &profileArray[profileArray[0] + 3];
dflet 0:6ad60d78b315 1170
dflet 0:6ad60d78b315 1171 aes_decrypt(decKeyPtr, key);
dflet 0:6ad60d78b315 1172 if (profileArray[profileArray[0] + 1] > 16)
dflet 0:6ad60d78b315 1173 aes_decrypt((unsigned char *)(decKeyPtr + 16), key);
dflet 0:6ad60d78b315 1174
dflet 0:6ad60d78b315 1175 if (*(unsigned char *)(decKeyPtr +31) != 0)
dflet 0:6ad60d78b315 1176 {
dflet 0:6ad60d78b315 1177 if (*decKeyPtr == 31)
dflet 0:6ad60d78b315 1178 {
dflet 0:6ad60d78b315 1179 keyLen = 31;
dflet 0:6ad60d78b315 1180 decKeyPtr++;
dflet 0:6ad60d78b315 1181 }
dflet 0:6ad60d78b315 1182 else
dflet 0:6ad60d78b315 1183 {
dflet 0:6ad60d78b315 1184 keyLen = 32;
dflet 0:6ad60d78b315 1185 }
dflet 0:6ad60d78b315 1186 }
dflet 0:6ad60d78b315 1187 else
dflet 0:6ad60d78b315 1188 {
dflet 0:6ad60d78b315 1189 keyLen = *decKeyPtr;
dflet 0:6ad60d78b315 1190 decKeyPtr++;
dflet 0:6ad60d78b315 1191 }
dflet 0:6ad60d78b315 1192
dflet 0:6ad60d78b315 1193 // add a profile
dflet 0:6ad60d78b315 1194 switch (profileArray[profileArray[0] + 2])
dflet 0:6ad60d78b315 1195 {
dflet 0:6ad60d78b315 1196 case WLAN_SEC_UNSEC://None
dflet 0:6ad60d78b315 1197 {
dflet 0:6ad60d78b315 1198 returnValue = wlan_add_profile(profileArray[profileArray[0] + 2], // security type
dflet 0:6ad60d78b315 1199 ssidPtr, // SSID
dflet 0:6ad60d78b315 1200 ssidLen, // SSID length
dflet 0:6ad60d78b315 1201 NULL, // BSSID
dflet 0:6ad60d78b315 1202 1, // Priority
dflet 0:6ad60d78b315 1203 0, 0, 0, 0, 0);
dflet 0:6ad60d78b315 1204
dflet 0:6ad60d78b315 1205 break;
dflet 0:6ad60d78b315 1206 }
dflet 0:6ad60d78b315 1207
dflet 0:6ad60d78b315 1208 case WLAN_SEC_WEP://WEP
dflet 0:6ad60d78b315 1209 {
dflet 0:6ad60d78b315 1210 returnValue = wlan_add_profile(profileArray[profileArray[0] + 2], // security type
dflet 0:6ad60d78b315 1211 ssidPtr, // SSID
dflet 0:6ad60d78b315 1212 ssidLen, // SSID length
dflet 0:6ad60d78b315 1213 NULL, // BSSID
dflet 0:6ad60d78b315 1214 1, // Priority
dflet 0:6ad60d78b315 1215 keyLen, // KEY length
dflet 0:6ad60d78b315 1216 0, // KEY index
dflet 0:6ad60d78b315 1217 0,
dflet 0:6ad60d78b315 1218 decKeyPtr, // KEY
dflet 0:6ad60d78b315 1219 0);
dflet 0:6ad60d78b315 1220
dflet 0:6ad60d78b315 1221 break;
dflet 0:6ad60d78b315 1222 }
dflet 0:6ad60d78b315 1223
dflet 0:6ad60d78b315 1224 case WLAN_SEC_WPA://WPA
dflet 0:6ad60d78b315 1225 case WLAN_SEC_WPA2://WPA2
dflet 0:6ad60d78b315 1226 {
dflet 0:6ad60d78b315 1227 returnValue = wlan_add_profile(WLAN_SEC_WPA2, // security type
dflet 0:6ad60d78b315 1228 ssidPtr,
dflet 0:6ad60d78b315 1229 ssidLen,
dflet 0:6ad60d78b315 1230 NULL, // BSSID
dflet 0:6ad60d78b315 1231 1, // Priority
dflet 0:6ad60d78b315 1232 0x18, // PairwiseCipher
dflet 0:6ad60d78b315 1233 0x1e, // GroupCipher
dflet 0:6ad60d78b315 1234 2, // KEY management
dflet 0:6ad60d78b315 1235 decKeyPtr, // KEY
dflet 0:6ad60d78b315 1236 keyLen); // KEY length
dflet 0:6ad60d78b315 1237
dflet 0:6ad60d78b315 1238 break;
dflet 0:6ad60d78b315 1239 }
dflet 0:6ad60d78b315 1240 }
dflet 0:6ad60d78b315 1241
dflet 0:6ad60d78b315 1242 return returnValue;
dflet 0:6ad60d78b315 1243 }
dflet 0:6ad60d78b315 1244 #endif //CC3000_UNENCRYPTED_SMART_CONFIG
dflet 0:6ad60d78b315 1245
dflet 0:6ad60d78b315 1246 //*****************************************************************************
dflet 0:6ad60d78b315 1247 //
dflet 0:6ad60d78b315 1248 // Close the Doxygen group.
dflet 0:6ad60d78b315 1249 //! @}
dflet 0:6ad60d78b315 1250 //
dflet 0:6ad60d78b315 1251 //*****************************************************************************
dflet 0:6ad60d78b315 1252