mlme.c
来自「ralink最新rt3070 usb wifi 无线网卡驱动程序」· C语言 代码 · 共 1,979 行 · 第 1/5 页
C
1,979 行
pAd->RalinkCounters.OneSecDmaDoneCount[QID_AC_BE] = 0; pAd->RalinkCounters.OneSecDmaDoneCount[QID_AC_BK] = 0; pAd->RalinkCounters.OneSecDmaDoneCount[QID_AC_VI] = 0; pAd->RalinkCounters.OneSecDmaDoneCount[QID_AC_VO] = 0; pAd->RalinkCounters.OneSecTxDoneCount = 0; pAd->RalinkCounters.OneSecRxCount = 0; pAd->RalinkCounters.OneSecTxAggregationCount = 0; pAd->RalinkCounters.OneSecRxAggregationCount = 0; return;}unsigned long rx_AMSDU;unsigned long rx_Total;/* ========================================================================== Description: This routine is executed periodically to - 1. Decide if it's a right time to turn on PwrMgmt bit of all outgoiing frames 2. Calculate ChannelQuality based on statistics of the last period, so that TX rate won't toggling very frequently between a successful TX and a failed TX. 3. If the calculated ChannelQuality indicated current connection not healthy, then a ROAMing attempt is tried here. IRQL = DISPATCH_LEVEL ========================================================================== */#define ADHOC_BEACON_LOST_TIME (8*OS_HZ) // 8 secVOID MlmePeriodicExec( IN PVOID SystemSpecific1, IN PVOID FunctionContext, IN PVOID SystemSpecific2, IN PVOID SystemSpecific3) { ULONG TxTotalCnt; PRTMP_ADAPTER pAd = (RTMP_ADAPTER *)FunctionContext;#ifdef CONFIG_STA_SUPPORT#endif // CONFIG_STA_SUPPORT // // 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_RADIO_OFF | fRTMP_ADAPTER_RADIO_MEASUREMENT | fRTMP_ADAPTER_RESET_IN_PROGRESS)))) return; 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)) return; if (pAd->Mlme.PeriodicRound & 0x1) { // This is the fix for wifi 11n extension channel overlapping test case. for 2860D if (((pAd->MACVersion & 0xffff) == 0x0101) && (STA_TGN_WIFI_ON(pAd)) && (pAd->CommonCfg.IOTestParm.bToggle == FALSE)) { RTMP_IO_WRITE32(pAd, TXOP_CTRL_CFG, 0x24Bf); pAd->CommonCfg.IOTestParm.bToggle = TRUE; } else if ((STA_TGN_WIFI_ON(pAd)) && ((pAd->MACVersion & 0xffff) == 0x0101)) { RTMP_IO_WRITE32(pAd, TXOP_CTRL_CFG, 0x243f); pAd->CommonCfg.IOTestParm.bToggle = FALSE; } } }#endif // CONFIG_STA_SUPPORT // pAd->bUpdateBcnCntDone = FALSE; // RECBATimerTimeout(SystemSpecific1,FunctionContext,SystemSpecific2,SystemSpecific3); pAd->Mlme.PeriodicRound ++;#ifdef RT2870 // execute every 100ms, update the Tx FIFO Cnt for update Tx Rate. NICUpdateFifoStaCounters(pAd);#endif // RT2870 // // 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. if (pAd->Mlme.PeriodicRound %MLME_TASK_EXEC_MULTIPLE == 0) { 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) { // reset counters rx_AMSDU = 0; rx_Total = 0; } //ORIBATimerTimeout(pAd); // Media status changed, report to NDIS if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_MEDIA_STATE_CHANGE)) { RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_MEDIA_STATE_CHANGE); if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED)) { pAd->IndicateMediaState = NdisMediaStateConnected; RTMP_IndicateMediaState(pAd); } else { pAd->IndicateMediaState = NdisMediaStateDisconnected; RTMP_IndicateMediaState(pAd); } } NdisGetSystemUpTime(&pAd->Mlme.Now32); // add the most up-to-date h/w raw counters into software variable, so that // 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) { TxTotalCnt = pAd->RalinkCounters.OneSecTxNoRetryOkCount + pAd->RalinkCounters.OneSecTxRetryOkCount + pAd->RalinkCounters.OneSecTxFailCount; // dynamic adjust antenna evaluation period according to the traffic if (TxTotalCnt > 50) { if (pAd->Mlme.OneSecPeriodicRound % 10 == 0) { AsicEvaluateRxAnt(pAd); } } else { if (pAd->Mlme.OneSecPeriodicRound % 3 == 0) { AsicEvaluateRxAnt(pAd); } } } }#ifdef CONFIG_STA_SUPPORT IF_DEV_CONFIG_OPMODE_ON_STA(pAd) STAMlmePeriodicExec(pAd);#endif // CONFIG_STA_SUPPORT // MlmeResetRalinkCounters(pAd);#ifdef CONFIG_STA_SUPPORT IF_DEV_CONFIG_OPMODE_ON_STA(pAd) { { // 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. // Software Patch Solution: // 1. Polling debug state register 0x10F4 every one second. // 2. If in 0x10F4 the ((bit29==1) && (bit7==1)) OR ((bit29==1) && (bit5==1)), it means the deadlock has occurred. // 3. If the deadlock occurred, reset MAC/BBP by setting 0x1004 to 0x0001 for a while then setting it back to 0x000C again. UINT32 MacReg = 0; RTMP_IO_READ32(pAd, 0x10F4, &MacReg); if (((MacReg & 0x20000000) && (MacReg & 0x80)) || ((MacReg & 0x20000000) && (MacReg & 0x20))) { RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x1); RTMPusecDelay(1); RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0xC); DBGPRINT(RT_DEBUG_WARN,("Warning, MAC specific condition occurs \n")); } } }#endif // CONFIG_STA_SUPPORT // RT28XX_MLME_HANDLER(pAd); } pAd->bUpdateBcnCntDone = FALSE;}#ifdef CONFIG_STA_SUPPORTVOID STAMlmePeriodicExec( PRTMP_ADAPTER pAd){ ULONG TxTotalCnt; int i;//// 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; } if ((pAd->PreMediaState != pAd->IndicateMediaState) && (pAd->CommonCfg.bWirelessEvent)) { if (pAd->IndicateMediaState == NdisMediaStateConnected) { RTMPSendWirelessEvent(pAd, IW_STA_LINKUP_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0); } pAd->PreMediaState = pAd->IndicateMediaState; } AsicStaBbpTuning(pAd); TxTotalCnt = pAd->RalinkCounters.OneSecTxNoRetryOkCount + pAd->RalinkCounters.OneSecTxRetryOkCount + pAd->RalinkCounters.OneSecTxFailCount; if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED)) { // update channel quality for Roaming and UI LinkQuality display MlmeCalculateChannelQuality(pAd, pAd->Mlme.Now32); } // must be AFTER MlmeDynamicTxRateSwitching() because it needs to know if // Radio is currently in noisy environment if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) AsicAdjustTxPower(pAd); 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)) MlmeCheckPsmChange(pAd, pAd->Mlme.Now32); pAd->RalinkCounters.LastOneSecTotalTxCount = TxTotalCnt; if ((pAd->StaCfg.LastBeaconRxTime + 1*OS_HZ < pAd->Mlme.Now32) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) && ((TxTotalCnt + pAd->RalinkCounters.OneSecRxOkCnt < 600))) { RTMPSetAGCInitValue(pAd, BW_20); DBGPRINT(RT_DEBUG_TRACE, ("MMCHK - No BEACON. restore R66 to the low bound(%d) \n", (0x2E + GET_LNA_GAIN(pAd)))); } //if ((pAd->RalinkCounters.OneSecTxNoRetryOkCount == 0) && // (pAd->RalinkCounters.OneSecTxRetryOkCount == 0)) { if (pAd->CommonCfg.bAPSDCapable && pAd->CommonCfg.APEdcaParm.bAPSDCapable) { // When APSD is enabled, the period changes as 20 sec if ((pAd->Mlme.OneSecPeriodicRound % 20) == 8) RTMPSendNullFrame(pAd, pAd->CommonCfg.TxRate, TRUE); } else { // Send out a NULL frame every 10 sec to inform AP that STA is still alive (Avoid being age out) if ((pAd->Mlme.OneSecPeriodicRound % 10) == 8) { if (pAd->CommonCfg.bWmmCapable) RTMPSendNullFrame(pAd, pAd->CommonCfg.TxRate, TRUE); else RTMPSendNullFrame(pAd, pAd->CommonCfg.TxRate, FALSE); } } } if (CQI_IS_DEAD(pAd->Mlme.ChannelQuality)) { DBGPRINT(RT_DEBUG_TRACE, ("MMCHK - No BEACON. Dead CQI. Auto Recovery attempt #%ld\n", pAd->RalinkCounters.BadCQIAutoRecoveryCount)); pAd->StaCfg.CCXAdjacentAPReportFlag = TRUE; pAd->StaCfg.CCXAdjacentAPLinkDownTime = pAd->StaCfg.LastBeaconRxTime; // 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 // // RTMPPatchMacBbpBug(pAd); MlmeAutoReconnectLastSSID(pAd); } else if (CQI_IS_BAD(pAd->Mlme.ChannelQuality)) { pAd->RalinkCounters.BadCQIAutoRecoveryCount ++; DBGPRINT(RT_DEBUG_TRACE, ("MMCHK - Bad CQI. Auto Recovery attempt #%ld\n", pAd->RalinkCounters.BadCQIAutoRecoveryCount)); MlmeAutoReconnectLastSSID(pAd); } // Add auto seamless roaming
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?