xref: /freebsd/sys/compat/linuxkpi/common/include/linux/ieee80211.h (revision 6549718b70f0e660a15685369afb4f9caf2215ce)
1 /*-
2  * Copyright (c) 2020-2023 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/bitops.h>
37 #include <linux/if_ether.h>
38 
39 
40 /* 9.4.2.55 Management MIC element (CMAC-256, GMAC-128, and GMAC-256). */
41 struct ieee80211_mmie_16 {
42 	uint8_t		element_id;
43 	uint8_t		length;
44 	uint16_t	key_id;
45 	uint8_t		ipn[6];
46 	uint8_t		mic[16];
47 };
48 
49 #define	IEEE80211_CCMP_HDR_LEN			8	/* 802.11i .. net80211 comment */
50 #define	IEEE80211_CCMP_PN_LEN			6
51 #define	IEEE80211_CCMP_MIC_LEN			8	/* || 16 */
52 #define	IEEE80211_CCMP_256_HDR_LEN		8
53 #define	IEEE80211_CCMP_256_MIC_LEN		16
54 #define	IEEE80211_GCMP_HDR_LEN			8
55 #define	IEEE80211_GCMP_MIC_LEN			16
56 #define	IEEE80211_GCMP_PN_LEN			6
57 #define	IEEE80211_GMAC_PN_LEN			6
58 
59 #define	IEEE80211_MAX_PN_LEN			16
60 
61 #define	IEEE80211_INVAL_HW_QUEUE		((uint8_t)-1)
62 
63 #define	IEEE80211_MAX_AMPDU_BUF_HT		IEEE80211_AGGR_BAWMAX
64 #define	IEEE80211_MAX_AMPDU_BUF_HE		256
65 #define	IEEE80211_MAX_AMPDU_BUF_EHT		1024
66 
67 #define	IEEE80211_MAX_FRAME_LEN			2352
68 #define	IEEE80211_MAX_DATA_LEN			(2300 + IEEE80211_CRC_LEN)
69 
70 #define	IEEE80211_MAX_MPDU_LEN_HT_BA		4095	/* 9.3.2.1 Format of Data frames; non-VHT non-DMG STA */
71 #define	IEEE80211_MAX_MPDU_LEN_HT_3839		3839
72 #define	IEEE80211_MAX_MPDU_LEN_HT_7935		7935
73 #define	IEEE80211_MAX_MPDU_LEN_VHT_3895		3895
74 #define	IEEE80211_MAX_MPDU_LEN_VHT_7991		7991
75 #define	IEEE80211_MAX_MPDU_LEN_VHT_11454	11454
76 
77 #define	IEEE80211_MAX_RTS_THRESHOLD		2346	/* net80211::IEEE80211_RTS_MAX */
78 
79 #define	IEEE80211_MIN_ACTION_SIZE		23	/* ? */
80 
81 /* Wi-Fi Peer-to-Peer (P2P) Technical Specification */
82 #define	IEEE80211_P2P_OPPPS_CTWINDOW_MASK	0x7f
83 #define	IEEE80211_P2P_OPPPS_ENABLE_BIT		BIT(7)
84 
85 /* 802.11-2016, 9.2.4.5.1, Table 9-6 QoS Control Field */
86 #define	IEEE80211_QOS_CTL_TAG1D_MASK		0x0007
87 #define	IEEE80211_QOS_CTL_TID_MASK		IEEE80211_QOS_TID
88 #define	IEEE80211_QOS_CTL_EOSP			0x0010
89 #define	IEEE80211_QOS_CTL_A_MSDU_PRESENT	0x0080
90 #define	IEEE80211_QOS_CTL_ACK_POLICY_MASK	0x0060
91 #define	IEEE80211_QOS_CTL_ACK_POLICY_NOACK	0x0020
92 #define	IEEE80211_QOS_CTL_MESH_CONTROL_PRESENT	0x0100
93 
94 #define	IEEE80211_RATE_SHORT_PREAMBLE		BIT(0)
95 
96 enum ieee80211_rate_control_changed_flags {
97 	IEEE80211_RC_BW_CHANGED			= BIT(0),
98 	IEEE80211_RC_NSS_CHANGED		= BIT(1),
99 	IEEE80211_RC_SUPP_RATES_CHANGED		= BIT(2),
100 	IEEE80211_RC_SMPS_CHANGED		= BIT(3),
101 };
102 
103 #define	IEEE80211_SCTL_FRAG			IEEE80211_SEQ_FRAG_MASK
104 #define	IEEE80211_SCTL_SEQ			IEEE80211_SEQ_SEQ_MASK
105 
106 #define	IEEE80211_TKIP_ICV_LEN			4
107 #define	IEEE80211_TKIP_IV_LEN			8	/* WEP + KID + EXT */
108 
109 #define	IEEE80211_VHT_EXT_NSS_BW_CAPABLE	(1 << 13)	/* assigned to tx_highest */
110 
111 #define	IEEE80211_VHT_MAX_AMPDU_1024K		7	/* 9.4.2.56.3 A-MPDU Parameters field, Table 9-163 */
112 
113 #define	IEEE80211_WEP_IV_LEN			3	/* net80211: IEEE80211_WEP_IVLEN */
114 #define	IEEE80211_WEP_ICV_LEN			4
115 
116 #define	WLAN_AUTH_OPEN				__LINE__ /* TODO FIXME brcmfmac */
117 #define	WLAN_CAPABILITY_IBSS			__LINE__ /* TODO FIXME no longer used? */
118 #define	WLAN_CAPABILITY_SHORT_PREAMBLE		__LINE__ /* TODO FIXME brcmfmac */
119 #define	WLAN_CAPABILITY_SHORT_SLOT_TIME		__LINE__ /* TODO FIXME brcmfmac */
120 
121 enum wlan_ht_cap_sm_ps {
122 	WLAN_HT_CAP_SM_PS_STATIC		= 0,
123 	WLAN_HT_CAP_SM_PS_DYNAMIC,
124 	WLAN_HT_CAP_SM_PS_INVALID,
125 	WLAN_HT_CAP_SM_PS_DISABLED,
126 };
127 
128 #define	WLAN_MAX_KEY_LEN			32 /* TODO FIXME brcmfmac */
129 #define	WLAN_PMKID_LEN				16 /* TODO FIXME brcmfmac */
130 
131 #define	WLAN_KEY_LEN_WEP40			5
132 #define	WLAN_KEY_LEN_WEP104			13
133 #define	WLAN_KEY_LEN_TKIP			32
134 #define	WLAN_KEY_LEN_CCMP			16
135 #define	WLAN_KEY_LEN_GCMP			16
136 #define	WLAN_KEY_LEN_AES_CMAC			16
137 #define	WLAN_KEY_LEN_GCMP_256			32
138 #define	WLAN_KEY_LEN_BIP_CMAC_256		32
139 #define	WLAN_KEY_LEN_BIP_GMAC_128		16
140 #define	WLAN_KEY_LEN_BIP_GMAC_256		32
141 
142 /* 802.11-2020, 9.4.2.55.3, Table 9-185 Subfields of the A-MPDU Parameters field */
143 enum ieee80211_min_mpdu_start_spacing {
144 	IEEE80211_HT_MPDU_DENSITY_NONE		= 0,
145 #if 0
146 	IEEE80211_HT_MPDU_DENSITY_XXX		= 1,	/* 1/4 us */
147 #endif
148 	IEEE80211_HT_MPDU_DENSITY_0_5		= 2,	/* 1/2 us */
149 	IEEE80211_HT_MPDU_DENSITY_1		= 3,	/* 1 us */
150 	IEEE80211_HT_MPDU_DENSITY_2		= 4,	/* 2 us */
151 	IEEE80211_HT_MPDU_DENSITY_4		= 5,	/* 4us */
152 	IEEE80211_HT_MPDU_DENSITY_8		= 6,	/* 8us */
153 	IEEE80211_HT_MPDU_DENSITY_16		= 7, 	/* 16us */
154 };
155 
156 /* 9.4.2.57, Table 9-168, HT Operation element fields and subfields */
157 #define	IEEE80211_HT_STBC_PARAM_DUAL_CTS_PROT	0x0080	/* B24.. */
158 
159 #define	IEEE80211_FCTL_FTYPE			IEEE80211_FC0_TYPE_MASK
160 #define	IEEE80211_FCTL_STYPE			IEEE80211_FC0_SUBTYPE_MASK
161 #define	IEEE80211_FCTL_ORDER			(IEEE80211_FC1_ORDER << 8)
162 #define	IEEE80211_FCTL_PROTECTED		(IEEE80211_FC1_PROTECTED << 8)
163 #define	IEEE80211_FCTL_FROMDS			(IEEE80211_FC1_DIR_FROMDS << 8)
164 #define	IEEE80211_FCTL_TODS			(IEEE80211_FC1_DIR_TODS << 8)
165 #define	IEEE80211_FCTL_MOREFRAGS		(IEEE80211_FC1_MORE_FRAG << 8)
166 #define	IEEE80211_FCTL_PM			(IEEE80211_FC1_PWR_MGT << 8)
167 
168 #define	IEEE80211_FTYPE_MGMT			IEEE80211_FC0_TYPE_MGT
169 #define	IEEE80211_FTYPE_CTL			IEEE80211_FC0_TYPE_CTL
170 #define	IEEE80211_FTYPE_DATA			IEEE80211_FC0_TYPE_DATA
171 
172 #define	IEEE80211_STYPE_ASSOC_REQ		IEEE80211_FC0_SUBTYPE_ASSOC_REQ
173 #define	IEEE80211_STYPE_REASSOC_REQ		IEEE80211_FC0_SUBTYPE_REASSOC_REQ
174 #define	IEEE80211_STYPE_PROBE_REQ		IEEE80211_FC0_SUBTYPE_PROBE_REQ
175 #define	IEEE80211_STYPE_DISASSOC		IEEE80211_FC0_SUBTYPE_DISASSOC
176 #define	IEEE80211_STYPE_AUTH			IEEE80211_FC0_SUBTYPE_AUTH
177 #define	IEEE80211_STYPE_DEAUTH			IEEE80211_FC0_SUBTYPE_DEAUTH
178 #define	IEEE80211_STYPE_CTS			IEEE80211_FC0_SUBTYPE_CTS
179 #define	IEEE80211_STYPE_RTS			IEEE80211_FC0_SUBTYPE_RTS
180 #define	IEEE80211_STYPE_ACTION			IEEE80211_FC0_SUBTYPE_ACTION
181 #define	IEEE80211_STYPE_QOS_DATA		IEEE80211_FC0_SUBTYPE_QOS_DATA
182 #define	IEEE80211_STYPE_QOS_NULLFUNC		IEEE80211_FC0_SUBTYPE_QOS_NULL
183 #define	IEEE80211_STYPE_QOS_CFACK		0xd0	/* XXX-BZ reserved? */
184 
185 #define	IEEE80211_NUM_ACS			4	/* net8021::WME_NUM_AC */
186 
187 #define	IEEE80211_MAX_SSID_LEN			32	/* 9.4.2.2 SSID element, net80211: IEEE80211_NWID_LEN */
188 
189 
190 /* Figure 9-27, BAR Control field */
191 #define	IEEE80211_BAR_CTRL_TID_INFO_MASK	0xf000
192 #define	IEEE80211_BAR_CTRL_TID_INFO_SHIFT	12
193 
194 #define	IEEE80211_PPE_THRES_INFO_PPET_SIZE		1 /* TODO FIXME ax? */
195 #define	IEEE80211_PPE_THRES_NSS_MASK			2 /* TODO FIXME ax? */
196 #define	IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS	3 /* TODO FIXME ax? */
197 #define	IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK	8 /* TODO FIXME ax? */
198 #define	IEEE80211_HE_PPE_THRES_INFO_HEADER_SIZE		16	/* TODO FIXME ax? */
199 
200 /* 802.11-2012, Table 8-130-HT Operation element fields and subfields, HT Protection */
201 #define	IEEE80211_HT_OP_MODE_PROTECTION			IEEE80211_HTINFO_OPMODE		/* Mask. */
202 #define	IEEE80211_HT_OP_MODE_PROTECTION_NONE		IEEE80211_HTINFO_OPMODE_PURE	/* No protection */
203 #define	IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER	IEEE80211_HTINFO_OPMODE_PROTOPT	/* Nonmember protection */
204 #define	IEEE80211_HT_OP_MODE_PROTECTION_20MHZ		IEEE80211_HTINFO_OPMODE_HT20PR	/* 20 MHz protection */
205 #define	IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED	IEEE80211_HTINFO_OPMODE_MIXED	/* Non-HT mixed */
206 
207 
208 /* 9.6.13.1, Table 9-342 TDLS Action field values. */
209 enum ieee80211_tdls_action_code {
210 	WLAN_TDLS_SETUP_REQUEST			= 0,
211 	WLAN_TDLS_SETUP_RESPONSE		= 1,
212 	WLAN_TDLS_SETUP_CONFIRM			= 2,
213 	WLAN_TDLS_TEARDOWN			= 3,
214 	WLAN_TDLS_PEER_TRAFFIC_INDICATION	= 4,
215 	WLAN_TDLS_CHANNEL_SWITCH_REQUEST	= 5,
216 	WLAN_TDLS_CHANNEL_SWITCH_RESPONSE	= 6,
217 	WLAN_TDLS_PEER_PSM_REQUEST		= 7,
218 	WLAN_TDLS_PEER_PSM_RESPONSE		= 8,
219 	WLAN_TDLS_PEER_TRAFFIC_RESPONSE		= 9,
220 	WLAN_TDLS_DISCOVERY_REQUEST		= 10,
221 	/* 11-255 reserved */
222 };
223 
224 /* 802.11-2020 9.4.2.26, Table 9-153. Extended Capabilities field. */
225 /* This is split up into octets CAPA1 = octet 1, ... */
226 #define	WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING			BIT(2  % 8)
227 #define	WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT			BIT(22 % 8)
228 #define	WLAN_EXT_CAPA3_TIMING_MEASUREMENT_SUPPORT		BIT(23 % 8)
229 #define	WLAN_EXT_CAPA8_OPMODE_NOTIF				BIT(62 % 8)
230 #define	WLAN_EXT_CAPA8_MAX_MSDU_IN_AMSDU_LSB			BIT(63 % 8)
231 #define	WLAN_EXT_CAPA9_MAX_MSDU_IN_AMSDU_MSB			BIT(64 % 8)
232 #define	WLAN_EXT_CAPA10_TWT_REQUESTER_SUPPORT			BIT(77 % 8)
233 #define	WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT			BIT(78 % 8)
234 #define	WLAN_EXT_CAPA10_OBSS_NARROW_BW_RU_TOLERANCE_SUPPORT	BIT(79 % 8)
235 
236 #define	WLAN_EXT_CAPA11_EMA_SUPPORT				0x00	/* XXX TODO FIXME */
237 
238 
239 /* iwlwifi/mvm/utils:: for (ac = IEEE80211_AC_VO; ac <= IEEE80211_AC_VI; ac++) */
240 /* Would be so much easier if we'd define constants to the same. */
241 enum ieee80211_ac_numbers {
242 	IEEE80211_AC_VO = 0,			/* net80211::WME_AC_VO */
243 	IEEE80211_AC_VI = 1,			/* net80211::WME_AC_VI */
244 	IEEE80211_AC_BE = 2,			/* net80211::WME_AC_BE */
245 	IEEE80211_AC_BK = 3,			/* net80211::WME_AC_BK */
246 };
247 
248 #define	IEEE80211_MAX_QUEUES			16	/* Assume IEEE80211_NUM_TIDS for the moment. */
249 
250 #define	IEEE80211_WMM_IE_STA_QOSINFO_AC_VO	1
251 #define	IEEE80211_WMM_IE_STA_QOSINFO_AC_VI	2
252 #define	IEEE80211_WMM_IE_STA_QOSINFO_AC_BK	4
253 #define	IEEE80211_WMM_IE_STA_QOSINFO_AC_BE	8
254 #define	IEEE80211_WMM_IE_STA_QOSINFO_SP_ALL	0xf
255 
256 
257 /* Define the LinuxKPI names directly to the net80211 ones. */
258 #define	IEEE80211_HT_CAP_LDPC_CODING		IEEE80211_HTCAP_LDPC
259 #define	IEEE80211_HT_CAP_SUP_WIDTH_20_40	IEEE80211_HTCAP_CHWIDTH40
260 #define	IEEE80211_HT_CAP_SM_PS			IEEE80211_HTCAP_SMPS
261 #define	IEEE80211_HT_CAP_SM_PS_SHIFT		2
262 #define	IEEE80211_HT_CAP_GRN_FLD		IEEE80211_HTCAP_GREENFIELD
263 #define	IEEE80211_HT_CAP_SGI_20			IEEE80211_HTCAP_SHORTGI20
264 #define	IEEE80211_HT_CAP_SGI_40			IEEE80211_HTCAP_SHORTGI40
265 #define	IEEE80211_HT_CAP_TX_STBC		IEEE80211_HTCAP_TXSTBC
266 #define	IEEE80211_HT_CAP_RX_STBC		IEEE80211_HTCAP_RXSTBC
267 #define	IEEE80211_HT_CAP_RX_STBC_SHIFT		IEEE80211_HTCAP_RXSTBC_S
268 #define	IEEE80211_HT_CAP_MAX_AMSDU		IEEE80211_HTCAP_MAXAMSDU
269 #define	IEEE80211_HT_CAP_DSSSCCK40		IEEE80211_HTCAP_DSSSCCK40
270 #define	IEEE80211_HT_CAP_LSIG_TXOP_PROT		IEEE80211_HTCAP_LSIGTXOPPROT
271 
272 #define	IEEE80211_HT_MCS_TX_DEFINED		0x0001
273 #define	IEEE80211_HT_MCS_TX_RX_DIFF		0x0002
274 #define	IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT	2
275 #define	IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK	0x0c
276 #define	IEEE80211_HT_MCS_RX_HIGHEST_MASK	0x3ff
277 #define	IEEE80211_HT_MCS_MASK_LEN		10
278 
279 #define	IEEE80211_MLD_MAX_NUM_LINKS		15
280 
281 struct ieee80211_mcs_info {
282 	uint8_t		rx_mask[IEEE80211_HT_MCS_MASK_LEN];
283 	uint16_t	rx_highest;
284 	uint8_t		tx_params;
285 	uint8_t		__reserved[3];
286 };
287 
288 /* 802.11-2020, 9.4.2.55.1 HT Capabilities element structure */
289 struct ieee80211_ht_cap {
290 	uint16_t				cap_info;
291 	uint8_t					ampdu_params_info;
292 	struct ieee80211_mcs_info		mcs;
293 	uint16_t				extended_ht_cap_info;
294 	uint32_t				tx_BF_cap_info;
295 	uint8_t					antenna_selection_info;
296 };
297 
298 #define	IEEE80211_HT_MAX_AMPDU_FACTOR		13
299 #define	IEEE80211_HE_HT_MAX_AMPDU_FACTOR	16
300 #define	IEEE80211_HE_VHT_MAX_AMPDU_FACTOR	20
301 #define	IEEE80211_HE_6GHZ_MAX_AMPDU_FACTOR	13
302 
303 enum ieee80211_ht_max_ampdu_len {
304 	IEEE80211_HT_MAX_AMPDU_64K
305 };
306 
307 enum ieee80211_ampdu_mlme_action {
308 	IEEE80211_AMPDU_RX_START,
309 	IEEE80211_AMPDU_RX_STOP,
310 	IEEE80211_AMPDU_TX_OPERATIONAL,
311 	IEEE80211_AMPDU_TX_START,
312 	IEEE80211_AMPDU_TX_STOP_CONT,
313 	IEEE80211_AMPDU_TX_STOP_FLUSH,
314 	IEEE80211_AMPDU_TX_STOP_FLUSH_CONT
315 };
316 
317 #define	IEEE80211_AMPDU_TX_START_IMMEDIATE	1
318 #define	IEEE80211_AMPDU_TX_START_DELAY_ADDBA	2
319 
320 enum ieee80211_chanctx_switch_mode {
321 	CHANCTX_SWMODE_REASSIGN_VIF,
322 	CHANCTX_SWMODE_SWAP_CONTEXTS,
323 };
324 
325 enum ieee80211_chanctx_change_flags {
326 	IEEE80211_CHANCTX_CHANGE_MIN_WIDTH	= BIT(0),
327 	IEEE80211_CHANCTX_CHANGE_RADAR		= BIT(1),
328 	IEEE80211_CHANCTX_CHANGE_RX_CHAINS	= BIT(2),
329 	IEEE80211_CHANCTX_CHANGE_WIDTH		= BIT(3),
330 	IEEE80211_CHANCTX_CHANGE_CHANNEL	= BIT(4),
331 };
332 
333 enum ieee80211_frame_release_type {
334 	IEEE80211_FRAME_RELEASE_PSPOLL		= 1,
335 	IEEE80211_FRAME_RELEASE_UAPSD		= 2,
336 };
337 
338 enum ieee80211_p2p_attr_ids {
339 	IEEE80211_P2P_ATTR_DEVICE_ID,
340 	IEEE80211_P2P_ATTR_DEVICE_INFO,
341 	IEEE80211_P2P_ATTR_GROUP_ID,
342 	IEEE80211_P2P_ATTR_LISTEN_CHANNEL,
343 	IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
344 };
345 
346 enum ieee80211_reconfig_type {
347 	IEEE80211_RECONFIG_TYPE_RESTART,
348 	IEEE80211_RECONFIG_TYPE_SUSPEND,
349 };
350 
351 enum ieee80211_roc_type {
352 	IEEE80211_ROC_TYPE_MGMT_TX,
353 	IEEE80211_ROC_TYPE_NORMAL,
354 };
355 
356 enum ieee80211_smps_mode {
357 	IEEE80211_SMPS_OFF,
358 	IEEE80211_SMPS_STATIC,
359 	IEEE80211_SMPS_DYNAMIC,
360 	IEEE80211_SMPS_AUTOMATIC,
361 	IEEE80211_SMPS_NUM_MODES,
362 };
363 
364 /* net80211::IEEE80211_S_* different but represents the state machine. */
365 /* Note: order here is important! */
366 enum ieee80211_sta_state {
367 	IEEE80211_STA_NOTEXIST		= 0,
368 	IEEE80211_STA_NONE		= 1,
369 	IEEE80211_STA_AUTH		= 2,
370 	IEEE80211_STA_ASSOC		= 3,
371 	IEEE80211_STA_AUTHORIZED	= 4,	/* 802.1x */
372 };
373 
374 enum ieee80211_sta_rx_bw {
375 	IEEE80211_STA_RX_BW_20,
376 	IEEE80211_STA_RX_BW_40,
377 	IEEE80211_STA_RX_BW_80,
378 	IEEE80211_STA_RX_BW_160,
379 	IEEE80211_STA_RX_BW_320,
380 };
381 
382 enum ieee80211_tx_info_flags {
383 	/* XXX TODO .. right shift numbers - not sure where that came from? */
384 	IEEE80211_TX_CTL_AMPDU			= BIT(0),
385 	IEEE80211_TX_CTL_ASSIGN_SEQ		= BIT(1),
386 	IEEE80211_TX_CTL_NO_ACK			= BIT(2),
387 	IEEE80211_TX_CTL_SEND_AFTER_DTIM	= BIT(3),
388 	IEEE80211_TX_CTL_TX_OFFCHAN		= BIT(4),
389 	IEEE80211_TX_CTL_REQ_TX_STATUS		= BIT(5),
390 	IEEE80211_TX_STATUS_EOSP		= BIT(6),
391 	IEEE80211_TX_STAT_ACK			= BIT(7),
392 	IEEE80211_TX_STAT_AMPDU			= BIT(8),
393 	IEEE80211_TX_STAT_AMPDU_NO_BACK		= BIT(9),
394 	IEEE80211_TX_STAT_TX_FILTERED		= BIT(10),
395 	IEEE80211_TX_STAT_NOACK_TRANSMITTED	= BIT(11),
396 	IEEE80211_TX_CTL_FIRST_FRAGMENT		= BIT(12),
397 	IEEE80211_TX_INTFL_DONT_ENCRYPT		= BIT(13),
398 	IEEE80211_TX_CTL_NO_CCK_RATE		= BIT(14),
399 	IEEE80211_TX_CTL_INJECTED		= BIT(15),
400 	IEEE80211_TX_CTL_HW_80211_ENCAP		= BIT(16),
401 	IEEE80211_TX_CTL_USE_MINRATE		= BIT(17),
402 	IEEE80211_TX_CTL_RATE_CTRL_PROBE	= BIT(18),
403 	IEEE80211_TX_CTL_LDPC			= BIT(19),
404 	IEEE80211_TX_CTL_STBC			= BIT(20),
405 };
406 
407 enum ieee80211_tx_status_flags {
408 	IEEE80211_TX_STATUS_ACK_SIGNAL_VALID	= BIT(0),
409 };
410 
411 enum ieee80211_tx_control_flags {
412 	/* XXX TODO .. right shift numbers */
413 	IEEE80211_TX_CTRL_PORT_CTRL_PROTO	= BIT(0),
414 	IEEE80211_TX_CTRL_PS_RESPONSE		= BIT(1),
415 	IEEE80211_TX_CTRL_RATE_INJECT		= BIT(2),
416 	IEEE80211_TX_CTRL_MLO_LINK		= 0xF0000000,	/* This is IEEE80211_LINK_UNSPECIFIED on the high bits. */
417 };
418 
419 enum ieee80211_tx_rate_flags {
420 	/* XXX TODO .. right shift numbers */
421 	IEEE80211_TX_RC_40_MHZ_WIDTH		= BIT(0),
422 	IEEE80211_TX_RC_80_MHZ_WIDTH		= BIT(1),
423 	IEEE80211_TX_RC_160_MHZ_WIDTH		= BIT(2),
424 	IEEE80211_TX_RC_GREEN_FIELD		= BIT(3),
425 	IEEE80211_TX_RC_MCS			= BIT(4),
426 	IEEE80211_TX_RC_SHORT_GI		= BIT(5),
427 	IEEE80211_TX_RC_VHT_MCS			= BIT(6),
428 	IEEE80211_TX_RC_USE_SHORT_PREAMBLE	= BIT(7),
429 };
430 
431 #define	IEEE80211_RNR_TBTT_PARAMS_PSD_RESERVED	-128
432 
433 #define	IEEE80211_HT_CTL_LEN	4
434 
435 struct ieee80211_hdr {		/* net80211::ieee80211_frame_addr4 */
436         __le16		frame_control;
437         __le16		duration_id;
438 	uint8_t		addr1[ETH_ALEN];
439 	uint8_t		addr2[ETH_ALEN];
440 	uint8_t		addr3[ETH_ALEN];
441 	__le16		seq_ctrl;
442 	uint8_t		addr4[ETH_ALEN];
443 };
444 
445 struct ieee80211_hdr_3addr {	/* net80211::ieee80211_frame */
446         __le16		frame_control;
447         __le16		duration_id;
448 	uint8_t		addr1[ETH_ALEN];
449 	uint8_t		addr2[ETH_ALEN];
450 	uint8_t		addr3[ETH_ALEN];
451 	__le16		seq_ctrl;
452 };
453 
454 struct ieee80211_qos_hdr {	/* net80211:ieee80211_qosframe */
455         __le16		frame_control;
456         __le16		duration_id;
457 	uint8_t		addr1[ETH_ALEN];
458 	uint8_t		addr2[ETH_ALEN];
459 	uint8_t		addr3[ETH_ALEN];
460 	__le16		seq_ctrl;
461 	__le16		qos_ctrl;
462 };
463 
464 struct ieee80211_vendor_ie {
465 };
466 
467 /* 802.11-2020, Table 9-359-Block Ack Action field values */
468 enum ieee80211_back {
469 	WLAN_ACTION_ADDBA_REQ		= 0,
470 };
471 
472 /* 802.11-2020, Table 9-51-Category values */
473 enum ieee80211_category {
474 	WLAN_CATEGORY_BACK		= 3,
475 };
476 
477 /* 80211-2020 9.3.3.2 Format of Management frames */
478 struct ieee80211_mgmt {
479 	__le16		frame_control;
480         __le16		duration_id;
481 	uint8_t		da[ETH_ALEN];
482 	uint8_t		sa[ETH_ALEN];
483 	uint8_t		bssid[ETH_ALEN];
484 	__le16		seq_ctrl;
485 	union {
486 		/* 9.3.3.3 Beacon frame format */
487 		struct {
488 			uint64_t	timestamp;
489 			uint16_t	beacon_int;
490 			uint16_t	capab_info;
491 			uint8_t		variable[0];
492 		} beacon;
493 		/* 9.3.3.10 Probe Request frame format */
494 		struct {
495 			uint8_t		variable[0];
496 		} probe_req;
497 		/* 9.3.3.11 Probe Response frame format */
498 		struct {
499 			uint64_t	timestamp;
500 			uint16_t	beacon_int;
501 			uint16_t	capab_info;
502 			uint8_t		variable[0];
503 		} probe_resp;
504 		/* 9.3.3.14 Action frame format */
505 		struct {
506 			/* 9.4.1.11 Action field */
507 			uint8_t		category;
508 			/* 9.6.8 Public Action details */
509 			union {
510 				/* 9.6.2.5 TPC Report frame format */
511 				struct {
512 					uint8_t spec_mgmt;
513 					uint8_t dialog_token;
514 					/* uint32_t tpc_rep_elem:: */
515 					uint8_t tpc_elem_id;
516 					uint8_t tpc_elem_length;
517 					uint8_t tpc_elem_tx_power;
518 					uint8_t tpc_elem_link_margin;
519 				} tpc_report;
520 				/* 9.6.8.33 Fine Timing Measurement frame format */
521 				struct {
522 					uint8_t	dialog_token;
523 					uint8_t	follow_up;
524 					uint8_t	tod[6];
525 					uint8_t	toa[6];
526 					uint16_t tod_error;
527 					uint16_t toa_error;
528 					uint8_t variable[0];
529 				} ftm;
530 				/* 802.11-2016, 9.6.5.2 ADDBA Request frame format */
531 				struct {
532 					uint8_t action_code;
533 					uint8_t dialog_token;
534 					uint16_t capab;
535 					uint16_t timeout;
536 					uint16_t start_seq_num;
537 					/* Optional follows... */
538 					uint8_t variable[0];
539 				} addba_req;
540 				/* XXX */
541 				struct {
542 					uint8_t dialog_token;
543 				} wnm_timing_msr;
544 			} u;
545 		} action;
546 	} u;
547 };
548 
549 struct ieee80211_cts {		/* net80211::ieee80211_frame_cts */
550         __le16		frame_control;
551         __le16		duration;
552 	uint8_t		ra[ETH_ALEN];
553 } __packed;
554 
555 struct ieee80211_rts {		/* net80211::ieee80211_frame_rts */
556         __le16		frame_control;
557         __le16		duration;
558 	uint8_t		ra[ETH_ALEN];
559 	uint8_t		ta[ETH_ALEN];
560 } __packed;
561 
562 #define	MHZ_TO_KHZ(_f)		((_f) * 1000)
563 #define	DBI_TO_MBI(_g)		((_g) * 100)
564 #define	MBI_TO_DBI(_x)		((_x) / 100)
565 #define	DBM_TO_MBM(_g)		((_g) * 100)
566 #define	MBM_TO_DBM(_x)		((_x) / 100)
567 
568 #define	IEEE80211_SEQ_TO_SN(_seqn)	(((_seqn) & IEEE80211_SEQ_SEQ_MASK) >> \
569 					    IEEE80211_SEQ_SEQ_SHIFT)
570 
571 /* Time unit (TU) to .. See net80211: IEEE80211_DUR_TU */
572 #define	TU_TO_JIFFIES(_tu)	(usecs_to_jiffies(_tu) * 1024)
573 #define	TU_TO_EXP_TIME(_tu)	(jiffies + TU_TO_JIFFIES(_tu))
574 
575 /* 9.4.2.21.1, Table 9-82. */
576 #define	IEEE80211_SPCT_MSR_RPRT_TYPE_LCI	8
577 #define	IEEE80211_SPCT_MSR_RPRT_TYPE_CIVIC	11
578 
579 /* 9.4.2.1, Table 9-77. Element IDs. */
580 enum ieee80211_eid {
581 	WLAN_EID_SSID				= 0,
582 	WLAN_EID_SUPP_RATES			= 1,
583 	WLAN_EID_DS_PARAMS			= 3,
584 	WLAN_EID_TIM				= 5,
585 	WLAN_EID_COUNTRY			= 7,	/* IEEE80211_ELEMID_COUNTRY */
586 	WLAN_EID_REQUEST			= 10,
587 	WLAN_EID_CHANNEL_SWITCH			= 37,
588 	WLAN_EID_MEASURE_REPORT			= 39,
589 	WLAN_EID_HT_CAPABILITY			= 45,	/* IEEE80211_ELEMID_HTCAP */
590 	WLAN_EID_RSN				= 48,	/* IEEE80211_ELEMID_RSN */
591 	WLAN_EID_EXT_SUPP_RATES			= 50,
592 	WLAN_EID_EXT_NON_INHERITANCE		= 56,
593 	WLAN_EID_EXT_CHANSWITCH_ANN		= 60,
594 	WLAN_EID_MULTIPLE_BSSID			= 71,	/* IEEE80211_ELEMID_MULTIBSSID */
595 	WLAN_EID_MULTI_BSSID_IDX		= 85,
596 	WLAN_EID_EXT_CAPABILITY			= 127,
597 	WLAN_EID_VHT_CAPABILITY			= 191,	/* IEEE80211_ELEMID_VHT_CAP */
598 	WLAN_EID_VENDOR_SPECIFIC		= 221,	/* IEEE80211_ELEMID_VENDOR */
599 };
600 
601 enum ieee80211_eid_ext {
602 	WLAN_EID_EXT_HE_CAPABILITY		= 35,
603 };
604 
605 #define	for_each_element(_elem, _data, _len) \
606 	for (_elem = (const struct element *)(_data); \
607 	    (((const uint8_t *)(_data) + (_len) - (const uint8_t *)_elem) >= sizeof(*_elem)) && \
608 		(((const uint8_t *)(_data) + (_len) - (const uint8_t *)_elem) >= (sizeof(*_elem) + _elem->datalen)); \
609 	    _elem = (const struct element *)(_elem->data + _elem->datalen))
610 
611 #define	for_each_element_id(_elem, _eid, _data, _len) \
612 	for_each_element(_elem, _data, _len) \
613 		if (_elem->id == (_eid))
614 
615 /* 9.4.1.7, Table 9-45. Reason codes. */
616 enum ieee80211_reason_code {
617 	/* reserved				= 0, */
618 	WLAN_REASON_UNSPECIFIED			= 1,
619 	WLAN_REASON_DEAUTH_LEAVING		= 3,	/* LEAVING_NETWORK_DEAUTH */
620 	WLAN_REASON_TDLS_TEARDOWN_UNREACHABLE	= 25,
621 	WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED	= 26,
622 };
623 
624 /* 9.4.1.9, Table 9-46. Status codes. */
625 enum ieee80211_status_code {
626 	WLAN_STATUS_SUCCESS			= 0,
627 	WLAN_STATUS_AUTH_TIMEOUT		= 16,	/* REJECTED_SEQUENCE_TIMEOUT */
628 };
629 
630 /* 9.3.1.22 Trigger frame format; 80211ax-2021 */
631 struct ieee80211_trigger {
632         __le16		frame_control;
633         __le16		duration_id;
634 	uint8_t		ra[ETH_ALEN];
635 	uint8_t		ta[ETH_ALEN];
636 	__le64		common_info;		/* 8+ really */
637 	uint8_t		variable[];
638 };
639 
640 /* Table 9-29c-Trigger Type subfield encoding */
641 enum {
642 	IEEE80211_TRIGGER_TYPE_BASIC		= 0x0,
643 #if 0
644 	/* Not seen yet. */
645 	BFRP					= 0x1,
646 	MU-BAR					= 0x2,
647 	MU-RTS					= 0x3,
648 	BSRP					= 0x4,
649 	GCR MU-BAR				= 0x5,
650 	BQRP					= 0x6,
651 	NFRP					= 0x7,
652 	/* 0x8..0xf reserved */
653 #endif
654 	IEEE80211_TRIGGER_TYPE_MASK		= 0xf
655 };
656 
657 /* 802.11-2020, Figure 9-687-Control field format; 802.11ax-2021 */
658 #define	IEEE80211_TWT_CONTROL_NEG_TYPE_BROADCAST	BIT(3)
659 #define	IEEE80211_TWT_CONTROL_RX_DISABLED		BIT(4)
660 #define	IEEE80211_TWT_CONTROL_WAKE_DUR_UNIT		BIT(5)
661 
662 /* 802.11-2020, Figure 9-688-Request Type field format; 802.11ax-2021 */
663 #define	IEEE80211_TWT_REQTYPE_SETUP_CMD		(BIT(1) | BIT(2) | BIT(3))
664 #define	IEEE80211_TWT_REQTYPE_TRIGGER		BIT(4)
665 #define	IEEE80211_TWT_REQTYPE_IMPLICIT		BIT(5)
666 #define	IEEE80211_TWT_REQTYPE_FLOWTYPE		BIT(6)
667 #define	IEEE80211_TWT_REQTYPE_FLOWID		(BIT(7) | BIT(8) | BIT(9))
668 #define	IEEE80211_TWT_REQTYPE_WAKE_INT_EXP	(BIT(10) | BIT(11) | BIT(12) | BIT(13) | BIT(14))
669 #define	IEEE80211_TWT_REQTYPE_PROTECTION	BIT(15)
670 
671 struct ieee80211_twt_params {
672 	int	mantissa, min_twt_dur, twt;
673 	uint16_t				req_type;
674 };
675 
676 struct ieee80211_twt_setup {
677 	int	control;
678 	struct ieee80211_twt_params		*params;
679 };
680 
681 /* 802.11-2020, Table 9-297-TWT Setup Command field values */
682 enum ieee80211_twt_setup_cmd {
683 	TWT_SETUP_CMD_REQUEST			= 0,
684 	TWT_SETUP_CMD_SUGGEST			= 1,
685 	/* DEMAND				= 2, */
686 	/* GROUPING				= 3, */
687 	TWT_SETUP_CMD_ACCEPT			= 4,
688 	/* ALTERNATE				= 5 */
689 	TWT_SETUP_CMD_DICTATE			= 6,
690 	TWT_SETUP_CMD_REJECT			= 7,
691 };
692 
693 struct ieee80211_bssid_index {
694 	int	bssid_index;
695 };
696 
697 enum ieee80211_reg_ap_power {
698 	IEEE80211_REG_LPI_AP,
699 	IEEE80211_REG_SP_AP,
700 	IEEE80211_REG_VLP_AP,
701 };
702 
703 /* net80211: IEEE80211_IS_CTL() */
704 static __inline bool
705 ieee80211_is_ctl(__le16 fc)
706 {
707 	__le16 v;
708 
709 	fc &= htole16(IEEE80211_FC0_TYPE_MASK);
710 	v = htole16(IEEE80211_FC0_TYPE_CTL);
711 
712 	return (fc == v);
713 }
714 
715 /* net80211: IEEE80211_IS_DATA() */
716 static __inline bool
717 ieee80211_is_data(__le16 fc)
718 {
719 	__le16 v;
720 
721 	fc &= htole16(IEEE80211_FC0_TYPE_MASK);
722 	v = htole16(IEEE80211_FC0_TYPE_DATA);
723 
724 	return (fc == v);
725 }
726 
727 /* net80211: IEEE80211_IS_QOSDATA() */
728 static __inline bool
729 ieee80211_is_data_qos(__le16 fc)
730 {
731 	__le16 v;
732 
733 	fc &= htole16(IEEE80211_FC0_SUBTYPE_QOS_DATA | IEEE80211_FC0_TYPE_MASK);
734 	v = htole16(IEEE80211_FC0_SUBTYPE_QOS_DATA | IEEE80211_FC0_TYPE_DATA);
735 
736 	return (fc == v);
737 }
738 
739 /* net80211: IEEE80211_IS_MGMT() */
740 static __inline bool
741 ieee80211_is_mgmt(__le16 fc)
742 {
743 	__le16 v;
744 
745 	fc &= htole16(IEEE80211_FC0_TYPE_MASK);
746 	v = htole16(IEEE80211_FC0_TYPE_MGT);
747 
748 	return (fc == v);
749 }
750 
751 
752 /* Derived from net80211::ieee80211_anyhdrsize. */
753 static __inline unsigned int
754 ieee80211_hdrlen(__le16 fc)
755 {
756 	unsigned int size;
757 
758 	if (ieee80211_is_ctl(fc)) {
759 		switch (fc & htole16(IEEE80211_FC0_SUBTYPE_MASK)) {
760 		case htole16(IEEE80211_FC0_SUBTYPE_CTS):
761 		case htole16(IEEE80211_FC0_SUBTYPE_ACK):
762 			return sizeof(struct ieee80211_frame_ack);
763 		case htole16(IEEE80211_FC0_SUBTYPE_BAR):
764 			return sizeof(struct ieee80211_frame_bar);
765 		}
766 		return (sizeof(struct ieee80211_frame_min));
767 	}
768 
769 	size = sizeof(struct ieee80211_frame);
770 	if (ieee80211_is_data(fc)) {
771 		if ((fc & htole16(IEEE80211_FC1_DIR_MASK << 8)) ==
772 		    htole16(IEEE80211_FC1_DIR_DSTODS << 8))
773 			size += IEEE80211_ADDR_LEN;
774 		if ((fc & htole16(IEEE80211_FC0_SUBTYPE_QOS_DATA |
775 		    IEEE80211_FC0_TYPE_MASK)) ==
776 		    htole16(IEEE80211_FC0_SUBTYPE_QOS_DATA |
777 		    IEEE80211_FC0_TYPE_DATA))
778 			size += sizeof(uint16_t);
779 	}
780 
781 	if (ieee80211_is_mgmt(fc)) {
782 #ifdef __notyet__
783 		printf("XXX-BZ %s: TODO? fc %#04x size %u\n",
784 		    __func__, fc, size);
785 #endif
786 		;
787 	}
788 
789 	return (size);
790 }
791 
792 static inline bool
793 ieee80211_is_trigger(__le16 fc)
794 {
795 	__le16 v;
796 
797 	fc &= htole16(IEEE80211_FC0_SUBTYPE_MASK | IEEE80211_FC0_TYPE_MASK);
798 	v = htole16(IEEE80211_FC0_SUBTYPE_TRIGGER | IEEE80211_FC0_TYPE_CTL);
799 
800 	return (fc == v);
801 }
802 
803 #endif	/* _LINUXKPI_LINUX_IEEE80211_H */
804