Home | History | Annotate | Line # | Download | only in net80211
ieee80211_var.h revision 1.2
      1 /*-
      2  * Copyright (c) 2001 Atsushi Onoe
      3  * Copyright (c) 2002, 2003 Sam Leffler, Errno Consulting
      4  * All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. The name of the author may not be used to endorse or promote products
     15  *    derived from this software without specific prior written permission.
     16  *
     17  * Alternatively, this software may be distributed under the terms of the
     18  * GNU General Public License ("GPL") version 2 as published by the Free
     19  * Software Foundation.
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  *
     32  * $FreeBSD: src/sys/net80211/ieee80211_var.h,v 1.5 2003/08/19 22:17:03 sam Exp $
     33  */
     34 #ifndef _NET80211_IEEE80211_VAR_H_
     35 #define _NET80211_IEEE80211_VAR_H_
     36 
     37 /*
     38  * Definitions for IEEE 802.11 drivers.
     39  */
     40 
     41 #include <net80211/ieee80211.h>
     42 #include <net80211/ieee80211_crypto.h>
     43 #include <net80211/ieee80211_node.h>
     44 #include <net80211/ieee80211_proto.h>
     45 
     46 #define	IEEE80211_CHAN_MAX	255
     47 #define	IEEE80211_CHAN_ANY	0xffff		/* token for ``any channel'' */
     48 #define	IEEE80211_CHAN_ANYC \
     49 	((struct ieee80211_channel *) IEEE80211_CHAN_ANY)
     50 
     51 enum ieee80211_phytype {
     52 	IEEE80211_T_DS,			/* direct sequence spread spectrum */
     53 	IEEE80211_T_FH,			/* frequency hopping */
     54 	IEEE80211_T_OFDM,		/* frequency division multiplexing */
     55 	IEEE80211_T_TURBO,		/* high rate OFDM, aka turbo mode */
     56 };
     57 #define	IEEE80211_T_CCK	IEEE80211_T_DS	/* more common nomenclature */
     58 
     59 /* XXX not really a mode; there are really multiple PHY's */
     60 enum ieee80211_phymode {
     61 	IEEE80211_MODE_AUTO	= 0,	/* autoselect */
     62 	IEEE80211_MODE_11A	= 1,	/* 5GHz, OFDM */
     63 	IEEE80211_MODE_11B	= 2,	/* 2GHz, CCK */
     64 	IEEE80211_MODE_11G	= 3,	/* 2GHz, OFDM */
     65 	IEEE80211_MODE_TURBO	= 4,	/* 5GHz, OFDM, 2x clock */
     66 };
     67 #define	IEEE80211_MODE_MAX	(IEEE80211_MODE_TURBO+1)
     68 
     69 enum ieee80211_opmode {
     70 	IEEE80211_M_STA		= 1,	/* infrastructure station */
     71 	IEEE80211_M_IBSS 	= 0,	/* IBSS (adhoc) station */
     72 	IEEE80211_M_AHDEMO	= 3,	/* Old lucent compatible adhoc demo */
     73 	IEEE80211_M_HOSTAP	= 6,	/* Software Access Point */
     74 	IEEE80211_M_MONITOR	= 8	/* Monitor mode */
     75 };
     76 
     77 /*
     78  * Channels are specified by frequency and attributes.
     79  */
     80 struct ieee80211_channel {
     81 	u_int16_t	ic_freq;	/* setting in Mhz */
     82 	u_int16_t	ic_flags;	/* see below */
     83 };
     84 
     85 /* bits 0-3 are for private use by drivers */
     86 /* channel attributes */
     87 #define	IEEE80211_CHAN_TURBO	0x0010	/* Turbo channel */
     88 #define	IEEE80211_CHAN_CCK	0x0020	/* CCK channel */
     89 #define	IEEE80211_CHAN_OFDM	0x0040	/* OFDM channel */
     90 #define	IEEE80211_CHAN_2GHZ	0x0080	/* 2 GHz spectrum channel. */
     91 #define	IEEE80211_CHAN_5GHZ	0x0100	/* 5 GHz spectrum channel */
     92 #define	IEEE80211_CHAN_PASSIVE	0x0200	/* Only passive scan allowed */
     93 #define	IEEE80211_CHAN_DYN	0x0400	/* Dynamic CCK-OFDM channel */
     94 
     95 /*
     96  * Useful combinations of channel characteristics.
     97  */
     98 #define	IEEE80211_CHAN_A \
     99 	(IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_OFDM)
    100 #define	IEEE80211_CHAN_B \
    101 	(IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_CCK)
    102 #define	IEEE80211_CHAN_PUREG \
    103 	(IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_OFDM)
    104 #define	IEEE80211_CHAN_G \
    105 	(IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_DYN)
    106 #define	IEEE80211_CHAN_T \
    107 	(IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_OFDM | IEEE80211_CHAN_TURBO)
    108 
    109 #define	IEEE80211_IS_CHAN_A(_c) \
    110 	(((_c)->ic_flags & IEEE80211_CHAN_A) == IEEE80211_CHAN_A)
    111 #define	IEEE80211_IS_CHAN_B(_c) \
    112 	(((_c)->ic_flags & IEEE80211_CHAN_B) == IEEE80211_CHAN_B)
    113 #define	IEEE80211_IS_CHAN_PUREG(_c) \
    114 	(((_c)->ic_flags & IEEE80211_CHAN_PUREG) == IEEE80211_CHAN_PUREG)
    115 #define	IEEE80211_IS_CHAN_G(_c) \
    116 	(((_c)->ic_flags & IEEE80211_CHAN_G) == IEEE80211_CHAN_G)
    117 #define	IEEE80211_IS_CHAN_T(_c) \
    118 	(((_c)->ic_flags & IEEE80211_CHAN_T) == IEEE80211_CHAN_T)
    119 
    120 #define	IEEE80211_IS_CHAN_2GHZ(_c) \
    121 	(((_c)->ic_flags & IEEE80211_CHAN_2GHZ) != 0)
    122 #define	IEEE80211_IS_CHAN_5GHZ(_c) \
    123 	(((_c)->ic_flags & IEEE80211_CHAN_5GHZ) != 0)
    124 #define	IEEE80211_IS_CHAN_OFDM(_c) \
    125 	(((_c)->ic_flags & IEEE80211_CHAN_OFDM) != 0)
    126 #define	IEEE80211_IS_CHAN_CCK(_c) \
    127 	(((_c)->ic_flags & IEEE80211_CHAN_CCK) != 0)
    128 
    129 /* ni_chan encoding for FH phy */
    130 #define	IEEE80211_FH_CHANMOD	80
    131 #define	IEEE80211_FH_CHAN(set,pat)	(((set)-1)*IEEE80211_FH_CHANMOD+(pat))
    132 #define	IEEE80211_FH_CHANSET(chan)	((chan)/IEEE80211_FH_CHANMOD+1)
    133 #define	IEEE80211_FH_CHANPAT(chan)	((chan)%IEEE80211_FH_CHANMOD)
    134 
    135 struct ieee80211com {
    136 #ifdef __NetBSD__
    137 	struct ethercom		ic_ec;
    138 #else
    139 	struct arpcom		ic_ac;
    140 #endif
    141 	void			(*ic_recv_mgmt)(struct ieee80211com *,
    142 				    struct mbuf *, struct ieee80211_node *,
    143 				    int, int, u_int32_t);
    144 	int			(*ic_send_mgmt)(struct ieee80211com *,
    145 				    struct ieee80211_node *, int, int);
    146 	int			(*ic_newstate)(struct ieee80211com *,
    147 				    enum ieee80211_state, int);
    148 	void			(*ic_newassoc)(struct ieee80211com *,
    149 				    struct ieee80211_node *, int);
    150 	u_int8_t		ic_myaddr[IEEE80211_ADDR_LEN];
    151 	struct ieee80211_rateset ic_sup_rates[IEEE80211_MODE_MAX];
    152 	struct ieee80211_channel ic_channels[IEEE80211_CHAN_MAX+1];
    153 	u_char			ic_chan_avail[roundup(IEEE80211_CHAN_MAX,NBBY)];
    154 	u_char			ic_chan_active[roundup(IEEE80211_CHAN_MAX, NBBY)];
    155 	u_char			ic_chan_scan[roundup(IEEE80211_CHAN_MAX,NBBY)];
    156 	struct ifqueue		ic_mgtq;
    157 	u_int32_t		ic_flags;	/* state flags */
    158 	u_int32_t		ic_caps;	/* capabilities */
    159 	u_int16_t		ic_modecaps;	/* set of mode capabilities */
    160 	u_int16_t		ic_curmode;	/* current mode */
    161 	enum ieee80211_phytype	ic_phytype;	/* XXX wrong for multi-mode */
    162 	enum ieee80211_opmode	ic_opmode;	/* operation mode */
    163 	enum ieee80211_state	ic_state;	/* 802.11 state */
    164 	struct ifmedia		ic_media;	/* interface media config */
    165 #ifdef __FreeBSD__
    166 	struct bpf_if		*ic_rawbpf;	/* packet filter structure */
    167 #else
    168 	caddr_t			ic_rawbpf;	/* packet filter structure */
    169 #endif
    170 	struct ieee80211_node	*ic_bss;	/* information for this node */
    171 	struct ieee80211_channel *ic_ibss_chan;
    172 	int			ic_fixed_rate;	/* index to ic_sup_rates[] */
    173 	u_int16_t		ic_rtsthreshold;
    174 	u_int16_t		ic_fragthreshold;
    175 #ifdef __FreeBSD__
    176 	struct mtx		ic_nodelock;	/* on node table */
    177 #endif
    178 	struct ieee80211_node	*(*ic_node_alloc)(struct ieee80211com *);
    179 	void			(*ic_node_free)(struct ieee80211com *,
    180 					struct ieee80211_node *);
    181 	void			(*ic_node_copy)(struct ieee80211com *,
    182 					struct ieee80211_node *,
    183 					const struct ieee80211_node *);
    184 	TAILQ_HEAD(, ieee80211_node) ic_node;	/* information of all nodes */
    185 	LIST_HEAD(, ieee80211_node) ic_hash[IEEE80211_NODE_HASHSIZE];
    186 	u_int16_t		ic_lintval;	/* listen interval */
    187 	u_int16_t		ic_holdover;	/* PM hold over duration */
    188 	u_int16_t		ic_txmin;	/* min tx retry count */
    189 	u_int16_t		ic_txmax;	/* max tx retry count */
    190 	u_int16_t		ic_txlifetime;	/* tx lifetime */
    191 	u_int16_t		ic_txpower;	/* tx power setting (dbM) */
    192 	u_int16_t		ic_bmisstimeout;/* beacon miss threshold (ms) */
    193 	int			ic_mgt_timer;	/* mgmt timeout */
    194 	int			ic_inact_timer;	/* inactivity timer wait */
    195 	int			ic_des_esslen;
    196 	u_int8_t		ic_des_essid[IEEE80211_NWID_LEN];
    197 	struct ieee80211_channel *ic_des_chan;	/* desired channel */
    198 	u_int8_t		ic_des_bssid[IEEE80211_ADDR_LEN];
    199 	struct ieee80211_wepkey	ic_nw_keys[IEEE80211_WEP_NKID];
    200 	int			ic_wep_txkey;	/* default tx key index */
    201 	void			*ic_wep_ctx;	/* wep crypt context */
    202 	u_int32_t		ic_iv;		/* initial vector for wep */
    203 };
    204 #ifdef __NetBSD__
    205 #define	ic_if		ic_ec.ec_if
    206 #else
    207 #define	ic_if		ic_ac.ac_if
    208 #endif
    209 #define	ic_softc	ic_if.if_softc
    210 
    211 #define	IEEE80211_ADDR_EQ(a1,a2)	(memcmp(a1,a2,IEEE80211_ADDR_LEN) == 0)
    212 #define	IEEE80211_ADDR_COPY(dst,src)	memcpy(dst,src,IEEE80211_ADDR_LEN)
    213 
    214 /* ic_flags */
    215 #define	IEEE80211_F_ASCAN	0x00000001	/* STATUS: active scan */
    216 #define	IEEE80211_F_SIBSS	0x00000002	/* STATUS: start IBSS */
    217 #define	IEEE80211_F_WEPON	0x00000100	/* CONF: WEP enabled */
    218 #define	IEEE80211_F_IBSSON	0x00000200	/* CONF: IBSS creation enable */
    219 #define	IEEE80211_F_PMGTON	0x00000400	/* CONF: Power mgmt enable */
    220 #define	IEEE80211_F_DESBSSID	0x00000800	/* CONF: des_bssid is set */
    221 #define	IEEE80211_F_SCANAP	0x00001000	/* CONF: Scanning AP */
    222 #define	IEEE80211_F_ROAMING	0x00002000	/* CONF: roaming enabled */
    223 #define	IEEE80211_F_SWRETRY	0x00004000	/* CONF: sw tx retry enabled */
    224 #define	IEEE80211_F_TXPMGT	0x00018000	/* STATUS: tx power */
    225 #define IEEE80211_F_TXPOW_OFF	0x00000000	/* TX Power: radio disabled */
    226 #define IEEE80211_F_TXPOW_FIXED	0x00008000	/* TX Power: fixed rate */
    227 #define IEEE80211_F_TXPOW_AUTO	0x00010000	/* TX Power: undefined */
    228 #define	IEEE80211_F_SHSLOT	0x00020000	/* CONF: short slot time */
    229 #define	IEEE80211_F_SHPREAMBLE	0x00040000	/* CONF: short preamble */
    230 
    231 /* ic_capabilities */
    232 #define	IEEE80211_C_WEP		0x00000001	/* CAPABILITY: WEP available */
    233 #define	IEEE80211_C_IBSS	0x00000002	/* CAPABILITY: IBSS available */
    234 #define	IEEE80211_C_PMGT	0x00000004	/* CAPABILITY: Power mgmt */
    235 #define	IEEE80211_C_HOSTAP	0x00000008	/* CAPABILITY: HOSTAP avail */
    236 #define	IEEE80211_C_AHDEMO	0x00000010	/* CAPABILITY: Old Adhoc Demo */
    237 #define	IEEE80211_C_SWRETRY	0x00000020	/* CAPABILITY: sw tx retry */
    238 #define	IEEE80211_C_TXPMGT	0x00000040	/* CAPABILITY: tx power mgmt */
    239 #define	IEEE80211_C_SHSLOT	0x00000080	/* CAPABILITY: short slottime */
    240 #define	IEEE80211_C_SHPREAMBLE	0x00000100	/* CAPABILITY: short preamble */
    241 #define	IEEE80211_C_MONITOR	0x00000200	/* CAPABILITY: monitor mode */
    242 
    243 /* flags for ieee80211_fix_rate() */
    244 #define	IEEE80211_F_DOSORT	0x00000001	/* sort rate list */
    245 #define	IEEE80211_F_DOFRATE	0x00000002	/* use fixed rate */
    246 #define	IEEE80211_F_DONEGO	0x00000004	/* calc negotiated rate */
    247 #define	IEEE80211_F_DODEL	0x00000008	/* delete ignore rate */
    248 
    249 void	ieee80211_ifattach(struct ifnet *);
    250 void	ieee80211_ifdetach(struct ifnet *);
    251 void	ieee80211_media_init(struct ifnet *, ifm_change_cb_t, ifm_stat_cb_t);
    252 int	ieee80211_media_change(struct ifnet *);
    253 void	ieee80211_media_status(struct ifnet *, struct ifmediareq *);
    254 int	ieee80211_ioctl(struct ifnet *, u_long, caddr_t);
    255 int	ieee80211_cfgget(struct ifnet *, u_long, caddr_t);
    256 int	ieee80211_cfgset(struct ifnet *, u_long, caddr_t);
    257 void	ieee80211_watchdog(struct ifnet *);
    258 int	ieee80211_fix_rate(struct ieee80211com *, struct ieee80211_node *, int);
    259 int	ieee80211_rate2media(struct ieee80211com *, int,
    260 		enum ieee80211_phymode);
    261 int	ieee80211_media2rate(int);
    262 u_int	ieee80211_mhz2ieee(u_int, u_int);
    263 u_int	ieee80211_chan2ieee(struct ieee80211com *, struct ieee80211_channel *);
    264 u_int	ieee80211_ieee2mhz(u_int, u_int);
    265 int	ieee80211_setmode(struct ieee80211com *, enum ieee80211_phymode);
    266 enum ieee80211_phymode ieee80211_chan2mode(struct ieee80211com *,
    267 		struct ieee80211_channel *);
    268 
    269 #define	IEEE80211_DEBUG
    270 #ifdef IEEE80211_DEBUG
    271 extern	int ieee80211_debug;
    272 #define	IEEE80211_DPRINTF(X)	if (ieee80211_debug) printf X
    273 #define	IEEE80211_DPRINTF2(X)	if (ieee80211_debug>1) printf X
    274 #else
    275 #define	IEEE80211_DPRINTF(X)
    276 #define	IEEE80211_DPRINTF2(X)
    277 #endif
    278 
    279 #endif /* _NET80211_IEEE80211_VAR_H_ */
    280