nfsd4: setclientid_confirm callback-change fixes
[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
72
73 /*================================================================*/
74 /* Constants */
75
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
85
86 /*--- Frame Control Field -------------------------------------*/
87 /* Frame Types */
88 #define WLAN_FTYPE_MGMT                 0x00
89 #define WLAN_FTYPE_CTL                  0x01
90 #define WLAN_FTYPE_DATA                 0x02
91
92 /* Frame subtypes */
93 /* Management */
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
105
106 /* Control */
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
115
116 /* Data */
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
125
126 /*================================================================*/
127 /* Macros */
128
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 */
134 /*               in bit 0.                                    */
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.        */
140 /*  e.g.                                                      */
141 /*     printf("the frame subtype is %x",                      */
142 /*                 GET_FC_FTYPE( ieee2host( rx.fc )))         */
143 /*                                                            */
144 /*     tx.fc = host2ieee( SET_FC_FTYPE(WLAN_FTYP_CTL) |       */
145 /*                        SET_FC_FSTYPE(WLAN_FSTYPE_RTS) );   */
146 /*------------------------------------------------------------*/
147
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)
153
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)
159
160 #define DOT11_RATE5_ISBASIC_GET(r)     (((u8)(r)) & BIT(7))
161
162 /*================================================================*/
163 /* Types */
164
165 /* Generic 802.11 Header types */
166
167 typedef struct p80211_hdr_a3 {
168         u16 fc;
169         u16 dur;
170         u8 a1[ETH_ALEN];
171         u8 a2[ETH_ALEN];
172         u8 a3[ETH_ALEN];
173         u16 seq;
174 } __attribute__ ((packed)) p80211_hdr_a3_t;
175
176 typedef struct p80211_hdr_a4 {
177         u16 fc;
178         u16 dur;
179         u8 a1[ETH_ALEN];
180         u8 a2[ETH_ALEN];
181         u8 a3[ETH_ALEN];
182         u16 seq;
183         u8 a4[ETH_ALEN];
184 } __attribute__ ((packed)) p80211_hdr_a4_t;
185
186 typedef union p80211_hdr {
187         p80211_hdr_a3_t a3;
188         p80211_hdr_a4_t a4;
189 } __attribute__ ((packed)) p80211_hdr_t;
190
191
192 /* Frame and header length macros */
193
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)
203
204 #define WLAN_FCS_LEN                    4
205
206 /* ftcl in HOST order */
207 static inline u16 p80211_headerlen(u16 fctl)
208 {
209         u16 hdrlen = 0;
210
211         switch (WLAN_GET_FC_FTYPE(fctl)) {
212         case WLAN_FTYPE_MGMT:
213                 hdrlen = WLAN_HDR_A3_LEN;
214                 break;
215         case WLAN_FTYPE_DATA:
216                 hdrlen = WLAN_HDR_A3_LEN;
217                 if (WLAN_GET_FC_TODS(fctl) && WLAN_GET_FC_FROMDS(fctl))
218                         hdrlen += ETH_ALEN;
219                 break;
220         case WLAN_FTYPE_CTL:
221                 hdrlen = WLAN_CTL_FRAMELEN(WLAN_GET_FC_FSTYPE(fctl)) -
222                     WLAN_FCS_LEN;
223                 break;
224         default:
225                 hdrlen = WLAN_HDR_A3_LEN;
226         }
227
228         return hdrlen;
229 }
230
231 #endif /* _P80211HDR_H */