xref: /freebsd/sys/net80211/ieee80211_node.h (revision 1f078120955947c85c54a8c088782ea5e4451eb5)
11a1e1d21SSam Leffler /*-
2fe267a55SPedro F. Giffuni  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3fe267a55SPedro F. Giffuni  *
47535e66aSSam Leffler  * Copyright (c) 2001 Atsushi Onoe
510ad9a77SSam Leffler  * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
61a1e1d21SSam Leffler  * All rights reserved.
71a1e1d21SSam Leffler  *
81a1e1d21SSam Leffler  * Redistribution and use in source and binary forms, with or without
91a1e1d21SSam Leffler  * modification, are permitted provided that the following conditions
101a1e1d21SSam Leffler  * are met:
111a1e1d21SSam Leffler  * 1. Redistributions of source code must retain the above copyright
121a1e1d21SSam Leffler  *    notice, this list of conditions and the following disclaimer.
131a1e1d21SSam Leffler  * 2. Redistributions in binary form must reproduce the above copyright
141a1e1d21SSam Leffler  *    notice, this list of conditions and the following disclaimer in the
151a1e1d21SSam Leffler  *    documentation and/or other materials provided with the distribution.
167535e66aSSam Leffler  *
177535e66aSSam Leffler  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
187535e66aSSam Leffler  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
197535e66aSSam Leffler  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
207535e66aSSam Leffler  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
217535e66aSSam Leffler  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
227535e66aSSam Leffler  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
237535e66aSSam Leffler  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
247535e66aSSam Leffler  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
257535e66aSSam Leffler  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
267535e66aSSam Leffler  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
271a1e1d21SSam Leffler  *
281a1e1d21SSam Leffler  * $FreeBSD$
291a1e1d21SSam Leffler  */
301a1e1d21SSam Leffler #ifndef _NET80211_IEEE80211_NODE_H_
311a1e1d21SSam Leffler #define _NET80211_IEEE80211_NODE_H_
321a1e1d21SSam Leffler 
338a1b9b6aSSam Leffler #include <net80211/ieee80211_ioctl.h>		/* for ieee80211_nodestats */
3468e8e04eSSam Leffler #include <net80211/ieee80211_ht.h>		/* for aggregation state */
358a1b9b6aSSam Leffler 
368a1b9b6aSSam Leffler /*
37b032f27cSSam Leffler  * Each ieee80211com instance has a single timer that fires every
38b032f27cSSam Leffler  * IEEE80211_INACT_WAIT seconds to handle "inactivity processing".
39b032f27cSSam Leffler  * This is used to do node inactivity processing when operating
4059aa14a9SRui Paulo  * as an AP, adhoc or mesh mode.  For inactivity processing each node
4128323addSBryan Drewery  * has a timeout set in its ni_inact field that is decremented
42b032f27cSSam Leffler  * on each timeout and the node is reclaimed when the counter goes
43b032f27cSSam Leffler  * to zero.  We use different inactivity timeout values depending
44b032f27cSSam Leffler  * on whether the node is associated and authorized (either by
45b032f27cSSam Leffler  * 802.1x or open/shared key authentication) or associated but yet
46b032f27cSSam Leffler  * to be authorized.  The latter timeout is shorter to more aggressively
478a1b9b6aSSam Leffler  * reclaim nodes that leave part way through the 802.1x exchange.
488a1b9b6aSSam Leffler  */
498a1b9b6aSSam Leffler #define	IEEE80211_INACT_WAIT	15		/* inactivity interval (secs) */
508a1b9b6aSSam Leffler #define	IEEE80211_INACT_INIT	(30/IEEE80211_INACT_WAIT)	/* initial */
518a1b9b6aSSam Leffler #define	IEEE80211_INACT_AUTH	(180/IEEE80211_INACT_WAIT)	/* associated but not authorized */
528a1b9b6aSSam Leffler #define	IEEE80211_INACT_RUN	(300/IEEE80211_INACT_WAIT)	/* authorized */
538a1b9b6aSSam Leffler #define	IEEE80211_INACT_PROBE	(30/IEEE80211_INACT_WAIT)	/* probe */
548a1b9b6aSSam Leffler #define	IEEE80211_INACT_SCAN	(300/IEEE80211_INACT_WAIT)	/* scanned */
558a1b9b6aSSam Leffler 
5668e8e04eSSam Leffler #define	IEEE80211_TRANS_WAIT 	2		/* mgt frame tx timer (secs) */
571a1e1d21SSam Leffler 
58b105a069SSam Leffler /* threshold for aging overlapping non-ERP bss */
59b105a069SSam Leffler #define	IEEE80211_NONERP_PRESENT_AGE	msecs_to_ticks(60*1000)
60b105a069SSam Leffler 
6159aa14a9SRui Paulo #define	IEEE80211_NODE_HASHSIZE	32		/* NB: hash size must be pow2 */
621a1e1d21SSam Leffler /* simple hash is enough for variation of macaddr */
6359aa14a9SRui Paulo #define	IEEE80211_NODE_HASH(ic, addr)	\
6468e8e04eSSam Leffler 	(((const uint8_t *)(addr))[IEEE80211_ADDR_LEN - 1] % \
658a1b9b6aSSam Leffler 		IEEE80211_NODE_HASHSIZE)
661a1e1d21SSam Leffler 
678a1b9b6aSSam Leffler struct ieee80211_node_table;
688a1b9b6aSSam Leffler struct ieee80211com;
69b032f27cSSam Leffler struct ieee80211vap;
70172b009aSAdrian Chadd struct ieee80211_scanparams;
71b032f27cSSam Leffler 
72b032f27cSSam Leffler /*
731e375f3aSBjoern A. Zeeb  * Information element (IE) ``blob''.  We use this structure
74b032f27cSSam Leffler  * to capture management frame payloads that need to be
750ce9091aSRui Paulo  * retained.  Information elements within the payload that
76b032f27cSSam Leffler  * we need to consult have references recorded.
77b032f27cSSam Leffler  */
78b032f27cSSam Leffler struct ieee80211_ies {
79b032f27cSSam Leffler 	/* the following are either NULL or point within data */
80b032f27cSSam Leffler 	uint8_t	*wpa_ie;	/* captured WPA ie */
81b032f27cSSam Leffler 	uint8_t	*rsn_ie;	/* captured RSN ie */
82b032f27cSSam Leffler 	uint8_t	*wme_ie;	/* captured WME ie */
83b032f27cSSam Leffler 	uint8_t	*ath_ie;	/* captured Atheros ie */
84b032f27cSSam Leffler 	uint8_t	*htcap_ie;	/* captured HTCAP ie */
85b032f27cSSam Leffler 	uint8_t	*htinfo_ie;	/* captured HTINFO ie */
8610ad9a77SSam Leffler 	uint8_t	*tdma_ie;	/* captured TDMA ie */
8759aa14a9SRui Paulo 	uint8_t *meshid_ie;	/* captured MESH ID ie */
8874a54be9SAdrian Chadd 	uint8_t	*vhtcap_ie;	/* captured VHTCAP ie */
8974a54be9SAdrian Chadd 	uint8_t	*vhtopmode_ie;	/* captured VHTOPMODE ie */
9074a54be9SAdrian Chadd 	uint8_t	*vhtpwrenv_ie;	/* captured VHTPWRENV ie */
9174a54be9SAdrian Chadd 	uint8_t	*apchanrep_ie;	/* captured APCHANREP ie */
9274a54be9SAdrian Chadd 	uint8_t	*bssload_ie;	/* captured BSSLOAD ie */
93a43cee70SSam Leffler 	uint8_t	*spare[4];
94b032f27cSSam Leffler 	/* NB: these must be the last members of this structure */
95b032f27cSSam Leffler 	uint8_t	*data;		/* frame data > 802.11 header */
96b032f27cSSam Leffler 	int	len;		/* data size in bytes */
97b032f27cSSam Leffler };
988a1b9b6aSSam Leffler 
991a1e1d21SSam Leffler /*
10059aa14a9SRui Paulo  * 802.11s (Mesh) Peer Link FSM state.
10159aa14a9SRui Paulo  */
10259aa14a9SRui Paulo enum ieee80211_mesh_mlstate {
10359aa14a9SRui Paulo 	IEEE80211_NODE_MESH_IDLE	= 0,
10459aa14a9SRui Paulo 	IEEE80211_NODE_MESH_OPENSNT	= 1,	/* open frame sent */
10559aa14a9SRui Paulo 	IEEE80211_NODE_MESH_OPENRCV	= 2,	/* open frame received */
10659aa14a9SRui Paulo 	IEEE80211_NODE_MESH_CONFIRMRCV	= 3,	/* confirm frame received */
10759aa14a9SRui Paulo 	IEEE80211_NODE_MESH_ESTABLISHED	= 4,	/* link established */
10859aa14a9SRui Paulo 	IEEE80211_NODE_MESH_HOLDING	= 5,	/* link closing */
10959aa14a9SRui Paulo };
11059aa14a9SRui Paulo #define	IEEE80211_MESH_MLSTATE_BITS \
11159aa14a9SRui Paulo 	"\20\1IDLE\2OPENSNT\2OPENRCV\3CONFIRMRCV\4ESTABLISHED\5HOLDING"
11259aa14a9SRui Paulo 
11359aa14a9SRui Paulo /*
1141a1e1d21SSam Leffler  * Node specific information.  Note that drivers are expected
1151a1e1d21SSam Leffler  * to derive from this structure to add device-specific per-node
1161a1e1d21SSam Leffler  * state.  This is done by overriding the ic_node_* methods in
1171a1e1d21SSam Leffler  * the ieee80211com structure.
1181a1e1d21SSam Leffler  */
1191a1e1d21SSam Leffler struct ieee80211_node {
120b032f27cSSam Leffler 	struct ieee80211vap	*ni_vap;	/* associated vap */
121b032f27cSSam Leffler 	struct ieee80211com	*ni_ic;		/* copy from vap to save deref*/
122b032f27cSSam Leffler 	struct ieee80211_node_table *ni_table;	/* NB: may be NULL */
123b032f27cSSam Leffler 	TAILQ_ENTRY(ieee80211_node) ni_list;	/* list of all nodes */
124b032f27cSSam Leffler 	LIST_ENTRY(ieee80211_node) ni_hash;	/* hash collision list */
125b032f27cSSam Leffler 	u_int			ni_refcnt;	/* count of held references */
126c4fe3956SSam Leffler 	u_int			ni_flags;
127c4fe3956SSam Leffler #define	IEEE80211_NODE_AUTH	0x000001	/* authorized for data */
128c4fe3956SSam Leffler #define	IEEE80211_NODE_QOS	0x000002	/* QoS enabled */
129c4fe3956SSam Leffler #define	IEEE80211_NODE_ERP	0x000004	/* ERP enabled */
130c4fe3956SSam Leffler /* NB: this must have the same value as IEEE80211_FC1_PWR_MGT */
131c4fe3956SSam Leffler #define	IEEE80211_NODE_PWR_MGT	0x000010	/* power save mode enabled */
132c4fe3956SSam Leffler #define	IEEE80211_NODE_AREF	0x000020	/* authentication ref held */
133c4fe3956SSam Leffler #define	IEEE80211_NODE_HT	0x000040	/* HT enabled */
134c4fe3956SSam Leffler #define	IEEE80211_NODE_HTCOMPAT	0x000080	/* HT setup w/ vendor OUI's */
135c4fe3956SSam Leffler #define	IEEE80211_NODE_WPS	0x000100	/* WPS association */
136c4fe3956SSam Leffler #define	IEEE80211_NODE_TSN	0x000200	/* TSN association */
137c4fe3956SSam Leffler #define	IEEE80211_NODE_AMPDU_RX	0x000400	/* AMPDU rx enabled */
138c4fe3956SSam Leffler #define	IEEE80211_NODE_AMPDU_TX	0x000800	/* AMPDU tx enabled */
1398c070d69SSam Leffler #define	IEEE80211_NODE_MIMO_PS	0x001000	/* MIMO power save enabled */
1408c070d69SSam Leffler #define	IEEE80211_NODE_MIMO_RTS	0x002000	/* send RTS in MIMO PS */
14144f7a6edSSam Leffler #define	IEEE80211_NODE_RIFS	0x004000	/* RIFS enabled */
14249942a97SSam Leffler #define	IEEE80211_NODE_SGI20	0x008000	/* Short GI in HT20 enabled */
14349942a97SSam Leffler #define	IEEE80211_NODE_SGI40	0x010000	/* Short GI in HT40 enabled */
1441b999d64SSam Leffler #define	IEEE80211_NODE_ASSOCID	0x020000	/* xmit requires associd */
145d0dd594cSSam Leffler #define	IEEE80211_NODE_AMSDU_RX	0x040000	/* AMSDU rx enabled */
146d0dd594cSSam Leffler #define	IEEE80211_NODE_AMSDU_TX	0x080000	/* AMSDU tx enabled */
1476d0ef1b9SAdrian Chadd #define	IEEE80211_NODE_VHT	0x100000	/* VHT enabled */
148c5bba9daSAndriy Voskoboinyk #define	IEEE80211_NODE_LDPC	0x200000	/* LDPC enabled */
1498379e8dbSAdrian Chadd #define	IEEE80211_NODE_UAPSD	0x400000	/* U-APSD power save enabled */
150c4fe3956SSam Leffler 	uint16_t		ni_associd;	/* association ID */
151c4fe3956SSam Leffler 	uint16_t		ni_vlan;	/* vlan tag */
152c4fe3956SSam Leffler 	uint16_t		ni_txpower;	/* current transmit power */
15368e8e04eSSam Leffler 	uint8_t			ni_authmode;	/* authentication algorithm */
15468e8e04eSSam Leffler 	uint8_t			ni_ath_flags;	/* Atheros feature flags */
15568e8e04eSSam Leffler 	/* NB: These must have the same values as IEEE80211_ATHC_* */
15668e8e04eSSam Leffler #define IEEE80211_NODE_TURBOP	0x0001		/* Turbo prime enable */
15768e8e04eSSam Leffler #define IEEE80211_NODE_COMP	0x0002		/* Compresssion enable */
15868e8e04eSSam Leffler #define IEEE80211_NODE_FF	0x0004          /* Fast Frame capable */
15968e8e04eSSam Leffler #define IEEE80211_NODE_XR	0x0008		/* Atheros WME enable */
16068e8e04eSSam Leffler #define IEEE80211_NODE_AR	0x0010		/* AR capable */
161c4fe3956SSam Leffler #define IEEE80211_NODE_BOOST	0x0080		/* Dynamic Turbo boosted */
16268e8e04eSSam Leffler 	uint16_t		ni_ath_defkeyix;/* Atheros def key index */
16301a03542SSam Leffler 	const struct ieee80211_txparam *ni_txparms;
1641b6167d2SSam Leffler 	uint32_t		ni_jointime;	/* time of join (secs) */
16568e8e04eSSam Leffler 	uint32_t		*ni_challenge;	/* shared-key challenge */
166b032f27cSSam Leffler 	struct ieee80211_ies	ni_ies;		/* captured ie's */
167b337fbc4SSam Leffler 						/* tx seq per-tid */
168dca68715SSam Leffler 	ieee80211_seq		ni_txseqs[IEEE80211_TID_SIZE];
169b337fbc4SSam Leffler 						/* rx seq previous per-tid*/
170dca68715SSam Leffler 	ieee80211_seq		ni_rxseqs[IEEE80211_TID_SIZE];
17168e8e04eSSam Leffler 	uint32_t		ni_rxfragstamp;	/* time stamp of last rx frag */
1728a1b9b6aSSam Leffler 	struct mbuf		*ni_rxfrag[3];	/* rx frag reassembly */
1738a1b9b6aSSam Leffler 	struct ieee80211_key	ni_ucastkey;	/* unicast key */
1741a1e1d21SSam Leffler 
1751a1e1d21SSam Leffler 	/* hardware */
176b032f27cSSam Leffler 	uint32_t		ni_avgrssi;	/* recv ssi state */
17768e8e04eSSam Leffler 	int8_t			ni_noise;	/* noise floor */
1781a1e1d21SSam Leffler 
179864ab114SAdrian Chadd 	/* mimo statistics */
180864ab114SAdrian Chadd 	uint32_t		ni_mimo_rssi_ctl[IEEE80211_MAX_CHAINS];
181864ab114SAdrian Chadd 	uint32_t		ni_mimo_rssi_ext[IEEE80211_MAX_CHAINS];
182864ab114SAdrian Chadd 	uint8_t			ni_mimo_noise_ctl[IEEE80211_MAX_CHAINS];
183864ab114SAdrian Chadd 	uint8_t			ni_mimo_noise_ext[IEEE80211_MAX_CHAINS];
184864ab114SAdrian Chadd 	uint8_t			ni_mimo_chains;
185864ab114SAdrian Chadd 
1861a1e1d21SSam Leffler 	/* header */
18768e8e04eSSam Leffler 	uint8_t			ni_macaddr[IEEE80211_ADDR_LEN];
18868e8e04eSSam Leffler 	uint8_t			ni_bssid[IEEE80211_ADDR_LEN];
1891a1e1d21SSam Leffler 
1901a1e1d21SSam Leffler 	/* beacon, probe response */
1918a1b9b6aSSam Leffler 	union {
19268e8e04eSSam Leffler 		uint8_t		data[8];
193b032f27cSSam Leffler 		u_int64_t	tsf;
1948a1b9b6aSSam Leffler 	} ni_tstamp;				/* from last rcv'd beacon */
19568e8e04eSSam Leffler 	uint16_t		ni_intval;	/* beacon interval */
19668e8e04eSSam Leffler 	uint16_t		ni_capinfo;	/* capabilities */
19768e8e04eSSam Leffler 	uint8_t			ni_esslen;
19868e8e04eSSam Leffler 	uint8_t			ni_essid[IEEE80211_NWID_LEN];
1991a1e1d21SSam Leffler 	struct ieee80211_rateset ni_rates;	/* negotiated rate set */
20068e8e04eSSam Leffler 	struct ieee80211_channel *ni_chan;
20168e8e04eSSam Leffler 	uint16_t		ni_fhdwell;	/* FH only */
20268e8e04eSSam Leffler 	uint8_t			ni_fhindex;	/* FH only */
203b032f27cSSam Leffler 	uint16_t		ni_erp;		/* ERP from beacon/probe resp */
20468e8e04eSSam Leffler 	uint16_t		ni_timoff;	/* byte offset to TIM ie */
20568e8e04eSSam Leffler 	uint8_t			ni_dtim_period;	/* DTIM period */
20668e8e04eSSam Leffler 	uint8_t			ni_dtim_count;	/* DTIM count for last bcn */
20768e8e04eSSam Leffler 
20859aa14a9SRui Paulo 	/* 11s state */
20959aa14a9SRui Paulo 	uint8_t			ni_meshidlen;
21059aa14a9SRui Paulo 	uint8_t			ni_meshid[IEEE80211_MESHID_LEN];
21159aa14a9SRui Paulo 	enum ieee80211_mesh_mlstate ni_mlstate;	/* peering management state */
21259aa14a9SRui Paulo 	uint16_t		ni_mllid;	/* link local ID */
21359aa14a9SRui Paulo 	uint16_t		ni_mlpid;	/* link peer ID */
21459aa14a9SRui Paulo 	struct callout		ni_mltimer;	/* link mesh timer */
21559aa14a9SRui Paulo 	uint8_t			ni_mlrcnt;	/* link mesh retry counter */
21659aa14a9SRui Paulo 	uint8_t			ni_mltval;	/* link mesh timer value */
217ff17492fSMonthadar Al Jaberi 	struct callout		ni_mlhtimer;	/* link mesh backoff timer */
218ff17492fSMonthadar Al Jaberi 	uint8_t			ni_mlhcnt;	/* link mesh holding counter */
21959aa14a9SRui Paulo 
22068e8e04eSSam Leffler 	/* 11n state */
22168e8e04eSSam Leffler 	uint16_t		ni_htcap;	/* HT capabilities */
22268e8e04eSSam Leffler 	uint8_t			ni_htparam;	/* HT params */
22368e8e04eSSam Leffler 	uint8_t			ni_htctlchan;	/* HT control channel */
22468e8e04eSSam Leffler 	uint8_t			ni_ht2ndchan;	/* HT 2nd channel */
22568e8e04eSSam Leffler 	uint8_t			ni_htopmode;	/* HT operating mode */
22668e8e04eSSam Leffler 	uint8_t			ni_htstbc;	/* HT */
22768e8e04eSSam Leffler 	uint8_t			ni_chw;		/* negotiated channel width */
22868e8e04eSSam Leffler 	struct ieee80211_htrateset ni_htrates;	/* negotiated ht rate set */
2292aa563dfSAdrian Chadd 	struct ieee80211_tx_ampdu ni_tx_ampdu[WME_NUM_TID];
23068e8e04eSSam Leffler 	struct ieee80211_rx_ampdu ni_rx_ampdu[WME_NUM_TID];
2311a1e1d21SSam Leffler 
232fdbc9e6eSAdrian Chadd 	/* VHT state */
233fdbc9e6eSAdrian Chadd 	uint32_t		ni_vhtcap;
2346d0ef1b9SAdrian Chadd 	uint16_t		ni_vht_basicmcs;
2356d0ef1b9SAdrian Chadd 	uint16_t		ni_vht_pad2;
236fdbc9e6eSAdrian Chadd 	struct ieee80211_vht_mcs_info	ni_vht_mcsinfo;
237fdbc9e6eSAdrian Chadd 	uint8_t			ni_vht_chan1;	/* 20/40/80/160 - VHT chan1 */
238fdbc9e6eSAdrian Chadd 	uint8_t			ni_vht_chan2;	/* 80+80 - VHT chan2 */
2396d0ef1b9SAdrian Chadd 	uint8_t			ni_vht_chanwidth;	/* IEEE80211_VHT_CHANWIDTH_ */
2406d0ef1b9SAdrian Chadd 	uint8_t			ni_vht_pad1;
241fdbc9e6eSAdrian Chadd 	uint32_t		ni_vht_spare[8];
242fdbc9e6eSAdrian Chadd 
243d0294711SAdrian Chadd 	/* fast-frames state */
244d0294711SAdrian Chadd 	struct mbuf *		ni_tx_superg[WME_NUM_TID];
245d0294711SAdrian Chadd 
2461a1e1d21SSam Leffler 	/* others */
2478a1b9b6aSSam Leffler 	short			ni_inact;	/* inactivity mark count */
2488a1b9b6aSSam Leffler 	short			ni_inact_reload;/* inactivity reload value */
249b032f27cSSam Leffler 	int			ni_txrate;	/* legacy rate/MCS */
25063092fceSSam Leffler 	struct ieee80211_psq	ni_psq;		/* power save queue */
2518a1b9b6aSSam Leffler 	struct ieee80211_nodestats ni_stats;	/* per-node statistics */
252b032f27cSSam Leffler 
253b032f27cSSam Leffler 	struct ieee80211vap	*ni_wdsvap;	/* associated WDS vap */
254b6108616SRui Paulo 	void			*ni_rctls;	/* private ratectl state */
2554d3dcce5SAdrian Chadd 
2564d3dcce5SAdrian Chadd 	/* quiet time IE state for the given node */
2574d3dcce5SAdrian Chadd 	uint32_t		ni_quiet_ie_set;	/* Quiet time IE was seen */
2584d3dcce5SAdrian Chadd 	struct			ieee80211_quiet_ie ni_quiet_ie;	/* last seen quiet IE */
2594d3dcce5SAdrian Chadd 
2608379e8dbSAdrian Chadd 	/* U-APSD */
2618379e8dbSAdrian Chadd 	uint8_t			ni_uapsd;	/* U-APSD per-node flags matching WMM STA QoS Info field */
2628379e8dbSAdrian Chadd 
263917181ddSBjoern A. Zeeb 	void			*ni_drv_data;	/* driver specific */
264917181ddSBjoern A. Zeeb 
265b6108616SRui Paulo 	uint64_t		ni_spare[3];
2661a1e1d21SSam Leffler };
2678a1b9b6aSSam Leffler MALLOC_DECLARE(M_80211_NODE);
268b032f27cSSam Leffler MALLOC_DECLARE(M_80211_NODE_IE);
2698a1b9b6aSSam Leffler 
27068e8e04eSSam Leffler #define	IEEE80211_NODE_ATH	(IEEE80211_NODE_FF | IEEE80211_NODE_TURBOP)
2711b6167d2SSam Leffler #define	IEEE80211_NODE_AMPDU \
2721b6167d2SSam Leffler 	(IEEE80211_NODE_AMPDU_RX | IEEE80211_NODE_AMPDU_TX)
273d0dd594cSSam Leffler #define	IEEE80211_NODE_AMSDU \
274d0dd594cSSam Leffler 	(IEEE80211_NODE_AMSDU_RX | IEEE80211_NODE_AMSDU_TX)
2759c62b7d4SSam Leffler #define	IEEE80211_NODE_HT_ALL \
2769c62b7d4SSam Leffler 	(IEEE80211_NODE_HT | IEEE80211_NODE_HTCOMPAT | \
277d0dd594cSSam Leffler 	 IEEE80211_NODE_AMPDU | IEEE80211_NODE_AMSDU | \
278d0dd594cSSam Leffler 	 IEEE80211_NODE_MIMO_PS | IEEE80211_NODE_MIMO_RTS | \
279d0dd594cSSam Leffler 	 IEEE80211_NODE_RIFS | IEEE80211_NODE_SGI20 | IEEE80211_NODE_SGI40)
28068e8e04eSSam Leffler 
2813d13a955SSam Leffler #define	IEEE80211_NODE_BITS \
2823d13a955SSam Leffler 	"\20\1AUTH\2QOS\3ERP\5PWR_MGT\6AREF\7HT\10HTCOMPAT\11WPS\12TSN" \
2833d13a955SSam Leffler 	"\13AMPDU_RX\14AMPDU_TX\15MIMO_PS\16MIMO_RTS\17RIFS\20SGI20\21SGI40" \
2843d13a955SSam Leffler 	"\22ASSOCID"
2853d13a955SSam Leffler 
2868a1b9b6aSSam Leffler #define	IEEE80211_NODE_AID(ni)	IEEE80211_AID(ni->ni_associd)
2878a1b9b6aSSam Leffler 
2888a1b9b6aSSam Leffler #define	IEEE80211_NODE_STAT(ni,stat)	(ni->ni_stats.ns_##stat++)
2898a1b9b6aSSam Leffler #define	IEEE80211_NODE_STAT_ADD(ni,stat,v)	(ni->ni_stats.ns_##stat += v)
2908a1b9b6aSSam Leffler #define	IEEE80211_NODE_STAT_SET(ni,stat,v)	(ni->ni_stats.ns_##stat = v)
2911a1e1d21SSam Leffler 
292b032f27cSSam Leffler /*
293b032f27cSSam Leffler  * Filtered rssi calculation support.  The receive rssi is maintained
294b032f27cSSam Leffler  * as an average over the last 10 frames received using a low pass filter
295b032f27cSSam Leffler  * (all frames for now, possibly need to be more selective).  Calculations
296b032f27cSSam Leffler  * are designed such that a good compiler can optimize them.  The avg
297b032f27cSSam Leffler  * rssi state should be initialized to IEEE80211_RSSI_DUMMY_MARKER and
298b032f27cSSam Leffler  * each sample incorporated with IEEE80211_RSSI_LPF.  Use IEEE80211_RSSI_GET
299b032f27cSSam Leffler  * to extract the current value.
300b032f27cSSam Leffler  *
301b032f27cSSam Leffler  * Note that we assume rssi data are in the range [-127..127] and we
302b032f27cSSam Leffler  * discard values <-20.  This is consistent with assumptions throughout
303b032f27cSSam Leffler  * net80211 that signal strength data are in .5 dBm units relative to
304b032f27cSSam Leffler  * the current noise floor (linear, not log).
305b032f27cSSam Leffler  */
306b032f27cSSam Leffler #define IEEE80211_RSSI_LPF_LEN		10
307b032f27cSSam Leffler #define	IEEE80211_RSSI_DUMMY_MARKER	127
308b032f27cSSam Leffler /* NB: pow2 to optimize out * and / */
309b032f27cSSam Leffler #define	IEEE80211_RSSI_EP_MULTIPLIER	(1<<7)
310b032f27cSSam Leffler #define IEEE80211_RSSI_IN(x)		((x) * IEEE80211_RSSI_EP_MULTIPLIER)
311b032f27cSSam Leffler #define _IEEE80211_RSSI_LPF(x, y, len) \
312b032f27cSSam Leffler     (((x) != IEEE80211_RSSI_DUMMY_MARKER) ? (((x) * ((len) - 1) + (y)) / (len)) : (y))
313b032f27cSSam Leffler #define IEEE80211_RSSI_LPF(x, y) do {					\
314b032f27cSSam Leffler     if ((y) >= -20) {							\
315b032f27cSSam Leffler     	x = _IEEE80211_RSSI_LPF((x), IEEE80211_RSSI_IN((y)), 		\
316b032f27cSSam Leffler 		IEEE80211_RSSI_LPF_LEN);				\
317b032f27cSSam Leffler     }									\
318b032f27cSSam Leffler } while (0)
319b032f27cSSam Leffler #define	IEEE80211_RSSI_EP_RND(x, mul) \
320b032f27cSSam Leffler 	((((x) % (mul)) >= ((mul)/2)) ? ((x) + ((mul) - 1)) / (mul) : (x)/(mul))
321b032f27cSSam Leffler #define	IEEE80211_RSSI_GET(x) \
322b032f27cSSam Leffler 	IEEE80211_RSSI_EP_RND(x, IEEE80211_RSSI_EP_MULTIPLIER)
323b032f27cSSam Leffler 
3241a1e1d21SSam Leffler static __inline struct ieee80211_node *
3251a1e1d21SSam Leffler ieee80211_ref_node(struct ieee80211_node *ni)
3261a1e1d21SSam Leffler {
3278a1b9b6aSSam Leffler 	ieee80211_node_incref(ni);
3281a1e1d21SSam Leffler 	return ni;
3291a1e1d21SSam Leffler }
3301a1e1d21SSam Leffler 
3311a1e1d21SSam Leffler static __inline void
3321a1e1d21SSam Leffler ieee80211_unref_node(struct ieee80211_node **ni)
3331a1e1d21SSam Leffler {
3348a1b9b6aSSam Leffler 	ieee80211_node_decref(*ni);
3351a1e1d21SSam Leffler 	*ni = NULL;			/* guard against use */
3361a1e1d21SSam Leffler }
3371a1e1d21SSam Leffler 
3380942c81cSSam Leffler void	ieee80211_node_attach(struct ieee80211com *);
3390942c81cSSam Leffler void	ieee80211_node_lateattach(struct ieee80211com *);
3400942c81cSSam Leffler void	ieee80211_node_detach(struct ieee80211com *);
341b032f27cSSam Leffler void	ieee80211_node_vattach(struct ieee80211vap *);
342b032f27cSSam Leffler void	ieee80211_node_latevattach(struct ieee80211vap *);
343b032f27cSSam Leffler void	ieee80211_node_vdetach(struct ieee80211vap *);
344566a6538SSam Leffler 
3458a1b9b6aSSam Leffler static __inline int
3468a1b9b6aSSam Leffler ieee80211_node_is_authorized(const struct ieee80211_node *ni)
3478a1b9b6aSSam Leffler {
3488a1b9b6aSSam Leffler 	return (ni->ni_flags & IEEE80211_NODE_AUTH);
3498a1b9b6aSSam Leffler }
3501a1e1d21SSam Leffler 
351e4918ecdSSam Leffler void	ieee80211_node_authorize(struct ieee80211_node *);
352e4918ecdSSam Leffler void	ieee80211_node_unauthorize(struct ieee80211_node *);
3531a1e1d21SSam Leffler 
354d77148fbSSam Leffler void	ieee80211_node_setuptxparms(struct ieee80211_node *);
355b032f27cSSam Leffler void	ieee80211_node_set_chan(struct ieee80211_node *,
356b032f27cSSam Leffler 		struct ieee80211_channel *);
357b032f27cSSam Leffler void	ieee80211_create_ibss(struct ieee80211vap*, struct ieee80211_channel *);
358b032f27cSSam Leffler void	ieee80211_reset_bss(struct ieee80211vap *);
359b032f27cSSam Leffler void	ieee80211_sync_curchan(struct ieee80211com *);
3605efea30fSAndrew Thompson void	ieee80211_setupcurchan(struct ieee80211com *,
3615efea30fSAndrew Thompson 	    struct ieee80211_channel *);
362b032f27cSSam Leffler void	ieee80211_setcurchan(struct ieee80211com *, struct ieee80211_channel *);
363b94299c4SAdrian Chadd void	ieee80211_update_chw(struct ieee80211com *);
364adad5b45SAdrian Chadd int	ieee80211_ibss_merge_check(struct ieee80211_node *);
365172b009aSAdrian Chadd int	ieee80211_ibss_node_check_new(struct ieee80211_node *ni,
366172b009aSAdrian Chadd 	    const struct ieee80211_scanparams *);
367641b4d0bSSam Leffler int	ieee80211_ibss_merge(struct ieee80211_node *);
36868e8e04eSSam Leffler struct ieee80211_scan_entry;
36910959256SSam Leffler int	ieee80211_sta_join(struct ieee80211vap *, struct ieee80211_channel *,
37068e8e04eSSam Leffler 		const struct ieee80211_scan_entry *);
371b032f27cSSam Leffler void	ieee80211_sta_leave(struct ieee80211_node *);
372b032f27cSSam Leffler void	ieee80211_node_deauth(struct ieee80211_node *, int);
373b032f27cSSam Leffler 
374b032f27cSSam Leffler int	ieee80211_ies_init(struct ieee80211_ies *, const uint8_t *, int);
375b032f27cSSam Leffler void	ieee80211_ies_cleanup(struct ieee80211_ies *);
376b032f27cSSam Leffler void	ieee80211_ies_expand(struct ieee80211_ies *);
377b032f27cSSam Leffler #define	ieee80211_ies_setie(_ies, _ie, _off) do {		\
378b032f27cSSam Leffler 	(_ies)._ie = (_ies).data + (_off);			\
379b032f27cSSam Leffler } while (0)
3808a1b9b6aSSam Leffler 
3818a1b9b6aSSam Leffler /*
3828a1b9b6aSSam Leffler  * Table of ieee80211_node instances.  Each ieee80211com
383b032f27cSSam Leffler  * has one that holds association stations (when operating
384b032f27cSSam Leffler  * as an ap) or neighbors (in ibss mode).
385b032f27cSSam Leffler  *
386b032f27cSSam Leffler  * XXX embed this in ieee80211com instead of indirect?
3878a1b9b6aSSam Leffler  */
3888a1b9b6aSSam Leffler struct ieee80211_node_table {
3898a1b9b6aSSam Leffler 	struct ieee80211com	*nt_ic;		/* back reference */
3908a1b9b6aSSam Leffler 	ieee80211_node_lock_t	nt_nodelock;	/* on node table */
3918a1b9b6aSSam Leffler 	TAILQ_HEAD(, ieee80211_node) nt_node;	/* information of all nodes */
3928a1b9b6aSSam Leffler 	LIST_HEAD(, ieee80211_node) nt_hash[IEEE80211_NODE_HASHSIZE];
393d2e877f0SAndriy Voskoboinyk 	int			nt_count;	/* number of nodes */
39468e8e04eSSam Leffler 	struct ieee80211_node	**nt_keyixmap;	/* key ix -> node map */
39568e8e04eSSam Leffler 	int			nt_keyixmax;	/* keyixmap size */
396b032f27cSSam Leffler 	const char		*nt_name;	/* table name for debug msgs */
3978a1b9b6aSSam Leffler 	int			nt_inact_init;	/* initial node inact setting */
3988a1b9b6aSSam Leffler };
3998a1b9b6aSSam Leffler 
400b032f27cSSam Leffler struct ieee80211_node *ieee80211_alloc_node(struct ieee80211_node_table *,
401b032f27cSSam Leffler 		struct ieee80211vap *,
402b032f27cSSam Leffler 		const uint8_t macaddr[IEEE80211_ADDR_LEN]);
403b032f27cSSam Leffler struct ieee80211_node *ieee80211_tmp_node(struct ieee80211vap *,
404b032f27cSSam Leffler 		const uint8_t macaddr[IEEE80211_ADDR_LEN]);
405b032f27cSSam Leffler struct ieee80211_node *ieee80211_dup_bss(struct ieee80211vap *,
406b032f27cSSam Leffler 		const uint8_t macaddr[IEEE80211_ADDR_LEN]);
407b032f27cSSam Leffler struct ieee80211_node *ieee80211_node_create_wds(struct ieee80211vap *,
408b032f27cSSam Leffler 		const uint8_t bssid[IEEE80211_ADDR_LEN],
409b032f27cSSam Leffler 		struct ieee80211_channel *);
4104a8e4d15SBjoern A. Zeeb 
4114a8e4d15SBjoern A. Zeeb /* These functions are taking __func__, __LINE__ for IEEE80211_DEBUG_REFCNT */
4124a8e4d15SBjoern A. Zeeb void	_ieee80211_free_node(struct ieee80211_node *,
4138a1b9b6aSSam Leffler 		const char *func, int line);
4144a8e4d15SBjoern A. Zeeb struct ieee80211_node *_ieee80211_find_node_locked(
415b032f27cSSam Leffler 		struct ieee80211_node_table *,
416b032f27cSSam Leffler 		const uint8_t macaddr[IEEE80211_ADDR_LEN],
417b032f27cSSam Leffler 		const char *func, int line);
4184a8e4d15SBjoern A. Zeeb struct ieee80211_node *_ieee80211_find_node(struct ieee80211_node_table *,
419b032f27cSSam Leffler 		const uint8_t macaddr[IEEE80211_ADDR_LEN],
420b032f27cSSam Leffler 		const char *func, int line);
4214a8e4d15SBjoern A. Zeeb struct ieee80211_node *_ieee80211_find_vap_node_locked(
422b032f27cSSam Leffler 		struct ieee80211_node_table *,
423b032f27cSSam Leffler 		const struct ieee80211vap *vap,
424b032f27cSSam Leffler 		const uint8_t macaddr[IEEE80211_ADDR_LEN],
425b032f27cSSam Leffler 		const char *func, int line);
4264a8e4d15SBjoern A. Zeeb struct ieee80211_node *_ieee80211_find_vap_node(
427b032f27cSSam Leffler 		struct ieee80211_node_table *,
428b032f27cSSam Leffler 		const struct ieee80211vap *vap,
429b032f27cSSam Leffler 		const uint8_t macaddr[IEEE80211_ADDR_LEN],
4308a1b9b6aSSam Leffler 		const char *func, int line);
4314a8e4d15SBjoern A. Zeeb struct ieee80211_node *_ieee80211_find_rxnode(struct ieee80211com *,
43268e8e04eSSam Leffler 		const struct ieee80211_frame_min *,
4338a1b9b6aSSam Leffler 		const char *func, int line);
4344a8e4d15SBjoern A. Zeeb struct ieee80211_node *_ieee80211_find_rxnode_withkey(
435c1225b52SSam Leffler 		struct ieee80211com *,
43668e8e04eSSam Leffler 		const struct ieee80211_frame_min *, uint16_t keyix,
437c1225b52SSam Leffler 		const char *func, int line);
4384a8e4d15SBjoern A. Zeeb struct ieee80211_node *_ieee80211_find_txnode(struct ieee80211vap *,
439*1f078120SJohn Baldwin 		const uint8_t macaddr[IEEE80211_ADDR_LEN],
44068e8e04eSSam Leffler 		const char *func, int line);
4418a1b9b6aSSam Leffler #define	ieee80211_free_node(ni) \
4424a8e4d15SBjoern A. Zeeb 	_ieee80211_free_node(ni, __func__, __LINE__)
443b032f27cSSam Leffler #define	ieee80211_find_node_locked(nt, mac) \
4444a8e4d15SBjoern A. Zeeb 	_ieee80211_find_node_locked(nt, mac, __func__, __LINE__)
4458a1b9b6aSSam Leffler #define	ieee80211_find_node(nt, mac) \
4464a8e4d15SBjoern A. Zeeb 	_ieee80211_find_node(nt, mac, __func__, __LINE__)
447b032f27cSSam Leffler #define	ieee80211_find_vap_node_locked(nt, vap, mac) \
4484a8e4d15SBjoern A. Zeeb 	_ieee80211_find_vap_node_locked(nt, vap, mac, __func__, __LINE__)
449b032f27cSSam Leffler #define	ieee80211_find_vap_node(nt, vap, mac) \
4504a8e4d15SBjoern A. Zeeb 	_ieee80211_find_vap_node(nt, vap, mac, __func__, __LINE__)
451b032f27cSSam Leffler #define	ieee80211_find_rxnode(ic, wh) \
4524a8e4d15SBjoern A. Zeeb 	_ieee80211_find_rxnode(ic, wh, __func__, __LINE__)
453b032f27cSSam Leffler #define	ieee80211_find_rxnode_withkey(ic, wh, keyix) \
4544a8e4d15SBjoern A. Zeeb 	_ieee80211_find_rxnode_withkey(ic, wh, keyix, __func__, __LINE__)
455b032f27cSSam Leffler #define	ieee80211_find_txnode(vap, mac) \
4564a8e4d15SBjoern A. Zeeb 	_ieee80211_find_txnode(vap, mac, __func__, __LINE__)
4574a8e4d15SBjoern A. Zeeb 
458c1225b52SSam Leffler int	ieee80211_node_delucastkey(struct ieee80211_node *);
45968e8e04eSSam Leffler void	ieee80211_node_timeout(void *arg);
4608a1b9b6aSSam Leffler 
4618a1b9b6aSSam Leffler typedef void ieee80211_iter_func(void *, struct ieee80211_node *);
462d2e877f0SAndriy Voskoboinyk int	ieee80211_iterate_nodes_vap(struct ieee80211_node_table *,
463d2e877f0SAndriy Voskoboinyk 		struct ieee80211vap *, ieee80211_iter_func *, void *);
4640942c81cSSam Leffler void	ieee80211_iterate_nodes(struct ieee80211_node_table *,
4658a1b9b6aSSam Leffler 		ieee80211_iter_func *, void *);
4668a1b9b6aSSam Leffler 
467f1481c8dSAdrian Chadd void	ieee80211_notify_erp_locked(struct ieee80211com *);
4680942c81cSSam Leffler void	ieee80211_dump_node(struct ieee80211_node_table *,
4698a1b9b6aSSam Leffler 		struct ieee80211_node *);
4700942c81cSSam Leffler void	ieee80211_dump_nodes(struct ieee80211_node_table *);
4718a1b9b6aSSam Leffler 
472b032f27cSSam Leffler struct ieee80211_node *ieee80211_fakeup_adhoc_node(struct ieee80211vap *,
473b032f27cSSam Leffler 		const uint8_t macaddr[IEEE80211_ADDR_LEN]);
47468e8e04eSSam Leffler struct ieee80211_scanparams;
475be425a0fSSam Leffler void	ieee80211_init_neighbor(struct ieee80211_node *,
476be425a0fSSam Leffler 		const struct ieee80211_frame *,
477be425a0fSSam Leffler 		const struct ieee80211_scanparams *);
478b032f27cSSam Leffler struct ieee80211_node *ieee80211_add_neighbor(struct ieee80211vap *,
479b5c99415SSam Leffler 		const struct ieee80211_frame *,
480b5c99415SSam Leffler 		const struct ieee80211_scanparams *);
481b032f27cSSam Leffler void	ieee80211_node_join(struct ieee80211_node *,int);
482b032f27cSSam Leffler void	ieee80211_node_leave(struct ieee80211_node *);
483b032f27cSSam Leffler int8_t	ieee80211_getrssi(struct ieee80211vap *);
484b032f27cSSam Leffler void	ieee80211_getsignal(struct ieee80211vap *, int8_t *, int8_t *);
4851a1e1d21SSam Leffler #endif /* _NET80211_IEEE80211_NODE_H_ */
486