Home | History | Annotate | Line # | Download | only in net80211
ieee80211_var.h revision 1.7
      1 /*	$NetBSD: ieee80211_var.h,v 1.7 2004/05/06 03:07:10 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_var.h,v 1.15 2004/04/05 22:10:26 sam Exp $
     34  */
     35 #ifndef _NET80211_IEEE80211_VAR_H_
     36 #define _NET80211_IEEE80211_VAR_H_
     37 
     38 /*
     39  * Definitions for IEEE 802.11 drivers.
     40  */
     41 
     42 #include <net80211/ieee80211.h>
     43 #include <net80211/ieee80211_crypto.h>
     44 #include <net80211/ieee80211_ioctl.h>		/* for ieee80211_stats */
     45 #include <net80211/ieee80211_node.h>
     46 #include <net80211/ieee80211_proto.h>
     47 
     48 #define	IEEE80211_CHAN_MAX	255
     49 #define	IEEE80211_CHAN_ANY	0xffff		/* token for ``any channel'' */
     50 #define	IEEE80211_CHAN_ANYC \
     51 	((struct ieee80211_channel *) IEEE80211_CHAN_ANY)
     52 
     53 #define	IEEE80211_TXPOWER_MAX	100	/* max power */
     54 #define	IEEE80211_TXPOWER_MIN	0	/* kill radio (if possible) */
     55 
     56 enum ieee80211_phytype {
     57 	IEEE80211_T_DS,			/* direct sequence spread spectrum */
     58 	IEEE80211_T_FH,			/* frequency hopping */
     59 	IEEE80211_T_OFDM,		/* frequency division multiplexing */
     60 	IEEE80211_T_TURBO,		/* high rate OFDM, aka turbo mode */
     61 };
     62 #define	IEEE80211_T_CCK	IEEE80211_T_DS	/* more common nomenclature */
     63 
     64 /* XXX not really a mode; there are really multiple PHY's */
     65 enum ieee80211_phymode {
     66 	IEEE80211_MODE_AUTO	= 0,	/* autoselect */
     67 	IEEE80211_MODE_11A	= 1,	/* 5GHz, OFDM */
     68 	IEEE80211_MODE_11B	= 2,	/* 2GHz, CCK */
     69 	IEEE80211_MODE_11G	= 3,	/* 2GHz, OFDM */
     70 	IEEE80211_MODE_FH	= 4,	/* 2GHz, GFSK */
     71 	IEEE80211_MODE_TURBO	= 5,	/* 5GHz, OFDM, 2x clock */
     72 };
     73 #define	IEEE80211_MODE_MAX	(IEEE80211_MODE_TURBO+1)
     74 
     75 enum ieee80211_opmode {
     76 	IEEE80211_M_STA		= 1,	/* infrastructure station */
     77 	IEEE80211_M_IBSS 	= 0,	/* IBSS (adhoc) station */
     78 	IEEE80211_M_AHDEMO	= 3,	/* Old lucent compatible adhoc demo */
     79 	IEEE80211_M_HOSTAP	= 6,	/* Software Access Point */
     80 	IEEE80211_M_MONITOR	= 8	/* Monitor mode */
     81 };
     82 
     83 /*
     84  * 802.11g protection mode.
     85  */
     86 enum ieee80211_protmode {
     87 	IEEE80211_PROT_NONE	= 0,	/* no protection */
     88 	IEEE80211_PROT_CTSONLY	= 1,	/* CTS to self */
     89 	IEEE80211_PROT_RTSCTS	= 2,	/* RTS-CTS */
     90 };
     91 
     92 /*
     93  * Channels are specified by frequency and attributes.
     94  */
     95 struct ieee80211_channel {
     96 	u_int16_t	ic_freq;	/* setting in Mhz */
     97 	u_int16_t	ic_flags;	/* see below */
     98 };
     99 
    100 /* bits 0-3 are for private use by drivers */
    101 /* channel attributes */
    102 #define	IEEE80211_CHAN_TURBO	0x0010	/* Turbo channel */
    103 #define	IEEE80211_CHAN_CCK	0x0020	/* CCK channel */
    104 #define	IEEE80211_CHAN_OFDM	0x0040	/* OFDM channel */
    105 #define	IEEE80211_CHAN_2GHZ	0x0080	/* 2 GHz spectrum channel. */
    106 #define	IEEE80211_CHAN_5GHZ	0x0100	/* 5 GHz spectrum channel */
    107 #define	IEEE80211_CHAN_PASSIVE	0x0200	/* Only passive scan allowed */
    108 #define	IEEE80211_CHAN_DYN	0x0400	/* Dynamic CCK-OFDM channel */
    109 #define	IEEE80211_CHAN_GFSK	0x0800	/* GFSK channel (FHSS PHY) */
    110 
    111 /*
    112  * Useful combinations of channel characteristics.
    113  */
    114 #define	IEEE80211_CHAN_FHSS \
    115 	(IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_GFSK)
    116 #define	IEEE80211_CHAN_A \
    117 	(IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_OFDM)
    118 #define	IEEE80211_CHAN_B \
    119 	(IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_CCK)
    120 #define	IEEE80211_CHAN_PUREG \
    121 	(IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_OFDM)
    122 #define	IEEE80211_CHAN_G \
    123 	(IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_DYN)
    124 #define	IEEE80211_CHAN_T \
    125 	(IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_OFDM | IEEE80211_CHAN_TURBO)
    126 
    127 #define	IEEE80211_IS_CHAN_FHSS(_c) \
    128 	(((_c)->ic_flags & IEEE80211_CHAN_FHSS) == IEEE80211_CHAN_FHSS)
    129 #define	IEEE80211_IS_CHAN_A(_c) \
    130 	(((_c)->ic_flags & IEEE80211_CHAN_A) == IEEE80211_CHAN_A)
    131 #define	IEEE80211_IS_CHAN_B(_c) \
    132 	(((_c)->ic_flags & IEEE80211_CHAN_B) == IEEE80211_CHAN_B)
    133 #define	IEEE80211_IS_CHAN_PUREG(_c) \
    134 	(((_c)->ic_flags & IEEE80211_CHAN_PUREG) == IEEE80211_CHAN_PUREG)
    135 #define	IEEE80211_IS_CHAN_G(_c) \
    136 	(((_c)->ic_flags & IEEE80211_CHAN_G) == IEEE80211_CHAN_G)
    137 #define	IEEE80211_IS_CHAN_T(_c) \
    138 	(((_c)->ic_flags & IEEE80211_CHAN_T) == IEEE80211_CHAN_T)
    139 
    140 #define	IEEE80211_IS_CHAN_2GHZ(_c) \
    141 	(((_c)->ic_flags & IEEE80211_CHAN_2GHZ) != 0)
    142 #define	IEEE80211_IS_CHAN_5GHZ(_c) \
    143 	(((_c)->ic_flags & IEEE80211_CHAN_5GHZ) != 0)
    144 #define	IEEE80211_IS_CHAN_OFDM(_c) \
    145 	(((_c)->ic_flags & IEEE80211_CHAN_OFDM) != 0)
    146 #define	IEEE80211_IS_CHAN_CCK(_c) \
    147 	(((_c)->ic_flags & IEEE80211_CHAN_CCK) != 0)
    148 #define	IEEE80211_IS_CHAN_GFSK(_c) \
    149 	(((_c)->ic_flags & IEEE80211_CHAN_GFSK) != 0)
    150 
    151 /* ni_chan encoding for FH phy */
    152 #define	IEEE80211_FH_CHANMOD	80
    153 #define	IEEE80211_FH_CHAN(set,pat)	(((set)-1)*IEEE80211_FH_CHANMOD+(pat))
    154 #define	IEEE80211_FH_CHANSET(chan)	((chan)/IEEE80211_FH_CHANMOD+1)
    155 #define	IEEE80211_FH_CHANPAT(chan)	((chan)%IEEE80211_FH_CHANMOD)
    156 
    157 #define	IEEE80211_PS_SLEEP	0x1	/* STA is in power saving mode */
    158 
    159 #define	IEEE80211_PS_MAX_QUEUE	50	/* maximum saved packets */
    160 
    161 struct ieee80211com {
    162 #ifdef __NetBSD__
    163 	struct ethercom		ic_ec;
    164 #else
    165 	struct arpcom		ic_ac;
    166 #endif
    167 	void			(*ic_recv_mgmt)(struct ieee80211com *,
    168 				    struct mbuf *, struct ieee80211_node *,
    169 				    int, int, u_int32_t);
    170 	int			(*ic_send_mgmt)(struct ieee80211com *,
    171 				    struct ieee80211_node *, int, int);
    172 	int			(*ic_newstate)(struct ieee80211com *,
    173 				    enum ieee80211_state, int);
    174 	void			(*ic_newassoc)(struct ieee80211com *,
    175 				    struct ieee80211_node *, int);
    176 	int			(*ic_set_tim)(struct ieee80211com *, int, int);
    177 	u_int8_t		ic_myaddr[IEEE80211_ADDR_LEN];
    178 	struct ieee80211_rateset ic_sup_rates[IEEE80211_MODE_MAX];
    179 	struct ieee80211_channel ic_channels[IEEE80211_CHAN_MAX+1];
    180 	u_char			ic_chan_avail[roundup(IEEE80211_CHAN_MAX,NBBY)];
    181 	u_char			ic_chan_active[roundup(IEEE80211_CHAN_MAX, NBBY)];
    182 	u_char			ic_chan_scan[roundup(IEEE80211_CHAN_MAX,NBBY)];
    183 	struct ifqueue		ic_mgtq;
    184 	struct ifqueue		ic_pwrsaveq;
    185 	u_int32_t		ic_flags;	/* state flags */
    186 	u_int32_t		ic_caps;	/* capabilities */
    187 	u_int16_t		ic_modecaps;	/* set of mode capabilities */
    188 	u_int16_t		ic_curmode;	/* current mode */
    189 	enum ieee80211_phytype	ic_phytype;	/* XXX wrong for multi-mode */
    190 	enum ieee80211_opmode	ic_opmode;	/* operation mode */
    191 	enum ieee80211_state	ic_state;	/* 802.11 state */
    192 	u_int32_t		ic_aid_bitmap[IEEE80211_MAX_AID / 32 + 1];
    193 	u_int16_t		ic_max_aid;
    194 	enum ieee80211_protmode	ic_protmode;	/* 802.11g protection mode */
    195 	struct ifmedia		ic_media;	/* interface media config */
    196 #ifdef __FreeBSD__
    197 	struct bpf_if		*ic_rawbpf;	/* packet filter structure */
    198 #else
    199 	caddr_t			ic_rawbpf;	/* packet filter structure */
    200 #endif
    201 	struct ieee80211_node	*ic_bss;	/* information for this node */
    202 	struct ieee80211_channel *ic_ibss_chan;
    203 	int			ic_fixed_rate;	/* index to ic_sup_rates[] */
    204 	u_int16_t		ic_rtsthreshold;
    205 	u_int16_t		ic_fragthreshold;
    206 #ifdef __FreeBSD__
    207 	struct mtx		ic_nodelock;	/* on node table */
    208 #endif
    209 	u_int			ic_scangen;	/* gen# for timeout scan */
    210 	struct ieee80211_node	*(*ic_node_alloc)(struct ieee80211com *);
    211 	void			(*ic_node_free)(struct ieee80211com *,
    212 					struct ieee80211_node *);
    213 	void			(*ic_node_copy)(struct ieee80211com *,
    214 					struct ieee80211_node *,
    215 					const struct ieee80211_node *);
    216 	u_int8_t		(*ic_node_getrssi)(struct ieee80211com *,
    217 					struct ieee80211_node *);
    218 	TAILQ_HEAD(, ieee80211_node) ic_node;	/* information of all nodes */
    219 	LIST_HEAD(, ieee80211_node) ic_hash[IEEE80211_NODE_HASHSIZE];
    220 	u_int16_t		ic_lintval;	/* listen interval */
    221 	u_int16_t		ic_holdover;	/* PM hold over duration */
    222 	u_int16_t		ic_txmin;	/* min tx retry count */
    223 	u_int16_t		ic_txmax;	/* max tx retry count */
    224 	u_int16_t		ic_txlifetime;	/* tx lifetime */
    225 	u_int16_t		ic_txpower;	/* tx power setting (dbM) */
    226 	u_int16_t		ic_bmisstimeout;/* beacon miss threshold (ms) */
    227 	int			ic_mgt_timer;	/* mgmt timeout */
    228 	int			ic_inact_timer;	/* inactivity timer wait */
    229 	int			ic_des_esslen;
    230 	u_int8_t		ic_des_essid[IEEE80211_NWID_LEN];
    231 	struct ieee80211_channel *ic_des_chan;	/* desired channel */
    232 	u_int8_t		ic_des_bssid[IEEE80211_ADDR_LEN];
    233 	struct ieee80211_wepkey	ic_nw_keys[IEEE80211_WEP_NKID];
    234 	int			ic_wep_txkey;	/* default tx key index */
    235 	void			*ic_wep_ctx;	/* wep crypt context */
    236 	u_int32_t		ic_iv;		/* initial vector for wep */
    237 	struct ieee80211_stats	ic_stats;	/* statistics */
    238 };
    239 #ifdef __NetBSD__
    240 #define	ic_if		ic_ec.ec_if
    241 #else
    242 #define	ic_if		ic_ac.ac_if
    243 #endif
    244 #define	ic_softc	ic_if.if_softc
    245 
    246 #define	IEEE80211_ADDR_EQ(a1,a2)	(memcmp(a1,a2,IEEE80211_ADDR_LEN) == 0)
    247 #define	IEEE80211_ADDR_COPY(dst,src)	memcpy(dst,src,IEEE80211_ADDR_LEN)
    248 
    249 /* ic_flags */
    250 #define	IEEE80211_F_ASCAN	0x00000001	/* STATUS: active scan */
    251 #define	IEEE80211_F_SIBSS	0x00000002	/* STATUS: start IBSS */
    252 #define	IEEE80211_F_WEPON	0x00000100	/* CONF: WEP enabled */
    253 #define	IEEE80211_F_IBSSON	0x00000200	/* CONF: IBSS creation enable */
    254 #define	IEEE80211_F_PMGTON	0x00000400	/* CONF: Power mgmt enable */
    255 #define	IEEE80211_F_DESBSSID	0x00000800	/* CONF: des_bssid is set */
    256 #define	IEEE80211_F_SCANAP	0x00001000	/* CONF: Scanning AP */
    257 #define	IEEE80211_F_ROAMING	0x00002000	/* CONF: roaming enabled */
    258 #define	IEEE80211_F_SWRETRY	0x00004000	/* CONF: sw tx retry enabled */
    259 #define	IEEE80211_F_TXPMGT	0x00018000	/* STATUS: tx power */
    260 #define IEEE80211_F_TXPOW_OFF	0x00000000	/* TX Power: radio disabled */
    261 #define IEEE80211_F_TXPOW_FIXED	0x00008000	/* TX Power: fixed rate */
    262 #define IEEE80211_F_TXPOW_AUTO	0x00010000	/* TX Power: undefined */
    263 #define	IEEE80211_F_SHSLOT	0x00020000	/* CONF: short slot time */
    264 #define	IEEE80211_F_SHPREAMBLE	0x00040000	/* CONF: short preamble */
    265 #define	IEEE80211_F_USEPROT	0x00100000	/* STATUS: protection enabled */
    266 #define	IEEE80211_F_USEBARKER	0x00200000	/* STATUS: use barker preamble*/
    267 
    268 /* ic_caps */
    269 #define	IEEE80211_C_WEP		0x00000001	/* CAPABILITY: WEP available */
    270 #define	IEEE80211_C_IBSS	0x00000002	/* CAPABILITY: IBSS available */
    271 #define	IEEE80211_C_PMGT	0x00000004	/* CAPABILITY: Power mgmt */
    272 #define	IEEE80211_C_HOSTAP	0x00000008	/* CAPABILITY: HOSTAP avail */
    273 #define	IEEE80211_C_AHDEMO	0x00000010	/* CAPABILITY: Old Adhoc Demo */
    274 #define	IEEE80211_C_SWRETRY	0x00000020	/* CAPABILITY: sw tx retry */
    275 #define	IEEE80211_C_TXPMGT	0x00000040	/* CAPABILITY: tx power mgmt */
    276 #define	IEEE80211_C_SHSLOT	0x00000080	/* CAPABILITY: short slottime */
    277 #define	IEEE80211_C_SHPREAMBLE	0x00000100	/* CAPABILITY: short preamble */
    278 #define	IEEE80211_C_MONITOR	0x00000200	/* CAPABILITY: monitor mode */
    279 
    280 /* flags for ieee80211_fix_rate() */
    281 #define	IEEE80211_F_DOSORT	0x00000001	/* sort rate list */
    282 #define	IEEE80211_F_DOFRATE	0x00000002	/* use fixed rate */
    283 #define	IEEE80211_F_DONEGO	0x00000004	/* calc negotiated rate */
    284 #define	IEEE80211_F_DODEL	0x00000008	/* delete ignore rate */
    285 
    286 void	ieee80211_ifattach(struct ifnet *);
    287 void	ieee80211_ifdetach(struct ifnet *);
    288 void	ieee80211_media_init(struct ifnet *, ifm_change_cb_t, ifm_stat_cb_t);
    289 int	ieee80211_media_change(struct ifnet *);
    290 void	ieee80211_media_status(struct ifnet *, struct ifmediareq *);
    291 int	ieee80211_ioctl(struct ifnet *, u_long, caddr_t);
    292 int	ieee80211_get_rate(struct ieee80211com *);
    293 int	ieee80211_cfgget(struct ifnet *, u_long, caddr_t);
    294 int	ieee80211_cfgset(struct ifnet *, u_long, caddr_t);
    295 void	ieee80211_watchdog(struct ifnet *);
    296 int	ieee80211_fix_rate(struct ieee80211com *, struct ieee80211_node *, int);
    297 int	ieee80211_rate2media(struct ieee80211com *, int,
    298 		enum ieee80211_phymode);
    299 int	ieee80211_media2rate(int);
    300 u_int	ieee80211_mhz2ieee(u_int, u_int);
    301 u_int	ieee80211_chan2ieee(struct ieee80211com *, struct ieee80211_channel *);
    302 u_int	ieee80211_ieee2mhz(u_int, u_int);
    303 int	ieee80211_setmode(struct ieee80211com *, enum ieee80211_phymode);
    304 enum ieee80211_phymode ieee80211_chan2mode(struct ieee80211com *,
    305 		struct ieee80211_channel *);
    306 
    307 #ifdef IEEE80211_DEBUG
    308 extern	int ieee80211_debug;
    309 #define	IEEE80211_DPRINTF(X)	if (ieee80211_debug) printf X
    310 #define	IEEE80211_DPRINTF2(X)	if (ieee80211_debug>1) printf X
    311 #else
    312 #define	IEEE80211_DPRINTF(X)
    313 #define	IEEE80211_DPRINTF2(X)
    314 #endif
    315 
    316 extern	int ieee80211_inact_max;
    317 
    318 #endif /* _NET80211_IEEE80211_VAR_H_ */
    319