Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
p80211hdr.h
Go to the documentation of this file.
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.
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 #include <linux/if_ether.h>
64 
65 /*--- Sizes -----------------------------------------------*/
66 #define WLAN_CRC_LEN 4
67 #define WLAN_BSSID_LEN 6
68 #define WLAN_HDR_A3_LEN 24
69 #define WLAN_HDR_A4_LEN 30
70 #define WLAN_SSID_MAXLEN 32
71 #define WLAN_DATA_MAXLEN 2312
72 #define WLAN_WEP_IV_LEN 4
73 #define WLAN_WEP_ICV_LEN 4
74 
75 /*--- Frame Control Field -------------------------------------*/
76 /* Frame Types */
77 #define WLAN_FTYPE_MGMT 0x00
78 #define WLAN_FTYPE_CTL 0x01
79 #define WLAN_FTYPE_DATA 0x02
80 
81 /* Frame subtypes */
82 /* Management */
83 #define WLAN_FSTYPE_ASSOCREQ 0x00
84 #define WLAN_FSTYPE_ASSOCRESP 0x01
85 #define WLAN_FSTYPE_REASSOCREQ 0x02
86 #define WLAN_FSTYPE_REASSOCRESP 0x03
87 #define WLAN_FSTYPE_PROBEREQ 0x04
88 #define WLAN_FSTYPE_PROBERESP 0x05
89 #define WLAN_FSTYPE_BEACON 0x08
90 #define WLAN_FSTYPE_ATIM 0x09
91 #define WLAN_FSTYPE_DISASSOC 0x0a
92 #define WLAN_FSTYPE_AUTHEN 0x0b
93 #define WLAN_FSTYPE_DEAUTHEN 0x0c
94 
95 /* Control */
96 #define WLAN_FSTYPE_BLOCKACKREQ 0x8
97 #define WLAN_FSTYPE_BLOCKACK 0x9
98 #define WLAN_FSTYPE_PSPOLL 0x0a
99 #define WLAN_FSTYPE_RTS 0x0b
100 #define WLAN_FSTYPE_CTS 0x0c
101 #define WLAN_FSTYPE_ACK 0x0d
102 #define WLAN_FSTYPE_CFEND 0x0e
103 #define WLAN_FSTYPE_CFENDCFACK 0x0f
104 
105 /* Data */
106 #define WLAN_FSTYPE_DATAONLY 0x00
107 #define WLAN_FSTYPE_DATA_CFACK 0x01
108 #define WLAN_FSTYPE_DATA_CFPOLL 0x02
109 #define WLAN_FSTYPE_DATA_CFACK_CFPOLL 0x03
110 #define WLAN_FSTYPE_NULL 0x04
111 #define WLAN_FSTYPE_CFACK 0x05
112 #define WLAN_FSTYPE_CFPOLL 0x06
113 #define WLAN_FSTYPE_CFACK_CFPOLL 0x07
114 
115 /*--- FC Macros ----------------------------------------------*/
116 /* Macros to get/set the bitfields of the Frame Control Field */
117 /* GET_FC_??? - takes the host byte-order value of an FC */
118 /* and retrieves the value of one of the */
119 /* bitfields and moves that value so its lsb is */
120 /* in bit 0. */
121 /* SET_FC_??? - takes a host order value for one of the FC */
122 /* bitfields and moves it to the proper bit */
123 /* location for ORing into a host order FC. */
124 /* To send the FC produced from SET_FC_???, */
125 /* one must put the bytes in IEEE order. */
126 /* e.g. */
127 /* printf("the frame subtype is %x", */
128 /* GET_FC_FTYPE( ieee2host( rx.fc ))) */
129 /* */
130 /* tx.fc = host2ieee( SET_FC_FTYPE(WLAN_FTYP_CTL) | */
131 /* SET_FC_FSTYPE(WLAN_FSTYPE_RTS) ); */
132 /*------------------------------------------------------------*/
133 
134 #define WLAN_GET_FC_FTYPE(n) ((((u16)(n)) & (BIT(2) | BIT(3))) >> 2)
135 #define WLAN_GET_FC_FSTYPE(n) ((((u16)(n)) & (BIT(4)|BIT(5)|BIT(6)|BIT(7))) >> 4)
136 #define WLAN_GET_FC_TODS(n) ((((u16)(n)) & (BIT(8))) >> 8)
137 #define WLAN_GET_FC_FROMDS(n) ((((u16)(n)) & (BIT(9))) >> 9)
138 #define WLAN_GET_FC_ISWEP(n) ((((u16)(n)) & (BIT(14))) >> 14)
139 
140 #define WLAN_SET_FC_FTYPE(n) (((u16)(n)) << 2)
141 #define WLAN_SET_FC_FSTYPE(n) (((u16)(n)) << 4)
142 #define WLAN_SET_FC_TODS(n) (((u16)(n)) << 8)
143 #define WLAN_SET_FC_FROMDS(n) (((u16)(n)) << 9)
144 #define WLAN_SET_FC_ISWEP(n) (((u16)(n)) << 14)
145 
146 #define DOT11_RATE5_ISBASIC_GET(r) (((u8)(r)) & BIT(7))
147 
148 /* Generic 802.11 Header types */
149 
157 } __packed;
158 
167 } __packed;
168 
169 union p80211_hdr {
172 } __packed;
173 
174 /* Frame and header length macros */
175 
176 #define WLAN_CTL_FRAMELEN(fstype) (\
177  (fstype) == WLAN_FSTYPE_BLOCKACKREQ ? 24 : \
178  (fstype) == WLAN_FSTYPE_BLOCKACK ? 152 : \
179  (fstype) == WLAN_FSTYPE_PSPOLL ? 20 : \
180  (fstype) == WLAN_FSTYPE_RTS ? 20 : \
181  (fstype) == WLAN_FSTYPE_CTS ? 14 : \
182  (fstype) == WLAN_FSTYPE_ACK ? 14 : \
183  (fstype) == WLAN_FSTYPE_CFEND ? 20 : \
184  (fstype) == WLAN_FSTYPE_CFENDCFACK ? 20 : 4)
185 
186 #define WLAN_FCS_LEN 4
187 
188 /* ftcl in HOST order */
189 static inline u16 p80211_headerlen(u16 fctl)
190 {
191  u16 hdrlen = 0;
192 
193  switch (WLAN_GET_FC_FTYPE(fctl)) {
194  case WLAN_FTYPE_MGMT:
195  hdrlen = WLAN_HDR_A3_LEN;
196  break;
197  case WLAN_FTYPE_DATA:
198  hdrlen = WLAN_HDR_A3_LEN;
199  if (WLAN_GET_FC_TODS(fctl) && WLAN_GET_FC_FROMDS(fctl))
200  hdrlen += ETH_ALEN;
201  break;
202  case WLAN_FTYPE_CTL:
203  hdrlen = WLAN_CTL_FRAMELEN(WLAN_GET_FC_FSTYPE(fctl)) -
204  WLAN_FCS_LEN;
205  break;
206  default:
207  hdrlen = WLAN_HDR_A3_LEN;
208  }
209 
210  return hdrlen;
211 }
212 
213 #endif /* _P80211HDR_H */