xref: /dflybsd-src/sys/netproto/802_11/ieee80211_var.h (revision 294727bf61ff113c99d212fd917091e69cb15a8c)
132176cfdSRui Paulo /*-
2f186073cSJoerg Sonnenberger  * Copyright (c) 2001 Atsushi Onoe
332176cfdSRui Paulo  * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
4f186073cSJoerg Sonnenberger  * All rights reserved.
5f186073cSJoerg Sonnenberger  *
6f186073cSJoerg Sonnenberger  * Redistribution and use in source and binary forms, with or without
7f186073cSJoerg Sonnenberger  * modification, are permitted provided that the following conditions
8f186073cSJoerg Sonnenberger  * are met:
9f186073cSJoerg Sonnenberger  * 1. Redistributions of source code must retain the above copyright
10f186073cSJoerg Sonnenberger  *    notice, this list of conditions and the following disclaimer.
11f186073cSJoerg Sonnenberger  * 2. Redistributions in binary form must reproduce the above copyright
12f186073cSJoerg Sonnenberger  *    notice, this list of conditions and the following disclaimer in the
13f186073cSJoerg Sonnenberger  *    documentation and/or other materials provided with the distribution.
14f186073cSJoerg Sonnenberger  *
15f186073cSJoerg Sonnenberger  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16f186073cSJoerg Sonnenberger  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17f186073cSJoerg Sonnenberger  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18f186073cSJoerg Sonnenberger  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19f186073cSJoerg Sonnenberger  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20f186073cSJoerg Sonnenberger  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21f186073cSJoerg Sonnenberger  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22f186073cSJoerg Sonnenberger  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23f186073cSJoerg Sonnenberger  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24f186073cSJoerg Sonnenberger  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25f186073cSJoerg Sonnenberger  *
26085ff963SMatthew Dillon  * $FreeBSD$
27f186073cSJoerg Sonnenberger  */
28841ab66cSSepherosa Ziehau #ifndef _NET80211_IEEE80211_VAR_H_
29841ab66cSSepherosa Ziehau #define _NET80211_IEEE80211_VAR_H_
30f186073cSJoerg Sonnenberger 
31f186073cSJoerg Sonnenberger /*
32f186073cSJoerg Sonnenberger  * Definitions for IEEE 802.11 drivers.
33f186073cSJoerg Sonnenberger  */
34841ab66cSSepherosa Ziehau /* NB: portability glue must go first */
3532176cfdSRui Paulo #if defined(__NetBSD__)
36085ff963SMatthew Dillon #include <netproto/802_11/ieee80211_netbsd.h>
3732176cfdSRui Paulo #elif defined(__FreeBSD__)
38085ff963SMatthew Dillon #include <netproto/802_11/ieee80211_freebsd.h>
3932176cfdSRui Paulo #elif defined(__DragonFly__)
40841ab66cSSepherosa Ziehau #include <netproto/802_11/ieee80211_dragonfly.h>
41085ff963SMatthew Dillon #elif defined(__linux__)
42085ff963SMatthew Dillon #include <netproto/802_11/ieee80211_linux.h>
43841ab66cSSepherosa Ziehau #else
44841ab66cSSepherosa Ziehau #error	"No support for your operating system!"
45841ab66cSSepherosa Ziehau #endif
46841ab66cSSepherosa Ziehau 
47841ab66cSSepherosa Ziehau #include <netproto/802_11/_ieee80211.h>
48f186073cSJoerg Sonnenberger #include <netproto/802_11/ieee80211.h>
4932176cfdSRui Paulo #include <netproto/802_11/ieee80211_ageq.h>
50f186073cSJoerg Sonnenberger #include <netproto/802_11/ieee80211_crypto.h>
5132176cfdSRui Paulo #include <netproto/802_11/ieee80211_dfs.h>
52f186073cSJoerg Sonnenberger #include <netproto/802_11/ieee80211_ioctl.h>		/* for ieee80211_stats */
5332176cfdSRui Paulo #include <netproto/802_11/ieee80211_phy.h>
5432176cfdSRui Paulo #include <netproto/802_11/ieee80211_power.h>
55f186073cSJoerg Sonnenberger #include <netproto/802_11/ieee80211_node.h>
56f186073cSJoerg Sonnenberger #include <netproto/802_11/ieee80211_proto.h>
5732176cfdSRui Paulo #include <netproto/802_11/ieee80211_radiotap.h>
5832176cfdSRui Paulo #include <netproto/802_11/ieee80211_scan.h>
59f186073cSJoerg Sonnenberger 
60085ff963SMatthew Dillon #define	IEEE80211_TXPOWER_MAX	100	/* .5 dBm (XXX units?) */
61841ab66cSSepherosa Ziehau #define	IEEE80211_TXPOWER_MIN	0	/* kill radio */
62f186073cSJoerg Sonnenberger 
63841ab66cSSepherosa Ziehau #define	IEEE80211_DTIM_DEFAULT	1	/* default DTIM period */
64841ab66cSSepherosa Ziehau #define	IEEE80211_BINTVAL_DEFAULT 100	/* default beacon interval (TU's) */
65f186073cSJoerg Sonnenberger 
66841ab66cSSepherosa Ziehau #define	IEEE80211_BMISS_MAX	2	/* maximum consecutive bmiss allowed */
67841ab66cSSepherosa Ziehau #define	IEEE80211_HWBMISS_DEFAULT 7	/* h/w bmiss threshold (beacons) */
68f186073cSJoerg Sonnenberger 
6932176cfdSRui Paulo #define	IEEE80211_BGSCAN_INTVAL_MIN	15	/* min bg scan intvl (secs) */
7032176cfdSRui Paulo #define	IEEE80211_BGSCAN_INTVAL_DEFAULT	(5*60)	/* default bg scan intvl */
7132176cfdSRui Paulo 
7232176cfdSRui Paulo #define	IEEE80211_BGSCAN_IDLE_MIN	100	/* min idle time (ms) */
7332176cfdSRui Paulo #define	IEEE80211_BGSCAN_IDLE_DEFAULT	250	/* default idle time (ms) */
7432176cfdSRui Paulo 
7532176cfdSRui Paulo #define	IEEE80211_SCAN_VALID_MIN	10	/* min scan valid time (secs) */
7632176cfdSRui Paulo #define	IEEE80211_SCAN_VALID_DEFAULT	60	/* default scan valid time */
7732176cfdSRui Paulo 
78841ab66cSSepherosa Ziehau #define	IEEE80211_PS_SLEEP	0x1	/* STA is in power saving mode */
79841ab66cSSepherosa Ziehau #define	IEEE80211_PS_MAX_QUEUE	50	/* maximum saved packets */
80f186073cSJoerg Sonnenberger 
8132176cfdSRui Paulo #define	IEEE80211_FIXED_RATE_NONE	0xff
8232176cfdSRui Paulo #define	IEEE80211_TXMAX_DEFAULT		6	/* default ucast max retries */
83f186073cSJoerg Sonnenberger 
84841ab66cSSepherosa Ziehau #define	IEEE80211_RTS_DEFAULT		IEEE80211_RTS_MAX
85841ab66cSSepherosa Ziehau #define	IEEE80211_FRAG_DEFAULT		IEEE80211_FRAG_MAX
86f186073cSJoerg Sonnenberger 
8734b861deSSepherosa Ziehau #define	IEEE80211_MS_TO_TU(x)	(((x) * 1000) / 1024)
8834b861deSSepherosa Ziehau #define	IEEE80211_TU_TO_MS(x)	(((x) * 1024) / 1000)
8934b861deSSepherosa Ziehau #define	IEEE80211_TU_TO_TICKS(x)(((x) * 1024 * hz) / (1000 * 1000))
90f186073cSJoerg Sonnenberger 
9132176cfdSRui Paulo /*
9232176cfdSRui Paulo  * 802.11 control state is split into a common portion that maps
9332176cfdSRui Paulo  * 1-1 to a physical device and one or more "Virtual AP's" (VAP)
9432176cfdSRui Paulo  * that are bound to an ieee80211com instance and share a single
9532176cfdSRui Paulo  * underlying device.  Each VAP has a corresponding OS device
9632176cfdSRui Paulo  * entity through which traffic flows and that applications use
9732176cfdSRui Paulo  * for issuing ioctls, etc.
9832176cfdSRui Paulo  */
9932176cfdSRui Paulo 
10032176cfdSRui Paulo /*
10132176cfdSRui Paulo  * Data common to one or more virtual AP's.  State shared by
10232176cfdSRui Paulo  * the underlying device and the net80211 layer is exposed here;
10332176cfdSRui Paulo  * e.g. device-specific callbacks.
10432176cfdSRui Paulo  */
10532176cfdSRui Paulo struct ieee80211vap;
10632176cfdSRui Paulo typedef void (*ieee80211vap_attach)(struct ieee80211vap *);
10732176cfdSRui Paulo 
10832176cfdSRui Paulo struct ieee80211_appie {
10932176cfdSRui Paulo 	uint16_t		ie_len;		/* size of ie_data */
11032176cfdSRui Paulo 	uint8_t			ie_data[];	/* user-specified IE's */
11132176cfdSRui Paulo };
11232176cfdSRui Paulo 
11332176cfdSRui Paulo struct ieee80211_tdma_param;
11432176cfdSRui Paulo struct ieee80211_rate_table;
11532176cfdSRui Paulo struct ieee80211_tx_ampdu;
11632176cfdSRui Paulo struct ieee80211_rx_ampdu;
11732176cfdSRui Paulo struct ieee80211_superg;
11832176cfdSRui Paulo struct ieee80211_frame;
119f186073cSJoerg Sonnenberger 
120f186073cSJoerg Sonnenberger struct ieee80211com {
121841ab66cSSepherosa Ziehau 	struct ifnet		*ic_ifp;	/* associated device */
122085ff963SMatthew Dillon 	ieee80211_com_lock_t	ic_comlock;	/* state update lock */
123085ff963SMatthew Dillon 	ieee80211_tx_lock_t	ic_txlock;	/* ic/vap TX lock */
12432176cfdSRui Paulo 	TAILQ_HEAD(, ieee80211vap) ic_vaps;	/* list of vap instances */
1254ac84526SSepherosa Ziehau 	int			ic_headroom;	/* driver tx headroom needs */
12632176cfdSRui Paulo 	enum ieee80211_phytype	ic_phytype;	/* XXX wrong for multi-mode */
12732176cfdSRui Paulo 	enum ieee80211_opmode	ic_opmode;	/* operation mode */
12832176cfdSRui Paulo 	struct ifmedia		ic_media;	/* interface media config */
12932176cfdSRui Paulo 	struct callout		ic_inact;	/* inactivity processing */
13032176cfdSRui Paulo 	struct taskqueue	*ic_tq;		/* deferred state thread */
13132176cfdSRui Paulo 	struct task		ic_parent_task;	/* deferred parent processing */
13232176cfdSRui Paulo 	struct task		ic_promisc_task;/* deferred promisc update */
13332176cfdSRui Paulo 	struct task		ic_mcast_task;	/* deferred mcast update */
13432176cfdSRui Paulo 	struct task		ic_chan_task;	/* deferred channel change */
13532176cfdSRui Paulo 	struct task		ic_bmiss_task;	/* deferred beacon miss hndlr */
136085ff963SMatthew Dillon 	struct task		ic_chw_task;	/* deferred HT CHW update */
137841ab66cSSepherosa Ziehau 
13832176cfdSRui Paulo 	uint32_t		ic_flags;	/* state flags */
13932176cfdSRui Paulo 	uint32_t		ic_flags_ext;	/* extended state flags */
14032176cfdSRui Paulo 	uint32_t		ic_flags_ht;	/* HT state flags */
14132176cfdSRui Paulo 	uint32_t		ic_flags_ven;	/* vendor state flags */
14232176cfdSRui Paulo 	uint32_t		ic_caps;	/* capabilities */
14332176cfdSRui Paulo 	uint32_t		ic_htcaps;	/* HT capabilities */
1444028af95SRui Paulo 	uint32_t		ic_htextcaps;	/* HT extended capabilities */
14532176cfdSRui Paulo 	uint32_t		ic_cryptocaps;	/* crypto capabilities */
14632176cfdSRui Paulo 	uint8_t			ic_modecaps[2];	/* set of mode capabilities */
14732176cfdSRui Paulo 	uint8_t			ic_promisc;	/* vap's needing promisc mode */
14832176cfdSRui Paulo 	uint8_t			ic_allmulti;	/* vap's needing all multicast*/
14932176cfdSRui Paulo 	uint8_t			ic_nrunning;	/* vap's marked running */
15032176cfdSRui Paulo 	uint8_t			ic_curmode;	/* current mode */
15132176cfdSRui Paulo 	uint16_t		ic_bintval;	/* beacon interval */
15232176cfdSRui Paulo 	uint16_t		ic_lintval;	/* listen interval */
15332176cfdSRui Paulo 	uint16_t		ic_holdover;	/* PM hold over duration */
15432176cfdSRui Paulo 	uint16_t		ic_txpowlimit;	/* global tx power limit */
155f186073cSJoerg Sonnenberger 	struct ieee80211_rateset ic_sup_rates[IEEE80211_MODE_MAX];
15632176cfdSRui Paulo 
15732176cfdSRui Paulo 	/*
15832176cfdSRui Paulo 	 * Channel state:
15932176cfdSRui Paulo 	 *
16032176cfdSRui Paulo 	 * ic_channels is the set of available channels for the device;
16132176cfdSRui Paulo 	 *    it is setup by the driver
16232176cfdSRui Paulo 	 * ic_nchans is the number of valid entries in ic_channels
16332176cfdSRui Paulo 	 * ic_chan_avail is a bit vector of these channels used to check
16432176cfdSRui Paulo 	 *    whether a channel is available w/o searching the channel table.
16532176cfdSRui Paulo 	 * ic_chan_active is a (potentially) constrained subset of
16632176cfdSRui Paulo 	 *    ic_chan_avail that reflects any mode setting or user-specified
16732176cfdSRui Paulo 	 *    limit on the set of channels to use/scan
16832176cfdSRui Paulo 	 * ic_curchan is the current channel the device is set to; it may
16932176cfdSRui Paulo 	 *    be different from ic_bsschan when we are off-channel scanning
17032176cfdSRui Paulo 	 *    or otherwise doing background work
17132176cfdSRui Paulo 	 * ic_bsschan is the channel selected for operation; it may
17232176cfdSRui Paulo 	 *    be undefined (IEEE80211_CHAN_ANYC)
17332176cfdSRui Paulo 	 * ic_prevchan is a cached ``previous channel'' used to optimize
17432176cfdSRui Paulo 	 *    lookups when switching back+forth between two channels
17532176cfdSRui Paulo 	 *    (e.g. for dynamic turbo)
17632176cfdSRui Paulo 	 */
17732176cfdSRui Paulo 	int			ic_nchans;	/* # entries in ic_channels */
17832176cfdSRui Paulo 	struct ieee80211_channel ic_channels[IEEE80211_CHAN_MAX];
179841ab66cSSepherosa Ziehau 	uint8_t			ic_chan_avail[IEEE80211_CHAN_BYTES];
180841ab66cSSepherosa Ziehau 	uint8_t			ic_chan_active[IEEE80211_CHAN_BYTES];
181841ab66cSSepherosa Ziehau 	uint8_t			ic_chan_scan[IEEE80211_CHAN_BYTES];
182841ab66cSSepherosa Ziehau 	struct ieee80211_channel *ic_curchan;	/* current channel */
18332176cfdSRui Paulo 	const struct ieee80211_rate_table *ic_rt; /* table for ic_curchan */
18432176cfdSRui Paulo 	struct ieee80211_channel *ic_bsschan;	/* bss channel */
18532176cfdSRui Paulo 	struct ieee80211_channel *ic_prevchan;	/* previous channel */
18632176cfdSRui Paulo 	struct ieee80211_regdomain ic_regdomain;/* regulatory data */
18732176cfdSRui Paulo 	struct ieee80211_appie	*ic_countryie;	/* calculated country ie */
18832176cfdSRui Paulo 	struct ieee80211_channel *ic_countryie_chan;
18932176cfdSRui Paulo 
19032176cfdSRui Paulo 	/* 802.11h/DFS state */
19132176cfdSRui Paulo 	struct ieee80211_channel *ic_csa_newchan;/* channel for doing CSA */
19232176cfdSRui Paulo 	short			ic_csa_mode;	/* mode for doing CSA */
19332176cfdSRui Paulo 	short			ic_csa_count;	/* count for doing CSA */
19432176cfdSRui Paulo 	struct ieee80211_dfs_state ic_dfs;	/* DFS state */
19532176cfdSRui Paulo 
19632176cfdSRui Paulo 	struct ieee80211_scan_state *ic_scan;	/* scan state */
19732176cfdSRui Paulo 	int			ic_lastdata;	/* time of last data frame */
19832176cfdSRui Paulo 	int			ic_lastscan;	/* time last scan completed */
19932176cfdSRui Paulo 
20032176cfdSRui Paulo 	/* NB: this is the union of all vap stations/neighbors */
20132176cfdSRui Paulo 	int			ic_max_keyix;	/* max h/w key index */
20232176cfdSRui Paulo 	struct ieee80211_node_table ic_sta;	/* stations/neighbors */
20332176cfdSRui Paulo 	struct ieee80211_ageq	ic_stageq;	/* frame staging queue */
20432176cfdSRui Paulo 	uint32_t		ic_hash_key;	/* random key for mac hash */
20532176cfdSRui Paulo 
20632176cfdSRui Paulo 	/* XXX multi-bss: split out common/vap parts */
20732176cfdSRui Paulo 	struct ieee80211_wme_state ic_wme;	/* WME/WMM state */
20832176cfdSRui Paulo 
20932176cfdSRui Paulo 	/* XXX multi-bss: can per-vap be done/make sense? */
21032176cfdSRui Paulo 	enum ieee80211_protmode	ic_protmode;	/* 802.11g protection mode */
211841ab66cSSepherosa Ziehau 	uint16_t		ic_nonerpsta;	/* # non-ERP stations */
212841ab66cSSepherosa Ziehau 	uint16_t		ic_longslotsta;	/* # long slot time stations */
21332176cfdSRui Paulo 	uint16_t		ic_sta_assoc;	/* stations associated */
21432176cfdSRui Paulo 	uint16_t		ic_ht_sta_assoc;/* HT stations associated */
21532176cfdSRui Paulo 	uint16_t		ic_ht40_sta_assoc;/* HT40 stations associated */
21632176cfdSRui Paulo 	uint8_t			ic_curhtprotmode;/* HTINFO bss state */
21732176cfdSRui Paulo 	enum ieee80211_protmode	ic_htprotmode;	/* HT protection mode */
21832176cfdSRui Paulo 	int			ic_lastnonerp;	/* last time non-ERP sta noted*/
21932176cfdSRui Paulo 	int			ic_lastnonht;	/* last time non-HT sta noted */
220085ff963SMatthew Dillon 	uint8_t			ic_rxstream;    /* # RX streams */
221085ff963SMatthew Dillon 	uint8_t			ic_txstream;    /* # TX streams */
22232176cfdSRui Paulo 
22332176cfdSRui Paulo 	/* optional state for Atheros SuperG protocol extensions */
22432176cfdSRui Paulo 	struct ieee80211_superg	*ic_superg;
22532176cfdSRui Paulo 
22632176cfdSRui Paulo 	/* radiotap handling */
22732176cfdSRui Paulo 	struct ieee80211_radiotap_header *ic_th;/* tx radiotap headers */
22832176cfdSRui Paulo 	void			*ic_txchan;	/* channel state in ic_th */
22932176cfdSRui Paulo 	struct ieee80211_radiotap_header *ic_rh;/* rx radiotap headers */
23032176cfdSRui Paulo 	void			*ic_rxchan;	/* channel state in ic_rh */
23132176cfdSRui Paulo 	int			ic_montaps;	/* active monitor mode taps */
23232176cfdSRui Paulo 
23332176cfdSRui Paulo 	/* virtual ap create/delete */
23432176cfdSRui Paulo 	struct ieee80211vap*	(*ic_vap_create)(struct ieee80211com *,
235085ff963SMatthew Dillon 				    const char [IFNAMSIZ], int,
236085ff963SMatthew Dillon 				    enum ieee80211_opmode, int,
237085ff963SMatthew Dillon 				    const uint8_t [IEEE80211_ADDR_LEN],
238085ff963SMatthew Dillon 				    const uint8_t [IEEE80211_ADDR_LEN]);
23932176cfdSRui Paulo 	void			(*ic_vap_delete)(struct ieee80211vap *);
24032176cfdSRui Paulo 	/* operating mode attachment */
24132176cfdSRui Paulo 	ieee80211vap_attach	ic_vattach[IEEE80211_OPMODE_MAX];
24232176cfdSRui Paulo 	/* return hardware/radio capabilities */
24332176cfdSRui Paulo 	void			(*ic_getradiocaps)(struct ieee80211com *,
24432176cfdSRui Paulo 				    int, int *, struct ieee80211_channel []);
24532176cfdSRui Paulo 	/* check and/or prepare regdomain state change */
24632176cfdSRui Paulo 	int			(*ic_setregdomain)(struct ieee80211com *,
24732176cfdSRui Paulo 				    struct ieee80211_regdomain *,
24832176cfdSRui Paulo 				    int, struct ieee80211_channel []);
249085ff963SMatthew Dillon 
250085ff963SMatthew Dillon 	int			(*ic_set_quiet)(struct ieee80211_node *,
251085ff963SMatthew Dillon 				    u_int8_t *quiet_elm);
252085ff963SMatthew Dillon 
25332176cfdSRui Paulo 	/* send/recv 802.11 management frame */
25432176cfdSRui Paulo 	int			(*ic_send_mgmt)(struct ieee80211_node *,
25532176cfdSRui Paulo 				     int, int);
25632176cfdSRui Paulo 	/* send raw 802.11 frame */
25732176cfdSRui Paulo 	int			(*ic_raw_xmit)(struct ieee80211_node *,
25832176cfdSRui Paulo 				    struct mbuf *,
25932176cfdSRui Paulo 				    const struct ieee80211_bpf_params *);
26032176cfdSRui Paulo 	/* update device state for 802.11 slot time change */
26132176cfdSRui Paulo 	void			(*ic_updateslot)(struct ifnet *);
26232176cfdSRui Paulo 	/* handle multicast state changes */
26332176cfdSRui Paulo 	void			(*ic_update_mcast)(struct ifnet *);
26432176cfdSRui Paulo 	/* handle promiscuous mode changes */
26532176cfdSRui Paulo 	void			(*ic_update_promisc)(struct ifnet *);
26632176cfdSRui Paulo 	/* new station association callback/notification */
26732176cfdSRui Paulo 	void			(*ic_newassoc)(struct ieee80211_node *, int);
26832176cfdSRui Paulo 	/* TDMA update notification */
26932176cfdSRui Paulo 	void			(*ic_tdma_update)(struct ieee80211_node *,
27032176cfdSRui Paulo 				    const struct ieee80211_tdma_param *, int);
27132176cfdSRui Paulo 	/* node state management */
27232176cfdSRui Paulo 	struct ieee80211_node*	(*ic_node_alloc)(struct ieee80211vap *,
27332176cfdSRui Paulo 				    const uint8_t [IEEE80211_ADDR_LEN]);
27432176cfdSRui Paulo 	void			(*ic_node_free)(struct ieee80211_node *);
27532176cfdSRui Paulo 	void			(*ic_node_cleanup)(struct ieee80211_node *);
27632176cfdSRui Paulo 	void			(*ic_node_age)(struct ieee80211_node *);
27732176cfdSRui Paulo 	void			(*ic_node_drain)(struct ieee80211_node *);
27832176cfdSRui Paulo 	int8_t			(*ic_node_getrssi)(const struct ieee80211_node*);
27932176cfdSRui Paulo 	void			(*ic_node_getsignal)(const struct ieee80211_node*,
28032176cfdSRui Paulo 				    int8_t *, int8_t *);
28132176cfdSRui Paulo 	void			(*ic_node_getmimoinfo)(
28232176cfdSRui Paulo 				    const struct ieee80211_node*,
28332176cfdSRui Paulo 				    struct ieee80211_mimo_info *);
28432176cfdSRui Paulo 	/* scanning support */
28532176cfdSRui Paulo 	void			(*ic_scan_start)(struct ieee80211com *);
28632176cfdSRui Paulo 	void			(*ic_scan_end)(struct ieee80211com *);
28732176cfdSRui Paulo 	void			(*ic_set_channel)(struct ieee80211com *);
28832176cfdSRui Paulo 	void			(*ic_scan_curchan)(struct ieee80211_scan_state *,
28932176cfdSRui Paulo 				    unsigned long);
29032176cfdSRui Paulo 	void			(*ic_scan_mindwell)(struct ieee80211_scan_state *);
291841ab66cSSepherosa Ziehau 
292841ab66cSSepherosa Ziehau 	/*
29332176cfdSRui Paulo 	 * 802.11n ADDBA support.  A simple/generic implementation
29432176cfdSRui Paulo 	 * of A-MPDU tx aggregation is provided; the driver may
29532176cfdSRui Paulo 	 * override these methods to provide their own support.
29632176cfdSRui Paulo 	 * A-MPDU rx re-ordering happens automatically if the
29732176cfdSRui Paulo 	 * driver passes out-of-order frames to ieee80211_input
29832176cfdSRui Paulo 	 * from an assocated HT station.
299841ab66cSSepherosa Ziehau 	 */
30032176cfdSRui Paulo 	int			(*ic_recv_action)(struct ieee80211_node *,
30132176cfdSRui Paulo 				    const struct ieee80211_frame *,
30232176cfdSRui Paulo 				    const uint8_t *frm, const uint8_t *efrm);
30332176cfdSRui Paulo 	int			(*ic_send_action)(struct ieee80211_node *,
30432176cfdSRui Paulo 				    int category, int action, void *);
30532176cfdSRui Paulo 	/* check if A-MPDU should be enabled this station+ac */
30632176cfdSRui Paulo 	int			(*ic_ampdu_enable)(struct ieee80211_node *,
30732176cfdSRui Paulo 				    struct ieee80211_tx_ampdu *);
30832176cfdSRui Paulo 	/* start/stop doing A-MPDU tx aggregation for a station */
30932176cfdSRui Paulo 	int			(*ic_addba_request)(struct ieee80211_node *,
31032176cfdSRui Paulo 				    struct ieee80211_tx_ampdu *,
31132176cfdSRui Paulo 				    int dialogtoken, int baparamset,
31232176cfdSRui Paulo 				    int batimeout);
31332176cfdSRui Paulo 	int			(*ic_addba_response)(struct ieee80211_node *,
31432176cfdSRui Paulo 				    struct ieee80211_tx_ampdu *,
31532176cfdSRui Paulo 				    int status, int baparamset, int batimeout);
31632176cfdSRui Paulo 	void			(*ic_addba_stop)(struct ieee80211_node *,
31732176cfdSRui Paulo 				    struct ieee80211_tx_ampdu *);
318085ff963SMatthew Dillon 	void			(*ic_addba_response_timeout)(struct ieee80211_node *,
319085ff963SMatthew Dillon 				    struct ieee80211_tx_ampdu *);
32032176cfdSRui Paulo 	/* BAR response received */
32132176cfdSRui Paulo 	void			(*ic_bar_response)(struct ieee80211_node *,
32232176cfdSRui Paulo 				    struct ieee80211_tx_ampdu *, int status);
32332176cfdSRui Paulo 	/* start/stop doing A-MPDU rx processing for a station */
32432176cfdSRui Paulo 	int			(*ic_ampdu_rx_start)(struct ieee80211_node *,
32532176cfdSRui Paulo 				    struct ieee80211_rx_ampdu *, int baparamset,
32632176cfdSRui Paulo 				    int batimeout, int baseqctl);
32732176cfdSRui Paulo 	void			(*ic_ampdu_rx_stop)(struct ieee80211_node *,
32832176cfdSRui Paulo 				    struct ieee80211_rx_ampdu *);
329085ff963SMatthew Dillon 
330085ff963SMatthew Dillon 	/* The channel width has changed (20<->2040) */
331085ff963SMatthew Dillon 	void			(*ic_update_chw)(struct ieee80211com *);
332085ff963SMatthew Dillon 
3334028af95SRui Paulo 	uint64_t		ic_spare[7];
334f186073cSJoerg Sonnenberger };
335f186073cSJoerg Sonnenberger 
33632176cfdSRui Paulo struct ieee80211_aclator;
33732176cfdSRui Paulo struct ieee80211_tdma_state;
33832176cfdSRui Paulo struct ieee80211_mesh_state;
33932176cfdSRui Paulo struct ieee80211_hwmp_state;
34032176cfdSRui Paulo 
34132176cfdSRui Paulo struct ieee80211vap {
34232176cfdSRui Paulo 	struct ifmedia		iv_media;	/* interface media config */
34332176cfdSRui Paulo 	struct ifnet		*iv_ifp;	/* associated device */
34432176cfdSRui Paulo 	struct bpf_if		*iv_rawbpf;	/* packet filter structure */
34532176cfdSRui Paulo 	struct sysctl_ctx_list	*iv_sysctl;	/* dynamic sysctl context */
34632176cfdSRui Paulo 	struct sysctl_oid	*iv_oid;	/* net.wlan.X sysctl oid */
34732176cfdSRui Paulo 
34832176cfdSRui Paulo 	TAILQ_ENTRY(ieee80211vap) iv_next;	/* list of vap instances */
34932176cfdSRui Paulo 	struct ieee80211com	*iv_ic;		/* back ptr to common state */
35032176cfdSRui Paulo 	uint32_t		iv_debug;	/* debug msg flags */
35132176cfdSRui Paulo 	struct ieee80211_stats	iv_stats;	/* statistics */
35232176cfdSRui Paulo 
35332176cfdSRui Paulo 	uint8_t			iv_myaddr[IEEE80211_ADDR_LEN];
35432176cfdSRui Paulo 	uint32_t		iv_flags;	/* state flags */
35532176cfdSRui Paulo 	uint32_t		iv_flags_ext;	/* extended state flags */
35632176cfdSRui Paulo 	uint32_t		iv_flags_ht;	/* HT state flags */
35732176cfdSRui Paulo 	uint32_t		iv_flags_ven;	/* vendor state flags */
35832176cfdSRui Paulo 	uint32_t		iv_caps;	/* capabilities */
35932176cfdSRui Paulo 	uint32_t		iv_htcaps;	/* HT capabilities */
3604028af95SRui Paulo 	uint32_t		iv_htextcaps;	/* HT extended capabilities */
36132176cfdSRui Paulo 	enum ieee80211_opmode	iv_opmode;	/* operation mode */
36232176cfdSRui Paulo 	enum ieee80211_state	iv_state;	/* state machine state */
36332176cfdSRui Paulo 	enum ieee80211_state	iv_nstate;	/* pending state */
36432176cfdSRui Paulo 	int			iv_nstate_arg;	/* pending state arg */
36532176cfdSRui Paulo 	struct task		iv_nstate_task;	/* deferred state processing */
36632176cfdSRui Paulo 	struct task		iv_swbmiss_task;/* deferred iv_bmiss call */
36732176cfdSRui Paulo 	struct callout		iv_mgtsend;	/* mgmt frame response timer */
36832176cfdSRui Paulo 						/* inactivity timer settings */
36932176cfdSRui Paulo 	int			iv_inact_init;	/* setting for new station */
37032176cfdSRui Paulo 	int			iv_inact_auth;	/* auth but not assoc setting */
37132176cfdSRui Paulo 	int			iv_inact_run;	/* authorized setting */
37232176cfdSRui Paulo 	int			iv_inact_probe;	/* inactive probe time */
37332176cfdSRui Paulo 
37432176cfdSRui Paulo 	int			iv_des_nssid;	/* # desired ssids */
37532176cfdSRui Paulo 	struct ieee80211_scan_ssid iv_des_ssid[1];/* desired ssid table */
37632176cfdSRui Paulo 	uint8_t			iv_des_bssid[IEEE80211_ADDR_LEN];
37732176cfdSRui Paulo 	struct ieee80211_channel *iv_des_chan;	/* desired channel */
37832176cfdSRui Paulo 	uint16_t		iv_des_mode;	/* desired mode */
37932176cfdSRui Paulo 	int			iv_nicknamelen;	/* XXX junk */
38032176cfdSRui Paulo 	uint8_t			iv_nickname[IEEE80211_NWID_LEN];
38132176cfdSRui Paulo 	u_int			iv_bgscanidle;	/* bg scan idle threshold */
38232176cfdSRui Paulo 	u_int			iv_bgscanintvl;	/* bg scan min interval */
38332176cfdSRui Paulo 	u_int			iv_scanvalid;	/* scan cache valid threshold */
38432176cfdSRui Paulo 	u_int			iv_scanreq_duration;
38532176cfdSRui Paulo 	u_int			iv_scanreq_mindwell;
38632176cfdSRui Paulo 	u_int			iv_scanreq_maxdwell;
38732176cfdSRui Paulo 	uint16_t		iv_scanreq_flags;/* held scan request params */
38832176cfdSRui Paulo 	uint8_t			iv_scanreq_nssid;
38932176cfdSRui Paulo 	struct ieee80211_scan_ssid iv_scanreq_ssid[IEEE80211_SCAN_MAX_SSID];
39032176cfdSRui Paulo 	/* sta-mode roaming state */
39132176cfdSRui Paulo 	enum ieee80211_roamingmode iv_roaming;	/* roaming mode */
39232176cfdSRui Paulo 	struct ieee80211_roamparam iv_roamparms[IEEE80211_MODE_MAX];
39332176cfdSRui Paulo 
39432176cfdSRui Paulo 	uint8_t			iv_bmissthreshold;
39532176cfdSRui Paulo 	uint8_t			iv_bmiss_count;	/* current beacon miss count */
39632176cfdSRui Paulo 	int			iv_bmiss_max;	/* max bmiss before scan */
39732176cfdSRui Paulo 	uint16_t		iv_swbmiss_count;/* beacons in last period */
39832176cfdSRui Paulo 	uint16_t		iv_swbmiss_period;/* s/w bmiss period */
39932176cfdSRui Paulo 	struct callout		iv_swbmiss;	/* s/w beacon miss timer */
40032176cfdSRui Paulo 
40132176cfdSRui Paulo 	int			iv_ampdu_rxmax;	/* A-MPDU rx limit (bytes) */
40232176cfdSRui Paulo 	int			iv_ampdu_density;/* A-MPDU density */
40332176cfdSRui Paulo 	int			iv_ampdu_limit;	/* A-MPDU tx limit (bytes) */
40432176cfdSRui Paulo 	int			iv_amsdu_limit;	/* A-MSDU tx limit (bytes) */
40532176cfdSRui Paulo 	u_int			iv_ampdu_mintraffic[WME_NUM_AC];
40632176cfdSRui Paulo 
40732176cfdSRui Paulo 	uint32_t		*iv_aid_bitmap;	/* association id map */
40832176cfdSRui Paulo 	uint16_t		iv_max_aid;
40932176cfdSRui Paulo 	uint16_t		iv_sta_assoc;	/* stations associated */
41032176cfdSRui Paulo 	uint16_t		iv_ps_sta;	/* stations in power save */
41132176cfdSRui Paulo 	uint16_t		iv_ps_pending;	/* ps sta's w/ pending frames */
41232176cfdSRui Paulo 	uint16_t		iv_txseq;	/* mcast xmit seq# space */
41332176cfdSRui Paulo 	uint16_t		iv_tim_len;	/* ic_tim_bitmap size (bytes) */
41432176cfdSRui Paulo 	uint8_t			*iv_tim_bitmap;	/* power-save stations w/ data*/
41532176cfdSRui Paulo 	uint8_t			iv_dtim_period;	/* DTIM period */
41632176cfdSRui Paulo 	uint8_t			iv_dtim_count;	/* DTIM count from last bcn */
41732176cfdSRui Paulo 						/* set/unset aid pwrsav state */
418085ff963SMatthew Dillon 	uint8_t			iv_quiet;	/* Quiet Element */
419085ff963SMatthew Dillon 	uint8_t			iv_quiet_count;	/* constant count for Quiet Element */
420085ff963SMatthew Dillon 	uint8_t			iv_quiet_count_value;	/* variable count for Quiet Element */
421085ff963SMatthew Dillon 	uint8_t			iv_quiet_period;	/* period for Quiet Element */
422085ff963SMatthew Dillon 	uint16_t		iv_quiet_duration;	/* duration for Quiet Element */
423085ff963SMatthew Dillon 	uint16_t		iv_quiet_offset;	/* offset for Quiet Element */
42432176cfdSRui Paulo 	int			iv_csa_count;	/* count for doing CSA */
42532176cfdSRui Paulo 
42632176cfdSRui Paulo 	struct ieee80211_node	*iv_bss;	/* information for this node */
42732176cfdSRui Paulo 	struct ieee80211_txparam iv_txparms[IEEE80211_MODE_MAX];
42832176cfdSRui Paulo 	uint16_t		iv_rtsthreshold;
42932176cfdSRui Paulo 	uint16_t		iv_fragthreshold;
43032176cfdSRui Paulo 	int			iv_inact_timer;	/* inactivity timer wait */
43132176cfdSRui Paulo 	/* application-specified IE's to attach to mgt frames */
43232176cfdSRui Paulo 	struct ieee80211_appie	*iv_appie_beacon;
43332176cfdSRui Paulo 	struct ieee80211_appie	*iv_appie_probereq;
43432176cfdSRui Paulo 	struct ieee80211_appie	*iv_appie_proberesp;
43532176cfdSRui Paulo 	struct ieee80211_appie	*iv_appie_assocreq;
43632176cfdSRui Paulo 	struct ieee80211_appie	*iv_appie_assocresp;
43732176cfdSRui Paulo 	struct ieee80211_appie	*iv_appie_wpa;
43832176cfdSRui Paulo 	uint8_t			*iv_wpa_ie;
43932176cfdSRui Paulo 	uint8_t			*iv_rsn_ie;
44032176cfdSRui Paulo 	uint16_t		iv_max_keyix;	/* max h/w key index */
44132176cfdSRui Paulo 	ieee80211_keyix		iv_def_txkey;	/* default/group tx key index */
44232176cfdSRui Paulo 	struct ieee80211_key	iv_nw_keys[IEEE80211_WEP_NKID];
44332176cfdSRui Paulo 	int			(*iv_key_alloc)(struct ieee80211vap *,
44432176cfdSRui Paulo 				    struct ieee80211_key *,
44532176cfdSRui Paulo 				    ieee80211_keyix *, ieee80211_keyix *);
44632176cfdSRui Paulo 	int			(*iv_key_delete)(struct ieee80211vap *,
44732176cfdSRui Paulo 				    const struct ieee80211_key *);
44832176cfdSRui Paulo 	int			(*iv_key_set)(struct ieee80211vap *,
44932176cfdSRui Paulo 				    const struct ieee80211_key *,
45032176cfdSRui Paulo 				    const uint8_t mac[IEEE80211_ADDR_LEN]);
45132176cfdSRui Paulo 	void			(*iv_key_update_begin)(struct ieee80211vap *);
45232176cfdSRui Paulo 	void			(*iv_key_update_end)(struct ieee80211vap *);
45332176cfdSRui Paulo 
45432176cfdSRui Paulo 	const struct ieee80211_authenticator *iv_auth; /* authenticator glue */
45532176cfdSRui Paulo 	void			*iv_ec;		/* private auth state */
45632176cfdSRui Paulo 
45732176cfdSRui Paulo 	const struct ieee80211_aclator *iv_acl;	/* acl glue */
45832176cfdSRui Paulo 	void			*iv_as;		/* private aclator state */
45932176cfdSRui Paulo 
4604028af95SRui Paulo 	const struct ieee80211_ratectl *iv_rate;
4614028af95SRui Paulo 	void			*iv_rs;		/* private ratectl state */
4624028af95SRui Paulo 
46332176cfdSRui Paulo 	struct ieee80211_tdma_state *iv_tdma;	/* tdma state */
46432176cfdSRui Paulo 	struct ieee80211_mesh_state *iv_mesh;	/* MBSS state */
46532176cfdSRui Paulo 	struct ieee80211_hwmp_state *iv_hwmp;	/* HWMP state */
46632176cfdSRui Paulo 
46732176cfdSRui Paulo 	/* operate-mode detach hook */
46832176cfdSRui Paulo 	void			(*iv_opdetach)(struct ieee80211vap *);
46932176cfdSRui Paulo 	/* receive processing */
47032176cfdSRui Paulo 	int			(*iv_input)(struct ieee80211_node *,
47132176cfdSRui Paulo 				    struct mbuf *, int, int);
47232176cfdSRui Paulo 	void			(*iv_recv_mgmt)(struct ieee80211_node *,
47332176cfdSRui Paulo 				    struct mbuf *, int, int, int);
47432176cfdSRui Paulo 	void			(*iv_recv_ctl)(struct ieee80211_node *,
47532176cfdSRui Paulo 				    struct mbuf *, int);
47632176cfdSRui Paulo 	void			(*iv_deliver_data)(struct ieee80211vap *,
47732176cfdSRui Paulo 				    struct ieee80211_node *, struct mbuf *);
47832176cfdSRui Paulo #if 0
47932176cfdSRui Paulo 	/* send processing */
48032176cfdSRui Paulo 	int			(*iv_send_mgmt)(struct ieee80211_node *,
48132176cfdSRui Paulo 				     int, int);
48232176cfdSRui Paulo #endif
48332176cfdSRui Paulo 	/* beacon miss processing */
48432176cfdSRui Paulo 	void			(*iv_bmiss)(struct ieee80211vap *);
48532176cfdSRui Paulo 	/* reset device state after 802.11 parameter/state change */
48632176cfdSRui Paulo 	int			(*iv_reset)(struct ieee80211vap *, u_long);
48732176cfdSRui Paulo 	/* [schedule] beacon frame update */
48832176cfdSRui Paulo 	void			(*iv_update_beacon)(struct ieee80211vap *, int);
48932176cfdSRui Paulo 	/* power save handling */
49032176cfdSRui Paulo 	void			(*iv_update_ps)(struct ieee80211vap *, int);
49132176cfdSRui Paulo 	int			(*iv_set_tim)(struct ieee80211_node *, int);
492d98a0bcfSMatthew Dillon 	void			(*iv_node_ps)(struct ieee80211_node *, int);
493d98a0bcfSMatthew Dillon 	void			(*iv_sta_ps)(struct ieee80211vap *, int);
494085ff963SMatthew Dillon 	void			(*iv_recv_pspoll)(struct ieee80211_node *,
495085ff963SMatthew Dillon 				    struct mbuf *);
496085ff963SMatthew Dillon 
49732176cfdSRui Paulo 	/* state machine processing */
49832176cfdSRui Paulo 	int			(*iv_newstate)(struct ieee80211vap *,
49932176cfdSRui Paulo 				    enum ieee80211_state, int);
50032176cfdSRui Paulo 	/* 802.3 output method for raw frame xmit */
501085ff963SMatthew Dillon #if defined(__DragonFly__)
50232176cfdSRui Paulo 	int			(*iv_output)(struct ifnet *, struct mbuf *,
50334a60cf6SRui Paulo 				    struct sockaddr *, struct rtentry *);
504085ff963SMatthew Dillon #else
505085ff963SMatthew Dillon 	int			(*iv_output)(struct ifnet *, struct mbuf *,
506*294727bfSImre Vadász 				    const struct sockaddr *, struct route *);
507085ff963SMatthew Dillon #endif
5084028af95SRui Paulo 	uint64_t		iv_spare[6];
50932176cfdSRui Paulo };
51032176cfdSRui Paulo MALLOC_DECLARE(M_80211_VAP);
51132176cfdSRui Paulo 
512f186073cSJoerg Sonnenberger #define	IEEE80211_ADDR_EQ(a1,a2)	(memcmp(a1,a2,IEEE80211_ADDR_LEN) == 0)
513f186073cSJoerg Sonnenberger #define	IEEE80211_ADDR_COPY(dst,src)	memcpy(dst,src,IEEE80211_ADDR_LEN)
514f186073cSJoerg Sonnenberger 
51532176cfdSRui Paulo /* ic_flags/iv_flags */
51632176cfdSRui Paulo #define	IEEE80211_F_TURBOP	0x00000001	/* CONF: ATH Turbo enabled*/
51732176cfdSRui Paulo #define	IEEE80211_F_COMP	0x00000002	/* CONF: ATH comp enabled */
51832176cfdSRui Paulo #define	IEEE80211_F_FF		0x00000004	/* CONF: ATH FF enabled */
51932176cfdSRui Paulo #define	IEEE80211_F_BURST	0x00000008	/* CONF: bursting enabled */
520841ab66cSSepherosa Ziehau /* NB: this is intentionally setup to be IEEE80211_CAPINFO_PRIVACY */
521841ab66cSSepherosa Ziehau #define	IEEE80211_F_PRIVACY	0x00000010	/* CONF: privacy enabled */
522841ab66cSSepherosa Ziehau #define	IEEE80211_F_PUREG	0x00000020	/* CONF: 11g w/o 11b sta's */
523841ab66cSSepherosa Ziehau #define	IEEE80211_F_SCAN	0x00000080	/* STATUS: scanning */
524841ab66cSSepherosa Ziehau #define	IEEE80211_F_ASCAN	0x00000100	/* STATUS: active scan */
525841ab66cSSepherosa Ziehau #define	IEEE80211_F_SIBSS	0x00000200	/* STATUS: start IBSS */
526841ab66cSSepherosa Ziehau /* NB: this is intentionally setup to be IEEE80211_CAPINFO_SHORT_SLOTTIME */
527841ab66cSSepherosa Ziehau #define	IEEE80211_F_SHSLOT	0x00000400	/* STATUS: use short slot time*/
528841ab66cSSepherosa Ziehau #define	IEEE80211_F_PMGTON	0x00000800	/* CONF: Power mgmt enable */
529841ab66cSSepherosa Ziehau #define	IEEE80211_F_DESBSSID	0x00001000	/* CONF: des_bssid is set */
530841ab66cSSepherosa Ziehau #define	IEEE80211_F_WME		0x00002000	/* CONF: enable WME use */
531841ab66cSSepherosa Ziehau #define	IEEE80211_F_BGSCAN	0x00004000	/* CONF: bg scan enabled (???)*/
532841ab66cSSepherosa Ziehau #define	IEEE80211_F_SWRETRY	0x00008000	/* CONF: sw tx retry enabled */
533841ab66cSSepherosa Ziehau #define IEEE80211_F_TXPOW_FIXED	0x00010000	/* TX Power: fixed rate */
534841ab66cSSepherosa Ziehau #define	IEEE80211_F_IBSSON	0x00020000	/* CONF: IBSS creation enable */
535841ab66cSSepherosa Ziehau #define	IEEE80211_F_SHPREAMBLE	0x00040000	/* STATUS: use short preamble */
536841ab66cSSepherosa Ziehau #define	IEEE80211_F_DATAPAD	0x00080000	/* CONF: do alignment pad */
537f186073cSJoerg Sonnenberger #define	IEEE80211_F_USEPROT	0x00100000	/* STATUS: protection enabled */
538f186073cSJoerg Sonnenberger #define	IEEE80211_F_USEBARKER	0x00200000	/* STATUS: use barker preamble*/
53932176cfdSRui Paulo #define	IEEE80211_F_CSAPENDING	0x00400000	/* STATUS: chan switch pending*/
540841ab66cSSepherosa Ziehau #define	IEEE80211_F_WPA1	0x00800000	/* CONF: WPA enabled */
541841ab66cSSepherosa Ziehau #define	IEEE80211_F_WPA2	0x01000000	/* CONF: WPA2 enabled */
542841ab66cSSepherosa Ziehau #define	IEEE80211_F_WPA		0x01800000	/* CONF: WPA/WPA2 enabled */
543841ab66cSSepherosa Ziehau #define	IEEE80211_F_DROPUNENC	0x02000000	/* CONF: drop unencrypted */
544841ab66cSSepherosa Ziehau #define	IEEE80211_F_COUNTERM	0x04000000	/* CONF: TKIP countermeasures */
545841ab66cSSepherosa Ziehau #define	IEEE80211_F_HIDESSID	0x08000000	/* CONF: hide SSID in beacon */
546841ab66cSSepherosa Ziehau #define	IEEE80211_F_NOBRIDGE	0x10000000	/* CONF: dis. internal bridge */
54732176cfdSRui Paulo #define	IEEE80211_F_PCF		0x20000000	/* CONF: PCF enabled */
54832176cfdSRui Paulo #define	IEEE80211_F_DOTH	0x40000000	/* CONF: 11h enabled */
54932176cfdSRui Paulo #define	IEEE80211_F_DWDS	0x80000000	/* CONF: Dynamic WDS enabled */
550841ab66cSSepherosa Ziehau 
55132176cfdSRui Paulo #define	IEEE80211_F_BITS \
55232176cfdSRui Paulo 	"\20\1TURBOP\2COMP\3FF\4BURST\5PRIVACY\6PUREG\10SCAN\11ASCAN\12SIBSS" \
55332176cfdSRui Paulo 	"\13SHSLOT\14PMGTON\15DESBSSID\16WME\17BGSCAN\20SWRETRY\21TXPOW_FIXED" \
55432176cfdSRui Paulo 	"\22IBSSON\23SHPREAMBLE\24DATAPAD\25USEPROT\26USERBARKER\27CSAPENDING" \
55532176cfdSRui Paulo 	"\30WPA1\31WPA2\32DROPUNENC\33COUNTERM\34HIDESSID\35NOBRIDG\36PCF" \
55632176cfdSRui Paulo 	"\37DOTH\40DWDS"
55732176cfdSRui Paulo 
55832176cfdSRui Paulo /* Atheros protocol-specific flags */
55932176cfdSRui Paulo #define	IEEE80211_F_ATHEROS \
56032176cfdSRui Paulo 	(IEEE80211_F_FF | IEEE80211_F_COMP | IEEE80211_F_TURBOP)
56132176cfdSRui Paulo /* Check if an Atheros capability was negotiated for use */
56232176cfdSRui Paulo #define	IEEE80211_ATH_CAP(vap, ni, bit) \
56332176cfdSRui Paulo 	((vap)->iv_flags & (ni)->ni_ath_flags & (bit))
56432176cfdSRui Paulo 
56532176cfdSRui Paulo /* ic_flags_ext/iv_flags_ext */
56632176cfdSRui Paulo #define	IEEE80211_FEXT_INACT	 0x00000002	/* CONF: sta inact handling */
56732176cfdSRui Paulo #define	IEEE80211_FEXT_SCANWAIT	 0x00000004	/* STATUS: awaiting scan */
568841ab66cSSepherosa Ziehau /* 0x00000006 reserved */
56932176cfdSRui Paulo #define	IEEE80211_FEXT_BGSCAN	 0x00000008	/* STATUS: complete bgscan */
57032176cfdSRui Paulo #define	IEEE80211_FEXT_WPS	 0x00000010	/* CONF: WPS enabled */
57132176cfdSRui Paulo #define	IEEE80211_FEXT_TSN 	 0x00000020	/* CONF: TSN enabled */
57232176cfdSRui Paulo #define	IEEE80211_FEXT_SCANREQ	 0x00000040	/* STATUS: scan req params */
57332176cfdSRui Paulo #define	IEEE80211_FEXT_RESUME	 0x00000080	/* STATUS: start on resume */
57432176cfdSRui Paulo #define	IEEE80211_FEXT_4ADDR	 0x00000100	/* CONF: apply 4-addr encap */
57532176cfdSRui Paulo #define	IEEE80211_FEXT_NONERP_PR 0x00000200	/* STATUS: non-ERP sta present*/
576841ab66cSSepherosa Ziehau #define	IEEE80211_FEXT_SWBMISS	 0x00000400	/* CONF: do bmiss in s/w */
57732176cfdSRui Paulo #define	IEEE80211_FEXT_DFS	 0x00000800	/* CONF: DFS enabled */
57832176cfdSRui Paulo #define	IEEE80211_FEXT_DOTD	 0x00001000	/* CONF: 11d enabled */
57932176cfdSRui Paulo #define	IEEE80211_FEXT_STATEWAIT 0x00002000	/* STATUS: awaiting state chg */
58032176cfdSRui Paulo #define	IEEE80211_FEXT_REINIT	 0x00004000	/* STATUS: INIT state first */
58132176cfdSRui Paulo #define	IEEE80211_FEXT_BPF	 0x00008000	/* STATUS: BPF tap present */
58232176cfdSRui Paulo /* NB: immutable: should be set only when creating a vap */
58332176cfdSRui Paulo #define	IEEE80211_FEXT_WDSLEGACY 0x00010000	/* CONF: legacy WDS operation */
584841ab66cSSepherosa Ziehau #define	IEEE80211_FEXT_PROBECHAN 0x00020000	/* CONF: probe passive channel*/
58532176cfdSRui Paulo #define	IEEE80211_FEXT_UNIQMAC	 0x00040000	/* CONF: user or computed mac */
586f186073cSJoerg Sonnenberger 
58732176cfdSRui Paulo #define	IEEE80211_FEXT_BITS \
58832176cfdSRui Paulo 	"\20\2INACT\3SCANWAIT\4BGSCAN\5WPS\6TSN\7SCANREQ\10RESUME" \
58932176cfdSRui Paulo 	"\0114ADDR\12NONEPR_PR\13SWBMISS\14DFS\15DOTD\16STATEWAIT\17REINIT" \
59032176cfdSRui Paulo 	"\20BPF\21WDSLEGACY\22PROBECHAN\23UNIQMAC"
59132176cfdSRui Paulo 
59232176cfdSRui Paulo /* ic_flags_ht/iv_flags_ht */
59332176cfdSRui Paulo #define	IEEE80211_FHT_NONHT_PR	 0x00000001	/* STATUS: non-HT sta present */
59432176cfdSRui Paulo #define	IEEE80211_FHT_GF  	 0x00040000	/* CONF: Greenfield enabled */
59532176cfdSRui Paulo #define	IEEE80211_FHT_HT	 0x00080000	/* CONF: HT supported */
59632176cfdSRui Paulo #define	IEEE80211_FHT_AMPDU_TX	 0x00100000	/* CONF: A-MPDU tx supported */
59732176cfdSRui Paulo #define	IEEE80211_FHT_AMPDU_RX	 0x00200000	/* CONF: A-MPDU rx supported */
59832176cfdSRui Paulo #define	IEEE80211_FHT_AMSDU_TX	 0x00400000	/* CONF: A-MSDU tx supported */
59932176cfdSRui Paulo #define	IEEE80211_FHT_AMSDU_RX	 0x00800000	/* CONF: A-MSDU rx supported */
60032176cfdSRui Paulo #define	IEEE80211_FHT_USEHT40	 0x01000000	/* CONF: 20/40 use enabled */
60132176cfdSRui Paulo #define	IEEE80211_FHT_PUREN	 0x02000000	/* CONF: 11n w/o legacy sta's */
60232176cfdSRui Paulo #define	IEEE80211_FHT_SHORTGI20	 0x04000000	/* CONF: short GI in HT20 */
60332176cfdSRui Paulo #define	IEEE80211_FHT_SHORTGI40	 0x08000000	/* CONF: short GI in HT40 */
60432176cfdSRui Paulo #define	IEEE80211_FHT_HTCOMPAT 	 0x10000000	/* CONF: HT vendor OUI's */
60532176cfdSRui Paulo #define	IEEE80211_FHT_RIFS  	 0x20000000	/* CONF: RIFS enabled */
60632176cfdSRui Paulo #define	IEEE80211_FHT_STBC_TX 	 0x40000000	/* CONF: STBC tx enabled */
60732176cfdSRui Paulo #define	IEEE80211_FHT_STBC_RX 	 0x80000000	/* CONF: STBC rx enabled */
60832176cfdSRui Paulo 
60932176cfdSRui Paulo #define	IEEE80211_FHT_BITS \
61032176cfdSRui Paulo 	"\20\1NONHT_PR" \
611085ff963SMatthew Dillon 	"\23GF\24HT\25AMPDU_TX\26AMPDU_TX" \
61232176cfdSRui Paulo 	"\27AMSDU_TX\30AMSDU_RX\31USEHT40\32PUREN\33SHORTGI20\34SHORTGI40" \
61332176cfdSRui Paulo 	"\35HTCOMPAT\36RIFS\37STBC_TX\40STBC_RX"
61432176cfdSRui Paulo 
61532176cfdSRui Paulo #define	IEEE80211_FVEN_BITS	"\20"
61632176cfdSRui Paulo 
61732176cfdSRui Paulo /* ic_caps/iv_caps: device driver capabilities */
61832176cfdSRui Paulo /* 0x2e available */
61932176cfdSRui Paulo #define	IEEE80211_C_STA		0x00000001	/* CAPABILITY: STA available */
62032176cfdSRui Paulo #define	IEEE80211_C_8023ENCAP	0x00000002	/* CAPABILITY: 802.3 encap */
621841ab66cSSepherosa Ziehau #define	IEEE80211_C_FF		0x00000040	/* CAPABILITY: ATH FF avail */
622841ab66cSSepherosa Ziehau #define	IEEE80211_C_TURBOP	0x00000080	/* CAPABILITY: ATH Turbo avail*/
623841ab66cSSepherosa Ziehau #define	IEEE80211_C_IBSS	0x00000100	/* CAPABILITY: IBSS available */
624841ab66cSSepherosa Ziehau #define	IEEE80211_C_PMGT	0x00000200	/* CAPABILITY: Power mgmt */
625841ab66cSSepherosa Ziehau #define	IEEE80211_C_HOSTAP	0x00000400	/* CAPABILITY: HOSTAP avail */
626841ab66cSSepherosa Ziehau #define	IEEE80211_C_AHDEMO	0x00000800	/* CAPABILITY: Old Adhoc Demo */
627841ab66cSSepherosa Ziehau #define	IEEE80211_C_SWRETRY	0x00001000	/* CAPABILITY: sw tx retry */
628841ab66cSSepherosa Ziehau #define	IEEE80211_C_TXPMGT	0x00002000	/* CAPABILITY: tx power mgmt */
629841ab66cSSepherosa Ziehau #define	IEEE80211_C_SHSLOT	0x00004000	/* CAPABILITY: short slottime */
630841ab66cSSepherosa Ziehau #define	IEEE80211_C_SHPREAMBLE	0x00008000	/* CAPABILITY: short preamble */
631841ab66cSSepherosa Ziehau #define	IEEE80211_C_MONITOR	0x00010000	/* CAPABILITY: monitor mode */
63232176cfdSRui Paulo #define	IEEE80211_C_DFS		0x00020000	/* CAPABILITY: DFS/radar avail*/
63332176cfdSRui Paulo #define	IEEE80211_C_MBSS	0x00040000	/* CAPABILITY: MBSS available */
634d98a0bcfSMatthew Dillon #define	IEEE80211_C_SWSLEEP	0x00080000	/* CAPABILITY: do sleep here */
63532176cfdSRui Paulo /* 0x7c0000 available */
636841ab66cSSepherosa Ziehau #define	IEEE80211_C_WPA1	0x00800000	/* CAPABILITY: WPA1 avail */
637841ab66cSSepherosa Ziehau #define	IEEE80211_C_WPA2	0x01000000	/* CAPABILITY: WPA2 avail */
638841ab66cSSepherosa Ziehau #define	IEEE80211_C_WPA		0x01800000	/* CAPABILITY: WPA1+WPA2 avail*/
639841ab66cSSepherosa Ziehau #define	IEEE80211_C_BURST	0x02000000	/* CAPABILITY: frame bursting */
640841ab66cSSepherosa Ziehau #define	IEEE80211_C_WME		0x04000000	/* CAPABILITY: WME avail */
641841ab66cSSepherosa Ziehau #define	IEEE80211_C_WDS		0x08000000	/* CAPABILITY: 4-addr support */
642841ab66cSSepherosa Ziehau /* 0x10000000 reserved */
643841ab66cSSepherosa Ziehau #define	IEEE80211_C_BGSCAN	0x20000000	/* CAPABILITY: bg scanning */
644841ab66cSSepherosa Ziehau #define	IEEE80211_C_TXFRAG	0x40000000	/* CAPABILITY: tx fragments */
64532176cfdSRui Paulo #define	IEEE80211_C_TDMA	0x80000000	/* CAPABILITY: TDMA avail */
646841ab66cSSepherosa Ziehau /* XXX protection/barker? */
647f186073cSJoerg Sonnenberger 
64832176cfdSRui Paulo #define	IEEE80211_C_OPMODE \
64932176cfdSRui Paulo 	(IEEE80211_C_STA | IEEE80211_C_IBSS | IEEE80211_C_HOSTAP | \
65032176cfdSRui Paulo 	 IEEE80211_C_AHDEMO | IEEE80211_C_MONITOR | IEEE80211_C_WDS | \
65132176cfdSRui Paulo 	 IEEE80211_C_TDMA | IEEE80211_C_MBSS)
652f186073cSJoerg Sonnenberger 
65332176cfdSRui Paulo #define	IEEE80211_C_BITS \
65432176cfdSRui Paulo 	"\20\1STA\002803ENCAP\7FF\10TURBOP\11IBSS\12PMGT" \
65532176cfdSRui Paulo 	"\13HOSTAP\14AHDEMO\15SWRETRY\16TXPMGT\17SHSLOT\20SHPREAMBLE" \
65632176cfdSRui Paulo 	"\21MONITOR\22DFS\23MBSS\30WPA1\31WPA2\32BURST\33WME\34WDS\36BGSCAN" \
65732176cfdSRui Paulo 	"\37TXFRAG\40TDMA"
65821152d39SSepherosa Ziehau 
65932176cfdSRui Paulo /*
66032176cfdSRui Paulo  * ic_htcaps/iv_htcaps: HT-specific device/driver capabilities
66132176cfdSRui Paulo  *
66232176cfdSRui Paulo  * NB: the low 16-bits are the 802.11 definitions, the upper
66332176cfdSRui Paulo  *     16-bits are used to define s/w/driver capabilities.
66432176cfdSRui Paulo  */
66532176cfdSRui Paulo #define	IEEE80211_HTC_AMPDU	0x00010000	/* CAPABILITY: A-MPDU tx */
66632176cfdSRui Paulo #define	IEEE80211_HTC_AMSDU	0x00020000	/* CAPABILITY: A-MSDU tx */
66732176cfdSRui Paulo /* NB: HT40 is implied by IEEE80211_HTCAP_CHWIDTH40 */
66832176cfdSRui Paulo #define	IEEE80211_HTC_HT	0x00040000	/* CAPABILITY: HT operation */
66932176cfdSRui Paulo #define	IEEE80211_HTC_SMPS	0x00080000	/* CAPABILITY: MIMO power save*/
67032176cfdSRui Paulo #define	IEEE80211_HTC_RIFS	0x00100000	/* CAPABILITY: RIFS support */
671085ff963SMatthew Dillon #define	IEEE80211_HTC_RXUNEQUAL	0x00200000	/* CAPABILITY: RX unequal MCS */
672085ff963SMatthew Dillon #define	IEEE80211_HTC_RXMCS32	0x00400000	/* CAPABILITY: MCS32 support */
673085ff963SMatthew Dillon #define	IEEE80211_HTC_TXUNEQUAL	0x00800000	/* CAPABILITY: TX unequal MCS */
674085ff963SMatthew Dillon #define	IEEE80211_HTC_TXMCS32	0x01000000	/* CAPABILITY: MCS32 suport */
67532176cfdSRui Paulo 
67632176cfdSRui Paulo #define	IEEE80211_C_HTCAP_BITS \
67732176cfdSRui Paulo 	"\20\1LDPC\2CHWIDTH40\5GREENFIELD\6SHORTGI20\7SHORTGI40\10TXSTBC" \
67832176cfdSRui Paulo 	"\21AMPDU\22AMSDU\23HT\24SMPS\25RIFS"
67932176cfdSRui Paulo 
68032176cfdSRui Paulo void	ieee80211_ifattach(struct ieee80211com *,
68132176cfdSRui Paulo 		const uint8_t macaddr[IEEE80211_ADDR_LEN]);
682841ab66cSSepherosa Ziehau void	ieee80211_ifdetach(struct ieee80211com *);
68332176cfdSRui Paulo int	ieee80211_vap_setup(struct ieee80211com *, struct ieee80211vap *,
684085ff963SMatthew Dillon 		const char name[IFNAMSIZ], int unit,
685085ff963SMatthew Dillon 		enum ieee80211_opmode opmode, int flags,
68632176cfdSRui Paulo 		const uint8_t bssid[IEEE80211_ADDR_LEN],
68732176cfdSRui Paulo 		const uint8_t macaddr[IEEE80211_ADDR_LEN]);
68832176cfdSRui Paulo int	ieee80211_vap_attach(struct ieee80211vap *,
689841ab66cSSepherosa Ziehau 		ifm_change_cb_t, ifm_stat_cb_t);
69032176cfdSRui Paulo void	ieee80211_vap_detach(struct ieee80211vap *);
69132176cfdSRui Paulo const struct ieee80211_rateset *ieee80211_get_suprates(struct ieee80211com *ic,
69232176cfdSRui Paulo 		const struct ieee80211_channel *);
69332176cfdSRui Paulo void	ieee80211_announce(struct ieee80211com *);
69432176cfdSRui Paulo void	ieee80211_announce_channels(struct ieee80211com *);
69532176cfdSRui Paulo void	ieee80211_drain(struct ieee80211com *);
69632176cfdSRui Paulo void	ieee80211_media_init(struct ieee80211com *);
697841ab66cSSepherosa Ziehau struct ieee80211com *ieee80211_find_vap(const uint8_t mac[IEEE80211_ADDR_LEN]);
698f186073cSJoerg Sonnenberger int	ieee80211_media_change(struct ifnet *);
699f186073cSJoerg Sonnenberger void	ieee80211_media_status(struct ifnet *, struct ifmediareq *);
700085ff963SMatthew Dillon #if defined(__DragonFly__)
70134a60cf6SRui Paulo int	ieee80211_ioctl(struct ifnet *, u_long, caddr_t, struct ucred *);
702085ff963SMatthew Dillon #else
703085ff963SMatthew Dillon int	ieee80211_ioctl(struct ifnet *, u_long, caddr_t);
704085ff963SMatthew Dillon #endif
705f186073cSJoerg Sonnenberger int	ieee80211_rate2media(struct ieee80211com *, int,
706f186073cSJoerg Sonnenberger 		enum ieee80211_phymode);
707f186073cSJoerg Sonnenberger int	ieee80211_media2rate(int);
70832176cfdSRui Paulo int	ieee80211_mhz2ieee(u_int, u_int);
70932176cfdSRui Paulo int	ieee80211_chan2ieee(struct ieee80211com *,
71047f525a7SSepherosa Ziehau 		const struct ieee80211_channel *);
711f186073cSJoerg Sonnenberger u_int	ieee80211_ieee2mhz(u_int, u_int);
71232176cfdSRui Paulo struct ieee80211_channel *ieee80211_find_channel(struct ieee80211com *,
71332176cfdSRui Paulo 		int freq, int flags);
71432176cfdSRui Paulo struct ieee80211_channel *ieee80211_find_channel_byieee(struct ieee80211com *,
71532176cfdSRui Paulo 		int ieee, int flags);
716f186073cSJoerg Sonnenberger int	ieee80211_setmode(struct ieee80211com *, enum ieee80211_phymode);
71732176cfdSRui Paulo enum ieee80211_phymode ieee80211_chan2mode(const struct ieee80211_channel *);
71832176cfdSRui Paulo uint32_t ieee80211_mac_hash(const struct ieee80211com *,
71932176cfdSRui Paulo 		const uint8_t addr[IEEE80211_ADDR_LEN]);
720f186073cSJoerg Sonnenberger 
72132176cfdSRui Paulo void	ieee80211_radiotap_attach(struct ieee80211com *,
72232176cfdSRui Paulo 	    struct ieee80211_radiotap_header *th, int tlen,
72332176cfdSRui Paulo 		uint32_t tx_radiotap,
72432176cfdSRui Paulo 	    struct ieee80211_radiotap_header *rh, int rlen,
72532176cfdSRui Paulo 		uint32_t rx_radiotap);
726085ff963SMatthew Dillon void	ieee80211_radiotap_attachv(struct ieee80211com *,
727085ff963SMatthew Dillon 	    struct ieee80211_radiotap_header *th,
728085ff963SMatthew Dillon 	    int tlen, int n_tx_v, uint32_t tx_radiotap,
729085ff963SMatthew Dillon 	    struct ieee80211_radiotap_header *rh,
730085ff963SMatthew Dillon 	    int rlen, int n_rx_v, uint32_t rx_radiotap);
73132176cfdSRui Paulo void	ieee80211_radiotap_detach(struct ieee80211com *);
73232176cfdSRui Paulo void	ieee80211_radiotap_vattach(struct ieee80211vap *);
73332176cfdSRui Paulo void	ieee80211_radiotap_vdetach(struct ieee80211vap *);
73432176cfdSRui Paulo void	ieee80211_radiotap_chan_change(struct ieee80211com *);
73532176cfdSRui Paulo void	ieee80211_radiotap_tx(struct ieee80211vap *, struct mbuf *);
73632176cfdSRui Paulo void	ieee80211_radiotap_rx(struct ieee80211vap *, struct mbuf *);
73732176cfdSRui Paulo void	ieee80211_radiotap_rx_all(struct ieee80211com *, struct mbuf *);
73832176cfdSRui Paulo 
73932176cfdSRui Paulo static __inline int
74032176cfdSRui Paulo ieee80211_radiotap_active(const struct ieee80211com *ic)
74132176cfdSRui Paulo {
74232176cfdSRui Paulo 	return (ic->ic_flags_ext & IEEE80211_FEXT_BPF) != 0;
74332176cfdSRui Paulo }
74432176cfdSRui Paulo 
74532176cfdSRui Paulo static __inline int
74632176cfdSRui Paulo ieee80211_radiotap_active_vap(const struct ieee80211vap *vap)
74732176cfdSRui Paulo {
74832176cfdSRui Paulo 	return (vap->iv_flags_ext & IEEE80211_FEXT_BPF) ||
74932176cfdSRui Paulo 	    vap->iv_ic->ic_montaps != 0;
75032176cfdSRui Paulo }
75132176cfdSRui Paulo 
75232176cfdSRui Paulo /*
75332176cfdSRui Paulo  * Enqueue a task on the state thread.
75432176cfdSRui Paulo  */
75532176cfdSRui Paulo static __inline void
75632176cfdSRui Paulo ieee80211_runtask(struct ieee80211com *ic, struct task *task)
75732176cfdSRui Paulo {
75832176cfdSRui Paulo 	taskqueue_enqueue(ic->ic_tq, task);
75932176cfdSRui Paulo }
76032176cfdSRui Paulo 
76132176cfdSRui Paulo /*
76232176cfdSRui Paulo  * Wait for a queued task to complete.
76332176cfdSRui Paulo  */
76432176cfdSRui Paulo static __inline void
76532176cfdSRui Paulo ieee80211_draintask(struct ieee80211com *ic, struct task *task)
76632176cfdSRui Paulo {
76732176cfdSRui Paulo 	taskqueue_drain(ic->ic_tq, task);
76832176cfdSRui Paulo }
769841ab66cSSepherosa Ziehau 
770841ab66cSSepherosa Ziehau /*
771841ab66cSSepherosa Ziehau  * Key update synchronization methods.  XXX should not be visible.
772841ab66cSSepherosa Ziehau  */
773841ab66cSSepherosa Ziehau static __inline void
77432176cfdSRui Paulo ieee80211_key_update_begin(struct ieee80211vap *vap)
775841ab66cSSepherosa Ziehau {
77632176cfdSRui Paulo 	vap->iv_key_update_begin(vap);
777841ab66cSSepherosa Ziehau }
778841ab66cSSepherosa Ziehau static __inline void
77932176cfdSRui Paulo ieee80211_key_update_end(struct ieee80211vap *vap)
780841ab66cSSepherosa Ziehau {
78132176cfdSRui Paulo 	vap->iv_key_update_end(vap);
782841ab66cSSepherosa Ziehau }
783841ab66cSSepherosa Ziehau 
784841ab66cSSepherosa Ziehau /*
785841ab66cSSepherosa Ziehau  * XXX these need to be here for IEEE80211_F_DATAPAD
786841ab66cSSepherosa Ziehau  */
787841ab66cSSepherosa Ziehau 
788841ab66cSSepherosa Ziehau /*
789841ab66cSSepherosa Ziehau  * Return the space occupied by the 802.11 header and any
790841ab66cSSepherosa Ziehau  * padding required by the driver.  This works for a
791841ab66cSSepherosa Ziehau  * management or data frame.
792841ab66cSSepherosa Ziehau  */
793841ab66cSSepherosa Ziehau static __inline int
794841ab66cSSepherosa Ziehau ieee80211_hdrspace(struct ieee80211com *ic, const void *data)
795841ab66cSSepherosa Ziehau {
796841ab66cSSepherosa Ziehau 	int size = ieee80211_hdrsize(data);
797841ab66cSSepherosa Ziehau 	if (ic->ic_flags & IEEE80211_F_DATAPAD)
798841ab66cSSepherosa Ziehau 		size = roundup(size, sizeof(uint32_t));
799841ab66cSSepherosa Ziehau 	return size;
800841ab66cSSepherosa Ziehau }
801841ab66cSSepherosa Ziehau 
802841ab66cSSepherosa Ziehau /*
803841ab66cSSepherosa Ziehau  * Like ieee80211_hdrspace, but handles any type of frame.
804841ab66cSSepherosa Ziehau  */
805841ab66cSSepherosa Ziehau static __inline int
806841ab66cSSepherosa Ziehau ieee80211_anyhdrspace(struct ieee80211com *ic, const void *data)
807841ab66cSSepherosa Ziehau {
808841ab66cSSepherosa Ziehau 	int size = ieee80211_anyhdrsize(data);
809841ab66cSSepherosa Ziehau 	if (ic->ic_flags & IEEE80211_F_DATAPAD)
810841ab66cSSepherosa Ziehau 		size = roundup(size, sizeof(uint32_t));
811841ab66cSSepherosa Ziehau 	return size;
812841ab66cSSepherosa Ziehau }
813841ab66cSSepherosa Ziehau 
81432176cfdSRui Paulo /*
81532176cfdSRui Paulo  * Notify a vap that beacon state has been updated.
81632176cfdSRui Paulo  */
81732176cfdSRui Paulo static __inline void
81832176cfdSRui Paulo ieee80211_beacon_notify(struct ieee80211vap *vap, int what)
81932176cfdSRui Paulo {
82032176cfdSRui Paulo 	if (vap->iv_state == IEEE80211_S_RUN)
82132176cfdSRui Paulo 		vap->iv_update_beacon(vap, what);
82232176cfdSRui Paulo }
823820cef05SSepherosa Ziehau 
82432176cfdSRui Paulo /*
82532176cfdSRui Paulo  * Calculate HT channel promotion flags for a channel.
82632176cfdSRui Paulo  * XXX belongs in ieee80211_ht.h but needs IEEE80211_FHT_*
82732176cfdSRui Paulo  */
82832176cfdSRui Paulo static __inline int
82932176cfdSRui Paulo ieee80211_htchanflags(const struct ieee80211_channel *c)
83032176cfdSRui Paulo {
83132176cfdSRui Paulo 	return IEEE80211_IS_CHAN_HT40(c) ?
83232176cfdSRui Paulo 	    IEEE80211_FHT_HT | IEEE80211_FHT_USEHT40 :
83332176cfdSRui Paulo 	    IEEE80211_IS_CHAN_HT(c) ?  IEEE80211_FHT_HT : 0;
83432176cfdSRui Paulo }
83532176cfdSRui Paulo 
83632176cfdSRui Paulo /*
837f501b47dSMatthew Dillon  * Fetch the current TX power (cap) for the given node.
838f501b47dSMatthew Dillon  *
839f501b47dSMatthew Dillon  * This includes the node and ic/vap TX power limit as needed,
840f501b47dSMatthew Dillon  * but it doesn't take into account any per-rate limit.
841f501b47dSMatthew Dillon  */
842f501b47dSMatthew Dillon static __inline uint16_t
843f501b47dSMatthew Dillon ieee80211_get_node_txpower(struct ieee80211_node *ni)
844f501b47dSMatthew Dillon {
845f501b47dSMatthew Dillon 	struct ieee80211com *ic = ni->ni_ic;
846f501b47dSMatthew Dillon 	uint16_t txpower;
847f501b47dSMatthew Dillon 
848f501b47dSMatthew Dillon 	txpower = ni->ni_txpower;
849f501b47dSMatthew Dillon 	txpower = MIN(txpower, ic->ic_txpowlimit);
850f501b47dSMatthew Dillon 	if (ic->ic_curchan != NULL) {
851f501b47dSMatthew Dillon 		txpower = MIN(txpower, 2 * ic->ic_curchan->ic_maxregpower);
852f501b47dSMatthew Dillon 		txpower = MIN(txpower, ic->ic_curchan->ic_maxpower);
853f501b47dSMatthew Dillon 	}
854f501b47dSMatthew Dillon 
855f501b47dSMatthew Dillon 	return (txpower);
856f501b47dSMatthew Dillon }
857f501b47dSMatthew Dillon 
858f501b47dSMatthew Dillon /*
85932176cfdSRui Paulo  * Debugging facilities compiled in when IEEE80211_DEBUG is defined.
86032176cfdSRui Paulo  *
86132176cfdSRui Paulo  * The intent is that any problem in the net80211 layer can be
86232176cfdSRui Paulo  * diagnosed by inspecting the statistics (dumped by the wlanstats
86332176cfdSRui Paulo  * program) and/or the msgs generated by net80211.  Messages are
86432176cfdSRui Paulo  * broken into functional classes and can be controlled with the
86532176cfdSRui Paulo  * wlandebug program.  Certain of these msg groups are for facilities
86632176cfdSRui Paulo  * that are no longer part of net80211 (e.g. IEEE80211_MSG_DOT1XSM).
86732176cfdSRui Paulo  */
86832176cfdSRui Paulo #define	IEEE80211_MSG_11N	0x80000000	/* 11n mode debug */
869841ab66cSSepherosa Ziehau #define	IEEE80211_MSG_DEBUG	0x40000000	/* IFF_DEBUG equivalent */
870841ab66cSSepherosa Ziehau #define	IEEE80211_MSG_DUMPPKTS	0x20000000	/* IFF_LINK2 equivalant */
871841ab66cSSepherosa Ziehau #define	IEEE80211_MSG_CRYPTO	0x10000000	/* crypto work */
872841ab66cSSepherosa Ziehau #define	IEEE80211_MSG_INPUT	0x08000000	/* input handling */
873841ab66cSSepherosa Ziehau #define	IEEE80211_MSG_XRATE	0x04000000	/* rate set handling */
874841ab66cSSepherosa Ziehau #define	IEEE80211_MSG_ELEMID	0x02000000	/* element id parsing */
875841ab66cSSepherosa Ziehau #define	IEEE80211_MSG_NODE	0x01000000	/* node handling */
876841ab66cSSepherosa Ziehau #define	IEEE80211_MSG_ASSOC	0x00800000	/* association handling */
877841ab66cSSepherosa Ziehau #define	IEEE80211_MSG_AUTH	0x00400000	/* authentication handling */
878841ab66cSSepherosa Ziehau #define	IEEE80211_MSG_SCAN	0x00200000	/* scanning */
879841ab66cSSepherosa Ziehau #define	IEEE80211_MSG_OUTPUT	0x00100000	/* output handling */
880841ab66cSSepherosa Ziehau #define	IEEE80211_MSG_STATE	0x00080000	/* state machine */
881841ab66cSSepherosa Ziehau #define	IEEE80211_MSG_POWER	0x00040000	/* power save handling */
88232176cfdSRui Paulo #define	IEEE80211_MSG_HWMP	0x00020000	/* hybrid mesh protocol */
883841ab66cSSepherosa Ziehau #define	IEEE80211_MSG_DOT1XSM	0x00010000	/* 802.1x state machine */
884841ab66cSSepherosa Ziehau #define	IEEE80211_MSG_RADIUS	0x00008000	/* 802.1x radius client */
885841ab66cSSepherosa Ziehau #define	IEEE80211_MSG_RADDUMP	0x00004000	/* dump 802.1x radius packets */
88632176cfdSRui Paulo #define	IEEE80211_MSG_MESH	0x00002000	/* mesh networking */
887841ab66cSSepherosa Ziehau #define	IEEE80211_MSG_WPA	0x00001000	/* WPA/RSN protocol */
888841ab66cSSepherosa Ziehau #define	IEEE80211_MSG_ACL	0x00000800	/* ACL handling */
889841ab66cSSepherosa Ziehau #define	IEEE80211_MSG_WME	0x00000400	/* WME protocol */
890841ab66cSSepherosa Ziehau #define	IEEE80211_MSG_SUPERG	0x00000200	/* Atheros SuperG protocol */
891841ab66cSSepherosa Ziehau #define	IEEE80211_MSG_DOTH	0x00000100	/* 802.11h support */
892841ab66cSSepherosa Ziehau #define	IEEE80211_MSG_INACT	0x00000080	/* inactivity handling */
893841ab66cSSepherosa Ziehau #define	IEEE80211_MSG_ROAM	0x00000040	/* sta-mode roaming */
89432176cfdSRui Paulo #define	IEEE80211_MSG_RATECTL	0x00000020	/* tx rate control */
89532176cfdSRui Paulo #define	IEEE80211_MSG_ACTION	0x00000010	/* action frame handling */
89632176cfdSRui Paulo #define	IEEE80211_MSG_WDS	0x00000008	/* WDS handling */
89732176cfdSRui Paulo #define	IEEE80211_MSG_IOCTL	0x00000004	/* ioctl handling */
89832176cfdSRui Paulo #define	IEEE80211_MSG_TDMA	0x00000002	/* TDMA handling */
899841ab66cSSepherosa Ziehau 
900841ab66cSSepherosa Ziehau #define	IEEE80211_MSG_ANY	0xffffffff	/* anything */
901841ab66cSSepherosa Ziehau 
90232176cfdSRui Paulo #define	IEEE80211_MSG_BITS \
90332176cfdSRui Paulo 	"\20\2TDMA\3IOCTL\4WDS\5ACTION\6RATECTL\7ROAM\10INACT\11DOTH\12SUPERG" \
90432176cfdSRui Paulo 	"\13WME\14ACL\15WPA\16RADKEYS\17RADDUMP\20RADIUS\21DOT1XSM\22HWMP" \
90532176cfdSRui Paulo 	"\23POWER\24STATE\25OUTPUT\26SCAN\27AUTH\30ASSOC\31NODE\32ELEMID" \
90632176cfdSRui Paulo 	"\33XRATE\34INPUT\35CRYPTO\36DUPMPKTS\37DEBUG\04011N"
907820cef05SSepherosa Ziehau 
908f186073cSJoerg Sonnenberger #ifdef IEEE80211_DEBUG
90932176cfdSRui Paulo #define	ieee80211_msg(_vap, _m)	((_vap)->iv_debug & (_m))
91032176cfdSRui Paulo #define	IEEE80211_DPRINTF(_vap, _m, _fmt, ...) do {			\
91132176cfdSRui Paulo 	if (ieee80211_msg(_vap, _m))					\
91232176cfdSRui Paulo 		ieee80211_note(_vap, _fmt, __VA_ARGS__);		\
913841ab66cSSepherosa Ziehau } while (0)
91432176cfdSRui Paulo #define	IEEE80211_NOTE(_vap, _m, _ni, _fmt, ...) do {			\
91532176cfdSRui Paulo 	if (ieee80211_msg(_vap, _m))					\
91632176cfdSRui Paulo 		ieee80211_note_mac(_vap, (_ni)->ni_macaddr, _fmt, __VA_ARGS__);\
917476d885dSSepherosa Ziehau } while (0)
91832176cfdSRui Paulo #define	IEEE80211_NOTE_MAC(_vap, _m, _mac, _fmt, ...) do {		\
91932176cfdSRui Paulo 	if (ieee80211_msg(_vap, _m))					\
92032176cfdSRui Paulo 		ieee80211_note_mac(_vap, _mac, _fmt, __VA_ARGS__);	\
921841ab66cSSepherosa Ziehau } while (0)
92232176cfdSRui Paulo #define	IEEE80211_NOTE_FRAME(_vap, _m, _wh, _fmt, ...) do {		\
92332176cfdSRui Paulo 	if (ieee80211_msg(_vap, _m))					\
92432176cfdSRui Paulo 		ieee80211_note_frame(_vap, _wh, _fmt, __VA_ARGS__);	\
925841ab66cSSepherosa Ziehau } while (0)
926f92fae3fSSascha Wildner void	ieee80211_note(const struct ieee80211vap *, const char *, ...)
927f92fae3fSSascha Wildner 		__printflike(2, 3);
928085ff963SMatthew Dillon void	ieee80211_note_mac(const struct ieee80211vap *,
929f92fae3fSSascha Wildner 		const uint8_t mac[IEEE80211_ADDR_LEN], const char *, ...)
930f92fae3fSSascha Wildner 		__printflike(3, 4);
931085ff963SMatthew Dillon void	ieee80211_note_frame(const struct ieee80211vap *,
932f92fae3fSSascha Wildner 		const struct ieee80211_frame *, const char *, ...)
933f92fae3fSSascha Wildner 		__printflike(3, 4);
93432176cfdSRui Paulo #define	ieee80211_msg_debug(_vap) \
93532176cfdSRui Paulo 	((_vap)->iv_debug & IEEE80211_MSG_DEBUG)
93632176cfdSRui Paulo #define	ieee80211_msg_dumppkts(_vap) \
93732176cfdSRui Paulo 	((_vap)->iv_debug & IEEE80211_MSG_DUMPPKTS)
93832176cfdSRui Paulo #define	ieee80211_msg_input(_vap) \
93932176cfdSRui Paulo 	((_vap)->iv_debug & IEEE80211_MSG_INPUT)
94032176cfdSRui Paulo #define	ieee80211_msg_radius(_vap) \
94132176cfdSRui Paulo 	((_vap)->iv_debug & IEEE80211_MSG_RADIUS)
94232176cfdSRui Paulo #define	ieee80211_msg_dumpradius(_vap) \
94332176cfdSRui Paulo 	((_vap)->iv_debug & IEEE80211_MSG_RADDUMP)
94432176cfdSRui Paulo #define	ieee80211_msg_dumpradkeys(_vap) \
94532176cfdSRui Paulo 	((_vap)->iv_debug & IEEE80211_MSG_RADKEYS)
94632176cfdSRui Paulo #define	ieee80211_msg_scan(_vap) \
94732176cfdSRui Paulo 	((_vap)->iv_debug & IEEE80211_MSG_SCAN)
94832176cfdSRui Paulo #define	ieee80211_msg_assoc(_vap) \
94932176cfdSRui Paulo 	((_vap)->iv_debug & IEEE80211_MSG_ASSOC)
950f186073cSJoerg Sonnenberger 
95132176cfdSRui Paulo /*
95232176cfdSRui Paulo  * Emit a debug message about discarding a frame or information
95332176cfdSRui Paulo  * element.  One format is for extracting the mac address from
95432176cfdSRui Paulo  * the frame header; the other is for when a header is not
95532176cfdSRui Paulo  * available or otherwise appropriate.
95632176cfdSRui Paulo  */
95732176cfdSRui Paulo #define	IEEE80211_DISCARD(_vap, _m, _wh, _type, _fmt, ...) do {		\
95832176cfdSRui Paulo 	if ((_vap)->iv_debug & (_m))					\
95932176cfdSRui Paulo 		ieee80211_discard_frame(_vap, _wh, _type, _fmt, __VA_ARGS__);\
96032176cfdSRui Paulo } while (0)
96132176cfdSRui Paulo #define	IEEE80211_DISCARD_IE(_vap, _m, _wh, _type, _fmt, ...) do {	\
96232176cfdSRui Paulo 	if ((_vap)->iv_debug & (_m))					\
96332176cfdSRui Paulo 		ieee80211_discard_ie(_vap, _wh, _type, _fmt, __VA_ARGS__);\
96432176cfdSRui Paulo } while (0)
96532176cfdSRui Paulo #define	IEEE80211_DISCARD_MAC(_vap, _m, _mac, _type, _fmt, ...) do {	\
96632176cfdSRui Paulo 	if ((_vap)->iv_debug & (_m))					\
96732176cfdSRui Paulo 		ieee80211_discard_mac(_vap, _mac, _type, _fmt, __VA_ARGS__);\
96832176cfdSRui Paulo } while (0)
96932176cfdSRui Paulo 
970085ff963SMatthew Dillon void ieee80211_discard_frame(const struct ieee80211vap *,
971f92fae3fSSascha Wildner 	const struct ieee80211_frame *, const char *type, const char *fmt, ...)
972f92fae3fSSascha Wildner 	__printflike(4, 5);
973085ff963SMatthew Dillon void ieee80211_discard_ie(const struct ieee80211vap *,
974f92fae3fSSascha Wildner 	const struct ieee80211_frame *, const char *type, const char *fmt, ...)
975f92fae3fSSascha Wildner 	__printflike(4, 5);
976085ff963SMatthew Dillon void ieee80211_discard_mac(const struct ieee80211vap *,
977085ff963SMatthew Dillon 	const uint8_t mac[IEEE80211_ADDR_LEN], const char *type,
978f92fae3fSSascha Wildner 	const char *fmt, ...)
979f92fae3fSSascha Wildner 	__printflike(4, 5);
98032176cfdSRui Paulo #else
98132176cfdSRui Paulo #define	IEEE80211_DPRINTF(_vap, _m, _fmt, ...)
98232176cfdSRui Paulo #define	IEEE80211_NOTE(_vap, _m, _ni, _fmt, ...)
98332176cfdSRui Paulo #define	IEEE80211_NOTE_FRAME(_vap, _m, _wh, _fmt, ...)
98432176cfdSRui Paulo #define	IEEE80211_NOTE_MAC(_vap, _m, _mac, _fmt, ...)
98532176cfdSRui Paulo #define	ieee80211_msg_dumppkts(_vap)	0
98632176cfdSRui Paulo #define	ieee80211_msg(_vap, _m)		0
98732176cfdSRui Paulo 
98832176cfdSRui Paulo #define	IEEE80211_DISCARD(_vap, _m, _wh, _type, _fmt, ...)
98932176cfdSRui Paulo #define	IEEE80211_DISCARD_IE(_vap, _m, _wh, _type, _fmt, ...)
99032176cfdSRui Paulo #define	IEEE80211_DISCARD_MAC(_vap, _m, _mac, _type, _fmt, ...)
99132176cfdSRui Paulo #endif
992820cef05SSepherosa Ziehau 
993841ab66cSSepherosa Ziehau #endif /* _NET80211_IEEE80211_VAR_H_ */
994