Merge branch 'slab/next' into slab/for-linus
[firefly-linux-kernel-4.4.55.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 daemon 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 daemon
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(struct vnt_private *pDevice, int rtnl_locked)
64 {
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,
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(struct vnt_private *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(struct vnt_private *pDevice,
161         int val, int rtnl_locked)
162 {
163         if (val < 0 || val > 1)
164                 return -EINVAL;
165
166         if (pDevice->bEnableHostapd == val)
167                 return 0;
168
169         pDevice->bEnableHostapd = val;
170
171         if (val)
172                 return hostap_enable_hostapd(pDevice, rtnl_locked);
173         else
174                 return hostap_disable_hostapd(pDevice, rtnl_locked);
175 }
176
177
178 /*
179  * Description:
180  *      remove station function supported for hostap daemon
181  *
182  * Parameters:
183  *  In:
184  *      pDevice   -
185  *      param     -
186  *  Out:
187  *
188  * Return Value:
189  *
190  */
191 static int hostap_remove_sta(struct vnt_private *pDevice,
192         struct viawget_hostapd_param *param)
193 {
194         unsigned int uNodeIndex;
195
196
197     if (BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &uNodeIndex)) {
198         BSSvRemoveOneNode(pDevice, uNodeIndex);
199     }
200     else {
201         return -ENOENT;
202     }
203         return 0;
204 }
205
206 /*
207  * Description:
208  *      add a station from hostap daemon
209  *
210  * Parameters:
211  *  In:
212  *      pDevice   -
213  *      param     -
214  *  Out:
215  *
216  * Return Value:
217  *
218  */
219 static int hostap_add_sta(struct vnt_private *pDevice,
220         struct viawget_hostapd_param *param)
221 {
222         struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
223         unsigned int uNodeIndex;
224
225         if (!BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &uNodeIndex))
226                 BSSvCreateOneNode(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(struct vnt_private *pDevice,
279         struct viawget_hostapd_param *param)
280 {
281         struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
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(struct vnt_private *pDevice,
312                 struct viawget_hostapd_param *param)
313 {
314         struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
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(struct vnt_private *pDevice,
346                                         struct viawget_hostapd_param *param)
347 {
348         struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
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(struct vnt_private *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(struct vnt_private *pDevice,
414         struct viawget_hostapd_param *param, int param_len)
415 {
416         struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
417         u32 dwKeyIndex = 0;
418         u8 abyKey[MAX_KEY_LEN];
419         u8 abySeq[MAX_KEY_LEN];
420         NDIS_802_11_KEY_RSC   KeyRSC;
421         u8 byKeyDecMode = KEY_CTL_WEP;
422         int ret = 0;
423         s32 iNodeIndex = -1;
424         int ii;
425         int bKeyTableFull = false;
426         u16 wKeyCtl = 0;
427
428
429         param->u.crypt.err = 0;
430
431         if (param->u.crypt.alg > WPA_ALG_CCMP)
432                 return -EINVAL;
433
434
435         if ((param->u.crypt.idx > 3) || (param->u.crypt.key_len > MAX_KEY_LEN)) {
436                 param->u.crypt.err = HOSTAP_CRYPT_ERR_KEY_SET_FAILED;
437                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " HOSTAP_CRYPT_ERR_KEY_SET_FAILED\n");
438                 return -EINVAL;
439         }
440
441         if (is_broadcast_ether_addr(param->sta_addr)) {
442                 if (param->u.crypt.idx >= MAX_GROUP_KEY)
443                         return -EINVAL;
444         iNodeIndex = 0;
445
446         } else {
447             if (BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &iNodeIndex) == false) {
448                 param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
449             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " HOSTAP_CRYPT_ERR_UNKNOWN_ADDR\n");
450                 return -EINVAL;
451             }
452         }
453     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " hostap_set_encryption: sta_index %d \n", iNodeIndex);
454     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " hostap_set_encryption: alg %d \n", param->u.crypt.alg);
455
456         if (param->u.crypt.alg == WPA_ALG_NONE) {
457
458         if (pMgmt->sNodeDBTable[iNodeIndex].bOnFly == true) {
459             if (KeybRemoveKey( pDevice,
460                                &(pDevice->sKey),
461                                param->sta_addr,
462                                pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex
463                               ) == false) {
464                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "KeybRemoveKey fail \n");
465             }
466             pMgmt->sNodeDBTable[iNodeIndex].bOnFly = false;
467         }
468         pMgmt->sNodeDBTable[iNodeIndex].byKeyIndex = 0;
469         pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex = 0;
470         pMgmt->sNodeDBTable[iNodeIndex].uWepKeyLength = 0;
471         pMgmt->sNodeDBTable[iNodeIndex].KeyRSC = 0;
472         pMgmt->sNodeDBTable[iNodeIndex].dwTSC47_16 = 0;
473         pMgmt->sNodeDBTable[iNodeIndex].wTSC15_0 = 0;
474         pMgmt->sNodeDBTable[iNodeIndex].byCipherSuite = 0;
475         memset(&pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[0],
476                 0,
477                 MAX_KEY_LEN
478                );
479
480         return ret;
481         }
482
483     memcpy(abyKey, param->u.crypt.key, param->u.crypt.key_len);
484     // copy to node key tbl
485     pMgmt->sNodeDBTable[iNodeIndex].byKeyIndex = param->u.crypt.idx;
486     pMgmt->sNodeDBTable[iNodeIndex].uWepKeyLength = param->u.crypt.key_len;
487     memcpy(&pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[0],
488             param->u.crypt.key,
489             param->u.crypt.key_len
490            );
491
492     dwKeyIndex = (DWORD)(param->u.crypt.idx);
493     if (param->u.crypt.flags & HOSTAP_CRYPT_FLAG_SET_TX_KEY) {
494         pDevice->byKeyIndex = (BYTE)dwKeyIndex;
495         pDevice->bTransmitKey = true;
496         dwKeyIndex |= (1 << 31);
497     }
498
499         if (param->u.crypt.alg == WPA_ALG_WEP) {
500
501         if ((pDevice->bEnable8021x == false) || (iNodeIndex == 0)) {
502             KeybSetDefaultKey(  pDevice,
503                                 &(pDevice->sKey),
504                                 dwKeyIndex & ~(BIT30 | USE_KEYRSC),
505                                 param->u.crypt.key_len,
506                                 NULL,
507                                 abyKey,
508                                 KEY_CTL_WEP
509                              );
510
511         } else {
512             // 8021x enable, individual key
513             dwKeyIndex |= (1 << 30); // set pairwise key
514                 if (KeybSetKey(pDevice, &(pDevice->sKey),
515                         &param->sta_addr[0],
516                         dwKeyIndex & ~(USE_KEYRSC),
517                         param->u.crypt.key_len,
518                         &KeyRSC, (PBYTE)abyKey,
519                         KEY_CTL_WEP
520                            ) == true) {
521
522
523                 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = true;
524
525             } else {
526                 // Key Table Full
527                 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = false;
528                 bKeyTableFull = true;
529             }
530         }
531         pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
532         pDevice->bEncryptionEnable = true;
533         pMgmt->byCSSPK = KEY_CTL_WEP;
534         pMgmt->byCSSGK = KEY_CTL_WEP;
535         pMgmt->sNodeDBTable[iNodeIndex].byCipherSuite = KEY_CTL_WEP;
536         pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex = dwKeyIndex;
537         return ret;
538         }
539
540         if (param->u.crypt.seq) {
541             memcpy(&abySeq, param->u.crypt.seq, 8);
542                 for (ii = 0 ; ii < 8 ; ii++)
543                         KeyRSC |= (unsigned long)abySeq[ii] << (ii * 8);
544
545                 dwKeyIndex |= 1 << 29;
546                 pMgmt->sNodeDBTable[iNodeIndex].KeyRSC = KeyRSC;
547         }
548
549         if (param->u.crypt.alg == WPA_ALG_TKIP) {
550             if (param->u.crypt.key_len != MAX_KEY_LEN)
551                 return -EINVAL;
552             pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
553         byKeyDecMode = KEY_CTL_TKIP;
554         pMgmt->byCSSPK = KEY_CTL_TKIP;
555         pMgmt->byCSSGK = KEY_CTL_TKIP;
556         }
557
558         if (param->u.crypt.alg == WPA_ALG_CCMP) {
559             if ((param->u.crypt.key_len != AES_KEY_LEN) ||
560                 (pDevice->byLocalID <= REV_ID_VT3253_A1))
561                 return -EINVAL;
562         pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
563         byKeyDecMode = KEY_CTL_CCMP;
564         pMgmt->byCSSPK = KEY_CTL_CCMP;
565         pMgmt->byCSSGK = KEY_CTL_CCMP;
566     }
567
568
569     if (iNodeIndex == 0) {
570        KeybSetDefaultKey(  pDevice,
571                            &(pDevice->sKey),
572                            dwKeyIndex,
573                            param->u.crypt.key_len,
574                         &KeyRSC,
575                            abyKey,
576                            byKeyDecMode
577                           );
578        pMgmt->sNodeDBTable[iNodeIndex].bOnFly = true;
579
580     } else {
581         dwKeyIndex |= (1 << 30); // set pairwise key
582         if (KeybSetKey(pDevice,
583                        &(pDevice->sKey),
584                        &param->sta_addr[0],
585                        dwKeyIndex,
586                        param->u.crypt.key_len,
587                         &KeyRSC,
588                        (PBYTE)abyKey,
589                         byKeyDecMode
590                        ) == true) {
591
592             pMgmt->sNodeDBTable[iNodeIndex].bOnFly = true;
593
594         } else {
595             // Key Table Full
596             pMgmt->sNodeDBTable[iNodeIndex].bOnFly = false;
597             bKeyTableFull = true;
598             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Key Table Full\n");
599         }
600
601     }
602
603     if (bKeyTableFull == true) {
604         wKeyCtl &= 0x7F00;              // clear all key control filed
605         wKeyCtl |= (byKeyDecMode << 4);
606         wKeyCtl |= (byKeyDecMode);
607         wKeyCtl |= 0x0044;              // use group key for all address
608         wKeyCtl |= 0x4000;              // disable KeyTable[MAX_KEY_TABLE-1] on-fly to genernate rx int
609 // Todo.. xxxxxx
610         //MACvSetDefaultKeyCtl(pDevice->PortOffset, wKeyCtl, MAX_KEY_TABLE-1, pDevice->byLocalID);
611     }
612
613     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Set key sta_index= %d \n", iNodeIndex);
614     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " tx_index=%d len=%d \n", param->u.crypt.idx,
615                param->u.crypt.key_len );
616     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " key=%x-%x-%x-%x-%x-xxxxx \n",
617                pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[0],
618                pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[1],
619                pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[2],
620                pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[3],
621                pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[4]
622               );
623
624         // set wep key
625     pDevice->bEncryptionEnable = true;
626     pMgmt->sNodeDBTable[iNodeIndex].byCipherSuite = byKeyDecMode;
627     pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex = dwKeyIndex;
628     pMgmt->sNodeDBTable[iNodeIndex].dwTSC47_16 = 0;
629     pMgmt->sNodeDBTable[iNodeIndex].wTSC15_0 = 0;
630
631         return ret;
632 }
633
634
635
636 /*
637  * Description:
638  *      get each stations encryption key
639  *
640  * Parameters:
641  *  In:
642  *      pDevice   -
643  *      param     -
644  *  Out:
645  *
646  * Return Value:
647  *
648  */
649 static int hostap_get_encryption(struct vnt_private *pDevice,
650                                        struct viawget_hostapd_param *param,
651                                        int param_len)
652 {
653         struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
654         int ret = 0;
655         int ii;
656         s32 iNodeIndex = 0;
657
658
659         param->u.crypt.err = 0;
660
661         if (is_broadcast_ether_addr(param->sta_addr)) {
662         iNodeIndex = 0;
663         } else {
664             if (BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &iNodeIndex) == false) {
665                 param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
666             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "hostap_get_encryption: HOSTAP_CRYPT_ERR_UNKNOWN_ADDR\n");
667                 return -EINVAL;
668             }
669         }
670         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "hostap_get_encryption: %d\n", iNodeIndex);
671     memset(param->u.crypt.seq, 0, 8);
672     for (ii = 0 ; ii < 8 ; ii++) {
673         param->u.crypt.seq[ii] = (BYTE)pMgmt->sNodeDBTable[iNodeIndex].KeyRSC >> (ii * 8);
674     }
675
676         return ret;
677 }
678
679
680 /*
681  * Description:
682  *      vt6656_hostap_ioctl main function supported for hostap daemon.
683  *
684  * Parameters:
685  *  In:
686  *      pDevice   -
687  *      iw_point  -
688  *  Out:
689  *
690  * Return Value:
691  *
692  */
693
694 int vt6656_hostap_ioctl(struct vnt_private *pDevice, struct iw_point *p)
695 {
696         struct viawget_hostapd_param *param;
697         int ret = 0;
698         int ap_ioctl = 0;
699
700         if (p->length < sizeof(struct viawget_hostapd_param) ||
701             p->length > VIAWGET_HOSTAPD_MAX_BUF_SIZE || !p->pointer)
702                 return -EINVAL;
703
704         param = kmalloc((int)p->length, (int)GFP_KERNEL);
705         if (param == NULL)
706                 return -ENOMEM;
707
708         if (copy_from_user(param, p->pointer, p->length)) {
709                 ret = -EFAULT;
710                 goto out;
711         }
712
713         switch (param->cmd) {
714         case VIAWGET_HOSTAPD_SET_ENCRYPTION:
715             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SET_ENCRYPTION \n");
716         spin_lock_irq(&pDevice->lock);
717                 ret = hostap_set_encryption(pDevice, param, p->length);
718         spin_unlock_irq(&pDevice->lock);
719                 break;
720         case VIAWGET_HOSTAPD_GET_ENCRYPTION:
721             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_GET_ENCRYPTION \n");
722         spin_lock_irq(&pDevice->lock);
723                 ret = hostap_get_encryption(pDevice, param, p->length);
724         spin_unlock_irq(&pDevice->lock);
725                 break;
726         case VIAWGET_HOSTAPD_SET_ASSOC_AP_ADDR:
727             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SET_ASSOC_AP_ADDR \n");
728                 ret = -EOPNOTSUPP;
729                 goto out;
730         case VIAWGET_HOSTAPD_FLUSH:
731             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_FLUSH \n");
732         spin_lock_irq(&pDevice->lock);
733         hostap_flush_sta(pDevice);
734         spin_unlock_irq(&pDevice->lock);
735                 break;
736         case VIAWGET_HOSTAPD_ADD_STA:
737             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_ADD_STA \n");
738          spin_lock_irq(&pDevice->lock);
739                  ret = hostap_add_sta(pDevice, param);
740          spin_unlock_irq(&pDevice->lock);
741                 break;
742         case VIAWGET_HOSTAPD_REMOVE_STA:
743             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_REMOVE_STA \n");
744          spin_lock_irq(&pDevice->lock);
745                  ret = hostap_remove_sta(pDevice, param);
746          spin_unlock_irq(&pDevice->lock);
747                 break;
748         case VIAWGET_HOSTAPD_GET_INFO_STA:
749             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_GET_INFO_STA \n");
750                  ret = hostap_get_info_sta(pDevice, param);
751                  ap_ioctl = 1;
752                 break;
753         case VIAWGET_HOSTAPD_SET_FLAGS_STA:
754             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SET_FLAGS_STA \n");
755                  ret = hostap_set_flags_sta(pDevice, param);
756                 break;
757
758         case VIAWGET_HOSTAPD_MLME:
759             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_MLME \n");
760             return -EOPNOTSUPP;
761
762         case VIAWGET_HOSTAPD_SET_GENERIC_ELEMENT:
763             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SET_GENERIC_ELEMENT \n");
764                 ret = hostap_set_generic_element(pDevice, param);
765                 break;
766
767         case VIAWGET_HOSTAPD_SCAN_REQ:
768             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SCAN_REQ \n");
769             return -EOPNOTSUPP;
770
771         case VIAWGET_HOSTAPD_STA_CLEAR_STATS:
772             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_STA_CLEAR_STATS \n");
773             ret = -EOPNOTSUPP;
774             goto out;
775         default:
776             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "vt6656_hostap_ioctl: unknown cmd=%d\n",
777                        (int)param->cmd);
778                 ret = -EOPNOTSUPP;
779                 goto out;
780         }
781
782
783         if ((ret == 0) && ap_ioctl) {
784                 if (copy_to_user(p->pointer, param, p->length)) {
785                         ret = -EFAULT;
786                         goto out;
787                 }
788         }
789
790  out:
791         kfree(param);
792
793         return ret;
794 }
795