xref: /wlan-dirver/qca-wifi-host-cmn/umac/scan/dispatcher/src/wlan_scan_utils_api.c (revision 22f89679c1f1aeaf62e34eaee8c5ca99467bd241)
1 /*
2  * Copyright (c) 2017-2021 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for
6  * any purpose with or without fee is hereby granted, provided that the
7  * above copyright notice and this permission notice appear in all
8  * copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 /*
21  * DOC: Defines scan utility functions
22  */
23 
24 #include <wlan_cmn.h>
25 #include <wlan_scan_ucfg_api.h>
26 #include <wlan_scan_utils_api.h>
27 #include <../../core/src/wlan_scan_cache_db.h>
28 #include <../../core/src/wlan_scan_main.h>
29 #include <wlan_reg_services_api.h>
30 #if defined(WLAN_SAE_SINGLE_PMK) && defined(WLAN_FEATURE_ROAM_OFFLOAD)
31 #include <wlan_mlme_api.h>
32 #endif
33 #ifdef WLAN_FEATURE_11BE_MLO
34 #include <wlan_utility.h>
35 #include "wlan_mlo_mgr_public_structs.h"
36 #include <utils_mlo.h>
37 #endif
38 #include "wlan_psoc_mlme_api.h"
39 #include "reg_services_public_struct.h"
40 
41 #define MAX_IE_LEN 1024
42 #define SHORT_SSID_LEN 4
43 #define NEIGHBOR_AP_LEN 1
44 #define BSS_PARAMS_LEN 1
45 
46 const char*
47 util_scan_get_ev_type_name(enum scan_event_type type)
48 {
49 	static const char * const event_name[] = {
50 		[SCAN_EVENT_TYPE_STARTED] = "STARTED",
51 		[SCAN_EVENT_TYPE_COMPLETED] = "COMPLETED",
52 		[SCAN_EVENT_TYPE_BSS_CHANNEL] = "HOME_CHANNEL",
53 		[SCAN_EVENT_TYPE_FOREIGN_CHANNEL] = "FOREIGN_CHANNEL",
54 		[SCAN_EVENT_TYPE_DEQUEUED] = "DEQUEUED",
55 		[SCAN_EVENT_TYPE_PREEMPTED] = "PREEMPTED",
56 		[SCAN_EVENT_TYPE_START_FAILED] = "START_FAILED",
57 		[SCAN_EVENT_TYPE_RESTARTED] = "RESTARTED",
58 		[SCAN_EVENT_TYPE_FOREIGN_CHANNEL_EXIT] = "FOREIGN_CHANNEL_EXIT",
59 		[SCAN_EVENT_TYPE_SUSPENDED] = "SUSPENDED",
60 		[SCAN_EVENT_TYPE_RESUMED] = "RESUMED",
61 		[SCAN_EVENT_TYPE_NLO_COMPLETE] = "NLO_COMPLETE",
62 		[SCAN_EVENT_TYPE_NLO_MATCH] = "NLO_MATCH",
63 		[SCAN_EVENT_TYPE_INVALID] = "INVALID",
64 		[SCAN_EVENT_TYPE_GPIO_TIMEOUT] = "GPIO_TIMEOUT",
65 		[SCAN_EVENT_TYPE_RADIO_MEASUREMENT_START] =
66 			"RADIO_MEASUREMENT_START",
67 		[SCAN_EVENT_TYPE_RADIO_MEASUREMENT_END] =
68 			"RADIO_MEASUREMENT_END",
69 		[SCAN_EVENT_TYPE_BSSID_MATCH] = "BSSID_MATCH",
70 		[SCAN_EVENT_TYPE_FOREIGN_CHANNEL_GET_NF] =
71 			"FOREIGN_CHANNEL_GET_NF",
72 	};
73 
74 	if (type >= SCAN_EVENT_TYPE_MAX)
75 		return "UNKNOWN";
76 
77 	return event_name[type];
78 }
79 
80 
81 const char*
82 util_scan_get_ev_reason_name(enum scan_completion_reason reason)
83 {
84 	static const char * const reason_name[] = {
85 		[SCAN_REASON_NONE] = "NONE",
86 		[SCAN_REASON_COMPLETED] = "COMPLETED",
87 		[SCAN_REASON_CANCELLED] = "CANCELLED",
88 		[SCAN_REASON_PREEMPTED] = "PREEMPTED",
89 		[SCAN_REASON_TIMEDOUT] = "TIMEDOUT",
90 		[SCAN_REASON_INTERNAL_FAILURE] = "INTERNAL_FAILURE",
91 		[SCAN_REASON_SUSPENDED] = "SUSPENDED",
92 		[SCAN_REASON_RUN_FAILED] = "RUN_FAILED",
93 		[SCAN_REASON_TERMINATION_FUNCTION] = "TERMINATION_FUNCTION",
94 		[SCAN_REASON_MAX_OFFCHAN_RETRIES] = "MAX_OFFCHAN_RETRIES",
95 		[SCAN_REASON_DFS_VIOLATION] = "DFS_NOL_VIOLATION",
96 	};
97 
98 	if (reason >= SCAN_REASON_MAX)
99 		return "UNKNOWN";
100 
101 	return reason_name[reason];
102 }
103 
104 qdf_time_t
105 util_get_last_scan_time(struct wlan_objmgr_vdev *vdev)
106 {
107 	uint8_t pdev_id;
108 	struct wlan_scan_obj *scan_obj;
109 
110 	if (!vdev) {
111 		scm_warn("null vdev");
112 		QDF_ASSERT(0);
113 		return 0;
114 	}
115 	pdev_id = wlan_scan_vdev_get_pdev_id(vdev);
116 	scan_obj = wlan_vdev_get_scan_obj(vdev);
117 
118 	if (scan_obj)
119 		return scan_obj->pdev_info[pdev_id].last_scan_time;
120 	else
121 		return 0;
122 }
123 
124 enum wlan_band util_scan_scm_freq_to_band(uint16_t freq)
125 {
126 	if (WLAN_REG_IS_24GHZ_CH_FREQ(freq))
127 		return WLAN_BAND_2_4_GHZ;
128 
129 	return WLAN_BAND_5_GHZ;
130 }
131 
132 bool util_is_scan_entry_match(
133 	struct scan_cache_entry *entry1,
134 	struct scan_cache_entry *entry2)
135 {
136 
137 	if (entry1->cap_info.wlan_caps.ess !=
138 	   entry2->cap_info.wlan_caps.ess)
139 		return false;
140 
141 	if (entry1->cap_info.wlan_caps.ess &&
142 	   !qdf_mem_cmp(entry1->bssid.bytes,
143 	   entry2->bssid.bytes, QDF_MAC_ADDR_SIZE)) {
144 		/* Check for BSS */
145 		if (util_is_ssid_match(&entry1->ssid, &entry2->ssid) ||
146 		    util_scan_is_null_ssid(&entry1->ssid) ||
147 		    util_scan_is_null_ssid(&entry2->ssid))
148 			return true;
149 	} else if (entry1->cap_info.wlan_caps.ibss &&
150 	   (entry1->channel.chan_freq ==
151 	   entry2->channel.chan_freq)) {
152 		/*
153 		 * Same channel cannot have same SSID for
154 		 * different IBSS, so no need to check BSSID
155 		 */
156 		if (util_is_ssid_match(
157 		   &entry1->ssid, &entry2->ssid))
158 			return true;
159 	} else if (!entry1->cap_info.wlan_caps.ibss &&
160 	   !entry1->cap_info.wlan_caps.ess &&
161 	   !qdf_mem_cmp(entry1->bssid.bytes,
162 	   entry2->bssid.bytes, QDF_MAC_ADDR_SIZE)) {
163 		/* In case of P2P devices, ess and ibss will be set to zero */
164 		return true;
165 	}
166 
167 	return false;
168 }
169 
170 static bool util_is_pureg_rate(uint8_t *rates, uint8_t nrates)
171 {
172 	static const uint8_t g_rates[] = {12, 18, 24, 36, 48, 72, 96, 108};
173 	bool pureg = false;
174 	uint8_t i, j;
175 
176 	for (i = 0; i < nrates; i++) {
177 		for (j = 0; j < QDF_ARRAY_SIZE(g_rates); j++) {
178 			if (WLAN_RV(rates[i]) == g_rates[j]) {
179 				pureg = true;
180 				break;
181 			}
182 		}
183 		if (pureg)
184 			break;
185 	}
186 
187 	return pureg;
188 }
189 
190 #ifdef WLAN_FEATURE_11BE
191 static enum wlan_phymode
192 util_scan_get_phymode_11be(struct wlan_objmgr_pdev *pdev,
193 			   struct scan_cache_entry *scan_params,
194 			   enum wlan_phymode phymode,
195 			   uint8_t band_mask)
196 {
197 	struct wlan_ie_ehtops *eht_ops;
198 	uint8_t width;
199 
200 	eht_ops = (struct wlan_ie_ehtops *)util_scan_entry_ehtop(scan_params);
201 	if (!util_scan_entry_ehtcap(scan_params) || !eht_ops)
202 		return phymode;
203 
204 	if (QDF_GET_BITS(eht_ops->ehtop_param,
205 			 EHTOP_INFO_PRESENT_IDX, EHTOP_INFO_PRESENT_BITS)) {
206 		width = QDF_GET_BITS(eht_ops->control,
207 				     EHTOP_INFO_CHAN_WIDTH_IDX,
208 				     EHTOP_INFO_CHAN_WIDTH_BITS);
209 		switch (width) {
210 		case WLAN_EHT_CHWIDTH_20:
211 			phymode = WLAN_PHYMODE_11BEA_EHT20;
212 			break;
213 		case WLAN_EHT_CHWIDTH_40:
214 			phymode = WLAN_PHYMODE_11BEA_EHT40;
215 			break;
216 		case WLAN_EHT_CHWIDTH_80:
217 			phymode = WLAN_PHYMODE_11BEA_EHT80;
218 			break;
219 		case WLAN_EHT_CHWIDTH_160:
220 			phymode = WLAN_PHYMODE_11BEA_EHT160;
221 			break;
222 		case WLAN_EHT_CHWIDTH_320:
223 			phymode = WLAN_PHYMODE_11BEA_EHT320;
224 			break;
225 		default:
226 			scm_debug("Invalid eht_ops width: %d", width);
227 			phymode = WLAN_PHYMODE_11BEA_EHT20;
228 			break;
229 		}
230 	} else {
231 		switch (phymode) {
232 		case WLAN_PHYMODE_11AXA_HE20:
233 			phymode = WLAN_PHYMODE_11BEA_EHT20;
234 			break;
235 		case WLAN_PHYMODE_11AXG_HE20:
236 			phymode = WLAN_PHYMODE_11BEG_EHT20;
237 			break;
238 		case WLAN_PHYMODE_11AXA_HE40:
239 			phymode = WLAN_PHYMODE_11BEA_EHT40;
240 			break;
241 		case WLAN_PHYMODE_11AXG_HE40:
242 			phymode = WLAN_PHYMODE_11BEG_EHT40;
243 			break;
244 		case WLAN_PHYMODE_11AXA_HE80:
245 			phymode = WLAN_PHYMODE_11BEA_EHT80;
246 			break;
247 		case WLAN_PHYMODE_11AXA_HE160:
248 			phymode = WLAN_PHYMODE_11BEA_EHT160;
249 			break;
250 		default:
251 			break;
252 		}
253 	}
254 
255 	if (QDF_GET_BITS(eht_ops->ehtop_param,
256 			 EHTOP_INFO_PRESENT_IDX, EHTOP_INFO_PRESENT_BITS)) {
257 		scan_params->channel.cfreq0 =
258 			wlan_reg_chan_band_to_freq(pdev,
259 						   eht_ops->ccfs0,
260 						   band_mask);
261 		scan_params->channel.cfreq1 =
262 			wlan_reg_chan_band_to_freq(pdev,
263 						   eht_ops->ccfs1,
264 						   band_mask);
265 	}
266 
267 	if (QDF_GET_BITS(eht_ops->ehtop_param,
268 			 EHTOP_PARAM_DISABLED_SC_BITMAP_PRESENT_IDX,
269 			 EHTOP_PARAM_DISABLED_SC_BITMAP_PRESENT_BITS)) {
270 		scan_params->channel.puncture_bitmap =
271 			QDF_GET_BITS(eht_ops->disabled_sub_chan_bitmap[0],
272 				     0, 8);
273 		scan_params->channel.puncture_bitmap |=
274 			QDF_GET_BITS(eht_ops->disabled_sub_chan_bitmap[1],
275 				     0, 8) << 8;
276 	} else {
277 		scan_params->channel.puncture_bitmap = 0;
278 	}
279 
280 	return phymode;
281 }
282 #else
283 static enum wlan_phymode
284 util_scan_get_phymode_11be(struct wlan_objmgr_pdev *pdev,
285 			   struct scan_cache_entry *scan_params,
286 			   enum wlan_phymode phymode,
287 			   uint8_t band_mask)
288 {
289 	return phymode;
290 }
291 #endif
292 
293 #ifdef CONFIG_BAND_6GHZ
294 static struct he_oper_6g_param *util_scan_get_he_6g_params(uint8_t *he_ops)
295 {
296 	uint8_t len;
297 	uint32_t he_oper_params;
298 
299 	if (!he_ops)
300 		return NULL;
301 
302 	len = he_ops[1];
303 	he_ops += sizeof(struct ie_header);
304 
305 	if (len < WLAN_HEOP_FIXED_PARAM_LENGTH)
306 		return NULL;
307 
308 	/* element id extension */
309 	he_ops++;
310 	len--;
311 
312 	he_oper_params = LE_READ_4(he_ops);
313 	if (!(he_oper_params & WLAN_HEOP_6GHZ_INFO_PRESENT_MASK))
314 		return NULL;
315 
316 	/* fixed params - element id extension */
317 	he_ops += WLAN_HEOP_FIXED_PARAM_LENGTH - 1;
318 	len -= WLAN_HEOP_FIXED_PARAM_LENGTH - 1;
319 
320 	if (!len)
321 		return NULL;
322 
323 	/* vht oper params */
324 	if (he_oper_params & WLAN_HEOP_VHTOP_PRESENT_MASK) {
325 		if (len < WLAN_HEOP_VHTOP_LENGTH)
326 			return NULL;
327 		he_ops += WLAN_HEOP_VHTOP_LENGTH;
328 		len -= WLAN_HEOP_VHTOP_LENGTH;
329 	}
330 
331 	if (!len)
332 		return NULL;
333 
334 	if (he_oper_params & WLAN_HEOP_CO_LOCATED_BSS_MASK) {
335 		he_ops += WLAN_HEOP_CO_LOCATED_BSS_LENGTH;
336 		len -= WLAN_HEOP_CO_LOCATED_BSS_LENGTH;
337 	}
338 
339 	if (len < sizeof(struct he_oper_6g_param))
340 		return NULL;
341 
342 	return (struct he_oper_6g_param *)he_ops;
343 }
344 
345 #ifdef WLAN_FEATURE_11BE
346 /*
347  * util_scan_is_out_of_band_leak_eht() - Check if eht beacon out of BSS BW
348  * @pdev: pointer to pdev.
349  * @scan_params: scan entry generated by beacon/probe rsp
350  * @band_mask: band mask of frequency beacon/probe rsp received
351  * @current_freq: frequency beacon/probe rsp received
352  *
353  * 1. If BSS BW <= 80MHz
354  * If Absolute value of (Current Channel Channel Center Frequency Segment 0) <=
355  * BSS BW/2 then eht beacon in BSS operating BW
356  * else eht beacon out of BSS operating BW
357  *
358  * 2. If BSS BW > 80MHz
359  * If Absolute value of (Current Channel Channel Center Frequency Segment 1) <=
360  * BSS BW/2 then eht beacon in BSS operating BW
361  * else eht beacon out of BSS operating BW
362  *
363  * Return: bool, whether eht beacon out of BSS operating BW
364  */
365 static bool
366 util_scan_is_out_of_band_leak_eht(struct wlan_objmgr_pdev *pdev,
367 				  struct scan_cache_entry *scan_params,
368 				  uint8_t band_mask,
369 				  qdf_freq_t current_freq)
370 {
371 	struct wlan_ie_ehtops *eht_ops;
372 	uint8_t ch_width;
373 	uint32_t bw;
374 	uint32_t freq_diff;
375 	qdf_freq_t freq_seg0;
376 	qdf_freq_t freq_seg1;
377 
378 	eht_ops = (struct wlan_ie_ehtops *)util_scan_entry_ehtop(scan_params);
379 	if (!util_scan_entry_ehtcap(scan_params) || !eht_ops)
380 		return false;
381 
382 	if (!QDF_GET_BITS(eht_ops->ehtop_param,
383 			  EHTOP_INFO_PRESENT_IDX, EHTOP_INFO_PRESENT_BITS))
384 		return false;
385 
386 	ch_width = QDF_GET_BITS(eht_ops->control,
387 				EHTOP_INFO_CHAN_WIDTH_IDX,
388 				EHTOP_INFO_CHAN_WIDTH_BITS);
389 	freq_seg0 = wlan_reg_chan_band_to_freq(pdev, eht_ops->ccfs0,
390 					       band_mask);
391 	freq_seg1 = wlan_reg_chan_band_to_freq(pdev, eht_ops->ccfs1,
392 					       band_mask);
393 	if (ch_width == WLAN_EHT_CHWIDTH_320)
394 		bw = BW_320_MHZ;
395 	else if (ch_width == WLAN_EHT_CHWIDTH_160)
396 		bw = BW_160_MHZ;
397 	else if (ch_width == WLAN_EHT_CHWIDTH_80)
398 		bw = BW_80_MHZ;
399 	else  if (ch_width == WLAN_EHT_CHWIDTH_40)
400 		bw = BW_40_MHZ;
401 	else  if (ch_width == WLAN_EHT_CHWIDTH_20)
402 		bw = BW_20_MHZ;
403 	else
404 		bw = BW_20_MHZ;
405 
406 	if (bw <= BW_80_MHZ)
407 		freq_diff = abs(freq_seg0 - current_freq);
408 	else
409 		freq_diff = abs(freq_seg1 - current_freq);
410 	if (freq_diff <= bw / 2)
411 		return false;
412 
413 	scm_debug("Leaked freq:%u ch width:%u freq0:%u freq1:%u",
414 		  current_freq, bw, freq_seg0, freq_seg1);
415 	return true;
416 }
417 #else
418 static bool
419 util_scan_is_out_of_band_leak_eht(struct wlan_objmgr_pdev *pdev,
420 				  struct scan_cache_entry *scan_params,
421 				  uint8_t band_mask,
422 				  qdf_freq_t current_freq)
423 {
424 	return false;
425 }
426 #endif
427 
428 /*
429  * util_scan_is_out_of_band_leak_he() - Check if HE beacon out of BSS BW
430  * @pdev: pointer to pdev.
431  * @he_6g_params: HE 6 GHz params
432  * @band_mask: band mask of frequency beacon/probe rsp received
433  * @current_freq: frequency beacon/probe rsp received
434  *
435  * 1. If BSS BW <= 80MHz
436  * If Absolute value of (Current Channel Channel Center Frequency Segment 0) <=
437  * BSS BW/2 then HE beacon in BSS operating BW
438  *
439  * 2. If BSS BW is 160MHz
440  * If Absolute value of (Current Channel Channel Center Frequency Segment 1) <=
441  * BSS BW/2 then HE beacon in BSS operating BW
442  *
443  * 3. If BSS BW is 80+80MHz
444  * If absolute value of (Current Channel - Channel Center Frequency Segment 0)
445  * <= 40 or absolute value of (Current Channel - Channel Center Frequency
446  *  Segment 1) <= 40, then HE beacon in BSS operating BW
447  *
448  * Return: bool, whether HE beacon out of BSS operating BW
449  */
450 static bool
451 util_scan_is_out_of_band_leak_he(struct wlan_objmgr_pdev *pdev,
452 				 struct he_oper_6g_param *he_6g_params,
453 				 uint8_t band_mask,
454 				 qdf_freq_t current_freq)
455 {
456 	uint8_t ch_width;
457 	uint32_t bw;
458 	uint32_t freq_diff;
459 	qdf_freq_t freq_seg0;
460 	qdf_freq_t freq_seg1;
461 
462 	ch_width = he_6g_params->width;
463 	freq_seg0 = wlan_reg_chan_band_to_freq(pdev,
464 					       he_6g_params->chan_freq_seg0,
465 					       band_mask);
466 	freq_seg1 = wlan_reg_chan_band_to_freq(pdev,
467 					       he_6g_params->chan_freq_seg1,
468 					       band_mask);
469 	if (ch_width == WLAN_HE_6GHZ_CHWIDTH_160_80_80)
470 		bw = BW_160_MHZ;
471 	else if (ch_width == WLAN_HE_6GHZ_CHWIDTH_80)
472 		bw = BW_80_MHZ;
473 	else  if (ch_width == WLAN_HE_6GHZ_CHWIDTH_40)
474 		bw = BW_40_MHZ;
475 	else  if (ch_width == WLAN_HE_6GHZ_CHWIDTH_20)
476 		bw = BW_20_MHZ;
477 	else
478 		bw = BW_20_MHZ;
479 
480 	if (bw <= BW_80_MHZ) {
481 		freq_diff = abs(freq_seg0 - current_freq);
482 		if (freq_diff <= bw / 2)
483 			return false;
484 	} else if (WLAN_IS_HE160(he_6g_params)) {
485 		freq_diff = abs(freq_seg1 - current_freq);
486 		if (freq_diff <= bw / 2)
487 			return false;
488 	} else if (WLAN_IS_HE80_80(he_6g_params)) {
489 		freq_diff = abs(freq_seg0 - current_freq);
490 		if (freq_diff <= BW_40_MHZ)
491 			return false;
492 		freq_diff = abs(freq_seg1 - current_freq);
493 		if (freq_diff <= BW_40_MHZ)
494 			return false;
495 	}
496 
497 	scm_debug("Leaked freq:%u ch width:%u freq0:%u freq1:%u",
498 		  current_freq, bw, freq_seg0, freq_seg1);
499 
500 	return true;
501 }
502 
503 /*
504  * util_scan_get_chan_from_he_6g_params() - Get chan info from 6 GHz param
505  * @pdev: pointer to pdev.
506  * @scan_params: scan entry generated by beacon/probe rsp
507  * @chan_freq: output parameter, primary freq from 6 GHz he params
508  * @is_6g_dup_bcon: output parameter, bool, if false, invalid 6g duplicated
509 	beacon out of BSS operating BW or not duplicated beacon, can drop if
510 	channel mismatch
511  * @band_mask: band mask of frequency beacon/probe rsp received
512  * @current_freq: frequency beacon/probe rsp received
513  *
514  * Return: QDF_STATUS
515  */
516 static QDF_STATUS
517 util_scan_get_chan_from_he_6g_params(struct wlan_objmgr_pdev *pdev,
518 				     struct scan_cache_entry *scan_params,
519 				     qdf_freq_t *chan_freq,
520 				     bool *is_6g_dup_bcon, uint8_t band_mask,
521 				     qdf_freq_t current_freq)
522 {
523 	struct he_oper_6g_param *he_6g_params;
524 	uint8_t *he_ops;
525 	struct wlan_scan_obj *scan_obj;
526 	struct wlan_objmgr_psoc *psoc;
527 	bool is_out_of_band_leak = true;
528 
529 	psoc = wlan_pdev_get_psoc(pdev);
530 	if (!psoc) {
531 		scm_err("psoc is NULL");
532 		return QDF_STATUS_E_INVAL;
533 	}
534 
535 	scan_obj = wlan_psoc_get_scan_obj(psoc);
536 	if (!scan_obj) {
537 		scm_err("scan_obj is NULL");
538 		return QDF_STATUS_E_INVAL;
539 	}
540 
541 	*is_6g_dup_bcon = false;
542 
543 	he_ops = util_scan_entry_heop(scan_params);
544 	if (!util_scan_entry_hecap(scan_params) || !he_ops)
545 		return QDF_STATUS_SUCCESS;
546 
547 	he_6g_params = util_scan_get_he_6g_params(he_ops);
548 	if (!he_6g_params)
549 		return QDF_STATUS_SUCCESS;
550 
551 	*chan_freq = wlan_reg_chan_band_to_freq(pdev,
552 						he_6g_params->primary_channel,
553 						band_mask);
554 	if (scan_obj->drop_bcn_on_invalid_freq &&
555 	    wlan_reg_is_disable_for_pwrmode(pdev, *chan_freq,
556 					    REG_BEST_PWR_MODE)) {
557 		scm_debug_rl(QDF_MAC_ADDR_FMT": Drop as invalid channel %d freq %d in HE 6Ghz params",
558 			     QDF_MAC_ADDR_REF(scan_params->bssid.bytes),
559 			     he_6g_params->primary_channel, *chan_freq);
560 		return QDF_STATUS_E_INVAL;
561 	}
562 
563 	if (!he_6g_params->duplicate_beacon) {
564 		*is_6g_dup_bcon = false;
565 		return QDF_STATUS_SUCCESS;
566 	}
567 	is_out_of_band_leak =
568 		util_scan_is_out_of_band_leak_eht(pdev, scan_params, band_mask,
569 						  current_freq);
570 	if (is_out_of_band_leak) {
571 		*is_6g_dup_bcon = false;
572 		return QDF_STATUS_SUCCESS;
573 	}
574 	is_out_of_band_leak =
575 		util_scan_is_out_of_band_leak_he(pdev, he_6g_params, band_mask,
576 						 current_freq);
577 	if (is_out_of_band_leak) {
578 		*is_6g_dup_bcon = false;
579 		return QDF_STATUS_SUCCESS;
580 	}
581 
582 	*is_6g_dup_bcon = true;
583 
584 	return QDF_STATUS_SUCCESS;
585 }
586 
587 static enum wlan_phymode
588 util_scan_get_phymode_6g(struct wlan_objmgr_pdev *pdev,
589 			 struct scan_cache_entry *scan_params)
590 {
591 	struct he_oper_6g_param *he_6g_params;
592 	enum wlan_phymode phymode = WLAN_PHYMODE_11AXA_HE20;
593 	uint8_t *he_ops;
594 	uint8_t band_mask = BIT(REG_BAND_6G);
595 
596 	he_ops = util_scan_entry_heop(scan_params);
597 	if (!util_scan_entry_hecap(scan_params) || !he_ops)
598 		return phymode;
599 
600 	he_6g_params = util_scan_get_he_6g_params(he_ops);
601 	if (!he_6g_params)
602 		return phymode;
603 
604 	switch (he_6g_params->width) {
605 	case WLAN_HE_6GHZ_CHWIDTH_20:
606 		phymode = WLAN_PHYMODE_11AXA_HE20;
607 		break;
608 	case WLAN_HE_6GHZ_CHWIDTH_40:
609 		phymode = WLAN_PHYMODE_11AXA_HE40;
610 		break;
611 	case WLAN_HE_6GHZ_CHWIDTH_80:
612 		phymode = WLAN_PHYMODE_11AXA_HE80;
613 		break;
614 	case WLAN_HE_6GHZ_CHWIDTH_160_80_80:
615 		if (WLAN_IS_HE80_80(he_6g_params))
616 			phymode = WLAN_PHYMODE_11AXA_HE80_80;
617 		else if (WLAN_IS_HE160(he_6g_params))
618 			phymode = WLAN_PHYMODE_11AXA_HE160;
619 		else
620 			phymode = WLAN_PHYMODE_11AXA_HE80;
621 		break;
622 	default:
623 		scm_err("Invalid he_6g_params width: %d", he_6g_params->width);
624 		phymode = WLAN_PHYMODE_11AXA_HE20;
625 		break;
626 	}
627 
628 	if (he_6g_params->chan_freq_seg0)
629 		scan_params->channel.cfreq0 =
630 			wlan_reg_chan_band_to_freq(pdev,
631 					he_6g_params->chan_freq_seg0,
632 					band_mask);
633 	if (he_6g_params->chan_freq_seg1)
634 		scan_params->channel.cfreq1 =
635 			wlan_reg_chan_band_to_freq(pdev,
636 					he_6g_params->chan_freq_seg1,
637 					band_mask);
638 
639 	phymode = util_scan_get_phymode_11be(pdev, scan_params,
640 					     phymode, band_mask);
641 
642 	return phymode;
643 }
644 
645 uint8_t
646 util_scan_get_6g_oper_channel(uint8_t *he_op_ie)
647 {
648 	struct he_oper_6g_param *he_6g_params;
649 
650 	he_6g_params = util_scan_get_he_6g_params(he_op_ie);
651 	if (!he_6g_params)
652 		return 0;
653 
654 	return he_6g_params->primary_channel;
655 }
656 
657 #else
658 static QDF_STATUS
659 util_scan_get_chan_from_he_6g_params(struct wlan_objmgr_pdev *pdev,
660 				     struct scan_cache_entry *scan_params,
661 				     qdf_freq_t *chan_freq,
662 				     bool *is_6g_dup_bcon,
663 				     uint8_t band_mask,
664 				     qdf_freq_t current_freq)
665 {
666 	return QDF_STATUS_SUCCESS;
667 }
668 static inline enum wlan_phymode
669 util_scan_get_phymode_6g(struct wlan_objmgr_pdev *pdev,
670 			 struct scan_cache_entry *scan_params)
671 {
672 	return WLAN_PHYMODE_AUTO;
673 }
674 #endif
675 
676 static inline
677 uint32_t util_scan_sec_chan_freq_from_htinfo(struct wlan_ie_htinfo_cmn *htinfo,
678 					     uint32_t primary_chan_freq)
679 {
680 	if (htinfo->hi_extchoff == WLAN_HTINFO_EXTOFFSET_ABOVE)
681 		return primary_chan_freq + WLAN_CHAN_SPACING_20MHZ;
682 	else if (htinfo->hi_extchoff == WLAN_HTINFO_EXTOFFSET_BELOW)
683 		return primary_chan_freq - WLAN_CHAN_SPACING_20MHZ;
684 
685 	return 0;
686 }
687 
688 static enum wlan_phymode
689 util_scan_get_phymode_5g(struct wlan_objmgr_pdev *pdev,
690 			 struct scan_cache_entry *scan_params)
691 {
692 	enum wlan_phymode phymode = WLAN_PHYMODE_AUTO;
693 	uint16_t ht_cap = 0;
694 	struct htcap_cmn_ie *htcap;
695 	struct wlan_ie_htinfo_cmn *htinfo;
696 	struct wlan_ie_vhtop *vhtop;
697 	uint8_t band_mask = BIT(REG_BAND_5G);
698 
699 	htcap = (struct htcap_cmn_ie *)
700 		util_scan_entry_htcap(scan_params);
701 	htinfo = (struct wlan_ie_htinfo_cmn *)
702 		util_scan_entry_htinfo(scan_params);
703 	vhtop = (struct wlan_ie_vhtop *)
704 		util_scan_entry_vhtop(scan_params);
705 
706 	if (!(htcap && htinfo))
707 		return WLAN_PHYMODE_11A;
708 
709 	if (htcap)
710 		ht_cap = le16toh(htcap->hc_cap);
711 
712 	if (ht_cap & WLAN_HTCAP_C_CHWIDTH40)
713 		phymode = WLAN_PHYMODE_11NA_HT40;
714 	else
715 		phymode = WLAN_PHYMODE_11NA_HT20;
716 
717 	scan_params->channel.cfreq0 =
718 		util_scan_sec_chan_freq_from_htinfo(htinfo,
719 						scan_params->channel.chan_freq);
720 
721 	if (util_scan_entry_vhtcap(scan_params) && vhtop) {
722 		switch (vhtop->vht_op_chwidth) {
723 		case WLAN_VHTOP_CHWIDTH_2040:
724 			if (ht_cap & WLAN_HTCAP_C_CHWIDTH40)
725 				phymode = WLAN_PHYMODE_11AC_VHT40;
726 			else
727 				phymode = WLAN_PHYMODE_11AC_VHT20;
728 			break;
729 		case WLAN_VHTOP_CHWIDTH_80:
730 			if (WLAN_IS_REVSIG_VHT80_80(vhtop))
731 				phymode = WLAN_PHYMODE_11AC_VHT80_80;
732 			else if (WLAN_IS_REVSIG_VHT160(vhtop))
733 				phymode = WLAN_PHYMODE_11AC_VHT160;
734 			else
735 				phymode = WLAN_PHYMODE_11AC_VHT80;
736 			break;
737 		case WLAN_VHTOP_CHWIDTH_160:
738 			phymode = WLAN_PHYMODE_11AC_VHT160;
739 			break;
740 		case WLAN_VHTOP_CHWIDTH_80_80:
741 			phymode = WLAN_PHYMODE_11AC_VHT80_80;
742 			break;
743 		default:
744 			scm_debug("bad channel: %d",
745 				  vhtop->vht_op_chwidth);
746 			phymode = WLAN_PHYMODE_11AC_VHT20;
747 			break;
748 		}
749 		if (vhtop->vht_op_ch_freq_seg1)
750 			scan_params->channel.cfreq0 =
751 				wlan_reg_chan_band_to_freq(pdev,
752 						vhtop->vht_op_ch_freq_seg1,
753 						band_mask);
754 		if (vhtop->vht_op_ch_freq_seg2)
755 			scan_params->channel.cfreq1 =
756 				wlan_reg_chan_band_to_freq(pdev,
757 						vhtop->vht_op_ch_freq_seg2,
758 						band_mask);
759 	}
760 
761 	if (!util_scan_entry_hecap(scan_params))
762 		return phymode;
763 
764 	/* for 5Ghz Check for HE, only if VHT cap and HE cap are present */
765 	if (!IS_WLAN_PHYMODE_VHT(phymode))
766 		return phymode;
767 
768 	switch (phymode) {
769 	case WLAN_PHYMODE_11AC_VHT20:
770 		phymode = WLAN_PHYMODE_11AXA_HE20;
771 		break;
772 	case WLAN_PHYMODE_11AC_VHT40:
773 		phymode = WLAN_PHYMODE_11AXA_HE40;
774 		break;
775 	case WLAN_PHYMODE_11AC_VHT80:
776 		phymode = WLAN_PHYMODE_11AXA_HE80;
777 		break;
778 	case WLAN_PHYMODE_11AC_VHT160:
779 		phymode = WLAN_PHYMODE_11AXA_HE160;
780 		break;
781 	case WLAN_PHYMODE_11AC_VHT80_80:
782 		phymode = WLAN_PHYMODE_11AXA_HE80_80;
783 		break;
784 	default:
785 		phymode = WLAN_PHYMODE_11AXA_HE20;
786 		break;
787 	}
788 
789 	phymode = util_scan_get_phymode_11be(pdev, scan_params,
790 					     phymode, band_mask);
791 
792 	return phymode;
793 }
794 
795 #ifdef WLAN_FEATURE_11BE
796 static enum wlan_phymode
797 util_scan_get_phymode_2g_11be(struct scan_cache_entry *scan_params,
798 			      enum wlan_phymode  phymode)
799 {
800 	if (!util_scan_entry_ehtcap(scan_params))
801 		return phymode;
802 
803 	if (phymode == WLAN_PHYMODE_11AXG_HE40PLUS)
804 		phymode = WLAN_PHYMODE_11BEG_EHT40PLUS;
805 	else if (phymode == WLAN_PHYMODE_11AXG_HE40MINUS)
806 		phymode = WLAN_PHYMODE_11BEG_EHT40MINUS;
807 	else
808 		phymode = WLAN_PHYMODE_11BEG_EHT20;
809 
810 	return phymode;
811 }
812 #else
813 static enum wlan_phymode
814 util_scan_get_phymode_2g_11be(struct scan_cache_entry *scan_params,
815 			      enum wlan_phymode  phymode)
816 {
817 	return phymode;
818 }
819 #endif
820 
821 static enum wlan_phymode
822 util_scan_get_phymode_2g(struct scan_cache_entry *scan_params)
823 {
824 	enum wlan_phymode phymode = WLAN_PHYMODE_AUTO;
825 	uint16_t ht_cap = 0;
826 	struct htcap_cmn_ie *htcap;
827 	struct wlan_ie_htinfo_cmn *htinfo;
828 	struct wlan_ie_vhtop *vhtop;
829 
830 	htcap = (struct htcap_cmn_ie *)
831 		util_scan_entry_htcap(scan_params);
832 	htinfo = (struct wlan_ie_htinfo_cmn *)
833 		util_scan_entry_htinfo(scan_params);
834 	vhtop = (struct wlan_ie_vhtop *)
835 		util_scan_entry_vhtop(scan_params);
836 
837 	if (htcap)
838 		ht_cap = le16toh(htcap->hc_cap);
839 
840 	if (htcap && htinfo) {
841 		if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) &&
842 		   (htinfo->hi_extchoff == WLAN_HTINFO_EXTOFFSET_ABOVE))
843 			phymode = WLAN_PHYMODE_11NG_HT40PLUS;
844 		else if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) &&
845 		   (htinfo->hi_extchoff == WLAN_HTINFO_EXTOFFSET_BELOW))
846 			phymode = WLAN_PHYMODE_11NG_HT40MINUS;
847 		else
848 			phymode = WLAN_PHYMODE_11NG_HT20;
849 	} else if (util_scan_entry_xrates(scan_params)) {
850 		/* only 11G stations will have more than 8 rates */
851 		phymode = WLAN_PHYMODE_11G;
852 	} else {
853 		/* Some mischievous g-only APs do not set extended rates */
854 		if (util_scan_entry_rates(scan_params)) {
855 			if (util_is_pureg_rate(&scan_params->ie_list.rates[2],
856 			   scan_params->ie_list.rates[1]))
857 				phymode = WLAN_PHYMODE_11G;
858 			else
859 				phymode = WLAN_PHYMODE_11B;
860 		} else {
861 			phymode = WLAN_PHYMODE_11B;
862 		}
863 	}
864 
865 	/* Check for VHT only if HT cap is present */
866 	if (!IS_WLAN_PHYMODE_HT(phymode))
867 		return phymode;
868 
869 	scan_params->channel.cfreq0 =
870 		util_scan_sec_chan_freq_from_htinfo(htinfo,
871 						scan_params->channel.chan_freq);
872 
873 	if (util_scan_entry_vhtcap(scan_params) && vhtop) {
874 		switch (vhtop->vht_op_chwidth) {
875 		case WLAN_VHTOP_CHWIDTH_2040:
876 			if (phymode == WLAN_PHYMODE_11NG_HT40PLUS)
877 				phymode = WLAN_PHYMODE_11AC_VHT40PLUS_2G;
878 			else if (phymode == WLAN_PHYMODE_11NG_HT40MINUS)
879 				phymode = WLAN_PHYMODE_11AC_VHT40MINUS_2G;
880 			else
881 				phymode = WLAN_PHYMODE_11AC_VHT20_2G;
882 
883 			break;
884 		default:
885 			scm_info("bad vht_op_chwidth: %d",
886 				 vhtop->vht_op_chwidth);
887 			phymode = WLAN_PHYMODE_11AC_VHT20_2G;
888 			break;
889 		}
890 	}
891 
892 	if (!util_scan_entry_hecap(scan_params))
893 		return phymode;
894 
895 	if (phymode == WLAN_PHYMODE_11AC_VHT40PLUS_2G ||
896 	    phymode == WLAN_PHYMODE_11NG_HT40PLUS)
897 		phymode = WLAN_PHYMODE_11AXG_HE40PLUS;
898 	else if (phymode == WLAN_PHYMODE_11AC_VHT40MINUS_2G ||
899 		 phymode == WLAN_PHYMODE_11NG_HT40MINUS)
900 		phymode = WLAN_PHYMODE_11AXG_HE40MINUS;
901 	else
902 		phymode = WLAN_PHYMODE_11AXG_HE20;
903 
904 	phymode = util_scan_get_phymode_2g_11be(scan_params, phymode);
905 
906 	return phymode;
907 }
908 
909 static enum wlan_phymode
910 util_scan_get_phymode(struct wlan_objmgr_pdev *pdev,
911 		      struct scan_cache_entry *scan_params)
912 {
913 	if (WLAN_REG_IS_24GHZ_CH_FREQ(scan_params->channel.chan_freq))
914 		return util_scan_get_phymode_2g(scan_params);
915 	else if (WLAN_REG_IS_6GHZ_CHAN_FREQ(scan_params->channel.chan_freq))
916 		return util_scan_get_phymode_6g(pdev, scan_params);
917 	else
918 		return util_scan_get_phymode_5g(pdev, scan_params);
919 }
920 
921 static QDF_STATUS
922 util_scan_parse_chan_switch_wrapper_ie(struct scan_cache_entry *scan_params,
923 	struct ie_header *sub_ie, qdf_size_t sub_ie_len)
924 {
925 	/* Walk through to check nothing is malformed */
926 	while (sub_ie_len >= sizeof(struct ie_header)) {
927 		/* At least one more header is present */
928 		sub_ie_len -= sizeof(struct ie_header);
929 
930 		if (sub_ie->ie_len == 0) {
931 			sub_ie += 1;
932 			continue;
933 		}
934 		if (sub_ie_len < sub_ie->ie_len) {
935 			scm_debug_rl(QDF_MAC_ADDR_FMT": Incomplete corrupted IE:%x",
936 				     QDF_MAC_ADDR_REF(scan_params->bssid.bytes),
937 				     WLAN_ELEMID_CHAN_SWITCH_WRAP);
938 			return QDF_STATUS_E_INVAL;
939 		}
940 		switch (sub_ie->ie_id) {
941 		case WLAN_ELEMID_COUNTRY:
942 			if (sub_ie->ie_len < WLAN_COUNTRY_IE_MIN_LEN)
943 				return QDF_STATUS_E_INVAL;
944 			scan_params->ie_list.country = (uint8_t *)sub_ie;
945 			break;
946 		case WLAN_ELEMID_WIDE_BAND_CHAN_SWITCH:
947 			if (sub_ie->ie_len < WLAN_WIDE_BW_CHAN_SWITCH_IE_LEN)
948 				return QDF_STATUS_E_INVAL;
949 			scan_params->ie_list.widebw = (uint8_t *)sub_ie;
950 			break;
951 		case WLAN_ELEMID_VHT_TX_PWR_ENVLP:
952 			if (sub_ie->ie_len > WLAN_TPE_IE_MAX_LEN)
953 				return QDF_STATUS_E_INVAL;
954 			scan_params->ie_list.txpwrenvlp = (uint8_t *)sub_ie;
955 			break;
956 		}
957 		/* Consume sub info element */
958 		sub_ie_len -= sub_ie->ie_len;
959 		/* go to next Sub IE */
960 		sub_ie = (struct ie_header *)
961 			(((uint8_t *) sub_ie) +
962 			sizeof(struct ie_header) + sub_ie->ie_len);
963 	}
964 
965 	return QDF_STATUS_SUCCESS;
966 }
967 
968 bool
969 util_scan_is_hidden_ssid(struct ie_ssid *ssid)
970 {
971 	uint8_t i;
972 
973 	/*
974 	 * We flag this as Hidden SSID if the Length is 0
975 	 * of the SSID only contains 0's
976 	 */
977 	if (!ssid || !ssid->ssid_len)
978 		return true;
979 
980 	for (i = 0; i < ssid->ssid_len; i++)
981 		if (ssid->ssid[i] != 0)
982 			return false;
983 
984 	/* All 0's */
985 	return true;
986 }
987 
988 #ifdef WLAN_FEATURE_11BE_MLO
989 static void
990 util_scan_update_rnr_mld(struct rnr_bss_info *rnr,
991 			 struct neighbor_ap_info_field *ap_info, uint8_t *data)
992 {
993 	uint8_t tbtt_info_length;
994 	bool mld_info_present = false;
995 
996 	tbtt_info_length = ap_info->tbtt_header.tbtt_info_length;
997 	if (tbtt_info_length >=
998 		TBTT_NEIGHBOR_AP_BSSID_S_SSID_BSS_PARAM_20MHZ_PSD_MLD_PARAM)
999 		tbtt_info_length =
1000 		   TBTT_NEIGHBOR_AP_BSSID_S_SSID_BSS_PARAM_20MHZ_PSD_MLD_PARAM;
1001 
1002 	switch (tbtt_info_length) {
1003 	case TBTT_NEIGHBOR_AP_BSSID_S_SSID_BSS_PARAM_20MHZ_PSD_MLD_PARAM:
1004 		rnr->channel_number = ap_info->channel_number;
1005 		rnr->operating_class = ap_info->operting_class;
1006 		qdf_mem_copy(&rnr->bssid, &data[1], QDF_MAC_ADDR_SIZE);
1007 		qdf_mem_copy(&rnr->short_ssid, &data[7], SHORT_SSID_LEN);
1008 		rnr->bss_params = data[11];
1009 		rnr->psd_20mhz = data[12];
1010 		qdf_mem_copy(&rnr->mld_info, &data[13],
1011 			     sizeof(struct rnr_mld_info));
1012 		mld_info_present = true;
1013 		break;
1014 	};
1015 
1016 	rnr->mld_info_valid = mld_info_present;
1017 }
1018 #else
1019 static void
1020 util_scan_update_rnr_mld(struct rnr_bss_info *rnr,
1021 			 struct neighbor_ap_info_field *ap_info, uint8_t *data)
1022 {
1023 	scm_debug("Wrong fieldtype");
1024 }
1025 #endif
1026 
1027 static QDF_STATUS
1028 util_scan_update_rnr(struct rnr_bss_info *rnr,
1029 		     struct neighbor_ap_info_field *ap_info,
1030 		     uint8_t *data)
1031 {
1032 	uint8_t tbtt_info_length;
1033 
1034 	tbtt_info_length = ap_info->tbtt_header.tbtt_info_length;
1035 
1036 	switch (tbtt_info_length) {
1037 	case TBTT_NEIGHBOR_AP_OFFSET_ONLY:
1038 		/* Dont store it skip*/
1039 		break;
1040 
1041 	case TBTT_NEIGHBOR_AP_BSS_PARAM:
1042 		/* Dont store it skip*/
1043 		break;
1044 
1045 	case TBTT_NEIGHBOR_AP_SHORTSSID:
1046 		rnr->channel_number = ap_info->channel_number;
1047 		rnr->operating_class = ap_info->operting_class;
1048 		qdf_mem_copy(&rnr->short_ssid, &data[1], SHORT_SSID_LEN);
1049 		break;
1050 
1051 	case TBTT_NEIGHBOR_AP_S_SSID_BSS_PARAM:
1052 		rnr->channel_number = ap_info->channel_number;
1053 		rnr->operating_class = ap_info->operting_class;
1054 		qdf_mem_copy(&rnr->short_ssid, &data[1], SHORT_SSID_LEN);
1055 		rnr->bss_params = data[5];
1056 		break;
1057 
1058 	case TBTT_NEIGHBOR_AP_BSSID:
1059 		rnr->channel_number = ap_info->channel_number;
1060 		rnr->operating_class = ap_info->operting_class;
1061 		qdf_mem_copy(&rnr->bssid, &data[1], QDF_MAC_ADDR_SIZE);
1062 		break;
1063 
1064 	case TBTT_NEIGHBOR_AP_BSSID_BSS_PARAM:
1065 		rnr->channel_number = ap_info->channel_number;
1066 		rnr->operating_class = ap_info->operting_class;
1067 		qdf_mem_copy(&rnr->bssid, &data[1], QDF_MAC_ADDR_SIZE);
1068 		rnr->bss_params = data[7];
1069 		break;
1070 
1071 	case TBTT_NEIGHBOR_AP_BSSID_BSS_PARAM_20MHZ_PSD:
1072 		rnr->channel_number = ap_info->channel_number;
1073 		rnr->operating_class = ap_info->operting_class;
1074 		qdf_mem_copy(&rnr->bssid, &data[1], QDF_MAC_ADDR_SIZE);
1075 		rnr->bss_params = data[7];
1076 		rnr->psd_20mhz = data[8];
1077 		break;
1078 
1079 	case TBTT_NEIGHBOR_AP_BSSSID_S_SSID:
1080 		rnr->channel_number = ap_info->channel_number;
1081 		rnr->operating_class = ap_info->operting_class;
1082 		qdf_mem_copy(&rnr->bssid, &data[1], QDF_MAC_ADDR_SIZE);
1083 		qdf_mem_copy(&rnr->short_ssid, &data[7], SHORT_SSID_LEN);
1084 		break;
1085 
1086 	case TBTT_NEIGHBOR_AP_BSSID_S_SSID_BSS_PARAM:
1087 		rnr->channel_number = ap_info->channel_number;
1088 		rnr->operating_class = ap_info->operting_class;
1089 		qdf_mem_copy(&rnr->bssid, &data[1], QDF_MAC_ADDR_SIZE);
1090 		qdf_mem_copy(&rnr->short_ssid, &data[7], SHORT_SSID_LEN);
1091 		rnr->bss_params = data[11];
1092 		break;
1093 
1094 	case TBTT_NEIGHBOR_AP_BSSID_S_SSID_BSS_PARAM_20MHZ_PSD:
1095 		rnr->channel_number = ap_info->channel_number;
1096 		rnr->operating_class = ap_info->operting_class;
1097 		qdf_mem_copy(&rnr->bssid, &data[1], QDF_MAC_ADDR_SIZE);
1098 		qdf_mem_copy(&rnr->short_ssid, &data[7], SHORT_SSID_LEN);
1099 		rnr->bss_params = data[11];
1100 		rnr->psd_20mhz = data[12];
1101 		break;
1102 
1103 	default:
1104 		util_scan_update_rnr_mld(rnr, ap_info, data);
1105 	}
1106 
1107 	return QDF_STATUS_SUCCESS;
1108 }
1109 
1110 static QDF_STATUS
1111 util_scan_parse_rnr_ie(struct scan_cache_entry *scan_entry,
1112 		       struct ie_header *ie)
1113 {
1114 	uint32_t rnr_ie_len;
1115 	uint16_t tbtt_count, tbtt_length, i, fieldtype, idx;
1116 	uint8_t *data;
1117 	struct neighbor_ap_info_field *neighbor_ap_info;
1118 
1119 	rnr_ie_len = ie->ie_len;
1120 	data = (uint8_t *)ie + sizeof(struct ie_header);
1121 	idx = scan_entry->rnr.count;
1122 
1123 	while (data < ((uint8_t *)ie + rnr_ie_len + 2)) {
1124 		neighbor_ap_info = (struct neighbor_ap_info_field *)data;
1125 		tbtt_count = neighbor_ap_info->tbtt_header.tbtt_info_count;
1126 		tbtt_length = neighbor_ap_info->tbtt_header.tbtt_info_length;
1127 		fieldtype = neighbor_ap_info->tbtt_header.tbbt_info_fieldtype;
1128 		scm_debug("channel number %d, op class %d",
1129 			  neighbor_ap_info->channel_number,
1130 			  neighbor_ap_info->operting_class);
1131 		scm_debug("tbtt_count %d, tbtt_length %d, fieldtype %d",
1132 			  tbtt_count, tbtt_length, fieldtype);
1133 		data += sizeof(struct neighbor_ap_info_field);
1134 
1135 		if (tbtt_count > TBTT_INFO_COUNT)
1136 			break;
1137 
1138 		for (i = 0; i < (tbtt_count + 1) &&
1139 		     data < ((uint8_t *)ie + rnr_ie_len + 2); i++) {
1140 			if ((i < MAX_RNR_BSS) && (idx < MAX_RNR_BSS))
1141 				util_scan_update_rnr(
1142 					&scan_entry->rnr.bss_info[idx++],
1143 					neighbor_ap_info,
1144 					data);
1145 			data += tbtt_length;
1146 		}
1147 	}
1148 
1149 	scan_entry->rnr.count = idx;
1150 
1151 	return QDF_STATUS_SUCCESS;
1152 }
1153 
1154 #ifdef WLAN_FEATURE_11BE_MLO
1155 static void
1156 util_scan_parse_t2lm_ie(struct scan_cache_entry *scan_params,
1157 			struct extn_ie_header *extn_ie)
1158 {
1159 	uint8_t t2lm_idx = 0;
1160 
1161 	if (extn_ie->ie_extn_id == WLAN_EXTN_ELEMID_T2LM)
1162 		for (t2lm_idx = 0; t2lm_idx < WLAN_MAX_T2LM_IE; t2lm_idx++) {
1163 			if (!scan_params->ie_list.t2lm[t2lm_idx]) {
1164 				scan_params->ie_list.t2lm[t2lm_idx] =
1165 					(uint8_t *)extn_ie;
1166 				return;
1167 		}
1168 	}
1169 }
1170 #endif
1171 
1172 #ifdef WLAN_FEATURE_11BE
1173 #ifdef WLAN_FEATURE_11BE_MLO
1174 static void util_scan_parse_ml_ie(struct scan_cache_entry *scan_params,
1175 				  struct extn_ie_header *extn_ie)
1176 {
1177 	uint8_t *ml_ie;
1178 	uint32_t ml_ie_len;
1179 	enum wlan_ml_variant ml_variant;
1180 	QDF_STATUS ret;
1181 
1182 	if (extn_ie->ie_extn_id != WLAN_EXTN_ELEMID_MULTI_LINK)
1183 		return;
1184 
1185 	ml_ie = (uint8_t *)extn_ie;
1186 	ml_ie_len = ml_ie[TAG_LEN_POS];
1187 
1188 	/* Adding the size of IE header to ML IE length */
1189 	ml_ie_len += sizeof(struct ie_header);
1190 	ret = util_get_mlie_variant(ml_ie, ml_ie_len, (int *)&ml_variant);
1191 	if (ret) {
1192 		scm_err("Unable to get ml variant");
1193 		return;
1194 	}
1195 
1196 	switch (ml_variant) {
1197 	case WLAN_ML_VARIANT_BASIC:
1198 		scan_params->ie_list.multi_link_bv = (uint8_t *)extn_ie;
1199 		break;
1200 	case WLAN_ML_VARIANT_RECONFIG:
1201 		scan_params->ie_list.multi_link_rv = (uint8_t *)extn_ie;
1202 		break;
1203 	default:
1204 		break;
1205 	}
1206 }
1207 #else
1208 static void util_scan_parse_ml_ie(struct scan_cache_entry *scan_params,
1209 				  struct extn_ie_header *extn_ie)
1210 {
1211 }
1212 #endif
1213 static void util_scan_parse_eht_ie(struct scan_cache_entry *scan_params,
1214 				   struct extn_ie_header *extn_ie)
1215 {
1216 	switch (extn_ie->ie_extn_id) {
1217 	case WLAN_EXTN_ELEMID_EHTCAP:
1218 		scan_params->ie_list.ehtcap = (uint8_t *)extn_ie;
1219 		break;
1220 	case WLAN_EXTN_ELEMID_EHTOP:
1221 		scan_params->ie_list.ehtop  = (uint8_t *)extn_ie;
1222 		break;
1223 	default:
1224 		break;
1225 	}
1226 
1227 	util_scan_parse_ml_ie(scan_params, extn_ie);
1228 	util_scan_parse_t2lm_ie(scan_params, extn_ie);
1229 }
1230 #else
1231 static void util_scan_parse_eht_ie(struct scan_cache_entry *scan_params,
1232 				   struct extn_ie_header *extn_ie)
1233 {
1234 }
1235 #endif
1236 
1237 static QDF_STATUS
1238 util_scan_parse_extn_ie(struct scan_cache_entry *scan_params,
1239 			struct ie_header *ie)
1240 {
1241 	struct extn_ie_header *extn_ie = (struct extn_ie_header *) ie;
1242 
1243 	switch (extn_ie->ie_extn_id) {
1244 	case WLAN_EXTN_ELEMID_MAX_CHAN_SWITCH_TIME:
1245 		if (extn_ie->ie_len != WLAN_MAX_CHAN_SWITCH_TIME_IE_LEN)
1246 			return QDF_STATUS_E_INVAL;
1247 		scan_params->ie_list.mcst  = (uint8_t *)ie;
1248 		break;
1249 	case WLAN_EXTN_ELEMID_SRP:
1250 		if (extn_ie->ie_len > WLAN_MAX_SRP_IE_LEN)
1251 			return QDF_STATUS_E_INVAL;
1252 		scan_params->ie_list.srp   = (uint8_t *)ie;
1253 		break;
1254 	case WLAN_EXTN_ELEMID_HECAP:
1255 		scan_params->ie_list.hecap = (uint8_t *)ie;
1256 		break;
1257 	case WLAN_EXTN_ELEMID_HEOP:
1258 		if (extn_ie->ie_len > WLAN_MAX_HEOP_IE_LEN)
1259 			return QDF_STATUS_E_INVAL;
1260 		scan_params->ie_list.heop  = (uint8_t *)ie;
1261 		break;
1262 	case WLAN_EXTN_ELEMID_ESP:
1263 		scan_params->ie_list.esp = (uint8_t *)ie;
1264 		break;
1265 	case WLAN_EXTN_ELEMID_MUEDCA:
1266 		if (extn_ie->ie_len > WLAN_MAX_MUEDCA_IE_LEN)
1267 			return QDF_STATUS_E_INVAL;
1268 		scan_params->ie_list.muedca = (uint8_t *)ie;
1269 		break;
1270 	case WLAN_EXTN_ELEMID_HE_6G_CAP:
1271 		if (extn_ie->ie_len > WLAN_MAX_HE_6G_CAP_IE_LEN)
1272 			return QDF_STATUS_E_INVAL;
1273 		scan_params->ie_list.hecap_6g = (uint8_t *)ie;
1274 		break;
1275 	default:
1276 		break;
1277 	}
1278 	util_scan_parse_eht_ie(scan_params, extn_ie);
1279 
1280 	return QDF_STATUS_SUCCESS;
1281 }
1282 
1283 static QDF_STATUS
1284 util_scan_parse_vendor_ie(struct scan_cache_entry *scan_params,
1285 	struct ie_header *ie)
1286 {
1287 	if (!scan_params->ie_list.vendor)
1288 		scan_params->ie_list.vendor = (uint8_t *)ie;
1289 
1290 	if (is_wpa_oui((uint8_t *)ie)) {
1291 		scan_params->ie_list.wpa = (uint8_t *)ie;
1292 	} else if (is_wps_oui((uint8_t *)ie)) {
1293 		scan_params->ie_list.wps = (uint8_t *)ie;
1294 		/* WCN IE should be a subset of WPS IE */
1295 		if (is_wcn_oui((uint8_t *)ie))
1296 			scan_params->ie_list.wcn = (uint8_t *)ie;
1297 	} else if (is_wme_param((uint8_t *)ie)) {
1298 		if (ie->ie_len > WLAN_VENDOR_WME_IE_LEN)
1299 			return QDF_STATUS_E_INVAL;
1300 
1301 		scan_params->ie_list.wmeparam = (uint8_t *)ie;
1302 	} else if (is_wme_info((uint8_t *)ie)) {
1303 		scan_params->ie_list.wmeinfo = (uint8_t *)ie;
1304 	} else if (is_atheros_oui((uint8_t *)ie)) {
1305 		if (ie->ie_len > WLAN_VENDOR_ATHCAPS_IE_LEN)
1306 			return QDF_STATUS_E_INVAL;
1307 
1308 		scan_params->ie_list.athcaps = (uint8_t *)ie;
1309 	} else if (is_atheros_extcap_oui((uint8_t *)ie)) {
1310 		if (ie->ie_len > WLAN_VENDOR_ATH_EXTCAP_IE_LEN)
1311 			return QDF_STATUS_E_INVAL;
1312 
1313 		scan_params->ie_list.athextcaps = (uint8_t *)ie;
1314 	} else if (is_sfa_oui((uint8_t *)ie)) {
1315 		if (ie->ie_len > WLAN_VENDOR_SFA_IE_LEN)
1316 			return QDF_STATUS_E_INVAL;
1317 
1318 		scan_params->ie_list.sfa = (uint8_t *)ie;
1319 	} else if (is_p2p_oui((uint8_t *)ie)) {
1320 		scan_params->ie_list.p2p = (uint8_t *)ie;
1321 	} else if (is_qca_son_oui((uint8_t *)ie,
1322 				  QCA_OUI_WHC_AP_INFO_SUBTYPE)) {
1323 		if (ie->ie_len > WLAN_VENDOR_SON_IE_LEN)
1324 			return QDF_STATUS_E_INVAL;
1325 
1326 		scan_params->ie_list.sonadv = (uint8_t *)ie;
1327 	} else if (is_ht_cap((uint8_t *)ie)) {
1328 		/* we only care if there isn't already an HT IE (ANA) */
1329 		if (!scan_params->ie_list.htcap) {
1330 			if (ie->ie_len != (WLAN_VENDOR_HT_IE_OFFSET_LEN +
1331 					   sizeof(struct htcap_cmn_ie)))
1332 				return QDF_STATUS_E_INVAL;
1333 			scan_params->ie_list.htcap =
1334 			 (uint8_t *)&(((struct wlan_vendor_ie_htcap *)ie)->ie);
1335 		}
1336 	} else if (is_ht_info((uint8_t *)ie)) {
1337 		/* we only care if there isn't already an HT IE (ANA) */
1338 		if (!scan_params->ie_list.htinfo) {
1339 			if (ie->ie_len != WLAN_VENDOR_HT_IE_OFFSET_LEN +
1340 					  sizeof(struct wlan_ie_htinfo_cmn))
1341 				return QDF_STATUS_E_INVAL;
1342 			scan_params->ie_list.htinfo =
1343 			  (uint8_t *)&(((struct wlan_vendor_ie_htinfo *)
1344 			  ie)->hi_ie);
1345 		}
1346 	} else if (is_interop_vht((uint8_t *)ie) &&
1347 	    !(scan_params->ie_list.vhtcap)) {
1348 		uint8_t *vendor_ie = (uint8_t *)(ie);
1349 
1350 		if (ie->ie_len < ((WLAN_VENDOR_VHTCAP_IE_OFFSET +
1351 				 sizeof(struct wlan_ie_vhtcaps)) -
1352 				 sizeof(struct ie_header)))
1353 			return QDF_STATUS_E_INVAL;
1354 		vendor_ie = ((uint8_t *)(ie)) + WLAN_VENDOR_VHTCAP_IE_OFFSET;
1355 		if (vendor_ie[1] != (sizeof(struct wlan_ie_vhtcaps)) -
1356 				      sizeof(struct ie_header))
1357 			return QDF_STATUS_E_INVAL;
1358 		/* location where Interop Vht Cap IE and VHT OP IE Present */
1359 		scan_params->ie_list.vhtcap = (((uint8_t *)(ie)) +
1360 						WLAN_VENDOR_VHTCAP_IE_OFFSET);
1361 		if (ie->ie_len > ((WLAN_VENDOR_VHTCAP_IE_OFFSET +
1362 				 sizeof(struct wlan_ie_vhtcaps)) -
1363 				 sizeof(struct ie_header))) {
1364 			if (ie->ie_len < ((WLAN_VENDOR_VHTOP_IE_OFFSET +
1365 					  sizeof(struct wlan_ie_vhtop)) -
1366 					  sizeof(struct ie_header)))
1367 				return QDF_STATUS_E_INVAL;
1368 			vendor_ie = ((uint8_t *)(ie)) +
1369 				    WLAN_VENDOR_VHTOP_IE_OFFSET;
1370 			if (vendor_ie[1] != (sizeof(struct wlan_ie_vhtop) -
1371 					     sizeof(struct ie_header)))
1372 				return QDF_STATUS_E_INVAL;
1373 			scan_params->ie_list.vhtop = (((uint8_t *)(ie)) +
1374 						   WLAN_VENDOR_VHTOP_IE_OFFSET);
1375 		}
1376 	} else if (is_bwnss_oui((uint8_t *)ie)) {
1377 		/*
1378 		 * Bandwidth-NSS map has sub-type & version.
1379 		 * hence copy data just after version byte
1380 		 */
1381 		if (ie->ie_len > WLAN_BWNSS_MAP_OFFSET)
1382 			scan_params->ie_list.bwnss_map = (((uint8_t *)ie) + 8);
1383 	} else if (is_mbo_oce_oui((uint8_t *)ie)) {
1384 		scan_params->ie_list.mbo_oce = (uint8_t *)ie;
1385 	} else if (is_extender_oui((uint8_t *)ie)) {
1386 		scan_params->ie_list.extender = (uint8_t *)ie;
1387 	} else if (is_adaptive_11r_oui((uint8_t *)ie)) {
1388 		if ((ie->ie_len < OUI_LENGTH) ||
1389 		    (ie->ie_len > MAX_ADAPTIVE_11R_IE_LEN))
1390 			return QDF_STATUS_E_INVAL;
1391 
1392 		scan_params->ie_list.adaptive_11r = (uint8_t *)ie +
1393 						sizeof(struct ie_header);
1394 	} else if (is_sae_single_pmk_oui((uint8_t *)ie)) {
1395 		if ((ie->ie_len < OUI_LENGTH) ||
1396 		    (ie->ie_len > MAX_SAE_SINGLE_PMK_IE_LEN)) {
1397 			scm_debug("Invalid sae single pmk OUI");
1398 			return QDF_STATUS_E_INVAL;
1399 		}
1400 		scan_params->ie_list.single_pmk = (uint8_t *)ie +
1401 						sizeof(struct ie_header);
1402 	} else if (is_qcn_oui((uint8_t *)ie)) {
1403 		scan_params->ie_list.qcn = (uint8_t *)ie;
1404 	}
1405 
1406 	return QDF_STATUS_SUCCESS;
1407 }
1408 
1409 static QDF_STATUS
1410 util_scan_populate_bcn_ie_list(struct wlan_objmgr_pdev *pdev,
1411 			       struct scan_cache_entry *scan_params,
1412 			       qdf_freq_t *chan_freq, uint8_t band_mask)
1413 {
1414 	struct ie_header *ie, *sub_ie;
1415 	uint32_t ie_len, sub_ie_len;
1416 	QDF_STATUS status;
1417 	uint8_t chan_idx;
1418 	struct wlan_scan_obj *scan_obj;
1419 	struct wlan_objmgr_psoc *psoc;
1420 	uint8_t tpe_idx = 0;
1421 
1422 	psoc = wlan_pdev_get_psoc(pdev);
1423 	if (!psoc) {
1424 		scm_err("psoc is NULL");
1425 		return QDF_STATUS_E_INVAL;
1426 	}
1427 
1428 	scan_obj = wlan_psoc_get_scan_obj(psoc);
1429 	if (!scan_obj) {
1430 		scm_err("scan_obj is NULL");
1431 		return QDF_STATUS_E_INVAL;
1432 	}
1433 
1434 	ie_len = util_scan_entry_ie_len(scan_params);
1435 	ie = (struct ie_header *)
1436 		  util_scan_entry_ie_data(scan_params);
1437 
1438 	while (ie_len >= sizeof(struct ie_header)) {
1439 		ie_len -= sizeof(struct ie_header);
1440 
1441 		if (!ie->ie_len) {
1442 			ie += 1;
1443 			continue;
1444 		}
1445 
1446 		if (ie_len < ie->ie_len) {
1447 			if (scan_obj->allow_bss_with_incomplete_ie) {
1448 				scm_debug(QDF_MAC_ADDR_FMT": Scan allowed with incomplete corrupted IE:%x, ie_len: %d, ie->ie_len: %d, stop processing further",
1449 					  QDF_MAC_ADDR_REF(scan_params->bssid.bytes),
1450 					  ie->ie_id, ie_len, ie->ie_len);
1451 				break;
1452 			}
1453 			scm_debug(QDF_MAC_ADDR_FMT": Scan not allowed with incomplete corrupted IE:%x, ie_len: %d, ie->ie_len: %d, stop processing further",
1454 				  QDF_MAC_ADDR_REF(scan_params->bssid.bytes),
1455 				  ie->ie_id, ie_len, ie->ie_len);
1456 			return QDF_STATUS_E_INVAL;
1457 		}
1458 
1459 		switch (ie->ie_id) {
1460 		case WLAN_ELEMID_SSID:
1461 			if (ie->ie_len > (sizeof(struct ie_ssid) -
1462 					  sizeof(struct ie_header)))
1463 				goto err;
1464 			scan_params->ie_list.ssid = (uint8_t *)ie;
1465 			break;
1466 		case WLAN_ELEMID_RATES:
1467 			if (ie->ie_len > WLAN_SUPPORTED_RATES_IE_MAX_LEN)
1468 				goto err;
1469 			scan_params->ie_list.rates = (uint8_t *)ie;
1470 			break;
1471 		case WLAN_ELEMID_DSPARMS:
1472 			if (ie->ie_len != WLAN_DS_PARAM_IE_MAX_LEN)
1473 				return QDF_STATUS_E_INVAL;
1474 			scan_params->ie_list.ds_param = (uint8_t *)ie;
1475 			chan_idx = ((struct ds_ie *)ie)->cur_chan;
1476 			*chan_freq = wlan_reg_chan_band_to_freq(pdev, chan_idx,
1477 								band_mask);
1478 			/* Drop if invalid freq */
1479 			if (scan_obj->drop_bcn_on_invalid_freq &&
1480 			    !wlan_reg_is_freq_present_in_cur_chan_list(pdev,
1481 								*chan_freq)) {
1482 				scm_debug(QDF_MAC_ADDR_FMT": Drop as invalid chan %d in DS IE, freq %d, band_mask %d",
1483 					  QDF_MAC_ADDR_REF(
1484 						  scan_params->bssid.bytes),
1485 					  chan_idx, *chan_freq, band_mask);
1486 				return QDF_STATUS_E_INVAL;
1487 			}
1488 			break;
1489 		case WLAN_ELEMID_TIM:
1490 			if (ie->ie_len < WLAN_TIM_IE_MIN_LENGTH)
1491 				goto err;
1492 			scan_params->ie_list.tim = (uint8_t *)ie;
1493 			scan_params->dtim_period =
1494 				((struct wlan_tim_ie *)ie)->tim_period;
1495 			break;
1496 		case WLAN_ELEMID_COUNTRY:
1497 			if (ie->ie_len < WLAN_COUNTRY_IE_MIN_LEN)
1498 				goto err;
1499 			scan_params->ie_list.country = (uint8_t *)ie;
1500 			break;
1501 		case WLAN_ELEMID_QBSS_LOAD:
1502 			if (ie->ie_len != sizeof(struct qbss_load_ie) -
1503 					  sizeof(struct ie_header)) {
1504 				/*
1505 				 * Expected QBSS IE length is 5Bytes; For some
1506 				 * old cisco AP, QBSS IE length is 4Bytes, which
1507 				 * doesn't match with latest spec, So ignore
1508 				 * QBSS IE in such case.
1509 				 */
1510 				break;
1511 			}
1512 			scan_params->ie_list.qbssload = (uint8_t *)ie;
1513 			break;
1514 		case WLAN_ELEMID_CHANSWITCHANN:
1515 			if (ie->ie_len != WLAN_CSA_IE_MAX_LEN)
1516 				goto err;
1517 			scan_params->ie_list.csa = (uint8_t *)ie;
1518 			break;
1519 		case WLAN_ELEMID_IBSSDFS:
1520 			if (ie->ie_len < WLAN_IBSSDFS_IE_MIN_LEN)
1521 				goto err;
1522 			scan_params->ie_list.ibssdfs = (uint8_t *)ie;
1523 			break;
1524 		case WLAN_ELEMID_QUIET:
1525 			if (ie->ie_len != WLAN_QUIET_IE_MAX_LEN)
1526 				goto err;
1527 			scan_params->ie_list.quiet = (uint8_t *)ie;
1528 			break;
1529 		case WLAN_ELEMID_ERP:
1530 			if (ie->ie_len != (sizeof(struct erp_ie) -
1531 					    sizeof(struct ie_header)))
1532 				goto err;
1533 			scan_params->erp = ((struct erp_ie *)ie)->value;
1534 			break;
1535 		case WLAN_ELEMID_HTCAP_ANA:
1536 			if (ie->ie_len == sizeof(struct htcap_cmn_ie)) {
1537 				scan_params->ie_list.htcap =
1538 				(uint8_t *)&(((struct htcap_ie *)ie)->ie);
1539 			}
1540 			break;
1541 		case WLAN_ELEMID_RSN:
1542 			/*
1543 			 * For security cert TC, RSNIE length can be 1 but if
1544 			 * beacon is dropped, old entry will remain in scan
1545 			 * cache and cause cert TC failure as connection with
1546 			 * old entry with valid RSN IE will pass.
1547 			 * So instead of dropping the frame, do not store the
1548 			 * RSN pointer so that old entry is overwritten.
1549 			 */
1550 			if (ie->ie_len >= WLAN_RSN_IE_MIN_LEN)
1551 				scan_params->ie_list.rsn = (uint8_t *)ie;
1552 			break;
1553 		case WLAN_ELEMID_XRATES:
1554 			if (ie->ie_len > WLAN_EXT_SUPPORTED_RATES_IE_MAX_LEN)
1555 				goto err;
1556 			scan_params->ie_list.xrates = (uint8_t *)ie;
1557 			break;
1558 		case WLAN_ELEMID_EXTCHANSWITCHANN:
1559 			if (ie->ie_len != WLAN_XCSA_IE_MAX_LEN)
1560 				goto err;
1561 			scan_params->ie_list.xcsa = (uint8_t *)ie;
1562 			break;
1563 		case WLAN_ELEMID_SECCHANOFFSET:
1564 			if (ie->ie_len != WLAN_SECCHANOFF_IE_MAX_LEN)
1565 				goto err;
1566 			scan_params->ie_list.secchanoff = (uint8_t *)ie;
1567 			break;
1568 		case WLAN_ELEMID_HTINFO_ANA:
1569 			if (ie->ie_len != sizeof(struct wlan_ie_htinfo_cmn))
1570 				goto err;
1571 			scan_params->ie_list.htinfo =
1572 			  (uint8_t *)&(((struct wlan_ie_htinfo *) ie)->hi_ie);
1573 			chan_idx = ((struct wlan_ie_htinfo_cmn *)
1574 				 (scan_params->ie_list.htinfo))->hi_ctrlchannel;
1575 			*chan_freq = wlan_reg_chan_band_to_freq(pdev, chan_idx,
1576 								band_mask);
1577 			/* Drop if invalid freq */
1578 			if (scan_obj->drop_bcn_on_invalid_freq &&
1579 			    wlan_reg_is_disable_for_pwrmode(
1580 						pdev, *chan_freq,
1581 						REG_CURRENT_PWR_MODE)) {
1582 				scm_debug_rl(QDF_MAC_ADDR_FMT": Drop as invalid channel %d freq %d in HT_INFO IE",
1583 					     QDF_MAC_ADDR_REF(scan_params->bssid.bytes),
1584 					     chan_idx, *chan_freq);
1585 				return QDF_STATUS_E_INVAL;
1586 			}
1587 			break;
1588 		case WLAN_ELEMID_WAPI:
1589 			if (ie->ie_len < WLAN_WAPI_IE_MIN_LEN)
1590 				goto err;
1591 			scan_params->ie_list.wapi = (uint8_t *)ie;
1592 			break;
1593 		case WLAN_ELEMID_XCAPS:
1594 			if (ie->ie_len > WLAN_EXTCAP_IE_MAX_LEN)
1595 				goto err;
1596 			scan_params->ie_list.extcaps = (uint8_t *)ie;
1597 			break;
1598 		case WLAN_ELEMID_VHTCAP:
1599 			if (ie->ie_len != (sizeof(struct wlan_ie_vhtcaps) -
1600 					   sizeof(struct ie_header)))
1601 				goto err;
1602 			scan_params->ie_list.vhtcap = (uint8_t *)ie;
1603 			break;
1604 		case WLAN_ELEMID_VHTOP:
1605 			if (ie->ie_len != (sizeof(struct wlan_ie_vhtop) -
1606 					   sizeof(struct ie_header)))
1607 				goto err;
1608 			scan_params->ie_list.vhtop = (uint8_t *)ie;
1609 			break;
1610 		case WLAN_ELEMID_OP_MODE_NOTIFY:
1611 			if (ie->ie_len != WLAN_OPMODE_IE_MAX_LEN)
1612 				goto err;
1613 			scan_params->ie_list.opmode = (uint8_t *)ie;
1614 			break;
1615 		case WLAN_ELEMID_MOBILITY_DOMAIN:
1616 			if (ie->ie_len != WLAN_MOBILITY_DOMAIN_IE_MAX_LEN)
1617 				goto err;
1618 			scan_params->ie_list.mdie = (uint8_t *)ie;
1619 			break;
1620 		case WLAN_ELEMID_VENDOR:
1621 			status = util_scan_parse_vendor_ie(scan_params,
1622 							   ie);
1623 			if (QDF_IS_STATUS_ERROR(status))
1624 				goto err_status;
1625 			break;
1626 		case WLAN_ELEMID_VHT_TX_PWR_ENVLP:
1627 			if (ie->ie_len < WLAN_TPE_IE_MIN_LEN)
1628 				goto err;
1629 			if (tpe_idx >= WLAN_MAX_NUM_TPE_IE)
1630 				goto err;
1631 			scan_params->ie_list.tpe[tpe_idx++] = (uint8_t *)ie;
1632 			break;
1633 		case WLAN_ELEMID_CHAN_SWITCH_WRAP:
1634 			scan_params->ie_list.cswrp = (uint8_t *)ie;
1635 			/* Go to next sub IE */
1636 			sub_ie = (struct ie_header *)
1637 			(((uint8_t *)ie) + sizeof(struct ie_header));
1638 			sub_ie_len = ie->ie_len;
1639 			status =
1640 				util_scan_parse_chan_switch_wrapper_ie(
1641 					scan_params, sub_ie, sub_ie_len);
1642 			if (QDF_IS_STATUS_ERROR(status)) {
1643 				goto err_status;
1644 			}
1645 			break;
1646 		case WLAN_ELEMID_FILS_INDICATION:
1647 			if (ie->ie_len < WLAN_FILS_INDICATION_IE_MIN_LEN)
1648 				goto err;
1649 			scan_params->ie_list.fils_indication = (uint8_t *)ie;
1650 			break;
1651 		case WLAN_ELEMID_RSNXE:
1652 			if (!ie->ie_len)
1653 				goto err;
1654 			scan_params->ie_list.rsnxe = (uint8_t *)ie;
1655 			break;
1656 		case WLAN_ELEMID_EXTN_ELEM:
1657 			status = util_scan_parse_extn_ie(scan_params, ie);
1658 			if (QDF_IS_STATUS_ERROR(status))
1659 				goto err_status;
1660 			break;
1661 		case WLAN_ELEMID_REDUCED_NEIGHBOR_REPORT:
1662 			if (ie->ie_len < WLAN_RNR_IE_MIN_LEN)
1663 				goto err;
1664 			scan_params->ie_list.rnrie = (uint8_t *)ie;
1665 			status = util_scan_parse_rnr_ie(scan_params, ie);
1666 			if (QDF_IS_STATUS_ERROR(status))
1667 				goto err_status;
1668 			break;
1669 		default:
1670 			break;
1671 		}
1672 
1673 		/* Consume info element */
1674 		ie_len -= ie->ie_len;
1675 		/* Go to next IE */
1676 		ie = (struct ie_header *)
1677 			(((uint8_t *) ie) +
1678 			sizeof(struct ie_header) +
1679 			ie->ie_len);
1680 	}
1681 
1682 	return QDF_STATUS_SUCCESS;
1683 
1684 err:
1685 	status = QDF_STATUS_E_INVAL;
1686 err_status:
1687 	scm_debug("failed to parse IE - id: %d, len: %d",
1688 		  ie->ie_id, ie->ie_len);
1689 
1690 	return status;
1691 }
1692 
1693 /**
1694  * util_scan_update_esp_data: update ESP params from beacon/probe response
1695  * @esp_information: pointer to wlan_esp_information
1696  * @scan_entry: new received entry
1697  *
1698  * The Estimated Service Parameters element is
1699  * used by a AP to provide information to another STA which
1700  * can then use the information as input to an algorithm to
1701  * generate an estimate of throughput between the two STAs.
1702  * The ESP Information List field contains from 1 to 4 ESP
1703  * Information fields(each field 24 bits), each corresponding
1704  * to an access category for which estimated service parameters
1705  * information is provided.
1706  *
1707  * Return: None
1708  */
1709 static void util_scan_update_esp_data(struct wlan_esp_ie *esp_information,
1710 		struct scan_cache_entry *scan_entry)
1711 {
1712 
1713 	uint8_t *data;
1714 	int i = 0;
1715 	uint64_t total_elements;
1716 	struct wlan_esp_info *esp_info;
1717 	struct wlan_esp_ie *esp_ie;
1718 
1719 	esp_ie = (struct wlan_esp_ie *)
1720 		util_scan_entry_esp_info(scan_entry);
1721 
1722 	total_elements  = esp_ie->esp_len;
1723 	data = (uint8_t *)esp_ie + 3;
1724 	do_div(total_elements, ESP_INFORMATION_LIST_LENGTH);
1725 
1726 	if (total_elements > MAX_ESP_INFORMATION_FIELD) {
1727 		scm_err("No of Air time fractions are greater than supported");
1728 		return;
1729 	}
1730 
1731 	for (i = 0; i < total_elements &&
1732 	     data < ((uint8_t *)esp_ie + esp_ie->esp_len + 3); i++) {
1733 		esp_info = (struct wlan_esp_info *)data;
1734 		if (esp_info->access_category == ESP_AC_BK) {
1735 			qdf_mem_copy(&esp_information->esp_info_AC_BK,
1736 					data, 3);
1737 			data = data + ESP_INFORMATION_LIST_LENGTH;
1738 			continue;
1739 		}
1740 		if (esp_info->access_category == ESP_AC_BE) {
1741 			qdf_mem_copy(&esp_information->esp_info_AC_BE,
1742 					data, 3);
1743 			data = data + ESP_INFORMATION_LIST_LENGTH;
1744 			continue;
1745 		}
1746 		if (esp_info->access_category == ESP_AC_VI) {
1747 			qdf_mem_copy(&esp_information->esp_info_AC_VI,
1748 					data, 3);
1749 			data = data + ESP_INFORMATION_LIST_LENGTH;
1750 			continue;
1751 		}
1752 		if (esp_info->access_category == ESP_AC_VO) {
1753 			qdf_mem_copy(&esp_information->esp_info_AC_VO,
1754 					data, 3);
1755 			data = data + ESP_INFORMATION_LIST_LENGTH;
1756 			break;
1757 		}
1758 	}
1759 }
1760 
1761 /**
1762  * util_scan_scm_update_bss_with_esp_data: calculate estimated air time
1763  * fraction
1764  * @scan_entry: new received entry
1765  *
1766  * This function process all Access category ESP params and provide
1767  * best effort air time fraction.
1768  * If best effort is not available, it will choose VI, VO and BK in sequence
1769  *
1770  */
1771 static void util_scan_scm_update_bss_with_esp_data(
1772 		struct scan_cache_entry *scan_entry)
1773 {
1774 	uint8_t air_time_fraction = 0;
1775 	struct wlan_esp_ie esp_information;
1776 
1777 	if (!scan_entry->ie_list.esp)
1778 		return;
1779 
1780 	util_scan_update_esp_data(&esp_information, scan_entry);
1781 
1782 	/*
1783 	 * If the ESP metric is transmitting multiple airtime fractions, then
1784 	 * follow the sequence AC_BE, AC_VI, AC_VO, AC_BK and pick whichever is
1785 	 * the first one available
1786 	 */
1787 	if (esp_information.esp_info_AC_BE.access_category
1788 			== ESP_AC_BE)
1789 		air_time_fraction =
1790 			esp_information.esp_info_AC_BE.
1791 			estimated_air_fraction;
1792 	else if (esp_information.esp_info_AC_VI.access_category
1793 			== ESP_AC_VI)
1794 		air_time_fraction =
1795 			esp_information.esp_info_AC_VI.
1796 			estimated_air_fraction;
1797 	else if (esp_information.esp_info_AC_VO.access_category
1798 			== ESP_AC_VO)
1799 		air_time_fraction =
1800 			esp_information.esp_info_AC_VO.
1801 			estimated_air_fraction;
1802 	else if (esp_information.esp_info_AC_BK.access_category
1803 			== ESP_AC_BK)
1804 		air_time_fraction =
1805 			esp_information.esp_info_AC_BK.
1806 				estimated_air_fraction;
1807 	scan_entry->air_time_fraction = air_time_fraction;
1808 }
1809 
1810 /**
1811  * util_scan_scm_calc_nss_supported_by_ap() - finds out nss from AP
1812  * @scan_params: new received entry
1813  *
1814  * Return: number of nss advertised by AP
1815  */
1816 static int util_scan_scm_calc_nss_supported_by_ap(
1817 		struct scan_cache_entry *scan_params)
1818 {
1819 	struct htcap_cmn_ie *htcap;
1820 	struct wlan_ie_vhtcaps *vhtcaps;
1821 	struct wlan_ie_hecaps *hecaps;
1822 	uint16_t rx_mcs_map = 0;
1823 
1824 	htcap = (struct htcap_cmn_ie *)
1825 		util_scan_entry_htcap(scan_params);
1826 	vhtcaps = (struct wlan_ie_vhtcaps *)
1827 		util_scan_entry_vhtcap(scan_params);
1828 	hecaps = (struct wlan_ie_hecaps *)
1829 		util_scan_entry_hecap(scan_params);
1830 
1831 	if (hecaps) {
1832 		/* Using rx mcs map related to 80MHz or lower as in some
1833 		 * cases higher mcs may support lesser NSS than that
1834 		 * of lowe mcs. Thus giving max NSS capability.
1835 		 */
1836 		rx_mcs_map =
1837 			qdf_cpu_to_le16(hecaps->mcs_bw_map[0].rx_mcs_map);
1838 	} else if (vhtcaps) {
1839 		rx_mcs_map = vhtcaps->rx_mcs_map;
1840 	}
1841 
1842 	if (hecaps || vhtcaps) {
1843 		if ((rx_mcs_map & 0xC000) != 0xC000)
1844 			return 8;
1845 
1846 		if ((rx_mcs_map & 0x3000) != 0x3000)
1847 			return 7;
1848 
1849 		if ((rx_mcs_map & 0x0C00) != 0x0C00)
1850 			return 6;
1851 
1852 		if ((rx_mcs_map & 0x0300) != 0x0300)
1853 			return 5;
1854 
1855 		if ((rx_mcs_map & 0x00C0) != 0x00C0)
1856 			return 4;
1857 
1858 		if ((rx_mcs_map & 0x0030) != 0x0030)
1859 			return 3;
1860 
1861 		if ((rx_mcs_map & 0x000C) != 0x000C)
1862 			return 2;
1863 	} else if (htcap) {
1864 		if (htcap->mcsset[3])
1865 			return 4;
1866 
1867 		if (htcap->mcsset[2])
1868 			return 3;
1869 
1870 		if (htcap->mcsset[1])
1871 			return 2;
1872 
1873 	}
1874 	return 1;
1875 }
1876 
1877 #ifdef WLAN_DFS_CHAN_HIDDEN_SSID
1878 QDF_STATUS
1879 util_scan_add_hidden_ssid(struct wlan_objmgr_pdev *pdev, qdf_nbuf_t bcnbuf)
1880 {
1881 	struct wlan_frame_hdr *hdr;
1882 	struct wlan_bcn_frame *bcn;
1883 	struct wlan_scan_obj *scan_obj;
1884 	struct wlan_ssid *conf_ssid;
1885 	struct  ie_header *ie;
1886 	uint32_t frame_len = qdf_nbuf_len(bcnbuf);
1887 	uint16_t bcn_ie_offset, ssid_ie_start_offset, ssid_ie_end_offset;
1888 	uint16_t tmplen, ie_length;
1889 	uint8_t *pbeacon, *tmp;
1890 	bool     set_ssid_flag = false;
1891 	struct ie_ssid ssid = {0};
1892 	uint8_t pdev_id;
1893 
1894 	if (!pdev) {
1895 		scm_warn("pdev: 0x%pK is NULL", pdev);
1896 		return QDF_STATUS_E_NULL_VALUE;
1897 	}
1898 	pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
1899 	scan_obj = wlan_pdev_get_scan_obj(pdev);
1900 	if (!scan_obj) {
1901 		scm_warn("null scan_obj");
1902 		return QDF_STATUS_E_NULL_VALUE;
1903 	}
1904 
1905 	conf_ssid = &scan_obj->pdev_info[pdev_id].conf_ssid;
1906 
1907 	hdr = (struct wlan_frame_hdr *)qdf_nbuf_data(bcnbuf);
1908 
1909 	/* received bssid does not match configured bssid */
1910 	if (qdf_mem_cmp(hdr->i_addr3, scan_obj->pdev_info[pdev_id].conf_bssid,
1911 			QDF_MAC_ADDR_SIZE) ||
1912 			conf_ssid->length == 0) {
1913 		return QDF_STATUS_SUCCESS;
1914 	}
1915 
1916 	bcn = (struct wlan_bcn_frame *)(qdf_nbuf_data(bcnbuf) + sizeof(*hdr));
1917 	pbeacon = (uint8_t *)bcn;
1918 
1919 	ie = (struct ie_header *)(pbeacon +
1920 				  offsetof(struct wlan_bcn_frame, ie));
1921 
1922 	bcn_ie_offset = offsetof(struct wlan_bcn_frame, ie);
1923 	ie_length = (uint16_t)(frame_len - sizeof(*hdr) -
1924 			       bcn_ie_offset);
1925 
1926 	while (ie_length >=  sizeof(struct ie_header)) {
1927 		ie_length -= sizeof(struct ie_header);
1928 
1929 		bcn_ie_offset += sizeof(struct ie_header);
1930 
1931 		if (ie_length < ie->ie_len) {
1932 			scm_debug("Incomplete corrupted IE:%x", ie->ie_id);
1933 			return QDF_STATUS_E_INVAL;
1934 		}
1935 		if (ie->ie_id == WLAN_ELEMID_SSID) {
1936 			if (ie->ie_len > (sizeof(struct ie_ssid) -
1937 						 sizeof(struct ie_header))) {
1938 				return QDF_STATUS_E_INVAL;
1939 			}
1940 			ssid.ssid_id = ie->ie_id;
1941 			ssid.ssid_len = ie->ie_len;
1942 
1943 			if (ssid.ssid_len)
1944 				qdf_mem_copy(ssid.ssid,
1945 					     ie + sizeof(struct ie_header),
1946 					     ssid.ssid_len);
1947 
1948 			if (util_scan_is_hidden_ssid(&ssid)) {
1949 				set_ssid_flag  = true;
1950 				ssid_ie_start_offset = bcn_ie_offset -
1951 					sizeof(struct ie_header);
1952 				ssid_ie_end_offset = bcn_ie_offset +
1953 					ie->ie_len;
1954 			}
1955 		}
1956 		if (ie->ie_len == 0) {
1957 			ie += 1;    /* next IE */
1958 			continue;
1959 		}
1960 		if (ie->ie_id == WLAN_ELEMID_VENDOR &&
1961 		    is_wps_oui((uint8_t *)ie)) {
1962 			set_ssid_flag = false;
1963 			break;
1964 		}
1965 		/* Consume info element */
1966 		ie_length -=  ie->ie_len;
1967 		/* Go to next IE */
1968 		ie = (struct ie_header *)(((uint8_t *)ie) +
1969 				sizeof(struct ie_header) +
1970 				ie->ie_len);
1971 	}
1972 
1973 	if (set_ssid_flag) {
1974 		/* Hidden SSID if the Length is 0 */
1975 		if (!ssid.ssid_len) {
1976 			/* increase the taillength by length of ssid */
1977 			if (qdf_nbuf_put_tail(bcnbuf,
1978 					      conf_ssid->length) == NULL) {
1979 				scm_debug("No enough tailroom");
1980 				return  QDF_STATUS_E_NOMEM;
1981 			}
1982 			/*
1983 			 * "qdf_nbuf_put_tail" might change the data pointer of
1984 			 * the skb. Therefore use the new data area.
1985 			 */
1986 			pbeacon = (qdf_nbuf_data(bcnbuf) + sizeof(*hdr));
1987 			/* length of the buffer to be copied */
1988 			tmplen = frame_len -
1989 				sizeof(*hdr) - ssid_ie_end_offset;
1990 			/*
1991 			 * tmp memory to copy the beacon info
1992 			 * after ssid ie.
1993 			 */
1994 			tmp = qdf_mem_malloc(tmplen * sizeof(u_int8_t));
1995 			if (!tmp)
1996 				return  QDF_STATUS_E_NOMEM;
1997 
1998 			/* Copy beacon data after ssid ie to tmp */
1999 			qdf_nbuf_copy_bits(bcnbuf, (sizeof(*hdr) +
2000 					   ssid_ie_end_offset), tmplen, tmp);
2001 			/* Add ssid length */
2002 			*(pbeacon + (ssid_ie_start_offset + 1))
2003 				= conf_ssid->length;
2004 			/* Insert the  SSID string */
2005 			qdf_mem_copy((pbeacon + ssid_ie_end_offset),
2006 				     conf_ssid->ssid, conf_ssid->length);
2007 			/* Copy rest of the beacon data */
2008 			qdf_mem_copy((pbeacon + ssid_ie_end_offset +
2009 				      conf_ssid->length), tmp, tmplen);
2010 			qdf_mem_free(tmp);
2011 
2012 			/* Hidden ssid with all 0's */
2013 		} else if (ssid.ssid_len == conf_ssid->length) {
2014 			/* Insert the  SSID string */
2015 			qdf_mem_copy((pbeacon + ssid_ie_start_offset +
2016 				      sizeof(struct ie_header)),
2017 				      conf_ssid->ssid, conf_ssid->length);
2018 		} else {
2019 			scm_debug("mismatch in hidden ssid length");
2020 			return QDF_STATUS_E_INVAL;
2021 		}
2022 	}
2023 	return QDF_STATUS_SUCCESS;
2024 }
2025 #endif /* WLAN_DFS_CHAN_HIDDEN_SSID */
2026 
2027 #ifdef WLAN_ADAPTIVE_11R
2028 /**
2029  * scm_fill_adaptive_11r_cap() - Check if the AP supports adaptive 11r
2030  * @scan_entry: Pointer to the scan entry
2031  *
2032  * Return: true if adaptive 11r is advertised else false
2033  */
2034 static void scm_fill_adaptive_11r_cap(struct scan_cache_entry *scan_entry)
2035 {
2036 	uint8_t *ie;
2037 	uint8_t data;
2038 	bool adaptive_11r;
2039 
2040 	ie = util_scan_entry_adaptive_11r(scan_entry);
2041 	if (!ie)
2042 		return;
2043 
2044 	data = *(ie + OUI_LENGTH);
2045 	adaptive_11r = (data & 0x1) ? true : false;
2046 
2047 	scan_entry->adaptive_11r_ap = adaptive_11r;
2048 }
2049 #else
2050 static void scm_fill_adaptive_11r_cap(struct scan_cache_entry *scan_entry)
2051 {
2052 	scan_entry->adaptive_11r_ap = false;
2053 }
2054 #endif
2055 
2056 static void util_scan_set_security(struct scan_cache_entry *scan_params)
2057 {
2058 	if (util_scan_entry_wpa(scan_params))
2059 		scan_params->security_type |= SCAN_SECURITY_TYPE_WPA;
2060 
2061 	if (util_scan_entry_rsn(scan_params))
2062 		scan_params->security_type |= SCAN_SECURITY_TYPE_RSN;
2063 	if (util_scan_entry_wapi(scan_params))
2064 		scan_params->security_type |= SCAN_SECURITY_TYPE_WAPI;
2065 
2066 	if (!scan_params->security_type &&
2067 	    scan_params->cap_info.wlan_caps.privacy)
2068 		scan_params->security_type |= SCAN_SECURITY_TYPE_WEP;
2069 }
2070 
2071 #ifdef WLAN_FEATURE_11BE_MLO
2072 /*
2073  * Multi link IE field offsets
2074  *  ------------------------------------------------------------------------
2075  * | EID(1) | Len (1) | EID_EXT (1) | ML_CONTROL (2) | CMN_INFO (var) | ... |
2076  *  ------------------------------------------------------------------------
2077  */
2078 #define ML_CONTROL_OFFSET 3
2079 #define ML_CMN_INFO_OFFSET ML_CONTROL_OFFSET + 2
2080 
2081 #define CMN_INFO_LINK_ID_PRESENT_BIT      BIT(4)
2082 #define LINK_INFO_MAC_ADDR_PRESENT_BIT    BIT(5)
2083 
2084 /* This function is implemented as per IEEE802.11be D1.0, there is no difference
2085  * in presence bitmap for beacon, probe response and probe request frames.
2086  * This code is to be revisited for future drafts if the presence bitmap values
2087  * changes for the beacon, probe response and probe request frames.
2088  */
2089 static uint8_t util_get_link_info_offset(uint8_t *ml_ie, bool *is_ml_ie_valid)
2090 {
2091 	qdf_size_t ml_ie_len = 0;
2092 	qdf_size_t parsed_ie_len = 0;
2093 	struct wlan_ie_multilink *mlie_fixed;
2094 	uint16_t mlcontrol;
2095 	uint16_t presencebm;
2096 	qdf_size_t actual_len;
2097 
2098 	if (!ml_ie) {
2099 		scm_err("ml_ie is null");
2100 		return 0;
2101 	}
2102 
2103 	if (!is_ml_ie_valid) {
2104 		scm_err_rl("is_ml_ie_valid is null");
2105 		return 0;
2106 	}
2107 
2108 	ml_ie_len = ml_ie[TAG_LEN_POS];
2109 	if (!ml_ie_len) {
2110 		scm_err("ml_ie_len is zero");
2111 		return 0;
2112 	}
2113 
2114 	if (ml_ie_len < sizeof(struct wlan_ie_multilink)) {
2115 		scm_err_rl("Length %zu octets is smaller than required for the fixed portion of Multi-Link element (%zu octets)",
2116 			   ml_ie_len, sizeof(struct wlan_ie_multilink));
2117 		return 0;
2118 	}
2119 
2120 	mlie_fixed = (struct wlan_ie_multilink *)ml_ie;
2121 	mlcontrol = le16toh(mlie_fixed->mlcontrol);
2122 	presencebm = QDF_GET_BITS(mlcontrol, WLAN_ML_CTRL_PBM_IDX,
2123 				  WLAN_ML_CTRL_PBM_BITS);
2124 
2125 	parsed_ie_len += sizeof(*mlie_fixed);
2126 
2127 	parsed_ie_len += WLAN_ML_BV_CINFO_LENGTH_SIZE;
2128 	parsed_ie_len += QDF_MAC_ADDR_SIZE;
2129 
2130 	/* Check if Link ID info is present */
2131 	if (presencebm & WLAN_ML_BV_CTRL_PBM_LINKIDINFO_P)
2132 		parsed_ie_len += WLAN_ML_BV_CINFO_LINKIDINFO_SIZE;
2133 
2134 	/* Check if BSS parameter change count is present */
2135 	if (presencebm & WLAN_ML_BV_CTRL_PBM_BSSPARAMCHANGECNT_P)
2136 		parsed_ie_len += WLAN_ML_BSSPARAMCHNGCNT_SIZE;
2137 
2138 	/* Check if Medium Sync Delay Info is present */
2139 	if (presencebm & WLAN_ML_BV_CTRL_PBM_MEDIUMSYNCDELAYINFO_P)
2140 		parsed_ie_len += WLAN_ML_BV_CINFO_MEDMSYNCDELAYINFO_SIZE;
2141 
2142 	/* Check if EML cap is present */
2143 	if (presencebm & WLAN_ML_BV_CTRL_PBM_EMLCAP_P)
2144 		parsed_ie_len += WLAN_ML_BV_CINFO_EMLCAP_SIZE;
2145 
2146 	/* Check if MLD cap and op is present */
2147 	if (presencebm & WLAN_ML_BV_CTRL_PBM_MLDCAPANDOP_P)
2148 		parsed_ie_len += WLAN_ML_BV_CINFO_MLDCAPANDOP_SIZE;
2149 
2150 	/* Check if MLD ID is present */
2151 	if (presencebm & WLAN_ML_BV_CTRL_PBM_MLDID_P)
2152 		parsed_ie_len += WLAN_ML_BV_CINFO_MLDID_SIZE;
2153 
2154 	/* Offset calculation starts from the beginning of the ML IE (including
2155 	 * EID) hence, adding the size of IE header to ML IE length.
2156 	 */
2157 	actual_len = ml_ie_len + sizeof(struct ie_header);
2158 	if (parsed_ie_len <= actual_len) {
2159 		*is_ml_ie_valid = true;
2160 	} else {
2161 		*is_ml_ie_valid = false;
2162 		scm_err("Invalid ML IE, expect min len: %zu, actual len: %zu",
2163 			parsed_ie_len, actual_len);
2164 	}
2165 	if (parsed_ie_len < actual_len)
2166 		return parsed_ie_len;
2167 
2168 	return 0;
2169 }
2170 
2171 static void util_get_ml_bv_partner_link_info(struct scan_cache_entry *scan_entry)
2172 {
2173 	uint8_t *ml_ie = scan_entry->ie_list.multi_link_bv;
2174 	bool is_ml_ie_valid;
2175 	uint8_t offset = util_get_link_info_offset(ml_ie, &is_ml_ie_valid);
2176 	uint16_t sta_ctrl;
2177 	uint8_t *stactrl_offset = NULL, *ielist_offset;
2178 	uint8_t perstaprof_len = 0, perstaprof_stainfo_len = 0, ielist_len = 0;
2179 	struct partner_link_info *link_info = NULL;
2180 	uint8_t eid = 0;
2181 	uint8_t link_idx = 0;
2182 	uint8_t rnr_idx = 0;
2183 	struct rnr_bss_info *rnr = NULL;
2184 
2185 	/* Update partner info  from RNR IE */
2186 	while ((rnr_idx < MAX_RNR_BSS) && (rnr_idx < scan_entry->rnr.count)) {
2187 		if (link_idx >= (MLD_MAX_LINKS - 1))
2188 			break;
2189 		rnr = &scan_entry->rnr.bss_info[rnr_idx];
2190 		if (rnr->mld_info_valid && !rnr->mld_info.mld_id) {
2191 			link_info = &scan_entry->ml_info.link_info[link_idx];
2192 			qdf_mem_copy(&link_info->link_addr,
2193 				     &rnr->bssid, QDF_MAC_ADDR_SIZE);
2194 
2195 			link_info->link_id = rnr->mld_info.link_id;
2196 			link_info->freq =
2197 				wlan_reg_chan_opclass_to_freq(rnr->channel_number,
2198 							      rnr->operating_class,
2199 							      true);
2200 			if (!link_info->freq)
2201 				scm_debug("freq 0 rnr channel %u op_class %u",
2202 					  rnr->channel_number,
2203 					  rnr->operating_class);
2204 			link_info->op_class = rnr->operating_class;
2205 			link_idx++;
2206 		}
2207 		rnr_idx++;
2208 	}
2209 
2210 	scan_entry->ml_info.num_links = link_idx;
2211 	if (!offset)
2212 		return;
2213 
2214 	/* TODO: loop through all the STA info fields */
2215 
2216 	/* Sub element ID 0 represents Per-STA Profile */
2217 	if (ml_ie[offset] == 0) {
2218 		perstaprof_len = ml_ie[offset + 1];
2219 		stactrl_offset = &ml_ie[offset + 2];
2220 
2221 		/* Skip sub element ID and length fields */
2222 		offset += 2;
2223 
2224 		sta_ctrl = *(uint16_t *)(ml_ie + offset);
2225 
2226 		/* Skip STA control field */
2227 		offset += 2;
2228 
2229 		/*
2230 		 * offset points to the beginning of the STA Info field which
2231 		 * holds the length of the variable field.
2232 		 */
2233 		perstaprof_stainfo_len = ml_ie[offset];
2234 
2235 		/* Skip STA Info Length field */
2236 		offset += WLAN_ML_BV_LINFO_PERSTAPROF_STAINFO_LENGTH_SIZE;
2237 
2238 		/*
2239 		 * To point to the ie_list offset move past the STA Info field.
2240 		 */
2241 		ielist_offset  = &ml_ie[offset + perstaprof_stainfo_len];
2242 
2243 		/*
2244 		 * Ensure that the STA Control Field + STA Info Field
2245 		 * is smaller than the per-STA profile when incrementing
2246 		 * the pointer to avoid underflow during subtraction.
2247 		 */
2248 		if ((perstaprof_stainfo_len +
2249 		     WLAN_ML_BV_LINFO_PERSTAPROF_STAINFO_LENGTH_SIZE +
2250 		     WLAN_ML_BV_LINFO_PERSTAPROF_STACTRL_SIZE) <
2251 							perstaprof_len) {
2252 			ielist_len = perstaprof_len -
2253 			     (WLAN_ML_BV_LINFO_PERSTAPROF_STACTRL_SIZE +
2254 			      WLAN_ML_BV_LINFO_PERSTAPROF_STAINFO_LENGTH_SIZE +
2255 			      perstaprof_stainfo_len);
2256 		} else {
2257 			scm_debug("No STA profile IE list found");
2258 			ielist_len = 0;
2259 		}
2260 
2261 		link_info = NULL;
2262 		for (link_idx = 0; link_idx < scan_entry->ml_info.num_links;
2263 		     link_idx++) {
2264 			if (scan_entry->ml_info.link_info[link_idx].link_id ==
2265 							(sta_ctrl & 0xF)) {
2266 				link_info = &scan_entry->ml_info.link_info[link_idx];
2267 			}
2268                 }
2269 
2270 		/* Get the pointers to CSA, ECSA, Max Channel Switch Time IE. */
2271 		if (link_info) {
2272 			link_info->csa_ie = wlan_get_ie_ptr_from_eid
2273 				(WLAN_ELEMID_CHANSWITCHANN, ielist_offset,
2274 				 ielist_len);
2275 
2276 			link_info->ecsa_ie = wlan_get_ie_ptr_from_eid
2277 				(WLAN_ELEMID_EXTCHANSWITCHANN, ielist_offset,
2278 				 ielist_len);
2279 
2280 			eid = WLAN_EXTN_ELEMID_MAX_CHAN_SWITCH_TIME;
2281 			link_info->max_cst_ie = wlan_get_ext_ie_ptr_from_ext_id
2282 					(&eid, 1, ielist_offset, ielist_len);
2283 		}
2284 	}
2285 }
2286 
2287 static void util_scan_update_ml_info(struct scan_cache_entry *scan_entry)
2288 {
2289 	uint8_t *ml_ie = scan_entry->ie_list.multi_link_bv;
2290 	uint16_t multi_link_ctrl;
2291 	uint8_t offset;
2292 	uint8_t mlie_min_len;
2293 	bool is_ml_ie_valid = true;
2294 
2295 	if (!scan_entry->ie_list.ehtcap && scan_entry->ie_list.multi_link_bv) {
2296 		scan_entry->ie_list.multi_link_bv = NULL;
2297 		return;
2298 	}
2299 	if (!scan_entry->ie_list.multi_link_bv)
2300 		return;
2301 
2302 	mlie_min_len = util_get_link_info_offset(ml_ie, &is_ml_ie_valid);
2303 	if (!is_ml_ie_valid) {
2304 		scan_entry->ie_list.multi_link_bv = NULL;
2305 		return;
2306 	}
2307 
2308 	multi_link_ctrl = *(uint16_t *)(ml_ie + ML_CONTROL_OFFSET);
2309 
2310 	/* TODO: update ml_info based on ML IE */
2311 
2312 	multi_link_ctrl = *(uint16_t *)(ml_ie + ML_CONTROL_OFFSET);
2313 	offset = ML_CMN_INFO_OFFSET;
2314 
2315 	/* Increment the offset to account for the Common Info Length */
2316 	offset += WLAN_ML_BV_CINFO_LENGTH_SIZE;
2317 
2318 	qdf_mem_copy(&scan_entry->ml_info.mld_mac_addr,
2319 		     ml_ie + offset, 6);
2320 	offset += 6;
2321 
2322 	/* TODO: Decode it from ML IE */
2323 	scan_entry->ml_info.num_links = 0;
2324 
2325 	/**
2326 	 * Copy Link ID & MAC address of the scan cache entry as first entry
2327 	 * in the partner info list
2328 	 */
2329 	if (multi_link_ctrl & CMN_INFO_LINK_ID_PRESENT_BIT)
2330 		scan_entry->ml_info.self_link_id = ml_ie[offset] & 0x0F;
2331 
2332 	util_get_ml_bv_partner_link_info(scan_entry);
2333 }
2334 #else
2335 static void util_scan_update_ml_info(struct scan_cache_entry *scan_entry)
2336 {
2337 }
2338 #endif
2339 
2340 static QDF_STATUS
2341 util_scan_gen_scan_entry(struct wlan_objmgr_pdev *pdev,
2342 			 uint8_t *frame, qdf_size_t frame_len,
2343 			 uint32_t frm_subtype,
2344 			 struct mgmt_rx_event_params *rx_param,
2345 			 struct scan_mbssid_info *mbssid_info,
2346 			 qdf_list_t *scan_list)
2347 {
2348 	struct wlan_frame_hdr *hdr;
2349 	struct wlan_bcn_frame *bcn;
2350 	QDF_STATUS status = QDF_STATUS_SUCCESS;
2351 	struct ie_ssid *ssid;
2352 	struct scan_cache_entry *scan_entry;
2353 	struct qbss_load_ie *qbss_load;
2354 	struct scan_cache_node *scan_node;
2355 	uint8_t i;
2356 	qdf_freq_t chan_freq = 0;
2357 	bool is_6g_dup_bcon = false;
2358 	uint8_t band_mask;
2359 	qdf_freq_t recv_freq = 0;
2360 
2361 	scan_entry = qdf_mem_malloc_atomic(sizeof(*scan_entry));
2362 	if (!scan_entry) {
2363 		scm_err("failed to allocate memory for scan_entry");
2364 		return QDF_STATUS_E_NOMEM;
2365 	}
2366 
2367 	scan_entry->raw_frame.ptr =
2368 			qdf_mem_malloc_atomic(frame_len);
2369 	if (!scan_entry->raw_frame.ptr) {
2370 		scm_err("failed to allocate memory for frame");
2371 		qdf_mem_free(scan_entry);
2372 		return QDF_STATUS_E_NOMEM;
2373 	}
2374 
2375 	bcn = (struct wlan_bcn_frame *)
2376 			   (frame + sizeof(*hdr));
2377 	hdr = (struct wlan_frame_hdr *)frame;
2378 
2379 	/* update timestamp in nanoseconds needed by kernel layers */
2380 	scan_entry->boottime_ns = qdf_get_bootbased_boottime_ns();
2381 
2382 	scan_entry->frm_subtype = frm_subtype;
2383 	qdf_mem_copy(scan_entry->bssid.bytes,
2384 		hdr->i_addr3, QDF_MAC_ADDR_SIZE);
2385 	/* Scr addr */
2386 	qdf_mem_copy(scan_entry->mac_addr.bytes,
2387 		hdr->i_addr2, QDF_MAC_ADDR_SIZE);
2388 	scan_entry->seq_num =
2389 		(le16toh(*(uint16_t *)hdr->i_seq) >> WLAN_SEQ_SEQ_SHIFT);
2390 
2391 	scan_entry->snr = rx_param->snr;
2392 	scan_entry->avg_snr = WLAN_SNR_IN(scan_entry->snr);
2393 	scan_entry->rssi_raw = rx_param->rssi;
2394 	scan_entry->avg_rssi = WLAN_RSSI_IN(scan_entry->rssi_raw);
2395 	scan_entry->tsf_delta = rx_param->tsf_delta;
2396 	scan_entry->pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
2397 
2398 	recv_freq = rx_param->chan_freq;
2399 	/* Copy per chain rssi to scan entry */
2400 	qdf_mem_copy(scan_entry->per_chain_rssi, rx_param->rssi_ctl,
2401 		     WLAN_MGMT_TXRX_HOST_MAX_ANTENNA);
2402 	band_mask = BIT(wlan_reg_freq_to_band(recv_freq));
2403 
2404 	if (!wlan_psoc_nif_fw_ext_cap_get(wlan_pdev_get_psoc(pdev),
2405 					  WLAN_SOC_CEXT_HW_DB2DBM)) {
2406 		for (i = 0; i < WLAN_MGMT_TXRX_HOST_MAX_ANTENNA; i++) {
2407 			if (scan_entry->per_chain_rssi[i] !=
2408 			    WLAN_INVALID_PER_CHAIN_SNR)
2409 				scan_entry->per_chain_rssi[i] +=
2410 						WLAN_NOISE_FLOOR_DBM_DEFAULT;
2411 			else
2412 				scan_entry->per_chain_rssi[i] =
2413 						WLAN_INVALID_PER_CHAIN_RSSI;
2414 		}
2415 	}
2416 
2417 	/* store jiffies */
2418 	scan_entry->rrm_parent_tsf = (uint32_t)qdf_system_ticks();
2419 
2420 	scan_entry->bcn_int = le16toh(bcn->beacon_interval);
2421 
2422 	/*
2423 	 * In case if the beacon doesn't have
2424 	 * valid beacon interval falback to def
2425 	 */
2426 	if (!scan_entry->bcn_int)
2427 		scan_entry->bcn_int = 100;
2428 	scan_entry->cap_info.value = le16toh(bcn->capability.value);
2429 	qdf_mem_copy(scan_entry->tsf_info.data,
2430 		bcn->timestamp, 8);
2431 	scan_entry->erp = ERP_NON_ERP_PRESENT;
2432 
2433 	scan_entry->scan_entry_time =
2434 		qdf_mc_timer_get_system_time();
2435 
2436 	scan_entry->raw_frame.len = frame_len;
2437 	qdf_mem_copy(scan_entry->raw_frame.ptr,
2438 		frame, frame_len);
2439 	status = util_scan_populate_bcn_ie_list(pdev, scan_entry, &chan_freq,
2440 						band_mask);
2441 	if (QDF_IS_STATUS_ERROR(status)) {
2442 		scm_debug(QDF_MAC_ADDR_FMT": failed to parse beacon IE",
2443 			  QDF_MAC_ADDR_REF(scan_entry->bssid.bytes));
2444 		qdf_mem_free(scan_entry->raw_frame.ptr);
2445 		qdf_mem_free(scan_entry);
2446 		return QDF_STATUS_E_FAILURE;
2447 	}
2448 
2449 	ssid = (struct ie_ssid *)
2450 		scan_entry->ie_list.ssid;
2451 
2452 	if (ssid && (ssid->ssid_len > WLAN_SSID_MAX_LEN)) {
2453 		qdf_mem_free(scan_entry->raw_frame.ptr);
2454 		qdf_mem_free(scan_entry);
2455 		return QDF_STATUS_E_FAILURE;
2456 	}
2457 
2458 	if (scan_entry->ie_list.p2p)
2459 		scan_entry->is_p2p = true;
2460 
2461 	if (!chan_freq && util_scan_entry_hecap(scan_entry)) {
2462 		status = util_scan_get_chan_from_he_6g_params(pdev, scan_entry,
2463 							      &chan_freq,
2464 							      &is_6g_dup_bcon,
2465 							      band_mask,
2466 							      recv_freq);
2467 		if (QDF_IS_STATUS_ERROR(status)) {
2468 			qdf_mem_free(scan_entry->raw_frame.ptr);
2469 			qdf_mem_free(scan_entry);
2470 			return QDF_STATUS_E_FAILURE;
2471 		}
2472 	}
2473 
2474 	if (chan_freq)
2475 		scan_entry->channel.chan_freq = chan_freq;
2476 
2477 	/* If no channel info is present in beacon use meta channel */
2478 	if (!scan_entry->channel.chan_freq) {
2479 		scan_entry->channel.chan_freq = recv_freq;
2480 	} else if (recv_freq !=
2481 	   scan_entry->channel.chan_freq) {
2482 		if (!wlan_reg_is_49ghz_freq(scan_entry->channel.chan_freq) &&
2483 		    !is_6g_dup_bcon)
2484 			scan_entry->channel_mismatch = true;
2485 	}
2486 
2487 	if (util_scan_is_hidden_ssid(ssid)) {
2488 		scan_entry->ie_list.ssid = NULL;
2489 		scan_entry->is_hidden_ssid = true;
2490 	} else {
2491 		qdf_mem_copy(scan_entry->ssid.ssid,
2492 				ssid->ssid, ssid->ssid_len);
2493 		scan_entry->ssid.length = ssid->ssid_len;
2494 		scan_entry->hidden_ssid_timestamp =
2495 			scan_entry->scan_entry_time;
2496 	}
2497 	qdf_mem_copy(&scan_entry->mbssid_info, mbssid_info,
2498 		     sizeof(scan_entry->mbssid_info));
2499 
2500 	scan_entry->phy_mode = util_scan_get_phymode(pdev, scan_entry);
2501 
2502 	scan_entry->nss = util_scan_scm_calc_nss_supported_by_ap(scan_entry);
2503 	scm_fill_adaptive_11r_cap(scan_entry);
2504 	util_scan_set_security(scan_entry);
2505 
2506 	util_scan_scm_update_bss_with_esp_data(scan_entry);
2507 	qbss_load = (struct qbss_load_ie *)
2508 			util_scan_entry_qbssload(scan_entry);
2509 	if (qbss_load)
2510 		scan_entry->qbss_chan_load = qbss_load->qbss_chan_load;
2511 
2512 	scan_node = qdf_mem_malloc_atomic(sizeof(*scan_node));
2513 	if (!scan_node) {
2514 		qdf_mem_free(scan_entry->raw_frame.ptr);
2515 		qdf_mem_free(scan_entry);
2516 		return QDF_STATUS_E_FAILURE;
2517 	}
2518 
2519 	util_scan_update_ml_info(scan_entry);
2520 
2521 	scan_node->entry = scan_entry;
2522 	qdf_list_insert_front(scan_list, &scan_node->node);
2523 
2524 	return status;
2525 }
2526 
2527 #ifdef WLAN_FEATURE_MBSSID
2528 /*
2529  * util_is_noninh_ie() - find the noninhertance information element
2530  * in the received frame's IE list, so that we can stop inheriting that IE
2531  * in the caller function.
2532  *
2533  * @elem_id: Element ID in the received frame's IE, which is being processed.
2534  * @non_inh_list: pointer to the non inherited list of element IDs or
2535  *                list of extension element IDs.
2536  * @len: Length of non inheritance IE list
2537  *
2538  * Return: False if the element ID is not found or else return true
2539  */
2540 static bool util_is_noninh_ie(uint8_t elem_id,
2541 			      uint8_t *non_inh_list,
2542 			      int8_t len)
2543 {
2544 	int count;
2545 
2546 	for (count = 0; count < len; count++) {
2547 		if (elem_id == non_inh_list[count])
2548 			return true;
2549 	}
2550 
2551 	return false;
2552 }
2553 
2554 /*
2555  * util_scan_find_noninheritance_ie() - find noninheritance information element
2556  * This block of code is to identify if there is any non-inheritance element
2557  * present as part of the nontransmitted BSSID profile.
2558  * @elem_id: element id
2559  * @ies: pointer consisting of IEs
2560  * @len: IE length
2561  *
2562  * Return: NULL if the element ID is not found or if IE pointer is NULL else
2563  * pointer to the first byte of the requested element
2564  */
2565 static uint8_t
2566 *util_scan_find_noninheritance_ie(uint8_t elem_id, uint8_t *ies,
2567 				  int32_t len)
2568 {
2569 	if (!ies)
2570 		return NULL;
2571 
2572 	while (len >= MIN_IE_LEN && len >= ies[TAG_LEN_POS] + MIN_IE_LEN) {
2573 		if ((ies[ID_POS] == elem_id) &&
2574 		    (ies[ELEM_ID_EXTN_POS] ==
2575 		     WLAN_EXTN_ELEMID_NONINHERITANCE)) {
2576 			return ies;
2577 		}
2578 		len -= ies[TAG_LEN_POS] + MIN_IE_LEN;
2579 		ies += ies[TAG_LEN_POS] + MIN_IE_LEN;
2580 	}
2581 
2582 	return NULL;
2583 }
2584 #endif
2585 
2586 /*
2587  * util_scan_find_ie() - find information element
2588  * @eid: element id
2589  * @ies: pointer consisting of IEs
2590  * @len: IE length
2591  *
2592  * Return: NULL if the element ID is not found or if IE pointer is NULL else
2593  * pointer to the first byte of the requested element
2594  */
2595 static uint8_t *util_scan_find_ie(uint8_t eid, uint8_t *ies,
2596 				  int32_t len)
2597 {
2598 	if (!ies)
2599 		return NULL;
2600 
2601 	while (len >= 2 && len >= ies[1] + 2) {
2602 		if (ies[0] == eid)
2603 			return ies;
2604 		len -= ies[1] + 2;
2605 		ies += ies[1] + 2;
2606 	}
2607 
2608 	return NULL;
2609 }
2610 
2611 #ifdef WLAN_FEATURE_MBSSID
2612 static void util_gen_new_bssid(uint8_t *bssid, uint8_t max_bssid,
2613 			       uint8_t mbssid_index,
2614 			       uint8_t *new_bssid_addr)
2615 {
2616 	uint8_t lsb_n;
2617 	int i;
2618 
2619 	for (i = 0; i < QDF_MAC_ADDR_SIZE; i++)
2620 		new_bssid_addr[i] = bssid[i];
2621 
2622 	lsb_n = new_bssid_addr[5] & ((1 << max_bssid) - 1);
2623 
2624 	new_bssid_addr[5] &= ~((1 << max_bssid) - 1);
2625 	new_bssid_addr[5] |= (lsb_n + mbssid_index) % (1 << max_bssid);
2626 }
2627 
2628 /*
2629  * util_parse_noninheritance_list() - This block of code will be executed only
2630  * if there is a valid non inheritance IE present in the nontx profile.
2631  * Host need not inherit those list of element IDs and list of element ID
2632  * extensions from the transmitted BSSID profile.
2633  * Since non-inheritance element is an element ID extension, it should
2634  * be part of extension element. So first we need to find if there are
2635  * any extension element present in the nontransmitted BSSID profile.
2636  * @extn_elem: If valid, it points to the element ID field of
2637  * extension element tag in the nontransmitted BSSID profile.
2638  * It may or may not have non inheritance tag present.
2639  *      _____________________________________________
2640  *     |         |       |       |List of|List of    |
2641  *     | Element |Length |Element|Element|Element ID |
2642  *     |  ID     |       |ID extn| IDs   |Extension  |
2643  *     |_________|_______|_______|_______|___________|
2644  * List of Element IDs:
2645  *      __________________
2646  *     |         |        |
2647  *     |  Length |Element |
2648  *     |         |ID List |
2649  *     |_________|________|
2650  * List of Element ID Extensions:
2651  *      __________________________
2652  *     |         |                |
2653  *     |  Length |Element ID      |
2654  *     |         |extension List  |
2655  *     |_________|________________|
2656  * @elem_list: Element ID list
2657  * @extn_elem_list: Element ID exiension list
2658  * @non_inheritance_ie: Non inheritance IE information
2659  */
2660 
2661 static void util_parse_noninheritance_list(uint8_t *extn_elem,
2662 					   uint8_t **elem_list,
2663 					   uint8_t **extn_elem_list,
2664 					   struct non_inheritance_ie *ninh)
2665 {
2666 	int8_t extn_rem_len = 0;
2667 
2668 	if (extn_elem[ELEM_ID_LIST_LEN_POS] < extn_elem[TAG_LEN_POS]) {
2669 		/*
2670 		 * extn_rem_len represents the number of bytes after
2671 		 * the length subfield of list of Element IDs.
2672 		 * So here, extn_rem_len should be equal to
2673 		 * Element ID list + Length subfield of Element ID
2674 		 * extension list + Element ID extension list.
2675 		 *
2676 		 * Here we have taken two pointers pointing to the
2677 		 * element ID list and element ID extension list
2678 		 * which we will use to detect the same elements
2679 		 * in the transmitted BSSID profile and choose not
2680 		 * to inherit those elements while constructing the
2681 		 * frame for nontransmitted BSSID profile.
2682 		 */
2683 		extn_rem_len = extn_elem[TAG_LEN_POS] - MIN_IE_LEN;
2684 		ninh->non_inherit = true;
2685 
2686 		if (extn_rem_len && extn_elem[ELEM_ID_LIST_LEN_POS]) {
2687 			if (extn_rem_len >= extn_elem[ELEM_ID_LIST_LEN_POS]) {
2688 				ninh->list_len =
2689 					extn_elem[ELEM_ID_LIST_LEN_POS];
2690 				*elem_list = extn_elem + ELEM_ID_LIST_POS;
2691 				extn_rem_len -= ninh->list_len;
2692 			} else {
2693 				/*
2694 				 * Corrupt frame. length subfield of
2695 				 * element ID list is greater than
2696 				 * what it should be. Go ahead with
2697 				 * frame generation but do not honour
2698 				 * the non inheritance part. Also, mark
2699 				 * the element ID in subcopy as 0, so
2700 				 * that this element info will not
2701 				 * be copied.
2702 				 */
2703 				ninh->non_inherit = false;
2704 				extn_elem[0] = 0;
2705 			}
2706 		}
2707 
2708 		extn_rem_len--;
2709 		if (extn_rem_len > 0) {
2710 			if (!ninh->list_len) {
2711 				ninh->extn_len =
2712 					extn_elem[ELEM_ID_LIST_LEN_POS + 1];
2713 			} else {
2714 				ninh->extn_len =
2715 					extn_elem[ELEM_ID_LIST_POS +
2716 					ninh->list_len];
2717 			}
2718 
2719 			if (extn_rem_len != ninh->extn_len) {
2720 				/*
2721 				 * Corrupt frame. length subfield of
2722 				 * element ID extn list is not
2723 				 * what it should be. Go ahead with
2724 				 * frame generation but do not honour
2725 				 * the non inheritance part. Also, mark
2726 				 * the element ID in subcopy as 0, so
2727 				 * that this element info will not
2728 				 * be copied.
2729 				 */
2730 				ninh->non_inherit = false;
2731 				extn_elem[0] = 0;
2732 			}
2733 
2734 			if (ninh->extn_len) {
2735 				*extn_elem_list =
2736 					(extn_elem + ninh->list_len +
2737 					 ELEM_ID_LIST_POS + 1);
2738 			}
2739 		}
2740 	}
2741 }
2742 
2743 #ifdef WLAN_FEATURE_11BE_MLO
2744 /**
2745  * util_handle_rnr_ie_for_mbssid() - parse and modify RNR IE for MBSSID feature
2746  * @rnr: The pointer to RNR IE
2747  * @bssid_index: BSSID index from MBSSID index IE
2748  * @pos: The buffer pointer to save the transformed RNR IE, caller is expected
2749  *       to supply a buffer that is at least as big as @rnr
2750  *
2751  * Per the description about Neighbor AP Information field about MLD
2752  * parameters subfield in section 9.4.2.170.2 of Draft P802.11be_D1.4.
2753  * If the reported AP is affiliated with the same MLD of the reporting AP,
2754  * the TBTT information is skipped; If the reported AP is affiliated with
2755  * the same MLD of the nontransmitted BSSID, the TBTT information is
2756  * copied and the MLD ID is changed to 0.
2757  *
2758  * Return: Length of the element written to @pos
2759  */
2760 static int util_handle_rnr_ie_for_mbssid(const uint8_t *rnr,
2761 					 uint8_t bssid_index, uint8_t *pos)
2762 {
2763 	size_t rnr_len;
2764 	const uint8_t *data, *rnr_end;
2765 	uint8_t *rnr_new;
2766 	struct neighbor_ap_info_field *neighbor_ap_info;
2767 	struct rnr_mld_info *mld_param;
2768 	uint8_t tbtt_type, tbtt_len, tbtt_count;
2769 	uint8_t mld_pos, mld_id;
2770 	int32_t i, copy_len;
2771 	/* The count of TBTT info field whose MLD ID equals to 0 in a neighbor
2772 	 * AP information field.
2773 	 */
2774 	uint32_t tbtt_info_field_count;
2775 	/* The total bytes of TBTT info fields whose MLD ID equals to 0 in
2776 	 * current RNR IE.
2777 	 */
2778 	uint32_t tbtt_info_field_len = 0;
2779 	uint8_t nbr_ap_info_len = sizeof(struct neighbor_ap_info_field);
2780 
2781 	rnr_len = rnr[TAG_LEN_POS];
2782 	rnr_end = rnr + rnr_len + MIN_IE_LEN;
2783 	rnr_new = pos;
2784 	qdf_mem_copy(pos, rnr, MIN_IE_LEN);
2785 	pos += MIN_IE_LEN;
2786 
2787 	data = rnr + PAYLOAD_START_POS;
2788 	while (data < rnr_end) {
2789 		neighbor_ap_info = (struct neighbor_ap_info_field *)data;
2790 		tbtt_count = neighbor_ap_info->tbtt_header.tbtt_info_count;
2791 		tbtt_len = neighbor_ap_info->tbtt_header.tbtt_info_length;
2792 		tbtt_type = neighbor_ap_info->tbtt_header.tbbt_info_fieldtype;
2793 		scm_debug("channel number %d, op class %d, bssid_index %d",
2794 			  neighbor_ap_info->channel_number,
2795 			  neighbor_ap_info->operting_class, bssid_index);
2796 		scm_debug("tbtt_count %d, tbtt_length %d, tbtt_type %d",
2797 			  tbtt_count, tbtt_len, tbtt_type);
2798 
2799 		copy_len = tbtt_len * (tbtt_count + 1) +
2800 			   nbr_ap_info_len;
2801 		if (data + copy_len > rnr_end)
2802 			return 0;
2803 
2804 		if (tbtt_len >=
2805 		    TBTT_NEIGHBOR_AP_BSSID_S_SSID_BSS_PARAM_20MHZ_PSD_MLD_PARAM)
2806 			mld_pos =
2807 			     TBTT_NEIGHBOR_AP_BSSID_S_SSID_BSS_PARAM_20MHZ_PSD;
2808 		else
2809 			mld_pos = 0;
2810 
2811 		/* If MLD params do not exist, copy this neighbor AP
2812 		 * information field.
2813 		 * Per Draft P802.11be_D1.4, tbtt_type value 1, 2 and 3
2814 		 * are reserved,
2815 		 */
2816 		if (mld_pos == 0 || tbtt_type != 0) {
2817 			scm_debug("no MLD params, tbtt_type %d", tbtt_type);
2818 			qdf_mem_copy(pos, data, copy_len);
2819 			pos += copy_len;
2820 			data += copy_len;
2821 			continue;
2822 		}
2823 
2824 		qdf_mem_copy(pos, data, nbr_ap_info_len);
2825 		neighbor_ap_info = (struct neighbor_ap_info_field *)pos;
2826 		pos += nbr_ap_info_len;
2827 		data += nbr_ap_info_len;
2828 
2829 		tbtt_info_field_count = 0;
2830 		for (i = 0; i < tbtt_count + 1; i++) {
2831 			mld_param = (struct rnr_mld_info *)&data[mld_pos];
2832 			mld_id = mld_param->mld_id;
2833 
2834 			/* Refer to Draft P802.11be_D1.4
2835 			 * 9.4.2.170.2 Neighbor AP Information field about
2836 			 * MLD parameters subfield
2837 			 */
2838 			if (mld_id == 0) {
2839 				/* Skip this TBTT information since this
2840 				 * reported AP is affiliated with the same MLD
2841 				 * of the reporting AP who sending the frame
2842 				 * carrying this element.
2843 				 */
2844 				tbtt_info_field_len += tbtt_len;
2845 				data += tbtt_len;
2846 				tbtt_info_field_count++;
2847 			} else if (mld_id == bssid_index) {
2848 				/* Copy this TBTT information and change MLD
2849 				 * to 0 as this reported AP is affiliated with
2850 				 * the same MLD of the nontransmitted BSSID.
2851 				 */
2852 				qdf_mem_copy(pos, data, tbtt_len);
2853 				mld_param =
2854 					(struct rnr_mld_info *)&pos[mld_pos];
2855 				scm_debug("change MLD ID from %d to 0",
2856 					  mld_param->mld_id);
2857 				mld_param->mld_id = 0;
2858 				data += tbtt_len;
2859 				pos += tbtt_len;
2860 			} else {
2861 				qdf_mem_copy(pos, data, tbtt_len);
2862 				data += tbtt_len;
2863 				pos += tbtt_len;
2864 			}
2865 		}
2866 
2867 		scm_debug("skip %d neighbor info", tbtt_info_field_count);
2868 		if (tbtt_info_field_count == (tbtt_count + 1)) {
2869 			/* If all the TBTT information are skipped, then also
2870 			 * revert the neighbor AP info which has been copied.
2871 			 */
2872 			pos -= nbr_ap_info_len;
2873 			tbtt_info_field_len += nbr_ap_info_len;
2874 		} else {
2875 			neighbor_ap_info->tbtt_header.tbtt_info_count -=
2876 							tbtt_info_field_count;
2877 		}
2878 	}
2879 
2880 	rnr_new[TAG_LEN_POS] = rnr_len - tbtt_info_field_len;
2881 	if (rnr_new[TAG_LEN_POS] > 0)
2882 		rnr_len = rnr_new[TAG_LEN_POS] + MIN_IE_LEN;
2883 	else
2884 		rnr_len = 0;
2885 
2886 	return rnr_len;
2887 }
2888 #else
2889 static int util_handle_rnr_ie_for_mbssid(const uint8_t *rnr,
2890 					 uint8_t bssid_index, uint8_t *pos)
2891 {
2892 	return 0;
2893 }
2894 #endif
2895 
2896 static uint32_t util_gen_new_ie(uint8_t *ie, uint32_t ielen,
2897 				uint8_t *subelement,
2898 				size_t subie_len, uint8_t *new_ie,
2899 				uint8_t bssid_index)
2900 {
2901 	uint8_t *pos, *tmp;
2902 	const uint8_t *tmp_old, *tmp_new;
2903 	uint8_t *sub_copy, *extn_elem = NULL;
2904 	struct non_inheritance_ie ninh = {0};
2905 	uint8_t *elem_list = NULL, *extn_elem_list = NULL;
2906 	size_t tmp_rem_len;
2907 
2908 	/* copy subelement as we need to change its content to
2909 	 * mark an ie after it is processed.
2910 	 */
2911 	sub_copy = qdf_mem_malloc(subie_len);
2912 	if (!sub_copy)
2913 		return 0;
2914 	qdf_mem_copy(sub_copy, subelement, subie_len);
2915 
2916 	pos = &new_ie[0];
2917 
2918 	/* new ssid */
2919 	tmp_new = util_scan_find_ie(WLAN_ELEMID_SSID, sub_copy, subie_len);
2920 	if (tmp_new) {
2921 		scm_debug(" SSID " QDF_SSID_FMT,
2922 			  QDF_SSID_REF(tmp_new[1],
2923 				       &tmp_new[PAYLOAD_START_POS]));
2924 		if ((pos + tmp_new[1] + MIN_IE_LEN) <=
2925 		    (new_ie + ielen)) {
2926 			qdf_mem_copy(pos, tmp_new,
2927 				     (tmp_new[1] + MIN_IE_LEN));
2928 			pos += (tmp_new[1] + MIN_IE_LEN);
2929 		}
2930 	}
2931 
2932 	extn_elem = util_scan_find_noninheritance_ie(WLAN_ELEMID_EXTN_ELEM,
2933 						     sub_copy, subie_len);
2934 
2935 	if (extn_elem && extn_elem[TAG_LEN_POS]) {
2936 		util_parse_noninheritance_list(extn_elem, &elem_list,
2937 					       &extn_elem_list, &ninh);
2938 	}
2939 
2940 	/* go through IEs in ie (skip SSID) and subelement,
2941 	 * merge them into new_ie
2942 	 */
2943 	tmp_old = util_scan_find_ie(WLAN_ELEMID_SSID, ie, ielen);
2944 	tmp_old = (tmp_old) ? tmp_old + tmp_old[1] + MIN_IE_LEN : ie;
2945 
2946 	while (((tmp_old + tmp_old[1] + MIN_IE_LEN) - ie) <= ielen) {
2947 		ninh.non_inh_ie_found = 0;
2948 		if (ninh.non_inherit) {
2949 			if (ninh.list_len) {
2950 				ninh.non_inh_ie_found =
2951 					util_is_noninh_ie(tmp_old[0],
2952 							  elem_list,
2953 							  ninh.list_len);
2954 			}
2955 
2956 			if (!ninh.non_inh_ie_found &&
2957 			    ninh.extn_len &&
2958 			    (tmp_old[0] == WLAN_ELEMID_EXTN_ELEM)) {
2959 				ninh.non_inh_ie_found =
2960 					util_is_noninh_ie(tmp_old[2],
2961 							  extn_elem_list,
2962 							  ninh.extn_len);
2963 			}
2964 		}
2965 
2966 		if (ninh.non_inh_ie_found || (tmp_old[0] == 0)) {
2967 			tmp_old += tmp_old[1] + MIN_IE_LEN;
2968 			continue;
2969 		}
2970 
2971 		tmp = (uint8_t *)util_scan_find_ie(tmp_old[0], sub_copy,
2972 						   subie_len);
2973 		if (!tmp) {
2974 			/* ie in old ie but not in subelement */
2975 			if (tmp_old[0] == WLAN_ELEMID_REDUCED_NEIGHBOR_REPORT) {
2976 				/* handle rnr ie for mbssid*/
2977 				pos +=
2978 				    util_handle_rnr_ie_for_mbssid(tmp_old,
2979 								  bssid_index,
2980 								  pos);
2981 			} else if (tmp_old[0] != WLAN_ELEMID_MULTIPLE_BSSID) {
2982 				if ((pos + tmp_old[1] + MIN_IE_LEN) <=
2983 				    (new_ie + ielen)) {
2984 					qdf_mem_copy(pos, tmp_old,
2985 						     (tmp_old[1] +
2986 						      MIN_IE_LEN));
2987 					pos += tmp_old[1] + MIN_IE_LEN;
2988 				}
2989 			}
2990 		} else {
2991 			/* ie in transmitting ie also in subelement,
2992 			 * copy from subelement and flag the ie in subelement
2993 			 * as copied (by setting eid field to 0xff).
2994 			 * To determine if the vendor ies are same:
2995 			 * 1. For Cisco OUI, compare only OUI + type
2996 			 * 2. For other OUI, compare OUI + type + subType
2997 			 */
2998 			tmp_rem_len = subie_len - (tmp - sub_copy);
2999 			if (tmp_old[0] == WLAN_ELEMID_VENDOR &&
3000 			    tmp_rem_len >= MIN_VENDOR_TAG_LEN) {
3001 				/* If Vendor IE also presents in STA profile,
3002 				 * then ignore the Vendor IE which is for
3003 				 * reporting STA. It only needs to copy Vendor
3004 				 * IE from STA profile for reported BSSID.
3005 				 * The copy happens when going through the
3006 				 * remaining IEs.
3007 				 */
3008 				;
3009 			} else if (tmp_old[0] == WLAN_ELEMID_EXTN_ELEM) {
3010 				if (tmp_old[PAYLOAD_START_POS] ==
3011 				    tmp[PAYLOAD_START_POS]) {
3012 					/* same ie, copy from subelement */
3013 					if ((pos + tmp[1] + MIN_IE_LEN) <=
3014 					    (new_ie + ielen)) {
3015 						qdf_mem_copy(pos, tmp,
3016 							     tmp[1] +
3017 							     MIN_IE_LEN);
3018 						pos += tmp[1] + MIN_IE_LEN;
3019 						tmp[0] = 0;
3020 					}
3021 				} else {
3022 					if ((pos + tmp_old[1] + MIN_IE_LEN) <=
3023 					    (new_ie + ielen)) {
3024 						qdf_mem_copy(pos, tmp_old,
3025 							     tmp_old[1] +
3026 							     MIN_IE_LEN);
3027 						pos += tmp_old[1] +
3028 							MIN_IE_LEN;
3029 					}
3030 				}
3031 
3032 			} else {
3033 				/* copy ie from subelement into new ie */
3034 				if ((pos + tmp[1] + MIN_IE_LEN) <=
3035 				    (new_ie + ielen)) {
3036 					qdf_mem_copy(pos, tmp,
3037 						     tmp[1] + MIN_IE_LEN);
3038 					pos += tmp[1] + MIN_IE_LEN;
3039 					tmp[0] = 0;
3040 				}
3041 			}
3042 		}
3043 
3044 		if (((tmp_old + tmp_old[1] + MIN_IE_LEN) - ie) >= ielen)
3045 			break;
3046 
3047 		tmp_old += tmp_old[1] + MIN_IE_LEN;
3048 	}
3049 
3050 	/* go through subelement again to check if there is any ie not
3051 	 * copied to new ie, skip ssid, capability, bssid-index ie
3052 	 */
3053 	tmp_new = sub_copy;
3054 	while (((tmp_new + tmp_new[1] + MIN_IE_LEN) - sub_copy) <=
3055 	       subie_len) {
3056 		if (!(tmp_new[0] == WLAN_ELEMID_NONTX_BSSID_CAP ||
3057 		      tmp_new[0] == WLAN_ELEMID_SSID ||
3058 		      tmp_new[0] == WLAN_ELEMID_MULTI_BSSID_IDX ||
3059 		      ((tmp_new[0] == WLAN_ELEMID_EXTN_ELEM) &&
3060 		       (tmp_new[2] == WLAN_EXTN_ELEMID_NONINHERITANCE)))) {
3061 			if ((pos + tmp_new[1] + MIN_IE_LEN) <=
3062 			    (new_ie + ielen)) {
3063 				qdf_mem_copy(pos, tmp_new,
3064 					     tmp_new[1] + MIN_IE_LEN);
3065 				pos += tmp_new[1] + MIN_IE_LEN;
3066 			}
3067 		}
3068 		if (((tmp_new + tmp_new[1] + MIN_IE_LEN) - sub_copy) >=
3069 		    subie_len)
3070 			break;
3071 		tmp_new += tmp_new[1] + MIN_IE_LEN;
3072 	}
3073 
3074 	qdf_mem_free(sub_copy);
3075 
3076 	if (pos > new_ie)
3077 		return pos - new_ie;
3078 	else
3079 		return 0;
3080 }
3081 
3082 static enum nontx_profile_reasoncode
3083 util_handle_nontx_prof(uint8_t *mbssid_elem, uint8_t *subelement,
3084 		       uint8_t *next_subelement,
3085 		       struct scan_mbssid_info *mbssid_info,
3086 		       char *bssid, char *new_bssid)
3087 {
3088 	uint8_t *mbssid_index_ie;
3089 	uint32_t prof_len;
3090 
3091 	prof_len = subelement[TAG_LEN_POS];
3092 	/*
3093 	 * If we are executing the split portion of the nontx
3094 	 * profile present in the subsequent MBSSID, then there
3095 	 * is no need of any sanity check for valid BSS profile
3096 	 */
3097 
3098 	if (mbssid_info->split_prof_continue) {
3099 		if ((subelement[ID_POS] != 0) ||
3100 		    (subelement[TAG_LEN_POS] < SPLIT_PROF_DATA_LEAST_LEN)) {
3101 			return INVALID_SPLIT_PROF;
3102 		}
3103 	} else {
3104 		if ((subelement[ID_POS] != 0) ||
3105 		    (subelement[TAG_LEN_POS] < VALID_ELEM_LEAST_LEN)) {
3106 			/* not a valid BSS profile */
3107 			return INVALID_NONTX_PROF;
3108 		}
3109 	}
3110 
3111 	if (mbssid_info->split_profile) {
3112 		if (next_subelement[PAYLOAD_START_POS] !=
3113 		    WLAN_ELEMID_NONTX_BSSID_CAP) {
3114 			mbssid_info->prof_residue = true;
3115 		}
3116 	}
3117 
3118 	if (!mbssid_info->split_prof_continue &&
3119 	    ((subelement[PAYLOAD_START_POS] != WLAN_ELEMID_NONTX_BSSID_CAP) ||
3120 	     (subelement[NONTX_BSSID_CAP_TAG_LEN_POS] != CAP_INFO_LEN))) {
3121 		/* The first element within the Nontransmitted
3122 		 * BSSID Profile is not the Nontransmitted
3123 		 * BSSID Capability element.
3124 		 */
3125 		return INVALID_NONTX_PROF;
3126 	}
3127 
3128 	/* found a Nontransmitted BSSID Profile */
3129 	mbssid_index_ie =
3130 		util_scan_find_ie(WLAN_ELEMID_MULTI_BSSID_IDX,
3131 				  (subelement + PAYLOAD_START_POS), prof_len);
3132 
3133 	if (!mbssid_index_ie) {
3134 		if (!mbssid_info->prof_residue)
3135 			return INVALID_NONTX_PROF;
3136 
3137 		mbssid_info->skip_bssid_copy = true;
3138 	} else if ((mbssid_index_ie[TAG_LEN_POS] < 1) ||
3139 		   (mbssid_index_ie[BSS_INDEX_POS] == 0)) {
3140 		/* No valid Multiple BSSID-Index element */
3141 		return INVALID_NONTX_PROF;
3142 	}
3143 
3144 	if (!mbssid_info->skip_bssid_copy) {
3145 		qdf_mem_copy(mbssid_info->trans_bssid,
3146 			     bssid, QDF_MAC_ADDR_SIZE);
3147 		mbssid_info->profile_num =
3148 			mbssid_index_ie[BSS_INDEX_POS];
3149 		util_gen_new_bssid(bssid,
3150 				   mbssid_elem[MBSSID_INDICATOR_POS],
3151 				   mbssid_index_ie[BSS_INDEX_POS],
3152 				   new_bssid);
3153 	}
3154 	/* In single MBSS IE, there could be subelement holding
3155 	 * remaining vendor IEs of non tx profile from last MBSS IE
3156 	 * [split profile] and new non tx profile, hence reset
3157 	 * skip_bssid_copy flag after each subelement processing
3158 	 */
3159 	mbssid_info->skip_bssid_copy = false;
3160 	return VALID_NONTX_PROF;
3161 }
3162 
3163 /*
3164  * What's split profile:
3165  *  If any nontransmitted BSSID profile is fragmented across
3166  * multiple MBSSID elements, then it is called split profile.
3167  * For a split profile to exist we need to have at least two
3168  * MBSSID elements as part of the RX beacon or probe response
3169  * Hence, first we need to identify the next MBSSID element
3170  * and check for the 5th bit from the starting of the next
3171  * MBSSID IE and if it does not have Nontransmitted BSSID
3172  * capability element, then it's a split profile case.
3173  */
3174 static bool util_scan_is_split_prof_found(uint8_t *next_elem,
3175 					  uint8_t *ie, uint32_t ielen)
3176 {
3177 	uint8_t *next_mbssid_elem;
3178 
3179 	if (next_elem[0] == WLAN_ELEMID_MULTIPLE_BSSID) {
3180 		if ((next_elem[TAG_LEN_POS] >= VALID_ELEM_LEAST_LEN) &&
3181 		    (next_elem[SUBELEM_DATA_POS_FROM_MBSSID] !=
3182 		     WLAN_ELEMID_NONTX_BSSID_CAP)) {
3183 			return true;
3184 		}
3185 	} else {
3186 		next_mbssid_elem =
3187 			util_scan_find_ie(WLAN_ELEMID_MULTIPLE_BSSID,
3188 					  next_elem,
3189 					  ielen - (next_elem - ie));
3190 		if (!next_mbssid_elem)
3191 			return false;
3192 
3193 		if ((next_mbssid_elem[TAG_LEN_POS] >= VALID_ELEM_LEAST_LEN) &&
3194 		    (next_mbssid_elem[SUBELEM_DATA_POS_FROM_MBSSID] !=
3195 		     WLAN_ELEMID_NONTX_BSSID_CAP)) {
3196 			return true;
3197 		}
3198 	}
3199 
3200 	return false;
3201 }
3202 
3203 static QDF_STATUS util_scan_parse_mbssid(struct wlan_objmgr_pdev *pdev,
3204 					 uint8_t *frame, qdf_size_t frame_len,
3205 					 uint32_t frm_subtype,
3206 					 struct mgmt_rx_event_params *rx_param,
3207 					 qdf_list_t *scan_list)
3208 {
3209 	struct wlan_bcn_frame *bcn;
3210 	struct wlan_frame_hdr *hdr;
3211 	struct scan_mbssid_info mbssid_info = {0};
3212 	QDF_STATUS status;
3213 	uint8_t *pos, *subelement, *next_elem;
3214 	uint8_t *mbssid_elem;
3215 	uint32_t subie_len, new_ie_len, ielen;
3216 	uint8_t *next_subelement = NULL;
3217 	uint8_t new_bssid[QDF_MAC_ADDR_SIZE], bssid[QDF_MAC_ADDR_SIZE];
3218 	uint8_t *new_ie, *split_prof_start = NULL, *split_prof_end = NULL;
3219 	uint8_t *ie, *new_frame = NULL;
3220 	int new_frame_len = 0, split_prof_len = 0;
3221 	enum nontx_profile_reasoncode retval;
3222 	uint8_t *nontx_profile = NULL;
3223 
3224 	hdr = (struct wlan_frame_hdr *)frame;
3225 	bcn = (struct wlan_bcn_frame *)(frame + sizeof(struct wlan_frame_hdr));
3226 	ie = (uint8_t *)&bcn->ie;
3227 	ielen = (uint16_t)(frame_len -
3228 			   sizeof(struct wlan_frame_hdr) -
3229 			   offsetof(struct wlan_bcn_frame, ie));
3230 	qdf_mem_copy(bssid, hdr->i_addr3, QDF_MAC_ADDR_SIZE);
3231 
3232 	if (!util_scan_find_ie(WLAN_ELEMID_MULTIPLE_BSSID, ie, ielen))
3233 		return QDF_STATUS_E_FAILURE;
3234 
3235 	pos = ie;
3236 
3237 	new_ie = qdf_mem_malloc(ielen);
3238 	if (!new_ie)
3239 		return QDF_STATUS_E_NOMEM;
3240 
3241 	while (pos < (ie + ielen + MIN_IE_LEN)) {
3242 		mbssid_elem =
3243 			util_scan_find_ie(WLAN_ELEMID_MULTIPLE_BSSID, pos,
3244 					  ielen - (pos - ie));
3245 		if (!mbssid_elem)
3246 			break;
3247 
3248 		mbssid_info.profile_count =
3249 			(1 << mbssid_elem[MBSSID_INDICATOR_POS]);
3250 
3251 		next_elem =
3252 			mbssid_elem + mbssid_elem[TAG_LEN_POS] + MIN_IE_LEN;
3253 
3254 		/* Skip Element ID, Len, MaxBSSID Indicator */
3255 		if (!mbssid_info.split_profile &&
3256 		    (mbssid_elem[TAG_LEN_POS] < VALID_ELEM_LEAST_LEN)) {
3257 			break;
3258 		}
3259 
3260 		/*
3261 		 * Find if the next IE is MBSSID, if not, then scan through
3262 		 * the IE list and find the next MBSSID tag, if present.
3263 		 * Once we find the MBSSID tag, check if this MBSSID tag has
3264 		 * the other fragmented part of the non Tx profile.
3265 		 */
3266 
3267 		mbssid_info.split_profile =
3268 			util_scan_is_split_prof_found(next_elem, ie, ielen);
3269 
3270 		for (subelement = mbssid_elem + SUBELEMENT_START_POS;
3271 		     subelement < (next_elem - 1);
3272 		     subelement += MIN_IE_LEN + subelement[TAG_LEN_POS]) {
3273 			subie_len = subelement[TAG_LEN_POS];
3274 
3275 			/*
3276 			 * if prof_residue is true, that means we are
3277 			 * in the continuation of the fragmented profile part,
3278 			 * present in the next MBSSD IE else this profile
3279 			 * is a non fragmented non tx BSSID profile.
3280 			 */
3281 
3282 			if (mbssid_info.prof_residue)
3283 				mbssid_info.split_prof_continue = true;
3284 			else
3285 				mbssid_info.split_prof_continue = false;
3286 
3287 			if (subie_len > MAX_SUBELEM_LEN) {
3288 				scm_err_rl("Corrupt frame with subie_len: %d\n"
3289 					   "split_prof_continue: %d\n"
3290 					   "prof_residue: %d\n",
3291 					   subie_len,
3292 					   mbssid_info.split_prof_continue,
3293 					   mbssid_info.prof_residue);
3294 				if (mbssid_info.split_prof_continue) {
3295 					qdf_mem_free(split_prof_start);
3296 					split_prof_start = NULL;
3297 				}
3298 
3299 				qdf_mem_free(new_ie);
3300 				return QDF_STATUS_E_INVAL;
3301 			}
3302 
3303 			if ((next_elem - subelement) <
3304 			    (MIN_IE_LEN + subie_len))
3305 				break;
3306 
3307 			next_subelement = subelement + subie_len + MIN_IE_LEN;
3308 			retval = util_handle_nontx_prof(mbssid_elem, subelement,
3309 							next_subelement,
3310 							&mbssid_info,
3311 							bssid, new_bssid);
3312 
3313 			if (retval == INVALID_SPLIT_PROF) {
3314 				scm_err_rl("Corrupt frame with ID_POS: %d\n"
3315 					   "TAG_LEN_POS: %d\n",
3316 					   subelement[ID_POS],
3317 					   subelement[TAG_LEN_POS]);
3318 				qdf_mem_free(split_prof_start);
3319 				split_prof_start = NULL;
3320 				qdf_mem_free(new_ie);
3321 				return QDF_STATUS_E_INVAL;
3322 			} else if (retval == INVALID_NONTX_PROF) {
3323 				continue;
3324 			}
3325 
3326 			/*
3327 			 * Merging parts of nontx profile-
3328 			 * Just for understanding, let's make an assumption
3329 			 * that nontx profile is fragmented across MBSSIE1
3330 			 * and MBSSIE2.
3331 			 * mbssid_info.prof_residue being set indicates
3332 			 * that the ongoing nontx profile is part of split
3333 			 * profile, whose other fragmented part is present
3334 			 * in MBSSIE2.
3335 			 * So once prof_residue is set, we need to
3336 			 * identify whether we are accessing the split
3337 			 * profile in MBSSIE1 or MBSSIE2.
3338 			 * If we are in MBSSIE1, then copy the part of split
3339 			 * profile from MBSSIE1 into a new buffer and then
3340 			 * move to the next part of the split profile which
3341 			 * is present in MBSSIE2 and append that part into
3342 			 * the new buffer.
3343 			 * Once the full profile is accumulated, go ahead with
3344 			 * the ie generation and length calculation of the
3345 			 * new frame.
3346 			 */
3347 
3348 			if (mbssid_info.prof_residue) {
3349 				if (!mbssid_info.split_prof_continue) {
3350 					split_prof_start =
3351 						qdf_mem_malloc(ielen);
3352 					if (!split_prof_start) {
3353 						scm_err_rl("Malloc failed");
3354 						qdf_mem_free(new_ie);
3355 						return QDF_STATUS_E_NOMEM;
3356 					}
3357 
3358 					qdf_mem_copy(split_prof_start,
3359 						     subelement,
3360 						     (subie_len +
3361 						      MIN_IE_LEN));
3362 					split_prof_end = (split_prof_start +
3363 							  subie_len +
3364 							  MIN_IE_LEN);
3365 					break;
3366 				}
3367 
3368 				/*
3369 				 * Currently we are accessing other part of the
3370 				 * split profile present in the subsequent
3371 				 * MBSSIE. There is a possibility that one
3372 				 * non tx profile is spread across more than
3373 				 * two MBSSID tag as well. This code will
3374 				 * handle such scenario.
3375 				 */
3376 
3377 				if (split_prof_end) {
3378 					qdf_mem_copy(split_prof_end,
3379 						     (subelement + MIN_IE_LEN),
3380 						     subie_len);
3381 					split_prof_end += subie_len;
3382 				}
3383 
3384 				/*
3385 				 * When to stop the process of accumulating
3386 				 * parts of split profile, is decided by
3387 				 * mbssid_info.prof_residue. prof_residue
3388 				 * could be made false if there is not any
3389 				 * continuation of the split profile.
3390 				 * which could be identified by two factors
3391 				 * 1. By checking if the next MBSSIE's first
3392 				 * non tx profile is not a fragmented one or
3393 				 * 2. there is a probability that first
3394 				 * subelement of MBSSIE2 is end if split
3395 				 * profile and the next subelement of MBSSIE2
3396 				 * is a non split one.
3397 				 */
3398 
3399 				if (!mbssid_info.split_profile ||
3400 				    (next_subelement[PAYLOAD_START_POS] ==
3401 				     WLAN_ELEMID_NONTX_BSSID_CAP)) {
3402 					mbssid_info.prof_residue = false;
3403 				}
3404 
3405 				/*
3406 				 * Until above mentioned conditions are met,
3407 				 * we need to iterate and keep accumulating
3408 				 * the split profile contents.
3409 				 */
3410 
3411 				if (mbssid_info.prof_residue)
3412 					break;
3413 
3414 				if (split_prof_end) {
3415 					split_prof_len =
3416 						(split_prof_end -
3417 						 split_prof_start - MIN_IE_LEN);
3418 				}
3419 			}
3420 
3421 			if (mbssid_info.split_prof_continue) {
3422 				nontx_profile = split_prof_start;
3423 				subie_len = split_prof_len;
3424 			} else {
3425 				nontx_profile = subelement;
3426 			}
3427 
3428 			new_ie_len =
3429 				util_gen_new_ie(ie, ielen,
3430 						(nontx_profile +
3431 						 PAYLOAD_START_POS),
3432 						subie_len, new_ie,
3433 						mbssid_info.profile_num);
3434 
3435 			if (!new_ie_len) {
3436 				if (mbssid_info.split_prof_continue) {
3437 					qdf_mem_free(split_prof_start);
3438 					split_prof_start = NULL;
3439 				}
3440 				continue;
3441 			}
3442 
3443 			new_frame_len = frame_len - ielen + new_ie_len;
3444 
3445 			if (new_frame_len < 0 || new_frame_len > frame_len) {
3446 				if (mbssid_info.split_prof_continue) {
3447 					qdf_mem_free(split_prof_start);
3448 					split_prof_start = NULL;
3449 				}
3450 				qdf_mem_free(new_ie);
3451 				scm_err("Invalid frame:Stop MBSSIE parsing");
3452 				scm_err("Frame_len: %zu,ielen:%u,new_ie_len:%u",
3453 					frame_len, ielen, new_ie_len);
3454 				return QDF_STATUS_E_INVAL;
3455 			}
3456 
3457 			new_frame = qdf_mem_malloc(new_frame_len);
3458 			if (!new_frame) {
3459 				if (mbssid_info.split_prof_continue) {
3460 					qdf_mem_free(split_prof_start);
3461 					split_prof_start = NULL;
3462 				}
3463 				qdf_mem_free(new_ie);
3464 				scm_err_rl("Malloc for new_frame failed");
3465 				scm_err_rl("split_prof_continue: %d",
3466 					   mbssid_info.split_prof_continue);
3467 				return QDF_STATUS_E_NOMEM;
3468 			}
3469 
3470 			/*
3471 			 * Copy the header(24byte), timestamp(8 byte),
3472 			 * beaconinterval(2byte) and capability(2byte)
3473 			 */
3474 			qdf_mem_copy(new_frame, frame, FIXED_LENGTH);
3475 			/* Copy the new ie generated from MBSSID profile*/
3476 			hdr = (struct wlan_frame_hdr *)new_frame;
3477 			qdf_mem_copy(hdr->i_addr2, new_bssid,
3478 				     QDF_MAC_ADDR_SIZE);
3479 			qdf_mem_copy(hdr->i_addr3, new_bssid,
3480 				     QDF_MAC_ADDR_SIZE);
3481 			bcn = (struct wlan_bcn_frame *)
3482 				(new_frame + sizeof(struct wlan_frame_hdr));
3483 			/* update the non-tx capability */
3484 			qdf_mem_copy(&bcn->capability,
3485 				     nontx_profile + CAP_INFO_POS,
3486 				     CAP_INFO_LEN);
3487 
3488 			/* Copy the new ie generated from MBSSID profile*/
3489 			qdf_mem_copy(new_frame +
3490 				     offsetof(struct wlan_bcn_frame, ie) +
3491 				     sizeof(struct wlan_frame_hdr),
3492 				     new_ie, new_ie_len);
3493 			status = util_scan_gen_scan_entry(pdev, new_frame,
3494 							  new_frame_len,
3495 							  frm_subtype,
3496 							  rx_param,
3497 							  &mbssid_info,
3498 							  scan_list);
3499 			if (QDF_IS_STATUS_ERROR(status)) {
3500 				if (mbssid_info.split_prof_continue) {
3501 					qdf_mem_free(split_prof_start);
3502 					split_prof_start = NULL;
3503 					qdf_mem_zero(&mbssid_info,
3504 						     sizeof(mbssid_info));
3505 				}
3506 				qdf_mem_free(new_frame);
3507 				scm_err_rl("failed to generate a scan entry");
3508 				scm_err_rl("split_prof_continue: %d",
3509 					   mbssid_info.split_prof_continue);
3510 				break;
3511 			}
3512 			/* scan entry makes its own copy so free the frame*/
3513 			if (mbssid_info.split_prof_continue) {
3514 				qdf_mem_free(split_prof_start);
3515 				split_prof_start = NULL;
3516 			}
3517 			qdf_mem_free(new_frame);
3518 		}
3519 
3520 		pos = next_elem;
3521 	}
3522 	qdf_mem_free(new_ie);
3523 
3524 	if (split_prof_start)
3525 		qdf_mem_free(split_prof_start);
3526 
3527 	return QDF_STATUS_SUCCESS;
3528 }
3529 #else
3530 static QDF_STATUS util_scan_parse_mbssid(struct wlan_objmgr_pdev *pdev,
3531 					 uint8_t *frame, qdf_size_t frame_len,
3532 					 uint32_t frm_subtype,
3533 					 struct mgmt_rx_event_params *rx_param,
3534 					 qdf_list_t *scan_list)
3535 {
3536 	return QDF_STATUS_SUCCESS;
3537 }
3538 #endif
3539 
3540 #if defined(WLAN_FEATURE_11BE) && defined(WLAN_FEATURE_11BE_MLO_MBSSID)
3541 /*
3542  * util_scan_gen_txvap_scan_entry() - Strip out the MBSSID tag from the received
3543  * frame and update the modified frame length before generating a scan entry.
3544  * It is redundant to have MBSSID information as part of the TX vap/ profile
3545  * specific scan entry.
3546  *
3547  * @pdev: pdev context
3548  * @frame: Unsoiled frame passed from util_scan_parse_beacon_frame()
3549  * @frame_len: Length of the unsoiled frame
3550  * @ie_list: Points to the start of IE list in parent/ unsoiled frame
3551  * @ielen: Length of the complete IE list from parent/ unsoiled frame
3552  * @frm_subtype: Frame subtype
3553  * @rx_param: host mgmt header params
3554  * @scan_list: Scan entry list of bss candidates after filtering
3555  * @mbssid_info: Data structure to carry MBSSID information
3556  *
3557  * Return: False if the scan entry generation is not successful
3558  */
3559 static QDF_STATUS
3560 util_scan_gen_txvap_scan_entry(struct wlan_objmgr_pdev *pdev,
3561 			       uint8_t *frame, qdf_size_t frame_len,
3562 			       uint8_t *ie_list, uint32_t ielen,
3563 			       uint32_t frm_subtype,
3564 			       struct mgmt_rx_event_params *rx_param,
3565 			       qdf_list_t *scan_list,
3566 			       struct scan_mbssid_info *mbssid_info)
3567 {
3568 	uint8_t *src_ie, *dest_ptr, *container;
3569 	uint16_t new_frame_len, new_ie_len = 0;
3570 	uint8_t *trimmed_frame, fixed_len = 0;
3571 	QDF_STATUS status = QDF_STATUS_SUCCESS;
3572 
3573 	/*
3574 	 * Allocate a buffer to copy only the TX VAP information after
3575 	 * stripping out the MBSSID IE from the parent beacon.
3576 	 * The allocation size should be the size of a frame as at
3577 	 * this point it is unknown what would be the new frame length
3578 	 * after stripping the MBSSID IE.
3579 	 */
3580 	container = qdf_mem_malloc(frame_len);
3581 	if (!container) {
3582 		scm_err_rl("Malloc for container failed");
3583 		return QDF_STATUS_E_NOMEM;
3584 	}
3585 
3586 	dest_ptr = &container[0];
3587 	fixed_len = sizeof(struct wlan_frame_hdr) +
3588 		offsetof(struct wlan_bcn_frame, ie);
3589 
3590 	/*Copy the data till IE list before procesisng the IE one by one*/
3591 	qdf_mem_copy(dest_ptr, frame, fixed_len);
3592 
3593 	dest_ptr += fixed_len;
3594 	src_ie = ie_list;
3595 
3596 	/*
3597 	 * Go through the IE list from the parent beacon and copy one by one.
3598 	 * Skip copying it to the container if it's an MBSSID tag.
3599 	 */
3600 	while (((src_ie + src_ie[TAG_LEN_POS] + MIN_IE_LEN) -
3601 		ie_list) <= ielen) {
3602 		if (src_ie[ID_POS] == WLAN_ELEMID_MULTIPLE_BSSID) {
3603 			src_ie += src_ie[TAG_LEN_POS] + MIN_IE_LEN;
3604 			continue;
3605 		}
3606 
3607 		qdf_mem_copy(dest_ptr, src_ie,
3608 			     (src_ie[TAG_LEN_POS] + MIN_IE_LEN));
3609 
3610 		dest_ptr += src_ie[TAG_LEN_POS] + MIN_IE_LEN;
3611 		if (((src_ie + src_ie[TAG_LEN_POS] +
3612 		      MIN_IE_LEN) - ie_list) >= ielen)
3613 			break;
3614 
3615 		src_ie += src_ie[TAG_LEN_POS] + MIN_IE_LEN;
3616 	}
3617 
3618 	if (dest_ptr > container)
3619 		new_ie_len = dest_ptr - (container + fixed_len);
3620 
3621 	new_frame_len = frame_len - ielen + new_ie_len;
3622 
3623 	/*
3624 	 * At the start of this handler, we have allocated a memory block
3625 	 * of size same as a full beacon frame size, as we are not sure
3626 	 * of what would be the size of the new frame. After stripping out
3627 	 * the MBSSID tag from the parent beacon, there are some unused
3628 	 * memory. Hence do another malloc of the new frame length
3629 	 * (length of the new frame which has only TX VAP information)
3630 	 * and copy the needed data from the container, then free the
3631 	 * memory corresponds to container.
3632 	 * Post copy, use the trimmed frame and the new frame length
3633 	 * to generate scan entry for the TX profile.
3634 	 */
3635 	trimmed_frame = qdf_mem_malloc(new_frame_len);
3636 	if (!trimmed_frame) {
3637 		scm_err_rl("Malloc for trimmed frame failed");
3638 		qdf_mem_free(container);
3639 		return QDF_STATUS_E_NOMEM;
3640 	}
3641 
3642 	qdf_mem_copy(trimmed_frame, container, new_frame_len);
3643 	qdf_mem_free(container);
3644 
3645 	status = util_scan_gen_scan_entry(pdev, trimmed_frame,
3646 					  new_frame_len,
3647 					  frm_subtype,
3648 					  rx_param,
3649 					  mbssid_info,
3650 					  scan_list);
3651 
3652 	if (QDF_IS_STATUS_ERROR(status))
3653 		scm_debug_rl("Failed to create a scan entry");
3654 
3655 	qdf_mem_free(trimmed_frame);
3656 	return status;
3657 }
3658 
3659 /*
3660  * util_scan_parse_eht_beacon() : This API will be executed
3661  * only for 11BE platforms as per current design.
3662  * IF MBSSID IE is present in the beacon then
3663  * scan component will create a new entry for
3664  * each BSSID found in the MBSSID
3665  * util_scan_parse_mbssid() takes care of creating
3666  * scan entries for every non tx profile present in
3667  * the MBSSID tag.
3668  * util_scan_gen_txvap_scan_entry() helps in generating
3669  * scan entry for the tx profile.
3670  */
3671 static QDF_STATUS
3672 util_scan_parse_eht_beacon(struct wlan_objmgr_pdev *pdev,
3673 			   uint8_t *frame, qdf_size_t frame_len,
3674 			   uint8_t *ie_list, uint32_t ielen,
3675 			   uint32_t frm_subtype,
3676 			   struct mgmt_rx_event_params *rx_param,
3677 			   qdf_list_t *scan_list,
3678 			   struct scan_mbssid_info *mbssid_info,
3679 			   uint8_t *mbssid_ie)
3680 {
3681 	QDF_STATUS status = QDF_STATUS_SUCCESS;
3682 
3683 	if (mbssid_ie) {
3684 		status = util_scan_parse_mbssid(pdev, frame, frame_len,
3685 						frm_subtype, rx_param,
3686 						scan_list);
3687 
3688 		if (QDF_IS_STATUS_ERROR(status)) {
3689 			scm_debug_rl("NonTx prof: Failed to create scan entry");
3690 			return status;
3691 		}
3692 
3693 		status = util_scan_gen_txvap_scan_entry(pdev, frame,
3694 							frame_len, ie_list,
3695 							ielen, frm_subtype,
3696 							rx_param, scan_list,
3697 							mbssid_info);
3698 
3699 		if (QDF_IS_STATUS_ERROR(status))
3700 			scm_debug_rl("TX prof: Failed to create scan entry");
3701 
3702 		return status;
3703 	}
3704 
3705 	/*For Non MBSSIE case*/
3706 	status = util_scan_gen_scan_entry(pdev, frame, frame_len,
3707 					  frm_subtype, rx_param,
3708 					  mbssid_info, scan_list);
3709 
3710 	if (QDF_IS_STATUS_ERROR(status))
3711 		scm_debug_rl("Non-MBSSIE frame: Failed to create scan entry");
3712 
3713 	return status;
3714 }
3715 
3716 static bool
3717 util_scan_is_platform_eht_capable(struct wlan_objmgr_pdev *pdev)
3718 {
3719 	struct wlan_objmgr_psoc *psoc = NULL;
3720 	struct wlan_lmac_if_tx_ops *tx_ops = NULL;
3721 	struct wlan_lmac_if_scan_tx_ops *scan_ops = NULL;
3722 	uint8_t pdev_id;
3723 
3724 	psoc = wlan_pdev_get_psoc(pdev);
3725 	if (!psoc) {
3726 		scm_debug_rl("psoc is null");
3727 		return false;
3728 	}
3729 	tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
3730 	if (!tx_ops) {
3731 		scm_debug_rl("tx_ops is null");
3732 		return false;
3733 	}
3734 	scan_ops = &tx_ops->scan;
3735 	if (!scan_ops) {
3736 		scm_debug_rl("scan_ops is null");
3737 		return false;
3738 	}
3739 	pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
3740 
3741 	if (scan_ops->is_platform_eht_capable)
3742 		return scan_ops->is_platform_eht_capable(psoc, pdev_id);
3743 
3744 	return false;
3745 }
3746 #else
3747 static QDF_STATUS
3748 util_scan_parse_eht_beacon(struct wlan_objmgr_pdev *pdev,
3749 			   uint8_t *frame, qdf_size_t frame_len,
3750 			   uint8_t *ie_list, uint32_t ielen,
3751 			   uint32_t frm_subtype,
3752 			   struct mgmt_rx_event_params *rx_param,
3753 			   qdf_list_t *scan_list,
3754 			   struct scan_mbssid_info *mbssid_info,
3755 			   uint8_t *mbssid_ie)
3756 {
3757 	return QDF_STATUS_SUCCESS;
3758 }
3759 
3760 static bool
3761 util_scan_is_platform_eht_capable(struct wlan_objmgr_pdev *pdev)
3762 {
3763 	return false;
3764 }
3765 #endif
3766 
3767 static QDF_STATUS
3768 util_scan_parse_beacon_frame(struct wlan_objmgr_pdev *pdev,
3769 			     uint8_t *frame,
3770 			     qdf_size_t frame_len,
3771 			     uint32_t frm_subtype,
3772 			     struct mgmt_rx_event_params *rx_param,
3773 			     qdf_list_t *scan_list)
3774 {
3775 	struct wlan_bcn_frame *bcn;
3776 	struct wlan_frame_hdr *hdr;
3777 	uint8_t *mbssid_ie = NULL, *extcap_ie;
3778 	uint32_t ie_len = 0;
3779 	QDF_STATUS status = QDF_STATUS_E_FAILURE;
3780 	struct scan_mbssid_info mbssid_info = { 0 };
3781 	uint8_t *ie_list;
3782 	bool eht_support = false;
3783 
3784 	hdr = (struct wlan_frame_hdr *)frame;
3785 	bcn = (struct wlan_bcn_frame *)
3786 		(frame + sizeof(struct wlan_frame_hdr));
3787 	ie_list = (uint8_t *)&bcn->ie;
3788 	ie_len = (uint16_t)(frame_len -
3789 			    sizeof(struct wlan_frame_hdr) -
3790 			    offsetof(struct wlan_bcn_frame, ie));
3791 
3792 	extcap_ie = util_scan_find_ie(WLAN_ELEMID_XCAPS,
3793 				      (uint8_t *)&bcn->ie, ie_len);
3794 	/* Process MBSSID when Multiple BSSID (Bit 22) is set in Ext Caps */
3795 	if (extcap_ie &&
3796 	    extcap_ie[1] >= 3 && extcap_ie[1] <= WLAN_EXTCAP_IE_MAX_LEN &&
3797 	    (extcap_ie[4] & 0x40)) {
3798 		mbssid_ie = util_scan_find_ie(WLAN_ELEMID_MULTIPLE_BSSID,
3799 					      (uint8_t *)&bcn->ie, ie_len);
3800 		if (mbssid_ie) {
3801 			if (mbssid_ie[1] <= 0) {
3802 				scm_debug("MBSSID IE length is wrong %d",
3803 					  mbssid_ie[1]);
3804 				return status;
3805 			}
3806 			qdf_mem_copy(&mbssid_info.trans_bssid,
3807 				     hdr->i_addr3, QDF_MAC_ADDR_SIZE);
3808 			mbssid_info.profile_count = 1 << mbssid_ie[2];
3809 		}
3810 	}
3811 
3812 	eht_support = util_scan_is_platform_eht_capable(pdev);
3813 
3814 	if (eht_support) {
3815 		status = util_scan_parse_eht_beacon(pdev, frame, frame_len,
3816 						    ie_list, ie_len,
3817 						    frm_subtype, rx_param,
3818 						    scan_list, &mbssid_info,
3819 						    mbssid_ie);
3820 		return status;
3821 	}
3822 
3823 	status = util_scan_gen_scan_entry(pdev, frame, frame_len,
3824 					  frm_subtype, rx_param,
3825 					  &mbssid_info,
3826 					  scan_list);
3827 
3828 	if (mbssid_ie)
3829 		status = util_scan_parse_mbssid(pdev, frame, frame_len,
3830 						frm_subtype, rx_param,
3831 						scan_list);
3832 
3833 	if (QDF_IS_STATUS_ERROR(status))
3834 		scm_debug_rl("Failed to create scan entry");
3835 
3836 	return status;
3837 }
3838 
3839 qdf_list_t *
3840 util_scan_unpack_beacon_frame(struct wlan_objmgr_pdev *pdev, uint8_t *frame,
3841 			      qdf_size_t frame_len, uint32_t frm_subtype,
3842 			      struct mgmt_rx_event_params *rx_param)
3843 {
3844 	qdf_list_t *scan_list;
3845 	QDF_STATUS status;
3846 
3847 	scan_list = qdf_mem_malloc_atomic(sizeof(*scan_list));
3848 	if (!scan_list) {
3849 		scm_err("failed to allocate scan_list");
3850 		return NULL;
3851 	}
3852 	qdf_list_create(scan_list, MAX_SCAN_CACHE_SIZE);
3853 
3854 	status = util_scan_parse_beacon_frame(pdev, frame, frame_len,
3855 					      frm_subtype, rx_param,
3856 					      scan_list);
3857 	if (QDF_IS_STATUS_ERROR(status)) {
3858 		ucfg_scan_purge_results(scan_list);
3859 		return NULL;
3860 	}
3861 
3862 	return scan_list;
3863 }
3864 
3865 QDF_STATUS
3866 util_scan_entry_update_mlme_info(struct wlan_objmgr_pdev *pdev,
3867 	struct scan_cache_entry *scan_entry)
3868 {
3869 
3870 	if (!pdev || !scan_entry) {
3871 		scm_err("pdev 0x%pK, scan_entry: 0x%pK", pdev, scan_entry);
3872 		return QDF_STATUS_E_INVAL;
3873 	}
3874 
3875 	return scm_update_scan_mlme_info(pdev, scan_entry);
3876 }
3877 
3878 bool util_is_scan_completed(struct scan_event *event, bool *success)
3879 {
3880 	if ((event->type == SCAN_EVENT_TYPE_COMPLETED) ||
3881 	    (event->type == SCAN_EVENT_TYPE_DEQUEUED) ||
3882 	    (event->type == SCAN_EVENT_TYPE_START_FAILED)) {
3883 		if ((event->type == SCAN_EVENT_TYPE_COMPLETED) &&
3884 		    (event->reason == SCAN_REASON_COMPLETED))
3885 			*success = true;
3886 		else
3887 			*success = false;
3888 
3889 		return true;
3890 	}
3891 
3892 	*success = false;
3893 	return false;
3894 }
3895 
3896 #if defined(WLAN_SAE_SINGLE_PMK) && defined(WLAN_FEATURE_ROAM_OFFLOAD)
3897 bool
3898 util_scan_entry_single_pmk(struct wlan_objmgr_psoc *psoc,
3899 			   struct scan_cache_entry *scan_entry)
3900 {
3901 	if (scan_entry->ie_list.single_pmk &&
3902 	    wlan_mlme_is_sae_single_pmk_enabled(psoc))
3903 		return true;
3904 
3905 	return false;
3906 }
3907 #endif
3908