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