Btrfs: device_list_add() should not update list when mounted
[linux/fpc-iii.git] / drivers / staging / vt6655 / wpactl.c
blob8392d4d1d5ed75e83ff60123bc66f9f17132b016
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: Oct. 20, 2003
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 "rf.h"
43 /*--------------------- Static Definitions -------------------------*/
45 #define VIAWGET_WPA_MAX_BUF_SIZE 1024
47 static const int frequency_list[] = {
48 2412, 2417, 2422, 2427, 2432, 2437, 2442,
49 2447, 2452, 2457, 2462, 2467, 2472, 2484
51 /*--------------------- Static Classes ----------------------------*/
53 /*--------------------- Static Variables --------------------------*/
54 static int msglevel = MSG_LEVEL_INFO;
56 /*--------------------- Static Functions --------------------------*/
58 /*--------------------- Export Variables --------------------------*/
59 static void wpadev_setup(struct net_device *dev)
61 dev->type = ARPHRD_IEEE80211;
62 dev->hard_header_len = ETH_HLEN;
63 dev->mtu = 2048;
64 dev->addr_len = ETH_ALEN;
65 dev->tx_queue_len = 1000;
67 memset(dev->broadcast, 0xFF, ETH_ALEN);
69 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
73 * Description:
74 * register netdev for wpa supplicant daemon
76 * Parameters:
77 * In:
78 * pDevice -
79 * enable -
80 * Out:
82 * Return Value:
86 static int wpa_init_wpadev(PSDevice pDevice)
88 PSDevice wpadev_priv;
89 struct net_device *dev = pDevice->dev;
90 int ret = 0;
92 pDevice->wpadev = alloc_netdev(sizeof(PSDevice), "vntwpa", wpadev_setup);
93 if (pDevice->wpadev == NULL)
94 return -ENOMEM;
96 wpadev_priv = netdev_priv(pDevice->wpadev);
97 *wpadev_priv = *pDevice;
98 eth_hw_addr_inherit(pDevice->wpadev, dev);
99 pDevice->wpadev->base_addr = dev->base_addr;
100 pDevice->wpadev->irq = dev->irq;
101 pDevice->wpadev->mem_start = dev->mem_start;
102 pDevice->wpadev->mem_end = dev->mem_end;
103 ret = register_netdev(pDevice->wpadev);
104 if (ret) {
105 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: register_netdev(WPA) failed!\n",
106 dev->name);
107 free_netdev(pDevice->wpadev);
108 return -1;
111 if (pDevice->skb == NULL) {
112 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
113 if (pDevice->skb == NULL)
114 return -ENOMEM;
117 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Registered netdev %s for WPA management\n",
118 dev->name, pDevice->wpadev->name);
120 return 0;
124 * Description:
125 * unregister net_device (wpadev)
127 * Parameters:
128 * In:
129 * pDevice -
130 * Out:
132 * Return Value:
136 static int wpa_release_wpadev(PSDevice pDevice)
138 if (pDevice->skb) {
139 dev_kfree_skb(pDevice->skb);
140 pDevice->skb = NULL;
143 if (pDevice->wpadev) {
144 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Netdevice %s unregistered\n",
145 pDevice->dev->name, pDevice->wpadev->name);
146 unregister_netdev(pDevice->wpadev);
147 free_netdev(pDevice->wpadev);
148 pDevice->wpadev = NULL;
151 return 0;
155 * Description:
156 * Set enable/disable dev for wpa supplicant daemon
158 * Parameters:
159 * In:
160 * pDevice -
161 * val -
162 * Out:
164 * Return Value:
168 int wpa_set_wpadev(PSDevice pDevice, int val)
170 if (val)
171 return wpa_init_wpadev(pDevice);
172 else
173 return wpa_release_wpadev(pDevice);
177 * Description:
178 * Set WPA algorithm & keys
180 * Parameters:
181 * In:
182 * pDevice -
183 * param -
184 * Out:
186 * Return Value:
190 int wpa_set_keys(PSDevice pDevice, void *ctx,
191 bool fcpfkernel) __must_hold(&pDevice->lock)
193 struct viawget_wpa_param *param = ctx;
194 PSMgmtObject pMgmt = pDevice->pMgmt;
195 unsigned long dwKeyIndex = 0;
196 unsigned char abyKey[MAX_KEY_LEN];
197 unsigned char abySeq[MAX_KEY_LEN];
198 QWORD KeyRSC;
199 unsigned char byKeyDecMode = KEY_CTL_WEP;
200 int ret = 0;
201 int uu, ii;
203 if (param->u.wpa_key.alg_name > WPA_ALG_CCMP ||
204 param->u.wpa_key.key_len > MAX_KEY_LEN ||
205 param->u.wpa_key.seq_len > MAX_KEY_LEN)
206 return -EINVAL;
208 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "param->u.wpa_key.alg_name = %d\n", param->u.wpa_key.alg_name);
209 if (param->u.wpa_key.alg_name == WPA_ALG_NONE) {
210 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
211 pDevice->bEncryptionEnable = false;
212 pDevice->byKeyIndex = 0;
213 pDevice->bTransmitKey = false;
214 KeyvRemoveAllWEPKey(&(pDevice->sKey), pDevice->PortOffset);
215 for (uu = 0; uu < MAX_KEY_TABLE; uu++)
216 MACvDisableKeyEntry(pDevice->PortOffset, uu);
218 return ret;
221 if (param->u.wpa_key.key && fcpfkernel) {
222 memcpy(&abyKey[0], param->u.wpa_key.key, param->u.wpa_key.key_len);
223 } else {
224 spin_unlock_irq(&pDevice->lock);
225 if (param->u.wpa_key.key &&
226 copy_from_user(&abyKey[0], param->u.wpa_key.key, param->u.wpa_key.key_len)) {
227 spin_lock_irq(&pDevice->lock);
228 return -EINVAL;
230 spin_lock_irq(&pDevice->lock);
233 dwKeyIndex = (unsigned long)(param->u.wpa_key.key_index);
235 if (param->u.wpa_key.alg_name == WPA_ALG_WEP) {
236 if (dwKeyIndex > 3) {
237 return -EINVAL;
238 } else {
239 if (param->u.wpa_key.set_tx) {
240 pDevice->byKeyIndex = (unsigned char)dwKeyIndex;
241 pDevice->bTransmitKey = true;
242 dwKeyIndex |= (1 << 31);
244 KeybSetDefaultKey(&(pDevice->sKey),
245 dwKeyIndex & ~(BIT30 | USE_KEYRSC),
246 param->u.wpa_key.key_len,
247 NULL,
248 abyKey,
249 KEY_CTL_WEP,
250 pDevice->PortOffset,
251 pDevice->byLocalID);
254 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
255 pDevice->bEncryptionEnable = true;
256 return ret;
259 if (param->u.wpa_key.seq && fcpfkernel) {
260 memcpy(&abySeq[0], param->u.wpa_key.seq, param->u.wpa_key.seq_len);
261 } else {
262 spin_unlock_irq(&pDevice->lock);
263 if (param->u.wpa_key.seq &&
264 copy_from_user(&abySeq[0], param->u.wpa_key.seq, param->u.wpa_key.seq_len)) {
265 spin_lock_irq(&pDevice->lock);
266 return -EINVAL;
268 spin_lock_irq(&pDevice->lock);
271 if (param->u.wpa_key.seq_len > 0) {
272 for (ii = 0; ii < param->u.wpa_key.seq_len; ii++) {
273 if (ii < 4)
274 LODWORD(KeyRSC) |= (abySeq[ii] << (ii * 8));
275 else
276 HIDWORD(KeyRSC) |= (abySeq[ii] << ((ii-4) * 8));
278 dwKeyIndex |= 1 << 29;
281 if (param->u.wpa_key.key_index >= MAX_GROUP_KEY) {
282 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "return dwKeyIndex > 3\n");
283 return -EINVAL;
286 if (param->u.wpa_key.alg_name == WPA_ALG_TKIP)
287 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
289 if (param->u.wpa_key.alg_name == WPA_ALG_CCMP)
290 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
292 if (param->u.wpa_key.set_tx)
293 dwKeyIndex |= (1 << 31);
295 if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled)
296 byKeyDecMode = KEY_CTL_CCMP;
297 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled)
298 byKeyDecMode = KEY_CTL_TKIP;
299 else
300 byKeyDecMode = KEY_CTL_WEP;
302 // Fix HCT test that set 256 bits KEY and Ndis802_11Encryption3Enabled
303 if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
304 if (param->u.wpa_key.key_len == MAX_KEY_LEN)
305 byKeyDecMode = KEY_CTL_TKIP;
306 else if (param->u.wpa_key.key_len == WLAN_WEP40_KEYLEN)
307 byKeyDecMode = KEY_CTL_WEP;
308 else if (param->u.wpa_key.key_len == WLAN_WEP104_KEYLEN)
309 byKeyDecMode = KEY_CTL_WEP;
310 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
311 if (param->u.wpa_key.key_len == WLAN_WEP40_KEYLEN)
312 byKeyDecMode = KEY_CTL_WEP;
313 else if (param->u.wpa_key.key_len == WLAN_WEP104_KEYLEN)
314 byKeyDecMode = KEY_CTL_WEP;
317 // Check TKIP key length
318 if ((byKeyDecMode == KEY_CTL_TKIP) &&
319 (param->u.wpa_key.key_len != MAX_KEY_LEN)) {
320 // TKIP Key must be 256 bits
321 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "return- TKIP Key must be 256 bits!\n");
322 return -EINVAL;
324 // Check AES key length
325 if ((byKeyDecMode == KEY_CTL_CCMP) &&
326 (param->u.wpa_key.key_len != AES_KEY_LEN)) {
327 // AES Key must be 128 bits
328 return -EINVAL;
331 // spin_lock_irq(&pDevice->lock);
332 if (is_broadcast_ether_addr(&param->addr[0]) || (param->addr == NULL)) {
333 // If is_broadcast_ether_addr, set the key as every key entry's group key.
334 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Groupe Key Assign.\n");
336 if (KeybSetAllGroupKey(&(pDevice->sKey),
337 dwKeyIndex,
338 param->u.wpa_key.key_len,
339 (PQWORD) &(KeyRSC),
340 (unsigned char *)abyKey,
341 byKeyDecMode,
342 pDevice->PortOffset,
343 pDevice->byLocalID) &&
344 KeybSetDefaultKey(&(pDevice->sKey),
345 dwKeyIndex,
346 param->u.wpa_key.key_len,
347 (PQWORD) &(KeyRSC),
348 (unsigned char *)abyKey,
349 byKeyDecMode,
350 pDevice->PortOffset,
351 pDevice->byLocalID)) {
352 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "GROUP Key Assign.\n");
354 } else {
355 return -EINVAL;
358 } else {
359 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pairwise Key Assign.\n");
360 // BSSID not 0xffffffffffff
361 // Pairwise Key can't be WEP
362 if (byKeyDecMode == KEY_CTL_WEP) {
363 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pairwise Key can't be WEP\n");
364 return -EINVAL;
367 dwKeyIndex |= (1 << 30); // set pairwise key
368 if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA)
369 return -EINVAL;
371 if (KeybSetKey(&(pDevice->sKey),
372 &param->addr[0],
373 dwKeyIndex,
374 param->u.wpa_key.key_len,
375 (PQWORD) &(KeyRSC),
376 (unsigned char *)abyKey,
377 byKeyDecMode,
378 pDevice->PortOffset,
379 pDevice->byLocalID)) {
380 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pairwise Key Set\n");
382 } else {
383 // Key Table Full
384 return -EINVAL;
386 } // BSSID not 0xffffffffffff
387 if ((ret == 0) && ((param->u.wpa_key.set_tx) != 0)) {
388 pDevice->byKeyIndex = (unsigned char)param->u.wpa_key.key_index;
389 pDevice->bTransmitKey = true;
391 pDevice->bEncryptionEnable = true;
393 return ret;
397 * Description:
398 * enable wpa auth & mode
400 * Parameters:
401 * In:
402 * pDevice -
403 * param -
404 * Out:
406 * Return Value:
410 static int wpa_set_wpa(PSDevice pDevice,
411 struct viawget_wpa_param *param)
413 PSMgmtObject pMgmt = pDevice->pMgmt;
415 pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
416 pMgmt->bShareKeyAlgorithm = false;
418 return 0;
422 * Description:
423 * set disassociate
425 * Parameters:
426 * In:
427 * pDevice -
428 * param -
429 * Out:
431 * Return Value:
435 static int wpa_set_disassociate(PSDevice pDevice,
436 struct viawget_wpa_param *param)
438 PSMgmtObject pMgmt = pDevice->pMgmt;
440 spin_lock_irq(&pDevice->lock);
441 if (pDevice->bLinkPass) {
442 if (!memcmp(param->addr, pMgmt->abyCurrBSSID, 6))
443 bScheduleCommand((void *)pDevice, WLAN_CMD_DISASSOCIATE, NULL);
445 spin_unlock_irq(&pDevice->lock);
447 return 0;
451 * Description:
452 * enable scan process
454 * Parameters:
455 * In:
456 * pDevice -
457 * param -
458 * Out:
460 * Return Value:
464 static int wpa_set_scan(PSDevice pDevice,
465 struct viawget_wpa_param *param)
467 spin_lock_irq(&pDevice->lock);
468 BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass);
469 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
470 spin_unlock_irq(&pDevice->lock);
472 return 0;
476 * Description:
477 * get bssid
479 * Parameters:
480 * In:
481 * pDevice -
482 * param -
483 * Out:
485 * Return Value:
489 static int wpa_get_bssid(PSDevice pDevice,
490 struct viawget_wpa_param *param)
492 PSMgmtObject pMgmt = pDevice->pMgmt;
494 memcpy(param->u.wpa_associate.bssid, pMgmt->abyCurrBSSID , 6);
496 return 0;
500 * Description:
501 * get bssid
503 * Parameters:
504 * In:
505 * pDevice -
506 * param -
507 * Out:
509 * Return Value:
513 static int wpa_get_ssid(PSDevice pDevice,
514 struct viawget_wpa_param *param)
516 PSMgmtObject pMgmt = pDevice->pMgmt;
517 PWLAN_IE_SSID pItemSSID;
519 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
521 memcpy(param->u.wpa_associate.ssid, pItemSSID->abySSID , pItemSSID->len);
522 param->u.wpa_associate.ssid_len = pItemSSID->len;
524 return 0;
528 * Description:
529 * get scan results
531 * Parameters:
532 * In:
533 * pDevice -
534 * param -
535 * Out:
537 * Return Value:
541 static int wpa_get_scan(PSDevice pDevice,
542 struct viawget_wpa_param *param)
544 struct viawget_scan_result *scan_buf;
545 PSMgmtObject pMgmt = pDevice->pMgmt;
546 PWLAN_IE_SSID pItemSSID;
547 PKnownBSS pBSS;
548 unsigned char *pBuf;
549 int ret = 0;
550 u16 count = 0;
551 u16 ii, jj;
552 #if 1
554 unsigned char *ptempBSS;
556 ptempBSS = kmalloc(sizeof(KnownBSS), GFP_ATOMIC);
558 if (ptempBSS == NULL) {
559 printk(KERN_ERR "bubble sort kmalloc memory fail@@@\n");
561 ret = -ENOMEM;
563 return ret;
567 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
568 for (jj = 0; jj < MAX_BSS_NUM - ii - 1; jj++) {
569 if ((pMgmt->sBSSList[jj].bActive != true) ||
571 ((pMgmt->sBSSList[jj].uRSSI > pMgmt->sBSSList[jj + 1].uRSSI) && (pMgmt->sBSSList[jj + 1].bActive != false))) {
572 memcpy(ptempBSS, &pMgmt->sBSSList[jj], sizeof(KnownBSS));
574 memcpy(&pMgmt->sBSSList[jj], &pMgmt->sBSSList[jj + 1], sizeof(KnownBSS));
576 memcpy(&pMgmt->sBSSList[jj + 1], ptempBSS, sizeof(KnownBSS));
584 kfree(ptempBSS);
585 #endif
587 //******mike:bubble sort by stronger RSSI*****//
589 count = 0;
590 pBSS = &(pMgmt->sBSSList[0]);
591 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
592 pBSS = &(pMgmt->sBSSList[ii]);
593 if (!pBSS->bActive)
594 continue;
595 count++;
598 pBuf = kcalloc(count, sizeof(struct viawget_scan_result), GFP_ATOMIC);
600 if (pBuf == NULL) {
601 ret = -ENOMEM;
602 return ret;
604 scan_buf = (struct viawget_scan_result *)pBuf;
605 pBSS = &(pMgmt->sBSSList[0]);
606 for (ii = 0, jj = 0; ii < MAX_BSS_NUM; ii++) {
607 pBSS = &(pMgmt->sBSSList[ii]);
608 if (pBSS->bActive) {
609 if (jj >= count)
610 break;
611 memcpy(scan_buf->bssid, pBSS->abyBSSID, WLAN_BSSID_LEN);
612 pItemSSID = (PWLAN_IE_SSID)pBSS->abySSID;
613 memcpy(scan_buf->ssid, pItemSSID->abySSID, pItemSSID->len);
614 scan_buf->ssid_len = pItemSSID->len;
615 scan_buf->freq = frequency_list[pBSS->uChannel-1];
616 scan_buf->caps = pBSS->wCapInfo;
618 if (pBSS->wWPALen != 0) {
619 scan_buf->wpa_ie_len = pBSS->wWPALen;
620 memcpy(scan_buf->wpa_ie, pBSS->byWPAIE, pBSS->wWPALen);
622 if (pBSS->wRSNLen != 0) {
623 scan_buf->rsn_ie_len = pBSS->wRSNLen;
624 memcpy(scan_buf->rsn_ie, pBSS->byRSNIE, pBSS->wRSNLen);
626 scan_buf = (struct viawget_scan_result *)((unsigned char *)scan_buf + sizeof(struct viawget_scan_result));
627 jj++;
631 if (jj < count)
632 count = jj;
634 if (copy_to_user(param->u.scan_results.buf, pBuf, sizeof(struct viawget_scan_result) * count))
635 ret = -EFAULT;
637 param->u.scan_results.scan_count = count;
638 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " param->u.scan_results.scan_count = %d\n", count);
640 kfree(pBuf);
641 return ret;
645 * Description:
646 * set associate with AP
648 * Parameters:
649 * In:
650 * pDevice -
651 * param -
652 * Out:
654 * Return Value:
658 static int wpa_set_associate(PSDevice pDevice,
659 struct viawget_wpa_param *param)
661 PSMgmtObject pMgmt = pDevice->pMgmt;
662 PWLAN_IE_SSID pItemSSID;
663 unsigned char abyNullAddr[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
664 unsigned char abyWPAIE[64];
665 bool bWepEnabled = false;
667 // set key type & algorithm
668 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pairwise_suite = %d\n", param->u.wpa_associate.pairwise_suite);
669 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "group_suite = %d\n", param->u.wpa_associate.group_suite);
670 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "key_mgmt_suite = %d\n", param->u.wpa_associate.key_mgmt_suite);
671 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "auth_alg = %d\n", param->u.wpa_associate.auth_alg);
672 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "mode = %d\n", param->u.wpa_associate.mode);
673 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wpa_ie_len = %d\n", param->u.wpa_associate.wpa_ie_len);
675 if (param->u.wpa_associate.wpa_ie_len) {
676 if (!param->u.wpa_associate.wpa_ie)
677 return -EINVAL;
678 if (param->u.wpa_associate.wpa_ie_len > sizeof(abyWPAIE))
679 return -EINVAL;
680 if (copy_from_user(&abyWPAIE[0], param->u.wpa_associate.wpa_ie, param->u.wpa_associate.wpa_ie_len))
681 return -EFAULT;
684 if (param->u.wpa_associate.mode == 1)
685 pMgmt->eConfigMode = WMAC_CONFIG_IBSS_STA;
686 else
687 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
688 // set ssid
689 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
690 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
691 pItemSSID->byElementID = WLAN_EID_SSID;
692 pItemSSID->len = param->u.wpa_associate.ssid_len;
693 memcpy(pItemSSID->abySSID, param->u.wpa_associate.ssid, pItemSSID->len);
694 // set bssid
695 if (memcmp(param->u.wpa_associate.bssid, &abyNullAddr[0], 6) != 0)
696 memcpy(pMgmt->abyDesireBSSID, param->u.wpa_associate.bssid, 6);
697 else
698 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, pItemSSID->abySSID);
700 if (param->u.wpa_associate.wpa_ie_len == 0) {
701 if (param->u.wpa_associate.auth_alg & AUTH_ALG_SHARED_KEY)
702 pMgmt->eAuthenMode = WMAC_AUTH_SHAREKEY;
703 else
704 pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
705 } else if (abyWPAIE[0] == RSN_INFO_ELEM) {
706 if (param->u.wpa_associate.key_mgmt_suite == KEY_MGMT_PSK)
707 pMgmt->eAuthenMode = WMAC_AUTH_WPA2PSK;
708 else
709 pMgmt->eAuthenMode = WMAC_AUTH_WPA2;
710 } else {
711 if (param->u.wpa_associate.key_mgmt_suite == KEY_MGMT_WPA_NONE)
712 pMgmt->eAuthenMode = WMAC_AUTH_WPANONE;
713 else if (param->u.wpa_associate.key_mgmt_suite == KEY_MGMT_PSK)
714 pMgmt->eAuthenMode = WMAC_AUTH_WPAPSK;
715 else
716 pMgmt->eAuthenMode = WMAC_AUTH_WPA;
719 switch (param->u.wpa_associate.pairwise_suite) {
720 case CIPHER_CCMP:
721 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
722 break;
723 case CIPHER_TKIP:
724 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
725 break;
726 case CIPHER_WEP40:
727 case CIPHER_WEP104:
728 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
729 bWepEnabled = true;
730 break;
731 case CIPHER_NONE:
732 if (param->u.wpa_associate.group_suite == CIPHER_CCMP)
733 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
734 else
735 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
736 break;
737 default:
738 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
741 //DavidWang add for WPA_supplicant support open/share mode
743 if (pMgmt->eAuthenMode == WMAC_AUTH_SHAREKEY) {
744 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
745 pMgmt->bShareKeyAlgorithm = true;
746 } else if (pMgmt->eAuthenMode == WMAC_AUTH_OPEN) {
747 if (!bWepEnabled) pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
748 else pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
750 //mike save old encryption status
751 pDevice->eOldEncryptionStatus = pDevice->eEncryptionStatus;
753 if (pDevice->eEncryptionStatus != Ndis802_11EncryptionDisabled)
754 pDevice->bEncryptionEnable = true;
755 else
756 pDevice->bEncryptionEnable = false;
757 if (!((pMgmt->eAuthenMode == WMAC_AUTH_SHAREKEY) ||
758 ((pMgmt->eAuthenMode == WMAC_AUTH_OPEN) && bWepEnabled))) //DavidWang //20080717-06,<Modify> by chester//Not to initial WEP
759 KeyvInitTable(&pDevice->sKey, pDevice->PortOffset);
760 spin_lock_irq(&pDevice->lock);
761 pDevice->bLinkPass = false;
762 memset(pMgmt->abyCurrBSSID, 0, 6);
763 pMgmt->eCurrState = WMAC_STATE_IDLE;
764 netif_stop_queue(pDevice->dev);
765 //20080701-02,<Add> by Mike Liu
766 /*******search if ap_scan=2 ,which is associating request in hidden ssid mode ****/
768 PKnownBSS pCurr = NULL;
769 pCurr = BSSpSearchBSSList(pDevice,
770 pMgmt->abyDesireBSSID,
771 pMgmt->abyDesireSSID,
772 pMgmt->eConfigPHYMode
775 if (pCurr == NULL) {
776 printk("wpa_set_associate---->hidden mode site survey before associate.......\n");
777 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
780 /****************************************************************/
781 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
782 spin_unlock_irq(&pDevice->lock);
784 return 0;
788 * Description:
789 * wpa_ioctl main function supported for wpa supplicant
791 * Parameters:
792 * In:
793 * pDevice -
794 * iw_point -
795 * Out:
797 * Return Value:
801 int wpa_ioctl(PSDevice pDevice, struct iw_point *p)
803 struct viawget_wpa_param *param;
804 int ret = 0;
805 int wpa_ioctl = 0;
807 if (p->length < sizeof(struct viawget_wpa_param) ||
808 p->length > VIAWGET_WPA_MAX_BUF_SIZE || !p->pointer)
809 return -EINVAL;
811 param = kmalloc((int)p->length, GFP_KERNEL);
812 if (param == NULL)
813 return -ENOMEM;
815 if (copy_from_user(param, p->pointer, p->length)) {
816 ret = -EFAULT;
817 goto out;
820 switch (param->cmd) {
821 case VIAWGET_SET_WPA:
822 ret = wpa_set_wpa(pDevice, param);
823 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_WPA\n");
824 break;
826 case VIAWGET_SET_KEY:
827 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_KEY\n");
828 spin_lock_irq(&pDevice->lock);
829 ret = wpa_set_keys(pDevice, param, false);
830 spin_unlock_irq(&pDevice->lock);
831 break;
833 case VIAWGET_SET_SCAN:
834 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_SCAN\n");
835 ret = wpa_set_scan(pDevice, param);
836 break;
838 case VIAWGET_GET_SCAN:
839 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_GET_SCAN\n");
840 ret = wpa_get_scan(pDevice, param);
841 wpa_ioctl = 1;
842 break;
844 case VIAWGET_GET_SSID:
845 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_GET_SSID\n");
846 ret = wpa_get_ssid(pDevice, param);
847 wpa_ioctl = 1;
848 break;
850 case VIAWGET_GET_BSSID:
851 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_GET_BSSID\n");
852 ret = wpa_get_bssid(pDevice, param);
853 wpa_ioctl = 1;
854 break;
856 case VIAWGET_SET_ASSOCIATE:
857 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_ASSOCIATE\n");
858 ret = wpa_set_associate(pDevice, param);
859 break;
861 case VIAWGET_SET_DISASSOCIATE:
862 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_DISASSOCIATE\n");
863 ret = wpa_set_disassociate(pDevice, param);
864 break;
866 case VIAWGET_SET_DROP_UNENCRYPT:
867 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_DROP_UNENCRYPT\n");
868 break;
870 case VIAWGET_SET_DEAUTHENTICATE:
871 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_DEAUTHENTICATE\n");
872 break;
874 default:
875 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wpa_ioctl: unknown cmd=%d\n",
876 param->cmd);
877 ret = -EOPNOTSUPP;
878 goto out;
881 if ((ret == 0) && wpa_ioctl) {
882 if (copy_to_user(p->pointer, param, p->length)) {
883 ret = -EFAULT;
884 goto out;
888 out:
889 kfree(param);
891 return ret;