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