Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / ipxe / src / drivers / net / p80211hdr.h
1 /* src/include/wlan/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 FILE_LICENCE ( GPL2_ONLY );
61
62 #ifndef _P80211HDR_H
63 #define _P80211HDR_H
64
65 /*================================================================*/
66 /* System Includes */
67
68 /*================================================================*/
69 /* Project Includes */
70
71 #ifndef  _WLAN_COMPAT_H
72 #include <wlan/wlan_compat.h>
73 #endif
74
75
76 /*================================================================*/
77 /* Constants */
78
79 /*--- Sizes -----------------------------------------------*/
80 #define WLAN_ADDR_LEN                   6
81 #define WLAN_CRC_LEN                    4
82 #define WLAN_BSSID_LEN                  6
83 #define WLAN_BSS_TS_LEN                 8
84 #define WLAN_HDR_A3_LEN                 24
85 #define WLAN_HDR_A4_LEN                 30
86 #define WLAN_SSID_MAXLEN                32
87 #define WLAN_DATA_MAXLEN                2312
88 #define WLAN_A3FR_MAXLEN                (WLAN_HDR_A3_LEN + WLAN_DATA_MAXLEN + WLAN_CRC_LEN)
89 #define WLAN_A4FR_MAXLEN                (WLAN_HDR_A4_LEN + WLAN_DATA_MAXLEN + WLAN_CRC_LEN)
90 #define WLAN_BEACON_FR_MAXLEN           (WLAN_HDR_A3_LEN + 334)
91 #define WLAN_ATIM_FR_MAXLEN             (WLAN_HDR_A3_LEN + 0)
92 #define WLAN_DISASSOC_FR_MAXLEN         (WLAN_HDR_A3_LEN + 2)
93 #define WLAN_ASSOCREQ_FR_MAXLEN         (WLAN_HDR_A3_LEN + 48)
94 #define WLAN_ASSOCRESP_FR_MAXLEN        (WLAN_HDR_A3_LEN + 16)
95 #define WLAN_REASSOCREQ_FR_MAXLEN       (WLAN_HDR_A3_LEN + 54)
96 #define WLAN_REASSOCRESP_FR_MAXLEN      (WLAN_HDR_A3_LEN + 16)
97 #define WLAN_PROBEREQ_FR_MAXLEN         (WLAN_HDR_A3_LEN + 44)
98 #define WLAN_PROBERESP_FR_MAXLEN        (WLAN_HDR_A3_LEN + 78)
99 #define WLAN_AUTHEN_FR_MAXLEN           (WLAN_HDR_A3_LEN + 261)
100 #define WLAN_DEAUTHEN_FR_MAXLEN         (WLAN_HDR_A3_LEN + 2)
101 #define WLAN_WEP_NKEYS                  4
102 #define WLAN_WEP_MAXKEYLEN              13
103 #define WLAN_CHALLENGE_IE_LEN           130
104 #define WLAN_CHALLENGE_LEN              128
105 #define WLAN_WEP_IV_LEN                 4
106 #define WLAN_WEP_ICV_LEN                4
107
108 /*--- Frame Control Field -------------------------------------*/
109 /* Frame Types */
110 #define WLAN_FTYPE_MGMT                 0x00
111 #define WLAN_FTYPE_CTL                  0x01
112 #define WLAN_FTYPE_DATA                 0x02
113
114 /* Frame subtypes */
115 /* Management */
116 #define WLAN_FSTYPE_ASSOCREQ            0x00
117 #define WLAN_FSTYPE_ASSOCRESP           0x01
118 #define WLAN_FSTYPE_REASSOCREQ          0x02
119 #define WLAN_FSTYPE_REASSOCRESP         0x03
120 #define WLAN_FSTYPE_PROBEREQ            0x04
121 #define WLAN_FSTYPE_PROBERESP           0x05
122 #define WLAN_FSTYPE_BEACON              0x08
123 #define WLAN_FSTYPE_ATIM                0x09
124 #define WLAN_FSTYPE_DISASSOC            0x0a
125 #define WLAN_FSTYPE_AUTHEN              0x0b
126 #define WLAN_FSTYPE_DEAUTHEN            0x0c
127
128 /* Control */
129 #define WLAN_FSTYPE_BLOCKACKREQ         0x8
130 #define WLAN_FSTYPE_BLOCKACK            0x9
131 #define WLAN_FSTYPE_PSPOLL              0x0a
132 #define WLAN_FSTYPE_RTS                 0x0b
133 #define WLAN_FSTYPE_CTS                 0x0c
134 #define WLAN_FSTYPE_ACK                 0x0d
135 #define WLAN_FSTYPE_CFEND               0x0e
136 #define WLAN_FSTYPE_CFENDCFACK          0x0f
137
138 /* Data */
139 #define WLAN_FSTYPE_DATAONLY            0x00
140 #define WLAN_FSTYPE_DATA_CFACK          0x01
141 #define WLAN_FSTYPE_DATA_CFPOLL         0x02
142 #define WLAN_FSTYPE_DATA_CFACK_CFPOLL   0x03
143 #define WLAN_FSTYPE_NULL                0x04
144 #define WLAN_FSTYPE_CFACK               0x05
145 #define WLAN_FSTYPE_CFPOLL              0x06
146 #define WLAN_FSTYPE_CFACK_CFPOLL        0x07
147
148
149 /*================================================================*/
150 /* Macros */
151
152 /*--- FC Macros ----------------------------------------------*/
153 /* Macros to get/set the bitfields of the Frame Control Field */
154 /*  GET_FC_??? - takes the host byte-order value of an FC     */
155 /*               and retrieves the value of one of the        */
156 /*               bitfields and moves that value so its lsb is */
157 /*               in bit 0.                                    */
158 /*  SET_FC_??? - takes a host order value for one of the FC   */
159 /*               bitfields and moves it to the proper bit     */
160 /*               location for ORing into a host order FC.     */
161 /*               To send the FC produced from SET_FC_???,     */
162 /*               one must put the bytes in IEEE order.        */
163 /*  e.g.                                                      */
164 /*     printf("the frame subtype is %x",                      */
165 /*                 GET_FC_FTYPE( ieee2host( rx.fc )))         */
166 /*                                                            */
167 /*     tx.fc = host2ieee( SET_FC_FTYPE(WLAN_FTYP_CTL) |       */
168 /*                        SET_FC_FSTYPE(WLAN_FSTYPE_RTS) );   */
169 /*------------------------------------------------------------*/
170
171 #define WLAN_GET_FC_PVER(n)      (((uint16_t)(n)) & (BIT0 | BIT1))
172 #define WLAN_GET_FC_FTYPE(n)    ((((uint16_t)(n)) & (BIT2 | BIT3)) >> 2)
173 #define WLAN_GET_FC_FSTYPE(n)   ((((uint16_t)(n)) & (BIT4|BIT5|BIT6|BIT7)) >> 4)
174 #define WLAN_GET_FC_TODS(n)     ((((uint16_t)(n)) & (BIT8)) >> 8)
175 #define WLAN_GET_FC_FROMDS(n)   ((((uint16_t)(n)) & (BIT9)) >> 9)
176 #define WLAN_GET_FC_MOREFRAG(n) ((((uint16_t)(n)) & (BIT10)) >> 10)
177 #define WLAN_GET_FC_RETRY(n)    ((((uint16_t)(n)) & (BIT11)) >> 11)
178 #define WLAN_GET_FC_PWRMGT(n)   ((((uint16_t)(n)) & (BIT12)) >> 12)
179 #define WLAN_GET_FC_MOREDATA(n) ((((uint16_t)(n)) & (BIT13)) >> 13)
180 #define WLAN_GET_FC_ISWEP(n)    ((((uint16_t)(n)) & (BIT14)) >> 14)
181 #define WLAN_GET_FC_ORDER(n)    ((((uint16_t)(n)) & (BIT15)) >> 15)
182
183 #define WLAN_SET_FC_PVER(n)     ((uint16_t)(n))
184 #define WLAN_SET_FC_FTYPE(n)    (((uint16_t)(n)) << 2)
185 #define WLAN_SET_FC_FSTYPE(n)   (((uint16_t)(n)) << 4)
186 #define WLAN_SET_FC_TODS(n)     (((uint16_t)(n)) << 8)
187 #define WLAN_SET_FC_FROMDS(n)   (((uint16_t)(n)) << 9)
188 #define WLAN_SET_FC_MOREFRAG(n) (((uint16_t)(n)) << 10)
189 #define WLAN_SET_FC_RETRY(n)    (((uint16_t)(n)) << 11)
190 #define WLAN_SET_FC_PWRMGT(n)   (((uint16_t)(n)) << 12)
191 #define WLAN_SET_FC_MOREDATA(n) (((uint16_t)(n)) << 13)
192 #define WLAN_SET_FC_ISWEP(n)    (((uint16_t)(n)) << 14)
193 #define WLAN_SET_FC_ORDER(n)    (((uint16_t)(n)) << 15)
194
195 /*--- Duration Macros ----------------------------------------*/
196 /* Macros to get/set the bitfields of the Duration Field      */
197 /*  - the duration value is only valid when bit15 is zero     */
198 /*  - the firmware handles these values, so I'm not going     */
199 /*    these macros right now.                                 */
200 /*------------------------------------------------------------*/
201
202 /*--- Sequence Control  Macros -------------------------------*/
203 /* Macros to get/set the bitfields of the Sequence Control    */
204 /* Field.                                                     */
205 /*------------------------------------------------------------*/
206 #define WLAN_GET_SEQ_FRGNUM(n) (((uint16_t)(n)) & (BIT0|BIT1|BIT2|BIT3))
207 #define WLAN_GET_SEQ_SEQNUM(n) ((((uint16_t)(n)) & (~(BIT0|BIT1|BIT2|BIT3))) >> 4)
208
209 /*--- Data ptr macro -----------------------------------------*/
210 /* Creates a uint8_t* to the data portion of a frame            */
211 /* Assumes you're passing in a ptr to the beginning of the hdr*/
212 /*------------------------------------------------------------*/
213 #define WLAN_HDR_A3_DATAP(p) (((uint8_t*)(p)) + WLAN_HDR_A3_LEN)
214 #define WLAN_HDR_A4_DATAP(p) (((uint8_t*)(p)) + WLAN_HDR_A4_LEN)
215
216 #define DOT11_RATE5_ISBASIC_GET(r)     (((uint8_t)(r)) & BIT7)
217
218 /*================================================================*/
219 /* Types */
220
221 /* BSS Timestamp */
222 typedef uint8_t wlan_bss_ts_t[WLAN_BSS_TS_LEN];
223
224 /* Generic 802.11 Header types */
225
226 typedef struct p80211_hdr_a3
227 {
228         uint16_t        fc;
229         uint16_t        dur;
230         uint8_t a1[WLAN_ADDR_LEN];
231         uint8_t a2[WLAN_ADDR_LEN];
232         uint8_t a3[WLAN_ADDR_LEN];
233         uint16_t        seq;
234 } __WLAN_ATTRIB_PACK__ p80211_hdr_a3_t;
235
236 typedef struct p80211_hdr_a4
237 {
238         uint16_t        fc;
239         uint16_t        dur;
240         uint8_t a1[WLAN_ADDR_LEN];
241         uint8_t a2[WLAN_ADDR_LEN];
242         uint8_t a3[WLAN_ADDR_LEN];
243         uint16_t        seq;
244         uint8_t a4[WLAN_ADDR_LEN];
245 } __WLAN_ATTRIB_PACK__ p80211_hdr_a4_t;
246
247 typedef union p80211_hdr
248 {
249         p80211_hdr_a3_t         a3;
250         p80211_hdr_a4_t         a4;
251 } __WLAN_ATTRIB_PACK__ p80211_hdr_t;
252
253
254 /*================================================================*/
255 /* Extern Declarations */
256
257
258 /*================================================================*/
259 /* Function Declarations */
260
261 /* Frame and header length macros */
262
263 #define WLAN_CTL_FRAMELEN(fstype) (\
264         (fstype) == WLAN_FSTYPE_BLOCKACKREQ     ? 24 : \
265         (fstype) == WLAN_FSTYPE_BLOCKACK        ? 152 : \
266         (fstype) == WLAN_FSTYPE_PSPOLL          ? 20 : \
267         (fstype) == WLAN_FSTYPE_RTS             ? 20 : \
268         (fstype) == WLAN_FSTYPE_CTS             ? 14 : \
269         (fstype) == WLAN_FSTYPE_ACK             ? 14 : \
270         (fstype) == WLAN_FSTYPE_CFEND           ? 20 : \
271         (fstype) == WLAN_FSTYPE_CFENDCFACK      ? 20 : 4)
272
273 #define WLAN_FCS_LEN                    4
274
275 /* ftcl in HOST order */
276 inline static uint16_t p80211_headerlen(uint16_t fctl)
277 {
278         uint16_t hdrlen = 0;
279
280         switch ( WLAN_GET_FC_FTYPE(fctl) ) {
281         case WLAN_FTYPE_MGMT:
282                 hdrlen = WLAN_HDR_A3_LEN;
283                 break;
284         case WLAN_FTYPE_DATA:
285                 hdrlen = WLAN_HDR_A3_LEN;
286                 if ( WLAN_GET_FC_TODS(fctl) && WLAN_GET_FC_FROMDS(fctl) ) {
287                         hdrlen += WLAN_ADDR_LEN;
288                 }
289                 break;
290         case WLAN_FTYPE_CTL:
291                 hdrlen = WLAN_CTL_FRAMELEN(WLAN_GET_FC_FSTYPE(fctl)) -
292                         WLAN_FCS_LEN;
293                 break;
294         default:
295                 hdrlen = WLAN_HDR_A3_LEN;
296         }
297
298         return hdrlen;
299 }
300
301 #endif /* _P80211HDR_H */