xref: /dflybsd-src/sys/netproto/802_11/ieee80211_node.h (revision 805c8e8e4093ceca2e27510ad3a66d4de8060a55)
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_NODE_H_
29841ab66cSSepherosa Ziehau #define _NET80211_IEEE80211_NODE_H_
30f186073cSJoerg Sonnenberger 
31841ab66cSSepherosa Ziehau #include <netproto/802_11/ieee80211_ioctl.h>		/* for ieee80211_nodestats */
3232176cfdSRui Paulo #include <netproto/802_11/ieee80211_ht.h>		/* for aggregation state */
33f186073cSJoerg Sonnenberger 
34841ab66cSSepherosa Ziehau /*
3532176cfdSRui Paulo  * Each ieee80211com instance has a single timer that fires every
3632176cfdSRui Paulo  * IEEE80211_INACT_WAIT seconds to handle "inactivity processing".
3732176cfdSRui Paulo  * This is used to do node inactivity processing when operating
3832176cfdSRui Paulo  * as an AP, adhoc or mesh mode.  For inactivity processing each node
3932176cfdSRui Paulo  * has a timeout set in it's ni_inact field that is decremented
4032176cfdSRui Paulo  * on each timeout and the node is reclaimed when the counter goes
4132176cfdSRui Paulo  * to zero.  We use different inactivity timeout values depending
4232176cfdSRui Paulo  * on whether the node is associated and authorized (either by
4332176cfdSRui Paulo  * 802.1x or open/shared key authentication) or associated but yet
4432176cfdSRui Paulo  * to be authorized.  The latter timeout is shorter to more aggressively
45841ab66cSSepherosa Ziehau  * reclaim nodes that leave part way through the 802.1x exchange.
46841ab66cSSepherosa Ziehau  */
47841ab66cSSepherosa Ziehau #define	IEEE80211_INACT_WAIT	15		/* inactivity interval (secs) */
48841ab66cSSepherosa Ziehau #define	IEEE80211_INACT_INIT	(30/IEEE80211_INACT_WAIT)	/* initial */
49841ab66cSSepherosa Ziehau #define	IEEE80211_INACT_AUTH	(180/IEEE80211_INACT_WAIT)	/* associated but not authorized */
50841ab66cSSepherosa Ziehau #define	IEEE80211_INACT_RUN	(300/IEEE80211_INACT_WAIT)	/* authorized */
51841ab66cSSepherosa Ziehau #define	IEEE80211_INACT_PROBE	(30/IEEE80211_INACT_WAIT)	/* probe */
52841ab66cSSepherosa Ziehau #define	IEEE80211_INACT_SCAN	(300/IEEE80211_INACT_WAIT)	/* scanned */
53841ab66cSSepherosa Ziehau 
5432176cfdSRui Paulo #define	IEEE80211_TRANS_WAIT 	2		/* mgt frame tx timer (secs) */
55f186073cSJoerg Sonnenberger 
5632176cfdSRui Paulo /* threshold for aging overlapping non-ERP bss */
5732176cfdSRui Paulo #define	IEEE80211_NONERP_PRESENT_AGE	msecs_to_ticks(60*1000)
5832176cfdSRui Paulo 
5932176cfdSRui Paulo #define	IEEE80211_NODE_HASHSIZE	32		/* NB: hash size must be pow2 */
60f186073cSJoerg Sonnenberger /* simple hash is enough for variation of macaddr */
6132176cfdSRui Paulo #define	IEEE80211_NODE_HASH(ic, addr)	\
62841ab66cSSepherosa Ziehau 	(((const uint8_t *)(addr))[IEEE80211_ADDR_LEN - 1] % \
63841ab66cSSepherosa Ziehau 		IEEE80211_NODE_HASHSIZE)
64f186073cSJoerg Sonnenberger 
65841ab66cSSepherosa Ziehau struct ieee80211_node_table;
66841ab66cSSepherosa Ziehau struct ieee80211com;
6732176cfdSRui Paulo struct ieee80211vap;
6832176cfdSRui Paulo 
6932176cfdSRui Paulo /*
7032176cfdSRui Paulo  * Information element ``blob''.  We use this structure
7132176cfdSRui Paulo  * to capture management frame payloads that need to be
7232176cfdSRui Paulo  * retained.  Information elements within the payload that
7332176cfdSRui Paulo  * we need to consult have references recorded.
7432176cfdSRui Paulo  */
7532176cfdSRui Paulo struct ieee80211_ies {
7632176cfdSRui Paulo 	/* the following are either NULL or point within data */
7732176cfdSRui Paulo 	uint8_t	*wpa_ie;	/* captured WPA ie */
7832176cfdSRui Paulo 	uint8_t	*rsn_ie;	/* captured RSN ie */
7932176cfdSRui Paulo 	uint8_t	*wme_ie;	/* captured WME ie */
8032176cfdSRui Paulo 	uint8_t	*ath_ie;	/* captured Atheros ie */
8132176cfdSRui Paulo 	uint8_t	*htcap_ie;	/* captured HTCAP ie */
8232176cfdSRui Paulo 	uint8_t	*htinfo_ie;	/* captured HTINFO ie */
8332176cfdSRui Paulo 	uint8_t	*tdma_ie;	/* captured TDMA ie */
8432176cfdSRui Paulo 	uint8_t *meshid_ie;	/* captured MESH ID ie */
8532176cfdSRui Paulo 	uint8_t	*spare[4];
8632176cfdSRui Paulo 	/* NB: these must be the last members of this structure */
8732176cfdSRui Paulo 	uint8_t	*data;		/* frame data > 802.11 header */
8832176cfdSRui Paulo 	int	len;		/* data size in bytes */
8932176cfdSRui Paulo };
9032176cfdSRui Paulo 
9132176cfdSRui Paulo /*
9232176cfdSRui Paulo  * 802.11s (Mesh) Peer Link FSM state.
9332176cfdSRui Paulo  */
9432176cfdSRui Paulo enum ieee80211_mesh_mlstate {
9532176cfdSRui Paulo 	IEEE80211_NODE_MESH_IDLE	= 0,
9632176cfdSRui Paulo 	IEEE80211_NODE_MESH_OPENSNT	= 1,	/* open frame sent */
9732176cfdSRui Paulo 	IEEE80211_NODE_MESH_OPENRCV	= 2,	/* open frame received */
9832176cfdSRui Paulo 	IEEE80211_NODE_MESH_CONFIRMRCV	= 3,	/* confirm frame received */
9932176cfdSRui Paulo 	IEEE80211_NODE_MESH_ESTABLISHED	= 4,	/* link established */
10032176cfdSRui Paulo 	IEEE80211_NODE_MESH_HOLDING	= 5,	/* link closing */
10132176cfdSRui Paulo };
10232176cfdSRui Paulo #define	IEEE80211_MESH_MLSTATE_BITS \
10332176cfdSRui Paulo 	"\20\1IDLE\2OPENSNT\2OPENRCV\3CONFIRMRCV\4ESTABLISHED\5HOLDING"
104841ab66cSSepherosa Ziehau 
105f186073cSJoerg Sonnenberger /*
106f186073cSJoerg Sonnenberger  * Node specific information.  Note that drivers are expected
107f186073cSJoerg Sonnenberger  * to derive from this structure to add device-specific per-node
108f186073cSJoerg Sonnenberger  * state.  This is done by overriding the ic_node_* methods in
109f186073cSJoerg Sonnenberger  * the ieee80211com structure.
110f186073cSJoerg Sonnenberger  */
111f186073cSJoerg Sonnenberger struct ieee80211_node {
11232176cfdSRui Paulo 	struct ieee80211vap	*ni_vap;	/* associated vap */
11332176cfdSRui Paulo 	struct ieee80211com	*ni_ic;		/* copy from vap to save deref*/
11432176cfdSRui Paulo 	struct ieee80211_node_table *ni_table;	/* NB: may be NULL */
11532176cfdSRui Paulo 	TAILQ_ENTRY(ieee80211_node) ni_list;	/* list of all nodes */
11632176cfdSRui Paulo 	LIST_ENTRY(ieee80211_node) ni_hash;	/* hash collision list */
11732176cfdSRui Paulo 	u_int			ni_refcnt;	/* count of held references */
11832176cfdSRui Paulo 	u_int			ni_scangen;	/* gen# for timeout scan */
11932176cfdSRui Paulo 	u_int			ni_flags;
12032176cfdSRui Paulo #define	IEEE80211_NODE_AUTH	0x000001	/* authorized for data */
12132176cfdSRui Paulo #define	IEEE80211_NODE_QOS	0x000002	/* QoS enabled */
12232176cfdSRui Paulo #define	IEEE80211_NODE_ERP	0x000004	/* ERP enabled */
123841ab66cSSepherosa Ziehau /* NB: this must have the same value as IEEE80211_FC1_PWR_MGT */
12432176cfdSRui Paulo #define	IEEE80211_NODE_PWR_MGT	0x000010	/* power save mode enabled */
12532176cfdSRui Paulo #define	IEEE80211_NODE_AREF	0x000020	/* authentication ref held */
12632176cfdSRui Paulo #define	IEEE80211_NODE_HT	0x000040	/* HT enabled */
12732176cfdSRui Paulo #define	IEEE80211_NODE_HTCOMPAT	0x000080	/* HT setup w/ vendor OUI's */
12832176cfdSRui Paulo #define	IEEE80211_NODE_WPS	0x000100	/* WPS association */
12932176cfdSRui Paulo #define	IEEE80211_NODE_TSN	0x000200	/* TSN association */
13032176cfdSRui Paulo #define	IEEE80211_NODE_AMPDU_RX	0x000400	/* AMPDU rx enabled */
13132176cfdSRui Paulo #define	IEEE80211_NODE_AMPDU_TX	0x000800	/* AMPDU tx enabled */
13232176cfdSRui Paulo #define	IEEE80211_NODE_MIMO_PS	0x001000	/* MIMO power save enabled */
13332176cfdSRui Paulo #define	IEEE80211_NODE_MIMO_RTS	0x002000	/* send RTS in MIMO PS */
13432176cfdSRui Paulo #define	IEEE80211_NODE_RIFS	0x004000	/* RIFS enabled */
13532176cfdSRui Paulo #define	IEEE80211_NODE_SGI20	0x008000	/* Short GI in HT20 enabled */
13632176cfdSRui Paulo #define	IEEE80211_NODE_SGI40	0x010000	/* Short GI in HT40 enabled */
13732176cfdSRui Paulo #define	IEEE80211_NODE_ASSOCID	0x020000	/* xmit requires associd */
13832176cfdSRui Paulo #define	IEEE80211_NODE_AMSDU_RX	0x040000	/* AMSDU rx enabled */
13932176cfdSRui Paulo #define	IEEE80211_NODE_AMSDU_TX	0x080000	/* AMSDU tx enabled */
14032176cfdSRui Paulo 	uint16_t		ni_associd;	/* association ID */
141841ab66cSSepherosa Ziehau 	uint16_t		ni_vlan;	/* vlan tag */
14232176cfdSRui Paulo 	uint16_t		ni_txpower;	/* current transmit power */
14332176cfdSRui Paulo 	uint8_t			ni_authmode;	/* authentication algorithm */
14432176cfdSRui Paulo 	uint8_t			ni_ath_flags;	/* Atheros feature flags */
14532176cfdSRui Paulo 	/* NB: These must have the same values as IEEE80211_ATHC_* */
14632176cfdSRui Paulo #define IEEE80211_NODE_TURBOP	0x0001		/* Turbo prime enable */
14732176cfdSRui Paulo #define IEEE80211_NODE_COMP	0x0002		/* Compresssion enable */
14832176cfdSRui Paulo #define IEEE80211_NODE_FF	0x0004          /* Fast Frame capable */
14932176cfdSRui Paulo #define IEEE80211_NODE_XR	0x0008		/* Atheros WME enable */
15032176cfdSRui Paulo #define IEEE80211_NODE_AR	0x0010		/* AR capable */
15132176cfdSRui Paulo #define IEEE80211_NODE_BOOST	0x0080		/* Dynamic Turbo boosted */
15232176cfdSRui Paulo 	uint16_t		ni_ath_defkeyix;/* Atheros def key index */
15332176cfdSRui Paulo 	const struct ieee80211_txparam *ni_txparms;
154085ff963SMatthew Dillon 	uint32_t		ni_jointime;	/* time of join (secs) */
155841ab66cSSepherosa Ziehau 	uint32_t		*ni_challenge;	/* shared-key challenge */
15632176cfdSRui Paulo 	struct ieee80211_ies	ni_ies;		/* captured ie's */
15732176cfdSRui Paulo 						/* tx seq per-tid */
15832176cfdSRui Paulo 	ieee80211_seq		ni_txseqs[IEEE80211_TID_SIZE];
15932176cfdSRui Paulo 						/* rx seq previous per-tid*/
16032176cfdSRui Paulo 	ieee80211_seq		ni_rxseqs[IEEE80211_TID_SIZE];
161841ab66cSSepherosa Ziehau 	uint32_t		ni_rxfragstamp;	/* time stamp of last rx frag */
162841ab66cSSepherosa Ziehau 	struct mbuf		*ni_rxfrag[3];	/* rx frag reassembly */
163841ab66cSSepherosa Ziehau 	struct ieee80211_key	ni_ucastkey;	/* unicast key */
164f186073cSJoerg Sonnenberger 
165f186073cSJoerg Sonnenberger 	/* hardware */
16632176cfdSRui Paulo 	uint32_t		ni_avgrssi;	/* recv ssi state */
16732176cfdSRui Paulo 	int8_t			ni_noise;	/* noise floor */
168f186073cSJoerg Sonnenberger 
169085ff963SMatthew Dillon 	/* mimo statistics */
170085ff963SMatthew Dillon 	uint32_t		ni_mimo_rssi_ctl[IEEE80211_MAX_CHAINS];
171085ff963SMatthew Dillon 	uint32_t		ni_mimo_rssi_ext[IEEE80211_MAX_CHAINS];
172085ff963SMatthew Dillon 	uint8_t			ni_mimo_noise_ctl[IEEE80211_MAX_CHAINS];
173085ff963SMatthew Dillon 	uint8_t			ni_mimo_noise_ext[IEEE80211_MAX_CHAINS];
174085ff963SMatthew Dillon 	uint8_t			ni_mimo_chains;
175085ff963SMatthew Dillon 
176f186073cSJoerg Sonnenberger 	/* header */
177f186073cSJoerg Sonnenberger 	uint8_t			ni_macaddr[IEEE80211_ADDR_LEN];
178f186073cSJoerg Sonnenberger 	uint8_t			ni_bssid[IEEE80211_ADDR_LEN];
179f186073cSJoerg Sonnenberger 
180f186073cSJoerg Sonnenberger 	/* beacon, probe response */
181841ab66cSSepherosa Ziehau 	union {
182841ab66cSSepherosa Ziehau 		uint8_t		data[8];
18332176cfdSRui Paulo 		u_int64_t	tsf;
184841ab66cSSepherosa Ziehau 	} ni_tstamp;				/* from last rcv'd beacon */
185f186073cSJoerg Sonnenberger 	uint16_t		ni_intval;	/* beacon interval */
186f186073cSJoerg Sonnenberger 	uint16_t		ni_capinfo;	/* capabilities */
187f186073cSJoerg Sonnenberger 	uint8_t			ni_esslen;
188f186073cSJoerg Sonnenberger 	uint8_t			ni_essid[IEEE80211_NWID_LEN];
189f186073cSJoerg Sonnenberger 	struct ieee80211_rateset ni_rates;	/* negotiated rate set */
19032176cfdSRui Paulo 	struct ieee80211_channel *ni_chan;
191f186073cSJoerg Sonnenberger 	uint16_t		ni_fhdwell;	/* FH only */
192f186073cSJoerg Sonnenberger 	uint8_t			ni_fhindex;	/* FH only */
19332176cfdSRui Paulo 	uint16_t		ni_erp;		/* ERP from beacon/probe resp */
194841ab66cSSepherosa Ziehau 	uint16_t		ni_timoff;	/* byte offset to TIM ie */
195841ab66cSSepherosa Ziehau 	uint8_t			ni_dtim_period;	/* DTIM period */
196841ab66cSSepherosa Ziehau 	uint8_t			ni_dtim_count;	/* DTIM count for last bcn */
197f186073cSJoerg Sonnenberger 
19832176cfdSRui Paulo 	/* 11s state */
19932176cfdSRui Paulo 	uint8_t			ni_meshidlen;
20032176cfdSRui Paulo 	uint8_t			ni_meshid[IEEE80211_MESHID_LEN];
20132176cfdSRui Paulo 	enum ieee80211_mesh_mlstate ni_mlstate;	/* peering management state */
20232176cfdSRui Paulo 	uint16_t		ni_mllid;	/* link local ID */
20332176cfdSRui Paulo 	uint16_t		ni_mlpid;	/* link peer ID */
20432176cfdSRui Paulo 	struct callout		ni_mltimer;	/* link mesh timer */
20532176cfdSRui Paulo 	uint8_t			ni_mlrcnt;	/* link mesh retry counter */
20632176cfdSRui Paulo 	uint8_t			ni_mltval;	/* link mesh timer value */
207085ff963SMatthew Dillon 	struct callout		ni_mlhtimer;	/* link mesh backoff timer */
208085ff963SMatthew Dillon 	uint8_t			ni_mlhcnt;	/* link mesh holding counter */
20932176cfdSRui Paulo 
21032176cfdSRui Paulo 	/* 11n state */
21132176cfdSRui Paulo 	uint16_t		ni_htcap;	/* HT capabilities */
21232176cfdSRui Paulo 	uint8_t			ni_htparam;	/* HT params */
21332176cfdSRui Paulo 	uint8_t			ni_htctlchan;	/* HT control channel */
21432176cfdSRui Paulo 	uint8_t			ni_ht2ndchan;	/* HT 2nd channel */
21532176cfdSRui Paulo 	uint8_t			ni_htopmode;	/* HT operating mode */
21632176cfdSRui Paulo 	uint8_t			ni_htstbc;	/* HT */
21732176cfdSRui Paulo 	uint8_t			ni_chw;		/* negotiated channel width */
21832176cfdSRui Paulo 	struct ieee80211_htrateset ni_htrates;	/* negotiated ht rate set */
219085ff963SMatthew Dillon 	struct ieee80211_tx_ampdu ni_tx_ampdu[WME_NUM_TID];
22032176cfdSRui Paulo 	struct ieee80211_rx_ampdu ni_rx_ampdu[WME_NUM_TID];
22132176cfdSRui Paulo 
2224f655ef5SMatthew Dillon 	/* fast-frames state */
2234f655ef5SMatthew Dillon 	struct mbuf *		ni_tx_superg[WME_NUM_TID];
2244f655ef5SMatthew Dillon 
225f186073cSJoerg Sonnenberger 	/* others */
226841ab66cSSepherosa Ziehau 	short			ni_inact;	/* inactivity mark count */
227841ab66cSSepherosa Ziehau 	short			ni_inact_reload;/* inactivity reload value */
22832176cfdSRui Paulo 	int			ni_txrate;	/* legacy rate/MCS */
22932176cfdSRui Paulo 	struct ieee80211_psq	ni_psq;		/* power save queue */
230841ab66cSSepherosa Ziehau 	struct ieee80211_nodestats ni_stats;	/* per-node statistics */
23132176cfdSRui Paulo 
23232176cfdSRui Paulo 	struct ieee80211vap	*ni_wdsvap;	/* associated WDS vap */
2334028af95SRui Paulo 	void			*ni_rctls;	/* private ratectl state */
2344028af95SRui Paulo 	uint64_t		ni_spare[3];
235f186073cSJoerg Sonnenberger };
236*805c8e8eSzrj #ifdef MALLOC_DECLARE
237841ab66cSSepherosa Ziehau MALLOC_DECLARE(M_80211_NODE);
23832176cfdSRui Paulo MALLOC_DECLARE(M_80211_NODE_IE);
239*805c8e8eSzrj #endif
24032176cfdSRui Paulo 
24132176cfdSRui Paulo #define	IEEE80211_NODE_ATH	(IEEE80211_NODE_FF | IEEE80211_NODE_TURBOP)
24232176cfdSRui Paulo #define	IEEE80211_NODE_AMPDU \
24332176cfdSRui Paulo 	(IEEE80211_NODE_AMPDU_RX | IEEE80211_NODE_AMPDU_TX)
24432176cfdSRui Paulo #define	IEEE80211_NODE_AMSDU \
24532176cfdSRui Paulo 	(IEEE80211_NODE_AMSDU_RX | IEEE80211_NODE_AMSDU_TX)
24632176cfdSRui Paulo #define	IEEE80211_NODE_HT_ALL \
24732176cfdSRui Paulo 	(IEEE80211_NODE_HT | IEEE80211_NODE_HTCOMPAT | \
24832176cfdSRui Paulo 	 IEEE80211_NODE_AMPDU | IEEE80211_NODE_AMSDU | \
24932176cfdSRui Paulo 	 IEEE80211_NODE_MIMO_PS | IEEE80211_NODE_MIMO_RTS | \
25032176cfdSRui Paulo 	 IEEE80211_NODE_RIFS | IEEE80211_NODE_SGI20 | IEEE80211_NODE_SGI40)
25132176cfdSRui Paulo 
25232176cfdSRui Paulo #define	IEEE80211_NODE_BITS \
25332176cfdSRui Paulo 	"\20\1AUTH\2QOS\3ERP\5PWR_MGT\6AREF\7HT\10HTCOMPAT\11WPS\12TSN" \
25432176cfdSRui Paulo 	"\13AMPDU_RX\14AMPDU_TX\15MIMO_PS\16MIMO_RTS\17RIFS\20SGI20\21SGI40" \
25532176cfdSRui Paulo 	"\22ASSOCID"
256841ab66cSSepherosa Ziehau 
257841ab66cSSepherosa Ziehau #define	IEEE80211_NODE_AID(ni)	IEEE80211_AID(ni->ni_associd)
258841ab66cSSepherosa Ziehau 
259841ab66cSSepherosa Ziehau #define	IEEE80211_NODE_STAT(ni,stat)	(ni->ni_stats.ns_##stat++)
260841ab66cSSepherosa Ziehau #define	IEEE80211_NODE_STAT_ADD(ni,stat,v)	(ni->ni_stats.ns_##stat += v)
261841ab66cSSepherosa Ziehau #define	IEEE80211_NODE_STAT_SET(ni,stat,v)	(ni->ni_stats.ns_##stat = v)
262f186073cSJoerg Sonnenberger 
26332176cfdSRui Paulo /*
26432176cfdSRui Paulo  * Filtered rssi calculation support.  The receive rssi is maintained
26532176cfdSRui Paulo  * as an average over the last 10 frames received using a low pass filter
26632176cfdSRui Paulo  * (all frames for now, possibly need to be more selective).  Calculations
26732176cfdSRui Paulo  * are designed such that a good compiler can optimize them.  The avg
26832176cfdSRui Paulo  * rssi state should be initialized to IEEE80211_RSSI_DUMMY_MARKER and
26932176cfdSRui Paulo  * each sample incorporated with IEEE80211_RSSI_LPF.  Use IEEE80211_RSSI_GET
27032176cfdSRui Paulo  * to extract the current value.
27132176cfdSRui Paulo  *
27232176cfdSRui Paulo  * Note that we assume rssi data are in the range [-127..127] and we
27332176cfdSRui Paulo  * discard values <-20.  This is consistent with assumptions throughout
27432176cfdSRui Paulo  * net80211 that signal strength data are in .5 dBm units relative to
27532176cfdSRui Paulo  * the current noise floor (linear, not log).
27632176cfdSRui Paulo  */
27732176cfdSRui Paulo #define IEEE80211_RSSI_LPF_LEN		10
27832176cfdSRui Paulo #define	IEEE80211_RSSI_DUMMY_MARKER	127
27932176cfdSRui Paulo /* NB: pow2 to optimize out * and / */
28032176cfdSRui Paulo #define	IEEE80211_RSSI_EP_MULTIPLIER	(1<<7)
28132176cfdSRui Paulo #define IEEE80211_RSSI_IN(x)		((x) * IEEE80211_RSSI_EP_MULTIPLIER)
28232176cfdSRui Paulo #define _IEEE80211_RSSI_LPF(x, y, len) \
28332176cfdSRui Paulo     (((x) != IEEE80211_RSSI_DUMMY_MARKER) ? (((x) * ((len) - 1) + (y)) / (len)) : (y))
28432176cfdSRui Paulo #define IEEE80211_RSSI_LPF(x, y) do {					\
28532176cfdSRui Paulo     if ((y) >= -20) {							\
28632176cfdSRui Paulo     	x = _IEEE80211_RSSI_LPF((x), IEEE80211_RSSI_IN((y)), 		\
28732176cfdSRui Paulo 		IEEE80211_RSSI_LPF_LEN);				\
28832176cfdSRui Paulo     }									\
28932176cfdSRui Paulo } while (0)
29032176cfdSRui Paulo #define	IEEE80211_RSSI_EP_RND(x, mul) \
29132176cfdSRui Paulo 	((((x) % (mul)) >= ((mul)/2)) ? ((x) + ((mul) - 1)) / (mul) : (x)/(mul))
29232176cfdSRui Paulo #define	IEEE80211_RSSI_GET(x) \
29332176cfdSRui Paulo 	IEEE80211_RSSI_EP_RND(x, IEEE80211_RSSI_EP_MULTIPLIER)
29432176cfdSRui Paulo 
295f186073cSJoerg Sonnenberger static __inline struct ieee80211_node *
ieee80211_ref_node(struct ieee80211_node * ni)296f186073cSJoerg Sonnenberger ieee80211_ref_node(struct ieee80211_node *ni)
297f186073cSJoerg Sonnenberger {
298841ab66cSSepherosa Ziehau 	ieee80211_node_incref(ni);
299f186073cSJoerg Sonnenberger 	return ni;
300f186073cSJoerg Sonnenberger }
301f186073cSJoerg Sonnenberger 
302f186073cSJoerg Sonnenberger static __inline void
ieee80211_unref_node(struct ieee80211_node ** ni)303f186073cSJoerg Sonnenberger ieee80211_unref_node(struct ieee80211_node **ni)
304f186073cSJoerg Sonnenberger {
305841ab66cSSepherosa Ziehau 	ieee80211_node_decref(*ni);
306f186073cSJoerg Sonnenberger 	*ni = NULL;			/* guard against use */
307f186073cSJoerg Sonnenberger }
308f186073cSJoerg Sonnenberger 
309841ab66cSSepherosa Ziehau void	ieee80211_node_attach(struct ieee80211com *);
310841ab66cSSepherosa Ziehau void	ieee80211_node_lateattach(struct ieee80211com *);
311841ab66cSSepherosa Ziehau void	ieee80211_node_detach(struct ieee80211com *);
31232176cfdSRui Paulo void	ieee80211_node_vattach(struct ieee80211vap *);
31332176cfdSRui Paulo void	ieee80211_node_latevattach(struct ieee80211vap *);
31432176cfdSRui Paulo void	ieee80211_node_vdetach(struct ieee80211vap *);
315f186073cSJoerg Sonnenberger 
316841ab66cSSepherosa Ziehau static __inline int
ieee80211_node_is_authorized(const struct ieee80211_node * ni)317841ab66cSSepherosa Ziehau ieee80211_node_is_authorized(const struct ieee80211_node *ni)
318841ab66cSSepherosa Ziehau {
319841ab66cSSepherosa Ziehau 	return (ni->ni_flags & IEEE80211_NODE_AUTH);
320841ab66cSSepherosa Ziehau }
321f186073cSJoerg Sonnenberger 
322841ab66cSSepherosa Ziehau void	ieee80211_node_authorize(struct ieee80211_node *);
323841ab66cSSepherosa Ziehau void	ieee80211_node_unauthorize(struct ieee80211_node *);
324f186073cSJoerg Sonnenberger 
32532176cfdSRui Paulo void	ieee80211_node_setuptxparms(struct ieee80211_node *);
32632176cfdSRui Paulo void	ieee80211_node_set_chan(struct ieee80211_node *,
327f39a365aSSepherosa Ziehau 		struct ieee80211_channel *);
32832176cfdSRui Paulo void	ieee80211_create_ibss(struct ieee80211vap*, struct ieee80211_channel *);
32932176cfdSRui Paulo void	ieee80211_reset_bss(struct ieee80211vap *);
33032176cfdSRui Paulo void	ieee80211_sync_curchan(struct ieee80211com *);
33132176cfdSRui Paulo void	ieee80211_setupcurchan(struct ieee80211com *,
33232176cfdSRui Paulo 	    struct ieee80211_channel *);
33332176cfdSRui Paulo void	ieee80211_setcurchan(struct ieee80211com *, struct ieee80211_channel *);
334085ff963SMatthew Dillon void	ieee80211_update_chw(struct ieee80211com *);
3354f655ef5SMatthew Dillon int	ieee80211_ibss_merge_check(struct ieee80211_node *);
336841ab66cSSepherosa Ziehau int	ieee80211_ibss_merge(struct ieee80211_node *);
33732176cfdSRui Paulo struct ieee80211_scan_entry;
33832176cfdSRui Paulo int	ieee80211_sta_join(struct ieee80211vap *, struct ieee80211_channel *,
33932176cfdSRui Paulo 		const struct ieee80211_scan_entry *);
34032176cfdSRui Paulo void	ieee80211_sta_leave(struct ieee80211_node *);
34132176cfdSRui Paulo void	ieee80211_node_deauth(struct ieee80211_node *, int);
34232176cfdSRui Paulo 
34332176cfdSRui Paulo int	ieee80211_ies_init(struct ieee80211_ies *, const uint8_t *, int);
34432176cfdSRui Paulo void	ieee80211_ies_cleanup(struct ieee80211_ies *);
34532176cfdSRui Paulo void	ieee80211_ies_expand(struct ieee80211_ies *);
34632176cfdSRui Paulo #define	ieee80211_ies_setie(_ies, _ie, _off) do {		\
34732176cfdSRui Paulo 	(_ies)._ie = (_ies).data + (_off);			\
34832176cfdSRui Paulo } while (0)
349841ab66cSSepherosa Ziehau 
350841ab66cSSepherosa Ziehau /*
351841ab66cSSepherosa Ziehau  * Table of ieee80211_node instances.  Each ieee80211com
35232176cfdSRui Paulo  * has one that holds association stations (when operating
35332176cfdSRui Paulo  * as an ap) or neighbors (in ibss mode).
35432176cfdSRui Paulo  *
35532176cfdSRui Paulo  * XXX embed this in ieee80211com instead of indirect?
356841ab66cSSepherosa Ziehau  */
357841ab66cSSepherosa Ziehau struct ieee80211_node_table {
358841ab66cSSepherosa Ziehau 	struct ieee80211com	*nt_ic;		/* back reference */
359085ff963SMatthew Dillon 	ieee80211_node_lock_t	nt_nodelock;	/* on node table */
360841ab66cSSepherosa Ziehau 	TAILQ_HEAD(, ieee80211_node) nt_node;	/* information of all nodes */
361841ab66cSSepherosa Ziehau 	LIST_HEAD(, ieee80211_node) nt_hash[IEEE80211_NODE_HASHSIZE];
362841ab66cSSepherosa Ziehau 	struct ieee80211_node	**nt_keyixmap;	/* key ix -> node map */
363841ab66cSSepherosa Ziehau 	int			nt_keyixmax;	/* keyixmap size */
36432176cfdSRui Paulo 	const char		*nt_name;	/* table name for debug msgs */
365085ff963SMatthew Dillon 	ieee80211_scan_lock_t	nt_scanlock;	/* on nt_scangen */
36632176cfdSRui Paulo 	u_int			nt_scangen;	/* gen# for iterators */
36732176cfdSRui Paulo 	int			nt_inact_init;	/* initial node inact setting */
368841ab66cSSepherosa Ziehau };
369841ab66cSSepherosa Ziehau 
37032176cfdSRui Paulo struct ieee80211_node *ieee80211_alloc_node(struct ieee80211_node_table *,
37132176cfdSRui Paulo 		struct ieee80211vap *,
37232176cfdSRui Paulo 		const uint8_t macaddr[IEEE80211_ADDR_LEN]);
37332176cfdSRui Paulo struct ieee80211_node *ieee80211_tmp_node(struct ieee80211vap *,
37432176cfdSRui Paulo 		const uint8_t macaddr[IEEE80211_ADDR_LEN]);
37532176cfdSRui Paulo struct ieee80211_node *ieee80211_dup_bss(struct ieee80211vap *,
37632176cfdSRui Paulo 		const uint8_t macaddr[IEEE80211_ADDR_LEN]);
37732176cfdSRui Paulo struct ieee80211_node *ieee80211_node_create_wds(struct ieee80211vap *,
37832176cfdSRui Paulo 		const uint8_t bssid[IEEE80211_ADDR_LEN],
37932176cfdSRui Paulo 		struct ieee80211_channel *);
380841ab66cSSepherosa Ziehau #ifdef IEEE80211_DEBUG_REFCNT
381841ab66cSSepherosa Ziehau void	ieee80211_free_node_debug(struct ieee80211_node *,
382841ab66cSSepherosa Ziehau 		const char *func, int line);
38332176cfdSRui Paulo struct ieee80211_node *ieee80211_find_node_locked_debug(
38432176cfdSRui Paulo 		struct ieee80211_node_table *,
38532176cfdSRui Paulo 		const uint8_t macaddr[IEEE80211_ADDR_LEN],
386841ab66cSSepherosa Ziehau 		const char *func, int line);
38732176cfdSRui Paulo struct ieee80211_node *ieee80211_find_node_debug(struct ieee80211_node_table *,
38832176cfdSRui Paulo 		const uint8_t macaddr[IEEE80211_ADDR_LEN],
38932176cfdSRui Paulo 		const char *func, int line);
39032176cfdSRui Paulo struct ieee80211_node *ieee80211_find_vap_node_locked_debug(
39132176cfdSRui Paulo 		struct ieee80211_node_table *,
39232176cfdSRui Paulo 		const struct ieee80211vap *vap,
39332176cfdSRui Paulo 		const uint8_t macaddr[IEEE80211_ADDR_LEN],
39432176cfdSRui Paulo 		const char *func, int line);
39532176cfdSRui Paulo struct ieee80211_node *ieee80211_find_vap_node_debug(
39632176cfdSRui Paulo 		struct ieee80211_node_table *,
39732176cfdSRui Paulo 		const struct ieee80211vap *vap,
39832176cfdSRui Paulo 		const uint8_t macaddr[IEEE80211_ADDR_LEN],
39932176cfdSRui Paulo 		const char *func, int line);
40032176cfdSRui Paulo struct ieee80211_node * ieee80211_find_rxnode_debug(struct ieee80211com *,
40132176cfdSRui Paulo 		const struct ieee80211_frame_min *,
402841ab66cSSepherosa Ziehau 		const char *func, int line);
403841ab66cSSepherosa Ziehau struct ieee80211_node * ieee80211_find_rxnode_withkey_debug(
404841ab66cSSepherosa Ziehau 		struct ieee80211com *,
405841ab66cSSepherosa Ziehau 		const struct ieee80211_frame_min *, uint16_t keyix,
406841ab66cSSepherosa Ziehau 		const char *func, int line);
40732176cfdSRui Paulo struct ieee80211_node *ieee80211_find_txnode_debug(struct ieee80211vap *,
40832176cfdSRui Paulo 		const uint8_t *,
409841ab66cSSepherosa Ziehau 		const char *func, int line);
410841ab66cSSepherosa Ziehau #define	ieee80211_free_node(ni) \
411841ab66cSSepherosa Ziehau 	ieee80211_free_node_debug(ni, __func__, __LINE__)
41232176cfdSRui Paulo #define	ieee80211_find_node_locked(nt, mac) \
41332176cfdSRui Paulo 	ieee80211_find_node_locked_debug(nt, mac, __func__, __LINE__)
414841ab66cSSepherosa Ziehau #define	ieee80211_find_node(nt, mac) \
415841ab66cSSepherosa Ziehau 	ieee80211_find_node_debug(nt, mac, __func__, __LINE__)
41632176cfdSRui Paulo #define	ieee80211_find_vap_node_locked(nt, vap, mac) \
41732176cfdSRui Paulo 	ieee80211_find_vap_node_locked_debug(nt, vap, mac, __func__, __LINE__)
41832176cfdSRui Paulo #define	ieee80211_find_vap_node(nt, vap, mac) \
41932176cfdSRui Paulo 	ieee80211_find_vap_node_debug(nt, vap, mac, __func__, __LINE__)
42032176cfdSRui Paulo #define	ieee80211_find_rxnode(ic, wh) \
42132176cfdSRui Paulo 	ieee80211_find_rxnode_debug(ic, wh, __func__, __LINE__)
42232176cfdSRui Paulo #define	ieee80211_find_rxnode_withkey(ic, wh, keyix) \
42332176cfdSRui Paulo 	ieee80211_find_rxnode_withkey_debug(ic, wh, keyix, __func__, __LINE__)
42432176cfdSRui Paulo #define	ieee80211_find_txnode(vap, mac) \
42532176cfdSRui Paulo 	ieee80211_find_txnode_debug(vap, mac, __func__, __LINE__)
426841ab66cSSepherosa Ziehau #else
427841ab66cSSepherosa Ziehau void	ieee80211_free_node(struct ieee80211_node *);
42832176cfdSRui Paulo struct ieee80211_node *ieee80211_find_node_locked(struct ieee80211_node_table *,
42932176cfdSRui Paulo 		const uint8_t macaddr[IEEE80211_ADDR_LEN]);
43032176cfdSRui Paulo struct ieee80211_node *ieee80211_find_node(struct ieee80211_node_table *,
43132176cfdSRui Paulo 		const uint8_t macaddr[IEEE80211_ADDR_LEN]);
43232176cfdSRui Paulo struct ieee80211_node *ieee80211_find_vap_node_locked(
43332176cfdSRui Paulo 		struct ieee80211_node_table *, const struct ieee80211vap *,
43432176cfdSRui Paulo 		const uint8_t macaddr[IEEE80211_ADDR_LEN]);
43532176cfdSRui Paulo struct ieee80211_node *ieee80211_find_vap_node(
43632176cfdSRui Paulo 		struct ieee80211_node_table *, const struct ieee80211vap *,
43732176cfdSRui Paulo 		const uint8_t macaddr[IEEE80211_ADDR_LEN]);
43832176cfdSRui Paulo struct ieee80211_node * ieee80211_find_rxnode(struct ieee80211com *,
43932176cfdSRui Paulo 		const struct ieee80211_frame_min *);
440841ab66cSSepherosa Ziehau struct ieee80211_node * ieee80211_find_rxnode_withkey(struct ieee80211com *,
441841ab66cSSepherosa Ziehau 		const struct ieee80211_frame_min *, uint16_t keyix);
44232176cfdSRui Paulo struct ieee80211_node *ieee80211_find_txnode(struct ieee80211vap *,
44332176cfdSRui Paulo 		const uint8_t macaddr[IEEE80211_ADDR_LEN]);
444841ab66cSSepherosa Ziehau #endif
445841ab66cSSepherosa Ziehau int	ieee80211_node_delucastkey(struct ieee80211_node *);
446085ff963SMatthew Dillon void	ieee80211_node_timeout(void *arg);
447841ab66cSSepherosa Ziehau 
448841ab66cSSepherosa Ziehau typedef void ieee80211_iter_func(void *, struct ieee80211_node *);
449085ff963SMatthew Dillon int	ieee80211_iterate_nt(struct ieee80211_node_table *,
450085ff963SMatthew Dillon 		struct ieee80211_node **, uint16_t);
451841ab66cSSepherosa Ziehau void	ieee80211_iterate_nodes(struct ieee80211_node_table *,
452841ab66cSSepherosa Ziehau 		ieee80211_iter_func *, void *);
453841ab66cSSepherosa Ziehau 
45432176cfdSRui Paulo void	ieee80211_notify_erp(struct ieee80211com *);
455841ab66cSSepherosa Ziehau void	ieee80211_dump_node(struct ieee80211_node_table *,
456841ab66cSSepherosa Ziehau 		struct ieee80211_node *);
457841ab66cSSepherosa Ziehau void	ieee80211_dump_nodes(struct ieee80211_node_table *);
458841ab66cSSepherosa Ziehau 
45932176cfdSRui Paulo struct ieee80211_node *ieee80211_fakeup_adhoc_node(struct ieee80211vap *,
46032176cfdSRui Paulo 		const uint8_t macaddr[IEEE80211_ADDR_LEN]);
46132176cfdSRui Paulo struct ieee80211_scanparams;
462841ab66cSSepherosa Ziehau void	ieee80211_init_neighbor(struct ieee80211_node *,
463841ab66cSSepherosa Ziehau 		const struct ieee80211_frame *,
464841ab66cSSepherosa Ziehau 		const struct ieee80211_scanparams *);
46532176cfdSRui Paulo struct ieee80211_node *ieee80211_add_neighbor(struct ieee80211vap *,
466841ab66cSSepherosa Ziehau 		const struct ieee80211_frame *,
467841ab66cSSepherosa Ziehau 		const struct ieee80211_scanparams *);
46832176cfdSRui Paulo void	ieee80211_node_join(struct ieee80211_node *,int);
46932176cfdSRui Paulo void	ieee80211_node_leave(struct ieee80211_node *);
47032176cfdSRui Paulo int8_t	ieee80211_getrssi(struct ieee80211vap *);
47132176cfdSRui Paulo void	ieee80211_getsignal(struct ieee80211vap *, int8_t *, int8_t *);
472841ab66cSSepherosa Ziehau #endif /* _NET80211_IEEE80211_NODE_H_ */
473