Linux Audio

Check our new training course

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