e1000e: cleanup PARENTHESIS_ALIGNMENT checkpatch checks
[linux/fpc-iii.git] / drivers / staging / vt6656 / wcmd.c
blob4bb652bf7cf6ce4d1df2d2a9deafd58f90ae3cbf
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 void s_vProbeChannel(struct vnt_private *);
73 static struct vnt_tx_mgmt *s_MgrMakeProbeRequest(struct vnt_private *,
74 struct vnt_manager *pMgmt, u8 *pScanBSSID, PWLAN_IE_SSID pSSID,
75 PWLAN_IE_SUPP_RATES pCurrRates, PWLAN_IE_SUPP_RATES pCurrExtSuppRates);
78 static int s_bCommandComplete(struct vnt_private *);
81 static int s_bClearBSSID_SCAN(struct vnt_private *);
83 /*--------------------- Export Variables --------------------------*/
85 /*--------------------- Export Functions --------------------------*/
88 * Description:
89 * Stop AdHoc beacon during scan process
91 * Parameters:
92 * In:
93 * pDevice - Pointer to the adapter
94 * Out:
95 * none
97 * Return Value: none
101 static void vAdHocBeaconStop(struct vnt_private *pDevice)
103 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
104 int bStop;
107 * temporarily stop Beacon packet for AdHoc Server
108 * if all of the following coditions are met:
109 * (1) STA is in AdHoc mode
110 * (2) VT3253 is programmed as automatic Beacon Transmitting
111 * (3) One of the following conditions is met
112 * (3.1) AdHoc channel is in B/G band and the
113 * current scan channel is in A band
114 * or
115 * (3.2) AdHoc channel is in A mode
117 bStop = false;
118 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) &&
119 (pMgmt->eCurrState >= WMAC_STATE_STARTED))
121 if ((pMgmt->uIBSSChannel <= CB_MAX_CHANNEL_24G) &&
122 (pMgmt->uScanChannel > CB_MAX_CHANNEL_24G))
124 bStop = true;
126 if (pMgmt->uIBSSChannel > CB_MAX_CHANNEL_24G)
128 bStop = true;
132 if (bStop)
134 //PMESG(("STOP_BEACON: IBSSChannel = %u, ScanChannel = %u\n",
135 // pMgmt->uIBSSChannel, pMgmt->uScanChannel));
136 MACvRegBitsOff(pDevice, MAC_REG_TCR, TCR_AUTOBCNTX);
139 } /* vAdHocBeaconStop */
143 * Description:
144 * Restart AdHoc beacon after scan process complete
146 * Parameters:
147 * In:
148 * pDevice - Pointer to the adapter
149 * Out:
150 * none
152 * Return Value: none
155 static void vAdHocBeaconRestart(struct vnt_private *pDevice)
157 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
160 * Restart Beacon packet for AdHoc Server
161 * if all of the following coditions are met:
162 * (1) STA is in AdHoc mode
163 * (2) VT3253 is programmed as automatic Beacon Transmitting
165 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) &&
166 (pMgmt->eCurrState >= WMAC_STATE_STARTED))
168 //PMESG(("RESTART_BEACON\n"));
169 MACvRegBitsOn(pDevice, MAC_REG_TCR, TCR_AUTOBCNTX);
177 * Routine Description:
178 * Prepare and send probe request management frames.
181 * Return Value:
182 * none.
186 static void s_vProbeChannel(struct vnt_private *pDevice)
188 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
189 struct vnt_tx_mgmt *pTxPacket;
190 u8 abyCurrSuppRatesG[] = {WLAN_EID_SUPP_RATES,
191 8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C};
192 /* 1M, 2M, 5M, 11M, 18M, 24M, 36M, 54M*/
193 u8 abyCurrExtSuppRatesG[] = {WLAN_EID_EXTSUPP_RATES,
194 4, 0x0C, 0x12, 0x18, 0x60};
195 /* 6M, 9M, 12M, 48M*/
196 u8 abyCurrSuppRatesA[] = {WLAN_EID_SUPP_RATES,
197 8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
198 u8 abyCurrSuppRatesB[] = {WLAN_EID_SUPP_RATES,
199 4, 0x02, 0x04, 0x0B, 0x16};
200 u8 *pbyRate;
201 int ii;
204 if (pDevice->byBBType == BB_TYPE_11A) {
205 pbyRate = &abyCurrSuppRatesA[0];
206 } else if (pDevice->byBBType == BB_TYPE_11B) {
207 pbyRate = &abyCurrSuppRatesB[0];
208 } else {
209 pbyRate = &abyCurrSuppRatesG[0];
211 // build an assocreq frame and send it
212 pTxPacket = s_MgrMakeProbeRequest
214 pDevice,
215 pMgmt,
216 pMgmt->abyScanBSSID,
217 (PWLAN_IE_SSID)pMgmt->abyScanSSID,
218 (PWLAN_IE_SUPP_RATES)pbyRate,
219 (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRatesG
222 if (pTxPacket != NULL ){
223 for (ii = 0; ii < 1 ; ii++) {
224 if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
225 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Probe request sending fail.. \n");
227 else {
228 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Probe request is sending.. \n");
240 * Routine Description:
241 * Constructs an probe request frame
244 * Return Value:
245 * A ptr to Tx frame or NULL on allocation failure
250 struct vnt_tx_mgmt *s_MgrMakeProbeRequest(struct vnt_private *pDevice,
251 struct vnt_manager *pMgmt, u8 *pScanBSSID, PWLAN_IE_SSID pSSID,
252 PWLAN_IE_SUPP_RATES pCurrRates, PWLAN_IE_SUPP_RATES pCurrExtSuppRates)
254 struct vnt_tx_mgmt *pTxPacket = NULL;
255 WLAN_FR_PROBEREQ sFrame;
258 pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
259 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
260 + WLAN_PROBEREQ_FR_MAXLEN);
261 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
262 + sizeof(struct vnt_tx_mgmt));
263 sFrame.pBuf = (PBYTE)pTxPacket->p80211Header;
264 sFrame.len = WLAN_PROBEREQ_FR_MAXLEN;
265 vMgrEncodeProbeRequest(&sFrame);
266 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
268 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
269 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_PROBEREQ)
271 memcpy( sFrame.pHdr->sA3.abyAddr1, pScanBSSID, WLAN_ADDR_LEN);
272 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
273 memcpy( sFrame.pHdr->sA3.abyAddr3, pScanBSSID, WLAN_BSSID_LEN);
274 // Copy the SSID, pSSID->len=0 indicate broadcast SSID
275 sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
276 sFrame.len += pSSID->len + WLAN_IEHDR_LEN;
277 memcpy(sFrame.pSSID, pSSID, pSSID->len + WLAN_IEHDR_LEN);
278 sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
279 sFrame.len += pCurrRates->len + WLAN_IEHDR_LEN;
280 memcpy(sFrame.pSuppRates, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
281 // Copy the extension rate set
282 if (pDevice->byBBType == BB_TYPE_11G) {
283 sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
284 sFrame.len += pCurrExtSuppRates->len + WLAN_IEHDR_LEN;
285 memcpy(sFrame.pExtSuppRates, pCurrExtSuppRates, pCurrExtSuppRates->len + WLAN_IEHDR_LEN);
287 pTxPacket->cbMPDULen = sFrame.len;
288 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
290 return pTxPacket;
293 void vCommandTimerWait(struct vnt_private *pDevice, unsigned long MSecond)
296 init_timer(&pDevice->sTimerCommand);
298 pDevice->sTimerCommand.data = (unsigned long)pDevice;
299 pDevice->sTimerCommand.function = (TimerFunction)vRunCommand;
300 pDevice->sTimerCommand.expires = RUN_AT((MSecond * HZ) / 1000);
302 add_timer(&pDevice->sTimerCommand);
304 return;
307 void vRunCommand(struct vnt_private *pDevice)
309 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
310 PWLAN_IE_SSID pItemSSID;
311 PWLAN_IE_SSID pItemSSIDCurr;
312 CMD_STATUS Status;
313 struct sk_buff *skb;
314 union iwreq_data wrqu;
315 int ii;
316 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
317 u8 byData;
320 if (pDevice->dwDiagRefCount != 0)
321 return;
322 if (pDevice->bCmdRunning != true)
323 return;
325 spin_lock_irq(&pDevice->lock);
327 switch ( pDevice->eCommandState ) {
329 case WLAN_CMD_SCAN_START:
331 pDevice->byReAssocCount = 0;
332 if (pDevice->bRadioOff == true) {
333 s_bCommandComplete(pDevice);
334 spin_unlock_irq(&pDevice->lock);
335 return;
338 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
339 s_bCommandComplete(pDevice);
340 spin_unlock_irq(&pDevice->lock);
341 return;
344 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyScanSSID;
346 if (pMgmt->uScanChannel == 0 ) {
347 pMgmt->uScanChannel = pDevice->byMinChannel;
349 if (pMgmt->uScanChannel > pDevice->byMaxChannel) {
350 pMgmt->eScanState = WMAC_NO_SCANNING;
352 if (pDevice->byBBType != pDevice->byScanBBType) {
353 pDevice->byBBType = pDevice->byScanBBType;
354 CARDvSetBSSMode(pDevice);
357 if (pDevice->bUpdateBBVGA) {
358 BBvSetShortSlotTime(pDevice);
359 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGACurrent);
360 BBvUpdatePreEDThreshold(pDevice, false);
362 // Set channel back
363 vAdHocBeaconRestart(pDevice);
364 // Set channel back
365 CARDbSetMediaChannel(pDevice, pMgmt->uCurrChannel);
366 // Set Filter
367 if (pMgmt->bCurrBSSIDFilterOn) {
368 MACvRegBitsOn(pDevice, MAC_REG_RCR, RCR_BSSID);
369 pDevice->byRxMode |= RCR_BSSID;
371 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Scanning, set back to channel: [%d]\n", pMgmt->uCurrChannel);
372 pDevice->bStopDataPkt = false;
373 s_bCommandComplete(pDevice);
374 spin_unlock_irq(&pDevice->lock);
375 return;
377 } else {
378 if (!ChannelValid(pDevice->byZoneType, pMgmt->uScanChannel)) {
379 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Invalid channel pMgmt->uScanChannel = %d \n",pMgmt->uScanChannel);
380 s_bCommandComplete(pDevice);
381 spin_unlock_irq(&pDevice->lock);
382 return;
384 if (pMgmt->uScanChannel == pDevice->byMinChannel) {
385 // pMgmt->eScanType = WMAC_SCAN_ACTIVE; //mike mark
386 pMgmt->abyScanBSSID[0] = 0xFF;
387 pMgmt->abyScanBSSID[1] = 0xFF;
388 pMgmt->abyScanBSSID[2] = 0xFF;
389 pMgmt->abyScanBSSID[3] = 0xFF;
390 pMgmt->abyScanBSSID[4] = 0xFF;
391 pMgmt->abyScanBSSID[5] = 0xFF;
392 pItemSSID->byElementID = WLAN_EID_SSID;
393 // clear bssid list
394 /* BSSvClearBSSList((void *) pDevice,
395 pDevice->bLinkPass); */
396 pMgmt->eScanState = WMAC_IS_SCANNING;
397 pDevice->byScanBBType = pDevice->byBBType; //lucas
398 pDevice->bStopDataPkt = true;
399 // Turn off RCR_BSSID filter every time
400 MACvRegBitsOff(pDevice, MAC_REG_RCR, RCR_BSSID);
401 pDevice->byRxMode &= ~RCR_BSSID;
404 //lucas
405 vAdHocBeaconStop(pDevice);
406 if ((pDevice->byBBType != BB_TYPE_11A) && (pMgmt->uScanChannel > CB_MAX_CHANNEL_24G)) {
407 pDevice->byBBType = BB_TYPE_11A;
408 CARDvSetBSSMode(pDevice);
410 else if ((pDevice->byBBType == BB_TYPE_11A) && (pMgmt->uScanChannel <= CB_MAX_CHANNEL_24G)) {
411 pDevice->byBBType = BB_TYPE_11G;
412 CARDvSetBSSMode(pDevice);
414 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Scanning.... channel: [%d]\n", pMgmt->uScanChannel);
415 // Set channel
416 CARDbSetMediaChannel(pDevice, pMgmt->uScanChannel);
417 // Set Baseband to be more sensitive.
419 if (pDevice->bUpdateBBVGA) {
420 BBvSetShortSlotTime(pDevice);
421 BBvSetVGAGainOffset(pDevice, pDevice->abyBBVGA[0]);
422 BBvUpdatePreEDThreshold(pDevice, true);
424 pMgmt->uScanChannel++;
426 while (!ChannelValid(pDevice->byZoneType, pMgmt->uScanChannel) &&
427 pMgmt->uScanChannel <= pDevice->byMaxChannel ){
428 pMgmt->uScanChannel++;
431 if (pMgmt->uScanChannel > pDevice->byMaxChannel) {
432 // Set Baseband to be not sensitive and rescan
433 pDevice->eCommandState = WLAN_CMD_SCAN_END;
436 if ((pMgmt->b11hEnable == false) ||
437 (pMgmt->uScanChannel < CB_MAX_CHANNEL_24G)) {
438 s_vProbeChannel(pDevice);
439 spin_unlock_irq(&pDevice->lock);
440 vCommandTimerWait((void *) pDevice, 100);
441 return;
442 } else {
443 spin_unlock_irq(&pDevice->lock);
444 vCommandTimerWait((void *) pDevice, WCMD_PASSIVE_SCAN_TIME);
445 return;
450 break;
452 case WLAN_CMD_SCAN_END:
454 // Set Baseband's sensitivity back.
455 if (pDevice->byBBType != pDevice->byScanBBType) {
456 pDevice->byBBType = pDevice->byScanBBType;
457 CARDvSetBSSMode(pDevice);
460 if (pDevice->bUpdateBBVGA) {
461 BBvSetShortSlotTime(pDevice);
462 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGACurrent);
463 BBvUpdatePreEDThreshold(pDevice, false);
466 // Set channel back
467 vAdHocBeaconRestart(pDevice);
468 // Set channel back
469 CARDbSetMediaChannel(pDevice, pMgmt->uCurrChannel);
470 // Set Filter
471 if (pMgmt->bCurrBSSIDFilterOn) {
472 MACvRegBitsOn(pDevice, MAC_REG_RCR, RCR_BSSID);
473 pDevice->byRxMode |= RCR_BSSID;
475 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Scanning, set back to channel: [%d]\n", pMgmt->uCurrChannel);
476 pMgmt->eScanState = WMAC_NO_SCANNING;
477 pDevice->bStopDataPkt = false;
479 /*send scan event to wpa_Supplicant*/
480 PRINT_K("wireless_send_event--->SIOCGIWSCAN(scan done)\n");
481 memset(&wrqu, 0, sizeof(wrqu));
482 wireless_send_event(pDevice->dev, SIOCGIWSCAN, &wrqu, NULL);
484 s_bCommandComplete(pDevice);
485 break;
487 case WLAN_CMD_DISASSOCIATE_START :
488 pDevice->byReAssocCount = 0;
489 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
490 (pMgmt->eCurrState != WMAC_STATE_ASSOC)) {
491 s_bCommandComplete(pDevice);
492 spin_unlock_irq(&pDevice->lock);
493 return;
494 } else {
496 pDevice->bwextstep0 = false;
497 pDevice->bwextstep1 = false;
498 pDevice->bwextstep2 = false;
499 pDevice->bwextstep3 = false;
500 pDevice->bWPASuppWextEnabled = false;
501 pDevice->fWPA_Authened = false;
503 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Send Disassociation Packet..\n");
504 // reason = 8 : disassoc because sta has left
505 vMgrDisassocBeginSta((void *) pDevice,
506 pMgmt,
507 pMgmt->abyCurrBSSID,
508 (8),
509 &Status);
510 pDevice->bLinkPass = false;
511 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW);
512 // unlock command busy
513 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
514 pItemSSID->len = 0;
515 memset(pItemSSID->abySSID, 0, WLAN_SSID_MAXLEN);
516 pMgmt->eCurrState = WMAC_STATE_IDLE;
517 pMgmt->sNodeDBTable[0].bActive = false;
518 // pDevice->bBeaconBufReady = false;
520 netif_stop_queue(pDevice->dev);
521 if (pDevice->bNeedRadioOFF == true)
522 CARDbRadioPowerOff(pDevice);
523 s_bCommandComplete(pDevice);
524 break;
527 case WLAN_CMD_SSID_START:
529 pDevice->byReAssocCount = 0;
530 if (pDevice->bRadioOff == true) {
531 s_bCommandComplete(pDevice);
532 spin_unlock_irq(&pDevice->lock);
533 return;
536 memcpy(pMgmt->abyAdHocSSID,pMgmt->abyDesireSSID,
537 ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->len + WLAN_IEHDR_LEN);
539 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
540 pItemSSIDCurr = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
541 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" cmd: desire ssid = %s\n", pItemSSID->abySSID);
542 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" cmd: curr ssid = %s\n", pItemSSIDCurr->abySSID);
544 if (pMgmt->eCurrState == WMAC_STATE_ASSOC) {
545 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Cmd pMgmt->eCurrState == WMAC_STATE_ASSOC\n");
546 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" pItemSSID->len =%d\n",pItemSSID->len);
547 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" pItemSSIDCurr->len = %d\n",pItemSSIDCurr->len);
548 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" desire ssid = %s\n", pItemSSID->abySSID);
549 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" curr ssid = %s\n", pItemSSIDCurr->abySSID);
552 if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) ||
553 ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)&& (pMgmt->eCurrState == WMAC_STATE_JOINTED))) {
555 if (pItemSSID->len == pItemSSIDCurr->len) {
556 if (memcmp(pItemSSID->abySSID, pItemSSIDCurr->abySSID, pItemSSID->len) == 0) {
557 s_bCommandComplete(pDevice);
558 spin_unlock_irq(&pDevice->lock);
559 return;
562 netif_stop_queue(pDevice->dev);
563 pDevice->bLinkPass = false;
564 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW);
566 // set initial state
567 pMgmt->eCurrState = WMAC_STATE_IDLE;
568 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
569 PSvDisablePowerSaving((void *) pDevice);
570 BSSvClearNodeDBTable(pDevice, 0);
571 vMgrJoinBSSBegin((void *) pDevice, &Status);
572 // if Infra mode
573 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED)) {
574 // Call mgr to begin the deauthentication
575 // reason = (3) because sta has left ESS
576 if (pMgmt->eCurrState >= WMAC_STATE_AUTH) {
577 vMgrDeAuthenBeginSta((void *)pDevice,
578 pMgmt,
579 pMgmt->abyCurrBSSID,
580 (3),
581 &Status);
583 // Call mgr to begin the authentication
584 vMgrAuthenBeginSta((void *) pDevice, pMgmt, &Status);
585 if (Status == CMD_STATUS_SUCCESS) {
586 pDevice->byLinkWaitCount = 0;
587 pDevice->eCommandState = WLAN_AUTHENTICATE_WAIT;
588 vCommandTimerWait((void *) pDevice, AUTHENTICATE_TIMEOUT);
589 spin_unlock_irq(&pDevice->lock);
590 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Set eCommandState = WLAN_AUTHENTICATE_WAIT\n");
591 return;
594 // if Adhoc mode
595 else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
596 if (pMgmt->eCurrState == WMAC_STATE_JOINTED) {
597 if (netif_queue_stopped(pDevice->dev)){
598 netif_wake_queue(pDevice->dev);
600 pDevice->bLinkPass = true;
601 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER);
602 pMgmt->sNodeDBTable[0].bActive = true;
603 pMgmt->sNodeDBTable[0].uInActiveCount = 0;
605 else {
606 // start own IBSS
607 DBG_PRT(MSG_LEVEL_DEBUG,
608 KERN_INFO "CreateOwn IBSS by CurrMode = IBSS_STA\n");
609 vMgrCreateOwnIBSS((void *) pDevice, &Status);
610 if (Status != CMD_STATUS_SUCCESS){
611 DBG_PRT(MSG_LEVEL_DEBUG,
612 KERN_INFO "WLAN_CMD_IBSS_CREATE fail!\n");
614 BSSvAddMulticastNode(pDevice);
616 s_bClearBSSID_SCAN(pDevice);
618 // if SSID not found
619 else if (pMgmt->eCurrMode == WMAC_MODE_STANDBY) {
620 if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA ||
621 pMgmt->eConfigMode == WMAC_CONFIG_AUTO) {
622 // start own IBSS
623 DBG_PRT(MSG_LEVEL_DEBUG,
624 KERN_INFO "CreateOwn IBSS by CurrMode = STANDBY\n");
625 vMgrCreateOwnIBSS((void *) pDevice, &Status);
626 if (Status != CMD_STATUS_SUCCESS){
627 DBG_PRT(MSG_LEVEL_DEBUG,
628 KERN_INFO "WLAN_CMD_IBSS_CREATE fail!\n");
630 BSSvAddMulticastNode(pDevice);
631 s_bClearBSSID_SCAN(pDevice);
633 pDevice->bLinkPass = true;
634 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER);
635 if (netif_queue_stopped(pDevice->dev)){
636 netif_wake_queue(pDevice->dev);
638 s_bClearBSSID_SCAN(pDevice);
641 else {
642 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disconnect SSID none\n");
643 // if(pDevice->bWPASuppWextEnabled == true)
645 union iwreq_data wrqu;
646 memset(&wrqu, 0, sizeof (wrqu));
647 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
648 PRINT_K("wireless_send_event--->SIOCGIWAP(disassociated:vMgrJoinBSSBegin Fail !!)\n");
649 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
653 s_bCommandComplete(pDevice);
654 break;
656 case WLAN_AUTHENTICATE_WAIT :
657 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState == WLAN_AUTHENTICATE_WAIT\n");
658 if (pMgmt->eCurrState == WMAC_STATE_AUTH) {
659 pDevice->byLinkWaitCount = 0;
660 // Call mgr to begin the association
661 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCurrState == WMAC_STATE_AUTH\n");
662 vMgrAssocBeginSta((void *) pDevice, pMgmt, &Status);
663 if (Status == CMD_STATUS_SUCCESS) {
664 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState = WLAN_ASSOCIATE_WAIT\n");
665 pDevice->byLinkWaitCount = 0;
666 pDevice->eCommandState = WLAN_ASSOCIATE_WAIT;
667 vCommandTimerWait((void *) pDevice, ASSOCIATE_TIMEOUT);
668 spin_unlock_irq(&pDevice->lock);
669 return;
672 else if(pMgmt->eCurrState < WMAC_STATE_AUTHPENDING) {
673 printk("WLAN_AUTHENTICATE_WAIT:Authen Fail???\n");
675 else if(pDevice->byLinkWaitCount <= 4){ //mike add:wait another 2 sec if authenticated_frame delay!
676 pDevice->byLinkWaitCount ++;
677 printk("WLAN_AUTHENTICATE_WAIT:wait %d times!!\n",pDevice->byLinkWaitCount);
678 spin_unlock_irq(&pDevice->lock);
679 vCommandTimerWait((void *) pDevice, AUTHENTICATE_TIMEOUT/2);
680 return;
682 pDevice->byLinkWaitCount = 0;
684 s_bCommandComplete(pDevice);
685 break;
687 case WLAN_ASSOCIATE_WAIT :
688 if (pMgmt->eCurrState == WMAC_STATE_ASSOC) {
689 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCurrState == WMAC_STATE_ASSOC\n");
690 if (pDevice->ePSMode != WMAC_POWER_CAM) {
691 PSvEnablePowerSaving((void *) pDevice,
692 pMgmt->wListenInterval);
695 if (pMgmt->eAuthenMode >= WMAC_AUTH_WPA) {
696 KeybRemoveAllKey(pDevice, &(pDevice->sKey), pDevice->abyBSSID);
699 pDevice->byLinkWaitCount = 0;
700 pDevice->byReAssocCount = 0;
701 pDevice->bLinkPass = true;
702 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER);
703 s_bClearBSSID_SCAN(pDevice);
705 if (netif_queue_stopped(pDevice->dev)){
706 netif_wake_queue(pDevice->dev);
709 if(pDevice->IsTxDataTrigger != false) { //TxDataTimer is not triggered at the first time
710 // printk("Re-initial TxDataTimer****\n");
711 del_timer(&pDevice->sTimerTxData);
712 init_timer(&pDevice->sTimerTxData);
713 pDevice->sTimerTxData.data = (unsigned long) pDevice;
714 pDevice->sTimerTxData.function = (TimerFunction)BSSvSecondTxData;
715 pDevice->sTimerTxData.expires = RUN_AT(10*HZ); //10s callback
716 pDevice->fTxDataInSleep = false;
717 pDevice->nTxDataTimeCout = 0;
719 else {
720 // printk("mike:-->First time trigger TimerTxData InSleep\n");
722 pDevice->IsTxDataTrigger = true;
723 add_timer(&pDevice->sTimerTxData);
726 else if(pMgmt->eCurrState < WMAC_STATE_ASSOCPENDING) {
727 printk("WLAN_ASSOCIATE_WAIT:Association Fail???\n");
729 else if(pDevice->byLinkWaitCount <= 4){ //mike add:wait another 2 sec if associated_frame delay!
730 pDevice->byLinkWaitCount ++;
731 printk("WLAN_ASSOCIATE_WAIT:wait %d times!!\n",pDevice->byLinkWaitCount);
732 spin_unlock_irq(&pDevice->lock);
733 vCommandTimerWait((void *) pDevice, ASSOCIATE_TIMEOUT/2);
734 return;
736 pDevice->byLinkWaitCount = 0;
738 s_bCommandComplete(pDevice);
739 break;
741 case WLAN_CMD_AP_MODE_START :
742 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState == WLAN_CMD_AP_MODE_START\n");
744 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
745 del_timer(&pMgmt->sTimerSecondCallback);
746 pMgmt->eCurrState = WMAC_STATE_IDLE;
747 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
748 pDevice->bLinkPass = false;
749 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW);
750 if (pDevice->bEnableHostWEP == true)
751 BSSvClearNodeDBTable(pDevice, 1);
752 else
753 BSSvClearNodeDBTable(pDevice, 0);
754 pDevice->uAssocCount = 0;
755 pMgmt->eCurrState = WMAC_STATE_IDLE;
756 pDevice->bFixRate = false;
758 vMgrCreateOwnIBSS((void *) pDevice, &Status);
759 if (Status != CMD_STATUS_SUCCESS) {
760 DBG_PRT(MSG_LEVEL_DEBUG,
761 KERN_INFO "vMgrCreateOwnIBSS fail!\n");
763 // always turn off unicast bit
764 MACvRegBitsOff(pDevice, MAC_REG_RCR, RCR_UNICAST);
765 pDevice->byRxMode &= ~RCR_UNICAST;
766 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wcmd: rx_mode = %x\n", pDevice->byRxMode );
767 BSSvAddMulticastNode(pDevice);
768 if (netif_queue_stopped(pDevice->dev)){
769 netif_wake_queue(pDevice->dev);
771 pDevice->bLinkPass = true;
772 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER);
773 add_timer(&pMgmt->sTimerSecondCallback);
775 s_bCommandComplete(pDevice);
776 break;
778 case WLAN_CMD_TX_PSPACKET_START :
779 // DTIM Multicast tx
780 if (pMgmt->sNodeDBTable[0].bRxPSPoll) {
781 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[0].sTxPSQueue)) != NULL) {
782 if (skb_queue_empty(&pMgmt->sNodeDBTable[0].sTxPSQueue)) {
783 pMgmt->abyPSTxMap[0] &= ~byMask[0];
784 pDevice->bMoreData = false;
786 else {
787 pDevice->bMoreData = true;
790 if (nsDMA_tx_packet(pDevice, TYPE_AC0DMA, skb) != 0) {
791 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Multicast ps tx fail \n");
794 pMgmt->sNodeDBTable[0].wEnQueueCnt--;
798 // PS nodes tx
799 for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) {
800 if (pMgmt->sNodeDBTable[ii].bActive &&
801 pMgmt->sNodeDBTable[ii].bRxPSPoll) {
802 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Index=%d Enqueu Cnt= %d\n",
803 ii, pMgmt->sNodeDBTable[ii].wEnQueueCnt);
804 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) != NULL) {
805 if (skb_queue_empty(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) {
806 // clear tx map
807 pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[ii].wAID >> 3] &=
808 ~byMask[pMgmt->sNodeDBTable[ii].wAID & 7];
809 pDevice->bMoreData = false;
811 else {
812 pDevice->bMoreData = true;
815 if (nsDMA_tx_packet(pDevice, TYPE_AC0DMA, skb) != 0) {
816 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "sta ps tx fail \n");
819 pMgmt->sNodeDBTable[ii].wEnQueueCnt--;
820 // check if sta ps enable, wait next pspoll
821 // if sta ps disable, send all pending buffers.
822 if (pMgmt->sNodeDBTable[ii].bPSEnable)
823 break;
825 if (skb_queue_empty(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) {
826 // clear tx map
827 pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[ii].wAID >> 3] &=
828 ~byMask[pMgmt->sNodeDBTable[ii].wAID & 7];
829 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Index=%d PS queue clear \n", ii);
831 pMgmt->sNodeDBTable[ii].bRxPSPoll = false;
835 s_bCommandComplete(pDevice);
836 break;
838 case WLAN_CMD_RADIO_START:
840 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState == WLAN_CMD_RADIO_START\n");
841 // if (pDevice->bRadioCmd == true)
842 // CARDbRadioPowerOn(pDevice);
843 // else
844 // CARDbRadioPowerOff(pDevice);
847 int ntStatus = STATUS_SUCCESS;
848 BYTE byTmp;
850 ntStatus = CONTROLnsRequestIn(pDevice,
851 MESSAGE_TYPE_READ,
852 MAC_REG_GPIOCTL1,
853 MESSAGE_REQUEST_MACREG,
855 &byTmp);
857 if ( ntStatus != STATUS_SUCCESS ) {
858 s_bCommandComplete(pDevice);
859 spin_unlock_irq(&pDevice->lock);
860 return;
862 if ( (byTmp & GPIO3_DATA) == 0 ) {
863 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" WLAN_CMD_RADIO_START_OFF........................\n");
864 // Old commands are useless.
865 // empty command Q
866 pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
867 pDevice->uCmdDequeueIdx = 0;
868 pDevice->uCmdEnqueueIdx = 0;
869 //0415pDevice->bCmdRunning = false;
870 pDevice->bCmdClear = true;
871 pDevice->bStopTx0Pkt = false;
872 pDevice->bStopDataPkt = true;
874 pDevice->byKeyIndex = 0;
875 pDevice->bTransmitKey = false;
876 spin_unlock_irq(&pDevice->lock);
877 KeyvInitTable(pDevice,&pDevice->sKey);
878 spin_lock_irq(&pDevice->lock);
879 pMgmt->byCSSPK = KEY_CTL_NONE;
880 pMgmt->byCSSGK = KEY_CTL_NONE;
882 if (pDevice->bLinkPass == true) {
883 // reason = 8 : disassoc because sta has left
884 vMgrDisassocBeginSta((void *) pDevice,
885 pMgmt,
886 pMgmt->abyCurrBSSID,
887 (8),
888 &Status);
889 pDevice->bLinkPass = false;
890 // unlock command busy
891 pMgmt->eCurrState = WMAC_STATE_IDLE;
892 pMgmt->sNodeDBTable[0].bActive = false;
893 // if(pDevice->bWPASuppWextEnabled == true)
895 union iwreq_data wrqu;
896 memset(&wrqu, 0, sizeof (wrqu));
897 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
898 PRINT_K("wireless_send_event--->SIOCGIWAP(disassociated)\n");
899 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
902 pDevice->bwextstep0 = false;
903 pDevice->bwextstep1 = false;
904 pDevice->bwextstep2 = false;
905 pDevice->bwextstep3 = false;
906 pDevice->bWPASuppWextEnabled = false;
907 //clear current SSID
908 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
909 pItemSSID->len = 0;
910 memset(pItemSSID->abySSID, 0, WLAN_SSID_MAXLEN);
911 //clear desired SSID
912 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
913 pItemSSID->len = 0;
914 memset(pItemSSID->abySSID, 0, WLAN_SSID_MAXLEN);
916 netif_stop_queue(pDevice->dev);
917 CARDbRadioPowerOff(pDevice);
918 MACvRegBitsOn(pDevice,MAC_REG_GPIOCTL1,GPIO3_INTMD);
919 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_OFF);
920 pDevice->bHWRadioOff = true;
921 } else {
922 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" WLAN_CMD_RADIO_START_ON........................\n");
923 pDevice->bHWRadioOff = false;
924 CARDbRadioPowerOn(pDevice);
925 MACvRegBitsOff(pDevice,MAC_REG_GPIOCTL1,GPIO3_INTMD);
926 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_ON);
930 s_bCommandComplete(pDevice);
931 break;
934 case WLAN_CMD_CHANGE_BBSENSITIVITY_START:
936 pDevice->bStopDataPkt = true;
937 pDevice->byBBVGACurrent = pDevice->byBBVGANew;
938 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGACurrent);
939 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Change sensitivity pDevice->byBBVGACurrent = %x\n", pDevice->byBBVGACurrent);
940 pDevice->bStopDataPkt = false;
941 s_bCommandComplete(pDevice);
942 break;
944 case WLAN_CMD_TBTT_WAKEUP_START:
945 PSbIsNextTBTTWakeUp(pDevice);
946 s_bCommandComplete(pDevice);
947 break;
949 case WLAN_CMD_BECON_SEND_START:
950 bMgrPrepareBeaconToSend(pDevice, pMgmt);
951 s_bCommandComplete(pDevice);
952 break;
954 case WLAN_CMD_SETPOWER_START:
956 RFbSetPower(pDevice, pDevice->wCurrentRate, pMgmt->uCurrChannel);
958 s_bCommandComplete(pDevice);
959 break;
961 case WLAN_CMD_CHANGE_ANTENNA_START:
962 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Change from Antenna%d to", (int)pDevice->dwRxAntennaSel);
963 if ( pDevice->dwRxAntennaSel == 0) {
964 pDevice->dwRxAntennaSel=1;
965 if (pDevice->bTxRxAntInv == true)
966 BBvSetAntennaMode(pDevice, ANT_RXA);
967 else
968 BBvSetAntennaMode(pDevice, ANT_RXB);
969 } else {
970 pDevice->dwRxAntennaSel=0;
971 if (pDevice->bTxRxAntInv == true)
972 BBvSetAntennaMode(pDevice, ANT_RXB);
973 else
974 BBvSetAntennaMode(pDevice, ANT_RXA);
976 s_bCommandComplete(pDevice);
977 break;
979 case WLAN_CMD_REMOVE_ALLKEY_START:
980 KeybRemoveAllKey(pDevice, &(pDevice->sKey), pDevice->abyBSSID);
981 s_bCommandComplete(pDevice);
982 break;
985 case WLAN_CMD_MAC_DISPOWERSAVING_START:
986 ControlvReadByte (pDevice, MESSAGE_REQUEST_MACREG, MAC_REG_PSCTL, &byData);
987 if ( (byData & PSCTL_PS) != 0 ) {
988 // disable power saving hw function
989 CONTROLnsRequestOut(pDevice,
990 MESSAGE_TYPE_DISABLE_PS,
994 NULL
997 s_bCommandComplete(pDevice);
998 break;
1000 case WLAN_CMD_11H_CHSW_START:
1001 CARDbSetMediaChannel(pDevice, pDevice->byNewChannel);
1002 pDevice->bChannelSwitch = false;
1003 pMgmt->uCurrChannel = pDevice->byNewChannel;
1004 pDevice->bStopDataPkt = false;
1005 s_bCommandComplete(pDevice);
1006 break;
1008 default:
1009 s_bCommandComplete(pDevice);
1010 break;
1011 } //switch
1013 spin_unlock_irq(&pDevice->lock);
1014 return;
1018 static int s_bCommandComplete(struct vnt_private *pDevice)
1020 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1021 PWLAN_IE_SSID pSSID;
1022 int bRadioCmd = false;
1023 int bForceSCAN = true;
1026 pDevice->eCommandState = WLAN_CMD_IDLE;
1027 if (pDevice->cbFreeCmdQueue == CMD_Q_SIZE) {
1028 //Command Queue Empty
1029 pDevice->bCmdRunning = false;
1030 return true;
1032 else {
1033 pDevice->eCommand = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].eCmd;
1034 pSSID = (PWLAN_IE_SSID)pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].abyCmdDesireSSID;
1035 bRadioCmd = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].bRadioCmd;
1036 bForceSCAN = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].bForceSCAN;
1037 ADD_ONE_WITH_WRAP_AROUND(pDevice->uCmdDequeueIdx, CMD_Q_SIZE);
1038 pDevice->cbFreeCmdQueue++;
1039 pDevice->bCmdRunning = true;
1040 switch ( pDevice->eCommand ) {
1041 case WLAN_CMD_BSSID_SCAN:
1042 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState= WLAN_CMD_BSSID_SCAN\n");
1043 pDevice->eCommandState = WLAN_CMD_SCAN_START;
1044 pMgmt->uScanChannel = 0;
1045 if (pSSID->len != 0) {
1046 memcpy(pMgmt->abyScanSSID, pSSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
1047 } else {
1048 memset(pMgmt->abyScanSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
1051 if ((bForceSCAN == false) && (pDevice->bLinkPass == true)) {
1052 if ((pSSID->len == ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len) &&
1053 ( !memcmp(pSSID->abySSID, ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID, pSSID->len))) {
1054 pDevice->eCommandState = WLAN_CMD_IDLE;
1058 break;
1059 case WLAN_CMD_SSID:
1060 pDevice->eCommandState = WLAN_CMD_SSID_START;
1061 if (pSSID->len > WLAN_SSID_MAXLEN)
1062 pSSID->len = WLAN_SSID_MAXLEN;
1063 if (pSSID->len != 0)
1064 memcpy(pMgmt->abyDesireSSID, pSSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
1065 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState= WLAN_CMD_SSID_START\n");
1066 break;
1067 case WLAN_CMD_DISASSOCIATE:
1068 pDevice->eCommandState = WLAN_CMD_DISASSOCIATE_START;
1069 break;
1070 case WLAN_CMD_RX_PSPOLL:
1071 pDevice->eCommandState = WLAN_CMD_TX_PSPACKET_START;
1072 break;
1073 case WLAN_CMD_RUN_AP:
1074 pDevice->eCommandState = WLAN_CMD_AP_MODE_START;
1075 break;
1076 case WLAN_CMD_RADIO:
1077 pDevice->eCommandState = WLAN_CMD_RADIO_START;
1078 pDevice->bRadioCmd = bRadioCmd;
1079 break;
1080 case WLAN_CMD_CHANGE_BBSENSITIVITY:
1081 pDevice->eCommandState = WLAN_CMD_CHANGE_BBSENSITIVITY_START;
1082 break;
1084 case WLAN_CMD_TBTT_WAKEUP:
1085 pDevice->eCommandState = WLAN_CMD_TBTT_WAKEUP_START;
1086 break;
1088 case WLAN_CMD_BECON_SEND:
1089 pDevice->eCommandState = WLAN_CMD_BECON_SEND_START;
1090 break;
1092 case WLAN_CMD_SETPOWER:
1093 pDevice->eCommandState = WLAN_CMD_SETPOWER_START;
1094 break;
1096 case WLAN_CMD_CHANGE_ANTENNA:
1097 pDevice->eCommandState = WLAN_CMD_CHANGE_ANTENNA_START;
1098 break;
1100 case WLAN_CMD_REMOVE_ALLKEY:
1101 pDevice->eCommandState = WLAN_CMD_REMOVE_ALLKEY_START;
1102 break;
1104 case WLAN_CMD_MAC_DISPOWERSAVING:
1105 pDevice->eCommandState = WLAN_CMD_MAC_DISPOWERSAVING_START;
1106 break;
1108 case WLAN_CMD_11H_CHSW:
1109 pDevice->eCommandState = WLAN_CMD_11H_CHSW_START;
1110 break;
1112 default:
1113 break;
1116 vCommandTimerWait(pDevice, 0);
1119 return true;
1122 int bScheduleCommand(struct vnt_private *pDevice,
1123 CMD_CODE eCommand, u8 *pbyItem0)
1126 if (pDevice->cbFreeCmdQueue == 0) {
1127 return (false);
1129 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].eCmd = eCommand;
1130 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bForceSCAN = true;
1131 memset(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID, 0 , WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
1132 if (pbyItem0 != NULL) {
1133 switch (eCommand) {
1134 case WLAN_CMD_BSSID_SCAN:
1135 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bForceSCAN = false;
1136 memcpy(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID,
1137 pbyItem0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
1138 break;
1140 case WLAN_CMD_SSID:
1141 memcpy(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID,
1142 pbyItem0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
1143 break;
1145 case WLAN_CMD_DISASSOCIATE:
1146 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bNeedRadioOFF = *((int *)pbyItem0);
1147 break;
1149 case WLAN_CMD_DEAUTH:
1150 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].wDeAuthenReason = *((PWORD)pbyItem0);
1151 break;
1154 case WLAN_CMD_RADIO:
1155 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bRadioCmd = *((int *)pbyItem0);
1156 break;
1158 default:
1159 break;
1163 ADD_ONE_WITH_WRAP_AROUND(pDevice->uCmdEnqueueIdx, CMD_Q_SIZE);
1164 pDevice->cbFreeCmdQueue--;
1166 if (pDevice->bCmdRunning == false) {
1167 s_bCommandComplete(pDevice);
1169 else {
1171 return (true);
1176 * Description:
1177 * Clear BSSID_SCAN cmd in CMD Queue
1179 * Parameters:
1180 * In:
1181 * hDeviceContext - Pointer to the adapter
1182 * eCommand - Command
1183 * Out:
1184 * none
1186 * Return Value: true if success; otherwise false
1189 static int s_bClearBSSID_SCAN(struct vnt_private *pDevice)
1191 unsigned int uCmdDequeueIdx = pDevice->uCmdDequeueIdx;
1192 unsigned int ii;
1194 if ((pDevice->cbFreeCmdQueue < CMD_Q_SIZE) && (uCmdDequeueIdx != pDevice->uCmdEnqueueIdx)) {
1195 for (ii = 0; ii < (CMD_Q_SIZE - pDevice->cbFreeCmdQueue); ii ++) {
1196 if (pDevice->eCmdQueue[uCmdDequeueIdx].eCmd == WLAN_CMD_BSSID_SCAN)
1197 pDevice->eCmdQueue[uCmdDequeueIdx].eCmd = WLAN_CMD_IDLE;
1198 ADD_ONE_WITH_WRAP_AROUND(uCmdDequeueIdx, CMD_Q_SIZE);
1199 if (uCmdDequeueIdx == pDevice->uCmdEnqueueIdx)
1200 break;
1203 return true;
1207 //mike add:reset command timer
1208 void vResetCommandTimer(struct vnt_private *pDevice)
1211 //delete timer
1212 del_timer(&pDevice->sTimerCommand);
1213 //init timer
1214 init_timer(&pDevice->sTimerCommand);
1215 pDevice->sTimerCommand.data = (unsigned long)pDevice;
1216 pDevice->sTimerCommand.function = (TimerFunction)vRunCommand;
1217 pDevice->sTimerCommand.expires = RUN_AT(HZ);
1218 pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
1219 pDevice->uCmdDequeueIdx = 0;
1220 pDevice->uCmdEnqueueIdx = 0;
1221 pDevice->eCommandState = WLAN_CMD_IDLE;
1222 pDevice->bCmdRunning = false;
1223 pDevice->bCmdClear = false;
1226 void BSSvSecondTxData(struct vnt_private *pDevice)
1228 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1230 pDevice->nTxDataTimeCout++;
1232 if (pDevice->nTxDataTimeCout < 4) { //don't tx data if timer less than 40s
1233 // printk("mike:%s-->no data Tx not exceed the desired Time as %d\n",__FUNCTION__,
1234 // (int)pDevice->nTxDataTimeCout);
1235 pDevice->sTimerTxData.expires = RUN_AT(10 * HZ); //10s callback
1236 add_timer(&pDevice->sTimerTxData);
1237 return;
1240 spin_lock_irq(&pDevice->lock);
1241 //is wap_supplicant running successful OR only open && sharekey mode!
1242 if (((pDevice->bLinkPass == true) &&
1243 (pMgmt->eAuthenMode < WMAC_AUTH_WPA)) || //open && sharekey linking
1244 (pDevice->fWPA_Authened == true)) { //wpa linking
1245 // printk("mike:%s-->InSleep Tx Data Procedure\n",__FUNCTION__);
1246 pDevice->fTxDataInSleep = true;
1247 PSbSendNullPacket(pDevice); //send null packet
1248 pDevice->fTxDataInSleep = false;
1250 spin_unlock_irq(&pDevice->lock);
1252 pDevice->sTimerTxData.expires = RUN_AT(10 * HZ); //10s callback
1253 add_timer(&pDevice->sTimerTxData);