⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mlme.c

📁 Linux下的RT系列无线网卡驱动,可以直接在x86平台上编译
💻 C
📖 第 1 页 / 共 5 页
字号:
		// software-based RX Antenna diversity		RTMPInitTimer(pAd, &pAd->Mlme.RxAntEvalTimer, GET_TIMER_FUNCTION(AsicRxAntEvalTimeout), pAd, FALSE);	} while (FALSE);	DBGPRINT(RT_DEBUG_TRACE, ("<-- MLME Initialize\n"));	return Status;}/*	==========================================================================	Description:		main loop of the MLME	Pre:		Mlme has to be initialized, and there are something inside the queue	Note:		This function is invoked from MPSetInformation and MPReceive;		This task guarantee only one MlmeHandler will run. 	IRQL = DISPATCH_LEVEL		========================================================================== */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	NdisAcquireSpinLock(&pAd->Mlme.TaskLock);	if(pAd->Mlme.bRunning) 	{		NdisReleaseSpinLock(&pAd->Mlme.TaskLock);		return;	} 	else 	{		pAd->Mlme.bRunning = TRUE;	}	NdisReleaseSpinLock(&pAd->Mlme.TaskLock);	while (!MlmeQueueEmpty(&pAd->Mlme.Queue)) 	{		//From message type, determine which state machine I should drive		if (MlmeDequeue(&pAd->Mlme.Queue, &Elem)) 		{			// if dequeue success			switch (Elem->Machine) 			{				// STA state machines#ifdef	CONFIG_STA_SUPPORT				case ASSOC_STATE_MACHINE:					StateMachinePerformAction(pAd, &pAd->Mlme.AssocMachine, Elem);					break;				case AUTH_STATE_MACHINE:					StateMachinePerformAction(pAd, &pAd->Mlme.AuthMachine, Elem);					break;				case AUTH_RSP_STATE_MACHINE:					StateMachinePerformAction(pAd, &pAd->Mlme.AuthRspMachine, Elem);					break;				case SYNC_STATE_MACHINE:					StateMachinePerformAction(pAd, &pAd->Mlme.SyncMachine, Elem);					break;				case MLME_CNTL_STATE_MACHINE:					MlmeCntlMachinePerformAction(pAd, &pAd->Mlme.CntlMachine, Elem);					break;				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;#endif // CONFIG_STA_SUPPORT //										case ACTION_STATE_MACHINE:					StateMachinePerformAction(pAd, &pAd->Mlme.ActMachine, Elem);					break;					default:					DBGPRINT(RT_DEBUG_TRACE, ("ERROR: Illegal machine in MlmeHandler()\n"));					break;			} // end of switch			// free MLME element			Elem->Occupied = FALSE;			Elem->MsgLen = 0;		}		else {			DBGPRINT_ERR(("MlmeHandler: MlmeQueue empty\n"));		}	}	NdisAcquireSpinLock(&pAd->Mlme.TaskLock);	pAd->Mlme.bRunning = FALSE;	NdisReleaseSpinLock(&pAd->Mlme.TaskLock);}/*	==========================================================================	Description:		Destructor of MLME (Destroy queue, state machine, spin lock and timer)	Parameters:		Adapter - NIC Adapter pointer	Post:		The MLME task will no longer work properly	IRQL = PASSIVE_LEVEL	========================================================================== */VOID MlmeHalt(	IN PRTMP_ADAPTER pAd) {	BOOLEAN 	  Cancelled;	DBGPRINT(RT_DEBUG_TRACE, ("==> MlmeHalt\n"));	if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))	{		// disable BEACON generation and other BEACON related hardware timers		AsicDisableSync(pAd);	}#ifdef CONFIG_STA_SUPPORT	// Cancel pending timers	RTMPCancelTimer(&pAd->MlmeAux.AssocTimer,		&Cancelled);	RTMPCancelTimer(&pAd->MlmeAux.ReassocTimer,		&Cancelled);	RTMPCancelTimer(&pAd->MlmeAux.DisassocTimer,	&Cancelled);	RTMPCancelTimer(&pAd->MlmeAux.AuthTimer,		&Cancelled);	RTMPCancelTimer(&pAd->MlmeAux.BeaconTimer,		&Cancelled);	RTMPCancelTimer(&pAd->MlmeAux.ScanTimer,		&Cancelled);#endif // CONFIG_STA_SUPPORT //	RTMPCancelTimer(&pAd->Mlme.PeriodicTimer,		&Cancelled);	RTMPCancelTimer(&pAd->Mlme.RxAntEvalTimer,		&Cancelled);#ifdef CONFIG_STA_SUPPORT	RTMPCancelTimer(&pAd->Mlme.LinkDownTimer,		&Cancelled);#endif // CONFIG_STA_SUPPORT //	if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))	{		// Set LED		RTMPSetLED(pAd, LED_HALT);	}	RTMPusecDelay(5000);    //  5 msec to gurantee Ant Diversity timer canceled	MlmeQueueDestroy(&pAd->Mlme.Queue);	NdisFreeSpinLock(&pAd->Mlme.TaskLock);	DBGPRINT(RT_DEBUG_TRACE, ("<== MlmeHalt\n"));}VOID MlmeResetRalinkCounters(	IN  PRTMP_ADAPTER   pAd){	pAd->RalinkCounters.LastOneSecRxOkDataCnt = pAd->RalinkCounters.OneSecRxOkDataCnt;	// clear all OneSecxxx counters.	pAd->RalinkCounters.OneSecBeaconSentCnt = 0;	pAd->RalinkCounters.OneSecFalseCCACnt = 0;	pAd->RalinkCounters.OneSecRxFcsErrCnt = 0;	pAd->RalinkCounters.OneSecRxOkCnt = 0;	pAd->RalinkCounters.OneSecTxFailCount = 0;	pAd->RalinkCounters.OneSecTxNoRetryOkCount = 0;	pAd->RalinkCounters.OneSecTxRetryOkCount = 0;	pAd->RalinkCounters.OneSecRxOkDataCnt = 0;	// TODO: for debug only. to be removed	pAd->RalinkCounters.OneSecOsTxCount[QID_AC_BE] = 0;	pAd->RalinkCounters.OneSecOsTxCount[QID_AC_BK] = 0;	pAd->RalinkCounters.OneSecOsTxCount[QID_AC_VI] = 0;	pAd->RalinkCounters.OneSecOsTxCount[QID_AC_VO] = 0;	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;	// 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)) || 		(RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF)) ||		(RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_MEASUREMENT)) ||				(RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS)))		return;	#ifdef CONFIG_STA_SUPPORT    // Do nothing if monitor mode is on	if (MONITOR_ON(pAd))		return;#endif // CONFIG_STA_SUPPORT //	//	RECBATimerTimeout(SystemSpecific1,FunctionContext,SystemSpecific2,SystemSpecific3);	pAd->Mlme.PeriodicRound ++;	// Normal 1 second Mlme PeriodicExec.	if (pAd->Mlme.PeriodicRound %MLME_TASK_EXEC_MULTIPLE == 0)	{                pAd->Mlme.OneSecPeriodicRound ++;#ifdef RALINK_ATE    	if (pAd->ate.Mode != ATE_STOP)    	{			if (pAd->ate.bRxFer == 1)			{				pAd->ate.RxTotalCnt += pAd->ate.RxCntPerSec;			    printk("MlmePeriodicExec: Rx packet cnt = %ld/%ld\n", pAd->ate.RxCntPerSec, pAd->ate.RxTotalCnt);				pAd->ate.RxCntPerSec = 0;				if (pAd->ate.RxAntennaSel == 0)					printk("MlmePeriodicExec: Rx AvgRssi0=%d, AvgRssi1=%d, AvgRssi2=%d\n\n",						pAd->ate.AvgRssi0, pAd->ate.AvgRssi1, pAd->ate.AvgRssi2);				else					printk("MlmePeriodicExec: Rx AvgRssi=%d\n\n", pAd->ate.AvgRssi0);			}			MlmeResetRalinkCounters(pAd);			return;    	}#endif // RALINK_ATE //		if (rx_Total)		{			DBGPRINT(RT_DEBUG_LOUD,("%lu/%lu (%lu%%) , TxDone %ld\n", rx_AMSDU, rx_Total,  (rx_AMSDU*100)/rx_Total, pAd->RalinkCounters.OneSecDmaDoneCount[0]));			// 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();			}			else			{				pAd->IndicateMediaState = NdisMediaStateDisconnected;				RTMP_IndicateMediaState();			}		}		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);																										   		// Need statistics after read counter. So put after NICUpdateRawCounters		ORIBATimerTimeout(pAd);		// if MGMT RING is full more than twice within 1 second, we consider there's		// a hardware problem stucking the TX path. In this case, try a hardware reset		// to recover the system	//	if (pAd->RalinkCounters.MgmtRingFullCount >= 2)	//		RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HARDWARE_ERROR);	//	else	//		pAd->RalinkCounters.MgmtRingFullCount = 0;		// The time period for checking antenna is according to traffic		if (pAd->Mlme.bEnableAutoAntennaCheck)		{			TxTotalCnt = pAd->RalinkCounters.OneSecTxNoRetryOkCount + 							 pAd->RalinkCounters.OneSecTxRetryOkCount + 							 pAd->RalinkCounters.OneSecTxFailCount;			if (TxTotalCnt > 50)			{				if (pAd->Mlme.OneSecPeriodicRound % 10 == 0)				{					AsicEvaluateRxAnt(pAd);				}			}			else			{				if (pAd->Mlme.OneSecPeriodicRound % 3 == 0)				{					AsicEvaluateRxAnt(pAd);				}			}		}#ifdef CONFIG_STA_SUPPORT//	else		STAMlmePeriodicExec(pAd);#endif // CONFIG_STA_SUPPORT //		MlmeResetRalinkCounters(pAd);		MlmeHandler(pAd);	}}#ifdef CONFIG_STA_SUPPORTVOID STAMlmePeriodicExec(	PRTMP_ADAPTER pAd){	ULONG			    TxTotalCnt;    TX_RTY_CFG_STRUC	CurTxRryCfg;//// We return here in ATE mode, because the statistics // that ATE needs are not collected via this routine.//#ifdef RALINK_ATE	if (pAd->ate.Mode != ATE_STOP)		return;#endif // RALINK_ATE //#ifdef WPA_SUPPLICANT_SUPPORT    if (pAd->StaCfg.WpaSupplicantUP == 0)    #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;    }	DBGPRINT(RT_DEBUG_INFO,("MMCHK - CommonCfg.Ssid[%d]=%c%c%c%c... MlmeAux.Ssid[%d]=%c%c%c%c...\n",			pAd->CommonCfg.SsidLen, pAd->CommonCfg.Ssid[0], pAd->CommonCfg.Ssid[1], pAd->CommonCfg.Ssid[2], pAd->CommonCfg.Ssid[3],			pAd->MlmeAux.SsidLen, pAd->MlmeAux.Ssid[0], pAd->MlmeAux.Ssid[1], pAd->MlmeAux.Ssid[2], pAd->MlmeAux.Ssid[3]));	TxTotalCnt = pAd->RalinkCounters.OneSecTxNoRetryOkCount + 					 pAd->RalinkCounters.OneSecTxRetryOkCount + 					 pAd->RalinkCounters.OneSecTxFailCount;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -