Staging: vt665x: Text janitor in prep for driver merge, part 2
[linux-2.6/mini2440.git] / drivers / staging / vt6655 / hostap.c
blob658e1aec8f33b480f19f626b27563fbd12d723cf
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.
19 * File: hostap.c
21 * Purpose: handle hostap deamon ioctl input/out functions
23 * Author: Lyndon Chen
25 * Date: Oct. 20, 2003
27 * Functions:
29 * Revision History:
34 #if !defined(__HOSTAP_H__)
35 #include "hostap.h"
36 #endif
37 #if !defined(__IOCMD_H__)
38 #include "iocmd.h"
39 #endif
40 #if !defined(__MAC_H__)
41 #include "mac.h"
42 #endif
43 #if !defined(__CARD_H__)
44 #include "card.h"
45 #endif
46 #if !defined(__BASEBAND_H__)
47 #include "baseband.h"
48 #endif
49 #if !defined(__WPACTL_H__)
50 #include "wpactl.h"
51 #endif
52 #if !defined(__KEY_H__)
53 #include "key.h"
54 #endif
55 #if !defined(__MAC_H__)
56 #include "mac.h"
57 #endif
60 #define VIAWGET_HOSTAPD_MAX_BUF_SIZE 1024
61 #define HOSTAP_CRYPT_FLAG_SET_TX_KEY BIT0
62 #define HOSTAP_CRYPT_FLAG_PERMANENT BIT1
63 #define HOSTAP_CRYPT_ERR_UNKNOWN_ALG 2
64 #define HOSTAP_CRYPT_ERR_UNKNOWN_ADDR 3
65 #define HOSTAP_CRYPT_ERR_CRYPT_INIT_FAILED 4
66 #define HOSTAP_CRYPT_ERR_KEY_SET_FAILED 5
67 #define HOSTAP_CRYPT_ERR_TX_KEY_SET_FAILED 6
68 #define HOSTAP_CRYPT_ERR_CARD_CONF_FAILED 7
71 /*--------------------- Static Definitions -------------------------*/
73 /*--------------------- Static Classes ----------------------------*/
75 /*--------------------- Static Variables --------------------------*/
76 //static int msglevel =MSG_LEVEL_DEBUG;
77 static int msglevel =MSG_LEVEL_INFO;
79 /*--------------------- Static Functions --------------------------*/
84 /*--------------------- Export Variables --------------------------*/
88 * Description:
89 * register net_device (AP) for hostap deamon
91 * Parameters:
92 * In:
93 * pDevice -
94 * rtnl_locked -
95 * Out:
97 * Return Value:
101 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
103 PSDevice apdev_priv;
104 struct net_device *dev = pDevice->dev;
105 int ret;
106 const struct net_device_ops apdev_netdev_ops = {
107 .ndo_start_xmit = pDevice->tx_80211,
110 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
112 pDevice->apdev = (struct net_device *)kmalloc(sizeof(struct net_device), GFP_KERNEL);
113 if (pDevice->apdev == NULL)
114 return -ENOMEM;
115 memset(pDevice->apdev, 0, sizeof(struct net_device));
117 apdev_priv = netdev_priv(pDevice->apdev);
118 *apdev_priv = *pDevice;
119 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
121 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
123 pDevice->apdev->type = ARPHRD_IEEE80211;
125 pDevice->apdev->base_addr = dev->base_addr;
126 pDevice->apdev->irq = dev->irq;
127 pDevice->apdev->mem_start = dev->mem_start;
128 pDevice->apdev->mem_end = dev->mem_end;
129 sprintf(pDevice->apdev->name, "%sap", dev->name);
130 if (rtnl_locked)
131 ret = register_netdevice(pDevice->apdev);
132 else
133 ret = register_netdev(pDevice->apdev);
134 if (ret) {
135 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: register_netdevice(AP) failed!\n",
136 dev->name);
137 return -1;
140 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Registered netdevice %s for AP management\n",
141 dev->name, pDevice->apdev->name);
143 KeyvInitTable(&pDevice->sKey, pDevice->PortOffset);
145 return 0;
149 * Description:
150 * unregister net_device(AP)
152 * Parameters:
153 * In:
154 * pDevice -
155 * rtnl_locked -
156 * Out:
158 * Return Value:
162 static int hostap_disable_hostapd(PSDevice pDevice, int rtnl_locked)
165 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: disabling hostapd mode\n", pDevice->dev->name);
167 if (pDevice->apdev && pDevice->apdev->name && pDevice->apdev->name[0]) {
168 if (rtnl_locked)
169 unregister_netdevice(pDevice->apdev);
170 else
171 unregister_netdev(pDevice->apdev);
172 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Netdevice %s unregistered\n",
173 pDevice->dev->name, pDevice->apdev->name);
175 kfree(pDevice->apdev);
176 pDevice->apdev = NULL;
177 pDevice->bEnable8021x = FALSE;
178 pDevice->bEnableHostWEP = FALSE;
179 pDevice->bEncryptionEnable = FALSE;
181 //4.2007-0118-03,<Add> by EinsnLiu
182 //execute some clear work
183 pDevice->pMgmt->byCSSPK=KEY_CTL_NONE;
184 pDevice->pMgmt->byCSSGK=KEY_CTL_NONE;
185 KeyvInitTable(&pDevice->sKey,pDevice->PortOffset);
187 return 0;
192 * Description:
193 * Set enable/disable hostapd mode
195 * Parameters:
196 * In:
197 * pDevice -
198 * rtnl_locked -
199 * Out:
201 * Return Value:
205 int hostap_set_hostapd(PSDevice pDevice, int val, int rtnl_locked)
207 if (val < 0 || val > 1)
208 return -EINVAL;
210 if (pDevice->bEnableHostapd == val)
211 return 0;
213 pDevice->bEnableHostapd = val;
215 if (val)
216 return hostap_enable_hostapd(pDevice, rtnl_locked);
217 else
218 return hostap_disable_hostapd(pDevice, rtnl_locked);
223 * Description:
224 * remove station function supported for hostap deamon
226 * Parameters:
227 * In:
228 * pDevice -
229 * param -
230 * Out:
232 * Return Value:
235 static int hostap_remove_sta(PSDevice pDevice,
236 struct viawget_hostapd_param *param)
238 UINT uNodeIndex;
241 if (BSSDBbIsSTAInNodeDB(pDevice->pMgmt, param->sta_addr, &uNodeIndex)) {
242 BSSvRemoveOneNode(pDevice, uNodeIndex);
244 else {
245 return -ENOENT;
247 return 0;
251 * Description:
252 * add a station from hostap deamon
254 * Parameters:
255 * In:
256 * pDevice -
257 * param -
258 * Out:
260 * Return Value:
263 static int hostap_add_sta(PSDevice pDevice,
264 struct viawget_hostapd_param *param)
266 PSMgmtObject pMgmt = pDevice->pMgmt;
267 UINT uNodeIndex;
270 if (!BSSDBbIsSTAInNodeDB(pMgmt, param->sta_addr, &uNodeIndex)) {
271 BSSvCreateOneNode((PSDevice)pDevice, &uNodeIndex);
273 memcpy(pMgmt->sNodeDBTable[uNodeIndex].abyMACAddr, param->sta_addr, WLAN_ADDR_LEN);
274 pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_ASSOC;
275 pMgmt->sNodeDBTable[uNodeIndex].wCapInfo = param->u.add_sta.capability;
276 // TODO listenInterval
277 // pMgmt->sNodeDBTable[uNodeIndex].wListenInterval = 1;
278 pMgmt->sNodeDBTable[uNodeIndex].bPSEnable = FALSE;
279 pMgmt->sNodeDBTable[uNodeIndex].bySuppRate = param->u.add_sta.tx_supp_rates;
281 // set max tx rate
282 pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate =
283 pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate;
284 // set max basic rate
285 pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate = RATE_2M;
286 // Todo: check sta preamble, if ap can't support, set status code
287 pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble =
288 WLAN_GET_CAP_INFO_SHORTPREAMBLE(pMgmt->sNodeDBTable[uNodeIndex].wCapInfo);
290 pMgmt->sNodeDBTable[uNodeIndex].wAID = (WORD)param->u.add_sta.aid;
292 pMgmt->sNodeDBTable[uNodeIndex].ulLastRxJiffer = jiffies;
294 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Add STA AID= %d \n", pMgmt->sNodeDBTable[uNodeIndex].wAID);
295 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "MAC=%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X \n",
296 param->sta_addr[0],
297 param->sta_addr[1],
298 param->sta_addr[2],
299 param->sta_addr[3],
300 param->sta_addr[4],
301 param->sta_addr[5]
303 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Max Support rate = %d \n",
304 pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate);
306 return 0;
310 * Description:
311 * get station info
313 * Parameters:
314 * In:
315 * pDevice -
316 * param -
317 * Out:
319 * Return Value:
323 static int hostap_get_info_sta(PSDevice pDevice,
324 struct viawget_hostapd_param *param)
326 PSMgmtObject pMgmt = pDevice->pMgmt;
327 UINT uNodeIndex;
329 if (BSSDBbIsSTAInNodeDB(pMgmt, param->sta_addr, &uNodeIndex)) {
330 param->u.get_info_sta.inactive_sec =
331 (jiffies - pMgmt->sNodeDBTable[uNodeIndex].ulLastRxJiffer) / HZ;
333 //param->u.get_info_sta.txexc = pMgmt->sNodeDBTable[uNodeIndex].uTxAttempts;
335 else {
336 return -ENOENT;
339 return 0;
343 * Description:
344 * reset txexec
346 * Parameters:
347 * In:
348 * pDevice -
349 * param -
350 * Out:
351 * TURE, FALSE
353 * Return Value:
357 static int hostap_reset_txexc_sta(PSDevice pDevice,
358 struct viawget_hostapd_param *param)
360 PSMgmtObject pMgmt = pDevice->pMgmt;
361 UINT uNodeIndex;
363 if (BSSDBbIsSTAInNodeDB(pMgmt, param->sta_addr, &uNodeIndex)) {
364 pMgmt->sNodeDBTable[uNodeIndex].uTxAttempts = 0;
366 else {
367 return -ENOENT;
370 return 0;
375 * Description:
376 * set station flag
378 * Parameters:
379 * In:
380 * pDevice -
381 * param -
382 * Out:
384 * Return Value:
387 static int hostap_set_flags_sta(PSDevice pDevice,
388 struct viawget_hostapd_param *param)
390 PSMgmtObject pMgmt = pDevice->pMgmt;
391 UINT uNodeIndex;
393 if (BSSDBbIsSTAInNodeDB(pMgmt, param->sta_addr, &uNodeIndex)) {
394 pMgmt->sNodeDBTable[uNodeIndex].dwFlags |= param->u.set_flags_sta.flags_or;
395 pMgmt->sNodeDBTable[uNodeIndex].dwFlags &= param->u.set_flags_sta.flags_and;
396 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " dwFlags = %x \n",
397 (UINT)pMgmt->sNodeDBTable[uNodeIndex].dwFlags);
399 else {
400 return -ENOENT;
403 return 0;
409 * Description:
410 * set generic element (wpa ie)
412 * Parameters:
413 * In:
414 * pDevice -
415 * param -
416 * Out:
418 * Return Value:
421 static int hostap_set_generic_element(PSDevice pDevice,
422 struct viawget_hostapd_param *param)
424 PSMgmtObject pMgmt = pDevice->pMgmt;
428 memcpy( pMgmt->abyWPAIE,
429 param->u.generic_elem.data,
430 param->u.generic_elem.len
433 pMgmt->wWPAIELen = param->u.generic_elem.len;
435 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pMgmt->wWPAIELen = %d\n", pMgmt->wWPAIELen);
437 // disable wpa
438 if (pMgmt->wWPAIELen == 0) {
439 pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
440 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " No WPAIE, Disable WPA \n");
441 } else {
442 // enable wpa
443 if ((pMgmt->abyWPAIE[0] == WLAN_EID_RSN_WPA) ||
444 (pMgmt->abyWPAIE[0] == WLAN_EID_RSN)) {
445 pMgmt->eAuthenMode = WMAC_AUTH_WPANONE;
446 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set WPAIE enable WPA\n");
447 } else
448 return -EINVAL;
451 return 0;
455 * Description:
456 * flush station nodes table.
458 * Parameters:
459 * In:
460 * pDevice -
461 * Out:
463 * Return Value:
467 static void hostap_flush_sta(PSDevice pDevice)
469 // reserved node index =0 for multicast node.
470 BSSvClearNodeDBTable(pDevice, 1);
471 pDevice->uAssocCount = 0;
473 return;
477 * Description:
478 * set each stations encryption key
480 * Parameters:
481 * In:
482 * pDevice -
483 * param -
484 * Out:
486 * Return Value:
489 static int hostap_set_encryption(PSDevice pDevice,
490 struct viawget_hostapd_param *param,
491 int param_len)
493 PSMgmtObject pMgmt = pDevice->pMgmt;
494 DWORD dwKeyIndex = 0;
495 BYTE abyKey[MAX_KEY_LEN];
496 BYTE abySeq[MAX_KEY_LEN];
497 NDIS_802_11_KEY_RSC KeyRSC;
498 BYTE byKeyDecMode = KEY_CTL_WEP;
499 int ret = 0;
500 int iNodeIndex = -1;
501 int ii;
502 BOOL bKeyTableFull = FALSE;
503 WORD wKeyCtl = 0;
506 param->u.crypt.err = 0;
508 if (param_len !=
509 (int) ((char *) param->u.crypt.key - (char *) param) +
510 param->u.crypt.key_len)
511 return -EINVAL;
514 if (param->u.crypt.alg > WPA_ALG_CCMP)
515 return -EINVAL;
518 if ((param->u.crypt.idx > 3) || (param->u.crypt.key_len > MAX_KEY_LEN)) {
519 param->u.crypt.err = HOSTAP_CRYPT_ERR_KEY_SET_FAILED;
520 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " HOSTAP_CRYPT_ERR_KEY_SET_FAILED\n");
521 return -EINVAL;
524 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
525 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
526 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
527 if (param->u.crypt.idx >= MAX_GROUP_KEY)
528 return -EINVAL;
529 iNodeIndex = 0;
531 } else {
532 if (BSSDBbIsSTAInNodeDB(pMgmt, param->sta_addr, &iNodeIndex) == FALSE) {
533 param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
534 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " HOSTAP_CRYPT_ERR_UNKNOWN_ADDR\n");
535 return -EINVAL;
538 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " hostap_set_encryption: sta_index %d \n", iNodeIndex);
539 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " hostap_set_encryption: alg %d \n", param->u.crypt.alg);
541 if (param->u.crypt.alg == WPA_ALG_NONE) {
543 if (pMgmt->sNodeDBTable[iNodeIndex].bOnFly == TRUE) {
544 if (KeybRemoveKey(&(pDevice->sKey),
545 param->sta_addr,
546 pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex,
547 pDevice->PortOffset) == FALSE) {
548 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "KeybRemoveKey fail \n");
550 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = FALSE;
552 pMgmt->sNodeDBTable[iNodeIndex].byKeyIndex = 0;
553 pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex = 0;
554 pMgmt->sNodeDBTable[iNodeIndex].uWepKeyLength = 0;
555 pMgmt->sNodeDBTable[iNodeIndex].KeyRSC = 0;
556 pMgmt->sNodeDBTable[iNodeIndex].dwTSC47_16 = 0;
557 pMgmt->sNodeDBTable[iNodeIndex].wTSC15_0 = 0;
558 pMgmt->sNodeDBTable[iNodeIndex].byCipherSuite = 0;
559 memset(&pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[0],
561 MAX_KEY_LEN
564 return ret;
567 memcpy(abyKey, param->u.crypt.key, param->u.crypt.key_len);
568 // copy to node key tbl
569 pMgmt->sNodeDBTable[iNodeIndex].byKeyIndex = param->u.crypt.idx;
570 pMgmt->sNodeDBTable[iNodeIndex].uWepKeyLength = param->u.crypt.key_len;
571 memcpy(&pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[0],
572 param->u.crypt.key,
573 param->u.crypt.key_len
576 dwKeyIndex = (DWORD)(param->u.crypt.idx);
577 if (param->u.crypt.flags & HOSTAP_CRYPT_FLAG_SET_TX_KEY) {
578 pDevice->byKeyIndex = (BYTE)dwKeyIndex;
579 pDevice->bTransmitKey = TRUE;
580 dwKeyIndex |= (1 << 31);
583 if (param->u.crypt.alg == WPA_ALG_WEP) {
585 if ((pDevice->bEnable8021x == FALSE) || (iNodeIndex == 0)) {
586 KeybSetDefaultKey(&(pDevice->sKey),
587 dwKeyIndex & ~(BIT30 | USE_KEYRSC),
588 param->u.crypt.key_len,
589 NULL,
590 abyKey,
591 KEY_CTL_WEP,
592 pDevice->PortOffset,
593 pDevice->byLocalID);
595 } else {
596 // 8021x enable, individual key
597 dwKeyIndex |= (1 << 30); // set pairwise key
598 if (KeybSetKey(&(pDevice->sKey),
599 &param->sta_addr[0],
600 dwKeyIndex & ~(USE_KEYRSC),
601 param->u.crypt.key_len,
602 (PQWORD) &(KeyRSC),
603 (PBYTE)abyKey,
604 KEY_CTL_WEP,
605 pDevice->PortOffset,
606 pDevice->byLocalID) == TRUE) {
608 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = TRUE;
610 } else {
611 // Key Table Full
612 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = FALSE;
613 bKeyTableFull = TRUE;
616 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
617 pDevice->bEncryptionEnable = TRUE;
618 pMgmt->byCSSPK = KEY_CTL_WEP;
619 pMgmt->byCSSGK = KEY_CTL_WEP;
620 pMgmt->sNodeDBTable[iNodeIndex].byCipherSuite = KEY_CTL_WEP;
621 pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex = dwKeyIndex;
622 return ret;
625 if (param->u.crypt.seq) {
626 memcpy(&abySeq, param->u.crypt.seq, 8);
627 for (ii = 0 ; ii < 8 ; ii++) {
628 KeyRSC |= (abySeq[ii] << (ii * 8));
630 dwKeyIndex |= 1 << 29;
631 pMgmt->sNodeDBTable[iNodeIndex].KeyRSC = KeyRSC;
634 if (param->u.crypt.alg == WPA_ALG_TKIP) {
635 if (param->u.crypt.key_len != MAX_KEY_LEN)
636 return -EINVAL;
637 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
638 byKeyDecMode = KEY_CTL_TKIP;
639 pMgmt->byCSSPK = KEY_CTL_TKIP;
640 pMgmt->byCSSGK = KEY_CTL_TKIP;
643 if (param->u.crypt.alg == WPA_ALG_CCMP) {
644 if ((param->u.crypt.key_len != AES_KEY_LEN) ||
645 (pDevice->byLocalID <= REV_ID_VT3253_A1))
646 return -EINVAL;
647 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
648 byKeyDecMode = KEY_CTL_CCMP;
649 pMgmt->byCSSPK = KEY_CTL_CCMP;
650 pMgmt->byCSSGK = KEY_CTL_CCMP;
654 if (iNodeIndex == 0) {
655 KeybSetDefaultKey(&(pDevice->sKey),
656 dwKeyIndex,
657 param->u.crypt.key_len,
658 (PQWORD) &(KeyRSC),
659 abyKey,
660 byKeyDecMode,
661 pDevice->PortOffset,
662 pDevice->byLocalID);
663 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = TRUE;
665 } else {
666 dwKeyIndex |= (1 << 30); // set pairwise key
667 if (KeybSetKey(&(pDevice->sKey),
668 &param->sta_addr[0],
669 dwKeyIndex,
670 param->u.crypt.key_len,
671 (PQWORD) &(KeyRSC),
672 (PBYTE)abyKey,
673 byKeyDecMode,
674 pDevice->PortOffset,
675 pDevice->byLocalID) == TRUE) {
677 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = TRUE;
679 } else {
680 // Key Table Full
681 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = FALSE;
682 bKeyTableFull = TRUE;
683 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Key Table Full\n");
688 if (bKeyTableFull == TRUE) {
689 wKeyCtl &= 0x7F00; // clear all key control filed
690 wKeyCtl |= (byKeyDecMode << 4);
691 wKeyCtl |= (byKeyDecMode);
692 wKeyCtl |= 0x0044; // use group key for all address
693 wKeyCtl |= 0x4000; // disable KeyTable[MAX_KEY_TABLE-1] on-fly to genernate rx int
694 MACvSetDefaultKeyCtl(pDevice->PortOffset, wKeyCtl, MAX_KEY_TABLE-1, pDevice->byLocalID);
697 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Set key sta_index= %d \n", iNodeIndex);
698 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " tx_index=%d len=%d \n", param->u.crypt.idx,
699 param->u.crypt.key_len );
700 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " key=%x-%x-%x-%x-%x-xxxxx \n",
701 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[0],
702 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[1],
703 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[2],
704 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[3],
705 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[4]
708 // set wep key
709 pDevice->bEncryptionEnable = TRUE;
710 pMgmt->sNodeDBTable[iNodeIndex].byCipherSuite = byKeyDecMode;
711 pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex = dwKeyIndex;
712 pMgmt->sNodeDBTable[iNodeIndex].dwTSC47_16 = 0;
713 pMgmt->sNodeDBTable[iNodeIndex].wTSC15_0 = 0;
715 return ret;
721 * Description:
722 * get each stations encryption key
724 * Parameters:
725 * In:
726 * pDevice -
727 * param -
728 * Out:
730 * Return Value:
733 static int hostap_get_encryption(PSDevice pDevice,
734 struct viawget_hostapd_param *param,
735 int param_len)
737 PSMgmtObject pMgmt = pDevice->pMgmt;
738 int ret = 0;
739 int ii;
740 int iNodeIndex =0;
743 param->u.crypt.err = 0;
745 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
746 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
747 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
748 iNodeIndex = 0;
749 } else {
750 if (BSSDBbIsSTAInNodeDB(pMgmt, param->sta_addr, &iNodeIndex) == FALSE) {
751 param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
752 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "hostap_get_encryption: HOSTAP_CRYPT_ERR_UNKNOWN_ADDR\n");
753 return -EINVAL;
756 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "hostap_get_encryption: %d\n", iNodeIndex);
757 memset(param->u.crypt.seq, 0, 8);
758 for (ii = 0 ; ii < 8 ; ii++) {
759 param->u.crypt.seq[ii] = (BYTE)pMgmt->sNodeDBTable[iNodeIndex].KeyRSC >> (ii * 8);
762 return ret;
767 * Description:
768 * hostap_ioctl main function supported for hostap deamon.
770 * Parameters:
771 * In:
772 * pDevice -
773 * iw_point -
774 * Out:
776 * Return Value:
780 int hostap_ioctl(PSDevice pDevice, struct iw_point *p)
782 struct viawget_hostapd_param *param;
783 int ret = 0;
784 int ap_ioctl = 0;
786 if (p->length < sizeof(struct viawget_hostapd_param) ||
787 p->length > VIAWGET_HOSTAPD_MAX_BUF_SIZE || !p->pointer)
788 return -EINVAL;
790 param = (struct viawget_hostapd_param *) kmalloc((int)p->length, (int)GFP_KERNEL);
791 if (param == NULL)
792 return -ENOMEM;
794 if (copy_from_user(param, p->pointer, p->length)) {
795 ret = -EFAULT;
796 goto out;
799 switch (param->cmd) {
800 case VIAWGET_HOSTAPD_SET_ENCRYPTION:
801 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SET_ENCRYPTION \n");
802 spin_lock_irq(&pDevice->lock);
803 ret = hostap_set_encryption(pDevice, param, p->length);
804 spin_unlock_irq(&pDevice->lock);
805 break;
806 case VIAWGET_HOSTAPD_GET_ENCRYPTION:
807 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_GET_ENCRYPTION \n");
808 spin_lock_irq(&pDevice->lock);
809 ret = hostap_get_encryption(pDevice, param, p->length);
810 spin_unlock_irq(&pDevice->lock);
811 break;
812 case VIAWGET_HOSTAPD_SET_ASSOC_AP_ADDR:
813 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SET_ASSOC_AP_ADDR \n");
814 return -EOPNOTSUPP;
815 break;
816 case VIAWGET_HOSTAPD_FLUSH:
817 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_FLUSH \n");
818 spin_lock_irq(&pDevice->lock);
819 hostap_flush_sta(pDevice);
820 spin_unlock_irq(&pDevice->lock);
821 break;
822 case VIAWGET_HOSTAPD_ADD_STA:
823 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_ADD_STA \n");
824 spin_lock_irq(&pDevice->lock);
825 ret = hostap_add_sta(pDevice, param);
826 spin_unlock_irq(&pDevice->lock);
827 break;
828 case VIAWGET_HOSTAPD_REMOVE_STA:
829 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_REMOVE_STA \n");
830 spin_lock_irq(&pDevice->lock);
831 ret = hostap_remove_sta(pDevice, param);
832 spin_unlock_irq(&pDevice->lock);
833 break;
834 case VIAWGET_HOSTAPD_GET_INFO_STA:
835 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_GET_INFO_STA \n");
836 ret = hostap_get_info_sta(pDevice, param);
837 ap_ioctl = 1;
838 break;
840 case VIAWGET_HOSTAPD_RESET_TXEXC_STA:
841 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_RESET_TXEXC_STA \n");
842 ret = hostap_reset_txexc_sta(pDevice, param);
843 break;
845 case VIAWGET_HOSTAPD_SET_FLAGS_STA:
846 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SET_FLAGS_STA \n");
847 ret = hostap_set_flags_sta(pDevice, param);
848 break;
850 case VIAWGET_HOSTAPD_MLME:
851 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_MLME \n");
852 return -EOPNOTSUPP;
854 case VIAWGET_HOSTAPD_SET_GENERIC_ELEMENT:
855 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SET_GENERIC_ELEMENT \n");
856 ret = hostap_set_generic_element(pDevice, param);
857 break;
859 case VIAWGET_HOSTAPD_SCAN_REQ:
860 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SCAN_REQ \n");
861 return -EOPNOTSUPP;
863 case VIAWGET_HOSTAPD_STA_CLEAR_STATS:
864 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_STA_CLEAR_STATS \n");
865 return -EOPNOTSUPP;
867 default:
868 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "hostap_ioctl: unknown cmd=%d\n",
869 (int)param->cmd);
870 return -EOPNOTSUPP;
871 break;
875 if ((ret == 0) && ap_ioctl) {
876 if (copy_to_user(p->pointer, param, p->length)) {
877 ret = -EFAULT;
878 goto out;
882 out:
883 if (param != NULL)
884 kfree(param);
886 return ret;