ieee80211.h 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385
  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_MESH_CONFIG_LEN 19
  104. #define IEEE80211_QOS_CTL_LEN 2
  105. #define IEEE80211_QOS_CTL_TID_MASK 0x000F
  106. #define IEEE80211_QOS_CTL_TAG1D_MASK 0x0007
  107. struct ieee80211_hdr {
  108. __le16 frame_control;
  109. __le16 duration_id;
  110. u8 addr1[6];
  111. u8 addr2[6];
  112. u8 addr3[6];
  113. __le16 seq_ctrl;
  114. u8 addr4[6];
  115. } __attribute__ ((packed));
  116. /**
  117. * ieee80211_has_tods - check if IEEE80211_FCTL_TODS is set
  118. * @fc: frame control bytes in little-endian byteorder
  119. */
  120. static inline int ieee80211_has_tods(__le16 fc)
  121. {
  122. return (fc & cpu_to_le16(IEEE80211_FCTL_TODS)) != 0;
  123. }
  124. /**
  125. * ieee80211_has_fromds - check if IEEE80211_FCTL_FROMDS is set
  126. * @fc: frame control bytes in little-endian byteorder
  127. */
  128. static inline int ieee80211_has_fromds(__le16 fc)
  129. {
  130. return (fc & cpu_to_le16(IEEE80211_FCTL_FROMDS)) != 0;
  131. }
  132. /**
  133. * ieee80211_has_a4 - check if IEEE80211_FCTL_TODS and IEEE80211_FCTL_FROMDS are set
  134. * @fc: frame control bytes in little-endian byteorder
  135. */
  136. static inline int ieee80211_has_a4(__le16 fc)
  137. {
  138. __le16 tmp = cpu_to_le16(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS);
  139. return (fc & tmp) == tmp;
  140. }
  141. /**
  142. * ieee80211_has_morefrags - check if IEEE80211_FCTL_MOREFRAGS is set
  143. * @fc: frame control bytes in little-endian byteorder
  144. */
  145. static inline int ieee80211_has_morefrags(__le16 fc)
  146. {
  147. return (fc & cpu_to_le16(IEEE80211_FCTL_MOREFRAGS)) != 0;
  148. }
  149. /**
  150. * ieee80211_has_retry - check if IEEE80211_FCTL_RETRY is set
  151. * @fc: frame control bytes in little-endian byteorder
  152. */
  153. static inline int ieee80211_has_retry(__le16 fc)
  154. {
  155. return (fc & cpu_to_le16(IEEE80211_FCTL_RETRY)) != 0;
  156. }
  157. /**
  158. * ieee80211_has_pm - check if IEEE80211_FCTL_PM is set
  159. * @fc: frame control bytes in little-endian byteorder
  160. */
  161. static inline int ieee80211_has_pm(__le16 fc)
  162. {
  163. return (fc & cpu_to_le16(IEEE80211_FCTL_PM)) != 0;
  164. }
  165. /**
  166. * ieee80211_has_moredata - check if IEEE80211_FCTL_MOREDATA is set
  167. * @fc: frame control bytes in little-endian byteorder
  168. */
  169. static inline int ieee80211_has_moredata(__le16 fc)
  170. {
  171. return (fc & cpu_to_le16(IEEE80211_FCTL_MOREDATA)) != 0;
  172. }
  173. /**
  174. * ieee80211_has_protected - check if IEEE80211_FCTL_PROTECTED is set
  175. * @fc: frame control bytes in little-endian byteorder
  176. */
  177. static inline int ieee80211_has_protected(__le16 fc)
  178. {
  179. return (fc & cpu_to_le16(IEEE80211_FCTL_PROTECTED)) != 0;
  180. }
  181. /**
  182. * ieee80211_has_order - check if IEEE80211_FCTL_ORDER is set
  183. * @fc: frame control bytes in little-endian byteorder
  184. */
  185. static inline int ieee80211_has_order(__le16 fc)
  186. {
  187. return (fc & cpu_to_le16(IEEE80211_FCTL_ORDER)) != 0;
  188. }
  189. /**
  190. * ieee80211_is_mgmt - check if type is IEEE80211_FTYPE_MGMT
  191. * @fc: frame control bytes in little-endian byteorder
  192. */
  193. static inline int ieee80211_is_mgmt(__le16 fc)
  194. {
  195. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE)) ==
  196. cpu_to_le16(IEEE80211_FTYPE_MGMT);
  197. }
  198. /**
  199. * ieee80211_is_ctl - check if type is IEEE80211_FTYPE_CTL
  200. * @fc: frame control bytes in little-endian byteorder
  201. */
  202. static inline int ieee80211_is_ctl(__le16 fc)
  203. {
  204. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE)) ==
  205. cpu_to_le16(IEEE80211_FTYPE_CTL);
  206. }
  207. /**
  208. * ieee80211_is_data - check if type is IEEE80211_FTYPE_DATA
  209. * @fc: frame control bytes in little-endian byteorder
  210. */
  211. static inline int ieee80211_is_data(__le16 fc)
  212. {
  213. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE)) ==
  214. cpu_to_le16(IEEE80211_FTYPE_DATA);
  215. }
  216. /**
  217. * ieee80211_is_data_qos - check if type is IEEE80211_FTYPE_DATA and IEEE80211_STYPE_QOS_DATA is set
  218. * @fc: frame control bytes in little-endian byteorder
  219. */
  220. static inline int ieee80211_is_data_qos(__le16 fc)
  221. {
  222. /*
  223. * mask with QOS_DATA rather than IEEE80211_FCTL_STYPE as we just need
  224. * to check the one bit
  225. */
  226. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_STYPE_QOS_DATA)) ==
  227. cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_QOS_DATA);
  228. }
  229. /**
  230. * ieee80211_is_data_present - check if type is IEEE80211_FTYPE_DATA and has data
  231. * @fc: frame control bytes in little-endian byteorder
  232. */
  233. static inline int ieee80211_is_data_present(__le16 fc)
  234. {
  235. /*
  236. * mask with 0x40 and test that that bit is clear to only return true
  237. * for the data-containing substypes.
  238. */
  239. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | 0x40)) ==
  240. cpu_to_le16(IEEE80211_FTYPE_DATA);
  241. }
  242. /**
  243. * ieee80211_is_assoc_req - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_ASSOC_REQ
  244. * @fc: frame control bytes in little-endian byteorder
  245. */
  246. static inline int ieee80211_is_assoc_req(__le16 fc)
  247. {
  248. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
  249. cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ASSOC_REQ);
  250. }
  251. /**
  252. * ieee80211_is_assoc_resp - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_ASSOC_RESP
  253. * @fc: frame control bytes in little-endian byteorder
  254. */
  255. static inline int ieee80211_is_assoc_resp(__le16 fc)
  256. {
  257. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
  258. cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ASSOC_RESP);
  259. }
  260. /**
  261. * ieee80211_is_reassoc_req - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_REASSOC_REQ
  262. * @fc: frame control bytes in little-endian byteorder
  263. */
  264. static inline int ieee80211_is_reassoc_req(__le16 fc)
  265. {
  266. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
  267. cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_REASSOC_REQ);
  268. }
  269. /**
  270. * ieee80211_is_reassoc_resp - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_REASSOC_RESP
  271. * @fc: frame control bytes in little-endian byteorder
  272. */
  273. static inline int ieee80211_is_reassoc_resp(__le16 fc)
  274. {
  275. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
  276. cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_REASSOC_RESP);
  277. }
  278. /**
  279. * ieee80211_is_probe_req - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_PROBE_REQ
  280. * @fc: frame control bytes in little-endian byteorder
  281. */
  282. static inline int ieee80211_is_probe_req(__le16 fc)
  283. {
  284. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
  285. cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ);
  286. }
  287. /**
  288. * ieee80211_is_probe_resp - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_PROBE_RESP
  289. * @fc: frame control bytes in little-endian byteorder
  290. */
  291. static inline int ieee80211_is_probe_resp(__le16 fc)
  292. {
  293. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
  294. cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_RESP);
  295. }
  296. /**
  297. * ieee80211_is_beacon - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_BEACON
  298. * @fc: frame control bytes in little-endian byteorder
  299. */
  300. static inline int ieee80211_is_beacon(__le16 fc)
  301. {
  302. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
  303. cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_BEACON);
  304. }
  305. /**
  306. * ieee80211_is_atim - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_ATIM
  307. * @fc: frame control bytes in little-endian byteorder
  308. */
  309. static inline int ieee80211_is_atim(__le16 fc)
  310. {
  311. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
  312. cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ATIM);
  313. }
  314. /**
  315. * ieee80211_is_disassoc - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_DISASSOC
  316. * @fc: frame control bytes in little-endian byteorder
  317. */
  318. static inline int ieee80211_is_disassoc(__le16 fc)
  319. {
  320. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
  321. cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_DISASSOC);
  322. }
  323. /**
  324. * ieee80211_is_auth - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_AUTH
  325. * @fc: frame control bytes in little-endian byteorder
  326. */
  327. static inline int ieee80211_is_auth(__le16 fc)
  328. {
  329. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
  330. cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_AUTH);
  331. }
  332. /**
  333. * ieee80211_is_deauth - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_DEAUTH
  334. * @fc: frame control bytes in little-endian byteorder
  335. */
  336. static inline int ieee80211_is_deauth(__le16 fc)
  337. {
  338. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
  339. cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_DEAUTH);
  340. }
  341. /**
  342. * ieee80211_is_action - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_ACTION
  343. * @fc: frame control bytes in little-endian byteorder
  344. */
  345. static inline int ieee80211_is_action(__le16 fc)
  346. {
  347. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
  348. cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION);
  349. }
  350. /**
  351. * ieee80211_is_back_req - check if IEEE80211_FTYPE_CTL && IEEE80211_STYPE_BACK_REQ
  352. * @fc: frame control bytes in little-endian byteorder
  353. */
  354. static inline int ieee80211_is_back_req(__le16 fc)
  355. {
  356. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
  357. cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_BACK_REQ);
  358. }
  359. /**
  360. * ieee80211_is_back - check if IEEE80211_FTYPE_CTL && IEEE80211_STYPE_BACK
  361. * @fc: frame control bytes in little-endian byteorder
  362. */
  363. static inline int ieee80211_is_back(__le16 fc)
  364. {
  365. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
  366. cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_BACK);
  367. }
  368. /**
  369. * ieee80211_is_pspoll - check if IEEE80211_FTYPE_CTL && IEEE80211_STYPE_PSPOLL
  370. * @fc: frame control bytes in little-endian byteorder
  371. */
  372. static inline int ieee80211_is_pspoll(__le16 fc)
  373. {
  374. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
  375. cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_PSPOLL);
  376. }
  377. /**
  378. * ieee80211_is_rts - check if IEEE80211_FTYPE_CTL && IEEE80211_STYPE_RTS
  379. * @fc: frame control bytes in little-endian byteorder
  380. */
  381. static inline int ieee80211_is_rts(__le16 fc)
  382. {
  383. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
  384. cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
  385. }
  386. /**
  387. * ieee80211_is_cts - check if IEEE80211_FTYPE_CTL && IEEE80211_STYPE_CTS
  388. * @fc: frame control bytes in little-endian byteorder
  389. */
  390. static inline int ieee80211_is_cts(__le16 fc)
  391. {
  392. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
  393. cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
  394. }
  395. /**
  396. * ieee80211_is_ack - check if IEEE80211_FTYPE_CTL && IEEE80211_STYPE_ACK
  397. * @fc: frame control bytes in little-endian byteorder
  398. */
  399. static inline int ieee80211_is_ack(__le16 fc)
  400. {
  401. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
  402. cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_ACK);
  403. }
  404. /**
  405. * ieee80211_is_cfend - check if IEEE80211_FTYPE_CTL && IEEE80211_STYPE_CFEND
  406. * @fc: frame control bytes in little-endian byteorder
  407. */
  408. static inline int ieee80211_is_cfend(__le16 fc)
  409. {
  410. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
  411. cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CFEND);
  412. }
  413. /**
  414. * ieee80211_is_cfendack - check if IEEE80211_FTYPE_CTL && IEEE80211_STYPE_CFENDACK
  415. * @fc: frame control bytes in little-endian byteorder
  416. */
  417. static inline int ieee80211_is_cfendack(__le16 fc)
  418. {
  419. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
  420. cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CFENDACK);
  421. }
  422. /**
  423. * ieee80211_is_nullfunc - check if FTYPE=IEEE80211_FTYPE_DATA and STYPE=IEEE80211_STYPE_NULLFUNC
  424. * @fc: frame control bytes in little-endian byteorder
  425. */
  426. static inline int ieee80211_is_nullfunc(__le16 fc)
  427. {
  428. return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
  429. cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC);
  430. }
  431. struct ieee80211s_hdr {
  432. u8 flags;
  433. u8 ttl;
  434. __le32 seqnum;
  435. u8 eaddr1[6];
  436. u8 eaddr2[6];
  437. u8 eaddr3[6];
  438. } __attribute__ ((packed));
  439. /* Mesh flags */
  440. #define MESH_FLAGS_AE_A4 0x1
  441. #define MESH_FLAGS_AE_A5_A6 0x2
  442. #define MESH_FLAGS_PS_DEEP 0x4
  443. /**
  444. * struct ieee80211_quiet_ie
  445. *
  446. * This structure refers to "Quiet information element"
  447. */
  448. struct ieee80211_quiet_ie {
  449. u8 count;
  450. u8 period;
  451. __le16 duration;
  452. __le16 offset;
  453. } __attribute__ ((packed));
  454. /**
  455. * struct ieee80211_msrment_ie
  456. *
  457. * This structure refers to "Measurement Request/Report information element"
  458. */
  459. struct ieee80211_msrment_ie {
  460. u8 token;
  461. u8 mode;
  462. u8 type;
  463. u8 request[0];
  464. } __attribute__ ((packed));
  465. /**
  466. * struct ieee80211_channel_sw_ie
  467. *
  468. * This structure refers to "Channel Switch Announcement information element"
  469. */
  470. struct ieee80211_channel_sw_ie {
  471. u8 mode;
  472. u8 new_ch_num;
  473. u8 count;
  474. } __attribute__ ((packed));
  475. /**
  476. * struct ieee80211_tim
  477. *
  478. * This structure refers to "Traffic Indication Map information element"
  479. */
  480. struct ieee80211_tim_ie {
  481. u8 dtim_count;
  482. u8 dtim_period;
  483. u8 bitmap_ctrl;
  484. /* variable size: 1 - 251 bytes */
  485. u8 virtual_map[0];
  486. } __attribute__ ((packed));
  487. #define WLAN_SA_QUERY_TR_ID_LEN 16
  488. struct ieee80211_mgmt {
  489. __le16 frame_control;
  490. __le16 duration;
  491. u8 da[6];
  492. u8 sa[6];
  493. u8 bssid[6];
  494. __le16 seq_ctrl;
  495. union {
  496. struct {
  497. __le16 auth_alg;
  498. __le16 auth_transaction;
  499. __le16 status_code;
  500. /* possibly followed by Challenge text */
  501. u8 variable[0];
  502. } __attribute__ ((packed)) auth;
  503. struct {
  504. __le16 reason_code;
  505. } __attribute__ ((packed)) deauth;
  506. struct {
  507. __le16 capab_info;
  508. __le16 listen_interval;
  509. /* followed by SSID and Supported rates */
  510. u8 variable[0];
  511. } __attribute__ ((packed)) assoc_req;
  512. struct {
  513. __le16 capab_info;
  514. __le16 status_code;
  515. __le16 aid;
  516. /* followed by Supported rates */
  517. u8 variable[0];
  518. } __attribute__ ((packed)) assoc_resp, reassoc_resp;
  519. struct {
  520. __le16 capab_info;
  521. __le16 listen_interval;
  522. u8 current_ap[6];
  523. /* followed by SSID and Supported rates */
  524. u8 variable[0];
  525. } __attribute__ ((packed)) reassoc_req;
  526. struct {
  527. __le16 reason_code;
  528. } __attribute__ ((packed)) disassoc;
  529. struct {
  530. __le64 timestamp;
  531. __le16 beacon_int;
  532. __le16 capab_info;
  533. /* followed by some of SSID, Supported rates,
  534. * FH Params, DS Params, CF Params, IBSS Params, TIM */
  535. u8 variable[0];
  536. } __attribute__ ((packed)) beacon;
  537. struct {
  538. /* only variable items: SSID, Supported rates */
  539. u8 variable[0];
  540. } __attribute__ ((packed)) probe_req;
  541. struct {
  542. __le64 timestamp;
  543. __le16 beacon_int;
  544. __le16 capab_info;
  545. /* followed by some of SSID, Supported rates,
  546. * FH Params, DS Params, CF Params, IBSS Params */
  547. u8 variable[0];
  548. } __attribute__ ((packed)) probe_resp;
  549. struct {
  550. u8 category;
  551. union {
  552. struct {
  553. u8 action_code;
  554. u8 dialog_token;
  555. u8 status_code;
  556. u8 variable[0];
  557. } __attribute__ ((packed)) wme_action;
  558. struct{
  559. u8 action_code;
  560. u8 element_id;
  561. u8 length;
  562. struct ieee80211_channel_sw_ie sw_elem;
  563. } __attribute__((packed)) chan_switch;
  564. struct{
  565. u8 action_code;
  566. u8 dialog_token;
  567. u8 element_id;
  568. u8 length;
  569. struct ieee80211_msrment_ie msr_elem;
  570. } __attribute__((packed)) measurement;
  571. struct{
  572. u8 action_code;
  573. u8 dialog_token;
  574. __le16 capab;
  575. __le16 timeout;
  576. __le16 start_seq_num;
  577. } __attribute__((packed)) addba_req;
  578. struct{
  579. u8 action_code;
  580. u8 dialog_token;
  581. __le16 status;
  582. __le16 capab;
  583. __le16 timeout;
  584. } __attribute__((packed)) addba_resp;
  585. struct{
  586. u8 action_code;
  587. __le16 params;
  588. __le16 reason_code;
  589. } __attribute__((packed)) delba;
  590. struct{
  591. u8 action_code;
  592. /* capab_info for open and confirm,
  593. * reason for close
  594. */
  595. __le16 aux;
  596. /* Followed in plink_confirm by status
  597. * code, AID and supported rates,
  598. * and directly by supported rates in
  599. * plink_open and plink_close
  600. */
  601. u8 variable[0];
  602. } __attribute__((packed)) plink_action;
  603. struct{
  604. u8 action_code;
  605. u8 variable[0];
  606. } __attribute__((packed)) mesh_action;
  607. struct {
  608. u8 action;
  609. u8 trans_id[WLAN_SA_QUERY_TR_ID_LEN];
  610. } __attribute__ ((packed)) sa_query;
  611. } u;
  612. } __attribute__ ((packed)) action;
  613. } u;
  614. } __attribute__ ((packed));
  615. /* mgmt header + 1 byte category code */
  616. #define IEEE80211_MIN_ACTION_SIZE offsetof(struct ieee80211_mgmt, u.action.u)
  617. /* Management MIC information element (IEEE 802.11w) */
  618. struct ieee80211_mmie {
  619. u8 element_id;
  620. u8 length;
  621. __le16 key_id;
  622. u8 sequence_number[6];
  623. u8 mic[8];
  624. } __attribute__ ((packed));
  625. /* Control frames */
  626. struct ieee80211_rts {
  627. __le16 frame_control;
  628. __le16 duration;
  629. u8 ra[6];
  630. u8 ta[6];
  631. } __attribute__ ((packed));
  632. struct ieee80211_cts {
  633. __le16 frame_control;
  634. __le16 duration;
  635. u8 ra[6];
  636. } __attribute__ ((packed));
  637. struct ieee80211_pspoll {
  638. __le16 frame_control;
  639. __le16 aid;
  640. u8 bssid[6];
  641. u8 ta[6];
  642. } __attribute__ ((packed));
  643. /**
  644. * struct ieee80211_bar - HT Block Ack Request
  645. *
  646. * This structure refers to "HT BlockAckReq" as
  647. * described in 802.11n draft section 7.2.1.7.1
  648. */
  649. struct ieee80211_bar {
  650. __le16 frame_control;
  651. __le16 duration;
  652. __u8 ra[6];
  653. __u8 ta[6];
  654. __le16 control;
  655. __le16 start_seq_num;
  656. } __attribute__((packed));
  657. /* 802.11 BAR control masks */
  658. #define IEEE80211_BAR_CTRL_ACK_POLICY_NORMAL 0x0000
  659. #define IEEE80211_BAR_CTRL_CBMTID_COMPRESSED_BA 0x0004
  660. #define IEEE80211_HT_MCS_MASK_LEN 10
  661. /**
  662. * struct ieee80211_mcs_info - MCS information
  663. * @rx_mask: RX mask
  664. * @rx_highest: highest supported RX rate
  665. * @tx_params: TX parameters
  666. */
  667. struct ieee80211_mcs_info {
  668. u8 rx_mask[IEEE80211_HT_MCS_MASK_LEN];
  669. __le16 rx_highest;
  670. u8 tx_params;
  671. u8 reserved[3];
  672. } __attribute__((packed));
  673. /* 802.11n HT capability MSC set */
  674. #define IEEE80211_HT_MCS_RX_HIGHEST_MASK 0x3ff
  675. #define IEEE80211_HT_MCS_TX_DEFINED 0x01
  676. #define IEEE80211_HT_MCS_TX_RX_DIFF 0x02
  677. /* value 0 == 1 stream etc */
  678. #define IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK 0x0C
  679. #define IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT 2
  680. #define IEEE80211_HT_MCS_TX_MAX_STREAMS 4
  681. #define IEEE80211_HT_MCS_TX_UNEQUAL_MODULATION 0x10
  682. /*
  683. * 802.11n D5.0 20.3.5 / 20.6 says:
  684. * - indices 0 to 7 and 32 are single spatial stream
  685. * - 8 to 31 are multiple spatial streams using equal modulation
  686. * [8..15 for two streams, 16..23 for three and 24..31 for four]
  687. * - remainder are multiple spatial streams using unequal modulation
  688. */
  689. #define IEEE80211_HT_MCS_UNEQUAL_MODULATION_START 33
  690. #define IEEE80211_HT_MCS_UNEQUAL_MODULATION_START_BYTE \
  691. (IEEE80211_HT_MCS_UNEQUAL_MODULATION_START / 8)
  692. /**
  693. * struct ieee80211_ht_cap - HT capabilities
  694. *
  695. * This structure is the "HT capabilities element" as
  696. * described in 802.11n D5.0 7.3.2.57
  697. */
  698. struct ieee80211_ht_cap {
  699. __le16 cap_info;
  700. u8 ampdu_params_info;
  701. /* 16 bytes MCS information */
  702. struct ieee80211_mcs_info mcs;
  703. __le16 extended_ht_cap_info;
  704. __le32 tx_BF_cap_info;
  705. u8 antenna_selection_info;
  706. } __attribute__ ((packed));
  707. /* 802.11n HT capabilities masks (for cap_info) */
  708. #define IEEE80211_HT_CAP_LDPC_CODING 0x0001
  709. #define IEEE80211_HT_CAP_SUP_WIDTH_20_40 0x0002
  710. #define IEEE80211_HT_CAP_SM_PS 0x000C
  711. #define IEEE80211_HT_CAP_GRN_FLD 0x0010
  712. #define IEEE80211_HT_CAP_SGI_20 0x0020
  713. #define IEEE80211_HT_CAP_SGI_40 0x0040
  714. #define IEEE80211_HT_CAP_TX_STBC 0x0080
  715. #define IEEE80211_HT_CAP_RX_STBC 0x0300
  716. #define IEEE80211_HT_CAP_DELAY_BA 0x0400
  717. #define IEEE80211_HT_CAP_MAX_AMSDU 0x0800
  718. #define IEEE80211_HT_CAP_DSSSCCK40 0x1000
  719. #define IEEE80211_HT_CAP_PSMP_SUPPORT 0x2000
  720. #define IEEE80211_HT_CAP_40MHZ_INTOLERANT 0x4000
  721. #define IEEE80211_HT_CAP_LSIG_TXOP_PROT 0x8000
  722. /* 802.11n HT capability AMPDU settings (for ampdu_params_info) */
  723. #define IEEE80211_HT_AMPDU_PARM_FACTOR 0x03
  724. #define IEEE80211_HT_AMPDU_PARM_DENSITY 0x1C
  725. /**
  726. * struct ieee80211_ht_info - HT information
  727. *
  728. * This structure is the "HT information element" as
  729. * described in 802.11n D5.0 7.3.2.58
  730. */
  731. struct ieee80211_ht_info {
  732. u8 control_chan;
  733. u8 ht_param;
  734. __le16 operation_mode;
  735. __le16 stbc_param;
  736. u8 basic_set[16];
  737. } __attribute__ ((packed));
  738. /* for ht_param */
  739. #define IEEE80211_HT_PARAM_CHA_SEC_OFFSET 0x03
  740. #define IEEE80211_HT_PARAM_CHA_SEC_NONE 0x00
  741. #define IEEE80211_HT_PARAM_CHA_SEC_ABOVE 0x01
  742. #define IEEE80211_HT_PARAM_CHA_SEC_BELOW 0x03
  743. #define IEEE80211_HT_PARAM_CHAN_WIDTH_ANY 0x04
  744. #define IEEE80211_HT_PARAM_RIFS_MODE 0x08
  745. #define IEEE80211_HT_PARAM_SPSMP_SUPPORT 0x10
  746. #define IEEE80211_HT_PARAM_SERV_INTERVAL_GRAN 0xE0
  747. /* for operation_mode */
  748. #define IEEE80211_HT_OP_MODE_PROTECTION 0x0003
  749. #define IEEE80211_HT_OP_MODE_PROTECTION_NONE 0
  750. #define IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER 1
  751. #define IEEE80211_HT_OP_MODE_PROTECTION_20MHZ 2
  752. #define IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED 3
  753. #define IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT 0x0004
  754. #define IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT 0x0010
  755. /* for stbc_param */
  756. #define IEEE80211_HT_STBC_PARAM_DUAL_BEACON 0x0040
  757. #define IEEE80211_HT_STBC_PARAM_DUAL_CTS_PROT 0x0080
  758. #define IEEE80211_HT_STBC_PARAM_STBC_BEACON 0x0100
  759. #define IEEE80211_HT_STBC_PARAM_LSIG_TXOP_FULLPROT 0x0200
  760. #define IEEE80211_HT_STBC_PARAM_PCO_ACTIVE 0x0400
  761. #define IEEE80211_HT_STBC_PARAM_PCO_PHASE 0x0800
  762. /* block-ack parameters */
  763. #define IEEE80211_ADDBA_PARAM_POLICY_MASK 0x0002
  764. #define IEEE80211_ADDBA_PARAM_TID_MASK 0x003C
  765. #define IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK 0xFFA0
  766. #define IEEE80211_DELBA_PARAM_TID_MASK 0xF000
  767. #define IEEE80211_DELBA_PARAM_INITIATOR_MASK 0x0800
  768. /*
  769. * A-PMDU buffer sizes
  770. * According to IEEE802.11n spec size varies from 8K to 64K (in powers of 2)
  771. */
  772. #define IEEE80211_MIN_AMPDU_BUF 0x8
  773. #define IEEE80211_MAX_AMPDU_BUF 0x40
  774. /* Spatial Multiplexing Power Save Modes */
  775. #define WLAN_HT_CAP_SM_PS_STATIC 0
  776. #define WLAN_HT_CAP_SM_PS_DYNAMIC 1
  777. #define WLAN_HT_CAP_SM_PS_INVALID 2
  778. #define WLAN_HT_CAP_SM_PS_DISABLED 3
  779. /* Authentication algorithms */
  780. #define WLAN_AUTH_OPEN 0
  781. #define WLAN_AUTH_SHARED_KEY 1
  782. #define WLAN_AUTH_LEAP 128
  783. #define WLAN_AUTH_CHALLENGE_LEN 128
  784. #define WLAN_CAPABILITY_ESS (1<<0)
  785. #define WLAN_CAPABILITY_IBSS (1<<1)
  786. #define WLAN_CAPABILITY_CF_POLLABLE (1<<2)
  787. #define WLAN_CAPABILITY_CF_POLL_REQUEST (1<<3)
  788. #define WLAN_CAPABILITY_PRIVACY (1<<4)
  789. #define WLAN_CAPABILITY_SHORT_PREAMBLE (1<<5)
  790. #define WLAN_CAPABILITY_PBCC (1<<6)
  791. #define WLAN_CAPABILITY_CHANNEL_AGILITY (1<<7)
  792. /* 802.11h */
  793. #define WLAN_CAPABILITY_SPECTRUM_MGMT (1<<8)
  794. #define WLAN_CAPABILITY_QOS (1<<9)
  795. #define WLAN_CAPABILITY_SHORT_SLOT_TIME (1<<10)
  796. #define WLAN_CAPABILITY_DSSS_OFDM (1<<13)
  797. /* measurement */
  798. #define IEEE80211_SPCT_MSR_RPRT_MODE_LATE (1<<0)
  799. #define IEEE80211_SPCT_MSR_RPRT_MODE_INCAPABLE (1<<1)
  800. #define IEEE80211_SPCT_MSR_RPRT_MODE_REFUSED (1<<2)
  801. #define IEEE80211_SPCT_MSR_RPRT_TYPE_BASIC 0
  802. #define IEEE80211_SPCT_MSR_RPRT_TYPE_CCA 1
  803. #define IEEE80211_SPCT_MSR_RPRT_TYPE_RPI 2
  804. /* 802.11g ERP information element */
  805. #define WLAN_ERP_NON_ERP_PRESENT (1<<0)
  806. #define WLAN_ERP_USE_PROTECTION (1<<1)
  807. #define WLAN_ERP_BARKER_PREAMBLE (1<<2)
  808. /* WLAN_ERP_BARKER_PREAMBLE values */
  809. enum {
  810. WLAN_ERP_PREAMBLE_SHORT = 0,
  811. WLAN_ERP_PREAMBLE_LONG = 1,
  812. };
  813. /* Status codes */
  814. enum ieee80211_statuscode {
  815. WLAN_STATUS_SUCCESS = 0,
  816. WLAN_STATUS_UNSPECIFIED_FAILURE = 1,
  817. WLAN_STATUS_CAPS_UNSUPPORTED = 10,
  818. WLAN_STATUS_REASSOC_NO_ASSOC = 11,
  819. WLAN_STATUS_ASSOC_DENIED_UNSPEC = 12,
  820. WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG = 13,
  821. WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION = 14,
  822. WLAN_STATUS_CHALLENGE_FAIL = 15,
  823. WLAN_STATUS_AUTH_TIMEOUT = 16,
  824. WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA = 17,
  825. WLAN_STATUS_ASSOC_DENIED_RATES = 18,
  826. /* 802.11b */
  827. WLAN_STATUS_ASSOC_DENIED_NOSHORTPREAMBLE = 19,
  828. WLAN_STATUS_ASSOC_DENIED_NOPBCC = 20,
  829. WLAN_STATUS_ASSOC_DENIED_NOAGILITY = 21,
  830. /* 802.11h */
  831. WLAN_STATUS_ASSOC_DENIED_NOSPECTRUM = 22,
  832. WLAN_STATUS_ASSOC_REJECTED_BAD_POWER = 23,
  833. WLAN_STATUS_ASSOC_REJECTED_BAD_SUPP_CHAN = 24,
  834. /* 802.11g */
  835. WLAN_STATUS_ASSOC_DENIED_NOSHORTTIME = 25,
  836. WLAN_STATUS_ASSOC_DENIED_NODSSSOFDM = 26,
  837. /* 802.11w */
  838. WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY = 30,
  839. WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION = 31,
  840. /* 802.11i */
  841. WLAN_STATUS_INVALID_IE = 40,
  842. WLAN_STATUS_INVALID_GROUP_CIPHER = 41,
  843. WLAN_STATUS_INVALID_PAIRWISE_CIPHER = 42,
  844. WLAN_STATUS_INVALID_AKMP = 43,
  845. WLAN_STATUS_UNSUPP_RSN_VERSION = 44,
  846. WLAN_STATUS_INVALID_RSN_IE_CAP = 45,
  847. WLAN_STATUS_CIPHER_SUITE_REJECTED = 46,
  848. /* 802.11e */
  849. WLAN_STATUS_UNSPECIFIED_QOS = 32,
  850. WLAN_STATUS_ASSOC_DENIED_NOBANDWIDTH = 33,
  851. WLAN_STATUS_ASSOC_DENIED_LOWACK = 34,
  852. WLAN_STATUS_ASSOC_DENIED_UNSUPP_QOS = 35,
  853. WLAN_STATUS_REQUEST_DECLINED = 37,
  854. WLAN_STATUS_INVALID_QOS_PARAM = 38,
  855. WLAN_STATUS_CHANGE_TSPEC = 39,
  856. WLAN_STATUS_WAIT_TS_DELAY = 47,
  857. WLAN_STATUS_NO_DIRECT_LINK = 48,
  858. WLAN_STATUS_STA_NOT_PRESENT = 49,
  859. WLAN_STATUS_STA_NOT_QSTA = 50,
  860. };
  861. /* Reason codes */
  862. enum ieee80211_reasoncode {
  863. WLAN_REASON_UNSPECIFIED = 1,
  864. WLAN_REASON_PREV_AUTH_NOT_VALID = 2,
  865. WLAN_REASON_DEAUTH_LEAVING = 3,
  866. WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY = 4,
  867. WLAN_REASON_DISASSOC_AP_BUSY = 5,
  868. WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA = 6,
  869. WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA = 7,
  870. WLAN_REASON_DISASSOC_STA_HAS_LEFT = 8,
  871. WLAN_REASON_STA_REQ_ASSOC_WITHOUT_AUTH = 9,
  872. /* 802.11h */
  873. WLAN_REASON_DISASSOC_BAD_POWER = 10,
  874. WLAN_REASON_DISASSOC_BAD_SUPP_CHAN = 11,
  875. /* 802.11i */
  876. WLAN_REASON_INVALID_IE = 13,
  877. WLAN_REASON_MIC_FAILURE = 14,
  878. WLAN_REASON_4WAY_HANDSHAKE_TIMEOUT = 15,
  879. WLAN_REASON_GROUP_KEY_HANDSHAKE_TIMEOUT = 16,
  880. WLAN_REASON_IE_DIFFERENT = 17,
  881. WLAN_REASON_INVALID_GROUP_CIPHER = 18,
  882. WLAN_REASON_INVALID_PAIRWISE_CIPHER = 19,
  883. WLAN_REASON_INVALID_AKMP = 20,
  884. WLAN_REASON_UNSUPP_RSN_VERSION = 21,
  885. WLAN_REASON_INVALID_RSN_IE_CAP = 22,
  886. WLAN_REASON_IEEE8021X_FAILED = 23,
  887. WLAN_REASON_CIPHER_SUITE_REJECTED = 24,
  888. /* 802.11e */
  889. WLAN_REASON_DISASSOC_UNSPECIFIED_QOS = 32,
  890. WLAN_REASON_DISASSOC_QAP_NO_BANDWIDTH = 33,
  891. WLAN_REASON_DISASSOC_LOW_ACK = 34,
  892. WLAN_REASON_DISASSOC_QAP_EXCEED_TXOP = 35,
  893. WLAN_REASON_QSTA_LEAVE_QBSS = 36,
  894. WLAN_REASON_QSTA_NOT_USE = 37,
  895. WLAN_REASON_QSTA_REQUIRE_SETUP = 38,
  896. WLAN_REASON_QSTA_TIMEOUT = 39,
  897. WLAN_REASON_QSTA_CIPHER_NOT_SUPP = 45,
  898. };
  899. /* Information Element IDs */
  900. enum ieee80211_eid {
  901. WLAN_EID_SSID = 0,
  902. WLAN_EID_SUPP_RATES = 1,
  903. WLAN_EID_FH_PARAMS = 2,
  904. WLAN_EID_DS_PARAMS = 3,
  905. WLAN_EID_CF_PARAMS = 4,
  906. WLAN_EID_TIM = 5,
  907. WLAN_EID_IBSS_PARAMS = 6,
  908. WLAN_EID_CHALLENGE = 16,
  909. /* 802.11d */
  910. WLAN_EID_COUNTRY = 7,
  911. WLAN_EID_HP_PARAMS = 8,
  912. WLAN_EID_HP_TABLE = 9,
  913. WLAN_EID_REQUEST = 10,
  914. /* 802.11e */
  915. WLAN_EID_QBSS_LOAD = 11,
  916. WLAN_EID_EDCA_PARAM_SET = 12,
  917. WLAN_EID_TSPEC = 13,
  918. WLAN_EID_TCLAS = 14,
  919. WLAN_EID_SCHEDULE = 15,
  920. WLAN_EID_TS_DELAY = 43,
  921. WLAN_EID_TCLAS_PROCESSING = 44,
  922. WLAN_EID_QOS_CAPA = 46,
  923. /* 802.11s
  924. *
  925. * All mesh EID numbers are pending IEEE 802.11 ANA approval.
  926. * The numbers have been incremented from those suggested in
  927. * 802.11s/D2.0 so that MESH_CONFIG does not conflict with
  928. * EXT_SUPP_RATES.
  929. */
  930. WLAN_EID_MESH_CONFIG = 51,
  931. WLAN_EID_MESH_ID = 52,
  932. WLAN_EID_PEER_LINK = 55,
  933. WLAN_EID_PREQ = 68,
  934. WLAN_EID_PREP = 69,
  935. WLAN_EID_PERR = 70,
  936. /* 802.11h */
  937. WLAN_EID_PWR_CONSTRAINT = 32,
  938. WLAN_EID_PWR_CAPABILITY = 33,
  939. WLAN_EID_TPC_REQUEST = 34,
  940. WLAN_EID_TPC_REPORT = 35,
  941. WLAN_EID_SUPPORTED_CHANNELS = 36,
  942. WLAN_EID_CHANNEL_SWITCH = 37,
  943. WLAN_EID_MEASURE_REQUEST = 38,
  944. WLAN_EID_MEASURE_REPORT = 39,
  945. WLAN_EID_QUIET = 40,
  946. WLAN_EID_IBSS_DFS = 41,
  947. /* 802.11g */
  948. WLAN_EID_ERP_INFO = 42,
  949. WLAN_EID_EXT_SUPP_RATES = 50,
  950. /* 802.11n */
  951. WLAN_EID_HT_CAPABILITY = 45,
  952. WLAN_EID_HT_INFORMATION = 61,
  953. /* 802.11i */
  954. WLAN_EID_RSN = 48,
  955. WLAN_EID_TIMEOUT_INTERVAL = 56,
  956. WLAN_EID_MMIE = 76 /* 802.11w */,
  957. WLAN_EID_WPA = 221,
  958. WLAN_EID_GENERIC = 221,
  959. WLAN_EID_VENDOR_SPECIFIC = 221,
  960. WLAN_EID_QOS_PARAMETER = 222
  961. };
  962. /* Action category code */
  963. enum ieee80211_category {
  964. WLAN_CATEGORY_SPECTRUM_MGMT = 0,
  965. WLAN_CATEGORY_QOS = 1,
  966. WLAN_CATEGORY_DLS = 2,
  967. WLAN_CATEGORY_BACK = 3,
  968. WLAN_CATEGORY_PUBLIC = 4,
  969. WLAN_CATEGORY_SA_QUERY = 8,
  970. WLAN_CATEGORY_WMM = 17,
  971. };
  972. /* SPECTRUM_MGMT action code */
  973. enum ieee80211_spectrum_mgmt_actioncode {
  974. WLAN_ACTION_SPCT_MSR_REQ = 0,
  975. WLAN_ACTION_SPCT_MSR_RPRT = 1,
  976. WLAN_ACTION_SPCT_TPC_REQ = 2,
  977. WLAN_ACTION_SPCT_TPC_RPRT = 3,
  978. WLAN_ACTION_SPCT_CHL_SWITCH = 4,
  979. };
  980. /*
  981. * IEEE 802.11-2007 7.3.2.9 Country information element
  982. *
  983. * Minimum length is 8 octets, ie len must be evenly
  984. * divisible by 2
  985. */
  986. /* Although the spec says 8 I'm seeing 6 in practice */
  987. #define IEEE80211_COUNTRY_IE_MIN_LEN 6
  988. /*
  989. * For regulatory extension stuff see IEEE 802.11-2007
  990. * Annex I (page 1141) and Annex J (page 1147). Also
  991. * review 7.3.2.9.
  992. *
  993. * When dot11RegulatoryClassesRequired is true and the
  994. * first_channel/reg_extension_id is >= 201 then the IE
  995. * compromises of the 'ext' struct represented below:
  996. *
  997. * - Regulatory extension ID - when generating IE this just needs
  998. * to be monotonically increasing for each triplet passed in
  999. * the IE
  1000. * - Regulatory class - index into set of rules
  1001. * - Coverage class - index into air propagation time (Table 7-27),
  1002. * in microseconds, you can compute the air propagation time from
  1003. * the index by multiplying by 3, so index 10 yields a propagation
  1004. * of 10 us. Valid values are 0-31, values 32-255 are not defined
  1005. * yet. A value of 0 inicates air propagation of <= 1 us.
  1006. *
  1007. * See also Table I.2 for Emission limit sets and table
  1008. * I.3 for Behavior limit sets. Table J.1 indicates how to map
  1009. * a reg_class to an emission limit set and behavior limit set.
  1010. */
  1011. #define IEEE80211_COUNTRY_EXTENSION_ID 201
  1012. /*
  1013. * Channels numbers in the IE must be monotonically increasing
  1014. * if dot11RegulatoryClassesRequired is not true.
  1015. *
  1016. * If dot11RegulatoryClassesRequired is true consecutive
  1017. * subband triplets following a regulatory triplet shall
  1018. * have monotonically increasing first_channel number fields.
  1019. *
  1020. * Channel numbers shall not overlap.
  1021. *
  1022. * Note that max_power is signed.
  1023. */
  1024. struct ieee80211_country_ie_triplet {
  1025. union {
  1026. struct {
  1027. u8 first_channel;
  1028. u8 num_channels;
  1029. s8 max_power;
  1030. } __attribute__ ((packed)) chans;
  1031. struct {
  1032. u8 reg_extension_id;
  1033. u8 reg_class;
  1034. u8 coverage_class;
  1035. } __attribute__ ((packed)) ext;
  1036. };
  1037. } __attribute__ ((packed));
  1038. enum ieee80211_timeout_interval_type {
  1039. WLAN_TIMEOUT_REASSOC_DEADLINE = 1 /* 802.11r */,
  1040. WLAN_TIMEOUT_KEY_LIFETIME = 2 /* 802.11r */,
  1041. WLAN_TIMEOUT_ASSOC_COMEBACK = 3 /* 802.11w */,
  1042. };
  1043. /* BACK action code */
  1044. enum ieee80211_back_actioncode {
  1045. WLAN_ACTION_ADDBA_REQ = 0,
  1046. WLAN_ACTION_ADDBA_RESP = 1,
  1047. WLAN_ACTION_DELBA = 2,
  1048. };
  1049. /* BACK (block-ack) parties */
  1050. enum ieee80211_back_parties {
  1051. WLAN_BACK_RECIPIENT = 0,
  1052. WLAN_BACK_INITIATOR = 1,
  1053. WLAN_BACK_TIMER = 2,
  1054. };
  1055. /* SA Query action */
  1056. enum ieee80211_sa_query_action {
  1057. WLAN_ACTION_SA_QUERY_REQUEST = 0,
  1058. WLAN_ACTION_SA_QUERY_RESPONSE = 1,
  1059. };
  1060. /* A-MSDU 802.11n */
  1061. #define IEEE80211_QOS_CONTROL_A_MSDU_PRESENT 0x0080
  1062. /* cipher suite selectors */
  1063. #define WLAN_CIPHER_SUITE_USE_GROUP 0x000FAC00
  1064. #define WLAN_CIPHER_SUITE_WEP40 0x000FAC01
  1065. #define WLAN_CIPHER_SUITE_TKIP 0x000FAC02
  1066. /* reserved: 0x000FAC03 */
  1067. #define WLAN_CIPHER_SUITE_CCMP 0x000FAC04
  1068. #define WLAN_CIPHER_SUITE_WEP104 0x000FAC05
  1069. #define WLAN_CIPHER_SUITE_AES_CMAC 0x000FAC06
  1070. #define WLAN_MAX_KEY_LEN 32
  1071. /**
  1072. * ieee80211_get_qos_ctl - get pointer to qos control bytes
  1073. * @hdr: the frame
  1074. *
  1075. * The qos ctrl bytes come after the frame_control, duration, seq_num
  1076. * and 3 or 4 addresses of length ETH_ALEN.
  1077. * 3 addr: 2 + 2 + 2 + 3*6 = 24
  1078. * 4 addr: 2 + 2 + 2 + 4*6 = 30
  1079. */
  1080. static inline u8 *ieee80211_get_qos_ctl(struct ieee80211_hdr *hdr)
  1081. {
  1082. if (ieee80211_has_a4(hdr->frame_control))
  1083. return (u8 *)hdr + 30;
  1084. else
  1085. return (u8 *)hdr + 24;
  1086. }
  1087. /**
  1088. * ieee80211_get_SA - get pointer to SA
  1089. * @hdr: the frame
  1090. *
  1091. * Given an 802.11 frame, this function returns the offset
  1092. * to the source address (SA). It does not verify that the
  1093. * header is long enough to contain the address, and the
  1094. * header must be long enough to contain the frame control
  1095. * field.
  1096. */
  1097. static inline u8 *ieee80211_get_SA(struct ieee80211_hdr *hdr)
  1098. {
  1099. if (ieee80211_has_a4(hdr->frame_control))
  1100. return hdr->addr4;
  1101. if (ieee80211_has_fromds(hdr->frame_control))
  1102. return hdr->addr3;
  1103. return hdr->addr2;
  1104. }
  1105. /**
  1106. * ieee80211_get_DA - get pointer to DA
  1107. * @hdr: the frame
  1108. *
  1109. * Given an 802.11 frame, this function returns the offset
  1110. * to the destination address (DA). It does not verify that
  1111. * the header is long enough to contain the address, and the
  1112. * header must be long enough to contain the frame control
  1113. * field.
  1114. */
  1115. static inline u8 *ieee80211_get_DA(struct ieee80211_hdr *hdr)
  1116. {
  1117. if (ieee80211_has_tods(hdr->frame_control))
  1118. return hdr->addr3;
  1119. else
  1120. return hdr->addr1;
  1121. }
  1122. /**
  1123. * ieee80211_is_robust_mgmt_frame - check if frame is a robust management frame
  1124. * @hdr: the frame (buffer must include at least the first octet of payload)
  1125. */
  1126. static inline bool ieee80211_is_robust_mgmt_frame(struct ieee80211_hdr *hdr)
  1127. {
  1128. if (ieee80211_is_disassoc(hdr->frame_control) ||
  1129. ieee80211_is_deauth(hdr->frame_control))
  1130. return true;
  1131. if (ieee80211_is_action(hdr->frame_control)) {
  1132. u8 *category;
  1133. /*
  1134. * Action frames, excluding Public Action frames, are Robust
  1135. * Management Frames. However, if we are looking at a Protected
  1136. * frame, skip the check since the data may be encrypted and
  1137. * the frame has already been found to be a Robust Management
  1138. * Frame (by the other end).
  1139. */
  1140. if (ieee80211_has_protected(hdr->frame_control))
  1141. return true;
  1142. category = ((u8 *) hdr) + 24;
  1143. return *category != WLAN_CATEGORY_PUBLIC;
  1144. }
  1145. return false;
  1146. }
  1147. /**
  1148. * ieee80211_fhss_chan_to_freq - get channel frequency
  1149. * @channel: the FHSS channel
  1150. *
  1151. * Convert IEEE802.11 FHSS channel to frequency (MHz)
  1152. * Ref IEEE 802.11-2007 section 14.6
  1153. */
  1154. static inline int ieee80211_fhss_chan_to_freq(int channel)
  1155. {
  1156. if ((channel > 1) && (channel < 96))
  1157. return channel + 2400;
  1158. else
  1159. return -1;
  1160. }
  1161. /**
  1162. * ieee80211_freq_to_fhss_chan - get channel
  1163. * @freq: the channels frequency
  1164. *
  1165. * Convert frequency (MHz) to IEEE802.11 FHSS channel
  1166. * Ref IEEE 802.11-2007 section 14.6
  1167. */
  1168. static inline int ieee80211_freq_to_fhss_chan(int freq)
  1169. {
  1170. if ((freq > 2401) && (freq < 2496))
  1171. return freq - 2400;
  1172. else
  1173. return -1;
  1174. }
  1175. /**
  1176. * ieee80211_dsss_chan_to_freq - get channel center frequency
  1177. * @channel: the DSSS channel
  1178. *
  1179. * Convert IEEE802.11 DSSS channel to the center frequency (MHz).
  1180. * Ref IEEE 802.11-2007 section 15.6
  1181. */
  1182. static inline int ieee80211_dsss_chan_to_freq(int channel)
  1183. {
  1184. if ((channel > 0) && (channel < 14))
  1185. return 2407 + (channel * 5);
  1186. else if (channel == 14)
  1187. return 2484;
  1188. else
  1189. return -1;
  1190. }
  1191. /**
  1192. * ieee80211_freq_to_dsss_chan - get channel
  1193. * @freq: the frequency
  1194. *
  1195. * Convert frequency (MHz) to IEEE802.11 DSSS channel
  1196. * Ref IEEE 802.11-2007 section 15.6
  1197. *
  1198. * This routine selects the channel with the closest center frequency.
  1199. */
  1200. static inline int ieee80211_freq_to_dsss_chan(int freq)
  1201. {
  1202. if ((freq >= 2410) && (freq < 2475))
  1203. return (freq - 2405) / 5;
  1204. else if ((freq >= 2482) && (freq < 2487))
  1205. return 14;
  1206. else
  1207. return -1;
  1208. }
  1209. /* Convert IEEE802.11 HR DSSS channel to frequency (MHz) and back
  1210. * Ref IEEE 802.11-2007 section 18.4.6.2
  1211. *
  1212. * The channels and frequencies are the same as those defined for DSSS
  1213. */
  1214. #define ieee80211_hr_chan_to_freq(chan) ieee80211_dsss_chan_to_freq(chan)
  1215. #define ieee80211_freq_to_hr_chan(freq) ieee80211_freq_to_dsss_chan(freq)
  1216. /* Convert IEEE802.11 ERP channel to frequency (MHz) and back
  1217. * Ref IEEE 802.11-2007 section 19.4.2
  1218. */
  1219. #define ieee80211_erp_chan_to_freq(chan) ieee80211_hr_chan_to_freq(chan)
  1220. #define ieee80211_freq_to_erp_chan(freq) ieee80211_freq_to_hr_chan(freq)
  1221. /**
  1222. * ieee80211_ofdm_chan_to_freq - get channel center frequency
  1223. * @s_freq: starting frequency == (dotChannelStartingFactor/2) MHz
  1224. * @channel: the OFDM channel
  1225. *
  1226. * Convert IEEE802.11 OFDM channel to center frequency (MHz)
  1227. * Ref IEEE 802.11-2007 section 17.3.8.3.2
  1228. */
  1229. static inline int ieee80211_ofdm_chan_to_freq(int s_freq, int channel)
  1230. {
  1231. if ((channel > 0) && (channel <= 200) &&
  1232. (s_freq >= 4000))
  1233. return s_freq + (channel * 5);
  1234. else
  1235. return -1;
  1236. }
  1237. /**
  1238. * ieee80211_freq_to_ofdm_channel - get channel
  1239. * @s_freq: starting frequency == (dotChannelStartingFactor/2) MHz
  1240. * @freq: the frequency
  1241. *
  1242. * Convert frequency (MHz) to IEEE802.11 OFDM channel
  1243. * Ref IEEE 802.11-2007 section 17.3.8.3.2
  1244. *
  1245. * This routine selects the channel with the closest center frequency.
  1246. */
  1247. static inline int ieee80211_freq_to_ofdm_chan(int s_freq, int freq)
  1248. {
  1249. if ((freq > (s_freq + 2)) && (freq <= (s_freq + 1202)) &&
  1250. (s_freq >= 4000))
  1251. return (freq + 2 - s_freq) / 5;
  1252. else
  1253. return -1;
  1254. }
  1255. #endif /* LINUX_IEEE80211_H */