Linux 3.13-rc1
[linux-2.6-microblaze.git] / drivers / staging / vt6656 / wcmd.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: wcmd.c
20  *
21  * Purpose: Handles the management command interface functions
22  *
23  * Author: Lyndon Chen
24  *
25  * Date: May 8, 2003
26  *
27  * Functions:
28  *      s_vProbeChannel - Active scan channel
29  *      s_MgrMakeProbeRequest - Make ProbeRequest packet
30  *      CommandTimer - Timer function to handle command
31  *      s_bCommandComplete - Command Complete function
32  *      bScheduleCommand - Push Command and wait Command Scheduler to do
33  *      vCommandTimer- Command call back functions
34  *      vCommandTimerWait- Call back timer
35  *      s_bClearBSSID_SCAN- Clear BSSID_SCAN cmd in CMD Queue
36  *
37  * Revision History:
38  *
39  */
40
41 #include "tmacro.h"
42 #include "device.h"
43 #include "mac.h"
44 #include "card.h"
45 #include "80211hdr.h"
46 #include "wcmd.h"
47 #include "wmgr.h"
48 #include "power.h"
49 #include "wctl.h"
50 #include "baseband.h"
51 #include "control.h"
52 #include "rxtx.h"
53 #include "rf.h"
54 #include "rndis.h"
55 #include "channel.h"
56 #include "iowpa.h"
57
58 static int          msglevel                =MSG_LEVEL_INFO;
59 //static int          msglevel                =MSG_LEVEL_DEBUG;
60
61 static void s_vProbeChannel(struct vnt_private *);
62
63 static struct vnt_tx_mgmt *s_MgrMakeProbeRequest(struct vnt_private *,
64         struct vnt_manager *pMgmt, u8 *pScanBSSID, PWLAN_IE_SSID pSSID,
65         PWLAN_IE_SUPP_RATES pCurrRates, PWLAN_IE_SUPP_RATES pCurrExtSuppRates);
66
67 static int s_bCommandComplete(struct vnt_private *);
68
69 static int s_bClearBSSID_SCAN(struct vnt_private *);
70
71 /*
72  * Description:
73  *      Stop AdHoc beacon during scan process
74  *
75  * Parameters:
76  *  In:
77  *      pDevice     - Pointer to the adapter
78  *  Out:
79  *      none
80  *
81  * Return Value: none
82  *
83  */
84
85 static void vAdHocBeaconStop(struct vnt_private *pDevice)
86 {
87         struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
88         int bStop;
89
90     /*
91      * temporarily stop Beacon packet for AdHoc Server
92      * if all of the following coditions are met:
93      *  (1) STA is in AdHoc mode
94      *  (2) VT3253 is programmed as automatic Beacon Transmitting
95      *  (3) One of the following conditions is met
96      *      (3.1) AdHoc channel is in B/G band and the
97      *      current scan channel is in A band
98      *      or
99      *      (3.2) AdHoc channel is in A mode
100      */
101     bStop = false;
102     if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) &&
103     (pMgmt->eCurrState >= WMAC_STATE_STARTED))
104     {
105         if ((pMgmt->uIBSSChannel <=  CB_MAX_CHANNEL_24G) &&
106              (pMgmt->uScanChannel > CB_MAX_CHANNEL_24G))
107         {
108             bStop = true;
109         }
110         if (pMgmt->uIBSSChannel >  CB_MAX_CHANNEL_24G)
111         {
112             bStop = true;
113         }
114     }
115
116     if (bStop)
117     {
118         //PMESG(("STOP_BEACON: IBSSChannel = %u, ScanChannel = %u\n",
119         //        pMgmt->uIBSSChannel, pMgmt->uScanChannel));
120         MACvRegBitsOff(pDevice, MAC_REG_TCR, TCR_AUTOBCNTX);
121     }
122
123 } /* vAdHocBeaconStop */
124
125 /*
126  * Description:
127  *      Restart AdHoc beacon after scan process complete
128  *
129  * Parameters:
130  *  In:
131  *      pDevice     - Pointer to the adapter
132  *  Out:
133  *      none
134  *
135  * Return Value: none
136  *
137  */
138 static void vAdHocBeaconRestart(struct vnt_private *pDevice)
139 {
140         struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
141
142     /*
143      * Restart Beacon packet for AdHoc Server
144      * if all of the following coditions are met:
145      *  (1) STA is in AdHoc mode
146      *  (2) VT3253 is programmed as automatic Beacon Transmitting
147      */
148     if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) &&
149     (pMgmt->eCurrState >= WMAC_STATE_STARTED))
150     {
151         //PMESG(("RESTART_BEACON\n"));
152         MACvRegBitsOn(pDevice, MAC_REG_TCR, TCR_AUTOBCNTX);
153     }
154
155 }
156
157 /*+
158  *
159  * Routine Description:
160  *   Prepare and send probe request management frames.
161  *
162  *
163  * Return Value:
164  *    none.
165  *
166 -*/
167
168 static void s_vProbeChannel(struct vnt_private *pDevice)
169 {
170         struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
171         struct vnt_tx_mgmt *pTxPacket;
172         u8 abyCurrSuppRatesG[] = {WLAN_EID_SUPP_RATES,
173                         8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C};
174                         /* 1M,   2M,   5M,   11M,  18M,  24M,  36M,  54M*/
175         u8 abyCurrExtSuppRatesG[] = {WLAN_EID_EXTSUPP_RATES,
176                         4, 0x0C, 0x12, 0x18, 0x60};
177                         /* 6M,   9M,   12M,  48M*/
178         u8 abyCurrSuppRatesA[] = {WLAN_EID_SUPP_RATES,
179                         8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
180         u8 abyCurrSuppRatesB[] = {WLAN_EID_SUPP_RATES,
181                         4, 0x02, 0x04, 0x0B, 0x16};
182         u8 *pbyRate;
183         int ii;
184
185     if (pDevice->byBBType == BB_TYPE_11A) {
186         pbyRate = &abyCurrSuppRatesA[0];
187     } else if (pDevice->byBBType == BB_TYPE_11B) {
188         pbyRate = &abyCurrSuppRatesB[0];
189     } else {
190         pbyRate = &abyCurrSuppRatesG[0];
191     }
192     // build an assocreq frame and send it
193     pTxPacket = s_MgrMakeProbeRequest
194                 (
195                   pDevice,
196                   pMgmt,
197                   pMgmt->abyScanBSSID,
198                   (PWLAN_IE_SSID)pMgmt->abyScanSSID,
199                   (PWLAN_IE_SUPP_RATES)pbyRate,
200                   (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRatesG
201                 );
202
203     if (pTxPacket != NULL ){
204         for (ii = 0; ii < 1 ; ii++) {
205             if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
206                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Probe request sending fail.. \n");
207             }
208             else {
209                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Probe request is sending.. \n");
210             }
211         }
212     }
213
214 }
215
216 /*+
217  *
218  * Routine Description:
219  *  Constructs an probe request frame
220  *
221  *
222  * Return Value:
223  *    A ptr to Tx frame or NULL on allocation failure
224  *
225 -*/
226
227 struct vnt_tx_mgmt *s_MgrMakeProbeRequest(struct vnt_private *pDevice,
228         struct vnt_manager *pMgmt, u8 *pScanBSSID, PWLAN_IE_SSID pSSID,
229         PWLAN_IE_SUPP_RATES pCurrRates, PWLAN_IE_SUPP_RATES pCurrExtSuppRates)
230 {
231         struct vnt_tx_mgmt *pTxPacket = NULL;
232         WLAN_FR_PROBEREQ sFrame;
233
234         pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
235         memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
236                 + WLAN_PROBEREQ_FR_MAXLEN);
237         pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
238                 + sizeof(struct vnt_tx_mgmt));
239     sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
240     sFrame.len = WLAN_PROBEREQ_FR_MAXLEN;
241     vMgrEncodeProbeRequest(&sFrame);
242     sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
243         (
244         WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
245         WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_PROBEREQ)
246         ));
247     memcpy( sFrame.pHdr->sA3.abyAddr1, pScanBSSID, WLAN_ADDR_LEN);
248     memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
249     memcpy( sFrame.pHdr->sA3.abyAddr3, pScanBSSID, WLAN_BSSID_LEN);
250     // Copy the SSID, pSSID->len=0 indicate broadcast SSID
251     sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
252     sFrame.len += pSSID->len + WLAN_IEHDR_LEN;
253     memcpy(sFrame.pSSID, pSSID, pSSID->len + WLAN_IEHDR_LEN);
254     sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
255     sFrame.len += pCurrRates->len + WLAN_IEHDR_LEN;
256     memcpy(sFrame.pSuppRates, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
257     // Copy the extension rate set
258     if (pDevice->byBBType == BB_TYPE_11G) {
259         sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
260         sFrame.len += pCurrExtSuppRates->len + WLAN_IEHDR_LEN;
261         memcpy(sFrame.pExtSuppRates, pCurrExtSuppRates, pCurrExtSuppRates->len + WLAN_IEHDR_LEN);
262     }
263     pTxPacket->cbMPDULen = sFrame.len;
264     pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
265
266     return pTxPacket;
267 }
268
269 void vCommandTimerWait(struct vnt_private *pDevice, unsigned long MSecond)
270 {
271         schedule_delayed_work(&pDevice->run_command_work,
272                                                 msecs_to_jiffies(MSecond));
273 }
274
275 void vRunCommand(struct work_struct *work)
276 {
277         struct vnt_private *pDevice =
278                 container_of(work, struct vnt_private, run_command_work.work);
279         struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
280         PWLAN_IE_SSID pItemSSID;
281         PWLAN_IE_SSID pItemSSIDCurr;
282         CMD_STATUS Status;
283         struct sk_buff  *skb;
284         union iwreq_data wrqu;
285         int ii;
286         u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
287         u8 byData;
288
289         if (pDevice->Flags & fMP_DISCONNECTED)
290                 return;
291
292     if (pDevice->dwDiagRefCount != 0)
293         return;
294     if (pDevice->bCmdRunning != true)
295         return;
296
297     spin_lock_irq(&pDevice->lock);
298
299     switch ( pDevice->eCommandState ) {
300
301         case WLAN_CMD_SCAN_START:
302
303                 pDevice->byReAssocCount = 0;
304             if (pDevice->bRadioOff == true) {
305                 s_bCommandComplete(pDevice);
306                 spin_unlock_irq(&pDevice->lock);
307                 return;
308             }
309
310             if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
311                 s_bCommandComplete(pDevice);
312                 spin_unlock_irq(&pDevice->lock);
313                 return;
314             }
315
316             pItemSSID = (PWLAN_IE_SSID)pMgmt->abyScanSSID;
317
318             if (pMgmt->uScanChannel == 0 ) {
319                 pMgmt->uScanChannel = pDevice->byMinChannel;
320             }
321             if (pMgmt->uScanChannel > pDevice->byMaxChannel) {
322                 pDevice->eCommandState = WLAN_CMD_SCAN_END;
323                 s_bCommandComplete(pDevice);
324                 spin_unlock_irq(&pDevice->lock);
325                 return;
326
327             } else {
328                 if (!ChannelValid(pDevice->byZoneType, pMgmt->uScanChannel)) {
329                     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Invalid channel pMgmt->uScanChannel = %d \n",pMgmt->uScanChannel);
330                         pMgmt->uScanChannel++;
331                     s_bCommandComplete(pDevice);
332                     spin_unlock_irq(&pDevice->lock);
333                     return;
334                 }
335                 if (pMgmt->uScanChannel == pDevice->byMinChannel) {
336                    // pMgmt->eScanType = WMAC_SCAN_ACTIVE;          //mike mark
337                     pMgmt->abyScanBSSID[0] = 0xFF;
338                     pMgmt->abyScanBSSID[1] = 0xFF;
339                     pMgmt->abyScanBSSID[2] = 0xFF;
340                     pMgmt->abyScanBSSID[3] = 0xFF;
341                     pMgmt->abyScanBSSID[4] = 0xFF;
342                     pMgmt->abyScanBSSID[5] = 0xFF;
343                     pItemSSID->byElementID = WLAN_EID_SSID;
344                     // clear bssid list
345                     /* BSSvClearBSSList((void *) pDevice,
346                        pDevice->bLinkPass); */
347                     pMgmt->eScanState = WMAC_IS_SCANNING;
348                     pDevice->byScanBBType = pDevice->byBBType;  //lucas
349                     pDevice->bStopDataPkt = true;
350                     // Turn off RCR_BSSID filter every time
351                     MACvRegBitsOff(pDevice, MAC_REG_RCR, RCR_BSSID);
352                     pDevice->byRxMode &= ~RCR_BSSID;
353
354                 }
355                 //lucas
356                 vAdHocBeaconStop(pDevice);
357                 if ((pDevice->byBBType != BB_TYPE_11A) && (pMgmt->uScanChannel > CB_MAX_CHANNEL_24G)) {
358                     pDevice->byBBType = BB_TYPE_11A;
359                     CARDvSetBSSMode(pDevice);
360                 }
361                 else if ((pDevice->byBBType == BB_TYPE_11A) && (pMgmt->uScanChannel <= CB_MAX_CHANNEL_24G)) {
362                     pDevice->byBBType = BB_TYPE_11G;
363                     CARDvSetBSSMode(pDevice);
364                 }
365                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Scanning....  channel: [%d]\n", pMgmt->uScanChannel);
366                 // Set channel
367                 CARDbSetMediaChannel(pDevice, pMgmt->uScanChannel);
368                 // Set Baseband to be more sensitive.
369
370                 if (pDevice->bUpdateBBVGA) {
371                     BBvSetShortSlotTime(pDevice);
372                     BBvSetVGAGainOffset(pDevice, pDevice->abyBBVGA[0]);
373                     BBvUpdatePreEDThreshold(pDevice, true);
374                 }
375                 pMgmt->uScanChannel++;
376
377                 while (!ChannelValid(pDevice->byZoneType, pMgmt->uScanChannel) &&
378                         pMgmt->uScanChannel <= pDevice->byMaxChannel ){
379                     pMgmt->uScanChannel++;
380                 }
381
382                 if (pMgmt->uScanChannel > pDevice->byMaxChannel) {
383                     // Set Baseband to be not sensitive and rescan
384                     pDevice->eCommandState = WLAN_CMD_SCAN_END;
385
386                 }
387                 if ((pMgmt->b11hEnable == false) ||
388                     (pMgmt->uScanChannel < CB_MAX_CHANNEL_24G)) {
389                     s_vProbeChannel(pDevice);
390                     spin_unlock_irq(&pDevice->lock);
391                      vCommandTimerWait((void *) pDevice, 100);
392                     return;
393                 } else {
394                     spin_unlock_irq(&pDevice->lock);
395                     vCommandTimerWait((void *) pDevice, WCMD_PASSIVE_SCAN_TIME);
396                     return;
397                 }
398
399             }
400
401             break;
402
403         case WLAN_CMD_SCAN_END:
404
405             // Set Baseband's sensitivity back.
406             if (pDevice->byBBType != pDevice->byScanBBType) {
407                 pDevice->byBBType = pDevice->byScanBBType;
408                 CARDvSetBSSMode(pDevice);
409             }
410
411             if (pDevice->bUpdateBBVGA) {
412                 BBvSetShortSlotTime(pDevice);
413                 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGACurrent);
414                 BBvUpdatePreEDThreshold(pDevice, false);
415             }
416
417             // Set channel back
418             vAdHocBeaconRestart(pDevice);
419             // Set channel back
420             CARDbSetMediaChannel(pDevice, pMgmt->uCurrChannel);
421             // Set Filter
422             if (pMgmt->bCurrBSSIDFilterOn) {
423                 MACvRegBitsOn(pDevice, MAC_REG_RCR, RCR_BSSID);
424                 pDevice->byRxMode |= RCR_BSSID;
425             }
426             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Scanning, set back to channel: [%d]\n", pMgmt->uCurrChannel);
427                 pMgmt->uScanChannel = 0;
428             pMgmt->eScanState = WMAC_NO_SCANNING;
429             pDevice->bStopDataPkt = false;
430
431                 /*send scan event to wpa_Supplicant*/
432                 PRINT_K("wireless_send_event--->SIOCGIWSCAN(scan done)\n");
433                 memset(&wrqu, 0, sizeof(wrqu));
434                 wireless_send_event(pDevice->dev, SIOCGIWSCAN, &wrqu, NULL);
435
436             s_bCommandComplete(pDevice);
437             break;
438
439         case WLAN_CMD_DISASSOCIATE_START :
440                 pDevice->byReAssocCount = 0;
441             if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
442                 (pMgmt->eCurrState != WMAC_STATE_ASSOC)) {
443                 s_bCommandComplete(pDevice);
444                 spin_unlock_irq(&pDevice->lock);
445                 return;
446             } else {
447
448                       pDevice->bwextstep0 = false;
449                         pDevice->bwextstep1 = false;
450                         pDevice->bwextstep2 = false;
451                         pDevice->bwextstep3 = false;
452                    pDevice->bWPASuppWextEnabled = false;
453                    pDevice->fWPA_Authened = false;
454
455                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Send Disassociation Packet..\n");
456                 // reason = 8 : disassoc because sta has left
457                 vMgrDisassocBeginSta((void *) pDevice,
458                                      pMgmt,
459                                      pMgmt->abyCurrBSSID,
460                                      (8),
461                                      &Status);
462                 pDevice->bLinkPass = false;
463                 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW);
464                 // unlock command busy
465                 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
466                 pItemSSID->len = 0;
467                 memset(pItemSSID->abySSID, 0, WLAN_SSID_MAXLEN);
468                 pMgmt->eCurrState = WMAC_STATE_IDLE;
469                 pMgmt->sNodeDBTable[0].bActive = false;
470 //                pDevice->bBeaconBufReady = false;
471             }
472             netif_stop_queue(pDevice->dev);
473             if (pDevice->bNeedRadioOFF == true)
474                 CARDbRadioPowerOff(pDevice);
475             s_bCommandComplete(pDevice);
476             break;
477
478         case WLAN_CMD_SSID_START:
479
480                 pDevice->byReAssocCount = 0;
481             if (pDevice->bRadioOff == true) {
482                 s_bCommandComplete(pDevice);
483                 spin_unlock_irq(&pDevice->lock);
484                 return;
485             }
486
487             memcpy(pMgmt->abyAdHocSSID,pMgmt->abyDesireSSID,
488                               ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->len + WLAN_IEHDR_LEN);
489
490             pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
491             pItemSSIDCurr = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
492             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" cmd: desire ssid = %s\n", pItemSSID->abySSID);
493             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" cmd: curr ssid = %s\n", pItemSSIDCurr->abySSID);
494
495             if (pMgmt->eCurrState == WMAC_STATE_ASSOC) {
496                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Cmd pMgmt->eCurrState == WMAC_STATE_ASSOC\n");
497                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" pItemSSID->len =%d\n",pItemSSID->len);
498                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" pItemSSIDCurr->len = %d\n",pItemSSIDCurr->len);
499                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" desire ssid = %s\n", pItemSSID->abySSID);
500                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" curr ssid = %s\n", pItemSSIDCurr->abySSID);
501             }
502
503             if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) ||
504                 ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)&& (pMgmt->eCurrState == WMAC_STATE_JOINTED))) {
505
506                 if (pItemSSID->len == pItemSSIDCurr->len) {
507                     if (memcmp(pItemSSID->abySSID, pItemSSIDCurr->abySSID, pItemSSID->len) == 0) {
508                         s_bCommandComplete(pDevice);
509                         spin_unlock_irq(&pDevice->lock);
510                         return;
511                     }
512                 }
513                 netif_stop_queue(pDevice->dev);
514                 pDevice->bLinkPass = false;
515                 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW);
516             }
517             // set initial state
518             pMgmt->eCurrState = WMAC_STATE_IDLE;
519             pMgmt->eCurrMode = WMAC_MODE_STANDBY;
520             PSvDisablePowerSaving((void *) pDevice);
521             BSSvClearNodeDBTable(pDevice, 0);
522             vMgrJoinBSSBegin((void *) pDevice, &Status);
523             // if Infra mode
524             if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED)) {
525                 // Call mgr to begin the deauthentication
526                 // reason = (3) because sta has left ESS
527               if (pMgmt->eCurrState >= WMAC_STATE_AUTH) {
528                 vMgrDeAuthenBeginSta((void *)pDevice,
529                                      pMgmt,
530                                      pMgmt->abyCurrBSSID,
531                                      (3),
532                                      &Status);
533               }
534                 // Call mgr to begin the authentication
535                 vMgrAuthenBeginSta((void *) pDevice, pMgmt, &Status);
536                 if (Status == CMD_STATUS_SUCCESS) {
537                    pDevice->byLinkWaitCount = 0;
538                     pDevice->eCommandState = WLAN_AUTHENTICATE_WAIT;
539                     vCommandTimerWait((void *) pDevice, AUTHENTICATE_TIMEOUT);
540                     spin_unlock_irq(&pDevice->lock);
541                     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Set eCommandState = WLAN_AUTHENTICATE_WAIT\n");
542                     return;
543                 }
544             }
545             // if Adhoc mode
546             else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
547                 if (pMgmt->eCurrState == WMAC_STATE_JOINTED) {
548                     if (netif_queue_stopped(pDevice->dev)){
549                         netif_wake_queue(pDevice->dev);
550                     }
551                     pDevice->bLinkPass = true;
552                     ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER);
553                     pMgmt->sNodeDBTable[0].bActive = true;
554                     pMgmt->sNodeDBTable[0].uInActiveCount = 0;
555                 }
556                 else {
557                     // start own IBSS
558                     DBG_PRT(MSG_LEVEL_DEBUG,
559                             KERN_INFO "CreateOwn IBSS by CurrMode = IBSS_STA\n");
560                     vMgrCreateOwnIBSS((void *) pDevice, &Status);
561                     if (Status != CMD_STATUS_SUCCESS){
562                         DBG_PRT(MSG_LEVEL_DEBUG,
563                                 KERN_INFO "WLAN_CMD_IBSS_CREATE fail!\n");
564                     }
565                     BSSvAddMulticastNode(pDevice);
566                 }
567                 s_bClearBSSID_SCAN(pDevice);
568             }
569             // if SSID not found
570             else if (pMgmt->eCurrMode == WMAC_MODE_STANDBY) {
571                 if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA ||
572                     pMgmt->eConfigMode == WMAC_CONFIG_AUTO) {
573                     // start own IBSS
574                         DBG_PRT(MSG_LEVEL_DEBUG,
575                                 KERN_INFO "CreateOwn IBSS by CurrMode = STANDBY\n");
576                     vMgrCreateOwnIBSS((void *) pDevice, &Status);
577                     if (Status != CMD_STATUS_SUCCESS){
578                         DBG_PRT(MSG_LEVEL_DEBUG,
579                                 KERN_INFO "WLAN_CMD_IBSS_CREATE fail!\n");
580                     }
581                     BSSvAddMulticastNode(pDevice);
582                     s_bClearBSSID_SCAN(pDevice);
583 /*
584                     pDevice->bLinkPass = true;
585                     ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER);
586                     if (netif_queue_stopped(pDevice->dev)){
587                         netif_wake_queue(pDevice->dev);
588                     }
589                     s_bClearBSSID_SCAN(pDevice);
590 */
591                 }
592                 else {
593                     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disconnect SSID none\n");
594                     // if(pDevice->bWPASuppWextEnabled == true)
595                         {
596                         union iwreq_data  wrqu;
597                         memset(&wrqu, 0, sizeof (wrqu));
598                           wrqu.ap_addr.sa_family = ARPHRD_ETHER;
599                         PRINT_K("wireless_send_event--->SIOCGIWAP(disassociated:vMgrJoinBSSBegin Fail !!)\n");
600                         wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
601                        }
602                 }
603             }
604             s_bCommandComplete(pDevice);
605             break;
606
607         case WLAN_AUTHENTICATE_WAIT :
608             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState == WLAN_AUTHENTICATE_WAIT\n");
609             if (pMgmt->eCurrState == WMAC_STATE_AUTH) {
610                 pDevice->byLinkWaitCount = 0;
611                 // Call mgr to begin the association
612                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCurrState == WMAC_STATE_AUTH\n");
613                 vMgrAssocBeginSta((void *) pDevice, pMgmt, &Status);
614                 if (Status == CMD_STATUS_SUCCESS) {
615                     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState = WLAN_ASSOCIATE_WAIT\n");
616                   pDevice->byLinkWaitCount = 0;
617                     pDevice->eCommandState = WLAN_ASSOCIATE_WAIT;
618                     vCommandTimerWait((void *) pDevice, ASSOCIATE_TIMEOUT);
619                     spin_unlock_irq(&pDevice->lock);
620                     return;
621                 }
622             }
623            else if(pMgmt->eCurrState < WMAC_STATE_AUTHPENDING) {
624                printk("WLAN_AUTHENTICATE_WAIT:Authen Fail???\n");
625            }
626            else  if(pDevice->byLinkWaitCount <= 4){    //mike add:wait another 2 sec if authenticated_frame delay!
627                 pDevice->byLinkWaitCount ++;
628                printk("WLAN_AUTHENTICATE_WAIT:wait %d times!!\n",pDevice->byLinkWaitCount);
629                spin_unlock_irq(&pDevice->lock);
630                vCommandTimerWait((void *) pDevice, AUTHENTICATE_TIMEOUT/2);
631                return;
632            }
633                   pDevice->byLinkWaitCount = 0;
634
635             s_bCommandComplete(pDevice);
636             break;
637
638         case WLAN_ASSOCIATE_WAIT :
639             if (pMgmt->eCurrState == WMAC_STATE_ASSOC) {
640                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCurrState == WMAC_STATE_ASSOC\n");
641                 if (pDevice->ePSMode != WMAC_POWER_CAM) {
642                         PSvEnablePowerSaving((void *) pDevice,
643                                              pMgmt->wListenInterval);
644                 }
645 /*
646                 if (pMgmt->eAuthenMode >= WMAC_AUTH_WPA) {
647                     KeybRemoveAllKey(pDevice, &(pDevice->sKey), pDevice->abyBSSID);
648                 }
649 */
650                 pDevice->byLinkWaitCount = 0;
651                 pDevice->byReAssocCount = 0;
652                 pDevice->bLinkPass = true;
653                 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER);
654                 s_bClearBSSID_SCAN(pDevice);
655
656                 if (netif_queue_stopped(pDevice->dev)){
657                     netif_wake_queue(pDevice->dev);
658                 }
659
660             }
661            else if(pMgmt->eCurrState < WMAC_STATE_ASSOCPENDING) {
662                printk("WLAN_ASSOCIATE_WAIT:Association Fail???\n");
663            }
664            else  if(pDevice->byLinkWaitCount <= 4){    //mike add:wait another 2 sec if associated_frame delay!
665                 pDevice->byLinkWaitCount ++;
666                printk("WLAN_ASSOCIATE_WAIT:wait %d times!!\n",pDevice->byLinkWaitCount);
667                spin_unlock_irq(&pDevice->lock);
668                vCommandTimerWait((void *) pDevice, ASSOCIATE_TIMEOUT/2);
669                return;
670            }
671
672             s_bCommandComplete(pDevice);
673             break;
674
675         case WLAN_CMD_AP_MODE_START :
676             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState == WLAN_CMD_AP_MODE_START\n");
677
678             if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
679                 cancel_delayed_work_sync(&pDevice->second_callback_work);
680                 pMgmt->eCurrState = WMAC_STATE_IDLE;
681                 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
682                 pDevice->bLinkPass = false;
683                 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW);
684                 if (pDevice->bEnableHostWEP == true)
685                     BSSvClearNodeDBTable(pDevice, 1);
686                 else
687                     BSSvClearNodeDBTable(pDevice, 0);
688                 pDevice->uAssocCount = 0;
689                 pMgmt->eCurrState = WMAC_STATE_IDLE;
690                 pDevice->bFixRate = false;
691
692                 vMgrCreateOwnIBSS((void *) pDevice, &Status);
693                 if (Status != CMD_STATUS_SUCCESS) {
694                         DBG_PRT(MSG_LEVEL_DEBUG,
695                                 KERN_INFO "vMgrCreateOwnIBSS fail!\n");
696                 }
697                 // always turn off unicast bit
698                 MACvRegBitsOff(pDevice, MAC_REG_RCR, RCR_UNICAST);
699                 pDevice->byRxMode &= ~RCR_UNICAST;
700                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wcmd: rx_mode = %x\n", pDevice->byRxMode );
701                 BSSvAddMulticastNode(pDevice);
702                 if (netif_queue_stopped(pDevice->dev)){
703                     netif_wake_queue(pDevice->dev);
704                 }
705                 pDevice->bLinkPass = true;
706                 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER);
707                 schedule_delayed_work(&pDevice->second_callback_work, HZ);
708             }
709             s_bCommandComplete(pDevice);
710             break;
711
712         case WLAN_CMD_TX_PSPACKET_START :
713             // DTIM Multicast tx
714             if (pMgmt->sNodeDBTable[0].bRxPSPoll) {
715                 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[0].sTxPSQueue)) != NULL) {
716                     if (skb_queue_empty(&pMgmt->sNodeDBTable[0].sTxPSQueue)) {
717                         pMgmt->abyPSTxMap[0] &= ~byMask[0];
718                         pDevice->bMoreData = false;
719                     }
720                     else {
721                         pDevice->bMoreData = true;
722                     }
723
724                     if (nsDMA_tx_packet(pDevice, TYPE_AC0DMA, skb) != 0) {
725                         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Multicast ps tx fail \n");
726                     }
727
728                     pMgmt->sNodeDBTable[0].wEnQueueCnt--;
729                 }
730             }
731
732             // PS nodes tx
733             for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) {
734                 if (pMgmt->sNodeDBTable[ii].bActive &&
735                     pMgmt->sNodeDBTable[ii].bRxPSPoll) {
736                     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Index=%d Enqueu Cnt= %d\n",
737                                ii, pMgmt->sNodeDBTable[ii].wEnQueueCnt);
738                     while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) != NULL) {
739                         if (skb_queue_empty(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) {
740                             // clear tx map
741                             pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[ii].wAID >> 3] &=
742                                     ~byMask[pMgmt->sNodeDBTable[ii].wAID & 7];
743                             pDevice->bMoreData = false;
744                         }
745                         else {
746                             pDevice->bMoreData = true;
747                         }
748
749                         if (nsDMA_tx_packet(pDevice, TYPE_AC0DMA, skb) != 0) {
750                             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "sta ps tx fail \n");
751                         }
752
753                         pMgmt->sNodeDBTable[ii].wEnQueueCnt--;
754                         // check if sta ps enable, wait next pspoll
755                         // if sta ps disable, send all pending buffers.
756                         if (pMgmt->sNodeDBTable[ii].bPSEnable)
757                             break;
758                     }
759                     if (skb_queue_empty(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) {
760                         // clear tx map
761                         pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[ii].wAID >> 3] &=
762                                     ~byMask[pMgmt->sNodeDBTable[ii].wAID & 7];
763                         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Index=%d PS queue clear \n", ii);
764                     }
765                     pMgmt->sNodeDBTable[ii].bRxPSPoll = false;
766                 }
767             }
768
769             s_bCommandComplete(pDevice);
770             break;
771
772         case WLAN_CMD_RADIO_START:
773
774             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState == WLAN_CMD_RADIO_START\n");
775        //     if (pDevice->bRadioCmd == true)
776        //         CARDbRadioPowerOn(pDevice);
777        //     else
778        //         CARDbRadioPowerOff(pDevice);
779
780        {
781                int ntStatus = STATUS_SUCCESS;
782         u8            byTmp;
783
784         ntStatus = CONTROLnsRequestIn(pDevice,
785                                     MESSAGE_TYPE_READ,
786                                     MAC_REG_GPIOCTL1,
787                                     MESSAGE_REQUEST_MACREG,
788                                     1,
789                                     &byTmp);
790
791         if ( ntStatus != STATUS_SUCCESS ) {
792                 s_bCommandComplete(pDevice);
793                 spin_unlock_irq(&pDevice->lock);
794                 return;
795         }
796         if ( (byTmp & GPIO3_DATA) == 0 ) {
797             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" WLAN_CMD_RADIO_START_OFF........................\n");
798                 // Old commands are useless.
799                 // empty command Q
800                pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
801                 pDevice->uCmdDequeueIdx = 0;
802                 pDevice->uCmdEnqueueIdx = 0;
803                 //0415pDevice->bCmdRunning = false;
804                 pDevice->bCmdClear = true;
805                 pDevice->bStopTx0Pkt = false;
806                 pDevice->bStopDataPkt = true;
807
808                 pDevice->byKeyIndex = 0;
809                 pDevice->bTransmitKey = false;
810             spin_unlock_irq(&pDevice->lock);
811             KeyvInitTable(pDevice,&pDevice->sKey);
812             spin_lock_irq(&pDevice->lock);
813                pMgmt->byCSSPK = KEY_CTL_NONE;
814                 pMgmt->byCSSGK = KEY_CTL_NONE;
815
816           if (pDevice->bLinkPass == true) {
817                 // reason = 8 : disassoc because sta has left
818                 vMgrDisassocBeginSta((void *) pDevice,
819                                      pMgmt,
820                                      pMgmt->abyCurrBSSID,
821                                      (8),
822                                      &Status);
823                        pDevice->bLinkPass = false;
824                 // unlock command busy
825                         pMgmt->eCurrState = WMAC_STATE_IDLE;
826                         pMgmt->sNodeDBTable[0].bActive = false;
827                     // if(pDevice->bWPASuppWextEnabled == true)
828                         {
829                         union iwreq_data  wrqu;
830                         memset(&wrqu, 0, sizeof (wrqu));
831                           wrqu.ap_addr.sa_family = ARPHRD_ETHER;
832                         PRINT_K("wireless_send_event--->SIOCGIWAP(disassociated)\n");
833                         wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
834                        }
835                 }
836                        pDevice->bwextstep0 = false;
837                         pDevice->bwextstep1 = false;
838                         pDevice->bwextstep2 = false;
839                         pDevice->bwextstep3 = false;
840                       pDevice->bWPASuppWextEnabled = false;
841                           //clear current SSID
842                   pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
843                   pItemSSID->len = 0;
844                   memset(pItemSSID->abySSID, 0, WLAN_SSID_MAXLEN);
845                 //clear desired SSID
846                 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
847                 pItemSSID->len = 0;
848                 memset(pItemSSID->abySSID, 0, WLAN_SSID_MAXLEN);
849
850             netif_stop_queue(pDevice->dev);
851             CARDbRadioPowerOff(pDevice);
852              MACvRegBitsOn(pDevice,MAC_REG_GPIOCTL1,GPIO3_INTMD);
853             ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_OFF);
854             pDevice->bHWRadioOff = true;
855         } else {
856             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" WLAN_CMD_RADIO_START_ON........................\n");
857             pDevice->bHWRadioOff = false;
858                 CARDbRadioPowerOn(pDevice);
859             MACvRegBitsOff(pDevice,MAC_REG_GPIOCTL1,GPIO3_INTMD);
860             ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_ON);
861         }
862       }
863
864             s_bCommandComplete(pDevice);
865             break;
866
867         case WLAN_CMD_CHANGE_BBSENSITIVITY_START:
868
869             pDevice->bStopDataPkt = true;
870             pDevice->byBBVGACurrent = pDevice->byBBVGANew;
871             BBvSetVGAGainOffset(pDevice, pDevice->byBBVGACurrent);
872             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Change sensitivity pDevice->byBBVGACurrent = %x\n", pDevice->byBBVGACurrent);
873             pDevice->bStopDataPkt = false;
874             s_bCommandComplete(pDevice);
875             break;
876
877         case WLAN_CMD_TBTT_WAKEUP_START:
878             PSbIsNextTBTTWakeUp(pDevice);
879             s_bCommandComplete(pDevice);
880             break;
881
882         case WLAN_CMD_BECON_SEND_START:
883             bMgrPrepareBeaconToSend(pDevice, pMgmt);
884             s_bCommandComplete(pDevice);
885             break;
886
887         case WLAN_CMD_SETPOWER_START:
888
889             RFbSetPower(pDevice, pDevice->wCurrentRate, pMgmt->uCurrChannel);
890
891             s_bCommandComplete(pDevice);
892             break;
893
894         case WLAN_CMD_CHANGE_ANTENNA_START:
895             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Change from Antenna%d to", (int)pDevice->dwRxAntennaSel);
896             if ( pDevice->dwRxAntennaSel == 0) {
897                 pDevice->dwRxAntennaSel=1;
898                 if (pDevice->bTxRxAntInv == true)
899                     BBvSetAntennaMode(pDevice, ANT_RXA);
900                 else
901                     BBvSetAntennaMode(pDevice, ANT_RXB);
902             } else {
903                 pDevice->dwRxAntennaSel=0;
904                 if (pDevice->bTxRxAntInv == true)
905                     BBvSetAntennaMode(pDevice, ANT_RXB);
906                 else
907                     BBvSetAntennaMode(pDevice, ANT_RXA);
908             }
909             s_bCommandComplete(pDevice);
910             break;
911
912         case WLAN_CMD_REMOVE_ALLKEY_START:
913             KeybRemoveAllKey(pDevice, &(pDevice->sKey), pDevice->abyBSSID);
914             s_bCommandComplete(pDevice);
915             break;
916
917         case WLAN_CMD_MAC_DISPOWERSAVING_START:
918             ControlvReadByte (pDevice, MESSAGE_REQUEST_MACREG, MAC_REG_PSCTL, &byData);
919             if ( (byData & PSCTL_PS) != 0 ) {
920                 // disable power saving hw function
921                 CONTROLnsRequestOut(pDevice,
922                                 MESSAGE_TYPE_DISABLE_PS,
923                                 0,
924                                 0,
925                                 0,
926                                 NULL
927                                 );
928             }
929             s_bCommandComplete(pDevice);
930             break;
931
932         case WLAN_CMD_11H_CHSW_START:
933             CARDbSetMediaChannel(pDevice, pDevice->byNewChannel);
934             pDevice->bChannelSwitch = false;
935             pMgmt->uCurrChannel = pDevice->byNewChannel;
936             pDevice->bStopDataPkt = false;
937             s_bCommandComplete(pDevice);
938             break;
939
940         default:
941             s_bCommandComplete(pDevice);
942             break;
943     } //switch
944
945     spin_unlock_irq(&pDevice->lock);
946     return;
947 }
948
949 static int s_bCommandComplete(struct vnt_private *pDevice)
950 {
951         struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
952         PWLAN_IE_SSID pSSID;
953         int bRadioCmd = false;
954         int bForceSCAN = true;
955
956     pDevice->eCommandState = WLAN_CMD_IDLE;
957     if (pDevice->cbFreeCmdQueue == CMD_Q_SIZE) {
958         //Command Queue Empty
959         pDevice->bCmdRunning = false;
960         return true;
961     }
962     else {
963         pDevice->eCommand = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].eCmd;
964         pSSID = (PWLAN_IE_SSID)pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].abyCmdDesireSSID;
965         bRadioCmd = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].bRadioCmd;
966         bForceSCAN = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].bForceSCAN;
967         ADD_ONE_WITH_WRAP_AROUND(pDevice->uCmdDequeueIdx, CMD_Q_SIZE);
968         pDevice->cbFreeCmdQueue++;
969         pDevice->bCmdRunning = true;
970         switch ( pDevice->eCommand ) {
971             case WLAN_CMD_BSSID_SCAN:
972                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState= WLAN_CMD_BSSID_SCAN\n");
973                 pDevice->eCommandState = WLAN_CMD_SCAN_START;
974                 pMgmt->uScanChannel = 0;
975                 if (pSSID->len != 0) {
976                     memcpy(pMgmt->abyScanSSID, pSSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
977                 } else {
978                     memset(pMgmt->abyScanSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
979                 }
980 /*
981                 if ((bForceSCAN == false) && (pDevice->bLinkPass == true)) {
982                     if ((pSSID->len == ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len) &&
983                         ( !memcmp(pSSID->abySSID, ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID, pSSID->len))) {
984                         pDevice->eCommandState = WLAN_CMD_IDLE;
985                     }
986                 }
987 */
988                 break;
989             case WLAN_CMD_SSID:
990                 pDevice->eCommandState = WLAN_CMD_SSID_START;
991                 if (pSSID->len > WLAN_SSID_MAXLEN)
992                     pSSID->len = WLAN_SSID_MAXLEN;
993                 if (pSSID->len != 0)
994                     memcpy(pMgmt->abyDesireSSID, pSSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
995                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState= WLAN_CMD_SSID_START\n");
996                 break;
997             case WLAN_CMD_DISASSOCIATE:
998                 pDevice->eCommandState = WLAN_CMD_DISASSOCIATE_START;
999                 break;
1000             case WLAN_CMD_RX_PSPOLL:
1001                 pDevice->eCommandState = WLAN_CMD_TX_PSPACKET_START;
1002                 break;
1003             case WLAN_CMD_RUN_AP:
1004                 pDevice->eCommandState = WLAN_CMD_AP_MODE_START;
1005                 break;
1006             case WLAN_CMD_RADIO:
1007                 pDevice->eCommandState = WLAN_CMD_RADIO_START;
1008                 pDevice->bRadioCmd = bRadioCmd;
1009                 break;
1010             case WLAN_CMD_CHANGE_BBSENSITIVITY:
1011                 pDevice->eCommandState = WLAN_CMD_CHANGE_BBSENSITIVITY_START;
1012                 break;
1013
1014             case WLAN_CMD_TBTT_WAKEUP:
1015                 pDevice->eCommandState = WLAN_CMD_TBTT_WAKEUP_START;
1016                 break;
1017
1018             case WLAN_CMD_BECON_SEND:
1019                 pDevice->eCommandState = WLAN_CMD_BECON_SEND_START;
1020                 break;
1021
1022             case WLAN_CMD_SETPOWER:
1023                 pDevice->eCommandState = WLAN_CMD_SETPOWER_START;
1024                 break;
1025
1026             case WLAN_CMD_CHANGE_ANTENNA:
1027                 pDevice->eCommandState = WLAN_CMD_CHANGE_ANTENNA_START;
1028                 break;
1029
1030             case WLAN_CMD_REMOVE_ALLKEY:
1031                 pDevice->eCommandState = WLAN_CMD_REMOVE_ALLKEY_START;
1032                 break;
1033
1034             case WLAN_CMD_MAC_DISPOWERSAVING:
1035                 pDevice->eCommandState = WLAN_CMD_MAC_DISPOWERSAVING_START;
1036                 break;
1037
1038             case WLAN_CMD_11H_CHSW:
1039                 pDevice->eCommandState = WLAN_CMD_11H_CHSW_START;
1040                 break;
1041
1042             default:
1043                 break;
1044
1045         }
1046         vCommandTimerWait(pDevice, 0);
1047     }
1048
1049     return true;
1050 }
1051
1052 int bScheduleCommand(struct vnt_private *pDevice,
1053                 CMD_CODE eCommand, u8 *pbyItem0)
1054 {
1055
1056     if (pDevice->cbFreeCmdQueue == 0) {
1057         return (false);
1058     }
1059     pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].eCmd = eCommand;
1060     pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bForceSCAN = true;
1061     memset(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID, 0 , WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
1062     if (pbyItem0 != NULL) {
1063         switch (eCommand) {
1064             case WLAN_CMD_BSSID_SCAN:
1065                 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bForceSCAN = false;
1066                 memcpy(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID,
1067                          pbyItem0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
1068                 break;
1069
1070             case WLAN_CMD_SSID:
1071                 memcpy(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID,
1072                          pbyItem0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
1073                 break;
1074
1075             case WLAN_CMD_DISASSOCIATE:
1076                 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bNeedRadioOFF = *((int *)pbyItem0);
1077                 break;
1078 /*
1079             case WLAN_CMD_DEAUTH:
1080                 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].wDeAuthenReason = *((u16 *)pbyItem0);
1081                 break;
1082 */
1083
1084             case WLAN_CMD_RADIO:
1085                 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bRadioCmd = *((int *)pbyItem0);
1086                 break;
1087
1088             default:
1089                 break;
1090         }
1091     }
1092
1093     ADD_ONE_WITH_WRAP_AROUND(pDevice->uCmdEnqueueIdx, CMD_Q_SIZE);
1094     pDevice->cbFreeCmdQueue--;
1095
1096     if (pDevice->bCmdRunning == false) {
1097         s_bCommandComplete(pDevice);
1098     }
1099     else {
1100     }
1101     return (true);
1102
1103 }
1104
1105 /*
1106  * Description:
1107  *      Clear BSSID_SCAN cmd in CMD Queue
1108  *
1109  * Parameters:
1110  *  In:
1111  *      hDeviceContext  - Pointer to the adapter
1112  *      eCommand        - Command
1113  *  Out:
1114  *      none
1115  *
1116  * Return Value: true if success; otherwise false
1117  *
1118  */
1119 static int s_bClearBSSID_SCAN(struct vnt_private *pDevice)
1120 {
1121         unsigned int uCmdDequeueIdx = pDevice->uCmdDequeueIdx;
1122         unsigned int ii;
1123
1124     if ((pDevice->cbFreeCmdQueue < CMD_Q_SIZE) && (uCmdDequeueIdx != pDevice->uCmdEnqueueIdx)) {
1125         for (ii = 0; ii < (CMD_Q_SIZE - pDevice->cbFreeCmdQueue); ii ++) {
1126             if (pDevice->eCmdQueue[uCmdDequeueIdx].eCmd == WLAN_CMD_BSSID_SCAN)
1127                 pDevice->eCmdQueue[uCmdDequeueIdx].eCmd = WLAN_CMD_IDLE;
1128             ADD_ONE_WITH_WRAP_AROUND(uCmdDequeueIdx, CMD_Q_SIZE);
1129             if (uCmdDequeueIdx == pDevice->uCmdEnqueueIdx)
1130                 break;
1131         }
1132     }
1133     return true;
1134 }
1135
1136 //mike add:reset command timer
1137 void vResetCommandTimer(struct vnt_private *pDevice)
1138 {
1139         cancel_delayed_work_sync(&pDevice->run_command_work);
1140
1141         pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
1142         pDevice->uCmdDequeueIdx = 0;
1143         pDevice->uCmdEnqueueIdx = 0;
1144         pDevice->eCommandState = WLAN_CMD_IDLE;
1145         pDevice->bCmdRunning = false;
1146         pDevice->bCmdClear = false;
1147 }