2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 * Purpose: handle wpa supplicant ioctl input/out functions
34 #if !defined(__WPACTL_H__)
37 #if !defined(__KEY_H__)
40 #if !defined(__MAC_H__)
43 #if !defined(__DEVICE_H__)
46 #if !defined(__WMGR_H__)
49 #if !defined(__IOCMD_H__)
52 #if !defined(__IOWPA_H__)
55 //2008-0717-05, <Add> by James
56 #if !defined(__RF_H__)
60 /*--------------------- Static Definitions -------------------------*/
62 #define VIAWGET_WPA_MAX_BUF_SIZE 1024
66 static const int frequency_list[] = {
67 2412, 2417, 2422, 2427, 2432, 2437, 2442,
68 2447, 2452, 2457, 2462, 2467, 2472, 2484
70 /*--------------------- Static Classes ----------------------------*/
72 /*--------------------- Static Variables --------------------------*/
73 //static int msglevel =MSG_LEVEL_DEBUG;
74 static int msglevel =MSG_LEVEL_INFO;
76 /*--------------------- Static Functions --------------------------*/
81 /*--------------------- Export Variables --------------------------*/
84 static void wpadev_setup(struct net_device *dev)
86 dev->type = ARPHRD_IEEE80211;
87 dev->hard_header_len = ETH_HLEN;
89 dev->addr_len = ETH_ALEN;
90 dev->tx_queue_len = 1000;
92 memset(dev->broadcast,0xFF, ETH_ALEN);
94 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
101 * register netdev for wpa supplicant deamon
113 static int wpa_init_wpadev(PSDevice pDevice)
115 PSDevice wpadev_priv;
116 struct net_device *dev = pDevice->dev;
119 pDevice->wpadev = alloc_netdev(sizeof(PSDevice), "vntwpa", wpadev_setup);
120 if (pDevice->wpadev == NULL)
123 wpadev_priv = netdev_priv(pDevice->wpadev);
124 *wpadev_priv = *pDevice;
126 memcpy(pDevice->wpadev->dev_addr, dev->dev_addr, U_ETHER_ADDR_LEN);
127 pDevice->wpadev->base_addr = dev->base_addr;
128 pDevice->wpadev->irq = dev->irq;
129 pDevice->wpadev->mem_start = dev->mem_start;
130 pDevice->wpadev->mem_end = dev->mem_end;
131 ret = register_netdev(pDevice->wpadev);
133 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: register_netdev(WPA) failed!\n",
135 free_netdev(pDevice->wpadev);
139 if (pDevice->skb == NULL) {
140 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
141 if (pDevice->skb == NULL)
145 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Registered netdev %s for WPA management\n",
146 dev->name, pDevice->wpadev->name);
154 * unregister net_device (wpadev)
165 static int wpa_release_wpadev(PSDevice pDevice)
169 dev_kfree_skb(pDevice->skb);
173 if (pDevice->wpadev) {
174 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Netdevice %s unregistered\n",
175 pDevice->dev->name, pDevice->wpadev->name);
176 unregister_netdev(pDevice->wpadev);
177 free_netdev(pDevice->wpadev);
178 pDevice->wpadev = NULL;
190 * Set enable/disable dev for wpa supplicant deamon
202 int wpa_set_wpadev(PSDevice pDevice, int val)
207 return wpa_init_wpadev(pDevice);
209 return wpa_release_wpadev(pDevice);
215 * Set WPA algorithm & keys
227 int wpa_set_keys(PSDevice pDevice, void *ctx, BOOL fcpfkernel)
229 struct viawget_wpa_param *param=ctx;
230 PSMgmtObject pMgmt = pDevice->pMgmt;
231 DWORD dwKeyIndex = 0;
232 BYTE abyKey[MAX_KEY_LEN];
233 BYTE abySeq[MAX_KEY_LEN];
235 // NDIS_802_11_KEY_RSC KeyRSC;
236 BYTE byKeyDecMode = KEY_CTL_WEP;
241 if (param->u.wpa_key.alg_name > WPA_ALG_CCMP)
244 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "param->u.wpa_key.alg_name = %d \n", param->u.wpa_key.alg_name);
245 if (param->u.wpa_key.alg_name == WPA_ALG_NONE) {
246 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
247 pDevice->bEncryptionEnable = FALSE;
248 pDevice->byKeyIndex = 0;
249 pDevice->bTransmitKey = FALSE;
250 KeyvRemoveAllWEPKey(&(pDevice->sKey), pDevice->PortOffset);
251 for (uu=0; uu<MAX_KEY_TABLE; uu++) {
252 MACvDisableKeyEntry(pDevice->PortOffset, uu);
257 //spin_unlock_irq(&pDevice->lock);
258 if(param->u.wpa_key.key && fcpfkernel) {
259 memcpy(&abyKey[0], param->u.wpa_key.key, param->u.wpa_key.key_len);
262 spin_unlock_irq(&pDevice->lock);
263 if (param->u.wpa_key.key &&
264 copy_from_user(&abyKey[0], param->u.wpa_key.key, param->u.wpa_key.key_len)){
265 spin_lock_irq(&pDevice->lock);
268 spin_lock_irq(&pDevice->lock);
271 dwKeyIndex = (DWORD)(param->u.wpa_key.key_index);
273 if (param->u.wpa_key.alg_name == WPA_ALG_WEP) {
274 if (dwKeyIndex > 3) {
278 if (param->u.wpa_key.set_tx) {
279 pDevice->byKeyIndex = (BYTE)dwKeyIndex;
280 pDevice->bTransmitKey = TRUE;
281 dwKeyIndex |= (1 << 31);
283 KeybSetDefaultKey(&(pDevice->sKey),
284 dwKeyIndex & ~(BIT30 | USE_KEYRSC),
285 param->u.wpa_key.key_len,
293 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
294 pDevice->bEncryptionEnable = TRUE;
298 //spin_unlock_irq(&pDevice->lock);
299 if(param->u.wpa_key.seq && fcpfkernel) {
300 memcpy(&abySeq[0], param->u.wpa_key.seq, param->u.wpa_key.seq_len);
303 spin_unlock_irq(&pDevice->lock);
304 if (param->u.wpa_key.seq &&
305 copy_from_user(&abySeq[0], param->u.wpa_key.seq, param->u.wpa_key.seq_len)){
307 spin_lock_irq(&pDevice->lock);
310 spin_lock_irq(&pDevice->lock);
313 if (param->u.wpa_key.seq_len > 0) {
314 for (ii = 0 ; ii < param->u.wpa_key.seq_len ; ii++) {
316 LODWORD(KeyRSC) |= (abySeq[ii] << (ii * 8));
318 HIDWORD(KeyRSC) |= (abySeq[ii] << ((ii-4) * 8));
319 //KeyRSC |= (abySeq[ii] << (ii * 8));
321 dwKeyIndex |= 1 << 29;
324 if (param->u.wpa_key.key_index >= MAX_GROUP_KEY) {
325 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "return dwKeyIndex > 3\n");
329 if (param->u.wpa_key.alg_name == WPA_ALG_TKIP) {
330 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
333 if (param->u.wpa_key.alg_name == WPA_ALG_CCMP) {
334 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
337 if (param->u.wpa_key.set_tx)
338 dwKeyIndex |= (1 << 31);
340 if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled)
341 byKeyDecMode = KEY_CTL_CCMP;
342 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled)
343 byKeyDecMode = KEY_CTL_TKIP;
345 byKeyDecMode = KEY_CTL_WEP;
347 // Fix HCT test that set 256 bits KEY and Ndis802_11Encryption3Enabled
348 if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
349 if (param->u.wpa_key.key_len == MAX_KEY_LEN)
350 byKeyDecMode = KEY_CTL_TKIP;
351 else if (param->u.wpa_key.key_len == WLAN_WEP40_KEYLEN)
352 byKeyDecMode = KEY_CTL_WEP;
353 else if (param->u.wpa_key.key_len == WLAN_WEP104_KEYLEN)
354 byKeyDecMode = KEY_CTL_WEP;
355 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
356 if (param->u.wpa_key.key_len == WLAN_WEP40_KEYLEN)
357 byKeyDecMode = KEY_CTL_WEP;
358 else if (param->u.wpa_key.key_len == WLAN_WEP104_KEYLEN)
359 byKeyDecMode = KEY_CTL_WEP;
363 // Check TKIP key length
364 if ((byKeyDecMode == KEY_CTL_TKIP) &&
365 (param->u.wpa_key.key_len != MAX_KEY_LEN)) {
366 // TKIP Key must be 256 bits
367 //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA - TKIP Key must be 256 bits\n"));
368 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "return- TKIP Key must be 256 bits!\n");
371 // Check AES key length
372 if ((byKeyDecMode == KEY_CTL_CCMP) &&
373 (param->u.wpa_key.key_len != AES_KEY_LEN)) {
374 // AES Key must be 128 bits
375 //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA - AES Key must be 128 bits\n"));
379 // spin_lock_irq(&pDevice->lock);
380 if (IS_BROADCAST_ADDRESS(¶m->addr[0]) || (param->addr == NULL)) {
381 // If IS_BROADCAST_ADDRESS, set the key as every key entry's group key.
382 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Groupe Key Assign.\n");
384 if ((KeybSetAllGroupKey(&(pDevice->sKey),
386 param->u.wpa_key.key_len,
391 pDevice->byLocalID) == TRUE) &&
392 (KeybSetDefaultKey(&(pDevice->sKey),
394 param->u.wpa_key.key_len,
399 pDevice->byLocalID) == TRUE) ) {
400 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "GROUP Key Assign.\n");
403 //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA -KeybSetDefaultKey Fail.0\n"));
404 // spin_unlock_irq(&pDevice->lock);
409 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pairwise Key Assign.\n");
410 // BSSID not 0xffffffffffff
411 // Pairwise Key can't be WEP
412 if (byKeyDecMode == KEY_CTL_WEP) {
413 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pairwise Key can't be WEP\n");
414 //spin_unlock_irq(&pDevice->lock);
418 dwKeyIndex |= (1 << 30); // set pairwise key
419 if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) {
420 //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA - WMAC_CONFIG_IBSS_STA\n"));
421 //spin_unlock_irq(&pDevice->lock);
424 if (KeybSetKey(&(pDevice->sKey),
427 param->u.wpa_key.key_len,
432 pDevice->byLocalID) == TRUE) {
433 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pairwise Key Set\n");
437 if (IS_ETH_ADDRESS_EQUAL(¶m->addr[0], pDevice->abyBSSID)) {
438 //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA -Key Table Full.2\n"));
439 //spin_unlock_irq(&pDevice->lock);
443 // Save Key and configure just before associate/reassociate to BSSID
444 // we do not implement now
445 //spin_unlock_irq(&pDevice->lock);
449 } // BSSID not 0xffffffffffff
450 if ((ret == 0) && ((param->u.wpa_key.set_tx) != 0)) {
451 pDevice->byKeyIndex = (BYTE)param->u.wpa_key.key_index;
452 pDevice->bTransmitKey = TRUE;
454 pDevice->bEncryptionEnable = TRUE;
455 //spin_unlock_irq(&pDevice->lock);
458 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " key=%x-%x-%x-%x-%x-xxxxx \n",
459 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][0],
460 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][1],
461 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][2],
462 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][3],
463 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][4]
474 * enable wpa auth & mode
486 static int wpa_set_wpa(PSDevice pDevice,
487 struct viawget_wpa_param *param)
490 PSMgmtObject pMgmt = pDevice->pMgmt;
493 pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
494 pMgmt->bShareKeyAlgorithm = FALSE;
516 static int wpa_set_disassociate(PSDevice pDevice,
517 struct viawget_wpa_param *param)
519 PSMgmtObject pMgmt = pDevice->pMgmt;
522 spin_lock_irq(&pDevice->lock);
523 if (pDevice->bLinkPass) {
524 if (!memcmp(param->addr, pMgmt->abyCurrBSSID, 6))
525 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_DISASSOCIATE, NULL);
527 spin_unlock_irq(&pDevice->lock);
536 * enable scan process
548 static int wpa_set_scan(PSDevice pDevice,
549 struct viawget_wpa_param *param)
553 spin_lock_irq(&pDevice->lock);
554 BSSvClearBSSList((HANDLE)pDevice, pDevice->bLinkPass);
555 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, NULL);
556 spin_unlock_irq(&pDevice->lock);
577 static int wpa_get_bssid(PSDevice pDevice,
578 struct viawget_wpa_param *param)
580 PSMgmtObject pMgmt = pDevice->pMgmt;
583 memcpy(param->u.wpa_associate.bssid, pMgmt->abyCurrBSSID , 6);
604 static int wpa_get_ssid(PSDevice pDevice,
605 struct viawget_wpa_param *param)
607 PSMgmtObject pMgmt = pDevice->pMgmt;
608 PWLAN_IE_SSID pItemSSID;
611 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
613 memcpy(param->u.wpa_associate.ssid, pItemSSID->abySSID , pItemSSID->len);
614 param->u.wpa_associate.ssid_len = pItemSSID->len;
635 static int wpa_get_scan(PSDevice pDevice,
636 struct viawget_wpa_param *param)
638 struct viawget_scan_result *scan_buf;
639 PSMgmtObject pMgmt = pDevice->pMgmt;
640 PWLAN_IE_SSID pItemSSID;
652 ptempBSS = kmalloc(sizeof(KnownBSS), (int)GFP_ATOMIC);
654 if (ptempBSS == NULL) {
656 printk("bubble sort kmalloc memory fail@@@\n");
664 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
666 for(jj=0;jj<MAX_BSS_NUM-ii-1;jj++) {
668 if((pMgmt->sBSSList[jj].bActive!=TRUE) ||
670 ((pMgmt->sBSSList[jj].uRSSI>pMgmt->sBSSList[jj+1].uRSSI) &&(pMgmt->sBSSList[jj+1].bActive!=FALSE))) {
672 memcpy(ptempBSS,&pMgmt->sBSSList[jj],sizeof(KnownBSS));
674 memcpy(&pMgmt->sBSSList[jj],&pMgmt->sBSSList[jj+1],sizeof(KnownBSS));
676 memcpy(&pMgmt->sBSSList[jj+1],ptempBSS,sizeof(KnownBSS));
686 // printk("bubble sort result:\n");
688 //for (ii = 0; ii < MAX_BSS_NUM; ii++)
690 // printk("%d [%s]:RSSI=%d\n",ii,((PWLAN_IE_SSID)(pMgmt->sBSSList[ii].abySSID))->abySSID,
692 // pMgmt->sBSSList[ii].uRSSI);
696 //******mike:bubble sort by stronger RSSI*****//
702 pBSS = &(pMgmt->sBSSList[0]);
703 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
704 pBSS = &(pMgmt->sBSSList[ii]);
710 pBuf = kmalloc(sizeof(struct viawget_scan_result) * count, (int)GFP_ATOMIC);
716 memset(pBuf, 0, sizeof(struct viawget_scan_result) * count);
717 scan_buf = (struct viawget_scan_result *)pBuf;
718 pBSS = &(pMgmt->sBSSList[0]);
719 for (ii = 0, jj = 0; ii < MAX_BSS_NUM ; ii++) {
720 pBSS = &(pMgmt->sBSSList[ii]);
724 memcpy(scan_buf->bssid, pBSS->abyBSSID, WLAN_BSSID_LEN);
725 pItemSSID = (PWLAN_IE_SSID)pBSS->abySSID;
726 memcpy(scan_buf->ssid, pItemSSID->abySSID, pItemSSID->len);
727 scan_buf->ssid_len = pItemSSID->len;
728 scan_buf->freq = frequency_list[pBSS->uChannel-1];
729 scan_buf->caps = pBSS->wCapInfo;
730 //scan_buf->caps = pBSS->wCapInfo;
734 //scan_buf->maxrate =
735 if (pBSS->wWPALen != 0) {
736 scan_buf->wpa_ie_len = pBSS->wWPALen;
737 memcpy(scan_buf->wpa_ie, pBSS->byWPAIE, pBSS->wWPALen);
739 if (pBSS->wRSNLen != 0) {
740 scan_buf->rsn_ie_len = pBSS->wRSNLen;
741 memcpy(scan_buf->rsn_ie, pBSS->byRSNIE, pBSS->wRSNLen);
743 scan_buf = (struct viawget_scan_result *)((PBYTE)scan_buf + sizeof(struct viawget_scan_result));
751 if (copy_to_user(param->u.scan_results.buf, pBuf, sizeof(struct viawget_scan_result) * count)) {
754 param->u.scan_results.scan_count = count;
755 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " param->u.scan_results.scan_count = %d\n", count)
765 * set associate with AP
777 static int wpa_set_associate(PSDevice pDevice,
778 struct viawget_wpa_param *param)
780 PSMgmtObject pMgmt = pDevice->pMgmt;
781 PWLAN_IE_SSID pItemSSID;
782 BYTE abyNullAddr[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
785 BOOL bWepEnabled=FALSE;
787 // set key type & algorithm
788 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pairwise_suite = %d\n", param->u.wpa_associate.pairwise_suite);
789 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "group_suite = %d\n", param->u.wpa_associate.group_suite);
790 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "key_mgmt_suite = %d\n", param->u.wpa_associate.key_mgmt_suite);
791 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "auth_alg = %d\n", param->u.wpa_associate.auth_alg);
792 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "mode = %d\n", param->u.wpa_associate.mode);
793 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wpa_ie_len = %d\n", param->u.wpa_associate.wpa_ie_len);
796 if (param->u.wpa_associate.wpa_ie &&
797 copy_from_user(&abyWPAIE[0], param->u.wpa_associate.wpa_ie, param->u.wpa_associate.wpa_ie_len))
800 if (param->u.wpa_associate.mode == 1)
801 pMgmt->eConfigMode = WMAC_CONFIG_IBSS_STA;
803 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
805 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
806 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
807 pItemSSID->byElementID = WLAN_EID_SSID;
808 pItemSSID->len = param->u.wpa_associate.ssid_len;
809 memcpy(pItemSSID->abySSID, param->u.wpa_associate.ssid, pItemSSID->len);
811 if (memcmp(param->u.wpa_associate.bssid, &abyNullAddr[0], 6) != 0)
812 memcpy(pMgmt->abyDesireBSSID, param->u.wpa_associate.bssid, 6);
815 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, pItemSSID->abySSID);
818 if (param->u.wpa_associate.wpa_ie_len == 0) {
819 if (param->u.wpa_associate.auth_alg & AUTH_ALG_SHARED_KEY)
820 pMgmt->eAuthenMode = WMAC_AUTH_SHAREKEY;
822 pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
823 } else if (abyWPAIE[0] == RSN_INFO_ELEM) {
824 if (param->u.wpa_associate.key_mgmt_suite == KEY_MGMT_PSK)
825 pMgmt->eAuthenMode = WMAC_AUTH_WPA2PSK;
827 pMgmt->eAuthenMode = WMAC_AUTH_WPA2;
829 if (param->u.wpa_associate.key_mgmt_suite == KEY_MGMT_WPA_NONE)
830 pMgmt->eAuthenMode = WMAC_AUTH_WPANONE;
831 else if (param->u.wpa_associate.key_mgmt_suite == KEY_MGMT_PSK)
832 pMgmt->eAuthenMode = WMAC_AUTH_WPAPSK;
834 pMgmt->eAuthenMode = WMAC_AUTH_WPA;
837 switch (param->u.wpa_associate.pairwise_suite) {
839 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
842 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
846 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
850 if (param->u.wpa_associate.group_suite == CIPHER_CCMP)
851 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
853 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
856 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
859 //DavidWang add for WPA_supplicant support open/share mode
861 if (pMgmt->eAuthenMode == WMAC_AUTH_SHAREKEY) {
862 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
863 //pMgmt->eAuthenMode = WMAC_AUTH_SHAREKEY;
864 pMgmt->bShareKeyAlgorithm = TRUE;
866 else if (pMgmt->eAuthenMode == WMAC_AUTH_OPEN) {
867 if(!bWepEnabled) pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
868 else pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
869 //pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
870 //pMgmt->bShareKeyAlgorithm = FALSE; //20080717-06,<Modify> by chester//Fix Open mode, WEP encrytion
872 //mike save old encryption status
873 pDevice->eOldEncryptionStatus = pDevice->eEncryptionStatus;
875 if (pDevice->eEncryptionStatus != Ndis802_11EncryptionDisabled)
876 pDevice->bEncryptionEnable = TRUE;
878 pDevice->bEncryptionEnable = FALSE;
879 if (!((pMgmt->eAuthenMode == WMAC_AUTH_SHAREKEY) ||
880 ((pMgmt->eAuthenMode == WMAC_AUTH_OPEN) && (bWepEnabled==TRUE))) ) //DavidWang //20080717-06,<Modify> by chester//Not to initial WEP
881 KeyvInitTable(&pDevice->sKey, pDevice->PortOffset);
882 spin_lock_irq(&pDevice->lock);
883 pDevice->bLinkPass = FALSE;
884 memset(pMgmt->abyCurrBSSID, 0, 6);
885 pMgmt->eCurrState = WMAC_STATE_IDLE;
886 netif_stop_queue(pDevice->dev);
887 //20080701-02,<Add> by Mike Liu
888 /*******search if ap_scan=2 ,which is associating request in hidden ssid mode ****/
890 PKnownBSS pCurr = NULL;
891 pCurr = BSSpSearchBSSList(pDevice,
892 pMgmt->abyDesireBSSID,
893 pMgmt->abyDesireSSID,
894 pMgmt->eConfigPHYMode
898 printk("wpa_set_associate---->hidden mode site survey before associate.......\n");
899 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
902 /****************************************************************/
903 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_SSID, NULL);
904 spin_unlock_irq(&pDevice->lock);
912 * wpa_ioctl main function supported for wpa supplicant
924 int wpa_ioctl(PSDevice pDevice, struct iw_point *p)
926 struct viawget_wpa_param *param;
930 if (p->length < sizeof(struct viawget_wpa_param) ||
931 p->length > VIAWGET_WPA_MAX_BUF_SIZE || !p->pointer)
934 param = (struct viawget_wpa_param *) kmalloc((int)p->length, (int)GFP_KERNEL);
938 if (copy_from_user(param, p->pointer, p->length)) {
943 switch (param->cmd) {
944 case VIAWGET_SET_WPA:
945 ret = wpa_set_wpa(pDevice, param);
946 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_WPA \n");
949 case VIAWGET_SET_KEY:
950 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_KEY \n");
951 spin_lock_irq(&pDevice->lock);
952 ret = wpa_set_keys(pDevice, param, FALSE);
953 spin_unlock_irq(&pDevice->lock);
956 case VIAWGET_SET_SCAN:
957 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_SCAN \n");
958 ret = wpa_set_scan(pDevice, param);
961 case VIAWGET_GET_SCAN:
962 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_GET_SCAN\n");
963 ret = wpa_get_scan(pDevice, param);
967 case VIAWGET_GET_SSID:
968 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_GET_SSID \n");
969 ret = wpa_get_ssid(pDevice, param);
973 case VIAWGET_GET_BSSID:
974 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_GET_BSSID \n");
975 ret = wpa_get_bssid(pDevice, param);
979 case VIAWGET_SET_ASSOCIATE:
980 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_ASSOCIATE \n");
981 ret = wpa_set_associate(pDevice, param);
984 case VIAWGET_SET_DISASSOCIATE:
985 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_DISASSOCIATE \n");
986 ret = wpa_set_disassociate(pDevice, param);
989 case VIAWGET_SET_DROP_UNENCRYPT:
990 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_DROP_UNENCRYPT \n");
993 case VIAWGET_SET_DEAUTHENTICATE:
994 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_DEAUTHENTICATE \n");
998 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wpa_ioctl: unknown cmd=%d\n",
1004 if ((ret == 0) && wpa_ioctl) {
1005 if (copy_to_user(p->pointer, param, p->length)) {