On Tue, Nov 06, 2007 at 02:33:53AM -0800, akpm@linux-foundation.org wrote:
[mmotm.git] / drivers / staging / vt6656 / wpactl.c
blob4555bc0448b957d908350d1e2bcda7bfd4ae9035
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, U_ETHER_ADDR_LEN);
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);
191 * Description:
192 * Set WPA algorithm & keys
194 * Parameters:
195 * In:
196 * pDevice -
197 * param -
198 * Out:
200 * Return Value:
204 int wpa_set_keys(PSDevice pDevice, void *ctx, BOOL fcpfkernel)
206 struct viawget_wpa_param *param=ctx;
207 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
208 DWORD dwKeyIndex = 0;
209 BYTE abyKey[MAX_KEY_LEN];
210 BYTE abySeq[MAX_KEY_LEN];
211 QWORD KeyRSC;
212 // NDIS_802_11_KEY_RSC KeyRSC;
213 BYTE byKeyDecMode = KEY_CTL_WEP;
214 int ret = 0;
215 int uu, ii;
218 if (param->u.wpa_key.alg_name > WPA_ALG_CCMP)
219 return -EINVAL;
221 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "param->u.wpa_key.alg_name = %d \n", param->u.wpa_key.alg_name);
222 if (param->u.wpa_key.alg_name == WPA_ALG_NONE) {
223 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
224 pDevice->bEncryptionEnable = FALSE;
225 pDevice->byKeyIndex = 0;
226 pDevice->bTransmitKey = FALSE;
227 for (uu=0; uu<MAX_KEY_TABLE; uu++) {
228 MACvDisableKeyEntry(pDevice, uu);
230 return ret;
233 spin_unlock_irq(&pDevice->lock);
234 if(param->u.wpa_key.key && fcpfkernel) {
235 memcpy(&abyKey[0], param->u.wpa_key.key, param->u.wpa_key.key_len);
237 else {
238 if (param->u.wpa_key.key &&
239 copy_from_user(&abyKey[0], param->u.wpa_key.key, param->u.wpa_key.key_len)) {
240 spin_lock_irq(&pDevice->lock);
241 return -EINVAL;
244 spin_lock_irq(&pDevice->lock);
246 dwKeyIndex = (DWORD)(param->u.wpa_key.key_index);
248 if (param->u.wpa_key.alg_name == WPA_ALG_WEP) {
249 if (dwKeyIndex > 3) {
250 return -EINVAL;
252 else {
253 if (param->u.wpa_key.set_tx) {
254 pDevice->byKeyIndex = (BYTE)dwKeyIndex;
255 pDevice->bTransmitKey = TRUE;
256 dwKeyIndex |= (1 << 31);
258 KeybSetDefaultKey( pDevice,
259 &(pDevice->sKey),
260 dwKeyIndex & ~(BIT30 | USE_KEYRSC),
261 param->u.wpa_key.key_len,
262 NULL,
263 abyKey,
264 KEY_CTL_WEP
268 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
269 pDevice->bEncryptionEnable = TRUE;
270 return ret;
273 spin_unlock_irq(&pDevice->lock);
274 if(param->u.wpa_key.seq && fcpfkernel) {
275 memcpy(&abySeq[0], param->u.wpa_key.seq, param->u.wpa_key.seq_len);
277 else {
278 if (param->u.wpa_key.seq &&
279 copy_from_user(&abySeq[0], param->u.wpa_key.seq, param->u.wpa_key.seq_len)) {
280 spin_lock_irq(&pDevice->lock);
281 return -EINVAL;
284 spin_lock_irq(&pDevice->lock);
286 if (param->u.wpa_key.seq_len > 0) {
287 for (ii = 0 ; ii < param->u.wpa_key.seq_len ; ii++) {
288 if (ii < 4)
289 LODWORD(KeyRSC) |= (abySeq[ii] << (ii * 8));
290 else
291 HIDWORD(KeyRSC) |= (abySeq[ii] << ((ii-4) * 8));
292 //KeyRSC |= (abySeq[ii] << (ii * 8));
294 dwKeyIndex |= 1 << 29;
297 if (param->u.wpa_key.key_index >= MAX_GROUP_KEY) {
298 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "return dwKeyIndex > 3\n");
299 return -EINVAL;
302 if (param->u.wpa_key.alg_name == WPA_ALG_TKIP) {
303 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
306 if (param->u.wpa_key.alg_name == WPA_ALG_CCMP) {
307 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
310 if (param->u.wpa_key.set_tx)
311 dwKeyIndex |= (1 << 31);
314 if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled)
315 byKeyDecMode = KEY_CTL_CCMP;
316 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled)
317 byKeyDecMode = KEY_CTL_TKIP;
318 else
319 byKeyDecMode = KEY_CTL_WEP;
321 // Fix HCT test that set 256 bits KEY and Ndis802_11Encryption3Enabled
322 if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
323 if (param->u.wpa_key.key_len == MAX_KEY_LEN)
324 byKeyDecMode = KEY_CTL_TKIP;
325 else if (param->u.wpa_key.key_len == WLAN_WEP40_KEYLEN)
326 byKeyDecMode = KEY_CTL_WEP;
327 else if (param->u.wpa_key.key_len == WLAN_WEP104_KEYLEN)
328 byKeyDecMode = KEY_CTL_WEP;
329 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
330 if (param->u.wpa_key.key_len == WLAN_WEP40_KEYLEN)
331 byKeyDecMode = KEY_CTL_WEP;
332 else if (param->u.wpa_key.key_len == WLAN_WEP104_KEYLEN)
333 byKeyDecMode = KEY_CTL_WEP;
336 // Check TKIP key length
337 if ((byKeyDecMode == KEY_CTL_TKIP) &&
338 (param->u.wpa_key.key_len != MAX_KEY_LEN)) {
339 // TKIP Key must be 256 bits
340 //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA - TKIP Key must be 256 bits\n"));
341 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "return- TKIP Key must be 256 bits!\n");
342 return -EINVAL;
344 // Check AES key length
345 if ((byKeyDecMode == KEY_CTL_CCMP) &&
346 (param->u.wpa_key.key_len != AES_KEY_LEN)) {
347 // AES Key must be 128 bits
348 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "return - AES Key must be 128 bits\n");
349 return -EINVAL;
353 if (IS_BROADCAST_ADDRESS(&param->addr[0]) || (param->addr == NULL)) {
354 // If IS_BROADCAST_ADDRESS, set the key as every key entry's group key.
355 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Groupe Key Assign.\n");
357 if ((KeybSetAllGroupKey(pDevice,
358 &(pDevice->sKey),
359 dwKeyIndex,
360 param->u.wpa_key.key_len,
361 (PQWORD) &(KeyRSC),
362 (PBYTE)abyKey,
363 byKeyDecMode
364 ) == TRUE) &&
365 (KeybSetDefaultKey(pDevice,
366 &(pDevice->sKey),
367 dwKeyIndex,
368 param->u.wpa_key.key_len,
369 (PQWORD) &(KeyRSC),
370 (PBYTE)abyKey,
371 byKeyDecMode
372 ) == TRUE) ) {
373 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "GROUP Key Assign.\n");
375 } else {
376 //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA -KeybSetDefaultKey Fail.0\n"));
377 return -EINVAL;
380 } else {
381 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pairwise Key Assign.\n");
382 // BSSID not 0xffffffffffff
383 // Pairwise Key can't be WEP
384 if (byKeyDecMode == KEY_CTL_WEP) {
385 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pairwise Key can't be WEP\n");
386 return -EINVAL;
389 dwKeyIndex |= (1 << 30); // set pairwise key
390 if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) {
391 //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA - WMAC_CONFIG_IBSS_STA\n"));
392 return -EINVAL;
394 if (KeybSetKey(pDevice,
395 &(pDevice->sKey),
396 &param->addr[0],
397 dwKeyIndex,
398 param->u.wpa_key.key_len,
399 (PQWORD) &(KeyRSC),
400 (PBYTE)abyKey,
401 byKeyDecMode
402 ) == TRUE) {
403 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pairwise Key Set\n");
405 } else {
406 // Key Table Full
407 if (IS_ETH_ADDRESS_EQUAL(&param->addr[0], pDevice->abyBSSID)) {
408 //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA -Key Table Full.2\n"));
409 return -EINVAL;
411 } else {
412 // Save Key and configure just before associate/reassociate to BSSID
413 // we do not implement now
414 return -EINVAL;
417 } // BSSID not 0xffffffffffff
418 if ((ret == 0) && ((param->u.wpa_key.set_tx) != 0)) {
419 pDevice->byKeyIndex = (BYTE)param->u.wpa_key.key_index;
420 pDevice->bTransmitKey = TRUE;
422 pDevice->bEncryptionEnable = TRUE;
425 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " key=%x-%x-%x-%x-%x-xxxxx \n",
426 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][0],
427 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][1],
428 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][2],
429 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][3],
430 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][4]
434 return ret;
440 * Description:
441 * enable wpa auth & mode
443 * Parameters:
444 * In:
445 * pDevice -
446 * param -
447 * Out:
449 * Return Value:
453 static int wpa_set_wpa(PSDevice pDevice,
454 struct viawget_wpa_param *param)
457 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
458 int ret = 0;
460 pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
461 pMgmt->bShareKeyAlgorithm = FALSE;
463 return ret;
470 * Description:
471 * set disassociate
473 * Parameters:
474 * In:
475 * pDevice -
476 * param -
477 * Out:
479 * Return Value:
483 static int wpa_set_disassociate(PSDevice pDevice,
484 struct viawget_wpa_param *param)
486 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
487 int ret = 0;
489 spin_lock_irq(&pDevice->lock);
490 if (pDevice->bLinkPass) {
491 if (!memcmp(param->addr, pMgmt->abyCurrBSSID, 6))
492 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_DISASSOCIATE, NULL);
494 spin_unlock_irq(&pDevice->lock);
496 return ret;
502 * Description:
503 * enable scan process
505 * Parameters:
506 * In:
507 * pDevice -
508 * param -
509 * Out:
511 * Return Value:
515 static int wpa_set_scan(PSDevice pDevice,
516 struct viawget_wpa_param *param)
518 int ret = 0;
520 //2007-0919-01<Add>by MikeLiu
521 /**set ap_scan=1&&scan_ssid=1 under hidden ssid mode**/
522 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
523 PWLAN_IE_SSID pItemSSID;
524 printk("wpa_set_scan-->desired [ssid=%s,ssid_len=%d]\n",
525 param->u.scan_req.ssid,param->u.scan_req.ssid_len);
526 // Set the SSID
527 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
528 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
529 pItemSSID->byElementID = WLAN_EID_SSID;
530 memcpy(pItemSSID->abySSID, param->u.scan_req.ssid, param->u.scan_req.ssid_len);
531 pItemSSID->len = param->u.scan_req.ssid_len;
533 spin_lock_irq(&pDevice->lock);
534 BSSvClearBSSList((HANDLE)pDevice, pDevice->bLinkPass);
535 // bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, NULL);
536 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
537 spin_unlock_irq(&pDevice->lock);
539 return ret;
545 * Description:
546 * get bssid
548 * Parameters:
549 * In:
550 * pDevice -
551 * param -
552 * Out:
554 * Return Value:
558 static int wpa_get_bssid(PSDevice pDevice,
559 struct viawget_wpa_param *param)
561 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
562 int ret = 0;
563 memcpy(param->u.wpa_associate.bssid, pMgmt->abyCurrBSSID , 6);
565 return ret;
571 * Description:
572 * get bssid
574 * Parameters:
575 * In:
576 * pDevice -
577 * param -
578 * Out:
580 * Return Value:
584 static int wpa_get_ssid(PSDevice pDevice,
585 struct viawget_wpa_param *param)
587 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
588 PWLAN_IE_SSID pItemSSID;
589 int ret = 0;
591 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
593 memcpy(param->u.wpa_associate.ssid, pItemSSID->abySSID , pItemSSID->len);
594 param->u.wpa_associate.ssid_len = pItemSSID->len;
596 return ret;
602 * Description:
603 * get scan results
605 * Parameters:
606 * In:
607 * pDevice -
608 * param -
609 * Out:
611 * Return Value:
615 static int wpa_get_scan(PSDevice pDevice,
616 struct viawget_wpa_param *param)
618 struct viawget_scan_result *scan_buf;
619 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
620 PWLAN_IE_SSID pItemSSID;
621 PKnownBSS pBSS;
622 PBYTE pBuf;
623 int ret = 0;
624 u16 count = 0;
625 u16 ii, jj;
626 long ldBm;//James //add
628 //******mike:bubble sort by stronger RSSI*****//
630 PBYTE ptempBSS;
634 ptempBSS = kmalloc(sizeof(KnownBSS), (int)GFP_ATOMIC);
636 if (ptempBSS == NULL) {
638 printk("bubble sort kmalloc memory fail@@@\n");
640 ret = -ENOMEM;
642 return ret;
646 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
648 for(jj=0;jj<MAX_BSS_NUM-ii-1;jj++) {
650 if((pMgmt->sBSSList[jj].bActive!=TRUE) ||
652 ((pMgmt->sBSSList[jj].uRSSI>pMgmt->sBSSList[jj+1].uRSSI) &&(pMgmt->sBSSList[jj+1].bActive!=FALSE))) {
654 memcpy(ptempBSS,&pMgmt->sBSSList[jj],sizeof(KnownBSS));
656 memcpy(&pMgmt->sBSSList[jj],&pMgmt->sBSSList[jj+1],sizeof(KnownBSS));
658 memcpy(&pMgmt->sBSSList[jj+1],ptempBSS,sizeof(KnownBSS));
666 kfree(ptempBSS);
668 // printk("bubble sort result:\n");
670 count = 0;
671 pBSS = &(pMgmt->sBSSList[0]);
672 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
673 pBSS = &(pMgmt->sBSSList[ii]);
674 if (!pBSS->bActive)
675 continue;
676 count++;
679 pBuf = kmalloc(sizeof(struct viawget_scan_result) * count, (int)GFP_ATOMIC);
681 if (pBuf == NULL) {
682 ret = -ENOMEM;
683 return ret;
685 memset(pBuf, 0, sizeof(struct viawget_scan_result) * count);
686 scan_buf = (struct viawget_scan_result *)pBuf;
687 pBSS = &(pMgmt->sBSSList[0]);
688 for (ii = 0, jj = 0; ii < MAX_BSS_NUM ; ii++) {
689 pBSS = &(pMgmt->sBSSList[ii]);
690 if (pBSS->bActive) {
691 if (jj >= count)
692 break;
693 memcpy(scan_buf->bssid, pBSS->abyBSSID, WLAN_BSSID_LEN);
694 pItemSSID = (PWLAN_IE_SSID)pBSS->abySSID;
695 memcpy(scan_buf->ssid, pItemSSID->abySSID, pItemSSID->len);
696 scan_buf->ssid_len = pItemSSID->len;
697 scan_buf->freq = frequency_list[pBSS->uChannel-1];
698 scan_buf->caps = pBSS->wCapInfo; //DavidWang for sharemode
699 //20080717-05,<Add> by James Li
700 RFvRSSITodBm(pDevice, (BYTE)(pBSS->uRSSI), &ldBm);
701 if(-ldBm<50){
702 scan_buf->qual = 100;
703 }else if(-ldBm > 90) {
704 scan_buf->qual = 0;
705 }else {
706 scan_buf->qual=(40-(-ldBm-50))*100/40;
709 //James
710 //scan_buf->caps = pBSS->wCapInfo;
711 //scan_buf->qual =
712 scan_buf->noise = 0;
713 scan_buf->level = ldBm;
714 //20080717-05,<Add> by James Li--End
715 //scan_buf->maxrate =
716 if (pBSS->wWPALen != 0) {
717 scan_buf->wpa_ie_len = pBSS->wWPALen;
718 memcpy(scan_buf->wpa_ie, pBSS->byWPAIE, pBSS->wWPALen);
720 if (pBSS->wRSNLen != 0) {
721 scan_buf->rsn_ie_len = pBSS->wRSNLen;
722 memcpy(scan_buf->rsn_ie, pBSS->byRSNIE, pBSS->wRSNLen);
724 scan_buf = (struct viawget_scan_result *)((PBYTE)scan_buf + sizeof(struct viawget_scan_result));
725 jj ++;
729 if (jj < count)
730 count = jj;
732 if (copy_to_user(param->u.scan_results.buf, pBuf, sizeof(struct viawget_scan_result) * count)) {
733 ret = -EFAULT;
735 param->u.scan_results.scan_count = count;
736 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " param->u.scan_results.scan_count = %d\n", count)
738 kfree(pBuf);
739 return ret;
745 * Description:
746 * set associate with AP
748 * Parameters:
749 * In:
750 * pDevice -
751 * param -
752 * Out:
754 * Return Value:
758 static int wpa_set_associate(PSDevice pDevice,
759 struct viawget_wpa_param *param)
761 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
762 PWLAN_IE_SSID pItemSSID;
763 BYTE abyNullAddr[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
764 BYTE abyWPAIE[64];
765 int ret = 0;
766 BOOL bwepEnabled=FALSE;
768 // set key type & algorithm
769 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pairwise_suite = %d\n", param->u.wpa_associate.pairwise_suite);
770 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "group_suite = %d\n", param->u.wpa_associate.group_suite);
771 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "key_mgmt_suite = %d\n", param->u.wpa_associate.key_mgmt_suite);
772 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "auth_alg = %d\n", param->u.wpa_associate.auth_alg);
773 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "mode = %d\n", param->u.wpa_associate.mode);
774 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wpa_ie_len = %d\n", param->u.wpa_associate.wpa_ie_len);
775 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Roaming dBm = %d\n", param->u.wpa_associate.roam_dbm); //Davidwang
777 if (param->u.wpa_associate.wpa_ie &&
778 copy_from_user(&abyWPAIE[0], param->u.wpa_associate.wpa_ie, param->u.wpa_associate.wpa_ie_len))
779 return -EINVAL;
781 if (param->u.wpa_associate.mode == 1)
782 pMgmt->eConfigMode = WMAC_CONFIG_IBSS_STA;
783 else
784 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
786 // set bssid
787 if (memcmp(param->u.wpa_associate.bssid, &abyNullAddr[0], 6) != 0)
788 memcpy(pMgmt->abyDesireBSSID, param->u.wpa_associate.bssid, 6);
789 // set ssid
790 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
791 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
792 pItemSSID->byElementID = WLAN_EID_SSID;
793 pItemSSID->len = param->u.wpa_associate.ssid_len;
794 memcpy(pItemSSID->abySSID, param->u.wpa_associate.ssid, pItemSSID->len);
796 if (param->u.wpa_associate.wpa_ie_len == 0) {
797 if (param->u.wpa_associate.auth_alg & AUTH_ALG_SHARED_KEY)
798 pMgmt->eAuthenMode = WMAC_AUTH_SHAREKEY;
799 else
800 pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
801 } else if (abyWPAIE[0] == RSN_INFO_ELEM) {
802 if (param->u.wpa_associate.key_mgmt_suite == KEY_MGMT_PSK)
803 pMgmt->eAuthenMode = WMAC_AUTH_WPA2PSK;
804 else
805 pMgmt->eAuthenMode = WMAC_AUTH_WPA2;
806 } else {
807 if (param->u.wpa_associate.key_mgmt_suite == KEY_MGMT_WPA_NONE)
808 pMgmt->eAuthenMode = WMAC_AUTH_WPANONE;
809 else if (param->u.wpa_associate.key_mgmt_suite == KEY_MGMT_PSK)
810 pMgmt->eAuthenMode = WMAC_AUTH_WPAPSK;
811 else
812 pMgmt->eAuthenMode = WMAC_AUTH_WPA;
815 switch (param->u.wpa_associate.pairwise_suite) {
816 case CIPHER_CCMP:
817 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
818 break;
819 case CIPHER_TKIP:
820 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
821 break;
822 case CIPHER_WEP40:
823 case CIPHER_WEP104:
824 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
825 bwepEnabled = TRUE;
826 // printk("****************wpa_set_associate:set CIPHER_WEP40_104\n");
827 break;
828 case CIPHER_NONE:
829 if (param->u.wpa_associate.group_suite == CIPHER_CCMP)
830 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
831 else
832 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
833 break;
834 default:
835 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
838 pMgmt->Roam_dbm = param->u.wpa_associate.roam_dbm;
839 // if ((pMgmt->Roam_dbm > 40)&&(pMgmt->Roam_dbm<80))
840 // pDevice->bEnableRoaming = TRUE;
842 if (pMgmt->eAuthenMode == WMAC_AUTH_SHAREKEY) { //@wep-sharekey
843 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
844 pMgmt->bShareKeyAlgorithm = TRUE;
846 else if (pMgmt->eAuthenMode == WMAC_AUTH_OPEN) {
847 if(bwepEnabled==TRUE) { //@open-wep
848 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
850 else { //@only open
851 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
854 //mike save old encryption status
855 pDevice->eOldEncryptionStatus = pDevice->eEncryptionStatus;
857 if (pDevice->eEncryptionStatus != Ndis802_11EncryptionDisabled)
858 pDevice->bEncryptionEnable = TRUE;
859 else
860 pDevice->bEncryptionEnable = FALSE;
862 if ((pMgmt->eAuthenMode == WMAC_AUTH_SHAREKEY) ||
863 ((pMgmt->eAuthenMode == WMAC_AUTH_OPEN) && (bwepEnabled==TRUE))) {
864 //mike re-comment:open-wep && sharekey-wep needn't do initial key!!
867 else
868 KeyvInitTable(pDevice,&pDevice->sKey);
870 spin_lock_irq(&pDevice->lock);
871 pDevice->bLinkPass = FALSE;
872 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW);
873 memset(pMgmt->abyCurrBSSID, 0, 6);
874 pMgmt->eCurrState = WMAC_STATE_IDLE;
875 netif_stop_queue(pDevice->dev);
877 //20080701-02,<Add> by Mike Liu
878 /*******search if ap_scan=2 ,which is associating request in hidden ssid mode ****/
880 PKnownBSS pCurr = NULL;
881 pCurr = BSSpSearchBSSList(pDevice,
882 pMgmt->abyDesireBSSID,
883 pMgmt->abyDesireSSID,
884 pDevice->eConfigPHYMode
887 if (pCurr == NULL){
888 printk("wpa_set_associate---->hidden mode site survey before associate.......\n");
889 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
892 /****************************************************************/
894 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_SSID, NULL);
895 spin_unlock_irq(&pDevice->lock);
897 return ret;
902 * Description:
903 * wpa_ioctl main function supported for wpa supplicant
905 * Parameters:
906 * In:
907 * pDevice -
908 * iw_point -
909 * Out:
911 * Return Value:
915 int wpa_ioctl(PSDevice pDevice, struct iw_point *p)
917 struct viawget_wpa_param *param;
918 int ret = 0;
919 int wpa_ioctl = 0;
921 if (p->length < sizeof(struct viawget_wpa_param) ||
922 p->length > VIAWGET_WPA_MAX_BUF_SIZE || !p->pointer)
923 return -EINVAL;
925 param = (struct viawget_wpa_param *) kmalloc((int)p->length, (int)GFP_KERNEL);
926 if (param == NULL)
927 return -ENOMEM;
929 if (copy_from_user(param, p->pointer, p->length)) {
930 ret = -EFAULT;
931 goto out;
934 switch (param->cmd) {
935 case VIAWGET_SET_WPA:
936 ret = wpa_set_wpa(pDevice, param);
937 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_WPA \n");
938 break;
940 case VIAWGET_SET_KEY:
941 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_KEY \n");
942 spin_lock_irq(&pDevice->lock);
943 ret = wpa_set_keys(pDevice, param, FALSE);
944 spin_unlock_irq(&pDevice->lock);
945 break;
947 case VIAWGET_SET_SCAN:
948 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_SCAN \n");
949 ret = wpa_set_scan(pDevice, param);
950 break;
952 case VIAWGET_GET_SCAN:
953 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_GET_SCAN\n");
954 ret = wpa_get_scan(pDevice, param);
955 wpa_ioctl = 1;
956 break;
958 case VIAWGET_GET_SSID:
959 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_GET_SSID \n");
960 ret = wpa_get_ssid(pDevice, param);
961 wpa_ioctl = 1;
962 break;
964 case VIAWGET_GET_BSSID:
965 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_GET_BSSID \n");
966 ret = wpa_get_bssid(pDevice, param);
967 wpa_ioctl = 1;
968 break;
970 case VIAWGET_SET_ASSOCIATE:
971 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_ASSOCIATE \n");
972 ret = wpa_set_associate(pDevice, param);
973 break;
975 case VIAWGET_SET_DISASSOCIATE:
976 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_DISASSOCIATE \n");
977 ret = wpa_set_disassociate(pDevice, param);
978 break;
980 case VIAWGET_SET_DROP_UNENCRYPT:
981 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_DROP_UNENCRYPT \n");
982 break;
984 case VIAWGET_SET_DEAUTHENTICATE:
985 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_DEAUTHENTICATE \n");
986 break;
988 default:
989 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wpa_ioctl: unknown cmd=%d\n",
990 param->cmd);
991 return -EOPNOTSUPP;
992 break;
995 if ((ret == 0) && wpa_ioctl) {
996 if (copy_to_user(p->pointer, param, p->length)) {
997 ret = -EFAULT;
998 goto out;
1002 out:
1003 if (param != NULL)
1004 kfree(param);
1006 return ret;