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.
22 * Purpose: handle wpa supplicant ioctl input/out functions
43 /*--------------------- Static Definitions -------------------------*/
45 #define VIAWGET_WPA_MAX_BUF_SIZE 1024
47 static const int frequency_list
[] = {
48 2412, 2417, 2422, 2427, 2432, 2437, 2442,
49 2447, 2452, 2457, 2462, 2467, 2472, 2484
51 /*--------------------- Static Classes ----------------------------*/
53 /*--------------------- Static Variables --------------------------*/
54 //static int msglevel =MSG_LEVEL_DEBUG;
55 static int msglevel
= MSG_LEVEL_INFO
;
57 /*--------------------- Static Functions --------------------------*/
59 /*--------------------- Export Variables --------------------------*/
60 static void wpadev_setup(struct net_device
*dev
)
62 dev
->type
= ARPHRD_IEEE80211
;
63 dev
->hard_header_len
= ETH_HLEN
;
65 dev
->addr_len
= ETH_ALEN
;
66 dev
->tx_queue_len
= 1000;
68 memset(dev
->broadcast
, 0xFF, ETH_ALEN
);
70 dev
->flags
= IFF_BROADCAST
|IFF_MULTICAST
;
75 * register netdev for wpa supplicant daemon
87 static int wpa_init_wpadev(PSDevice pDevice
)
90 struct net_device
*dev
= pDevice
->dev
;
93 pDevice
->wpadev
= alloc_netdev(sizeof(PSDevice
), "vntwpa", wpadev_setup
);
94 if (pDevice
->wpadev
== NULL
)
97 wpadev_priv
= netdev_priv(pDevice
->wpadev
);
98 *wpadev_priv
= *pDevice
;
99 memcpy(pDevice
->wpadev
->dev_addr
, dev
->dev_addr
, ETH_ALEN
);
100 pDevice
->wpadev
->base_addr
= dev
->base_addr
;
101 pDevice
->wpadev
->irq
= dev
->irq
;
102 pDevice
->wpadev
->mem_start
= dev
->mem_start
;
103 pDevice
->wpadev
->mem_end
= dev
->mem_end
;
104 ret
= register_netdev(pDevice
->wpadev
);
106 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%s: register_netdev(WPA) failed!\n",
108 free_netdev(pDevice
->wpadev
);
112 if (pDevice
->skb
== NULL
) {
113 pDevice
->skb
= dev_alloc_skb((int)pDevice
->rx_buf_sz
);
114 if (pDevice
->skb
== NULL
)
118 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%s: Registered netdev %s for WPA management\n",
119 dev
->name
, pDevice
->wpadev
->name
);
126 * unregister net_device (wpadev)
137 static int wpa_release_wpadev(PSDevice pDevice
)
140 dev_kfree_skb(pDevice
->skb
);
144 if (pDevice
->wpadev
) {
145 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%s: Netdevice %s unregistered\n",
146 pDevice
->dev
->name
, pDevice
->wpadev
->name
);
147 unregister_netdev(pDevice
->wpadev
);
148 free_netdev(pDevice
->wpadev
);
149 pDevice
->wpadev
= NULL
;
157 * Set enable/disable dev for wpa supplicant daemon
169 int wpa_set_wpadev(PSDevice pDevice
, int val
)
172 return wpa_init_wpadev(pDevice
);
174 return wpa_release_wpadev(pDevice
);
179 * Set WPA algorithm & keys
191 int wpa_set_keys(PSDevice pDevice
, void *ctx
, bool fcpfkernel
)
193 struct viawget_wpa_param
*param
= ctx
;
194 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
195 unsigned long dwKeyIndex
= 0;
196 unsigned char abyKey
[MAX_KEY_LEN
];
197 unsigned char abySeq
[MAX_KEY_LEN
];
199 // NDIS_802_11_KEY_RSC KeyRSC;
200 unsigned char byKeyDecMode
= KEY_CTL_WEP
;
204 if (param
->u
.wpa_key
.alg_name
> WPA_ALG_CCMP
||
205 param
->u
.wpa_key
.key_len
>= MAX_KEY_LEN
||
206 param
->u
.wpa_key
.seq_len
>= MAX_KEY_LEN
)
209 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"param->u.wpa_key.alg_name = %d \n", param
->u
.wpa_key
.alg_name
);
210 if (param
->u
.wpa_key
.alg_name
== WPA_ALG_NONE
) {
211 pDevice
->eEncryptionStatus
= Ndis802_11EncryptionDisabled
;
212 pDevice
->bEncryptionEnable
= false;
213 pDevice
->byKeyIndex
= 0;
214 pDevice
->bTransmitKey
= false;
215 KeyvRemoveAllWEPKey(&(pDevice
->sKey
), pDevice
->PortOffset
);
216 for (uu
= 0; uu
< MAX_KEY_TABLE
; uu
++) {
217 MACvDisableKeyEntry(pDevice
->PortOffset
, uu
);
222 //spin_unlock_irq(&pDevice->lock);
223 if (param
->u
.wpa_key
.key
&& fcpfkernel
) {
224 memcpy(&abyKey
[0], param
->u
.wpa_key
.key
, param
->u
.wpa_key
.key_len
);
226 spin_unlock_irq(&pDevice
->lock
);
227 if (param
->u
.wpa_key
.key
&&
228 copy_from_user(&abyKey
[0], param
->u
.wpa_key
.key
, param
->u
.wpa_key
.key_len
)) {
229 spin_lock_irq(&pDevice
->lock
);
232 spin_lock_irq(&pDevice
->lock
);
235 dwKeyIndex
= (unsigned long)(param
->u
.wpa_key
.key_index
);
237 if (param
->u
.wpa_key
.alg_name
== WPA_ALG_WEP
) {
238 if (dwKeyIndex
> 3) {
241 if (param
->u
.wpa_key
.set_tx
) {
242 pDevice
->byKeyIndex
= (unsigned char)dwKeyIndex
;
243 pDevice
->bTransmitKey
= true;
244 dwKeyIndex
|= (1 << 31);
246 KeybSetDefaultKey(&(pDevice
->sKey
),
247 dwKeyIndex
& ~(BIT30
| USE_KEYRSC
),
248 param
->u
.wpa_key
.key_len
,
256 pDevice
->eEncryptionStatus
= Ndis802_11Encryption1Enabled
;
257 pDevice
->bEncryptionEnable
= true;
261 //spin_unlock_irq(&pDevice->lock);
262 if (param
->u
.wpa_key
.seq
&& fcpfkernel
) {
263 memcpy(&abySeq
[0], param
->u
.wpa_key
.seq
, param
->u
.wpa_key
.seq_len
);
265 spin_unlock_irq(&pDevice
->lock
);
266 if (param
->u
.wpa_key
.seq
&&
267 copy_from_user(&abySeq
[0], param
->u
.wpa_key
.seq
, param
->u
.wpa_key
.seq_len
)) {
268 spin_lock_irq(&pDevice
->lock
);
271 spin_lock_irq(&pDevice
->lock
);
274 if (param
->u
.wpa_key
.seq_len
> 0) {
275 for (ii
= 0; ii
< param
->u
.wpa_key
.seq_len
; ii
++) {
277 LODWORD(KeyRSC
) |= (abySeq
[ii
] << (ii
* 8));
279 HIDWORD(KeyRSC
) |= (abySeq
[ii
] << ((ii
-4) * 8));
280 //KeyRSC |= (abySeq[ii] << (ii * 8));
282 dwKeyIndex
|= 1 << 29;
285 if (param
->u
.wpa_key
.key_index
>= MAX_GROUP_KEY
) {
286 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"return dwKeyIndex > 3\n");
290 if (param
->u
.wpa_key
.alg_name
== WPA_ALG_TKIP
) {
291 pDevice
->eEncryptionStatus
= Ndis802_11Encryption2Enabled
;
294 if (param
->u
.wpa_key
.alg_name
== WPA_ALG_CCMP
) {
295 pDevice
->eEncryptionStatus
= Ndis802_11Encryption3Enabled
;
298 if (param
->u
.wpa_key
.set_tx
)
299 dwKeyIndex
|= (1 << 31);
301 if (pDevice
->eEncryptionStatus
== Ndis802_11Encryption3Enabled
)
302 byKeyDecMode
= KEY_CTL_CCMP
;
303 else if (pDevice
->eEncryptionStatus
== Ndis802_11Encryption2Enabled
)
304 byKeyDecMode
= KEY_CTL_TKIP
;
306 byKeyDecMode
= KEY_CTL_WEP
;
308 // Fix HCT test that set 256 bits KEY and Ndis802_11Encryption3Enabled
309 if (pDevice
->eEncryptionStatus
== Ndis802_11Encryption3Enabled
) {
310 if (param
->u
.wpa_key
.key_len
== MAX_KEY_LEN
)
311 byKeyDecMode
= KEY_CTL_TKIP
;
312 else if (param
->u
.wpa_key
.key_len
== WLAN_WEP40_KEYLEN
)
313 byKeyDecMode
= KEY_CTL_WEP
;
314 else if (param
->u
.wpa_key
.key_len
== WLAN_WEP104_KEYLEN
)
315 byKeyDecMode
= KEY_CTL_WEP
;
316 } else if (pDevice
->eEncryptionStatus
== Ndis802_11Encryption2Enabled
) {
317 if (param
->u
.wpa_key
.key_len
== WLAN_WEP40_KEYLEN
)
318 byKeyDecMode
= KEY_CTL_WEP
;
319 else if (param
->u
.wpa_key
.key_len
== WLAN_WEP104_KEYLEN
)
320 byKeyDecMode
= KEY_CTL_WEP
;
323 // Check TKIP key length
324 if ((byKeyDecMode
== KEY_CTL_TKIP
) &&
325 (param
->u
.wpa_key
.key_len
!= MAX_KEY_LEN
)) {
326 // TKIP Key must be 256 bits
327 //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA - TKIP Key must be 256 bits\n"));
328 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"return- TKIP Key must be 256 bits!\n");
331 // Check AES key length
332 if ((byKeyDecMode
== KEY_CTL_CCMP
) &&
333 (param
->u
.wpa_key
.key_len
!= AES_KEY_LEN
)) {
334 // AES Key must be 128 bits
335 //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA - AES Key must be 128 bits\n"));
339 // spin_lock_irq(&pDevice->lock);
340 if (is_broadcast_ether_addr(¶m
->addr
[0]) || (param
->addr
== NULL
)) {
341 // If is_broadcast_ether_addr, set the key as every key entry's group key.
342 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Groupe Key Assign.\n");
344 if ((KeybSetAllGroupKey(&(pDevice
->sKey
),
346 param
->u
.wpa_key
.key_len
,
348 (unsigned char *)abyKey
,
351 pDevice
->byLocalID
) == true) &&
352 (KeybSetDefaultKey(&(pDevice
->sKey
),
354 param
->u
.wpa_key
.key_len
,
356 (unsigned char *)abyKey
,
359 pDevice
->byLocalID
) == true)) {
360 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"GROUP Key Assign.\n");
363 //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA -KeybSetDefaultKey Fail.0\n"));
364 // spin_unlock_irq(&pDevice->lock);
369 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Pairwise Key Assign.\n");
370 // BSSID not 0xffffffffffff
371 // Pairwise Key can't be WEP
372 if (byKeyDecMode
== KEY_CTL_WEP
) {
373 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Pairwise Key can't be WEP\n");
374 //spin_unlock_irq(&pDevice->lock);
378 dwKeyIndex
|= (1 << 30); // set pairwise key
379 if (pMgmt
->eConfigMode
== WMAC_CONFIG_IBSS_STA
) {
380 //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA - WMAC_CONFIG_IBSS_STA\n"));
381 //spin_unlock_irq(&pDevice->lock);
384 if (KeybSetKey(&(pDevice
->sKey
),
387 param
->u
.wpa_key
.key_len
,
389 (unsigned char *)abyKey
,
392 pDevice
->byLocalID
) == true) {
393 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Pairwise Key Set\n");
397 if (!compare_ether_addr(¶m
->addr
[0], pDevice
->abyBSSID
)) {
398 //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA -Key Table Full.2\n"));
399 //spin_unlock_irq(&pDevice->lock);
403 // Save Key and configure just before associate/reassociate to BSSID
404 // we do not implement now
405 //spin_unlock_irq(&pDevice->lock);
409 } // BSSID not 0xffffffffffff
410 if ((ret
== 0) && ((param
->u
.wpa_key
.set_tx
) != 0)) {
411 pDevice
->byKeyIndex
= (unsigned char)param
->u
.wpa_key
.key_index
;
412 pDevice
->bTransmitKey
= true;
414 pDevice
->bEncryptionEnable
= true;
415 //spin_unlock_irq(&pDevice->lock);
418 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " key=%x-%x-%x-%x-%x-xxxxx \n",
419 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][0],
420 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][1],
421 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][2],
422 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][3],
423 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][4]
432 * enable wpa auth & mode
444 static int wpa_set_wpa(PSDevice pDevice
,
445 struct viawget_wpa_param
*param
)
447 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
450 pMgmt
->eAuthenMode
= WMAC_AUTH_OPEN
;
451 pMgmt
->bShareKeyAlgorithm
= false;
470 static int wpa_set_disassociate(PSDevice pDevice
,
471 struct viawget_wpa_param
*param
)
473 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
476 spin_lock_irq(&pDevice
->lock
);
477 if (pDevice
->bLinkPass
) {
478 if (!memcmp(param
->addr
, pMgmt
->abyCurrBSSID
, 6))
479 bScheduleCommand((void *)pDevice
, WLAN_CMD_DISASSOCIATE
, NULL
);
481 spin_unlock_irq(&pDevice
->lock
);
488 * enable scan process
500 static int wpa_set_scan(PSDevice pDevice
,
501 struct viawget_wpa_param
*param
)
505 spin_lock_irq(&pDevice
->lock
);
506 BSSvClearBSSList((void *)pDevice
, pDevice
->bLinkPass
);
507 bScheduleCommand((void *)pDevice
, WLAN_CMD_BSSID_SCAN
, NULL
);
508 spin_unlock_irq(&pDevice
->lock
);
527 static int wpa_get_bssid(PSDevice pDevice
,
528 struct viawget_wpa_param
*param
)
530 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
533 memcpy(param
->u
.wpa_associate
.bssid
, pMgmt
->abyCurrBSSID
, 6);
552 static int wpa_get_ssid(PSDevice pDevice
,
553 struct viawget_wpa_param
*param
)
555 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
556 PWLAN_IE_SSID pItemSSID
;
559 pItemSSID
= (PWLAN_IE_SSID
)pMgmt
->abyCurrSSID
;
561 memcpy(param
->u
.wpa_associate
.ssid
, pItemSSID
->abySSID
, pItemSSID
->len
);
562 param
->u
.wpa_associate
.ssid_len
= pItemSSID
->len
;
581 static int wpa_get_scan(PSDevice pDevice
,
582 struct viawget_wpa_param
*param
)
584 struct viawget_scan_result
*scan_buf
;
585 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
586 PWLAN_IE_SSID pItemSSID
;
594 unsigned char *ptempBSS
;
596 ptempBSS
= kmalloc(sizeof(KnownBSS
), (int)GFP_ATOMIC
);
598 if (ptempBSS
== NULL
) {
599 printk("bubble sort kmalloc memory fail@@@\n");
607 for (ii
= 0; ii
< MAX_BSS_NUM
; ii
++) {
608 for (jj
= 0; jj
< MAX_BSS_NUM
- ii
- 1; jj
++) {
609 if ((pMgmt
->sBSSList
[jj
].bActive
!= true) ||
611 ((pMgmt
->sBSSList
[jj
].uRSSI
> pMgmt
->sBSSList
[jj
+ 1].uRSSI
) && (pMgmt
->sBSSList
[jj
+ 1].bActive
!= false))) {
612 memcpy(ptempBSS
, &pMgmt
->sBSSList
[jj
], sizeof(KnownBSS
));
614 memcpy(&pMgmt
->sBSSList
[jj
], &pMgmt
->sBSSList
[jj
+ 1], sizeof(KnownBSS
));
616 memcpy(&pMgmt
->sBSSList
[jj
+ 1], ptempBSS
, sizeof(KnownBSS
));
627 //******mike:bubble sort by stronger RSSI*****//
630 pBSS
= &(pMgmt
->sBSSList
[0]);
631 for (ii
= 0; ii
< MAX_BSS_NUM
; ii
++) {
632 pBSS
= &(pMgmt
->sBSSList
[ii
]);
638 pBuf
= kcalloc(count
, sizeof(struct viawget_scan_result
), (int)GFP_ATOMIC
);
644 scan_buf
= (struct viawget_scan_result
*)pBuf
;
645 pBSS
= &(pMgmt
->sBSSList
[0]);
646 for (ii
= 0, jj
= 0; ii
< MAX_BSS_NUM
; ii
++) {
647 pBSS
= &(pMgmt
->sBSSList
[ii
]);
651 memcpy(scan_buf
->bssid
, pBSS
->abyBSSID
, WLAN_BSSID_LEN
);
652 pItemSSID
= (PWLAN_IE_SSID
)pBSS
->abySSID
;
653 memcpy(scan_buf
->ssid
, pItemSSID
->abySSID
, pItemSSID
->len
);
654 scan_buf
->ssid_len
= pItemSSID
->len
;
655 scan_buf
->freq
= frequency_list
[pBSS
->uChannel
-1];
656 scan_buf
->caps
= pBSS
->wCapInfo
;
657 //scan_buf->caps = pBSS->wCapInfo;
661 //scan_buf->maxrate =
662 if (pBSS
->wWPALen
!= 0) {
663 scan_buf
->wpa_ie_len
= pBSS
->wWPALen
;
664 memcpy(scan_buf
->wpa_ie
, pBSS
->byWPAIE
, pBSS
->wWPALen
);
666 if (pBSS
->wRSNLen
!= 0) {
667 scan_buf
->rsn_ie_len
= pBSS
->wRSNLen
;
668 memcpy(scan_buf
->rsn_ie
, pBSS
->byRSNIE
, pBSS
->wRSNLen
);
670 scan_buf
= (struct viawget_scan_result
*)((unsigned char *)scan_buf
+ sizeof(struct viawget_scan_result
));
678 if (copy_to_user(param
->u
.scan_results
.buf
, pBuf
, sizeof(struct viawget_scan_result
) * count
)) {
681 param
->u
.scan_results
.scan_count
= count
;
682 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" param->u.scan_results.scan_count = %d\n", count
)
690 * set associate with AP
702 static int wpa_set_associate(PSDevice pDevice
,
703 struct viawget_wpa_param
*param
)
705 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
706 PWLAN_IE_SSID pItemSSID
;
707 unsigned char abyNullAddr
[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
708 unsigned char abyWPAIE
[64];
710 bool bWepEnabled
= false;
712 // set key type & algorithm
713 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pairwise_suite = %d\n", param
->u
.wpa_associate
.pairwise_suite
);
714 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"group_suite = %d\n", param
->u
.wpa_associate
.group_suite
);
715 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"key_mgmt_suite = %d\n", param
->u
.wpa_associate
.key_mgmt_suite
);
716 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"auth_alg = %d\n", param
->u
.wpa_associate
.auth_alg
);
717 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"mode = %d\n", param
->u
.wpa_associate
.mode
);
718 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"wpa_ie_len = %d\n", param
->u
.wpa_associate
.wpa_ie_len
);
720 if (param
->u
.wpa_associate
.wpa_ie_len
) {
721 if (!param
->u
.wpa_associate
.wpa_ie
)
723 if (param
->u
.wpa_associate
.wpa_ie_len
> sizeof(abyWPAIE
))
725 if (copy_from_user(&abyWPAIE
[0], param
->u
.wpa_associate
.wpa_ie
, param
->u
.wpa_associate
.wpa_ie_len
))
729 if (param
->u
.wpa_associate
.mode
== 1)
730 pMgmt
->eConfigMode
= WMAC_CONFIG_IBSS_STA
;
732 pMgmt
->eConfigMode
= WMAC_CONFIG_ESS_STA
;
734 memset(pMgmt
->abyDesireSSID
, 0, WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
+ 1);
735 pItemSSID
= (PWLAN_IE_SSID
)pMgmt
->abyDesireSSID
;
736 pItemSSID
->byElementID
= WLAN_EID_SSID
;
737 pItemSSID
->len
= param
->u
.wpa_associate
.ssid_len
;
738 memcpy(pItemSSID
->abySSID
, param
->u
.wpa_associate
.ssid
, pItemSSID
->len
);
740 if (memcmp(param
->u
.wpa_associate
.bssid
, &abyNullAddr
[0], 6) != 0)
741 memcpy(pMgmt
->abyDesireBSSID
, param
->u
.wpa_associate
.bssid
, 6);
743 bScheduleCommand((void *)pDevice
, WLAN_CMD_BSSID_SCAN
, pItemSSID
->abySSID
);
746 if (param
->u
.wpa_associate
.wpa_ie_len
== 0) {
747 if (param
->u
.wpa_associate
.auth_alg
& AUTH_ALG_SHARED_KEY
)
748 pMgmt
->eAuthenMode
= WMAC_AUTH_SHAREKEY
;
750 pMgmt
->eAuthenMode
= WMAC_AUTH_OPEN
;
751 } else if (abyWPAIE
[0] == RSN_INFO_ELEM
) {
752 if (param
->u
.wpa_associate
.key_mgmt_suite
== KEY_MGMT_PSK
)
753 pMgmt
->eAuthenMode
= WMAC_AUTH_WPA2PSK
;
755 pMgmt
->eAuthenMode
= WMAC_AUTH_WPA2
;
757 if (param
->u
.wpa_associate
.key_mgmt_suite
== KEY_MGMT_WPA_NONE
)
758 pMgmt
->eAuthenMode
= WMAC_AUTH_WPANONE
;
759 else if (param
->u
.wpa_associate
.key_mgmt_suite
== KEY_MGMT_PSK
)
760 pMgmt
->eAuthenMode
= WMAC_AUTH_WPAPSK
;
762 pMgmt
->eAuthenMode
= WMAC_AUTH_WPA
;
765 switch (param
->u
.wpa_associate
.pairwise_suite
) {
767 pDevice
->eEncryptionStatus
= Ndis802_11Encryption3Enabled
;
770 pDevice
->eEncryptionStatus
= Ndis802_11Encryption2Enabled
;
774 pDevice
->eEncryptionStatus
= Ndis802_11Encryption1Enabled
;
778 if (param
->u
.wpa_associate
.group_suite
== CIPHER_CCMP
)
779 pDevice
->eEncryptionStatus
= Ndis802_11Encryption3Enabled
;
781 pDevice
->eEncryptionStatus
= Ndis802_11Encryption2Enabled
;
784 pDevice
->eEncryptionStatus
= Ndis802_11EncryptionDisabled
;
787 //DavidWang add for WPA_supplicant support open/share mode
789 if (pMgmt
->eAuthenMode
== WMAC_AUTH_SHAREKEY
) {
790 pDevice
->eEncryptionStatus
= Ndis802_11Encryption1Enabled
;
791 //pMgmt->eAuthenMode = WMAC_AUTH_SHAREKEY;
792 pMgmt
->bShareKeyAlgorithm
= true;
793 } else if (pMgmt
->eAuthenMode
== WMAC_AUTH_OPEN
) {
794 if (!bWepEnabled
) pDevice
->eEncryptionStatus
= Ndis802_11EncryptionDisabled
;
795 else pDevice
->eEncryptionStatus
= Ndis802_11Encryption1Enabled
;
796 //pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
797 //pMgmt->bShareKeyAlgorithm = false; //20080717-06,<Modify> by chester//Fix Open mode, WEP encryption
799 //mike save old encryption status
800 pDevice
->eOldEncryptionStatus
= pDevice
->eEncryptionStatus
;
802 if (pDevice
->eEncryptionStatus
!= Ndis802_11EncryptionDisabled
)
803 pDevice
->bEncryptionEnable
= true;
805 pDevice
->bEncryptionEnable
= false;
806 if (!((pMgmt
->eAuthenMode
== WMAC_AUTH_SHAREKEY
) ||
807 ((pMgmt
->eAuthenMode
== WMAC_AUTH_OPEN
) && (bWepEnabled
== true)))) //DavidWang //20080717-06,<Modify> by chester//Not to initial WEP
808 KeyvInitTable(&pDevice
->sKey
, pDevice
->PortOffset
);
809 spin_lock_irq(&pDevice
->lock
);
810 pDevice
->bLinkPass
= false;
811 memset(pMgmt
->abyCurrBSSID
, 0, 6);
812 pMgmt
->eCurrState
= WMAC_STATE_IDLE
;
813 netif_stop_queue(pDevice
->dev
);
814 //20080701-02,<Add> by Mike Liu
815 /*******search if ap_scan=2 ,which is associating request in hidden ssid mode ****/
817 PKnownBSS pCurr
= NULL
;
818 pCurr
= BSSpSearchBSSList(pDevice
,
819 pMgmt
->abyDesireBSSID
,
820 pMgmt
->abyDesireSSID
,
821 pMgmt
->eConfigPHYMode
825 printk("wpa_set_associate---->hidden mode site survey before associate.......\n");
826 bScheduleCommand((void *)pDevice
, WLAN_CMD_BSSID_SCAN
, pMgmt
->abyDesireSSID
);
829 /****************************************************************/
830 bScheduleCommand((void *)pDevice
, WLAN_CMD_SSID
, NULL
);
831 spin_unlock_irq(&pDevice
->lock
);
838 * wpa_ioctl main function supported for wpa supplicant
850 int wpa_ioctl(PSDevice pDevice
, struct iw_point
*p
)
852 struct viawget_wpa_param
*param
;
856 if (p
->length
< sizeof(struct viawget_wpa_param
) ||
857 p
->length
> VIAWGET_WPA_MAX_BUF_SIZE
|| !p
->pointer
)
860 param
= kmalloc((int)p
->length
, (int)GFP_KERNEL
);
864 if (copy_from_user(param
, p
->pointer
, p
->length
)) {
869 switch (param
->cmd
) {
870 case VIAWGET_SET_WPA
:
871 ret
= wpa_set_wpa(pDevice
, param
);
872 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"VIAWGET_SET_WPA \n");
875 case VIAWGET_SET_KEY
:
876 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"VIAWGET_SET_KEY \n");
877 spin_lock_irq(&pDevice
->lock
);
878 ret
= wpa_set_keys(pDevice
, param
, false);
879 spin_unlock_irq(&pDevice
->lock
);
882 case VIAWGET_SET_SCAN
:
883 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"VIAWGET_SET_SCAN \n");
884 ret
= wpa_set_scan(pDevice
, param
);
887 case VIAWGET_GET_SCAN
:
888 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"VIAWGET_GET_SCAN\n");
889 ret
= wpa_get_scan(pDevice
, param
);
893 case VIAWGET_GET_SSID
:
894 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"VIAWGET_GET_SSID \n");
895 ret
= wpa_get_ssid(pDevice
, param
);
899 case VIAWGET_GET_BSSID
:
900 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"VIAWGET_GET_BSSID \n");
901 ret
= wpa_get_bssid(pDevice
, param
);
905 case VIAWGET_SET_ASSOCIATE
:
906 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"VIAWGET_SET_ASSOCIATE \n");
907 ret
= wpa_set_associate(pDevice
, param
);
910 case VIAWGET_SET_DISASSOCIATE
:
911 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"VIAWGET_SET_DISASSOCIATE \n");
912 ret
= wpa_set_disassociate(pDevice
, param
);
915 case VIAWGET_SET_DROP_UNENCRYPT
:
916 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"VIAWGET_SET_DROP_UNENCRYPT \n");
919 case VIAWGET_SET_DEAUTHENTICATE
:
920 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"VIAWGET_SET_DEAUTHENTICATE \n");
924 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"wpa_ioctl: unknown cmd=%d\n",
930 if ((ret
== 0) && wpa_ioctl
) {
931 if (copy_to_user(p
->pointer
, param
, p
->length
)) {