p80211hdr.h

Go to the documentation of this file.
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_BLOCKACKREQ   0x8
00128 #define WLAN_FSTYPE_BLOCKACK      0x9
00129 #define WLAN_FSTYPE_PSPOLL    0x0a
00130 #define WLAN_FSTYPE_RTS     0x0b
00131 #define WLAN_FSTYPE_CTS     0x0c
00132 #define WLAN_FSTYPE_ACK     0x0d
00133 #define WLAN_FSTYPE_CFEND   0x0e
00134 #define WLAN_FSTYPE_CFENDCFACK    0x0f
00135 
00136 /* Data */
00137 #define WLAN_FSTYPE_DATAONLY    0x00
00138 #define WLAN_FSTYPE_DATA_CFACK    0x01
00139 #define WLAN_FSTYPE_DATA_CFPOLL   0x02
00140 #define WLAN_FSTYPE_DATA_CFACK_CFPOLL 0x03
00141 #define WLAN_FSTYPE_NULL    0x04
00142 #define WLAN_FSTYPE_CFACK   0x05
00143 #define WLAN_FSTYPE_CFPOLL    0x06
00144 #define WLAN_FSTYPE_CFACK_CFPOLL  0x07
00145 
00146 /* Data with QOS */
00147 #define WLAN_FSTYPE_QOS_MASK    0x08
00148 #define WLAN_FSTYPE_QOS_UNMASK    0x07
00149 #define WLAN_FSTYPE_QOS_DATAONLY    (WLAN_FSTYPE_DATAONLY + WLAN_FSTYPE_QOS_MASK)
00150 #define WLAN_FSTYPE_QOS_DATA_CFACK    (WLAN_FSTYPE_DATA_CFACK + WLAN_FSTYPE_QOS_MASK)
00151 #define WLAN_FSTYPE_QOS_DATA_CFPOLL   (WLAN_FSTYPE_DATA_CFPOLL + WLAN_FSTYPE_QOS_MASK)
00152 #define WLAN_FSTYPE_QOS_DATA_CFACK_CFPOLL (WLAN_FSTYPE_DATA_CFACK_CFPOLL + WLAN_FSTYPE_QOS_MASK)
00153 #define WLAN_FSTYPE_QOS_NULL      (WLAN_FSTYPE_NULL + WLAN_FSTYPE_QOS_MASK)
00154 #define WLAN_FSTYPE_QOS_CFACK     (WLAN_FSTYPE_CFACK + WLAN_FSTYPE_QOS_MASK)
00155 #define WLAN_FSTYPE_QOS_CFPOLL      (WLAN_FSTYPE_CFPOLL + WLAN_FSTYPE_QOS_MASK)
00156 #define WLAN_FSTYPE_QOS_CFACK_CFPOLL    (WLAN_FSTYPE_CFACK_CFPOLL + WLAN_FSTYPE_QOS_MASK)
00157 
00158 
00159 /*================================================================*/
00160 /* Macros */
00161 
00162 /*--- FC Macros ----------------------------------------------*/
00163 /* Macros to get/set the bitfields of the Frame Control Field */
00164 /*  GET_FC_??? - takes the host byte-order value of an FC     */
00165 /*               and retrieves the value of one of the        */
00166 /*               bitfields and moves that value so its lsb is */
00167 /*               in bit 0.                                    */
00168 /*  SET_FC_??? - takes a host order value for one of the FC   */
00169 /*               bitfields and moves it to the proper bit     */
00170 /*               location for ORing into a host order FC.     */
00171 /*               To send the FC produced from SET_FC_???,     */
00172 /*               one must put the bytes in IEEE order.        */
00173 /*  e.g.                                                      */
00174 /*     printf("the frame subtype is %x",                      */
00175 /*                 GET_FC_FTYPE( ieee2host( rx.fc )))         */
00176 /*                                                            */
00177 /*     tx.fc = host2ieee( SET_FC_FTYPE(WLAN_FTYP_CTL) |       */
00178 /*                        SET_FC_FSTYPE(WLAN_FSTYPE_RTS) );   */
00179 /*------------------------------------------------------------*/
00180 
00181 #define WLAN_GET_FC_PVER(n)  (((UINT16)(n)) & (BIT0 | BIT1))
00182 #define WLAN_GET_FC_FTYPE(n)  ((((UINT16)(n)) & (BIT2 | BIT3)) >> 2)
00183 #define WLAN_GET_FC_FSTYPE(n) ((((UINT16)(n)) & (BIT4|BIT5|BIT6|BIT7)) >> 4)
00184 #define WLAN_GET_FC_TODS(n)   ((((UINT16)(n)) & (BIT8)) >> 8)
00185 #define WLAN_GET_FC_FROMDS(n) ((((UINT16)(n)) & (BIT9)) >> 9)
00186 #define WLAN_GET_FC_MOREFRAG(n) ((((UINT16)(n)) & (BIT10)) >> 10)
00187 #define WLAN_GET_FC_RETRY(n)  ((((UINT16)(n)) & (BIT11)) >> 11)
00188 #define WLAN_GET_FC_PWRMGT(n) ((((UINT16)(n)) & (BIT12)) >> 12)
00189 #define WLAN_GET_FC_MOREDATA(n) ((((UINT16)(n)) & (BIT13)) >> 13)
00190 #define WLAN_GET_FC_ISWEP(n)  ((((UINT16)(n)) & (BIT14)) >> 14)
00191 #define WLAN_GET_FC_ORDER(n)  ((((UINT16)(n)) & (BIT15)) >> 15)
00192 
00193 #define WLAN_SET_FC_PVER(n) ((UINT16)(n))
00194 #define WLAN_SET_FC_FTYPE(n)  (((UINT16)(n)) << 2)
00195 #define WLAN_SET_FC_FSTYPE(n) (((UINT16)(n)) << 4)
00196 #define WLAN_SET_FC_TODS(n)   (((UINT16)(n)) << 8)
00197 #define WLAN_SET_FC_FROMDS(n) (((UINT16)(n)) << 9)
00198 #define WLAN_SET_FC_MOREFRAG(n) (((UINT16)(n)) << 10)
00199 #define WLAN_SET_FC_RETRY(n)  (((UINT16)(n)) << 11)
00200 #define WLAN_SET_FC_PWRMGT(n) (((UINT16)(n)) << 12)
00201 #define WLAN_SET_FC_MOREDATA(n) (((UINT16)(n)) << 13)
00202 #define WLAN_SET_FC_ISWEP(n)  (((UINT16)(n)) << 14)
00203 #define WLAN_SET_FC_ORDER(n)  (((UINT16)(n)) << 15)
00204 
00205 /*--- Duration Macros ----------------------------------------*/
00206 /* Macros to get/set the bitfields of the Duration Field      */
00207 /*  - the duration value is only valid when bit15 is zero     */
00208 /*  - the firmware handles these values, so I'm not going     */
00209 /*    these macros right now.                                 */
00210 /*------------------------------------------------------------*/
00211 
00212 /*--- Sequence Control  Macros -------------------------------*/
00213 /* Macros to get/set the bitfields of the Sequence Control    */
00214 /* Field.                                                     */
00215 /*------------------------------------------------------------*/
00216 #define WLAN_GET_SEQ_FRGNUM(n) (((UINT16)(n)) & (BIT0|BIT1|BIT2|BIT3))
00217 #define WLAN_GET_SEQ_SEQNUM(n) ((((UINT16)(n)) & (~(BIT0|BIT1|BIT2|BIT3))) >> 4) 
00218 
00219 /*--- Data ptr macro -----------------------------------------*/
00220 /* Creates a UINT8* to the data portion of a frame            */
00221 /* Assumes you're passing in a ptr to the beginning of the hdr*/
00222 /*------------------------------------------------------------*/
00223 #define WLAN_HDR_A3_DATAP(p) (((UINT8*)(p)) + WLAN_HDR_A3_LEN)
00224 #define WLAN_HDR_A4_DATAP(p) (((UINT8*)(p)) + WLAN_HDR_A4_LEN)
00225 
00226 #define DOT11_RATE5_ISBASIC_GET(r)     (((UINT8)(r)) & BIT7)
00227 
00228 /*================================================================*/
00229 /* Types */
00230 
00231 /* BSS Timestamp */
00232 typedef UINT8 wlan_bss_ts_t[WLAN_BSS_TS_LEN];
00233 
00234 /* Generic 802.11 Header types */
00235 
00236 typedef struct p80211_hdr_a3
00237 {
00238   UINT16  fc;
00239   UINT16  dur;
00240   UINT8 a1[WLAN_ADDR_LEN];
00241   UINT8 a2[WLAN_ADDR_LEN];
00242   UINT8 a3[WLAN_ADDR_LEN];
00243   UINT16  seq;
00244 } __WLAN_ATTRIB_PACK__ p80211_hdr_a3_t;
00245 
00246 typedef struct p80211_hdr_a4
00247 {
00248   UINT16  fc;
00249   UINT16  dur;
00250   UINT8 a1[WLAN_ADDR_LEN];
00251   UINT8 a2[WLAN_ADDR_LEN];
00252   UINT8 a3[WLAN_ADDR_LEN];
00253   UINT16  seq;
00254   UINT8 a4[WLAN_ADDR_LEN];
00255 } __WLAN_ATTRIB_PACK__ p80211_hdr_a4_t;
00256 
00257 typedef union p80211_hdr
00258 {
00259   p80211_hdr_a3_t   a3;
00260   p80211_hdr_a4_t   a4;
00261 } __WLAN_ATTRIB_PACK__ p80211_hdr_t;
00262 
00263 
00264 /*================================================================*/
00265 /* Extern Declarations */
00266 
00267 
00268 /*================================================================*/
00269 /* Function Declarations */
00270 
00271 /* Frame and header lenght macros */
00272 
00273 #define WLAN_CTL_FRAMELEN(fstype) (\
00274   (fstype) == WLAN_FSTYPE_BLOCKACKREQ ? 24 : \
00275   (fstype) == WLAN_FSTYPE_BLOCKACK    ? 152 : \
00276   (fstype) == WLAN_FSTYPE_PSPOLL    ? 20 : \
00277   (fstype) == WLAN_FSTYPE_RTS   ? 20 : \
00278   (fstype) == WLAN_FSTYPE_CTS   ? 14 : \
00279   (fstype) == WLAN_FSTYPE_ACK   ? 14 : \
00280   (fstype) == WLAN_FSTYPE_CFEND   ? 20 : \
00281   (fstype) == WLAN_FSTYPE_CFENDCFACK  ? 20 : 4)
00282 
00283 #define WLAN_FCS_LEN      4
00284 
00285 /* ftcl in HOST order */
00286 inline static UINT16 p80211_headerlen(UINT16 fctl)
00287 {
00288   UINT16 hdrlen = 0;
00289 
00290   switch ( WLAN_GET_FC_FTYPE(fctl) ) {
00291   case WLAN_FTYPE_MGMT:
00292     hdrlen = WLAN_HDR_A3_LEN;
00293     break;
00294   case WLAN_FTYPE_DATA:
00295     hdrlen = WLAN_HDR_A3_LEN;
00296     if ( WLAN_GET_FC_TODS(fctl) && WLAN_GET_FC_FROMDS(fctl) ) {
00297       hdrlen += WLAN_ADDR_LEN;
00298     }
00299     break;
00300   case WLAN_FTYPE_CTL:
00301     hdrlen = WLAN_CTL_FRAMELEN(WLAN_GET_FC_FSTYPE(fctl)) - 
00302       WLAN_FCS_LEN; 
00303     break;
00304   default:
00305     hdrlen = WLAN_HDR_A3_LEN;
00306   }
00307   
00308   return hdrlen;
00309 }
00310 
00311 #endif /* _P80211HDR_H */

Generated on Fri Jul 25 17:10:35 2008 for WifiScanner by  doxygen 1.5.5