| 1 | /*	$OpenBSD: ieee80211_node.h,v 1.101 2026/03/29 21:16:21 kirill 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_ratesets_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_ratesets_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_ratesets_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 | 	/* HE capabilities */ |
| 374 | 	uint8_t			ni_he_mac_cap[IEEE80211_HE_MAC_CAPS_LEN]; |
| 375 | 	uint8_t			ni_he_phy_cap[IEEE80211_HE_PHY_CAPS_LEN]; |
| 376 | 	uint16_t		ni_he_rxmcs_80; |
| 377 | 	uint16_t		ni_he_txmcs_80; |
| 378 | 	uint16_t		ni_he_rxmcs_160; |
| 379 | 	uint16_t		ni_he_txmcs_160; |
| 380 | 	uint16_t		ni_he_rxmcs_80p80; |
| 381 | 	uint16_t		ni_he_txmcs_80p80; |
| 382 | |
| 383 | 	/* HE operation */ |
| 384 | 	uint8_t			ni_he_oper_params[IEEE80211_HEOP_PARAMS_LEN]; |
| 385 | 	uint16_t		ni_he_basic_mcs; |
| 386 | |
| 387 | 	/* Timeout handlers which trigger Tx Block Ack negotiation. */ |
| 388 | 	struct timeout		ni_addba_req_to[IEEE80211_NUM_TID]; |
| 389 | 	int			ni_addba_req_intval[IEEE80211_NUM_TID]; |
| 390 | #define IEEE80211_ADDBA_REQ_INTVAL_MAX 30	/* in seconds */ |
| 391 | |
| 392 | 	/* Block Ack records */ |
| 393 | 	struct ieee80211_tx_ba	ni_tx_ba[IEEE80211_NUM_TID]; |
| 394 | 	struct ieee80211_rx_ba	ni_rx_ba[IEEE80211_NUM_TID]; |
| 395 | |
| 396 | 	int			ni_txmcs;	/* current MCS used for TX */ |
| 397 | 	int			ni_vht_ss;	/* VHT # spatial streams */ |
| 398 | 	int			ni_he_ss;	/* HE # spatial streams */ |
| 399 | |
| 400 | 	/* others */ |
| 401 | 	u_int16_t		ni_associd;	/* assoc response */ |
| 402 | 	u_int16_t		ni_txseq;	/* seq to be transmitted */ |
| 403 | 	u_int16_t		ni_rxseq;	/* seq previous received */ |
| 404 | 	u_int16_t		ni_qos_txseqs[IEEE80211_NUM_TID]; |
| 405 | 	u_int16_t		ni_qos_rxseqs[IEEE80211_NUM_TID]; |
| 406 | 	int			ni_fails;	/* failure count to associate */ |
| 407 | 	uint32_t		ni_assoc_fail;	/* assoc failure reasons */ |
| 408 | #define IEEE80211_NODE_ASSOCFAIL_CHAN		0x01 |
| 409 | #define IEEE80211_NODE_ASSOCFAIL_IBSS		0x02 |
| 410 | #define IEEE80211_NODE_ASSOCFAIL_PRIVACY	0x04 |
| 411 | #define IEEE80211_NODE_ASSOCFAIL_BASIC_RATE	0x08 |
| 412 | #define IEEE80211_NODE_ASSOCFAIL_ESSID		0x10 |
| 413 | #define IEEE80211_NODE_ASSOCFAIL_BSSID		0x20 |
| 414 | #define IEEE80211_NODE_ASSOCFAIL_WPA_PROTO	0x40 |
| 415 | #define IEEE80211_NODE_ASSOCFAIL_WPA_KEY	0x80 |
| 416 | #define IEEE80211_NODE_ASSOCFAIL_CSA		0x100 |
| 417 | |
| 418 | 	int			ni_inact;	/* inactivity mark count */ |
| 419 | 	int			ni_txrate;	/* index to ni_rates[] */ |
| 420 | 	int			ni_state; |
| 421 | |
| 422 | 	u_int32_t		ni_flags;	/* special-purpose state */ |
| 423 | #define IEEE80211_NODE_ERP		0x0001 |
| 424 | #define IEEE80211_NODE_QOS		0x0002 |
| 425 | #define IEEE80211_NODE_REKEY		0x0004	/* GTK rekeying in progress */ |
| 426 | #define IEEE80211_NODE_RXPROT		0x0008	/* RX protection ON */ |
| 427 | #define IEEE80211_NODE_TXPROT		0x0010	/* TX protection ON */ |
| 428 | #define IEEE80211_NODE_TXRXPROT	\ |
| 429 | 	(IEEE80211_NODE_TXPROT | IEEE80211_NODE_RXPROT) |
| 430 | #define IEEE80211_NODE_RXMGMTPROT	0x0020	/* RX MMPDU protection ON */ |
| 431 | #define IEEE80211_NODE_TXMGMTPROT	0x0040	/* TX MMPDU protection ON */ |
| 432 | #define IEEE80211_NODE_MFP		0x0080	/* MFP negotiated */ |
| 433 | #define IEEE80211_NODE_PMK		0x0100	/* ni_pmk set */ |
| 434 | #define IEEE80211_NODE_PMKID		0x0200	/* ni_pmkid set */ |
| 435 | #define IEEE80211_NODE_HT		0x0400	/* HT negotiated */ |
| 436 | #define IEEE80211_NODE_SA_QUERY		0x0800	/* SA Query in progress */ |
| 437 | #define IEEE80211_NODE_SA_QUERY_FAILED	0x1000	/* last SA Query failed */ |
| 438 | #define IEEE80211_NODE_RSN_NEW_PTK	0x2000	/* expecting a new PTK */ |
| 439 | #define IEEE80211_NODE_HT_SGI20		0x4000	/* SGI on 20 MHz negotiated */ |
| 440 | #define IEEE80211_NODE_HT_SGI40		0x8000	/* SGI on 40 MHz negotiated */ |
| 441 | #define IEEE80211_NODE_VHT		0x10000	/* VHT negotiated */ |
| 442 | #define IEEE80211_NODE_HTCAP		0x20000	/* claims to support HT */ |
| 443 | #define IEEE80211_NODE_VHTCAP		0x40000	/* claims to support VHT */ |
| 444 | #define IEEE80211_NODE_VHT_SGI80	0x80000	/* SGI on 80 MHz negotiated */ |
| 445 | #define IEEE80211_NODE_VHT_SGI160	0x100000 /* SGI on 160 MHz negotiated */ |
| 446 | #define IEEE80211_NODE_HE		0x200000 /* HE negotiated */ |
| 447 | #define IEEE80211_NODE_HECAP		0x400000 /* claims to support HE */ |
| 448 | #define IEEE80211_NODE_CSA		0x800000 /* channel switch announced */ |
| 449 | |
| 450 | 	/* If not NULL, this function gets called when ni_refcnt hits zero. */ |
| 451 | 	void			(*ni_unref_cb)(struct ieee80211com *, |
| 452 | 					struct ieee80211_node *); |
| 453 | 	void *			ni_unref_arg; |
| 454 | 	size_t 			ni_unref_arg_size; |
| 455 | }; |
| 456 | |
| 457 | RBT_HEAD(ieee80211_tree, ieee80211_node); |
| 458 | |
| 459 | struct ieee80211_ess_rbt { |
| 460 | 	RBT_ENTRY(ieee80211_ess_rbt)	 ess_rbt; |
| 461 | 	u_int8_t			 esslen; |
| 462 | 	u_int8_t			 essid[IEEE80211_NWID_LEN]; |
| 463 | 	struct ieee80211_node		*ni2; |
| 464 | 	struct ieee80211_node		*ni5; |
| 465 | 	struct ieee80211_node		*ni; |
| 466 | }; |
| 467 | |
| 468 | RBT_HEAD(ieee80211_ess_tree, ieee80211_ess_rbt); |
| 469 | |
| 470 | static inline void |
| 471 | ieee80211_node_incref(struct ieee80211_node *ni) |
| 472 | { |
| 473 | 	int		s; |
| 474 | |
| 475 | 	s = splnet(); |
| 476 | 	ni->ni_refcnt++; |
| 477 | 	splx(s); |
| 478 | } |
| 479 | |
| 480 | static inline u_int |
| 481 | ieee80211_node_decref(struct ieee80211_node *ni) |
| 482 | { |
| 483 | 	u_int		refcnt; |
| 484 | 	int 		s; |
| 485 | |
| 486 | 	s = splnet(); |
| 487 | 	refcnt = --ni->ni_refcnt; |
| 488 | 	splx(s); |
| 489 | 	return refcnt; |
| 490 | } |
| 491 | |
| 492 | static inline struct ieee80211_node * |
| 493 | ieee80211_ref_node(struct ieee80211_node *ni) |
| 494 | { |
| 495 | 	ieee80211_node_incref(ni); |
| 496 | 	return ni; |
| 497 | } |
| 498 | |
| 499 | static inline void |
| 500 | ieee80211_unref_node(struct ieee80211_node **ni) |
| 501 | { |
| 502 | 	ieee80211_node_decref(*ni); |
| 503 | 	*ni = NULL;			/* guard against use */ |
| 504 | } |
| 505 | |
| 506 | /* |
| 507 | * Check if the peer supports HT. |
| 508 | * Require a HT capabilities IE and at least one of the mandatory MCS. |
| 509 | * MCS 0-7 are mandatory but some APs have particular MCS disabled. |
| 510 | */ |
| 511 | static inline int |
| 512 | ieee80211_node_supports_ht(struct ieee80211_node *ni) |
| 513 | { |
| 514 | 	return ((ni->ni_flags & IEEE80211_NODE_HTCAP) && |
| 515 | 	 ni->ni_rxmcs[0] & 0xff); |
| 516 | } |
| 517 | |
| 518 | /* Check if the peer supports HT short guard interval (SGI) on 20 MHz. */ |
| 519 | static inline int |
| 520 | ieee80211_node_supports_ht_sgi20(struct ieee80211_node *ni) |
| 521 | { |
| 522 | 	return ieee80211_node_supports_ht(ni) && |
| 523 | 	 (ni->ni_htcaps & IEEE80211_HTCAP_SGI20); |
| 524 | } |
| 525 | |
| 526 | /* Check if the peer supports HT short guard interval (SGI) on 40 MHz. */ |
| 527 | static inline int |
| 528 | ieee80211_node_supports_ht_sgi40(struct ieee80211_node *ni) |
| 529 | { |
| 530 | 	return ieee80211_node_supports_ht(ni) && |
| 531 | 	 (ni->ni_htcaps & IEEE80211_HTCAP_SGI40); |
| 532 | } |
| 533 | |
| 534 | /* Check if the peer can receive frames sent on a 40 MHz channel. */ |
| 535 | static inline int |
| 536 | ieee80211_node_supports_ht_chan40(struct ieee80211_node *ni) |
| 537 | { |
| 538 | 	return (ieee80211_node_supports_ht(ni) && |
| 539 | 	 (ni->ni_htcaps & IEEE80211_HTCAP_CBW20_40) && |
| 540 | 	 (ni->ni_htop0 & IEEE80211_HTOP0_CHW)); |
| 541 | } |
| 542 | |
| 543 | /* |
| 544 | * Check if the peer supports VHT. |
| 545 | * Require a VHT capabilities IE and support for VHT MCS with a single |
| 546 | * spatial stream. |
| 547 | */ |
| 548 | static inline int |
| 549 | ieee80211_node_supports_vht(struct ieee80211_node *ni) |
| 550 | { |
| 551 | 	uint16_t rx_mcs; |
| 552 | |
| 553 | 	rx_mcs = (ni->ni_vht_rxmcs & IEEE80211_VHT_MCS_FOR_SS_MASK(1)) >> |
| 554 | 	 IEEE80211_VHT_MCS_FOR_SS_SHIFT(1); |
| 555 | |
| 556 | 	return ((ni->ni_flags & IEEE80211_NODE_VHTCAP) && |
| 557 | 	 rx_mcs != IEEE80211_VHT_MCS_SS_NOT_SUPP); |
| 558 | } |
| 559 | |
| 560 | /* Check if the peer supports VHT short guard interval (SGI) on 80 MHz. */ |
| 561 | static inline int |
| 562 | ieee80211_node_supports_vht_sgi80(struct ieee80211_node *ni) |
| 563 | { |
| 564 | 	return ieee80211_node_supports_vht(ni) && |
| 565 | 	 (ni->ni_vhtcaps & IEEE80211_VHTCAP_SGI80); |
| 566 | } |
| 567 | |
| 568 | /* Check if the peer supports VHT short guard interval (SGI) on 160 MHz. */ |
| 569 | static inline int |
| 570 | ieee80211_node_supports_vht_sgi160(struct ieee80211_node *ni) |
| 571 | { |
| 572 | 	return ieee80211_node_supports_vht(ni) && |
| 573 | 	 (ni->ni_vhtcaps & IEEE80211_VHTCAP_SGI160); |
| 574 | } |
| 575 | |
| 576 | /* Check if the peer can receive frames sent on an 80 MHz channel. */ |
| 577 | static inline int |
| 578 | ieee80211_node_supports_vht_chan80(struct ieee80211_node *ni) |
| 579 | { |
| 580 | 	uint8_t cap_chan_width, op_chan_width; |
| 581 | |
| 582 | 	if (!ieee80211_node_supports_vht(ni)) |
| 583 | 		return 0; |
| 584 | |
| 585 | 	cap_chan_width = (ni->ni_vhtcaps & IEEE80211_VHTCAP_CHAN_WIDTH_MASK) >> |
| 586 | 	 IEEE80211_VHTCAP_CHAN_WIDTH_SHIFT; |
| 587 | 	if (cap_chan_width != IEEE80211_VHTCAP_CHAN_WIDTH_80 &&	 |
| 588 | 	 cap_chan_width != IEEE80211_VHTCAP_CHAN_WIDTH_160 &&	 |
| 589 | 	 cap_chan_width != IEEE80211_VHTCAP_CHAN_WIDTH_160_8080) |
| 590 | 		return 0; |
| 591 | |
| 592 | 	op_chan_width = (ni->ni_vht_chan_width & |
| 593 | 	 IEEE80211_VHTOP0_CHAN_WIDTH_MASK) >> |
| 594 | 	 IEEE80211_VHTOP0_CHAN_WIDTH_SHIFT; |
| 595 | |
| 596 | 	return (op_chan_width == IEEE80211_VHTOP0_CHAN_WIDTH_80 || |
| 597 | 	 op_chan_width == IEEE80211_VHTOP0_CHAN_WIDTH_160 || |
| 598 | 	 op_chan_width == IEEE80211_VHTOP0_CHAN_WIDTH_8080); |
| 599 | } |
| 600 | |
| 601 | /* Check if the peer can receive frames sent on a 160 MHz channel. */ |
| 602 | static inline int |
| 603 | ieee80211_node_supports_vht_chan160(struct ieee80211_node *ni) |
| 604 | { |
| 605 | 	uint8_t cap_chan_width, op_chan_width; |
| 606 | |
| 607 | 	if (!ieee80211_node_supports_vht(ni)) |
| 608 | 		return 0; |
| 609 | |
| 610 | 	cap_chan_width = (ni->ni_vhtcaps & IEEE80211_VHTCAP_CHAN_WIDTH_MASK) >> |
| 611 | 	 IEEE80211_VHTCAP_CHAN_WIDTH_SHIFT; |
| 612 | 	if (cap_chan_width != IEEE80211_VHTCAP_CHAN_WIDTH_160 && |
| 613 | 	 cap_chan_width != IEEE80211_VHTCAP_CHAN_WIDTH_160_8080 && |
| 614 | 	 ((ni->ni_vhtcaps & IEEE80211_VHTCAP_EXT_NSS_BW_MASK) == 0 || |
| 615 | 	 (ni->ni_vht_tx_max_lgi_mbit_s & |
| 616 | 	 IEEE80211_VHT_EXT_NSS_BW_CAPABLE) == 0)) |
| 617 | 		return 0; |
| 618 | |
| 619 | 	op_chan_width = (ni->ni_vht_chan_width & |
| 620 | 	 IEEE80211_VHTOP0_CHAN_WIDTH_MASK) >> |
| 621 | 	 IEEE80211_VHTOP0_CHAN_WIDTH_SHIFT; |
| 622 | |
| 623 | 	return (op_chan_width == IEEE80211_VHTOP0_CHAN_WIDTH_160); |
| 624 | } |
| 625 | |
| 626 | /* |
| 627 | * Check if the peer supports HE. |
| 628 | * Require a HE capabilities IE and support for HE MCS with a single |
| 629 | * spatial stream. |
| 630 | */ |
| 631 | static inline int |
| 632 | ieee80211_node_supports_he(struct ieee80211_node *ni) |
| 633 | { |
| 634 | 	uint16_t rx_mcs; |
| 635 | |
| 636 | 	rx_mcs = (ni->ni_he_rxmcs_80 & IEEE80211_HE_MCS_FOR_SS_MASK(1)) >> |
| 637 | 	 IEEE80211_HE_MCS_FOR_SS_SHIFT(1); |
| 638 | |
| 639 | 	return ((ni->ni_flags & IEEE80211_NODE_HECAP) && |
| 640 | 	 rx_mcs != IEEE80211_HE_MCS_SS_NOT_SUPP); |
| 641 | } |
| 642 | |
| 643 | struct ieee80211com; |
| 644 | |
| 645 | typedef void ieee80211_iter_func(void *, struct ieee80211_node *); |
| 646 | |
| 647 | void ieee80211_node_attach(struct ifnet *); |
| 648 | void ieee80211_node_lateattach(struct ifnet *); |
| 649 | void ieee80211_node_detach(struct ifnet *); |
| 650 | |
| 651 | void ieee80211_begin_scan(struct ifnet *); |
| 652 | void ieee80211_next_scan(struct ifnet *); |
| 653 | void ieee80211_end_scan(struct ifnet *); |
| 654 | void ieee80211_reset_scan(struct ifnet *); |
| 655 | struct ieee80211_node *ieee80211_alloc_node(struct ieee80211com *, |
| 656 | 		const u_int8_t *); |
| 657 | struct ieee80211_node *ieee80211_dup_bss(struct ieee80211com *, |
| 658 | 		const u_int8_t *); |
| 659 | struct ieee80211_node *ieee80211_find_node(struct ieee80211com *, |
| 660 | 		const u_int8_t *); |
| 661 | void ieee80211_node_tx_ba_clear(struct ieee80211_node *, int); |
| 662 | void ieee80211_ba_del(struct ieee80211_node *); |
| 663 | struct ieee80211_node *ieee80211_find_rxnode(struct ieee80211com *, |
| 664 | 		const struct ieee80211_frame *); |
| 665 | struct ieee80211_node *ieee80211_find_txnode(struct ieee80211com *, |
| 666 | 		const u_int8_t *); |
| 667 | void ieee80211_release_node(struct ieee80211com *, |
| 668 | 		struct ieee80211_node *); |
| 669 | void ieee80211_node_cleanup(struct ieee80211com *, struct ieee80211_node *); |
| 670 | void ieee80211_free_allnodes(struct ieee80211com *, int); |
| 671 | void ieee80211_iterate_nodes(struct ieee80211com *, |
| 672 | 		ieee80211_iter_func *, void *); |
| 673 | void ieee80211_clean_cached(struct ieee80211com *); |
| 674 | void ieee80211_clean_nodes(struct ieee80211com *, int); |
| 675 | void ieee80211_setup_htcaps(struct ieee80211_node *, const uint8_t *, |
| 676 | uint8_t); |
| 677 | void ieee80211_clear_htcaps(struct ieee80211_node *); |
| 678 | int ieee80211_setup_htop(struct ieee80211_node *, const uint8_t *, |
| 679 | uint8_t, int); |
| 680 | void ieee80211_setup_vhtcaps(struct ieee80211_node *, const uint8_t *, |
| 681 | uint8_t); |
| 682 | void ieee80211_clear_vhtcaps(struct ieee80211_node *); |
| 683 | int ieee80211_setup_vhtop(struct ieee80211_node *, const uint8_t *, |
| 684 | uint8_t, int); |
| 685 | void ieee80211_setup_hecaps(struct ieee80211_node *, const uint8_t *, |
| 686 | uint8_t); |
| 687 | void ieee80211_clear_hecaps(struct ieee80211_node *); |
| 688 | int ieee80211_setup_heop(struct ieee80211_node *, const uint8_t *, |
| 689 | uint8_t, int); |
| 690 | int ieee80211_setup_rates(struct ieee80211com *, |
| 691 | 	 struct ieee80211_node *, const u_int8_t *, const u_int8_t *, int); |
| 692 | enum ieee80211_phymode ieee80211_node_abg_mode(struct ieee80211com *, |
| 693 | 	 struct ieee80211_node *); |
| 694 | void ieee80211_node_trigger_addba_req(struct ieee80211_node *, int); |
| 695 | void ieee80211_count_longslotsta(void *, struct ieee80211_node *); |
| 696 | void ieee80211_count_nonerpsta(void *, struct ieee80211_node *); |
| 697 | void ieee80211_count_pssta(void *, struct ieee80211_node *); |
| 698 | void ieee80211_count_rekeysta(void *, struct ieee80211_node *); |
| 699 | void ieee80211_node_join(struct ieee80211com *, |
| 700 | 		struct ieee80211_node *, int); |
| 701 | void ieee80211_node_leave(struct ieee80211com *, |
| 702 | 		struct ieee80211_node *); |
| 703 | int ieee80211_match_bss(struct ieee80211com *, struct ieee80211_node *, int); |
| 704 | void ieee80211_node_switch_bss(struct ieee80211com *, struct ieee80211_node *); |
| 705 | void ieee80211_node_tx_stopped(struct ieee80211com *, struct ieee80211_node *); |
| 706 | struct ieee80211_node *ieee80211_node_choose_bss(struct ieee80211com *, int, |
| 707 | 		struct ieee80211_node **); |
| 708 | void ieee80211_node_join_bss(struct ieee80211com *, struct ieee80211_node *); |
| 709 | void ieee80211_create_ibss(struct ieee80211com* , |
| 710 | 		struct ieee80211_channel *); |
| 711 | void ieee80211_notify_dtim(struct ieee80211com *); |
| 712 | void ieee80211_set_tim(struct ieee80211com *, int, int); |
| 713 | void ieee80211_free_node(struct ieee80211com *, struct ieee80211_node *); |
| 714 | |
| 715 | int ieee80211_node_cmp(const struct ieee80211_node *, |
| 716 | 		const struct ieee80211_node *); |
| 717 | int ieee80211_ess_cmp(const struct ieee80211_ess_rbt *, |
| 718 | 		const struct ieee80211_ess_rbt *); |
| 719 | RBT_PROTOTYPE(ieee80211_tree, ieee80211_node, ni_node, ieee80211_node_cmp); |
| 720 | RBT_PROTOTYPE(ieee80211_ess_tree, ieee80211_ess_rbt, ess_rbt, ieee80211_ess_cmp); |
| 721 | |
| 722 | #endif /* _NET80211_IEEE80211_NODE_H_ */ |