1/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 * IEEE 802.11 defines
4 *
5 * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
6 * <jkmaline@cc.hut.fi>
7 * Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi>
8 * Copyright (c) 2005, Devicescape Software, Inc.
9 * Copyright (c) 2006, Michael Wu <flamingice@sourmilk.net>
10 * Copyright (c) 2013 - 2014 Intel Mobile Communications GmbH
11 * Copyright (c) 2016 - 2017 Intel Deutschland GmbH
12 * Copyright (c) 2018 - 2025 Intel Corporation
13 */
14
15#ifndef LINUX_IEEE80211_H
16#define LINUX_IEEE80211_H
17
18#include <linux/types.h>
19#include <linux/if_ether.h>
20#include <linux/etherdevice.h>
21#include <linux/bitfield.h>
22#include <asm/byteorder.h>
23#include <linux/unaligned.h>
24
25/*
26 * DS bit usage
27 *
28 * TA = transmitter address
29 * RA = receiver address
30 * DA = destination address
31 * SA = source address
32 *
33 * ToDS FromDS A1(RA) A2(TA) A3 A4 Use
34 * -----------------------------------------------------------------
35 * 0 0 DA SA BSSID - IBSS/DLS
36 * 0 1 DA BSSID SA - AP -> STA
37 * 1 0 BSSID SA DA - AP <- STA
38 * 1 1 RA TA DA SA unspecified (WDS)
39 */
40
41#define FCS_LEN 4
42
43#define IEEE80211_FCTL_VERS 0x0003
44#define IEEE80211_FCTL_FTYPE 0x000c
45#define IEEE80211_FCTL_STYPE 0x00f0
46#define IEEE80211_FCTL_TODS 0x0100
47#define IEEE80211_FCTL_FROMDS 0x0200
48#define IEEE80211_FCTL_MOREFRAGS 0x0400
49#define IEEE80211_FCTL_RETRY 0x0800
50#define IEEE80211_FCTL_PM 0x1000
51#define IEEE80211_FCTL_MOREDATA 0x2000
52#define IEEE80211_FCTL_PROTECTED 0x4000
53#define IEEE80211_FCTL_ORDER 0x8000
54#define IEEE80211_FCTL_CTL_EXT 0x0f00
55
56#define IEEE80211_SCTL_FRAG 0x000F
57#define IEEE80211_SCTL_SEQ 0xFFF0
58
59#define IEEE80211_FTYPE_MGMT 0x0000
60#define IEEE80211_FTYPE_CTL 0x0004
61#define IEEE80211_FTYPE_DATA 0x0008
62#define IEEE80211_FTYPE_EXT 0x000c
63
64/* management */
65#define IEEE80211_STYPE_ASSOC_REQ 0x0000
66#define IEEE80211_STYPE_ASSOC_RESP 0x0010
67#define IEEE80211_STYPE_REASSOC_REQ 0x0020
68#define IEEE80211_STYPE_REASSOC_RESP 0x0030
69#define IEEE80211_STYPE_PROBE_REQ 0x0040
70#define IEEE80211_STYPE_PROBE_RESP 0x0050
71#define IEEE80211_STYPE_BEACON 0x0080
72#define IEEE80211_STYPE_ATIM 0x0090
73#define IEEE80211_STYPE_DISASSOC 0x00A0
74#define IEEE80211_STYPE_AUTH 0x00B0
75#define IEEE80211_STYPE_DEAUTH 0x00C0
76#define IEEE80211_STYPE_ACTION 0x00D0
77
78/* control */
79#define IEEE80211_STYPE_TRIGGER 0x0020
80#define IEEE80211_STYPE_CTL_EXT 0x0060
81#define IEEE80211_STYPE_BACK_REQ 0x0080
82#define IEEE80211_STYPE_BACK 0x0090
83#define IEEE80211_STYPE_PSPOLL 0x00A0
84#define IEEE80211_STYPE_RTS 0x00B0
85#define IEEE80211_STYPE_CTS 0x00C0
86#define IEEE80211_STYPE_ACK 0x00D0
87#define IEEE80211_STYPE_CFEND 0x00E0
88#define IEEE80211_STYPE_CFENDACK 0x00F0
89
90/* data */
91#define IEEE80211_STYPE_DATA 0x0000
92#define IEEE80211_STYPE_DATA_CFACK 0x0010
93#define IEEE80211_STYPE_DATA_CFPOLL 0x0020
94#define IEEE80211_STYPE_DATA_CFACKPOLL 0x0030
95#define IEEE80211_STYPE_NULLFUNC 0x0040
96#define IEEE80211_STYPE_CFACK 0x0050
97#define IEEE80211_STYPE_CFPOLL 0x0060
98#define IEEE80211_STYPE_CFACKPOLL 0x0070
99#define IEEE80211_STYPE_QOS_DATA 0x0080
100#define IEEE80211_STYPE_QOS_DATA_CFACK 0x0090
101#define IEEE80211_STYPE_QOS_DATA_CFPOLL 0x00A0
102#define IEEE80211_STYPE_QOS_DATA_CFACKPOLL 0x00B0
103#define IEEE80211_STYPE_QOS_NULLFUNC 0x00C0
104#define IEEE80211_STYPE_QOS_CFACK 0x00D0
105#define IEEE80211_STYPE_QOS_CFPOLL 0x00E0
106#define IEEE80211_STYPE_QOS_CFACKPOLL 0x00F0
107
108/* extension, added by 802.11ad */
109#define IEEE80211_STYPE_DMG_BEACON 0x0000
110#define IEEE80211_STYPE_S1G_BEACON 0x0010
111
112/* bits unique to S1G beacon */
113#define IEEE80211_S1G_BCN_NEXT_TBTT 0x100
114#define IEEE80211_S1G_BCN_CSSID 0x200
115#define IEEE80211_S1G_BCN_ANO 0x400
116
117/* see 802.11ah-2016 9.9 NDP CMAC frames */
118#define IEEE80211_S1G_1MHZ_NDP_BITS 25
119#define IEEE80211_S1G_1MHZ_NDP_BYTES 4
120#define IEEE80211_S1G_2MHZ_NDP_BITS 37
121#define IEEE80211_S1G_2MHZ_NDP_BYTES 5
122
123#define IEEE80211_NDP_FTYPE_CTS 0
124#define IEEE80211_NDP_FTYPE_CF_END 0
125#define IEEE80211_NDP_FTYPE_PS_POLL 1
126#define IEEE80211_NDP_FTYPE_ACK 2
127#define IEEE80211_NDP_FTYPE_PS_POLL_ACK 3
128#define IEEE80211_NDP_FTYPE_BA 4
129#define IEEE80211_NDP_FTYPE_BF_REPORT_POLL 5
130#define IEEE80211_NDP_FTYPE_PAGING 6
131#define IEEE80211_NDP_FTYPE_PREQ 7
132
133#define SM64(f, v) ((((u64)v) << f##_S) & f)
134
135/* NDP CMAC frame fields */
136#define IEEE80211_NDP_FTYPE 0x0000000000000007
137#define IEEE80211_NDP_FTYPE_S 0x0000000000000000
138
139/* 1M Probe Request 11ah 9.9.3.1.1 */
140#define IEEE80211_NDP_1M_PREQ_ANO 0x0000000000000008
141#define IEEE80211_NDP_1M_PREQ_ANO_S 3
142#define IEEE80211_NDP_1M_PREQ_CSSID 0x00000000000FFFF0
143#define IEEE80211_NDP_1M_PREQ_CSSID_S 4
144#define IEEE80211_NDP_1M_PREQ_RTYPE 0x0000000000100000
145#define IEEE80211_NDP_1M_PREQ_RTYPE_S 20
146#define IEEE80211_NDP_1M_PREQ_RSV 0x0000000001E00000
147#define IEEE80211_NDP_1M_PREQ_RSV 0x0000000001E00000
148/* 2M Probe Request 11ah 9.9.3.1.2 */
149#define IEEE80211_NDP_2M_PREQ_ANO 0x0000000000000008
150#define IEEE80211_NDP_2M_PREQ_ANO_S 3
151#define IEEE80211_NDP_2M_PREQ_CSSID 0x0000000FFFFFFFF0
152#define IEEE80211_NDP_2M_PREQ_CSSID_S 4
153#define IEEE80211_NDP_2M_PREQ_RTYPE 0x0000001000000000
154#define IEEE80211_NDP_2M_PREQ_RTYPE_S 36
155
156#define IEEE80211_ANO_NETTYPE_WILD 15
157
158/* control extension - for IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTL_EXT */
159#define IEEE80211_CTL_EXT_POLL 0x2000
160#define IEEE80211_CTL_EXT_SPR 0x3000
161#define IEEE80211_CTL_EXT_GRANT 0x4000
162#define IEEE80211_CTL_EXT_DMG_CTS 0x5000
163#define IEEE80211_CTL_EXT_DMG_DTS 0x6000
164#define IEEE80211_CTL_EXT_SSW 0x8000
165#define IEEE80211_CTL_EXT_SSW_FBACK 0x9000
166#define IEEE80211_CTL_EXT_SSW_ACK 0xa000
167
168
169#define IEEE80211_SN_MASK ((IEEE80211_SCTL_SEQ) >> 4)
170#define IEEE80211_MAX_SN IEEE80211_SN_MASK
171#define IEEE80211_SN_MODULO (IEEE80211_MAX_SN + 1)
172
173
174/* PV1 Layout IEEE 802.11-2020 9.8.3.1 */
175#define IEEE80211_PV1_FCTL_VERS 0x0003
176#define IEEE80211_PV1_FCTL_FTYPE 0x001c
177#define IEEE80211_PV1_FCTL_STYPE 0x00e0
178#define IEEE80211_PV1_FCTL_FROMDS 0x0100
179#define IEEE80211_PV1_FCTL_MOREFRAGS 0x0200
180#define IEEE80211_PV1_FCTL_PM 0x0400
181#define IEEE80211_PV1_FCTL_MOREDATA 0x0800
182#define IEEE80211_PV1_FCTL_PROTECTED 0x1000
183#define IEEE80211_PV1_FCTL_END_SP 0x2000
184#define IEEE80211_PV1_FCTL_RELAYED 0x4000
185#define IEEE80211_PV1_FCTL_ACK_POLICY 0x8000
186#define IEEE80211_PV1_FCTL_CTL_EXT 0x0f00
187
188static inline bool ieee80211_sn_less(u16 sn1, u16 sn2)
189{
190 return ((sn1 - sn2) & IEEE80211_SN_MASK) > (IEEE80211_SN_MODULO >> 1);
191}
192
193static inline bool ieee80211_sn_less_eq(u16 sn1, u16 sn2)
194{
195 return ((sn2 - sn1) & IEEE80211_SN_MASK) <= (IEEE80211_SN_MODULO >> 1);
196}
197
198static inline u16 ieee80211_sn_add(u16 sn1, u16 sn2)
199{
200 return (sn1 + sn2) & IEEE80211_SN_MASK;
201}
202
203static inline u16 ieee80211_sn_inc(u16 sn)
204{
205 return ieee80211_sn_add(sn1: sn, sn2: 1);
206}
207
208static inline u16 ieee80211_sn_sub(u16 sn1, u16 sn2)
209{
210 return (sn1 - sn2) & IEEE80211_SN_MASK;
211}
212
213#define IEEE80211_SEQ_TO_SN(seq) (((seq) & IEEE80211_SCTL_SEQ) >> 4)
214#define IEEE80211_SN_TO_SEQ(ssn) (((ssn) << 4) & IEEE80211_SCTL_SEQ)
215
216/* miscellaneous IEEE 802.11 constants */
217#define IEEE80211_MAX_FRAG_THRESHOLD 2352
218#define IEEE80211_MAX_RTS_THRESHOLD 2353
219#define IEEE80211_MAX_AID 2007
220#define IEEE80211_MAX_AID_S1G 8191
221#define IEEE80211_MAX_TIM_LEN 251
222#define IEEE80211_MAX_MESH_PEERINGS 63
223
224/* S1G encoding types */
225#define IEEE80211_S1G_TIM_ENC_MODE_BLOCK 0
226#define IEEE80211_S1G_TIM_ENC_MODE_SINGLE 1
227#define IEEE80211_S1G_TIM_ENC_MODE_OLB 2
228
229/* Maximum size for the MA-UNITDATA primitive, 802.11 standard section
230 6.2.1.1.2.
231
232 802.11e clarifies the figure in section 7.1.2. The frame body is
233 up to 2304 octets long (maximum MSDU size) plus any crypt overhead. */
234#define IEEE80211_MAX_DATA_LEN 2304
235/* 802.11ad extends maximum MSDU size for DMG (freq > 40Ghz) networks
236 * to 7920 bytes, see 8.2.3 General frame format
237 */
238#define IEEE80211_MAX_DATA_LEN_DMG 7920
239/* 30 byte 4 addr hdr, 2 byte QoS, 2304 byte MSDU, 12 byte crypt, 4 byte FCS */
240#define IEEE80211_MAX_FRAME_LEN 2352
241
242/* Maximal size of an A-MSDU that can be transported in a HT BA session */
243#define IEEE80211_MAX_MPDU_LEN_HT_BA 4095
244
245/* Maximal size of an A-MSDU */
246#define IEEE80211_MAX_MPDU_LEN_HT_3839 3839
247#define IEEE80211_MAX_MPDU_LEN_HT_7935 7935
248
249#define IEEE80211_MAX_MPDU_LEN_VHT_3895 3895
250#define IEEE80211_MAX_MPDU_LEN_VHT_7991 7991
251#define IEEE80211_MAX_MPDU_LEN_VHT_11454 11454
252
253#define IEEE80211_MAX_SSID_LEN 32
254
255#define IEEE80211_MAX_MESH_ID_LEN 32
256
257#define IEEE80211_FIRST_TSPEC_TSID 8
258#define IEEE80211_NUM_TIDS 16
259
260/* number of user priorities 802.11 uses */
261#define IEEE80211_NUM_UPS 8
262/* number of ACs */
263#define IEEE80211_NUM_ACS 4
264
265#define IEEE80211_QOS_CTL_LEN 2
266/* 1d tag mask */
267#define IEEE80211_QOS_CTL_TAG1D_MASK 0x0007
268/* TID mask */
269#define IEEE80211_QOS_CTL_TID_MASK 0x000f
270/* EOSP */
271#define IEEE80211_QOS_CTL_EOSP 0x0010
272/* ACK policy */
273#define IEEE80211_QOS_CTL_ACK_POLICY_NORMAL 0x0000
274#define IEEE80211_QOS_CTL_ACK_POLICY_NOACK 0x0020
275#define IEEE80211_QOS_CTL_ACK_POLICY_NO_EXPL 0x0040
276#define IEEE80211_QOS_CTL_ACK_POLICY_BLOCKACK 0x0060
277#define IEEE80211_QOS_CTL_ACK_POLICY_MASK 0x0060
278/* A-MSDU 802.11n */
279#define IEEE80211_QOS_CTL_A_MSDU_PRESENT 0x0080
280/* Mesh Control 802.11s */
281#define IEEE80211_QOS_CTL_MESH_CONTROL_PRESENT 0x0100
282
283/* Mesh Power Save Level */
284#define IEEE80211_QOS_CTL_MESH_PS_LEVEL 0x0200
285/* Mesh Receiver Service Period Initiated */
286#define IEEE80211_QOS_CTL_RSPI 0x0400
287
288/* U-APSD queue for WMM IEs sent by AP */
289#define IEEE80211_WMM_IE_AP_QOSINFO_UAPSD (1<<7)
290#define IEEE80211_WMM_IE_AP_QOSINFO_PARAM_SET_CNT_MASK 0x0f
291
292/* U-APSD queues for WMM IEs sent by STA */
293#define IEEE80211_WMM_IE_STA_QOSINFO_AC_VO (1<<0)
294#define IEEE80211_WMM_IE_STA_QOSINFO_AC_VI (1<<1)
295#define IEEE80211_WMM_IE_STA_QOSINFO_AC_BK (1<<2)
296#define IEEE80211_WMM_IE_STA_QOSINFO_AC_BE (1<<3)
297#define IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK 0x0f
298
299/* U-APSD max SP length for WMM IEs sent by STA */
300#define IEEE80211_WMM_IE_STA_QOSINFO_SP_ALL 0x00
301#define IEEE80211_WMM_IE_STA_QOSINFO_SP_2 0x01
302#define IEEE80211_WMM_IE_STA_QOSINFO_SP_4 0x02
303#define IEEE80211_WMM_IE_STA_QOSINFO_SP_6 0x03
304#define IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK 0x03
305#define IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT 5
306
307#define IEEE80211_HT_CTL_LEN 4
308
309/* trigger type within common_info of trigger frame */
310#define IEEE80211_TRIGGER_TYPE_MASK 0xf
311#define IEEE80211_TRIGGER_TYPE_BASIC 0x0
312#define IEEE80211_TRIGGER_TYPE_BFRP 0x1
313#define IEEE80211_TRIGGER_TYPE_MU_BAR 0x2
314#define IEEE80211_TRIGGER_TYPE_MU_RTS 0x3
315#define IEEE80211_TRIGGER_TYPE_BSRP 0x4
316#define IEEE80211_TRIGGER_TYPE_GCR_MU_BAR 0x5
317#define IEEE80211_TRIGGER_TYPE_BQRP 0x6
318#define IEEE80211_TRIGGER_TYPE_NFRP 0x7
319
320/* UL-bandwidth within common_info of trigger frame */
321#define IEEE80211_TRIGGER_ULBW_MASK 0xc0000
322#define IEEE80211_TRIGGER_ULBW_20MHZ 0x0
323#define IEEE80211_TRIGGER_ULBW_40MHZ 0x1
324#define IEEE80211_TRIGGER_ULBW_80MHZ 0x2
325#define IEEE80211_TRIGGER_ULBW_160_80P80MHZ 0x3
326
327struct ieee80211_hdr {
328 __le16 frame_control;
329 __le16 duration_id;
330 struct_group(addrs,
331 u8 addr1[ETH_ALEN];
332 u8 addr2[ETH_ALEN];
333 u8 addr3[ETH_ALEN];
334 );
335 __le16 seq_ctrl;
336 u8 addr4[ETH_ALEN];
337} __packed __aligned(2);
338
339struct ieee80211_hdr_3addr {
340 __le16 frame_control;
341 __le16 duration_id;
342 u8 addr1[ETH_ALEN];
343 u8 addr2[ETH_ALEN];
344 u8 addr3[ETH_ALEN];
345 __le16 seq_ctrl;
346} __packed __aligned(2);
347
348struct ieee80211_qos_hdr {
349 __le16 frame_control;
350 __le16 duration_id;
351 u8 addr1[ETH_ALEN];
352 u8 addr2[ETH_ALEN];
353 u8 addr3[ETH_ALEN];
354 __le16 seq_ctrl;
355 __le16 qos_ctrl;
356} __packed __aligned(2);
357
358struct ieee80211_qos_hdr_4addr {
359 __le16 frame_control;
360 __le16 duration_id;
361 u8 addr1[ETH_ALEN];
362 u8 addr2[ETH_ALEN];
363 u8 addr3[ETH_ALEN];
364 __le16 seq_ctrl;
365 u8 addr4[ETH_ALEN];
366 __le16 qos_ctrl;
367} __packed __aligned(2);
368
369struct ieee80211_trigger {
370 __le16 frame_control;
371 __le16 duration;
372 u8 ra[ETH_ALEN];
373 u8 ta[ETH_ALEN];
374 __le64 common_info;
375 u8 variable[];
376} __packed __aligned(2);
377
378/**
379 * ieee80211_has_tods - check if IEEE80211_FCTL_TODS is set
380 * @fc: frame control bytes in little-endian byteorder
381 * Return: whether or not the frame has to-DS set
382 */
383static inline bool ieee80211_has_tods(__le16 fc)
384{
385 return (fc & cpu_to_le16(IEEE80211_FCTL_TODS)) != 0;
386}
387
388/**
389 * ieee80211_has_fromds - check if IEEE80211_FCTL_FROMDS is set
390 * @fc: frame control bytes in little-endian byteorder
391 * Return: whether or not the frame has from-DS set
392 */
393static inline bool ieee80211_has_fromds(__le16 fc)
394{
395 return (fc & cpu_to_le16(IEEE80211_FCTL_FROMDS)) != 0;
396}
397
398/**
399 * ieee80211_has_a4 - check if IEEE80211_FCTL_TODS and IEEE80211_FCTL_FROMDS are set
400 * @fc: frame control bytes in little-endian byteorder
401 * Return: whether or not it's a 4-address frame (from-DS and to-DS set)
402 */
403static inline bool ieee80211_has_a4(__le16 fc)
404{
405 __le16 tmp = cpu_to_le16(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS);
406 return (fc & tmp) == tmp;
407}
408
409/**
410 * ieee80211_has_morefrags - check if IEEE80211_FCTL_MOREFRAGS is set
411 * @fc: frame control bytes in little-endian byteorder
412 * Return: whether or not the frame has more fragments (more frags bit set)
413 */
414static inline bool ieee80211_has_morefrags(__le16 fc)
415{
416 return (fc & cpu_to_le16(IEEE80211_FCTL_MOREFRAGS)) != 0;
417}
418
419/**
420 * ieee80211_has_retry - check if IEEE80211_FCTL_RETRY is set
421 * @fc: frame control bytes in little-endian byteorder
422 * Return: whether or not the retry flag is set
423 */
424static inline bool ieee80211_has_retry(__le16 fc)
425{
426 return (fc & cpu_to_le16(IEEE80211_FCTL_RETRY)) != 0;
427}
428
429/**
430 * ieee80211_has_pm - check if IEEE80211_FCTL_PM is set
431 * @fc: frame control bytes in little-endian byteorder
432 * Return: whether or not the power management flag is set
433 */
434static inline bool ieee80211_has_pm(__le16 fc)
435{
436 return (fc & cpu_to_le16(IEEE80211_FCTL_PM)) != 0;
437}
438
439/**
440 * ieee80211_has_moredata - check if IEEE80211_FCTL_MOREDATA is set
441 * @fc: frame control bytes in little-endian byteorder
442 * Return: whether or not the more data flag is set
443 */
444static inline bool ieee80211_has_moredata(__le16 fc)
445{
446 return (fc & cpu_to_le16(IEEE80211_FCTL_MOREDATA)) != 0;
447}
448
449/**
450 * ieee80211_has_protected - check if IEEE80211_FCTL_PROTECTED is set
451 * @fc: frame control bytes in little-endian byteorder
452 * Return: whether or not the protected flag is set
453 */
454static inline bool ieee80211_has_protected(__le16 fc)
455{
456 return (fc & cpu_to_le16(IEEE80211_FCTL_PROTECTED)) != 0;
457}
458
459/**
460 * ieee80211_has_order - check if IEEE80211_FCTL_ORDER is set
461 * @fc: frame control bytes in little-endian byteorder
462 * Return: whether or not the order flag is set
463 */
464static inline bool ieee80211_has_order(__le16 fc)
465{
466 return (fc & cpu_to_le16(IEEE80211_FCTL_ORDER)) != 0;
467}
468
469/**
470 * ieee80211_is_mgmt - check if type is IEEE80211_FTYPE_MGMT
471 * @fc: frame control bytes in little-endian byteorder
472 * Return: whether or not the frame type is management
473 */
474static inline bool ieee80211_is_mgmt(__le16 fc)
475{
476 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE)) ==
477 cpu_to_le16(IEEE80211_FTYPE_MGMT);
478}
479
480/**
481 * ieee80211_is_ctl - check if type is IEEE80211_FTYPE_CTL
482 * @fc: frame control bytes in little-endian byteorder
483 * Return: whether or not the frame type is control
484 */
485static inline bool ieee80211_is_ctl(__le16 fc)
486{
487 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE)) ==
488 cpu_to_le16(IEEE80211_FTYPE_CTL);
489}
490
491/**
492 * ieee80211_is_data - check if type is IEEE80211_FTYPE_DATA
493 * @fc: frame control bytes in little-endian byteorder
494 * Return: whether or not the frame is a data frame
495 */
496static inline bool ieee80211_is_data(__le16 fc)
497{
498 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE)) ==
499 cpu_to_le16(IEEE80211_FTYPE_DATA);
500}
501
502/**
503 * ieee80211_is_ext - check if type is IEEE80211_FTYPE_EXT
504 * @fc: frame control bytes in little-endian byteorder
505 * Return: whether or not the frame type is extended
506 */
507static inline bool ieee80211_is_ext(__le16 fc)
508{
509 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE)) ==
510 cpu_to_le16(IEEE80211_FTYPE_EXT);
511}
512
513
514/**
515 * ieee80211_is_data_qos - check if type is IEEE80211_FTYPE_DATA and IEEE80211_STYPE_QOS_DATA is set
516 * @fc: frame control bytes in little-endian byteorder
517 * Return: whether or not the frame is a QoS data frame
518 */
519static inline bool ieee80211_is_data_qos(__le16 fc)
520{
521 /*
522 * mask with QOS_DATA rather than IEEE80211_FCTL_STYPE as we just need
523 * to check the one bit
524 */
525 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_STYPE_QOS_DATA)) ==
526 cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_QOS_DATA);
527}
528
529/**
530 * ieee80211_is_data_present - check if type is IEEE80211_FTYPE_DATA and has data
531 * @fc: frame control bytes in little-endian byteorder
532 * Return: whether or not the frame is a QoS data frame that has data
533 * (i.e. is not null data)
534 */
535static inline bool ieee80211_is_data_present(__le16 fc)
536{
537 /*
538 * mask with 0x40 and test that that bit is clear to only return true
539 * for the data-containing substypes.
540 */
541 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | 0x40)) ==
542 cpu_to_le16(IEEE80211_FTYPE_DATA);
543}
544
545/**
546 * ieee80211_is_assoc_req - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_ASSOC_REQ
547 * @fc: frame control bytes in little-endian byteorder
548 * Return: whether or not the frame is an association request
549 */
550static inline bool ieee80211_is_assoc_req(__le16 fc)
551{
552 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
553 cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ASSOC_REQ);
554}
555
556/**
557 * ieee80211_is_assoc_resp - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_ASSOC_RESP
558 * @fc: frame control bytes in little-endian byteorder
559 * Return: whether or not the frame is an association response
560 */
561static inline bool ieee80211_is_assoc_resp(__le16 fc)
562{
563 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
564 cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ASSOC_RESP);
565}
566
567/**
568 * ieee80211_is_reassoc_req - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_REASSOC_REQ
569 * @fc: frame control bytes in little-endian byteorder
570 * Return: whether or not the frame is a reassociation request
571 */
572static inline bool ieee80211_is_reassoc_req(__le16 fc)
573{
574 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
575 cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_REASSOC_REQ);
576}
577
578/**
579 * ieee80211_is_reassoc_resp - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_REASSOC_RESP
580 * @fc: frame control bytes in little-endian byteorder
581 * Return: whether or not the frame is a reassociation response
582 */
583static inline bool ieee80211_is_reassoc_resp(__le16 fc)
584{
585 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
586 cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_REASSOC_RESP);
587}
588
589/**
590 * ieee80211_is_probe_req - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_PROBE_REQ
591 * @fc: frame control bytes in little-endian byteorder
592 * Return: whether or not the frame is a probe request
593 */
594static inline bool ieee80211_is_probe_req(__le16 fc)
595{
596 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
597 cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ);
598}
599
600/**
601 * ieee80211_is_probe_resp - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_PROBE_RESP
602 * @fc: frame control bytes in little-endian byteorder
603 * Return: whether or not the frame is a probe response
604 */
605static inline bool ieee80211_is_probe_resp(__le16 fc)
606{
607 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
608 cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_RESP);
609}
610
611/**
612 * ieee80211_is_beacon - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_BEACON
613 * @fc: frame control bytes in little-endian byteorder
614 * Return: whether or not the frame is a (regular, not S1G) beacon
615 */
616static inline bool ieee80211_is_beacon(__le16 fc)
617{
618 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
619 cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_BEACON);
620}
621
622/**
623 * ieee80211_is_s1g_beacon - check if IEEE80211_FTYPE_EXT &&
624 * IEEE80211_STYPE_S1G_BEACON
625 * @fc: frame control bytes in little-endian byteorder
626 * Return: whether or not the frame is an S1G beacon
627 */
628static inline bool ieee80211_is_s1g_beacon(__le16 fc)
629{
630 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE |
631 IEEE80211_FCTL_STYPE)) ==
632 cpu_to_le16(IEEE80211_FTYPE_EXT | IEEE80211_STYPE_S1G_BEACON);
633}
634
635/**
636 * ieee80211_s1g_has_next_tbtt - check if IEEE80211_S1G_BCN_NEXT_TBTT
637 * @fc: frame control bytes in little-endian byteorder
638 * Return: whether or not the frame contains the variable-length
639 * next TBTT field
640 */
641static inline bool ieee80211_s1g_has_next_tbtt(__le16 fc)
642{
643 return ieee80211_is_s1g_beacon(fc) &&
644 (fc & cpu_to_le16(IEEE80211_S1G_BCN_NEXT_TBTT));
645}
646
647/**
648 * ieee80211_s1g_has_ano - check if IEEE80211_S1G_BCN_ANO
649 * @fc: frame control bytes in little-endian byteorder
650 * Return: whether or not the frame contains the variable-length
651 * ANO field
652 */
653static inline bool ieee80211_s1g_has_ano(__le16 fc)
654{
655 return ieee80211_is_s1g_beacon(fc) &&
656 (fc & cpu_to_le16(IEEE80211_S1G_BCN_ANO));
657}
658
659/**
660 * ieee80211_s1g_has_cssid - check if IEEE80211_S1G_BCN_CSSID
661 * @fc: frame control bytes in little-endian byteorder
662 * Return: whether or not the frame contains the variable-length
663 * compressed SSID field
664 */
665static inline bool ieee80211_s1g_has_cssid(__le16 fc)
666{
667 return ieee80211_is_s1g_beacon(fc) &&
668 (fc & cpu_to_le16(IEEE80211_S1G_BCN_CSSID));
669}
670
671/**
672 * ieee80211_is_atim - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_ATIM
673 * @fc: frame control bytes in little-endian byteorder
674 * Return: whether or not the frame is an ATIM frame
675 */
676static inline bool ieee80211_is_atim(__le16 fc)
677{
678 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
679 cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ATIM);
680}
681
682/**
683 * ieee80211_is_disassoc - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_DISASSOC
684 * @fc: frame control bytes in little-endian byteorder
685 * Return: whether or not the frame is a disassociation frame
686 */
687static inline bool ieee80211_is_disassoc(__le16 fc)
688{
689 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
690 cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_DISASSOC);
691}
692
693/**
694 * ieee80211_is_auth - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_AUTH
695 * @fc: frame control bytes in little-endian byteorder
696 * Return: whether or not the frame is an authentication frame
697 */
698static inline bool ieee80211_is_auth(__le16 fc)
699{
700 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
701 cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_AUTH);
702}
703
704/**
705 * ieee80211_is_deauth - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_DEAUTH
706 * @fc: frame control bytes in little-endian byteorder
707 * Return: whether or not the frame is a deauthentication frame
708 */
709static inline bool ieee80211_is_deauth(__le16 fc)
710{
711 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
712 cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_DEAUTH);
713}
714
715/**
716 * ieee80211_is_action - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_ACTION
717 * @fc: frame control bytes in little-endian byteorder
718 * Return: whether or not the frame is an action frame
719 */
720static inline bool ieee80211_is_action(__le16 fc)
721{
722 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
723 cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION);
724}
725
726/**
727 * ieee80211_is_back_req - check if IEEE80211_FTYPE_CTL && IEEE80211_STYPE_BACK_REQ
728 * @fc: frame control bytes in little-endian byteorder
729 * Return: whether or not the frame is a block-ACK request frame
730 */
731static inline bool ieee80211_is_back_req(__le16 fc)
732{
733 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
734 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_BACK_REQ);
735}
736
737/**
738 * ieee80211_is_back - check if IEEE80211_FTYPE_CTL && IEEE80211_STYPE_BACK
739 * @fc: frame control bytes in little-endian byteorder
740 * Return: whether or not the frame is a block-ACK frame
741 */
742static inline bool ieee80211_is_back(__le16 fc)
743{
744 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
745 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_BACK);
746}
747
748/**
749 * ieee80211_is_pspoll - check if IEEE80211_FTYPE_CTL && IEEE80211_STYPE_PSPOLL
750 * @fc: frame control bytes in little-endian byteorder
751 * Return: whether or not the frame is a PS-poll frame
752 */
753static inline bool ieee80211_is_pspoll(__le16 fc)
754{
755 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
756 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_PSPOLL);
757}
758
759/**
760 * ieee80211_is_rts - check if IEEE80211_FTYPE_CTL && IEEE80211_STYPE_RTS
761 * @fc: frame control bytes in little-endian byteorder
762 * Return: whether or not the frame is an RTS frame
763 */
764static inline bool ieee80211_is_rts(__le16 fc)
765{
766 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
767 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
768}
769
770/**
771 * ieee80211_is_cts - check if IEEE80211_FTYPE_CTL && IEEE80211_STYPE_CTS
772 * @fc: frame control bytes in little-endian byteorder
773 * Return: whether or not the frame is a CTS frame
774 */
775static inline bool ieee80211_is_cts(__le16 fc)
776{
777 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
778 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
779}
780
781/**
782 * ieee80211_is_ack - check if IEEE80211_FTYPE_CTL && IEEE80211_STYPE_ACK
783 * @fc: frame control bytes in little-endian byteorder
784 * Return: whether or not the frame is an ACK frame
785 */
786static inline bool ieee80211_is_ack(__le16 fc)
787{
788 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
789 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_ACK);
790}
791
792/**
793 * ieee80211_is_cfend - check if IEEE80211_FTYPE_CTL && IEEE80211_STYPE_CFEND
794 * @fc: frame control bytes in little-endian byteorder
795 * Return: whether or not the frame is a CF-end frame
796 */
797static inline bool ieee80211_is_cfend(__le16 fc)
798{
799 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
800 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CFEND);
801}
802
803/**
804 * ieee80211_is_cfendack - check if IEEE80211_FTYPE_CTL && IEEE80211_STYPE_CFENDACK
805 * @fc: frame control bytes in little-endian byteorder
806 * Return: whether or not the frame is a CF-end-ack frame
807 */
808static inline bool ieee80211_is_cfendack(__le16 fc)
809{
810 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
811 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CFENDACK);
812}
813
814/**
815 * ieee80211_is_nullfunc - check if frame is a regular (non-QoS) nullfunc frame
816 * @fc: frame control bytes in little-endian byteorder
817 * Return: whether or not the frame is a nullfunc frame
818 */
819static inline bool ieee80211_is_nullfunc(__le16 fc)
820{
821 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
822 cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC);
823}
824
825/**
826 * ieee80211_is_qos_nullfunc - check if frame is a QoS nullfunc frame
827 * @fc: frame control bytes in little-endian byteorder
828 * Return: whether or not the frame is a QoS nullfunc frame
829 */
830static inline bool ieee80211_is_qos_nullfunc(__le16 fc)
831{
832 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
833 cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_QOS_NULLFUNC);
834}
835
836/**
837 * ieee80211_is_trigger - check if frame is trigger frame
838 * @fc: frame control field in little-endian byteorder
839 * Return: whether or not the frame is a trigger frame
840 */
841static inline bool ieee80211_is_trigger(__le16 fc)
842{
843 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
844 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_TRIGGER);
845}
846
847/**
848 * ieee80211_is_any_nullfunc - check if frame is regular or QoS nullfunc frame
849 * @fc: frame control bytes in little-endian byteorder
850 * Return: whether or not the frame is a nullfunc or QoS nullfunc frame
851 */
852static inline bool ieee80211_is_any_nullfunc(__le16 fc)
853{
854 return (ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc));
855}
856
857/**
858 * ieee80211_is_first_frag - check if IEEE80211_SCTL_FRAG is not set
859 * @seq_ctrl: frame sequence control bytes in little-endian byteorder
860 * Return: whether or not the frame is the first fragment (also true if
861 * it's not fragmented at all)
862 */
863static inline bool ieee80211_is_first_frag(__le16 seq_ctrl)
864{
865 return (seq_ctrl & cpu_to_le16(IEEE80211_SCTL_FRAG)) == 0;
866}
867
868/**
869 * ieee80211_is_frag - check if a frame is a fragment
870 * @hdr: 802.11 header of the frame
871 * Return: whether or not the frame is a fragment
872 */
873static inline bool ieee80211_is_frag(struct ieee80211_hdr *hdr)
874{
875 return ieee80211_has_morefrags(fc: hdr->frame_control) ||
876 hdr->seq_ctrl & cpu_to_le16(IEEE80211_SCTL_FRAG);
877}
878
879static inline u16 ieee80211_get_sn(struct ieee80211_hdr *hdr)
880{
881 return le16_get_bits(v: hdr->seq_ctrl, IEEE80211_SCTL_SEQ);
882}
883
884struct ieee80211s_hdr {
885 u8 flags;
886 u8 ttl;
887 __le32 seqnum;
888 u8 eaddr1[ETH_ALEN];
889 u8 eaddr2[ETH_ALEN];
890} __packed __aligned(2);
891
892/* Mesh flags */
893#define MESH_FLAGS_AE_A4 0x1
894#define MESH_FLAGS_AE_A5_A6 0x2
895#define MESH_FLAGS_AE 0x3
896#define MESH_FLAGS_PS_DEEP 0x4
897
898/**
899 * enum ieee80211_preq_flags - mesh PREQ element flags
900 *
901 * @IEEE80211_PREQ_PROACTIVE_PREP_FLAG: proactive PREP subfield
902 */
903enum ieee80211_preq_flags {
904 IEEE80211_PREQ_PROACTIVE_PREP_FLAG = 1<<2,
905};
906
907/**
908 * enum ieee80211_preq_target_flags - mesh PREQ element per target flags
909 *
910 * @IEEE80211_PREQ_TO_FLAG: target only subfield
911 * @IEEE80211_PREQ_USN_FLAG: unknown target HWMP sequence number subfield
912 */
913enum ieee80211_preq_target_flags {
914 IEEE80211_PREQ_TO_FLAG = 1<<0,
915 IEEE80211_PREQ_USN_FLAG = 1<<2,
916};
917
918/**
919 * struct ieee80211_quiet_ie - Quiet element
920 * @count: Quiet Count
921 * @period: Quiet Period
922 * @duration: Quiet Duration
923 * @offset: Quiet Offset
924 *
925 * This structure represents the payload of the "Quiet element" as
926 * described in IEEE Std 802.11-2020 section 9.4.2.22.
927 */
928struct ieee80211_quiet_ie {
929 u8 count;
930 u8 period;
931 __le16 duration;
932 __le16 offset;
933} __packed;
934
935/**
936 * struct ieee80211_msrment_ie - Measurement element
937 * @token: Measurement Token
938 * @mode: Measurement Report Mode
939 * @type: Measurement Type
940 * @request: Measurement Request or Measurement Report
941 *
942 * This structure represents the payload of both the "Measurement
943 * Request element" and the "Measurement Report element" as described
944 * in IEEE Std 802.11-2020 sections 9.4.2.20 and 9.4.2.21.
945 */
946struct ieee80211_msrment_ie {
947 u8 token;
948 u8 mode;
949 u8 type;
950 u8 request[];
951} __packed;
952
953/**
954 * struct ieee80211_channel_sw_ie - Channel Switch Announcement element
955 * @mode: Channel Switch Mode
956 * @new_ch_num: New Channel Number
957 * @count: Channel Switch Count
958 *
959 * This structure represents the payload of the "Channel Switch
960 * Announcement element" as described in IEEE Std 802.11-2020 section
961 * 9.4.2.18.
962 */
963struct ieee80211_channel_sw_ie {
964 u8 mode;
965 u8 new_ch_num;
966 u8 count;
967} __packed;
968
969/**
970 * struct ieee80211_ext_chansw_ie - Extended Channel Switch Announcement element
971 * @mode: Channel Switch Mode
972 * @new_operating_class: New Operating Class
973 * @new_ch_num: New Channel Number
974 * @count: Channel Switch Count
975 *
976 * This structure represents the "Extended Channel Switch Announcement
977 * element" as described in IEEE Std 802.11-2020 section 9.4.2.52.
978 */
979struct ieee80211_ext_chansw_ie {
980 u8 mode;
981 u8 new_operating_class;
982 u8 new_ch_num;
983 u8 count;
984} __packed;
985
986/**
987 * struct ieee80211_sec_chan_offs_ie - secondary channel offset IE
988 * @sec_chan_offs: secondary channel offset, uses IEEE80211_HT_PARAM_CHA_SEC_*
989 * values here
990 * This structure represents the "Secondary Channel Offset element"
991 */
992struct ieee80211_sec_chan_offs_ie {
993 u8 sec_chan_offs;
994} __packed;
995
996/**
997 * struct ieee80211_mesh_chansw_params_ie - mesh channel switch parameters IE
998 * @mesh_ttl: Time To Live
999 * @mesh_flags: Flags
1000 * @mesh_reason: Reason Code
1001 * @mesh_pre_value: Precedence Value
1002 *
1003 * This structure represents the payload of the "Mesh Channel Switch
1004 * Parameters element" as described in IEEE Std 802.11-2020 section
1005 * 9.4.2.102.
1006 */
1007struct ieee80211_mesh_chansw_params_ie {
1008 u8 mesh_ttl;
1009 u8 mesh_flags;
1010 __le16 mesh_reason;
1011 __le16 mesh_pre_value;
1012} __packed;
1013
1014/**
1015 * struct ieee80211_wide_bw_chansw_ie - wide bandwidth channel switch IE
1016 * @new_channel_width: New Channel Width
1017 * @new_center_freq_seg0: New Channel Center Frequency Segment 0
1018 * @new_center_freq_seg1: New Channel Center Frequency Segment 1
1019 *
1020 * This structure represents the payload of the "Wide Bandwidth
1021 * Channel Switch element" as described in IEEE Std 802.11-2020
1022 * section 9.4.2.160.
1023 */
1024struct ieee80211_wide_bw_chansw_ie {
1025 u8 new_channel_width;
1026 u8 new_center_freq_seg0, new_center_freq_seg1;
1027} __packed;
1028
1029/**
1030 * struct ieee80211_tim_ie - Traffic Indication Map information element
1031 * @dtim_count: DTIM Count
1032 * @dtim_period: DTIM Period
1033 * @bitmap_ctrl: Bitmap Control
1034 * @required_octet: "Syntatic sugar" to force the struct size to the
1035 * minimum valid size when carried in a non-S1G PPDU
1036 * @virtual_map: Partial Virtual Bitmap
1037 *
1038 * This structure represents the payload of the "TIM element" as
1039 * described in IEEE Std 802.11-2020 section 9.4.2.5. Note that this
1040 * definition is only applicable when the element is carried in a
1041 * non-S1G PPDU. When the TIM is carried in an S1G PPDU, the Bitmap
1042 * Control and Partial Virtual Bitmap may not be present.
1043 */
1044struct ieee80211_tim_ie {
1045 u8 dtim_count;
1046 u8 dtim_period;
1047 u8 bitmap_ctrl;
1048 union {
1049 u8 required_octet;
1050 DECLARE_FLEX_ARRAY(u8, virtual_map);
1051 };
1052} __packed;
1053
1054/**
1055 * struct ieee80211_meshconf_ie - Mesh Configuration element
1056 * @meshconf_psel: Active Path Selection Protocol Identifier
1057 * @meshconf_pmetric: Active Path Selection Metric Identifier
1058 * @meshconf_congest: Congestion Control Mode Identifier
1059 * @meshconf_synch: Synchronization Method Identifier
1060 * @meshconf_auth: Authentication Protocol Identifier
1061 * @meshconf_form: Mesh Formation Info
1062 * @meshconf_cap: Mesh Capability (see &enum mesh_config_capab_flags)
1063 *
1064 * This structure represents the payload of the "Mesh Configuration
1065 * element" as described in IEEE Std 802.11-2020 section 9.4.2.97.
1066 */
1067struct ieee80211_meshconf_ie {
1068 u8 meshconf_psel;
1069 u8 meshconf_pmetric;
1070 u8 meshconf_congest;
1071 u8 meshconf_synch;
1072 u8 meshconf_auth;
1073 u8 meshconf_form;
1074 u8 meshconf_cap;
1075} __packed;
1076
1077/**
1078 * enum mesh_config_capab_flags - Mesh Configuration IE capability field flags
1079 *
1080 * @IEEE80211_MESHCONF_CAPAB_ACCEPT_PLINKS: STA is willing to establish
1081 * additional mesh peerings with other mesh STAs
1082 * @IEEE80211_MESHCONF_CAPAB_FORWARDING: the STA forwards MSDUs
1083 * @IEEE80211_MESHCONF_CAPAB_TBTT_ADJUSTING: TBTT adjustment procedure
1084 * is ongoing
1085 * @IEEE80211_MESHCONF_CAPAB_POWER_SAVE_LEVEL: STA is in deep sleep mode or has
1086 * neighbors in deep sleep mode
1087 *
1088 * Enumerates the "Mesh Capability" as described in IEEE Std
1089 * 802.11-2020 section 9.4.2.97.7.
1090 */
1091enum mesh_config_capab_flags {
1092 IEEE80211_MESHCONF_CAPAB_ACCEPT_PLINKS = 0x01,
1093 IEEE80211_MESHCONF_CAPAB_FORWARDING = 0x08,
1094 IEEE80211_MESHCONF_CAPAB_TBTT_ADJUSTING = 0x20,
1095 IEEE80211_MESHCONF_CAPAB_POWER_SAVE_LEVEL = 0x40,
1096};
1097
1098#define IEEE80211_MESHCONF_FORM_CONNECTED_TO_GATE 0x1
1099
1100/*
1101 * mesh channel switch parameters element's flag indicator
1102 *
1103 */
1104#define WLAN_EID_CHAN_SWITCH_PARAM_TX_RESTRICT BIT(0)
1105#define WLAN_EID_CHAN_SWITCH_PARAM_INITIATOR BIT(1)
1106#define WLAN_EID_CHAN_SWITCH_PARAM_REASON BIT(2)
1107
1108/**
1109 * struct ieee80211_rann_ie - RANN (root announcement) element
1110 * @rann_flags: Flags
1111 * @rann_hopcount: Hop Count
1112 * @rann_ttl: Element TTL
1113 * @rann_addr: Root Mesh STA Address
1114 * @rann_seq: HWMP Sequence Number
1115 * @rann_interval: Interval
1116 * @rann_metric: Metric
1117 *
1118 * This structure represents the payload of the "RANN element" as
1119 * described in IEEE Std 802.11-2020 section 9.4.2.111.
1120 */
1121struct ieee80211_rann_ie {
1122 u8 rann_flags;
1123 u8 rann_hopcount;
1124 u8 rann_ttl;
1125 u8 rann_addr[ETH_ALEN];
1126 __le32 rann_seq;
1127 __le32 rann_interval;
1128 __le32 rann_metric;
1129} __packed;
1130
1131enum ieee80211_rann_flags {
1132 RANN_FLAG_IS_GATE = 1 << 0,
1133};
1134
1135enum ieee80211_ht_chanwidth_values {
1136 IEEE80211_HT_CHANWIDTH_20MHZ = 0,
1137 IEEE80211_HT_CHANWIDTH_ANY = 1,
1138};
1139
1140/**
1141 * enum ieee80211_vht_opmode_bits - VHT operating mode field bits
1142 * @IEEE80211_OPMODE_NOTIF_CHANWIDTH_MASK: channel width mask
1143 * @IEEE80211_OPMODE_NOTIF_CHANWIDTH_20MHZ: 20 MHz channel width
1144 * @IEEE80211_OPMODE_NOTIF_CHANWIDTH_40MHZ: 40 MHz channel width
1145 * @IEEE80211_OPMODE_NOTIF_CHANWIDTH_80MHZ: 80 MHz channel width
1146 * @IEEE80211_OPMODE_NOTIF_CHANWIDTH_160MHZ: 160 MHz or 80+80 MHz channel width
1147 * @IEEE80211_OPMODE_NOTIF_BW_160_80P80: 160 / 80+80 MHz indicator flag
1148 * @IEEE80211_OPMODE_NOTIF_RX_NSS_MASK: number of spatial streams mask
1149 * (the NSS value is the value of this field + 1)
1150 * @IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT: number of spatial streams shift
1151 * @IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF: indicates streams in SU-MIMO PPDU
1152 * using a beamforming steering matrix
1153 */
1154enum ieee80211_vht_opmode_bits {
1155 IEEE80211_OPMODE_NOTIF_CHANWIDTH_MASK = 0x03,
1156 IEEE80211_OPMODE_NOTIF_CHANWIDTH_20MHZ = 0,
1157 IEEE80211_OPMODE_NOTIF_CHANWIDTH_40MHZ = 1,
1158 IEEE80211_OPMODE_NOTIF_CHANWIDTH_80MHZ = 2,
1159 IEEE80211_OPMODE_NOTIF_CHANWIDTH_160MHZ = 3,
1160 IEEE80211_OPMODE_NOTIF_BW_160_80P80 = 0x04,
1161 IEEE80211_OPMODE_NOTIF_RX_NSS_MASK = 0x70,
1162 IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT = 4,
1163 IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF = 0x80,
1164};
1165
1166/**
1167 * enum ieee80211_s1g_chanwidth - S1G channel widths
1168 * These are defined in IEEE802.11-2016ah Table 10-20
1169 * as BSS Channel Width
1170 *
1171 * @IEEE80211_S1G_CHANWIDTH_1MHZ: 1MHz operating channel
1172 * @IEEE80211_S1G_CHANWIDTH_2MHZ: 2MHz operating channel
1173 * @IEEE80211_S1G_CHANWIDTH_4MHZ: 4MHz operating channel
1174 * @IEEE80211_S1G_CHANWIDTH_8MHZ: 8MHz operating channel
1175 * @IEEE80211_S1G_CHANWIDTH_16MHZ: 16MHz operating channel
1176 */
1177enum ieee80211_s1g_chanwidth {
1178 IEEE80211_S1G_CHANWIDTH_1MHZ = 0,
1179 IEEE80211_S1G_CHANWIDTH_2MHZ = 1,
1180 IEEE80211_S1G_CHANWIDTH_4MHZ = 3,
1181 IEEE80211_S1G_CHANWIDTH_8MHZ = 7,
1182 IEEE80211_S1G_CHANWIDTH_16MHZ = 15,
1183};
1184
1185/**
1186 * enum ieee80211_s1g_pri_chanwidth - S1G primary channel widths
1187 * described in IEEE80211-2024 Table 10-39.
1188 *
1189 * @IEEE80211_S1G_PRI_CHANWIDTH_2MHZ: 2MHz primary channel
1190 * @IEEE80211_S1G_PRI_CHANWIDTH_1MHZ: 1MHz primary channel
1191 */
1192enum ieee80211_s1g_pri_chanwidth {
1193 IEEE80211_S1G_PRI_CHANWIDTH_2MHZ = 0,
1194 IEEE80211_S1G_PRI_CHANWIDTH_1MHZ = 1,
1195};
1196
1197#define WLAN_SA_QUERY_TR_ID_LEN 2
1198#define WLAN_MEMBERSHIP_LEN 8
1199#define WLAN_USER_POSITION_LEN 16
1200
1201/**
1202 * struct ieee80211_tpc_report_ie - TPC Report element
1203 * @tx_power: Transmit Power
1204 * @link_margin: Link Margin
1205 *
1206 * This structure represents the payload of the "TPC Report element" as
1207 * described in IEEE Std 802.11-2020 section 9.4.2.16.
1208 */
1209struct ieee80211_tpc_report_ie {
1210 u8 tx_power;
1211 u8 link_margin;
1212} __packed;
1213
1214#define IEEE80211_ADDBA_EXT_FRAG_LEVEL_MASK GENMASK(2, 1)
1215#define IEEE80211_ADDBA_EXT_FRAG_LEVEL_SHIFT 1
1216#define IEEE80211_ADDBA_EXT_NO_FRAG BIT(0)
1217#define IEEE80211_ADDBA_EXT_BUF_SIZE_MASK GENMASK(7, 5)
1218#define IEEE80211_ADDBA_EXT_BUF_SIZE_SHIFT 10
1219
1220struct ieee80211_addba_ext_ie {
1221 u8 data;
1222} __packed;
1223
1224/**
1225 * struct ieee80211_s1g_bcn_compat_ie - S1G Beacon Compatibility element
1226 * @compat_info: Compatibility Information
1227 * @beacon_int: Beacon Interval
1228 * @tsf_completion: TSF Completion
1229 *
1230 * This structure represents the payload of the "S1G Beacon
1231 * Compatibility element" as described in IEEE Std 802.11-2020 section
1232 * 9.4.2.196.
1233 */
1234struct ieee80211_s1g_bcn_compat_ie {
1235 __le16 compat_info;
1236 __le16 beacon_int;
1237 __le32 tsf_completion;
1238} __packed;
1239
1240/**
1241 * struct ieee80211_s1g_oper_ie - S1G Operation element
1242 * @ch_width: S1G Operation Information Channel Width
1243 * @oper_class: S1G Operation Information Operating Class
1244 * @primary_ch: S1G Operation Information Primary Channel Number
1245 * @oper_ch: S1G Operation Information Channel Center Frequency
1246 * @basic_mcs_nss: Basic S1G-MCS and NSS Set
1247 *
1248 * This structure represents the payload of the "S1G Operation
1249 * element" as described in IEEE Std 802.11-2020 section 9.4.2.212.
1250 */
1251struct ieee80211_s1g_oper_ie {
1252 u8 ch_width;
1253 u8 oper_class;
1254 u8 primary_ch;
1255 u8 oper_ch;
1256 __le16 basic_mcs_nss;
1257} __packed;
1258
1259/**
1260 * struct ieee80211_aid_response_ie - AID Response element
1261 * @aid: AID/Group AID
1262 * @switch_count: AID Switch Count
1263 * @response_int: AID Response Interval
1264 *
1265 * This structure represents the payload of the "AID Response element"
1266 * as described in IEEE Std 802.11-2020 section 9.4.2.194.
1267 */
1268struct ieee80211_aid_response_ie {
1269 __le16 aid;
1270 u8 switch_count;
1271 __le16 response_int;
1272} __packed;
1273
1274struct ieee80211_s1g_cap {
1275 u8 capab_info[10];
1276 u8 supp_mcs_nss[5];
1277} __packed;
1278
1279struct ieee80211_ext {
1280 __le16 frame_control;
1281 __le16 duration;
1282 union {
1283 struct {
1284 u8 sa[ETH_ALEN];
1285 __le32 timestamp;
1286 u8 change_seq;
1287 u8 variable[];
1288 } __packed s1g_beacon;
1289 } u;
1290} __packed __aligned(2);
1291
1292/**
1293 * ieee80211_s1g_optional_len - determine length of optional S1G beacon fields
1294 * @fc: frame control bytes in little-endian byteorder
1295 * Return: total length in bytes of the optional fixed-length fields
1296 *
1297 * S1G beacons may contain up to three optional fixed-length fields that
1298 * precede the variable-length elements. Whether these fields are present
1299 * is indicated by flags in the frame control field.
1300 *
1301 * From IEEE 802.11-2024 section 9.3.4.3:
1302 * - Next TBTT field may be 0 or 3 bytes
1303 * - Short SSID field may be 0 or 4 bytes
1304 * - Access Network Options (ANO) field may be 0 or 1 byte
1305 */
1306static inline size_t
1307ieee80211_s1g_optional_len(__le16 fc)
1308{
1309 size_t len = 0;
1310
1311 if (ieee80211_s1g_has_next_tbtt(fc))
1312 len += 3;
1313
1314 if (ieee80211_s1g_has_cssid(fc))
1315 len += 4;
1316
1317 if (ieee80211_s1g_has_ano(fc))
1318 len += 1;
1319
1320 return len;
1321}
1322
1323#define IEEE80211_TWT_CONTROL_NDP BIT(0)
1324#define IEEE80211_TWT_CONTROL_RESP_MODE BIT(1)
1325#define IEEE80211_TWT_CONTROL_NEG_TYPE_BROADCAST BIT(3)
1326#define IEEE80211_TWT_CONTROL_RX_DISABLED BIT(4)
1327#define IEEE80211_TWT_CONTROL_WAKE_DUR_UNIT BIT(5)
1328
1329#define IEEE80211_TWT_REQTYPE_REQUEST BIT(0)
1330#define IEEE80211_TWT_REQTYPE_SETUP_CMD GENMASK(3, 1)
1331#define IEEE80211_TWT_REQTYPE_TRIGGER BIT(4)
1332#define IEEE80211_TWT_REQTYPE_IMPLICIT BIT(5)
1333#define IEEE80211_TWT_REQTYPE_FLOWTYPE BIT(6)
1334#define IEEE80211_TWT_REQTYPE_FLOWID GENMASK(9, 7)
1335#define IEEE80211_TWT_REQTYPE_WAKE_INT_EXP GENMASK(14, 10)
1336#define IEEE80211_TWT_REQTYPE_PROTECTION BIT(15)
1337
1338enum ieee80211_twt_setup_cmd {
1339 TWT_SETUP_CMD_REQUEST,
1340 TWT_SETUP_CMD_SUGGEST,
1341 TWT_SETUP_CMD_DEMAND,
1342 TWT_SETUP_CMD_GROUPING,
1343 TWT_SETUP_CMD_ACCEPT,
1344 TWT_SETUP_CMD_ALTERNATE,
1345 TWT_SETUP_CMD_DICTATE,
1346 TWT_SETUP_CMD_REJECT,
1347};
1348
1349struct ieee80211_twt_params {
1350 __le16 req_type;
1351 __le64 twt;
1352 u8 min_twt_dur;
1353 __le16 mantissa;
1354 u8 channel;
1355} __packed;
1356
1357struct ieee80211_twt_setup {
1358 u8 dialog_token;
1359 u8 element_id;
1360 u8 length;
1361 u8 control;
1362 u8 params[];
1363} __packed;
1364
1365#define IEEE80211_TTLM_MAX_CNT 2
1366#define IEEE80211_TTLM_CONTROL_DIRECTION 0x03
1367#define IEEE80211_TTLM_CONTROL_DEF_LINK_MAP 0x04
1368#define IEEE80211_TTLM_CONTROL_SWITCH_TIME_PRESENT 0x08
1369#define IEEE80211_TTLM_CONTROL_EXPECTED_DUR_PRESENT 0x10
1370#define IEEE80211_TTLM_CONTROL_LINK_MAP_SIZE 0x20
1371
1372#define IEEE80211_TTLM_DIRECTION_DOWN 0
1373#define IEEE80211_TTLM_DIRECTION_UP 1
1374#define IEEE80211_TTLM_DIRECTION_BOTH 2
1375
1376/**
1377 * struct ieee80211_ttlm_elem - TID-To-Link Mapping element
1378 *
1379 * Defined in section 9.4.2.314 in P802.11be_D4
1380 *
1381 * @control: the first part of control field
1382 * @optional: the second part of control field
1383 */
1384struct ieee80211_ttlm_elem {
1385 u8 control;
1386 u8 optional[];
1387} __packed;
1388
1389/**
1390 * struct ieee80211_bss_load_elem - BSS Load elemen
1391 *
1392 * Defined in section 9.4.2.26 in IEEE 802.11-REVme D4.1
1393 *
1394 * @sta_count: total number of STAs currently associated with the AP.
1395 * @channel_util: Percentage of time that the access point sensed the channel
1396 * was busy. This value is in range [0, 255], the highest value means
1397 * 100% busy.
1398 * @avail_admission_capa: remaining amount of medium time used for admission
1399 * control.
1400 */
1401struct ieee80211_bss_load_elem {
1402 __le16 sta_count;
1403 u8 channel_util;
1404 __le16 avail_admission_capa;
1405} __packed;
1406
1407struct ieee80211_mgmt {
1408 __le16 frame_control;
1409 __le16 duration;
1410 u8 da[ETH_ALEN];
1411 u8 sa[ETH_ALEN];
1412 u8 bssid[ETH_ALEN];
1413 __le16 seq_ctrl;
1414 union {
1415 struct {
1416 __le16 auth_alg;
1417 __le16 auth_transaction;
1418 __le16 status_code;
1419 /* possibly followed by Challenge text */
1420 u8 variable[];
1421 } __packed auth;
1422 struct {
1423 __le16 reason_code;
1424 } __packed deauth;
1425 struct {
1426 __le16 capab_info;
1427 __le16 listen_interval;
1428 /* followed by SSID and Supported rates */
1429 u8 variable[];
1430 } __packed assoc_req;
1431 struct {
1432 __le16 capab_info;
1433 __le16 status_code;
1434 __le16 aid;
1435 /* followed by Supported rates */
1436 u8 variable[];
1437 } __packed assoc_resp, reassoc_resp;
1438 struct {
1439 __le16 capab_info;
1440 __le16 status_code;
1441 u8 variable[];
1442 } __packed s1g_assoc_resp, s1g_reassoc_resp;
1443 struct {
1444 __le16 capab_info;
1445 __le16 listen_interval;
1446 u8 current_ap[ETH_ALEN];
1447 /* followed by SSID and Supported rates */
1448 u8 variable[];
1449 } __packed reassoc_req;
1450 struct {
1451 __le16 reason_code;
1452 } __packed disassoc;
1453 struct {
1454 __le64 timestamp;
1455 __le16 beacon_int;
1456 __le16 capab_info;
1457 /* followed by some of SSID, Supported rates,
1458 * FH Params, DS Params, CF Params, IBSS Params, TIM */
1459 u8 variable[];
1460 } __packed beacon;
1461 struct {
1462 /* only variable items: SSID, Supported rates */
1463 DECLARE_FLEX_ARRAY(u8, variable);
1464 } __packed probe_req;
1465 struct {
1466 __le64 timestamp;
1467 __le16 beacon_int;
1468 __le16 capab_info;
1469 /* followed by some of SSID, Supported rates,
1470 * FH Params, DS Params, CF Params, IBSS Params */
1471 u8 variable[];
1472 } __packed probe_resp;
1473 struct {
1474 u8 category;
1475 union {
1476 struct {
1477 u8 action_code;
1478 u8 dialog_token;
1479 u8 status_code;
1480 u8 variable[];
1481 } __packed wme_action;
1482 struct{
1483 u8 action_code;
1484 u8 variable[];
1485 } __packed chan_switch;
1486 struct{
1487 u8 action_code;
1488 struct ieee80211_ext_chansw_ie data;
1489 u8 variable[];
1490 } __packed ext_chan_switch;
1491 struct{
1492 u8 action_code;
1493 u8 dialog_token;
1494 u8 element_id;
1495 u8 length;
1496 struct ieee80211_msrment_ie msr_elem;
1497 } __packed measurement;
1498 struct{
1499 u8 action_code;
1500 u8 dialog_token;
1501 __le16 capab;
1502 __le16 timeout;
1503 __le16 start_seq_num;
1504 /* followed by BA Extension */
1505 u8 variable[];
1506 } __packed addba_req;
1507 struct{
1508 u8 action_code;
1509 u8 dialog_token;
1510 __le16 status;
1511 __le16 capab;
1512 __le16 timeout;
1513 /* followed by BA Extension */
1514 u8 variable[];
1515 } __packed addba_resp;
1516 struct{
1517 u8 action_code;
1518 __le16 params;
1519 __le16 reason_code;
1520 } __packed delba;
1521 struct {
1522 u8 action_code;
1523 u8 variable[];
1524 } __packed self_prot;
1525 struct{
1526 u8 action_code;
1527 u8 variable[];
1528 } __packed mesh_action;
1529 struct {
1530 u8 action;
1531 u8 trans_id[WLAN_SA_QUERY_TR_ID_LEN];
1532 } __packed sa_query;
1533 struct {
1534 u8 action;
1535 u8 smps_control;
1536 } __packed ht_smps;
1537 struct {
1538 u8 action_code;
1539 u8 chanwidth;
1540 } __packed ht_notify_cw;
1541 struct {
1542 u8 action_code;
1543 u8 dialog_token;
1544 __le16 capability;
1545 u8 variable[];
1546 } __packed tdls_discover_resp;
1547 struct {
1548 u8 action_code;
1549 u8 operating_mode;
1550 } __packed vht_opmode_notif;
1551 struct {
1552 u8 action_code;
1553 u8 membership[WLAN_MEMBERSHIP_LEN];
1554 u8 position[WLAN_USER_POSITION_LEN];
1555 } __packed vht_group_notif;
1556 struct {
1557 u8 action_code;
1558 u8 dialog_token;
1559 u8 tpc_elem_id;
1560 u8 tpc_elem_length;
1561 struct ieee80211_tpc_report_ie tpc;
1562 } __packed tpc_report;
1563 struct {
1564 u8 action_code;
1565 u8 dialog_token;
1566 u8 follow_up;
1567 u8 tod[6];
1568 u8 toa[6];
1569 __le16 tod_error;
1570 __le16 toa_error;
1571 u8 variable[];
1572 } __packed ftm;
1573 struct {
1574 u8 action_code;
1575 u8 variable[];
1576 } __packed s1g;
1577 struct {
1578 u8 action_code;
1579 u8 dialog_token;
1580 u8 follow_up;
1581 u32 tod;
1582 u32 toa;
1583 u8 max_tod_error;
1584 u8 max_toa_error;
1585 } __packed wnm_timing_msr;
1586 struct {
1587 u8 action_code;
1588 u8 dialog_token;
1589 u8 variable[];
1590 } __packed ttlm_req;
1591 struct {
1592 u8 action_code;
1593 u8 dialog_token;
1594 __le16 status_code;
1595 u8 variable[];
1596 } __packed ttlm_res;
1597 struct {
1598 u8 action_code;
1599 } __packed ttlm_tear_down;
1600 struct {
1601 u8 action_code;
1602 u8 dialog_token;
1603 u8 variable[];
1604 } __packed ml_reconf_req;
1605 struct {
1606 u8 action_code;
1607 u8 dialog_token;
1608 u8 count;
1609 u8 variable[];
1610 } __packed ml_reconf_resp;
1611 struct {
1612 u8 action_code;
1613 u8 variable[];
1614 } __packed epcs;
1615 } u;
1616 } __packed action;
1617 DECLARE_FLEX_ARRAY(u8, body); /* Generic frame body */
1618 } u;
1619} __packed __aligned(2);
1620
1621/* Supported rates membership selectors */
1622#define BSS_MEMBERSHIP_SELECTOR_HT_PHY 127
1623#define BSS_MEMBERSHIP_SELECTOR_VHT_PHY 126
1624#define BSS_MEMBERSHIP_SELECTOR_GLK 125
1625#define BSS_MEMBERSHIP_SELECTOR_EPD 124
1626#define BSS_MEMBERSHIP_SELECTOR_SAE_H2E 123
1627#define BSS_MEMBERSHIP_SELECTOR_HE_PHY 122
1628#define BSS_MEMBERSHIP_SELECTOR_EHT_PHY 121
1629
1630#define BSS_MEMBERSHIP_SELECTOR_MIN BSS_MEMBERSHIP_SELECTOR_EHT_PHY
1631
1632/* mgmt header + 1 byte category code */
1633#define IEEE80211_MIN_ACTION_SIZE offsetof(struct ieee80211_mgmt, u.action.u)
1634
1635
1636/* Management MIC information element (IEEE 802.11w) */
1637struct ieee80211_mmie {
1638 u8 element_id;
1639 u8 length;
1640 __le16 key_id;
1641 u8 sequence_number[6];
1642 u8 mic[8];
1643} __packed;
1644
1645/* Management MIC information element (IEEE 802.11w) for GMAC and CMAC-256 */
1646struct ieee80211_mmie_16 {
1647 u8 element_id;
1648 u8 length;
1649 __le16 key_id;
1650 u8 sequence_number[6];
1651 u8 mic[16];
1652} __packed;
1653
1654struct ieee80211_vendor_ie {
1655 u8 element_id;
1656 u8 len;
1657 u8 oui[3];
1658 u8 oui_type;
1659} __packed;
1660
1661struct ieee80211_wmm_ac_param {
1662 u8 aci_aifsn; /* AIFSN, ACM, ACI */
1663 u8 cw; /* ECWmin, ECWmax (CW = 2^ECW - 1) */
1664 __le16 txop_limit;
1665} __packed;
1666
1667struct ieee80211_wmm_param_ie {
1668 u8 element_id; /* Element ID: 221 (0xdd); */
1669 u8 len; /* Length: 24 */
1670 /* required fields for WMM version 1 */
1671 u8 oui[3]; /* 00:50:f2 */
1672 u8 oui_type; /* 2 */
1673 u8 oui_subtype; /* 1 */
1674 u8 version; /* 1 for WMM version 1.0 */
1675 u8 qos_info; /* AP/STA specific QoS info */
1676 u8 reserved; /* 0 */
1677 /* AC_BE, AC_BK, AC_VI, AC_VO */
1678 struct ieee80211_wmm_ac_param ac[4];
1679} __packed;
1680
1681/* Control frames */
1682struct ieee80211_rts {
1683 __le16 frame_control;
1684 __le16 duration;
1685 u8 ra[ETH_ALEN];
1686 u8 ta[ETH_ALEN];
1687} __packed __aligned(2);
1688
1689struct ieee80211_cts {
1690 __le16 frame_control;
1691 __le16 duration;
1692 u8 ra[ETH_ALEN];
1693} __packed __aligned(2);
1694
1695struct ieee80211_pspoll {
1696 __le16 frame_control;
1697 __le16 aid;
1698 u8 bssid[ETH_ALEN];
1699 u8 ta[ETH_ALEN];
1700} __packed __aligned(2);
1701
1702/* TDLS */
1703
1704/* Channel switch timing */
1705struct ieee80211_ch_switch_timing {
1706 __le16 switch_time;
1707 __le16 switch_timeout;
1708} __packed;
1709
1710/* Link-id information element */
1711struct ieee80211_tdls_lnkie {
1712 u8 ie_type; /* Link Identifier IE */
1713 u8 ie_len;
1714 u8 bssid[ETH_ALEN];
1715 u8 init_sta[ETH_ALEN];
1716 u8 resp_sta[ETH_ALEN];
1717} __packed;
1718
1719struct ieee80211_tdls_data {
1720 u8 da[ETH_ALEN];
1721 u8 sa[ETH_ALEN];
1722 __be16 ether_type;
1723 u8 payload_type;
1724 u8 category;
1725 u8 action_code;
1726 union {
1727 struct {
1728 u8 dialog_token;
1729 __le16 capability;
1730 u8 variable[];
1731 } __packed setup_req;
1732 struct {
1733 __le16 status_code;
1734 u8 dialog_token;
1735 __le16 capability;
1736 u8 variable[];
1737 } __packed setup_resp;
1738 struct {
1739 __le16 status_code;
1740 u8 dialog_token;
1741 u8 variable[];
1742 } __packed setup_cfm;
1743 struct {
1744 __le16 reason_code;
1745 u8 variable[];
1746 } __packed teardown;
1747 struct {
1748 u8 dialog_token;
1749 u8 variable[];
1750 } __packed discover_req;
1751 struct {
1752 u8 target_channel;
1753 u8 oper_class;
1754 u8 variable[];
1755 } __packed chan_switch_req;
1756 struct {
1757 __le16 status_code;
1758 u8 variable[];
1759 } __packed chan_switch_resp;
1760 } u;
1761} __packed;
1762
1763/*
1764 * Peer-to-Peer IE attribute related definitions.
1765 */
1766/*
1767 * enum ieee80211_p2p_attr_id - identifies type of peer-to-peer attribute.
1768 */
1769enum ieee80211_p2p_attr_id {
1770 IEEE80211_P2P_ATTR_STATUS = 0,
1771 IEEE80211_P2P_ATTR_MINOR_REASON,
1772 IEEE80211_P2P_ATTR_CAPABILITY,
1773 IEEE80211_P2P_ATTR_DEVICE_ID,
1774 IEEE80211_P2P_ATTR_GO_INTENT,
1775 IEEE80211_P2P_ATTR_GO_CONFIG_TIMEOUT,
1776 IEEE80211_P2P_ATTR_LISTEN_CHANNEL,
1777 IEEE80211_P2P_ATTR_GROUP_BSSID,
1778 IEEE80211_P2P_ATTR_EXT_LISTEN_TIMING,
1779 IEEE80211_P2P_ATTR_INTENDED_IFACE_ADDR,
1780 IEEE80211_P2P_ATTR_MANAGABILITY,
1781 IEEE80211_P2P_ATTR_CHANNEL_LIST,
1782 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
1783 IEEE80211_P2P_ATTR_DEVICE_INFO,
1784 IEEE80211_P2P_ATTR_GROUP_INFO,
1785 IEEE80211_P2P_ATTR_GROUP_ID,
1786 IEEE80211_P2P_ATTR_INTERFACE,
1787 IEEE80211_P2P_ATTR_OPER_CHANNEL,
1788 IEEE80211_P2P_ATTR_INVITE_FLAGS,
1789 /* 19 - 220: Reserved */
1790 IEEE80211_P2P_ATTR_VENDOR_SPECIFIC = 221,
1791
1792 IEEE80211_P2P_ATTR_MAX
1793};
1794
1795/* Notice of Absence attribute - described in P2P spec 4.1.14 */
1796/* Typical max value used here */
1797#define IEEE80211_P2P_NOA_DESC_MAX 4
1798
1799struct ieee80211_p2p_noa_desc {
1800 u8 count;
1801 __le32 duration;
1802 __le32 interval;
1803 __le32 start_time;
1804} __packed;
1805
1806struct ieee80211_p2p_noa_attr {
1807 u8 index;
1808 u8 oppps_ctwindow;
1809 struct ieee80211_p2p_noa_desc desc[IEEE80211_P2P_NOA_DESC_MAX];
1810} __packed;
1811
1812#define IEEE80211_P2P_OPPPS_ENABLE_BIT BIT(7)
1813#define IEEE80211_P2P_OPPPS_CTWINDOW_MASK 0x7F
1814
1815/**
1816 * struct ieee80211_bar - Block Ack Request frame format
1817 * @frame_control: Frame Control
1818 * @duration: Duration
1819 * @ra: RA
1820 * @ta: TA
1821 * @control: BAR Control
1822 * @start_seq_num: Starting Sequence Number (see Figure 9-37)
1823 *
1824 * This structure represents the "BlockAckReq frame format"
1825 * as described in IEEE Std 802.11-2020 section 9.3.1.7.
1826*/
1827struct ieee80211_bar {
1828 __le16 frame_control;
1829 __le16 duration;
1830 __u8 ra[ETH_ALEN];
1831 __u8 ta[ETH_ALEN];
1832 __le16 control;
1833 __le16 start_seq_num;
1834} __packed;
1835
1836/* 802.11 BAR control masks */
1837#define IEEE80211_BAR_CTRL_ACK_POLICY_NORMAL 0x0000
1838#define IEEE80211_BAR_CTRL_MULTI_TID 0x0002
1839#define IEEE80211_BAR_CTRL_CBMTID_COMPRESSED_BA 0x0004
1840#define IEEE80211_BAR_CTRL_TID_INFO_MASK 0xf000
1841#define IEEE80211_BAR_CTRL_TID_INFO_SHIFT 12
1842
1843#define IEEE80211_HT_MCS_MASK_LEN 10
1844
1845/**
1846 * struct ieee80211_mcs_info - Supported MCS Set field
1847 * @rx_mask: RX mask
1848 * @rx_highest: highest supported RX rate. If set represents
1849 * the highest supported RX data rate in units of 1 Mbps.
1850 * If this field is 0 this value should not be used to
1851 * consider the highest RX data rate supported.
1852 * @tx_params: TX parameters
1853 * @reserved: Reserved bits
1854 *
1855 * This structure represents the "Supported MCS Set field" as
1856 * described in IEEE Std 802.11-2020 section 9.4.2.55.4.
1857 */
1858struct ieee80211_mcs_info {
1859 u8 rx_mask[IEEE80211_HT_MCS_MASK_LEN];
1860 __le16 rx_highest;
1861 u8 tx_params;
1862 u8 reserved[3];
1863} __packed;
1864
1865/* 802.11n HT capability MSC set */
1866#define IEEE80211_HT_MCS_RX_HIGHEST_MASK 0x3ff
1867#define IEEE80211_HT_MCS_TX_DEFINED 0x01
1868#define IEEE80211_HT_MCS_TX_RX_DIFF 0x02
1869/* value 0 == 1 stream etc */
1870#define IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK 0x0C
1871#define IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT 2
1872#define IEEE80211_HT_MCS_TX_MAX_STREAMS 4
1873#define IEEE80211_HT_MCS_TX_UNEQUAL_MODULATION 0x10
1874
1875#define IEEE80211_HT_MCS_CHAINS(mcs) ((mcs) == 32 ? 1 : (1 + ((mcs) >> 3)))
1876
1877/*
1878 * 802.11n D5.0 20.3.5 / 20.6 says:
1879 * - indices 0 to 7 and 32 are single spatial stream
1880 * - 8 to 31 are multiple spatial streams using equal modulation
1881 * [8..15 for two streams, 16..23 for three and 24..31 for four]
1882 * - remainder are multiple spatial streams using unequal modulation
1883 */
1884#define IEEE80211_HT_MCS_UNEQUAL_MODULATION_START 33
1885#define IEEE80211_HT_MCS_UNEQUAL_MODULATION_START_BYTE \
1886 (IEEE80211_HT_MCS_UNEQUAL_MODULATION_START / 8)
1887
1888/**
1889 * struct ieee80211_ht_cap - HT capabilities element
1890 * @cap_info: HT Capability Information
1891 * @ampdu_params_info: A-MPDU Parameters
1892 * @mcs: Supported MCS Set
1893 * @extended_ht_cap_info: HT Extended Capabilities
1894 * @tx_BF_cap_info: Transmit Beamforming Capabilities
1895 * @antenna_selection_info: ASEL Capability
1896 *
1897 * This structure represents the payload of the "HT Capabilities
1898 * element" as described in IEEE Std 802.11-2020 section 9.4.2.55.
1899 */
1900struct ieee80211_ht_cap {
1901 __le16 cap_info;
1902 u8 ampdu_params_info;
1903
1904 /* 16 bytes MCS information */
1905 struct ieee80211_mcs_info mcs;
1906
1907 __le16 extended_ht_cap_info;
1908 __le32 tx_BF_cap_info;
1909 u8 antenna_selection_info;
1910} __packed;
1911
1912/* 802.11n HT capabilities masks (for cap_info) */
1913#define IEEE80211_HT_CAP_LDPC_CODING 0x0001
1914#define IEEE80211_HT_CAP_SUP_WIDTH_20_40 0x0002
1915#define IEEE80211_HT_CAP_SM_PS 0x000C
1916#define IEEE80211_HT_CAP_SM_PS_SHIFT 2
1917#define IEEE80211_HT_CAP_GRN_FLD 0x0010
1918#define IEEE80211_HT_CAP_SGI_20 0x0020
1919#define IEEE80211_HT_CAP_SGI_40 0x0040
1920#define IEEE80211_HT_CAP_TX_STBC 0x0080
1921#define IEEE80211_HT_CAP_RX_STBC 0x0300
1922#define IEEE80211_HT_CAP_RX_STBC_SHIFT 8
1923#define IEEE80211_HT_CAP_DELAY_BA 0x0400
1924#define IEEE80211_HT_CAP_MAX_AMSDU 0x0800
1925#define IEEE80211_HT_CAP_DSSSCCK40 0x1000
1926#define IEEE80211_HT_CAP_RESERVED 0x2000
1927#define IEEE80211_HT_CAP_40MHZ_INTOLERANT 0x4000
1928#define IEEE80211_HT_CAP_LSIG_TXOP_PROT 0x8000
1929
1930/* 802.11n HT extended capabilities masks (for extended_ht_cap_info) */
1931#define IEEE80211_HT_EXT_CAP_PCO 0x0001
1932#define IEEE80211_HT_EXT_CAP_PCO_TIME 0x0006
1933#define IEEE80211_HT_EXT_CAP_PCO_TIME_SHIFT 1
1934#define IEEE80211_HT_EXT_CAP_MCS_FB 0x0300
1935#define IEEE80211_HT_EXT_CAP_MCS_FB_SHIFT 8
1936#define IEEE80211_HT_EXT_CAP_HTC_SUP 0x0400
1937#define IEEE80211_HT_EXT_CAP_RD_RESPONDER 0x0800
1938
1939/* 802.11n HT capability AMPDU settings (for ampdu_params_info) */
1940#define IEEE80211_HT_AMPDU_PARM_FACTOR 0x03
1941#define IEEE80211_HT_AMPDU_PARM_DENSITY 0x1C
1942#define IEEE80211_HT_AMPDU_PARM_DENSITY_SHIFT 2
1943
1944/*
1945 * Maximum length of AMPDU that the STA can receive in high-throughput (HT).
1946 * Length = 2 ^ (13 + max_ampdu_length_exp) - 1 (octets)
1947 */
1948enum ieee80211_max_ampdu_length_exp {
1949 IEEE80211_HT_MAX_AMPDU_8K = 0,
1950 IEEE80211_HT_MAX_AMPDU_16K = 1,
1951 IEEE80211_HT_MAX_AMPDU_32K = 2,
1952 IEEE80211_HT_MAX_AMPDU_64K = 3
1953};
1954
1955/*
1956 * Maximum length of AMPDU that the STA can receive in VHT.
1957 * Length = 2 ^ (13 + max_ampdu_length_exp) - 1 (octets)
1958 */
1959enum ieee80211_vht_max_ampdu_length_exp {
1960 IEEE80211_VHT_MAX_AMPDU_8K = 0,
1961 IEEE80211_VHT_MAX_AMPDU_16K = 1,
1962 IEEE80211_VHT_MAX_AMPDU_32K = 2,
1963 IEEE80211_VHT_MAX_AMPDU_64K = 3,
1964 IEEE80211_VHT_MAX_AMPDU_128K = 4,
1965 IEEE80211_VHT_MAX_AMPDU_256K = 5,
1966 IEEE80211_VHT_MAX_AMPDU_512K = 6,
1967 IEEE80211_VHT_MAX_AMPDU_1024K = 7
1968};
1969
1970#define IEEE80211_HT_MAX_AMPDU_FACTOR 13
1971
1972/* Minimum MPDU start spacing */
1973enum ieee80211_min_mpdu_spacing {
1974 IEEE80211_HT_MPDU_DENSITY_NONE = 0, /* No restriction */
1975 IEEE80211_HT_MPDU_DENSITY_0_25 = 1, /* 1/4 usec */
1976 IEEE80211_HT_MPDU_DENSITY_0_5 = 2, /* 1/2 usec */
1977 IEEE80211_HT_MPDU_DENSITY_1 = 3, /* 1 usec */
1978 IEEE80211_HT_MPDU_DENSITY_2 = 4, /* 2 usec */
1979 IEEE80211_HT_MPDU_DENSITY_4 = 5, /* 4 usec */
1980 IEEE80211_HT_MPDU_DENSITY_8 = 6, /* 8 usec */
1981 IEEE80211_HT_MPDU_DENSITY_16 = 7 /* 16 usec */
1982};
1983
1984/**
1985 * struct ieee80211_ht_operation - HT operation IE
1986 * @primary_chan: Primary Channel
1987 * @ht_param: HT Operation Information parameters
1988 * @operation_mode: HT Operation Information operation mode
1989 * @stbc_param: HT Operation Information STBC params
1990 * @basic_set: Basic HT-MCS Set
1991 *
1992 * This structure represents the payload of the "HT Operation
1993 * element" as described in IEEE Std 802.11-2020 section 9.4.2.56.
1994 */
1995struct ieee80211_ht_operation {
1996 u8 primary_chan;
1997 u8 ht_param;
1998 __le16 operation_mode;
1999 __le16 stbc_param;
2000 u8 basic_set[16];
2001} __packed;
2002
2003/* for ht_param */
2004#define IEEE80211_HT_PARAM_CHA_SEC_OFFSET 0x03
2005#define IEEE80211_HT_PARAM_CHA_SEC_NONE 0x00
2006#define IEEE80211_HT_PARAM_CHA_SEC_ABOVE 0x01
2007#define IEEE80211_HT_PARAM_CHA_SEC_BELOW 0x03
2008#define IEEE80211_HT_PARAM_CHAN_WIDTH_ANY 0x04
2009#define IEEE80211_HT_PARAM_RIFS_MODE 0x08
2010
2011/* for operation_mode */
2012#define IEEE80211_HT_OP_MODE_PROTECTION 0x0003
2013#define IEEE80211_HT_OP_MODE_PROTECTION_NONE 0
2014#define IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER 1
2015#define IEEE80211_HT_OP_MODE_PROTECTION_20MHZ 2
2016#define IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED 3
2017#define IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT 0x0004
2018#define IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT 0x0010
2019#define IEEE80211_HT_OP_MODE_CCFS2_SHIFT 5
2020#define IEEE80211_HT_OP_MODE_CCFS2_MASK 0x1fe0
2021
2022/* for stbc_param */
2023#define IEEE80211_HT_STBC_PARAM_DUAL_BEACON 0x0040
2024#define IEEE80211_HT_STBC_PARAM_DUAL_CTS_PROT 0x0080
2025#define IEEE80211_HT_STBC_PARAM_STBC_BEACON 0x0100
2026#define IEEE80211_HT_STBC_PARAM_LSIG_TXOP_FULLPROT 0x0200
2027#define IEEE80211_HT_STBC_PARAM_PCO_ACTIVE 0x0400
2028#define IEEE80211_HT_STBC_PARAM_PCO_PHASE 0x0800
2029
2030
2031/* block-ack parameters */
2032#define IEEE80211_ADDBA_PARAM_AMSDU_MASK 0x0001
2033#define IEEE80211_ADDBA_PARAM_POLICY_MASK 0x0002
2034#define IEEE80211_ADDBA_PARAM_TID_MASK 0x003C
2035#define IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK 0xFFC0
2036#define IEEE80211_DELBA_PARAM_TID_MASK 0xF000
2037#define IEEE80211_DELBA_PARAM_INITIATOR_MASK 0x0800
2038
2039/*
2040 * A-MPDU buffer sizes
2041 * According to HT size varies from 8 to 64 frames
2042 * HE adds the ability to have up to 256 frames.
2043 * EHT adds the ability to have up to 1K frames.
2044 */
2045#define IEEE80211_MIN_AMPDU_BUF 0x8
2046#define IEEE80211_MAX_AMPDU_BUF_HT 0x40
2047#define IEEE80211_MAX_AMPDU_BUF_HE 0x100
2048#define IEEE80211_MAX_AMPDU_BUF_EHT 0x400
2049
2050
2051/* Spatial Multiplexing Power Save Modes (for capability) */
2052#define WLAN_HT_CAP_SM_PS_STATIC 0
2053#define WLAN_HT_CAP_SM_PS_DYNAMIC 1
2054#define WLAN_HT_CAP_SM_PS_INVALID 2
2055#define WLAN_HT_CAP_SM_PS_DISABLED 3
2056
2057/* for SM power control field lower two bits */
2058#define WLAN_HT_SMPS_CONTROL_DISABLED 0
2059#define WLAN_HT_SMPS_CONTROL_STATIC 1
2060#define WLAN_HT_SMPS_CONTROL_DYNAMIC 3
2061
2062/**
2063 * struct ieee80211_vht_mcs_info - VHT MCS information
2064 * @rx_mcs_map: RX MCS map 2 bits for each stream, total 8 streams
2065 * @rx_highest: Indicates highest long GI VHT PPDU data rate
2066 * STA can receive. Rate expressed in units of 1 Mbps.
2067 * If this field is 0 this value should not be used to
2068 * consider the highest RX data rate supported.
2069 * The top 3 bits of this field indicate the Maximum NSTS,total
2070 * (a beamformee capability.)
2071 * @tx_mcs_map: TX MCS map 2 bits for each stream, total 8 streams
2072 * @tx_highest: Indicates highest long GI VHT PPDU data rate
2073 * STA can transmit. Rate expressed in units of 1 Mbps.
2074 * If this field is 0 this value should not be used to
2075 * consider the highest TX data rate supported.
2076 * The top 2 bits of this field are reserved, the
2077 * 3rd bit from the top indiciates VHT Extended NSS BW
2078 * Capability.
2079 */
2080struct ieee80211_vht_mcs_info {
2081 __le16 rx_mcs_map;
2082 __le16 rx_highest;
2083 __le16 tx_mcs_map;
2084 __le16 tx_highest;
2085} __packed;
2086
2087/* for rx_highest */
2088#define IEEE80211_VHT_MAX_NSTS_TOTAL_SHIFT 13
2089#define IEEE80211_VHT_MAX_NSTS_TOTAL_MASK (7 << IEEE80211_VHT_MAX_NSTS_TOTAL_SHIFT)
2090
2091/* for tx_highest */
2092#define IEEE80211_VHT_EXT_NSS_BW_CAPABLE (1 << 13)
2093
2094/**
2095 * enum ieee80211_vht_mcs_support - VHT MCS support definitions
2096 * @IEEE80211_VHT_MCS_SUPPORT_0_7: MCSes 0-7 are supported for the
2097 * number of streams
2098 * @IEEE80211_VHT_MCS_SUPPORT_0_8: MCSes 0-8 are supported
2099 * @IEEE80211_VHT_MCS_SUPPORT_0_9: MCSes 0-9 are supported
2100 * @IEEE80211_VHT_MCS_NOT_SUPPORTED: This number of streams isn't supported
2101 *
2102 * These definitions are used in each 2-bit subfield of the @rx_mcs_map
2103 * and @tx_mcs_map fields of &struct ieee80211_vht_mcs_info, which are
2104 * both split into 8 subfields by number of streams. These values indicate
2105 * which MCSes are supported for the number of streams the value appears
2106 * for.
2107 */
2108enum ieee80211_vht_mcs_support {
2109 IEEE80211_VHT_MCS_SUPPORT_0_7 = 0,
2110 IEEE80211_VHT_MCS_SUPPORT_0_8 = 1,
2111 IEEE80211_VHT_MCS_SUPPORT_0_9 = 2,
2112 IEEE80211_VHT_MCS_NOT_SUPPORTED = 3,
2113};
2114
2115/**
2116 * struct ieee80211_vht_cap - VHT capabilities
2117 *
2118 * This structure is the "VHT capabilities element" as
2119 * described in 802.11ac D3.0 8.4.2.160
2120 * @vht_cap_info: VHT capability info
2121 * @supp_mcs: VHT MCS supported rates
2122 */
2123struct ieee80211_vht_cap {
2124 __le32 vht_cap_info;
2125 struct ieee80211_vht_mcs_info supp_mcs;
2126} __packed;
2127
2128/**
2129 * enum ieee80211_vht_chanwidth - VHT channel width
2130 * @IEEE80211_VHT_CHANWIDTH_USE_HT: use the HT operation IE to
2131 * determine the channel width (20 or 40 MHz)
2132 * @IEEE80211_VHT_CHANWIDTH_80MHZ: 80 MHz bandwidth
2133 * @IEEE80211_VHT_CHANWIDTH_160MHZ: 160 MHz bandwidth
2134 * @IEEE80211_VHT_CHANWIDTH_80P80MHZ: 80+80 MHz bandwidth
2135 */
2136enum ieee80211_vht_chanwidth {
2137 IEEE80211_VHT_CHANWIDTH_USE_HT = 0,
2138 IEEE80211_VHT_CHANWIDTH_80MHZ = 1,
2139 IEEE80211_VHT_CHANWIDTH_160MHZ = 2,
2140 IEEE80211_VHT_CHANWIDTH_80P80MHZ = 3,
2141};
2142
2143/**
2144 * struct ieee80211_vht_operation - VHT operation IE
2145 *
2146 * This structure is the "VHT operation element" as
2147 * described in 802.11ac D3.0 8.4.2.161
2148 * @chan_width: Operating channel width
2149 * @center_freq_seg0_idx: center freq segment 0 index
2150 * @center_freq_seg1_idx: center freq segment 1 index
2151 * @basic_mcs_set: VHT Basic MCS rate set
2152 */
2153struct ieee80211_vht_operation {
2154 u8 chan_width;
2155 u8 center_freq_seg0_idx;
2156 u8 center_freq_seg1_idx;
2157 __le16 basic_mcs_set;
2158} __packed;
2159
2160/**
2161 * struct ieee80211_he_cap_elem - HE capabilities element
2162 * @mac_cap_info: HE MAC Capabilities Information
2163 * @phy_cap_info: HE PHY Capabilities Information
2164 *
2165 * This structure represents the fixed fields of the payload of the
2166 * "HE capabilities element" as described in IEEE Std 802.11ax-2021
2167 * sections 9.4.2.248.2 and 9.4.2.248.3.
2168 */
2169struct ieee80211_he_cap_elem {
2170 u8 mac_cap_info[6];
2171 u8 phy_cap_info[11];
2172} __packed;
2173
2174#define IEEE80211_TX_RX_MCS_NSS_DESC_MAX_LEN 5
2175
2176/**
2177 * enum ieee80211_he_mcs_support - HE MCS support definitions
2178 * @IEEE80211_HE_MCS_SUPPORT_0_7: MCSes 0-7 are supported for the
2179 * number of streams
2180 * @IEEE80211_HE_MCS_SUPPORT_0_9: MCSes 0-9 are supported
2181 * @IEEE80211_HE_MCS_SUPPORT_0_11: MCSes 0-11 are supported
2182 * @IEEE80211_HE_MCS_NOT_SUPPORTED: This number of streams isn't supported
2183 *
2184 * These definitions are used in each 2-bit subfield of the rx_mcs_*
2185 * and tx_mcs_* fields of &struct ieee80211_he_mcs_nss_supp, which are
2186 * both split into 8 subfields by number of streams. These values indicate
2187 * which MCSes are supported for the number of streams the value appears
2188 * for.
2189 */
2190enum ieee80211_he_mcs_support {
2191 IEEE80211_HE_MCS_SUPPORT_0_7 = 0,
2192 IEEE80211_HE_MCS_SUPPORT_0_9 = 1,
2193 IEEE80211_HE_MCS_SUPPORT_0_11 = 2,
2194 IEEE80211_HE_MCS_NOT_SUPPORTED = 3,
2195};
2196
2197/**
2198 * struct ieee80211_he_mcs_nss_supp - HE Tx/Rx HE MCS NSS Support Field
2199 *
2200 * This structure holds the data required for the Tx/Rx HE MCS NSS Support Field
2201 * described in P802.11ax_D2.0 section 9.4.2.237.4
2202 *
2203 * @rx_mcs_80: Rx MCS map 2 bits for each stream, total 8 streams, for channel
2204 * widths less than 80MHz.
2205 * @tx_mcs_80: Tx MCS map 2 bits for each stream, total 8 streams, for channel
2206 * widths less than 80MHz.
2207 * @rx_mcs_160: Rx MCS map 2 bits for each stream, total 8 streams, for channel
2208 * width 160MHz.
2209 * @tx_mcs_160: Tx MCS map 2 bits for each stream, total 8 streams, for channel
2210 * width 160MHz.
2211 * @rx_mcs_80p80: Rx MCS map 2 bits for each stream, total 8 streams, for
2212 * channel width 80p80MHz.
2213 * @tx_mcs_80p80: Tx MCS map 2 bits for each stream, total 8 streams, for
2214 * channel width 80p80MHz.
2215 */
2216struct ieee80211_he_mcs_nss_supp {
2217 __le16 rx_mcs_80;
2218 __le16 tx_mcs_80;
2219 __le16 rx_mcs_160;
2220 __le16 tx_mcs_160;
2221 __le16 rx_mcs_80p80;
2222 __le16 tx_mcs_80p80;
2223} __packed;
2224
2225/**
2226 * struct ieee80211_he_operation - HE Operation element
2227 * @he_oper_params: HE Operation Parameters + BSS Color Information
2228 * @he_mcs_nss_set: Basic HE-MCS And NSS Set
2229 * @optional: Optional fields VHT Operation Information, Max Co-Hosted
2230 * BSSID Indicator, and 6 GHz Operation Information
2231 *
2232 * This structure represents the payload of the "HE Operation
2233 * element" as described in IEEE Std 802.11ax-2021 section 9.4.2.249.
2234 */
2235struct ieee80211_he_operation {
2236 __le32 he_oper_params;
2237 __le16 he_mcs_nss_set;
2238 u8 optional[];
2239} __packed;
2240
2241/**
2242 * struct ieee80211_he_spr - Spatial Reuse Parameter Set element
2243 * @he_sr_control: SR Control
2244 * @optional: Optional fields Non-SRG OBSS PD Max Offset, SRG OBSS PD
2245 * Min Offset, SRG OBSS PD Max Offset, SRG BSS Color
2246 * Bitmap, and SRG Partial BSSID Bitmap
2247 *
2248 * This structure represents the payload of the "Spatial Reuse
2249 * Parameter Set element" as described in IEEE Std 802.11ax-2021
2250 * section 9.4.2.252.
2251 */
2252struct ieee80211_he_spr {
2253 u8 he_sr_control;
2254 u8 optional[];
2255} __packed;
2256
2257/**
2258 * struct ieee80211_he_mu_edca_param_ac_rec - MU AC Parameter Record field
2259 * @aifsn: ACI/AIFSN
2260 * @ecw_min_max: ECWmin/ECWmax
2261 * @mu_edca_timer: MU EDCA Timer
2262 *
2263 * This structure represents the "MU AC Parameter Record" as described
2264 * in IEEE Std 802.11ax-2021 section 9.4.2.251, Figure 9-788p.
2265 */
2266struct ieee80211_he_mu_edca_param_ac_rec {
2267 u8 aifsn;
2268 u8 ecw_min_max;
2269 u8 mu_edca_timer;
2270} __packed;
2271
2272/**
2273 * struct ieee80211_mu_edca_param_set - MU EDCA Parameter Set element
2274 * @mu_qos_info: QoS Info
2275 * @ac_be: MU AC_BE Parameter Record
2276 * @ac_bk: MU AC_BK Parameter Record
2277 * @ac_vi: MU AC_VI Parameter Record
2278 * @ac_vo: MU AC_VO Parameter Record
2279 *
2280 * This structure represents the payload of the "MU EDCA Parameter Set
2281 * element" as described in IEEE Std 802.11ax-2021 section 9.4.2.251.
2282 */
2283struct ieee80211_mu_edca_param_set {
2284 u8 mu_qos_info;
2285 struct ieee80211_he_mu_edca_param_ac_rec ac_be;
2286 struct ieee80211_he_mu_edca_param_ac_rec ac_bk;
2287 struct ieee80211_he_mu_edca_param_ac_rec ac_vi;
2288 struct ieee80211_he_mu_edca_param_ac_rec ac_vo;
2289} __packed;
2290
2291#define IEEE80211_EHT_MCS_NSS_RX 0x0f
2292#define IEEE80211_EHT_MCS_NSS_TX 0xf0
2293
2294/**
2295 * struct ieee80211_eht_mcs_nss_supp_20mhz_only - EHT 20MHz only station max
2296 * supported NSS for per MCS.
2297 *
2298 * For each field below, bits 0 - 3 indicate the maximal number of spatial
2299 * streams for Rx, and bits 4 - 7 indicate the maximal number of spatial streams
2300 * for Tx.
2301 *
2302 * @rx_tx_mcs7_max_nss: indicates the maximum number of spatial streams
2303 * supported for reception and the maximum number of spatial streams
2304 * supported for transmission for MCS 0 - 7.
2305 * @rx_tx_mcs9_max_nss: indicates the maximum number of spatial streams
2306 * supported for reception and the maximum number of spatial streams
2307 * supported for transmission for MCS 8 - 9.
2308 * @rx_tx_mcs11_max_nss: indicates the maximum number of spatial streams
2309 * supported for reception and the maximum number of spatial streams
2310 * supported for transmission for MCS 10 - 11.
2311 * @rx_tx_mcs13_max_nss: indicates the maximum number of spatial streams
2312 * supported for reception and the maximum number of spatial streams
2313 * supported for transmission for MCS 12 - 13.
2314 * @rx_tx_max_nss: array of the previous fields for easier loop access
2315 */
2316struct ieee80211_eht_mcs_nss_supp_20mhz_only {
2317 union {
2318 struct {
2319 u8 rx_tx_mcs7_max_nss;
2320 u8 rx_tx_mcs9_max_nss;
2321 u8 rx_tx_mcs11_max_nss;
2322 u8 rx_tx_mcs13_max_nss;
2323 };
2324 u8 rx_tx_max_nss[4];
2325 };
2326};
2327
2328/**
2329 * struct ieee80211_eht_mcs_nss_supp_bw - EHT max supported NSS per MCS (except
2330 * 20MHz only stations).
2331 *
2332 * For each field below, bits 0 - 3 indicate the maximal number of spatial
2333 * streams for Rx, and bits 4 - 7 indicate the maximal number of spatial streams
2334 * for Tx.
2335 *
2336 * @rx_tx_mcs9_max_nss: indicates the maximum number of spatial streams
2337 * supported for reception and the maximum number of spatial streams
2338 * supported for transmission for MCS 0 - 9.
2339 * @rx_tx_mcs11_max_nss: indicates the maximum number of spatial streams
2340 * supported for reception and the maximum number of spatial streams
2341 * supported for transmission for MCS 10 - 11.
2342 * @rx_tx_mcs13_max_nss: indicates the maximum number of spatial streams
2343 * supported for reception and the maximum number of spatial streams
2344 * supported for transmission for MCS 12 - 13.
2345 * @rx_tx_max_nss: array of the previous fields for easier loop access
2346 */
2347struct ieee80211_eht_mcs_nss_supp_bw {
2348 union {
2349 struct {
2350 u8 rx_tx_mcs9_max_nss;
2351 u8 rx_tx_mcs11_max_nss;
2352 u8 rx_tx_mcs13_max_nss;
2353 };
2354 u8 rx_tx_max_nss[3];
2355 };
2356};
2357
2358/**
2359 * struct ieee80211_eht_cap_elem_fixed - EHT capabilities fixed data
2360 *
2361 * This structure is the "EHT Capabilities element" fixed fields as
2362 * described in P802.11be_D2.0 section 9.4.2.313.
2363 *
2364 * @mac_cap_info: MAC capabilities, see IEEE80211_EHT_MAC_CAP*
2365 * @phy_cap_info: PHY capabilities, see IEEE80211_EHT_PHY_CAP*
2366 */
2367struct ieee80211_eht_cap_elem_fixed {
2368 u8 mac_cap_info[2];
2369 u8 phy_cap_info[9];
2370} __packed;
2371
2372/**
2373 * struct ieee80211_eht_cap_elem - EHT capabilities element
2374 * @fixed: fixed parts, see &ieee80211_eht_cap_elem_fixed
2375 * @optional: optional parts
2376 */
2377struct ieee80211_eht_cap_elem {
2378 struct ieee80211_eht_cap_elem_fixed fixed;
2379
2380 /*
2381 * Followed by:
2382 * Supported EHT-MCS And NSS Set field: 4, 3, 6 or 9 octets.
2383 * EHT PPE Thresholds field: variable length.
2384 */
2385 u8 optional[];
2386} __packed;
2387
2388#define IEEE80211_EHT_OPER_INFO_PRESENT 0x01
2389#define IEEE80211_EHT_OPER_DISABLED_SUBCHANNEL_BITMAP_PRESENT 0x02
2390#define IEEE80211_EHT_OPER_EHT_DEF_PE_DURATION 0x04
2391#define IEEE80211_EHT_OPER_GROUP_ADDRESSED_BU_IND_LIMIT 0x08
2392#define IEEE80211_EHT_OPER_GROUP_ADDRESSED_BU_IND_EXP_MASK 0x30
2393#define IEEE80211_EHT_OPER_MCS15_DISABLE 0x40
2394
2395/**
2396 * struct ieee80211_eht_operation - eht operation element
2397 *
2398 * This structure is the "EHT Operation Element" fields as
2399 * described in P802.11be_D2.0 section 9.4.2.311
2400 *
2401 * @params: EHT operation element parameters. See &IEEE80211_EHT_OPER_*
2402 * @basic_mcs_nss: indicates the EHT-MCSs for each number of spatial streams in
2403 * EHT PPDUs that are supported by all EHT STAs in the BSS in transmit and
2404 * receive.
2405 * @optional: optional parts
2406 */
2407struct ieee80211_eht_operation {
2408 u8 params;
2409 struct ieee80211_eht_mcs_nss_supp_20mhz_only basic_mcs_nss;
2410 u8 optional[];
2411} __packed;
2412
2413/**
2414 * struct ieee80211_eht_operation_info - eht operation information
2415 *
2416 * @control: EHT operation information control.
2417 * @ccfs0: defines a channel center frequency for a 20, 40, 80, 160, or 320 MHz
2418 * EHT BSS.
2419 * @ccfs1: defines a channel center frequency for a 160 or 320 MHz EHT BSS.
2420 * @optional: optional parts
2421 */
2422struct ieee80211_eht_operation_info {
2423 u8 control;
2424 u8 ccfs0;
2425 u8 ccfs1;
2426 u8 optional[];
2427} __packed;
2428
2429/* 802.11ac VHT Capabilities */
2430#define IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895 0x00000000
2431#define IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991 0x00000001
2432#define IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 0x00000002
2433#define IEEE80211_VHT_CAP_MAX_MPDU_MASK 0x00000003
2434#define IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ 0x00000004
2435#define IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ 0x00000008
2436#define IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK 0x0000000C
2437#define IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_SHIFT 2
2438#define IEEE80211_VHT_CAP_RXLDPC 0x00000010
2439#define IEEE80211_VHT_CAP_SHORT_GI_80 0x00000020
2440#define IEEE80211_VHT_CAP_SHORT_GI_160 0x00000040
2441#define IEEE80211_VHT_CAP_TXSTBC 0x00000080
2442#define IEEE80211_VHT_CAP_RXSTBC_1 0x00000100
2443#define IEEE80211_VHT_CAP_RXSTBC_2 0x00000200
2444#define IEEE80211_VHT_CAP_RXSTBC_3 0x00000300
2445#define IEEE80211_VHT_CAP_RXSTBC_4 0x00000400
2446#define IEEE80211_VHT_CAP_RXSTBC_MASK 0x00000700
2447#define IEEE80211_VHT_CAP_RXSTBC_SHIFT 8
2448#define IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE 0x00000800
2449#define IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE 0x00001000
2450#define IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT 13
2451#define IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK \
2452 (7 << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT)
2453#define IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT 16
2454#define IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK \
2455 (7 << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT)
2456#define IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE 0x00080000
2457#define IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE 0x00100000
2458#define IEEE80211_VHT_CAP_VHT_TXOP_PS 0x00200000
2459#define IEEE80211_VHT_CAP_HTC_VHT 0x00400000
2460#define IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT 23
2461#define IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK \
2462 (7 << IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT)
2463#define IEEE80211_VHT_CAP_VHT_LINK_ADAPTATION_VHT_UNSOL_MFB 0x08000000
2464#define IEEE80211_VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB 0x0c000000
2465#define IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN 0x10000000
2466#define IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN 0x20000000
2467#define IEEE80211_VHT_CAP_EXT_NSS_BW_SHIFT 30
2468#define IEEE80211_VHT_CAP_EXT_NSS_BW_MASK 0xc0000000
2469
2470/**
2471 * ieee80211_get_vht_max_nss - return max NSS for a given bandwidth/MCS
2472 * @cap: VHT capabilities of the peer
2473 * @bw: bandwidth to use
2474 * @mcs: MCS index to use
2475 * @ext_nss_bw_capable: indicates whether or not the local transmitter
2476 * (rate scaling algorithm) can deal with the new logic
2477 * (dot11VHTExtendedNSSBWCapable)
2478 * @max_vht_nss: current maximum NSS as advertised by the STA in
2479 * operating mode notification, can be 0 in which case the
2480 * capability data will be used to derive this (from MCS support)
2481 * Return: The maximum NSS that can be used for the given bandwidth/MCS
2482 * combination
2483 *
2484 * Due to the VHT Extended NSS Bandwidth Support, the maximum NSS can
2485 * vary for a given BW/MCS. This function parses the data.
2486 *
2487 * Note: This function is exported by cfg80211.
2488 */
2489int ieee80211_get_vht_max_nss(struct ieee80211_vht_cap *cap,
2490 enum ieee80211_vht_chanwidth bw,
2491 int mcs, bool ext_nss_bw_capable,
2492 unsigned int max_vht_nss);
2493
2494/* 802.11ax HE MAC capabilities */
2495#define IEEE80211_HE_MAC_CAP0_HTC_HE 0x01
2496#define IEEE80211_HE_MAC_CAP0_TWT_REQ 0x02
2497#define IEEE80211_HE_MAC_CAP0_TWT_RES 0x04
2498#define IEEE80211_HE_MAC_CAP0_DYNAMIC_FRAG_NOT_SUPP 0x00
2499#define IEEE80211_HE_MAC_CAP0_DYNAMIC_FRAG_LEVEL_1 0x08
2500#define IEEE80211_HE_MAC_CAP0_DYNAMIC_FRAG_LEVEL_2 0x10
2501#define IEEE80211_HE_MAC_CAP0_DYNAMIC_FRAG_LEVEL_3 0x18
2502#define IEEE80211_HE_MAC_CAP0_DYNAMIC_FRAG_MASK 0x18
2503#define IEEE80211_HE_MAC_CAP0_MAX_NUM_FRAG_MSDU_1 0x00
2504#define IEEE80211_HE_MAC_CAP0_MAX_NUM_FRAG_MSDU_2 0x20
2505#define IEEE80211_HE_MAC_CAP0_MAX_NUM_FRAG_MSDU_4 0x40
2506#define IEEE80211_HE_MAC_CAP0_MAX_NUM_FRAG_MSDU_8 0x60
2507#define IEEE80211_HE_MAC_CAP0_MAX_NUM_FRAG_MSDU_16 0x80
2508#define IEEE80211_HE_MAC_CAP0_MAX_NUM_FRAG_MSDU_32 0xa0
2509#define IEEE80211_HE_MAC_CAP0_MAX_NUM_FRAG_MSDU_64 0xc0
2510#define IEEE80211_HE_MAC_CAP0_MAX_NUM_FRAG_MSDU_UNLIMITED 0xe0
2511#define IEEE80211_HE_MAC_CAP0_MAX_NUM_FRAG_MSDU_MASK 0xe0
2512
2513#define IEEE80211_HE_MAC_CAP1_MIN_FRAG_SIZE_UNLIMITED 0x00
2514#define IEEE80211_HE_MAC_CAP1_MIN_FRAG_SIZE_128 0x01
2515#define IEEE80211_HE_MAC_CAP1_MIN_FRAG_SIZE_256 0x02
2516#define IEEE80211_HE_MAC_CAP1_MIN_FRAG_SIZE_512 0x03
2517#define IEEE80211_HE_MAC_CAP1_MIN_FRAG_SIZE_MASK 0x03
2518#define IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_0US 0x00
2519#define IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_8US 0x04
2520#define IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US 0x08
2521#define IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_MASK 0x0c
2522#define IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_1 0x00
2523#define IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_2 0x10
2524#define IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_3 0x20
2525#define IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_4 0x30
2526#define IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_5 0x40
2527#define IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_6 0x50
2528#define IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_7 0x60
2529#define IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8 0x70
2530#define IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_MASK 0x70
2531
2532/* Link adaptation is split between byte HE_MAC_CAP1 and
2533 * HE_MAC_CAP2. It should be set only if IEEE80211_HE_MAC_CAP0_HTC_HE
2534 * in which case the following values apply:
2535 * 0 = No feedback.
2536 * 1 = reserved.
2537 * 2 = Unsolicited feedback.
2538 * 3 = both
2539 */
2540#define IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION 0x80
2541
2542#define IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION 0x01
2543#define IEEE80211_HE_MAC_CAP2_ALL_ACK 0x02
2544#define IEEE80211_HE_MAC_CAP2_TRS 0x04
2545#define IEEE80211_HE_MAC_CAP2_BSR 0x08
2546#define IEEE80211_HE_MAC_CAP2_BCAST_TWT 0x10
2547#define IEEE80211_HE_MAC_CAP2_32BIT_BA_BITMAP 0x20
2548#define IEEE80211_HE_MAC_CAP2_MU_CASCADING 0x40
2549#define IEEE80211_HE_MAC_CAP2_ACK_EN 0x80
2550
2551#define IEEE80211_HE_MAC_CAP3_OMI_CONTROL 0x02
2552#define IEEE80211_HE_MAC_CAP3_OFDMA_RA 0x04
2553
2554/* The maximum length of an A-MDPU is defined by the combination of the Maximum
2555 * A-MDPU Length Exponent field in the HT capabilities, VHT capabilities and the
2556 * same field in the HE capabilities.
2557 */
2558#define IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_0 0x00
2559#define IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_1 0x08
2560#define IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_2 0x10
2561#define IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_3 0x18
2562#define IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_MASK 0x18
2563#define IEEE80211_HE_MAC_CAP3_AMSDU_FRAG 0x20
2564#define IEEE80211_HE_MAC_CAP3_FLEX_TWT_SCHED 0x40
2565#define IEEE80211_HE_MAC_CAP3_RX_CTRL_FRAME_TO_MULTIBSS 0x80
2566
2567#define IEEE80211_HE_MAC_CAP4_BSRP_BQRP_A_MPDU_AGG 0x01
2568#define IEEE80211_HE_MAC_CAP4_QTP 0x02
2569#define IEEE80211_HE_MAC_CAP4_BQR 0x04
2570#define IEEE80211_HE_MAC_CAP4_PSR_RESP 0x08
2571#define IEEE80211_HE_MAC_CAP4_NDP_FB_REP 0x10
2572#define IEEE80211_HE_MAC_CAP4_OPS 0x20
2573#define IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU 0x40
2574/* Multi TID agg TX is split between byte #4 and #5
2575 * The value is a combination of B39,B40,B41
2576 */
2577#define IEEE80211_HE_MAC_CAP4_MULTI_TID_AGG_TX_QOS_B39 0x80
2578
2579#define IEEE80211_HE_MAC_CAP5_MULTI_TID_AGG_TX_QOS_B40 0x01
2580#define IEEE80211_HE_MAC_CAP5_MULTI_TID_AGG_TX_QOS_B41 0x02
2581#define IEEE80211_HE_MAC_CAP5_SUBCHAN_SELECTIVE_TRANSMISSION 0x04
2582#define IEEE80211_HE_MAC_CAP5_UL_2x996_TONE_RU 0x08
2583#define IEEE80211_HE_MAC_CAP5_OM_CTRL_UL_MU_DATA_DIS_RX 0x10
2584#define IEEE80211_HE_MAC_CAP5_HE_DYNAMIC_SM_PS 0x20
2585#define IEEE80211_HE_MAC_CAP5_PUNCTURED_SOUNDING 0x40
2586#define IEEE80211_HE_MAC_CAP5_HT_VHT_TRIG_FRAME_RX 0x80
2587
2588#define IEEE80211_HE_VHT_MAX_AMPDU_FACTOR 20
2589#define IEEE80211_HE_HT_MAX_AMPDU_FACTOR 16
2590#define IEEE80211_HE_6GHZ_MAX_AMPDU_FACTOR 13
2591
2592/* 802.11ax HE PHY capabilities */
2593#define IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G 0x02
2594#define IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G 0x04
2595#define IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G 0x08
2596#define IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G 0x10
2597#define IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_MASK_ALL 0x1e
2598
2599#define IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_RU_MAPPING_IN_2G 0x20
2600#define IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_RU_MAPPING_IN_5G 0x40
2601#define IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_MASK 0xfe
2602
2603#define IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_80MHZ_ONLY_SECOND_20MHZ 0x01
2604#define IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_80MHZ_ONLY_SECOND_40MHZ 0x02
2605#define IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_160MHZ_ONLY_SECOND_20MHZ 0x04
2606#define IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_160MHZ_ONLY_SECOND_40MHZ 0x08
2607#define IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_MASK 0x0f
2608#define IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A 0x10
2609#define IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD 0x20
2610#define IEEE80211_HE_PHY_CAP1_HE_LTF_AND_GI_FOR_HE_PPDUS_0_8US 0x40
2611/* Midamble RX/TX Max NSTS is split between byte #2 and byte #3 */
2612#define IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_TX_MAX_NSTS 0x80
2613
2614#define IEEE80211_HE_PHY_CAP2_MIDAMBLE_RX_TX_MAX_NSTS 0x01
2615#define IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US 0x02
2616#define IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ 0x04
2617#define IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ 0x08
2618#define IEEE80211_HE_PHY_CAP2_DOPPLER_TX 0x10
2619#define IEEE80211_HE_PHY_CAP2_DOPPLER_RX 0x20
2620
2621/* Note that the meaning of UL MU below is different between an AP and a non-AP
2622 * sta, where in the AP case it indicates support for Rx and in the non-AP sta
2623 * case it indicates support for Tx.
2624 */
2625#define IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO 0x40
2626#define IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO 0x80
2627
2628#define IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_NO_DCM 0x00
2629#define IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_BPSK 0x01
2630#define IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_QPSK 0x02
2631#define IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_16_QAM 0x03
2632#define IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_MASK 0x03
2633#define IEEE80211_HE_PHY_CAP3_DCM_MAX_TX_NSS_1 0x00
2634#define IEEE80211_HE_PHY_CAP3_DCM_MAX_TX_NSS_2 0x04
2635#define IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_NO_DCM 0x00
2636#define IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_BPSK 0x08
2637#define IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_QPSK 0x10
2638#define IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_16_QAM 0x18
2639#define IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_MASK 0x18
2640#define IEEE80211_HE_PHY_CAP3_DCM_MAX_RX_NSS_1 0x00
2641#define IEEE80211_HE_PHY_CAP3_DCM_MAX_RX_NSS_2 0x20
2642#define IEEE80211_HE_PHY_CAP3_RX_PARTIAL_BW_SU_IN_20MHZ_MU 0x40
2643#define IEEE80211_HE_PHY_CAP3_SU_BEAMFORMER 0x80
2644
2645#define IEEE80211_HE_PHY_CAP4_SU_BEAMFORMEE 0x01
2646#define IEEE80211_HE_PHY_CAP4_MU_BEAMFORMER 0x02
2647
2648/* Minimal allowed value of Max STS under 80MHz is 3 */
2649#define IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_UNDER_80MHZ_4 0x0c
2650#define IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_UNDER_80MHZ_5 0x10
2651#define IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_UNDER_80MHZ_6 0x14
2652#define IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_UNDER_80MHZ_7 0x18
2653#define IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_UNDER_80MHZ_8 0x1c
2654#define IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_UNDER_80MHZ_MASK 0x1c
2655
2656/* Minimal allowed value of Max STS above 80MHz is 3 */
2657#define IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_ABOVE_80MHZ_4 0x60
2658#define IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_ABOVE_80MHZ_5 0x80
2659#define IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_ABOVE_80MHZ_6 0xa0
2660#define IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_ABOVE_80MHZ_7 0xc0
2661#define IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_ABOVE_80MHZ_8 0xe0
2662#define IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_ABOVE_80MHZ_MASK 0xe0
2663
2664#define IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_UNDER_80MHZ_1 0x00
2665#define IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_UNDER_80MHZ_2 0x01
2666#define IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_UNDER_80MHZ_3 0x02
2667#define IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_UNDER_80MHZ_4 0x03
2668#define IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_UNDER_80MHZ_5 0x04
2669#define IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_UNDER_80MHZ_6 0x05
2670#define IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_UNDER_80MHZ_7 0x06
2671#define IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_UNDER_80MHZ_8 0x07
2672#define IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_UNDER_80MHZ_MASK 0x07
2673
2674#define IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_ABOVE_80MHZ_1 0x00
2675#define IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_ABOVE_80MHZ_2 0x08
2676#define IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_ABOVE_80MHZ_3 0x10
2677#define IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_ABOVE_80MHZ_4 0x18
2678#define IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_ABOVE_80MHZ_5 0x20
2679#define IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_ABOVE_80MHZ_6 0x28
2680#define IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_ABOVE_80MHZ_7 0x30
2681#define IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_ABOVE_80MHZ_8 0x38
2682#define IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_ABOVE_80MHZ_MASK 0x38
2683
2684#define IEEE80211_HE_PHY_CAP5_NG16_SU_FEEDBACK 0x40
2685#define IEEE80211_HE_PHY_CAP5_NG16_MU_FEEDBACK 0x80
2686
2687#define IEEE80211_HE_PHY_CAP6_CODEBOOK_SIZE_42_SU 0x01
2688#define IEEE80211_HE_PHY_CAP6_CODEBOOK_SIZE_75_MU 0x02
2689#define IEEE80211_HE_PHY_CAP6_TRIG_SU_BEAMFORMING_FB 0x04
2690#define IEEE80211_HE_PHY_CAP6_TRIG_MU_BEAMFORMING_PARTIAL_BW_FB 0x08
2691#define IEEE80211_HE_PHY_CAP6_TRIG_CQI_FB 0x10
2692#define IEEE80211_HE_PHY_CAP6_PARTIAL_BW_EXT_RANGE 0x20
2693#define IEEE80211_HE_PHY_CAP6_PARTIAL_BANDWIDTH_DL_MUMIMO 0x40
2694#define IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT 0x80
2695
2696#define IEEE80211_HE_PHY_CAP7_PSR_BASED_SR 0x01
2697#define IEEE80211_HE_PHY_CAP7_POWER_BOOST_FACTOR_SUPP 0x02
2698#define IEEE80211_HE_PHY_CAP7_HE_SU_MU_PPDU_4XLTF_AND_08_US_GI 0x04
2699#define IEEE80211_HE_PHY_CAP7_MAX_NC_1 0x08
2700#define IEEE80211_HE_PHY_CAP7_MAX_NC_2 0x10
2701#define IEEE80211_HE_PHY_CAP7_MAX_NC_3 0x18
2702#define IEEE80211_HE_PHY_CAP7_MAX_NC_4 0x20
2703#define IEEE80211_HE_PHY_CAP7_MAX_NC_5 0x28
2704#define IEEE80211_HE_PHY_CAP7_MAX_NC_6 0x30
2705#define IEEE80211_HE_PHY_CAP7_MAX_NC_7 0x38
2706#define IEEE80211_HE_PHY_CAP7_MAX_NC_MASK 0x38
2707#define IEEE80211_HE_PHY_CAP7_STBC_TX_ABOVE_80MHZ 0x40
2708#define IEEE80211_HE_PHY_CAP7_STBC_RX_ABOVE_80MHZ 0x80
2709
2710#define IEEE80211_HE_PHY_CAP8_HE_ER_SU_PPDU_4XLTF_AND_08_US_GI 0x01
2711#define IEEE80211_HE_PHY_CAP8_20MHZ_IN_40MHZ_HE_PPDU_IN_2G 0x02
2712#define IEEE80211_HE_PHY_CAP8_20MHZ_IN_160MHZ_HE_PPDU 0x04
2713#define IEEE80211_HE_PHY_CAP8_80MHZ_IN_160MHZ_HE_PPDU 0x08
2714#define IEEE80211_HE_PHY_CAP8_HE_ER_SU_1XLTF_AND_08_US_GI 0x10
2715#define IEEE80211_HE_PHY_CAP8_MIDAMBLE_RX_TX_2X_AND_1XLTF 0x20
2716#define IEEE80211_HE_PHY_CAP8_DCM_MAX_RU_242 0x00
2717#define IEEE80211_HE_PHY_CAP8_DCM_MAX_RU_484 0x40
2718#define IEEE80211_HE_PHY_CAP8_DCM_MAX_RU_996 0x80
2719#define IEEE80211_HE_PHY_CAP8_DCM_MAX_RU_2x996 0xc0
2720#define IEEE80211_HE_PHY_CAP8_DCM_MAX_RU_MASK 0xc0
2721
2722#define IEEE80211_HE_PHY_CAP9_LONGER_THAN_16_SIGB_OFDM_SYM 0x01
2723#define IEEE80211_HE_PHY_CAP9_NON_TRIGGERED_CQI_FEEDBACK 0x02
2724#define IEEE80211_HE_PHY_CAP9_TX_1024_QAM_LESS_THAN_242_TONE_RU 0x04
2725#define IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU 0x08
2726#define IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_COMP_SIGB 0x10
2727#define IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_NON_COMP_SIGB 0x20
2728#define IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_0US 0x0
2729#define IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_8US 0x1
2730#define IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_16US 0x2
2731#define IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_RESERVED 0x3
2732#define IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_POS 6
2733#define IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_MASK 0xc0
2734
2735#define IEEE80211_HE_PHY_CAP10_HE_MU_M1RU_MAX_LTF 0x01
2736
2737/* 802.11ax HE TX/RX MCS NSS Support */
2738#define IEEE80211_TX_RX_MCS_NSS_SUPP_HIGHEST_MCS_POS (3)
2739#define IEEE80211_TX_RX_MCS_NSS_SUPP_TX_BITMAP_POS (6)
2740#define IEEE80211_TX_RX_MCS_NSS_SUPP_RX_BITMAP_POS (11)
2741#define IEEE80211_TX_RX_MCS_NSS_SUPP_TX_BITMAP_MASK 0x07c0
2742#define IEEE80211_TX_RX_MCS_NSS_SUPP_RX_BITMAP_MASK 0xf800
2743
2744/* TX/RX HE MCS Support field Highest MCS subfield encoding */
2745enum ieee80211_he_highest_mcs_supported_subfield_enc {
2746 HIGHEST_MCS_SUPPORTED_MCS7 = 0,
2747 HIGHEST_MCS_SUPPORTED_MCS8,
2748 HIGHEST_MCS_SUPPORTED_MCS9,
2749 HIGHEST_MCS_SUPPORTED_MCS10,
2750 HIGHEST_MCS_SUPPORTED_MCS11,
2751};
2752
2753/* Calculate 802.11ax HE capabilities IE Tx/Rx HE MCS NSS Support Field size */
2754static inline u8
2755ieee80211_he_mcs_nss_size(const struct ieee80211_he_cap_elem *he_cap)
2756{
2757 u8 count = 4;
2758
2759 if (he_cap->phy_cap_info[0] &
2760 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G)
2761 count += 4;
2762
2763 if (he_cap->phy_cap_info[0] &
2764 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G)
2765 count += 4;
2766
2767 return count;
2768}
2769
2770/* 802.11ax HE PPE Thresholds */
2771#define IEEE80211_PPE_THRES_NSS_SUPPORT_2NSS (1)
2772#define IEEE80211_PPE_THRES_NSS_POS (0)
2773#define IEEE80211_PPE_THRES_NSS_MASK (7)
2774#define IEEE80211_PPE_THRES_RU_INDEX_BITMASK_2x966_AND_966_RU \
2775 (BIT(5) | BIT(6))
2776#define IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK 0x78
2777#define IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS (3)
2778#define IEEE80211_PPE_THRES_INFO_PPET_SIZE (3)
2779#define IEEE80211_HE_PPE_THRES_INFO_HEADER_SIZE (7)
2780
2781/*
2782 * Calculate 802.11ax HE capabilities IE PPE field size
2783 * Input: Header byte of ppe_thres (first byte), and HE capa IE's PHY cap u8*
2784 */
2785static inline u8
2786ieee80211_he_ppe_size(u8 ppe_thres_hdr, const u8 *phy_cap_info)
2787{
2788 u8 n;
2789
2790 if ((phy_cap_info[6] &
2791 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) == 0)
2792 return 0;
2793
2794 n = hweight8(ppe_thres_hdr &
2795 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK);
2796 n *= (1 + ((ppe_thres_hdr & IEEE80211_PPE_THRES_NSS_MASK) >>
2797 IEEE80211_PPE_THRES_NSS_POS));
2798
2799 /*
2800 * Each pair is 6 bits, and we need to add the 7 "header" bits to the
2801 * total size.
2802 */
2803 n = (n * IEEE80211_PPE_THRES_INFO_PPET_SIZE * 2) + 7;
2804 n = DIV_ROUND_UP(n, 8);
2805
2806 return n;
2807}
2808
2809static inline bool ieee80211_he_capa_size_ok(const u8 *data, u8 len)
2810{
2811 const struct ieee80211_he_cap_elem *he_cap_ie_elem = (const void *)data;
2812 u8 needed = sizeof(*he_cap_ie_elem);
2813
2814 if (len < needed)
2815 return false;
2816
2817 needed += ieee80211_he_mcs_nss_size(he_cap: he_cap_ie_elem);
2818 if (len < needed)
2819 return false;
2820
2821 if (he_cap_ie_elem->phy_cap_info[6] &
2822 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) {
2823 if (len < needed + 1)
2824 return false;
2825 needed += ieee80211_he_ppe_size(ppe_thres_hdr: data[needed],
2826 phy_cap_info: he_cap_ie_elem->phy_cap_info);
2827 }
2828
2829 return len >= needed;
2830}
2831
2832/* HE Operation defines */
2833#define IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK 0x00000007
2834#define IEEE80211_HE_OPERATION_TWT_REQUIRED 0x00000008
2835#define IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK 0x00003ff0
2836#define IEEE80211_HE_OPERATION_RTS_THRESHOLD_OFFSET 4
2837#define IEEE80211_HE_OPERATION_VHT_OPER_INFO 0x00004000
2838#define IEEE80211_HE_OPERATION_CO_HOSTED_BSS 0x00008000
2839#define IEEE80211_HE_OPERATION_ER_SU_DISABLE 0x00010000
2840#define IEEE80211_HE_OPERATION_6GHZ_OP_INFO 0x00020000
2841#define IEEE80211_HE_OPERATION_BSS_COLOR_MASK 0x3f000000
2842#define IEEE80211_HE_OPERATION_BSS_COLOR_OFFSET 24
2843#define IEEE80211_HE_OPERATION_PARTIAL_BSS_COLOR 0x40000000
2844#define IEEE80211_HE_OPERATION_BSS_COLOR_DISABLED 0x80000000
2845
2846#define IEEE80211_6GHZ_CTRL_REG_LPI_AP 0
2847#define IEEE80211_6GHZ_CTRL_REG_SP_AP 1
2848#define IEEE80211_6GHZ_CTRL_REG_VLP_AP 2
2849#define IEEE80211_6GHZ_CTRL_REG_INDOOR_LPI_AP 3
2850#define IEEE80211_6GHZ_CTRL_REG_INDOOR_SP_AP_OLD 4
2851#define IEEE80211_6GHZ_CTRL_REG_INDOOR_SP_AP 8
2852
2853/**
2854 * struct ieee80211_he_6ghz_oper - HE 6 GHz operation Information field
2855 * @primary: primary channel
2856 * @control: control flags
2857 * @ccfs0: channel center frequency segment 0
2858 * @ccfs1: channel center frequency segment 1
2859 * @minrate: minimum rate (in 1 Mbps units)
2860 */
2861struct ieee80211_he_6ghz_oper {
2862 u8 primary;
2863#define IEEE80211_HE_6GHZ_OPER_CTRL_CHANWIDTH 0x3
2864#define IEEE80211_HE_6GHZ_OPER_CTRL_CHANWIDTH_20MHZ 0
2865#define IEEE80211_HE_6GHZ_OPER_CTRL_CHANWIDTH_40MHZ 1
2866#define IEEE80211_HE_6GHZ_OPER_CTRL_CHANWIDTH_80MHZ 2
2867#define IEEE80211_HE_6GHZ_OPER_CTRL_CHANWIDTH_160MHZ 3
2868#define IEEE80211_HE_6GHZ_OPER_CTRL_DUP_BEACON 0x4
2869#define IEEE80211_HE_6GHZ_OPER_CTRL_REG_INFO 0x78
2870 u8 control;
2871 u8 ccfs0;
2872 u8 ccfs1;
2873 u8 minrate;
2874} __packed;
2875
2876/**
2877 * enum ieee80211_reg_conn_bits - represents Regulatory connectivity field bits.
2878 *
2879 * This enumeration defines bit flags used to represent regulatory connectivity
2880 * field bits.
2881 *
2882 * @IEEE80211_REG_CONN_LPI_VALID: Indicates whether the LPI bit is valid.
2883 * @IEEE80211_REG_CONN_LPI_VALUE: Represents the value of the LPI bit.
2884 * @IEEE80211_REG_CONN_SP_VALID: Indicates whether the SP bit is valid.
2885 * @IEEE80211_REG_CONN_SP_VALUE: Represents the value of the SP bit.
2886 */
2887enum ieee80211_reg_conn_bits {
2888 IEEE80211_REG_CONN_LPI_VALID = BIT(0),
2889 IEEE80211_REG_CONN_LPI_VALUE = BIT(1),
2890 IEEE80211_REG_CONN_SP_VALID = BIT(2),
2891 IEEE80211_REG_CONN_SP_VALUE = BIT(3),
2892};
2893
2894/* transmit power interpretation type of transmit power envelope element */
2895enum ieee80211_tx_power_intrpt_type {
2896 IEEE80211_TPE_LOCAL_EIRP,
2897 IEEE80211_TPE_LOCAL_EIRP_PSD,
2898 IEEE80211_TPE_REG_CLIENT_EIRP,
2899 IEEE80211_TPE_REG_CLIENT_EIRP_PSD,
2900};
2901
2902/* category type of transmit power envelope element */
2903enum ieee80211_tx_power_category_6ghz {
2904 IEEE80211_TPE_CAT_6GHZ_DEFAULT = 0,
2905 IEEE80211_TPE_CAT_6GHZ_SUBORDINATE = 1,
2906};
2907
2908/*
2909 * For IEEE80211_TPE_LOCAL_EIRP / IEEE80211_TPE_REG_CLIENT_EIRP,
2910 * setting to 63.5 dBm means no constraint.
2911 */
2912#define IEEE80211_TPE_MAX_TX_PWR_NO_CONSTRAINT 127
2913
2914/*
2915 * For IEEE80211_TPE_LOCAL_EIRP_PSD / IEEE80211_TPE_REG_CLIENT_EIRP_PSD,
2916 * setting to 127 indicates no PSD limit for the 20 MHz channel.
2917 */
2918#define IEEE80211_TPE_PSD_NO_LIMIT 127
2919
2920/**
2921 * struct ieee80211_tx_pwr_env - Transmit Power Envelope
2922 * @info: Transmit Power Information field
2923 * @variable: Maximum Transmit Power field
2924 *
2925 * This structure represents the payload of the "Transmit Power
2926 * Envelope element" as described in IEEE Std 802.11ax-2021 section
2927 * 9.4.2.161
2928 */
2929struct ieee80211_tx_pwr_env {
2930 u8 info;
2931 u8 variable[];
2932} __packed;
2933
2934#define IEEE80211_TX_PWR_ENV_INFO_COUNT 0x7
2935#define IEEE80211_TX_PWR_ENV_INFO_INTERPRET 0x38
2936#define IEEE80211_TX_PWR_ENV_INFO_CATEGORY 0xC0
2937
2938#define IEEE80211_TX_PWR_ENV_EXT_COUNT 0xF
2939
2940static inline bool ieee80211_valid_tpe_element(const u8 *data, u8 len)
2941{
2942 const struct ieee80211_tx_pwr_env *env = (const void *)data;
2943 u8 count, interpret, category;
2944 u8 needed = sizeof(*env);
2945 u8 N; /* also called N in the spec */
2946
2947 if (len < needed)
2948 return false;
2949
2950 count = u8_get_bits(v: env->info, IEEE80211_TX_PWR_ENV_INFO_COUNT);
2951 interpret = u8_get_bits(v: env->info, IEEE80211_TX_PWR_ENV_INFO_INTERPRET);
2952 category = u8_get_bits(v: env->info, IEEE80211_TX_PWR_ENV_INFO_CATEGORY);
2953
2954 switch (category) {
2955 case IEEE80211_TPE_CAT_6GHZ_DEFAULT:
2956 case IEEE80211_TPE_CAT_6GHZ_SUBORDINATE:
2957 break;
2958 default:
2959 return false;
2960 }
2961
2962 switch (interpret) {
2963 case IEEE80211_TPE_LOCAL_EIRP:
2964 case IEEE80211_TPE_REG_CLIENT_EIRP:
2965 if (count > 3)
2966 return false;
2967
2968 /* count == 0 encodes 1 value for 20 MHz, etc. */
2969 needed += count + 1;
2970
2971 if (len < needed)
2972 return false;
2973
2974 /* there can be extension fields not accounted for in 'count' */
2975
2976 return true;
2977 case IEEE80211_TPE_LOCAL_EIRP_PSD:
2978 case IEEE80211_TPE_REG_CLIENT_EIRP_PSD:
2979 if (count > 4)
2980 return false;
2981
2982 N = count ? 1 << (count - 1) : 1;
2983 needed += N;
2984
2985 if (len < needed)
2986 return false;
2987
2988 if (len > needed) {
2989 u8 K = u8_get_bits(v: env->variable[N],
2990 IEEE80211_TX_PWR_ENV_EXT_COUNT);
2991
2992 needed += 1 + K;
2993 if (len < needed)
2994 return false;
2995 }
2996
2997 return true;
2998 }
2999
3000 return false;
3001}
3002
3003/*
3004 * ieee80211_he_oper_size - calculate 802.11ax HE Operations IE size
3005 * @he_oper_ie: byte data of the He Operations IE, stating from the byte
3006 * after the ext ID byte. It is assumed that he_oper_ie has at least
3007 * sizeof(struct ieee80211_he_operation) bytes, the caller must have
3008 * validated this.
3009 * @return the actual size of the IE data (not including header), or 0 on error
3010 */
3011static inline u8
3012ieee80211_he_oper_size(const u8 *he_oper_ie)
3013{
3014 const struct ieee80211_he_operation *he_oper = (const void *)he_oper_ie;
3015 u8 oper_len = sizeof(struct ieee80211_he_operation);
3016 u32 he_oper_params;
3017
3018 /* Make sure the input is not NULL */
3019 if (!he_oper_ie)
3020 return 0;
3021
3022 /* Calc required length */
3023 he_oper_params = le32_to_cpu(he_oper->he_oper_params);
3024 if (he_oper_params & IEEE80211_HE_OPERATION_VHT_OPER_INFO)
3025 oper_len += 3;
3026 if (he_oper_params & IEEE80211_HE_OPERATION_CO_HOSTED_BSS)
3027 oper_len++;
3028 if (he_oper_params & IEEE80211_HE_OPERATION_6GHZ_OP_INFO)
3029 oper_len += sizeof(struct ieee80211_he_6ghz_oper);
3030
3031 /* Add the first byte (extension ID) to the total length */
3032 oper_len++;
3033
3034 return oper_len;
3035}
3036
3037/**
3038 * ieee80211_he_6ghz_oper - obtain 6 GHz operation field
3039 * @he_oper: HE operation element (must be pre-validated for size)
3040 * but may be %NULL
3041 *
3042 * Return: a pointer to the 6 GHz operation field, or %NULL
3043 */
3044static inline const struct ieee80211_he_6ghz_oper *
3045ieee80211_he_6ghz_oper(const struct ieee80211_he_operation *he_oper)
3046{
3047 const u8 *ret;
3048 u32 he_oper_params;
3049
3050 if (!he_oper)
3051 return NULL;
3052
3053 ret = (const void *)&he_oper->optional;
3054
3055 he_oper_params = le32_to_cpu(he_oper->he_oper_params);
3056
3057 if (!(he_oper_params & IEEE80211_HE_OPERATION_6GHZ_OP_INFO))
3058 return NULL;
3059 if (he_oper_params & IEEE80211_HE_OPERATION_VHT_OPER_INFO)
3060 ret += 3;
3061 if (he_oper_params & IEEE80211_HE_OPERATION_CO_HOSTED_BSS)
3062 ret++;
3063
3064 return (const void *)ret;
3065}
3066
3067/* HE Spatial Reuse defines */
3068#define IEEE80211_HE_SPR_PSR_DISALLOWED BIT(0)
3069#define IEEE80211_HE_SPR_NON_SRG_OBSS_PD_SR_DISALLOWED BIT(1)
3070#define IEEE80211_HE_SPR_NON_SRG_OFFSET_PRESENT BIT(2)
3071#define IEEE80211_HE_SPR_SRG_INFORMATION_PRESENT BIT(3)
3072#define IEEE80211_HE_SPR_HESIGA_SR_VAL15_ALLOWED BIT(4)
3073
3074/*
3075 * ieee80211_he_spr_size - calculate 802.11ax HE Spatial Reuse IE size
3076 * @he_spr_ie: byte data of the He Spatial Reuse IE, stating from the byte
3077 * after the ext ID byte. It is assumed that he_spr_ie has at least
3078 * sizeof(struct ieee80211_he_spr) bytes, the caller must have validated
3079 * this
3080 * @return the actual size of the IE data (not including header), or 0 on error
3081 */
3082static inline u8
3083ieee80211_he_spr_size(const u8 *he_spr_ie)
3084{
3085 const struct ieee80211_he_spr *he_spr = (const void *)he_spr_ie;
3086 u8 spr_len = sizeof(struct ieee80211_he_spr);
3087 u8 he_spr_params;
3088
3089 /* Make sure the input is not NULL */
3090 if (!he_spr_ie)
3091 return 0;
3092
3093 /* Calc required length */
3094 he_spr_params = he_spr->he_sr_control;
3095 if (he_spr_params & IEEE80211_HE_SPR_NON_SRG_OFFSET_PRESENT)
3096 spr_len++;
3097 if (he_spr_params & IEEE80211_HE_SPR_SRG_INFORMATION_PRESENT)
3098 spr_len += 18;
3099
3100 /* Add the first byte (extension ID) to the total length */
3101 spr_len++;
3102
3103 return spr_len;
3104}
3105
3106/* S1G Capabilities Information field */
3107#define IEEE80211_S1G_CAPABILITY_LEN 15
3108
3109#define S1G_CAP0_S1G_LONG BIT(0)
3110#define S1G_CAP0_SGI_1MHZ BIT(1)
3111#define S1G_CAP0_SGI_2MHZ BIT(2)
3112#define S1G_CAP0_SGI_4MHZ BIT(3)
3113#define S1G_CAP0_SGI_8MHZ BIT(4)
3114#define S1G_CAP0_SGI_16MHZ BIT(5)
3115#define S1G_CAP0_SUPP_CH_WIDTH GENMASK(7, 6)
3116
3117#define S1G_SUPP_CH_WIDTH_2 0
3118#define S1G_SUPP_CH_WIDTH_4 1
3119#define S1G_SUPP_CH_WIDTH_8 2
3120#define S1G_SUPP_CH_WIDTH_16 3
3121#define S1G_SUPP_CH_WIDTH_MAX(cap) ((1 << FIELD_GET(S1G_CAP0_SUPP_CH_WIDTH, \
3122 cap[0])) << 1)
3123
3124#define S1G_CAP1_RX_LDPC BIT(0)
3125#define S1G_CAP1_TX_STBC BIT(1)
3126#define S1G_CAP1_RX_STBC BIT(2)
3127#define S1G_CAP1_SU_BFER BIT(3)
3128#define S1G_CAP1_SU_BFEE BIT(4)
3129#define S1G_CAP1_BFEE_STS GENMASK(7, 5)
3130
3131#define S1G_CAP2_SOUNDING_DIMENSIONS GENMASK(2, 0)
3132#define S1G_CAP2_MU_BFER BIT(3)
3133#define S1G_CAP2_MU_BFEE BIT(4)
3134#define S1G_CAP2_PLUS_HTC_VHT BIT(5)
3135#define S1G_CAP2_TRAVELING_PILOT GENMASK(7, 6)
3136
3137#define S1G_CAP3_RD_RESPONDER BIT(0)
3138#define S1G_CAP3_HT_DELAYED_BA BIT(1)
3139#define S1G_CAP3_MAX_MPDU_LEN BIT(2)
3140#define S1G_CAP3_MAX_AMPDU_LEN_EXP GENMASK(4, 3)
3141#define S1G_CAP3_MIN_MPDU_START GENMASK(7, 5)
3142
3143#define S1G_CAP4_UPLINK_SYNC BIT(0)
3144#define S1G_CAP4_DYNAMIC_AID BIT(1)
3145#define S1G_CAP4_BAT BIT(2)
3146#define S1G_CAP4_TIME_ADE BIT(3)
3147#define S1G_CAP4_NON_TIM BIT(4)
3148#define S1G_CAP4_GROUP_AID BIT(5)
3149#define S1G_CAP4_STA_TYPE GENMASK(7, 6)
3150
3151#define S1G_CAP5_CENT_AUTH_CONTROL BIT(0)
3152#define S1G_CAP5_DIST_AUTH_CONTROL BIT(1)
3153#define S1G_CAP5_AMSDU BIT(2)
3154#define S1G_CAP5_AMPDU BIT(3)
3155#define S1G_CAP5_ASYMMETRIC_BA BIT(4)
3156#define S1G_CAP5_FLOW_CONTROL BIT(5)
3157#define S1G_CAP5_SECTORIZED_BEAM GENMASK(7, 6)
3158
3159#define S1G_CAP6_OBSS_MITIGATION BIT(0)
3160#define S1G_CAP6_FRAGMENT_BA BIT(1)
3161#define S1G_CAP6_NDP_PS_POLL BIT(2)
3162#define S1G_CAP6_RAW_OPERATION BIT(3)
3163#define S1G_CAP6_PAGE_SLICING BIT(4)
3164#define S1G_CAP6_TXOP_SHARING_IMP_ACK BIT(5)
3165#define S1G_CAP6_VHT_LINK_ADAPT GENMASK(7, 6)
3166
3167#define S1G_CAP7_TACK_AS_PS_POLL BIT(0)
3168#define S1G_CAP7_DUP_1MHZ BIT(1)
3169#define S1G_CAP7_MCS_NEGOTIATION BIT(2)
3170#define S1G_CAP7_1MHZ_CTL_RESPONSE_PREAMBLE BIT(3)
3171#define S1G_CAP7_NDP_BFING_REPORT_POLL BIT(4)
3172#define S1G_CAP7_UNSOLICITED_DYN_AID BIT(5)
3173#define S1G_CAP7_SECTOR_TRAINING_OPERATION BIT(6)
3174#define S1G_CAP7_TEMP_PS_MODE_SWITCH BIT(7)
3175
3176#define S1G_CAP8_TWT_GROUPING BIT(0)
3177#define S1G_CAP8_BDT BIT(1)
3178#define S1G_CAP8_COLOR GENMASK(4, 2)
3179#define S1G_CAP8_TWT_REQUEST BIT(5)
3180#define S1G_CAP8_TWT_RESPOND BIT(6)
3181#define S1G_CAP8_PV1_FRAME BIT(7)
3182
3183#define S1G_CAP9_LINK_ADAPT_PER_CONTROL_RESPONSE BIT(0)
3184
3185#define S1G_OPER_CH_WIDTH_PRIMARY BIT(0)
3186#define S1G_OPER_CH_WIDTH_OPER GENMASK(4, 1)
3187#define S1G_OPER_CH_PRIMARY_LOCATION BIT(5)
3188
3189#define S1G_2M_PRIMARY_LOCATION_LOWER 0
3190#define S1G_2M_PRIMARY_LOCATION_UPPER 1
3191
3192/* EHT MAC capabilities as defined in P802.11be_D2.0 section 9.4.2.313.2 */
3193#define IEEE80211_EHT_MAC_CAP0_EPCS_PRIO_ACCESS 0x01
3194#define IEEE80211_EHT_MAC_CAP0_OM_CONTROL 0x02
3195#define IEEE80211_EHT_MAC_CAP0_TRIG_TXOP_SHARING_MODE1 0x04
3196#define IEEE80211_EHT_MAC_CAP0_TRIG_TXOP_SHARING_MODE2 0x08
3197#define IEEE80211_EHT_MAC_CAP0_RESTRICTED_TWT 0x10
3198#define IEEE80211_EHT_MAC_CAP0_SCS_TRAFFIC_DESC 0x20
3199#define IEEE80211_EHT_MAC_CAP0_MAX_MPDU_LEN_MASK 0xc0
3200#define IEEE80211_EHT_MAC_CAP0_MAX_MPDU_LEN_3895 0
3201#define IEEE80211_EHT_MAC_CAP0_MAX_MPDU_LEN_7991 1
3202#define IEEE80211_EHT_MAC_CAP0_MAX_MPDU_LEN_11454 2
3203
3204#define IEEE80211_EHT_MAC_CAP1_MAX_AMPDU_LEN_MASK 0x01
3205#define IEEE80211_EHT_MAC_CAP1_EHT_TRS 0x02
3206#define IEEE80211_EHT_MAC_CAP1_TXOP_RET 0x04
3207#define IEEE80211_EHT_MAC_CAP1_TWO_BQRS 0x08
3208#define IEEE80211_EHT_MAC_CAP1_EHT_LINK_ADAPT_MASK 0x30
3209#define IEEE80211_EHT_MAC_CAP1_UNSOL_EPCS_PRIO_ACCESS 0x40
3210
3211/* EHT PHY capabilities as defined in P802.11be_D2.0 section 9.4.2.313.3 */
3212#define IEEE80211_EHT_PHY_CAP0_320MHZ_IN_6GHZ 0x02
3213#define IEEE80211_EHT_PHY_CAP0_242_TONE_RU_GT20MHZ 0x04
3214#define IEEE80211_EHT_PHY_CAP0_NDP_4_EHT_LFT_32_GI 0x08
3215#define IEEE80211_EHT_PHY_CAP0_PARTIAL_BW_UL_MU_MIMO 0x10
3216#define IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMER 0x20
3217#define IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMEE 0x40
3218
3219/* EHT beamformee number of spatial streams <= 80MHz is split */
3220#define IEEE80211_EHT_PHY_CAP0_BEAMFORMEE_SS_80MHZ_MASK 0x80
3221#define IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_80MHZ_MASK 0x03
3222
3223#define IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_160MHZ_MASK 0x1c
3224#define IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_320MHZ_MASK 0xe0
3225
3226#define IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_80MHZ_MASK 0x07
3227#define IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_160MHZ_MASK 0x38
3228
3229/* EHT number of sounding dimensions for 320MHz is split */
3230#define IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_320MHZ_MASK 0xc0
3231#define IEEE80211_EHT_PHY_CAP3_SOUNDING_DIM_320MHZ_MASK 0x01
3232#define IEEE80211_EHT_PHY_CAP3_NG_16_SU_FEEDBACK 0x02
3233#define IEEE80211_EHT_PHY_CAP3_NG_16_MU_FEEDBACK 0x04
3234#define IEEE80211_EHT_PHY_CAP3_CODEBOOK_4_2_SU_FDBK 0x08
3235#define IEEE80211_EHT_PHY_CAP3_CODEBOOK_7_5_MU_FDBK 0x10
3236#define IEEE80211_EHT_PHY_CAP3_TRIG_SU_BF_FDBK 0x20
3237#define IEEE80211_EHT_PHY_CAP3_TRIG_MU_BF_PART_BW_FDBK 0x40
3238#define IEEE80211_EHT_PHY_CAP3_TRIG_CQI_FDBK 0x80
3239
3240#define IEEE80211_EHT_PHY_CAP4_PART_BW_DL_MU_MIMO 0x01
3241#define IEEE80211_EHT_PHY_CAP4_PSR_SR_SUPP 0x02
3242#define IEEE80211_EHT_PHY_CAP4_POWER_BOOST_FACT_SUPP 0x04
3243#define IEEE80211_EHT_PHY_CAP4_EHT_MU_PPDU_4_EHT_LTF_08_GI 0x08
3244#define IEEE80211_EHT_PHY_CAP4_MAX_NC_MASK 0xf0
3245
3246#define IEEE80211_EHT_PHY_CAP5_NON_TRIG_CQI_FEEDBACK 0x01
3247#define IEEE80211_EHT_PHY_CAP5_TX_LESS_242_TONE_RU_SUPP 0x02
3248#define IEEE80211_EHT_PHY_CAP5_RX_LESS_242_TONE_RU_SUPP 0x04
3249#define IEEE80211_EHT_PHY_CAP5_PPE_THRESHOLD_PRESENT 0x08
3250#define IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_MASK 0x30
3251#define IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_0US 0
3252#define IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_8US 1
3253#define IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_16US 2
3254#define IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_20US 3
3255
3256/* Maximum number of supported EHT LTF is split */
3257#define IEEE80211_EHT_PHY_CAP5_MAX_NUM_SUPP_EHT_LTF_MASK 0xc0
3258#define IEEE80211_EHT_PHY_CAP5_SUPP_EXTRA_EHT_LTF 0x40
3259#define IEEE80211_EHT_PHY_CAP6_MAX_NUM_SUPP_EHT_LTF_MASK 0x07
3260
3261#define IEEE80211_EHT_PHY_CAP6_MCS15_SUPP_80MHZ 0x08
3262#define IEEE80211_EHT_PHY_CAP6_MCS15_SUPP_160MHZ 0x30
3263#define IEEE80211_EHT_PHY_CAP6_MCS15_SUPP_320MHZ 0x40
3264#define IEEE80211_EHT_PHY_CAP6_MCS15_SUPP_MASK 0x78
3265#define IEEE80211_EHT_PHY_CAP6_EHT_DUP_6GHZ_SUPP 0x80
3266
3267#define IEEE80211_EHT_PHY_CAP7_20MHZ_STA_RX_NDP_WIDER_BW 0x01
3268#define IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_80MHZ 0x02
3269#define IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_160MHZ 0x04
3270#define IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_320MHZ 0x08
3271#define IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_80MHZ 0x10
3272#define IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_160MHZ 0x20
3273#define IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_320MHZ 0x40
3274#define IEEE80211_EHT_PHY_CAP7_TB_SOUNDING_FDBK_RATE_LIMIT 0x80
3275
3276#define IEEE80211_EHT_PHY_CAP8_RX_1024QAM_WIDER_BW_DL_OFDMA 0x01
3277#define IEEE80211_EHT_PHY_CAP8_RX_4096QAM_WIDER_BW_DL_OFDMA 0x02
3278
3279/*
3280 * EHT operation channel width as defined in P802.11be_D2.0 section 9.4.2.311
3281 */
3282#define IEEE80211_EHT_OPER_CHAN_WIDTH 0x7
3283#define IEEE80211_EHT_OPER_CHAN_WIDTH_20MHZ 0
3284#define IEEE80211_EHT_OPER_CHAN_WIDTH_40MHZ 1
3285#define IEEE80211_EHT_OPER_CHAN_WIDTH_80MHZ 2
3286#define IEEE80211_EHT_OPER_CHAN_WIDTH_160MHZ 3
3287#define IEEE80211_EHT_OPER_CHAN_WIDTH_320MHZ 4
3288
3289/* Calculate 802.11be EHT capabilities IE Tx/Rx EHT MCS NSS Support Field size */
3290static inline u8
3291ieee80211_eht_mcs_nss_size(const struct ieee80211_he_cap_elem *he_cap,
3292 const struct ieee80211_eht_cap_elem_fixed *eht_cap,
3293 bool from_ap)
3294{
3295 u8 count = 0;
3296
3297 /* on 2.4 GHz, if it supports 40 MHz, the result is 3 */
3298 if (he_cap->phy_cap_info[0] &
3299 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G)
3300 return 3;
3301
3302 /* on 2.4 GHz, these three bits are reserved, so should be 0 */
3303 if (he_cap->phy_cap_info[0] &
3304 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G)
3305 count += 3;
3306
3307 if (he_cap->phy_cap_info[0] &
3308 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G)
3309 count += 3;
3310
3311 if (eht_cap->phy_cap_info[0] & IEEE80211_EHT_PHY_CAP0_320MHZ_IN_6GHZ)
3312 count += 3;
3313
3314 if (count)
3315 return count;
3316
3317 return from_ap ? 3 : 4;
3318}
3319
3320/* 802.11be EHT PPE Thresholds */
3321#define IEEE80211_EHT_PPE_THRES_NSS_POS 0
3322#define IEEE80211_EHT_PPE_THRES_NSS_MASK 0xf
3323#define IEEE80211_EHT_PPE_THRES_RU_INDEX_BITMASK_MASK 0x1f0
3324#define IEEE80211_EHT_PPE_THRES_INFO_PPET_SIZE 3
3325#define IEEE80211_EHT_PPE_THRES_INFO_HEADER_SIZE 9
3326
3327/*
3328 * Calculate 802.11be EHT capabilities IE EHT field size
3329 */
3330static inline u8
3331ieee80211_eht_ppe_size(u16 ppe_thres_hdr, const u8 *phy_cap_info)
3332{
3333 u32 n;
3334
3335 if (!(phy_cap_info[5] &
3336 IEEE80211_EHT_PHY_CAP5_PPE_THRESHOLD_PRESENT))
3337 return 0;
3338
3339 n = hweight16(ppe_thres_hdr &
3340 IEEE80211_EHT_PPE_THRES_RU_INDEX_BITMASK_MASK);
3341 n *= 1 + u16_get_bits(v: ppe_thres_hdr, IEEE80211_EHT_PPE_THRES_NSS_MASK);
3342
3343 /*
3344 * Each pair is 6 bits, and we need to add the 9 "header" bits to the
3345 * total size.
3346 */
3347 n = n * IEEE80211_EHT_PPE_THRES_INFO_PPET_SIZE * 2 +
3348 IEEE80211_EHT_PPE_THRES_INFO_HEADER_SIZE;
3349 return DIV_ROUND_UP(n, 8);
3350}
3351
3352static inline bool
3353ieee80211_eht_capa_size_ok(const u8 *he_capa, const u8 *data, u8 len,
3354 bool from_ap)
3355{
3356 const struct ieee80211_eht_cap_elem_fixed *elem = (const void *)data;
3357 u8 needed = sizeof(struct ieee80211_eht_cap_elem_fixed);
3358
3359 if (len < needed || !he_capa)
3360 return false;
3361
3362 needed += ieee80211_eht_mcs_nss_size(he_cap: (const void *)he_capa,
3363 eht_cap: (const void *)data,
3364 from_ap);
3365 if (len < needed)
3366 return false;
3367
3368 if (elem->phy_cap_info[5] &
3369 IEEE80211_EHT_PHY_CAP5_PPE_THRESHOLD_PRESENT) {
3370 u16 ppe_thres_hdr;
3371
3372 if (len < needed + sizeof(ppe_thres_hdr))
3373 return false;
3374
3375 ppe_thres_hdr = get_unaligned_le16(p: data + needed);
3376 needed += ieee80211_eht_ppe_size(ppe_thres_hdr,
3377 phy_cap_info: elem->phy_cap_info);
3378 }
3379
3380 return len >= needed;
3381}
3382
3383static inline bool
3384ieee80211_eht_oper_size_ok(const u8 *data, u8 len)
3385{
3386 const struct ieee80211_eht_operation *elem = (const void *)data;
3387 u8 needed = sizeof(*elem);
3388
3389 if (len < needed)
3390 return false;
3391
3392 if (elem->params & IEEE80211_EHT_OPER_INFO_PRESENT) {
3393 needed += 3;
3394
3395 if (elem->params &
3396 IEEE80211_EHT_OPER_DISABLED_SUBCHANNEL_BITMAP_PRESENT)
3397 needed += 2;
3398 }
3399
3400 return len >= needed;
3401}
3402
3403/* must validate ieee80211_eht_oper_size_ok() first */
3404static inline u16
3405ieee80211_eht_oper_dis_subchan_bitmap(const struct ieee80211_eht_operation *eht_oper)
3406{
3407 const struct ieee80211_eht_operation_info *info =
3408 (const void *)eht_oper->optional;
3409
3410 if (!(eht_oper->params & IEEE80211_EHT_OPER_INFO_PRESENT))
3411 return 0;
3412
3413 if (!(eht_oper->params & IEEE80211_EHT_OPER_DISABLED_SUBCHANNEL_BITMAP_PRESENT))
3414 return 0;
3415
3416 return get_unaligned_le16(p: info->optional);
3417}
3418
3419#define IEEE80211_BW_IND_DIS_SUBCH_PRESENT BIT(1)
3420
3421struct ieee80211_bandwidth_indication {
3422 u8 params;
3423 struct ieee80211_eht_operation_info info;
3424} __packed;
3425
3426static inline bool
3427ieee80211_bandwidth_indication_size_ok(const u8 *data, u8 len)
3428{
3429 const struct ieee80211_bandwidth_indication *bwi = (const void *)data;
3430
3431 if (len < sizeof(*bwi))
3432 return false;
3433
3434 if (bwi->params & IEEE80211_BW_IND_DIS_SUBCH_PRESENT &&
3435 len < sizeof(*bwi) + 2)
3436 return false;
3437
3438 return true;
3439}
3440
3441#define LISTEN_INT_USF GENMASK(15, 14)
3442#define LISTEN_INT_UI GENMASK(13, 0)
3443
3444#define IEEE80211_MAX_USF FIELD_MAX(LISTEN_INT_USF)
3445#define IEEE80211_MAX_UI FIELD_MAX(LISTEN_INT_UI)
3446
3447/* Authentication algorithms */
3448#define WLAN_AUTH_OPEN 0
3449#define WLAN_AUTH_SHARED_KEY 1
3450#define WLAN_AUTH_FT 2
3451#define WLAN_AUTH_SAE 3
3452#define WLAN_AUTH_FILS_SK 4
3453#define WLAN_AUTH_FILS_SK_PFS 5
3454#define WLAN_AUTH_FILS_PK 6
3455#define WLAN_AUTH_LEAP 128
3456
3457#define WLAN_AUTH_CHALLENGE_LEN 128
3458
3459#define WLAN_CAPABILITY_ESS (1<<0)
3460#define WLAN_CAPABILITY_IBSS (1<<1)
3461
3462/*
3463 * A mesh STA sets the ESS and IBSS capability bits to zero.
3464 * however, this holds true for p2p probe responses (in the p2p_find
3465 * phase) as well.
3466 */
3467#define WLAN_CAPABILITY_IS_STA_BSS(cap) \
3468 (!((cap) & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)))
3469
3470#define WLAN_CAPABILITY_CF_POLLABLE (1<<2)
3471#define WLAN_CAPABILITY_CF_POLL_REQUEST (1<<3)
3472#define WLAN_CAPABILITY_PRIVACY (1<<4)
3473#define WLAN_CAPABILITY_SHORT_PREAMBLE (1<<5)
3474#define WLAN_CAPABILITY_PBCC (1<<6)
3475#define WLAN_CAPABILITY_CHANNEL_AGILITY (1<<7)
3476
3477/* 802.11h */
3478#define WLAN_CAPABILITY_SPECTRUM_MGMT (1<<8)
3479#define WLAN_CAPABILITY_QOS (1<<9)
3480#define WLAN_CAPABILITY_SHORT_SLOT_TIME (1<<10)
3481#define WLAN_CAPABILITY_APSD (1<<11)
3482#define WLAN_CAPABILITY_RADIO_MEASURE (1<<12)
3483#define WLAN_CAPABILITY_DSSS_OFDM (1<<13)
3484#define WLAN_CAPABILITY_DEL_BACK (1<<14)
3485#define WLAN_CAPABILITY_IMM_BACK (1<<15)
3486
3487/* DMG (60gHz) 802.11ad */
3488/* type - bits 0..1 */
3489#define WLAN_CAPABILITY_DMG_TYPE_MASK (3<<0)
3490#define WLAN_CAPABILITY_DMG_TYPE_IBSS (1<<0) /* Tx by: STA */
3491#define WLAN_CAPABILITY_DMG_TYPE_PBSS (2<<0) /* Tx by: PCP */
3492#define WLAN_CAPABILITY_DMG_TYPE_AP (3<<0) /* Tx by: AP */
3493
3494#define WLAN_CAPABILITY_DMG_CBAP_ONLY (1<<2)
3495#define WLAN_CAPABILITY_DMG_CBAP_SOURCE (1<<3)
3496#define WLAN_CAPABILITY_DMG_PRIVACY (1<<4)
3497#define WLAN_CAPABILITY_DMG_ECPAC (1<<5)
3498
3499#define WLAN_CAPABILITY_DMG_SPECTRUM_MGMT (1<<8)
3500#define WLAN_CAPABILITY_DMG_RADIO_MEASURE (1<<12)
3501
3502/* measurement */
3503#define IEEE80211_SPCT_MSR_RPRT_MODE_LATE (1<<0)
3504#define IEEE80211_SPCT_MSR_RPRT_MODE_INCAPABLE (1<<1)
3505#define IEEE80211_SPCT_MSR_RPRT_MODE_REFUSED (1<<2)
3506
3507#define IEEE80211_SPCT_MSR_RPRT_TYPE_BASIC 0
3508#define IEEE80211_SPCT_MSR_RPRT_TYPE_CCA 1
3509#define IEEE80211_SPCT_MSR_RPRT_TYPE_RPI 2
3510#define IEEE80211_SPCT_MSR_RPRT_TYPE_LCI 8
3511#define IEEE80211_SPCT_MSR_RPRT_TYPE_CIVIC 11
3512
3513/* 802.11g ERP information element */
3514#define WLAN_ERP_NON_ERP_PRESENT (1<<0)
3515#define WLAN_ERP_USE_PROTECTION (1<<1)
3516#define WLAN_ERP_BARKER_PREAMBLE (1<<2)
3517
3518/* WLAN_ERP_BARKER_PREAMBLE values */
3519enum {
3520 WLAN_ERP_PREAMBLE_SHORT = 0,
3521 WLAN_ERP_PREAMBLE_LONG = 1,
3522};
3523
3524/* Band ID, 802.11ad #8.4.1.45 */
3525enum {
3526 IEEE80211_BANDID_TV_WS = 0, /* TV white spaces */
3527 IEEE80211_BANDID_SUB1 = 1, /* Sub-1 GHz (excluding TV white spaces) */
3528 IEEE80211_BANDID_2G = 2, /* 2.4 GHz */
3529 IEEE80211_BANDID_3G = 3, /* 3.6 GHz */
3530 IEEE80211_BANDID_5G = 4, /* 4.9 and 5 GHz */
3531 IEEE80211_BANDID_60G = 5, /* 60 GHz */
3532};
3533
3534/* Status codes */
3535enum ieee80211_statuscode {
3536 WLAN_STATUS_SUCCESS = 0,
3537 WLAN_STATUS_UNSPECIFIED_FAILURE = 1,
3538 WLAN_STATUS_CAPS_UNSUPPORTED = 10,
3539 WLAN_STATUS_REASSOC_NO_ASSOC = 11,
3540 WLAN_STATUS_ASSOC_DENIED_UNSPEC = 12,
3541 WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG = 13,
3542 WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION = 14,
3543 WLAN_STATUS_CHALLENGE_FAIL = 15,
3544 WLAN_STATUS_AUTH_TIMEOUT = 16,
3545 WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA = 17,
3546 WLAN_STATUS_ASSOC_DENIED_RATES = 18,
3547 /* 802.11b */
3548 WLAN_STATUS_ASSOC_DENIED_NOSHORTPREAMBLE = 19,
3549 WLAN_STATUS_ASSOC_DENIED_NOPBCC = 20,
3550 WLAN_STATUS_ASSOC_DENIED_NOAGILITY = 21,
3551 /* 802.11h */
3552 WLAN_STATUS_ASSOC_DENIED_NOSPECTRUM = 22,
3553 WLAN_STATUS_ASSOC_REJECTED_BAD_POWER = 23,
3554 WLAN_STATUS_ASSOC_REJECTED_BAD_SUPP_CHAN = 24,
3555 /* 802.11g */
3556 WLAN_STATUS_ASSOC_DENIED_NOSHORTTIME = 25,
3557 WLAN_STATUS_ASSOC_DENIED_NODSSSOFDM = 26,
3558 /* 802.11w */
3559 WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY = 30,
3560 WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION = 31,
3561 /* 802.11i */
3562 WLAN_STATUS_INVALID_IE = 40,
3563 WLAN_STATUS_INVALID_GROUP_CIPHER = 41,
3564 WLAN_STATUS_INVALID_PAIRWISE_CIPHER = 42,
3565 WLAN_STATUS_INVALID_AKMP = 43,
3566 WLAN_STATUS_UNSUPP_RSN_VERSION = 44,
3567 WLAN_STATUS_INVALID_RSN_IE_CAP = 45,
3568 WLAN_STATUS_CIPHER_SUITE_REJECTED = 46,
3569 /* 802.11e */
3570 WLAN_STATUS_UNSPECIFIED_QOS = 32,
3571 WLAN_STATUS_ASSOC_DENIED_NOBANDWIDTH = 33,
3572 WLAN_STATUS_ASSOC_DENIED_LOWACK = 34,
3573 WLAN_STATUS_ASSOC_DENIED_UNSUPP_QOS = 35,
3574 WLAN_STATUS_REQUEST_DECLINED = 37,
3575 WLAN_STATUS_INVALID_QOS_PARAM = 38,
3576 WLAN_STATUS_CHANGE_TSPEC = 39,
3577 WLAN_STATUS_WAIT_TS_DELAY = 47,
3578 WLAN_STATUS_NO_DIRECT_LINK = 48,
3579 WLAN_STATUS_STA_NOT_PRESENT = 49,
3580 WLAN_STATUS_STA_NOT_QSTA = 50,
3581 /* 802.11s */
3582 WLAN_STATUS_ANTI_CLOG_REQUIRED = 76,
3583 WLAN_STATUS_FCG_NOT_SUPP = 78,
3584 WLAN_STATUS_STA_NO_TBTT = 78,
3585 /* 802.11ad */
3586 WLAN_STATUS_REJECTED_WITH_SUGGESTED_CHANGES = 39,
3587 WLAN_STATUS_REJECTED_FOR_DELAY_PERIOD = 47,
3588 WLAN_STATUS_REJECT_WITH_SCHEDULE = 83,
3589 WLAN_STATUS_PENDING_ADMITTING_FST_SESSION = 86,
3590 WLAN_STATUS_PERFORMING_FST_NOW = 87,
3591 WLAN_STATUS_PENDING_GAP_IN_BA_WINDOW = 88,
3592 WLAN_STATUS_REJECT_U_PID_SETTING = 89,
3593 WLAN_STATUS_REJECT_DSE_BAND = 96,
3594 WLAN_STATUS_DENIED_WITH_SUGGESTED_BAND_AND_CHANNEL = 99,
3595 WLAN_STATUS_DENIED_DUE_TO_SPECTRUM_MANAGEMENT = 103,
3596 /* 802.11ai */
3597 WLAN_STATUS_FILS_AUTHENTICATION_FAILURE = 108,
3598 WLAN_STATUS_UNKNOWN_AUTHENTICATION_SERVER = 109,
3599 WLAN_STATUS_SAE_HASH_TO_ELEMENT = 126,
3600 WLAN_STATUS_SAE_PK = 127,
3601 WLAN_STATUS_DENIED_TID_TO_LINK_MAPPING = 133,
3602 WLAN_STATUS_PREF_TID_TO_LINK_MAPPING_SUGGESTED = 134,
3603};
3604
3605
3606/* Reason codes */
3607enum ieee80211_reasoncode {
3608 WLAN_REASON_UNSPECIFIED = 1,
3609 WLAN_REASON_PREV_AUTH_NOT_VALID = 2,
3610 WLAN_REASON_DEAUTH_LEAVING = 3,
3611 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY = 4,
3612 WLAN_REASON_DISASSOC_AP_BUSY = 5,
3613 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA = 6,
3614 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA = 7,
3615 WLAN_REASON_DISASSOC_STA_HAS_LEFT = 8,
3616 WLAN_REASON_STA_REQ_ASSOC_WITHOUT_AUTH = 9,
3617 /* 802.11h */
3618 WLAN_REASON_DISASSOC_BAD_POWER = 10,
3619 WLAN_REASON_DISASSOC_BAD_SUPP_CHAN = 11,
3620 /* 802.11i */
3621 WLAN_REASON_INVALID_IE = 13,
3622 WLAN_REASON_MIC_FAILURE = 14,
3623 WLAN_REASON_4WAY_HANDSHAKE_TIMEOUT = 15,
3624 WLAN_REASON_GROUP_KEY_HANDSHAKE_TIMEOUT = 16,
3625 WLAN_REASON_IE_DIFFERENT = 17,
3626 WLAN_REASON_INVALID_GROUP_CIPHER = 18,
3627 WLAN_REASON_INVALID_PAIRWISE_CIPHER = 19,
3628 WLAN_REASON_INVALID_AKMP = 20,
3629 WLAN_REASON_UNSUPP_RSN_VERSION = 21,
3630 WLAN_REASON_INVALID_RSN_IE_CAP = 22,
3631 WLAN_REASON_IEEE8021X_FAILED = 23,
3632 WLAN_REASON_CIPHER_SUITE_REJECTED = 24,
3633 /* TDLS (802.11z) */
3634 WLAN_REASON_TDLS_TEARDOWN_UNREACHABLE = 25,
3635 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED = 26,
3636 /* 802.11e */
3637 WLAN_REASON_DISASSOC_UNSPECIFIED_QOS = 32,
3638 WLAN_REASON_DISASSOC_QAP_NO_BANDWIDTH = 33,
3639 WLAN_REASON_DISASSOC_LOW_ACK = 34,
3640 WLAN_REASON_DISASSOC_QAP_EXCEED_TXOP = 35,
3641 WLAN_REASON_QSTA_LEAVE_QBSS = 36,
3642 WLAN_REASON_QSTA_NOT_USE = 37,
3643 WLAN_REASON_QSTA_REQUIRE_SETUP = 38,
3644 WLAN_REASON_QSTA_TIMEOUT = 39,
3645 WLAN_REASON_QSTA_CIPHER_NOT_SUPP = 45,
3646 /* 802.11s */
3647 WLAN_REASON_MESH_PEER_CANCELED = 52,
3648 WLAN_REASON_MESH_MAX_PEERS = 53,
3649 WLAN_REASON_MESH_CONFIG = 54,
3650 WLAN_REASON_MESH_CLOSE = 55,
3651 WLAN_REASON_MESH_MAX_RETRIES = 56,
3652 WLAN_REASON_MESH_CONFIRM_TIMEOUT = 57,
3653 WLAN_REASON_MESH_INVALID_GTK = 58,
3654 WLAN_REASON_MESH_INCONSISTENT_PARAM = 59,
3655 WLAN_REASON_MESH_INVALID_SECURITY = 60,
3656 WLAN_REASON_MESH_PATH_ERROR = 61,
3657 WLAN_REASON_MESH_PATH_NOFORWARD = 62,
3658 WLAN_REASON_MESH_PATH_DEST_UNREACHABLE = 63,
3659 WLAN_REASON_MAC_EXISTS_IN_MBSS = 64,
3660 WLAN_REASON_MESH_CHAN_REGULATORY = 65,
3661 WLAN_REASON_MESH_CHAN = 66,
3662};
3663
3664
3665/* Information Element IDs */
3666enum ieee80211_eid {
3667 WLAN_EID_SSID = 0,
3668 WLAN_EID_SUPP_RATES = 1,
3669 WLAN_EID_FH_PARAMS = 2, /* reserved now */
3670 WLAN_EID_DS_PARAMS = 3,
3671 WLAN_EID_CF_PARAMS = 4,
3672 WLAN_EID_TIM = 5,
3673 WLAN_EID_IBSS_PARAMS = 6,
3674 WLAN_EID_COUNTRY = 7,
3675 /* 8, 9 reserved */
3676 WLAN_EID_REQUEST = 10,
3677 WLAN_EID_QBSS_LOAD = 11,
3678 WLAN_EID_EDCA_PARAM_SET = 12,
3679 WLAN_EID_TSPEC = 13,
3680 WLAN_EID_TCLAS = 14,
3681 WLAN_EID_SCHEDULE = 15,
3682 WLAN_EID_CHALLENGE = 16,
3683 /* 17-31 reserved for challenge text extension */
3684 WLAN_EID_PWR_CONSTRAINT = 32,
3685 WLAN_EID_PWR_CAPABILITY = 33,
3686 WLAN_EID_TPC_REQUEST = 34,
3687 WLAN_EID_TPC_REPORT = 35,
3688 WLAN_EID_SUPPORTED_CHANNELS = 36,
3689 WLAN_EID_CHANNEL_SWITCH = 37,
3690 WLAN_EID_MEASURE_REQUEST = 38,
3691 WLAN_EID_MEASURE_REPORT = 39,
3692 WLAN_EID_QUIET = 40,
3693 WLAN_EID_IBSS_DFS = 41,
3694 WLAN_EID_ERP_INFO = 42,
3695 WLAN_EID_TS_DELAY = 43,
3696 WLAN_EID_TCLAS_PROCESSING = 44,
3697 WLAN_EID_HT_CAPABILITY = 45,
3698 WLAN_EID_QOS_CAPA = 46,
3699 /* 47 reserved for Broadcom */
3700 WLAN_EID_RSN = 48,
3701 WLAN_EID_802_15_COEX = 49,
3702 WLAN_EID_EXT_SUPP_RATES = 50,
3703 WLAN_EID_AP_CHAN_REPORT = 51,
3704 WLAN_EID_NEIGHBOR_REPORT = 52,
3705 WLAN_EID_RCPI = 53,
3706 WLAN_EID_MOBILITY_DOMAIN = 54,
3707 WLAN_EID_FAST_BSS_TRANSITION = 55,
3708 WLAN_EID_TIMEOUT_INTERVAL = 56,
3709 WLAN_EID_RIC_DATA = 57,
3710 WLAN_EID_DSE_REGISTERED_LOCATION = 58,
3711 WLAN_EID_SUPPORTED_REGULATORY_CLASSES = 59,
3712 WLAN_EID_EXT_CHANSWITCH_ANN = 60,
3713 WLAN_EID_HT_OPERATION = 61,
3714 WLAN_EID_SECONDARY_CHANNEL_OFFSET = 62,
3715 WLAN_EID_BSS_AVG_ACCESS_DELAY = 63,
3716 WLAN_EID_ANTENNA_INFO = 64,
3717 WLAN_EID_RSNI = 65,
3718 WLAN_EID_MEASUREMENT_PILOT_TX_INFO = 66,
3719 WLAN_EID_BSS_AVAILABLE_CAPACITY = 67,
3720 WLAN_EID_BSS_AC_ACCESS_DELAY = 68,
3721 WLAN_EID_TIME_ADVERTISEMENT = 69,
3722 WLAN_EID_RRM_ENABLED_CAPABILITIES = 70,
3723 WLAN_EID_MULTIPLE_BSSID = 71,
3724 WLAN_EID_BSS_COEX_2040 = 72,
3725 WLAN_EID_BSS_INTOLERANT_CHL_REPORT = 73,
3726 WLAN_EID_OVERLAP_BSS_SCAN_PARAM = 74,
3727 WLAN_EID_RIC_DESCRIPTOR = 75,
3728 WLAN_EID_MMIE = 76,
3729 WLAN_EID_ASSOC_COMEBACK_TIME = 77,
3730 WLAN_EID_EVENT_REQUEST = 78,
3731 WLAN_EID_EVENT_REPORT = 79,
3732 WLAN_EID_DIAGNOSTIC_REQUEST = 80,
3733 WLAN_EID_DIAGNOSTIC_REPORT = 81,
3734 WLAN_EID_LOCATION_PARAMS = 82,
3735 WLAN_EID_NON_TX_BSSID_CAP = 83,
3736 WLAN_EID_SSID_LIST = 84,
3737 WLAN_EID_MULTI_BSSID_IDX = 85,
3738 WLAN_EID_FMS_DESCRIPTOR = 86,
3739 WLAN_EID_FMS_REQUEST = 87,
3740 WLAN_EID_FMS_RESPONSE = 88,
3741 WLAN_EID_QOS_TRAFFIC_CAPA = 89,
3742 WLAN_EID_BSS_MAX_IDLE_PERIOD = 90,
3743 WLAN_EID_TSF_REQUEST = 91,
3744 WLAN_EID_TSF_RESPOSNE = 92,
3745 WLAN_EID_WNM_SLEEP_MODE = 93,
3746 WLAN_EID_TIM_BCAST_REQ = 94,
3747 WLAN_EID_TIM_BCAST_RESP = 95,
3748 WLAN_EID_COLL_IF_REPORT = 96,
3749 WLAN_EID_CHANNEL_USAGE = 97,
3750 WLAN_EID_TIME_ZONE = 98,
3751 WLAN_EID_DMS_REQUEST = 99,
3752 WLAN_EID_DMS_RESPONSE = 100,
3753 WLAN_EID_LINK_ID = 101,
3754 WLAN_EID_WAKEUP_SCHEDUL = 102,
3755 /* 103 reserved */
3756 WLAN_EID_CHAN_SWITCH_TIMING = 104,
3757 WLAN_EID_PTI_CONTROL = 105,
3758 WLAN_EID_PU_BUFFER_STATUS = 106,
3759 WLAN_EID_INTERWORKING = 107,
3760 WLAN_EID_ADVERTISEMENT_PROTOCOL = 108,
3761 WLAN_EID_EXPEDITED_BW_REQ = 109,
3762 WLAN_EID_QOS_MAP_SET = 110,
3763 WLAN_EID_ROAMING_CONSORTIUM = 111,
3764 WLAN_EID_EMERGENCY_ALERT = 112,
3765 WLAN_EID_MESH_CONFIG = 113,
3766 WLAN_EID_MESH_ID = 114,
3767 WLAN_EID_LINK_METRIC_REPORT = 115,
3768 WLAN_EID_CONGESTION_NOTIFICATION = 116,
3769 WLAN_EID_PEER_MGMT = 117,
3770 WLAN_EID_CHAN_SWITCH_PARAM = 118,
3771 WLAN_EID_MESH_AWAKE_WINDOW = 119,
3772 WLAN_EID_BEACON_TIMING = 120,
3773 WLAN_EID_MCCAOP_SETUP_REQ = 121,
3774 WLAN_EID_MCCAOP_SETUP_RESP = 122,
3775 WLAN_EID_MCCAOP_ADVERT = 123,
3776 WLAN_EID_MCCAOP_TEARDOWN = 124,
3777 WLAN_EID_GANN = 125,
3778 WLAN_EID_RANN = 126,
3779 WLAN_EID_EXT_CAPABILITY = 127,
3780 /* 128, 129 reserved for Agere */
3781 WLAN_EID_PREQ = 130,
3782 WLAN_EID_PREP = 131,
3783 WLAN_EID_PERR = 132,
3784 /* 133-136 reserved for Cisco */
3785 WLAN_EID_PXU = 137,
3786 WLAN_EID_PXUC = 138,
3787 WLAN_EID_AUTH_MESH_PEER_EXCH = 139,
3788 WLAN_EID_MIC = 140,
3789 WLAN_EID_DESTINATION_URI = 141,
3790 WLAN_EID_UAPSD_COEX = 142,
3791 WLAN_EID_WAKEUP_SCHEDULE = 143,
3792 WLAN_EID_EXT_SCHEDULE = 144,
3793 WLAN_EID_STA_AVAILABILITY = 145,
3794 WLAN_EID_DMG_TSPEC = 146,
3795 WLAN_EID_DMG_AT = 147,
3796 WLAN_EID_DMG_CAP = 148,
3797 /* 149 reserved for Cisco */
3798 WLAN_EID_CISCO_VENDOR_SPECIFIC = 150,
3799 WLAN_EID_DMG_OPERATION = 151,
3800 WLAN_EID_DMG_BSS_PARAM_CHANGE = 152,
3801 WLAN_EID_DMG_BEAM_REFINEMENT = 153,
3802 WLAN_EID_CHANNEL_MEASURE_FEEDBACK = 154,
3803 /* 155-156 reserved for Cisco */
3804 WLAN_EID_AWAKE_WINDOW = 157,
3805 WLAN_EID_MULTI_BAND = 158,
3806 WLAN_EID_ADDBA_EXT = 159,
3807 WLAN_EID_NEXT_PCP_LIST = 160,
3808 WLAN_EID_PCP_HANDOVER = 161,
3809 WLAN_EID_DMG_LINK_MARGIN = 162,
3810 WLAN_EID_SWITCHING_STREAM = 163,
3811 WLAN_EID_SESSION_TRANSITION = 164,
3812 WLAN_EID_DYN_TONE_PAIRING_REPORT = 165,
3813 WLAN_EID_CLUSTER_REPORT = 166,
3814 WLAN_EID_RELAY_CAP = 167,
3815 WLAN_EID_RELAY_XFER_PARAM_SET = 168,
3816 WLAN_EID_BEAM_LINK_MAINT = 169,
3817 WLAN_EID_MULTIPLE_MAC_ADDR = 170,
3818 WLAN_EID_U_PID = 171,
3819 WLAN_EID_DMG_LINK_ADAPT_ACK = 172,
3820 /* 173 reserved for Symbol */
3821 WLAN_EID_MCCAOP_ADV_OVERVIEW = 174,
3822 WLAN_EID_QUIET_PERIOD_REQ = 175,
3823 /* 176 reserved for Symbol */
3824 WLAN_EID_QUIET_PERIOD_RESP = 177,
3825 /* 178-179 reserved for Symbol */
3826 /* 180 reserved for ISO/IEC 20011 */
3827 WLAN_EID_EPAC_POLICY = 182,
3828 WLAN_EID_CLISTER_TIME_OFF = 183,
3829 WLAN_EID_INTER_AC_PRIO = 184,
3830 WLAN_EID_SCS_DESCRIPTOR = 185,
3831 WLAN_EID_QLOAD_REPORT = 186,
3832 WLAN_EID_HCCA_TXOP_UPDATE_COUNT = 187,
3833 WLAN_EID_HL_STREAM_ID = 188,
3834 WLAN_EID_GCR_GROUP_ADDR = 189,
3835 WLAN_EID_ANTENNA_SECTOR_ID_PATTERN = 190,
3836 WLAN_EID_VHT_CAPABILITY = 191,
3837 WLAN_EID_VHT_OPERATION = 192,
3838 WLAN_EID_EXTENDED_BSS_LOAD = 193,
3839 WLAN_EID_WIDE_BW_CHANNEL_SWITCH = 194,
3840 WLAN_EID_TX_POWER_ENVELOPE = 195,
3841 WLAN_EID_CHANNEL_SWITCH_WRAPPER = 196,
3842 WLAN_EID_AID = 197,
3843 WLAN_EID_QUIET_CHANNEL = 198,
3844 WLAN_EID_OPMODE_NOTIF = 199,
3845
3846 WLAN_EID_REDUCED_NEIGHBOR_REPORT = 201,
3847
3848 WLAN_EID_AID_REQUEST = 210,
3849 WLAN_EID_AID_RESPONSE = 211,
3850 WLAN_EID_S1G_BCN_COMPAT = 213,
3851 WLAN_EID_S1G_SHORT_BCN_INTERVAL = 214,
3852 WLAN_EID_S1G_TWT = 216,
3853 WLAN_EID_S1G_CAPABILITIES = 217,
3854 WLAN_EID_VENDOR_SPECIFIC = 221,
3855 WLAN_EID_QOS_PARAMETER = 222,
3856 WLAN_EID_S1G_OPERATION = 232,
3857 WLAN_EID_CAG_NUMBER = 237,
3858 WLAN_EID_AP_CSN = 239,
3859 WLAN_EID_FILS_INDICATION = 240,
3860 WLAN_EID_DILS = 241,
3861 WLAN_EID_FRAGMENT = 242,
3862 WLAN_EID_RSNX = 244,
3863 WLAN_EID_EXTENSION = 255
3864};
3865
3866/* Element ID Extensions for Element ID 255 */
3867enum ieee80211_eid_ext {
3868 WLAN_EID_EXT_ASSOC_DELAY_INFO = 1,
3869 WLAN_EID_EXT_FILS_REQ_PARAMS = 2,
3870 WLAN_EID_EXT_FILS_KEY_CONFIRM = 3,
3871 WLAN_EID_EXT_FILS_SESSION = 4,
3872 WLAN_EID_EXT_FILS_HLP_CONTAINER = 5,
3873 WLAN_EID_EXT_FILS_IP_ADDR_ASSIGN = 6,
3874 WLAN_EID_EXT_KEY_DELIVERY = 7,
3875 WLAN_EID_EXT_FILS_WRAPPED_DATA = 8,
3876 WLAN_EID_EXT_FILS_PUBLIC_KEY = 12,
3877 WLAN_EID_EXT_FILS_NONCE = 13,
3878 WLAN_EID_EXT_FUTURE_CHAN_GUIDANCE = 14,
3879 WLAN_EID_EXT_DH_PARAMETER = 32,
3880 WLAN_EID_EXT_HE_CAPABILITY = 35,
3881 WLAN_EID_EXT_HE_OPERATION = 36,
3882 WLAN_EID_EXT_UORA = 37,
3883 WLAN_EID_EXT_HE_MU_EDCA = 38,
3884 WLAN_EID_EXT_HE_SPR = 39,
3885 WLAN_EID_EXT_NDP_FEEDBACK_REPORT_PARAMSET = 41,
3886 WLAN_EID_EXT_BSS_COLOR_CHG_ANN = 42,
3887 WLAN_EID_EXT_QUIET_TIME_PERIOD_SETUP = 43,
3888 WLAN_EID_EXT_ESS_REPORT = 45,
3889 WLAN_EID_EXT_OPS = 46,
3890 WLAN_EID_EXT_HE_BSS_LOAD = 47,
3891 WLAN_EID_EXT_MAX_CHANNEL_SWITCH_TIME = 52,
3892 WLAN_EID_EXT_MULTIPLE_BSSID_CONFIGURATION = 55,
3893 WLAN_EID_EXT_NON_INHERITANCE = 56,
3894 WLAN_EID_EXT_KNOWN_BSSID = 57,
3895 WLAN_EID_EXT_SHORT_SSID_LIST = 58,
3896 WLAN_EID_EXT_HE_6GHZ_CAPA = 59,
3897 WLAN_EID_EXT_UL_MU_POWER_CAPA = 60,
3898 WLAN_EID_EXT_EHT_OPERATION = 106,
3899 WLAN_EID_EXT_EHT_MULTI_LINK = 107,
3900 WLAN_EID_EXT_EHT_CAPABILITY = 108,
3901 WLAN_EID_EXT_TID_TO_LINK_MAPPING = 109,
3902 WLAN_EID_EXT_BANDWIDTH_INDICATION = 135,
3903 WLAN_EID_EXT_KNOWN_STA_IDENTIFCATION = 136,
3904 WLAN_EID_EXT_NON_AP_STA_REG_CON = 137,
3905};
3906
3907/* Action category code */
3908enum ieee80211_category {
3909 WLAN_CATEGORY_SPECTRUM_MGMT = 0,
3910 WLAN_CATEGORY_QOS = 1,
3911 WLAN_CATEGORY_DLS = 2,
3912 WLAN_CATEGORY_BACK = 3,
3913 WLAN_CATEGORY_PUBLIC = 4,
3914 WLAN_CATEGORY_RADIO_MEASUREMENT = 5,
3915 WLAN_CATEGORY_FAST_BBS_TRANSITION = 6,
3916 WLAN_CATEGORY_HT = 7,
3917 WLAN_CATEGORY_SA_QUERY = 8,
3918 WLAN_CATEGORY_PROTECTED_DUAL_OF_ACTION = 9,
3919 WLAN_CATEGORY_WNM = 10,
3920 WLAN_CATEGORY_WNM_UNPROTECTED = 11,
3921 WLAN_CATEGORY_TDLS = 12,
3922 WLAN_CATEGORY_MESH_ACTION = 13,
3923 WLAN_CATEGORY_MULTIHOP_ACTION = 14,
3924 WLAN_CATEGORY_SELF_PROTECTED = 15,
3925 WLAN_CATEGORY_DMG = 16,
3926 WLAN_CATEGORY_WMM = 17,
3927 WLAN_CATEGORY_FST = 18,
3928 WLAN_CATEGORY_UNPROT_DMG = 20,
3929 WLAN_CATEGORY_VHT = 21,
3930 WLAN_CATEGORY_S1G = 22,
3931 WLAN_CATEGORY_PROTECTED_EHT = 37,
3932 WLAN_CATEGORY_VENDOR_SPECIFIC_PROTECTED = 126,
3933 WLAN_CATEGORY_VENDOR_SPECIFIC = 127,
3934};
3935
3936/* SPECTRUM_MGMT action code */
3937enum ieee80211_spectrum_mgmt_actioncode {
3938 WLAN_ACTION_SPCT_MSR_REQ = 0,
3939 WLAN_ACTION_SPCT_MSR_RPRT = 1,
3940 WLAN_ACTION_SPCT_TPC_REQ = 2,
3941 WLAN_ACTION_SPCT_TPC_RPRT = 3,
3942 WLAN_ACTION_SPCT_CHL_SWITCH = 4,
3943};
3944
3945/* HT action codes */
3946enum ieee80211_ht_actioncode {
3947 WLAN_HT_ACTION_NOTIFY_CHANWIDTH = 0,
3948 WLAN_HT_ACTION_SMPS = 1,
3949 WLAN_HT_ACTION_PSMP = 2,
3950 WLAN_HT_ACTION_PCO_PHASE = 3,
3951 WLAN_HT_ACTION_CSI = 4,
3952 WLAN_HT_ACTION_NONCOMPRESSED_BF = 5,
3953 WLAN_HT_ACTION_COMPRESSED_BF = 6,
3954 WLAN_HT_ACTION_ASEL_IDX_FEEDBACK = 7,
3955};
3956
3957/* VHT action codes */
3958enum ieee80211_vht_actioncode {
3959 WLAN_VHT_ACTION_COMPRESSED_BF = 0,
3960 WLAN_VHT_ACTION_GROUPID_MGMT = 1,
3961 WLAN_VHT_ACTION_OPMODE_NOTIF = 2,
3962};
3963
3964/* Self Protected Action codes */
3965enum ieee80211_self_protected_actioncode {
3966 WLAN_SP_RESERVED = 0,
3967 WLAN_SP_MESH_PEERING_OPEN = 1,
3968 WLAN_SP_MESH_PEERING_CONFIRM = 2,
3969 WLAN_SP_MESH_PEERING_CLOSE = 3,
3970 WLAN_SP_MGK_INFORM = 4,
3971 WLAN_SP_MGK_ACK = 5,
3972};
3973
3974/* Mesh action codes */
3975enum ieee80211_mesh_actioncode {
3976 WLAN_MESH_ACTION_LINK_METRIC_REPORT,
3977 WLAN_MESH_ACTION_HWMP_PATH_SELECTION,
3978 WLAN_MESH_ACTION_GATE_ANNOUNCEMENT,
3979 WLAN_MESH_ACTION_CONGESTION_CONTROL_NOTIFICATION,
3980 WLAN_MESH_ACTION_MCCA_SETUP_REQUEST,
3981 WLAN_MESH_ACTION_MCCA_SETUP_REPLY,
3982 WLAN_MESH_ACTION_MCCA_ADVERTISEMENT_REQUEST,
3983 WLAN_MESH_ACTION_MCCA_ADVERTISEMENT,
3984 WLAN_MESH_ACTION_MCCA_TEARDOWN,
3985 WLAN_MESH_ACTION_TBTT_ADJUSTMENT_REQUEST,
3986 WLAN_MESH_ACTION_TBTT_ADJUSTMENT_RESPONSE,
3987};
3988
3989/* Unprotected WNM action codes */
3990enum ieee80211_unprotected_wnm_actioncode {
3991 WLAN_UNPROTECTED_WNM_ACTION_TIM = 0,
3992 WLAN_UNPROTECTED_WNM_ACTION_TIMING_MEASUREMENT_RESPONSE = 1,
3993};
3994
3995/* Protected EHT action codes */
3996enum ieee80211_protected_eht_actioncode {
3997 WLAN_PROTECTED_EHT_ACTION_TTLM_REQ = 0,
3998 WLAN_PROTECTED_EHT_ACTION_TTLM_RES = 1,
3999 WLAN_PROTECTED_EHT_ACTION_TTLM_TEARDOWN = 2,
4000 WLAN_PROTECTED_EHT_ACTION_EPCS_ENABLE_REQ = 3,
4001 WLAN_PROTECTED_EHT_ACTION_EPCS_ENABLE_RESP = 4,
4002 WLAN_PROTECTED_EHT_ACTION_EPCS_ENABLE_TEARDOWN = 5,
4003 WLAN_PROTECTED_EHT_ACTION_EML_OP_MODE_NOTIF = 6,
4004 WLAN_PROTECTED_EHT_ACTION_LINK_RECOMMEND = 7,
4005 WLAN_PROTECTED_EHT_ACTION_ML_OP_UPDATE_REQ = 8,
4006 WLAN_PROTECTED_EHT_ACTION_ML_OP_UPDATE_RESP = 9,
4007 WLAN_PROTECTED_EHT_ACTION_LINK_RECONFIG_NOTIF = 10,
4008 WLAN_PROTECTED_EHT_ACTION_LINK_RECONFIG_REQ = 11,
4009 WLAN_PROTECTED_EHT_ACTION_LINK_RECONFIG_RESP = 12,
4010};
4011
4012/* Security key length */
4013enum ieee80211_key_len {
4014 WLAN_KEY_LEN_WEP40 = 5,
4015 WLAN_KEY_LEN_WEP104 = 13,
4016 WLAN_KEY_LEN_CCMP = 16,
4017 WLAN_KEY_LEN_CCMP_256 = 32,
4018 WLAN_KEY_LEN_TKIP = 32,
4019 WLAN_KEY_LEN_AES_CMAC = 16,
4020 WLAN_KEY_LEN_SMS4 = 32,
4021 WLAN_KEY_LEN_GCMP = 16,
4022 WLAN_KEY_LEN_GCMP_256 = 32,
4023 WLAN_KEY_LEN_BIP_CMAC_256 = 32,
4024 WLAN_KEY_LEN_BIP_GMAC_128 = 16,
4025 WLAN_KEY_LEN_BIP_GMAC_256 = 32,
4026};
4027
4028enum ieee80211_s1g_actioncode {
4029 WLAN_S1G_AID_SWITCH_REQUEST,
4030 WLAN_S1G_AID_SWITCH_RESPONSE,
4031 WLAN_S1G_SYNC_CONTROL,
4032 WLAN_S1G_STA_INFO_ANNOUNCE,
4033 WLAN_S1G_EDCA_PARAM_SET,
4034 WLAN_S1G_EL_OPERATION,
4035 WLAN_S1G_TWT_SETUP,
4036 WLAN_S1G_TWT_TEARDOWN,
4037 WLAN_S1G_SECT_GROUP_ID_LIST,
4038 WLAN_S1G_SECT_ID_FEEDBACK,
4039 WLAN_S1G_TWT_INFORMATION = 11,
4040};
4041
4042/* Radio measurement action codes as defined in IEEE 802.11-2024 - Table 9-470 */
4043enum ieee80211_radio_measurement_actioncode {
4044 WLAN_RM_ACTION_RADIO_MEASUREMENT_REQUEST = 0,
4045 WLAN_RM_ACTION_RADIO_MEASUREMENT_REPORT = 1,
4046 WLAN_RM_ACTION_LINK_MEASUREMENT_REQUEST = 2,
4047 WLAN_RM_ACTION_LINK_MEASUREMENT_REPORT = 3,
4048 WLAN_RM_ACTION_NEIGHBOR_REPORT_REQUEST = 4,
4049 WLAN_RM_ACTION_NEIGHBOR_REPORT_RESPONSE = 5,
4050};
4051
4052#define IEEE80211_WEP_IV_LEN 4
4053#define IEEE80211_WEP_ICV_LEN 4
4054#define IEEE80211_CCMP_HDR_LEN 8
4055#define IEEE80211_CCMP_MIC_LEN 8
4056#define IEEE80211_CCMP_PN_LEN 6
4057#define IEEE80211_CCMP_256_HDR_LEN 8
4058#define IEEE80211_CCMP_256_MIC_LEN 16
4059#define IEEE80211_CCMP_256_PN_LEN 6
4060#define IEEE80211_TKIP_IV_LEN 8
4061#define IEEE80211_TKIP_ICV_LEN 4
4062#define IEEE80211_CMAC_PN_LEN 6
4063#define IEEE80211_GMAC_PN_LEN 6
4064#define IEEE80211_GCMP_HDR_LEN 8
4065#define IEEE80211_GCMP_MIC_LEN 16
4066#define IEEE80211_GCMP_PN_LEN 6
4067
4068#define FILS_NONCE_LEN 16
4069#define FILS_MAX_KEK_LEN 64
4070
4071#define FILS_ERP_MAX_USERNAME_LEN 16
4072#define FILS_ERP_MAX_REALM_LEN 253
4073#define FILS_ERP_MAX_RRK_LEN 64
4074
4075#define PMK_MAX_LEN 64
4076#define SAE_PASSWORD_MAX_LEN 128
4077
4078/* Public action codes (IEEE Std 802.11-2016, 9.6.8.1, Table 9-307) */
4079enum ieee80211_pub_actioncode {
4080 WLAN_PUB_ACTION_20_40_BSS_COEX = 0,
4081 WLAN_PUB_ACTION_DSE_ENABLEMENT = 1,
4082 WLAN_PUB_ACTION_DSE_DEENABLEMENT = 2,
4083 WLAN_PUB_ACTION_DSE_REG_LOC_ANN = 3,
4084 WLAN_PUB_ACTION_EXT_CHANSW_ANN = 4,
4085 WLAN_PUB_ACTION_DSE_MSMT_REQ = 5,
4086 WLAN_PUB_ACTION_DSE_MSMT_RESP = 6,
4087 WLAN_PUB_ACTION_MSMT_PILOT = 7,
4088 WLAN_PUB_ACTION_DSE_PC = 8,
4089 WLAN_PUB_ACTION_VENDOR_SPECIFIC = 9,
4090 WLAN_PUB_ACTION_GAS_INITIAL_REQ = 10,
4091 WLAN_PUB_ACTION_GAS_INITIAL_RESP = 11,
4092 WLAN_PUB_ACTION_GAS_COMEBACK_REQ = 12,
4093 WLAN_PUB_ACTION_GAS_COMEBACK_RESP = 13,
4094 WLAN_PUB_ACTION_TDLS_DISCOVER_RES = 14,
4095 WLAN_PUB_ACTION_LOC_TRACK_NOTI = 15,
4096 WLAN_PUB_ACTION_QAB_REQUEST_FRAME = 16,
4097 WLAN_PUB_ACTION_QAB_RESPONSE_FRAME = 17,
4098 WLAN_PUB_ACTION_QMF_POLICY = 18,
4099 WLAN_PUB_ACTION_QMF_POLICY_CHANGE = 19,
4100 WLAN_PUB_ACTION_QLOAD_REQUEST = 20,
4101 WLAN_PUB_ACTION_QLOAD_REPORT = 21,
4102 WLAN_PUB_ACTION_HCCA_TXOP_ADVERT = 22,
4103 WLAN_PUB_ACTION_HCCA_TXOP_RESPONSE = 23,
4104 WLAN_PUB_ACTION_PUBLIC_KEY = 24,
4105 WLAN_PUB_ACTION_CHANNEL_AVAIL_QUERY = 25,
4106 WLAN_PUB_ACTION_CHANNEL_SCHEDULE_MGMT = 26,
4107 WLAN_PUB_ACTION_CONTACT_VERI_SIGNAL = 27,
4108 WLAN_PUB_ACTION_GDD_ENABLEMENT_REQ = 28,
4109 WLAN_PUB_ACTION_GDD_ENABLEMENT_RESP = 29,
4110 WLAN_PUB_ACTION_NETWORK_CHANNEL_CONTROL = 30,
4111 WLAN_PUB_ACTION_WHITE_SPACE_MAP_ANN = 31,
4112 WLAN_PUB_ACTION_FTM_REQUEST = 32,
4113 WLAN_PUB_ACTION_FTM_RESPONSE = 33,
4114 WLAN_PUB_ACTION_FILS_DISCOVERY = 34,
4115};
4116
4117/* TDLS action codes */
4118enum ieee80211_tdls_actioncode {
4119 WLAN_TDLS_SETUP_REQUEST = 0,
4120 WLAN_TDLS_SETUP_RESPONSE = 1,
4121 WLAN_TDLS_SETUP_CONFIRM = 2,
4122 WLAN_TDLS_TEARDOWN = 3,
4123 WLAN_TDLS_PEER_TRAFFIC_INDICATION = 4,
4124 WLAN_TDLS_CHANNEL_SWITCH_REQUEST = 5,
4125 WLAN_TDLS_CHANNEL_SWITCH_RESPONSE = 6,
4126 WLAN_TDLS_PEER_PSM_REQUEST = 7,
4127 WLAN_TDLS_PEER_PSM_RESPONSE = 8,
4128 WLAN_TDLS_PEER_TRAFFIC_RESPONSE = 9,
4129 WLAN_TDLS_DISCOVERY_REQUEST = 10,
4130};
4131
4132/* Extended Channel Switching capability to be set in the 1st byte of
4133 * the @WLAN_EID_EXT_CAPABILITY information element
4134 */
4135#define WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING BIT(2)
4136
4137/* Multiple BSSID capability is set in the 6th bit of 3rd byte of the
4138 * @WLAN_EID_EXT_CAPABILITY information element
4139 */
4140#define WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT BIT(6)
4141
4142/* Timing Measurement protocol for time sync is set in the 7th bit of 3rd byte
4143 * of the @WLAN_EID_EXT_CAPABILITY information element
4144 */
4145#define WLAN_EXT_CAPA3_TIMING_MEASUREMENT_SUPPORT BIT(7)
4146
4147/* TDLS capabilities in the 4th byte of @WLAN_EID_EXT_CAPABILITY */
4148#define WLAN_EXT_CAPA4_TDLS_BUFFER_STA BIT(4)
4149#define WLAN_EXT_CAPA4_TDLS_PEER_PSM BIT(5)
4150#define WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH BIT(6)
4151
4152/* Interworking capabilities are set in 7th bit of 4th byte of the
4153 * @WLAN_EID_EXT_CAPABILITY information element
4154 */
4155#define WLAN_EXT_CAPA4_INTERWORKING_ENABLED BIT(7)
4156
4157/*
4158 * TDLS capabililites to be enabled in the 5th byte of the
4159 * @WLAN_EID_EXT_CAPABILITY information element
4160 */
4161#define WLAN_EXT_CAPA5_TDLS_ENABLED BIT(5)
4162#define WLAN_EXT_CAPA5_TDLS_PROHIBITED BIT(6)
4163#define WLAN_EXT_CAPA5_TDLS_CH_SW_PROHIBITED BIT(7)
4164
4165#define WLAN_EXT_CAPA8_TDLS_WIDE_BW_ENABLED BIT(5)
4166#define WLAN_EXT_CAPA8_OPMODE_NOTIF BIT(6)
4167
4168/* Defines the maximal number of MSDUs in an A-MSDU. */
4169#define WLAN_EXT_CAPA8_MAX_MSDU_IN_AMSDU_LSB BIT(7)
4170#define WLAN_EXT_CAPA9_MAX_MSDU_IN_AMSDU_MSB BIT(0)
4171
4172/*
4173 * Fine Timing Measurement Initiator - bit 71 of @WLAN_EID_EXT_CAPABILITY
4174 * information element
4175 */
4176#define WLAN_EXT_CAPA9_FTM_INITIATOR BIT(7)
4177
4178/* Defines support for TWT Requester and TWT Responder */
4179#define WLAN_EXT_CAPA10_TWT_REQUESTER_SUPPORT BIT(5)
4180#define WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT BIT(6)
4181
4182/*
4183 * When set, indicates that the AP is able to tolerate 26-tone RU UL
4184 * OFDMA transmissions using HE TB PPDU from OBSS (not falsely classify the
4185 * 26-tone RU UL OFDMA transmissions as radar pulses).
4186 */
4187#define WLAN_EXT_CAPA10_OBSS_NARROW_BW_RU_TOLERANCE_SUPPORT BIT(7)
4188
4189/* Defines support for enhanced multi-bssid advertisement*/
4190#define WLAN_EXT_CAPA11_EMA_SUPPORT BIT(3)
4191
4192/* Enable Beacon Protection */
4193#define WLAN_EXT_CAPA11_BCN_PROTECT BIT(4)
4194
4195/* TDLS specific payload type in the LLC/SNAP header */
4196#define WLAN_TDLS_SNAP_RFTYPE 0x2
4197
4198/* BSS Coex IE information field bits */
4199#define WLAN_BSS_COEX_INFORMATION_REQUEST BIT(0)
4200
4201/**
4202 * enum ieee80211_mesh_sync_method - mesh synchronization method identifier
4203 *
4204 * @IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET: the default synchronization method
4205 * @IEEE80211_SYNC_METHOD_VENDOR: a vendor specific synchronization method
4206 * that will be specified in a vendor specific information element
4207 */
4208enum ieee80211_mesh_sync_method {
4209 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET = 1,
4210 IEEE80211_SYNC_METHOD_VENDOR = 255,
4211};
4212
4213/**
4214 * enum ieee80211_mesh_path_protocol - mesh path selection protocol identifier
4215 *
4216 * @IEEE80211_PATH_PROTOCOL_HWMP: the default path selection protocol
4217 * @IEEE80211_PATH_PROTOCOL_VENDOR: a vendor specific protocol that will
4218 * be specified in a vendor specific information element
4219 */
4220enum ieee80211_mesh_path_protocol {
4221 IEEE80211_PATH_PROTOCOL_HWMP = 1,
4222 IEEE80211_PATH_PROTOCOL_VENDOR = 255,
4223};
4224
4225/**
4226 * enum ieee80211_mesh_path_metric - mesh path selection metric identifier
4227 *
4228 * @IEEE80211_PATH_METRIC_AIRTIME: the default path selection metric
4229 * @IEEE80211_PATH_METRIC_VENDOR: a vendor specific metric that will be
4230 * specified in a vendor specific information element
4231 */
4232enum ieee80211_mesh_path_metric {
4233 IEEE80211_PATH_METRIC_AIRTIME = 1,
4234 IEEE80211_PATH_METRIC_VENDOR = 255,
4235};
4236
4237/**
4238 * enum ieee80211_root_mode_identifier - root mesh STA mode identifier
4239 *
4240 * These attribute are used by dot11MeshHWMPRootMode to set root mesh STA mode
4241 *
4242 * @IEEE80211_ROOTMODE_NO_ROOT: the mesh STA is not a root mesh STA (default)
4243 * @IEEE80211_ROOTMODE_ROOT: the mesh STA is a root mesh STA if greater than
4244 * this value
4245 * @IEEE80211_PROACTIVE_PREQ_NO_PREP: the mesh STA is a root mesh STA supports
4246 * the proactive PREQ with proactive PREP subfield set to 0
4247 * @IEEE80211_PROACTIVE_PREQ_WITH_PREP: the mesh STA is a root mesh STA
4248 * supports the proactive PREQ with proactive PREP subfield set to 1
4249 * @IEEE80211_PROACTIVE_RANN: the mesh STA is a root mesh STA supports
4250 * the proactive RANN
4251 */
4252enum ieee80211_root_mode_identifier {
4253 IEEE80211_ROOTMODE_NO_ROOT = 0,
4254 IEEE80211_ROOTMODE_ROOT = 1,
4255 IEEE80211_PROACTIVE_PREQ_NO_PREP = 2,
4256 IEEE80211_PROACTIVE_PREQ_WITH_PREP = 3,
4257 IEEE80211_PROACTIVE_RANN = 4,
4258};
4259
4260/*
4261 * IEEE 802.11-2007 7.3.2.9 Country information element
4262 *
4263 * Minimum length is 8 octets, ie len must be evenly
4264 * divisible by 2
4265 */
4266
4267/* Although the spec says 8 I'm seeing 6 in practice */
4268#define IEEE80211_COUNTRY_IE_MIN_LEN 6
4269
4270/* The Country String field of the element shall be 3 octets in length */
4271#define IEEE80211_COUNTRY_STRING_LEN 3
4272
4273/*
4274 * For regulatory extension stuff see IEEE 802.11-2007
4275 * Annex I (page 1141) and Annex J (page 1147). Also
4276 * review 7.3.2.9.
4277 *
4278 * When dot11RegulatoryClassesRequired is true and the
4279 * first_channel/reg_extension_id is >= 201 then the IE
4280 * compromises of the 'ext' struct represented below:
4281 *
4282 * - Regulatory extension ID - when generating IE this just needs
4283 * to be monotonically increasing for each triplet passed in
4284 * the IE
4285 * - Regulatory class - index into set of rules
4286 * - Coverage class - index into air propagation time (Table 7-27),
4287 * in microseconds, you can compute the air propagation time from
4288 * the index by multiplying by 3, so index 10 yields a propagation
4289 * of 10 us. Valid values are 0-31, values 32-255 are not defined
4290 * yet. A value of 0 inicates air propagation of <= 1 us.
4291 *
4292 * See also Table I.2 for Emission limit sets and table
4293 * I.3 for Behavior limit sets. Table J.1 indicates how to map
4294 * a reg_class to an emission limit set and behavior limit set.
4295 */
4296#define IEEE80211_COUNTRY_EXTENSION_ID 201
4297
4298/*
4299 * Channels numbers in the IE must be monotonically increasing
4300 * if dot11RegulatoryClassesRequired is not true.
4301 *
4302 * If dot11RegulatoryClassesRequired is true consecutive
4303 * subband triplets following a regulatory triplet shall
4304 * have monotonically increasing first_channel number fields.
4305 *
4306 * Channel numbers shall not overlap.
4307 *
4308 * Note that max_power is signed.
4309 */
4310struct ieee80211_country_ie_triplet {
4311 union {
4312 struct {
4313 u8 first_channel;
4314 u8 num_channels;
4315 s8 max_power;
4316 } __packed chans;
4317 struct {
4318 u8 reg_extension_id;
4319 u8 reg_class;
4320 u8 coverage_class;
4321 } __packed ext;
4322 };
4323} __packed;
4324
4325enum ieee80211_timeout_interval_type {
4326 WLAN_TIMEOUT_REASSOC_DEADLINE = 1 /* 802.11r */,
4327 WLAN_TIMEOUT_KEY_LIFETIME = 2 /* 802.11r */,
4328 WLAN_TIMEOUT_ASSOC_COMEBACK = 3 /* 802.11w */,
4329};
4330
4331/**
4332 * struct ieee80211_timeout_interval_ie - Timeout Interval element
4333 * @type: type, see &enum ieee80211_timeout_interval_type
4334 * @value: timeout interval value
4335 */
4336struct ieee80211_timeout_interval_ie {
4337 u8 type;
4338 __le32 value;
4339} __packed;
4340
4341/**
4342 * enum ieee80211_idle_options - BSS idle options
4343 * @WLAN_IDLE_OPTIONS_PROTECTED_KEEP_ALIVE: the station should send an RSN
4344 * protected frame to the AP to reset the idle timer at the AP for
4345 * the station.
4346 */
4347enum ieee80211_idle_options {
4348 WLAN_IDLE_OPTIONS_PROTECTED_KEEP_ALIVE = BIT(0),
4349};
4350
4351/**
4352 * struct ieee80211_bss_max_idle_period_ie - BSS max idle period element struct
4353 *
4354 * This structure refers to "BSS Max idle period element"
4355 *
4356 * @max_idle_period: indicates the time period during which a station can
4357 * refrain from transmitting frames to its associated AP without being
4358 * disassociated. In units of 1000 TUs.
4359 * @idle_options: indicates the options associated with the BSS idle capability
4360 * as specified in &enum ieee80211_idle_options.
4361 */
4362struct ieee80211_bss_max_idle_period_ie {
4363 __le16 max_idle_period;
4364 u8 idle_options;
4365} __packed;
4366
4367/* BACK action code */
4368enum ieee80211_back_actioncode {
4369 WLAN_ACTION_ADDBA_REQ = 0,
4370 WLAN_ACTION_ADDBA_RESP = 1,
4371 WLAN_ACTION_DELBA = 2,
4372};
4373
4374/* BACK (block-ack) parties */
4375enum ieee80211_back_parties {
4376 WLAN_BACK_RECIPIENT = 0,
4377 WLAN_BACK_INITIATOR = 1,
4378};
4379
4380/* SA Query action */
4381enum ieee80211_sa_query_action {
4382 WLAN_ACTION_SA_QUERY_REQUEST = 0,
4383 WLAN_ACTION_SA_QUERY_RESPONSE = 1,
4384};
4385
4386/**
4387 * struct ieee80211_bssid_index - multiple BSSID index element structure
4388 *
4389 * This structure refers to "Multiple BSSID-index element"
4390 *
4391 * @bssid_index: BSSID index
4392 * @dtim_period: optional, overrides transmitted BSS dtim period
4393 * @dtim_count: optional, overrides transmitted BSS dtim count
4394 */
4395struct ieee80211_bssid_index {
4396 u8 bssid_index;
4397 u8 dtim_period;
4398 u8 dtim_count;
4399};
4400
4401/**
4402 * struct ieee80211_multiple_bssid_configuration - multiple BSSID configuration
4403 * element structure
4404 *
4405 * This structure refers to "Multiple BSSID Configuration element"
4406 *
4407 * @bssid_count: total number of active BSSIDs in the set
4408 * @profile_periodicity: the least number of beacon frames need to be received
4409 * in order to discover all the nontransmitted BSSIDs in the set.
4410 */
4411struct ieee80211_multiple_bssid_configuration {
4412 u8 bssid_count;
4413 u8 profile_periodicity;
4414};
4415
4416#define SUITE(oui, id) (((oui) << 8) | (id))
4417
4418/* cipher suite selectors */
4419#define WLAN_CIPHER_SUITE_USE_GROUP SUITE(0x000FAC, 0)
4420#define WLAN_CIPHER_SUITE_WEP40 SUITE(0x000FAC, 1)
4421#define WLAN_CIPHER_SUITE_TKIP SUITE(0x000FAC, 2)
4422/* reserved: SUITE(0x000FAC, 3) */
4423#define WLAN_CIPHER_SUITE_CCMP SUITE(0x000FAC, 4)
4424#define WLAN_CIPHER_SUITE_WEP104 SUITE(0x000FAC, 5)
4425#define WLAN_CIPHER_SUITE_AES_CMAC SUITE(0x000FAC, 6)
4426#define WLAN_CIPHER_SUITE_GCMP SUITE(0x000FAC, 8)
4427#define WLAN_CIPHER_SUITE_GCMP_256 SUITE(0x000FAC, 9)
4428#define WLAN_CIPHER_SUITE_CCMP_256 SUITE(0x000FAC, 10)
4429#define WLAN_CIPHER_SUITE_BIP_GMAC_128 SUITE(0x000FAC, 11)
4430#define WLAN_CIPHER_SUITE_BIP_GMAC_256 SUITE(0x000FAC, 12)
4431#define WLAN_CIPHER_SUITE_BIP_CMAC_256 SUITE(0x000FAC, 13)
4432
4433#define WLAN_CIPHER_SUITE_SMS4 SUITE(0x001472, 1)
4434
4435/* AKM suite selectors */
4436#define WLAN_AKM_SUITE_8021X SUITE(0x000FAC, 1)
4437#define WLAN_AKM_SUITE_PSK SUITE(0x000FAC, 2)
4438#define WLAN_AKM_SUITE_FT_8021X SUITE(0x000FAC, 3)
4439#define WLAN_AKM_SUITE_FT_PSK SUITE(0x000FAC, 4)
4440#define WLAN_AKM_SUITE_8021X_SHA256 SUITE(0x000FAC, 5)
4441#define WLAN_AKM_SUITE_PSK_SHA256 SUITE(0x000FAC, 6)
4442#define WLAN_AKM_SUITE_TDLS SUITE(0x000FAC, 7)
4443#define WLAN_AKM_SUITE_SAE SUITE(0x000FAC, 8)
4444#define WLAN_AKM_SUITE_FT_OVER_SAE SUITE(0x000FAC, 9)
4445#define WLAN_AKM_SUITE_AP_PEER_KEY SUITE(0x000FAC, 10)
4446#define WLAN_AKM_SUITE_8021X_SUITE_B SUITE(0x000FAC, 11)
4447#define WLAN_AKM_SUITE_8021X_SUITE_B_192 SUITE(0x000FAC, 12)
4448#define WLAN_AKM_SUITE_FT_8021X_SHA384 SUITE(0x000FAC, 13)
4449#define WLAN_AKM_SUITE_FILS_SHA256 SUITE(0x000FAC, 14)
4450#define WLAN_AKM_SUITE_FILS_SHA384 SUITE(0x000FAC, 15)
4451#define WLAN_AKM_SUITE_FT_FILS_SHA256 SUITE(0x000FAC, 16)
4452#define WLAN_AKM_SUITE_FT_FILS_SHA384 SUITE(0x000FAC, 17)
4453#define WLAN_AKM_SUITE_OWE SUITE(0x000FAC, 18)
4454#define WLAN_AKM_SUITE_FT_PSK_SHA384 SUITE(0x000FAC, 19)
4455#define WLAN_AKM_SUITE_PSK_SHA384 SUITE(0x000FAC, 20)
4456
4457#define WLAN_AKM_SUITE_WFA_DPP SUITE(WLAN_OUI_WFA, 2)
4458
4459#define WLAN_MAX_KEY_LEN 32
4460
4461#define WLAN_PMK_NAME_LEN 16
4462#define WLAN_PMKID_LEN 16
4463#define WLAN_PMK_LEN_EAP_LEAP 16
4464#define WLAN_PMK_LEN 32
4465#define WLAN_PMK_LEN_SUITE_B_192 48
4466
4467#define WLAN_OUI_WFA 0x506f9a
4468#define WLAN_OUI_TYPE_WFA_P2P 9
4469#define WLAN_OUI_TYPE_WFA_DPP 0x1A
4470#define WLAN_OUI_MICROSOFT 0x0050f2
4471#define WLAN_OUI_TYPE_MICROSOFT_WPA 1
4472#define WLAN_OUI_TYPE_MICROSOFT_WMM 2
4473#define WLAN_OUI_TYPE_MICROSOFT_WPS 4
4474#define WLAN_OUI_TYPE_MICROSOFT_TPC 8
4475
4476/*
4477 * WMM/802.11e Tspec Element
4478 */
4479#define IEEE80211_WMM_IE_TSPEC_TID_MASK 0x0F
4480#define IEEE80211_WMM_IE_TSPEC_TID_SHIFT 1
4481
4482enum ieee80211_tspec_status_code {
4483 IEEE80211_TSPEC_STATUS_ADMISS_ACCEPTED = 0,
4484 IEEE80211_TSPEC_STATUS_ADDTS_INVAL_PARAMS = 0x1,
4485};
4486
4487struct ieee80211_tspec_ie {
4488 u8 element_id;
4489 u8 len;
4490 u8 oui[3];
4491 u8 oui_type;
4492 u8 oui_subtype;
4493 u8 version;
4494 __le16 tsinfo;
4495 u8 tsinfo_resvd;
4496 __le16 nominal_msdu;
4497 __le16 max_msdu;
4498 __le32 min_service_int;
4499 __le32 max_service_int;
4500 __le32 inactivity_int;
4501 __le32 suspension_int;
4502 __le32 service_start_time;
4503 __le32 min_data_rate;
4504 __le32 mean_data_rate;
4505 __le32 peak_data_rate;
4506 __le32 max_burst_size;
4507 __le32 delay_bound;
4508 __le32 min_phy_rate;
4509 __le16 sba;
4510 __le16 medium_time;
4511} __packed;
4512
4513struct ieee80211_he_6ghz_capa {
4514 /* uses IEEE80211_HE_6GHZ_CAP_* below */
4515 __le16 capa;
4516} __packed;
4517
4518/* HE 6 GHz band capabilities */
4519/* uses enum ieee80211_min_mpdu_spacing values */
4520#define IEEE80211_HE_6GHZ_CAP_MIN_MPDU_START 0x0007
4521/* uses enum ieee80211_vht_max_ampdu_length_exp values */
4522#define IEEE80211_HE_6GHZ_CAP_MAX_AMPDU_LEN_EXP 0x0038
4523/* uses IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_* values */
4524#define IEEE80211_HE_6GHZ_CAP_MAX_MPDU_LEN 0x00c0
4525/* WLAN_HT_CAP_SM_PS_* values */
4526#define IEEE80211_HE_6GHZ_CAP_SM_PS 0x0600
4527#define IEEE80211_HE_6GHZ_CAP_RD_RESPONDER 0x0800
4528#define IEEE80211_HE_6GHZ_CAP_RX_ANTPAT_CONS 0x1000
4529#define IEEE80211_HE_6GHZ_CAP_TX_ANTPAT_CONS 0x2000
4530
4531/**
4532 * ieee80211_get_qos_ctl - get pointer to qos control bytes
4533 * @hdr: the frame
4534 * Return: a pointer to the QoS control field in the frame header
4535 *
4536 * The qos ctrl bytes come after the frame_control, duration, seq_num
4537 * and 3 or 4 addresses of length ETH_ALEN. Checks frame_control to choose
4538 * between struct ieee80211_qos_hdr_4addr and struct ieee80211_qos_hdr.
4539 */
4540static inline u8 *ieee80211_get_qos_ctl(struct ieee80211_hdr *hdr)
4541{
4542 union {
4543 struct ieee80211_qos_hdr addr3;
4544 struct ieee80211_qos_hdr_4addr addr4;
4545 } *qos;
4546
4547 qos = (void *)hdr;
4548 if (ieee80211_has_a4(fc: qos->addr3.frame_control))
4549 return (u8 *)&qos->addr4.qos_ctrl;
4550 else
4551 return (u8 *)&qos->addr3.qos_ctrl;
4552}
4553
4554/**
4555 * ieee80211_get_tid - get qos TID
4556 * @hdr: the frame
4557 * Return: the TID from the QoS control field
4558 */
4559static inline u8 ieee80211_get_tid(struct ieee80211_hdr *hdr)
4560{
4561 u8 *qc = ieee80211_get_qos_ctl(hdr);
4562
4563 return qc[0] & IEEE80211_QOS_CTL_TID_MASK;
4564}
4565
4566/**
4567 * ieee80211_get_SA - get pointer to SA
4568 * @hdr: the frame
4569 * Return: a pointer to the source address (SA)
4570 *
4571 * Given an 802.11 frame, this function returns the offset
4572 * to the source address (SA). It does not verify that the
4573 * header is long enough to contain the address, and the
4574 * header must be long enough to contain the frame control
4575 * field.
4576 */
4577static inline u8 *ieee80211_get_SA(struct ieee80211_hdr *hdr)
4578{
4579 if (ieee80211_has_a4(fc: hdr->frame_control))
4580 return hdr->addr4;
4581 if (ieee80211_has_fromds(fc: hdr->frame_control))
4582 return hdr->addr3;
4583 return hdr->addr2;
4584}
4585
4586/**
4587 * ieee80211_get_DA - get pointer to DA
4588 * @hdr: the frame
4589 * Return: a pointer to the destination address (DA)
4590 *
4591 * Given an 802.11 frame, this function returns the offset
4592 * to the destination address (DA). It does not verify that
4593 * the header is long enough to contain the address, and the
4594 * header must be long enough to contain the frame control
4595 * field.
4596 */
4597static inline u8 *ieee80211_get_DA(struct ieee80211_hdr *hdr)
4598{
4599 if (ieee80211_has_tods(fc: hdr->frame_control))
4600 return hdr->addr3;
4601 else
4602 return hdr->addr1;
4603}
4604
4605/**
4606 * ieee80211_is_bufferable_mmpdu - check if frame is bufferable MMPDU
4607 * @skb: the skb to check, starting with the 802.11 header
4608 * Return: whether or not the MMPDU is bufferable
4609 */
4610static inline bool ieee80211_is_bufferable_mmpdu(struct sk_buff *skb)
4611{
4612 struct ieee80211_mgmt *mgmt = (void *)skb->data;
4613 __le16 fc = mgmt->frame_control;
4614
4615 /*
4616 * IEEE 802.11 REVme D2.0 definition of bufferable MMPDU;
4617 * note that this ignores the IBSS special case.
4618 */
4619 if (!ieee80211_is_mgmt(fc))
4620 return false;
4621
4622 if (ieee80211_is_disassoc(fc) || ieee80211_is_deauth(fc))
4623 return true;
4624
4625 if (!ieee80211_is_action(fc))
4626 return false;
4627
4628 if (skb->len < offsetofend(typeof(*mgmt), u.action.u.ftm.action_code))
4629 return true;
4630
4631 /* action frame - additionally check for non-bufferable FTM */
4632
4633 if (mgmt->u.action.category != WLAN_CATEGORY_PUBLIC &&
4634 mgmt->u.action.category != WLAN_CATEGORY_PROTECTED_DUAL_OF_ACTION)
4635 return true;
4636
4637 if (mgmt->u.action.u.ftm.action_code == WLAN_PUB_ACTION_FTM_REQUEST ||
4638 mgmt->u.action.u.ftm.action_code == WLAN_PUB_ACTION_FTM_RESPONSE)
4639 return false;
4640
4641 return true;
4642}
4643
4644/**
4645 * _ieee80211_is_robust_mgmt_frame - check if frame is a robust management frame
4646 * @hdr: the frame (buffer must include at least the first octet of payload)
4647 * Return: whether or not the frame is a robust management frame
4648 */
4649static inline bool _ieee80211_is_robust_mgmt_frame(struct ieee80211_hdr *hdr)
4650{
4651 if (ieee80211_is_disassoc(fc: hdr->frame_control) ||
4652 ieee80211_is_deauth(fc: hdr->frame_control))
4653 return true;
4654
4655 if (ieee80211_is_action(fc: hdr->frame_control)) {
4656 u8 *category;
4657
4658 /*
4659 * Action frames, excluding Public Action frames, are Robust
4660 * Management Frames. However, if we are looking at a Protected
4661 * frame, skip the check since the data may be encrypted and
4662 * the frame has already been found to be a Robust Management
4663 * Frame (by the other end).
4664 */
4665 if (ieee80211_has_protected(fc: hdr->frame_control))
4666 return true;
4667 category = ((u8 *) hdr) + 24;
4668 return *category != WLAN_CATEGORY_PUBLIC &&
4669 *category != WLAN_CATEGORY_HT &&
4670 *category != WLAN_CATEGORY_WNM_UNPROTECTED &&
4671 *category != WLAN_CATEGORY_SELF_PROTECTED &&
4672 *category != WLAN_CATEGORY_UNPROT_DMG &&
4673 *category != WLAN_CATEGORY_VHT &&
4674 *category != WLAN_CATEGORY_S1G &&
4675 *category != WLAN_CATEGORY_VENDOR_SPECIFIC;
4676 }
4677
4678 return false;
4679}
4680
4681/**
4682 * ieee80211_is_robust_mgmt_frame - check if skb contains a robust mgmt frame
4683 * @skb: the skb containing the frame, length will be checked
4684 * Return: whether or not the frame is a robust management frame
4685 */
4686static inline bool ieee80211_is_robust_mgmt_frame(struct sk_buff *skb)
4687{
4688 if (skb->len < IEEE80211_MIN_ACTION_SIZE)
4689 return false;
4690 return _ieee80211_is_robust_mgmt_frame(hdr: (void *)skb->data);
4691}
4692
4693/**
4694 * ieee80211_is_public_action - check if frame is a public action frame
4695 * @hdr: the frame
4696 * @len: length of the frame
4697 * Return: whether or not the frame is a public action frame
4698 */
4699static inline bool ieee80211_is_public_action(struct ieee80211_hdr *hdr,
4700 size_t len)
4701{
4702 struct ieee80211_mgmt *mgmt = (void *)hdr;
4703
4704 if (len < IEEE80211_MIN_ACTION_SIZE)
4705 return false;
4706 if (!ieee80211_is_action(fc: hdr->frame_control))
4707 return false;
4708 return mgmt->u.action.category == WLAN_CATEGORY_PUBLIC;
4709}
4710
4711/**
4712 * ieee80211_is_protected_dual_of_public_action - check if skb contains a
4713 * protected dual of public action management frame
4714 * @skb: the skb containing the frame, length will be checked
4715 *
4716 * Return: true if the skb contains a protected dual of public action
4717 * management frame, false otherwise.
4718 */
4719static inline bool
4720ieee80211_is_protected_dual_of_public_action(struct sk_buff *skb)
4721{
4722 u8 action;
4723
4724 if (!ieee80211_is_public_action(hdr: (void *)skb->data, len: skb->len) ||
4725 skb->len < IEEE80211_MIN_ACTION_SIZE + 1)
4726 return false;
4727
4728 action = *(u8 *)(skb->data + IEEE80211_MIN_ACTION_SIZE);
4729
4730 return action != WLAN_PUB_ACTION_20_40_BSS_COEX &&
4731 action != WLAN_PUB_ACTION_DSE_REG_LOC_ANN &&
4732 action != WLAN_PUB_ACTION_MSMT_PILOT &&
4733 action != WLAN_PUB_ACTION_TDLS_DISCOVER_RES &&
4734 action != WLAN_PUB_ACTION_LOC_TRACK_NOTI &&
4735 action != WLAN_PUB_ACTION_FTM_REQUEST &&
4736 action != WLAN_PUB_ACTION_FTM_RESPONSE &&
4737 action != WLAN_PUB_ACTION_FILS_DISCOVERY &&
4738 action != WLAN_PUB_ACTION_VENDOR_SPECIFIC;
4739}
4740
4741/**
4742 * _ieee80211_is_group_privacy_action - check if frame is a group addressed
4743 * privacy action frame
4744 * @hdr: the frame
4745 * Return: whether or not the frame is a group addressed privacy action frame
4746 */
4747static inline bool _ieee80211_is_group_privacy_action(struct ieee80211_hdr *hdr)
4748{
4749 struct ieee80211_mgmt *mgmt = (void *)hdr;
4750
4751 if (!ieee80211_is_action(fc: hdr->frame_control) ||
4752 !is_multicast_ether_addr(addr: hdr->addr1))
4753 return false;
4754
4755 return mgmt->u.action.category == WLAN_CATEGORY_MESH_ACTION ||
4756 mgmt->u.action.category == WLAN_CATEGORY_MULTIHOP_ACTION;
4757}
4758
4759/**
4760 * ieee80211_is_group_privacy_action - check if frame is a group addressed
4761 * privacy action frame
4762 * @skb: the skb containing the frame, length will be checked
4763 * Return: whether or not the frame is a group addressed privacy action frame
4764 */
4765static inline bool ieee80211_is_group_privacy_action(struct sk_buff *skb)
4766{
4767 if (skb->len < IEEE80211_MIN_ACTION_SIZE)
4768 return false;
4769 return _ieee80211_is_group_privacy_action(hdr: (void *)skb->data);
4770}
4771
4772/**
4773 * ieee80211_tu_to_usec - convert time units (TU) to microseconds
4774 * @tu: the TUs
4775 * Return: the time value converted to microseconds
4776 */
4777static inline unsigned long ieee80211_tu_to_usec(unsigned long tu)
4778{
4779 return 1024 * tu;
4780}
4781
4782static inline bool __ieee80211_check_tim(const struct ieee80211_tim_ie *tim,
4783 u8 tim_len, u16 aid)
4784{
4785 u8 mask;
4786 u8 index, indexn1, indexn2;
4787
4788 if (unlikely(!tim || tim_len < sizeof(*tim)))
4789 return false;
4790
4791 aid &= 0x3fff;
4792 index = aid / 8;
4793 mask = 1 << (aid & 7);
4794
4795 indexn1 = tim->bitmap_ctrl & 0xfe;
4796 indexn2 = tim_len + indexn1 - 4;
4797
4798 if (index < indexn1 || index > indexn2)
4799 return false;
4800
4801 index -= indexn1;
4802
4803 return !!(tim->virtual_map[index] & mask);
4804}
4805
4806struct s1g_tim_aid {
4807 u16 aid;
4808 u8 target_blk; /* Target block index */
4809 u8 target_subblk; /* Target subblock index */
4810 u8 target_subblk_bit; /* Target subblock bit */
4811};
4812
4813struct s1g_tim_enc_block {
4814 u8 enc_mode;
4815 bool inverse;
4816 const u8 *ptr;
4817 u8 len;
4818
4819 /*
4820 * For an OLB encoded block that spans multiple blocks, this
4821 * is the offset into the span described by that encoded block.
4822 */
4823 u8 olb_blk_offset;
4824};
4825
4826/*
4827 * Helper routines to quickly extract the length of an encoded block. Validation
4828 * is also performed to ensure the length extracted lies within the TIM.
4829 */
4830
4831static inline int ieee80211_s1g_len_bitmap(const u8 *ptr, const u8 *end)
4832{
4833 u8 blkmap;
4834 u8 n_subblks;
4835
4836 if (ptr >= end)
4837 return -EINVAL;
4838
4839 blkmap = *ptr;
4840 n_subblks = hweight8(blkmap);
4841
4842 if (ptr + 1 + n_subblks > end)
4843 return -EINVAL;
4844
4845 return 1 + n_subblks;
4846}
4847
4848static inline int ieee80211_s1g_len_single(const u8 *ptr, const u8 *end)
4849{
4850 return (ptr + 1 > end) ? -EINVAL : 1;
4851}
4852
4853static inline int ieee80211_s1g_len_olb(const u8 *ptr, const u8 *end)
4854{
4855 if (ptr >= end)
4856 return -EINVAL;
4857
4858 return (ptr + 1 + *ptr > end) ? -EINVAL : 1 + *ptr;
4859}
4860
4861/*
4862 * Enumerate all encoded blocks until we find the encoded block that describes
4863 * our target AID. OLB is a special case as a single encoded block can describe
4864 * multiple blocks as a single encoded block.
4865 */
4866static inline int ieee80211_s1g_find_target_block(struct s1g_tim_enc_block *enc,
4867 const struct s1g_tim_aid *aid,
4868 const u8 *ptr, const u8 *end)
4869{
4870 /* need at least block-control octet */
4871 while (ptr + 1 <= end) {
4872 u8 ctrl = *ptr++;
4873 u8 mode = ctrl & 0x03;
4874 bool contains, inverse = ctrl & BIT(2);
4875 u8 span, blk_off = ctrl >> 3;
4876 int len;
4877
4878 switch (mode) {
4879 case IEEE80211_S1G_TIM_ENC_MODE_BLOCK:
4880 len = ieee80211_s1g_len_bitmap(ptr, end);
4881 contains = blk_off == aid->target_blk;
4882 break;
4883 case IEEE80211_S1G_TIM_ENC_MODE_SINGLE:
4884 len = ieee80211_s1g_len_single(ptr, end);
4885 contains = blk_off == aid->target_blk;
4886 break;
4887 case IEEE80211_S1G_TIM_ENC_MODE_OLB:
4888 len = ieee80211_s1g_len_olb(ptr, end);
4889 /*
4890 * An OLB encoded block can describe more then one
4891 * block, meaning an encoded OLB block can span more
4892 * then a single block.
4893 */
4894 if (len > 0) {
4895 /* Minus one for the length octet */
4896 span = DIV_ROUND_UP(len - 1, 8);
4897 /*
4898 * Check if our target block lies within the
4899 * block span described by this encoded block.
4900 */
4901 contains = (aid->target_blk >= blk_off) &&
4902 (aid->target_blk < blk_off + span);
4903 }
4904 break;
4905 default:
4906 return -EOPNOTSUPP;
4907 }
4908
4909 if (len < 0)
4910 return len;
4911
4912 if (contains) {
4913 enc->enc_mode = mode;
4914 enc->inverse = inverse;
4915 enc->ptr = ptr;
4916 enc->len = (u8)len;
4917 enc->olb_blk_offset = blk_off;
4918 return 0;
4919 }
4920
4921 ptr += len;
4922 }
4923
4924 return -ENOENT;
4925}
4926
4927static inline bool ieee80211_s1g_parse_bitmap(struct s1g_tim_enc_block *enc,
4928 struct s1g_tim_aid *aid)
4929{
4930 const u8 *ptr = enc->ptr;
4931 u8 blkmap = *ptr++;
4932
4933 /*
4934 * If our block bitmap does not contain a set bit that corresponds
4935 * to our AID, it could mean a variety of things depending on if
4936 * the encoding mode is inverted or not.
4937 *
4938 * 1. If inverted, it means the entire subblock is present and hence
4939 * our AID has been set.
4940 * 2. If not inverted, it means our subblock is not present and hence
4941 * it is all zero meaning our AID is not set.
4942 */
4943 if (!(blkmap & BIT(aid->target_subblk)))
4944 return enc->inverse;
4945
4946 /*
4947 * Increment ptr by the number of set subblocks that appear before our
4948 * target subblock. If our target subblock is 0, do nothing as ptr
4949 * already points to our target subblock.
4950 */
4951 if (aid->target_subblk)
4952 ptr += hweight8(blkmap & GENMASK(aid->target_subblk - 1, 0));
4953
4954 return !!(*ptr & BIT(aid->target_subblk_bit)) ^ enc->inverse;
4955}
4956
4957static inline bool ieee80211_s1g_parse_single(struct s1g_tim_enc_block *enc,
4958 struct s1g_tim_aid *aid)
4959{
4960 /*
4961 * Single AID mode describes, as the name suggests, a single AID
4962 * within the block described by the encoded block. The octet
4963 * contains the 6 LSBs of the AID described in the block. The other
4964 * 2 bits are reserved. When inversed, every single AID described
4965 * by the current block have buffered traffic except for the AID
4966 * described in the single AID octet.
4967 */
4968 return ((*enc->ptr & 0x3f) == (aid->aid & 0x3f)) ^ enc->inverse;
4969}
4970
4971static inline bool ieee80211_s1g_parse_olb(struct s1g_tim_enc_block *enc,
4972 struct s1g_tim_aid *aid)
4973{
4974 const u8 *ptr = enc->ptr;
4975 u8 blk_len = *ptr++;
4976 /*
4977 * Given an OLB encoded block that describes multiple blocks,
4978 * calculate the offset into the span. Then calculate the
4979 * subblock location normally.
4980 */
4981 u16 span_offset = aid->target_blk - enc->olb_blk_offset;
4982 u16 subblk_idx = span_offset * 8 + aid->target_subblk;
4983
4984 if (subblk_idx >= blk_len)
4985 return enc->inverse;
4986
4987 return !!(ptr[subblk_idx] & BIT(aid->target_subblk_bit)) ^ enc->inverse;
4988}
4989
4990/*
4991 * An S1G PVB has 3 non optional encoding types, each that can be inverted.
4992 * An S1G PVB is constructed with zero or more encoded block subfields. Each
4993 * encoded block represents a single "block" of AIDs (64), and each encoded
4994 * block can contain one of the 3 encoding types alongside a single bit for
4995 * whether the bits should be inverted.
4996 *
4997 * As the standard makes no guarantee about the ordering of encoded blocks,
4998 * we must parse every encoded block in the worst case scenario given an
4999 * AID that lies within the last block.
5000 */
5001static inline bool ieee80211_s1g_check_tim(const struct ieee80211_tim_ie *tim,
5002 u8 tim_len, u16 aid)
5003{
5004 int err;
5005 struct s1g_tim_aid target_aid;
5006 struct s1g_tim_enc_block enc_blk;
5007
5008 if (tim_len < 3)
5009 return false;
5010
5011 target_aid.aid = aid;
5012 target_aid.target_blk = (aid >> 6) & 0x1f;
5013 target_aid.target_subblk = (aid >> 3) & 0x7;
5014 target_aid.target_subblk_bit = aid & 0x7;
5015
5016 /*
5017 * Find our AIDs target encoded block and fill &enc_blk with the
5018 * encoded blocks information. If no entry is found or an error
5019 * occurs return false.
5020 */
5021 err = ieee80211_s1g_find_target_block(enc: &enc_blk, aid: &target_aid,
5022 ptr: tim->virtual_map,
5023 end: (const u8 *)tim + tim_len + 2);
5024 if (err)
5025 return false;
5026
5027 switch (enc_blk.enc_mode) {
5028 case IEEE80211_S1G_TIM_ENC_MODE_BLOCK:
5029 return ieee80211_s1g_parse_bitmap(enc: &enc_blk, aid: &target_aid);
5030 case IEEE80211_S1G_TIM_ENC_MODE_SINGLE:
5031 return ieee80211_s1g_parse_single(enc: &enc_blk, aid: &target_aid);
5032 case IEEE80211_S1G_TIM_ENC_MODE_OLB:
5033 return ieee80211_s1g_parse_olb(enc: &enc_blk, aid: &target_aid);
5034 default:
5035 return false;
5036 }
5037}
5038
5039/**
5040 * ieee80211_check_tim - check if AID bit is set in TIM
5041 * @tim: the TIM IE
5042 * @tim_len: length of the TIM IE
5043 * @aid: the AID to look for
5044 * @s1g: whether the TIM is from an S1G PPDU
5045 * Return: whether or not traffic is indicated in the TIM for the given AID
5046 */
5047static inline bool ieee80211_check_tim(const struct ieee80211_tim_ie *tim,
5048 u8 tim_len, u16 aid, bool s1g)
5049{
5050 return s1g ? ieee80211_s1g_check_tim(tim, tim_len, aid) :
5051 __ieee80211_check_tim(tim, tim_len, aid);
5052}
5053
5054/**
5055 * ieee80211_get_tdls_action - get TDLS action code
5056 * @skb: the skb containing the frame, length will not be checked
5057 * Return: the TDLS action code, or -1 if it's not an encapsulated TDLS action
5058 * frame
5059 *
5060 * This function assumes the frame is a data frame, and that the network header
5061 * is in the correct place.
5062 */
5063static inline int ieee80211_get_tdls_action(struct sk_buff *skb)
5064{
5065 if (!skb_is_nonlinear(skb) &&
5066 skb->len > (skb_network_offset(skb) + 2)) {
5067 /* Point to where the indication of TDLS should start */
5068 const u8 *tdls_data = skb_network_header(skb) - 2;
5069
5070 if (get_unaligned_be16(p: tdls_data) == ETH_P_TDLS &&
5071 tdls_data[2] == WLAN_TDLS_SNAP_RFTYPE &&
5072 tdls_data[3] == WLAN_CATEGORY_TDLS)
5073 return tdls_data[4];
5074 }
5075
5076 return -1;
5077}
5078
5079/* convert time units */
5080#define TU_TO_JIFFIES(x) (usecs_to_jiffies((x) * 1024))
5081#define TU_TO_EXP_TIME(x) (jiffies + TU_TO_JIFFIES(x))
5082
5083/* convert frequencies */
5084#define MHZ_TO_KHZ(freq) ((freq) * 1000)
5085#define KHZ_TO_MHZ(freq) ((freq) / 1000)
5086#define PR_KHZ(f) KHZ_TO_MHZ(f), f % 1000
5087#define KHZ_F "%d.%03d"
5088
5089/* convert powers */
5090#define DBI_TO_MBI(gain) ((gain) * 100)
5091#define MBI_TO_DBI(gain) ((gain) / 100)
5092#define DBM_TO_MBM(gain) ((gain) * 100)
5093#define MBM_TO_DBM(gain) ((gain) / 100)
5094
5095/**
5096 * ieee80211_action_contains_tpc - checks if the frame contains TPC element
5097 * @skb: the skb containing the frame, length will be checked
5098 * Return: %true if the frame contains a TPC element, %false otherwise
5099 *
5100 * This function checks if it's either TPC report action frame or Link
5101 * Measurement report action frame as defined in IEEE Std. 802.11-2012 8.5.2.5
5102 * and 8.5.7.5 accordingly.
5103 */
5104static inline bool ieee80211_action_contains_tpc(struct sk_buff *skb)
5105{
5106 struct ieee80211_mgmt *mgmt = (void *)skb->data;
5107
5108 if (!ieee80211_is_action(fc: mgmt->frame_control))
5109 return false;
5110
5111 if (skb->len < IEEE80211_MIN_ACTION_SIZE +
5112 sizeof(mgmt->u.action.u.tpc_report))
5113 return false;
5114
5115 /*
5116 * TPC report - check that:
5117 * category = 0 (Spectrum Management) or 5 (Radio Measurement)
5118 * spectrum management action = 3 (TPC/Link Measurement report)
5119 * TPC report EID = 35
5120 * TPC report element length = 2
5121 *
5122 * The spectrum management's tpc_report struct is used here both for
5123 * parsing tpc_report and radio measurement's link measurement report
5124 * frame, since the relevant part is identical in both frames.
5125 */
5126 if (mgmt->u.action.category != WLAN_CATEGORY_SPECTRUM_MGMT &&
5127 mgmt->u.action.category != WLAN_CATEGORY_RADIO_MEASUREMENT)
5128 return false;
5129
5130 /* both spectrum mgmt and link measurement have same action code */
5131 if (mgmt->u.action.u.tpc_report.action_code !=
5132 WLAN_ACTION_SPCT_TPC_RPRT)
5133 return false;
5134
5135 if (mgmt->u.action.u.tpc_report.tpc_elem_id != WLAN_EID_TPC_REPORT ||
5136 mgmt->u.action.u.tpc_report.tpc_elem_length !=
5137 sizeof(struct ieee80211_tpc_report_ie))
5138 return false;
5139
5140 return true;
5141}
5142
5143/**
5144 * ieee80211_is_timing_measurement - check if frame is timing measurement response
5145 * @skb: the SKB to check
5146 * Return: whether or not the frame is a valid timing measurement response
5147 */
5148static inline bool ieee80211_is_timing_measurement(struct sk_buff *skb)
5149{
5150 struct ieee80211_mgmt *mgmt = (void *)skb->data;
5151
5152 if (skb->len < IEEE80211_MIN_ACTION_SIZE)
5153 return false;
5154
5155 if (!ieee80211_is_action(fc: mgmt->frame_control))
5156 return false;
5157
5158 if (mgmt->u.action.category == WLAN_CATEGORY_WNM_UNPROTECTED &&
5159 mgmt->u.action.u.wnm_timing_msr.action_code ==
5160 WLAN_UNPROTECTED_WNM_ACTION_TIMING_MEASUREMENT_RESPONSE &&
5161 skb->len >= offsetofend(typeof(*mgmt), u.action.u.wnm_timing_msr))
5162 return true;
5163
5164 return false;
5165}
5166
5167/**
5168 * ieee80211_is_ftm - check if frame is FTM response
5169 * @skb: the SKB to check
5170 * Return: whether or not the frame is a valid FTM response action frame
5171 */
5172static inline bool ieee80211_is_ftm(struct sk_buff *skb)
5173{
5174 struct ieee80211_mgmt *mgmt = (void *)skb->data;
5175
5176 if (!ieee80211_is_public_action(hdr: (void *)mgmt, len: skb->len))
5177 return false;
5178
5179 if (mgmt->u.action.u.ftm.action_code ==
5180 WLAN_PUB_ACTION_FTM_RESPONSE &&
5181 skb->len >= offsetofend(typeof(*mgmt), u.action.u.ftm))
5182 return true;
5183
5184 return false;
5185}
5186
5187/**
5188 * ieee80211_is_s1g_short_beacon - check if frame is an S1G short beacon
5189 * @fc: frame control bytes in little-endian byteorder
5190 * @variable: pointer to the beacon frame elements
5191 * @variable_len: length of the frame elements
5192 * Return: whether or not the frame is an S1G short beacon. As per
5193 * IEEE80211-2024 11.1.3.10.1, The S1G beacon compatibility element shall
5194 * always be present as the first element in beacon frames generated at a
5195 * TBTT (Target Beacon Transmission Time), so any frame not containing
5196 * this element must have been generated at a TSBTT (Target Short Beacon
5197 * Transmission Time) that is not a TBTT. Additionally, short beacons are
5198 * prohibited from containing the S1G beacon compatibility element as per
5199 * IEEE80211-2024 9.3.4.3 Table 9-76, so if we have an S1G beacon with
5200 * either no elements or the first element is not the beacon compatibility
5201 * element, we have a short beacon.
5202 */
5203static inline bool ieee80211_is_s1g_short_beacon(__le16 fc, const u8 *variable,
5204 size_t variable_len)
5205{
5206 if (!ieee80211_is_s1g_beacon(fc))
5207 return false;
5208
5209 /*
5210 * If the frame does not contain at least 1 element (this is perfectly
5211 * valid in a short beacon) and is an S1G beacon, we have a short
5212 * beacon.
5213 */
5214 if (variable_len < 2)
5215 return true;
5216
5217 return variable[0] != WLAN_EID_S1G_BCN_COMPAT;
5218}
5219
5220struct element {
5221 u8 id;
5222 u8 datalen;
5223 u8 data[];
5224} __packed;
5225
5226/* element iteration helpers */
5227#define for_each_element(_elem, _data, _datalen) \
5228 for (_elem = (const struct element *)(_data); \
5229 (const u8 *)(_data) + (_datalen) - (const u8 *)_elem >= \
5230 (int)sizeof(*_elem) && \
5231 (const u8 *)(_data) + (_datalen) - (const u8 *)_elem >= \
5232 (int)sizeof(*_elem) + _elem->datalen; \
5233 _elem = (const struct element *)(_elem->data + _elem->datalen))
5234
5235#define for_each_element_id(element, _id, data, datalen) \
5236 for_each_element(element, data, datalen) \
5237 if (element->id == (_id))
5238
5239#define for_each_element_extid(element, extid, _data, _datalen) \
5240 for_each_element(element, _data, _datalen) \
5241 if (element->id == WLAN_EID_EXTENSION && \
5242 element->datalen > 0 && \
5243 element->data[0] == (extid))
5244
5245#define for_each_subelement(sub, element) \
5246 for_each_element(sub, (element)->data, (element)->datalen)
5247
5248#define for_each_subelement_id(sub, id, element) \
5249 for_each_element_id(sub, id, (element)->data, (element)->datalen)
5250
5251#define for_each_subelement_extid(sub, extid, element) \
5252 for_each_element_extid(sub, extid, (element)->data, (element)->datalen)
5253
5254/**
5255 * for_each_element_completed - determine if element parsing consumed all data
5256 * @element: element pointer after for_each_element() or friends
5257 * @data: same data pointer as passed to for_each_element() or friends
5258 * @datalen: same data length as passed to for_each_element() or friends
5259 * Return: %true if all elements were iterated, %false otherwise; see notes
5260 *
5261 * This function returns %true if all the data was parsed or considered
5262 * while walking the elements. Only use this if your for_each_element()
5263 * loop cannot be broken out of, otherwise it always returns %false.
5264 *
5265 * If some data was malformed, this returns %false since the last parsed
5266 * element will not fill the whole remaining data.
5267 */
5268static inline bool for_each_element_completed(const struct element *element,
5269 const void *data, size_t datalen)
5270{
5271 return (const u8 *)element == (const u8 *)data + datalen;
5272}
5273
5274/*
5275 * RSNX Capabilities:
5276 * bits 0-3: Field length (n-1)
5277 */
5278#define WLAN_RSNX_CAPA_PROTECTED_TWT BIT(4)
5279#define WLAN_RSNX_CAPA_SAE_H2E BIT(5)
5280
5281/*
5282 * reduced neighbor report, based on Draft P802.11ax_D6.1,
5283 * section 9.4.2.170 and accepted contributions.
5284 */
5285#define IEEE80211_AP_INFO_TBTT_HDR_TYPE 0x03
5286#define IEEE80211_AP_INFO_TBTT_HDR_FILTERED 0x04
5287#define IEEE80211_AP_INFO_TBTT_HDR_COLOC 0x08
5288#define IEEE80211_AP_INFO_TBTT_HDR_COUNT 0xF0
5289#define IEEE80211_TBTT_INFO_TYPE_TBTT 0
5290#define IEEE80211_TBTT_INFO_TYPE_MLD 1
5291
5292#define IEEE80211_RNR_TBTT_PARAMS_OCT_RECOMMENDED 0x01
5293#define IEEE80211_RNR_TBTT_PARAMS_SAME_SSID 0x02
5294#define IEEE80211_RNR_TBTT_PARAMS_MULTI_BSSID 0x04
5295#define IEEE80211_RNR_TBTT_PARAMS_TRANSMITTED_BSSID 0x08
5296#define IEEE80211_RNR_TBTT_PARAMS_COLOC_ESS 0x10
5297#define IEEE80211_RNR_TBTT_PARAMS_PROBE_ACTIVE 0x20
5298#define IEEE80211_RNR_TBTT_PARAMS_COLOC_AP 0x40
5299
5300#define IEEE80211_RNR_TBTT_PARAMS_PSD_NO_LIMIT 127
5301#define IEEE80211_RNR_TBTT_PARAMS_PSD_RESERVED -128
5302
5303struct ieee80211_neighbor_ap_info {
5304 u8 tbtt_info_hdr;
5305 u8 tbtt_info_len;
5306 u8 op_class;
5307 u8 channel;
5308} __packed;
5309
5310enum ieee80211_range_params_max_total_ltf {
5311 IEEE80211_RANGE_PARAMS_MAX_TOTAL_LTF_4 = 0,
5312 IEEE80211_RANGE_PARAMS_MAX_TOTAL_LTF_8,
5313 IEEE80211_RANGE_PARAMS_MAX_TOTAL_LTF_16,
5314 IEEE80211_RANGE_PARAMS_MAX_TOTAL_LTF_UNSPECIFIED,
5315};
5316
5317/*
5318 * reduced neighbor report, based on Draft P802.11be_D3.0,
5319 * section 9.4.2.170.2.
5320 */
5321struct ieee80211_rnr_mld_params {
5322 u8 mld_id;
5323 __le16 params;
5324} __packed;
5325
5326#define IEEE80211_RNR_MLD_PARAMS_LINK_ID 0x000F
5327#define IEEE80211_RNR_MLD_PARAMS_BSS_CHANGE_COUNT 0x0FF0
5328#define IEEE80211_RNR_MLD_PARAMS_UPDATES_INCLUDED 0x1000
5329#define IEEE80211_RNR_MLD_PARAMS_DISABLED_LINK 0x2000
5330
5331/* Format of the TBTT information element if it has 7, 8 or 9 bytes */
5332struct ieee80211_tbtt_info_7_8_9 {
5333 u8 tbtt_offset;
5334 u8 bssid[ETH_ALEN];
5335
5336 /* The following element is optional, structure may not grow */
5337 u8 bss_params;
5338 s8 psd_20;
5339} __packed;
5340
5341/* Format of the TBTT information element if it has >= 11 bytes */
5342struct ieee80211_tbtt_info_ge_11 {
5343 u8 tbtt_offset;
5344 u8 bssid[ETH_ALEN];
5345 __le32 short_ssid;
5346
5347 /* The following elements are optional, structure may grow */
5348 u8 bss_params;
5349 s8 psd_20;
5350 struct ieee80211_rnr_mld_params mld_params;
5351} __packed;
5352
5353/* multi-link device */
5354#define IEEE80211_MLD_MAX_NUM_LINKS 15
5355
5356#define IEEE80211_ML_CONTROL_TYPE 0x0007
5357#define IEEE80211_ML_CONTROL_TYPE_BASIC 0
5358#define IEEE80211_ML_CONTROL_TYPE_PREQ 1
5359#define IEEE80211_ML_CONTROL_TYPE_RECONF 2
5360#define IEEE80211_ML_CONTROL_TYPE_TDLS 3
5361#define IEEE80211_ML_CONTROL_TYPE_PRIO_ACCESS 4
5362#define IEEE80211_ML_CONTROL_PRESENCE_MASK 0xfff0
5363
5364struct ieee80211_multi_link_elem {
5365 __le16 control;
5366 u8 variable[];
5367} __packed;
5368
5369#define IEEE80211_MLC_BASIC_PRES_LINK_ID 0x0010
5370#define IEEE80211_MLC_BASIC_PRES_BSS_PARAM_CH_CNT 0x0020
5371#define IEEE80211_MLC_BASIC_PRES_MED_SYNC_DELAY 0x0040
5372#define IEEE80211_MLC_BASIC_PRES_EML_CAPA 0x0080
5373#define IEEE80211_MLC_BASIC_PRES_MLD_CAPA_OP 0x0100
5374#define IEEE80211_MLC_BASIC_PRES_MLD_ID 0x0200
5375#define IEEE80211_MLC_BASIC_PRES_EXT_MLD_CAPA_OP 0x0400
5376
5377#define IEEE80211_MED_SYNC_DELAY_DURATION 0x00ff
5378#define IEEE80211_MED_SYNC_DELAY_SYNC_OFDM_ED_THRESH 0x0f00
5379#define IEEE80211_MED_SYNC_DELAY_SYNC_MAX_NUM_TXOPS 0xf000
5380
5381/*
5382 * Described in P802.11be_D3.0
5383 * dot11MSDTimerDuration should default to 5484 (i.e. 171.375)
5384 * dot11MSDOFDMEDthreshold defaults to -72 (i.e. 0)
5385 * dot11MSDTXOPMAX defaults to 1
5386 */
5387#define IEEE80211_MED_SYNC_DELAY_DEFAULT 0x10ac
5388
5389#define IEEE80211_EML_CAP_EMLSR_SUPP 0x0001
5390#define IEEE80211_EML_CAP_EMLSR_PADDING_DELAY 0x000e
5391#define IEEE80211_EML_CAP_EMLSR_PADDING_DELAY_0US 0
5392#define IEEE80211_EML_CAP_EMLSR_PADDING_DELAY_32US 1
5393#define IEEE80211_EML_CAP_EMLSR_PADDING_DELAY_64US 2
5394#define IEEE80211_EML_CAP_EMLSR_PADDING_DELAY_128US 3
5395#define IEEE80211_EML_CAP_EMLSR_PADDING_DELAY_256US 4
5396#define IEEE80211_EML_CAP_EMLSR_TRANSITION_DELAY 0x0070
5397#define IEEE80211_EML_CAP_EMLSR_TRANSITION_DELAY_0US 0
5398#define IEEE80211_EML_CAP_EMLSR_TRANSITION_DELAY_16US 1
5399#define IEEE80211_EML_CAP_EMLSR_TRANSITION_DELAY_32US 2
5400#define IEEE80211_EML_CAP_EMLSR_TRANSITION_DELAY_64US 3
5401#define IEEE80211_EML_CAP_EMLSR_TRANSITION_DELAY_128US 4
5402#define IEEE80211_EML_CAP_EMLSR_TRANSITION_DELAY_256US 5
5403#define IEEE80211_EML_CAP_EMLMR_SUPPORT 0x0080
5404#define IEEE80211_EML_CAP_EMLMR_DELAY 0x0700
5405#define IEEE80211_EML_CAP_EMLMR_DELAY_0US 0
5406#define IEEE80211_EML_CAP_EMLMR_DELAY_32US 1
5407#define IEEE80211_EML_CAP_EMLMR_DELAY_64US 2
5408#define IEEE80211_EML_CAP_EMLMR_DELAY_128US 3
5409#define IEEE80211_EML_CAP_EMLMR_DELAY_256US 4
5410#define IEEE80211_EML_CAP_TRANSITION_TIMEOUT 0x7800
5411#define IEEE80211_EML_CAP_TRANSITION_TIMEOUT_0 0
5412#define IEEE80211_EML_CAP_TRANSITION_TIMEOUT_128US 1
5413#define IEEE80211_EML_CAP_TRANSITION_TIMEOUT_256US 2
5414#define IEEE80211_EML_CAP_TRANSITION_TIMEOUT_512US 3
5415#define IEEE80211_EML_CAP_TRANSITION_TIMEOUT_1TU 4
5416#define IEEE80211_EML_CAP_TRANSITION_TIMEOUT_2TU 5
5417#define IEEE80211_EML_CAP_TRANSITION_TIMEOUT_4TU 6
5418#define IEEE80211_EML_CAP_TRANSITION_TIMEOUT_8TU 7
5419#define IEEE80211_EML_CAP_TRANSITION_TIMEOUT_16TU 8
5420#define IEEE80211_EML_CAP_TRANSITION_TIMEOUT_32TU 9
5421#define IEEE80211_EML_CAP_TRANSITION_TIMEOUT_64TU 10
5422#define IEEE80211_EML_CAP_TRANSITION_TIMEOUT_128TU 11
5423
5424#define IEEE80211_MLD_CAP_OP_MAX_SIMUL_LINKS 0x000f
5425#define IEEE80211_MLD_CAP_OP_SRS_SUPPORT 0x0010
5426#define IEEE80211_MLD_CAP_OP_TID_TO_LINK_MAP_NEG_SUPP 0x0060
5427#define IEEE80211_MLD_CAP_OP_TID_TO_LINK_MAP_NEG_NO_SUPP 0
5428#define IEEE80211_MLD_CAP_OP_TID_TO_LINK_MAP_NEG_SUPP_SAME 1
5429#define IEEE80211_MLD_CAP_OP_TID_TO_LINK_MAP_NEG_RESERVED 2
5430#define IEEE80211_MLD_CAP_OP_TID_TO_LINK_MAP_NEG_SUPP_DIFF 3
5431#define IEEE80211_MLD_CAP_OP_FREQ_SEP_TYPE_IND 0x0f80
5432#define IEEE80211_MLD_CAP_OP_AAR_SUPPORT 0x1000
5433#define IEEE80211_MLD_CAP_OP_LINK_RECONF_SUPPORT 0x2000
5434#define IEEE80211_MLD_CAP_OP_ALIGNED_TWT_SUPPORT 0x4000
5435
5436struct ieee80211_mle_basic_common_info {
5437 u8 len;
5438 u8 mld_mac_addr[ETH_ALEN];
5439 u8 variable[];
5440} __packed;
5441
5442#define IEEE80211_MLC_PREQ_PRES_MLD_ID 0x0010
5443
5444struct ieee80211_mle_preq_common_info {
5445 u8 len;
5446 u8 variable[];
5447} __packed;
5448
5449#define IEEE80211_MLC_RECONF_PRES_MLD_MAC_ADDR 0x0010
5450#define IEEE80211_MLC_RECONF_PRES_EML_CAPA 0x0020
5451#define IEEE80211_MLC_RECONF_PRES_MLD_CAPA_OP 0x0040
5452#define IEEE80211_MLC_RECONF_PRES_EXT_MLD_CAPA_OP 0x0080
5453
5454/* no fixed fields in RECONF */
5455
5456struct ieee80211_mle_tdls_common_info {
5457 u8 len;
5458 u8 ap_mld_mac_addr[ETH_ALEN];
5459} __packed;
5460
5461#define IEEE80211_MLC_PRIO_ACCESS_PRES_AP_MLD_MAC_ADDR 0x0010
5462
5463/* no fixed fields in PRIO_ACCESS */
5464
5465/**
5466 * ieee80211_mle_common_size - check multi-link element common size
5467 * @data: multi-link element, must already be checked for size using
5468 * ieee80211_mle_size_ok()
5469 * Return: the size of the multi-link element's "common" subfield
5470 */
5471static inline u8 ieee80211_mle_common_size(const u8 *data)
5472{
5473 const struct ieee80211_multi_link_elem *mle = (const void *)data;
5474 u16 control = le16_to_cpu(mle->control);
5475
5476 switch (u16_get_bits(v: control, IEEE80211_ML_CONTROL_TYPE)) {
5477 case IEEE80211_ML_CONTROL_TYPE_BASIC:
5478 case IEEE80211_ML_CONTROL_TYPE_PREQ:
5479 case IEEE80211_ML_CONTROL_TYPE_TDLS:
5480 case IEEE80211_ML_CONTROL_TYPE_RECONF:
5481 case IEEE80211_ML_CONTROL_TYPE_PRIO_ACCESS:
5482 /*
5483 * The length is the first octet pointed by mle->variable so no
5484 * need to add anything
5485 */
5486 break;
5487 default:
5488 WARN_ON(1);
5489 return 0;
5490 }
5491
5492 return sizeof(*mle) + mle->variable[0];
5493}
5494
5495/**
5496 * ieee80211_mle_get_link_id - returns the link ID
5497 * @data: the basic multi link element
5498 * Return: the link ID, or -1 if not present
5499 *
5500 * The element is assumed to be of the correct type (BASIC) and big enough,
5501 * this must be checked using ieee80211_mle_type_ok().
5502 */
5503static inline int ieee80211_mle_get_link_id(const u8 *data)
5504{
5505 const struct ieee80211_multi_link_elem *mle = (const void *)data;
5506 u16 control = le16_to_cpu(mle->control);
5507 const u8 *common = mle->variable;
5508
5509 /* common points now at the beginning of ieee80211_mle_basic_common_info */
5510 common += sizeof(struct ieee80211_mle_basic_common_info);
5511
5512 if (!(control & IEEE80211_MLC_BASIC_PRES_LINK_ID))
5513 return -1;
5514
5515 return *common;
5516}
5517
5518/**
5519 * ieee80211_mle_get_bss_param_ch_cnt - returns the BSS parameter change count
5520 * @data: pointer to the basic multi link element
5521 * Return: the BSS Parameter Change Count field value, or -1 if not present
5522 *
5523 * The element is assumed to be of the correct type (BASIC) and big enough,
5524 * this must be checked using ieee80211_mle_type_ok().
5525 */
5526static inline int
5527ieee80211_mle_get_bss_param_ch_cnt(const u8 *data)
5528{
5529 const struct ieee80211_multi_link_elem *mle = (const void *)data;
5530 u16 control = le16_to_cpu(mle->control);
5531 const u8 *common = mle->variable;
5532
5533 /* common points now at the beginning of ieee80211_mle_basic_common_info */
5534 common += sizeof(struct ieee80211_mle_basic_common_info);
5535
5536 if (!(control & IEEE80211_MLC_BASIC_PRES_BSS_PARAM_CH_CNT))
5537 return -1;
5538
5539 if (control & IEEE80211_MLC_BASIC_PRES_LINK_ID)
5540 common += 1;
5541
5542 return *common;
5543}
5544
5545/**
5546 * ieee80211_mle_get_eml_med_sync_delay - returns the medium sync delay
5547 * @data: pointer to the multi-link element
5548 * Return: the medium synchronization delay field value from the multi-link
5549 * element, or the default value (%IEEE80211_MED_SYNC_DELAY_DEFAULT)
5550 * if not present
5551 *
5552 * The element is assumed to be of the correct type (BASIC) and big enough,
5553 * this must be checked using ieee80211_mle_type_ok().
5554 */
5555static inline u16 ieee80211_mle_get_eml_med_sync_delay(const u8 *data)
5556{
5557 const struct ieee80211_multi_link_elem *mle = (const void *)data;
5558 u16 control = le16_to_cpu(mle->control);
5559 const u8 *common = mle->variable;
5560
5561 /* common points now at the beginning of ieee80211_mle_basic_common_info */
5562 common += sizeof(struct ieee80211_mle_basic_common_info);
5563
5564 if (!(control & IEEE80211_MLC_BASIC_PRES_MED_SYNC_DELAY))
5565 return IEEE80211_MED_SYNC_DELAY_DEFAULT;
5566
5567 if (control & IEEE80211_MLC_BASIC_PRES_LINK_ID)
5568 common += 1;
5569 if (control & IEEE80211_MLC_BASIC_PRES_BSS_PARAM_CH_CNT)
5570 common += 1;
5571
5572 return get_unaligned_le16(p: common);
5573}
5574
5575/**
5576 * ieee80211_mle_get_eml_cap - returns the EML capability
5577 * @data: pointer to the multi-link element
5578 * Return: the EML capability field value from the multi-link element,
5579 * or 0 if not present
5580 *
5581 * The element is assumed to be of the correct type (BASIC) and big enough,
5582 * this must be checked using ieee80211_mle_type_ok().
5583 */
5584static inline u16 ieee80211_mle_get_eml_cap(const u8 *data)
5585{
5586 const struct ieee80211_multi_link_elem *mle = (const void *)data;
5587 u16 control = le16_to_cpu(mle->control);
5588 const u8 *common = mle->variable;
5589
5590 /* common points now at the beginning of ieee80211_mle_basic_common_info */
5591 common += sizeof(struct ieee80211_mle_basic_common_info);
5592
5593 if (!(control & IEEE80211_MLC_BASIC_PRES_EML_CAPA))
5594 return 0;
5595
5596 if (control & IEEE80211_MLC_BASIC_PRES_LINK_ID)
5597 common += 1;
5598 if (control & IEEE80211_MLC_BASIC_PRES_BSS_PARAM_CH_CNT)
5599 common += 1;
5600 if (control & IEEE80211_MLC_BASIC_PRES_MED_SYNC_DELAY)
5601 common += 2;
5602
5603 return get_unaligned_le16(p: common);
5604}
5605
5606/**
5607 * ieee80211_mle_get_mld_capa_op - returns the MLD capabilities and operations.
5608 * @data: pointer to the multi-link element
5609 * Return: the MLD capabilities and operations field value from the multi-link
5610 * element, or 0 if not present
5611 *
5612 * The element is assumed to be of the correct type (BASIC) and big enough,
5613 * this must be checked using ieee80211_mle_type_ok().
5614 */
5615static inline u16 ieee80211_mle_get_mld_capa_op(const u8 *data)
5616{
5617 const struct ieee80211_multi_link_elem *mle = (const void *)data;
5618 u16 control = le16_to_cpu(mle->control);
5619 const u8 *common = mle->variable;
5620
5621 /*
5622 * common points now at the beginning of
5623 * ieee80211_mle_basic_common_info
5624 */
5625 common += sizeof(struct ieee80211_mle_basic_common_info);
5626
5627 if (!(control & IEEE80211_MLC_BASIC_PRES_MLD_CAPA_OP))
5628 return 0;
5629
5630 if (control & IEEE80211_MLC_BASIC_PRES_LINK_ID)
5631 common += 1;
5632 if (control & IEEE80211_MLC_BASIC_PRES_BSS_PARAM_CH_CNT)
5633 common += 1;
5634 if (control & IEEE80211_MLC_BASIC_PRES_MED_SYNC_DELAY)
5635 common += 2;
5636 if (control & IEEE80211_MLC_BASIC_PRES_EML_CAPA)
5637 common += 2;
5638
5639 return get_unaligned_le16(p: common);
5640}
5641
5642/* Defined in Figure 9-1074t in P802.11be_D7.0 */
5643#define IEEE80211_EHT_ML_EXT_MLD_CAPA_OP_PARAM_UPDATE 0x0001
5644#define IEEE80211_EHT_ML_EXT_MLD_CAPA_OP_RECO_MAX_LINKS_MASK 0x001e
5645#define IEEE80211_EHT_ML_EXT_MLD_CAPA_NSTR_UPDATE 0x0020
5646#define IEEE80211_EHT_ML_EXT_MLD_CAPA_EMLSR_ENA_ON_ONE_LINK 0x0040
5647#define IEEE80211_EHT_ML_EXT_MLD_CAPA_BTM_MLD_RECO_MULTI_AP 0x0080
5648
5649/**
5650 * ieee80211_mle_get_ext_mld_capa_op - returns the extended MLD capabilities
5651 * and operations.
5652 * @data: pointer to the multi-link element
5653 * Return: the extended MLD capabilities and operations field value from
5654 * the multi-link element, or 0 if not present
5655 *
5656 * The element is assumed to be of the correct type (BASIC) and big enough,
5657 * this must be checked using ieee80211_mle_type_ok().
5658 */
5659static inline u16 ieee80211_mle_get_ext_mld_capa_op(const u8 *data)
5660{
5661 const struct ieee80211_multi_link_elem *mle = (const void *)data;
5662 u16 control = le16_to_cpu(mle->control);
5663 const u8 *common = mle->variable;
5664
5665 /*
5666 * common points now at the beginning of
5667 * ieee80211_mle_basic_common_info
5668 */
5669 common += sizeof(struct ieee80211_mle_basic_common_info);
5670
5671 if (!(control & IEEE80211_MLC_BASIC_PRES_EXT_MLD_CAPA_OP))
5672 return 0;
5673
5674 if (control & IEEE80211_MLC_BASIC_PRES_LINK_ID)
5675 common += 1;
5676 if (control & IEEE80211_MLC_BASIC_PRES_BSS_PARAM_CH_CNT)
5677 common += 1;
5678 if (control & IEEE80211_MLC_BASIC_PRES_MED_SYNC_DELAY)
5679 common += 2;
5680 if (control & IEEE80211_MLC_BASIC_PRES_EML_CAPA)
5681 common += 2;
5682 if (control & IEEE80211_MLC_BASIC_PRES_MLD_CAPA_OP)
5683 common += 2;
5684 if (control & IEEE80211_MLC_BASIC_PRES_MLD_ID)
5685 common += 1;
5686
5687 return get_unaligned_le16(p: common);
5688}
5689
5690/**
5691 * ieee80211_mle_get_mld_id - returns the MLD ID
5692 * @data: pointer to the multi-link element
5693 * Return: The MLD ID in the given multi-link element, or 0 if not present
5694 *
5695 * The element is assumed to be of the correct type (BASIC) and big enough,
5696 * this must be checked using ieee80211_mle_type_ok().
5697 */
5698static inline u8 ieee80211_mle_get_mld_id(const u8 *data)
5699{
5700 const struct ieee80211_multi_link_elem *mle = (const void *)data;
5701 u16 control = le16_to_cpu(mle->control);
5702 const u8 *common = mle->variable;
5703
5704 /*
5705 * common points now at the beginning of
5706 * ieee80211_mle_basic_common_info
5707 */
5708 common += sizeof(struct ieee80211_mle_basic_common_info);
5709
5710 if (!(control & IEEE80211_MLC_BASIC_PRES_MLD_ID))
5711 return 0;
5712
5713 if (control & IEEE80211_MLC_BASIC_PRES_LINK_ID)
5714 common += 1;
5715 if (control & IEEE80211_MLC_BASIC_PRES_BSS_PARAM_CH_CNT)
5716 common += 1;
5717 if (control & IEEE80211_MLC_BASIC_PRES_MED_SYNC_DELAY)
5718 common += 2;
5719 if (control & IEEE80211_MLC_BASIC_PRES_EML_CAPA)
5720 common += 2;
5721 if (control & IEEE80211_MLC_BASIC_PRES_MLD_CAPA_OP)
5722 common += 2;
5723
5724 return *common;
5725}
5726
5727/**
5728 * ieee80211_mle_size_ok - validate multi-link element size
5729 * @data: pointer to the element data
5730 * @len: length of the containing element
5731 * Return: whether or not the multi-link element size is OK
5732 */
5733static inline bool ieee80211_mle_size_ok(const u8 *data, size_t len)
5734{
5735 const struct ieee80211_multi_link_elem *mle = (const void *)data;
5736 u8 fixed = sizeof(*mle);
5737 u8 common = 0;
5738 bool check_common_len = false;
5739 u16 control;
5740
5741 if (!data || len < fixed)
5742 return false;
5743
5744 control = le16_to_cpu(mle->control);
5745
5746 switch (u16_get_bits(v: control, IEEE80211_ML_CONTROL_TYPE)) {
5747 case IEEE80211_ML_CONTROL_TYPE_BASIC:
5748 common += sizeof(struct ieee80211_mle_basic_common_info);
5749 check_common_len = true;
5750 if (control & IEEE80211_MLC_BASIC_PRES_LINK_ID)
5751 common += 1;
5752 if (control & IEEE80211_MLC_BASIC_PRES_BSS_PARAM_CH_CNT)
5753 common += 1;
5754 if (control & IEEE80211_MLC_BASIC_PRES_MED_SYNC_DELAY)
5755 common += 2;
5756 if (control & IEEE80211_MLC_BASIC_PRES_EML_CAPA)
5757 common += 2;
5758 if (control & IEEE80211_MLC_BASIC_PRES_MLD_CAPA_OP)
5759 common += 2;
5760 if (control & IEEE80211_MLC_BASIC_PRES_MLD_ID)
5761 common += 1;
5762 if (control & IEEE80211_MLC_BASIC_PRES_EXT_MLD_CAPA_OP)
5763 common += 2;
5764 break;
5765 case IEEE80211_ML_CONTROL_TYPE_PREQ:
5766 common += sizeof(struct ieee80211_mle_preq_common_info);
5767 if (control & IEEE80211_MLC_PREQ_PRES_MLD_ID)
5768 common += 1;
5769 check_common_len = true;
5770 break;
5771 case IEEE80211_ML_CONTROL_TYPE_RECONF:
5772 if (control & IEEE80211_MLC_RECONF_PRES_MLD_MAC_ADDR)
5773 common += ETH_ALEN;
5774 if (control & IEEE80211_MLC_RECONF_PRES_EML_CAPA)
5775 common += 2;
5776 if (control & IEEE80211_MLC_RECONF_PRES_MLD_CAPA_OP)
5777 common += 2;
5778 if (control & IEEE80211_MLC_RECONF_PRES_EXT_MLD_CAPA_OP)
5779 common += 2;
5780 break;
5781 case IEEE80211_ML_CONTROL_TYPE_TDLS:
5782 common += sizeof(struct ieee80211_mle_tdls_common_info);
5783 check_common_len = true;
5784 break;
5785 case IEEE80211_ML_CONTROL_TYPE_PRIO_ACCESS:
5786 common = ETH_ALEN + 1;
5787 break;
5788 default:
5789 /* we don't know this type */
5790 return true;
5791 }
5792
5793 if (len < fixed + common)
5794 return false;
5795
5796 if (!check_common_len)
5797 return true;
5798
5799 /* if present, common length is the first octet there */
5800 return mle->variable[0] >= common;
5801}
5802
5803/**
5804 * ieee80211_mle_type_ok - validate multi-link element type and size
5805 * @data: pointer to the element data
5806 * @type: expected type of the element
5807 * @len: length of the containing element
5808 * Return: whether or not the multi-link element type matches and size is OK
5809 */
5810static inline bool ieee80211_mle_type_ok(const u8 *data, u8 type, size_t len)
5811{
5812 const struct ieee80211_multi_link_elem *mle = (const void *)data;
5813 u16 control;
5814
5815 if (!ieee80211_mle_size_ok(data, len))
5816 return false;
5817
5818 control = le16_to_cpu(mle->control);
5819
5820 if (u16_get_bits(v: control, IEEE80211_ML_CONTROL_TYPE) == type)
5821 return true;
5822
5823 return false;
5824}
5825
5826enum ieee80211_mle_subelems {
5827 IEEE80211_MLE_SUBELEM_PER_STA_PROFILE = 0,
5828 IEEE80211_MLE_SUBELEM_FRAGMENT = 254,
5829};
5830
5831#define IEEE80211_MLE_STA_CONTROL_LINK_ID 0x000f
5832#define IEEE80211_MLE_STA_CONTROL_COMPLETE_PROFILE 0x0010
5833#define IEEE80211_MLE_STA_CONTROL_STA_MAC_ADDR_PRESENT 0x0020
5834#define IEEE80211_MLE_STA_CONTROL_BEACON_INT_PRESENT 0x0040
5835#define IEEE80211_MLE_STA_CONTROL_TSF_OFFS_PRESENT 0x0080
5836#define IEEE80211_MLE_STA_CONTROL_DTIM_INFO_PRESENT 0x0100
5837#define IEEE80211_MLE_STA_CONTROL_NSTR_LINK_PAIR_PRESENT 0x0200
5838#define IEEE80211_MLE_STA_CONTROL_NSTR_BITMAP_SIZE 0x0400
5839#define IEEE80211_MLE_STA_CONTROL_BSS_PARAM_CHANGE_CNT_PRESENT 0x0800
5840
5841struct ieee80211_mle_per_sta_profile {
5842 __le16 control;
5843 u8 sta_info_len;
5844 u8 variable[];
5845} __packed;
5846
5847/**
5848 * ieee80211_mle_basic_sta_prof_size_ok - validate basic multi-link element sta
5849 * profile size
5850 * @data: pointer to the sub element data
5851 * @len: length of the containing sub element
5852 * Return: %true if the STA profile is large enough, %false otherwise
5853 */
5854static inline bool ieee80211_mle_basic_sta_prof_size_ok(const u8 *data,
5855 size_t len)
5856{
5857 const struct ieee80211_mle_per_sta_profile *prof = (const void *)data;
5858 u16 control;
5859 u8 fixed = sizeof(*prof);
5860 u8 info_len = 1;
5861
5862 if (len < fixed)
5863 return false;
5864
5865 control = le16_to_cpu(prof->control);
5866
5867 if (control & IEEE80211_MLE_STA_CONTROL_STA_MAC_ADDR_PRESENT)
5868 info_len += 6;
5869 if (control & IEEE80211_MLE_STA_CONTROL_BEACON_INT_PRESENT)
5870 info_len += 2;
5871 if (control & IEEE80211_MLE_STA_CONTROL_TSF_OFFS_PRESENT)
5872 info_len += 8;
5873 if (control & IEEE80211_MLE_STA_CONTROL_DTIM_INFO_PRESENT)
5874 info_len += 2;
5875 if (control & IEEE80211_MLE_STA_CONTROL_COMPLETE_PROFILE &&
5876 control & IEEE80211_MLE_STA_CONTROL_NSTR_LINK_PAIR_PRESENT) {
5877 if (control & IEEE80211_MLE_STA_CONTROL_NSTR_BITMAP_SIZE)
5878 info_len += 2;
5879 else
5880 info_len += 1;
5881 }
5882 if (control & IEEE80211_MLE_STA_CONTROL_BSS_PARAM_CHANGE_CNT_PRESENT)
5883 info_len += 1;
5884
5885 return prof->sta_info_len >= info_len &&
5886 fixed + prof->sta_info_len - 1 <= len;
5887}
5888
5889/**
5890 * ieee80211_mle_basic_sta_prof_bss_param_ch_cnt - get per-STA profile BSS
5891 * parameter change count
5892 * @prof: the per-STA profile, having been checked with
5893 * ieee80211_mle_basic_sta_prof_size_ok() for the correct length
5894 *
5895 * Return: The BSS parameter change count value if present, 0 otherwise.
5896 */
5897static inline u8
5898ieee80211_mle_basic_sta_prof_bss_param_ch_cnt(const struct ieee80211_mle_per_sta_profile *prof)
5899{
5900 u16 control = le16_to_cpu(prof->control);
5901 const u8 *pos = prof->variable;
5902
5903 if (!(control & IEEE80211_MLE_STA_CONTROL_BSS_PARAM_CHANGE_CNT_PRESENT))
5904 return 0;
5905
5906 if (control & IEEE80211_MLE_STA_CONTROL_STA_MAC_ADDR_PRESENT)
5907 pos += 6;
5908 if (control & IEEE80211_MLE_STA_CONTROL_BEACON_INT_PRESENT)
5909 pos += 2;
5910 if (control & IEEE80211_MLE_STA_CONTROL_TSF_OFFS_PRESENT)
5911 pos += 8;
5912 if (control & IEEE80211_MLE_STA_CONTROL_DTIM_INFO_PRESENT)
5913 pos += 2;
5914 if (control & IEEE80211_MLE_STA_CONTROL_COMPLETE_PROFILE &&
5915 control & IEEE80211_MLE_STA_CONTROL_NSTR_LINK_PAIR_PRESENT) {
5916 if (control & IEEE80211_MLE_STA_CONTROL_NSTR_BITMAP_SIZE)
5917 pos += 2;
5918 else
5919 pos += 1;
5920 }
5921
5922 return *pos;
5923}
5924
5925#define IEEE80211_MLE_STA_RECONF_CONTROL_LINK_ID 0x000f
5926#define IEEE80211_MLE_STA_RECONF_CONTROL_COMPLETE_PROFILE 0x0010
5927#define IEEE80211_MLE_STA_RECONF_CONTROL_STA_MAC_ADDR_PRESENT 0x0020
5928#define IEEE80211_MLE_STA_RECONF_CONTROL_AP_REM_TIMER_PRESENT 0x0040
5929#define IEEE80211_MLE_STA_RECONF_CONTROL_OPERATION_TYPE 0x0780
5930#define IEEE80211_MLE_STA_RECONF_CONTROL_OPERATION_TYPE_AP_REM 0
5931#define IEEE80211_MLE_STA_RECONF_CONTROL_OPERATION_TYPE_OP_PARAM_UPDATE 1
5932#define IEEE80211_MLE_STA_RECONF_CONTROL_OPERATION_TYPE_ADD_LINK 2
5933#define IEEE80211_MLE_STA_RECONF_CONTROL_OPERATION_TYPE_DEL_LINK 3
5934#define IEEE80211_MLE_STA_RECONF_CONTROL_OPERATION_TYPE_NSTR_STATUS 4
5935#define IEEE80211_MLE_STA_RECONF_CONTROL_OPERATION_PARAMS_PRESENT 0x0800
5936
5937/**
5938 * ieee80211_mle_reconf_sta_prof_size_ok - validate reconfiguration multi-link
5939 * element sta profile size.
5940 * @data: pointer to the sub element data
5941 * @len: length of the containing sub element
5942 * Return: %true if the STA profile is large enough, %false otherwise
5943 */
5944static inline bool ieee80211_mle_reconf_sta_prof_size_ok(const u8 *data,
5945 size_t len)
5946{
5947 const struct ieee80211_mle_per_sta_profile *prof = (const void *)data;
5948 u16 control;
5949 u8 fixed = sizeof(*prof);
5950 u8 info_len = 1;
5951
5952 if (len < fixed)
5953 return false;
5954
5955 control = le16_to_cpu(prof->control);
5956
5957 if (control & IEEE80211_MLE_STA_RECONF_CONTROL_STA_MAC_ADDR_PRESENT)
5958 info_len += ETH_ALEN;
5959 if (control & IEEE80211_MLE_STA_RECONF_CONTROL_AP_REM_TIMER_PRESENT)
5960 info_len += 2;
5961 if (control & IEEE80211_MLE_STA_RECONF_CONTROL_OPERATION_PARAMS_PRESENT)
5962 info_len += 2;
5963
5964 return prof->sta_info_len >= info_len &&
5965 fixed + prof->sta_info_len - 1 <= len;
5966}
5967
5968#define IEEE80211_MLE_STA_EPCS_CONTROL_LINK_ID 0x000f
5969#define IEEE80211_EPCS_ENA_RESP_BODY_LEN 3
5970
5971static inline bool ieee80211_tid_to_link_map_size_ok(const u8 *data, size_t len)
5972{
5973 const struct ieee80211_ttlm_elem *t2l = (const void *)data;
5974 u8 control, fixed = sizeof(*t2l), elem_len = 0;
5975
5976 if (len < fixed)
5977 return false;
5978
5979 control = t2l->control;
5980
5981 if (control & IEEE80211_TTLM_CONTROL_SWITCH_TIME_PRESENT)
5982 elem_len += 2;
5983 if (control & IEEE80211_TTLM_CONTROL_EXPECTED_DUR_PRESENT)
5984 elem_len += 3;
5985
5986 if (!(control & IEEE80211_TTLM_CONTROL_DEF_LINK_MAP)) {
5987 u8 bm_size;
5988
5989 elem_len += 1;
5990 if (len < fixed + elem_len)
5991 return false;
5992
5993 if (control & IEEE80211_TTLM_CONTROL_LINK_MAP_SIZE)
5994 bm_size = 1;
5995 else
5996 bm_size = 2;
5997
5998 elem_len += hweight8(t2l->optional[0]) * bm_size;
5999 }
6000
6001 return len >= fixed + elem_len;
6002}
6003
6004/**
6005 * ieee80211_emlsr_pad_delay_in_us - Fetch the EMLSR Padding delay
6006 * in microseconds
6007 * @eml_cap: EML capabilities field value from common info field of
6008 * the Multi-link element
6009 * Return: the EMLSR Padding delay (in microseconds) encoded in the
6010 * EML Capabilities field
6011 */
6012
6013static inline u32 ieee80211_emlsr_pad_delay_in_us(u16 eml_cap)
6014{
6015 /* IEEE Std 802.11be-2024 Table 9-417i—Encoding of the EMLSR
6016 * Padding Delay subfield.
6017 */
6018 u32 pad_delay = u16_get_bits(v: eml_cap,
6019 IEEE80211_EML_CAP_EMLSR_PADDING_DELAY);
6020
6021 if (!pad_delay ||
6022 pad_delay > IEEE80211_EML_CAP_EMLSR_PADDING_DELAY_256US)
6023 return 0;
6024
6025 return 32 * (1 << (pad_delay - 1));
6026}
6027
6028/**
6029 * ieee80211_emlsr_trans_delay_in_us - Fetch the EMLSR Transition
6030 * delay in microseconds
6031 * @eml_cap: EML capabilities field value from common info field of
6032 * the Multi-link element
6033 * Return: the EMLSR Transition delay (in microseconds) encoded in the
6034 * EML Capabilities field
6035 */
6036
6037static inline u32 ieee80211_emlsr_trans_delay_in_us(u16 eml_cap)
6038{
6039 /* IEEE Std 802.11be-2024 Table 9-417j—Encoding of the EMLSR
6040 * Transition Delay subfield.
6041 */
6042 u32 trans_delay =
6043 u16_get_bits(v: eml_cap,
6044 IEEE80211_EML_CAP_EMLSR_TRANSITION_DELAY);
6045
6046 /* invalid values also just use 0 */
6047 if (!trans_delay ||
6048 trans_delay > IEEE80211_EML_CAP_EMLSR_TRANSITION_DELAY_256US)
6049 return 0;
6050
6051 return 16 * (1 << (trans_delay - 1));
6052}
6053
6054/**
6055 * ieee80211_eml_trans_timeout_in_us - Fetch the EMLSR Transition
6056 * timeout value in microseconds
6057 * @eml_cap: EML capabilities field value from common info field of
6058 * the Multi-link element
6059 * Return: the EMLSR Transition timeout (in microseconds) encoded in
6060 * the EML Capabilities field
6061 */
6062
6063static inline u32 ieee80211_eml_trans_timeout_in_us(u16 eml_cap)
6064{
6065 /* IEEE Std 802.11be-2024 Table 9-417m—Encoding of the
6066 * Transition Timeout subfield.
6067 */
6068 u8 timeout = u16_get_bits(v: eml_cap,
6069 IEEE80211_EML_CAP_TRANSITION_TIMEOUT);
6070
6071 /* invalid values also just use 0 */
6072 if (!timeout || timeout > IEEE80211_EML_CAP_TRANSITION_TIMEOUT_128TU)
6073 return 0;
6074
6075 return 128 * (1 << (timeout - 1));
6076}
6077
6078#define for_each_mle_subelement(_elem, _data, _len) \
6079 if (ieee80211_mle_size_ok(_data, _len)) \
6080 for_each_element(_elem, \
6081 _data + ieee80211_mle_common_size(_data),\
6082 _len - ieee80211_mle_common_size(_data))
6083
6084/* NAN operation mode, as defined in Wi-Fi Aware (TM) specification Table 81 */
6085#define NAN_OP_MODE_PHY_MODE_VHT 0x01
6086#define NAN_OP_MODE_PHY_MODE_HE 0x10
6087#define NAN_OP_MODE_PHY_MODE_MASK 0x11
6088#define NAN_OP_MODE_80P80MHZ 0x02
6089#define NAN_OP_MODE_160MHZ 0x04
6090#define NAN_OP_MODE_PNDL_SUPPRTED 0x08
6091
6092/* NAN Device capabilities, as defined in Wi-Fi Aware (TM) specification
6093 * Table 79
6094 */
6095#define NAN_DEV_CAPA_DFS_OWNER 0x01
6096#define NAN_DEV_CAPA_EXT_KEY_ID_SUPPORTED 0x02
6097#define NAN_DEV_CAPA_SIM_NDP_RX_SUPPORTED 0x04
6098#define NAN_DEV_CAPA_NDPE_SUPPORTED 0x08
6099#define NAN_DEV_CAPA_S3_SUPPORTED 0x10
6100
6101#endif /* LINUX_IEEE80211_H */
6102