mlme.c

来自「ralink最新rt3070 usb wifi 无线网卡驱动程序」· C语言 代码 · 共 1,979 行 · 第 1/5 页

C
1,979
字号
		{60, 0x98402ec8, 0x984c0692, 0x98158a55, 0x980ed183},		{62, 0x98402ec8, 0x984c0692, 0x98158a55, 0x980ed193},		{64, 0x98402ec8, 0x984c0692, 0x98158a55, 0x980ed1a3}, // Plugfest#4, Day4, change RFR3 left4th 9->5.		// 802.11 HyperLan 2		{100, 0x98402ec8, 0x984c06b2, 0x98178a55, 0x980ed783},				// 2008.04.30 modified 		// The system team has AN to improve the EVM value 		// for channel 102 to 108 for the RT2850/RT2750 dual band solution.		{102, 0x98402ec8, 0x985c06b2, 0x98578a55, 0x980ed793},		{104, 0x98402ec8, 0x985c06b2, 0x98578a55, 0x980ed1a3},		{108, 0x98402ecc, 0x985c0a32, 0x98578a55, 0x980ed193},		{110, 0x98402ecc, 0x984c0a36, 0x98178a55, 0x980ed183},		{112, 0x98402ecc, 0x984c0a36, 0x98178a55, 0x980ed19b},		{116, 0x98402ecc, 0x984c0a3a, 0x98178a55, 0x980ed1a3},		{118, 0x98402ecc, 0x984c0a3e, 0x98178a55, 0x980ed193},		{120, 0x98402ec4, 0x984c0382, 0x98178a55, 0x980ed183},		{124, 0x98402ec4, 0x984c0382, 0x98178a55, 0x980ed193},		{126, 0x98402ec4, 0x984c0382, 0x98178a55, 0x980ed15b}, // 0x980ed1bb->0x980ed15b required by Rory 20070927		{128, 0x98402ec4, 0x984c0382, 0x98178a55, 0x980ed1a3},		{132, 0x98402ec4, 0x984c0386, 0x98178a55, 0x980ed18b},		{134, 0x98402ec4, 0x984c0386, 0x98178a55, 0x980ed193},		{136, 0x98402ec4, 0x984c0386, 0x98178a55, 0x980ed19b},		{140, 0x98402ec4, 0x984c038a, 0x98178a55, 0x980ed183},		// 802.11 UNII		{149, 0x98402ec4, 0x984c038a, 0x98178a55, 0x980ed1a7},		{151, 0x98402ec4, 0x984c038e, 0x98178a55, 0x980ed187},		{153, 0x98402ec4, 0x984c038e, 0x98178a55, 0x980ed18f},		{157, 0x98402ec4, 0x984c038e, 0x98178a55, 0x980ed19f},		{159, 0x98402ec4, 0x984c038e, 0x98178a55, 0x980ed1a7},		{161, 0x98402ec4, 0x984c0392, 0x98178a55, 0x980ed187},		{165, 0x98402ec4, 0x984c0392, 0x98178a55, 0x980ed197},		// Japan		{184, 0x95002ccc, 0x9500491e, 0x9509be55, 0x950c0a0b},		{188, 0x95002ccc, 0x95004922, 0x9509be55, 0x950c0a13},		{192, 0x95002ccc, 0x95004926, 0x9509be55, 0x950c0a1b},		{196, 0x95002ccc, 0x9500492a, 0x9509be55, 0x950c0a23},		{208, 0x95002ccc, 0x9500493a, 0x9509be55, 0x950c0a13},		{212, 0x95002ccc, 0x9500493e, 0x9509be55, 0x950c0a1b},		{216, 0x95002ccc, 0x95004982, 0x9509be55, 0x950c0a23},		// still lack of MMAC(Japan) ch 34,38,42,46};UCHAR	NUM_OF_2850_CHNL = (sizeof(RF2850RegTable) / sizeof(RTMP_RF_REGS));FREQUENCY_ITEM FreqItems3020[] ={		/**************************************************/	// ISM : 2.4 to 2.483 GHz                         //	/**************************************************/	// 11g	/**************************************************/	//-CH---N-------R---K-----------	{1,    241,  2,  2},	{2,    241,	 2,  7},	{3,    242,	 2,  2},	{4,    242,	 2,  7},	{5,    243,	 2,  2},	{6,    243,	 2,  7},	{7,    244,	 2,  2},	{8,    244,	 2,  7},	{9,    245,	 2,  2},	{10,   245,	 2,  7},	{11,   246,	 2,  2},	{12,   246,	 2,  7},	{13,   247,	 2,  2},	{14,   248,	 2,  4},};//2008/07/10:KH Modified to share this variableUCHAR	NUM_OF_3020_CHNL=(sizeof(FreqItems3020) / sizeof(FREQUENCY_ITEM));/*	==========================================================================	Description:		initialize the MLME task and its data structure (queue, spinlock, 		timer, state machines).	IRQL = PASSIVE_LEVEL	Return:		always return NDIS_STATUS_SUCCESS	==========================================================================*/NDIS_STATUS MlmeInit(	IN PRTMP_ADAPTER pAd) {	NDIS_STATUS Status = NDIS_STATUS_SUCCESS;	DBGPRINT(RT_DEBUG_TRACE, ("--> MLME Initialize\n"));	do 	{		Status = MlmeQueueInit(&pAd->Mlme.Queue);		if(Status != NDIS_STATUS_SUCCESS) 			break;		pAd->Mlme.bRunning = FALSE;		NdisAllocateSpinLock(&pAd->Mlme.TaskLock);#ifdef CONFIG_STA_SUPPORT		IF_DEV_CONFIG_OPMODE_ON_STA(pAd)		{			BssTableInit(&pAd->ScanTab);			// init STA state machines			AssocStateMachineInit(pAd, &pAd->Mlme.AssocMachine, pAd->Mlme.AssocFunc);			AuthStateMachineInit(pAd, &pAd->Mlme.AuthMachine, pAd->Mlme.AuthFunc);			AuthRspStateMachineInit(pAd, &pAd->Mlme.AuthRspMachine, pAd->Mlme.AuthRspFunc);			SyncStateMachineInit(pAd, &pAd->Mlme.SyncMachine, pAd->Mlme.SyncFunc);			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);		// Init mlme periodic timer		RTMPInitTimer(pAd, &pAd->Mlme.PeriodicTimer, GET_TIMER_FUNCTION(MlmePeriodicExec), pAd, TRUE);		// Set mlme periodic timer		RTMPSetTimer(&pAd->Mlme.PeriodicTimer, MLME_TASK_EXEC_INTV);		// software-based RX Antenna diversity		RTMPInitTimer(pAd, &pAd->Mlme.RxAntEvalTimer, GET_TIMER_FUNCTION(AsicRxAntEvalTimeout), pAd, FALSE);#ifdef CONFIG_STA_SUPPORT#endif // CONFIG_STA_SUPPORT //	} 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;	// 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)) 	{		if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_MLME_RESET_IN_PROGRESS) ||			RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS) ||			RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))		{			DBGPRINT(RT_DEBUG_TRACE, ("Device Halted or Removed or MlmeRest, exit MlmeHandler! (queue num = %ld)\n", pAd->Mlme.Queue.Num));			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;				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;#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;					default:					DBGPRINT(RT_DEBUG_TRACE, ("ERROR: Illegal machine %ld in MlmeHandler()\n", Elem->Machine));					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;#ifdef RT3070	UINT32		TxPinCfg = 0x00050F0F;#endif // RT3070 //	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	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);		RTMPCancelTimer(&pAd->MlmeAux.DisassocTimer,	&Cancelled);		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 //	RTMPCancelTimer(&pAd->Mlme.PeriodicTimer,		&Cancelled);	RTMPCancelTimer(&pAd->Mlme.RxAntEvalTimer,		&Cancelled);	if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))	{		// 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	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;

⌨️ 快捷键说明

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