You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ieee80211.h 36KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161
  1. #ifndef _IPXE_IEEE80211_H
  2. #define _IPXE_IEEE80211_H
  3. #include <stddef.h>
  4. #include <ipxe/if_ether.h> /* for ETH_ALEN */
  5. #include <endian.h>
  6. /** @file
  7. * Constants and data structures defined in IEEE 802.11, subsetted
  8. * according to what iPXE knows how to use.
  9. */
  10. FILE_LICENCE(GPL2_OR_LATER);
  11. /* ---------- Maximum lengths of things ---------- */
  12. /**
  13. * @defgroup ieee80211_maxlen Maximum lengths in the 802.11 protocol
  14. * @{
  15. */
  16. /** Maximum length of frame payload
  17. *
  18. * This does not include cryptographic overhead, which can be up to 20
  19. * bytes, but it DOES include the 802.2 LLC/SNAP headers that are used
  20. * on data frames (but not management frames).
  21. */
  22. #define IEEE80211_MAX_DATA_LEN 2304
  23. /** Length of LLC/SNAP headers on data frames */
  24. #define IEEE80211_LLC_HEADER_LEN 8
  25. /** Maximum cryptographic overhead before encrypted data */
  26. #define IEEE80211_MAX_CRYPTO_HEADER 8
  27. /** Maximum cryptographic overhead after encrypted data
  28. *
  29. * This does not count the MIC in TKIP frames, since that is
  30. * considered to be part of the MSDU and thus contributes to the size
  31. * of the data field.
  32. *
  33. * It @e does count the MIC in CCMP frames, which is considered part
  34. * of the MPDU (outside the data field).
  35. */
  36. #define IEEE80211_MAX_CRYPTO_TRAILER 8
  37. /** Total maximum cryptographic overhead */
  38. #define IEEE80211_MAX_CRYPTO_OVERHEAD 16
  39. /** Bytes of network-layer data that can go into a regular data frame */
  40. #define IEEE80211_MAX_FRAME_DATA 2296
  41. /** Frame header length for frames we might work with
  42. *
  43. * QoS adds a two-byte field on top of this, and APs communicating
  44. * with each other in Wireless Distribution System (WDS) mode add an
  45. * extra 6-byte MAC address field, but we do not work with such
  46. * frames.
  47. */
  48. #define IEEE80211_TYP_FRAME_HEADER_LEN 24
  49. /** Theoretical maximum frame header length
  50. *
  51. * This includes the QoS and WDS Addr4 fields that we should never
  52. * see.
  53. */
  54. #define IEEE80211_MAX_FRAME_HEADER_LEN 32
  55. /** Maximum combined frame length
  56. *
  57. * The biggest frame will include 32 frame header bytes, 16 bytes of
  58. * crypto overhead, and 2304 data bytes.
  59. */
  60. #define IEEE80211_MAX_FRAME_LEN 2352
  61. /** Maximum length of an ESSID */
  62. #define IEEE80211_MAX_SSID_LEN 32
  63. /** @} */
  64. /* ---------- Frame Control defines ---------- */
  65. /**
  66. * @defgroup ieee80211_fc 802.11 Frame Control field bits
  67. * @{
  68. */
  69. /** 802.11 Frame Control field, Version bitmask */
  70. #define IEEE80211_FC_VERSION 0x0003
  71. /** Expected value of Version bits in Frame Control */
  72. #define IEEE80211_THIS_VERSION 0x0000
  73. /** 802.11 Frame Control field, Frame Type bitmask */
  74. #define IEEE80211_FC_TYPE 0x000C
  75. /** Type value for management (layer-2) frames */
  76. #define IEEE80211_TYPE_MGMT 0x0000
  77. /** Type value for control (layer-1, hardware-managed) frames */
  78. #define IEEE80211_TYPE_CTRL 0x0004
  79. /** Type value for data frames */
  80. #define IEEE80211_TYPE_DATA 0x0008
  81. /** 802.11 Frame Control field, Frame Subtype bitmask */
  82. #define IEEE80211_FC_SUBTYPE 0x00F0
  83. /** Subtype value for association-request management frames
  84. *
  85. * Association request frames are sent after authentication from the
  86. * client to the Access Point to establish the client as part of the
  87. * Access Point's network.
  88. */
  89. #define IEEE80211_STYPE_ASSOC_REQ 0x0000
  90. /** Subtype value for association-response management frames
  91. *
  92. * Association response frames are sent by the Access Point to confirm
  93. * or deny the association requested in an association request frame.
  94. */
  95. #define IEEE80211_STYPE_ASSOC_RESP 0x0010
  96. /** Subtype value for reassociation-request management frames
  97. *
  98. * Reassociation request frames are sent by clients wishing to change
  99. * from one Access Point to another while roaming within the same
  100. * extended network (same ESSID).
  101. */
  102. #define IEEE80211_STYPE_REASSOC_REQ 0x0020
  103. /** Subtype value for reassociation-response management frames
  104. *
  105. * Reassociation response frames are sent by the Access Point to
  106. * confirm or deny the swap requested in a reassociation request
  107. * frame.
  108. */
  109. #define IEEE80211_STYPE_REASSOC_RESP 0x0030
  110. /** Subtype value for probe-request management frames
  111. *
  112. * Probe request frames are sent by clients to request that all Access
  113. * Points on the sending channel, or all belonging to a particular
  114. * ESSID, identify themselves by BSSID, supported transfer rates, RF
  115. * configuration, and other capabilities.
  116. */
  117. #define IEEE80211_STYPE_PROBE_REQ 0x0040
  118. /** Subtype value for probe-response management frames
  119. *
  120. * Probe response frames are sent by Access Points in response to
  121. * probe request frames, providing the requested information.
  122. */
  123. #define IEEE80211_STYPE_PROBE_RESP 0x0050
  124. /** Subtype value for beacon management frames
  125. *
  126. * Beacon frames are sent by Access Points at regular intervals,
  127. * usually ten per second, on the channel on which they communicate.
  128. * They can be used to probe passively for access points on a channel
  129. * where local regulatory restrictions prohibit active scanning, or
  130. * due to their regularity as a mechanism to determine the fraction of
  131. * packets that are being dropped.
  132. */
  133. #define IEEE80211_STYPE_BEACON 0x0080
  134. /** Subtype value for disassociation management frames
  135. *
  136. * Disassociation frames are sent by either a client or an Access
  137. * Point to unequivocally terminate the association between the two.
  138. * They may be sent by clients upon leaving the network, or by an
  139. * Access Point upon reconfiguration, among other reasons; they are
  140. * usually more "polite" than deauthentication frames.
  141. */
  142. #define IEEE80211_STYPE_DISASSOC 0x00A0
  143. /** Subtype value for authentication management frames
  144. *
  145. * Authentication frames are exchanged between a client and an Access
  146. * Point before association may be performed. Confusingly, in the most
  147. * common authentication method (Open System) no security tokens are
  148. * exchanged at all. Modern 802.11 security handshaking takes place
  149. * after association.
  150. */
  151. #define IEEE80211_STYPE_AUTH 0x00B0
  152. /** Subtype value for deauthentication management frames
  153. *
  154. * Deauthentication frames are sent by either a client or an Access
  155. * Point to terminate the authentication (and therefore also the
  156. * association) between the two. They are generally more forceful than
  157. * disassociation frames, sent for such reasons as a failure to
  158. * set up security properly after associating.
  159. */
  160. #define IEEE80211_STYPE_DEAUTH 0x00C0
  161. /** Subtype value for action management frames
  162. *
  163. * Action frames are used to implement spectrum management and QoS
  164. * features that iPXE currently does not support.
  165. */
  166. #define IEEE80211_STYPE_ACTION 0x00D0
  167. /** Subtype value for RTS (request to send) control frames */
  168. #define IEEE80211_STYPE_RTS 0x00B0
  169. /** Subtype value for CTS (clear to send) control frames */
  170. #define IEEE80211_STYPE_CTS 0x00C0
  171. /** Subtype value for ACK (acknowledgement) control frames */
  172. #define IEEE80211_STYPE_ACK 0x00D0
  173. /** Subtype value for ordinary data frames, with no QoS or CF add-ons */
  174. #define IEEE80211_STYPE_DATA 0x0000
  175. /** Subtype value for data frames containing no data */
  176. #define IEEE80211_STYPE_NODATA 0x0040
  177. /** 802.11 Frame Control field: To Data System flag
  178. *
  179. * This is set on data frames sent to an Access Point.
  180. */
  181. #define IEEE80211_FC_TODS 0x0100
  182. /** 802.11 Frame Control field: From Data System flag
  183. *
  184. * This is set on data frames sent from an Access Point. If both TODS
  185. * and FROMDS are set, the frame header is a 4-address format used for
  186. * inter-Access Point communication.
  187. */
  188. #define IEEE80211_FC_FROMDS 0x0200
  189. /** 802.11 Frame Control field: More Fragments flag */
  190. #define IEEE80211_FC_MORE_FRAG 0x0400
  191. /** 802.11 Frame Control field: Retransmission flag */
  192. #define IEEE80211_FC_RETRY 0x0800
  193. /** 802.11 Frame Control field: Power Managed flag
  194. *
  195. * This is set on any frame sent by a low-power station that will go
  196. * into a power-saving mode immediately after this frame. Access
  197. * Points are not allowed to act as low-power stations.
  198. */
  199. #define IEEE80211_FC_PWR_MGMT 0x1000
  200. /** 802.11 Frame Control field: More Data flag
  201. *
  202. * This is set on any frame sent by a station that has more data
  203. * queued to be sent than is in the frame.
  204. */
  205. #define IEEE80211_FC_MORE_DATA 0x2000
  206. /** 802.11 Frame Control field: Protected flag
  207. *
  208. * This is set on frames in which data is encrypted (by any method).
  209. */
  210. #define IEEE80211_FC_PROTECTED 0x4000
  211. /** 802.11 Frame Control field: Ordered flag [?] */
  212. #define IEEE80211_FC_ORDER 0x8000
  213. /** @} */
  214. /* ---------- Sequence Control defines ---------- */
  215. /**
  216. * @defgroup ieee80211_seq 802.11 Sequence Control field handling
  217. * @{
  218. */
  219. /** Extract sequence number from 802.11 Sequence Control field */
  220. #define IEEE80211_SEQNR( seq ) ( ( seq ) >> 4 )
  221. /** Extract fragment number from 802.11 Sequence Control field */
  222. #define IEEE80211_FRAG( seq ) ( ( seq ) & 0x000F )
  223. /** Make 802.11 Sequence Control field from sequence and fragment numbers */
  224. #define IEEE80211_MAKESEQ( seqnr, frag ) \
  225. ( ( ( ( seqnr ) & 0xFFF ) << 4 ) | ( ( frag ) & 0xF ) )
  226. /** @} */
  227. /* ---------- Frame header formats ---------- */
  228. /**
  229. * @defgroup ieee80211_hdr 802.11 frame header formats
  230. * @{
  231. */
  232. /** An 802.11 data or management frame without QoS or WDS header fields */
  233. struct ieee80211_frame
  234. {
  235. u16 fc; /**< 802.11 Frame Control field */
  236. u16 duration; /**< Microseconds to reserve link */
  237. u8 addr1[ETH_ALEN]; /**< Address 1 (immediate receiver) */
  238. u8 addr2[ETH_ALEN]; /**< Address 2 (immediate sender) */
  239. u8 addr3[ETH_ALEN]; /**< Address 3 (often "forward to") */
  240. u16 seq; /**< 802.11 Sequence Control field */
  241. u8 data[0]; /**< Beginning of frame data */
  242. } __attribute__((packed));
  243. /** The 802.2 LLC/SNAP header sent before actual data in a data frame
  244. *
  245. * This header is not acknowledged in the 802.11 standard at all; it
  246. * is treated just like data for MAC-layer purposes, including
  247. * fragmentation and encryption. It is actually two headers
  248. * concatenated: a three-byte 802.2 LLC header indicating Subnetwork
  249. * Accesss Protocol (SNAP) in both source and destination Service
  250. * Access Point (SAP) fields, and a five-byte SNAP header indicating a
  251. * zero OUI and two-byte Ethernet protocol type field.
  252. *
  253. * Thus, an eight-byte header in which six of the bytes are redundant.
  254. * Lovely, isn't it?
  255. */
  256. struct ieee80211_llc_snap_header
  257. {
  258. /* LLC part: */
  259. u8 dsap; /**< Destination SAP ID */
  260. u8 ssap; /**< Source SAP ID */
  261. u8 ctrl; /**< Control information */
  262. /* SNAP part: */
  263. u8 oui[3]; /**< Organization code, usually 0 */
  264. u16 ethertype; /**< Ethernet Type field */
  265. } __attribute__((packed));
  266. /** Value for DSAP field in 802.2 LLC header for 802.11 frames: SNAP */
  267. #define IEEE80211_LLC_DSAP 0xAA
  268. /** Value for SSAP field in 802.2 LLC header for 802.11 frames: SNAP */
  269. #define IEEE80211_LLC_SSAP 0xAA
  270. /** Value for control field in 802.2 LLC header for 802.11 frames
  271. *
  272. * "Unnumbered Information".
  273. */
  274. #define IEEE80211_LLC_CTRL 0x03
  275. /** 16-byte RTS frame format, with abbreviated header */
  276. struct ieee80211_rts
  277. {
  278. u16 fc; /**< 802.11 Frame Control field */
  279. u16 duration; /**< Microseconds to reserve link */
  280. u8 addr1[ETH_ALEN]; /**< Address 1 (immediate receiver) */
  281. u8 addr2[ETH_ALEN]; /**< Address 2 (immediate sender) */
  282. } __attribute__((packed));
  283. /** Length of 802.11 RTS control frame */
  284. #define IEEE80211_RTS_LEN 16
  285. /** 10-byte CTS or ACK frame format, with abbreviated header */
  286. struct ieee80211_cts_or_ack
  287. {
  288. u16 fc; /**< 802.11 Frame Control field */
  289. u16 duration; /**< Microseconds to reserve link */
  290. u8 addr1[ETH_ALEN]; /**< Address 1 (immediate receiver) */
  291. } __attribute__((packed));
  292. #define ieee80211_cts ieee80211_cts_or_ack
  293. #define ieee80211_ack ieee80211_cts_or_ack
  294. /** Length of 802.11 CTS control frame */
  295. #define IEEE80211_CTS_LEN 10
  296. /** Length of 802.11 ACK control frame */
  297. #define IEEE80211_ACK_LEN 10
  298. /** @} */
  299. /* ---------- Capability bits, status and reason codes ---------- */
  300. /**
  301. * @defgroup ieee80211_capab 802.11 management frame capability field bits
  302. * @{
  303. */
  304. /** Set if using an Access Point (managed mode) */
  305. #define IEEE80211_CAPAB_MANAGED 0x0001
  306. /** Set if operating in IBSS (no-AP, "Ad-Hoc") mode */
  307. #define IEEE80211_CAPAB_ADHOC 0x0002
  308. /** Set if we support Contention-Free Period operation */
  309. #define IEEE80211_CAPAB_CFPOLL 0x0004
  310. /** Set if we wish to be polled for Contention-Free operation */
  311. #define IEEE80211_CAPAB_CFPR 0x0008
  312. /** Set if the network is encrypted (by any method) */
  313. #define IEEE80211_CAPAB_PRIVACY 0x0010
  314. /** Set if PHY supports short preambles on 802.11b */
  315. #define IEEE80211_CAPAB_SHORT_PMBL 0x0020
  316. /** Set if PHY supports PBCC modulation */
  317. #define IEEE80211_CAPAB_PBCC 0x0040
  318. /** Set if we support Channel Agility */
  319. #define IEEE80211_CAPAB_CHAN_AGILITY 0x0080
  320. /** Set if we support spectrum management (DFS and TPC) on the 5GHz band */
  321. #define IEEE80211_CAPAB_SPECTRUM_MGMT 0x0100
  322. /** Set if we support Quality of Service enhancements */
  323. #define IEEE80211_CAPAB_QOS 0x0200
  324. /** Set if PHY supports short slot time on 802.11g */
  325. #define IEEE80211_CAPAB_SHORT_SLOT 0x0400
  326. /** Set if PHY supports APSD option */
  327. #define IEEE80211_CAPAB_APSD 0x0800
  328. /** Set if PHY supports DSSS/OFDM modulation (one way of 802.11 b/g mixing) */
  329. #define IEEE80211_CAPAB_DSSS_OFDM 0x2000
  330. /** Set if we support delayed block ACK */
  331. #define IEEE80211_CAPAB_DELAYED_BACK 0x4000
  332. /** Set if we support immediate block ACK */
  333. #define IEEE80211_CAPAB_IMMED_BACK 0x8000
  334. /** @} */
  335. /**
  336. * @defgroup ieee80211_status 802.11 status codes
  337. *
  338. * These are returned to indicate an immediate denial of
  339. * authentication or association. In iPXE, the lower 5 bits of the
  340. * status code are encoded into the file-unique portion of an error
  341. * code, the ERRFILE portion is always @c ERRFILE_net80211, and the
  342. * POSIX error code is @c ECONNREFUSED for status 0-31 or @c
  343. * EHOSTUNREACH for status 32-63.
  344. *
  345. * For a complete table with non-abbreviated error messages, see IEEE
  346. * Std 802.11-2007, Table 7-23, p.94.
  347. *
  348. * @{
  349. */
  350. #define IEEE80211_STATUS_SUCCESS 0
  351. #define IEEE80211_STATUS_FAILURE 1
  352. #define IEEE80211_STATUS_CAPAB_UNSUPP 10
  353. #define IEEE80211_STATUS_REASSOC_INVALID 11
  354. #define IEEE80211_STATUS_ASSOC_DENIED 12
  355. #define IEEE80211_STATUS_AUTH_ALGO_UNSUPP 13
  356. #define IEEE80211_STATUS_AUTH_SEQ_INVALID 14
  357. #define IEEE80211_STATUS_AUTH_CHALL_INVALID 15
  358. #define IEEE80211_STATUS_AUTH_TIMEOUT 16
  359. #define IEEE80211_STATUS_ASSOC_NO_ROOM 17
  360. #define IEEE80211_STATUS_ASSOC_NEED_RATE 18
  361. #define IEEE80211_STATUS_ASSOC_NEED_SHORT_PMBL 19
  362. #define IEEE80211_STATUS_ASSOC_NEED_PBCC 20
  363. #define IEEE80211_STATUS_ASSOC_NEED_CHAN_AGILITY 21
  364. #define IEEE80211_STATUS_ASSOC_NEED_SPECTRUM_MGMT 22
  365. #define IEEE80211_STATUS_ASSOC_BAD_POWER 23
  366. #define IEEE80211_STATUS_ASSOC_BAD_CHANNELS 24
  367. #define IEEE80211_STATUS_ASSOC_NEED_SHORT_SLOT 25
  368. #define IEEE80211_STATUS_ASSOC_NEED_DSSS_OFDM 26
  369. #define IEEE80211_STATUS_QOS_FAILURE 32
  370. #define IEEE80211_STATUS_QOS_NO_ROOM 33
  371. #define IEEE80211_STATUS_LINK_IS_HORRIBLE 34
  372. #define IEEE80211_STATUS_ASSOC_NEED_QOS 35
  373. #define IEEE80211_STATUS_REQUEST_DECLINED 37
  374. #define IEEE80211_STATUS_REQUEST_INVALID 38
  375. #define IEEE80211_STATUS_TS_NOT_CREATED_AGAIN 39
  376. #define IEEE80211_STATUS_INVALID_IE 40
  377. #define IEEE80211_STATUS_GROUP_CIPHER_INVALID 41
  378. #define IEEE80211_STATUS_PAIR_CIPHER_INVALID 42
  379. #define IEEE80211_STATUS_AKMP_INVALID 43
  380. #define IEEE80211_STATUS_RSN_VERSION_UNSUPP 44
  381. #define IEEE80211_STATUS_RSN_CAPAB_INVALID 45
  382. #define IEEE80211_STATUS_CIPHER_REJECTED 46
  383. #define IEEE80211_STATUS_TS_NOT_CREATED_WAIT 47
  384. #define IEEE80211_STATUS_DIRECT_LINK_FORBIDDEN 48
  385. #define IEEE80211_STATUS_DEST_NOT_PRESENT 49
  386. #define IEEE80211_STATUS_DEST_NOT_QOS 50
  387. #define IEEE80211_STATUS_ASSOC_LISTEN_TOO_HIGH 51
  388. /** @} */
  389. /**
  390. * @defgroup ieee80211_reason 802.11 reason codes
  391. *
  392. * These are returned to indicate the reason for a deauthentication or
  393. * disassociation sent (usually) after authentication or association
  394. * had succeeded. In iPXE, the lower 5 bits of the reason code are
  395. * encoded into the file-unique portion of an error code, the ERRFILE
  396. * portion is always @c ERRFILE_net80211, and the POSIX error code is
  397. * @c ECONNRESET for reason 0-31 or @c ENETRESET for reason 32-63.
  398. *
  399. * For a complete table with non-abbreviated error messages, see IEEE
  400. * Std 802.11-2007, Table 7-22, p.92.
  401. *
  402. * @{
  403. */
  404. #define IEEE80211_REASON_NONE 0
  405. #define IEEE80211_REASON_UNSPECIFIED 1
  406. #define IEEE80211_REASON_AUTH_NO_LONGER_VALID 2
  407. #define IEEE80211_REASON_LEAVING 3
  408. #define IEEE80211_REASON_INACTIVITY 4
  409. #define IEEE80211_REASON_OUT_OF_RESOURCES 5
  410. #define IEEE80211_REASON_NEED_AUTH 6
  411. #define IEEE80211_REASON_NEED_ASSOC 7
  412. #define IEEE80211_REASON_LEAVING_TO_ROAM 8
  413. #define IEEE80211_REASON_REASSOC_INVALID 9
  414. #define IEEE80211_REASON_BAD_POWER 10
  415. #define IEEE80211_REASON_BAD_CHANNELS 11
  416. #define IEEE80211_REASON_INVALID_IE 13
  417. #define IEEE80211_REASON_MIC_FAILURE 14
  418. #define IEEE80211_REASON_4WAY_TIMEOUT 15
  419. #define IEEE80211_REASON_GROUPKEY_TIMEOUT 16
  420. #define IEEE80211_REASON_4WAY_INVALID 17
  421. #define IEEE80211_REASON_GROUP_CIPHER_INVALID 18
  422. #define IEEE80211_REASON_PAIR_CIPHER_INVALID 19
  423. #define IEEE80211_REASON_AKMP_INVALID 20
  424. #define IEEE80211_REASON_RSN_VERSION_INVALID 21
  425. #define IEEE80211_REASON_RSN_CAPAB_INVALID 22
  426. #define IEEE80211_REASON_8021X_FAILURE 23
  427. #define IEEE80211_REASON_CIPHER_REJECTED 24
  428. #define IEEE80211_REASON_QOS_UNSPECIFIED 32
  429. #define IEEE80211_REASON_QOS_OUT_OF_RESOURCES 33
  430. #define IEEE80211_REASON_LINK_IS_HORRIBLE 34
  431. #define IEEE80211_REASON_INVALID_TXOP 35
  432. #define IEEE80211_REASON_REQUESTED_LEAVING 36
  433. #define IEEE80211_REASON_REQUESTED_NO_USE 37
  434. #define IEEE80211_REASON_REQUESTED_NEED_SETUP 38
  435. #define IEEE80211_REASON_REQUESTED_TIMEOUT 39
  436. #define IEEE80211_REASON_CIPHER_UNSUPPORTED 45
  437. /** @} */
  438. /* ---------- Information element declarations ---------- */
  439. /**
  440. * @defgroup ieee80211_ie 802.11 information elements
  441. *
  442. * Many management frames include a section that amounts to a
  443. * concatenation of these information elements, so that the sender can
  444. * choose which information to send and the receiver can ignore the
  445. * parts it doesn't understand. Each IE contains a two-byte header,
  446. * one byte ID and one byte length, followed by IE-specific data. The
  447. * length does not include the two-byte header. Information elements
  448. * are required to be sorted by ID, but iPXE does not require that in
  449. * those it receives.
  450. *
  451. * This group also includes a few inline functions to simplify common
  452. * tasks in IE processing.
  453. *
  454. * @{
  455. */
  456. /** Generic 802.11 information element header */
  457. struct ieee80211_ie_header {
  458. u8 id; /**< Information element ID */
  459. u8 len; /**< Information element length */
  460. } __attribute__ ((packed));
  461. /** 802.11 SSID information element */
  462. struct ieee80211_ie_ssid {
  463. u8 id; /**< SSID ID: 0 */
  464. u8 len; /**< SSID length */
  465. char ssid[0]; /**< SSID data, not NUL-terminated */
  466. } __attribute__ ((packed));
  467. /** Information element ID for SSID information element */
  468. #define IEEE80211_IE_SSID 0
  469. /** 802.11 rates information element
  470. *
  471. * The first 8 rates go in an IE of type RATES (1), and any more rates
  472. * go in one of type EXT_RATES (50). Each rate is a byte with the low
  473. * 7 bits equal to the rate in units of 500 kbps, and the high bit set
  474. * if and only if the rate is "basic" (must be supported by all
  475. * connected stations).
  476. */
  477. struct ieee80211_ie_rates {
  478. u8 id; /**< Rates ID: 1 or 50 */
  479. u8 len; /**< Number of rates */
  480. u8 rates[0]; /**< Rates data, one rate per byte */
  481. } __attribute__ ((packed));
  482. /** Information element ID for rates information element */
  483. #define IEEE80211_IE_RATES 1
  484. /** Information element ID for extended rates information element */
  485. #define IEEE80211_IE_EXT_RATES 50
  486. /** 802.11 Direct Spectrum parameter information element
  487. *
  488. * This just contains the channel number. It has the fancy name
  489. * because IEEE 802.11 also defines a frequency-hopping PHY that
  490. * changes channels at regular intervals following a predetermined
  491. * pattern; in practice nobody uses the FH PHY.
  492. */
  493. struct ieee80211_ie_ds_param {
  494. u8 id; /**< DS parameter ID: 3 */
  495. u8 len; /**< DS parameter length: 1 */
  496. u8 current_channel; /**< Current channel number, 1-14 */
  497. } __attribute__ ((packed));
  498. /** Information element ID for Direct Spectrum parameter information element */
  499. #define IEEE80211_IE_DS_PARAM 3
  500. /** 802.11 Country information element regulatory extension triplet */
  501. struct ieee80211_ie_country_ext_triplet {
  502. u8 reg_ext_id; /**< Regulatory extension ID */
  503. u8 reg_class_id; /**< Regulatory class ID */
  504. u8 coverage_class; /**< Coverage class */
  505. } __attribute__ ((packed));
  506. /** 802.11 Country information element regulatory band triplet */
  507. struct ieee80211_ie_country_band_triplet {
  508. u8 first_channel; /**< Channel number for first channel in band */
  509. u8 nr_channels; /**< Number of contiguous channels in band */
  510. u8 max_txpower; /**< Maximum TX power in dBm */
  511. } __attribute__ ((packed));
  512. /** 802.11 Country information element regulatory triplet
  513. *
  514. * It is a band triplet if the first byte is 200 or less, and a
  515. * regulatory extension triplet otherwise.
  516. */
  517. union ieee80211_ie_country_triplet {
  518. /** Differentiator between band and ext triplets */
  519. u8 first;
  520. /** Information about a band of channels */
  521. struct ieee80211_ie_country_band_triplet band;
  522. /** Regulatory extension information */
  523. struct ieee80211_ie_country_ext_triplet ext;
  524. };
  525. /** 802.11 Country information element
  526. *
  527. * This contains some data about RF regulations.
  528. */
  529. struct ieee80211_ie_country {
  530. u8 id; /**< Country information ID: 7 */
  531. u8 len; /**< Country information length: varies */
  532. char name[2]; /**< ISO Alpha2 country code */
  533. char in_out; /**< 'I' for indoor, 'O' for outdoor */
  534. /** List of regulatory triplets */
  535. union ieee80211_ie_country_triplet triplet[0];
  536. } __attribute__ ((packed));
  537. /** Information element ID for Country information element */
  538. #define IEEE80211_IE_COUNTRY 7
  539. /** 802.11 Request information element
  540. *
  541. * This contains a list of information element types we would like to
  542. * be included in probe response frames.
  543. */
  544. struct ieee80211_ie_request {
  545. u8 id; /**< Request ID: 10 */
  546. u8 len; /**< Number of IEs requested */
  547. u8 request[0]; /**< List of IEs requested */
  548. } __attribute__ ((packed));
  549. /** Information element ID for Request information element */
  550. #define IEEE80211_IE_REQUEST 10
  551. /** 802.11 Challenge Text information element
  552. *
  553. * This is used in authentication frames under Shared Key
  554. * authentication.
  555. */
  556. struct ieee80211_ie_challenge_text {
  557. u8 id; /**< Challenge Text ID: 16 */
  558. u8 len; /**< Challenge Text length: usually 128 */
  559. u8 challenge_text[0]; /**< Challenge Text data */
  560. } __attribute__ ((packed));
  561. /** Information element ID for Challenge Text information element */
  562. #define IEEE80211_IE_CHALLENGE_TEXT 16
  563. /** 802.11 Power Constraint information element
  564. *
  565. * This is used to specify an additional power limitation on top of
  566. * the Country requirements.
  567. */
  568. struct ieee80211_ie_power_constraint {
  569. u8 id; /**< Power Constraint ID: 52 */
  570. u8 len; /**< Power Constraint length: 1 */
  571. u8 power_constraint; /**< Decrease in allowed TX power, dBm */
  572. } __attribute__ ((packed));
  573. /** Information element ID for Power Constraint information element */
  574. #define IEEE80211_IE_POWER_CONSTRAINT 52
  575. /** 802.11 Power Capability information element
  576. *
  577. * This is used in association request frames to indicate the extremes
  578. * of our TX power abilities. It is required only if we indicate
  579. * support for spectrum management.
  580. */
  581. struct ieee80211_ie_power_capab {
  582. u8 id; /**< Power Capability ID: 33 */
  583. u8 len; /**< Power Capability length: 2 */
  584. u8 min_txpower; /**< Minimum possible TX power, dBm */
  585. u8 max_txpower; /**< Maximum possible TX power, dBm */
  586. } __attribute__ ((packed));
  587. /** Information element ID for Power Capability information element */
  588. #define IEEE80211_IE_POWER_CAPAB 33
  589. /** 802.11 Channels information element channel band tuple */
  590. struct ieee80211_ie_channels_channel_band {
  591. u8 first_channel; /**< Channel number of first channel in band */
  592. u8 nr_channels; /**< Number of channels in band */
  593. } __attribute__ ((packed));
  594. /** 802.11 Channels information element
  595. *
  596. * This is used in association frames to indicate the channels we can
  597. * use. It is required only if we indicate support for spectrum
  598. * management.
  599. */
  600. struct ieee80211_ie_channels {
  601. u8 id; /**< Channels ID: 36 */
  602. u8 len; /**< Channels length: 2 */
  603. /** List of (start, length) channel bands we can use */
  604. struct ieee80211_ie_channels_channel_band channels[0];
  605. } __attribute__ ((packed));
  606. /** Information element ID for Channels information element */
  607. #define IEEE80211_IE_CHANNELS 36
  608. /** 802.11 ERP Information information element
  609. *
  610. * This is used to communicate some PHY-level flags.
  611. */
  612. struct ieee80211_ie_erp_info {
  613. u8 id; /**< ERP Information ID: 42 */
  614. u8 len; /**< ERP Information length: 1 */
  615. u8 erp_info; /**< ERP flags */
  616. } __attribute__ ((packed));
  617. /** Information element ID for ERP Information information element */
  618. #define IEEE80211_IE_ERP_INFO 42
  619. /** ERP information element: Flag set if 802.11b stations are present */
  620. #define IEEE80211_ERP_NONERP_PRESENT 0x01
  621. /** ERP information element: Flag set if CTS protection must be used */
  622. #define IEEE80211_ERP_USE_PROTECTION 0x02
  623. /** ERP information element: Flag set if long preambles must be used */
  624. #define IEEE80211_ERP_BARKER_LONG 0x04
  625. /** 802.11 Robust Security Network ("WPA") information element
  626. *
  627. * Showing once again a striking clarity of design, the IEEE folks put
  628. * dynamically-sized data in the middle of this structure. As such,
  629. * the below structure definition only works for IEs we create
  630. * ourselves, which always have one pairwise cipher and one AKM;
  631. * received IEs should be parsed piecemeal.
  632. *
  633. * Also inspired was IEEE's choice of 16-bit fields to count the
  634. * number of 4-byte elements in a structure with a maximum length of
  635. * 255 bytes.
  636. *
  637. * Many fields reference a cipher or authentication-type ID; this is a
  638. * three-byte OUI followed by one byte identifying the cipher with
  639. * respect to that OUI. For all standard ciphers the OUI is 00:0F:AC,
  640. * except in old-style WPA IEs encapsulated in vendor-specific IEs,
  641. * where it's 00:50:F2.
  642. */
  643. struct ieee80211_ie_rsn {
  644. /** Information element ID */
  645. u8 id;
  646. /** Information element length */
  647. u8 len;
  648. /** RSN information element version */
  649. u16 version;
  650. /** Cipher ID for the cipher used in multicast/broadcast frames */
  651. u32 group_cipher;
  652. /** Number of unicast ciphers supported */
  653. u16 pairwise_count;
  654. /** List of cipher IDs for supported unicast frame ciphers */
  655. u32 pairwise_cipher[1];
  656. /** Number of authentication types supported */
  657. u16 akm_count;
  658. /** List of authentication type IDs for supported types */
  659. u32 akm_list[1];
  660. /** Security capabilities field (RSN only) */
  661. u16 rsn_capab;
  662. /** Number of PMKIDs included (present only in association frames) */
  663. u16 pmkid_count;
  664. /** List of PMKIDs included, each a 16-byte SHA1 hash */
  665. u8 pmkid_list[0];
  666. } __attribute__((packed));
  667. /** Information element ID for Robust Security Network information element */
  668. #define IEEE80211_IE_RSN 48
  669. /** Calculate necessary size of RSN information element
  670. *
  671. * @v npair Number of pairwise ciphers supported
  672. * @v nauth Number of authentication types supported
  673. * @v npmkid Number of PMKIDs to include
  674. * @v is_rsn If TRUE, calculate RSN IE size; if FALSE, calculate WPA IE size
  675. * @ret size Necessary size of IE, including header bytes
  676. */
  677. static inline size_t ieee80211_rsn_size ( int npair, int nauth, int npmkid,
  678. int rsn_ie ) {
  679. return 16 + 4 * ( npair + nauth ) + 16 * npmkid - 4 * ! rsn_ie;
  680. }
  681. /** Make OUI plus type byte into 32-bit integer for easy comparison */
  682. #if __BYTE_ORDER == __BIG_ENDIAN
  683. #define _MKOUI( a, b, c, t ) \
  684. ( ( ( a ) << 24 ) | ( ( b ) << 16 ) | ( ( c ) << 8 ) | ( d ) )
  685. #define OUI_ORG_MASK 0xFFFFFF00
  686. #define OUI_TYPE_MASK 0x000000FF
  687. #else
  688. #define _MKOUI( a, b, c, t ) \
  689. ( ( ( t ) << 24 ) | ( ( c ) << 16 ) | ( ( b ) << 8 ) | ( a ) )
  690. #define OUI_ORG_MASK 0x00FFFFFF
  691. #define OUI_TYPE_MASK 0xFF000000
  692. #endif
  693. /** Organization part for OUIs in standard RSN IE */
  694. #define IEEE80211_RSN_OUI _MKOUI ( 0x00, 0x0F, 0xAC, 0 )
  695. /** Organization part for OUIs in old WPA IE */
  696. #define IEEE80211_WPA_OUI _MKOUI ( 0x00, 0x50, 0xF2, 0 )
  697. /** Old vendor-type WPA IE OUI type + subtype */
  698. #define IEEE80211_WPA_OUI_VEN _MKOUI ( 0x00, 0x50, 0xF2, 0x01 )
  699. /** 802.11 RSN IE: expected version number */
  700. #define IEEE80211_RSN_VERSION 1
  701. /** 802.11 RSN IE: cipher type for 40-bit WEP */
  702. #define IEEE80211_RSN_CTYPE_WEP40 _MKOUI ( 0, 0, 0, 0x01 )
  703. /** 802.11 RSN IE: cipher type for 104-bit WEP */
  704. #define IEEE80211_RSN_CTYPE_WEP104 _MKOUI ( 0, 0, 0, 0x05 )
  705. /** 802.11 RSN IE: cipher type for TKIP ("WPA") */
  706. #define IEEE80211_RSN_CTYPE_TKIP _MKOUI ( 0, 0, 0, 0x02 )
  707. /** 802.11 RSN IE: cipher type for CCMP ("WPA2") */
  708. #define IEEE80211_RSN_CTYPE_CCMP _MKOUI ( 0, 0, 0, 0x04 )
  709. /** 802.11 RSN IE: cipher type for "use group"
  710. *
  711. * This can only appear as a pairwise cipher, and means unicast frames
  712. * should be encrypted in the same way as broadcast/multicast frames.
  713. */
  714. #define IEEE80211_RSN_CTYPE_USEGROUP _MKOUI ( 0, 0, 0, 0x00 )
  715. /** 802.11 RSN IE: auth method type for using an 802.1X server */
  716. #define IEEE80211_RSN_ATYPE_8021X _MKOUI ( 0, 0, 0, 0x01 )
  717. /** 802.11 RSN IE: auth method type for using a pre-shared key */
  718. #define IEEE80211_RSN_ATYPE_PSK _MKOUI ( 0, 0, 0, 0x02 )
  719. /** 802.11 RSN IE capabilities: AP supports pre-authentication */
  720. #define IEEE80211_RSN_CAPAB_PREAUTH 0x001
  721. /** 802.11 RSN IE capabilities: Node has conflict between TKIP and WEP
  722. *
  723. * This is a legacy issue; APs always set it to 0, and iPXE sets it to
  724. * 0.
  725. */
  726. #define IEEE80211_RSN_CAPAB_NO_PAIRWISE 0x002
  727. /** 802.11 RSN IE capabilities: Number of PTKSA replay counters
  728. *
  729. * A value of 0 means one replay counter, 1 means two, 2 means four,
  730. * and 3 means sixteen.
  731. */
  732. #define IEEE80211_RSN_CAPAB_PTKSA_REPLAY 0x00C
  733. /** 802.11 RSN IE capabilities: Number of GTKSA replay counters
  734. *
  735. * A value of 0 means one replay counter, 1 means two, 2 means four,
  736. * and 3 means sixteen.
  737. */
  738. #define IEEE80211_RSN_CAPAB_GTKSA_REPLAY 0x030
  739. /** 802.11 RSN IE capabilities: PeerKey Handshaking is suported */
  740. #define IEEE80211_RSN_CAPAB_PEERKEY 0x200
  741. /** 802.11 RSN IE capabilities: One replay counter
  742. *
  743. * This should be AND'ed with @c IEEE80211_RSN_CAPAB_PTKSA_REPLAY or
  744. * @c IEEE80211_RSN_CAPAB_GTKSA_REPLAY (or both) to produce a value
  745. * which can be OR'ed into the capabilities field.
  746. */
  747. #define IEEE80211_RSN_1_CTR 0x000
  748. /** 802.11 RSN IE capabilities: Two replay counters */
  749. #define IEEE80211_RSN_2_CTR 0x014
  750. /** 802.11 RSN IE capabilities: Four replay counters */
  751. #define IEEE80211_RSN_4_CTR 0x028
  752. /** 802.11 RSN IE capabilities: 16 replay counters */
  753. #define IEEE80211_RSN_16_CTR 0x03C
  754. /** 802.11 Vendor Specific information element
  755. *
  756. * One often sees the RSN IE masquerading as vendor-specific on
  757. * devices that were produced prior to 802.11i (the WPA amendment)
  758. * being finalized.
  759. */
  760. struct ieee80211_ie_vendor {
  761. u8 id; /**< Vendor-specific ID: 221 */
  762. u8 len; /**< Vendor-specific length: variable */
  763. u32 oui; /**< OUI and vendor-specific type byte */
  764. u8 data[0]; /**< Vendor-specific data */
  765. } __attribute__ ((packed));
  766. /** Information element ID for Vendor Specific information element */
  767. #define IEEE80211_IE_VENDOR 221
  768. /** Any 802.11 information element
  769. *
  770. * This is formatted for ease of use, so IEs with complex structures
  771. * get referenced in full, while those with only one byte of data or a
  772. * simple array are pulled in to avoid a layer of indirection like
  773. * ie->channels.channels[0].
  774. */
  775. union ieee80211_ie
  776. {
  777. /** Generic and simple information element info */
  778. struct {
  779. u8 id; /**< Information element ID */
  780. u8 len; /**< Information element data length */
  781. union {
  782. char ssid[0]; /**< SSID text */
  783. u8 rates[0]; /**< Rates data */
  784. u8 request[0]; /**< Request list */
  785. u8 challenge_text[0]; /**< Challenge text data */
  786. u8 power_constraint; /**< Power constraint, dBm */
  787. u8 erp_info; /**< ERP information flags */
  788. /** List of channels */
  789. struct ieee80211_ie_channels_channel_band channels[0];
  790. };
  791. };
  792. /** DS parameter set */
  793. struct ieee80211_ie_ds_param ds_param;
  794. /** Country information */
  795. struct ieee80211_ie_country country;
  796. /** Power capability */
  797. struct ieee80211_ie_power_capab power_capab;
  798. /** Security information */
  799. struct ieee80211_ie_rsn rsn;
  800. /** Vendor-specific */
  801. struct ieee80211_ie_vendor vendor;
  802. };
  803. /** Check that 802.11 information element is bounded by buffer
  804. *
  805. * @v ie Information element
  806. * @v end End of buffer in which information element is stored
  807. * @ret ok TRUE if the IE is completely contained within the buffer
  808. */
  809. static inline int ieee80211_ie_bound ( union ieee80211_ie *ie, void *end )
  810. {
  811. void *iep = ie;
  812. return ( iep + 2 <= end && iep + 2 + ie->len <= end );
  813. }
  814. /** Advance to next 802.11 information element
  815. *
  816. * @v ie Current information element pointer
  817. * @v end Pointer to first byte not in information element space
  818. * @ret next Pointer to next information element, or NULL if no more
  819. *
  820. * When processing received IEs, @a end should be set to the I/O
  821. * buffer tail pointer; when marshalling IEs for sending, @a end
  822. * should be NULL.
  823. */
  824. static inline union ieee80211_ie * ieee80211_next_ie ( union ieee80211_ie *ie,
  825. void *end )
  826. {
  827. void *next_ie_byte = ( void * ) ie + ie->len + 2;
  828. union ieee80211_ie *next_ie = next_ie_byte;
  829. if ( ! end )
  830. return next_ie;
  831. if ( ieee80211_ie_bound ( next_ie, end ) )
  832. return next_ie;
  833. return NULL;
  834. }
  835. /** @} */
  836. /* ---------- Management frame data formats ---------- */
  837. /**
  838. * @defgroup ieee80211_mgmt_data Management frame data payloads
  839. * @{
  840. */
  841. /** Beacon or probe response frame data */
  842. struct ieee80211_beacon_or_probe_resp
  843. {
  844. /** 802.11 TSFT value at frame send */
  845. u64 timestamp;
  846. /** Interval at which beacons are sent, in units of 1024 us */
  847. u16 beacon_interval;
  848. /** Capability flags */
  849. u16 capability;
  850. /** List of information elements */
  851. union ieee80211_ie info_element[0];
  852. } __attribute__((packed));
  853. #define ieee80211_beacon ieee80211_beacon_or_probe_resp
  854. #define ieee80211_probe_resp ieee80211_beacon_or_probe_resp
  855. /** Disassociation or deauthentication frame data */
  856. struct ieee80211_disassoc_or_deauth
  857. {
  858. /** Reason code */
  859. u16 reason;
  860. } __attribute__((packed));
  861. #define ieee80211_disassoc ieee80211_disassoc_or_deauth
  862. #define ieee80211_deauth ieee80211_disassoc_or_deauth
  863. /** Association request frame data */
  864. struct ieee80211_assoc_req
  865. {
  866. /** Capability flags */
  867. u16 capability;
  868. /** Interval at which we wake up, in units of the beacon interval */
  869. u16 listen_interval;
  870. /** List of information elements */
  871. union ieee80211_ie info_element[0];
  872. } __attribute__((packed));
  873. /** Association or reassociation response frame data */
  874. struct ieee80211_assoc_or_reassoc_resp
  875. {
  876. /** Capability flags */
  877. u16 capability;
  878. /** Status code */
  879. u16 status;
  880. /** Association ID */
  881. u16 aid;
  882. /** List of information elements */
  883. union ieee80211_ie info_element[0];
  884. } __attribute__((packed));
  885. #define ieee80211_assoc_resp ieee80211_assoc_or_reassoc_resp
  886. #define ieee80211_reassoc_resp ieee80211_assoc_or_reassoc_resp
  887. /** Reassociation request frame data */
  888. struct ieee80211_reassoc_req
  889. {
  890. /** Capability flags */
  891. u16 capability;
  892. /** Interval at which we wake up, in units of the beacon interval */
  893. u16 listen_interval;
  894. /** MAC address of current Access Point */
  895. u8 current_addr[ETH_ALEN];
  896. /** List of information elements */
  897. union ieee80211_ie info_element[0];
  898. } __attribute__((packed));
  899. /** Probe request frame data */
  900. struct ieee80211_probe_req
  901. {
  902. /** List of information elements */
  903. union ieee80211_ie info_element[0];
  904. } __attribute__((packed));
  905. /** Authentication frame data */
  906. struct ieee80211_auth
  907. {
  908. /** Authentication algorithm (Open System or Shared Key) */
  909. u16 algorithm;
  910. /** Sequence number of this frame; first from client to AP is 1 */
  911. u16 tx_seq;
  912. /** Status code */
  913. u16 status;
  914. /** List of information elements */
  915. union ieee80211_ie info_element[0];
  916. } __attribute__((packed));
  917. /** Open System authentication algorithm */
  918. #define IEEE80211_AUTH_OPEN_SYSTEM 0
  919. /** Shared Key authentication algorithm */
  920. #define IEEE80211_AUTH_SHARED_KEY 1
  921. /** @} */
  922. #endif