4 * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
6 * Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi>
7 * Copyright (c) 2005, Devicescape Software, Inc.
8 * Copyright (c) 2006, Michael Wu <flamingice@sourmilk.net>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
18 #include <linux/types.h>
19 #include <asm/byteorder.h>
23 #define IEEE80211_FCTL_VERS 0x0003
24 #define IEEE80211_FCTL_FTYPE 0x000c
25 #define IEEE80211_FCTL_STYPE 0x00f0
26 #define IEEE80211_FCTL_TODS 0x0100
27 #define IEEE80211_FCTL_FROMDS 0x0200
28 #define IEEE80211_FCTL_MOREFRAGS 0x0400
29 #define IEEE80211_FCTL_RETRY 0x0800
30 #define IEEE80211_FCTL_PM 0x1000
31 #define IEEE80211_FCTL_MOREDATA 0x2000
32 #define IEEE80211_FCTL_PROTECTED 0x4000
33 #define IEEE80211_FCTL_ORDER 0x8000
35 #define IEEE80211_SCTL_FRAG 0x000F
36 #define IEEE80211_SCTL_SEQ 0xFFF0
38 #define IEEE80211_FTYPE_MGMT 0x0000
39 #define IEEE80211_FTYPE_CTL 0x0004
40 #define IEEE80211_FTYPE_DATA 0x0008
43 #define IEEE80211_STYPE_ASSOC_REQ 0x0000
44 #define IEEE80211_STYPE_ASSOC_RESP 0x0010
45 #define IEEE80211_STYPE_REASSOC_REQ 0x0020
46 #define IEEE80211_STYPE_REASSOC_RESP 0x0030
47 #define IEEE80211_STYPE_PROBE_REQ 0x0040
48 #define IEEE80211_STYPE_PROBE_RESP 0x0050
49 #define IEEE80211_STYPE_BEACON 0x0080
50 #define IEEE80211_STYPE_ATIM 0x0090
51 #define IEEE80211_STYPE_DISASSOC 0x00A0
52 #define IEEE80211_STYPE_AUTH 0x00B0
53 #define IEEE80211_STYPE_DEAUTH 0x00C0
54 #define IEEE80211_STYPE_ACTION 0x00D0
57 #define IEEE80211_STYPE_BACK_REQ 0x0080
58 #define IEEE80211_STYPE_BACK 0x0090
59 #define IEEE80211_STYPE_PSPOLL 0x00A0
60 #define IEEE80211_STYPE_RTS 0x00B0
61 #define IEEE80211_STYPE_CTS 0x00C0
62 #define IEEE80211_STYPE_ACK 0x00D0
63 #define IEEE80211_STYPE_CFEND 0x00E0
64 #define IEEE80211_STYPE_CFENDACK 0x00F0
67 #define IEEE80211_STYPE_DATA 0x0000
68 #define IEEE80211_STYPE_DATA_CFACK 0x0010
69 #define IEEE80211_STYPE_DATA_CFPOLL 0x0020
70 #define IEEE80211_STYPE_DATA_CFACKPOLL 0x0030
71 #define IEEE80211_STYPE_NULLFUNC 0x0040
72 #define IEEE80211_STYPE_CFACK 0x0050
73 #define IEEE80211_STYPE_CFPOLL 0x0060
74 #define IEEE80211_STYPE_CFACKPOLL 0x0070
75 #define IEEE80211_STYPE_QOS_DATA 0x0080
76 #define IEEE80211_STYPE_QOS_DATA_CFACK 0x0090
77 #define IEEE80211_STYPE_QOS_DATA_CFPOLL 0x00A0
78 #define IEEE80211_STYPE_QOS_DATA_CFACKPOLL 0x00B0
79 #define IEEE80211_STYPE_QOS_NULLFUNC 0x00C0
80 #define IEEE80211_STYPE_QOS_CFACK 0x00D0
81 #define IEEE80211_STYPE_QOS_CFPOLL 0x00E0
82 #define IEEE80211_STYPE_QOS_CFACKPOLL 0x00F0
85 /* miscellaneous IEEE 802.11 constants */
86 #define IEEE80211_MAX_FRAG_THRESHOLD 2352
87 #define IEEE80211_MAX_RTS_THRESHOLD 2353
88 #define IEEE80211_MAX_AID 2007
89 #define IEEE80211_MAX_TIM_LEN 251
90 /* Maximum size for the MA-UNITDATA primitive, 802.11 standard section
93 802.11e clarifies the figure in section 7.1.2. The frame body is
94 up to 2304 octets long (maximum MSDU size) plus any crypt overhead. */
95 #define IEEE80211_MAX_DATA_LEN 2304
96 /* 30 byte 4 addr hdr, 2 byte QoS, 2304 byte MSDU, 12 byte crypt, 4 byte FCS */
97 #define IEEE80211_MAX_FRAME_LEN 2352
99 #define IEEE80211_MAX_SSID_LEN 32
100 #define IEEE80211_MAX_MESH_ID_LEN 32
102 struct ieee80211_hdr
{
103 __le16 frame_control
;
110 } __attribute__ ((packed
));
113 struct ieee80211s_hdr
{
120 } __attribute__ ((packed
));
123 struct ieee80211_mgmt
{
124 __le16 frame_control
;
133 __le16 auth_transaction
;
135 /* possibly followed by Challenge text */
137 } __attribute__ ((packed
)) auth
;
140 } __attribute__ ((packed
)) deauth
;
143 __le16 listen_interval
;
144 /* followed by SSID and Supported rates */
146 } __attribute__ ((packed
)) assoc_req
;
151 /* followed by Supported rates */
153 } __attribute__ ((packed
)) assoc_resp
, reassoc_resp
;
156 __le16 listen_interval
;
158 /* followed by SSID and Supported rates */
160 } __attribute__ ((packed
)) reassoc_req
;
163 } __attribute__ ((packed
)) disassoc
;
168 /* followed by some of SSID, Supported rates,
169 * FH Params, DS Params, CF Params, IBSS Params, TIM */
171 } __attribute__ ((packed
)) beacon
;
173 /* only variable items: SSID, Supported rates */
175 } __attribute__ ((packed
)) probe_req
;
180 /* followed by some of SSID, Supported rates,
181 * FH Params, DS Params, CF Params, IBSS Params */
183 } __attribute__ ((packed
)) probe_resp
;
192 } __attribute__ ((packed
)) wme_action
;
200 } __attribute__((packed
)) chan_switch
;
206 __le16 start_seq_num
;
207 } __attribute__((packed
)) addba_req
;
214 } __attribute__((packed
)) addba_resp
;
219 } __attribute__((packed
)) delba
;
222 /* capab_info for open and confirm,
226 /* Followed in plink_confirm by status
227 * code, AID and supported rates,
228 * and directly by supported rates in
229 * plink_open and plink_close
232 } __attribute__((packed
)) plink_action
;
236 } __attribute__((packed
)) mesh_action
;
238 } __attribute__ ((packed
)) action
;
240 } __attribute__ ((packed
));
244 struct ieee80211_rts
{
245 __le16 frame_control
;
249 } __attribute__ ((packed
));
251 struct ieee80211_cts
{
252 __le16 frame_control
;
255 } __attribute__ ((packed
));
258 * struct ieee80211_bar - HT Block Ack Request
260 * This structure refers to "HT BlockAckReq" as
261 * described in 802.11n draft section 7.2.1.7.1
263 struct ieee80211_bar
{
264 __le16 frame_control
;
269 __le16 start_seq_num
;
270 } __attribute__((packed
));
273 * struct ieee80211_ht_cap - HT capabilities
275 * This structure refers to "HT capabilities element" as
276 * described in 802.11n draft section 7.3.2.52
278 struct ieee80211_ht_cap
{
280 u8 ampdu_params_info
;
282 __le16 extended_ht_cap_info
;
283 __le32 tx_BF_cap_info
;
284 u8 antenna_selection_info
;
285 } __attribute__ ((packed
));
288 * struct ieee80211_ht_cap - HT additional information
290 * This structure refers to "HT information element" as
291 * described in 802.11n draft section 7.3.2.53
293 struct ieee80211_ht_addt_info
{
296 __le16 operation_mode
;
299 } __attribute__ ((packed
));
301 /* 802.11n HT capabilities masks */
302 #define IEEE80211_HT_CAP_SUP_WIDTH 0x0002
303 #define IEEE80211_HT_CAP_MIMO_PS 0x000C
304 #define IEEE80211_HT_CAP_GRN_FLD 0x0010
305 #define IEEE80211_HT_CAP_SGI_20 0x0020
306 #define IEEE80211_HT_CAP_SGI_40 0x0040
307 #define IEEE80211_HT_CAP_DELAY_BA 0x0400
308 #define IEEE80211_HT_CAP_MAX_AMSDU 0x0800
309 /* 802.11n HT capability AMPDU settings */
310 #define IEEE80211_HT_CAP_AMPDU_FACTOR 0x03
311 #define IEEE80211_HT_CAP_AMPDU_DENSITY 0x1C
312 /* 802.11n HT capability MSC set */
313 #define IEEE80211_SUPP_MCS_SET_UEQM 4
314 #define IEEE80211_HT_CAP_MAX_STREAMS 4
315 #define IEEE80211_SUPP_MCS_SET_LEN 10
316 /* maximum streams the spec allows */
317 #define IEEE80211_HT_CAP_MCS_TX_DEFINED 0x01
318 #define IEEE80211_HT_CAP_MCS_TX_RX_DIFF 0x02
319 #define IEEE80211_HT_CAP_MCS_TX_STREAMS 0x0C
320 #define IEEE80211_HT_CAP_MCS_TX_UEQM 0x10
321 /* 802.11n HT IE masks */
322 #define IEEE80211_HT_IE_CHA_SEC_OFFSET 0x03
323 #define IEEE80211_HT_IE_CHA_SEC_ABOVE 0x01
324 #define IEEE80211_HT_IE_CHA_SEC_BELOW 0x03
325 #define IEEE80211_HT_IE_CHA_WIDTH 0x04
326 #define IEEE80211_HT_IE_HT_PROTECTION 0x0003
327 #define IEEE80211_HT_IE_NON_GF_STA_PRSNT 0x0004
328 #define IEEE80211_HT_IE_NON_HT_STA_PRSNT 0x0010
330 /* MIMO Power Save Modes */
331 #define WLAN_HT_CAP_MIMO_PS_STATIC 0
332 #define WLAN_HT_CAP_MIMO_PS_DYNAMIC 1
333 #define WLAN_HT_CAP_MIMO_PS_INVALID 2
334 #define WLAN_HT_CAP_MIMO_PS_DISABLED 3
336 /* Authentication algorithms */
337 #define WLAN_AUTH_OPEN 0
338 #define WLAN_AUTH_SHARED_KEY 1
339 #define WLAN_AUTH_FAST_BSS_TRANSITION 2
340 #define WLAN_AUTH_LEAP 128
342 #define WLAN_AUTH_CHALLENGE_LEN 128
344 #define WLAN_CAPABILITY_ESS (1<<0)
345 #define WLAN_CAPABILITY_IBSS (1<<1)
346 #define WLAN_CAPABILITY_CF_POLLABLE (1<<2)
347 #define WLAN_CAPABILITY_CF_POLL_REQUEST (1<<3)
348 #define WLAN_CAPABILITY_PRIVACY (1<<4)
349 #define WLAN_CAPABILITY_SHORT_PREAMBLE (1<<5)
350 #define WLAN_CAPABILITY_PBCC (1<<6)
351 #define WLAN_CAPABILITY_CHANNEL_AGILITY (1<<7)
353 #define WLAN_CAPABILITY_SPECTRUM_MGMT (1<<8)
354 #define WLAN_CAPABILITY_QOS (1<<9)
355 #define WLAN_CAPABILITY_SHORT_SLOT_TIME (1<<10)
356 #define WLAN_CAPABILITY_DSSS_OFDM (1<<13)
358 /* 802.11g ERP information element */
359 #define WLAN_ERP_NON_ERP_PRESENT (1<<0)
360 #define WLAN_ERP_USE_PROTECTION (1<<1)
361 #define WLAN_ERP_BARKER_PREAMBLE (1<<2)
363 /* WLAN_ERP_BARKER_PREAMBLE values */
365 WLAN_ERP_PREAMBLE_SHORT
= 0,
366 WLAN_ERP_PREAMBLE_LONG
= 1,
370 enum ieee80211_statuscode
{
371 WLAN_STATUS_SUCCESS
= 0,
372 WLAN_STATUS_UNSPECIFIED_FAILURE
= 1,
373 WLAN_STATUS_CAPS_UNSUPPORTED
= 10,
374 WLAN_STATUS_REASSOC_NO_ASSOC
= 11,
375 WLAN_STATUS_ASSOC_DENIED_UNSPEC
= 12,
376 WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
= 13,
377 WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION
= 14,
378 WLAN_STATUS_CHALLENGE_FAIL
= 15,
379 WLAN_STATUS_AUTH_TIMEOUT
= 16,
380 WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
= 17,
381 WLAN_STATUS_ASSOC_DENIED_RATES
= 18,
383 WLAN_STATUS_ASSOC_DENIED_NOSHORTPREAMBLE
= 19,
384 WLAN_STATUS_ASSOC_DENIED_NOPBCC
= 20,
385 WLAN_STATUS_ASSOC_DENIED_NOAGILITY
= 21,
387 WLAN_STATUS_ASSOC_DENIED_NOSPECTRUM
= 22,
388 WLAN_STATUS_ASSOC_REJECTED_BAD_POWER
= 23,
389 WLAN_STATUS_ASSOC_REJECTED_BAD_SUPP_CHAN
= 24,
391 WLAN_STATUS_ASSOC_DENIED_NOSHORTTIME
= 25,
392 WLAN_STATUS_ASSOC_DENIED_NODSSSOFDM
= 26,
394 WLAN_STATUS_INVALID_IE
= 40,
395 WLAN_STATUS_INVALID_GROUP_CIPHER
= 41,
396 WLAN_STATUS_INVALID_PAIRWISE_CIPHER
= 42,
397 WLAN_STATUS_INVALID_AKMP
= 43,
398 WLAN_STATUS_UNSUPP_RSN_VERSION
= 44,
399 WLAN_STATUS_INVALID_RSN_IE_CAP
= 45,
400 WLAN_STATUS_CIPHER_SUITE_REJECTED
= 46,
402 WLAN_STATUS_UNSPECIFIED_QOS
= 32,
403 WLAN_STATUS_ASSOC_DENIED_NOBANDWIDTH
= 33,
404 WLAN_STATUS_ASSOC_DENIED_LOWACK
= 34,
405 WLAN_STATUS_ASSOC_DENIED_UNSUPP_QOS
= 35,
406 WLAN_STATUS_REQUEST_DECLINED
= 37,
407 WLAN_STATUS_INVALID_QOS_PARAM
= 38,
408 WLAN_STATUS_CHANGE_TSPEC
= 39,
409 WLAN_STATUS_WAIT_TS_DELAY
= 47,
410 WLAN_STATUS_NO_DIRECT_LINK
= 48,
411 WLAN_STATUS_STA_NOT_PRESENT
= 49,
412 WLAN_STATUS_STA_NOT_QSTA
= 50,
417 enum ieee80211_reasoncode
{
418 WLAN_REASON_UNSPECIFIED
= 1,
419 WLAN_REASON_PREV_AUTH_NOT_VALID
= 2,
420 WLAN_REASON_DEAUTH_LEAVING
= 3,
421 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
= 4,
422 WLAN_REASON_DISASSOC_AP_BUSY
= 5,
423 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA
= 6,
424 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA
= 7,
425 WLAN_REASON_DISASSOC_STA_HAS_LEFT
= 8,
426 WLAN_REASON_STA_REQ_ASSOC_WITHOUT_AUTH
= 9,
428 WLAN_REASON_DISASSOC_BAD_POWER
= 10,
429 WLAN_REASON_DISASSOC_BAD_SUPP_CHAN
= 11,
431 WLAN_REASON_INVALID_IE
= 13,
432 WLAN_REASON_MIC_FAILURE
= 14,
433 WLAN_REASON_4WAY_HANDSHAKE_TIMEOUT
= 15,
434 WLAN_REASON_GROUP_KEY_HANDSHAKE_TIMEOUT
= 16,
435 WLAN_REASON_IE_DIFFERENT
= 17,
436 WLAN_REASON_INVALID_GROUP_CIPHER
= 18,
437 WLAN_REASON_INVALID_PAIRWISE_CIPHER
= 19,
438 WLAN_REASON_INVALID_AKMP
= 20,
439 WLAN_REASON_UNSUPP_RSN_VERSION
= 21,
440 WLAN_REASON_INVALID_RSN_IE_CAP
= 22,
441 WLAN_REASON_IEEE8021X_FAILED
= 23,
442 WLAN_REASON_CIPHER_SUITE_REJECTED
= 24,
444 WLAN_REASON_DISASSOC_UNSPECIFIED_QOS
= 32,
445 WLAN_REASON_DISASSOC_QAP_NO_BANDWIDTH
= 33,
446 WLAN_REASON_DISASSOC_LOW_ACK
= 34,
447 WLAN_REASON_DISASSOC_QAP_EXCEED_TXOP
= 35,
448 WLAN_REASON_QSTA_LEAVE_QBSS
= 36,
449 WLAN_REASON_QSTA_NOT_USE
= 37,
450 WLAN_REASON_QSTA_REQUIRE_SETUP
= 38,
451 WLAN_REASON_QSTA_TIMEOUT
= 39,
452 WLAN_REASON_QSTA_CIPHER_NOT_SUPP
= 45,
456 /* Information Element IDs */
459 WLAN_EID_SUPP_RATES
= 1,
460 WLAN_EID_FH_PARAMS
= 2,
461 WLAN_EID_DS_PARAMS
= 3,
462 WLAN_EID_CF_PARAMS
= 4,
464 WLAN_EID_IBSS_PARAMS
= 6,
465 WLAN_EID_CHALLENGE
= 16,
467 WLAN_EID_COUNTRY
= 7,
468 WLAN_EID_HP_PARAMS
= 8,
469 WLAN_EID_HP_TABLE
= 9,
470 WLAN_EID_REQUEST
= 10,
472 WLAN_EID_QBSS_LOAD
= 11,
473 WLAN_EID_EDCA_PARAM_SET
= 12,
476 WLAN_EID_SCHEDULE
= 15,
477 WLAN_EID_TS_DELAY
= 43,
478 WLAN_EID_TCLAS_PROCESSING
= 44,
479 WLAN_EID_QOS_CAPA
= 46,
482 * All mesh EID numbers are pending IEEE 802.11 ANA approval.
483 * The numbers have been incremented from those suggested in
484 * 802.11s/D2.0 so that MESH_CONFIG does not conflict with
487 WLAN_EID_MESH_CONFIG
= 51,
488 WLAN_EID_MESH_ID
= 52,
489 WLAN_EID_PEER_LINK
= 55,
494 WLAN_EID_PWR_CONSTRAINT
= 32,
495 WLAN_EID_PWR_CAPABILITY
= 33,
496 WLAN_EID_TPC_REQUEST
= 34,
497 WLAN_EID_TPC_REPORT
= 35,
498 WLAN_EID_SUPPORTED_CHANNELS
= 36,
499 WLAN_EID_CHANNEL_SWITCH
= 37,
500 WLAN_EID_MEASURE_REQUEST
= 38,
501 WLAN_EID_MEASURE_REPORT
= 39,
503 WLAN_EID_IBSS_DFS
= 41,
505 WLAN_EID_ERP_INFO
= 42,
506 WLAN_EID_EXT_SUPP_RATES
= 50,
508 WLAN_EID_HT_CAPABILITY
= 45,
509 WLAN_EID_HT_EXTRA_INFO
= 61,
513 WLAN_EID_GENERIC
= 221,
514 WLAN_EID_VENDOR_SPECIFIC
= 221,
515 WLAN_EID_QOS_PARAMETER
= 222
518 /* Action category code */
519 enum ieee80211_category
{
520 WLAN_CATEGORY_SPECTRUM_MGMT
= 0,
521 WLAN_CATEGORY_QOS
= 1,
522 WLAN_CATEGORY_DLS
= 2,
523 WLAN_CATEGORY_BACK
= 3,
524 WLAN_CATEGORY_WMM
= 17,
527 /* BACK action code */
528 enum ieee80211_back_actioncode
{
529 WLAN_ACTION_ADDBA_REQ
= 0,
530 WLAN_ACTION_ADDBA_RESP
= 1,
531 WLAN_ACTION_DELBA
= 2,
534 /* BACK (block-ack) parties */
535 enum ieee80211_back_parties
{
536 WLAN_BACK_RECIPIENT
= 0,
537 WLAN_BACK_INITIATOR
= 1,
542 #define IEEE80211_QOS_CONTROL_A_MSDU_PRESENT 0x0080
544 /* cipher suite selectors */
545 #define WLAN_CIPHER_SUITE_USE_GROUP 0x000FAC00
546 #define WLAN_CIPHER_SUITE_WEP40 0x000FAC01
547 #define WLAN_CIPHER_SUITE_TKIP 0x000FAC02
548 /* reserved: 0x000FAC03 */
549 #define WLAN_CIPHER_SUITE_CCMP 0x000FAC04
550 #define WLAN_CIPHER_SUITE_WEP104 0x000FAC05
552 #define WLAN_MAX_KEY_LEN 32
555 * ieee80211_get_SA - get pointer to SA
557 * Given an 802.11 frame, this function returns the offset
558 * to the source address (SA). It does not verify that the
559 * header is long enough to contain the address, and the
560 * header must be long enough to contain the frame control
565 static inline u8
*ieee80211_get_SA(struct ieee80211_hdr
*hdr
)
567 __le16 fc
= hdr
->frame_control
;
568 fc
&= cpu_to_le16(IEEE80211_FCTL_TODS
| IEEE80211_FCTL_FROMDS
);
571 case __constant_cpu_to_le16(IEEE80211_FCTL_FROMDS
):
573 case __constant_cpu_to_le16(IEEE80211_FCTL_TODS
|IEEE80211_FCTL_FROMDS
):
581 * ieee80211_get_DA - get pointer to DA
583 * Given an 802.11 frame, this function returns the offset
584 * to the destination address (DA). It does not verify that
585 * the header is long enough to contain the address, and the
586 * header must be long enough to contain the frame control
591 static inline u8
*ieee80211_get_DA(struct ieee80211_hdr
*hdr
)
593 __le16 fc
= hdr
->frame_control
;
594 fc
&= cpu_to_le16(IEEE80211_FCTL_TODS
);
603 * ieee80211_get_morefrag - determine whether the MOREFRAGS bit is set
605 * This function determines whether the "more fragments" bit is set
610 static inline int ieee80211_get_morefrag(struct ieee80211_hdr
*hdr
)
612 __le16 fc
= hdr
->frame_control
;
613 return !!(fc
& cpu_to_le16(IEEE80211_FCTL_MOREFRAGS
));
616 #endif /* IEEE80211_H */