x86/xen: resume timer irqs early
[linux/fpc-iii.git] / drivers / staging / vt6656 / hostap.c
blobc699a3058b39920a34daf1a6f63524be990e29cb
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 daemon 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"
40 #include "datarate.h"
42 #define VIAWGET_HOSTAPD_MAX_BUF_SIZE 1024
43 #define HOSTAP_CRYPT_FLAG_SET_TX_KEY BIT0
44 #define HOSTAP_CRYPT_ERR_UNKNOWN_ADDR 3
45 #define HOSTAP_CRYPT_ERR_KEY_SET_FAILED 5
47 static int msglevel =MSG_LEVEL_INFO;
50 * Description:
51 * register net_device (AP) for hostap daemon
53 * Parameters:
54 * In:
55 * pDevice -
56 * rtnl_locked -
57 * Out:
59 * Return Value:
63 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
65 struct vnt_private *apdev_priv;
66 struct net_device *dev = pDevice->dev;
67 int ret;
68 const struct net_device_ops apdev_netdev_ops = {
69 .ndo_start_xmit = pDevice->tx_80211,
72 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
74 pDevice->apdev = kzalloc(sizeof(struct net_device), GFP_KERNEL);
75 if (pDevice->apdev == NULL)
76 return -ENOMEM;
78 apdev_priv = netdev_priv(pDevice->apdev);
79 *apdev_priv = *pDevice;
80 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
82 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
84 pDevice->apdev->type = ARPHRD_IEEE80211;
86 pDevice->apdev->base_addr = dev->base_addr;
87 pDevice->apdev->irq = dev->irq;
88 pDevice->apdev->mem_start = dev->mem_start;
89 pDevice->apdev->mem_end = dev->mem_end;
90 sprintf(pDevice->apdev->name, "%sap", dev->name);
91 if (rtnl_locked)
92 ret = register_netdevice(pDevice->apdev);
93 else
94 ret = register_netdev(pDevice->apdev);
95 if (ret) {
96 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: register_netdevice(AP) failed!\n",
97 dev->name);
98 return -1;
101 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Registered netdevice %s for AP management\n",
102 dev->name, pDevice->apdev->name);
104 KeyvInitTable(pDevice,&pDevice->sKey);
106 return 0;
110 * Description:
111 * unregister net_device(AP)
113 * Parameters:
114 * In:
115 * pDevice -
116 * rtnl_locked -
117 * Out:
119 * Return Value:
123 static int hostap_disable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
126 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: disabling hostapd mode\n", pDevice->dev->name);
128 if (pDevice->apdev && pDevice->apdev->name && pDevice->apdev->name[0]) {
129 if (rtnl_locked)
130 unregister_netdevice(pDevice->apdev);
131 else
132 unregister_netdev(pDevice->apdev);
133 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Netdevice %s unregistered\n",
134 pDevice->dev->name, pDevice->apdev->name);
136 free_netdev(pDevice->apdev);
137 pDevice->apdev = NULL;
138 pDevice->bEnable8021x = false;
139 pDevice->bEnableHostWEP = false;
140 pDevice->bEncryptionEnable = false;
142 return 0;
146 * Description:
147 * Set enable/disable hostapd mode
149 * Parameters:
150 * In:
151 * pDevice -
152 * rtnl_locked -
153 * Out:
155 * Return Value:
159 int vt6656_hostap_set_hostapd(struct vnt_private *pDevice,
160 int val, int rtnl_locked)
162 if (val < 0 || val > 1)
163 return -EINVAL;
165 if (pDevice->bEnableHostapd == val)
166 return 0;
168 pDevice->bEnableHostapd = val;
170 if (val)
171 return hostap_enable_hostapd(pDevice, rtnl_locked);
172 else
173 return hostap_disable_hostapd(pDevice, rtnl_locked);
177 * Description:
178 * remove station function supported for hostap daemon
180 * Parameters:
181 * In:
182 * pDevice -
183 * param -
184 * Out:
186 * Return Value:
189 static int hostap_remove_sta(struct vnt_private *pDevice,
190 struct viawget_hostapd_param *param)
192 unsigned int uNodeIndex;
194 if (BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &uNodeIndex)) {
195 BSSvRemoveOneNode(pDevice, uNodeIndex);
197 else {
198 return -ENOENT;
200 return 0;
204 * Description:
205 * add a station from hostap daemon
207 * Parameters:
208 * In:
209 * pDevice -
210 * param -
211 * Out:
213 * Return Value:
216 static int hostap_add_sta(struct vnt_private *pDevice,
217 struct viawget_hostapd_param *param)
219 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
220 unsigned int uNodeIndex;
222 if (!BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &uNodeIndex))
223 BSSvCreateOneNode(pDevice, &uNodeIndex);
225 memcpy(pMgmt->sNodeDBTable[uNodeIndex].abyMACAddr, param->sta_addr, WLAN_ADDR_LEN);
226 pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_ASSOC;
227 pMgmt->sNodeDBTable[uNodeIndex].wCapInfo = param->u.add_sta.capability;
228 // TODO listenInterval
229 // pMgmt->sNodeDBTable[uNodeIndex].wListenInterval = 1;
230 pMgmt->sNodeDBTable[uNodeIndex].bPSEnable = false;
231 pMgmt->sNodeDBTable[uNodeIndex].bySuppRate = param->u.add_sta.tx_supp_rates;
233 // set max tx rate
234 pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate =
235 pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate;
236 // set max basic rate
237 pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate = RATE_2M;
238 // Todo: check sta preamble, if ap can't support, set status code
239 pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble =
240 WLAN_GET_CAP_INFO_SHORTPREAMBLE(pMgmt->sNodeDBTable[uNodeIndex].wCapInfo);
242 pMgmt->sNodeDBTable[uNodeIndex].wAID = (u16)param->u.add_sta.aid;
244 pMgmt->sNodeDBTable[uNodeIndex].ulLastRxJiffer = jiffies;
246 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Add STA AID= %d \n", pMgmt->sNodeDBTable[uNodeIndex].wAID);
247 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "MAC=%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X \n",
248 param->sta_addr[0],
249 param->sta_addr[1],
250 param->sta_addr[2],
251 param->sta_addr[3],
252 param->sta_addr[4],
253 param->sta_addr[5]
255 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Max Support rate = %d \n",
256 pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate);
258 return 0;
262 * Description:
263 * get station info
265 * Parameters:
266 * In:
267 * pDevice -
268 * param -
269 * Out:
271 * Return Value:
275 static int hostap_get_info_sta(struct vnt_private *pDevice,
276 struct viawget_hostapd_param *param)
278 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
279 unsigned int uNodeIndex;
281 if (BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &uNodeIndex)) {
282 param->u.get_info_sta.inactive_sec =
283 (jiffies - pMgmt->sNodeDBTable[uNodeIndex].ulLastRxJiffer) / HZ;
285 //param->u.get_info_sta.txexc = pMgmt->sNodeDBTable[uNodeIndex].uTxAttempts;
287 else {
288 return -ENOENT;
291 return 0;
295 * Description:
296 * set station flag
298 * Parameters:
299 * In:
300 * pDevice -
301 * param -
302 * Out:
304 * Return Value:
307 static int hostap_set_flags_sta(struct vnt_private *pDevice,
308 struct viawget_hostapd_param *param)
310 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
311 unsigned int uNodeIndex;
313 if (BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &uNodeIndex)) {
314 pMgmt->sNodeDBTable[uNodeIndex].dwFlags |= param->u.set_flags_sta.flags_or;
315 pMgmt->sNodeDBTable[uNodeIndex].dwFlags &= param->u.set_flags_sta.flags_and;
316 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " dwFlags = %x\n",
317 (unsigned int) pMgmt->sNodeDBTable[uNodeIndex].dwFlags);
319 else {
320 return -ENOENT;
323 return 0;
327 * Description:
328 * set generic element (wpa ie)
330 * Parameters:
331 * In:
332 * pDevice -
333 * param -
334 * Out:
336 * Return Value:
339 static int hostap_set_generic_element(struct vnt_private *pDevice,
340 struct viawget_hostapd_param *param)
342 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
344 memcpy( pMgmt->abyWPAIE,
345 param->u.generic_elem.data,
346 param->u.generic_elem.len
349 pMgmt->wWPAIELen = param->u.generic_elem.len;
351 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pMgmt->wWPAIELen = %d\n", pMgmt->wWPAIELen);
353 // disable wpa
354 if (pMgmt->wWPAIELen == 0) {
355 pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
356 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " No WPAIE, Disable WPA \n");
357 } else {
358 // enable wpa
359 if ((pMgmt->abyWPAIE[0] == WLAN_EID_RSN_WPA) ||
360 (pMgmt->abyWPAIE[0] == WLAN_EID_RSN)) {
361 pMgmt->eAuthenMode = WMAC_AUTH_WPANONE;
362 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set WPAIE enable WPA\n");
363 } else
364 return -EINVAL;
367 return 0;
371 * Description:
372 * flush station nodes table.
374 * Parameters:
375 * In:
376 * pDevice -
377 * Out:
379 * Return Value:
383 static void hostap_flush_sta(struct vnt_private *pDevice)
385 // reserved node index =0 for multicast node.
386 BSSvClearNodeDBTable(pDevice, 1);
387 pDevice->uAssocCount = 0;
389 return;
393 * Description:
394 * set each stations encryption key
396 * Parameters:
397 * In:
398 * pDevice -
399 * param -
400 * Out:
402 * Return Value:
405 static int hostap_set_encryption(struct vnt_private *pDevice,
406 struct viawget_hostapd_param *param, int param_len)
408 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
409 u32 dwKeyIndex = 0;
410 u8 abyKey[MAX_KEY_LEN];
411 u8 abySeq[MAX_KEY_LEN];
412 NDIS_802_11_KEY_RSC KeyRSC;
413 u8 byKeyDecMode = KEY_CTL_WEP;
414 int ret = 0;
415 s32 iNodeIndex = -1;
416 int ii;
417 int bKeyTableFull = false;
418 u16 wKeyCtl = 0;
420 param->u.crypt.err = 0;
422 if (param->u.crypt.alg > WPA_ALG_CCMP)
423 return -EINVAL;
425 if ((param->u.crypt.idx > 3) || (param->u.crypt.key_len > MAX_KEY_LEN)) {
426 param->u.crypt.err = HOSTAP_CRYPT_ERR_KEY_SET_FAILED;
427 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " HOSTAP_CRYPT_ERR_KEY_SET_FAILED\n");
428 return -EINVAL;
431 if (is_broadcast_ether_addr(param->sta_addr)) {
432 if (param->u.crypt.idx >= MAX_GROUP_KEY)
433 return -EINVAL;
434 iNodeIndex = 0;
436 } else {
437 if (BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &iNodeIndex) == false) {
438 param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
439 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " HOSTAP_CRYPT_ERR_UNKNOWN_ADDR\n");
440 return -EINVAL;
443 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " hostap_set_encryption: sta_index %d \n", iNodeIndex);
444 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " hostap_set_encryption: alg %d \n", param->u.crypt.alg);
446 if (param->u.crypt.alg == WPA_ALG_NONE) {
448 if (pMgmt->sNodeDBTable[iNodeIndex].bOnFly == true) {
449 if (KeybRemoveKey( pDevice,
450 &(pDevice->sKey),
451 param->sta_addr,
452 pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex
453 ) == false) {
454 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "KeybRemoveKey fail \n");
456 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = false;
458 pMgmt->sNodeDBTable[iNodeIndex].byKeyIndex = 0;
459 pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex = 0;
460 pMgmt->sNodeDBTable[iNodeIndex].uWepKeyLength = 0;
461 pMgmt->sNodeDBTable[iNodeIndex].KeyRSC = 0;
462 pMgmt->sNodeDBTable[iNodeIndex].dwTSC47_16 = 0;
463 pMgmt->sNodeDBTable[iNodeIndex].wTSC15_0 = 0;
464 pMgmt->sNodeDBTable[iNodeIndex].byCipherSuite = 0;
465 memset(&pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[0],
467 MAX_KEY_LEN
470 return ret;
473 memcpy(abyKey, param->u.crypt.key, param->u.crypt.key_len);
474 // copy to node key tbl
475 pMgmt->sNodeDBTable[iNodeIndex].byKeyIndex = param->u.crypt.idx;
476 pMgmt->sNodeDBTable[iNodeIndex].uWepKeyLength = param->u.crypt.key_len;
477 memcpy(&pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[0],
478 param->u.crypt.key,
479 param->u.crypt.key_len
482 dwKeyIndex = (u32)(param->u.crypt.idx);
483 if (param->u.crypt.flags & HOSTAP_CRYPT_FLAG_SET_TX_KEY) {
484 pDevice->byKeyIndex = (u8)dwKeyIndex;
485 pDevice->bTransmitKey = true;
486 dwKeyIndex |= (1 << 31);
489 if (param->u.crypt.alg == WPA_ALG_WEP) {
491 if ((pDevice->bEnable8021x == false) || (iNodeIndex == 0)) {
492 KeybSetDefaultKey( pDevice,
493 &(pDevice->sKey),
494 dwKeyIndex & ~(BIT30 | USE_KEYRSC),
495 param->u.crypt.key_len,
496 NULL,
497 abyKey,
498 KEY_CTL_WEP
501 } else {
502 // 8021x enable, individual key
503 dwKeyIndex |= (1 << 30); // set pairwise key
504 if (KeybSetKey(pDevice, &(pDevice->sKey),
505 &param->sta_addr[0],
506 dwKeyIndex & ~(USE_KEYRSC),
507 param->u.crypt.key_len,
508 &KeyRSC, (u8 *)abyKey,
509 KEY_CTL_WEP
510 ) == true) {
512 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = true;
514 } else {
515 // Key Table Full
516 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = false;
517 bKeyTableFull = true;
520 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
521 pDevice->bEncryptionEnable = true;
522 pMgmt->byCSSPK = KEY_CTL_WEP;
523 pMgmt->byCSSGK = KEY_CTL_WEP;
524 pMgmt->sNodeDBTable[iNodeIndex].byCipherSuite = KEY_CTL_WEP;
525 pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex = dwKeyIndex;
526 return ret;
529 if (param->u.crypt.seq) {
530 memcpy(&abySeq, param->u.crypt.seq, 8);
531 for (ii = 0 ; ii < 8 ; ii++)
532 KeyRSC |= (unsigned long)abySeq[ii] << (ii * 8);
534 dwKeyIndex |= 1 << 29;
535 pMgmt->sNodeDBTable[iNodeIndex].KeyRSC = KeyRSC;
538 if (param->u.crypt.alg == WPA_ALG_TKIP) {
539 if (param->u.crypt.key_len != MAX_KEY_LEN)
540 return -EINVAL;
541 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
542 byKeyDecMode = KEY_CTL_TKIP;
543 pMgmt->byCSSPK = KEY_CTL_TKIP;
544 pMgmt->byCSSGK = KEY_CTL_TKIP;
547 if (param->u.crypt.alg == WPA_ALG_CCMP) {
548 if ((param->u.crypt.key_len != AES_KEY_LEN) ||
549 (pDevice->byLocalID <= REV_ID_VT3253_A1))
550 return -EINVAL;
551 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
552 byKeyDecMode = KEY_CTL_CCMP;
553 pMgmt->byCSSPK = KEY_CTL_CCMP;
554 pMgmt->byCSSGK = KEY_CTL_CCMP;
557 if (iNodeIndex == 0) {
558 KeybSetDefaultKey( pDevice,
559 &(pDevice->sKey),
560 dwKeyIndex,
561 param->u.crypt.key_len,
562 &KeyRSC,
563 abyKey,
564 byKeyDecMode
566 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = true;
568 } else {
569 dwKeyIndex |= (1 << 30); // set pairwise key
570 if (KeybSetKey(pDevice,
571 &(pDevice->sKey),
572 &param->sta_addr[0],
573 dwKeyIndex,
574 param->u.crypt.key_len,
575 &KeyRSC,
576 (u8 *)abyKey,
577 byKeyDecMode
578 ) == true) {
580 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = true;
582 } else {
583 // Key Table Full
584 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = false;
585 bKeyTableFull = true;
586 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Key Table Full\n");
591 if (bKeyTableFull == true) {
592 wKeyCtl &= 0x7F00; // clear all key control filed
593 wKeyCtl |= (byKeyDecMode << 4);
594 wKeyCtl |= (byKeyDecMode);
595 wKeyCtl |= 0x0044; // use group key for all address
596 wKeyCtl |= 0x4000; // disable KeyTable[MAX_KEY_TABLE-1] on-fly to genernate rx int
597 // Todo.. xxxxxx
598 //MACvSetDefaultKeyCtl(pDevice->PortOffset, wKeyCtl, MAX_KEY_TABLE-1, pDevice->byLocalID);
601 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Set key sta_index= %d \n", iNodeIndex);
602 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " tx_index=%d len=%d \n", param->u.crypt.idx,
603 param->u.crypt.key_len );
604 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " key=%x-%x-%x-%x-%x-xxxxx \n",
605 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[0],
606 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[1],
607 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[2],
608 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[3],
609 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[4]
612 // set wep key
613 pDevice->bEncryptionEnable = true;
614 pMgmt->sNodeDBTable[iNodeIndex].byCipherSuite = byKeyDecMode;
615 pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex = dwKeyIndex;
616 pMgmt->sNodeDBTable[iNodeIndex].dwTSC47_16 = 0;
617 pMgmt->sNodeDBTable[iNodeIndex].wTSC15_0 = 0;
619 return ret;
623 * Description:
624 * get each stations encryption key
626 * Parameters:
627 * In:
628 * pDevice -
629 * param -
630 * Out:
632 * Return Value:
635 static int hostap_get_encryption(struct vnt_private *pDevice,
636 struct viawget_hostapd_param *param,
637 int param_len)
639 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
640 int ret = 0;
641 int ii;
642 s32 iNodeIndex = 0;
644 param->u.crypt.err = 0;
646 if (is_broadcast_ether_addr(param->sta_addr)) {
647 iNodeIndex = 0;
648 } else {
649 if (BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &iNodeIndex) == false) {
650 param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
651 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "hostap_get_encryption: HOSTAP_CRYPT_ERR_UNKNOWN_ADDR\n");
652 return -EINVAL;
655 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "hostap_get_encryption: %d\n", iNodeIndex);
656 memset(param->u.crypt.seq, 0, 8);
657 for (ii = 0 ; ii < 8 ; ii++) {
658 param->u.crypt.seq[ii] = (u8)pMgmt->sNodeDBTable[iNodeIndex].KeyRSC >> (ii * 8);
661 return ret;
665 * Description:
666 * vt6656_hostap_ioctl main function supported for hostap daemon.
668 * Parameters:
669 * In:
670 * pDevice -
671 * iw_point -
672 * Out:
674 * Return Value:
678 int vt6656_hostap_ioctl(struct vnt_private *pDevice, struct iw_point *p)
680 struct viawget_hostapd_param *param;
681 int ret = 0;
682 int ap_ioctl = 0;
684 if (p->length < sizeof(struct viawget_hostapd_param) ||
685 p->length > VIAWGET_HOSTAPD_MAX_BUF_SIZE || !p->pointer)
686 return -EINVAL;
688 param = kmalloc((int)p->length, (int)GFP_KERNEL);
689 if (param == NULL)
690 return -ENOMEM;
692 if (copy_from_user(param, p->pointer, p->length)) {
693 ret = -EFAULT;
694 goto out;
697 switch (param->cmd) {
698 case VIAWGET_HOSTAPD_SET_ENCRYPTION:
699 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SET_ENCRYPTION \n");
700 spin_lock_irq(&pDevice->lock);
701 ret = hostap_set_encryption(pDevice, param, p->length);
702 spin_unlock_irq(&pDevice->lock);
703 break;
704 case VIAWGET_HOSTAPD_GET_ENCRYPTION:
705 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_GET_ENCRYPTION \n");
706 spin_lock_irq(&pDevice->lock);
707 ret = hostap_get_encryption(pDevice, param, p->length);
708 spin_unlock_irq(&pDevice->lock);
709 break;
710 case VIAWGET_HOSTAPD_SET_ASSOC_AP_ADDR:
711 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SET_ASSOC_AP_ADDR \n");
712 ret = -EOPNOTSUPP;
713 goto out;
714 case VIAWGET_HOSTAPD_FLUSH:
715 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_FLUSH \n");
716 spin_lock_irq(&pDevice->lock);
717 hostap_flush_sta(pDevice);
718 spin_unlock_irq(&pDevice->lock);
719 break;
720 case VIAWGET_HOSTAPD_ADD_STA:
721 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_ADD_STA \n");
722 spin_lock_irq(&pDevice->lock);
723 ret = hostap_add_sta(pDevice, param);
724 spin_unlock_irq(&pDevice->lock);
725 break;
726 case VIAWGET_HOSTAPD_REMOVE_STA:
727 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_REMOVE_STA \n");
728 spin_lock_irq(&pDevice->lock);
729 ret = hostap_remove_sta(pDevice, param);
730 spin_unlock_irq(&pDevice->lock);
731 break;
732 case VIAWGET_HOSTAPD_GET_INFO_STA:
733 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_GET_INFO_STA \n");
734 ret = hostap_get_info_sta(pDevice, param);
735 ap_ioctl = 1;
736 break;
737 case VIAWGET_HOSTAPD_SET_FLAGS_STA:
738 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SET_FLAGS_STA \n");
739 ret = hostap_set_flags_sta(pDevice, param);
740 break;
742 case VIAWGET_HOSTAPD_MLME:
743 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_MLME \n");
744 return -EOPNOTSUPP;
746 case VIAWGET_HOSTAPD_SET_GENERIC_ELEMENT:
747 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SET_GENERIC_ELEMENT \n");
748 ret = hostap_set_generic_element(pDevice, param);
749 break;
751 case VIAWGET_HOSTAPD_SCAN_REQ:
752 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SCAN_REQ \n");
753 return -EOPNOTSUPP;
755 case VIAWGET_HOSTAPD_STA_CLEAR_STATS:
756 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_STA_CLEAR_STATS \n");
757 ret = -EOPNOTSUPP;
758 goto out;
759 default:
760 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "vt6656_hostap_ioctl: unknown cmd=%d\n",
761 (int)param->cmd);
762 ret = -EOPNOTSUPP;
763 goto out;
766 if ((ret == 0) && ap_ioctl) {
767 if (copy_to_user(p->pointer, param, p->length)) {
768 ret = -EFAULT;
769 goto out;
773 out:
774 kfree(param);
776 return ret;