1116742Ssam/*-
2116904Ssam * Copyright (c) 2001 Atsushi Onoe
3186904Ssam * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
4116742Ssam * All rights reserved.
5116742Ssam *
6116742Ssam * Redistribution and use in source and binary forms, with or without
7116742Ssam * modification, are permitted provided that the following conditions
8116742Ssam * are met:
9116742Ssam * 1. Redistributions of source code must retain the above copyright
10116742Ssam *    notice, this list of conditions and the following disclaimer.
11116742Ssam * 2. Redistributions in binary form must reproduce the above copyright
12116742Ssam *    notice, this list of conditions and the following disclaimer in the
13116742Ssam *    documentation and/or other materials provided with the distribution.
14116742Ssam *
15116904Ssam * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16116904Ssam * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17116904Ssam * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18116904Ssam * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19116904Ssam * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20116904Ssam * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21116904Ssam * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22116904Ssam * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23116904Ssam * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24116904Ssam * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25116904Ssam *
26116742Ssam * $FreeBSD: stable/11/sys/net80211/ieee80211_node.h 330458 2018-03-05 08:18:13Z eadler $
27116742Ssam */
28116742Ssam#ifndef _NET80211_IEEE80211_NODE_H_
29116742Ssam#define _NET80211_IEEE80211_NODE_H_
30116742Ssam
31138568Ssam#include <net80211/ieee80211_ioctl.h>		/* for ieee80211_nodestats */
32170530Ssam#include <net80211/ieee80211_ht.h>		/* for aggregation state */
33116742Ssam
34138568Ssam/*
35178354Ssam * Each ieee80211com instance has a single timer that fires every
36178354Ssam * IEEE80211_INACT_WAIT seconds to handle "inactivity processing".
37178354Ssam * This is used to do node inactivity processing when operating
38195618Srpaulo * as an AP, adhoc or mesh mode.  For inactivity processing each node
39178354Ssam * has a timeout set in it's ni_inact field that is decremented
40178354Ssam * on each timeout and the node is reclaimed when the counter goes
41178354Ssam * to zero.  We use different inactivity timeout values depending
42178354Ssam * on whether the node is associated and authorized (either by
43178354Ssam * 802.1x or open/shared key authentication) or associated but yet
44178354Ssam * to be authorized.  The latter timeout is shorter to more aggressively
45138568Ssam * reclaim nodes that leave part way through the 802.1x exchange.
46138568Ssam */
47138568Ssam#define	IEEE80211_INACT_WAIT	15		/* inactivity interval (secs) */
48138568Ssam#define	IEEE80211_INACT_INIT	(30/IEEE80211_INACT_WAIT)	/* initial */
49138568Ssam#define	IEEE80211_INACT_AUTH	(180/IEEE80211_INACT_WAIT)	/* associated but not authorized */
50138568Ssam#define	IEEE80211_INACT_RUN	(300/IEEE80211_INACT_WAIT)	/* authorized */
51138568Ssam#define	IEEE80211_INACT_PROBE	(30/IEEE80211_INACT_WAIT)	/* probe */
52138568Ssam#define	IEEE80211_INACT_SCAN	(300/IEEE80211_INACT_WAIT)	/* scanned */
53138568Ssam
54170530Ssam#define	IEEE80211_TRANS_WAIT 	2		/* mgt frame tx timer (secs) */
55138568Ssam
56172211Ssam/* threshold for aging overlapping non-ERP bss */
57172211Ssam#define	IEEE80211_NONERP_PRESENT_AGE	msecs_to_ticks(60*1000)
58172211Ssam
59195618Srpaulo#define	IEEE80211_NODE_HASHSIZE	32		/* NB: hash size must be pow2 */
60116742Ssam/* simple hash is enough for variation of macaddr */
61195618Srpaulo#define	IEEE80211_NODE_HASH(ic, addr)	\
62170530Ssam	(((const uint8_t *)(addr))[IEEE80211_ADDR_LEN - 1] % \
63138568Ssam		IEEE80211_NODE_HASHSIZE)
64116742Ssam
65138568Ssamstruct ieee80211_node_table;
66138568Ssamstruct ieee80211com;
67178354Ssamstruct ieee80211vap;
68330458Seadlerstruct ieee80211_scanparams;
69138568Ssam
70116742Ssam/*
71178354Ssam * Information element ``blob''.  We use this structure
72178354Ssam * to capture management frame payloads that need to be
73190093Srpaulo * retained.  Information elements within the payload that
74178354Ssam * we need to consult have references recorded.
75178354Ssam */
76178354Ssamstruct ieee80211_ies {
77178354Ssam	/* the following are either NULL or point within data */
78178354Ssam	uint8_t	*wpa_ie;	/* captured WPA ie */
79178354Ssam	uint8_t	*rsn_ie;	/* captured RSN ie */
80178354Ssam	uint8_t	*wme_ie;	/* captured WME ie */
81178354Ssam	uint8_t	*ath_ie;	/* captured Atheros ie */
82178354Ssam	uint8_t	*htcap_ie;	/* captured HTCAP ie */
83178354Ssam	uint8_t	*htinfo_ie;	/* captured HTINFO ie */
84186904Ssam	uint8_t	*tdma_ie;	/* captured TDMA ie */
85195618Srpaulo	uint8_t *meshid_ie;	/* captured MESH ID ie */
86193239Ssam	uint8_t	*spare[4];
87178354Ssam	/* NB: these must be the last members of this structure */
88178354Ssam	uint8_t	*data;		/* frame data > 802.11 header */
89178354Ssam	int	len;		/* data size in bytes */
90178354Ssam};
91178354Ssam
92178354Ssam/*
93195618Srpaulo * 802.11s (Mesh) Peer Link FSM state.
94195618Srpaulo */
95195618Srpauloenum ieee80211_mesh_mlstate {
96195618Srpaulo	IEEE80211_NODE_MESH_IDLE	= 0,
97195618Srpaulo	IEEE80211_NODE_MESH_OPENSNT	= 1,	/* open frame sent */
98195618Srpaulo	IEEE80211_NODE_MESH_OPENRCV	= 2,	/* open frame received */
99195618Srpaulo	IEEE80211_NODE_MESH_CONFIRMRCV	= 3,	/* confirm frame received */
100195618Srpaulo	IEEE80211_NODE_MESH_ESTABLISHED	= 4,	/* link established */
101195618Srpaulo	IEEE80211_NODE_MESH_HOLDING	= 5,	/* link closing */
102195618Srpaulo};
103195618Srpaulo#define	IEEE80211_MESH_MLSTATE_BITS \
104195618Srpaulo	"\20\1IDLE\2OPENSNT\2OPENRCV\3CONFIRMRCV\4ESTABLISHED\5HOLDING"
105195618Srpaulo
106195618Srpaulo/*
107116742Ssam * Node specific information.  Note that drivers are expected
108116742Ssam * to derive from this structure to add device-specific per-node
109116742Ssam * state.  This is done by overriding the ic_node_* methods in
110116742Ssam * the ieee80211com structure.
111116742Ssam */
112116742Ssamstruct ieee80211_node {
113178354Ssam	struct ieee80211vap	*ni_vap;	/* associated vap */
114178354Ssam	struct ieee80211com	*ni_ic;		/* copy from vap to save deref*/
115178354Ssam	struct ieee80211_node_table *ni_table;	/* NB: may be NULL */
116178354Ssam	TAILQ_ENTRY(ieee80211_node) ni_list;	/* list of all nodes */
117178354Ssam	LIST_ENTRY(ieee80211_node) ni_hash;	/* hash collision list */
118178354Ssam	u_int			ni_refcnt;	/* count of held references */
119183252Ssam	u_int			ni_flags;
120183252Ssam#define	IEEE80211_NODE_AUTH	0x000001	/* authorized for data */
121183252Ssam#define	IEEE80211_NODE_QOS	0x000002	/* QoS enabled */
122183252Ssam#define	IEEE80211_NODE_ERP	0x000004	/* ERP enabled */
123183252Ssam/* NB: this must have the same value as IEEE80211_FC1_PWR_MGT */
124183252Ssam#define	IEEE80211_NODE_PWR_MGT	0x000010	/* power save mode enabled */
125183252Ssam#define	IEEE80211_NODE_AREF	0x000020	/* authentication ref held */
126183252Ssam#define	IEEE80211_NODE_HT	0x000040	/* HT enabled */
127183252Ssam#define	IEEE80211_NODE_HTCOMPAT	0x000080	/* HT setup w/ vendor OUI's */
128183252Ssam#define	IEEE80211_NODE_WPS	0x000100	/* WPS association */
129183252Ssam#define	IEEE80211_NODE_TSN	0x000200	/* TSN association */
130183252Ssam#define	IEEE80211_NODE_AMPDU_RX	0x000400	/* AMPDU rx enabled */
131183252Ssam#define	IEEE80211_NODE_AMPDU_TX	0x000800	/* AMPDU tx enabled */
132183255Ssam#define	IEEE80211_NODE_MIMO_PS	0x001000	/* MIMO power save enabled */
133183255Ssam#define	IEEE80211_NODE_MIMO_RTS	0x002000	/* send RTS in MIMO PS */
134183256Ssam#define	IEEE80211_NODE_RIFS	0x004000	/* RIFS enabled */
135183257Ssam#define	IEEE80211_NODE_SGI20	0x008000	/* Short GI in HT20 enabled */
136183257Ssam#define	IEEE80211_NODE_SGI40	0x010000	/* Short GI in HT40 enabled */
137186099Ssam#define	IEEE80211_NODE_ASSOCID	0x020000	/* xmit requires associd */
138193549Ssam#define	IEEE80211_NODE_AMSDU_RX	0x040000	/* AMSDU rx enabled */
139193549Ssam#define	IEEE80211_NODE_AMSDU_TX	0x080000	/* AMSDU tx enabled */
140183252Ssam	uint16_t		ni_associd;	/* association ID */
141183252Ssam	uint16_t		ni_vlan;	/* vlan tag */
142183252Ssam	uint16_t		ni_txpower;	/* current transmit power */
143170530Ssam	uint8_t			ni_authmode;	/* authentication algorithm */
144170530Ssam	uint8_t			ni_ath_flags;	/* Atheros feature flags */
145170530Ssam	/* NB: These must have the same values as IEEE80211_ATHC_* */
146170530Ssam#define IEEE80211_NODE_TURBOP	0x0001		/* Turbo prime enable */
147170530Ssam#define IEEE80211_NODE_COMP	0x0002		/* Compresssion enable */
148170530Ssam#define IEEE80211_NODE_FF	0x0004          /* Fast Frame capable */
149170530Ssam#define IEEE80211_NODE_XR	0x0008		/* Atheros WME enable */
150170530Ssam#define IEEE80211_NODE_AR	0x0010		/* AR capable */
151183252Ssam#define IEEE80211_NODE_BOOST	0x0080		/* Dynamic Turbo boosted */
152170530Ssam	uint16_t		ni_ath_defkeyix;/* Atheros def key index */
153183251Ssam	const struct ieee80211_txparam *ni_txparms;
154173273Ssam	uint32_t		ni_jointime;	/* time of join (secs) */
155170530Ssam	uint32_t		*ni_challenge;	/* shared-key challenge */
156178354Ssam	struct ieee80211_ies	ni_ies;		/* captured ie's */
157172225Ssam						/* tx seq per-tid */
158191756Ssam	ieee80211_seq		ni_txseqs[IEEE80211_TID_SIZE];
159172225Ssam						/* rx seq previous per-tid*/
160191756Ssam	ieee80211_seq		ni_rxseqs[IEEE80211_TID_SIZE];
161170530Ssam	uint32_t		ni_rxfragstamp;	/* time stamp of last rx frag */
162138568Ssam	struct mbuf		*ni_rxfrag[3];	/* rx frag reassembly */
163138568Ssam	struct ieee80211_key	ni_ucastkey;	/* unicast key */
164116742Ssam
165116742Ssam	/* hardware */
166178354Ssam	uint32_t		ni_avgrssi;	/* recv ssi state */
167170530Ssam	int8_t			ni_noise;	/* noise floor */
168116742Ssam
169220445Sadrian	/* mimo statistics */
170220445Sadrian	uint32_t		ni_mimo_rssi_ctl[IEEE80211_MAX_CHAINS];
171220445Sadrian	uint32_t		ni_mimo_rssi_ext[IEEE80211_MAX_CHAINS];
172220445Sadrian	uint8_t			ni_mimo_noise_ctl[IEEE80211_MAX_CHAINS];
173220445Sadrian	uint8_t			ni_mimo_noise_ext[IEEE80211_MAX_CHAINS];
174220445Sadrian	uint8_t			ni_mimo_chains;
175220445Sadrian
176116742Ssam	/* header */
177170530Ssam	uint8_t			ni_macaddr[IEEE80211_ADDR_LEN];
178170530Ssam	uint8_t			ni_bssid[IEEE80211_ADDR_LEN];
179116742Ssam
180116742Ssam	/* beacon, probe response */
181138568Ssam	union {
182170530Ssam		uint8_t		data[8];
183178354Ssam		u_int64_t	tsf;
184138568Ssam	} ni_tstamp;				/* from last rcv'd beacon */
185170530Ssam	uint16_t		ni_intval;	/* beacon interval */
186170530Ssam	uint16_t		ni_capinfo;	/* capabilities */
187170530Ssam	uint8_t			ni_esslen;
188170530Ssam	uint8_t			ni_essid[IEEE80211_NWID_LEN];
189116742Ssam	struct ieee80211_rateset ni_rates;	/* negotiated rate set */
190170530Ssam	struct ieee80211_channel *ni_chan;
191170530Ssam	uint16_t		ni_fhdwell;	/* FH only */
192170530Ssam	uint8_t			ni_fhindex;	/* FH only */
193178354Ssam	uint16_t		ni_erp;		/* ERP from beacon/probe resp */
194170530Ssam	uint16_t		ni_timoff;	/* byte offset to TIM ie */
195170530Ssam	uint8_t			ni_dtim_period;	/* DTIM period */
196170530Ssam	uint8_t			ni_dtim_count;	/* DTIM count for last bcn */
197116742Ssam
198195618Srpaulo	/* 11s state */
199195618Srpaulo	uint8_t			ni_meshidlen;
200195618Srpaulo	uint8_t			ni_meshid[IEEE80211_MESHID_LEN];
201195618Srpaulo	enum ieee80211_mesh_mlstate ni_mlstate;	/* peering management state */
202195618Srpaulo	uint16_t		ni_mllid;	/* link local ID */
203195618Srpaulo	uint16_t		ni_mlpid;	/* link peer ID */
204195618Srpaulo	struct callout		ni_mltimer;	/* link mesh timer */
205195618Srpaulo	uint8_t			ni_mlrcnt;	/* link mesh retry counter */
206195618Srpaulo	uint8_t			ni_mltval;	/* link mesh timer value */
207246497Smonthadar	struct callout		ni_mlhtimer;	/* link mesh backoff timer */
208246497Smonthadar	uint8_t			ni_mlhcnt;	/* link mesh holding counter */
209195618Srpaulo
210170530Ssam	/* 11n state */
211170530Ssam	uint16_t		ni_htcap;	/* HT capabilities */
212170530Ssam	uint8_t			ni_htparam;	/* HT params */
213170530Ssam	uint8_t			ni_htctlchan;	/* HT control channel */
214170530Ssam	uint8_t			ni_ht2ndchan;	/* HT 2nd channel */
215170530Ssam	uint8_t			ni_htopmode;	/* HT operating mode */
216170530Ssam	uint8_t			ni_htstbc;	/* HT */
217170530Ssam	uint8_t			ni_chw;		/* negotiated channel width */
218170530Ssam	struct ieee80211_htrateset ni_htrates;	/* negotiated ht rate set */
219234324Sadrian	struct ieee80211_tx_ampdu ni_tx_ampdu[WME_NUM_TID];
220170530Ssam	struct ieee80211_rx_ampdu ni_rx_ampdu[WME_NUM_TID];
221170530Ssam
222288318Sadrian	/* fast-frames state */
223288318Sadrian	struct mbuf *		ni_tx_superg[WME_NUM_TID];
224288318Sadrian
225116742Ssam	/* others */
226138568Ssam	short			ni_inact;	/* inactivity mark count */
227138568Ssam	short			ni_inact_reload;/* inactivity reload value */
228178354Ssam	int			ni_txrate;	/* legacy rate/MCS */
229184288Ssam	struct ieee80211_psq	ni_psq;		/* power save queue */
230138568Ssam	struct ieee80211_nodestats ni_stats;	/* per-node statistics */
231178354Ssam
232178354Ssam	struct ieee80211vap	*ni_wdsvap;	/* associated WDS vap */
233206358Srpaulo	void			*ni_rctls;	/* private ratectl state */
234206358Srpaulo	uint64_t		ni_spare[3];
235116742Ssam};
236138568SsamMALLOC_DECLARE(M_80211_NODE);
237178354SsamMALLOC_DECLARE(M_80211_NODE_IE);
238116742Ssam
239170530Ssam#define	IEEE80211_NODE_ATH	(IEEE80211_NODE_FF | IEEE80211_NODE_TURBOP)
240173273Ssam#define	IEEE80211_NODE_AMPDU \
241173273Ssam	(IEEE80211_NODE_AMPDU_RX | IEEE80211_NODE_AMPDU_TX)
242193549Ssam#define	IEEE80211_NODE_AMSDU \
243193549Ssam	(IEEE80211_NODE_AMSDU_RX | IEEE80211_NODE_AMSDU_TX)
244182828Ssam#define	IEEE80211_NODE_HT_ALL \
245182828Ssam	(IEEE80211_NODE_HT | IEEE80211_NODE_HTCOMPAT | \
246193549Ssam	 IEEE80211_NODE_AMPDU | IEEE80211_NODE_AMSDU | \
247193549Ssam	 IEEE80211_NODE_MIMO_PS | IEEE80211_NODE_MIMO_RTS | \
248193549Ssam	 IEEE80211_NODE_RIFS | IEEE80211_NODE_SGI20 | IEEE80211_NODE_SGI40)
249170530Ssam
250187797Ssam#define	IEEE80211_NODE_BITS \
251187797Ssam	"\20\1AUTH\2QOS\3ERP\5PWR_MGT\6AREF\7HT\10HTCOMPAT\11WPS\12TSN" \
252187797Ssam	"\13AMPDU_RX\14AMPDU_TX\15MIMO_PS\16MIMO_RTS\17RIFS\20SGI20\21SGI40" \
253187797Ssam	"\22ASSOCID"
254187797Ssam
255138568Ssam#define	IEEE80211_NODE_AID(ni)	IEEE80211_AID(ni->ni_associd)
256138568Ssam
257138568Ssam#define	IEEE80211_NODE_STAT(ni,stat)	(ni->ni_stats.ns_##stat++)
258138568Ssam#define	IEEE80211_NODE_STAT_ADD(ni,stat,v)	(ni->ni_stats.ns_##stat += v)
259138568Ssam#define	IEEE80211_NODE_STAT_SET(ni,stat,v)	(ni->ni_stats.ns_##stat = v)
260138568Ssam
261178354Ssam/*
262178354Ssam * Filtered rssi calculation support.  The receive rssi is maintained
263178354Ssam * as an average over the last 10 frames received using a low pass filter
264178354Ssam * (all frames for now, possibly need to be more selective).  Calculations
265178354Ssam * are designed such that a good compiler can optimize them.  The avg
266178354Ssam * rssi state should be initialized to IEEE80211_RSSI_DUMMY_MARKER and
267178354Ssam * each sample incorporated with IEEE80211_RSSI_LPF.  Use IEEE80211_RSSI_GET
268178354Ssam * to extract the current value.
269178354Ssam *
270178354Ssam * Note that we assume rssi data are in the range [-127..127] and we
271178354Ssam * discard values <-20.  This is consistent with assumptions throughout
272178354Ssam * net80211 that signal strength data are in .5 dBm units relative to
273178354Ssam * the current noise floor (linear, not log).
274178354Ssam */
275178354Ssam#define IEEE80211_RSSI_LPF_LEN		10
276178354Ssam#define	IEEE80211_RSSI_DUMMY_MARKER	127
277178354Ssam/* NB: pow2 to optimize out * and / */
278178354Ssam#define	IEEE80211_RSSI_EP_MULTIPLIER	(1<<7)
279178354Ssam#define IEEE80211_RSSI_IN(x)		((x) * IEEE80211_RSSI_EP_MULTIPLIER)
280178354Ssam#define _IEEE80211_RSSI_LPF(x, y, len) \
281178354Ssam    (((x) != IEEE80211_RSSI_DUMMY_MARKER) ? (((x) * ((len) - 1) + (y)) / (len)) : (y))
282178354Ssam#define IEEE80211_RSSI_LPF(x, y) do {					\
283178354Ssam    if ((y) >= -20) {							\
284178354Ssam    	x = _IEEE80211_RSSI_LPF((x), IEEE80211_RSSI_IN((y)), 		\
285178354Ssam		IEEE80211_RSSI_LPF_LEN);				\
286178354Ssam    }									\
287178354Ssam} while (0)
288178354Ssam#define	IEEE80211_RSSI_EP_RND(x, mul) \
289178354Ssam	((((x) % (mul)) >= ((mul)/2)) ? ((x) + ((mul) - 1)) / (mul) : (x)/(mul))
290178354Ssam#define	IEEE80211_RSSI_GET(x) \
291178354Ssam	IEEE80211_RSSI_EP_RND(x, IEEE80211_RSSI_EP_MULTIPLIER)
292178354Ssam
293116742Ssamstatic __inline struct ieee80211_node *
294116742Ssamieee80211_ref_node(struct ieee80211_node *ni)
295116742Ssam{
296138568Ssam	ieee80211_node_incref(ni);
297116742Ssam	return ni;
298116742Ssam}
299116742Ssam
300116742Ssamstatic __inline void
301116742Ssamieee80211_unref_node(struct ieee80211_node **ni)
302116742Ssam{
303138568Ssam	ieee80211_node_decref(*ni);
304116742Ssam	*ni = NULL;			/* guard against use */
305116742Ssam}
306116742Ssam
307144618Ssamvoid	ieee80211_node_attach(struct ieee80211com *);
308144618Ssamvoid	ieee80211_node_lateattach(struct ieee80211com *);
309144618Ssamvoid	ieee80211_node_detach(struct ieee80211com *);
310178354Ssamvoid	ieee80211_node_vattach(struct ieee80211vap *);
311178354Ssamvoid	ieee80211_node_latevattach(struct ieee80211vap *);
312178354Ssamvoid	ieee80211_node_vdetach(struct ieee80211vap *);
313127877Ssam
314138568Ssamstatic __inline int
315138568Ssamieee80211_node_is_authorized(const struct ieee80211_node *ni)
316138568Ssam{
317138568Ssam	return (ni->ni_flags & IEEE80211_NODE_AUTH);
318138568Ssam}
319116742Ssam
320148302Ssamvoid	ieee80211_node_authorize(struct ieee80211_node *);
321148302Ssamvoid	ieee80211_node_unauthorize(struct ieee80211_node *);
322138568Ssam
323193966Ssamvoid	ieee80211_node_setuptxparms(struct ieee80211_node *);
324178354Ssamvoid	ieee80211_node_set_chan(struct ieee80211_node *,
325178354Ssam		struct ieee80211_channel *);
326178354Ssamvoid	ieee80211_create_ibss(struct ieee80211vap*, struct ieee80211_channel *);
327178354Ssamvoid	ieee80211_reset_bss(struct ieee80211vap *);
328178354Ssamvoid	ieee80211_sync_curchan(struct ieee80211com *);
329191746Sthompsavoid	ieee80211_setupcurchan(struct ieee80211com *,
330191746Sthompsa	    struct ieee80211_channel *);
331178354Ssamvoid	ieee80211_setcurchan(struct ieee80211com *, struct ieee80211_channel *);
332233452Sadrianvoid	ieee80211_update_chw(struct ieee80211com *);
333297728Sadrianint	ieee80211_ibss_merge_check(struct ieee80211_node *);
334330458Seadlerint	ieee80211_ibss_node_check_new(struct ieee80211_node *ni,
335330458Seadler	    const struct ieee80211_scanparams *);
336148306Ssamint	ieee80211_ibss_merge(struct ieee80211_node *);
337170530Ssamstruct ieee80211_scan_entry;
338184274Ssamint	ieee80211_sta_join(struct ieee80211vap *, struct ieee80211_channel *,
339170530Ssam		const struct ieee80211_scan_entry *);
340178354Ssamvoid	ieee80211_sta_leave(struct ieee80211_node *);
341178354Ssamvoid	ieee80211_node_deauth(struct ieee80211_node *, int);
342138568Ssam
343178354Ssamint	ieee80211_ies_init(struct ieee80211_ies *, const uint8_t *, int);
344178354Ssamvoid	ieee80211_ies_cleanup(struct ieee80211_ies *);
345178354Ssamvoid	ieee80211_ies_expand(struct ieee80211_ies *);
346178354Ssam#define	ieee80211_ies_setie(_ies, _ie, _off) do {		\
347178354Ssam	(_ies)._ie = (_ies).data + (_off);			\
348178354Ssam} while (0)
349178354Ssam
350138568Ssam/*
351138568Ssam * Table of ieee80211_node instances.  Each ieee80211com
352178354Ssam * has one that holds association stations (when operating
353178354Ssam * as an ap) or neighbors (in ibss mode).
354178354Ssam *
355178354Ssam * XXX embed this in ieee80211com instead of indirect?
356138568Ssam */
357138568Ssamstruct ieee80211_node_table {
358138568Ssam	struct ieee80211com	*nt_ic;		/* back reference */
359138568Ssam	ieee80211_node_lock_t	nt_nodelock;	/* on node table */
360138568Ssam	TAILQ_HEAD(, ieee80211_node) nt_node;	/* information of all nodes */
361138568Ssam	LIST_HEAD(, ieee80211_node) nt_hash[IEEE80211_NODE_HASHSIZE];
362170530Ssam	struct ieee80211_node	**nt_keyixmap;	/* key ix -> node map */
363170530Ssam	int			nt_keyixmax;	/* keyixmap size */
364178354Ssam	const char		*nt_name;	/* table name for debug msgs */
365138568Ssam	int			nt_inact_init;	/* initial node inact setting */
366138568Ssam};
367138568Ssam
368178354Ssamstruct ieee80211_node *ieee80211_alloc_node(struct ieee80211_node_table *,
369178354Ssam		struct ieee80211vap *,
370178354Ssam		const uint8_t macaddr[IEEE80211_ADDR_LEN]);
371178354Ssamstruct ieee80211_node *ieee80211_tmp_node(struct ieee80211vap *,
372178354Ssam		const uint8_t macaddr[IEEE80211_ADDR_LEN]);
373178354Ssamstruct ieee80211_node *ieee80211_dup_bss(struct ieee80211vap *,
374178354Ssam		const uint8_t macaddr[IEEE80211_ADDR_LEN]);
375178354Ssamstruct ieee80211_node *ieee80211_node_create_wds(struct ieee80211vap *,
376178354Ssam		const uint8_t bssid[IEEE80211_ADDR_LEN],
377178354Ssam		struct ieee80211_channel *);
378138568Ssam#ifdef IEEE80211_DEBUG_REFCNT
379144618Ssamvoid	ieee80211_free_node_debug(struct ieee80211_node *,
380138568Ssam		const char *func, int line);
381178354Ssamstruct ieee80211_node *ieee80211_find_node_locked_debug(
382178354Ssam		struct ieee80211_node_table *,
383178354Ssam		const uint8_t macaddr[IEEE80211_ADDR_LEN],
384178354Ssam		const char *func, int line);
385170530Ssamstruct ieee80211_node *ieee80211_find_node_debug(struct ieee80211_node_table *,
386178354Ssam		const uint8_t macaddr[IEEE80211_ADDR_LEN],
387138568Ssam		const char *func, int line);
388178354Ssamstruct ieee80211_node *ieee80211_find_vap_node_locked_debug(
389178354Ssam		struct ieee80211_node_table *,
390178354Ssam		const struct ieee80211vap *vap,
391178354Ssam		const uint8_t macaddr[IEEE80211_ADDR_LEN],
392178354Ssam		const char *func, int line);
393178354Ssamstruct ieee80211_node *ieee80211_find_vap_node_debug(
394178354Ssam		struct ieee80211_node_table *,
395178354Ssam		const struct ieee80211vap *vap,
396178354Ssam		const uint8_t macaddr[IEEE80211_ADDR_LEN],
397178354Ssam		const char *func, int line);
398170530Ssamstruct ieee80211_node * ieee80211_find_rxnode_debug(struct ieee80211com *,
399170530Ssam		const struct ieee80211_frame_min *,
400138568Ssam		const char *func, int line);
401148863Ssamstruct ieee80211_node * ieee80211_find_rxnode_withkey_debug(
402148863Ssam		struct ieee80211com *,
403170530Ssam		const struct ieee80211_frame_min *, uint16_t keyix,
404148863Ssam		const char *func, int line);
405178354Ssamstruct ieee80211_node *ieee80211_find_txnode_debug(struct ieee80211vap *,
406170530Ssam		const uint8_t *,
407170530Ssam		const char *func, int line);
408138568Ssam#define	ieee80211_free_node(ni) \
409138568Ssam	ieee80211_free_node_debug(ni, __func__, __LINE__)
410178354Ssam#define	ieee80211_find_node_locked(nt, mac) \
411178354Ssam	ieee80211_find_node_locked_debug(nt, mac, __func__, __LINE__)
412138568Ssam#define	ieee80211_find_node(nt, mac) \
413138568Ssam	ieee80211_find_node_debug(nt, mac, __func__, __LINE__)
414178354Ssam#define	ieee80211_find_vap_node_locked(nt, vap, mac) \
415178354Ssam	ieee80211_find_vap_node_locked_debug(nt, vap, mac, __func__, __LINE__)
416178354Ssam#define	ieee80211_find_vap_node(nt, vap, mac) \
417178354Ssam	ieee80211_find_vap_node_debug(nt, vap, mac, __func__, __LINE__)
418178354Ssam#define	ieee80211_find_rxnode(ic, wh) \
419178354Ssam	ieee80211_find_rxnode_debug(ic, wh, __func__, __LINE__)
420178354Ssam#define	ieee80211_find_rxnode_withkey(ic, wh, keyix) \
421178354Ssam	ieee80211_find_rxnode_withkey_debug(ic, wh, keyix, __func__, __LINE__)
422178354Ssam#define	ieee80211_find_txnode(vap, mac) \
423178354Ssam	ieee80211_find_txnode_debug(vap, mac, __func__, __LINE__)
424138568Ssam#else
425144618Ssamvoid	ieee80211_free_node(struct ieee80211_node *);
426178354Ssamstruct ieee80211_node *ieee80211_find_node_locked(struct ieee80211_node_table *,
427178354Ssam		const uint8_t macaddr[IEEE80211_ADDR_LEN]);
428170530Ssamstruct ieee80211_node *ieee80211_find_node(struct ieee80211_node_table *,
429178354Ssam		const uint8_t macaddr[IEEE80211_ADDR_LEN]);
430178354Ssamstruct ieee80211_node *ieee80211_find_vap_node_locked(
431178354Ssam		struct ieee80211_node_table *, const struct ieee80211vap *,
432178354Ssam		const uint8_t macaddr[IEEE80211_ADDR_LEN]);
433178354Ssamstruct ieee80211_node *ieee80211_find_vap_node(
434178354Ssam		struct ieee80211_node_table *, const struct ieee80211vap *,
435178354Ssam		const uint8_t macaddr[IEEE80211_ADDR_LEN]);
436170530Ssamstruct ieee80211_node * ieee80211_find_rxnode(struct ieee80211com *,
437170530Ssam		const struct ieee80211_frame_min *);
438148863Ssamstruct ieee80211_node * ieee80211_find_rxnode_withkey(struct ieee80211com *,
439170530Ssam		const struct ieee80211_frame_min *, uint16_t keyix);
440178354Ssamstruct ieee80211_node *ieee80211_find_txnode(struct ieee80211vap *,
441178354Ssam		const uint8_t macaddr[IEEE80211_ADDR_LEN]);
442138568Ssam#endif
443148863Ssamint	ieee80211_node_delucastkey(struct ieee80211_node *);
444170530Ssamvoid	ieee80211_node_timeout(void *arg);
445138568Ssam
446116742Ssamtypedef void ieee80211_iter_func(void *, struct ieee80211_node *);
447239312Sadrianint	ieee80211_iterate_nt(struct ieee80211_node_table *,
448239312Sadrian		struct ieee80211_node **, uint16_t);
449144618Ssamvoid	ieee80211_iterate_nodes(struct ieee80211_node_table *,
450116742Ssam		ieee80211_iter_func *, void *);
451116742Ssam
452178354Ssamvoid	ieee80211_notify_erp(struct ieee80211com *);
453144618Ssamvoid	ieee80211_dump_node(struct ieee80211_node_table *,
454138568Ssam		struct ieee80211_node *);
455144618Ssamvoid	ieee80211_dump_nodes(struct ieee80211_node_table *);
456138568Ssam
457178354Ssamstruct ieee80211_node *ieee80211_fakeup_adhoc_node(struct ieee80211vap *,
458178354Ssam		const uint8_t macaddr[IEEE80211_ADDR_LEN]);
459170530Ssamstruct ieee80211_scanparams;
460153073Ssamvoid	ieee80211_init_neighbor(struct ieee80211_node *,
461153073Ssam		const struct ieee80211_frame *,
462153073Ssam		const struct ieee80211_scanparams *);
463178354Ssamstruct ieee80211_node *ieee80211_add_neighbor(struct ieee80211vap *,
464148936Ssam		const struct ieee80211_frame *,
465148936Ssam		const struct ieee80211_scanparams *);
466178354Ssamvoid	ieee80211_node_join(struct ieee80211_node *,int);
467178354Ssamvoid	ieee80211_node_leave(struct ieee80211_node *);
468178354Ssamint8_t	ieee80211_getrssi(struct ieee80211vap *);
469178354Ssamvoid	ieee80211_getsignal(struct ieee80211vap *, int8_t *, int8_t *);
470116742Ssam#endif /* _NET80211_IEEE80211_NODE_H_ */
471