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 */
71 #ifndef _WLAN_COMPAT_H
72 #include "wlan_compat.h"
76 /*================================================================*/
79 /*--- Sizes -----------------------------------------------*/
80 #define WLAN_CRC_LEN 4
81 #define WLAN_BSSID_LEN 6
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_WEP_IV_LEN 4
87 #define WLAN_WEP_ICV_LEN 4
89 /*--- Frame Control Field -------------------------------------*/
91 #define WLAN_FTYPE_MGMT 0x00
92 #define WLAN_FTYPE_CTL 0x01
93 #define WLAN_FTYPE_DATA 0x02
97 #define WLAN_FSTYPE_ASSOCREQ 0x00
98 #define WLAN_FSTYPE_ASSOCRESP 0x01
99 #define WLAN_FSTYPE_REASSOCREQ 0x02
100 #define WLAN_FSTYPE_REASSOCRESP 0x03
101 #define WLAN_FSTYPE_PROBEREQ 0x04
102 #define WLAN_FSTYPE_PROBERESP 0x05
103 #define WLAN_FSTYPE_BEACON 0x08
104 #define WLAN_FSTYPE_ATIM 0x09
105 #define WLAN_FSTYPE_DISASSOC 0x0a
106 #define WLAN_FSTYPE_AUTHEN 0x0b
107 #define WLAN_FSTYPE_DEAUTHEN 0x0c
110 #define WLAN_FSTYPE_BLOCKACKREQ 0x8
111 #define WLAN_FSTYPE_BLOCKACK 0x9
112 #define WLAN_FSTYPE_PSPOLL 0x0a
113 #define WLAN_FSTYPE_RTS 0x0b
114 #define WLAN_FSTYPE_CTS 0x0c
115 #define WLAN_FSTYPE_ACK 0x0d
116 #define WLAN_FSTYPE_CFEND 0x0e
117 #define WLAN_FSTYPE_CFENDCFACK 0x0f
120 #define WLAN_FSTYPE_DATAONLY 0x00
121 #define WLAN_FSTYPE_DATA_CFACK 0x01
122 #define WLAN_FSTYPE_DATA_CFPOLL 0x02
123 #define WLAN_FSTYPE_DATA_CFACK_CFPOLL 0x03
124 #define WLAN_FSTYPE_NULL 0x04
125 #define WLAN_FSTYPE_CFACK 0x05
126 #define WLAN_FSTYPE_CFPOLL 0x06
127 #define WLAN_FSTYPE_CFACK_CFPOLL 0x07
129 /*================================================================*/
132 /*--- FC Macros ----------------------------------------------*/
133 /* Macros to get/set the bitfields of the Frame Control Field */
134 /* GET_FC_??? - takes the host byte-order value of an FC */
135 /* and retrieves the value of one of the */
136 /* bitfields and moves that value so its lsb is */
138 /* SET_FC_??? - takes a host order value for one of the FC */
139 /* bitfields and moves it to the proper bit */
140 /* location for ORing into a host order FC. */
141 /* To send the FC produced from SET_FC_???, */
142 /* one must put the bytes in IEEE order. */
144 /* printf("the frame subtype is %x", */
145 /* GET_FC_FTYPE( ieee2host( rx.fc ))) */
147 /* tx.fc = host2ieee( SET_FC_FTYPE(WLAN_FTYP_CTL) | */
148 /* SET_FC_FSTYPE(WLAN_FSTYPE_RTS) ); */
149 /*------------------------------------------------------------*/
151 #define WLAN_GET_FC_FTYPE(n) ((((u16)(n)) & (BIT(2) | BIT(3))) >> 2)
152 #define WLAN_GET_FC_FSTYPE(n) ((((u16)(n)) & (BIT(4)|BIT(5)|BIT(6)|BIT(7))) >> 4)
153 #define WLAN_GET_FC_TODS(n) ((((u16)(n)) & (BIT(8))) >> 8)
154 #define WLAN_GET_FC_FROMDS(n) ((((u16)(n)) & (BIT(9))) >> 9)
155 #define WLAN_GET_FC_ISWEP(n) ((((u16)(n)) & (BIT(14))) >> 14)
157 #define WLAN_SET_FC_FTYPE(n) (((u16)(n)) << 2)
158 #define WLAN_SET_FC_FSTYPE(n) (((u16)(n)) << 4)
159 #define WLAN_SET_FC_TODS(n) (((u16)(n)) << 8)
160 #define WLAN_SET_FC_FROMDS(n) (((u16)(n)) << 9)
161 #define WLAN_SET_FC_ISWEP(n) (((u16)(n)) << 14)
163 #define DOT11_RATE5_ISBASIC_GET(r) (((u8)(r)) & BIT(7))
165 /*================================================================*/
168 /* Generic 802.11 Header types */
170 typedef struct p80211_hdr_a3 {
177 } __attribute__ ((packed)) p80211_hdr_a3_t;
179 typedef struct p80211_hdr_a4 {
187 } __attribute__ ((packed)) p80211_hdr_a4_t;
189 typedef union p80211_hdr {
192 } __attribute__ ((packed)) p80211_hdr_t;
195 /* Frame and header length macros */
197 #define WLAN_CTL_FRAMELEN(fstype) (\
198 (fstype) == WLAN_FSTYPE_BLOCKACKREQ ? 24 : \
199 (fstype) == WLAN_FSTYPE_BLOCKACK ? 152 : \
200 (fstype) == WLAN_FSTYPE_PSPOLL ? 20 : \
201 (fstype) == WLAN_FSTYPE_RTS ? 20 : \
202 (fstype) == WLAN_FSTYPE_CTS ? 14 : \
203 (fstype) == WLAN_FSTYPE_ACK ? 14 : \
204 (fstype) == WLAN_FSTYPE_CFEND ? 20 : \
205 (fstype) == WLAN_FSTYPE_CFENDCFACK ? 20 : 4)
207 #define WLAN_FCS_LEN 4
209 /* ftcl in HOST order */
210 static inline u16 p80211_headerlen(u16 fctl)
214 switch (WLAN_GET_FC_FTYPE(fctl)) {
215 case WLAN_FTYPE_MGMT:
216 hdrlen = WLAN_HDR_A3_LEN;
218 case WLAN_FTYPE_DATA:
219 hdrlen = WLAN_HDR_A3_LEN;
220 if (WLAN_GET_FC_TODS(fctl) && WLAN_GET_FC_FROMDS(fctl))
224 hdrlen = WLAN_CTL_FRAMELEN(WLAN_GET_FC_FSTYPE(fctl)) -
228 hdrlen = WLAN_HDR_A3_LEN;
234 #endif /* _P80211HDR_H */