xref: /wlan-dirver/qca-wifi-host-cmn/wmi/src/wmi_unified_extscan_tlv.c (revision 92d87f51612f6c3b2285266215edee8911647c2f)
1 /*
2  * Copyright (c) 2016-2018 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 #include <osdep.h>
20 #include "wmi.h"
21 #include "wmi_unified_priv.h"
22 
23 /**
24  * send_reset_passpoint_network_list_cmd_tlv() - reset passpoint network list
25  * @wmi_handle: wmi handle
26  * @req: passpoint network request structure
27  *
28  * This function sends down WMI command with network id set to wildcard id.
29  * firmware shall clear all the config entries
30  *
31  * Return: QDF_STATUS enumeration
32  */
33 static QDF_STATUS send_reset_passpoint_network_list_cmd_tlv
34 					(wmi_unified_t wmi_handle,
35 					struct wifi_passpoint_req_param *req)
36 {
37 	wmi_passpoint_config_cmd_fixed_param *cmd;
38 	wmi_buf_t buf;
39 	uint32_t len;
40 	int ret;
41 
42 	len = sizeof(*cmd);
43 	buf = wmi_buf_alloc(wmi_handle, len);
44 	if (!buf) {
45 		WMI_LOGE("%s: Failed allocate wmi buffer", __func__);
46 		return QDF_STATUS_E_NOMEM;
47 	}
48 
49 	cmd = (wmi_passpoint_config_cmd_fixed_param *) wmi_buf_data(buf);
50 
51 	WMITLV_SET_HDR(&cmd->tlv_header,
52 			WMITLV_TAG_STRUC_wmi_passpoint_config_cmd_fixed_param,
53 			WMITLV_GET_STRUCT_TLVLEN(
54 			wmi_passpoint_config_cmd_fixed_param));
55 	cmd->id = WMI_PASSPOINT_NETWORK_ID_WILDCARD;
56 
57 	ret = wmi_unified_cmd_send(wmi_handle, buf, len,
58 				   WMI_PASSPOINT_LIST_CONFIG_CMDID);
59 	if (ret) {
60 		WMI_LOGE("%s: Failed to send reset passpoint network list wmi cmd",
61 			 __func__);
62 		wmi_buf_free(buf);
63 		return QDF_STATUS_E_FAILURE;
64 	}
65 
66 	return QDF_STATUS_SUCCESS;
67 }
68 
69 /**
70  * send_set_passpoint_network_list_cmd_tlv() - set passpoint network list
71  * @wmi_handle: wmi handle
72  * @req: passpoint network request structure
73  *
74  * This function reads the incoming @req and fill in the destination
75  * WMI structure and send down the passpoint configs down to the firmware
76  *
77  * Return: QDF_STATUS enumeration
78  */
79 static QDF_STATUS send_set_passpoint_network_list_cmd_tlv
80 					(wmi_unified_t wmi_handle,
81 					struct wifi_passpoint_req_param *req)
82 {
83 	wmi_passpoint_config_cmd_fixed_param *cmd;
84 	u_int8_t i, j, *bytes;
85 	wmi_buf_t buf;
86 	uint32_t len;
87 	int ret;
88 
89 	len = sizeof(*cmd);
90 	for (i = 0; i < req->num_networks; i++) {
91 		buf = wmi_buf_alloc(wmi_handle, len);
92 		if (!buf) {
93 			WMI_LOGE("%s: Failed allocate wmi buffer", __func__);
94 			return QDF_STATUS_E_NOMEM;
95 		}
96 
97 		cmd = (wmi_passpoint_config_cmd_fixed_param *)
98 				wmi_buf_data(buf);
99 
100 		WMITLV_SET_HDR(&cmd->tlv_header,
101 			WMITLV_TAG_STRUC_wmi_passpoint_config_cmd_fixed_param,
102 			WMITLV_GET_STRUCT_TLVLEN(
103 			wmi_passpoint_config_cmd_fixed_param));
104 		cmd->id = req->networks[i].id;
105 		WMI_LOGD("%s: network id: %u", __func__, cmd->id);
106 		qdf_mem_copy(cmd->realm, req->networks[i].realm,
107 			strlen(req->networks[i].realm) + 1);
108 		WMI_LOGD("%s: realm: %s", __func__, cmd->realm);
109 		for (j = 0; j < PASSPOINT_ROAMING_CONSORTIUM_ID_NUM; j++) {
110 			bytes = (uint8_t *) &req->networks[i].roaming_consortium_ids[j];
111 			WMI_LOGD("index: %d rcids: %02x %02x %02x %02x %02x %02x %02x %02x",
112 				j, bytes[0], bytes[1], bytes[2], bytes[3],
113 				bytes[4], bytes[5], bytes[6], bytes[7]);
114 
115 			qdf_mem_copy(&cmd->roaming_consortium_ids[j],
116 				&req->networks[i].roaming_consortium_ids[j],
117 				PASSPOINT_ROAMING_CONSORTIUM_ID_LEN);
118 		}
119 		qdf_mem_copy(cmd->plmn, req->networks[i].plmn,
120 				PASSPOINT_PLMN_ID_LEN);
121 		WMI_LOGD("%s: plmn: %02x:%02x:%02x", __func__,
122 			cmd->plmn[0], cmd->plmn[1], cmd->plmn[2]);
123 
124 		ret = wmi_unified_cmd_send(wmi_handle, buf, len,
125 					   WMI_PASSPOINT_LIST_CONFIG_CMDID);
126 		if (ret) {
127 			WMI_LOGE("%s: Failed to send set passpoint network list wmi cmd",
128 				 __func__);
129 			wmi_buf_free(buf);
130 			return QDF_STATUS_E_FAILURE;
131 		}
132 	}
133 
134 	return QDF_STATUS_SUCCESS;
135 }
136 
137 /** send_set_epno_network_list_cmd_tlv() - set epno network list
138  * @wmi_handle: wmi handle
139  * @req: epno config params request structure
140  *
141  * This function reads the incoming epno config request structure
142  * and constructs the WMI message to the firmware.
143  *
144  * Returns: 0 on success, error number otherwise
145  */
146 static QDF_STATUS send_set_epno_network_list_cmd_tlv(wmi_unified_t wmi_handle,
147 		struct wifi_enhanched_pno_params *req)
148 {
149 	wmi_nlo_config_cmd_fixed_param *cmd;
150 	nlo_configured_parameters *nlo_list;
151 	enlo_candidate_score_params *cand_score_params;
152 	u_int8_t i, *buf_ptr;
153 	wmi_buf_t buf;
154 	uint32_t len;
155 	QDF_STATUS ret;
156 
157 	/* Fixed Params */
158 	len = sizeof(*cmd);
159 	if (req->num_networks) {
160 		/* TLV place holder for array of structures
161 		 * then each nlo_configured_parameters(nlo_list) TLV.
162 		 */
163 		len += WMI_TLV_HDR_SIZE;
164 		len += (sizeof(nlo_configured_parameters)
165 			    * QDF_MIN(req->num_networks, WMI_NLO_MAX_SSIDS));
166 		/* TLV for array of uint32 channel_list */
167 		len += WMI_TLV_HDR_SIZE;
168 		/* TLV for nlo_channel_prediction_cfg */
169 		len += WMI_TLV_HDR_SIZE;
170 		/* TLV for candidate score params */
171 		len += sizeof(enlo_candidate_score_params);
172 	}
173 
174 	buf = wmi_buf_alloc(wmi_handle, len);
175 	if (!buf) {
176 		WMI_LOGE("%s: Failed allocate wmi buffer", __func__);
177 		return QDF_STATUS_E_NOMEM;
178 	}
179 
180 	cmd = (wmi_nlo_config_cmd_fixed_param *) wmi_buf_data(buf);
181 
182 	buf_ptr = (u_int8_t *) cmd;
183 	WMITLV_SET_HDR(&cmd->tlv_header,
184 		       WMITLV_TAG_STRUC_wmi_nlo_config_cmd_fixed_param,
185 		       WMITLV_GET_STRUCT_TLVLEN(
186 			       wmi_nlo_config_cmd_fixed_param));
187 	cmd->vdev_id = req->session_id;
188 
189 	/* set flag to reset if num of networks are 0 */
190 	cmd->flags = (req->num_networks == 0 ?
191 		WMI_NLO_CONFIG_ENLO_RESET : WMI_NLO_CONFIG_ENLO);
192 
193 	buf_ptr += sizeof(wmi_nlo_config_cmd_fixed_param);
194 
195 	cmd->no_of_ssids = QDF_MIN(req->num_networks, WMI_NLO_MAX_SSIDS);
196 	WMI_LOGD("SSID count: %d flags: %d",
197 		cmd->no_of_ssids, cmd->flags);
198 
199 	/* Fill nlo_config only when num_networks are non zero */
200 	if (cmd->no_of_ssids) {
201 		/* Fill networks */
202 		WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_STRUC,
203 			cmd->no_of_ssids * sizeof(nlo_configured_parameters));
204 		buf_ptr += WMI_TLV_HDR_SIZE;
205 
206 		nlo_list = (nlo_configured_parameters *) buf_ptr;
207 		for (i = 0; i < cmd->no_of_ssids; i++) {
208 			WMITLV_SET_HDR(&nlo_list[i].tlv_header,
209 				WMITLV_TAG_ARRAY_BYTE,
210 				WMITLV_GET_STRUCT_TLVLEN(
211 				nlo_configured_parameters));
212 			/* Copy ssid and it's length */
213 			nlo_list[i].ssid.valid = true;
214 			nlo_list[i].ssid.ssid.ssid_len =
215 				req->networks[i].ssid.length;
216 			qdf_mem_copy(nlo_list[i].ssid.ssid.ssid,
217 				     req->networks[i].ssid.mac_ssid,
218 				     nlo_list[i].ssid.ssid.ssid_len);
219 			WMI_LOGD("index: %d ssid: %.*s len: %d", i,
220 				 nlo_list[i].ssid.ssid.ssid_len,
221 				 (char *) nlo_list[i].ssid.ssid.ssid,
222 				 nlo_list[i].ssid.ssid.ssid_len);
223 
224 			/* Copy pno flags */
225 			nlo_list[i].bcast_nw_type.valid = true;
226 			nlo_list[i].bcast_nw_type.bcast_nw_type =
227 					req->networks[i].flags;
228 			WMI_LOGD("PNO flags (%u)",
229 				nlo_list[i].bcast_nw_type.bcast_nw_type);
230 
231 			/* Copy auth bit field */
232 			nlo_list[i].auth_type.valid = true;
233 			nlo_list[i].auth_type.auth_type =
234 					req->networks[i].auth_bit_field;
235 			WMI_LOGD("Auth bit field (%u)",
236 					nlo_list[i].auth_type.auth_type);
237 		}
238 
239 		buf_ptr += cmd->no_of_ssids * sizeof(nlo_configured_parameters);
240 		/* Fill the channel list */
241 		WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_UINT32, 0);
242 		buf_ptr += WMI_TLV_HDR_SIZE;
243 
244 		/* Fill prediction_param */
245 		WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_STRUC, 0);
246 		buf_ptr += WMI_TLV_HDR_SIZE;
247 
248 		/* Fill epno candidate score params */
249 		cand_score_params = (enlo_candidate_score_params *) buf_ptr;
250 		WMITLV_SET_HDR(buf_ptr,
251 			WMITLV_TAG_STRUC_enlo_candidate_score_param,
252 			WMITLV_GET_STRUCT_TLVLEN(enlo_candidate_score_params));
253 		cand_score_params->min5GHz_rssi =
254 			req->min_5ghz_rssi;
255 		cand_score_params->min24GHz_rssi =
256 			req->min_24ghz_rssi;
257 		cand_score_params->initial_score_max =
258 			req->initial_score_max;
259 		cand_score_params->current_connection_bonus =
260 			req->current_connection_bonus;
261 		cand_score_params->same_network_bonus =
262 			req->same_network_bonus;
263 		cand_score_params->secure_bonus =
264 			req->secure_bonus;
265 		cand_score_params->band5GHz_bonus =
266 			req->band_5ghz_bonus;
267 		buf_ptr += sizeof(enlo_candidate_score_params);
268 	}
269 
270 	ret = wmi_unified_cmd_send(wmi_handle, buf, len,
271 			WMI_NETWORK_LIST_OFFLOAD_CONFIG_CMDID);
272 	if (QDF_IS_STATUS_ERROR(ret)) {
273 		WMI_LOGE("%s: Failed to send nlo wmi cmd", __func__);
274 		wmi_buf_free(buf);
275 		return QDF_STATUS_E_INVAL;
276 	}
277 
278 	WMI_LOGD("set ePNO list request sent successfully for vdev %d",
279 		 req->session_id);
280 
281 	return ret;
282 }
283 
284 /**
285  * send_extscan_get_capabilities_cmd_tlv() - extscan get capabilities
286  * @wmi_handle: wmi handle
287  * @pgetcapab: get capabilities params
288  *
289  * This function send request to fw to get extscan capabilities.
290  *
291  * Return: CDF status
292  */
293 static QDF_STATUS send_extscan_get_capabilities_cmd_tlv(wmi_unified_t wmi_handle,
294 		    struct extscan_capabilities_params *pgetcapab)
295 {
296 	wmi_extscan_get_capabilities_cmd_fixed_param *cmd;
297 	wmi_buf_t wmi_buf;
298 	uint32_t len;
299 	uint8_t *buf_ptr;
300 
301 	len = sizeof(*cmd);
302 	wmi_buf = wmi_buf_alloc(wmi_handle, len);
303 	if (!wmi_buf) {
304 		WMI_LOGE("%s: wmi_buf_alloc failed", __func__);
305 		return QDF_STATUS_E_NOMEM;
306 	}
307 	buf_ptr = (uint8_t *) wmi_buf_data(wmi_buf);
308 
309 	cmd = (wmi_extscan_get_capabilities_cmd_fixed_param *) buf_ptr;
310 	WMITLV_SET_HDR(&cmd->tlv_header,
311 	       WMITLV_TAG_STRUC_wmi_extscan_get_capabilities_cmd_fixed_param,
312 	       WMITLV_GET_STRUCT_TLVLEN
313 	       (wmi_extscan_get_capabilities_cmd_fixed_param));
314 
315 	cmd->request_id = pgetcapab->request_id;
316 
317 	if (wmi_unified_cmd_send(wmi_handle, wmi_buf, len,
318 				 WMI_EXTSCAN_GET_CAPABILITIES_CMDID)) {
319 		WMI_LOGE("%s: failed to  command", __func__);
320 		wmi_buf_free(wmi_buf);
321 		return QDF_STATUS_E_FAILURE;
322 	}
323 	return QDF_STATUS_SUCCESS;
324 }
325 
326 /**
327  * send_extscan_get_cached_results_cmd_tlv() - extscan get cached results
328  * @wmi_handle: wmi handle
329  * @pcached_results: cached results parameters
330  *
331  * This function send request to fw to get cached results.
332  *
333  * Return: CDF status
334  */
335 static QDF_STATUS send_extscan_get_cached_results_cmd_tlv(wmi_unified_t wmi_handle,
336 		  struct extscan_cached_result_params *pcached_results)
337 {
338 	wmi_extscan_get_cached_results_cmd_fixed_param *cmd;
339 	wmi_buf_t wmi_buf;
340 	uint32_t len;
341 	uint8_t *buf_ptr;
342 
343 	len = sizeof(*cmd);
344 	wmi_buf = wmi_buf_alloc(wmi_handle, len);
345 	if (!wmi_buf) {
346 		WMI_LOGE("%s: wmi_buf_alloc failed", __func__);
347 		return QDF_STATUS_E_NOMEM;
348 	}
349 	buf_ptr = (uint8_t *) wmi_buf_data(wmi_buf);
350 
351 	cmd = (wmi_extscan_get_cached_results_cmd_fixed_param *) buf_ptr;
352 	WMITLV_SET_HDR(&cmd->tlv_header,
353 		WMITLV_TAG_STRUC_wmi_extscan_get_cached_results_cmd_fixed_param,
354 		WMITLV_GET_STRUCT_TLVLEN
355 		(wmi_extscan_get_cached_results_cmd_fixed_param));
356 
357 	cmd->request_id = pcached_results->request_id;
358 	cmd->vdev_id = pcached_results->session_id;
359 	cmd->control_flags = pcached_results->flush;
360 
361 	if (wmi_unified_cmd_send(wmi_handle, wmi_buf, len,
362 				 WMI_EXTSCAN_GET_CACHED_RESULTS_CMDID)) {
363 		WMI_LOGE("%s: failed to  command", __func__);
364 		wmi_buf_free(wmi_buf);
365 		return QDF_STATUS_E_FAILURE;
366 	}
367 	return QDF_STATUS_SUCCESS;
368 }
369 
370 /**
371  * send_extscan_stop_change_monitor_cmd_tlv() - send stop change monitor cmd
372  * @wmi_handle: wmi handle
373  * @reset_req: Reset change request params
374  *
375  * This function sends stop change monitor request to fw.
376  *
377  * Return: CDF status
378  */
379 static QDF_STATUS send_extscan_stop_change_monitor_cmd_tlv
380 			(wmi_unified_t wmi_handle,
381 			struct extscan_capabilities_reset_params *reset_req)
382 {
383 	wmi_extscan_configure_wlan_change_monitor_cmd_fixed_param *cmd;
384 	wmi_buf_t wmi_buf;
385 	uint32_t len;
386 	uint8_t *buf_ptr;
387 	int change_list = 0;
388 
389 	len = sizeof(*cmd);
390 
391 	/* reset significant change tlv is set to 0 */
392 	len += WMI_TLV_HDR_SIZE;
393 	len += change_list * sizeof(wmi_extscan_wlan_change_bssid_param);
394 	wmi_buf = wmi_buf_alloc(wmi_handle, len);
395 	if (!wmi_buf) {
396 		WMI_LOGE("%s: wmi_buf_alloc failed", __func__);
397 		return QDF_STATUS_E_NOMEM;
398 	}
399 	buf_ptr = (uint8_t *) wmi_buf_data(wmi_buf);
400 
401 	cmd = (wmi_extscan_configure_wlan_change_monitor_cmd_fixed_param *)
402 		buf_ptr;
403 	WMITLV_SET_HDR(&cmd->tlv_header,
404 	WMITLV_TAG_STRUC_wmi_extscan_configure_wlan_change_monitor_cmd_fixed_param,
405 		WMITLV_GET_STRUCT_TLVLEN
406 		(wmi_extscan_configure_wlan_change_monitor_cmd_fixed_param));
407 
408 	cmd->request_id = reset_req->request_id;
409 	cmd->vdev_id = reset_req->session_id;
410 	cmd->mode = 0;
411 
412 	buf_ptr += sizeof(*cmd);
413 	WMITLV_SET_HDR(buf_ptr,
414 		       WMITLV_TAG_ARRAY_STRUC,
415 		       change_list *
416 		       sizeof(wmi_extscan_wlan_change_bssid_param));
417 	buf_ptr += WMI_TLV_HDR_SIZE + (change_list *
418 				       sizeof
419 				       (wmi_extscan_wlan_change_bssid_param));
420 
421 	if (wmi_unified_cmd_send(wmi_handle, wmi_buf, len,
422 			 WMI_EXTSCAN_CONFIGURE_WLAN_CHANGE_MONITOR_CMDID)) {
423 		WMI_LOGE("%s: failed to  command", __func__);
424 		wmi_buf_free(wmi_buf);
425 		return QDF_STATUS_E_FAILURE;
426 	}
427 	return QDF_STATUS_SUCCESS;
428 }
429 
430 /**
431  * wmi_get_buf_extscan_change_monitor_cmd() - fill change monitor request
432  * @wmi_handle: wmi handle
433  * @psigchange: change monitor request params
434  * @buf: wmi buffer
435  * @buf_len: buffer length
436  *
437  * This function fills elements of change monitor request buffer.
438  *
439  * Return: CDF status
440  */
441 static QDF_STATUS wmi_get_buf_extscan_change_monitor_cmd
442 			(wmi_unified_t wmi_handle,
443 			struct extscan_set_sig_changereq_params
444 			*psigchange, wmi_buf_t *buf, int *buf_len)
445 {
446 	wmi_extscan_configure_wlan_change_monitor_cmd_fixed_param *cmd;
447 	wmi_extscan_wlan_change_bssid_param *dest_chglist;
448 	uint8_t *buf_ptr;
449 	int j;
450 	int len = sizeof(*cmd);
451 	uint32_t numap = psigchange->num_ap;
452 	struct ap_threshold_params *src_ap = psigchange->ap;
453 
454 	if (!numap || (numap > WMI_WLAN_EXTSCAN_MAX_SIGNIFICANT_CHANGE_APS)) {
455 		WMI_LOGE("%s: Invalid number of bssid's", __func__);
456 		return QDF_STATUS_E_INVAL;
457 	}
458 	len += WMI_TLV_HDR_SIZE;
459 	len += numap * sizeof(wmi_extscan_wlan_change_bssid_param);
460 
461 	*buf = wmi_buf_alloc(wmi_handle, len);
462 	if (!*buf) {
463 		WMI_LOGP("%s: failed to allocate memory for change monitor cmd",
464 			 __func__);
465 		return QDF_STATUS_E_FAILURE;
466 	}
467 	buf_ptr = (uint8_t *) wmi_buf_data(*buf);
468 	cmd =
469 		(wmi_extscan_configure_wlan_change_monitor_cmd_fixed_param *)
470 		buf_ptr;
471 	WMITLV_SET_HDR(&cmd->tlv_header,
472 	WMITLV_TAG_STRUC_wmi_extscan_configure_wlan_change_monitor_cmd_fixed_param,
473 	       WMITLV_GET_STRUCT_TLVLEN
474 	       (wmi_extscan_configure_wlan_change_monitor_cmd_fixed_param));
475 
476 	cmd->request_id = psigchange->request_id;
477 	cmd->vdev_id = psigchange->session_id;
478 	cmd->total_entries = numap;
479 	cmd->mode = 1;
480 	cmd->num_entries_in_page = numap;
481 	cmd->lost_ap_scan_count = psigchange->lostap_sample_size;
482 	cmd->max_rssi_samples = psigchange->rssi_sample_size;
483 	cmd->rssi_averaging_samples = psigchange->rssi_sample_size;
484 	cmd->max_out_of_range_count = psigchange->min_breaching;
485 
486 	buf_ptr += sizeof(*cmd);
487 	WMITLV_SET_HDR(buf_ptr,
488 		       WMITLV_TAG_ARRAY_STRUC,
489 		       numap * sizeof(wmi_extscan_wlan_change_bssid_param));
490 	dest_chglist = (wmi_extscan_wlan_change_bssid_param *)
491 		       (buf_ptr + WMI_TLV_HDR_SIZE);
492 
493 	for (j = 0; j < numap; j++) {
494 		WMITLV_SET_HDR(dest_chglist,
495 		       WMITLV_TAG_STRUC_wmi_extscan_bucket_cmd_fixed_param,
496 		       WMITLV_GET_STRUCT_TLVLEN
497 		       (wmi_extscan_wlan_change_bssid_param));
498 
499 		dest_chglist->lower_rssi_limit = src_ap->low;
500 		dest_chglist->upper_rssi_limit = src_ap->high;
501 		WMI_CHAR_ARRAY_TO_MAC_ADDR(src_ap->bssid.bytes,
502 					   &dest_chglist->bssid);
503 
504 		WMI_LOGD("%s: min_rssi %d", __func__,
505 			 dest_chglist->lower_rssi_limit);
506 		dest_chglist++;
507 		src_ap++;
508 	}
509 	buf_ptr += WMI_TLV_HDR_SIZE +
510 		   (numap * sizeof(wmi_extscan_wlan_change_bssid_param));
511 	*buf_len = len;
512 	return QDF_STATUS_SUCCESS;
513 }
514 
515 /**
516  * send_extscan_start_change_monitor_cmd_tlv() - send start change monitor cmd
517  * @wmi_handle: wmi handle
518  * @psigchange: change monitor request params
519  *
520  * This function sends start change monitor request to fw.
521  *
522  * Return: CDF status
523  */
524 static QDF_STATUS send_extscan_start_change_monitor_cmd_tlv
525 			(wmi_unified_t wmi_handle,
526 			struct extscan_set_sig_changereq_params *
527 			psigchange)
528 {
529 	QDF_STATUS qdf_status = QDF_STATUS_SUCCESS;
530 	wmi_buf_t buf;
531 	int len;
532 
533 
534 	qdf_status = wmi_get_buf_extscan_change_monitor_cmd(wmi_handle,
535 			     psigchange, &buf,
536 			     &len);
537 	if (qdf_status != QDF_STATUS_SUCCESS) {
538 		WMI_LOGE("%s: Failed to get buffer for change monitor cmd",
539 			 __func__);
540 		return QDF_STATUS_E_FAILURE;
541 	}
542 	if (!buf) {
543 		WMI_LOGE("%s: Failed to get buffer", __func__);
544 		return QDF_STATUS_E_FAILURE;
545 	}
546 	if (wmi_unified_cmd_send(wmi_handle, buf, len,
547 		 WMI_EXTSCAN_CONFIGURE_WLAN_CHANGE_MONITOR_CMDID)) {
548 		WMI_LOGE("%s: failed to send command", __func__);
549 		wmi_buf_free(buf);
550 		return QDF_STATUS_E_FAILURE;
551 	}
552 	return QDF_STATUS_SUCCESS;
553 }
554 
555 /**
556  * send_extscan_stop_hotlist_monitor_cmd_tlv() - stop hotlist monitor
557  * @wmi_handle: wmi handle
558  * @photlist_reset: hotlist reset params
559  *
560  * This function configures hotlist monitor to stop in fw.
561  *
562  * Return: CDF status
563  */
564 static QDF_STATUS send_extscan_stop_hotlist_monitor_cmd_tlv
565 		(wmi_unified_t wmi_handle,
566 		struct extscan_bssid_hotlist_reset_params *photlist_reset)
567 {
568 	wmi_extscan_configure_hotlist_monitor_cmd_fixed_param *cmd;
569 	wmi_buf_t wmi_buf;
570 	uint32_t len;
571 	uint8_t *buf_ptr;
572 	int hotlist_entries = 0;
573 
574 	len = sizeof(*cmd);
575 
576 	/* reset bssid hotlist with tlv set to 0 */
577 	len += WMI_TLV_HDR_SIZE;
578 	len += hotlist_entries * sizeof(wmi_extscan_hotlist_entry);
579 
580 	wmi_buf = wmi_buf_alloc(wmi_handle, len);
581 	if (!wmi_buf) {
582 		WMI_LOGE("%s: wmi_buf_alloc failed", __func__);
583 		return QDF_STATUS_E_NOMEM;
584 	}
585 
586 	buf_ptr = (uint8_t *) wmi_buf_data(wmi_buf);
587 	cmd = (wmi_extscan_configure_hotlist_monitor_cmd_fixed_param *)
588 	      buf_ptr;
589 	WMITLV_SET_HDR(&cmd->tlv_header,
590 	WMITLV_TAG_STRUC_wmi_extscan_configure_hotlist_monitor_cmd_fixed_param,
591 	WMITLV_GET_STRUCT_TLVLEN
592 	(wmi_extscan_configure_hotlist_monitor_cmd_fixed_param));
593 
594 	cmd->request_id = photlist_reset->request_id;
595 	cmd->vdev_id = photlist_reset->session_id;
596 	cmd->mode = 0;
597 
598 	buf_ptr += sizeof(*cmd);
599 	WMITLV_SET_HDR(buf_ptr,
600 		       WMITLV_TAG_ARRAY_STRUC,
601 		       hotlist_entries * sizeof(wmi_extscan_hotlist_entry));
602 	buf_ptr += WMI_TLV_HDR_SIZE +
603 		   (hotlist_entries * sizeof(wmi_extscan_hotlist_entry));
604 
605 	if (wmi_unified_cmd_send(wmi_handle, wmi_buf, len,
606 				WMI_EXTSCAN_CONFIGURE_HOTLIST_MONITOR_CMDID)) {
607 		WMI_LOGE("%s: failed to  command", __func__);
608 		wmi_buf_free(wmi_buf);
609 		return QDF_STATUS_E_FAILURE;
610 	}
611 	return QDF_STATUS_SUCCESS;
612 }
613 
614 /**
615  * send_stop_extscan_cmd_tlv() - stop extscan command to fw.
616  * @wmi_handle: wmi handle
617  * @pstopcmd: stop scan command request params
618  *
619  * This function sends stop extscan request to fw.
620  *
621  * Return: CDF Status.
622  */
623 static QDF_STATUS send_stop_extscan_cmd_tlv(wmi_unified_t wmi_handle,
624 			  struct extscan_stop_req_params *pstopcmd)
625 {
626 	wmi_extscan_stop_cmd_fixed_param *cmd;
627 	wmi_buf_t wmi_buf;
628 	uint32_t len;
629 	uint8_t *buf_ptr;
630 
631 	len = sizeof(*cmd);
632 	wmi_buf = wmi_buf_alloc(wmi_handle, len);
633 	if (!wmi_buf) {
634 		WMI_LOGE("%s: wmi_buf_alloc failed", __func__);
635 		return QDF_STATUS_E_NOMEM;
636 	}
637 	buf_ptr = (uint8_t *) wmi_buf_data(wmi_buf);
638 	cmd = (wmi_extscan_stop_cmd_fixed_param *) buf_ptr;
639 	WMITLV_SET_HDR(&cmd->tlv_header,
640 		       WMITLV_TAG_STRUC_wmi_extscan_stop_cmd_fixed_param,
641 		       WMITLV_GET_STRUCT_TLVLEN
642 			       (wmi_extscan_stop_cmd_fixed_param));
643 
644 	cmd->request_id = pstopcmd->request_id;
645 	cmd->vdev_id = pstopcmd->session_id;
646 
647 	if (wmi_unified_cmd_send(wmi_handle, wmi_buf, len,
648 				 WMI_EXTSCAN_STOP_CMDID)) {
649 		WMI_LOGE("%s: failed to  command", __func__);
650 		wmi_buf_free(wmi_buf);
651 		return QDF_STATUS_E_FAILURE;
652 	}
653 
654 	return QDF_STATUS_SUCCESS;
655 }
656 
657 /**
658  * wmi_get_buf_extscan_start_cmd() - Fill extscan start request
659  * @wmi_handle: wmi handle
660  * @pstart: scan command request params
661  * @buf: event buffer
662  * @buf_len: length of buffer
663  *
664  * This function fills individual elements of extscan request and
665  * TLV for buckets, channel list.
666  *
667  * Return: CDF Status.
668  */
669 static
670 QDF_STATUS wmi_get_buf_extscan_start_cmd(wmi_unified_t wmi_handle,
671 			 struct wifi_scan_cmd_req_params *pstart,
672 			 wmi_buf_t *buf, int *buf_len)
673 {
674 	wmi_extscan_start_cmd_fixed_param *cmd;
675 	wmi_extscan_bucket *dest_blist;
676 	wmi_extscan_bucket_channel *dest_clist;
677 	struct wifi_scan_bucket_params *src_bucket = pstart->buckets;
678 	struct wifi_scan_channelspec_params *src_channel = src_bucket->channels;
679 	struct wifi_scan_channelspec_params save_channel[WMI_WLAN_EXTSCAN_MAX_CHANNELS];
680 
681 	uint8_t *buf_ptr;
682 	int i, k, count = 0;
683 	int len = sizeof(*cmd);
684 	int nbuckets = pstart->numBuckets;
685 	int nchannels = 0;
686 
687 	/* These TLV's are are NULL by default */
688 	uint32_t ie_len_with_pad = 0;
689 	int num_ssid = 0;
690 	int num_bssid = 0;
691 	int ie_len = 0;
692 
693 	uint32_t base_period = pstart->basePeriod;
694 
695 	/* TLV placeholder for ssid_list (NULL) */
696 	len += WMI_TLV_HDR_SIZE;
697 	len += num_ssid * sizeof(wmi_ssid);
698 
699 	/* TLV placeholder for bssid_list (NULL) */
700 	len += WMI_TLV_HDR_SIZE;
701 	len += num_bssid * sizeof(wmi_mac_addr);
702 
703 	/* TLV placeholder for ie_data (NULL) */
704 	len += WMI_TLV_HDR_SIZE;
705 	len += ie_len * sizeof(uint32_t);
706 
707 	/* TLV placeholder for bucket */
708 	len += WMI_TLV_HDR_SIZE;
709 	len += nbuckets * sizeof(wmi_extscan_bucket);
710 
711 	/* TLV channel placeholder */
712 	len += WMI_TLV_HDR_SIZE;
713 	for (i = 0; i < nbuckets; i++) {
714 		nchannels += src_bucket->numChannels;
715 		src_bucket++;
716 	}
717 
718 	WMI_LOGD("%s: Total buckets: %d total #of channels is %d",
719 		__func__, nbuckets, nchannels);
720 	len += nchannels * sizeof(wmi_extscan_bucket_channel);
721 	/* Allocate the memory */
722 	*buf = wmi_buf_alloc(wmi_handle, len);
723 	if (!*buf) {
724 		WMI_LOGP("%s: failed to allocate memory for start extscan cmd",
725 			__func__);
726 		return QDF_STATUS_E_NOMEM;
727 	}
728 	buf_ptr = (uint8_t *) wmi_buf_data(*buf);
729 	cmd = (wmi_extscan_start_cmd_fixed_param *) buf_ptr;
730 	WMITLV_SET_HDR(&cmd->tlv_header,
731 		       WMITLV_TAG_STRUC_wmi_extscan_start_cmd_fixed_param,
732 		       WMITLV_GET_STRUCT_TLVLEN
733 			       (wmi_extscan_start_cmd_fixed_param));
734 
735 	cmd->request_id = pstart->requestId;
736 	cmd->vdev_id = pstart->sessionId;
737 	cmd->base_period = pstart->basePeriod;
738 	cmd->num_buckets = nbuckets;
739 	cmd->configuration_flags = 0;
740 	if (pstart->configuration_flags & WMI_EXTSCAN_LP_EXTENDED_BATCHING)
741 		cmd->configuration_flags |= WMI_EXTSCAN_EXTENDED_BATCHING_EN;
742 	WMI_LOGI("%s: configuration_flags: 0x%x", __func__,
743 			cmd->configuration_flags);
744 #ifdef FEATURE_WLAN_EXTSCAN
745 	cmd->min_rest_time = WMI_EXTSCAN_REST_TIME;
746 	cmd->max_rest_time = WMI_EXTSCAN_REST_TIME;
747 	cmd->max_scan_time = WMI_EXTSCAN_MAX_SCAN_TIME;
748 	cmd->burst_duration = WMI_EXTSCAN_BURST_DURATION;
749 #endif
750 	cmd->max_bssids_per_scan_cycle = pstart->maxAPperScan;
751 
752 	/* The max dwell time is retrieved from the first channel
753 	 * of the first bucket and kept common for all channels.
754 	 */
755 	cmd->min_dwell_time_active = pstart->min_dwell_time_active;
756 	cmd->max_dwell_time_active = pstart->max_dwell_time_active;
757 	cmd->min_dwell_time_passive = pstart->min_dwell_time_passive;
758 	cmd->max_dwell_time_passive = pstart->max_dwell_time_passive;
759 	cmd->max_bssids_per_scan_cycle = pstart->maxAPperScan;
760 	cmd->max_table_usage = pstart->report_threshold_percent;
761 	cmd->report_threshold_num_scans = pstart->report_threshold_num_scans;
762 
763 	cmd->repeat_probe_time = cmd->max_dwell_time_active /
764 					WMI_SCAN_NPROBES_DEFAULT;
765 	cmd->probe_delay = 0;
766 	cmd->probe_spacing_time = 0;
767 	cmd->idle_time = 0;
768 	cmd->scan_ctrl_flags = WMI_SCAN_ADD_BCAST_PROBE_REQ |
769 			       WMI_SCAN_ADD_CCK_RATES |
770 			       WMI_SCAN_ADD_OFDM_RATES |
771 			       WMI_SCAN_ADD_SPOOFED_MAC_IN_PROBE_REQ |
772 			       WMI_SCAN_ADD_DS_IE_IN_PROBE_REQ;
773 	WMI_SCAN_SET_DWELL_MODE(cmd->scan_ctrl_flags,
774 			pstart->extscan_adaptive_dwell_mode);
775 	cmd->scan_priority = WMI_SCAN_PRIORITY_VERY_LOW;
776 	cmd->num_ssids = 0;
777 	cmd->num_bssid = 0;
778 	cmd->ie_len = 0;
779 	cmd->n_probes = (cmd->repeat_probe_time > 0) ?
780 			cmd->max_dwell_time_active / cmd->repeat_probe_time : 0;
781 
782 	buf_ptr += sizeof(*cmd);
783 	WMITLV_SET_HDR(buf_ptr,
784 		       WMITLV_TAG_ARRAY_FIXED_STRUC,
785 		       num_ssid * sizeof(wmi_ssid));
786 	buf_ptr += WMI_TLV_HDR_SIZE + (num_ssid * sizeof(wmi_ssid));
787 
788 	WMITLV_SET_HDR(buf_ptr,
789 		       WMITLV_TAG_ARRAY_FIXED_STRUC,
790 		       num_bssid * sizeof(wmi_mac_addr));
791 	buf_ptr += WMI_TLV_HDR_SIZE + (num_bssid * sizeof(wmi_mac_addr));
792 
793 	ie_len_with_pad = 0;
794 	WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_BYTE,
795 			  ie_len_with_pad);
796 	buf_ptr += WMI_TLV_HDR_SIZE + ie_len_with_pad;
797 
798 	WMITLV_SET_HDR(buf_ptr,
799 		       WMITLV_TAG_ARRAY_STRUC,
800 		       nbuckets * sizeof(wmi_extscan_bucket));
801 	dest_blist = (wmi_extscan_bucket *)
802 		     (buf_ptr + WMI_TLV_HDR_SIZE);
803 	src_bucket = pstart->buckets;
804 
805 	/* Retrieve scanning information from each bucket and
806 	 * channels and send it to the target
807 	 */
808 	for (i = 0; i < nbuckets; i++) {
809 		WMITLV_SET_HDR(dest_blist,
810 		      WMITLV_TAG_STRUC_wmi_extscan_bucket_cmd_fixed_param,
811 		      WMITLV_GET_STRUCT_TLVLEN(wmi_extscan_bucket));
812 
813 		dest_blist->bucket_id = src_bucket->bucket;
814 		dest_blist->base_period_multiplier =
815 			src_bucket->period / base_period;
816 		dest_blist->min_period = src_bucket->period;
817 		dest_blist->max_period = src_bucket->max_period;
818 		dest_blist->exp_backoff = src_bucket->exponent;
819 		dest_blist->exp_max_step_count = src_bucket->step_count;
820 		dest_blist->channel_band = src_bucket->band;
821 		dest_blist->num_channels = src_bucket->numChannels;
822 		dest_blist->notify_extscan_events = 0;
823 
824 		if (src_bucket->reportEvents & WMI_EXTSCAN_REPORT_EVENTS_EACH_SCAN)
825 			dest_blist->notify_extscan_events =
826 					WMI_EXTSCAN_CYCLE_COMPLETED_EVENT |
827 					WMI_EXTSCAN_CYCLE_STARTED_EVENT;
828 
829 		if (src_bucket->reportEvents &
830 				WMI_EXTSCAN_REPORT_EVENTS_FULL_RESULTS) {
831 			dest_blist->forwarding_flags =
832 				WMI_EXTSCAN_FORWARD_FRAME_TO_HOST;
833 			dest_blist->notify_extscan_events |=
834 				WMI_EXTSCAN_BUCKET_COMPLETED_EVENT |
835 				WMI_EXTSCAN_CYCLE_STARTED_EVENT |
836 				WMI_EXTSCAN_CYCLE_COMPLETED_EVENT;
837 		} else {
838 			dest_blist->forwarding_flags =
839 				WMI_EXTSCAN_NO_FORWARDING;
840 		}
841 
842 		if (src_bucket->reportEvents & WMI_EXTSCAN_REPORT_EVENTS_NO_BATCH)
843 			dest_blist->configuration_flags = 0;
844 		else
845 			dest_blist->configuration_flags =
846 				WMI_EXTSCAN_BUCKET_CACHE_RESULTS;
847 
848 		WMI_LOGI("%s: ntfy_extscan_events:%u cfg_flags:%u fwd_flags:%u",
849 			__func__, dest_blist->notify_extscan_events,
850 			dest_blist->configuration_flags,
851 			dest_blist->forwarding_flags);
852 
853 		dest_blist->min_dwell_time_active =
854 				   src_bucket->min_dwell_time_active;
855 		dest_blist->max_dwell_time_active =
856 				   src_bucket->max_dwell_time_active;
857 		dest_blist->min_dwell_time_passive =
858 				   src_bucket->min_dwell_time_passive;
859 		dest_blist->max_dwell_time_passive =
860 				   src_bucket->max_dwell_time_passive;
861 		src_channel = src_bucket->channels;
862 
863 		/* save the channel info to later populate
864 		 * the  channel TLV
865 		 */
866 		for (k = 0; k < src_bucket->numChannels; k++) {
867 			save_channel[count++].channel = src_channel->channel;
868 			src_channel++;
869 		}
870 		dest_blist++;
871 		src_bucket++;
872 	}
873 	buf_ptr += WMI_TLV_HDR_SIZE + (nbuckets * sizeof(wmi_extscan_bucket));
874 	WMITLV_SET_HDR(buf_ptr,
875 		       WMITLV_TAG_ARRAY_STRUC,
876 		       nchannels * sizeof(wmi_extscan_bucket_channel));
877 	dest_clist = (wmi_extscan_bucket_channel *)
878 		     (buf_ptr + WMI_TLV_HDR_SIZE);
879 
880 	/* Active or passive scan is based on the bucket dwell time
881 	 * and channel specific active,passive scans are not
882 	 * supported yet
883 	 */
884 	for (i = 0; i < nchannels; i++) {
885 		WMITLV_SET_HDR(dest_clist,
886 		WMITLV_TAG_STRUC_wmi_extscan_bucket_channel_event_fixed_param,
887 			   WMITLV_GET_STRUCT_TLVLEN
888 			   (wmi_extscan_bucket_channel));
889 		dest_clist->channel = save_channel[i].channel;
890 		dest_clist++;
891 	}
892 	buf_ptr += WMI_TLV_HDR_SIZE +
893 		   (nchannels * sizeof(wmi_extscan_bucket_channel));
894 	*buf_len = len;
895 	return QDF_STATUS_SUCCESS;
896 }
897 
898 /**
899  * send_start_extscan_cmd_tlv() - start extscan command to fw.
900  * @wmi_handle: wmi handle
901  * @pstart: scan command request params
902  *
903  * This function sends start extscan request to fw.
904  *
905  * Return: CDF Status.
906  */
907 static QDF_STATUS send_start_extscan_cmd_tlv(wmi_unified_t wmi_handle,
908 			  struct wifi_scan_cmd_req_params *pstart)
909 {
910 	QDF_STATUS qdf_status = QDF_STATUS_SUCCESS;
911 	wmi_buf_t buf;
912 	int len;
913 
914 	/* Fill individual elements of extscan request and
915 	 * TLV for buckets, channel list.
916 	 */
917 	qdf_status = wmi_get_buf_extscan_start_cmd(wmi_handle,
918 			     pstart, &buf, &len);
919 	if (qdf_status != QDF_STATUS_SUCCESS) {
920 		WMI_LOGE("%s: Failed to get buffer for ext scan cmd", __func__);
921 		return QDF_STATUS_E_FAILURE;
922 	}
923 	if (!buf) {
924 		WMI_LOGE("%s:Failed to get buffer for current extscan info",
925 			__func__);
926 		return QDF_STATUS_E_FAILURE;
927 	}
928 	if (wmi_unified_cmd_send(wmi_handle, buf,
929 				 len, WMI_EXTSCAN_START_CMDID)) {
930 		WMI_LOGE("%s: failed to send command", __func__);
931 		wmi_buf_free(buf);
932 		return QDF_STATUS_E_FAILURE;
933 	}
934 
935 	return QDF_STATUS_SUCCESS;
936 }
937 
938 /** wmi_get_hotlist_entries_per_page() - hotlist entries per page
939  * @wmi_handle: wmi handle.
940  * @cmd: size of command structure.
941  * @per_entry_size: per entry size.
942  *
943  * This utility function calculates how many hotlist entries can
944  * fit in one page.
945  *
946  * Return: number of entries
947  */
948 static inline int wmi_get_hotlist_entries_per_page
949 				(wmi_unified_t wmi_handle,
950 				size_t cmd_size,
951 				size_t per_entry_size)
952 {
953 	uint32_t avail_space = 0;
954 	int num_entries = 0;
955 	uint16_t max_msg_len = wmi_get_max_msg_len(wmi_handle);
956 
957 	/* Calculate number of hotlist entries that can
958 	 * be passed in wma message request.
959 	 */
960 	avail_space = max_msg_len - cmd_size;
961 	num_entries = avail_space / per_entry_size;
962 	return num_entries;
963 }
964 
965 /**
966  * send_get_buf_extscan_hotlist_cmd_tlv() - prepare hotlist command
967  * @wmi_handle: wmi handle
968  * @photlist: hotlist command params
969  * @buf_len: buffer length
970  *
971  * This function fills individual elements for  hotlist request and
972  * TLV for bssid entries
973  *
974  * Return: CDF Status.
975  */
976 static QDF_STATUS send_get_buf_extscan_hotlist_cmd_tlv
977 			(wmi_unified_t wmi_handle,
978 			struct ext_scan_setbssi_hotlist_params *photlist,
979 			int *buf_len)
980 {
981 	wmi_extscan_configure_hotlist_monitor_cmd_fixed_param *cmd = NULL;
982 	wmi_extscan_hotlist_entry *dest_hotlist;
983 	struct ap_threshold_params *src_ap = photlist->ap;
984 	wmi_buf_t buf;
985 	uint8_t *buf_ptr;
986 
987 	int j, index = 0;
988 	int cmd_len = 0;
989 	int num_entries;
990 	int min_entries = 0;
991 	uint32_t numap = photlist->numAp;
992 	int len = sizeof(*cmd);
993 
994 	len += WMI_TLV_HDR_SIZE;
995 	cmd_len = len;
996 
997 	num_entries = wmi_get_hotlist_entries_per_page(wmi_handle,
998 							cmd_len,
999 							sizeof(*dest_hotlist));
1000 	/* setbssid hotlist expects the bssid list
1001 	 * to be non zero value
1002 	 */
1003 	if (!numap || (numap > WMI_WLAN_EXTSCAN_MAX_HOTLIST_APS)) {
1004 		WMI_LOGE("Invalid number of APs: %d", numap);
1005 		return QDF_STATUS_E_INVAL;
1006 	}
1007 
1008 	/* Split the hot list entry pages and send multiple command
1009 	 * requests if the buffer reaches the maximum request size
1010 	 */
1011 	while (index < numap) {
1012 		min_entries = QDF_MIN(num_entries, numap);
1013 		len += min_entries * sizeof(wmi_extscan_hotlist_entry);
1014 		buf = wmi_buf_alloc(wmi_handle, len);
1015 		if (!buf) {
1016 			WMI_LOGP("%s: wmi_buf_alloc failed", __func__);
1017 			return QDF_STATUS_E_FAILURE;
1018 		}
1019 		buf_ptr = (uint8_t *) wmi_buf_data(buf);
1020 		cmd = (wmi_extscan_configure_hotlist_monitor_cmd_fixed_param *)
1021 		      buf_ptr;
1022 		WMITLV_SET_HDR(&cmd->tlv_header,
1023 			       WMITLV_TAG_STRUC_wmi_extscan_configure_hotlist_monitor_cmd_fixed_param,
1024 			       WMITLV_GET_STRUCT_TLVLEN
1025 				       (wmi_extscan_configure_hotlist_monitor_cmd_fixed_param));
1026 
1027 		/* Multiple requests are sent until the num_entries_in_page
1028 		 * matches the total_entries
1029 		 */
1030 		cmd->request_id = photlist->requestId;
1031 		cmd->vdev_id = photlist->sessionId;
1032 		cmd->total_entries = numap;
1033 		cmd->mode = 1;
1034 		cmd->num_entries_in_page = min_entries;
1035 		cmd->lost_ap_scan_count = photlist->lost_ap_sample_size;
1036 		cmd->first_entry_index = index;
1037 
1038 		WMI_LOGD("%s: vdev id:%d total_entries: %d num_entries: %d lost_ap_sample_size: %d",
1039 			__func__, cmd->vdev_id, cmd->total_entries,
1040 			cmd->num_entries_in_page,
1041 			cmd->lost_ap_scan_count);
1042 
1043 		buf_ptr += sizeof(*cmd);
1044 		WMITLV_SET_HDR(buf_ptr,
1045 			       WMITLV_TAG_ARRAY_STRUC,
1046 			       min_entries * sizeof(wmi_extscan_hotlist_entry));
1047 		dest_hotlist = (wmi_extscan_hotlist_entry *)
1048 			       (buf_ptr + WMI_TLV_HDR_SIZE);
1049 
1050 		/* Populate bssid, channel info and rssi
1051 		 * for the bssid's that are sent as hotlists.
1052 		 */
1053 		for (j = 0; j < min_entries; j++) {
1054 			WMITLV_SET_HDR(dest_hotlist,
1055 				       WMITLV_TAG_STRUC_wmi_extscan_bucket_cmd_fixed_param,
1056 				       WMITLV_GET_STRUCT_TLVLEN
1057 					       (wmi_extscan_hotlist_entry));
1058 
1059 			dest_hotlist->min_rssi = src_ap->low;
1060 			WMI_CHAR_ARRAY_TO_MAC_ADDR(src_ap->bssid.bytes,
1061 						   &dest_hotlist->bssid);
1062 
1063 			WMI_LOGD("%s:channel:%d min_rssi %d",
1064 				 __func__, dest_hotlist->channel,
1065 				 dest_hotlist->min_rssi);
1066 			WMI_LOGD
1067 				("%s: bssid mac_addr31to0: 0x%x, mac_addr47to32: 0x%x",
1068 				__func__, dest_hotlist->bssid.mac_addr31to0,
1069 				dest_hotlist->bssid.mac_addr47to32);
1070 			dest_hotlist++;
1071 			src_ap++;
1072 		}
1073 		buf_ptr += WMI_TLV_HDR_SIZE +
1074 			   (min_entries * sizeof(wmi_extscan_hotlist_entry));
1075 
1076 		if (wmi_unified_cmd_send(wmi_handle, buf, len,
1077 				WMI_EXTSCAN_CONFIGURE_HOTLIST_MONITOR_CMDID)) {
1078 			WMI_LOGE("%s: failed to send command", __func__);
1079 			wmi_buf_free(buf);
1080 			return QDF_STATUS_E_FAILURE;
1081 		}
1082 		index = index + min_entries;
1083 		num_entries = numap - min_entries;
1084 		len = cmd_len;
1085 	}
1086 	return QDF_STATUS_SUCCESS;
1087 }
1088 
1089 void wmi_extscan_attach_tlv(wmi_unified_t wmi_handle)
1090 {
1091 	struct wmi_ops *ops = wmi_handle->ops;
1092 	ops->send_reset_passpoint_network_list_cmd =
1093 				send_reset_passpoint_network_list_cmd_tlv;
1094 	ops->send_set_passpoint_network_list_cmd =
1095 				send_set_passpoint_network_list_cmd_tlv;
1096 	ops->send_set_epno_network_list_cmd =
1097 				send_set_epno_network_list_cmd_tlv;
1098 	ops->send_extscan_get_capabilities_cmd =
1099 				 send_extscan_get_capabilities_cmd_tlv;
1100 	ops->send_extscan_get_cached_results_cmd =
1101 				send_extscan_get_cached_results_cmd_tlv;
1102 	ops->send_extscan_stop_change_monitor_cmd =
1103 				send_extscan_stop_change_monitor_cmd_tlv;
1104 	ops->send_extscan_start_change_monitor_cmd =
1105 				send_extscan_start_change_monitor_cmd_tlv;
1106 	ops->send_extscan_stop_hotlist_monitor_cmd =
1107 				send_extscan_stop_hotlist_monitor_cmd_tlv;
1108 	ops->send_stop_extscan_cmd = send_stop_extscan_cmd_tlv;
1109 	ops->send_start_extscan_cmd = send_start_extscan_cmd_tlv;
1110 	ops->send_get_buf_extscan_hotlist_cmd =
1111 				send_get_buf_extscan_hotlist_cmd_tlv;
1112 }
1113