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