xref: /freebsd/sys/compat/linuxkpi/common/include/linux/ieee80211.h (revision c5f3a7f62217f20f0c7b2c4fc3fb2646336b0802)
1 /*-
2  * Copyright (c) 2020-2024 The FreeBSD Foundation
3  *
4  * This software was developed by Björn Zeeb under sponsorship from
5  * the FreeBSD Foundation.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 #ifndef	_LINUXKPI_LINUX_IEEE80211_H
30 #define	_LINUXKPI_LINUX_IEEE80211_H
31 
32 #include <sys/types.h>
33 #include <net80211/ieee80211.h>
34 
35 #include <asm/unaligned.h>
36 #include <linux/kernel.h>
37 #include <linux/bitops.h>
38 #include <linux/if_ether.h>
39 
40 /* linux_80211.c */
41 extern int linuxkpi_debug_80211;
42 #ifndef	D80211_TODO
43 #define	D80211_TODO		0x1
44 #endif
45 #define	TODO(...)		if (linuxkpi_debug_80211 & D80211_TODO)	\
46     printf("%s:%d: XXX LKPI80211 TODO\n", __func__, __LINE__)
47 
48 
49 /* 9.4.2.55 Management MIC element (CMAC-256, GMAC-128, and GMAC-256). */
50 struct ieee80211_mmie_16 {
51 	uint8_t		element_id;
52 	uint8_t		length;
53 	uint16_t	key_id;
54 	uint8_t		ipn[6];
55 	uint8_t		mic[16];
56 };
57 
58 #define	IEEE80211_CCMP_HDR_LEN			8	/* 802.11i .. net80211 comment */
59 #define	IEEE80211_CCMP_PN_LEN			6
60 #define	IEEE80211_CCMP_MIC_LEN			8	/* || 16 */
61 #define	IEEE80211_CCMP_256_HDR_LEN		8
62 #define	IEEE80211_CCMP_256_MIC_LEN		16
63 #define	IEEE80211_GCMP_HDR_LEN			8
64 #define	IEEE80211_GCMP_MIC_LEN			16
65 #define	IEEE80211_GCMP_PN_LEN			6
66 #define	IEEE80211_GMAC_PN_LEN			6
67 
68 #define	IEEE80211_MAX_PN_LEN			16
69 
70 #define	IEEE80211_INVAL_HW_QUEUE		((uint8_t)-1)
71 
72 #define	IEEE80211_MAX_AMPDU_BUF_HT		IEEE80211_AGGR_BAWMAX
73 #define	IEEE80211_MAX_AMPDU_BUF_HE		256
74 #define	IEEE80211_MAX_AMPDU_BUF_EHT		1024
75 
76 #define	IEEE80211_MAX_FRAME_LEN			2352
77 #define	IEEE80211_MAX_DATA_LEN			(2300 + IEEE80211_CRC_LEN)
78 
79 #define	IEEE80211_MAX_MPDU_LEN_HT_BA		4095	/* 9.3.2.1 Format of Data frames; non-VHT non-DMG STA */
80 #define	IEEE80211_MAX_MPDU_LEN_HT_3839		3839
81 #define	IEEE80211_MAX_MPDU_LEN_HT_7935		7935
82 #define	IEEE80211_MAX_MPDU_LEN_VHT_3895		3895
83 #define	IEEE80211_MAX_MPDU_LEN_VHT_7991		7991
84 #define	IEEE80211_MAX_MPDU_LEN_VHT_11454	11454
85 
86 #define	IEEE80211_MAX_RTS_THRESHOLD		2346	/* net80211::IEEE80211_RTS_MAX */
87 
88 #define	IEEE80211_MIN_ACTION_SIZE		23	/* ? */
89 
90 /* Wi-Fi Peer-to-Peer (P2P) Technical Specification */
91 #define	IEEE80211_P2P_OPPPS_CTWINDOW_MASK	0x7f
92 #define	IEEE80211_P2P_OPPPS_ENABLE_BIT		BIT(7)
93 
94 /* 802.11-2016, 9.2.4.5.1, Table 9-6 QoS Control Field */
95 #define	IEEE80211_QOS_CTL_TAG1D_MASK		0x0007
96 #define	IEEE80211_QOS_CTL_TID_MASK		IEEE80211_QOS_TID
97 #define	IEEE80211_QOS_CTL_EOSP			0x0010
98 #define	IEEE80211_QOS_CTL_A_MSDU_PRESENT	0x0080
99 #define	IEEE80211_QOS_CTL_ACK_POLICY_MASK	0x0060
100 #define	IEEE80211_QOS_CTL_ACK_POLICY_NOACK	0x0020
101 #define	IEEE80211_QOS_CTL_MESH_CONTROL_PRESENT	0x0100
102 
103 #define	IEEE80211_RATE_SHORT_PREAMBLE		BIT(0)
104 
105 enum ieee80211_rate_control_changed_flags {
106 	IEEE80211_RC_BW_CHANGED			= BIT(0),
107 	IEEE80211_RC_NSS_CHANGED		= BIT(1),
108 	IEEE80211_RC_SUPP_RATES_CHANGED		= BIT(2),
109 	IEEE80211_RC_SMPS_CHANGED		= BIT(3),
110 };
111 
112 #define	IEEE80211_SCTL_FRAG			IEEE80211_SEQ_FRAG_MASK
113 #define	IEEE80211_SCTL_SEQ			IEEE80211_SEQ_SEQ_MASK
114 
115 #define	IEEE80211_TKIP_ICV_LEN			4
116 #define	IEEE80211_TKIP_IV_LEN			8	/* WEP + KID + EXT */
117 
118 #define	IEEE80211_VHT_EXT_NSS_BW_CAPABLE	(1 << 13)	/* assigned to tx_highest */
119 
120 #define	IEEE80211_VHT_MAX_AMPDU_1024K		7	/* 9.4.2.56.3 A-MPDU Parameters field, Table 9-163 */
121 
122 #define	IEEE80211_WEP_IV_LEN			3	/* net80211: IEEE80211_WEP_IVLEN */
123 #define	IEEE80211_WEP_ICV_LEN			4
124 
125 #define	WLAN_AUTH_OPEN				__LINE__ /* TODO FIXME brcmfmac */
126 #define	WLAN_CAPABILITY_IBSS			__LINE__ /* TODO FIXME no longer used? */
127 #define	WLAN_CAPABILITY_SHORT_PREAMBLE		__LINE__ /* TODO FIXME brcmfmac */
128 #define	WLAN_CAPABILITY_SHORT_SLOT_TIME		__LINE__ /* TODO FIXME brcmfmac */
129 
130 enum wlan_ht_cap_sm_ps {
131 	WLAN_HT_CAP_SM_PS_STATIC		= 0,
132 	WLAN_HT_CAP_SM_PS_DYNAMIC,
133 	WLAN_HT_CAP_SM_PS_INVALID,
134 	WLAN_HT_CAP_SM_PS_DISABLED,
135 };
136 
137 #define	WLAN_MAX_KEY_LEN			32
138 #define	WLAN_PMKID_LEN				16
139 #define	WLAN_PMK_LEN_SUITE_B_192		48
140 
141 #define	WLAN_KEY_LEN_WEP40			5
142 #define	WLAN_KEY_LEN_WEP104			13
143 #define	WLAN_KEY_LEN_TKIP			32
144 #define	WLAN_KEY_LEN_CCMP			16
145 #define	WLAN_KEY_LEN_GCMP			16
146 #define	WLAN_KEY_LEN_AES_CMAC			16
147 #define	WLAN_KEY_LEN_GCMP_256			32
148 #define	WLAN_KEY_LEN_BIP_CMAC_256		32
149 #define	WLAN_KEY_LEN_BIP_GMAC_128		16
150 #define	WLAN_KEY_LEN_BIP_GMAC_256		32
151 
152 /* 802.11-2020, 9.4.2.55.3, Table 9-185 Subfields of the A-MPDU Parameters field */
153 enum ieee80211_min_mpdu_start_spacing {
154 	IEEE80211_HT_MPDU_DENSITY_NONE		= 0,
155 #if 0
156 	IEEE80211_HT_MPDU_DENSITY_XXX		= 1,	/* 1/4 us */
157 #endif
158 	IEEE80211_HT_MPDU_DENSITY_0_5		= 2,	/* 1/2 us */
159 	IEEE80211_HT_MPDU_DENSITY_1		= 3,	/* 1 us */
160 	IEEE80211_HT_MPDU_DENSITY_2		= 4,	/* 2 us */
161 	IEEE80211_HT_MPDU_DENSITY_4		= 5,	/* 4us */
162 	IEEE80211_HT_MPDU_DENSITY_8		= 6,	/* 8us */
163 	IEEE80211_HT_MPDU_DENSITY_16		= 7, 	/* 16us */
164 };
165 
166 /* 9.4.2.57, Table 9-168, HT Operation element fields and subfields */
167 #define	IEEE80211_HT_STBC_PARAM_DUAL_CTS_PROT	0x0080	/* B24.. */
168 
169 #define	IEEE80211_FCTL_FTYPE			IEEE80211_FC0_TYPE_MASK
170 #define	IEEE80211_FCTL_STYPE			IEEE80211_FC0_SUBTYPE_MASK
171 #define	IEEE80211_FCTL_ORDER			(IEEE80211_FC1_ORDER << 8)
172 #define	IEEE80211_FCTL_PROTECTED		(IEEE80211_FC1_PROTECTED << 8)
173 #define	IEEE80211_FCTL_FROMDS			(IEEE80211_FC1_DIR_FROMDS << 8)
174 #define	IEEE80211_FCTL_TODS			(IEEE80211_FC1_DIR_TODS << 8)
175 #define	IEEE80211_FCTL_MOREFRAGS		(IEEE80211_FC1_MORE_FRAG << 8)
176 #define	IEEE80211_FCTL_PM			(IEEE80211_FC1_PWR_MGT << 8)
177 
178 #define	IEEE80211_FTYPE_MGMT			IEEE80211_FC0_TYPE_MGT
179 #define	IEEE80211_FTYPE_CTL			IEEE80211_FC0_TYPE_CTL
180 #define	IEEE80211_FTYPE_DATA			IEEE80211_FC0_TYPE_DATA
181 
182 #define	IEEE80211_STYPE_ASSOC_REQ		IEEE80211_FC0_SUBTYPE_ASSOC_REQ
183 #define	IEEE80211_STYPE_REASSOC_REQ		IEEE80211_FC0_SUBTYPE_REASSOC_REQ
184 #define	IEEE80211_STYPE_PROBE_REQ		IEEE80211_FC0_SUBTYPE_PROBE_REQ
185 #define	IEEE80211_STYPE_DISASSOC		IEEE80211_FC0_SUBTYPE_DISASSOC
186 #define	IEEE80211_STYPE_AUTH			IEEE80211_FC0_SUBTYPE_AUTH
187 #define	IEEE80211_STYPE_DEAUTH			IEEE80211_FC0_SUBTYPE_DEAUTH
188 #define	IEEE80211_STYPE_CTS			IEEE80211_FC0_SUBTYPE_CTS
189 #define	IEEE80211_STYPE_RTS			IEEE80211_FC0_SUBTYPE_RTS
190 #define	IEEE80211_STYPE_ACTION			IEEE80211_FC0_SUBTYPE_ACTION
191 #define	IEEE80211_STYPE_DATA			IEEE80211_FC0_SUBTYPE_DATA
192 #define	IEEE80211_STYPE_QOS_DATA		IEEE80211_FC0_SUBTYPE_QOS_DATA
193 #define	IEEE80211_STYPE_QOS_NULLFUNC		IEEE80211_FC0_SUBTYPE_QOS_NULL
194 #define	IEEE80211_STYPE_QOS_CFACK		0xd0	/* XXX-BZ reserved? */
195 
196 #define	IEEE80211_NUM_ACS			4	/* net8021::WME_NUM_AC */
197 
198 #define	IEEE80211_MAX_SSID_LEN			32	/* 9.4.2.2 SSID element, net80211: IEEE80211_NWID_LEN */
199 
200 
201 /* Figure 9-27, BAR Control field */
202 #define	IEEE80211_BAR_CTRL_TID_INFO_MASK	0xf000
203 #define	IEEE80211_BAR_CTRL_TID_INFO_SHIFT	12
204 
205 #define	IEEE80211_PPE_THRES_INFO_PPET_SIZE		1 /* TODO FIXME ax? */
206 #define	IEEE80211_PPE_THRES_NSS_MASK			2 /* TODO FIXME ax? */
207 #define	IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS	3 /* TODO FIXME ax? */
208 #define	IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK	8 /* TODO FIXME ax? */
209 #define	IEEE80211_HE_PPE_THRES_INFO_HEADER_SIZE		16	/* TODO FIXME ax? */
210 
211 /* 802.11-2012, Table 8-130-HT Operation element fields and subfields, HT Protection */
212 #define	IEEE80211_HT_OP_MODE_PROTECTION			IEEE80211_HTINFO_OPMODE		/* Mask. */
213 #define	IEEE80211_HT_OP_MODE_PROTECTION_NONE		IEEE80211_HTINFO_OPMODE_PURE	/* No protection */
214 #define	IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER	IEEE80211_HTINFO_OPMODE_PROTOPT	/* Nonmember protection */
215 #define	IEEE80211_HT_OP_MODE_PROTECTION_20MHZ		IEEE80211_HTINFO_OPMODE_HT20PR	/* 20 MHz protection */
216 #define	IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED	IEEE80211_HTINFO_OPMODE_MIXED	/* Non-HT mixed */
217 
218 
219 /* 9.6.13.1, Table 9-342 TDLS Action field values. */
220 enum ieee80211_tdls_action_code {
221 	WLAN_TDLS_SETUP_REQUEST			= 0,
222 	WLAN_TDLS_SETUP_RESPONSE		= 1,
223 	WLAN_TDLS_SETUP_CONFIRM			= 2,
224 	WLAN_TDLS_TEARDOWN			= 3,
225 	WLAN_TDLS_PEER_TRAFFIC_INDICATION	= 4,
226 	WLAN_TDLS_CHANNEL_SWITCH_REQUEST	= 5,
227 	WLAN_TDLS_CHANNEL_SWITCH_RESPONSE	= 6,
228 	WLAN_TDLS_PEER_PSM_REQUEST		= 7,
229 	WLAN_TDLS_PEER_PSM_RESPONSE		= 8,
230 	WLAN_TDLS_PEER_TRAFFIC_RESPONSE		= 9,
231 	WLAN_TDLS_DISCOVERY_REQUEST		= 10,
232 	/* 11-255 reserved */
233 };
234 
235 /* 802.11-2020 9.4.2.26, Table 9-153. Extended Capabilities field. */
236 /* This is split up into octets CAPA1 = octet 1, ... */
237 #define	WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING			BIT(2  % 8)
238 #define	WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT			BIT(22 % 8)
239 #define	WLAN_EXT_CAPA3_TIMING_MEASUREMENT_SUPPORT		BIT(23 % 8)
240 #define	WLAN_EXT_CAPA8_OPMODE_NOTIF				BIT(62 % 8)
241 #define	WLAN_EXT_CAPA8_MAX_MSDU_IN_AMSDU_LSB			BIT(63 % 8)
242 #define	WLAN_EXT_CAPA9_MAX_MSDU_IN_AMSDU_MSB			BIT(64 % 8)
243 #define	WLAN_EXT_CAPA10_TWT_REQUESTER_SUPPORT			BIT(77 % 8)
244 #define	WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT			BIT(78 % 8)
245 #define	WLAN_EXT_CAPA10_OBSS_NARROW_BW_RU_TOLERANCE_SUPPORT	BIT(79 % 8)
246 
247 #define	WLAN_EXT_CAPA11_EMA_SUPPORT				0x00	/* XXX TODO FIXME */
248 
249 
250 /* iwlwifi/mvm/utils:: for (ac = IEEE80211_AC_VO; ac <= IEEE80211_AC_VI; ac++) */
251 /* Would be so much easier if we'd define constants to the same. */
252 enum ieee80211_ac_numbers {
253 	IEEE80211_AC_VO = 0,			/* net80211::WME_AC_VO */
254 	IEEE80211_AC_VI = 1,			/* net80211::WME_AC_VI */
255 	IEEE80211_AC_BE = 2,			/* net80211::WME_AC_BE */
256 	IEEE80211_AC_BK = 3,			/* net80211::WME_AC_BK */
257 };
258 
259 #define	IEEE80211_MAX_QUEUES			16	/* Assume IEEE80211_NUM_TIDS for the moment. */
260 
261 #define	IEEE80211_WMM_IE_STA_QOSINFO_AC_VO	1
262 #define	IEEE80211_WMM_IE_STA_QOSINFO_AC_VI	2
263 #define	IEEE80211_WMM_IE_STA_QOSINFO_AC_BK	4
264 #define	IEEE80211_WMM_IE_STA_QOSINFO_AC_BE	8
265 #define	IEEE80211_WMM_IE_STA_QOSINFO_SP_ALL	0xf
266 
267 
268 /* Define the LinuxKPI names directly to the net80211 ones. */
269 #define	IEEE80211_HT_CAP_LDPC_CODING		IEEE80211_HTCAP_LDPC
270 #define	IEEE80211_HT_CAP_SUP_WIDTH_20_40	IEEE80211_HTCAP_CHWIDTH40
271 #define	IEEE80211_HT_CAP_SM_PS			IEEE80211_HTCAP_SMPS
272 #define	IEEE80211_HT_CAP_SM_PS_SHIFT		2
273 #define	IEEE80211_HT_CAP_GRN_FLD		IEEE80211_HTCAP_GREENFIELD
274 #define	IEEE80211_HT_CAP_SGI_20			IEEE80211_HTCAP_SHORTGI20
275 #define	IEEE80211_HT_CAP_SGI_40			IEEE80211_HTCAP_SHORTGI40
276 #define	IEEE80211_HT_CAP_TX_STBC		IEEE80211_HTCAP_TXSTBC
277 #define	IEEE80211_HT_CAP_RX_STBC		IEEE80211_HTCAP_RXSTBC
278 #define	IEEE80211_HT_CAP_RX_STBC_SHIFT		IEEE80211_HTCAP_RXSTBC_S
279 #define	IEEE80211_HT_CAP_MAX_AMSDU		IEEE80211_HTCAP_MAXAMSDU
280 #define	IEEE80211_HT_CAP_DSSSCCK40		IEEE80211_HTCAP_DSSSCCK40
281 #define	IEEE80211_HT_CAP_LSIG_TXOP_PROT		IEEE80211_HTCAP_LSIGTXOPPROT
282 
283 #define	IEEE80211_HT_MCS_TX_DEFINED		0x0001
284 #define	IEEE80211_HT_MCS_TX_RX_DIFF		0x0002
285 #define	IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT	2
286 #define	IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK	0x0c
287 #define	IEEE80211_HT_MCS_RX_HIGHEST_MASK	0x3ff
288 #define	IEEE80211_HT_MCS_MASK_LEN		10
289 
290 #define	IEEE80211_MLD_MAX_NUM_LINKS		15
291 #define	IEEE80211_MLD_CAP_OP_TID_TO_LINK_MAP_NEG_SUPP		0x0060
292 #define	IEEE80211_MLD_CAP_OP_TID_TO_LINK_MAP_NEG_SUPP_SAME	1
293 
294 struct ieee80211_mcs_info {
295 	uint8_t		rx_mask[IEEE80211_HT_MCS_MASK_LEN];
296 	uint16_t	rx_highest;
297 	uint8_t		tx_params;
298 	uint8_t		__reserved[3];
299 };
300 
301 /* 802.11-2020, 9.4.2.55.1 HT Capabilities element structure */
302 struct ieee80211_ht_cap {
303 	uint16_t				cap_info;
304 	uint8_t					ampdu_params_info;
305 	struct ieee80211_mcs_info		mcs;
306 	uint16_t				extended_ht_cap_info;
307 	uint32_t				tx_BF_cap_info;
308 	uint8_t					antenna_selection_info;
309 };
310 
311 #define	IEEE80211_HT_MAX_AMPDU_FACTOR		13
312 #define	IEEE80211_HE_HT_MAX_AMPDU_FACTOR	16
313 #define	IEEE80211_HE_VHT_MAX_AMPDU_FACTOR	20
314 #define	IEEE80211_HE_6GHZ_MAX_AMPDU_FACTOR	13
315 
316 enum ieee80211_ht_max_ampdu_len {
317 	IEEE80211_HT_MAX_AMPDU_64K
318 };
319 
320 enum ieee80211_ampdu_mlme_action {
321 	IEEE80211_AMPDU_RX_START,
322 	IEEE80211_AMPDU_RX_STOP,
323 	IEEE80211_AMPDU_TX_OPERATIONAL,
324 	IEEE80211_AMPDU_TX_START,
325 	IEEE80211_AMPDU_TX_STOP_CONT,
326 	IEEE80211_AMPDU_TX_STOP_FLUSH,
327 	IEEE80211_AMPDU_TX_STOP_FLUSH_CONT
328 };
329 
330 #define	IEEE80211_AMPDU_TX_START_IMMEDIATE	1
331 #define	IEEE80211_AMPDU_TX_START_DELAY_ADDBA	2
332 
333 enum ieee80211_chanctx_switch_mode {
334 	CHANCTX_SWMODE_REASSIGN_VIF,
335 	CHANCTX_SWMODE_SWAP_CONTEXTS,
336 };
337 
338 enum ieee80211_chanctx_change_flags {
339 	IEEE80211_CHANCTX_CHANGE_MIN_WIDTH	= BIT(0),
340 	IEEE80211_CHANCTX_CHANGE_RADAR		= BIT(1),
341 	IEEE80211_CHANCTX_CHANGE_RX_CHAINS	= BIT(2),
342 	IEEE80211_CHANCTX_CHANGE_WIDTH		= BIT(3),
343 	IEEE80211_CHANCTX_CHANGE_CHANNEL	= BIT(4),
344 	IEEE80211_CHANCTX_CHANGE_PUNCTURING	= BIT(5),
345 };
346 
347 enum ieee80211_frame_release_type {
348 	IEEE80211_FRAME_RELEASE_PSPOLL		= 1,
349 	IEEE80211_FRAME_RELEASE_UAPSD		= 2,
350 };
351 
352 enum ieee80211_p2p_attr_ids {
353 	IEEE80211_P2P_ATTR_DEVICE_ID,
354 	IEEE80211_P2P_ATTR_DEVICE_INFO,
355 	IEEE80211_P2P_ATTR_GROUP_ID,
356 	IEEE80211_P2P_ATTR_LISTEN_CHANNEL,
357 	IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
358 };
359 
360 enum ieee80211_reconfig_type {
361 	IEEE80211_RECONFIG_TYPE_RESTART,
362 	IEEE80211_RECONFIG_TYPE_SUSPEND,
363 };
364 
365 enum ieee80211_roc_type {
366 	IEEE80211_ROC_TYPE_MGMT_TX,
367 	IEEE80211_ROC_TYPE_NORMAL,
368 };
369 
370 enum ieee80211_smps_mode {
371 	IEEE80211_SMPS_OFF,
372 	IEEE80211_SMPS_STATIC,
373 	IEEE80211_SMPS_DYNAMIC,
374 	IEEE80211_SMPS_AUTOMATIC,
375 	IEEE80211_SMPS_NUM_MODES,
376 };
377 
378 /* net80211::IEEE80211_S_* different but represents the state machine. */
379 /* Note: order here is important! */
380 enum ieee80211_sta_state {
381 	IEEE80211_STA_NOTEXIST		= 0,
382 	IEEE80211_STA_NONE		= 1,
383 	IEEE80211_STA_AUTH		= 2,
384 	IEEE80211_STA_ASSOC		= 3,
385 	IEEE80211_STA_AUTHORIZED	= 4,	/* 802.1x */
386 };
387 
388 enum ieee80211_sta_rx_bw {
389 	IEEE80211_STA_RX_BW_20,
390 	IEEE80211_STA_RX_BW_40,
391 	IEEE80211_STA_RX_BW_80,
392 	IEEE80211_STA_RX_BW_160,
393 	IEEE80211_STA_RX_BW_320,
394 };
395 
396 enum ieee80211_tx_info_flags {
397 	/* XXX TODO .. right shift numbers - not sure where that came from? */
398 	IEEE80211_TX_CTL_AMPDU			= BIT(0),
399 	IEEE80211_TX_CTL_ASSIGN_SEQ		= BIT(1),
400 	IEEE80211_TX_CTL_NO_ACK			= BIT(2),
401 	IEEE80211_TX_CTL_SEND_AFTER_DTIM	= BIT(3),
402 	IEEE80211_TX_CTL_TX_OFFCHAN		= BIT(4),
403 	IEEE80211_TX_CTL_REQ_TX_STATUS		= BIT(5),
404 	IEEE80211_TX_STATUS_EOSP		= BIT(6),
405 	IEEE80211_TX_STAT_ACK			= BIT(7),
406 	IEEE80211_TX_STAT_AMPDU			= BIT(8),
407 	IEEE80211_TX_STAT_AMPDU_NO_BACK		= BIT(9),
408 	IEEE80211_TX_STAT_TX_FILTERED		= BIT(10),
409 	IEEE80211_TX_STAT_NOACK_TRANSMITTED	= BIT(11),
410 	IEEE80211_TX_CTL_FIRST_FRAGMENT		= BIT(12),
411 	IEEE80211_TX_INTFL_DONT_ENCRYPT		= BIT(13),
412 	IEEE80211_TX_CTL_NO_CCK_RATE		= BIT(14),
413 	IEEE80211_TX_CTL_INJECTED		= BIT(15),
414 	IEEE80211_TX_CTL_HW_80211_ENCAP		= BIT(16),
415 	IEEE80211_TX_CTL_USE_MINRATE		= BIT(17),
416 	IEEE80211_TX_CTL_RATE_CTRL_PROBE	= BIT(18),
417 	IEEE80211_TX_CTL_LDPC			= BIT(19),
418 	IEEE80211_TX_CTL_STBC			= BIT(20),
419 };
420 
421 enum ieee80211_tx_status_flags {
422 	IEEE80211_TX_STATUS_ACK_SIGNAL_VALID	= BIT(0),
423 };
424 
425 enum ieee80211_tx_control_flags {
426 	/* XXX TODO .. right shift numbers */
427 	IEEE80211_TX_CTRL_PORT_CTRL_PROTO	= BIT(0),
428 	IEEE80211_TX_CTRL_PS_RESPONSE		= BIT(1),
429 	IEEE80211_TX_CTRL_RATE_INJECT		= BIT(2),
430 	IEEE80211_TX_CTRL_MLO_LINK		= 0xF0000000,	/* This is IEEE80211_LINK_UNSPECIFIED on the high bits. */
431 };
432 
433 enum ieee80211_tx_rate_flags {
434 	/* XXX TODO .. right shift numbers */
435 	IEEE80211_TX_RC_40_MHZ_WIDTH		= BIT(0),
436 	IEEE80211_TX_RC_80_MHZ_WIDTH		= BIT(1),
437 	IEEE80211_TX_RC_160_MHZ_WIDTH		= BIT(2),
438 	IEEE80211_TX_RC_GREEN_FIELD		= BIT(3),
439 	IEEE80211_TX_RC_MCS			= BIT(4),
440 	IEEE80211_TX_RC_SHORT_GI		= BIT(5),
441 	IEEE80211_TX_RC_VHT_MCS			= BIT(6),
442 	IEEE80211_TX_RC_USE_SHORT_PREAMBLE	= BIT(7),
443 };
444 
445 #define	IEEE80211_RNR_TBTT_PARAMS_PSD_RESERVED	-128
446 
447 #define	IEEE80211_HT_CTL_LEN	4
448 
449 struct ieee80211_hdr {		/* net80211::ieee80211_frame_addr4 */
450         __le16		frame_control;
451         __le16		duration_id;
452 	uint8_t		addr1[ETH_ALEN];
453 	uint8_t		addr2[ETH_ALEN];
454 	uint8_t		addr3[ETH_ALEN];
455 	__le16		seq_ctrl;
456 	uint8_t		addr4[ETH_ALEN];
457 };
458 
459 struct ieee80211_hdr_3addr {	/* net80211::ieee80211_frame */
460         __le16		frame_control;
461         __le16		duration_id;
462 	uint8_t		addr1[ETH_ALEN];
463 	uint8_t		addr2[ETH_ALEN];
464 	uint8_t		addr3[ETH_ALEN];
465 	__le16		seq_ctrl;
466 };
467 
468 struct ieee80211_qos_hdr {	/* net80211:ieee80211_qosframe */
469         __le16		frame_control;
470         __le16		duration_id;
471 	uint8_t		addr1[ETH_ALEN];
472 	uint8_t		addr2[ETH_ALEN];
473 	uint8_t		addr3[ETH_ALEN];
474 	__le16		seq_ctrl;
475 	__le16		qos_ctrl;
476 };
477 
478 struct ieee80211_vendor_ie {
479 };
480 
481 /* 802.11-2020, Table 9-359-Block Ack Action field values */
482 enum ieee80211_back {
483 	WLAN_ACTION_ADDBA_REQ		= 0,
484 };
485 
486 /* 802.11-2020, Table 9-51-Category values */
487 enum ieee80211_category {
488 	WLAN_CATEGORY_BACK		= 3,
489 };
490 
491 /* 80211-2020 9.3.3.2 Format of Management frames */
492 struct ieee80211_mgmt {
493 	__le16		frame_control;
494         __le16		duration_id;
495 	uint8_t		da[ETH_ALEN];
496 	uint8_t		sa[ETH_ALEN];
497 	uint8_t		bssid[ETH_ALEN];
498 	__le16		seq_ctrl;
499 	union {
500 		/* 9.3.3.3 Beacon frame format */
501 		struct {
502 			uint64_t	timestamp;
503 			uint16_t	beacon_int;
504 			uint16_t	capab_info;
505 			uint8_t		variable[0];
506 		} beacon;
507 		/* 9.3.3.10 Probe Request frame format */
508 		struct {
509 			uint8_t		variable[0];
510 		} probe_req;
511 		/* 9.3.3.11 Probe Response frame format */
512 		struct {
513 			uint64_t	timestamp;
514 			uint16_t	beacon_int;
515 			uint16_t	capab_info;
516 			uint8_t		variable[0];
517 		} probe_resp;
518 		/* 9.3.3.14 Action frame format */
519 		struct {
520 			/* 9.4.1.11 Action field */
521 			uint8_t		category;
522 			/* 9.6.8 Public Action details */
523 			union {
524 				/* 9.6.2.5 TPC Report frame format */
525 				struct {
526 					uint8_t spec_mgmt;
527 					uint8_t dialog_token;
528 					/* uint32_t tpc_rep_elem:: */
529 					uint8_t tpc_elem_id;
530 					uint8_t tpc_elem_length;
531 					uint8_t tpc_elem_tx_power;
532 					uint8_t tpc_elem_link_margin;
533 				} tpc_report;
534 				/* 9.6.8.33 Fine Timing Measurement frame format */
535 				struct {
536 					uint8_t	dialog_token;
537 					uint8_t	follow_up;
538 					uint8_t	tod[6];
539 					uint8_t	toa[6];
540 					uint16_t tod_error;
541 					uint16_t toa_error;
542 					uint8_t variable[0];
543 				} ftm;
544 				/* 802.11-2016, 9.6.5.2 ADDBA Request frame format */
545 				struct {
546 					uint8_t action_code;
547 					uint8_t dialog_token;
548 					uint16_t capab;
549 					uint16_t timeout;
550 					uint16_t start_seq_num;
551 					/* Optional follows... */
552 					uint8_t variable[0];
553 				} addba_req;
554 				/* XXX */
555 				struct {
556 					uint8_t dialog_token;
557 				} wnm_timing_msr;
558 			} u;
559 		} action;
560 		DECLARE_FLEX_ARRAY(uint8_t, body);
561 	} u;
562 };
563 
564 struct ieee80211_cts {		/* net80211::ieee80211_frame_cts */
565         __le16		frame_control;
566         __le16		duration;
567 	uint8_t		ra[ETH_ALEN];
568 } __packed;
569 
570 struct ieee80211_rts {		/* net80211::ieee80211_frame_rts */
571         __le16		frame_control;
572         __le16		duration;
573 	uint8_t		ra[ETH_ALEN];
574 	uint8_t		ta[ETH_ALEN];
575 } __packed;
576 
577 #define	MHZ_TO_KHZ(_f)		((_f) * 1000)
578 #define	DBI_TO_MBI(_g)		((_g) * 100)
579 #define	MBI_TO_DBI(_x)		((_x) / 100)
580 #define	DBM_TO_MBM(_g)		((_g) * 100)
581 #define	MBM_TO_DBM(_x)		((_x) / 100)
582 
583 #define	IEEE80211_SEQ_TO_SN(_seqn)	(((_seqn) & IEEE80211_SEQ_SEQ_MASK) >> \
584 					    IEEE80211_SEQ_SEQ_SHIFT)
585 #define	IEEE80211_SN_TO_SEQ(_sn)	(((_sn) << IEEE80211_SEQ_SEQ_SHIFT) & \
586 					    IEEE80211_SEQ_SEQ_MASK)
587 
588 /* Time unit (TU) to .. See net80211: IEEE80211_DUR_TU */
589 #define	TU_TO_JIFFIES(_tu)	(usecs_to_jiffies(_tu) * 1024)
590 #define	TU_TO_EXP_TIME(_tu)	(jiffies + TU_TO_JIFFIES(_tu))
591 
592 /* 9.4.2.21.1, Table 9-82. */
593 #define	IEEE80211_SPCT_MSR_RPRT_TYPE_LCI	8
594 #define	IEEE80211_SPCT_MSR_RPRT_TYPE_CIVIC	11
595 
596 /* 9.4.2.1, Table 9-77. Element IDs. */
597 enum ieee80211_eid {
598 	WLAN_EID_SSID				= 0,
599 	WLAN_EID_SUPP_RATES			= 1,
600 	WLAN_EID_DS_PARAMS			= 3,
601 	WLAN_EID_TIM				= 5,
602 	WLAN_EID_COUNTRY			= 7,	/* IEEE80211_ELEMID_COUNTRY */
603 	WLAN_EID_REQUEST			= 10,
604 	WLAN_EID_CHANNEL_SWITCH			= 37,
605 	WLAN_EID_MEASURE_REPORT			= 39,
606 	WLAN_EID_HT_CAPABILITY			= 45,	/* IEEE80211_ELEMID_HTCAP */
607 	WLAN_EID_RSN				= 48,	/* IEEE80211_ELEMID_RSN */
608 	WLAN_EID_EXT_SUPP_RATES			= 50,
609 	WLAN_EID_EXT_NON_INHERITANCE		= 56,
610 	WLAN_EID_EXT_CHANSWITCH_ANN		= 60,
611 	WLAN_EID_MULTIPLE_BSSID			= 71,	/* IEEE80211_ELEMID_MULTIBSSID */
612 	WLAN_EID_MULTI_BSSID_IDX		= 85,
613 	WLAN_EID_EXT_CAPABILITY			= 127,
614 	WLAN_EID_VHT_CAPABILITY			= 191,	/* IEEE80211_ELEMID_VHT_CAP */
615 	WLAN_EID_VENDOR_SPECIFIC		= 221,	/* IEEE80211_ELEMID_VENDOR */
616 };
617 
618 enum ieee80211_eid_ext {
619 	WLAN_EID_EXT_HE_CAPABILITY		= 35,
620 };
621 
622 #define	for_each_element(_elem, _data, _len) \
623 	for (_elem = (const struct element *)(_data); \
624 	    (((const uint8_t *)(_data) + (_len) - (const uint8_t *)_elem) >= sizeof(*_elem)) && \
625 		(((const uint8_t *)(_data) + (_len) - (const uint8_t *)_elem) >= (sizeof(*_elem) + _elem->datalen)); \
626 	    _elem = (const struct element *)(_elem->data + _elem->datalen))
627 
628 #define	for_each_element_id(_elem, _eid, _data, _len) \
629 	for_each_element(_elem, _data, _len) \
630 		if (_elem->id == (_eid))
631 
632 /* 9.4.1.7, Table 9-45. Reason codes. */
633 enum ieee80211_reason_code {
634 	/* reserved				= 0, */
635 	WLAN_REASON_UNSPECIFIED			= 1,
636 	WLAN_REASON_DEAUTH_LEAVING		= 3,	/* LEAVING_NETWORK_DEAUTH */
637 	WLAN_REASON_TDLS_TEARDOWN_UNREACHABLE	= 25,
638 	WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED	= 26,
639 };
640 
641 /* 9.4.1.9, Table 9-46. Status codes. */
642 enum ieee80211_status_code {
643 	WLAN_STATUS_SUCCESS			= 0,
644 	WLAN_STATUS_AUTH_TIMEOUT		= 16,	/* REJECTED_SEQUENCE_TIMEOUT */
645 };
646 
647 /* 9.3.1.22 Trigger frame format; 80211ax-2021 */
648 struct ieee80211_trigger {
649         __le16		frame_control;
650         __le16		duration_id;
651 	uint8_t		ra[ETH_ALEN];
652 	uint8_t		ta[ETH_ALEN];
653 	__le64		common_info;		/* 8+ really */
654 	uint8_t		variable[];
655 };
656 
657 /* Table 9-29c-Trigger Type subfield encoding */
658 enum {
659 	IEEE80211_TRIGGER_TYPE_BASIC		= 0x0,
660 	IEEE80211_TRIGGER_TYPE_MU_BAR		= 0x2,
661 #if 0
662 	/* Not seen yet. */
663 	BFRP					= 0x1,
664 	MU-RTS					= 0x3,
665 	BSRP					= 0x4,
666 	GCR MU-BAR				= 0x5,
667 	BQRP					= 0x6,
668 	NFRP					= 0x7,
669 	/* 0x8..0xf reserved */
670 #endif
671 	IEEE80211_TRIGGER_TYPE_MASK		= 0xf
672 };
673 
674 #define	IEEE80211_TRIGGER_ULBW_MASK		0xc0000
675 #define	IEEE80211_TRIGGER_ULBW_20MHZ		0x0
676 #define	IEEE80211_TRIGGER_ULBW_40MHZ		0x1
677 #define	IEEE80211_TRIGGER_ULBW_80MHZ		0x2
678 #define	IEEE80211_TRIGGER_ULBW_160_80P80MHZ	0x3
679 
680 /* 802.11-2020, Figure 9-687-Control field format; 802.11ax-2021 */
681 #define	IEEE80211_TWT_CONTROL_NEG_TYPE_BROADCAST	BIT(3)
682 #define	IEEE80211_TWT_CONTROL_RX_DISABLED		BIT(4)
683 #define	IEEE80211_TWT_CONTROL_WAKE_DUR_UNIT		BIT(5)
684 
685 /* 802.11-2020, Figure 9-688-Request Type field format; 802.11ax-2021 */
686 #define	IEEE80211_TWT_REQTYPE_SETUP_CMD		(BIT(1) | BIT(2) | BIT(3))
687 #define	IEEE80211_TWT_REQTYPE_TRIGGER		BIT(4)
688 #define	IEEE80211_TWT_REQTYPE_IMPLICIT		BIT(5)
689 #define	IEEE80211_TWT_REQTYPE_FLOWTYPE		BIT(6)
690 #define	IEEE80211_TWT_REQTYPE_FLOWID		(BIT(7) | BIT(8) | BIT(9))
691 #define	IEEE80211_TWT_REQTYPE_WAKE_INT_EXP	(BIT(10) | BIT(11) | BIT(12) | BIT(13) | BIT(14))
692 #define	IEEE80211_TWT_REQTYPE_PROTECTION	BIT(15)
693 
694 struct ieee80211_twt_params {
695 	int	mantissa, min_twt_dur, twt;
696 	uint16_t				req_type;
697 };
698 
699 struct ieee80211_twt_setup {
700 	int	control;
701 	struct ieee80211_twt_params		*params;
702 };
703 
704 /* 802.11-2020, Table 9-297-TWT Setup Command field values */
705 enum ieee80211_twt_setup_cmd {
706 	TWT_SETUP_CMD_REQUEST			= 0,
707 	TWT_SETUP_CMD_SUGGEST			= 1,
708 	/* DEMAND				= 2, */
709 	/* GROUPING				= 3, */
710 	TWT_SETUP_CMD_ACCEPT			= 4,
711 	/* ALTERNATE				= 5 */
712 	TWT_SETUP_CMD_DICTATE			= 6,
713 	TWT_SETUP_CMD_REJECT			= 7,
714 };
715 
716 struct ieee80211_bssid_index {
717 	int	bssid_index;
718 };
719 
720 enum ieee80211_ap_reg_power {
721 	IEEE80211_REG_UNSET_AP,
722 	IEEE80211_REG_LPI_AP,
723 	IEEE80211_REG_SP_AP,
724 	IEEE80211_REG_VLP_AP,
725 };
726 
727 /*
728  * 802.11ax-2021, Table 9-277-Meaning of Maximum Transmit Power Count subfield
729  * if Maximum Transmit Power Interpretation subfield is 1 or 3
730  */
731 #define	IEEE80211_MAX_NUM_PWR_LEVEL		8
732 
733 /*
734  * 802.11ax-2021, Table 9-275a-Maximum Transmit Power Interpretation subfield
735  * encoding (4) * Table E-12-Regulatory Info subfield encoding in the
736  * United States (2)
737  */
738 #define	IEEE80211_TPE_MAX_IE_NUM		8
739 
740 /* 802.11ax-2021, 9.4.2.161 Transmit Power Envelope element */
741 struct ieee80211_tx_pwr_env {
742 	uint8_t		tx_power_info;
743 	uint8_t		tx_power[IEEE80211_MAX_NUM_PWR_LEVEL];
744 };
745 
746 /* 802.11ax-2021, Figure 9-617-Transmit Power Information field format */
747 /* These are field masks (3bit/3bit/2bit). */
748 #define	IEEE80211_TX_PWR_ENV_INFO_COUNT		0x07
749 #define	IEEE80211_TX_PWR_ENV_INFO_INTERPRET	0x38
750 #define	IEEE80211_TX_PWR_ENV_INFO_CATEGORY	0xc0
751 
752 /*
753  * 802.11ax-2021, Table 9-275a-Maximum Transmit Power Interpretation subfield
754  * encoding
755  */
756 enum ieee80211_tx_pwr_interpretation_subfield_enc {
757 	IEEE80211_TPE_LOCAL_EIRP,
758 	IEEE80211_TPE_LOCAL_EIRP_PSD,
759 	IEEE80211_TPE_REG_CLIENT_EIRP,
760 	IEEE80211_TPE_REG_CLIENT_EIRP_PSD,
761 };
762 
763 
764 /* net80211: IEEE80211_IS_CTL() */
765 static __inline bool
766 ieee80211_is_ctl(__le16 fc)
767 {
768 	__le16 v;
769 
770 	fc &= htole16(IEEE80211_FC0_TYPE_MASK);
771 	v = htole16(IEEE80211_FC0_TYPE_CTL);
772 
773 	return (fc == v);
774 }
775 
776 /* net80211: IEEE80211_IS_DATA() */
777 static __inline bool
778 ieee80211_is_data(__le16 fc)
779 {
780 	__le16 v;
781 
782 	fc &= htole16(IEEE80211_FC0_TYPE_MASK);
783 	v = htole16(IEEE80211_FC0_TYPE_DATA);
784 
785 	return (fc == v);
786 }
787 
788 /* net80211: IEEE80211_IS_QOSDATA() */
789 static __inline bool
790 ieee80211_is_data_qos(__le16 fc)
791 {
792 	__le16 v;
793 
794 	fc &= htole16(IEEE80211_FC0_SUBTYPE_QOS_DATA | IEEE80211_FC0_TYPE_MASK);
795 	v = htole16(IEEE80211_FC0_SUBTYPE_QOS_DATA | IEEE80211_FC0_TYPE_DATA);
796 
797 	return (fc == v);
798 }
799 
800 /* net80211: IEEE80211_IS_MGMT() */
801 static __inline bool
802 ieee80211_is_mgmt(__le16 fc)
803 {
804 	__le16 v;
805 
806 	fc &= htole16(IEEE80211_FC0_TYPE_MASK);
807 	v = htole16(IEEE80211_FC0_TYPE_MGT);
808 
809 	return (fc == v);
810 }
811 
812 
813 /* Derived from net80211::ieee80211_anyhdrsize. */
814 static __inline unsigned int
815 ieee80211_hdrlen(__le16 fc)
816 {
817 	unsigned int size;
818 
819 	if (ieee80211_is_ctl(fc)) {
820 		switch (fc & htole16(IEEE80211_FC0_SUBTYPE_MASK)) {
821 		case htole16(IEEE80211_FC0_SUBTYPE_CTS):
822 		case htole16(IEEE80211_FC0_SUBTYPE_ACK):
823 			return sizeof(struct ieee80211_frame_ack);
824 		case htole16(IEEE80211_FC0_SUBTYPE_BAR):
825 			return sizeof(struct ieee80211_frame_bar);
826 		}
827 		return (sizeof(struct ieee80211_frame_min));
828 	}
829 
830 	size = sizeof(struct ieee80211_frame);
831 	if (ieee80211_is_data(fc)) {
832 		if ((fc & htole16(IEEE80211_FC1_DIR_MASK << 8)) ==
833 		    htole16(IEEE80211_FC1_DIR_DSTODS << 8))
834 			size += IEEE80211_ADDR_LEN;
835 		if ((fc & htole16(IEEE80211_FC0_SUBTYPE_QOS_DATA |
836 		    IEEE80211_FC0_TYPE_MASK)) ==
837 		    htole16(IEEE80211_FC0_SUBTYPE_QOS_DATA |
838 		    IEEE80211_FC0_TYPE_DATA))
839 			size += sizeof(uint16_t);
840 	}
841 
842 	if (ieee80211_is_mgmt(fc)) {
843 #ifdef __notyet__
844 		printf("XXX-BZ %s: TODO? fc %#04x size %u\n",
845 		    __func__, fc, size);
846 #endif
847 		;
848 	}
849 
850 	return (size);
851 }
852 
853 static inline bool
854 ieee80211_is_trigger(__le16 fc)
855 {
856 	__le16 v;
857 
858 	fc &= htole16(IEEE80211_FC0_SUBTYPE_MASK | IEEE80211_FC0_TYPE_MASK);
859 	v = htole16(IEEE80211_FC0_SUBTYPE_TRIGGER | IEEE80211_FC0_TYPE_CTL);
860 
861 	return (fc == v);
862 }
863 
864 static __inline bool
865 ieee80211_is_action(__le16 fc)
866 {
867 	__le16 v;
868 
869 	fc &= htole16(IEEE80211_FC0_SUBTYPE_MASK | IEEE80211_FC0_TYPE_MASK);
870 	v = htole16(IEEE80211_FC0_SUBTYPE_ACTION | IEEE80211_FC0_TYPE_MGT);
871 
872 	return (fc == v);
873 }
874 
875 static __inline bool
876 ieee80211_is_probe_resp(__le16 fc)
877 {
878 	__le16 v;
879 
880 	fc &= htole16(IEEE80211_FC0_SUBTYPE_MASK | IEEE80211_FC0_TYPE_MASK);
881 	v = htole16(IEEE80211_FC0_SUBTYPE_PROBE_RESP | IEEE80211_FC0_TYPE_MGT);
882 
883 	return (fc == v);
884 }
885 
886 static __inline bool
887 ieee80211_is_auth(__le16 fc)
888 {
889 	__le16 v;
890 
891 	fc &= htole16(IEEE80211_FC0_SUBTYPE_MASK | IEEE80211_FC0_TYPE_MASK);
892 	v = htole16(IEEE80211_FC0_SUBTYPE_AUTH | IEEE80211_FC0_TYPE_MGT);
893 
894 	return (fc == v);
895 }
896 
897 static __inline bool
898 ieee80211_is_assoc_req(__le16 fc)
899 {
900 	__le16 v;
901 
902 	fc &= htole16(IEEE80211_FC0_SUBTYPE_MASK | IEEE80211_FC0_TYPE_MASK);
903 	v = htole16(IEEE80211_FC0_SUBTYPE_ASSOC_REQ | IEEE80211_FC0_TYPE_MGT);
904 
905 	return (fc == v);
906 }
907 
908 static __inline bool
909 ieee80211_is_assoc_resp(__le16 fc)
910 {
911 	__le16 v;
912 
913 	fc &= htole16(IEEE80211_FC0_SUBTYPE_MASK | IEEE80211_FC0_TYPE_MASK);
914 	v = htole16(IEEE80211_FC0_SUBTYPE_ASSOC_RESP | IEEE80211_FC0_TYPE_MGT);
915 
916 	return (fc == v);
917 }
918 
919 static __inline bool
920 ieee80211_is_reassoc_req(__le16 fc)
921 {
922 	__le16 v;
923 
924 	fc &= htole16(IEEE80211_FC0_SUBTYPE_MASK | IEEE80211_FC0_TYPE_MASK);
925 	v = htole16(IEEE80211_FC0_SUBTYPE_REASSOC_REQ | IEEE80211_FC0_TYPE_MGT);
926 
927 	return (fc == v);
928 }
929 
930 static __inline bool
931 ieee80211_is_reassoc_resp(__le16 fc)
932 {
933 	__le16 v;
934 
935 	fc &= htole16(IEEE80211_FC0_SUBTYPE_MASK | IEEE80211_FC0_TYPE_MASK);
936 	v = htole16(IEEE80211_FC0_SUBTYPE_REASSOC_RESP | IEEE80211_FC0_TYPE_MGT);
937 
938 	return (fc == v);
939 }
940 
941 static __inline bool
942 ieee80211_is_disassoc(__le16 fc)
943 {
944 	__le16 v;
945 
946 	fc &= htole16(IEEE80211_FC0_SUBTYPE_MASK | IEEE80211_FC0_TYPE_MASK);
947 	v = htole16(IEEE80211_FC0_SUBTYPE_DISASSOC | IEEE80211_FC0_TYPE_MGT);
948 
949 	return (fc == v);
950 }
951 
952 static __inline bool
953 ieee80211_is_data_present(__le16 fc)
954 {
955 	__le16 v;
956 
957 	/* If it is a data frame and NODATA is not present. */
958 	fc &= htole16(IEEE80211_FC0_TYPE_MASK | IEEE80211_FC0_SUBTYPE_NODATA);
959 	v = htole16(IEEE80211_FC0_TYPE_DATA);
960 
961 	return (fc == v);
962 }
963 
964 static __inline bool
965 ieee80211_is_deauth(__le16 fc)
966 {
967 	__le16 v;
968 
969 	fc &= htole16(IEEE80211_FC0_SUBTYPE_MASK | IEEE80211_FC0_TYPE_MASK);
970 	v = htole16(IEEE80211_FC0_SUBTYPE_DEAUTH | IEEE80211_FC0_TYPE_MGT);
971 
972 	return (fc == v);
973 }
974 
975 static __inline bool
976 ieee80211_is_beacon(__le16 fc)
977 {
978 	__le16 v;
979 
980 	/*
981 	 * For as much as I get it this comes in LE and unlike FreeBSD
982 	 * where we get the entire frame header and u8[], here we get the
983 	 * 9.2.4.1 Frame Control field only. Mask and compare.
984 	 */
985 	fc &= htole16(IEEE80211_FC0_SUBTYPE_MASK | IEEE80211_FC0_TYPE_MASK);
986 	v = htole16(IEEE80211_FC0_SUBTYPE_BEACON | IEEE80211_FC0_TYPE_MGT);
987 
988 	return (fc == v);
989 }
990 
991 
992 static __inline bool
993 ieee80211_is_probe_req(__le16 fc)
994 {
995 	__le16 v;
996 
997 	fc &= htole16(IEEE80211_FC0_SUBTYPE_MASK | IEEE80211_FC0_TYPE_MASK);
998 	v = htole16(IEEE80211_FC0_SUBTYPE_PROBE_REQ | IEEE80211_FC0_TYPE_MGT);
999 
1000 	return (fc == v);
1001 }
1002 
1003 static __inline bool
1004 ieee80211_has_protected(__le16 fc)
1005 {
1006 
1007 	return (fc & htole16(IEEE80211_FC1_PROTECTED << 8));
1008 }
1009 
1010 static __inline bool
1011 ieee80211_is_back_req(__le16 fc)
1012 {
1013 	__le16 v;
1014 
1015 	fc &= htole16(IEEE80211_FC0_SUBTYPE_MASK | IEEE80211_FC0_TYPE_MASK);
1016 	v = htole16(IEEE80211_FC0_SUBTYPE_BAR | IEEE80211_FC0_TYPE_CTL);
1017 
1018 	return (fc == v);
1019 }
1020 
1021 static __inline bool
1022 ieee80211_is_bufferable_mmpdu(struct sk_buff *skb)
1023 {
1024 	struct ieee80211_mgmt *mgmt;
1025 	__le16 fc;
1026 
1027 	mgmt = (struct ieee80211_mgmt *)skb->data;
1028 	fc = mgmt->frame_control;
1029 
1030 	/* 11.2.2 Bufferable MMPDUs, 80211-2020. */
1031 	/* XXX we do not care about IBSS yet. */
1032 
1033 	if (!ieee80211_is_mgmt(fc))
1034 		return (false);
1035 	if (ieee80211_is_action(fc))		/* XXX FTM? */
1036 		return (true);			/* XXX false? */
1037 	if (ieee80211_is_disassoc(fc))
1038 		return (true);
1039 	if (ieee80211_is_deauth(fc))
1040 		return (true);
1041 
1042 	TODO();
1043 
1044 	return (false);
1045 }
1046 
1047 static __inline bool
1048 ieee80211_is_nullfunc(__le16 fc)
1049 {
1050 	__le16 v;
1051 
1052 	fc &= htole16(IEEE80211_FC0_SUBTYPE_MASK | IEEE80211_FC0_TYPE_MASK);
1053 	v = htole16(IEEE80211_FC0_SUBTYPE_NODATA | IEEE80211_FC0_TYPE_DATA);
1054 
1055 	return (fc == v);
1056 }
1057 
1058 static __inline bool
1059 ieee80211_is_qos_nullfunc(__le16 fc)
1060 {
1061 	__le16 v;
1062 
1063 	fc &= htole16(IEEE80211_FC0_SUBTYPE_MASK | IEEE80211_FC0_TYPE_MASK);
1064 	v = htole16(IEEE80211_FC0_SUBTYPE_QOS_NULL | IEEE80211_FC0_TYPE_DATA);
1065 
1066 	return (fc == v);
1067 }
1068 
1069 static __inline bool
1070 ieee80211_is_any_nullfunc(__le16 fc)
1071 {
1072 
1073 	return (ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc));
1074 }
1075 
1076 static inline bool
1077 ieee80211_is_pspoll(__le16 fc)
1078 {
1079 	__le16 v;
1080 
1081 	fc &= htole16(IEEE80211_FC0_SUBTYPE_MASK | IEEE80211_FC0_TYPE_MASK);
1082 	v = htole16(IEEE80211_FC0_SUBTYPE_PS_POLL | IEEE80211_FC0_TYPE_CTL);
1083 
1084 	return (fc == v);
1085 }
1086 
1087 static __inline bool
1088 ieee80211_has_a4(__le16 fc)
1089 {
1090 	__le16 v;
1091 
1092 	fc &= htole16((IEEE80211_FC1_DIR_TODS | IEEE80211_FC1_DIR_FROMDS) << 8);
1093 	v = htole16((IEEE80211_FC1_DIR_TODS | IEEE80211_FC1_DIR_FROMDS) << 8);
1094 
1095 	return (fc == v);
1096 }
1097 
1098 static __inline bool
1099 ieee80211_has_order(__le16 fc)
1100 {
1101 
1102 	return (fc & htole16(IEEE80211_FC1_ORDER << 8));
1103 }
1104 
1105 static __inline bool
1106 ieee80211_has_retry(__le16 fc)
1107 {
1108 
1109 	return (fc & htole16(IEEE80211_FC1_RETRY << 8));
1110 }
1111 
1112 
1113 static __inline bool
1114 ieee80211_has_fromds(__le16 fc)
1115 {
1116 
1117 	return (fc & htole16(IEEE80211_FC1_DIR_FROMDS << 8));
1118 }
1119 
1120 static __inline bool
1121 ieee80211_has_tods(__le16 fc)
1122 {
1123 
1124 	return (fc & htole16(IEEE80211_FC1_DIR_TODS << 8));
1125 }
1126 
1127 static __inline uint8_t *
1128 ieee80211_get_SA(struct ieee80211_hdr *hdr)
1129 {
1130 
1131 	if (ieee80211_has_a4(hdr->frame_control))
1132 		return (hdr->addr4);
1133 	if (ieee80211_has_fromds(hdr->frame_control))
1134 		return (hdr->addr3);
1135 	return (hdr->addr2);
1136 }
1137 
1138 static __inline uint8_t *
1139 ieee80211_get_DA(struct ieee80211_hdr *hdr)
1140 {
1141 
1142 	if (ieee80211_has_tods(hdr->frame_control))
1143 		return (hdr->addr3);
1144 	return (hdr->addr1);
1145 }
1146 
1147 static __inline bool
1148 ieee80211_is_frag(struct ieee80211_hdr *hdr)
1149 {
1150 	TODO();
1151 	return (false);
1152 }
1153 
1154 static __inline bool
1155 ieee80211_is_first_frag(__le16 fc)
1156 {
1157 	TODO();
1158 	return (false);
1159 }
1160 
1161 static __inline bool
1162 ieee80211_is_robust_mgmt_frame(struct sk_buff *skb)
1163 {
1164 	TODO();
1165 	return (false);
1166 }
1167 
1168 static __inline bool
1169 ieee80211_is_ftm(struct sk_buff *skb)
1170 {
1171 	TODO();
1172 	return (false);
1173 }
1174 
1175 static __inline bool
1176 ieee80211_is_timing_measurement(struct sk_buff *skb)
1177 {
1178 	TODO();
1179 	return (false);
1180 }
1181 
1182 static __inline bool
1183 ieee80211_has_pm(__le16 fc)
1184 {
1185 	TODO();
1186 	return (false);
1187 }
1188 
1189 static __inline bool
1190 ieee80211_has_morefrags(__le16 fc)
1191 {
1192 
1193 	fc &= htole16(IEEE80211_FC1_MORE_FRAG << 8);
1194 	return (fc != 0);
1195 }
1196 
1197 static __inline u8 *
1198 ieee80211_get_qos_ctl(struct ieee80211_hdr *hdr)
1199 {
1200         if (ieee80211_has_a4(hdr->frame_control))
1201                 return (u8 *)hdr + 30;
1202         else
1203                 return (u8 *)hdr + 24;
1204 }
1205 
1206 
1207 #endif	/* _LINUXKPI_LINUX_IEEE80211_H */
1208