CC3000HostDriver for device TI CC3000 some changes were made due to mbed compiler and the use of void*

Dependents:   CC3000Test

Committer:
dflet
Date:
Fri Aug 02 15:06:15 2013 +0000
Revision:
0:9cb694f00b7b
First commit TI CC3000HostDriver library

Who changed what in which revision?

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