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

📄 assoc.c

📁 ralink 2870 usb无线网卡 最新驱动
💻 C
📖 第 1 页 / 共 4 页
字号:
/* ************************************************************************* * Ralink Tech Inc. * 5F., No.36, Taiyuan St., Jhubei City, * Hsinchu County 302, * 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:	assoc.c	Abstract:	Revision History:	Who			When			What	--------	----------		----------------------------------------------	John		2004-9-3		porting from RT2500*/#include "rt_config.h"UCHAR	CipherWpaTemplate[] = {		0xdd, 					// WPA IE		0x16,					// Length		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, 0x01	// authentication		};UCHAR	CipherWpa2Template[] = {		0x30,					// RSN IE		0x14,					// Length			0x01, 0x00,				// Version		0x00, 0x0f, 0xac, 0x02,	// group cipher, TKIP		0x01, 0x00,				// number of pairwise		0x00, 0x0f, 0xac, 0x02,	// unicast		0x01, 0x00,				// number of authentication method		0x00, 0x0f, 0xac, 0x02,	// authentication		0x00, 0x00,				// RSN capability		};UCHAR	Ccx2IeInfo[] = { 0x00, 0x40, 0x96, 0x03, 0x02};/*  	==========================================================================	Description: 		association state machine init, including state transition and timer init	Parameters: 		S - pointer to the association state machine	IRQL = PASSIVE_LEVEL		========================================================================== */VOID AssocStateMachineInit(	IN	PRTMP_ADAPTER	pAd, 	IN  STATE_MACHINE *S, 	OUT STATE_MACHINE_FUNC Trans[]) {	StateMachineInit(S, Trans, MAX_ASSOC_STATE, MAX_ASSOC_MSG, (STATE_MACHINE_FUNC)Drop, ASSOC_IDLE, ASSOC_MACHINE_BASE);	// first column	StateMachineSetAction(S, ASSOC_IDLE, MT2_MLME_ASSOC_REQ, (STATE_MACHINE_FUNC)MlmeAssocReqAction);	StateMachineSetAction(S, ASSOC_IDLE, MT2_MLME_REASSOC_REQ, (STATE_MACHINE_FUNC)MlmeReassocReqAction);	StateMachineSetAction(S, ASSOC_IDLE, MT2_MLME_DISASSOC_REQ, (STATE_MACHINE_FUNC)MlmeDisassocReqAction);	StateMachineSetAction(S, ASSOC_IDLE, MT2_PEER_DISASSOC_REQ, (STATE_MACHINE_FUNC)PeerDisassocAction);	// second column	StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_MLME_ASSOC_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenAssoc);	StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_MLME_REASSOC_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenReassoc);	StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_MLME_DISASSOC_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenDisassociate);	StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_PEER_DISASSOC_REQ, (STATE_MACHINE_FUNC)PeerDisassocAction);	StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_PEER_ASSOC_RSP, (STATE_MACHINE_FUNC)PeerAssocRspAction);	//	// Patch 3Com AP MOde:3CRWE454G72	// We send Assoc request frame to this AP, it always send Reassoc Rsp not Associate Rsp.	//	StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_PEER_REASSOC_RSP, (STATE_MACHINE_FUNC)PeerAssocRspAction);	StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_ASSOC_TIMEOUT, (STATE_MACHINE_FUNC)AssocTimeoutAction);	// third column	StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_MLME_ASSOC_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenAssoc);	StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_MLME_REASSOC_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenReassoc);	StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_MLME_DISASSOC_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenDisassociate);	StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_PEER_DISASSOC_REQ, (STATE_MACHINE_FUNC)PeerDisassocAction);	StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_PEER_REASSOC_RSP, (STATE_MACHINE_FUNC)PeerReassocRspAction);	//	// Patch, AP doesn't send Reassociate Rsp frame to Station.	//	StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_PEER_ASSOC_RSP, (STATE_MACHINE_FUNC)PeerReassocRspAction);		StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_REASSOC_TIMEOUT, (STATE_MACHINE_FUNC)ReassocTimeoutAction);	// fourth column	StateMachineSetAction(S, DISASSOC_WAIT_RSP, MT2_MLME_ASSOC_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenAssoc);	StateMachineSetAction(S, DISASSOC_WAIT_RSP, MT2_MLME_REASSOC_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenReassoc);	StateMachineSetAction(S, DISASSOC_WAIT_RSP, MT2_MLME_DISASSOC_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenDisassociate);	StateMachineSetAction(S, DISASSOC_WAIT_RSP, MT2_PEER_DISASSOC_REQ, (STATE_MACHINE_FUNC)PeerDisassocAction);	StateMachineSetAction(S, DISASSOC_WAIT_RSP, MT2_DISASSOC_TIMEOUT, (STATE_MACHINE_FUNC)DisassocTimeoutAction);	// initialize the timer	RTMPInitTimer(pAd, &pAd->MlmeAux.AssocTimer, GET_TIMER_FUNCTION(AssocTimeout), pAd, FALSE);	RTMPInitTimer(pAd, &pAd->MlmeAux.ReassocTimer, GET_TIMER_FUNCTION(ReassocTimeout), pAd, FALSE);	RTMPInitTimer(pAd, &pAd->MlmeAux.DisassocTimer, GET_TIMER_FUNCTION(DisassocTimeout), pAd, FALSE);}/*	==========================================================================	Description:		Association timeout procedure. After association timeout, this function 		will be called and it will put a message into the MLME queue	Parameters:		Standard timer parameters	IRQL = DISPATCH_LEVEL	========================================================================== */VOID AssocTimeout(IN PVOID SystemSpecific1, 				 IN PVOID FunctionContext, 				 IN PVOID SystemSpecific2, 				 IN PVOID SystemSpecific3) {	RTMP_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 | fRTMP_ADAPTER_NIC_NOT_EXIST))		return;		MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_ASSOC_TIMEOUT, 0, NULL);	RTMP_MLME_HANDLER(pAd);}/*	==========================================================================	Description:		Reassociation timeout procedure. After reassociation timeout, this 		function will be called and put a message into the MLME queue	Parameters:		Standard timer parameters	IRQL = DISPATCH_LEVEL	========================================================================== */VOID ReassocTimeout(IN PVOID SystemSpecific1, 					IN PVOID FunctionContext, 					IN PVOID SystemSpecific2, 					IN PVOID SystemSpecific3) {	RTMP_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 | fRTMP_ADAPTER_NIC_NOT_EXIST))		return;		MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_REASSOC_TIMEOUT, 0, NULL);	RTMP_MLME_HANDLER(pAd);}/*	==========================================================================	Description:		Disassociation timeout procedure. After disassociation timeout, this 		function will be called and put a message into the MLME queue	Parameters:		Standard timer parameters	IRQL = DISPATCH_LEVEL	========================================================================== */VOID DisassocTimeout(IN PVOID SystemSpecific1, 					IN PVOID FunctionContext, 					IN PVOID SystemSpecific2, 					IN PVOID SystemSpecific3) {	RTMP_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 | fRTMP_ADAPTER_NIC_NOT_EXIST))		return;		MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_DISASSOC_TIMEOUT, 0, NULL);	RTMP_MLME_HANDLER(pAd);}/*	==========================================================================	Description:		mlme assoc req handling procedure	Parameters:		Adapter - Adapter pointer		Elem - MLME Queue Element	Pre:		the station has been authenticated and the following information is stored in the config			-# SSID			-# supported rates and their length			-# listen interval (Adapter->StaCfg.default_listen_count)			-# Transmit power  (Adapter->StaCfg.tx_power)	Post  :		-# An association request frame is generated and sent to the air		-# Association timer starts		-# Association state -> ASSOC_WAIT_RSP	IRQL = DISPATCH_LEVEL	========================================================================== */VOID MlmeAssocReqAction(	IN PRTMP_ADAPTER pAd, 	IN MLME_QUEUE_ELEM *Elem) {	UCHAR			ApAddr[6];	HEADER_802_11	AssocHdr;	UCHAR			WmeIe[9] = {IE_VENDOR_SPECIFIC, 0x07, 0x00, 0x50, 0xf2, 0x02, 0x00, 0x01, 0x00};	USHORT			ListenIntv;	ULONG			Timeout;	USHORT			CapabilityInfo;	BOOLEAN			TimerCancelled;	PUCHAR			pOutBuffer = NULL;	NDIS_STATUS		NStatus;	ULONG			FrameLen = 0;	ULONG			tmp;	USHORT			VarIesOffset;	USHORT			Status;	// Block all authentication request durning WPA block period	if (pAd->StaCfg.bBlockAssoc == TRUE)	{		DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - Block Assoc request durning WPA block period!\n"));		pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;		Status = MLME_STATE_MACHINE_REJECT;		MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_ASSOC_CONF, 2, &Status);	}		// check sanity first	else if (MlmeAssocReqSanity(pAd, Elem->Msg, Elem->MsgLen, ApAddr, &CapabilityInfo, &Timeout, &ListenIntv)) 	{		RTMPCancelTimer(&pAd->MlmeAux.AssocTimer, &TimerCancelled);		COPY_MAC_ADDR(pAd->MlmeAux.Bssid, ApAddr);		// Get an unused nonpaged memory		NStatus = MlmeAllocateMemory(pAd, &pOutBuffer);  		if (NStatus != NDIS_STATUS_SUCCESS) 		{			DBGPRINT(RT_DEBUG_TRACE,("ASSOC - MlmeAssocReqAction() allocate memory failed \n"));			pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;			Status = MLME_FAIL_NO_RESOURCE;			MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_ASSOC_CONF, 2, &Status);			return;		}		// Add by James 03/06/27		pAd->StaCfg.AssocInfo.Length = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION); 		// Association don't need to report MAC address		pAd->StaCfg.AssocInfo.AvailableRequestFixedIEs =			NDIS_802_11_AI_REQFI_CAPABILITIES | NDIS_802_11_AI_REQFI_LISTENINTERVAL;		pAd->StaCfg.AssocInfo.RequestFixedIEs.Capabilities = CapabilityInfo;		pAd->StaCfg.AssocInfo.RequestFixedIEs.ListenInterval = ListenIntv;				// Only reassociate need this		//COPY_MAC_ADDR(pAd->StaCfg.AssocInfo.RequestFixedIEs.CurrentAPAddress, ApAddr);		pAd->StaCfg.AssocInfo.OffsetRequestIEs = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);		        NdisZeroMemory(pAd->StaCfg.ReqVarIEs, MAX_VIE_LEN);		// First add SSID		VarIesOffset = 0;		NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset, &SsidIe, 1);		VarIesOffset += 1;		NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset, &pAd->MlmeAux.SsidLen, 1);		VarIesOffset += 1;		NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen);		VarIesOffset += pAd->MlmeAux.SsidLen;		// Second add Supported rates		NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset, &SupRateIe, 1);		VarIesOffset += 1;		NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset, &pAd->MlmeAux.SupRateLen, 1);		VarIesOffset += 1;		NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset, pAd->MlmeAux.SupRate, pAd->MlmeAux.SupRateLen);		VarIesOffset += pAd->MlmeAux.SupRateLen;		// End Add by James        if ((pAd->CommonCfg.Channel > 14) &&             (pAd->CommonCfg.bIEEE80211H == TRUE))            CapabilityInfo |= 0x0100;		DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - Send ASSOC request...\n"));		MgtMacHeaderInit(pAd, &AssocHdr, SUBTYPE_ASSOC_REQ, 0, ApAddr, ApAddr);				// Build basic frame first		MakeOutgoingFrame(pOutBuffer,				&FrameLen,						  sizeof(HEADER_802_11),	&AssocHdr,						  2,						&CapabilityInfo,						  2,						&ListenIntv,						  1,						&SsidIe,						  1,						&pAd->MlmeAux.SsidLen, 						  pAd->MlmeAux.SsidLen, 	pAd->MlmeAux.Ssid,						  1,						&SupRateIe,						  1,						&pAd->MlmeAux.SupRateLen,						  pAd->MlmeAux.SupRateLen,  pAd->MlmeAux.SupRate,						  END_OF_ARGS);		if (pAd->MlmeAux.ExtRateLen != 0)		{			MakeOutgoingFrame(pOutBuffer + FrameLen,    &tmp,							  1,                        &ExtRateIe,							  1,                        &pAd->MlmeAux.ExtRateLen,							  pAd->MlmeAux.ExtRateLen,  pAd->MlmeAux.ExtRate,														  END_OF_ARGS);			FrameLen += tmp;		}#ifdef DOT11_N_SUPPORT		// HT		if ((pAd->MlmeAux.HtCapabilityLen > 0) && (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED))		{			ULONG TmpLen;			UCHAR HtLen;			UCHAR BROADCOM[4] = {0x0, 0x90, 0x4c, 0x33};			if (pAd->StaActive.SupportedPhyInfo.bPreNHt == TRUE)			{				HtLen = SIZE_HT_CAP_IE + 4;				MakeOutgoingFrame(pOutBuffer + FrameLen,            &TmpLen,							  1,                                &WpaIe,							  1,                                &HtLen,							  4,                                &BROADCOM[0],							 pAd->MlmeAux.HtCapabilityLen,          &pAd->MlmeAux.HtCapability, 							  END_OF_ARGS);			}			else							{#ifdef RT_BIG_ENDIAN		        HT_CAPABILITY_IE HtCapabilityTmp;#endif			#ifndef RT_BIG_ENDIAN				MakeOutgoingFrame(pOutBuffer + FrameLen,            &TmpLen,							  1,                                &HtCapIe,							  1,                                &pAd->MlmeAux.HtCapabilityLen,							 pAd->MlmeAux.HtCapabilityLen,          &pAd->MlmeAux.HtCapability, 							  END_OF_ARGS);#else                NdisZeroMemory(&HtCapabilityTmp, sizeof(HT_CAPABILITY_IE));                NdisMoveMemory(&HtCapabilityTmp, &pAd->MlmeAux.HtCapability, pAd->MlmeAux.HtCapabilityLen);        		*(USHORT *)(&HtCapabilityTmp.HtCapInfo) = SWAP16(*(USHORT *)(&HtCapabilityTmp.HtCapInfo));        		*(USHORT *)(&HtCapabilityTmp.ExtHtCapInfo) = SWAP16(*(USHORT *)(&HtCapabilityTmp.ExtHtCapInfo));        		MakeOutgoingFrame(pOutBuffer + FrameLen,         &TmpLen,        							1,                           &HtCapIe,        							1,                           &pAd->MlmeAux.HtCapabilityLen,        							pAd->MlmeAux.HtCapabilityLen,&HtCapabilityTmp,         							END_OF_ARGS);#endif			}			FrameLen += TmpLen;		}#endif // DOT11_N_SUPPORT //		// add Ralink proprietary IE to inform AP this STA is going to use AGGREGATION or PIGGY-BACK+AGGREGATION		// Case I: (Aggregation + Piggy-Back)		// 1. user enable aggregation, AND		// 2. Mac support piggy-back		// 3. AP annouces it's PIGGY-BACK+AGGREGATION-capable in BEACON		// Case II: (Aggregation)		// 1. user enable aggregation, AND		// 2. AP annouces it's AGGREGATION-capable in BEACON		if (pAd->CommonCfg.bAggregationCapable)		{			if ((pAd->CommonCfg.bPiggyBackCapable) && ((pAd->MlmeAux.APRalinkIe & 0x00000003) == 3))			{				ULONG TmpLen;				UCHAR RalinkIe[9] = {IE_VENDOR_SPECIFIC, 7, 0x00, 0x0c, 0x43, 0x03, 0x00, 0x00, 0x00}; 				MakeOutgoingFrame(pOutBuffer+FrameLen,           &TmpLen,								  9,                             RalinkIe,								  END_OF_ARGS);				FrameLen += TmpLen;			}			else if (pAd->MlmeAux.APRalinkIe & 0x00000001)			{				ULONG TmpLen;				UCHAR RalinkIe[9] = {IE_VENDOR_SPECIFIC, 7, 0x00, 0x0c, 0x43, 0x01, 0x00, 0x00, 0x00}; 				MakeOutgoingFrame(pOutBuffer+FrameLen,           &TmpLen,								  9,                             RalinkIe,								  END_OF_ARGS);				FrameLen += TmpLen;			}		}		else		{			ULONG TmpLen;			UCHAR RalinkIe[9] = {IE_VENDOR_SPECIFIC, 7, 0x00, 0x0c, 0x43, 0x06, 0x00, 0x00, 0x00}; 			MakeOutgoingFrame(pOutBuffer+FrameLen,		 &TmpLen,							  9,						 RalinkIe,

⌨️ 快捷键说明

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