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