ieee80211.h 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025
  1. /*
  2. * IEEE 802.11 defines
  3. *
  4. * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
  5. * <jkmaline@cc.hut.fi>
  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>
  9. *
  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.
  13. */
  14. #ifndef LINUX_IEEE80211_H
  15. #define LINUX_IEEE80211_H
  16. #include <linux/types.h>
  17. #include <asm/byteorder.h>
  18. /*
  19. * DS bit usage
  20. *
  21. * TA = transmitter address
  22. * RA = receiver address
  23. * DA = destination address
  24. * SA = source address
  25. *
  26. * ToDS FromDS A1(RA) A2(TA) A3 A4 Use
  27. * -----------------------------------------------------------------
  28. * 0 0 DA SA BSSID - IBSS/DLS
  29. * 0 1 DA BSSID SA - AP -> STA
  30. * 1 0 BSSID SA DA - AP <- STA
  31. * 1 1 RA TA DA SA unspecified (WDS)
  32. */
  33. #define FCS_LEN 4
  34. #define IEEE80211_FCTL_VERS 0x0003
  35. #define IEEE80211_FCTL_FTYPE 0x000c
  36. #define IEEE80211_FCTL_STYPE 0x00f0
  37. #define IEEE80211_FCTL_TODS 0x0100
  38. #define IEEE80211_FCTL_FROMDS 0x0200
  39. #define IEEE80211_FCTL_MOREFRAGS 0x0400
  40. #define IEEE80211_FCTL_RETRY 0x0800
  41. #define IEEE80211_FCTL_PM 0x1000
  42. #define IEEE80211_FCTL_MOREDATA 0x2000
  43. #define IEEE80211_FCTL_PROTECTED 0x4000
  44. #define IEEE80211_FCTL_ORDER 0x8000
  45. #define IEEE80211_SCTL_FRAG 0x000F
  46. #define IEEE80211_SCTL_SEQ 0xFFF0
  47. #define IEEE80211_FTYPE_MGMT 0x0000
  48. #define IEEE80211_FTYPE_CTL 0x0004
  49. #define IEEE80211_FTYPE_DATA 0x0008
  50. /* management */
  51. #define IEEE80211_STYPE_ASSOC_REQ 0x0000
  52. #define IEEE80211_STYPE_ASSOC_RESP 0x0010
  53. #define IEEE80211_STYPE_REASSOC_REQ 0x0020
  54. #define IEEE80211_STYPE_REASSOC_RESP 0x0030
  55. #define IEEE80211_STYPE_PROBE_REQ 0x0040
  56. #define IEEE80211_STYPE_PROBE_RESP 0x0050
  57. #define IEEE80211_STYPE_BEACON 0x0080
  58. #define IEEE80211_STYPE_ATIM 0x0090
  59. #define IEEE80211_STYPE_DISASSOC 0x00A0
  60. #define IEEE80211_STYPE_AUTH 0x00B0
  61. #define IEEE80211_STYPE_DEAUTH 0x00C0
  62. #define IEEE80211_STYPE_ACTION 0x00D0
  63. /* control */
  64. #define IEEE80211_STYPE_BACK_REQ 0x0080
  65. #define IEEE80211_STYPE_BACK 0x0090
  66. #define IEEE80211_STYPE_PSPOLL 0x00A0
  67. #define IEEE80211_STYPE_RTS 0x00B0
  68. #define IEEE80211_STYPE_CTS 0x00C0
  69. #define IEEE80211_STYPE_ACK 0x00D0
  70. #define IEEE80211_STYPE_CFEND 0x00E0
  71. #define IEEE80211_STYPE_CFENDACK 0x00F0
  72. /* data */
  73. #define IEEE80211_STYPE_DATA 0x0000
  74. #define IEEE80211_STYPE_DATA_CFACK 0x0010
  75. #define IEEE80211_STYPE_DATA_CFPOLL 0x0020
  76. #define IEEE80211_STYPE_DATA_CFACKPOLL 0x0030
  77. #define IEEE80211_STYPE_NULLFUNC 0x0040
  78. #define IEEE80211_STYPE_CFACK 0x0050
  79. #define IEEE80211_STYPE_CFPOLL 0x0060
  80. #define IEEE80211_STYPE_CFACKPOLL 0x0070
  81. #define IEEE80211_STYPE_QOS_DATA 0x0080
  82. #define IEEE80211_STYPE_QOS_DATA_CFACK 0x0090
  83. #define IEEE80211_STYPE_QOS_DATA_CFPOLL 0x00A0
  84. #define IEEE80211_STYPE_QOS_DATA_CFACKPOLL 0x00B0
  85. #define IEEE80211_STYPE_QOS_NULLFUNC 0x00C0
  86. #define IEEE80211_STYPE_QOS_CFACK 0x00D0
  87. #define IEEE80211_STYPE_QOS_CFPOLL 0x00E0
  88. #define IEEE80211_STYPE_QOS_CFACKPOLL 0x00F0
  89. /* miscellaneous IEEE 802.11 constants */
  90. #define IEEE80211_MAX_FRAG_THRESHOLD 2352
  91. #define IEEE80211_MAX_RTS_THRESHOLD 2353
  92. #define IEEE80211_MAX_AID 2007
  93. #define IEEE80211_MAX_TIM_LEN 251
  94. /* Maximum size for the MA-UNITDATA primitive, 802.11 standard section
  95. 6.2.1.1.2.
  96. 802.11e clarifies the figure in section 7.1.2. The frame body is
  97. up to 2304 octets long (maximum MSDU size) plus any crypt overhead. */
  98. #define IEEE80211_MAX_DATA_LEN 2304
  99. /* 30 byte 4 addr hdr, 2 byte QoS, 2304 byte MSDU, 12 byte crypt, 4 byte FCS */
  100. #define IEEE80211_MAX_FRAME_LEN 2352
  101. #define IEEE80211_MAX_SSID_LEN 32
  102. #define IEEE80211_MAX_MESH_ID_LEN 32
  103. #define IEEE80211_QOS_CTL_LEN 2
  104. /* 1d tag mask */
  105. #define IEEE80211_QOS_CTL_TAG1D_MASK 0x0007
  106. /* TID mask */
  107. #define IEEE80211_QOS_CTL_TID_MASK 0x000f
  108. /* EOSP */
  109. #define IEEE80211_QOS_CTL_EOSP 0x0010
  110. /* ACK policy */
  111. #define IEEE80211_QOS_CTL_ACK_POLICY_NORMAL 0x0000
  112. #define IEEE80211_QOS_CTL_ACK_POLICY_NOACK 0x0020
  113. #define IEEE80211_QOS_CTL_ACK_POLICY_NO_EXPL 0x0040
  114. #define IEEE80211_QOS_CTL_ACK_POLICY_BLOCKACK 0x0060
  115. #define IEEE80211_QOS_CTL_ACK_POLICY_MASK 0x0060
  116. /* A-MSDU 802.11n */
  117. #define IEEE80211_QOS_CTL_A_MSDU_PRESENT 0x0080
  118. /* Mesh Control 802.11s */
  119. #define IEEE80211_QOS_CTL_MESH_CONTROL_PRESENT 0x0100
  120. /* U-APSD queue for WMM IEs sent by AP */
  121. #define IEEE80211_WMM_IE_AP_QOSINFO_UAPSD (1<<7)
  122. #define IEEE80211_WMM_IE_AP_QOSINFO_PARAM_SET_CNT_MASK 0x0f
  123. /* U-APSD queues for WMM IEs sent by STA */
  124. #define IEEE80211_WMM_IE_STA_QOSINFO_AC_VO (1<<0)
  125. #define IEEE80211_WMM_IE_STA_QOSINFO_AC_VI (1<<1)
  126. #define IEEE80211_WMM_IE_STA_QOSINFO_AC_BK (1<<2)
  127. #define IEEE80211_WMM_IE_STA_QOSINFO_AC_BE (1<<3)
  128. #define IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK 0x0f
  129. /* U-APSD max SP length for WMM IEs sent by STA */
  130. #define IEEE80211_WMM_IE_STA_QOSINFO_SP_ALL 0x00
  131. #define IEEE80211_WMM_IE_STA_QOSINFO_SP_2 0x01
  132. #define IEEE80211_WMM_IE_STA_QOSINFO_SP_4 0x02
  133. #define IEEE80211_WMM_IE_STA_QOSINFO_SP_6 0x03
  134. #define IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK 0x03
  135. #define IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT 5
  136. #define IEEE80211_HT_CTL_LEN 4
  137. struct ieee80211_hdr {
  138. __le16 frame_control;
  139. __le16 duration_id;
  140. u8 addr1[6];
  141. u8 addr2[6];
  142. u8 addr3[6];
  143. __le16 seq_ctrl;
  144. u8 addr4[6];
  145. } __attribute__ ((packed));
  146. struct ieee80211_hdr_3addr {
  147. __le16 frame_control;
  148. __le16 duration_id;
  149. u8 addr1[6];
  150. u8 addr2[6];
  151. u8 addr3[6];
  152. __le16 seq_ctrl;
  153. } __attribute__ ((packed));
  154. struct ieee80211_qos_hdr {
  155. __le16 frame_control;
  156. __le16 duration_id;
  157. u8 addr1[6];
  158. u8 addr2[6];
  159. u8 addr3[6];
  160. __le16 seq_ctrl;
  161. __le16 qos_ctrl;
  162. } __attribute__ ((packed));
  163. /**
  164. * ieee80211_has_tods - check if IEEE80211_FCTL_TODS is set
  165. * @fc: frame control bytes in little-endian byteorder
  166. */
  167. static inline int ieee80211_has_tods(__le16 fc)
  168. {
  169. return (fc & cpu_to_le16(IEEE80211_FCTL_TODS)) != 0;
  170. }
  171. /**
  172. * ieee80211_has_fromds - check if IEEE80211_FCTL_FROMDS is set
  173. * @fc: frame control bytes in little-endian byteorder
  174. */
  175. static inline int ieee80211_has_fromds(__le16 fc)
  176. {
  177. return (fc & cpu_to_le16(IEEE80211_FCTL_FROMDS)) != 0;
  178. }
  179. /**
  180. * ieee80211_has_a4 - check if IEEE80211_FCTL_TODS and IEEE80211_FCTL_FROMDS are set
  181. * @fc: frame control bytes in little-endian byteorder
  182. */
  183. static inline int ieee80211_has_a4(__le16 fc)
  184. {
  185. __le16 tmp = cpu_to_le16(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS);
  186. return (fc & tmp) == tmp;
  187. }
  188. /**
  189. * ieee80211_has_morefrags - check if IEEE80211_FCTL_MOREFRAGS is set
  190. * @fc: frame control bytes in little-endian byteorder
  191. */
  192. static inline int ieee80211_has_morefrags(__le16 fc)
  193. {
  194. return (fc & cpu_to_le16(IEEE80211_FCTL_MOREFRAGS)) != 0;
  195. }
  196. /**
  197. * ieee80211_has_retry - check if IEEE80211_FCTL_RETRY is set
  198. * @fc: frame control bytes in little-endian byteorder
  199. */
  200. static inline int ieee80211_has_retry(__le16 fc)
  201. {
  202. return (fc & cpu_to_le16(IEEE80211_FCTL_RETRY)) != 0;
  203. }
  204. /**
  205. * ieee80211_has_pm - check if IEEE80211_FCTL_PM is set
  206. * @fc: frame control bytes in little-endian byteorder
  207. */
  208. static inline int ieee80211_has_pm(__le16 fc)
  209. {
  210. return (fc & cpu_to_le16(IEEE80211_FCTL_PM)) != 0;
  211. }
  212. /**
  213. * ieee80211_has_moredata - check if IEEE80211_FCTL_MOREDATA is set
  214. * @fc: frame control bytes in little-endian byteorder
  215. */
  216. static inline int ieee80211_has_moredata(__le16 fc)
  217. {
  218. return (fc & cpu_to_le16(IEEE80211_FCTL_MOREDATA)) != 0;
  219. }
  220. /**
  221. * ieee80211_has_protected - check if IEEE80211_FCTL_PROTECTED is set
  222. * @fc: frame control bytes in little-endian byteorder
  223. */
  224. static inline int ieee80211_has_protected(__le16 fc)
  225. {
  226. return (fc & cpu_to_le16(IEEE80211_FCTL_PROTECTED)) != 0;
  227. }
  228. /**
  229. * ieee80211_has_order - check if IEEE80211_FCTL_ORDER is set
  230. * @fc: frame control bytes in little-endian byteorder
  231. */
  232. static inline int ieee80211_has_order(__le16 fc)
  233. {
  234. return (fc & cpu_to_le16(IEEE80211_FCTL_ORDER)) != 0;
  235. }
  236. /**
  237. * ieee80211_is_mgmt - check if type is IEEE80211_FTYPE_MGMT
  238. * @fc: frame control bytes in little-endian byteorder
  239. */
  240. static inline int ieee80211_is_mgmt(__le16 fc)
  241. {
  242. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE)) ==
  243. cpu_to_le16(IEEE80211_FTYPE_MGMT);
  244. }
  245. /**
  246. * ieee80211_is_ctl - check if type is IEEE80211_FTYPE_CTL
  247. * @fc: frame control bytes in little-endian byteorder
  248. */
  249. static inline int ieee80211_is_ctl(__le16 fc)
  250. {
  251. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE)) ==
  252. cpu_to_le16(IEEE80211_FTYPE_CTL);
  253. }
  254. /**
  255. * ieee80211_is_data - check if type is IEEE80211_FTYPE_DATA
  256. * @fc: frame control bytes in little-endian byteorder
  257. */
  258. static inline int ieee80211_is_data(__le16 fc)
  259. {
  260. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE)) ==
  261. cpu_to_le16(IEEE80211_FTYPE_DATA);
  262. }
  263. /**
  264. * ieee80211_is_data_qos - check if type is IEEE80211_FTYPE_DATA and IEEE80211_STYPE_QOS_DATA is set
  265. * @fc: frame control bytes in little-endian byteorder
  266. */
  267. static inline int ieee80211_is_data_qos(__le16 fc)
  268. {
  269. /*
  270. * mask with QOS_DATA rather than IEEE80211_FCTL_STYPE as we just need
  271. * to check the one bit
  272. */
  273. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_STYPE_QOS_DATA)) ==
  274. cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_QOS_DATA);
  275. }
  276. /**
  277. * ieee80211_is_data_present - check if type is IEEE80211_FTYPE_DATA and has data
  278. * @fc: frame control bytes in little-endian byteorder
  279. */
  280. static inline int ieee80211_is_data_present(__le16 fc)
  281. {
  282. /*
  283. * mask with 0x40 and test that that bit is clear to only return true
  284. * for the data-containing substypes.
  285. */
  286. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | 0x40)) ==
  287. cpu_to_le16(IEEE80211_FTYPE_DATA);
  288. }
  289. /**
  290. * ieee80211_is_assoc_req - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_ASSOC_REQ
  291. * @fc: frame control bytes in little-endian byteorder
  292. */
  293. static inline int ieee80211_is_assoc_req(__le16 fc)
  294. {
  295. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
  296. cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ASSOC_REQ);
  297. }
  298. /**
  299. * ieee80211_is_assoc_resp - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_ASSOC_RESP
  300. * @fc: frame control bytes in little-endian byteorder
  301. */
  302. static inline int ieee80211_is_assoc_resp(__le16 fc)
  303. {
  304. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
  305. cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ASSOC_RESP);
  306. }
  307. /**
  308. * ieee80211_is_reassoc_req - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_REASSOC_REQ
  309. * @fc: frame control bytes in little-endian byteorder
  310. */
  311. static inline int ieee80211_is_reassoc_req(__le16 fc)
  312. {
  313. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
  314. cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_REASSOC_REQ);
  315. }
  316. /**
  317. * ieee80211_is_reassoc_resp - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_REASSOC_RESP
  318. * @fc: frame control bytes in little-endian byteorder
  319. */
  320. static inline int ieee80211_is_reassoc_resp(__le16 fc)
  321. {
  322. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
  323. cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_REASSOC_RESP);
  324. }
  325. /**
  326. * ieee80211_is_probe_req - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_PROBE_REQ
  327. * @fc: frame control bytes in little-endian byteorder
  328. */
  329. static inline int ieee80211_is_probe_req(__le16 fc)
  330. {
  331. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
  332. cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ);
  333. }
  334. /**
  335. * ieee80211_is_probe_resp - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_PROBE_RESP
  336. * @fc: frame control bytes in little-endian byteorder
  337. */
  338. static inline int ieee80211_is_probe_resp(__le16 fc)
  339. {
  340. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
  341. cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_RESP);
  342. }
  343. /**
  344. * ieee80211_is_beacon - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_BEACON
  345. * @fc: frame control bytes in little-endian byteorder
  346. */
  347. static inline int ieee80211_is_beacon(__le16 fc)
  348. {
  349. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
  350. cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_BEACON);
  351. }
  352. /**
  353. * ieee80211_is_atim - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_ATIM
  354. * @fc: frame control bytes in little-endian byteorder
  355. */
  356. static inline int ieee80211_is_atim(__le16 fc)
  357. {
  358. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
  359. cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ATIM);
  360. }
  361. /**
  362. * ieee80211_is_disassoc - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_DISASSOC
  363. * @fc: frame control bytes in little-endian byteorder
  364. */
  365. static inline int ieee80211_is_disassoc(__le16 fc)
  366. {
  367. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
  368. cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_DISASSOC);
  369. }
  370. /**
  371. * ieee80211_is_auth - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_AUTH
  372. * @fc: frame control bytes in little-endian byteorder
  373. */
  374. static inline int ieee80211_is_auth(__le16 fc)
  375. {
  376. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
  377. cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_AUTH);
  378. }
  379. /**
  380. * ieee80211_is_deauth - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_DEAUTH
  381. * @fc: frame control bytes in little-endian byteorder
  382. */
  383. static inline int ieee80211_is_deauth(__le16 fc)
  384. {
  385. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
  386. cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_DEAUTH);
  387. }
  388. /**
  389. * ieee80211_is_action - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_ACTION
  390. * @fc: frame control bytes in little-endian byteorder
  391. */
  392. static inline int ieee80211_is_action(__le16 fc)
  393. {
  394. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
  395. cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION);
  396. }
  397. /**
  398. * ieee80211_is_back_req - check if IEEE80211_FTYPE_CTL && IEEE80211_STYPE_BACK_REQ
  399. * @fc: frame control bytes in little-endian byteorder
  400. */
  401. static inline int ieee80211_is_back_req(__le16 fc)
  402. {
  403. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
  404. cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_BACK_REQ);
  405. }
  406. /**
  407. * ieee80211_is_back - check if IEEE80211_FTYPE_CTL && IEEE80211_STYPE_BACK
  408. * @fc: frame control bytes in little-endian byteorder
  409. */
  410. static inline int ieee80211_is_back(__le16 fc)
  411. {
  412. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
  413. cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_BACK);
  414. }
  415. /**
  416. * ieee80211_is_pspoll - check if IEEE80211_FTYPE_CTL && IEEE80211_STYPE_PSPOLL
  417. * @fc: frame control bytes in little-endian byteorder
  418. */
  419. static inline int ieee80211_is_pspoll(__le16 fc)
  420. {
  421. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
  422. cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_PSPOLL);
  423. }
  424. /**
  425. * ieee80211_is_rts - check if IEEE80211_FTYPE_CTL && IEEE80211_STYPE_RTS
  426. * @fc: frame control bytes in little-endian byteorder
  427. */
  428. static inline int ieee80211_is_rts(__le16 fc)
  429. {
  430. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
  431. cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
  432. }
  433. /**
  434. * ieee80211_is_cts - check if IEEE80211_FTYPE_CTL && IEEE80211_STYPE_CTS
  435. * @fc: frame control bytes in little-endian byteorder
  436. */
  437. static inline int ieee80211_is_cts(__le16 fc)
  438. {
  439. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
  440. cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
  441. }
  442. /**
  443. * ieee80211_is_ack - check if IEEE80211_FTYPE_CTL && IEEE80211_STYPE_ACK
  444. * @fc: frame control bytes in little-endian byteorder
  445. */
  446. static inline int ieee80211_is_ack(__le16 fc)
  447. {
  448. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
  449. cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_ACK);
  450. }
  451. /**
  452. * ieee80211_is_cfend - check if IEEE80211_FTYPE_CTL && IEEE80211_STYPE_CFEND
  453. * @fc: frame control bytes in little-endian byteorder
  454. */
  455. static inline int ieee80211_is_cfend(__le16 fc)
  456. {
  457. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
  458. cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CFEND);
  459. }
  460. /**
  461. * ieee80211_is_cfendack - check if IEEE80211_FTYPE_CTL && IEEE80211_STYPE_CFENDACK
  462. * @fc: frame control bytes in little-endian byteorder
  463. */
  464. static inline int ieee80211_is_cfendack(__le16 fc)
  465. {
  466. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
  467. cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CFENDACK);
  468. }
  469. /**
  470. * ieee80211_is_nullfunc - check if frame is a regular (non-QoS) nullfunc frame
  471. * @fc: frame control bytes in little-endian byteorder
  472. */
  473. static inline int ieee80211_is_nullfunc(__le16 fc)
  474. {
  475. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
  476. cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC);
  477. }
  478. /**
  479. * ieee80211_is_qos_nullfunc - check if frame is a QoS nullfunc frame
  480. * @fc: frame control bytes in little-endian byteorder
  481. */
  482. static inline int ieee80211_is_qos_nullfunc(__le16 fc)
  483. {
  484. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
  485. cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_QOS_NULLFUNC);
  486. }
  487. /**
  488. * ieee80211_is_first_frag - check if IEEE80211_SCTL_FRAG is not set
  489. * @seq_ctrl: frame sequence control bytes in little-endian byteorder
  490. */
  491. static inline int ieee80211_is_first_frag(__le16 seq_ctrl)
  492. {
  493. return (seq_ctrl & cpu_to_le16(IEEE80211_SCTL_FRAG)) == 0;
  494. }
  495. struct ieee80211s_hdr {
  496. u8 flags;
  497. u8 ttl;
  498. __le32 seqnum;
  499. u8 eaddr1[6];
  500. u8 eaddr2[6];
  501. } __attribute__ ((packed));
  502. /* Mesh flags */
  503. #define MESH_FLAGS_AE_A4 0x1
  504. #define MESH_FLAGS_AE_A5_A6 0x2
  505. #define MESH_FLAGS_AE 0x3
  506. #define MESH_FLAGS_PS_DEEP 0x4
  507. /**
  508. * struct ieee80211_quiet_ie
  509. *
  510. * This structure refers to "Quiet information element"
  511. */
  512. struct ieee80211_quiet_ie {
  513. u8 count;
  514. u8 period;
  515. __le16 duration;
  516. __le16 offset;
  517. } __attribute__ ((packed));
  518. /**
  519. * struct ieee80211_msrment_ie
  520. *
  521. * This structure refers to "Measurement Request/Report information element"
  522. */
  523. struct ieee80211_msrment_ie {
  524. u8 token;
  525. u8 mode;
  526. u8 type;
  527. u8 request[0];
  528. } __attribute__ ((packed));
  529. /**
  530. * struct ieee80211_channel_sw_ie
  531. *
  532. * This structure refers to "Channel Switch Announcement information element"
  533. */
  534. struct ieee80211_channel_sw_ie {
  535. u8 mode;
  536. u8 new_ch_num;
  537. u8 count;
  538. } __attribute__ ((packed));
  539. /**
  540. * struct ieee80211_tim
  541. *
  542. * This structure refers to "Traffic Indication Map information element"
  543. */
  544. struct ieee80211_tim_ie {
  545. u8 dtim_count;
  546. u8 dtim_period;
  547. u8 bitmap_ctrl;
  548. /* variable size: 1 - 251 bytes */
  549. u8 virtual_map[1];
  550. } __attribute__ ((packed));
  551. /**
  552. * struct ieee80211_meshconf_ie
  553. *
  554. * This structure refers to "Mesh Configuration information element"
  555. */
  556. struct ieee80211_meshconf_ie {
  557. u8 meshconf_psel;
  558. u8 meshconf_pmetric;
  559. u8 meshconf_congest;
  560. u8 meshconf_synch;
  561. u8 meshconf_auth;
  562. u8 meshconf_form;
  563. u8 meshconf_cap;
  564. } __attribute__ ((packed));
  565. /**
  566. * struct ieee80211_rann_ie
  567. *
  568. * This structure refers to "Root Announcement information element"
  569. */
  570. struct ieee80211_rann_ie {
  571. u8 rann_flags;
  572. u8 rann_hopcount;
  573. u8 rann_ttl;
  574. u8 rann_addr[6];
  575. u32 rann_seq;
  576. u32 rann_interval;
  577. u32 rann_metric;
  578. } __attribute__ ((packed));
  579. enum ieee80211_rann_flags {
  580. RANN_FLAG_IS_GATE = 1 << 0,
  581. };
  582. #define WLAN_SA_QUERY_TR_ID_LEN 2
  583. struct ieee80211_mgmt {
  584. __le16 frame_control;
  585. __le16 duration;
  586. u8 da[6];
  587. u8 sa[6];
  588. u8 bssid[6];
  589. __le16 seq_ctrl;
  590. union {
  591. struct {
  592. __le16 auth_alg;
  593. __le16 auth_transaction;
  594. __le16 status_code;
  595. /* possibly followed by Challenge text */
  596. u8 variable[0];
  597. } __attribute__ ((packed)) auth;
  598. struct {
  599. __le16 reason_code;
  600. } __attribute__ ((packed)) deauth;
  601. struct {
  602. __le16 capab_info;
  603. __le16 listen_interval;
  604. /* followed by SSID and Supported rates */
  605. u8 variable[0];
  606. } __attribute__ ((packed)) assoc_req;
  607. struct {
  608. __le16 capab_info;
  609. __le16 status_code;
  610. __le16 aid;
  611. /* followed by Supported rates */
  612. u8 variable[0];
  613. } __attribute__ ((packed)) assoc_resp, reassoc_resp;
  614. struct {
  615. __le16 capab_info;
  616. __le16 listen_interval;
  617. u8 current_ap[6];
  618. /* followed by SSID and Supported rates */
  619. u8 variable[0];
  620. } __attribute__ ((packed)) reassoc_req;
  621. struct {
  622. __le16 reason_code;
  623. } __attribute__ ((packed)) disassoc;
  624. struct {
  625. __le64 timestamp;
  626. __le16 beacon_int;
  627. __le16 capab_info;
  628. /* followed by some of SSID, Supported rates,
  629. * FH Params, DS Params, CF Params, IBSS Params, TIM */
  630. u8 variable[0];
  631. } __attribute__ ((packed)) beacon;
  632. struct {
  633. /* only variable items: SSID, Supported rates */
  634. u8 variable[0];
  635. } __attribute__ ((packed)) probe_req;
  636. struct {
  637. __le64 timestamp;
  638. __le16 beacon_int;
  639. __le16 capab_info;
  640. /* followed by some of SSID, Supported rates,
  641. * FH Params, DS Params, CF Params, IBSS Params */
  642. u8 variable[0];
  643. } __attribute__ ((packed)) probe_resp;
  644. struct {
  645. u8 category;
  646. union {
  647. struct {
  648. u8 action_code;
  649. u8 dialog_token;
  650. u8 status_code;
  651. u8 variable[0];
  652. } __attribute__ ((packed)) wme_action;
  653. struct{
  654. u8 action_code;
  655. u8 element_id;
  656. u8 length;
  657. struct ieee80211_channel_sw_ie sw_elem;
  658. } __attribute__((packed)) chan_switch;
  659. struct{
  660. u8 action_code;
  661. u8 dialog_token;
  662. u8 element_id;
  663. u8 length;
  664. struct ieee80211_msrment_ie msr_elem;
  665. } __attribute__((packed)) measurement;
  666. struct{
  667. u8 action_code;
  668. u8 dialog_token;
  669. __le16 capab;
  670. __le16 timeout;
  671. __le16 start_seq_num;
  672. } __attribute__((packed)) addba_req;
  673. struct{
  674. u8 action_code;
  675. u8 dialog_token;
  676. __le16 status;
  677. __le16 capab;
  678. __le16 timeout;
  679. } __attribute__((packed)) addba_resp;
  680. struct{
  681. u8 action_code;
  682. __le16 params;
  683. __le16 reason_code;
  684. } __attribute__((packed)) delba;
  685. struct {
  686. u8 action_code;
  687. u8 variable[0];
  688. } __attribute__((packed)) self_prot;
  689. struct{
  690. u8 action_code;
  691. u8 variable[0];
  692. } __attribute__((packed)) mesh_action;
  693. struct {
  694. u8 action;
  695. u8 trans_id[WLAN_SA_QUERY_TR_ID_LEN];
  696. } __attribute__ ((packed)) sa_query;
  697. struct {
  698. u8 action;
  699. u8 smps_control;
  700. } __attribute__ ((packed)) ht_smps;
  701. struct {
  702. u8 action_code;
  703. u8 dialog_token;
  704. __le16 capability;
  705. u8 variable[0];
  706. } __packed tdls_discover_resp;
  707. } u;
  708. } __attribute__ ((packed)) action;
  709. } u;
  710. } __attribute__ ((packed));
  711. /* Supported Rates value encodings in 802.11n-2009 7.3.2.2 */
  712. #define BSS_MEMBERSHIP_SELECTOR_HT_PHY 127
  713. /* mgmt header + 1 byte category code */
  714. #define IEEE80211_MIN_ACTION_SIZE offsetof(struct ieee80211_mgmt, u.action.u)
  715. /* Management MIC information element (IEEE 802.11w) */
  716. struct ieee80211_mmie {
  717. u8 element_id;
  718. u8 length;
  719. __le16 key_id;
  720. u8 sequence_number[6];
  721. u8 mic[8];
  722. } __attribute__ ((packed));
  723. struct ieee80211_vendor_ie {
  724. u8 element_id;
  725. u8 len;
  726. u8 oui[3];
  727. u8 oui_type;
  728. } __packed;
  729. /* Control frames */
  730. struct ieee80211_rts {
  731. __le16 frame_control;
  732. __le16 duration;
  733. u8 ra[6];
  734. u8 ta[6];
  735. } __attribute__ ((packed));
  736. struct ieee80211_cts {
  737. __le16 frame_control;
  738. __le16 duration;
  739. u8 ra[6];
  740. } __attribute__ ((packed));
  741. struct ieee80211_pspoll {
  742. __le16 frame_control;
  743. __le16 aid;
  744. u8 bssid[6];
  745. u8 ta[6];
  746. } __attribute__ ((packed));
  747. /* TDLS */
  748. /* Link-id information element */
  749. struct ieee80211_tdls_lnkie {
  750. u8 ie_type; /* Link Identifier IE */
  751. u8 ie_len;
  752. u8 bssid[6];
  753. u8 init_sta[6];
  754. u8 resp_sta[6];
  755. } __packed;
  756. struct ieee80211_tdls_data {
  757. u8 da[6];
  758. u8 sa[6];
  759. __be16 ether_type;
  760. u8 payload_type;
  761. u8 category;
  762. u8 action_code;
  763. union {
  764. struct {
  765. u8 dialog_token;
  766. __le16 capability;
  767. u8 variable[0];
  768. } __packed setup_req;
  769. struct {
  770. __le16 status_code;
  771. u8 dialog_token;
  772. __le16 capability;
  773. u8 variable[0];
  774. } __packed setup_resp;
  775. struct {
  776. __le16 status_code;
  777. u8 dialog_token;
  778. u8 variable[0];
  779. } __packed setup_cfm;
  780. struct {
  781. __le16 reason_code;
  782. u8 variable[0];
  783. } __packed teardown;
  784. struct {
  785. u8 dialog_token;
  786. u8 variable[0];
  787. } __packed discover_req;
  788. } u;
  789. } __packed;
  790. /**
  791. * struct ieee80211_bar - HT Block Ack Request
  792. *
  793. * This structure refers to "HT BlockAckReq" as
  794. * described in 802.11n draft section 7.2.1.7.1
  795. */
  796. struct ieee80211_bar {
  797. __le16 frame_control;
  798. __le16 duration;
  799. __u8 ra[6];
  800. __u8 ta[6];
  801. __le16 control;
  802. __le16 start_seq_num;
  803. } __attribute__((packed));
  804. /* 802.11 BAR control masks */
  805. #define IEEE80211_BAR_CTRL_ACK_POLICY_NORMAL 0x0000
  806. #define IEEE80211_BAR_CTRL_MULTI_TID 0x0002
  807. #define IEEE80211_BAR_CTRL_CBMTID_COMPRESSED_BA 0x0004
  808. #define IEEE80211_BAR_CTRL_TID_INFO_MASK 0xf000
  809. #define IEEE80211_BAR_CTRL_TID_INFO_SHIFT 12
  810. #define IEEE80211_HT_MCS_MASK_LEN 10
  811. /**
  812. * struct ieee80211_mcs_info - MCS information
  813. * @rx_mask: RX mask
  814. * @rx_highest: highest supported RX rate. If set represents
  815. * the highest supported RX data rate in units of 1 Mbps.
  816. * If this field is 0 this value should not be used to
  817. * consider the highest RX data rate supported.
  818. * @tx_params: TX parameters
  819. */
  820. struct ieee80211_mcs_info {
  821. u8 rx_mask[IEEE80211_HT_MCS_MASK_LEN];
  822. __le16 rx_highest;
  823. u8 tx_params;
  824. u8 reserved[3];
  825. } __attribute__((packed));
  826. /* 802.11n HT capability MSC set */
  827. #define IEEE80211_HT_MCS_RX_HIGHEST_MASK 0x3ff
  828. #define IEEE80211_HT_MCS_TX_DEFINED 0x01
  829. #define IEEE80211_HT_MCS_TX_RX_DIFF 0x02
  830. /* value 0 == 1 stream etc */
  831. #define IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK 0x0C
  832. #define IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT 2
  833. #define IEEE80211_HT_MCS_TX_MAX_STREAMS 4
  834. #define IEEE80211_HT_MCS_TX_UNEQUAL_MODULATION 0x10
  835. /*
  836. * 802.11n D5.0 20.3.5 / 20.6 says:
  837. * - indices 0 to 7 and 32 are single spatial stream
  838. * - 8 to 31 are multiple spatial streams using equal modulation
  839. * [8..15 for two streams, 16..23 for three and 24..31 for four]
  840. * - remainder are multiple spatial streams using unequal modulation
  841. */
  842. #define IEEE80211_HT_MCS_UNEQUAL_MODULATION_START 33
  843. #define IEEE80211_HT_MCS_UNEQUAL_MODULATION_START_BYTE \
  844. (IEEE80211_HT_MCS_UNEQUAL_MODULATION_START / 8)
  845. /**
  846. * struct ieee80211_ht_cap - HT capabilities
  847. *
  848. * This structure is the "HT capabilities element" as
  849. * described in 802.11n D5.0 7.3.2.57
  850. */
  851. struct ieee80211_ht_cap {
  852. __le16 cap_info;
  853. u8 ampdu_params_info;
  854. /* 16 bytes MCS information */
  855. struct ieee80211_mcs_info mcs;
  856. __le16 extended_ht_cap_info;
  857. __le32 tx_BF_cap_info;
  858. u8 antenna_selection_info;
  859. } __attribute__ ((packed));
  860. /* 802.11n HT capabilities masks (for cap_info) */
  861. #define IEEE80211_HT_CAP_LDPC_CODING 0x0001
  862. #define IEEE80211_HT_CAP_SUP_WIDTH_20_40 0x0002
  863. #define IEEE80211_HT_CAP_SM_PS 0x000C
  864. #define IEEE80211_HT_CAP_SM_PS_SHIFT 2
  865. #define IEEE80211_HT_CAP_GRN_FLD 0x0010
  866. #define IEEE80211_HT_CAP_SGI_20 0x0020
  867. #define IEEE80211_HT_CAP_SGI_40 0x0040
  868. #define IEEE80211_HT_CAP_TX_STBC 0x0080
  869. #define IEEE80211_HT_CAP_RX_STBC 0x0300
  870. #define IEEE80211_HT_CAP_RX_STBC_SHIFT 8
  871. #define IEEE80211_HT_CAP_DELAY_BA 0x0400
  872. #define IEEE80211_HT_CAP_MAX_AMSDU 0x0800
  873. #define IEEE80211_HT_CAP_DSSSCCK40 0x1000
  874. #define IEEE80211_HT_CAP_RESERVED 0x2000
  875. #define IEEE80211_HT_CAP_40MHZ_INTOLERANT 0x4000
  876. #define IEEE80211_HT_CAP_LSIG_TXOP_PROT 0x8000
  877. /* 802.11n HT extended capabilities masks (for extended_ht_cap_info) */
  878. #define IEEE80211_HT_EXT_CAP_PCO 0x0001
  879. #define IEEE80211_HT_EXT_CAP_PCO_TIME 0x0006
  880. #define IEEE80211_HT_EXT_CAP_PCO_TIME_SHIFT 1
  881. #define IEEE80211_HT_EXT_CAP_MCS_FB 0x0300
  882. #define IEEE80211_HT_EXT_CAP_MCS_FB_SHIFT 8
  883. #define IEEE80211_HT_EXT_CAP_HTC_SUP 0x0400
  884. #define IEEE80211_HT_EXT_CAP_RD_RESPONDER 0x0800
  885. /* 802.11n HT capability AMPDU settings (for ampdu_params_info) */
  886. #define IEEE80211_HT_AMPDU_PARM_FACTOR 0x03
  887. #define IEEE80211_HT_AMPDU_PARM_DENSITY 0x1C
  888. #define IEEE80211_HT_AMPDU_PARM_DENSITY_SHIFT 2
  889. /*
  890. * Maximum length of AMPDU that the STA can receive.
  891. * Length = 2 ^ (13 + max_ampdu_length_exp) - 1 (octets)
  892. */
  893. enum ieee80211_max_ampdu_length_exp {
  894. IEEE80211_HT_MAX_AMPDU_8K = 0,
  895. IEEE80211_HT_MAX_AMPDU_16K = 1,
  896. IEEE80211_HT_MAX_AMPDU_32K = 2,
  897. IEEE80211_HT_MAX_AMPDU_64K = 3
  898. };
  899. #define IEEE80211_HT_MAX_AMPDU_FACTOR 13
  900. /* Minimum MPDU start spacing */
  901. enum ieee80211_min_mpdu_spacing {
  902. IEEE80211_HT_MPDU_DENSITY_NONE = 0, /* No restriction */
  903. IEEE80211_HT_MPDU_DENSITY_0_25 = 1, /* 1/4 usec */
  904. IEEE80211_HT_MPDU_DENSITY_0_5 = 2, /* 1/2 usec */
  905. IEEE80211_HT_MPDU_DENSITY_1 = 3, /* 1 usec */
  906. IEEE80211_HT_MPDU_DENSITY_2 = 4, /* 2 usec */
  907. IEEE80211_HT_MPDU_DENSITY_4 = 5, /* 4 usec */
  908. IEEE80211_HT_MPDU_DENSITY_8 = 6, /* 8 usec */
  909. IEEE80211_HT_MPDU_DENSITY_16 = 7 /* 16 usec */
  910. };
  911. /**
  912. * struct ieee80211_ht_info - HT information
  913. *
  914. * This structure is the "HT information element" as
  915. * described in 802.11n D5.0 7.3.2.58
  916. */
  917. struct ieee80211_ht_info {
  918. u8 control_chan;
  919. u8 ht_param;
  920. __le16 operation_mode;
  921. __le16 stbc_param;
  922. u8 basic_set[16];
  923. } __attribute__ ((packed));
  924. /* for ht_param */
  925. #define IEEE80211_HT_PARAM_CHA_SEC_OFFSET 0x03
  926. #define IEEE80211_HT_PARAM_CHA_SEC_NONE 0x00
  927. #define IEEE80211_HT_PARAM_CHA_SEC_ABOVE 0x01
  928. #define IEEE80211_HT_PARAM_CHA_SEC_BELOW 0x03
  929. #define IEEE80211_HT_PARAM_CHAN_WIDTH_ANY 0x04
  930. #define IEEE80211_HT_PARAM_RIFS_MODE 0x08
  931. #define IEEE80211_HT_PARAM_SPSMP_SUPPORT 0x10
  932. #define IEEE80211_HT_PARAM_SERV_INTERVAL_GRAN 0xE0
  933. /* for operation_mode */
  934. #define IEEE80211_HT_OP_MODE_PROTECTION 0x0003
  935. #define IEEE80211_HT_OP_MODE_PROTECTION_NONE 0
  936. #define IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER 1
  937. #define IEEE80211_HT_OP_MODE_PROTECTION_20MHZ 2
  938. #define IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED 3
  939. #define IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT 0x0004
  940. #define IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT 0x0010
  941. /* for stbc_param */
  942. #define IEEE80211_HT_STBC_PARAM_DUAL_BEACON 0x0040
  943. #define IEEE80211_HT_STBC_PARAM_DUAL_CTS_PROT 0x0080
  944. #define IEEE80211_HT_STBC_PARAM_STBC_BEACON 0x0100
  945. #define IEEE80211_HT_STBC_PARAM_LSIG_TXOP_FULLPROT 0x0200
  946. #define IEEE80211_HT_STBC_PARAM_PCO_ACTIVE 0x0400
  947. #define IEEE80211_HT_STBC_PARAM_PCO_PHASE 0x0800
  948. /* block-ack parameters */
  949. #define IEEE80211_ADDBA_PARAM_POLICY_MASK 0x0002
  950. #define IEEE80211_ADDBA_PARAM_TID_MASK 0x003C
  951. #define IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK 0xFFC0
  952. #define IEEE80211_DELBA_PARAM_TID_MASK 0xF000
  953. #define IEEE80211_DELBA_PARAM_INITIATOR_MASK 0x0800
  954. /*
  955. * A-PMDU buffer sizes
  956. * According to IEEE802.11n spec size varies from 8K to 64K (in powers of 2)
  957. */
  958. #define IEEE80211_MIN_AMPDU_BUF 0x8
  959. #define IEEE80211_MAX_AMPDU_BUF 0x40
  960. /* Spatial Multiplexing Power Save Modes (for capability) */
  961. #define WLAN_HT_CAP_SM_PS_STATIC 0
  962. #define WLAN_HT_CAP_SM_PS_DYNAMIC 1
  963. #define WLAN_HT_CAP_SM_PS_INVALID 2
  964. #define WLAN_HT_CAP_SM_PS_DISABLED 3
  965. /* for SM power control field lower two bits */
  966. #define WLAN_HT_SMPS_CONTROL_DISABLED 0
  967. #define WLAN_HT_SMPS_CONTROL_STATIC 1
  968. #define WLAN_HT_SMPS_CONTROL_DYNAMIC 3
  969. /**
  970. * struct ieee80211_vht_mcs_info - VHT MCS information
  971. * @rx_mcs_map: RX MCS map 2 bits for each stream, total 8 streams
  972. * @rx_highest: Indicates highest long GI VHT PPDU data rate
  973. * STA can receive. Rate expressed in units of 1 Mbps.
  974. * If this field is 0 this value should not be used to
  975. * consider the highest RX data rate supported.
  976. * @tx_mcs_map: TX MCS map 2 bits for each stream, total 8 streams
  977. * @tx_highest: Indicates highest long GI VHT PPDU data rate
  978. * STA can transmit. Rate expressed in units of 1 Mbps.
  979. * If this field is 0 this value should not be used to
  980. * consider the highest TX data rate supported.
  981. */
  982. struct ieee80211_vht_mcs_info {
  983. __le16 rx_mcs_map;
  984. __le16 rx_highest;
  985. __le16 tx_mcs_map;
  986. __le16 tx_highest;
  987. } __packed;
  988. /**
  989. * struct ieee80211_vht_cap - VHT capabilities
  990. *
  991. * This structure is the "VHT capabilities element" as
  992. * described in 802.11ac D3.0 8.4.2.160
  993. * @vht_cap_info: VHT capability info
  994. * @supp_mcs: VHT MCS supported rates
  995. */
  996. struct ieee80211_vht_cap {
  997. __le32 vht_cap_info;
  998. struct ieee80211_vht_mcs_info supp_mcs;
  999. } __packed;
  1000. /**
  1001. * struct ieee80211_vht_operation - VHT operation IE
  1002. *
  1003. * This structure is the "VHT operation element" as
  1004. * described in 802.11ac D3.0 8.4.2.161
  1005. * @chan_width: Operating channel width
  1006. * @center_freq_seg1_idx: center freq segment 1 index
  1007. * @center_freq_seg2_idx: center freq segment 2 index
  1008. * @basic_mcs_set: VHT Basic MCS rate set
  1009. */
  1010. struct ieee80211_vht_operation {
  1011. u8 chan_width;
  1012. u8 center_freq_seg1_idx;
  1013. u8 center_freq_seg2_idx;
  1014. __le16 basic_mcs_set;
  1015. } __packed;
  1016. #define IEEE80211_VHT_MCS_ZERO_TO_SEVEN_SUPPORT 0
  1017. #define IEEE80211_VHT_MCS_ZERO_TO_EIGHT_SUPPORT 1
  1018. #define IEEE80211_VHT_MCS_ZERO_TO_NINE_SUPPORT 2
  1019. #define IEEE80211_VHT_MCS_NOT_SUPPORTED 3
  1020. /* 802.11ac VHT Capabilities */
  1021. #define IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895 0x00000000
  1022. #define IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991 0x00000001
  1023. #define IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 0x00000002
  1024. #define IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ 0x00000004
  1025. #define IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ 0x00000008
  1026. #define IEEE80211_VHT_CAP_RXLDPC 0x00000010
  1027. #define IEEE80211_VHT_CAP_SHORT_GI_80 0x00000020
  1028. #define IEEE80211_VHT_CAP_SHORT_GI_160 0x00000040
  1029. #define IEEE80211_VHT_CAP_TXSTBC 0x00000080
  1030. #define IEEE80211_VHT_CAP_RXSTBC_1 0x00000100
  1031. #define IEEE80211_VHT_CAP_RXSTBC_2 0x00000200
  1032. #define IEEE80211_VHT_CAP_RXSTBC_3 0x00000300
  1033. #define IEEE80211_VHT_CAP_RXSTBC_4 0x00000400
  1034. #define IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE 0x00000800
  1035. #define IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE 0x00001000
  1036. #define IEEE80211_VHT_CAP_BEAMFORMER_ANTENNAS_MAX 0x00006000
  1037. #define IEEE80211_VHT_CAP_SOUNDING_DIMENTION_MAX 0x00030000
  1038. #define IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE 0x00080000
  1039. #define IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE 0x00100000
  1040. #define IEEE80211_VHT_CAP_VHT_TXOP_PS 0x00200000
  1041. #define IEEE80211_VHT_CAP_HTC_VHT 0x00400000
  1042. #define IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT 0x00800000
  1043. #define IEEE80211_VHT_CAP_VHT_LINK_ADAPTATION_VHT_UNSOL_MFB 0x08000000
  1044. #define IEEE80211_VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB 0x0c000000
  1045. #define IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN 0x10000000
  1046. #define IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN 0x20000000
  1047. /* Authentication algorithms */
  1048. #define WLAN_AUTH_OPEN 0
  1049. #define WLAN_AUTH_SHARED_KEY 1
  1050. #define WLAN_AUTH_FT 2
  1051. #define WLAN_AUTH_SAE 3
  1052. #define WLAN_AUTH_LEAP 128
  1053. #define WLAN_AUTH_CHALLENGE_LEN 128
  1054. #define WLAN_CAPABILITY_ESS (1<<0)
  1055. #define WLAN_CAPABILITY_IBSS (1<<1)
  1056. /*
  1057. * A mesh STA sets the ESS and IBSS capability bits to zero.
  1058. * however, this holds true for p2p probe responses (in the p2p_find
  1059. * phase) as well.
  1060. */
  1061. #define WLAN_CAPABILITY_IS_STA_BSS(cap) \
  1062. (!((cap) & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)))
  1063. #define WLAN_CAPABILITY_CF_POLLABLE (1<<2)
  1064. #define WLAN_CAPABILITY_CF_POLL_REQUEST (1<<3)
  1065. #define WLAN_CAPABILITY_PRIVACY (1<<4)
  1066. #define WLAN_CAPABILITY_SHORT_PREAMBLE (1<<5)
  1067. #define WLAN_CAPABILITY_PBCC (1<<6)
  1068. #define WLAN_CAPABILITY_CHANNEL_AGILITY (1<<7)
  1069. /* 802.11h */
  1070. #define WLAN_CAPABILITY_SPECTRUM_MGMT (1<<8)
  1071. #define WLAN_CAPABILITY_QOS (1<<9)
  1072. #define WLAN_CAPABILITY_SHORT_SLOT_TIME (1<<10)
  1073. #define WLAN_CAPABILITY_DSSS_OFDM (1<<13)
  1074. /* measurement */
  1075. #define IEEE80211_SPCT_MSR_RPRT_MODE_LATE (1<<0)
  1076. #define IEEE80211_SPCT_MSR_RPRT_MODE_INCAPABLE (1<<1)
  1077. #define IEEE80211_SPCT_MSR_RPRT_MODE_REFUSED (1<<2)
  1078. #define IEEE80211_SPCT_MSR_RPRT_TYPE_BASIC 0
  1079. #define IEEE80211_SPCT_MSR_RPRT_TYPE_CCA 1
  1080. #define IEEE80211_SPCT_MSR_RPRT_TYPE_RPI 2
  1081. /* 802.11g ERP information element */
  1082. #define WLAN_ERP_NON_ERP_PRESENT (1<<0)
  1083. #define WLAN_ERP_USE_PROTECTION (1<<1)
  1084. #define WLAN_ERP_BARKER_PREAMBLE (1<<2)
  1085. /* WLAN_ERP_BARKER_PREAMBLE values */
  1086. enum {
  1087. WLAN_ERP_PREAMBLE_SHORT = 0,
  1088. WLAN_ERP_PREAMBLE_LONG = 1,
  1089. };
  1090. /* Status codes */
  1091. enum ieee80211_statuscode {
  1092. WLAN_STATUS_SUCCESS = 0,
  1093. WLAN_STATUS_UNSPECIFIED_FAILURE = 1,
  1094. WLAN_STATUS_CAPS_UNSUPPORTED = 10,
  1095. WLAN_STATUS_REASSOC_NO_ASSOC = 11,
  1096. WLAN_STATUS_ASSOC_DENIED_UNSPEC = 12,
  1097. WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG = 13,
  1098. WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION = 14,
  1099. WLAN_STATUS_CHALLENGE_FAIL = 15,
  1100. WLAN_STATUS_AUTH_TIMEOUT = 16,
  1101. WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA = 17,
  1102. WLAN_STATUS_ASSOC_DENIED_RATES = 18,
  1103. /* 802.11b */
  1104. WLAN_STATUS_ASSOC_DENIED_NOSHORTPREAMBLE = 19,
  1105. WLAN_STATUS_ASSOC_DENIED_NOPBCC = 20,
  1106. WLAN_STATUS_ASSOC_DENIED_NOAGILITY = 21,
  1107. /* 802.11h */
  1108. WLAN_STATUS_ASSOC_DENIED_NOSPECTRUM = 22,
  1109. WLAN_STATUS_ASSOC_REJECTED_BAD_POWER = 23,
  1110. WLAN_STATUS_ASSOC_REJECTED_BAD_SUPP_CHAN = 24,
  1111. /* 802.11g */
  1112. WLAN_STATUS_ASSOC_DENIED_NOSHORTTIME = 25,
  1113. WLAN_STATUS_ASSOC_DENIED_NODSSSOFDM = 26,
  1114. /* 802.11w */
  1115. WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY = 30,
  1116. WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION = 31,
  1117. /* 802.11i */
  1118. WLAN_STATUS_INVALID_IE = 40,
  1119. WLAN_STATUS_INVALID_GROUP_CIPHER = 41,
  1120. WLAN_STATUS_INVALID_PAIRWISE_CIPHER = 42,
  1121. WLAN_STATUS_INVALID_AKMP = 43,
  1122. WLAN_STATUS_UNSUPP_RSN_VERSION = 44,
  1123. WLAN_STATUS_INVALID_RSN_IE_CAP = 45,
  1124. WLAN_STATUS_CIPHER_SUITE_REJECTED = 46,
  1125. /* 802.11e */
  1126. WLAN_STATUS_UNSPECIFIED_QOS = 32,
  1127. WLAN_STATUS_ASSOC_DENIED_NOBANDWIDTH = 33,
  1128. WLAN_STATUS_ASSOC_DENIED_LOWACK = 34,
  1129. WLAN_STATUS_ASSOC_DENIED_UNSUPP_QOS = 35,
  1130. WLAN_STATUS_REQUEST_DECLINED = 37,
  1131. WLAN_STATUS_INVALID_QOS_PARAM = 38,
  1132. WLAN_STATUS_CHANGE_TSPEC = 39,
  1133. WLAN_STATUS_WAIT_TS_DELAY = 47,
  1134. WLAN_STATUS_NO_DIRECT_LINK = 48,
  1135. WLAN_STATUS_STA_NOT_PRESENT = 49,
  1136. WLAN_STATUS_STA_NOT_QSTA = 50,
  1137. /* 802.11s */
  1138. WLAN_STATUS_ANTI_CLOG_REQUIRED = 76,
  1139. WLAN_STATUS_FCG_NOT_SUPP = 78,
  1140. WLAN_STATUS_STA_NO_TBTT = 78,
  1141. };
  1142. /* Reason codes */
  1143. enum ieee80211_reasoncode {
  1144. WLAN_REASON_UNSPECIFIED = 1,
  1145. WLAN_REASON_PREV_AUTH_NOT_VALID = 2,
  1146. WLAN_REASON_DEAUTH_LEAVING = 3,
  1147. WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY = 4,
  1148. WLAN_REASON_DISASSOC_AP_BUSY = 5,
  1149. WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA = 6,
  1150. WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA = 7,
  1151. WLAN_REASON_DISASSOC_STA_HAS_LEFT = 8,
  1152. WLAN_REASON_STA_REQ_ASSOC_WITHOUT_AUTH = 9,
  1153. /* 802.11h */
  1154. WLAN_REASON_DISASSOC_BAD_POWER = 10,
  1155. WLAN_REASON_DISASSOC_BAD_SUPP_CHAN = 11,
  1156. /* 802.11i */
  1157. WLAN_REASON_INVALID_IE = 13,
  1158. WLAN_REASON_MIC_FAILURE = 14,
  1159. WLAN_REASON_4WAY_HANDSHAKE_TIMEOUT = 15,
  1160. WLAN_REASON_GROUP_KEY_HANDSHAKE_TIMEOUT = 16,
  1161. WLAN_REASON_IE_DIFFERENT = 17,
  1162. WLAN_REASON_INVALID_GROUP_CIPHER = 18,
  1163. WLAN_REASON_INVALID_PAIRWISE_CIPHER = 19,
  1164. WLAN_REASON_INVALID_AKMP = 20,
  1165. WLAN_REASON_UNSUPP_RSN_VERSION = 21,
  1166. WLAN_REASON_INVALID_RSN_IE_CAP = 22,
  1167. WLAN_REASON_IEEE8021X_FAILED = 23,
  1168. WLAN_REASON_CIPHER_SUITE_REJECTED = 24,
  1169. /* 802.11e */
  1170. WLAN_REASON_DISASSOC_UNSPECIFIED_QOS = 32,
  1171. WLAN_REASON_DISASSOC_QAP_NO_BANDWIDTH = 33,
  1172. WLAN_REASON_DISASSOC_LOW_ACK = 34,
  1173. WLAN_REASON_DISASSOC_QAP_EXCEED_TXOP = 35,
  1174. WLAN_REASON_QSTA_LEAVE_QBSS = 36,
  1175. WLAN_REASON_QSTA_NOT_USE = 37,
  1176. WLAN_REASON_QSTA_REQUIRE_SETUP = 38,
  1177. WLAN_REASON_QSTA_TIMEOUT = 39,
  1178. WLAN_REASON_QSTA_CIPHER_NOT_SUPP = 45,
  1179. /* 802.11s */
  1180. WLAN_REASON_MESH_PEER_CANCELED = 52,
  1181. WLAN_REASON_MESH_MAX_PEERS = 53,
  1182. WLAN_REASON_MESH_CONFIG = 54,
  1183. WLAN_REASON_MESH_CLOSE = 55,
  1184. WLAN_REASON_MESH_MAX_RETRIES = 56,
  1185. WLAN_REASON_MESH_CONFIRM_TIMEOUT = 57,
  1186. WLAN_REASON_MESH_INVALID_GTK = 58,
  1187. WLAN_REASON_MESH_INCONSISTENT_PARAM = 59,
  1188. WLAN_REASON_MESH_INVALID_SECURITY = 60,
  1189. WLAN_REASON_MESH_PATH_ERROR = 61,
  1190. WLAN_REASON_MESH_PATH_NOFORWARD = 62,
  1191. WLAN_REASON_MESH_PATH_DEST_UNREACHABLE = 63,
  1192. WLAN_REASON_MAC_EXISTS_IN_MBSS = 64,
  1193. WLAN_REASON_MESH_CHAN_REGULATORY = 65,
  1194. WLAN_REASON_MESH_CHAN = 66,
  1195. };
  1196. /* Information Element IDs */
  1197. enum ieee80211_eid {
  1198. WLAN_EID_SSID = 0,
  1199. WLAN_EID_SUPP_RATES = 1,
  1200. WLAN_EID_FH_PARAMS = 2,
  1201. WLAN_EID_DS_PARAMS = 3,
  1202. WLAN_EID_CF_PARAMS = 4,
  1203. WLAN_EID_TIM = 5,
  1204. WLAN_EID_IBSS_PARAMS = 6,
  1205. WLAN_EID_CHALLENGE = 16,
  1206. WLAN_EID_COUNTRY = 7,
  1207. WLAN_EID_HP_PARAMS = 8,
  1208. WLAN_EID_HP_TABLE = 9,
  1209. WLAN_EID_REQUEST = 10,
  1210. WLAN_EID_QBSS_LOAD = 11,
  1211. WLAN_EID_EDCA_PARAM_SET = 12,
  1212. WLAN_EID_TSPEC = 13,
  1213. WLAN_EID_TCLAS = 14,
  1214. WLAN_EID_SCHEDULE = 15,
  1215. WLAN_EID_TS_DELAY = 43,
  1216. WLAN_EID_TCLAS_PROCESSING = 44,
  1217. WLAN_EID_QOS_CAPA = 46,
  1218. /* 802.11z */
  1219. WLAN_EID_LINK_ID = 101,
  1220. /* 802.11s */
  1221. WLAN_EID_MESH_CONFIG = 113,
  1222. WLAN_EID_MESH_ID = 114,
  1223. WLAN_EID_LINK_METRIC_REPORT = 115,
  1224. WLAN_EID_CONGESTION_NOTIFICATION = 116,
  1225. WLAN_EID_PEER_MGMT = 117,
  1226. WLAN_EID_CHAN_SWITCH_PARAM = 118,
  1227. WLAN_EID_MESH_AWAKE_WINDOW = 119,
  1228. WLAN_EID_BEACON_TIMING = 120,
  1229. WLAN_EID_MCCAOP_SETUP_REQ = 121,
  1230. WLAN_EID_MCCAOP_SETUP_RESP = 122,
  1231. WLAN_EID_MCCAOP_ADVERT = 123,
  1232. WLAN_EID_MCCAOP_TEARDOWN = 124,
  1233. WLAN_EID_GANN = 125,
  1234. WLAN_EID_RANN = 126,
  1235. WLAN_EID_PREQ = 130,
  1236. WLAN_EID_PREP = 131,
  1237. WLAN_EID_PERR = 132,
  1238. WLAN_EID_PXU = 137,
  1239. WLAN_EID_PXUC = 138,
  1240. WLAN_EID_AUTH_MESH_PEER_EXCH = 139,
  1241. WLAN_EID_MIC = 140,
  1242. WLAN_EID_PWR_CONSTRAINT = 32,
  1243. WLAN_EID_PWR_CAPABILITY = 33,
  1244. WLAN_EID_TPC_REQUEST = 34,
  1245. WLAN_EID_TPC_REPORT = 35,
  1246. WLAN_EID_SUPPORTED_CHANNELS = 36,
  1247. WLAN_EID_CHANNEL_SWITCH = 37,
  1248. WLAN_EID_MEASURE_REQUEST = 38,
  1249. WLAN_EID_MEASURE_REPORT = 39,
  1250. WLAN_EID_QUIET = 40,
  1251. WLAN_EID_IBSS_DFS = 41,
  1252. WLAN_EID_ERP_INFO = 42,
  1253. WLAN_EID_EXT_SUPP_RATES = 50,
  1254. WLAN_EID_HT_CAPABILITY = 45,
  1255. WLAN_EID_HT_INFORMATION = 61,
  1256. WLAN_EID_RSN = 48,
  1257. WLAN_EID_MMIE = 76,
  1258. WLAN_EID_WPA = 221,
  1259. WLAN_EID_GENERIC = 221,
  1260. WLAN_EID_VENDOR_SPECIFIC = 221,
  1261. WLAN_EID_QOS_PARAMETER = 222,
  1262. WLAN_EID_AP_CHAN_REPORT = 51,
  1263. WLAN_EID_NEIGHBOR_REPORT = 52,
  1264. WLAN_EID_RCPI = 53,
  1265. WLAN_EID_BSS_AVG_ACCESS_DELAY = 63,
  1266. WLAN_EID_ANTENNA_INFO = 64,
  1267. WLAN_EID_RSNI = 65,
  1268. WLAN_EID_MEASUREMENT_PILOT_TX_INFO = 66,
  1269. WLAN_EID_BSS_AVAILABLE_CAPACITY = 67,
  1270. WLAN_EID_BSS_AC_ACCESS_DELAY = 68,
  1271. WLAN_EID_RRM_ENABLED_CAPABILITIES = 70,
  1272. WLAN_EID_MULTIPLE_BSSID = 71,
  1273. WLAN_EID_BSS_COEX_2040 = 72,
  1274. WLAN_EID_OVERLAP_BSS_SCAN_PARAM = 74,
  1275. WLAN_EID_EXT_CAPABILITY = 127,
  1276. WLAN_EID_MOBILITY_DOMAIN = 54,
  1277. WLAN_EID_FAST_BSS_TRANSITION = 55,
  1278. WLAN_EID_TIMEOUT_INTERVAL = 56,
  1279. WLAN_EID_RIC_DATA = 57,
  1280. WLAN_EID_RIC_DESCRIPTOR = 75,
  1281. WLAN_EID_DSE_REGISTERED_LOCATION = 58,
  1282. WLAN_EID_SUPPORTED_REGULATORY_CLASSES = 59,
  1283. WLAN_EID_EXT_CHANSWITCH_ANN = 60,
  1284. WLAN_EID_VHT_CAPABILITY = 191,
  1285. WLAN_EID_VHT_OPERATION = 192,
  1286. };
  1287. /* Action category code */
  1288. enum ieee80211_category {
  1289. WLAN_CATEGORY_SPECTRUM_MGMT = 0,
  1290. WLAN_CATEGORY_QOS = 1,
  1291. WLAN_CATEGORY_DLS = 2,
  1292. WLAN_CATEGORY_BACK = 3,
  1293. WLAN_CATEGORY_PUBLIC = 4,
  1294. WLAN_CATEGORY_HT = 7,
  1295. WLAN_CATEGORY_SA_QUERY = 8,
  1296. WLAN_CATEGORY_PROTECTED_DUAL_OF_ACTION = 9,
  1297. WLAN_CATEGORY_TDLS = 12,
  1298. WLAN_CATEGORY_MESH_ACTION = 13,
  1299. WLAN_CATEGORY_MULTIHOP_ACTION = 14,
  1300. WLAN_CATEGORY_SELF_PROTECTED = 15,
  1301. WLAN_CATEGORY_WMM = 17,
  1302. WLAN_CATEGORY_VENDOR_SPECIFIC_PROTECTED = 126,
  1303. WLAN_CATEGORY_VENDOR_SPECIFIC = 127,
  1304. };
  1305. /* SPECTRUM_MGMT action code */
  1306. enum ieee80211_spectrum_mgmt_actioncode {
  1307. WLAN_ACTION_SPCT_MSR_REQ = 0,
  1308. WLAN_ACTION_SPCT_MSR_RPRT = 1,
  1309. WLAN_ACTION_SPCT_TPC_REQ = 2,
  1310. WLAN_ACTION_SPCT_TPC_RPRT = 3,
  1311. WLAN_ACTION_SPCT_CHL_SWITCH = 4,
  1312. };
  1313. /* HT action codes */
  1314. enum ieee80211_ht_actioncode {
  1315. WLAN_HT_ACTION_NOTIFY_CHANWIDTH = 0,
  1316. WLAN_HT_ACTION_SMPS = 1,
  1317. WLAN_HT_ACTION_PSMP = 2,
  1318. WLAN_HT_ACTION_PCO_PHASE = 3,
  1319. WLAN_HT_ACTION_CSI = 4,
  1320. WLAN_HT_ACTION_NONCOMPRESSED_BF = 5,
  1321. WLAN_HT_ACTION_COMPRESSED_BF = 6,
  1322. WLAN_HT_ACTION_ASEL_IDX_FEEDBACK = 7,
  1323. };
  1324. /* Self Protected Action codes */
  1325. enum ieee80211_self_protected_actioncode {
  1326. WLAN_SP_RESERVED = 0,
  1327. WLAN_SP_MESH_PEERING_OPEN = 1,
  1328. WLAN_SP_MESH_PEERING_CONFIRM = 2,
  1329. WLAN_SP_MESH_PEERING_CLOSE = 3,
  1330. WLAN_SP_MGK_INFORM = 4,
  1331. WLAN_SP_MGK_ACK = 5,
  1332. };
  1333. /* Mesh action codes */
  1334. enum ieee80211_mesh_actioncode {
  1335. WLAN_MESH_ACTION_LINK_METRIC_REPORT,
  1336. WLAN_MESH_ACTION_HWMP_PATH_SELECTION,
  1337. WLAN_MESH_ACTION_GATE_ANNOUNCEMENT,
  1338. WLAN_MESH_ACTION_CONGESTION_CONTROL_NOTIFICATION,
  1339. WLAN_MESH_ACTION_MCCA_SETUP_REQUEST,
  1340. WLAN_MESH_ACTION_MCCA_SETUP_REPLY,
  1341. WLAN_MESH_ACTION_MCCA_ADVERTISEMENT_REQUEST,
  1342. WLAN_MESH_ACTION_MCCA_ADVERTISEMENT,
  1343. WLAN_MESH_ACTION_MCCA_TEARDOWN,
  1344. WLAN_MESH_ACTION_TBTT_ADJUSTMENT_REQUEST,
  1345. WLAN_MESH_ACTION_TBTT_ADJUSTMENT_RESPONSE,
  1346. };
  1347. /* Security key length */
  1348. enum ieee80211_key_len {
  1349. WLAN_KEY_LEN_WEP40 = 5,
  1350. WLAN_KEY_LEN_WEP104 = 13,
  1351. WLAN_KEY_LEN_CCMP = 16,
  1352. WLAN_KEY_LEN_TKIP = 32,
  1353. WLAN_KEY_LEN_AES_CMAC = 16,
  1354. WLAN_KEY_LEN_WAPI_SMS4 = 32,
  1355. };
  1356. /* Public action codes */
  1357. enum ieee80211_pub_actioncode {
  1358. WLAN_PUB_ACTION_TDLS_DISCOVER_RES = 14,
  1359. };
  1360. /* TDLS action codes */
  1361. enum ieee80211_tdls_actioncode {
  1362. WLAN_TDLS_SETUP_REQUEST = 0,
  1363. WLAN_TDLS_SETUP_RESPONSE = 1,
  1364. WLAN_TDLS_SETUP_CONFIRM = 2,
  1365. WLAN_TDLS_TEARDOWN = 3,
  1366. WLAN_TDLS_PEER_TRAFFIC_INDICATION = 4,
  1367. WLAN_TDLS_CHANNEL_SWITCH_REQUEST = 5,
  1368. WLAN_TDLS_CHANNEL_SWITCH_RESPONSE = 6,
  1369. WLAN_TDLS_PEER_PSM_REQUEST = 7,
  1370. WLAN_TDLS_PEER_PSM_RESPONSE = 8,
  1371. WLAN_TDLS_PEER_TRAFFIC_RESPONSE = 9,
  1372. WLAN_TDLS_DISCOVERY_REQUEST = 10,
  1373. };
  1374. /*
  1375. * TDLS capabililites to be enabled in the 5th byte of the
  1376. * @WLAN_EID_EXT_CAPABILITY information element
  1377. */
  1378. #define WLAN_EXT_CAPA5_TDLS_ENABLED BIT(5)
  1379. #define WLAN_EXT_CAPA5_TDLS_PROHIBITED BIT(6)
  1380. /* TDLS specific payload type in the LLC/SNAP header */
  1381. #define WLAN_TDLS_SNAP_RFTYPE 0x2
  1382. /**
  1383. * enum - mesh path selection protocol identifier
  1384. *
  1385. * @IEEE80211_PATH_PROTOCOL_HWMP: the default path selection protocol
  1386. * @IEEE80211_PATH_PROTOCOL_VENDOR: a vendor specific protocol that will
  1387. * be specified in a vendor specific information element
  1388. */
  1389. enum {
  1390. IEEE80211_PATH_PROTOCOL_HWMP = 0,
  1391. IEEE80211_PATH_PROTOCOL_VENDOR = 255,
  1392. };
  1393. /**
  1394. * enum - mesh path selection metric identifier
  1395. *
  1396. * @IEEE80211_PATH_METRIC_AIRTIME: the default path selection metric
  1397. * @IEEE80211_PATH_METRIC_VENDOR: a vendor specific metric that will be
  1398. * specified in a vendor specific information element
  1399. */
  1400. enum {
  1401. IEEE80211_PATH_METRIC_AIRTIME = 0,
  1402. IEEE80211_PATH_METRIC_VENDOR = 255,
  1403. };
  1404. /*
  1405. * IEEE 802.11-2007 7.3.2.9 Country information element
  1406. *
  1407. * Minimum length is 8 octets, ie len must be evenly
  1408. * divisible by 2
  1409. */
  1410. /* Although the spec says 8 I'm seeing 6 in practice */
  1411. #define IEEE80211_COUNTRY_IE_MIN_LEN 6
  1412. /* The Country String field of the element shall be 3 octets in length */
  1413. #define IEEE80211_COUNTRY_STRING_LEN 3
  1414. /*
  1415. * For regulatory extension stuff see IEEE 802.11-2007
  1416. * Annex I (page 1141) and Annex J (page 1147). Also
  1417. * review 7.3.2.9.
  1418. *
  1419. * When dot11RegulatoryClassesRequired is true and the
  1420. * first_channel/reg_extension_id is >= 201 then the IE
  1421. * compromises of the 'ext' struct represented below:
  1422. *
  1423. * - Regulatory extension ID - when generating IE this just needs
  1424. * to be monotonically increasing for each triplet passed in
  1425. * the IE
  1426. * - Regulatory class - index into set of rules
  1427. * - Coverage class - index into air propagation time (Table 7-27),
  1428. * in microseconds, you can compute the air propagation time from
  1429. * the index by multiplying by 3, so index 10 yields a propagation
  1430. * of 10 us. Valid values are 0-31, values 32-255 are not defined
  1431. * yet. A value of 0 inicates air propagation of <= 1 us.
  1432. *
  1433. * See also Table I.2 for Emission limit sets and table
  1434. * I.3 for Behavior limit sets. Table J.1 indicates how to map
  1435. * a reg_class to an emission limit set and behavior limit set.
  1436. */
  1437. #define IEEE80211_COUNTRY_EXTENSION_ID 201
  1438. /*
  1439. * Channels numbers in the IE must be monotonically increasing
  1440. * if dot11RegulatoryClassesRequired is not true.
  1441. *
  1442. * If dot11RegulatoryClassesRequired is true consecutive
  1443. * subband triplets following a regulatory triplet shall
  1444. * have monotonically increasing first_channel number fields.
  1445. *
  1446. * Channel numbers shall not overlap.
  1447. *
  1448. * Note that max_power is signed.
  1449. */
  1450. struct ieee80211_country_ie_triplet {
  1451. union {
  1452. struct {
  1453. u8 first_channel;
  1454. u8 num_channels;
  1455. s8 max_power;
  1456. } __attribute__ ((packed)) chans;
  1457. struct {
  1458. u8 reg_extension_id;
  1459. u8 reg_class;
  1460. u8 coverage_class;
  1461. } __attribute__ ((packed)) ext;
  1462. };
  1463. } __attribute__ ((packed));
  1464. enum ieee80211_timeout_interval_type {
  1465. WLAN_TIMEOUT_REASSOC_DEADLINE = 1 /* 802.11r */,
  1466. WLAN_TIMEOUT_KEY_LIFETIME = 2 /* 802.11r */,
  1467. WLAN_TIMEOUT_ASSOC_COMEBACK = 3 /* 802.11w */,
  1468. };
  1469. /* BACK action code */
  1470. enum ieee80211_back_actioncode {
  1471. WLAN_ACTION_ADDBA_REQ = 0,
  1472. WLAN_ACTION_ADDBA_RESP = 1,
  1473. WLAN_ACTION_DELBA = 2,
  1474. };
  1475. /* BACK (block-ack) parties */
  1476. enum ieee80211_back_parties {
  1477. WLAN_BACK_RECIPIENT = 0,
  1478. WLAN_BACK_INITIATOR = 1,
  1479. };
  1480. /* SA Query action */
  1481. enum ieee80211_sa_query_action {
  1482. WLAN_ACTION_SA_QUERY_REQUEST = 0,
  1483. WLAN_ACTION_SA_QUERY_RESPONSE = 1,
  1484. };
  1485. /* cipher suite selectors */
  1486. #define WLAN_CIPHER_SUITE_USE_GROUP 0x000FAC00
  1487. #define WLAN_CIPHER_SUITE_WEP40 0x000FAC01
  1488. #define WLAN_CIPHER_SUITE_TKIP 0x000FAC02
  1489. /* reserved: 0x000FAC03 */
  1490. #define WLAN_CIPHER_SUITE_CCMP 0x000FAC04
  1491. #define WLAN_CIPHER_SUITE_WEP104 0x000FAC05
  1492. #define WLAN_CIPHER_SUITE_AES_CMAC 0x000FAC06
  1493. #define WLAN_CIPHER_SUITE_SMS4 0x00147201 /* WAPI */
  1494. #define WLAN_CIPHER_SUITE_PMK 0x00904C00 /* 802.11r */
  1495. /* AKM suite selectors */
  1496. #define WLAN_AKM_SUITE_8021X 0x000FAC01
  1497. #define WLAN_AKM_SUITE_PSK 0x000FAC02
  1498. #define WLAN_AKM_SUITE_FT_8021X 0x000FAC03 /* 802.11r */
  1499. #define WLAN_AKM_SUITE_FT_PSK 0x000FAC04 /* 802.11r */
  1500. #define WLAN_AKM_SUITE_SAE 0x000FAC08
  1501. #define WLAN_AKM_SUITE_FT_OVER_SAE 0x000FAC09
  1502. #define WLAN_AKM_SUITE_WAPI_PSK 0x000FAC11 /* WAPI */
  1503. #define WLAN_AKM_SUITE_WAPI_CERT 0x000FAC12 /* WAPI */
  1504. #define WLAN_AKM_SUITE_CCKM 0x00409600 /* CCKM */
  1505. #define WLAN_MAX_KEY_LEN 32
  1506. #define WLAN_PMKID_LEN 16
  1507. #define WLAN_OUI_WFA 0x506f9a
  1508. #define WLAN_OUI_TYPE_WFA_P2P 9
  1509. /*
  1510. * WMM/802.11e Tspec Element
  1511. */
  1512. #define IEEE80211_WMM_IE_TSPEC_TID_MASK 0x0F
  1513. #define IEEE80211_WMM_IE_TSPEC_TID_SHIFT 1
  1514. enum ieee80211_tspec_status_code {
  1515. IEEE80211_TSPEC_STATUS_ADMISS_ACCEPTED = 0,
  1516. IEEE80211_TSPEC_STATUS_ADDTS_INVAL_PARAMS = 0x1,
  1517. };
  1518. struct ieee80211_tspec_ie {
  1519. u8 element_id;
  1520. u8 len;
  1521. u8 oui[3];
  1522. u8 oui_type;
  1523. u8 oui_subtype;
  1524. u8 version;
  1525. __le16 tsinfo;
  1526. u8 tsinfo_resvd;
  1527. __le16 nominal_msdu;
  1528. __le16 max_msdu;
  1529. __le32 min_service_int;
  1530. __le32 max_service_int;
  1531. __le32 inactivity_int;
  1532. __le32 suspension_int;
  1533. __le32 service_start_time;
  1534. __le32 min_data_rate;
  1535. __le32 mean_data_rate;
  1536. __le32 peak_data_rate;
  1537. __le32 max_burst_size;
  1538. __le32 delay_bound;
  1539. __le32 min_phy_rate;
  1540. __le16 sba;
  1541. __le16 medium_time;
  1542. } __packed;
  1543. /**
  1544. * ieee80211_get_qos_ctl - get pointer to qos control bytes
  1545. * @hdr: the frame
  1546. *
  1547. * The qos ctrl bytes come after the frame_control, duration, seq_num
  1548. * and 3 or 4 addresses of length ETH_ALEN.
  1549. * 3 addr: 2 + 2 + 2 + 3*6 = 24
  1550. * 4 addr: 2 + 2 + 2 + 4*6 = 30
  1551. */
  1552. static inline u8 *ieee80211_get_qos_ctl(struct ieee80211_hdr *hdr)
  1553. {
  1554. if (ieee80211_has_a4(hdr->frame_control))
  1555. return (u8 *)hdr + 30;
  1556. else
  1557. return (u8 *)hdr + 24;
  1558. }
  1559. /**
  1560. * ieee80211_get_SA - get pointer to SA
  1561. * @hdr: the frame
  1562. *
  1563. * Given an 802.11 frame, this function returns the offset
  1564. * to the source address (SA). It does not verify that the
  1565. * header is long enough to contain the address, and the
  1566. * header must be long enough to contain the frame control
  1567. * field.
  1568. */
  1569. static inline u8 *ieee80211_get_SA(struct ieee80211_hdr *hdr)
  1570. {
  1571. if (ieee80211_has_a4(hdr->frame_control))
  1572. return hdr->addr4;
  1573. if (ieee80211_has_fromds(hdr->frame_control))
  1574. return hdr->addr3;
  1575. return hdr->addr2;
  1576. }
  1577. /**
  1578. * ieee80211_get_DA - get pointer to DA
  1579. * @hdr: the frame
  1580. *
  1581. * Given an 802.11 frame, this function returns the offset
  1582. * to the destination address (DA). It does not verify that
  1583. * the header is long enough to contain the address, and the
  1584. * header must be long enough to contain the frame control
  1585. * field.
  1586. */
  1587. static inline u8 *ieee80211_get_DA(struct ieee80211_hdr *hdr)
  1588. {
  1589. if (ieee80211_has_tods(hdr->frame_control))
  1590. return hdr->addr3;
  1591. else
  1592. return hdr->addr1;
  1593. }
  1594. /**
  1595. * ieee80211_is_robust_mgmt_frame - check if frame is a robust management frame
  1596. * @hdr: the frame (buffer must include at least the first octet of payload)
  1597. */
  1598. static inline bool ieee80211_is_robust_mgmt_frame(struct ieee80211_hdr *hdr)
  1599. {
  1600. if (ieee80211_is_disassoc(hdr->frame_control) ||
  1601. ieee80211_is_deauth(hdr->frame_control))
  1602. return true;
  1603. if (ieee80211_is_action(hdr->frame_control)) {
  1604. u8 *category;
  1605. /*
  1606. * Action frames, excluding Public Action frames, are Robust
  1607. * Management Frames. However, if we are looking at a Protected
  1608. * frame, skip the check since the data may be encrypted and
  1609. * the frame has already been found to be a Robust Management
  1610. * Frame (by the other end).
  1611. */
  1612. if (ieee80211_has_protected(hdr->frame_control))
  1613. return true;
  1614. category = ((u8 *) hdr) + 24;
  1615. return *category != WLAN_CATEGORY_PUBLIC &&
  1616. *category != WLAN_CATEGORY_HT &&
  1617. *category != WLAN_CATEGORY_SELF_PROTECTED &&
  1618. *category != WLAN_CATEGORY_VENDOR_SPECIFIC;
  1619. }
  1620. return false;
  1621. }
  1622. /**
  1623. * ieee80211_is_public_action - check if frame is a public action frame
  1624. * @hdr: the frame
  1625. * @len: length of the frame
  1626. */
  1627. static inline bool ieee80211_is_public_action(struct ieee80211_hdr *hdr,
  1628. size_t len)
  1629. {
  1630. struct ieee80211_mgmt *mgmt = (void *)hdr;
  1631. if (len < IEEE80211_MIN_ACTION_SIZE)
  1632. return false;
  1633. if (!ieee80211_is_action(hdr->frame_control))
  1634. return false;
  1635. return mgmt->u.action.category == WLAN_CATEGORY_PUBLIC;
  1636. }
  1637. /**
  1638. * ieee80211_fhss_chan_to_freq - get channel frequency
  1639. * @channel: the FHSS channel
  1640. *
  1641. * Convert IEEE802.11 FHSS channel to frequency (MHz)
  1642. * Ref IEEE 802.11-2007 section 14.6
  1643. */
  1644. static inline int ieee80211_fhss_chan_to_freq(int channel)
  1645. {
  1646. if ((channel > 1) && (channel < 96))
  1647. return channel + 2400;
  1648. else
  1649. return -1;
  1650. }
  1651. /**
  1652. * ieee80211_freq_to_fhss_chan - get channel
  1653. * @freq: the channels frequency
  1654. *
  1655. * Convert frequency (MHz) to IEEE802.11 FHSS channel
  1656. * Ref IEEE 802.11-2007 section 14.6
  1657. */
  1658. static inline int ieee80211_freq_to_fhss_chan(int freq)
  1659. {
  1660. if ((freq > 2401) && (freq < 2496))
  1661. return freq - 2400;
  1662. else
  1663. return -1;
  1664. }
  1665. /**
  1666. * ieee80211_dsss_chan_to_freq - get channel center frequency
  1667. * @channel: the DSSS channel
  1668. *
  1669. * Convert IEEE802.11 DSSS channel to the center frequency (MHz).
  1670. * Ref IEEE 802.11-2007 section 15.6
  1671. */
  1672. static inline int ieee80211_dsss_chan_to_freq(int channel)
  1673. {
  1674. if ((channel > 0) && (channel < 14))
  1675. return 2407 + (channel * 5);
  1676. else if (channel == 14)
  1677. return 2484;
  1678. else
  1679. return -1;
  1680. }
  1681. /**
  1682. * ieee80211_freq_to_dsss_chan - get channel
  1683. * @freq: the frequency
  1684. *
  1685. * Convert frequency (MHz) to IEEE802.11 DSSS channel
  1686. * Ref IEEE 802.11-2007 section 15.6
  1687. *
  1688. * This routine selects the channel with the closest center frequency.
  1689. */
  1690. static inline int ieee80211_freq_to_dsss_chan(int freq)
  1691. {
  1692. if ((freq >= 2410) && (freq < 2475))
  1693. return (freq - 2405) / 5;
  1694. else if ((freq >= 2482) && (freq < 2487))
  1695. return 14;
  1696. else
  1697. return -1;
  1698. }
  1699. /* Convert IEEE802.11 HR DSSS channel to frequency (MHz) and back
  1700. * Ref IEEE 802.11-2007 section 18.4.6.2
  1701. *
  1702. * The channels and frequencies are the same as those defined for DSSS
  1703. */
  1704. #define ieee80211_hr_chan_to_freq(chan) ieee80211_dsss_chan_to_freq(chan)
  1705. #define ieee80211_freq_to_hr_chan(freq) ieee80211_freq_to_dsss_chan(freq)
  1706. /* Convert IEEE802.11 ERP channel to frequency (MHz) and back
  1707. * Ref IEEE 802.11-2007 section 19.4.2
  1708. */
  1709. #define ieee80211_erp_chan_to_freq(chan) ieee80211_hr_chan_to_freq(chan)
  1710. #define ieee80211_freq_to_erp_chan(freq) ieee80211_freq_to_hr_chan(freq)
  1711. /**
  1712. * ieee80211_ofdm_chan_to_freq - get channel center frequency
  1713. * @s_freq: starting frequency == (dotChannelStartingFactor/2) MHz
  1714. * @channel: the OFDM channel
  1715. *
  1716. * Convert IEEE802.11 OFDM channel to center frequency (MHz)
  1717. * Ref IEEE 802.11-2007 section 17.3.8.3.2
  1718. */
  1719. static inline int ieee80211_ofdm_chan_to_freq(int s_freq, int channel)
  1720. {
  1721. if ((channel > 0) && (channel <= 200) &&
  1722. (s_freq >= 4000))
  1723. return s_freq + (channel * 5);
  1724. else
  1725. return -1;
  1726. }
  1727. /**
  1728. * ieee80211_freq_to_ofdm_channel - get channel
  1729. * @s_freq: starting frequency == (dotChannelStartingFactor/2) MHz
  1730. * @freq: the frequency
  1731. *
  1732. * Convert frequency (MHz) to IEEE802.11 OFDM channel
  1733. * Ref IEEE 802.11-2007 section 17.3.8.3.2
  1734. *
  1735. * This routine selects the channel with the closest center frequency.
  1736. */
  1737. static inline int ieee80211_freq_to_ofdm_chan(int s_freq, int freq)
  1738. {
  1739. if ((freq > (s_freq + 2)) && (freq <= (s_freq + 1202)) &&
  1740. (s_freq >= 4000))
  1741. return (freq + 2 - s_freq) / 5;
  1742. else
  1743. return -1;
  1744. }
  1745. /**
  1746. * ieee80211_tu_to_usec - convert time units (TU) to microseconds
  1747. * @tu: the TUs
  1748. */
  1749. static inline unsigned long ieee80211_tu_to_usec(unsigned long tu)
  1750. {
  1751. return 1024 * tu;
  1752. }
  1753. /**
  1754. * ieee80211_check_tim - check if AID bit is set in TIM
  1755. * @tim: the TIM IE
  1756. * @tim_len: length of the TIM IE
  1757. * @aid: the AID to look for
  1758. */
  1759. static inline bool ieee80211_check_tim(struct ieee80211_tim_ie *tim,
  1760. u8 tim_len, u16 aid)
  1761. {
  1762. u8 mask;
  1763. u8 index, indexn1, indexn2;
  1764. if (unlikely(!tim || tim_len < sizeof(*tim)))
  1765. return false;
  1766. aid &= 0x3fff;
  1767. index = aid / 8;
  1768. mask = 1 << (aid & 7);
  1769. indexn1 = tim->bitmap_ctrl & 0xfe;
  1770. indexn2 = tim_len + indexn1 - 4;
  1771. if (index < indexn1 || index > indexn2)
  1772. return false;
  1773. index -= indexn1;
  1774. return !!(tim->virtual_map[index] & mask);
  1775. }
  1776. struct element {
  1777. u8 id;
  1778. u8 datalen;
  1779. u8 data[];
  1780. } __packed;
  1781. /* element iteration helpers */
  1782. #define for_each_element(_elem, _data, _datalen) \
  1783. for (_elem = (const struct element *)(_data); \
  1784. (const u8 *)(_data) + (_datalen) - (const u8 *)_elem >= \
  1785. (int)sizeof(*_elem) && \
  1786. (const u8 *)(_data) + (_datalen) - (const u8 *)_elem >= \
  1787. (int)sizeof(*_elem) + _elem->datalen; \
  1788. _elem = (const struct element *)(_elem->data + _elem->datalen))
  1789. #define for_each_element_id(element, _id, data, datalen) \
  1790. for_each_element(element, data, datalen) \
  1791. if (element->id == (_id))
  1792. #define for_each_element_extid(element, extid, data, datalen) \
  1793. for_each_element(element, data, datalen) \
  1794. if (element->id == WLAN_EID_EXTENSION && \
  1795. element->datalen > 0 && \
  1796. element->data[0] == (extid))
  1797. #define for_each_subelement(sub, element) \
  1798. for_each_element(sub, (element)->data, (element)->datalen)
  1799. #define for_each_subelement_id(sub, id, element) \
  1800. for_each_element_id(sub, id, (element)->data, (element)->datalen)
  1801. #define for_each_subelement_extid(sub, extid, element) \
  1802. for_each_element_extid(sub, extid, (element)->data, (element)->datalen)
  1803. /**
  1804. * for_each_element_completed - determine if element parsing consumed all data
  1805. * @element: element pointer after for_each_element() or friends
  1806. * @data: same data pointer as passed to for_each_element() or friends
  1807. * @datalen: same data length as passed to for_each_element() or friends
  1808. *
  1809. * This function returns %true if all the data was parsed or considered
  1810. * while walking the elements. Only use this if your for_each_element()
  1811. * loop cannot be broken out of, otherwise it always returns %false.
  1812. *
  1813. * If some data was malformed, this returns %false since the last parsed
  1814. * element will not fill the whole remaining data.
  1815. */
  1816. static inline bool for_each_element_completed(const struct element *element,
  1817. const void *data, size_t datalen)
  1818. {
  1819. return (const u8 *)element == (const u8 *)data + datalen;
  1820. }
  1821. #endif /* LINUX_IEEE80211_H */