00001 /* src/include/wlan/p80211hdr.h 00002 * 00003 * Macros, types, and functions for handling 802.11 MAC headers 00004 * 00005 * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved. 00006 * -------------------------------------------------------------------- 00007 * 00008 * linux-wlan 00009 * 00010 * The contents of this file are subject to the Mozilla Public 00011 * License Version 1.1 (the "License"); you may not use this file 00012 * except in compliance with the License. You may obtain a copy of 00013 * the License at http://www.mozilla.org/MPL/ 00014 * 00015 * Software distributed under the License is distributed on an "AS 00016 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 00017 * implied. See the License for the specific language governing 00018 * rights and limitations under the License. 00019 * 00020 * Alternatively, the contents of this file may be used under the 00021 * terms of the GNU Public License version 2 (the "GPL"), in which 00022 * case the provisions of the GPL are applicable instead of the 00023 * above. If you wish to allow the use of your version of this file 00024 * only under the terms of the GPL and not to allow others to use 00025 * your version of this file under the MPL, indicate your decision 00026 * by deleting the provisions above and replace them with the notice 00027 * and other provisions required by the GPL. If you do not delete 00028 * the provisions above, a recipient may use your version of this 00029 * file under either the MPL or the GPL. 00030 * 00031 * -------------------------------------------------------------------- 00032 * 00033 * Inquiries regarding the linux-wlan Open Source project can be 00034 * made directly to: 00035 * 00036 * AbsoluteValue Systems Inc. 00037 * info@linux-wlan.com 00038 * http://www.linux-wlan.com 00039 * 00040 * -------------------------------------------------------------------- 00041 * 00042 * Portions of the development of this software were funded by 00043 * Intersil Corporation as part of PRISM(R) chipset product development. 00044 * 00045 * -------------------------------------------------------------------- 00046 * 00047 * This file declares the constants and types used in the interface 00048 * between a wlan driver and the user mode utilities. 00049 * 00050 * Note: 00051 * - Constant values are always in HOST byte order. To assign 00052 * values to multi-byte fields they _must_ be converted to 00053 * ieee byte order. To retrieve multi-byte values from incoming 00054 * frames, they must be converted to host order. 00055 * 00056 * All functions declared here are implemented in p80211.c 00057 * -------------------------------------------------------------------- 00058 */ 00059 00060 #ifndef _P80211HDR_H 00061 #define _P80211HDR_H 00062 00063 /*================================================================*/ 00064 /* System Includes */ 00065 00066 /*================================================================*/ 00067 /* Project Includes */ 00068 00069 #ifndef _WLAN_COMPAT_H 00070 #include <wlan/wlan_compat.h> 00071 #endif 00072 00073 00074 /*================================================================*/ 00075 /* Constants */ 00076 00077 /*--- Sizes -----------------------------------------------*/ 00078 #define WLAN_ADDR_LEN 6 00079 #define WLAN_CRC_LEN 4 00080 #define WLAN_BSSID_LEN 6 00081 #define WLAN_BSS_TS_LEN 8 00082 #define WLAN_HDR_A3_LEN 24 00083 #define WLAN_HDR_A4_LEN 30 00084 #define WLAN_SSID_MAXLEN 32 00085 #define WLAN_DATA_MAXLEN 2312 00086 #define WLAN_A3FR_MAXLEN (WLAN_HDR_A3_LEN + WLAN_DATA_MAXLEN + WLAN_CRC_LEN) 00087 #define WLAN_A4FR_MAXLEN (WLAN_HDR_A4_LEN + WLAN_DATA_MAXLEN + WLAN_CRC_LEN) 00088 #define WLAN_BEACON_FR_MAXLEN (WLAN_HDR_A3_LEN + 334) 00089 #define WLAN_ATIM_FR_MAXLEN (WLAN_HDR_A3_LEN + 0) 00090 #define WLAN_DISASSOC_FR_MAXLEN (WLAN_HDR_A3_LEN + 2) 00091 #define WLAN_ASSOCREQ_FR_MAXLEN (WLAN_HDR_A3_LEN + 48) 00092 #define WLAN_ASSOCRESP_FR_MAXLEN (WLAN_HDR_A3_LEN + 16) 00093 #define WLAN_REASSOCREQ_FR_MAXLEN (WLAN_HDR_A3_LEN + 54) 00094 #define WLAN_REASSOCRESP_FR_MAXLEN (WLAN_HDR_A3_LEN + 16) 00095 #define WLAN_PROBEREQ_FR_MAXLEN (WLAN_HDR_A3_LEN + 44) 00096 #define WLAN_PROBERESP_FR_MAXLEN (WLAN_HDR_A3_LEN + 78) 00097 #define WLAN_AUTHEN_FR_MAXLEN (WLAN_HDR_A3_LEN + 261) 00098 #define WLAN_DEAUTHEN_FR_MAXLEN (WLAN_HDR_A3_LEN + 2) 00099 #define WLAN_WEP_NKEYS 4 00100 #define WLAN_WEP_MAXKEYLEN 13 00101 #define WLAN_CHALLENGE_IE_LEN 130 00102 #define WLAN_CHALLENGE_LEN 128 00103 #define WLAN_WEP_IV_LEN 4 00104 #define WLAN_WEP_ICV_LEN 4 00105 00106 /*--- Frame Control Field -------------------------------------*/ 00107 /* Frame Types */ 00108 #define WLAN_FTYPE_MGMT 0x00 00109 #define WLAN_FTYPE_CTL 0x01 00110 #define WLAN_FTYPE_DATA 0x02 00111 00112 /* Frame subtypes */ 00113 /* Management */ 00114 #define WLAN_FSTYPE_ASSOCREQ 0x00 00115 #define WLAN_FSTYPE_ASSOCRESP 0x01 00116 #define WLAN_FSTYPE_REASSOCREQ 0x02 00117 #define WLAN_FSTYPE_REASSOCRESP 0x03 00118 #define WLAN_FSTYPE_PROBEREQ 0x04 00119 #define WLAN_FSTYPE_PROBERESP 0x05 00120 #define WLAN_FSTYPE_BEACON 0x08 00121 #define WLAN_FSTYPE_ATIM 0x09 00122 #define WLAN_FSTYPE_DISASSOC 0x0a 00123 #define WLAN_FSTYPE_AUTHEN 0x0b 00124 #define WLAN_FSTYPE_DEAUTHEN 0x0c 00125 00126 /* Control */ 00127 #define WLAN_FSTYPE_PSPOLL 0x0a 00128 #define WLAN_FSTYPE_RTS 0x0b 00129 #define WLAN_FSTYPE_CTS 0x0c 00130 #define WLAN_FSTYPE_ACK 0x0d 00131 #define WLAN_FSTYPE_CFEND 0x0e 00132 #define WLAN_FSTYPE_CFENDCFACK 0x0f 00133 00134 /* Data */ 00135 #define WLAN_FSTYPE_DATAONLY 0x00 00136 #define WLAN_FSTYPE_DATA_CFACK 0x01 00137 #define WLAN_FSTYPE_DATA_CFPOLL 0x02 00138 #define WLAN_FSTYPE_DATA_CFACK_CFPOLL 0x03 00139 #define WLAN_FSTYPE_NULL 0x04 00140 #define WLAN_FSTYPE_CFACK 0x05 00141 #define WLAN_FSTYPE_CFPOLL 0x06 00142 #define WLAN_FSTYPE_CFACK_CFPOLL 0x07 00143 00144 00145 /*================================================================*/ 00146 /* Macros */ 00147 00148 /*--- FC Macros ----------------------------------------------*/ 00149 /* Macros to get/set the bitfields of the Frame Control Field */ 00150 /* GET_FC_??? - takes the host byte-order value of an FC */ 00151 /* and retrieves the value of one of the */ 00152 /* bitfields and moves that value so its lsb is */ 00153 /* in bit 0. */ 00154 /* SET_FC_??? - takes a host order value for one of the FC */ 00155 /* bitfields and moves it to the proper bit */ 00156 /* location for ORing into a host order FC. */ 00157 /* To send the FC produced from SET_FC_???, */ 00158 /* one must put the bytes in IEEE order. */ 00159 /* e.g. */ 00160 /* printf("the frame subtype is %x", */ 00161 /* GET_FC_FTYPE( ieee2host( rx.fc ))) */ 00162 /* */ 00163 /* tx.fc = host2ieee( SET_FC_FTYPE(WLAN_FTYP_CTL) | */ 00164 /* SET_FC_FSTYPE(WLAN_FSTYPE_RTS) ); */ 00165 /*------------------------------------------------------------*/ 00166 00167 #define WLAN_GET_FC_PVER(n) (((UINT16)(n)) & (BIT0 | BIT1)) 00168 #define WLAN_GET_FC_FTYPE(n) ((((UINT16)(n)) & (BIT2 | BIT3)) >> 2) 00169 #define WLAN_GET_FC_FSTYPE(n) ((((UINT16)(n)) & (BIT4|BIT5|BIT6|BIT7)) >> 4) 00170 #define WLAN_GET_FC_TODS(n) ((((UINT16)(n)) & (BIT8)) >> 8) 00171 #define WLAN_GET_FC_FROMDS(n) ((((UINT16)(n)) & (BIT9)) >> 9) 00172 #define WLAN_GET_FC_MOREFRAG(n) ((((UINT16)(n)) & (BIT10)) >> 10) 00173 #define WLAN_GET_FC_RETRY(n) ((((UINT16)(n)) & (BIT11)) >> 11) 00174 #define WLAN_GET_FC_PWRMGT(n) ((((UINT16)(n)) & (BIT12)) >> 12) 00175 #define WLAN_GET_FC_MOREDATA(n) ((((UINT16)(n)) & (BIT13)) >> 13) 00176 #define WLAN_GET_FC_ISWEP(n) ((((UINT16)(n)) & (BIT14)) >> 14) 00177 #define WLAN_GET_FC_ORDER(n) ((((UINT16)(n)) & (BIT15)) >> 15) 00178 00179 #define WLAN_SET_FC_PVER(n) ((UINT16)(n)) 00180 #define WLAN_SET_FC_FTYPE(n) (((UINT16)(n)) << 2) 00181 #define WLAN_SET_FC_FSTYPE(n) (((UINT16)(n)) << 4) 00182 #define WLAN_SET_FC_TODS(n) (((UINT16)(n)) << 8) 00183 #define WLAN_SET_FC_FROMDS(n) (((UINT16)(n)) << 9) 00184 #define WLAN_SET_FC_MOREFRAG(n) (((UINT16)(n)) << 10) 00185 #define WLAN_SET_FC_RETRY(n) (((UINT16)(n)) << 11) 00186 #define WLAN_SET_FC_PWRMGT(n) (((UINT16)(n)) << 12) 00187 #define WLAN_SET_FC_MOREDATA(n) (((UINT16)(n)) << 13) 00188 #define WLAN_SET_FC_ISWEP(n) (((UINT16)(n)) << 14) 00189 #define WLAN_SET_FC_ORDER(n) (((UINT16)(n)) << 15) 00190 00191 /*--- Duration Macros ----------------------------------------*/ 00192 /* Macros to get/set the bitfields of the Duration Field */ 00193 /* - the duration value is only valid when bit15 is zero */ 00194 /* - the firmware handles these values, so I'm not going */ 00195 /* these macros right now. */ 00196 /*------------------------------------------------------------*/ 00197 00198 /*--- Sequence Control Macros -------------------------------*/ 00199 /* Macros to get/set the bitfields of the Sequence Control */ 00200 /* Field. */ 00201 /*------------------------------------------------------------*/ 00202 #define WLAN_GET_SEQ_FRGNUM(n) (((UINT16)(n)) & (BIT0|BIT1|BIT2|BIT3)) 00203 #define WLAN_GET_SEQ_SEQNUM(n) ((((UINT16)(n)) & (~(BIT0|BIT1|BIT2|BIT3))) >> 4) 00204 00205 /*--- Data ptr macro -----------------------------------------*/ 00206 /* Creates a UINT8* to the data portion of a frame */ 00207 /* Assumes you're passing in a ptr to the beginning of the hdr*/ 00208 /*------------------------------------------------------------*/ 00209 #define WLAN_HDR_A3_DATAP(p) (((UINT8*)(p)) + WLAN_HDR_A3_LEN) 00210 #define WLAN_HDR_A4_DATAP(p) (((UINT8*)(p)) + WLAN_HDR_A4_LEN) 00211 00212 #define DOT11_RATE5_ISBASIC_GET(r) (((UINT8)(r)) & BIT7) 00213 00214 /*================================================================*/ 00215 /* Types */ 00216 00217 /* BSS Timestamp */ 00218 typedef UINT8 wlan_bss_ts_t[WLAN_BSS_TS_LEN]; 00219 00220 /* Generic 802.11 Header types */ 00221 00222 typedef struct p80211_hdr_a3 00223 { 00224 UINT16 fc __WLAN_ATTRIB_PACK__; 00225 UINT16 dur __WLAN_ATTRIB_PACK__; 00226 UINT8 a1[WLAN_ADDR_LEN] __WLAN_ATTRIB_PACK__; 00227 UINT8 a2[WLAN_ADDR_LEN] __WLAN_ATTRIB_PACK__; 00228 UINT8 a3[WLAN_ADDR_LEN] __WLAN_ATTRIB_PACK__; 00229 UINT16 seq __WLAN_ATTRIB_PACK__; 00230 } __WLAN_ATTRIB_PACK__ p80211_hdr_a3_t; 00231 00232 typedef struct p80211_hdr_a4 00233 { 00234 UINT16 fc __WLAN_ATTRIB_PACK__; 00235 UINT16 dur __WLAN_ATTRIB_PACK__; 00236 UINT8 a1[WLAN_ADDR_LEN] __WLAN_ATTRIB_PACK__; 00237 UINT8 a2[WLAN_ADDR_LEN] __WLAN_ATTRIB_PACK__; 00238 UINT8 a3[WLAN_ADDR_LEN] __WLAN_ATTRIB_PACK__; 00239 UINT16 seq __WLAN_ATTRIB_PACK__; 00240 UINT8 a4[WLAN_ADDR_LEN] __WLAN_ATTRIB_PACK__; 00241 } __WLAN_ATTRIB_PACK__ p80211_hdr_a4_t; 00242 00243 typedef union p80211_hdr 00244 { 00245 p80211_hdr_a3_t a3 __WLAN_ATTRIB_PACK__; 00246 p80211_hdr_a4_t a4 __WLAN_ATTRIB_PACK__; 00247 } __WLAN_ATTRIB_PACK__ p80211_hdr_t; 00248 00249 00250 /*================================================================*/ 00251 /* Extern Declarations */ 00252 00253 00254 /*================================================================*/ 00255 /* Function Declarations */ 00256 00257 void p802addr_to_str( char *buf, UINT8 *addr); 00258 00259 /* Frame and header lenght macros */ 00260 00261 #define WLAN_CTL_FRAMELEN(fstype) (\ 00262 (fstype) == WLAN_FSTYPE_PSPOLL ? 20 : \ 00263 (fstype) == WLAN_FSTYPE_RTS ? 20 : \ 00264 (fstype) == WLAN_FSTYPE_CTS ? 14 : \ 00265 (fstype) == WLAN_FSTYPE_ACK ? 14 : \ 00266 (fstype) == WLAN_FSTYPE_CFEND ? 20 : \ 00267 (fstype) == WLAN_FSTYPE_CFENDCFACK ? 20 : 0) 00268 00269 #define WLAN_FCS_LEN 4 00270 00271 /* ftcl in HOST order */ 00272 inline static UINT16 p80211_headerlen(UINT16 fctl) 00273 { 00274 UINT16 hdrlen = 0; 00275 00276 switch ( WLAN_GET_FC_FTYPE(fctl) ) { 00277 case WLAN_FTYPE_MGMT: 00278 hdrlen = WLAN_HDR_A3_LEN; 00279 break; 00280 case WLAN_FTYPE_DATA: 00281 hdrlen = WLAN_HDR_A3_LEN; 00282 if ( WLAN_GET_FC_TODS(fctl) && WLAN_GET_FC_FROMDS(fctl) ) { 00283 hdrlen += WLAN_ADDR_LEN; 00284 } 00285 break; 00286 case WLAN_FTYPE_CTL: 00287 hdrlen = WLAN_CTL_FRAMELEN(WLAN_GET_FC_FSTYPE(fctl)) - 00288 WLAN_FCS_LEN; 00289 break; 00290 default: 00291 hdrlen = WLAN_HDR_A3_LEN; 00292 } 00293 00294 return hdrlen; 00295 } 00296 00297 #endif /* _P80211HDR_H */