xref: /wlan-dirver/qca-wifi-host-cmn/os_if/linux/scan/src/wlan_cfg80211_scan.c (revision 1f55ed1a9f5050d8da228aa8dd3fff7c0242aa71)
1 /*
2  * Copyright (c) 2017-2019 The Linux Foundation. All rights reserved.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for
5  * any purpose with or without fee is hereby granted, provided that the
6  * above copyright notice and this permission notice appear in all
7  * copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16  * PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 /**
20  * DOC: defines driver functions interfacing with linux kernel
21  */
22 
23 #include <qdf_list.h>
24 #include <qdf_status.h>
25 #include <linux/wireless.h>
26 #include <linux/netdevice.h>
27 #include <net/cfg80211.h>
28 #include <wlan_scan_utils_api.h>
29 #include <wlan_cfg80211.h>
30 #include <wlan_cfg80211_scan.h>
31 #include <wlan_osif_priv.h>
32 #include <wlan_scan_public_structs.h>
33 #include <wlan_scan_ucfg_api.h>
34 #include <wlan_cfg80211_scan.h>
35 #include <qdf_mem.h>
36 #include <wlan_utility.h>
37 #ifdef WLAN_POLICY_MGR_ENABLE
38 #include <wlan_policy_mgr_api.h>
39 #endif
40 #include <wlan_reg_services_api.h>
41 
42 static const
43 struct nla_policy scan_policy[QCA_WLAN_VENDOR_ATTR_SCAN_MAX + 1] = {
44 	[QCA_WLAN_VENDOR_ATTR_SCAN_FLAGS] = {.type = NLA_U32},
45 	[QCA_WLAN_VENDOR_ATTR_SCAN_TX_NO_CCK_RATE] = {.type = NLA_FLAG},
46 	[QCA_WLAN_VENDOR_ATTR_SCAN_COOKIE] = {.type = NLA_U64},
47 };
48 
49 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0))
50 static uint32_t hdd_config_sched_scan_start_delay(
51 		struct cfg80211_sched_scan_request *request)
52 {
53 	return request->delay;
54 }
55 #else
56 static uint32_t hdd_config_sched_scan_start_delay(
57 		struct cfg80211_sched_scan_request *request)
58 {
59 	return 0;
60 }
61 #endif
62 
63 #if defined(CFG80211_SCAN_RANDOM_MAC_ADDR) || \
64 	(LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0))
65 /**
66  * wlan_fill_scan_rand_attrs() - Populate the scan randomization attrs
67  * @vdev: pointer to objmgr vdev
68  * @flags: cfg80211 scan flags
69  * @mac_addr: random mac addr from cfg80211
70  * @mac_addr_mask: mac addr mask from cfg80211
71  * @randomize: output variable to check scan randomization status
72  * @addr: output variable to hold random addr
73  * @mask: output variable to hold mac mask
74  *
75  * Return: None
76  */
77 static void wlan_fill_scan_rand_attrs(struct wlan_objmgr_vdev *vdev,
78 				      uint32_t flags,
79 				      uint8_t *mac_addr,
80 				      uint8_t *mac_addr_mask,
81 				      bool *randomize,
82 				      uint8_t *addr,
83 				      uint8_t *mask)
84 {
85 	*randomize = false;
86 	if (!(flags & NL80211_SCAN_FLAG_RANDOM_ADDR))
87 		return;
88 
89 	if (wlan_vdev_mlme_get_opmode(vdev) != QDF_STA_MODE)
90 		return;
91 
92 	if (wlan_vdev_is_connected(vdev))
93 		return;
94 
95 	*randomize = true;
96 	memcpy(addr, mac_addr, QDF_MAC_ADDR_SIZE);
97 	memcpy(mask, mac_addr_mask, QDF_MAC_ADDR_SIZE);
98 	cfg80211_debug("Random mac addr: %pM and Random mac mask: %pM",
99 		       addr, mask);
100 }
101 
102 /**
103  * wlan_scan_rand_attrs() - Wrapper function to fill scan random attrs
104  * @vdev: pointer to objmgr vdev
105  * @request: pointer to cfg80211 scan request
106  * @req: pointer to cmn module scan request
107  *
108  * This is a wrapper function which invokes wlan_fill_scan_rand_attrs()
109  * to fill random attributes of internal scan request with cfg80211_scan_request
110  *
111  * Return: None
112  */
113 static void wlan_scan_rand_attrs(struct wlan_objmgr_vdev *vdev,
114 				 struct cfg80211_scan_request *request,
115 				 struct scan_start_request *req)
116 {
117 	bool *randomize = &req->scan_req.scan_random.randomize;
118 	uint8_t *mac_addr = req->scan_req.scan_random.mac_addr;
119 	uint8_t *mac_mask = req->scan_req.scan_random.mac_mask;
120 
121 	wlan_fill_scan_rand_attrs(vdev, request->flags, request->mac_addr,
122 				  request->mac_addr_mask, randomize, mac_addr,
123 				  mac_mask);
124 	if (!*randomize)
125 		return;
126 
127 	req->scan_req.scan_f_add_spoofed_mac_in_probe = true;
128 	req->scan_req.scan_f_add_rand_seq_in_probe = true;
129 }
130 #else
131 /**
132  * wlan_scan_rand_attrs() - Wrapper function to fill scan random attrs
133  * @vdev: pointer to objmgr vdev
134  * @request: pointer to cfg80211 scan request
135  * @req: pointer to cmn module scan request
136  *
137  * This is a wrapper function which invokes wlan_fill_scan_rand_attrs()
138  * to fill random attributes of internal scan request with cfg80211_scan_request
139  *
140  * Return: None
141  */
142 static void wlan_scan_rand_attrs(struct wlan_objmgr_vdev *vdev,
143 				 struct cfg80211_scan_request *request,
144 				 struct scan_start_request *req)
145 {
146 }
147 #endif
148 
149 #ifdef FEATURE_WLAN_SCAN_PNO
150 #if ((LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0)) || \
151 	defined(CFG80211_MULTI_SCAN_PLAN_BACKPORT))
152 
153 /**
154  * wlan_config_sched_scan_plan() - configures the sched scan plans
155  *   from the framework.
156  * @pno_req: pointer to PNO scan request
157  * @request: pointer to scan request from framework
158  *
159  * Return: None
160  */
161 static void wlan_config_sched_scan_plan(struct pno_scan_req_params *pno_req,
162 	struct cfg80211_sched_scan_request *request)
163 {
164 	/*
165 	 * As of now max 2 scan plans were supported by firmware
166 	 * if number of scan plan supported by firmware increased below logic
167 	 * must change.
168 	 */
169 	if (request->n_scan_plans == SCAN_PNO_MAX_PLAN_REQUEST) {
170 		pno_req->fast_scan_period =
171 			request->scan_plans[0].interval * MSEC_PER_SEC;
172 		pno_req->fast_scan_max_cycles =
173 			request->scan_plans[0].iterations;
174 		pno_req->slow_scan_period =
175 			request->scan_plans[1].interval * MSEC_PER_SEC;
176 	} else if (request->n_scan_plans == 1) {
177 		pno_req->fast_scan_period =
178 			request->scan_plans[0].interval * MSEC_PER_SEC;
179 		/*
180 		 * if only one scan plan is configured from framework
181 		 * then both fast and slow scan should be configured with the
182 		 * same value that is why fast scan cycles are hardcoded to one
183 		 */
184 		pno_req->fast_scan_max_cycles = 1;
185 		pno_req->slow_scan_period =
186 			request->scan_plans[0].interval * MSEC_PER_SEC;
187 	} else {
188 		cfg80211_err("Invalid number of scan plans %d !!",
189 			request->n_scan_plans);
190 	}
191 }
192 #else
193 static void wlan_config_sched_scan_plan(struct pno_scan_req_params *pno_req,
194 	struct cfg80211_sched_scan_request *request)
195 {
196 	pno_req->fast_scan_period = request->interval;
197 	pno_req->fast_scan_max_cycles = SCAN_PNO_DEF_SCAN_TIMER_REPEAT;
198 	pno_req->slow_scan_period =
199 		SCAN_PNO_DEF_SLOW_SCAN_MULTIPLIER *
200 		pno_req->fast_scan_period;
201 }
202 #endif
203 
204 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 12, 0)
205 static inline void
206 wlan_cfg80211_sched_scan_results(struct wiphy *wiphy, uint64_t reqid)
207 {
208 	cfg80211_sched_scan_results(wiphy);
209 }
210 #else
211 static inline void
212 wlan_cfg80211_sched_scan_results(struct wiphy *wiphy, uint64_t reqid)
213 {
214 	cfg80211_sched_scan_results(wiphy, reqid);
215 }
216 #endif
217 
218 /**
219  * wlan_cfg80211_pno_callback() - pno callback function to handle
220  * pno events.
221  * @vdev: vdev ptr
222  * @event: scan events
223  * @args: argument
224  *
225  * Return: void
226  */
227 static void wlan_cfg80211_pno_callback(struct wlan_objmgr_vdev *vdev,
228 	struct scan_event *event,
229 	void *args)
230 {
231 	struct wlan_objmgr_pdev *pdev;
232 	struct pdev_osif_priv *pdev_ospriv;
233 
234 	if (event->type != SCAN_EVENT_TYPE_NLO_COMPLETE)
235 		return;
236 
237 	cfg80211_debug("vdev id = %d", event->vdev_id);
238 
239 	pdev = wlan_vdev_get_pdev(vdev);
240 	if (!pdev) {
241 		cfg80211_err("pdev is NULL");
242 		return;
243 	}
244 
245 	pdev_ospriv = wlan_pdev_get_ospriv(pdev);
246 	if (!pdev_ospriv) {
247 		cfg80211_err("pdev_ospriv is NULL");
248 		return;
249 	}
250 	wlan_cfg80211_sched_scan_results(pdev_ospriv->wiphy, 0);
251 }
252 
253 #ifdef WLAN_POLICY_MGR_ENABLE
254 static bool wlan_cfg80211_is_ap_go_present(struct wlan_objmgr_psoc *psoc)
255 {
256 	return policy_mgr_mode_specific_connection_count(psoc,
257 							  PM_SAP_MODE,
258 							  NULL) ||
259 		policy_mgr_mode_specific_connection_count(psoc,
260 							  PM_P2P_GO_MODE,
261 							  NULL);
262 }
263 
264 static QDF_STATUS wlan_cfg80211_is_chan_ok_for_dnbs(
265 			struct wlan_objmgr_psoc *psoc,
266 			u8 channel, bool *ok)
267 {
268 	QDF_STATUS status = policy_mgr_is_chan_ok_for_dnbs(psoc, channel, ok);
269 
270 	if (QDF_IS_STATUS_ERROR(status)) {
271 		cfg80211_err("DNBS check failed");
272 		return status;
273 	}
274 
275 	return QDF_STATUS_SUCCESS;
276 }
277 #else
278 static bool wlan_cfg80211_is_ap_go_present(struct wlan_objmgr_psoc *psoc)
279 {
280 	return false;
281 }
282 
283 static QDF_STATUS wlan_cfg80211_is_chan_ok_for_dnbs(
284 			struct wlan_objmgr_psoc *psoc,
285 			u8 channel,
286 			bool *ok)
287 {
288 	if (!ok)
289 		return QDF_STATUS_E_INVAL;
290 
291 	*ok = true;
292 	return QDF_STATUS_SUCCESS;
293 }
294 #endif
295 
296 #if defined(CFG80211_SCAN_RANDOM_MAC_ADDR) || \
297 	(LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0))
298 /**
299  * wlan_pno_scan_rand_attr() - Wrapper function to fill sched scan random attrs
300  * @vdev: pointer to objmgr vdev
301  * @request: pointer to cfg80211 sched scan request
302  * @req: pointer to cmn module pno scan request
303  *
304  * This is a wrapper function which invokes wlan_fill_scan_rand_attrs()
305  * to fill random attributes of internal pno scan
306  * with cfg80211_sched_scan_request
307  *
308  * Return: None
309  */
310 static void wlan_pno_scan_rand_attr(struct wlan_objmgr_vdev *vdev,
311 				    struct cfg80211_sched_scan_request *request,
312 				    struct pno_scan_req_params *req)
313 {
314 	bool *randomize = &req->scan_random.randomize;
315 	uint8_t *mac_addr = req->scan_random.mac_addr;
316 	uint8_t *mac_mask = req->scan_random.mac_mask;
317 
318 	wlan_fill_scan_rand_attrs(vdev, request->flags, request->mac_addr,
319 				  request->mac_addr_mask, randomize, mac_addr,
320 				  mac_mask);
321 }
322 #else
323 /**
324  * wlan_pno_scan_rand_attr() - Wrapper function to fill sched scan random attrs
325  * @vdev: pointer to objmgr vdev
326  * @request: pointer to cfg80211 sched scan request
327  * @req: pointer to cmn module pno scan request
328  *
329  * This is a wrapper function which invokes wlan_fill_scan_rand_attrs()
330  * to fill random attributes of internal pno scan
331  * with cfg80211_sched_scan_request
332  *
333  * Return: None
334  */
335 static void wlan_pno_scan_rand_attr(struct wlan_objmgr_vdev *vdev,
336 				    struct cfg80211_sched_scan_request *request,
337 				    struct pno_scan_req_params *req)
338 {
339 }
340 #endif
341 
342 /**
343  * wlan_hdd_sched_scan_update_relative_rssi() - update CPNO params
344  * @pno_request: pointer to PNO scan request
345  * @request: Pointer to cfg80211 scheduled scan start request
346  *
347  * This function is used to update Connected PNO params sent by kernel
348  *
349  * Return: None
350  */
351 #if defined(CFG80211_REPORT_BETTER_BSS_IN_SCHED_SCAN) || \
352 	(LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0))
353 static inline void wlan_hdd_sched_scan_update_relative_rssi(
354 			struct pno_scan_req_params *pno_request,
355 			struct cfg80211_sched_scan_request *request)
356 {
357 	pno_request->relative_rssi_set = request->relative_rssi_set;
358 	pno_request->relative_rssi = request->relative_rssi;
359 	if (NL80211_BAND_2GHZ == request->rssi_adjust.band)
360 		pno_request->band_rssi_pref.band = WLAN_BAND_2_4_GHZ;
361 	else if (NL80211_BAND_5GHZ == request->rssi_adjust.band)
362 		pno_request->band_rssi_pref.band = WLAN_BAND_5_GHZ;
363 	pno_request->band_rssi_pref.rssi = request->rssi_adjust.delta;
364 }
365 #else
366 static inline void wlan_hdd_sched_scan_update_relative_rssi(
367 			struct pno_scan_req_params *pno_request,
368 			struct cfg80211_sched_scan_request *request)
369 {
370 }
371 #endif
372 
373 int wlan_cfg80211_sched_scan_start(struct wlan_objmgr_vdev *vdev,
374 				   struct cfg80211_sched_scan_request *request,
375 				   uint8_t scan_backoff_multiplier)
376 {
377 	struct pno_scan_req_params *req;
378 	int i, j, ret = 0;
379 	QDF_STATUS status;
380 	uint8_t num_chan = 0, channel;
381 	struct wlan_objmgr_pdev *pdev = wlan_vdev_get_pdev(vdev);
382 	struct wlan_objmgr_psoc *psoc;
383 	uint32_t valid_ch[SCAN_PNO_MAX_NETW_CHANNELS_EX] = {0};
384 
385 	if (ucfg_scan_get_pno_in_progress(vdev)) {
386 		cfg80211_debug("pno is already in progress");
387 		return -EBUSY;
388 	}
389 
390 	if (ucfg_scan_get_pdev_status(pdev) !=
391 	   SCAN_NOT_IN_PROGRESS) {
392 		status = wlan_abort_scan(pdev,
393 				wlan_objmgr_pdev_get_pdev_id(pdev),
394 				INVAL_VDEV_ID, INVAL_SCAN_ID, true);
395 		if (QDF_IS_STATUS_ERROR(status)) {
396 			cfg80211_err("aborting the existing scan is unsuccessful");
397 			return -EBUSY;
398 		}
399 	}
400 
401 	req = qdf_mem_malloc(sizeof(*req));
402 	if (!req) {
403 		cfg80211_err("req malloc failed");
404 		return -ENOMEM;
405 	}
406 
407 	wlan_pdev_obj_lock(pdev);
408 	psoc = wlan_pdev_get_psoc(pdev);
409 	wlan_pdev_obj_unlock(pdev);
410 
411 	req->networks_cnt = request->n_match_sets;
412 	req->vdev_id = wlan_vdev_get_id(vdev);
413 
414 	if ((!req->networks_cnt) ||
415 	    (req->networks_cnt > SCAN_PNO_MAX_SUPP_NETWORKS)) {
416 		cfg80211_err("Network input is not correct %d",
417 			req->networks_cnt);
418 		ret = -EINVAL;
419 		goto error;
420 	}
421 
422 	if (request->n_channels > SCAN_PNO_MAX_NETW_CHANNELS_EX) {
423 		cfg80211_err("Incorrect number of channels %d",
424 			request->n_channels);
425 		ret = -EINVAL;
426 		goto error;
427 	}
428 
429 	if (request->n_channels) {
430 		char chl[(request->n_channels * 5) + 1];
431 		int len = 0;
432 		bool ap_or_go_present = wlan_cfg80211_is_ap_go_present(psoc);
433 
434 		for (i = 0; i < request->n_channels; i++) {
435 			channel = request->channels[i]->hw_value;
436 			if (wlan_reg_is_dsrc_chan(pdev, channel))
437 				continue;
438 
439 			if (ap_or_go_present) {
440 				bool ok;
441 
442 				status =
443 				wlan_cfg80211_is_chan_ok_for_dnbs(psoc,
444 								  channel,
445 								  &ok);
446 				if (QDF_IS_STATUS_ERROR(status)) {
447 					cfg80211_err("DNBS check failed");
448 					qdf_mem_free(req);
449 					ret = -EINVAL;
450 					goto error;
451 				}
452 				if (!ok)
453 					continue;
454 			}
455 			len += snprintf(chl + len, 5, "%d ", channel);
456 			valid_ch[num_chan++] = wlan_chan_to_freq(channel);
457 		}
458 		cfg80211_notice("No. of Scan Channels: %d", num_chan);
459 		cfg80211_notice("Channel-List: %s", chl);
460 		/* If all channels are DFS and dropped,
461 		 * then ignore the PNO request
462 		 */
463 		if (!num_chan) {
464 			cfg80211_notice("Channel list empty due to filtering of DSRC");
465 			ret = -EINVAL;
466 			goto error;
467 		}
468 	}
469 
470 	/* Filling per profile  params */
471 	for (i = 0; i < req->networks_cnt; i++) {
472 		req->networks_list[i].ssid.length =
473 			request->match_sets[i].ssid.ssid_len;
474 
475 		if ((!req->networks_list[i].ssid.length) ||
476 		    (req->networks_list[i].ssid.length > WLAN_SSID_MAX_LEN)) {
477 			cfg80211_err(" SSID Len %d is not correct for network %d",
478 				  req->networks_list[i].ssid.length, i);
479 			ret = -EINVAL;
480 			goto error;
481 		}
482 
483 		qdf_mem_copy(req->networks_list[i].ssid.ssid,
484 			request->match_sets[i].ssid.ssid,
485 			req->networks_list[i].ssid.length);
486 		req->networks_list[i].authentication = 0;   /*eAUTH_TYPE_ANY */
487 		req->networks_list[i].encryption = 0;       /*eED_ANY */
488 		req->networks_list[i].bc_new_type = 0;    /*eBCAST_UNKNOWN */
489 
490 		cfg80211_notice("Received ssid:%.*s",
491 			req->networks_list[i].ssid.length,
492 			req->networks_list[i].ssid.ssid);
493 
494 		/*Copying list of valid channel into request */
495 		qdf_mem_copy(req->networks_list[i].channels, valid_ch,
496 			num_chan * sizeof(uint32_t));
497 		req->networks_list[i].channel_cnt = num_chan;
498 		req->networks_list[i].rssi_thresh =
499 			request->match_sets[i].rssi_thold;
500 	}
501 
502 	/* set scan to passive if no SSIDs are specified in the request */
503 	if (0 == request->n_ssids)
504 		req->do_passive_scan = true;
505 	else
506 		req->do_passive_scan = false;
507 
508 	for (i = 0; i < request->n_ssids; i++) {
509 		j = 0;
510 		while (j < req->networks_cnt) {
511 			if ((req->networks_list[j].ssid.length ==
512 			     request->ssids[i].ssid_len) &&
513 			    (!qdf_mem_cmp(req->networks_list[j].ssid.ssid,
514 					 request->ssids[i].ssid,
515 					 req->networks_list[j].ssid.length))) {
516 				req->networks_list[j].bc_new_type =
517 					SSID_BC_TYPE_HIDDEN;
518 				break;
519 			}
520 			j++;
521 		}
522 	}
523 	cfg80211_notice("Number of hidden networks being Configured = %d",
524 		  request->n_ssids);
525 
526 	/*
527 	 * Before Kernel 4.4
528 	 *   Driver gets only one time interval which is hard coded in
529 	 *   supplicant for 10000ms.
530 	 *
531 	 * After Kernel 4.4
532 	 *   User can configure multiple scan_plans, each scan would have
533 	 *   separate scan cycle and interval. (interval is in unit of second.)
534 	 *   For our use case, we would only have supplicant set one scan_plan,
535 	 *   and firmware also support only one as well, so pick up the first
536 	 *   index.
537 	 *
538 	 *   Taking power consumption into account
539 	 *   firmware after gPNOScanTimerRepeatValue times fast_scan_period
540 	 *   switches slow_scan_period. This is less frequent scans and firmware
541 	 *   shall be in slow_scan_period mode until next PNO Start.
542 	 */
543 	wlan_config_sched_scan_plan(req, request);
544 	req->delay_start_time = hdd_config_sched_scan_start_delay(request);
545 	req->scan_backoff_multiplier = scan_backoff_multiplier;
546 	cfg80211_notice("Base scan interval: %d sec, scan cycles: %d, slow scan interval %d",
547 		req->fast_scan_period, req->fast_scan_max_cycles,
548 		req->slow_scan_period);
549 	wlan_hdd_sched_scan_update_relative_rssi(req, request);
550 
551 	psoc = wlan_pdev_get_psoc(pdev);
552 	ucfg_scan_register_pno_cb(psoc,
553 		wlan_cfg80211_pno_callback, NULL);
554 	ucfg_scan_get_pno_def_params(vdev, req);
555 
556 	if (req->scan_random.randomize)
557 		wlan_pno_scan_rand_attr(vdev, request, req);
558 
559 	if (ucfg_ie_whitelist_enabled(psoc, vdev))
560 		ucfg_copy_ie_whitelist_attrs(psoc, &req->ie_whitelist);
561 	status = ucfg_scan_pno_start(vdev, req);
562 	if (QDF_IS_STATUS_ERROR(status)) {
563 		cfg80211_err("Failed to enable PNO");
564 		ret = -EINVAL;
565 		goto error;
566 	}
567 
568 	cfg80211_info("PNO scan request offloaded");
569 
570 error:
571 	qdf_mem_free(req);
572 	return ret;
573 }
574 
575 int wlan_cfg80211_sched_scan_stop(struct wlan_objmgr_vdev *vdev)
576 {
577 	QDF_STATUS status;
578 
579 	status = ucfg_scan_pno_stop(vdev);
580 	if (QDF_IS_STATUS_ERROR(status))
581 		cfg80211_err("Failed to disabled PNO");
582 	else
583 		cfg80211_info("PNO scan disabled");
584 
585 	return 0;
586 }
587 #endif /*FEATURE_WLAN_SCAN_PNO */
588 
589 /**
590  * wlan_copy_bssid_scan_request() - API to copy the bssid to Scan request
591  * @scan_req: Pointer to scan_start_request
592  * @request: scan request from Supplicant
593  *
594  * This API copies the BSSID in scan request from Supplicant and copies it to
595  * the scan_start_request
596  *
597  * Return: None
598  */
599 #if defined(CFG80211_SCAN_BSSID) || \
600 	(LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
601 static inline void
602 wlan_copy_bssid_scan_request(struct scan_start_request *scan_req,
603 		struct cfg80211_scan_request *request)
604 {
605 	qdf_mem_copy(scan_req->scan_req.bssid_list[0].bytes,
606 				request->bssid, QDF_MAC_ADDR_SIZE);
607 }
608 #else
609 static inline void
610 wlan_copy_bssid_scan_request(struct scan_start_request *scan_req,
611 		struct cfg80211_scan_request *request)
612 {
613 
614 }
615 #endif
616 
617 /**
618  * wlan_scan_request_enqueue() - enqueue Scan Request
619  * @pdev: pointer to pdev object
620  * @req: Pointer to the scan request
621  * @source: source of the scan request
622  * @scan_id: scan identifier
623  *
624  * Enqueue scan request in the global  scan list.This list
625  * stores the active scan request information.
626  *
627  * Return: 0 on success, error number otherwise
628  */
629 static int wlan_scan_request_enqueue(struct wlan_objmgr_pdev *pdev,
630 			struct cfg80211_scan_request *req,
631 			uint8_t source, uint32_t scan_id)
632 {
633 	struct scan_req *scan_req;
634 	QDF_STATUS status;
635 	struct pdev_osif_priv *osif_ctx;
636 	struct osif_scan_pdev *osif_scan;
637 
638 	scan_req = qdf_mem_malloc(sizeof(*scan_req));
639 	if (NULL == scan_req) {
640 		cfg80211_alert("malloc failed for Scan req");
641 		return -ENOMEM;
642 	}
643 
644 	/* Get NL global context from objmgr*/
645 	osif_ctx = wlan_pdev_get_ospriv(pdev);
646 	osif_scan = osif_ctx->osif_scan;
647 	scan_req->scan_request = req;
648 	scan_req->source = source;
649 	scan_req->scan_id = scan_id;
650 	scan_req->dev = req->wdev->netdev;
651 
652 	qdf_mutex_acquire(&osif_scan->scan_req_q_lock);
653 	status = qdf_list_insert_back(&osif_scan->scan_req_q,
654 					&scan_req->node);
655 	qdf_mutex_release(&osif_scan->scan_req_q_lock);
656 	if (QDF_STATUS_SUCCESS != status) {
657 		cfg80211_err("Failed to enqueue Scan Req");
658 		qdf_mem_free(scan_req);
659 		return -EINVAL;
660 	}
661 
662 	return 0;
663 }
664 
665 /**
666  * wlan_scan_request_dequeue() - dequeue scan request
667  * @nl_ctx: Global HDD context
668  * @scan_id: scan id
669  * @req: scan request
670  * @dev: net device
671  * @source : returns source of the scan request
672  *
673  * Return: QDF_STATUS
674  */
675 static QDF_STATUS wlan_scan_request_dequeue(
676 	struct wlan_objmgr_pdev *pdev,
677 	uint32_t scan_id, struct cfg80211_scan_request **req,
678 	uint8_t *source, struct net_device **dev)
679 {
680 	QDF_STATUS status = QDF_STATUS_E_FAILURE;
681 	struct scan_req *scan_req;
682 	qdf_list_node_t *node = NULL, *next_node = NULL;
683 	struct pdev_osif_priv *osif_ctx;
684 	struct osif_scan_pdev *scan_priv;
685 
686 	cfg80211_debug("Dequeue Scan id: %d", scan_id);
687 
688 	if ((source == NULL) || (req == NULL)) {
689 		cfg80211_err("source or request is NULL");
690 		return QDF_STATUS_E_NULL_VALUE;
691 	}
692 
693 	/* Get NL global context from objmgr*/
694 	osif_ctx = wlan_pdev_get_ospriv(pdev);
695 	if (!osif_ctx) {
696 		cfg80211_err("Failed to retrieve osif context");
697 		return status;
698 	}
699 	scan_priv = osif_ctx->osif_scan;
700 
701 	if (qdf_list_empty(&scan_priv->scan_req_q)) {
702 		cfg80211_info("Scan List is empty");
703 		return QDF_STATUS_E_FAILURE;
704 	}
705 
706 	qdf_mutex_acquire(&scan_priv->scan_req_q_lock);
707 	if (QDF_STATUS_SUCCESS !=
708 		qdf_list_peek_front(&scan_priv->scan_req_q, &next_node)) {
709 		qdf_mutex_release(&scan_priv->scan_req_q_lock);
710 		cfg80211_err("Failed to remove Scan Req from queue");
711 		return QDF_STATUS_E_FAILURE;
712 	}
713 
714 	do {
715 		node = next_node;
716 		scan_req = qdf_container_of(node, struct scan_req,
717 					node);
718 		if (scan_req->scan_id == scan_id) {
719 			status = qdf_list_remove_node(&scan_priv->scan_req_q,
720 					node);
721 			if (status == QDF_STATUS_SUCCESS) {
722 				*req = scan_req->scan_request;
723 				*source = scan_req->source;
724 				*dev = scan_req->dev;
725 				qdf_mem_free(scan_req);
726 				qdf_mutex_release(&scan_priv->scan_req_q_lock);
727 				cfg80211_debug("removed Scan id: %d, req = %pK, pending scans %d",
728 					       scan_id, req,
729 					       qdf_list_size(&scan_priv->
730 							     scan_req_q));
731 				return QDF_STATUS_SUCCESS;
732 			} else {
733 				qdf_mutex_release(&scan_priv->scan_req_q_lock);
734 				cfg80211_err("Failed to remove node scan id %d, pending scans %d",
735 				      scan_id,
736 				      qdf_list_size(&scan_priv->scan_req_q));
737 				return status;
738 			}
739 		}
740 	} while (QDF_STATUS_SUCCESS ==
741 		qdf_list_peek_next(&scan_priv->scan_req_q, node, &next_node));
742 	qdf_mutex_release(&scan_priv->scan_req_q_lock);
743 	cfg80211_err("Failed to find scan id %d", scan_id);
744 
745 	return status;
746 }
747 
748 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
749 /**
750  * wlan_cfg80211_scan_done() - Scan completed callback to cfg80211
751  * @netdev: Net device
752  * @req : Scan request
753  * @aborted : true scan aborted false scan success
754  *
755  * This function notifies scan done to cfg80211
756  *
757  * Return: none
758  */
759 static void wlan_cfg80211_scan_done(struct net_device *netdev,
760 				    struct cfg80211_scan_request *req,
761 				    bool aborted)
762 {
763 	struct cfg80211_scan_info info = {
764 		.aborted = aborted
765 	};
766 
767 	if (netdev->flags & IFF_UP)
768 		cfg80211_scan_done(req, &info);
769 }
770 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
771 /**
772  * wlan_cfg80211_scan_done() - Scan completed callback to cfg80211
773  * @netdev: Net device
774  * @req : Scan request
775  * @aborted : true scan aborted false scan success
776  *
777  * This function notifies scan done to cfg80211
778  *
779  * Return: none
780  */
781 static void wlan_cfg80211_scan_done(struct net_device *netdev,
782 				    struct cfg80211_scan_request *req,
783 				    bool aborted)
784 {
785 	if (netdev->flags & IFF_UP)
786 		cfg80211_scan_done(req, aborted);
787 }
788 #endif
789 
790 /**
791  * wlan_vendor_scan_callback() - Scan completed callback event
792  *
793  * @req : Scan request
794  * @aborted : true scan aborted false scan success
795  *
796  * This function sends scan completed callback event to NL.
797  *
798  * Return: none
799  */
800 static void wlan_vendor_scan_callback(struct cfg80211_scan_request *req,
801 					bool aborted)
802 {
803 	struct sk_buff *skb;
804 	struct nlattr *attr;
805 	int i;
806 	uint8_t scan_status;
807 	uint64_t cookie;
808 
809 	skb = cfg80211_vendor_event_alloc(req->wdev->wiphy, req->wdev,
810 			SCAN_DONE_EVENT_BUF_SIZE + 4 + NLMSG_HDRLEN,
811 			QCA_NL80211_VENDOR_SUBCMD_SCAN_DONE_INDEX,
812 			GFP_ATOMIC);
813 
814 	if (!skb) {
815 		cfg80211_err("skb alloc failed");
816 		qdf_mem_free(req);
817 		return;
818 	}
819 
820 	cookie = (uintptr_t)req;
821 
822 	attr = nla_nest_start(skb, QCA_WLAN_VENDOR_ATTR_SCAN_SSIDS);
823 	if (!attr)
824 		goto nla_put_failure;
825 	for (i = 0; i < req->n_ssids; i++) {
826 		if (nla_put(skb, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
827 			goto nla_put_failure;
828 	}
829 	nla_nest_end(skb, attr);
830 
831 	attr = nla_nest_start(skb, QCA_WLAN_VENDOR_ATTR_SCAN_FREQUENCIES);
832 	if (!attr)
833 		goto nla_put_failure;
834 	for (i = 0; i < req->n_channels; i++) {
835 		if (nla_put_u32(skb, i, req->channels[i]->center_freq))
836 			goto nla_put_failure;
837 	}
838 	nla_nest_end(skb, attr);
839 
840 	if (req->ie &&
841 		nla_put(skb, QCA_WLAN_VENDOR_ATTR_SCAN_IE, req->ie_len,
842 			req->ie))
843 		goto nla_put_failure;
844 
845 	if (req->flags &&
846 		nla_put_u32(skb, QCA_WLAN_VENDOR_ATTR_SCAN_FLAGS, req->flags))
847 		goto nla_put_failure;
848 
849 	if (wlan_cfg80211_nla_put_u64(skb, QCA_WLAN_VENDOR_ATTR_SCAN_COOKIE,
850 					cookie))
851 		goto nla_put_failure;
852 
853 	scan_status = (aborted == true) ? VENDOR_SCAN_STATUS_ABORTED :
854 		VENDOR_SCAN_STATUS_NEW_RESULTS;
855 	if (nla_put_u8(skb, QCA_WLAN_VENDOR_ATTR_SCAN_STATUS, scan_status))
856 		goto nla_put_failure;
857 
858 	cfg80211_vendor_event(skb, GFP_ATOMIC);
859 	qdf_mem_free(req);
860 
861 	return;
862 
863 nla_put_failure:
864 	kfree_skb(skb);
865 	qdf_mem_free(req);
866 }
867 
868 
869 /**
870  * wlan_cfg80211_scan_done_callback() - scan done callback function called after
871  * scan is finished
872  * @vdev: vdev ptr
873  * @event: Scan event
874  * @args: Scan cb arg
875  *
876  * Return: void
877  */
878 static void wlan_cfg80211_scan_done_callback(
879 					struct wlan_objmgr_vdev *vdev,
880 					struct scan_event *event,
881 					void *args)
882 {
883 	struct cfg80211_scan_request *req = NULL;
884 	bool success = false;
885 	uint32_t scan_id = event->scan_id;
886 	uint8_t source = NL_SCAN;
887 	struct wlan_objmgr_pdev *pdev;
888 	struct pdev_osif_priv *osif_priv;
889 	struct net_device *netdev = NULL;
890 	QDF_STATUS status;
891 
892 	qdf_mtrace(QDF_MODULE_ID_SCAN, QDF_MODULE_ID_OS_IF, event->type,
893 		   event->vdev_id, event->scan_id);
894 
895 	if (!util_is_scan_completed(event, &success))
896 		return;
897 
898 	cfg80211_debug("scan ID = %d vdev id = %d, event type %s(%d) reason = %s(%d)",
899 		       scan_id, event->vdev_id,
900 		       util_scan_get_ev_type_name(event->type), event->type,
901 		       util_scan_get_ev_reason_name(event->reason),
902 		       event->reason);
903 
904 	pdev = wlan_vdev_get_pdev(vdev);
905 	status = wlan_scan_request_dequeue(
906 			pdev, scan_id, &req, &source, &netdev);
907 	if (QDF_IS_STATUS_ERROR(status)) {
908 		cfg80211_err("Dequeue of scan request failed ID: %d", scan_id);
909 		goto allow_suspend;
910 	}
911 
912 	if (!netdev) {
913 		cfg80211_err("net dev is NULL,Drop scan event Id: %d",
914 				 scan_id);
915 		goto allow_suspend;
916 	}
917 
918 	/* Make sure vdev is active */
919 	status = wlan_objmgr_vdev_try_get_ref(vdev, WLAN_OSIF_ID);
920 	if (QDF_IS_STATUS_ERROR(status)) {
921 		cfg80211_err("Failed to get vdev reference: scan Id: %d",
922 				 scan_id);
923 		goto allow_suspend;
924 	}
925 
926 	/*
927 	 * Scan can be triggred from NL or vendor scan
928 	 * - If scan is triggered from NL then cfg80211 scan done should be
929 	 * called to updated scan completion to NL.
930 	 * - If scan is triggred through vendor command then
931 	 * scan done event will be posted
932 	 */
933 	if (NL_SCAN == source)
934 		wlan_cfg80211_scan_done(netdev, req, !success);
935 	else
936 		wlan_vendor_scan_callback(req, !success);
937 
938 	wlan_objmgr_vdev_release_ref(vdev, WLAN_OSIF_ID);
939 allow_suspend:
940 	osif_priv = wlan_pdev_get_ospriv(pdev);
941 	if (qdf_list_empty(&osif_priv->osif_scan->scan_req_q))
942 		qdf_runtime_pm_allow_suspend(
943 			&osif_priv->osif_scan->runtime_pm_lock);
944 
945 }
946 
947 QDF_STATUS wlan_scan_runtime_pm_init(struct wlan_objmgr_pdev *pdev)
948 {
949 	struct pdev_osif_priv *osif_priv;
950 	struct osif_scan_pdev *scan_priv;
951 
952 	wlan_pdev_obj_lock(pdev);
953 	osif_priv = wlan_pdev_get_ospriv(pdev);
954 	wlan_pdev_obj_unlock(pdev);
955 
956 	scan_priv = osif_priv->osif_scan;
957 
958 	return qdf_runtime_lock_init(&scan_priv->runtime_pm_lock);
959 }
960 
961 void wlan_scan_runtime_pm_deinit(struct wlan_objmgr_pdev *pdev)
962 {
963 	struct pdev_osif_priv *osif_priv;
964 	struct osif_scan_pdev *scan_priv;
965 
966 	wlan_pdev_obj_lock(pdev);
967 	osif_priv = wlan_pdev_get_ospriv(pdev);
968 	wlan_pdev_obj_unlock(pdev);
969 
970 	scan_priv = osif_priv->osif_scan;
971 	qdf_runtime_lock_deinit(&scan_priv->runtime_pm_lock);
972 }
973 
974 QDF_STATUS wlan_cfg80211_scan_priv_init(struct wlan_objmgr_pdev *pdev)
975 {
976 	struct pdev_osif_priv *osif_priv;
977 	struct osif_scan_pdev *scan_priv;
978 	struct wlan_objmgr_psoc *psoc;
979 	wlan_scan_requester req_id;
980 
981 	psoc = wlan_pdev_get_psoc(pdev);
982 
983 	req_id = ucfg_scan_register_requester(psoc, "CFG",
984 		wlan_cfg80211_scan_done_callback, NULL);
985 
986 	osif_priv = wlan_pdev_get_ospriv(pdev);
987 	scan_priv = qdf_mem_malloc(sizeof(*scan_priv));
988 	if (!scan_priv) {
989 		cfg80211_err("failed to allocate memory");
990 		return QDF_STATUS_E_NOMEM;
991 	}
992 	/* Initialize the scan request queue */
993 	osif_priv->osif_scan = scan_priv;
994 	qdf_list_create(&scan_priv->scan_req_q, WLAN_MAX_SCAN_COUNT);
995 	qdf_mutex_create(&scan_priv->scan_req_q_lock);
996 	scan_priv->req_id = req_id;
997 
998 	return QDF_STATUS_SUCCESS;
999 }
1000 
1001 QDF_STATUS wlan_cfg80211_scan_priv_deinit(struct wlan_objmgr_pdev *pdev)
1002 {
1003 	struct pdev_osif_priv *osif_priv;
1004 	struct osif_scan_pdev *scan_priv;
1005 	struct wlan_objmgr_psoc *psoc;
1006 
1007 	psoc = wlan_pdev_get_psoc(pdev);
1008 	osif_priv = wlan_pdev_get_ospriv(pdev);
1009 
1010 	wlan_cfg80211_cleanup_scan_queue(pdev, NULL);
1011 	scan_priv = osif_priv->osif_scan;
1012 	ucfg_scan_unregister_requester(psoc, scan_priv->req_id);
1013 	qdf_list_destroy(&scan_priv->scan_req_q);
1014 	qdf_mutex_destroy(&scan_priv->scan_req_q_lock);
1015 	qdf_mem_free(scan_priv);
1016 	osif_priv->osif_scan = NULL;
1017 
1018 	return QDF_STATUS_SUCCESS;
1019 }
1020 
1021 /**
1022  * wlan_cfg80211_enqueue_for_cleanup() - Function to populate scan cleanup queue
1023  * @scan_cleanup_q: Scan cleanup queue to be populated
1024  * @scan_priv: Pointer to scan related data used by cfg80211 scan
1025  * @dev: Netdevice pointer
1026  *
1027  * The function synchrounously iterates through the global scan queue to
1028  * identify entries that have to be cleaned up, copies identified entries
1029  * to another queue(to send scan complete event to NL later) and removes the
1030  * entry from the global scan queue.
1031  *
1032  * Return: None
1033  */
1034 static void
1035 wlan_cfg80211_enqueue_for_cleanup(qdf_list_t *scan_cleanup_q,
1036 				  struct osif_scan_pdev *scan_priv,
1037 				  struct net_device *dev)
1038 {
1039 	struct scan_req *scan_req, *scan_cleanup;
1040 	qdf_list_node_t *node = NULL, *next_node = NULL;
1041 
1042 	qdf_mutex_acquire(&scan_priv->scan_req_q_lock);
1043 	if (QDF_STATUS_SUCCESS !=
1044 		qdf_list_peek_front(&scan_priv->scan_req_q,
1045 				    &node)) {
1046 		qdf_mutex_release(&scan_priv->scan_req_q_lock);
1047 		return;
1048 	}
1049 
1050 	while (node) {
1051 		/*
1052 		 * Keep track of the next node, to traverse through the list
1053 		 * in the event of the current node being deleted.
1054 		 */
1055 		qdf_list_peek_next(&scan_priv->scan_req_q,
1056 				   node, &next_node);
1057 		scan_req = qdf_container_of(node, struct scan_req, node);
1058 		if (!dev || (dev == scan_req->dev)) {
1059 			scan_cleanup = qdf_mem_malloc(sizeof(struct scan_req));
1060 			if (!scan_cleanup) {
1061 				qdf_mutex_release(&scan_priv->scan_req_q_lock);
1062 				cfg80211_err("Failed to allocate memory");
1063 				return;
1064 			}
1065 			scan_cleanup->scan_request = scan_req->scan_request;
1066 			scan_cleanup->scan_id = scan_req->scan_id;
1067 			scan_cleanup->source = scan_req->source;
1068 			scan_cleanup->dev = scan_req->dev;
1069 			qdf_list_insert_back(scan_cleanup_q,
1070 					     &scan_cleanup->node);
1071 			if (QDF_STATUS_SUCCESS !=
1072 				qdf_list_remove_node(&scan_priv->scan_req_q,
1073 						     node)) {
1074 				qdf_mutex_release(&scan_priv->scan_req_q_lock);
1075 				cfg80211_err("Failed to remove scan request");
1076 				return;
1077 			}
1078 			qdf_mem_free(scan_req);
1079 		}
1080 		node = next_node;
1081 		next_node = NULL;
1082 	}
1083 	qdf_mutex_release(&scan_priv->scan_req_q_lock);
1084 }
1085 
1086 void wlan_cfg80211_cleanup_scan_queue(struct wlan_objmgr_pdev *pdev,
1087 				      struct net_device *dev)
1088 {
1089 	struct scan_req *scan_req;
1090 	struct cfg80211_scan_request *req;
1091 	uint8_t source;
1092 	bool aborted = true;
1093 	struct pdev_osif_priv *osif_priv;
1094 	qdf_list_t scan_cleanup_q;
1095 	qdf_list_node_t *node = NULL;
1096 
1097 	if (!pdev) {
1098 		cfg80211_err("pdev is Null");
1099 		return;
1100 	}
1101 
1102 	osif_priv = wlan_pdev_get_ospriv(pdev);
1103 
1104 	/*
1105 	 * To avoid any race conditions, create a local list to copy all the
1106 	 * scan entries to be removed and then send scan complete for each of
1107 	 * the identified entries to NL.
1108 	 */
1109 	qdf_list_create(&scan_cleanup_q, WLAN_MAX_SCAN_COUNT);
1110 	wlan_cfg80211_enqueue_for_cleanup(&scan_cleanup_q,
1111 					  osif_priv->osif_scan, dev);
1112 
1113 	while (!qdf_list_empty(&scan_cleanup_q)) {
1114 		if (QDF_STATUS_SUCCESS != qdf_list_remove_front(&scan_cleanup_q,
1115 								&node)) {
1116 			cfg80211_err("Failed to remove scan request");
1117 			return;
1118 		}
1119 		scan_req = container_of(node, struct scan_req, node);
1120 		req = scan_req->scan_request;
1121 		source = scan_req->source;
1122 		if (NL_SCAN == source)
1123 			wlan_cfg80211_scan_done(scan_req->dev, req,
1124 						aborted);
1125 		else
1126 			wlan_vendor_scan_callback(req, aborted);
1127 
1128 		qdf_mem_free(scan_req);
1129 	}
1130 	qdf_list_destroy(&scan_cleanup_q);
1131 
1132 	return;
1133 }
1134 
1135 /**
1136  * wlan_cfg80211_update_scan_policy_type_flags() - Set scan flags according to
1137  * scan request
1138  * @scan_req: Pointer to csr scan req
1139  *
1140  * Return: None
1141  */
1142 #if defined(CFG80211_SCAN_DBS_CONTROL_SUPPORT) || \
1143 	   (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0))
1144 static void wlan_cfg80211_update_scan_policy_type_flags(
1145 	struct cfg80211_scan_request *req,
1146 	struct scan_req_params *scan_req)
1147 {
1148 	if (req->flags & NL80211_SCAN_FLAG_HIGH_ACCURACY)
1149 		scan_req->scan_policy_high_accuracy = true;
1150 	if (req->flags & NL80211_SCAN_FLAG_LOW_SPAN)
1151 		scan_req->scan_policy_low_span = true;
1152 	if (req->flags & NL80211_SCAN_FLAG_LOW_POWER)
1153 		scan_req->scan_policy_low_power = true;
1154 }
1155 #else
1156 static inline void wlan_cfg80211_update_scan_policy_type_flags(
1157 		struct cfg80211_scan_request *req,
1158 		struct scan_req_params *scan_req)
1159 {
1160 }
1161 #endif
1162 
1163 int wlan_cfg80211_scan(struct wlan_objmgr_vdev *vdev,
1164 		       struct cfg80211_scan_request *request,
1165 		       struct scan_params *params)
1166 {
1167 	struct scan_start_request *req;
1168 	struct wlan_ssid *pssid;
1169 	uint8_t i;
1170 	int ret = 0;
1171 	uint8_t num_chan = 0, channel;
1172 	uint32_t c_freq;
1173 	struct wlan_objmgr_pdev *pdev = wlan_vdev_get_pdev(vdev);
1174 	wlan_scan_requester req_id;
1175 	struct pdev_osif_priv *osif_priv;
1176 	struct wlan_objmgr_psoc *psoc;
1177 	wlan_scan_id scan_id;
1178 	bool is_p2p_scan = false;
1179 	enum wlan_band band;
1180 	struct net_device *netdev = NULL;
1181 	QDF_STATUS qdf_status;
1182 
1183 	psoc = wlan_pdev_get_psoc(pdev);
1184 	if (!psoc) {
1185 		cfg80211_err("Invalid psoc object");
1186 		return -EINVAL;
1187 	}
1188 	req = qdf_mem_malloc(sizeof(*req));
1189 	if (!req) {
1190 		cfg80211_err("Failed to allocate scan request memory");
1191 		return -EINVAL;
1192 	}
1193 	/* Initialize the scan global params */
1194 	ucfg_scan_init_default_params(vdev, req);
1195 
1196 	/* Get NL global context from objmgr*/
1197 	osif_priv = wlan_pdev_get_ospriv(pdev);
1198 	req_id = osif_priv->osif_scan->req_id;
1199 	scan_id = ucfg_scan_get_scan_id(psoc);
1200 	if (!scan_id) {
1201 		cfg80211_err("Invalid scan id");
1202 		qdf_mem_free(req);
1203 		return -EINVAL;
1204 	}
1205 	/* fill the scan request structure */
1206 	req->vdev = vdev;
1207 	req->scan_req.vdev_id = wlan_vdev_get_id(vdev);
1208 	req->scan_req.scan_id = scan_id;
1209 	req->scan_req.scan_req_id = req_id;
1210 
1211 	/* Update scan policy type flags according to cfg scan request */
1212 	wlan_cfg80211_update_scan_policy_type_flags(request,
1213 					     &req->scan_req);
1214 	/*
1215 	 * Even though supplicant doesn't provide any SSIDs, n_ssids is
1216 	 * set to 1.  Because of this, driver is assuming that this is not
1217 	 * wildcard scan and so is not aging out the scan results.
1218 	 */
1219 	if ((request->ssids) && (request->n_ssids == 1) &&
1220 	    ('\0' == request->ssids->ssid[0])) {
1221 		request->n_ssids = 0;
1222 	}
1223 
1224 	if ((request->ssids) && (0 < request->n_ssids)) {
1225 		int j;
1226 		req->scan_req.num_ssids = request->n_ssids;
1227 
1228 		if (req->scan_req.num_ssids > WLAN_SCAN_MAX_NUM_SSID) {
1229 			cfg80211_info("number of ssid received %d is greater than MAX %d so copy only MAX nuber of SSIDs",
1230 				      req->scan_req.num_ssids,
1231 				      WLAN_SCAN_MAX_NUM_SSID);
1232 			req->scan_req.num_ssids = WLAN_SCAN_MAX_NUM_SSID;
1233 		}
1234 		/* copy all the ssid's and their length */
1235 		for (j = 0; j < req->scan_req.num_ssids; j++)  {
1236 			pssid = &req->scan_req.ssid[j];
1237 			/* get the ssid length */
1238 			pssid->length = request->ssids[j].ssid_len;
1239 			if (pssid->length > WLAN_SSID_MAX_LEN)
1240 				pssid->length = WLAN_SSID_MAX_LEN;
1241 			qdf_mem_copy(pssid->ssid,
1242 				     &request->ssids[j].ssid[0],
1243 				     pssid->length);
1244 			cfg80211_info("SSID number %d: %.*s", j, pssid->length,
1245 				      pssid->ssid);
1246 		}
1247 	}
1248 	if (request->ssids ||
1249 	   (wlan_vdev_mlme_get_opmode(vdev) == QDF_P2P_GO_MODE))
1250 		req->scan_req.scan_f_passive = false;
1251 
1252 	if (params->half_rate)
1253 		req->scan_req.scan_f_half_rate = true;
1254 	else if (params->quarter_rate)
1255 		req->scan_req.scan_f_quarter_rate = true;
1256 
1257 	if (params->strict_pscan)
1258 		req->scan_req.scan_f_strict_passive_pch = true;
1259 
1260 	if ((request->n_ssids == 1) && request->ssids &&
1261 	   !qdf_mem_cmp(&request->ssids[0], "DIRECT-", 7))
1262 		is_p2p_scan = true;
1263 
1264 	if (is_p2p_scan && request->no_cck)
1265 		req->scan_req.p2p_scan_type = SCAN_P2P_SEARCH;
1266 
1267 	/* Set dwell time mode according to scan policy type flags */
1268 	if (req->scan_req.scan_policy_high_accuracy)
1269 		req->scan_req.adaptive_dwell_time_mode =
1270 					SCAN_DWELL_MODE_STATIC;
1271 	if ((req->scan_req.scan_policy_low_power) ||
1272 	   (req->scan_req.scan_policy_low_span))
1273 		req->scan_req.adaptive_dwell_time_mode =
1274 					SCAN_DWELL_MODE_AGGRESSIVE;
1275 
1276 	/*
1277 	 * FW require at least 1 MAC to send probe request.
1278 	 * If MAC is all 0 set it to BC addr as this is the address on
1279 	 * which fw will send probe req.
1280 	 */
1281 	req->scan_req.num_bssid = 1;
1282 	wlan_copy_bssid_scan_request(req, request);
1283 	if (qdf_is_macaddr_zero(&req->scan_req.bssid_list[0]))
1284 		qdf_set_macaddr_broadcast(&req->scan_req.bssid_list[0]);
1285 
1286 	if (request->n_channels) {
1287 		char chl[(request->n_channels * 5) + 1];
1288 		int len = 0;
1289 #ifdef WLAN_POLICY_MGR_ENABLE
1290 		bool ap_or_go_present =
1291 			policy_mgr_mode_specific_connection_count(
1292 			     psoc, PM_SAP_MODE, NULL) ||
1293 			     policy_mgr_mode_specific_connection_count(
1294 			     psoc, PM_P2P_GO_MODE, NULL);
1295 #endif
1296 
1297 		for (i = 0; i < request->n_channels; i++) {
1298 			channel = request->channels[i]->hw_value;
1299 			c_freq = wlan_reg_chan_to_freq(pdev, channel);
1300 			if (wlan_reg_is_dsrc_chan(pdev, channel))
1301 				continue;
1302 #ifdef WLAN_POLICY_MGR_ENABLE
1303 			if (ap_or_go_present) {
1304 				bool ok;
1305 
1306 				qdf_status =
1307 					policy_mgr_is_chan_ok_for_dnbs(psoc,
1308 								       channel,
1309 								       &ok);
1310 
1311 				if (QDF_IS_STATUS_ERROR(qdf_status)) {
1312 					cfg80211_err("DNBS check failed");
1313 					qdf_mem_free(req);
1314 					ret = -EINVAL;
1315 					goto end;
1316 				}
1317 				if (!ok)
1318 					continue;
1319 			}
1320 #endif
1321 			len += snprintf(chl + len, 5, "%d ", channel);
1322 			req->scan_req.chan_list.chan[num_chan].freq = c_freq;
1323 			band = util_scan_scm_freq_to_band(c_freq);
1324 			if (band == WLAN_BAND_2_4_GHZ)
1325 				req->scan_req.chan_list.chan[num_chan].phymode =
1326 					SCAN_PHY_MODE_11G;
1327 			else
1328 				req->scan_req.chan_list.chan[num_chan].phymode =
1329 					SCAN_PHY_MODE_11A;
1330 			num_chan++;
1331 			if (num_chan >= WLAN_SCAN_MAX_NUM_CHANNELS)
1332 				break;
1333 		}
1334 		cfg80211_info("Channel-List: %s", chl);
1335 		cfg80211_info("No. of Scan Channels: %d", num_chan);
1336 	}
1337 	if (!num_chan) {
1338 		cfg80211_err("Received zero non-dsrc channels");
1339 		qdf_mem_free(req);
1340 		ret = -EINVAL;
1341 		goto end;
1342 	}
1343 	req->scan_req.chan_list.num_chan = num_chan;
1344 
1345 	/* P2P increase the scan priority */
1346 	if (is_p2p_scan)
1347 		req->scan_req.scan_priority = SCAN_PRIORITY_HIGH;
1348 	if (request->ie_len) {
1349 		req->scan_req.extraie.ptr = qdf_mem_malloc(request->ie_len);
1350 		if (!req->scan_req.extraie.ptr) {
1351 			cfg80211_err("Failed to allocate memory");
1352 			ret = -ENOMEM;
1353 			qdf_mem_free(req);
1354 			goto end;
1355 		}
1356 		req->scan_req.extraie.len = request->ie_len;
1357 		qdf_mem_copy(req->scan_req.extraie.ptr, request->ie,
1358 				request->ie_len);
1359 	} else if (params->default_ie.ptr && params->default_ie.len) {
1360 		req->scan_req.extraie.ptr =
1361 			qdf_mem_malloc(params->default_ie.len);
1362 		if (!req->scan_req.extraie.ptr) {
1363 			cfg80211_err("Failed to allocate memory");
1364 			ret = -ENOMEM;
1365 			qdf_mem_free(req);
1366 			goto end;
1367 		}
1368 		req->scan_req.extraie.len = params->default_ie.len;
1369 		qdf_mem_copy(req->scan_req.extraie.ptr, params->default_ie.ptr,
1370 			     params->default_ie.len);
1371 	}
1372 
1373 	if (!is_p2p_scan) {
1374 		if (req->scan_req.scan_random.randomize)
1375 			wlan_scan_rand_attrs(vdev, request, req);
1376 		if (ucfg_ie_whitelist_enabled(psoc, vdev) &&
1377 		    ucfg_copy_ie_whitelist_attrs(psoc,
1378 					&req->scan_req.ie_whitelist))
1379 			req->scan_req.scan_f_en_ie_whitelist_in_probe = true;
1380 	}
1381 
1382 	if (request->flags & NL80211_SCAN_FLAG_FLUSH)
1383 		ucfg_scan_flush_results(pdev, NULL);
1384 
1385 	/* Enqueue the scan request */
1386 	wlan_scan_request_enqueue(pdev, request, params->source,
1387 				  req->scan_req.scan_id);
1388 
1389 	qdf_runtime_pm_prevent_suspend(
1390 		&osif_priv->osif_scan->runtime_pm_lock);
1391 
1392 	qdf_status = ucfg_scan_start(req);
1393 	if (QDF_IS_STATUS_ERROR(qdf_status)) {
1394 		cfg80211_err("ucfg_scan_start returned error %d", qdf_status);
1395 		if (qdf_status == QDF_STATUS_E_RESOURCES)
1396 			cfg80211_err("HO is in progress.So defer the scan by informing busy");
1397 		wlan_scan_request_dequeue(pdev, scan_id, &request,
1398 					  &params->source, &netdev);
1399 		if (qdf_list_empty(&osif_priv->osif_scan->scan_req_q))
1400 			qdf_runtime_pm_allow_suspend(
1401 				&osif_priv->osif_scan->runtime_pm_lock);
1402 	}
1403 	ret = qdf_status_to_os_return(qdf_status);
1404 
1405 end:
1406 	return ret;
1407 }
1408 
1409 /**
1410  * wlan_get_scanid() - API to get the scan id
1411  * from the scan cookie attribute.
1412  * @pdev: Pointer to pdev object
1413  * @scan_id: Pointer to scan id
1414  * @cookie : Scan cookie attribute
1415  *
1416  * API to get the scan id from the scan cookie attribute
1417  * sent from supplicant by matching scan request.
1418  *
1419  * Return: 0 for success, non zero for failure
1420  */
1421 static int wlan_get_scanid(struct wlan_objmgr_pdev *pdev,
1422 			       uint32_t *scan_id, uint64_t cookie)
1423 {
1424 	struct scan_req *scan_req;
1425 	qdf_list_node_t *node = NULL;
1426 	qdf_list_node_t *ptr_node = NULL;
1427 	int ret = -EINVAL;
1428 	struct pdev_osif_priv *osif_ctx;
1429 	struct osif_scan_pdev *scan_priv;
1430 
1431 	/* Get NL global context from objmgr*/
1432 	osif_ctx = wlan_pdev_get_ospriv(pdev);
1433 	if (!osif_ctx) {
1434 		cfg80211_err("Failed to retrieve osif context");
1435 		return ret;
1436 	}
1437 	scan_priv = osif_ctx->osif_scan;
1438 	qdf_mutex_acquire(&scan_priv->scan_req_q_lock);
1439 	if (qdf_list_empty(&scan_priv->scan_req_q)) {
1440 		qdf_mutex_release(&scan_priv->scan_req_q_lock);
1441 		cfg80211_err("Failed to retrieve scan id");
1442 		return ret;
1443 	}
1444 
1445 	if (QDF_STATUS_SUCCESS !=
1446 			    qdf_list_peek_front(&scan_priv->scan_req_q,
1447 			    &ptr_node)) {
1448 		qdf_mutex_release(&scan_priv->scan_req_q_lock);
1449 		return ret;
1450 	}
1451 
1452 	do {
1453 		node = ptr_node;
1454 		scan_req = qdf_container_of(node, struct scan_req, node);
1455 		if (cookie ==
1456 		    (uintptr_t)(scan_req->scan_request)) {
1457 			*scan_id = scan_req->scan_id;
1458 			ret = 0;
1459 			break;
1460 		}
1461 	} while (QDF_STATUS_SUCCESS ==
1462 		 qdf_list_peek_next(&scan_priv->scan_req_q,
1463 		 node, &ptr_node));
1464 
1465 	qdf_mutex_release(&scan_priv->scan_req_q_lock);
1466 
1467 	return ret;
1468 }
1469 
1470 QDF_STATUS wlan_abort_scan(struct wlan_objmgr_pdev *pdev,
1471 				   uint32_t pdev_id, uint32_t vdev_id,
1472 				   wlan_scan_id scan_id, bool sync)
1473 {
1474 	struct scan_cancel_request *req;
1475 	struct pdev_osif_priv *osif_ctx;
1476 	struct osif_scan_pdev *scan_priv;
1477 	QDF_STATUS status;
1478 	struct wlan_objmgr_vdev *vdev;
1479 
1480 	req = qdf_mem_malloc(sizeof(*req));
1481 	if (!req) {
1482 		cfg80211_err("Failed to allocate memory");
1483 		return QDF_STATUS_E_NOMEM;
1484 	}
1485 
1486 	/* Get NL global context from objmgr*/
1487 	osif_ctx = wlan_pdev_get_ospriv(pdev);
1488 	if (!osif_ctx) {
1489 		cfg80211_err("Failed to retrieve osif context");
1490 		qdf_mem_free(req);
1491 		return QDF_STATUS_E_FAILURE;
1492 	}
1493 	if (vdev_id == INVAL_VDEV_ID)
1494 		vdev = wlan_objmgr_pdev_get_first_vdev(pdev, WLAN_OSIF_ID);
1495 	else
1496 		vdev = wlan_objmgr_get_vdev_by_id_from_pdev(pdev,
1497 				vdev_id, WLAN_OSIF_ID);
1498 
1499 	if (!vdev) {
1500 		cfg80211_err("Failed get vdev");
1501 		qdf_mem_free(req);
1502 		return QDF_STATUS_E_INVAL;
1503 	}
1504 	scan_priv = osif_ctx->osif_scan;
1505 	req->cancel_req.requester = scan_priv->req_id;
1506 	req->vdev = vdev;
1507 	req->cancel_req.scan_id = scan_id;
1508 	req->cancel_req.pdev_id = pdev_id;
1509 	req->cancel_req.vdev_id = vdev_id;
1510 	if (scan_id != INVAL_SCAN_ID)
1511 		req->cancel_req.req_type = WLAN_SCAN_CANCEL_SINGLE;
1512 	else if (vdev_id == INVAL_VDEV_ID)
1513 		req->cancel_req.req_type = WLAN_SCAN_CANCEL_PDEV_ALL;
1514 	else
1515 		req->cancel_req.req_type = WLAN_SCAN_CANCEL_VDEV_ALL;
1516 
1517 	if (sync)
1518 		status = ucfg_scan_cancel_sync(req);
1519 	else
1520 		status = ucfg_scan_cancel(req);
1521 	if (QDF_IS_STATUS_ERROR(status))
1522 		cfg80211_err("Cancel scan request failed");
1523 
1524 	wlan_objmgr_vdev_release_ref(vdev, WLAN_OSIF_ID);
1525 
1526 	return status;
1527 }
1528 
1529 int wlan_cfg80211_abort_scan(struct wlan_objmgr_pdev *pdev)
1530 {
1531 	uint8_t pdev_id;
1532 
1533 	pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
1534 
1535 	if (ucfg_scan_get_pdev_status(pdev) !=
1536 	   SCAN_NOT_IN_PROGRESS)
1537 		wlan_abort_scan(pdev, pdev_id,
1538 			INVAL_VDEV_ID, INVAL_SCAN_ID, true);
1539 
1540 	return 0;
1541 }
1542 
1543 int wlan_vendor_abort_scan(struct wlan_objmgr_pdev *pdev,
1544 			const void *data, int data_len)
1545 {
1546 	struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_SCAN_MAX + 1];
1547 	int ret = -EINVAL;
1548 	wlan_scan_id scan_id;
1549 	uint64_t cookie;
1550 	uint8_t pdev_id;
1551 
1552 	pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
1553 	if (wlan_cfg80211_nla_parse(tb, QCA_WLAN_VENDOR_ATTR_SCAN_MAX, data,
1554 				    data_len, scan_policy)) {
1555 		cfg80211_err("Invalid ATTR");
1556 		return ret;
1557 	}
1558 
1559 	if (tb[QCA_WLAN_VENDOR_ATTR_SCAN_COOKIE]) {
1560 		cookie = nla_get_u64(
1561 			    tb[QCA_WLAN_VENDOR_ATTR_SCAN_COOKIE]);
1562 		ret = wlan_get_scanid(pdev, &scan_id, cookie);
1563 		if (ret != 0)
1564 			return ret;
1565 		if (ucfg_scan_get_pdev_status(pdev) !=
1566 		   SCAN_NOT_IN_PROGRESS)
1567 			wlan_abort_scan(pdev, INVAL_PDEV_ID,
1568 					INVAL_VDEV_ID, scan_id, true);
1569 	}
1570 	return 0;
1571 }
1572 
1573 static inline struct ieee80211_channel *
1574 wlan_get_ieee80211_channel(struct wiphy *wiphy,
1575 		struct wlan_objmgr_pdev *pdev,
1576 		int chan_no)
1577 {
1578 	unsigned int freq;
1579 	struct ieee80211_channel *chan;
1580 
1581 	freq = wlan_reg_chan_to_freq(pdev, chan_no);
1582 	chan = ieee80211_get_channel(wiphy, freq);
1583 	if (!chan)
1584 		cfg80211_err("chan is NULL, chan_no: %d freq: %d",
1585 			chan_no, freq);
1586 
1587 	return chan;
1588 }
1589 
1590 #ifdef WLAN_ENABLE_AGEIE_ON_SCAN_RESULTS
1591 static inline int wlan_get_frame_len(struct scan_cache_entry *scan_params)
1592 {
1593 	return util_scan_entry_frame_len(scan_params) + sizeof(qcom_ie_age);
1594 }
1595 
1596 static inline void wlan_add_age_ie(uint8_t *mgmt_frame,
1597 	struct scan_cache_entry *scan_params)
1598 {
1599 	qcom_ie_age *qie_age = NULL;
1600 
1601 	/* GPS Requirement: need age ie per entry. Using vendor specific. */
1602 	/* Assuming this is the last IE, copy at the end */
1603 	qie_age = (qcom_ie_age *) (mgmt_frame +
1604 		   util_scan_entry_frame_len(scan_params));
1605 	qie_age->element_id = QCOM_VENDOR_IE_ID;
1606 	qie_age->len = QCOM_VENDOR_IE_AGE_LEN;
1607 	qie_age->oui_1 = QCOM_OUI1;
1608 	qie_age->oui_2 = QCOM_OUI2;
1609 	qie_age->oui_3 = QCOM_OUI3;
1610 	qie_age->type = QCOM_VENDOR_IE_AGE_TYPE;
1611 	/*
1612 	 * Lowi expects the timestamp of bss in units of 1/10 ms. In driver
1613 	 * all bss related timestamp is in units of ms. Due to this when scan
1614 	 * results are sent to lowi the scan age is high.To address this,
1615 	 * send age in units of 1/10 ms.
1616 	 */
1617 	qie_age->age =
1618 		(uint32_t)(qdf_mc_timer_get_system_time() -
1619 		  scan_params->scan_entry_time)/10;
1620 	qie_age->tsf_delta = scan_params->tsf_delta;
1621 	memcpy(&qie_age->beacon_tsf, scan_params->tsf_info.data,
1622 		  sizeof(qie_age->beacon_tsf));
1623 	memcpy(&qie_age->seq_ctrl, &scan_params->seq_num,
1624 	       sizeof(qie_age->seq_ctrl));
1625 }
1626 #else
1627 static inline int wlan_get_frame_len(struct scan_cache_entry *scan_params)
1628 {
1629 	return util_scan_entry_frame_len(scan_params);
1630 }
1631 
1632 static inline void wlan_add_age_ie(uint8_t *mgmt_frame,
1633 	struct scan_cache_entry *scan_params)
1634 {
1635 }
1636 #endif /* WLAN_ENABLE_AGEIE_ON_SCAN_RESULTS */
1637 
1638 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0)) || \
1639 	defined(CFG80211_INFORM_BSS_FRAME_DATA)
1640 /**
1641  * wlan_fill_per_chain_rssi() - fill per chain RSSI in inform bss
1642  * @data: bss data
1643  * @per_chain_snr: per chain RSSI
1644  *
1645  * Return: void
1646  */
1647 #if defined(CFG80211_SCAN_PER_CHAIN_RSSI_SUPPORT) || \
1648 	   (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0))
1649 static void wlan_fill_per_chain_rssi(struct cfg80211_inform_bss *data,
1650 	struct wlan_cfg80211_inform_bss *bss)
1651 {
1652 
1653 	uint32_t i;
1654 
1655 	if (!bss || !data) {
1656 		cfg80211_err("Received bss is NULL");
1657 		return;
1658 	}
1659 	for (i = 0; i < WLAN_MGMT_TXRX_HOST_MAX_ANTENNA; i++) {
1660 		if (!bss->per_chain_rssi[i] ||
1661 		    (bss->per_chain_rssi[i] == WLAN_INVALID_PER_CHAIN_RSSI))
1662 			continue;
1663 		data->chain_signal[i] = bss->per_chain_rssi[i];
1664 		data->chains |= BIT(i);
1665 	}
1666 }
1667 #else
1668 static inline void
1669 wlan_fill_per_chain_rssi(struct cfg80211_inform_bss *data,
1670 	struct wlan_cfg80211_inform_bss *bss)
1671 {
1672 }
1673 #endif
1674 
1675 struct cfg80211_bss *
1676 wlan_cfg80211_inform_bss_frame_data(struct wiphy *wiphy,
1677 		struct wlan_cfg80211_inform_bss *bss)
1678 {
1679 	struct cfg80211_inform_bss data  = {0};
1680 
1681 	if (!bss) {
1682 		cfg80211_err("bss is null");
1683 		return NULL;
1684 	}
1685 	wlan_fill_per_chain_rssi(&data, bss);
1686 
1687 	data.chan = bss->chan;
1688 	data.boottime_ns = bss->boottime_ns;
1689 	data.signal = bss->rssi;
1690 	return cfg80211_inform_bss_frame_data(wiphy, &data, bss->mgmt,
1691 					      bss->frame_len, GFP_ATOMIC);
1692 }
1693 #else
1694 struct cfg80211_bss *
1695 wlan_cfg80211_inform_bss_frame_data(struct wiphy *wiphy,
1696 		struct wlan_cfg80211_inform_bss *bss)
1697 
1698 {
1699 	return cfg80211_inform_bss_frame(wiphy, bss->chan, bss->mgmt,
1700 					 bss->frame_len,
1701 					 bss->rssi, GFP_ATOMIC);
1702 }
1703 #endif
1704 
1705 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0))
1706 static inline void wlan_cfg80211_put_bss(struct wiphy *wiphy,
1707 		struct cfg80211_bss *bss)
1708 {
1709 	cfg80211_put_bss(wiphy, bss);
1710 }
1711 #else
1712 static inline void wlan_cfg80211_put_bss(struct wiphy *wiphy,
1713 		struct cfg80211_bss *bss)
1714 {
1715 	cfg80211_put_bss(bss);
1716 }
1717 #endif
1718 
1719 void wlan_cfg80211_inform_bss_frame(struct wlan_objmgr_pdev *pdev,
1720 		struct scan_cache_entry *scan_params)
1721 {
1722 	struct pdev_osif_priv *pdev_ospriv = wlan_pdev_get_ospriv(pdev);
1723 	struct wiphy *wiphy;
1724 	struct cfg80211_bss *bss = NULL;
1725 	struct wlan_cfg80211_inform_bss bss_data = {0};
1726 
1727 	if (!pdev_ospriv) {
1728 		cfg80211_err("os_priv is NULL");
1729 		return;
1730 	}
1731 
1732 	wiphy = pdev_ospriv->wiphy;
1733 
1734 	bss_data.frame_len = wlan_get_frame_len(scan_params);
1735 	bss_data.mgmt = qdf_mem_malloc_atomic(bss_data.frame_len);
1736 	if (!bss_data.mgmt) {
1737 		cfg80211_err("mem alloc failed for bss %pM seq %d",
1738 			     bss_data.mgmt->bssid, scan_params->seq_num);
1739 		return;
1740 	}
1741 	qdf_mem_copy(bss_data.mgmt,
1742 		 util_scan_entry_frame_ptr(scan_params),
1743 		 util_scan_entry_frame_len(scan_params));
1744 	/*
1745 	 * Android does not want the timestamp from the frame.
1746 	 * Instead it wants a monotonic increasing value
1747 	 */
1748 	bss_data.mgmt->u.probe_resp.timestamp = qdf_get_monotonic_boottime();
1749 	wlan_add_age_ie((uint8_t *)bss_data.mgmt, scan_params);
1750 	/*
1751 	 * Based on .ini configuration, raw rssi can be reported for bss.
1752 	 * Raw rssi is typically used for estimating power.
1753 	 */
1754 	bss_data.rssi = scan_params->rssi_raw;
1755 
1756 	bss_data.chan = wlan_get_ieee80211_channel(wiphy, pdev,
1757 		scan_params->channel.chan_idx);
1758 	if (!bss_data.chan) {
1759 		cfg80211_err("Channel not found for bss %pM seq %d chan %d",
1760 			     bss_data.mgmt->bssid, scan_params->seq_num,
1761 			     scan_params->channel.chan_idx);
1762 		qdf_mem_free(bss_data.mgmt);
1763 		return;
1764 	}
1765 
1766 	/*
1767 	 * Supplicant takes the signal strength in terms of
1768 	 * mBm (1 dBm = 100 mBm).
1769 	 */
1770 	bss_data.rssi = QDF_MIN(bss_data.rssi, 0) * 100;
1771 
1772 	bss_data.boottime_ns = scan_params->boottime_ns;
1773 
1774 	qdf_mem_copy(bss_data.per_chain_rssi, scan_params->per_chain_rssi,
1775 		     WLAN_MGMT_TXRX_HOST_MAX_ANTENNA);
1776 
1777 	bss = wlan_cfg80211_inform_bss_frame_data(wiphy, &bss_data);
1778 	if (!bss)
1779 		cfg80211_err("failed to inform bss %pM seq %d",
1780 			     bss_data.mgmt->bssid, scan_params->seq_num);
1781 	else
1782 		wlan_cfg80211_put_bss(wiphy, bss);
1783 
1784 	qdf_mem_free(bss_data.mgmt);
1785 }
1786