Home | History | Annotate | Line # | Download | only in net80211
ieee80211.h revision 1.4
      1 /*	$NetBSD: ieee80211.h,v 1.4 2003/10/15 11:43:51 dyoung Exp $	*/
      2 /*-
      3  * Copyright (c) 2001 Atsushi Onoe
      4  * Copyright (c) 2002, 2003 Sam Leffler, Errno Consulting
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. The name of the author may not be used to endorse or promote products
     16  *    derived from this software without specific prior written permission.
     17  *
     18  * Alternatively, this software may be distributed under the terms of the
     19  * GNU General Public License ("GPL") version 2 as published by the Free
     20  * Software Foundation.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  *
     33  * $FreeBSD: src/sys/net80211/ieee80211.h,v 1.2 2003/06/27 05:13:52 sam Exp $
     34  */
     35 #ifndef _NET80211_IEEE80211_H_
     36 #define _NET80211_IEEE80211_H_
     37 
     38 /*
     39  * 802.11 protocol definitions.
     40  */
     41 
     42 #define	IEEE80211_ADDR_LEN	6		/* size of 802.11 address */
     43 /* is 802.11 address multicast/broadcast? */
     44 #define	IEEE80211_IS_MULTICAST(_a)	(*(_a) & 0x01)
     45 
     46 /* IEEE 802.11 PLCP header */
     47 struct ieee80211_plcp_hdr {
     48 	u_int16_t	i_sfd;
     49 	u_int8_t	i_signal;
     50 	u_int8_t	i_service;
     51 	u_int16_t	i_length;
     52 	u_int16_t	i_crc;
     53 } __attribute__((__packed__));
     54 
     55 #define IEEE80211_PLCP_SFD      0xF3A0
     56 #define IEEE80211_PLCP_SERVICE  0x00
     57 
     58 /*
     59  * generic definitions for IEEE 802.11 frames
     60  */
     61 struct ieee80211_frame {
     62 	u_int8_t	i_fc[2];
     63 	u_int8_t	i_dur[2];
     64 	u_int8_t	i_addr1[IEEE80211_ADDR_LEN];
     65 	u_int8_t	i_addr2[IEEE80211_ADDR_LEN];
     66 	u_int8_t	i_addr3[IEEE80211_ADDR_LEN];
     67 	u_int8_t	i_seq[2];
     68 	/* possibly followed by addr4[IEEE80211_ADDR_LEN]; */
     69 	/* see below */
     70 } __attribute__((__packed__));
     71 
     72 struct ieee80211_frame_addr4 {
     73 	u_int8_t	i_fc[2];
     74 	u_int8_t	i_dur[2];
     75 	u_int8_t	i_addr1[IEEE80211_ADDR_LEN];
     76 	u_int8_t	i_addr2[IEEE80211_ADDR_LEN];
     77 	u_int8_t	i_addr3[IEEE80211_ADDR_LEN];
     78 	u_int8_t	i_seq[2];
     79 	u_int8_t	i_addr4[IEEE80211_ADDR_LEN];
     80 } __attribute__((__packed__));
     81 
     82 #define	IEEE80211_FC0_VERSION_MASK		0x03
     83 #define	IEEE80211_FC0_VERSION_SHIFT		0
     84 #define	IEEE80211_FC0_VERSION_0			0x00
     85 #define	IEEE80211_FC0_TYPE_MASK			0x0c
     86 #define	IEEE80211_FC0_TYPE_SHIFT		2
     87 #define	IEEE80211_FC0_TYPE_MGT			0x00
     88 #define	IEEE80211_FC0_TYPE_CTL			0x04
     89 #define	IEEE80211_FC0_TYPE_DATA			0x08
     90 
     91 #define	IEEE80211_FC0_SUBTYPE_MASK		0xf0
     92 #define	IEEE80211_FC0_SUBTYPE_SHIFT		4
     93 /* for TYPE_MGT */
     94 #define	IEEE80211_FC0_SUBTYPE_ASSOC_REQ		0x00
     95 #define	IEEE80211_FC0_SUBTYPE_ASSOC_RESP	0x10
     96 #define	IEEE80211_FC0_SUBTYPE_REASSOC_REQ	0x20
     97 #define	IEEE80211_FC0_SUBTYPE_REASSOC_RESP	0x30
     98 #define	IEEE80211_FC0_SUBTYPE_PROBE_REQ		0x40
     99 #define	IEEE80211_FC0_SUBTYPE_PROBE_RESP	0x50
    100 #define	IEEE80211_FC0_SUBTYPE_BEACON		0x80
    101 #define	IEEE80211_FC0_SUBTYPE_ATIM		0x90
    102 #define	IEEE80211_FC0_SUBTYPE_DISASSOC		0xa0
    103 #define	IEEE80211_FC0_SUBTYPE_AUTH		0xb0
    104 #define	IEEE80211_FC0_SUBTYPE_DEAUTH		0xc0
    105 /* for TYPE_CTL */
    106 #define	IEEE80211_FC0_SUBTYPE_PS_POLL		0xa0
    107 #define	IEEE80211_FC0_SUBTYPE_RTS		0xb0
    108 #define	IEEE80211_FC0_SUBTYPE_CTS		0xc0
    109 #define	IEEE80211_FC0_SUBTYPE_ACK		0xd0
    110 #define	IEEE80211_FC0_SUBTYPE_CF_END		0xe0
    111 #define	IEEE80211_FC0_SUBTYPE_CF_END_ACK	0xf0
    112 /* for TYPE_DATA (bit combination) */
    113 #define	IEEE80211_FC0_SUBTYPE_DATA		0x00
    114 #define	IEEE80211_FC0_SUBTYPE_CF_ACK		0x10
    115 #define	IEEE80211_FC0_SUBTYPE_CF_POLL		0x20
    116 #define	IEEE80211_FC0_SUBTYPE_CF_ACPL		0x30
    117 #define	IEEE80211_FC0_SUBTYPE_NODATA		0x40
    118 #define	IEEE80211_FC0_SUBTYPE_CFACK		0x50
    119 #define	IEEE80211_FC0_SUBTYPE_CFPOLL		0x60
    120 #define	IEEE80211_FC0_SUBTYPE_CF_ACK_CF_ACK	0x70
    121 
    122 #define	IEEE80211_FC1_DIR_MASK			0x03
    123 #define	IEEE80211_FC1_DIR_NODS			0x00	/* STA->STA */
    124 #define	IEEE80211_FC1_DIR_TODS			0x01	/* STA->AP  */
    125 #define	IEEE80211_FC1_DIR_FROMDS		0x02	/* AP ->STA */
    126 #define	IEEE80211_FC1_DIR_DSTODS		0x03	/* AP ->AP  */
    127 
    128 #define	IEEE80211_FC1_MORE_FRAG			0x04
    129 #define	IEEE80211_FC1_RETRY			0x08
    130 #define	IEEE80211_FC1_PWR_MGT			0x10
    131 #define	IEEE80211_FC1_MORE_DATA			0x20
    132 #define	IEEE80211_FC1_WEP			0x40
    133 #define	IEEE80211_FC1_ORDER			0x80
    134 
    135 #define	IEEE80211_SEQ_FRAG_MASK			0x000f
    136 #define	IEEE80211_SEQ_FRAG_SHIFT		0
    137 #define	IEEE80211_SEQ_SEQ_MASK			0xfff0
    138 #define	IEEE80211_SEQ_SEQ_SHIFT			4
    139 
    140 #define	IEEE80211_NWID_LEN			32
    141 
    142 /*
    143  * BEACON management packets
    144  *
    145  *	octet timestamp[8]
    146  *	octet beacon interval[2]
    147  *	octet capability information[2]
    148  *	information element
    149  *		octet elemid
    150  *		octet length
    151  *		octet information[length]
    152  */
    153 
    154 typedef uint8_t *ieee80211_mgt_beacon_t;
    155 
    156 #define	IEEE80211_BEACON_INTERVAL(beacon) \
    157 	((beacon)[8] | ((beacon)[9] << 8))
    158 #define	IEEE80211_BEACON_CAPABILITY(beacon) \
    159 	((beacon)[10] | ((beacon)[11] << 8))
    160 
    161 #define	IEEE80211_CAPINFO_ESS			0x0001
    162 #define	IEEE80211_CAPINFO_IBSS			0x0002
    163 #define	IEEE80211_CAPINFO_CF_POLLABLE		0x0004
    164 #define	IEEE80211_CAPINFO_CF_POLLREQ		0x0008
    165 #define	IEEE80211_CAPINFO_PRIVACY		0x0010
    166 #define	IEEE80211_CAPINFO_SHORT_PREAMBLE	0x0020
    167 #define	IEEE80211_CAPINFO_PBCC			0x0040
    168 #define	IEEE80211_CAPINFO_CHNL_AGILITY		0x0080
    169 /* bits 8-9 are reserved */
    170 #define	IEEE80211_CAPINFO_SHORT_SLOTTIME	0x0400
    171 /* bits 11-12 are reserved */
    172 #define	IEEE80211_CAPINFO_DSSSOFDM		0x2000
    173 /* bits 14-15 are reserved */
    174 
    175 /*
    176  * Management information elements
    177  */
    178 struct ieee80211_information {
    179 	char	ssid[IEEE80211_NWID_LEN+1];
    180 	struct rates {
    181 		u_int8_t	*p;
    182 	} rates;
    183 	struct fh {
    184 		u_int16_t	dwell;
    185 		u_int8_t	set;
    186 		u_int8_t	pattern;
    187 		u_int8_t	index;
    188 	} fh;
    189 	struct ds {
    190 		u_int8_t	channel;
    191 	} ds;
    192 	struct cf {
    193 		u_int8_t	count;
    194 		u_int8_t	period;
    195 		u_int8_t	maxdur[2];
    196 		u_int8_t	dur[2];
    197 	} cf;
    198 	struct tim {
    199 		u_int8_t	count;
    200 		u_int8_t	period;
    201 		u_int8_t	bitctl;
    202 		/* u_int8_t	pvt[251]; The driver needs to use this. */
    203 	} tim;
    204 	struct ibss {
    205 		u_int16_t	atim;
    206 	} ibss;
    207 	struct challenge {
    208 		u_int8_t	*p;
    209 		u_int8_t	len;
    210 	} challenge;
    211 	struct erp {
    212 		u_int8_t	flags;
    213 	} erp;
    214 };
    215 
    216 enum {
    217 	IEEE80211_ELEMID_SSID			= 0,
    218 	IEEE80211_ELEMID_RATES			= 1,
    219 	IEEE80211_ELEMID_FHPARMS		= 2,
    220 	IEEE80211_ELEMID_DSPARMS		= 3,
    221 	IEEE80211_ELEMID_CFPARMS		= 4,
    222 	IEEE80211_ELEMID_TIM			= 5,
    223 	IEEE80211_ELEMID_IBSSPARMS		= 6,
    224 	IEEE80211_ELEMID_COUNTRY		= 7,
    225 	IEEE80211_ELEMID_CHALLENGE		= 16,
    226 	IEEE80211_ELEMID_ERP			= 42,
    227 	IEEE80211_ELEMID_XRATES			= 50,
    228 };
    229 
    230 #define IEEE80211_CHALLENGE_LEN			128
    231 
    232 #define	IEEE80211_RATE_BASIC			0x80
    233 #define	IEEE80211_RATE_VAL			0x7f
    234 
    235 /* EPR information element flags */
    236 #define	IEEE80211_ERP_NON_ERP_PRESENT		0x01
    237 #define	IEEE80211_ERP_USE_PROTECTION		0x02
    238 #define	IEEE80211_ERP_BARKER_MODE		0x04
    239 
    240 /*
    241  * AUTH management packets
    242  *
    243  *	octet algo[2]
    244  *	octet seq[2]
    245  *	octet status[2]
    246  *	octet chal.id
    247  *	octet chal.length
    248  *	octet chal.text[253]
    249  */
    250 
    251 typedef u_int8_t *ieee80211_mgt_auth_t;
    252 
    253 #define	IEEE80211_AUTH_ALGORITHM(auth) \
    254 	((auth)[0] | ((auth)[1] << 8))
    255 #define	IEEE80211_AUTH_TRANSACTION(auth) \
    256 	((auth)[2] | ((auth)[3] << 8))
    257 #define	IEEE80211_AUTH_STATUS(auth) \
    258 	((auth)[4] | ((auth)[5] << 8))
    259 
    260 #define	IEEE80211_AUTH_ALG_OPEN			0x0000
    261 #define	IEEE80211_AUTH_ALG_SHARED		0x0001
    262 
    263 enum {
    264 	IEEE80211_AUTH_OPEN_REQUEST		= 1,
    265 	IEEE80211_AUTH_OPEN_RESPONSE		= 2,
    266 };
    267 
    268 enum {
    269 	IEEE80211_AUTH_SHARED_REQUEST		= 1,
    270 	IEEE80211_AUTH_SHARED_CHALLENGE		= 2,
    271 	IEEE80211_AUTH_SHARED_RESPONSE		= 3,
    272 	IEEE80211_AUTH_SHARED_PASS		= 4,
    273 };
    274 
    275 /*
    276  * Reason codes
    277  *
    278  * Unlisted codes are reserved
    279  */
    280 
    281 enum {
    282 	IEEE80211_REASON_UNSPECIFIED		= 1,
    283 	IEEE80211_REASON_AUTH_EXPIRE		= 2,
    284 	IEEE80211_REASON_AUTH_LEAVE		= 3,
    285 	IEEE80211_REASON_ASSOC_EXPIRE		= 4,
    286 	IEEE80211_REASON_ASSOC_TOOMANY		= 5,
    287 	IEEE80211_REASON_NOT_AUTHED		= 6,
    288 	IEEE80211_REASON_NOT_ASSOCED		= 7,
    289 	IEEE80211_REASON_ASSOC_LEAVE		= 8,
    290 	IEEE80211_REASON_ASSOC_NOT_AUTHED	= 9,
    291 
    292 	IEEE80211_STATUS_SUCCESS		= 0,
    293 	IEEE80211_STATUS_UNSPECIFIED		= 1,
    294 	IEEE80211_STATUS_CAPINFO		= 10,
    295 	IEEE80211_STATUS_NOT_ASSOCED		= 11,
    296 	IEEE80211_STATUS_OTHER			= 12,
    297 	IEEE80211_STATUS_ALG			= 13,
    298 	IEEE80211_STATUS_SEQUENCE		= 14,
    299 	IEEE80211_STATUS_CHALLENGE		= 15,
    300 	IEEE80211_STATUS_TIMEOUT		= 16,
    301 	IEEE80211_STATUS_TOOMANY		= 17,
    302 	IEEE80211_STATUS_BASIC_RATE		= 18,
    303 	IEEE80211_STATUS_SP_REQUIRED		= 19,
    304 	IEEE80211_STATUS_PBCC_REQUIRED		= 20,
    305 	IEEE80211_STATUS_CA_REQUIRED		= 21,
    306 	IEEE80211_STATUS_TOO_MANY_STATIONS	= 22,
    307 	IEEE80211_STATUS_RATES			= 23,
    308 	IEEE80211_STATUS_SHORTSLOT_REQUIRED	= 25,
    309 	IEEE80211_STATUS_DSSSOFDM_REQUIRED	= 26,
    310 };
    311 
    312 #define	IEEE80211_WEP_KEYLEN			5	/* 40bit */
    313 #define	IEEE80211_WEP_IVLEN			3	/* 24bit */
    314 #define	IEEE80211_WEP_KIDLEN			1	/* 1 octet */
    315 #define	IEEE80211_WEP_CRCLEN			4	/* CRC-32 */
    316 #define	IEEE80211_WEP_NKID			4	/* number of key ids */
    317 
    318 #define	IEEE80211_CRC_LEN			4
    319 
    320 #define	IEEE80211_MTU				1500
    321 #define	IEEE80211_MAX_LEN			(2300 + IEEE80211_CRC_LEN + \
    322     (IEEE80211_WEP_IVLEN + IEEE80211_WEP_KIDLEN + IEEE80211_WEP_CRCLEN))
    323 
    324 #define	IEEE80211_MAX_AID			2007
    325 
    326 #define	IEEE80211_AID_SET(b, w) \
    327 	((w)[((b) & ~0xc000) / 32] |= (1 << (((b) & ~0xc000) % 32)))
    328 #define	IEEE80211_AID_CLR(b, w) \
    329 	((w)[((b) & ~0xc000) / 32] &= ~(1 << (((b) & ~0xc000) % 32)))
    330 #define	IEEE80211_AID_ISSET(b, w) \
    331 	((w)[((b) & ~0xc000) / 32] & (1 << (((b) & ~0xc000) % 32)))
    332 
    333 /*
    334  * RTS frame length parameters.  The default is specified in
    335  * the 802.11 spec.  The max may be wrong for jumbo frames.
    336  */
    337 #define	IEEE80211_RTS_DEFAULT			512
    338 #define	IEEE80211_RTS_MIN			1
    339 #define	IEEE80211_RTS_MAX			IEEE80211_MAX_LEN
    340 
    341 enum {
    342 	IEEE80211_AUTH_NONE	= 0,
    343 	IEEE80211_AUTH_OPEN	= 1,
    344 	IEEE80211_AUTH_SHARED	= 2,
    345 };
    346 
    347 #endif /* _NET80211_IEEE80211_H_ */
    348