]> git.ipfire.org Git - thirdparty/kernel/linux.git/blame - drivers/staging/vt6655/wcmd.c
Fix common misspellings
[thirdparty/kernel/linux.git] / drivers / staging / vt6655 / wcmd.c
CommitLineData
612822f5 1/*
5449c685
FB
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 *
5449c685
FB
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
5449c685 41#include "ttype.h"
5449c685 42#include "tmacro.h"
5449c685 43#include "device.h"
5449c685 44#include "mac.h"
5449c685 45#include "card.h"
5449c685 46#include "80211hdr.h"
5449c685 47#include "wcmd.h"
5449c685 48#include "wmgr.h"
5449c685 49#include "power.h"
5449c685 50#include "wctl.h"
5449c685 51#include "baseband.h"
5449c685 52#include "rxtx.h"
5449c685 53#include "rf.h"
5449c685 54#include "iowpa.h"
79566eb2 55#include "channel.h"
5449c685
FB
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
6b35b7b3 70void
5449c685 71s_vProbeChannel(
3a215e0f 72 PSDevice pDevice
5449c685
FB
73 );
74
75
76static
77PSTxMgmtPacket
78s_MgrMakeProbeRequest(
3a215e0f
CC
79 PSDevice pDevice,
80 PSMgmtObject pMgmt,
2989e96f 81 unsigned char *pScanBSSID,
3a215e0f
CC
82 PWLAN_IE_SSID pSSID,
83 PWLAN_IE_SUPP_RATES pCurrRates,
84 PWLAN_IE_SUPP_RATES pCurrExtSuppRates
5449c685
FB
85 );
86
612822f5 87
5449c685 88static
7b6a0013 89bool
5449c685
FB
90s_bCommandComplete (
91 PSDevice pDevice
92 );
93
94/*--------------------- Export Variables --------------------------*/
95
96
97/*--------------------- Export Functions --------------------------*/
98
99
612822f5 100
5449c685
FB
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);
7b6a0013 120 bool bStop;
5449c685
FB
121
122 /*
123 * temporarily stop Beacon packet for AdHoc Server
124 * if all of the following coditions 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 */
5a5a2a6a 133 bStop = false;
5449c685
FB
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 {
1b12068a 140 bStop = true;
5449c685
FB
141 }
142 if (pMgmt->uIBSSChannel > CB_MAX_CHANNEL_24G)
143 {
1b12068a 144 bStop = true;
5449c685
FB
145 }
146 }
147
148 if (bStop)
149 {
150 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
151 }
152
612822f5
JL
153} /* vAdHocBeaconStop */
154
5449c685
FB
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
612822f5
JL
192
193
5449c685
FB
194/*+
195 *
196 * Routine Description:
197 * Prepare and send probe request management frames.
198 *
199 *
200 * Return Value:
201 * none.
202 *
203-*/
204
205static
6b35b7b3 206void
5449c685 207s_vProbeChannel(
3a215e0f 208 PSDevice pDevice
5449c685
FB
209 )
210{
211 //1M, 2M, 5M, 11M, 18M, 24M, 36M, 54M
3fc9b584
CC
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};
5449c685 214 //6M, 9M, 12M, 48M
3fc9b584
CC
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};
2989e96f 217 unsigned char *pbyRate;
5449c685
FB
218 PSTxMgmtPacket pTxPacket;
219 PSMgmtObject pMgmt = pDevice->pMgmt;
b6e95cd5 220 unsigned int ii;
5449c685
FB
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) {
7e809a9b 244 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Probe request sending fail.. \n");
5449c685
FB
245 }
246 else {
7e809a9b 247 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Probe request is sending.. \n");
5449c685
FB
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(
3a215e0f
CC
271 PSDevice pDevice,
272 PSMgmtObject pMgmt,
2989e96f 273 unsigned char *pScanBSSID,
3a215e0f
CC
274 PWLAN_IE_SSID pSSID,
275 PWLAN_IE_SUPP_RATES pCurrRates,
276 PWLAN_IE_SUPP_RATES pCurrExtSuppRates
5449c685
FB
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);
2989e96f
CC
286 pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
287 sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
5449c685
FB
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
612822f5 320
6b35b7b3 321void
5449c685 322vCommandTimerWait(
3a215e0f 323 void *hDeviceContext,
b6e95cd5 324 unsigned int MSecond
5449c685
FB
325 )
326{
327 PSDevice pDevice = (PSDevice)hDeviceContext;
328
329 init_timer(&pDevice->sTimerCommand);
e3fd16d0 330 pDevice->sTimerCommand.data = (unsigned long) pDevice;
5449c685
FB
331 pDevice->sTimerCommand.function = (TimerFunction)vCommandTimer;
332 // RUN_AT :1 msec ~= (HZ/1024)
b6e95cd5 333 pDevice->sTimerCommand.expires = (unsigned int)RUN_AT((MSecond * HZ) >> 10);
5449c685
FB
334 add_timer(&pDevice->sTimerCommand);
335 return;
336}
337
338
339
612822f5 340
6b35b7b3 341void
5449c685 342vCommandTimer (
3a215e0f 343 void *hDeviceContext
5449c685
FB
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;
b6e95cd5 351 unsigned int ii;
3fc9b584 352 unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
5449c685
FB
353 struct sk_buff *skb;
354
355
356 if (pDevice->dwDiagRefCount != 0)
357 return;
1b12068a 358 if (pDevice->bCmdRunning != true)
5449c685
FB
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;
1b12068a 368 if (pDevice->bRadioOff == true) {
5449c685
FB
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
7e809a9b 381 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState= WLAN_CMD_SCAN_START\n");
5449c685
FB
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);
e64354c0 386 vCommandTimerWait((void *)pDevice, 10);
5449c685
FB
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
79566eb2 400 set_channel(pMgmt->pAdapter, pMgmt->uCurrChannel);
7e809a9b 401 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Scanning, set back to channel: [%d]\n", pMgmt->uCurrChannel);
5449c685
FB
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
79566eb2 412 if (!is_channel_valid(pMgmt->uScanChannel)) {
7e809a9b 413 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Invalid channel pMgmt->uScanChannel = %d \n",pMgmt->uScanChannel);
5449c685
FB
414 s_bCommandComplete(pDevice);
415 return;
416 }
417//printk("chester-pMgmt->uScanChannel=%d,pDevice->byMaxChannel=%d\n",pMgmt->uScanChannel,pDevice->byMaxChannel);
418 if (pMgmt->uScanChannel == pDevice->byMinChannel) {
419 //pMgmt->eScanType = WMAC_SCAN_ACTIVE;
420 pMgmt->abyScanBSSID[0] = 0xFF;
421 pMgmt->abyScanBSSID[1] = 0xFF;
422 pMgmt->abyScanBSSID[2] = 0xFF;
423 pMgmt->abyScanBSSID[3] = 0xFF;
424 pMgmt->abyScanBSSID[4] = 0xFF;
425 pMgmt->abyScanBSSID[5] = 0xFF;
426 pItemSSID->byElementID = WLAN_EID_SSID;
427 // clear bssid list
e64354c0 428 // BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass);
5449c685
FB
429 pMgmt->eScanState = WMAC_IS_SCANNING;
430
431 }
432
433 vAdHocBeaconStop(pDevice);
434
1b12068a 435 if (set_channel(pMgmt->pAdapter, pMgmt->uScanChannel) == true) {
7e809a9b 436 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"SCAN Channel: %d\n", pMgmt->uScanChannel);
5449c685 437 } else {
7e809a9b 438 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"SET SCAN Channel Fail: %d\n", pMgmt->uScanChannel);
5449c685
FB
439 }
440 CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, OP_MODE_UNKNOWN);
441// printk("chester-mxch=%d\n",pDevice->byMaxChannel);
442 // printk("chester-ch=%d\n",pMgmt->uScanChannel);
443 pMgmt->uScanChannel++;
444//2008-8-4 <modify> by chester
79566eb2 445 if (!is_channel_valid(pMgmt->uScanChannel) &&
5449c685
FB
446 pMgmt->uScanChannel <= pDevice->byMaxChannel ){
447 pMgmt->uScanChannel=pDevice->byMaxChannel+1;
448 pMgmt->eCommandState = WLAN_CMD_SCAN_END;
449
450 }
451
452
5a5a2a6a 453 if ((pMgmt->b11hEnable == false) ||
5449c685
FB
454 (pMgmt->uScanChannel < CB_MAX_CHANNEL_24G)) {
455 s_vProbeChannel(pDevice);
456 spin_unlock_irq(&pDevice->lock);
e64354c0 457 vCommandTimerWait((void *)pDevice, WCMD_ACTIVE_SCAN_TIME);
5449c685
FB
458 return;
459 } else {
460 spin_unlock_irq(&pDevice->lock);
e64354c0 461 vCommandTimerWait((void *)pDevice, WCMD_PASSIVE_SCAN_TIME);
5449c685
FB
462 return;
463 }
464
465 }
466
467 break;
468
469 case WLAN_CMD_SCAN_END:
470
471 // Set Baseband's sensitivity back.
472 // Set channel back
79566eb2 473 set_channel(pMgmt->pAdapter, pMgmt->uCurrChannel);
7e809a9b 474 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Scanning, set back to channel: [%d]\n", pMgmt->uCurrChannel);
5449c685
FB
475 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
476 CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, OP_MODE_ADHOC);
477 } else {
478 CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, OP_MODE_INFRASTRUCTURE);
479 }
480
481 pMgmt->eScanState = WMAC_NO_SCANNING;
482 vAdHocBeaconRestart(pDevice);
483//2008-0409-07, <Add> by Einsn Liu
484#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
485 if(pMgmt->eScanType == WMAC_SCAN_PASSIVE)
486 {//send scan event to wpa_Supplicant
487 union iwreq_data wrqu;
488 memset(&wrqu, 0, sizeof(wrqu));
489 wireless_send_event(pDevice->dev, SIOCGIWSCAN, &wrqu, NULL);
490 }
491#endif
492 s_bCommandComplete(pDevice);
493 break;
494
495 case WLAN_CMD_DISASSOCIATE_START :
496 pDevice->byReAssocCount = 0;
497 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
498 (pMgmt->eCurrState != WMAC_STATE_ASSOC)) {
499 s_bCommandComplete(pDevice);
500 spin_unlock_irq(&pDevice->lock);
501 return;
502 } else {
7e809a9b 503 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Send Disassociation Packet..\n");
5449c685 504 // reason = 8 : disassoc because sta has left
e64354c0 505 vMgrDisassocBeginSta((void *)pDevice, pMgmt, pMgmt->abyCurrBSSID, (8), &Status);
5a5a2a6a 506 pDevice->bLinkPass = false;
5449c685
FB
507 // unlock command busy
508 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
509 pItemSSID->len = 0;
510 memset(pItemSSID->abySSID, 0, WLAN_SSID_MAXLEN);
511 pMgmt->eCurrState = WMAC_STATE_IDLE;
5a5a2a6a
CC
512 pMgmt->sNodeDBTable[0].bActive = false;
513// pDevice->bBeaconBufReady = false;
5449c685
FB
514 }
515 netif_stop_queue(pDevice->dev);
516 pDevice->eCommandState = WLAN_DISASSOCIATE_WAIT;
517 // wait all Control TD complete
518 if (pDevice->iTDUsed[TYPE_TXDMA0] != 0){
e64354c0 519 vCommandTimerWait((void *)pDevice, 10);
5449c685
FB
520 spin_unlock_irq(&pDevice->lock);
521 return;
522 };
7e809a9b 523 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" CARDbRadioPowerOff\n");
5449c685
FB
524 //2008-09-02 <mark> by chester
525 // CARDbRadioPowerOff(pDevice);
526 s_bCommandComplete(pDevice);
527 break;
528
529 case WLAN_DISASSOCIATE_WAIT :
530 // wait all Control TD complete
531 if (pDevice->iTDUsed[TYPE_TXDMA0] != 0){
e64354c0 532 vCommandTimerWait((void *)pDevice, 10);
5449c685
FB
533 spin_unlock_irq(&pDevice->lock);
534 return;
535 };
536//2008-09-02 <mark> by chester
537 // CARDbRadioPowerOff(pDevice);
538 s_bCommandComplete(pDevice);
539 break;
540
541 case WLAN_CMD_SSID_START:
542 pDevice->byReAssocCount = 0;
1b12068a 543 if (pDevice->bRadioOff == true) {
5449c685
FB
544 s_bCommandComplete(pDevice);
545 spin_unlock_irq(&pDevice->lock);
546 return;
547 }
548//printk("chester-currmode=%d\n",pMgmt->eCurrMode);
549printk("chester-abyDesireSSID=%s\n",((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->abySSID);
550 //memcpy(pMgmt->abyAdHocSSID,pMgmt->abyDesireSSID,
551 //((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->len + WLAN_IEHDR_LEN);
552 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
553 pItemSSIDCurr = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
7e809a9b
JL
554 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" cmd: desire ssid = %s\n", pItemSSID->abySSID);
555 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" cmd: curr ssid = %s\n", pItemSSIDCurr->abySSID);
5449c685
FB
556
557 if (pMgmt->eCurrState == WMAC_STATE_ASSOC) {
7e809a9b
JL
558 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Cmd pMgmt->eCurrState == WMAC_STATE_ASSOC\n");
559 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" pItemSSID->len =%d\n",pItemSSID->len);
560 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" pItemSSIDCurr->len = %d\n",pItemSSIDCurr->len);
561 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" desire ssid = %s\n", pItemSSID->abySSID);
562 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" curr ssid = %s\n", pItemSSIDCurr->abySSID);
5449c685
FB
563 }
564
565 if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) ||
566 ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)&& (pMgmt->eCurrState == WMAC_STATE_JOINTED))) {
567
568 if (pItemSSID->len == pItemSSIDCurr->len) {
569 if (memcmp(pItemSSID->abySSID, pItemSSIDCurr->abySSID, pItemSSID->len) == 0) {
570 s_bCommandComplete(pDevice);
571 spin_unlock_irq(&pDevice->lock);
572 return;
573 }
574 }
575
576 netif_stop_queue(pDevice->dev);
5a5a2a6a 577 pDevice->bLinkPass = false;
5449c685
FB
578 }
579 // set initial state
580 pMgmt->eCurrState = WMAC_STATE_IDLE;
581 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
e64354c0 582 PSvDisablePowerSaving((void *)pDevice);
5449c685
FB
583 BSSvClearNodeDBTable(pDevice, 0);
584
e64354c0 585 vMgrJoinBSSBegin((void *)pDevice, &Status);
5449c685
FB
586 // if Infra mode
587 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED)) {
588
589 // Call mgr to begin the deauthentication
25985edc 590 // reason = (3) because sta has left ESS
5449c685 591 if (pMgmt->eCurrState>= WMAC_STATE_AUTH) {
e64354c0 592 vMgrDeAuthenBeginSta((void *)pDevice, pMgmt, pMgmt->abyCurrBSSID, (3), &Status);
5449c685
FB
593 }
594 // Call mgr to begin the authentication
e64354c0 595 vMgrAuthenBeginSta((void *)pDevice, pMgmt, &Status);
5449c685
FB
596 if (Status == CMD_STATUS_SUCCESS) {
597 pDevice->byLinkWaitCount = 0;
598 pDevice->eCommandState = WLAN_AUTHENTICATE_WAIT;
e64354c0 599 vCommandTimerWait((void *)pDevice, AUTHENTICATE_TIMEOUT);
5449c685 600 spin_unlock_irq(&pDevice->lock);
7e809a9b 601 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Set eCommandState = WLAN_AUTHENTICATE_WAIT\n");
5449c685
FB
602 return;
603 }
604 }
605 // if Adhoc mode
606 else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
607 if (pMgmt->eCurrState == WMAC_STATE_JOINTED) {
608 if (netif_queue_stopped(pDevice->dev)){
609 netif_wake_queue(pDevice->dev);
610 }
1b12068a 611 pDevice->bLinkPass = true;
5449c685 612
1b12068a 613 pMgmt->sNodeDBTable[0].bActive = true;
5449c685
FB
614 pMgmt->sNodeDBTable[0].uInActiveCount = 0;
615 bClearBSSID_SCAN(pDevice);
616 }
617 else {
618 // start own IBSS
e64354c0 619 vMgrCreateOwnIBSS((void *)pDevice, &Status);
5449c685 620 if (Status != CMD_STATUS_SUCCESS){
7e809a9b 621 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " WLAN_CMD_IBSS_CREATE fail ! \n");
5449c685
FB
622 };
623 BSSvAddMulticastNode(pDevice);
624 }
625 }
626 // if SSID not found
627 else if (pMgmt->eCurrMode == WMAC_MODE_STANDBY) {
628 if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA ||
629 pMgmt->eConfigMode == WMAC_CONFIG_AUTO) {
630 // start own IBSS
e64354c0 631 vMgrCreateOwnIBSS((void *)pDevice, &Status);
5449c685 632 if (Status != CMD_STATUS_SUCCESS){
7e809a9b 633 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" WLAN_CMD_IBSS_CREATE fail ! \n");
5449c685
FB
634 };
635 BSSvAddMulticastNode(pDevice);
636 if (netif_queue_stopped(pDevice->dev)){
637 netif_wake_queue(pDevice->dev);
638 }
1b12068a 639 pDevice->bLinkPass = true;
5449c685
FB
640 }
641 else {
7e809a9b 642 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disconnect SSID none\n");
5449c685 643 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1b12068a 644 // if(pDevice->bWPASuppWextEnabled == true)
5449c685
FB
645 {
646 union iwreq_data wrqu;
647 memset(&wrqu, 0, sizeof (wrqu));
648 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
649 printk("wireless_send_event--->SIOCGIWAP(disassociated:vMgrJoinBSSBegin Fail !!)\n");
650 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
651 }
652 #endif
653
654 }
655 }
656 s_bCommandComplete(pDevice);
657 break;
658
659 case WLAN_AUTHENTICATE_WAIT :
7e809a9b 660 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState == WLAN_AUTHENTICATE_WAIT\n");
5449c685
FB
661 if (pMgmt->eCurrState == WMAC_STATE_AUTH) {
662 // Call mgr to begin the association
663 pDevice->byLinkWaitCount = 0;
7e809a9b 664 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCurrState == WMAC_STATE_AUTH\n");
e64354c0 665 vMgrAssocBeginSta((void *)pDevice, pMgmt, &Status);
5449c685
FB
666 if (Status == CMD_STATUS_SUCCESS) {
667 pDevice->byLinkWaitCount = 0;
7e809a9b 668 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState = WLAN_ASSOCIATE_WAIT\n");
5449c685 669 pDevice->eCommandState = WLAN_ASSOCIATE_WAIT;
e64354c0 670 vCommandTimerWait((void *)pDevice, ASSOCIATE_TIMEOUT);
5449c685
FB
671 spin_unlock_irq(&pDevice->lock);
672 return;
673 }
674 }
675
676 else if(pMgmt->eCurrState < WMAC_STATE_AUTHPENDING) {
677 printk("WLAN_AUTHENTICATE_WAIT:Authen Fail???\n");
678 }
679 else if(pDevice->byLinkWaitCount <= 4){ //mike add:wait another 2 sec if authenticated_frame delay!
680 pDevice->byLinkWaitCount ++;
681 printk("WLAN_AUTHENTICATE_WAIT:wait %d times!!\n",pDevice->byLinkWaitCount);
682 spin_unlock_irq(&pDevice->lock);
e64354c0 683 vCommandTimerWait((void *)pDevice, AUTHENTICATE_TIMEOUT/2);
5449c685
FB
684 return;
685 }
686 pDevice->byLinkWaitCount = 0;
687 #if 0
688 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1b12068a 689 // if(pDevice->bWPASuppWextEnabled == true)
5449c685
FB
690 {
691 union iwreq_data wrqu;
692 memset(&wrqu, 0, sizeof (wrqu));
693 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
694 printk("wireless_send_event--->SIOCGIWAP(disassociated:AUTHENTICATE_WAIT_timeout)\n");
695 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
696 }
697 #endif
698 #endif
699 s_bCommandComplete(pDevice);
700 break;
701
702 case WLAN_ASSOCIATE_WAIT :
703 if (pMgmt->eCurrState == WMAC_STATE_ASSOC) {
7e809a9b 704 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCurrState == WMAC_STATE_ASSOC\n");
5449c685 705 if (pDevice->ePSMode != WMAC_POWER_CAM) {
e64354c0 706 PSvEnablePowerSaving((void *)pDevice, pMgmt->wListenInterval);
5449c685
FB
707 }
708 if (pMgmt->eAuthenMode >= WMAC_AUTH_WPA) {
709 KeybRemoveAllKey(&(pDevice->sKey), pDevice->abyBSSID, pDevice->PortOffset);
710 }
1b12068a 711 pDevice->bLinkPass = true;
5449c685
FB
712 pDevice->byLinkWaitCount = 0;
713 pDevice->byReAssocCount = 0;
714 bClearBSSID_SCAN(pDevice);
715 if (pDevice->byFOETuning) {
716 BBvSetFOE(pDevice->PortOffset);
717 PSbSendNullPacket(pDevice);
718 }
719 if (netif_queue_stopped(pDevice->dev)){
720 netif_wake_queue(pDevice->dev);
721 }
722 #ifdef TxInSleep
5a5a2a6a 723 if(pDevice->IsTxDataTrigger != false) { //TxDataTimer is not triggered at the first time
5449c685
FB
724 // printk("Re-initial TxDataTimer****\n");
725 del_timer(&pDevice->sTimerTxData);
726 init_timer(&pDevice->sTimerTxData);
e3fd16d0 727 pDevice->sTimerTxData.data = (unsigned long) pDevice;
5449c685
FB
728 pDevice->sTimerTxData.function = (TimerFunction)BSSvSecondTxData;
729 pDevice->sTimerTxData.expires = RUN_AT(10*HZ); //10s callback
5a5a2a6a 730 pDevice->fTxDataInSleep = false;
5449c685
FB
731 pDevice->nTxDataTimeCout = 0;
732 }
733 else {
734 // printk("mike:-->First time triger TimerTxData InSleep\n");
735 }
1b12068a 736 pDevice->IsTxDataTrigger = true;
5449c685
FB
737 add_timer(&pDevice->sTimerTxData);
738 #endif
739 }
740 else if(pMgmt->eCurrState < WMAC_STATE_ASSOCPENDING) {
741 printk("WLAN_ASSOCIATE_WAIT:Association Fail???\n");
742 }
743 else if(pDevice->byLinkWaitCount <= 4){ //mike add:wait another 2 sec if associated_frame delay!
744 pDevice->byLinkWaitCount ++;
745 printk("WLAN_ASSOCIATE_WAIT:wait %d times!!\n",pDevice->byLinkWaitCount);
746 spin_unlock_irq(&pDevice->lock);
e64354c0 747 vCommandTimerWait((void *)pDevice, ASSOCIATE_TIMEOUT/2);
5449c685
FB
748 return;
749 }
750 pDevice->byLinkWaitCount = 0;
751 #if 0
752 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1b12068a 753 // if(pDevice->bWPASuppWextEnabled == true)
5449c685
FB
754 {
755 union iwreq_data wrqu;
756 memset(&wrqu, 0, sizeof (wrqu));
757 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
758 printk("wireless_send_event--->SIOCGIWAP(disassociated:ASSOCIATE_WAIT_timeout)\n");
759 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
760 }
761 #endif
762 #endif
763
764 s_bCommandComplete(pDevice);
765 break;
766
767 case WLAN_CMD_AP_MODE_START :
7e809a9b 768 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState == WLAN_CMD_AP_MODE_START\n");
5449c685
FB
769
770 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
771 del_timer(&pMgmt->sTimerSecondCallback);
772 pMgmt->eCurrState = WMAC_STATE_IDLE;
773 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
5a5a2a6a 774 pDevice->bLinkPass = false;
1b12068a 775 if (pDevice->bEnableHostWEP == true)
5449c685
FB
776 BSSvClearNodeDBTable(pDevice, 1);
777 else
778 BSSvClearNodeDBTable(pDevice, 0);
779 pDevice->uAssocCount = 0;
780 pMgmt->eCurrState = WMAC_STATE_IDLE;
5a5a2a6a 781 pDevice->bFixRate = false;
5449c685 782
e64354c0 783 vMgrCreateOwnIBSS((void *)pDevice, &Status);
5449c685 784 if (Status != CMD_STATUS_SUCCESS){
7e809a9b 785 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " vMgrCreateOwnIBSS fail ! \n");
5449c685
FB
786 };
787 // alway turn off unicast bit
788 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_RCR, RCR_UNICAST);
789 pDevice->byRxMode &= ~RCR_UNICAST;
7e809a9b 790 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wcmd: rx_mode = %x\n", pDevice->byRxMode );
5449c685
FB
791 BSSvAddMulticastNode(pDevice);
792 if (netif_queue_stopped(pDevice->dev)){
793 netif_wake_queue(pDevice->dev);
794 }
1b12068a 795 pDevice->bLinkPass = true;
5449c685
FB
796 add_timer(&pMgmt->sTimerSecondCallback);
797 }
798 s_bCommandComplete(pDevice);
799 break;
800
801 case WLAN_CMD_TX_PSPACKET_START :
802 // DTIM Multicast tx
803 if (pMgmt->sNodeDBTable[0].bRxPSPoll) {
804 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[0].sTxPSQueue)) != NULL) {
805 if (skb_queue_empty(&pMgmt->sNodeDBTable[0].sTxPSQueue)) {
806 pMgmt->abyPSTxMap[0] &= ~byMask[0];
5a5a2a6a 807 pDevice->bMoreData = false;
5449c685
FB
808 }
809 else {
1b12068a 810 pDevice->bMoreData = true;
5449c685
FB
811 }
812 if (!device_dma0_xmit(pDevice, skb, 0)) {
7e809a9b 813 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Multicast ps tx fail \n");
5449c685
FB
814 }
815 pMgmt->sNodeDBTable[0].wEnQueueCnt--;
816 }
817 };
818
819 // PS nodes tx
820 for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) {
821 if (pMgmt->sNodeDBTable[ii].bActive &&
822 pMgmt->sNodeDBTable[ii].bRxPSPoll) {
7e809a9b 823 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Index=%d Enqueu Cnt= %d\n",
5449c685
FB
824 ii, pMgmt->sNodeDBTable[ii].wEnQueueCnt);
825 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) != NULL) {
826 if (skb_queue_empty(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) {
827 // clear tx map
828 pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[ii].wAID >> 3] &=
829 ~byMask[pMgmt->sNodeDBTable[ii].wAID & 7];
5a5a2a6a 830 pDevice->bMoreData = false;
5449c685
FB
831 }
832 else {
1b12068a 833 pDevice->bMoreData = true;
5449c685
FB
834 }
835 if (!device_dma0_xmit(pDevice, skb, ii)) {
7e809a9b 836 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "sta ps tx fail \n");
5449c685
FB
837 }
838 pMgmt->sNodeDBTable[ii].wEnQueueCnt--;
839 // check if sta ps enable, wait next pspoll
840 // if sta ps disable, send all pending buffers.
841 if (pMgmt->sNodeDBTable[ii].bPSEnable)
842 break;
843 }
844 if (skb_queue_empty(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) {
845 // clear tx map
846 pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[ii].wAID >> 3] &=
847 ~byMask[pMgmt->sNodeDBTable[ii].wAID & 7];
7e809a9b 848 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Index=%d PS queue clear \n", ii);
5449c685 849 }
5a5a2a6a 850 pMgmt->sNodeDBTable[ii].bRxPSPoll = false;
5449c685
FB
851 }
852 }
853
854 s_bCommandComplete(pDevice);
855 break;
856
857
858 case WLAN_CMD_RADIO_START :
7e809a9b 859 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState == WLAN_CMD_RADIO_START\n");
1b12068a 860 if (pDevice->bRadioCmd == true)
5449c685
FB
861 CARDbRadioPowerOn(pDevice);
862 else
863 CARDbRadioPowerOff(pDevice);
864
865 s_bCommandComplete(pDevice);
866 break;
867
868
869 case WLAN_CMD_CHECK_BBSENSITIVITY_CHANGE :
7e809a9b 870 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState == WLAN_CMD_CHECK_BBSENSITIVITY_START\n");
5449c685
FB
871 // wait all TD complete
872 if (pDevice->iTDUsed[TYPE_AC0DMA] != 0){
e64354c0 873 vCommandTimerWait((void *)pDevice, 10);
5449c685
FB
874 spin_unlock_irq(&pDevice->lock);
875 return;
876 }
877 if (pDevice->iTDUsed[TYPE_TXDMA0] != 0){
e64354c0 878 vCommandTimerWait((void *)pDevice, 10);
5449c685
FB
879 spin_unlock_irq(&pDevice->lock);
880 return;
881 }
882 pDevice->byBBVGACurrent = pDevice->byBBVGANew;
883 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGACurrent);
7e809a9b 884 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"SetVGAGainOffset %02X\n", pDevice->byBBVGACurrent);
5449c685
FB
885 s_bCommandComplete(pDevice);
886 break;
887
888 default :
889 s_bCommandComplete(pDevice);
890 break;
891
892 } //switch
893 spin_unlock_irq(&pDevice->lock);
894 return;
895
896}
897
898
899static
7b6a0013 900bool
5449c685
FB
901s_bCommandComplete (
902 PSDevice pDevice
903 )
904{
905 PWLAN_IE_SSID pSSID;
7b6a0013 906 bool bRadioCmd = false;
2986db5f 907 //unsigned short wDeAuthenReason = 0;
7b6a0013 908 bool bForceSCAN = true;
5449c685
FB
909 PSMgmtObject pMgmt = pDevice->pMgmt;
910
911
912 pDevice->eCommandState = WLAN_CMD_IDLE;
913 if (pDevice->cbFreeCmdQueue == CMD_Q_SIZE) {
914 //Command Queue Empty
5a5a2a6a 915 pDevice->bCmdRunning = false;
1b12068a 916 return true;
5449c685
FB
917 }
918 else {
919 pDevice->eCommand = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].eCmd;
920 pSSID = (PWLAN_IE_SSID)pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].abyCmdDesireSSID;
921 bRadioCmd = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].bRadioCmd;
922 bForceSCAN = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].bForceSCAN;
923 ADD_ONE_WITH_WRAP_AROUND(pDevice->uCmdDequeueIdx, CMD_Q_SIZE);
924 pDevice->cbFreeCmdQueue++;
1b12068a 925 pDevice->bCmdRunning = true;
5449c685
FB
926 switch ( pDevice->eCommand ) {
927 case WLAN_CMD_BSSID_SCAN:
7e809a9b 928 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState= WLAN_CMD_BSSID_SCAN\n");
5449c685
FB
929 pDevice->eCommandState = WLAN_CMD_SCAN_START;
930 pMgmt->uScanChannel = 0;
931 if (pSSID->len != 0) {
51b6d9c2 932 memcpy(pMgmt->abyScanSSID, pSSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
5449c685
FB
933 } else {
934 memset(pMgmt->abyScanSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
935 }
936/*
5a5a2a6a 937 if ((bForceSCAN == false) && (pDevice->bLinkPass == true)) {
5449c685 938 if ((pSSID->len == ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len) &&
51b6d9c2 939 ( !memcmp(pSSID->abySSID, ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID, pSSID->len))) {
5449c685
FB
940 pDevice->eCommandState = WLAN_CMD_IDLE;
941 }
942 }
943*/
944 break;
945 case WLAN_CMD_SSID:
946 pDevice->eCommandState = WLAN_CMD_SSID_START;
947 if (pSSID->len > WLAN_SSID_MAXLEN)
948 pSSID->len = WLAN_SSID_MAXLEN;
949 if (pSSID->len != 0)
51b6d9c2 950 memcpy(pDevice->pMgmt->abyDesireSSID, pSSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
7e809a9b 951 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState= WLAN_CMD_SSID_START\n");
5449c685
FB
952 break;
953 case WLAN_CMD_DISASSOCIATE:
954 pDevice->eCommandState = WLAN_CMD_DISASSOCIATE_START;
955 break;
956 case WLAN_CMD_RX_PSPOLL:
957 pDevice->eCommandState = WLAN_CMD_TX_PSPACKET_START;
958 break;
959 case WLAN_CMD_RUN_AP:
960 pDevice->eCommandState = WLAN_CMD_AP_MODE_START;
961 break;
962 case WLAN_CMD_RADIO:
963 pDevice->eCommandState = WLAN_CMD_RADIO_START;
964 pDevice->bRadioCmd = bRadioCmd;
965 break;
966 case WLAN_CMD_CHANGE_BBSENSITIVITY:
967 pDevice->eCommandState = WLAN_CMD_CHECK_BBSENSITIVITY_CHANGE;
968 break;
969
970 default:
971 break;
972
973 }
974
e64354c0 975 vCommandTimerWait((void *)pDevice, 0);
5449c685
FB
976 }
977
1b12068a 978 return true;
5449c685
FB
979}
980
981
982
7b6a0013 983bool bScheduleCommand (
3a215e0f
CC
984 void *hDeviceContext,
985 CMD_CODE eCommand,
2989e96f 986 unsigned char *pbyItem0
5449c685
FB
987 )
988{
989 PSDevice pDevice = (PSDevice)hDeviceContext;
990
991
992 if (pDevice->cbFreeCmdQueue == 0) {
5a5a2a6a 993 return (false);
5449c685
FB
994 }
995 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].eCmd = eCommand;
1b12068a 996 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bForceSCAN = true;
5449c685
FB
997 memset(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID, 0 , WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
998
999 if (pbyItem0 != NULL) {
1000 switch (eCommand) {
1001
1002 case WLAN_CMD_BSSID_SCAN:
51b6d9c2 1003 memcpy(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID,
5449c685 1004 pbyItem0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
5a5a2a6a 1005 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bForceSCAN = false;
5449c685
FB
1006 break;
1007
1008 case WLAN_CMD_SSID:
51b6d9c2 1009 memcpy(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID,
5449c685
FB
1010 pbyItem0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
1011 break;
1012
1013 case WLAN_CMD_DISASSOCIATE:
a884847a 1014 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bNeedRadioOFF = *((int *)pbyItem0);
5449c685
FB
1015 break;
1016/*
1017 case WLAN_CMD_DEAUTH:
15df6c2b 1018 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].wDeAuthenReason = *((unsigned short *)pbyItem0);
5449c685
FB
1019 break;
1020*/
1021
1022 case WLAN_CMD_RX_PSPOLL:
1023 break;
1024
1025 case WLAN_CMD_RADIO:
a884847a 1026 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bRadioCmd = *((int *)pbyItem0);
5449c685
FB
1027 break;
1028
1029 case WLAN_CMD_CHANGE_BBSENSITIVITY:
1030 pDevice->eCommandState = WLAN_CMD_CHECK_BBSENSITIVITY_CHANGE;
1031 break;
1032
1033 default:
1034 break;
1035 }
1036 }
1037
1038 ADD_ONE_WITH_WRAP_AROUND(pDevice->uCmdEnqueueIdx, CMD_Q_SIZE);
1039 pDevice->cbFreeCmdQueue--;
1040
5a5a2a6a 1041 if (pDevice->bCmdRunning == false) {
5449c685
FB
1042 s_bCommandComplete(pDevice);
1043 }
1044 else {
1045 }
1b12068a 1046 return (true);
5449c685
FB
1047
1048}
1049
1050/*
1051 * Description:
1052 * Clear BSSID_SCAN cmd in CMD Queue
1053 *
1054 * Parameters:
1055 * In:
1056 * hDeviceContext - Pointer to the adapter
1057 * eCommand - Command
1058 * Out:
1059 * none
1060 *
5a5a2a6a 1061 * Return Value: true if success; otherwise false
5449c685
FB
1062 *
1063 */
7b6a0013 1064bool bClearBSSID_SCAN (
3a215e0f 1065 void *hDeviceContext
5449c685
FB
1066 )
1067{
1068 PSDevice pDevice = (PSDevice)hDeviceContext;
b6e95cd5
CC
1069 unsigned int uCmdDequeueIdx = pDevice->uCmdDequeueIdx;
1070 unsigned int ii;
5449c685
FB
1071
1072 if ((pDevice->cbFreeCmdQueue < CMD_Q_SIZE) && (uCmdDequeueIdx != pDevice->uCmdEnqueueIdx)) {
1073 for (ii = 0; ii < (CMD_Q_SIZE - pDevice->cbFreeCmdQueue); ii ++) {
1074 if (pDevice->eCmdQueue[uCmdDequeueIdx].eCmd == WLAN_CMD_BSSID_SCAN)
1075 pDevice->eCmdQueue[uCmdDequeueIdx].eCmd = WLAN_CMD_IDLE;
1076 ADD_ONE_WITH_WRAP_AROUND(uCmdDequeueIdx, CMD_Q_SIZE);
1077 if (uCmdDequeueIdx == pDevice->uCmdEnqueueIdx)
1078 break;
1079 }
1080 }
1b12068a 1081 return true;
5449c685
FB
1082}
1083
1084//mike add:reset command timer
6b35b7b3 1085void
5449c685 1086vResetCommandTimer(
3a215e0f 1087 void *hDeviceContext
5449c685
FB
1088 )
1089{
1090 PSDevice pDevice = (PSDevice)hDeviceContext;
1091
1092 //delete timer
1093 del_timer(&pDevice->sTimerCommand);
1094 //init timer
1095 init_timer(&pDevice->sTimerCommand);
e3fd16d0 1096 pDevice->sTimerCommand.data = (unsigned long) pDevice;
5449c685
FB
1097 pDevice->sTimerCommand.function = (TimerFunction)vCommandTimer;
1098 pDevice->sTimerCommand.expires = RUN_AT(HZ);
1099 pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
1100 pDevice->uCmdDequeueIdx = 0;
1101 pDevice->uCmdEnqueueIdx = 0;
1102 pDevice->eCommandState = WLAN_CMD_IDLE;
5a5a2a6a
CC
1103 pDevice->bCmdRunning = false;
1104 pDevice->bCmdClear = false;
5449c685
FB
1105}
1106
1107
1108#ifdef TxInSleep
6b35b7b3 1109void
5449c685 1110BSSvSecondTxData(
3a215e0f 1111 void *hDeviceContext
5449c685
FB
1112 )
1113{
1114 PSDevice pDevice = (PSDevice)hDeviceContext;
1115 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1116 pDevice->nTxDataTimeCout++;
1117
1118 if(pDevice->nTxDataTimeCout<4) //don't tx data if timer less than 40s
1119 {
1120 // printk("mike:%s-->no data Tx not exceed the desired Time as %d\n",__FUNCTION__,
1121 // (int)pDevice->nTxDataTimeCout);
1122 pDevice->sTimerTxData.expires = RUN_AT(10*HZ); //10s callback
1123 add_timer(&pDevice->sTimerTxData);
1124 return;
1125 }
1126
1127 spin_lock_irq(&pDevice->lock);
1128 #if 1
1b12068a
CC
1129 if(((pDevice->bLinkPass ==true)&&(pMgmt->eAuthenMode < WMAC_AUTH_WPA)) || //open && sharekey linking
1130 (pDevice->fWPA_Authened == true)) { //wpa linking
5449c685 1131 #else
1b12068a 1132 if(pDevice->bLinkPass ==true) {
5449c685
FB
1133 #endif
1134
1135 // printk("mike:%s-->InSleep Tx Data Procedure\n",__FUNCTION__);
1b12068a 1136 pDevice->fTxDataInSleep = true;
5449c685 1137 PSbSendNullPacket(pDevice); //send null packet
5a5a2a6a 1138 pDevice->fTxDataInSleep = false;
5449c685
FB
1139 }
1140 spin_unlock_irq(&pDevice->lock);
1141
1142 pDevice->sTimerTxData.expires = RUN_AT(10*HZ); //10s callback
1143 add_timer(&pDevice->sTimerTxData);
1144 return;
1145}
1146#endif
1147