2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 * Purpose: Handles the management command interface functions
28 * s_vProbeChannel - Active scan channel
29 * s_MgrMakeProbeRequest - Make ProbeRequest packet
30 * CommandTimer - Timer function to handle command
31 * s_bCommandComplete - Command Complete function
32 * bScheduleCommand - Push Command and wait Command Scheduler to do
33 * vCommandTimer- Command call back functions
34 * vCommandTimerWait- Call back timer
35 * bClearBSSID_SCAN- Clear BSSID_SCAN cmd in CMD Queue
57 /*--------------------- Static Definitions -------------------------*/
59 /*--------------------- Static Classes ----------------------------*/
61 /*--------------------- Static Variables --------------------------*/
62 static int msglevel
= MSG_LEVEL_INFO
;
63 //static int msglevel =MSG_LEVEL_DEBUG;
64 /*--------------------- Static Functions --------------------------*/
74 s_MgrMakeProbeRequest(
77 unsigned char *pScanBSSID
,
79 PWLAN_IE_SUPP_RATES pCurrRates
,
80 PWLAN_IE_SUPP_RATES pCurrExtSuppRates
89 /*--------------------- Export Variables --------------------------*/
91 /*--------------------- Export Functions --------------------------*/
95 * Stop AdHoc beacon during scan process
99 * pDevice - Pointer to the adapter
108 vAdHocBeaconStop(PSDevice pDevice
)
110 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
114 * temporarily stop Beacon packet for AdHoc Server
115 * if all of the following conditions are met:
116 * (1) STA is in AdHoc mode
117 * (2) VT3253 is programmed as automatic Beacon Transmitting
118 * (3) One of the following conditions is met
119 * (3.1) AdHoc channel is in B/G band and the
120 * current scan channel is in A band
122 * (3.2) AdHoc channel is in A mode
125 if ((pMgmt
->eCurrMode
== WMAC_MODE_IBSS_STA
) &&
126 (pMgmt
->eCurrState
>= WMAC_STATE_STARTED
)) {
127 if ((pMgmt
->uIBSSChannel
<= CB_MAX_CHANNEL_24G
) &&
128 (pMgmt
->uScanChannel
> CB_MAX_CHANNEL_24G
)) {
131 if (pMgmt
->uIBSSChannel
> CB_MAX_CHANNEL_24G
) {
137 MACvRegBitsOff(pDevice
->PortOffset
, MAC_REG_TCR
, TCR_AUTOBCNTX
);
139 } /* vAdHocBeaconStop */
143 * Restart AdHoc beacon after scan process complete
147 * pDevice - Pointer to the adapter
156 vAdHocBeaconRestart(PSDevice pDevice
)
158 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
161 * Restart Beacon packet for AdHoc Server
162 * if all of the following coditions are met:
163 * (1) STA is in AdHoc mode
164 * (2) VT3253 is programmed as automatic Beacon Transmitting
166 if ((pMgmt
->eCurrMode
== WMAC_MODE_IBSS_STA
) &&
167 (pMgmt
->eCurrState
>= WMAC_STATE_STARTED
)) {
168 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_TCR
, TCR_AUTOBCNTX
);
174 * Routine Description:
175 * Prepare and send probe request management frames.
189 //1M, 2M, 5M, 11M, 18M, 24M, 36M, 54M
190 unsigned char abyCurrSuppRatesG
[] = {WLAN_EID_SUPP_RATES
, 8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C};
191 unsigned char abyCurrExtSuppRatesG
[] = {WLAN_EID_EXTSUPP_RATES
, 4, 0x0C, 0x12, 0x18, 0x60};
193 unsigned char abyCurrSuppRatesA
[] = {WLAN_EID_SUPP_RATES
, 8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
194 unsigned char abyCurrSuppRatesB
[] = {WLAN_EID_SUPP_RATES
, 4, 0x02, 0x04, 0x0B, 0x16};
195 unsigned char *pbyRate
;
196 PSTxMgmtPacket pTxPacket
;
197 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
200 if (pDevice
->eCurrentPHYType
== PHY_TYPE_11A
) {
201 pbyRate
= &abyCurrSuppRatesA
[0];
202 } else if (pDevice
->eCurrentPHYType
== PHY_TYPE_11B
) {
203 pbyRate
= &abyCurrSuppRatesB
[0];
205 pbyRate
= &abyCurrSuppRatesG
[0];
207 // build an assocreq frame and send it
208 pTxPacket
= s_MgrMakeProbeRequest
213 (PWLAN_IE_SSID
)pMgmt
->abyScanSSID
,
214 (PWLAN_IE_SUPP_RATES
)pbyRate
,
215 (PWLAN_IE_SUPP_RATES
)abyCurrExtSuppRatesG
218 if (pTxPacket
!= NULL
) {
219 for (ii
= 0; ii
< 2; ii
++) {
220 if (csMgmt_xmit(pDevice
, pTxPacket
) != CMD_STATUS_PENDING
) {
221 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Probe request sending fail.. \n");
223 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Probe request is sending.. \n");
231 * Routine Description:
232 * Constructs an probe request frame
236 * A ptr to Tx frame or NULL on allocation failure
241 s_MgrMakeProbeRequest(
244 unsigned char *pScanBSSID
,
246 PWLAN_IE_SUPP_RATES pCurrRates
,
247 PWLAN_IE_SUPP_RATES pCurrExtSuppRates
251 PSTxMgmtPacket pTxPacket
= NULL
;
252 WLAN_FR_PROBEREQ sFrame
;
254 pTxPacket
= (PSTxMgmtPacket
)pMgmt
->pbyMgmtPacketPool
;
255 memset(pTxPacket
, 0, sizeof(STxMgmtPacket
) + WLAN_PROBEREQ_FR_MAXLEN
);
256 pTxPacket
->p80211Header
= (PUWLAN_80211HDR
)((unsigned char *)pTxPacket
+ sizeof(STxMgmtPacket
));
257 sFrame
.pBuf
= (unsigned char *)pTxPacket
->p80211Header
;
258 sFrame
.len
= WLAN_PROBEREQ_FR_MAXLEN
;
259 vMgrEncodeProbeRequest(&sFrame
);
260 sFrame
.pHdr
->sA3
.wFrameCtl
= cpu_to_le16(
262 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR
) |
263 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_PROBEREQ
)
265 memcpy(sFrame
.pHdr
->sA3
.abyAddr1
, pScanBSSID
, WLAN_ADDR_LEN
);
266 memcpy(sFrame
.pHdr
->sA3
.abyAddr2
, pMgmt
->abyMACAddr
, WLAN_ADDR_LEN
);
267 memcpy(sFrame
.pHdr
->sA3
.abyAddr3
, pScanBSSID
, WLAN_BSSID_LEN
);
268 // Copy the SSID, pSSID->len=0 indicate broadcast SSID
269 sFrame
.pSSID
= (PWLAN_IE_SSID
)(sFrame
.pBuf
+ sFrame
.len
);
270 sFrame
.len
+= pSSID
->len
+ WLAN_IEHDR_LEN
;
271 memcpy(sFrame
.pSSID
, pSSID
, pSSID
->len
+ WLAN_IEHDR_LEN
);
272 sFrame
.pSuppRates
= (PWLAN_IE_SUPP_RATES
)(sFrame
.pBuf
+ sFrame
.len
);
273 sFrame
.len
+= pCurrRates
->len
+ WLAN_IEHDR_LEN
;
274 memcpy(sFrame
.pSuppRates
, pCurrRates
, pCurrRates
->len
+ WLAN_IEHDR_LEN
);
275 // Copy the extension rate set
276 if (pDevice
->eCurrentPHYType
== PHY_TYPE_11G
) {
277 sFrame
.pExtSuppRates
= (PWLAN_IE_SUPP_RATES
)(sFrame
.pBuf
+ sFrame
.len
);
278 sFrame
.len
+= pCurrExtSuppRates
->len
+ WLAN_IEHDR_LEN
;
279 memcpy(sFrame
.pExtSuppRates
, pCurrExtSuppRates
, pCurrExtSuppRates
->len
+ WLAN_IEHDR_LEN
);
281 pTxPacket
->cbMPDULen
= sFrame
.len
;
282 pTxPacket
->cbPayloadLen
= sFrame
.len
- WLAN_HDR_ADDR3_LEN
;
289 void *hDeviceContext
,
293 PSDevice pDevice
= (PSDevice
)hDeviceContext
;
295 init_timer(&pDevice
->sTimerCommand
);
296 pDevice
->sTimerCommand
.data
= (unsigned long) pDevice
;
297 pDevice
->sTimerCommand
.function
= (TimerFunction
)vCommandTimer
;
298 // RUN_AT :1 msec ~= (HZ/1024)
299 pDevice
->sTimerCommand
.expires
= (unsigned int)RUN_AT((MSecond
* HZ
) >> 10);
300 add_timer(&pDevice
->sTimerCommand
);
309 PSDevice pDevice
= (PSDevice
)hDeviceContext
;
310 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
311 PWLAN_IE_SSID pItemSSID
;
312 PWLAN_IE_SSID pItemSSIDCurr
;
315 unsigned char byMask
[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
318 if (pDevice
->dwDiagRefCount
!= 0)
320 if (!pDevice
->bCmdRunning
)
323 spin_lock_irq(&pDevice
->lock
);
325 switch (pDevice
->eCommandState
) {
326 case WLAN_CMD_SCAN_START
:
328 pDevice
->byReAssocCount
= 0;
329 if (pDevice
->bRadioOff
) {
330 s_bCommandComplete(pDevice
);
331 spin_unlock_irq(&pDevice
->lock
);
335 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) {
336 s_bCommandComplete(pDevice
);
337 CARDbSetBSSID(pMgmt
->pAdapter
, pMgmt
->abyCurrBSSID
, OP_MODE_AP
);
338 spin_unlock_irq(&pDevice
->lock
);
342 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"eCommandState= WLAN_CMD_SCAN_START\n");
343 pItemSSID
= (PWLAN_IE_SSID
)pMgmt
->abyScanSSID
;
344 // wait all Data TD complete
345 if (pDevice
->iTDUsed
[TYPE_AC0DMA
] != 0) {
346 spin_unlock_irq(&pDevice
->lock
);
347 vCommandTimerWait((void *)pDevice
, 10);
351 if (pMgmt
->uScanChannel
== 0) {
352 pMgmt
->uScanChannel
= pDevice
->byMinChannel
;
353 // Set Baseband to be more sensitive.
356 if (pMgmt
->uScanChannel
> pDevice
->byMaxChannel
) {
357 pMgmt
->eScanState
= WMAC_NO_SCANNING
;
359 // Set Baseband's sensitivity back.
361 set_channel(pMgmt
->pAdapter
, pMgmt
->uCurrChannel
);
362 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Scanning, set back to channel: [%d]\n", pMgmt
->uCurrChannel
);
363 if (pMgmt
->eCurrMode
== WMAC_MODE_IBSS_STA
) {
364 CARDbSetBSSID(pMgmt
->pAdapter
, pMgmt
->abyCurrBSSID
, OP_MODE_ADHOC
);
366 CARDbSetBSSID(pMgmt
->pAdapter
, pMgmt
->abyCurrBSSID
, OP_MODE_INFRASTRUCTURE
);
368 vAdHocBeaconRestart(pDevice
);
369 s_bCommandComplete(pDevice
);
372 //2008-8-4 <add> by chester
373 if (!is_channel_valid(pMgmt
->uScanChannel
)) {
374 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Invalid channel pMgmt->uScanChannel = %d \n", pMgmt
->uScanChannel
);
375 s_bCommandComplete(pDevice
);
376 spin_unlock_irq(&pDevice
->lock
);
379 if (pMgmt
->uScanChannel
== pDevice
->byMinChannel
) {
380 //pMgmt->eScanType = WMAC_SCAN_ACTIVE;
381 pMgmt
->abyScanBSSID
[0] = 0xFF;
382 pMgmt
->abyScanBSSID
[1] = 0xFF;
383 pMgmt
->abyScanBSSID
[2] = 0xFF;
384 pMgmt
->abyScanBSSID
[3] = 0xFF;
385 pMgmt
->abyScanBSSID
[4] = 0xFF;
386 pMgmt
->abyScanBSSID
[5] = 0xFF;
387 pItemSSID
->byElementID
= WLAN_EID_SSID
;
389 // BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass);
390 pMgmt
->eScanState
= WMAC_IS_SCANNING
;
394 vAdHocBeaconStop(pDevice
);
396 if (set_channel(pMgmt
->pAdapter
, pMgmt
->uScanChannel
)) {
397 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"SCAN Channel: %d\n", pMgmt
->uScanChannel
);
399 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"SET SCAN Channel Fail: %d\n", pMgmt
->uScanChannel
);
401 CARDbSetBSSID(pMgmt
->pAdapter
, pMgmt
->abyCurrBSSID
, OP_MODE_UNKNOWN
);
402 pMgmt
->uScanChannel
++;
403 //2008-8-4 <modify> by chester
404 if (!is_channel_valid(pMgmt
->uScanChannel
) &&
405 pMgmt
->uScanChannel
<= pDevice
->byMaxChannel
) {
406 pMgmt
->uScanChannel
= pDevice
->byMaxChannel
+ 1;
407 pMgmt
->eCommandState
= WLAN_CMD_SCAN_END
;
411 if (!pMgmt
->b11hEnable
||
412 (pMgmt
->uScanChannel
< CB_MAX_CHANNEL_24G
)) {
413 s_vProbeChannel(pDevice
);
414 spin_unlock_irq(&pDevice
->lock
);
415 vCommandTimerWait((void *)pDevice
, WCMD_ACTIVE_SCAN_TIME
);
418 spin_unlock_irq(&pDevice
->lock
);
419 vCommandTimerWait((void *)pDevice
, WCMD_PASSIVE_SCAN_TIME
);
427 case WLAN_CMD_SCAN_END
:
429 // Set Baseband's sensitivity back.
431 set_channel(pMgmt
->pAdapter
, pMgmt
->uCurrChannel
);
432 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Scanning, set back to channel: [%d]\n", pMgmt
->uCurrChannel
);
433 if (pMgmt
->eCurrMode
== WMAC_MODE_IBSS_STA
) {
434 CARDbSetBSSID(pMgmt
->pAdapter
, pMgmt
->abyCurrBSSID
, OP_MODE_ADHOC
);
436 CARDbSetBSSID(pMgmt
->pAdapter
, pMgmt
->abyCurrBSSID
, OP_MODE_INFRASTRUCTURE
);
439 pMgmt
->eScanState
= WMAC_NO_SCANNING
;
440 vAdHocBeaconRestart(pDevice
);
441 //2008-0409-07, <Add> by Einsn Liu
442 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
443 if (pMgmt
->eScanType
== WMAC_SCAN_PASSIVE
)
444 {//send scan event to wpa_Supplicant
445 union iwreq_data wrqu
;
446 memset(&wrqu
, 0, sizeof(wrqu
));
447 wireless_send_event(pDevice
->dev
, SIOCGIWSCAN
, &wrqu
, NULL
);
450 s_bCommandComplete(pDevice
);
453 case WLAN_CMD_DISASSOCIATE_START
:
454 pDevice
->byReAssocCount
= 0;
455 if ((pMgmt
->eCurrMode
== WMAC_MODE_ESS_STA
) &&
456 (pMgmt
->eCurrState
!= WMAC_STATE_ASSOC
)) {
457 s_bCommandComplete(pDevice
);
458 spin_unlock_irq(&pDevice
->lock
);
461 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Send Disassociation Packet..\n");
462 // reason = 8 : disassoc because sta has left
463 vMgrDisassocBeginSta((void *)pDevice
, pMgmt
, pMgmt
->abyCurrBSSID
, (8), &Status
);
464 pDevice
->bLinkPass
= false;
465 // unlock command busy
466 pItemSSID
= (PWLAN_IE_SSID
)pMgmt
->abyCurrSSID
;
468 memset(pItemSSID
->abySSID
, 0, WLAN_SSID_MAXLEN
);
469 pMgmt
->eCurrState
= WMAC_STATE_IDLE
;
470 pMgmt
->sNodeDBTable
[0].bActive
= false;
471 // pDevice->bBeaconBufReady = false;
473 netif_stop_queue(pDevice
->dev
);
474 pDevice
->eCommandState
= WLAN_DISASSOCIATE_WAIT
;
475 // wait all Control TD complete
476 if (pDevice
->iTDUsed
[TYPE_TXDMA0
] != 0) {
477 vCommandTimerWait((void *)pDevice
, 10);
478 spin_unlock_irq(&pDevice
->lock
);
481 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" CARDbRadioPowerOff\n");
482 //2008-09-02 <mark> by chester
483 // CARDbRadioPowerOff(pDevice);
484 s_bCommandComplete(pDevice
);
487 case WLAN_DISASSOCIATE_WAIT
:
488 // wait all Control TD complete
489 if (pDevice
->iTDUsed
[TYPE_TXDMA0
] != 0) {
490 vCommandTimerWait((void *)pDevice
, 10);
491 spin_unlock_irq(&pDevice
->lock
);
494 //2008-09-02 <mark> by chester
495 // CARDbRadioPowerOff(pDevice);
496 s_bCommandComplete(pDevice
);
499 case WLAN_CMD_SSID_START
:
500 pDevice
->byReAssocCount
= 0;
501 if (pDevice
->bRadioOff
) {
502 s_bCommandComplete(pDevice
);
503 spin_unlock_irq(&pDevice
->lock
);
506 printk("chester-abyDesireSSID=%s\n", ((PWLAN_IE_SSID
)pMgmt
->abyDesireSSID
)->abySSID
);
507 //memcpy(pMgmt->abyAdHocSSID,pMgmt->abyDesireSSID,
508 //((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->len + WLAN_IEHDR_LEN);
509 pItemSSID
= (PWLAN_IE_SSID
)pMgmt
->abyDesireSSID
;
510 pItemSSIDCurr
= (PWLAN_IE_SSID
)pMgmt
->abyCurrSSID
;
511 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" cmd: desire ssid = %s\n", pItemSSID
->abySSID
);
512 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" cmd: curr ssid = %s\n", pItemSSIDCurr
->abySSID
);
514 if (pMgmt
->eCurrState
== WMAC_STATE_ASSOC
) {
515 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" Cmd pMgmt->eCurrState == WMAC_STATE_ASSOC\n");
516 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" pItemSSID->len =%d\n", pItemSSID
->len
);
517 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" pItemSSIDCurr->len = %d\n", pItemSSIDCurr
->len
);
518 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" desire ssid = %s\n", pItemSSID
->abySSID
);
519 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" curr ssid = %s\n", pItemSSIDCurr
->abySSID
);
522 if ((pMgmt
->eCurrState
== WMAC_STATE_ASSOC
) ||
523 ((pMgmt
->eCurrMode
== WMAC_MODE_IBSS_STA
) && (pMgmt
->eCurrState
== WMAC_STATE_JOINTED
))) {
524 if (pItemSSID
->len
== pItemSSIDCurr
->len
) {
525 if (memcmp(pItemSSID
->abySSID
, pItemSSIDCurr
->abySSID
, pItemSSID
->len
) == 0) {
526 s_bCommandComplete(pDevice
);
527 spin_unlock_irq(&pDevice
->lock
);
532 netif_stop_queue(pDevice
->dev
);
533 pDevice
->bLinkPass
= false;
536 pMgmt
->eCurrState
= WMAC_STATE_IDLE
;
537 pMgmt
->eCurrMode
= WMAC_MODE_STANDBY
;
538 PSvDisablePowerSaving((void *)pDevice
);
539 BSSvClearNodeDBTable(pDevice
, 0);
541 vMgrJoinBSSBegin((void *)pDevice
, &Status
);
543 if ((pMgmt
->eCurrMode
== WMAC_MODE_ESS_STA
) && (pMgmt
->eCurrState
== WMAC_STATE_JOINTED
)) {
544 // Call mgr to begin the deauthentication
545 // reason = (3) because sta has left ESS
546 if (pMgmt
->eCurrState
>= WMAC_STATE_AUTH
) {
547 vMgrDeAuthenBeginSta((void *)pDevice
, pMgmt
, pMgmt
->abyCurrBSSID
, (3), &Status
);
549 // Call mgr to begin the authentication
550 vMgrAuthenBeginSta((void *)pDevice
, pMgmt
, &Status
);
551 if (Status
== CMD_STATUS_SUCCESS
) {
552 pDevice
->byLinkWaitCount
= 0;
553 pDevice
->eCommandState
= WLAN_AUTHENTICATE_WAIT
;
554 vCommandTimerWait((void *)pDevice
, AUTHENTICATE_TIMEOUT
);
555 spin_unlock_irq(&pDevice
->lock
);
556 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" Set eCommandState = WLAN_AUTHENTICATE_WAIT\n");
561 else if (pMgmt
->eCurrMode
== WMAC_MODE_IBSS_STA
) {
562 if (pMgmt
->eCurrState
== WMAC_STATE_JOINTED
) {
563 if (netif_queue_stopped(pDevice
->dev
)) {
564 netif_wake_queue(pDevice
->dev
);
566 pDevice
->bLinkPass
= true;
568 pMgmt
->sNodeDBTable
[0].bActive
= true;
569 pMgmt
->sNodeDBTable
[0].uInActiveCount
= 0;
570 bClearBSSID_SCAN(pDevice
);
573 vMgrCreateOwnIBSS((void *)pDevice
, &Status
);
574 if (Status
!= CMD_STATUS_SUCCESS
) {
575 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" WLAN_CMD_IBSS_CREATE fail ! \n");
577 BSSvAddMulticastNode(pDevice
);
581 else if (pMgmt
->eCurrMode
== WMAC_MODE_STANDBY
) {
582 if (pMgmt
->eConfigMode
== WMAC_CONFIG_IBSS_STA
||
583 pMgmt
->eConfigMode
== WMAC_CONFIG_AUTO
) {
585 vMgrCreateOwnIBSS((void *)pDevice
, &Status
);
586 if (Status
!= CMD_STATUS_SUCCESS
) {
587 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" WLAN_CMD_IBSS_CREATE fail ! \n");
589 BSSvAddMulticastNode(pDevice
);
590 if (netif_queue_stopped(pDevice
->dev
)) {
591 netif_wake_queue(pDevice
->dev
);
593 pDevice
->bLinkPass
= true;
595 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Disconnect SSID none\n");
596 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
598 union iwreq_data wrqu
;
599 memset(&wrqu
, 0, sizeof(wrqu
));
600 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
601 printk("wireless_send_event--->SIOCGIWAP(disassociated:vMgrJoinBSSBegin Fail !!)\n");
602 wireless_send_event(pDevice
->dev
, SIOCGIWAP
, &wrqu
, NULL
);
608 s_bCommandComplete(pDevice
);
611 case WLAN_AUTHENTICATE_WAIT
:
612 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"eCommandState == WLAN_AUTHENTICATE_WAIT\n");
613 if (pMgmt
->eCurrState
== WMAC_STATE_AUTH
) {
614 // Call mgr to begin the association
615 pDevice
->byLinkWaitCount
= 0;
616 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"eCurrState == WMAC_STATE_AUTH\n");
617 vMgrAssocBeginSta((void *)pDevice
, pMgmt
, &Status
);
618 if (Status
== CMD_STATUS_SUCCESS
) {
619 pDevice
->byLinkWaitCount
= 0;
620 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"eCommandState = WLAN_ASSOCIATE_WAIT\n");
621 pDevice
->eCommandState
= WLAN_ASSOCIATE_WAIT
;
622 vCommandTimerWait((void *)pDevice
, ASSOCIATE_TIMEOUT
);
623 spin_unlock_irq(&pDevice
->lock
);
628 else if (pMgmt
->eCurrState
< WMAC_STATE_AUTHPENDING
) {
629 printk("WLAN_AUTHENTICATE_WAIT:Authen Fail???\n");
630 } else if (pDevice
->byLinkWaitCount
<= 4) { //mike add:wait another 2 sec if authenticated_frame delay!
631 pDevice
->byLinkWaitCount
++;
632 printk("WLAN_AUTHENTICATE_WAIT:wait %d times!!\n", pDevice
->byLinkWaitCount
);
633 spin_unlock_irq(&pDevice
->lock
);
634 vCommandTimerWait((void *)pDevice
, AUTHENTICATE_TIMEOUT
/2);
637 pDevice
->byLinkWaitCount
= 0;
638 s_bCommandComplete(pDevice
);
641 case WLAN_ASSOCIATE_WAIT
:
642 if (pMgmt
->eCurrState
== WMAC_STATE_ASSOC
) {
643 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"eCurrState == WMAC_STATE_ASSOC\n");
644 if (pDevice
->ePSMode
!= WMAC_POWER_CAM
) {
645 PSvEnablePowerSaving((void *)pDevice
, pMgmt
->wListenInterval
);
647 if (pMgmt
->eAuthenMode
>= WMAC_AUTH_WPA
) {
648 KeybRemoveAllKey(&(pDevice
->sKey
), pDevice
->abyBSSID
, pDevice
->PortOffset
);
650 pDevice
->bLinkPass
= true;
651 pDevice
->byLinkWaitCount
= 0;
652 pDevice
->byReAssocCount
= 0;
653 bClearBSSID_SCAN(pDevice
);
654 if (pDevice
->byFOETuning
) {
655 BBvSetFOE(pDevice
->PortOffset
);
656 PSbSendNullPacket(pDevice
);
658 if (netif_queue_stopped(pDevice
->dev
)) {
659 netif_wake_queue(pDevice
->dev
);
662 if (pDevice
->IsTxDataTrigger
) { //TxDataTimer is not triggered at the first time
663 del_timer(&pDevice
->sTimerTxData
);
664 init_timer(&pDevice
->sTimerTxData
);
665 pDevice
->sTimerTxData
.data
= (unsigned long) pDevice
;
666 pDevice
->sTimerTxData
.function
= (TimerFunction
)BSSvSecondTxData
;
667 pDevice
->sTimerTxData
.expires
= RUN_AT(10*HZ
); //10s callback
668 pDevice
->fTxDataInSleep
= false;
669 pDevice
->nTxDataTimeCout
= 0;
672 pDevice
->IsTxDataTrigger
= true;
673 add_timer(&pDevice
->sTimerTxData
);
675 } else if (pMgmt
->eCurrState
< WMAC_STATE_ASSOCPENDING
) {
676 printk("WLAN_ASSOCIATE_WAIT:Association Fail???\n");
677 } else if (pDevice
->byLinkWaitCount
<= 4) { //mike add:wait another 2 sec if associated_frame delay!
678 pDevice
->byLinkWaitCount
++;
679 printk("WLAN_ASSOCIATE_WAIT:wait %d times!!\n", pDevice
->byLinkWaitCount
);
680 spin_unlock_irq(&pDevice
->lock
);
681 vCommandTimerWait((void *)pDevice
, ASSOCIATE_TIMEOUT
/2);
684 pDevice
->byLinkWaitCount
= 0;
686 s_bCommandComplete(pDevice
);
689 case WLAN_CMD_AP_MODE_START
:
690 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"eCommandState == WLAN_CMD_AP_MODE_START\n");
692 if (pMgmt
->eConfigMode
== WMAC_CONFIG_AP
) {
693 del_timer(&pMgmt
->sTimerSecondCallback
);
694 pMgmt
->eCurrState
= WMAC_STATE_IDLE
;
695 pMgmt
->eCurrMode
= WMAC_MODE_STANDBY
;
696 pDevice
->bLinkPass
= false;
697 if (pDevice
->bEnableHostWEP
)
698 BSSvClearNodeDBTable(pDevice
, 1);
700 BSSvClearNodeDBTable(pDevice
, 0);
701 pDevice
->uAssocCount
= 0;
702 pMgmt
->eCurrState
= WMAC_STATE_IDLE
;
703 pDevice
->bFixRate
= false;
705 vMgrCreateOwnIBSS((void *)pDevice
, &Status
);
706 if (Status
!= CMD_STATUS_SUCCESS
) {
707 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" vMgrCreateOwnIBSS fail ! \n");
709 // alway turn off unicast bit
710 MACvRegBitsOff(pDevice
->PortOffset
, MAC_REG_RCR
, RCR_UNICAST
);
711 pDevice
->byRxMode
&= ~RCR_UNICAST
;
712 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"wcmd: rx_mode = %x\n", pDevice
->byRxMode
);
713 BSSvAddMulticastNode(pDevice
);
714 if (netif_queue_stopped(pDevice
->dev
)) {
715 netif_wake_queue(pDevice
->dev
);
717 pDevice
->bLinkPass
= true;
718 add_timer(&pMgmt
->sTimerSecondCallback
);
720 s_bCommandComplete(pDevice
);
723 case WLAN_CMD_TX_PSPACKET_START
:
725 if (pMgmt
->sNodeDBTable
[0].bRxPSPoll
) {
726 while ((skb
= skb_dequeue(&pMgmt
->sNodeDBTable
[0].sTxPSQueue
)) != NULL
) {
727 if (skb_queue_empty(&pMgmt
->sNodeDBTable
[0].sTxPSQueue
)) {
728 pMgmt
->abyPSTxMap
[0] &= ~byMask
[0];
729 pDevice
->bMoreData
= false;
731 pDevice
->bMoreData
= true;
733 if (!device_dma0_xmit(pDevice
, skb
, 0)) {
734 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Multicast ps tx fail \n");
736 pMgmt
->sNodeDBTable
[0].wEnQueueCnt
--;
741 for (ii
= 1; ii
< (MAX_NODE_NUM
+ 1); ii
++) {
742 if (pMgmt
->sNodeDBTable
[ii
].bActive
&&
743 pMgmt
->sNodeDBTable
[ii
].bRxPSPoll
) {
744 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Index=%d Enqueu Cnt= %d\n",
745 ii
, pMgmt
->sNodeDBTable
[ii
].wEnQueueCnt
);
746 while ((skb
= skb_dequeue(&pMgmt
->sNodeDBTable
[ii
].sTxPSQueue
)) != NULL
) {
747 if (skb_queue_empty(&pMgmt
->sNodeDBTable
[ii
].sTxPSQueue
)) {
749 pMgmt
->abyPSTxMap
[pMgmt
->sNodeDBTable
[ii
].wAID
>> 3] &=
750 ~byMask
[pMgmt
->sNodeDBTable
[ii
].wAID
& 7];
751 pDevice
->bMoreData
= false;
753 pDevice
->bMoreData
= true;
755 if (!device_dma0_xmit(pDevice
, skb
, ii
)) {
756 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"sta ps tx fail \n");
758 pMgmt
->sNodeDBTable
[ii
].wEnQueueCnt
--;
759 // check if sta ps enabled, and wait next pspoll.
760 // if sta ps disable, then send all pending buffers.
761 if (pMgmt
->sNodeDBTable
[ii
].bPSEnable
)
764 if (skb_queue_empty(&pMgmt
->sNodeDBTable
[ii
].sTxPSQueue
)) {
766 pMgmt
->abyPSTxMap
[pMgmt
->sNodeDBTable
[ii
].wAID
>> 3] &=
767 ~byMask
[pMgmt
->sNodeDBTable
[ii
].wAID
& 7];
768 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Index=%d PS queue clear \n", ii
);
770 pMgmt
->sNodeDBTable
[ii
].bRxPSPoll
= false;
774 s_bCommandComplete(pDevice
);
777 case WLAN_CMD_RADIO_START
:
778 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"eCommandState == WLAN_CMD_RADIO_START\n");
779 if (pDevice
->bRadioCmd
)
780 CARDbRadioPowerOn(pDevice
);
782 CARDbRadioPowerOff(pDevice
);
784 s_bCommandComplete(pDevice
);
787 case WLAN_CMD_CHECK_BBSENSITIVITY_CHANGE
:
788 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "eCommandState == WLAN_CMD_CHECK_BBSENSITIVITY_START\n");
789 // wait all TD complete
790 if (pDevice
->iTDUsed
[TYPE_AC0DMA
] != 0) {
791 vCommandTimerWait((void *)pDevice
, 10);
792 spin_unlock_irq(&pDevice
->lock
);
795 if (pDevice
->iTDUsed
[TYPE_TXDMA0
] != 0) {
796 vCommandTimerWait((void *)pDevice
, 10);
797 spin_unlock_irq(&pDevice
->lock
);
800 pDevice
->byBBVGACurrent
= pDevice
->byBBVGANew
;
801 BBvSetVGAGainOffset(pDevice
, pDevice
->byBBVGACurrent
);
802 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"SetVGAGainOffset %02X\n", pDevice
->byBBVGACurrent
);
803 s_bCommandComplete(pDevice
);
807 s_bCommandComplete(pDevice
);
811 spin_unlock_irq(&pDevice
->lock
);
822 bool bRadioCmd
= false;
823 //unsigned short wDeAuthenReason = 0;
824 bool bForceSCAN
= true;
825 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
827 pDevice
->eCommandState
= WLAN_CMD_IDLE
;
828 if (pDevice
->cbFreeCmdQueue
== CMD_Q_SIZE
) {
829 //Command Queue Empty
830 pDevice
->bCmdRunning
= false;
833 pDevice
->eCommand
= pDevice
->eCmdQueue
[pDevice
->uCmdDequeueIdx
].eCmd
;
834 pSSID
= (PWLAN_IE_SSID
)pDevice
->eCmdQueue
[pDevice
->uCmdDequeueIdx
].abyCmdDesireSSID
;
835 bRadioCmd
= pDevice
->eCmdQueue
[pDevice
->uCmdDequeueIdx
].bRadioCmd
;
836 bForceSCAN
= pDevice
->eCmdQueue
[pDevice
->uCmdDequeueIdx
].bForceSCAN
;
837 ADD_ONE_WITH_WRAP_AROUND(pDevice
->uCmdDequeueIdx
, CMD_Q_SIZE
);
838 pDevice
->cbFreeCmdQueue
++;
839 pDevice
->bCmdRunning
= true;
840 switch (pDevice
->eCommand
) {
841 case WLAN_CMD_BSSID_SCAN
:
842 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"eCommandState= WLAN_CMD_BSSID_SCAN\n");
843 pDevice
->eCommandState
= WLAN_CMD_SCAN_START
;
844 pMgmt
->uScanChannel
= 0;
845 if (pSSID
->len
!= 0) {
846 memcpy(pMgmt
->abyScanSSID
, pSSID
, WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
+ 1);
848 memset(pMgmt
->abyScanSSID
, 0, WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
+ 1);
851 if ((bForceSCAN == false) && (pDevice->bLinkPass == true)) {
852 if ((pSSID->len == ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len) &&
853 (!memcmp(pSSID->abySSID, ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID, pSSID->len))) {
854 pDevice->eCommandState = WLAN_CMD_IDLE;
860 pDevice
->eCommandState
= WLAN_CMD_SSID_START
;
861 if (pSSID
->len
> WLAN_SSID_MAXLEN
)
862 pSSID
->len
= WLAN_SSID_MAXLEN
;
864 memcpy(pDevice
->pMgmt
->abyDesireSSID
, pSSID
, WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
+ 1);
865 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"eCommandState= WLAN_CMD_SSID_START\n");
867 case WLAN_CMD_DISASSOCIATE
:
868 pDevice
->eCommandState
= WLAN_CMD_DISASSOCIATE_START
;
870 case WLAN_CMD_RX_PSPOLL
:
871 pDevice
->eCommandState
= WLAN_CMD_TX_PSPACKET_START
;
873 case WLAN_CMD_RUN_AP
:
874 pDevice
->eCommandState
= WLAN_CMD_AP_MODE_START
;
877 pDevice
->eCommandState
= WLAN_CMD_RADIO_START
;
878 pDevice
->bRadioCmd
= bRadioCmd
;
880 case WLAN_CMD_CHANGE_BBSENSITIVITY
:
881 pDevice
->eCommandState
= WLAN_CMD_CHECK_BBSENSITIVITY_CHANGE
;
889 vCommandTimerWait((void *)pDevice
, 0);
895 bool bScheduleCommand(
896 void *hDeviceContext
,
898 unsigned char *pbyItem0
901 PSDevice pDevice
= (PSDevice
)hDeviceContext
;
903 if (pDevice
->cbFreeCmdQueue
== 0) {
906 pDevice
->eCmdQueue
[pDevice
->uCmdEnqueueIdx
].eCmd
= eCommand
;
907 pDevice
->eCmdQueue
[pDevice
->uCmdEnqueueIdx
].bForceSCAN
= true;
908 memset(pDevice
->eCmdQueue
[pDevice
->uCmdEnqueueIdx
].abyCmdDesireSSID
, 0 , WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
+ 1);
910 if (pbyItem0
!= NULL
) {
912 case WLAN_CMD_BSSID_SCAN
:
913 memcpy(pDevice
->eCmdQueue
[pDevice
->uCmdEnqueueIdx
].abyCmdDesireSSID
,
914 pbyItem0
, WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
+ 1);
915 pDevice
->eCmdQueue
[pDevice
->uCmdEnqueueIdx
].bForceSCAN
= false;
919 memcpy(pDevice
->eCmdQueue
[pDevice
->uCmdEnqueueIdx
].abyCmdDesireSSID
,
920 pbyItem0
, WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
+ 1);
923 case WLAN_CMD_DISASSOCIATE
:
924 pDevice
->eCmdQueue
[pDevice
->uCmdEnqueueIdx
].bNeedRadioOFF
= *((int *)pbyItem0
);
927 case WLAN_CMD_DEAUTH:
928 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].wDeAuthenReason = *((unsigned short *)pbyItem0);
932 case WLAN_CMD_RX_PSPOLL
:
936 pDevice
->eCmdQueue
[pDevice
->uCmdEnqueueIdx
].bRadioCmd
= *((int *)pbyItem0
);
939 case WLAN_CMD_CHANGE_BBSENSITIVITY
:
940 pDevice
->eCommandState
= WLAN_CMD_CHECK_BBSENSITIVITY_CHANGE
;
948 ADD_ONE_WITH_WRAP_AROUND(pDevice
->uCmdEnqueueIdx
, CMD_Q_SIZE
);
949 pDevice
->cbFreeCmdQueue
--;
951 if (!pDevice
->bCmdRunning
) {
952 s_bCommandComplete(pDevice
);
960 * Clear BSSID_SCAN cmd in CMD Queue
964 * hDeviceContext - Pointer to the adapter
969 * Return Value: true if success; otherwise false
972 bool bClearBSSID_SCAN(
976 PSDevice pDevice
= (PSDevice
)hDeviceContext
;
977 unsigned int uCmdDequeueIdx
= pDevice
->uCmdDequeueIdx
;
980 if ((pDevice
->cbFreeCmdQueue
< CMD_Q_SIZE
) && (uCmdDequeueIdx
!= pDevice
->uCmdEnqueueIdx
)) {
981 for (ii
= 0; ii
< (CMD_Q_SIZE
- pDevice
->cbFreeCmdQueue
); ii
++) {
982 if (pDevice
->eCmdQueue
[uCmdDequeueIdx
].eCmd
== WLAN_CMD_BSSID_SCAN
)
983 pDevice
->eCmdQueue
[uCmdDequeueIdx
].eCmd
= WLAN_CMD_IDLE
;
984 ADD_ONE_WITH_WRAP_AROUND(uCmdDequeueIdx
, CMD_Q_SIZE
);
985 if (uCmdDequeueIdx
== pDevice
->uCmdEnqueueIdx
)
992 //mike add:reset command timer
998 PSDevice pDevice
= (PSDevice
)hDeviceContext
;
1001 del_timer(&pDevice
->sTimerCommand
);
1003 init_timer(&pDevice
->sTimerCommand
);
1004 pDevice
->sTimerCommand
.data
= (unsigned long) pDevice
;
1005 pDevice
->sTimerCommand
.function
= (TimerFunction
)vCommandTimer
;
1006 pDevice
->sTimerCommand
.expires
= RUN_AT(HZ
);
1007 pDevice
->cbFreeCmdQueue
= CMD_Q_SIZE
;
1008 pDevice
->uCmdDequeueIdx
= 0;
1009 pDevice
->uCmdEnqueueIdx
= 0;
1010 pDevice
->eCommandState
= WLAN_CMD_IDLE
;
1011 pDevice
->bCmdRunning
= false;
1012 pDevice
->bCmdClear
= false;
1018 void *hDeviceContext
1021 PSDevice pDevice
= (PSDevice
)hDeviceContext
;
1022 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
1023 pDevice
->nTxDataTimeCout
++;
1025 if (pDevice
->nTxDataTimeCout
< 4) //don't tx data if timer less than 40s
1027 pDevice
->sTimerTxData
.expires
= RUN_AT(10*HZ
); //10s callback
1028 add_timer(&pDevice
->sTimerTxData
);
1032 spin_lock_irq(&pDevice
->lock
);
1034 if ((pDevice
->bLinkPass
&& (pMgmt
->eAuthenMode
< WMAC_AUTH_WPA
)) || //open && sharekey linking
1035 pDevice
->fWPA_Authened
) { //wpa linking
1037 if (pDevice
->bLinkPass
== true) {
1039 pDevice
->fTxDataInSleep
= true;
1040 PSbSendNullPacket(pDevice
); //send null packet
1041 pDevice
->fTxDataInSleep
= false;
1043 spin_unlock_irq(&pDevice
->lock
);
1045 pDevice
->sTimerTxData
.expires
= RUN_AT(10*HZ
); //10s callback
1046 add_timer(&pDevice
->sTimerTxData
);