wcmd.c revision 3bd1a38ba8bf190d560d65bfbce5343d1262678a
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
60
61
62/*---------------------  Static Classes  ----------------------------*/
63
64/*---------------------  Static Variables  --------------------------*/
65static int msglevel = MSG_LEVEL_INFO;
66//static int          msglevel                =MSG_LEVEL_DEBUG;
67/*---------------------  Static Functions  --------------------------*/
68
69static
70void
71s_vProbeChannel(
72	PSDevice pDevice
73);
74
75
76static
77PSTxMgmtPacket
78s_MgrMakeProbeRequest(
79	PSDevice pDevice,
80	PSMgmtObject pMgmt,
81	unsigned char *pScanBSSID,
82	PWLAN_IE_SSID pSSID,
83	PWLAN_IE_SUPP_RATES pCurrRates,
84	PWLAN_IE_SUPP_RATES pCurrExtSuppRates
85);
86
87
88static
89bool
90s_bCommandComplete(
91	PSDevice pDevice
92);
93
94/*---------------------  Export Variables  --------------------------*/
95
96
97/*---------------------  Export Functions  --------------------------*/
98
99
100
101/*
102 * Description:
103 *      Stop AdHoc beacon during scan process
104 *
105 * Parameters:
106 *  In:
107 *      pDevice     - Pointer to the adapter
108 *  Out:
109 *      none
110 *
111 * Return Value: none
112 *
113 */
114static
115void
116vAdHocBeaconStop(PSDevice  pDevice)
117{
118
119	PSMgmtObject    pMgmt = &(pDevice->sMgmtObj);
120	bool bStop;
121
122	/*
123	 * temporarily stop Beacon packet for AdHoc Server
124	 * if all of the following conditions are met:
125	 *  (1) STA is in AdHoc mode
126	 *  (2) VT3253 is programmed as automatic Beacon Transmitting
127	 *  (3) One of the following conditions is met
128	 *      (3.1) AdHoc channel is in B/G band and the
129	 *      current scan channel is in A band
130	 *      or
131	 *      (3.2) AdHoc channel is in A mode
132	 */
133	bStop = false;
134	if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) &&
135	    (pMgmt->eCurrState >= WMAC_STATE_STARTED))
136	{
137		if ((pMgmt->uIBSSChannel <=  CB_MAX_CHANNEL_24G) &&
138		    (pMgmt->uScanChannel > CB_MAX_CHANNEL_24G))
139		{
140			bStop = true;
141		}
142		if (pMgmt->uIBSSChannel >  CB_MAX_CHANNEL_24G)
143		{
144			bStop = true;
145		}
146	}
147
148	if (bStop)
149	{
150		MACvRegBitsOff(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
151	}
152
153} /* vAdHocBeaconStop */
154
155
156/*
157 * Description:
158 *      Restart AdHoc beacon after scan process complete
159 *
160 * Parameters:
161 *  In:
162 *      pDevice     - Pointer to the adapter
163 *  Out:
164 *      none
165 *
166 * Return Value: none
167 *
168 */
169static
170void
171vAdHocBeaconRestart(PSDevice pDevice)
172{
173	PSMgmtObject    pMgmt = &(pDevice->sMgmtObj);
174
175	/*
176	 * Restart Beacon packet for AdHoc Server
177	 * if all of the following coditions are met:
178	 *  (1) STA is in AdHoc mode
179	 *  (2) VT3253 is programmed as automatic Beacon Transmitting
180	 */
181	if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) &&
182	    (pMgmt->eCurrState >= WMAC_STATE_STARTED))
183	{
184		MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
185	}
186
187}
188
189
190
191
192
193
194/*+
195 *
196 * Routine Description:
197 *   Prepare and send probe request management frames.
198 *
199 *
200 * Return Value:
201 *    none.
202 *
203 -*/
204
205static
206void
207s_vProbeChannel(
208	PSDevice pDevice
209)
210{
211	//1M,   2M,   5M,   11M,  18M,  24M,  36M,  54M
212	unsigned char abyCurrSuppRatesG[] = {WLAN_EID_SUPP_RATES, 8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C};
213	unsigned char abyCurrExtSuppRatesG[] = {WLAN_EID_EXTSUPP_RATES, 4, 0x0C, 0x12, 0x18, 0x60};
214	//6M,   9M,   12M,  48M
215	unsigned char abyCurrSuppRatesA[] = {WLAN_EID_SUPP_RATES, 8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
216	unsigned char abyCurrSuppRatesB[] = {WLAN_EID_SUPP_RATES, 4, 0x02, 0x04, 0x0B, 0x16};
217	unsigned char *pbyRate;
218	PSTxMgmtPacket  pTxPacket;
219	PSMgmtObject    pMgmt = pDevice->pMgmt;
220	unsigned int ii;
221
222
223	if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
224		pbyRate = &abyCurrSuppRatesA[0];
225	} else if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
226		pbyRate = &abyCurrSuppRatesB[0];
227	} else {
228		pbyRate = &abyCurrSuppRatesG[0];
229	}
230	// build an assocreq frame and send it
231	pTxPacket = s_MgrMakeProbeRequest
232		(
233			pDevice,
234			pMgmt,
235			pMgmt->abyScanBSSID,
236			(PWLAN_IE_SSID)pMgmt->abyScanSSID,
237			(PWLAN_IE_SUPP_RATES)pbyRate,
238			(PWLAN_IE_SUPP_RATES)abyCurrExtSuppRatesG
239			);
240
241	if (pTxPacket != NULL) {
242		for (ii = 0; ii < 2; ii++) {
243			if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
244				DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Probe request sending fail.. \n");
245			}
246			else {
247				DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Probe request is sending.. \n");
248			}
249		}
250	}
251
252}
253
254
255
256
257/*+
258 *
259 * Routine Description:
260 *  Constructs an probe request frame
261 *
262 *
263 * Return Value:
264 *    A ptr to Tx frame or NULL on allocation failue
265 *
266 -*/
267
268
269PSTxMgmtPacket
270s_MgrMakeProbeRequest(
271	PSDevice pDevice,
272	PSMgmtObject pMgmt,
273	unsigned char *pScanBSSID,
274	PWLAN_IE_SSID pSSID,
275	PWLAN_IE_SUPP_RATES pCurrRates,
276	PWLAN_IE_SUPP_RATES pCurrExtSuppRates
277
278)
279{
280	PSTxMgmtPacket      pTxPacket = NULL;
281	WLAN_FR_PROBEREQ    sFrame;
282
283
284	pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
285	memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_PROBEREQ_FR_MAXLEN);
286	pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
287	sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
288	sFrame.len = WLAN_PROBEREQ_FR_MAXLEN;
289	vMgrEncodeProbeRequest(&sFrame);
290	sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
291		(
292			WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
293			WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_PROBEREQ)
294));
295	memcpy(sFrame.pHdr->sA3.abyAddr1, pScanBSSID, WLAN_ADDR_LEN);
296	memcpy(sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
297	memcpy(sFrame.pHdr->sA3.abyAddr3, pScanBSSID, WLAN_BSSID_LEN);
298	// Copy the SSID, pSSID->len=0 indicate broadcast SSID
299	sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
300	sFrame.len += pSSID->len + WLAN_IEHDR_LEN;
301	memcpy(sFrame.pSSID, pSSID, pSSID->len + WLAN_IEHDR_LEN);
302	sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
303	sFrame.len += pCurrRates->len + WLAN_IEHDR_LEN;
304	memcpy(sFrame.pSuppRates, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
305	// Copy the extension rate set
306	if (pDevice->eCurrentPHYType == PHY_TYPE_11G) {
307		sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
308		sFrame.len += pCurrExtSuppRates->len + WLAN_IEHDR_LEN;
309		memcpy(sFrame.pExtSuppRates, pCurrExtSuppRates, pCurrExtSuppRates->len + WLAN_IEHDR_LEN);
310	}
311	pTxPacket->cbMPDULen = sFrame.len;
312	pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
313
314	return pTxPacket;
315}
316
317
318
319
320
321void
322vCommandTimerWait(
323	void *hDeviceContext,
324	unsigned int MSecond
325)
326{
327	PSDevice        pDevice = (PSDevice)hDeviceContext;
328
329	init_timer(&pDevice->sTimerCommand);
330	pDevice->sTimerCommand.data = (unsigned long) pDevice;
331	pDevice->sTimerCommand.function = (TimerFunction)vCommandTimer;
332	// RUN_AT :1 msec ~= (HZ/1024)
333	pDevice->sTimerCommand.expires = (unsigned int)RUN_AT((MSecond * HZ) >> 10);
334	add_timer(&pDevice->sTimerCommand);
335	return;
336}
337
338
339
340
341void
342vCommandTimer(
343	void *hDeviceContext
344)
345{
346	PSDevice        pDevice = (PSDevice)hDeviceContext;
347	PSMgmtObject    pMgmt = pDevice->pMgmt;
348	PWLAN_IE_SSID   pItemSSID;
349	PWLAN_IE_SSID   pItemSSIDCurr;
350	CMD_STATUS      Status;
351	unsigned int ii;
352	unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
353	struct sk_buff  *skb;
354
355
356	if (pDevice->dwDiagRefCount != 0)
357		return;
358	if (pDevice->bCmdRunning != true)
359		return;
360
361	spin_lock_irq(&pDevice->lock);
362
363	switch (pDevice->eCommandState) {
364
365	case WLAN_CMD_SCAN_START:
366
367		pDevice->byReAssocCount = 0;
368		if (pDevice->bRadioOff == true) {
369			s_bCommandComplete(pDevice);
370			spin_unlock_irq(&pDevice->lock);
371			return;
372		}
373
374		if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
375			s_bCommandComplete(pDevice);
376			CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, OP_MODE_AP);
377			spin_unlock_irq(&pDevice->lock);
378			return;
379		}
380
381		DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "eCommandState= WLAN_CMD_SCAN_START\n");
382		pItemSSID = (PWLAN_IE_SSID)pMgmt->abyScanSSID;
383		// wait all Data TD complete
384		if (pDevice->iTDUsed[TYPE_AC0DMA] != 0) {
385			spin_unlock_irq(&pDevice->lock);
386			vCommandTimerWait((void *)pDevice, 10);
387			return;
388		}
389
390		if (pMgmt->uScanChannel == 0) {
391			pMgmt->uScanChannel = pDevice->byMinChannel;
392			// Set Baseband to be more sensitive.
393
394		}
395		if (pMgmt->uScanChannel > pDevice->byMaxChannel) {
396			pMgmt->eScanState = WMAC_NO_SCANNING;
397
398			// Set Baseband's sensitivity back.
399			// Set channel back
400			set_channel(pMgmt->pAdapter, pMgmt->uCurrChannel);
401			DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Scanning, set back to channel: [%d]\n", pMgmt->uCurrChannel);
402			if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
403				CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, OP_MODE_ADHOC);
404			} else {
405				CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, OP_MODE_INFRASTRUCTURE);
406			}
407			vAdHocBeaconRestart(pDevice);
408			s_bCommandComplete(pDevice);
409
410		} else {
411//2008-8-4 <add> by chester
412			if (!is_channel_valid(pMgmt->uScanChannel)) {
413				DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Invalid channel pMgmt->uScanChannel = %d \n", pMgmt->uScanChannel);
414				s_bCommandComplete(pDevice);
415				spin_unlock_irq(&pDevice->lock);
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((void *)pDevice, pDevice->bLinkPass);
430				pMgmt->eScanState = WMAC_IS_SCANNING;
431
432			}
433
434			vAdHocBeaconStop(pDevice);
435
436			if (set_channel(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 (!is_channel_valid(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((void *)pDevice, WCMD_ACTIVE_SCAN_TIME);
459				return;
460			} else {
461				spin_unlock_irq(&pDevice->lock);
462				vCommandTimerWait((void *)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		set_channel(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((void *)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((void *)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((void *)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);
550		printk("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((void *)pDevice);
584		BSSvClearNodeDBTable(pDevice, 0);
585
586		vMgrJoinBSSBegin((void *)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) because sta has left ESS
592			if (pMgmt->eCurrState >= WMAC_STATE_AUTH) {
593				vMgrDeAuthenBeginSta((void *)pDevice, pMgmt, pMgmt->abyCurrBSSID, (3), &Status);
594			}
595			// Call mgr to begin the authentication
596			vMgrAuthenBeginSta((void *)pDevice, pMgmt, &Status);
597			if (Status == CMD_STATUS_SUCCESS) {
598				pDevice->byLinkWaitCount = 0;
599				pDevice->eCommandState = WLAN_AUTHENTICATE_WAIT;
600				vCommandTimerWait((void *)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((void *)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((void *)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((void *)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((void *)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((void *)pDevice, AUTHENTICATE_TIMEOUT/2);
685			return;
686		}
687		pDevice->byLinkWaitCount = 0;
688		s_bCommandComplete(pDevice);
689		break;
690
691	case WLAN_ASSOCIATE_WAIT:
692		if (pMgmt->eCurrState == WMAC_STATE_ASSOC) {
693			DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "eCurrState == WMAC_STATE_ASSOC\n");
694			if (pDevice->ePSMode != WMAC_POWER_CAM) {
695				PSvEnablePowerSaving((void *)pDevice, pMgmt->wListenInterval);
696			}
697			if (pMgmt->eAuthenMode >= WMAC_AUTH_WPA) {
698				KeybRemoveAllKey(&(pDevice->sKey), pDevice->abyBSSID, pDevice->PortOffset);
699			}
700			pDevice->bLinkPass = true;
701			pDevice->byLinkWaitCount = 0;
702			pDevice->byReAssocCount = 0;
703			bClearBSSID_SCAN(pDevice);
704			if (pDevice->byFOETuning) {
705				BBvSetFOE(pDevice->PortOffset);
706				PSbSendNullPacket(pDevice);
707			}
708			if (netif_queue_stopped(pDevice->dev)) {
709				netif_wake_queue(pDevice->dev);
710			}
711#ifdef TxInSleep
712			if (pDevice->IsTxDataTrigger != false)   {    //TxDataTimer is not triggered at the first time
713				// printk("Re-initial TxDataTimer****\n");
714				del_timer(&pDevice->sTimerTxData);
715				init_timer(&pDevice->sTimerTxData);
716				pDevice->sTimerTxData.data = (unsigned long) pDevice;
717				pDevice->sTimerTxData.function = (TimerFunction)BSSvSecondTxData;
718				pDevice->sTimerTxData.expires = RUN_AT(10*HZ);      //10s callback
719				pDevice->fTxDataInSleep = false;
720				pDevice->nTxDataTimeCout = 0;
721			}
722			else {
723				// printk("mike:-->First time trigger TimerTxData InSleep\n");
724			}
725			pDevice->IsTxDataTrigger = true;
726			add_timer(&pDevice->sTimerTxData);
727#endif
728		}
729		else if (pMgmt->eCurrState < WMAC_STATE_ASSOCPENDING) {
730			printk("WLAN_ASSOCIATE_WAIT:Association Fail???\n");
731		}
732		else  if (pDevice->byLinkWaitCount <= 4) {    //mike add:wait another 2 sec if associated_frame delay!
733			pDevice->byLinkWaitCount++;
734			printk("WLAN_ASSOCIATE_WAIT:wait %d times!!\n", pDevice->byLinkWaitCount);
735			spin_unlock_irq(&pDevice->lock);
736			vCommandTimerWait((void *)pDevice, ASSOCIATE_TIMEOUT/2);
737			return;
738		}
739		pDevice->byLinkWaitCount = 0;
740
741		s_bCommandComplete(pDevice);
742		break;
743
744	case WLAN_CMD_AP_MODE_START:
745		DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "eCommandState == WLAN_CMD_AP_MODE_START\n");
746
747		if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
748			del_timer(&pMgmt->sTimerSecondCallback);
749			pMgmt->eCurrState = WMAC_STATE_IDLE;
750			pMgmt->eCurrMode = WMAC_MODE_STANDBY;
751			pDevice->bLinkPass = false;
752			if (pDevice->bEnableHostWEP == true)
753				BSSvClearNodeDBTable(pDevice, 1);
754			else
755				BSSvClearNodeDBTable(pDevice, 0);
756			pDevice->uAssocCount = 0;
757			pMgmt->eCurrState = WMAC_STATE_IDLE;
758			pDevice->bFixRate = false;
759
760			vMgrCreateOwnIBSS((void *)pDevice, &Status);
761			if (Status != CMD_STATUS_SUCCESS) {
762				DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " vMgrCreateOwnIBSS fail ! \n");
763			}
764			// alway turn off unicast bit
765			MACvRegBitsOff(pDevice->PortOffset, MAC_REG_RCR, RCR_UNICAST);
766			pDevice->byRxMode &= ~RCR_UNICAST;
767			DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wcmd: rx_mode = %x\n", pDevice->byRxMode);
768			BSSvAddMulticastNode(pDevice);
769			if (netif_queue_stopped(pDevice->dev)) {
770				netif_wake_queue(pDevice->dev);
771			}
772			pDevice->bLinkPass = true;
773			add_timer(&pMgmt->sTimerSecondCallback);
774		}
775		s_bCommandComplete(pDevice);
776		break;
777
778	case WLAN_CMD_TX_PSPACKET_START:
779		// DTIM Multicast tx
780		if (pMgmt->sNodeDBTable[0].bRxPSPoll) {
781			while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[0].sTxPSQueue)) != NULL) {
782				if (skb_queue_empty(&pMgmt->sNodeDBTable[0].sTxPSQueue)) {
783					pMgmt->abyPSTxMap[0] &= ~byMask[0];
784					pDevice->bMoreData = false;
785				}
786				else {
787					pDevice->bMoreData = true;
788				}
789				if (!device_dma0_xmit(pDevice, skb, 0)) {
790					DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Multicast ps tx fail \n");
791				}
792				pMgmt->sNodeDBTable[0].wEnQueueCnt--;
793			}
794		}
795
796		// PS nodes tx
797		for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) {
798			if (pMgmt->sNodeDBTable[ii].bActive &&
799			    pMgmt->sNodeDBTable[ii].bRxPSPoll) {
800				DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Index=%d Enqueu Cnt= %d\n",
801					ii, pMgmt->sNodeDBTable[ii].wEnQueueCnt);
802				while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) != NULL) {
803					if (skb_queue_empty(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) {
804						// clear tx map
805						pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[ii].wAID >> 3] &=
806							~byMask[pMgmt->sNodeDBTable[ii].wAID & 7];
807						pDevice->bMoreData = false;
808					}
809					else {
810						pDevice->bMoreData = true;
811					}
812					if (!device_dma0_xmit(pDevice, skb, ii)) {
813						DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "sta ps tx fail \n");
814					}
815					pMgmt->sNodeDBTable[ii].wEnQueueCnt--;
816					// check if sta ps enabled, and wait next pspoll.
817					// if sta ps disable, then send all pending buffers.
818					if (pMgmt->sNodeDBTable[ii].bPSEnable)
819						break;
820				}
821				if (skb_queue_empty(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) {
822					// clear tx map
823					pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[ii].wAID >> 3] &=
824						~byMask[pMgmt->sNodeDBTable[ii].wAID & 7];
825					DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Index=%d PS queue clear \n", ii);
826				}
827				pMgmt->sNodeDBTable[ii].bRxPSPoll = false;
828			}
829		}
830
831		s_bCommandComplete(pDevice);
832		break;
833
834
835	case WLAN_CMD_RADIO_START:
836		DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "eCommandState == WLAN_CMD_RADIO_START\n");
837		if (pDevice->bRadioCmd == true)
838			CARDbRadioPowerOn(pDevice);
839		else
840			CARDbRadioPowerOff(pDevice);
841
842		s_bCommandComplete(pDevice);
843		break;
844
845
846	case WLAN_CMD_CHECK_BBSENSITIVITY_CHANGE:
847		//DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "eCommandState == WLAN_CMD_CHECK_BBSENSITIVITY_START\n");
848		// wait all TD complete
849		if (pDevice->iTDUsed[TYPE_AC0DMA] != 0) {
850			vCommandTimerWait((void *)pDevice, 10);
851			spin_unlock_irq(&pDevice->lock);
852			return;
853		}
854		if (pDevice->iTDUsed[TYPE_TXDMA0] != 0) {
855			vCommandTimerWait((void *)pDevice, 10);
856			spin_unlock_irq(&pDevice->lock);
857			return;
858		}
859		pDevice->byBBVGACurrent = pDevice->byBBVGANew;
860		BBvSetVGAGainOffset(pDevice, pDevice->byBBVGACurrent);
861		DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "SetVGAGainOffset %02X\n", pDevice->byBBVGACurrent);
862		s_bCommandComplete(pDevice);
863		break;
864
865	default:
866		s_bCommandComplete(pDevice);
867		break;
868
869	} //switch
870	spin_unlock_irq(&pDevice->lock);
871	return;
872
873}
874
875
876static
877bool
878s_bCommandComplete(
879	PSDevice pDevice
880)
881{
882	PWLAN_IE_SSID pSSID;
883	bool bRadioCmd = false;
884	//unsigned short wDeAuthenReason = 0;
885	bool bForceSCAN = true;
886	PSMgmtObject  pMgmt = pDevice->pMgmt;
887
888
889	pDevice->eCommandState = WLAN_CMD_IDLE;
890	if (pDevice->cbFreeCmdQueue == CMD_Q_SIZE) {
891		//Command Queue Empty
892		pDevice->bCmdRunning = false;
893		return true;
894	}
895	else {
896		pDevice->eCommand = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].eCmd;
897		pSSID = (PWLAN_IE_SSID)pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].abyCmdDesireSSID;
898		bRadioCmd = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].bRadioCmd;
899		bForceSCAN = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].bForceSCAN;
900		ADD_ONE_WITH_WRAP_AROUND(pDevice->uCmdDequeueIdx, CMD_Q_SIZE);
901		pDevice->cbFreeCmdQueue++;
902		pDevice->bCmdRunning = true;
903		switch (pDevice->eCommand) {
904		case WLAN_CMD_BSSID_SCAN:
905			DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "eCommandState= WLAN_CMD_BSSID_SCAN\n");
906			pDevice->eCommandState = WLAN_CMD_SCAN_START;
907			pMgmt->uScanChannel = 0;
908			if (pSSID->len != 0) {
909				memcpy(pMgmt->abyScanSSID, pSSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
910			} else {
911				memset(pMgmt->abyScanSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
912			}
913/*
914  if ((bForceSCAN == false) && (pDevice->bLinkPass == true)) {
915  if ((pSSID->len == ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len) &&
916  (!memcmp(pSSID->abySSID, ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID, pSSID->len))) {
917  pDevice->eCommandState = WLAN_CMD_IDLE;
918  }
919  }
920*/
921			break;
922		case WLAN_CMD_SSID:
923			pDevice->eCommandState = WLAN_CMD_SSID_START;
924			if (pSSID->len > WLAN_SSID_MAXLEN)
925				pSSID->len = WLAN_SSID_MAXLEN;
926			if (pSSID->len != 0)
927				memcpy(pDevice->pMgmt->abyDesireSSID, pSSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
928			DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "eCommandState= WLAN_CMD_SSID_START\n");
929			break;
930		case WLAN_CMD_DISASSOCIATE:
931			pDevice->eCommandState = WLAN_CMD_DISASSOCIATE_START;
932			break;
933		case WLAN_CMD_RX_PSPOLL:
934			pDevice->eCommandState = WLAN_CMD_TX_PSPACKET_START;
935			break;
936		case WLAN_CMD_RUN_AP:
937			pDevice->eCommandState = WLAN_CMD_AP_MODE_START;
938			break;
939		case WLAN_CMD_RADIO:
940			pDevice->eCommandState = WLAN_CMD_RADIO_START;
941			pDevice->bRadioCmd = bRadioCmd;
942			break;
943		case WLAN_CMD_CHANGE_BBSENSITIVITY:
944			pDevice->eCommandState = WLAN_CMD_CHECK_BBSENSITIVITY_CHANGE;
945			break;
946
947		default:
948			break;
949
950		}
951
952		vCommandTimerWait((void *)pDevice, 0);
953	}
954
955	return true;
956}
957
958
959
960bool bScheduleCommand(
961	void *hDeviceContext,
962	CMD_CODE    eCommand,
963	unsigned char *pbyItem0
964)
965{
966	PSDevice        pDevice = (PSDevice)hDeviceContext;
967
968
969	if (pDevice->cbFreeCmdQueue == 0) {
970		return (false);
971	}
972	pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].eCmd = eCommand;
973	pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bForceSCAN = true;
974	memset(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID, 0 , WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
975
976	if (pbyItem0 != NULL) {
977		switch (eCommand) {
978
979		case WLAN_CMD_BSSID_SCAN:
980			memcpy(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID,
981			       pbyItem0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
982			pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bForceSCAN = false;
983			break;
984
985		case WLAN_CMD_SSID:
986			memcpy(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID,
987			       pbyItem0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
988			break;
989
990		case WLAN_CMD_DISASSOCIATE:
991			pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bNeedRadioOFF = *((int *)pbyItem0);
992			break;
993/*
994  case WLAN_CMD_DEAUTH:
995  pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].wDeAuthenReason = *((unsigned short *)pbyItem0);
996  break;
997*/
998
999		case WLAN_CMD_RX_PSPOLL:
1000			break;
1001
1002		case WLAN_CMD_RADIO:
1003			pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bRadioCmd = *((int *)pbyItem0);
1004			break;
1005
1006		case WLAN_CMD_CHANGE_BBSENSITIVITY:
1007			pDevice->eCommandState = WLAN_CMD_CHECK_BBSENSITIVITY_CHANGE;
1008			break;
1009
1010		default:
1011			break;
1012		}
1013	}
1014
1015	ADD_ONE_WITH_WRAP_AROUND(pDevice->uCmdEnqueueIdx, CMD_Q_SIZE);
1016	pDevice->cbFreeCmdQueue--;
1017
1018	if (pDevice->bCmdRunning == false) {
1019		s_bCommandComplete(pDevice);
1020	}
1021	else {
1022	}
1023	return (true);
1024
1025}
1026
1027/*
1028 * Description:
1029 *      Clear BSSID_SCAN cmd in CMD Queue
1030 *
1031 * Parameters:
1032 *  In:
1033 *      hDeviceContext  - Pointer to the adapter
1034 *      eCommand        - Command
1035 *  Out:
1036 *      none
1037 *
1038 * Return Value: true if success; otherwise false
1039 *
1040 */
1041bool bClearBSSID_SCAN(
1042	void *hDeviceContext
1043)
1044{
1045	PSDevice        pDevice = (PSDevice)hDeviceContext;
1046	unsigned int uCmdDequeueIdx = pDevice->uCmdDequeueIdx;
1047	unsigned int ii;
1048
1049	if ((pDevice->cbFreeCmdQueue < CMD_Q_SIZE) && (uCmdDequeueIdx != pDevice->uCmdEnqueueIdx)) {
1050		for (ii = 0; ii < (CMD_Q_SIZE - pDevice->cbFreeCmdQueue); ii++) {
1051			if (pDevice->eCmdQueue[uCmdDequeueIdx].eCmd == WLAN_CMD_BSSID_SCAN)
1052				pDevice->eCmdQueue[uCmdDequeueIdx].eCmd = WLAN_CMD_IDLE;
1053			ADD_ONE_WITH_WRAP_AROUND(uCmdDequeueIdx, CMD_Q_SIZE);
1054			if (uCmdDequeueIdx == pDevice->uCmdEnqueueIdx)
1055				break;
1056		}
1057	}
1058	return true;
1059}
1060
1061//mike add:reset command timer
1062void
1063vResetCommandTimer(
1064	void *hDeviceContext
1065)
1066{
1067	PSDevice        pDevice = (PSDevice)hDeviceContext;
1068
1069	//delete timer
1070	del_timer(&pDevice->sTimerCommand);
1071	//init timer
1072	init_timer(&pDevice->sTimerCommand);
1073	pDevice->sTimerCommand.data = (unsigned long) pDevice;
1074	pDevice->sTimerCommand.function = (TimerFunction)vCommandTimer;
1075	pDevice->sTimerCommand.expires = RUN_AT(HZ);
1076	pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
1077	pDevice->uCmdDequeueIdx = 0;
1078	pDevice->uCmdEnqueueIdx = 0;
1079	pDevice->eCommandState = WLAN_CMD_IDLE;
1080	pDevice->bCmdRunning = false;
1081	pDevice->bCmdClear = false;
1082}
1083
1084
1085#ifdef TxInSleep
1086void
1087BSSvSecondTxData(
1088	void *hDeviceContext
1089)
1090{
1091	PSDevice        pDevice = (PSDevice)hDeviceContext;
1092	PSMgmtObject  pMgmt = &(pDevice->sMgmtObj);
1093	pDevice->nTxDataTimeCout++;
1094
1095	if (pDevice->nTxDataTimeCout < 4)     //don't tx data if timer less than 40s
1096	{
1097		// printk("mike:%s-->no data Tx not exceed the desired Time as %d\n",__FUNCTION__,
1098		//	(int)pDevice->nTxDataTimeCout);
1099		pDevice->sTimerTxData.expires = RUN_AT(10*HZ);      //10s callback
1100		add_timer(&pDevice->sTimerTxData);
1101		return;
1102	}
1103
1104	spin_lock_irq(&pDevice->lock);
1105#if 1
1106	if (((pDevice->bLinkPass == true) && (pMgmt->eAuthenMode < WMAC_AUTH_WPA)) ||  //open && sharekey linking
1107	   (pDevice->fWPA_Authened == true)) {   //wpa linking
1108#else
1109		if (pDevice->bLinkPass == true) {
1110#endif
1111
1112			//   printk("mike:%s-->InSleep Tx Data Procedure\n",__FUNCTION__);
1113			pDevice->fTxDataInSleep = true;
1114			PSbSendNullPacket(pDevice);      //send null packet
1115			pDevice->fTxDataInSleep = false;
1116		}
1117		spin_unlock_irq(&pDevice->lock);
1118
1119		pDevice->sTimerTxData.expires = RUN_AT(10*HZ);      //10s callback
1120		add_timer(&pDevice->sTimerTxData);
1121		return;
1122	}
1123#endif
1124
1125