iPXE
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 FILE_LICENCE ( GPL2_ONLY );
00061 
00062 #ifndef _P80211HDR_H
00063 #define _P80211HDR_H
00064 
00065 /*================================================================*/
00066 /* System Includes */
00067 
00068 /*================================================================*/
00069 /* Project Includes */
00070 
00071 #ifndef  _WLAN_COMPAT_H
00072 #include <wlan/wlan_compat.h>
00073 #endif
00074 
00075 
00076 /*================================================================*/
00077 /* Constants */
00078 
00079 /*--- Sizes -----------------------------------------------*/
00080 #define WLAN_ADDR_LEN                   6
00081 #define WLAN_CRC_LEN                    4
00082 #define WLAN_BSSID_LEN                  6
00083 #define WLAN_BSS_TS_LEN                 8
00084 #define WLAN_HDR_A3_LEN                 24
00085 #define WLAN_HDR_A4_LEN                 30
00086 #define WLAN_SSID_MAXLEN                32
00087 #define WLAN_DATA_MAXLEN                2312
00088 #define WLAN_A3FR_MAXLEN                (WLAN_HDR_A3_LEN + WLAN_DATA_MAXLEN + WLAN_CRC_LEN)
00089 #define WLAN_A4FR_MAXLEN                (WLAN_HDR_A4_LEN + WLAN_DATA_MAXLEN + WLAN_CRC_LEN)
00090 #define WLAN_BEACON_FR_MAXLEN           (WLAN_HDR_A3_LEN + 334)
00091 #define WLAN_ATIM_FR_MAXLEN             (WLAN_HDR_A3_LEN + 0)
00092 #define WLAN_DISASSOC_FR_MAXLEN         (WLAN_HDR_A3_LEN + 2)
00093 #define WLAN_ASSOCREQ_FR_MAXLEN         (WLAN_HDR_A3_LEN + 48)
00094 #define WLAN_ASSOCRESP_FR_MAXLEN        (WLAN_HDR_A3_LEN + 16)
00095 #define WLAN_REASSOCREQ_FR_MAXLEN       (WLAN_HDR_A3_LEN + 54)
00096 #define WLAN_REASSOCRESP_FR_MAXLEN      (WLAN_HDR_A3_LEN + 16)
00097 #define WLAN_PROBEREQ_FR_MAXLEN         (WLAN_HDR_A3_LEN + 44)
00098 #define WLAN_PROBERESP_FR_MAXLEN        (WLAN_HDR_A3_LEN + 78)
00099 #define WLAN_AUTHEN_FR_MAXLEN           (WLAN_HDR_A3_LEN + 261)
00100 #define WLAN_DEAUTHEN_FR_MAXLEN         (WLAN_HDR_A3_LEN + 2)
00101 #define WLAN_WEP_NKEYS                  4
00102 #define WLAN_WEP_MAXKEYLEN              13
00103 #define WLAN_CHALLENGE_IE_LEN           130
00104 #define WLAN_CHALLENGE_LEN              128
00105 #define WLAN_WEP_IV_LEN                 4
00106 #define WLAN_WEP_ICV_LEN                4
00107 
00108 /*--- Frame Control Field -------------------------------------*/
00109 /* Frame Types */
00110 #define WLAN_FTYPE_MGMT                 0x00
00111 #define WLAN_FTYPE_CTL                  0x01
00112 #define WLAN_FTYPE_DATA                 0x02
00113 
00114 /* Frame subtypes */
00115 /* Management */
00116 #define WLAN_FSTYPE_ASSOCREQ            0x00
00117 #define WLAN_FSTYPE_ASSOCRESP           0x01
00118 #define WLAN_FSTYPE_REASSOCREQ          0x02
00119 #define WLAN_FSTYPE_REASSOCRESP         0x03
00120 #define WLAN_FSTYPE_PROBEREQ            0x04
00121 #define WLAN_FSTYPE_PROBERESP           0x05
00122 #define WLAN_FSTYPE_BEACON              0x08
00123 #define WLAN_FSTYPE_ATIM                0x09
00124 #define WLAN_FSTYPE_DISASSOC            0x0a
00125 #define WLAN_FSTYPE_AUTHEN              0x0b
00126 #define WLAN_FSTYPE_DEAUTHEN            0x0c
00127 
00128 /* Control */
00129 #define WLAN_FSTYPE_BLOCKACKREQ         0x8
00130 #define WLAN_FSTYPE_BLOCKACK            0x9
00131 #define WLAN_FSTYPE_PSPOLL              0x0a
00132 #define WLAN_FSTYPE_RTS                 0x0b
00133 #define WLAN_FSTYPE_CTS                 0x0c
00134 #define WLAN_FSTYPE_ACK                 0x0d
00135 #define WLAN_FSTYPE_CFEND               0x0e
00136 #define WLAN_FSTYPE_CFENDCFACK          0x0f
00137 
00138 /* Data */
00139 #define WLAN_FSTYPE_DATAONLY            0x00
00140 #define WLAN_FSTYPE_DATA_CFACK          0x01
00141 #define WLAN_FSTYPE_DATA_CFPOLL         0x02
00142 #define WLAN_FSTYPE_DATA_CFACK_CFPOLL   0x03
00143 #define WLAN_FSTYPE_NULL                0x04
00144 #define WLAN_FSTYPE_CFACK               0x05
00145 #define WLAN_FSTYPE_CFPOLL              0x06
00146 #define WLAN_FSTYPE_CFACK_CFPOLL        0x07
00147 
00148 
00149 /*================================================================*/
00150 /* Macros */
00151 
00152 /*--- FC Macros ----------------------------------------------*/
00153 /* Macros to get/set the bitfields of the Frame Control Field */
00154 /*  GET_FC_??? - takes the host byte-order value of an FC     */
00155 /*               and retrieves the value of one of the        */
00156 /*               bitfields and moves that value so its lsb is */
00157 /*               in bit 0.                                    */
00158 /*  SET_FC_??? - takes a host order value for one of the FC   */
00159 /*               bitfields and moves it to the proper bit     */
00160 /*               location for ORing into a host order FC.     */
00161 /*               To send the FC produced from SET_FC_???,     */
00162 /*               one must put the bytes in IEEE order.        */
00163 /*  e.g.                                                      */
00164 /*     printf("the frame subtype is %x",                      */
00165 /*                 GET_FC_FTYPE( ieee2host( rx.fc )))         */
00166 /*                                                            */
00167 /*     tx.fc = host2ieee( SET_FC_FTYPE(WLAN_FTYP_CTL) |       */
00168 /*                        SET_FC_FSTYPE(WLAN_FSTYPE_RTS) );   */
00169 /*------------------------------------------------------------*/
00170 
00171 #define WLAN_GET_FC_PVER(n)      (((uint16_t)(n)) & (BIT0 | BIT1))
00172 #define WLAN_GET_FC_FTYPE(n)    ((((uint16_t)(n)) & (BIT2 | BIT3)) >> 2)
00173 #define WLAN_GET_FC_FSTYPE(n)   ((((uint16_t)(n)) & (BIT4|BIT5|BIT6|BIT7)) >> 4)
00174 #define WLAN_GET_FC_TODS(n)     ((((uint16_t)(n)) & (BIT8)) >> 8)
00175 #define WLAN_GET_FC_FROMDS(n)   ((((uint16_t)(n)) & (BIT9)) >> 9)
00176 #define WLAN_GET_FC_MOREFRAG(n) ((((uint16_t)(n)) & (BIT10)) >> 10)
00177 #define WLAN_GET_FC_RETRY(n)    ((((uint16_t)(n)) & (BIT11)) >> 11)
00178 #define WLAN_GET_FC_PWRMGT(n)   ((((uint16_t)(n)) & (BIT12)) >> 12)
00179 #define WLAN_GET_FC_MOREDATA(n) ((((uint16_t)(n)) & (BIT13)) >> 13)
00180 #define WLAN_GET_FC_ISWEP(n)    ((((uint16_t)(n)) & (BIT14)) >> 14)
00181 #define WLAN_GET_FC_ORDER(n)    ((((uint16_t)(n)) & (BIT15)) >> 15)
00182 
00183 #define WLAN_SET_FC_PVER(n)     ((uint16_t)(n))
00184 #define WLAN_SET_FC_FTYPE(n)    (((uint16_t)(n)) << 2)
00185 #define WLAN_SET_FC_FSTYPE(n)   (((uint16_t)(n)) << 4)
00186 #define WLAN_SET_FC_TODS(n)     (((uint16_t)(n)) << 8)
00187 #define WLAN_SET_FC_FROMDS(n)   (((uint16_t)(n)) << 9)
00188 #define WLAN_SET_FC_MOREFRAG(n) (((uint16_t)(n)) << 10)
00189 #define WLAN_SET_FC_RETRY(n)    (((uint16_t)(n)) << 11)
00190 #define WLAN_SET_FC_PWRMGT(n)   (((uint16_t)(n)) << 12)
00191 #define WLAN_SET_FC_MOREDATA(n) (((uint16_t)(n)) << 13)
00192 #define WLAN_SET_FC_ISWEP(n)    (((uint16_t)(n)) << 14)
00193 #define WLAN_SET_FC_ORDER(n)    (((uint16_t)(n)) << 15)
00194 
00195 /*--- Duration Macros ----------------------------------------*/
00196 /* Macros to get/set the bitfields of the Duration Field      */
00197 /*  - the duration value is only valid when bit15 is zero     */
00198 /*  - the firmware handles these values, so I'm not going     */
00199 /*    these macros right now.                                 */
00200 /*------------------------------------------------------------*/
00201 
00202 /*--- Sequence Control  Macros -------------------------------*/
00203 /* Macros to get/set the bitfields of the Sequence Control    */
00204 /* Field.                                                     */
00205 /*------------------------------------------------------------*/
00206 #define WLAN_GET_SEQ_FRGNUM(n) (((uint16_t)(n)) & (BIT0|BIT1|BIT2|BIT3))
00207 #define WLAN_GET_SEQ_SEQNUM(n) ((((uint16_t)(n)) & (~(BIT0|BIT1|BIT2|BIT3))) >> 4)
00208 
00209 /*--- Data ptr macro -----------------------------------------*/
00210 /* Creates a uint8_t* to the data portion of a frame            */
00211 /* Assumes you're passing in a ptr to the beginning of the hdr*/
00212 /*------------------------------------------------------------*/
00213 #define WLAN_HDR_A3_DATAP(p) (((uint8_t*)(p)) + WLAN_HDR_A3_LEN)
00214 #define WLAN_HDR_A4_DATAP(p) (((uint8_t*)(p)) + WLAN_HDR_A4_LEN)
00215 
00216 #define DOT11_RATE5_ISBASIC_GET(r)     (((uint8_t)(r)) & BIT7)
00217 
00218 /*================================================================*/
00219 /* Types */
00220 
00221 /* BSS Timestamp */
00222 typedef uint8_t wlan_bss_ts_t[WLAN_BSS_TS_LEN];
00223 
00224 /* Generic 802.11 Header types */
00225 
00226 typedef struct p80211_hdr_a3
00227 {
00228         uint16_t        fc;
00229         uint16_t        dur;
00230         uint8_t a1[WLAN_ADDR_LEN];
00231         uint8_t a2[WLAN_ADDR_LEN];
00232         uint8_t a3[WLAN_ADDR_LEN];
00233         uint16_t        seq;
00234 } __WLAN_ATTRIB_PACK__ p80211_hdr_a3_t;
00235 
00236 typedef struct p80211_hdr_a4
00237 {
00238         uint16_t        fc;
00239         uint16_t        dur;
00240         uint8_t a1[WLAN_ADDR_LEN];
00241         uint8_t a2[WLAN_ADDR_LEN];
00242         uint8_t a3[WLAN_ADDR_LEN];
00243         uint16_t        seq;
00244         uint8_t a4[WLAN_ADDR_LEN];
00245 } __WLAN_ATTRIB_PACK__ p80211_hdr_a4_t;
00246 
00247 typedef union p80211_hdr
00248 {
00249         p80211_hdr_a3_t         a3;
00250         p80211_hdr_a4_t         a4;
00251 } __WLAN_ATTRIB_PACK__ p80211_hdr_t;
00252 
00253 
00254 /*================================================================*/
00255 /* Extern Declarations */
00256 
00257 
00258 /*================================================================*/
00259 /* Function Declarations */
00260 
00261 /* Frame and header length macros */
00262 
00263 #define WLAN_CTL_FRAMELEN(fstype) (\
00264         (fstype) == WLAN_FSTYPE_BLOCKACKREQ     ? 24 : \
00265         (fstype) == WLAN_FSTYPE_BLOCKACK        ? 152 : \
00266         (fstype) == WLAN_FSTYPE_PSPOLL          ? 20 : \
00267         (fstype) == WLAN_FSTYPE_RTS             ? 20 : \
00268         (fstype) == WLAN_FSTYPE_CTS             ? 14 : \
00269         (fstype) == WLAN_FSTYPE_ACK             ? 14 : \
00270         (fstype) == WLAN_FSTYPE_CFEND           ? 20 : \
00271         (fstype) == WLAN_FSTYPE_CFENDCFACK      ? 20 : 4)
00272 
00273 #define WLAN_FCS_LEN                    4
00274 
00275 /* ftcl in HOST order */
00276 inline static uint16_t p80211_headerlen(uint16_t fctl)
00277 {
00278         uint16_t hdrlen = 0;
00279 
00280         switch ( WLAN_GET_FC_FTYPE(fctl) ) {
00281         case WLAN_FTYPE_MGMT:
00282                 hdrlen = WLAN_HDR_A3_LEN;
00283                 break;
00284         case WLAN_FTYPE_DATA:
00285                 hdrlen = WLAN_HDR_A3_LEN;
00286                 if ( WLAN_GET_FC_TODS(fctl) && WLAN_GET_FC_FROMDS(fctl) ) {
00287                         hdrlen += WLAN_ADDR_LEN;
00288                 }
00289                 break;
00290         case WLAN_FTYPE_CTL:
00291                 hdrlen = WLAN_CTL_FRAMELEN(WLAN_GET_FC_FSTYPE(fctl)) -
00292                         WLAN_FCS_LEN;
00293                 break;
00294         default:
00295                 hdrlen = WLAN_HDR_A3_LEN;
00296         }
00297 
00298         return hdrlen;
00299 }
00300 
00301 #endif /* _P80211HDR_H */