Staging: wlan-ng: Remove use of WLAN_ADDR_LEN
[safe/jmp/linux-2.6] / drivers / staging / wlan-ng / p80211hdr.h
1 /* p80211hdr.h
2 *
3 * Macros, types, and functions for handling 802.11 MAC headers
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 * Note:
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 * All functions declared here are implemented in p80211.c
57 * --------------------------------------------------------------------
58 */
59
60 #ifndef _P80211HDR_H
61 #define _P80211HDR_H
62
63 /*================================================================*/
64 /* System Includes */
65
66 #include <linux/if_ether.h>
67
68 /*================================================================*/
69 /* Project Includes */
70
71 #ifndef  _WLAN_COMPAT_H
72 #include "wlan_compat.h"
73 #endif
74
75
76 /*================================================================*/
77 /* Constants */
78
79 /*--- Sizes -----------------------------------------------*/
80 #define WLAN_CRC_LEN                    4
81 #define WLAN_BSSID_LEN                  6
82 #define WLAN_BSS_TS_LEN                 8
83 #define WLAN_HDR_A3_LEN                 24
84 #define WLAN_HDR_A4_LEN                 30
85 #define WLAN_SSID_MAXLEN                32
86 #define WLAN_DATA_MAXLEN                2312
87 #define WLAN_A3FR_MAXLEN                (WLAN_HDR_A3_LEN + WLAN_DATA_MAXLEN + WLAN_CRC_LEN)
88 #define WLAN_A4FR_MAXLEN                (WLAN_HDR_A4_LEN + WLAN_DATA_MAXLEN + WLAN_CRC_LEN)
89 #define WLAN_BEACON_FR_MAXLEN           (WLAN_HDR_A3_LEN + 334)
90 #define WLAN_ATIM_FR_MAXLEN             (WLAN_HDR_A3_LEN + 0)
91 #define WLAN_DISASSOC_FR_MAXLEN         (WLAN_HDR_A3_LEN + 2)
92 #define WLAN_ASSOCREQ_FR_MAXLEN         (WLAN_HDR_A3_LEN + 48)
93 #define WLAN_ASSOCRESP_FR_MAXLEN        (WLAN_HDR_A3_LEN + 16)
94 #define WLAN_REASSOCREQ_FR_MAXLEN       (WLAN_HDR_A3_LEN + 54)
95 #define WLAN_REASSOCRESP_FR_MAXLEN      (WLAN_HDR_A3_LEN + 16)
96 #define WLAN_PROBEREQ_FR_MAXLEN         (WLAN_HDR_A3_LEN + 44)
97 #define WLAN_PROBERESP_FR_MAXLEN        (WLAN_HDR_A3_LEN + 78)
98 #define WLAN_AUTHEN_FR_MAXLEN           (WLAN_HDR_A3_LEN + 261)
99 #define WLAN_DEAUTHEN_FR_MAXLEN         (WLAN_HDR_A3_LEN + 2)
100 #define WLAN_WEP_NKEYS                  4
101 #define WLAN_WEP_MAXKEYLEN              13
102 #define WLAN_CHALLENGE_IE_LEN           130
103 #define WLAN_CHALLENGE_LEN              128
104 #define WLAN_WEP_IV_LEN                 4
105 #define WLAN_WEP_ICV_LEN                4
106
107 /*--- Frame Control Field -------------------------------------*/
108 /* Frame Types */
109 #define WLAN_FTYPE_MGMT                 0x00
110 #define WLAN_FTYPE_CTL                  0x01
111 #define WLAN_FTYPE_DATA                 0x02
112
113 /* Frame subtypes */
114 /* Management */
115 #define WLAN_FSTYPE_ASSOCREQ            0x00
116 #define WLAN_FSTYPE_ASSOCRESP           0x01
117 #define WLAN_FSTYPE_REASSOCREQ          0x02
118 #define WLAN_FSTYPE_REASSOCRESP         0x03
119 #define WLAN_FSTYPE_PROBEREQ            0x04
120 #define WLAN_FSTYPE_PROBERESP           0x05
121 #define WLAN_FSTYPE_BEACON              0x08
122 #define WLAN_FSTYPE_ATIM                0x09
123 #define WLAN_FSTYPE_DISASSOC            0x0a
124 #define WLAN_FSTYPE_AUTHEN              0x0b
125 #define WLAN_FSTYPE_DEAUTHEN            0x0c
126
127 /* Control */
128 #define WLAN_FSTYPE_BLOCKACKREQ         0x8
129 #define WLAN_FSTYPE_BLOCKACK            0x9
130 #define WLAN_FSTYPE_PSPOLL              0x0a
131 #define WLAN_FSTYPE_RTS                 0x0b
132 #define WLAN_FSTYPE_CTS                 0x0c
133 #define WLAN_FSTYPE_ACK                 0x0d
134 #define WLAN_FSTYPE_CFEND               0x0e
135 #define WLAN_FSTYPE_CFENDCFACK          0x0f
136
137 /* Data */
138 #define WLAN_FSTYPE_DATAONLY            0x00
139 #define WLAN_FSTYPE_DATA_CFACK          0x01
140 #define WLAN_FSTYPE_DATA_CFPOLL         0x02
141 #define WLAN_FSTYPE_DATA_CFACK_CFPOLL   0x03
142 #define WLAN_FSTYPE_NULL                0x04
143 #define WLAN_FSTYPE_CFACK               0x05
144 #define WLAN_FSTYPE_CFPOLL              0x06
145 #define WLAN_FSTYPE_CFACK_CFPOLL        0x07
146
147
148 /*================================================================*/
149 /* Macros */
150
151 /*--- FC Macros ----------------------------------------------*/
152 /* Macros to get/set the bitfields of the Frame Control Field */
153 /*  GET_FC_??? - takes the host byte-order value of an FC     */
154 /*               and retrieves the value of one of the        */
155 /*               bitfields and moves that value so its lsb is */
156 /*               in bit 0.                                    */
157 /*  SET_FC_??? - takes a host order value for one of the FC   */
158 /*               bitfields and moves it to the proper bit     */
159 /*               location for ORing into a host order FC.     */
160 /*               To send the FC produced from SET_FC_???,     */
161 /*               one must put the bytes in IEEE order.        */
162 /*  e.g.                                                      */
163 /*     printf("the frame subtype is %x",                      */
164 /*                 GET_FC_FTYPE( ieee2host( rx.fc )))         */
165 /*                                                            */
166 /*     tx.fc = host2ieee( SET_FC_FTYPE(WLAN_FTYP_CTL) |       */
167 /*                        SET_FC_FSTYPE(WLAN_FSTYPE_RTS) );   */
168 /*------------------------------------------------------------*/
169
170 #define WLAN_GET_FC_PVER(n)      (((u16)(n)) & (BIT0 | BIT1))
171 #define WLAN_GET_FC_FTYPE(n)    ((((u16)(n)) & (BIT2 | BIT3)) >> 2)
172 #define WLAN_GET_FC_FSTYPE(n)   ((((u16)(n)) & (BIT4|BIT5|BIT6|BIT7)) >> 4)
173 #define WLAN_GET_FC_TODS(n)     ((((u16)(n)) & (BIT8)) >> 8)
174 #define WLAN_GET_FC_FROMDS(n)   ((((u16)(n)) & (BIT9)) >> 9)
175 #define WLAN_GET_FC_MOREFRAG(n) ((((u16)(n)) & (BIT10)) >> 10)
176 #define WLAN_GET_FC_RETRY(n)    ((((u16)(n)) & (BIT11)) >> 11)
177 #define WLAN_GET_FC_PWRMGT(n)   ((((u16)(n)) & (BIT12)) >> 12)
178 #define WLAN_GET_FC_MOREDATA(n) ((((u16)(n)) & (BIT13)) >> 13)
179 #define WLAN_GET_FC_ISWEP(n)    ((((u16)(n)) & (BIT14)) >> 14)
180 #define WLAN_GET_FC_ORDER(n)    ((((u16)(n)) & (BIT15)) >> 15)
181
182 #define WLAN_SET_FC_PVER(n)     ((u16)(n))
183 #define WLAN_SET_FC_FTYPE(n)    (((u16)(n)) << 2)
184 #define WLAN_SET_FC_FSTYPE(n)   (((u16)(n)) << 4)
185 #define WLAN_SET_FC_TODS(n)     (((u16)(n)) << 8)
186 #define WLAN_SET_FC_FROMDS(n)   (((u16)(n)) << 9)
187 #define WLAN_SET_FC_MOREFRAG(n) (((u16)(n)) << 10)
188 #define WLAN_SET_FC_RETRY(n)    (((u16)(n)) << 11)
189 #define WLAN_SET_FC_PWRMGT(n)   (((u16)(n)) << 12)
190 #define WLAN_SET_FC_MOREDATA(n) (((u16)(n)) << 13)
191 #define WLAN_SET_FC_ISWEP(n)    (((u16)(n)) << 14)
192 #define WLAN_SET_FC_ORDER(n)    (((u16)(n)) << 15)
193
194 /*--- Duration Macros ----------------------------------------*/
195 /* Macros to get/set the bitfields of the Duration Field      */
196 /*  - the duration value is only valid when bit15 is zero     */
197 /*  - the firmware handles these values, so I'm not going     */
198 /*    these macros right now.                                 */
199 /*------------------------------------------------------------*/
200
201 /*--- Sequence Control  Macros -------------------------------*/
202 /* Macros to get/set the bitfields of the Sequence Control    */
203 /* Field.                                                     */
204 /*------------------------------------------------------------*/
205 #define WLAN_GET_SEQ_FRGNUM(n) (((u16)(n)) & (BIT0|BIT1|BIT2|BIT3))
206 #define WLAN_GET_SEQ_SEQNUM(n) ((((u16)(n)) & (~(BIT0|BIT1|BIT2|BIT3))) >> 4)
207
208 /*--- Data ptr macro -----------------------------------------*/
209 /* Creates a u8* to the data portion of a frame            */
210 /* Assumes you're passing in a ptr to the beginning of the hdr*/
211 /*------------------------------------------------------------*/
212 #define WLAN_HDR_A3_DATAP(p) (((u8*)(p)) + WLAN_HDR_A3_LEN)
213 #define WLAN_HDR_A4_DATAP(p) (((u8*)(p)) + WLAN_HDR_A4_LEN)
214
215 #define DOT11_RATE5_ISBASIC_GET(r)     (((u8)(r)) & BIT7)
216
217 /*================================================================*/
218 /* Types */
219
220 /* BSS Timestamp */
221 typedef u8 wlan_bss_ts_t[WLAN_BSS_TS_LEN];
222
223 /* Generic 802.11 Header types */
224
225 typedef struct p80211_hdr_a3
226 {
227         u16     fc;
228         u16     dur;
229         u8      a1[ETH_ALEN];
230         u8      a2[ETH_ALEN];
231         u8      a3[ETH_ALEN];
232         u16     seq;
233 } __attribute__((packed)) p80211_hdr_a3_t;
234
235 typedef struct p80211_hdr_a4
236 {
237         u16     fc;
238         u16     dur;
239         u8      a1[ETH_ALEN];
240         u8      a2[ETH_ALEN];
241         u8      a3[ETH_ALEN];
242         u16     seq;
243         u8      a4[ETH_ALEN];
244 } __attribute__((packed)) p80211_hdr_a4_t;
245
246 typedef union p80211_hdr
247 {
248         p80211_hdr_a3_t         a3;
249         p80211_hdr_a4_t         a4;
250 } __attribute__((packed)) p80211_hdr_t;
251
252
253 /*================================================================*/
254 /* Extern Declarations */
255
256
257 /*================================================================*/
258 /* Function Declarations */
259
260 /* Frame and header lenght macros */
261
262 #define WLAN_CTL_FRAMELEN(fstype) (\
263         (fstype) == WLAN_FSTYPE_BLOCKACKREQ     ? 24 : \
264         (fstype) == WLAN_FSTYPE_BLOCKACK        ? 152 : \
265         (fstype) == WLAN_FSTYPE_PSPOLL          ? 20 : \
266         (fstype) == WLAN_FSTYPE_RTS             ? 20 : \
267         (fstype) == WLAN_FSTYPE_CTS             ? 14 : \
268         (fstype) == WLAN_FSTYPE_ACK             ? 14 : \
269         (fstype) == WLAN_FSTYPE_CFEND           ? 20 : \
270         (fstype) == WLAN_FSTYPE_CFENDCFACK      ? 20 : 4)
271
272 #define WLAN_FCS_LEN                    4
273
274 /* ftcl in HOST order */
275 inline static u16 p80211_headerlen(u16 fctl)
276 {
277         u16 hdrlen = 0;
278
279         switch ( WLAN_GET_FC_FTYPE(fctl) ) {
280         case WLAN_FTYPE_MGMT:
281                 hdrlen = WLAN_HDR_A3_LEN;
282                 break;
283         case WLAN_FTYPE_DATA:
284                 hdrlen = WLAN_HDR_A3_LEN;
285                 if ( WLAN_GET_FC_TODS(fctl) && WLAN_GET_FC_FROMDS(fctl) ) {
286                         hdrlen += ETH_ALEN;
287                 }
288                 break;
289         case WLAN_FTYPE_CTL:
290                 hdrlen = WLAN_CTL_FRAMELEN(WLAN_GET_FC_FSTYPE(fctl)) -
291                         WLAN_FCS_LEN;
292                 break;
293         default:
294                 hdrlen = WLAN_HDR_A3_LEN;
295         }
296
297         return hdrlen;
298 }
299
300 #endif /* _P80211HDR_H */