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

📄 cmm_sanity.c

📁 Linux下的RT系列无线网卡驱动,可以直接在x86平台上编译
💻 C
📖 第 1 页 / 共 3 页
字号:
/* ************************************************************************* * 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:	sanity.c	Abstract:	Revision History:	Who			When			What	--------	----------		----------------------------------------------	John Chang  2004-09-01      add WMM support*/#include "rt_config.h"extern UCHAR	CISCO_OUI[];extern UCHAR	WPA_OUI[];extern UCHAR	RSN_OUI[];extern UCHAR	WME_INFO_ELEM[];extern UCHAR	WME_PARM_ELEM[];extern UCHAR	Ccx2QosInfo[];extern UCHAR	RALINK_OUI[];extern UCHAR	BROADCOM_OUI[];extern UCHAR    WPS_OUI[];/*     ==========================================================================    Description:        MLME message sanity check    Return:        TRUE if all parameters are OK, FALSE otherwise        	IRQL = DISPATCH_LEVEL    ========================================================================== */BOOLEAN MlmeAddBAReqSanity(    IN PRTMP_ADAPTER pAd,     IN VOID *Msg,     IN ULONG MsgLen,     OUT PUCHAR pAddr2) {    PMLME_ADDBA_REQ_STRUCT   pInfo;    pInfo = (MLME_ADDBA_REQ_STRUCT *)Msg;    if ((MsgLen != sizeof(MLME_ADDBA_REQ_STRUCT)))    {        DBGPRINT(RT_DEBUG_TRACE, ("MlmeAddBAReqSanity fail - message lenght not correct.\n"));        return FALSE;    }		    if ((pInfo->Wcid >= MAX_LEN_OF_MAC_TABLE))    {        DBGPRINT(RT_DEBUG_TRACE, ("MlmeAddBAReqSanity fail - The peer Mac is not associated yet.\n"));        return FALSE;    }		/*    if ((pInfo->BaBufSize > Max_RX_REORDERBUF) || (pInfo->BaBufSize < 2))    {        DBGPRINT(RT_DEBUG_TRACE, ("MlmeAddBAReqSanity fail - Rx Reordering buffer too big or too small\n"));        return FALSE;    } 	*/      if ((pInfo->pAddr[0]&0x01) == 0x01)    {        DBGPRINT(RT_DEBUG_TRACE, ("MlmeAddBAReqSanity fail - broadcast address not support BA\n"));        return FALSE;    }	        return TRUE;}/*     ==========================================================================    Description:        MLME message sanity check    Return:        TRUE if all parameters are OK, FALSE otherwise        	IRQL = DISPATCH_LEVEL    ========================================================================== */BOOLEAN MlmeDelBAReqSanity(    IN PRTMP_ADAPTER pAd,     IN VOID *Msg,     IN ULONG MsgLen) {	MLME_DELBA_REQ_STRUCT *pInfo;	pInfo = (MLME_DELBA_REQ_STRUCT *)Msg;    if ((MsgLen != sizeof(MLME_DELBA_REQ_STRUCT)))    {        DBGPRINT(RT_DEBUG_TRACE, ("MlmeDelBAReqSanity fail - message lenght not correct.\n"));        return FALSE;    }		    if ((pInfo->Wcid >= MAX_LEN_OF_MAC_TABLE))    {        DBGPRINT(RT_DEBUG_TRACE, ("MlmeDelBAReqSanity fail - The peer Mac is not associated yet.\n"));        return FALSE;    }	    if ((pInfo->TID & 0xf0))    {        DBGPRINT(RT_DEBUG_TRACE, ("MlmeDelBAReqSanity fail - The peer TID is incorrect.\n"));        return FALSE;    }	        return TRUE;}BOOLEAN PeerAddBAReqActionSanity(    IN PRTMP_ADAPTER pAd,     IN VOID *pMsg,     IN ULONG MsgLen,	OUT PUCHAR pAddr2){	PFRAME_802_11 pFrame = (PFRAME_802_11)pMsg;	PFRAME_ADDBA_REQ pAddFrame;	pAddFrame = (PFRAME_ADDBA_REQ)(pMsg);	if (MsgLen < (sizeof(FRAME_ADDBA_REQ)))	{		DBGPRINT(RT_DEBUG_ERROR,("PeerAddBAReqActionSanity: ADDBA Request frame length size = %ld incorrect\n", MsgLen));		return FALSE;	}	// we support immediate BA.#ifdef BIG_ENDIAN	*(USHORT *)(&pAddFrame->BaParm) = SWAP16(*(USHORT *)(&pAddFrame->BaParm));	pAddFrame->TimeOutValue = SWAP16(pAddFrame->TimeOutValue);	pAddFrame->BaStartSeq.word = SWAP16(pAddFrame->BaStartSeq.word); #endif	if (pAddFrame->BaParm.BAPolicy != IMMED_BA)	{		DBGPRINT(RT_DEBUG_ERROR,("PeerAddBAReqActionSanity: ADDBA Request Ba Policy[%d] not support\n", pAddFrame->BaParm.BAPolicy));		DBGPRINT(RT_DEBUG_ERROR,("ADDBA Request. tid=%x, Bufsize=%x, AMSDUSupported=%x \n", pAddFrame->BaParm.TID, pAddFrame->BaParm.BufSize, pAddFrame->BaParm.AMSDUSupported));		return FALSE;	}	// we support immediate BA.	if (pAddFrame->BaParm.TID &0xfff0)	{		DBGPRINT(RT_DEBUG_ERROR,("PeerAddBAReqActionSanity: ADDBA Request incorrect TID = %d\n", pAddFrame->BaParm.TID));		return FALSE;	}	COPY_MAC_ADDR(pAddr2, pFrame->Hdr.Addr2);	return TRUE;}BOOLEAN PeerAddBARspActionSanity(    IN PRTMP_ADAPTER pAd,     IN VOID *pMsg,     IN ULONG MsgLen){	//PFRAME_802_11 pFrame = (PFRAME_802_11)pMsg;	PFRAME_ADDBA_RSP pAddFrame;		pAddFrame = (PFRAME_ADDBA_RSP)(pMsg);	if (MsgLen < (sizeof(FRAME_ADDBA_RSP)))	{		DBGPRINT(RT_DEBUG_ERROR,("PeerAddBARspActionSanity: ADDBA Response frame length size = %ld incorrect\n", MsgLen));		return FALSE;	}	// we support immediate BA.#ifdef BIG_ENDIAN	*(USHORT *)(&pAddFrame->BaParm) = SWAP16(*(USHORT *)(&pAddFrame->BaParm));	pAddFrame->StatusCode = SWAP16(pAddFrame->StatusCode);	pAddFrame->TimeOutValue = SWAP16(pAddFrame->TimeOutValue);#endif	if (pAddFrame->BaParm.BAPolicy != IMMED_BA)	{		DBGPRINT(RT_DEBUG_ERROR,("PeerAddBAReqActionSanity: ADDBA Response Ba Policy[%d] not support\n", pAddFrame->BaParm.BAPolicy));		return FALSE;	}	// we support immediate BA.	if (pAddFrame->BaParm.TID &0xfff0)	{		DBGPRINT(RT_DEBUG_ERROR,("PeerAddBARspActionSanity: ADDBA Response incorrect TID = %d\n", pAddFrame->BaParm.TID));		return FALSE;	}	return TRUE;}BOOLEAN PeerDelBAActionSanity(    IN PRTMP_ADAPTER pAd,     IN UCHAR Wcid,     IN VOID *pMsg,     IN ULONG MsgLen ){	//PFRAME_802_11 pFrame = (PFRAME_802_11)pMsg;	PFRAME_DELBA_REQ  pDelFrame;	if (MsgLen != (sizeof(FRAME_DELBA_REQ)))		return FALSE;		if (Wcid >= MAX_LEN_OF_MAC_TABLE)		return FALSE;		pDelFrame = (PFRAME_DELBA_REQ)(pMsg);#ifdef BIG_ENDIAN	*(USHORT *)(&pDelFrame->DelbaParm) = SWAP16(*(USHORT *)(&pDelFrame->DelbaParm));	pDelFrame->ReasonCode = SWAP16(pDelFrame->ReasonCode);#endif	if (pDelFrame->DelbaParm.TID &0xfff0)		return FALSE;		return TRUE;}/*     ==========================================================================    Description:        MLME message sanity check    Return:        TRUE if all parameters are OK, FALSE otherwise        	IRQL = DISPATCH_LEVEL    ========================================================================== */BOOLEAN PeerBeaconAndProbeRspSanity(    IN PRTMP_ADAPTER pAd,    IN VOID *Msg,     IN ULONG MsgLen,     OUT PUCHAR pAddr2,     OUT PUCHAR pBssid,     OUT CHAR Ssid[],     OUT UCHAR *pSsidLen,     OUT UCHAR *pBssType,     OUT USHORT *pBeaconPeriod,     OUT UCHAR *pChannel,     OUT UCHAR *pNewChannel,     OUT LARGE_INTEGER *pTimestamp,     OUT CF_PARM *pCfParm,     OUT USHORT *pAtimWin,     OUT USHORT *pCapabilityInfo,     OUT UCHAR *pErp,    OUT UCHAR *pDtimCount,     OUT UCHAR *pDtimPeriod,     OUT UCHAR *pBcastFlag,     OUT UCHAR *pMessageToMe,     OUT UCHAR SupRate[],    OUT UCHAR *pSupRateLen,    OUT UCHAR ExtRate[],    OUT UCHAR *pExtRateLen,    OUT	UCHAR *pCkipFlag,    OUT	UCHAR *pAironetCellPowerLimit,    OUT PEDCA_PARM       pEdcaParm,    OUT PQBSS_LOAD_PARM  pQbssLoad,    OUT PQOS_CAPABILITY_PARM pQosCapability,    OUT ULONG *pRalinkIe,    OUT UCHAR		 *pHtCapabilityLen,#ifdef CONFIG_STA_SUPPORT    OUT UCHAR		 *pPreNHtCapabilityLen,#endif // CONFIG_STA_SUPPORT //    OUT HT_CAPABILITY_IE *pHtCapability,	OUT UCHAR		 *AddHtInfoLen,	OUT ADD_HT_INFO_IE *AddHtInfo,	OUT UCHAR *NewExtChannelOffset,		// Ht extension channel offset(above or below)    OUT USHORT *LengthVIE,	    OUT	PNDIS_802_11_VARIABLE_IEs pVIE) {    CHAR				*Ptr;#ifdef CONFIG_STA_SUPPORT	CHAR 				TimLen;#endif // CONFIG_STA_SUPPORT //    PFRAME_802_11		pFrame;    PEID_STRUCT         pEid;    UCHAR				SubType;    UCHAR				Sanity;    //UCHAR				ECWMin, ECWMax;    //MAC_CSR9_STRUC		Csr9;    ULONG				Length = 0;    // Add for 3 necessary EID field check    Sanity = 0;    *pAtimWin = 0;    *pErp = 0;	    *pDtimCount = 0;    *pDtimPeriod = 0;    *pBcastFlag = 0;    *pMessageToMe = 0;    *pExtRateLen = 0;    *pCkipFlag = 0;			        // Default of CkipFlag is 0    *pAironetCellPowerLimit = 0xFF;  // Default of AironetCellPowerLimit is 0xFF    *LengthVIE = 0;					// Set the length of VIE to init value 0    *pHtCapabilityLen = 0;					// Set the length of VIE to init value 0#ifdef CONFIG_STA_SUPPORT    *pPreNHtCapabilityLen = 0;					// Set the length of VIE to init value 0#endif // CONFIG_STA_SUPPORT //    *AddHtInfoLen = 0;					// Set the length of VIE to init value 0    *pRalinkIe = 0;    *pNewChannel = 0;    *NewExtChannelOffset = 0xff;	//Default 0xff means no such IE    pCfParm->bValid = FALSE;        // default: no IE_CF found    pQbssLoad->bValid = FALSE;      // default: no IE_QBSS_LOAD found    pEdcaParm->bValid = FALSE;      // default: no IE_EDCA_PARAMETER found    pQosCapability->bValid = FALSE; // default: no IE_QOS_CAPABILITY found        pFrame = (PFRAME_802_11)Msg;        // get subtype from header    SubType = (UCHAR)pFrame->Hdr.FC.SubType;    // get Addr2 and BSSID from header    COPY_MAC_ADDR(pAddr2, pFrame->Hdr.Addr2);    COPY_MAC_ADDR(pBssid, pFrame->Hdr.Addr3);    //	hex_dump("Beacon", Msg, MsgLen);    Ptr = pFrame->Octet;    Length += LENGTH_802_11;        // get timestamp from payload and advance the pointer    NdisMoveMemory(pTimestamp, Ptr, TIMESTAMP_LEN);#ifdef BIG_ENDIAN	pTimestamp->u.LowPart = SWAP32(pTimestamp->u.LowPart);	pTimestamp->u.HighPart = SWAP32(pTimestamp->u.HighPart);#endif    Ptr += TIMESTAMP_LEN;    Length += TIMESTAMP_LEN;    // get beacon interval from payload and advance the pointer    NdisMoveMemory(pBeaconPeriod, Ptr, 2);    Ptr += 2;    Length += 2;    // get capability info from payload and advance the pointer    NdisMoveMemory(pCapabilityInfo, Ptr, 2);    Ptr += 2;    Length += 2;    if (CAP_IS_ESS_ON(*pCapabilityInfo))         *pBssType = BSS_INFRA;    else         *pBssType = BSS_ADHOC;    pEid = (PEID_STRUCT) Ptr;    // get variable fields from payload and advance the pointer    while ((Length + 2 + pEid->Len) <= MsgLen)        {        //        // Secure copy VIE to VarIE[MAX_VIE_LEN] didn't overflow.        //        if ((*LengthVIE + pEid->Len + 2) >= MAX_VIE_LEN)        {            DBGPRINT(RT_DEBUG_WARN, ("PeerBeaconAndProbeRspSanity - Variable IEs out of resource [len(=%d) > MAX_VIE_LEN(=%d)]\n",                    (*LengthVIE + pEid->Len + 2), MAX_VIE_LEN));            break;        }        switch(pEid->Eid)        {            case IE_SSID:                // Already has one SSID EID in this beacon, ignore the second one                if (Sanity & 0x1)                    break;                if(pEid->Len <= MAX_LEN_OF_SSID)                {                    NdisMoveMemory(Ssid, pEid->Octet, pEid->Len);                    *pSsidLen = pEid->Len;                    Sanity |= 0x1;                }                else                {                    DBGPRINT(RT_DEBUG_TRACE, ("PeerBeaconAndProbeRspSanity - wrong IE_SSID (len=%d)\n",pEid->Len));                    return FALSE;                }                break;            case IE_SUPP_RATES:                if(pEid->Len <= MAX_LEN_OF_SUPPORTED_RATES)                {                    Sanity |= 0x2;                    NdisMoveMemory(SupRate, pEid->Octet, pEid->Len);                    *pSupRateLen = pEid->Len;                    // TODO: 2004-09-14 not a good design here, cause it exclude extra rates                     // from ScanTab. We should report as is. And filter out unsupported                    // rates in MlmeAux.                    // Check against the supported rates                    // RTMPCheckRates(pAd, SupRate, pSupRateLen);                }                else                {                    DBGPRINT(RT_DEBUG_TRACE, ("PeerBeaconAndProbeRspSanity - wrong IE_SUPP_RATES (len=%d)\n",pEid->Len));                    return FALSE;                }                break;            case IE_HT_CAP:			if (pEid->Len >= SIZE_HT_CAP_IE)  //Note: allow extension.!!			{				NdisMoveMemory(pHtCapability, pEid->Octet, sizeof(HT_CAPABILITY_IE));

⌨️ 快捷键说明

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