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

📄 connect.c

📁 Linux下的RT系列无线网卡驱动,可以直接在x86平台上编译
💻 C
📖 第 1 页 / 共 5 页
字号:
/* ************************************************************************* * Ralink Tech Inc. * 4F, No. 2 Technology 5th Rd. * Science-based Industrial Park * Hsin-chu, Taiwan, R.O.C. * * (c) Copyright 2002-2007, Ralink Technology, Inc. * * This program is free software; you can redistribute it and/or modify  *  * it under the terms of the GNU General Public License as published by  *  * the Free Software Foundation; either version 2 of the License, or     *  * (at your option) any later version.                                   *  *                                                                       *  * This program is distributed in the hope that it will be useful,       *  * but WITHOUT ANY WARRANTY; without even the implied warranty of        *  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *  * GNU General Public License for more details.                          *  *                                                                       *  * You should have received a copy of the GNU General Public License     *  * along with this program; if not, write to the                         *  * Free Software Foundation, Inc.,                                       *  * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *  *                                                                       *  ************************************************************************* 	Module Name:	connect.c	Abstract:	Revision History:	Who			When			What	--------	----------		----------------------------------------------	John			2004-08-08			Major modification from RT2560*/#include "rt_config.h"UCHAR	CipherSuiteWpaNoneTkip[] = {		0x00, 0x50, 0xf2, 0x01,	// oui		0x01, 0x00,				// Version		0x00, 0x50, 0xf2, 0x02,	// Multicast		0x01, 0x00,				// Number of unicast		0x00, 0x50, 0xf2, 0x02,	// unicast		0x01, 0x00,				// number of authentication method		0x00, 0x50, 0xf2, 0x00	// authentication		};UCHAR	CipherSuiteWpaNoneTkipLen = (sizeof(CipherSuiteWpaNoneTkip) / sizeof(UCHAR));UCHAR	CipherSuiteWpaNoneAes[] = {		0x00, 0x50, 0xf2, 0x01,	// oui		0x01, 0x00,				// Version		0x00, 0x50, 0xf2, 0x04,	// Multicast		0x01, 0x00,				// Number of unicast		0x00, 0x50, 0xf2, 0x04,	// unicast		0x01, 0x00,				// number of authentication method		0x00, 0x50, 0xf2, 0x00	// authentication		};UCHAR	CipherSuiteWpaNoneAesLen = (sizeof(CipherSuiteWpaNoneAes) / sizeof(UCHAR));// The following MACRO is called after 1. starting an new IBSS, 2. succesfully JOIN an IBSS,// or 3. succesfully ASSOCIATE to a BSS, 4. successfully RE_ASSOCIATE to a BSS// All settings successfuly negotiated furing MLME state machines become final settings// and are copied to pAd->StaActive#define COPY_SETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG(_pAd)                                 \{                                                                                       \	_pAd->CommonCfg.SsidLen = _pAd->MlmeAux.SsidLen;                                    \	NdisMoveMemory(_pAd->CommonCfg.Ssid, _pAd->MlmeAux.Ssid, _pAd->MlmeAux.SsidLen);    \	COPY_MAC_ADDR(_pAd->CommonCfg.Bssid, _pAd->MlmeAux.Bssid);                          \	_pAd->CommonCfg.Channel = _pAd->MlmeAux.Channel;                                    \	_pAd->CommonCfg.CentralChannel = _pAd->MlmeAux.CentralChannel;                                    \	_pAd->StaActive.Aid = _pAd->MlmeAux.Aid;                                            \	_pAd->StaActive.AtimWin = _pAd->MlmeAux.AtimWin;                                    \	_pAd->StaActive.CapabilityInfo = _pAd->MlmeAux.CapabilityInfo;                      \	_pAd->CommonCfg.BeaconPeriod = _pAd->MlmeAux.BeaconPeriod;                          \	_pAd->StaActive.CfpMaxDuration = _pAd->MlmeAux.CfpMaxDuration;                      \	_pAd->StaActive.CfpPeriod = _pAd->MlmeAux.CfpPeriod;                                \	_pAd->StaActive.SupRateLen = _pAd->MlmeAux.SupRateLen;                              \	NdisMoveMemory(_pAd->StaActive.SupRate, _pAd->MlmeAux.SupRate, _pAd->MlmeAux.SupRateLen);   \	_pAd->StaActive.ExtRateLen = _pAd->MlmeAux.ExtRateLen;                                      \	NdisMoveMemory(_pAd->StaActive.ExtRate, _pAd->MlmeAux.ExtRate, _pAd->MlmeAux.ExtRateLen);   \	NdisMoveMemory(&_pAd->CommonCfg.APEdcaParm, &_pAd->MlmeAux.APEdcaParm, sizeof(EDCA_PARM));  \	NdisMoveMemory(&_pAd->CommonCfg.APQosCapability, &_pAd->MlmeAux.APQosCapability, sizeof(QOS_CAPABILITY_PARM));  \	NdisMoveMemory(&_pAd->CommonCfg.APQbssLoad, &_pAd->MlmeAux.APQbssLoad, sizeof(QBSS_LOAD_PARM)); \	COPY_MAC_ADDR(_pAd->MacTab.Content[BSSID_WCID].Addr, _pAd->MlmeAux.Bssid);                          \	_pAd->MacTab.Content[BSSID_WCID].Aid = _pAd->MlmeAux.Aid;                                            \	_pAd->MacTab.Content[BSSID_WCID].PairwiseKey.CipherAlg = _pAd->StaCfg.PairCipher;				 \	COPY_MAC_ADDR(_pAd->MacTab.Content[BSSID_WCID].PairwiseKey.BssId, _pAd->MlmeAux.Bssid);				 \}/*	==========================================================================	Description:	IRQL = PASSIVE_LEVEL	==========================================================================*/VOID MlmeCntlInit(	IN PRTMP_ADAPTER pAd, 	IN STATE_MACHINE *S, 	OUT STATE_MACHINE_FUNC Trans[]) {	// Control state machine differs from other state machines, the interface 	// follows the standard interface	pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;}/*	==========================================================================	Description:	IRQL = DISPATCH_LEVEL		==========================================================================*/VOID MlmeCntlMachinePerformAction(	IN PRTMP_ADAPTER pAd, 	IN STATE_MACHINE *S, 	IN MLME_QUEUE_ELEM *Elem) {	switch(pAd->Mlme.CntlMachine.CurrState) 	{		case CNTL_IDLE:		    CntlIdleProc(pAd, Elem);			break;		case CNTL_WAIT_DISASSOC:			CntlWaitDisassocProc(pAd, Elem);			break;		case CNTL_WAIT_JOIN:			CntlWaitJoinProc(pAd, Elem);			break;		// CNTL_WAIT_REASSOC is the only state in CNTL machine that does		// not triggered directly or indirectly by "RTMPSetInformation(OID_xxx)". 		// Therefore not protected by NDIS's "only one outstanding OID request" 		// rule. Which means NDIS may SET OID in the middle of ROAMing attempts.		// Current approach is to block new SET request at RTMPSetInformation()		// when CntlMachine.CurrState is not CNTL_IDLE		case CNTL_WAIT_REASSOC:			CntlWaitReassocProc(pAd, Elem);			break;		case CNTL_WAIT_START:			CntlWaitStartProc(pAd, Elem);			break;		case CNTL_WAIT_AUTH:			CntlWaitAuthProc(pAd, Elem);			break;		case CNTL_WAIT_AUTH2:			CntlWaitAuthProc2(pAd, Elem);			break;		case CNTL_WAIT_ASSOC:			CntlWaitAssocProc(pAd, Elem);			break;		case CNTL_WAIT_OID_LIST_SCAN:			if(Elem->MsgType == MT2_SCAN_CONF) 			{				// Resume TxRing after SCANING complete. We hope the out-of-service time				// won't be too long to let upper layer time-out the waiting frames				RTMPResumeMsduTransmission(pAd);				if (pAd->StaCfg.CCXReqType != MSRN_TYPE_UNUSED)				{					// Cisco scan request is finished, prepare beacon report					MlmeEnqueue(pAd, AIRONET_STATE_MACHINE, MT2_AIRONET_SCAN_DONE, 0, NULL);				}				pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;			}			break;		case CNTL_WAIT_OID_DISASSOC:			if (Elem->MsgType == MT2_DISASSOC_CONF) 			{				LinkDown(pAd, FALSE);				pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;			}			break;		default:			DBGPRINT_ERR(("!ERROR! CNTL - Illegal message type(=%ld)", Elem->MsgType));			break;	}}/*	==========================================================================	Description:	IRQL = DISPATCH_LEVEL		==========================================================================*/VOID CntlIdleProc(	IN PRTMP_ADAPTER pAd, 	IN MLME_QUEUE_ELEM *Elem) {	MLME_DISASSOC_REQ_STRUCT   DisassocReq;	if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF))		return;			switch(Elem->MsgType) 	{		case OID_802_11_SSID:			CntlOidSsidProc(pAd, Elem);			break;		case OID_802_11_BSSID:			CntlOidRTBssidProc(pAd,Elem);			break;		case OID_802_11_BSSID_LIST_SCAN:			CntlOidScanProc(pAd,Elem);			break;		case OID_802_11_DISASSOCIATE:			DisassocParmFill(pAd, &DisassocReq, pAd->CommonCfg.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_OID_DISASSOC;#ifdef WPA_SUPPLICANT_SUPPORT            if (pAd->StaCfg.WpaSupplicantUP != 2)#endif // WPA_SUPPLICANT_SUPPORT //            {    			// Set the AutoReconnectSsid to prevent it reconnect to old SSID    			// Since calling this indicate user don't want to connect to that SSID anymore.    			pAd->MlmeAux.AutoReconnectSsidLen= 32;    			NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.AutoReconnectSsidLen);            }			break;		case MT2_MLME_ROAMING_REQ:			CntlMlmeRoamingProc(pAd, Elem);			break;        case OID_802_11_MIC_FAILURE_REPORT_FRAME:            WpaMicFailureReportFrame(pAd, Elem);            break;		default:			DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Illegal message in CntlIdleProc(MsgType=%ld)\n",Elem->MsgType));			break;	}}// IRQL = DISPATCH_LEVELVOID CntlOidScanProc(	IN PRTMP_ADAPTER pAd,	IN MLME_QUEUE_ELEM *Elem){	MLME_SCAN_REQ_STRUCT       ScanReq;	ULONG                      BssIdx = BSS_NOT_FOUND;	BSS_ENTRY                  CurrBss;	DBGPRINT(RT_DEBUG_INFO, ("CNTL - SCAN starts\n"));	// record current BSS if network is connected. 	// 2003-2-13 do not include current IBSS if this is the only STA in this IBSS.	if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED))	{		BssIdx = BssSsidTableSearch(&pAd->ScanTab, pAd->CommonCfg.Bssid, pAd->CommonCfg.Ssid, pAd->CommonCfg.SsidLen, pAd->CommonCfg.Channel);		if (BssIdx != BSS_NOT_FOUND)		{			NdisMoveMemory(&CurrBss, &pAd->ScanTab.BssEntry[BssIdx], sizeof(BSS_ENTRY));			// 2003-2-20 reset this RSSI to a low value but not zero. In normal case, the coming SCAN			//     should return a correct RSSI to overwrite this. If no BEEACON received after SCAN, 			//     at least we still report a "greater than 0" RSSI since we claim it's CONNECTED.			// CurrBss.Rssi = pAd->BbpRssiToDbmDelta - 85; // assume -85 dB		}	}	// clean up previous SCAN result, add current BSS back to table if any	BssTableInit(&pAd->ScanTab); 	if (BssIdx != BSS_NOT_FOUND)	{		// DDK Note: If the NIC is associated with a particular BSSID and SSID 		//    that are not contained in the list of BSSIDs generated by this scan, the 		//    BSSID description of the currently associated BSSID and SSID should be 		//    appended to the list of BSSIDs in the NIC's database.		// To ensure this, we append this BSS as the first entry in SCAN result		NdisMoveMemory(&pAd->ScanTab.BssEntry[0], &CurrBss, sizeof(BSS_ENTRY));		pAd->ScanTab.BssNr = 1;	}	ScanParmFill(pAd, &ScanReq, "", 0, 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;}/*	==========================================================================	Description:		Before calling this routine, user desired SSID should already been		recorded in CommonCfg.Ssid[]	IRQL = DISPATCH_LEVEL		==========================================================================*/VOID CntlOidSsidProc(	IN PRTMP_ADAPTER pAd, 	IN MLME_QUEUE_ELEM * Elem) {	PNDIS_802_11_SSID          pOidSsid = (NDIS_802_11_SSID *)Elem->Msg;	MLME_DISASSOC_REQ_STRUCT   DisassocReq;	ULONG					   Now;	// Step 1. record the desired user settings to MlmeAux	NdisZeroMemory(pAd->MlmeAux.Ssid, MAX_LEN_OF_SSID);	NdisMoveMemory(pAd->MlmeAux.Ssid, pOidSsid->Ssid, pOidSsid->SsidLength);	pAd->MlmeAux.SsidLen = (UCHAR)pOidSsid->SsidLength;	NdisZeroMemory(pAd->MlmeAux.Bssid, MAC_ADDR_LEN);	pAd->MlmeAux.BssType = pAd->StaCfg.BssType;	//	// Update Reconnect Ssid, that user desired to connect.	//	NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, MAX_LEN_OF_SSID);	NdisMoveMemory(pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen);	pAd->MlmeAux.AutoReconnectSsidLen = pAd->MlmeAux.SsidLen;	// step 2. find all matching BSS in the lastest SCAN result (inBssTab) 	//    & log them into MlmeAux.SsidBssTab for later-on iteration. Sort by RSSI order	BssTableSsidSort(pAd, &pAd->MlmeAux.SsidBssTab, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen);	DBGPRINT(RT_DEBUG_TRACE, ("CntlOidSsidProc():CNTL - %d BSS of %d BSS match the desire (%d)SSID - %s\n",			pAd->MlmeAux.SsidBssTab.BssNr, pAd->ScanTab.BssNr, pAd->MlmeAux.SsidLen, pAd->MlmeAux.Ssid));	NdisGetSystemUpTime(&Now);	if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED) && 		(pAd->CommonCfg.SsidLen == pAd->MlmeAux.SsidBssTab.BssEntry[0].SsidLen) &&		NdisEqualMemory(pAd->CommonCfg.Ssid, pAd->MlmeAux.SsidBssTab.BssEntry[0].Ssid, pAd->CommonCfg.SsidLen) &&		MAC_ADDR_EQUAL(pAd->CommonCfg.Bssid, pAd->MlmeAux.SsidBssTab.BssEntry[0].Bssid))	{		// Case 1. already connected with an AP who has the desired SSID 		//         with highest RSSI		// Add checking Mode "LEAP" for CCX 1.0		if (((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||			 (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||			 (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) ||			 (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) #ifdef LEAP_SUPPORT			 || (pAd->StaCfg.LeapAuthMode == CISCO_AuthModeLEAP)#endif // LEAP_SUPPORT //			 ) &&			(pAd->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))		{			// case 1.1 For WPA, WPA-PSK, if the 1x port is not secured, we have to redo 			//          connection process			DBGPRINT(RT_DEBUG_TRACE, ("CntlOidSsidProc():CNTL - disassociate with current AP...\n"));			DisassocParmFill(pAd, &DisassocReq, pAd->CommonCfg.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 (pAd->bConfigChanged == TRUE)		{			// case 1.2 Important Config has changed, we have to reconnect to the same AP			DBGPRINT(RT_DEBUG_TRACE, ("CntlOidSsidProc():CNTL - disassociate with current AP Because config changed...\n"));			DisassocParmFill(pAd, &DisassocReq, pAd->CommonCfg.Bssid, REASON_DISASSOC_STA_LEAVING);			MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_DISASSOC_REQ, 						sizeof(MLME_DISASSOC_REQ_STRUCT), &DisassocReq);

⌨️ 快捷键说明

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