blob: 31eb8df56414443fd29ac8064b850d57c2abb1ef [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Abhishek Singh5432c352019-01-02 17:11:44 +05302 * Copyright (c) 2011-2019 The Linux Foundation. All rights reserved.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004 * 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/*
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +053020 * DOC: csr_api_scan.c
21 *
22 * Implementation for the Common Scan interfaces.
23 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080024
25#include "ani_global.h"
26
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080027#include "csr_inside_api.h"
28#include "sme_inside.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080029
30#include "csr_support.h"
31
32#include "host_diag_core_log.h"
33#include "host_diag_core_event.h"
34
35#include "cds_reg_service.h"
36#include "wma_types.h"
37#include "cds_utils.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080038#include "wma.h"
39
Tushnim Bhattacharyya0c4ad2d2017-03-09 15:59:03 -080040#include "wlan_policy_mgr_api.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080041#include "wlan_hdd_main.h"
Agrawal Ashish21ba2572016-09-03 16:40:10 +053042#include "pld_common.h"
yeshwanth sriram guntukadb501222017-01-24 15:21:31 +053043#include "csr_internal.h"
Abhishek Singh6092fbb2017-01-25 18:10:31 +053044#include <wlan_scan_ucfg_api.h>
Abhishek Singhcd131ae2019-04-09 15:05:17 +053045#include <wlan_scan_api.h>
Abhishek Singh6092fbb2017-01-25 18:10:31 +053046#include <wlan_scan_utils_api.h>
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -080047#include <wlan_objmgr_vdev_obj.h>
48#include <wlan_objmgr_pdev_obj.h>
49#include <wlan_utility.h>
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070050#include "wlan_reg_services_api.h"
Wu Gaof3cbeaf2019-01-15 18:26:25 +080051#include "sch_api.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080052
Jeff Johnson70fa7bb2018-12-05 08:27:19 -080053static void csr_set_cfg_valid_channel_list(struct mac_context *mac,
54 uint8_t *pChannelList,
55 uint8_t NumChannels);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080056
Jeff Johnson70fa7bb2018-12-05 08:27:19 -080057static void csr_save_tx_power_to_cfg(struct mac_context *mac,
58 tDblLinkList *pList,
59 uint32_t cfgId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080060
Jeff Johnson70fa7bb2018-12-05 08:27:19 -080061static void csr_set_cfg_country_code(struct mac_context *mac,
62 uint8_t *countryCode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080063
Jeff Johnson70fa7bb2018-12-05 08:27:19 -080064static void csr_purge_channel_power(struct mac_context *mac,
65 tDblLinkList *pChannelList);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080066
Jeff Johnsonedece842018-12-02 11:13:52 -080067static bool csr_roam_is_valid_channel(struct mac_context *mac, uint8_t channel);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080068
Abhishek Singh221cf992018-02-22 13:44:53 +053069/* pResult is invalid calling this function. */
Jeff Johnson8c3ecdd2018-12-05 08:48:54 -080070void csr_free_scan_result_entry(struct mac_context *mac,
71 struct tag_csrscan_result *pResult)
Abhishek Singh221cf992018-02-22 13:44:53 +053072{
Jeff Johnson038efe72019-03-18 13:39:31 -070073 if (pResult->Result.pvIes)
Abhishek Singh221cf992018-02-22 13:44:53 +053074 qdf_mem_free(pResult->Result.pvIes);
75
76 qdf_mem_free(pResult);
77}
78
Jeff Johnsonedece842018-12-02 11:13:52 -080079static QDF_STATUS csr_ll_scan_purge_result(struct mac_context *mac,
Abhishek Singh221cf992018-02-22 13:44:53 +053080 tDblLinkList *pList)
81{
82 QDF_STATUS status = QDF_STATUS_SUCCESS;
83 tListElem *pEntry;
84 struct tag_csrscan_result *pBssDesc;
85
Abhishek Singh221cf992018-02-22 13:44:53 +053086 while ((pEntry = csr_ll_remove_head(pList, LL_ACCESS_NOLOCK)) != NULL) {
87 pBssDesc = GET_BASE_ADDR(pEntry, struct tag_csrscan_result,
88 Link);
Jeff Johnsonc44820d2018-11-22 13:40:38 -080089 csr_free_scan_result_entry(mac, pBssDesc);
Abhishek Singh221cf992018-02-22 13:44:53 +053090 }
91
Abhishek Singh221cf992018-02-22 13:44:53 +053092 return status;
93}
94
Jeff Johnsonedece842018-12-02 11:13:52 -080095QDF_STATUS csr_scan_open(struct mac_context *mac_ctx)
Abhishek Singh221cf992018-02-22 13:44:53 +053096{
Jeff Johnson616417f2018-06-27 10:20:53 -070097 csr_ll_open(&mac_ctx->scan.channelPowerInfoList24);
98 csr_ll_open(&mac_ctx->scan.channelPowerInfoList5G);
Abhishek Singh221cf992018-02-22 13:44:53 +053099
100 return QDF_STATUS_SUCCESS;
101}
102
Jeff Johnsonedece842018-12-02 11:13:52 -0800103QDF_STATUS csr_scan_close(struct mac_context *mac)
Abhishek Singh221cf992018-02-22 13:44:53 +0530104{
Jeff Johnsonc44820d2018-11-22 13:40:38 -0800105 csr_purge_channel_power(mac, &mac->scan.channelPowerInfoList24);
106 csr_purge_channel_power(mac, &mac->scan.channelPowerInfoList5G);
107 csr_ll_close(&mac->scan.channelPowerInfoList24);
108 csr_ll_close(&mac->scan.channelPowerInfoList5G);
Abhishek Singh935e4772018-11-21 14:14:10 +0530109 ucfg_scan_psoc_set_disable(mac->psoc, REASON_SYSTEM_DOWN);
110
Abhishek Singh221cf992018-02-22 13:44:53 +0530111 return QDF_STATUS_SUCCESS;
112}
Jeff Johnson8c3ecdd2018-12-05 08:48:54 -0800113
Jeff Johnsonedece842018-12-02 11:13:52 -0800114QDF_STATUS csr_scan_handle_search_for_ssid(struct mac_context *mac_ctx,
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -0800115 uint32_t session_id)
116{
117 QDF_STATUS status = QDF_STATUS_E_FAILURE;
118 tScanResultHandle hBSSList = CSR_INVALID_SCANRESULT_HANDLE;
119 tCsrScanResultFilter *pScanFilter = NULL;
Jeff Johnson66ee8a92018-03-17 15:24:26 -0700120 struct csr_roam_profile *profile;
gaurank kathpalia14e2f912017-08-31 14:51:45 +0530121 struct csr_roam_session *session;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800122
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -0800123 session = CSR_GET_SESSION(mac_ctx, session_id);
124 if (!session) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700125 sme_err("session %d not found", session_id);
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -0800126 return QDF_STATUS_E_FAILURE;
127 }
128 profile = session->scan_info.profile;
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700129 sme_debug("session %d", session_id);
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -0800130 do {
Will Huangea701062018-06-26 14:03:18 +0800131 /* If this scan is for HDD reassociate */
132 if (mac_ctx->roam.neighborRoamInfo[session_id].
133 uOsRequestedHandoff) {
134 /* notify LFR state m/c */
135 status = csr_neighbor_roam_sssid_scan_done
136 (mac_ctx, session_id, QDF_STATUS_SUCCESS);
137 if (!QDF_IS_STATUS_SUCCESS(status))
138 csr_neighbor_roam_start_lfr_scan(mac_ctx,
139 session_id);
140 status = QDF_STATUS_SUCCESS;
141 break;
142 }
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -0800143 /*
144 * If there is roam command waiting, ignore this roam because
145 * the newer roam command is the one to execute
146 */
147 if (csr_is_roam_command_waiting_for_session(mac_ctx, session_id)) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700148 sme_warn("aborts because roam command waiting");
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -0800149 break;
150 }
Jeff Johnson038efe72019-03-18 13:39:31 -0700151 if (!profile)
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -0800152 break;
153 pScanFilter = qdf_mem_malloc(sizeof(tCsrScanResultFilter));
Jeff Johnson038efe72019-03-18 13:39:31 -0700154 if (!pScanFilter) {
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -0800155 status = QDF_STATUS_E_NOMEM;
156 break;
157 }
158 status = csr_roam_prepare_filter_from_profile(mac_ctx, profile,
159 pScanFilter);
160 if (!QDF_IS_STATUS_SUCCESS(status))
161 break;
162 status = csr_scan_get_result(mac_ctx, pScanFilter, &hBSSList);
163 if (!QDF_IS_STATUS_SUCCESS(status))
164 break;
165 if (mac_ctx->roam.roamSession[session_id].connectState ==
166 eCSR_ASSOC_STATE_TYPE_INFRA_DISCONNECTING) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700167 sme_err("upper layer issued disconnetion");
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -0800168 status = QDF_STATUS_E_FAILURE;
169 break;
170 }
171 status = csr_roam_issue_connect(mac_ctx, session_id, profile,
172 hBSSList, eCsrHddIssued,
173 session->scan_info.roam_id,
174 true, true);
Will Huang8e8d3002018-05-11 10:48:03 +0800175 hBSSList = CSR_INVALID_SCANRESULT_HANDLE;
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -0800176 } while (0);
177
178 if (!QDF_IS_STATUS_SUCCESS(status)) {
179 if (CSR_INVALID_SCANRESULT_HANDLE != hBSSList) {
180 csr_scan_result_purge(mac_ctx, hBSSList);
181 }
182 /* We haven't done anything to this profile */
183 csr_roam_call_callback(mac_ctx, session_id, NULL,
184 session->scan_info.roam_id,
185 eCSR_ROAM_ASSOCIATION_FAILURE,
186 eCSR_ROAM_RESULT_SCAN_FOR_SSID_FAILURE);
187 }
188 if (pScanFilter) {
189 csr_free_scan_filter(mac_ctx, pScanFilter);
190 qdf_mem_free(pScanFilter);
191 }
192 return status;
193}
194
Vignesh Viswanathan014096a2017-12-07 01:24:44 +0530195/**
196 * csr_handle_fils_scan_for_ssid_failure() - Checks and fills FILS seq number
197 * in roam_info structure to send to hdd
198 *
199 * @roam_profile: Pointer to current roam_profile structure
200 * @roam_info: Pointer to roam_info strucure to be filled
201 *
202 * Return: true for FILS connection else false
203 */
204#ifdef WLAN_FEATURE_FILS_SK
Jeff Johnson66ee8a92018-03-17 15:24:26 -0700205static bool
206csr_handle_fils_scan_for_ssid_failure(struct csr_roam_profile *roam_profile,
207 struct csr_roam_info *roam_info)
Vignesh Viswanathan014096a2017-12-07 01:24:44 +0530208{
209 if (roam_profile && roam_profile->fils_con_info &&
210 roam_profile->fils_con_info->is_fils_connection) {
211 sme_debug("send roam_info for FILS connection failure, seq %d",
212 roam_profile->fils_con_info->sequence_number);
213 roam_info->is_fils_connection = true;
214 roam_info->fils_seq_num =
215 roam_profile->fils_con_info->sequence_number;
216 return true;
217 }
218
219 return false;
220}
221#else
Jeff Johnson66ee8a92018-03-17 15:24:26 -0700222static bool
223csr_handle_fils_scan_for_ssid_failure(struct csr_roam_profile *roam_profile,
224 struct csr_roam_info *roam_info)
Vignesh Viswanathan014096a2017-12-07 01:24:44 +0530225{
226 return false;
227}
228#endif
229
Jeff Johnsonedece842018-12-02 11:13:52 -0800230QDF_STATUS csr_scan_handle_search_for_ssid_failure(struct mac_context *mac_ctx,
Jeff Johnson8c3ecdd2018-12-05 08:48:54 -0800231 uint32_t session_id)
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -0800232{
233 QDF_STATUS status = QDF_STATUS_SUCCESS;
Jeff Johnson66ee8a92018-03-17 15:24:26 -0700234 struct csr_roam_profile *profile;
gaurank kathpalia14e2f912017-08-31 14:51:45 +0530235 struct csr_roam_session *session = CSR_GET_SESSION(mac_ctx, session_id);
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -0800236 eCsrRoamResult roam_result;
Vignesh Viswanathan014096a2017-12-07 01:24:44 +0530237 struct csr_roam_info *roam_info = NULL;
238 struct tag_csrscan_result *scan_result;
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -0800239
240 if (!session) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700241 sme_err("session %d not found", session_id);
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -0800242 return QDF_STATUS_E_FAILURE;
243 }
Will Huangea701062018-06-26 14:03:18 +0800244
245 /* If this scan is for HDD reassociate */
246 if (mac_ctx->roam.neighborRoamInfo[session_id].uOsRequestedHandoff) {
247 /* notify LFR state m/c */
248 status = csr_neighbor_roam_sssid_scan_done
249 (mac_ctx, session_id, QDF_STATUS_E_FAILURE);
250 if (!QDF_IS_STATUS_SUCCESS(status))
251 csr_neighbor_roam_start_lfr_scan(mac_ctx, session_id);
252 return QDF_STATUS_SUCCESS;
253 }
254
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -0800255 profile = session->scan_info.profile;
256
257 /*
258 * Check whether it is for start ibss. No need to do anything if it
259 * is a JOIN request
260 */
261 if (profile && CSR_IS_START_IBSS(profile)) {
262 status = csr_roam_issue_connect(mac_ctx, session_id, profile, NULL,
263 eCsrHddIssued, session->scan_info.roam_id,
264 true, true);
265 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700266 sme_err("failed to issue startIBSS, session_id %d status: 0x%08X roam id %d",
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -0800267 session_id, status, session->scan_info.roam_id);
268 csr_roam_call_callback(mac_ctx, session_id, NULL,
269 session->scan_info.roam_id, eCSR_ROAM_FAILED,
270 eCSR_ROAM_RESULT_FAILURE);
271 }
272 return status;
273 }
274 roam_result = eCSR_ROAM_RESULT_FAILURE;
Jeff Johnson038efe72019-03-18 13:39:31 -0700275 if (profile && csr_is_bss_type_ibss(profile->BSSType)) {
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -0800276 roam_result = eCSR_ROAM_RESULT_IBSS_START_FAILED;
277 goto roam_completion;
278 }
Vignesh Viswanathan014096a2017-12-07 01:24:44 +0530279
280 roam_info = qdf_mem_malloc(sizeof(struct csr_roam_info));
Arif Hussain0ef77082018-10-10 16:42:53 -0700281 if (!roam_info)
Vignesh Viswanathan014096a2017-12-07 01:24:44 +0530282 goto roam_completion;
Vignesh Viswanathan014096a2017-12-07 01:24:44 +0530283
284 if (session->scan_info.roambssentry) {
285 scan_result = GET_BASE_ADDR(session->scan_info.roambssentry,
286 struct tag_csrscan_result, Link);
287 roam_info->pBssDesc = &scan_result->Result.BssDescriptor;
288 }
289 roam_info->statusCode = session->joinFailStatusCode.statusCode;
290 roam_info->reasonCode = session->joinFailStatusCode.reasonCode;
291
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -0800292 /* Only indicate assoc_completion if we indicate assoc_start. */
293 if (session->bRefAssocStartCnt > 0) {
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -0800294 session->bRefAssocStartCnt--;
Jeff Johnsoneddf5442017-10-04 10:55:53 -0700295 csr_roam_call_callback(mac_ctx, session_id, roam_info,
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -0800296 session->scan_info.roam_id,
297 eCSR_ROAM_ASSOCIATION_COMPLETION,
298 eCSR_ROAM_RESULT_SCAN_FOR_SSID_FAILURE);
299 } else {
Vignesh Viswanathan014096a2017-12-07 01:24:44 +0530300 if (!csr_handle_fils_scan_for_ssid_failure(
301 profile, roam_info)) {
302 qdf_mem_free(roam_info);
303 roam_info = NULL;
304 }
305 csr_roam_call_callback(mac_ctx, session_id, roam_info,
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -0800306 session->scan_info.roam_id,
307 eCSR_ROAM_ASSOCIATION_FAILURE,
308 eCSR_ROAM_RESULT_SCAN_FOR_SSID_FAILURE);
309 }
Vignesh Viswanathan014096a2017-12-07 01:24:44 +0530310
311 if (roam_info)
312 qdf_mem_free(roam_info);
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -0800313roam_completion:
314 csr_roam_completion(mac_ctx, session_id, NULL, NULL, roam_result,
315 false);
316 return status;
317}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800318
Jeff Johnsonedece842018-12-02 11:13:52 -0800319QDF_STATUS csr_scan_result_purge(struct mac_context *mac,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800320 tScanResultHandle hScanList)
321{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530322 QDF_STATUS status = QDF_STATUS_E_INVAL;
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +0530323 struct scan_result_list *pScanList =
324 (struct scan_result_list *) hScanList;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800325
326 if (pScanList) {
Jeff Johnsonc44820d2018-11-22 13:40:38 -0800327 status = csr_ll_scan_purge_result(mac, &pScanList->List);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800328 csr_ll_close(&pScanList->List);
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530329 qdf_mem_free(pScanList);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800330 }
331 return status;
332}
333
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800334/* Add the channel to the occupiedChannels array */
Jianmin Zhu8d7afc22019-04-17 13:10:22 +0800335static void csr_add_to_occupied_channels(struct mac_context *mac,
336 uint8_t ch,
337 uint8_t sessionId,
338 struct csr_channel *occupied_ch,
339 bool is_init_list)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800340{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530341 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800342 uint8_t num_occupied_ch = occupied_ch->numChannels;
343 uint8_t *occupied_ch_lst = occupied_ch->channelList;
344
Kapil Gupta0a2477b2016-08-23 18:00:34 +0530345 if (is_init_list)
Jeff Johnsonc44820d2018-11-22 13:40:38 -0800346 mac->scan.roam_candidate_count[sessionId]++;
Kapil Gupta0a2477b2016-08-23 18:00:34 +0530347
348 if (csr_is_channel_present_in_list(occupied_ch_lst,
349 num_occupied_ch, ch))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800350 return;
351
352 status = csr_add_to_channel_list_front(occupied_ch_lst,
353 num_occupied_ch, ch);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530354 if (QDF_IS_STATUS_SUCCESS(status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800355 occupied_ch->numChannels++;
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700356 sme_debug("Added channel %d to the list (count=%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800357 ch, occupied_ch->numChannels);
358 if (occupied_ch->numChannels >
359 CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN)
360 occupied_ch->numChannels =
361 CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN;
362 }
363}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800364
365/* Put the BSS into the scan result list */
366/* pIes can not be NULL */
Jeff Johnsonedece842018-12-02 11:13:52 -0800367static void csr_scan_add_result(struct mac_context *mac_ctx,
Abhishek Singhf723e3d2018-02-20 18:02:37 +0530368 struct tag_csrscan_result *pResult)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800369{
Abhishek Singh6f56d212017-04-12 14:31:57 +0530370 qdf_nbuf_t buf;
371 uint8_t *data;
372 struct mgmt_rx_event_params rx_param = {0};
373 struct wlan_frame_hdr *hdr;
374 struct wlan_bcn_frame *fixed_frame;
Abhishek Singhf05b0cb62018-02-20 18:06:13 +0530375 uint32_t buf_len, i;
Abhishek Singh6f56d212017-04-12 14:31:57 +0530376 tSirBssDescription *bss_desc;
377 enum mgmt_frame_type frm_type = MGMT_BEACON;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800378
Abhishek Singhf723e3d2018-02-20 18:02:37 +0530379 if (!pResult) {
380 sme_err("pResult is null");
381 return;
382 }
383
Abhishek Singh6f56d212017-04-12 14:31:57 +0530384 bss_desc = &pResult->Result.BssDescriptor;
385 if (bss_desc->fProbeRsp)
386 frm_type = MGMT_PROBE_RESP;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800387
Abhishek Singh6f56d212017-04-12 14:31:57 +0530388 rx_param.pdev_id = 0;
389 rx_param.channel = bss_desc->channelId;
390 rx_param.rssi = bss_desc->rssi;
391 rx_param.tsf_delta = bss_desc->tsf_delta;
Abhishek Singhf723e3d2018-02-20 18:02:37 +0530392
Abhishek Singhf05b0cb62018-02-20 18:06:13 +0530393 /* Set all per chain rssi as invalid */
394 for (i = 0; i < WLAN_MGMT_TXRX_HOST_MAX_ANTENNA; i++)
395 rx_param.rssi_ctl[i] = WLAN_INVALID_PER_CHAIN_RSSI;
396
Abhishek Singh6f56d212017-04-12 14:31:57 +0530397 buf_len = GET_IE_LEN_IN_BSS(bss_desc->length) +
398 + offsetof(struct wlan_bcn_frame, ie) + sizeof(*hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800399
Abhishek Singh6f56d212017-04-12 14:31:57 +0530400 buf = qdf_nbuf_alloc(NULL, qdf_roundup(buf_len, 4),
401 0, 4, false);
Arif Hussain0ef77082018-10-10 16:42:53 -0700402 if (!buf)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800403 return;
Arif Hussain0ef77082018-10-10 16:42:53 -0700404
Abhishek Singh6f56d212017-04-12 14:31:57 +0530405 qdf_nbuf_put_tail(buf, buf_len);
406 qdf_nbuf_set_protocol(buf, ETH_P_CONTROL);
407
408 data = qdf_nbuf_data(buf);
409 hdr = (struct wlan_frame_hdr *) data;
410 qdf_mem_copy(hdr->i_addr3, bss_desc->bssId, QDF_MAC_ADDR_SIZE);
411 qdf_mem_copy(hdr->i_addr2, bss_desc->bssId, QDF_MAC_ADDR_SIZE);
412 qdf_mem_copy(hdr->i_seq,
413 &bss_desc->seq_ctrl, sizeof(uint16_t));
414
415 data += sizeof(*hdr);
416 fixed_frame = (struct wlan_bcn_frame *)data;
417 qdf_mem_copy(fixed_frame->timestamp,
418 bss_desc->timeStamp, 8);
419 fixed_frame->beacon_interval = bss_desc->beaconInterval;
420 fixed_frame->capability.value = bss_desc->capabilityInfo;
421 data += offsetof(struct wlan_bcn_frame, ie);
422
423 qdf_mem_copy(data, bss_desc->ieFields,
424 GET_IE_LEN_IN_BSS(bss_desc->length));
Abhishek Singhcd131ae2019-04-09 15:05:17 +0530425 wlan_scan_process_bcn_probe_rx_sync(mac_ctx->psoc, buf, &rx_param,
426 frm_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800427}
428
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800429/*
430 * NOTE: This routine is being added to make
431 * sure that scan results are not being flushed
432 * while roaming. If the scan results are flushed,
433 * we are unable to recover from
434 * csr_roam_roaming_state_disassoc_rsp_processor.
435 * If it is needed to remove this routine,
436 * first ensure that we recover gracefully from
437 * csr_roam_roaming_state_disassoc_rsp_processor if
438 * csr_scan_get_result returns with a failure because
439 * of not being able to find the roaming BSS.
440 */
Jeff Johnsonedece842018-12-02 11:13:52 -0800441static bool csr_scan_flush_denied(struct mac_context *mac)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800442{
443 uint8_t sessionId;
444
Dustin Brownad06be62019-02-04 14:52:56 -0800445 for (sessionId = 0; sessionId < WLAN_MAX_VDEVS; sessionId++) {
Jeff Johnsonc44820d2018-11-22 13:40:38 -0800446 if (CSR_IS_SESSION_VALID(mac, sessionId)) {
447 if (csr_neighbor_middle_of_roaming(mac, sessionId))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800448 return 1;
449 }
450 }
451 return 0;
452}
453
Jeff Johnsonedece842018-12-02 11:13:52 -0800454static bool csr_scan_save_bss_description(struct mac_context *mac,
Jeff Johnson8c3ecdd2018-12-05 08:48:54 -0800455 tSirBssDescription *pBSSDescription)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800456{
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +0530457 struct tag_csrscan_result *pCsrBssDescription = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800458 uint32_t cbBSSDesc;
459 uint32_t cbAllocated;
460
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +0530461 /* figure out how big the BSS description is (the BSSDesc->length does
462 * NOT include the size of the length field itself).
463 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800464 cbBSSDesc = pBSSDescription->length + sizeof(pBSSDescription->length);
465
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +0530466 cbAllocated = sizeof(struct tag_csrscan_result) + cbBSSDesc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800467
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530468 pCsrBssDescription = qdf_mem_malloc(cbAllocated);
Arif Hussain0ef77082018-10-10 16:42:53 -0700469 if (!pCsrBssDescription)
Abhishek Singha92cf1e2017-11-02 17:04:11 +0530470 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800471
Abhishek Singha92cf1e2017-11-02 17:04:11 +0530472 pCsrBssDescription->AgingCount =
Jeff Johnsonc44820d2018-11-22 13:40:38 -0800473 (int32_t) mac->roam.configParam.agingCount;
Abhishek Singha92cf1e2017-11-02 17:04:11 +0530474 sme_debug(
Srinivas Girigowdacb7b8b82019-04-10 14:27:47 -0700475 "Set Aging Count = %d for BSS " QDF_MAC_ADDR_STR " ",
Abhishek Singha92cf1e2017-11-02 17:04:11 +0530476 pCsrBssDescription->AgingCount,
Srinivas Girigowda34fbba02019-04-08 12:07:44 -0700477 QDF_MAC_ADDR_ARRAY(pCsrBssDescription->Result.BssDescriptor.
Abhishek Singha92cf1e2017-11-02 17:04:11 +0530478 bssId));
479 qdf_mem_copy(&pCsrBssDescription->Result.BssDescriptor,
480 pBSSDescription, cbBSSDesc);
Jeff Johnsonc44820d2018-11-22 13:40:38 -0800481 csr_scan_add_result(mac, pCsrBssDescription);
482 csr_free_scan_result_entry(mac, pCsrBssDescription);
Abhishek Singha92cf1e2017-11-02 17:04:11 +0530483
484 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800485}
486
487/* Append a Bss Description... */
Jeff Johnsonedece842018-12-02 11:13:52 -0800488bool csr_scan_append_bss_description(struct mac_context *mac,
Abhishek Singhf723e3d2018-02-20 18:02:37 +0530489 tSirBssDescription *pSirBssDescription)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800490{
Jeff Johnson8c3ecdd2018-12-05 08:48:54 -0800491 return csr_scan_save_bss_description(mac, pSirBssDescription);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800492}
493
Jeff Johnson8c3ecdd2018-12-05 08:48:54 -0800494static void csr_purge_channel_power(struct mac_context *mac,
495 tDblLinkList *pChannelList)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800496{
gaurank kathpalia14e2f912017-08-31 14:51:45 +0530497 struct csr_channel_powerinfo *pChannelSet;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800498 tListElem *pEntry;
499
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800500 /*
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +0530501 * Remove the channel sets from the learned list and put them
502 * in the free list
503 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800504 while ((pEntry = csr_ll_remove_head(pChannelList,
505 LL_ACCESS_NOLOCK)) != NULL) {
gaurank kathpalia14e2f912017-08-31 14:51:45 +0530506 pChannelSet = GET_BASE_ADDR(pEntry,
507 struct csr_channel_powerinfo, link);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800508 if (pChannelSet)
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530509 qdf_mem_free(pChannelSet);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800510 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800511}
512
513/*
514 * Save the channelList into the ultimate storage as the final stage of channel
515 * Input: pCountryInfo -- the country code (e.g. "USI"), channel list, and power
516 * limit are all stored inside this data structure
517 */
Jeff Johnsonedece842018-12-02 11:13:52 -0800518QDF_STATUS csr_save_to_channel_power2_g_5_g(struct mac_context *mac,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800519 uint32_t tableSize,
520 tSirMacChanInfo *channelTable)
521{
522 uint32_t i = tableSize / sizeof(tSirMacChanInfo);
523 tSirMacChanInfo *pChannelInfo;
gaurank kathpalia14e2f912017-08-31 14:51:45 +0530524 struct csr_channel_powerinfo *pChannelSet;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800525 bool f2GHzInfoFound = false;
526 bool f2GListPurged = false, f5GListPurged = false;
527
528 pChannelInfo = channelTable;
529 /* atleast 3 bytes have to be remaining -- from "countryString" */
530 while (i--) {
gaurank kathpalia14e2f912017-08-31 14:51:45 +0530531 pChannelSet = qdf_mem_malloc(sizeof(struct csr_channel_powerinfo));
Jeff Johnson038efe72019-03-18 13:39:31 -0700532 if (!pChannelSet) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800533 pChannelInfo++;
534 continue;
535 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800536 pChannelSet->firstChannel = pChannelInfo->firstChanNum;
537 pChannelSet->numChannels = pChannelInfo->numChannels;
538 /*
539 * Now set the inter-channel offset based on the frequency band
540 * the channel set lies in
541 */
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700542 if ((WLAN_REG_IS_24GHZ_CH(pChannelSet->firstChannel)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800543 ((pChannelSet->firstChannel +
544 (pChannelSet->numChannels - 1)) <=
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700545 WLAN_REG_MAX_24GHZ_CH_NUM)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800546 pChannelSet->interChannelOffset = 1;
547 f2GHzInfoFound = true;
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700548 } else if ((WLAN_REG_IS_5GHZ_CH(pChannelSet->firstChannel))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800549 && ((pChannelSet->firstChannel +
550 ((pChannelSet->numChannels - 1) * 4)) <=
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700551 WLAN_REG_MAX_5GHZ_CH_NUM)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800552 pChannelSet->interChannelOffset = 4;
553 f2GHzInfoFound = false;
554 } else {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700555 sme_warn("Invalid Channel %d Present in Country IE",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800556 pChannelSet->firstChannel);
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530557 qdf_mem_free(pChannelSet);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530558 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800559 }
Anurag Chouhan6d760662016-02-20 16:05:43 +0530560 pChannelSet->txPower = QDF_MIN(pChannelInfo->maxTxPower,
Wu Gao5f764082019-01-04 15:54:38 +0800561 mac->mlme_cfg->power.max_tx_power);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800562 if (f2GHzInfoFound) {
563 if (!f2GListPurged) {
564 /* purge previous results if found new */
Jeff Johnsonc44820d2018-11-22 13:40:38 -0800565 csr_purge_channel_power(mac,
566 &mac->scan.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800567 channelPowerInfoList24);
568 f2GListPurged = true;
569 }
Jeff Johnsonc44820d2018-11-22 13:40:38 -0800570 if (CSR_IS_OPERATING_BG_BAND(mac)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800571 /* add to the list of 2.4 GHz channel sets */
Jeff Johnsonc44820d2018-11-22 13:40:38 -0800572 csr_ll_insert_tail(&mac->scan.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800573 channelPowerInfoList24,
574 &pChannelSet->link,
575 LL_ACCESS_LOCK);
576 } else {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700577 sme_debug(
578 "Adding 11B/G ch in 11A. 1st ch %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800579 pChannelSet->firstChannel);
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530580 qdf_mem_free(pChannelSet);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800581 }
582 } else {
583 /* 5GHz info found */
584 if (!f5GListPurged) {
585 /* purge previous results if found new */
Jeff Johnsonc44820d2018-11-22 13:40:38 -0800586 csr_purge_channel_power(mac,
587 &mac->scan.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800588 channelPowerInfoList5G);
589 f5GListPurged = true;
590 }
Jeff Johnsonc44820d2018-11-22 13:40:38 -0800591 if (CSR_IS_OPERATING_A_BAND(mac)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800592 /* add to the list of 5GHz channel sets */
Jeff Johnsonc44820d2018-11-22 13:40:38 -0800593 csr_ll_insert_tail(&mac->scan.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800594 channelPowerInfoList5G,
595 &pChannelSet->link,
596 LL_ACCESS_LOCK);
597 } else {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700598 sme_debug(
599 "Adding 11A ch in B/G. 1st ch %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800600 pChannelSet->firstChannel);
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530601 qdf_mem_free(pChannelSet);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800602 }
603 }
604 pChannelInfo++; /* move to next entry */
605 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530606 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800607}
608
Jeff Johnsonedece842018-12-02 11:13:52 -0800609void csr_apply_power2_current(struct mac_context *mac)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800610{
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700611 sme_debug("Updating Cfg with power settings");
Jeff Johnsonc44820d2018-11-22 13:40:38 -0800612 csr_save_tx_power_to_cfg(mac, &mac->scan.channelPowerInfoList24,
gaurank kathpalia3d2e3852018-10-03 22:03:23 +0530613 BAND_2G);
Jeff Johnsonc44820d2018-11-22 13:40:38 -0800614 csr_save_tx_power_to_cfg(mac, &mac->scan.channelPowerInfoList5G,
gaurank kathpalia3d2e3852018-10-03 22:03:23 +0530615 BAND_5G);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800616}
617
Jeff Johnsonedece842018-12-02 11:13:52 -0800618void csr_apply_channel_power_info_to_fw(struct mac_context *mac_ctx,
Jeff Johnson8c3ecdd2018-12-05 08:48:54 -0800619 struct csr_channel *ch_lst,
620 uint8_t *countryCode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800621{
622 int i;
623 uint8_t num_ch = 0;
624 uint8_t tempNumChannels = 0;
gaurank kathpalia14e2f912017-08-31 14:51:45 +0530625 struct csr_channel tmp_ch_lst;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800626
627 if (ch_lst->numChannels) {
Srinivas Girigowda98234532019-03-11 15:31:12 -0700628 tempNumChannels = QDF_MIN(ch_lst->numChannels,
Wu Gao0821b0d2019-01-11 17:31:11 +0800629 CFG_VALID_CHANNEL_LIST_LEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800630 for (i = 0; i < tempNumChannels; i++) {
631 tmp_ch_lst.channelList[num_ch] = ch_lst->channelList[i];
632 num_ch++;
633 }
634 tmp_ch_lst.numChannels = num_ch;
635 /* Store the channel+power info in the global place: Cfg */
636 csr_apply_power2_current(mac_ctx);
637 csr_set_cfg_valid_channel_list(mac_ctx, tmp_ch_lst.channelList,
638 tmp_ch_lst.numChannels);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800639 } else {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700640 sme_err("11D channel list is empty");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800641 }
642 csr_set_cfg_country_code(mac_ctx, countryCode);
643}
644
645#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
Jeff Johnsonedece842018-12-02 11:13:52 -0800646static void csr_diag_reset_country_information(struct mac_context *mac)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800647{
648
649 host_log_802_11d_pkt_type *p11dLog;
650 int Index;
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +0530651
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800652 WLAN_HOST_DIAG_LOG_ALLOC(p11dLog, host_log_802_11d_pkt_type,
653 LOG_WLAN_80211D_C);
654 if (!p11dLog)
655 return;
656
657 p11dLog->eventId = WLAN_80211D_EVENT_RESET;
Jeff Johnsonc44820d2018-11-22 13:40:38 -0800658 qdf_mem_copy(p11dLog->countryCode, mac->scan.countryCodeCurrent, 3);
659 p11dLog->numChannel = mac->scan.base_channels.numChannels;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800660 if (p11dLog->numChannel <= HOST_LOG_MAX_NUM_CHANNEL) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530661 qdf_mem_copy(p11dLog->Channels,
Jeff Johnsonc44820d2018-11-22 13:40:38 -0800662 mac->scan.base_channels.channelList,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800663 p11dLog->numChannel);
664 for (Index = 0;
Jeff Johnsonc44820d2018-11-22 13:40:38 -0800665 Index < mac->scan.base_channels.numChannels;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800666 Index++) {
Anurag Chouhan6d760662016-02-20 16:05:43 +0530667 p11dLog->TxPwr[Index] = QDF_MIN(
Jeff Johnsonc44820d2018-11-22 13:40:38 -0800668 mac->scan.defaultPowerTable[Index].tx_power,
Wu Gao5f764082019-01-04 15:54:38 +0800669 mac->mlme_cfg->power.max_tx_power);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800670 }
671 }
Abhinav Kumard4d6eb72018-12-04 20:30:37 +0530672 if (!mac->mlme_cfg->gen.enabled_11d)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800673 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
674 else
675 p11dLog->supportMultipleDomain =
676 WLAN_80211D_SUPPORT_MULTI_DOMAIN;
677 WLAN_HOST_DIAG_LOG_REPORT(p11dLog);
678}
679#endif /* FEATURE_WLAN_DIAG_SUPPORT_CSR */
680
681/**
682 * csr_apply_channel_power_info_wrapper() - sends channel info to fw
Jeff Johnsonc44820d2018-11-22 13:40:38 -0800683 * @mac: main MAC data structure
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800684 *
685 * This function sends the channel power info to firmware
686 *
687 * Return: none
688 */
Jeff Johnsonedece842018-12-02 11:13:52 -0800689void csr_apply_channel_power_info_wrapper(struct mac_context *mac)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800690{
691
692#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
Jeff Johnsonc44820d2018-11-22 13:40:38 -0800693 csr_diag_reset_country_information(mac);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800694#endif /* FEATURE_WLAN_DIAG_SUPPORT_CSR */
Jeff Johnsonc44820d2018-11-22 13:40:38 -0800695 csr_prune_channel_list_for_mode(mac, &mac->scan.base_channels);
696 csr_save_channel_power_for_band(mac, false);
697 csr_save_channel_power_for_band(mac, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800698 /* apply the channel list, power settings, and the country code. */
Jeff Johnsonc44820d2018-11-22 13:40:38 -0800699 csr_apply_channel_power_info_to_fw(mac,
700 &mac->scan.base_channels, mac->scan.countryCodeCurrent);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800701 /* clear the 11d channel list */
hangtian127c9532019-01-12 13:29:07 +0800702 qdf_mem_zero(&mac->scan.channels11d, sizeof(mac->scan.channels11d));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800703}
704
Qiwei Caiba95ce62018-08-23 10:43:16 +0800705#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800706/* caller allocated memory for pNumChn and pChnPowerInfo */
707/* As input, *pNumChn has the size of the array of pChnPowerInfo */
708/* Upon return, *pNumChn has the number of channels assigned. */
Jeff Johnson8c3ecdd2018-12-05 08:48:54 -0800709static void csr_get_channel_power_info(struct mac_context *mac,
710 tDblLinkList *list,
Jeff Johnson00fa67d2016-10-14 08:07:36 -0700711 uint32_t *num_ch,
712 struct channel_power *chn_pwr_info)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800713{
714 tListElem *entry;
715 uint32_t chn_idx = 0, idx;
gaurank kathpalia14e2f912017-08-31 14:51:45 +0530716 struct csr_channel_powerinfo *ch_set;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800717
718 /* Get 2.4Ghz first */
719 entry = csr_ll_peek_head(list, LL_ACCESS_LOCK);
720 while (entry && (chn_idx < *num_ch)) {
gaurank kathpalia14e2f912017-08-31 14:51:45 +0530721 ch_set = GET_BASE_ADDR(entry,
722 struct csr_channel_powerinfo, link);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800723 for (idx = 0; (idx < ch_set->numChannels)
724 && (chn_idx < *num_ch); idx++) {
Amar Singhala297bfa2015-10-15 15:07:29 -0700725 chn_pwr_info[chn_idx].chan_num =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800726 (uint8_t) (ch_set->firstChannel
727 + (idx * ch_set->interChannelOffset));
Amar Singhal5cccafe2017-02-15 12:42:58 -0800728 chn_pwr_info[chn_idx++].tx_power = ch_set->txPower;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800729 }
730 entry = csr_ll_next(list, entry, LL_ACCESS_LOCK);
731 }
732 *num_ch = chn_idx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800733}
734
Jeff Johnsonedece842018-12-02 11:13:52 -0800735static void csr_diag_apply_country_info(struct mac_context *mac_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800736{
737 host_log_802_11d_pkt_type *p11dLog;
Wu Gao0821b0d2019-01-11 17:31:11 +0800738 struct channel_power chnPwrInfo[CFG_VALID_CHANNEL_LIST_LEN];
739 uint32_t nChnInfo = CFG_VALID_CHANNEL_LIST_LEN, nTmp;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800740
741 WLAN_HOST_DIAG_LOG_ALLOC(p11dLog, host_log_802_11d_pkt_type,
742 LOG_WLAN_80211D_C);
743 if (!p11dLog)
744 return;
745
746 p11dLog->eventId = WLAN_80211D_EVENT_COUNTRY_SET;
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530747 qdf_mem_copy(p11dLog->countryCode, mac_ctx->scan.countryCode11d, 3);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800748 p11dLog->numChannel = mac_ctx->scan.channels11d.numChannels;
749 if (p11dLog->numChannel > HOST_LOG_MAX_NUM_CHANNEL)
750 goto diag_end;
751
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530752 qdf_mem_copy(p11dLog->Channels,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800753 mac_ctx->scan.channels11d.channelList,
754 p11dLog->numChannel);
755 csr_get_channel_power_info(mac_ctx,
756 &mac_ctx->scan.channelPowerInfoList24,
757 &nChnInfo, chnPwrInfo);
758 nTmp = nChnInfo;
Wu Gao0821b0d2019-01-11 17:31:11 +0800759 nChnInfo = CFG_VALID_CHANNEL_LIST_LEN - nTmp;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800760 csr_get_channel_power_info(mac_ctx,
761 &mac_ctx->scan.channelPowerInfoList5G,
762 &nChnInfo, &chnPwrInfo[nTmp]);
763 for (nTmp = 0; nTmp < p11dLog->numChannel; nTmp++) {
764 for (nChnInfo = 0;
Wu Gao0821b0d2019-01-11 17:31:11 +0800765 nChnInfo < CFG_VALID_CHANNEL_LIST_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800766 nChnInfo++) {
767 if (p11dLog->Channels[nTmp] ==
Amar Singhala297bfa2015-10-15 15:07:29 -0700768 chnPwrInfo[nChnInfo].chan_num) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800769 p11dLog->TxPwr[nTmp] =
Amar Singhal5cccafe2017-02-15 12:42:58 -0800770 chnPwrInfo[nChnInfo].tx_power;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800771 break;
772 }
773 }
774 }
775diag_end:
Abhinav Kumard4d6eb72018-12-04 20:30:37 +0530776 if (!mac_ctx->mlme_cfg->gen.enabled_11d)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800777 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
778 else
779 p11dLog->supportMultipleDomain =
780 WLAN_80211D_SUPPORT_MULTI_DOMAIN;
781 WLAN_HOST_DIAG_LOG_REPORT(p11dLog);
782}
783#endif /* #ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR */
784
785/**
786 * csr_apply_country_information() - apply country code information
Jeff Johnsonc44820d2018-11-22 13:40:38 -0800787 * @mac: core MAC data structure
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800788 *
789 * This function programs the new country code
790 *
791 * Return: none
792 */
Jeff Johnsonedece842018-12-02 11:13:52 -0800793void csr_apply_country_information(struct mac_context *mac)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800794{
795 v_REGDOMAIN_t domainId;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530796 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800797
Jeff Johnsonc44820d2018-11-22 13:40:38 -0800798 if (!wlan_reg_11d_enabled_on_host(mac->psoc))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800799 return;
Jeff Johnsonc44820d2018-11-22 13:40:38 -0800800 status = csr_get_regulatory_domain_for_country(mac,
801 mac->scan.countryCode11d, &domainId, SOURCE_QUERY);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530802 if (!QDF_IS_STATUS_SUCCESS(status))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800803 return;
804 /* Check whether we need to enforce default domain */
805#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
Jeff Johnsonc44820d2018-11-22 13:40:38 -0800806 csr_diag_apply_country_info(mac);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800807#endif /* #ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR */
808
Jeff Johnsonc44820d2018-11-22 13:40:38 -0800809 if (mac->scan.domainIdCurrent != domainId)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800810 return;
Jeff Johnsonc44820d2018-11-22 13:40:38 -0800811 if (mac->scan.domainIdCurrent != domainId) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700812 sme_debug("Domain Changed Old %d, new %d",
Jeff Johnsonc44820d2018-11-22 13:40:38 -0800813 mac->scan.domainIdCurrent, domainId);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700814 if (domainId >= REGDOMAIN_COUNT)
815 sme_err("fail to set regId %d", domainId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800816 }
Jeff Johnsonc44820d2018-11-22 13:40:38 -0800817 mac->scan.domainIdCurrent = domainId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800818 /* switch to active scans using this new channel list */
Jeff Johnsonc44820d2018-11-22 13:40:38 -0800819 mac->scan.curScanType = eSIR_ACTIVE_SCAN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800820}
821
Jeff Johnsonedece842018-12-02 11:13:52 -0800822void csr_save_channel_power_for_band(struct mac_context *mac, bool fill_5f)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800823{
824 uint32_t idx, count = 0;
825 tSirMacChanInfo *chan_info;
826 tSirMacChanInfo *ch_info_start;
827 int32_t max_ch_idx;
828 bool tmp_bool;
829 uint8_t ch = 0;
830
831 max_ch_idx =
Jeff Johnsonc44820d2018-11-22 13:40:38 -0800832 (mac->scan.base_channels.numChannels <
Wu Gao0821b0d2019-01-11 17:31:11 +0800833 CFG_VALID_CHANNEL_LIST_LEN) ?
Jeff Johnsonc44820d2018-11-22 13:40:38 -0800834 mac->scan.base_channels.numChannels :
Wu Gao0821b0d2019-01-11 17:31:11 +0800835 CFG_VALID_CHANNEL_LIST_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800836
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530837 chan_info = qdf_mem_malloc(sizeof(tSirMacChanInfo) *
Wu Gao0821b0d2019-01-11 17:31:11 +0800838 CFG_VALID_CHANNEL_LIST_LEN);
Jeff Johnson038efe72019-03-18 13:39:31 -0700839 if (!chan_info)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800840 return;
841
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800842 ch_info_start = chan_info;
843 for (idx = 0; idx < max_ch_idx; idx++) {
Jeff Johnsonc44820d2018-11-22 13:40:38 -0800844 ch = mac->scan.defaultPowerTable[idx].chan_num;
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700845 tmp_bool = (fill_5f && WLAN_REG_IS_5GHZ_CH(ch)) ||
846 (!fill_5f && WLAN_REG_IS_24GHZ_CH(ch));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800847 if (!tmp_bool)
848 continue;
849
Wu Gao0821b0d2019-01-11 17:31:11 +0800850 if (count >= CFG_VALID_CHANNEL_LIST_LEN) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700851 sme_warn("count: %d exceeded", count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800852 break;
853 }
854
855 chan_info->firstChanNum =
Jeff Johnsonc44820d2018-11-22 13:40:38 -0800856 mac->scan.defaultPowerTable[idx].chan_num;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800857 chan_info->numChannels = 1;
858 chan_info->maxTxPower =
Jeff Johnsonc44820d2018-11-22 13:40:38 -0800859 QDF_MIN(mac->scan.defaultPowerTable[idx].tx_power,
Wu Gao5f764082019-01-04 15:54:38 +0800860 mac->mlme_cfg->power.max_tx_power);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800861 chan_info++;
862 count++;
863 }
864 if (count) {
Jeff Johnsonc44820d2018-11-22 13:40:38 -0800865 csr_save_to_channel_power2_g_5_g(mac,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800866 count * sizeof(tSirMacChanInfo), ch_info_start);
867 }
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530868 qdf_mem_free(ch_info_start);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800869}
870
Jeff Johnsonedece842018-12-02 11:13:52 -0800871bool csr_is_supported_channel(struct mac_context *mac, uint8_t channelId)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800872{
873 bool fRet = false;
874 uint32_t i;
875
Jeff Johnsonc44820d2018-11-22 13:40:38 -0800876 for (i = 0; i < mac->scan.base_channels.numChannels; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800877 if (channelId ==
Jeff Johnsonc44820d2018-11-22 13:40:38 -0800878 mac->scan.base_channels.channelList[i]) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800879 fRet = true;
880 break;
881 }
882 }
883
884 return fRet;
885}
886
887/*
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +0530888 * 802.11D only: Gather 11d IE via beacon or Probe response and store them in
889 * pAdapter->channels11d
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800890 */
Jeff Johnsonedece842018-12-02 11:13:52 -0800891bool csr_learn_11dcountry_information(struct mac_context *mac,
Jeff Johnson8c3ecdd2018-12-05 08:48:54 -0800892 tSirBssDescription *pSirBssDesc,
893 tDot11fBeaconIEs *pIes, bool fForce)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800894{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530895 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800896 uint8_t *pCountryCodeSelected;
897 bool fRet = false;
898 v_REGDOMAIN_t domainId;
899 tDot11fBeaconIEs *pIesLocal = pIes;
900 bool useVoting = false;
901
Jeff Johnson038efe72019-03-18 13:39:31 -0700902 if ((!pSirBssDesc) && (!pIes))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800903 useVoting = true;
904
905 /* check if .11d support is enabled */
Jeff Johnsonc44820d2018-11-22 13:40:38 -0800906 if (!wlan_reg_11d_enabled_on_host(mac->psoc))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800907 goto free_ie;
908
909 if (false == useVoting) {
910 if (!pIesLocal &&
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530911 (!QDF_IS_STATUS_SUCCESS(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800912 csr_get_parsed_bss_description_ies(
Jeff Johnsonc44820d2018-11-22 13:40:38 -0800913 mac, pSirBssDesc, &pIesLocal))))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800914 goto free_ie;
915 /* check if country information element is present */
916 if (!pIesLocal->Country.present)
917 /* No country info */
918 goto free_ie;
Jeff Johnsonc44820d2018-11-22 13:40:38 -0800919 status = csr_get_regulatory_domain_for_country(mac,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800920 pIesLocal->Country.country, &domainId,
Amar Singhala297bfa2015-10-15 15:07:29 -0700921 SOURCE_QUERY);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530922 if (QDF_IS_STATUS_SUCCESS(status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800923 && (domainId == REGDOMAIN_WORLD))
924 goto free_ie;
925 } /* useVoting == false */
926
927 if (false == useVoting)
928 pCountryCodeSelected = pIesLocal->Country.country;
929 else
Jeff Johnsonc44820d2018-11-22 13:40:38 -0800930 pCountryCodeSelected = mac->scan.countryCodeElected;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800931
Jeff Johnsonc44820d2018-11-22 13:40:38 -0800932 if (qdf_mem_cmp(pCountryCodeSelected, mac->scan.countryCodeCurrent,
Amar Singhalb6d0dc42016-10-19 09:45:05 -0700933 CDS_COUNTRY_CODE_LEN) == 0) {
Jeff Johnsonc44820d2018-11-22 13:40:38 -0800934 qdf_mem_copy(mac->scan.countryCode11d,
935 mac->scan.countryCodeCurrent,
Amar Singhalb6d0dc42016-10-19 09:45:05 -0700936 CDS_COUNTRY_CODE_LEN);
Amar Singhal9d5b1fe2016-10-16 20:16:05 -0700937 goto free_ie;
Amar Singhalb6d0dc42016-10-19 09:45:05 -0700938 }
Amar Singhal9d5b1fe2016-10-16 20:16:05 -0700939
Jeff Johnsonc44820d2018-11-22 13:40:38 -0800940 mac->reg_hint_src = SOURCE_11D;
941 status = csr_get_regulatory_domain_for_country(mac,
Amar Singhala297bfa2015-10-15 15:07:29 -0700942 pCountryCodeSelected, &domainId, SOURCE_11D);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530943 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700944 sme_err("fail to get regId %d", domainId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800945 fRet = false;
946 goto free_ie;
947 }
948
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800949 fRet = true;
950free_ie:
951 if (!pIes && pIesLocal) {
952 /* locally allocated */
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530953 qdf_mem_free(pIesLocal);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800954 }
955 return fRet;
956}
957
Jeff Johnson8c3ecdd2018-12-05 08:48:54 -0800958static enum csr_scancomplete_nextcommand
959csr_scan_get_next_command_state(struct mac_context *mac_ctx,
960 uint32_t session_id,
961 eCsrScanStatus scan_status,
962 uint8_t *chan)
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -0800963{
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +0530964 enum csr_scancomplete_nextcommand NextCommand = eCsrNextScanNothing;
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -0800965 int8_t channel;
gaurank kathpalia14e2f912017-08-31 14:51:45 +0530966 struct csr_roam_session *session;
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -0800967
Krunal Soni35a94532018-01-09 10:54:31 -0800968 if (!CSR_IS_SESSION_VALID(mac_ctx, session_id)) {
969 sme_err("session %d is invalid", session_id);
970 return NextCommand;
971 }
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -0800972 session = CSR_GET_SESSION(mac_ctx, session_id);
973 switch (session->scan_info.scan_reason) {
974 case eCsrScanForSsid:
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700975 sme_debug("Resp for Scan For Ssid");
Liangwei Dong1ba99482018-10-19 02:57:29 -0400976 channel = csr_scan_get_channel_for_hw_mode_change(
977 mac_ctx,
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -0800978 session_id,
979 session->scan_info.profile);
980 if ((!channel) || scan_status) {
981 NextCommand = eCsrNexteScanForSsidFailure;
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700982 sme_err("next Scan For Ssid Failure %d %d",
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -0800983 channel, scan_status);
984 } else {
985 NextCommand = eCsrNextCheckAllowConc;
986 *chan = channel;
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700987 sme_debug("next CheckAllowConc");
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -0800988 }
989 break;
990 default:
991 NextCommand = eCsrNextScanNothing;
992 break;
993 }
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700994 sme_debug("Next Command %d", NextCommand);
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -0800995 return NextCommand;
996}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800997
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800998#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
999static void
Jeff Johnsonedece842018-12-02 11:13:52 -08001000csr_diag_scan_complete(struct mac_context *mac_ctx,
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001001 eCsrScanStatus scan_status)
1002{
1003 host_log_scan_pkt_type *pScanLog = NULL;
Abhishek Singh6f56d212017-04-12 14:31:57 +05301004 qdf_list_t *list = NULL;
1005 struct wlan_objmgr_pdev *pdev = NULL;
1006 struct scan_cache_node *cur_node = NULL;
1007 struct scan_cache_node *next_node = NULL;
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001008 int n = 0, c = 0;
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001009
1010 WLAN_HOST_DIAG_LOG_ALLOC(pScanLog,
1011 host_log_scan_pkt_type,
1012 LOG_WLAN_SCAN_C);
1013 if (!pScanLog)
1014 return;
1015
1016 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_RSP;
1017
1018 if (eCSR_SCAN_SUCCESS != scan_status) {
1019 pScanLog->status = WLAN_SCAN_STATUS_FAILURE;
1020 WLAN_HOST_DIAG_LOG_REPORT(pScanLog);
1021 return;
1022 }
Abhishek Singh6f56d212017-04-12 14:31:57 +05301023 pdev = wlan_objmgr_get_pdev_by_id(mac_ctx->psoc,
1024 0, WLAN_LEGACY_MAC_ID);
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001025
Abhishek Singh6f56d212017-04-12 14:31:57 +05301026 if (!pdev) {
1027 sme_err("pdev is NULL");
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001028 return;
1029 }
1030
Abhishek Singh6f56d212017-04-12 14:31:57 +05301031 list = ucfg_scan_get_result(pdev, NULL);
Krunal Soni35a94532018-01-09 10:54:31 -08001032 if (list)
1033 sme_debug("num_entries %d", qdf_list_size(list));
1034 if (!list || (list && !qdf_list_size(list))) {
Abhishek Singh6f56d212017-04-12 14:31:57 +05301035 sme_err("get scan result failed");
1036 WLAN_HOST_DIAG_LOG_REPORT(pScanLog);
1037 wlan_objmgr_pdev_release_ref(pdev, WLAN_LEGACY_MAC_ID);
Sandeep Puligilla2e233c62017-11-07 12:45:57 -08001038 if (list)
1039 ucfg_scan_purge_results(list);
Abhishek Singh6f56d212017-04-12 14:31:57 +05301040 return;
1041 }
1042
1043 qdf_list_peek_front(list,
1044 (qdf_list_node_t **) &cur_node);
1045 while (cur_node) {
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001046 if (n < HOST_LOG_MAX_NUM_BSSID) {
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001047 qdf_mem_copy(pScanLog->bssid[n],
Abhishek Singh6f56d212017-04-12 14:31:57 +05301048 cur_node->entry->bssid.bytes,
1049 QDF_MAC_ADDR_SIZE);
1050 if (cur_node->entry->ssid.length >
1051 WLAN_SSID_MAX_LEN)
1052 cur_node->entry->ssid.length =
1053 WLAN_SSID_MAX_LEN;
1054 qdf_mem_copy(pScanLog->ssid[n],
1055 cur_node->entry->ssid.ssid,
1056 cur_node->entry->ssid.length);
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001057 n++;
1058 }
1059 c++;
Abhishek Singh6f56d212017-04-12 14:31:57 +05301060 qdf_list_peek_next(
1061 list,
1062 (qdf_list_node_t *) cur_node,
1063 (qdf_list_node_t **) &next_node);
1064 cur_node = next_node;
1065 next_node = NULL;
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001066 }
1067 pScanLog->numSsid = (uint8_t) n;
1068 pScanLog->totalSsid = (uint8_t) c;
Abhishek Singh6f56d212017-04-12 14:31:57 +05301069 ucfg_scan_purge_results(list);
1070 wlan_objmgr_pdev_release_ref(pdev, WLAN_LEGACY_MAC_ID);
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001071 WLAN_HOST_DIAG_LOG_REPORT(pScanLog);
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001072}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001073#endif /* #ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR */
1074
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001075/**
Deepak Dhamdhere6f7fbbe2017-02-28 13:35:52 -08001076 * csr_saved_scan_cmd_free_fields() - Free internal fields of scan command
1077 *
1078 * @mac_ctx: Global MAC context
Abhishek Singh221cf992018-02-22 13:44:53 +05301079 * @session: sme session
Deepak Dhamdhere6f7fbbe2017-02-28 13:35:52 -08001080 *
1081 * Frees data structures allocated inside saved_scan_cmd and releases
1082 * the profile.
1083 * Return: None
1084 */
1085
Jeff Johnsonedece842018-12-02 11:13:52 -08001086void csr_saved_scan_cmd_free_fields(struct mac_context *mac_ctx,
gaurank kathpalia14e2f912017-08-31 14:51:45 +05301087 struct csr_roam_session *session)
Deepak Dhamdhere6f7fbbe2017-02-28 13:35:52 -08001088{
1089 if (session->scan_info.profile) {
Jianmin Zhu9b7bef72018-12-18 21:17:15 +08001090 sme_debug("Free profile for session %d", session->sessionId);
Deepak Dhamdhere6f7fbbe2017-02-28 13:35:52 -08001091 csr_release_profile(mac_ctx,
1092 session->scan_info.profile);
1093 qdf_mem_free(session->scan_info.profile);
1094 session->scan_info.profile = NULL;
1095 }
1096
1097 if (session->scan_info.roambssentry) {
1098 qdf_mem_free(session->scan_info.roambssentry);
1099 session->scan_info.roambssentry = NULL;
1100 }
1101}
1102/**
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001103 * csr_save_profile() - Save the profile info from sme command
1104 * @mac_ctx: Global MAC context
1105 * @save_cmd: Pointer where the command will be saved
1106 * @command: Command from which the profile will be saved
1107 *
1108 * Saves the profile information from the SME's scan command
1109 *
1110 * Return: QDF_STATUS
1111 */
Jeff Johnsonedece842018-12-02 11:13:52 -08001112static QDF_STATUS csr_save_profile(struct mac_context *mac_ctx,
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001113 uint32_t session_id)
1114{
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05301115 struct tag_csrscan_result *scan_result;
1116 struct tag_csrscan_result *temp;
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001117 uint32_t bss_len;
gaurank kathpalia14e2f912017-08-31 14:51:45 +05301118 struct csr_roam_session *session;
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001119
Krunal Soni35a94532018-01-09 10:54:31 -08001120 /*
1121 * check the session's validity first, if session itself
1122 * is not valid then there is no point of releasing the memory
1123 * for invalid session (i.e. "goto error" case)
1124 */
1125 if (!CSR_IS_SESSION_VALID(mac_ctx, session_id)) {
1126 sme_err("session %d is invalid", session_id);
1127 return QDF_STATUS_E_FAILURE;
1128 }
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001129 session = CSR_GET_SESSION(mac_ctx, session_id);
1130 if (!session->scan_info.roambssentry)
1131 return QDF_STATUS_SUCCESS;
1132
1133 scan_result = GET_BASE_ADDR(session->scan_info.roambssentry,
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05301134 struct tag_csrscan_result, Link);
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001135
1136 bss_len = scan_result->Result.BssDescriptor.length +
1137 sizeof(scan_result->Result.BssDescriptor.length);
1138
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05301139 temp = qdf_mem_malloc(sizeof(struct tag_csrscan_result) + bss_len);
Arif Hussain0ef77082018-10-10 16:42:53 -07001140 if (!temp)
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001141 goto error;
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001142
1143 temp->AgingCount = scan_result->AgingCount;
1144 temp->preferValue = scan_result->preferValue;
1145 temp->capValue = scan_result->capValue;
1146 temp->ucEncryptionType = scan_result->ucEncryptionType;
1147 temp->mcEncryptionType = scan_result->mcEncryptionType;
1148 temp->authType = scan_result->authType;
1149 /* pvIes is unsued in success/failure */
1150 temp->Result.pvIes = NULL;
1151
1152 qdf_mem_copy(temp->Result.pvIes,
1153 scan_result->Result.pvIes,
1154 sizeof(*scan_result->Result.pvIes));
1155 temp->Result.ssId.length = scan_result->Result.ssId.length;
1156 qdf_mem_copy(temp->Result.ssId.ssId,
1157 scan_result->Result.ssId.ssId,
1158 sizeof(scan_result->Result.ssId.ssId));
1159 temp->Result.timer = scan_result->Result.timer;
1160 qdf_mem_copy(&temp->Result.BssDescriptor,
1161 &scan_result->Result.BssDescriptor,
1162 sizeof(temp->Result.BssDescriptor));
1163 temp->Link.last = temp->Link.next = NULL;
1164 session->scan_info.roambssentry = (tListElem *)temp;
1165
1166 return QDF_STATUS_SUCCESS;
1167error:
1168 csr_scan_handle_search_for_ssid_failure(mac_ctx,
1169 session_id);
Deepak Dhamdhere6f7fbbe2017-02-28 13:35:52 -08001170 csr_saved_scan_cmd_free_fields(mac_ctx, session);
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001171
1172 return QDF_STATUS_E_FAILURE;
1173}
1174
Jeff Johnsonedece842018-12-02 11:13:52 -08001175static void csr_handle_nxt_cmd(struct mac_context *mac_ctx,
Jeff Johnson8c3ecdd2018-12-05 08:48:54 -08001176 enum csr_scancomplete_nextcommand nxt_cmd,
1177 uint32_t session_id,
1178 uint8_t chan)
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001179{
1180 QDF_STATUS status, ret;
Jianmin Zhu9b7bef72018-12-18 21:17:15 +08001181 struct csr_roam_session *session;
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001182
1183 switch (nxt_cmd) {
1184
1185 case eCsrNexteScanForSsidSuccess:
1186 csr_scan_handle_search_for_ssid(mac_ctx, session_id);
1187 break;
1188 case eCsrNexteScanForSsidFailure:
1189 csr_scan_handle_search_for_ssid_failure(mac_ctx, session_id);
1190 break;
1191 case eCsrNextCheckAllowConc:
Tushnim Bhattacharyya0c4ad2d2017-03-09 15:59:03 -08001192 ret = policy_mgr_current_connections_update(mac_ctx->psoc,
1193 session_id, chan,
Tushnim Bhattacharyya3b99f4b2018-03-26 14:19:24 -07001194 POLICY_MGR_UPDATE_REASON_HIDDEN_STA);
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07001195 sme_debug("chan: %d session: %d status: %d",
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001196 chan, session_id, ret);
1197
1198 status = csr_save_profile(mac_ctx, session_id);
1199 if (!QDF_IS_STATUS_SUCCESS(status)) {
1200 /* csr_save_profile should report error */
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07001201 sme_err("profile save failed %d", status);
Jianmin Zhu9b7bef72018-12-18 21:17:15 +08001202 break;
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001203 }
1204
1205 if (QDF_STATUS_E_FAILURE == ret) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07001206 sme_err("conn update fail %d", chan);
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001207 csr_scan_handle_search_for_ssid_failure(mac_ctx,
1208 session_id);
1209 } else if ((QDF_STATUS_E_NOSUPPORT == ret) ||
1210 (QDF_STATUS_E_ALREADY == ret)) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07001211 sme_err("conn update ret %d", ret);
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001212 csr_scan_handle_search_for_ssid(mac_ctx, session_id);
1213 }
1214 /* Else: Set hw mode was issued and the saved connect would
1215 * be issued after set hw mode response
1216 */
Jianmin Zhud4439462018-12-27 14:03:17 +08001217 if (QDF_IS_STATUS_SUCCESS(ret))
Jianmin Zhu9b7bef72018-12-18 21:17:15 +08001218 return;
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001219 default:
1220 break;
1221 }
Jianmin Zhu9b7bef72018-12-18 21:17:15 +08001222 session = CSR_GET_SESSION(mac_ctx, session_id);
1223 if (session)
1224 csr_saved_scan_cmd_free_fields(mac_ctx, session);
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001225}
Abhishek Singhe6857812017-03-10 18:20:06 +05301226
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001227void csr_scan_callback(struct wlan_objmgr_vdev *vdev,
Jeff Johnson8c3ecdd2018-12-05 08:48:54 -08001228 struct scan_event *event, void *arg)
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001229{
1230 eCsrScanStatus scan_status = eCSR_SCAN_FAILURE;
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05301231 enum csr_scancomplete_nextcommand NextCommand = eCsrNextScanNothing;
Jeff Johnsonedece842018-12-02 11:13:52 -08001232 struct mac_context *mac_ctx;
gaurank kathpalia14e2f912017-08-31 14:51:45 +05301233 struct csr_roam_session *session;
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001234 uint32_t session_id = 0;
1235 uint8_t chan = 0;
Jiachao Wub8f89212018-05-24 15:43:59 +08001236 bool success = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001237
Jeff Johnsonedece842018-12-02 11:13:52 -08001238 mac_ctx = (struct mac_context *)arg;
Jiachao Wub8f89212018-05-24 15:43:59 +08001239
Ashish Kumar Dhanotiya8d039c82018-07-11 20:41:14 +05301240 qdf_mtrace(QDF_MODULE_ID_SCAN, QDF_MODULE_ID_SME, event->type,
1241 event->vdev_id, event->scan_id);
1242
Jiachao Wub8f89212018-05-24 15:43:59 +08001243 if (!util_is_scan_completed(event, &success))
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001244 return;
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05301245
Jiachao Wub8f89212018-05-24 15:43:59 +08001246 if (success)
1247 scan_status = eCSR_SCAN_SUCCESS;
1248
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001249 session_id = wlan_vdev_get_id(vdev);
Krunal Soni35a94532018-01-09 10:54:31 -08001250 if (!CSR_IS_SESSION_VALID(mac_ctx, session_id)) {
1251 sme_err("session %d is invalid", session_id);
1252 return;
1253 }
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001254 session = CSR_GET_SESSION(mac_ctx, session_id);
1255
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07001256 sme_debug("Scan Completion: status %d session %d scan_id %d",
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001257 scan_status, session_id, event->scan_id);
1258
1259 /* verify whether scan event is related to scan interested by CSR */
1260 if (session->scan_info.scan_id != event->scan_id) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07001261 sme_debug("Scan Completion on wrong scan_id %d, expected %d",
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001262 session->scan_info.scan_id, event->scan_id);
1263 return;
1264 }
1265#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
1266 csr_diag_scan_complete(mac_ctx, scan_status);
1267#endif
1268 NextCommand = csr_scan_get_next_command_state(mac_ctx,
1269 session_id, scan_status,
1270 &chan);
1271 /* We reuse the command here instead reissue a new command */
1272 csr_handle_nxt_cmd(mac_ctx, NextCommand,
1273 session_id, chan);
1274}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001275
Jeff Johnsonedece842018-12-02 11:13:52 -08001276tCsrScanResultInfo *csr_scan_result_get_first(struct mac_context *mac,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001277 tScanResultHandle hScanResult)
1278{
1279 tListElem *pEntry;
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05301280 struct tag_csrscan_result *pResult;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001281 tCsrScanResultInfo *pRet = NULL;
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05301282 struct scan_result_list *pResultList =
1283 (struct scan_result_list *) hScanResult;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001284
1285 if (pResultList) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001286 pEntry = csr_ll_peek_head(&pResultList->List, LL_ACCESS_NOLOCK);
1287 if (pEntry) {
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05301288 pResult = GET_BASE_ADDR(pEntry, struct
1289 tag_csrscan_result, Link);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001290 pRet = &pResult->Result;
1291 }
1292 pResultList->pCurEntry = pEntry;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001293 }
1294
1295 return pRet;
1296}
1297
Jeff Johnsonedece842018-12-02 11:13:52 -08001298tCsrScanResultInfo *csr_scan_result_get_next(struct mac_context *mac,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001299 tScanResultHandle hScanResult)
1300{
1301 tListElem *pEntry = NULL;
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05301302 struct tag_csrscan_result *pResult = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001303 tCsrScanResultInfo *pRet = NULL;
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05301304 struct scan_result_list *pResultList =
1305 (struct scan_result_list *) hScanResult;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001306
1307 if (!pResultList)
1308 return NULL;
1309
Jeff Johnson038efe72019-03-18 13:39:31 -07001310 if (!pResultList->pCurEntry)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001311 pEntry = csr_ll_peek_head(&pResultList->List, LL_ACCESS_NOLOCK);
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05301312 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001313 pEntry = csr_ll_next(&pResultList->List, pResultList->pCurEntry,
1314 LL_ACCESS_NOLOCK);
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05301315
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001316 if (pEntry) {
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05301317 pResult = GET_BASE_ADDR(pEntry, struct tag_csrscan_result,
1318 Link);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001319 pRet = &pResult->Result;
1320 }
1321 pResultList->pCurEntry = pEntry;
Jianmin Zhub659fa12019-01-30 11:48:49 +08001322
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001323 return pRet;
1324}
1325
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001326/**
1327 * csr_scan_for_ssid() - Function usually used for BSSs that suppresses SSID
1328 * @mac_ctx: Pointer to Global Mac structure
Jeff Johnson66ee8a92018-03-17 15:24:26 -07001329 * @profile: pointer to struct csr_roam_profile
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001330 * @roam_id: variable representing roam id
1331 * @notify: boolean variable
1332 *
1333 * Function is usually used for BSSs that suppresses SSID so the profile
1334 * shall have one and only one SSID.
1335 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301336 * Return: Success - QDF_STATUS_SUCCESS, Failure - error number
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001337 */
Jeff Johnsonedece842018-12-02 11:13:52 -08001338QDF_STATUS csr_scan_for_ssid(struct mac_context *mac_ctx, uint32_t session_id,
Jeff Johnson8c3ecdd2018-12-05 08:48:54 -08001339 struct csr_roam_profile *profile, uint32_t roam_id,
1340 bool notify)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001341{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301342 QDF_STATUS status = QDF_STATUS_E_INVAL;
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001343 uint32_t num_ssid = profile->SSIDs.numOfSSIDs;
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001344 struct scan_start_request *req;
1345 struct wlan_objmgr_vdev *vdev;
Himanshu Agarwal12445c12017-11-07 14:56:09 +05301346 uint8_t i, chan, num_chan = 0;
Vignesh Viswanathanad47f0a2018-03-15 16:42:17 +05301347 uint8_t pdev_id;
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001348 wlan_scan_id scan_id;
gaurank kathpalia14e2f912017-08-31 14:51:45 +05301349 struct csr_roam_session *session = CSR_GET_SESSION(mac_ctx, session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001350
Krunal Soni35a94532018-01-09 10:54:31 -08001351 if (!CSR_IS_SESSION_VALID(mac_ctx, session_id)) {
1352 sme_err("session %d is invalid", session_id);
1353 return status;
1354 }
Abhinav Kumarf9989582018-02-06 17:42:22 +05301355
Abhishek Singh935e4772018-11-21 14:14:10 +05301356 if (num_ssid != 1) {
1357 sme_err("numSSID (%d) is invalid", profile->SSIDs.numOfSSIDs);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001358 return status;
1359 }
1360
Vignesh Viswanathanad47f0a2018-03-15 16:42:17 +05301361 if (!mac_ctx->pdev) {
1362 sme_err("pdev ctx is NULL");
1363 return status;
1364 }
1365 pdev_id = wlan_objmgr_pdev_get_pdev_id(mac_ctx->pdev);
1366
Jianmin Zhud4439462018-12-27 14:03:17 +08001367 /* Free old memory if any before its overwritten */
1368 csr_saved_scan_cmd_free_fields(mac_ctx, session);
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001369 session->scan_info.profile =
Jeff Johnson66ee8a92018-03-17 15:24:26 -07001370 qdf_mem_malloc(sizeof(struct csr_roam_profile));
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001371 if (!session->scan_info.profile)
1372 status = QDF_STATUS_E_NOMEM;
1373 else
1374 status = csr_roam_copy_profile(mac_ctx,
1375 session->scan_info.profile,
1376 profile);
Abhinav Kumar3b724f52018-12-26 15:18:11 +05301377 if (QDF_IS_STATUS_ERROR(status))
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001378 goto error;
1379 scan_id = ucfg_scan_get_scan_id(mac_ctx->psoc);
1380 session->scan_info.scan_id = scan_id;
1381 session->scan_info.scan_reason = eCsrScanForSsid;
1382 session->scan_info.roam_id = roam_id;
1383 req = qdf_mem_malloc(sizeof(*req));
Abhinav Kumar3b724f52018-12-26 15:18:11 +05301384 if (!req) {
1385 status = QDF_STATUS_E_NOMEM;
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001386 goto error;
Abhinav Kumar3b724f52018-12-26 15:18:11 +05301387 }
Vignesh Viswanathanad47f0a2018-03-15 16:42:17 +05301388
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001389 vdev = wlan_objmgr_get_vdev_by_macaddr_from_psoc(mac_ctx->psoc,
Vignesh Viswanathanad47f0a2018-03-15 16:42:17 +05301390 pdev_id,
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001391 session->selfMacAddr.bytes,
1392 WLAN_LEGACY_SME_ID);
1393 ucfg_scan_init_default_params(vdev, req);
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001394 req->scan_req.scan_id = scan_id;
1395 req->scan_req.vdev_id = session_id;
1396 req->scan_req.scan_req_id = mac_ctx->scan.requester_id;
Deepak Dhamdhereca7315c2017-10-20 13:05:56 -07001397 req->scan_req.scan_f_passive = false;
1398 req->scan_req.scan_f_bcast_probe = false;
1399
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001400 if (QDF_P2P_CLIENT_MODE == profile->csrPersona)
1401 req->scan_req.scan_priority = SCAN_PRIORITY_HIGH;
1402
1403 /* Allocate memory for IE field */
1404 if (profile->pAddIEScan) {
1405 req->scan_req.extraie.ptr =
1406 qdf_mem_malloc(profile->nAddIEScanLength);
1407
Jeff Johnson038efe72019-03-18 13:39:31 -07001408 if (!req->scan_req.extraie.ptr)
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001409 status = QDF_STATUS_E_NOMEM;
1410 else
1411 status = QDF_STATUS_SUCCESS;
1412
1413 if (QDF_IS_STATUS_SUCCESS(status)) {
1414 qdf_mem_copy(req->scan_req.extraie.ptr,
1415 profile->pAddIEScan,
1416 profile->nAddIEScanLength);
1417 req->scan_req.extraie.len = profile->nAddIEScanLength;
1418 } else {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07001419 sme_err("No memory for scanning IE fields");
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001420 }
1421 }
1422
1423 req->scan_req.num_bssid = 1;
1424 if (profile->BSSIDs.numOfBSSIDs == 1)
1425 qdf_copy_macaddr(&req->scan_req.bssid_list[0],
1426 profile->BSSIDs.bssid);
1427 else
1428 qdf_set_macaddr_broadcast(&req->scan_req.bssid_list[0]);
1429
1430 if (profile->ChannelInfo.numOfChannels) {
1431 for (i = 0; i < profile->ChannelInfo.numOfChannels; i++) {
1432 if (csr_roam_is_valid_channel(mac_ctx,
1433 profile->ChannelInfo.ChannelList[i])) {
1434 chan = profile->ChannelInfo.ChannelList[i];
Abhishek Singha394b6c2017-11-03 17:14:58 +05301435 req->scan_req.chan_list.chan[num_chan].freq =
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001436 wlan_chan_to_freq(chan);
1437 num_chan++;
1438 }
1439 }
Abhishek Singha394b6c2017-11-03 17:14:58 +05301440 req->scan_req.chan_list.num_chan = num_chan;
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001441 }
1442
1443 /* Extend it for multiple SSID */
1444 if (profile->SSIDs.numOfSSIDs) {
Srinivas Girigowdab8fdc642019-03-19 15:33:03 -07001445 if (profile->SSIDs.SSIDList[0].SSID.length > WLAN_SSID_MAX_LEN) {
Sandeep Puligillac0f77442017-11-07 01:20:32 -08001446 sme_debug("wrong ssid length = %d",
1447 profile->SSIDs.SSIDList[0].SSID.length);
1448 status = QDF_STATUS_E_INVAL;
1449 goto error;
1450 }
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001451 req->scan_req.num_ssids = 1;
1452 qdf_mem_copy(&req->scan_req.ssid[0].ssid,
1453 &profile->SSIDs.SSIDList[0].SSID.ssId,
1454 profile->SSIDs.SSIDList[0].SSID.length);
1455 req->scan_req.ssid[0].length =
1456 profile->SSIDs.SSIDList[0].SSID.length;
Himanshu Agarwal12445c12017-11-07 14:56:09 +05301457 sme_debug("scan for SSID = %.*s", req->scan_req.ssid[0].length,
1458 req->scan_req.ssid[0].ssid);
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001459 }
1460 status = ucfg_scan_start(req);
1461 wlan_objmgr_vdev_release_ref(vdev, WLAN_LEGACY_SME_ID);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001462error:
Abhinav Kumar3b724f52018-12-26 15:18:11 +05301463 if (QDF_IS_STATUS_ERROR(status)) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07001464 sme_err("failed to initiate scan with status: %d", status);
Sandeep Puligillab0e017c2017-06-09 18:09:55 -07001465 csr_release_profile(mac_ctx, session->scan_info.profile);
1466 qdf_mem_free(session->scan_info.profile);
1467 session->scan_info.profile = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001468 if (notify)
1469 csr_roam_call_callback(mac_ctx, session_id, NULL,
1470 roam_id, eCSR_ROAM_FAILED,
1471 eCSR_ROAM_RESULT_FAILURE);
1472 }
1473 return status;
1474}
1475
Jeff Johnsonedece842018-12-02 11:13:52 -08001476static void csr_set_cfg_valid_channel_list(struct mac_context *mac,
Jeff Johnson8c3ecdd2018-12-05 08:48:54 -08001477 uint8_t *pChannelList,
1478 uint8_t NumChannels)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001479{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301480 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001481
Abhishek Singh438cd7e2017-08-11 12:21:06 +05301482 QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001483 "%s: dump valid channel list(NumChannels(%d))",
1484 __func__, NumChannels);
Abhishek Singh438cd7e2017-08-11 12:21:06 +05301485 QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001486 pChannelList, NumChannels);
Wu Gaof3cbeaf2019-01-15 18:26:25 +08001487 qdf_mem_copy(mac->mlme_cfg->reg.valid_channel_list, pChannelList,
1488 NumChannels);
1489 mac->mlme_cfg->reg.valid_channel_list_num = NumChannels;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001490
Abhishek Singh438cd7e2017-08-11 12:21:06 +05301491 QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001492 "Scan offload is enabled, update default chan list");
1493 /*
1494 * disable fcc constraint since new country code
1495 * is being set
1496 */
Jeff Johnsonc44820d2018-11-22 13:40:38 -08001497 mac->scan.fcc_constraint = false;
1498 status = csr_update_channel_list(mac);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301499 if (QDF_STATUS_SUCCESS != status) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301500 QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001501 "failed to update the supported channel list");
1502 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001503}
1504
1505/*
1506 * The Tx power limits are saved in the cfg for future usage.
1507 */
Jeff Johnson61b50892019-03-20 09:22:05 -07001508static void csr_save_tx_power_to_cfg(struct mac_context *mac,
gaurank kathpalia3d2e3852018-10-03 22:03:23 +05301509 tDblLinkList *pList,
1510 enum band_info band)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001511{
1512 tListElem *pEntry;
1513 uint32_t cbLen = 0, dataLen, tmp_len;
gaurank kathpalia14e2f912017-08-31 14:51:45 +05301514 struct csr_channel_powerinfo *ch_set;
Paul Zhang2f789232019-04-19 16:40:24 +08001515 uint32_t idx, count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001516 tSirMacChanInfo *ch_pwr_set;
gaurank kathpalia3d2e3852018-10-03 22:03:23 +05301517 uint8_t *p_buf = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001518
1519 /* allocate maximum space for all channels */
Wu Gao0821b0d2019-01-11 17:31:11 +08001520 dataLen = CFG_VALID_CHANNEL_LIST_LEN * sizeof(tSirMacChanInfo);
gaurank kathpalia3d2e3852018-10-03 22:03:23 +05301521 p_buf = qdf_mem_malloc(dataLen);
1522 if (!p_buf)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001523 return;
1524
gaurank kathpalia3d2e3852018-10-03 22:03:23 +05301525 ch_pwr_set = (tSirMacChanInfo *)(p_buf);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001526 pEntry = csr_ll_peek_head(pList, LL_ACCESS_LOCK);
1527 /*
1528 * write the tuples (startChan, numChan, txPower) for each channel found
1529 * in the channel power list.
1530 */
1531 while (pEntry) {
gaurank kathpalia14e2f912017-08-31 14:51:45 +05301532 ch_set = GET_BASE_ADDR(pEntry,
1533 struct csr_channel_powerinfo, link);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001534 if (1 != ch_set->interChannelOffset) {
1535 /*
1536 * we keep the 5G channel sets internally with an
1537 * interchannel offset of 4. Expand these to the right
1538 * format. (inter channel offset of 1 is the only option
1539 * for the triplets that 11d advertises.
1540 */
1541 tmp_len = cbLen + (ch_set->numChannels *
1542 sizeof(tSirMacChanInfo));
1543 if (tmp_len >= dataLen) {
1544 /*
1545 * expanding this entry will overflow our
1546 * allocation
1547 */
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07001548 sme_err(
1549 "Buffer overflow, start %d, num %d, offset %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001550 ch_set->firstChannel,
1551 ch_set->numChannels,
1552 ch_set->interChannelOffset);
1553 break;
1554 }
1555
1556 for (idx = 0; idx < ch_set->numChannels; idx++) {
1557 ch_pwr_set->firstChanNum = (tSirMacChanNum)
1558 (ch_set->firstChannel + (idx *
1559 ch_set->interChannelOffset));
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07001560 sme_debug(
1561 "Setting Channel Number %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001562 ch_pwr_set->firstChanNum);
1563 ch_pwr_set->numChannels = 1;
1564 ch_pwr_set->maxTxPower =
Anurag Chouhan6d760662016-02-20 16:05:43 +05301565 QDF_MIN(ch_set->txPower,
Jeff Johnson61b50892019-03-20 09:22:05 -07001566 mac->mlme_cfg->power.max_tx_power);
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07001567 sme_debug(
1568 "Setting Max Transmit Power %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001569 ch_pwr_set->maxTxPower);
1570 cbLen += sizeof(tSirMacChanInfo);
1571 ch_pwr_set++;
Paul Zhang2f789232019-04-19 16:40:24 +08001572 count++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001573 }
1574 } else {
1575 if (cbLen >= dataLen) {
1576 /* this entry will overflow our allocation */
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07001577 sme_err(
1578 "Buffer overflow, start %d, num %d, offset %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001579 ch_set->firstChannel,
1580 ch_set->numChannels,
1581 ch_set->interChannelOffset);
1582 break;
1583 }
1584 ch_pwr_set->firstChanNum = ch_set->firstChannel;
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07001585 sme_debug("Setting Channel Number %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001586 ch_pwr_set->firstChanNum);
1587 ch_pwr_set->numChannels = ch_set->numChannels;
Anurag Chouhan6d760662016-02-20 16:05:43 +05301588 ch_pwr_set->maxTxPower = QDF_MIN(ch_set->txPower,
Jeff Johnson61b50892019-03-20 09:22:05 -07001589 mac->mlme_cfg->power.max_tx_power);
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07001590 sme_debug(
1591 "Setting Max Tx Power %d, nTxPower %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001592 ch_pwr_set->maxTxPower,
Jeff Johnson61b50892019-03-20 09:22:05 -07001593 mac->mlme_cfg->power.max_tx_power);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001594 cbLen += sizeof(tSirMacChanInfo);
1595 ch_pwr_set++;
Paul Zhang2f789232019-04-19 16:40:24 +08001596 count++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001597 }
1598 pEntry = csr_ll_next(pList, pEntry, LL_ACCESS_LOCK);
1599 }
Paul Zhang2f789232019-04-19 16:40:24 +08001600 if (band == BAND_2G) {
1601 mac->mlme_cfg->power.max_tx_power_24.len = 3 * count;
Jeff Johnson61b50892019-03-20 09:22:05 -07001602 qdf_mem_copy(mac->mlme_cfg->power.max_tx_power_24.data,
gaurank kathpalia3d2e3852018-10-03 22:03:23 +05301603 (uint8_t *)p_buf,
Jeff Johnson61b50892019-03-20 09:22:05 -07001604 mac->mlme_cfg->power.max_tx_power_24.len);
Paul Zhang2f789232019-04-19 16:40:24 +08001605 }
1606 if (band == BAND_5G) {
1607 mac->mlme_cfg->power.max_tx_power_5.len = 3 * count;
Jeff Johnson61b50892019-03-20 09:22:05 -07001608 qdf_mem_copy(mac->mlme_cfg->power.max_tx_power_5.data,
gaurank kathpalia3d2e3852018-10-03 22:03:23 +05301609 (uint8_t *)p_buf,
Jeff Johnson61b50892019-03-20 09:22:05 -07001610 mac->mlme_cfg->power.max_tx_power_5.len);
Paul Zhang2f789232019-04-19 16:40:24 +08001611 }
gaurank kathpalia3d2e3852018-10-03 22:03:23 +05301612 qdf_mem_free(p_buf);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001613}
1614
Jeff Johnson8c3ecdd2018-12-05 08:48:54 -08001615static void csr_set_cfg_country_code(struct mac_context *mac,
1616 uint8_t *countryCode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001617{
Wu Gaoaa155142019-01-14 15:09:26 +08001618 uint8_t cc[CFG_COUNTRY_CODE_LEN];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001619 /* v_REGDOMAIN_t DomainId */
1620
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07001621 sme_debug("Setting Country Code in Cfg %s", countryCode);
Wu Gaoaa155142019-01-14 15:09:26 +08001622 qdf_mem_copy(cc, countryCode, CFG_COUNTRY_CODE_LEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001623
1624 /*
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05301625 * Don't program the bogus country codes that we created for Korea in
1626 * the MAC. if we see the bogus country codes, program the MAC with
1627 * the right country code.
1628 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001629 if (('K' == countryCode[0] && '1' == countryCode[1]) ||
1630 ('K' == countryCode[0] && '2' == countryCode[1]) ||
1631 ('K' == countryCode[0] && '3' == countryCode[1]) ||
1632 ('K' == countryCode[0] && '4' == countryCode[1])) {
1633 /*
1634 * replace the alternate Korea country codes, 'K1', 'K2', ..
1635 * with 'KR' for Korea
1636 */
1637 cc[1] = 'R';
1638 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001639
1640 /*
Wu Gaof3cbeaf2019-01-15 18:26:25 +08001641 * country code is moved to mlme component, and it is limited to call
1642 * legacy api, so required to call sch_edca_profile_update_all if
1643 * overwrite country code in mlme component
1644 */
1645 qdf_mem_copy(mac->mlme_cfg->reg.country_code, cc, CFG_COUNTRY_CODE_LEN);
1646 mac->mlme_cfg->reg.country_code_len = CFG_COUNTRY_CODE_LEN;
1647 sme_debug("CFG_COUNTRY_CODE changed");
1648 sch_edca_profile_update_all(mac);
1649 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001650 * Need to let HALPHY know about the current domain so it can apply some
1651 * domain-specific settings (TX filter...)
1652 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001653}
1654
Jeff Johnsonedece842018-12-02 11:13:52 -08001655QDF_STATUS csr_get_country_code(struct mac_context *mac, uint8_t *pBuf,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001656 uint8_t *pbLen)
1657{
Wu Gaoaa155142019-01-14 15:09:26 +08001658 if (pBuf && pbLen && (*pbLen >= CFG_COUNTRY_CODE_LEN)) {
Wu Gaof3cbeaf2019-01-15 18:26:25 +08001659 *pbLen = mac->mlme_cfg->reg.country_code_len;
1660 qdf_mem_copy(pBuf, mac->mlme_cfg->reg.country_code,
1661 (uint32_t)*pbLen);
1662 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001663 }
1664
Varun Reddy Yeturu7b2a6572017-06-15 11:07:28 -07001665 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001666}
1667
Jeff Johnson8c3ecdd2018-12-05 08:48:54 -08001668QDF_STATUS csr_scan_abort_mac_scan(struct mac_context *mac_ctx,
1669 uint32_t vdev_id,
Abhishek Singh9fabbbb2018-01-29 17:38:36 +05301670 uint32_t scan_id)
Sandeep Puligilladf6454a2016-10-21 16:10:59 -07001671{
Abhishek Singh9fabbbb2018-01-29 17:38:36 +05301672 struct scan_cancel_request *req;
1673 QDF_STATUS status;
1674 struct wlan_objmgr_vdev *vdev;
Sandeep Puligilladf6454a2016-10-21 16:10:59 -07001675
Abhishek Singh9fabbbb2018-01-29 17:38:36 +05301676 req = qdf_mem_malloc(sizeof(*req));
Arif Hussain0ef77082018-10-10 16:42:53 -07001677 if (!req)
Abhishek Singh9fabbbb2018-01-29 17:38:36 +05301678 return QDF_STATUS_E_NOMEM;
Sandeep Puligilladf6454a2016-10-21 16:10:59 -07001679
Abhishek Singh9fabbbb2018-01-29 17:38:36 +05301680 /* Get NL global context from objmgr*/
1681 if (vdev_id == INVAL_VDEV_ID)
Abhishek Singhcdd3d4c2018-11-14 11:56:05 +05301682 vdev = wlan_objmgr_pdev_get_first_vdev(mac_ctx->pdev,
1683 WLAN_LEGACY_SME_ID);
Abhishek Singh9fabbbb2018-01-29 17:38:36 +05301684 else
1685 vdev = wlan_objmgr_get_vdev_by_id_from_pdev(mac_ctx->pdev,
1686 vdev_id, WLAN_LEGACY_SME_ID);
Sandeep Puligilladf6454a2016-10-21 16:10:59 -07001687
Abhishek Singh9fabbbb2018-01-29 17:38:36 +05301688 if (!vdev) {
1689 sme_err("Failed get vdev");
1690 qdf_mem_free(req);
1691 return QDF_STATUS_E_INVAL;
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +05301692 }
Abhishek Singh9fabbbb2018-01-29 17:38:36 +05301693
1694 req->vdev = vdev;
1695 req->cancel_req.scan_id = scan_id;
1696 req->cancel_req.pdev_id = wlan_objmgr_pdev_get_pdev_id(mac_ctx->pdev);
1697 req->cancel_req.vdev_id = vdev_id;
1698 if (scan_id != INVAL_SCAN_ID)
1699 req->cancel_req.req_type = WLAN_SCAN_CANCEL_SINGLE;
1700 if (vdev_id == INVAL_VDEV_ID)
1701 req->cancel_req.req_type = WLAN_SCAN_CANCEL_PDEV_ALL;
1702 else
1703 req->cancel_req.req_type = WLAN_SCAN_CANCEL_VDEV_ALL;
1704
1705 status = ucfg_scan_cancel(req);
1706 if (QDF_IS_STATUS_ERROR(status))
1707 sme_err("Cancel scan request failed");
1708
1709 wlan_objmgr_vdev_release_ref(vdev, WLAN_LEGACY_SME_ID);
1710
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001711 return status;
1712}
Jeff Johnsonedece842018-12-02 11:13:52 -08001713QDF_STATUS csr_remove_nonscan_cmd_from_pending_list(struct mac_context *mac,
Jeff Johnson8c3ecdd2018-12-05 08:48:54 -08001714 uint8_t sessionId,
1715 eSmeCommandType commandType)
Krunal Soni72dba662017-02-15 20:13:17 -08001716{
1717 tDblLinkList localList;
1718 tListElem *pEntry;
1719 tSmeCmd *pCommand;
1720 tListElem *pEntryToRemove;
1721 QDF_STATUS status = QDF_STATUS_E_FAILURE;
1722
1723 qdf_mem_zero(&localList, sizeof(tDblLinkList));
Jeff Johnson616417f2018-06-27 10:20:53 -07001724 if (!QDF_IS_STATUS_SUCCESS(csr_ll_open(&localList))) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07001725 sme_err("failed to open list");
Krunal Soni72dba662017-02-15 20:13:17 -08001726 return status;
1727 }
1728
Jeff Johnsonc44820d2018-11-22 13:40:38 -08001729 pEntry = csr_nonscan_pending_ll_peek_head(mac, LL_ACCESS_NOLOCK);
Krunal Soni72dba662017-02-15 20:13:17 -08001730
1731 /*
1732 * Have to make sure we don't loop back to the head of the list,
1733 * which will happen if the entry is NOT on the list
1734 */
1735 while (pEntry) {
1736 pEntryToRemove = pEntry;
Jeff Johnsonc44820d2018-11-22 13:40:38 -08001737 pEntry = csr_nonscan_pending_ll_next(mac,
Krunal Soni72dba662017-02-15 20:13:17 -08001738 pEntry, LL_ACCESS_NOLOCK);
1739 pCommand = GET_BASE_ADDR(pEntryToRemove, tSmeCmd, Link);
1740
1741 if ((pCommand->command == commandType) &&
1742 (pCommand->sessionId == sessionId)) {
Will Huang24d272b2018-09-07 20:25:30 +08001743 /* Insert to localList and remove later */
1744 csr_ll_insert_tail(&localList, pEntryToRemove,
1745 LL_ACCESS_NOLOCK);
1746 status = QDF_STATUS_SUCCESS;
Krunal Soni72dba662017-02-15 20:13:17 -08001747 }
1748 }
Jianmin Zhub659fa12019-01-30 11:48:49 +08001749
Krunal Soni72dba662017-02-15 20:13:17 -08001750
1751 while ((pEntry = csr_ll_remove_head(&localList, LL_ACCESS_NOLOCK))) {
1752 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07001753 sme_debug("Sending abort for command ID %d",
Abhinav Kumarf9989582018-02-06 17:42:22 +05301754 sessionId);
Jeff Johnsonc44820d2018-11-22 13:40:38 -08001755 csr_release_command(mac, pCommand);
Krunal Soni72dba662017-02-15 20:13:17 -08001756 }
1757
1758 csr_ll_close(&localList);
1759 return status;
1760}
Jeff Johnson8c3ecdd2018-12-05 08:48:54 -08001761
Jeff Johnsonedece842018-12-02 11:13:52 -08001762bool csr_roam_is_valid_channel(struct mac_context *mac, uint8_t channel)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001763{
1764 bool fValid = false;
1765 uint32_t idx_valid_ch;
Jeff Johnsonc44820d2018-11-22 13:40:38 -08001766 uint32_t len = mac->roam.numValidChannels;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001767
1768 for (idx_valid_ch = 0; (idx_valid_ch < len); idx_valid_ch++) {
Jeff Johnsonc44820d2018-11-22 13:40:38 -08001769 if (channel == mac->roam.validChannelList[idx_valid_ch]) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001770 fValid = true;
1771 break;
1772 }
1773 }
1774 return fValid;
1775}
1776
Jeff Johnsonedece842018-12-02 11:13:52 -08001777QDF_STATUS csr_scan_create_entry_in_scan_cache(struct mac_context *mac,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001778 uint32_t sessionId,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301779 struct qdf_mac_addr bssid,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001780 uint8_t channel)
1781{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301782 QDF_STATUS status = QDF_STATUS_SUCCESS;
Jeff Johnsonc44820d2018-11-22 13:40:38 -08001783 struct csr_roam_session *pSession = CSR_GET_SESSION(mac, sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001784 tSirBssDescription *pNewBssDescriptor = NULL;
1785 uint32_t size = 0;
1786
Jeff Johnson038efe72019-03-18 13:39:31 -07001787 if (!pSession) {
Abhishek Singhf723e3d2018-02-20 18:02:37 +05301788 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001789 }
Srinivas Girigowdacb7b8b82019-04-10 14:27:47 -07001790 sme_debug("Current bssid::"QDF_MAC_ADDR_STR,
Srinivas Girigowda34fbba02019-04-08 12:07:44 -07001791 QDF_MAC_ADDR_ARRAY(pSession->pConnectBssDesc->bssId));
Srinivas Girigowdacb7b8b82019-04-10 14:27:47 -07001792 sme_debug("My bssid::"QDF_MAC_ADDR_STR" channel %d",
Srinivas Girigowda34fbba02019-04-08 12:07:44 -07001793 QDF_MAC_ADDR_ARRAY(bssid.bytes), channel);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001794
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001795 size = pSession->pConnectBssDesc->length +
1796 sizeof(pSession->pConnectBssDesc->length);
1797 if (!size) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07001798 sme_err("length of bss descriptor is 0");
Abhishek Singhf723e3d2018-02-20 18:02:37 +05301799 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001800 }
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301801 pNewBssDescriptor = qdf_mem_malloc(size);
Arif Hussain0ef77082018-10-10 16:42:53 -07001802 if (pNewBssDescriptor)
Abhishek Singhf723e3d2018-02-20 18:02:37 +05301803 return QDF_STATUS_E_FAILURE;
Arif Hussain0ef77082018-10-10 16:42:53 -07001804
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301805 qdf_mem_copy(pNewBssDescriptor, pSession->pConnectBssDesc, size);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001806 /* change the BSSID & channel as passed */
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301807 qdf_mem_copy(pNewBssDescriptor->bssId, bssid.bytes,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001808 sizeof(tSirMacAddr));
1809 pNewBssDescriptor->channelId = channel;
Jeff Johnsonc44820d2018-11-22 13:40:38 -08001810 if (!csr_scan_append_bss_description(mac, pNewBssDescriptor)) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07001811 sme_err("csr_scan_append_bss_description failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301812 status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001813 goto free_mem;
1814 }
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07001815 sme_err("entry successfully added in scan cache");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001816
1817free_mem:
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05301818 if (pNewBssDescriptor)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301819 qdf_mem_free(pNewBssDescriptor);
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05301820
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001821 return status;
1822}
1823
1824#ifdef FEATURE_WLAN_ESE
1825/* Update the TSF with the difference in system time */
1826void update_cckmtsf(uint32_t *timeStamp0, uint32_t *timeStamp1,
Arun Khandavalli8a711cb2017-01-03 20:23:56 +05301827 uint64_t *incr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001828{
1829 uint64_t timeStamp64 = ((uint64_t) *timeStamp1 << 32) | (*timeStamp0);
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05301830
Arun Khandavalli8a711cb2017-01-03 20:23:56 +05301831 timeStamp64 = (uint64_t)(timeStamp64 + (*incr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001832 *timeStamp0 = (uint32_t) (timeStamp64 & 0xffffffff);
1833 *timeStamp1 = (uint32_t) ((timeStamp64 >> 32) & 0xffffffff);
1834}
1835#endif
1836
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001837#ifdef WLAN_FEATURE_ROAM_OFFLOAD
Pragaspathi Thilagaraj1d8e2ab2019-03-04 23:59:21 +05301838QDF_STATUS
1839csr_rso_save_ap_to_scan_cache(struct mac_context *mac,
1840 struct roam_offload_synch_ind *roam_sync_ind_ptr,
1841 struct bss_description *bss_desc_ptr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001842{
1843 uint32_t length = 0;
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05301844 struct tag_csrscan_result *scan_res_ptr = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001845
1846 length = roam_sync_ind_ptr->beaconProbeRespLength -
1847 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET);
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05301848 scan_res_ptr = qdf_mem_malloc(sizeof(struct tag_csrscan_result) +
1849 length);
Arif Hussain0ef77082018-10-10 16:42:53 -07001850 if (!scan_res_ptr)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301851 return QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001852
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301853 qdf_mem_copy(&scan_res_ptr->Result.BssDescriptor,
Varun Reddy Yeturud5939f82015-12-24 18:14:02 -08001854 bss_desc_ptr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001855 (sizeof(tSirBssDescription) + length));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001856
Srinivas Girigowdacb7b8b82019-04-10 14:27:47 -07001857 sme_debug("LFR3:Add BSSID to scan cache" QDF_MAC_ADDR_STR,
Srinivas Girigowda34fbba02019-04-08 12:07:44 -07001858 QDF_MAC_ADDR_ARRAY(scan_res_ptr->Result.BssDescriptor.bssId));
Jeff Johnsonc44820d2018-11-22 13:40:38 -08001859 csr_scan_add_result(mac, scan_res_ptr);
1860 csr_free_scan_result_entry(mac, scan_res_ptr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301861 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001862}
1863#endif
Jeff Johnson8c3ecdd2018-12-05 08:48:54 -08001864
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001865/**
Naveen Rawat664a7cb2017-01-19 17:58:14 -08001866 * csr_get_fst_bssdescr_ptr() - This function returns the pointer to first bss
1867 * description from scan handle
1868 * @result_handle: an object for the result.
1869 *
1870 * Return: first bss descriptor from the scan handle.
1871 */
Pragaspathi Thilagaraj1d8e2ab2019-03-04 23:59:21 +05301872struct bss_description*
1873csr_get_fst_bssdescr_ptr(tScanResultHandle result_handle)
Naveen Rawat664a7cb2017-01-19 17:58:14 -08001874{
1875 tListElem *first_element = NULL;
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05301876 struct tag_csrscan_result *scan_result = NULL;
1877 struct scan_result_list *bss_list =
1878 (struct scan_result_list *)result_handle;
Naveen Rawat664a7cb2017-01-19 17:58:14 -08001879
Jeff Johnson038efe72019-03-18 13:39:31 -07001880 if (!bss_list) {
Naveen Rawat664a7cb2017-01-19 17:58:14 -08001881 QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_ERROR,
1882 FL("Empty bss_list"));
1883 return NULL;
1884 }
1885 if (csr_ll_is_list_empty(&bss_list->List, LL_ACCESS_NOLOCK)) {
1886 QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_ERROR,
1887 FL("bss_list->List is empty"));
Naveen Rawat664a7cb2017-01-19 17:58:14 -08001888 return NULL;
1889 }
1890 first_element = csr_ll_peek_head(&bss_list->List, LL_ACCESS_NOLOCK);
Jeff Johnson038efe72019-03-18 13:39:31 -07001891 if (!first_element) {
Naveen Rawat664a7cb2017-01-19 17:58:14 -08001892 QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_ERROR,
1893 FL("peer head return NULL"));
1894 return NULL;
1895 }
1896
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05301897 scan_result = GET_BASE_ADDR(first_element, struct tag_csrscan_result,
1898 Link);
Naveen Rawat664a7cb2017-01-19 17:58:14 -08001899
1900 return &scan_result->Result.BssDescriptor;
1901}
1902
1903/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001904 * csr_get_bssdescr_from_scan_handle() - This function to extract
1905 * first bss description from scan handle
1906 * @result_handle: an object for the result.
1907 *
1908 * This function is written to extract first bss from scan handle.
1909 *
1910 * Return: first bss descriptor from the scan handle.
1911 */
Jeff Johnson8c3ecdd2018-12-05 08:48:54 -08001912tSirBssDescription *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001913csr_get_bssdescr_from_scan_handle(tScanResultHandle result_handle,
Jeff Johnson8c3ecdd2018-12-05 08:48:54 -08001914 tSirBssDescription *bss_descr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001915{
1916 tListElem *first_element = NULL;
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05301917 struct tag_csrscan_result *scan_result = NULL;
1918 struct scan_result_list *bss_list =
1919 (struct scan_result_list *)result_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001920
Jeff Johnson038efe72019-03-18 13:39:31 -07001921 if (!bss_list) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301922 QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001923 FL("Empty bss_list"));
1924 return NULL;
1925 }
1926 if (csr_ll_is_list_empty(&bss_list->List, LL_ACCESS_NOLOCK)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301927 QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001928 FL("bss_list->List is empty"));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301929 qdf_mem_free(bss_list);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001930 return NULL;
1931 }
1932 first_element = csr_ll_peek_head(&bss_list->List, LL_ACCESS_NOLOCK);
1933 if (first_element) {
1934 scan_result = GET_BASE_ADDR(first_element,
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05301935 struct tag_csrscan_result,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001936 Link);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301937 qdf_mem_copy(bss_descr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001938 &scan_result->Result.BssDescriptor,
1939 sizeof(tSirBssDescription));
1940 }
1941 return bss_descr;
1942}
1943
Tushnim Bhattacharyya3f780532018-08-01 19:11:40 -07001944uint8_t
Jeff Johnsonedece842018-12-02 11:13:52 -08001945csr_get_channel_for_hw_mode_change(struct mac_context *mac_ctx,
Tushnim Bhattacharyya3f780532018-08-01 19:11:40 -07001946 tScanResultHandle result_handle,
1947 uint32_t session_id)
1948{
1949 tListElem *next_element = NULL;
1950 struct tag_csrscan_result *scan_result = NULL;
1951 struct scan_result_list *bss_list =
1952 (struct scan_result_list *)result_handle;
1953 uint8_t channel_id = 0;
1954
Jeff Johnson038efe72019-03-18 13:39:31 -07001955 if (!bss_list) {
Tushnim Bhattacharyya3f780532018-08-01 19:11:40 -07001956 QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_ERROR,
1957 FL("Empty bss_list"));
1958 goto end;
1959 }
1960
1961 if (policy_mgr_is_hw_dbs_capable(mac_ctx->psoc) == false) {
1962 QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_DEBUG,
1963 FL("driver isn't dbs capable"));
1964 goto end;
1965 }
1966
1967 if (policy_mgr_is_current_hwmode_dbs(mac_ctx->psoc)) {
1968 QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_DEBUG,
1969 FL("driver is already in DBS"));
1970 goto end;
1971 }
1972
1973 if (!policy_mgr_is_dbs_allowed_for_concurrency(mac_ctx->psoc,
1974 QDF_STA_MODE)) {
1975 QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_DEBUG,
1976 FL("DBS is not allowed for this concurrency combo"));
1977 goto end;
1978 }
1979
1980 if (!policy_mgr_is_hw_dbs_2x2_capable(mac_ctx->psoc) &&
1981 !policy_mgr_get_connection_count(mac_ctx->psoc)) {
1982 QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_DEBUG,
1983 FL("1x1 DBS HW with no prior connection"));
1984 goto end;
1985 }
1986
1987 if (csr_ll_is_list_empty(&bss_list->List, LL_ACCESS_NOLOCK)) {
1988 QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_ERROR,
1989 FL("bss_list->List is empty"));
1990 qdf_mem_free(bss_list);
1991 goto end;
1992 }
1993
1994 next_element = csr_ll_peek_head(&bss_list->List, LL_ACCESS_NOLOCK);
1995 while (next_element) {
1996 scan_result = GET_BASE_ADDR(next_element,
1997 struct tag_csrscan_result,
1998 Link);
1999 if (policy_mgr_is_hw_dbs_2x2_capable(mac_ctx->psoc)) {
2000 if (WLAN_REG_IS_24GHZ_CH
2001 (scan_result->Result.BssDescriptor.channelId)) {
2002 channel_id =
2003 scan_result->
2004 Result.BssDescriptor.channelId;
2005 break;
2006 }
2007 } else {
2008 if (WLAN_REG_IS_24GHZ_CH
2009 (scan_result->Result.BssDescriptor.channelId) &&
2010 policy_mgr_is_any_mode_active_on_band_along_with_session
2011 (mac_ctx->psoc,
2012 session_id, POLICY_MGR_BAND_5)) {
2013 channel_id =
2014 scan_result->
2015 Result.BssDescriptor.channelId;
2016 break;
2017 }
2018 if (WLAN_REG_IS_5GHZ_CH
2019 (scan_result->Result.BssDescriptor.channelId) &&
2020 policy_mgr_is_any_mode_active_on_band_along_with_session
2021 (mac_ctx->psoc,
2022 session_id, POLICY_MGR_BAND_24)) {
2023 channel_id =
2024 scan_result->
2025 Result.BssDescriptor.channelId;
2026 break;
2027 }
2028 }
2029 next_element = csr_ll_next(&bss_list->List, next_element,
2030 LL_ACCESS_NOLOCK);
2031 }
2032end:
2033 return channel_id;
2034}
2035
Liangwei Dong1ba99482018-10-19 02:57:29 -04002036uint8_t
Jeff Johnson8c3ecdd2018-12-05 08:48:54 -08002037csr_scan_get_channel_for_hw_mode_change(struct mac_context *mac_ctx,
2038 uint32_t session_id,
2039 struct csr_roam_profile *profile)
Liangwei Dong1ba99482018-10-19 02:57:29 -04002040{
2041 tScanResultHandle result_handle = NULL;
2042 QDF_STATUS status;
2043 uint8_t first_ap_ch = 0;
2044 uint8_t candidate_chan;
2045
2046 status = sme_get_ap_channel_from_scan_cache(profile, &result_handle,
2047 &first_ap_ch);
2048 if (status != QDF_STATUS_SUCCESS || !result_handle || !first_ap_ch) {
2049 if (result_handle)
2050 sme_scan_result_purge(result_handle);
2051 sme_err("fail get scan result: status %d first ap ch %d",
2052 status, first_ap_ch);
2053 return 0;
2054 }
2055 if (!policy_mgr_check_for_session_conc(mac_ctx->psoc, session_id,
2056 first_ap_ch)) {
2057 sme_scan_result_purge(result_handle);
2058 sme_err("Conc not allowed for the session %d ch %d",
2059 session_id, first_ap_ch);
2060 return 0;
2061 }
2062
2063 candidate_chan = csr_get_channel_for_hw_mode_change(mac_ctx,
2064 result_handle,
2065 session_id);
2066 sme_scan_result_purge(result_handle);
2067 if (!candidate_chan)
2068 candidate_chan = first_ap_ch;
2069 sme_debug("session %d hw mode check candidate_chan %d", session_id,
2070 candidate_chan);
2071
2072 return candidate_chan;
2073}
2074
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302075static enum wlan_auth_type csr_covert_auth_type_new(eCsrAuthType auth)
2076{
2077 switch (auth) {
2078 case eCSR_AUTH_TYPE_NONE:
2079 case eCSR_AUTH_TYPE_OPEN_SYSTEM:
2080 return WLAN_AUTH_TYPE_OPEN_SYSTEM;
2081 case eCSR_AUTH_TYPE_SHARED_KEY:
2082 return WLAN_AUTH_TYPE_SHARED_KEY;
2083 case eCSR_AUTH_TYPE_AUTOSWITCH:
2084 return WLAN_AUTH_TYPE_AUTOSWITCH;
2085 case eCSR_AUTH_TYPE_WPA:
2086 return WLAN_AUTH_TYPE_WPA;
2087 case eCSR_AUTH_TYPE_WPA_PSK:
2088 return WLAN_AUTH_TYPE_WPA_PSK;
2089 case eCSR_AUTH_TYPE_WPA_NONE:
2090 return WLAN_AUTH_TYPE_WPA_NONE;
2091 case eCSR_AUTH_TYPE_RSN:
2092 return WLAN_AUTH_TYPE_RSN;
2093 case eCSR_AUTH_TYPE_RSN_PSK:
2094 return WLAN_AUTH_TYPE_RSN_PSK;
2095 case eCSR_AUTH_TYPE_FT_RSN:
2096 return WLAN_AUTH_TYPE_FT_RSN;
2097 case eCSR_AUTH_TYPE_FT_RSN_PSK:
2098 return WLAN_AUTH_TYPE_FT_RSN_PSK;
2099 case eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE:
2100 return WLAN_AUTH_TYPE_WAPI_WAI_CERTIFICATE;
2101 case eCSR_AUTH_TYPE_WAPI_WAI_PSK:
2102 return WLAN_AUTH_TYPE_WAPI_WAI_PSK;
2103 case eCSR_AUTH_TYPE_CCKM_WPA:
2104 return WLAN_AUTH_TYPE_CCKM_WPA;
2105 case eCSR_AUTH_TYPE_CCKM_RSN:
2106 return WLAN_AUTH_TYPE_CCKM_RSN;
2107 case eCSR_AUTH_TYPE_RSN_PSK_SHA256:
2108 return WLAN_AUTH_TYPE_RSN_PSK_SHA256;
2109 case eCSR_AUTH_TYPE_RSN_8021X_SHA256:
2110 return WLAN_AUTH_TYPE_RSN_8021X_SHA256;
Sridhar Selvaraj6cf642f2017-08-21 14:28:10 +05302111 case eCSR_AUTH_TYPE_FILS_SHA256:
2112 return WLAN_AUTH_TYPE_FILS_SHA256;
2113 case eCSR_AUTH_TYPE_FILS_SHA384:
2114 return WLAN_AUTH_TYPE_FILS_SHA384;
2115 case eCSR_AUTH_TYPE_FT_FILS_SHA256:
2116 return WLAN_AUTH_TYPE_FT_FILS_SHA256;
2117 case eCSR_AUTH_TYPE_FT_FILS_SHA384:
2118 return WLAN_AUTH_TYPE_FT_FILS_SHA384;
Abhishek Singh02cb9e02017-08-30 17:39:50 +05302119 case eCSR_AUTH_TYPE_DPP_RSN:
2120 return WLAN_AUTH_TYPE_DPP_RSN;
Padma, Santhosh Kumarc69ce072017-11-06 18:21:05 +05302121 case eCSR_AUTH_TYPE_OWE:
2122 return WLAN_AUTH_TYPE_OWE;
Padma, Santhosh Kumare587a5c2017-12-21 12:44:46 +05302123 case eCSR_AUTH_TYPE_SUITEB_EAP_SHA256:
2124 return WLAN_AUTH_TYPE_SUITEB_EAP_SHA256;
2125 case eCSR_AUTH_TYPE_SUITEB_EAP_SHA384:
2126 return WLAN_AUTH_TYPE_SUITEB_EAP_SHA384;
Padma, Santhosh Kumar07eb80b2017-07-05 16:10:06 +05302127 case eCSR_AUTH_TYPE_SAE:
2128 return WLAN_AUTH_TYPE_SAE;
Srinivas Dasarib328f1a2018-12-18 17:45:06 +05302129 case eCSR_AUTH_TYPE_OSEN:
2130 return WLAN_AUTH_TYPE_OSEN;
Pragaspathi Thilagaraj96259b22019-02-15 01:08:27 +05302131 case eCSR_AUTH_TYPE_FT_SAE:
2132 return WLAN_AUTH_TYPE_FT_SAE;
2133 case eCSR_AUTH_TYPE_FT_SUITEB_EAP_SHA384:
2134 return WLAN_AUTH_TYPE_FT_SUITEB_EAP_SHA384;
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302135 case eCSR_NUM_OF_SUPPORT_AUTH_TYPE:
2136 default:
2137 return WLAN_AUTH_TYPE_OPEN_SYSTEM;
2138 }
2139}
2140
2141static eCsrAuthType csr_covert_auth_type_old(enum wlan_auth_type auth)
2142{
2143 switch (auth) {
2144 case WLAN_AUTH_TYPE_OPEN_SYSTEM:
2145 return eCSR_AUTH_TYPE_OPEN_SYSTEM;
2146 case WLAN_AUTH_TYPE_SHARED_KEY:
2147 return eCSR_AUTH_TYPE_SHARED_KEY;
2148 case WLAN_AUTH_TYPE_AUTOSWITCH:
2149 return eCSR_AUTH_TYPE_AUTOSWITCH;
2150 case WLAN_AUTH_TYPE_WPA:
2151 return eCSR_AUTH_TYPE_WPA;
2152 case WLAN_AUTH_TYPE_WPA_PSK:
2153 return eCSR_AUTH_TYPE_WPA_PSK;
2154 case WLAN_AUTH_TYPE_WPA_NONE:
2155 return eCSR_AUTH_TYPE_WPA_NONE;
2156 case WLAN_AUTH_TYPE_RSN:
2157 return eCSR_AUTH_TYPE_RSN;
2158 case WLAN_AUTH_TYPE_RSN_PSK:
2159 return eCSR_AUTH_TYPE_RSN_PSK;
2160 case WLAN_AUTH_TYPE_FT_RSN:
2161 return eCSR_AUTH_TYPE_FT_RSN;
2162 case WLAN_AUTH_TYPE_FT_RSN_PSK:
2163 return eCSR_AUTH_TYPE_FT_RSN_PSK;
2164 case WLAN_AUTH_TYPE_WAPI_WAI_CERTIFICATE:
2165 return eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE;
2166 case WLAN_AUTH_TYPE_WAPI_WAI_PSK:
2167 return eCSR_AUTH_TYPE_WAPI_WAI_PSK;
2168 case WLAN_AUTH_TYPE_CCKM_WPA:
2169 return eCSR_AUTH_TYPE_CCKM_WPA;
2170 case WLAN_AUTH_TYPE_CCKM_RSN:
2171 return eCSR_AUTH_TYPE_CCKM_RSN;
2172 case WLAN_AUTH_TYPE_RSN_PSK_SHA256:
2173 return eCSR_AUTH_TYPE_RSN_PSK_SHA256;
2174 case WLAN_AUTH_TYPE_RSN_8021X_SHA256:
2175 return eCSR_AUTH_TYPE_RSN_8021X_SHA256;
Sridhar Selvaraj6cf642f2017-08-21 14:28:10 +05302176 case WLAN_AUTH_TYPE_FILS_SHA256:
2177 return eCSR_AUTH_TYPE_FILS_SHA256;
2178 case WLAN_AUTH_TYPE_FILS_SHA384:
2179 return eCSR_AUTH_TYPE_FILS_SHA384;
2180 case WLAN_AUTH_TYPE_FT_FILS_SHA256:
2181 return eCSR_AUTH_TYPE_FT_FILS_SHA256;
2182 case WLAN_AUTH_TYPE_FT_FILS_SHA384:
2183 return eCSR_AUTH_TYPE_FT_FILS_SHA384;
Abhishek Singh02cb9e02017-08-30 17:39:50 +05302184 case WLAN_AUTH_TYPE_DPP_RSN:
2185 return eCSR_AUTH_TYPE_DPP_RSN;
Padma, Santhosh Kumarc69ce072017-11-06 18:21:05 +05302186 case WLAN_AUTH_TYPE_OWE:
2187 return eCSR_AUTH_TYPE_OWE;
Padma, Santhosh Kumare587a5c2017-12-21 12:44:46 +05302188 case WLAN_AUTH_TYPE_SUITEB_EAP_SHA256:
2189 return eCSR_AUTH_TYPE_SUITEB_EAP_SHA256;
2190 case WLAN_AUTH_TYPE_SUITEB_EAP_SHA384:
2191 return eCSR_AUTH_TYPE_SUITEB_EAP_SHA384;
Padma, Santhosh Kumar07eb80b2017-07-05 16:10:06 +05302192 case WLAN_AUTH_TYPE_SAE:
2193 return eCSR_AUTH_TYPE_SAE;
Srinivas Dasarib328f1a2018-12-18 17:45:06 +05302194 case WLAN_AUTH_TYPE_OSEN:
2195 return eCSR_AUTH_TYPE_OSEN;
Pragaspathi Thilagaraj96259b22019-02-15 01:08:27 +05302196 case WLAN_AUTH_TYPE_FT_SAE:
2197 return eCSR_AUTH_TYPE_FT_SAE;
2198 case WLAN_AUTH_TYPE_FT_SUITEB_EAP_SHA384:
2199 return eCSR_AUTH_TYPE_FT_SUITEB_EAP_SHA384;
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302200 case WLAN_NUM_OF_SUPPORT_AUTH_TYPE:
2201 default:
2202 return eCSR_AUTH_TYPE_OPEN_SYSTEM;
2203 }
2204}
2205
2206static enum wlan_enc_type csr_covert_enc_type_new(eCsrEncryptionType enc)
2207{
2208 switch (enc) {
2209 case eCSR_ENCRYPT_TYPE_NONE:
2210 return WLAN_ENCRYPT_TYPE_NONE;
2211 case eCSR_ENCRYPT_TYPE_WEP40_STATICKEY:
2212 return WLAN_ENCRYPT_TYPE_WEP40_STATICKEY;
2213 case eCSR_ENCRYPT_TYPE_WEP104_STATICKEY:
2214 return WLAN_ENCRYPT_TYPE_WEP104_STATICKEY;
2215 case eCSR_ENCRYPT_TYPE_WEP40:
2216 return WLAN_ENCRYPT_TYPE_WEP40;
2217 case eCSR_ENCRYPT_TYPE_WEP104:
2218 return WLAN_ENCRYPT_TYPE_WEP104;
2219 case eCSR_ENCRYPT_TYPE_TKIP:
2220 return WLAN_ENCRYPT_TYPE_TKIP;
2221 case eCSR_ENCRYPT_TYPE_AES:
2222 return WLAN_ENCRYPT_TYPE_AES;
2223 case eCSR_ENCRYPT_TYPE_WPI:
2224 return WLAN_ENCRYPT_TYPE_WPI;
2225 case eCSR_ENCRYPT_TYPE_KRK:
2226 return WLAN_ENCRYPT_TYPE_KRK;
2227 case eCSR_ENCRYPT_TYPE_BTK:
2228 return WLAN_ENCRYPT_TYPE_BTK;
2229 case eCSR_ENCRYPT_TYPE_AES_CMAC:
2230 return WLAN_ENCRYPT_TYPE_AES_CMAC;
Mukul Sharma05504ac2017-06-08 12:35:53 +05302231 case eCSR_ENCRYPT_TYPE_AES_GCMP:
2232 return WLAN_ENCRYPT_TYPE_AES_GCMP;
2233 case eCSR_ENCRYPT_TYPE_AES_GCMP_256:
2234 return WLAN_ENCRYPT_TYPE_AES_GCMP_256;
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302235 case eCSR_ENCRYPT_TYPE_ANY:
2236 default:
2237 return WLAN_ENCRYPT_TYPE_NONE;
2238 }
2239}
2240
2241static eCsrEncryptionType csr_covert_enc_type_old(enum wlan_enc_type enc)
2242{
2243 switch (enc) {
2244 case WLAN_ENCRYPT_TYPE_NONE:
2245 return eCSR_ENCRYPT_TYPE_NONE;
2246 case WLAN_ENCRYPT_TYPE_WEP40_STATICKEY:
2247 return eCSR_ENCRYPT_TYPE_WEP40_STATICKEY;
2248 case WLAN_ENCRYPT_TYPE_WEP104_STATICKEY:
2249 return eCSR_ENCRYPT_TYPE_WEP104_STATICKEY;
2250 case WLAN_ENCRYPT_TYPE_WEP40:
2251 return eCSR_ENCRYPT_TYPE_WEP40;
2252 case WLAN_ENCRYPT_TYPE_WEP104:
2253 return eCSR_ENCRYPT_TYPE_WEP104;
2254 case WLAN_ENCRYPT_TYPE_TKIP:
2255 return eCSR_ENCRYPT_TYPE_TKIP;
2256 case WLAN_ENCRYPT_TYPE_AES:
2257 return eCSR_ENCRYPT_TYPE_AES;
2258 case WLAN_ENCRYPT_TYPE_WPI:
2259 return eCSR_ENCRYPT_TYPE_WPI;
2260 case WLAN_ENCRYPT_TYPE_KRK:
2261 return eCSR_ENCRYPT_TYPE_KRK;
2262 case WLAN_ENCRYPT_TYPE_BTK:
2263 return eCSR_ENCRYPT_TYPE_BTK;
2264 case WLAN_ENCRYPT_TYPE_AES_CMAC:
2265 return eCSR_ENCRYPT_TYPE_AES_CMAC;
Mukul Sharma05504ac2017-06-08 12:35:53 +05302266 case WLAN_ENCRYPT_TYPE_AES_GCMP:
2267 return eCSR_ENCRYPT_TYPE_AES_GCMP;
2268 case WLAN_ENCRYPT_TYPE_AES_GCMP_256:
2269 return eCSR_ENCRYPT_TYPE_AES_GCMP_256;
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302270 case WLAN_ENCRYPT_TYPE_ANY:
2271 default:
2272 return eCSR_ENCRYPT_TYPE_NONE;
2273 }
2274}
2275
Padma, Santhosh Kumar4117d7a2017-12-20 17:39:33 +05302276#ifdef WLAN_FEATURE_11W
2277/**
2278 * csr_update_pmf_cap: Updates PMF cap
2279 * @src_filter: Source filter
2280 * @dst_filter: Destination filter
2281 *
2282 * Return: None
2283 */
2284static void csr_update_pmf_cap(tCsrScanResultFilter *src_filter,
Jeff Johnson8c3ecdd2018-12-05 08:48:54 -08002285 struct scan_filter *dst_filter) {
Padma, Santhosh Kumar4117d7a2017-12-20 17:39:33 +05302286
2287 if (src_filter->MFPCapable || src_filter->MFPEnabled)
2288 dst_filter->pmf_cap = WLAN_PMF_CAPABLE;
2289 if (src_filter->MFPRequired)
2290 dst_filter->pmf_cap = WLAN_PMF_REQUIRED;
2291}
2292#else
2293static inline void csr_update_pmf_cap(tCsrScanResultFilter *src_filter,
Jeff Johnson8c3ecdd2018-12-05 08:48:54 -08002294 struct scan_filter *dst_filter)
Padma, Santhosh Kumar4117d7a2017-12-20 17:39:33 +05302295{}
2296#endif
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302297
Sandeep Puligilla2fcc2542018-03-27 17:54:06 -07002298/**
2299 * csr_convert_dotllmod_phymode: Convert eCsrPhyMode to wlan_phymode
2300 * @dotllmode: phy mode
2301 *
2302 * Return: returns enum wlan_phymode
2303 */
2304static enum wlan_phymode csr_convert_dotllmod_phymode(eCsrPhyMode dotllmode)
2305{
2306
2307 enum wlan_phymode con_phy_mode;
2308
2309 switch (dotllmode) {
2310 case eCSR_DOT11_MODE_abg:
2311 con_phy_mode = WLAN_PHYMODE_AUTO;
2312 break;
2313 case eCSR_DOT11_MODE_11a:
2314 con_phy_mode = WLAN_PHYMODE_11A;
2315 break;
2316 case eCSR_DOT11_MODE_11b:
2317 con_phy_mode = WLAN_PHYMODE_11B;
2318 break;
2319 case eCSR_DOT11_MODE_11g:
2320 con_phy_mode = WLAN_PHYMODE_11G;
2321 break;
2322 case eCSR_DOT11_MODE_11n:
2323 con_phy_mode = WLAN_PHYMODE_11NA_HT20;
2324 break;
2325 case eCSR_DOT11_MODE_11g_ONLY:
2326 con_phy_mode = WLAN_PHYMODE_11G;
2327 break;
2328 case eCSR_DOT11_MODE_11n_ONLY:
2329 con_phy_mode = WLAN_PHYMODE_11NA_HT20;
2330 break;
2331 case eCSR_DOT11_MODE_11b_ONLY:
2332 con_phy_mode = WLAN_PHYMODE_11B;
2333 break;
2334 case eCSR_DOT11_MODE_11ac:
2335 con_phy_mode = WLAN_PHYMODE_11AC_VHT160;
2336 break;
2337 case eCSR_DOT11_MODE_11ac_ONLY:
2338 con_phy_mode = WLAN_PHYMODE_11AC_VHT160;
2339 break;
2340 case eCSR_DOT11_MODE_AUTO:
2341 con_phy_mode = WLAN_PHYMODE_AUTO;
2342 break;
2343 case eCSR_DOT11_MODE_11ax:
2344 con_phy_mode = WLAN_PHYMODE_11AXA_HE160;
2345 break;
2346 case eCSR_DOT11_MODE_11ax_ONLY:
2347 con_phy_mode = WLAN_PHYMODE_11AXA_HE160;
2348 break;
2349 default:
2350 con_phy_mode = WLAN_PHYMODE_AUTO;
2351 break;
2352 }
2353
2354 return con_phy_mode;
2355}
2356
Pragaspathi Thilagaraj1f3f99f2019-04-24 23:48:47 +05302357#ifdef WLAN_ADAPTIVE_11R
2358/**
2359 * csr_update_adaptive_11r_scan_filter - Copy adaptive 11r ini to scan
2360 * module
2361 * @mac_ctx: Pointer to mac_context
2362 * @scan_filter: Scan filter to be sent to scan module
2363 *
2364 * Return: None
2365 */
2366static void
2367csr_update_adaptive_11r_scan_filter(struct mac_context *mac_ctx,
2368 struct scan_filter *filter)
2369{
2370 filter->enable_adaptive_11r =
2371 mac_ctx->mlme_cfg->lfr.enable_adaptive_11r;
2372}
2373#else
2374static inline void
2375csr_update_adaptive_11r_scan_filter(struct mac_context *mac_ctx,
2376 struct scan_filter *filter)
2377{
2378 filter->enable_adaptive_11r = false;
2379}
2380#endif
2381
Jeff Johnsonedece842018-12-02 11:13:52 -08002382static QDF_STATUS csr_prepare_scan_filter(struct mac_context *mac_ctx,
Jeff Johnson8c3ecdd2018-12-05 08:48:54 -08002383 tCsrScanResultFilter *pFilter,
2384 struct scan_filter *filter)
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302385{
2386 int i;
2387 uint32_t len = 0;
2388 QDF_STATUS status;
Tushnim Bhattacharyya0c4ad2d2017-03-09 15:59:03 -08002389 enum policy_mgr_con_mode new_mode;
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302390
2391 filter->num_of_bssid = pFilter->BSSIDs.numOfBSSIDs;
2392 if (filter->num_of_bssid > WLAN_SCAN_FILTER_NUM_BSSID)
2393 filter->num_of_bssid = WLAN_SCAN_FILTER_NUM_BSSID;
2394 for (i = 0; i < filter->num_of_bssid; i++)
2395 qdf_mem_copy(filter->bssid_list[i].bytes,
2396 pFilter->BSSIDs.bssid[i].bytes,
2397 QDF_MAC_ADDR_SIZE);
2398
2399 filter->num_of_ssid = pFilter->SSIDs.numOfSSIDs;
2400 if (filter->num_of_ssid > WLAN_SCAN_FILTER_NUM_SSID)
2401 filter->num_of_ssid = WLAN_SCAN_FILTER_NUM_SSID;
2402 for (i = 0; i < filter->num_of_ssid; i++) {
2403 filter->ssid_list[i].length =
2404 pFilter->SSIDs.SSIDList[i].SSID.length;
2405 qdf_mem_copy(filter->ssid_list[i].ssid,
2406 pFilter->SSIDs.SSIDList[i].SSID.ssId,
2407 filter->ssid_list[i].length);
2408 }
2409
2410 filter->num_of_channels =
2411 pFilter->ChannelInfo.numOfChannels;
2412 if (filter->num_of_channels > QDF_MAX_NUM_CHAN)
2413 filter->num_of_channels = QDF_MAX_NUM_CHAN;
2414 qdf_mem_copy(filter->channel_list,
2415 pFilter->ChannelInfo.ChannelList,
2416 filter->num_of_channels);
2417
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05302418 if (pFilter->realm_check) {
2419 filter->fils_scan_filter.realm_check = true;
2420 qdf_mem_copy(filter->fils_scan_filter.fils_realm,
2421 pFilter->fils_realm, REAM_HASH_LEN);
2422 }
2423
Abhishek Singhedb73602018-02-20 15:20:26 +05302424 if (pFilter->force_rsne_override) {
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302425
Abhishek Singh821f09c2018-02-26 15:18:40 +05302426 sme_debug("force_rsne_override set auth type and enctype to any and ignore pmf cap");
Abhishek Singhedb73602018-02-20 15:20:26 +05302427
Abhishek Singh821f09c2018-02-26 15:18:40 +05302428 filter->num_of_auth = 1;
2429 filter->auth_type[0] = WLAN_AUTH_TYPE_ANY;
2430 filter->num_of_enc_type = 1;
2431 filter->enc_type[0] = WLAN_ENCRYPT_TYPE_ANY;
2432 filter->num_of_mc_enc_type = 1;
2433 filter->mc_enc_type[0] = WLAN_ENCRYPT_TYPE_ANY;
2434
Abhishek Singh63781032018-02-23 14:59:22 +05302435 filter->ignore_pmf_cap = true;
Abhishek Singhedb73602018-02-20 15:20:26 +05302436 } else {
2437 filter->num_of_auth =
2438 pFilter->authType.numEntries;
2439 if (filter->num_of_auth > WLAN_NUM_OF_SUPPORT_AUTH_TYPE)
2440 filter->num_of_auth = WLAN_NUM_OF_SUPPORT_AUTH_TYPE;
2441 for (i = 0; i < filter->num_of_auth; i++)
2442 filter->auth_type[i] =
2443 csr_covert_auth_type_new(
2444 pFilter->authType.authType[i]);
2445 filter->num_of_enc_type =
2446 pFilter->EncryptionType.numEntries;
2447 if (filter->num_of_enc_type > WLAN_NUM_OF_ENCRYPT_TYPE)
2448 filter->num_of_enc_type = WLAN_NUM_OF_ENCRYPT_TYPE;
2449 for (i = 0; i < filter->num_of_enc_type; i++)
2450 filter->enc_type[i] =
2451 csr_covert_enc_type_new(
2452 pFilter->EncryptionType.encryptionType[i]);
2453 filter->num_of_mc_enc_type =
2454 pFilter->mcEncryptionType.numEntries;
2455 if (filter->num_of_mc_enc_type > WLAN_NUM_OF_ENCRYPT_TYPE)
2456 filter->num_of_mc_enc_type = WLAN_NUM_OF_ENCRYPT_TYPE;
2457 for (i = 0; i < filter->num_of_mc_enc_type; i++)
2458 filter->mc_enc_type[i] =
2459 csr_covert_enc_type_new(
2460 pFilter->mcEncryptionType.encryptionType[i]);
2461 }
Jeff Johnson9e760832018-12-15 12:41:36 -08002462 qdf_mem_copy(filter->country, pFilter->countryCode,
Wu Gaoaa155142019-01-14 15:09:26 +08002463 CFG_COUNTRY_CODE_LEN);
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302464
gaurank kathpalia26900982017-12-19 13:57:48 +05302465 if (pFilter->bWPSAssociation || pFilter->bOSENAssociation)
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302466 filter->ignore_auth_enc_type = true;
2467
2468 filter->rrm_measurement_filter = pFilter->fMeasurement;
2469
Jeff Johnson9e760832018-12-15 12:41:36 -08002470 filter->mobility_domain = pFilter->mdid.mobility_domain;
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302471
2472 filter->p2p_results = pFilter->p2pResult;
2473
Padma, Santhosh Kumar4117d7a2017-12-20 17:39:33 +05302474 csr_update_pmf_cap(pFilter, filter);
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302475
2476 if (pFilter->BSSType == eCSR_BSS_TYPE_INFRASTRUCTURE)
2477 filter->bss_type = WLAN_TYPE_BSS;
2478 else if (pFilter->BSSType == eCSR_BSS_TYPE_IBSS ||
2479 pFilter->BSSType == eCSR_BSS_TYPE_START_IBSS)
2480 filter->bss_type = WLAN_TYPE_IBSS;
2481 else
2482 filter->bss_type = WLAN_TYPE_ANY;
2483
Sandeep Puligilla2fcc2542018-03-27 17:54:06 -07002484 filter->dot11_mode = csr_convert_dotllmod_phymode(pFilter->phyMode);
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302485
gaurank kathpalia5efa73b2017-12-29 10:55:16 +05302486 // enable bss scoring for only STA mode
2487 if (pFilter->csrPersona == QDF_STA_MODE)
2488 filter->bss_scoring_required = true;
2489 else
2490 filter->bss_scoring_required = false;
Pragaspathi Thilagaraj1f3f99f2019-04-24 23:48:47 +05302491
2492 csr_update_adaptive_11r_scan_filter(mac_ctx, filter);
2493
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302494 if (!pFilter->BSSIDs.numOfBSSIDs) {
Tushnim Bhattacharyya0c4ad2d2017-03-09 15:59:03 -08002495 if (policy_mgr_map_concurrency_mode(
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302496 &pFilter->csrPersona, &new_mode)) {
Tushnim Bhattacharyya0c4ad2d2017-03-09 15:59:03 -08002497 status = policy_mgr_get_pcl(mac_ctx->psoc, new_mode,
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302498 filter->pcl_channel_list, &len,
Abhishek Singhb58164a2017-07-19 18:47:23 +05302499 filter->pcl_weight_list, QDF_MAX_NUM_CHAN);
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302500 filter->num_of_pcl_channels = (uint8_t)len;
2501 }
2502 }
Abhishek Singhb58164a2017-07-19 18:47:23 +05302503 qdf_mem_copy(filter->bssid_hint.bytes,
2504 pFilter->bssid_hint.bytes,
2505 QDF_MAC_ADDR_SIZE);
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302506
2507 return QDF_STATUS_SUCCESS;
2508}
2509
Sridhar Selvaraja44c19e2017-08-21 14:20:20 +05302510#ifdef WLAN_FEATURE_FILS_SK
2511/**
2512 * csr_update_bss_with_fils_data: Fill FILS params in bss desc from scan entry
2513 * @mac_ctx: mac context
2514 * @scan_entry: scan entry
2515 * @bss_descr: bss description
2516 */
Jeff Johnsonedece842018-12-02 11:13:52 -08002517static void csr_update_bss_with_fils_data(struct mac_context *mac_ctx,
Sridhar Selvaraja44c19e2017-08-21 14:20:20 +05302518 struct scan_cache_entry *scan_entry,
2519 tSirBssDescription *bss_descr)
2520{
Naveen Rawat72475db2017-12-13 18:07:35 -08002521 int ret;
Krunal Soni35a94532018-01-09 10:54:31 -08002522 tDot11fIEfils_indication fils_indication = {0};
Sridhar Selvaraja44c19e2017-08-21 14:20:20 +05302523 struct sir_fils_indication fils_ind;
2524
2525 if (!scan_entry->ie_list.fils_indication)
2526 return;
2527
Naveen Rawat72475db2017-12-13 18:07:35 -08002528 ret = dot11f_unpack_ie_fils_indication(mac_ctx,
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05302529 scan_entry->ie_list.fils_indication +
2530 SIR_FILS_IND_ELEM_OFFSET,
Sridhar Selvaraja44c19e2017-08-21 14:20:20 +05302531 *(scan_entry->ie_list.fils_indication + 1),
2532 &fils_indication, false);
Srinivas Girigowdaeff16d92018-09-12 14:56:29 -07002533 if (DOT11F_FAILED(ret)) {
Naveen Rawat72475db2017-12-13 18:07:35 -08002534 sme_err("unpack failed ret: 0x%x", ret);
2535 return;
2536 }
Sridhar Selvaraja44c19e2017-08-21 14:20:20 +05302537
2538 update_fils_data(&fils_ind, &fils_indication);
2539 if (fils_ind.realm_identifier.realm_cnt > SIR_MAX_REALM_COUNT)
2540 fils_ind.realm_identifier.realm_cnt = SIR_MAX_REALM_COUNT;
2541
2542 bss_descr->fils_info_element.realm_cnt =
2543 fils_ind.realm_identifier.realm_cnt;
2544 qdf_mem_copy(bss_descr->fils_info_element.realm,
2545 fils_ind.realm_identifier.realm,
2546 bss_descr->fils_info_element.realm_cnt * SIR_REALM_LEN);
2547 if (fils_ind.cache_identifier.is_present) {
2548 bss_descr->fils_info_element.is_cache_id_present = true;
2549 qdf_mem_copy(bss_descr->fils_info_element.cache_id,
2550 fils_ind.cache_identifier.identifier, CACHE_ID_LEN);
2551 }
2552 if (fils_ind.is_fils_sk_auth_supported)
2553 bss_descr->fils_info_element.is_fils_sk_supported = true;
2554}
2555#else
Jeff Johnsonedece842018-12-02 11:13:52 -08002556static void csr_update_bss_with_fils_data(struct mac_context *mac_ctx,
Sridhar Selvaraja44c19e2017-08-21 14:20:20 +05302557 struct scan_cache_entry *scan_entry,
2558 tSirBssDescription *bss_descr)
2559{ }
2560#endif
2561
Yeshwanth Sriram Guntukaa6c3d272019-04-13 12:25:53 +05302562/**
2563 * csr_is_assoc_disallowed() - Find if assoc disallowed
2564 * bit is set in AP's beacon or probe response
2565 * @mac_ctx: mac context
2566 * @scan_entry: scan entry
2567 *
2568 * Return: True if assoc disallowed is set else false
2569 */
2570static bool csr_is_assoc_disallowed(struct mac_context *mac_ctx,
2571 struct scan_cache_entry *scan_entry)
2572{
2573 int ret;
2574 tDot11fIEMBO_IE mbo_ie = {0};
2575 uint8_t *mbo_oce;
2576
2577 mbo_oce = util_scan_entry_mbo_oce(scan_entry);
2578
2579 if (!mbo_oce)
2580 return false;
2581
2582 ret = dot11f_unpack_ie_MBO_IE(mac_ctx, mbo_oce + SIR_MBO_ELEM_OFFSET,
2583 *(mbo_oce + 1) - SIR_MAC_MBO_OUI_SIZE,
2584 &mbo_ie, false);
2585
2586 if (DOT11F_FAILED(ret)) {
2587 sme_err("unpack failed ret: 0x%x", ret);
2588 return false;
2589 }
2590
2591 return mbo_ie.assoc_disallowed.present;
2592}
2593
Jeff Johnsonedece842018-12-02 11:13:52 -08002594static QDF_STATUS csr_fill_bss_from_scan_entry(struct mac_context *mac_ctx,
Jeff Johnson8c3ecdd2018-12-05 08:48:54 -08002595 struct scan_cache_entry *scan_entry,
2596 struct tag_csrscan_result **p_result)
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302597{
2598 tDot11fBeaconIEs *bcn_ies;
2599 tSirBssDescription *bss_desc;
2600 tCsrScanResultInfo *result_info;
2601 tpSirMacMgmtHdr hdr;
2602 uint8_t *ie_ptr;
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05302603 struct tag_csrscan_result *bss;
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302604 uint32_t bss_len, alloc_len, ie_len;
2605 QDF_STATUS status;
2606
2607 ie_len = util_scan_entry_ie_len(scan_entry);
2608 ie_ptr = util_scan_entry_ie_data(scan_entry);
2609
2610 hdr = (tpSirMacMgmtHdr)scan_entry->raw_frame.ptr;
2611
2612 bss_len = (uint16_t)(offsetof(tSirBssDescription,
2613 ieFields[0]) + ie_len);
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05302614 alloc_len = sizeof(struct tag_csrscan_result) + bss_len;
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302615 bss = qdf_mem_malloc(alloc_len);
Arif Hussain0ef77082018-10-10 16:42:53 -07002616 if (!bss)
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302617 return QDF_STATUS_E_NOMEM;
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302618
2619 bss->AgingCount =
2620 (int32_t) mac_ctx->roam.configParam.agingCount;
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302621 bss->ucEncryptionType =
2622 csr_covert_enc_type_old(scan_entry->neg_sec_info.uc_enc);
2623 bss->mcEncryptionType =
2624 csr_covert_enc_type_old(scan_entry->neg_sec_info.mc_enc);
2625 bss->authType =
2626 csr_covert_auth_type_old(scan_entry->neg_sec_info.auth_type);
Abhishek Singhb58164a2017-07-19 18:47:23 +05302627 bss->bss_score = scan_entry->bss_score;
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302628
2629 result_info = &bss->Result;
2630 result_info->ssId.length = scan_entry->ssid.length;
2631 qdf_mem_copy(result_info->ssId.ssId,
2632 scan_entry->ssid.ssid,
2633 result_info->ssId.length);
2634 result_info->timer = scan_entry->hidden_ssid_timestamp;
2635
2636 bss_desc = &result_info->BssDescriptor;
2637
2638 bss_desc->length = (uint16_t) (offsetof(tSirBssDescription,
2639 ieFields[0]) - sizeof(bss_desc->length) + ie_len);
2640
2641 qdf_mem_copy(bss_desc->bssId,
2642 scan_entry->bssid.bytes,
2643 QDF_MAC_ADDR_SIZE);
Sandeep Puligilla1fcdb772017-02-22 21:14:59 -08002644 bss_desc->scansystimensec = scan_entry->scan_entry_time;
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302645 qdf_mem_copy(bss_desc->timeStamp,
2646 scan_entry->tsf_info.data, 8);
2647
2648 bss_desc->beaconInterval = scan_entry->bcn_int;
2649 bss_desc->capabilityInfo = scan_entry->cap_info.value;
2650
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07002651 if (WLAN_REG_IS_5GHZ_CH(scan_entry->channel.chan_idx))
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302652 bss_desc->nwType = eSIR_11A_NW_TYPE;
2653 else if (scan_entry->phy_mode == WLAN_PHYMODE_11B)
2654 bss_desc->nwType = eSIR_11B_NW_TYPE;
2655 else
2656 bss_desc->nwType = eSIR_11G_NW_TYPE;
2657
2658 bss_desc->rssi = scan_entry->rssi_raw;
2659 bss_desc->rssi_raw = scan_entry->rssi_raw;
2660
2661 /* channelId what peer sent in beacon/probersp. */
2662 bss_desc->channelId =
2663 scan_entry->channel.chan_idx;
2664 /* channelId on which we are parked at. */
2665 /* used only in scan case. */
2666 bss_desc->channelIdSelf =
2667 scan_entry->channel.chan_idx;
2668 bss_desc->rx_channel = bss_desc->channelIdSelf;
2669 bss_desc->received_time =
2670 scan_entry->scan_entry_time;
2671 bss_desc->startTSF[0] =
2672 mac_ctx->rrm.rrmPEContext.startTSF[0];
2673 bss_desc->startTSF[1] =
2674 mac_ctx->rrm.rrmPEContext.startTSF[1];
2675 bss_desc->parentTSF =
2676 scan_entry->rrm_parent_tsf;
2677 bss_desc->fProbeRsp = (scan_entry->frm_subtype ==
Srinivas Girigowdadf90cea2019-03-07 16:03:25 -08002678 MGMT_SUBTYPE_PROBE_RESP);
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302679 bss_desc->seq_ctrl = hdr->seqControl;
2680 bss_desc->tsf_delta = scan_entry->tsf_delta;
Yeshwanth Sriram Guntukaa6c3d272019-04-13 12:25:53 +05302681 bss_desc->assoc_disallowed = csr_is_assoc_disallowed(mac_ctx,
2682 scan_entry);
Pragaspathi Thilagaraj1f3f99f2019-04-24 23:48:47 +05302683 bss_desc->adaptive_11r_ap = scan_entry->adaptive_11r_ap;
Sandeep Puligillad8546bb2019-02-15 10:49:38 -08002684 qdf_mem_copy(&bss_desc->mbssid_info, &scan_entry->mbssid_info,
2685 sizeof(struct scan_mbssid_info));
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302686
2687 qdf_mem_copy((uint8_t *) &bss_desc->ieFields,
2688 ie_ptr, ie_len);
2689
2690 status = csr_get_parsed_bss_description_ies(mac_ctx,
2691 bss_desc, &bcn_ies);
2692 if (QDF_IS_STATUS_ERROR(status)) {
2693 qdf_mem_free(bss);
2694 return status;
2695 }
2696 result_info->pvIes = bcn_ies;
2697
2698 if (bcn_ies->MobilityDomain.present) {
2699 bss_desc->mdiePresent = true;
2700 qdf_mem_copy((uint8_t *)&(bss_desc->mdie[0]),
2701 (uint8_t *)&(bcn_ies->MobilityDomain.MDID),
2702 sizeof(uint16_t));
2703 bss_desc->mdie[2] =
2704 ((bcn_ies->MobilityDomain.overDSCap << 0) |
2705 (bcn_ies->MobilityDomain.resourceReqCap << 1));
2706 }
2707#ifdef FEATURE_WLAN_ESE
2708 if (bcn_ies->QBSSLoad.present) {
2709 bss_desc->QBSSLoad_present = true;
2710 bss_desc->QBSSLoad_avail =
2711 bcn_ies->QBSSLoad.avail;
2712 }
2713#endif
Sridhar Selvaraja44c19e2017-08-21 14:20:20 +05302714 csr_update_bss_with_fils_data(mac_ctx, scan_entry, bss_desc);
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302715 if (scan_entry->alt_wcn_ie.ptr) {
2716 bss_desc->WscIeLen = scan_entry->alt_wcn_ie.len;
2717 qdf_mem_copy(bss_desc->WscIeProbeRsp,
2718 scan_entry->alt_wcn_ie.ptr,
2719 scan_entry->alt_wcn_ie.len);
2720 }
2721
2722 *p_result = bss;
2723 return QDF_STATUS_SUCCESS;
2724}
2725
Jeff Johnsonedece842018-12-02 11:13:52 -08002726static QDF_STATUS csr_parse_scan_list(struct mac_context *mac_ctx,
Jeff Johnson8c3ecdd2018-12-05 08:48:54 -08002727 struct scan_result_list *ret_list,
2728 qdf_list_t *scan_list)
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302729{
2730 QDF_STATUS status = QDF_STATUS_SUCCESS;
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05302731 struct tag_csrscan_result *pResult = NULL;
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302732 struct scan_cache_node *cur_node = NULL;
2733 struct scan_cache_node *next_node = NULL;
2734
2735 status =
2736 qdf_list_peek_front(scan_list,
2737 (qdf_list_node_t **) &cur_node);
2738
2739 while (cur_node) {
2740 qdf_list_peek_next(
2741 scan_list,
2742 (qdf_list_node_t *) cur_node,
2743 (qdf_list_node_t **) &next_node);
2744 status = csr_fill_bss_from_scan_entry(mac_ctx,
2745 cur_node->entry, &pResult);
2746 if (QDF_IS_STATUS_ERROR(status))
2747 return status;
2748 if (pResult)
2749 csr_ll_insert_tail(&ret_list->List, &pResult->Link,
2750 LL_ACCESS_NOLOCK);
2751 cur_node = next_node;
2752 next_node = NULL;
2753 }
2754
2755 return status;
2756}
Abhishek Singhf3756fc2017-06-28 16:04:06 +05302757
2758/**
2759 * csr_remove_ap_due_to_rssi() - check if bss is present in
2760 * list of BSSID which rejected Assoc due to RSSI
2761 * @list: rssi based rejected BSS list
2762 * @bss_descr: pointer to bss description
2763 *
2764 * Check if the time interval indicated in last Assoc reject
2765 * has expired OR rssi has improved by margin indicated
2766 * in last Assoc reject. If any of the condition match remove
2767 * the AP from the avoid list, else do not try to conenct
2768 * to the AP
2769 *
2770 * Return: true if connection cannot be tried with AP else false
2771 */
2772static bool csr_remove_ap_due_to_rssi(qdf_list_t *list,
Jeff Johnson8c3ecdd2018-12-05 08:48:54 -08002773 tSirBssDescription *bss_descr)
Abhishek Singhf3756fc2017-06-28 16:04:06 +05302774{
2775 QDF_STATUS status;
2776 struct sir_rssi_disallow_lst *cur_node = NULL;
2777 qdf_list_node_t *cur_lst = NULL, *next_lst = NULL;
2778 qdf_time_t cur_time;
2779 uint32_t time_diff;
2780
2781 if (!qdf_list_size(list))
2782 return false;
2783
2784 cur_time = qdf_do_div(qdf_get_monotonic_boottime(),
2785 QDF_MC_TIMER_TO_MS_UNIT);
2786
2787 qdf_list_peek_front(list, &cur_lst);
2788 while (cur_lst) {
2789 cur_node = qdf_container_of(cur_lst,
2790 struct sir_rssi_disallow_lst, node);
2791
2792 qdf_list_peek_next(list, cur_lst, &next_lst);
2793
2794 time_diff = cur_time - cur_node->time_during_rejection;
2795 if ((time_diff > cur_node->retry_delay)) {
2796 sme_debug("Remove %pM as time diff %d is greater retry delay %d",
2797 cur_node->bssid.bytes, time_diff,
2798 cur_node->retry_delay);
2799 status = qdf_list_remove_node(list, cur_lst);
2800 if (QDF_IS_STATUS_SUCCESS(status))
2801 qdf_mem_free(cur_node);
2802 cur_lst = next_lst;
2803 next_lst = NULL;
2804 cur_node = NULL;
2805 continue;
2806 }
2807
2808 if (!qdf_mem_cmp(cur_node->bssid.bytes,
2809 bss_descr->bssId, QDF_MAC_ADDR_SIZE))
2810 break;
2811 cur_lst = next_lst;
2812 next_lst = NULL;
2813 cur_node = NULL;
2814 }
2815
2816 if (cur_node) {
2817 time_diff = cur_time - cur_node->time_during_rejection;
2818 if (!(time_diff > cur_node->retry_delay ||
2819 bss_descr->rssi_raw >= cur_node->expected_rssi)) {
2820 sme_err("Don't Attempt to connect %pM (time diff %d retry delay %d rssi %d expected rssi %d)",
2821 cur_node->bssid.bytes, time_diff,
2822 cur_node->retry_delay, bss_descr->rssi_raw,
2823 cur_node->expected_rssi);
2824 return true;
2825 }
2826 sme_debug("Remove %pM as time diff %d is greater retry delay %d or RSSI %d is greater than expected %d",
2827 cur_node->bssid.bytes, time_diff,
2828 cur_node->retry_delay,
2829 bss_descr->rssi_raw,
2830 cur_node->expected_rssi);
2831 status = qdf_list_remove_node(list, cur_lst);
2832 if (QDF_IS_STATUS_SUCCESS(status))
2833 qdf_mem_free(cur_node);
2834 }
2835
2836 return false;
2837}
2838
2839/**
2840 * csr_filter_ap_due_to_rssi_reject() - filter the AP who has sent
2841 * assoc reject due to RSSI if condition has not improved
2842 * @mac_ctx: mac context
2843 * @scan_list: candidate list for the connection
2844 *
2845 * Return: void
2846 */
Jeff Johnsonedece842018-12-02 11:13:52 -08002847static void csr_filter_ap_due_to_rssi_reject(struct mac_context *mac_ctx,
Jeff Johnson8c3ecdd2018-12-05 08:48:54 -08002848 struct scan_result_list *scan_list)
Abhishek Singhf3756fc2017-06-28 16:04:06 +05302849{
2850 tListElem *cur_entry;
2851 tListElem *next_entry;
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05302852 struct tag_csrscan_result *scan_res;
Abhishek Singhf3756fc2017-06-28 16:04:06 +05302853 bool remove;
2854
2855 if (!scan_list ||
2856 !qdf_list_size(&mac_ctx->roam.rssi_disallow_bssid))
2857 return;
2858
Abhishek Singhf3756fc2017-06-28 16:04:06 +05302859 cur_entry = csr_ll_peek_head(&scan_list->List, LL_ACCESS_NOLOCK);
2860 while (cur_entry) {
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05302861 scan_res = GET_BASE_ADDR(cur_entry, struct tag_csrscan_result,
Abhishek Singhf3756fc2017-06-28 16:04:06 +05302862 Link);
2863 next_entry = csr_ll_next(&scan_list->List,
2864 cur_entry, LL_ACCESS_NOLOCK);
Jingxiang Gef95dc4d2019-02-26 14:20:31 +08002865
2866 qdf_mutex_acquire(&mac_ctx->roam.rssi_disallow_bssid_lock);
Abhishek Singhf3756fc2017-06-28 16:04:06 +05302867 remove = csr_remove_ap_due_to_rssi(
2868 &mac_ctx->roam.rssi_disallow_bssid,
2869 &scan_res->Result.BssDescriptor);
Jingxiang Gef95dc4d2019-02-26 14:20:31 +08002870 qdf_mutex_release(&mac_ctx->roam.rssi_disallow_bssid_lock);
2871
Abhishek Singhf3756fc2017-06-28 16:04:06 +05302872 if (remove) {
2873 csr_ll_remove_entry(&scan_list->List,
2874 cur_entry, LL_ACCESS_NOLOCK);
2875 csr_free_scan_result_entry(mac_ctx, scan_res);
2876 }
2877 cur_entry = next_entry;
2878 next_entry = NULL;
2879 }
Abhishek Singhf3756fc2017-06-28 16:04:06 +05302880}
2881
Yeshwanth Sriram Guntukaa6c3d272019-04-13 12:25:53 +05302882/**
2883 * csr_remove_ap_with_assoc_disallowed() - Remove APs with assoc
2884 * disallowed bit set
2885 * @mac_ctx: mac context
2886 * @scan_list: candidate list for the connection
2887 *
2888 * Return: None
2889 */
2890static void csr_remove_ap_with_assoc_disallowed(struct mac_context *mac_ctx,
2891 struct scan_result_list *scan_list)
2892{
2893 tListElem *cur_entry;
2894 tListElem *next_entry;
2895 struct tag_csrscan_result *scan_res;
2896
2897 if (!scan_list)
2898 return;
2899
2900 cur_entry = csr_ll_peek_head(&scan_list->List, LL_ACCESS_NOLOCK);
2901 while (cur_entry) {
2902 scan_res = GET_BASE_ADDR(cur_entry, struct tag_csrscan_result,
2903 Link);
2904 next_entry = csr_ll_next(&scan_list->List, cur_entry,
2905 LL_ACCESS_NOLOCK);
2906
2907 if (!mac_ctx->ignore_assoc_disallowed &&
2908 scan_res->Result.BssDescriptor.assoc_disallowed) {
2909 csr_ll_remove_entry(&scan_list->List, cur_entry,
2910 LL_ACCESS_NOLOCK);
2911 csr_free_scan_result_entry(mac_ctx, scan_res);
2912 }
2913 cur_entry = next_entry;
2914 next_entry = NULL;
2915 }
2916}
2917
Jeff Johnsonedece842018-12-02 11:13:52 -08002918QDF_STATUS csr_scan_get_result(struct mac_context *mac_ctx,
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302919 tCsrScanResultFilter *pFilter,
2920 tScanResultHandle *results)
2921{
2922 QDF_STATUS status;
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05302923 struct scan_result_list *ret_list = NULL;
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302924 qdf_list_t *list = NULL;
Sandeep Puligilla8345f3d2018-10-22 15:43:48 -07002925 struct scan_filter *filter = NULL;
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302926 struct wlan_objmgr_pdev *pdev = NULL;
Yeshwanth Sriram Guntukaa6c3d272019-04-13 12:25:53 +05302927 uint32_t num_bss;
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302928
2929 if (results)
2930 *results = CSR_INVALID_SCANRESULT_HANDLE;
2931
2932 pdev = wlan_objmgr_get_pdev_by_id(mac_ctx->psoc,
2933 0, WLAN_LEGACY_MAC_ID);
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302934 if (!pdev) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07002935 sme_err("pdev is NULL");
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302936 return QDF_STATUS_E_INVAL;
2937 }
2938
2939 if (pFilter) {
Sandeep Puligilla8345f3d2018-10-22 15:43:48 -07002940 filter = qdf_mem_malloc(sizeof(*filter));
2941 if (!filter) {
2942 status = QDF_STATUS_E_NOMEM;
2943 goto error;
2944 }
2945
2946 status = csr_prepare_scan_filter(mac_ctx, pFilter, filter);
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302947 if (QDF_IS_STATUS_ERROR(status)) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07002948 sme_err("Prepare filter failed");
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302949 goto error;
2950 }
2951 }
2952
2953 list = ucfg_scan_get_result(pdev,
Sandeep Puligilla8345f3d2018-10-22 15:43:48 -07002954 pFilter ? filter : NULL);
Krunal Soni35a94532018-01-09 10:54:31 -08002955 if (list)
2956 sme_debug("num_entries %d", qdf_list_size(list));
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302957
Krunal Soni35a94532018-01-09 10:54:31 -08002958 if (!list || (list && !qdf_list_size(list))) {
Jianmin Zhucc6b3d02019-03-07 14:19:34 +08002959 sme_debug("get scan result failed");
Abhishek Singhd1d10b42017-06-07 16:12:01 +05302960 status = QDF_STATUS_E_NULL_VALUE;
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302961 goto error;
2962 }
2963
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05302964 ret_list = qdf_mem_malloc(sizeof(struct scan_result_list));
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302965 if (!ret_list) {
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302966 status = QDF_STATUS_E_NOMEM;
2967 goto error;
2968 }
2969
Jeff Johnson616417f2018-06-27 10:20:53 -07002970 csr_ll_open(&ret_list->List);
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302971 ret_list->pCurEntry = NULL;
2972 status = csr_parse_scan_list(mac_ctx,
2973 ret_list, list);
Yeshwanth Sriram Guntukaa6c3d272019-04-13 12:25:53 +05302974 num_bss = csr_ll_count(&ret_list->List);
Vignesh Viswanathan9dd88d32017-11-22 14:22:03 +05302975 sme_debug("status: %d No of BSS: %d",
Yeshwanth Sriram Guntukaa6c3d272019-04-13 12:25:53 +05302976 status, num_bss);
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302977 if (QDF_IS_STATUS_ERROR(status) || !results)
2978 /* Fail or No one wants the result. */
2979 csr_scan_result_purge(mac_ctx, (tScanResultHandle) ret_list);
2980 else {
Yeshwanth Sriram Guntukaa6c3d272019-04-13 12:25:53 +05302981 if (pFilter) {
Abhishek Singhf3756fc2017-06-28 16:04:06 +05302982 csr_filter_ap_due_to_rssi_reject(mac_ctx, ret_list);
Yeshwanth Sriram Guntukaa6c3d272019-04-13 12:25:53 +05302983 csr_remove_ap_with_assoc_disallowed(mac_ctx, ret_list);
2984 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302985 if (!csr_ll_count(&ret_list->List)) {
2986 /* This mean that there is no match */
2987 csr_ll_close(&ret_list->List);
2988 qdf_mem_free(ret_list);
Yeshwanth Sriram Guntukaa6c3d272019-04-13 12:25:53 +05302989 /*
2990 * Do not trigger scan for ssid if the scan entries
2991 * are removed either due to rssi reject or assoc
2992 * disallowed.
2993 */
2994 if (num_bss)
2995 status = QDF_STATUS_E_EXISTS;
2996 else
2997 status = QDF_STATUS_E_NULL_VALUE;
Abhishek Singh6092fbb2017-01-25 18:10:31 +05302998 } else if (results) {
2999 *results = ret_list;
3000 }
3001 }
3002
3003error:
Sandeep Puligilla8345f3d2018-10-22 15:43:48 -07003004 if (filter)
3005 qdf_mem_free(filter);
Abhishek Singh6092fbb2017-01-25 18:10:31 +05303006 if (list)
3007 ucfg_scan_purge_results(list);
3008 if (pdev)
3009 wlan_objmgr_pdev_release_ref(pdev, WLAN_LEGACY_MAC_ID);
3010
3011 return status;
3012}
3013
Jeff Johnsonedece842018-12-02 11:13:52 -08003014QDF_STATUS csr_scan_get_result_for_bssid(struct mac_context *mac_ctx,
Jeff Johnson8c3ecdd2018-12-05 08:48:54 -08003015 struct qdf_mac_addr *bssid,
3016 tCsrScanResultInfo *res)
Vignesh Viswanathan9dd88d32017-11-22 14:22:03 +05303017{
3018 QDF_STATUS status = QDF_STATUS_E_FAILURE;
3019 tCsrScanResultFilter *scan_filter = NULL;
3020 tScanResultHandle filtered_scan_result = NULL;
3021 tCsrScanResultInfo *scan_result;
3022
3023 if (!mac_ctx) {
3024 QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_ERROR,
3025 FL("mac_ctx is NULL"));
3026 return QDF_STATUS_E_FAILURE;
3027 }
3028
3029 scan_filter = qdf_mem_malloc(sizeof(tCsrScanResultFilter));
Arif Hussain0ef77082018-10-10 16:42:53 -07003030 if (!scan_filter)
Vignesh Viswanathan9dd88d32017-11-22 14:22:03 +05303031 return QDF_STATUS_E_NOMEM;
Vignesh Viswanathan9dd88d32017-11-22 14:22:03 +05303032
Krunal Soni3fa80e22018-01-09 14:16:02 -08003033 scan_filter->BSSIDs.bssid = qdf_mem_malloc(sizeof(*bssid));
Vignesh Viswanathan9dd88d32017-11-22 14:22:03 +05303034 if (!scan_filter->BSSIDs.bssid) {
Vignesh Viswanathan9dd88d32017-11-22 14:22:03 +05303035 status = QDF_STATUS_E_FAILURE;
3036 goto free_filter;
3037 }
3038
3039 scan_filter->BSSIDs.numOfBSSIDs = 1;
Krunal Soni3fa80e22018-01-09 14:16:02 -08003040 qdf_mem_copy(scan_filter->BSSIDs.bssid, bssid, sizeof(*bssid));
Vignesh Viswanathan9dd88d32017-11-22 14:22:03 +05303041
3042 status = csr_scan_get_result(mac_ctx, scan_filter,
3043 &filtered_scan_result);
3044
3045 if (!QDF_IS_STATUS_SUCCESS(status)) {
3046 sme_err("Failed to get scan result");
3047 goto free_filter;
3048 }
3049
3050 scan_result = csr_scan_result_get_first(mac_ctx, filtered_scan_result);
3051
3052 if (scan_result) {
3053 res->pvIes = NULL;
3054 res->ssId.length = scan_result->ssId.length;
3055 qdf_mem_copy(&res->ssId.ssId, &scan_result->ssId.ssId,
3056 res->ssId.length);
3057 res->timer = scan_result->timer;
3058 qdf_mem_copy(&res->BssDescriptor, &scan_result->BssDescriptor,
3059 sizeof(tSirBssDescription));
3060 status = QDF_STATUS_SUCCESS;
3061 } else {
3062 status = QDF_STATUS_E_FAILURE;
3063 }
3064
3065 csr_scan_result_purge(mac_ctx, filtered_scan_result);
3066
3067free_filter:
3068 csr_free_scan_filter(mac_ctx, scan_filter);
3069 if (scan_filter)
3070 qdf_mem_free(scan_filter);
3071
3072 return status;
3073}
3074
Abhishek Singh6092fbb2017-01-25 18:10:31 +05303075static inline QDF_STATUS
Jeff Johnsonedece842018-12-02 11:13:52 -08003076csr_flush_scan_results(struct mac_context *mac_ctx,
Jeff Johnson8c3ecdd2018-12-05 08:48:54 -08003077 struct scan_filter *filter)
Abhishek Singh6092fbb2017-01-25 18:10:31 +05303078{
3079 struct wlan_objmgr_pdev *pdev = NULL;
3080 QDF_STATUS status;
3081
3082 pdev = wlan_objmgr_get_pdev_by_id(mac_ctx->psoc,
3083 0, WLAN_LEGACY_MAC_ID);
3084 if (!pdev) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07003085 sme_err("pdev is NULL");
Abhishek Singh6092fbb2017-01-25 18:10:31 +05303086 return QDF_STATUS_E_INVAL;
3087 }
3088 status = ucfg_scan_flush_results(pdev, filter);
3089
3090 wlan_objmgr_pdev_release_ref(pdev, WLAN_LEGACY_MAC_ID);
3091 return status;
3092}
3093
Jeff Johnsonedece842018-12-02 11:13:52 -08003094QDF_STATUS csr_scan_flush_result(struct mac_context *mac_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +05303095{
3096
3097 if (csr_scan_flush_denied(mac_ctx)) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07003098 sme_err("scan flush denied in roam state");
Abhishek Singh6092fbb2017-01-25 18:10:31 +05303099 return QDF_STATUS_E_FAILURE;
3100 }
3101
3102 return csr_flush_scan_results(mac_ctx, NULL);
3103}
3104
Jeff Johnsonedece842018-12-02 11:13:52 -08003105static inline void csr_flush_bssid(struct mac_context *mac_ctx,
Jeff Johnson8c3ecdd2018-12-05 08:48:54 -08003106 uint8_t *bssid)
Abhishek Singh6092fbb2017-01-25 18:10:31 +05303107{
Sandeep Puligilla8345f3d2018-10-22 15:43:48 -07003108 struct scan_filter *filter;
Abhishek Singh6092fbb2017-01-25 18:10:31 +05303109
Sandeep Puligilla8345f3d2018-10-22 15:43:48 -07003110 filter = qdf_mem_malloc(sizeof(*filter));
3111 if (!filter)
3112 return;
Abhishek Singh6092fbb2017-01-25 18:10:31 +05303113
Sandeep Puligilla8345f3d2018-10-22 15:43:48 -07003114 filter->num_of_bssid = 1;
3115 qdf_mem_copy(filter->bssid_list[0].bytes,
3116 bssid, QDF_MAC_ADDR_SIZE);
3117
3118 csr_flush_scan_results(mac_ctx, filter);
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07003119 sme_debug("Removed BSS entry:%pM", bssid);
Sandeep Puligilla8345f3d2018-10-22 15:43:48 -07003120 if (filter)
3121 qdf_mem_free(filter);
Abhishek Singh6092fbb2017-01-25 18:10:31 +05303122}
3123
Jeff Johnsonedece842018-12-02 11:13:52 -08003124void csr_remove_bssid_from_scan_list(struct mac_context *mac_ctx,
Jeff Johnson8c3ecdd2018-12-05 08:48:54 -08003125 tSirMacAddr bssid)
Abhishek Singh6092fbb2017-01-25 18:10:31 +05303126{
3127 csr_flush_bssid(mac_ctx, bssid);
3128}
3129
Jeff Johnsonedece842018-12-02 11:13:52 -08003130void csr_init_occupied_channels_list(struct mac_context *mac_ctx,
Jeff Johnson8c3ecdd2018-12-05 08:48:54 -08003131 uint8_t sessionId)
Abhishek Singh6092fbb2017-01-25 18:10:31 +05303132{
Jianmin Zhu5b8c5ca2019-04-15 20:02:01 +08003133 qdf_list_t *list = NULL;
3134 struct wlan_objmgr_pdev *pdev = NULL;
3135 qdf_list_node_t *cur_lst = NULL;
3136 qdf_list_node_t *next_lst = NULL;
3137 struct scan_cache_node *cur_node = NULL;
3138 struct scan_filter *filter;
Abhishek Singh6092fbb2017-01-25 18:10:31 +05303139 tpCsrNeighborRoamControlInfo neighbor_roam_info =
3140 &mac_ctx->roam.neighborRoamInfo[sessionId];
Jianmin Zhu5b8c5ca2019-04-15 20:02:01 +08003141 tCsrRoamConnectedProfile *profile = NULL;
Jianmin Zhu8d7afc22019-04-17 13:10:22 +08003142 uint8_t ch;
Abhishek Singh6092fbb2017-01-25 18:10:31 +05303143
Jianmin Zhu5b8c5ca2019-04-15 20:02:01 +08003144 if (!(mac_ctx && mac_ctx->roam.roamSession &&
3145 CSR_IS_SESSION_VALID(mac_ctx, sessionId))) {
3146 sme_debug("Invalid session");
3147 return;
3148 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +05303149 if (neighbor_roam_info->cfgParams.channelInfo.numOfChannels) {
3150 /*
3151 * Ini file contains neighbor scan channel list, hence NO need
3152 * to build occupied channel list"
3153 */
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07003154 sme_debug("Ini contains neighbor scan ch list");
Abhishek Singh6092fbb2017-01-25 18:10:31 +05303155 return;
3156 }
3157
3158 if (!csr_neighbor_roam_is_new_connected_profile(mac_ctx, sessionId)) {
3159 /*
3160 * Do not flush occupied list since current roam profile matches
3161 * previous
3162 */
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07003163 sme_debug("Current roam profile matches prev");
Abhishek Singh6092fbb2017-01-25 18:10:31 +05303164 return;
3165 }
3166
Jianmin Zhu5b8c5ca2019-04-15 20:02:01 +08003167 profile = &mac_ctx->roam.roamSession[sessionId].connectedProfile;
3168 if (!profile)
3169 return;
3170
3171 filter = qdf_mem_malloc(sizeof(*filter));
3172 if (!filter) {
3173 sme_err("filter is NULL");
3174 return;
3175 }
3176
3177 filter->num_of_auth = 1;
3178 filter->auth_type[0] = csr_covert_auth_type_new(profile->AuthType);
3179 filter->num_of_enc_type = 1;
3180 filter->enc_type[0] = csr_covert_enc_type_new(profile->EncryptionType);
3181 filter->num_of_mc_enc_type = 1;
3182 filter->mc_enc_type[0] =
3183 csr_covert_enc_type_new(profile->mcEncryptionType);
3184 filter->num_of_ssid = 1;
3185 filter->ssid_list[0].length = profile->SSID.length;
3186 qdf_mem_copy(filter->ssid_list[0].ssid, profile->SSID.ssId,
3187 profile->SSID.length);
3188
3189 pdev = wlan_objmgr_get_pdev_by_id(mac_ctx->psoc, 0, WLAN_LEGACY_MAC_ID);
3190
3191 if (!pdev) {
3192 sme_err("pdev is NULL");
3193 qdf_mem_free(filter);
3194 return;
3195 }
3196
Abhishek Singh6092fbb2017-01-25 18:10:31 +05303197 /* Empty occupied channels here */
3198 mac_ctx->scan.occupiedChannels[sessionId].numChannels = 0;
3199 mac_ctx->scan.roam_candidate_count[sessionId] = 0;
Jianmin Zhu8d7afc22019-04-17 13:10:22 +08003200
3201 csr_add_to_occupied_channels(
3202 mac_ctx, profile->operationChannel,
3203 sessionId,
3204 &mac_ctx->scan.occupiedChannels[sessionId],
3205 true);
Jianmin Zhu5b8c5ca2019-04-15 20:02:01 +08003206 list = ucfg_scan_get_result(pdev, filter);
3207 if (list)
3208 sme_debug("num_entries %d", qdf_list_size(list));
3209 if (!list || (list && !qdf_list_size(list))) {
3210 sme_err("get scan result failed");
3211 wlan_objmgr_pdev_release_ref(pdev, WLAN_LEGACY_MAC_ID);
3212 qdf_mem_free(filter);
3213 if (list)
3214 ucfg_scan_purge_results(list);
3215 return;
Abhishek Singh6092fbb2017-01-25 18:10:31 +05303216 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +05303217
Jianmin Zhu5b8c5ca2019-04-15 20:02:01 +08003218 qdf_list_peek_front(list, &cur_lst);
3219 while (cur_lst) {
3220 cur_node = qdf_container_of(cur_lst, struct scan_cache_node,
3221 node);
Jianmin Zhu8d7afc22019-04-17 13:10:22 +08003222 ch = cur_node->entry->channel.chan_idx;
3223 csr_add_to_occupied_channels(
3224 mac_ctx, ch,
Jianmin Zhu5b8c5ca2019-04-15 20:02:01 +08003225 sessionId,
3226 &mac_ctx->scan.occupiedChannels[sessionId],
3227 true);
3228 qdf_list_peek_next(list, cur_lst, &next_lst);
3229 cur_lst = next_lst;
3230 next_lst = NULL;
3231 }
3232
3233 qdf_mem_free(filter);
3234 ucfg_scan_purge_results(list);
3235 wlan_objmgr_pdev_release_ref(pdev, WLAN_LEGACY_MAC_ID);
Abhishek Singh6092fbb2017-01-25 18:10:31 +05303236}
3237
3238/**
3239 * csr_scan_filter_results: filter scan result based
3240 * on valid channel list number.
3241 * @mac_ctx: mac context
3242 *
3243 * Get scan result from scan list and Check Scan result channel number
3244 * with 11d channel list if channel number is found in 11d channel list
3245 * then do not remove scan result entry from scan list
3246 *
3247 * return: QDF Status
3248 */
Jeff Johnsonedece842018-12-02 11:13:52 -08003249QDF_STATUS csr_scan_filter_results(struct mac_context *mac_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +05303250{
3251 QDF_STATUS status = QDF_STATUS_SUCCESS;
3252 uint32_t len = sizeof(mac_ctx->roam.validChannelList);
3253 struct wlan_objmgr_pdev *pdev = NULL;
3254
3255 pdev = wlan_objmgr_get_pdev_by_id(mac_ctx->psoc,
3256 0, WLAN_LEGACY_MAC_ID);
3257 if (!pdev) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07003258 sme_err("pdev is NULL");
Abhishek Singh6092fbb2017-01-25 18:10:31 +05303259 return QDF_STATUS_E_INVAL;
3260 }
3261 status = csr_get_cfg_valid_channels(mac_ctx,
3262 mac_ctx->roam.validChannelList,
3263 &len);
3264
3265 /* Get valid channels list from CFG */
3266 if (QDF_IS_STATUS_ERROR(status)) {
3267 wlan_objmgr_pdev_release_ref(pdev, WLAN_LEGACY_MAC_ID);
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07003268 sme_err("Failed to get Channel list from CFG");
Abhishek Singh6092fbb2017-01-25 18:10:31 +05303269 return status;
3270 }
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07003271 sme_debug("No of valid channel %d", len);
Abhishek Singh6092fbb2017-01-25 18:10:31 +05303272
3273 ucfg_scan_filter_valid_channel(pdev,
3274 mac_ctx->roam.validChannelList, len);
3275 wlan_objmgr_pdev_release_ref(pdev, WLAN_LEGACY_MAC_ID);
3276 return QDF_STATUS_SUCCESS;
3277}