spi-topcliff-pch: add recovery processing in case wait-event timeout
[zen-stable.git] / drivers / staging / vt6656 / wpactl.c
blob2fa4f845a755fef71216cff48b9aeb79b60260a5
1 /*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
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.
20 * File: wpactl.c
22 * Purpose: handle wpa supplicant ioctl input/out functions
24 * Author: Lyndon Chen
26 * Date: July 28, 2006
28 * Functions:
30 * Revision History:
34 #include "wpactl.h"
35 #include "key.h"
36 #include "mac.h"
37 #include "device.h"
38 #include "wmgr.h"
39 #include "iocmd.h"
40 #include "iowpa.h"
41 #include "control.h"
42 #include "rndis.h"
43 #include "rf.h"
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;
71 dev->mtu = 2048;
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;
81 * Description:
82 * register netdev for wpa supplicant deamon
84 * Parameters:
85 * In:
86 * pDevice -
87 * enable -
88 * Out:
90 * Return Value:
94 static int wpa_init_wpadev(PSDevice pDevice)
96 PSDevice wpadev_priv;
97 struct net_device *dev = pDevice->dev;
98 int ret=0;
100 pDevice->wpadev = alloc_netdev(sizeof(PSDevice), "vntwpa", wpadev_setup);
101 if (pDevice->wpadev == NULL)
102 return -ENOMEM;
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);
112 if (ret) {
113 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: register_netdev(WPA) failed!\n",
114 dev->name);
115 free_netdev(pDevice->wpadev);
116 return -1;
119 if (pDevice->skb == NULL) {
120 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
121 if (pDevice->skb == NULL)
122 return -ENOMEM;
125 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Registered netdev %s for WPA management\n",
126 dev->name, pDevice->wpadev->name);
128 return 0;
133 * Description:
134 * unregister net_device (wpadev)
136 * Parameters:
137 * In:
138 * pDevice -
139 * Out:
141 * Return Value:
145 static int wpa_release_wpadev(PSDevice pDevice)
147 if (pDevice->skb) {
148 dev_kfree_skb(pDevice->skb);
149 pDevice->skb = NULL;
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;
160 return 0;
168 * Description:
169 * Set enable/disable dev for wpa supplicant deamon
171 * Parameters:
172 * In:
173 * pDevice -
174 * val -
175 * Out:
177 * Return Value:
181 int wpa_set_wpadev(PSDevice pDevice, int val)
183 if (val)
184 return wpa_init_wpadev(pDevice);
185 else
186 return wpa_release_wpadev(pDevice);
190 * Description:
191 * Set WPA algorithm & keys
193 * Parameters:
194 * In:
195 * pDevice -
196 * param -
197 * Out:
199 * Return Value:
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];
210 QWORD KeyRSC;
211 // NDIS_802_11_KEY_RSC KeyRSC;
212 BYTE byKeyDecMode = KEY_CTL_WEP;
213 int ret = 0;
214 int uu, ii;
217 if (param->u.wpa_key.alg_name > WPA_ALG_CCMP)
218 return -EINVAL;
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);
229 return ret;
232 if (param->u.wpa_key.key && param->u.wpa_key.key_len > sizeof(abyKey))
233 return -EINVAL;
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);
239 else {
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);
243 return -EINVAL;
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) {
252 return -EINVAL;
254 else {
255 if (param->u.wpa_key.set_tx) {
256 pDevice->byKeyIndex = (BYTE)dwKeyIndex;
257 pDevice->bTransmitKey = TRUE;
258 dwKeyIndex |= (1 << 31);
260 KeybSetDefaultKey( pDevice,
261 &(pDevice->sKey),
262 dwKeyIndex & ~(BIT30 | USE_KEYRSC),
263 param->u.wpa_key.key_len,
264 NULL,
265 abyKey,
266 KEY_CTL_WEP
270 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
271 pDevice->bEncryptionEnable = TRUE;
272 return ret;
276 if (param->u.wpa_key.seq && param->u.wpa_key.seq_len > sizeof(abySeq))
277 return -EINVAL;
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);
283 else {
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);
287 return -EINVAL;
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++) {
294 if (ii < 4)
295 LODWORD(KeyRSC) |= (abySeq[ii] << (ii * 8));
296 else
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");
305 return -EINVAL;
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;
324 else
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");
348 return -EINVAL;
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");
355 return -EINVAL;
358 if (is_broadcast_ether_addr(&param->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,
363 &(pDevice->sKey),
364 dwKeyIndex,
365 param->u.wpa_key.key_len,
366 (PQWORD) &(KeyRSC),
367 (PBYTE)abyKey,
368 byKeyDecMode
369 ) == TRUE) &&
370 (KeybSetDefaultKey(pDevice,
371 &(pDevice->sKey),
372 dwKeyIndex,
373 param->u.wpa_key.key_len,
374 (PQWORD) &(KeyRSC),
375 (PBYTE)abyKey,
376 byKeyDecMode
377 ) == TRUE) ) {
378 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "GROUP Key Assign.\n");
380 } else {
381 //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA -KeybSetDefaultKey Fail.0\n"));
382 return -EINVAL;
385 } else {
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");
391 return -EINVAL;
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"));
397 return -EINVAL;
399 if (KeybSetKey(pDevice,
400 &(pDevice->sKey),
401 &param->addr[0],
402 dwKeyIndex,
403 param->u.wpa_key.key_len,
404 (PQWORD) &(KeyRSC),
405 (PBYTE)abyKey,
406 byKeyDecMode
407 ) == TRUE) {
408 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pairwise Key Set\n");
410 } else {
411 // Key Table Full
412 if (!compare_ether_addr(&param->addr[0], pDevice->abyBSSID)) {
413 //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA -Key Table Full.2\n"));
414 return -EINVAL;
416 } else {
417 // Save Key and configure just before associate/reassociate to BSSID
418 // we do not implement now
419 return -EINVAL;
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]
439 return ret;
445 * Description:
446 * enable wpa auth & mode
448 * Parameters:
449 * In:
450 * pDevice -
451 * param -
452 * Out:
454 * Return Value:
458 static int wpa_set_wpa(PSDevice pDevice,
459 struct viawget_wpa_param *param)
462 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
463 int ret = 0;
465 pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
466 pMgmt->bShareKeyAlgorithm = FALSE;
468 return ret;
475 * Description:
476 * set disassociate
478 * Parameters:
479 * In:
480 * pDevice -
481 * param -
482 * Out:
484 * Return Value:
488 static int wpa_set_disassociate(PSDevice pDevice,
489 struct viawget_wpa_param *param)
491 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
492 int ret = 0;
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);
501 return ret;
507 * Description:
508 * enable scan process
510 * Parameters:
511 * In:
512 * pDevice -
513 * param -
514 * Out:
516 * Return Value:
520 static int wpa_set_scan(PSDevice pDevice,
521 struct viawget_wpa_param *param)
523 int ret = 0;
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);
530 // Set the SSID
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,
541 WLAN_CMD_BSSID_SCAN,
542 pMgmt->abyDesireSSID);
543 spin_unlock_irq(&pDevice->lock);
545 return ret;
551 * Description:
552 * get bssid
554 * Parameters:
555 * In:
556 * pDevice -
557 * param -
558 * Out:
560 * Return Value:
564 static int wpa_get_bssid(PSDevice pDevice,
565 struct viawget_wpa_param *param)
567 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
568 int ret = 0;
569 memcpy(param->u.wpa_associate.bssid, pMgmt->abyCurrBSSID , 6);
571 return ret;
577 * Description:
578 * get bssid
580 * Parameters:
581 * In:
582 * pDevice -
583 * param -
584 * Out:
586 * Return Value:
590 static int wpa_get_ssid(PSDevice pDevice,
591 struct viawget_wpa_param *param)
593 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
594 PWLAN_IE_SSID pItemSSID;
595 int ret = 0;
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;
602 return ret;
608 * Description:
609 * get scan results
611 * Parameters:
612 * In:
613 * pDevice -
614 * param -
615 * Out:
617 * Return Value:
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;
627 PKnownBSS pBSS;
628 PBYTE pBuf;
629 int ret = 0;
630 u16 count = 0;
631 u16 ii, jj;
632 long ldBm;//James //add
634 //******mike:bubble sort by stronger RSSI*****//
636 PBYTE ptempBSS;
640 ptempBSS = kmalloc(sizeof(KnownBSS), (int)GFP_ATOMIC);
642 if (ptempBSS == NULL) {
644 printk("bubble sort kmalloc memory fail@@@\n");
646 ret = -ENOMEM;
648 return ret;
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));
672 kfree(ptempBSS);
674 // printk("bubble sort result:\n");
676 count = 0;
677 pBSS = &(pMgmt->sBSSList[0]);
678 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
679 pBSS = &(pMgmt->sBSSList[ii]);
680 if (!pBSS->bActive)
681 continue;
682 count++;
685 pBuf = kcalloc(count, sizeof(struct viawget_scan_result), (int)GFP_ATOMIC);
687 if (pBuf == NULL) {
688 ret = -ENOMEM;
689 return ret;
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]);
695 if (pBSS->bActive) {
696 if (jj >= count)
697 break;
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);
706 if(-ldBm<50){
707 scan_buf->qual = 100;
708 }else if(-ldBm > 90) {
709 scan_buf->qual = 0;
710 }else {
711 scan_buf->qual=(40-(-ldBm-50))*100/40;
714 //James
715 //scan_buf->caps = pBSS->wCapInfo;
716 //scan_buf->qual =
717 scan_buf->noise = 0;
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));
730 jj ++;
734 if (jj < count)
735 count = jj;
737 if (copy_to_user(param->u.scan_results.buf, pBuf, sizeof(struct viawget_scan_result) * count)) {
738 ret = -EFAULT;
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)
743 kfree(pBuf);
744 return ret;
750 * Description:
751 * set associate with AP
753 * Parameters:
754 * In:
755 * pDevice -
756 * param -
757 * Out:
759 * Return Value:
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};
769 BYTE abyWPAIE[64];
770 int ret = 0;
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))
784 return -EINVAL;
786 if (copy_from_user(&abyWPAIE[0], param->u.wpa_associate.wpa_ie,
787 param->u.wpa_associate.wpa_ie_len))
788 return -EFAULT;
791 if (param->u.wpa_associate.mode == 1)
792 pMgmt->eConfigMode = WMAC_CONFIG_IBSS_STA;
793 else
794 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
796 // set bssid
797 if (memcmp(param->u.wpa_associate.bssid, &abyNullAddr[0], 6) != 0)
798 memcpy(pMgmt->abyDesireBSSID, param->u.wpa_associate.bssid, 6);
799 // set ssid
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;
809 else
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;
814 else
815 pMgmt->eAuthenMode = WMAC_AUTH_WPA2;
816 } else {
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;
821 else
822 pMgmt->eAuthenMode = WMAC_AUTH_WPA;
825 switch (param->u.wpa_associate.pairwise_suite) {
826 case CIPHER_CCMP:
827 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
828 break;
829 case CIPHER_TKIP:
830 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
831 break;
832 case CIPHER_WEP40:
833 case CIPHER_WEP104:
834 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
835 bwepEnabled = TRUE;
836 // printk("****************wpa_set_associate:set CIPHER_WEP40_104\n");
837 break;
838 case CIPHER_NONE:
839 if (param->u.wpa_associate.group_suite == CIPHER_CCMP)
840 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
841 else
842 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
843 break;
844 default:
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;
860 else { //@only open
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;
869 else
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!!
877 else
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
896 if (pCurr == NULL){
897 printk("wpa_set_associate---->hidden mode site survey before associate.......\n");
898 bScheduleCommand((void *) pDevice,
899 WLAN_CMD_BSSID_SCAN,
900 pMgmt->abyDesireSSID);
903 /****************************************************************/
905 bScheduleCommand((void *) pDevice, WLAN_CMD_SSID, NULL);
906 spin_unlock_irq(&pDevice->lock);
908 return ret;
913 * Description:
914 * wpa_ioctl main function supported for wpa supplicant
916 * Parameters:
917 * In:
918 * pDevice -
919 * iw_point -
920 * Out:
922 * Return Value:
926 int wpa_ioctl(PSDevice pDevice, struct iw_point *p)
928 struct viawget_wpa_param *param;
929 int ret = 0;
930 int wpa_ioctl = 0;
932 if (p->length < sizeof(struct viawget_wpa_param) ||
933 p->length > VIAWGET_WPA_MAX_BUF_SIZE || !p->pointer)
934 return -EINVAL;
936 param = kmalloc((int)p->length, (int)GFP_KERNEL);
937 if (param == NULL)
938 return -ENOMEM;
940 if (copy_from_user(param, p->pointer, p->length)) {
941 ret = -EFAULT;
942 goto out;
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");
949 break;
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);
956 break;
958 case VIAWGET_SET_SCAN:
959 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_SCAN \n");
960 ret = wpa_set_scan(pDevice, param);
961 break;
963 case VIAWGET_GET_SCAN:
964 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_GET_SCAN\n");
965 ret = wpa_get_scan(pDevice, param);
966 wpa_ioctl = 1;
967 break;
969 case VIAWGET_GET_SSID:
970 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_GET_SSID \n");
971 ret = wpa_get_ssid(pDevice, param);
972 wpa_ioctl = 1;
973 break;
975 case VIAWGET_GET_BSSID:
976 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_GET_BSSID \n");
977 ret = wpa_get_bssid(pDevice, param);
978 wpa_ioctl = 1;
979 break;
981 case VIAWGET_SET_ASSOCIATE:
982 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_ASSOCIATE \n");
983 ret = wpa_set_associate(pDevice, param);
984 break;
986 case VIAWGET_SET_DISASSOCIATE:
987 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_DISASSOCIATE \n");
988 ret = wpa_set_disassociate(pDevice, param);
989 break;
991 case VIAWGET_SET_DROP_UNENCRYPT:
992 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_DROP_UNENCRYPT \n");
993 break;
995 case VIAWGET_SET_DEAUTHENTICATE:
996 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_DEAUTHENTICATE \n");
997 break;
999 default:
1000 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wpa_ioctl: unknown cmd=%d\n",
1001 param->cmd);
1002 return -EOPNOTSUPP;
1003 break;
1006 if ((ret == 0) && wpa_ioctl) {
1007 if (copy_to_user(p->pointer, param, p->length)) {
1008 ret = -EFAULT;
1009 goto out;
1013 out:
1014 kfree(param);
1016 return ret;