ACPI: thinkpad-acpi: add development version tag
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / staging / wlan-ng / p80211hdr.h
blob1703c92394761c09cd1035a18917c59b1459d510
1 /* p80211hdr.h
3 * Macros, types, and functions for handling 802.11 MAC headers
5 * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.
6 * --------------------------------------------------------------------
8 * linux-wlan
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
34 * made directly to:
36 * AbsoluteValue Systems Inc.
37 * info@linux-wlan.com
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.
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.
56 * All functions declared here are implemented in p80211.c
57 * --------------------------------------------------------------------
60 #ifndef _P80211HDR_H
61 #define _P80211HDR_H
63 /*================================================================*/
64 /* System Includes */
66 #include <linux/if_ether.h>
68 /*================================================================*/
69 /* Project Includes */
71 /*================================================================*/
72 /* Constants */
74 /*--- Sizes -----------------------------------------------*/
75 #define WLAN_CRC_LEN 4
76 #define WLAN_BSSID_LEN 6
77 #define WLAN_HDR_A3_LEN 24
78 #define WLAN_HDR_A4_LEN 30
79 #define WLAN_SSID_MAXLEN 32
80 #define WLAN_DATA_MAXLEN 2312
81 #define WLAN_WEP_IV_LEN 4
82 #define WLAN_WEP_ICV_LEN 4
84 /*--- Frame Control Field -------------------------------------*/
85 /* Frame Types */
86 #define WLAN_FTYPE_MGMT 0x00
87 #define WLAN_FTYPE_CTL 0x01
88 #define WLAN_FTYPE_DATA 0x02
90 /* Frame subtypes */
91 /* Management */
92 #define WLAN_FSTYPE_ASSOCREQ 0x00
93 #define WLAN_FSTYPE_ASSOCRESP 0x01
94 #define WLAN_FSTYPE_REASSOCREQ 0x02
95 #define WLAN_FSTYPE_REASSOCRESP 0x03
96 #define WLAN_FSTYPE_PROBEREQ 0x04
97 #define WLAN_FSTYPE_PROBERESP 0x05
98 #define WLAN_FSTYPE_BEACON 0x08
99 #define WLAN_FSTYPE_ATIM 0x09
100 #define WLAN_FSTYPE_DISASSOC 0x0a
101 #define WLAN_FSTYPE_AUTHEN 0x0b
102 #define WLAN_FSTYPE_DEAUTHEN 0x0c
104 /* Control */
105 #define WLAN_FSTYPE_BLOCKACKREQ 0x8
106 #define WLAN_FSTYPE_BLOCKACK 0x9
107 #define WLAN_FSTYPE_PSPOLL 0x0a
108 #define WLAN_FSTYPE_RTS 0x0b
109 #define WLAN_FSTYPE_CTS 0x0c
110 #define WLAN_FSTYPE_ACK 0x0d
111 #define WLAN_FSTYPE_CFEND 0x0e
112 #define WLAN_FSTYPE_CFENDCFACK 0x0f
114 /* Data */
115 #define WLAN_FSTYPE_DATAONLY 0x00
116 #define WLAN_FSTYPE_DATA_CFACK 0x01
117 #define WLAN_FSTYPE_DATA_CFPOLL 0x02
118 #define WLAN_FSTYPE_DATA_CFACK_CFPOLL 0x03
119 #define WLAN_FSTYPE_NULL 0x04
120 #define WLAN_FSTYPE_CFACK 0x05
121 #define WLAN_FSTYPE_CFPOLL 0x06
122 #define WLAN_FSTYPE_CFACK_CFPOLL 0x07
124 /*================================================================*/
125 /* Macros */
127 /*--- FC Macros ----------------------------------------------*/
128 /* Macros to get/set the bitfields of the Frame Control Field */
129 /* GET_FC_??? - takes the host byte-order value of an FC */
130 /* and retrieves the value of one of the */
131 /* bitfields and moves that value so its lsb is */
132 /* in bit 0. */
133 /* SET_FC_??? - takes a host order value for one of the FC */
134 /* bitfields and moves it to the proper bit */
135 /* location for ORing into a host order FC. */
136 /* To send the FC produced from SET_FC_???, */
137 /* one must put the bytes in IEEE order. */
138 /* e.g. */
139 /* printf("the frame subtype is %x", */
140 /* GET_FC_FTYPE( ieee2host( rx.fc ))) */
141 /* */
142 /* tx.fc = host2ieee( SET_FC_FTYPE(WLAN_FTYP_CTL) | */
143 /* SET_FC_FSTYPE(WLAN_FSTYPE_RTS) ); */
144 /*------------------------------------------------------------*/
146 #define WLAN_GET_FC_FTYPE(n) ((((u16)(n)) & (BIT(2) | BIT(3))) >> 2)
147 #define WLAN_GET_FC_FSTYPE(n) ((((u16)(n)) & (BIT(4)|BIT(5)|BIT(6)|BIT(7))) >> 4)
148 #define WLAN_GET_FC_TODS(n) ((((u16)(n)) & (BIT(8))) >> 8)
149 #define WLAN_GET_FC_FROMDS(n) ((((u16)(n)) & (BIT(9))) >> 9)
150 #define WLAN_GET_FC_ISWEP(n) ((((u16)(n)) & (BIT(14))) >> 14)
152 #define WLAN_SET_FC_FTYPE(n) (((u16)(n)) << 2)
153 #define WLAN_SET_FC_FSTYPE(n) (((u16)(n)) << 4)
154 #define WLAN_SET_FC_TODS(n) (((u16)(n)) << 8)
155 #define WLAN_SET_FC_FROMDS(n) (((u16)(n)) << 9)
156 #define WLAN_SET_FC_ISWEP(n) (((u16)(n)) << 14)
158 #define DOT11_RATE5_ISBASIC_GET(r) (((u8)(r)) & BIT(7))
160 /*================================================================*/
161 /* Types */
163 /* Generic 802.11 Header types */
165 typedef struct p80211_hdr_a3 {
166 u16 fc;
167 u16 dur;
168 u8 a1[ETH_ALEN];
169 u8 a2[ETH_ALEN];
170 u8 a3[ETH_ALEN];
171 u16 seq;
172 } __attribute__ ((packed)) p80211_hdr_a3_t;
174 typedef struct p80211_hdr_a4 {
175 u16 fc;
176 u16 dur;
177 u8 a1[ETH_ALEN];
178 u8 a2[ETH_ALEN];
179 u8 a3[ETH_ALEN];
180 u16 seq;
181 u8 a4[ETH_ALEN];
182 } __attribute__ ((packed)) p80211_hdr_a4_t;
184 typedef union p80211_hdr {
185 p80211_hdr_a3_t a3;
186 p80211_hdr_a4_t a4;
187 } __attribute__ ((packed)) p80211_hdr_t;
189 /* Frame and header length macros */
191 #define WLAN_CTL_FRAMELEN(fstype) (\
192 (fstype) == WLAN_FSTYPE_BLOCKACKREQ ? 24 : \
193 (fstype) == WLAN_FSTYPE_BLOCKACK ? 152 : \
194 (fstype) == WLAN_FSTYPE_PSPOLL ? 20 : \
195 (fstype) == WLAN_FSTYPE_RTS ? 20 : \
196 (fstype) == WLAN_FSTYPE_CTS ? 14 : \
197 (fstype) == WLAN_FSTYPE_ACK ? 14 : \
198 (fstype) == WLAN_FSTYPE_CFEND ? 20 : \
199 (fstype) == WLAN_FSTYPE_CFENDCFACK ? 20 : 4)
201 #define WLAN_FCS_LEN 4
203 /* ftcl in HOST order */
204 static inline u16 p80211_headerlen(u16 fctl)
206 u16 hdrlen = 0;
208 switch (WLAN_GET_FC_FTYPE(fctl)) {
209 case WLAN_FTYPE_MGMT:
210 hdrlen = WLAN_HDR_A3_LEN;
211 break;
212 case WLAN_FTYPE_DATA:
213 hdrlen = WLAN_HDR_A3_LEN;
214 if (WLAN_GET_FC_TODS(fctl) && WLAN_GET_FC_FROMDS(fctl))
215 hdrlen += ETH_ALEN;
216 break;
217 case WLAN_FTYPE_CTL:
218 hdrlen = WLAN_CTL_FRAMELEN(WLAN_GET_FC_FSTYPE(fctl)) -
219 WLAN_FCS_LEN;
220 break;
221 default:
222 hdrlen = WLAN_HDR_A3_LEN;
225 return hdrlen;
228 #endif /* _P80211HDR_H */