Staging: vt665x: Text janitor in prep for driver merge, part 2
[safe/jmp/linux-2.6] / drivers / staging / vt6655 / ioctl.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: ioctl.c
20  *
21  * Purpose:  private ioctl functions
22  *
23  * Author: Lyndon Chen
24  *
25  * Date: Auguest 20, 2003
26  *
27  * Functions:
28  *
29  * Revision History:
30  *
31  */
32
33
34 #if !defined(__IOCTL_H__)
35 #include "ioctl.h"
36 #endif
37 #if !defined(__IOCMD_H__)
38 #include "iocmd.h"
39 #endif
40 #if !defined(__MAC_H__)
41 #include "mac.h"
42 #endif
43 #if !defined(__CARD_H__)
44 #include "card.h"
45 #endif
46 #if !defined(__HOSTAP_H__)
47 #include "hostap.h"
48 #endif
49 #if !defined(__UMEM_H__)
50 #include "umem.h"
51 #endif
52 #if !defined(__WPACTL_H__)
53 #include "wpactl.h"
54 #endif
55 #if !defined(__RF_H__)
56 #include "rf.h"
57 #endif
58
59
60 /*---------------------  Static Definitions -------------------------*/
61
62 /*---------------------  Static Classes  ----------------------------*/
63
64 /*---------------------  Static Variables  --------------------------*/
65 //static int          msglevel                =MSG_LEVEL_DEBUG;
66 static int          msglevel                =MSG_LEVEL_INFO;
67
68 #ifdef WPA_SM_Transtatus
69     SWPAResult wpa_Result;
70 #endif
71
72 /*---------------------  Static Functions  --------------------------*/
73
74 /*---------------------  Export Variables  --------------------------*/
75
76 int private_ioctl(PSDevice pDevice, struct ifreq *rq) {
77
78         PSCmdRequest        pReq = (PSCmdRequest)rq;
79     PSMgmtObject        pMgmt = pDevice->pMgmt;
80         int                     result = 0;
81     PWLAN_IE_SSID       pItemSSID;
82     SCmdBSSJoin         sJoinCmd;
83     SCmdZoneTypeSet  sZoneTypeCmd;
84     SCmdScan            sScanCmd;
85     SCmdStartAP         sStartAPCmd;
86     SCmdSetWEP          sWEPCmd;
87     SCmdValue           sValue;
88     SBSSIDList          sList;
89     SNodeList           sNodeList;
90     PSBSSIDList         pList;
91     PSNodeList          pNodeList;
92     UINT                cbListCount;
93     PKnownBSS           pBSS;
94     PKnownNodeDB        pNode;
95     UINT                ii, jj;
96     SCmdLinkStatus      sLinkStatus;
97     BYTE                abySuppRates[] = {WLAN_EID_SUPP_RATES, 4, 0x02, 0x04, 0x0B, 0x16};
98     BYTE                abyNullAddr[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
99     DWORD               dwKeyIndex= 0;
100     BYTE                abyScanSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
101     LONG                ldBm;
102
103     pReq->wResult = 0;
104
105     switch(pReq->wCmdCode) {
106
107     case WLAN_CMD_BSS_SCAN:
108
109         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_BSS_SCAN..begin \n");
110         if (copy_from_user(&sScanCmd, pReq->data, sizeof(SCmdScan))) {
111                         result = -EFAULT;
112                         break;
113                 };
114
115         pItemSSID = (PWLAN_IE_SSID)sScanCmd.ssid;
116         if (pItemSSID->len != 0) {
117             memset(abyScanSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
118             memcpy(abyScanSSID, pItemSSID, pItemSSID->len + WLAN_IEHDR_LEN);
119         }
120
121         if (pDevice->bMACSuspend == TRUE) {
122             if (pDevice->bRadioOff == TRUE)
123                 CARDbRadioPowerOn(pDevice);
124             vMgrTimerInit(pDevice);
125             MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
126             add_timer(&pMgmt->sTimerSecondCallback);
127             pDevice->bMACSuspend = FALSE;
128         }
129         spin_lock_irq(&pDevice->lock);
130         if (memcmp(pMgmt->abyCurrBSSID, &abyNullAddr[0], 6) == 0)
131             BSSvClearBSSList((HANDLE)pDevice, FALSE);
132         else
133             BSSvClearBSSList((HANDLE)pDevice, pDevice->bLinkPass);
134
135         if (pItemSSID->len != 0)
136             bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, abyScanSSID);
137         else
138             bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, NULL);
139         spin_unlock_irq(&pDevice->lock);
140         break;
141
142     case WLAN_CMD_ZONETYPE_SET:
143         //mike add :cann't support.
144            result=-EOPNOTSUPP;
145           break;
146
147         if (copy_from_user(&sZoneTypeCmd, pReq->data, sizeof(SCmdZoneTypeSet))) {
148                         result = -EFAULT;
149                         break;
150                 };
151
152           if(sZoneTypeCmd.bWrite==TRUE) {
153           //////write zonetype
154                 if(sZoneTypeCmd.ZoneType == ZoneType_USA) {
155                   //set to USA
156                    printk("set_ZoneType:USA\n");
157                 }
158                 else if(sZoneTypeCmd.ZoneType == ZoneType_Japan) {
159                   //set to Japan
160                   printk("set_ZoneType:Japan\n");
161                 }
162                else if(sZoneTypeCmd.ZoneType == ZoneType_Europe) {
163                   //set to Europe
164                   printk("set_ZoneType:Europe\n");
165                 }
166             }
167         else {
168           ///////read zonetype
169           BYTE                       zonetype=0;
170
171
172            if(zonetype == 0x00)  { //USA
173              sZoneTypeCmd.ZoneType = ZoneType_USA;
174            }
175          else if(zonetype == 0x01) { //Japan
176              sZoneTypeCmd.ZoneType = ZoneType_Japan;
177           }
178          else if(zonetype == 0x02) { //Europe
179              sZoneTypeCmd.ZoneType = ZoneType_Europe;
180          }
181          else { //Unknow ZoneType
182                 printk("Error:ZoneType[%x] Unknown ???\n",zonetype);
183                  result = -EFAULT;
184                 break;
185          }
186            if (copy_to_user(pReq->data, &sZoneTypeCmd, sizeof(SCmdZoneTypeSet))) {
187                         result = -EFAULT;
188                         break;
189                 };
190         }
191
192              break;
193
194     case WLAN_CMD_BSS_JOIN:
195
196         if (pDevice->bMACSuspend == TRUE) {
197             if (pDevice->bRadioOff == TRUE)
198                 CARDbRadioPowerOn(pDevice);
199             vMgrTimerInit(pDevice);
200             MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
201             add_timer(&pMgmt->sTimerSecondCallback);
202             pDevice->bMACSuspend = FALSE;
203         }
204
205         if (copy_from_user(&sJoinCmd, pReq->data, sizeof(SCmdBSSJoin))) {
206                         result = -EFAULT;
207                         break;
208                 };
209
210         pItemSSID = (PWLAN_IE_SSID)sJoinCmd.ssid;
211         memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
212                 memcpy(pMgmt->abyDesireSSID, pItemSSID, pItemSSID->len + WLAN_IEHDR_LEN);
213             if (sJoinCmd.wBSSType == ADHOC) {
214                 pMgmt->eConfigMode = WMAC_CONFIG_IBSS_STA;
215                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ioct set to adhoc mode\n");
216             }
217             else {
218                 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
219                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ioct set to STA mode\n");
220             }
221             if (sJoinCmd.bPSEnable == TRUE) {
222             pDevice->ePSMode = WMAC_POWER_FAST;
223 //            pDevice->ePSMode = WMAC_POWER_MAX;
224             pMgmt->wListenInterval = 2;
225             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Power Saving On\n");
226         }
227         else {
228             pDevice->ePSMode = WMAC_POWER_CAM;
229             pMgmt->wListenInterval = 1;
230             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Power Saving Off \n");
231         }
232
233         if (sJoinCmd.bShareKeyAuth == TRUE){
234             pMgmt->bShareKeyAlgorithm = TRUE;
235             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Share Key \n");
236         }
237         else {
238             pMgmt->bShareKeyAlgorithm = FALSE;
239             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Open System \n");
240         }
241             pDevice->uChannel = sJoinCmd.uChannel;
242         netif_stop_queue(pDevice->dev);
243         spin_lock_irq(&pDevice->lock);
244         pMgmt->eCurrState = WMAC_STATE_IDLE;
245         bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
246         bScheduleCommand((HANDLE) pDevice, WLAN_CMD_SSID, NULL);
247         spin_unlock_irq(&pDevice->lock);
248         break;
249
250     case WLAN_CMD_SET_WEP:
251         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_SET_WEP Key. \n");
252         memset(&sWEPCmd, 0 ,sizeof(SCmdSetWEP));
253         if (copy_from_user(&sWEPCmd, pReq->data, sizeof(SCmdSetWEP))) {
254                         result = -EFAULT;
255                         break;
256                 };
257             if (sWEPCmd.bEnableWep != TRUE) {
258             pDevice->bEncryptionEnable = FALSE;
259             pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
260             MACvDisableDefaultKey(pDevice->PortOffset);
261             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WEP function disable. \n");
262             break;
263         }
264
265         for (ii = 0; ii < WLAN_WEP_NKEYS; ii ++) {
266             if (sWEPCmd.bWepKeyAvailable[ii]) {
267                 if (ii == sWEPCmd.byKeyIndex)
268         //2006-1123-02,<Modify> by EinsnLiu
269         //Evaluate the "dwKeyIndex" error
270         //  dwKeyIndex |= (1 << 31);
271           dwKeyIndex =ii|(1 << 31);
272                 else
273                     dwKeyIndex = ii;
274
275                 KeybSetDefaultKey(&(pDevice->sKey),
276                                     dwKeyIndex,
277                                     sWEPCmd.auWepKeyLength[ii],
278                                     NULL,
279                                     (PBYTE)&sWEPCmd.abyWepKey[ii][0],
280                                     KEY_CTL_WEP,
281                                     pDevice->PortOffset,
282                                     pDevice->byLocalID);
283             }
284         }
285         pDevice->byKeyIndex = sWEPCmd.byKeyIndex;
286         pDevice->bTransmitKey = TRUE;
287         pDevice->bEncryptionEnable = TRUE;
288         pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
289
290         break;
291
292     case WLAN_CMD_GET_LINK:
293         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_GET_LINK status. \n");
294
295         memset(sLinkStatus.abySSID, 0 , WLAN_SSID_MAXLEN + 1);
296
297         if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)
298             sLinkStatus.wBSSType = ADHOC;
299         else
300             sLinkStatus.wBSSType = INFRA;
301
302         if (pMgmt->eCurrState == WMAC_STATE_JOINTED)
303             sLinkStatus.byState = ADHOC_JOINTED;
304         else
305             sLinkStatus.byState = ADHOC_STARTED;
306
307         sLinkStatus.uChannel = pMgmt->uCurrChannel;
308         if (pDevice->bLinkPass == TRUE) {
309             sLinkStatus.bLink = TRUE;
310                     pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
311                     memcpy(sLinkStatus.abySSID, pItemSSID->abySSID, pItemSSID->len);
312                     memcpy(sLinkStatus.abyBSSID, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
313                     sLinkStatus.uLinkRate = pMgmt->sNodeDBTable[0].wTxDataRate;
314             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Link Success ! \n");
315         }
316         else {
317             sLinkStatus.bLink = FALSE;
318         }
319         if (copy_to_user(pReq->data, &sLinkStatus, sizeof(SCmdLinkStatus))) {
320                         result = -EFAULT;
321                         break;
322                 };
323
324         break;
325
326     case WLAN_CMD_GET_LISTLEN:
327                 cbListCount = 0;
328                 pBSS = &(pMgmt->sBSSList[0]);
329         for (ii = 0; ii < MAX_BSS_NUM; ii++) {
330             pBSS = &(pMgmt->sBSSList[ii]);
331             if (!pBSS->bActive)
332                 continue;
333             cbListCount++;
334         };
335         sList.uItem = cbListCount;
336         if (copy_to_user(pReq->data, &sList, sizeof(SBSSIDList))) {
337                         result = -EFAULT;
338                         break;
339                 };
340         pReq->wResult = 0;
341         break;
342
343     case WLAN_CMD_GET_LIST:
344         if (copy_from_user(&sList, pReq->data, sizeof(SBSSIDList))) {
345                         result = -EFAULT;
346                         break;
347                 };
348         pList = (PSBSSIDList)kmalloc(sizeof(SBSSIDList) + (sList.uItem * sizeof(SBSSIDItem)), (int)GFP_ATOMIC);
349         if (pList == NULL) {
350             result = -ENOMEM;
351             break;
352         }
353                 pList->uItem = sList.uItem;
354                 pBSS = &(pMgmt->sBSSList[0]);
355         for (ii = 0, jj = 0; jj < MAX_BSS_NUM ; jj++) {
356             pBSS = &(pMgmt->sBSSList[jj]);
357             if (pBSS->bActive) {
358                     pList->sBSSIDList[ii].uChannel = pBSS->uChannel;
359                     pList->sBSSIDList[ii].wBeaconInterval = pBSS->wBeaconInterval;
360                     pList->sBSSIDList[ii].wCapInfo = pBSS->wCapInfo;
361 //                  pList->sBSSIDList[ii].uRSSI = pBSS->uRSSI;
362                     RFvRSSITodBm(pDevice, (BYTE)(pBSS->uRSSI), &ldBm);
363                     pList->sBSSIDList[ii].uRSSI = (UINT)ldBm;
364                     memcpy(pList->sBSSIDList[ii].abyBSSID, pBSS->abyBSSID, WLAN_BSSID_LEN);
365                     pItemSSID = (PWLAN_IE_SSID)pBSS->abySSID;
366                     memset(pList->sBSSIDList[ii].abySSID, 0, WLAN_SSID_MAXLEN + 1);
367                     memcpy(pList->sBSSIDList[ii].abySSID, pItemSSID->abySSID, pItemSSID->len);
368                 if (WLAN_GET_CAP_INFO_ESS(pBSS->wCapInfo)) {
369                         pList->sBSSIDList[ii].byNetType = INFRA;
370                 }
371                 else {
372                         pList->sBSSIDList[ii].byNetType = ADHOC;
373                     }
374                     if (WLAN_GET_CAP_INFO_PRIVACY(pBSS->wCapInfo)) {
375                         pList->sBSSIDList[ii].bWEPOn = TRUE;
376                 }
377                 else {
378                         pList->sBSSIDList[ii].bWEPOn = FALSE;
379                     }
380                     ii ++;
381                     if (ii >= pList->uItem)
382                         break;
383             }
384         }
385
386         if (copy_to_user(pReq->data, pList, sizeof(SBSSIDList) + (sList.uItem * sizeof(SBSSIDItem)))) {
387                         result = -EFAULT;
388                         break;
389                 };
390         kfree(pList);
391         pReq->wResult = 0;
392         break;
393
394     case WLAN_CMD_GET_MIB:
395         if (copy_to_user(pReq->data, &(pDevice->s802_11Counter), sizeof(SDot11MIBCount))) {
396                         result = -EFAULT;
397                         break;
398                 };
399         break;
400
401     case WLAN_CMD_GET_STAT:
402         if (copy_to_user(pReq->data, &(pDevice->scStatistic), sizeof(SStatCounter))) {
403                         result = -EFAULT;
404                         break;
405                 };
406         break;
407     case WLAN_CMD_STOP_MAC:
408
409         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_STOP_MAC\n");
410         netif_stop_queue(pDevice->dev);
411
412         spin_lock_irq(&pDevice->lock);
413         if (pDevice->bRadioOff == FALSE) {
414             CARDbRadioPowerOff(pDevice);
415         }
416         pDevice->bLinkPass = FALSE;
417         memset(pMgmt->abyCurrBSSID, 0, 6);
418         pMgmt->eCurrState = WMAC_STATE_IDLE;
419         del_timer(&pDevice->sTimerCommand);
420         del_timer(&pMgmt->sTimerSecondCallback);
421         pDevice->bCmdRunning = FALSE;
422         pDevice->bMACSuspend = TRUE;
423         MACvIntDisable(pDevice->PortOffset);
424         spin_unlock_irq(&pDevice->lock);
425
426         break;
427
428     case WLAN_CMD_START_MAC:
429
430         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_START_MAC\n");
431
432         if (pDevice->bMACSuspend == TRUE) {
433             if (pDevice->bRadioOff == TRUE)
434                 CARDbRadioPowerOn(pDevice);
435             vMgrTimerInit(pDevice);
436             MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
437             add_timer(&pMgmt->sTimerSecondCallback);
438             pDevice->bMACSuspend = FALSE;
439         }
440         break;
441
442     case WLAN_CMD_SET_HOSTAPD:
443
444         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_SET_HOSTAPD\n");
445
446         if (copy_from_user(&sValue, pReq->data, sizeof(SCmdValue))) {
447                         result = -EFAULT;
448                         break;
449                 };
450                 if (sValue.dwValue == 1) {
451             if (hostap_set_hostapd(pDevice, 1, 1) == 0){
452                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable HOSTAP\n");
453             }
454             else {
455                             result = -EFAULT;
456                             break;
457                         }
458         }
459         else {
460             hostap_set_hostapd(pDevice, 0, 1);
461             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disable HOSTAP\n");
462         }
463
464         break;
465
466     case WLAN_CMD_SET_HOSTAPD_STA:
467
468         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_SET_HOSTAPD_STA\n");
469
470         break;
471     case WLAN_CMD_SET_802_1X:
472
473         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_SET_802_1X\n");
474         if (copy_from_user(&sValue, pReq->data, sizeof(SCmdValue))) {
475                         result = -EFAULT;
476                         break;
477                 };
478
479                 if (sValue.dwValue == 1) {
480             pDevice->bEnable8021x = TRUE;
481             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable 802.1x\n");
482         }
483         else {
484             pDevice->bEnable8021x = FALSE;
485             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disable 802.1x\n");
486         }
487
488         break;
489
490
491     case WLAN_CMD_SET_HOST_WEP:
492
493         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_SET_HOST_WEP\n");
494         if (copy_from_user(&sValue, pReq->data, sizeof(SCmdValue))) {
495                         result = -EFAULT;
496                         break;
497                 };
498
499                 if (sValue.dwValue == 1) {
500             pDevice->bEnableHostWEP = TRUE;
501             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable HostWEP\n");
502         }
503         else {
504             pDevice->bEnableHostWEP = FALSE;
505             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disable HostWEP\n");
506         }
507
508         break;
509
510     case WLAN_CMD_SET_WPA:
511          DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_SET_WPA\n");
512
513         if (copy_from_user(&sValue, pReq->data, sizeof(SCmdValue))) {
514                         result = -EFAULT;
515                         break;
516                 };
517                 if (sValue.dwValue == 1) {
518                      DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "up wpadev\n");
519                    memcpy(pDevice->wpadev->dev_addr, pDevice->dev->dev_addr, U_ETHER_ADDR_LEN);
520                    pDevice->bWPADEVUp = TRUE;
521         }
522         else {
523             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "close wpadev\n");
524            pDevice->bWPADEVUp = FALSE;
525         }
526
527         break;
528
529     case WLAN_CMD_AP_START:
530
531         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_AP_START\n");
532         if (pDevice->bRadioOff == TRUE) {
533             CARDbRadioPowerOn(pDevice);
534             vMgrTimerInit(pDevice);
535             MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
536             add_timer(&pMgmt->sTimerSecondCallback);
537         }
538         if (copy_from_user(&sStartAPCmd, pReq->data, sizeof(SCmdStartAP))) {
539                         result = -EFAULT;
540                         break;
541                 };
542
543             if (sStartAPCmd.wBSSType == AP) {
544                 pMgmt->eConfigMode = WMAC_CONFIG_AP;
545                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ioct set to AP mode\n");
546             }
547             else {
548                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ioct BSS type not set to AP mode\n");
549                         result = -EFAULT;
550                         break;
551             }
552
553
554             if (sStartAPCmd.wBBPType == PHY80211g) {
555             pMgmt->byAPBBType = PHY_TYPE_11G;
556         }
557         else if (sStartAPCmd.wBBPType == PHY80211a) {
558                  pMgmt->byAPBBType = PHY_TYPE_11A;
559         }
560         else {
561             pMgmt->byAPBBType = PHY_TYPE_11B;
562         }
563
564         pItemSSID = (PWLAN_IE_SSID)sStartAPCmd.ssid;
565         memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
566                 memcpy(pMgmt->abyDesireSSID, pItemSSID, pItemSSID->len + WLAN_IEHDR_LEN);
567
568             if ((sStartAPCmd.uChannel > 0)&&(sStartAPCmd.uChannel <= 14))
569                 pDevice->uChannel = sStartAPCmd.uChannel;
570
571             if ((sStartAPCmd.uBeaconInt >= 20) && (sStartAPCmd.uBeaconInt <= 1000))
572             pMgmt->wIBSSBeaconPeriod = sStartAPCmd.uBeaconInt;
573         else
574             pMgmt->wIBSSBeaconPeriod = 100;
575
576         if (sStartAPCmd.bShareKeyAuth == TRUE){
577             pMgmt->bShareKeyAlgorithm = TRUE;
578             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Share Key \n");
579         }
580         else {
581             pMgmt->bShareKeyAlgorithm = FALSE;
582             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Open System \n");
583         }
584         memcpy(pMgmt->abyIBSSSuppRates, abySuppRates, 6);
585
586         if (sStartAPCmd.byBasicRate & BIT3) {
587             pMgmt->abyIBSSSuppRates[2] |= BIT7;
588             pMgmt->abyIBSSSuppRates[3] |= BIT7;
589             pMgmt->abyIBSSSuppRates[4] |= BIT7;
590             pMgmt->abyIBSSSuppRates[5] |= BIT7;
591         }else if (sStartAPCmd.byBasicRate & BIT2) {
592              pMgmt->abyIBSSSuppRates[2] |= BIT7;
593              pMgmt->abyIBSSSuppRates[3] |= BIT7;
594              pMgmt->abyIBSSSuppRates[4] |= BIT7;
595         }else if (sStartAPCmd.byBasicRate & BIT1) {
596              pMgmt->abyIBSSSuppRates[2] |= BIT7;
597              pMgmt->abyIBSSSuppRates[3] |= BIT7;
598         }else if (sStartAPCmd.byBasicRate & BIT1) {
599              pMgmt->abyIBSSSuppRates[2] |= BIT7;
600         }else {
601             //default 1,2M
602              pMgmt->abyIBSSSuppRates[2] |= BIT7;
603              pMgmt->abyIBSSSuppRates[3] |= BIT7;
604         }
605
606         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Support Rate= %x %x %x %x\n",
607                 pMgmt->abyIBSSSuppRates[2],
608                 pMgmt->abyIBSSSuppRates[3],
609                 pMgmt->abyIBSSSuppRates[4],
610                 pMgmt->abyIBSSSuppRates[5]
611                 );
612
613         netif_stop_queue(pDevice->dev);
614         spin_lock_irq(&pDevice->lock);
615         bScheduleCommand((HANDLE)pDevice, WLAN_CMD_RUN_AP, NULL);
616         spin_unlock_irq(&pDevice->lock);
617         break;
618
619     case WLAN_CMD_GET_NODE_CNT:
620
621                 cbListCount = 0;
622                 pNode = &(pMgmt->sNodeDBTable[0]);
623         for (ii = 0; ii < (MAX_NODE_NUM + 1); ii++) {
624             pNode = &(pMgmt->sNodeDBTable[ii]);
625             if (!pNode->bActive)
626                 continue;
627             cbListCount++;
628         };
629
630         sNodeList.uItem = cbListCount;
631         if (copy_to_user(pReq->data, &sNodeList, sizeof(SNodeList))) {
632                         result = -EFAULT;
633                         break;
634                 };
635         pReq->wResult = 0;
636         break;
637
638     case WLAN_CMD_GET_NODE_LIST:
639
640         if (copy_from_user(&sNodeList, pReq->data, sizeof(SNodeList))) {
641                         result = -EFAULT;
642                         break;
643                 };
644         pNodeList = (PSNodeList)kmalloc(sizeof(SNodeList) + (sNodeList.uItem * sizeof(SNodeItem)), (int)GFP_ATOMIC);
645         if (pNodeList == NULL) {
646             result = -ENOMEM;
647             break;
648         }
649                 pNodeList->uItem = sNodeList.uItem;
650                 pNode = &(pMgmt->sNodeDBTable[0]);
651         for (ii = 0, jj = 0; ii < (MAX_NODE_NUM + 1); ii++) {
652             pNode = &(pMgmt->sNodeDBTable[ii]);
653             if (pNode->bActive) {
654                     pNodeList->sNodeList[jj].wAID = pNode->wAID;
655                     memcpy(pNodeList->sNodeList[jj].abyMACAddr, pNode->abyMACAddr, WLAN_ADDR_LEN);
656                     pNodeList->sNodeList[jj].wTxDataRate = pNode->wTxDataRate;
657                     pNodeList->sNodeList[jj].wInActiveCount = (WORD)pNode->uInActiveCount;
658                     pNodeList->sNodeList[jj].wEnQueueCnt = (WORD)pNode->wEnQueueCnt;
659                     pNodeList->sNodeList[jj].wFlags = (WORD)pNode->dwFlags;
660                     pNodeList->sNodeList[jj].bPWBitOn = pNode->bPSEnable;
661                     pNodeList->sNodeList[jj].byKeyIndex = pNode->byKeyIndex;
662                     pNodeList->sNodeList[jj].wWepKeyLength = pNode->uWepKeyLength;
663                     memcpy(&(pNodeList->sNodeList[jj].abyWepKey[0]), &(pNode->abyWepKey[0]), WEP_KEYMAXLEN);
664                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "key= %2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
665                             pNodeList->sNodeList[jj].abyWepKey[0],
666                             pNodeList->sNodeList[jj].abyWepKey[1],
667                             pNodeList->sNodeList[jj].abyWepKey[2],
668                             pNodeList->sNodeList[jj].abyWepKey[3],
669                             pNodeList->sNodeList[jj].abyWepKey[4]
670                            );
671                     pNodeList->sNodeList[jj].bIsInFallback = pNode->bIsInFallback;
672                     pNodeList->sNodeList[jj].uTxFailures = pNode->uTxFailures;
673                     pNodeList->sNodeList[jj].uTxAttempts = pNode->uTxAttempts;
674                     pNodeList->sNodeList[jj].wFailureRatio = (WORD)pNode->uFailureRatio;
675                     jj ++;
676                     if (jj >= pNodeList->uItem)
677                         break;
678                 }
679                 };
680         if (copy_to_user(pReq->data, pNodeList, sizeof(SNodeList) + (sNodeList.uItem * sizeof(SNodeItem)))) {
681                         result = -EFAULT;
682                         break;
683                 };
684         kfree(pNodeList);
685         pReq->wResult = 0;
686         break;
687
688 #ifdef WPA_SM_Transtatus
689     case 0xFF:
690         memset(wpa_Result.ifname,0,sizeof(wpa_Result.ifname));
691             wpa_Result.proto = 0;
692             wpa_Result.key_mgmt = 0;
693             wpa_Result.eap_type = 0;
694             wpa_Result.authenticated = FALSE;
695               pDevice->fWPA_Authened = FALSE;
696         if (copy_from_user(&wpa_Result, pReq->data, sizeof(wpa_Result))) {
697             result = -EFAULT;
698                         break;
699                 }
700
701 if(wpa_Result.authenticated==TRUE) {
702    #ifdef SndEvt_ToAPI
703    {
704      union iwreq_data      wrqu;
705
706      pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
707
708      memset(&wrqu, 0, sizeof(wrqu));
709      wrqu.data.flags = RT_WPACONNECTED_EVENT_FLAG;
710      wrqu.data.length =pItemSSID->len;
711      wireless_send_event(pDevice->dev, IWEVCUSTOM, &wrqu, pItemSSID->abySSID);
712    }
713    #endif
714          pDevice->fWPA_Authened = TRUE;           //is sucessful peer to wpa_Result.authenticated?
715 }
716
717         //printk("get private wpa_supplicant announce WPA SM\n");
718         //printk("wpa-->ifname=%s\n",wpa_Result.ifname);
719         //printk("wpa-->proto=%d\n",wpa_Result.proto);
720         //printk("wpa-->key-mgmt=%d\n",wpa_Result.key_mgmt);
721         //printk("wpa-->eap_type=%d\n",wpa_Result.eap_type);
722         //printk("wpa-->authenticated is %s\n",(wpa_Result.authenticated==TRUE)?"TRUE":"FALSE");
723
724         pReq->wResult = 0;
725         break;
726 #endif
727
728     default:
729         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Private command not support..\n");
730     }
731
732     return result;
733 }
734
735 /*
736 VOID
737 vConfigWEPKey (
738     IN PSDevice pDevice,
739     IN DWORD    dwKeyIndex,
740     IN PBYTE    pbyKey,
741     IN ULONG    uKeyLength
742     )
743 {
744     int ii;
745
746
747     ZERO_MEMORY(&pDevice->abyWepKey[dwKeyIndex][0], WLAN_WEPMAX_KEYLEN);
748     MEMvCopy(&pDevice->abyWepKey[dwKeyIndex][0], pbyKey, uKeyLength);
749
750     pDevice->bWepKeyAvailable[dwKeyIndex] = TRUE;
751     pDevice->auWepKeyLength[dwKeyIndex] = uKeyLength;
752
753     MACvSetDefaultKeyEntry(pDevice->PortOffset, uKeyLength, dwKeyIndex,
754                            (PDWORD) &(pDevice->abyWepKey[dwKeyIndex][0]), pDevice->byLocalID);
755
756     if (pDevice->eEncryptionStatus < Ndis802_11EncryptionNotSupported) {
757         for(ii=0; ii<MAX_GROUP_KEY; ii++) {
758             if ((pDevice->bWepKeyAvailable[ii] == TRUE) &&
759                 (pDevice->auWepKeyLength[ii] == WLAN_WEP232_KEYLEN)) {
760                 pDevice->uCurrentWEPMode = TX_WEP_SW232;
761                 MACvDisableDefaultKey(pDevice->PortOffset);
762                 break;
763             }
764         }
765         if ((ii == MAX_GROUP_KEY) &&
766             (pDevice->eEncryptionStatus < Ndis802_11EncryptionNotSupported)) {
767             MACvEnableDefaultKey(pDevice->PortOffset, pDevice->byLocalID);
768         }
769     }
770 }
771 */