xref: /openbsd/sys/net80211/ieee80211_node.h (revision 7307575a)
1 /*	$OpenBSD: ieee80211_node.h,v 1.94 2022/03/20 12:01:58 stsp Exp $	*/
2 /*	$NetBSD: ieee80211_node.h,v 1.9 2004/04/30 22:57:32 dyoung Exp $	*/
3 
4 /*-
5  * Copyright (c) 2001 Atsushi Onoe
6  * Copyright (c) 2002, 2003 Sam Leffler, Errno Consulting
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. The name of the author may not be used to endorse or promote products
18  *    derived from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  *
31  * $FreeBSD: src/sys/net80211/ieee80211_node.h,v 1.10 2004/04/05 22:10:26 sam Exp $
32  */
33 #ifndef _NET80211_IEEE80211_NODE_H_
34 #define _NET80211_IEEE80211_NODE_H_
35 
36 #include <sys/tree.h>
37 
38 #define	IEEE80211_PSCAN_WAIT	5		/* passive scan wait */
39 #define	IEEE80211_TRANS_WAIT	5		/* transition wait */
40 #define	IEEE80211_INACT_WAIT	5		/* inactivity timer interval */
41 #define	IEEE80211_INACT_MAX	(300/IEEE80211_INACT_WAIT)
42 #define	IEEE80211_CACHE_SIZE	512
43 #define	IEEE80211_CACHE_WAIT	30
44 #define	IEEE80211_INACT_SCAN	10		/* for station mode */
45 
46 struct ieee80211_rateset {
47 	u_int8_t		rs_nrates;
48 	u_int8_t		rs_rates[IEEE80211_RATE_MAXSIZE];
49 };
50 
51 extern const struct ieee80211_rateset ieee80211_std_rateset_11a;
52 extern const struct ieee80211_rateset ieee80211_std_rateset_11b;
53 extern const struct ieee80211_rateset ieee80211_std_rateset_11g;
54 
55 /* Index into ieee80211_std_rateset_11n[] array. */
56 #define IEEE80211_HT_RATESET_SISO	0
57 #define IEEE80211_HT_RATESET_SISO_SGI	1
58 #define IEEE80211_HT_RATESET_MIMO2	2
59 #define IEEE80211_HT_RATESET_MIMO2_SGI	3
60 #define IEEE80211_HT_RATESET_MIMO3	4
61 #define IEEE80211_HT_RATESET_MIMO3_SGI	5
62 #define IEEE80211_HT_RATESET_MIMO4	6
63 #define IEEE80211_HT_RATESET_MIMO4_SGI	7
64 #define IEEE80211_HT_RATESET_SISO_40	8
65 #define IEEE80211_HT_RATESET_SISO_SGI40 9
66 #define IEEE80211_HT_RATESET_MIMO2_40	10
67 #define IEEE80211_HT_RATESET_MIMO2_SGI40 11
68 #define IEEE80211_HT_RATESET_MIMO3_40	12
69 #define IEEE80211_HT_RATESET_MIMO3_SGI40 13
70 #define IEEE80211_HT_RATESET_MIMO4_40	14
71 #define IEEE80211_HT_RATESET_MIMO4_SGI40 15
72 #define IEEE80211_HT_NUM_RATESETS	16
73 
74 /* Maximum number of rates in a HT rateset. */
75 #define IEEE80211_HT_RATESET_MAX_NRATES	8
76 
77 /* Number of MCS indices represented by struct ieee80211_ht_rateset. */
78 #define IEEE80211_HT_RATESET_NUM_MCS 32
79 
80 struct ieee80211_ht_rateset {
81 	uint32_t nrates;
82 	uint32_t rates[IEEE80211_HT_RATESET_MAX_NRATES]; /* 500 kbit/s units */
83 
84 	/*
85 	 * This bitmask can only express MCS 0 - MCS 31.
86 	 * IEEE 802.11 defined 77 HT MCS in total but common hardware
87 	 * implementations tend to support MCS index 0 through 31 only.
88 	 */
89 	uint32_t mcs_mask;
90 
91 	/* Range of MCS indices represented in this rateset. */
92 	int min_mcs;
93 	int max_mcs;
94 
95 	int chan40;
96 	int sgi;
97 };
98 
99 extern const struct ieee80211_ht_rateset ieee80211_std_ratesets_11n[];
100 
101 /* Index into ieee80211_std_rateset_11ac[] array. */
102 #define IEEE80211_VHT_RATESET_SISO		0
103 #define IEEE80211_VHT_RATESET_SISO_SGI		1
104 #define IEEE80211_VHT_RATESET_MIMO2		2
105 #define IEEE80211_VHT_RATESET_MIMO2_SGI		3
106 #define IEEE80211_VHT_RATESET_SISO_40		4
107 #define IEEE80211_VHT_RATESET_SISO_40_SGI	5
108 #define IEEE80211_VHT_RATESET_MIMO2_40		6
109 #define IEEE80211_VHT_RATESET_MIMO2_40_SGI	7
110 #define IEEE80211_VHT_RATESET_SISO_80		8
111 #define IEEE80211_VHT_RATESET_SISO_80_SGI	9
112 #define IEEE80211_VHT_RATESET_MIMO2_80		10
113 #define IEEE80211_VHT_RATESET_MIMO2_80_SGI	11
114 #define IEEE80211_VHT_NUM_RATESETS		12
115 
116 /* Maximum number of rates in a VHT rateset. */
117 #define IEEE80211_VHT_RATESET_MAX_NRATES	10
118 
119 struct ieee80211_vht_rateset {
120 	int idx; /* This rateset's index in ieee80211_std_rateset_11ac[]. */
121 
122 	uint32_t nrates;
123 	uint32_t rates[IEEE80211_VHT_RATESET_MAX_NRATES]; /* 500 kbit/s units */
124 
125 	/* Number of spatial streams used by rates in this rateset. */
126 	int num_ss;
127 
128 	int chan40;
129 	int chan80;
130 	int sgi;
131 };
132 
133 extern const struct ieee80211_vht_rateset ieee80211_std_ratesets_11ac[];
134 
135 enum ieee80211_node_state {
136 	IEEE80211_STA_CACHE,	/* cached node */
137 	IEEE80211_STA_BSS,	/* ic->ic_bss, the network we joined */
138 	IEEE80211_STA_AUTH,	/* successfully authenticated */
139 	IEEE80211_STA_ASSOC,	/* successfully associated */
140 	IEEE80211_STA_COLLECT	/* This node remains in the cache while
141 				 * the driver sends a de-auth message;
142 				 * afterward it should be freed to make room
143 				 * for a new node.
144 				 */
145 };
146 
147 #define	ieee80211_node_newstate(__ni, __state)	\
148 	do {					\
149 		(__ni)->ni_state = (__state);	\
150 	} while (0)
151 
152 enum ieee80211_node_psstate {
153 	IEEE80211_PS_AWAKE,
154 	IEEE80211_PS_DOZE
155 };
156 
157 #define	IEEE80211_PS_MAX_QUEUE	50	/* maximum saved packets */
158 
159 /* Authenticator state machine: 4-Way Handshake (see 8.5.6.1.1) */
160 enum {
161 	RSNA_INITIALIZE,
162 	RSNA_AUTHENTICATION,
163 	RSNA_AUTHENTICATION_2,
164 	RSNA_INITPMK,
165 	RSNA_INITPSK,
166 	RSNA_PTKSTART,
167 	RSNA_PTKCALCNEGOTIATING,
168 	RSNA_PTKCALCNEGOTIATING_2,
169 	RSNA_PTKINITNEGOTIATING,
170 	RSNA_PTKINITDONE,
171 	RSNA_DISCONNECT,
172 	RSNA_DISCONNECTED
173 };
174 
175 /* Authenticator state machine: Group Key Handshake (see 8.5.6.1.2) */
176 enum {
177 	RSNA_IDLE,
178 	RSNA_REKEYNEGOTIATING,
179 	RSNA_REKEYESTABLISHED,
180 	RSNA_KEYERROR
181 };
182 
183 /* Supplicant state machine: 4-Way Handshake (not documented in standard) */
184 enum {
185 	RSNA_SUPP_INITIALIZE,		/* not expecting any messages */
186 	RSNA_SUPP_PTKSTART,		/* awaiting handshake message 1 */
187 	RSNA_SUPP_PTKNEGOTIATING,	/* got message 1 and derived PTK */
188 	RSNA_SUPP_PTKDONE		/* got message 3 and authenticated AP */
189 };
190 
191 struct ieee80211_rxinfo {
192 	u_int32_t		rxi_flags;
193 	u_int32_t		rxi_tstamp;
194 	int			rxi_rssi;
195 	uint8_t			rxi_chan;
196 };
197 #define IEEE80211_RXI_HWDEC		0x00000001
198 #define IEEE80211_RXI_AMPDU_DONE	0x00000002
199 #define IEEE80211_RXI_HWDEC_SAME_PN	0x00000004
200 #define IEEE80211_RXI_SAME_SEQ		0x00000008
201 
202 /* Block Acknowledgement Record */
203 struct ieee80211_tx_ba {
204 	struct ieee80211_node	*ba_ni;	/* backpointer for callbacks */
205 	struct timeout		ba_to;
206 	int			ba_timeout_val;
207 	int			ba_state;
208 #define IEEE80211_BA_INIT	0
209 #define IEEE80211_BA_REQUESTED	1
210 #define IEEE80211_BA_AGREED	2
211 
212 	/* ADDBA parameter set field for this BA agreement. */
213 	u_int16_t		ba_params;
214 
215 	/* These values are IEEE802.11 frame sequence numbers (0x0-0xfff) */
216 	u_int16_t		ba_winstart;
217 	u_int16_t		ba_winend;
218 
219 	/* Number of A-MPDU subframes in reorder buffer. */
220 	u_int16_t		ba_winsize;
221 #define IEEE80211_BA_MAX_WINSZ	64	/* corresponds to maximum ADDBA BUFSZ */
222 
223 	u_int8_t		ba_token;
224 
225 	/* Bitmap for ACK'd frames in the current BA window. */
226 	uint64_t		ba_bitmap;
227 };
228 
229 struct ieee80211_rx_ba {
230 	struct ieee80211_node	*ba_ni;	/* backpointer for callbacks */
231 	struct {
232 		struct mbuf		*m;
233 		struct ieee80211_rxinfo	rxi;
234 	}			*ba_buf;
235 	struct timeout		ba_to;
236 	int			ba_timeout_val;
237 	int			ba_state;
238 	u_int16_t		ba_params;
239 	u_int16_t		ba_winstart;
240 	u_int16_t		ba_winend;
241 	u_int16_t		ba_winsize;
242 	u_int16_t		ba_head;
243 	struct timeout		ba_gap_to;
244 #define IEEE80211_BA_GAP_TIMEOUT	300 /* msec */
245 
246 	/*
247 	 * Counter for frames forced to wait in the reordering buffer
248 	 * due to a leading gap caused by one or more missing frames.
249 	 */
250 	int			ba_gapwait;
251 
252 	/* Counter for consecutive frames which missed the BA window. */
253 	int			ba_winmiss;
254 	/* Sequence number of previous frame which missed the BA window. */
255 	uint16_t		ba_missedsn;
256 	/* Window moves forward after this many frames have missed it. */
257 #define IEEE80211_BA_MAX_WINMISS	8
258 
259 	uint8_t			ba_token;
260 };
261 
262 /*
263  * Node specific information.  Note that drivers are expected
264  * to derive from this structure to add device-specific per-node
265  * state.  This is done by overriding the ic_node_* methods in
266  * the ieee80211com structure.
267  */
268 struct ieee80211_node {
269 	RBT_ENTRY(ieee80211_node)	ni_node;
270 
271 	struct ieee80211com	*ni_ic;		/* back-pointer */
272 
273 	u_int			ni_refcnt;
274 	u_int			ni_scangen;	/* gen# for timeout scan */
275 
276 	/* hardware */
277 	u_int32_t		ni_rstamp;	/* recv timestamp */
278 	u_int8_t		ni_rssi;	/* recv ssi */
279 
280 	/* header */
281 	u_int8_t		ni_macaddr[IEEE80211_ADDR_LEN];
282 	u_int8_t		ni_bssid[IEEE80211_ADDR_LEN];
283 
284 	/* beacon, probe response */
285 	u_int8_t		ni_tstamp[8];	/* from last rcv'd beacon */
286 	u_int16_t		ni_intval;	/* beacon interval */
287 	u_int16_t		ni_capinfo;	/* capabilities */
288 	u_int8_t		ni_esslen;
289 	u_int8_t		ni_essid[IEEE80211_NWID_LEN];
290 	struct ieee80211_rateset ni_rates;	/* negotiated rate set */
291 	u_int8_t		*ni_country;	/* country information XXX */
292 	struct ieee80211_channel *ni_chan;
293 	u_int8_t		ni_erp;		/* 11g only */
294 
295 	/* DTIM and contention free period (CFP) */
296 	u_int8_t		ni_dtimcount;
297 	u_int8_t		ni_dtimperiod;
298 #ifdef notyet
299 	u_int8_t		ni_cfpperiod;	/* # of DTIMs between CFPs */
300 	u_int16_t		ni_cfpduremain;	/* remaining cfp duration */
301 	u_int16_t		ni_cfpmaxduration;/* max CFP duration in TU */
302 	u_int16_t		ni_nextdtim;	/* time to next DTIM */
303 	u_int16_t		ni_timoffset;
304 #endif
305 
306 	/* power saving mode */
307 	u_int8_t		ni_pwrsave;
308 	struct mbuf_queue	ni_savedq;	/* packets queued for pspoll */
309 
310 	/* RSN */
311 	struct timeout		ni_eapol_to;
312 	u_int			ni_rsn_state;
313 	u_int			ni_rsn_supp_state;
314 	u_int			ni_rsn_gstate;
315 	u_int			ni_rsn_retries;
316 	u_int			ni_supported_rsnprotos;
317 	u_int			ni_rsnprotos;
318 	u_int			ni_supported_rsnakms;
319 	u_int			ni_rsnakms;
320 	u_int			ni_rsnciphers;
321 	enum ieee80211_cipher	ni_rsngroupcipher;
322 	enum ieee80211_cipher	ni_rsngroupmgmtcipher;
323 	u_int16_t		ni_rsncaps;
324 	enum ieee80211_cipher	ni_rsncipher;
325 	u_int8_t		ni_nonce[EAPOL_KEY_NONCE_LEN];
326 	u_int8_t		ni_pmk[IEEE80211_PMK_LEN];
327 	u_int8_t		ni_pmkid[IEEE80211_PMKID_LEN];
328 	u_int64_t		ni_replaycnt;
329 	u_int8_t		ni_replaycnt_ok;
330 	u_int64_t		ni_reqreplaycnt;
331 	u_int8_t		ni_reqreplaycnt_ok;
332 	u_int8_t		*ni_rsnie;
333 	struct ieee80211_key	ni_pairwise_key;
334 	struct ieee80211_ptk	ni_ptk;
335 	u_int8_t		ni_key_count;
336 	int			ni_port_valid;
337 
338 	/* SA Query */
339 	u_int16_t		ni_sa_query_trid;
340 	struct timeout		ni_sa_query_to;
341 	int			ni_sa_query_count;
342 
343 	/* HT capabilities */
344 	uint16_t		ni_htcaps;
345 	uint8_t			ni_ampdu_param;
346 	uint8_t			ni_rxmcs[howmany(80,NBBY)];
347 	uint16_t		ni_max_rxrate;	/* in Mb/s, 0 <= rate <= 1023 */
348 	uint8_t			ni_tx_mcs_set;
349 	uint16_t		ni_htxcaps;
350 	uint32_t		ni_txbfcaps;
351 	uint8_t			ni_aselcaps;
352 
353 	/* HT operation */
354 	uint8_t			ni_primary_chan; /* XXX corresponds to ni_chan */
355 	uint8_t			ni_htop0;
356 	uint16_t		ni_htop1;
357 	uint16_t		ni_htop2;
358 	uint8_t			ni_basic_mcs[howmany(128,NBBY)];
359 
360 	/* VHT capabilities */
361 	uint32_t		ni_vhtcaps;
362 	uint16_t		ni_vht_rxmcs;
363 	uint16_t		ni_vht_rx_max_lgi_mbit_s;
364 	uint16_t		ni_vht_txmcs;
365 	uint16_t		ni_vht_tx_max_lgi_mbit_s;
366 
367 	/* VHT operation */
368 	uint8_t			ni_vht_chan_width;
369 	uint8_t			ni_vht_chan_center_freq_idx0;
370 	uint8_t			ni_vht_chan_center_freq_idx1;
371 	uint16_t		ni_vht_basic_mcs;
372 
373 	/* Timeout handlers which trigger Tx Block Ack negotiation. */
374 	struct timeout		ni_addba_req_to[IEEE80211_NUM_TID];
375 	int			ni_addba_req_intval[IEEE80211_NUM_TID];
376 #define IEEE80211_ADDBA_REQ_INTVAL_MAX 30	/* in seconds */
377 
378 	/* Block Ack records */
379 	struct ieee80211_tx_ba	ni_tx_ba[IEEE80211_NUM_TID];
380 	struct ieee80211_rx_ba	ni_rx_ba[IEEE80211_NUM_TID];
381 
382 	int			ni_txmcs;	/* current MCS used for TX */
383 	int			ni_vht_ss;	/* VHT # spatial streams */
384 
385 	/* others */
386 	u_int16_t		ni_associd;	/* assoc response */
387 	u_int16_t		ni_txseq;	/* seq to be transmitted */
388 	u_int16_t		ni_rxseq;	/* seq previous received */
389 	u_int16_t		ni_qos_txseqs[IEEE80211_NUM_TID];
390 	u_int16_t		ni_qos_rxseqs[IEEE80211_NUM_TID];
391 	int			ni_fails;	/* failure count to associate */
392 	uint32_t		ni_assoc_fail;	/* assoc failure reasons */
393 #define IEEE80211_NODE_ASSOCFAIL_CHAN		0x01
394 #define IEEE80211_NODE_ASSOCFAIL_IBSS		0x02
395 #define IEEE80211_NODE_ASSOCFAIL_PRIVACY	0x04
396 #define IEEE80211_NODE_ASSOCFAIL_BASIC_RATE	0x08
397 #define IEEE80211_NODE_ASSOCFAIL_ESSID		0x10
398 #define IEEE80211_NODE_ASSOCFAIL_BSSID		0x20
399 #define IEEE80211_NODE_ASSOCFAIL_WPA_PROTO	0x40
400 #define IEEE80211_NODE_ASSOCFAIL_WPA_KEY	0x80
401 
402 	int			ni_inact;	/* inactivity mark count */
403 	int			ni_txrate;	/* index to ni_rates[] */
404 	int			ni_state;
405 
406 	u_int32_t		ni_flags;	/* special-purpose state */
407 #define IEEE80211_NODE_ERP		0x0001
408 #define IEEE80211_NODE_QOS		0x0002
409 #define IEEE80211_NODE_REKEY		0x0004	/* GTK rekeying in progress */
410 #define IEEE80211_NODE_RXPROT		0x0008	/* RX protection ON */
411 #define IEEE80211_NODE_TXPROT		0x0010	/* TX protection ON */
412 #define IEEE80211_NODE_TXRXPROT	\
413 	(IEEE80211_NODE_TXPROT | IEEE80211_NODE_RXPROT)
414 #define IEEE80211_NODE_RXMGMTPROT	0x0020	/* RX MMPDU protection ON */
415 #define IEEE80211_NODE_TXMGMTPROT	0x0040	/* TX MMPDU protection ON */
416 #define IEEE80211_NODE_MFP		0x0080	/* MFP negotiated */
417 #define IEEE80211_NODE_PMK		0x0100	/* ni_pmk set */
418 #define IEEE80211_NODE_PMKID		0x0200	/* ni_pmkid set */
419 #define IEEE80211_NODE_HT		0x0400	/* HT negotiated */
420 #define IEEE80211_NODE_SA_QUERY		0x0800	/* SA Query in progress */
421 #define IEEE80211_NODE_SA_QUERY_FAILED	0x1000	/* last SA Query failed */
422 #define IEEE80211_NODE_RSN_NEW_PTK	0x2000	/* expecting a new PTK */
423 #define IEEE80211_NODE_HT_SGI20		0x4000	/* SGI on 20 MHz negotiated */
424 #define IEEE80211_NODE_HT_SGI40		0x8000	/* SGI on 40 MHz negotiated */
425 #define IEEE80211_NODE_VHT		0x10000	/* VHT negotiated */
426 #define IEEE80211_NODE_HTCAP		0x20000	/* claims to support HT */
427 #define IEEE80211_NODE_VHTCAP		0x40000	/* claims to support VHT */
428 #define IEEE80211_NODE_VHT_SGI80	0x80000	/* SGI on 80 MHz negotiated */
429 #define IEEE80211_NODE_VHT_SGI160	0x100000 /* SGI on 160 MHz negotiated */
430 
431 	/* If not NULL, this function gets called when ni_refcnt hits zero. */
432 	void			(*ni_unref_cb)(struct ieee80211com *,
433 					struct ieee80211_node *);
434 	void *			ni_unref_arg;
435 	size_t 			ni_unref_arg_size;
436 };
437 
438 RBT_HEAD(ieee80211_tree, ieee80211_node);
439 
440 struct ieee80211_ess_rbt {
441 	RBT_ENTRY(ieee80211_ess_rbt)	 ess_rbt;
442 	u_int8_t			 esslen;
443 	u_int8_t			 essid[IEEE80211_NWID_LEN];
444 	struct ieee80211_node		*ni2;
445 	struct ieee80211_node		*ni5;
446 	struct ieee80211_node		*ni;
447 };
448 
449 RBT_HEAD(ieee80211_ess_tree, ieee80211_ess_rbt);
450 
451 static inline void
ieee80211_node_incref(struct ieee80211_node * ni)452 ieee80211_node_incref(struct ieee80211_node *ni)
453 {
454 	int		s;
455 
456 	s = splnet();
457 	ni->ni_refcnt++;
458 	splx(s);
459 }
460 
461 static inline u_int
ieee80211_node_decref(struct ieee80211_node * ni)462 ieee80211_node_decref(struct ieee80211_node *ni)
463 {
464 	u_int		refcnt;
465 	int 		s;
466 
467 	s = splnet();
468 	refcnt = --ni->ni_refcnt;
469 	splx(s);
470 	return refcnt;
471 }
472 
473 static inline struct ieee80211_node *
ieee80211_ref_node(struct ieee80211_node * ni)474 ieee80211_ref_node(struct ieee80211_node *ni)
475 {
476 	ieee80211_node_incref(ni);
477 	return ni;
478 }
479 
480 static inline void
ieee80211_unref_node(struct ieee80211_node ** ni)481 ieee80211_unref_node(struct ieee80211_node **ni)
482 {
483 	ieee80211_node_decref(*ni);
484 	*ni = NULL;			/* guard against use */
485 }
486 
487 /*
488  * Check if the peer supports HT.
489  * Require a HT capabilities IE and at least one of the mandatory MCS.
490  * MCS 0-7 are mandatory but some APs have particular MCS disabled.
491  */
492 static inline int
ieee80211_node_supports_ht(struct ieee80211_node * ni)493 ieee80211_node_supports_ht(struct ieee80211_node *ni)
494 {
495 	return ((ni->ni_flags & IEEE80211_NODE_HTCAP) &&
496 	    ni->ni_rxmcs[0] & 0xff);
497 }
498 
499 /* Check if the peer supports HT short guard interval (SGI) on 20 MHz. */
500 static inline int
ieee80211_node_supports_ht_sgi20(struct ieee80211_node * ni)501 ieee80211_node_supports_ht_sgi20(struct ieee80211_node *ni)
502 {
503 	return ieee80211_node_supports_ht(ni) &&
504 	    (ni->ni_htcaps & IEEE80211_HTCAP_SGI20);
505 }
506 
507 /* Check if the peer supports HT short guard interval (SGI) on 40 MHz. */
508 static inline int
ieee80211_node_supports_ht_sgi40(struct ieee80211_node * ni)509 ieee80211_node_supports_ht_sgi40(struct ieee80211_node *ni)
510 {
511 	return ieee80211_node_supports_ht(ni) &&
512 	    (ni->ni_htcaps & IEEE80211_HTCAP_SGI40);
513 }
514 
515 /* Check if the peer can receive frames sent on a 40 MHz channel. */
516 static inline int
ieee80211_node_supports_ht_chan40(struct ieee80211_node * ni)517 ieee80211_node_supports_ht_chan40(struct ieee80211_node *ni)
518 {
519 	return (ieee80211_node_supports_ht(ni) &&
520 	    (ni->ni_htcaps & IEEE80211_HTCAP_CBW20_40) &&
521 	    (ni->ni_htop0 & IEEE80211_HTOP0_CHW));
522 }
523 
524 /*
525  * Check if the peer supports VHT.
526  * Require a VHT capabilities IE and support for VHT MCS with a single
527  * spatial stream.
528  */
529 static inline int
ieee80211_node_supports_vht(struct ieee80211_node * ni)530 ieee80211_node_supports_vht(struct ieee80211_node *ni)
531 {
532 	uint16_t rx_mcs;
533 
534 	rx_mcs = (ni->ni_vht_rxmcs & IEEE80211_VHT_MCS_FOR_SS_MASK(1)) >>
535 	    IEEE80211_VHT_MCS_FOR_SS_SHIFT(1);
536 
537 	return ((ni->ni_flags & IEEE80211_NODE_VHTCAP) &&
538 	    rx_mcs != IEEE80211_VHT_MCS_SS_NOT_SUPP);
539 }
540 
541 /* Check if the peer supports VHT short guard interval (SGI) on 80 MHz. */
542 static inline int
ieee80211_node_supports_vht_sgi80(struct ieee80211_node * ni)543 ieee80211_node_supports_vht_sgi80(struct ieee80211_node *ni)
544 {
545 	return ieee80211_node_supports_vht(ni) &&
546 	    (ni->ni_vhtcaps & IEEE80211_VHTCAP_SGI80);
547 }
548 
549 /* Check if the peer supports VHT short guard interval (SGI) on 160 MHz. */
550 static inline int
ieee80211_node_supports_vht_sgi160(struct ieee80211_node * ni)551 ieee80211_node_supports_vht_sgi160(struct ieee80211_node *ni)
552 {
553 	return ieee80211_node_supports_vht(ni) &&
554 	    (ni->ni_vhtcaps & IEEE80211_VHTCAP_SGI160);
555 }
556 
557 /* Check if the peer can receive frames sent on an 80 MHz channel. */
558 static inline int
ieee80211_node_supports_vht_chan80(struct ieee80211_node * ni)559 ieee80211_node_supports_vht_chan80(struct ieee80211_node *ni)
560 {
561 	uint8_t cap_chan_width, op_chan_width;
562 
563 	if (!ieee80211_node_supports_vht(ni))
564 		return 0;
565 
566 	cap_chan_width = (ni->ni_vhtcaps & IEEE80211_VHTCAP_CHAN_WIDTH_MASK) >>
567 	    IEEE80211_VHTCAP_CHAN_WIDTH_SHIFT;
568 	if (cap_chan_width != IEEE80211_VHTCAP_CHAN_WIDTH_80 &&
569 	    cap_chan_width != IEEE80211_VHTCAP_CHAN_WIDTH_160 &&
570 	    cap_chan_width != IEEE80211_VHTCAP_CHAN_WIDTH_160_8080)
571 		return 0;
572 
573 	op_chan_width = (ni->ni_vht_chan_width &
574 	    IEEE80211_VHTOP0_CHAN_WIDTH_MASK) >>
575 	    IEEE80211_VHTOP0_CHAN_WIDTH_SHIFT;
576 
577 	return (op_chan_width == IEEE80211_VHTOP0_CHAN_WIDTH_80 ||
578 	    op_chan_width == IEEE80211_VHTOP0_CHAN_WIDTH_160 ||
579 	    op_chan_width == IEEE80211_VHTOP0_CHAN_WIDTH_8080);
580 }
581 
582 /* Check if the peer can receive frames sent on a 160 MHz channel. */
583 static inline int
ieee80211_node_supports_vht_chan160(struct ieee80211_node * ni)584 ieee80211_node_supports_vht_chan160(struct ieee80211_node *ni)
585 {
586 	uint8_t cap_chan_width, op_chan_width;
587 
588 	if (!ieee80211_node_supports_vht(ni))
589 		return 0;
590 
591 	cap_chan_width = (ni->ni_vhtcaps & IEEE80211_VHTCAP_CHAN_WIDTH_MASK) >>
592 	    IEEE80211_VHTCAP_CHAN_WIDTH_SHIFT;
593 	if (cap_chan_width != IEEE80211_VHTCAP_CHAN_WIDTH_160)
594 		return 0;
595 
596 	op_chan_width = (ni->ni_vht_chan_width &
597 	    IEEE80211_VHTOP0_CHAN_WIDTH_MASK) >>
598 	    IEEE80211_VHTOP0_CHAN_WIDTH_SHIFT;
599 
600 	return (op_chan_width == IEEE80211_VHTOP0_CHAN_WIDTH_160);
601 }
602 
603 struct ieee80211com;
604 
605 typedef void ieee80211_iter_func(void *, struct ieee80211_node *);
606 
607 void ieee80211_node_attach(struct ifnet *);
608 void ieee80211_node_lateattach(struct ifnet *);
609 void ieee80211_node_detach(struct ifnet *);
610 
611 void ieee80211_begin_scan(struct ifnet *);
612 void ieee80211_next_scan(struct ifnet *);
613 void ieee80211_end_scan(struct ifnet *);
614 void ieee80211_reset_scan(struct ifnet *);
615 struct ieee80211_node *ieee80211_alloc_node(struct ieee80211com *,
616 		const u_int8_t *);
617 struct ieee80211_node *ieee80211_dup_bss(struct ieee80211com *,
618 		const u_int8_t *);
619 struct ieee80211_node *ieee80211_find_node(struct ieee80211com *,
620 		const u_int8_t *);
621 void ieee80211_node_tx_ba_clear(struct ieee80211_node *, int);
622 void ieee80211_ba_del(struct ieee80211_node *);
623 struct ieee80211_node *ieee80211_find_rxnode(struct ieee80211com *,
624 		const struct ieee80211_frame *);
625 struct ieee80211_node *ieee80211_find_txnode(struct ieee80211com *,
626 		const u_int8_t *);
627 void ieee80211_release_node(struct ieee80211com *,
628 		struct ieee80211_node *);
629 void ieee80211_node_cleanup(struct ieee80211com *, struct ieee80211_node *);
630 void ieee80211_free_allnodes(struct ieee80211com *, int);
631 void ieee80211_iterate_nodes(struct ieee80211com *,
632 		ieee80211_iter_func *, void *);
633 void ieee80211_clean_cached(struct ieee80211com *);
634 void ieee80211_clean_nodes(struct ieee80211com *, int);
635 void ieee80211_setup_htcaps(struct ieee80211_node *, const uint8_t *,
636     uint8_t);
637 void ieee80211_clear_htcaps(struct ieee80211_node *);
638 int ieee80211_setup_htop(struct ieee80211_node *, const uint8_t *,
639     uint8_t, int);
640 void ieee80211_setup_vhtcaps(struct ieee80211_node *, const uint8_t *,
641     uint8_t);
642 void ieee80211_clear_vhtcaps(struct ieee80211_node *);
643 int ieee80211_setup_vhtop(struct ieee80211_node *, const uint8_t *,
644     uint8_t, int);
645 int ieee80211_setup_rates(struct ieee80211com *,
646 	    struct ieee80211_node *, const u_int8_t *, const u_int8_t *, int);
647 void ieee80211_node_trigger_addba_req(struct ieee80211_node *, int);
648 int ieee80211_iserp_sta(const struct ieee80211_node *);
649 void ieee80211_count_longslotsta(void *, struct ieee80211_node *);
650 void ieee80211_count_nonerpsta(void *, struct ieee80211_node *);
651 void ieee80211_count_pssta(void *, struct ieee80211_node *);
652 void ieee80211_count_rekeysta(void *, struct ieee80211_node *);
653 void ieee80211_node_join(struct ieee80211com *,
654 		struct ieee80211_node *, int);
655 void ieee80211_node_leave(struct ieee80211com *,
656 		struct ieee80211_node *);
657 int ieee80211_match_bss(struct ieee80211com *, struct ieee80211_node *, int);
658 void ieee80211_node_tx_stopped(struct ieee80211com *, struct ieee80211_node *);
659 struct ieee80211_node *ieee80211_node_choose_bss(struct ieee80211com *, int,
660 		struct ieee80211_node **);
661 void ieee80211_node_join_bss(struct ieee80211com *, struct ieee80211_node *);
662 void ieee80211_create_ibss(struct ieee80211com* ,
663 		struct ieee80211_channel *);
664 void ieee80211_notify_dtim(struct ieee80211com *);
665 void ieee80211_set_tim(struct ieee80211com *, int, int);
666 void ieee80211_free_node(struct ieee80211com *, struct ieee80211_node *);
667 
668 int ieee80211_node_cmp(const struct ieee80211_node *,
669 		const struct ieee80211_node *);
670 int ieee80211_ess_cmp(const struct ieee80211_ess_rbt *,
671 		const struct ieee80211_ess_rbt *);
672 RBT_PROTOTYPE(ieee80211_tree, ieee80211_node, ni_node, ieee80211_node_cmp);
673 RBT_PROTOTYPE(ieee80211_ess_tree, ieee80211_ess_rbt, ess_rbt, ieee80211_ess_cmp);
674 
675 #endif /* _NET80211_IEEE80211_NODE_H_ */
676