Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

ieee80211.h 36KB

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