p80211mgmt.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. /* SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1) */
  2. /* p80211mgmt.h
  3. *
  4. * Macros, types, and functions to handle 802.11 mgmt frames
  5. *
  6. * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.
  7. * --------------------------------------------------------------------
  8. *
  9. * linux-wlan
  10. *
  11. * The contents of this file are subject to the Mozilla Public
  12. * License Version 1.1 (the "License"); you may not use this file
  13. * except in compliance with the License. You may obtain a copy of
  14. * the License at http://www.mozilla.org/MPL/
  15. *
  16. * Software distributed under the License is distributed on an "AS
  17. * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  18. * implied. See the License for the specific language governing
  19. * rights and limitations under the License.
  20. *
  21. * Alternatively, the contents of this file may be used under the
  22. * terms of the GNU Public License version 2 (the "GPL"), in which
  23. * case the provisions of the GPL are applicable instead of the
  24. * above. If you wish to allow the use of your version of this file
  25. * only under the terms of the GPL and not to allow others to use
  26. * your version of this file under the MPL, indicate your decision
  27. * by deleting the provisions above and replace them with the notice
  28. * and other provisions required by the GPL. If you do not delete
  29. * the provisions above, a recipient may use your version of this
  30. * file under either the MPL or the GPL.
  31. *
  32. * --------------------------------------------------------------------
  33. *
  34. * Inquiries regarding the linux-wlan Open Source project can be
  35. * made directly to:
  36. *
  37. * AbsoluteValue Systems Inc.
  38. * info@linux-wlan.com
  39. * http://www.linux-wlan.com
  40. *
  41. * --------------------------------------------------------------------
  42. *
  43. * Portions of the development of this software were funded by
  44. * Intersil Corporation as part of PRISM(R) chipset product development.
  45. *
  46. * --------------------------------------------------------------------
  47. *
  48. * This file declares the constants and types used in the interface
  49. * between a wlan driver and the user mode utilities.
  50. *
  51. * Notes:
  52. * - Constant values are always in HOST byte order. To assign
  53. * values to multi-byte fields they _must_ be converted to
  54. * ieee byte order. To retrieve multi-byte values from incoming
  55. * frames, they must be converted to host order.
  56. *
  57. * - The len member of the frame structure does NOT!!! include
  58. * the MAC CRC. Therefore, the len field on rx'd frames should
  59. * have 4 subtracted from it.
  60. *
  61. * All functions declared here are implemented in p80211.c
  62. *
  63. * The types, macros, and functions defined here are primarily
  64. * used for encoding and decoding management frames. They are
  65. * designed to follow these patterns of use:
  66. *
  67. * DECODE:
  68. * 1) a frame of length len is received into buffer b
  69. * 2) using the hdr structure and macros, we determine the type
  70. * 3) an appropriate mgmt frame structure, mf, is allocated and zeroed
  71. * 4) mf.hdr = b
  72. * mf.buf = b
  73. * mf.len = len
  74. * 5) call mgmt_decode( mf )
  75. * 6) the frame field pointers in mf are now set. Note that any
  76. * multi-byte frame field values accessed using the frame field
  77. * pointers are in ieee byte order and will have to be converted
  78. * to host order.
  79. *
  80. * ENCODE:
  81. * 1) Library client allocates buffer space for maximum length
  82. * frame of the desired type
  83. * 2) Library client allocates a mgmt frame structure, called mf,
  84. * of the desired type
  85. * 3) Set the following:
  86. * mf.type = <desired type>
  87. * mf.buf = <allocated buffer address>
  88. * 4) call mgmt_encode( mf )
  89. * 5) all of the fixed field pointers and fixed length information element
  90. * pointers in mf are now set to their respective locations in the
  91. * allocated space (fortunately, all variable length information elements
  92. * fall at the end of their respective frames).
  93. * 5a) The length field is set to include the last of the fixed and fixed
  94. * length fields. It may have to be updated for optional or variable
  95. * length information elements.
  96. * 6) Optional and variable length information elements are special cases
  97. * and must be handled individually by the client code.
  98. * --------------------------------------------------------------------
  99. */
  100. #ifndef _P80211MGMT_H
  101. #define _P80211MGMT_H
  102. #ifndef _P80211HDR_H
  103. #include "p80211hdr.h"
  104. #endif
  105. /*-- Information Element IDs --------------------*/
  106. #define WLAN_EID_SSID 0
  107. #define WLAN_EID_SUPP_RATES 1
  108. #define WLAN_EID_FH_PARMS 2
  109. #define WLAN_EID_DS_PARMS 3
  110. #define WLAN_EID_CF_PARMS 4
  111. #define WLAN_EID_TIM 5
  112. #define WLAN_EID_IBSS_PARMS 6
  113. /*-- values 7-15 reserved --*/
  114. #define WLAN_EID_CHALLENGE 16
  115. /*-- values 17-31 reserved for challenge text extension --*/
  116. /*-- values 32-255 reserved --*/
  117. /*-- Reason Codes -------------------------------*/
  118. #define WLAN_MGMT_REASON_RSVD 0
  119. #define WLAN_MGMT_REASON_UNSPEC 1
  120. #define WLAN_MGMT_REASON_PRIOR_AUTH_INVALID 2
  121. #define WLAN_MGMT_REASON_DEAUTH_LEAVING 3
  122. #define WLAN_MGMT_REASON_DISASSOC_INACTIVE 4
  123. #define WLAN_MGMT_REASON_DISASSOC_AP_BUSY 5
  124. #define WLAN_MGMT_REASON_CLASS2_NONAUTH 6
  125. #define WLAN_MGMT_REASON_CLASS3_NONASSOC 7
  126. #define WLAN_MGMT_REASON_DISASSOC_STA_HASLEFT 8
  127. #define WLAN_MGMT_REASON_CANT_ASSOC_NONAUTH 9
  128. /*-- Status Codes -------------------------------*/
  129. #define WLAN_MGMT_STATUS_SUCCESS 0
  130. #define WLAN_MGMT_STATUS_UNSPEC_FAILURE 1
  131. #define WLAN_MGMT_STATUS_CAPS_UNSUPPORTED 10
  132. #define WLAN_MGMT_STATUS_REASSOC_NO_ASSOC 11
  133. #define WLAN_MGMT_STATUS_ASSOC_DENIED_UNSPEC 12
  134. #define WLAN_MGMT_STATUS_UNSUPPORTED_AUTHALG 13
  135. #define WLAN_MGMT_STATUS_RX_AUTH_NOSEQ 14
  136. #define WLAN_MGMT_STATUS_CHALLENGE_FAIL 15
  137. #define WLAN_MGMT_STATUS_AUTH_TIMEOUT 16
  138. #define WLAN_MGMT_STATUS_ASSOC_DENIED_BUSY 17
  139. #define WLAN_MGMT_STATUS_ASSOC_DENIED_RATES 18
  140. /* p80211b additions */
  141. #define WLAN_MGMT_STATUS_ASSOC_DENIED_NOSHORT 19
  142. #define WLAN_MGMT_STATUS_ASSOC_DENIED_NOPBCC 20
  143. #define WLAN_MGMT_STATUS_ASSOC_DENIED_NOAGILITY 21
  144. /*-- Auth Algorithm Field ---------------------------*/
  145. #define WLAN_AUTH_ALG_OPENSYSTEM 0
  146. #define WLAN_AUTH_ALG_SHAREDKEY 1
  147. /*-- Management Frame Field Offsets -------------*/
  148. /* Note: Not all fields are listed because of variable lengths, */
  149. /* see the code in p80211.c to see how we search for fields */
  150. /* Note: These offsets are from the start of the frame data */
  151. #define WLAN_BEACON_OFF_TS 0
  152. #define WLAN_BEACON_OFF_BCN_int 8
  153. #define WLAN_BEACON_OFF_CAPINFO 10
  154. #define WLAN_BEACON_OFF_SSID 12
  155. #define WLAN_DISASSOC_OFF_REASON 0
  156. #define WLAN_ASSOCREQ_OFF_CAP_INFO 0
  157. #define WLAN_ASSOCREQ_OFF_LISTEN_int 2
  158. #define WLAN_ASSOCREQ_OFF_SSID 4
  159. #define WLAN_ASSOCRESP_OFF_CAP_INFO 0
  160. #define WLAN_ASSOCRESP_OFF_STATUS 2
  161. #define WLAN_ASSOCRESP_OFF_AID 4
  162. #define WLAN_ASSOCRESP_OFF_SUPP_RATES 6
  163. #define WLAN_REASSOCREQ_OFF_CAP_INFO 0
  164. #define WLAN_REASSOCREQ_OFF_LISTEN_int 2
  165. #define WLAN_REASSOCREQ_OFF_CURR_AP 4
  166. #define WLAN_REASSOCREQ_OFF_SSID 10
  167. #define WLAN_REASSOCRESP_OFF_CAP_INFO 0
  168. #define WLAN_REASSOCRESP_OFF_STATUS 2
  169. #define WLAN_REASSOCRESP_OFF_AID 4
  170. #define WLAN_REASSOCRESP_OFF_SUPP_RATES 6
  171. #define WLAN_PROBEREQ_OFF_SSID 0
  172. #define WLAN_PROBERESP_OFF_TS 0
  173. #define WLAN_PROBERESP_OFF_BCN_int 8
  174. #define WLAN_PROBERESP_OFF_CAP_INFO 10
  175. #define WLAN_PROBERESP_OFF_SSID 12
  176. #define WLAN_AUTHEN_OFF_AUTH_ALG 0
  177. #define WLAN_AUTHEN_OFF_AUTH_SEQ 2
  178. #define WLAN_AUTHEN_OFF_STATUS 4
  179. #define WLAN_AUTHEN_OFF_CHALLENGE 6
  180. #define WLAN_DEAUTHEN_OFF_REASON 0
  181. /*-- Capability Field ---------------------------*/
  182. #define WLAN_GET_MGMT_CAP_INFO_ESS(n) ((n) & BIT(0))
  183. #define WLAN_GET_MGMT_CAP_INFO_IBSS(n) (((n) & BIT(1)) >> 1)
  184. #define WLAN_GET_MGMT_CAP_INFO_CFPOLLABLE(n) (((n) & BIT(2)) >> 2)
  185. #define WLAN_GET_MGMT_CAP_INFO_CFPOLLREQ(n) (((n) & BIT(3)) >> 3)
  186. #define WLAN_GET_MGMT_CAP_INFO_PRIVACY(n) (((n) & BIT(4)) >> 4)
  187. /* p80211b additions */
  188. #define WLAN_GET_MGMT_CAP_INFO_SHORT(n) (((n) & BIT(5)) >> 5)
  189. #define WLAN_GET_MGMT_CAP_INFO_PBCC(n) (((n) & BIT(6)) >> 6)
  190. #define WLAN_GET_MGMT_CAP_INFO_AGILITY(n) (((n) & BIT(7)) >> 7)
  191. #define WLAN_SET_MGMT_CAP_INFO_ESS(n) (n)
  192. #define WLAN_SET_MGMT_CAP_INFO_IBSS(n) ((n) << 1)
  193. #define WLAN_SET_MGMT_CAP_INFO_CFPOLLABLE(n) ((n) << 2)
  194. #define WLAN_SET_MGMT_CAP_INFO_CFPOLLREQ(n) ((n) << 3)
  195. #define WLAN_SET_MGMT_CAP_INFO_PRIVACY(n) ((n) << 4)
  196. /* p80211b additions */
  197. #define WLAN_SET_MGMT_CAP_INFO_SHORT(n) ((n) << 5)
  198. #define WLAN_SET_MGMT_CAP_INFO_PBCC(n) ((n) << 6)
  199. #define WLAN_SET_MGMT_CAP_INFO_AGILITY(n) ((n) << 7)
  200. /*-- Information Element Types --------------------*/
  201. /* prototype structure, all IEs start with these members */
  202. struct wlan_ie {
  203. u8 eid;
  204. u8 len;
  205. } __packed;
  206. /*-- Service Set Identity (SSID) -----------------*/
  207. struct wlan_ie_ssid {
  208. u8 eid;
  209. u8 len;
  210. u8 ssid[1]; /* may be zero, ptrs may overlap */
  211. } __packed;
  212. /*-- Supported Rates -----------------------------*/
  213. struct wlan_ie_supp_rates {
  214. u8 eid;
  215. u8 len;
  216. u8 rates[1]; /* had better be at LEAST one! */
  217. } __packed;
  218. /*-- FH Parameter Set ----------------------------*/
  219. struct wlan_ie_fh_parms {
  220. u8 eid;
  221. u8 len;
  222. u16 dwell;
  223. u8 hopset;
  224. u8 hoppattern;
  225. u8 hopindex;
  226. } __packed;
  227. /*-- DS Parameter Set ----------------------------*/
  228. struct wlan_ie_ds_parms {
  229. u8 eid;
  230. u8 len;
  231. u8 curr_ch;
  232. } __packed;
  233. /*-- CF Parameter Set ----------------------------*/
  234. struct wlan_ie_cf_parms {
  235. u8 eid;
  236. u8 len;
  237. u8 cfp_cnt;
  238. u8 cfp_period;
  239. u16 cfp_maxdur;
  240. u16 cfp_durremaining;
  241. } __packed;
  242. /*-- TIM ------------------------------------------*/
  243. struct wlan_ie_tim {
  244. u8 eid;
  245. u8 len;
  246. u8 dtim_cnt;
  247. u8 dtim_period;
  248. u8 bitmap_ctl;
  249. u8 virt_bm[1];
  250. } __packed;
  251. /*-- IBSS Parameter Set ---------------------------*/
  252. struct wlan_ie_ibss_parms {
  253. u8 eid;
  254. u8 len;
  255. u16 atim_win;
  256. } __packed;
  257. /*-- Challenge Text ------------------------------*/
  258. struct wlan_ie_challenge {
  259. u8 eid;
  260. u8 len;
  261. u8 challenge[1];
  262. } __packed;
  263. /*-------------------------------------------------*/
  264. /* Frame Types */
  265. /* prototype structure, all mgmt frame types will start with these members */
  266. struct wlan_fr_mgmt {
  267. u16 type;
  268. u16 len; /* DOES NOT include CRC !!!! */
  269. u8 *buf;
  270. union p80211_hdr *hdr;
  271. /* used for target specific data, skb in Linux */
  272. void *priv;
  273. /*-- fixed fields -----------*/
  274. /*-- info elements ----------*/
  275. };
  276. /*-- Beacon ---------------------------------------*/
  277. struct wlan_fr_beacon {
  278. u16 type;
  279. u16 len;
  280. u8 *buf;
  281. union p80211_hdr *hdr;
  282. /* used for target specific data, skb in Linux */
  283. void *priv;
  284. /*-- fixed fields -----------*/
  285. u64 *ts;
  286. u16 *bcn_int;
  287. u16 *cap_info;
  288. /*-- info elements ----------*/
  289. struct wlan_ie_ssid *ssid;
  290. struct wlan_ie_supp_rates *supp_rates;
  291. struct wlan_ie_fh_parms *fh_parms;
  292. struct wlan_ie_ds_parms *ds_parms;
  293. struct wlan_ie_cf_parms *cf_parms;
  294. struct wlan_ie_ibss_parms *ibss_parms;
  295. struct wlan_ie_tim *tim;
  296. };
  297. /*-- IBSS ATIM ------------------------------------*/
  298. struct wlan_fr_ibssatim {
  299. u16 type;
  300. u16 len;
  301. u8 *buf;
  302. union p80211_hdr *hdr;
  303. /* used for target specific data, skb in Linux */
  304. void *priv;
  305. /*-- fixed fields -----------*/
  306. /*-- info elements ----------*/
  307. /* this frame type has a null body */
  308. };
  309. /*-- Disassociation -------------------------------*/
  310. struct wlan_fr_disassoc {
  311. u16 type;
  312. u16 len;
  313. u8 *buf;
  314. union p80211_hdr *hdr;
  315. /* used for target specific data, skb in Linux */
  316. void *priv;
  317. /*-- fixed fields -----------*/
  318. u16 *reason;
  319. /*-- info elements ----------*/
  320. };
  321. /*-- Association Request --------------------------*/
  322. struct wlan_fr_assocreq {
  323. u16 type;
  324. u16 len;
  325. u8 *buf;
  326. union p80211_hdr *hdr;
  327. /* used for target specific data, skb in Linux */
  328. void *priv;
  329. /*-- fixed fields -----------*/
  330. u16 *cap_info;
  331. u16 *listen_int;
  332. /*-- info elements ----------*/
  333. struct wlan_ie_ssid *ssid;
  334. struct wlan_ie_supp_rates *supp_rates;
  335. };
  336. /*-- Association Response -------------------------*/
  337. struct wlan_fr_assocresp {
  338. u16 type;
  339. u16 len;
  340. u8 *buf;
  341. union p80211_hdr *hdr;
  342. /* used for target specific data, skb in Linux */
  343. void *priv;
  344. /*-- fixed fields -----------*/
  345. u16 *cap_info;
  346. u16 *status;
  347. u16 *aid;
  348. /*-- info elements ----------*/
  349. struct wlan_ie_supp_rates *supp_rates;
  350. };
  351. /*-- Reassociation Request ------------------------*/
  352. struct wlan_fr_reassocreq {
  353. u16 type;
  354. u16 len;
  355. u8 *buf;
  356. union p80211_hdr *hdr;
  357. /* used for target specific data, skb in Linux */
  358. void *priv;
  359. /*-- fixed fields -----------*/
  360. u16 *cap_info;
  361. u16 *listen_int;
  362. u8 *curr_ap;
  363. /*-- info elements ----------*/
  364. struct wlan_ie_ssid *ssid;
  365. struct wlan_ie_supp_rates *supp_rates;
  366. };
  367. /*-- Reassociation Response -----------------------*/
  368. struct wlan_fr_reassocresp {
  369. u16 type;
  370. u16 len;
  371. u8 *buf;
  372. union p80211_hdr *hdr;
  373. /* used for target specific data, skb in Linux */
  374. void *priv;
  375. /*-- fixed fields -----------*/
  376. u16 *cap_info;
  377. u16 *status;
  378. u16 *aid;
  379. /*-- info elements ----------*/
  380. struct wlan_ie_supp_rates *supp_rates;
  381. };
  382. /*-- Probe Request --------------------------------*/
  383. struct wlan_fr_probereq {
  384. u16 type;
  385. u16 len;
  386. u8 *buf;
  387. union p80211_hdr *hdr;
  388. /* used for target specific data, skb in Linux */
  389. void *priv;
  390. /*-- fixed fields -----------*/
  391. /*-- info elements ----------*/
  392. struct wlan_ie_ssid *ssid;
  393. struct wlan_ie_supp_rates *supp_rates;
  394. };
  395. /*-- Probe Response -------------------------------*/
  396. struct wlan_fr_proberesp {
  397. u16 type;
  398. u16 len;
  399. u8 *buf;
  400. union p80211_hdr *hdr;
  401. /* used for target specific data, skb in Linux */
  402. void *priv;
  403. /*-- fixed fields -----------*/
  404. u64 *ts;
  405. u16 *bcn_int;
  406. u16 *cap_info;
  407. /*-- info elements ----------*/
  408. struct wlan_ie_ssid *ssid;
  409. struct wlan_ie_supp_rates *supp_rates;
  410. struct wlan_ie_fh_parms *fh_parms;
  411. struct wlan_ie_ds_parms *ds_parms;
  412. struct wlan_ie_cf_parms *cf_parms;
  413. struct wlan_ie_ibss_parms *ibss_parms;
  414. };
  415. /*-- Authentication -------------------------------*/
  416. struct wlan_fr_authen {
  417. u16 type;
  418. u16 len;
  419. u8 *buf;
  420. union p80211_hdr *hdr;
  421. /* used for target specific data, skb in Linux */
  422. void *priv;
  423. /*-- fixed fields -----------*/
  424. u16 *auth_alg;
  425. u16 *auth_seq;
  426. u16 *status;
  427. /*-- info elements ----------*/
  428. struct wlan_ie_challenge *challenge;
  429. };
  430. /*-- Deauthenication -----------------------------*/
  431. struct wlan_fr_deauthen {
  432. u16 type;
  433. u16 len;
  434. u8 *buf;
  435. union p80211_hdr *hdr;
  436. /* used for target specific data, skb in Linux */
  437. void *priv;
  438. /*-- fixed fields -----------*/
  439. u16 *reason;
  440. /*-- info elements ----------*/
  441. };
  442. void wlan_mgmt_encode_beacon(struct wlan_fr_beacon *f);
  443. void wlan_mgmt_decode_beacon(struct wlan_fr_beacon *f);
  444. void wlan_mgmt_encode_disassoc(struct wlan_fr_disassoc *f);
  445. void wlan_mgmt_decode_disassoc(struct wlan_fr_disassoc *f);
  446. void wlan_mgmt_encode_assocreq(struct wlan_fr_assocreq *f);
  447. void wlan_mgmt_decode_assocreq(struct wlan_fr_assocreq *f);
  448. void wlan_mgmt_encode_assocresp(struct wlan_fr_assocresp *f);
  449. void wlan_mgmt_decode_assocresp(struct wlan_fr_assocresp *f);
  450. void wlan_mgmt_encode_reassocreq(struct wlan_fr_reassocreq *f);
  451. void wlan_mgmt_decode_reassocreq(struct wlan_fr_reassocreq *f);
  452. void wlan_mgmt_encode_reassocresp(struct wlan_fr_reassocresp *f);
  453. void wlan_mgmt_decode_reassocresp(struct wlan_fr_reassocresp *f);
  454. void wlan_mgmt_encode_probereq(struct wlan_fr_probereq *f);
  455. void wlan_mgmt_decode_probereq(struct wlan_fr_probereq *f);
  456. void wlan_mgmt_encode_proberesp(struct wlan_fr_proberesp *f);
  457. void wlan_mgmt_decode_proberesp(struct wlan_fr_proberesp *f);
  458. void wlan_mgmt_encode_authen(struct wlan_fr_authen *f);
  459. void wlan_mgmt_decode_authen(struct wlan_fr_authen *f);
  460. void wlan_mgmt_encode_deauthen(struct wlan_fr_deauthen *f);
  461. void wlan_mgmt_decode_deauthen(struct wlan_fr_deauthen *f);
  462. #endif /* _P80211MGMT_H */