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 * s_bClearBSSID_SCAN- Clear BSSID_SCAN cmd in CMD Queue
58 static int msglevel =MSG_LEVEL_INFO;
59 //static int msglevel =MSG_LEVEL_DEBUG;
61 static void s_vProbeChannel(struct vnt_private *);
63 static struct vnt_tx_mgmt *s_MgrMakeProbeRequest(struct vnt_private *,
64 struct vnt_manager *pMgmt, u8 *pScanBSSID, PWLAN_IE_SSID pSSID,
65 PWLAN_IE_SUPP_RATES pCurrRates, PWLAN_IE_SUPP_RATES pCurrExtSuppRates);
67 static int s_bCommandComplete(struct vnt_private *);
69 static int s_bClearBSSID_SCAN(struct vnt_private *);
73 * Stop AdHoc beacon during scan process
77 * pDevice - Pointer to the adapter
85 static void vAdHocBeaconStop(struct vnt_private *pDevice)
87 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
91 * temporarily stop Beacon packet for AdHoc Server
92 * if all of the following coditions are met:
93 * (1) STA is in AdHoc mode
94 * (2) VT3253 is programmed as automatic Beacon Transmitting
95 * (3) One of the following conditions is met
96 * (3.1) AdHoc channel is in B/G band and the
97 * current scan channel is in A band
99 * (3.2) AdHoc channel is in A mode
102 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) &&
103 (pMgmt->eCurrState >= WMAC_STATE_STARTED))
105 if ((pMgmt->uIBSSChannel <= CB_MAX_CHANNEL_24G) &&
106 (pMgmt->uScanChannel > CB_MAX_CHANNEL_24G))
110 if (pMgmt->uIBSSChannel > CB_MAX_CHANNEL_24G)
118 //PMESG(("STOP_BEACON: IBSSChannel = %u, ScanChannel = %u\n",
119 // pMgmt->uIBSSChannel, pMgmt->uScanChannel));
120 MACvRegBitsOff(pDevice, MAC_REG_TCR, TCR_AUTOBCNTX);
123 } /* vAdHocBeaconStop */
127 * Restart AdHoc beacon after scan process complete
131 * pDevice - Pointer to the adapter
138 static void vAdHocBeaconRestart(struct vnt_private *pDevice)
140 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
143 * Restart Beacon packet for AdHoc Server
144 * if all of the following coditions are met:
145 * (1) STA is in AdHoc mode
146 * (2) VT3253 is programmed as automatic Beacon Transmitting
148 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) &&
149 (pMgmt->eCurrState >= WMAC_STATE_STARTED))
151 //PMESG(("RESTART_BEACON\n"));
152 MACvRegBitsOn(pDevice, MAC_REG_TCR, TCR_AUTOBCNTX);
159 * Routine Description:
160 * Prepare and send probe request management frames.
168 static void s_vProbeChannel(struct vnt_private *pDevice)
170 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
171 struct vnt_tx_mgmt *pTxPacket;
172 u8 abyCurrSuppRatesG[] = {WLAN_EID_SUPP_RATES,
173 8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C};
174 /* 1M, 2M, 5M, 11M, 18M, 24M, 36M, 54M*/
175 u8 abyCurrExtSuppRatesG[] = {WLAN_EID_EXTSUPP_RATES,
176 4, 0x0C, 0x12, 0x18, 0x60};
177 /* 6M, 9M, 12M, 48M*/
178 u8 abyCurrSuppRatesA[] = {WLAN_EID_SUPP_RATES,
179 8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
180 u8 abyCurrSuppRatesB[] = {WLAN_EID_SUPP_RATES,
181 4, 0x02, 0x04, 0x0B, 0x16};
185 if (pDevice->byBBType == BB_TYPE_11A) {
186 pbyRate = &abyCurrSuppRatesA[0];
187 } else if (pDevice->byBBType == BB_TYPE_11B) {
188 pbyRate = &abyCurrSuppRatesB[0];
190 pbyRate = &abyCurrSuppRatesG[0];
192 // build an assocreq frame and send it
193 pTxPacket = s_MgrMakeProbeRequest
198 (PWLAN_IE_SSID)pMgmt->abyScanSSID,
199 (PWLAN_IE_SUPP_RATES)pbyRate,
200 (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRatesG
203 if (pTxPacket != NULL ){
204 for (ii = 0; ii < 1 ; ii++) {
205 if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
206 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Probe request sending fail.. \n");
209 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Probe request is sending.. \n");
218 * Routine Description:
219 * Constructs an probe request frame
223 * A ptr to Tx frame or NULL on allocation failure
227 struct vnt_tx_mgmt *s_MgrMakeProbeRequest(struct vnt_private *pDevice,
228 struct vnt_manager *pMgmt, u8 *pScanBSSID, PWLAN_IE_SSID pSSID,
229 PWLAN_IE_SUPP_RATES pCurrRates, PWLAN_IE_SUPP_RATES pCurrExtSuppRates)
231 struct vnt_tx_mgmt *pTxPacket = NULL;
232 WLAN_FR_PROBEREQ sFrame;
234 pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
235 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
236 + WLAN_PROBEREQ_FR_MAXLEN);
237 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
238 + sizeof(struct vnt_tx_mgmt));
239 sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
240 sFrame.len = WLAN_PROBEREQ_FR_MAXLEN;
241 vMgrEncodeProbeRequest(&sFrame);
242 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
244 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
245 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_PROBEREQ)
247 memcpy( sFrame.pHdr->sA3.abyAddr1, pScanBSSID, WLAN_ADDR_LEN);
248 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
249 memcpy( sFrame.pHdr->sA3.abyAddr3, pScanBSSID, WLAN_BSSID_LEN);
250 // Copy the SSID, pSSID->len=0 indicate broadcast SSID
251 sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
252 sFrame.len += pSSID->len + WLAN_IEHDR_LEN;
253 memcpy(sFrame.pSSID, pSSID, pSSID->len + WLAN_IEHDR_LEN);
254 sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
255 sFrame.len += pCurrRates->len + WLAN_IEHDR_LEN;
256 memcpy(sFrame.pSuppRates, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
257 // Copy the extension rate set
258 if (pDevice->byBBType == BB_TYPE_11G) {
259 sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
260 sFrame.len += pCurrExtSuppRates->len + WLAN_IEHDR_LEN;
261 memcpy(sFrame.pExtSuppRates, pCurrExtSuppRates, pCurrExtSuppRates->len + WLAN_IEHDR_LEN);
263 pTxPacket->cbMPDULen = sFrame.len;
264 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
269 void vCommandTimerWait(struct vnt_private *pDevice, unsigned long MSecond)
271 schedule_delayed_work(&pDevice->run_command_work,
272 msecs_to_jiffies(MSecond));
275 void vRunCommand(struct work_struct *work)
277 struct vnt_private *pDevice =
278 container_of(work, struct vnt_private, run_command_work.work);
279 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
280 PWLAN_IE_SSID pItemSSID;
281 PWLAN_IE_SSID pItemSSIDCurr;
284 union iwreq_data wrqu;
286 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
289 if (pDevice->Flags & fMP_DISCONNECTED)
292 if (pDevice->dwDiagRefCount != 0)
294 if (pDevice->bCmdRunning != true)
297 spin_lock_irq(&pDevice->lock);
299 switch ( pDevice->eCommandState ) {
301 case WLAN_CMD_SCAN_START:
303 pDevice->byReAssocCount = 0;
304 if (pDevice->bRadioOff == true) {
305 s_bCommandComplete(pDevice);
306 spin_unlock_irq(&pDevice->lock);
310 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
311 s_bCommandComplete(pDevice);
312 spin_unlock_irq(&pDevice->lock);
316 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyScanSSID;
318 if (pMgmt->uScanChannel == 0 ) {
319 pMgmt->uScanChannel = pDevice->byMinChannel;
321 if (pMgmt->uScanChannel > pDevice->byMaxChannel) {
322 pDevice->eCommandState = WLAN_CMD_SCAN_END;
323 s_bCommandComplete(pDevice);
324 spin_unlock_irq(&pDevice->lock);
328 if (!ChannelValid(pDevice->byZoneType, pMgmt->uScanChannel)) {
329 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Invalid channel pMgmt->uScanChannel = %d \n",pMgmt->uScanChannel);
330 pMgmt->uScanChannel++;
331 s_bCommandComplete(pDevice);
332 spin_unlock_irq(&pDevice->lock);
335 if (pMgmt->uScanChannel == pDevice->byMinChannel) {
336 // pMgmt->eScanType = WMAC_SCAN_ACTIVE; //mike mark
337 pMgmt->abyScanBSSID[0] = 0xFF;
338 pMgmt->abyScanBSSID[1] = 0xFF;
339 pMgmt->abyScanBSSID[2] = 0xFF;
340 pMgmt->abyScanBSSID[3] = 0xFF;
341 pMgmt->abyScanBSSID[4] = 0xFF;
342 pMgmt->abyScanBSSID[5] = 0xFF;
343 pItemSSID->byElementID = WLAN_EID_SSID;
345 /* BSSvClearBSSList((void *) pDevice,
346 pDevice->bLinkPass); */
347 pMgmt->eScanState = WMAC_IS_SCANNING;
348 pDevice->byScanBBType = pDevice->byBBType; //lucas
349 pDevice->bStopDataPkt = true;
350 // Turn off RCR_BSSID filter every time
351 MACvRegBitsOff(pDevice, MAC_REG_RCR, RCR_BSSID);
352 pDevice->byRxMode &= ~RCR_BSSID;
356 vAdHocBeaconStop(pDevice);
357 if ((pDevice->byBBType != BB_TYPE_11A) && (pMgmt->uScanChannel > CB_MAX_CHANNEL_24G)) {
358 pDevice->byBBType = BB_TYPE_11A;
359 CARDvSetBSSMode(pDevice);
361 else if ((pDevice->byBBType == BB_TYPE_11A) && (pMgmt->uScanChannel <= CB_MAX_CHANNEL_24G)) {
362 pDevice->byBBType = BB_TYPE_11G;
363 CARDvSetBSSMode(pDevice);
365 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Scanning.... channel: [%d]\n", pMgmt->uScanChannel);
367 CARDbSetMediaChannel(pDevice, pMgmt->uScanChannel);
368 // Set Baseband to be more sensitive.
370 if (pDevice->bUpdateBBVGA) {
371 BBvSetShortSlotTime(pDevice);
372 BBvSetVGAGainOffset(pDevice, pDevice->abyBBVGA[0]);
373 BBvUpdatePreEDThreshold(pDevice, true);
375 pMgmt->uScanChannel++;
377 while (!ChannelValid(pDevice->byZoneType, pMgmt->uScanChannel) &&
378 pMgmt->uScanChannel <= pDevice->byMaxChannel ){
379 pMgmt->uScanChannel++;
382 if (pMgmt->uScanChannel > pDevice->byMaxChannel) {
383 // Set Baseband to be not sensitive and rescan
384 pDevice->eCommandState = WLAN_CMD_SCAN_END;
387 if ((pMgmt->b11hEnable == false) ||
388 (pMgmt->uScanChannel < CB_MAX_CHANNEL_24G)) {
389 s_vProbeChannel(pDevice);
390 spin_unlock_irq(&pDevice->lock);
391 vCommandTimerWait((void *) pDevice, 100);
394 spin_unlock_irq(&pDevice->lock);
395 vCommandTimerWait((void *) pDevice, WCMD_PASSIVE_SCAN_TIME);
403 case WLAN_CMD_SCAN_END:
405 // Set Baseband's sensitivity back.
406 if (pDevice->byBBType != pDevice->byScanBBType) {
407 pDevice->byBBType = pDevice->byScanBBType;
408 CARDvSetBSSMode(pDevice);
411 if (pDevice->bUpdateBBVGA) {
412 BBvSetShortSlotTime(pDevice);
413 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGACurrent);
414 BBvUpdatePreEDThreshold(pDevice, false);
418 vAdHocBeaconRestart(pDevice);
420 CARDbSetMediaChannel(pDevice, pMgmt->uCurrChannel);
422 if (pMgmt->bCurrBSSIDFilterOn) {
423 MACvRegBitsOn(pDevice, MAC_REG_RCR, RCR_BSSID);
424 pDevice->byRxMode |= RCR_BSSID;
426 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Scanning, set back to channel: [%d]\n", pMgmt->uCurrChannel);
427 pMgmt->uScanChannel = 0;
428 pMgmt->eScanState = WMAC_NO_SCANNING;
429 pDevice->bStopDataPkt = false;
431 /*send scan event to wpa_Supplicant*/
432 PRINT_K("wireless_send_event--->SIOCGIWSCAN(scan done)\n");
433 memset(&wrqu, 0, sizeof(wrqu));
434 wireless_send_event(pDevice->dev, SIOCGIWSCAN, &wrqu, NULL);
436 s_bCommandComplete(pDevice);
439 case WLAN_CMD_DISASSOCIATE_START :
440 pDevice->byReAssocCount = 0;
441 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
442 (pMgmt->eCurrState != WMAC_STATE_ASSOC)) {
443 s_bCommandComplete(pDevice);
444 spin_unlock_irq(&pDevice->lock);
448 pDevice->bwextstep0 = false;
449 pDevice->bwextstep1 = false;
450 pDevice->bwextstep2 = false;
451 pDevice->bwextstep3 = false;
452 pDevice->bWPASuppWextEnabled = false;
453 pDevice->fWPA_Authened = false;
455 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Send Disassociation Packet..\n");
456 // reason = 8 : disassoc because sta has left
457 vMgrDisassocBeginSta((void *) pDevice,
462 pDevice->bLinkPass = false;
463 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW);
464 // unlock command busy
465 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
467 memset(pItemSSID->abySSID, 0, WLAN_SSID_MAXLEN);
468 pMgmt->eCurrState = WMAC_STATE_IDLE;
469 pMgmt->sNodeDBTable[0].bActive = false;
470 // pDevice->bBeaconBufReady = false;
472 netif_stop_queue(pDevice->dev);
473 if (pDevice->bNeedRadioOFF == true)
474 CARDbRadioPowerOff(pDevice);
475 s_bCommandComplete(pDevice);
478 case WLAN_CMD_SSID_START:
480 pDevice->byReAssocCount = 0;
481 if (pDevice->bRadioOff == true) {
482 s_bCommandComplete(pDevice);
483 spin_unlock_irq(&pDevice->lock);
487 memcpy(pMgmt->abyAdHocSSID,pMgmt->abyDesireSSID,
488 ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->len + WLAN_IEHDR_LEN);
490 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
491 pItemSSIDCurr = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
492 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" cmd: desire ssid = %s\n", pItemSSID->abySSID);
493 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" cmd: curr ssid = %s\n", pItemSSIDCurr->abySSID);
495 if (pMgmt->eCurrState == WMAC_STATE_ASSOC) {
496 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Cmd pMgmt->eCurrState == WMAC_STATE_ASSOC\n");
497 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" pItemSSID->len =%d\n",pItemSSID->len);
498 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" pItemSSIDCurr->len = %d\n",pItemSSIDCurr->len);
499 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" desire ssid = %s\n", pItemSSID->abySSID);
500 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" curr ssid = %s\n", pItemSSIDCurr->abySSID);
503 if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) ||
504 ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)&& (pMgmt->eCurrState == WMAC_STATE_JOINTED))) {
506 if (pItemSSID->len == pItemSSIDCurr->len) {
507 if (memcmp(pItemSSID->abySSID, pItemSSIDCurr->abySSID, pItemSSID->len) == 0) {
508 s_bCommandComplete(pDevice);
509 spin_unlock_irq(&pDevice->lock);
513 netif_stop_queue(pDevice->dev);
514 pDevice->bLinkPass = false;
515 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW);
518 pMgmt->eCurrState = WMAC_STATE_IDLE;
519 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
520 PSvDisablePowerSaving((void *) pDevice);
521 BSSvClearNodeDBTable(pDevice, 0);
522 vMgrJoinBSSBegin((void *) pDevice, &Status);
524 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED)) {
525 // Call mgr to begin the deauthentication
526 // reason = (3) because sta has left ESS
527 if (pMgmt->eCurrState >= WMAC_STATE_AUTH) {
528 vMgrDeAuthenBeginSta((void *)pDevice,
534 // Call mgr to begin the authentication
535 vMgrAuthenBeginSta((void *) pDevice, pMgmt, &Status);
536 if (Status == CMD_STATUS_SUCCESS) {
537 pDevice->byLinkWaitCount = 0;
538 pDevice->eCommandState = WLAN_AUTHENTICATE_WAIT;
539 vCommandTimerWait((void *) pDevice, AUTHENTICATE_TIMEOUT);
540 spin_unlock_irq(&pDevice->lock);
541 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Set eCommandState = WLAN_AUTHENTICATE_WAIT\n");
546 else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
547 if (pMgmt->eCurrState == WMAC_STATE_JOINTED) {
548 if (netif_queue_stopped(pDevice->dev)){
549 netif_wake_queue(pDevice->dev);
551 pDevice->bLinkPass = true;
552 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER);
553 pMgmt->sNodeDBTable[0].bActive = true;
554 pMgmt->sNodeDBTable[0].uInActiveCount = 0;
558 DBG_PRT(MSG_LEVEL_DEBUG,
559 KERN_INFO "CreateOwn IBSS by CurrMode = IBSS_STA\n");
560 vMgrCreateOwnIBSS((void *) pDevice, &Status);
561 if (Status != CMD_STATUS_SUCCESS){
562 DBG_PRT(MSG_LEVEL_DEBUG,
563 KERN_INFO "WLAN_CMD_IBSS_CREATE fail!\n");
565 BSSvAddMulticastNode(pDevice);
567 s_bClearBSSID_SCAN(pDevice);
570 else if (pMgmt->eCurrMode == WMAC_MODE_STANDBY) {
571 if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA ||
572 pMgmt->eConfigMode == WMAC_CONFIG_AUTO) {
574 DBG_PRT(MSG_LEVEL_DEBUG,
575 KERN_INFO "CreateOwn IBSS by CurrMode = STANDBY\n");
576 vMgrCreateOwnIBSS((void *) pDevice, &Status);
577 if (Status != CMD_STATUS_SUCCESS){
578 DBG_PRT(MSG_LEVEL_DEBUG,
579 KERN_INFO "WLAN_CMD_IBSS_CREATE fail!\n");
581 BSSvAddMulticastNode(pDevice);
582 s_bClearBSSID_SCAN(pDevice);
584 pDevice->bLinkPass = true;
585 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER);
586 if (netif_queue_stopped(pDevice->dev)){
587 netif_wake_queue(pDevice->dev);
589 s_bClearBSSID_SCAN(pDevice);
593 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disconnect SSID none\n");
594 // if(pDevice->bWPASuppWextEnabled == true)
596 union iwreq_data wrqu;
597 memset(&wrqu, 0, sizeof (wrqu));
598 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
599 PRINT_K("wireless_send_event--->SIOCGIWAP(disassociated:vMgrJoinBSSBegin Fail !!)\n");
600 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
604 s_bCommandComplete(pDevice);
607 case WLAN_AUTHENTICATE_WAIT :
608 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState == WLAN_AUTHENTICATE_WAIT\n");
609 if (pMgmt->eCurrState == WMAC_STATE_AUTH) {
610 pDevice->byLinkWaitCount = 0;
611 // Call mgr to begin the association
612 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCurrState == WMAC_STATE_AUTH\n");
613 vMgrAssocBeginSta((void *) pDevice, pMgmt, &Status);
614 if (Status == CMD_STATUS_SUCCESS) {
615 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState = WLAN_ASSOCIATE_WAIT\n");
616 pDevice->byLinkWaitCount = 0;
617 pDevice->eCommandState = WLAN_ASSOCIATE_WAIT;
618 vCommandTimerWait((void *) pDevice, ASSOCIATE_TIMEOUT);
619 spin_unlock_irq(&pDevice->lock);
623 else if(pMgmt->eCurrState < WMAC_STATE_AUTHPENDING) {
624 printk("WLAN_AUTHENTICATE_WAIT:Authen Fail???\n");
626 else if(pDevice->byLinkWaitCount <= 4){ //mike add:wait another 2 sec if authenticated_frame delay!
627 pDevice->byLinkWaitCount ++;
628 printk("WLAN_AUTHENTICATE_WAIT:wait %d times!!\n",pDevice->byLinkWaitCount);
629 spin_unlock_irq(&pDevice->lock);
630 vCommandTimerWait((void *) pDevice, AUTHENTICATE_TIMEOUT/2);
633 pDevice->byLinkWaitCount = 0;
635 s_bCommandComplete(pDevice);
638 case WLAN_ASSOCIATE_WAIT :
639 if (pMgmt->eCurrState == WMAC_STATE_ASSOC) {
640 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCurrState == WMAC_STATE_ASSOC\n");
641 if (pDevice->ePSMode != WMAC_POWER_CAM) {
642 PSvEnablePowerSaving((void *) pDevice,
643 pMgmt->wListenInterval);
646 if (pMgmt->eAuthenMode >= WMAC_AUTH_WPA) {
647 KeybRemoveAllKey(pDevice, &(pDevice->sKey), pDevice->abyBSSID);
650 pDevice->byLinkWaitCount = 0;
651 pDevice->byReAssocCount = 0;
652 pDevice->bLinkPass = true;
653 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER);
654 s_bClearBSSID_SCAN(pDevice);
656 if (netif_queue_stopped(pDevice->dev)){
657 netif_wake_queue(pDevice->dev);
661 else if(pMgmt->eCurrState < WMAC_STATE_ASSOCPENDING) {
662 printk("WLAN_ASSOCIATE_WAIT:Association Fail???\n");
664 else if(pDevice->byLinkWaitCount <= 4){ //mike add:wait another 2 sec if associated_frame delay!
665 pDevice->byLinkWaitCount ++;
666 printk("WLAN_ASSOCIATE_WAIT:wait %d times!!\n",pDevice->byLinkWaitCount);
667 spin_unlock_irq(&pDevice->lock);
668 vCommandTimerWait((void *) pDevice, ASSOCIATE_TIMEOUT/2);
672 s_bCommandComplete(pDevice);
675 case WLAN_CMD_AP_MODE_START :
676 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState == WLAN_CMD_AP_MODE_START\n");
678 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
679 cancel_delayed_work_sync(&pDevice->second_callback_work);
680 pMgmt->eCurrState = WMAC_STATE_IDLE;
681 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
682 pDevice->bLinkPass = false;
683 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW);
684 if (pDevice->bEnableHostWEP == true)
685 BSSvClearNodeDBTable(pDevice, 1);
687 BSSvClearNodeDBTable(pDevice, 0);
688 pDevice->uAssocCount = 0;
689 pMgmt->eCurrState = WMAC_STATE_IDLE;
690 pDevice->bFixRate = false;
692 vMgrCreateOwnIBSS((void *) pDevice, &Status);
693 if (Status != CMD_STATUS_SUCCESS) {
694 DBG_PRT(MSG_LEVEL_DEBUG,
695 KERN_INFO "vMgrCreateOwnIBSS fail!\n");
697 // always turn off unicast bit
698 MACvRegBitsOff(pDevice, MAC_REG_RCR, RCR_UNICAST);
699 pDevice->byRxMode &= ~RCR_UNICAST;
700 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wcmd: rx_mode = %x\n", pDevice->byRxMode );
701 BSSvAddMulticastNode(pDevice);
702 if (netif_queue_stopped(pDevice->dev)){
703 netif_wake_queue(pDevice->dev);
705 pDevice->bLinkPass = true;
706 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER);
707 schedule_delayed_work(&pDevice->second_callback_work, HZ);
709 s_bCommandComplete(pDevice);
712 case WLAN_CMD_TX_PSPACKET_START :
714 if (pMgmt->sNodeDBTable[0].bRxPSPoll) {
715 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[0].sTxPSQueue)) != NULL) {
716 if (skb_queue_empty(&pMgmt->sNodeDBTable[0].sTxPSQueue)) {
717 pMgmt->abyPSTxMap[0] &= ~byMask[0];
718 pDevice->bMoreData = false;
721 pDevice->bMoreData = true;
724 if (nsDMA_tx_packet(pDevice, TYPE_AC0DMA, skb) != 0) {
725 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Multicast ps tx fail \n");
728 pMgmt->sNodeDBTable[0].wEnQueueCnt--;
733 for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) {
734 if (pMgmt->sNodeDBTable[ii].bActive &&
735 pMgmt->sNodeDBTable[ii].bRxPSPoll) {
736 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Index=%d Enqueu Cnt= %d\n",
737 ii, pMgmt->sNodeDBTable[ii].wEnQueueCnt);
738 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) != NULL) {
739 if (skb_queue_empty(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) {
741 pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[ii].wAID >> 3] &=
742 ~byMask[pMgmt->sNodeDBTable[ii].wAID & 7];
743 pDevice->bMoreData = false;
746 pDevice->bMoreData = true;
749 if (nsDMA_tx_packet(pDevice, TYPE_AC0DMA, skb) != 0) {
750 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "sta ps tx fail \n");
753 pMgmt->sNodeDBTable[ii].wEnQueueCnt--;
754 // check if sta ps enable, wait next pspoll
755 // if sta ps disable, send all pending buffers.
756 if (pMgmt->sNodeDBTable[ii].bPSEnable)
759 if (skb_queue_empty(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) {
761 pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[ii].wAID >> 3] &=
762 ~byMask[pMgmt->sNodeDBTable[ii].wAID & 7];
763 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Index=%d PS queue clear \n", ii);
765 pMgmt->sNodeDBTable[ii].bRxPSPoll = false;
769 s_bCommandComplete(pDevice);
772 case WLAN_CMD_RADIO_START:
774 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState == WLAN_CMD_RADIO_START\n");
775 // if (pDevice->bRadioCmd == true)
776 // CARDbRadioPowerOn(pDevice);
778 // CARDbRadioPowerOff(pDevice);
781 int ntStatus = STATUS_SUCCESS;
784 ntStatus = CONTROLnsRequestIn(pDevice,
787 MESSAGE_REQUEST_MACREG,
791 if ( ntStatus != STATUS_SUCCESS ) {
792 s_bCommandComplete(pDevice);
793 spin_unlock_irq(&pDevice->lock);
796 if ( (byTmp & GPIO3_DATA) == 0 ) {
797 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" WLAN_CMD_RADIO_START_OFF........................\n");
798 // Old commands are useless.
800 pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
801 pDevice->uCmdDequeueIdx = 0;
802 pDevice->uCmdEnqueueIdx = 0;
803 //0415pDevice->bCmdRunning = false;
804 pDevice->bCmdClear = true;
805 pDevice->bStopTx0Pkt = false;
806 pDevice->bStopDataPkt = true;
808 pDevice->byKeyIndex = 0;
809 pDevice->bTransmitKey = false;
810 spin_unlock_irq(&pDevice->lock);
811 KeyvInitTable(pDevice,&pDevice->sKey);
812 spin_lock_irq(&pDevice->lock);
813 pMgmt->byCSSPK = KEY_CTL_NONE;
814 pMgmt->byCSSGK = KEY_CTL_NONE;
816 if (pDevice->bLinkPass == true) {
817 // reason = 8 : disassoc because sta has left
818 vMgrDisassocBeginSta((void *) pDevice,
823 pDevice->bLinkPass = false;
824 // unlock command busy
825 pMgmt->eCurrState = WMAC_STATE_IDLE;
826 pMgmt->sNodeDBTable[0].bActive = false;
827 // if(pDevice->bWPASuppWextEnabled == true)
829 union iwreq_data wrqu;
830 memset(&wrqu, 0, sizeof (wrqu));
831 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
832 PRINT_K("wireless_send_event--->SIOCGIWAP(disassociated)\n");
833 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
836 pDevice->bwextstep0 = false;
837 pDevice->bwextstep1 = false;
838 pDevice->bwextstep2 = false;
839 pDevice->bwextstep3 = false;
840 pDevice->bWPASuppWextEnabled = false;
842 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
844 memset(pItemSSID->abySSID, 0, WLAN_SSID_MAXLEN);
846 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
848 memset(pItemSSID->abySSID, 0, WLAN_SSID_MAXLEN);
850 netif_stop_queue(pDevice->dev);
851 CARDbRadioPowerOff(pDevice);
852 MACvRegBitsOn(pDevice,MAC_REG_GPIOCTL1,GPIO3_INTMD);
853 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_OFF);
854 pDevice->bHWRadioOff = true;
856 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" WLAN_CMD_RADIO_START_ON........................\n");
857 pDevice->bHWRadioOff = false;
858 CARDbRadioPowerOn(pDevice);
859 MACvRegBitsOff(pDevice,MAC_REG_GPIOCTL1,GPIO3_INTMD);
860 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_ON);
864 s_bCommandComplete(pDevice);
867 case WLAN_CMD_CHANGE_BBSENSITIVITY_START:
869 pDevice->bStopDataPkt = true;
870 pDevice->byBBVGACurrent = pDevice->byBBVGANew;
871 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGACurrent);
872 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Change sensitivity pDevice->byBBVGACurrent = %x\n", pDevice->byBBVGACurrent);
873 pDevice->bStopDataPkt = false;
874 s_bCommandComplete(pDevice);
877 case WLAN_CMD_TBTT_WAKEUP_START:
878 PSbIsNextTBTTWakeUp(pDevice);
879 s_bCommandComplete(pDevice);
882 case WLAN_CMD_BECON_SEND_START:
883 bMgrPrepareBeaconToSend(pDevice, pMgmt);
884 s_bCommandComplete(pDevice);
887 case WLAN_CMD_SETPOWER_START:
889 RFbSetPower(pDevice, pDevice->wCurrentRate, pMgmt->uCurrChannel);
891 s_bCommandComplete(pDevice);
894 case WLAN_CMD_CHANGE_ANTENNA_START:
895 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Change from Antenna%d to", (int)pDevice->dwRxAntennaSel);
896 if ( pDevice->dwRxAntennaSel == 0) {
897 pDevice->dwRxAntennaSel=1;
898 if (pDevice->bTxRxAntInv == true)
899 BBvSetAntennaMode(pDevice, ANT_RXA);
901 BBvSetAntennaMode(pDevice, ANT_RXB);
903 pDevice->dwRxAntennaSel=0;
904 if (pDevice->bTxRxAntInv == true)
905 BBvSetAntennaMode(pDevice, ANT_RXB);
907 BBvSetAntennaMode(pDevice, ANT_RXA);
909 s_bCommandComplete(pDevice);
912 case WLAN_CMD_REMOVE_ALLKEY_START:
913 KeybRemoveAllKey(pDevice, &(pDevice->sKey), pDevice->abyBSSID);
914 s_bCommandComplete(pDevice);
917 case WLAN_CMD_MAC_DISPOWERSAVING_START:
918 ControlvReadByte (pDevice, MESSAGE_REQUEST_MACREG, MAC_REG_PSCTL, &byData);
919 if ( (byData & PSCTL_PS) != 0 ) {
920 // disable power saving hw function
921 CONTROLnsRequestOut(pDevice,
922 MESSAGE_TYPE_DISABLE_PS,
929 s_bCommandComplete(pDevice);
932 case WLAN_CMD_11H_CHSW_START:
933 CARDbSetMediaChannel(pDevice, pDevice->byNewChannel);
934 pDevice->bChannelSwitch = false;
935 pMgmt->uCurrChannel = pDevice->byNewChannel;
936 pDevice->bStopDataPkt = false;
937 s_bCommandComplete(pDevice);
941 s_bCommandComplete(pDevice);
945 spin_unlock_irq(&pDevice->lock);
949 static int s_bCommandComplete(struct vnt_private *pDevice)
951 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
953 int bRadioCmd = false;
954 int bForceSCAN = true;
956 pDevice->eCommandState = WLAN_CMD_IDLE;
957 if (pDevice->cbFreeCmdQueue == CMD_Q_SIZE) {
958 //Command Queue Empty
959 pDevice->bCmdRunning = false;
963 pDevice->eCommand = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].eCmd;
964 pSSID = (PWLAN_IE_SSID)pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].abyCmdDesireSSID;
965 bRadioCmd = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].bRadioCmd;
966 bForceSCAN = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].bForceSCAN;
967 ADD_ONE_WITH_WRAP_AROUND(pDevice->uCmdDequeueIdx, CMD_Q_SIZE);
968 pDevice->cbFreeCmdQueue++;
969 pDevice->bCmdRunning = true;
970 switch ( pDevice->eCommand ) {
971 case WLAN_CMD_BSSID_SCAN:
972 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState= WLAN_CMD_BSSID_SCAN\n");
973 pDevice->eCommandState = WLAN_CMD_SCAN_START;
974 pMgmt->uScanChannel = 0;
975 if (pSSID->len != 0) {
976 memcpy(pMgmt->abyScanSSID, pSSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
978 memset(pMgmt->abyScanSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
981 if ((bForceSCAN == false) && (pDevice->bLinkPass == true)) {
982 if ((pSSID->len == ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len) &&
983 ( !memcmp(pSSID->abySSID, ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID, pSSID->len))) {
984 pDevice->eCommandState = WLAN_CMD_IDLE;
990 pDevice->eCommandState = WLAN_CMD_SSID_START;
991 if (pSSID->len > WLAN_SSID_MAXLEN)
992 pSSID->len = WLAN_SSID_MAXLEN;
994 memcpy(pMgmt->abyDesireSSID, pSSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
995 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState= WLAN_CMD_SSID_START\n");
997 case WLAN_CMD_DISASSOCIATE:
998 pDevice->eCommandState = WLAN_CMD_DISASSOCIATE_START;
1000 case WLAN_CMD_RX_PSPOLL:
1001 pDevice->eCommandState = WLAN_CMD_TX_PSPACKET_START;
1003 case WLAN_CMD_RUN_AP:
1004 pDevice->eCommandState = WLAN_CMD_AP_MODE_START;
1006 case WLAN_CMD_RADIO:
1007 pDevice->eCommandState = WLAN_CMD_RADIO_START;
1008 pDevice->bRadioCmd = bRadioCmd;
1010 case WLAN_CMD_CHANGE_BBSENSITIVITY:
1011 pDevice->eCommandState = WLAN_CMD_CHANGE_BBSENSITIVITY_START;
1014 case WLAN_CMD_TBTT_WAKEUP:
1015 pDevice->eCommandState = WLAN_CMD_TBTT_WAKEUP_START;
1018 case WLAN_CMD_BECON_SEND:
1019 pDevice->eCommandState = WLAN_CMD_BECON_SEND_START;
1022 case WLAN_CMD_SETPOWER:
1023 pDevice->eCommandState = WLAN_CMD_SETPOWER_START;
1026 case WLAN_CMD_CHANGE_ANTENNA:
1027 pDevice->eCommandState = WLAN_CMD_CHANGE_ANTENNA_START;
1030 case WLAN_CMD_REMOVE_ALLKEY:
1031 pDevice->eCommandState = WLAN_CMD_REMOVE_ALLKEY_START;
1034 case WLAN_CMD_MAC_DISPOWERSAVING:
1035 pDevice->eCommandState = WLAN_CMD_MAC_DISPOWERSAVING_START;
1038 case WLAN_CMD_11H_CHSW:
1039 pDevice->eCommandState = WLAN_CMD_11H_CHSW_START;
1046 vCommandTimerWait(pDevice, 0);
1052 int bScheduleCommand(struct vnt_private *pDevice,
1053 CMD_CODE eCommand, u8 *pbyItem0)
1056 if (pDevice->cbFreeCmdQueue == 0) {
1059 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].eCmd = eCommand;
1060 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bForceSCAN = true;
1061 memset(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID, 0 , WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
1062 if (pbyItem0 != NULL) {
1064 case WLAN_CMD_BSSID_SCAN:
1065 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bForceSCAN = false;
1066 memcpy(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID,
1067 pbyItem0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
1071 memcpy(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID,
1072 pbyItem0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
1075 case WLAN_CMD_DISASSOCIATE:
1076 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bNeedRadioOFF = *((int *)pbyItem0);
1079 case WLAN_CMD_DEAUTH:
1080 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].wDeAuthenReason = *((u16 *)pbyItem0);
1084 case WLAN_CMD_RADIO:
1085 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bRadioCmd = *((int *)pbyItem0);
1093 ADD_ONE_WITH_WRAP_AROUND(pDevice->uCmdEnqueueIdx, CMD_Q_SIZE);
1094 pDevice->cbFreeCmdQueue--;
1096 if (pDevice->bCmdRunning == false) {
1097 s_bCommandComplete(pDevice);
1107 * Clear BSSID_SCAN cmd in CMD Queue
1111 * hDeviceContext - Pointer to the adapter
1112 * eCommand - Command
1116 * Return Value: true if success; otherwise false
1119 static int s_bClearBSSID_SCAN(struct vnt_private *pDevice)
1121 unsigned int uCmdDequeueIdx = pDevice->uCmdDequeueIdx;
1124 if ((pDevice->cbFreeCmdQueue < CMD_Q_SIZE) && (uCmdDequeueIdx != pDevice->uCmdEnqueueIdx)) {
1125 for (ii = 0; ii < (CMD_Q_SIZE - pDevice->cbFreeCmdQueue); ii ++) {
1126 if (pDevice->eCmdQueue[uCmdDequeueIdx].eCmd == WLAN_CMD_BSSID_SCAN)
1127 pDevice->eCmdQueue[uCmdDequeueIdx].eCmd = WLAN_CMD_IDLE;
1128 ADD_ONE_WITH_WRAP_AROUND(uCmdDequeueIdx, CMD_Q_SIZE);
1129 if (uCmdDequeueIdx == pDevice->uCmdEnqueueIdx)
1136 //mike add:reset command timer
1137 void vResetCommandTimer(struct vnt_private *pDevice)
1139 cancel_delayed_work_sync(&pDevice->run_command_work);
1141 pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
1142 pDevice->uCmdDequeueIdx = 0;
1143 pDevice->uCmdEnqueueIdx = 0;
1144 pDevice->eCommandState = WLAN_CMD_IDLE;
1145 pDevice->bCmdRunning = false;
1146 pDevice->bCmdClear = false;