Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound-2.6
[linux-2.6-block.git] / drivers / staging / vt6656 / hostap.c
CommitLineData
92b96797
FB
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 * File: hostap.c
20 *
21 * Purpose: handle hostap deamon ioctl input/out functions
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: Oct. 20, 2003
26 *
27 * Functions:
28 *
29 * Revision History:
30 *
31 */
32
92b96797 33#include "hostap.h"
92b96797 34#include "iocmd.h"
92b96797 35#include "mac.h"
92b96797 36#include "card.h"
92b96797 37#include "baseband.h"
92b96797 38#include "wpactl.h"
92b96797 39#include "key.h"
92b96797 40#include "datarate.h"
92b96797
FB
41
42#define VIAWGET_HOSTAPD_MAX_BUF_SIZE 1024
43#define HOSTAP_CRYPT_FLAG_SET_TX_KEY BIT0
44#define HOSTAP_CRYPT_FLAG_PERMANENT BIT1
45#define HOSTAP_CRYPT_ERR_UNKNOWN_ALG 2
46#define HOSTAP_CRYPT_ERR_UNKNOWN_ADDR 3
47#define HOSTAP_CRYPT_ERR_CRYPT_INIT_FAILED 4
48#define HOSTAP_CRYPT_ERR_KEY_SET_FAILED 5
49#define HOSTAP_CRYPT_ERR_TX_KEY_SET_FAILED 6
50#define HOSTAP_CRYPT_ERR_CARD_CONF_FAILED 7
51
52
53/*--------------------- Static Definitions -------------------------*/
54
55/*--------------------- Static Classes ----------------------------*/
56
57/*--------------------- Static Variables --------------------------*/
58//static int msglevel =MSG_LEVEL_DEBUG;
59static int msglevel =MSG_LEVEL_INFO;
60
61/*--------------------- Static Functions --------------------------*/
62
63
64
65
66/*--------------------- Export Variables --------------------------*/
67
68
69/*
70 * Description:
71 * register net_device (AP) for hostap deamon
72 *
73 * Parameters:
74 * In:
75 * pDevice -
76 * rtnl_locked -
77 * Out:
78 *
79 * Return Value:
80 *
81 */
82
83static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
84{
1e28efa3 85 PSDevice apdev_priv;
92b96797
FB
86 struct net_device *dev = pDevice->dev;
87 int ret;
d899d403
JL
88 const struct net_device_ops apdev_netdev_ops = {
89 .ndo_start_xmit = pDevice->tx_80211,
90 };
92b96797
FB
91
92 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
93
94 pDevice->apdev = (struct net_device *)kmalloc(sizeof(struct net_device), GFP_KERNEL);
77f58b13 95 if (pDevice->apdev == NULL)
92b96797
FB
96 return -ENOMEM;
97 memset(pDevice->apdev, 0, sizeof(struct net_device));
98
1e28efa3
FB
99 apdev_priv = netdev_priv(pDevice->apdev);
100 *apdev_priv = *pDevice;
92b96797 101 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
dd8db704 102
dd8db704
FB
103 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
104
92b96797
FB
105 pDevice->apdev->type = ARPHRD_IEEE80211;
106
107 pDevice->apdev->base_addr = dev->base_addr;
108 pDevice->apdev->irq = dev->irq;
109 pDevice->apdev->mem_start = dev->mem_start;
110 pDevice->apdev->mem_end = dev->mem_end;
111 sprintf(pDevice->apdev->name, "%sap", dev->name);
112 if (rtnl_locked)
113 ret = register_netdevice(pDevice->apdev);
114 else
115 ret = register_netdev(pDevice->apdev);
116 if (ret) {
117 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: register_netdevice(AP) failed!\n",
118 dev->name);
119 return -1;
120 }
121
122 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Registered netdevice %s for AP management\n",
123 dev->name, pDevice->apdev->name);
124
125 KeyvInitTable(pDevice,&pDevice->sKey);
126
127 return 0;
128}
129
130/*
131 * Description:
132 * unregister net_device(AP)
133 *
134 * Parameters:
135 * In:
136 * pDevice -
137 * rtnl_locked -
138 * Out:
139 *
140 * Return Value:
141 *
142 */
143
144static int hostap_disable_hostapd(PSDevice pDevice, int rtnl_locked)
145{
146
147 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: disabling hostapd mode\n", pDevice->dev->name);
148
149 if (pDevice->apdev && pDevice->apdev->name && pDevice->apdev->name[0]) {
150 if (rtnl_locked)
151 unregister_netdevice(pDevice->apdev);
152 else
153 unregister_netdev(pDevice->apdev);
154 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Netdevice %s unregistered\n",
155 pDevice->dev->name, pDevice->apdev->name);
156 }
157 kfree(pDevice->apdev);
158 pDevice->apdev = NULL;
159 pDevice->bEnable8021x = FALSE;
160 pDevice->bEnableHostWEP = FALSE;
161 pDevice->bEncryptionEnable = FALSE;
162
163 return 0;
164}
165
166
167/*
168 * Description:
169 * Set enable/disable hostapd mode
170 *
171 * Parameters:
172 * In:
173 * pDevice -
174 * rtnl_locked -
175 * Out:
176 *
177 * Return Value:
178 *
179 */
180
181int hostap_set_hostapd(PSDevice pDevice, int val, int rtnl_locked)
182{
183 if (val < 0 || val > 1)
184 return -EINVAL;
185
186 if (pDevice->bEnableHostapd == val)
187 return 0;
188
189 pDevice->bEnableHostapd = val;
190
191 if (val)
192 return hostap_enable_hostapd(pDevice, rtnl_locked);
193 else
194 return hostap_disable_hostapd(pDevice, rtnl_locked);
195}
196
197
198/*
199 * Description:
200 * remove station function supported for hostap deamon
201 *
202 * Parameters:
203 * In:
204 * pDevice -
205 * param -
206 * Out:
207 *
208 * Return Value:
209 *
210 */
211static int hostap_remove_sta(PSDevice pDevice,
212 struct viawget_hostapd_param *param)
213{
214 UINT uNodeIndex;
215
216
217 if (BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &uNodeIndex)) {
218 BSSvRemoveOneNode(pDevice, uNodeIndex);
219 }
220 else {
221 return -ENOENT;
222 }
223 return 0;
224}
225
226/*
227 * Description:
228 * add a station from hostap deamon
229 *
230 * Parameters:
231 * In:
232 * pDevice -
233 * param -
234 * Out:
235 *
236 * Return Value:
237 *
238 */
239static int hostap_add_sta(PSDevice pDevice,
240 struct viawget_hostapd_param *param)
241{
242 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
243 UINT uNodeIndex;
244
245
246 if (!BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &uNodeIndex)) {
247 BSSvCreateOneNode((PSDevice)pDevice, &uNodeIndex);
248 }
249 memcpy(pMgmt->sNodeDBTable[uNodeIndex].abyMACAddr, param->sta_addr, WLAN_ADDR_LEN);
250 pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_ASSOC;
251 pMgmt->sNodeDBTable[uNodeIndex].wCapInfo = param->u.add_sta.capability;
252// TODO listenInterval
253// pMgmt->sNodeDBTable[uNodeIndex].wListenInterval = 1;
254 pMgmt->sNodeDBTable[uNodeIndex].bPSEnable = FALSE;
255 pMgmt->sNodeDBTable[uNodeIndex].bySuppRate = param->u.add_sta.tx_supp_rates;
256
257 // set max tx rate
258 pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate =
259 pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate;
260 // set max basic rate
261 pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate = RATE_2M;
262 // Todo: check sta preamble, if ap can't support, set status code
263 pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble =
264 WLAN_GET_CAP_INFO_SHORTPREAMBLE(pMgmt->sNodeDBTable[uNodeIndex].wCapInfo);
265
266 pMgmt->sNodeDBTable[uNodeIndex].wAID = (WORD)param->u.add_sta.aid;
267
268 pMgmt->sNodeDBTable[uNodeIndex].ulLastRxJiffer = jiffies;
269
270 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Add STA AID= %d \n", pMgmt->sNodeDBTable[uNodeIndex].wAID);
271 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "MAC=%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X \n",
272 param->sta_addr[0],
273 param->sta_addr[1],
274 param->sta_addr[2],
275 param->sta_addr[3],
276 param->sta_addr[4],
277 param->sta_addr[5]
278 ) ;
279 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Max Support rate = %d \n",
280 pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate);
281
282 return 0;
283}
284
285/*
286 * Description:
287 * get station info
288 *
289 * Parameters:
290 * In:
291 * pDevice -
292 * param -
293 * Out:
294 *
295 * Return Value:
296 *
297 */
298
299static int hostap_get_info_sta(PSDevice pDevice,
300 struct viawget_hostapd_param *param)
301{
302 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
303 UINT uNodeIndex;
304
305 if (BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &uNodeIndex)) {
306 param->u.get_info_sta.inactive_sec =
307 (jiffies - pMgmt->sNodeDBTable[uNodeIndex].ulLastRxJiffer) / HZ;
308
309 //param->u.get_info_sta.txexc = pMgmt->sNodeDBTable[uNodeIndex].uTxAttempts;
310 }
311 else {
312 return -ENOENT;
313 }
314
315 return 0;
316}
317
318/*
319 * Description:
320 * reset txexec
321 *
322 * Parameters:
323 * In:
324 * pDevice -
325 * param -
326 * Out:
327 * TURE, FALSE
328 *
329 * Return Value:
330 *
331 */
332/*
333static int hostap_reset_txexc_sta(PSDevice pDevice,
334 struct viawget_hostapd_param *param)
335{
336 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
337 UINT uNodeIndex;
338
339 if (BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &uNodeIndex)) {
340 pMgmt->sNodeDBTable[uNodeIndex].uTxAttempts = 0;
341 }
342 else {
343 return -ENOENT;
344 }
345
346 return 0;
347}
348*/
349
350/*
351 * Description:
352 * set station flag
353 *
354 * Parameters:
355 * In:
356 * pDevice -
357 * param -
358 * Out:
359 *
360 * Return Value:
361 *
362 */
363static int hostap_set_flags_sta(PSDevice pDevice,
364 struct viawget_hostapd_param *param)
365{
366 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
367 UINT uNodeIndex;
368
369 if (BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &uNodeIndex)) {
370 pMgmt->sNodeDBTable[uNodeIndex].dwFlags |= param->u.set_flags_sta.flags_or;
371 pMgmt->sNodeDBTable[uNodeIndex].dwFlags &= param->u.set_flags_sta.flags_and;
372 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " dwFlags = %x \n",
373 (UINT)pMgmt->sNodeDBTable[uNodeIndex].dwFlags);
374 }
375 else {
376 return -ENOENT;
377 }
378
379 return 0;
380}
381
382
383
384/*
385 * Description:
386 * set generic element (wpa ie)
387 *
388 * Parameters:
389 * In:
390 * pDevice -
391 * param -
392 * Out:
393 *
394 * Return Value:
395 *
396 */
397static int hostap_set_generic_element(PSDevice pDevice,
398 struct viawget_hostapd_param *param)
399{
400 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
401
402
403
404 memcpy( pMgmt->abyWPAIE,
405 param->u.generic_elem.data,
406 param->u.generic_elem.len
407 );
408
409 pMgmt->wWPAIELen = param->u.generic_elem.len;
410
411 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pMgmt->wWPAIELen = %d\n", pMgmt->wWPAIELen);
412
413 // disable wpa
414 if (pMgmt->wWPAIELen == 0) {
415 pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
416 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " No WPAIE, Disable WPA \n");
417 } else {
418 // enable wpa
419 if ((pMgmt->abyWPAIE[0] == WLAN_EID_RSN_WPA) ||
420 (pMgmt->abyWPAIE[0] == WLAN_EID_RSN)) {
421 pMgmt->eAuthenMode = WMAC_AUTH_WPANONE;
422 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set WPAIE enable WPA\n");
423 } else
424 return -EINVAL;
425 }
426
427 return 0;
428}
429
430/*
431 * Description:
432 * flush station nodes table.
433 *
434 * Parameters:
435 * In:
436 * pDevice -
437 * Out:
438 *
439 * Return Value:
440 *
441 */
442
443static void hostap_flush_sta(PSDevice pDevice)
444{
445 // reserved node index =0 for multicast node.
446 BSSvClearNodeDBTable(pDevice, 1);
447 pDevice->uAssocCount = 0;
448
449 return;
450}
451
452/*
453 * Description:
454 * set each stations encryption key
455 *
456 * Parameters:
457 * In:
458 * pDevice -
459 * param -
460 * Out:
461 *
462 * Return Value:
463 *
464 */
465static int hostap_set_encryption(PSDevice pDevice,
466 struct viawget_hostapd_param *param,
467 int param_len)
468{
469 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
470 DWORD dwKeyIndex = 0;
471 BYTE abyKey[MAX_KEY_LEN];
472 BYTE abySeq[MAX_KEY_LEN];
473 NDIS_802_11_KEY_RSC KeyRSC;
474 BYTE byKeyDecMode = KEY_CTL_WEP;
475 int ret = 0;
476 int iNodeIndex = -1;
477 int ii;
478 BOOL bKeyTableFull = FALSE;
479 WORD wKeyCtl = 0;
480
481
482 param->u.crypt.err = 0;
483/*
484 if (param_len !=
485 (int) ((char *) param->u.crypt.key - (char *) param) +
486 param->u.crypt.key_len)
487 return -EINVAL;
488*/
489
490 if (param->u.crypt.alg > WPA_ALG_CCMP)
491 return -EINVAL;
492
493
494 if ((param->u.crypt.idx > 3) || (param->u.crypt.key_len > MAX_KEY_LEN)) {
495 param->u.crypt.err = HOSTAP_CRYPT_ERR_KEY_SET_FAILED;
496 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " HOSTAP_CRYPT_ERR_KEY_SET_FAILED\n");
497 return -EINVAL;
498 }
499
500 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
501 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
502 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
503 if (param->u.crypt.idx >= MAX_GROUP_KEY)
504 return -EINVAL;
505 iNodeIndex = 0;
506
507 } else {
508 if (BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &iNodeIndex) == FALSE) {
509 param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
510 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " HOSTAP_CRYPT_ERR_UNKNOWN_ADDR\n");
511 return -EINVAL;
512 }
513 }
514 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " hostap_set_encryption: sta_index %d \n", iNodeIndex);
515 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " hostap_set_encryption: alg %d \n", param->u.crypt.alg);
516
517 if (param->u.crypt.alg == WPA_ALG_NONE) {
518
519 if (pMgmt->sNodeDBTable[iNodeIndex].bOnFly == TRUE) {
520 if (KeybRemoveKey( pDevice,
521 &(pDevice->sKey),
522 param->sta_addr,
523 pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex
524 ) == FALSE) {
525 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "KeybRemoveKey fail \n");
526 }
527 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = FALSE;
528 }
529 pMgmt->sNodeDBTable[iNodeIndex].byKeyIndex = 0;
530 pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex = 0;
531 pMgmt->sNodeDBTable[iNodeIndex].uWepKeyLength = 0;
532 pMgmt->sNodeDBTable[iNodeIndex].KeyRSC = 0;
533 pMgmt->sNodeDBTable[iNodeIndex].dwTSC47_16 = 0;
534 pMgmt->sNodeDBTable[iNodeIndex].wTSC15_0 = 0;
535 pMgmt->sNodeDBTable[iNodeIndex].byCipherSuite = 0;
536 memset(&pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[0],
537 0,
538 MAX_KEY_LEN
539 );
540
541 return ret;
542 }
543
544 memcpy(abyKey, param->u.crypt.key, param->u.crypt.key_len);
545 // copy to node key tbl
546 pMgmt->sNodeDBTable[iNodeIndex].byKeyIndex = param->u.crypt.idx;
547 pMgmt->sNodeDBTable[iNodeIndex].uWepKeyLength = param->u.crypt.key_len;
548 memcpy(&pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[0],
549 param->u.crypt.key,
550 param->u.crypt.key_len
551 );
552
553 dwKeyIndex = (DWORD)(param->u.crypt.idx);
554 if (param->u.crypt.flags & HOSTAP_CRYPT_FLAG_SET_TX_KEY) {
555 pDevice->byKeyIndex = (BYTE)dwKeyIndex;
556 pDevice->bTransmitKey = TRUE;
557 dwKeyIndex |= (1 << 31);
558 }
559
560 if (param->u.crypt.alg == WPA_ALG_WEP) {
561
562 if ((pDevice->bEnable8021x == FALSE) || (iNodeIndex == 0)) {
563 KeybSetDefaultKey( pDevice,
564 &(pDevice->sKey),
565 dwKeyIndex & ~(BIT30 | USE_KEYRSC),
566 param->u.crypt.key_len,
567 NULL,
568 abyKey,
569 KEY_CTL_WEP
570 );
571
572 } else {
573 // 8021x enable, individual key
574 dwKeyIndex |= (1 << 30); // set pairwise key
575 if (KeybSetKey(pDevice,
576 &(pDevice->sKey),
577 &param->sta_addr[0],
578 dwKeyIndex & ~(USE_KEYRSC),
579 param->u.crypt.key_len,
580 (PQWORD) &(KeyRSC),
581 (PBYTE)abyKey,
582 KEY_CTL_WEP
583 ) == TRUE) {
584
585
586 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = TRUE;
587
588 } else {
589 // Key Table Full
590 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = FALSE;
591 bKeyTableFull = TRUE;
592 }
593 }
594 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
595 pDevice->bEncryptionEnable = TRUE;
596 pMgmt->byCSSPK = KEY_CTL_WEP;
597 pMgmt->byCSSGK = KEY_CTL_WEP;
598 pMgmt->sNodeDBTable[iNodeIndex].byCipherSuite = KEY_CTL_WEP;
599 pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex = dwKeyIndex;
600 return ret;
601 }
602
603 if (param->u.crypt.seq) {
604 memcpy(&abySeq, param->u.crypt.seq, 8);
605 for (ii = 0 ; ii < 8 ; ii++) {
606 KeyRSC |= (abySeq[ii] << (ii * 8));
607 }
608 dwKeyIndex |= 1 << 29;
609 pMgmt->sNodeDBTable[iNodeIndex].KeyRSC = KeyRSC;
610 }
611
612 if (param->u.crypt.alg == WPA_ALG_TKIP) {
613 if (param->u.crypt.key_len != MAX_KEY_LEN)
614 return -EINVAL;
615 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
616 byKeyDecMode = KEY_CTL_TKIP;
617 pMgmt->byCSSPK = KEY_CTL_TKIP;
618 pMgmt->byCSSGK = KEY_CTL_TKIP;
619 }
620
621 if (param->u.crypt.alg == WPA_ALG_CCMP) {
622 if ((param->u.crypt.key_len != AES_KEY_LEN) ||
623 (pDevice->byLocalID <= REV_ID_VT3253_A1))
624 return -EINVAL;
625 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
626 byKeyDecMode = KEY_CTL_CCMP;
627 pMgmt->byCSSPK = KEY_CTL_CCMP;
628 pMgmt->byCSSGK = KEY_CTL_CCMP;
629 }
630
631
632 if (iNodeIndex == 0) {
633 KeybSetDefaultKey( pDevice,
634 &(pDevice->sKey),
635 dwKeyIndex,
636 param->u.crypt.key_len,
637 (PQWORD) &(KeyRSC),
638 abyKey,
639 byKeyDecMode
640 );
641 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = TRUE;
642
643 } else {
644 dwKeyIndex |= (1 << 30); // set pairwise key
645 if (KeybSetKey(pDevice,
646 &(pDevice->sKey),
647 &param->sta_addr[0],
648 dwKeyIndex,
649 param->u.crypt.key_len,
650 (PQWORD) &(KeyRSC),
651 (PBYTE)abyKey,
652 byKeyDecMode
653 ) == TRUE) {
654
655 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = TRUE;
656
657 } else {
658 // Key Table Full
659 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = FALSE;
660 bKeyTableFull = TRUE;
661 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Key Table Full\n");
662 }
663
664 }
665
666 if (bKeyTableFull == TRUE) {
667 wKeyCtl &= 0x7F00; // clear all key control filed
668 wKeyCtl |= (byKeyDecMode << 4);
669 wKeyCtl |= (byKeyDecMode);
670 wKeyCtl |= 0x0044; // use group key for all address
671 wKeyCtl |= 0x4000; // disable KeyTable[MAX_KEY_TABLE-1] on-fly to genernate rx int
672// Todo.. xxxxxx
673 //MACvSetDefaultKeyCtl(pDevice->PortOffset, wKeyCtl, MAX_KEY_TABLE-1, pDevice->byLocalID);
674 }
675
676 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Set key sta_index= %d \n", iNodeIndex);
677 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " tx_index=%d len=%d \n", param->u.crypt.idx,
678 param->u.crypt.key_len );
679 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " key=%x-%x-%x-%x-%x-xxxxx \n",
680 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[0],
681 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[1],
682 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[2],
683 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[3],
684 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[4]
685 );
686
687 // set wep key
688 pDevice->bEncryptionEnable = TRUE;
689 pMgmt->sNodeDBTable[iNodeIndex].byCipherSuite = byKeyDecMode;
690 pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex = dwKeyIndex;
691 pMgmt->sNodeDBTable[iNodeIndex].dwTSC47_16 = 0;
692 pMgmt->sNodeDBTable[iNodeIndex].wTSC15_0 = 0;
693
694 return ret;
695}
696
697
698
699/*
700 * Description:
701 * get each stations encryption key
702 *
703 * Parameters:
704 * In:
705 * pDevice -
706 * param -
707 * Out:
708 *
709 * Return Value:
710 *
711 */
712static int hostap_get_encryption(PSDevice pDevice,
713 struct viawget_hostapd_param *param,
714 int param_len)
715{
716 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
717 int ret = 0;
718 int ii;
719 int iNodeIndex =0;
720
721
722 param->u.crypt.err = 0;
723
724 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
725 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
726 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
727 iNodeIndex = 0;
728 } else {
729 if (BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &iNodeIndex) == FALSE) {
730 param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
731 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "hostap_get_encryption: HOSTAP_CRYPT_ERR_UNKNOWN_ADDR\n");
732 return -EINVAL;
733 }
734 }
735 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "hostap_get_encryption: %d\n", iNodeIndex);
736 memset(param->u.crypt.seq, 0, 8);
737 for (ii = 0 ; ii < 8 ; ii++) {
738 param->u.crypt.seq[ii] = (BYTE)pMgmt->sNodeDBTable[iNodeIndex].KeyRSC >> (ii * 8);
739 }
740
741 return ret;
742}
743
744
745/*
746 * Description:
747 * hostap_ioctl main function supported for hostap deamon.
748 *
749 * Parameters:
750 * In:
751 * pDevice -
752 * iw_point -
753 * Out:
754 *
755 * Return Value:
756 *
757 */
758
759int hostap_ioctl(PSDevice pDevice, struct iw_point *p)
760{
761 struct viawget_hostapd_param *param;
762 int ret = 0;
763 int ap_ioctl = 0;
764
765 if (p->length < sizeof(struct viawget_hostapd_param) ||
766 p->length > VIAWGET_HOSTAPD_MAX_BUF_SIZE || !p->pointer)
767 return -EINVAL;
768
769 param = (struct viawget_hostapd_param *) kmalloc((int)p->length, (int)GFP_KERNEL);
770 if (param == NULL)
771 return -ENOMEM;
772
773 if (copy_from_user(param, p->pointer, p->length)) {
774 ret = -EFAULT;
775 goto out;
776 }
777
778 switch (param->cmd) {
779 case VIAWGET_HOSTAPD_SET_ENCRYPTION:
780 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SET_ENCRYPTION \n");
781 spin_lock_irq(&pDevice->lock);
782 ret = hostap_set_encryption(pDevice, param, p->length);
783 spin_unlock_irq(&pDevice->lock);
784 break;
785 case VIAWGET_HOSTAPD_GET_ENCRYPTION:
786 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_GET_ENCRYPTION \n");
787 spin_lock_irq(&pDevice->lock);
788 ret = hostap_get_encryption(pDevice, param, p->length);
789 spin_unlock_irq(&pDevice->lock);
790 break;
791 case VIAWGET_HOSTAPD_SET_ASSOC_AP_ADDR:
792 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SET_ASSOC_AP_ADDR \n");
793 return -EOPNOTSUPP;
794 break;
795 case VIAWGET_HOSTAPD_FLUSH:
796 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_FLUSH \n");
797 spin_lock_irq(&pDevice->lock);
798 hostap_flush_sta(pDevice);
799 spin_unlock_irq(&pDevice->lock);
800 break;
801 case VIAWGET_HOSTAPD_ADD_STA:
802 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_ADD_STA \n");
803 spin_lock_irq(&pDevice->lock);
804 ret = hostap_add_sta(pDevice, param);
805 spin_unlock_irq(&pDevice->lock);
806 break;
807 case VIAWGET_HOSTAPD_REMOVE_STA:
808 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_REMOVE_STA \n");
809 spin_lock_irq(&pDevice->lock);
810 ret = hostap_remove_sta(pDevice, param);
811 spin_unlock_irq(&pDevice->lock);
812 break;
813 case VIAWGET_HOSTAPD_GET_INFO_STA:
814 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_GET_INFO_STA \n");
815 ret = hostap_get_info_sta(pDevice, param);
816 ap_ioctl = 1;
817 break;
818/*
819 case VIAWGET_HOSTAPD_RESET_TXEXC_STA:
820 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_RESET_TXEXC_STA \n");
821 ret = hostap_reset_txexc_sta(pDevice, param);
822 break;
823*/
824 case VIAWGET_HOSTAPD_SET_FLAGS_STA:
825 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SET_FLAGS_STA \n");
826 ret = hostap_set_flags_sta(pDevice, param);
827 break;
828
829 case VIAWGET_HOSTAPD_MLME:
830 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_MLME \n");
831 return -EOPNOTSUPP;
832
833 case VIAWGET_HOSTAPD_SET_GENERIC_ELEMENT:
834 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SET_GENERIC_ELEMENT \n");
835 ret = hostap_set_generic_element(pDevice, param);
836 break;
837
838 case VIAWGET_HOSTAPD_SCAN_REQ:
839 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SCAN_REQ \n");
840 return -EOPNOTSUPP;
841
842 case VIAWGET_HOSTAPD_STA_CLEAR_STATS:
843 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_STA_CLEAR_STATS \n");
844 return -EOPNOTSUPP;
845
846 default:
847 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "hostap_ioctl: unknown cmd=%d\n",
848 (int)param->cmd);
849 return -EOPNOTSUPP;
850 break;
851 }
852
853
854 if ((ret == 0) && ap_ioctl) {
855 if (copy_to_user(p->pointer, param, p->length)) {
856 ret = -EFAULT;
857 goto out;
858 }
859 }
860
861 out:
862 if (param != NULL)
863 kfree(param);
864
865 return ret;
866}
867