Merge remote-tracking branch 'cleancache/linux-next'
[linux-2.6/next.git] / drivers / staging / vt6656 / wcmd.c
blob78ea121b7e2ef4d9aa495da61367fa83ee8e41c7
1 /*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
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.
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.
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.
19 * File: wcmd.c
21 * Purpose: Handles the management command interface functions
23 * Author: Lyndon Chen
25 * Date: May 8, 2003
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 * s_bClearBSSID_SCAN- Clear BSSID_SCAN cmd in CMD Queue
37 * Revision History:
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 "control.h"
53 #include "rxtx.h"
54 #include "rf.h"
55 #include "rndis.h"
56 #include "channel.h"
57 #include "iowpa.h"
59 /*--------------------- Static Definitions -------------------------*/
64 /*--------------------- Static Classes ----------------------------*/
66 /*--------------------- Static Variables --------------------------*/
67 static int msglevel =MSG_LEVEL_INFO;
68 //static int msglevel =MSG_LEVEL_DEBUG;
69 /*--------------------- Static Functions --------------------------*/
71 static
72 void
73 s_vProbeChannel(
74 PSDevice pDevice
78 static
79 PSTxMgmtPacket
80 s_MgrMakeProbeRequest(
81 PSDevice pDevice,
82 PSMgmtObject pMgmt,
83 PBYTE pScanBSSID,
84 PWLAN_IE_SSID pSSID,
85 PWLAN_IE_SUPP_RATES pCurrRates,
86 PWLAN_IE_SUPP_RATES pCurrExtSuppRates
90 static
91 BOOL
92 s_bCommandComplete (
93 PSDevice pDevice
97 static BOOL s_bClearBSSID_SCAN(void *hDeviceContext);
99 /*--------------------- Export Variables --------------------------*/
101 /*--------------------- Export Functions --------------------------*/
104 * Description:
105 * Stop AdHoc beacon during scan process
107 * Parameters:
108 * In:
109 * pDevice - Pointer to the adapter
110 * Out:
111 * none
113 * Return Value: none
117 static
118 void
119 vAdHocBeaconStop(PSDevice pDevice)
122 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
123 BOOL bStop;
126 * temporarily stop Beacon packet for AdHoc Server
127 * if all of the following coditions are met:
128 * (1) STA is in AdHoc mode
129 * (2) VT3253 is programmed as automatic Beacon Transmitting
130 * (3) One of the following conditions is met
131 * (3.1) AdHoc channel is in B/G band and the
132 * current scan channel is in A band
133 * or
134 * (3.2) AdHoc channel is in A mode
136 bStop = FALSE;
137 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) &&
138 (pMgmt->eCurrState >= WMAC_STATE_STARTED))
140 if ((pMgmt->uIBSSChannel <= CB_MAX_CHANNEL_24G) &&
141 (pMgmt->uScanChannel > CB_MAX_CHANNEL_24G))
143 bStop = TRUE;
145 if (pMgmt->uIBSSChannel > CB_MAX_CHANNEL_24G)
147 bStop = TRUE;
151 if (bStop)
153 //PMESG(("STOP_BEACON: IBSSChannel = %u, ScanChannel = %u\n",
154 // pMgmt->uIBSSChannel, pMgmt->uScanChannel));
155 MACvRegBitsOff(pDevice, MAC_REG_TCR, TCR_AUTOBCNTX);
158 } /* vAdHocBeaconStop */
162 * Description:
163 * Restart AdHoc beacon after scan process complete
165 * Parameters:
166 * In:
167 * pDevice - Pointer to the adapter
168 * Out:
169 * none
171 * Return Value: none
174 static
175 void
176 vAdHocBeaconRestart(PSDevice pDevice)
178 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
181 * Restart Beacon packet for AdHoc Server
182 * if all of the following coditions are met:
183 * (1) STA is in AdHoc mode
184 * (2) VT3253 is programmed as automatic Beacon Transmitting
186 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) &&
187 (pMgmt->eCurrState >= WMAC_STATE_STARTED))
189 //PMESG(("RESTART_BEACON\n"));
190 MACvRegBitsOn(pDevice, MAC_REG_TCR, TCR_AUTOBCNTX);
198 * Routine Description:
199 * Prepare and send probe request management frames.
202 * Return Value:
203 * none.
207 static
208 void
209 s_vProbeChannel(
210 PSDevice pDevice
213 //1M, 2M, 5M, 11M, 18M, 24M, 36M, 54M
214 BYTE abyCurrSuppRatesG[] = {WLAN_EID_SUPP_RATES, 8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C};
215 BYTE abyCurrExtSuppRatesG[] = {WLAN_EID_EXTSUPP_RATES, 4, 0x0C, 0x12, 0x18, 0x60};
216 //6M, 9M, 12M, 48M
217 BYTE abyCurrSuppRatesA[] = {WLAN_EID_SUPP_RATES, 8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
218 BYTE abyCurrSuppRatesB[] = {WLAN_EID_SUPP_RATES, 4, 0x02, 0x04, 0x0B, 0x16};
219 PBYTE pbyRate;
220 PSTxMgmtPacket pTxPacket;
221 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
222 unsigned int ii;
225 if (pDevice->byBBType == BB_TYPE_11A) {
226 pbyRate = &abyCurrSuppRatesA[0];
227 } else if (pDevice->byBBType == BB_TYPE_11B) {
228 pbyRate = &abyCurrSuppRatesB[0];
229 } else {
230 pbyRate = &abyCurrSuppRatesG[0];
232 // build an assocreq frame and send it
233 pTxPacket = s_MgrMakeProbeRequest
235 pDevice,
236 pMgmt,
237 pMgmt->abyScanBSSID,
238 (PWLAN_IE_SSID)pMgmt->abyScanSSID,
239 (PWLAN_IE_SUPP_RATES)pbyRate,
240 (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRatesG
243 if (pTxPacket != NULL ){
244 for (ii = 0; ii < 1 ; ii++) {
245 if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
246 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Probe request sending fail.. \n");
248 else {
249 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Probe request is sending.. \n");
261 * Routine Description:
262 * Constructs an probe request frame
265 * Return Value:
266 * A ptr to Tx frame or NULL on allocation failue
271 PSTxMgmtPacket
272 s_MgrMakeProbeRequest(
273 PSDevice pDevice,
274 PSMgmtObject pMgmt,
275 PBYTE pScanBSSID,
276 PWLAN_IE_SSID pSSID,
277 PWLAN_IE_SUPP_RATES pCurrRates,
278 PWLAN_IE_SUPP_RATES pCurrExtSuppRates
282 PSTxMgmtPacket pTxPacket = NULL;
283 WLAN_FR_PROBEREQ sFrame;
286 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
287 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_PROBEREQ_FR_MAXLEN);
288 pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket));
289 sFrame.pBuf = (PBYTE)pTxPacket->p80211Header;
290 sFrame.len = WLAN_PROBEREQ_FR_MAXLEN;
291 vMgrEncodeProbeRequest(&sFrame);
292 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
294 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
295 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_PROBEREQ)
297 memcpy( sFrame.pHdr->sA3.abyAddr1, pScanBSSID, WLAN_ADDR_LEN);
298 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
299 memcpy( sFrame.pHdr->sA3.abyAddr3, pScanBSSID, WLAN_BSSID_LEN);
300 // Copy the SSID, pSSID->len=0 indicate broadcast SSID
301 sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
302 sFrame.len += pSSID->len + WLAN_IEHDR_LEN;
303 memcpy(sFrame.pSSID, pSSID, pSSID->len + WLAN_IEHDR_LEN);
304 sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
305 sFrame.len += pCurrRates->len + WLAN_IEHDR_LEN;
306 memcpy(sFrame.pSuppRates, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
307 // Copy the extension rate set
308 if (pDevice->byBBType == BB_TYPE_11G) {
309 sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
310 sFrame.len += pCurrExtSuppRates->len + WLAN_IEHDR_LEN;
311 memcpy(sFrame.pExtSuppRates, pCurrExtSuppRates, pCurrExtSuppRates->len + WLAN_IEHDR_LEN);
313 pTxPacket->cbMPDULen = sFrame.len;
314 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
316 return pTxPacket;
319 void vCommandTimerWait(void *hDeviceContext, unsigned int MSecond)
321 PSDevice pDevice = (PSDevice)hDeviceContext;
323 init_timer(&pDevice->sTimerCommand);
324 pDevice->sTimerCommand.data = (unsigned long)pDevice;
325 pDevice->sTimerCommand.function = (TimerFunction)vRunCommand;
326 // RUN_AT :1 msec ~= (HZ/1024)
327 pDevice->sTimerCommand.expires = (unsigned int)RUN_AT((MSecond * HZ) >> 10);
328 add_timer(&pDevice->sTimerCommand);
329 return;
332 void vRunCommand(void *hDeviceContext)
334 PSDevice pDevice = (PSDevice)hDeviceContext;
335 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
336 PWLAN_IE_SSID pItemSSID;
337 PWLAN_IE_SSID pItemSSIDCurr;
338 CMD_STATUS Status;
339 unsigned int ii;
340 BYTE byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
341 struct sk_buff *skb;
342 BYTE byData;
345 if (pDevice->dwDiagRefCount != 0)
346 return;
347 if (pDevice->bCmdRunning != TRUE)
348 return;
350 spin_lock_irq(&pDevice->lock);
352 switch ( pDevice->eCommandState ) {
354 case WLAN_CMD_SCAN_START:
356 pDevice->byReAssocCount = 0;
357 if (pDevice->bRadioOff == TRUE) {
358 s_bCommandComplete(pDevice);
359 spin_unlock_irq(&pDevice->lock);
360 return;
363 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
364 s_bCommandComplete(pDevice);
365 spin_unlock_irq(&pDevice->lock);
366 return;
369 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyScanSSID;
371 if (pMgmt->uScanChannel == 0 ) {
372 pMgmt->uScanChannel = pDevice->byMinChannel;
374 if (pMgmt->uScanChannel > pDevice->byMaxChannel) {
375 pMgmt->eScanState = WMAC_NO_SCANNING;
377 if (pDevice->byBBType != pDevice->byScanBBType) {
378 pDevice->byBBType = pDevice->byScanBBType;
379 CARDvSetBSSMode(pDevice);
382 if (pDevice->bUpdateBBVGA) {
383 BBvSetShortSlotTime(pDevice);
384 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGACurrent);
385 BBvUpdatePreEDThreshold(pDevice, FALSE);
387 // Set channel back
388 vAdHocBeaconRestart(pDevice);
389 // Set channel back
390 CARDbSetMediaChannel(pDevice, pMgmt->uCurrChannel);
391 // Set Filter
392 if (pMgmt->bCurrBSSIDFilterOn) {
393 MACvRegBitsOn(pDevice, MAC_REG_RCR, RCR_BSSID);
394 pDevice->byRxMode |= RCR_BSSID;
396 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Scanning, set back to channel: [%d]\n", pMgmt->uCurrChannel);
397 pDevice->bStopDataPkt = FALSE;
398 s_bCommandComplete(pDevice);
399 spin_unlock_irq(&pDevice->lock);
400 return;
402 } else {
403 if (!ChannelValid(pDevice->byZoneType, pMgmt->uScanChannel)) {
404 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Invalid channel pMgmt->uScanChannel = %d \n",pMgmt->uScanChannel);
405 s_bCommandComplete(pDevice);
406 spin_unlock_irq(&pDevice->lock);
407 return;
409 if (pMgmt->uScanChannel == pDevice->byMinChannel) {
410 // pMgmt->eScanType = WMAC_SCAN_ACTIVE; //mike mark
411 pMgmt->abyScanBSSID[0] = 0xFF;
412 pMgmt->abyScanBSSID[1] = 0xFF;
413 pMgmt->abyScanBSSID[2] = 0xFF;
414 pMgmt->abyScanBSSID[3] = 0xFF;
415 pMgmt->abyScanBSSID[4] = 0xFF;
416 pMgmt->abyScanBSSID[5] = 0xFF;
417 pItemSSID->byElementID = WLAN_EID_SSID;
418 // clear bssid list
419 /* BSSvClearBSSList((void *) pDevice,
420 pDevice->bLinkPass); */
421 pMgmt->eScanState = WMAC_IS_SCANNING;
422 pDevice->byScanBBType = pDevice->byBBType; //lucas
423 pDevice->bStopDataPkt = TRUE;
424 // Turn off RCR_BSSID filter every time
425 MACvRegBitsOff(pDevice, MAC_REG_RCR, RCR_BSSID);
426 pDevice->byRxMode &= ~RCR_BSSID;
429 //lucas
430 vAdHocBeaconStop(pDevice);
431 if ((pDevice->byBBType != BB_TYPE_11A) && (pMgmt->uScanChannel > CB_MAX_CHANNEL_24G)) {
432 pDevice->byBBType = BB_TYPE_11A;
433 CARDvSetBSSMode(pDevice);
435 else if ((pDevice->byBBType == BB_TYPE_11A) && (pMgmt->uScanChannel <= CB_MAX_CHANNEL_24G)) {
436 pDevice->byBBType = BB_TYPE_11G;
437 CARDvSetBSSMode(pDevice);
439 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Scanning.... channel: [%d]\n", pMgmt->uScanChannel);
440 // Set channel
441 CARDbSetMediaChannel(pDevice, pMgmt->uScanChannel);
442 // Set Baseband to be more sensitive.
444 if (pDevice->bUpdateBBVGA) {
445 BBvSetShortSlotTime(pDevice);
446 BBvSetVGAGainOffset(pDevice, pDevice->abyBBVGA[0]);
447 BBvUpdatePreEDThreshold(pDevice, TRUE);
449 pMgmt->uScanChannel++;
451 while (!ChannelValid(pDevice->byZoneType, pMgmt->uScanChannel) &&
452 pMgmt->uScanChannel <= pDevice->byMaxChannel ){
453 pMgmt->uScanChannel++;
456 if (pMgmt->uScanChannel > pDevice->byMaxChannel) {
457 // Set Baseband to be not sensitive and rescan
458 pDevice->eCommandState = WLAN_CMD_SCAN_END;
461 if ((pMgmt->b11hEnable == FALSE) ||
462 (pMgmt->uScanChannel < CB_MAX_CHANNEL_24G)) {
463 s_vProbeChannel(pDevice);
464 spin_unlock_irq(&pDevice->lock);
465 vCommandTimerWait((void *) pDevice, 100);
466 return;
467 } else {
468 spin_unlock_irq(&pDevice->lock);
469 vCommandTimerWait((void *) pDevice, WCMD_PASSIVE_SCAN_TIME);
470 return;
475 break;
477 case WLAN_CMD_SCAN_END:
479 // Set Baseband's sensitivity back.
480 if (pDevice->byBBType != pDevice->byScanBBType) {
481 pDevice->byBBType = pDevice->byScanBBType;
482 CARDvSetBSSMode(pDevice);
485 if (pDevice->bUpdateBBVGA) {
486 BBvSetShortSlotTime(pDevice);
487 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGACurrent);
488 BBvUpdatePreEDThreshold(pDevice, FALSE);
491 // Set channel back
492 vAdHocBeaconRestart(pDevice);
493 // Set channel back
494 CARDbSetMediaChannel(pDevice, pMgmt->uCurrChannel);
495 // Set Filter
496 if (pMgmt->bCurrBSSIDFilterOn) {
497 MACvRegBitsOn(pDevice, MAC_REG_RCR, RCR_BSSID);
498 pDevice->byRxMode |= RCR_BSSID;
500 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Scanning, set back to channel: [%d]\n", pMgmt->uCurrChannel);
501 pMgmt->eScanState = WMAC_NO_SCANNING;
502 pDevice->bStopDataPkt = FALSE;
504 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
505 if(pMgmt->eScanType == WMAC_SCAN_PASSIVE)
507 //send scan event to wpa_Supplicant
508 union iwreq_data wrqu;
509 PRINT_K("wireless_send_event--->SIOCGIWSCAN(scan done)\n");
510 memset(&wrqu, 0, sizeof(wrqu));
511 wireless_send_event(pDevice->dev, SIOCGIWSCAN, &wrqu, NULL);
513 #endif
514 s_bCommandComplete(pDevice);
515 break;
517 case WLAN_CMD_DISASSOCIATE_START :
518 pDevice->byReAssocCount = 0;
519 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
520 (pMgmt->eCurrState != WMAC_STATE_ASSOC)) {
521 s_bCommandComplete(pDevice);
522 spin_unlock_irq(&pDevice->lock);
523 return;
524 } else {
526 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
527 pDevice->bwextstep0 = FALSE;
528 pDevice->bwextstep1 = FALSE;
529 pDevice->bwextstep2 = FALSE;
530 pDevice->bwextstep3 = FALSE;
531 pDevice->bWPASuppWextEnabled = FALSE;
532 #endif
533 pDevice->fWPA_Authened = FALSE;
535 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Send Disassociation Packet..\n");
536 // reason = 8 : disassoc because sta has left
537 vMgrDisassocBeginSta((void *) pDevice,
538 pMgmt,
539 pMgmt->abyCurrBSSID,
540 (8),
541 &Status);
542 pDevice->bLinkPass = FALSE;
543 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW);
544 // unlock command busy
545 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
546 pItemSSID->len = 0;
547 memset(pItemSSID->abySSID, 0, WLAN_SSID_MAXLEN);
548 pMgmt->eCurrState = WMAC_STATE_IDLE;
549 pMgmt->sNodeDBTable[0].bActive = FALSE;
550 // pDevice->bBeaconBufReady = FALSE;
552 netif_stop_queue(pDevice->dev);
553 if (pDevice->bNeedRadioOFF == TRUE)
554 CARDbRadioPowerOff(pDevice);
555 s_bCommandComplete(pDevice);
556 break;
559 case WLAN_CMD_SSID_START:
561 pDevice->byReAssocCount = 0;
562 if (pDevice->bRadioOff == TRUE) {
563 s_bCommandComplete(pDevice);
564 spin_unlock_irq(&pDevice->lock);
565 return;
568 memcpy(pMgmt->abyAdHocSSID,pMgmt->abyDesireSSID,
569 ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->len + WLAN_IEHDR_LEN);
571 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
572 pItemSSIDCurr = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
573 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" cmd: desire ssid = %s\n", pItemSSID->abySSID);
574 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" cmd: curr ssid = %s\n", pItemSSIDCurr->abySSID);
576 if (pMgmt->eCurrState == WMAC_STATE_ASSOC) {
577 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Cmd pMgmt->eCurrState == WMAC_STATE_ASSOC\n");
578 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" pItemSSID->len =%d\n",pItemSSID->len);
579 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" pItemSSIDCurr->len = %d\n",pItemSSIDCurr->len);
580 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" desire ssid = %s\n", pItemSSID->abySSID);
581 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" curr ssid = %s\n", pItemSSIDCurr->abySSID);
584 if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) ||
585 ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)&& (pMgmt->eCurrState == WMAC_STATE_JOINTED))) {
587 if (pItemSSID->len == pItemSSIDCurr->len) {
588 if (memcmp(pItemSSID->abySSID, pItemSSIDCurr->abySSID, pItemSSID->len) == 0) {
589 s_bCommandComplete(pDevice);
590 spin_unlock_irq(&pDevice->lock);
591 return;
594 netif_stop_queue(pDevice->dev);
595 pDevice->bLinkPass = FALSE;
596 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW);
598 // set initial state
599 pMgmt->eCurrState = WMAC_STATE_IDLE;
600 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
601 PSvDisablePowerSaving((void *) pDevice);
602 BSSvClearNodeDBTable(pDevice, 0);
603 vMgrJoinBSSBegin((void *) pDevice, &Status);
604 // if Infra mode
605 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED)) {
606 // Call mgr to begin the deauthentication
607 // reason = (3) because sta has left ESS
608 if (pMgmt->eCurrState >= WMAC_STATE_AUTH) {
609 vMgrDeAuthenBeginSta((void *)pDevice,
610 pMgmt,
611 pMgmt->abyCurrBSSID,
612 (3),
613 &Status);
615 // Call mgr to begin the authentication
616 vMgrAuthenBeginSta((void *) pDevice, pMgmt, &Status);
617 if (Status == CMD_STATUS_SUCCESS) {
618 pDevice->byLinkWaitCount = 0;
619 pDevice->eCommandState = WLAN_AUTHENTICATE_WAIT;
620 vCommandTimerWait((void *) pDevice, AUTHENTICATE_TIMEOUT);
621 spin_unlock_irq(&pDevice->lock);
622 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Set eCommandState = WLAN_AUTHENTICATE_WAIT\n");
623 return;
626 // if Adhoc mode
627 else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
628 if (pMgmt->eCurrState == WMAC_STATE_JOINTED) {
629 if (netif_queue_stopped(pDevice->dev)){
630 netif_wake_queue(pDevice->dev);
632 pDevice->bLinkPass = TRUE;
633 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER);
634 pMgmt->sNodeDBTable[0].bActive = TRUE;
635 pMgmt->sNodeDBTable[0].uInActiveCount = 0;
637 else {
638 // start own IBSS
639 DBG_PRT(MSG_LEVEL_DEBUG,
640 KERN_INFO "CreateOwn IBSS by CurrMode = IBSS_STA\n");
641 vMgrCreateOwnIBSS((void *) pDevice, &Status);
642 if (Status != CMD_STATUS_SUCCESS){
643 DBG_PRT(MSG_LEVEL_DEBUG,
644 KERN_INFO "WLAN_CMD_IBSS_CREATE fail!\n");
646 BSSvAddMulticastNode(pDevice);
648 s_bClearBSSID_SCAN(pDevice);
650 // if SSID not found
651 else if (pMgmt->eCurrMode == WMAC_MODE_STANDBY) {
652 if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA ||
653 pMgmt->eConfigMode == WMAC_CONFIG_AUTO) {
654 // start own IBSS
655 DBG_PRT(MSG_LEVEL_DEBUG,
656 KERN_INFO "CreateOwn IBSS by CurrMode = STANDBY\n");
657 vMgrCreateOwnIBSS((void *) pDevice, &Status);
658 if (Status != CMD_STATUS_SUCCESS){
659 DBG_PRT(MSG_LEVEL_DEBUG,
660 KERN_INFO "WLAN_CMD_IBSS_CREATE fail!\n");
662 BSSvAddMulticastNode(pDevice);
663 s_bClearBSSID_SCAN(pDevice);
665 pDevice->bLinkPass = TRUE;
666 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER);
667 if (netif_queue_stopped(pDevice->dev)){
668 netif_wake_queue(pDevice->dev);
670 s_bClearBSSID_SCAN(pDevice);
673 else {
674 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disconnect SSID none\n");
675 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
676 // if(pDevice->bWPASuppWextEnabled == TRUE)
678 union iwreq_data wrqu;
679 memset(&wrqu, 0, sizeof (wrqu));
680 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
681 PRINT_K("wireless_send_event--->SIOCGIWAP(disassociated:vMgrJoinBSSBegin Fail !!)\n");
682 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
684 #endif
687 s_bCommandComplete(pDevice);
688 break;
690 case WLAN_AUTHENTICATE_WAIT :
691 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState == WLAN_AUTHENTICATE_WAIT\n");
692 if (pMgmt->eCurrState == WMAC_STATE_AUTH) {
693 pDevice->byLinkWaitCount = 0;
694 // Call mgr to begin the association
695 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCurrState == WMAC_STATE_AUTH\n");
696 vMgrAssocBeginSta((void *) pDevice, pMgmt, &Status);
697 if (Status == CMD_STATUS_SUCCESS) {
698 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState = WLAN_ASSOCIATE_WAIT\n");
699 pDevice->byLinkWaitCount = 0;
700 pDevice->eCommandState = WLAN_ASSOCIATE_WAIT;
701 vCommandTimerWait((void *) pDevice, ASSOCIATE_TIMEOUT);
702 spin_unlock_irq(&pDevice->lock);
703 return;
706 else if(pMgmt->eCurrState < WMAC_STATE_AUTHPENDING) {
707 printk("WLAN_AUTHENTICATE_WAIT:Authen Fail???\n");
709 else if(pDevice->byLinkWaitCount <= 4){ //mike add:wait another 2 sec if authenticated_frame delay!
710 pDevice->byLinkWaitCount ++;
711 printk("WLAN_AUTHENTICATE_WAIT:wait %d times!!\n",pDevice->byLinkWaitCount);
712 spin_unlock_irq(&pDevice->lock);
713 vCommandTimerWait((void *) pDevice, AUTHENTICATE_TIMEOUT/2);
714 return;
716 pDevice->byLinkWaitCount = 0;
718 s_bCommandComplete(pDevice);
719 break;
721 case WLAN_ASSOCIATE_WAIT :
722 if (pMgmt->eCurrState == WMAC_STATE_ASSOC) {
723 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCurrState == WMAC_STATE_ASSOC\n");
724 if (pDevice->ePSMode != WMAC_POWER_CAM) {
725 PSvEnablePowerSaving((void *) pDevice,
726 pMgmt->wListenInterval);
729 if (pMgmt->eAuthenMode >= WMAC_AUTH_WPA) {
730 KeybRemoveAllKey(pDevice, &(pDevice->sKey), pDevice->abyBSSID);
733 pDevice->byLinkWaitCount = 0;
734 pDevice->byReAssocCount = 0;
735 pDevice->bLinkPass = TRUE;
736 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER);
737 s_bClearBSSID_SCAN(pDevice);
739 if (netif_queue_stopped(pDevice->dev)){
740 netif_wake_queue(pDevice->dev);
743 if(pDevice->IsTxDataTrigger != FALSE) { //TxDataTimer is not triggered at the first time
744 // printk("Re-initial TxDataTimer****\n");
745 del_timer(&pDevice->sTimerTxData);
746 init_timer(&pDevice->sTimerTxData);
747 pDevice->sTimerTxData.data = (unsigned long) pDevice;
748 pDevice->sTimerTxData.function = (TimerFunction)BSSvSecondTxData;
749 pDevice->sTimerTxData.expires = RUN_AT(10*HZ); //10s callback
750 pDevice->fTxDataInSleep = FALSE;
751 pDevice->nTxDataTimeCout = 0;
753 else {
754 // printk("mike:-->First time triger TimerTxData InSleep\n");
756 pDevice->IsTxDataTrigger = TRUE;
757 add_timer(&pDevice->sTimerTxData);
760 else if(pMgmt->eCurrState < WMAC_STATE_ASSOCPENDING) {
761 printk("WLAN_ASSOCIATE_WAIT:Association Fail???\n");
763 else if(pDevice->byLinkWaitCount <= 4){ //mike add:wait another 2 sec if associated_frame delay!
764 pDevice->byLinkWaitCount ++;
765 printk("WLAN_ASSOCIATE_WAIT:wait %d times!!\n",pDevice->byLinkWaitCount);
766 spin_unlock_irq(&pDevice->lock);
767 vCommandTimerWait((void *) pDevice, ASSOCIATE_TIMEOUT/2);
768 return;
770 pDevice->byLinkWaitCount = 0;
772 s_bCommandComplete(pDevice);
773 break;
775 case WLAN_CMD_AP_MODE_START :
776 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState == WLAN_CMD_AP_MODE_START\n");
778 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
779 del_timer(&pMgmt->sTimerSecondCallback);
780 pMgmt->eCurrState = WMAC_STATE_IDLE;
781 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
782 pDevice->bLinkPass = FALSE;
783 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW);
784 if (pDevice->bEnableHostWEP == TRUE)
785 BSSvClearNodeDBTable(pDevice, 1);
786 else
787 BSSvClearNodeDBTable(pDevice, 0);
788 pDevice->uAssocCount = 0;
789 pMgmt->eCurrState = WMAC_STATE_IDLE;
790 pDevice->bFixRate = FALSE;
792 vMgrCreateOwnIBSS((void *) pDevice, &Status);
793 if (Status != CMD_STATUS_SUCCESS) {
794 DBG_PRT(MSG_LEVEL_DEBUG,
795 KERN_INFO "vMgrCreateOwnIBSS fail!\n");
797 // alway turn off unicast bit
798 MACvRegBitsOff(pDevice, MAC_REG_RCR, RCR_UNICAST);
799 pDevice->byRxMode &= ~RCR_UNICAST;
800 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wcmd: rx_mode = %x\n", pDevice->byRxMode );
801 BSSvAddMulticastNode(pDevice);
802 if (netif_queue_stopped(pDevice->dev)){
803 netif_wake_queue(pDevice->dev);
805 pDevice->bLinkPass = TRUE;
806 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER);
807 add_timer(&pMgmt->sTimerSecondCallback);
809 s_bCommandComplete(pDevice);
810 break;
812 case WLAN_CMD_TX_PSPACKET_START :
813 // DTIM Multicast tx
814 if (pMgmt->sNodeDBTable[0].bRxPSPoll) {
815 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[0].sTxPSQueue)) != NULL) {
816 if (skb_queue_empty(&pMgmt->sNodeDBTable[0].sTxPSQueue)) {
817 pMgmt->abyPSTxMap[0] &= ~byMask[0];
818 pDevice->bMoreData = FALSE;
820 else {
821 pDevice->bMoreData = TRUE;
824 if (nsDMA_tx_packet(pDevice, TYPE_AC0DMA, skb) != 0) {
825 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Multicast ps tx fail \n");
828 pMgmt->sNodeDBTable[0].wEnQueueCnt--;
832 // PS nodes tx
833 for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) {
834 if (pMgmt->sNodeDBTable[ii].bActive &&
835 pMgmt->sNodeDBTable[ii].bRxPSPoll) {
836 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Index=%d Enqueu Cnt= %d\n",
837 ii, pMgmt->sNodeDBTable[ii].wEnQueueCnt);
838 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) != NULL) {
839 if (skb_queue_empty(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) {
840 // clear tx map
841 pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[ii].wAID >> 3] &=
842 ~byMask[pMgmt->sNodeDBTable[ii].wAID & 7];
843 pDevice->bMoreData = FALSE;
845 else {
846 pDevice->bMoreData = TRUE;
849 if (nsDMA_tx_packet(pDevice, TYPE_AC0DMA, skb) != 0) {
850 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "sta ps tx fail \n");
853 pMgmt->sNodeDBTable[ii].wEnQueueCnt--;
854 // check if sta ps enable, wait next pspoll
855 // if sta ps disable, send all pending buffers.
856 if (pMgmt->sNodeDBTable[ii].bPSEnable)
857 break;
859 if (skb_queue_empty(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) {
860 // clear tx map
861 pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[ii].wAID >> 3] &=
862 ~byMask[pMgmt->sNodeDBTable[ii].wAID & 7];
863 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Index=%d PS queue clear \n", ii);
865 pMgmt->sNodeDBTable[ii].bRxPSPoll = FALSE;
869 s_bCommandComplete(pDevice);
870 break;
872 case WLAN_CMD_RADIO_START:
874 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState == WLAN_CMD_RADIO_START\n");
875 // if (pDevice->bRadioCmd == TRUE)
876 // CARDbRadioPowerOn(pDevice);
877 // else
878 // CARDbRadioPowerOff(pDevice);
881 int ntStatus = STATUS_SUCCESS;
882 BYTE byTmp;
884 ntStatus = CONTROLnsRequestIn(pDevice,
885 MESSAGE_TYPE_READ,
886 MAC_REG_GPIOCTL1,
887 MESSAGE_REQUEST_MACREG,
889 &byTmp);
891 if ( ntStatus != STATUS_SUCCESS ) {
892 s_bCommandComplete(pDevice);
893 spin_unlock_irq(&pDevice->lock);
894 return;
896 if ( (byTmp & GPIO3_DATA) == 0 ) {
897 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" WLAN_CMD_RADIO_START_OFF........................\n");
898 // Old commands are useless.
899 // empty command Q
900 pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
901 pDevice->uCmdDequeueIdx = 0;
902 pDevice->uCmdEnqueueIdx = 0;
903 //0415pDevice->bCmdRunning = FALSE;
904 pDevice->bCmdClear = TRUE;
905 pDevice->bStopTx0Pkt = FALSE;
906 pDevice->bStopDataPkt = TRUE;
908 pDevice->byKeyIndex = 0;
909 pDevice->bTransmitKey = FALSE;
910 spin_unlock_irq(&pDevice->lock);
911 KeyvInitTable(pDevice,&pDevice->sKey);
912 spin_lock_irq(&pDevice->lock);
913 pMgmt->byCSSPK = KEY_CTL_NONE;
914 pMgmt->byCSSGK = KEY_CTL_NONE;
916 if (pDevice->bLinkPass == TRUE) {
917 // reason = 8 : disassoc because sta has left
918 vMgrDisassocBeginSta((void *) pDevice,
919 pMgmt,
920 pMgmt->abyCurrBSSID,
921 (8),
922 &Status);
923 pDevice->bLinkPass = FALSE;
924 // unlock command busy
925 pMgmt->eCurrState = WMAC_STATE_IDLE;
926 pMgmt->sNodeDBTable[0].bActive = FALSE;
927 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
928 // if(pDevice->bWPASuppWextEnabled == TRUE)
930 union iwreq_data wrqu;
931 memset(&wrqu, 0, sizeof (wrqu));
932 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
933 PRINT_K("wireless_send_event--->SIOCGIWAP(disassociated)\n");
934 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
936 #endif
938 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
939 pDevice->bwextstep0 = FALSE;
940 pDevice->bwextstep1 = FALSE;
941 pDevice->bwextstep2 = FALSE;
942 pDevice->bwextstep3 = FALSE;
943 pDevice->bWPASuppWextEnabled = FALSE;
944 #endif
945 //clear current SSID
946 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
947 pItemSSID->len = 0;
948 memset(pItemSSID->abySSID, 0, WLAN_SSID_MAXLEN);
949 //clear dessire SSID
950 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
951 pItemSSID->len = 0;
952 memset(pItemSSID->abySSID, 0, WLAN_SSID_MAXLEN);
954 netif_stop_queue(pDevice->dev);
955 CARDbRadioPowerOff(pDevice);
956 MACvRegBitsOn(pDevice,MAC_REG_GPIOCTL1,GPIO3_INTMD);
957 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_OFF);
958 pDevice->bHWRadioOff = TRUE;
959 } else {
960 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" WLAN_CMD_RADIO_START_ON........................\n");
961 pDevice->bHWRadioOff = FALSE;
962 CARDbRadioPowerOn(pDevice);
963 MACvRegBitsOff(pDevice,MAC_REG_GPIOCTL1,GPIO3_INTMD);
964 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_ON);
968 s_bCommandComplete(pDevice);
969 break;
972 case WLAN_CMD_CHANGE_BBSENSITIVITY_START:
974 pDevice->bStopDataPkt = TRUE;
975 pDevice->byBBVGACurrent = pDevice->byBBVGANew;
976 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGACurrent);
977 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Change sensitivity pDevice->byBBVGACurrent = %x\n", pDevice->byBBVGACurrent);
978 pDevice->bStopDataPkt = FALSE;
979 s_bCommandComplete(pDevice);
980 break;
982 case WLAN_CMD_TBTT_WAKEUP_START:
983 PSbIsNextTBTTWakeUp(pDevice);
984 s_bCommandComplete(pDevice);
985 break;
987 case WLAN_CMD_BECON_SEND_START:
988 bMgrPrepareBeaconToSend(pDevice, pMgmt);
989 s_bCommandComplete(pDevice);
990 break;
992 case WLAN_CMD_SETPOWER_START:
994 RFbSetPower(pDevice, pDevice->wCurrentRate, pMgmt->uCurrChannel);
996 s_bCommandComplete(pDevice);
997 break;
999 case WLAN_CMD_CHANGE_ANTENNA_START:
1000 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Change from Antenna%d to", (int)pDevice->dwRxAntennaSel);
1001 if ( pDevice->dwRxAntennaSel == 0) {
1002 pDevice->dwRxAntennaSel=1;
1003 if (pDevice->bTxRxAntInv == TRUE)
1004 BBvSetAntennaMode(pDevice, ANT_RXA);
1005 else
1006 BBvSetAntennaMode(pDevice, ANT_RXB);
1007 } else {
1008 pDevice->dwRxAntennaSel=0;
1009 if (pDevice->bTxRxAntInv == TRUE)
1010 BBvSetAntennaMode(pDevice, ANT_RXB);
1011 else
1012 BBvSetAntennaMode(pDevice, ANT_RXA);
1014 s_bCommandComplete(pDevice);
1015 break;
1017 case WLAN_CMD_REMOVE_ALLKEY_START:
1018 KeybRemoveAllKey(pDevice, &(pDevice->sKey), pDevice->abyBSSID);
1019 s_bCommandComplete(pDevice);
1020 break;
1023 case WLAN_CMD_MAC_DISPOWERSAVING_START:
1024 ControlvReadByte (pDevice, MESSAGE_REQUEST_MACREG, MAC_REG_PSCTL, &byData);
1025 if ( (byData & PSCTL_PS) != 0 ) {
1026 // disable power saving hw function
1027 CONTROLnsRequestOut(pDevice,
1028 MESSAGE_TYPE_DISABLE_PS,
1032 NULL
1035 s_bCommandComplete(pDevice);
1036 break;
1038 case WLAN_CMD_11H_CHSW_START:
1039 CARDbSetMediaChannel(pDevice, pDevice->byNewChannel);
1040 pDevice->bChannelSwitch = FALSE;
1041 pMgmt->uCurrChannel = pDevice->byNewChannel;
1042 pDevice->bStopDataPkt = FALSE;
1043 s_bCommandComplete(pDevice);
1044 break;
1046 default:
1047 s_bCommandComplete(pDevice);
1048 break;
1049 } //switch
1051 spin_unlock_irq(&pDevice->lock);
1052 return;
1056 static
1057 BOOL
1058 s_bCommandComplete (
1059 PSDevice pDevice
1062 PWLAN_IE_SSID pSSID;
1063 BOOL bRadioCmd = FALSE;
1064 //WORD wDeAuthenReason = 0;
1065 BOOL bForceSCAN = TRUE;
1066 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1069 pDevice->eCommandState = WLAN_CMD_IDLE;
1070 if (pDevice->cbFreeCmdQueue == CMD_Q_SIZE) {
1071 //Command Queue Empty
1072 pDevice->bCmdRunning = FALSE;
1073 return TRUE;
1075 else {
1076 pDevice->eCommand = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].eCmd;
1077 pSSID = (PWLAN_IE_SSID)pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].abyCmdDesireSSID;
1078 bRadioCmd = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].bRadioCmd;
1079 bForceSCAN = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].bForceSCAN;
1080 ADD_ONE_WITH_WRAP_AROUND(pDevice->uCmdDequeueIdx, CMD_Q_SIZE);
1081 pDevice->cbFreeCmdQueue++;
1082 pDevice->bCmdRunning = TRUE;
1083 switch ( pDevice->eCommand ) {
1084 case WLAN_CMD_BSSID_SCAN:
1085 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState= WLAN_CMD_BSSID_SCAN\n");
1086 pDevice->eCommandState = WLAN_CMD_SCAN_START;
1087 pMgmt->uScanChannel = 0;
1088 if (pSSID->len != 0) {
1089 memcpy(pMgmt->abyScanSSID, pSSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
1090 } else {
1091 memset(pMgmt->abyScanSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
1094 if ((bForceSCAN == FALSE) && (pDevice->bLinkPass == TRUE)) {
1095 if ((pSSID->len == ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len) &&
1096 ( !memcmp(pSSID->abySSID, ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID, pSSID->len))) {
1097 pDevice->eCommandState = WLAN_CMD_IDLE;
1101 break;
1102 case WLAN_CMD_SSID:
1103 pDevice->eCommandState = WLAN_CMD_SSID_START;
1104 if (pSSID->len > WLAN_SSID_MAXLEN)
1105 pSSID->len = WLAN_SSID_MAXLEN;
1106 if (pSSID->len != 0)
1107 memcpy(pMgmt->abyDesireSSID, pSSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
1108 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState= WLAN_CMD_SSID_START\n");
1109 break;
1110 case WLAN_CMD_DISASSOCIATE:
1111 pDevice->eCommandState = WLAN_CMD_DISASSOCIATE_START;
1112 break;
1113 case WLAN_CMD_RX_PSPOLL:
1114 pDevice->eCommandState = WLAN_CMD_TX_PSPACKET_START;
1115 break;
1116 case WLAN_CMD_RUN_AP:
1117 pDevice->eCommandState = WLAN_CMD_AP_MODE_START;
1118 break;
1119 case WLAN_CMD_RADIO:
1120 pDevice->eCommandState = WLAN_CMD_RADIO_START;
1121 pDevice->bRadioCmd = bRadioCmd;
1122 break;
1123 case WLAN_CMD_CHANGE_BBSENSITIVITY:
1124 pDevice->eCommandState = WLAN_CMD_CHANGE_BBSENSITIVITY_START;
1125 break;
1127 case WLAN_CMD_TBTT_WAKEUP:
1128 pDevice->eCommandState = WLAN_CMD_TBTT_WAKEUP_START;
1129 break;
1131 case WLAN_CMD_BECON_SEND:
1132 pDevice->eCommandState = WLAN_CMD_BECON_SEND_START;
1133 break;
1135 case WLAN_CMD_SETPOWER:
1136 pDevice->eCommandState = WLAN_CMD_SETPOWER_START;
1137 break;
1139 case WLAN_CMD_CHANGE_ANTENNA:
1140 pDevice->eCommandState = WLAN_CMD_CHANGE_ANTENNA_START;
1141 break;
1143 case WLAN_CMD_REMOVE_ALLKEY:
1144 pDevice->eCommandState = WLAN_CMD_REMOVE_ALLKEY_START;
1145 break;
1147 case WLAN_CMD_MAC_DISPOWERSAVING:
1148 pDevice->eCommandState = WLAN_CMD_MAC_DISPOWERSAVING_START;
1149 break;
1151 case WLAN_CMD_11H_CHSW:
1152 pDevice->eCommandState = WLAN_CMD_11H_CHSW_START;
1153 break;
1155 default:
1156 break;
1159 vCommandTimerWait((void *) pDevice, 0);
1162 return TRUE;
1165 BOOL bScheduleCommand(void *hDeviceContext,
1166 CMD_CODE eCommand,
1167 PBYTE pbyItem0)
1169 PSDevice pDevice = (PSDevice)hDeviceContext;
1172 if (pDevice->cbFreeCmdQueue == 0) {
1173 return (FALSE);
1175 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].eCmd = eCommand;
1176 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bForceSCAN = TRUE;
1177 memset(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID, 0 , WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
1178 if (pbyItem0 != NULL) {
1179 switch (eCommand) {
1180 case WLAN_CMD_BSSID_SCAN:
1181 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bForceSCAN = FALSE;
1182 memcpy(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID,
1183 pbyItem0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
1184 break;
1186 case WLAN_CMD_SSID:
1187 memcpy(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID,
1188 pbyItem0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
1189 break;
1191 case WLAN_CMD_DISASSOCIATE:
1192 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bNeedRadioOFF = *((int *)pbyItem0);
1193 break;
1195 case WLAN_CMD_DEAUTH:
1196 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].wDeAuthenReason = *((PWORD)pbyItem0);
1197 break;
1200 case WLAN_CMD_RADIO:
1201 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bRadioCmd = *((int *)pbyItem0);
1202 break;
1204 default:
1205 break;
1209 ADD_ONE_WITH_WRAP_AROUND(pDevice->uCmdEnqueueIdx, CMD_Q_SIZE);
1210 pDevice->cbFreeCmdQueue--;
1212 if (pDevice->bCmdRunning == FALSE) {
1213 s_bCommandComplete(pDevice);
1215 else {
1217 return (TRUE);
1222 * Description:
1223 * Clear BSSID_SCAN cmd in CMD Queue
1225 * Parameters:
1226 * In:
1227 * hDeviceContext - Pointer to the adapter
1228 * eCommand - Command
1229 * Out:
1230 * none
1232 * Return Value: TRUE if success; otherwise FALSE
1235 static BOOL s_bClearBSSID_SCAN(void *hDeviceContext)
1237 PSDevice pDevice = (PSDevice)hDeviceContext;
1238 unsigned int uCmdDequeueIdx = pDevice->uCmdDequeueIdx;
1239 unsigned int ii;
1241 if ((pDevice->cbFreeCmdQueue < CMD_Q_SIZE) && (uCmdDequeueIdx != pDevice->uCmdEnqueueIdx)) {
1242 for (ii = 0; ii < (CMD_Q_SIZE - pDevice->cbFreeCmdQueue); ii ++) {
1243 if (pDevice->eCmdQueue[uCmdDequeueIdx].eCmd == WLAN_CMD_BSSID_SCAN)
1244 pDevice->eCmdQueue[uCmdDequeueIdx].eCmd = WLAN_CMD_IDLE;
1245 ADD_ONE_WITH_WRAP_AROUND(uCmdDequeueIdx, CMD_Q_SIZE);
1246 if (uCmdDequeueIdx == pDevice->uCmdEnqueueIdx)
1247 break;
1250 return TRUE;
1254 //mike add:reset command timer
1255 void vResetCommandTimer(void *hDeviceContext)
1257 PSDevice pDevice = (PSDevice)hDeviceContext;
1259 //delete timer
1260 del_timer(&pDevice->sTimerCommand);
1261 //init timer
1262 init_timer(&pDevice->sTimerCommand);
1263 pDevice->sTimerCommand.data = (unsigned long)pDevice;
1264 pDevice->sTimerCommand.function = (TimerFunction)vRunCommand;
1265 pDevice->sTimerCommand.expires = RUN_AT(HZ);
1266 pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
1267 pDevice->uCmdDequeueIdx = 0;
1268 pDevice->uCmdEnqueueIdx = 0;
1269 pDevice->eCommandState = WLAN_CMD_IDLE;
1270 pDevice->bCmdRunning = FALSE;
1271 pDevice->bCmdClear = FALSE;
1274 void BSSvSecondTxData(void *hDeviceContext)
1276 PSDevice pDevice = (PSDevice)hDeviceContext;
1277 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1279 pDevice->nTxDataTimeCout++;
1281 if(pDevice->nTxDataTimeCout<4) //don't tx data if timer less than 40s
1283 // printk("mike:%s-->no data Tx not exceed the desired Time as %d\n",__FUNCTION__,
1284 // (int)pDevice->nTxDataTimeCout);
1285 pDevice->sTimerTxData.expires = RUN_AT(10*HZ); //10s callback
1286 add_timer(&pDevice->sTimerTxData);
1287 return;
1290 spin_lock_irq(&pDevice->lock);
1291 //is wap_supplicant running successful OR only open && sharekey mode!
1292 if(((pDevice->bLinkPass ==TRUE)&&(pMgmt->eAuthenMode < WMAC_AUTH_WPA)) || //open && sharekey linking
1293 (pDevice->fWPA_Authened == TRUE)) { //wpa linking
1294 // printk("mike:%s-->InSleep Tx Data Procedure\n",__FUNCTION__);
1295 pDevice->fTxDataInSleep = TRUE;
1296 PSbSendNullPacket(pDevice); //send null packet
1297 pDevice->fTxDataInSleep = FALSE;
1299 spin_unlock_irq(&pDevice->lock);
1301 pDevice->sTimerTxData.expires = RUN_AT(10*HZ); //10s callback
1302 add_timer(&pDevice->sTimerTxData);
1303 return;