1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright 2002-2005, Instant802 Networks, Inc.
4 * Copyright 2005-2006, Devicescape Software, Inc.
7 * Copyright 2013-2014 Intel Mobile Communications GmbH
8 * Copyright (C) 2015-2017 Intel Deutschland GmbH
9 * Copyright (C) 2018-2024 Intel Corporation
11 * element parsing for mac80211
14 #include <net/mac80211.h>
15 #include <linux/netdevice.h>
16 #include <linux/export.h>
17 #include <linux/types.h>
18 #include <linux/slab.h>
19 #include <linux/skbuff.h>
20 #include <linux/etherdevice.h>
21 #include <linux/if_arp.h>
22 #include <linux/bitmap.h>
23 #include <linux/crc32.h>
24 #include <net/net_namespace.h>
25 #include <net/cfg80211.h>
26 #include <net/rtnetlink.h>
27 #include <kunit/visibility.h>
29 #include "ieee80211_i.h"
30 #include "driver-ops.h"
37 struct ieee80211_elems_parse {
38 /* must be first for kfree to work */
39 struct ieee802_11_elems elems;
41 /* The basic Multi-Link element in the original elements */
42 const struct element *ml_basic_elem;
44 /* The reconfiguration Multi-Link element in the original elements */
45 const struct element *ml_reconf_elem;
48 * scratch buffer that can be used for various element parsing related
49 * tasks, e.g., element de-fragmentation etc.
53 u8 scratch[] __counted_by(scratch_len);
57 ieee80211_parse_extension_element(u32 *crc,
58 const struct element *elem,
59 struct ieee80211_elems_parse *elems_parse,
60 struct ieee80211_elems_parse_params *params)
62 struct ieee802_11_elems *elems = &elems_parse->elems;
63 const void *data = elem->data + 1;
64 bool calc_crc = false;
70 len = elem->datalen - 1;
72 switch (elem->data[0]) {
73 case WLAN_EID_EXT_HE_MU_EDCA:
74 if (params->mode < IEEE80211_CONN_MODE_HE)
77 if (len >= sizeof(*elems->mu_edca_param_set))
78 elems->mu_edca_param_set = data;
80 case WLAN_EID_EXT_HE_CAPABILITY:
81 if (params->mode < IEEE80211_CONN_MODE_HE)
83 if (ieee80211_he_capa_size_ok(data, len)) {
85 elems->he_cap_len = len;
88 case WLAN_EID_EXT_HE_OPERATION:
89 if (params->mode < IEEE80211_CONN_MODE_HE)
92 if (len >= sizeof(*elems->he_operation) &&
93 len >= ieee80211_he_oper_size(data) - 1)
94 elems->he_operation = data;
96 case WLAN_EID_EXT_UORA:
97 if (params->mode < IEEE80211_CONN_MODE_HE)
100 elems->uora_element = data;
102 case WLAN_EID_EXT_MAX_CHANNEL_SWITCH_TIME:
104 elems->max_channel_switch_time = data;
106 case WLAN_EID_EXT_MULTIPLE_BSSID_CONFIGURATION:
107 if (len >= sizeof(*elems->mbssid_config_ie))
108 elems->mbssid_config_ie = data;
110 case WLAN_EID_EXT_HE_SPR:
111 if (params->mode < IEEE80211_CONN_MODE_HE)
113 if (len >= sizeof(*elems->he_spr) &&
114 len >= ieee80211_he_spr_size(data))
115 elems->he_spr = data;
117 case WLAN_EID_EXT_HE_6GHZ_CAPA:
118 if (params->mode < IEEE80211_CONN_MODE_HE)
120 if (len >= sizeof(*elems->he_6ghz_capa))
121 elems->he_6ghz_capa = data;
123 case WLAN_EID_EXT_EHT_CAPABILITY:
124 if (params->mode < IEEE80211_CONN_MODE_EHT)
126 if (ieee80211_eht_capa_size_ok(elems->he_cap,
129 elems->eht_cap = data;
130 elems->eht_cap_len = len;
133 case WLAN_EID_EXT_EHT_OPERATION:
134 if (params->mode < IEEE80211_CONN_MODE_EHT)
136 if (ieee80211_eht_oper_size_ok(data, len))
137 elems->eht_operation = data;
140 case WLAN_EID_EXT_EHT_MULTI_LINK:
141 if (params->mode < IEEE80211_CONN_MODE_EHT)
145 if (ieee80211_mle_size_ok(data, len)) {
146 const struct ieee80211_multi_link_elem *mle =
149 switch (le16_get_bits(mle->control,
150 IEEE80211_ML_CONTROL_TYPE)) {
151 case IEEE80211_ML_CONTROL_TYPE_BASIC:
152 if (elems_parse->ml_basic_elem) {
153 elems->parse_error |=
154 IEEE80211_PARSE_ERR_DUP_NEST_ML_BASIC;
157 elems_parse->ml_basic_elem = elem;
159 case IEEE80211_ML_CONTROL_TYPE_RECONF:
160 elems_parse->ml_reconf_elem = elem;
167 case WLAN_EID_EXT_BANDWIDTH_INDICATION:
168 if (params->mode < IEEE80211_CONN_MODE_EHT)
170 if (ieee80211_bandwidth_indication_size_ok(data, len))
171 elems->bandwidth_indication = data;
174 case WLAN_EID_EXT_TID_TO_LINK_MAPPING:
175 if (params->mode < IEEE80211_CONN_MODE_EHT)
178 if (ieee80211_tid_to_link_map_size_ok(data, len) &&
179 elems->ttlm_num < ARRAY_SIZE(elems->ttlm)) {
180 elems->ttlm[elems->ttlm_num] = (void *)data;
187 *crc = crc32_be(*crc, (void *)elem, elem->datalen + 2);
191 _ieee802_11_parse_elems_full(struct ieee80211_elems_parse_params *params,
192 struct ieee80211_elems_parse *elems_parse,
193 const struct element *check_inherit)
195 struct ieee802_11_elems *elems = &elems_parse->elems;
196 const struct element *elem;
197 bool calc_crc = params->filter != 0;
198 DECLARE_BITMAP(seen_elems, 256);
199 u32 crc = params->crc;
201 bitmap_zero(seen_elems, 256);
203 for_each_element(elem, params->start, params->len) {
204 const struct element *subelem;
205 u8 elem_parse_failed;
207 u8 elen = elem->datalen;
208 const u8 *pos = elem->data;
211 !cfg80211_is_element_inherited(elem,
217 case WLAN_EID_SUPP_RATES:
218 case WLAN_EID_FH_PARAMS:
219 case WLAN_EID_DS_PARAMS:
220 case WLAN_EID_CF_PARAMS:
222 case WLAN_EID_IBSS_PARAMS:
223 case WLAN_EID_CHALLENGE:
225 case WLAN_EID_ERP_INFO:
226 case WLAN_EID_EXT_SUPP_RATES:
227 case WLAN_EID_HT_CAPABILITY:
228 case WLAN_EID_HT_OPERATION:
229 case WLAN_EID_VHT_CAPABILITY:
230 case WLAN_EID_VHT_OPERATION:
231 case WLAN_EID_MESH_ID:
232 case WLAN_EID_MESH_CONFIG:
233 case WLAN_EID_PEER_MGMT:
238 case WLAN_EID_CHANNEL_SWITCH:
239 case WLAN_EID_EXT_CHANSWITCH_ANN:
240 case WLAN_EID_COUNTRY:
241 case WLAN_EID_PWR_CONSTRAINT:
242 case WLAN_EID_TIMEOUT_INTERVAL:
243 case WLAN_EID_SECONDARY_CHANNEL_OFFSET:
244 case WLAN_EID_WIDE_BW_CHANNEL_SWITCH:
245 case WLAN_EID_CHAN_SWITCH_PARAM:
246 case WLAN_EID_EXT_CAPABILITY:
247 case WLAN_EID_CHAN_SWITCH_TIMING:
248 case WLAN_EID_LINK_ID:
249 case WLAN_EID_BSS_MAX_IDLE_PERIOD:
251 case WLAN_EID_S1G_BCN_COMPAT:
252 case WLAN_EID_S1G_CAPABILITIES:
253 case WLAN_EID_S1G_OPERATION:
254 case WLAN_EID_AID_RESPONSE:
255 case WLAN_EID_S1G_SHORT_BCN_INTERVAL:
257 * not listing WLAN_EID_CHANNEL_SWITCH_WRAPPER -- it seems possible
258 * that if the content gets bigger it might be needed more than once
260 if (test_bit(id, seen_elems)) {
261 elems->parse_error |=
262 IEEE80211_PARSE_ERR_DUP_ELEM;
268 if (calc_crc && id < 64 && (params->filter & (1ULL << id)))
269 crc = crc32_be(crc, pos - 2, elen + 2);
271 elem_parse_failed = 0;
274 case WLAN_EID_LINK_ID:
275 if (elen + 2 < sizeof(struct ieee80211_tdls_lnkie)) {
277 IEEE80211_PARSE_ERR_BAD_ELEM_SIZE;
280 elems->lnk_id = (void *)(pos - 2);
282 case WLAN_EID_CHAN_SWITCH_TIMING:
283 if (elen < sizeof(struct ieee80211_ch_switch_timing)) {
285 IEEE80211_PARSE_ERR_BAD_ELEM_SIZE;
288 elems->ch_sw_timing = (void *)pos;
290 case WLAN_EID_EXT_CAPABILITY:
291 elems->ext_capab = pos;
292 elems->ext_capab_len = elen;
296 elems->ssid_len = elen;
298 case WLAN_EID_SUPP_RATES:
299 elems->supp_rates = pos;
300 elems->supp_rates_len = elen;
302 case WLAN_EID_DS_PARAMS:
304 elems->ds_params = pos;
307 IEEE80211_PARSE_ERR_BAD_ELEM_SIZE;
310 if (elen >= sizeof(struct ieee80211_tim_ie)) {
311 elems->tim = (void *)pos;
312 elems->tim_len = elen;
315 IEEE80211_PARSE_ERR_BAD_ELEM_SIZE;
317 case WLAN_EID_VENDOR_SPECIFIC:
318 if (elen >= 4 && pos[0] == 0x00 && pos[1] == 0x50 &&
320 /* Microsoft OUI (00:50:F2) */
323 crc = crc32_be(crc, pos - 2, elen + 2);
325 if (elen >= 5 && pos[3] == 2) {
326 /* OUI Type 2 - WMM IE */
328 elems->wmm_info = pos;
329 elems->wmm_info_len = elen;
330 } else if (pos[4] == 1) {
331 elems->wmm_param = pos;
332 elems->wmm_param_len = elen;
339 elems->rsn_len = elen;
341 case WLAN_EID_ERP_INFO:
343 elems->erp_info = pos;
346 IEEE80211_PARSE_ERR_BAD_ELEM_SIZE;
348 case WLAN_EID_EXT_SUPP_RATES:
349 elems->ext_supp_rates = pos;
350 elems->ext_supp_rates_len = elen;
352 case WLAN_EID_HT_CAPABILITY:
353 if (params->mode < IEEE80211_CONN_MODE_HT)
355 if (elen >= sizeof(struct ieee80211_ht_cap))
356 elems->ht_cap_elem = (void *)pos;
359 IEEE80211_PARSE_ERR_BAD_ELEM_SIZE;
361 case WLAN_EID_HT_OPERATION:
362 if (params->mode < IEEE80211_CONN_MODE_HT)
364 if (elen >= sizeof(struct ieee80211_ht_operation))
365 elems->ht_operation = (void *)pos;
368 IEEE80211_PARSE_ERR_BAD_ELEM_SIZE;
370 case WLAN_EID_VHT_CAPABILITY:
371 if (params->mode < IEEE80211_CONN_MODE_VHT)
373 if (elen >= sizeof(struct ieee80211_vht_cap))
374 elems->vht_cap_elem = (void *)pos;
377 IEEE80211_PARSE_ERR_BAD_ELEM_SIZE;
379 case WLAN_EID_VHT_OPERATION:
380 if (params->mode < IEEE80211_CONN_MODE_VHT)
382 if (elen >= sizeof(struct ieee80211_vht_operation)) {
383 elems->vht_operation = (void *)pos;
385 crc = crc32_be(crc, pos - 2, elen + 2);
389 IEEE80211_PARSE_ERR_BAD_ELEM_SIZE;
391 case WLAN_EID_OPMODE_NOTIF:
392 if (params->mode < IEEE80211_CONN_MODE_VHT)
395 elems->opmode_notif = pos;
397 crc = crc32_be(crc, pos - 2, elen + 2);
401 IEEE80211_PARSE_ERR_BAD_ELEM_SIZE;
403 case WLAN_EID_MESH_ID:
404 elems->mesh_id = pos;
405 elems->mesh_id_len = elen;
407 case WLAN_EID_MESH_CONFIG:
408 if (elen >= sizeof(struct ieee80211_meshconf_ie))
409 elems->mesh_config = (void *)pos;
412 IEEE80211_PARSE_ERR_BAD_ELEM_SIZE;
414 case WLAN_EID_PEER_MGMT:
415 elems->peering = pos;
416 elems->peering_len = elen;
418 case WLAN_EID_MESH_AWAKE_WINDOW:
420 elems->awake_window = (void *)pos;
424 elems->preq_len = elen;
428 elems->prep_len = elen;
432 elems->perr_len = elen;
435 if (elen >= sizeof(struct ieee80211_rann_ie))
436 elems->rann = (void *)pos;
439 IEEE80211_PARSE_ERR_BAD_ELEM_SIZE;
441 case WLAN_EID_CHANNEL_SWITCH:
442 if (elen != sizeof(struct ieee80211_channel_sw_ie)) {
444 IEEE80211_PARSE_ERR_BAD_ELEM_SIZE;
447 elems->ch_switch_ie = (void *)pos;
449 case WLAN_EID_EXT_CHANSWITCH_ANN:
450 if (elen != sizeof(struct ieee80211_ext_chansw_ie)) {
452 IEEE80211_PARSE_ERR_BAD_ELEM_SIZE;
455 elems->ext_chansw_ie = (void *)pos;
457 case WLAN_EID_SECONDARY_CHANNEL_OFFSET:
458 if (params->mode < IEEE80211_CONN_MODE_HT)
460 if (elen != sizeof(struct ieee80211_sec_chan_offs_ie)) {
462 IEEE80211_PARSE_ERR_BAD_ELEM_SIZE;
465 elems->sec_chan_offs = (void *)pos;
467 case WLAN_EID_CHAN_SWITCH_PARAM:
469 sizeof(*elems->mesh_chansw_params_ie)) {
471 IEEE80211_PARSE_ERR_BAD_ELEM_SIZE;
474 elems->mesh_chansw_params_ie = (void *)pos;
476 case WLAN_EID_WIDE_BW_CHANNEL_SWITCH:
477 if (params->mode < IEEE80211_CONN_MODE_VHT)
480 if (!params->action) {
482 IEEE80211_PARSE_ERR_UNEXPECTED_ELEM;
486 if (elen < sizeof(*elems->wide_bw_chansw_ie)) {
488 IEEE80211_PARSE_ERR_BAD_ELEM_SIZE;
491 elems->wide_bw_chansw_ie = (void *)pos;
493 case WLAN_EID_CHANNEL_SWITCH_WRAPPER:
494 if (params->mode < IEEE80211_CONN_MODE_VHT)
496 if (params->action) {
498 IEEE80211_PARSE_ERR_UNEXPECTED_ELEM;
502 * This is a bit tricky, but as we only care about
503 * a few elements, parse them out manually.
505 subelem = cfg80211_find_elem(WLAN_EID_WIDE_BW_CHANNEL_SWITCH,
508 if (subelem->datalen >= sizeof(*elems->wide_bw_chansw_ie))
509 elems->wide_bw_chansw_ie =
510 (void *)subelem->data;
513 IEEE80211_PARSE_ERR_BAD_ELEM_SIZE;
516 if (params->mode < IEEE80211_CONN_MODE_EHT)
519 subelem = cfg80211_find_ext_elem(WLAN_EID_EXT_BANDWIDTH_INDICATION,
522 const void *edata = subelem->data + 1;
523 u8 edatalen = subelem->datalen - 1;
525 if (ieee80211_bandwidth_indication_size_ok(edata,
527 elems->bandwidth_indication = edata;
530 IEEE80211_PARSE_ERR_BAD_ELEM_SIZE;
533 case WLAN_EID_COUNTRY:
534 elems->country_elem = pos;
535 elems->country_elem_len = elen;
537 case WLAN_EID_PWR_CONSTRAINT:
540 IEEE80211_PARSE_ERR_BAD_ELEM_SIZE;
543 elems->pwr_constr_elem = pos;
545 case WLAN_EID_CISCO_VENDOR_SPECIFIC:
546 /* Lots of different options exist, but we only care
547 * about the Dynamic Transmit Power Control element.
548 * First check for the Cisco OUI, then for the DTPC
553 IEEE80211_PARSE_ERR_BAD_ELEM_SIZE;
557 if (pos[0] != 0x00 || pos[1] != 0x40 ||
558 pos[2] != 0x96 || pos[3] != 0x00)
563 IEEE80211_PARSE_ERR_BAD_ELEM_SIZE;
568 crc = crc32_be(crc, pos - 2, elen + 2);
570 elems->cisco_dtpc_elem = pos;
572 case WLAN_EID_ADDBA_EXT:
573 if (elen < sizeof(struct ieee80211_addba_ext_ie)) {
575 IEEE80211_PARSE_ERR_BAD_ELEM_SIZE;
578 elems->addba_ext_ie = (void *)pos;
580 case WLAN_EID_TIMEOUT_INTERVAL:
581 if (elen >= sizeof(struct ieee80211_timeout_interval_ie))
582 elems->timeout_int = (void *)pos;
585 IEEE80211_PARSE_ERR_BAD_ELEM_SIZE;
587 case WLAN_EID_BSS_MAX_IDLE_PERIOD:
588 if (elen >= sizeof(*elems->max_idle_period_ie))
589 elems->max_idle_period_ie = (void *)pos;
593 elems->rsnx_len = elen;
595 case WLAN_EID_TX_POWER_ENVELOPE:
597 elen > sizeof(struct ieee80211_tx_pwr_env))
600 if (elems->tx_pwr_env_num >= ARRAY_SIZE(elems->tx_pwr_env))
603 elems->tx_pwr_env[elems->tx_pwr_env_num] = (void *)pos;
604 elems->tx_pwr_env_len[elems->tx_pwr_env_num] = elen;
605 elems->tx_pwr_env_num++;
607 case WLAN_EID_EXTENSION:
608 ieee80211_parse_extension_element(calc_crc ?
613 case WLAN_EID_S1G_CAPABILITIES:
614 if (params->mode != IEEE80211_CONN_MODE_S1G)
616 if (elen >= sizeof(*elems->s1g_capab))
617 elems->s1g_capab = (void *)pos;
620 IEEE80211_PARSE_ERR_BAD_ELEM_SIZE;
622 case WLAN_EID_S1G_OPERATION:
623 if (params->mode != IEEE80211_CONN_MODE_S1G)
625 if (elen == sizeof(*elems->s1g_oper))
626 elems->s1g_oper = (void *)pos;
629 IEEE80211_PARSE_ERR_BAD_ELEM_SIZE;
631 case WLAN_EID_S1G_BCN_COMPAT:
632 if (params->mode != IEEE80211_CONN_MODE_S1G)
634 if (elen == sizeof(*elems->s1g_bcn_compat))
635 elems->s1g_bcn_compat = (void *)pos;
638 IEEE80211_PARSE_ERR_BAD_ELEM_SIZE;
640 case WLAN_EID_AID_RESPONSE:
641 if (params->mode != IEEE80211_CONN_MODE_S1G)
643 if (elen == sizeof(struct ieee80211_aid_response_ie))
644 elems->aid_resp = (void *)pos;
647 IEEE80211_PARSE_ERR_BAD_ELEM_SIZE;
653 if (elem_parse_failed)
654 elems->parse_error |= elem_parse_failed;
656 __set_bit(id, seen_elems);
659 if (!for_each_element_completed(elem, params->start, params->len))
660 elems->parse_error |= IEEE80211_PARSE_ERR_INVALID_END;
665 static size_t ieee802_11_find_bssid_profile(const u8 *start, size_t len,
666 struct ieee802_11_elems *elems,
667 struct cfg80211_bss *bss,
668 u8 *nontransmitted_profile)
670 const struct element *elem, *sub;
671 size_t profile_len = 0;
674 if (!bss || !bss->transmitted_bss)
677 for_each_element_id(elem, WLAN_EID_MULTIPLE_BSSID, start, len) {
678 if (elem->datalen < 2)
680 if (elem->data[0] < 1 || elem->data[0] > 8)
683 for_each_element(sub, elem->data + 1, elem->datalen - 1) {
684 u8 new_bssid[ETH_ALEN];
687 if (sub->id != 0 || sub->datalen < 4) {
688 /* not a valid BSS profile */
692 if (sub->data[0] != WLAN_EID_NON_TX_BSSID_CAP ||
694 /* The first element of the
695 * Nontransmitted BSSID Profile is not
696 * the Nontransmitted BSSID Capability
702 memset(nontransmitted_profile, 0, len);
703 profile_len = cfg80211_merge_profile(start, len,
706 nontransmitted_profile,
709 /* found a Nontransmitted BSSID Profile */
710 index = cfg80211_find_ie(WLAN_EID_MULTI_BSSID_IDX,
711 nontransmitted_profile,
713 if (!index || index[1] < 1 || index[2] == 0) {
714 /* Invalid MBSSID Index element */
718 cfg80211_gen_new_bssid(bss->transmitted_bss->bssid,
722 if (ether_addr_equal(new_bssid, bss->bssid)) {
724 elems->bssid_index_len = index[1];
725 elems->bssid_index = (void *)&index[2];
731 return found ? profile_len : 0;
735 ieee80211_mle_get_sta_prof(struct ieee80211_elems_parse *elems_parse,
738 struct ieee802_11_elems *elems = &elems_parse->elems;
739 const struct ieee80211_multi_link_elem *ml = elems->ml_basic;
740 ssize_t ml_len = elems->ml_basic_len;
741 const struct element *sub;
743 for_each_mle_subelement(sub, (u8 *)ml, ml_len) {
744 struct ieee80211_mle_per_sta_profile *prof = (void *)sub->data;
745 ssize_t sta_prof_len;
748 if (sub->id != IEEE80211_MLE_SUBELEM_PER_STA_PROFILE)
751 if (!ieee80211_mle_basic_sta_prof_size_ok(sub->data,
755 control = le16_to_cpu(prof->control);
757 if (link_id != u16_get_bits(control,
758 IEEE80211_MLE_STA_CONTROL_LINK_ID))
761 if (!(control & IEEE80211_MLE_STA_CONTROL_COMPLETE_PROFILE))
764 /* the sub element can be fragmented */
766 cfg80211_defragment_element(sub,
768 elems_parse->scratch_pos,
769 elems_parse->scratch +
770 elems_parse->scratch_len -
771 elems_parse->scratch_pos,
772 IEEE80211_MLE_SUBELEM_FRAGMENT);
774 if (sta_prof_len < 0)
777 elems->prof = (void *)elems_parse->scratch_pos;
778 elems->sta_prof_len = sta_prof_len;
779 elems_parse->scratch_pos += sta_prof_len;
785 static void ieee80211_mle_parse_link(struct ieee80211_elems_parse *elems_parse,
786 struct ieee80211_elems_parse_params *params)
788 struct ieee802_11_elems *elems = &elems_parse->elems;
789 struct ieee80211_mle_per_sta_profile *prof;
790 struct ieee80211_elems_parse_params sub = {
791 .mode = params->mode,
792 .action = params->action,
793 .from_ap = params->from_ap,
796 ssize_t ml_len = elems->ml_basic_len;
797 const struct element *non_inherit = NULL;
800 ml_len = cfg80211_defragment_element(elems_parse->ml_basic_elem,
803 elems_parse->scratch_pos,
804 elems_parse->scratch +
805 elems_parse->scratch_len -
806 elems_parse->scratch_pos,
812 elems->ml_basic = (const void *)elems_parse->scratch_pos;
813 elems->ml_basic_len = ml_len;
814 elems_parse->scratch_pos += ml_len;
816 if (params->link_id == -1)
819 ieee80211_mle_get_sta_prof(elems_parse, params->link_id);
825 /* check if we have the 4 bytes for the fixed part in assoc response */
826 if (elems->sta_prof_len < sizeof(*prof) + prof->sta_info_len - 1 + 4) {
828 elems->sta_prof_len = 0;
833 * Skip the capability information and the status code that are expected
834 * as part of the station profile in association response frames. Note
835 * the -1 is because the 'sta_info_len' is accounted to as part of the
836 * per-STA profile, but not part of the 'u8 variable[]' portion.
838 sub.start = prof->variable + prof->sta_info_len - 1 + 4;
839 end = (const u8 *)prof + elems->sta_prof_len;
840 sub.len = end - sub.start;
842 non_inherit = cfg80211_find_ext_elem(WLAN_EID_EXT_NON_INHERITANCE,
844 _ieee802_11_parse_elems_full(&sub, elems_parse, non_inherit);
848 ieee80211_mle_defrag_reconf(struct ieee80211_elems_parse *elems_parse)
850 struct ieee802_11_elems *elems = &elems_parse->elems;
853 ml_len = cfg80211_defragment_element(elems_parse->ml_reconf_elem,
856 elems_parse->scratch_pos,
857 elems_parse->scratch +
858 elems_parse->scratch_len -
859 elems_parse->scratch_pos,
863 elems->ml_reconf = (void *)elems_parse->scratch_pos;
864 elems->ml_reconf_len = ml_len;
865 elems_parse->scratch_pos += ml_len;
868 struct ieee802_11_elems *
869 ieee802_11_parse_elems_full(struct ieee80211_elems_parse_params *params)
871 struct ieee80211_elems_parse *elems_parse;
872 struct ieee802_11_elems *elems;
873 const struct element *non_inherit = NULL;
874 u8 *nontransmitted_profile;
875 int nontransmitted_profile_len = 0;
876 size_t scratch_len = 3 * params->len;
878 BUILD_BUG_ON(offsetof(typeof(*elems_parse), elems) != 0);
880 elems_parse = kzalloc(struct_size(elems_parse, scratch, scratch_len),
885 elems_parse->scratch_len = scratch_len;
886 elems_parse->scratch_pos = elems_parse->scratch;
888 elems = &elems_parse->elems;
889 elems->ie_start = params->start;
890 elems->total_len = params->len;
892 nontransmitted_profile = elems_parse->scratch_pos;
893 nontransmitted_profile_len =
894 ieee802_11_find_bssid_profile(params->start, params->len,
896 nontransmitted_profile);
897 elems_parse->scratch_pos += nontransmitted_profile_len;
898 non_inherit = cfg80211_find_ext_elem(WLAN_EID_EXT_NON_INHERITANCE,
899 nontransmitted_profile,
900 nontransmitted_profile_len);
902 elems->crc = _ieee802_11_parse_elems_full(params, elems_parse,
905 /* Override with nontransmitted profile, if found */
906 if (nontransmitted_profile_len) {
907 struct ieee80211_elems_parse_params sub = {
908 .mode = params->mode,
909 .start = nontransmitted_profile,
910 .len = nontransmitted_profile_len,
911 .action = params->action,
912 .link_id = params->link_id,
915 _ieee802_11_parse_elems_full(&sub, elems_parse, NULL);
918 ieee80211_mle_parse_link(elems_parse, params);
920 ieee80211_mle_defrag_reconf(elems_parse);
922 if (elems->tim && !elems->parse_error) {
923 const struct ieee80211_tim_ie *tim_ie = elems->tim;
925 elems->dtim_period = tim_ie->dtim_period;
926 elems->dtim_count = tim_ie->dtim_count;
929 /* Override DTIM period and count if needed */
930 if (elems->bssid_index &&
931 elems->bssid_index_len >=
932 offsetofend(struct ieee80211_bssid_index, dtim_period))
933 elems->dtim_period = elems->bssid_index->dtim_period;
935 if (elems->bssid_index &&
936 elems->bssid_index_len >=
937 offsetofend(struct ieee80211_bssid_index, dtim_count))
938 elems->dtim_count = elems->bssid_index->dtim_count;
942 EXPORT_SYMBOL_IF_KUNIT(ieee802_11_parse_elems_full);
944 int ieee80211_parse_bitrates(enum nl80211_chan_width width,
945 const struct ieee80211_supported_band *sband,
946 const u8 *srates, int srates_len, u32 *rates)
948 u32 rate_flags = ieee80211_chanwidth_rate_flags(width);
949 struct ieee80211_rate *br;
950 int brate, rate, i, j, count = 0;
954 for (i = 0; i < srates_len; i++) {
955 rate = srates[i] & 0x7f;
957 for (j = 0; j < sband->n_bitrates; j++) {
958 br = &sband->bitrates[j];
959 if ((rate_flags & br->flags) != rate_flags)
962 brate = DIV_ROUND_UP(br->bitrate, 5);