staging: vt6655: Remove commented out printks
[linux-2.6/btrfs-unstable.git] / drivers / staging / vt6655 / wcmd.c
blob9001fceee10dd373c78633a849ea31396ca841a0
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 * 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 "rxtx.h"
53 #include "rf.h"
54 #include "iowpa.h"
55 #include "channel.h"
57 /*--------------------- Static Definitions -------------------------*/
62 /*--------------------- Static Classes ----------------------------*/
64 /*--------------------- Static Variables --------------------------*/
65 static int msglevel = MSG_LEVEL_INFO;
66 //static int msglevel =MSG_LEVEL_DEBUG;
67 /*--------------------- Static Functions --------------------------*/
69 static
70 void
71 s_vProbeChannel(
72 PSDevice pDevice
76 static
77 PSTxMgmtPacket
78 s_MgrMakeProbeRequest(
79 PSDevice pDevice,
80 PSMgmtObject pMgmt,
81 unsigned char *pScanBSSID,
82 PWLAN_IE_SSID pSSID,
83 PWLAN_IE_SUPP_RATES pCurrRates,
84 PWLAN_IE_SUPP_RATES pCurrExtSuppRates
88 static
89 bool
90 s_bCommandComplete(
91 PSDevice pDevice
94 /*--------------------- Export Variables --------------------------*/
97 /*--------------------- Export Functions --------------------------*/
102 * Description:
103 * Stop AdHoc beacon during scan process
105 * Parameters:
106 * In:
107 * pDevice - Pointer to the adapter
108 * Out:
109 * none
111 * Return Value: none
114 static
115 void
116 vAdHocBeaconStop(PSDevice pDevice)
119 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
120 bool bStop;
123 * temporarily stop Beacon packet for AdHoc Server
124 * if all of the following conditions are met:
125 * (1) STA is in AdHoc mode
126 * (2) VT3253 is programmed as automatic Beacon Transmitting
127 * (3) One of the following conditions is met
128 * (3.1) AdHoc channel is in B/G band and the
129 * current scan channel is in A band
130 * or
131 * (3.2) AdHoc channel is in A mode
133 bStop = false;
134 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) &&
135 (pMgmt->eCurrState >= WMAC_STATE_STARTED))
137 if ((pMgmt->uIBSSChannel <= CB_MAX_CHANNEL_24G) &&
138 (pMgmt->uScanChannel > CB_MAX_CHANNEL_24G))
140 bStop = true;
142 if (pMgmt->uIBSSChannel > CB_MAX_CHANNEL_24G)
144 bStop = true;
148 if (bStop)
150 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
153 } /* vAdHocBeaconStop */
157 * Description:
158 * Restart AdHoc beacon after scan process complete
160 * Parameters:
161 * In:
162 * pDevice - Pointer to the adapter
163 * Out:
164 * none
166 * Return Value: none
169 static
170 void
171 vAdHocBeaconRestart(PSDevice pDevice)
173 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
176 * Restart Beacon packet for AdHoc Server
177 * if all of the following coditions are met:
178 * (1) STA is in AdHoc mode
179 * (2) VT3253 is programmed as automatic Beacon Transmitting
181 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) &&
182 (pMgmt->eCurrState >= WMAC_STATE_STARTED))
184 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
196 * Routine Description:
197 * Prepare and send probe request management frames.
200 * Return Value:
201 * none.
205 static
206 void
207 s_vProbeChannel(
208 PSDevice pDevice
211 //1M, 2M, 5M, 11M, 18M, 24M, 36M, 54M
212 unsigned char abyCurrSuppRatesG[] = {WLAN_EID_SUPP_RATES, 8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C};
213 unsigned char abyCurrExtSuppRatesG[] = {WLAN_EID_EXTSUPP_RATES, 4, 0x0C, 0x12, 0x18, 0x60};
214 //6M, 9M, 12M, 48M
215 unsigned char abyCurrSuppRatesA[] = {WLAN_EID_SUPP_RATES, 8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
216 unsigned char abyCurrSuppRatesB[] = {WLAN_EID_SUPP_RATES, 4, 0x02, 0x04, 0x0B, 0x16};
217 unsigned char *pbyRate;
218 PSTxMgmtPacket pTxPacket;
219 PSMgmtObject pMgmt = pDevice->pMgmt;
220 unsigned int ii;
223 if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
224 pbyRate = &abyCurrSuppRatesA[0];
225 } else if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
226 pbyRate = &abyCurrSuppRatesB[0];
227 } else {
228 pbyRate = &abyCurrSuppRatesG[0];
230 // build an assocreq frame and send it
231 pTxPacket = s_MgrMakeProbeRequest
233 pDevice,
234 pMgmt,
235 pMgmt->abyScanBSSID,
236 (PWLAN_IE_SSID)pMgmt->abyScanSSID,
237 (PWLAN_IE_SUPP_RATES)pbyRate,
238 (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRatesG
241 if (pTxPacket != NULL) {
242 for (ii = 0; ii < 2; ii++) {
243 if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
244 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Probe request sending fail.. \n");
246 else {
247 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Probe request is sending.. \n");
259 * Routine Description:
260 * Constructs an probe request frame
263 * Return Value:
264 * A ptr to Tx frame or NULL on allocation failue
269 PSTxMgmtPacket
270 s_MgrMakeProbeRequest(
271 PSDevice pDevice,
272 PSMgmtObject pMgmt,
273 unsigned char *pScanBSSID,
274 PWLAN_IE_SSID pSSID,
275 PWLAN_IE_SUPP_RATES pCurrRates,
276 PWLAN_IE_SUPP_RATES pCurrExtSuppRates
280 PSTxMgmtPacket pTxPacket = NULL;
281 WLAN_FR_PROBEREQ sFrame;
284 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
285 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_PROBEREQ_FR_MAXLEN);
286 pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
287 sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
288 sFrame.len = WLAN_PROBEREQ_FR_MAXLEN;
289 vMgrEncodeProbeRequest(&sFrame);
290 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
292 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
293 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_PROBEREQ)
295 memcpy(sFrame.pHdr->sA3.abyAddr1, pScanBSSID, WLAN_ADDR_LEN);
296 memcpy(sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
297 memcpy(sFrame.pHdr->sA3.abyAddr3, pScanBSSID, WLAN_BSSID_LEN);
298 // Copy the SSID, pSSID->len=0 indicate broadcast SSID
299 sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
300 sFrame.len += pSSID->len + WLAN_IEHDR_LEN;
301 memcpy(sFrame.pSSID, pSSID, pSSID->len + WLAN_IEHDR_LEN);
302 sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
303 sFrame.len += pCurrRates->len + WLAN_IEHDR_LEN;
304 memcpy(sFrame.pSuppRates, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
305 // Copy the extension rate set
306 if (pDevice->eCurrentPHYType == PHY_TYPE_11G) {
307 sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
308 sFrame.len += pCurrExtSuppRates->len + WLAN_IEHDR_LEN;
309 memcpy(sFrame.pExtSuppRates, pCurrExtSuppRates, pCurrExtSuppRates->len + WLAN_IEHDR_LEN);
311 pTxPacket->cbMPDULen = sFrame.len;
312 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
314 return pTxPacket;
321 void
322 vCommandTimerWait(
323 void *hDeviceContext,
324 unsigned int MSecond
327 PSDevice pDevice = (PSDevice)hDeviceContext;
329 init_timer(&pDevice->sTimerCommand);
330 pDevice->sTimerCommand.data = (unsigned long) pDevice;
331 pDevice->sTimerCommand.function = (TimerFunction)vCommandTimer;
332 // RUN_AT :1 msec ~= (HZ/1024)
333 pDevice->sTimerCommand.expires = (unsigned int)RUN_AT((MSecond * HZ) >> 10);
334 add_timer(&pDevice->sTimerCommand);
335 return;
341 void
342 vCommandTimer(
343 void *hDeviceContext
346 PSDevice pDevice = (PSDevice)hDeviceContext;
347 PSMgmtObject pMgmt = pDevice->pMgmt;
348 PWLAN_IE_SSID pItemSSID;
349 PWLAN_IE_SSID pItemSSIDCurr;
350 CMD_STATUS Status;
351 unsigned int ii;
352 unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
353 struct sk_buff *skb;
356 if (pDevice->dwDiagRefCount != 0)
357 return;
358 if (pDevice->bCmdRunning != true)
359 return;
361 spin_lock_irq(&pDevice->lock);
363 switch (pDevice->eCommandState) {
365 case WLAN_CMD_SCAN_START:
367 pDevice->byReAssocCount = 0;
368 if (pDevice->bRadioOff == true) {
369 s_bCommandComplete(pDevice);
370 spin_unlock_irq(&pDevice->lock);
371 return;
374 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
375 s_bCommandComplete(pDevice);
376 CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, OP_MODE_AP);
377 spin_unlock_irq(&pDevice->lock);
378 return;
381 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "eCommandState= WLAN_CMD_SCAN_START\n");
382 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyScanSSID;
383 // wait all Data TD complete
384 if (pDevice->iTDUsed[TYPE_AC0DMA] != 0) {
385 spin_unlock_irq(&pDevice->lock);
386 vCommandTimerWait((void *)pDevice, 10);
387 return;
390 if (pMgmt->uScanChannel == 0) {
391 pMgmt->uScanChannel = pDevice->byMinChannel;
392 // Set Baseband to be more sensitive.
395 if (pMgmt->uScanChannel > pDevice->byMaxChannel) {
396 pMgmt->eScanState = WMAC_NO_SCANNING;
398 // Set Baseband's sensitivity back.
399 // Set channel back
400 set_channel(pMgmt->pAdapter, pMgmt->uCurrChannel);
401 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Scanning, set back to channel: [%d]\n", pMgmt->uCurrChannel);
402 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
403 CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, OP_MODE_ADHOC);
404 } else {
405 CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, OP_MODE_INFRASTRUCTURE);
407 vAdHocBeaconRestart(pDevice);
408 s_bCommandComplete(pDevice);
410 } else {
411 //2008-8-4 <add> by chester
412 if (!is_channel_valid(pMgmt->uScanChannel)) {
413 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Invalid channel pMgmt->uScanChannel = %d \n", pMgmt->uScanChannel);
414 s_bCommandComplete(pDevice);
415 spin_unlock_irq(&pDevice->lock);
416 return;
418 if (pMgmt->uScanChannel == pDevice->byMinChannel) {
419 //pMgmt->eScanType = WMAC_SCAN_ACTIVE;
420 pMgmt->abyScanBSSID[0] = 0xFF;
421 pMgmt->abyScanBSSID[1] = 0xFF;
422 pMgmt->abyScanBSSID[2] = 0xFF;
423 pMgmt->abyScanBSSID[3] = 0xFF;
424 pMgmt->abyScanBSSID[4] = 0xFF;
425 pMgmt->abyScanBSSID[5] = 0xFF;
426 pItemSSID->byElementID = WLAN_EID_SSID;
427 // clear bssid list
428 // BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass);
429 pMgmt->eScanState = WMAC_IS_SCANNING;
433 vAdHocBeaconStop(pDevice);
435 if (set_channel(pMgmt->pAdapter, pMgmt->uScanChannel) == true) {
436 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "SCAN Channel: %d\n", pMgmt->uScanChannel);
437 } else {
438 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "SET SCAN Channel Fail: %d\n", pMgmt->uScanChannel);
440 CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, OP_MODE_UNKNOWN);
441 pMgmt->uScanChannel++;
442 //2008-8-4 <modify> by chester
443 if (!is_channel_valid(pMgmt->uScanChannel) &&
444 pMgmt->uScanChannel <= pDevice->byMaxChannel) {
445 pMgmt->uScanChannel = pDevice->byMaxChannel + 1;
446 pMgmt->eCommandState = WLAN_CMD_SCAN_END;
451 if ((pMgmt->b11hEnable == false) ||
452 (pMgmt->uScanChannel < CB_MAX_CHANNEL_24G)) {
453 s_vProbeChannel(pDevice);
454 spin_unlock_irq(&pDevice->lock);
455 vCommandTimerWait((void *)pDevice, WCMD_ACTIVE_SCAN_TIME);
456 return;
457 } else {
458 spin_unlock_irq(&pDevice->lock);
459 vCommandTimerWait((void *)pDevice, WCMD_PASSIVE_SCAN_TIME);
460 return;
465 break;
467 case WLAN_CMD_SCAN_END:
469 // Set Baseband's sensitivity back.
470 // Set channel back
471 set_channel(pMgmt->pAdapter, pMgmt->uCurrChannel);
472 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Scanning, set back to channel: [%d]\n", pMgmt->uCurrChannel);
473 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
474 CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, OP_MODE_ADHOC);
475 } else {
476 CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, OP_MODE_INFRASTRUCTURE);
479 pMgmt->eScanState = WMAC_NO_SCANNING;
480 vAdHocBeaconRestart(pDevice);
481 //2008-0409-07, <Add> by Einsn Liu
482 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
483 if (pMgmt->eScanType == WMAC_SCAN_PASSIVE)
484 {//send scan event to wpa_Supplicant
485 union iwreq_data wrqu;
486 memset(&wrqu, 0, sizeof(wrqu));
487 wireless_send_event(pDevice->dev, SIOCGIWSCAN, &wrqu, NULL);
489 #endif
490 s_bCommandComplete(pDevice);
491 break;
493 case WLAN_CMD_DISASSOCIATE_START:
494 pDevice->byReAssocCount = 0;
495 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
496 (pMgmt->eCurrState != WMAC_STATE_ASSOC)) {
497 s_bCommandComplete(pDevice);
498 spin_unlock_irq(&pDevice->lock);
499 return;
500 } else {
501 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send Disassociation Packet..\n");
502 // reason = 8 : disassoc because sta has left
503 vMgrDisassocBeginSta((void *)pDevice, pMgmt, pMgmt->abyCurrBSSID, (8), &Status);
504 pDevice->bLinkPass = false;
505 // unlock command busy
506 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
507 pItemSSID->len = 0;
508 memset(pItemSSID->abySSID, 0, WLAN_SSID_MAXLEN);
509 pMgmt->eCurrState = WMAC_STATE_IDLE;
510 pMgmt->sNodeDBTable[0].bActive = false;
511 // pDevice->bBeaconBufReady = false;
513 netif_stop_queue(pDevice->dev);
514 pDevice->eCommandState = WLAN_DISASSOCIATE_WAIT;
515 // wait all Control TD complete
516 if (pDevice->iTDUsed[TYPE_TXDMA0] != 0) {
517 vCommandTimerWait((void *)pDevice, 10);
518 spin_unlock_irq(&pDevice->lock);
519 return;
521 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " CARDbRadioPowerOff\n");
522 //2008-09-02 <mark> by chester
523 // CARDbRadioPowerOff(pDevice);
524 s_bCommandComplete(pDevice);
525 break;
527 case WLAN_DISASSOCIATE_WAIT:
528 // wait all Control TD complete
529 if (pDevice->iTDUsed[TYPE_TXDMA0] != 0) {
530 vCommandTimerWait((void *)pDevice, 10);
531 spin_unlock_irq(&pDevice->lock);
532 return;
534 //2008-09-02 <mark> by chester
535 // CARDbRadioPowerOff(pDevice);
536 s_bCommandComplete(pDevice);
537 break;
539 case WLAN_CMD_SSID_START:
540 pDevice->byReAssocCount = 0;
541 if (pDevice->bRadioOff == true) {
542 s_bCommandComplete(pDevice);
543 spin_unlock_irq(&pDevice->lock);
544 return;
546 printk("chester-abyDesireSSID=%s\n", ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->abySSID);
547 //memcpy(pMgmt->abyAdHocSSID,pMgmt->abyDesireSSID,
548 //((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->len + WLAN_IEHDR_LEN);
549 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
550 pItemSSIDCurr = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
551 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " cmd: desire ssid = %s\n", pItemSSID->abySSID);
552 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " cmd: curr ssid = %s\n", pItemSSIDCurr->abySSID);
554 if (pMgmt->eCurrState == WMAC_STATE_ASSOC) {
555 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Cmd pMgmt->eCurrState == WMAC_STATE_ASSOC\n");
556 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " pItemSSID->len =%d\n", pItemSSID->len);
557 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " pItemSSIDCurr->len = %d\n", pItemSSIDCurr->len);
558 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " desire ssid = %s\n", pItemSSID->abySSID);
559 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " curr ssid = %s\n", pItemSSIDCurr->abySSID);
562 if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) ||
563 ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED))) {
565 if (pItemSSID->len == pItemSSIDCurr->len) {
566 if (memcmp(pItemSSID->abySSID, pItemSSIDCurr->abySSID, pItemSSID->len) == 0) {
567 s_bCommandComplete(pDevice);
568 spin_unlock_irq(&pDevice->lock);
569 return;
573 netif_stop_queue(pDevice->dev);
574 pDevice->bLinkPass = false;
576 // set initial state
577 pMgmt->eCurrState = WMAC_STATE_IDLE;
578 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
579 PSvDisablePowerSaving((void *)pDevice);
580 BSSvClearNodeDBTable(pDevice, 0);
582 vMgrJoinBSSBegin((void *)pDevice, &Status);
583 // if Infra mode
584 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED)) {
586 // Call mgr to begin the deauthentication
587 // reason = (3) because sta has left ESS
588 if (pMgmt->eCurrState >= WMAC_STATE_AUTH) {
589 vMgrDeAuthenBeginSta((void *)pDevice, pMgmt, pMgmt->abyCurrBSSID, (3), &Status);
591 // Call mgr to begin the authentication
592 vMgrAuthenBeginSta((void *)pDevice, pMgmt, &Status);
593 if (Status == CMD_STATUS_SUCCESS) {
594 pDevice->byLinkWaitCount = 0;
595 pDevice->eCommandState = WLAN_AUTHENTICATE_WAIT;
596 vCommandTimerWait((void *)pDevice, AUTHENTICATE_TIMEOUT);
597 spin_unlock_irq(&pDevice->lock);
598 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Set eCommandState = WLAN_AUTHENTICATE_WAIT\n");
599 return;
602 // if Adhoc mode
603 else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
604 if (pMgmt->eCurrState == WMAC_STATE_JOINTED) {
605 if (netif_queue_stopped(pDevice->dev)) {
606 netif_wake_queue(pDevice->dev);
608 pDevice->bLinkPass = true;
610 pMgmt->sNodeDBTable[0].bActive = true;
611 pMgmt->sNodeDBTable[0].uInActiveCount = 0;
612 bClearBSSID_SCAN(pDevice);
614 else {
615 // start own IBSS
616 vMgrCreateOwnIBSS((void *)pDevice, &Status);
617 if (Status != CMD_STATUS_SUCCESS) {
618 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " WLAN_CMD_IBSS_CREATE fail ! \n");
620 BSSvAddMulticastNode(pDevice);
623 // if SSID not found
624 else if (pMgmt->eCurrMode == WMAC_MODE_STANDBY) {
625 if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA ||
626 pMgmt->eConfigMode == WMAC_CONFIG_AUTO) {
627 // start own IBSS
628 vMgrCreateOwnIBSS((void *)pDevice, &Status);
629 if (Status != CMD_STATUS_SUCCESS) {
630 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " WLAN_CMD_IBSS_CREATE fail ! \n");
632 BSSvAddMulticastNode(pDevice);
633 if (netif_queue_stopped(pDevice->dev)) {
634 netif_wake_queue(pDevice->dev);
636 pDevice->bLinkPass = true;
638 else {
639 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disconnect SSID none\n");
640 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
641 // if (pDevice->bWPASuppWextEnabled == true)
643 union iwreq_data wrqu;
644 memset(&wrqu, 0, sizeof(wrqu));
645 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
646 printk("wireless_send_event--->SIOCGIWAP(disassociated:vMgrJoinBSSBegin Fail !!)\n");
647 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
649 #endif
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 // Call mgr to begin the association
660 pDevice->byLinkWaitCount = 0;
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 pDevice->byLinkWaitCount = 0;
665 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "eCommandState = WLAN_ASSOCIATE_WAIT\n");
666 pDevice->eCommandState = WLAN_ASSOCIATE_WAIT;
667 vCommandTimerWait((void *)pDevice, ASSOCIATE_TIMEOUT);
668 spin_unlock_irq(&pDevice->lock);
669 return;
673 else if (pMgmt->eCurrState < WMAC_STATE_AUTHPENDING) {
674 printk("WLAN_AUTHENTICATE_WAIT:Authen Fail???\n");
676 else if (pDevice->byLinkWaitCount <= 4) { //mike add:wait another 2 sec if authenticated_frame delay!
677 pDevice->byLinkWaitCount++;
678 printk("WLAN_AUTHENTICATE_WAIT:wait %d times!!\n", pDevice->byLinkWaitCount);
679 spin_unlock_irq(&pDevice->lock);
680 vCommandTimerWait((void *)pDevice, AUTHENTICATE_TIMEOUT/2);
681 return;
683 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, pMgmt->wListenInterval);
693 if (pMgmt->eAuthenMode >= WMAC_AUTH_WPA) {
694 KeybRemoveAllKey(&(pDevice->sKey), pDevice->abyBSSID, pDevice->PortOffset);
696 pDevice->bLinkPass = true;
697 pDevice->byLinkWaitCount = 0;
698 pDevice->byReAssocCount = 0;
699 bClearBSSID_SCAN(pDevice);
700 if (pDevice->byFOETuning) {
701 BBvSetFOE(pDevice->PortOffset);
702 PSbSendNullPacket(pDevice);
704 if (netif_queue_stopped(pDevice->dev)) {
705 netif_wake_queue(pDevice->dev);
707 #ifdef TxInSleep
708 if (pDevice->IsTxDataTrigger != false) { //TxDataTimer is not triggered at the first time
709 del_timer(&pDevice->sTimerTxData);
710 init_timer(&pDevice->sTimerTxData);
711 pDevice->sTimerTxData.data = (unsigned long) pDevice;
712 pDevice->sTimerTxData.function = (TimerFunction)BSSvSecondTxData;
713 pDevice->sTimerTxData.expires = RUN_AT(10*HZ); //10s callback
714 pDevice->fTxDataInSleep = false;
715 pDevice->nTxDataTimeCout = 0;
717 else {
719 pDevice->IsTxDataTrigger = true;
720 add_timer(&pDevice->sTimerTxData);
721 #endif
723 else if (pMgmt->eCurrState < WMAC_STATE_ASSOCPENDING) {
724 printk("WLAN_ASSOCIATE_WAIT:Association Fail???\n");
726 else if (pDevice->byLinkWaitCount <= 4) { //mike add:wait another 2 sec if associated_frame delay!
727 pDevice->byLinkWaitCount++;
728 printk("WLAN_ASSOCIATE_WAIT:wait %d times!!\n", pDevice->byLinkWaitCount);
729 spin_unlock_irq(&pDevice->lock);
730 vCommandTimerWait((void *)pDevice, ASSOCIATE_TIMEOUT/2);
731 return;
733 pDevice->byLinkWaitCount = 0;
735 s_bCommandComplete(pDevice);
736 break;
738 case WLAN_CMD_AP_MODE_START:
739 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "eCommandState == WLAN_CMD_AP_MODE_START\n");
741 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
742 del_timer(&pMgmt->sTimerSecondCallback);
743 pMgmt->eCurrState = WMAC_STATE_IDLE;
744 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
745 pDevice->bLinkPass = false;
746 if (pDevice->bEnableHostWEP == true)
747 BSSvClearNodeDBTable(pDevice, 1);
748 else
749 BSSvClearNodeDBTable(pDevice, 0);
750 pDevice->uAssocCount = 0;
751 pMgmt->eCurrState = WMAC_STATE_IDLE;
752 pDevice->bFixRate = false;
754 vMgrCreateOwnIBSS((void *)pDevice, &Status);
755 if (Status != CMD_STATUS_SUCCESS) {
756 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " vMgrCreateOwnIBSS fail ! \n");
758 // alway turn off unicast bit
759 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_RCR, RCR_UNICAST);
760 pDevice->byRxMode &= ~RCR_UNICAST;
761 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wcmd: rx_mode = %x\n", pDevice->byRxMode);
762 BSSvAddMulticastNode(pDevice);
763 if (netif_queue_stopped(pDevice->dev)) {
764 netif_wake_queue(pDevice->dev);
766 pDevice->bLinkPass = true;
767 add_timer(&pMgmt->sTimerSecondCallback);
769 s_bCommandComplete(pDevice);
770 break;
772 case WLAN_CMD_TX_PSPACKET_START:
773 // DTIM Multicast tx
774 if (pMgmt->sNodeDBTable[0].bRxPSPoll) {
775 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[0].sTxPSQueue)) != NULL) {
776 if (skb_queue_empty(&pMgmt->sNodeDBTable[0].sTxPSQueue)) {
777 pMgmt->abyPSTxMap[0] &= ~byMask[0];
778 pDevice->bMoreData = false;
780 else {
781 pDevice->bMoreData = true;
783 if (!device_dma0_xmit(pDevice, skb, 0)) {
784 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Multicast ps tx fail \n");
786 pMgmt->sNodeDBTable[0].wEnQueueCnt--;
790 // PS nodes tx
791 for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) {
792 if (pMgmt->sNodeDBTable[ii].bActive &&
793 pMgmt->sNodeDBTable[ii].bRxPSPoll) {
794 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Index=%d Enqueu Cnt= %d\n",
795 ii, pMgmt->sNodeDBTable[ii].wEnQueueCnt);
796 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) != NULL) {
797 if (skb_queue_empty(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) {
798 // clear tx map
799 pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[ii].wAID >> 3] &=
800 ~byMask[pMgmt->sNodeDBTable[ii].wAID & 7];
801 pDevice->bMoreData = false;
803 else {
804 pDevice->bMoreData = true;
806 if (!device_dma0_xmit(pDevice, skb, ii)) {
807 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "sta ps tx fail \n");
809 pMgmt->sNodeDBTable[ii].wEnQueueCnt--;
810 // check if sta ps enabled, and wait next pspoll.
811 // if sta ps disable, then send all pending buffers.
812 if (pMgmt->sNodeDBTable[ii].bPSEnable)
813 break;
815 if (skb_queue_empty(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) {
816 // clear tx map
817 pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[ii].wAID >> 3] &=
818 ~byMask[pMgmt->sNodeDBTable[ii].wAID & 7];
819 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Index=%d PS queue clear \n", ii);
821 pMgmt->sNodeDBTable[ii].bRxPSPoll = false;
825 s_bCommandComplete(pDevice);
826 break;
829 case WLAN_CMD_RADIO_START:
830 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "eCommandState == WLAN_CMD_RADIO_START\n");
831 if (pDevice->bRadioCmd == true)
832 CARDbRadioPowerOn(pDevice);
833 else
834 CARDbRadioPowerOff(pDevice);
836 s_bCommandComplete(pDevice);
837 break;
840 case WLAN_CMD_CHECK_BBSENSITIVITY_CHANGE:
841 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "eCommandState == WLAN_CMD_CHECK_BBSENSITIVITY_START\n");
842 // wait all TD complete
843 if (pDevice->iTDUsed[TYPE_AC0DMA] != 0) {
844 vCommandTimerWait((void *)pDevice, 10);
845 spin_unlock_irq(&pDevice->lock);
846 return;
848 if (pDevice->iTDUsed[TYPE_TXDMA0] != 0) {
849 vCommandTimerWait((void *)pDevice, 10);
850 spin_unlock_irq(&pDevice->lock);
851 return;
853 pDevice->byBBVGACurrent = pDevice->byBBVGANew;
854 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGACurrent);
855 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "SetVGAGainOffset %02X\n", pDevice->byBBVGACurrent);
856 s_bCommandComplete(pDevice);
857 break;
859 default:
860 s_bCommandComplete(pDevice);
861 break;
863 } //switch
864 spin_unlock_irq(&pDevice->lock);
865 return;
870 static
871 bool
872 s_bCommandComplete(
873 PSDevice pDevice
876 PWLAN_IE_SSID pSSID;
877 bool bRadioCmd = false;
878 //unsigned short wDeAuthenReason = 0;
879 bool bForceSCAN = true;
880 PSMgmtObject pMgmt = pDevice->pMgmt;
883 pDevice->eCommandState = WLAN_CMD_IDLE;
884 if (pDevice->cbFreeCmdQueue == CMD_Q_SIZE) {
885 //Command Queue Empty
886 pDevice->bCmdRunning = false;
887 return true;
889 else {
890 pDevice->eCommand = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].eCmd;
891 pSSID = (PWLAN_IE_SSID)pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].abyCmdDesireSSID;
892 bRadioCmd = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].bRadioCmd;
893 bForceSCAN = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].bForceSCAN;
894 ADD_ONE_WITH_WRAP_AROUND(pDevice->uCmdDequeueIdx, CMD_Q_SIZE);
895 pDevice->cbFreeCmdQueue++;
896 pDevice->bCmdRunning = true;
897 switch (pDevice->eCommand) {
898 case WLAN_CMD_BSSID_SCAN:
899 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "eCommandState= WLAN_CMD_BSSID_SCAN\n");
900 pDevice->eCommandState = WLAN_CMD_SCAN_START;
901 pMgmt->uScanChannel = 0;
902 if (pSSID->len != 0) {
903 memcpy(pMgmt->abyScanSSID, pSSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
904 } else {
905 memset(pMgmt->abyScanSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
908 if ((bForceSCAN == false) && (pDevice->bLinkPass == true)) {
909 if ((pSSID->len == ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len) &&
910 (!memcmp(pSSID->abySSID, ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID, pSSID->len))) {
911 pDevice->eCommandState = WLAN_CMD_IDLE;
915 break;
916 case WLAN_CMD_SSID:
917 pDevice->eCommandState = WLAN_CMD_SSID_START;
918 if (pSSID->len > WLAN_SSID_MAXLEN)
919 pSSID->len = WLAN_SSID_MAXLEN;
920 if (pSSID->len != 0)
921 memcpy(pDevice->pMgmt->abyDesireSSID, pSSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
922 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "eCommandState= WLAN_CMD_SSID_START\n");
923 break;
924 case WLAN_CMD_DISASSOCIATE:
925 pDevice->eCommandState = WLAN_CMD_DISASSOCIATE_START;
926 break;
927 case WLAN_CMD_RX_PSPOLL:
928 pDevice->eCommandState = WLAN_CMD_TX_PSPACKET_START;
929 break;
930 case WLAN_CMD_RUN_AP:
931 pDevice->eCommandState = WLAN_CMD_AP_MODE_START;
932 break;
933 case WLAN_CMD_RADIO:
934 pDevice->eCommandState = WLAN_CMD_RADIO_START;
935 pDevice->bRadioCmd = bRadioCmd;
936 break;
937 case WLAN_CMD_CHANGE_BBSENSITIVITY:
938 pDevice->eCommandState = WLAN_CMD_CHECK_BBSENSITIVITY_CHANGE;
939 break;
941 default:
942 break;
946 vCommandTimerWait((void *)pDevice, 0);
949 return true;
954 bool bScheduleCommand(
955 void *hDeviceContext,
956 CMD_CODE eCommand,
957 unsigned char *pbyItem0
960 PSDevice pDevice = (PSDevice)hDeviceContext;
963 if (pDevice->cbFreeCmdQueue == 0) {
964 return (false);
966 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].eCmd = eCommand;
967 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bForceSCAN = true;
968 memset(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID, 0 , WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
970 if (pbyItem0 != NULL) {
971 switch (eCommand) {
973 case WLAN_CMD_BSSID_SCAN:
974 memcpy(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID,
975 pbyItem0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
976 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bForceSCAN = false;
977 break;
979 case WLAN_CMD_SSID:
980 memcpy(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID,
981 pbyItem0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
982 break;
984 case WLAN_CMD_DISASSOCIATE:
985 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bNeedRadioOFF = *((int *)pbyItem0);
986 break;
988 case WLAN_CMD_DEAUTH:
989 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].wDeAuthenReason = *((unsigned short *)pbyItem0);
990 break;
993 case WLAN_CMD_RX_PSPOLL:
994 break;
996 case WLAN_CMD_RADIO:
997 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bRadioCmd = *((int *)pbyItem0);
998 break;
1000 case WLAN_CMD_CHANGE_BBSENSITIVITY:
1001 pDevice->eCommandState = WLAN_CMD_CHECK_BBSENSITIVITY_CHANGE;
1002 break;
1004 default:
1005 break;
1009 ADD_ONE_WITH_WRAP_AROUND(pDevice->uCmdEnqueueIdx, CMD_Q_SIZE);
1010 pDevice->cbFreeCmdQueue--;
1012 if (pDevice->bCmdRunning == false) {
1013 s_bCommandComplete(pDevice);
1015 else {
1017 return (true);
1022 * Description:
1023 * Clear BSSID_SCAN cmd in CMD Queue
1025 * Parameters:
1026 * In:
1027 * hDeviceContext - Pointer to the adapter
1028 * eCommand - Command
1029 * Out:
1030 * none
1032 * Return Value: true if success; otherwise false
1035 bool bClearBSSID_SCAN(
1036 void *hDeviceContext
1039 PSDevice pDevice = (PSDevice)hDeviceContext;
1040 unsigned int uCmdDequeueIdx = pDevice->uCmdDequeueIdx;
1041 unsigned int ii;
1043 if ((pDevice->cbFreeCmdQueue < CMD_Q_SIZE) && (uCmdDequeueIdx != pDevice->uCmdEnqueueIdx)) {
1044 for (ii = 0; ii < (CMD_Q_SIZE - pDevice->cbFreeCmdQueue); ii++) {
1045 if (pDevice->eCmdQueue[uCmdDequeueIdx].eCmd == WLAN_CMD_BSSID_SCAN)
1046 pDevice->eCmdQueue[uCmdDequeueIdx].eCmd = WLAN_CMD_IDLE;
1047 ADD_ONE_WITH_WRAP_AROUND(uCmdDequeueIdx, CMD_Q_SIZE);
1048 if (uCmdDequeueIdx == pDevice->uCmdEnqueueIdx)
1049 break;
1052 return true;
1055 //mike add:reset command timer
1056 void
1057 vResetCommandTimer(
1058 void *hDeviceContext
1061 PSDevice pDevice = (PSDevice)hDeviceContext;
1063 //delete timer
1064 del_timer(&pDevice->sTimerCommand);
1065 //init timer
1066 init_timer(&pDevice->sTimerCommand);
1067 pDevice->sTimerCommand.data = (unsigned long) pDevice;
1068 pDevice->sTimerCommand.function = (TimerFunction)vCommandTimer;
1069 pDevice->sTimerCommand.expires = RUN_AT(HZ);
1070 pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
1071 pDevice->uCmdDequeueIdx = 0;
1072 pDevice->uCmdEnqueueIdx = 0;
1073 pDevice->eCommandState = WLAN_CMD_IDLE;
1074 pDevice->bCmdRunning = false;
1075 pDevice->bCmdClear = false;
1079 #ifdef TxInSleep
1080 void
1081 BSSvSecondTxData(
1082 void *hDeviceContext
1085 PSDevice pDevice = (PSDevice)hDeviceContext;
1086 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1087 pDevice->nTxDataTimeCout++;
1089 if (pDevice->nTxDataTimeCout < 4) //don't tx data if timer less than 40s
1091 pDevice->sTimerTxData.expires = RUN_AT(10*HZ); //10s callback
1092 add_timer(&pDevice->sTimerTxData);
1093 return;
1096 spin_lock_irq(&pDevice->lock);
1097 #if 1
1098 if (((pDevice->bLinkPass == true) && (pMgmt->eAuthenMode < WMAC_AUTH_WPA)) || //open && sharekey linking
1099 (pDevice->fWPA_Authened == true)) { //wpa linking
1100 #else
1101 if (pDevice->bLinkPass == true) {
1102 #endif
1103 pDevice->fTxDataInSleep = true;
1104 PSbSendNullPacket(pDevice); //send null packet
1105 pDevice->fTxDataInSleep = false;
1107 spin_unlock_irq(&pDevice->lock);
1109 pDevice->sTimerTxData.expires = RUN_AT(10*HZ); //10s callback
1110 add_timer(&pDevice->sTimerTxData);
1111 return;
1113 #endif