xref: /freebsd/sys/compat/linuxkpi/common/include/linux/ieee80211.h (revision 43a5ec4eb41567cc92586503212743d89686d78f)
1 /*-
2  * Copyright (c) 2020-2021 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  * $FreeBSD$
29  */
30 
31 #ifndef	_LINUXKPI_LINUX_IEEE80211_H
32 #define	_LINUXKPI_LINUX_IEEE80211_H
33 
34 #include <sys/types.h>
35 #include <net80211/ieee80211.h>
36 
37 #include <asm/unaligned.h>
38 #include <linux/bitops.h>
39 #include <linux/if_ether.h>
40 
41 /* linux_80211.c */
42 extern int debug_80211;
43 
44 
45 #define	IEEE80211_CCMP_HDR_LEN			8	/* 802.11i .. net80211 comment */
46 #define	IEEE80211_CCMP_PN_LEN			6
47 #define	IEEE80211_CCMP_MIC_LEN			8	/* || 16 */
48 #define	IEEE80211_GCMP_HDR_LEN			8
49 #define	IEEE80211_GCMP_PN_LEN			6
50 #define	IEEE80211_GMAC_PN_LEN			6
51 
52 #define	IEEE80211_MAX_PN_LEN			16
53 
54 #define	IEEE80211_INVAL_HW_QUEUE		((uint8_t)-1)
55 
56 #define	IEEE80211_MAX_AMPDU_BUF_HT		0x40
57 #define	IEEE80211_MAX_AMPDU_BUF			256	/* for HE? */
58 
59 #define	IEEE80211_MAX_DATA_LEN			(2300 + IEEE80211_CRC_LEN)
60 
61 #define	IEEE80211_MAX_MPDU_LEN_HT_BA		4095	/* 9.3.2.1 Format of Data frames; non-VHT non-DMG STA */
62 #define	IEEE80211_MAX_MPDU_LEN_HT_3839		3839
63 #define	IEEE80211_MAX_MPDU_LEN_VHT_3895		3895
64 #define	IEEE80211_MAX_MPDU_LEN_VHT_7991		7991
65 #define	IEEE80211_MAX_MPDU_LEN_VHT_11454	11454
66 
67 #define	IEEE80211_MAX_RTS_THRESHOLD		2346	/* net80211::IEEE80211_RTS_MAX */
68 
69 #define	IEEE80211_MIN_ACTION_SIZE		23	/* ? */
70 
71 /* Wi-Fi Peer-to-Peer (P2P) Technical Specification */
72 #define	IEEE80211_P2P_OPPPS_CTWINDOW_MASK	0x7f
73 #define	IEEE80211_P2P_OPPPS_ENABLE_BIT		BIT(7)
74 
75 #define	IEEE80211_QOS_CTL_A_MSDU_PRESENT	0x0080	/* 9.2.4.5.1, Table 9-6 QoS Control Field */
76 
77 #define	IEEE80211_RATE_SHORT_PREAMBLE		BIT(0)
78 
79 enum ieee80211_rate_control_changed_flags {
80 	IEEE80211_RC_BW_CHANGED			= BIT(0),
81 	IEEE80211_RC_NSS_CHANGED		= BIT(1),
82 	IEEE80211_RC_SUPP_RATES_CHANGED		= BIT(2),
83 };
84 
85 #define	IEEE80211_SCTL_FRAG			IEEE80211_SEQ_FRAG_MASK
86 #define	IEEE80211_SCTL_SEQ			IEEE80211_SEQ_SEQ_MASK
87 
88 #define	IEEE80211_TKIP_ICV_LEN			4
89 #define	IEEE80211_TKIP_IV_LEN			8	/* WEP + KID + EXT */
90 
91 #define	IEEE80211_VHT_EXT_NSS_BW_CAPABLE	(1 << 13)	/* assigned to tx_highest */
92 
93 #define	IEEE80211_VHT_MAX_AMPDU_1024K		7	/* 9.4.2.56.3 A-MPDU Parameters field, Table 9-163 */
94 
95 #define	IEEE80211_WEP_IV_LEN			3	/* net80211: IEEE80211_WEP_IVLEN */
96 #define	IEEE80211_WEP_ICV_LEN			4
97 
98 #define	WLAN_AUTH_OPEN				__LINE__ /* TODO FIXME brcmfmac */
99 #define	WLAN_CAPABILITY_IBSS			__LINE__ /* TODO FIXME no longer used? */
100 #define	WLAN_CAPABILITY_SHORT_PREAMBLE		__LINE__ /* TODO FIXME brcmfmac */
101 #define	WLAN_CAPABILITY_SHORT_SLOT_TIME		__LINE__ /* TODO FIXME brcmfmac */
102 
103 
104 #define	WLAN_MAX_KEY_LEN			32 /* TODO FIXME brcmfmac */
105 #define	WLAN_PMKID_LEN				16 /* TODO FIXME brcmfmac */
106 
107 #define	WLAN_KEY_LEN_CCMP			16
108 #define	WLAN_KEY_LEN_GCMP_256			32
109 
110 /* 9.4.2.56.3, Table 9-163 Subfields of the A-MPDU Parameters field */
111 enum ieee80211_min_mpdu_start_spacing {
112 	IEEE80211_HT_MPDU_DENSITY_4		= 5,	/* 4us */
113 	IEEE80211_HT_MPDU_DENSITY_16		= 7, 	/* 16us */
114 };
115 
116 /* 9.4.2.57, Table 9-168, HT Operation element fields and subfields */
117 #define	IEEE80211_HT_STBC_PARAM_DUAL_CTS_PROT	0x0080	/* B24.. */
118 
119 #define	IEEE80211_FCTL_STYPE			IEEE80211_FC0_SUBTYPE_MASK
120 
121 #define	IEEE80211_STYPE_ASSOC_REQ		IEEE80211_FC0_SUBTYPE_ASSOC_REQ
122 #define	IEEE80211_STYPE_REASSOC_REQ		IEEE80211_FC0_SUBTYPE_REASSOC_REQ
123 #define	IEEE80211_STYPE_PROBE_REQ		IEEE80211_FC0_SUBTYPE_PROBE_REQ
124 #define	IEEE80211_STYPE_DISASSOC		IEEE80211_FC0_SUBTYPE_DISASSOC
125 #define	IEEE80211_STYPE_AUTH			IEEE80211_FC0_SUBTYPE_AUTH
126 #define	IEEE80211_STYPE_DEAUTH			IEEE80211_FC0_SUBTYPE_DEAUTH
127 #define	IEEE80211_STYPE_ACTION			IEEE80211_FC0_SUBTYPE_ACTION
128 
129 #define	IEEE80211_NUM_ACS			4	/* net8021::WME_NUM_AC */
130 
131 #define	IEEE80211_MAX_SSID_LEN			32	/* 9.4.2.2 SSID element, net80211: IEEE80211_NWID_LEN */
132 
133 
134 /* Figure 9-27, BAR Control field */
135 #define	IEEE80211_BAR_CTRL_TID_INFO_MASK	0xf000
136 #define	IEEE80211_BAR_CTRL_TID_INFO_SHIFT	12
137 
138 #define	IEEE80211_PPE_THRES_INFO_PPET_SIZE		1 /* TODO FIXME ax? */
139 #define	IEEE80211_PPE_THRES_NSS_MASK			2 /* TODO FIXME ax? */
140 #define	IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS	3 /* TODO FIXME ax? */
141 #define	IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK	8 /* TODO FIXME ax? */
142 
143 #define	IEEE80211_HT_OP_MODE_PROTECTION			0x03	/* MASK */
144 #define	IEEE80211_HT_OP_MODE_PROTECTION_NONE		0x00
145 #define	IEEE80211_HT_OP_MODE_PROTECTION_20MHZ		0x01
146 #define	IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED	0x02
147 #define	IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER	0x03
148 
149 
150 /* 9.6.13.1, Table 9-342 TDLS Action field values. */
151 enum ieee80211_tdls_action_code {
152 	WLAN_TDLS_SETUP_REQUEST			= 0,
153 	WLAN_TDLS_SETUP_RESPONSE		= 1,
154 	WLAN_TDLS_SETUP_CONFIRM			= 2,
155 	WLAN_TDLS_TEARDOWN			= 3,
156 	WLAN_TDLS_PEER_TRAFFIC_INDICATION	= 4,
157 	WLAN_TDLS_CHANNEL_SWITCH_REQUEST	= 5,
158 	WLAN_TDLS_CHANNEL_SWITCH_RESPONSE	= 6,
159 	WLAN_TDLS_PEER_PSM_REQUEST		= 7,
160 	WLAN_TDLS_PEER_PSM_RESPONSE		= 8,
161 	WLAN_TDLS_PEER_TRAFFIC_RESPONSE		= 9,
162 	WLAN_TDLS_DISCOVERY_REQUEST		= 10,
163 	/* 11-255 reserved */
164 };
165 
166 /* 9.4.2.27, Table 9-135. Extended Capabilities field. */
167 /* This is split up into octets CAPA1 = octet 1, ... */
168 #define	WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING			BIT(2  % 8)
169 #define	WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT			BIT(22 % 8)
170 #define	WLAN_EXT_CAPA8_OPMODE_NOTIF				BIT(62 % 8)
171 #define	WLAN_EXT_CAPA10_TWT_REQUESTER_SUPPORT			BIT(5)		/* XXX */
172 #define	WLAN_EXT_CAPA10_OBSS_NARROW_BW_RU_TOLERANCE_SUPPORT	BIT(7)		/* XXX */
173 
174 
175 /* iwlwifi/mvm/utils:: for (ac = IEEE80211_AC_VO; ac <= IEEE80211_AC_VI; ac++) */
176 /* Would be so much easier if we'd define constants to the same. */
177 enum ieee80211_ac_numbers {
178 	IEEE80211_AC_VO = 0,			/* net80211::WME_AC_VO */
179 	IEEE80211_AC_VI = 1,			/* net80211::WME_AC_VI */
180 	IEEE80211_AC_BE = 2,			/* net80211::WME_AC_BE */
181 	IEEE80211_AC_BK = 3,			/* net80211::WME_AC_BK */
182 };
183 
184 #define	IEEE80211_MAX_QUEUES			16	/* Assume IEEE80211_NUM_TIDS for the moment. */
185 
186 #define	IEEE80211_WMM_IE_STA_QOSINFO_AC_VO	1
187 #define	IEEE80211_WMM_IE_STA_QOSINFO_AC_VI	2
188 #define	IEEE80211_WMM_IE_STA_QOSINFO_AC_BK	4
189 #define	IEEE80211_WMM_IE_STA_QOSINFO_AC_BE	8
190 #define	IEEE80211_WMM_IE_STA_QOSINFO_SP_ALL	0xf
191 
192 struct vht_mcs {
193 	uint16_t	rx_mcs_map;
194 	uint16_t	rx_highest;
195 	uint16_t	tx_mcs_map;
196 	uint16_t	tx_highest;
197 };
198 
199 struct ieee80211_vht_cap {
200 	struct vht_mcs				supp_mcs;;
201 	__le32					vht_cap_info;
202 };
203 
204 enum ieee80211_ht_max_ampdu_len {
205 	IEEE80211_HT_MAX_AMPDU_64K
206 };
207 
208 enum ieee80211_ampdu_mlme_action {
209 	IEEE80211_AMPDU_RX_START,
210 	IEEE80211_AMPDU_RX_STOP,
211 	IEEE80211_AMPDU_TX_OPERATIONAL,
212 	IEEE80211_AMPDU_TX_START,
213 	IEEE80211_AMPDU_TX_START_DELAY_ADDBA,
214 	IEEE80211_AMPDU_TX_START_IMMEDIATE,
215 	IEEE80211_AMPDU_TX_STOP_CONT,
216 	IEEE80211_AMPDU_TX_STOP_FLUSH,
217 	IEEE80211_AMPDU_TX_STOP_FLUSH_CONT
218 };
219 
220 enum ieee80211_chanctx_switch_mode {
221 	CHANCTX_SWMODE_REASSIGN_VIF,
222 	CHANCTX_SWMODE_SWAP_CONTEXTS,
223 };
224 
225 enum ieee80211_chanctx_change_flags {
226 	IEEE80211_CHANCTX_CHANGE_MIN_WIDTH	= BIT(0),
227 	IEEE80211_CHANCTX_CHANGE_RADAR		= BIT(1),
228 	IEEE80211_CHANCTX_CHANGE_RX_CHAINS	= BIT(2),
229 	IEEE80211_CHANCTX_CHANGE_WIDTH		= BIT(3),
230 };
231 
232 enum ieee80211_frame_release_type {
233 	IEEE80211_FRAME_RELEASE_PSPOLL		= 1,
234 	IEEE80211_FRAME_RELEASE_UAPSD		= 2,
235 };
236 
237 enum ieee80211_p2p_attr_ids {
238 	IEEE80211_P2P_ATTR_DEVICE_ID,
239 	IEEE80211_P2P_ATTR_DEVICE_INFO,
240 	IEEE80211_P2P_ATTR_GROUP_ID,
241 	IEEE80211_P2P_ATTR_LISTEN_CHANNEL,
242 };
243 
244 enum ieee80211_reconfig_type {
245 	IEEE80211_RECONFIG_TYPE_RESTART,
246 	IEEE80211_RECONFIG_TYPE_SUSPEND,
247 };
248 
249 enum ieee80211_roc_type {
250 	IEEE80211_ROC_TYPE_MGMT_TX,
251 	IEEE80211_ROC_TYPE_NORMAL,
252 };
253 
254 enum ieee80211_smps_mode {
255 	IEEE80211_SMPS_OFF,
256 	IEEE80211_SMPS_STATIC,
257 	IEEE80211_SMPS_DYNAMIC,
258 	IEEE80211_SMPS_AUTOMATIC,
259 	IEEE80211_SMPS_NUM_MODES,
260 };
261 
262 /* net80211::IEEE80211_S_* different but represents the state machine. */
263 /* Note: order here is important! */
264 enum ieee80211_sta_state {
265 	IEEE80211_STA_NOTEXIST,
266 	IEEE80211_STA_NONE,
267 	IEEE80211_STA_AUTH,
268 	IEEE80211_STA_ASSOC,
269 	IEEE80211_STA_AUTHORIZED,		/* 802.1x */
270 };
271 
272 enum ieee80211_sta_rx_bw {
273 	IEEE80211_STA_RX_BW_20,
274 	IEEE80211_STA_RX_BW_40,
275 	IEEE80211_STA_RX_BW_80,
276 	IEEE80211_STA_RX_BW_160,
277 };
278 
279 enum ieee80211_tx_info_flags {
280 	/* XXX TODO .. right shift numbers - not sure where that came from? */
281 	IEEE80211_TX_CTL_AMPDU			= BIT(0),
282 	IEEE80211_TX_CTL_ASSIGN_SEQ		= BIT(1),
283 	IEEE80211_TX_CTL_NO_ACK			= BIT(2),
284 	IEEE80211_TX_CTL_SEND_AFTER_DTIM	= BIT(3),
285 	IEEE80211_TX_CTL_TX_OFFCHAN		= BIT(4),
286 	IEEE80211_TX_CTL_REQ_TX_STATUS		= BIT(5),
287 	IEEE80211_TX_STATUS_EOSP		= BIT(6),
288 	IEEE80211_TX_STAT_ACK			= BIT(7),
289 	IEEE80211_TX_STAT_AMPDU			= BIT(8),
290 	IEEE80211_TX_STAT_AMPDU_NO_BACK		= BIT(9),
291 	IEEE80211_TX_STAT_TX_FILTERED		= BIT(10),
292 	IEEE80211_TX_STAT_NOACK_TRANSMITTED	= BIT(11),
293 };
294 
295 enum ieee80211_tx_control_flags {
296 	/* XXX TODO .. right shift numbers */
297 	IEEE80211_TX_CTRL_PORT_CTRL_PROTO	= BIT(0),
298 };
299 
300 enum ieee80211_tx_rate_flags {
301 	/* XXX TODO .. right shift numbers */
302 	IEEE80211_TX_RC_40_MHZ_WIDTH		= BIT(0),
303 	IEEE80211_TX_RC_80_MHZ_WIDTH		= BIT(1),
304 	IEEE80211_TX_RC_160_MHZ_WIDTH		= BIT(2),
305 	IEEE80211_TX_RC_GREEN_FIELD		= BIT(3),
306 	IEEE80211_TX_RC_MCS			= BIT(4),
307 	IEEE80211_TX_RC_SHORT_GI		= BIT(5),
308 	IEEE80211_TX_RC_VHT_MCS			= BIT(6),
309 };
310 
311 struct ieee80211_hdr {		/* net80211::ieee80211_frame */
312         __le16		frame_control;
313         __le16		duration_id;
314 	uint8_t		addr1[ETH_ALEN];
315 	uint8_t		addr2[ETH_ALEN];
316 	uint8_t		addr3[ETH_ALEN];
317 	__le16		seq_ctrl;
318 	uint8_t		addr4[ETH_ALEN];
319 };
320 
321 struct ieee80211_vendor_ie {
322 };
323 
324 /* 9.3.3.2 Format of Management frames */
325 struct ieee80211_mgmt {
326 	__le16		frame_control;
327         __le16		duration_id;
328 	uint8_t		da[ETH_ALEN];
329 	uint8_t		sa[ETH_ALEN];
330 	uint8_t		bssid[ETH_ALEN];
331 	__le16		seq_ctrl;
332 	union {
333 		/* 9.3.3.3 Beacon frame format */
334 		struct {
335 			uint64_t	timestamp;
336 			uint16_t	beacon_int;
337 			uint16_t	capab_info;
338 			uint8_t		variable[0];
339 		} beacon;
340 		/* 9.3.3.10 Probe Request frame format */
341 		struct {
342 			uint8_t		variable[0];
343 		} probe_req;
344 		/* 9.3.3.11 Probe Response frame format */
345 		struct {
346 			uint64_t	timestamp;
347 			uint16_t	beacon_int;
348 			uint16_t	capab_info;
349 			uint8_t		variable[0];
350 		} probe_resp;
351 		/* 9.3.3.14 Action frame format */
352 		struct {
353 			/* 9.4.1.11 Action field */
354 			uint8_t		category;
355 			/* 9.6.8 Public Action details */
356 			union {
357 				/* 9.6.8.33 Fine Timing Measurement frame format */
358 				struct {
359 					uint8_t	dialog_token;
360 					uint8_t	follow_up;
361 					uint8_t	tod[6];
362 					uint8_t	toa[6];
363 					uint16_t tod_error;
364 					uint16_t toa_error;
365 					uint8_t variable[0];
366 				} ftm;
367 			} u;
368 		} action;
369 	} u;
370 };
371 
372 #define	MHZ_TO_KHZ(_f)		((_f) * 1000)
373 #define	DBI_TO_MBI(_g)		((_g) * 100)
374 #define	MBI_TO_DBI(_x)		((_x) / 100)
375 #define	DBM_TO_MBM(_g)		((_g) * 100)
376 #define	MBM_TO_DBM(_x)		((_x) / 100)
377 
378 #define	IEEE80211_SEQ_TO_SN(_seqn)	(((_seqn) & IEEE80211_SEQ_SEQ_MASK) >> \
379 					    IEEE80211_SEQ_SEQ_SHIFT)
380 
381 /* Time unit (TU) to .. See net80211: IEEE80211_DUR_TU */
382 #define	TU_TO_JIFFIES(_tu)	(usecs_to_jiffies(_tu) * 1024)
383 #define	TU_TO_EXP_TIME(_tu)	(jiffies + TU_TO_JIFFIES(_tu))
384 
385 /* 9.4.2.21.1, Table 9-82. */
386 #define	IEEE80211_SPCT_MSR_RPRT_TYPE_LCI	8
387 #define	IEEE80211_SPCT_MSR_RPRT_TYPE_CIVIC	11
388 
389 /* 9.4.2.1, Table 9-77. Element IDs. */
390 enum ieee80211_eid {
391 	WLAN_EID_SSID				= 0,
392 	WLAN_EID_SUPP_RATES			= 1,
393 	WLAN_EID_DS_PARAMS			= 3,
394 	WLAN_EID_TIM				= 5,
395 	WLAN_EID_COUNTRY			= 7, /* IEEE80211_ELEMID_COUNTRY */
396 	WLAN_EID_REQUEST			= 10,
397 	WLAN_EID_CHANNEL_SWITCH			= 37,
398 	WLAN_EID_MEASURE_REPORT			= 39,
399 	WLAN_EID_RSN				= 48, /* IEEE80211_ELEMID_RSN */
400 	WLAN_EID_EXT_SUPP_RATES			= 50,
401 	WLAN_EID_EXT_CHANSWITCH_ANN		= 60,
402 	WLAN_EID_EXT_CAPABILITY			= 127,
403 	WLAN_EID_VENDOR_SPECIFIC		= 221,
404 };
405 
406 /* 9.4.1.7, Table 9-45. Reason codes. */
407 enum ieee80211_reason_code {
408 	/* reserved				= 0, */
409 	WLAN_REASON_UNSPECIFIED			= 1,
410 	WLAN_REASON_DEAUTH_LEAVING		= 3,	/* LEAVING_NETWORK_DEAUTH */
411 	WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED	= 26,
412 };
413 
414 /* 9.4.1.9, Table 9-46. Status codes. */
415 enum ieee80211_status_code {
416 	WLAN_STATUS_SUCCESS			= 0,
417 	WLAN_STATUS_AUTH_TIMEOUT		= 16,	/* REJECTED_SEQUENCE_TIMEOUT */
418 };
419 
420 /* net80211: IEEE80211_IS_CTL() */
421 static __inline bool
422 ieee80211_is_ctl(__le16 fc)
423 {
424 	__le16 v;
425 
426 	fc &= htole16(IEEE80211_FC0_TYPE_MASK);
427 	v = htole16(IEEE80211_FC0_TYPE_CTL);
428 
429 	return (fc == v);
430 }
431 
432 /* net80211: IEEE80211_IS_DATA() */
433 static __inline bool
434 ieee80211_is_data(__le16 fc)
435 {
436 	__le16 v;
437 
438 	fc &= htole16(IEEE80211_FC0_TYPE_MASK);
439 	v = htole16(IEEE80211_FC0_TYPE_DATA);
440 
441 	return (fc == v);
442 }
443 
444 /* net80211: IEEE80211_IS_QOSDATA() */
445 static __inline bool
446 ieee80211_is_data_qos(__le16 fc)
447 {
448 	__le16 v;
449 
450 	fc &= htole16(IEEE80211_FC0_SUBTYPE_QOS | IEEE80211_FC0_TYPE_MASK |
451 	    IEEE80211_FC0_VERSION_MASK);
452 	v = htole16(IEEE80211_FC0_QOSDATA);
453 
454 	return (fc == v);
455 }
456 
457 /* net80211: IEEE80211_IS_MGMT() */
458 static __inline bool
459 ieee80211_is_mgmt(__le16 fc)
460 {
461 	__le16 v;
462 
463 	fc &= htole16(IEEE80211_FC0_TYPE_MASK);
464 	v = htole16(IEEE80211_FC0_TYPE_MGT);
465 
466 	return (fc == v);
467 }
468 
469 
470 /* Derived from net80211::ieee80211_anyhdrsize. */
471 static __inline unsigned int
472 ieee80211_hdrlen(__le16 fc)
473 {
474 	unsigned int size;
475 
476 	if (ieee80211_is_ctl(fc)) {
477 		switch (fc & htole16(IEEE80211_FC0_SUBTYPE_MASK)) {
478 		case htole16(IEEE80211_FC0_SUBTYPE_CTS):
479 		case htole16(IEEE80211_FC0_SUBTYPE_ACK):
480 			return sizeof(struct ieee80211_frame_ack);
481 		case htole16(IEEE80211_FC0_SUBTYPE_BAR):
482 			return sizeof(struct ieee80211_frame_bar);
483 		}
484 		return (sizeof(struct ieee80211_frame_min));
485 	}
486 
487 	size = sizeof(struct ieee80211_frame);
488 	if (ieee80211_is_data(fc)) {
489 		if ((fc & htole16(IEEE80211_FC1_DIR_MASK << 8)) ==
490 		    htole16(IEEE80211_FC1_DIR_DSTODS << 8))
491 			size += IEEE80211_ADDR_LEN;
492 		if ((fc & htole16(IEEE80211_FC0_SUBTYPE_QOS |
493 		    IEEE80211_FC0_TYPE_MASK)) ==
494 		    htole16(IEEE80211_FC0_SUBTYPE_QOS |
495 		    IEEE80211_FC0_TYPE_DATA))
496 			size += sizeof(uint16_t);
497 	}
498 
499 	if (ieee80211_is_mgmt(fc)) {
500 #ifdef __notyet__
501 		if (debug_80211 > 0)
502 			printf("XXX-BZ %s: TODO? fc %#04x size %u\n",
503 			    __func__, fc, size);
504 #endif
505 		;
506 	}
507 
508 	return (size);
509 }
510 
511 #endif	/* _LINUXKPI_LINUX_IEEE80211_H */
512