Debian Codegraph @

include/linux/ieee80211.h

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