xref: /freebsd/sys/net80211/ieee80211_node.h (revision d029471197792b75e7bb99333457d3e1897171ea)
11a1e1d21SSam Leffler /*-
27535e66aSSam Leffler  * Copyright (c) 2001 Atsushi Onoe
310ad9a77SSam Leffler  * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
41a1e1d21SSam Leffler  * All rights reserved.
51a1e1d21SSam Leffler  *
61a1e1d21SSam Leffler  * Redistribution and use in source and binary forms, with or without
71a1e1d21SSam Leffler  * modification, are permitted provided that the following conditions
81a1e1d21SSam Leffler  * are met:
91a1e1d21SSam Leffler  * 1. Redistributions of source code must retain the above copyright
101a1e1d21SSam Leffler  *    notice, this list of conditions and the following disclaimer.
111a1e1d21SSam Leffler  * 2. Redistributions in binary form must reproduce the above copyright
121a1e1d21SSam Leffler  *    notice, this list of conditions and the following disclaimer in the
131a1e1d21SSam Leffler  *    documentation and/or other materials provided with the distribution.
147535e66aSSam Leffler  *
157535e66aSSam Leffler  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
167535e66aSSam Leffler  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
177535e66aSSam Leffler  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
187535e66aSSam Leffler  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
197535e66aSSam Leffler  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
207535e66aSSam Leffler  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
217535e66aSSam Leffler  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
227535e66aSSam Leffler  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
237535e66aSSam Leffler  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
247535e66aSSam Leffler  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
251a1e1d21SSam Leffler  *
261a1e1d21SSam Leffler  * $FreeBSD$
271a1e1d21SSam Leffler  */
281a1e1d21SSam Leffler #ifndef _NET80211_IEEE80211_NODE_H_
291a1e1d21SSam Leffler #define _NET80211_IEEE80211_NODE_H_
301a1e1d21SSam Leffler 
318a1b9b6aSSam Leffler #include <net80211/ieee80211_ioctl.h>		/* for ieee80211_nodestats */
3268e8e04eSSam Leffler #include <net80211/ieee80211_ht.h>		/* for aggregation state */
338a1b9b6aSSam Leffler 
348a1b9b6aSSam Leffler /*
35b032f27cSSam Leffler  * Each ieee80211com instance has a single timer that fires every
36b032f27cSSam Leffler  * IEEE80211_INACT_WAIT seconds to handle "inactivity processing".
37b032f27cSSam Leffler  * This is used to do node inactivity processing when operating
3859aa14a9SRui Paulo  * as an AP, adhoc or mesh mode.  For inactivity processing each node
39b032f27cSSam Leffler  * has a timeout set in it's ni_inact field that is decremented
40b032f27cSSam Leffler  * on each timeout and the node is reclaimed when the counter goes
41b032f27cSSam Leffler  * to zero.  We use different inactivity timeout values depending
42b032f27cSSam Leffler  * on whether the node is associated and authorized (either by
43b032f27cSSam Leffler  * 802.1x or open/shared key authentication) or associated but yet
44b032f27cSSam Leffler  * to be authorized.  The latter timeout is shorter to more aggressively
458a1b9b6aSSam Leffler  * reclaim nodes that leave part way through the 802.1x exchange.
468a1b9b6aSSam Leffler  */
478a1b9b6aSSam Leffler #define	IEEE80211_INACT_WAIT	15		/* inactivity interval (secs) */
488a1b9b6aSSam Leffler #define	IEEE80211_INACT_INIT	(30/IEEE80211_INACT_WAIT)	/* initial */
498a1b9b6aSSam Leffler #define	IEEE80211_INACT_AUTH	(180/IEEE80211_INACT_WAIT)	/* associated but not authorized */
508a1b9b6aSSam Leffler #define	IEEE80211_INACT_RUN	(300/IEEE80211_INACT_WAIT)	/* authorized */
518a1b9b6aSSam Leffler #define	IEEE80211_INACT_PROBE	(30/IEEE80211_INACT_WAIT)	/* probe */
528a1b9b6aSSam Leffler #define	IEEE80211_INACT_SCAN	(300/IEEE80211_INACT_WAIT)	/* scanned */
538a1b9b6aSSam Leffler 
5468e8e04eSSam Leffler #define	IEEE80211_TRANS_WAIT 	2		/* mgt frame tx timer (secs) */
551a1e1d21SSam Leffler 
56b105a069SSam Leffler /* threshold for aging overlapping non-ERP bss */
57b105a069SSam Leffler #define	IEEE80211_NONERP_PRESENT_AGE	msecs_to_ticks(60*1000)
58b105a069SSam Leffler 
5959aa14a9SRui Paulo #define	IEEE80211_NODE_HASHSIZE	32		/* NB: hash size must be pow2 */
601a1e1d21SSam Leffler /* simple hash is enough for variation of macaddr */
6159aa14a9SRui Paulo #define	IEEE80211_NODE_HASH(ic, addr)	\
6268e8e04eSSam Leffler 	(((const uint8_t *)(addr))[IEEE80211_ADDR_LEN - 1] % \
638a1b9b6aSSam Leffler 		IEEE80211_NODE_HASHSIZE)
641a1e1d21SSam Leffler 
658a1b9b6aSSam Leffler struct ieee80211_node_table;
668a1b9b6aSSam Leffler struct ieee80211com;
67b032f27cSSam Leffler struct ieee80211vap;
68b032f27cSSam Leffler 
69b032f27cSSam Leffler /*
70b032f27cSSam Leffler  * Information element ``blob''.  We use this structure
71b032f27cSSam Leffler  * to capture management frame payloads that need to be
720ce9091aSRui Paulo  * retained.  Information elements within the payload that
73b032f27cSSam Leffler  * we need to consult have references recorded.
74b032f27cSSam Leffler  */
75b032f27cSSam Leffler struct ieee80211_ies {
76b032f27cSSam Leffler 	/* the following are either NULL or point within data */
77b032f27cSSam Leffler 	uint8_t	*wpa_ie;	/* captured WPA ie */
78b032f27cSSam Leffler 	uint8_t	*rsn_ie;	/* captured RSN ie */
79b032f27cSSam Leffler 	uint8_t	*wme_ie;	/* captured WME ie */
80b032f27cSSam Leffler 	uint8_t	*ath_ie;	/* captured Atheros ie */
81b032f27cSSam Leffler 	uint8_t	*htcap_ie;	/* captured HTCAP ie */
82b032f27cSSam Leffler 	uint8_t	*htinfo_ie;	/* captured HTINFO ie */
8310ad9a77SSam Leffler 	uint8_t	*tdma_ie;	/* captured TDMA ie */
8459aa14a9SRui Paulo 	uint8_t *meshid_ie;	/* captured MESH ID ie */
85a43cee70SSam Leffler 	uint8_t	*spare[4];
86b032f27cSSam Leffler 	/* NB: these must be the last members of this structure */
87b032f27cSSam Leffler 	uint8_t	*data;		/* frame data > 802.11 header */
88b032f27cSSam Leffler 	int	len;		/* data size in bytes */
89b032f27cSSam Leffler };
908a1b9b6aSSam Leffler 
911a1e1d21SSam Leffler /*
9259aa14a9SRui Paulo  * 802.11s (Mesh) Peer Link FSM state.
9359aa14a9SRui Paulo  */
9459aa14a9SRui Paulo enum ieee80211_mesh_mlstate {
9559aa14a9SRui Paulo 	IEEE80211_NODE_MESH_IDLE	= 0,
9659aa14a9SRui Paulo 	IEEE80211_NODE_MESH_OPENSNT	= 1,	/* open frame sent */
9759aa14a9SRui Paulo 	IEEE80211_NODE_MESH_OPENRCV	= 2,	/* open frame received */
9859aa14a9SRui Paulo 	IEEE80211_NODE_MESH_CONFIRMRCV	= 3,	/* confirm frame received */
9959aa14a9SRui Paulo 	IEEE80211_NODE_MESH_ESTABLISHED	= 4,	/* link established */
10059aa14a9SRui Paulo 	IEEE80211_NODE_MESH_HOLDING	= 5,	/* link closing */
10159aa14a9SRui Paulo };
10259aa14a9SRui Paulo #define	IEEE80211_MESH_MLSTATE_BITS \
10359aa14a9SRui Paulo 	"\20\1IDLE\2OPENSNT\2OPENRCV\3CONFIRMRCV\4ESTABLISHED\5HOLDING"
10459aa14a9SRui Paulo 
10559aa14a9SRui Paulo /*
1061a1e1d21SSam Leffler  * Node specific information.  Note that drivers are expected
1071a1e1d21SSam Leffler  * to derive from this structure to add device-specific per-node
1081a1e1d21SSam Leffler  * state.  This is done by overriding the ic_node_* methods in
1091a1e1d21SSam Leffler  * the ieee80211com structure.
1101a1e1d21SSam Leffler  */
1111a1e1d21SSam Leffler struct ieee80211_node {
112b032f27cSSam Leffler 	struct ieee80211vap	*ni_vap;	/* associated vap */
113b032f27cSSam Leffler 	struct ieee80211com	*ni_ic;		/* copy from vap to save deref*/
114b032f27cSSam Leffler 	struct ieee80211_node_table *ni_table;	/* NB: may be NULL */
115b032f27cSSam Leffler 	TAILQ_ENTRY(ieee80211_node) ni_list;	/* list of all nodes */
116b032f27cSSam Leffler 	LIST_ENTRY(ieee80211_node) ni_hash;	/* hash collision list */
117b032f27cSSam Leffler 	u_int			ni_refcnt;	/* count of held references */
118303ebc3cSSam Leffler 	u_int			ni_scangen;	/* gen# for timeout scan */
119c4fe3956SSam Leffler 	u_int			ni_flags;
120c4fe3956SSam Leffler #define	IEEE80211_NODE_AUTH	0x000001	/* authorized for data */
121c4fe3956SSam Leffler #define	IEEE80211_NODE_QOS	0x000002	/* QoS enabled */
122c4fe3956SSam Leffler #define	IEEE80211_NODE_ERP	0x000004	/* ERP enabled */
123c4fe3956SSam Leffler /* NB: this must have the same value as IEEE80211_FC1_PWR_MGT */
124c4fe3956SSam Leffler #define	IEEE80211_NODE_PWR_MGT	0x000010	/* power save mode enabled */
125c4fe3956SSam Leffler #define	IEEE80211_NODE_AREF	0x000020	/* authentication ref held */
126c4fe3956SSam Leffler #define	IEEE80211_NODE_HT	0x000040	/* HT enabled */
127c4fe3956SSam Leffler #define	IEEE80211_NODE_HTCOMPAT	0x000080	/* HT setup w/ vendor OUI's */
128c4fe3956SSam Leffler #define	IEEE80211_NODE_WPS	0x000100	/* WPS association */
129c4fe3956SSam Leffler #define	IEEE80211_NODE_TSN	0x000200	/* TSN association */
130c4fe3956SSam Leffler #define	IEEE80211_NODE_AMPDU_RX	0x000400	/* AMPDU rx enabled */
131c4fe3956SSam Leffler #define	IEEE80211_NODE_AMPDU_TX	0x000800	/* AMPDU tx enabled */
1328c070d69SSam Leffler #define	IEEE80211_NODE_MIMO_PS	0x001000	/* MIMO power save enabled */
1338c070d69SSam Leffler #define	IEEE80211_NODE_MIMO_RTS	0x002000	/* send RTS in MIMO PS */
13444f7a6edSSam Leffler #define	IEEE80211_NODE_RIFS	0x004000	/* RIFS enabled */
13549942a97SSam Leffler #define	IEEE80211_NODE_SGI20	0x008000	/* Short GI in HT20 enabled */
13649942a97SSam Leffler #define	IEEE80211_NODE_SGI40	0x010000	/* Short GI in HT40 enabled */
1371b999d64SSam Leffler #define	IEEE80211_NODE_ASSOCID	0x020000	/* xmit requires associd */
138d0dd594cSSam Leffler #define	IEEE80211_NODE_AMSDU_RX	0x040000	/* AMSDU rx enabled */
139d0dd594cSSam Leffler #define	IEEE80211_NODE_AMSDU_TX	0x080000	/* AMSDU tx enabled */
140c4fe3956SSam Leffler 	uint16_t		ni_associd;	/* association ID */
141c4fe3956SSam Leffler 	uint16_t		ni_vlan;	/* vlan tag */
142c4fe3956SSam Leffler 	uint16_t		ni_txpower;	/* current transmit power */
14368e8e04eSSam Leffler 	uint8_t			ni_authmode;	/* authentication algorithm */
14468e8e04eSSam Leffler 	uint8_t			ni_ath_flags;	/* Atheros feature flags */
14568e8e04eSSam Leffler 	/* NB: These must have the same values as IEEE80211_ATHC_* */
14668e8e04eSSam Leffler #define IEEE80211_NODE_TURBOP	0x0001		/* Turbo prime enable */
14768e8e04eSSam Leffler #define IEEE80211_NODE_COMP	0x0002		/* Compresssion enable */
14868e8e04eSSam Leffler #define IEEE80211_NODE_FF	0x0004          /* Fast Frame capable */
14968e8e04eSSam Leffler #define IEEE80211_NODE_XR	0x0008		/* Atheros WME enable */
15068e8e04eSSam Leffler #define IEEE80211_NODE_AR	0x0010		/* AR capable */
151c4fe3956SSam Leffler #define IEEE80211_NODE_BOOST	0x0080		/* Dynamic Turbo boosted */
15268e8e04eSSam Leffler 	uint16_t		ni_ath_defkeyix;/* Atheros def key index */
15301a03542SSam Leffler 	const struct ieee80211_txparam *ni_txparms;
1541b6167d2SSam Leffler 	uint32_t		ni_jointime;	/* time of join (secs) */
15568e8e04eSSam Leffler 	uint32_t		*ni_challenge;	/* shared-key challenge */
156b032f27cSSam Leffler 	struct ieee80211_ies	ni_ies;		/* captured ie's */
157b337fbc4SSam Leffler 						/* tx seq per-tid */
158dca68715SSam Leffler 	ieee80211_seq		ni_txseqs[IEEE80211_TID_SIZE];
159b337fbc4SSam Leffler 						/* rx seq previous per-tid*/
160dca68715SSam Leffler 	ieee80211_seq		ni_rxseqs[IEEE80211_TID_SIZE];
16168e8e04eSSam Leffler 	uint32_t		ni_rxfragstamp;	/* time stamp of last rx frag */
1628a1b9b6aSSam Leffler 	struct mbuf		*ni_rxfrag[3];	/* rx frag reassembly */
1638a1b9b6aSSam Leffler 	struct ieee80211_key	ni_ucastkey;	/* unicast key */
1641a1e1d21SSam Leffler 
1651a1e1d21SSam Leffler 	/* hardware */
166b032f27cSSam Leffler 	uint32_t		ni_avgrssi;	/* recv ssi state */
16768e8e04eSSam Leffler 	int8_t			ni_noise;	/* noise floor */
1681a1e1d21SSam Leffler 
169864ab114SAdrian Chadd 	/* mimo statistics */
170864ab114SAdrian Chadd 	uint32_t		ni_mimo_rssi_ctl[IEEE80211_MAX_CHAINS];
171864ab114SAdrian Chadd 	uint32_t		ni_mimo_rssi_ext[IEEE80211_MAX_CHAINS];
172864ab114SAdrian Chadd 	uint8_t			ni_mimo_noise_ctl[IEEE80211_MAX_CHAINS];
173864ab114SAdrian Chadd 	uint8_t			ni_mimo_noise_ext[IEEE80211_MAX_CHAINS];
174864ab114SAdrian Chadd 	uint8_t			ni_mimo_chains;
175864ab114SAdrian Chadd 
1761a1e1d21SSam Leffler 	/* header */
17768e8e04eSSam Leffler 	uint8_t			ni_macaddr[IEEE80211_ADDR_LEN];
17868e8e04eSSam Leffler 	uint8_t			ni_bssid[IEEE80211_ADDR_LEN];
1791a1e1d21SSam Leffler 
1801a1e1d21SSam Leffler 	/* beacon, probe response */
1818a1b9b6aSSam Leffler 	union {
18268e8e04eSSam Leffler 		uint8_t		data[8];
183b032f27cSSam Leffler 		u_int64_t	tsf;
1848a1b9b6aSSam Leffler 	} ni_tstamp;				/* from last rcv'd beacon */
18568e8e04eSSam Leffler 	uint16_t		ni_intval;	/* beacon interval */
18668e8e04eSSam Leffler 	uint16_t		ni_capinfo;	/* capabilities */
18768e8e04eSSam Leffler 	uint8_t			ni_esslen;
18868e8e04eSSam Leffler 	uint8_t			ni_essid[IEEE80211_NWID_LEN];
1891a1e1d21SSam Leffler 	struct ieee80211_rateset ni_rates;	/* negotiated rate set */
19068e8e04eSSam Leffler 	struct ieee80211_channel *ni_chan;
19168e8e04eSSam Leffler 	uint16_t		ni_fhdwell;	/* FH only */
19268e8e04eSSam Leffler 	uint8_t			ni_fhindex;	/* FH only */
193b032f27cSSam Leffler 	uint16_t		ni_erp;		/* ERP from beacon/probe resp */
19468e8e04eSSam Leffler 	uint16_t		ni_timoff;	/* byte offset to TIM ie */
19568e8e04eSSam Leffler 	uint8_t			ni_dtim_period;	/* DTIM period */
19668e8e04eSSam Leffler 	uint8_t			ni_dtim_count;	/* DTIM count for last bcn */
19768e8e04eSSam Leffler 
19859aa14a9SRui Paulo 	/* 11s state */
19959aa14a9SRui Paulo 	uint8_t			ni_meshidlen;
20059aa14a9SRui Paulo 	uint8_t			ni_meshid[IEEE80211_MESHID_LEN];
20159aa14a9SRui Paulo 	enum ieee80211_mesh_mlstate ni_mlstate;	/* peering management state */
20259aa14a9SRui Paulo 	uint16_t		ni_mllid;	/* link local ID */
20359aa14a9SRui Paulo 	uint16_t		ni_mlpid;	/* link peer ID */
20459aa14a9SRui Paulo 	struct callout		ni_mltimer;	/* link mesh timer */
20559aa14a9SRui Paulo 	uint8_t			ni_mlrcnt;	/* link mesh retry counter */
20659aa14a9SRui Paulo 	uint8_t			ni_mltval;	/* link mesh timer value */
207ff17492fSMonthadar Al Jaberi 	struct callout		ni_mlhtimer;	/* link mesh backoff timer */
208ff17492fSMonthadar Al Jaberi 	uint8_t			ni_mlhcnt;	/* link mesh holding counter */
20959aa14a9SRui Paulo 
21068e8e04eSSam Leffler 	/* 11n state */
21168e8e04eSSam Leffler 	uint16_t		ni_htcap;	/* HT capabilities */
21268e8e04eSSam Leffler 	uint8_t			ni_htparam;	/* HT params */
21368e8e04eSSam Leffler 	uint8_t			ni_htctlchan;	/* HT control channel */
21468e8e04eSSam Leffler 	uint8_t			ni_ht2ndchan;	/* HT 2nd channel */
21568e8e04eSSam Leffler 	uint8_t			ni_htopmode;	/* HT operating mode */
21668e8e04eSSam Leffler 	uint8_t			ni_htstbc;	/* HT */
21768e8e04eSSam Leffler 	uint8_t			ni_chw;		/* negotiated channel width */
21868e8e04eSSam Leffler 	struct ieee80211_htrateset ni_htrates;	/* negotiated ht rate set */
2192aa563dfSAdrian Chadd 	struct ieee80211_tx_ampdu ni_tx_ampdu[WME_NUM_TID];
22068e8e04eSSam Leffler 	struct ieee80211_rx_ampdu ni_rx_ampdu[WME_NUM_TID];
2211a1e1d21SSam Leffler 
222*d0294711SAdrian Chadd 	/* fast-frames state */
223*d0294711SAdrian Chadd 	struct mbuf *		ni_tx_superg[WME_NUM_TID];
224*d0294711SAdrian Chadd 
2251a1e1d21SSam Leffler 	/* others */
2268a1b9b6aSSam Leffler 	short			ni_inact;	/* inactivity mark count */
2278a1b9b6aSSam Leffler 	short			ni_inact_reload;/* inactivity reload value */
228b032f27cSSam Leffler 	int			ni_txrate;	/* legacy rate/MCS */
22963092fceSSam Leffler 	struct ieee80211_psq	ni_psq;		/* power save queue */
2308a1b9b6aSSam Leffler 	struct ieee80211_nodestats ni_stats;	/* per-node statistics */
231b032f27cSSam Leffler 
232b032f27cSSam Leffler 	struct ieee80211vap	*ni_wdsvap;	/* associated WDS vap */
233b6108616SRui Paulo 	void			*ni_rctls;	/* private ratectl state */
234b6108616SRui Paulo 	uint64_t		ni_spare[3];
2351a1e1d21SSam Leffler };
2368a1b9b6aSSam Leffler MALLOC_DECLARE(M_80211_NODE);
237b032f27cSSam Leffler MALLOC_DECLARE(M_80211_NODE_IE);
2388a1b9b6aSSam Leffler 
23968e8e04eSSam Leffler #define	IEEE80211_NODE_ATH	(IEEE80211_NODE_FF | IEEE80211_NODE_TURBOP)
2401b6167d2SSam Leffler #define	IEEE80211_NODE_AMPDU \
2411b6167d2SSam Leffler 	(IEEE80211_NODE_AMPDU_RX | IEEE80211_NODE_AMPDU_TX)
242d0dd594cSSam Leffler #define	IEEE80211_NODE_AMSDU \
243d0dd594cSSam Leffler 	(IEEE80211_NODE_AMSDU_RX | IEEE80211_NODE_AMSDU_TX)
2449c62b7d4SSam Leffler #define	IEEE80211_NODE_HT_ALL \
2459c62b7d4SSam Leffler 	(IEEE80211_NODE_HT | IEEE80211_NODE_HTCOMPAT | \
246d0dd594cSSam Leffler 	 IEEE80211_NODE_AMPDU | IEEE80211_NODE_AMSDU | \
247d0dd594cSSam Leffler 	 IEEE80211_NODE_MIMO_PS | IEEE80211_NODE_MIMO_RTS | \
248d0dd594cSSam Leffler 	 IEEE80211_NODE_RIFS | IEEE80211_NODE_SGI20 | IEEE80211_NODE_SGI40)
24968e8e04eSSam Leffler 
2503d13a955SSam Leffler #define	IEEE80211_NODE_BITS \
2513d13a955SSam Leffler 	"\20\1AUTH\2QOS\3ERP\5PWR_MGT\6AREF\7HT\10HTCOMPAT\11WPS\12TSN" \
2523d13a955SSam Leffler 	"\13AMPDU_RX\14AMPDU_TX\15MIMO_PS\16MIMO_RTS\17RIFS\20SGI20\21SGI40" \
2533d13a955SSam Leffler 	"\22ASSOCID"
2543d13a955SSam Leffler 
2558a1b9b6aSSam Leffler #define	IEEE80211_NODE_AID(ni)	IEEE80211_AID(ni->ni_associd)
2568a1b9b6aSSam Leffler 
2578a1b9b6aSSam Leffler #define	IEEE80211_NODE_STAT(ni,stat)	(ni->ni_stats.ns_##stat++)
2588a1b9b6aSSam Leffler #define	IEEE80211_NODE_STAT_ADD(ni,stat,v)	(ni->ni_stats.ns_##stat += v)
2598a1b9b6aSSam Leffler #define	IEEE80211_NODE_STAT_SET(ni,stat,v)	(ni->ni_stats.ns_##stat = v)
2601a1e1d21SSam Leffler 
261b032f27cSSam Leffler /*
262b032f27cSSam Leffler  * Filtered rssi calculation support.  The receive rssi is maintained
263b032f27cSSam Leffler  * as an average over the last 10 frames received using a low pass filter
264b032f27cSSam Leffler  * (all frames for now, possibly need to be more selective).  Calculations
265b032f27cSSam Leffler  * are designed such that a good compiler can optimize them.  The avg
266b032f27cSSam Leffler  * rssi state should be initialized to IEEE80211_RSSI_DUMMY_MARKER and
267b032f27cSSam Leffler  * each sample incorporated with IEEE80211_RSSI_LPF.  Use IEEE80211_RSSI_GET
268b032f27cSSam Leffler  * to extract the current value.
269b032f27cSSam Leffler  *
270b032f27cSSam Leffler  * Note that we assume rssi data are in the range [-127..127] and we
271b032f27cSSam Leffler  * discard values <-20.  This is consistent with assumptions throughout
272b032f27cSSam Leffler  * net80211 that signal strength data are in .5 dBm units relative to
273b032f27cSSam Leffler  * the current noise floor (linear, not log).
274b032f27cSSam Leffler  */
275b032f27cSSam Leffler #define IEEE80211_RSSI_LPF_LEN		10
276b032f27cSSam Leffler #define	IEEE80211_RSSI_DUMMY_MARKER	127
277b032f27cSSam Leffler /* NB: pow2 to optimize out * and / */
278b032f27cSSam Leffler #define	IEEE80211_RSSI_EP_MULTIPLIER	(1<<7)
279b032f27cSSam Leffler #define IEEE80211_RSSI_IN(x)		((x) * IEEE80211_RSSI_EP_MULTIPLIER)
280b032f27cSSam Leffler #define _IEEE80211_RSSI_LPF(x, y, len) \
281b032f27cSSam Leffler     (((x) != IEEE80211_RSSI_DUMMY_MARKER) ? (((x) * ((len) - 1) + (y)) / (len)) : (y))
282b032f27cSSam Leffler #define IEEE80211_RSSI_LPF(x, y) do {					\
283b032f27cSSam Leffler     if ((y) >= -20) {							\
284b032f27cSSam Leffler     	x = _IEEE80211_RSSI_LPF((x), IEEE80211_RSSI_IN((y)), 		\
285b032f27cSSam Leffler 		IEEE80211_RSSI_LPF_LEN);				\
286b032f27cSSam Leffler     }									\
287b032f27cSSam Leffler } while (0)
288b032f27cSSam Leffler #define	IEEE80211_RSSI_EP_RND(x, mul) \
289b032f27cSSam Leffler 	((((x) % (mul)) >= ((mul)/2)) ? ((x) + ((mul) - 1)) / (mul) : (x)/(mul))
290b032f27cSSam Leffler #define	IEEE80211_RSSI_GET(x) \
291b032f27cSSam Leffler 	IEEE80211_RSSI_EP_RND(x, IEEE80211_RSSI_EP_MULTIPLIER)
292b032f27cSSam Leffler 
2931a1e1d21SSam Leffler static __inline struct ieee80211_node *
2941a1e1d21SSam Leffler ieee80211_ref_node(struct ieee80211_node *ni)
2951a1e1d21SSam Leffler {
2968a1b9b6aSSam Leffler 	ieee80211_node_incref(ni);
2971a1e1d21SSam Leffler 	return ni;
2981a1e1d21SSam Leffler }
2991a1e1d21SSam Leffler 
3001a1e1d21SSam Leffler static __inline void
3011a1e1d21SSam Leffler ieee80211_unref_node(struct ieee80211_node **ni)
3021a1e1d21SSam Leffler {
3038a1b9b6aSSam Leffler 	ieee80211_node_decref(*ni);
3041a1e1d21SSam Leffler 	*ni = NULL;			/* guard against use */
3051a1e1d21SSam Leffler }
3061a1e1d21SSam Leffler 
3070942c81cSSam Leffler void	ieee80211_node_attach(struct ieee80211com *);
3080942c81cSSam Leffler void	ieee80211_node_lateattach(struct ieee80211com *);
3090942c81cSSam Leffler void	ieee80211_node_detach(struct ieee80211com *);
310b032f27cSSam Leffler void	ieee80211_node_vattach(struct ieee80211vap *);
311b032f27cSSam Leffler void	ieee80211_node_latevattach(struct ieee80211vap *);
312b032f27cSSam Leffler void	ieee80211_node_vdetach(struct ieee80211vap *);
313566a6538SSam Leffler 
3148a1b9b6aSSam Leffler static __inline int
3158a1b9b6aSSam Leffler ieee80211_node_is_authorized(const struct ieee80211_node *ni)
3168a1b9b6aSSam Leffler {
3178a1b9b6aSSam Leffler 	return (ni->ni_flags & IEEE80211_NODE_AUTH);
3188a1b9b6aSSam Leffler }
3191a1e1d21SSam Leffler 
320e4918ecdSSam Leffler void	ieee80211_node_authorize(struct ieee80211_node *);
321e4918ecdSSam Leffler void	ieee80211_node_unauthorize(struct ieee80211_node *);
3221a1e1d21SSam Leffler 
323d77148fbSSam Leffler void	ieee80211_node_setuptxparms(struct ieee80211_node *);
324b032f27cSSam Leffler void	ieee80211_node_set_chan(struct ieee80211_node *,
325b032f27cSSam Leffler 		struct ieee80211_channel *);
326b032f27cSSam Leffler void	ieee80211_create_ibss(struct ieee80211vap*, struct ieee80211_channel *);
327b032f27cSSam Leffler void	ieee80211_reset_bss(struct ieee80211vap *);
328b032f27cSSam Leffler void	ieee80211_sync_curchan(struct ieee80211com *);
3295efea30fSAndrew Thompson void	ieee80211_setupcurchan(struct ieee80211com *,
3305efea30fSAndrew Thompson 	    struct ieee80211_channel *);
331b032f27cSSam Leffler void	ieee80211_setcurchan(struct ieee80211com *, struct ieee80211_channel *);
332b94299c4SAdrian Chadd void	ieee80211_update_chw(struct ieee80211com *);
333641b4d0bSSam Leffler int	ieee80211_ibss_merge(struct ieee80211_node *);
33468e8e04eSSam Leffler struct ieee80211_scan_entry;
33510959256SSam Leffler int	ieee80211_sta_join(struct ieee80211vap *, struct ieee80211_channel *,
33668e8e04eSSam Leffler 		const struct ieee80211_scan_entry *);
337b032f27cSSam Leffler void	ieee80211_sta_leave(struct ieee80211_node *);
338b032f27cSSam Leffler void	ieee80211_node_deauth(struct ieee80211_node *, int);
339b032f27cSSam Leffler 
340b032f27cSSam Leffler int	ieee80211_ies_init(struct ieee80211_ies *, const uint8_t *, int);
341b032f27cSSam Leffler void	ieee80211_ies_cleanup(struct ieee80211_ies *);
342b032f27cSSam Leffler void	ieee80211_ies_expand(struct ieee80211_ies *);
343b032f27cSSam Leffler #define	ieee80211_ies_setie(_ies, _ie, _off) do {		\
344b032f27cSSam Leffler 	(_ies)._ie = (_ies).data + (_off);			\
345b032f27cSSam Leffler } while (0)
3468a1b9b6aSSam Leffler 
3478a1b9b6aSSam Leffler /*
3488a1b9b6aSSam Leffler  * Table of ieee80211_node instances.  Each ieee80211com
349b032f27cSSam Leffler  * has one that holds association stations (when operating
350b032f27cSSam Leffler  * as an ap) or neighbors (in ibss mode).
351b032f27cSSam Leffler  *
352b032f27cSSam Leffler  * XXX embed this in ieee80211com instead of indirect?
3538a1b9b6aSSam Leffler  */
3548a1b9b6aSSam Leffler struct ieee80211_node_table {
3558a1b9b6aSSam Leffler 	struct ieee80211com	*nt_ic;		/* back reference */
3568a1b9b6aSSam Leffler 	ieee80211_node_lock_t	nt_nodelock;	/* on node table */
3578a1b9b6aSSam Leffler 	TAILQ_HEAD(, ieee80211_node) nt_node;	/* information of all nodes */
3588a1b9b6aSSam Leffler 	LIST_HEAD(, ieee80211_node) nt_hash[IEEE80211_NODE_HASHSIZE];
35968e8e04eSSam Leffler 	struct ieee80211_node	**nt_keyixmap;	/* key ix -> node map */
36068e8e04eSSam Leffler 	int			nt_keyixmax;	/* keyixmap size */
361b032f27cSSam Leffler 	const char		*nt_name;	/* table name for debug msgs */
3628a1b9b6aSSam Leffler 	ieee80211_scan_lock_t	nt_scanlock;	/* on nt_scangen */
363b032f27cSSam Leffler 	u_int			nt_scangen;	/* gen# for iterators */
3648a1b9b6aSSam Leffler 	int			nt_inact_init;	/* initial node inact setting */
3658a1b9b6aSSam Leffler };
3668a1b9b6aSSam Leffler 
367b032f27cSSam Leffler struct ieee80211_node *ieee80211_alloc_node(struct ieee80211_node_table *,
368b032f27cSSam Leffler 		struct ieee80211vap *,
369b032f27cSSam Leffler 		const uint8_t macaddr[IEEE80211_ADDR_LEN]);
370b032f27cSSam Leffler struct ieee80211_node *ieee80211_tmp_node(struct ieee80211vap *,
371b032f27cSSam Leffler 		const uint8_t macaddr[IEEE80211_ADDR_LEN]);
372b032f27cSSam Leffler struct ieee80211_node *ieee80211_dup_bss(struct ieee80211vap *,
373b032f27cSSam Leffler 		const uint8_t macaddr[IEEE80211_ADDR_LEN]);
374b032f27cSSam Leffler struct ieee80211_node *ieee80211_node_create_wds(struct ieee80211vap *,
375b032f27cSSam Leffler 		const uint8_t bssid[IEEE80211_ADDR_LEN],
376b032f27cSSam Leffler 		struct ieee80211_channel *);
3778a1b9b6aSSam Leffler #ifdef IEEE80211_DEBUG_REFCNT
3780942c81cSSam Leffler void	ieee80211_free_node_debug(struct ieee80211_node *,
3798a1b9b6aSSam Leffler 		const char *func, int line);
380b032f27cSSam Leffler struct ieee80211_node *ieee80211_find_node_locked_debug(
381b032f27cSSam Leffler 		struct ieee80211_node_table *,
382b032f27cSSam Leffler 		const uint8_t macaddr[IEEE80211_ADDR_LEN],
383b032f27cSSam Leffler 		const char *func, int line);
38468e8e04eSSam Leffler struct ieee80211_node *ieee80211_find_node_debug(struct ieee80211_node_table *,
385b032f27cSSam Leffler 		const uint8_t macaddr[IEEE80211_ADDR_LEN],
386b032f27cSSam Leffler 		const char *func, int line);
387b032f27cSSam Leffler struct ieee80211_node *ieee80211_find_vap_node_locked_debug(
388b032f27cSSam Leffler 		struct ieee80211_node_table *,
389b032f27cSSam Leffler 		const struct ieee80211vap *vap,
390b032f27cSSam Leffler 		const uint8_t macaddr[IEEE80211_ADDR_LEN],
391b032f27cSSam Leffler 		const char *func, int line);
392b032f27cSSam Leffler struct ieee80211_node *ieee80211_find_vap_node_debug(
393b032f27cSSam Leffler 		struct ieee80211_node_table *,
394b032f27cSSam Leffler 		const struct ieee80211vap *vap,
395b032f27cSSam Leffler 		const uint8_t macaddr[IEEE80211_ADDR_LEN],
3968a1b9b6aSSam Leffler 		const char *func, int line);
39768e8e04eSSam Leffler struct ieee80211_node * ieee80211_find_rxnode_debug(struct ieee80211com *,
39868e8e04eSSam Leffler 		const struct ieee80211_frame_min *,
3998a1b9b6aSSam Leffler 		const char *func, int line);
400c1225b52SSam Leffler struct ieee80211_node * ieee80211_find_rxnode_withkey_debug(
401c1225b52SSam Leffler 		struct ieee80211com *,
40268e8e04eSSam Leffler 		const struct ieee80211_frame_min *, uint16_t keyix,
403c1225b52SSam Leffler 		const char *func, int line);
404b032f27cSSam Leffler struct ieee80211_node *ieee80211_find_txnode_debug(struct ieee80211vap *,
40568e8e04eSSam Leffler 		const uint8_t *,
40668e8e04eSSam Leffler 		const char *func, int line);
4078a1b9b6aSSam Leffler #define	ieee80211_free_node(ni) \
4088a1b9b6aSSam Leffler 	ieee80211_free_node_debug(ni, __func__, __LINE__)
409b032f27cSSam Leffler #define	ieee80211_find_node_locked(nt, mac) \
410b032f27cSSam Leffler 	ieee80211_find_node_locked_debug(nt, mac, __func__, __LINE__)
4118a1b9b6aSSam Leffler #define	ieee80211_find_node(nt, mac) \
4128a1b9b6aSSam Leffler 	ieee80211_find_node_debug(nt, mac, __func__, __LINE__)
413b032f27cSSam Leffler #define	ieee80211_find_vap_node_locked(nt, vap, mac) \
414b032f27cSSam Leffler 	ieee80211_find_vap_node_locked_debug(nt, vap, mac, __func__, __LINE__)
415b032f27cSSam Leffler #define	ieee80211_find_vap_node(nt, vap, mac) \
416b032f27cSSam Leffler 	ieee80211_find_vap_node_debug(nt, vap, mac, __func__, __LINE__)
417b032f27cSSam Leffler #define	ieee80211_find_rxnode(ic, wh) \
418b032f27cSSam Leffler 	ieee80211_find_rxnode_debug(ic, wh, __func__, __LINE__)
419b032f27cSSam Leffler #define	ieee80211_find_rxnode_withkey(ic, wh, keyix) \
420b032f27cSSam Leffler 	ieee80211_find_rxnode_withkey_debug(ic, wh, keyix, __func__, __LINE__)
421b032f27cSSam Leffler #define	ieee80211_find_txnode(vap, mac) \
422b032f27cSSam Leffler 	ieee80211_find_txnode_debug(vap, mac, __func__, __LINE__)
4238a1b9b6aSSam Leffler #else
4240942c81cSSam Leffler void	ieee80211_free_node(struct ieee80211_node *);
425b032f27cSSam Leffler struct ieee80211_node *ieee80211_find_node_locked(struct ieee80211_node_table *,
426b032f27cSSam Leffler 		const uint8_t macaddr[IEEE80211_ADDR_LEN]);
42768e8e04eSSam Leffler struct ieee80211_node *ieee80211_find_node(struct ieee80211_node_table *,
428b032f27cSSam Leffler 		const uint8_t macaddr[IEEE80211_ADDR_LEN]);
429b032f27cSSam Leffler struct ieee80211_node *ieee80211_find_vap_node_locked(
430b032f27cSSam Leffler 		struct ieee80211_node_table *, const struct ieee80211vap *,
431b032f27cSSam Leffler 		const uint8_t macaddr[IEEE80211_ADDR_LEN]);
432b032f27cSSam Leffler struct ieee80211_node *ieee80211_find_vap_node(
433b032f27cSSam Leffler 		struct ieee80211_node_table *, const struct ieee80211vap *,
434b032f27cSSam Leffler 		const uint8_t macaddr[IEEE80211_ADDR_LEN]);
43568e8e04eSSam Leffler struct ieee80211_node * ieee80211_find_rxnode(struct ieee80211com *,
43668e8e04eSSam Leffler 		const struct ieee80211_frame_min *);
437c1225b52SSam Leffler struct ieee80211_node * ieee80211_find_rxnode_withkey(struct ieee80211com *,
43868e8e04eSSam Leffler 		const struct ieee80211_frame_min *, uint16_t keyix);
439b032f27cSSam Leffler struct ieee80211_node *ieee80211_find_txnode(struct ieee80211vap *,
440b032f27cSSam Leffler 		const uint8_t macaddr[IEEE80211_ADDR_LEN]);
4418a1b9b6aSSam Leffler #endif
442c1225b52SSam Leffler int	ieee80211_node_delucastkey(struct ieee80211_node *);
44368e8e04eSSam Leffler void	ieee80211_node_timeout(void *arg);
4448a1b9b6aSSam Leffler 
4458a1b9b6aSSam Leffler typedef void ieee80211_iter_func(void *, struct ieee80211_node *);
4467d684b4bSAdrian Chadd int	ieee80211_iterate_nt(struct ieee80211_node_table *,
4477d684b4bSAdrian Chadd 		struct ieee80211_node **, uint16_t);
4480942c81cSSam Leffler void	ieee80211_iterate_nodes(struct ieee80211_node_table *,
4498a1b9b6aSSam Leffler 		ieee80211_iter_func *, void *);
4508a1b9b6aSSam Leffler 
451b032f27cSSam Leffler void	ieee80211_notify_erp(struct ieee80211com *);
4520942c81cSSam Leffler void	ieee80211_dump_node(struct ieee80211_node_table *,
4538a1b9b6aSSam Leffler 		struct ieee80211_node *);
4540942c81cSSam Leffler void	ieee80211_dump_nodes(struct ieee80211_node_table *);
4558a1b9b6aSSam Leffler 
456b032f27cSSam Leffler struct ieee80211_node *ieee80211_fakeup_adhoc_node(struct ieee80211vap *,
457b032f27cSSam Leffler 		const uint8_t macaddr[IEEE80211_ADDR_LEN]);
45868e8e04eSSam Leffler struct ieee80211_scanparams;
459be425a0fSSam Leffler void	ieee80211_init_neighbor(struct ieee80211_node *,
460be425a0fSSam Leffler 		const struct ieee80211_frame *,
461be425a0fSSam Leffler 		const struct ieee80211_scanparams *);
462b032f27cSSam Leffler struct ieee80211_node *ieee80211_add_neighbor(struct ieee80211vap *,
463b5c99415SSam Leffler 		const struct ieee80211_frame *,
464b5c99415SSam Leffler 		const struct ieee80211_scanparams *);
465b032f27cSSam Leffler void	ieee80211_node_join(struct ieee80211_node *,int);
466b032f27cSSam Leffler void	ieee80211_node_leave(struct ieee80211_node *);
467b032f27cSSam Leffler int8_t	ieee80211_getrssi(struct ieee80211vap *);
468b032f27cSSam Leffler void	ieee80211_getsignal(struct ieee80211vap *, int8_t *, int8_t *);
4691a1e1d21SSam Leffler #endif /* _NET80211_IEEE80211_NODE_H_ */
470