2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
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.
21 * Purpose: Handles the management command interface 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
57 /*--------------------- Static Definitions -------------------------*/
59 /*--------------------- Static Classes ----------------------------*/
61 /*--------------------- Static Functions --------------------------*/
66 struct vnt_private *pDevice
71 s_MgrMakeProbeRequest(
72 struct vnt_private *pDevice,
74 unsigned char *pScanBSSID,
76 PWLAN_IE_SUPP_RATES pCurrRates,
77 PWLAN_IE_SUPP_RATES pCurrExtSuppRates
83 struct vnt_private *pDevice
86 /*--------------------- Export Variables --------------------------*/
88 /*--------------------- Export Functions --------------------------*/
92 * Stop AdHoc beacon during scan process
96 * pDevice - Pointer to the adapter
105 vAdHocBeaconStop(struct vnt_private *pDevice)
107 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
111 * temporarily stop Beacon packet for AdHoc Server
112 * if all of the following conditions are met:
113 * (1) STA is in AdHoc mode
114 * (2) VT3253 is programmed as automatic Beacon Transmitting
115 * (3) One of the following conditions is met
116 * (3.1) AdHoc channel is in B/G band and the
117 * current scan channel is in A band
119 * (3.2) AdHoc channel is in A mode
122 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) &&
123 (pMgmt->eCurrState >= WMAC_STATE_STARTED)) {
124 if ((pMgmt->uIBSSChannel <= CB_MAX_CHANNEL_24G) &&
125 (pMgmt->uScanChannel > CB_MAX_CHANNEL_24G)) {
128 if (pMgmt->uIBSSChannel > CB_MAX_CHANNEL_24G)
134 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
135 } /* vAdHocBeaconStop */
139 * Restart AdHoc beacon after scan process complete
143 * pDevice - Pointer to the adapter
152 vAdHocBeaconRestart(struct vnt_private *pDevice)
154 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
157 * Restart Beacon packet for AdHoc Server
158 * if all of the following coditions are met:
159 * (1) STA is in AdHoc mode
160 * (2) VT3253 is programmed as automatic Beacon Transmitting
162 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) &&
163 (pMgmt->eCurrState >= WMAC_STATE_STARTED)) {
164 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
170 * Routine Description:
171 * Prepare and send probe request management frames.
182 struct vnt_private *pDevice
185 //1M, 2M, 5M, 11M, 18M, 24M, 36M, 54M
186 unsigned char abyCurrSuppRatesG[] = {WLAN_EID_SUPP_RATES, 8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C};
187 unsigned char abyCurrExtSuppRatesG[] = {WLAN_EID_EXTSUPP_RATES, 4, 0x0C, 0x12, 0x18, 0x60};
189 unsigned char abyCurrSuppRatesA[] = {WLAN_EID_SUPP_RATES, 8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
190 unsigned char abyCurrSuppRatesB[] = {WLAN_EID_SUPP_RATES, 4, 0x02, 0x04, 0x0B, 0x16};
191 unsigned char *pbyRate;
192 PSTxMgmtPacket pTxPacket;
193 PSMgmtObject pMgmt = pDevice->pMgmt;
196 if (pDevice->eCurrentPHYType == PHY_TYPE_11A)
197 pbyRate = &abyCurrSuppRatesA[0];
198 else if (pDevice->eCurrentPHYType == PHY_TYPE_11B)
199 pbyRate = &abyCurrSuppRatesB[0];
201 pbyRate = &abyCurrSuppRatesG[0];
203 // build an assocreq frame and send it
204 pTxPacket = s_MgrMakeProbeRequest
209 (PWLAN_IE_SSID)pMgmt->abyScanSSID,
210 (PWLAN_IE_SUPP_RATES)pbyRate,
211 (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRatesG
214 if (pTxPacket != NULL) {
215 for (ii = 0; ii < 2; ii++) {
216 if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING)
217 pr_debug("Probe request sending fail..\n");
219 pr_debug("Probe request is sending..\n");
226 * Routine Description:
227 * Constructs an probe request frame
231 * A ptr to Tx frame or NULL on allocation failure
235 static PSTxMgmtPacket
236 s_MgrMakeProbeRequest(
237 struct vnt_private *pDevice,
239 unsigned char *pScanBSSID,
241 PWLAN_IE_SUPP_RATES pCurrRates,
242 PWLAN_IE_SUPP_RATES pCurrExtSuppRates
246 PSTxMgmtPacket pTxPacket = NULL;
248 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
249 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_PROBEREQ_FR_MAXLEN);
250 pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
257 void *hDeviceContext,
261 struct vnt_private *pDevice = hDeviceContext;
263 init_timer(&pDevice->sTimerCommand);
264 pDevice->sTimerCommand.data = (unsigned long) pDevice;
265 pDevice->sTimerCommand.function = (TimerFunction)vCommandTimer;
266 // RUN_AT :1 msec ~= (HZ/1024)
267 pDevice->sTimerCommand.expires = (unsigned int)RUN_AT((MSecond * HZ) >> 10);
268 add_timer(&pDevice->sTimerCommand);
276 struct vnt_private *pDevice = hDeviceContext;
277 PSMgmtObject pMgmt = pDevice->pMgmt;
278 PWLAN_IE_SSID pItemSSID;
279 PWLAN_IE_SSID pItemSSIDCurr;
281 unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
284 if (pDevice->dwDiagRefCount != 0)
286 if (!pDevice->bCmdRunning)
289 spin_lock_irq(&pDevice->lock);
291 switch (pDevice->eCommandState) {
292 case WLAN_CMD_SCAN_START:
294 pDevice->byReAssocCount = 0;
295 if (pDevice->bRadioOff) {
296 s_bCommandComplete(pDevice);
297 spin_unlock_irq(&pDevice->lock);
301 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
302 s_bCommandComplete(pDevice);
303 CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, NL80211_IFTYPE_AP);
304 spin_unlock_irq(&pDevice->lock);
308 pr_debug("eCommandState= WLAN_CMD_SCAN_START\n");
309 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyScanSSID;
310 // wait all Data TD complete
311 if (pDevice->iTDUsed[TYPE_AC0DMA] != 0) {
312 spin_unlock_irq(&pDevice->lock);
313 vCommandTimerWait((void *)pDevice, 10);
317 if (pMgmt->uScanChannel == 0) {
318 pMgmt->uScanChannel = pDevice->byMinChannel;
319 // Set Baseband to be more sensitive.
322 if (pMgmt->uScanChannel > pDevice->byMaxChannel) {
323 pMgmt->eScanState = WMAC_NO_SCANNING;
325 // Set Baseband's sensitivity back.
327 set_channel(pMgmt->pAdapter, pMgmt->uCurrChannel);
328 pr_debug("Scanning, set back to channel: [%d]\n",
329 pMgmt->uCurrChannel);
330 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)
331 CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, NL80211_IFTYPE_ADHOC);
333 CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, NL80211_IFTYPE_STATION);
335 vAdHocBeaconRestart(pDevice);
336 s_bCommandComplete(pDevice);
339 //2008-8-4 <add> by chester
340 if (!is_channel_valid(pMgmt->uScanChannel)) {
341 pr_debug("Invalid channel pMgmt->uScanChannel = %d\n",
342 pMgmt->uScanChannel);
343 s_bCommandComplete(pDevice);
344 spin_unlock_irq(&pDevice->lock);
347 if (pMgmt->uScanChannel == pDevice->byMinChannel) {
348 pMgmt->abyScanBSSID[0] = 0xFF;
349 pMgmt->abyScanBSSID[1] = 0xFF;
350 pMgmt->abyScanBSSID[2] = 0xFF;
351 pMgmt->abyScanBSSID[3] = 0xFF;
352 pMgmt->abyScanBSSID[4] = 0xFF;
353 pMgmt->abyScanBSSID[5] = 0xFF;
354 pItemSSID->byElementID = WLAN_EID_SSID;
355 pMgmt->eScanState = WMAC_IS_SCANNING;
359 vAdHocBeaconStop(pDevice);
361 if (set_channel(pMgmt->pAdapter, pMgmt->uScanChannel))
362 pr_debug("SCAN Channel: %d\n",
363 pMgmt->uScanChannel);
365 pr_debug("SET SCAN Channel Fail: %d\n",
366 pMgmt->uScanChannel);
368 CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, NL80211_IFTYPE_UNSPECIFIED);
369 pMgmt->uScanChannel++;
370 //2008-8-4 <modify> by chester
371 if (!is_channel_valid(pMgmt->uScanChannel) &&
372 pMgmt->uScanChannel <= pDevice->byMaxChannel) {
373 pMgmt->uScanChannel = pDevice->byMaxChannel + 1;
374 pMgmt->eCommandState = WLAN_CMD_SCAN_END;
378 if (!pMgmt->b11hEnable ||
379 (pMgmt->uScanChannel < CB_MAX_CHANNEL_24G)) {
380 s_vProbeChannel(pDevice);
381 spin_unlock_irq(&pDevice->lock);
382 vCommandTimerWait((void *)pDevice, WCMD_ACTIVE_SCAN_TIME);
385 spin_unlock_irq(&pDevice->lock);
386 vCommandTimerWait((void *)pDevice, WCMD_PASSIVE_SCAN_TIME);
394 case WLAN_CMD_SCAN_END:
396 // Set Baseband's sensitivity back.
398 set_channel(pMgmt->pAdapter, pMgmt->uCurrChannel);
399 pr_debug("Scanning, set back to channel: [%d]\n",
400 pMgmt->uCurrChannel);
401 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)
402 CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, NL80211_IFTYPE_ADHOC);
404 CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, NL80211_IFTYPE_STATION);
406 pMgmt->eScanState = WMAC_NO_SCANNING;
407 vAdHocBeaconRestart(pDevice);
408 //2008-0409-07, <Add> by Einsn Liu
409 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
410 if (pMgmt->eScanType == WMAC_SCAN_PASSIVE) {
411 //send scan event to wpa_Supplicant
412 union iwreq_data wrqu;
414 memset(&wrqu, 0, sizeof(wrqu));
415 wireless_send_event(pDevice->dev, SIOCGIWSCAN, &wrqu, NULL);
418 s_bCommandComplete(pDevice);
421 case WLAN_CMD_DISASSOCIATE_START:
422 pDevice->byReAssocCount = 0;
423 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
424 (pMgmt->eCurrState != WMAC_STATE_ASSOC)) {
425 s_bCommandComplete(pDevice);
426 spin_unlock_irq(&pDevice->lock);
429 pr_debug("Send Disassociation Packet..\n");
430 // reason = 8 : disassoc because sta has left
431 pDevice->bLinkPass = false;
432 // unlock command busy
433 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
435 memset(pItemSSID->abySSID, 0, WLAN_SSID_MAXLEN);
436 pMgmt->eCurrState = WMAC_STATE_IDLE;
437 pMgmt->sNodeDBTable[0].bActive = false;
439 netif_stop_queue(pDevice->dev);
440 pDevice->eCommandState = WLAN_DISASSOCIATE_WAIT;
441 // wait all Control TD complete
442 if (pDevice->iTDUsed[TYPE_TXDMA0] != 0) {
443 vCommandTimerWait((void *)pDevice, 10);
444 spin_unlock_irq(&pDevice->lock);
447 pr_debug(" CARDbRadioPowerOff\n");
448 //2008-09-02 <mark> by chester
449 s_bCommandComplete(pDevice);
452 case WLAN_DISASSOCIATE_WAIT:
453 // wait all Control TD complete
454 if (pDevice->iTDUsed[TYPE_TXDMA0] != 0) {
455 vCommandTimerWait((void *)pDevice, 10);
456 spin_unlock_irq(&pDevice->lock);
459 //2008-09-02 <mark> by chester
460 s_bCommandComplete(pDevice);
463 case WLAN_CMD_SSID_START:
464 pDevice->byReAssocCount = 0;
465 if (pDevice->bRadioOff) {
466 s_bCommandComplete(pDevice);
467 spin_unlock_irq(&pDevice->lock);
470 pr_debug("chester-abyDesireSSID=%s\n", ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->abySSID);
471 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
472 pItemSSIDCurr = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
473 pr_debug(" cmd: desire ssid = %s\n", pItemSSID->abySSID);
474 pr_debug(" cmd: curr ssid = %s\n", pItemSSIDCurr->abySSID);
476 if (pMgmt->eCurrState == WMAC_STATE_ASSOC) {
477 pr_debug(" Cmd pMgmt->eCurrState == WMAC_STATE_ASSOC\n");
478 pr_debug(" pItemSSID->len =%d\n", pItemSSID->len);
479 pr_debug(" pItemSSIDCurr->len = %d\n",
481 pr_debug(" desire ssid = %s\n", pItemSSID->abySSID);
482 pr_debug(" curr ssid = %s\n", pItemSSIDCurr->abySSID);
485 if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) ||
486 ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED))) {
487 if (pItemSSID->len == pItemSSIDCurr->len) {
488 if (memcmp(pItemSSID->abySSID, pItemSSIDCurr->abySSID, pItemSSID->len) == 0) {
489 s_bCommandComplete(pDevice);
490 spin_unlock_irq(&pDevice->lock);
495 netif_stop_queue(pDevice->dev);
496 pDevice->bLinkPass = false;
499 pMgmt->eCurrState = WMAC_STATE_IDLE;
500 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
501 PSvDisablePowerSaving((void *)pDevice);
502 BSSvClearNodeDBTable(pDevice, 0);
505 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED)) {
506 // Call mgr to begin the deauthentication
507 // reason = (3) because sta has left ESS
509 // Call mgr to begin the authentication
512 else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
513 if (pMgmt->eCurrState == WMAC_STATE_JOINTED) {
514 if (netif_queue_stopped(pDevice->dev))
515 netif_wake_queue(pDevice->dev);
517 pDevice->bLinkPass = true;
519 pMgmt->sNodeDBTable[0].bActive = true;
520 pMgmt->sNodeDBTable[0].uInActiveCount = 0;
521 bClearBSSID_SCAN(pDevice);
525 BSSvAddMulticastNode(pDevice);
529 else if (pMgmt->eCurrMode == WMAC_MODE_STANDBY) {
530 if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA ||
531 pMgmt->eConfigMode == WMAC_CONFIG_AUTO) {
534 BSSvAddMulticastNode(pDevice);
535 if (netif_queue_stopped(pDevice->dev))
536 netif_wake_queue(pDevice->dev);
538 pDevice->bLinkPass = true;
540 pr_debug("Disconnect SSID none\n");
541 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
543 union iwreq_data wrqu;
545 memset(&wrqu, 0, sizeof(wrqu));
546 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
547 pr_debug("wireless_send_event--->SIOCGIWAP(disassociated:vMgrJoinBSSBegin Fail !!)\n");
548 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
554 s_bCommandComplete(pDevice);
557 case WLAN_AUTHENTICATE_WAIT:
558 pr_debug("eCommandState == WLAN_AUTHENTICATE_WAIT\n");
559 if (pMgmt->eCurrState == WMAC_STATE_AUTH) {
560 // Call mgr to begin the association
561 pDevice->byLinkWaitCount = 0;
562 pr_debug("eCurrState == WMAC_STATE_AUTH\n");
565 else if (pMgmt->eCurrState < WMAC_STATE_AUTHPENDING) {
566 pr_debug("WLAN_AUTHENTICATE_WAIT:Authen Fail???\n");
567 } else if (pDevice->byLinkWaitCount <= 4) { //mike add:wait another 2 sec if authenticated_frame delay!
568 pDevice->byLinkWaitCount++;
569 pr_debug("WLAN_AUTHENTICATE_WAIT:wait %d times!!\n", pDevice->byLinkWaitCount);
570 spin_unlock_irq(&pDevice->lock);
571 vCommandTimerWait((void *)pDevice, AUTHENTICATE_TIMEOUT/2);
574 pDevice->byLinkWaitCount = 0;
575 s_bCommandComplete(pDevice);
578 case WLAN_ASSOCIATE_WAIT:
579 if (pMgmt->eCurrState == WMAC_STATE_ASSOC) {
580 pr_debug("eCurrState == WMAC_STATE_ASSOC\n");
581 if (pDevice->ePSMode != WMAC_POWER_CAM)
582 PSvEnablePowerSaving((void *)pDevice, pMgmt->wListenInterval);
584 if (pMgmt->eAuthenMode >= WMAC_AUTH_WPA)
585 KeybRemoveAllKey(&(pDevice->sKey), pDevice->abyBSSID, pDevice->PortOffset);
587 pDevice->bLinkPass = true;
588 pDevice->byLinkWaitCount = 0;
589 pDevice->byReAssocCount = 0;
590 bClearBSSID_SCAN(pDevice);
591 if (pDevice->byFOETuning) {
592 BBvSetFOE(pDevice->PortOffset);
594 if (netif_queue_stopped(pDevice->dev))
595 netif_wake_queue(pDevice->dev);
597 if (pDevice->IsTxDataTrigger) { //TxDataTimer is not triggered at the first time
598 del_timer(&pDevice->sTimerTxData);
599 init_timer(&pDevice->sTimerTxData);
600 pDevice->sTimerTxData.data = (unsigned long) pDevice;
601 pDevice->sTimerTxData.function = (TimerFunction)BSSvSecondTxData;
602 pDevice->sTimerTxData.expires = RUN_AT(10*HZ); //10s callback
603 pDevice->fTxDataInSleep = false;
604 pDevice->nTxDataTimeCout = 0;
607 pDevice->IsTxDataTrigger = true;
608 add_timer(&pDevice->sTimerTxData);
610 } else if (pMgmt->eCurrState < WMAC_STATE_ASSOCPENDING) {
611 netdev_err(pDevice->dev,
612 "WLAN_ASSOCIATE_WAIT:Association Fail???\n");
613 } else if (pDevice->byLinkWaitCount <= 4) { //mike add:wait another 2 sec if associated_frame delay!
614 pDevice->byLinkWaitCount++;
615 pr_debug("WLAN_ASSOCIATE_WAIT:wait %d times!!\n", pDevice->byLinkWaitCount);
616 spin_unlock_irq(&pDevice->lock);
617 vCommandTimerWait((void *)pDevice, ASSOCIATE_TIMEOUT/2);
620 pDevice->byLinkWaitCount = 0;
622 s_bCommandComplete(pDevice);
625 case WLAN_CMD_AP_MODE_START:
626 pr_debug("eCommandState == WLAN_CMD_AP_MODE_START\n");
628 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
629 del_timer(&pMgmt->sTimerSecondCallback);
630 pMgmt->eCurrState = WMAC_STATE_IDLE;
631 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
632 pDevice->bLinkPass = false;
633 if (pDevice->bEnableHostWEP)
634 BSSvClearNodeDBTable(pDevice, 1);
636 BSSvClearNodeDBTable(pDevice, 0);
637 pDevice->uAssocCount = 0;
638 pMgmt->eCurrState = WMAC_STATE_IDLE;
639 pDevice->bFixRate = false;
641 // alway turn off unicast bit
642 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_RCR, RCR_UNICAST);
643 pDevice->byRxMode &= ~RCR_UNICAST;
644 pr_debug("wcmd: rx_mode = %x\n", pDevice->byRxMode);
645 BSSvAddMulticastNode(pDevice);
646 if (netif_queue_stopped(pDevice->dev))
647 netif_wake_queue(pDevice->dev);
649 pDevice->bLinkPass = true;
650 add_timer(&pMgmt->sTimerSecondCallback);
652 s_bCommandComplete(pDevice);
655 case WLAN_CMD_TX_PSPACKET_START:
657 if (pMgmt->sNodeDBTable[0].bRxPSPoll) {
658 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[0].sTxPSQueue)) != NULL) {
659 if (skb_queue_empty(&pMgmt->sNodeDBTable[0].sTxPSQueue)) {
660 pMgmt->abyPSTxMap[0] &= ~byMask[0];
661 pDevice->bMoreData = false;
663 pDevice->bMoreData = true;
666 pMgmt->sNodeDBTable[0].wEnQueueCnt--;
671 for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) {
672 if (pMgmt->sNodeDBTable[ii].bActive &&
673 pMgmt->sNodeDBTable[ii].bRxPSPoll) {
674 pr_debug("Index=%d Enqueu Cnt= %d\n",
676 pMgmt->sNodeDBTable[ii].wEnQueueCnt);
677 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) != NULL) {
678 if (skb_queue_empty(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) {
680 pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[ii].wAID >> 3] &=
681 ~byMask[pMgmt->sNodeDBTable[ii].wAID & 7];
682 pDevice->bMoreData = false;
684 pDevice->bMoreData = true;
687 pMgmt->sNodeDBTable[ii].wEnQueueCnt--;
688 // check if sta ps enabled, and wait next pspoll.
689 // if sta ps disable, then send all pending buffers.
690 if (pMgmt->sNodeDBTable[ii].bPSEnable)
693 if (skb_queue_empty(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) {
695 pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[ii].wAID >> 3] &=
696 ~byMask[pMgmt->sNodeDBTable[ii].wAID & 7];
697 pr_debug("Index=%d PS queue clear\n",
700 pMgmt->sNodeDBTable[ii].bRxPSPoll = false;
704 s_bCommandComplete(pDevice);
707 case WLAN_CMD_RADIO_START:
708 pr_debug("eCommandState == WLAN_CMD_RADIO_START\n");
709 if (pDevice->bRadioCmd)
710 CARDbRadioPowerOn(pDevice);
712 CARDbRadioPowerOff(pDevice);
714 s_bCommandComplete(pDevice);
717 case WLAN_CMD_CHECK_BBSENSITIVITY_CHANGE:
718 // wait all TD complete
719 if (pDevice->iTDUsed[TYPE_AC0DMA] != 0) {
720 vCommandTimerWait((void *)pDevice, 10);
721 spin_unlock_irq(&pDevice->lock);
724 if (pDevice->iTDUsed[TYPE_TXDMA0] != 0) {
725 vCommandTimerWait((void *)pDevice, 10);
726 spin_unlock_irq(&pDevice->lock);
729 pDevice->byBBVGACurrent = pDevice->byBBVGANew;
730 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGACurrent);
731 pr_debug("SetVGAGainOffset %02X\n", pDevice->byBBVGACurrent);
732 s_bCommandComplete(pDevice);
736 s_bCommandComplete(pDevice);
740 spin_unlock_irq(&pDevice->lock);
746 struct vnt_private *pDevice
750 bool bRadioCmd = false;
751 bool bForceSCAN = true;
752 PSMgmtObject pMgmt = pDevice->pMgmt;
754 pDevice->eCommandState = WLAN_CMD_IDLE;
755 if (pDevice->cbFreeCmdQueue == CMD_Q_SIZE) {
756 //Command Queue Empty
757 pDevice->bCmdRunning = false;
760 pDevice->eCommand = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].eCmd;
761 pSSID = (PWLAN_IE_SSID)pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].abyCmdDesireSSID;
762 bRadioCmd = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].bRadioCmd;
763 bForceSCAN = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].bForceSCAN;
764 ADD_ONE_WITH_WRAP_AROUND(pDevice->uCmdDequeueIdx, CMD_Q_SIZE);
765 pDevice->cbFreeCmdQueue++;
766 pDevice->bCmdRunning = true;
767 switch (pDevice->eCommand) {
768 case WLAN_CMD_BSSID_SCAN:
769 pr_debug("eCommandState= WLAN_CMD_BSSID_SCAN\n");
770 pDevice->eCommandState = WLAN_CMD_SCAN_START;
771 pMgmt->uScanChannel = 0;
773 memcpy(pMgmt->abyScanSSID, pSSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
775 memset(pMgmt->abyScanSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
779 pDevice->eCommandState = WLAN_CMD_SSID_START;
780 if (pSSID->len > WLAN_SSID_MAXLEN)
781 pSSID->len = WLAN_SSID_MAXLEN;
783 memcpy(pDevice->pMgmt->abyDesireSSID, pSSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
784 pr_debug("eCommandState= WLAN_CMD_SSID_START\n");
786 case WLAN_CMD_DISASSOCIATE:
787 pDevice->eCommandState = WLAN_CMD_DISASSOCIATE_START;
789 case WLAN_CMD_RX_PSPOLL:
790 pDevice->eCommandState = WLAN_CMD_TX_PSPACKET_START;
792 case WLAN_CMD_RUN_AP:
793 pDevice->eCommandState = WLAN_CMD_AP_MODE_START;
796 pDevice->eCommandState = WLAN_CMD_RADIO_START;
797 pDevice->bRadioCmd = bRadioCmd;
799 case WLAN_CMD_CHANGE_BBSENSITIVITY:
800 pDevice->eCommandState = WLAN_CMD_CHECK_BBSENSITIVITY_CHANGE;
808 vCommandTimerWait((void *)pDevice, 0);
814 bool bScheduleCommand(
815 void *hDeviceContext,
817 unsigned char *pbyItem0
820 struct vnt_private *pDevice = hDeviceContext;
822 if (pDevice->cbFreeCmdQueue == 0)
825 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].eCmd = eCommand;
826 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bForceSCAN = true;
827 memset(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID, 0 , WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
829 if (pbyItem0 != NULL) {
831 case WLAN_CMD_BSSID_SCAN:
832 memcpy(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID,
833 pbyItem0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
834 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bForceSCAN = false;
838 memcpy(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID,
839 pbyItem0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
842 case WLAN_CMD_DISASSOCIATE:
843 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bNeedRadioOFF = *((int *)pbyItem0);
846 case WLAN_CMD_RX_PSPOLL:
850 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bRadioCmd = *((int *)pbyItem0);
853 case WLAN_CMD_CHANGE_BBSENSITIVITY:
854 pDevice->eCommandState = WLAN_CMD_CHECK_BBSENSITIVITY_CHANGE;
862 ADD_ONE_WITH_WRAP_AROUND(pDevice->uCmdEnqueueIdx, CMD_Q_SIZE);
863 pDevice->cbFreeCmdQueue--;
865 if (!pDevice->bCmdRunning)
866 s_bCommandComplete(pDevice);
873 * Clear BSSID_SCAN cmd in CMD Queue
877 * hDeviceContext - Pointer to the adapter
882 * Return Value: true if success; otherwise false
885 bool bClearBSSID_SCAN(
889 struct vnt_private *pDevice = hDeviceContext;
890 unsigned int uCmdDequeueIdx = pDevice->uCmdDequeueIdx;
893 if ((pDevice->cbFreeCmdQueue < CMD_Q_SIZE) && (uCmdDequeueIdx != pDevice->uCmdEnqueueIdx)) {
894 for (ii = 0; ii < (CMD_Q_SIZE - pDevice->cbFreeCmdQueue); ii++) {
895 if (pDevice->eCmdQueue[uCmdDequeueIdx].eCmd == WLAN_CMD_BSSID_SCAN)
896 pDevice->eCmdQueue[uCmdDequeueIdx].eCmd = WLAN_CMD_IDLE;
897 ADD_ONE_WITH_WRAP_AROUND(uCmdDequeueIdx, CMD_Q_SIZE);
898 if (uCmdDequeueIdx == pDevice->uCmdEnqueueIdx)
905 //mike add:reset command timer
911 struct vnt_private *pDevice = hDeviceContext;
914 del_timer(&pDevice->sTimerCommand);
916 init_timer(&pDevice->sTimerCommand);
917 pDevice->sTimerCommand.data = (unsigned long) pDevice;
918 pDevice->sTimerCommand.function = (TimerFunction)vCommandTimer;
919 pDevice->sTimerCommand.expires = RUN_AT(HZ);
920 pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
921 pDevice->uCmdDequeueIdx = 0;
922 pDevice->uCmdEnqueueIdx = 0;
923 pDevice->eCommandState = WLAN_CMD_IDLE;
924 pDevice->bCmdRunning = false;
925 pDevice->bCmdClear = false;
933 struct vnt_private *pDevice = hDeviceContext;
934 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
936 pDevice->nTxDataTimeCout++;
938 if (pDevice->nTxDataTimeCout < 4) //don't tx data if timer less than 40s
940 pDevice->sTimerTxData.expires = RUN_AT(10*HZ); //10s callback
941 add_timer(&pDevice->sTimerTxData);
945 spin_lock_irq(&pDevice->lock);
947 /* open && sharekey linking */
948 if ((pDevice->bLinkPass && (pMgmt->eAuthenMode < WMAC_AUTH_WPA)) ||
949 pDevice->fWPA_Authened) { /* wpa linking */
950 pDevice->fTxDataInSleep = true;
951 pDevice->fTxDataInSleep = false;
954 spin_unlock_irq(&pDevice->lock);
956 pDevice->sTimerTxData.expires = RUN_AT(10*HZ); /* 10s callback */
957 add_timer(&pDevice->sTimerTxData);