Staging: wlan-ng: p80211mgmt.h: Coding style cleanups
[sfrench/cifs-2.6.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  _WLAN_COMPAT_H
107 #include "wlan_compat.h"
108 #endif
109
110 #ifndef  _P80211HDR_H
111 #include "p80211hdr.h"
112 #endif
113
114
115 /*================================================================*/
116 /* Constants */
117
118 /*-- Information Element IDs --------------------*/
119 #define WLAN_EID_SSID           0
120 #define WLAN_EID_SUPP_RATES     1
121 #define WLAN_EID_FH_PARMS       2
122 #define WLAN_EID_DS_PARMS       3
123 #define WLAN_EID_CF_PARMS       4
124 #define WLAN_EID_TIM            5
125 #define WLAN_EID_IBSS_PARMS     6
126 /*-- values 7-15 reserved --*/
127 #define WLAN_EID_CHALLENGE      16
128 /*-- values 17-31 reserved for challenge text extension --*/
129 /*-- values 32-255 reserved --*/
130
131 /*-- Reason Codes -------------------------------*/
132 #define WLAN_MGMT_REASON_RSVD                   0
133 #define WLAN_MGMT_REASON_UNSPEC                 1
134 #define WLAN_MGMT_REASON_PRIOR_AUTH_INVALID     2
135 #define WLAN_MGMT_REASON_DEAUTH_LEAVING         3
136 #define WLAN_MGMT_REASON_DISASSOC_INACTIVE      4
137 #define WLAN_MGMT_REASON_DISASSOC_AP_BUSY       5
138 #define WLAN_MGMT_REASON_CLASS2_NONAUTH         6
139 #define WLAN_MGMT_REASON_CLASS3_NONASSOC        7
140 #define WLAN_MGMT_REASON_DISASSOC_STA_HASLEFT   8
141 #define WLAN_MGMT_REASON_CANT_ASSOC_NONAUTH     9
142
143 /*-- Status Codes -------------------------------*/
144 #define WLAN_MGMT_STATUS_SUCCESS                0
145 #define WLAN_MGMT_STATUS_UNSPEC_FAILURE         1
146 #define WLAN_MGMT_STATUS_CAPS_UNSUPPORTED       10
147 #define WLAN_MGMT_STATUS_REASSOC_NO_ASSOC       11
148 #define WLAN_MGMT_STATUS_ASSOC_DENIED_UNSPEC    12
149 #define WLAN_MGMT_STATUS_UNSUPPORTED_AUTHALG    13
150 #define WLAN_MGMT_STATUS_RX_AUTH_NOSEQ          14
151 #define WLAN_MGMT_STATUS_CHALLENGE_FAIL         15
152 #define WLAN_MGMT_STATUS_AUTH_TIMEOUT           16
153 #define WLAN_MGMT_STATUS_ASSOC_DENIED_BUSY      17
154 #define WLAN_MGMT_STATUS_ASSOC_DENIED_RATES     18
155   /* p80211b additions */
156 #define WLAN_MGMT_STATUS_ASSOC_DENIED_NOSHORT   19
157 #define WLAN_MGMT_STATUS_ASSOC_DENIED_NOPBCC    20
158 #define WLAN_MGMT_STATUS_ASSOC_DENIED_NOAGILITY 21
159
160 /*-- Auth Algorithm Field ---------------------------*/
161 #define WLAN_AUTH_ALG_OPENSYSTEM                0
162 #define WLAN_AUTH_ALG_SHAREDKEY                 1
163
164 /*-- Management Frame Field Offsets -------------*/
165 /* Note: Not all fields are listed because of variable lengths,   */
166 /*       see the code in p80211.c to see how we search for fields */
167 /* Note: These offsets are from the start of the frame data       */
168
169 #define WLAN_BEACON_OFF_TS                      0
170 #define WLAN_BEACON_OFF_BCN_int                 8
171 #define WLAN_BEACON_OFF_CAPINFO                 10
172 #define WLAN_BEACON_OFF_SSID                    12
173
174 #define WLAN_DISASSOC_OFF_REASON                0
175
176 #define WLAN_ASSOCREQ_OFF_CAP_INFO              0
177 #define WLAN_ASSOCREQ_OFF_LISTEN_int            2
178 #define WLAN_ASSOCREQ_OFF_SSID                  4
179
180 #define WLAN_ASSOCRESP_OFF_CAP_INFO             0
181 #define WLAN_ASSOCRESP_OFF_STATUS               2
182 #define WLAN_ASSOCRESP_OFF_AID                  4
183 #define WLAN_ASSOCRESP_OFF_SUPP_RATES           6
184
185 #define WLAN_REASSOCREQ_OFF_CAP_INFO            0
186 #define WLAN_REASSOCREQ_OFF_LISTEN_int          2
187 #define WLAN_REASSOCREQ_OFF_CURR_AP             4
188 #define WLAN_REASSOCREQ_OFF_SSID                10
189
190 #define WLAN_REASSOCRESP_OFF_CAP_INFO           0
191 #define WLAN_REASSOCRESP_OFF_STATUS             2
192 #define WLAN_REASSOCRESP_OFF_AID                4
193 #define WLAN_REASSOCRESP_OFF_SUPP_RATES         6
194
195 #define WLAN_PROBEREQ_OFF_SSID                  0
196
197 #define WLAN_PROBERESP_OFF_TS                   0
198 #define WLAN_PROBERESP_OFF_BCN_int              8
199 #define WLAN_PROBERESP_OFF_CAP_INFO             10
200 #define WLAN_PROBERESP_OFF_SSID                 12
201
202 #define WLAN_AUTHEN_OFF_AUTH_ALG                0
203 #define WLAN_AUTHEN_OFF_AUTH_SEQ                2
204 #define WLAN_AUTHEN_OFF_STATUS                  4
205 #define WLAN_AUTHEN_OFF_CHALLENGE               6
206
207 #define WLAN_DEAUTHEN_OFF_REASON                0
208
209 /*-- Capability Field ---------------------------*/
210 #define WLAN_GET_MGMT_CAP_INFO_ESS(n)           ((n) & BIT(0))
211 #define WLAN_GET_MGMT_CAP_INFO_IBSS(n)          (((n) & BIT(1)) >> 1)
212 #define WLAN_GET_MGMT_CAP_INFO_CFPOLLABLE(n)    (((n) & BIT(2)) >> 2)
213 #define WLAN_GET_MGMT_CAP_INFO_CFPOLLREQ(n)     (((n) & BIT(3)) >> 3)
214 #define WLAN_GET_MGMT_CAP_INFO_PRIVACY(n)       (((n) & BIT(4)) >> 4)
215   /* p80211b additions */
216 #define WLAN_GET_MGMT_CAP_INFO_SHORT(n)         (((n) & BIT(5)) >> 5)
217 #define WLAN_GET_MGMT_CAP_INFO_PBCC(n)          (((n) & BIT(6)) >> 6)
218 #define WLAN_GET_MGMT_CAP_INFO_AGILITY(n)       (((n) & BIT(7)) >> 7)
219
220 #define WLAN_SET_MGMT_CAP_INFO_ESS(n)           (n)
221 #define WLAN_SET_MGMT_CAP_INFO_IBSS(n)          ((n) << 1)
222 #define WLAN_SET_MGMT_CAP_INFO_CFPOLLABLE(n)    ((n) << 2)
223 #define WLAN_SET_MGMT_CAP_INFO_CFPOLLREQ(n)     ((n) << 3)
224 #define WLAN_SET_MGMT_CAP_INFO_PRIVACY(n)       ((n) << 4)
225   /* p80211b additions */
226 #define WLAN_SET_MGMT_CAP_INFO_SHORT(n)         ((n) << 5)
227 #define WLAN_SET_MGMT_CAP_INFO_PBCC(n)          ((n) << 6)
228 #define WLAN_SET_MGMT_CAP_INFO_AGILITY(n)       ((n) << 7)
229
230 /*-- Information Element Types --------------------*/
231 /* prototype structure, all IEs start with these members */
232
233 typedef struct wlan_ie {
234         u8 eid;
235         u8 len;
236 } __attribute__ ((packed)) wlan_ie_t;
237
238 /*-- Service Set Identity (SSID)  -----------------*/
239 typedef struct wlan_ie_ssid {
240         u8 eid;
241         u8 len;
242         u8 ssid[1];             /* may be zero, ptrs may overlap */
243 } __attribute__ ((packed)) wlan_ie_ssid_t;
244
245 /*-- Supported Rates  -----------------------------*/
246 typedef struct wlan_ie_supp_rates {
247         u8 eid;
248         u8 len;
249         u8 rates[1];            /* had better be at LEAST one! */
250 } __attribute__ ((packed)) wlan_ie_supp_rates_t;
251
252 /*-- FH Parameter Set  ----------------------------*/
253 typedef struct wlan_ie_fh_parms {
254         u8 eid;
255         u8 len;
256         u16 dwell;
257         u8 hopset;
258         u8 hoppattern;
259         u8 hopindex;
260 } __attribute__ ((packed)) wlan_ie_fh_parms_t;
261
262 /*-- DS Parameter Set  ----------------------------*/
263 typedef struct wlan_ie_ds_parms {
264         u8 eid;
265         u8 len;
266         u8 curr_ch;
267 } __attribute__ ((packed)) wlan_ie_ds_parms_t;
268
269 /*-- CF Parameter Set  ----------------------------*/
270
271 typedef struct wlan_ie_cf_parms {
272         u8 eid;
273         u8 len;
274         u8 cfp_cnt;
275         u8 cfp_period;
276         u16 cfp_maxdur;
277         u16 cfp_durremaining;
278 } __attribute__ ((packed)) wlan_ie_cf_parms_t;
279
280 /*-- TIM ------------------------------------------*/
281 typedef struct wlan_ie_tim {
282         u8 eid;
283         u8 len;
284         u8 dtim_cnt;
285         u8 dtim_period;
286         u8 bitmap_ctl;
287         u8 virt_bm[1];
288 } __attribute__ ((packed)) wlan_ie_tim_t;
289
290 /*-- IBSS Parameter Set ---------------------------*/
291 typedef struct wlan_ie_ibss_parms {
292         u8 eid;
293         u8 len;
294         u16 atim_win;
295 } __attribute__ ((packed)) wlan_ie_ibss_parms_t;
296
297 /*-- Challenge Text  ------------------------------*/
298 typedef struct wlan_ie_challenge {
299         u8 eid;
300         u8 len;
301         u8 challenge[1];
302 } __attribute__ ((packed)) wlan_ie_challenge_t;
303
304 /*-------------------------------------------------*/
305 /*  Frame Types  */
306
307 /* prototype structure, all mgmt frame types will start with these members */
308 typedef struct wlan_fr_mgmt {
309         u16 type;
310         u16 len;                /* DOES NOT include CRC !!!! */
311         u8 *buf;
312         p80211_hdr_t *hdr;
313         /* used for target specific data, skb in Linux */
314         void *priv;
315         /*-- fixed fields -----------*/
316         /*-- info elements ----------*/
317 } wlan_fr_mgmt_t;
318
319 /*-- Beacon ---------------------------------------*/
320 typedef struct wlan_fr_beacon {
321         u16 type;
322         u16 len;
323         u8 *buf;
324         p80211_hdr_t *hdr;
325         /* used for target specific data, skb in Linux */
326         void *priv;
327         /*-- fixed fields -----------*/
328         u64 *ts;
329         u16 *bcn_int;
330         u16 *cap_info;
331         /*-- info elements ----------*/
332         wlan_ie_ssid_t *ssid;
333         wlan_ie_supp_rates_t *supp_rates;
334         wlan_ie_fh_parms_t *fh_parms;
335         wlan_ie_ds_parms_t *ds_parms;
336         wlan_ie_cf_parms_t *cf_parms;
337         wlan_ie_ibss_parms_t *ibss_parms;
338         wlan_ie_tim_t *tim;
339
340 } wlan_fr_beacon_t;
341
342 /*-- IBSS ATIM ------------------------------------*/
343 typedef struct wlan_fr_ibssatim {
344         u16 type;
345         u16 len;
346         u8 *buf;
347         p80211_hdr_t *hdr;
348         /* used for target specific data, skb in Linux */
349         void *priv;
350
351         /*-- fixed fields -----------*/
352         /*-- info elements ----------*/
353
354         /* this frame type has a null body */
355
356 } wlan_fr_ibssatim_t;
357
358 /*-- Disassociation -------------------------------*/
359 typedef struct wlan_fr_disassoc {
360         u16 type;
361         u16 len;
362         u8 *buf;
363         p80211_hdr_t *hdr;
364         /* used for target specific data, skb in Linux */
365         void *priv;
366         /*-- fixed fields -----------*/
367         u16 *reason;
368
369         /*-- info elements ----------*/
370
371 } wlan_fr_disassoc_t;
372
373 /*-- Association Request --------------------------*/
374 typedef struct wlan_fr_assocreq {
375         u16 type;
376         u16 len;
377         u8 *buf;
378         p80211_hdr_t *hdr;
379         /* used for target specific data, skb in Linux */
380         void *priv;
381         /*-- fixed fields -----------*/
382         u16 *cap_info;
383         u16 *listen_int;
384         /*-- info elements ----------*/
385         wlan_ie_ssid_t *ssid;
386         wlan_ie_supp_rates_t *supp_rates;
387
388 } wlan_fr_assocreq_t;
389
390 /*-- Association Response -------------------------*/
391 typedef struct wlan_fr_assocresp {
392         u16 type;
393         u16 len;
394         u8 *buf;
395         p80211_hdr_t *hdr;
396         /* used for target specific data, skb in Linux */
397         void *priv;
398         /*-- fixed fields -----------*/
399         u16 *cap_info;
400         u16 *status;
401         u16 *aid;
402         /*-- info elements ----------*/
403         wlan_ie_supp_rates_t *supp_rates;
404
405 } wlan_fr_assocresp_t;
406
407 /*-- Reassociation Request ------------------------*/
408 typedef struct wlan_fr_reassocreq {
409         u16 type;
410         u16 len;
411         u8 *buf;
412         p80211_hdr_t *hdr;
413         /* used for target specific data, skb in Linux */
414         void *priv;
415         /*-- fixed fields -----------*/
416         u16 *cap_info;
417         u16 *listen_int;
418         u8 *curr_ap;
419         /*-- info elements ----------*/
420         wlan_ie_ssid_t *ssid;
421         wlan_ie_supp_rates_t *supp_rates;
422
423 } wlan_fr_reassocreq_t;
424
425 /*-- Reassociation Response -----------------------*/
426 typedef struct wlan_fr_reassocresp {
427         u16 type;
428         u16 len;
429         u8 *buf;
430         p80211_hdr_t *hdr;
431         /* used for target specific data, skb in Linux */
432         void *priv;
433         /*-- fixed fields -----------*/
434         u16 *cap_info;
435         u16 *status;
436         u16 *aid;
437         /*-- info elements ----------*/
438         wlan_ie_supp_rates_t *supp_rates;
439
440 } wlan_fr_reassocresp_t;
441
442 /*-- Probe Request --------------------------------*/
443 typedef struct wlan_fr_probereq {
444         u16 type;
445         u16 len;
446         u8 *buf;
447         p80211_hdr_t *hdr;
448         /* used for target specific data, skb in Linux */
449         void *priv;
450         /*-- fixed fields -----------*/
451         /*-- info elements ----------*/
452         wlan_ie_ssid_t *ssid;
453         wlan_ie_supp_rates_t *supp_rates;
454
455 } wlan_fr_probereq_t;
456
457 /*-- Probe Response -------------------------------*/
458 typedef struct wlan_fr_proberesp {
459         u16 type;
460         u16 len;
461         u8 *buf;
462         p80211_hdr_t *hdr;
463         /* used for target specific data, skb in Linux */
464         void *priv;
465         /*-- fixed fields -----------*/
466         u64 *ts;
467         u16 *bcn_int;
468         u16 *cap_info;
469         /*-- info elements ----------*/
470         wlan_ie_ssid_t *ssid;
471         wlan_ie_supp_rates_t *supp_rates;
472         wlan_ie_fh_parms_t *fh_parms;
473         wlan_ie_ds_parms_t *ds_parms;
474         wlan_ie_cf_parms_t *cf_parms;
475         wlan_ie_ibss_parms_t *ibss_parms;
476 } wlan_fr_proberesp_t;
477
478 /*-- Authentication -------------------------------*/
479 typedef struct wlan_fr_authen {
480         u16 type;
481         u16 len;
482         u8 *buf;
483         p80211_hdr_t *hdr;
484         /* used for target specific data, skb in Linux */
485         void *priv;
486         /*-- fixed fields -----------*/
487         u16 *auth_alg;
488         u16 *auth_seq;
489         u16 *status;
490         /*-- info elements ----------*/
491         wlan_ie_challenge_t *challenge;
492
493 } wlan_fr_authen_t;
494
495 /*-- Deauthenication -----------------------------*/
496 typedef struct wlan_fr_deauthen {
497         u16 type;
498         u16 len;
499         u8 *buf;
500         p80211_hdr_t *hdr;
501         /* used for target specific data, skb in Linux */
502         void *priv;
503         /*-- fixed fields -----------*/
504         u16 *reason;
505
506         /*-- info elements ----------*/
507
508 } wlan_fr_deauthen_t;
509
510 void wlan_mgmt_encode_beacon(wlan_fr_beacon_t *f);
511 void wlan_mgmt_decode_beacon(wlan_fr_beacon_t *f);
512 void wlan_mgmt_encode_disassoc(wlan_fr_disassoc_t *f);
513 void wlan_mgmt_decode_disassoc(wlan_fr_disassoc_t *f);
514 void wlan_mgmt_encode_assocreq(wlan_fr_assocreq_t *f);
515 void wlan_mgmt_decode_assocreq(wlan_fr_assocreq_t *f);
516 void wlan_mgmt_encode_assocresp(wlan_fr_assocresp_t *f);
517 void wlan_mgmt_decode_assocresp(wlan_fr_assocresp_t *f);
518 void wlan_mgmt_encode_reassocreq(wlan_fr_reassocreq_t *f);
519 void wlan_mgmt_decode_reassocreq(wlan_fr_reassocreq_t *f);
520 void wlan_mgmt_encode_reassocresp(wlan_fr_reassocresp_t *f);
521 void wlan_mgmt_decode_reassocresp(wlan_fr_reassocresp_t *f);
522 void wlan_mgmt_encode_probereq(wlan_fr_probereq_t *f);
523 void wlan_mgmt_decode_probereq(wlan_fr_probereq_t *f);
524 void wlan_mgmt_encode_proberesp(wlan_fr_proberesp_t *f);
525 void wlan_mgmt_decode_proberesp(wlan_fr_proberesp_t *f);
526 void wlan_mgmt_encode_authen(wlan_fr_authen_t *f);
527 void wlan_mgmt_decode_authen(wlan_fr_authen_t *f);
528 void wlan_mgmt_encode_deauthen(wlan_fr_deauthen_t *f);
529 void wlan_mgmt_decode_deauthen(wlan_fr_deauthen_t *f);
530
531 #endif /* _P80211MGMT_H */