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