diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2009-06-19 17:48:32 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-06-19 17:48:32 -0700 |
commit | fb20871a54961b82d35303b43452928186c1361d (patch) | |
tree | 1beeb39e45eda1c8b5893090904b583fceeb07ef /drivers/staging/rt2860/common/mlme.c | |
parent | bee89ab228e6f51c4ddd3481b9bd491859a8ee7b (diff) | |
parent | c7a5d70796379e3d51d0c652fbe1634b81d3bbd5 (diff) |
Merge git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging-2.6
* git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging-2.6: (342 commits)
Staging: comedi: fix build errors
Staging: udlfb: update to version 0.2.3
Staging: udlfb: fix some sparse warnings.
Staging: udlfb: clean up checkpatch warnings in udlfb.c
Staging: udlfb: clean up checkpatch warnings in udlfb.h
Staging: udlfb: add udlfb driver to build
Staging: add udlfb driver
Staging: pata_rdc: remove pointless comments
Staging: pata_rdc: remove DRIVER macros
Staging: pata_rdc: remove dbgprintf macro
Staging: pata_rdc: remove broken flag
Staging: pata_rdc: fix build warnings
Staging: pata_rdc: use PCI_DEVICE
Staging: pata_rdc: remove function prototypes
Staging: pata_rdc: coding style fixes
Staging: pata_rdc: convert code to work in 2.6.29
Staging: pata_rdc: add driver to the build system
Staging: add pata_rdc driver
Staging: remove obsolete serqt_usb driver
Staging: serqt_usb2 add the driver to the build
...
Diffstat (limited to 'drivers/staging/rt2860/common/mlme.c')
-rw-r--r-- | drivers/staging/rt2860/common/mlme.c | 1890 |
1 files changed, 1188 insertions, 702 deletions
diff --git a/drivers/staging/rt2860/common/mlme.c b/drivers/staging/rt2860/common/mlme.c index 2edf2999f5c..bb6fccbdca4 100644 --- a/drivers/staging/rt2860/common/mlme.c +++ b/drivers/staging/rt2860/common/mlme.c @@ -50,11 +50,7 @@ UCHAR Ccx2QosInfo[] = {0x00, 0x40, 0x96, 0x04}; UCHAR RALINK_OUI[] = {0x00, 0x0c, 0x43}; UCHAR BROADCOM_OUI[] = {0x00, 0x90, 0x4c}; UCHAR WPS_OUI[] = {0x00, 0x50, 0xf2, 0x04}; -#ifdef CONFIG_STA_SUPPORT -#ifdef DOT11_N_SUPPORT UCHAR PRE_N_HT_OUI[] = {0x00, 0x90, 0x4c}; -#endif // DOT11_N_SUPPORT // -#endif // CONFIG_STA_SUPPORT // UCHAR RateSwitchTable[] = { // Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF) @@ -130,7 +126,6 @@ UCHAR RateSwitchTable11G[] = { 0x07, 0x10, 7, 10, 13, }; -#ifdef DOT11_N_SUPPORT UCHAR RateSwitchTable11N1S[] = { // Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF) 0x09, 0x00, 0, 0, 0, // Initial used item after association @@ -287,7 +282,6 @@ UCHAR RateSwitchTable11BGN3SForABand[] = { // 3*3 0x0a, 0x20, 23, 8, 25, 0x0b, 0x22, 23, 8, 25, }; -#endif // DOT11_N_SUPPORT // PUCHAR ReasonString[] = { /* 0 */ "Reserved", @@ -334,14 +328,9 @@ USHORT RateIdTo500Kbps[] = { 2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108, 144, UCHAR SsidIe = IE_SSID; UCHAR SupRateIe = IE_SUPP_RATES; UCHAR ExtRateIe = IE_EXT_SUPP_RATES; -#ifdef DOT11_N_SUPPORT UCHAR HtCapIe = IE_HT_CAP; UCHAR AddHtInfoIe = IE_ADD_HT; UCHAR NewExtChanIe = IE_SECONDARY_CH_OFFSET; -#ifdef DOT11N_DRAFT3 -UCHAR ExtHtCapIe = IE_EXT_CAPABILITY; -#endif // DOT11N_DRAFT3 // -#endif // DOT11_N_SUPPORT // UCHAR ErpIe = IE_ERP; UCHAR DsIe = IE_DS_PARM; UCHAR TimIe = IE_TIM; @@ -349,6 +338,9 @@ UCHAR WpaIe = IE_WPA; UCHAR Wpa2Ie = IE_WPA2; UCHAR IbssIe = IE_IBSS_PARM; UCHAR Ccx2Ie = IE_CCX_V2; +#ifdef RT2870 +UCHAR WapiIe = IE_WAPI; +#endif extern UCHAR WPA_OUI[]; @@ -457,7 +449,13 @@ FREQUENCY_ITEM FreqItems3020[] = {13, 247, 2, 2}, {14, 248, 2, 4}, }; +#ifndef RT30xx #define NUM_OF_3020_CHNL (sizeof(FreqItems3020) / sizeof(FREQUENCY_ITEM)) +#endif +#ifdef RT30xx +//2008/07/10:KH Modified to share this variable +UCHAR NUM_OF_3020_CHNL=(sizeof(FreqItems3020) / sizeof(FREQUENCY_ITEM)); +#endif /* ========================================================================== @@ -488,8 +486,6 @@ NDIS_STATUS MlmeInit( pAd->Mlme.bRunning = FALSE; NdisAllocateSpinLock(&pAd->Mlme.TaskLock); -#ifdef CONFIG_STA_SUPPORT - IF_DEV_CONFIG_OPMODE_ON_STA(pAd) { BssTableInit(&pAd->ScanTab); @@ -501,18 +497,10 @@ NDIS_STATUS MlmeInit( WpaPskStateMachineInit(pAd, &pAd->Mlme.WpaPskMachine, pAd->Mlme.WpaPskFunc); AironetStateMachineInit(pAd, &pAd->Mlme.AironetMachine, pAd->Mlme.AironetFunc); -#ifdef QOS_DLS_SUPPORT - DlsStateMachineInit(pAd, &pAd->Mlme.DlsMachine, pAd->Mlme.DlsFunc); -#endif // QOS_DLS_SUPPORT // - - // Since we are using switch/case to implement it, the init is different from the above // state machine init MlmeCntlInit(pAd, &pAd->Mlme.CntlMachine, NULL); } -#endif // CONFIG_STA_SUPPORT // - - ActionStateMachineInit(pAd, &pAd->Mlme.ActMachine, pAd->Mlme.ActFunc); @@ -525,9 +513,7 @@ NDIS_STATUS MlmeInit( // software-based RX Antenna diversity RTMPInitTimer(pAd, &pAd->Mlme.RxAntEvalTimer, GET_TIMER_FUNCTION(AsicRxAntEvalTimeout), pAd, FALSE); - -#ifdef CONFIG_STA_SUPPORT - IF_DEV_CONFIG_OPMODE_ON_STA(pAd) +#ifdef RT2860 { if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_ADVANCE_POWER_SAVE_PCIE_DEVICE)) { @@ -536,8 +522,7 @@ NDIS_STATUS MlmeInit( RTMPInitTimer(pAd, &pAd->Mlme.RadioOnOffTimer, GET_TIMER_FUNCTION(RadioOnExec), pAd, FALSE); } } -#endif // CONFIG_STA_SUPPORT // - +#endif } while (FALSE); DBGPRINT(RT_DEBUG_TRACE, ("<-- MLME Initialize\n")); @@ -563,9 +548,6 @@ VOID MlmeHandler( IN PRTMP_ADAPTER pAd) { MLME_QUEUE_ELEM *Elem = NULL; -#ifdef APCLI_SUPPORT - SHORT apcliIfIndex; -#endif // Only accept MLME and Frame from peer side, no other (control/data) frame should // get into this state machine @@ -592,23 +574,24 @@ VOID MlmeHandler( break; } -#ifdef RALINK_ATE - if(ATE_ON(pAd)) - { - DBGPRINT(RT_DEBUG_TRACE, ("The driver is in ATE mode now in MlmeHandler\n")); - break; - } -#endif // RALINK_ATE // - //From message type, determine which state machine I should drive if (MlmeDequeue(&pAd->Mlme.Queue, &Elem)) { +#ifdef RT2870 + if (Elem->MsgType == MT2_RESET_CONF) + { + DBGPRINT_RAW(RT_DEBUG_TRACE, ("!!! reset MLME state machine !!!\n")); + MlmeRestartStateMachine(pAd); + Elem->Occupied = FALSE; + Elem->MsgLen = 0; + continue; + } +#endif // RT2870 // // if dequeue success switch (Elem->Machine) { // STA state machines -#ifdef CONFIG_STA_SUPPORT case ASSOC_STATE_MACHINE: StateMachinePerformAction(pAd, &pAd->Mlme.AssocMachine, Elem); break; @@ -627,22 +610,9 @@ VOID MlmeHandler( case WPA_PSK_STATE_MACHINE: StateMachinePerformAction(pAd, &pAd->Mlme.WpaPskMachine, Elem); break; -#ifdef LEAP_SUPPORT - case LEAP_STATE_MACHINE: - LeapMachinePerformAction(pAd, &pAd->Mlme.LeapMachine, Elem); - break; -#endif case AIRONET_STATE_MACHINE: StateMachinePerformAction(pAd, &pAd->Mlme.AironetMachine, Elem); break; - -#ifdef QOS_DLS_SUPPORT - case DLS_STATE_MACHINE: - StateMachinePerformAction(pAd, &pAd->Mlme.DlsMachine, Elem); - break; -#endif // QOS_DLS_SUPPORT // -#endif // CONFIG_STA_SUPPORT // - case ACTION_STATE_MACHINE: StateMachinePerformAction(pAd, &pAd->Mlme.ActMachine, Elem); break; @@ -687,6 +657,9 @@ VOID MlmeHalt( IN PRTMP_ADAPTER pAd) { BOOLEAN Cancelled; +#ifdef RT3070 + UINT32 TxPinCfg = 0x00050F0F; +#endif // RT3070 // DBGPRINT(RT_DEBUG_TRACE, ("==> MlmeHalt\n")); @@ -696,12 +669,7 @@ VOID MlmeHalt( AsicDisableSync(pAd); } -#ifdef CONFIG_STA_SUPPORT - IF_DEV_CONFIG_OPMODE_ON_STA(pAd) { -#ifdef QOS_DLS_SUPPORT - UCHAR i; -#endif // QOS_DLS_SUPPORT // // Cancel pending timers RTMPCancelTimer(&pAd->MlmeAux.AssocTimer, &Cancelled); RTMPCancelTimer(&pAd->MlmeAux.ReassocTimer, &Cancelled); @@ -709,20 +677,14 @@ VOID MlmeHalt( RTMPCancelTimer(&pAd->MlmeAux.AuthTimer, &Cancelled); RTMPCancelTimer(&pAd->MlmeAux.BeaconTimer, &Cancelled); RTMPCancelTimer(&pAd->MlmeAux.ScanTimer, &Cancelled); +#ifdef RT2860 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_ADVANCE_POWER_SAVE_PCIE_DEVICE)) { RTMPCancelTimer(&pAd->Mlme.PsPollTimer, &Cancelled); RTMPCancelTimer(&pAd->Mlme.RadioOnOffTimer, &Cancelled); } - -#ifdef QOS_DLS_SUPPORT - for (i=0; i<MAX_NUM_OF_DLS_ENTRY; i++) - { - RTMPCancelTimer(&pAd->StaCfg.DLSEntry[i].Timer, &Cancelled); - } -#endif // QOS_DLS_SUPPORT // +#endif } -#endif // CONFIG_STA_SUPPORT // RTMPCancelTimer(&pAd->Mlme.PeriodicTimer, &Cancelled); RTMPCancelTimer(&pAd->Mlme.RxAntEvalTimer, &Cancelled); @@ -734,6 +696,27 @@ VOID MlmeHalt( // Set LED RTMPSetLED(pAd, LED_HALT); RTMPSetSignalLED(pAd, -100); // Force signal strength Led to be turned off, firmware is not done it. +#ifdef RT2870 + { + LED_CFG_STRUC LedCfg; + RTMP_IO_READ32(pAd, LED_CFG, &LedCfg.word); + LedCfg.field.LedPolar = 0; + LedCfg.field.RLedMode = 0; + LedCfg.field.GLedMode = 0; + LedCfg.field.YLedMode = 0; + RTMP_IO_WRITE32(pAd, LED_CFG, LedCfg.word); + } +#endif // RT2870 // +#ifdef RT3070 + // + // Turn off LNA_PE + // + if (IS_RT3070(pAd) || IS_RT3071(pAd)) + { + TxPinCfg &= 0xFFFFF0F0; + RTUSBWriteMACRegister(pAd, TX_PIN_CFG, TxPinCfg); + } +#endif // RT3070 // } RTMPusecDelay(5000); // 5 msec to gurantee Ant Diversity timer canceled @@ -804,6 +787,7 @@ VOID MlmePeriodicExec( ULONG TxTotalCnt; PRTMP_ADAPTER pAd = (RTMP_ADAPTER *)FunctionContext; +#ifdef RT2860 //Baron 2008/07/10 //printk("Baron_Test:\t%s", RTMPGetRalinkEncryModeStr(pAd->StaCfg.WepStatus)); //If the STA security setting is OPEN or WEP, pAd->StaCfg.WpaSupplicantUP = 0. @@ -817,8 +801,6 @@ VOID MlmePeriodicExec( pAd->StaCfg.WpaSupplicantUP = 1; } -#ifdef CONFIG_STA_SUPPORT - IF_DEV_CONFIG_OPMODE_ON_STA(pAd) { // If Hardware controlled Radio enabled, we have to check GPIO pin2 every 2 second. // Move code to here, because following code will return when radio is off @@ -858,7 +840,7 @@ VOID MlmePeriodicExec( } } } -#endif // CONFIG_STA_SUPPORT // +#endif /* RT2860 */ // Do nothing if the driver is starting halt state. // This might happen when timer already been fired before cancel timer with mlmehalt @@ -868,7 +850,7 @@ VOID MlmePeriodicExec( fRTMP_ADAPTER_RESET_IN_PROGRESS)))) return; - IF_DEV_CONFIG_OPMODE_ON_STA(pAd) +#ifdef RT2860 { if ((pAd->RalinkCounters.LastReceivedByteCount == pAd->RalinkCounters.ReceivedByteCount) && (pAd->StaCfg.bRadio == TRUE)) { @@ -906,23 +888,9 @@ VOID MlmePeriodicExec( AsicResetFromDMABusy(pAd); } } - +#endif /* RT2860 */ RT28XX_MLME_PRE_SANITY_CHECK(pAd); -#ifdef RALINK_ATE - /* Do not show RSSI until "Normal 1 second Mlme PeriodicExec". */ - if (ATE_ON(pAd)) - { - if (pAd->Mlme.PeriodicRound % MLME_TASK_EXEC_MULTIPLE != (MLME_TASK_EXEC_MULTIPLE - 1)) - { - pAd->Mlme.PeriodicRound ++; - return; - } - } -#endif // RALINK_ATE // - -#ifdef CONFIG_STA_SUPPORT - IF_DEV_CONFIG_OPMODE_ON_STA(pAd) { // Do nothing if monitor mode is on if (MONITOR_ON(pAd)) @@ -947,26 +915,26 @@ VOID MlmePeriodicExec( } } } -#endif // CONFIG_STA_SUPPORT // pAd->bUpdateBcnCntDone = FALSE; // RECBATimerTimeout(SystemSpecific1,FunctionContext,SystemSpecific2,SystemSpecific3); pAd->Mlme.PeriodicRound ++; +#ifdef RT3070 + // execute every 100ms, update the Tx FIFO Cnt for update Tx Rate. + NICUpdateFifoStaCounters(pAd); +#endif // RT3070 // // execute every 500ms if ((pAd->Mlme.PeriodicRound % 5 == 0) && RTMPAutoRateSwitchCheck(pAd)/*(OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_TX_RATE_SWITCH_ENABLED))*/) { -#ifdef CONFIG_STA_SUPPORT // perform dynamic tx rate switching based on past TX history - IF_DEV_CONFIG_OPMODE_ON_STA(pAd) { if ((OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED) ) && (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE))) MlmeDynamicTxRateSwitching(pAd); } -#endif // CONFIG_STA_SUPPORT // } // Normal 1 second Mlme PeriodicExec. @@ -974,30 +942,6 @@ VOID MlmePeriodicExec( { pAd->Mlme.OneSecPeriodicRound ++; -#ifdef RALINK_ATE - if (ATE_ON(pAd)) - { - /* request from Baron : move this routine from later to here */ - /* for showing Rx error count in ATE RXFRAME */ - NICUpdateRawCounters(pAd); - if (pAd->ate.bRxFer == 1) - { - pAd->ate.RxTotalCnt += pAd->ate.RxCntPerSec; - ate_print(KERN_EMERG "MlmePeriodicExec: Rx packet cnt = %d/%d\n", pAd->ate.RxCntPerSec, pAd->ate.RxTotalCnt); - pAd->ate.RxCntPerSec = 0; - - if (pAd->ate.RxAntennaSel == 0) - ate_print(KERN_EMERG "MlmePeriodicExec: Rx AvgRssi0=%d, AvgRssi1=%d, AvgRssi2=%d\n\n", - pAd->ate.AvgRssi0, pAd->ate.AvgRssi1, pAd->ate.AvgRssi2); - else - ate_print(KERN_EMERG "MlmePeriodicExec: Rx AvgRssi=%d\n\n", pAd->ate.AvgRssi0); - } - MlmeResetRalinkCounters(pAd); - return; - } -#endif // RALINK_ATE // - - if (rx_Total) { @@ -1029,12 +973,12 @@ VOID MlmePeriodicExec( // the dynamic tuning mechanism below are based on most up-to-date information NICUpdateRawCounters(pAd); +#ifdef RT2870 + RT2870_WatchDog(pAd); +#endif // RT2870 // -#ifdef DOT11_N_SUPPORT // Need statistics after read counter. So put after NICUpdateRawCounters ORIBATimerTimeout(pAd); -#endif // DOT11_N_SUPPORT // - // The time period for checking antenna is according to traffic if (pAd->Mlme.bEnableAutoAntennaCheck) @@ -1043,6 +987,7 @@ VOID MlmePeriodicExec( pAd->RalinkCounters.OneSecTxRetryOkCount + pAd->RalinkCounters.OneSecTxFailCount; + // dynamic adjust antenna evaluation period according to the traffic if (TxTotalCnt > 50) { if (pAd->Mlme.OneSecPeriodicRound % 10 == 0) @@ -1059,17 +1004,14 @@ VOID MlmePeriodicExec( } } -#ifdef CONFIG_STA_SUPPORT - IF_DEV_CONFIG_OPMODE_ON_STA(pAd) - STAMlmePeriodicExec(pAd); -#endif // CONFIG_STA_SUPPORT // + STAMlmePeriodicExec(pAd); MlmeResetRalinkCounters(pAd); -#ifdef CONFIG_STA_SUPPORT - IF_DEV_CONFIG_OPMODE_ON_STA(pAd) { +#ifdef RT2860 if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST) && (pAd->bPCIclkOff == FALSE)) +#endif { // When Adhoc beacon is enabled and RTS/CTS is enabled, there is a chance that hardware MAC FSM will run into a deadlock // and sending CTS-to-self over and over. @@ -1091,41 +1033,32 @@ VOID MlmePeriodicExec( } } } -#endif // CONFIG_STA_SUPPORT // RT28XX_MLME_HANDLER(pAd); } - pAd->bUpdateBcnCntDone = FALSE; } -#ifdef CONFIG_STA_SUPPORT VOID STAMlmePeriodicExec( PRTMP_ADAPTER pAd) { +#ifdef RT2860 ULONG TxTotalCnt; +#endif +#ifdef RT2870 + ULONG TxTotalCnt; + int i; +#endif -// -// We return here in ATE mode, because the statistics -// that ATE needs are not collected via this routine. -// -#ifdef RALINK_ATE - // It is supposed that we will never reach here in ATE mode. - ASSERT(!(ATE_ON(pAd))); - if (ATE_ON(pAd)) - return; -#endif // RALINK_ATE // - -#ifdef WPA_SUPPLICANT_SUPPORT if (pAd->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_DISABLE) -#endif // WPA_SUPPLICANT_SUPPORT // { // WPA MIC error should block association attempt for 60 seconds if (pAd->StaCfg.bBlockAssoc && (pAd->StaCfg.LastMicErrorTime + (60 * OS_HZ) < pAd->Mlme.Now32)) pAd->StaCfg.bBlockAssoc = FALSE; } +#ifdef RT2860 //Baron 2008/07/10 //printk("Baron_Test:\t%s", RTMPGetRalinkEncryModeStr(pAd->StaCfg.WepStatus)); //If the STA security setting is OPEN or WEP, pAd->StaCfg.WpaSupplicantUP = 0. @@ -1138,6 +1071,7 @@ VOID STAMlmePeriodicExec( { pAd->StaCfg.WpaSupplicantUP = 1; } +#endif if ((pAd->PreMediaState != pAd->IndicateMediaState) && (pAd->CommonCfg.bWirelessEvent)) { @@ -1148,6 +1082,7 @@ VOID STAMlmePeriodicExec( pAd->PreMediaState = pAd->IndicateMediaState; } +#ifdef RT2860 if ((pAd->OpMode == OPMODE_STA) && (IDLE_ON(pAd)) && (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_ADVANCE_POWER_SAVE_PCIE_DEVICE)) && (pAd->Mlme.SyncMachine.CurrState == SYNC_IDLE) && @@ -1157,6 +1092,7 @@ VOID STAMlmePeriodicExec( { RT28xxPciAsicRadioOff(pAd, GUI_IDLE_POWER_SAVE, 0); } +#endif @@ -1179,11 +1115,6 @@ VOID STAMlmePeriodicExec( if (INFRA_ON(pAd)) { -#ifdef QOS_DLS_SUPPORT - // Check DLS time out, then tear down those session - RTMPCheckDLSTimeOut(pAd); -#endif // QOS_DLS_SUPPORT // - // Is PSM bit consistent with user power management policy? // This is the only place that will set PSM bit ON. if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE)) @@ -1228,26 +1159,11 @@ VOID STAMlmePeriodicExec( // Lost AP, send disconnect & link down event LinkDown(pAd, FALSE); -#ifdef WPA_SUPPLICANT_SUPPORT -#ifndef NATIVE_WPA_SUPPLICANT_SUPPORT - if (pAd->StaCfg.WpaSupplicantUP) - { - union iwreq_data wrqu; - //send disassociate event to wpa_supplicant - memset(&wrqu, 0, sizeof(wrqu)); - wrqu.data.flags = RT_DISASSOC_EVENT_FLAG; - wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, NULL); - } -#endif // NATIVE_WPA_SUPPLICANT_SUPPORT // -#endif // WPA_SUPPLICANT_SUPPORT // - -#ifdef NATIVE_WPA_SUPPLICANT_SUPPORT { union iwreq_data wrqu; memset(wrqu.ap_addr.sa_data, 0, MAC_ADDR_LEN); wireless_send_event(pAd->net_dev, SIOCGIWAP, &wrqu, NULL); } -#endif // NATIVE_WPA_SUPPLICANT_SUPPORT // MlmeAutoReconnectLastSSID(pAd); } @@ -1273,6 +1189,7 @@ VOID STAMlmePeriodicExec( } else if (ADHOC_ON(pAd)) { +#ifdef RT2860 // 2003-04-17 john. this is a patch that driver forces a BEACON out if ASIC fails // the "TX BEACON competition" for the entire past 1 sec. // So that even when ASIC's BEACONgen engine been blocked @@ -1297,7 +1214,6 @@ VOID STAMlmePeriodicExec( pAd->StaCfg.AdhocBOnlyJoined = FALSE; } -#ifdef DOT11_N_SUPPORT if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED) { if ((pAd->StaCfg.AdhocBGJoined) && @@ -1314,7 +1230,7 @@ VOID STAMlmePeriodicExec( pAd->StaCfg.Adhoc20NJoined = FALSE; } } -#endif // DOT11_N_SUPPORT // +#endif /* RT2860 */ //radar detect if ((pAd->CommonCfg.Channel > 14) @@ -1339,6 +1255,19 @@ VOID STAMlmePeriodicExec( MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_START_REQ, sizeof(MLME_START_REQ_STRUCT), &StartReq); pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_START; } + +#ifdef RT2870 + for (i = 1; i < MAX_LEN_OF_MAC_TABLE; i++) + { + MAC_TABLE_ENTRY *pEntry = &pAd->MacTab.Content[i]; + + if (pEntry->ValidAsCLI == FALSE) + continue; + + if (pEntry->LastBeaconRxTime + ADHOC_BEACON_LOST_TIME < pAd->Mlme.Now32) + MacTableDeleteEntry(pAd, pEntry->Aid, pEntry->Addr); + } +#endif } else // no INFRA nor ADHOC connection { @@ -1378,14 +1307,6 @@ VOID STAMlmePeriodicExec( } else { -#ifdef CARRIER_DETECTION_SUPPORT // Roger sync Carrier - if (pAd->CommonCfg.CarrierDetect.Enable == TRUE) - { - if ((pAd->Mlme.OneSecPeriodicRound % 5) == 1) - MlmeAutoReconnectLastSSID(pAd); - } - else -#endif // CARRIER_DETECTION_SUPPORT // MlmeAutoReconnectLastSSID(pAd); } } @@ -1394,7 +1315,6 @@ VOID STAMlmePeriodicExec( SKIP_AUTO_SCAN_CONN: -#ifdef DOT11_N_SUPPORT if ((pAd->MacTab.Content[BSSID_WCID].TXBAbitmap !=0) && (pAd->MacTab.fAnyBASession == FALSE)) { pAd->MacTab.fAnyBASession = TRUE; @@ -1405,15 +1325,6 @@ SKIP_AUTO_SCAN_CONN: pAd->MacTab.fAnyBASession = FALSE; AsicUpdateProtect(pAd, pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode, ALLN_SETPROTECT, FALSE, FALSE); } -#endif // DOT11_N_SUPPORT // - - -#ifdef DOT11_N_SUPPORT -#ifdef DOT11N_DRAFT3 - if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_SCAN_2040)) - TriEventCounterMaintenance(pAd); -#endif // DOT11N_DRAFT3 // -#endif // DOT11_N_SUPPORT // return; } @@ -1473,7 +1384,6 @@ VOID MlmeAutoReconnectLastSSID( RT28XX_MLME_HANDLER(pAd); } } -#endif // CONFIG_STA_SUPPORT // /* ========================================================================== @@ -1522,15 +1432,19 @@ VOID MlmeSelectTxRateTable( break; } -#ifdef CONFIG_STA_SUPPORT if ((pAd->OpMode == OPMODE_STA) && ADHOC_ON(pAd)) { -#ifdef DOT11_N_SUPPORT if ((pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED) && +#ifdef RT2860 !pAd->StaCfg.AdhocBOnlyJoined && !pAd->StaCfg.AdhocBGJoined && (pAd->StaActive.SupportedPhyInfo.MCSSet[0] == 0xff) && ((pAd->StaActive.SupportedPhyInfo.MCSSet[1] == 0x00) || (pAd->Antenna.field.TxPath == 1))) +#endif +#ifdef RT2870 + (pEntry->HTCapability.MCSSet[0] == 0xff) && + ((pEntry->HTCapability.MCSSet[1] == 0x00) || (pAd->Antenna.field.TxPath == 1))) +#endif {// 11N 1S Adhoc *ppTable = RateSwitchTable11N1S; *pTableSize = RateSwitchTable11N1S[0]; @@ -1538,10 +1452,16 @@ VOID MlmeSelectTxRateTable( } else if ((pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED) && +#ifdef RT2860 !pAd->StaCfg.AdhocBOnlyJoined && !pAd->StaCfg.AdhocBGJoined && (pAd->StaActive.SupportedPhyInfo.MCSSet[0] == 0xff) && (pAd->StaActive.SupportedPhyInfo.MCSSet[1] == 0xff) && +#endif +#ifdef RT2870 + (pEntry->HTCapability.MCSSet[0] == 0xff) && + (pEntry->HTCapability.MCSSet[1] == 0xff) && +#endif (pAd->Antenna.field.TxPath == 2)) {// 11N 2S Adhoc if (pAd->LatchRfRegs.Channel <= 14) @@ -1559,7 +1479,7 @@ VOID MlmeSelectTxRateTable( } else -#endif // DOT11_N_SUPPORT // +#ifdef RT2860 if (pAd->CommonCfg.PhyMode == PHY_11B) { *ppTable = RateSwitchTable11B; @@ -1568,6 +1488,12 @@ VOID MlmeSelectTxRateTable( } else if((pAd->LatchRfRegs.Channel <= 14) && (pAd->StaCfg.AdhocBOnlyJoined == TRUE)) +#endif +#ifdef RT2870 + if ((pEntry->RateLen == 4) + && (pEntry->HTCapability.MCSSet[0] == 0) && (pEntry->HTCapability.MCSSet[1] == 0) + ) +#endif { // USe B Table when Only b-only Station in my IBSS . *ppTable = RateSwitchTable11B; @@ -1591,9 +1517,7 @@ VOID MlmeSelectTxRateTable( } break; } -#endif // CONFIG_STA_SUPPORT // -#ifdef DOT11_N_SUPPORT if ((pEntry->RateLen == 12) && (pEntry->HTCapability.MCSSet[0] == 0xff) && ((pEntry->HTCapability.MCSSet[1] == 0x00) || (pAd->CommonCfg.TxStream == 1))) {// 11BGN 1S AP @@ -1650,12 +1574,13 @@ VOID MlmeSelectTxRateTable( break; } -#endif // DOT11_N_SUPPORT // + //else if ((pAd->StaActive.SupRateLen == 4) && (pAd->StaActive.ExtRateLen == 0) && (pAd->StaActive.SupportedPhyInfo.MCSSet[0] == 0) && (pAd->StaActive.SupportedPhyInfo.MCSSet[1] == 0)) if ((pEntry->RateLen == 4) -#ifdef DOT11_N_SUPPORT +#ifndef RT30xx +//Iverson mark for Adhoc b mode,sta will use rate 54 Mbps when connect with sta b/g/n mode && (pEntry->HTCapability.MCSSet[0] == 0) && (pEntry->HTCapability.MCSSet[1] == 0) -#endif // DOT11_N_SUPPORT // +#endif ) {// B only AP *ppTable = RateSwitchTable11B; @@ -1667,9 +1592,7 @@ VOID MlmeSelectTxRateTable( //else if ((pAd->StaActive.SupRateLen + pAd->StaActive.ExtRateLen > 8) && (pAd->StaActive.SupportedPhyInfo.MCSSet[0] == 0) && (pAd->StaActive.SupportedPhyInfo.MCSSet[1] == 0)) if ((pEntry->RateLen > 8) -#ifdef DOT11_N_SUPPORT && (pEntry->HTCapability.MCSSet[0] == 0) && (pEntry->HTCapability.MCSSet[1] == 0) -#endif // DOT11_N_SUPPORT // ) {// B/G mixed AP *ppTable = RateSwitchTable11BG; @@ -1681,9 +1604,7 @@ VOID MlmeSelectTxRateTable( //else if ((pAd->StaActive.SupRateLen + pAd->StaActive.ExtRateLen == 8) && (pAd->StaActive.SupportedPhyInfo.MCSSet[0] == 0) && (pAd->StaActive.SupportedPhyInfo.MCSSet[1] == 0)) if ((pEntry->RateLen == 8) -#ifdef DOT11_N_SUPPORT && (pEntry->HTCapability.MCSSet[0] == 0) && (pEntry->HTCapability.MCSSet[1] == 0) -#endif // DOT11_N_SUPPORT // ) {// G only AP *ppTable = RateSwitchTable11G; @@ -1692,16 +1613,10 @@ VOID MlmeSelectTxRateTable( break; } -#ifdef DOT11_N_SUPPORT -#endif // DOT11_N_SUPPORT // -#ifdef CONFIG_STA_SUPPORT - IF_DEV_CONFIG_OPMODE_ON_STA(pAd) { -#ifdef DOT11_N_SUPPORT //else if ((pAd->StaActive.SupportedPhyInfo.MCSSet[0] == 0) && (pAd->StaActive.SupportedPhyInfo.MCSSet[1] == 0)) if ((pEntry->HTCapability.MCSSet[0] == 0) && (pEntry->HTCapability.MCSSet[1] == 0)) -#endif // DOT11_N_SUPPORT // { // Legacy mode if (pAd->CommonCfg.MaxTxRate <= RATE_11) { @@ -1724,7 +1639,7 @@ VOID MlmeSelectTxRateTable( } break; } -#ifdef DOT11_N_SUPPORT + if (pAd->LatchRfRegs.Channel <= 14) { if (pAd->CommonCfg.TxStream == 1) @@ -1759,15 +1674,13 @@ VOID MlmeSelectTxRateTable( DBGPRINT_RAW(RT_DEBUG_ERROR,("DRS: unkown mode,default use 11N 2S AP \n")); } } -#endif // DOT11_N_SUPPORT // + DBGPRINT_RAW(RT_DEBUG_ERROR,("DRS: unkown mode (SupRateLen=%d, ExtRateLen=%d, MCSSet[0]=0x%x, MCSSet[1]=0x%x)\n", pAd->StaActive.SupRateLen, pAd->StaActive.ExtRateLen, pAd->StaActive.SupportedPhyInfo.MCSSet[0], pAd->StaActive.SupportedPhyInfo.MCSSet[1])); } -#endif // CONFIG_STA_SUPPORT // } while(FALSE); } -#ifdef CONFIG_STA_SUPPORT /* ========================================================================== Description: @@ -1921,14 +1834,6 @@ VOID MlmeCalculateChannelQuality( CHAR MaxRssi; ULONG BeaconLostTime = BEACON_LOST_TIME; -#ifdef CARRIER_DETECTION_SUPPORT // Roger sync Carrier - // longer beacon lost time when carrier detection enabled - if (pAd->CommonCfg.CarrierDetect.Enable == TRUE) - { - BeaconLostTime = BEACON_LOST_TIME + BEACON_LOST_TIME/2; - } -#endif // CARRIER_DETECTION_SUPPORT // - MaxRssi = RTMPMaxRssi(pAd, pAd->StaCfg.RssiSample.LastRssi0, pAd->StaCfg.RssiSample.LastRssi1, pAd->StaCfg.RssiSample.LastRssi2); // @@ -1993,13 +1898,11 @@ VOID MlmeSetTxRate( { UCHAR MaxMode = MODE_OFDM; -#ifdef DOT11_N_SUPPORT MaxMode = MODE_HTGREENFIELD; if (pTxRate->STBC && (pAd->StaCfg.MaxHTPhyMode.field.STBC) && (pAd->Antenna.field.TxPath == 2)) pAd->StaCfg.HTPhyMode.field.STBC = STBC_USE; else -#endif // DOT11_N_SUPPORT // pAd->StaCfg.HTPhyMode.field.STBC = STBC_NONE; if (pTxRate->CurrMCS < MCS_AUTO) @@ -2029,14 +1932,11 @@ VOID MlmeSetTxRate( if (pTxRate->Mode <= MaxMode) pAd->StaCfg.HTPhyMode.field.MODE = pTxRate->Mode; -#ifdef DOT11_N_SUPPORT if (pTxRate->ShortGI && (pAd->StaCfg.MaxHTPhyMode.field.ShortGI)) pAd->StaCfg.HTPhyMode.field.ShortGI = GI_400; else -#endif // DOT11_N_SUPPORT // pAd->StaCfg.HTPhyMode.field.ShortGI = GI_800; -#ifdef DOT11_N_SUPPORT // Reexam each bandwidth's SGI support. if (pAd->StaCfg.HTPhyMode.field.ShortGI == GI_400) { @@ -2080,17 +1980,15 @@ VOID MlmeSetTxRate( { AsicUpdateProtect(pAd, HT_RTSCTS_6M, ALLN_SETPROTECT, TRUE, (BOOLEAN)pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent); } -#endif // DOT11_N_SUPPORT // pEntry->HTPhyMode.field.STBC = pAd->StaCfg.HTPhyMode.field.STBC; pEntry->HTPhyMode.field.ShortGI = pAd->StaCfg.HTPhyMode.field.ShortGI; pEntry->HTPhyMode.field.MCS = pAd->StaCfg.HTPhyMode.field.MCS; pEntry->HTPhyMode.field.MODE = pAd->StaCfg.HTPhyMode.field.MODE; -#ifdef DOT11_N_SUPPORT + if ((pAd->StaCfg.MaxHTPhyMode.field.MODE == MODE_HTGREENFIELD) && pAd->WIFItestbed.bGreenField) pEntry->HTPhyMode.field.MODE = MODE_HTGREENFIELD; -#endif // DOT11_N_SUPPORT // } pAd->LastTxRate = (USHORT)(pEntry->HTPhyMode.word); @@ -2130,18 +2028,6 @@ VOID MlmeDynamicTxRateSwitching( ULONG TxRetransmit = 0, TxSuccess = 0, TxFailCount = 0; MAC_TABLE_ENTRY *pEntry; -#ifdef RALINK_ATE - if (ATE_ON(pAd)) - { - return; - } -#endif // RALINK_ATE // - - /*if (pAd->Antenna.field.RxPath > 1) - Rssi = (pAd->StaCfg.RssiSample.AvgRssi0 + pAd->StaCfg.RssiSample.AvgRssi1) >> 1; - else - Rssi = pAd->StaCfg.RssiSample.AvgRssi0;*/ - // // walk through MAC table, see if need to change AP's TX rate toward each entry // @@ -2155,7 +2041,15 @@ VOID MlmeDynamicTxRateSwitching( if ((pAd->MacTab.Size == 1) || (pEntry->ValidAsDls)) { +#ifdef RT2860 Rssi = RTMPMaxRssi(pAd, (CHAR)pAd->StaCfg.RssiSample.AvgRssi0, (CHAR)pAd->StaCfg.RssiSample.AvgRssi1, (CHAR)pAd->StaCfg.RssiSample.AvgRssi2); +#endif +#ifdef RT2870 + Rssi = RTMPMaxRssi(pAd, + pAd->StaCfg.RssiSample.AvgRssi0, + pAd->StaCfg.RssiSample.AvgRssi1, + pAd->StaCfg.RssiSample.AvgRssi2); +#endif // Update statistic counter RTMP_IO_READ32(pAd, TX_STA_CNT0, &TxStaCnt0.word); @@ -2185,7 +2079,21 @@ VOID MlmeDynamicTxRateSwitching( } else { +#ifdef RT2860 Rssi = RTMPMaxRssi(pAd, (CHAR)pEntry->RssiSample.AvgRssi0, (CHAR)pEntry->RssiSample.AvgRssi1, (CHAR)pEntry->RssiSample.AvgRssi2); +#endif +#ifdef RT2870 + if (INFRA_ON(pAd) && (i == 1)) + Rssi = RTMPMaxRssi(pAd, + pAd->StaCfg.RssiSample.AvgRssi0, + pAd->StaCfg.RssiSample.AvgRssi1, + pAd->StaCfg.RssiSample.AvgRssi2); + else + Rssi = RTMPMaxRssi(pAd, + pEntry->RssiSample.AvgRssi0, + pEntry->RssiSample.AvgRssi1, + pEntry->RssiSample.AvgRssi2); +#endif TxTotalCnt = pEntry->OneSecTxNoRetryOkCount + pEntry->OneSecTxRetryOkCount + @@ -2242,14 +2150,12 @@ VOID MlmeDynamicTxRateSwitching( pCurrTxRate = (PRTMP_TX_RATE_SWITCH) &pTable[(CurrRateIdx+1)*5]; -#ifdef DOT11_N_SUPPORT if ((Rssi > -65) && (pCurrTxRate->Mode >= MODE_HTMIX)) { TrainUp = (pCurrTxRate->TrainUp + (pCurrTxRate->TrainUp >> 1)); TrainDown = (pCurrTxRate->TrainDown + (pCurrTxRate->TrainDown >> 1)); } else -#endif // DOT11_N_SUPPORT // { TrainUp = pCurrTxRate->TrainUp; TrainDown = pCurrTxRate->TrainDown; @@ -2327,7 +2233,6 @@ VOID MlmeDynamicTxRateSwitching( { MCS14 = idx; } - //else if ((pCurrTxRate->CurrMCS == MCS_15)/* && (pCurrTxRate->ShortGI == GI_800)*/) //we hope to use ShortGI as initial rate else if ((pCurrTxRate->CurrMCS == MCS_15) && (pCurrTxRate->ShortGI == GI_800)) //we hope to use ShortGI as initial rate, however Atheros's chip has bugs when short GI { MCS15 = idx; @@ -2373,7 +2278,7 @@ VOID MlmeDynamicTxRateSwitching( RssiOffset = 8; } } -#ifdef DOT11_N_SUPPORT + /*if (MCS15)*/ if ((pTable == RateSwitchTable11BGN3S) || (pTable == RateSwitchTable11N3S) || @@ -2439,7 +2344,6 @@ VOID MlmeDynamicTxRateSwitching( TxRateIdx = MCS0; } else -#endif // DOT11_N_SUPPORT // {// Legacy mode if (MCS7 && (Rssi > -70)) TxRateIdx = MCS7; @@ -2613,7 +2517,12 @@ VOID StaQuickResponeForRateUpExec( UCHAR UpRateIdx = 0, DownRateIdx = 0, CurrRateIdx = 0; ULONG TxTotalCnt; ULONG TxErrorRatio = 0; +#ifdef RT2860 BOOLEAN bTxRateChanged = TRUE; //, bUpgradeQuality = FALSE; +#endif +#ifdef RT2870 + BOOLEAN bTxRateChanged; //, bUpgradeQuality = FALSE; +#endif PRTMP_TX_RATE_SWITCH pCurrTxRate, pNextTxRate = NULL; PUCHAR pTable; UCHAR TableSize = 0; @@ -2638,11 +2547,25 @@ VOID StaQuickResponeForRateUpExec( if (RTMPCheckEntryEnableAutoRateSwitch(pAd, pEntry) == FALSE) continue; +#ifdef RT2860 //Rssi = RTMPMaxRssi(pAd, (CHAR)pAd->StaCfg.AvgRssi0, (CHAR)pAd->StaCfg.AvgRssi1, (CHAR)pAd->StaCfg.AvgRssi2); if (pAd->Antenna.field.TxPath > 1) Rssi = (pAd->StaCfg.RssiSample.AvgRssi0 + pAd->StaCfg.RssiSample.AvgRssi1) >> 1; else Rssi = pAd->StaCfg.RssiSample.AvgRssi0; +#endif +#ifdef RT2870 + if (INFRA_ON(pAd) && (i == 1)) + Rssi = RTMPMaxRssi(pAd, + pAd->StaCfg.RssiSample.AvgRssi0, + pAd->StaCfg.RssiSample.AvgRssi1, + pAd->StaCfg.RssiSample.AvgRssi2); + else + Rssi = RTMPMaxRssi(pAd, + pEntry->RssiSample.AvgRssi0, + pEntry->RssiSample.AvgRssi1, + pEntry->RssiSample.AvgRssi2); +#endif CurrRateIdx = pAd->CommonCfg.TxRateIndex; @@ -2667,14 +2590,12 @@ VOID StaQuickResponeForRateUpExec( pCurrTxRate = (PRTMP_TX_RATE_SWITCH) &pTable[(CurrRateIdx+1)*5]; -#ifdef DOT11_N_SUPPORT if ((Rssi > -65) && (pCurrTxRate->Mode >= MODE_HTMIX)) { TrainUp = (pCurrTxRate->TrainUp + (pCurrTxRate->TrainUp >> 1)); TrainDown = (pCurrTxRate->TrainDown + (pCurrTxRate->TrainDown >> 1)); } else -#endif // DOT11_N_SUPPORT // { TrainUp = pCurrTxRate->TrainUp; TrainDown = pCurrTxRate->TrainDown; @@ -2784,6 +2705,9 @@ VOID StaQuickResponeForRateUpExec( pAd->DrsCounters.TxRateUpPenalty = 0; NdisZeroMemory(pAd->DrsCounters.TxQuality, sizeof(USHORT) * MAX_STEP_OF_TX_RATE_SWITCH); NdisZeroMemory(pAd->DrsCounters.PER, sizeof(UCHAR) * MAX_STEP_OF_TX_RATE_SWITCH); +#ifdef RT2870 + bTxRateChanged = TRUE; +#endif } // if rate-down happen, only clear DownRate's bad history else if (pAd->CommonCfg.TxRateIndex < CurrRateIdx) @@ -2793,6 +2717,9 @@ VOID StaQuickResponeForRateUpExec( pAd->DrsCounters.TxRateUpPenalty = 0; // no penalty pAd->DrsCounters.TxQuality[pAd->CommonCfg.TxRateIndex] = 0; pAd->DrsCounters.PER[pAd->CommonCfg.TxRateIndex] = 0; +#ifdef RT2870 + bTxRateChanged = TRUE; +#endif } else { @@ -2848,7 +2775,13 @@ VOID MlmeCheckPsmChange( if (INFRA_ON(pAd) && (PowerMode != Ndis802_11PowerModeCAM) && (pAd->StaCfg.Psm == PWR_ACTIVE) && +#ifdef RT2860 RTMP_TEST_PSFLAG(pAd, fRTMP_PS_CAN_GO_SLEEP)) +#endif +#if !defined(RT2860) && !defined(RT30xx) + (pAd->Mlme.CntlMachine.CurrState == CNTL_IDLE)) +#endif +#ifndef RT30xx { NdisGetSystemUpTime(&pAd->Mlme.LastSendNULLpsmTime); pAd->RalinkCounters.RxCountSinceLastNULL = 0; @@ -2862,6 +2795,42 @@ VOID MlmeCheckPsmChange( RTMPSendNullFrame(pAd, pAd->CommonCfg.TxRate, TRUE); } } +#endif +#ifdef RT30xx +// (! RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) + (pAd->Mlme.CntlMachine.CurrState == CNTL_IDLE) /*&& + (pAd->RalinkCounters.OneSecTxNoRetryOkCount == 0) && + (pAd->RalinkCounters.OneSecTxRetryOkCount == 0)*/) + { + // add by johnli, use Rx OK data count per second to calculate throughput + // If Ttraffic is too high ( > 400 Rx per second), don't go to sleep mode. If tx rate is low, use low criteria + // Mode=CCK/MCS=3 => 11 Mbps, Mode=OFDM/MCS=3 => 18 Mbps + if (((pAd->StaCfg.HTPhyMode.field.MCS <= 3) && +/* Iverson mark + (pAd->StaCfg.HTPhyMode.field.MODE <= MODE_OFDM) && +*/ + (pAd->RalinkCounters.OneSecRxOkDataCnt < (ULONG)100)) || + ((pAd->StaCfg.HTPhyMode.field.MCS > 3) && +/* Iverson mark + (pAd->StaCfg.HTPhyMode.field.MODE > MODE_OFDM) && +*/ + (pAd->RalinkCounters.OneSecRxOkDataCnt < (ULONG)400))) + { + // Get this time + NdisGetSystemUpTime(&pAd->Mlme.LastSendNULLpsmTime); + pAd->RalinkCounters.RxCountSinceLastNULL = 0; + MlmeSetPsmBit(pAd, PWR_SAVE); + if (!(pAd->CommonCfg.bAPSDCapable && pAd->CommonCfg.APEdcaParm.bAPSDCapable)) + { + RTMPSendNullFrame(pAd, pAd->CommonCfg.TxRate, FALSE); + } + else + { + RTMPSendNullFrame(pAd, pAd->CommonCfg.TxRate, TRUE); + } + } + } +#endif } // IRQL = PASSIVE_LEVEL @@ -2876,10 +2845,10 @@ VOID MlmeSetPsmBit( RTMP_IO_READ32(pAd, AUTO_RSP_CFG, &csr4.word); csr4.field.AckCtsPsmBit = (psm == PWR_SAVE)? 1:0; RTMP_IO_WRITE32(pAd, AUTO_RSP_CFG, csr4.word); +#ifndef RT30xx DBGPRINT(RT_DEBUG_TRACE, ("MlmeSetPsmBit = %d\n", psm)); +#endif } -#endif // CONFIG_STA_SUPPORT // - // IRQL = DISPATCH_LEVEL VOID MlmeSetTxPreamble( @@ -3018,9 +2987,6 @@ VOID MlmeUpdateTxRates( //=========================================================================== //=========================================================================== - -#ifdef CONFIG_STA_SUPPORT - IF_DEV_CONFIG_OPMODE_ON_STA(pAd) { pHtPhy = &pAd->StaCfg.HTPhyMode; pMaxHtPhy = &pAd->StaCfg.MaxHTPhyMode; @@ -3036,7 +3002,6 @@ VOID MlmeUpdateTxRates( MaxDesire = RATE_11; } } -#endif // CONFIG_STA_SUPPORT // pAd->CommonCfg.MaxDesiredRate = MaxDesire; pMinHtPhy->word = 0; @@ -3065,7 +3030,6 @@ VOID MlmeUpdateTxRates( } #endif -#ifdef CONFIG_STA_SUPPORT if ((ADHOC_ON(pAd) || INFRA_ON(pAd)) && (pAd->OpMode == OPMODE_STA)) { pSupRate = &pAd->StaActive.SupRate[0]; @@ -3074,7 +3038,6 @@ VOID MlmeUpdateTxRates( ExtRateLen = pAd->StaActive.ExtRateLen; } else -#endif // CONFIG_STA_SUPPORT // { pSupRate = &pAd->CommonCfg.SupRate[0]; pExtRate = &pAd->CommonCfg.ExtRate[0]; @@ -3151,10 +3114,9 @@ VOID MlmeUpdateTxRates( if (*auto_rate_cur_p) { short dbm = 0; -#ifdef CONFIG_STA_SUPPORT - IF_DEV_CONFIG_OPMODE_ON_STA(pAd) - dbm = pAd->StaCfg.RssiSample.AvgRssi0 - pAd->BbpRssiToDbmDelta; -#endif // CONFIG_STA_SUPPORT // + + dbm = pAd->StaCfg.RssiSample.AvgRssi0 - pAd->BbpRssiToDbmDelta; + if (bLinkUp == TRUE) pAd->CommonCfg.TxRate = RATE_24; else @@ -3212,9 +3174,7 @@ VOID MlmeUpdateTxRates( { case PHY_11BG_MIXED: case PHY_11B: -#ifdef DOT11_N_SUPPORT case PHY_11BGN_MIXED: -#endif // DOT11_N_SUPPORT // pAd->CommonCfg.MlmeRate = RATE_1; pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_CCK; pAd->CommonCfg.MlmeTransmit.field.MCS = RATE_1; @@ -3222,22 +3182,18 @@ VOID MlmeUpdateTxRates( break; case PHY_11G: case PHY_11A: -#ifdef DOT11_N_SUPPORT case PHY_11AGN_MIXED: case PHY_11GN_MIXED: case PHY_11N_2_4G: case PHY_11AN_MIXED: case PHY_11N_5G: -#endif // DOT11_N_SUPPORT // pAd->CommonCfg.MlmeRate = RATE_6; pAd->CommonCfg.RtsRate = RATE_6; pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_OFDM; pAd->CommonCfg.MlmeTransmit.field.MCS = OfdmRateToRxwiMCS[pAd->CommonCfg.MlmeRate]; break; case PHY_11ABG_MIXED: -#ifdef DOT11_N_SUPPORT case PHY_11ABGN_MIXED: -#endif // DOT11_N_SUPPORT // if (pAd->CommonCfg.Channel <= 14) { pAd->CommonCfg.MlmeRate = RATE_1; @@ -3280,7 +3236,6 @@ VOID MlmeUpdateTxRates( pAd->CommonCfg.MlmeTransmit.word, pAd->MacTab.Content[BSSID_WCID].MinHTPhyMode.word ,pAd->MacTab.Content[BSSID_WCID].MaxHTPhyMode.word ,pAd->MacTab.Content[BSSID_WCID].HTPhyMode.word )); } -#ifdef DOT11_N_SUPPORT /* ========================================================================== Description: @@ -3313,8 +3268,6 @@ VOID MlmeUpdateHtTxRates( auto_rate_cur_p = NULL; -#ifdef CONFIG_STA_SUPPORT - IF_DEV_CONFIG_OPMODE_ON_STA(pAd) { pDesireHtPhy = &pAd->StaCfg.DesiredHtPhyInfo; pActiveHtPhy = &pAd->StaCfg.DesiredHtPhyInfo; @@ -3324,9 +3277,7 @@ VOID MlmeUpdateHtTxRates( auto_rate_cur_p = &pAd->StaCfg.bAutoTxRateSwitch; } -#endif // CONFIG_STA_SUPPORT // -#ifdef CONFIG_STA_SUPPORT if ((ADHOC_ON(pAd) || INFRA_ON(pAd)) && (pAd->OpMode == OPMODE_STA)) { if (pAd->StaActive.SupportedPhyInfo.bHtEnable == FALSE) @@ -3342,7 +3293,6 @@ VOID MlmeUpdateHtTxRates( pMaxHtPhy->field.STBC = STBC_NONE; } else -#endif // CONFIG_STA_SUPPORT // { if (pDesireHtPhy->bHtEnable == FALSE) return; @@ -3393,7 +3343,6 @@ VOID MlmeUpdateHtTxRates( pMinHtPhy->field.STBC = 0; pMinHtPhy->field.ShortGI = 0; //If STA assigns fixed rate. update to fixed here. -#ifdef CONFIG_STA_SUPPORT if ( (pAd->OpMode == OPMODE_STA) && (pDesireHtPhy->MCSSet[0] != 0xff)) { if (pDesireHtPhy->MCSSet[4] != 0) @@ -3417,8 +3366,6 @@ VOID MlmeUpdateHtTxRates( break; } } -#endif // CONFIG_STA_SUPPORT // - // Decide ht rate pHtPhy->field.STBC = pMaxHtPhy->field.STBC; @@ -3438,7 +3385,6 @@ VOID MlmeUpdateHtTxRates( pHtPhy->field.BW, pHtPhy->field.ShortGI, pHtPhy->field.MODE)); DBGPRINT(RT_DEBUG_TRACE,("MlmeUpdateHtTxRates<=== \n")); } -#endif // DOT11_N_SUPPORT // // IRQL = DISPATCH_LEVEL VOID MlmeRadioOff( @@ -3483,7 +3429,6 @@ VOID BssTableInit( } } -#ifdef DOT11_N_SUPPORT VOID BATableInit( IN PRTMP_ADAPTER pAd, IN BA_TABLE *Tab) @@ -3503,7 +3448,6 @@ VOID BATableInit( Tab->BAOriEntry[i].ORI_BA_Status = Originator_NONE; } } -#endif // DOT11_N_SUPPORT // /*! \brief search the BSS table by SSID * \param p_tab pointer to the bss table @@ -3613,7 +3557,6 @@ VOID BssTableDeleteEntry( } } -#ifdef DOT11_N_SUPPORT /* ======================================================================== Routine Description: @@ -3645,7 +3588,6 @@ VOID BATableDeleteORIEntry( NdisReleaseSpinLock(&pAd->BATabLock); } } -#endif // DOT11_N_SUPPORT // /*! \brief * \param @@ -3762,7 +3704,7 @@ VOID BssEntrySet( pBss->AddHtInfoLen = 0; pBss->HtCapabilityLen = 0; -#ifdef DOT11_N_SUPPORT + if (HtCapabilityLen> 0) { pBss->HtCapabilityLen = HtCapabilityLen; @@ -3782,7 +3724,6 @@ VOID BssEntrySet( } } } -#endif // DOT11_N_SUPPORT // BssCipherParse(pBss); @@ -3800,8 +3741,6 @@ VOID BssEntrySet( else pBss->QbssLoad.bValid = FALSE; -#ifdef CONFIG_STA_SUPPORT - IF_DEV_CONFIG_OPMODE_ON_STA(pAd) { PEID_STRUCT pEid; USHORT Length = 0; @@ -3809,11 +3748,9 @@ VOID BssEntrySet( NdisZeroMemory(&pBss->WpaIE.IE[0], MAX_CUSTOM_LEN); NdisZeroMemory(&pBss->RsnIE.IE[0], MAX_CUSTOM_LEN); -#ifdef EXT_BUILD_CHANNEL_LIST - NdisZeroMemory(&pBss->CountryString[0], 3); - pBss->bHasCountryIE = FALSE; -#endif // EXT_BUILD_CHANNEL_LIST // + pEid = (PEID_STRUCT) pVIE; + while ((Length + 2 + (USHORT)pEid->Len) <= LengthVIE) { switch(pEid->Eid) @@ -3842,18 +3779,11 @@ VOID BssEntrySet( NdisMoveMemory(pBss->RsnIE.IE, pEid, pBss->RsnIE.IELen); } break; -#ifdef EXT_BUILD_CHANNEL_LIST - case IE_COUNTRY: - NdisMoveMemory(&pBss->CountryString[0], pEid->Octet, 3); - pBss->bHasCountryIE = TRUE; - break; -#endif // EXT_BUILD_CHANNEL_LIST // } Length = Length + 2 + (USHORT)pEid->Len; // Eid[1] + Len[1]+ content[Len] pEid = (PEID_STRUCT)((UCHAR*)pEid + 2 + pEid->Len); } } -#endif // CONFIG_STA_SUPPORT // } /*! @@ -3947,119 +3877,22 @@ ULONG BssTableSetEntry( } else { +#ifdef RT30xx + /* avoid Hidden SSID form beacon to overwirite correct SSID from probe response */ + if ((SSID_EQUAL(Ssid, SsidLen, Tab->BssEntry[Idx].Ssid, Tab->BssEntry[Idx].SsidLen)) || + (NdisEqualMemory(Tab->BssEntry[Idx].Ssid, ZeroSsid, Tab->BssEntry[Idx].SsidLen))) + { +#endif BssEntrySet(pAd, &Tab->BssEntry[Idx], pBssid, Ssid, SsidLen, BssType, BeaconPeriod,CfParm, AtimWin, CapabilityInfo, SupRate, SupRateLen, ExtRate, ExtRateLen,pHtCapability, pAddHtInfo,HtCapabilityLen, AddHtInfoLen, NewExtChanOffset, ChannelNo, Rssi, TimeStamp, CkipFlag, pEdcaParm, pQosCapability, pQbssLoad, LengthVIE, pVIE); - } - - return Idx; -} - -#ifdef CONFIG_STA_SUPPORT -#ifdef DOT11_N_SUPPORT -#ifdef DOT11N_DRAFT3 -VOID TriEventInit( - IN PRTMP_ADAPTER pAd) -{ - UCHAR i; - - for (i = 0;i < MAX_TRIGGER_EVENT;i++) - pAd->CommonCfg.TriggerEventTab.EventA[i].bValid = FALSE; - - pAd->CommonCfg.TriggerEventTab.EventANo = 0; - pAd->CommonCfg.TriggerEventTab.EventBCountDown = 0; -} - -ULONG TriEventTableSetEntry( - IN PRTMP_ADAPTER pAd, - OUT TRIGGER_EVENT_TAB *Tab, - IN PUCHAR pBssid, - IN HT_CAPABILITY_IE *pHtCapability, - IN UCHAR HtCapabilityLen, - IN UCHAR RegClass, - IN UCHAR ChannelNo) -{ - // Event A - if (HtCapabilityLen == 0) - { - if (Tab->EventANo < MAX_TRIGGER_EVENT) - { - RTMPMoveMemory(Tab->EventA[Tab->EventANo].BSSID, pBssid, 6); - Tab->EventA[Tab->EventANo].bValid = TRUE; - Tab->EventA[Tab->EventANo].Channel = ChannelNo; - Tab->EventA[Tab->EventANo].CDCounter = pAd->CommonCfg.Dot11BssWidthChanTranDelay; - if (RegClass != 0) - { - // Beacon has Regulatory class IE. So use beacon's - Tab->EventA[Tab->EventANo].RegClass = RegClass; - } - else - { - // Use Station's Regulatory class instead. - if (pAd->StaActive.SupportedHtPhy.bHtEnable == TRUE) - { - if (pAd->CommonCfg.CentralChannel > pAd->CommonCfg.Channel) - { - Tab->EventA[Tab->EventANo].RegClass = 32; - } - else if (pAd->CommonCfg.CentralChannel < pAd->CommonCfg.Channel) - Tab->EventA[Tab->EventANo].RegClass = 33; - } - else - Tab->EventA[Tab->EventANo].RegClass = ??; - - } - - Tab->EventANo ++; - } - } - else if (pHtCapability->HtCapInfo.Intolerant40) - { - Tab->EventBCountDown = pAd->CommonCfg.Dot11BssWidthChanTranDelay; - } - -} - -/* - ======================================================================== - Routine Description: - Trigger Event table Maintainence called once every second. - - Arguments: - // IRQL = DISPATCH_LEVEL - ======================================================================== -*/ -VOID TriEventCounterMaintenance( - IN PRTMP_ADAPTER pAd) -{ - UCHAR i; - BOOLEAN bNotify = FALSE; - for (i = 0;i < MAX_TRIGGER_EVENT;i++) - { - if (pAd->CommonCfg.TriggerEventTab.EventA[i].bValid && (pAd->CommonCfg.TriggerEventTab.EventA[i].CDCounter > 0)) - { - pAd->CommonCfg.TriggerEventTab.EventA[i].CDCounter--; - if (pAd->CommonCfg.TriggerEventTab.EventA[i].CDCounter == 0) - { - pAd->CommonCfg.TriggerEventTab.EventA[i].bValid = FALSE; - pAd->CommonCfg.TriggerEventTab.EventANo --; - // Need to send 20/40 Coexistence Notify frame if has status change. - bNotify = TRUE; - } +#ifdef RT30xx } - } - if (pAd->CommonCfg.TriggerEventTab.EventBCountDown > 0) - { - pAd->CommonCfg.TriggerEventTab.EventBCountDown--; - if (pAd->CommonCfg.TriggerEventTab.EventBCountDown == 0) - bNotify = TRUE; +#endif } - if (bNotify == TRUE) - Update2040CoexistFrameAndNotify(pAd, BSSID_WCID, TRUE); + return Idx; } -#endif // DOT11N_DRAFT3 // -#endif // DOT11_N_SUPPORT // // IRQL = DISPATCH_LEVEL VOID BssTableSsidSort( @@ -4079,9 +3912,6 @@ VOID BssTableSsidSort( if (((pAd->CommonCfg.bIEEE80211H == 1) && (pAd->MlmeAux.Channel > 14) && RadarChannelCheck(pAd, pInBss->Channel)) -#ifdef CARRIER_DETECTION_SUPPORT // Roger sync Carrier - || (pAd->CommonCfg.CarrierDetect.Enable == TRUE) -#endif // CARRIER_DETECTION_SUPPORT // ) { if (pInBss->Hidden) @@ -4093,18 +3923,6 @@ VOID BssTableSsidSort( { BSS_ENTRY *pOutBss = &OutTab->BssEntry[OutTab->BssNr]; - -#ifdef EXT_BUILD_CHANNEL_LIST - // If no Country IE exists no Connection will be established when IEEE80211dClientMode is strict. - if ((pAd->StaCfg.IEEE80211dClientMode == Rt802_11_D_Strict) && - (pInBss->bHasCountryIE == FALSE)) - { - DBGPRINT(RT_DEBUG_TRACE,("StaCfg.IEEE80211dClientMode == Rt802_11_D_Strict, but this AP doesn't have country IE.\n")); - continue; - } -#endif // EXT_BUILD_CHANNEL_LIST // - -#ifdef DOT11_N_SUPPORT // 2.4G/5G N only mode if ((pInBss->HtCapabilityLen == 0) && ((pAd->CommonCfg.PhyMode == PHY_11N_2_4G) || (pAd->CommonCfg.PhyMode == PHY_11N_5G))) @@ -4112,7 +3930,6 @@ VOID BssTableSsidSort( DBGPRINT(RT_DEBUG_TRACE,("STA is in N-only Mode, this AP don't have Ht capability in Beacon.\n")); continue; } -#endif // DOT11_N_SUPPORT // // New for WPA2 // Check the Authmode first @@ -4132,9 +3949,14 @@ VOID BssTableSsidSort( continue; // check group cipher +#ifndef RT30xx if ((pAd->StaCfg.WepStatus < pInBss->WPA.GroupCipher) && (pInBss->WPA.GroupCipher != Ndis802_11GroupWEP40Enabled) && (pInBss->WPA.GroupCipher != Ndis802_11GroupWEP104Enabled)) +#endif +#ifdef RT30xx + if (pAd->StaCfg.WepStatus < pInBss->WPA.GroupCipher) +#endif continue; // check pairwise cipher, skip if none matched @@ -4153,9 +3975,14 @@ VOID BssTableSsidSort( continue; // check group cipher +#ifndef RT30xx if ((pAd->StaCfg.WepStatus < pInBss->WPA.GroupCipher) && (pInBss->WPA2.GroupCipher != Ndis802_11GroupWEP40Enabled) && (pInBss->WPA2.GroupCipher != Ndis802_11GroupWEP104Enabled)) +#endif +#ifdef RT30xx + if (pAd->StaCfg.WepStatus < pInBss->WPA2.GroupCipher) +#endif continue; // check pairwise cipher, skip if none matched @@ -4185,7 +4012,6 @@ VOID BssTableSsidSort( if (SsidLen == 0) continue; -#ifdef DOT11_N_SUPPORT // If both station and AP use 40MHz, still need to check if the 40MHZ band's legality in my country region // If this 40MHz wideband is not allowed in my country list, use bandwidth 20MHZ instead, if ((pInBss->CentralChannel != pInBss->Channel) && @@ -4205,7 +4031,6 @@ VOID BssTableSsidSort( } } } -#endif // DOT11_N_SUPPORT // // copy matching BSS from InTab to OutTab NdisMoveMemory(pOutBss, pInBss, sizeof(BSS_ENTRY)); @@ -4216,8 +4041,6 @@ VOID BssTableSsidSort( { BSS_ENTRY *pOutBss = &OutTab->BssEntry[OutTab->BssNr]; - -#ifdef DOT11_N_SUPPORT // 2.4G/5G N only mode if ((pInBss->HtCapabilityLen == 0) && ((pAd->CommonCfg.PhyMode == PHY_11N_2_4G) || (pAd->CommonCfg.PhyMode == PHY_11N_5G))) @@ -4225,7 +4048,6 @@ VOID BssTableSsidSort( DBGPRINT(RT_DEBUG_TRACE,("STA is in N-only Mode, this AP don't have Ht capability in Beacon.\n")); continue; } -#endif // DOT11_N_SUPPORT // // New for WPA2 // Check the Authmode first @@ -4281,7 +4103,6 @@ VOID BssTableSsidSort( else if (pAd->StaCfg.WepStatus != pInBss->WepStatus) continue; -#ifdef DOT11_N_SUPPORT // If both station and AP use 40MHz, still need to check if the 40MHZ band's legality in my country region // If this 40MHz wideband is not allowed in my country list, use bandwidth 20MHZ instead, if ((pInBss->CentralChannel != pInBss->Channel) && @@ -4294,7 +4115,6 @@ VOID BssTableSsidSort( pAd->CommonCfg.RegTransmitSetting.field.BW = BW_40; } } -#endif // DOT11_N_SUPPORT // // copy matching BSS from InTab to OutTab NdisMoveMemory(pOutBss, pInBss, sizeof(BSS_ENTRY)); @@ -4330,8 +4150,6 @@ VOID BssTableSortByRssi( } } } -#endif // CONFIG_STA_SUPPORT // - VOID BssCipherParse( IN OUT PBSS_ENTRY pBss) @@ -4442,10 +4260,16 @@ VOID BssCipherParse( switch (*pTmp) { case 1: +#ifndef RT30xx pBss->WPA.GroupCipher = Ndis802_11GroupWEP40Enabled; break; case 5: pBss->WPA.GroupCipher = Ndis802_11GroupWEP104Enabled; +#endif +#ifdef RT30xx + case 5: // Although WEP is not allowed in WPA related auth mode, we parse it anyway + pBss->WPA.GroupCipher = Ndis802_11Encryption1Enabled; +#endif break; case 2: pBss->WPA.GroupCipher = Ndis802_11Encryption2Enabled; @@ -4532,7 +4356,6 @@ VOID BssCipherParse( pBss->AuthMode = Ndis802_11AuthModeWPANone; pBss->AuthModeAux = Ndis802_11AuthModeWPANone; pBss->WepStatus = pBss->WPA.GroupCipher; - // Patched bugs for old driver if (pBss->WPA.PairCipherAux == Ndis802_11WEPDisabled) pBss->WPA.PairCipherAux = pBss->WPA.GroupCipher; } @@ -4562,10 +4385,16 @@ VOID BssCipherParse( switch (pCipher->Type) { case 1: +#ifndef RT30xx pBss->WPA2.GroupCipher = Ndis802_11GroupWEP40Enabled; break; case 5: pBss->WPA2.GroupCipher = Ndis802_11GroupWEP104Enabled; +#endif +#ifdef RT30xx + case 5: // Although WEP is not allowed in WPA related auth mode, we parse it anyway + pBss->WPA2.GroupCipher = Ndis802_11Encryption1Enabled; +#endif break; case 2: pBss->WPA2.GroupCipher = Ndis802_11Encryption2Enabled; @@ -4659,7 +4488,6 @@ VOID BssCipherParse( pBss->WPA.PairCipherAux = pBss->WPA2.PairCipherAux; pBss->WPA.GroupCipher = pBss->WPA2.GroupCipher; pBss->WepStatus = pBss->WPA.GroupCipher; - // Patched bugs for old driver if (pBss->WPA.PairCipherAux == Ndis802_11WEPDisabled) pBss->WPA.PairCipherAux = pBss->WPA.GroupCipher; } @@ -4735,10 +4563,9 @@ VOID MgtMacHeaderInit( pHdr80211->FC.SubType = SubType; pHdr80211->FC.ToDs = ToDs; COPY_MAC_ADDR(pHdr80211->Addr1, pDA); -#ifdef CONFIG_STA_SUPPORT - IF_DEV_CONFIG_OPMODE_ON_STA(pAd) - COPY_MAC_ADDR(pHdr80211->Addr2, pAd->CurrentAddress); -#endif // CONFIG_STA_SUPPORT // + + COPY_MAC_ADDR(pHdr80211->Addr2, pAd->CurrentAddress); + COPY_MAC_ADDR(pHdr80211->Addr3, pBssid); } @@ -4925,12 +4752,6 @@ BOOLEAN MlmeEnqueueForRecv( INT MsgType; MLME_QUEUE *Queue = (MLME_QUEUE *)&pAd->Mlme.Queue; -#ifdef RALINK_ATE - /* Nothing to do in ATE mode */ - if(ATE_ON(pAd)) - return FALSE; -#endif // RALINK_ATE // - // Do nothing if the driver is starting halt state. // This might happen when timer already been fired before cancel timer with mlmehalt if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST)) @@ -4951,8 +4772,6 @@ BOOLEAN MlmeEnqueueForRecv( return FALSE; } -#ifdef CONFIG_STA_SUPPORT - IF_DEV_CONFIG_OPMODE_ON_STA(pAd) { if (!MsgTypeSubst(pAd, pFrame, &Machine, &MsgType)) { @@ -4960,7 +4779,6 @@ BOOLEAN MlmeEnqueueForRecv( return FALSE; } } -#endif // CONFIG_STA_SUPPORT // // OK, we got all the informations, it is time to put things into queue NdisAcquireSpinLock(&(Queue->Lock)); @@ -5028,13 +4846,14 @@ BOOLEAN MlmeDequeue( VOID MlmeRestartStateMachine( IN PRTMP_ADAPTER pAd) { +#ifdef RT2860 MLME_QUEUE_ELEM *Elem = NULL; -#ifdef CONFIG_STA_SUPPORT +#endif BOOLEAN Cancelled; -#endif // CONFIG_STA_SUPPORT // DBGPRINT(RT_DEBUG_TRACE, ("MlmeRestartStateMachine \n")); +#ifdef RT2860 NdisAcquireSpinLock(&pAd->Mlme.TaskLock); if(pAd->Mlme.bRunning) { @@ -5062,13 +4881,9 @@ VOID MlmeRestartStateMachine( DBGPRINT_ERR(("MlmeRestartStateMachine: MlmeQueue empty\n")); } } +#endif /* RT2860 */ -#ifdef CONFIG_STA_SUPPORT - IF_DEV_CONFIG_OPMODE_ON_STA(pAd) { -#ifdef QOS_DLS_SUPPORT - UCHAR i; -#endif // QOS_DLS_SUPPORT // // Cancel all timer events // Be careful to cancel new added timer RTMPCancelTimer(&pAd->MlmeAux.AssocTimer, &Cancelled); @@ -5077,15 +4892,7 @@ VOID MlmeRestartStateMachine( RTMPCancelTimer(&pAd->MlmeAux.AuthTimer, &Cancelled); RTMPCancelTimer(&pAd->MlmeAux.BeaconTimer, &Cancelled); RTMPCancelTimer(&pAd->MlmeAux.ScanTimer, &Cancelled); - -#ifdef QOS_DLS_SUPPORT - for (i=0; i<MAX_NUM_OF_DLS_ENTRY; i++) - { - RTMPCancelTimer(&pAd->StaCfg.DLSEntry[i].Timer, &Cancelled); - } -#endif // QOS_DLS_SUPPORT // } -#endif // CONFIG_STA_SUPPORT // // Change back to original channel in case of doing scan AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE); @@ -5094,8 +4901,6 @@ VOID MlmeRestartStateMachine( // Resume MSDU which is turned off durning scan RTMPResumeMsduTransmission(pAd); -#ifdef CONFIG_STA_SUPPORT - IF_DEV_CONFIG_OPMODE_ON_STA(pAd) { // Set all state machines back IDLE pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE; @@ -5104,16 +4909,14 @@ VOID MlmeRestartStateMachine( pAd->Mlme.AuthRspMachine.CurrState = AUTH_RSP_IDLE; pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE; pAd->Mlme.ActMachine.CurrState = ACT_IDLE; -#ifdef QOS_DLS_SUPPORT - pAd->Mlme.DlsMachine.CurrState = DLS_IDLE; -#endif // QOS_DLS_SUPPORT // } -#endif // CONFIG_STA_SUPPORT // +#ifdef RT2860 // Remove running state NdisAcquireSpinLock(&pAd->Mlme.TaskLock); pAd->Mlme.bRunning = FALSE; NdisReleaseSpinLock(&pAd->Mlme.TaskLock); +#endif } /*! \brief test if the MLME Queue is empty @@ -5191,7 +4994,6 @@ VOID MlmeQueueDestroy( IRQL = DISPATCH_LEVEL */ -#ifdef CONFIG_STA_SUPPORT BOOLEAN MsgTypeSubst( IN PRTMP_ADAPTER pAd, IN PFRAME_802_11 pFrame, @@ -5215,16 +5017,6 @@ BOOLEAN MsgTypeSubst( *MsgType = MT2_AIRONET_MSG; return (TRUE); } -#ifdef LEAP_SUPPORT - if ( pAd->StaCfg.LeapAuthMode == CISCO_AuthModeLEAP ) //LEAP - { - // LEAP frames - *Machine = LEAP_STATE_MACHINE; - EAPType = *((UCHAR*)pFrame + LENGTH_802_11 + LENGTH_802_1_H + 1); - return (LeapMsgTypeSubst(EAPType, MsgType)); - } - else -#endif // LEAP_SUPPORT // { *Machine = WPA_PSK_STATE_MACHINE; EAPType = *((UCHAR*)pFrame + LENGTH_802_11 + LENGTH_802_1_H + 1); @@ -5311,7 +5103,6 @@ BOOLEAN MsgTypeSubst( return TRUE; } -#endif // CONFIG_STA_SUPPORT // // =========================================================================================== // state_machine.c @@ -5533,7 +5324,6 @@ VOID AsicUpdateAutoFallBackTable( } } break; -#ifdef DOT11_N_SUPPORT case 2: //HT-MIX case 3: //HT-GF { @@ -5595,7 +5385,6 @@ VOID AsicUpdateAutoFallBackTable( } } break; -#endif // DOT11_N_SUPPORT // } pNextTxRate = pCurrTxRate; @@ -5637,12 +5426,6 @@ VOID AsicUpdateProtect( UCHAR i; UINT32 MacReg = 0; -#ifdef RALINK_ATE - if (ATE_ON(pAd)) - return; -#endif // RALINK_ATE // - -#ifdef DOT11_N_SUPPORT if (!(pAd->CommonCfg.bHTProtect) && (OperationMode != 8)) { return; @@ -5656,19 +5439,14 @@ VOID AsicUpdateProtect( SetMask = ALLN_SETPROTECT; OperationMode = 8; } -#endif // DOT11_N_SUPPORT // // Config ASIC RTS threshold register RTMP_IO_READ32(pAd, TX_RTS_CFG, &MacReg); MacReg &= 0xFF0000FF; -#if 0 - MacReg |= (pAd->CommonCfg.RtsThreshold << 8); -#else + // If the user want disable RtsThreshold and enable Amsdu/Ralink-Aggregation, set the RtsThreshold as 4096 if (( -#ifdef DOT11_N_SUPPORT (pAd->CommonCfg.BACapability.field.AmsduEnable) || -#endif // DOT11_N_SUPPORT // (pAd->CommonCfg.bAggregationCapable == TRUE)) && pAd->CommonCfg.RtsThreshold == MAX_RTS_THRESHOLD) { @@ -5678,7 +5456,6 @@ VOID AsicUpdateProtect( { MacReg |= (pAd->CommonCfg.RtsThreshold << 8); } -#endif RTMP_IO_WRITE32(pAd, TX_RTS_CFG, MacReg); @@ -5717,7 +5494,6 @@ VOID AsicUpdateProtect( Protect[1] = ProtCfg.word; } -#ifdef DOT11_N_SUPPORT // Decide HT frame protection. if ((SetMask & ALLN_SETPROTECT) != 0) { @@ -5848,7 +5624,6 @@ VOID AsicUpdateProtect( break; } } -#endif // DOT11_N_SUPPORT // offset = CCK_PROT_CFG; for (i = 0;i < 6;i++) @@ -5860,6 +5635,276 @@ VOID AsicUpdateProtect( } } +#ifdef RT30xx +/* + ======================================================================== + + Routine Description: Write RT30xx RF register through MAC + + Arguments: + + Return Value: + + IRQL = + + Note: + + ======================================================================== +*/ +NTSTATUS RT30xxWriteRFRegister( + IN PRTMP_ADAPTER pAd, + IN UCHAR RegID, + IN UCHAR Value) +{ + RF_CSR_CFG_STRUC rfcsr; + UINT i = 0; + + do + { + RTMP_IO_READ32(pAd, RF_CSR_CFG, &rfcsr.word); + + if (!rfcsr.field.RF_CSR_KICK) + break; + i++; + } + while ((i < RETRY_LIMIT) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))); + + if ((i == RETRY_LIMIT) || (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))) + { + DBGPRINT_RAW(RT_DEBUG_ERROR, ("Retry count exhausted or device removed!!!\n")); + return STATUS_UNSUCCESSFUL; + } + + rfcsr.field.RF_CSR_WR = 1; + rfcsr.field.RF_CSR_KICK = 1; + rfcsr.field.TESTCSR_RFACC_REGNUM = RegID; + rfcsr.field.RF_CSR_DATA = Value; + + RTMP_IO_WRITE32(pAd, RF_CSR_CFG, rfcsr.word); + + return STATUS_SUCCESS; +} + + +/* + ======================================================================== + + Routine Description: Read RT30xx RF register through MAC + + Arguments: + + Return Value: + + IRQL = + + Note: + + ======================================================================== +*/ +NTSTATUS RT30xxReadRFRegister( + IN PRTMP_ADAPTER pAd, + IN UCHAR RegID, + IN PUCHAR pValue) +{ + RF_CSR_CFG_STRUC rfcsr; + UINT i=0, k=0; + + for (i=0; i<MAX_BUSY_COUNT; i++) + { + RTMP_IO_READ32(pAd, RF_CSR_CFG, &rfcsr.word); + + if (rfcsr.field.RF_CSR_KICK == BUSY) + { + continue; + } + rfcsr.word = 0; + rfcsr.field.RF_CSR_WR = 0; + rfcsr.field.RF_CSR_KICK = 1; + rfcsr.field.TESTCSR_RFACC_REGNUM = RegID; + RTMP_IO_WRITE32(pAd, RF_CSR_CFG, rfcsr.word); + for (k=0; k<MAX_BUSY_COUNT; k++) + { + RTMP_IO_READ32(pAd, RF_CSR_CFG, &rfcsr.word); + + if (rfcsr.field.RF_CSR_KICK == IDLE) + break; + } + if ((rfcsr.field.RF_CSR_KICK == IDLE) && + (rfcsr.field.TESTCSR_RFACC_REGNUM == RegID)) + { + *pValue = (UCHAR)rfcsr.field.RF_CSR_DATA; + break; + } + } + if (rfcsr.field.RF_CSR_KICK == BUSY) + { + DBGPRINT_ERR(("RF read R%d=0x%x fail, i[%d], k[%d]\n", RegID, rfcsr.word,i,k)); + return STATUS_UNSUCCESSFUL; + } + + return STATUS_SUCCESS; +} +#endif // RT30xx // + +#ifdef RT30xx +// add by johnli, RF power sequence setup +/* + ========================================================================== + Description: + + Load RF normal operation-mode setup + + ========================================================================== + */ +VOID RT30xxLoadRFNormalModeSetup( + IN PRTMP_ADAPTER pAd) +{ + UCHAR RFValue; + + // RX0_PD & TX0_PD, RF R1 register Bit 2 & Bit 3 to 0 and RF_BLOCK_en,RX1_PD & TX1_PD, Bit0, Bit 4 & Bit5 to 1 + RT30xxReadRFRegister(pAd, RF_R01, &RFValue); + RFValue = (RFValue & (~0x0C)) | 0x31; + RT30xxWriteRFRegister(pAd, RF_R01, RFValue); + + // TX_LO2_en, RF R15 register Bit 3 to 0 + RT30xxReadRFRegister(pAd, RF_R15, &RFValue); + RFValue &= (~0x08); + RT30xxWriteRFRegister(pAd, RF_R15, RFValue); + + // TX_LO1_en, RF R17 register Bit 3 to 0 + RT30xxReadRFRegister(pAd, RF_R17, &RFValue); + RFValue &= (~0x08); + // to fix rx long range issue + if (((pAd->MACVersion & 0xffff) >= 0x0211) && (pAd->NicConfig2.field.ExternalLNAForG == 0)) + { + RFValue |= 0x20; + } + RT30xxWriteRFRegister(pAd, RF_R17, RFValue); + + // RX_LO1_en, RF R20 register Bit 3 to 0 + RT30xxReadRFRegister(pAd, RF_R20, &RFValue); + RFValue &= (~0x08); + RT30xxWriteRFRegister(pAd, RF_R20, RFValue); + + // RX_LO2_en, RF R21 register Bit 3 to 0 + RT30xxReadRFRegister(pAd, RF_R21, &RFValue); + RFValue &= (~0x08); + RT30xxWriteRFRegister(pAd, RF_R21, RFValue); + + // LDORF_VC, RF R27 register Bit 2 to 0 + RT30xxReadRFRegister(pAd, RF_R27, &RFValue); + if ((pAd->MACVersion & 0xffff) < 0x0211) + RFValue = (RFValue & (~0x77)) | 0x3; + else + RFValue = (RFValue & (~0x77)); + RT30xxWriteRFRegister(pAd, RF_R27, RFValue); + /* end johnli */ +} + +/* + ========================================================================== + Description: + + Load RF sleep-mode setup + + ========================================================================== + */ +VOID RT30xxLoadRFSleepModeSetup( + IN PRTMP_ADAPTER pAd) +{ + UCHAR RFValue; + UINT32 MACValue; + + // RF_BLOCK_en. RF R1 register Bit 0 to 0 + RT30xxReadRFRegister(pAd, RF_R01, &RFValue); + RFValue &= (~0x01); + RT30xxWriteRFRegister(pAd, RF_R01, RFValue); + + // VCO_IC, RF R7 register Bit 4 & Bit 5 to 0 + RT30xxReadRFRegister(pAd, RF_R07, &RFValue); + RFValue &= (~0x30); + RT30xxWriteRFRegister(pAd, RF_R07, RFValue); + + // Idoh, RF R9 register Bit 1, Bit 2 & Bit 3 to 0 + RT30xxReadRFRegister(pAd, RF_R09, &RFValue); + RFValue &= (~0x0E); + RT30xxWriteRFRegister(pAd, RF_R09, RFValue); + + // RX_CTB_en, RF R21 register Bit 7 to 0 + RT30xxReadRFRegister(pAd, RF_R21, &RFValue); + RFValue &= (~0x80); + RT30xxWriteRFRegister(pAd, RF_R21, RFValue); + + // LDORF_VC, RF R27 register Bit 0, Bit 1 & Bit 2 to 1 + RT30xxReadRFRegister(pAd, RF_R27, &RFValue); + RFValue |= 0x77; + RT30xxWriteRFRegister(pAd, RF_R27, RFValue); + + RTMP_IO_READ32(pAd, LDO_CFG0, &MACValue); + MACValue |= 0x1D000000; + RTMP_IO_WRITE32(pAd, LDO_CFG0, MACValue); +} + +/* + ========================================================================== + Description: + + Reverse RF sleep-mode setup + + ========================================================================== + */ +VOID RT30xxReverseRFSleepModeSetup( + IN PRTMP_ADAPTER pAd) +{ + UCHAR RFValue; + UINT32 MACValue; + + // RF_BLOCK_en, RF R1 register Bit 0 to 1 + RT30xxReadRFRegister(pAd, RF_R01, &RFValue); + RFValue |= 0x01; + RT30xxWriteRFRegister(pAd, RF_R01, RFValue); + + // VCO_IC, RF R7 register Bit 4 & Bit 5 to 1 + RT30xxReadRFRegister(pAd, RF_R07, &RFValue); + RFValue |= 0x30; + RT30xxWriteRFRegister(pAd, RF_R07, RFValue); + + // Idoh, RF R9 register Bit 1, Bit 2 & Bit 3 to 1 + RT30xxReadRFRegister(pAd, RF_R09, &RFValue); + RFValue |= 0x0E; + RT30xxWriteRFRegister(pAd, RF_R09, RFValue); + + // RX_CTB_en, RF R21 register Bit 7 to 1 + RT30xxReadRFRegister(pAd, RF_R21, &RFValue); + RFValue |= 0x80; + RT30xxWriteRFRegister(pAd, RF_R21, RFValue); + + // LDORF_VC, RF R27 register Bit 2 to 0 + RT30xxReadRFRegister(pAd, RF_R27, &RFValue); + if ((pAd->MACVersion & 0xffff) < 0x0211) + RFValue = (RFValue & (~0x77)) | 0x3; + else + RFValue = (RFValue & (~0x77)); + RT30xxWriteRFRegister(pAd, RF_R27, RFValue); + + // RT3071 version E has fixed this issue + if ((pAd->NicConfig2.field.DACTestBit == 1) && ((pAd->MACVersion & 0xffff) < 0x0211)) + { + // patch tx EVM issue temporarily + RTMP_IO_READ32(pAd, LDO_CFG0, &MACValue); + MACValue = ((MACValue & 0xE0FFFFFF) | 0x0D000000); + RTMP_IO_WRITE32(pAd, LDO_CFG0, MACValue); + } + else + { + RTMP_IO_READ32(pAd, LDO_CFG0, &MACValue); + MACValue = ((MACValue & 0xE0FFFFFF) | 0x01000000); + RTMP_IO_WRITE32(pAd, LDO_CFG0, MACValue); + } +} +// end johnli +#endif // RT30xx // + /* ========================================================================== Description: @@ -5881,6 +5926,21 @@ VOID AsicSwitchChannel( RTMP_RF_REGS *RFRegTable; // Search Tx power value +#ifdef RT30xx + // We can't use ChannelList to search channel, since some central channl's txpowr doesn't list + // in ChannelList, so use TxPower array instead. + // + for (index = 0; index < MAX_NUM_OF_CHANNELS; index++) + { + if (Channel == pAd->TxPower[index].Channel) + { + TxPwer = pAd->TxPower[index].Power; + TxPwer2 = pAd->TxPower[index].Power2; + break; + } + } +#endif +#ifndef RT30xx for (index = 0; index < pAd->ChannelListNum; index++) { if (Channel == pAd->ChannelList[index].Channel) @@ -5890,12 +5950,152 @@ VOID AsicSwitchChannel( break; } } +#endif if (index == MAX_NUM_OF_CHANNELS) { +#ifndef RT30xx DBGPRINT(RT_DEBUG_ERROR, ("AsicSwitchChannel: Cant find the Channel#%d \n", Channel)); +#endif +#ifdef RT30xx + DBGPRINT(RT_DEBUG_ERROR, ("AsicSwitchChannel: Can't find the Channel#%d \n", Channel)); +#endif } +#ifdef RT2870 + // The RF programming sequence is difference between 3xxx and 2xxx +#ifdef RT30xx + if ((IS_RT3070(pAd) || IS_RT3090(pAd)) && ((pAd->RfIcType == RFIC_3020) || (pAd->RfIcType == RFIC_2020) || + (pAd->RfIcType == RFIC_3021) || (pAd->RfIcType == RFIC_3022))) +#endif +#ifndef RT30xx + if (IS_RT3070(pAd) && ((pAd->RfIcType == RFIC_3020) || (pAd->RfIcType == RFIC_2020))) +#endif + { + /* modify by WY for Read RF Reg. error */ + UCHAR RFValue; + + for (index = 0; index < NUM_OF_3020_CHNL; index++) + { + if (Channel == FreqItems3020[index].Channel) + { + // Programming channel parameters + RT30xxWriteRFRegister(pAd, RF_R02, FreqItems3020[index].N); + RT30xxWriteRFRegister(pAd, RF_R03, FreqItems3020[index].K); + +#ifndef RT30xx + RT30xxReadRFRegister(pAd, RF_R06, (PUCHAR)&RFValue); + RFValue = (RFValue & 0xFC) | FreqItems3020[index].R; + RT30xxWriteRFRegister(pAd, RF_R06, (UCHAR)RFValue); + + // Set Tx Power + RT30xxReadRFRegister(pAd, RF_R12, (PUCHAR)&RFValue); + RFValue = (RFValue & 0xE0) | TxPwer; + RT30xxWriteRFRegister(pAd, RF_R12, (UCHAR)RFValue); + + // Set RF offset + RT30xxReadRFRegister(pAd, RF_R23, (PUCHAR)&RFValue); + RFValue = (RFValue & 0x80) | pAd->RfFreqOffset; + RT30xxWriteRFRegister(pAd, RF_R23, (UCHAR)RFValue); +#endif +#ifdef RT30xx + RT30xxReadRFRegister(pAd, RF_R06, &RFValue); + RFValue = (RFValue & 0xFC) | FreqItems3020[index].R; + RT30xxWriteRFRegister(pAd, RF_R06, RFValue); + + // Set Tx0 Power + RT30xxReadRFRegister(pAd, RF_R12, &RFValue); + RFValue = (RFValue & 0xE0) | TxPwer; + RT30xxWriteRFRegister(pAd, RF_R12, RFValue); + + // Set Tx1 Power + RT30xxReadRFRegister(pAd, RF_R13, &RFValue); + RFValue = (RFValue & 0xE0) | TxPwer2; + RT30xxWriteRFRegister(pAd, RF_R13, RFValue); + + // Tx/Rx Stream setting + RT30xxReadRFRegister(pAd, RF_R01, &RFValue); + //if (IS_RT3090(pAd)) + // RFValue |= 0x01; // Enable RF block. + RFValue &= 0x03; //clear bit[7~2] + if (pAd->Antenna.field.TxPath == 1) + RFValue |= 0xA0; + else if (pAd->Antenna.field.TxPath == 2) + RFValue |= 0x80; + if (pAd->Antenna.field.RxPath == 1) + RFValue |= 0x50; + else if (pAd->Antenna.field.RxPath == 2) + RFValue |= 0x40; + RT30xxWriteRFRegister(pAd, RF_R01, RFValue); + + // Set RF offset + RT30xxReadRFRegister(pAd, RF_R23, &RFValue); + RFValue = (RFValue & 0x80) | pAd->RfFreqOffset; + RT30xxWriteRFRegister(pAd, RF_R23, RFValue); +#endif + + // Set BW + if (!bScan && (pAd->CommonCfg.BBPCurrentBW == BW_40)) + { + RFValue = pAd->Mlme.CaliBW40RfR24; + //DISABLE_11N_CHECK(pAd); + } + else + { + RFValue = pAd->Mlme.CaliBW20RfR24; + } +#ifndef RT30xx + RT30xxWriteRFRegister(pAd, RF_R24, (UCHAR)RFValue); + + // Enable RF tuning + RT30xxReadRFRegister(pAd, RF_R07, (PUCHAR)&RFValue); + RFValue = RFValue | 0x1; + RT30xxWriteRFRegister(pAd, RF_R07, (UCHAR)RFValue); + + // latch channel for future usage. + pAd->LatchRfRegs.Channel = Channel; +#endif +#ifdef RT30xx + RT30xxWriteRFRegister(pAd, RF_R24, RFValue); + RT30xxWriteRFRegister(pAd, RF_R31, RFValue); + + // Enable RF tuning + RT30xxReadRFRegister(pAd, RF_R07, &RFValue); + RFValue = RFValue | 0x1; + RT30xxWriteRFRegister(pAd, RF_R07, RFValue); + + // latch channel for future usage. + pAd->LatchRfRegs.Channel = Channel; + + DBGPRINT(RT_DEBUG_TRACE, ("SwitchChannel#%d(RF=%d, Pwr0=%d, Pwr1=%d, %dT), N=0x%02X, K=0x%02X, R=0x%02X\n", + Channel, + pAd->RfIcType, + TxPwer, + TxPwer2, + pAd->Antenna.field.TxPath, + FreqItems3020[index].N, + FreqItems3020[index].K, + FreqItems3020[index].R)); +#endif + + break; + } + } + +#ifndef RT30xx + DBGPRINT(RT_DEBUG_TRACE, ("SwitchChannel#%d(RF=%d, Pwr0=%d, Pwr1=%d, %dT), N=0x%02X, K=0x%02X, R=0x%02X\n", + Channel, + pAd->RfIcType, + TxPwer, + TxPwer2, + pAd->Antenna.field.TxPath, + FreqItems3020[index].N, + FreqItems3020[index].K, + FreqItems3020[index].R)); +#endif + } + else +#endif // RT2870 // { RFRegTable = RF2850RegTable; @@ -6149,6 +6349,53 @@ VOID AsicAntennaSelect( IN PRTMP_ADAPTER pAd, IN UCHAR Channel) { +#ifdef RT30xx + if (pAd->Mlme.OneSecPeriodicRound % 2 == 1) + { + // patch for AsicSetRxAnt failed + pAd->RxAnt.EvaluatePeriod = 0; + + // check every 2 second. If rcv-beacon less than 5 in the past 2 second, then AvgRSSI is no longer a + // valid indication of the distance between this AP and its clients. + if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED)) + { + SHORT realavgrssi1; + + // if no traffic then reset average rssi to trigger evaluation + if (pAd->StaCfg.NumOfAvgRssiSample < 5) + { + pAd->RxAnt.Pair1LastAvgRssi = (-99); + pAd->RxAnt.Pair2LastAvgRssi = (-99); + DBGPRINT(RT_DEBUG_TRACE, ("MlmePeriodicExec: no traffic/beacon, reset RSSI\n")); + } + + pAd->StaCfg.NumOfAvgRssiSample = 0; + realavgrssi1 = (pAd->RxAnt.Pair1AvgRssi[pAd->RxAnt.Pair1PrimaryRxAnt] >> 3); + + DBGPRINT(RT_DEBUG_TRACE,("Ant-realrssi0(%d), Lastrssi0(%d), EvaluateStableCnt=%d\n", realavgrssi1, pAd->RxAnt.Pair1LastAvgRssi, pAd->RxAnt.EvaluateStableCnt)); + + // if the difference between two rssi is larger or less than 5, then evaluate the other antenna + if ((pAd->RxAnt.EvaluateStableCnt < 2) || (realavgrssi1 > (pAd->RxAnt.Pair1LastAvgRssi + 5)) || (realavgrssi1 < (pAd->RxAnt.Pair1LastAvgRssi - 5))) + { + pAd->RxAnt.Pair1LastAvgRssi = realavgrssi1; + AsicEvaluateRxAnt(pAd); + } + } + else + { + // if not connected, always switch antenna to try to connect + UCHAR temp; + + temp = pAd->RxAnt.Pair1PrimaryRxAnt; + pAd->RxAnt.Pair1PrimaryRxAnt = pAd->RxAnt.Pair1SecondaryRxAnt; + pAd->RxAnt.Pair1SecondaryRxAnt = temp; + + DBGPRINT(RT_DEBUG_TRACE, ("MlmePeriodicExec: no connect, switch to another one to try connection\n")); + + AsicSetRxAnt(pAd, pAd->RxAnt.Pair1PrimaryRxAnt); + } + } +#endif /* RT30xx */ } /* @@ -6218,11 +6465,13 @@ VOID AsicAdjustTxPower( ULONG TxPwr[5]; CHAR Value; +#ifdef RT2860 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE) || (pAd->bPCIclkOff == TRUE) || RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_IDLE_RADIO_OFF) || RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) return; +#endif if (pAd->CommonCfg.BBPCurrentBW == BW_40) { @@ -6364,95 +6613,6 @@ VOID AsicAdjustTxPower( RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &BbpR1); BbpR1 &= 0xFC; -#ifdef SINGLE_SKU - // Handle regulatory max tx power constrain - do - { - UCHAR TxPwrInEEPROM = 0xFF, CountryTxPwr = 0xFF, criterion; - UCHAR AdjustMaxTxPwr[40]; - - if (pAd->CommonCfg.Channel > 14) // 5G band - TxPwrInEEPROM = ((pAd->CommonCfg.DefineMaxTxPwr & 0xFF00) >> 8); - else // 2.4G band - TxPwrInEEPROM = (pAd->CommonCfg.DefineMaxTxPwr & 0x00FF); - CountryTxPwr = GetCuntryMaxTxPwr(pAd, pAd->CommonCfg.Channel); - - // error handling, range check - if ((TxPwrInEEPROM > 0x50) || (CountryTxPwr > 0x50)) - { - DBGPRINT(RT_DEBUG_ERROR,("AsicAdjustTxPower - Invalid max tx power (=0x%02x), CountryTxPwr=%d\n", TxPwrInEEPROM, CountryTxPwr)); - break; - } - - criterion = *((PUCHAR)TxPwr + 2) & 0xF; // FAE use OFDM 6M as criterion - - DBGPRINT_RAW(RT_DEBUG_TRACE,("AsicAdjustTxPower (criterion=%d, TxPwrInEEPROM=%d, CountryTxPwr=%d)\n", criterion, TxPwrInEEPROM, CountryTxPwr)); - - // Adjust max tx power according to the relationship of tx power in E2PROM - for (i=0; i<5; i++) - { - // CCK will have 4dBm larger than OFDM - // Therefore, we should separate to parse the tx power field - if (i == 0) - { - for (j=0; j<8; j++) - { - Value = (CHAR)((TxPwr[i] >> j*4) & 0x0F); - - if (j < 4) - { - // CCK will have 4dBm larger than OFDM - AdjustMaxTxPwr[i*8+j] = TxPwrInEEPROM + (Value - criterion) + 4; - } - else - { - AdjustMaxTxPwr[i*8+j] = TxPwrInEEPROM + (Value - criterion); - } - DBGPRINT_RAW(RT_DEBUG_TRACE,("AsicAdjustTxPower (i/j=%d/%d, Value=%d, %d)\n", i, j, Value, AdjustMaxTxPwr[i*8+j])); - } - } - else - { - for (j=0; j<8; j++) - { - Value = (CHAR)((TxPwr[i] >> j*4) & 0x0F); - - AdjustMaxTxPwr[i*8+j] = TxPwrInEEPROM + (Value - criterion); - DBGPRINT_RAW(RT_DEBUG_TRACE,("AsicAdjustTxPower (i/j=%d/%d, Value=%d, %d)\n", i, j, Value, AdjustMaxTxPwr[i*8+j])); - } - } - } - - // Adjust tx power according to the relationship - for (i=0; i<5; i++) - { - if (TxPwr[i] != 0xffffffff) - { - for (j=0; j<8; j++) - { - Value = (CHAR)((TxPwr[i] >> j*4) & 0x0F); - - // The system tx power is larger than the regulatory, the power should be restrain - if (AdjustMaxTxPwr[i*8+j] > CountryTxPwr) - { - // decrease to zero and don't need to take care BBPR1 - if ((Value - (AdjustMaxTxPwr[i*8+j] - CountryTxPwr)) > 0) - Value -= (AdjustMaxTxPwr[i*8+j] - CountryTxPwr); - else - Value = 0; - - DBGPRINT_RAW(RT_DEBUG_TRACE,("AsicAdjustTxPower (i/j=%d/%d, Value=%d, %d)\n", i, j, Value, AdjustMaxTxPwr[i*8+j])); - } - else - DBGPRINT_RAW(RT_DEBUG_TRACE,("AsicAdjustTxPower (i/j=%d/%d, Value=%d, %d, no change)\n", i, j, Value, AdjustMaxTxPwr[i*8+j])); - - TxPwr[i] = (TxPwr[i] & ~(0x0000000F << j*4)) | (Value << j*4); - } - } - } - } while (FALSE); -#endif // SINGLE_SKU // - /* calculate delta power based on the percentage specified from UI */ // E2PROM setting is calibrated for maximum TX power (i.e. 100%) // We lower TX power here according to the percentage specified from UI @@ -6522,7 +6682,6 @@ VOID AsicAdjustTxPower( } -#ifdef CONFIG_STA_SUPPORT /* ========================================================================== Description: @@ -6568,12 +6727,22 @@ VOID AsicForceSleep( */ VOID AsicForceWakeup( IN PRTMP_ADAPTER pAd, +#ifdef RT2860 IN UCHAR Level) +#endif +#ifdef RT2870 + IN BOOLEAN bFromTx) +#endif { DBGPRINT(RT_DEBUG_TRACE, ("--> AsicForceWakeup \n")); +#ifdef RT2860 RT28XX_STA_FORCE_WAKEUP(pAd, Level); +#endif +#ifdef RT2870 + RT28XX_STA_FORCE_WAKEUP(pAd, bFromTx); +#endif } -#endif // CONFIG_STA_SUPPORT // + /* ========================================================================== Description: @@ -6688,9 +6857,7 @@ VOID AsicDisableRDG( Data &= 0xFFFFFF00; if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_DYNAMIC_BE_TXOP_ACTIVE) -#ifdef DOT11_N_SUPPORT && (pAd->MacTab.fAnyStationMIMOPSDynamic == FALSE) -#endif // DOT11_N_SUPPORT // ) { // For CWC test, change txop from 0x30 to 0x20 in TxBurst mode @@ -6745,8 +6912,7 @@ VOID AsicEnableBssSync( DBGPRINT(RT_DEBUG_TRACE, ("--->AsicEnableBssSync(INFRA mode)\n")); RTMP_IO_READ32(pAd, BCN_TIME_CFG, &csr.word); -#ifdef CONFIG_STA_SUPPORT - IF_DEV_CONFIG_OPMODE_ON_STA(pAd) + { csr.field.BeaconInterval = pAd->CommonCfg.BeaconPeriod << 4; // ASIC register in units of 1/16 TU csr.field.bTsfTicking = 1; @@ -6754,7 +6920,7 @@ VOID AsicEnableBssSync( csr.field.bBeaconGen = 0; // do NOT generate BEACON csr.field.bTBTTEnable = 1; } -#endif // CONFIG_STA_SUPPORT // + RTMP_IO_WRITE32(pAd, BCN_TIME_CFG, csr.word); } @@ -6785,6 +6951,7 @@ VOID AsicEnableIbssSync( csr9.field.bTsfTicking = 0; RTMP_IO_WRITE32(pAd, BCN_TIME_CFG, csr9.word); +#ifdef RT2860 // move BEACON TXD and frame content to on-chip memory ptr = (PUCHAR)&pAd->BeaconTxWI; for (i=0; i<TXWI_SIZE; i+=4) // 16-byte TXWI field @@ -6802,6 +6969,24 @@ VOID AsicEnableIbssSync( RTMP_IO_WRITE32(pAd, HW_BEACON_BASE0 + TXWI_SIZE + i, longptr); ptr +=4; } +#endif +#ifdef RT2870 + // move BEACON TXD and frame content to on-chip memory + ptr = (PUCHAR)&pAd->BeaconTxWI; + for (i=0; i<TXWI_SIZE; i+=2) // 16-byte TXWI field + { + RTUSBMultiWrite(pAd, HW_BEACON_BASE0 + i, ptr, 2); + ptr += 2; + } + + // start right after the 16-byte TXWI field + ptr = pAd->BeaconBuf; + for (i=0; i< pAd->BeaconTxWI.MPDUtotalByteCount; i+=2) + { + RTUSBMultiWrite(pAd, HW_BEACON_BASE0 + TXWI_SIZE + i, ptr, 2); + ptr +=2; + } +#endif // RT2870 // // start sending BEACON csr9.field.BeaconInterval = pAd->CommonCfg.BeaconPeriod << 4; // ASIC register in units of 1/16 TU @@ -6949,8 +7134,7 @@ VOID AsicSetEdcaParm( Ac2Cfg.field.Cwmin = pEdcaParm->Cwmin[QID_AC_VI]; Ac2Cfg.field.Cwmax = pEdcaParm->Cwmax[QID_AC_VI]; Ac2Cfg.field.Aifsn = pEdcaParm->Aifsn[QID_AC_VI]; -#ifdef CONFIG_STA_SUPPORT - IF_DEV_CONFIG_OPMODE_ON_STA(pAd) + { // Tuning for Wi-Fi WMM S06 if (pAd->CommonCfg.bWiFiTest && @@ -6958,15 +7142,22 @@ VOID AsicSetEdcaParm( Ac2Cfg.field.Aifsn -= 1; // Tuning for TGn Wi-Fi 5.2.32 - // STA TestBed changes in this item: conexant legacy sta ==> broadcom 11n sta + // STA TestBed changes in this item: connexant legacy sta ==> broadcom 11n sta if (STA_TGN_WIFI_ON(pAd) && pEdcaParm->Aifsn[QID_AC_VI] == 10) { Ac0Cfg.field.Aifsn = 3; Ac2Cfg.field.AcTxop = 5; } + +#ifdef RT30xx + if (pAd->RfIcType == RFIC_3020 || pAd->RfIcType == RFIC_2020) + { + // Tuning for WiFi WMM S3-T07: connexant legacy sta ==> broadcom 11n sta. + Ac2Cfg.field.Aifsn = 5; + } +#endif // RT30xx // } -#endif // CONFIG_STA_SUPPORT // Ac3Cfg.field.AcTxop = pEdcaParm->Txop[QID_AC_VO]; Ac3Cfg.field.Cwmin = pEdcaParm->Cwmin[QID_AC_VO]; @@ -7008,10 +7199,9 @@ VOID AsicSetEdcaParm( CwminCsr.field.Cwmin0 = pEdcaParm->Cwmin[QID_AC_BE]; CwminCsr.field.Cwmin1 = pEdcaParm->Cwmin[QID_AC_BK]; CwminCsr.field.Cwmin2 = pEdcaParm->Cwmin[QID_AC_VI]; -#ifdef CONFIG_STA_SUPPORT - IF_DEV_CONFIG_OPMODE_ON_STA(pAd) - CwminCsr.field.Cwmin3 = pEdcaParm->Cwmin[QID_AC_VO] - 1; //for TGn wifi test -#endif // CONFIG_STA_SUPPORT // + + CwminCsr.field.Cwmin3 = pEdcaParm->Cwmin[QID_AC_VO] - 1; //for TGn wifi test + RTMP_IO_WRITE32(pAd, WMM_CWMIN_CFG, CwminCsr.word); CwmaxCsr.word = 0; @@ -7025,8 +7215,7 @@ VOID AsicSetEdcaParm( AifsnCsr.field.Aifsn0 = Ac0Cfg.field.Aifsn; //pEdcaParm->Aifsn[QID_AC_BE]; AifsnCsr.field.Aifsn1 = Ac1Cfg.field.Aifsn; //pEdcaParm->Aifsn[QID_AC_BK]; AifsnCsr.field.Aifsn2 = Ac2Cfg.field.Aifsn; //pEdcaParm->Aifsn[QID_AC_VI]; -#ifdef CONFIG_STA_SUPPORT - IF_DEV_CONFIG_OPMODE_ON_STA(pAd) + { // Tuning for Wi-Fi WMM S06 if (pAd->CommonCfg.bWiFiTest && @@ -7034,20 +7223,25 @@ VOID AsicSetEdcaParm( AifsnCsr.field.Aifsn2 = Ac2Cfg.field.Aifsn - 4; // Tuning for TGn Wi-Fi 5.2.32 - // STA TestBed changes in this item: conexant legacy sta ==> broadcom 11n sta + // STA TestBed changes in this item: connexant legacy sta ==> broadcom 11n sta if (STA_TGN_WIFI_ON(pAd) && pEdcaParm->Aifsn[QID_AC_VI] == 10) { AifsnCsr.field.Aifsn0 = 3; AifsnCsr.field.Aifsn2 = 7; } +#ifdef RT2870 + if (INFRA_ON(pAd)) + CLIENT_STATUS_SET_FLAG(&pAd->MacTab.Content[BSSID_WCID], fCLIENT_STATUS_WMM_CAPABLE); +#endif } -#endif // CONFIG_STA_SUPPORT // -#ifdef CONFIG_STA_SUPPORT - IF_DEV_CONFIG_OPMODE_ON_STA(pAd) - AifsnCsr.field.Aifsn3 = Ac3Cfg.field.Aifsn - 1; //pEdcaParm->Aifsn[QID_AC_VO]; //for TGn wifi test -#endif // CONFIG_STA_SUPPORT // + AifsnCsr.field.Aifsn3 = Ac3Cfg.field.Aifsn - 1; //pEdcaParm->Aifsn[QID_AC_VO]; //for TGn wifi test +#ifdef RT30xx + if (pAd->RfIcType == RFIC_3020 || pAd->RfIcType == RFIC_2020) + AifsnCsr.field.Aifsn2 = 0x2; //pEdcaParm->Aifsn[QID_AC_VI]; //for WiFi WMM S4-T04. +#endif // RT30xx // + RTMP_IO_WRITE32(pAd, WMM_AIFSN_CFG, AifsnCsr.word); NdisMoveMemory(&pAd->CommonCfg.APEdcaParm, pEdcaParm, sizeof(EDCA_PARM)); @@ -7098,10 +7292,8 @@ VOID AsicSetSlotTime( ULONG SlotTime; UINT32 RegValue = 0; -#ifdef CONFIG_STA_SUPPORT if (pAd->CommonCfg.Channel > 14) bUseShortSlotTime = TRUE; -#endif // CONFIG_STA_SUPPORT // if (bUseShortSlotTime) OPSTATUS_SET_FLAG(pAd, fOP_STATUS_SHORT_SLOT_INUSED); @@ -7110,36 +7302,31 @@ VOID AsicSetSlotTime( SlotTime = (bUseShortSlotTime)? 9 : 20; -#ifdef CONFIG_STA_SUPPORT - IF_DEV_CONFIG_OPMODE_ON_STA(pAd) { +#ifndef RT30xx // force using short SLOT time for FAE to demo performance when TxBurst is ON if (((pAd->StaActive.SupportedPhyInfo.bHtEnable == FALSE) && (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED))) -#ifdef DOT11_N_SUPPORT || ((pAd->StaActive.SupportedPhyInfo.bHtEnable == TRUE) && (pAd->CommonCfg.BACapability.field.Policy == BA_NOTUSE)) -#endif // DOT11_N_SUPPORT // ) { // In this case, we will think it is doing Wi-Fi test // And we will not set to short slot when bEnableTxBurst is TRUE. } else if (pAd->CommonCfg.bEnableTxBurst) +#endif +#ifdef RT30xx + if (pAd->CommonCfg.bEnableTxBurst) +#endif SlotTime = 9; } -#endif // CONFIG_STA_SUPPORT // // // For some reasons, always set it to short slot time. // // ToDo: Should consider capability with 11B // -#ifdef CONFIG_STA_SUPPORT - IF_DEV_CONFIG_OPMODE_ON_STA(pAd) - { - if (pAd->StaCfg.BssType == BSS_ADHOC) - SlotTime = 20; - } -#endif // CONFIG_STA_SUPPORT // + if (pAd->StaCfg.BssType == BSS_ADHOC) + SlotTime = 20; RTMP_IO_READ32(pAd, BKOFF_SLOT_CFG, &RegValue); RegValue = RegValue & 0xFFFFFF00; @@ -7170,7 +7357,9 @@ VOID AsicAddSharedKeyEntry( { ULONG offset; //, csr0; SHAREDKEY_MODE_STRUC csr1; +#ifdef RT2860 INT i; +#endif DBGPRINT(RT_DEBUG_TRACE, ("AsicAddSharedKeyEntry BssIndex=%d, KeyIdx=%d\n", BssIndex,KeyIdx)); //============================================================================================ @@ -7192,28 +7381,43 @@ VOID AsicAddSharedKeyEntry( // // fill key material - key + TX MIC + RX MIC // + offset = SHARED_KEY_TABLE_BASE + (4*BssIndex + KeyIdx)*HW_KEY_ENTRY_SIZE; +#ifdef RT2860 for (i=0; i<MAX_LEN_OF_SHARE_KEY; i++) { RTMP_IO_WRITE8(pAd, offset + i, pKey[i]); } - +#endif +#ifdef RT2870 + RTUSBMultiWrite(pAd, offset, pKey, MAX_LEN_OF_SHARE_KEY); +#endif offset += MAX_LEN_OF_SHARE_KEY; if (pTxMic) { +#ifdef RT2860 for (i=0; i<8; i++) { RTMP_IO_WRITE8(pAd, offset + i, pTxMic[i]); } +#endif +#ifdef RT2870 + RTUSBMultiWrite(pAd, offset, pTxMic, 8); +#endif } offset += 8; if (pRxMic) { +#ifdef RT2860 for (i=0; i<8; i++) { RTMP_IO_WRITE8(pAd, offset + i, pRxMic[i]); } +#endif +#ifdef RT2870 + RTUSBMultiWrite(pAd, offset, pRxMic, 8); +#endif } @@ -7389,7 +7593,9 @@ VOID AsicAddKeyEntry( PUCHAR pTxtsc = pCipherKey->TxTsc; UCHAR CipherAlg = pCipherKey->CipherAlg; SHAREDKEY_MODE_STRUC csr1; +#ifdef RT2860 UCHAR i; +#endif DBGPRINT(RT_DEBUG_TRACE, ("==> AsicAddKeyEntry\n")); // @@ -7404,10 +7610,15 @@ VOID AsicAddKeyEntry( // 2.) Set Key to Asic // //for (i = 0; i < KeyLen; i++) +#ifdef RT2860 for (i = 0; i < MAX_LEN_OF_PEER_KEY; i++) { RTMP_IO_WRITE8(pAd, offset + i, pKey[i]); } +#endif +#ifdef RT2870 + RTUSBMultiWrite(pAd, offset, pKey, MAX_LEN_OF_PEER_KEY); +#endif offset += MAX_LEN_OF_PEER_KEY; // @@ -7415,19 +7626,29 @@ VOID AsicAddKeyEntry( // if (pTxMic) { +#ifdef RT2860 for (i = 0; i < 8; i++) { RTMP_IO_WRITE8(pAd, offset + i, pTxMic[i]); } +#endif +#ifdef RT2870 + RTUSBMultiWrite(pAd, offset, pTxMic, 8); +#endif } offset += LEN_TKIP_TXMICK; if (pRxMic) { +#ifdef RT2860 for (i = 0; i < 8; i++) { RTMP_IO_WRITE8(pAd, offset + i, pRxMic[i]); } +#endif +#ifdef RT2870 + RTUSBMultiWrite(pAd, offset, pRxMic, 8); +#endif } @@ -7437,6 +7658,7 @@ VOID AsicAddKeyEntry( // if (bTxKey) { +#ifdef RT2860 offset = MAC_IVEIV_TABLE_BASE + (WCID * HW_IVEIV_ENTRY_SIZE); // // Write IV @@ -7460,6 +7682,26 @@ VOID AsicAddKeyEntry( RTMP_IO_WRITE8(pAd, offset + i, pTxtsc[i + 2]); } +#endif +#ifdef RT2870 + UINT32 tmpVal; + + // + // Write IV + // + IV4 = (KeyIdx << 6); + if ((CipherAlg == CIPHER_TKIP) || (CipherAlg == CIPHER_TKIP_NO_MIC) ||(CipherAlg == CIPHER_AES)) + IV4 |= 0x20; // turn on extension bit means EIV existence + + tmpVal = pTxtsc[1] + (((pTxtsc[1] | 0x20) & 0x7f) << 8) + (pTxtsc[0] << 16) + (IV4 << 24); + RTMP_IO_WRITE32(pAd, offset, tmpVal); + + // + // Write EIV + // + offset += 4; + RTMP_IO_WRITE32(pAd, offset, *(PUINT32)&pCipherKey->TxTsc[2]); +#endif // RT2870 // AsicUpdateWCIDAttribute(pAd, WCID, BssIndex, CipherAlg, bUsePairewiseKeyTable); } @@ -7524,10 +7766,15 @@ VOID AsicAddPairwiseKeyEntry( // EKEY offset = PAIRWISE_KEY_TABLE_BASE + (WCID * HW_KEY_ENTRY_SIZE); +#ifdef RT2860 for (i=0; i<MAX_LEN_OF_PEER_KEY; i++) { RTMP_IO_WRITE8(pAd, offset + i, pKey[i]); } +#endif +#ifdef RT2870 + RTUSBMultiWrite(pAd, offset, &pCipherKey->Key[0], MAX_LEN_OF_PEER_KEY); +#endif // RT2870 // for (i=0; i<MAX_LEN_OF_PEER_KEY; i+=4) { UINT32 Value; @@ -7539,18 +7786,28 @@ VOID AsicAddPairwiseKeyEntry( // MIC KEY if (pTxMic) { +#ifdef RT2860 for (i=0; i<8; i++) { RTMP_IO_WRITE8(pAd, offset+i, pTxMic[i]); } +#endif +#ifdef RT2870 + RTUSBMultiWrite(pAd, offset, &pCipherKey->TxMic[0], 8); +#endif // RT2870 // } offset += 8; if (pRxMic) { +#ifdef RT2860 for (i=0; i<8; i++) { RTMP_IO_WRITE8(pAd, offset+i, pRxMic[i]); } +#endif +#ifdef RT2870 + RTUSBMultiWrite(pAd, offset, &pCipherKey->RxMic[0], 8); +#endif // RT2870 // } DBGPRINT(RT_DEBUG_TRACE,("AsicAddPairwiseKeyEntry: WCID #%d Alg=%s\n",WCID, CipherName[CipherAlg])); @@ -7599,9 +7856,7 @@ BOOLEAN AsicSendCommandToMcu( HOST_CMD_CSR_STRUC H2MCmd; H2M_MAILBOX_STRUC H2MMailbox; ULONG i = 0; -#ifdef RALINK_ATE - static UINT32 j = 0; -#endif // RALINK_ATE // + do { RTMP_IO_READ32(pAd, H2M_MAILBOX_CSR, &H2MMailbox.word); @@ -7611,33 +7866,10 @@ BOOLEAN AsicSendCommandToMcu( RTMPusecDelay(2); } while(i++ < 100); - if (i >= 100) + if (i > 100) { -#ifdef RALINK_ATE - if (pAd->ate.bFWLoading == TRUE) - { - /* reloading firmware when received iwpriv cmd "ATE=ATESTOP" */ - if (j > 0) - { - if (j % 64 != 0) - { - DBGPRINT(RT_DEBUG_ERROR, ("#")); - } - else - { - DBGPRINT(RT_DEBUG_ERROR, ("\n")); - } - ++j; - } - else if (j == 0) - { - DBGPRINT(RT_DEBUG_ERROR, ("Loading firmware. Please wait for a moment...\n")); - ++j; - } - } - else -#endif // RALINK_ATE // { +#ifdef RT2860 UINT32 Data; // Reset DMA @@ -7659,21 +7891,15 @@ BOOLEAN AsicSendCommandToMcu( RTMP_IO_READ32(pAd, PBF_SYS_CTRL, &Data); Data &= 0xfffffffd; RTMP_IO_WRITE32(pAd, PBF_SYS_CTRL, Data); +#endif /* RT2860 */ DBGPRINT_ERR(("H2M_MAILBOX still hold by MCU. command fail\n")); } //return FALSE; +#ifdef RT2870 + return FALSE; +#endif } -#ifdef RALINK_ATE - else if (pAd->ate.bFWLoading == TRUE) - { - /* reloading of firmware is completed */ - pAd->ate.bFWLoading = FALSE; - DBGPRINT(RT_DEBUG_ERROR, ("\n")); - j = 0; - } -#endif // RALINK_ATE // - H2MMailbox.field.Owner = 1; // pass ownership to MCU H2MMailbox.field.CmdToken = Token; H2MMailbox.field.HighByte = Arg1; @@ -7691,6 +7917,7 @@ BOOLEAN AsicSendCommandToMcu( return TRUE; } +#ifdef RT2860 BOOLEAN AsicCheckCommanOk( IN PRTMP_ADAPTER pAd, IN UCHAR Command) @@ -7755,6 +7982,7 @@ BOOLEAN AsicCheckCommanOk( return FALSE; } +#endif /* RT8260 */ /* ======================================================================== @@ -7797,8 +8025,6 @@ VOID RTMPCheckRates( NdisMoveMemory(SupRate, NewRate, NewRateLen); } -#ifdef CONFIG_STA_SUPPORT -#ifdef DOT11_N_SUPPORT BOOLEAN RTMPCheckChannel( IN PRTMP_ADAPTER pAd, IN UCHAR CentralChannel, @@ -7944,8 +8170,6 @@ BOOLEAN RTMPCheckHt( COPY_AP_HTSETTINGS_FROM_BEACON(pAd, pHtCapability); return TRUE; } -#endif // DOT11_N_SUPPORT // -#endif // CONFIG_STA_SUPPORT // /* ======================================================================== @@ -7978,10 +8202,8 @@ VOID RTMPUpdateMlmeRate( MinimumRate = RATE_1; break; case PHY_11BG_MIXED: -#ifdef DOT11_N_SUPPORT case PHY_11ABGN_MIXED: case PHY_11BGN_MIXED: -#endif // DOT11_N_SUPPORT // if ((pAd->MlmeAux.SupRateLen == 4) && (pAd->MlmeAux.ExtRateLen == 0)) // B only AP @@ -7995,13 +8217,11 @@ VOID RTMPUpdateMlmeRate( MinimumRate = RATE_6; break; case PHY_11A: -#ifdef DOT11_N_SUPPORT case PHY_11N_2_4G: // rt2860 need to check mlmerate for 802.11n case PHY_11GN_MIXED: case PHY_11AGN_MIXED: case PHY_11AN_MIXED: case PHY_11N_5G: -#endif // DOT11_N_SUPPORT // ProperMlmeRate = RATE_24; MinimumRate = RATE_6; break; @@ -8111,6 +8331,58 @@ CHAR RTMPMaxRssi( return larger; } +#ifdef RT30xx +// Antenna divesity use GPIO3 and EESK pin for control +// Antenna and EEPROM access are both using EESK pin, +// Therefor we should avoid accessing EESK at the same time +// Then restore antenna after EEPROM access +VOID AsicSetRxAnt( + IN PRTMP_ADAPTER pAd, + IN UCHAR Ant) +{ +#ifdef RT30xx + UINT32 Value; + UINT32 x; + + if ((pAd->EepromAccess) || + (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS)) || + (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) || + (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF)) || + (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))) + { + return; + } + + // the antenna selection is through firmware and MAC register(GPIO3) + if (Ant == 0) + { + // Main antenna + RTMP_IO_READ32(pAd, E2PROM_CSR, &x); + x |= (EESK); + RTMP_IO_WRITE32(pAd, E2PROM_CSR, x); + + RTMP_IO_READ32(pAd, GPIO_CTRL_CFG, &Value); + Value &= ~(0x0808); + RTMP_IO_WRITE32(pAd, GPIO_CTRL_CFG, Value); + DBGPRINT_RAW(RT_DEBUG_TRACE, ("AsicSetRxAnt, switch to main antenna\n")); + } + else + { + // Aux antenna + RTMP_IO_READ32(pAd, E2PROM_CSR, &x); + x &= ~(EESK); + RTMP_IO_WRITE32(pAd, E2PROM_CSR, x); + + RTMP_IO_READ32(pAd, GPIO_CTRL_CFG, &Value); + Value &= ~(0x0808); + Value |= 0x08; + RTMP_IO_WRITE32(pAd, GPIO_CTRL_CFG, Value); + DBGPRINT_RAW(RT_DEBUG_TRACE, ("AsicSetRxAnt, switch to aux antenna\n")); + } +#endif // RT30xx // +} +#endif /* RT30xx */ + /* ======================================================================== Routine Description: @@ -8129,14 +8401,7 @@ VOID AsicEvaluateRxAnt( { UCHAR BBPR3 = 0; -#ifdef RALINK_ATE - if (ATE_ON(pAd)) - return; -#endif // RALINK_ATE // - - -#ifdef CONFIG_STA_SUPPORT - IF_DEV_CONFIG_OPMODE_ON_STA(pAd) +#ifndef RT30xx { if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS | fRTMP_ADAPTER_HALT_IN_PROGRESS | @@ -8148,7 +8413,6 @@ VOID AsicEvaluateRxAnt( if (pAd->StaCfg.Psm == PWR_SAVE) return; } -#endif // CONFIG_STA_SUPPORT // RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BBPR3); BBPR3 &= (~0x18); @@ -8165,10 +8429,11 @@ VOID AsicEvaluateRxAnt( BBPR3 |= (0x0); } RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BBPR3); -#ifdef CONFIG_STA_SUPPORT - IF_DEV_CONFIG_OPMODE_ON_STA(pAd) + +#ifdef RT2860 pAd->StaCfg.BBPR3 = BBPR3; -#endif // CONFIG_STA_SUPPORT // +#endif +#ifdef RT2870 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED) ) { @@ -8187,6 +8452,90 @@ VOID AsicEvaluateRxAnt( pAd->Mlme.bLowThroughput = TRUE; } } +#endif +#endif /* RT30xx */ +#ifdef RT30xx + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS | + fRTMP_ADAPTER_HALT_IN_PROGRESS | + fRTMP_ADAPTER_RADIO_OFF | + fRTMP_ADAPTER_NIC_NOT_EXIST | + fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS) || + OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE) +#ifdef RT30xx + || (pAd->EepromAccess) +#endif // RT30xx // + ) + return; + + + { + //if (pAd->StaCfg.Psm == PWR_SAVE) + // return; + } + + // two antenna selection mechanism- one is antenna diversity, the other is failed antenna remove + // one is antenna diversity:there is only one antenna can rx and tx + // the other is failed antenna remove:two physical antenna can rx and tx + if (pAd->NicConfig2.field.AntDiversity) + { + DBGPRINT(RT_DEBUG_TRACE,("AntDiv - before evaluate Pair1-Ant (%d,%d)\n", + pAd->RxAnt.Pair1PrimaryRxAnt, pAd->RxAnt.Pair1SecondaryRxAnt)); + + AsicSetRxAnt(pAd, pAd->RxAnt.Pair1SecondaryRxAnt); + + pAd->RxAnt.EvaluatePeriod = 1; // 1:Means switch to SecondaryRxAnt, 0:Means switch to Pair1PrimaryRxAnt + pAd->RxAnt.FirstPktArrivedWhenEvaluate = FALSE; + pAd->RxAnt.RcvPktNumWhenEvaluate = 0; + + // a one-shot timer to end the evalution + // dynamic adjust antenna evaluation period according to the traffic + if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED)) + RTMPSetTimer(&pAd->Mlme.RxAntEvalTimer, 100); + else + RTMPSetTimer(&pAd->Mlme.RxAntEvalTimer, 300); + } + else + { + if (pAd->StaCfg.Psm == PWR_SAVE) + return; + + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BBPR3); + BBPR3 &= (~0x18); + if(pAd->Antenna.field.RxPath == 3) + { + BBPR3 |= (0x10); + } + else if(pAd->Antenna.field.RxPath == 2) + { + BBPR3 |= (0x8); + } + else if(pAd->Antenna.field.RxPath == 1) + { + BBPR3 |= (0x0); + } + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BBPR3); + } +#endif /* RT30xx */ + + if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED) + ) + { + ULONG TxTotalCnt = pAd->RalinkCounters.OneSecTxNoRetryOkCount + + pAd->RalinkCounters.OneSecTxRetryOkCount + + pAd->RalinkCounters.OneSecTxFailCount; + + // dynamic adjust antenna evaluation period according to the traffic + if (TxTotalCnt > 50) + { + RTMPSetTimer(&pAd->Mlme.RxAntEvalTimer, 20); + pAd->Mlme.bLowThroughput = FALSE; + } + else + { + RTMPSetTimer(&pAd->Mlme.RxAntEvalTimer, 300); + pAd->Mlme.bLowThroughput = TRUE; + } + } } /* @@ -8209,19 +8558,10 @@ VOID AsicRxAntEvalTimeout( IN PVOID SystemSpecific3) { RTMP_ADAPTER *pAd = (RTMP_ADAPTER *)FunctionContext; -#ifdef CONFIG_STA_SUPPORT UCHAR BBPR3 = 0; CHAR larger = -127, rssi0, rssi1, rssi2; -#endif // CONFIG_STA_SUPPORT // -#ifdef RALINK_ATE - if (ATE_ON(pAd)) - return; -#endif // RALINK_ATE // - - -#ifdef CONFIG_STA_SUPPORT - IF_DEV_CONFIG_OPMODE_ON_STA(pAd) +#ifndef RT30xx { if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS) || RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS) || @@ -8279,11 +8619,111 @@ VOID AsicRxAntEvalTimeout( BBPR3 |= (0x0); } RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BBPR3); +#ifdef RT2860 pAd->StaCfg.BBPR3 = BBPR3; +#endif } +#endif /* RT30xx */ +#ifdef RT30xx + if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS | + fRTMP_ADAPTER_HALT_IN_PROGRESS | + fRTMP_ADAPTER_RADIO_OFF | + fRTMP_ADAPTER_NIC_NOT_EXIST) || + OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE) +#ifdef RT30xx + || (pAd->EepromAccess) +#endif // RT30xx // + ) + return; -#endif // CONFIG_STA_SUPPORT // + { + //if (pAd->StaCfg.Psm == PWR_SAVE) + // return; + if (pAd->NicConfig2.field.AntDiversity) + { + if ((pAd->RxAnt.RcvPktNumWhenEvaluate != 0) && (pAd->RxAnt.Pair1AvgRssi[pAd->RxAnt.Pair1SecondaryRxAnt] >= pAd->RxAnt.Pair1AvgRssi[pAd->RxAnt.Pair1PrimaryRxAnt])) + { + UCHAR temp; + + // + // select PrimaryRxAntPair + // Role change, Used Pair1SecondaryRxAnt as PrimaryRxAntPair. + // Since Pair1SecondaryRxAnt Quality good than Pair1PrimaryRxAnt + // + temp = pAd->RxAnt.Pair1PrimaryRxAnt; + pAd->RxAnt.Pair1PrimaryRxAnt = pAd->RxAnt.Pair1SecondaryRxAnt; + pAd->RxAnt.Pair1SecondaryRxAnt = temp; + + pAd->RxAnt.Pair1LastAvgRssi = (pAd->RxAnt.Pair1AvgRssi[pAd->RxAnt.Pair1SecondaryRxAnt] >> 3); + pAd->RxAnt.EvaluateStableCnt = 0; + } + else + { + // if the evaluated antenna is not better than original, switch back to original antenna + AsicSetRxAnt(pAd, pAd->RxAnt.Pair1PrimaryRxAnt); + pAd->RxAnt.EvaluateStableCnt ++; + } + + pAd->RxAnt.EvaluatePeriod = 0; // 1:Means switch to SecondaryRxAnt, 0:Means switch to Pair1PrimaryRxAnt + + DBGPRINT(RT_DEBUG_TRACE,("AsicRxAntEvalAction::After Eval(fix in #%d), <%d, %d>, RcvPktNumWhenEvaluate=%ld\n", + pAd->RxAnt.Pair1PrimaryRxAnt, (pAd->RxAnt.Pair1AvgRssi[0] >> 3), (pAd->RxAnt.Pair1AvgRssi[1] >> 3), pAd->RxAnt.RcvPktNumWhenEvaluate)); + } + else + { + if (pAd->StaCfg.Psm == PWR_SAVE) + return; + + // if the traffic is low, use average rssi as the criteria + if (pAd->Mlme.bLowThroughput == TRUE) + { + rssi0 = pAd->StaCfg.RssiSample.LastRssi0; + rssi1 = pAd->StaCfg.RssiSample.LastRssi1; + rssi2 = pAd->StaCfg.RssiSample.LastRssi2; + } + else + { + rssi0 = pAd->StaCfg.RssiSample.AvgRssi0; + rssi1 = pAd->StaCfg.RssiSample.AvgRssi1; + rssi2 = pAd->StaCfg.RssiSample.AvgRssi2; + } + + if(pAd->Antenna.field.RxPath == 3) + { + larger = max(rssi0, rssi1); + + if (larger > (rssi2 + 20)) + pAd->Mlme.RealRxPath = 2; + else + pAd->Mlme.RealRxPath = 3; + } + else if(pAd->Antenna.field.RxPath == 2) + { + if (rssi0 > (rssi1 + 20)) + pAd->Mlme.RealRxPath = 1; + else + pAd->Mlme.RealRxPath = 2; + } + + RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BBPR3); + BBPR3 &= (~0x18); + if(pAd->Mlme.RealRxPath == 3) + { + BBPR3 |= (0x10); + } + else if(pAd->Mlme.RealRxPath == 2) + { + BBPR3 |= (0x8); + } + else if(pAd->Mlme.RealRxPath == 1) + { + BBPR3 |= (0x0); + } + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BBPR3); + } + } +#endif /* RT30xx */ } @@ -8350,9 +8790,6 @@ BOOLEAN RTMPCheckEntryEnableAutoRateSwitch( { BOOLEAN result = TRUE; - -#ifdef CONFIG_STA_SUPPORT - IF_DEV_CONFIG_OPMODE_ON_STA(pAd) { // only associated STA counts if (pEntry && (pEntry->ValidAsCLI) && (pEntry->Sst == SST_ASSOC)) @@ -8361,15 +8798,7 @@ BOOLEAN RTMPCheckEntryEnableAutoRateSwitch( } else result = FALSE; - -#ifdef QOS_DLS_SUPPORT - if (pEntry && (pEntry->ValidAsDls)) - result = pAd->StaCfg.bAutoTxRateSwitch; -#endif // QOS_DLS_SUPPORT // } -#endif // CONFIG_STA_SUPPORT // - - return result; } @@ -8378,14 +8807,9 @@ BOOLEAN RTMPCheckEntryEnableAutoRateSwitch( BOOLEAN RTMPAutoRateSwitchCheck( IN PRTMP_ADAPTER pAd) { + if (pAd->StaCfg.bAutoTxRateSwitch) + return TRUE; -#ifdef CONFIG_STA_SUPPORT - IF_DEV_CONFIG_OPMODE_ON_STA(pAd) - { - if (pAd->StaCfg.bAutoTxRateSwitch) - return TRUE; - } -#endif // CONFIG_STA_SUPPORT // return FALSE; } @@ -8411,13 +8835,7 @@ UCHAR RTMPStaFixedTxMode( { UCHAR tx_mode = FIXED_TXMODE_HT; - -#ifdef CONFIG_STA_SUPPORT - IF_DEV_CONFIG_OPMODE_ON_STA(pAd) - { - tx_mode = (UCHAR)pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode; - } -#endif // CONFIG_STA_SUPPORT // + tx_mode = (UCHAR)pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode; return tx_mode; } @@ -8474,7 +8892,6 @@ VOID RTMPUpdateLegacyTxSetting( } } -#ifdef CONFIG_STA_SUPPORT /* ========================================================================== Description: @@ -8505,7 +8922,12 @@ VOID AsicStaBbpTuning( && (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED) ) && !(OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE)) +#ifdef RT2860 && (pAd->bPCIclkOff == FALSE)) +#endif +#ifdef RT2870 + ) +#endif { RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R66, &OrigR66Value); R66 = OrigR66Value; @@ -8517,6 +8939,45 @@ VOID AsicStaBbpTuning( if (pAd->LatchRfRegs.Channel <= 14) { //BG band +#ifdef RT2870 + // RT3070 is a no LNA solution, it should have different control regarding to AGC gain control + // Otherwise, it will have some throughput side effect when low RSSI +#ifndef RT30xx + if (IS_RT3070(pAd)) +#endif +#ifdef RT30xx + if (IS_RT30xx(pAd)) +#endif + { + if (Rssi > RSSI_FOR_MID_LOW_SENSIBILITY) + { + R66 = 0x1C + 2*GET_LNA_GAIN(pAd) + 0x20; + if (OrigR66Value != R66) + { +#ifndef RT30xx + RTUSBWriteBBPRegister(pAd, BBP_R66, R66); +#endif +#ifdef RT30xx + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66); +#endif + } + } + else + { + R66 = 0x1C + 2*GET_LNA_GAIN(pAd); + if (OrigR66Value != R66) + { +#ifndef RT30xx + RTUSBWriteBBPRegister(pAd, BBP_R66, R66); +#endif +#ifdef RT30xx + RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66); +#endif + } + } + } + else +#endif // RT2870 // { if (Rssi > RSSI_FOR_MID_LOW_SENSIBILITY) { @@ -8582,6 +9043,7 @@ VOID AsicStaBbpTuning( } } +#ifdef RT2860 VOID AsicResetFromDMABusy( IN PRTMP_ADAPTER pAd) { @@ -8681,7 +9143,7 @@ VOID AsicResetPBF( DBGPRINT(RT_DEBUG_TRACE, ("<--- Asic HardReset PBF !!!! \n")); } } -#endif // CONFIG_STA_SUPPORT // +#endif /* RT2860 */ VOID RTMPSetAGCInitValue( IN PRTMP_ADAPTER pAd, @@ -8701,13 +9163,11 @@ VOID RTMPSetAGCInitValue( R66 = (UCHAR)(0x32 + (GET_LNA_GAIN(pAd)*5)/3); RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66); } -#ifdef DOT11_N_SUPPORT else { R66 = (UCHAR)(0x3A + (GET_LNA_GAIN(pAd)*5)/3); RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66); } -#endif // DOT11_N_SUPPORT // } } @@ -8722,6 +9182,15 @@ VOID AsicTurnOffRFClk( UCHAR index; RTMP_RF_REGS *RFRegTable; +#ifdef RT30xx + // The RF programming sequence is difference between 3xxx and 2xxx + if (IS_RT3090(pAd)) + { + RT30xxLoadRFSleepModeSetup(pAd); // add by johnli, RF power sequence setup, load RF sleep-mode setup + } + else + { +#endif // RT30xx // RFRegTable = RF2850RegTable; switch (pAd->RfIcType) @@ -8763,6 +9232,10 @@ VOID AsicTurnOffRFClk( default: break; } +#ifdef RT30xx + } +#endif // RT30xx // + } @@ -8776,6 +9249,14 @@ VOID AsicTurnOnRFClk( UCHAR index; RTMP_RF_REGS *RFRegTable; +#ifdef RT30xx + // The RF programming sequence is difference between 3xxx and 2xxx + if (IS_RT3090(pAd)) + { + } + else + { +#endif // RT30xx // RFRegTable = RF2850RegTable; switch (pAd->RfIcType) @@ -8822,9 +9303,14 @@ VOID AsicTurnOnRFClk( break; } +#ifndef RT30xx DBGPRINT(RT_DEBUG_TRACE, ("AsicTurnOnRFClk#%d(RF=%d, ) , R2=0x%08x\n", Channel, pAd->RfIcType, R2)); +#endif +#ifdef RT30xx + } +#endif // RT30xx // } |