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

📄 connect.c

📁 TP Link 321 Linux Driver
💻 C
📖 第 1 页 / 共 4 页
字号:
		{			MLME_SCAN_REQ_STRUCT	   ScanReq;			DBGPRINT(RT_DEBUG_TRACE, "CNTL - No matching BSS, start a new scan\n");						ScanParmFill(pAd, &ScanReq, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen, BSS_ANY, SCAN_ACTIVE);			MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_SCAN_REQ, 						sizeof(MLME_SCAN_REQ_STRUCT), &ScanReq);			pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_LIST_SCAN;						// Reset Missed scan number			pAd->PortCfg.LastScanTime = Now;		}		else		{			pAd->MlmeAux.BssIdx = 0;			IterateOnBssTab(pAd);		}	} }/*	==========================================================================	Description:	==========================================================================*/VOID CntlOidRTBssidProc(	IN PRTMP_ADAPTER pAd, 	IN MLME_QUEUE_ELEM * Elem) {	ULONG						BssIdx;	PUCHAR						pOidBssid = (PUCHAR)Elem->Msg;	MLME_DISASSOC_REQ_STRUCT	DisassocReq;	MLME_JOIN_REQ_STRUCT		JoinReq;	DBGPRINT(RT_DEBUG_TRACE, "CNTL - CntlOidRTBssidProc ...\n");	// record user desired settings	COPY_MAC_ADDR(pAd->MlmeAux.Bssid, pOidBssid);	pAd->MlmeAux.BssType = pAd->PortCfg.BssType;	// find the desired BSS in the latest SCAN result table	BssIdx = BssTableSearch(&pAd->ScanTab, pOidBssid, pAd->MlmeAux.Channel);		if (BssIdx == BSS_NOT_FOUND) 	{		DBGPRINT(RT_DEBUG_TRACE, "CNTL - BSSID not found. reply NDIS_STATUS_NOT_ACCEPTED\n");		pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;		return;	}	// copy the matched BSS entry from ScanTab to MlmeAux.SsidBssTab. Why?	// Because we need this entry to become the JOIN target in later on SYNC state machine	pAd->MlmeAux.BssIdx = 0;	pAd->MlmeAux.SsidBssTab.BssNr = 1;	NdisMoveMemory(&pAd->MlmeAux.SsidBssTab.BssEntry[0], &pAd->ScanTab.BssEntry[BssIdx], sizeof(BSS_ENTRY));	//	// Update Reconnect Ssid, that user desired to connect.	//	pAd->MlmeAux.AutoReconnectSsidLen = pAd->ScanTab.BssEntry[BssIdx].SsidLen;	NdisMoveMemory(pAd->MlmeAux.AutoReconnectSsid, pAd->ScanTab.BssEntry[BssIdx].Ssid, pAd->ScanTab.BssEntry[BssIdx].SsidLen);		// Add SSID into MlmeAux for site surey joining hidden SSID	pAd->MlmeAux.SsidLen = pAd->ScanTab.BssEntry[BssIdx].SsidLen;	NdisZeroMemory(pAd->MlmeAux.Ssid, MAX_LEN_OF_SSID);	NdisMoveMemory(pAd->MlmeAux.Ssid, pAd->ScanTab.BssEntry[BssIdx].Ssid, pAd->MlmeAux.SsidLen);		// 2002-11-26 skip the following checking. i.e. if user wants to re-connect to same AP	//	 we just follow normal procedure. The reason of user doing this may because he/she changed	//	 AP to another channel, but we still received BEACON from it thus don't claim Link Down.	//	 Since user knows he's changed AP channel, he'll re-connect again. By skipping the following	//	 checking, we'll disassociate then re-do normal association with this AP at the new channel.	// 2003-1-6 Re-enable this feature based on microsoft requirement which prefer not to re-do	//	 connection when setting the same BSSID.	if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED) && 		MAC_ADDR_EQUAL(pAd->PortCfg.Bssid, pOidBssid))	{		// already connected to the same BSSID, go back to idle state directly		DBGPRINT(RT_DEBUG_TRACE, "CNTL - already in this BSSID. ignore this SET_BSSID request\n");		pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;		#ifdef NATIVE_WPA_SUPPLICANT_SUPPORT		// 2007-04-11, in order to support NetworkManager, even if we already connected to the BSSID, we still		//				need to send wireless event to wpa_supplicant to notify that we already connected to the		//				AP.		if (pAd->PortCfg.bNativeWpa == TRUE)  // add by johnli			wext_notify_event_assoc(pAd, SIOCGIWAP, TRUE);#endif	} 	else 	{		if (INFRA_ON(pAd))		{			// disassoc from current AP first			DBGPRINT(RT_DEBUG_TRACE, "CNTL - disassociate with current AP ...\n");			DisassocParmFill(pAd, &DisassocReq, pAd->PortCfg.Bssid, REASON_DISASSOC_STA_LEAVING);			MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_DISASSOC_REQ, 						sizeof(MLME_DISASSOC_REQ_STRUCT), &DisassocReq);			pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_DISASSOC;		}		else		{			if (ADHOC_ON(pAd))			{				DBGPRINT(RT_DEBUG_TRACE, "CNTL - drop current ADHOC\n");				LinkDown(pAd, FALSE);				OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);				DBGPRINT(RT_DEBUG_TRACE, "NDIS_STATUS_MEDIA_DISCONNECT Event C!\n");			}			#if 0  // set  OrigWepStatus in OID_802_11_WEP_STATUS				 			// Change the wepstatus to original wepstatus			pAd->PortCfg.WepStatus	 = pAd->PortCfg.OrigWepStatus;			pAd->PortCfg.PairCipher  = pAd->PortCfg.OrigWepStatus;			pAd->PortCfg.GroupCipher = pAd->PortCfg.OrigWepStatus;#endif			// Check cipher suite, AP must have more secured cipher than station setting			// Set the Pairwise and Group cipher to match the intended AP setting			// We can only connect to AP with less secured cipher setting			if ((pAd->PortCfg.AuthMode == Ndis802_11AuthModeWPA) || (pAd->PortCfg.AuthMode == Ndis802_11AuthModeWPAPSK))			{				pAd->PortCfg.GroupCipher = pAd->ScanTab.BssEntry[BssIdx].WPA.GroupCipher;								if (pAd->PortCfg.WepStatus == pAd->ScanTab.BssEntry[BssIdx].WPA.PairCipher)					pAd->PortCfg.PairCipher = pAd->ScanTab.BssEntry[BssIdx].WPA.PairCipher;				else if (pAd->ScanTab.BssEntry[BssIdx].WPA.PairCipherAux != Ndis802_11WEPDisabled)					pAd->PortCfg.PairCipher = pAd->ScanTab.BssEntry[BssIdx].WPA.PairCipherAux;				else	// There is no PairCipher Aux, downgrade our capability to TKIP					pAd->PortCfg.PairCipher = Ndis802_11Encryption2Enabled;						}			else if ((pAd->PortCfg.AuthMode == Ndis802_11AuthModeWPA2) || (pAd->PortCfg.AuthMode == Ndis802_11AuthModeWPA2PSK))			{				pAd->PortCfg.GroupCipher = pAd->ScanTab.BssEntry[BssIdx].WPA2.GroupCipher;								if (pAd->PortCfg.WepStatus == pAd->ScanTab.BssEntry[BssIdx].WPA2.PairCipher)					pAd->PortCfg.PairCipher = pAd->ScanTab.BssEntry[BssIdx].WPA2.PairCipher;				else if (pAd->ScanTab.BssEntry[BssIdx].WPA2.PairCipherAux != Ndis802_11WEPDisabled)					pAd->PortCfg.PairCipher = pAd->ScanTab.BssEntry[BssIdx].WPA2.PairCipherAux;				else	// There is no PairCipher Aux, downgrade our capability to TKIP					pAd->PortCfg.PairCipher = Ndis802_11Encryption2Enabled;							// RSN capability				pAd->PortCfg.RsnCapability = pAd->ScanTab.BssEntry[BssIdx].WPA2.RsnCapability;			}			// Set Mix cipher flag			if (pAd->PortCfg.PairCipher != pAd->PortCfg.GroupCipher)				pAd->PortCfg.bMixCipher = TRUE;		  			// No active association, join the BSS immediately			DBGPRINT(RT_DEBUG_TRACE, "CNTL - joining %02x:%02x:%02x:%02x:%02x:%02x ...\n",				pOidBssid[0],pOidBssid[1],pOidBssid[2],pOidBssid[3],pOidBssid[4],pOidBssid[5]);			JoinParmFill(pAd, &JoinReq, pAd->MlmeAux.BssIdx);			MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_JOIN_REQ, 						sizeof(MLME_JOIN_REQ_STRUCT), &JoinReq);			pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_JOIN;		}	} }// Roaming is the only external request triggering CNTL state machine// despite of other "SET OID" operation. All "SET OID" related oerations // happen in sequence, because no other SET OID will be sent to this device// until the the previous SET operation is complete (successful o failed).// So, how do we quarantee this ROAMING request won't corrupt other "SET OID"?// or been corrupted by other "SET OID"?VOID CntlMlmeRoamingProc(	IN PRTMP_ADAPTER pAd, 	IN MLME_QUEUE_ELEM *Elem) {	// TODO: 	// AP in different channel may show lower RSSI than actual value??	// should we add a weighting factor to compensate it?	DBGPRINT(RT_DEBUG_TRACE,"CNTL - Roaming in MlmeAux.RoamTab...\n");		NdisMoveMemory(&pAd->MlmeAux.SsidBssTab, &pAd->MlmeAux.RoamTab, sizeof(pAd->MlmeAux.RoamTab));	pAd->MlmeAux.SsidBssTab.BssNr = pAd->MlmeAux.RoamTab.BssNr;	BssTableSortByRssi(&pAd->MlmeAux.SsidBssTab);	pAd->MlmeAux.BssIdx = 0;	IterateOnBssTab(pAd);}/*	==========================================================================	Description:	==========================================================================*/VOID CntlWaitDisassocProc(	IN PRTMP_ADAPTER pAd, 	IN MLME_QUEUE_ELEM *Elem) {	MLME_START_REQ_STRUCT	  StartReq;	printk("calling linkdown\n");	if (Elem->MsgType == MT2_DISASSOC_CONF) 	//if (Elem->MsgType == MT2_DISASSOC_CONF && !INFRA_ON(pAd) && !ADHOC_ON(pAd)) 	{		DBGPRINT(RT_DEBUG_TRACE, "CNTL - Dis-associate successful\n");		LinkDown(pAd, FALSE);				// case 1. no matching BSS, and user wants ADHOC, so we just start a new one				if ((pAd->MlmeAux.SsidBssTab.BssNr==0) && (pAd->PortCfg.BssType == BSS_ADHOC))		{			DBGPRINT(RT_DEBUG_TRACE, "CNTL - No matching BSS, start a new ADHOC (Ssid=%s)...\n",pAd->MlmeAux.Ssid);			StartParmFill(pAd, &StartReq, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen);			MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_START_REQ, 						sizeof(MLME_START_REQ_STRUCT), &StartReq);			pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_START;		}		// case 2. try each matched BSS		else		{			pAd->MlmeAux.BssIdx = 0;			IterateOnBssTab(pAd);		}	}}/*	==========================================================================	Description:	==========================================================================*/VOID CntlWaitJoinProc(	IN PRTMP_ADAPTER pAd, 	IN MLME_QUEUE_ELEM *Elem) {	USHORT						Reason;	MLME_AUTH_REQ_STRUCT		AuthReq;	if (Elem->MsgType == MT2_JOIN_CONF) 	{		NdisMoveMemory(&Reason, Elem->Msg, sizeof(USHORT));		if (Reason == MLME_SUCCESS) 		{			// 1. joined an IBSS, we are pretty much done here			if (pAd->MlmeAux.BssType == BSS_ADHOC)			{				LinkUp(pAd, BSS_ADHOC);				pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;				DBGPRINT(RT_DEBUG_TRACE, "CNTL - join the IBSS = %02x:%02x:%02x:%02x:%02x:%02x ...\n", 					pAd->PortCfg.Bssid[0],pAd->PortCfg.Bssid[1],pAd->PortCfg.Bssid[2],					pAd->PortCfg.Bssid[3],pAd->PortCfg.Bssid[4],pAd->PortCfg.Bssid[5]);			} 			// 2. joined a new INFRA network, start from authentication			else 			{				// either Ndis802_11AuthModeShared or Ndis802_11AuthModeAutoSwitch, try shared key first				if ((pAd->PortCfg.AuthMode == Ndis802_11AuthModeShared) ||					(pAd->PortCfg.AuthMode == Ndis802_11AuthModeAutoSwitch))				{					AuthParmFill(pAd, &AuthReq, pAd->MlmeAux.Bssid, Ndis802_11AuthModeShared);				}				else				{					AuthParmFill(pAd, &AuthReq, pAd->MlmeAux.Bssid, Ndis802_11AuthModeOpen);				}							MlmeEnqueue(pAd, AUTH_STATE_MACHINE, MT2_MLME_AUTH_REQ, 							sizeof(MLME_AUTH_REQ_STRUCT), &AuthReq);				pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_AUTH;			}		}		else		{			// 3. failed, try next BSS			pAd->MlmeAux.BssIdx++;			IterateOnBssTab(pAd);		} 	}	 }/*	==========================================================================	Description:	==========================================================================*/VOID CntlWaitStartProc(	IN PRTMP_ADAPTER pAd, 	IN MLME_QUEUE_ELEM *Elem) {	USHORT		Result;	if (Elem->MsgType == MT2_START_CONF) 	{		NdisMoveMemory(&Result, Elem->Msg, sizeof(USHORT));		if (Result == MLME_SUCCESS) 		{				LinkUp(pAd, BSS_ADHOC);			pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;            // Before send beacon, driver need do radar detection			if (((pAd->PortCfg.PhyMode == PHY_11A) || (pAd->PortCfg.PhyMode == PHY_11ABG_MIXED))&& (pAd->PortCfg.bIEEE80211H == 1) && RadarChannelCheck(pAd, pAd->PortCfg.Channel))			{				pAd->PortCfg.RadarDetect.RDMode = RD_SILENCE_MODE;				pAd->PortCfg.RadarDetect.RDCount = 0;				RadarDetectionStart(pAd);			}				DBGPRINT(RT_DEBUG_TRACE, "CNTL - start a new IBSS = %02x:%02x:%02x:%02x:%02x:%02x ...\n", 				pAd->PortCfg.Bssid[0],pAd->PortCfg.Bssid[1],pAd->PortCfg.Bssid[2],				pAd->PortCfg.Bssid[3],pAd->PortCfg.Bssid[4],pAd->PortCfg.Bssid[5]);		}		else		{			DBGPRINT(RT_DEBUG_TRACE, "CNTL - Start IBSS fail. BUG!!!!!\n");			pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;		}	}}/*	==========================================================================	Description:	==========================================================================*/VOID CntlWaitAuthProc(	IN PRTMP_ADAPTER pAd, 	IN MLME_QUEUE_ELEM *Elem) {	USHORT						 Reason;	MLME_ASSOC_REQ_STRUCT		 AssocReq;	MLME_AUTH_REQ_STRUCT		 AuthReq;	if (Elem->MsgType == MT2_AUTH_CONF) 	{		NdisMoveMemory(&Reason, Elem->Msg, sizeof(USHORT));		if (Reason == MLME_SUCCESS) 		{			DBGPRINT(RT_DEBUG_TRACE, "CNTL - AUTH OK\n");			AssocParmFill(pAd, &AssocReq, pAd->MlmeAux.Bssid, pAd->MlmeAux.CapabilityInfo, 						  ASSOC_TIMEOUT, pAd->PortCfg.DefaultListenCount);						  			MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_ASSOC_REQ, 						sizeof(MLME_ASSOC_REQ_STRUCT), &AssocReq);			pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_ASSOC;		} 		else		{			// This fail may because of the AP already keep us in its MAC table without 			// ageing-out. The previous authentication attempt must have let it remove us.			// so try Authentication again may help. For D-Link DWL-900AP+ compatibility.			DBGPRINT(RT_DEBUG_TRACE, "CNTL - AUTH FAIL, try again...\n");						if ((pAd->PortCfg.AuthMode == Ndis802_11AuthModeShared) ||				(pAd->PortCfg.AuthMode == Ndis802_11AuthModeAutoSwitch))			{				// either Ndis802_11AuthModeShared or Ndis802_11AuthModeAutoSwitch, try shared key first				AuthParmFill(pAd, &AuthReq, pAd->MlmeAux.Bssid, Ndis802_11AuthModeShared);			}			else			{				AuthParmFill(pAd, &AuthReq, pAd->MlmeAux.Bssid, Ndis802_11AuthModeOpen);			}   			MlmeEnqueue(pAd, AUTH_STATE_MACHINE, MT2_MLME_AUTH_REQ, 						sizeof(MLME_AUTH_REQ_STRUCT), &AuthReq);			pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_AUTH2;		}	}	 }/*	==========================================================================	Description:		==========================================================================*/VOID CntlWaitAuthProc2(	IN PRTMP_ADAPTER pAd, 	IN MLME_QUEUE_ELEM *Elem) {	USHORT						 Reason;	MLME_ASSOC_REQ_STRUCT		 AssocReq;	MLME_AUTH_REQ_STRUCT		 AuthReq;	if (Elem->MsgType == MT2_AUTH_CONF) 	{		NdisMoveMemory(&Reason, Elem->Msg, sizeof(USHORT));		if (Reason == MLME_SUCCESS) 		{			DBGPRINT(RT_DEBUG_TRACE, "CNTL - AUTH OK\n");			AssocParmFill(pAd, &AssocReq, pAd->MlmeAux.Bssid, pAd->MlmeAux.CapabilityInfo, 						  ASSOC_TIMEOUT, pAd->PortCfg.DefaultListenCount);			MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_ASSOC_REQ, 						sizeof(MLME_ASSOC_REQ_STRUCT), &AssocReq);			pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_ASSOC;		} 		else		{					if ((pAd->PortCfg.AuthMode == Ndis802_11AuthModeAutoSwitch) &&				 (pAd->MlmeAux.Alg == Ndis802_11AuthModeShared))			{				DBGPRINT(RT_DEBUG_TRACE, "CNTL - AUTH FAIL, try OPEN system...\n");				AuthParmFill(pAd, &AuthReq, pAd->MlmeAux.Bssid, Ndis802_11AuthModeOpen);				MlmeEnqueue(pAd, AUTH_STATE_MACHINE, MT2_MLME_AUTH_REQ, 							sizeof(MLME_AUTH_REQ_STRUCT), &AuthReq);				pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_AUTH2;			}			else 			{				// not success, try next BSS				DBGPRINT(RT_DEBUG_TRACE, "CNTL - AUTH FAIL, give up; try next BSS\n");// 2004-09-11 john -  why change state? 			   //			   pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE; //???????				pAd->MlmeAux.BssIdx++;				IterateOnBssTab(pAd);			}		}

⌨️ 快捷键说明

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