xref: /wlan-dirver/qca-wifi-host-cmn/os_if/linux/scan/src/wlan_cfg80211_scan.c (revision 8cfe6b10058a04cafb17eed051f2ddf11bee8931)
1 /*
2  * Copyright (c) 2017-2021 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2021-2023 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 driver functions interfacing with linux kernel
22  */
23 
24 #include <qdf_list.h>
25 #include <qdf_status.h>
26 #include <qdf_module.h>
27 #include <linux/wireless.h>
28 #include <linux/netdevice.h>
29 #include <net/cfg80211.h>
30 #include <wlan_scan_utils_api.h>
31 #include <wlan_cfg80211.h>
32 #include <wlan_cfg80211_scan.h>
33 #include <wlan_osif_priv.h>
34 #include <wlan_scan_public_structs.h>
35 #include <wlan_scan_ucfg_api.h>
36 #include <wlan_cfg80211_scan.h>
37 #include <qdf_mem.h>
38 #include <wlan_utility.h>
39 #include "cfg_ucfg_api.h"
40 #ifdef WLAN_POLICY_MGR_ENABLE
41 #include <wlan_policy_mgr_api.h>
42 #endif
43 #include <wlan_reg_services_api.h>
44 #ifdef FEATURE_WLAN_DIAG_SUPPORT
45 #include "host_diag_core_event.h"
46 #endif
47 
48 const struct nla_policy cfg80211_scan_policy[
49 			QCA_WLAN_VENDOR_ATTR_SCAN_MAX + 1] = {
50 	[QCA_WLAN_VENDOR_ATTR_SCAN_FLAGS] = {.type = NLA_U32},
51 	[QCA_WLAN_VENDOR_ATTR_SCAN_TX_NO_CCK_RATE] = {.type = NLA_FLAG},
52 	[QCA_WLAN_VENDOR_ATTR_SCAN_COOKIE] = {.type = NLA_U64},
53 };
54 
55 /**
56  * wlan_cfg80211_is_colocated_6ghz_scan_supported() - Check whether colocated
57  * 6ghz scan flag present in scan request or not
58  * @scan_flag: Flags bitmap coming from kernel
59  *
60  * Return: True if colocated 6ghz scan flag present in scan req
61  */
62 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0))
63 static bool
64 wlan_cfg80211_is_colocated_6ghz_scan_supported(uint32_t scan_flag)
65 {
66 	return !!(scan_flag & NL80211_SCAN_FLAG_COLOCATED_6GHZ);
67 }
68 #else
69 static inline bool
70 wlan_cfg80211_is_colocated_6ghz_scan_supported(uint32_t scan_flag)
71 {
72 	return false;
73 }
74 #endif
75 
76 #if defined(CFG80211_SCAN_RANDOM_MAC_ADDR) || \
77 	(LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0))
78 /**
79  * wlan_fill_scan_rand_attrs() - Populate the scan randomization attrs
80  * @vdev: pointer to objmgr vdev
81  * @flags: cfg80211 scan flags
82  * @mac_addr: random mac addr from cfg80211
83  * @mac_addr_mask: mac addr mask from cfg80211
84  * @randomize: output variable to check scan randomization status
85  * @addr: output variable to hold random addr
86  * @mask: output variable to hold mac mask
87  *
88  * Return: None
89  */
90 static void wlan_fill_scan_rand_attrs(struct wlan_objmgr_vdev *vdev,
91 				      uint32_t flags,
92 				      uint8_t *mac_addr,
93 				      uint8_t *mac_addr_mask,
94 				      bool *randomize,
95 				      uint8_t *addr,
96 				      uint8_t *mask)
97 {
98 	*randomize = false;
99 	if (!(flags & NL80211_SCAN_FLAG_RANDOM_ADDR))
100 		return;
101 
102 	if (wlan_vdev_mlme_get_opmode(vdev) != QDF_STA_MODE)
103 		return;
104 
105 	if (wlan_vdev_is_up(vdev) == QDF_STATUS_SUCCESS)
106 		return;
107 
108 	*randomize = true;
109 	memcpy(addr, mac_addr, QDF_MAC_ADDR_SIZE);
110 	memcpy(mask, mac_addr_mask, QDF_MAC_ADDR_SIZE);
111 	osif_debug("Random mac addr: "QDF_MAC_ADDR_FMT" and Random mac mask: "QDF_FULL_MAC_FMT,
112 		   QDF_MAC_ADDR_REF(addr), QDF_FULL_MAC_REF(mask));
113 }
114 
115 /**
116  * wlan_scan_rand_attrs() - Wrapper function to fill scan random attrs
117  * @vdev: pointer to objmgr vdev
118  * @request: pointer to cfg80211 scan request
119  * @req: pointer to cmn module scan request
120  *
121  * This is a wrapper function which invokes wlan_fill_scan_rand_attrs()
122  * to fill random attributes of internal scan request with cfg80211_scan_request
123  *
124  * Return: None
125  */
126 static void wlan_scan_rand_attrs(struct wlan_objmgr_vdev *vdev,
127 				 struct cfg80211_scan_request *request,
128 				 struct scan_start_request *req)
129 {
130 	bool *randomize = &req->scan_req.scan_random.randomize;
131 	uint8_t *mac_addr = req->scan_req.scan_random.mac_addr;
132 	uint8_t *mac_mask = req->scan_req.scan_random.mac_mask;
133 
134 	wlan_fill_scan_rand_attrs(vdev, request->flags, request->mac_addr,
135 				  request->mac_addr_mask, randomize, mac_addr,
136 				  mac_mask);
137 	if (!*randomize)
138 		return;
139 
140 	req->scan_req.scan_f_add_spoofed_mac_in_probe = true;
141 	req->scan_req.scan_f_add_rand_seq_in_probe = true;
142 }
143 #else
144 /**
145  * wlan_scan_rand_attrs() - Wrapper function to fill scan random attrs
146  * @vdev: pointer to objmgr vdev
147  * @request: pointer to cfg80211 scan request
148  * @req: pointer to cmn module scan request
149  *
150  * This is a wrapper function which invokes wlan_fill_scan_rand_attrs()
151  * to fill random attributes of internal scan request with cfg80211_scan_request
152  *
153  * Return: None
154  */
155 static void wlan_scan_rand_attrs(struct wlan_objmgr_vdev *vdev,
156 				 struct cfg80211_scan_request *request,
157 				 struct scan_start_request *req)
158 {
159 }
160 #endif
161 
162 #ifdef FEATURE_WLAN_SCAN_PNO
163 #if ((LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0)) || \
164 	defined(CFG80211_MULTI_SCAN_PLAN_BACKPORT))
165 
166 /**
167  * wlan_config_sched_scan_plan() - configures the sched scan plans
168  *   from the framework.
169  * @psoc: psoc object
170  * @pno_req: pointer to PNO scan request
171  * @request: pointer to scan request from framework
172  *
173  * Return: None
174  */
175 static void
176 wlan_config_sched_scan_plan(struct wlan_objmgr_psoc *psoc,
177 			    struct pno_scan_req_params *pno_req,
178 			    struct cfg80211_sched_scan_request *request)
179 {
180 	if (!ucfg_scan_get_user_config_sched_scan_plan(psoc) ||
181 	    request->n_scan_plans == 1) {
182 		pno_req->fast_scan_period =
183 		request->scan_plans[0].interval * MSEC_PER_SEC;
184 		/*
185 		 * if only one scan plan is configured from framework
186 		 * then both fast and slow scan should be configured with the
187 		 * same value that is why fast scan cycles are hardcoded to one
188 		 */
189 		pno_req->fast_scan_max_cycles = 1;
190 		pno_req->slow_scan_period =
191 			request->scan_plans[0].interval * MSEC_PER_SEC;
192 	}
193 	/*
194 	 * As of now max 2 scan plans were supported by firmware
195 	 * if number of scan plan supported by firmware increased below logic
196 	 * must change.
197 	 */
198 	else if (request->n_scan_plans == SCAN_PNO_MAX_PLAN_REQUEST) {
199 		pno_req->fast_scan_period =
200 			request->scan_plans[0].interval * MSEC_PER_SEC;
201 		pno_req->fast_scan_max_cycles =
202 			request->scan_plans[0].iterations;
203 		pno_req->slow_scan_period =
204 			request->scan_plans[1].interval * MSEC_PER_SEC;
205 	} else {
206 		osif_err("Invalid number of scan plans %d !!",
207 			 request->n_scan_plans);
208 	}
209 }
210 #else
211 #define wlan_config_sched_scan_plan(psoc, pno_req, request) \
212 	__wlan_config_sched_scan_plan(pno_req, request, psoc)
213 
214 static void
215 __wlan_config_sched_scan_plan(struct pno_scan_req_params *pno_req,
216 			      struct cfg80211_sched_scan_request *request,
217 			      struct wlan_objmgr_psoc *psoc)
218 {
219 	uint32_t scan_timer_repeat_value, slow_scan_multiplier;
220 
221 	scan_timer_repeat_value = ucfg_scan_get_scan_timer_repeat_value(psoc);
222 	slow_scan_multiplier = ucfg_scan_get_slow_scan_multiplier(psoc);
223 
224 	pno_req->fast_scan_period = request->interval;
225 	pno_req->fast_scan_max_cycles = scan_timer_repeat_value;
226 	pno_req->slow_scan_period =
227 		(slow_scan_multiplier * pno_req->fast_scan_period);
228 }
229 #endif
230 
231 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 12, 0)
232 static inline void
233 wlan_cfg80211_sched_scan_results(struct wiphy *wiphy, uint64_t reqid)
234 {
235 	cfg80211_sched_scan_results(wiphy);
236 }
237 #else
238 static inline void
239 wlan_cfg80211_sched_scan_results(struct wiphy *wiphy, uint64_t reqid)
240 {
241 	cfg80211_sched_scan_results(wiphy, reqid);
242 }
243 #endif
244 
245 /**
246  * wlan_cfg80211_pno_callback() - pno callback function to handle
247  * pno events.
248  * @vdev: vdev ptr
249  * @event: scan events
250  * @args: argument
251  *
252  * Return: void
253  */
254 static void wlan_cfg80211_pno_callback(struct wlan_objmgr_vdev *vdev,
255 	struct scan_event *event,
256 	void *args)
257 {
258 	struct wlan_objmgr_pdev *pdev;
259 	struct pdev_osif_priv *pdev_ospriv;
260 
261 	if (event->type != SCAN_EVENT_TYPE_NLO_COMPLETE)
262 		return;
263 
264 	osif_debug("vdev id = %d", event->vdev_id);
265 
266 	pdev = wlan_vdev_get_pdev(vdev);
267 	if (!pdev) {
268 		osif_err("pdev is NULL");
269 		return;
270 	}
271 
272 	pdev_ospriv = wlan_pdev_get_ospriv(pdev);
273 	if (!pdev_ospriv) {
274 		osif_err("pdev_ospriv is NULL");
275 		return;
276 	}
277 	wlan_cfg80211_sched_scan_results(pdev_ospriv->wiphy, 0);
278 }
279 
280 #ifdef WLAN_POLICY_MGR_ENABLE
281 static bool wlan_cfg80211_is_ap_go_present(struct wlan_objmgr_psoc *psoc)
282 {
283 	return policy_mgr_mode_specific_connection_count(psoc,
284 							  PM_SAP_MODE,
285 							  NULL) ||
286 		policy_mgr_mode_specific_connection_count(psoc,
287 							  PM_P2P_GO_MODE,
288 							  NULL);
289 }
290 
291 static QDF_STATUS wlan_cfg80211_is_chan_ok_for_dnbs(
292 			struct wlan_objmgr_psoc *psoc,
293 			u16 chan_freq, bool *ok)
294 {
295 	QDF_STATUS status = policy_mgr_is_chan_ok_for_dnbs(
296 				psoc, chan_freq, ok);
297 
298 	if (QDF_IS_STATUS_ERROR(status)) {
299 		osif_err("DNBS check failed");
300 		return status;
301 	}
302 
303 	return QDF_STATUS_SUCCESS;
304 }
305 #else
306 static bool wlan_cfg80211_is_ap_go_present(struct wlan_objmgr_psoc *psoc)
307 {
308 	return false;
309 }
310 
311 static QDF_STATUS wlan_cfg80211_is_chan_ok_for_dnbs(
312 			struct wlan_objmgr_psoc *psoc,
313 			u16 chan_freq,
314 			bool *ok)
315 {
316 	if (!ok)
317 		return QDF_STATUS_E_INVAL;
318 
319 	*ok = true;
320 	return QDF_STATUS_SUCCESS;
321 }
322 #endif
323 
324 #if defined(CFG80211_SCAN_RANDOM_MAC_ADDR) || \
325 	(LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0))
326 /**
327  * wlan_pno_scan_rand_attr() - Wrapper function to fill sched scan random attrs
328  * @vdev: pointer to objmgr vdev
329  * @request: pointer to cfg80211 sched scan request
330  * @req: pointer to cmn module pno scan request
331  *
332  * This is a wrapper function which invokes wlan_fill_scan_rand_attrs()
333  * to fill random attributes of internal pno scan
334  * with cfg80211_sched_scan_request
335  *
336  * Return: None
337  */
338 static void wlan_pno_scan_rand_attr(struct wlan_objmgr_vdev *vdev,
339 				    struct cfg80211_sched_scan_request *request,
340 				    struct pno_scan_req_params *req)
341 {
342 	bool *randomize = &req->scan_random.randomize;
343 	uint8_t *mac_addr = req->scan_random.mac_addr;
344 	uint8_t *mac_mask = req->scan_random.mac_mask;
345 
346 	wlan_fill_scan_rand_attrs(vdev, request->flags, request->mac_addr,
347 				  request->mac_addr_mask, randomize, mac_addr,
348 				  mac_mask);
349 }
350 #else
351 /**
352  * wlan_pno_scan_rand_attr() - Wrapper function to fill sched scan random attrs
353  * @vdev: pointer to objmgr vdev
354  * @request: pointer to cfg80211 sched scan request
355  * @req: pointer to cmn module pno scan request
356  *
357  * This is a wrapper function which invokes wlan_fill_scan_rand_attrs()
358  * to fill random attributes of internal pno scan
359  * with cfg80211_sched_scan_request
360  *
361  * Return: None
362  */
363 static void wlan_pno_scan_rand_attr(struct wlan_objmgr_vdev *vdev,
364 				    struct cfg80211_sched_scan_request *request,
365 				    struct pno_scan_req_params *req)
366 {
367 }
368 #endif
369 
370 /**
371  * wlan_hdd_sched_scan_update_relative_rssi() - update CPNO params
372  * @pno_request: pointer to PNO scan request
373  * @request: Pointer to cfg80211 scheduled scan start request
374  *
375  * This function is used to update Connected PNO params sent by kernel
376  *
377  * Return: None
378  */
379 #if defined(CFG80211_REPORT_BETTER_BSS_IN_SCHED_SCAN) || \
380 	(LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0))
381 static inline void wlan_hdd_sched_scan_update_relative_rssi(
382 			struct pno_scan_req_params *pno_request,
383 			struct cfg80211_sched_scan_request *request)
384 {
385 	pno_request->relative_rssi_set = request->relative_rssi_set;
386 	pno_request->relative_rssi = request->relative_rssi;
387 	if (NL80211_BAND_2GHZ == request->rssi_adjust.band)
388 		pno_request->band_rssi_pref.band = WLAN_BAND_2_4_GHZ;
389 	else if (NL80211_BAND_5GHZ == request->rssi_adjust.band)
390 		pno_request->band_rssi_pref.band = WLAN_BAND_5_GHZ;
391 	pno_request->band_rssi_pref.rssi = request->rssi_adjust.delta;
392 }
393 #else
394 static inline void wlan_hdd_sched_scan_update_relative_rssi(
395 			struct pno_scan_req_params *pno_request,
396 			struct cfg80211_sched_scan_request *request)
397 {
398 }
399 #endif
400 
401 #ifdef FEATURE_WLAN_SCAN_PNO
402 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0))
403 static uint32_t wlan_config_sched_scan_start_delay(
404 		struct cfg80211_sched_scan_request *request)
405 {
406 	return request->delay;
407 }
408 #else
409 static uint32_t wlan_config_sched_scan_start_delay(
410 		struct cfg80211_sched_scan_request *request)
411 {
412 	return 0;
413 }
414 #endif /*(LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0)) */
415 #endif /* FEATURE_WLAN_SCAN_PNO */
416 
417 int wlan_cfg80211_sched_scan_start(struct wlan_objmgr_vdev *vdev,
418 				   struct cfg80211_sched_scan_request *request,
419 				   uint8_t scan_backoff_multiplier)
420 {
421 	struct pno_scan_req_params *req;
422 	int i, j, ret = 0;
423 	QDF_STATUS status;
424 	uint8_t num_chan = 0;
425 	uint8_t updated_num_chan = 0;
426 	uint16_t chan_freq;
427 	struct wlan_objmgr_pdev *pdev = wlan_vdev_get_pdev(vdev);
428 	struct wlan_objmgr_psoc *psoc;
429 	uint32_t valid_ch[SCAN_PNO_MAX_NETW_CHANNELS_EX] = {0};
430 	bool enable_dfs_pno_chnl_scan;
431 
432 	if (ucfg_scan_get_pno_in_progress(vdev)) {
433 		osif_debug("pno is already in progress");
434 		return -EBUSY;
435 	}
436 
437 	if (ucfg_scan_get_pdev_status(pdev) !=
438 	   SCAN_NOT_IN_PROGRESS) {
439 		status = wlan_abort_scan(pdev,
440 				wlan_objmgr_pdev_get_pdev_id(pdev),
441 				INVAL_VDEV_ID, INVAL_SCAN_ID, true);
442 		if (QDF_IS_STATUS_ERROR(status))
443 			return -EBUSY;
444 	}
445 
446 	req = qdf_mem_malloc(sizeof(*req));
447 	if (!req)
448 		return -ENOMEM;
449 
450 	wlan_pdev_obj_lock(pdev);
451 	psoc = wlan_pdev_get_psoc(pdev);
452 	wlan_pdev_obj_unlock(pdev);
453 
454 	req->networks_cnt = request->n_match_sets;
455 	req->vdev_id = wlan_vdev_get_id(vdev);
456 	req->vdev = vdev;
457 	req->scan_policy_colocated_6ghz =
458 		wlan_cfg80211_is_colocated_6ghz_scan_supported(request->flags);
459 
460 	if ((!req->networks_cnt) ||
461 	    (req->networks_cnt > SCAN_PNO_MAX_SUPP_NETWORKS)) {
462 		osif_err("Network input is not correct %d",
463 			 req->networks_cnt);
464 		ret = -EINVAL;
465 		goto error;
466 	}
467 
468 	if (request->n_channels > SCAN_PNO_MAX_NETW_CHANNELS_EX) {
469 		osif_err("Incorrect number of channels %d",
470 			 request->n_channels);
471 		ret = -EINVAL;
472 		goto error;
473 	}
474 
475 	enable_dfs_pno_chnl_scan = ucfg_scan_is_dfs_chnl_scan_enabled(psoc);
476 	if (request->n_channels) {
477 		uint32_t buff_len;
478 		char *chl;
479 		int len = 0;
480 		bool ap_or_go_present = wlan_cfg80211_is_ap_go_present(psoc);
481 
482 		buff_len = (request->n_channels * 5) + 1;
483 		chl = qdf_mem_malloc(buff_len);
484 		if (!chl) {
485 			ret = -ENOMEM;
486 			goto error;
487 		}
488 		for (i = 0; i < request->n_channels; i++) {
489 			chan_freq = request->channels[i]->center_freq;
490 			if ((!enable_dfs_pno_chnl_scan) &&
491 			    (wlan_reg_is_dfs_for_freq(pdev, chan_freq))) {
492 				osif_debug("Dropping DFS channel freq :%d",
493 					   chan_freq);
494 				continue;
495 			}
496 			if (wlan_reg_is_dsrc_freq(chan_freq))
497 				continue;
498 
499 			if (ap_or_go_present) {
500 				bool ok;
501 
502 				status =
503 				wlan_cfg80211_is_chan_ok_for_dnbs(psoc,
504 								  chan_freq,
505 								  &ok);
506 				if (QDF_IS_STATUS_ERROR(status)) {
507 					osif_err("DNBS check failed");
508 					qdf_mem_free(chl);
509 					chl = NULL;
510 					ret = -EINVAL;
511 					goto error;
512 				}
513 				if (!ok)
514 					continue;
515 			}
516 			len += qdf_scnprintf(chl + len, buff_len - len, " %d", chan_freq);
517 			valid_ch[num_chan++] = chan_freq;
518 		}
519 		osif_debug("Channel-List[%d]:%s", num_chan, chl);
520 		qdf_mem_free(chl);
521 		chl = NULL;
522 		/* If all channels are DFS and dropped,
523 		 * then ignore the PNO request
524 		 */
525 		if (!num_chan) {
526 			osif_notice("Channel list empty due to filtering of DSRC");
527 			ret = -EINVAL;
528 			goto error;
529 		}
530 	}
531 
532 	/* Filling per profile  params */
533 	for (i = 0; i < req->networks_cnt; i++) {
534 		struct cfg80211_match_set *user_req = &request->match_sets[i];
535 		struct pno_nw_type *tgt_req = &req->networks_list[i];
536 
537 		tgt_req->ssid.length = user_req->ssid.ssid_len;
538 
539 		if (!tgt_req->ssid.length ||
540 		    tgt_req->ssid.length > WLAN_SSID_MAX_LEN) {
541 			osif_err(" SSID Len %d is not correct for network %d",
542 				 tgt_req->ssid.length, i);
543 			ret = -EINVAL;
544 			goto error;
545 		}
546 
547 		qdf_mem_copy(tgt_req->ssid.ssid, user_req->ssid.ssid,
548 			     tgt_req->ssid.length);
549 		tgt_req->authentication = 0;   /*eAUTH_TYPE_ANY */
550 		tgt_req->encryption = 0;       /*eED_ANY */
551 		tgt_req->bc_new_type = 0;    /*eBCAST_UNKNOWN */
552 
553 
554 		/*Copying list of valid channel into request */
555 		for (j = 0; j < num_chan; j++)
556 			tgt_req->pno_chan_list.chan[j].freq = valid_ch[j];
557 		tgt_req->pno_chan_list.num_chan = num_chan;
558 
559 		if (ucfg_is_6ghz_pno_scan_optimization_supported(psoc)) {
560 			uint32_t short_ssid =
561 				wlan_construct_shortssid(tgt_req->ssid.ssid,
562 							 tgt_req->ssid.length);
563 			updated_num_chan = num_chan;
564 			ucfg_scan_add_flags_to_pno_chan_list(vdev, req,
565 							     &updated_num_chan,
566 							     short_ssid, i);
567 		}
568 
569 		tgt_req->rssi_thresh = user_req->rssi_thold;
570 	}
571 
572 	/* set scan to passive if no SSIDs are specified in the request */
573 	if (0 == request->n_ssids)
574 		req->do_passive_scan = true;
575 	else
576 		req->do_passive_scan = false;
577 
578 	for (i = 0; i < request->n_ssids; i++) {
579 		j = 0;
580 		while (j < req->networks_cnt) {
581 			if ((req->networks_list[j].ssid.length ==
582 			     request->ssids[i].ssid_len) &&
583 			    (!qdf_mem_cmp(req->networks_list[j].ssid.ssid,
584 					 request->ssids[i].ssid,
585 					 req->networks_list[j].ssid.length))) {
586 				req->networks_list[j].bc_new_type =
587 					SSID_BC_TYPE_HIDDEN;
588 				break;
589 			}
590 			j++;
591 		}
592 	}
593 
594 	/*
595 	 * Before Kernel 4.4
596 	 *   Driver gets only one time interval which is hard coded in
597 	 *   supplicant for 10000ms.
598 	 *
599 	 * After Kernel 4.4
600 	 *   User can configure multiple scan_plans, each scan would have
601 	 *   separate scan cycle and interval. (interval is in unit of second.)
602 	 *   For our use case, we would only have supplicant set one scan_plan,
603 	 *   and firmware also support only one as well, so pick up the first
604 	 *   index.
605 	 *
606 	 *   Taking power consumption into account
607 	 *   firmware after gPNOScanTimerRepeatValue times fast_scan_period
608 	 *   switches slow_scan_period. This is less frequent scans and firmware
609 	 *   shall be in slow_scan_period mode until next PNO Start.
610 	 */
611 	wlan_config_sched_scan_plan(psoc, req, request);
612 	req->delay_start_time = wlan_config_sched_scan_start_delay(request);
613 	req->scan_backoff_multiplier = scan_backoff_multiplier;
614 
615 	wlan_hdd_sched_scan_update_relative_rssi(req, request);
616 
617 	psoc = wlan_pdev_get_psoc(pdev);
618 	ucfg_scan_register_pno_cb(psoc,
619 		wlan_cfg80211_pno_callback, NULL);
620 	ucfg_scan_get_pno_def_params(vdev, req);
621 
622 	if (req->scan_random.randomize)
623 		wlan_pno_scan_rand_attr(vdev, request, req);
624 
625 	if (ucfg_ie_allowlist_enabled(psoc, vdev))
626 		ucfg_copy_ie_allowlist_attrs(psoc, &req->ie_allowlist);
627 
628 	osif_debug("Network count %d n_ssids %d fast_scan_period: %d msec slow_scan_period: %d msec, fast_scan_max_cycles: %d, relative_rssi %d band_pref %d, rssi_pref %d",
629 		   req->networks_cnt, request->n_ssids, req->fast_scan_period,
630 		   req->slow_scan_period, req->fast_scan_max_cycles,
631 		   req->relative_rssi, req->band_rssi_pref.band,
632 		   req->band_rssi_pref.rssi);
633 
634 	for (i = 0; i < req->networks_cnt; i++)
635 		osif_debug("[%d] ssid: " QDF_SSID_FMT ", RSSI th %d bc NW type %u",
636 			   i,
637 			   QDF_SSID_REF(req->networks_list[i].ssid.length,
638 					req->networks_list[i].ssid.ssid),
639 			   req->networks_list[i].rssi_thresh,
640 			   req->networks_list[i].bc_new_type);
641 
642 	status = ucfg_scan_pno_start(vdev, req);
643 	if (QDF_IS_STATUS_ERROR(status)) {
644 		osif_err("Failed to enable PNO");
645 		ret = -EINVAL;
646 		goto error;
647 	}
648 
649 error:
650 	qdf_mem_free(req);
651 	return ret;
652 }
653 
654 int wlan_cfg80211_sched_scan_stop(struct wlan_objmgr_vdev *vdev)
655 {
656 	QDF_STATUS status;
657 
658 	status = ucfg_scan_pno_stop(vdev);
659 	if (QDF_IS_STATUS_ERROR(status))
660 		osif_debug("Failed to disable PNO");
661 
662 	return 0;
663 }
664 #endif /*FEATURE_WLAN_SCAN_PNO */
665 
666 /**
667  * wlan_copy_bssid_scan_request() - API to copy the bssid to Scan request
668  * @scan_req: Pointer to scan_start_request
669  * @request: scan request from Supplicant
670  *
671  * This API copies the BSSID in scan request from Supplicant and copies it to
672  * the scan_start_request
673  *
674  * Return: None
675  */
676 #if defined(CFG80211_SCAN_BSSID) || \
677 	(LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
678 static inline void
679 wlan_copy_bssid_scan_request(struct scan_start_request *scan_req,
680 		struct cfg80211_scan_request *request)
681 {
682 	qdf_mem_copy(scan_req->scan_req.bssid_list[0].bytes,
683 				request->bssid, QDF_MAC_ADDR_SIZE);
684 }
685 #else
686 static inline void
687 wlan_copy_bssid_scan_request(struct scan_start_request *scan_req,
688 		struct cfg80211_scan_request *request)
689 {
690 
691 }
692 #endif
693 
694 /**
695  * wlan_schedule_scan_start_request() - Schedule scan start request
696  * @pdev: pointer to pdev object
697  * @req: Pointer to the scan request
698  * @source: source of the scan request
699  * @scan_start_req: pointer to scan start request
700  *
701  * Schedule scan start request and enqueue scan request in the global scan
702  * list. This list stores the active scan request information.
703  *
704  * Return: QDF_STATUS
705  */
706 static QDF_STATUS
707 wlan_schedule_scan_start_request(struct wlan_objmgr_pdev *pdev,
708 				 struct cfg80211_scan_request *req,
709 				 uint8_t source,
710 				 struct scan_start_request *scan_start_req)
711 {
712 	struct scan_req *scan_req;
713 	QDF_STATUS status;
714 	struct pdev_osif_priv *osif_ctx;
715 	struct osif_scan_pdev *osif_scan;
716 
717 	scan_req = qdf_mem_malloc(sizeof(*scan_req));
718 	if (!scan_req) {
719 		ucfg_scm_scan_free_scan_request_mem(scan_start_req);
720 		return QDF_STATUS_E_NOMEM;
721 	}
722 
723 	/* Get NL global context from objmgr*/
724 	osif_ctx = wlan_pdev_get_ospriv(pdev);
725 	osif_scan = osif_ctx->osif_scan;
726 	scan_req->scan_request = req;
727 	scan_req->source = source;
728 	scan_req->scan_id = scan_start_req->scan_req.scan_id;
729 	scan_req->dev = req->wdev->netdev;
730 	scan_req->scan_start_timestamp = qdf_get_time_of_the_day_ms();
731 
732 	qdf_mutex_acquire(&osif_scan->scan_req_q_lock);
733 	if (qdf_list_size(&osif_scan->scan_req_q) < WLAN_MAX_SCAN_COUNT) {
734 		status = ucfg_scan_start(scan_start_req);
735 		if (QDF_IS_STATUS_SUCCESS(status)) {
736 			qdf_list_insert_back(&osif_scan->scan_req_q,
737 					     &scan_req->node);
738 		} else {
739 			osif_err("scan req failed with error %d", status);
740 			if (status == QDF_STATUS_E_RESOURCES)
741 				osif_err("HO is in progress.So defer the scan by informing busy");
742 		}
743 	} else {
744 		ucfg_scm_scan_free_scan_request_mem(scan_start_req);
745 		status = QDF_STATUS_E_RESOURCES;
746 	}
747 
748 	qdf_mutex_release(&osif_scan->scan_req_q_lock);
749 	if (QDF_IS_STATUS_ERROR(status)) {
750 		osif_rl_debug("Failed to enqueue Scan Req as max scan %d already queued",
751 			      qdf_list_size(&osif_scan->scan_req_q));
752 		qdf_mem_free(scan_req);
753 	}
754 
755 	return status;
756 }
757 
758 /**
759  * wlan_scan_request_dequeue() - dequeue scan request
760  * @pdev: pdev object
761  * @scan_id: scan id
762  * @req: scan request
763  * @source : returns source of the scan request
764  * @dev: returns source net device
765  * @scan_start_timestamp: returns scan start timestamp
766  *
767  * Return: QDF_STATUS
768  */
769 static QDF_STATUS wlan_scan_request_dequeue(
770 	struct wlan_objmgr_pdev *pdev,
771 	uint32_t scan_id, struct cfg80211_scan_request **req,
772 	uint8_t *source, struct net_device **dev,
773 	qdf_time_t *scan_start_timestamp)
774 {
775 	QDF_STATUS status = QDF_STATUS_E_FAILURE;
776 	struct scan_req *scan_req;
777 	qdf_list_node_t *node = NULL, *next_node = NULL;
778 	struct pdev_osif_priv *osif_ctx;
779 	struct osif_scan_pdev *scan_priv;
780 
781 	if ((!source) || (!req)) {
782 		osif_err("source or request is NULL");
783 		return QDF_STATUS_E_NULL_VALUE;
784 	}
785 
786 	/* Get NL global context from objmgr*/
787 	osif_ctx = wlan_pdev_get_ospriv(pdev);
788 	if (!osif_ctx) {
789 		osif_err("Failed to retrieve osif context");
790 		return status;
791 	}
792 	scan_priv = osif_ctx->osif_scan;
793 
794 	qdf_mutex_acquire(&scan_priv->scan_req_q_lock);
795 	if (qdf_list_empty(&scan_priv->scan_req_q)) {
796 		osif_info("Scan List is empty");
797 		qdf_mutex_release(&scan_priv->scan_req_q_lock);
798 		return QDF_STATUS_E_FAILURE;
799 	}
800 
801 	if (QDF_STATUS_SUCCESS !=
802 		qdf_list_peek_front(&scan_priv->scan_req_q, &next_node)) {
803 		qdf_mutex_release(&scan_priv->scan_req_q_lock);
804 		osif_err("Failed to remove Scan Req from queue");
805 		return QDF_STATUS_E_FAILURE;
806 	}
807 
808 	do {
809 		node = next_node;
810 		scan_req = qdf_container_of(node, struct scan_req, node);
811 		if (scan_req->scan_id == scan_id) {
812 			status = qdf_list_remove_node(&scan_priv->scan_req_q,
813 						      node);
814 			if (status == QDF_STATUS_SUCCESS) {
815 				*req = scan_req->scan_request;
816 				*source = scan_req->source;
817 				*dev = scan_req->dev;
818 				*scan_start_timestamp =
819 					scan_req->scan_start_timestamp;
820 				qdf_mem_free(scan_req);
821 				qdf_mutex_release(&scan_priv->scan_req_q_lock);
822 				osif_debug("removed Scan id: %d, req = %pK, pending scans %d",
823 					   scan_id, req,
824 					   qdf_list_size(&scan_priv->scan_req_q));
825 				return QDF_STATUS_SUCCESS;
826 			} else {
827 				qdf_mutex_release(&scan_priv->scan_req_q_lock);
828 				osif_err("Failed to remove scan id %d, pending scans %d",
829 					 scan_id,
830 					 qdf_list_size(&scan_priv->scan_req_q));
831 				return status;
832 			}
833 		}
834 	} while (QDF_STATUS_SUCCESS ==
835 		qdf_list_peek_next(&scan_priv->scan_req_q, node, &next_node));
836 	qdf_mutex_release(&scan_priv->scan_req_q_lock);
837 	osif_debug("Failed to find scan id %d", scan_id);
838 
839 	return status;
840 }
841 
842 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
843 /**
844  * wlan_cfg80211_scan_done() - Scan completed callback to cfg80211
845  * @netdev: Net device
846  * @req : Scan request
847  * @aborted : true scan aborted false scan success
848  * @osif_priv: OS private structure
849  *
850  * This function notifies scan done to cfg80211
851  *
852  * Return: none
853  */
854 void wlan_cfg80211_scan_done(struct net_device *netdev,
855 			     struct cfg80211_scan_request *req,
856 			     bool aborted, struct pdev_osif_priv *osif_priv)
857 {
858 	struct cfg80211_scan_info info = {
859 		.aborted = aborted
860 	};
861 	bool driver_internal_netdev_state;
862 
863 	driver_internal_netdev_state = netdev->flags & IFF_UP;
864 	if (osif_priv->osif_check_netdev_state)
865 		driver_internal_netdev_state =
866 			osif_priv->osif_check_netdev_state(netdev);
867 
868 	if (driver_internal_netdev_state)
869 		cfg80211_scan_done(req, &info);
870 	else
871 		osif_debug("scan done callback has been dropped :%s",
872 			   (netdev)->name);
873 }
874 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
875 /**
876  * wlan_cfg80211_scan_done() - Scan completed callback to cfg80211
877  * @netdev: Net device
878  * @req : Scan request
879  * @aborted : true scan aborted false scan success
880  * @osif_priv: OS private structure
881  *
882  * This function notifies scan done to cfg80211
883  *
884  * Return: none
885  */
886 void wlan_cfg80211_scan_done(struct net_device *netdev,
887 			     struct cfg80211_scan_request *req,
888 			     bool aborted, struct pdev_osif_priv *osif_priv)
889 {
890 	bool driver_internal_net_state;
891 
892 	driver_internal_netdev_state = netdev->flags & IFF_UP;
893 	if (osif_priv->osif_check_netdev_state)
894 		driver_internal_net_state =
895 			osif_priv->osif_check_netdev_state(netdev);
896 
897 	if (driver_internal_netdev_state)
898 		cfg80211_scan_done(req, aborted);
899 	else
900 		osif_debug("scan request has been dropped :%s", (netdev)->name);
901 }
902 #endif
903 
904 /**
905  * wlan_vendor_scan_callback() - Scan completed callback event
906  *
907  * @req : Scan request
908  * @aborted : true scan aborted false scan success
909  *
910  * This function sends scan completed callback event to NL.
911  *
912  * Return: none
913  */
914 static void wlan_vendor_scan_callback(struct cfg80211_scan_request *req,
915 					bool aborted)
916 {
917 	struct sk_buff *skb;
918 	struct nlattr *attr;
919 	int i;
920 	uint8_t scan_status;
921 	uint64_t cookie;
922 	int index = QCA_NL80211_VENDOR_SUBCMD_SCAN_DONE_INDEX;
923 
924 	skb = wlan_cfg80211_vendor_event_alloc(req->wdev->wiphy, req->wdev,
925 					       SCAN_DONE_EVENT_BUF_SIZE + 4 +
926 					       NLMSG_HDRLEN,
927 					       index,
928 					       GFP_ATOMIC);
929 
930 	if (!skb) {
931 		osif_err("skb alloc failed");
932 		qdf_mem_free(req);
933 		return;
934 	}
935 
936 	cookie = (uintptr_t)req;
937 
938 	attr = nla_nest_start(skb, QCA_WLAN_VENDOR_ATTR_SCAN_SSIDS);
939 	if (!attr)
940 		goto nla_put_failure;
941 	for (i = 0; i < req->n_ssids; i++) {
942 		if (nla_put(skb, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
943 			goto nla_put_failure;
944 	}
945 	nla_nest_end(skb, attr);
946 
947 	attr = nla_nest_start(skb, QCA_WLAN_VENDOR_ATTR_SCAN_FREQUENCIES);
948 	if (!attr)
949 		goto nla_put_failure;
950 	for (i = 0; i < req->n_channels; i++) {
951 		if (nla_put_u32(skb, i, req->channels[i]->center_freq))
952 			goto nla_put_failure;
953 	}
954 	nla_nest_end(skb, attr);
955 
956 	if (req->ie &&
957 		nla_put(skb, QCA_WLAN_VENDOR_ATTR_SCAN_IE, req->ie_len,
958 			req->ie))
959 		goto nla_put_failure;
960 
961 	if (req->flags &&
962 		nla_put_u32(skb, QCA_WLAN_VENDOR_ATTR_SCAN_FLAGS, req->flags))
963 		goto nla_put_failure;
964 
965 	if (wlan_cfg80211_nla_put_u64(skb, QCA_WLAN_VENDOR_ATTR_SCAN_COOKIE,
966 					cookie))
967 		goto nla_put_failure;
968 
969 	scan_status = (aborted == true) ? VENDOR_SCAN_STATUS_ABORTED :
970 		VENDOR_SCAN_STATUS_NEW_RESULTS;
971 	if (nla_put_u8(skb, QCA_WLAN_VENDOR_ATTR_SCAN_STATUS, scan_status))
972 		goto nla_put_failure;
973 
974 	wlan_cfg80211_vendor_event(skb, GFP_ATOMIC);
975 	qdf_mem_free(req);
976 
977 	return;
978 
979 nla_put_failure:
980 	wlan_cfg80211_vendor_free_skb(skb);
981 	qdf_mem_free(req);
982 }
983 
984 /**
985  * wlan_scan_acquire_wake_lock_timeout() - acquire scan wake lock
986  * @psoc: psoc ptr
987  * @scan_wake_lock: Scan wake lock
988  * @timeout: timeout in ms
989  *
990  * Return: void
991  */
992 static inline
993 void wlan_scan_acquire_wake_lock_timeout(struct wlan_objmgr_psoc *psoc,
994 					 qdf_wake_lock_t *scan_wake_lock,
995 					 uint32_t timeout)
996 {
997 	if (!psoc || !scan_wake_lock)
998 		return;
999 
1000 	if (ucfg_scan_wake_lock_in_user_scan(psoc))
1001 		qdf_wake_lock_timeout_acquire(scan_wake_lock, timeout);
1002 }
1003 
1004 
1005 /**
1006  * wlan_scan_release_wake_lock() - release scan wake lock
1007  * @psoc: psoc ptr
1008  * @scan_wake_lock: Scan wake lock
1009  *
1010  * Return: void
1011  */
1012 #ifdef FEATURE_WLAN_DIAG_SUPPORT
1013 static inline
1014 void wlan_scan_release_wake_lock(struct wlan_objmgr_psoc *psoc,
1015 				 qdf_wake_lock_t *scan_wake_lock)
1016 {
1017 	if (!psoc || !scan_wake_lock)
1018 		return;
1019 
1020 	if (ucfg_scan_wake_lock_in_user_scan(psoc))
1021 		qdf_wake_lock_release(scan_wake_lock,
1022 				      WIFI_POWER_EVENT_WAKELOCK_SCAN);
1023 }
1024 #else
1025 static inline
1026 void wlan_scan_release_wake_lock(struct wlan_objmgr_psoc *psoc,
1027 				 qdf_wake_lock_t *scan_wake_lock)
1028 {
1029 	if (!psoc || !scan_wake_lock)
1030 		return;
1031 
1032 	if (ucfg_scan_wake_lock_in_user_scan(psoc))
1033 		qdf_wake_lock_release(scan_wake_lock, 0);
1034 }
1035 #endif
1036 
1037 static
1038 uint32_t wlan_scan_get_bss_count_for_scan(struct wlan_objmgr_pdev *pdev,
1039 					  qdf_time_t scan_start_ts)
1040 {
1041 	struct scan_filter *filter;
1042 	qdf_list_t *list = NULL;
1043 	uint32_t count = 0;
1044 
1045 	if (!scan_start_ts)
1046 		return count;
1047 
1048 	filter = qdf_mem_malloc(sizeof(*filter));
1049 	if (!filter)
1050 		return count;
1051 
1052 	filter->ignore_auth_enc_type = true;
1053 	filter->age_threshold = qdf_get_time_of_the_day_ms() - scan_start_ts;
1054 
1055 	list = ucfg_scan_get_result(pdev, filter);
1056 
1057 	qdf_mem_free(filter);
1058 
1059 	if (list) {
1060 		count = qdf_list_size(list);
1061 		ucfg_scan_purge_results(list);
1062 	}
1063 
1064 	return count;
1065 }
1066 
1067 /**
1068  * wlan_cfg80211_scan_done_callback() - scan done callback function called after
1069  * scan is finished
1070  * @vdev: vdev ptr
1071  * @event: Scan event
1072  * @args: Scan cb arg
1073  *
1074  * Return: void
1075  */
1076 static void wlan_cfg80211_scan_done_callback(
1077 					struct wlan_objmgr_vdev *vdev,
1078 					struct scan_event *event,
1079 					void *args)
1080 {
1081 	struct cfg80211_scan_request *req = NULL;
1082 	bool success = false;
1083 	uint32_t scan_id;
1084 	uint8_t source = NL_SCAN;
1085 	struct wlan_objmgr_pdev *pdev;
1086 	struct pdev_osif_priv *osif_priv;
1087 	struct net_device *netdev = NULL;
1088 	QDF_STATUS status;
1089 	qdf_time_t scan_start_timestamp = 0;
1090 	uint32_t unique_bss_count = 0;
1091 
1092 	if (!event) {
1093 		osif_nofl_err("Invalid scan event received");
1094 		return;
1095 	}
1096 
1097 	scan_id = event->scan_id;
1098 
1099 	qdf_mtrace(QDF_MODULE_ID_SCAN, QDF_MODULE_ID_OS_IF, event->type,
1100 		   event->vdev_id, scan_id);
1101 
1102 	if (event->type == SCAN_EVENT_TYPE_STARTED)
1103 		osif_nofl_info("scan start scan id %d", scan_id);
1104 
1105 	if (!util_is_scan_completed(event, &success))
1106 		return;
1107 
1108 	pdev = wlan_vdev_get_pdev(vdev);
1109 	osif_priv = wlan_pdev_get_ospriv(pdev);
1110 	status = wlan_scan_request_dequeue(
1111 			pdev, scan_id, &req, &source, &netdev,
1112 			&scan_start_timestamp);
1113 	if (QDF_IS_STATUS_ERROR(status)) {
1114 		osif_err("Dequeue of scan request failed ID: %d", scan_id);
1115 		goto allow_suspend;
1116 	}
1117 
1118 	if (!netdev) {
1119 		osif_err("net dev is NULL,Drop scan event Id: %d", scan_id);
1120 		/*
1121 		 * Free scan request in case of VENDOR_SCAN as it is
1122 		 * allocated in driver.
1123 		 */
1124 		if (source == VENDOR_SCAN)
1125 			qdf_mem_free(req);
1126 		goto allow_suspend;
1127 	}
1128 
1129 	/* Make sure vdev is active */
1130 	status = wlan_objmgr_vdev_try_get_ref(vdev, WLAN_OSIF_ID);
1131 	if (QDF_IS_STATUS_ERROR(status)) {
1132 		osif_err("Failed to get vdev reference: scan Id: %d", scan_id);
1133 		/*
1134 		 * Free scan request in case of VENDOR_SCAN as it is
1135 		 * allocated in driver.
1136 		 */
1137 		if (source == VENDOR_SCAN)
1138 			qdf_mem_free(req);
1139 		goto allow_suspend;
1140 	}
1141 
1142 	/*
1143 	 * Scan can be triggred from NL or vendor scan
1144 	 * - If scan is triggered from NL then cfg80211 scan done should be
1145 	 * called to updated scan completion to NL.
1146 	 * - If scan is triggred through vendor command then
1147 	 * scan done event will be posted
1148 	 */
1149 	if (NL_SCAN == source)
1150 		wlan_cfg80211_scan_done(netdev, req, !success, osif_priv);
1151 	else
1152 		wlan_vendor_scan_callback(req, !success);
1153 
1154 	wlan_objmgr_vdev_release_ref(vdev, WLAN_OSIF_ID);
1155 
1156 	unique_bss_count = wlan_scan_get_bss_count_for_scan(pdev,
1157 							  scan_start_timestamp);
1158 	osif_nofl_info("vdev %d, scan id %d type %s(%d) reason %s(%d) scan found %d bss",
1159 		       event->vdev_id, scan_id,
1160 		       util_scan_get_ev_type_name(event->type), event->type,
1161 		       util_scan_get_ev_reason_name(event->reason),
1162 		       event->reason, unique_bss_count);
1163 allow_suspend:
1164 	qdf_mutex_acquire(&osif_priv->osif_scan->scan_req_q_lock);
1165 	if (qdf_list_empty(&osif_priv->osif_scan->scan_req_q)) {
1166 		struct wlan_objmgr_psoc *psoc;
1167 
1168 		qdf_mutex_release(&osif_priv->osif_scan->scan_req_q_lock);
1169 		qdf_runtime_pm_allow_suspend(
1170 			&osif_priv->osif_scan->runtime_pm_lock);
1171 
1172 		psoc = wlan_pdev_get_psoc(pdev);
1173 		wlan_scan_release_wake_lock(psoc,
1174 					&osif_priv->osif_scan->scan_wake_lock);
1175 		/*
1176 		 * Acquire wakelock to handle the case where APP's tries
1177 		 * to suspend immediately after the driver gets connect
1178 		 * request(i.e after scan) from supplicant, this result in
1179 		 * app's is suspending and not able to process the connect
1180 		 * request to AP
1181 		 */
1182 		wlan_scan_acquire_wake_lock_timeout(psoc,
1183 					&osif_priv->osif_scan->scan_wake_lock,
1184 					SCAN_WAKE_LOCK_CONNECT_DURATION);
1185 	} else {
1186 		qdf_mutex_release(&osif_priv->osif_scan->scan_req_q_lock);
1187 	}
1188 
1189 }
1190 
1191 QDF_STATUS wlan_scan_runtime_pm_init(struct wlan_objmgr_pdev *pdev)
1192 {
1193 	struct pdev_osif_priv *osif_priv;
1194 	struct osif_scan_pdev *scan_priv;
1195 
1196 	wlan_pdev_obj_lock(pdev);
1197 	osif_priv = wlan_pdev_get_ospriv(pdev);
1198 	wlan_pdev_obj_unlock(pdev);
1199 
1200 	scan_priv = osif_priv->osif_scan;
1201 
1202 	return qdf_runtime_lock_init(&scan_priv->runtime_pm_lock);
1203 }
1204 
1205 void wlan_scan_runtime_pm_deinit(struct wlan_objmgr_pdev *pdev)
1206 {
1207 	struct pdev_osif_priv *osif_priv;
1208 	struct osif_scan_pdev *scan_priv;
1209 
1210 	wlan_pdev_obj_lock(pdev);
1211 	osif_priv = wlan_pdev_get_ospriv(pdev);
1212 	wlan_pdev_obj_unlock(pdev);
1213 
1214 	scan_priv = osif_priv->osif_scan;
1215 	qdf_runtime_lock_deinit(&scan_priv->runtime_pm_lock);
1216 }
1217 
1218 QDF_STATUS wlan_cfg80211_scan_priv_init(struct wlan_objmgr_pdev *pdev)
1219 {
1220 	struct pdev_osif_priv *osif_priv;
1221 	struct osif_scan_pdev *scan_priv;
1222 	struct wlan_objmgr_psoc *psoc;
1223 	wlan_scan_requester req_id;
1224 
1225 	psoc = wlan_pdev_get_psoc(pdev);
1226 
1227 	req_id = ucfg_scan_register_requester(psoc, "CFG",
1228 		wlan_cfg80211_scan_done_callback, NULL);
1229 
1230 	osif_priv = wlan_pdev_get_ospriv(pdev);
1231 	scan_priv = qdf_mem_malloc(sizeof(*scan_priv));
1232 	if (!scan_priv)
1233 		return QDF_STATUS_E_NOMEM;
1234 
1235 	/* Initialize the scan request queue */
1236 	osif_priv->osif_scan = scan_priv;
1237 	scan_priv->req_id = req_id;
1238 	qdf_list_create(&scan_priv->scan_req_q, WLAN_MAX_SCAN_COUNT);
1239 	qdf_mutex_create(&scan_priv->scan_req_q_lock);
1240 	qdf_wake_lock_create(&scan_priv->scan_wake_lock, "scan_wake_lock");
1241 
1242 	return QDF_STATUS_SUCCESS;
1243 }
1244 
1245 QDF_STATUS wlan_cfg80211_scan_priv_deinit(struct wlan_objmgr_pdev *pdev)
1246 {
1247 	struct pdev_osif_priv *osif_priv;
1248 	struct osif_scan_pdev *scan_priv;
1249 	struct wlan_objmgr_psoc *psoc;
1250 
1251 	psoc = wlan_pdev_get_psoc(pdev);
1252 	osif_priv = wlan_pdev_get_ospriv(pdev);
1253 
1254 	wlan_cfg80211_cleanup_scan_queue(pdev, NULL);
1255 	scan_priv = osif_priv->osif_scan;
1256 	qdf_wake_lock_destroy(&scan_priv->scan_wake_lock);
1257 	qdf_mutex_destroy(&scan_priv->scan_req_q_lock);
1258 	qdf_list_destroy(&scan_priv->scan_req_q);
1259 	ucfg_scan_unregister_requester(psoc, scan_priv->req_id);
1260 	osif_priv->osif_scan = NULL;
1261 	qdf_mem_free(scan_priv);
1262 
1263 	return QDF_STATUS_SUCCESS;
1264 }
1265 
1266 /**
1267  * wlan_cfg80211_enqueue_for_cleanup() - Function to populate scan cleanup queue
1268  * @scan_cleanup_q: Scan cleanup queue to be populated
1269  * @scan_priv: Pointer to scan related data used by cfg80211 scan
1270  * @dev: Netdevice pointer
1271  *
1272  * The function synchrounously iterates through the global scan queue to
1273  * identify entries that have to be cleaned up, copies identified entries
1274  * to another queue(to send scan complete event to NL later) and removes the
1275  * entry from the global scan queue.
1276  *
1277  * Return: None
1278  */
1279 static void
1280 wlan_cfg80211_enqueue_for_cleanup(qdf_list_t *scan_cleanup_q,
1281 				  struct osif_scan_pdev *scan_priv,
1282 				  struct net_device *dev)
1283 {
1284 	struct scan_req *scan_req, *scan_cleanup;
1285 	qdf_list_node_t *node = NULL, *next_node = NULL;
1286 
1287 	qdf_mutex_acquire(&scan_priv->scan_req_q_lock);
1288 	if (QDF_STATUS_SUCCESS !=
1289 		qdf_list_peek_front(&scan_priv->scan_req_q,
1290 				    &node)) {
1291 		qdf_mutex_release(&scan_priv->scan_req_q_lock);
1292 		return;
1293 	}
1294 
1295 	while (node) {
1296 		/*
1297 		 * Keep track of the next node, to traverse through the list
1298 		 * in the event of the current node being deleted.
1299 		 */
1300 		qdf_list_peek_next(&scan_priv->scan_req_q,
1301 				   node, &next_node);
1302 		scan_req = qdf_container_of(node, struct scan_req, node);
1303 		if (!dev || (dev == scan_req->dev)) {
1304 			scan_cleanup = qdf_mem_malloc(sizeof(struct scan_req));
1305 			if (!scan_cleanup) {
1306 				qdf_mutex_release(&scan_priv->scan_req_q_lock);
1307 				return;
1308 			}
1309 			scan_cleanup->scan_request = scan_req->scan_request;
1310 			scan_cleanup->scan_id = scan_req->scan_id;
1311 			scan_cleanup->source = scan_req->source;
1312 			scan_cleanup->dev = scan_req->dev;
1313 			qdf_list_insert_back(scan_cleanup_q,
1314 					     &scan_cleanup->node);
1315 			if (QDF_STATUS_SUCCESS !=
1316 				qdf_list_remove_node(&scan_priv->scan_req_q,
1317 						     node)) {
1318 				qdf_mutex_release(&scan_priv->scan_req_q_lock);
1319 				osif_err("Failed to remove scan request");
1320 				return;
1321 			}
1322 			qdf_mem_free(scan_req);
1323 		}
1324 		node = next_node;
1325 		next_node = NULL;
1326 	}
1327 	qdf_mutex_release(&scan_priv->scan_req_q_lock);
1328 }
1329 
1330 void wlan_cfg80211_cleanup_scan_queue(struct wlan_objmgr_pdev *pdev,
1331 				      struct net_device *dev)
1332 {
1333 	struct scan_req *scan_req;
1334 	struct cfg80211_scan_request *req;
1335 	uint8_t source;
1336 	bool aborted = true;
1337 	struct pdev_osif_priv *osif_priv;
1338 	qdf_list_t scan_cleanup_q;
1339 	qdf_list_node_t *node = NULL;
1340 
1341 	if (!pdev) {
1342 		osif_err("pdev is Null");
1343 		return;
1344 	}
1345 
1346 	osif_priv = wlan_pdev_get_ospriv(pdev);
1347 
1348 	/*
1349 	 * To avoid any race conditions, create a local list to copy all the
1350 	 * scan entries to be removed and then send scan complete for each of
1351 	 * the identified entries to NL.
1352 	 */
1353 	qdf_list_create(&scan_cleanup_q, WLAN_MAX_SCAN_COUNT);
1354 	wlan_cfg80211_enqueue_for_cleanup(&scan_cleanup_q,
1355 					  osif_priv->osif_scan, dev);
1356 
1357 	while (!qdf_list_empty(&scan_cleanup_q)) {
1358 		if (QDF_STATUS_SUCCESS != qdf_list_remove_front(&scan_cleanup_q,
1359 								&node)) {
1360 			osif_err("Failed to remove scan request");
1361 			return;
1362 		}
1363 		scan_req = container_of(node, struct scan_req, node);
1364 		req = scan_req->scan_request;
1365 		source = scan_req->source;
1366 		if (NL_SCAN == source)
1367 			wlan_cfg80211_scan_done(scan_req->dev, req,
1368 						aborted, osif_priv);
1369 		else
1370 			wlan_vendor_scan_callback(req, aborted);
1371 
1372 		qdf_mem_free(scan_req);
1373 	}
1374 	qdf_list_destroy(&scan_cleanup_q);
1375 
1376 	return;
1377 }
1378 
1379 /**
1380  * wlan_cfg80211_update_scan_policy_type_flags() - Set scan flags according to
1381  * scan request
1382  * @req: scan request to populate
1383  * @scan_req: Pointer to scan request params
1384  *
1385  * Return: None
1386  */
1387 #if defined(CFG80211_SCAN_DBS_CONTROL_SUPPORT) || \
1388 	   (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0))
1389 static void wlan_cfg80211_update_scan_policy_type_flags(
1390 	struct cfg80211_scan_request *req,
1391 	struct scan_req_params *scan_req)
1392 {
1393 	if (req->flags & NL80211_SCAN_FLAG_HIGH_ACCURACY)
1394 		scan_req->scan_policy_high_accuracy = true;
1395 	if (req->flags & NL80211_SCAN_FLAG_LOW_SPAN)
1396 		scan_req->scan_policy_low_span = true;
1397 	if (req->flags & NL80211_SCAN_FLAG_LOW_POWER)
1398 		scan_req->scan_policy_low_power = true;
1399 
1400 	if (wlan_cfg80211_is_colocated_6ghz_scan_supported(req->flags))
1401 		scan_req->scan_policy_colocated_6ghz = true;
1402 }
1403 #else
1404 static inline void wlan_cfg80211_update_scan_policy_type_flags(
1405 		struct cfg80211_scan_request *req,
1406 		struct scan_req_params *scan_req)
1407 {
1408 }
1409 #endif
1410 
1411 #ifdef WLAN_POLICY_MGR_ENABLE
1412 static bool
1413 wlan_cfg80211_allow_simultaneous_scan(struct wlan_objmgr_psoc *psoc)
1414 {
1415 	return policy_mgr_is_scan_simultaneous_capable(psoc);
1416 }
1417 #else
1418 static bool
1419 wlan_cfg80211_allow_simultaneous_scan(struct wlan_objmgr_psoc *psoc)
1420 {
1421 	return true;
1422 }
1423 #endif
1424 
1425 enum scan_priority convert_nl_scan_priority_to_internal(
1426 	enum qca_wlan_vendor_scan_priority nl_scan_priority)
1427 {
1428 	switch (nl_scan_priority) {
1429 	case QCA_WLAN_VENDOR_SCAN_PRIORITY_VERY_LOW:
1430 		return SCAN_PRIORITY_VERY_LOW;
1431 
1432 	case QCA_WLAN_VENDOR_SCAN_PRIORITY_LOW:
1433 		return SCAN_PRIORITY_LOW;
1434 
1435 	case QCA_WLAN_VENDOR_SCAN_PRIORITY_MEDIUM:
1436 		return SCAN_PRIORITY_MEDIUM;
1437 
1438 	case QCA_WLAN_VENDOR_SCAN_PRIORITY_HIGH:
1439 		return SCAN_PRIORITY_HIGH;
1440 
1441 	case QCA_WLAN_VENDOR_SCAN_PRIORITY_VERY_HIGH:
1442 		return SCAN_PRIORITY_VERY_HIGH;
1443 
1444 	default:
1445 		return SCAN_PRIORITY_COUNT;
1446 	}
1447 }
1448 
1449 int wlan_cfg80211_scan(struct wlan_objmgr_vdev *vdev,
1450 		       struct cfg80211_scan_request *request,
1451 		       struct scan_params *params)
1452 {
1453 	struct scan_start_request *req;
1454 	struct wlan_ssid *pssid;
1455 	uint8_t i;
1456 	int ret = 0;
1457 	uint8_t num_chan = 0;
1458 	uint32_t c_freq;
1459 	struct wlan_objmgr_pdev *pdev = wlan_vdev_get_pdev(vdev);
1460 	wlan_scan_requester req_id;
1461 	struct pdev_osif_priv *osif_priv;
1462 	struct wlan_objmgr_psoc *psoc;
1463 	wlan_scan_id scan_id;
1464 	bool is_p2p_scan = false;
1465 	enum wlan_band band;
1466 	QDF_STATUS qdf_status;
1467 	enum QDF_OPMODE opmode;
1468 	uint32_t extra_ie_len = 0;
1469 
1470 	psoc = wlan_pdev_get_psoc(pdev);
1471 	if (!psoc) {
1472 		osif_err("Invalid psoc object");
1473 		return -EINVAL;
1474 	}
1475 	opmode = wlan_vdev_mlme_get_opmode(vdev);
1476 
1477 	osif_debug("%s(vdev%d): mode %d", request->wdev->netdev->name,
1478 		   wlan_vdev_get_id(vdev), opmode);
1479 
1480 	/* Get NL global context from objmgr*/
1481 	osif_priv = wlan_pdev_get_ospriv(pdev);
1482 	if (!osif_priv) {
1483 		osif_err("Invalid osif priv object");
1484 		return -EINVAL;
1485 	}
1486 
1487 	/*
1488 	 * For a non-SAP vdevs, if a scan is already going on i.e the scan queue
1489 	 * is not empty, and the simultaneous scan is disabled, dont allow 2nd
1490 	 * scan.
1491 	 */
1492 	qdf_mutex_acquire(&osif_priv->osif_scan->scan_req_q_lock);
1493 	if (!wlan_cfg80211_allow_simultaneous_scan(psoc) &&
1494 	    !qdf_list_empty(&osif_priv->osif_scan->scan_req_q) &&
1495 	    opmode != QDF_SAP_MODE) {
1496 		qdf_mutex_release(&osif_priv->osif_scan->scan_req_q_lock);
1497 		osif_err("Simultaneous scan disabled, reject scan");
1498 		return -EBUSY;
1499 	}
1500 	qdf_mutex_release(&osif_priv->osif_scan->scan_req_q_lock);
1501 
1502 	req = qdf_mem_malloc(sizeof(*req));
1503 	if (!req)
1504 		return -EINVAL;
1505 
1506 	/* Initialize the scan global params */
1507 	ucfg_scan_init_default_params(vdev, req);
1508 
1509 	req_id = osif_priv->osif_scan->req_id;
1510 	scan_id = ucfg_scan_get_scan_id(psoc);
1511 	if (!scan_id) {
1512 		osif_err("Invalid scan id");
1513 		qdf_mem_free(req);
1514 		return -EINVAL;
1515 	}
1516 
1517 	/* fill the scan request structure */
1518 	req->vdev = vdev;
1519 	req->scan_req.vdev_id = wlan_vdev_get_id(vdev);
1520 	req->scan_req.scan_id = scan_id;
1521 	req->scan_req.scan_req_id = req_id;
1522 
1523 	/* Update scan policy type flags according to cfg scan request */
1524 	wlan_cfg80211_update_scan_policy_type_flags(request,
1525 					     &req->scan_req);
1526 	/*
1527 	 * Even though supplicant doesn't provide any SSIDs, n_ssids is
1528 	 * set to 1.  Because of this, driver is assuming that this is not
1529 	 * wildcard scan and so is not aging out the scan results.
1530 	 */
1531 	if ((request->ssids) && (request->n_ssids == 1) &&
1532 	    ('\0' == request->ssids->ssid[0])) {
1533 		request->n_ssids = 0;
1534 	}
1535 
1536 	if ((request->ssids) && (0 < request->n_ssids)) {
1537 		int j;
1538 		req->scan_req.num_ssids = request->n_ssids;
1539 
1540 		if (req->scan_req.num_ssids > WLAN_SCAN_MAX_NUM_SSID) {
1541 			osif_info("number of ssid %d greater than MAX %d",
1542 				  req->scan_req.num_ssids,
1543 				  WLAN_SCAN_MAX_NUM_SSID);
1544 			req->scan_req.num_ssids = WLAN_SCAN_MAX_NUM_SSID;
1545 		}
1546 		/* copy all the ssid's and their length */
1547 		for (j = 0; j < req->scan_req.num_ssids; j++)  {
1548 			pssid = &req->scan_req.ssid[j];
1549 			/* get the ssid length */
1550 			pssid->length = request->ssids[j].ssid_len;
1551 			if (pssid->length > WLAN_SSID_MAX_LEN)
1552 				pssid->length = WLAN_SSID_MAX_LEN;
1553 			qdf_mem_copy(pssid->ssid,
1554 				     &request->ssids[j].ssid[0],
1555 				     pssid->length);
1556 		}
1557 	}
1558 	if (request->ssids ||
1559 	   (opmode == QDF_P2P_GO_MODE) || (opmode == QDF_P2P_DEVICE_MODE))
1560 		req->scan_req.scan_f_passive = false;
1561 
1562 	if (params->half_rate)
1563 		req->scan_req.scan_f_half_rate = true;
1564 	else if (params->quarter_rate)
1565 		req->scan_req.scan_f_quarter_rate = true;
1566 
1567 	if (params->strict_pscan)
1568 		req->scan_req.scan_f_strict_passive_pch = true;
1569 
1570 	if ((request->n_ssids == 1) && request->ssids &&
1571 	   !qdf_mem_cmp(&request->ssids[0], "DIRECT-", 7))
1572 		is_p2p_scan = true;
1573 
1574 	if (is_p2p_scan && request->no_cck)
1575 		req->scan_req.scan_type = SCAN_TYPE_P2P_SEARCH;
1576 
1577 	if (params->dwell_time_active)
1578 		req->scan_req.dwell_time_active = params->dwell_time_active;
1579 
1580 	if (params->dwell_time_active_2g)
1581 		req->scan_req.dwell_time_active_2g =
1582 			params->dwell_time_active_2g;
1583 
1584 	if (params->dwell_time_passive)
1585 		req->scan_req.dwell_time_passive = params->dwell_time_passive;
1586 
1587 	if (params->dwell_time_active_6g)
1588 		req->scan_req.dwell_time_active_6g =
1589 			params->dwell_time_active_6g;
1590 
1591 	if (params->dwell_time_passive_6g)
1592 		req->scan_req.dwell_time_passive_6g =
1593 			params->dwell_time_passive_6g;
1594 
1595 	/* Set dwell time mode according to scan policy type flags */
1596 	if (ucfg_scan_cfg_honour_nl_scan_policy_flags(psoc)) {
1597 		if (req->scan_req.scan_policy_high_accuracy)
1598 			req->scan_req.adaptive_dwell_time_mode =
1599 						SCAN_DWELL_MODE_STATIC;
1600 		if (req->scan_req.scan_policy_low_power)
1601 			req->scan_req.adaptive_dwell_time_mode =
1602 						SCAN_DWELL_MODE_AGGRESSIVE;
1603 	}
1604 
1605 	/*
1606 	 * FW require at least 1 MAC to send probe request.
1607 	 * If MAC is all 0 set it to BC addr as this is the address on
1608 	 * which fw will send probe req.
1609 	 */
1610 	req->scan_req.num_bssid = 1;
1611 	wlan_copy_bssid_scan_request(req, request);
1612 	if (qdf_is_macaddr_zero(&req->scan_req.bssid_list[0]))
1613 		qdf_set_macaddr_broadcast(&req->scan_req.bssid_list[0]);
1614 
1615 	if (params->scan_f_2ghz && !params->scan_f_5ghz) {
1616 		req->scan_req.scan_f_2ghz = true;
1617 		req->scan_req.scan_f_5ghz = false;
1618 	} else if (!params->scan_f_2ghz && params->scan_f_5ghz) {
1619 		req->scan_req.scan_f_2ghz = false;
1620 		req->scan_req.scan_f_5ghz = true;
1621 	}
1622 
1623 	if (request->n_channels) {
1624 #ifdef WLAN_POLICY_MGR_ENABLE
1625 		bool ap_or_go_present =
1626 			policy_mgr_mode_specific_connection_count(
1627 			     psoc, PM_SAP_MODE, NULL) ||
1628 			     policy_mgr_mode_specific_connection_count(
1629 			     psoc, PM_P2P_GO_MODE, NULL);
1630 #endif
1631 		for (i = 0; i < request->n_channels; i++) {
1632 			c_freq = request->channels[i]->center_freq;
1633 			if (wlan_reg_is_dsrc_freq(c_freq))
1634 				continue;
1635 #ifdef WLAN_POLICY_MGR_ENABLE
1636 			if (ap_or_go_present) {
1637 				bool ok;
1638 
1639 				qdf_status = policy_mgr_is_chan_ok_for_dnbs(
1640 							psoc, c_freq, &ok);
1641 
1642 				if (QDF_IS_STATUS_ERROR(qdf_status)) {
1643 					osif_err("DNBS check failed");
1644 					ret = -EINVAL;
1645 					goto err;
1646 				}
1647 				if (!ok)
1648 					continue;
1649 			}
1650 #endif
1651 
1652 			if ((req->scan_req.scan_f_2ghz &&
1653 			     WLAN_REG_IS_24GHZ_CH_FREQ(c_freq)) ||
1654 			    (req->scan_req.scan_f_5ghz &&
1655 			     (WLAN_REG_IS_5GHZ_CH_FREQ(c_freq) ||
1656 			      WLAN_REG_IS_49GHZ_FREQ(c_freq) ||
1657 			      WLAN_REG_IS_6GHZ_CHAN_FREQ(c_freq)))) {
1658 				req->scan_req.chan_list.chan[num_chan].freq =
1659 									c_freq;
1660 				band = util_scan_scm_freq_to_band(c_freq);
1661 				if (band == WLAN_BAND_2_4_GHZ)
1662 					req->scan_req.chan_list.chan[num_chan].phymode =
1663 						SCAN_PHY_MODE_11G;
1664 				else
1665 					req->scan_req.chan_list.chan[num_chan].phymode =
1666 						SCAN_PHY_MODE_11A;
1667 				num_chan++;
1668 				if (num_chan >= NUM_CHANNELS)
1669 					break;
1670 			}
1671 		}
1672 	}
1673 	if (!num_chan) {
1674 		osif_err("Received zero non-dsrc channels");
1675 		ret = -EINVAL;
1676 		goto err;
1677 	}
1678 	req->scan_req.chan_list.num_chan = num_chan;
1679 
1680 	/* P2P increase the scan priority */
1681 	if (is_p2p_scan)
1682 		req->scan_req.scan_priority = SCAN_PRIORITY_HIGH;
1683 
1684 	if (params->priority != SCAN_PRIORITY_COUNT)
1685 		req->scan_req.scan_priority = params->priority;
1686 
1687 	if (request->ie_len)
1688 		extra_ie_len = request->ie_len;
1689 	else if (params->default_ie.ptr && params->default_ie.len)
1690 		extra_ie_len = params->default_ie.len;
1691 
1692 	if (params->vendor_ie.ptr && params->vendor_ie.len)
1693 		extra_ie_len += params->vendor_ie.len;
1694 
1695 	if (extra_ie_len) {
1696 		req->scan_req.extraie.ptr = qdf_mem_malloc(extra_ie_len);
1697 		if (!req->scan_req.extraie.ptr) {
1698 			ret = -ENOMEM;
1699 			goto err;
1700 		}
1701 	}
1702 
1703 	if (request->ie_len) {
1704 		req->scan_req.extraie.len = request->ie_len;
1705 		qdf_mem_copy(req->scan_req.extraie.ptr, request->ie,
1706 			     request->ie_len);
1707 	} else if (params->default_ie.ptr && params->default_ie.len) {
1708 		req->scan_req.extraie.len = params->default_ie.len;
1709 		qdf_mem_copy(req->scan_req.extraie.ptr, params->default_ie.ptr,
1710 			     params->default_ie.len);
1711 	}
1712 
1713 	if (params->vendor_ie.ptr && params->vendor_ie.len) {
1714 		qdf_mem_copy((req->scan_req.extraie.ptr +
1715 			      req->scan_req.extraie.len),
1716 			     params->vendor_ie.ptr, params->vendor_ie.len);
1717 
1718 		req->scan_req.extraie.len += params->vendor_ie.len;
1719 	}
1720 
1721 	if (!is_p2p_scan) {
1722 		if (req->scan_req.scan_random.randomize)
1723 			wlan_scan_rand_attrs(vdev, request, req);
1724 		if (ucfg_ie_allowlist_enabled(psoc, vdev) &&
1725 		    ucfg_copy_ie_allowlist_attrs(psoc,
1726 						 &req->scan_req.ie_allowlist))
1727 			req->scan_req.scan_f_en_ie_allowlist_in_probe = true;
1728 	}
1729 
1730 	if (request->flags & NL80211_SCAN_FLAG_FLUSH)
1731 		ucfg_scan_flush_results(pdev, NULL);
1732 
1733 	if (params->scan_probe_unicast_ra)
1734 		req->scan_req.scan_ctrl_flags_ext |=
1735 				SCAN_FLAG_EXT_FORCE_UNICAST_RA;
1736 
1737 	osif_debug("scan_ctrl_flags_ext %0x",
1738 		   req->scan_req.scan_ctrl_flags_ext);
1739 
1740 	/*
1741 	 * Acquire wakelock to handle the case where APP's send scan to connect.
1742 	 * If suspend is received during scan scan will be aborted and APP will
1743 	 * not get scan result and not connect. eg if PNO is implemented in
1744 	 * framework.
1745 	 */
1746 	wlan_scan_acquire_wake_lock_timeout(psoc,
1747 					&osif_priv->osif_scan->scan_wake_lock,
1748 					SCAN_WAKE_LOCK_SCAN_DURATION);
1749 
1750 	qdf_runtime_pm_prevent_suspend(
1751 		&osif_priv->osif_scan->runtime_pm_lock);
1752 
1753 	qdf_status = wlan_schedule_scan_start_request(pdev, request,
1754 						      params->source, req);
1755 	if (QDF_IS_STATUS_ERROR(qdf_status)) {
1756 		qdf_mutex_acquire(&osif_priv->osif_scan->scan_req_q_lock);
1757 		if (qdf_list_empty(&osif_priv->osif_scan->scan_req_q)) {
1758 			qdf_mutex_release(
1759 				&osif_priv->osif_scan->scan_req_q_lock);
1760 			qdf_runtime_pm_allow_suspend(
1761 					&osif_priv->osif_scan->runtime_pm_lock);
1762 			wlan_scan_release_wake_lock(
1763 					psoc,
1764 					&osif_priv->osif_scan->scan_wake_lock);
1765 		} else {
1766 			qdf_mutex_release(
1767 				&osif_priv->osif_scan->scan_req_q_lock);
1768 		}
1769 	}
1770 
1771 	return qdf_status_to_os_return(qdf_status);
1772 
1773 err:
1774 	qdf_mem_free(req);
1775 	return ret;
1776 }
1777 
1778 /**
1779  * wlan_get_scanid() - API to get the scan id
1780  * from the scan cookie attribute.
1781  * @pdev: Pointer to pdev object
1782  * @scan_id: Pointer to scan id
1783  * @cookie : Scan cookie attribute
1784  *
1785  * API to get the scan id from the scan cookie attribute
1786  * sent from supplicant by matching scan request.
1787  *
1788  * Return: 0 for success, non zero for failure
1789  */
1790 static int wlan_get_scanid(struct wlan_objmgr_pdev *pdev,
1791 			       uint32_t *scan_id, uint64_t cookie)
1792 {
1793 	struct scan_req *scan_req;
1794 	qdf_list_node_t *node = NULL;
1795 	qdf_list_node_t *ptr_node = NULL;
1796 	int ret = -EINVAL;
1797 	struct pdev_osif_priv *osif_ctx;
1798 	struct osif_scan_pdev *scan_priv;
1799 
1800 	/* Get NL global context from objmgr*/
1801 	osif_ctx = wlan_pdev_get_ospriv(pdev);
1802 	if (!osif_ctx) {
1803 		osif_err("Failed to retrieve osif context");
1804 		return ret;
1805 	}
1806 	scan_priv = osif_ctx->osif_scan;
1807 	qdf_mutex_acquire(&scan_priv->scan_req_q_lock);
1808 	if (qdf_list_empty(&scan_priv->scan_req_q)) {
1809 		qdf_mutex_release(&scan_priv->scan_req_q_lock);
1810 		osif_err("Failed to retrieve scan id");
1811 		return ret;
1812 	}
1813 
1814 	if (QDF_STATUS_SUCCESS !=
1815 			    qdf_list_peek_front(&scan_priv->scan_req_q,
1816 			    &ptr_node)) {
1817 		qdf_mutex_release(&scan_priv->scan_req_q_lock);
1818 		return ret;
1819 	}
1820 
1821 	do {
1822 		node = ptr_node;
1823 		scan_req = qdf_container_of(node, struct scan_req, node);
1824 		if (cookie ==
1825 		    (uintptr_t)(scan_req->scan_request)) {
1826 			*scan_id = scan_req->scan_id;
1827 			ret = 0;
1828 			break;
1829 		}
1830 	} while (QDF_STATUS_SUCCESS ==
1831 		 qdf_list_peek_next(&scan_priv->scan_req_q,
1832 		 node, &ptr_node));
1833 
1834 	qdf_mutex_release(&scan_priv->scan_req_q_lock);
1835 
1836 	return ret;
1837 }
1838 
1839 QDF_STATUS wlan_abort_scan(struct wlan_objmgr_pdev *pdev,
1840 				   uint32_t pdev_id, uint32_t vdev_id,
1841 				   wlan_scan_id scan_id, bool sync)
1842 {
1843 	struct scan_cancel_request *req;
1844 	struct pdev_osif_priv *osif_ctx;
1845 	struct osif_scan_pdev *scan_priv;
1846 	QDF_STATUS status;
1847 	struct wlan_objmgr_vdev *vdev;
1848 
1849 	req = qdf_mem_malloc(sizeof(*req));
1850 	if (!req)
1851 		return QDF_STATUS_E_NOMEM;
1852 
1853 	/* Get NL global context from objmgr*/
1854 	osif_ctx = wlan_pdev_get_ospriv(pdev);
1855 	if (!osif_ctx) {
1856 		osif_err("Failed to retrieve osif context");
1857 		qdf_mem_free(req);
1858 		return QDF_STATUS_E_FAILURE;
1859 	}
1860 	if (vdev_id == INVAL_VDEV_ID)
1861 		vdev = wlan_objmgr_pdev_get_first_vdev(pdev, WLAN_OSIF_ID);
1862 	else
1863 		vdev = wlan_objmgr_get_vdev_by_id_from_pdev(pdev,
1864 				vdev_id, WLAN_OSIF_ID);
1865 
1866 	if (!vdev) {
1867 		qdf_mem_free(req);
1868 		return QDF_STATUS_E_INVAL;
1869 	}
1870 	scan_priv = osif_ctx->osif_scan;
1871 	req->cancel_req.requester = scan_priv->req_id;
1872 	req->vdev = vdev;
1873 	req->cancel_req.scan_id = scan_id;
1874 	req->cancel_req.pdev_id = pdev_id;
1875 	req->cancel_req.vdev_id = vdev_id;
1876 	if (scan_id != INVAL_SCAN_ID && scan_id != CANCEL_HOST_SCAN_ID)
1877 		req->cancel_req.req_type = WLAN_SCAN_CANCEL_SINGLE;
1878 	else if (scan_id == CANCEL_HOST_SCAN_ID)
1879 		req->cancel_req.req_type = WLAN_SCAN_CANCEL_HOST_VDEV_ALL;
1880 	else if (vdev_id == INVAL_VDEV_ID)
1881 		req->cancel_req.req_type = WLAN_SCAN_CANCEL_PDEV_ALL;
1882 	else
1883 		req->cancel_req.req_type = WLAN_SCAN_CANCEL_VDEV_ALL;
1884 
1885 	osif_debug("Type %d Vdev %d pdev %d scan id %d sync %d",
1886 		   req->cancel_req.req_type, req->cancel_req.vdev_id,
1887 		   req->cancel_req.pdev_id, req->cancel_req.scan_id, sync);
1888 
1889 	if (sync)
1890 		status = ucfg_scan_cancel_sync(req);
1891 	else
1892 		status = ucfg_scan_cancel(req);
1893 	if (QDF_IS_STATUS_ERROR(status))
1894 		osif_err("Cancel scan request failed");
1895 
1896 	wlan_objmgr_vdev_release_ref(vdev, WLAN_OSIF_ID);
1897 
1898 	return status;
1899 }
1900 
1901 qdf_export_symbol(wlan_abort_scan);
1902 
1903 int wlan_cfg80211_abort_scan(struct wlan_objmgr_pdev *pdev)
1904 {
1905 	uint8_t pdev_id;
1906 
1907 	pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
1908 
1909 	if (ucfg_scan_get_pdev_status(pdev) !=
1910 	   SCAN_NOT_IN_PROGRESS)
1911 		wlan_abort_scan(pdev, pdev_id,
1912 			INVAL_VDEV_ID, INVAL_SCAN_ID, true);
1913 
1914 	return 0;
1915 }
1916 
1917 int wlan_vendor_abort_scan(struct wlan_objmgr_pdev *pdev,
1918 			const void *data, int data_len)
1919 {
1920 	struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_SCAN_MAX + 1];
1921 	int ret = -EINVAL;
1922 	wlan_scan_id scan_id;
1923 	uint64_t cookie;
1924 	uint8_t pdev_id;
1925 
1926 	pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
1927 	if (wlan_cfg80211_nla_parse(tb, QCA_WLAN_VENDOR_ATTR_SCAN_MAX, data,
1928 				    data_len, cfg80211_scan_policy)) {
1929 		osif_err("Invalid ATTR");
1930 		return ret;
1931 	}
1932 
1933 	if (tb[QCA_WLAN_VENDOR_ATTR_SCAN_COOKIE]) {
1934 		cookie = nla_get_u64(
1935 			    tb[QCA_WLAN_VENDOR_ATTR_SCAN_COOKIE]);
1936 		ret = wlan_get_scanid(pdev, &scan_id, cookie);
1937 		if (ret != 0)
1938 			return ret;
1939 		if (ucfg_scan_get_pdev_status(pdev) !=
1940 		   SCAN_NOT_IN_PROGRESS)
1941 			wlan_abort_scan(pdev, INVAL_PDEV_ID,
1942 					INVAL_VDEV_ID, scan_id, true);
1943 	}
1944 	return 0;
1945 }
1946 
1947 static inline struct ieee80211_channel *
1948 wlan_get_ieee80211_channel(struct wiphy *wiphy,
1949 		struct wlan_objmgr_pdev *pdev,
1950 		int chan_freq)
1951 {
1952 	struct ieee80211_channel *chan;
1953 
1954 	chan = ieee80211_get_channel(wiphy, chan_freq);
1955 	if (!chan)
1956 		osif_err_rl("chan is NULL, freq: %d", chan_freq);
1957 
1958 	return chan;
1959 }
1960 
1961 #ifdef WLAN_ENABLE_AGEIE_ON_SCAN_RESULTS
1962 static inline int wlan_get_frame_len(struct scan_cache_entry *scan_params)
1963 {
1964 	return util_scan_entry_frame_len(scan_params) + sizeof(qcom_ie_age);
1965 }
1966 
1967 static inline void wlan_add_age_ie(uint8_t *mgmt_frame,
1968 	struct scan_cache_entry *scan_params)
1969 {
1970 	qcom_ie_age *qie_age = NULL;
1971 
1972 	/* GPS Requirement: need age ie per entry. Using vendor specific. */
1973 	/* Assuming this is the last IE, copy at the end */
1974 	qie_age = (qcom_ie_age *) (mgmt_frame +
1975 		   util_scan_entry_frame_len(scan_params));
1976 	qie_age->element_id = QCOM_VENDOR_IE_ID;
1977 	qie_age->len = QCOM_VENDOR_IE_AGE_LEN;
1978 	qie_age->oui_1 = QCOM_OUI1;
1979 	qie_age->oui_2 = QCOM_OUI2;
1980 	qie_age->oui_3 = QCOM_OUI3;
1981 	qie_age->type = QCOM_VENDOR_IE_AGE_TYPE;
1982 	/*
1983 	 * Lowi expects the timestamp of bss in units of 1/10 ms. In driver
1984 	 * all bss related timestamp is in units of ms. Due to this when scan
1985 	 * results are sent to lowi the scan age is high.To address this,
1986 	 * send age in units of 1/10 ms.
1987 	 */
1988 	qie_age->age =
1989 		(uint32_t)(qdf_mc_timer_get_system_time() -
1990 		  scan_params->scan_entry_time)/10;
1991 	qie_age->tsf_delta = scan_params->tsf_delta;
1992 	memcpy(&qie_age->beacon_tsf, scan_params->tsf_info.data,
1993 		  sizeof(qie_age->beacon_tsf));
1994 	memcpy(&qie_age->seq_ctrl, &scan_params->seq_num,
1995 	       sizeof(qie_age->seq_ctrl));
1996 }
1997 #else
1998 static inline int wlan_get_frame_len(struct scan_cache_entry *scan_params)
1999 {
2000 	return util_scan_entry_frame_len(scan_params);
2001 }
2002 
2003 static inline void wlan_add_age_ie(uint8_t *mgmt_frame,
2004 	struct scan_cache_entry *scan_params)
2005 {
2006 }
2007 #endif /* WLAN_ENABLE_AGEIE_ON_SCAN_RESULTS */
2008 
2009 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0)) || \
2010 	defined(CFG80211_INFORM_BSS_FRAME_DATA)
2011 /**
2012  * wlan_fill_per_chain_rssi() - fill per chain RSSI in inform bss
2013  * @data: destination bss data
2014  * @bss: source bss data containing per chain RSSI
2015  *
2016  * Return: void
2017  */
2018 #if defined(CFG80211_SCAN_PER_CHAIN_RSSI_SUPPORT) || \
2019 	   (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0))
2020 static void wlan_fill_per_chain_rssi(struct cfg80211_inform_bss *data,
2021 	struct wlan_cfg80211_inform_bss *bss)
2022 {
2023 
2024 	uint32_t i;
2025 
2026 	if (!bss || !data) {
2027 		osif_err("Received bss is NULL");
2028 		return;
2029 	}
2030 	for (i = 0; i < WLAN_MGMT_TXRX_HOST_MAX_ANTENNA; i++) {
2031 		if (!bss->per_chain_rssi[i] ||
2032 		    (bss->per_chain_rssi[i] == WLAN_INVALID_PER_CHAIN_RSSI))
2033 			continue;
2034 		data->chain_signal[i] = bss->per_chain_rssi[i];
2035 		data->chains |= BIT(i);
2036 	}
2037 }
2038 #else
2039 static inline void
2040 wlan_fill_per_chain_rssi(struct cfg80211_inform_bss *data,
2041 	struct wlan_cfg80211_inform_bss *bss)
2042 {
2043 }
2044 #endif
2045 
2046 struct cfg80211_bss *
2047 wlan_cfg80211_inform_bss_frame_data(struct wiphy *wiphy,
2048 		struct wlan_cfg80211_inform_bss *bss)
2049 {
2050 	struct cfg80211_inform_bss data  = {0};
2051 
2052 	if (!bss) {
2053 		osif_err("bss is null");
2054 		return NULL;
2055 	}
2056 	wlan_fill_per_chain_rssi(&data, bss);
2057 
2058 	data.chan = bss->chan;
2059 	data.boottime_ns = bss->boottime_ns;
2060 	data.signal = bss->rssi;
2061 	return cfg80211_inform_bss_frame_data(wiphy, &data, bss->mgmt,
2062 					      bss->frame_len, GFP_ATOMIC);
2063 }
2064 #else
2065 struct cfg80211_bss *
2066 wlan_cfg80211_inform_bss_frame_data(struct wiphy *wiphy,
2067 		struct wlan_cfg80211_inform_bss *bss)
2068 
2069 {
2070 	return cfg80211_inform_bss_frame(wiphy, bss->chan, bss->mgmt,
2071 					 bss->frame_len,
2072 					 bss->rssi, GFP_ATOMIC);
2073 }
2074 #endif
2075 
2076 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0))
2077 static inline void wlan_cfg80211_put_bss(struct wiphy *wiphy,
2078 		struct cfg80211_bss *bss)
2079 {
2080 	cfg80211_put_bss(wiphy, bss);
2081 }
2082 #else
2083 static inline void wlan_cfg80211_put_bss(struct wiphy *wiphy,
2084 		struct cfg80211_bss *bss)
2085 {
2086 	cfg80211_put_bss(bss);
2087 }
2088 #endif
2089 
2090 void wlan_cfg80211_inform_bss_frame(struct wlan_objmgr_pdev *pdev,
2091 		struct scan_cache_entry *scan_params)
2092 {
2093 	struct pdev_osif_priv *pdev_ospriv = wlan_pdev_get_ospriv(pdev);
2094 	struct wiphy *wiphy;
2095 	struct cfg80211_bss *bss = NULL;
2096 	struct wlan_cfg80211_inform_bss bss_data = {0};
2097 
2098 	if (!pdev_ospriv) {
2099 		osif_err("os_priv is NULL");
2100 		return;
2101 	}
2102 
2103 	wiphy = pdev_ospriv->wiphy;
2104 
2105 	bss_data.frame_len = wlan_get_frame_len(scan_params);
2106 	bss_data.mgmt = qdf_mem_malloc_atomic(bss_data.frame_len);
2107 	if (!bss_data.mgmt) {
2108 		osif_err("bss mem alloc failed for seq %d",
2109 			 scan_params->seq_num);
2110 		return;
2111 	}
2112 	qdf_mem_copy(bss_data.mgmt,
2113 		 util_scan_entry_frame_ptr(scan_params),
2114 		 util_scan_entry_frame_len(scan_params));
2115 	/*
2116 	 * Android does not want the timestamp from the frame.
2117 	 * Instead it wants a monotonic increasing value
2118 	 */
2119 	bss_data.mgmt->u.probe_resp.timestamp = qdf_get_monotonic_boottime();
2120 	wlan_add_age_ie((uint8_t *)bss_data.mgmt, scan_params);
2121 	/*
2122 	 * Based on .ini configuration, raw rssi can be reported for bss.
2123 	 * Raw rssi is typically used for estimating power.
2124 	 */
2125 	bss_data.rssi = scan_params->rssi_raw;
2126 
2127 	bss_data.chan = wlan_get_ieee80211_channel(wiphy, pdev,
2128 		scan_params->channel.chan_freq);
2129 	if (!bss_data.chan) {
2130 		osif_err_rl("Channel not found for bss " QDF_MAC_ADDR_FMT " seq %d chan_freq %d",
2131 			    QDF_MAC_ADDR_REF(bss_data.mgmt->bssid),
2132 			    scan_params->seq_num,
2133 			    scan_params->channel.chan_freq);
2134 		qdf_mem_free(bss_data.mgmt);
2135 		return;
2136 	}
2137 
2138 	/*
2139 	 * Supplicant takes the signal strength in terms of
2140 	 * mBm (1 dBm = 100 mBm).
2141 	 */
2142 	bss_data.rssi = QDF_MIN(bss_data.rssi, 0) * 100;
2143 
2144 	bss_data.boottime_ns = scan_params->boottime_ns;
2145 
2146 	qdf_mem_copy(bss_data.per_chain_rssi, scan_params->per_chain_rssi,
2147 		     WLAN_MGMT_TXRX_HOST_MAX_ANTENNA);
2148 
2149 	bss = wlan_cfg80211_inform_bss_frame_data(wiphy, &bss_data);
2150 	if (!bss)
2151 		osif_err("failed to inform bss "QDF_MAC_ADDR_FMT" seq %d",
2152 			 QDF_MAC_ADDR_REF(bss_data.mgmt->bssid),
2153 			 scan_params->seq_num);
2154 	else
2155 		wlan_cfg80211_put_bss(wiphy, bss);
2156 
2157 	qdf_mem_free(bss_data.mgmt);
2158 }
2159 
2160 #if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) && \
2161 	!defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
2162 struct cfg80211_bss *wlan_cfg80211_get_bss(struct wiphy *wiphy,
2163 					   struct ieee80211_channel *channel,
2164 					   const u8 *bssid, const u8 *ssid,
2165 					   size_t ssid_len)
2166 {
2167 	return cfg80211_get_bss(wiphy, channel, bssid,
2168 				ssid, ssid_len,
2169 				WLAN_CAPABILITY_ESS,
2170 				WLAN_CAPABILITY_ESS);
2171 }
2172 #else
2173 struct cfg80211_bss *wlan_cfg80211_get_bss(struct wiphy *wiphy,
2174 					   struct ieee80211_channel *channel,
2175 					   const u8 *bssid, const u8 *ssid,
2176 					   size_t ssid_len)
2177 {
2178 	return cfg80211_get_bss(wiphy, channel, bssid,
2179 				ssid, ssid_len,
2180 				IEEE80211_BSS_TYPE_ESS,
2181 				IEEE80211_PRIVACY_ANY);
2182 }
2183 #endif
2184 
2185 QDF_STATUS  __wlan_cfg80211_unlink_bss_list(struct wiphy *wiphy,
2186 					    struct wlan_objmgr_pdev *pdev,
2187 					    uint8_t *bssid, uint8_t *ssid,
2188 					    uint8_t ssid_len)
2189 {
2190 	struct cfg80211_bss *bss = NULL;
2191 	uint8_t vdev_id;
2192 
2193 	if (bssid && wlan_get_connected_vdev_by_bssid(pdev, bssid, &vdev_id)) {
2194 		osif_debug("BSS "QDF_MAC_ADDR_FMT" connected on vdev %d dont unlink",
2195 			   QDF_MAC_ADDR_REF(bssid), vdev_id);
2196 		return QDF_STATUS_E_FAILURE;
2197 	}
2198 
2199 	bss = wlan_cfg80211_get_bss(wiphy, NULL, bssid,
2200 				    ssid, ssid_len);
2201 	if (!bss) {
2202 		osif_info("BSS "QDF_MAC_ADDR_FMT" not found",
2203 			  QDF_MAC_ADDR_REF(bssid));
2204 	} else {
2205 		osif_debug("unlink entry for ssid:" QDF_SSID_FMT " and BSSID " QDF_MAC_ADDR_FMT,
2206 			   QDF_SSID_REF(ssid_len, ssid),
2207 			   QDF_MAC_ADDR_REF(bssid));
2208 		cfg80211_unlink_bss(wiphy, bss);
2209 		wlan_cfg80211_put_bss(wiphy, bss);
2210 	}
2211 
2212 	/*
2213 	 * Kernel creates separate entries into it's bss list for probe resp
2214 	 * and beacon for hidden AP. Both have separate ref count and thus
2215 	 * deleting one will not delete other entry.
2216 	 * If beacon entry of the hidden AP is not deleted and AP switch to
2217 	 * broadcasting SSID from Hiding SSID, kernel will reject the beacon
2218 	 * entry. So unlink the hidden beacon entry (if present) as well from
2219 	 * kernel, to avoid such issue.
2220 	 */
2221 	bss = wlan_cfg80211_get_bss(wiphy, NULL, bssid, NULL, 0);
2222 	if (!bss) {
2223 		osif_debug("Hidden bss not found for ssid:" QDF_SSID_FMT " BSSID: " QDF_MAC_ADDR_FMT " sid_len %d",
2224 			   QDF_SSID_REF(ssid_len, ssid),
2225 			   QDF_MAC_ADDR_REF(bssid), ssid_len);
2226 	} else {
2227 		osif_debug("unlink entry for Hidden ssid:" QDF_SSID_FMT " and BSSID " QDF_MAC_ADDR_FMT,
2228 			   QDF_SSID_REF(ssid_len, ssid),
2229 			   QDF_MAC_ADDR_REF(bssid));
2230 
2231 		cfg80211_unlink_bss(wiphy, bss);
2232 		/* cfg80211_get_bss get bss with ref count so release it */
2233 		wlan_cfg80211_put_bss(wiphy, bss);
2234 	}
2235 
2236 	return QDF_STATUS_SUCCESS;
2237 }
2238 void wlan_cfg80211_unlink_bss_list(struct wlan_objmgr_pdev *pdev,
2239 				   struct scan_cache_entry *scan_entry)
2240 {
2241 	struct pdev_osif_priv *pdev_ospriv = wlan_pdev_get_ospriv(pdev);
2242 	struct wiphy *wiphy;
2243 
2244 	if (!pdev_ospriv) {
2245 		osif_err("os_priv is NULL");
2246 		return;
2247 	}
2248 
2249 	wiphy = pdev_ospriv->wiphy;
2250 
2251 	__wlan_cfg80211_unlink_bss_list(wiphy, pdev, scan_entry->bssid.bytes,
2252 					scan_entry->ssid.ssid,
2253 					scan_entry->ssid.length);
2254 }
2255 
2256 #if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 12, 0))
2257 /*
2258  * wlan_scan_wiphy_set_max_sched_scans() - set maximum number of scheduled scans
2259  * to wiphy.
2260  * @wiphy: pointer to wiphy
2261  * @max_scans: max num scans to be configured
2262  *
2263  */
2264 static inline void
2265 wlan_scan_wiphy_set_max_sched_scans(struct wiphy *wiphy, uint8_t max_scans)
2266 {
2267 	if (max_scans == 0)
2268 		wiphy->flags &= ~WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
2269 	else
2270 		wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
2271 }
2272 #else
2273 static inline void
2274 wlan_scan_wiphy_set_max_sched_scans(struct wiphy *wiphy, uint8_t max_scans)
2275 {
2276 	wiphy->max_sched_scan_reqs = max_scans;
2277 }
2278 #endif /* KERNEL_VERSION(4, 12, 0) */
2279 
2280 #if defined(CFG80211_REPORT_BETTER_BSS_IN_SCHED_SCAN) || \
2281 	(LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0))
2282 void wlan_scan_cfg80211_add_connected_pno_support(struct wiphy *wiphy)
2283 {
2284 	wiphy_ext_feature_set(wiphy,
2285 			      NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI);
2286 }
2287 #endif
2288 
2289 #if ((LINUX_VERSION_CODE > KERNEL_VERSION(4, 4, 0)) || \
2290 		defined(CFG80211_MULTI_SCAN_PLAN_BACKPORT)) && \
2291 		defined(FEATURE_WLAN_SCAN_PNO)
2292 void wlan_config_sched_scan_plans_to_wiphy(struct wiphy *wiphy,
2293 					   struct wlan_objmgr_psoc *psoc)
2294 {
2295 	if (ucfg_scan_get_pno_scan_support(psoc)) {
2296 		wlan_scan_wiphy_set_max_sched_scans(wiphy, 1);
2297 		wiphy->max_sched_scan_ssids = SCAN_PNO_MAX_SUPP_NETWORKS;
2298 		wiphy->max_match_sets = SCAN_PNO_MAX_SUPP_NETWORKS;
2299 		wiphy->max_sched_scan_ie_len = SCAN_MAX_IE_LENGTH;
2300 		wiphy->max_sched_scan_plans = SCAN_PNO_MAX_PLAN_REQUEST;
2301 
2302 		wiphy->max_sched_scan_plan_interval =
2303 			ucfg_scan_get_max_sched_scan_plan_interval(psoc);
2304 
2305 		wiphy->max_sched_scan_plan_iterations =
2306 			ucfg_scan_get_max_sched_scan_plan_iterations(psoc);
2307 	}
2308 }
2309 #endif
2310