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
45 /*--------------------- Static Definitions -------------------------*/
47 #define VIAWGET_WPA_MAX_BUF_SIZE 1024
51 static const int frequency_list
[] = {
52 2412, 2417, 2422, 2427, 2432, 2437, 2442,
53 2447, 2452, 2457, 2462, 2467, 2472, 2484
55 /*--------------------- Static Classes ----------------------------*/
57 /*--------------------- Static Variables --------------------------*/
58 //static int msglevel =MSG_LEVEL_DEBUG;
59 static int msglevel
=MSG_LEVEL_INFO
;
61 /*--------------------- Static Functions --------------------------*/
66 /*--------------------- Export Variables --------------------------*/
67 static void wpadev_setup(struct net_device
*dev
)
69 dev
->type
= ARPHRD_IEEE80211
;
70 dev
->hard_header_len
= ETH_HLEN
;
72 dev
->addr_len
= ETH_ALEN
;
73 dev
->tx_queue_len
= 1000;
75 memset(dev
->broadcast
,0xFF, ETH_ALEN
);
77 dev
->flags
= IFF_BROADCAST
|IFF_MULTICAST
;
82 * register netdev for wpa supplicant deamon
94 static int wpa_init_wpadev(PSDevice pDevice
)
97 struct net_device
*dev
= pDevice
->dev
;
100 pDevice
->wpadev
= alloc_netdev(sizeof(PSDevice
), "vntwpa", wpadev_setup
);
101 if (pDevice
->wpadev
== NULL
)
104 wpadev_priv
= netdev_priv(pDevice
->wpadev
);
105 *wpadev_priv
= *pDevice
;
106 memcpy(pDevice
->wpadev
->dev_addr
, dev
->dev_addr
, ETH_ALEN
);
107 pDevice
->wpadev
->base_addr
= dev
->base_addr
;
108 pDevice
->wpadev
->irq
= dev
->irq
;
109 pDevice
->wpadev
->mem_start
= dev
->mem_start
;
110 pDevice
->wpadev
->mem_end
= dev
->mem_end
;
111 ret
= register_netdev(pDevice
->wpadev
);
113 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%s: register_netdev(WPA) failed!\n",
115 free_netdev(pDevice
->wpadev
);
119 if (pDevice
->skb
== NULL
) {
120 pDevice
->skb
= dev_alloc_skb((int)pDevice
->rx_buf_sz
);
121 if (pDevice
->skb
== NULL
)
125 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%s: Registered netdev %s for WPA management\n",
126 dev
->name
, pDevice
->wpadev
->name
);
134 * unregister net_device (wpadev)
145 static int wpa_release_wpadev(PSDevice pDevice
)
148 dev_kfree_skb(pDevice
->skb
);
152 if (pDevice
->wpadev
) {
153 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%s: Netdevice %s unregistered\n",
154 pDevice
->dev
->name
, pDevice
->wpadev
->name
);
155 unregister_netdev(pDevice
->wpadev
);
156 free_netdev(pDevice
->wpadev
);
157 pDevice
->wpadev
= NULL
;
169 * Set enable/disable dev for wpa supplicant deamon
181 int wpa_set_wpadev(PSDevice pDevice
, int val
)
184 return wpa_init_wpadev(pDevice
);
186 return wpa_release_wpadev(pDevice
);
191 * Set WPA algorithm & keys
203 int wpa_set_keys(PSDevice pDevice
, void *ctx
, BOOL fcpfkernel
)
205 struct viawget_wpa_param
*param
=ctx
;
206 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
207 DWORD dwKeyIndex
= 0;
208 BYTE abyKey
[MAX_KEY_LEN
];
209 BYTE abySeq
[MAX_KEY_LEN
];
211 // NDIS_802_11_KEY_RSC KeyRSC;
212 BYTE byKeyDecMode
= KEY_CTL_WEP
;
217 if (param
->u
.wpa_key
.alg_name
> WPA_ALG_CCMP
)
220 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"param->u.wpa_key.alg_name = %d \n", param
->u
.wpa_key
.alg_name
);
221 if (param
->u
.wpa_key
.alg_name
== WPA_ALG_NONE
) {
222 pDevice
->eEncryptionStatus
= Ndis802_11EncryptionDisabled
;
223 pDevice
->bEncryptionEnable
= FALSE
;
224 pDevice
->byKeyIndex
= 0;
225 pDevice
->bTransmitKey
= FALSE
;
226 for (uu
=0; uu
<MAX_KEY_TABLE
; uu
++) {
227 MACvDisableKeyEntry(pDevice
, uu
);
232 if (param
->u
.wpa_key
.key
&& param
->u
.wpa_key
.key_len
> sizeof(abyKey
))
235 spin_unlock_irq(&pDevice
->lock
);
236 if(param
->u
.wpa_key
.key
&& fcpfkernel
) {
237 memcpy(&abyKey
[0], param
->u
.wpa_key
.key
, param
->u
.wpa_key
.key_len
);
240 if (param
->u
.wpa_key
.key
&&
241 copy_from_user(&abyKey
[0], param
->u
.wpa_key
.key
, param
->u
.wpa_key
.key_len
)) {
242 spin_lock_irq(&pDevice
->lock
);
246 spin_lock_irq(&pDevice
->lock
);
248 dwKeyIndex
= (DWORD
)(param
->u
.wpa_key
.key_index
);
250 if (param
->u
.wpa_key
.alg_name
== WPA_ALG_WEP
) {
251 if (dwKeyIndex
> 3) {
255 if (param
->u
.wpa_key
.set_tx
) {
256 pDevice
->byKeyIndex
= (BYTE
)dwKeyIndex
;
257 pDevice
->bTransmitKey
= TRUE
;
258 dwKeyIndex
|= (1 << 31);
260 KeybSetDefaultKey( pDevice
,
262 dwKeyIndex
& ~(BIT30
| USE_KEYRSC
),
263 param
->u
.wpa_key
.key_len
,
270 pDevice
->eEncryptionStatus
= Ndis802_11Encryption1Enabled
;
271 pDevice
->bEncryptionEnable
= TRUE
;
276 if (param
->u
.wpa_key
.seq
&& param
->u
.wpa_key
.seq_len
> sizeof(abySeq
))
279 spin_unlock_irq(&pDevice
->lock
);
280 if(param
->u
.wpa_key
.seq
&& fcpfkernel
) {
281 memcpy(&abySeq
[0], param
->u
.wpa_key
.seq
, param
->u
.wpa_key
.seq_len
);
284 if (param
->u
.wpa_key
.seq
&&
285 copy_from_user(&abySeq
[0], param
->u
.wpa_key
.seq
, param
->u
.wpa_key
.seq_len
)) {
286 spin_lock_irq(&pDevice
->lock
);
290 spin_lock_irq(&pDevice
->lock
);
292 if (param
->u
.wpa_key
.seq_len
> 0) {
293 for (ii
= 0 ; ii
< param
->u
.wpa_key
.seq_len
; ii
++) {
295 LODWORD(KeyRSC
) |= (abySeq
[ii
] << (ii
* 8));
297 HIDWORD(KeyRSC
) |= (abySeq
[ii
] << ((ii
-4) * 8));
298 //KeyRSC |= (abySeq[ii] << (ii * 8));
300 dwKeyIndex
|= 1 << 29;
303 if (param
->u
.wpa_key
.key_index
>= MAX_GROUP_KEY
) {
304 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"return dwKeyIndex > 3\n");
308 if (param
->u
.wpa_key
.alg_name
== WPA_ALG_TKIP
) {
309 pDevice
->eEncryptionStatus
= Ndis802_11Encryption2Enabled
;
312 if (param
->u
.wpa_key
.alg_name
== WPA_ALG_CCMP
) {
313 pDevice
->eEncryptionStatus
= Ndis802_11Encryption3Enabled
;
316 if (param
->u
.wpa_key
.set_tx
)
317 dwKeyIndex
|= (1 << 31);
320 if (pDevice
->eEncryptionStatus
== Ndis802_11Encryption3Enabled
)
321 byKeyDecMode
= KEY_CTL_CCMP
;
322 else if (pDevice
->eEncryptionStatus
== Ndis802_11Encryption2Enabled
)
323 byKeyDecMode
= KEY_CTL_TKIP
;
325 byKeyDecMode
= KEY_CTL_WEP
;
327 // Fix HCT test that set 256 bits KEY and Ndis802_11Encryption3Enabled
328 if (pDevice
->eEncryptionStatus
== Ndis802_11Encryption3Enabled
) {
329 if (param
->u
.wpa_key
.key_len
== MAX_KEY_LEN
)
330 byKeyDecMode
= KEY_CTL_TKIP
;
331 else if (param
->u
.wpa_key
.key_len
== WLAN_WEP40_KEYLEN
)
332 byKeyDecMode
= KEY_CTL_WEP
;
333 else if (param
->u
.wpa_key
.key_len
== WLAN_WEP104_KEYLEN
)
334 byKeyDecMode
= KEY_CTL_WEP
;
335 } else if (pDevice
->eEncryptionStatus
== Ndis802_11Encryption2Enabled
) {
336 if (param
->u
.wpa_key
.key_len
== WLAN_WEP40_KEYLEN
)
337 byKeyDecMode
= KEY_CTL_WEP
;
338 else if (param
->u
.wpa_key
.key_len
== WLAN_WEP104_KEYLEN
)
339 byKeyDecMode
= KEY_CTL_WEP
;
342 // Check TKIP key length
343 if ((byKeyDecMode
== KEY_CTL_TKIP
) &&
344 (param
->u
.wpa_key
.key_len
!= MAX_KEY_LEN
)) {
345 // TKIP Key must be 256 bits
346 //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA - TKIP Key must be 256 bits\n"));
347 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"return- TKIP Key must be 256 bits!\n");
350 // Check AES key length
351 if ((byKeyDecMode
== KEY_CTL_CCMP
) &&
352 (param
->u
.wpa_key
.key_len
!= AES_KEY_LEN
)) {
353 // AES Key must be 128 bits
354 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"return - AES Key must be 128 bits\n");
358 if (is_broadcast_ether_addr(¶m
->addr
[0]) || (param
->addr
== NULL
)) {
359 /* if broadcast, set the key as every key entry's group key */
360 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Groupe Key Assign.\n");
362 if ((KeybSetAllGroupKey(pDevice
,
365 param
->u
.wpa_key
.key_len
,
370 (KeybSetDefaultKey(pDevice
,
373 param
->u
.wpa_key
.key_len
,
378 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"GROUP Key Assign.\n");
381 //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA -KeybSetDefaultKey Fail.0\n"));
386 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Pairwise Key Assign.\n");
387 // BSSID not 0xffffffffffff
388 // Pairwise Key can't be WEP
389 if (byKeyDecMode
== KEY_CTL_WEP
) {
390 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Pairwise Key can't be WEP\n");
394 dwKeyIndex
|= (1 << 30); // set pairwise key
395 if (pMgmt
->eConfigMode
== WMAC_CONFIG_IBSS_STA
) {
396 //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA - WMAC_CONFIG_IBSS_STA\n"));
399 if (KeybSetKey(pDevice
,
403 param
->u
.wpa_key
.key_len
,
408 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Pairwise Key Set\n");
412 if (!compare_ether_addr(¶m
->addr
[0], pDevice
->abyBSSID
)) {
413 //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA -Key Table Full.2\n"));
417 // Save Key and configure just before associate/reassociate to BSSID
418 // we do not implement now
422 } // BSSID not 0xffffffffffff
423 if ((ret
== 0) && ((param
->u
.wpa_key
.set_tx
) != 0)) {
424 pDevice
->byKeyIndex
= (BYTE
)param
->u
.wpa_key
.key_index
;
425 pDevice
->bTransmitKey
= TRUE
;
427 pDevice
->bEncryptionEnable
= TRUE
;
430 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " key=%x-%x-%x-%x-%x-xxxxx \n",
431 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][0],
432 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][1],
433 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][2],
434 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][3],
435 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][4]
446 * enable wpa auth & mode
458 static int wpa_set_wpa(PSDevice pDevice
,
459 struct viawget_wpa_param
*param
)
462 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
465 pMgmt
->eAuthenMode
= WMAC_AUTH_OPEN
;
466 pMgmt
->bShareKeyAlgorithm
= FALSE
;
488 static int wpa_set_disassociate(PSDevice pDevice
,
489 struct viawget_wpa_param
*param
)
491 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
494 spin_lock_irq(&pDevice
->lock
);
495 if (pDevice
->bLinkPass
) {
496 if (!memcmp(param
->addr
, pMgmt
->abyCurrBSSID
, 6))
497 bScheduleCommand((void *) pDevice
, WLAN_CMD_DISASSOCIATE
, NULL
);
499 spin_unlock_irq(&pDevice
->lock
);
508 * enable scan process
520 static int wpa_set_scan(PSDevice pDevice
,
521 struct viawget_wpa_param
*param
)
525 /**set ap_scan=1&&scan_ssid=1 under hidden ssid mode**/
526 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
527 PWLAN_IE_SSID pItemSSID
;
528 printk("wpa_set_scan-->desired [ssid=%s,ssid_len=%d]\n",
529 param
->u
.scan_req
.ssid
,param
->u
.scan_req
.ssid_len
);
531 memset(pMgmt
->abyDesireSSID
, 0, WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
+ 1);
532 pItemSSID
= (PWLAN_IE_SSID
)pMgmt
->abyDesireSSID
;
533 pItemSSID
->byElementID
= WLAN_EID_SSID
;
534 memcpy(pItemSSID
->abySSID
, param
->u
.scan_req
.ssid
, param
->u
.scan_req
.ssid_len
);
535 pItemSSID
->len
= param
->u
.scan_req
.ssid_len
;
537 spin_lock_irq(&pDevice
->lock
);
538 BSSvClearBSSList((void *) pDevice
, pDevice
->bLinkPass
);
539 /* bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, NULL); */
540 bScheduleCommand((void *) pDevice
,
542 pMgmt
->abyDesireSSID
);
543 spin_unlock_irq(&pDevice
->lock
);
564 static int wpa_get_bssid(PSDevice pDevice
,
565 struct viawget_wpa_param
*param
)
567 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
569 memcpy(param
->u
.wpa_associate
.bssid
, pMgmt
->abyCurrBSSID
, 6);
590 static int wpa_get_ssid(PSDevice pDevice
,
591 struct viawget_wpa_param
*param
)
593 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
594 PWLAN_IE_SSID pItemSSID
;
597 pItemSSID
= (PWLAN_IE_SSID
)pMgmt
->abyCurrSSID
;
599 memcpy(param
->u
.wpa_associate
.ssid
, pItemSSID
->abySSID
, pItemSSID
->len
);
600 param
->u
.wpa_associate
.ssid_len
= pItemSSID
->len
;
621 static int wpa_get_scan(PSDevice pDevice
,
622 struct viawget_wpa_param
*param
)
624 struct viawget_scan_result
*scan_buf
;
625 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
626 PWLAN_IE_SSID pItemSSID
;
632 long ldBm
;//James //add
634 //******mike:bubble sort by stronger RSSI*****//
640 ptempBSS
= kmalloc(sizeof(KnownBSS
), (int)GFP_ATOMIC
);
642 if (ptempBSS
== NULL
) {
644 printk("bubble sort kmalloc memory fail@@@\n");
652 for (ii
= 0; ii
< MAX_BSS_NUM
; ii
++) {
654 for (jj
= 0; jj
< MAX_BSS_NUM
- ii
- 1; jj
++) {
656 if ((pMgmt
->sBSSList
[jj
].bActive
!= TRUE
) ||
658 ((pMgmt
->sBSSList
[jj
].uRSSI
>pMgmt
->sBSSList
[jj
+1].uRSSI
) &&(pMgmt
->sBSSList
[jj
+1].bActive
!=FALSE
))) {
660 memcpy(ptempBSS
,&pMgmt
->sBSSList
[jj
],sizeof(KnownBSS
));
662 memcpy(&pMgmt
->sBSSList
[jj
],&pMgmt
->sBSSList
[jj
+1],sizeof(KnownBSS
));
664 memcpy(&pMgmt
->sBSSList
[jj
+1],ptempBSS
,sizeof(KnownBSS
));
674 // printk("bubble sort result:\n");
677 pBSS
= &(pMgmt
->sBSSList
[0]);
678 for (ii
= 0; ii
< MAX_BSS_NUM
; ii
++) {
679 pBSS
= &(pMgmt
->sBSSList
[ii
]);
685 pBuf
= kcalloc(count
, sizeof(struct viawget_scan_result
), (int)GFP_ATOMIC
);
691 scan_buf
= (struct viawget_scan_result
*)pBuf
;
692 pBSS
= &(pMgmt
->sBSSList
[0]);
693 for (ii
= 0, jj
= 0; ii
< MAX_BSS_NUM
; ii
++) {
694 pBSS
= &(pMgmt
->sBSSList
[ii
]);
698 memcpy(scan_buf
->bssid
, pBSS
->abyBSSID
, WLAN_BSSID_LEN
);
699 pItemSSID
= (PWLAN_IE_SSID
)pBSS
->abySSID
;
700 memcpy(scan_buf
->ssid
, pItemSSID
->abySSID
, pItemSSID
->len
);
701 scan_buf
->ssid_len
= pItemSSID
->len
;
702 scan_buf
->freq
= frequency_list
[pBSS
->uChannel
-1];
703 scan_buf
->caps
= pBSS
->wCapInfo
; //DavidWang for sharemode
705 RFvRSSITodBm(pDevice
, (BYTE
)(pBSS
->uRSSI
), &ldBm
);
707 scan_buf
->qual
= 100;
708 }else if(-ldBm
> 90) {
711 scan_buf
->qual
=(40-(-ldBm
-50))*100/40;
715 //scan_buf->caps = pBSS->wCapInfo;
718 scan_buf
->level
= ldBm
;
720 //scan_buf->maxrate =
721 if (pBSS
->wWPALen
!= 0) {
722 scan_buf
->wpa_ie_len
= pBSS
->wWPALen
;
723 memcpy(scan_buf
->wpa_ie
, pBSS
->byWPAIE
, pBSS
->wWPALen
);
725 if (pBSS
->wRSNLen
!= 0) {
726 scan_buf
->rsn_ie_len
= pBSS
->wRSNLen
;
727 memcpy(scan_buf
->rsn_ie
, pBSS
->byRSNIE
, pBSS
->wRSNLen
);
729 scan_buf
= (struct viawget_scan_result
*)((PBYTE
)scan_buf
+ sizeof(struct viawget_scan_result
));
737 if (copy_to_user(param
->u
.scan_results
.buf
, pBuf
, sizeof(struct viawget_scan_result
) * count
)) {
740 param
->u
.scan_results
.scan_count
= count
;
741 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" param->u.scan_results.scan_count = %d\n", count
)
751 * set associate with AP
763 static int wpa_set_associate(PSDevice pDevice
,
764 struct viawget_wpa_param
*param
)
766 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
767 PWLAN_IE_SSID pItemSSID
;
768 BYTE abyNullAddr
[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
771 BOOL bwepEnabled
=FALSE
;
773 // set key type & algorithm
774 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pairwise_suite = %d\n", param
->u
.wpa_associate
.pairwise_suite
);
775 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"group_suite = %d\n", param
->u
.wpa_associate
.group_suite
);
776 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"key_mgmt_suite = %d\n", param
->u
.wpa_associate
.key_mgmt_suite
);
777 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"auth_alg = %d\n", param
->u
.wpa_associate
.auth_alg
);
778 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"mode = %d\n", param
->u
.wpa_associate
.mode
);
779 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"wpa_ie_len = %d\n", param
->u
.wpa_associate
.wpa_ie_len
);
780 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Roaming dBm = %d\n", param
->u
.wpa_associate
.roam_dbm
); //Davidwang
782 if (param
->u
.wpa_associate
.wpa_ie
) {
783 if (param
->u
.wpa_associate
.wpa_ie_len
> sizeof(abyWPAIE
))
786 if (copy_from_user(&abyWPAIE
[0], param
->u
.wpa_associate
.wpa_ie
,
787 param
->u
.wpa_associate
.wpa_ie_len
))
791 if (param
->u
.wpa_associate
.mode
== 1)
792 pMgmt
->eConfigMode
= WMAC_CONFIG_IBSS_STA
;
794 pMgmt
->eConfigMode
= WMAC_CONFIG_ESS_STA
;
797 if (memcmp(param
->u
.wpa_associate
.bssid
, &abyNullAddr
[0], 6) != 0)
798 memcpy(pMgmt
->abyDesireBSSID
, param
->u
.wpa_associate
.bssid
, 6);
800 memset(pMgmt
->abyDesireSSID
, 0, WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
+ 1);
801 pItemSSID
= (PWLAN_IE_SSID
)pMgmt
->abyDesireSSID
;
802 pItemSSID
->byElementID
= WLAN_EID_SSID
;
803 pItemSSID
->len
= param
->u
.wpa_associate
.ssid_len
;
804 memcpy(pItemSSID
->abySSID
, param
->u
.wpa_associate
.ssid
, pItemSSID
->len
);
806 if (param
->u
.wpa_associate
.wpa_ie_len
== 0) {
807 if (param
->u
.wpa_associate
.auth_alg
& AUTH_ALG_SHARED_KEY
)
808 pMgmt
->eAuthenMode
= WMAC_AUTH_SHAREKEY
;
810 pMgmt
->eAuthenMode
= WMAC_AUTH_OPEN
;
811 } else if (abyWPAIE
[0] == RSN_INFO_ELEM
) {
812 if (param
->u
.wpa_associate
.key_mgmt_suite
== KEY_MGMT_PSK
)
813 pMgmt
->eAuthenMode
= WMAC_AUTH_WPA2PSK
;
815 pMgmt
->eAuthenMode
= WMAC_AUTH_WPA2
;
817 if (param
->u
.wpa_associate
.key_mgmt_suite
== KEY_MGMT_WPA_NONE
)
818 pMgmt
->eAuthenMode
= WMAC_AUTH_WPANONE
;
819 else if (param
->u
.wpa_associate
.key_mgmt_suite
== KEY_MGMT_PSK
)
820 pMgmt
->eAuthenMode
= WMAC_AUTH_WPAPSK
;
822 pMgmt
->eAuthenMode
= WMAC_AUTH_WPA
;
825 switch (param
->u
.wpa_associate
.pairwise_suite
) {
827 pDevice
->eEncryptionStatus
= Ndis802_11Encryption3Enabled
;
830 pDevice
->eEncryptionStatus
= Ndis802_11Encryption2Enabled
;
834 pDevice
->eEncryptionStatus
= Ndis802_11Encryption1Enabled
;
836 // printk("****************wpa_set_associate:set CIPHER_WEP40_104\n");
839 if (param
->u
.wpa_associate
.group_suite
== CIPHER_CCMP
)
840 pDevice
->eEncryptionStatus
= Ndis802_11Encryption3Enabled
;
842 pDevice
->eEncryptionStatus
= Ndis802_11Encryption2Enabled
;
845 pDevice
->eEncryptionStatus
= Ndis802_11EncryptionDisabled
;
848 pMgmt
->Roam_dbm
= param
->u
.wpa_associate
.roam_dbm
;
849 // if ((pMgmt->Roam_dbm > 40)&&(pMgmt->Roam_dbm<80))
850 // pDevice->bEnableRoaming = TRUE;
852 if (pMgmt
->eAuthenMode
== WMAC_AUTH_SHAREKEY
) { //@wep-sharekey
853 pDevice
->eEncryptionStatus
= Ndis802_11Encryption1Enabled
;
854 pMgmt
->bShareKeyAlgorithm
= TRUE
;
856 else if (pMgmt
->eAuthenMode
== WMAC_AUTH_OPEN
) {
857 if(bwepEnabled
==TRUE
) { //@open-wep
858 pDevice
->eEncryptionStatus
= Ndis802_11Encryption1Enabled
;
861 pDevice
->eEncryptionStatus
= Ndis802_11EncryptionDisabled
;
864 //mike save old encryption status
865 pDevice
->eOldEncryptionStatus
= pDevice
->eEncryptionStatus
;
867 if (pDevice
->eEncryptionStatus
!= Ndis802_11EncryptionDisabled
)
868 pDevice
->bEncryptionEnable
= TRUE
;
870 pDevice
->bEncryptionEnable
= FALSE
;
872 if ((pMgmt
->eAuthenMode
== WMAC_AUTH_SHAREKEY
) ||
873 ((pMgmt
->eAuthenMode
== WMAC_AUTH_OPEN
) && (bwepEnabled
==TRUE
))) {
874 //mike re-comment:open-wep && sharekey-wep needn't do initial key!!
878 KeyvInitTable(pDevice
,&pDevice
->sKey
);
880 spin_lock_irq(&pDevice
->lock
);
881 pDevice
->bLinkPass
= FALSE
;
882 ControlvMaskByte(pDevice
,MESSAGE_REQUEST_MACREG
,MAC_REG_PAPEDELAY
,LEDSTS_STS
,LEDSTS_SLOW
);
883 memset(pMgmt
->abyCurrBSSID
, 0, 6);
884 pMgmt
->eCurrState
= WMAC_STATE_IDLE
;
885 netif_stop_queue(pDevice
->dev
);
887 /*******search if ap_scan=2 ,which is associating request in hidden ssid mode ****/
889 PKnownBSS pCurr
= NULL
;
890 pCurr
= BSSpSearchBSSList(pDevice
,
891 pMgmt
->abyDesireBSSID
,
892 pMgmt
->abyDesireSSID
,
893 pDevice
->eConfigPHYMode
897 printk("wpa_set_associate---->hidden mode site survey before associate.......\n");
898 bScheduleCommand((void *) pDevice
,
900 pMgmt
->abyDesireSSID
);
903 /****************************************************************/
905 bScheduleCommand((void *) pDevice
, WLAN_CMD_SSID
, NULL
);
906 spin_unlock_irq(&pDevice
->lock
);
914 * wpa_ioctl main function supported for wpa supplicant
926 int wpa_ioctl(PSDevice pDevice
, struct iw_point
*p
)
928 struct viawget_wpa_param
*param
;
932 if (p
->length
< sizeof(struct viawget_wpa_param
) ||
933 p
->length
> VIAWGET_WPA_MAX_BUF_SIZE
|| !p
->pointer
)
936 param
= kmalloc((int)p
->length
, (int)GFP_KERNEL
);
940 if (copy_from_user(param
, p
->pointer
, p
->length
)) {
945 switch (param
->cmd
) {
946 case VIAWGET_SET_WPA
:
947 ret
= wpa_set_wpa(pDevice
, param
);
948 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"VIAWGET_SET_WPA \n");
951 case VIAWGET_SET_KEY
:
952 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"VIAWGET_SET_KEY \n");
953 spin_lock_irq(&pDevice
->lock
);
954 ret
= wpa_set_keys(pDevice
, param
, FALSE
);
955 spin_unlock_irq(&pDevice
->lock
);
958 case VIAWGET_SET_SCAN
:
959 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"VIAWGET_SET_SCAN \n");
960 ret
= wpa_set_scan(pDevice
, param
);
963 case VIAWGET_GET_SCAN
:
964 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"VIAWGET_GET_SCAN\n");
965 ret
= wpa_get_scan(pDevice
, param
);
969 case VIAWGET_GET_SSID
:
970 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"VIAWGET_GET_SSID \n");
971 ret
= wpa_get_ssid(pDevice
, param
);
975 case VIAWGET_GET_BSSID
:
976 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"VIAWGET_GET_BSSID \n");
977 ret
= wpa_get_bssid(pDevice
, param
);
981 case VIAWGET_SET_ASSOCIATE
:
982 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"VIAWGET_SET_ASSOCIATE \n");
983 ret
= wpa_set_associate(pDevice
, param
);
986 case VIAWGET_SET_DISASSOCIATE
:
987 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"VIAWGET_SET_DISASSOCIATE \n");
988 ret
= wpa_set_disassociate(pDevice
, param
);
991 case VIAWGET_SET_DROP_UNENCRYPT
:
992 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"VIAWGET_SET_DROP_UNENCRYPT \n");
995 case VIAWGET_SET_DEAUTHENTICATE
:
996 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"VIAWGET_SET_DEAUTHENTICATE \n");
1000 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"wpa_ioctl: unknown cmd=%d\n",
1006 if ((ret
== 0) && wpa_ioctl
) {
1007 if (copy_to_user(p
->pointer
, param
, p
->length
)) {