1 /*************************************************************************
3 * 4F, No. 2 Technology 5th Rd. *
4 * Science-based Industrial Park *
5 * Hsin-chu, Taiwan, R.O.C. *
7 * (c) Copyright 2002, Ralink Technology, Inc. *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
14 * This program is distributed in the hope that it will be useful, *
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
17 * GNU General Public License for more details. *
19 * You should have received a copy of the GNU General Public License *
20 * along with this program; if not, write to the *
21 * Free Software Foundation, Inc., *
22 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 *************************************************************************
33 -------- ---------- ----------------------------------------------
41 // maximum supported capability information -
42 // ESS, IBSS, Privacy, Short Preamble, Short Slot
43 #define SUPPORTED_CAPABILITY_INFO 0x0433
45 #define END_OF_ARGS -1
46 #define LFSR_MASK 0x80000057
47 #define TBTT_PRELOAD_TIME 384 // usec. LomgPreamble + 24-byte at 1Mbps
48 #define MLME_TASK_EXEC_INTV 1000 // 1 sec
50 #define BEACON_LOST_TIME (4*HZ) // 2048 msec = 2 sec
52 //#define AUTH_KEY_TIMEOUT 500 // unit: msec
53 //#define AUTH_OPEN_TIMEOUT 200 // unit: msec
54 #define AUTH_TIMEOUT 300 // unit: msec
55 #define ASSOC_TIMEOUT 300 // unit: msec
56 #define JOIN_TIMEOUT 2000 // unit: msec
57 #define MIN_CHANNEL_TIME 110 // unit: msec, for dual band scan
58 #define MAX_CHANNEL_TIME 140 // unit: msec, for single band scan
59 #define ACTIVE_SCAN_TIME 30 // Active scan waiting for probe response time
60 #define CW_MIN_IN_BITS 3 // actual CwMin = 2^CW_MIN_IN_BITS - 1 = 7
61 #define CW_MAX_IN_BITS 8 // actual CwMax = 2^CW_MAX_IN_BITS - 1 = 255
63 #define RSSI_TO_DBM_OFFSET 120 // for RT2530 RSSI-115 = dBm
64 #define RSSI_FOR_MID_TX_POWER 55 // -55 db is considered mid-distance
65 #define RSSI_FOR_LOW_TX_POWER 45 // -45 db is considered very short distance and
66 // eligible to use a lower TX power
67 #define RSSI_FOR_LOWEST_TX_POWER 30
68 #define MID_TX_POWER_DELTA 0 // -3 db from full TX power upon mid-distance to AP
69 #define LOW_TX_POWER_DELTA 3 // -8 db from full TX power upon very short distance
70 #define LOWEST_TX_POWER_DELTA 6 // -12 db from full TX power upon shortest distance
72 #define RSSI_TRIGGERED_UPON_BELOW_THRESHOLD 0
73 #define RSSI_TRIGGERED_UPON_EXCCEED_THRESHOLD 1
74 #define RSSI_THRESHOLD_FOR_ROAMING 25
77 // Channel Quality Indication
78 //#define CQI_GOOD_THRESHOLD 70 // >= this threshold means channel quality GOOD
79 //#define CQI_FAIR_THRESHOLD 50 // >= this threshold means channel quality FAIR
80 //#define CQI_POOR_THRESHOLD 30 // >= this threshold means channel quality POOR
81 // < this threshold means channel quality really BAD, link down
82 #define CQI_IS_GOOD(cqi) ((cqi) >= 50)
83 #define CQI_IS_FAIR(cqi) (((cqi) >= 20) && ((cqi) < 50)) // (((cqi) >= 50) && ((cqi) < 70))
84 #define CQI_IS_POOR(cqi) (((cqi) >= 5) && ((cqi) < 20)) // (((cqi) >= 25) && ((cqi) < 50))
85 #define CQI_IS_BAD(cqi) ((cqi) < 5) // ((cqi) < 25)
87 // weighting factor to calculate Channel quality, total should be 100%
88 #define RSSI_WEIGHTING 40
89 #define TX_WEIGHTING 40
90 #define RX_WEIGHTING 20
92 // prime number closest to 256
93 //#define HASH_TABLE_SIZE 191 //191 is another prime
94 // Only allows 32 entries in the table
95 #define MAC_TABLE_MAX_CAPACITY 32
97 #define MAC_ENTRY_NOT_USED 0xff
98 #define CONTENT_NOT_AVAIL 0xaa
100 // 10 minute of age out
101 #define MAC_TABLE_AGE_OUT_TIME 0xffffff
103 #define MAC_ADDR_HASH_ERROR 0xfffffffe
104 #define MAC_TABLE_UNKNOWN_INDEX 0xff
105 #define MAC_TABLE_ADDR_NOT_IN 0xfffffffd
107 #define PEER_KEY_NOT_USED 0
108 #define PEER_KEY_64_BIT 64
109 #define PEER_KEY_128_BIT 128
111 #define PEER_KEY_64BIT_LEN 8
112 #define PEER_KEY_128BIT_LEN 16
114 #define MAX_LEN_OF_BSS_TABLE 64
115 #define BSS_NOT_FOUND 0xFFFFFFFF
117 #define MAX_LEN_OF_MLME_QUEUE 10
119 //! assoc state-machine states
121 #define ASSOC_WAIT_RSP 1
122 #define REASSOC_WAIT_RSP 2
123 #define DISASSOC_WAIT_RSP 3
124 #define MAX_ASSOC_STATE 4
126 #define ASSOC_FUNC_SIZE 44 // 4-state * 12-event
128 //authentication state machine
129 #define AUTH_REQ_IDLE 0
130 #define AUTH_WAIT_SEQ2 1
131 #define AUTH_WAIT_SEQ4 2
132 #define MAX_AUTH_STATE 3
134 #define AUTH_FUNC_SIZE 15 // 3-state * 5-event
136 #define AUTH_RSP_IDLE 0
137 #define AUTH_RSP_WAIT_CHAL 1
138 #define MAX_AUTH_RSP_STATE 2
140 #define AUTH_RSP_FUNC_SIZE 6 // 2-state * 3-event
142 // SYNC state machine
143 #define SYNC_IDLE 0 // merge NO_BSS,IBSS_IDLE,IBSS_ACTIVE and BSS in to 1 state
144 #define JOIN_WAIT_BEACON 1
145 #define SCAN_LISTEN 2
146 #define MAX_SYNC_STATE 3
148 #define SYNC_FUNC_SIZE 30 // 3-state * 10-event
150 #define SCAN_PASSIVE 18
151 #define SCAN_ACTIVE 19
154 #define WPA_PSK_IDLE 0
155 #define MAX_WPA_PSK_STATE 1
156 #define WPA_PSK_FUNC_SIZE 5
158 // Control state machine
159 #define CNTL_IDLE 100
160 #define CNTL_WAIT_DISASSOC 101
161 #define CNTL_WAIT_JOIN 102
162 #define CNTL_WAIT_REASSOC 103
163 #define CNTL_WAIT_START 104
164 #define CNTL_WAIT_AUTH 105
165 #define CNTL_WAIT_ASSOC 106
166 #define CNTL_WAIT_AUTH2 107
167 #define CNTL_WAIT_OID_LIST_SCAN 108
168 #define CNTL_WAIT_OID_DISASSOC 109
170 //#define BSS_TABLE_EMPTY(x) ((x).BssNr == 0)
171 #define CapabilityInfoGen(Ess,Ibss,Cfp,CfpReq,Priv) ((Ess) ? 0x0001 : 0x0000) | ((Ibss) ? 0x0002 : 0x0000) | ((Cfp) ? 0x0004 : 0x0000) | ((CfpReq) ? 0x0008 : 0x0000) | ((Priv) ? 0x0010: 0x0000)
173 #define MAC_ADDR_IS_GROUP(Addr) ((((Addr).Octet[0]) & 0x01) != 0)
174 #define MAC_ADDR_HASH(Addr) ((Addr).Octet[0] ^ (Addr).Octet[1] ^ (Addr).Octet[2] ^ (Addr).Octet[3] ^ (Addr).Octet[4] ^ (Addr).Octet[5])
175 #define MAC_ADDR_HASH_INDEX(Addr) (MAC_ADDR_HASH(Addr) % HASH_TABLE_SIZE)
176 #define MAC_ADDR_EQUAL(pAddr1,pAddr2) RTMPEqualMemory((PVOID)(pAddr1), (PVOID)(pAddr2), MAC_ADDR_LEN)
177 #define COPY_MAC_ADDR(Addr1, Addr2) memcpy((Addr1), (Addr2), ETH_LENGTH_OF_ADDRESS)
178 //#define MAKE_BROADCAST_ADDR(Addr) NdisFillMemory(&Addr, MAC_ADDR_LEN, 0xff)
181 // assoiation ON. one LED ON. another blinking when TX, OFF when idle
182 #define ASIC_LED_ACT_ON(pAdapter) RTMP_IO_WRITE32(pAdapter, LEDCSR, 0x0003461E)
183 // no association, both LED off
184 #define ASIC_LED_ACT_OFF(pAdapter) RTMP_IO_WRITE32(pAdapter, LEDCSR, 0x0000461E)
185 //#define ASIC_LED_LINK_UP(pAdapter) RTMP_IO_WRITE32(pAdapter, LEDCSR, 0x00011E46)
186 //#define ASIC_LED_LINK_DOWN(pAdapter) RTMP_IO_WRITE32(pAdapter, LEDCSR, 0x00001E46)
188 #define CAP_IS_ESS_ON(x) (((x) & 0x0001) != 0)
189 #define CAP_IS_IBSS_ON(x) (((x) & 0x0002) != 0)
190 #define CAP_IS_CF_POLLABLE_ON(x) (((x) & 0x0004) != 0)
191 #define CAP_IS_CF_POLL_REQ_ON(x) (((x) & 0x0008) != 0)
192 #define CAP_IS_PRIVACY_ON(x) (((x) & 0x0010) != 0)
194 // 802.11G capability features
195 #define CAP_IS_SHORT_PREAMBLE_ON(x) (((x) & 0x0020) != 0)
196 #define CAP_IS_PBCC_ON(x) (((x) & 0x0040) != 0)
197 #define CAP_IS_AGILITY_ON(x) (((x) & 0x0080) != 0)
198 #define CAP_IS_EXT_RATE_PBCC_ON(x) (((x) & 0x0100) != 0)
199 //#define CAP_IS_CCK_OFDM_ON(x) (((x) & 0x0200) != 0)
200 #define CAP_IS_QOS(x) (((x) & 0x0200) != 0) // defined in 802.11e d4.3
201 #define CAP_IS_SHORT_SLOT_TIME(x) (((x) & 0x0400) != 0)
202 #define CAP_IS_APSD(x) (((x) & 0x0800) != 0) // defined in 802.11e d4.3
203 #define CAP_IS_Q_ACK(x) (((x) & 0x1000) != 0) // defined in 802.11e d4.3
204 #define CAP_IS_DSSS_OFDM(x) (((x) & 0x2000) != 0)
205 #define CAP_IS_BLOCK_ACK(x) (((x) & 0x4000) != 0) // defined in 802.11e d4.3
207 #define CAP_GENERATE(ess,ibss,cfp,cfpreq,priv,prea) ((ess) ? 0x0001 : 0x0000) | ((ibss) ? 0x0002 : 0x0000) | ((cfp) ? 0x0004 : 0x0000) | ((cfpreq) ? 0x0008 : 0x0000) | ((priv) ? 0x0010 : 0x0000) | ((prea) ? 0x0020 : 0x0000)
209 #define ERP_IS_NON_ERP_PRESENT(x) (((x) & 0x01) != 0) // define in 802.11g
210 #define ERP_IS_USE_PROTECTION(x) (((x) & 0x02) != 0) // define in 802.11g
211 #define ERP_IS_USE_BARKER_PREAMBLE(x) (((x) & 0x04) != 0) // define in 802.11g
213 #define TX_FER_TOO_HIGH(TxFER) ((TxFER) > 15) // consider rate down if FER>15%
214 #define TX_FER_VERY_LOW(TxFER) ((TxFER) < 7) // consider rate up if FER<7%
215 #define FAIR_FER 10 // any value between TOO_HIGH and VERY_LOW
216 #define DRS_TX_QUALITY_WORST_BOUND 3
217 #define DRS_PENALTY 8
219 // Ralink timer control block
220 typedef struct _RALINK_TIMER_STRUCT
{
221 struct timer_list TimerObj
; // Ndis Timer object
222 ULONG TimerValue
; // Timer value in milliseconds
223 BOOLEAN State
; // True if timer cancelled
224 BOOLEAN Repeat
; // True if periodic timer
225 } RALINK_TIMER_STRUCT
, *PRALINK_TIMER_STRUCT
;
227 // Mac Address data structure
228 typedef struct PACKED _MACADDR
{
229 UCHAR Octet
[MAC_ADDR_LEN
];
230 } MACADDR
, *PMACADDR
;
233 typedef struct PACKED _MACHDR
{
234 // 2-byte Frame Control. NOTE: bit field assigned from LSB first
275 typedef struct PACKED _MACFRAME
{
278 } MACFRAME
, *PMACFRAME
;
280 typedef struct PACKED _PSPOLL_FRAME
{
299 // Contention-free parameter (without ID and Length)
301 typedef struct PACKED _CF_PARM
{
304 USHORT CfpMaxDuration
;
305 USHORT CfpDurRemaining
;
306 } CF_PARM
, *PCF_PARM
;
309 typedef struct PACKED _BSS_ENTRY
{
316 UCHAR Rates
[MAX_LEN_OF_SUPPORTED_RATES
];
318 BOOLEAN ExtendedRateIeExist
; // records if this AP use EXTENDED_SUPPORTED_RATES IE
320 UCHAR Privacy
; // Indicate security function ON/OFF. Don't mess up with auth mode.
324 USHORT CapabilityInfo
;
328 USHORT CfpMaxDuration
;
329 USHORT CfpDurRemaining
;
331 CHAR Ssid
[MAX_LEN_OF_SSID
];
333 ULONG LastBeaconRxTime
; // OS's timestamp
335 // New for microsoft WPA support
336 NDIS_802_11_FIXED_IEs FixIEs
;
337 NDIS_802_11_WEP_STATUS WepStatus
;
338 UCHAR VarIELen
; // Length of next VIE include EID & Length
339 UCHAR VarIEs
[MAX_VIE_LEN
];
340 } BSS_ENTRY
, *PBSS_ENTRY
;
344 BSS_ENTRY BssEntry
[MAX_LEN_OF_BSS_TABLE
];
345 } BSS_TABLE
, *PBSS_TABLE
;
347 typedef struct PACKED _MLME_QUEUE_ELEM
{
351 LARGE_INTEGER TimeStamp
;
352 UCHAR Msg
[MAX_LEN_OF_MLME_BUFFER
];
356 } MLME_QUEUE_ELEM
, *PMLME_QUEUE_ELEM
;
358 typedef struct PACKED _MLME_QUEUE
{
363 MLME_QUEUE_ELEM Entry
[MAX_LEN_OF_MLME_QUEUE
];
364 } MLME_QUEUE
, *PMLME_QUEUE
;
366 typedef VOID (*STATE_MACHINE_FUNC
)(VOID
*Adaptor
, MLME_QUEUE_ELEM
*Elem
);
368 typedef struct PACKED _STATE_MACHINE
{
373 STATE_MACHINE_FUNC
*TransFunc
;
374 } STATE_MACHINE
, *PSTATE_MACHINE
;
376 // CNTL State Machine Aux data structure
377 typedef struct _CNTL_AUX
{
378 UCHAR Ssid
[MAX_LEN_OF_SSID
];
381 BSS_TABLE SsidBssTab
; // AP list for the same SSID
382 BSS_TABLE RoamTab
; // AP list eligible for roaming
385 BOOLEAN CurrReqIsFromNdis
; // TRUE - then we should call NdisMSetInformationComplete()
386 // FALSE - req is from driver itself.
387 // no NdisMSetInformationComplete() is required
388 } CNTL_AUX
, *PCNTL_AUX
;
390 // ASSOC State Machine Aux data structure
391 typedef struct _ASSOC_AUX
{
393 USHORT CapabilityInfo
;
395 CHAR Ssid
[MAX_LEN_OF_SSID
];
397 RALINK_TIMER_STRUCT AssocTimer
, ReassocTimer
, DisassocTimer
;
398 } ASSOC_AUX
, *PASSOC_AUX
;
400 // AUTH State Machine Aux data structure
401 typedef struct _AUTH_AUX
{
404 RALINK_TIMER_STRUCT AuthTimer
;
405 } AUTH_AUX
, *PAUTH_AUX
;
407 // AUTH-RSP State Machine Aux data structure
408 typedef struct PACKED _AUTH_RSP_AUX
{
411 CHAR Challenge
[CIPHER_TEXT_LEN
];
412 RALINK_TIMER_STRUCT AuthRspTimer
;
413 } AUTH_RSP_AUX
, *PAUTH_RSP_AUX
;
415 // SYNC State Machine Aux data structure
416 typedef struct _SYNC_AUX
{
421 CHAR Ssid
[MAX_LEN_OF_SSID
];
424 RALINK_TIMER_STRUCT BeaconTimer
, ScanTimer
;
427 // assoc struct is equal to reassoc
428 typedef struct PACKED _MLME_ASSOC_REQ_STRUCT
{
430 USHORT CapabilityInfo
;
433 } MLME_ASSOC_REQ_STRUCT
, *PMLME_ASSOC_REQ_STRUCT
, MLME_REASSOC_REQ_STRUCT
, *PMLME_REASSOC_REQ_STRUCT
;
435 typedef struct PACKED _MLME_DISASSOC_REQ_STRUCT
{
438 } MLME_DISASSOC_REQ_STRUCT
, *PMLME_DISASSOC_REQ_STRUCT
;
440 typedef struct PACKED _MLME_AUTH_REQ_STRUCT
{
444 } MLME_AUTH_REQ_STRUCT
, *PMLME_AUTH_REQ_STRUCT
;
446 typedef struct PACKED _MLME_DEAUTH_REQ_STRUCT
{
449 } MLME_DEAUTH_REQ_STRUCT
, *PMLME_DEAUTH_REQ_STRUCT
;
451 //typedef struct _MLME_AUTH_IND_STRUCT {
454 //} MLME_AUTH_IND_STRUCT, *PMLME_AUTH_IND_STRUCT;
456 //typedef struct _CLS2ERR_STRUCT {
458 //} CLS2ERR_STRUCT, *PCLS2ERR_STRUCT;
460 typedef struct PACKED _MLME_JOIN_REQ_STRUCT
{
462 } MLME_JOIN_REQ_STRUCT
;
464 typedef struct PACKED _MLME_SCAN_REQ_STRUCT
{
469 CHAR Ssid
[MAX_LEN_OF_SSID
];
470 } MLME_SCAN_REQ_STRUCT
, *PMLME_SCAN_REQ_STRUCT
;
472 typedef struct PACKED _MLME_START_REQ_STRUCT
{
473 CHAR Ssid
[MAX_LEN_OF_SSID
];
475 } MLME_START_REQ_STRUCT
, *PMLME_START_REQ_STRUCT
;
477 typedef struct PACKED _ARC4_CONTEXT
{
478 UCHAR x
, y
, State
[256], Key
[16]; // 128 bits key
479 } ARC4_CONTEXT
, *PARC4_CONTEXT
;
481 typedef struct PACKED _BEACON_EID_STRUCT
{
485 } BEACON_EID_STRUCT
,*PBEACON_EID_STRUCT
;
487 // New for WPA cipher suite
488 typedef struct PACKED _RSN_EID_STRUCT
{
498 } RSN_EID_STRUCT
, *PRSN_EID_STRUCT
;
500 extern UCHAR RateIdToMbps
[];
501 extern USHORT RateIdTo500Kbps
[];