ieee80211_var.h revision 117811
1116742Ssam/*-
2116904Ssam * Copyright (c) 2001 Atsushi Onoe
3116742Ssam * Copyright (c) 2002, 2003 Sam Leffler, Errno Consulting
4116742Ssam * All rights reserved.
5116742Ssam *
6116742Ssam * Redistribution and use in source and binary forms, with or without
7116742Ssam * modification, are permitted provided that the following conditions
8116742Ssam * are met:
9116742Ssam * 1. Redistributions of source code must retain the above copyright
10116742Ssam *    notice, this list of conditions and the following disclaimer.
11116742Ssam * 2. Redistributions in binary form must reproduce the above copyright
12116742Ssam *    notice, this list of conditions and the following disclaimer in the
13116742Ssam *    documentation and/or other materials provided with the distribution.
14116904Ssam * 3. The name of the author may not be used to endorse or promote products
15116904Ssam *    derived from this software without specific prior written permission.
16116742Ssam *
17116904Ssam * Alternatively, this software may be distributed under the terms of the
18116904Ssam * GNU General Public License ("GPL") version 2 as published by the Free
19116904Ssam * Software Foundation.
20116742Ssam *
21116904Ssam * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22116904Ssam * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23116904Ssam * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24116904Ssam * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25116904Ssam * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26116904Ssam * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27116904Ssam * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28116904Ssam * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29116904Ssam * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30116904Ssam * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31116904Ssam *
32116742Ssam * $FreeBSD: head/sys/net80211/ieee80211_var.h 117811 2003-07-20 21:36:08Z sam $
33116742Ssam */
34116742Ssam#ifndef _NET80211_IEEE80211_VAR_H_
35116742Ssam#define _NET80211_IEEE80211_VAR_H_
36116742Ssam
37116742Ssam/*
38116742Ssam * Definitions for IEEE 802.11 drivers.
39116742Ssam */
40116742Ssam
41116742Ssam#include <net80211/ieee80211.h>
42116742Ssam#include <net80211/ieee80211_crypto.h>
43116742Ssam#include <net80211/ieee80211_node.h>
44116742Ssam#include <net80211/ieee80211_proto.h>
45116742Ssam
46116742Ssam#define	IEEE80211_CHAN_MAX	255
47116742Ssam#define	IEEE80211_CHAN_ANY	0xffff		/* token for ``any channel'' */
48116742Ssam#define	IEEE80211_CHAN_ANYC \
49116742Ssam	((struct ieee80211_channel *) IEEE80211_CHAN_ANY)
50116742Ssam
51116742Ssamenum ieee80211_phytype {
52116742Ssam	IEEE80211_T_DS,			/* direct sequence spread spectrum */
53116742Ssam	IEEE80211_T_FH,			/* frequency hopping */
54116742Ssam	IEEE80211_T_OFDM,		/* frequency division multiplexing */
55116742Ssam	IEEE80211_T_TURBO,		/* high rate OFDM, aka turbo mode */
56116742Ssam};
57116742Ssam#define	IEEE80211_T_CCK	IEEE80211_T_DS	/* more common nomenclature */
58116742Ssam
59116742Ssam/* XXX not really a mode; there are really multiple PHY's */
60116742Ssamenum ieee80211_phymode {
61116742Ssam	IEEE80211_MODE_AUTO	= 0,	/* autoselect */
62116742Ssam	IEEE80211_MODE_11A	= 1,	/* 5GHz, OFDM */
63116742Ssam	IEEE80211_MODE_11B	= 2,	/* 2GHz, CCK */
64116742Ssam	IEEE80211_MODE_11G	= 3,	/* 2GHz, OFDM */
65116742Ssam	IEEE80211_MODE_TURBO	= 4,	/* 5GHz, OFDM, 2x clock */
66116742Ssam};
67116742Ssam#define	IEEE80211_MODE_MAX	(IEEE80211_MODE_TURBO+1)
68116742Ssam
69116742Ssamenum ieee80211_opmode {
70116742Ssam	IEEE80211_M_STA		= 1,	/* infrastructure station */
71116742Ssam	IEEE80211_M_IBSS 	= 0,	/* IBSS (adhoc) station */
72116742Ssam	IEEE80211_M_AHDEMO	= 3,	/* Old lucent compatible adhoc demo */
73116742Ssam	IEEE80211_M_HOSTAP	= 6	/* Software Access Point */
74116742Ssam};
75116742Ssam
76116742Ssam/*
77116742Ssam * Channels are specified by frequency and attributes.
78116742Ssam */
79116742Ssamstruct ieee80211_channel {
80116742Ssam	u_int16_t	ic_freq;	/* setting in Mhz */
81116742Ssam	u_int16_t	ic_flags;	/* see below */
82116742Ssam};
83116742Ssam
84116742Ssam/* bits 0-3 are for private use by drivers */
85116742Ssam/* channel attributes */
86116742Ssam#define	IEEE80211_CHAN_TURBO	0x0010	/* Turbo channel */
87116742Ssam#define	IEEE80211_CHAN_CCK	0x0020	/* CCK channel */
88116742Ssam#define	IEEE80211_CHAN_OFDM	0x0040	/* OFDM channel */
89116742Ssam#define	IEEE80211_CHAN_2GHZ	0x0080	/* 2 GHz spectrum channel. */
90116742Ssam#define	IEEE80211_CHAN_5GHZ	0x0100	/* 5 GHz spectrum channel */
91116742Ssam#define	IEEE80211_CHAN_PASSIVE	0x0200	/* Only passive scan allowed */
92116742Ssam#define	IEEE80211_CHAN_DYN	0x0400	/* Dynamic CCK-OFDM channel */
93116742Ssam
94116742Ssam/*
95116742Ssam * Useful combinations of channel characteristics.
96116742Ssam */
97116742Ssam#define	IEEE80211_CHAN_A \
98116742Ssam	(IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_OFDM)
99116742Ssam#define	IEEE80211_CHAN_B \
100116742Ssam	(IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_CCK)
101116742Ssam#define	IEEE80211_CHAN_PUREG \
102116742Ssam	(IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_OFDM)
103116742Ssam#define	IEEE80211_CHAN_G \
104116742Ssam	(IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_DYN)
105116742Ssam#define	IEEE80211_CHAN_T \
106116742Ssam	(IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_OFDM | IEEE80211_CHAN_TURBO)
107116742Ssam
108116742Ssam#define	IEEE80211_IS_CHAN_A(_c) \
109116742Ssam	(((_c)->ic_flags & IEEE80211_CHAN_A) == IEEE80211_CHAN_A)
110116742Ssam#define	IEEE80211_IS_CHAN_B(_c) \
111116742Ssam	(((_c)->ic_flags & IEEE80211_CHAN_B) == IEEE80211_CHAN_B)
112116742Ssam#define	IEEE80211_IS_CHAN_PUREG(_c) \
113116742Ssam	(((_c)->ic_flags & IEEE80211_CHAN_PUREG) == IEEE80211_CHAN_PUREG)
114116742Ssam#define	IEEE80211_IS_CHAN_G(_c) \
115116742Ssam	(((_c)->ic_flags & IEEE80211_CHAN_G) == IEEE80211_CHAN_G)
116116742Ssam#define	IEEE80211_IS_CHAN_T(_c) \
117116742Ssam	(((_c)->ic_flags & IEEE80211_CHAN_T) == IEEE80211_CHAN_T)
118116742Ssam
119116742Ssam#define	IEEE80211_IS_CHAN_2GHZ(_c) \
120116742Ssam	(((_c)->ic_flags & IEEE80211_CHAN_2GHZ) != 0)
121116742Ssam#define	IEEE80211_IS_CHAN_5GHZ(_c) \
122116742Ssam	(((_c)->ic_flags & IEEE80211_CHAN_5GHZ) != 0)
123116742Ssam#define	IEEE80211_IS_CHAN_OFDM(_c) \
124116742Ssam	(((_c)->ic_flags & IEEE80211_CHAN_OFDM) != 0)
125116742Ssam#define	IEEE80211_IS_CHAN_CCK(_c) \
126116742Ssam	(((_c)->ic_flags & IEEE80211_CHAN_CCK) != 0)
127116742Ssam
128116742Ssam/* ni_chan encoding for FH phy */
129116742Ssam#define	IEEE80211_FH_CHANMOD	80
130116742Ssam#define	IEEE80211_FH_CHAN(set,pat)	(((set)-1)*IEEE80211_FH_CHANMOD+(pat))
131116742Ssam#define	IEEE80211_FH_CHANSET(chan)	((chan)/IEEE80211_FH_CHANMOD+1)
132116742Ssam#define	IEEE80211_FH_CHANPAT(chan)	((chan)%IEEE80211_FH_CHANMOD)
133116742Ssam
134116742Ssamstruct ieee80211com {
135116742Ssam	struct arpcom		ic_ac;
136116742Ssam	void			(*ic_recv_mgmt)(struct ieee80211com *,
137116742Ssam				    struct mbuf *, int, int, u_int32_t, u_int);
138116742Ssam	int			(*ic_send_mgmt)(struct ieee80211com *,
139116742Ssam				    struct ieee80211_node *, int, int);
140117811Ssam	int			(*ic_newstate)(struct ieee80211com *,
141117811Ssam				    enum ieee80211_state, int);
142116742Ssam	void			(*ic_newassoc)(struct ieee80211com *,
143116742Ssam				    struct ieee80211_node *, int);
144116742Ssam	u_int8_t		ic_myaddr[IEEE80211_ADDR_LEN];
145116742Ssam	struct ieee80211_rateset ic_sup_rates[IEEE80211_MODE_MAX];
146116742Ssam	struct ieee80211_channel ic_channels[IEEE80211_CHAN_MAX+1];
147116742Ssam	u_char			ic_chan_avail[roundup(IEEE80211_CHAN_MAX,NBBY)];
148116742Ssam	u_char			ic_chan_active[roundup(IEEE80211_CHAN_MAX, NBBY)];
149116742Ssam	u_char			ic_chan_scan[roundup(IEEE80211_CHAN_MAX,NBBY)];
150116742Ssam	struct ifqueue		ic_mgtq;
151116742Ssam	u_int32_t		ic_flags;	/* state flags */
152116742Ssam	u_int32_t		ic_caps;	/* capabilities */
153116742Ssam	u_int16_t		ic_modecaps;	/* set of mode capabilities */
154116742Ssam	u_int16_t		ic_curmode;	/* current mode */
155116742Ssam	enum ieee80211_phytype	ic_phytype;	/* XXX wrong for multi-mode */
156116742Ssam	enum ieee80211_opmode	ic_opmode;	/* operation mode */
157116742Ssam	enum ieee80211_state	ic_state;	/* 802.11 state */
158116742Ssam	struct ifmedia		ic_media;	/* interface media config */
159116742Ssam	struct bpf_if		*ic_rawbpf;	/* packet filter structure */
160116742Ssam	struct ieee80211_node	*ic_bss;	/* information for this node */
161116742Ssam	struct ieee80211_channel *ic_ibss_chan;
162116742Ssam	int			ic_fixed_rate;	/* index to ic_sup_rates[] */
163116742Ssam	u_int16_t		ic_rtsthreshold;
164116742Ssam	u_int16_t		ic_fragthreshold;
165116742Ssam	struct mtx		ic_nodelock;	/* on node table */
166116742Ssam	struct ieee80211_node	*(*ic_node_alloc)(struct ieee80211com *);
167116742Ssam	void			(*ic_node_free)(struct ieee80211com *,
168116742Ssam					struct ieee80211_node *);
169116742Ssam	void			(*ic_node_copy)(struct ieee80211com *,
170116742Ssam					struct ieee80211_node *,
171116742Ssam					const struct ieee80211_node *);
172116742Ssam	TAILQ_HEAD(, ieee80211_node) ic_node;	/* information of all nodes */
173116742Ssam	LIST_HEAD(, ieee80211_node) ic_hash[IEEE80211_NODE_HASHSIZE];
174116742Ssam	u_int16_t		ic_lintval;	/* listen interval */
175116742Ssam	u_int16_t		ic_holdover;	/* PM hold over duration */
176116742Ssam	u_int16_t		ic_txmin;	/* min tx retry count */
177116742Ssam	u_int16_t		ic_txmax;	/* max tx retry count */
178116742Ssam	u_int16_t		ic_txlifetime;	/* tx lifetime */
179116742Ssam	u_int16_t		ic_txpower;	/* tx power setting (dbM) */
180116742Ssam	u_int16_t		ic_bmisstimeout;/* beacon miss threshold (ms) */
181116742Ssam	int			ic_mgt_timer;	/* mgmt timeout */
182116742Ssam	int			ic_inact_timer;	/* inactivity timer wait */
183116742Ssam	int			ic_des_esslen;
184116742Ssam	u_int8_t		ic_des_essid[IEEE80211_NWID_LEN];
185116742Ssam	struct ieee80211_channel *ic_des_chan;	/* desired channel */
186116742Ssam	u_int8_t		ic_des_bssid[IEEE80211_ADDR_LEN];
187116742Ssam	struct ieee80211_wepkey	ic_nw_keys[IEEE80211_WEP_NKID];
188116742Ssam	int			ic_wep_txkey;	/* default tx key index */
189116742Ssam	void			*ic_wep_ctx;	/* wep crypt context */
190116742Ssam	u_int32_t		ic_iv;		/* initial vector for wep */
191116742Ssam};
192116742Ssam#define	ic_if		ic_ac.ac_if
193116742Ssam#define	ic_softc	ic_if.if_softc
194116742Ssam
195116742Ssam#define	IEEE80211_ADDR_EQ(a1,a2)	(memcmp(a1,a2,IEEE80211_ADDR_LEN) == 0)
196116742Ssam#define	IEEE80211_ADDR_COPY(dst,src)	memcpy(dst,src,IEEE80211_ADDR_LEN)
197116742Ssam
198116742Ssam/* ic_flags */
199116742Ssam#define	IEEE80211_F_ASCAN	0x00000001	/* STATUS: active scan */
200116742Ssam#define	IEEE80211_F_SIBSS	0x00000002	/* STATUS: start IBSS */
201116742Ssam#define	IEEE80211_F_WEPON	0x00000100	/* CONF: WEP enabled */
202116742Ssam#define	IEEE80211_F_IBSSON	0x00000200	/* CONF: IBSS creation enable */
203116742Ssam#define	IEEE80211_F_PMGTON	0x00000400	/* CONF: Power mgmt enable */
204116742Ssam#define	IEEE80211_F_DESBSSID	0x00000800	/* CONF: des_bssid is set */
205116742Ssam#define	IEEE80211_F_SCANAP	0x00001000	/* CONF: Scanning AP */
206116742Ssam#define	IEEE80211_F_ROAMING	0x00002000	/* CONF: roaming enabled */
207116742Ssam#define	IEEE80211_F_SWRETRY	0x00004000	/* CONF: sw tx retry enabled */
208116742Ssam#define	IEEE80211_F_TXPMGT	0x00018000	/* STATUS: tx power */
209116742Ssam#define IEEE80211_F_TXPOW_OFF	0x00000000	/* TX Power: radio disabled */
210116742Ssam#define IEEE80211_F_TXPOW_FIXED	0x00008000	/* TX Power: fixed rate */
211116742Ssam#define IEEE80211_F_TXPOW_AUTO	0x00010000	/* TX Power: undefined */
212116742Ssam#define	IEEE80211_F_SHSLOT	0x00020000	/* CONF: short slot time */
213116742Ssam#define	IEEE80211_F_SHPREAMBLE	0x00040000	/* CONF: short preamble */
214116742Ssam
215116742Ssam/* ic_capabilities */
216116742Ssam#define	IEEE80211_C_WEP		0x00000001	/* CAPABILITY: WEP available */
217116742Ssam#define	IEEE80211_C_IBSS	0x00000002	/* CAPABILITY: IBSS available */
218116742Ssam#define	IEEE80211_C_PMGT	0x00000004	/* CAPABILITY: Power mgmt */
219116742Ssam#define	IEEE80211_C_HOSTAP	0x00000008	/* CAPABILITY: HOSTAP avail */
220116742Ssam#define	IEEE80211_C_AHDEMO	0x00000010	/* CAPABILITY: Old Adhoc Demo */
221116742Ssam#define	IEEE80211_C_SWRETRY	0x00000020	/* CAPABILITY: sw tx retry */
222116742Ssam#define	IEEE80211_C_TXPMGT	0x00000040	/* CAPABILITY: tx power mgmt */
223116742Ssam#define	IEEE80211_C_SHSLOT	0x00000080	/* CAPABILITY: short slottime */
224116742Ssam#define	IEEE80211_C_SHPREAMBLE	0x00000100	/* CAPABILITY: short preamble */
225116742Ssam
226116742Ssam/* flags for ieee80211_fix_rate() */
227116742Ssam#define	IEEE80211_F_DOSORT	0x00000001	/* sort rate list */
228116742Ssam#define	IEEE80211_F_DOFRATE	0x00000002	/* use fixed rate */
229116742Ssam#define	IEEE80211_F_DONEGO	0x00000004	/* calc negotiated rate */
230116742Ssam#define	IEEE80211_F_DODEL	0x00000008	/* delete ignore rate */
231116742Ssam
232116742Ssamvoid	ieee80211_ifattach(struct ifnet *);
233116742Ssamvoid	ieee80211_ifdetach(struct ifnet *);
234116742Ssamvoid	ieee80211_media_init(struct ifnet *, ifm_change_cb_t, ifm_stat_cb_t);
235116742Ssamint	ieee80211_media_change(struct ifnet *);
236116742Ssamvoid	ieee80211_media_status(struct ifnet *, struct ifmediareq *);
237116742Ssamint	ieee80211_ioctl(struct ifnet *, u_long, caddr_t);
238116742Ssamint	ieee80211_cfgget(struct ifnet *, u_long, caddr_t);
239116742Ssamint	ieee80211_cfgset(struct ifnet *, u_long, caddr_t);
240116742Ssamvoid	ieee80211_watchdog(struct ifnet *);
241116742Ssamint	ieee80211_fix_rate(struct ieee80211com *, struct ieee80211_node *, int);
242116742Ssamint	ieee80211_rate2media(struct ieee80211com *, int,
243116742Ssam		enum ieee80211_phymode);
244116742Ssamint	ieee80211_media2rate(int);
245116742Ssamu_int	ieee80211_mhz2ieee(u_int, u_int);
246116742Ssamu_int	ieee80211_chan2ieee(struct ieee80211com *, struct ieee80211_channel *);
247116742Ssamu_int	ieee80211_ieee2mhz(u_int, u_int);
248116742Ssamint	ieee80211_setmode(struct ieee80211com *, enum ieee80211_phymode);
249116742Ssamenum ieee80211_phymode ieee80211_chan2mode(struct ieee80211com *,
250116742Ssam		struct ieee80211_channel *);
251116742Ssam
252116742Ssam#define	IEEE80211_DEBUG
253116742Ssam#ifdef IEEE80211_DEBUG
254116742Ssamextern	int ieee80211_debug;
255116742Ssam#define	IEEE80211_DPRINTF(X)	if (ieee80211_debug) printf X
256116742Ssam#define	IEEE80211_DPRINTF2(X)	if (ieee80211_debug>1) printf X
257116742Ssam#else
258116742Ssam#define	IEEE80211_DPRINTF(X)
259116742Ssam#define	IEEE80211_DPRINTF2(X)
260116742Ssam#endif
261116742Ssam
262116742Ssam#endif /* _NET80211_IEEE80211_VAR_H_ */
263