Merge remote-tracking branch 'pm/linux-next'
[linux-2.6/next.git] / drivers / staging / vt6656 / wpactl.c
blob9216df01829e90e53ee8edd18b779800b6e0dbd5
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 spin_unlock_irq(&pDevice->lock);
233 if(param->u.wpa_key.key && fcpfkernel) {
234 memcpy(&abyKey[0], param->u.wpa_key.key, param->u.wpa_key.key_len);
236 else {
237 if (param->u.wpa_key.key &&
238 copy_from_user(&abyKey[0], param->u.wpa_key.key, param->u.wpa_key.key_len)) {
239 spin_lock_irq(&pDevice->lock);
240 return -EINVAL;
243 spin_lock_irq(&pDevice->lock);
245 dwKeyIndex = (DWORD)(param->u.wpa_key.key_index);
247 if (param->u.wpa_key.alg_name == WPA_ALG_WEP) {
248 if (dwKeyIndex > 3) {
249 return -EINVAL;
251 else {
252 if (param->u.wpa_key.set_tx) {
253 pDevice->byKeyIndex = (BYTE)dwKeyIndex;
254 pDevice->bTransmitKey = TRUE;
255 dwKeyIndex |= (1 << 31);
257 KeybSetDefaultKey( pDevice,
258 &(pDevice->sKey),
259 dwKeyIndex & ~(BIT30 | USE_KEYRSC),
260 param->u.wpa_key.key_len,
261 NULL,
262 abyKey,
263 KEY_CTL_WEP
267 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
268 pDevice->bEncryptionEnable = TRUE;
269 return ret;
272 spin_unlock_irq(&pDevice->lock);
273 if(param->u.wpa_key.seq && fcpfkernel) {
274 memcpy(&abySeq[0], param->u.wpa_key.seq, param->u.wpa_key.seq_len);
276 else {
277 if (param->u.wpa_key.seq &&
278 copy_from_user(&abySeq[0], param->u.wpa_key.seq, param->u.wpa_key.seq_len)) {
279 spin_lock_irq(&pDevice->lock);
280 return -EINVAL;
283 spin_lock_irq(&pDevice->lock);
285 if (param->u.wpa_key.seq_len > 0) {
286 for (ii = 0 ; ii < param->u.wpa_key.seq_len ; ii++) {
287 if (ii < 4)
288 LODWORD(KeyRSC) |= (abySeq[ii] << (ii * 8));
289 else
290 HIDWORD(KeyRSC) |= (abySeq[ii] << ((ii-4) * 8));
291 //KeyRSC |= (abySeq[ii] << (ii * 8));
293 dwKeyIndex |= 1 << 29;
296 if (param->u.wpa_key.key_index >= MAX_GROUP_KEY) {
297 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "return dwKeyIndex > 3\n");
298 return -EINVAL;
301 if (param->u.wpa_key.alg_name == WPA_ALG_TKIP) {
302 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
305 if (param->u.wpa_key.alg_name == WPA_ALG_CCMP) {
306 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
309 if (param->u.wpa_key.set_tx)
310 dwKeyIndex |= (1 << 31);
313 if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled)
314 byKeyDecMode = KEY_CTL_CCMP;
315 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled)
316 byKeyDecMode = KEY_CTL_TKIP;
317 else
318 byKeyDecMode = KEY_CTL_WEP;
320 // Fix HCT test that set 256 bits KEY and Ndis802_11Encryption3Enabled
321 if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
322 if (param->u.wpa_key.key_len == MAX_KEY_LEN)
323 byKeyDecMode = KEY_CTL_TKIP;
324 else if (param->u.wpa_key.key_len == WLAN_WEP40_KEYLEN)
325 byKeyDecMode = KEY_CTL_WEP;
326 else if (param->u.wpa_key.key_len == WLAN_WEP104_KEYLEN)
327 byKeyDecMode = KEY_CTL_WEP;
328 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
329 if (param->u.wpa_key.key_len == WLAN_WEP40_KEYLEN)
330 byKeyDecMode = KEY_CTL_WEP;
331 else if (param->u.wpa_key.key_len == WLAN_WEP104_KEYLEN)
332 byKeyDecMode = KEY_CTL_WEP;
335 // Check TKIP key length
336 if ((byKeyDecMode == KEY_CTL_TKIP) &&
337 (param->u.wpa_key.key_len != MAX_KEY_LEN)) {
338 // TKIP Key must be 256 bits
339 //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA - TKIP Key must be 256 bits\n"));
340 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "return- TKIP Key must be 256 bits!\n");
341 return -EINVAL;
343 // Check AES key length
344 if ((byKeyDecMode == KEY_CTL_CCMP) &&
345 (param->u.wpa_key.key_len != AES_KEY_LEN)) {
346 // AES Key must be 128 bits
347 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "return - AES Key must be 128 bits\n");
348 return -EINVAL;
351 if (is_broadcast_ether_addr(&param->addr[0]) || (param->addr == NULL)) {
352 /* if broadcast, set the key as every key entry's group key */
353 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Groupe Key Assign.\n");
355 if ((KeybSetAllGroupKey(pDevice,
356 &(pDevice->sKey),
357 dwKeyIndex,
358 param->u.wpa_key.key_len,
359 (PQWORD) &(KeyRSC),
360 (PBYTE)abyKey,
361 byKeyDecMode
362 ) == TRUE) &&
363 (KeybSetDefaultKey(pDevice,
364 &(pDevice->sKey),
365 dwKeyIndex,
366 param->u.wpa_key.key_len,
367 (PQWORD) &(KeyRSC),
368 (PBYTE)abyKey,
369 byKeyDecMode
370 ) == TRUE) ) {
371 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "GROUP Key Assign.\n");
373 } else {
374 //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA -KeybSetDefaultKey Fail.0\n"));
375 return -EINVAL;
378 } else {
379 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pairwise Key Assign.\n");
380 // BSSID not 0xffffffffffff
381 // Pairwise Key can't be WEP
382 if (byKeyDecMode == KEY_CTL_WEP) {
383 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pairwise Key can't be WEP\n");
384 return -EINVAL;
387 dwKeyIndex |= (1 << 30); // set pairwise key
388 if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) {
389 //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA - WMAC_CONFIG_IBSS_STA\n"));
390 return -EINVAL;
392 if (KeybSetKey(pDevice,
393 &(pDevice->sKey),
394 &param->addr[0],
395 dwKeyIndex,
396 param->u.wpa_key.key_len,
397 (PQWORD) &(KeyRSC),
398 (PBYTE)abyKey,
399 byKeyDecMode
400 ) == TRUE) {
401 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pairwise Key Set\n");
403 } else {
404 // Key Table Full
405 if (!compare_ether_addr(&param->addr[0], pDevice->abyBSSID)) {
406 //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA -Key Table Full.2\n"));
407 return -EINVAL;
409 } else {
410 // Save Key and configure just before associate/reassociate to BSSID
411 // we do not implement now
412 return -EINVAL;
415 } // BSSID not 0xffffffffffff
416 if ((ret == 0) && ((param->u.wpa_key.set_tx) != 0)) {
417 pDevice->byKeyIndex = (BYTE)param->u.wpa_key.key_index;
418 pDevice->bTransmitKey = TRUE;
420 pDevice->bEncryptionEnable = TRUE;
423 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " key=%x-%x-%x-%x-%x-xxxxx \n",
424 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][0],
425 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][1],
426 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][2],
427 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][3],
428 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][4]
432 return ret;
438 * Description:
439 * enable wpa auth & mode
441 * Parameters:
442 * In:
443 * pDevice -
444 * param -
445 * Out:
447 * Return Value:
451 static int wpa_set_wpa(PSDevice pDevice,
452 struct viawget_wpa_param *param)
455 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
456 int ret = 0;
458 pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
459 pMgmt->bShareKeyAlgorithm = FALSE;
461 return ret;
468 * Description:
469 * set disassociate
471 * Parameters:
472 * In:
473 * pDevice -
474 * param -
475 * Out:
477 * Return Value:
481 static int wpa_set_disassociate(PSDevice pDevice,
482 struct viawget_wpa_param *param)
484 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
485 int ret = 0;
487 spin_lock_irq(&pDevice->lock);
488 if (pDevice->bLinkPass) {
489 if (!memcmp(param->addr, pMgmt->abyCurrBSSID, 6))
490 bScheduleCommand((void *) pDevice, WLAN_CMD_DISASSOCIATE, NULL);
492 spin_unlock_irq(&pDevice->lock);
494 return ret;
500 * Description:
501 * enable scan process
503 * Parameters:
504 * In:
505 * pDevice -
506 * param -
507 * Out:
509 * Return Value:
513 static int wpa_set_scan(PSDevice pDevice,
514 struct viawget_wpa_param *param)
516 int ret = 0;
518 /**set ap_scan=1&&scan_ssid=1 under hidden ssid mode**/
519 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
520 PWLAN_IE_SSID pItemSSID;
521 printk("wpa_set_scan-->desired [ssid=%s,ssid_len=%d]\n",
522 param->u.scan_req.ssid,param->u.scan_req.ssid_len);
523 // Set the SSID
524 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
525 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
526 pItemSSID->byElementID = WLAN_EID_SSID;
527 memcpy(pItemSSID->abySSID, param->u.scan_req.ssid, param->u.scan_req.ssid_len);
528 pItemSSID->len = param->u.scan_req.ssid_len;
530 spin_lock_irq(&pDevice->lock);
531 BSSvClearBSSList((void *) pDevice, pDevice->bLinkPass);
532 /* bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, NULL); */
533 bScheduleCommand((void *) pDevice,
534 WLAN_CMD_BSSID_SCAN,
535 pMgmt->abyDesireSSID);
536 spin_unlock_irq(&pDevice->lock);
538 return ret;
544 * Description:
545 * get bssid
547 * Parameters:
548 * In:
549 * pDevice -
550 * param -
551 * Out:
553 * Return Value:
557 static int wpa_get_bssid(PSDevice pDevice,
558 struct viawget_wpa_param *param)
560 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
561 int ret = 0;
562 memcpy(param->u.wpa_associate.bssid, pMgmt->abyCurrBSSID , 6);
564 return ret;
570 * Description:
571 * get bssid
573 * Parameters:
574 * In:
575 * pDevice -
576 * param -
577 * Out:
579 * Return Value:
583 static int wpa_get_ssid(PSDevice pDevice,
584 struct viawget_wpa_param *param)
586 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
587 PWLAN_IE_SSID pItemSSID;
588 int ret = 0;
590 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
592 memcpy(param->u.wpa_associate.ssid, pItemSSID->abySSID , pItemSSID->len);
593 param->u.wpa_associate.ssid_len = pItemSSID->len;
595 return ret;
601 * Description:
602 * get scan results
604 * Parameters:
605 * In:
606 * pDevice -
607 * param -
608 * Out:
610 * Return Value:
614 static int wpa_get_scan(PSDevice pDevice,
615 struct viawget_wpa_param *param)
617 struct viawget_scan_result *scan_buf;
618 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
619 PWLAN_IE_SSID pItemSSID;
620 PKnownBSS pBSS;
621 PBYTE pBuf;
622 int ret = 0;
623 u16 count = 0;
624 u16 ii, jj;
625 long ldBm;//James //add
627 //******mike:bubble sort by stronger RSSI*****//
629 PBYTE ptempBSS;
633 ptempBSS = kmalloc(sizeof(KnownBSS), (int)GFP_ATOMIC);
635 if (ptempBSS == NULL) {
637 printk("bubble sort kmalloc memory fail@@@\n");
639 ret = -ENOMEM;
641 return ret;
645 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
647 for (jj = 0; jj < MAX_BSS_NUM - ii - 1; jj++) {
649 if ((pMgmt->sBSSList[jj].bActive != TRUE) ||
651 ((pMgmt->sBSSList[jj].uRSSI>pMgmt->sBSSList[jj+1].uRSSI) &&(pMgmt->sBSSList[jj+1].bActive!=FALSE))) {
653 memcpy(ptempBSS,&pMgmt->sBSSList[jj],sizeof(KnownBSS));
655 memcpy(&pMgmt->sBSSList[jj],&pMgmt->sBSSList[jj+1],sizeof(KnownBSS));
657 memcpy(&pMgmt->sBSSList[jj+1],ptempBSS,sizeof(KnownBSS));
665 kfree(ptempBSS);
667 // printk("bubble sort result:\n");
669 count = 0;
670 pBSS = &(pMgmt->sBSSList[0]);
671 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
672 pBSS = &(pMgmt->sBSSList[ii]);
673 if (!pBSS->bActive)
674 continue;
675 count++;
678 pBuf = kcalloc(count, sizeof(struct viawget_scan_result), (int)GFP_ATOMIC);
680 if (pBuf == NULL) {
681 ret = -ENOMEM;
682 return ret;
684 scan_buf = (struct viawget_scan_result *)pBuf;
685 pBSS = &(pMgmt->sBSSList[0]);
686 for (ii = 0, jj = 0; ii < MAX_BSS_NUM ; ii++) {
687 pBSS = &(pMgmt->sBSSList[ii]);
688 if (pBSS->bActive) {
689 if (jj >= count)
690 break;
691 memcpy(scan_buf->bssid, pBSS->abyBSSID, WLAN_BSSID_LEN);
692 pItemSSID = (PWLAN_IE_SSID)pBSS->abySSID;
693 memcpy(scan_buf->ssid, pItemSSID->abySSID, pItemSSID->len);
694 scan_buf->ssid_len = pItemSSID->len;
695 scan_buf->freq = frequency_list[pBSS->uChannel-1];
696 scan_buf->caps = pBSS->wCapInfo; //DavidWang for sharemode
698 RFvRSSITodBm(pDevice, (BYTE)(pBSS->uRSSI), &ldBm);
699 if(-ldBm<50){
700 scan_buf->qual = 100;
701 }else if(-ldBm > 90) {
702 scan_buf->qual = 0;
703 }else {
704 scan_buf->qual=(40-(-ldBm-50))*100/40;
707 //James
708 //scan_buf->caps = pBSS->wCapInfo;
709 //scan_buf->qual =
710 scan_buf->noise = 0;
711 scan_buf->level = ldBm;
713 //scan_buf->maxrate =
714 if (pBSS->wWPALen != 0) {
715 scan_buf->wpa_ie_len = pBSS->wWPALen;
716 memcpy(scan_buf->wpa_ie, pBSS->byWPAIE, pBSS->wWPALen);
718 if (pBSS->wRSNLen != 0) {
719 scan_buf->rsn_ie_len = pBSS->wRSNLen;
720 memcpy(scan_buf->rsn_ie, pBSS->byRSNIE, pBSS->wRSNLen);
722 scan_buf = (struct viawget_scan_result *)((PBYTE)scan_buf + sizeof(struct viawget_scan_result));
723 jj ++;
727 if (jj < count)
728 count = jj;
730 if (copy_to_user(param->u.scan_results.buf, pBuf, sizeof(struct viawget_scan_result) * count)) {
731 ret = -EFAULT;
733 param->u.scan_results.scan_count = count;
734 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " param->u.scan_results.scan_count = %d\n", count)
736 kfree(pBuf);
737 return ret;
743 * Description:
744 * set associate with AP
746 * Parameters:
747 * In:
748 * pDevice -
749 * param -
750 * Out:
752 * Return Value:
756 static int wpa_set_associate(PSDevice pDevice,
757 struct viawget_wpa_param *param)
759 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
760 PWLAN_IE_SSID pItemSSID;
761 BYTE abyNullAddr[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
762 BYTE abyWPAIE[64];
763 int ret = 0;
764 BOOL bwepEnabled=FALSE;
766 // set key type & algorithm
767 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pairwise_suite = %d\n", param->u.wpa_associate.pairwise_suite);
768 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "group_suite = %d\n", param->u.wpa_associate.group_suite);
769 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "key_mgmt_suite = %d\n", param->u.wpa_associate.key_mgmt_suite);
770 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "auth_alg = %d\n", param->u.wpa_associate.auth_alg);
771 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "mode = %d\n", param->u.wpa_associate.mode);
772 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wpa_ie_len = %d\n", param->u.wpa_associate.wpa_ie_len);
773 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Roaming dBm = %d\n", param->u.wpa_associate.roam_dbm); //Davidwang
775 if (param->u.wpa_associate.wpa_ie &&
776 copy_from_user(&abyWPAIE[0], param->u.wpa_associate.wpa_ie, param->u.wpa_associate.wpa_ie_len))
777 return -EINVAL;
779 if (param->u.wpa_associate.mode == 1)
780 pMgmt->eConfigMode = WMAC_CONFIG_IBSS_STA;
781 else
782 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
784 // set bssid
785 if (memcmp(param->u.wpa_associate.bssid, &abyNullAddr[0], 6) != 0)
786 memcpy(pMgmt->abyDesireBSSID, param->u.wpa_associate.bssid, 6);
787 // set ssid
788 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
789 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
790 pItemSSID->byElementID = WLAN_EID_SSID;
791 pItemSSID->len = param->u.wpa_associate.ssid_len;
792 memcpy(pItemSSID->abySSID, param->u.wpa_associate.ssid, pItemSSID->len);
794 if (param->u.wpa_associate.wpa_ie_len == 0) {
795 if (param->u.wpa_associate.auth_alg & AUTH_ALG_SHARED_KEY)
796 pMgmt->eAuthenMode = WMAC_AUTH_SHAREKEY;
797 else
798 pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
799 } else if (abyWPAIE[0] == RSN_INFO_ELEM) {
800 if (param->u.wpa_associate.key_mgmt_suite == KEY_MGMT_PSK)
801 pMgmt->eAuthenMode = WMAC_AUTH_WPA2PSK;
802 else
803 pMgmt->eAuthenMode = WMAC_AUTH_WPA2;
804 } else {
805 if (param->u.wpa_associate.key_mgmt_suite == KEY_MGMT_WPA_NONE)
806 pMgmt->eAuthenMode = WMAC_AUTH_WPANONE;
807 else if (param->u.wpa_associate.key_mgmt_suite == KEY_MGMT_PSK)
808 pMgmt->eAuthenMode = WMAC_AUTH_WPAPSK;
809 else
810 pMgmt->eAuthenMode = WMAC_AUTH_WPA;
813 switch (param->u.wpa_associate.pairwise_suite) {
814 case CIPHER_CCMP:
815 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
816 break;
817 case CIPHER_TKIP:
818 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
819 break;
820 case CIPHER_WEP40:
821 case CIPHER_WEP104:
822 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
823 bwepEnabled = TRUE;
824 // printk("****************wpa_set_associate:set CIPHER_WEP40_104\n");
825 break;
826 case CIPHER_NONE:
827 if (param->u.wpa_associate.group_suite == CIPHER_CCMP)
828 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
829 else
830 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
831 break;
832 default:
833 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
836 pMgmt->Roam_dbm = param->u.wpa_associate.roam_dbm;
837 // if ((pMgmt->Roam_dbm > 40)&&(pMgmt->Roam_dbm<80))
838 // pDevice->bEnableRoaming = TRUE;
840 if (pMgmt->eAuthenMode == WMAC_AUTH_SHAREKEY) { //@wep-sharekey
841 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
842 pMgmt->bShareKeyAlgorithm = TRUE;
844 else if (pMgmt->eAuthenMode == WMAC_AUTH_OPEN) {
845 if(bwepEnabled==TRUE) { //@open-wep
846 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
848 else { //@only open
849 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
852 //mike save old encryption status
853 pDevice->eOldEncryptionStatus = pDevice->eEncryptionStatus;
855 if (pDevice->eEncryptionStatus != Ndis802_11EncryptionDisabled)
856 pDevice->bEncryptionEnable = TRUE;
857 else
858 pDevice->bEncryptionEnable = FALSE;
860 if ((pMgmt->eAuthenMode == WMAC_AUTH_SHAREKEY) ||
861 ((pMgmt->eAuthenMode == WMAC_AUTH_OPEN) && (bwepEnabled==TRUE))) {
862 //mike re-comment:open-wep && sharekey-wep needn't do initial key!!
865 else
866 KeyvInitTable(pDevice,&pDevice->sKey);
868 spin_lock_irq(&pDevice->lock);
869 pDevice->bLinkPass = FALSE;
870 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW);
871 memset(pMgmt->abyCurrBSSID, 0, 6);
872 pMgmt->eCurrState = WMAC_STATE_IDLE;
873 netif_stop_queue(pDevice->dev);
875 /*******search if ap_scan=2 ,which is associating request in hidden ssid mode ****/
877 PKnownBSS pCurr = NULL;
878 pCurr = BSSpSearchBSSList(pDevice,
879 pMgmt->abyDesireBSSID,
880 pMgmt->abyDesireSSID,
881 pDevice->eConfigPHYMode
884 if (pCurr == NULL){
885 printk("wpa_set_associate---->hidden mode site survey before associate.......\n");
886 bScheduleCommand((void *) pDevice,
887 WLAN_CMD_BSSID_SCAN,
888 pMgmt->abyDesireSSID);
891 /****************************************************************/
893 bScheduleCommand((void *) pDevice, WLAN_CMD_SSID, NULL);
894 spin_unlock_irq(&pDevice->lock);
896 return ret;
901 * Description:
902 * wpa_ioctl main function supported for wpa supplicant
904 * Parameters:
905 * In:
906 * pDevice -
907 * iw_point -
908 * Out:
910 * Return Value:
914 int wpa_ioctl(PSDevice pDevice, struct iw_point *p)
916 struct viawget_wpa_param *param;
917 int ret = 0;
918 int wpa_ioctl = 0;
920 if (p->length < sizeof(struct viawget_wpa_param) ||
921 p->length > VIAWGET_WPA_MAX_BUF_SIZE || !p->pointer)
922 return -EINVAL;
924 param = kmalloc((int)p->length, (int)GFP_KERNEL);
925 if (param == NULL)
926 return -ENOMEM;
928 if (copy_from_user(param, p->pointer, p->length)) {
929 ret = -EFAULT;
930 goto out;
933 switch (param->cmd) {
934 case VIAWGET_SET_WPA:
935 ret = wpa_set_wpa(pDevice, param);
936 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_WPA \n");
937 break;
939 case VIAWGET_SET_KEY:
940 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_KEY \n");
941 spin_lock_irq(&pDevice->lock);
942 ret = wpa_set_keys(pDevice, param, FALSE);
943 spin_unlock_irq(&pDevice->lock);
944 break;
946 case VIAWGET_SET_SCAN:
947 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_SCAN \n");
948 ret = wpa_set_scan(pDevice, param);
949 break;
951 case VIAWGET_GET_SCAN:
952 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_GET_SCAN\n");
953 ret = wpa_get_scan(pDevice, param);
954 wpa_ioctl = 1;
955 break;
957 case VIAWGET_GET_SSID:
958 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_GET_SSID \n");
959 ret = wpa_get_ssid(pDevice, param);
960 wpa_ioctl = 1;
961 break;
963 case VIAWGET_GET_BSSID:
964 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_GET_BSSID \n");
965 ret = wpa_get_bssid(pDevice, param);
966 wpa_ioctl = 1;
967 break;
969 case VIAWGET_SET_ASSOCIATE:
970 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_ASSOCIATE \n");
971 ret = wpa_set_associate(pDevice, param);
972 break;
974 case VIAWGET_SET_DISASSOCIATE:
975 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_DISASSOCIATE \n");
976 ret = wpa_set_disassociate(pDevice, param);
977 break;
979 case VIAWGET_SET_DROP_UNENCRYPT:
980 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_DROP_UNENCRYPT \n");
981 break;
983 case VIAWGET_SET_DEAUTHENTICATE:
984 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_DEAUTHENTICATE \n");
985 break;
987 default:
988 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wpa_ioctl: unknown cmd=%d\n",
989 param->cmd);
990 return -EOPNOTSUPP;
991 break;
994 if ((ret == 0) && wpa_ioctl) {
995 if (copy_to_user(p->pointer, param, p->length)) {
996 ret = -EFAULT;
997 goto out;
1001 out:
1002 kfree(param);
1004 return ret;