mlme.c

来自「ralink最新rt3070 usb wifi 无线网卡驱动程序」· C语言 代码 · 共 1,979 行 · 第 1/5 页

C
1,979
字号
/* ************************************************************************* * 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:	mlme.c	Abstract:	Revision History:	Who			When			What	--------	----------		----------------------------------------------	John Chang	2004-08-25		Modify from RT2500 code base	John Chang	2004-09-06		modified for RT2600*/#include "rt_config.h"#include <stdarg.h>UCHAR	CISCO_OUI[] = {0x00, 0x40, 0x96};UCHAR	WPA_OUI[] = {0x00, 0x50, 0xf2, 0x01};UCHAR	RSN_OUI[] = {0x00, 0x0f, 0xac};UCHAR	WAPI_OUI[] = {0x00, 0x14, 0x72};UCHAR   WME_INFO_ELEM[]  = {0x00, 0x50, 0xf2, 0x02, 0x00, 0x01};UCHAR   WME_PARM_ELEM[] = {0x00, 0x50, 0xf2, 0x02, 0x01, 0x01};UCHAR	Ccx2QosInfo[] = {0x00, 0x40, 0x96, 0x04};UCHAR   RALINK_OUI[]  = {0x00, 0x0c, 0x43};UCHAR   BROADCOM_OUI[]  = {0x00, 0x90, 0x4c};UCHAR   WPS_OUI[] = {0x00, 0x50, 0xf2, 0x04};#ifdef CONFIG_STA_SUPPORT#ifdef DOT11_N_SUPPORTUCHAR	PRE_N_HT_OUI[]	= {0x00, 0x90, 0x4c};#endif // DOT11_N_SUPPORT //#endif // CONFIG_STA_SUPPORT //UCHAR RateSwitchTable[] = {// Item No.   Mode   Curr-MCS   TrainUp   TrainDown		// Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF)    0x11, 0x00,  0,  0,  0,						// Initial used item after association    0x00, 0x00,  0, 40, 101,    0x01, 0x00,  1, 40, 50,    0x02, 0x00,  2, 35, 45,    0x03, 0x00,  3, 20, 45,    0x04, 0x21,  0, 30, 50,    0x05, 0x21,  1, 20, 50,    0x06, 0x21,  2, 20, 50,    0x07, 0x21,  3, 15, 50,    0x08, 0x21,  4, 15, 30,    0x09, 0x21,  5, 10, 25,    0x0a, 0x21,  6,  8, 25,    0x0b, 0x21,  7,  8, 25,    0x0c, 0x20, 12,  15, 30,    0x0d, 0x20, 13,  8, 20,    0x0e, 0x20, 14,  8, 20,    0x0f, 0x20, 15,  8, 25,    0x10, 0x22, 15,  8, 25,    0x11, 0x00,  0,  0,  0,    0x12, 0x00,  0,  0,  0,    0x13, 0x00,  0,  0,  0,    0x14, 0x00,  0,  0,  0,    0x15, 0x00,  0,  0,  0,    0x16, 0x00,  0,  0,  0,    0x17, 0x00,  0,  0,  0,    0x18, 0x00,  0,  0,  0,    0x19, 0x00,  0,  0,  0,    0x1a, 0x00,  0,  0,  0,    0x1b, 0x00,  0,  0,  0,    0x1c, 0x00,  0,  0,  0,    0x1d, 0x00,  0,  0,  0,    0x1e, 0x00,  0,  0,  0,    0x1f, 0x00,  0,  0,  0,};UCHAR RateSwitchTable11B[] = {// Item No.   Mode   Curr-MCS   TrainUp   TrainDown		// Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF)    0x04, 0x03,  0,  0,  0,						// Initial used item after association    0x00, 0x00,  0, 40, 101,    0x01, 0x00,  1, 40, 50,    0x02, 0x00,  2, 35, 45,    0x03, 0x00,  3, 20, 45,};UCHAR RateSwitchTable11BG[] = {// Item No.   Mode   Curr-MCS   TrainUp   TrainDown		// Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF)    0x0a, 0x00,  0,  0,  0,						// Initial used item after association    0x00, 0x00,  0, 40, 101,    0x01, 0x00,  1, 40, 50,    0x02, 0x00,  2, 35, 45,    0x03, 0x00,  3, 20, 45,    0x04, 0x10,  2, 20, 35,    0x05, 0x10,  3, 16, 35,    0x06, 0x10,  4, 10, 25,    0x07, 0x10,  5, 16, 25,    0x08, 0x10,  6, 10, 25,    0x09, 0x10,  7, 10, 13,};UCHAR RateSwitchTable11G[] = {// Item No.   Mode   Curr-MCS   TrainUp   TrainDown		// Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF)    0x08, 0x00,  0,  0,  0,						// Initial used item after association    0x00, 0x10,  0, 20, 101,    0x01, 0x10,  1, 20, 35,    0x02, 0x10,  2, 20, 35,    0x03, 0x10,  3, 16, 35,    0x04, 0x10,  4, 10, 25,    0x05, 0x10,  5, 16, 25,    0x06, 0x10,  6, 10, 25,    0x07, 0x10,  7, 10, 13,};#ifdef DOT11_N_SUPPORTUCHAR RateSwitchTable11N1S[] = {// Item No.   Mode   Curr-MCS   TrainUp   TrainDown		// Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF)    0x09, 0x00,  0,  0,  0,						// Initial used item after association    0x00, 0x21,  0, 30, 101,    0x01, 0x21,  1, 20, 50,    0x02, 0x21,  2, 20, 50,    0x03, 0x21,  3, 15, 50,    0x04, 0x21,  4, 15, 30,    0x05, 0x21,  5, 10, 25,    0x06, 0x21,  6,  8, 14,    0x07, 0x21,  7,  8, 14,    0x08, 0x23,  7,  8, 14,};UCHAR RateSwitchTable11N2S[] = {// Item No.   Mode   Curr-MCS   TrainUp   TrainDown		// Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF)    0x0a, 0x00,  0,  0,  0,      // Initial used item after association    0x00, 0x21,  0, 30, 101,    0x01, 0x21,  1, 20, 50,    0x02, 0x21,  2, 20, 50,    0x03, 0x21,  3, 15, 50,    0x04, 0x21,  4, 15, 30,    0x05, 0x20, 12,  15, 30,    0x06, 0x20, 13,  8, 20,    0x07, 0x20, 14,  8, 20,    0x08, 0x20, 15,  8, 25,    0x09, 0x22, 15,  8, 25,};UCHAR RateSwitchTable11N3S[] = {// Item No.	Mode	Curr-MCS	TrainUp	TrainDown	// Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF)    0x0a, 0x00,  0,  0,  0,      // Initial used item after association    0x00, 0x21,  0, 30, 101,    0x01, 0x21,  1, 20, 50,    0x02, 0x21,  2, 20, 50,    0x03, 0x21,  3, 15, 50,    0x04, 0x21,  4, 15, 30,    0x05, 0x20, 12,  15, 30,    0x06, 0x20, 13,  8, 20,    0x07, 0x20, 14,  8, 20,    0x08, 0x20, 15,  8, 25,    0x09, 0x22, 15,  8, 25,};UCHAR RateSwitchTable11N2SForABand[] = {// Item No.   Mode   Curr-MCS   TrainUp   TrainDown		// Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF)    0x0b, 0x09,  0,  0,  0,						// Initial used item after association    0x00, 0x21,  0, 30, 101,    0x01, 0x21,  1, 20, 50,    0x02, 0x21,  2, 20, 50,    0x03, 0x21,  3, 15, 50,    0x04, 0x21,  4, 15, 30,    0x05, 0x21,  5, 15, 30,    0x06, 0x20, 12,  15, 30,    0x07, 0x20, 13,  8, 20,    0x08, 0x20, 14,  8, 20,    0x09, 0x20, 15,  8, 25,    0x0a, 0x22, 15,  8, 25,};UCHAR RateSwitchTable11N3SForABand[] = { // 3*3// Item No.   Mode   Curr-MCS   TrainUp   TrainDown		// Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF)    0x0b, 0x09,  0,  0,  0,						// Initial used item after association    0x00, 0x21,  0, 30, 101,    0x01, 0x21,  1, 20, 50,    0x02, 0x21,  2, 20, 50,    0x03, 0x21,  3, 15, 50,    0x04, 0x21,  4, 15, 30,    0x05, 0x21,  5, 15, 30,    0x06, 0x20, 12,  15, 30,    0x07, 0x20, 13,  8, 20,    0x08, 0x20, 14,  8, 20,    0x09, 0x20, 15,  8, 25,    0x0a, 0x22, 15,  8, 25,};UCHAR RateSwitchTable11BGN1S[] = {// Item No.   Mode   Curr-MCS   TrainUp   TrainDown		// Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF)    0x0d, 0x00,  0,  0,  0,						// Initial used item after association    0x00, 0x00,  0, 40, 101,    0x01, 0x00,  1, 40, 50,    0x02, 0x00,  2, 35, 45,    0x03, 0x00,  3, 20, 45,    0x04, 0x21,  0, 30,101,	//50    0x05, 0x21,  1, 20, 50,    0x06, 0x21,  2, 20, 50,    0x07, 0x21,  3, 15, 50,    0x08, 0x21,  4, 15, 30,    0x09, 0x21,  5, 10, 25,    0x0a, 0x21,  6,  8, 14,    0x0b, 0x21,  7,  8, 14,	0x0c, 0x23,  7,  8, 14,};UCHAR RateSwitchTable11BGN2S[] = {// Item No.   Mode   Curr-MCS   TrainUp   TrainDown		// Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF)    0x0a, 0x00,  0,  0,  0,						// Initial used item after association    0x00, 0x21,  0, 30,101,	//50    0x01, 0x21,  1, 20, 50,    0x02, 0x21,  2, 20, 50,    0x03, 0x21,  3, 15, 50,    0x04, 0x21,  4, 15, 30,    0x05, 0x20, 12, 15, 30,    0x06, 0x20, 13,  8, 20,    0x07, 0x20, 14,  8, 20,    0x08, 0x20, 15,  8, 25,    0x09, 0x22, 15,  8, 25,};UCHAR RateSwitchTable11BGN3S[] = { // 3*3// Item No.   Mode   Curr-MCS   TrainUp   TrainDown		// Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF)    0x0a, 0x00,  0,  0,  0,						// Initial used item after association    0x00, 0x21,  0, 30,101,	//50    0x01, 0x21,  1, 20, 50,    0x02, 0x21,  2, 20, 50,    0x03, 0x21,  3, 20, 50,    0x04, 0x21,  4, 15, 50,#if 1    0x05, 0x20, 20, 15, 30,    0x06, 0x20, 21,  8, 20,    0x07, 0x20, 22,  8, 20,    0x08, 0x20, 23,  8, 25,    0x09, 0x22, 23,  8, 25,#else // for RT2860 2*3 test    0x05, 0x20, 12, 15, 30,    0x06, 0x20, 13,  8, 20,    0x07, 0x20, 14,  8, 20,    0x08, 0x20, 15,  8, 25,    0x09, 0x22, 15,  8, 25,#endif};UCHAR RateSwitchTable11BGN2SForABand[] = {// Item No.   Mode   Curr-MCS   TrainUp   TrainDown		// Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF)    0x0b, 0x09,  0,  0,  0,						// Initial used item after association    0x00, 0x21,  0, 30,101,	//50    0x01, 0x21,  1, 20, 50,    0x02, 0x21,  2, 20, 50,    0x03, 0x21,  3, 15, 50,    0x04, 0x21,  4, 15, 30,    0x05, 0x21,  5, 15, 30,    0x06, 0x20, 12, 15, 30,    0x07, 0x20, 13,  8, 20,    0x08, 0x20, 14,  8, 20,    0x09, 0x20, 15,  8, 25,    0x0a, 0x22, 15,  8, 25,};UCHAR RateSwitchTable11BGN3SForABand[] = { // 3*3// Item No.   Mode   Curr-MCS   TrainUp   TrainDown		// Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF)    0x0c, 0x09,  0,  0,  0,						// Initial used item after association    0x00, 0x21,  0, 30,101,	//50    0x01, 0x21,  1, 20, 50,    0x02, 0x21,  2, 20, 50,    0x03, 0x21,  3, 15, 50,    0x04, 0x21,  4, 15, 30,    0x05, 0x21,  5, 15, 30,    0x06, 0x21, 12, 15, 30,    0x07, 0x20, 20, 15, 30,    0x08, 0x20, 21,  8, 20,    0x09, 0x20, 22,  8, 20,    0x0a, 0x20, 23,  8, 25,    0x0b, 0x22, 23,  8, 25,};#endif // DOT11_N_SUPPORT //PUCHAR ReasonString[] = {	/* 0  */	 "Reserved",	/* 1  */	 "Unspecified Reason",	/* 2  */	 "Previous Auth no longer valid",	/* 3  */	 "STA is leaving / has left",	/* 4  */	 "DIS-ASSOC due to inactivity",	/* 5  */	 "AP unable to hanle all associations",	/* 6  */	 "class 2 error",	/* 7  */	 "class 3 error",	/* 8  */	 "STA is leaving / has left",	/* 9  */	 "require auth before assoc/re-assoc",	/* 10 */	 "Reserved",	/* 11 */	 "Reserved",	/* 12 */	 "Reserved",	/* 13 */	 "invalid IE",	/* 14 */	 "MIC error",	/* 15 */	 "4-way handshake timeout",	/* 16 */	 "2-way (group key) handshake timeout",	/* 17 */	 "4-way handshake IE diff among AssosReq/Rsp/Beacon",	/* 18 */};extern UCHAR	 OfdmRateToRxwiMCS[];// since RT61 has better RX sensibility, we have to limit TX ACK rate not to exceed our normal data TX rate.// otherwise the WLAN peer may not be able to receive the ACK thus downgrade its data TX rateULONG BasicRateMask[12]				= {0xfffff001 /* 1-Mbps */, 0xfffff003 /* 2 Mbps */, 0xfffff007 /* 5.5 */, 0xfffff00f /* 11 */,									  0xfffff01f /* 6 */	 , 0xfffff03f /* 9 */	  , 0xfffff07f /* 12 */ , 0xfffff0ff /* 18 */,									  0xfffff1ff /* 24 */	 , 0xfffff3ff /* 36 */	  , 0xfffff7ff /* 48 */ , 0xffffffff /* 54 */};UCHAR MULTICAST_ADDR[MAC_ADDR_LEN] = {0x1,  0x00, 0x00, 0x00, 0x00, 0x00};UCHAR BROADCAST_ADDR[MAC_ADDR_LEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};UCHAR ZERO_MAC_ADDR[MAC_ADDR_LEN]  = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};// e.g. RssiSafeLevelForTxRate[RATE_36]" means if the current RSSI is greater than //		this value, then it's quaranteed capable of operating in 36 mbps TX rate in //		clean environment.//								  TxRate: 1   2   5.5	11	 6	  9    12	18	 24   36   48	54	 72  100CHAR RssiSafeLevelForTxRate[] ={  -92, -91, -90, -87, -88, -86, -85, -83, -81, -78, -72, -71, -40, -40 };UCHAR  RateIdToMbps[]	 = { 1, 2, 5, 11, 6, 9, 12, 18, 24, 36, 48, 54, 72, 100};USHORT RateIdTo500Kbps[] = { 2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108, 144, 200};UCHAR  SsidIe	 = IE_SSID;UCHAR  SupRateIe = IE_SUPP_RATES;UCHAR  ExtRateIe = IE_EXT_SUPP_RATES;#ifdef DOT11_N_SUPPORTUCHAR  HtCapIe = IE_HT_CAP;UCHAR  AddHtInfoIe = IE_ADD_HT;UCHAR  NewExtChanIe = IE_SECONDARY_CH_OFFSET;#ifdef DOT11N_DRAFT3UCHAR  ExtHtCapIe = IE_EXT_CAPABILITY;#endif // DOT11N_DRAFT3 //#endif // DOT11_N_SUPPORT //UCHAR  ErpIe	 = IE_ERP;UCHAR  DsIe 	 = IE_DS_PARM;UCHAR  TimIe	 = IE_TIM;UCHAR  WpaIe	 = IE_WPA;UCHAR  Wpa2Ie	 = IE_WPA2;UCHAR  IbssIe	 = IE_IBSS_PARM;UCHAR  Ccx2Ie	 = IE_CCX_V2;UCHAR  WapiIe	 = IE_WAPI;extern UCHAR	WPA_OUI[];UCHAR	SES_OUI[] = {0x00, 0x90, 0x4c};UCHAR	ZeroSsid[32] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};// Reset the RFIC setting to new series    RTMP_RF_REGS RF2850RegTable[] = {//		ch	 R1 		 R2 		 R3(TX0~4=0) R4		{1,  0x98402ecc, 0x984c0786, 0x9816b455, 0x9800510b},		{2,  0x98402ecc, 0x984c0786, 0x98168a55, 0x9800519f},		{3,  0x98402ecc, 0x984c078a, 0x98168a55, 0x9800518b},		{4,  0x98402ecc, 0x984c078a, 0x98168a55, 0x9800519f},		{5,  0x98402ecc, 0x984c078e, 0x98168a55, 0x9800518b},		{6,  0x98402ecc, 0x984c078e, 0x98168a55, 0x9800519f},		{7,  0x98402ecc, 0x984c0792, 0x98168a55, 0x9800518b},		{8,  0x98402ecc, 0x984c0792, 0x98168a55, 0x9800519f},		{9,  0x98402ecc, 0x984c0796, 0x98168a55, 0x9800518b},		{10, 0x98402ecc, 0x984c0796, 0x98168a55, 0x9800519f},		{11, 0x98402ecc, 0x984c079a, 0x98168a55, 0x9800518b},		{12, 0x98402ecc, 0x984c079a, 0x98168a55, 0x9800519f},		{13, 0x98402ecc, 0x984c079e, 0x98168a55, 0x9800518b},		{14, 0x98402ecc, 0x984c07a2, 0x98168a55, 0x98005193},		// 802.11 UNI / HyperLan 2		{36, 0x98402ecc, 0x984c099a, 0x98158a55, 0x980ed1a3},		{38, 0x98402ecc, 0x984c099e, 0x98158a55, 0x980ed193},		{40, 0x98402ec8, 0x984c0682, 0x98158a55, 0x980ed183},		{44, 0x98402ec8, 0x984c0682, 0x98158a55, 0x980ed1a3},		{46, 0x98402ec8, 0x984c0686, 0x98158a55, 0x980ed18b},		{48, 0x98402ec8, 0x984c0686, 0x98158a55, 0x980ed19b},		{52, 0x98402ec8, 0x984c068a, 0x98158a55, 0x980ed193},		{54, 0x98402ec8, 0x984c068a, 0x98158a55, 0x980ed1a3},		{56, 0x98402ec8, 0x984c068e, 0x98158a55, 0x980ed18b},

⌨️ 快捷键说明

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