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