staging: vt6655: Remove commented out printks
[linux-2.6/btrfs-unstable.git] / drivers / staging / vt6655 / hostap.c
blob0d42159a7045010882bd69d99016084c08bb0f48
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:
33 #include "hostap.h"
34 #include "iocmd.h"
35 #include "mac.h"
36 #include "card.h"
37 #include "baseband.h"
38 #include "wpactl.h"
39 #include "key.h"
41 #define VIAWGET_HOSTAPD_MAX_BUF_SIZE 1024
42 #define HOSTAP_CRYPT_FLAG_SET_TX_KEY BIT0
43 #define HOSTAP_CRYPT_ERR_UNKNOWN_ADDR 3
44 #define HOSTAP_CRYPT_ERR_KEY_SET_FAILED 5
46 /*--------------------- Static Definitions -------------------------*/
48 /*--------------------- Static Classes ----------------------------*/
50 /*--------------------- Static Variables --------------------------*/
51 //static int msglevel =MSG_LEVEL_DEBUG;
52 static int msglevel = MSG_LEVEL_INFO;
54 /*--------------------- Static Functions --------------------------*/
59 /*--------------------- Export Variables --------------------------*/
63 * Description:
64 * register net_device (AP) for hostap deamon
66 * Parameters:
67 * In:
68 * pDevice -
69 * rtnl_locked -
70 * Out:
72 * Return Value:
76 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
78 PSDevice apdev_priv;
79 struct net_device *dev = pDevice->dev;
80 int ret;
81 const struct net_device_ops apdev_netdev_ops = {
82 .ndo_start_xmit = pDevice->tx_80211,
85 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
87 pDevice->apdev = kzalloc(sizeof(struct net_device), GFP_KERNEL);
88 if (pDevice->apdev == NULL)
89 return -ENOMEM;
91 apdev_priv = netdev_priv(pDevice->apdev);
92 *apdev_priv = *pDevice;
93 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
95 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
97 pDevice->apdev->type = ARPHRD_IEEE80211;
99 pDevice->apdev->base_addr = dev->base_addr;
100 pDevice->apdev->irq = dev->irq;
101 pDevice->apdev->mem_start = dev->mem_start;
102 pDevice->apdev->mem_end = dev->mem_end;
103 sprintf(pDevice->apdev->name, "%sap", dev->name);
104 if (rtnl_locked)
105 ret = register_netdevice(pDevice->apdev);
106 else
107 ret = register_netdev(pDevice->apdev);
108 if (ret) {
109 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: register_netdevice(AP) failed!\n",
110 dev->name);
111 return -1;
114 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Registered netdevice %s for AP management\n",
115 dev->name, pDevice->apdev->name);
117 KeyvInitTable(&pDevice->sKey, pDevice->PortOffset);
119 return 0;
123 * Description:
124 * unregister net_device(AP)
126 * Parameters:
127 * In:
128 * pDevice -
129 * rtnl_locked -
130 * Out:
132 * Return Value:
136 static int hostap_disable_hostapd(PSDevice pDevice, int rtnl_locked)
139 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: disabling hostapd mode\n", pDevice->dev->name);
141 if (pDevice->apdev && pDevice->apdev->name && pDevice->apdev->name[0]) {
142 if (rtnl_locked)
143 unregister_netdevice(pDevice->apdev);
144 else
145 unregister_netdev(pDevice->apdev);
146 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Netdevice %s unregistered\n",
147 pDevice->dev->name, pDevice->apdev->name);
149 kfree(pDevice->apdev);
150 pDevice->apdev = NULL;
151 pDevice->bEnable8021x = false;
152 pDevice->bEnableHostWEP = false;
153 pDevice->bEncryptionEnable = false;
155 //4.2007-0118-03,<Add> by EinsnLiu
156 //execute some clear work
157 pDevice->pMgmt->byCSSPK = KEY_CTL_NONE;
158 pDevice->pMgmt->byCSSGK = KEY_CTL_NONE;
159 KeyvInitTable(&pDevice->sKey, pDevice->PortOffset);
161 return 0;
166 * Description:
167 * Set enable/disable hostapd mode
169 * Parameters:
170 * In:
171 * pDevice -
172 * rtnl_locked -
173 * Out:
175 * Return Value:
179 int vt6655_hostap_set_hostapd(PSDevice pDevice, int val, int rtnl_locked)
181 if (val < 0 || val > 1)
182 return -EINVAL;
184 if (pDevice->bEnableHostapd == val)
185 return 0;
187 pDevice->bEnableHostapd = val;
189 if (val)
190 return hostap_enable_hostapd(pDevice, rtnl_locked);
191 else
192 return hostap_disable_hostapd(pDevice, rtnl_locked);
197 * Description:
198 * remove station function supported for hostap deamon
200 * Parameters:
201 * In:
202 * pDevice -
203 * param -
204 * Out:
206 * Return Value:
209 static int hostap_remove_sta(PSDevice pDevice,
210 struct viawget_hostapd_param *param)
212 unsigned int uNodeIndex;
215 if (BSSDBbIsSTAInNodeDB(pDevice->pMgmt, param->sta_addr, &uNodeIndex)) {
216 BSSvRemoveOneNode(pDevice, uNodeIndex);
218 else {
219 return -ENOENT;
221 return 0;
225 * Description:
226 * add a station from hostap deamon
228 * Parameters:
229 * In:
230 * pDevice -
231 * param -
232 * Out:
234 * Return Value:
237 static int hostap_add_sta(PSDevice pDevice,
238 struct viawget_hostapd_param *param)
240 PSMgmtObject pMgmt = pDevice->pMgmt;
241 unsigned int uNodeIndex;
244 if (!BSSDBbIsSTAInNodeDB(pMgmt, param->sta_addr, &uNodeIndex)) {
245 BSSvCreateOneNode((PSDevice)pDevice, &uNodeIndex);
247 memcpy(pMgmt->sNodeDBTable[uNodeIndex].abyMACAddr, param->sta_addr, WLAN_ADDR_LEN);
248 pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_ASSOC;
249 pMgmt->sNodeDBTable[uNodeIndex].wCapInfo = param->u.add_sta.capability;
250 // TODO listenInterval
251 // pMgmt->sNodeDBTable[uNodeIndex].wListenInterval = 1;
252 pMgmt->sNodeDBTable[uNodeIndex].bPSEnable = false;
253 pMgmt->sNodeDBTable[uNodeIndex].bySuppRate = param->u.add_sta.tx_supp_rates;
255 // set max tx rate
256 pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate =
257 pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate;
258 // set max basic rate
259 pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate = RATE_2M;
260 // Todo: check sta preamble, if ap can't support, set status code
261 pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble =
262 WLAN_GET_CAP_INFO_SHORTPREAMBLE(pMgmt->sNodeDBTable[uNodeIndex].wCapInfo);
264 pMgmt->sNodeDBTable[uNodeIndex].wAID = (unsigned short)param->u.add_sta.aid;
266 pMgmt->sNodeDBTable[uNodeIndex].ulLastRxJiffer = jiffies;
268 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Add STA AID= %d \n", pMgmt->sNodeDBTable[uNodeIndex].wAID);
269 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "MAC=%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X \n",
270 param->sta_addr[0],
271 param->sta_addr[1],
272 param->sta_addr[2],
273 param->sta_addr[3],
274 param->sta_addr[4],
275 param->sta_addr[5]
277 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Max Support rate = %d \n",
278 pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate);
280 return 0;
284 * Description:
285 * get station info
287 * Parameters:
288 * In:
289 * pDevice -
290 * param -
291 * Out:
293 * Return Value:
297 static int hostap_get_info_sta(PSDevice pDevice,
298 struct viawget_hostapd_param *param)
300 PSMgmtObject pMgmt = pDevice->pMgmt;
301 unsigned int uNodeIndex;
303 if (BSSDBbIsSTAInNodeDB(pMgmt, param->sta_addr, &uNodeIndex)) {
304 param->u.get_info_sta.inactive_sec =
305 (jiffies - pMgmt->sNodeDBTable[uNodeIndex].ulLastRxJiffer) / HZ;
307 //param->u.get_info_sta.txexc = pMgmt->sNodeDBTable[uNodeIndex].uTxAttempts;
309 else {
310 return -ENOENT;
313 return 0;
317 * Description:
318 * reset txexec
320 * Parameters:
321 * In:
322 * pDevice -
323 * param -
324 * Out:
325 * true, false
327 * Return Value:
331 static int hostap_reset_txexc_sta(PSDevice pDevice,
332 struct viawget_hostapd_param *param)
334 PSMgmtObject pMgmt = pDevice->pMgmt;
335 unsigned int uNodeIndex;
337 if (BSSDBbIsSTAInNodeDB(pMgmt, param->sta_addr, &uNodeIndex)) {
338 pMgmt->sNodeDBTable[uNodeIndex].uTxAttempts = 0;
340 else {
341 return -ENOENT;
344 return 0;
349 * Description:
350 * set station flag
352 * Parameters:
353 * In:
354 * pDevice -
355 * param -
356 * Out:
358 * Return Value:
361 static int hostap_set_flags_sta(PSDevice pDevice,
362 struct viawget_hostapd_param *param)
364 PSMgmtObject pMgmt = pDevice->pMgmt;
365 unsigned int uNodeIndex;
367 if (BSSDBbIsSTAInNodeDB(pMgmt, param->sta_addr, &uNodeIndex)) {
368 pMgmt->sNodeDBTable[uNodeIndex].dwFlags |= param->u.set_flags_sta.flags_or;
369 pMgmt->sNodeDBTable[uNodeIndex].dwFlags &= param->u.set_flags_sta.flags_and;
370 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " dwFlags = %x \n",
371 (unsigned int)pMgmt->sNodeDBTable[uNodeIndex].dwFlags);
373 else {
374 return -ENOENT;
377 return 0;
383 * Description:
384 * set generic element (wpa ie)
386 * Parameters:
387 * In:
388 * pDevice -
389 * param -
390 * Out:
392 * Return Value:
395 static int hostap_set_generic_element(PSDevice pDevice,
396 struct viawget_hostapd_param *param)
398 PSMgmtObject pMgmt = pDevice->pMgmt;
402 memcpy(pMgmt->abyWPAIE,
403 param->u.generic_elem.data,
404 param->u.generic_elem.len
407 pMgmt->wWPAIELen = param->u.generic_elem.len;
409 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pMgmt->wWPAIELen = %d\n", pMgmt->wWPAIELen);
411 // disable wpa
412 if (pMgmt->wWPAIELen == 0) {
413 pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
414 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " No WPAIE, Disable WPA \n");
415 } else {
416 // enable wpa
417 if ((pMgmt->abyWPAIE[0] == WLAN_EID_RSN_WPA) ||
418 (pMgmt->abyWPAIE[0] == WLAN_EID_RSN)) {
419 pMgmt->eAuthenMode = WMAC_AUTH_WPANONE;
420 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set WPAIE enable WPA\n");
421 } else
422 return -EINVAL;
425 return 0;
429 * Description:
430 * flush station nodes table.
432 * Parameters:
433 * In:
434 * pDevice -
435 * Out:
437 * Return Value:
441 static void hostap_flush_sta(PSDevice pDevice)
443 // reserved node index =0 for multicast node.
444 BSSvClearNodeDBTable(pDevice, 1);
445 pDevice->uAssocCount = 0;
447 return;
451 * Description:
452 * set each stations encryption key
454 * Parameters:
455 * In:
456 * pDevice -
457 * param -
458 * Out:
460 * Return Value:
463 static int hostap_set_encryption(PSDevice pDevice,
464 struct viawget_hostapd_param *param,
465 int param_len)
467 PSMgmtObject pMgmt = pDevice->pMgmt;
468 unsigned long dwKeyIndex = 0;
469 unsigned char abyKey[MAX_KEY_LEN];
470 unsigned char abySeq[MAX_KEY_LEN];
471 NDIS_802_11_KEY_RSC KeyRSC;
472 unsigned char byKeyDecMode = KEY_CTL_WEP;
473 int ret = 0;
474 int iNodeIndex = -1;
475 int ii;
476 bool bKeyTableFull = false;
477 unsigned short wKeyCtl = 0;
480 param->u.crypt.err = 0;
482 if (param_len !=
483 (int) ((char *) param->u.crypt.key - (char *) param) +
484 param->u.crypt.key_len)
485 return -EINVAL;
488 if (param->u.crypt.alg > WPA_ALG_CCMP)
489 return -EINVAL;
492 if ((param->u.crypt.idx > 3) || (param->u.crypt.key_len > MAX_KEY_LEN)) {
493 param->u.crypt.err = HOSTAP_CRYPT_ERR_KEY_SET_FAILED;
494 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " HOSTAP_CRYPT_ERR_KEY_SET_FAILED\n");
495 return -EINVAL;
498 if (is_broadcast_ether_addr(param->sta_addr)) {
499 if (param->u.crypt.idx >= MAX_GROUP_KEY)
500 return -EINVAL;
501 iNodeIndex = 0;
503 } else {
504 if (BSSDBbIsSTAInNodeDB(pMgmt, param->sta_addr, &iNodeIndex) == false) {
505 param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
506 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " HOSTAP_CRYPT_ERR_UNKNOWN_ADDR\n");
507 return -EINVAL;
510 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " hostap_set_encryption: sta_index %d \n", iNodeIndex);
511 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " hostap_set_encryption: alg %d \n", param->u.crypt.alg);
513 if (param->u.crypt.alg == WPA_ALG_NONE) {
515 if (pMgmt->sNodeDBTable[iNodeIndex].bOnFly == true) {
516 if (KeybRemoveKey(&(pDevice->sKey),
517 param->sta_addr,
518 pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex,
519 pDevice->PortOffset) == false) {
520 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "KeybRemoveKey fail \n");
522 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = false;
524 pMgmt->sNodeDBTable[iNodeIndex].byKeyIndex = 0;
525 pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex = 0;
526 pMgmt->sNodeDBTable[iNodeIndex].uWepKeyLength = 0;
527 pMgmt->sNodeDBTable[iNodeIndex].KeyRSC = 0;
528 pMgmt->sNodeDBTable[iNodeIndex].dwTSC47_16 = 0;
529 pMgmt->sNodeDBTable[iNodeIndex].wTSC15_0 = 0;
530 pMgmt->sNodeDBTable[iNodeIndex].byCipherSuite = 0;
531 memset(&pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[0],
533 MAX_KEY_LEN
536 return ret;
539 memcpy(abyKey, param->u.crypt.key, param->u.crypt.key_len);
540 // copy to node key tbl
541 pMgmt->sNodeDBTable[iNodeIndex].byKeyIndex = param->u.crypt.idx;
542 pMgmt->sNodeDBTable[iNodeIndex].uWepKeyLength = param->u.crypt.key_len;
543 memcpy(&pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[0],
544 param->u.crypt.key,
545 param->u.crypt.key_len
548 dwKeyIndex = (unsigned long)(param->u.crypt.idx);
549 if (param->u.crypt.flags & HOSTAP_CRYPT_FLAG_SET_TX_KEY) {
550 pDevice->byKeyIndex = (unsigned char)dwKeyIndex;
551 pDevice->bTransmitKey = true;
552 dwKeyIndex |= (1 << 31);
555 if (param->u.crypt.alg == WPA_ALG_WEP) {
557 if ((pDevice->bEnable8021x == false) || (iNodeIndex == 0)) {
558 KeybSetDefaultKey(&(pDevice->sKey),
559 dwKeyIndex & ~(BIT30 | USE_KEYRSC),
560 param->u.crypt.key_len,
561 NULL,
562 abyKey,
563 KEY_CTL_WEP,
564 pDevice->PortOffset,
565 pDevice->byLocalID);
567 } else {
568 // 8021x enable, individual key
569 dwKeyIndex |= (1 << 30); // set pairwise key
570 if (KeybSetKey(&(pDevice->sKey),
571 &param->sta_addr[0],
572 dwKeyIndex & ~(USE_KEYRSC),
573 param->u.crypt.key_len,
574 (PQWORD) &(KeyRSC),
575 (unsigned char *)abyKey,
576 KEY_CTL_WEP,
577 pDevice->PortOffset,
578 pDevice->byLocalID) == true) {
580 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = true;
582 } else {
583 // Key Table Full
584 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = false;
585 bKeyTableFull = true;
588 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
589 pDevice->bEncryptionEnable = true;
590 pMgmt->byCSSPK = KEY_CTL_WEP;
591 pMgmt->byCSSGK = KEY_CTL_WEP;
592 pMgmt->sNodeDBTable[iNodeIndex].byCipherSuite = KEY_CTL_WEP;
593 pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex = dwKeyIndex;
594 return ret;
597 if (param->u.crypt.seq) {
598 memcpy(&abySeq, param->u.crypt.seq, 8);
599 for (ii = 0; ii < 8; ii++)
600 KeyRSC |= (unsigned long)abySeq[ii] << (ii * 8);
602 dwKeyIndex |= 1 << 29;
603 pMgmt->sNodeDBTable[iNodeIndex].KeyRSC = KeyRSC;
606 if (param->u.crypt.alg == WPA_ALG_TKIP) {
607 if (param->u.crypt.key_len != MAX_KEY_LEN)
608 return -EINVAL;
609 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
610 byKeyDecMode = KEY_CTL_TKIP;
611 pMgmt->byCSSPK = KEY_CTL_TKIP;
612 pMgmt->byCSSGK = KEY_CTL_TKIP;
615 if (param->u.crypt.alg == WPA_ALG_CCMP) {
616 if ((param->u.crypt.key_len != AES_KEY_LEN) ||
617 (pDevice->byLocalID <= REV_ID_VT3253_A1))
618 return -EINVAL;
619 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
620 byKeyDecMode = KEY_CTL_CCMP;
621 pMgmt->byCSSPK = KEY_CTL_CCMP;
622 pMgmt->byCSSGK = KEY_CTL_CCMP;
626 if (iNodeIndex == 0) {
627 KeybSetDefaultKey(&(pDevice->sKey),
628 dwKeyIndex,
629 param->u.crypt.key_len,
630 (PQWORD) &(KeyRSC),
631 abyKey,
632 byKeyDecMode,
633 pDevice->PortOffset,
634 pDevice->byLocalID);
635 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = true;
637 } else {
638 dwKeyIndex |= (1 << 30); // set pairwise key
639 if (KeybSetKey(&(pDevice->sKey),
640 &param->sta_addr[0],
641 dwKeyIndex,
642 param->u.crypt.key_len,
643 (PQWORD) &(KeyRSC),
644 (unsigned char *)abyKey,
645 byKeyDecMode,
646 pDevice->PortOffset,
647 pDevice->byLocalID) == true) {
649 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = true;
651 } else {
652 // Key Table Full
653 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = false;
654 bKeyTableFull = true;
655 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Key Table Full\n");
660 if (bKeyTableFull == true) {
661 wKeyCtl &= 0x7F00; // clear all key control filed
662 wKeyCtl |= (byKeyDecMode << 4);
663 wKeyCtl |= (byKeyDecMode);
664 wKeyCtl |= 0x0044; // use group key for all address
665 wKeyCtl |= 0x4000; // disable KeyTable[MAX_KEY_TABLE-1] on-fly to genernate rx int
666 MACvSetDefaultKeyCtl(pDevice->PortOffset, wKeyCtl, MAX_KEY_TABLE-1, pDevice->byLocalID);
669 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Set key sta_index= %d \n", iNodeIndex);
670 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " tx_index=%d len=%d \n", param->u.crypt.idx,
671 param->u.crypt.key_len);
672 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " key=%x-%x-%x-%x-%x-xxxxx \n",
673 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[0],
674 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[1],
675 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[2],
676 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[3],
677 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[4]
680 // set wep key
681 pDevice->bEncryptionEnable = true;
682 pMgmt->sNodeDBTable[iNodeIndex].byCipherSuite = byKeyDecMode;
683 pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex = dwKeyIndex;
684 pMgmt->sNodeDBTable[iNodeIndex].dwTSC47_16 = 0;
685 pMgmt->sNodeDBTable[iNodeIndex].wTSC15_0 = 0;
687 return ret;
693 * Description:
694 * get each stations encryption key
696 * Parameters:
697 * In:
698 * pDevice -
699 * param -
700 * Out:
702 * Return Value:
705 static int hostap_get_encryption(PSDevice pDevice,
706 struct viawget_hostapd_param *param,
707 int param_len)
709 PSMgmtObject pMgmt = pDevice->pMgmt;
710 int ret = 0;
711 int ii;
712 int iNodeIndex = 0;
715 param->u.crypt.err = 0;
717 if (is_broadcast_ether_addr(param->sta_addr)) {
718 iNodeIndex = 0;
719 } else {
720 if (BSSDBbIsSTAInNodeDB(pMgmt, param->sta_addr, &iNodeIndex) == false) {
721 param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
722 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "hostap_get_encryption: HOSTAP_CRYPT_ERR_UNKNOWN_ADDR\n");
723 return -EINVAL;
726 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "hostap_get_encryption: %d\n", iNodeIndex);
727 memset(param->u.crypt.seq, 0, 8);
728 for (ii = 0; ii < 8; ii++) {
729 param->u.crypt.seq[ii] = (unsigned char)pMgmt->sNodeDBTable[iNodeIndex].KeyRSC >> (ii * 8);
732 return ret;
737 * Description:
738 * vt6655_hostap_ioctl main function supported for hostap deamon.
740 * Parameters:
741 * In:
742 * pDevice -
743 * iw_point -
744 * Out:
746 * Return Value:
750 int vt6655_hostap_ioctl(PSDevice pDevice, struct iw_point *p)
752 struct viawget_hostapd_param *param;
753 int ret = 0;
754 int ap_ioctl = 0;
756 if (p->length < sizeof(struct viawget_hostapd_param) ||
757 p->length > VIAWGET_HOSTAPD_MAX_BUF_SIZE || !p->pointer)
758 return -EINVAL;
760 param = kmalloc((int)p->length, (int)GFP_KERNEL);
761 if (param == NULL)
762 return -ENOMEM;
764 if (copy_from_user(param, p->pointer, p->length)) {
765 ret = -EFAULT;
766 goto out;
769 switch (param->cmd) {
770 case VIAWGET_HOSTAPD_SET_ENCRYPTION:
771 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SET_ENCRYPTION \n");
772 spin_lock_irq(&pDevice->lock);
773 ret = hostap_set_encryption(pDevice, param, p->length);
774 spin_unlock_irq(&pDevice->lock);
775 break;
776 case VIAWGET_HOSTAPD_GET_ENCRYPTION:
777 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_GET_ENCRYPTION \n");
778 spin_lock_irq(&pDevice->lock);
779 ret = hostap_get_encryption(pDevice, param, p->length);
780 spin_unlock_irq(&pDevice->lock);
781 break;
782 case VIAWGET_HOSTAPD_SET_ASSOC_AP_ADDR:
783 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SET_ASSOC_AP_ADDR \n");
784 return -EOPNOTSUPP;
785 break;
786 case VIAWGET_HOSTAPD_FLUSH:
787 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_FLUSH \n");
788 spin_lock_irq(&pDevice->lock);
789 hostap_flush_sta(pDevice);
790 spin_unlock_irq(&pDevice->lock);
791 break;
792 case VIAWGET_HOSTAPD_ADD_STA:
793 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_ADD_STA \n");
794 spin_lock_irq(&pDevice->lock);
795 ret = hostap_add_sta(pDevice, param);
796 spin_unlock_irq(&pDevice->lock);
797 break;
798 case VIAWGET_HOSTAPD_REMOVE_STA:
799 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_REMOVE_STA \n");
800 spin_lock_irq(&pDevice->lock);
801 ret = hostap_remove_sta(pDevice, param);
802 spin_unlock_irq(&pDevice->lock);
803 break;
804 case VIAWGET_HOSTAPD_GET_INFO_STA:
805 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_GET_INFO_STA \n");
806 ret = hostap_get_info_sta(pDevice, param);
807 ap_ioctl = 1;
808 break;
810 case VIAWGET_HOSTAPD_RESET_TXEXC_STA:
811 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_RESET_TXEXC_STA \n");
812 ret = hostap_reset_txexc_sta(pDevice, param);
813 break;
815 case VIAWGET_HOSTAPD_SET_FLAGS_STA:
816 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SET_FLAGS_STA \n");
817 ret = hostap_set_flags_sta(pDevice, param);
818 break;
820 case VIAWGET_HOSTAPD_MLME:
821 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_MLME \n");
822 return -EOPNOTSUPP;
824 case VIAWGET_HOSTAPD_SET_GENERIC_ELEMENT:
825 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SET_GENERIC_ELEMENT \n");
826 ret = hostap_set_generic_element(pDevice, param);
827 break;
829 case VIAWGET_HOSTAPD_SCAN_REQ:
830 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SCAN_REQ \n");
831 return -EOPNOTSUPP;
833 case VIAWGET_HOSTAPD_STA_CLEAR_STATS:
834 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_STA_CLEAR_STATS \n");
835 return -EOPNOTSUPP;
837 default:
838 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "vt6655_hostap_ioctl: unknown cmd=%d\n",
839 (int)param->cmd);
840 return -EOPNOTSUPP;
841 break;
845 if ((ret == 0) && ap_ioctl) {
846 if (copy_to_user(p->pointer, param, p->length)) {
847 ret = -EFAULT;
848 goto out;
852 out:
853 kfree(param);
855 return ret;