Merge branch 'topic/omap3isp' of git://git.kernel.org/pub/scm/linux/kernel/git/mcheha...
[deliverable/linux.git] / drivers / staging / vt6655 / wpactl.c
1 /*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
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.
9 *
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.
14 *
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.
18 *
19 *
20 * File: wpactl.c
21 *
22 * Purpose: handle wpa supplicant ioctl input/out functions
23 *
24 * Author: Lyndon Chen
25 *
26 * Date: Oct. 20, 2003
27 *
28 * Functions:
29 *
30 * Revision History:
31 *
32 */
33
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"
42
43 /*--------------------- Static Definitions -------------------------*/
44
45 #define VIAWGET_WPA_MAX_BUF_SIZE 1024
46
47 static const int frequency_list[] = {
48 2412, 2417, 2422, 2427, 2432, 2437, 2442,
49 2447, 2452, 2457, 2462, 2467, 2472, 2484
50 };
51 /*--------------------- Static Classes ----------------------------*/
52
53 /*--------------------- Static Variables --------------------------*/
54 static int msglevel = MSG_LEVEL_INFO;
55
56 /*--------------------- Static Functions --------------------------*/
57
58 /*--------------------- Export Variables --------------------------*/
59 static void wpadev_setup(struct net_device *dev)
60 {
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;
66
67 memset(dev->broadcast, 0xFF, ETH_ALEN);
68
69 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
70 }
71
72 /*
73 * Description:
74 * register netdev for wpa supplicant daemon
75 *
76 * Parameters:
77 * In:
78 * pDevice -
79 * enable -
80 * Out:
81 *
82 * Return Value:
83 *
84 */
85
86 static int wpa_init_wpadev(PSDevice pDevice)
87 {
88 PSDevice wpadev_priv;
89 struct net_device *dev = pDevice->dev;
90 int ret = 0;
91
92 pDevice->wpadev = alloc_netdev(sizeof(PSDevice), "vntwpa", wpadev_setup);
93 if (pDevice->wpadev == NULL)
94 return -ENOMEM;
95
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;
109 }
110
111 if (pDevice->skb == NULL) {
112 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
113 if (pDevice->skb == NULL)
114 return -ENOMEM;
115 }
116
117 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Registered netdev %s for WPA management\n",
118 dev->name, pDevice->wpadev->name);
119
120 return 0;
121 }
122
123 /*
124 * Description:
125 * unregister net_device (wpadev)
126 *
127 * Parameters:
128 * In:
129 * pDevice -
130 * Out:
131 *
132 * Return Value:
133 *
134 */
135
136 static int wpa_release_wpadev(PSDevice pDevice)
137 {
138 if (pDevice->skb) {
139 dev_kfree_skb(pDevice->skb);
140 pDevice->skb = NULL;
141 }
142
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;
149 }
150
151 return 0;
152 }
153
154 /*
155 * Description:
156 * Set enable/disable dev for wpa supplicant daemon
157 *
158 * Parameters:
159 * In:
160 * pDevice -
161 * val -
162 * Out:
163 *
164 * Return Value:
165 *
166 */
167
168 int wpa_set_wpadev(PSDevice pDevice, int val)
169 {
170 if (val)
171 return wpa_init_wpadev(pDevice);
172 else
173 return wpa_release_wpadev(pDevice);
174 }
175
176 /*
177 * Description:
178 * Set WPA algorithm & keys
179 *
180 * Parameters:
181 * In:
182 * pDevice -
183 * param -
184 * Out:
185 *
186 * Return Value:
187 *
188 */
189
190 int wpa_set_keys(PSDevice pDevice, void *ctx,
191 bool fcpfkernel) __must_hold(&pDevice->lock)
192 {
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;
202
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;
207
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);
217
218 return ret;
219 }
220
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;
229 }
230 spin_lock_irq(&pDevice->lock);
231 }
232
233 dwKeyIndex = (unsigned long)(param->u.wpa_key.key_index);
234
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);
243 }
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);
252
253 }
254 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
255 pDevice->bEncryptionEnable = true;
256 return ret;
257 }
258
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;
267 }
268 spin_lock_irq(&pDevice->lock);
269 }
270
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));
277 }
278 dwKeyIndex |= 1 << 29;
279 }
280
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;
284 }
285
286 if (param->u.wpa_key.alg_name == WPA_ALG_TKIP)
287 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
288
289 if (param->u.wpa_key.alg_name == WPA_ALG_CCMP)
290 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
291
292 if (param->u.wpa_key.set_tx)
293 dwKeyIndex |= (1 << 31);
294
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;
301
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;
315 }
316
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;
323 }
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;
329 }
330
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");
335
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");
353
354 } else {
355 return -EINVAL;
356 }
357
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;
365 }
366
367 dwKeyIndex |= (1 << 30); // set pairwise key
368 if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA)
369 return -EINVAL;
370
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");
381
382 } else {
383 // Key Table Full
384 return -EINVAL;
385 }
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;
390 }
391 pDevice->bEncryptionEnable = true;
392
393 return ret;
394 }
395
396 /*
397 * Description:
398 * enable wpa auth & mode
399 *
400 * Parameters:
401 * In:
402 * pDevice -
403 * param -
404 * Out:
405 *
406 * Return Value:
407 *
408 */
409
410 static int wpa_set_wpa(PSDevice pDevice,
411 struct viawget_wpa_param *param)
412 {
413 PSMgmtObject pMgmt = pDevice->pMgmt;
414
415 pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
416 pMgmt->bShareKeyAlgorithm = false;
417
418 return 0;
419 }
420
421 /*
422 * Description:
423 * set disassociate
424 *
425 * Parameters:
426 * In:
427 * pDevice -
428 * param -
429 * Out:
430 *
431 * Return Value:
432 *
433 */
434
435 static int wpa_set_disassociate(PSDevice pDevice,
436 struct viawget_wpa_param *param)
437 {
438 PSMgmtObject pMgmt = pDevice->pMgmt;
439
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);
444 }
445 spin_unlock_irq(&pDevice->lock);
446
447 return 0;
448 }
449
450 /*
451 * Description:
452 * enable scan process
453 *
454 * Parameters:
455 * In:
456 * pDevice -
457 * param -
458 * Out:
459 *
460 * Return Value:
461 *
462 */
463
464 static int wpa_set_scan(PSDevice pDevice,
465 struct viawget_wpa_param *param)
466 {
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);
471
472 return 0;
473 }
474
475 /*
476 * Description:
477 * get bssid
478 *
479 * Parameters:
480 * In:
481 * pDevice -
482 * param -
483 * Out:
484 *
485 * Return Value:
486 *
487 */
488
489 static int wpa_get_bssid(PSDevice pDevice,
490 struct viawget_wpa_param *param)
491 {
492 PSMgmtObject pMgmt = pDevice->pMgmt;
493
494 memcpy(param->u.wpa_associate.bssid, pMgmt->abyCurrBSSID , 6);
495
496 return 0;
497 }
498
499 /*
500 * Description:
501 * get bssid
502 *
503 * Parameters:
504 * In:
505 * pDevice -
506 * param -
507 * Out:
508 *
509 * Return Value:
510 *
511 */
512
513 static int wpa_get_ssid(PSDevice pDevice,
514 struct viawget_wpa_param *param)
515 {
516 PSMgmtObject pMgmt = pDevice->pMgmt;
517 PWLAN_IE_SSID pItemSSID;
518
519 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
520
521 memcpy(param->u.wpa_associate.ssid, pItemSSID->abySSID , pItemSSID->len);
522 param->u.wpa_associate.ssid_len = pItemSSID->len;
523
524 return 0;
525 }
526
527 /*
528 * Description:
529 * get scan results
530 *
531 * Parameters:
532 * In:
533 * pDevice -
534 * param -
535 * Out:
536 *
537 * Return Value:
538 *
539 */
540
541 static int wpa_get_scan(PSDevice pDevice,
542 struct viawget_wpa_param *param)
543 {
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
553
554 unsigned char *ptempBSS;
555
556 ptempBSS = kmalloc(sizeof(KnownBSS), GFP_ATOMIC);
557
558 if (ptempBSS == NULL) {
559 printk(KERN_ERR "bubble sort kmalloc memory fail@@@\n");
560
561 ret = -ENOMEM;
562
563 return ret;
564
565 }
566
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) ||
570
571 ((pMgmt->sBSSList[jj].uRSSI > pMgmt->sBSSList[jj + 1].uRSSI) && (pMgmt->sBSSList[jj + 1].bActive != false))) {
572 memcpy(ptempBSS, &pMgmt->sBSSList[jj], sizeof(KnownBSS));
573
574 memcpy(&pMgmt->sBSSList[jj], &pMgmt->sBSSList[jj + 1], sizeof(KnownBSS));
575
576 memcpy(&pMgmt->sBSSList[jj + 1], ptempBSS, sizeof(KnownBSS));
577
578 }
579
580 }
581
582 }
583
584 kfree(ptempBSS);
585 #endif
586
587 //******mike:bubble sort by stronger RSSI*****//
588
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++;
596 }
597
598 pBuf = kcalloc(count, sizeof(struct viawget_scan_result), GFP_ATOMIC);
599
600 if (pBuf == NULL) {
601 ret = -ENOMEM;
602 return ret;
603 }
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;
617
618 if (pBSS->wWPALen != 0) {
619 scan_buf->wpa_ie_len = pBSS->wWPALen;
620 memcpy(scan_buf->wpa_ie, pBSS->byWPAIE, pBSS->wWPALen);
621 }
622 if (pBSS->wRSNLen != 0) {
623 scan_buf->rsn_ie_len = pBSS->wRSNLen;
624 memcpy(scan_buf->rsn_ie, pBSS->byRSNIE, pBSS->wRSNLen);
625 }
626 scan_buf = (struct viawget_scan_result *)((unsigned char *)scan_buf + sizeof(struct viawget_scan_result));
627 jj++;
628 }
629 }
630
631 if (jj < count)
632 count = jj;
633
634 if (copy_to_user(param->u.scan_results.buf, pBuf, sizeof(struct viawget_scan_result) * count))
635 ret = -EFAULT;
636
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);
639
640 kfree(pBuf);
641 return ret;
642 }
643
644 /*
645 * Description:
646 * set associate with AP
647 *
648 * Parameters:
649 * In:
650 * pDevice -
651 * param -
652 * Out:
653 *
654 * Return Value:
655 *
656 */
657
658 static int wpa_set_associate(PSDevice pDevice,
659 struct viawget_wpa_param *param)
660 {
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;
666
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);
674
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;
682 }
683
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);
699
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;
717 }
718
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;
739 }
740
741 //DavidWang add for WPA_supplicant support open/share mode
742
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;
749 }
750 //mike save old encryption status
751 pDevice->eOldEncryptionStatus = pDevice->eEncryptionStatus;
752
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 ****/
767 {
768 PKnownBSS pCurr = NULL;
769 pCurr = BSSpSearchBSSList(pDevice,
770 pMgmt->abyDesireBSSID,
771 pMgmt->abyDesireSSID,
772 pMgmt->eConfigPHYMode
773 );
774
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);
778 }
779 }
780 /****************************************************************/
781 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
782 spin_unlock_irq(&pDevice->lock);
783
784 return 0;
785 }
786
787 /*
788 * Description:
789 * wpa_ioctl main function supported for wpa supplicant
790 *
791 * Parameters:
792 * In:
793 * pDevice -
794 * iw_point -
795 * Out:
796 *
797 * Return Value:
798 *
799 */
800
801 int wpa_ioctl(PSDevice pDevice, struct iw_point *p)
802 {
803 struct viawget_wpa_param *param;
804 int ret = 0;
805 int wpa_ioctl = 0;
806
807 if (p->length < sizeof(struct viawget_wpa_param) ||
808 p->length > VIAWGET_WPA_MAX_BUF_SIZE || !p->pointer)
809 return -EINVAL;
810
811 param = kmalloc((int)p->length, GFP_KERNEL);
812 if (param == NULL)
813 return -ENOMEM;
814
815 if (copy_from_user(param, p->pointer, p->length)) {
816 ret = -EFAULT;
817 goto out;
818 }
819
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;
825
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;
832
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;
837
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;
843
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;
849
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;
855
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;
860
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;
865
866 case VIAWGET_SET_DROP_UNENCRYPT:
867 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_DROP_UNENCRYPT\n");
868 break;
869
870 case VIAWGET_SET_DEAUTHENTICATE:
871 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_DEAUTHENTICATE\n");
872 break;
873
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;
879 }
880
881 if ((ret == 0) && wpa_ioctl) {
882 if (copy_to_user(p->pointer, param, p->length)) {
883 ret = -EFAULT;
884 goto out;
885 }
886 }
887
888 out:
889 kfree(param);
890
891 return ret;
892 }
This page took 0.049644 seconds and 6 git commands to generate.