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