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 #include <linux/if_ether.h>
68 /*================================================================*/
69 /* Project Includes */
73 /*================================================================*/
76 /*--- Sizes -----------------------------------------------*/
77 #define WLAN_CRC_LEN 4
78 #define WLAN_BSSID_LEN 6
79 #define WLAN_HDR_A3_LEN 24
80 #define WLAN_HDR_A4_LEN 30
81 #define WLAN_SSID_MAXLEN 32
82 #define WLAN_DATA_MAXLEN 2312
83 #define WLAN_WEP_IV_LEN 4
84 #define WLAN_WEP_ICV_LEN 4
86 /*--- Frame Control Field -------------------------------------*/
88 #define WLAN_FTYPE_MGMT 0x00
89 #define WLAN_FTYPE_CTL 0x01
90 #define WLAN_FTYPE_DATA 0x02
94 #define WLAN_FSTYPE_ASSOCREQ 0x00
95 #define WLAN_FSTYPE_ASSOCRESP 0x01
96 #define WLAN_FSTYPE_REASSOCREQ 0x02
97 #define WLAN_FSTYPE_REASSOCRESP 0x03
98 #define WLAN_FSTYPE_PROBEREQ 0x04
99 #define WLAN_FSTYPE_PROBERESP 0x05
100 #define WLAN_FSTYPE_BEACON 0x08
101 #define WLAN_FSTYPE_ATIM 0x09
102 #define WLAN_FSTYPE_DISASSOC 0x0a
103 #define WLAN_FSTYPE_AUTHEN 0x0b
104 #define WLAN_FSTYPE_DEAUTHEN 0x0c
107 #define WLAN_FSTYPE_BLOCKACKREQ 0x8
108 #define WLAN_FSTYPE_BLOCKACK 0x9
109 #define WLAN_FSTYPE_PSPOLL 0x0a
110 #define WLAN_FSTYPE_RTS 0x0b
111 #define WLAN_FSTYPE_CTS 0x0c
112 #define WLAN_FSTYPE_ACK 0x0d
113 #define WLAN_FSTYPE_CFEND 0x0e
114 #define WLAN_FSTYPE_CFENDCFACK 0x0f
117 #define WLAN_FSTYPE_DATAONLY 0x00
118 #define WLAN_FSTYPE_DATA_CFACK 0x01
119 #define WLAN_FSTYPE_DATA_CFPOLL 0x02
120 #define WLAN_FSTYPE_DATA_CFACK_CFPOLL 0x03
121 #define WLAN_FSTYPE_NULL 0x04
122 #define WLAN_FSTYPE_CFACK 0x05
123 #define WLAN_FSTYPE_CFPOLL 0x06
124 #define WLAN_FSTYPE_CFACK_CFPOLL 0x07
126 /*================================================================*/
129 /*--- FC Macros ----------------------------------------------*/
130 /* Macros to get/set the bitfields of the Frame Control Field */
131 /* GET_FC_??? - takes the host byte-order value of an FC */
132 /* and retrieves the value of one of the */
133 /* bitfields and moves that value so its lsb is */
135 /* SET_FC_??? - takes a host order value for one of the FC */
136 /* bitfields and moves it to the proper bit */
137 /* location for ORing into a host order FC. */
138 /* To send the FC produced from SET_FC_???, */
139 /* one must put the bytes in IEEE order. */
141 /* printf("the frame subtype is %x", */
142 /* GET_FC_FTYPE( ieee2host( rx.fc ))) */
144 /* tx.fc = host2ieee( SET_FC_FTYPE(WLAN_FTYP_CTL) | */
145 /* SET_FC_FSTYPE(WLAN_FSTYPE_RTS) ); */
146 /*------------------------------------------------------------*/
148 #define WLAN_GET_FC_FTYPE(n) ((((u16)(n)) & (BIT(2) | BIT(3))) >> 2)
149 #define WLAN_GET_FC_FSTYPE(n) ((((u16)(n)) & (BIT(4)|BIT(5)|BIT(6)|BIT(7))) >> 4)
150 #define WLAN_GET_FC_TODS(n) ((((u16)(n)) & (BIT(8))) >> 8)
151 #define WLAN_GET_FC_FROMDS(n) ((((u16)(n)) & (BIT(9))) >> 9)
152 #define WLAN_GET_FC_ISWEP(n) ((((u16)(n)) & (BIT(14))) >> 14)
154 #define WLAN_SET_FC_FTYPE(n) (((u16)(n)) << 2)
155 #define WLAN_SET_FC_FSTYPE(n) (((u16)(n)) << 4)
156 #define WLAN_SET_FC_TODS(n) (((u16)(n)) << 8)
157 #define WLAN_SET_FC_FROMDS(n) (((u16)(n)) << 9)
158 #define WLAN_SET_FC_ISWEP(n) (((u16)(n)) << 14)
160 #define DOT11_RATE5_ISBASIC_GET(r) (((u8)(r)) & BIT(7))
162 /*================================================================*/
165 /* Generic 802.11 Header types */
167 typedef struct p80211_hdr_a3 {
174 } __attribute__ ((packed)) p80211_hdr_a3_t;
176 typedef struct p80211_hdr_a4 {
184 } __attribute__ ((packed)) p80211_hdr_a4_t;
186 typedef union p80211_hdr {
189 } __attribute__ ((packed)) p80211_hdr_t;
192 /* Frame and header length macros */
194 #define WLAN_CTL_FRAMELEN(fstype) (\
195 (fstype) == WLAN_FSTYPE_BLOCKACKREQ ? 24 : \
196 (fstype) == WLAN_FSTYPE_BLOCKACK ? 152 : \
197 (fstype) == WLAN_FSTYPE_PSPOLL ? 20 : \
198 (fstype) == WLAN_FSTYPE_RTS ? 20 : \
199 (fstype) == WLAN_FSTYPE_CTS ? 14 : \
200 (fstype) == WLAN_FSTYPE_ACK ? 14 : \
201 (fstype) == WLAN_FSTYPE_CFEND ? 20 : \
202 (fstype) == WLAN_FSTYPE_CFENDCFACK ? 20 : 4)
204 #define WLAN_FCS_LEN 4
206 /* ftcl in HOST order */
207 static inline u16 p80211_headerlen(u16 fctl)
211 switch (WLAN_GET_FC_FTYPE(fctl)) {
212 case WLAN_FTYPE_MGMT:
213 hdrlen = WLAN_HDR_A3_LEN;
215 case WLAN_FTYPE_DATA:
216 hdrlen = WLAN_HDR_A3_LEN;
217 if (WLAN_GET_FC_TODS(fctl) && WLAN_GET_FC_FROMDS(fctl))
221 hdrlen = WLAN_CTL_FRAMELEN(WLAN_GET_FC_FSTYPE(fctl)) -
225 hdrlen = WLAN_HDR_A3_LEN;
231 #endif /* _P80211HDR_H */