Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
wlan.cpp
00001 /***************************************************************************** 00002 * 00003 * wlan.c - CC3000 Host Driver Implementation. 00004 * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions 00008 * are met: 00009 * 00010 * Redistributions of source code must retain the above copyright 00011 * notice, this list of conditions and the following disclaimer. 00012 * 00013 * Redistributions in binary form must reproduce the above copyright 00014 * notice, this list of conditions and the following disclaimer in the 00015 * documentation and/or other materials provided with the 00016 * distribution. 00017 * 00018 * Neither the name of Texas Instruments Incorporated nor the names of 00019 * its contributors may be used to endorse or promote products derived 00020 * from this software without specific prior written permission. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00023 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00024 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00025 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00026 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00027 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00028 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00029 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00030 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00031 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00032 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00033 * 00034 *****************************************************************************/ 00035 00036 //***************************************************************************** 00037 // 00038 //! \addtogroup wlan_api 00039 //! @{ 00040 // 00041 //***************************************************************************** 00042 #include <string.h> 00043 #include "wlan.h" 00044 #include "hci.h" 00045 #include "spi.h" 00046 #include "socket.h" 00047 #include "nvmem.h" 00048 #include "security.h" 00049 #include "evnt_handler.h" 00050 00051 00052 volatile sSimplLinkInformation tSLInformation; 00053 00054 #define SMART_CONFIG_PROFILE_SIZE 67 // 67 = 32 (max ssid) + 32 (max key) + 1 (SSID length) + 1 (security type) + 1 (key length) 00055 00056 #ifndef CC3000_UNENCRYPTED_SMART_CONFIG 00057 unsigned char key[AES128_KEY_SIZE]; 00058 unsigned char profileArray[SMART_CONFIG_PROFILE_SIZE]; 00059 #endif //CC3000_UNENCRYPTED_SMART_CONFIG 00060 00061 /* patches type */ 00062 #define PATCHES_HOST_TYPE_WLAN_DRIVER 0x01 00063 #define PATCHES_HOST_TYPE_WLAN_FW 0x02 00064 #define PATCHES_HOST_TYPE_BOOTLOADER 0x03 00065 00066 #define SL_SET_SCAN_PARAMS_INTERVAL_LIST_SIZE (16) 00067 #define SL_SIMPLE_CONFIG_PREFIX_LENGTH (3) 00068 #define ETH_ALEN (6) 00069 #define MAXIMAL_SSID_LENGTH (32) 00070 00071 #define SL_PATCHES_REQUEST_DEFAULT (0) 00072 #define SL_PATCHES_REQUEST_FORCE_HOST (1) 00073 #define SL_PATCHES_REQUEST_FORCE_NONE (2) 00074 00075 00076 #define WLAN_SEC_UNSEC (0) 00077 #define WLAN_SEC_WEP (1) 00078 #define WLAN_SEC_WPA (2) 00079 #define WLAN_SEC_WPA2 (3) 00080 00081 00082 #define WLAN_SL_INIT_START_PARAMS_LEN (1) 00083 #define WLAN_PATCH_PARAMS_LENGTH (8) 00084 #define WLAN_SET_CONNECTION_POLICY_PARAMS_LEN (12) 00085 #define WLAN_DEL_PROFILE_PARAMS_LEN (4) 00086 #define WLAN_SET_MASK_PARAMS_LEN (4) 00087 #define WLAN_SET_SCAN_PARAMS_LEN (100) 00088 #define WLAN_GET_SCAN_RESULTS_PARAMS_LEN (4) 00089 #define WLAN_ADD_PROFILE_NOSEC_PARAM_LEN (24) 00090 #define WLAN_ADD_PROFILE_WEP_PARAM_LEN (36) 00091 #define WLAN_ADD_PROFILE_WPA_PARAM_LEN (44) 00092 #define WLAN_CONNECT_PARAM_LEN (29) 00093 #define WLAN_SMART_CONFIG_START_PARAMS_LEN (4) 00094 00095 00096 00097 00098 //***************************************************************************** 00099 // 00100 //! SimpleLink_Init_Start 00101 //! 00102 //! @param usPatchesAvailableAtHost flag to indicate if patches available 00103 //! from host or from EEPROM. Due to the 00104 //! fact the patches are burn to the EEPROM 00105 //! using the patch programmer utility, the 00106 //! patches will be available from the EEPROM 00107 //! and not from the host. 00108 //! 00109 //! @return none 00110 //! 00111 //! @brief Send HCI_CMND_SIMPLE_LINK_START to CC3000 00112 // 00113 //***************************************************************************** 00114 static void SimpleLink_Init_Start(unsigned short usPatchesAvailableAtHost) 00115 { 00116 unsigned char *ptr; 00117 unsigned char *args; 00118 00119 ptr = tSLInformation.pucTxCommandBuffer; 00120 args = (unsigned char *)(ptr + HEADERS_SIZE_CMD); 00121 00122 UINT8_TO_STREAM(args, ((usPatchesAvailableAtHost) ? SL_PATCHES_REQUEST_FORCE_HOST : SL_PATCHES_REQUEST_DEFAULT)); 00123 00124 // IRQ Line asserted - send HCI_CMND_SIMPLE_LINK_START to CC3000 00125 hci_command_send(HCI_CMND_SIMPLE_LINK_START, ptr, WLAN_SL_INIT_START_PARAMS_LEN); 00126 00127 SimpleLinkWaitEvent(HCI_CMND_SIMPLE_LINK_START, 0); 00128 } 00129 00130 00131 00132 //***************************************************************************** 00133 // 00134 //! wlan_init 00135 //! 00136 //! @param sWlanCB Asynchronous events callback. 00137 //! 0 no event call back. 00138 //! -call back parameters: 00139 //! 1) event_type: HCI_EVNT_WLAN_UNSOL_CONNECT connect event, 00140 //! HCI_EVNT_WLAN_UNSOL_DISCONNECT disconnect event, 00141 //! HCI_EVNT_WLAN_ASYNC_SIMPLE_CONFIG_DONE config done, 00142 //! HCI_EVNT_WLAN_UNSOL_DHCP dhcp report, 00143 //! HCI_EVNT_WLAN_ASYNC_PING_REPORT ping report OR 00144 //! HCI_EVNT_WLAN_KEEPALIVE keepalive. 00145 //! 2) data: pointer to extra data that received by the event 00146 //! (NULL no data). 00147 //! 3) length: data length. 00148 //! -Events with extra data: 00149 //! HCI_EVNT_WLAN_UNSOL_DHCP: 4 bytes IP, 4 bytes Mask, 00150 //! 4 bytes default gateway, 4 bytes DHCP server and 4 bytes 00151 //! for DNS server. 00152 //! HCI_EVNT_WLAN_ASYNC_PING_REPORT: 4 bytes Packets sent, 00153 //! 4 bytes Packets received, 4 bytes Min round time, 00154 //! 4 bytes Max round time and 4 bytes for Avg round time. 00155 //! 00156 //! @param sFWPatches 0 no patch or pointer to FW patches 00157 //! @param sDriverPatches 0 no patch or pointer to driver patches 00158 //! @param sBootLoaderPatches 0 no patch or pointer to bootloader patches 00159 //! @param sReadWlanInterruptPin init callback. the callback read wlan 00160 //! interrupt status. 00161 //! @param sWlanInterruptEnable init callback. the callback enable wlan 00162 //! interrupt. 00163 //! @param sWlanInterruptDisable init callback. the callback disable wlan 00164 //! interrupt. 00165 //! @param sWriteWlanPin init callback. the callback write value 00166 //! to device pin. 00167 //! 00168 //! @return none 00169 //! 00170 //! @sa wlan_set_event_mask , wlan_start , wlan_stop 00171 //! 00172 //! @brief Initialize wlan driver 00173 //! 00174 //! @warning This function must be called before ANY other wlan driver function 00175 // 00176 //***************************************************************************** 00177 00178 void wlan_init( tWlanCB sWlanCB, 00179 tFWPatches sFWPatches, 00180 tDriverPatches sDriverPatches, 00181 tBootLoaderPatches sBootLoaderPatches, 00182 tWlanReadInteruptPin sReadWlanInterruptPin, 00183 tWlanInterruptEnable sWlanInterruptEnable, 00184 tWlanInterruptDisable sWlanInterruptDisable, 00185 tWriteWlanPin sWriteWlanPin) 00186 { 00187 00188 tSLInformation.sFWPatches = sFWPatches; 00189 tSLInformation.sDriverPatches = sDriverPatches; 00190 tSLInformation.sBootLoaderPatches = sBootLoaderPatches; 00191 00192 // init io callback 00193 tSLInformation.ReadWlanInterruptPin = sReadWlanInterruptPin; 00194 tSLInformation.WlanInterruptEnable = sWlanInterruptEnable; 00195 tSLInformation.WlanInterruptDisable = sWlanInterruptDisable; 00196 tSLInformation.WriteWlanPin = sWriteWlanPin; 00197 00198 //init asynchronous events callback 00199 tSLInformation.sWlanCB= sWlanCB; 00200 00201 // By default TX Complete events are routed to host too 00202 tSLInformation.InformHostOnTxComplete = 1; 00203 } 00204 00205 //***************************************************************************** 00206 // 00207 //! SpiReceiveHandler 00208 //! 00209 //! @param pvBuffer - pointer to the received data buffer 00210 //! The function triggers Received event/data processing 00211 //! 00212 //! @param Pointer to the received data 00213 //! @return none 00214 //! 00215 //! @brief The function triggers Received event/data processing. It is 00216 //! called from the SPI library to receive the data 00217 // 00218 //***************************************************************************** 00219 void SpiReceiveHandler(void *pvBuffer) 00220 { 00221 tSLInformation.usEventOrDataReceived = 1; 00222 tSLInformation.pucReceivedData = (unsigned char *)pvBuffer; 00223 00224 hci_unsolicited_event_handler(); 00225 } 00226 00227 00228 //***************************************************************************** 00229 // 00230 //! wlan_start 00231 //! 00232 //! @param usPatchesAvailableAtHost - flag to indicate if patches available 00233 //! from host or from EEPROM. Due to the 00234 //! fact the patches are burn to the EEPROM 00235 //! using the patch programmer utility, the 00236 //! patches will be available from the EEPROM 00237 //! and not from the host. 00238 //! 00239 //! @return none 00240 //! 00241 //! @brief Start WLAN device. This function asserts the enable pin of 00242 //! the device (WLAN_EN), starting the HW initialization process. 00243 //! The function blocked until device Initialization is completed. 00244 //! Function also configure patches (FW, driver or bootloader) 00245 //! and calls appropriate device callbacks. 00246 //! 00247 //! @Note Prior calling the function wlan_init shall be called. 00248 //! @Warning This function must be called after wlan_init and before any 00249 //! other wlan API 00250 //! @sa wlan_init , wlan_stop 00251 //! 00252 // 00253 //***************************************************************************** 00254 00255 void 00256 wlan_start(unsigned short usPatchesAvailableAtHost) 00257 { 00258 00259 unsigned long ulSpiIRQState; 00260 00261 tSLInformation.NumberOfSentPackets = 0; 00262 tSLInformation.NumberOfReleasedPackets = 0; 00263 tSLInformation.usRxEventOpcode = 0; 00264 tSLInformation.usNumberOfFreeBuffers = 0; 00265 tSLInformation.usSlBufferLength = 0; 00266 tSLInformation.usBufferSize = 0; 00267 tSLInformation.usRxDataPending = 0; 00268 tSLInformation.slTransmitDataError = 0; 00269 tSLInformation.usEventOrDataReceived = 0; 00270 tSLInformation.pucReceivedData = 0; 00271 00272 // Allocate the memory for the RX/TX data transactions 00273 tSLInformation.pucTxCommandBuffer = (unsigned char *)wlan_tx_buffer; 00274 00275 // init spi 00276 SpiOpen(SpiReceiveHandler); 00277 00278 // Check the IRQ line 00279 ulSpiIRQState = tSLInformation.ReadWlanInterruptPin(); 00280 00281 // ASIC 1273 chip enable: toggle WLAN EN line 00282 tSLInformation.WriteWlanPin( WLAN_ENABLE ); 00283 00284 if (ulSpiIRQState) 00285 { 00286 // wait till the IRQ line goes low 00287 while(tSLInformation.ReadWlanInterruptPin() != 0) 00288 { 00289 } 00290 } 00291 else 00292 { 00293 // wait till the IRQ line goes high and than low 00294 while(tSLInformation.ReadWlanInterruptPin() == 0) 00295 { 00296 } 00297 00298 while(tSLInformation.ReadWlanInterruptPin() != 0) 00299 { 00300 } 00301 } 00302 00303 SimpleLink_Init_Start(usPatchesAvailableAtHost); 00304 00305 // Read Buffer's size and finish 00306 hci_command_send(HCI_CMND_READ_BUFFER_SIZE, tSLInformation.pucTxCommandBuffer, 0); 00307 SimpleLinkWaitEvent(HCI_CMND_READ_BUFFER_SIZE, 0); 00308 } 00309 00310 00311 //***************************************************************************** 00312 // 00313 //! wlan_stop 00314 //! 00315 //! @param none 00316 //! 00317 //! @return none 00318 //! 00319 //! @brief Stop WLAN device by putting it into reset state. 00320 //! 00321 //! @sa wlan_start 00322 // 00323 //***************************************************************************** 00324 00325 void 00326 wlan_stop(void) 00327 { 00328 // ASIC 1273 chip disable 00329 tSLInformation.WriteWlanPin( WLAN_DISABLE ); 00330 00331 // Wait till IRQ line goes high... 00332 while(tSLInformation.ReadWlanInterruptPin() == 0) 00333 { 00334 } 00335 00336 // Free the used by WLAN Driver memory 00337 if (tSLInformation.pucTxCommandBuffer) 00338 { 00339 tSLInformation.pucTxCommandBuffer = 0; 00340 } 00341 00342 SpiClose(); 00343 } 00344 00345 00346 //***************************************************************************** 00347 // 00348 //! wlan_connect 00349 //! 00350 //! @param sec_type security options: 00351 //! WLAN_SEC_UNSEC, 00352 //! WLAN_SEC_WEP (ASCII support only), 00353 //! WLAN_SEC_WPA or WLAN_SEC_WPA2 00354 //! @param ssid up to 32 bytes and is ASCII SSID of the AP 00355 //! @param ssid_len length of the SSID 00356 //! @param bssid 6 bytes specified the AP bssid 00357 //! @param key up to 16 bytes specified the AP security key 00358 //! @param key_len key length 00359 //! 00360 //! @return On success, zero is returned. On error, negative is returned. 00361 //! Note that even though a zero is returned on success to trigger 00362 //! connection operation, it does not mean that CCC3000 is already 00363 //! connected. An asynchronous "Connected" event is generated when 00364 //! actual association process finishes and CC3000 is connected to 00365 //! the AP. If DHCP is set, An asynchronous "DHCP" event is 00366 //! generated when DHCP process is finish. 00367 //! 00368 //! 00369 //! @brief Connect to AP 00370 //! @warning Please Note that when connection to AP configured with security 00371 //! type WEP, please confirm that the key is set as ASCII and not 00372 //! as HEX. 00373 //! @sa wlan_disconnect 00374 // 00375 //***************************************************************************** 00376 00377 #ifndef CC3000_TINY_DRIVER 00378 long 00379 wlan_connect(unsigned long ulSecType, char *ssid, long ssid_len, 00380 unsigned char *bssid, unsigned char *key, long key_len) 00381 { 00382 long ret; 00383 unsigned char *ptr; 00384 unsigned char *args; 00385 unsigned char bssid_zero[] = {0, 0, 0, 0, 0, 0}; 00386 00387 ret = EFAIL; 00388 ptr = tSLInformation.pucTxCommandBuffer; 00389 args = (ptr + HEADERS_SIZE_CMD); 00390 00391 // Fill in command buffer 00392 args = UINT32_TO_STREAM(args, 0x0000001c); 00393 args = UINT32_TO_STREAM(args, ssid_len); 00394 args = UINT32_TO_STREAM(args, ulSecType); 00395 args = UINT32_TO_STREAM(args, 0x00000010 + ssid_len); 00396 args = UINT32_TO_STREAM(args, key_len); 00397 args = UINT16_TO_STREAM(args, 0); 00398 00399 // padding shall be zeroed 00400 if(bssid) 00401 { 00402 ARRAY_TO_STREAM(args, bssid, ETH_ALEN); 00403 } 00404 else 00405 { 00406 ARRAY_TO_STREAM(args, bssid_zero, ETH_ALEN); 00407 } 00408 00409 ARRAY_TO_STREAM(args, ssid, ssid_len); 00410 00411 if(key_len && key) 00412 { 00413 ARRAY_TO_STREAM(args, key, key_len); 00414 } 00415 00416 // Initiate a HCI command 00417 hci_command_send(HCI_CMND_WLAN_CONNECT, ptr, WLAN_CONNECT_PARAM_LEN + 00418 ssid_len + key_len - 1); 00419 00420 // Wait for command complete event 00421 SimpleLinkWaitEvent(HCI_CMND_WLAN_CONNECT, &ret); 00422 errno = ret; 00423 00424 return(ret); 00425 } 00426 #else 00427 long 00428 wlan_connect(char *ssid, long ssid_len) 00429 { 00430 long ret; 00431 unsigned char *ptr; 00432 unsigned char *args; 00433 unsigned char bssid_zero[] = {0, 0, 0, 0, 0, 0}; 00434 00435 ret = EFAIL; 00436 ptr = tSLInformation.pucTxCommandBuffer; 00437 args = (ptr + HEADERS_SIZE_CMD); 00438 00439 // Fill in command buffer 00440 args = UINT32_TO_STREAM(args, 0x0000001c); 00441 args = UINT32_TO_STREAM(args, ssid_len); 00442 args = UINT32_TO_STREAM(args, 0); 00443 args = UINT32_TO_STREAM(args, 0x00000010 + ssid_len); 00444 args = UINT32_TO_STREAM(args, 0); 00445 args = UINT16_TO_STREAM(args, 0); 00446 00447 // padding shall be zeroed 00448 ARRAY_TO_STREAM(args, bssid_zero, ETH_ALEN); 00449 ARRAY_TO_STREAM(args, ssid, ssid_len); 00450 00451 // Initiate a HCI command 00452 hci_command_send(HCI_CMND_WLAN_CONNECT, ptr, WLAN_CONNECT_PARAM_LEN + 00453 ssid_len - 1); 00454 00455 // Wait for command complete event 00456 SimpleLinkWaitEvent(HCI_CMND_WLAN_CONNECT, &ret); 00457 errno = ret; 00458 00459 return(ret); 00460 } 00461 #endif 00462 00463 //***************************************************************************** 00464 // 00465 //! wlan_disconnect 00466 //! 00467 //! @return 0 disconnected done, other CC3000 already disconnected 00468 //! 00469 //! @brief Disconnect connection from AP. 00470 //! 00471 //! @sa wlan_connect 00472 // 00473 //***************************************************************************** 00474 00475 long 00476 wlan_disconnect() 00477 { 00478 long ret; 00479 unsigned char *ptr; 00480 00481 ret = EFAIL; 00482 ptr = tSLInformation.pucTxCommandBuffer; 00483 00484 hci_command_send(HCI_CMND_WLAN_DISCONNECT, ptr, 0); 00485 00486 // Wait for command complete event 00487 SimpleLinkWaitEvent(HCI_CMND_WLAN_DISCONNECT, &ret); 00488 errno = ret; 00489 00490 return(ret); 00491 } 00492 00493 //***************************************************************************** 00494 // 00495 //! wlan_ioctl_set_connection_policy 00496 //! 00497 //! @param should_connect_to_open_ap enable(1), disable(0) connect to any 00498 //! available AP. This parameter corresponds to the configuration of 00499 //! item # 3 in the brief description. 00500 //! @param should_use_fast_connect enable(1), disable(0). if enabled, tries 00501 //! to connect to the last connected AP. This parameter corresponds 00502 //! to the configuration of item # 1 in the brief description. 00503 //! @param auto_start enable(1), disable(0) auto connect 00504 //! after reset and periodically reconnect if needed. This 00505 //! configuration configures option 2 in the above description. 00506 //! 00507 //! @return On success, zero is returned. On error, -1 is returned 00508 //! 00509 //! @brief When auto is enabled, the device tries to connect according 00510 //! the following policy: 00511 //! 1) If fast connect is enabled and last connection is valid, 00512 //! the device will try to connect to it without the scanning 00513 //! procedure (fast). The last connection will be marked as 00514 //! invalid, due to adding/removing profile. 00515 //! 2) If profile exists, the device will try to connect it 00516 //! (Up to seven profiles). 00517 //! 3) If fast and profiles are not found, and open mode is 00518 //! enabled, the device will try to connect to any AP. 00519 //! * Note that the policy settings are stored in the CC3000 NVMEM. 00520 //! 00521 //! @sa wlan_add_profile , wlan_ioctl_del_profile 00522 // 00523 //***************************************************************************** 00524 00525 long 00526 wlan_ioctl_set_connection_policy(unsigned long should_connect_to_open_ap, 00527 unsigned long ulShouldUseFastConnect, 00528 unsigned long ulUseProfiles) 00529 { 00530 long ret; 00531 unsigned char *ptr; 00532 unsigned char *args; 00533 00534 ret = EFAIL; 00535 ptr = tSLInformation.pucTxCommandBuffer; 00536 args = (unsigned char *)(ptr + HEADERS_SIZE_CMD); 00537 00538 // Fill in HCI packet structure 00539 args = UINT32_TO_STREAM(args, should_connect_to_open_ap); 00540 args = UINT32_TO_STREAM(args, ulShouldUseFastConnect); 00541 args = UINT32_TO_STREAM(args, ulUseProfiles); 00542 00543 // Initiate a HCI command 00544 hci_command_send(HCI_CMND_WLAN_IOCTL_SET_CONNECTION_POLICY, 00545 ptr, WLAN_SET_CONNECTION_POLICY_PARAMS_LEN); 00546 00547 // Wait for command complete event 00548 SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_SET_CONNECTION_POLICY, &ret); 00549 00550 return(ret); 00551 } 00552 00553 //***************************************************************************** 00554 // 00555 //! wlan_add_profile 00556 //! 00557 //! @param ulSecType WLAN_SEC_UNSEC,WLAN_SEC_WEP,WLAN_SEC_WPA,WLAN_SEC_WPA2 00558 //! @param ucSsid ssid SSID up to 32 bytes 00559 //! @param ulSsidLen ssid length 00560 //! @param ucBssid bssid 6 bytes 00561 //! @param ulPriority ulPriority profile priority. Lowest priority:0. 00562 //! @param ulPairwiseCipher_Or_TxKeyLen key length for WEP security 00563 //! @param ulGroupCipher_TxKeyIndex key index 00564 //! @param ulKeyMgmt KEY management 00565 //! @param ucPf_OrKey security key 00566 //! @param ulPassPhraseLen security key length for WPA\WPA2 00567 //! 00568 //! @return On success, zero is returned. On error, -1 is returned 00569 //! 00570 //! @brief When auto start is enabled, the device connects to 00571 //! station from the profiles table. Up to 7 profiles are supported. 00572 //! If several profiles configured the device choose the highest 00573 //! priority profile, within each priority group, device will choose 00574 //! profile based on security policy, signal strength, etc 00575 //! parameters. All the profiles are stored in CC3000 NVMEM. 00576 //! 00577 //! @sa wlan_ioctl_del_profile 00578 // 00579 //***************************************************************************** 00580 00581 #ifndef CC3000_TINY_DRIVER 00582 long 00583 wlan_add_profile(unsigned long ulSecType, 00584 unsigned char* ucSsid, 00585 unsigned long ulSsidLen, 00586 unsigned char *ucBssid, 00587 unsigned long ulPriority, 00588 unsigned long ulPairwiseCipher_Or_TxKeyLen, 00589 unsigned long ulGroupCipher_TxKeyIndex, 00590 unsigned long ulKeyMgmt, 00591 unsigned char* ucPf_OrKey, 00592 unsigned long ulPassPhraseLen) 00593 { 00594 unsigned short arg_len; 00595 long ret; 00596 unsigned char *ptr; 00597 long i = 0; 00598 unsigned char *args; 00599 unsigned char bssid_zero[] = {0, 0, 0, 0, 0, 0}; 00600 00601 ptr = tSLInformation.pucTxCommandBuffer; 00602 args = (ptr + HEADERS_SIZE_CMD); 00603 00604 args = UINT32_TO_STREAM(args, ulSecType); 00605 00606 // Setup arguments in accordance with the security type 00607 switch (ulSecType) 00608 { 00609 //OPEN 00610 case WLAN_SEC_UNSEC: 00611 { 00612 args = UINT32_TO_STREAM(args, 0x00000014); 00613 args = UINT32_TO_STREAM(args, ulSsidLen); 00614 args = UINT16_TO_STREAM(args, 0); 00615 if(ucBssid) 00616 { 00617 ARRAY_TO_STREAM(args, ucBssid, ETH_ALEN); 00618 } 00619 else 00620 { 00621 ARRAY_TO_STREAM(args, bssid_zero, ETH_ALEN); 00622 } 00623 args = UINT32_TO_STREAM(args, ulPriority); 00624 ARRAY_TO_STREAM(args, ucSsid, ulSsidLen); 00625 00626 arg_len = WLAN_ADD_PROFILE_NOSEC_PARAM_LEN + ulSsidLen; 00627 } 00628 break; 00629 00630 //WEP 00631 case WLAN_SEC_WEP: 00632 { 00633 args = UINT32_TO_STREAM(args, 0x00000020); 00634 args = UINT32_TO_STREAM(args, ulSsidLen); 00635 args = UINT16_TO_STREAM(args, 0); 00636 if(ucBssid) 00637 { 00638 ARRAY_TO_STREAM(args, ucBssid, ETH_ALEN); 00639 } 00640 else 00641 { 00642 ARRAY_TO_STREAM(args, bssid_zero, ETH_ALEN); 00643 } 00644 args = UINT32_TO_STREAM(args, ulPriority); 00645 args = UINT32_TO_STREAM(args, 0x0000000C + ulSsidLen); 00646 args = UINT32_TO_STREAM(args, ulPairwiseCipher_Or_TxKeyLen); 00647 args = UINT32_TO_STREAM(args, ulGroupCipher_TxKeyIndex); 00648 ARRAY_TO_STREAM(args, ucSsid, ulSsidLen); 00649 00650 for(i = 0; i < 4; i++) 00651 { 00652 unsigned char *p = &ucPf_OrKey[i * ulPairwiseCipher_Or_TxKeyLen]; 00653 00654 ARRAY_TO_STREAM(args, p, ulPairwiseCipher_Or_TxKeyLen); 00655 } 00656 00657 arg_len = WLAN_ADD_PROFILE_WEP_PARAM_LEN + ulSsidLen + 00658 ulPairwiseCipher_Or_TxKeyLen * 4; 00659 00660 } 00661 break; 00662 00663 //WPA 00664 //WPA2 00665 case WLAN_SEC_WPA: 00666 case WLAN_SEC_WPA2: 00667 { 00668 args = UINT32_TO_STREAM(args, 0x00000028); 00669 args = UINT32_TO_STREAM(args, ulSsidLen); 00670 args = UINT16_TO_STREAM(args, 0); 00671 if(ucBssid) 00672 { 00673 ARRAY_TO_STREAM(args, ucBssid, ETH_ALEN); 00674 } 00675 else 00676 { 00677 ARRAY_TO_STREAM(args, bssid_zero, ETH_ALEN); 00678 } 00679 args = UINT32_TO_STREAM(args, ulPriority); 00680 args = UINT32_TO_STREAM(args, ulPairwiseCipher_Or_TxKeyLen); 00681 args = UINT32_TO_STREAM(args, ulGroupCipher_TxKeyIndex); 00682 args = UINT32_TO_STREAM(args, ulKeyMgmt); 00683 args = UINT32_TO_STREAM(args, 0x00000008 + ulSsidLen); 00684 args = UINT32_TO_STREAM(args, ulPassPhraseLen); 00685 ARRAY_TO_STREAM(args, ucSsid, ulSsidLen); 00686 ARRAY_TO_STREAM(args, ucPf_OrKey, ulPassPhraseLen); 00687 00688 arg_len = WLAN_ADD_PROFILE_WPA_PARAM_LEN + ulSsidLen + ulPassPhraseLen; 00689 } 00690 00691 break; 00692 } 00693 00694 // Initiate a HCI command 00695 hci_command_send(HCI_CMND_WLAN_IOCTL_ADD_PROFILE, 00696 ptr, arg_len); 00697 00698 // Wait for command complete event 00699 SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_ADD_PROFILE, &ret); 00700 00701 return(ret); 00702 } 00703 #else 00704 long 00705 wlan_add_profile(unsigned long ulSecType, 00706 unsigned char* ucSsid, 00707 unsigned long ulSsidLen, 00708 unsigned char *ucBssid, 00709 unsigned long ulPriority, 00710 unsigned long ulPairwiseCipher_Or_TxKeyLen, 00711 unsigned long ulGroupCipher_TxKeyIndex, 00712 unsigned long ulKeyMgmt, 00713 unsigned char* ucPf_OrKey, 00714 unsigned long ulPassPhraseLen) 00715 { 00716 return -1; 00717 } 00718 #endif 00719 00720 //***************************************************************************** 00721 // 00722 //! wlan_ioctl_del_profile 00723 //! 00724 //! @param index number of profile to delete 00725 //! 00726 //! @return On success, zero is returned. On error, -1 is returned 00727 //! 00728 //! @brief Delete WLAN profile 00729 //! 00730 //! @Note In order to delete all stored profile, set index to 255. 00731 //! 00732 //! @sa wlan_add_profile 00733 // 00734 //***************************************************************************** 00735 00736 long 00737 wlan_ioctl_del_profile(unsigned long ulIndex) 00738 { 00739 long ret; 00740 unsigned char *ptr; 00741 unsigned char *args; 00742 00743 ptr = tSLInformation.pucTxCommandBuffer; 00744 args = (unsigned char *)(ptr + HEADERS_SIZE_CMD); 00745 00746 // Fill in HCI packet structure 00747 args = UINT32_TO_STREAM(args, ulIndex); 00748 ret = EFAIL; 00749 00750 // Initiate a HCI command 00751 hci_command_send(HCI_CMND_WLAN_IOCTL_DEL_PROFILE, 00752 ptr, WLAN_DEL_PROFILE_PARAMS_LEN); 00753 00754 // Wait for command complete event 00755 SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_DEL_PROFILE, &ret); 00756 00757 return(ret); 00758 } 00759 00760 //***************************************************************************** 00761 // 00762 //! wlan_ioctl_get_scan_results 00763 //! 00764 //! @param[in] scan_timeout parameter not supported 00765 //! @param[out] ucResults scan results (_wlan_full_scan_results_args_t) 00766 //! 00767 //! @return On success, zero is returned. On error, -1 is returned 00768 //! 00769 //! @brief Gets entry from scan result table. 00770 //! The scan results are returned one by one, and each entry 00771 //! represents a single AP found in the area. The following is a 00772 //! format of the scan result: 00773 //! - 4 Bytes: number of networks found 00774 //! - 4 Bytes: The status of the scan: 0 - aged results, 00775 //! 1 - results valid, 2 - no results 00776 //! - 42 bytes: Result entry, where the bytes are arranged as follows: 00777 //! 00778 //! - 1 bit isValid - is result valid or not 00779 //! - 7 bits rssi - RSSI value; 00780 //! - 2 bits: securityMode - security mode of the AP: 00781 //! 0 - Open, 1 - WEP, 2 WPA, 3 WPA2 00782 //! - 6 bits: SSID name length 00783 //! - 2 bytes: the time at which the entry has entered into 00784 //! scans result table 00785 //! - 32 bytes: SSID name 00786 //! - 6 bytes: BSSID 00787 //! 00788 //! @Note scan_timeout, is not supported on this version. 00789 //! 00790 //! @sa wlan_ioctl_set_scan_params 00791 // 00792 //***************************************************************************** 00793 00794 #ifndef CC3000_TINY_DRIVER 00795 long 00796 wlan_ioctl_get_scan_results(unsigned long ulScanTimeout, 00797 unsigned char *ucResults) 00798 { 00799 unsigned char *ptr; 00800 unsigned char *args; 00801 00802 ptr = tSLInformation.pucTxCommandBuffer; 00803 args = (ptr + HEADERS_SIZE_CMD); 00804 00805 // Fill in temporary command buffer 00806 args = UINT32_TO_STREAM(args, ulScanTimeout); 00807 00808 // Initiate a HCI command 00809 hci_command_send(HCI_CMND_WLAN_IOCTL_GET_SCAN_RESULTS, 00810 ptr, WLAN_GET_SCAN_RESULTS_PARAMS_LEN); 00811 00812 // Wait for command complete event 00813 SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_GET_SCAN_RESULTS, ucResults); 00814 00815 return(0); 00816 } 00817 #endif 00818 00819 //***************************************************************************** 00820 // 00821 //! wlan_ioctl_set_scan_params 00822 //! 00823 //! @param uiEnable - start/stop application scan: 00824 //! 1 = start scan with default interval value of 10 min. 00825 //! in order to set a different scan interval value apply the value 00826 //! in milliseconds. minimum 1 second. 0=stop). Wlan reset 00827 //! (wlan_stop() wlan_start()) is needed when changing scan interval 00828 //! value. Saved: No 00829 //! @param uiMinDwellTime minimum dwell time value to be used for each 00830 //! channel, in milliseconds. Saved: yes 00831 //! Recommended Value: 100 (Default: 20) 00832 //! @param uiMaxDwellTime maximum dwell time value to be used for each 00833 //! channel, in milliseconds. Saved: yes 00834 //! Recommended Value: 100 (Default: 30) 00835 //! @param uiNumOfProbeRequests max probe request between dwell time. 00836 //! Saved: yes. Recommended Value: 5 (Default:2) 00837 //! @param uiChannelMask bitwise, up to 13 channels (0x1fff). 00838 //! Saved: yes. Default: 0x7ff 00839 //! @param uiRSSIThreshold RSSI threshold. Saved: yes (Default: -80) 00840 //! @param uiSNRThreshold NSR threshold. Saved: yes (Default: 0) 00841 //! @param uiDefaultTxPower probe Tx power. Saved: yes (Default: 205) 00842 //! @param aiIntervalList pointer to array with 16 entries (16 channels) 00843 //! each entry (unsigned long) holds timeout between periodic scan 00844 //! (connection scan) - in millisecond. Saved: yes. Default 2000ms. 00845 //! 00846 //! @return On success, zero is returned. On error, -1 is returned 00847 //! 00848 //! @brief start and stop scan procedure. Set scan parameters. 00849 //! 00850 //! @Note uiDefaultTxPower, is not supported on this version. 00851 //! 00852 //! @sa wlan_ioctl_get_scan_results 00853 // 00854 //***************************************************************************** 00855 00856 #ifndef CC3000_TINY_DRIVER 00857 long 00858 wlan_ioctl_set_scan_params(unsigned long uiEnable, unsigned long uiMinDwellTime, 00859 unsigned long uiMaxDwellTime, 00860 unsigned long uiNumOfProbeRequests, 00861 unsigned long uiChannelMask,long iRSSIThreshold, 00862 unsigned long uiSNRThreshold, 00863 unsigned long uiDefaultTxPower, 00864 unsigned long *aiIntervalList) 00865 { 00866 unsigned long uiRes; 00867 unsigned char *ptr; 00868 unsigned char *args; 00869 00870 ptr = tSLInformation.pucTxCommandBuffer; 00871 args = (ptr + HEADERS_SIZE_CMD); 00872 00873 // Fill in temporary command buffer 00874 args = UINT32_TO_STREAM(args, 36); 00875 args = UINT32_TO_STREAM(args, uiEnable); 00876 args = UINT32_TO_STREAM(args, uiMinDwellTime); 00877 args = UINT32_TO_STREAM(args, uiMaxDwellTime); 00878 args = UINT32_TO_STREAM(args, uiNumOfProbeRequests); 00879 args = UINT32_TO_STREAM(args, uiChannelMask); 00880 args = UINT32_TO_STREAM(args, iRSSIThreshold); 00881 args = UINT32_TO_STREAM(args, uiSNRThreshold); 00882 args = UINT32_TO_STREAM(args, uiDefaultTxPower); 00883 ARRAY_TO_STREAM(args, aiIntervalList, sizeof(unsigned long) * 00884 SL_SET_SCAN_PARAMS_INTERVAL_LIST_SIZE); 00885 00886 // Initiate a HCI command 00887 hci_command_send(HCI_CMND_WLAN_IOCTL_SET_SCANPARAM, 00888 ptr, WLAN_SET_SCAN_PARAMS_LEN); 00889 00890 // Wait for command complete event 00891 SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_SET_SCANPARAM, &uiRes); 00892 00893 return(uiRes); 00894 } 00895 #endif 00896 00897 //***************************************************************************** 00898 // 00899 //! wlan_set_event_mask 00900 //! 00901 //! @param mask mask option: 00902 //! HCI_EVNT_WLAN_UNSOL_CONNECT connect event 00903 //! HCI_EVNT_WLAN_UNSOL_DISCONNECT disconnect event 00904 //! HCI_EVNT_WLAN_ASYNC_SIMPLE_CONFIG_DONE smart config done 00905 //! HCI_EVNT_WLAN_UNSOL_INIT init done 00906 //! HCI_EVNT_WLAN_UNSOL_DHCP dhcp event report 00907 //! HCI_EVNT_WLAN_ASYNC_PING_REPORT ping report 00908 //! HCI_EVNT_WLAN_KEEPALIVE keepalive 00909 //! HCI_EVNT_WLAN_TX_COMPLETE - disable information on end of transmission 00910 //! Saved: no. 00911 //! 00912 //! @return On success, zero is returned. On error, -1 is returned 00913 //! 00914 //! @brief Mask event according to bit mask. In case that event is 00915 //! masked (1), the device will not send the masked event to host. 00916 // 00917 //***************************************************************************** 00918 00919 long 00920 wlan_set_event_mask(unsigned long ulMask) 00921 { 00922 long ret; 00923 unsigned char *ptr; 00924 unsigned char *args; 00925 00926 00927 if ((ulMask & HCI_EVNT_WLAN_TX_COMPLETE) == HCI_EVNT_WLAN_TX_COMPLETE) 00928 { 00929 tSLInformation.InformHostOnTxComplete = 0; 00930 00931 // Since an event is a virtual event - i.e. it is not coming from CC3000 00932 // there is no need to send anything to the device if it was an only event 00933 if (ulMask == HCI_EVNT_WLAN_TX_COMPLETE) 00934 { 00935 return 0; 00936 } 00937 00938 ulMask &= ~HCI_EVNT_WLAN_TX_COMPLETE; 00939 ulMask |= HCI_EVNT_WLAN_UNSOL_BASE; 00940 } 00941 else 00942 { 00943 tSLInformation.InformHostOnTxComplete = 1; 00944 } 00945 00946 ret = EFAIL; 00947 ptr = tSLInformation.pucTxCommandBuffer; 00948 args = (unsigned char *)(ptr + HEADERS_SIZE_CMD); 00949 00950 // Fill in HCI packet structure 00951 args = UINT32_TO_STREAM(args, ulMask); 00952 00953 // Initiate a HCI command 00954 hci_command_send(HCI_CMND_EVENT_MASK, 00955 ptr, WLAN_SET_MASK_PARAMS_LEN); 00956 00957 // Wait for command complete event 00958 SimpleLinkWaitEvent(HCI_CMND_EVENT_MASK, &ret); 00959 00960 return(ret); 00961 } 00962 00963 //***************************************************************************** 00964 // 00965 //! wlan_ioctl_statusget 00966 //! 00967 //! @param none 00968 //! 00969 //! @return WLAN_STATUS_DISCONNECTED, WLAN_STATUS_SCANING, 00970 //! STATUS_CONNECTING or WLAN_STATUS_CONNECTED 00971 //! 00972 //! @brief get wlan status: disconnected, scanning, connecting or connected 00973 // 00974 //***************************************************************************** 00975 00976 #ifndef CC3000_TINY_DRIVER 00977 long 00978 wlan_ioctl_statusget(void) 00979 { 00980 long ret; 00981 unsigned char *ptr; 00982 00983 ret = EFAIL; 00984 ptr = tSLInformation.pucTxCommandBuffer; 00985 00986 hci_command_send(HCI_CMND_WLAN_IOCTL_STATUSGET, 00987 ptr, 0); 00988 00989 // Wait for command complete event 00990 SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_STATUSGET, &ret); 00991 00992 return(ret); 00993 } 00994 #endif 00995 00996 //***************************************************************************** 00997 // 00998 //! wlan_smart_config_start 00999 //! 01000 //! @param algoEncryptedFlag indicates whether the information is encrypted 01001 //! 01002 //! @return On success, zero is returned. On error, -1 is returned 01003 //! 01004 //! @brief Start to acquire device profile. The device acquire its own 01005 //! profile, if profile message is found. The acquired AP information 01006 //! is stored in CC3000 EEPROM only in case AES128 encryption is used. 01007 //! In case AES128 encryption is not used, a profile is created by 01008 //! CC3000 internally. 01009 //! 01010 //! @Note An asynchronous event - Smart Config Done will be generated as soon 01011 //! as the process finishes successfully. 01012 //! 01013 //! @sa wlan_smart_config_set_prefix , wlan_smart_config_stop 01014 // 01015 //***************************************************************************** 01016 01017 long 01018 wlan_smart_config_start(unsigned long algoEncryptedFlag) 01019 { 01020 long ret; 01021 unsigned char *ptr; 01022 unsigned char *args; 01023 01024 ret = EFAIL; 01025 ptr = tSLInformation.pucTxCommandBuffer; 01026 args = (unsigned char *)(ptr + HEADERS_SIZE_CMD); 01027 01028 // Fill in HCI packet structure 01029 args = UINT32_TO_STREAM(args, algoEncryptedFlag); 01030 ret = EFAIL; 01031 01032 hci_command_send(HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_START, ptr, 01033 WLAN_SMART_CONFIG_START_PARAMS_LEN); 01034 01035 // Wait for command complete event 01036 SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_START, &ret); 01037 01038 return(ret); 01039 } 01040 01041 //***************************************************************************** 01042 // 01043 //! wlan_smart_config_stop 01044 //! 01045 //! @param algoEncryptedFlag indicates whether the information is encrypted 01046 //! 01047 //! @return On success, zero is returned. On error, -1 is returned 01048 //! 01049 //! @brief Stop the acquire profile procedure 01050 //! 01051 //! @sa wlan_smart_config_start , wlan_smart_config_set_prefix 01052 // 01053 //***************************************************************************** 01054 01055 long 01056 wlan_smart_config_stop(void) 01057 { 01058 long ret; 01059 unsigned char *ptr; 01060 01061 ret = EFAIL; 01062 ptr = tSLInformation.pucTxCommandBuffer; 01063 01064 hci_command_send(HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_STOP, ptr, 0); 01065 01066 // Wait for command complete event 01067 SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_STOP, &ret); 01068 01069 return(ret); 01070 } 01071 01072 //***************************************************************************** 01073 // 01074 //! wlan_smart_config_set_prefix 01075 //! 01076 //! @param newPrefix 3 bytes identify the SSID prefix for the Smart Config. 01077 //! 01078 //! @return On success, zero is returned. On error, -1 is returned 01079 //! 01080 //! @brief Configure station ssid prefix. The prefix is used internally 01081 //! in CC3000. It should always be TTT. 01082 //! 01083 //! @Note The prefix is stored in CC3000 NVMEM 01084 //! 01085 //! @sa wlan_smart_config_start , wlan_smart_config_stop 01086 // 01087 //***************************************************************************** 01088 01089 long 01090 wlan_smart_config_set_prefix(char* cNewPrefix) 01091 { 01092 long ret; 01093 unsigned char *ptr; 01094 unsigned char *args; 01095 01096 ret = EFAIL; 01097 ptr = tSLInformation.pucTxCommandBuffer; 01098 args = (ptr + HEADERS_SIZE_CMD); 01099 01100 if (cNewPrefix == NULL) 01101 return ret; 01102 else // with the new Smart Config, prefix must be TTT 01103 { 01104 *cNewPrefix = 'T'; 01105 *(cNewPrefix + 1) = 'T'; 01106 *(cNewPrefix + 2) = 'T'; 01107 } 01108 01109 ARRAY_TO_STREAM(args, cNewPrefix, SL_SIMPLE_CONFIG_PREFIX_LENGTH); 01110 01111 hci_command_send(HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_SET_PREFIX, ptr, 01112 SL_SIMPLE_CONFIG_PREFIX_LENGTH); 01113 01114 // Wait for command complete event 01115 SimpleLinkWaitEvent(HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_SET_PREFIX, &ret); 01116 01117 return(ret); 01118 } 01119 01120 //***************************************************************************** 01121 // 01122 //! wlan_smart_config_process 01123 //! 01124 //! @param none 01125 //! 01126 //! @return On success, zero is returned. On error, -1 is returned 01127 //! 01128 //! @brief process the acquired data and store it as a profile. The acquired 01129 //! AP information is stored in CC3000 EEPROM encrypted. 01130 //! The encrypted data is decrypted and stored as a profile. 01131 //! behavior is as defined by connection policy. 01132 // 01133 //***************************************************************************** 01134 01135 01136 #ifndef CC3000_UNENCRYPTED_SMART_CONFIG 01137 long 01138 wlan_smart_config_process() 01139 { 01140 signed long returnValue; 01141 unsigned long ssidLen, keyLen; 01142 unsigned char *decKeyPtr; 01143 unsigned char *ssidPtr; 01144 01145 // read the key from EEPROM - fileID 12 01146 returnValue = aes_read_key(key); 01147 01148 if (returnValue != 0) 01149 return returnValue; 01150 01151 // read the received data from fileID #13 and parse it according to the followings: 01152 // 1) SSID LEN - not encrypted 01153 // 2) SSID - not encrypted 01154 // 3) KEY LEN - not encrypted. always 32 bytes long 01155 // 4) Security type - not encrypted 01156 // 5) KEY - encrypted together with true key length as the first byte in KEY 01157 // to elaborate, there are two corner cases: 01158 // 1) the KEY is 32 bytes long. In this case, the first byte does not represent KEY length 01159 // 2) the KEY is 31 bytes long. In this case, the first byte represent KEY length and equals 31 01160 returnValue = nvmem_read(NVMEM_SHARED_MEM_FILEID, SMART_CONFIG_PROFILE_SIZE, 0, profileArray); 01161 01162 if (returnValue != 0) 01163 return returnValue; 01164 01165 ssidPtr = &profileArray[1]; 01166 01167 ssidLen = profileArray[0]; 01168 01169 decKeyPtr = &profileArray[profileArray[0] + 3]; 01170 01171 aes_decrypt(decKeyPtr, key); 01172 if (profileArray[profileArray[0] + 1] > 16) 01173 aes_decrypt((unsigned char *)(decKeyPtr + 16), key); 01174 01175 if (*(unsigned char *)(decKeyPtr +31) != 0) 01176 { 01177 if (*decKeyPtr == 31) 01178 { 01179 keyLen = 31; 01180 decKeyPtr++; 01181 } 01182 else 01183 { 01184 keyLen = 32; 01185 } 01186 } 01187 else 01188 { 01189 keyLen = *decKeyPtr; 01190 decKeyPtr++; 01191 } 01192 01193 // add a profile 01194 switch (profileArray[profileArray[0] + 2]) 01195 { 01196 case WLAN_SEC_UNSEC://None 01197 { 01198 returnValue = wlan_add_profile(profileArray[profileArray[0] + 2], // security type 01199 ssidPtr, // SSID 01200 ssidLen, // SSID length 01201 NULL, // BSSID 01202 1, // Priority 01203 0, 0, 0, 0, 0); 01204 01205 break; 01206 } 01207 01208 case WLAN_SEC_WEP://WEP 01209 { 01210 returnValue = wlan_add_profile(profileArray[profileArray[0] + 2], // security type 01211 ssidPtr, // SSID 01212 ssidLen, // SSID length 01213 NULL, // BSSID 01214 1, // Priority 01215 keyLen, // KEY length 01216 0, // KEY index 01217 0, 01218 decKeyPtr, // KEY 01219 0); 01220 01221 break; 01222 } 01223 01224 case WLAN_SEC_WPA://WPA 01225 case WLAN_SEC_WPA2://WPA2 01226 { 01227 returnValue = wlan_add_profile(WLAN_SEC_WPA2, // security type 01228 ssidPtr, 01229 ssidLen, 01230 NULL, // BSSID 01231 1, // Priority 01232 0x18, // PairwiseCipher 01233 0x1e, // GroupCipher 01234 2, // KEY management 01235 decKeyPtr, // KEY 01236 keyLen); // KEY length 01237 01238 break; 01239 } 01240 } 01241 01242 return returnValue; 01243 } 01244 #endif //CC3000_UNENCRYPTED_SMART_CONFIG 01245 01246 //***************************************************************************** 01247 // 01248 // Close the Doxygen group. 01249 //! @} 01250 // 01251 //***************************************************************************** 01252
Generated on Wed Jul 13 2022 13:30:51 by
1.7.2