MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / drivers / net / wireless / rtlink.org / mlme.h
blob9a283361f34c281a30a86d99e03ef72f7e558a7a
1 /*
2 ***************************************************************************
3 * Ralink Tech Inc.
4 * 4F, No. 2 Technology 5th Rd.
5 * Science-based Industrial Park
6 * Hsin-chu, Taiwan, R.O.C.
8 * (c) Copyright 2002, Ralink Technology, Inc.
10 * All rights reserved. Ralink's source code is an unpublished work and the
11 * use of a copyright notice does not imply otherwise. This source code
12 * contains confidential trade secret material of Ralink Tech. Any attemp
13 * or participation in deciphering, decoding, reverse engineering or in any
14 * way altering the source code is stricitly prohibited, unless the prior
15 * written consent of Ralink Technology, Inc. is obtained.
16 ***************************************************************************
18 Module Name:
19 mlme.h
21 Abstract:
23 Revision History:
24 Who When What
25 -------- ---------- ----------------------------------------------
26 John 2003-08-28
28 #ifndef __MLME_H__
29 #define __MLME_H__
31 #include "oid.h"
33 // maximum supported capability information -
34 // ESS, IBSS, Privacy, Short Preamble, Short Slot
35 #define SUPPORTED_CAPABILITY_INFO 0x0433
37 #define END_OF_ARGS -1
38 #define LFSR_MASK 0x80000057
39 #define TBTT_PRELOAD_TIME 384 // usec. LomgPreamble + 24-byte at 1Mbps
40 #define MLME_TASK_EXEC_INTV 1000 // 1 sec
42 #define BEACON_LOST_TIME (4*HZ) // 2048 msec = 2 sec
44 //#define AUTH_KEY_TIMEOUT 500 // unit: msec
45 //#define AUTH_OPEN_TIMEOUT 200 // unit: msec
46 #define AUTH_TIMEOUT 300 // unit: msec
47 #define ASSOC_TIMEOUT 300 // unit: msec
48 #define JOIN_TIMEOUT 2000 // unit: msec
49 #define MIN_CHANNEL_TIME 110 // unit: msec, for dual band scan
50 #define MAX_CHANNEL_TIME 140 // unit: msec, for single band scan
51 #define ACTIVE_SCAN_TIME 30 // Active scan waiting for probe response time
52 #define CW_MIN_IN_BITS 3 // actual CwMin = 2^CW_MIN_IN_BITS - 1 = 7
53 #define CW_MAX_IN_BITS 8 // actual CwMax = 2^CW_MAX_IN_BITS - 1 = 255
55 #define RSSI_TO_DBM_OFFSET 120 // for RT2530 RSSI-115 = dBm
56 #define RSSI_FOR_MID_TX_POWER 55 // -55 db is considered mid-distance
57 #define RSSI_FOR_LOW_TX_POWER 45 // -45 db is considered very short distance and
58 // eligible to use a lower TX power
59 #define RSSI_FOR_LOWEST_TX_POWER 30
60 #define MID_TX_POWER_DELTA 0 // -3 db from full TX power upon mid-distance to AP
61 #define LOW_TX_POWER_DELTA 3 // -8 db from full TX power upon very short distance
62 #define LOWEST_TX_POWER_DELTA 6 // -12 db from full TX power upon shortest distance
64 #define RSSI_TRIGGERED_UPON_BELOW_THRESHOLD 0
65 #define RSSI_TRIGGERED_UPON_EXCCEED_THRESHOLD 1
66 #define RSSI_THRESHOLD_FOR_ROAMING 25
67 #define RSSI_DELTA 5
69 // Channel Quality Indication
70 //#define CQI_GOOD_THRESHOLD 70 // >= this threshold means channel quality GOOD
71 //#define CQI_FAIR_THRESHOLD 50 // >= this threshold means channel quality FAIR
72 //#define CQI_POOR_THRESHOLD 30 // >= this threshold means channel quality POOR
73 // < this threshold means channel quality really BAD, link down
74 #define CQI_IS_GOOD(cqi) ((cqi) >= 50)
75 #define CQI_IS_FAIR(cqi) (((cqi) >= 20) && ((cqi) < 50)) // (((cqi) >= 50) && ((cqi) < 70))
76 #define CQI_IS_POOR(cqi) (((cqi) >= 5) && ((cqi) < 20)) // (((cqi) >= 25) && ((cqi) < 50))
77 #define CQI_IS_BAD(cqi) ((cqi) < 5) // ((cqi) < 25)
79 // weighting factor to calculate Channel quality, total should be 100%
80 #define RSSI_WEIGHTING 40
81 #define TX_WEIGHTING 40
82 #define RX_WEIGHTING 20
84 // prime number closest to 256
85 //#define HASH_TABLE_SIZE 191 //191 is another prime
86 // Only allows 32 entries in the table
87 #define MAC_TABLE_MAX_CAPACITY 32
89 #define MAC_ENTRY_NOT_USED 0xff
90 #define CONTENT_NOT_AVAIL 0xaa
92 // 10 minute of age out
93 #define MAC_TABLE_AGE_OUT_TIME 0xffffff
95 #define MAC_ADDR_HASH_ERROR 0xfffffffe
96 #define MAC_TABLE_UNKNOWN_INDEX 0xff
97 #define MAC_TABLE_ADDR_NOT_IN 0xfffffffd
99 #define PEER_KEY_NOT_USED 0
100 #define PEER_KEY_64_BIT 64
101 #define PEER_KEY_128_BIT 128
103 #define PEER_KEY_64BIT_LEN 8
104 #define PEER_KEY_128BIT_LEN 16
106 #define MAX_LEN_OF_BSS_TABLE 64
107 #define BSS_NOT_FOUND 0xFFFFFFFF
109 #define MAX_LEN_OF_MLME_QUEUE 10
111 //! assoc state-machine states
112 #define ASSOC_IDLE 0
113 #define ASSOC_WAIT_RSP 1
114 #define REASSOC_WAIT_RSP 2
115 #define DISASSOC_WAIT_RSP 3
116 #define MAX_ASSOC_STATE 4
118 #define ASSOC_FUNC_SIZE 44 // 4-state * 12-event
120 //authentication state machine
121 #define AUTH_REQ_IDLE 0
122 #define AUTH_WAIT_SEQ2 1
123 #define AUTH_WAIT_SEQ4 2
124 #define MAX_AUTH_STATE 3
126 #define AUTH_FUNC_SIZE 15 // 3-state * 5-event
128 #define AUTH_RSP_IDLE 0
129 #define AUTH_RSP_WAIT_CHAL 1
130 #define MAX_AUTH_RSP_STATE 2
132 #define AUTH_RSP_FUNC_SIZE 6 // 2-state * 3-event
134 // SYNC state machine
135 #define SYNC_IDLE 0 // merge NO_BSS,IBSS_IDLE,IBSS_ACTIVE and BSS in to 1 state
136 #define JOIN_WAIT_BEACON 1
137 #define SCAN_LISTEN 2
138 #define MAX_SYNC_STATE 3
140 #define SYNC_FUNC_SIZE 30 // 3-state * 10-event
142 #define SCAN_PASSIVE 18
143 #define SCAN_ACTIVE 19
145 //WPA State machine
146 #define WPA_PSK_IDLE 0
147 #define MAX_WPA_PSK_STATE 1
148 #define WPA_PSK_FUNC_SIZE 5
150 // Control state machine
151 #define CNTL_IDLE 100
152 #define CNTL_WAIT_DISASSOC 101
153 #define CNTL_WAIT_JOIN 102
154 #define CNTL_WAIT_REASSOC 103
155 #define CNTL_WAIT_START 104
156 #define CNTL_WAIT_AUTH 105
157 #define CNTL_WAIT_ASSOC 106
158 #define CNTL_WAIT_AUTH2 107
159 #define CNTL_WAIT_OID_LIST_SCAN 108
160 #define CNTL_WAIT_OID_DISASSOC 109
162 //#define BSS_TABLE_EMPTY(x) ((x).BssNr == 0)
163 #define CapabilityInfoGen(Ess,Ibss,Cfp,CfpReq,Priv) ((Ess) ? 0x0001 : 0x0000) | ((Ibss) ? 0x0002 : 0x0000) | ((Cfp) ? 0x0004 : 0x0000) | ((CfpReq) ? 0x0008 : 0x0000) | ((Priv) ? 0x0010: 0x0000)
165 #define MAC_ADDR_IS_GROUP(Addr) ((((Addr).Octet[0]) & 0x01) != 0)
166 #define MAC_ADDR_HASH(Addr) ((Addr).Octet[0] ^ (Addr).Octet[1] ^ (Addr).Octet[2] ^ (Addr).Octet[3] ^ (Addr).Octet[4] ^ (Addr).Octet[5])
167 #define MAC_ADDR_HASH_INDEX(Addr) (MAC_ADDR_HASH(Addr) % HASH_TABLE_SIZE)
168 #define MAC_ADDR_EQUAL(pAddr1,pAddr2) RTMPEqualMemory((PVOID)(pAddr1), (PVOID)(pAddr2), MAC_ADDR_LEN)
169 #define COPY_MAC_ADDR(Addr1, Addr2) memcpy((Addr1), (Addr2), ETH_LENGTH_OF_ADDRESS)
170 //#define MAKE_BROADCAST_ADDR(Addr) NdisFillMemory(&Addr, MAC_ADDR_LEN, 0xff)
172 // LED Control
173 // assoiation ON. one LED ON. another blinking when TX, OFF when idle
174 #define ASIC_LED_ACT_ON(pAdapter) RTMP_IO_WRITE32(pAdapter, LEDCSR, 0x0003461E)
175 // no association, both LED off
176 #define ASIC_LED_ACT_OFF(pAdapter) RTMP_IO_WRITE32(pAdapter, LEDCSR, 0x0000461E)
177 //#define ASIC_LED_LINK_UP(pAdapter) RTMP_IO_WRITE32(pAdapter, LEDCSR, 0x00011E46)
178 //#define ASIC_LED_LINK_DOWN(pAdapter) RTMP_IO_WRITE32(pAdapter, LEDCSR, 0x00001E46)
180 #define CAP_IS_ESS_ON(x) (((x) & 0x0001) != 0)
181 #define CAP_IS_IBSS_ON(x) (((x) & 0x0002) != 0)
182 #define CAP_IS_CF_POLLABLE_ON(x) (((x) & 0x0004) != 0)
183 #define CAP_IS_CF_POLL_REQ_ON(x) (((x) & 0x0008) != 0)
184 #define CAP_IS_PRIVACY_ON(x) (((x) & 0x0010) != 0)
186 // 802.11G capability features
187 #define CAP_IS_SHORT_PREAMBLE_ON(x) (((x) & 0x0020) != 0)
188 #define CAP_IS_PBCC_ON(x) (((x) & 0x0040) != 0)
189 #define CAP_IS_AGILITY_ON(x) (((x) & 0x0080) != 0)
190 #define CAP_IS_EXT_RATE_PBCC_ON(x) (((x) & 0x0100) != 0)
191 //#define CAP_IS_CCK_OFDM_ON(x) (((x) & 0x0200) != 0)
192 #define CAP_IS_QOS(x) (((x) & 0x0200) != 0) // defined in 802.11e d4.3
193 #define CAP_IS_SHORT_SLOT_TIME(x) (((x) & 0x0400) != 0)
194 #define CAP_IS_APSD(x) (((x) & 0x0800) != 0) // defined in 802.11e d4.3
195 #define CAP_IS_Q_ACK(x) (((x) & 0x1000) != 0) // defined in 802.11e d4.3
196 #define CAP_IS_DSSS_OFDM(x) (((x) & 0x2000) != 0)
197 #define CAP_IS_BLOCK_ACK(x) (((x) & 0x4000) != 0) // defined in 802.11e d4.3
199 #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)
201 #define ERP_IS_NON_ERP_PRESENT(x) (((x) & 0x01) != 0) // define in 802.11g
202 #define ERP_IS_USE_PROTECTION(x) (((x) & 0x02) != 0) // define in 802.11g
203 #define ERP_IS_USE_BARKER_PREAMBLE(x) (((x) & 0x04) != 0) // define in 802.11g
205 #define TX_FER_TOO_HIGH(TxFER) ((TxFER) > 15) // consider rate down if FER>15%
206 #define TX_FER_VERY_LOW(TxFER) ((TxFER) < 7) // consider rate up if FER<7%
207 #define FAIR_FER 10 // any value between TOO_HIGH and VERY_LOW
208 #define DRS_TX_QUALITY_WORST_BOUND 3
209 #define DRS_PENALTY 8
211 // Ralink timer control block
212 typedef struct _RALINK_TIMER_STRUCT {
213 struct timer_list TimerObj; // Ndis Timer object
214 ULONG TimerValue; // Timer value in milliseconds
215 BOOLEAN State; // True if timer cancelled
216 BOOLEAN Repeat; // True if periodic timer
217 } RALINK_TIMER_STRUCT, *PRALINK_TIMER_STRUCT;
219 // Mac Address data structure
220 typedef struct PACKED _MACADDR {
221 UCHAR Octet[MAC_ADDR_LEN];
222 } MACADDR, *PMACADDR;
224 // Mac Frame Header
225 typedef struct PACKED _MACHDR {
226 // 2-byte Frame Control. NOTE: bit field assigned from LSB first
227 #ifdef BIG_ENDIAN
228 USHORT Order:1;
229 USHORT Wep:1;
230 USHORT MoreData:1;
231 USHORT PwrMgmt:1;
232 USHORT Retry:1;
233 USHORT MoreFrag:1;
234 USHORT Frds:1;
235 USHORT Tods:1;
236 USHORT SubType:4;
237 USHORT Type:2;
238 USHORT Ver:2;
239 #else
240 USHORT Ver:2;
241 USHORT Type:2;
242 USHORT SubType:4;
243 USHORT Tods:1;
244 USHORT Frds:1;
245 USHORT MoreFrag:1;
246 USHORT Retry:1;
247 USHORT PwrMgmt:1;
248 USHORT MoreData:1;
249 USHORT Wep:1;
250 USHORT Order:1;
251 #endif
253 USHORT Duration;
254 MACADDR Addr1;
255 MACADDR Addr2;
256 MACADDR Addr3;
258 #ifdef BIG_ENDIAN
259 USHORT Seq:12;
260 USHORT Frag:4;
261 #else
262 USHORT Frag:4;
263 USHORT Seq:12;
264 #endif
265 } MACHDR, *PMACHDR;
267 typedef struct PACKED _MACFRAME {
268 MACHDR Hdr;
269 CHAR Octet[1];
270 } MACFRAME, *PMACFRAME;
272 typedef struct PACKED _PSPOLL_FRAME {
273 USHORT Ver:2;
274 USHORT Type:2;
275 USHORT SubType:4;
276 USHORT Tods:1;
277 USHORT Frds:1;
278 USHORT MoreFrag:1;
279 USHORT Retry:1;
280 USHORT PwrMgmt:1;
281 USHORT MoreData:1;
282 USHORT Wep:1;
283 USHORT Order:1;
285 USHORT Aid;
286 MACADDR Bssid;
287 MACADDR Ta;
288 } PSPOLL_FRAME;
291 // Contention-free parameter (without ID and Length)
293 typedef struct PACKED _CF_PARM {
294 UCHAR CfpCount;
295 UCHAR CfpPeriod;
296 USHORT CfpMaxDuration;
297 USHORT CfpDurRemaining;
298 } CF_PARM, *PCF_PARM;
301 typedef struct PACKED _BSS_ENTRY{
302 MACADDR Bssid;
303 UCHAR Channel;
304 UCHAR BssType;
305 USHORT AtimWin;
306 USHORT BeaconPeriod;
308 UCHAR Rates[MAX_LEN_OF_SUPPORTED_RATES];
309 UCHAR RatesLen;
310 BOOLEAN ExtendedRateIeExist; // records if this AP use EXTENDED_SUPPORTED_RATES IE
311 UCHAR Rssi;
312 UCHAR Privacy; // Indicate security function ON/OFF. Don't mess up with auth mode.
313 UCHAR Hidden;
314 UCHAR Reserved1[3]; // Scott added @2005-01-13 for alignment
315 USHORT DtimPeriod;
316 USHORT CapabilityInfo;
318 USHORT CfpCount;
319 USHORT CfpPeriod;
320 USHORT CfpMaxDuration;
321 USHORT CfpDurRemaining;
322 UCHAR SsidLen;
323 CHAR Ssid[MAX_LEN_OF_SSID];
324 UCHAR Reserved2[3]; // Scott added @2005-01-13 for alignment
325 ULONG LastBeaconRxTime; // OS's timestamp
327 // New for microsoft WPA support
328 NDIS_802_11_FIXED_IEs FixIEs;
329 NDIS_802_11_WEP_STATUS WepStatus;
330 UCHAR VarIELen; // Length of next VIE include EID & Length
331 UCHAR Reserved3[3]; // Scott added @2005-01-13 for alignment
332 UCHAR VarIEs[MAX_VIE_LEN];
333 } BSS_ENTRY, *PBSS_ENTRY;
335 typedef struct {
336 UCHAR BssNr;
337 UCHAR Reserved[3]; // Scott added @2005-01-13 for alignment
338 BSS_ENTRY BssEntry[MAX_LEN_OF_BSS_TABLE];
339 } BSS_TABLE, *PBSS_TABLE;
341 typedef struct PACKED _MLME_QUEUE_ELEM {
342 ULONG Machine;
343 ULONG MsgType;
344 ULONG MsgLen;
345 LARGE_INTEGER TimeStamp;
346 UCHAR Msg[MAX_LEN_OF_MLME_BUFFER];
347 UCHAR Rssi;
348 UCHAR Channel;
349 BOOLEAN Occupied;
350 UCHAR Reserved; // Scott added @2005-01-13 for alignment
351 } MLME_QUEUE_ELEM, *PMLME_QUEUE_ELEM;
353 typedef struct PACKED _MLME_QUEUE {
354 ULONG Num;
355 ULONG Head;
356 ULONG Tail;
357 spinlock_t Lock;
358 MLME_QUEUE_ELEM Entry[MAX_LEN_OF_MLME_QUEUE];
359 } MLME_QUEUE, *PMLME_QUEUE;
361 typedef VOID (*STATE_MACHINE_FUNC)(VOID *Adaptor, MLME_QUEUE_ELEM *Elem);
363 typedef struct PACKED _STATE_MACHINE {
364 ULONG Base;
365 ULONG NrState;
366 ULONG NrMsg;
367 ULONG CurrState;
368 STATE_MACHINE_FUNC *TransFunc;
369 } STATE_MACHINE, *PSTATE_MACHINE;
371 // CNTL State Machine Aux data structure
372 typedef struct _CNTL_AUX {
373 UCHAR Ssid[MAX_LEN_OF_SSID];
374 UCHAR SsidLen;
375 MACADDR Bssid;
376 BSS_TABLE SsidBssTab; // AP list for the same SSID
377 BSS_TABLE RoamTab; // AP list eligible for roaming
378 ULONG BssIdx;
379 ULONG RoamIdx;
380 BOOLEAN CurrReqIsFromNdis; // TRUE - then we should call NdisMSetInformationComplete()
381 // FALSE - req is from driver itself.
382 // no NdisMSetInformationComplete() is required
383 } CNTL_AUX, *PCNTL_AUX;
385 // ASSOC State Machine Aux data structure
386 typedef struct _ASSOC_AUX {
387 MACADDR Addr;
388 USHORT CapabilityInfo;
389 USHORT ListenIntv;
390 CHAR Ssid[MAX_LEN_OF_SSID];
391 UCHAR SsidLen;
392 RALINK_TIMER_STRUCT AssocTimer, ReassocTimer, DisassocTimer;
393 } ASSOC_AUX, *PASSOC_AUX;
395 // AUTH State Machine Aux data structure
396 typedef struct _AUTH_AUX {
397 MACADDR Addr;
398 USHORT Alg;
399 RALINK_TIMER_STRUCT AuthTimer;
400 } AUTH_AUX, *PAUTH_AUX;
402 // AUTH-RSP State Machine Aux data structure
403 typedef struct PACKED _AUTH_RSP_AUX {
404 MACADDR Addr;
405 USHORT Alg;
406 CHAR Challenge[CIPHER_TEXT_LEN];
407 RALINK_TIMER_STRUCT AuthRspTimer;
408 } AUTH_RSP_AUX, *PAUTH_RSP_AUX;
410 // SYNC State Machine Aux data structure
411 typedef struct _SYNC_AUX {
412 MACADDR Addr;
413 MACADDR Bssid;
414 UCHAR BssType;
415 UCHAR SsidLen;
416 CHAR Ssid[MAX_LEN_OF_SSID];
417 UCHAR ScanType;
418 UCHAR Channel;
419 RALINK_TIMER_STRUCT BeaconTimer, ScanTimer;
420 } SYNC_AUX;
422 // assoc struct is equal to reassoc
423 typedef struct PACKED _MLME_ASSOC_REQ_STRUCT{
424 MACADDR Addr;
425 USHORT CapabilityInfo;
426 USHORT ListenIntv;
427 ULONG Timeout;
428 } MLME_ASSOC_REQ_STRUCT, *PMLME_ASSOC_REQ_STRUCT, MLME_REASSOC_REQ_STRUCT, *PMLME_REASSOC_REQ_STRUCT;
430 typedef struct PACKED _MLME_DISASSOC_REQ_STRUCT{
431 MACADDR Addr;
432 USHORT Reason;
433 } MLME_DISASSOC_REQ_STRUCT, *PMLME_DISASSOC_REQ_STRUCT;
435 typedef struct PACKED _MLME_AUTH_REQ_STRUCT {
436 MACADDR Addr;
437 USHORT Alg;
438 ULONG Timeout;
439 } MLME_AUTH_REQ_STRUCT, *PMLME_AUTH_REQ_STRUCT;
441 typedef struct PACKED _MLME_DEAUTH_REQ_STRUCT {
442 MACADDR Addr;
443 USHORT Reason;
444 } MLME_DEAUTH_REQ_STRUCT, *PMLME_DEAUTH_REQ_STRUCT;
446 //typedef struct _MLME_AUTH_IND_STRUCT {
447 // MACADDR Addr;
448 // USHORT Alg;
449 //} MLME_AUTH_IND_STRUCT, *PMLME_AUTH_IND_STRUCT;
451 //typedef struct _CLS2ERR_STRUCT {
452 // MACADDR Addr;
453 //} CLS2ERR_STRUCT, *PCLS2ERR_STRUCT;
455 typedef struct PACKED _MLME_JOIN_REQ_STRUCT{
456 ULONG BssIdx;
457 } MLME_JOIN_REQ_STRUCT;
459 typedef struct PACKED _MLME_SCAN_REQ_STRUCT {
460 MACADDR Bssid;
461 UCHAR BssType;
462 UCHAR ScanType;
463 UCHAR SsidLen;
464 CHAR Ssid[MAX_LEN_OF_SSID];
465 } MLME_SCAN_REQ_STRUCT, *PMLME_SCAN_REQ_STRUCT;
467 typedef struct PACKED _MLME_START_REQ_STRUCT {
468 CHAR Ssid[MAX_LEN_OF_SSID];
469 UCHAR SsidLen;
470 } MLME_START_REQ_STRUCT, *PMLME_START_REQ_STRUCT;
472 typedef struct PACKED _ARC4_CONTEXT {
473 UCHAR x, y, State[256], Key[16]; // 128 bits key
474 } ARC4_CONTEXT, *PARC4_CONTEXT;
476 typedef struct PACKED _BEACON_EID_STRUCT {
477 UCHAR Eid;
478 UCHAR Len;
479 CHAR Octet[1];
480 } BEACON_EID_STRUCT,*PBEACON_EID_STRUCT;
482 // New for WPA cipher suite
483 typedef struct PACKED _RSN_EID_STRUCT {
484 UCHAR Eid;
485 UCHAR Length;
486 UCHAR Oui[4];
487 USHORT Version;
488 UCHAR Multicast[4];
489 USHORT Count;
490 struct {
491 UCHAR Oui[4];
492 } Unicast[1];
493 } RSN_EID_STRUCT, *PRSN_EID_STRUCT;
495 extern UCHAR RateIdToMbps[];
496 extern USHORT RateIdTo500Kbps[];
498 #endif // MLME_H__