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

📄 connect.c

📁 r73模块的无线网卡在Linux下的驱动程序
💻 C
📖 第 1 页 / 共 4 页
字号:
VOID CntlWaitAssocProc(	IN PRTMP_ADAPTER pAd,	IN MLME_QUEUE_ELEM *Elem){	USHORT		Reason;	if (Elem->MsgType == MT2_ASSOC_CONF)	{		memcpy(&Reason, Elem->Msg, sizeof(USHORT));		if (Reason == MLME_SUCCESS)		{			LinkUp(pAd, BSS_INFRA);			pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;			DBGPRINT(RT_DEBUG_TRACE, "CNTL - Association successful on BSS #%d\n",pAd->MlmeAux.BssIdx);		}		else		{			// not success, try next BSS			DBGPRINT(RT_DEBUG_TRACE, "CNTL - Association fails on BSS #%d\n",pAd->MlmeAux.BssIdx);			pAd->MlmeAux.BssIdx++;			IterateOnBssTab(pAd);		}	}}/*	==========================================================================	Description:	==========================================================================*/VOID CntlWaitReassocProc(	IN PRTMP_ADAPTER pAd,	IN MLME_QUEUE_ELEM *Elem){	USHORT		Result;	if (Elem->MsgType == MT2_REASSOC_CONF)	{		memcpy(&Result, Elem->Msg, sizeof(USHORT));		if (Result == MLME_SUCCESS)		{			//			// NDIS requires a new Link UP indication but no Link Down for RE-ASSOC			//			LinkUp(pAd, BSS_INFRA);			pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;			DBGPRINT(RT_DEBUG_TRACE, "CNTL - Re-assocition successful on BSS #%d\n", pAd->MlmeAux.RoamIdx);		}		else		{			// reassoc failed, try to pick next BSS in the BSS Table			DBGPRINT(RT_DEBUG_TRACE, "CNTL - Re-assocition fails on BSS #%d\n", pAd->MlmeAux.RoamIdx);			pAd->MlmeAux.RoamIdx++;			IterateOnBssTab2(pAd);		}	}}/*	==========================================================================	Description:	==========================================================================*/VOID LinkUp(	IN PRTMP_ADAPTER pAd,	IN UCHAR BssType){	ULONG	Now;	TXRX_CSR4_STRUC NewTxRxCsr4, CurTxRxCsr4;	//	// ASSOC - DisassocTimeoutAction	// CNTL - Dis-associate successful	// !!! LINK DOWN !!!	// [88888] OID_802_11_SSID should have returned NDTEST_WEP_AP2(Returned: )	//	COPY_SETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG(pAd);	DBGPRINT(RT_DEBUG_TRACE, "!!! LINK UP !!! (Infra=%d, AID=%d, ssid=%s)\n",		BssType, pAd->ActiveCfg.Aid, pAd->PortCfg.Ssid);	if (BssType == BSS_ADHOC)	{		OPSTATUS_SET_FLAG(pAd, fOP_STATUS_ADHOC_ON);		OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_INFRA_ON);	}	else	{		OPSTATUS_SET_FLAG(pAd, fOP_STATUS_INFRA_ON);		OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_ADHOC_ON);	}	AsicSetBssid(pAd, pAd->PortCfg.Bssid);	AsicSetSlotTime(pAd, (BOOLEAN)pAd->PortCfg.UseShortSlotTime);	AsicSetEdcaParm(pAd, &pAd->PortCfg.APEdcaParm);	MlmeUpdateTxRates(pAd, TRUE);	memset(&pAd->DrsCounters, 0, sizeof(COUNTER_DRS));	Now = jiffies;	pAd->PortCfg.LastBeaconRxTime = Now;   // last RX timestamp	if ((pAd->PortCfg.TxPreamble != Rt802_11PreambleLong) &&		CAP_IS_SHORT_PREAMBLE_ON(pAd->ActiveCfg.CapabilityInfo))	{		DBGPRINT(RT_DEBUG_INFO, "CNTL - !!! Set to short preamble!!!\n");		MlmeSetTxPreamble(pAd, Rt802_11PreambleShort);	}	OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED); 	if (pAd->PortCfg.RadarDetect.RDMode == RD_SILENCE_MODE)    {		RadarDetectionStop(pAd);    }	pAd->PortCfg.RadarDetect.RDMode = RD_NORMAL_MODE;	if (BssType == BSS_ADHOC)	{		//		// We also need to cancel the LinkDownTimer, no matter it was been set or not.		// It may be set when we start an Infrastructure mode.		// And not be canceled yet then we switch to Adohc at meanwhile.		//		RTMPCancelTimer(&pAd->Mlme.LinkDownTimer);		MakeIbssBeacon(pAd);        if (((pAd->PortCfg.PhyMode == PHY_11A) || (pAd->PortCfg.PhyMode == PHY_11ABG_MIXED))&& (pAd->PortCfg.bIEEE80211H == 1) && RadarChannelCheck(pAd, pAd->PortCfg.Channel))        {			;; //Do nothing        }		else        {            AsicEnableIbssSync(pAd);        }#ifdef	SINGLE_ADHOC_LINKUP		// Although this did not follow microsoft's recommendation.		//Change based on customer's request		OPSTATUS_SET_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);#endif	}	else // BSS_INFRA	{		int t;		// First cancel linkdown timer		t = RTMPCancelTimer(&pAd->Mlme.LinkDownTimer);		// Check the new SSID with last SSID		if (t)		{			if ((pAd->PortCfg.LastSsidLen != pAd->PortCfg.SsidLen) ||				((pAd->PortCfg.LastSsidLen == pAd->PortCfg.SsidLen) &&				 (RTMPCompareMemory(pAd->PortCfg.LastSsid, pAd->PortCfg.Ssid, pAd->PortCfg.LastSsidLen) != 0)))			{				// Send link down event before set to link up				DBGPRINT(RT_DEBUG_TRACE, "NDIS_STATUS_MEDIA_DISCONNECT Event AA!\n");			}		}		//		// On WPA mode, Remove All Keys if not connect to the last BSSID		// Key will be set after 4-way handshake.		//		if ((pAd->PortCfg.AuthMode >= Ndis802_11AuthModeWPA) &&			(!RTMPEqualMemory(pAd->PortCfg.LastBssid, pAd->PortCfg.Bssid, MAC_ADDR_LEN)))		{			// Remove all WPA keys			RTMPWPARemoveAllKeys(pAd);		}		// NOTE:		// the decision of using "short slot time" or not may change dynamically due to		// new STA association to the AP. so we have to decide that upon parsing BEACON, not here		// NOTE:		// the decision to use "RTC/CTS" or "CTS-to-self" protection or not may change dynamically		// due to new STA association to the AP. so we have to decide that upon parsing BEACON, not here		ComposePsPoll(pAd);		ComposeNullFrame(pAd);		AsicEnableBssSync(pAd);		// only INFRASTRUCTURE mode need to indicate connectivity immediately; ADHOC mode		// should wait until at least 2 active nodes in this BSSID.		OPSTATUS_SET_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);		if (pAd->PortCfg.bAggregationCapable && (pAd->MlmeAux.APRalinkIe & 0x00000001))			OPSTATUS_SET_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED);	}	DBGPRINT(RT_DEBUG_TRACE, "NDIS_STATUS_MEDIA_CONNECT Event B!\n");	// Set LED	RTMPSetLED(pAd, LED_LINK_UP);	//	// Enable OFDM TX rate auto fallback to CCK, if need.	//	RTUSBReadMACRegister(pAd, TXRX_CSR4, &CurTxRxCsr4.word);	NewTxRxCsr4.word = CurTxRxCsr4.word;	if ((pAd->PortCfg.Channel <= 14) &&		((pAd->PortCfg.PhyMode == PHY_11B) ||		 (pAd->PortCfg.PhyMode == PHY_11BG_MIXED) ||		 (pAd->PortCfg.PhyMode == PHY_11ABG_MIXED)))	{		NewTxRxCsr4.field.OfdmTxFallbacktoCCK = 1;	 //Enable OFDM TX rate auto fallback to CCK 1M, 2M	}	else	{		NewTxRxCsr4.field.OfdmTxFallbacktoCCK = 0;	 //Disable OFDM TX rate auto fallback to CCK 1M, 2M	}	if (NewTxRxCsr4.word!= CurTxRxCsr4.word)		RTUSBWriteMACRegister(pAd, TXRX_CSR4, NewTxRxCsr4.word);	pAd->Mlme.PeriodicRound = 0;		// re-schedule MlmePeriodicExec()	pAd->bConfigChanged = FALSE;		// Reset config flag	pAd->ExtraInfo = GENERAL_LINK_UP;	// Update extra information to link is up}/*	==========================================================================	Routine	Description:		Disconnect current BSSID	Arguments:		pAd				- Pointer to our adapter		IsReqFromAP		- Request from AP	Return Value:		None	Note:		We need more information to know it's this requst from AP.		If yes! we need to do extra handling, for example, remove the WPA key.		Otherwise on 4-way handshaking will faied, since the WPA key didn't be		remove while auto reconnect.		Disconnect request from AP, it means we will start afresh 4-way handshaking		on WPA mode.	==========================================================================*/VOID LinkDown(	IN PRTMP_ADAPTER pAd,	IN	BOOLEAN 	 IsReqFromAP){	TXRX_CSR4_STRUC CurTxRxCsr4;	DBGPRINT(RT_DEBUG_TRACE, "!!! LINK DOWN !!!\n");	OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED);	if (ADHOC_ON(pAd))		// Adhoc mode link down	{		OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_ADHOC_ON);#if 1 //#ifdef	SINGLE_ADHOC_LINKUP		OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);		// clean up previous SCAN result, add current BSS back to table if any		BssTableDeleteEntry(&pAd->ScanTab,							pAd->PortCfg.Bssid, pAd->PortCfg.Channel);#else		if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF))		{			OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);			BssTableDeleteEntry(&pAd->ScanTab,								pAd->PortCfg.Bssid, pAd->PortCfg.Channel);		}#endif	}	else					// Infra structure mode	{		OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_INFRA_ON);		OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);		// Saved last SSID for linkup comparison		pAd->PortCfg.LastSsidLen = pAd->PortCfg.SsidLen;		memcpy(pAd->PortCfg.LastSsid, pAd->PortCfg.Ssid, pAd->PortCfg.LastSsidLen);		COPY_MAC_ADDR(pAd->PortCfg.LastBssid, pAd->PortCfg.Bssid);		if (pAd->MlmeAux.CurrReqIsFromNdis == TRUE)		{			DBGPRINT(RT_DEBUG_TRACE, "NDIS_STATUS_MEDIA_DISCONNECT Event A!\n");			pAd->MlmeAux.CurrReqIsFromNdis = FALSE;		}		else		{			// Set linkdown timer			RTMPSetTimer(pAd, &pAd->Mlme.LinkDownTimer, 10000);		}		BssTableDeleteEntry(&pAd->ScanTab,							pAd->PortCfg.Bssid, pAd->PortCfg.Channel);		// restore back to -		//		1. long slot (20 us) or short slot (9 us) time		//		2. turn on/off RTS/CTS and/or CTS-to-self protection		//		3. short preamble		OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_BG_PROTECTION_INUSED);	}	//	// Reset CWMin & CWMax to default value	// Since we reset the slot time to 0x14(long slot time), so we also need to	// Reset the flag fOP_STATUS_SHORT_SLOT_INUSED at the same time.	//	RTUSBWriteMACRegister(pAd, MAC_CSR9, 0x0704a414);	OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_SHORT_SLOT_INUSED);	AsicSetSlotTime(pAd, (BOOLEAN)pAd->PortCfg.UseShortSlotTime);	AsicSetEdcaParm(pAd, NULL);	// Set LED	RTMPSetLED(pAd, LED_LINK_DOWN);	AsicDisableSync(pAd);	pAd->Mlme.PeriodicRound = 0;	// Remove PortCfg Information after link down	memset(pAd->PortCfg.Bssid, 0, MAC_ADDR_LEN);	memset(pAd->PortCfg.Ssid, 0, MAX_LEN_OF_SSID);	pAd->PortCfg.SsidLen = 0;	// Reset WPA-PSK state. Only reset when supplicant enabled	if (pAd->PortCfg.WpaState != SS_NOTUSE)	{		pAd->PortCfg.WpaState = SS_START;		// Clear Replay counter		memset(pAd->PortCfg.ReplayCounter, 0, 8);	}	//	// if link down come from AP, we need to remove all WPA keys on WPA mode.	// otherwise will cause 4-way handshaking failed, since the WPA key not empty.	//	if ((IsReqFromAP) && (pAd->PortCfg.AuthMode >= Ndis802_11AuthModeWPA))	{		// Remove all WPA keys		RTMPWPARemoveAllKeys(pAd);	}	// 802.1x port control	pAd->PortCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;	pAd->PortCfg.MicErrCnt = 0;	// Update extra information to link is up	pAd->ExtraInfo = GENERAL_LINK_DOWN;	// Clean association information	memset(&pAd->PortCfg.AssocInfo, 0, sizeof(NDIS_802_11_ASSOCIATION_INFORMATION));	pAd->PortCfg.AssocInfo.Length = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);	pAd->PortCfg.ReqVarIELen = 0;	pAd->PortCfg.ResVarIELen = 0;    // Restore MlmeRate	pAd->PortCfg.MlmeRate = pAd->PortCfg.BasicMlmeRate;	pAd->PortCfg.RtsRate = pAd->PortCfg.BasicMlmeRate;	//	// After link down, reset R17 to LowerBound.	//	if (pAd->MlmeAux.Channel <= 14)	{		RTUSBWriteBBPRegister(pAd, 17, pAd->BbpTuning.R17LowerBoundG);	}	else	{		RTUSBWriteBBPRegister(pAd, 17, pAd->BbpTuning.R17LowerBoundA);	}	if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MAX_RETRY_ENABLED))	{		RTUSBReadMACRegister(pAd, TXRX_CSR4, &CurTxRxCsr4.word);		CurTxRxCsr4.field.ShortRetryLimit = 0x07;		CurTxRxCsr4.field.LongRetryLimit = 0x04;		RTUSBWriteMACRegister(pAd, TXRX_CSR4, CurTxRxCsr4.word);		OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MAX_RETRY_ENABLED);	}	OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_RTS_PROTECTION_ENABLE);}/*	==========================================================================	Description:	==========================================================================*/VOID IterateOnBssTab(	IN PRTMP_ADAPTER pAd){	MLME_START_REQ_STRUCT	StartReq;	MLME_JOIN_REQ_STRUCT	JoinReq;	ULONG					BssIdx;

⌨️ 快捷键说明

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