3 * Macros, types, and functions for handling 802.11 MAC headers
5 * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.
6 * --------------------------------------------------------------------
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/
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.
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.
31 * --------------------------------------------------------------------
33 * Inquiries regarding the linux-wlan Open Source project can be
36 * AbsoluteValue Systems Inc.
38 * http://www.linux-wlan.com
40 * --------------------------------------------------------------------
42 * Portions of the development of this software were funded by
43 * Intersil Corporation as part of PRISM(R) chipset product development.
45 * --------------------------------------------------------------------
47 * This file declares the constants and types used in the interface
48 * between a wlan driver and the user mode utilities.
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.
56 * All functions declared here are implemented in p80211.c
57 * --------------------------------------------------------------------
63 /*================================================================*/
66 /*================================================================*/
67 /* Project Includes */
69 #ifndef _WLAN_COMPAT_H
70 #include "wlan_compat.h"
74 /*================================================================*/
77 /*--- Sizes -----------------------------------------------*/
78 #define WLAN_ADDR_LEN 6
79 #define WLAN_CRC_LEN 4
80 #define WLAN_BSSID_LEN 6
81 #define WLAN_BSS_TS_LEN 8
82 #define WLAN_HDR_A3_LEN 24
83 #define WLAN_HDR_A4_LEN 30
84 #define WLAN_SSID_MAXLEN 32
85 #define WLAN_DATA_MAXLEN 2312
86 #define WLAN_A3FR_MAXLEN (WLAN_HDR_A3_LEN + WLAN_DATA_MAXLEN + WLAN_CRC_LEN)
87 #define WLAN_A4FR_MAXLEN (WLAN_HDR_A4_LEN + WLAN_DATA_MAXLEN + WLAN_CRC_LEN)
88 #define WLAN_BEACON_FR_MAXLEN (WLAN_HDR_A3_LEN + 334)
89 #define WLAN_ATIM_FR_MAXLEN (WLAN_HDR_A3_LEN + 0)
90 #define WLAN_DISASSOC_FR_MAXLEN (WLAN_HDR_A3_LEN + 2)
91 #define WLAN_ASSOCREQ_FR_MAXLEN (WLAN_HDR_A3_LEN + 48)
92 #define WLAN_ASSOCRESP_FR_MAXLEN (WLAN_HDR_A3_LEN + 16)
93 #define WLAN_REASSOCREQ_FR_MAXLEN (WLAN_HDR_A3_LEN + 54)
94 #define WLAN_REASSOCRESP_FR_MAXLEN (WLAN_HDR_A3_LEN + 16)
95 #define WLAN_PROBEREQ_FR_MAXLEN (WLAN_HDR_A3_LEN + 44)
96 #define WLAN_PROBERESP_FR_MAXLEN (WLAN_HDR_A3_LEN + 78)
97 #define WLAN_AUTHEN_FR_MAXLEN (WLAN_HDR_A3_LEN + 261)
98 #define WLAN_DEAUTHEN_FR_MAXLEN (WLAN_HDR_A3_LEN + 2)
99 #define WLAN_WEP_NKEYS 4
100 #define WLAN_WEP_MAXKEYLEN 13
101 #define WLAN_CHALLENGE_IE_LEN 130
102 #define WLAN_CHALLENGE_LEN 128
103 #define WLAN_WEP_IV_LEN 4
104 #define WLAN_WEP_ICV_LEN 4
106 /*--- Frame Control Field -------------------------------------*/
108 #define WLAN_FTYPE_MGMT 0x00
109 #define WLAN_FTYPE_CTL 0x01
110 #define WLAN_FTYPE_DATA 0x02
114 #define WLAN_FSTYPE_ASSOCREQ 0x00
115 #define WLAN_FSTYPE_ASSOCRESP 0x01
116 #define WLAN_FSTYPE_REASSOCREQ 0x02
117 #define WLAN_FSTYPE_REASSOCRESP 0x03
118 #define WLAN_FSTYPE_PROBEREQ 0x04
119 #define WLAN_FSTYPE_PROBERESP 0x05
120 #define WLAN_FSTYPE_BEACON 0x08
121 #define WLAN_FSTYPE_ATIM 0x09
122 #define WLAN_FSTYPE_DISASSOC 0x0a
123 #define WLAN_FSTYPE_AUTHEN 0x0b
124 #define WLAN_FSTYPE_DEAUTHEN 0x0c
127 #define WLAN_FSTYPE_BLOCKACKREQ 0x8
128 #define WLAN_FSTYPE_BLOCKACK 0x9
129 #define WLAN_FSTYPE_PSPOLL 0x0a
130 #define WLAN_FSTYPE_RTS 0x0b
131 #define WLAN_FSTYPE_CTS 0x0c
132 #define WLAN_FSTYPE_ACK 0x0d
133 #define WLAN_FSTYPE_CFEND 0x0e
134 #define WLAN_FSTYPE_CFENDCFACK 0x0f
137 #define WLAN_FSTYPE_DATAONLY 0x00
138 #define WLAN_FSTYPE_DATA_CFACK 0x01
139 #define WLAN_FSTYPE_DATA_CFPOLL 0x02
140 #define WLAN_FSTYPE_DATA_CFACK_CFPOLL 0x03
141 #define WLAN_FSTYPE_NULL 0x04
142 #define WLAN_FSTYPE_CFACK 0x05
143 #define WLAN_FSTYPE_CFPOLL 0x06
144 #define WLAN_FSTYPE_CFACK_CFPOLL 0x07
147 /*================================================================*/
150 /*--- FC Macros ----------------------------------------------*/
151 /* Macros to get/set the bitfields of the Frame Control Field */
152 /* GET_FC_??? - takes the host byte-order value of an FC */
153 /* and retrieves the value of one of the */
154 /* bitfields and moves that value so its lsb is */
156 /* SET_FC_??? - takes a host order value for one of the FC */
157 /* bitfields and moves it to the proper bit */
158 /* location for ORing into a host order FC. */
159 /* To send the FC produced from SET_FC_???, */
160 /* one must put the bytes in IEEE order. */
162 /* printf("the frame subtype is %x", */
163 /* GET_FC_FTYPE( ieee2host( rx.fc ))) */
165 /* tx.fc = host2ieee( SET_FC_FTYPE(WLAN_FTYP_CTL) | */
166 /* SET_FC_FSTYPE(WLAN_FSTYPE_RTS) ); */
167 /*------------------------------------------------------------*/
169 #define WLAN_GET_FC_PVER(n) (((UINT16)(n)) & (BIT0 | BIT1))
170 #define WLAN_GET_FC_FTYPE(n) ((((UINT16)(n)) & (BIT2 | BIT3)) >> 2)
171 #define WLAN_GET_FC_FSTYPE(n) ((((UINT16)(n)) & (BIT4|BIT5|BIT6|BIT7)) >> 4)
172 #define WLAN_GET_FC_TODS(n) ((((UINT16)(n)) & (BIT8)) >> 8)
173 #define WLAN_GET_FC_FROMDS(n) ((((UINT16)(n)) & (BIT9)) >> 9)
174 #define WLAN_GET_FC_MOREFRAG(n) ((((UINT16)(n)) & (BIT10)) >> 10)
175 #define WLAN_GET_FC_RETRY(n) ((((UINT16)(n)) & (BIT11)) >> 11)
176 #define WLAN_GET_FC_PWRMGT(n) ((((UINT16)(n)) & (BIT12)) >> 12)
177 #define WLAN_GET_FC_MOREDATA(n) ((((UINT16)(n)) & (BIT13)) >> 13)
178 #define WLAN_GET_FC_ISWEP(n) ((((UINT16)(n)) & (BIT14)) >> 14)
179 #define WLAN_GET_FC_ORDER(n) ((((UINT16)(n)) & (BIT15)) >> 15)
181 #define WLAN_SET_FC_PVER(n) ((UINT16)(n))
182 #define WLAN_SET_FC_FTYPE(n) (((UINT16)(n)) << 2)
183 #define WLAN_SET_FC_FSTYPE(n) (((UINT16)(n)) << 4)
184 #define WLAN_SET_FC_TODS(n) (((UINT16)(n)) << 8)
185 #define WLAN_SET_FC_FROMDS(n) (((UINT16)(n)) << 9)
186 #define WLAN_SET_FC_MOREFRAG(n) (((UINT16)(n)) << 10)
187 #define WLAN_SET_FC_RETRY(n) (((UINT16)(n)) << 11)
188 #define WLAN_SET_FC_PWRMGT(n) (((UINT16)(n)) << 12)
189 #define WLAN_SET_FC_MOREDATA(n) (((UINT16)(n)) << 13)
190 #define WLAN_SET_FC_ISWEP(n) (((UINT16)(n)) << 14)
191 #define WLAN_SET_FC_ORDER(n) (((UINT16)(n)) << 15)
193 /*--- Duration Macros ----------------------------------------*/
194 /* Macros to get/set the bitfields of the Duration Field */
195 /* - the duration value is only valid when bit15 is zero */
196 /* - the firmware handles these values, so I'm not going */
197 /* these macros right now. */
198 /*------------------------------------------------------------*/
200 /*--- Sequence Control Macros -------------------------------*/
201 /* Macros to get/set the bitfields of the Sequence Control */
203 /*------------------------------------------------------------*/
204 #define WLAN_GET_SEQ_FRGNUM(n) (((UINT16)(n)) & (BIT0|BIT1|BIT2|BIT3))
205 #define WLAN_GET_SEQ_SEQNUM(n) ((((UINT16)(n)) & (~(BIT0|BIT1|BIT2|BIT3))) >> 4)
207 /*--- Data ptr macro -----------------------------------------*/
208 /* Creates a UINT8* to the data portion of a frame */
209 /* Assumes you're passing in a ptr to the beginning of the hdr*/
210 /*------------------------------------------------------------*/
211 #define WLAN_HDR_A3_DATAP(p) (((UINT8*)(p)) + WLAN_HDR_A3_LEN)
212 #define WLAN_HDR_A4_DATAP(p) (((UINT8*)(p)) + WLAN_HDR_A4_LEN)
214 #define DOT11_RATE5_ISBASIC_GET(r) (((UINT8)(r)) & BIT7)
216 /*================================================================*/
220 typedef UINT8 wlan_bss_ts_t[WLAN_BSS_TS_LEN];
222 /* Generic 802.11 Header types */
224 typedef struct p80211_hdr_a3
228 UINT8 a1[WLAN_ADDR_LEN];
229 UINT8 a2[WLAN_ADDR_LEN];
230 UINT8 a3[WLAN_ADDR_LEN];
232 } __WLAN_ATTRIB_PACK__ p80211_hdr_a3_t;
234 typedef struct p80211_hdr_a4
238 UINT8 a1[WLAN_ADDR_LEN];
239 UINT8 a2[WLAN_ADDR_LEN];
240 UINT8 a3[WLAN_ADDR_LEN];
242 UINT8 a4[WLAN_ADDR_LEN];
243 } __WLAN_ATTRIB_PACK__ p80211_hdr_a4_t;
245 typedef union p80211_hdr
249 } __WLAN_ATTRIB_PACK__ p80211_hdr_t;
252 /*================================================================*/
253 /* Extern Declarations */
256 /*================================================================*/
257 /* Function Declarations */
259 /* Frame and header lenght macros */
261 #define WLAN_CTL_FRAMELEN(fstype) (\
262 (fstype) == WLAN_FSTYPE_BLOCKACKREQ ? 24 : \
263 (fstype) == WLAN_FSTYPE_BLOCKACK ? 152 : \
264 (fstype) == WLAN_FSTYPE_PSPOLL ? 20 : \
265 (fstype) == WLAN_FSTYPE_RTS ? 20 : \
266 (fstype) == WLAN_FSTYPE_CTS ? 14 : \
267 (fstype) == WLAN_FSTYPE_ACK ? 14 : \
268 (fstype) == WLAN_FSTYPE_CFEND ? 20 : \
269 (fstype) == WLAN_FSTYPE_CFENDCFACK ? 20 : 4)
271 #define WLAN_FCS_LEN 4
273 /* ftcl in HOST order */
274 inline static UINT16 p80211_headerlen(UINT16 fctl)
278 switch ( WLAN_GET_FC_FTYPE(fctl) ) {
279 case WLAN_FTYPE_MGMT:
280 hdrlen = WLAN_HDR_A3_LEN;
282 case WLAN_FTYPE_DATA:
283 hdrlen = WLAN_HDR_A3_LEN;
284 if ( WLAN_GET_FC_TODS(fctl) && WLAN_GET_FC_FROMDS(fctl) ) {
285 hdrlen += WLAN_ADDR_LEN;
289 hdrlen = WLAN_CTL_FRAMELEN(WLAN_GET_FC_FSTYPE(fctl)) -
293 hdrlen = WLAN_HDR_A3_LEN;
299 #endif /* _P80211HDR_H */