]> Pileus Git - ~andy/linux/blob - drivers/staging/vt6655/hostap.c
staging:vt6655:rc4: Whitespace cleanups
[~andy/linux] / drivers / staging / vt6655 / 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
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
45
46 /*---------------------  Static Definitions -------------------------*/
47
48 /*---------------------  Static Classes  ----------------------------*/
49
50 /*---------------------  Static Variables  --------------------------*/
51 //static int          msglevel                =MSG_LEVEL_DEBUG;
52 static int msglevel = MSG_LEVEL_INFO;
53
54 /*---------------------  Static Functions  --------------------------*/
55
56
57
58
59 /*---------------------  Export Variables  --------------------------*/
60
61
62 /*
63  * Description:
64  *      register net_device (AP) for hostap deamon
65  *
66  * Parameters:
67  *  In:
68  *      pDevice             -
69  *      rtnl_locked         -
70  *  Out:
71  *
72  * Return Value:
73  *
74  */
75
76 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
77 {
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,
83         };
84
85         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
86
87         pDevice->apdev = kzalloc(sizeof(struct net_device), GFP_KERNEL);
88         if (pDevice->apdev == NULL)
89                 return -ENOMEM;
90
91         apdev_priv = netdev_priv(pDevice->apdev);
92         *apdev_priv = *pDevice;
93         memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
94
95         pDevice->apdev->netdev_ops = &apdev_netdev_ops;
96
97         pDevice->apdev->type = ARPHRD_IEEE80211;
98
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;
112         }
113
114         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Registered netdevice %s for AP management\n",
115                 dev->name, pDevice->apdev->name);
116
117         KeyvInitTable(&pDevice->sKey, pDevice->PortOffset);
118
119         return 0;
120 }
121
122 /*
123  * Description:
124  *      unregister net_device(AP)
125  *
126  * Parameters:
127  *  In:
128  *      pDevice             -
129  *      rtnl_locked         -
130  *  Out:
131  *
132  * Return Value:
133  *
134  */
135
136 static int hostap_disable_hostapd(PSDevice pDevice, int rtnl_locked)
137 {
138
139         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: disabling hostapd mode\n", pDevice->dev->name);
140
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);
148         }
149         kfree(pDevice->apdev);
150         pDevice->apdev = NULL;
151         pDevice->bEnable8021x = false;
152         pDevice->bEnableHostWEP = false;
153         pDevice->bEncryptionEnable = false;
154
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);
160
161         return 0;
162 }
163
164
165 /*
166  * Description:
167  *      Set enable/disable hostapd mode
168  *
169  * Parameters:
170  *  In:
171  *      pDevice             -
172  *      rtnl_locked         -
173  *  Out:
174  *
175  * Return Value:
176  *
177  */
178
179 int vt6655_hostap_set_hostapd(PSDevice pDevice, int val, int rtnl_locked)
180 {
181         if (val < 0 || val > 1)
182                 return -EINVAL;
183
184         if (pDevice->bEnableHostapd == val)
185                 return 0;
186
187         pDevice->bEnableHostapd = val;
188
189         if (val)
190                 return hostap_enable_hostapd(pDevice, rtnl_locked);
191         else
192                 return hostap_disable_hostapd(pDevice, rtnl_locked);
193 }
194
195
196 /*
197  * Description:
198  *      remove station function supported for hostap deamon
199  *
200  * Parameters:
201  *  In:
202  *      pDevice   -
203  *      param     -
204  *  Out:
205  *
206  * Return Value:
207  *
208  */
209 static int hostap_remove_sta(PSDevice pDevice,
210                              struct viawget_hostapd_param *param)
211 {
212         unsigned int uNodeIndex;
213
214
215         if (BSSDBbIsSTAInNodeDB(pDevice->pMgmt, param->sta_addr, &uNodeIndex)) {
216                 BSSvRemoveOneNode(pDevice, uNodeIndex);
217         }
218         else {
219                 return -ENOENT;
220         }
221         return 0;
222 }
223
224 /*
225  * Description:
226  *      add a station from hostap deamon
227  *
228  * Parameters:
229  *  In:
230  *      pDevice   -
231  *      param     -
232  *  Out:
233  *
234  * Return Value:
235  *
236  */
237 static int hostap_add_sta(PSDevice pDevice,
238                           struct viawget_hostapd_param *param)
239 {
240         PSMgmtObject    pMgmt = pDevice->pMgmt;
241         unsigned int uNodeIndex;
242
243
244         if (!BSSDBbIsSTAInNodeDB(pMgmt, param->sta_addr, &uNodeIndex)) {
245                 BSSvCreateOneNode((PSDevice)pDevice, &uNodeIndex);
246         }
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;
254
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);
263
264         pMgmt->sNodeDBTable[uNodeIndex].wAID = (unsigned short)param->u.add_sta.aid;
265
266         pMgmt->sNodeDBTable[uNodeIndex].ulLastRxJiffer = jiffies;
267
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]
276                 );
277         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Max Support rate = %d \n",
278                 pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate);
279
280         return 0;
281 }
282
283 /*
284  * Description:
285  *      get station info
286  *
287  * Parameters:
288  *  In:
289  *      pDevice   -
290  *      param     -
291  *  Out:
292  *
293  * Return Value:
294  *
295  */
296
297 static int hostap_get_info_sta(PSDevice pDevice,
298                                struct viawget_hostapd_param *param)
299 {
300         PSMgmtObject    pMgmt = pDevice->pMgmt;
301         unsigned int uNodeIndex;
302
303         if (BSSDBbIsSTAInNodeDB(pMgmt, param->sta_addr, &uNodeIndex)) {
304                 param->u.get_info_sta.inactive_sec =
305                         (jiffies - pMgmt->sNodeDBTable[uNodeIndex].ulLastRxJiffer) / HZ;
306
307                 //param->u.get_info_sta.txexc = pMgmt->sNodeDBTable[uNodeIndex].uTxAttempts;
308         }
309         else {
310                 return -ENOENT;
311         }
312
313         return 0;
314 }
315
316 /*
317  * Description:
318  *      reset txexec
319  *
320  * Parameters:
321  *  In:
322  *      pDevice   -
323  *      param     -
324  *  Out:
325  *      true, false
326  *
327  * Return Value:
328  *
329  */
330 /*
331   static int hostap_reset_txexc_sta(PSDevice pDevice,
332   struct viawget_hostapd_param *param)
333   {
334   PSMgmtObject    pMgmt = pDevice->pMgmt;
335   unsigned int uNodeIndex;
336
337   if (BSSDBbIsSTAInNodeDB(pMgmt, param->sta_addr, &uNodeIndex)) {
338   pMgmt->sNodeDBTable[uNodeIndex].uTxAttempts = 0;
339   }
340   else {
341   return -ENOENT;
342   }
343
344   return 0;
345   }
346 */
347
348 /*
349  * Description:
350  *      set station flag
351  *
352  * Parameters:
353  *  In:
354  *      pDevice   -
355  *      param     -
356  *  Out:
357  *
358  * Return Value:
359  *
360  */
361 static int hostap_set_flags_sta(PSDevice pDevice,
362                                 struct viawget_hostapd_param *param)
363 {
364         PSMgmtObject    pMgmt = pDevice->pMgmt;
365         unsigned int uNodeIndex;
366
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);
372         }
373         else {
374                 return -ENOENT;
375         }
376
377         return 0;
378 }
379
380
381
382 /*
383  * Description:
384  *      set generic element (wpa ie)
385  *
386  * Parameters:
387  *  In:
388  *      pDevice   -
389  *      param     -
390  *  Out:
391  *
392  * Return Value:
393  *
394  */
395 static int hostap_set_generic_element(PSDevice pDevice,
396                                       struct viawget_hostapd_param *param)
397 {
398         PSMgmtObject    pMgmt = pDevice->pMgmt;
399
400
401
402         memcpy(pMgmt->abyWPAIE,
403                param->u.generic_elem.data,
404                param->u.generic_elem.len
405                 );
406
407         pMgmt->wWPAIELen = param->u.generic_elem.len;
408
409         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pMgmt->wWPAIELen = %d\n", pMgmt->wWPAIELen);
410
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;
423         }
424
425         return 0;
426 }
427
428 /*
429  * Description:
430  *      flush station nodes table.
431  *
432  * Parameters:
433  *  In:
434  *      pDevice   -
435  *  Out:
436  *
437  * Return Value:
438  *
439  */
440
441 static void hostap_flush_sta(PSDevice pDevice)
442 {
443         // reserved node index =0 for multicast node.
444         BSSvClearNodeDBTable(pDevice, 1);
445         pDevice->uAssocCount = 0;
446
447         return;
448 }
449
450 /*
451  * Description:
452  *      set each stations encryption key
453  *
454  * Parameters:
455  *  In:
456  *      pDevice   -
457  *      param     -
458  *  Out:
459  *
460  * Return Value:
461  *
462  */
463 static int hostap_set_encryption(PSDevice pDevice,
464                                  struct viawget_hostapd_param *param,
465                                  int param_len)
466 {
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;
478
479
480         param->u.crypt.err = 0;
481 /*
482   if (param_len !=
483   (int) ((char *) param->u.crypt.key - (char *) param) +
484   param->u.crypt.key_len)
485   return -EINVAL;
486 */
487
488         if (param->u.crypt.alg > WPA_ALG_CCMP)
489                 return -EINVAL;
490
491
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;
496         }
497
498         if (is_broadcast_ether_addr(param->sta_addr)) {
499                 if (param->u.crypt.idx >= MAX_GROUP_KEY)
500                         return -EINVAL;
501                 iNodeIndex = 0;
502
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;
508                 }
509         }
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);
512
513         if (param->u.crypt.alg == WPA_ALG_NONE) {
514
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");
521                         }
522                         pMgmt->sNodeDBTable[iNodeIndex].bOnFly = false;
523                 }
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],
532                        0,
533                        MAX_KEY_LEN
534 );
535
536                 return ret;
537         }
538
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
546 );
547
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);
553         }
554
555         if (param->u.crypt.alg == WPA_ALG_WEP) {
556
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);
566
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) {
579
580                                 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = true;
581
582                         } else {
583                                 // Key Table Full
584                                 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = false;
585                                 bKeyTableFull = true;
586                         }
587                 }
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;
595         }
596
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);
601
602                 dwKeyIndex |= 1 << 29;
603                 pMgmt->sNodeDBTable[iNodeIndex].KeyRSC = KeyRSC;
604         }
605
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;
613         }
614
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;
623         }
624
625
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;
636
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) {
648
649                         pMgmt->sNodeDBTable[iNodeIndex].bOnFly = true;
650
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");
656                 }
657
658         }
659
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);
667         }
668
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]
678 );
679
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;
686
687         return ret;
688 }
689
690
691
692 /*
693  * Description:
694  *      get each stations encryption key
695  *
696  * Parameters:
697  *  In:
698  *      pDevice   -
699  *      param     -
700  *  Out:
701  *
702  * Return Value:
703  *
704  */
705 static int hostap_get_encryption(PSDevice pDevice,
706                                  struct viawget_hostapd_param *param,
707                                  int param_len)
708 {
709         PSMgmtObject    pMgmt = pDevice->pMgmt;
710         int     ret = 0;
711         int     ii;
712         int     iNodeIndex = 0;
713
714
715         param->u.crypt.err = 0;
716
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;
724                 }
725         }
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);
730         }
731
732         return ret;
733 }
734
735
736 /*
737  * Description:
738  *      vt6655_hostap_ioctl main function supported for hostap deamon.
739  *
740  * Parameters:
741  *  In:
742  *      pDevice   -
743  *      iw_point  -
744  *  Out:
745  *
746  * Return Value:
747  *
748  */
749
750 int vt6655_hostap_ioctl(PSDevice pDevice, struct iw_point *p)
751 {
752         struct viawget_hostapd_param *param;
753         int ret = 0;
754         int ap_ioctl = 0;
755
756         if (p->length < sizeof(struct viawget_hostapd_param) ||
757             p->length > VIAWGET_HOSTAPD_MAX_BUF_SIZE || !p->pointer)
758                 return -EINVAL;
759
760         param = kmalloc((int)p->length, (int)GFP_KERNEL);
761         if (param == NULL)
762                 return -ENOMEM;
763
764         if (copy_from_user(param, p->pointer, p->length)) {
765                 ret = -EFAULT;
766                 goto out;
767         }
768
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;
809 /*
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;
814 */
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;
819
820         case VIAWGET_HOSTAPD_MLME:
821                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_MLME \n");
822                 return -EOPNOTSUPP;
823
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;
828
829         case VIAWGET_HOSTAPD_SCAN_REQ:
830                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SCAN_REQ \n");
831                 return -EOPNOTSUPP;
832
833         case VIAWGET_HOSTAPD_STA_CLEAR_STATS:
834                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_STA_CLEAR_STATS \n");
835                 return -EOPNOTSUPP;
836
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;
842         }
843
844
845         if ((ret == 0) && ap_ioctl) {
846                 if (copy_to_user(p->pointer, param, p->length)) {
847                         ret = -EFAULT;
848                         goto out;
849                 }
850         }
851
852 out:
853         kfree(param);
854
855         return ret;
856 }
857