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