blob: c9d2c3b674b5dd5d77a911cf234fe43d4a831cec [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
gaurank kathpalia5efa73b2017-12-29 10:55:16 +05302 * Copyright (c) 2011-2018 The Linux Foundation. All rights reserved.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +053028/*
29 * DOC: csr_api_scan.c
30 *
31 * Implementation for the Common Scan interfaces.
32 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080033
34#include "ani_global.h"
35
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080036#include "csr_inside_api.h"
37#include "sme_inside.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080038
39#include "csr_support.h"
40
41#include "host_diag_core_log.h"
42#include "host_diag_core_event.h"
43
44#include "cds_reg_service.h"
45#include "wma_types.h"
46#include "cds_utils.h"
47#include "cfg_api.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080048#include "wma.h"
49
Tushnim Bhattacharyya0c4ad2d2017-03-09 15:59:03 -080050#include "wlan_policy_mgr_api.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080051#include "wlan_hdd_main.h"
Agrawal Ashish21ba2572016-09-03 16:40:10 +053052#include "pld_common.h"
yeshwanth sriram guntukadb501222017-01-24 15:21:31 +053053#include "csr_internal.h"
Abhishek Singh6092fbb2017-01-25 18:10:31 +053054#include <wlan_scan_ucfg_api.h>
Abhishek Singh6f56d212017-04-12 14:31:57 +053055#include <wlan_scan_tgt_api.h>
Abhishek Singh6092fbb2017-01-25 18:10:31 +053056#include <wlan_scan_utils_api.h>
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -080057#include <wlan_objmgr_vdev_obj.h>
58#include <wlan_objmgr_pdev_obj.h>
59#include <wlan_utility.h>
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070060#include "wlan_reg_services_api.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080061
62#define MIN_CHN_TIME_TO_FIND_GO 100
63#define MAX_CHN_TIME_TO_FIND_GO 100
64#define DIRECT_SSID_LEN 7
65
66/* Purpose of HIDDEN_TIMER
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +053067 * When we remove hidden ssid from the profile i.e., forget the SSID via GUI
68 * that SSID shouldn't see in the profile For above requirement we used timer
69 * limit, logic is explained below Timer value is initialsed to current time
70 * when it receives corresponding probe response of hidden SSID (The probe
71 * request is received regularly till SSID in the profile. Once it is removed
72 * from profile probe request is not sent.) when we receive probe response for
73 * broadcast probe request, during update SSID with saved SSID we will diff
74 * current time with saved SSID time if it is greater than 1 min then we are
75 * not updating with old one
76 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080077
78#define HIDDEN_TIMER (1*60*1000)
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +053079/* must be less than 100, represent the persentage of new RSSI */
80#define CSR_SCAN_RESULT_RSSI_WEIGHT 80
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080081#define MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL 140
82#define MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL 120
83
84#define MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL_FASTREASSOC 30
85#define MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL_FASTREASSOC 20
86
87#define PCL_ADVANTAGE 30
88#define PCL_RSSI_THRESHOLD -75
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080089#define CSR_SCAN_IS_OVER_BSS_LIMIT(pMac) \
90 ((pMac)->scan.nBssLimit <= (csr_ll_count(&(pMac)->scan.scanResultList)))
91
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +053092static void csr_set_default_scan_timing(tpAniSirGlobal pMac,
93 tSirScanType scanType,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080094 tCsrScanRequest *pScanRequest);
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +053095static QDF_STATUS csr_scan_channels(tpAniSirGlobal pMac, tSmeCmd *pCommand);
96static void csr_set_cfg_valid_channel_list(tpAniSirGlobal pMac, uint8_t
97 *pChannelList, uint8_t NumChannels);
98static void csr_save_tx_power_to_cfg(tpAniSirGlobal pMac, tDblLinkList *pList,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080099 uint32_t cfgId);
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +0530100static void csr_set_cfg_country_code(tpAniSirGlobal pMac, uint8_t *countryCode);
101static void csr_purge_channel_power(tpAniSirGlobal pMac, tDblLinkList
102 *pChannelList);
103static bool csr_roam_is_valid_channel(tpAniSirGlobal pMac, uint8_t channel);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800104
105#define CSR_IS_SOCIAL_CHANNEL(channel) \
106 (((channel) == 1) || ((channel) == 6) || ((channel) == 11))
107
108static void csr_release_scan_cmd_pending_list(tpAniSirGlobal pMac)
109{
110 tListElem *pEntry;
111 tSmeCmd *pCommand;
112
113 while ((pEntry =
114 csr_ll_remove_head(&pMac->scan.scanCmdPendingList,
115 LL_ACCESS_LOCK)) != NULL) {
116 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +0530117 if (eSmeCsrCommandMask & pCommand->command)
Krunal Soni81f068c2017-02-23 19:51:55 -0800118 csr_release_command(pMac, pCommand);
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +0530119 else
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700120 sme_err("Received command: %d", pCommand->command);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800121 }
122}
123
124/* pResult is invalid calling this function. */
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +0530125void csr_free_scan_result_entry(tpAniSirGlobal pMac, struct tag_csrscan_result
126 *pResult)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800127{
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +0530128 if (NULL != pResult->Result.pvIes)
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530129 qdf_mem_free(pResult->Result.pvIes);
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +0530130
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530131 qdf_mem_free(pResult);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800132}
133
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530134static QDF_STATUS csr_ll_scan_purge_result(tpAniSirGlobal pMac,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800135 tDblLinkList *pList)
136{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530137 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800138 tListElem *pEntry;
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +0530139 struct tag_csrscan_result *pBssDesc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800140
141 csr_ll_lock(pList);
142
143 while ((pEntry = csr_ll_remove_head(pList, LL_ACCESS_NOLOCK)) != NULL) {
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +0530144 pBssDesc = GET_BASE_ADDR(pEntry, struct tag_csrscan_result,
145 Link);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800146 csr_free_scan_result_entry(pMac, pBssDesc);
147 }
148
149 csr_ll_unlock(pList);
150
151 return status;
152}
153
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530154QDF_STATUS csr_scan_open(tpAniSirGlobal mac_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800155{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800156 csr_ll_open(mac_ctx->hHdd, &mac_ctx->scan.channelPowerInfoList24);
157 csr_ll_open(mac_ctx->hHdd, &mac_ctx->scan.channelPowerInfoList5G);
158#ifdef WLAN_AP_STA_CONCURRENCY
159 csr_ll_open(mac_ctx->hHdd, &mac_ctx->scan.scanCmdPendingList);
160#endif
161 mac_ctx->scan.fFullScanIssued = false;
162 mac_ctx->scan.nBssLimit = CSR_MAX_BSS_SUPPORT;
yeshwanth sriram guntuka4c9a6692017-03-13 12:44:59 +0530163
164 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800165}
166
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530167QDF_STATUS csr_scan_close(tpAniSirGlobal pMac)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800168{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800169#ifdef WLAN_AP_STA_CONCURRENCY
170 csr_release_scan_cmd_pending_list(pMac);
171#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800172#ifdef WLAN_AP_STA_CONCURRENCY
173 csr_ll_close(&pMac->scan.scanCmdPendingList);
174#endif
175 csr_purge_channel_power(pMac, &pMac->scan.channelPowerInfoList24);
176 csr_purge_channel_power(pMac, &pMac->scan.channelPowerInfoList5G);
177 csr_ll_close(&pMac->scan.channelPowerInfoList24);
178 csr_ll_close(&pMac->scan.channelPowerInfoList5G);
179 csr_scan_disable(pMac);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530180 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800181}
182
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530183QDF_STATUS csr_scan_enable(tpAniSirGlobal pMac)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800184{
185
186 pMac->scan.fScanEnable = true;
187
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530188 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800189}
190
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530191QDF_STATUS csr_scan_disable(tpAniSirGlobal pMac)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800192{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800193 pMac->scan.fScanEnable = false;
194
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530195 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800196}
197
198/* Set scan timing parameters according to state of other driver sessions */
199/* No validation of the parameters is performed. */
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +0530200static void csr_set_default_scan_timing(tpAniSirGlobal pMac,
201 tSirScanType scanType,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800202 tCsrScanRequest *pScanRequest)
203{
204#ifdef WLAN_AP_STA_CONCURRENCY
205 if (csr_is_any_session_connected(pMac)) {
206 /* Reset passive scan time as per ini parameter. */
207 cfg_set_int(pMac, WNI_CFG_PASSIVE_MAXIMUM_CHANNEL_TIME,
208 pMac->roam.configParam.nPassiveMaxChnTimeConc);
209 /* If multi-session, use the appropriate default scan times */
210 if (scanType == eSIR_ACTIVE_SCAN) {
211 pScanRequest->maxChnTime =
212 pMac->roam.configParam.nActiveMaxChnTimeConc;
213 pScanRequest->minChnTime =
214 pMac->roam.configParam.nActiveMinChnTimeConc;
215 } else {
216 pScanRequest->maxChnTime =
217 pMac->roam.configParam.nPassiveMaxChnTimeConc;
218 pScanRequest->minChnTime =
219 pMac->roam.configParam.nPassiveMinChnTimeConc;
220 }
221 pScanRequest->restTime = pMac->roam.configParam.nRestTimeConc;
222
Agrawal Ashish17bb3902016-05-05 13:29:40 +0530223 pScanRequest->min_rest_time =
224 pMac->roam.configParam.min_rest_time_conc;
225 pScanRequest->idle_time =
226 pMac->roam.configParam.idle_time_conc;
227
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800228 /* Return so that fields set above will not be overwritten. */
229 return;
230 }
231#endif
232
233 /* This portion of the code executed if multi-session not supported */
234 /* (WLAN_AP_STA_CONCURRENCY not defined) or no multi-session. */
235 /* Use the "regular" (non-concurrency) default scan timing. */
236 cfg_set_int(pMac, WNI_CFG_PASSIVE_MAXIMUM_CHANNEL_TIME,
237 pMac->roam.configParam.nPassiveMaxChnTime);
238 if (pScanRequest->scanType == eSIR_ACTIVE_SCAN) {
239 pScanRequest->maxChnTime =
240 pMac->roam.configParam.nActiveMaxChnTime;
241 pScanRequest->minChnTime =
242 pMac->roam.configParam.nActiveMinChnTime;
243 } else {
244 pScanRequest->maxChnTime =
245 pMac->roam.configParam.nPassiveMaxChnTime;
246 pScanRequest->minChnTime =
247 pMac->roam.configParam.nPassiveMinChnTime;
248 }
249#ifdef WLAN_AP_STA_CONCURRENCY
Agrawal Ashish17bb3902016-05-05 13:29:40 +0530250
251 /* No rest time/Idle time if no sessions are connected. */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800252 pScanRequest->restTime = 0;
Agrawal Ashish17bb3902016-05-05 13:29:40 +0530253 pScanRequest->min_rest_time = 0;
254 pScanRequest->idle_time = 0;
255
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800256#endif
257}
258
259/**
260 * csr_scan_2g_only_request() - This function will update the scan request with
261 * only 2.4GHz valid channel list.
262 * @mac_ctx: Pointer to Global MAC structure
263 * @scan_cmd scan cmd
264 * @scan_req scan req
265 *
266 * This function will update the scan request with only 2.4GHz valid channel
267 * list.
268 *
269 * @Return: status of operation
270 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530271static QDF_STATUS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800272csr_scan_2g_only_request(tpAniSirGlobal mac_ctx,
273 tSmeCmd *scan_cmd,
274 tCsrScanRequest *scan_req)
275{
276 uint8_t idx, lst_sz = 0;
277
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530278 QDF_ASSERT(scan_cmd && scan_req);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800279 /* To silence the KW tool null check is added */
280 if ((scan_cmd == NULL) || (scan_req == NULL)) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700281 sme_err("Scan Cmd or Scan Request is NULL");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530282 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800283 }
284
285 if (eCSR_SCAN_REQUEST_FULL_SCAN != scan_req->requestType)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530286 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800287
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700288 sme_debug("Scanning only 2G Channels during first scan");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800289
290 /* Contsruct valid Supported 2.4 GHz Channel List */
291 if (NULL == scan_req->ChannelInfo.ChannelList) {
292 scan_req->ChannelInfo.ChannelList =
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530293 qdf_mem_malloc(NUM_24GHZ_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800294 if (NULL == scan_req->ChannelInfo.ChannelList) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700295 sme_err("Memory allocation failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530296 return QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800297 }
298 for (idx = 1; idx <= NUM_24GHZ_CHANNELS; idx++) {
299 if (csr_is_supported_channel(mac_ctx, idx)) {
300 scan_req->ChannelInfo.ChannelList[lst_sz] = idx;
301 lst_sz++;
302 }
303 }
304 } else {
305 for (idx = 0;
306 idx < scan_req->ChannelInfo.numOfChannels;
307 idx++) {
308 if (scan_req->ChannelInfo.ChannelList[idx] <=
309 CDS_24_GHZ_CHANNEL_14
310 && csr_is_supported_channel(mac_ctx,
311 scan_req->ChannelInfo.ChannelList[idx])) {
312 scan_req->ChannelInfo.ChannelList[lst_sz] =
313 scan_req->ChannelInfo.ChannelList[idx];
314 lst_sz++;
315 }
316 }
317 }
318 scan_req->ChannelInfo.numOfChannels = lst_sz;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530319 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800320}
321
322static void
323csr_set_scan_reason(tSmeCmd *scan_cmd, eCsrRequestType req_type)
324{
325 switch (req_type) {
326 case eCSR_SCAN_REQUEST_11D_SCAN:
327 scan_cmd->u.scanCmd.reason = eCsrScan11d1;
328 break;
329#ifdef SOFTAP_CHANNEL_RANGE
330 case eCSR_SCAN_SOFTAP_CHANNEL_RANGE:
331#endif
332 case eCSR_SCAN_REQUEST_FULL_SCAN:
333 case eCSR_SCAN_P2P_DISCOVERY:
334 scan_cmd->u.scanCmd.reason = eCsrScanUserRequest;
335 break;
336 case eCSR_SCAN_HO_PROBE_SCAN:
337 scan_cmd->u.scanCmd.reason = eCsrScanProbeBss;
338 break;
339 case eCSR_SCAN_P2P_FIND_PEER:
340 scan_cmd->u.scanCmd.reason = eCsrScanP2PFindPeer;
341 break;
342 default:
343 break;
344 }
345}
346
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530347static QDF_STATUS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800348csr_issue_11d_scan(tpAniSirGlobal mac_ctx, tSmeCmd *scan_cmd,
349 tCsrScanRequest *scan_req, uint16_t session_id)
350{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530351 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800352 tSmeCmd *scan_11d_cmd = NULL;
353 tCsrScanRequest tmp_rq;
Naveen Rawatd4c0c542016-11-17 11:49:17 -0800354 tCsrChannelInfo *chn_info = &tmp_rq.ChannelInfo;
355 uint32_t num_chn = mac_ctx->scan.base_channels.numChannels;
gaurank kathpalia14e2f912017-08-31 14:51:45 +0530356 struct csr_roam_session *csr_session = CSR_GET_SESSION(mac_ctx,
357 session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800358
359 if (csr_session == NULL) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700360 sme_err("session %d not found", session_id);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530361 QDF_ASSERT(0);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530362 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800363 }
364
Naveen Rawatd4c0c542016-11-17 11:49:17 -0800365 if (num_chn > WNI_CFG_VALID_CHANNEL_LIST_LEN) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700366 sme_err("invalid number of channels: %d", num_chn);
Naveen Rawatd4c0c542016-11-17 11:49:17 -0800367 return QDF_STATUS_E_FAILURE;
368 }
369
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800370 if (!(((false == mac_ctx->first_scan_done)
371 && (eCSR_SCAN_REQUEST_11D_SCAN != scan_req->requestType))
372#ifdef SOFTAP_CHANNEL_RANGE
373 && (eCSR_SCAN_SOFTAP_CHANNEL_RANGE != scan_req->requestType)
374#endif
375 && (false == mac_ctx->scan.fEnableBypass11d)))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530376 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800377
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530378 qdf_mem_set(&tmp_rq, sizeof(tCsrScanRequest), 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800379 scan_11d_cmd = csr_get_command_buffer(mac_ctx);
380 if (!scan_11d_cmd) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700381 sme_err("scan_11d_cmd failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530382 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800383 }
384
gaurank kathpalia14e2f912017-08-31 14:51:45 +0530385 qdf_mem_set(&scan_11d_cmd->u.scanCmd, sizeof(struct scan_cmd), 0);
Naveen Rawatd4c0c542016-11-17 11:49:17 -0800386 chn_info->ChannelList = qdf_mem_malloc(num_chn);
387 if (NULL == chn_info->ChannelList) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700388 sme_err("Failed to allocate memory");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530389 return QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800390 }
Naveen Rawatd4c0c542016-11-17 11:49:17 -0800391 qdf_mem_copy(chn_info->ChannelList,
392 mac_ctx->scan.base_channels.channelList, num_chn);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800393
Naveen Rawatd4c0c542016-11-17 11:49:17 -0800394 chn_info->numOfChannels = (uint8_t) num_chn;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800395 scan_11d_cmd->command = eSmeCommandScan;
396 scan_11d_cmd->u.scanCmd.callback = mac_ctx->scan.callback11dScanDone;
397 scan_11d_cmd->u.scanCmd.pContext = NULL;
398 wma_get_scan_id(&scan_11d_cmd->u.scanCmd.scanID);
399 tmp_rq.BSSType = eCSR_BSS_TYPE_ANY;
400 tmp_rq.scan_id = scan_11d_cmd->u.scanCmd.scanID;
401
Abhinav Kumar37ad3272017-11-17 17:20:14 +0530402 status = qdf_mc_timer_init(&scan_11d_cmd->u.scanCmd.csr_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530403 QDF_TIMER_TYPE_SW,
Selvaraj, Sridhar2eed3932016-11-15 16:29:59 +0530404 csr_scan_active_list_timeout_handle, scan_11d_cmd);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800405
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -0700406 if (wlan_reg_11d_enabled_on_host(mac_ctx->psoc)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800407 tmp_rq.bcnRptReqScan = scan_req->bcnRptReqScan;
408 if (scan_req->bcnRptReqScan)
409 tmp_rq.scanType = scan_req->scanType ?
410 eSIR_PASSIVE_SCAN : scan_req->scanType;
411 else
412 tmp_rq.scanType = eSIR_PASSIVE_SCAN;
413 tmp_rq.requestType = eCSR_SCAN_REQUEST_11D_SCAN;
414 scan_11d_cmd->u.scanCmd.reason = eCsrScan11d1;
415 tmp_rq.maxChnTime =
416 mac_ctx->roam.configParam.nPassiveMaxChnTime;
417 tmp_rq.minChnTime =
418 mac_ctx->roam.configParam.nPassiveMinChnTime;
419 } else {
420 tmp_rq.bcnRptReqScan = scan_req->bcnRptReqScan;
421 if (scan_req->bcnRptReqScan)
422 tmp_rq.scanType = scan_req->scanType;
423 else
424 tmp_rq.scanType = eSIR_ACTIVE_SCAN;
425 tmp_rq.requestType = scan_req->requestType;
426 scan_11d_cmd->u.scanCmd.reason = scan_cmd->u.scanCmd.reason;
427 tmp_rq.maxChnTime = mac_ctx->roam.configParam.nActiveMaxChnTime;
428 tmp_rq.minChnTime = mac_ctx->roam.configParam.nActiveMinChnTime;
429 }
430 if (mac_ctx->roam.configParam.nInitialDwellTime) {
431 tmp_rq.maxChnTime = mac_ctx->roam.configParam.nInitialDwellTime;
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700432 sme_debug("11d scan, updating dwell time for first scan %u",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800433 tmp_rq.maxChnTime);
434 }
435
436 status = csr_scan_copy_request(mac_ctx,
437 &scan_11d_cmd->u.scanCmd.u.scanRequest, &tmp_rq);
438 /* Free the channel list */
Naveen Rawatd4c0c542016-11-17 11:49:17 -0800439 qdf_mem_free(chn_info->ChannelList);
440 chn_info->ChannelList = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530441 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700442 sme_err("csr_scan_copy_request failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530443 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800444 }
445
446 mac_ctx->scan.scanProfile.numOfChannels =
447 scan_11d_cmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
448
449
450 status = csr_queue_sme_command(mac_ctx, scan_11d_cmd, false);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530451 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700452 sme_err("Failed to send message status = %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800453 status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530454 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800455 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530456 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800457}
458
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530459QDF_STATUS csr_scan_request(tpAniSirGlobal pMac, uint16_t sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800460 tCsrScanRequest *scan_req,
461 csr_scan_completeCallback callback, void *pContext)
462{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530463 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800464 tSmeCmd *scan_cmd = NULL;
465 tCsrScanRequest *pTempScanReq = NULL;
gaurank kathpalia14e2f912017-08-31 14:51:45 +0530466 struct csr_config *cfg_prm = &pMac->roam.configParam;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800467
468 if (scan_req == NULL) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700469 sme_err("scan_req is NULL");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530470 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800471 return status;
472 }
473
474 /*
475 * During group formation, the P2P client scans for GO with the specific
476 * SSID. There will be chances of GO switching to other channels because
477 * of scan or to STA channel in case of STA+GO MCC scenario. So to
478 * increase the possibility of client to find the GO, the dwell time of
479 * scan is increased to 100ms.
480 * If the scan request is for specific SSId the length of SSID will be
481 * greater than 7 as SSID for p2p search contains "DIRECT-")
482 */
483 if (scan_req->p2pSearch
484 && scan_req->SSIDs.numOfSSIDs
485 && (NULL != scan_req->SSIDs.SSIDList)
486 && (scan_req->SSIDs.SSIDList->SSID.length > DIRECT_SSID_LEN)) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700487 sme_debug("P2P: Increasing the min and max Dwell time to %d for specific SSID scan %.*s",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800488 MAX_CHN_TIME_TO_FIND_GO,
489 scan_req->SSIDs.SSIDList->SSID.length,
490 scan_req->SSIDs.SSIDList->SSID.ssId);
491 scan_req->maxChnTime = MAX_CHN_TIME_TO_FIND_GO;
492 scan_req->minChnTime = MIN_CHN_TIME_TO_FIND_GO;
493 }
494
495 if (!pMac->scan.fScanEnable) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700496 sme_err("SId: %d Scanning not enabled Scan type=%u, numOfSSIDs=%d P2P search=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800497 sessionId, scan_req->requestType,
498 scan_req->SSIDs.numOfSSIDs,
499 scan_req->p2pSearch);
500 goto release_cmd;
501 }
502
503 scan_cmd = csr_get_command_buffer(pMac);
504 if (!scan_cmd) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700505 sme_err("scan_cmd is NULL");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800506 goto release_cmd;
507 }
508
gaurank kathpalia14e2f912017-08-31 14:51:45 +0530509 qdf_mem_set(&scan_cmd->u.scanCmd, sizeof(struct scan_cmd), 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800510 scan_cmd->command = eSmeCommandScan;
511 scan_cmd->sessionId = sessionId;
512 if (scan_cmd->sessionId >= CSR_ROAM_SESSION_MAX)
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700513 sme_err("Invalid Sme SessionID: %d", sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800514 scan_cmd->u.scanCmd.callback = callback;
515 scan_cmd->u.scanCmd.pContext = pContext;
516 csr_set_scan_reason(scan_cmd, scan_req->requestType);
517 if (scan_req->minChnTime == 0 && scan_req->maxChnTime == 0) {
518 /* The caller doesn't set the time correctly. Set it here */
519 csr_set_default_scan_timing(pMac, scan_req->scanType, scan_req);
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700520 sme_debug("Setting default min %d and max %d ChnTime",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800521 scan_req->minChnTime, scan_req->maxChnTime);
522 }
523#ifdef WLAN_AP_STA_CONCURRENCY
Agrawal Ashish17bb3902016-05-05 13:29:40 +0530524 /*
525 * Need to set restTime/min_Ret_time/idle_time
526 * only if at least one session is connected
527 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800528 if (scan_req->restTime == 0 && csr_is_any_session_connected(pMac)) {
529 scan_req->restTime = cfg_prm->nRestTimeConc;
Agrawal Ashish17bb3902016-05-05 13:29:40 +0530530 scan_req->min_rest_time = cfg_prm->min_rest_time_conc;
531 scan_req->idle_time = cfg_prm->idle_time_conc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800532 if (scan_req->scanType == eSIR_ACTIVE_SCAN) {
533 scan_req->maxChnTime = cfg_prm->nActiveMaxChnTimeConc;
534 scan_req->minChnTime = cfg_prm->nActiveMinChnTimeConc;
535 } else {
536 scan_req->maxChnTime = cfg_prm->nPassiveMaxChnTimeConc;
537 scan_req->minChnTime = cfg_prm->nPassiveMinChnTimeConc;
538 }
539 }
540#endif
541 /* Increase dwell time in case P2P Search and Miracast is not present */
542 if (scan_req->p2pSearch && scan_req->ChannelInfo.numOfChannels
543 == P2P_SOCIAL_CHANNELS && (!(pMac->sme.miracast_value))) {
544 scan_req->maxChnTime += P2P_SEARCH_DWELL_TIME_INCREASE;
545 }
546 scan_cmd->u.scanCmd.scanID = scan_req->scan_id;
547 /*
548 * If it is the first scan request from HDD, CSR checks if it is for 11d
549 * If it is not, CSR will save the scan request in the pending cmd queue
550 * & issue an 11d scan request to PE.
551 */
552 status = csr_issue_11d_scan(pMac, scan_cmd, scan_req, sessionId);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530553 if (status != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800554 goto release_cmd;
555
556 /*
557 * Scan only 2G Channels if set in ini file. This is mainly to reduce
558 * the First Scan duration once we turn on Wifi
559 */
560 if (pMac->scan.fFirstScanOnly2GChnl
561 && false == pMac->first_scan_done) {
562 csr_scan_2g_only_request(pMac, scan_cmd, scan_req);
563 pMac->first_scan_done = true;
564 }
565
566
567 if (cfg_prm->nInitialDwellTime) {
568 scan_req->maxChnTime = cfg_prm->nInitialDwellTime;
569 cfg_prm->nInitialDwellTime = 0;
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700570 sme_debug("updating dwell time for first scan %u",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800571 scan_req->maxChnTime);
572 }
Paul Zhang72697bd2017-12-20 09:24:25 +0800573
574 if (csr_is_conn_state_disconnected(pMac, sessionId))
575 scan_req->scan_adaptive_dwell_mode =
576 cfg_prm->scan_adaptive_dwell_mode_nc;
577 else
578 scan_req->scan_adaptive_dwell_mode =
579 cfg_prm->scan_adaptive_dwell_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800580
581 status = csr_scan_copy_request(pMac, &scan_cmd->u.scanCmd.u.scanRequest,
582 scan_req);
583 /*
584 * Reset the variable after the first scan is queued after loading the
585 * driver. The purpose of this parameter is that DFS channels are
586 * skipped during the first scan after loading the driver. The above API
587 * builds the target scan request in which this variable is used.
588 */
589 cfg_prm->initial_scan_no_dfs_chnl = 0;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530590 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700591 sme_err("fail to copy request status: %d", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800592 goto release_cmd;
593 }
594
595 pTempScanReq = &scan_cmd->u.scanCmd.u.scanRequest;
596 pMac->scan.scanProfile.numOfChannels =
597 pTempScanReq->ChannelInfo.numOfChannels;
Anurag Chouhan210db072016-02-22 18:42:15 +0530598 status = qdf_mc_timer_init(&scan_cmd->u.scanCmd.csr_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530599 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800600 csr_scan_active_list_timeout_handle, scan_cmd);
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700601 sme_debug(
602 "SId=%d scanId=%d Scan reason=%u numSSIDs=%d numChan=%d P2P search=%d minCT=%d maxCT=%d uIEFieldLen=%d BSSID: " MAC_ADDRESS_STR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800603 sessionId, scan_cmd->u.scanCmd.scanID,
604 scan_cmd->u.scanCmd.reason, pTempScanReq->SSIDs.numOfSSIDs,
605 pTempScanReq->ChannelInfo.numOfChannels,
606 pTempScanReq->p2pSearch, pTempScanReq->minChnTime,
Sreelakshmi Konamki8b8257c2016-12-12 15:44:54 +0530607 pTempScanReq->maxChnTime, pTempScanReq->uIEFieldLen,
608 MAC_ADDR_ARRAY(scan_cmd->u.scanCmd.u.scanRequest.bssid.bytes));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800609
610 status = csr_queue_sme_command(pMac, scan_cmd, false);
Krunal Soniaa179db2017-10-13 19:28:17 -0700611 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700612 sme_err("fail to send message status: %d", status);
Krunal Soniaa179db2017-10-13 19:28:17 -0700613 return status;
614 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800615
616release_cmd:
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530617 if (!QDF_IS_STATUS_SUCCESS(status) && scan_cmd) {
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +0530618 sme_err(" SId: %d Failed with status=%d Scan reason=%u numOfSSIDs=%d P2P search=%d scanId=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800619 sessionId, status, scan_cmd->u.scanCmd.reason,
620 scan_req->SSIDs.numOfSSIDs, scan_req->p2pSearch,
621 scan_cmd->u.scanCmd.scanID);
Krunal Soniaa179db2017-10-13 19:28:17 -0700622 csr_release_command_buffer(pMac, scan_cmd);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800623 }
624
625 return status;
626}
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -0800627#ifndef NAPIER_SCAN
gaurank kathpalia14e2f912017-08-31 14:51:45 +0530628static QDF_STATUS csr_issue_roam_after_lostlink_scan(
629 tpAniSirGlobal pMac, uint32_t sessionId,
630 enum csr_roam_reason reason)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800631{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530632 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800633 tScanResultHandle hBSSList = NULL;
634 tCsrScanResultFilter *pScanFilter = NULL;
635 uint32_t roamId = 0;
636 tCsrRoamProfile *pProfile = NULL;
gaurank kathpalia14e2f912017-08-31 14:51:45 +0530637 struct csr_roam_session *pSession = CSR_GET_SESSION(pMac, sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800638
639 if (!pSession) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700640 sme_err("session %d not found", sessionId);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530641 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800642 }
643
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800644 if (pSession->fCancelRoaming) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700645 sme_debug("lost link roaming canceled");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530646 status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800647 goto free_filter;
648 }
649 /* Here is the profile we need to connect to */
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530650 pScanFilter = qdf_mem_malloc(sizeof(tCsrScanResultFilter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800651 if (NULL == pScanFilter) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530652 status = QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800653 goto free_filter;
654 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800655 if (NULL == pSession->pCurRoamProfile) {
656 pScanFilter->EncryptionType.numEntries = 1;
657 pScanFilter->EncryptionType.encryptionType[0] =
658 eCSR_ENCRYPT_TYPE_NONE;
659 } else {
660 /*
661 * We have to make a copy of pCurRoamProfile because it will
662 * be free inside csr_roam_issue_connect
663 */
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530664 pProfile = qdf_mem_malloc(sizeof(tCsrRoamProfile));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800665 if (NULL == pProfile) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530666 status = QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800667 goto free_filter;
668 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800669 status = csr_roam_copy_profile(pMac, pProfile,
670 pSession->pCurRoamProfile);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530671 if (!QDF_IS_STATUS_SUCCESS(status))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800672 goto free_filter;
673 status = csr_roam_prepare_filter_from_profile(pMac, pProfile,
674 pScanFilter);
675 } /* We have a profile */
676 roamId = GET_NEXT_ROAM_ID(&pMac->roam);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530677 if (!QDF_IS_STATUS_SUCCESS(status))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800678 goto free_filter;
679
680 status = csr_scan_get_result(pMac, pScanFilter, &hBSSList);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530681 if (!QDF_IS_STATUS_SUCCESS(status))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800682 goto free_filter;
683
684 if (eCsrLostLink1 == reason) {
685 /* if possible put the last connected BSS in beginning */
686 csr_move_bss_to_head_from_bssid(pMac,
687 &pSession->connectedProfile.bssid, hBSSList);
688 }
689 status = csr_roam_issue_connect(pMac, sessionId, pProfile, hBSSList,
690 reason, roamId, true, true);
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +0530691 if (!QDF_IS_STATUS_SUCCESS(status))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800692 csr_scan_result_purge(pMac, hBSSList);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800693
694free_filter:
695 if (pScanFilter) {
696 /* we need to free memory for filter if profile exists */
697 csr_free_scan_filter(pMac, pScanFilter);
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530698 qdf_mem_free(pScanFilter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800699 }
700 if (NULL != pProfile) {
701 csr_release_profile(pMac, pProfile);
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530702 qdf_mem_free(pProfile);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800703 }
704 return status;
705}
706
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530707QDF_STATUS csr_scan_handle_failed_lostlink1(tpAniSirGlobal pMac,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800708 uint32_t sessionId)
709{
gaurank kathpalia14e2f912017-08-31 14:51:45 +0530710 struct csr_roam_session *pSession = CSR_GET_SESSION(pMac, sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800711
712 if (!pSession) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700713 sme_err("session %d not found", sessionId);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530714 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800715 }
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700716 sme_debug("Lost link scan 1 failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800717 if (pSession->fCancelRoaming)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530718 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800719 if (!pSession->pCurRoamProfile)
720 return csr_scan_request_lost_link3(pMac, sessionId);
721 /*
722 * We fail lostlink1 but there may be other BSS in the cached result
723 * fit the profile. Give it a try first
724 */
725 if (pSession->pCurRoamProfile->SSIDs.numOfSSIDs == 0 ||
726 pSession->pCurRoamProfile->SSIDs.numOfSSIDs > 1)
727 /* try lostlink scan2 */
728 return csr_scan_request_lost_link2(pMac, sessionId);
729 if (!pSession->pCurRoamProfile->ChannelInfo.ChannelList
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +0530730 || pSession->pCurRoamProfile->ChannelInfo.ChannelList[0] == 0)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800731 /* go straight to lostlink scan3 */
732 return csr_scan_request_lost_link3(pMac, sessionId);
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +0530733
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530734 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800735}
736
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530737QDF_STATUS csr_scan_handle_failed_lostlink2(tpAniSirGlobal pMac,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800738 uint32_t sessionId)
739{
gaurank kathpalia14e2f912017-08-31 14:51:45 +0530740 struct csr_roam_session *pSession = CSR_GET_SESSION(pMac, sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800741
742 if (!pSession) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700743 sme_err("session %d not found", sessionId);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530744 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800745 }
746
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700747 sme_debug("Lost link scan 2 failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800748 if (pSession->fCancelRoaming)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530749 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800750
751 if (!pSession->pCurRoamProfile
752 || !pSession->pCurRoamProfile->ChannelInfo.ChannelList
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +0530753 || pSession->pCurRoamProfile->ChannelInfo.ChannelList[0] == 0)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800754 /* try lostlink scan3 */
755 return csr_scan_request_lost_link3(pMac, sessionId);
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +0530756
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530757 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800758}
759
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530760QDF_STATUS csr_scan_handle_failed_lostlink3(tpAniSirGlobal pMac,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800761 uint32_t sessionId)
762{
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700763 sme_debug("Lost link scan 3 failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530764 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800765}
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530766static QDF_STATUS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800767csr_update_lost_link1_cmd(tpAniSirGlobal mac_ctx, tSmeCmd *cmd,
gaurank kathpalia14e2f912017-08-31 14:51:45 +0530768 struct csr_roam_session *pSession, uint32_t session_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800769{
770 uint8_t i, num_ch = 0;
771 tScanResultHandle bss_lst = NULL;
772 tCsrScanResultInfo *scan_result = NULL;
773 tCsrScanResultFilter *scan_filter = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530774 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800775 tCsrSSIDs *ssid_list = &cmd->u.scanCmd.u.scanRequest.SSIDs;
776 tCsrChannelInfo *ch_info = &cmd->u.scanCmd.u.scanRequest.ChannelInfo;
777
778 cmd->command = eSmeCommandScan;
779 cmd->sessionId = (uint8_t) session_id;
780 cmd->u.scanCmd.reason = eCsrScanLostLink1;
781 cmd->u.scanCmd.callback = NULL;
782 cmd->u.scanCmd.pContext = NULL;
783 cmd->u.scanCmd.u.scanRequest.maxChnTime =
784 mac_ctx->roam.configParam.nActiveMaxChnTime;
785 cmd->u.scanCmd.u.scanRequest.minChnTime =
786 mac_ctx->roam.configParam.nActiveMinChnTime;
787 cmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
788 wma_get_scan_id(&cmd->u.scanCmd.scanID);
Anurag Chouhan210db072016-02-22 18:42:15 +0530789 status = qdf_mc_timer_init(&cmd->u.scanCmd.csr_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530790 QDF_TIMER_TYPE_SW,
Selvaraj, Sridhar2eed3932016-11-15 16:29:59 +0530791 csr_scan_active_list_timeout_handle, cmd);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800792 cmd->u.scanCmd.u.scanRequest.scan_id =
793 cmd->u.scanCmd.scanID;
794
795 if (pSession->connectedProfile.SSID.length) {
796 /*
797 * on error: following memory will be released by call to
798 * csr_release_command_scan in the end
799 */
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530800 ssid_list->SSIDList = qdf_mem_malloc(sizeof(tCsrSSIDInfo));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800801 if (NULL == ssid_list->SSIDList)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530802 return QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800803 ssid_list->numOfSSIDs = 1;
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530804 qdf_mem_copy(&ssid_list->SSIDList[0].SSID,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800805 &pSession->connectedProfile.SSID,
806 sizeof(tSirMacSSid));
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +0530807 } else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800808 ssid_list->numOfSSIDs = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800809
810 if (!pSession->pCurRoamProfile)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530811 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800812
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530813 scan_filter = qdf_mem_malloc(sizeof(tCsrScanResultFilter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800814 if (NULL == scan_filter)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530815 return QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800816
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800817 status = csr_roam_prepare_filter_from_profile(mac_ctx,
818 pSession->pCurRoamProfile, scan_filter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530819 if (!QDF_IS_STATUS_SUCCESS(status))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800820 goto free_lost_link1_local_mem;
821
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530822 if (!(QDF_IS_STATUS_SUCCESS(csr_scan_get_result(mac_ctx, scan_filter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800823 &bss_lst)) && bss_lst)) {
824 if (csr_roam_is_channel_valid(mac_ctx,
825 pSession->connectedProfile.operationChannel)) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530826 ch_info->ChannelList = qdf_mem_malloc(1);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800827 if (NULL == ch_info->ChannelList) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530828 status = QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800829 goto free_lost_link1_local_mem;
830 }
831 ch_info->ChannelList[0] =
832 pSession->connectedProfile.operationChannel;
833 ch_info->numOfChannels = 1;
834 }
Arif Hussaind3bf1112016-07-29 10:16:53 -0700835 csr_free_scan_filter(mac_ctx, scan_filter);
836 qdf_mem_free(scan_filter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800837 return status;
838 }
839
840 /* on error: this mem will be released by csr_release_command_scan */
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530841 ch_info->ChannelList = qdf_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800842 if (NULL == ch_info->ChannelList) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530843 status = QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800844 goto free_lost_link1_local_mem;
845 }
846
847 scan_result = csr_scan_result_get_next(mac_ctx, bss_lst);
848 while (scan_result != NULL && num_ch < WNI_CFG_VALID_CHANNEL_LIST_LEN) {
849 for (i = 0; i < num_ch; i++) {
850 if (ch_info->ChannelList[i] ==
851 scan_result->BssDescriptor.channelId)
852 break;
853 }
854 if (i == num_ch)
855 ch_info->ChannelList[num_ch++] =
856 scan_result->BssDescriptor.channelId;
857 scan_result = csr_scan_result_get_next(mac_ctx, bss_lst);
858 }
859 /* Include the last connected BSS' channel */
860 if (csr_roam_is_channel_valid(mac_ctx,
861 pSession->connectedProfile.operationChannel)) {
862 for (i = 0; i < num_ch; i++) {
863 if (ch_info->ChannelList[i] ==
864 pSession->connectedProfile.operationChannel)
865 break;
866 }
867 if (i == num_ch)
868 ch_info->ChannelList[num_ch++] =
869 pSession->connectedProfile.operationChannel;
870 }
871 ch_info->numOfChannels = num_ch;
872free_lost_link1_local_mem:
873 if (scan_filter) {
874 csr_free_scan_filter(mac_ctx, scan_filter);
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530875 qdf_mem_free(scan_filter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800876 }
877 if (bss_lst)
878 csr_scan_result_purge(mac_ctx, bss_lst);
879 return status;
880}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800881/**
882 * csr_scan_request_lost_link1() - start scan on link lost 1
883 * @mac_ctx: mac global context
884 * @session_id: session id
885 *
886 * Lostlink1 scan is to actively scan the last connected profile's SSID on all
887 * matched BSS channels. If no roam profile (it should not), it is like
888 * lostlinkscan3
889 *
890 * Return: status of operation
891 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530892QDF_STATUS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800893csr_scan_request_lost_link1(tpAniSirGlobal mac_ctx, uint32_t session_id)
894{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530895 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800896 tSmeCmd *cmd = NULL;
gaurank kathpalia14e2f912017-08-31 14:51:45 +0530897 struct csr_roam_session *session = CSR_GET_SESSION(mac_ctx, session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800898
899 if (!session) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700900 sme_err("session %d not found", session_id);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530901 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800902 }
903
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800904 cmd = csr_get_command_buffer(mac_ctx);
905 if (!cmd) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530906 status = QDF_STATUS_E_RESOURCES;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800907 goto release_lost_link1_cmd;
908 }
gaurank kathpalia14e2f912017-08-31 14:51:45 +0530909 qdf_mem_set(&cmd->u.scanCmd, sizeof(struct scan_cmd), 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800910 status = csr_update_lost_link1_cmd(mac_ctx, cmd, session, session_id);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530911 if (!QDF_IS_STATUS_SUCCESS(status))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800912 goto release_lost_link1_cmd;
913
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530914 qdf_mem_set(&cmd->u.scanCmd.u.scanRequest.bssid,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530915 sizeof(struct qdf_mac_addr), 0xFF);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800916 status = csr_queue_sme_command(mac_ctx, cmd, false);
Krunal Soniaa179db2017-10-13 19:28:17 -0700917 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700918 sme_err("fail to send message status: %d", status);
Krunal Soniaa179db2017-10-13 19:28:17 -0700919 return status;
920 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800921
922release_lost_link1_cmd:
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530923 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -0700924 sme_warn("failed with status %d", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800925 if (cmd)
Krunal Soniaa179db2017-10-13 19:28:17 -0700926 csr_release_command_buffer(mac_ctx, cmd);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800927 status = csr_scan_handle_failed_lostlink1(mac_ctx, session_id);
928 }
929 return status;
930}
931
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530932static QDF_STATUS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800933csr_update_lost_link2_cmd(tpAniSirGlobal mac_ctx, tSmeCmd *cmd,
gaurank kathpalia14e2f912017-08-31 14:51:45 +0530934 uint32_t session_id, struct csr_roam_session *session)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800935{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530936 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800937 uint8_t i, num_ch = 0;
938 tScanResultHandle bss_lst = NULL;
939 tCsrScanResultInfo *scan_result = NULL;
940 tCsrScanResultFilter *scan_fltr = NULL;
941 tCsrChannelInfo *ch_info = &cmd->u.scanCmd.u.scanRequest.ChannelInfo;
942
943 cmd->command = eSmeCommandScan;
944 cmd->sessionId = (uint8_t) session_id;
945 cmd->u.scanCmd.reason = eCsrScanLostLink2;
946 cmd->u.scanCmd.callback = NULL;
947 cmd->u.scanCmd.pContext = NULL;
948 cmd->u.scanCmd.u.scanRequest.maxChnTime =
949 mac_ctx->roam.configParam.nActiveMaxChnTime;
950 cmd->u.scanCmd.u.scanRequest.minChnTime =
951 mac_ctx->roam.configParam.nActiveMinChnTime;
952 cmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
953 wma_get_scan_id(&cmd->u.scanCmd.scanID);
954 cmd->u.scanCmd.u.scanRequest.scan_id =
955 cmd->u.scanCmd.scanID;
956 if (!session->pCurRoamProfile)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530957 return QDF_STATUS_SUCCESS;
Anurag Chouhan210db072016-02-22 18:42:15 +0530958 status = qdf_mc_timer_init(&cmd->u.scanCmd.csr_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530959 QDF_TIMER_TYPE_SW,
Selvaraj, Sridhar2eed3932016-11-15 16:29:59 +0530960 csr_scan_active_list_timeout_handle, cmd);
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530961 scan_fltr = qdf_mem_malloc(sizeof(tCsrScanResultFilter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800962 if (NULL == scan_fltr)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530963 return QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800964
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530965 qdf_mem_set(scan_fltr, sizeof(tCsrScanResultFilter), 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800966 status = csr_roam_prepare_filter_from_profile(mac_ctx,
967 session->pCurRoamProfile, scan_fltr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530968 if (!QDF_IS_STATUS_SUCCESS(status))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800969 goto free_lost_link2_local_mem;
970
971 status = csr_scan_get_result(mac_ctx, scan_fltr, &bss_lst);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530972 if (!QDF_IS_STATUS_SUCCESS(status))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800973 goto free_lost_link2_local_mem;
974
975 if (!bss_lst)
976 goto free_lost_link2_local_mem;
977
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530978 ch_info->ChannelList = qdf_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800979 if (NULL == ch_info->ChannelList) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530980 status = QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800981 goto free_lost_link2_local_mem;
982 }
983 scan_result = csr_scan_result_get_next(mac_ctx, bss_lst);
984 while (scan_result != NULL && num_ch < WNI_CFG_VALID_CHANNEL_LIST_LEN) {
985 for (i = 0; i < num_ch; i++) {
986 if (ch_info->ChannelList[i] ==
987 scan_result->BssDescriptor.channelId)
988 break;
989 }
990 if (i == num_ch)
991 ch_info->ChannelList[num_ch++] =
992 scan_result->BssDescriptor.channelId;
993 scan_result = csr_scan_result_get_next(mac_ctx, bss_lst);
994 }
995 ch_info->numOfChannels = num_ch;
996
997free_lost_link2_local_mem:
998 if (scan_fltr) {
999 csr_free_scan_filter(mac_ctx, scan_fltr);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301000 qdf_mem_free(scan_fltr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001001 }
1002 if (bss_lst)
1003 csr_scan_result_purge(mac_ctx, bss_lst);
1004 return status;
1005}
1006
1007/**
1008 * csr_scan_request_lost_link2() - start scan on link lost 2
1009 * @mac_ctx: mac global context
1010 * @session_id: session id
1011 *
1012 * Lostlink2 scan is to actively scan the all SSIDs of the last roaming
1013 * profile's on all matched BSS channels. Since MAC doesn't support multiple
1014 * SSID, we scan all SSIDs and filter them afterwards
1015 *
1016 * Return: status of operation
1017 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301018QDF_STATUS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001019csr_scan_request_lost_link2(tpAniSirGlobal mac_ctx, uint32_t session_id)
1020{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301021 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001022 tSmeCmd *cmd = NULL;
gaurank kathpalia14e2f912017-08-31 14:51:45 +05301023 struct csr_roam_session *session = CSR_GET_SESSION(mac_ctx, session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001024
1025 if (!session) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07001026 sme_err("session %d not found", session_id);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301027 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001028 }
1029
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001030 cmd = csr_get_command_buffer(mac_ctx);
1031 if (!cmd) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301032 status = QDF_STATUS_E_RESOURCES;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001033 goto release_lost_link2_cmd;
1034 }
gaurank kathpalia14e2f912017-08-31 14:51:45 +05301035 qdf_mem_set(&cmd->u.scanCmd, sizeof(struct scan_cmd), 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001036 status = csr_update_lost_link2_cmd(mac_ctx, cmd, session_id, session);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301037 if (!QDF_IS_STATUS_SUCCESS(status))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001038 goto release_lost_link2_cmd;
1039
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301040 qdf_mem_set(&cmd->u.scanCmd.u.scanRequest.bssid,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301041 sizeof(struct qdf_mac_addr), 0xFF);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001042 /* Put to the head in pending queue */
1043 status = csr_queue_sme_command(mac_ctx, cmd, true);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301044 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07001045 sme_err("fail to send message status: %d", status);
Krunal Soniaa179db2017-10-13 19:28:17 -07001046 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001047 }
1048
1049release_lost_link2_cmd:
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301050 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07001051 sme_warn("failed with status %d", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001052 if (cmd)
Krunal Soniaa179db2017-10-13 19:28:17 -07001053 csr_release_command_buffer(mac_ctx, cmd);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001054 status = csr_scan_handle_failed_lostlink2(mac_ctx, session_id);
1055 }
1056 return status;
1057}
1058
1059/**
1060 * csr_scan_request_lost_link3() - To actively scan all valid channels
1061 * @mac_ctx: mac global context
1062 * @session_id: session id
1063 *
1064 * Return: status of operation
1065 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301066QDF_STATUS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001067csr_scan_request_lost_link3(tpAniSirGlobal mac_ctx, uint32_t session_id)
1068{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301069 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001070 tSmeCmd *cmd;
1071
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001072 do {
1073 cmd = csr_get_command_buffer(mac_ctx);
1074 if (!cmd) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301075 status = QDF_STATUS_E_RESOURCES;
Krunal Soniaa179db2017-10-13 19:28:17 -07001076 sme_warn("failed with status %d", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001077 break;
1078 }
gaurank kathpalia14e2f912017-08-31 14:51:45 +05301079 qdf_mem_set(&cmd->u.scanCmd, sizeof(struct scan_cmd), 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001080 cmd->command = eSmeCommandScan;
1081 cmd->sessionId = (uint8_t) session_id;
1082 cmd->u.scanCmd.reason = eCsrScanLostLink3;
1083 cmd->u.scanCmd.callback = NULL;
1084 cmd->u.scanCmd.pContext = NULL;
1085 cmd->u.scanCmd.u.scanRequest.maxChnTime =
1086 mac_ctx->roam.configParam.nActiveMaxChnTime;
1087 cmd->u.scanCmd.u.scanRequest.minChnTime =
1088 mac_ctx->roam.configParam.nActiveMinChnTime;
1089 cmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
1090 wma_get_scan_id(&cmd->u.scanCmd.scanID);
Anurag Chouhan210db072016-02-22 18:42:15 +05301091 status = qdf_mc_timer_init(&cmd->u.scanCmd.csr_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301092 QDF_TIMER_TYPE_SW,
Selvaraj, Sridhar2eed3932016-11-15 16:29:59 +05301093 csr_scan_active_list_timeout_handle, cmd);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001094 cmd->u.scanCmd.u.scanRequest.scan_id =
1095 cmd->u.scanCmd.scanID;
Anurag Chouhanc5548422016-02-24 18:33:27 +05301096 qdf_set_macaddr_broadcast(&cmd->u.scanCmd.u.scanRequest.bssid);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001097 /* Put to the head of pending queue */
1098 status = csr_queue_sme_command(mac_ctx, cmd, true);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301099 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07001100 sme_err("fail to send message status: %d", status);
Krunal Soniaa179db2017-10-13 19:28:17 -07001101 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001102 }
1103 } while (0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001104
1105 return status;
1106}
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001107#else
1108QDF_STATUS
1109csr_scan_request_lost_link1(tpAniSirGlobal mac_ctx, uint32_t session_id)
1110{
1111 return QDF_STATUS_E_FAILURE;
1112}
1113QDF_STATUS
1114csr_scan_request_lost_link3(tpAniSirGlobal mac_ctx, uint32_t session_id)
1115{
1116 return QDF_STATUS_E_FAILURE;
1117}
1118QDF_STATUS
1119csr_scan_request_lost_link2(tpAniSirGlobal mac_ctx, uint32_t session_id)
1120{
1121 return QDF_STATUS_E_FAILURE;
1122}
1123QDF_STATUS csr_scan_handle_failed_lostlink3(tpAniSirGlobal pMac,
1124 uint32_t sessionId)
1125{
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07001126 sme_debug("Lost link scan 3 failed");
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001127 return QDF_STATUS_SUCCESS;
1128}
1129#endif
Sandeep Puligilla344d7252017-09-15 16:23:33 -07001130
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001131QDF_STATUS csr_scan_handle_search_for_ssid(tpAniSirGlobal mac_ctx,
1132 uint32_t session_id)
1133{
1134 QDF_STATUS status = QDF_STATUS_E_FAILURE;
1135 tScanResultHandle hBSSList = CSR_INVALID_SCANRESULT_HANDLE;
1136 tCsrScanResultFilter *pScanFilter = NULL;
1137 tCsrRoamProfile *profile;
gaurank kathpalia14e2f912017-08-31 14:51:45 +05301138 struct csr_roam_session *session;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001139
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001140 session = CSR_GET_SESSION(mac_ctx, session_id);
1141 if (!session) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07001142 sme_err("session %d not found", session_id);
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001143 return QDF_STATUS_E_FAILURE;
1144 }
1145 profile = session->scan_info.profile;
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07001146 sme_debug("session %d", session_id);
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001147 do {
1148 /*
1149 * If there is roam command waiting, ignore this roam because
1150 * the newer roam command is the one to execute
1151 */
1152 if (csr_is_roam_command_waiting_for_session(mac_ctx, session_id)) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07001153 sme_warn("aborts because roam command waiting");
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001154 break;
1155 }
1156 if (profile == NULL)
1157 break;
1158 pScanFilter = qdf_mem_malloc(sizeof(tCsrScanResultFilter));
1159 if (NULL == pScanFilter) {
1160 status = QDF_STATUS_E_NOMEM;
1161 break;
1162 }
1163 status = csr_roam_prepare_filter_from_profile(mac_ctx, profile,
1164 pScanFilter);
1165 if (!QDF_IS_STATUS_SUCCESS(status))
1166 break;
1167 status = csr_scan_get_result(mac_ctx, pScanFilter, &hBSSList);
1168 if (!QDF_IS_STATUS_SUCCESS(status))
1169 break;
1170 if (mac_ctx->roam.roamSession[session_id].connectState ==
1171 eCSR_ASSOC_STATE_TYPE_INFRA_DISCONNECTING) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07001172 sme_err("upper layer issued disconnetion");
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001173 status = QDF_STATUS_E_FAILURE;
1174 break;
1175 }
1176 status = csr_roam_issue_connect(mac_ctx, session_id, profile,
1177 hBSSList, eCsrHddIssued,
1178 session->scan_info.roam_id,
1179 true, true);
1180 } while (0);
1181
1182 if (!QDF_IS_STATUS_SUCCESS(status)) {
1183 if (CSR_INVALID_SCANRESULT_HANDLE != hBSSList) {
1184 csr_scan_result_purge(mac_ctx, hBSSList);
1185 }
1186 /* We haven't done anything to this profile */
1187 csr_roam_call_callback(mac_ctx, session_id, NULL,
1188 session->scan_info.roam_id,
1189 eCSR_ROAM_ASSOCIATION_FAILURE,
1190 eCSR_ROAM_RESULT_SCAN_FOR_SSID_FAILURE);
1191 }
1192 if (pScanFilter) {
1193 csr_free_scan_filter(mac_ctx, pScanFilter);
1194 qdf_mem_free(pScanFilter);
1195 }
1196 return status;
1197}
1198
Vignesh Viswanathan014096a2017-12-07 01:24:44 +05301199/**
1200 * csr_handle_fils_scan_for_ssid_failure() - Checks and fills FILS seq number
1201 * in roam_info structure to send to hdd
1202 *
1203 * @roam_profile: Pointer to current roam_profile structure
1204 * @roam_info: Pointer to roam_info strucure to be filled
1205 *
1206 * Return: true for FILS connection else false
1207 */
1208#ifdef WLAN_FEATURE_FILS_SK
1209static
1210bool csr_handle_fils_scan_for_ssid_failure(tCsrRoamProfile *roam_profile,
1211 struct csr_roam_info *roam_info)
1212{
1213 if (roam_profile && roam_profile->fils_con_info &&
1214 roam_profile->fils_con_info->is_fils_connection) {
1215 sme_debug("send roam_info for FILS connection failure, seq %d",
1216 roam_profile->fils_con_info->sequence_number);
1217 roam_info->is_fils_connection = true;
1218 roam_info->fils_seq_num =
1219 roam_profile->fils_con_info->sequence_number;
1220 return true;
1221 }
1222
1223 return false;
1224}
1225#else
1226static
1227bool csr_handle_fils_scan_for_ssid_failure(tCsrRoamProfile *roam_profile,
1228 struct csr_roam_info *roam_info)
1229{
1230 return false;
1231}
1232#endif
1233
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001234QDF_STATUS csr_scan_handle_search_for_ssid_failure(tpAniSirGlobal mac_ctx,
1235 uint32_t session_id)
1236{
1237 QDF_STATUS status = QDF_STATUS_SUCCESS;
1238 tCsrRoamProfile *profile;
gaurank kathpalia14e2f912017-08-31 14:51:45 +05301239 struct csr_roam_session *session = CSR_GET_SESSION(mac_ctx, session_id);
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001240 eCsrRoamResult roam_result;
Vignesh Viswanathan014096a2017-12-07 01:24:44 +05301241 struct csr_roam_info *roam_info = NULL;
1242 struct tag_csrscan_result *scan_result;
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001243
1244 if (!session) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07001245 sme_err("session %d not found", session_id);
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001246 return QDF_STATUS_E_FAILURE;
1247 }
1248 profile = session->scan_info.profile;
1249
1250 /*
1251 * Check whether it is for start ibss. No need to do anything if it
1252 * is a JOIN request
1253 */
1254 if (profile && CSR_IS_START_IBSS(profile)) {
1255 status = csr_roam_issue_connect(mac_ctx, session_id, profile, NULL,
1256 eCsrHddIssued, session->scan_info.roam_id,
1257 true, true);
1258 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07001259 sme_err("failed to issue startIBSS, session_id %d status: 0x%08X roam id %d",
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001260 session_id, status, session->scan_info.roam_id);
1261 csr_roam_call_callback(mac_ctx, session_id, NULL,
1262 session->scan_info.roam_id, eCSR_ROAM_FAILED,
1263 eCSR_ROAM_RESULT_FAILURE);
1264 }
1265 return status;
1266 }
1267 roam_result = eCSR_ROAM_RESULT_FAILURE;
1268 if (NULL != profile && csr_is_bss_type_ibss(profile->BSSType)) {
1269 roam_result = eCSR_ROAM_RESULT_IBSS_START_FAILED;
1270 goto roam_completion;
1271 }
Vignesh Viswanathan014096a2017-12-07 01:24:44 +05301272
1273 roam_info = qdf_mem_malloc(sizeof(struct csr_roam_info));
1274 if (!roam_info) {
1275 sme_err("Failed to allocate memory for roam_info");
1276 goto roam_completion;
1277 }
1278
1279 if (session->scan_info.roambssentry) {
1280 scan_result = GET_BASE_ADDR(session->scan_info.roambssentry,
1281 struct tag_csrscan_result, Link);
1282 roam_info->pBssDesc = &scan_result->Result.BssDescriptor;
1283 }
1284 roam_info->statusCode = session->joinFailStatusCode.statusCode;
1285 roam_info->reasonCode = session->joinFailStatusCode.reasonCode;
1286
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001287 /* Only indicate assoc_completion if we indicate assoc_start. */
1288 if (session->bRefAssocStartCnt > 0) {
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001289 session->bRefAssocStartCnt--;
Jeff Johnsoneddf5442017-10-04 10:55:53 -07001290 csr_roam_call_callback(mac_ctx, session_id, roam_info,
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001291 session->scan_info.roam_id,
1292 eCSR_ROAM_ASSOCIATION_COMPLETION,
1293 eCSR_ROAM_RESULT_SCAN_FOR_SSID_FAILURE);
1294 } else {
Vignesh Viswanathan014096a2017-12-07 01:24:44 +05301295 if (!csr_handle_fils_scan_for_ssid_failure(
1296 profile, roam_info)) {
1297 qdf_mem_free(roam_info);
1298 roam_info = NULL;
1299 }
1300 csr_roam_call_callback(mac_ctx, session_id, roam_info,
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001301 session->scan_info.roam_id,
1302 eCSR_ROAM_ASSOCIATION_FAILURE,
1303 eCSR_ROAM_RESULT_SCAN_FOR_SSID_FAILURE);
1304 }
Vignesh Viswanathan014096a2017-12-07 01:24:44 +05301305
1306 if (roam_info)
1307 qdf_mem_free(roam_info);
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08001308roam_completion:
1309 csr_roam_completion(mac_ctx, session_id, NULL, NULL, roam_result,
1310 false);
1311 return status;
1312}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001313
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301314QDF_STATUS csr_scan_result_purge(tpAniSirGlobal pMac,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001315 tScanResultHandle hScanList)
1316{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301317 QDF_STATUS status = QDF_STATUS_E_INVAL;
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05301318 struct scan_result_list *pScanList =
1319 (struct scan_result_list *) hScanList;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001320
1321 if (pScanList) {
1322 status = csr_ll_scan_purge_result(pMac, &pScanList->List);
1323 csr_ll_close(&pScanList->List);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301324 qdf_mem_free(pScanList);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001325 }
1326 return status;
1327}
1328
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001329/* Add the channel to the occupiedChannels array */
1330static void csr_scan_add_to_occupied_channels(tpAniSirGlobal pMac,
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05301331 struct tag_csrscan_result *pResult,
Kapil Gupta0a2477b2016-08-23 18:00:34 +05301332 uint8_t sessionId,
gaurank kathpalia14e2f912017-08-31 14:51:45 +05301333 struct csr_channel *occupied_ch,
Kapil Gupta0a2477b2016-08-23 18:00:34 +05301334 tDot11fBeaconIEs *pIes,
1335 bool is_init_list)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001336{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301337 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001338 uint8_t ch;
1339 uint8_t num_occupied_ch = occupied_ch->numChannels;
1340 uint8_t *occupied_ch_lst = occupied_ch->channelList;
1341
1342 ch = pResult->Result.BssDescriptor.channelId;
Kapil Gupta0a2477b2016-08-23 18:00:34 +05301343 if (!csr_neighbor_roam_connected_profile_match(pMac,
1344 sessionId, pResult, pIes))
1345 return;
1346
1347 if (is_init_list)
1348 pMac->scan.roam_candidate_count[sessionId]++;
1349
1350 if (csr_is_channel_present_in_list(occupied_ch_lst,
1351 num_occupied_ch, ch))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001352 return;
1353
1354 status = csr_add_to_channel_list_front(occupied_ch_lst,
1355 num_occupied_ch, ch);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301356 if (QDF_IS_STATUS_SUCCESS(status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001357 occupied_ch->numChannels++;
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07001358 sme_debug("Added channel %d to the list (count=%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001359 ch, occupied_ch->numChannels);
1360 if (occupied_ch->numChannels >
1361 CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN)
1362 occupied_ch->numChannels =
1363 CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN;
1364 }
1365}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001366
1367/* Put the BSS into the scan result list */
1368/* pIes can not be NULL */
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05301369static void csr_scan_add_result(tpAniSirGlobal mac_ctx,
1370 struct tag_csrscan_result *pResult,
1371 tDot11fBeaconIEs *pIes,
1372 uint32_t sessionId)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001373{
Abhishek Singh6f56d212017-04-12 14:31:57 +05301374 qdf_nbuf_t buf;
1375 uint8_t *data;
1376 struct mgmt_rx_event_params rx_param = {0};
1377 struct wlan_frame_hdr *hdr;
1378 struct wlan_bcn_frame *fixed_frame;
1379 uint32_t buf_len;
1380 tSirBssDescription *bss_desc;
1381 enum mgmt_frame_type frm_type = MGMT_BEACON;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001382
Abhishek Singh6f56d212017-04-12 14:31:57 +05301383 bss_desc = &pResult->Result.BssDescriptor;
1384 if (bss_desc->fProbeRsp)
1385 frm_type = MGMT_PROBE_RESP;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001386
Abhishek Singh6f56d212017-04-12 14:31:57 +05301387 rx_param.pdev_id = 0;
1388 rx_param.channel = bss_desc->channelId;
1389 rx_param.rssi = bss_desc->rssi;
1390 rx_param.tsf_delta = bss_desc->tsf_delta;
1391 buf_len = GET_IE_LEN_IN_BSS(bss_desc->length) +
1392 + offsetof(struct wlan_bcn_frame, ie) + sizeof(*hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001393
Abhishek Singh6f56d212017-04-12 14:31:57 +05301394 buf = qdf_nbuf_alloc(NULL, qdf_roundup(buf_len, 4),
1395 0, 4, false);
1396 if (!buf) {
Srinivas Girigowda2c263352017-03-17 17:49:53 -07001397 sme_err("Failed to allocate wbuf for mgmt rx len (%u)",
Abhishek Singh6f56d212017-04-12 14:31:57 +05301398 buf_len);
Abhishek Singha92cf1e2017-11-02 17:04:11 +05301399 csr_free_scan_result_entry(mac_ctx, pResult);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001400 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001401 }
Abhishek Singh6f56d212017-04-12 14:31:57 +05301402 qdf_nbuf_put_tail(buf, buf_len);
1403 qdf_nbuf_set_protocol(buf, ETH_P_CONTROL);
1404
1405 data = qdf_nbuf_data(buf);
1406 hdr = (struct wlan_frame_hdr *) data;
1407 qdf_mem_copy(hdr->i_addr3, bss_desc->bssId, QDF_MAC_ADDR_SIZE);
1408 qdf_mem_copy(hdr->i_addr2, bss_desc->bssId, QDF_MAC_ADDR_SIZE);
1409 qdf_mem_copy(hdr->i_seq,
1410 &bss_desc->seq_ctrl, sizeof(uint16_t));
1411
1412 data += sizeof(*hdr);
1413 fixed_frame = (struct wlan_bcn_frame *)data;
1414 qdf_mem_copy(fixed_frame->timestamp,
1415 bss_desc->timeStamp, 8);
1416 fixed_frame->beacon_interval = bss_desc->beaconInterval;
1417 fixed_frame->capability.value = bss_desc->capabilityInfo;
1418 data += offsetof(struct wlan_bcn_frame, ie);
1419
1420 qdf_mem_copy(data, bss_desc->ieFields,
1421 GET_IE_LEN_IN_BSS(bss_desc->length));
1422 tgt_scan_bcn_probe_rx_callback(mac_ctx->psoc, NULL, buf, &rx_param,
1423 frm_type);
Abhishek Singha92cf1e2017-11-02 17:04:11 +05301424 csr_free_scan_result_entry(mac_ctx, pResult);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001425}
1426
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001427/*
1428 * NOTE: This routine is being added to make
1429 * sure that scan results are not being flushed
1430 * while roaming. If the scan results are flushed,
1431 * we are unable to recover from
1432 * csr_roam_roaming_state_disassoc_rsp_processor.
1433 * If it is needed to remove this routine,
1434 * first ensure that we recover gracefully from
1435 * csr_roam_roaming_state_disassoc_rsp_processor if
1436 * csr_scan_get_result returns with a failure because
1437 * of not being able to find the roaming BSS.
1438 */
Jeff Johnson00fa67d2016-10-14 08:07:36 -07001439static bool csr_scan_flush_denied(tpAniSirGlobal pMac)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001440{
1441 uint8_t sessionId;
1442
1443 for (sessionId = 0; sessionId < CSR_ROAM_SESSION_MAX; sessionId++) {
1444 if (CSR_IS_SESSION_VALID(pMac, sessionId)) {
1445 if (csr_neighbor_middle_of_roaming(pMac, sessionId))
1446 return 1;
1447 }
1448 }
1449 return 0;
1450}
1451
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301452QDF_STATUS csr_scanning_state_msg_processor(tpAniSirGlobal pMac,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001453 void *pMsgBuf)
1454{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301455 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001456 tSirMbMsg *pMsg = (tSirMbMsg *) pMsgBuf;
gaurank kathpalia14e2f912017-08-31 14:51:45 +05301457 struct csr_roam_session *pSession;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001458 tSirSmeAssocIndToUpperLayerCnf *pUpperLayerAssocCnf;
Jeff Johnson172237b2017-11-07 15:32:59 -08001459 struct csr_roam_info roamInfo;
1460 struct csr_roam_info *roam_info = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001461 uint32_t sessionId;
1462
1463 if (eWNI_SME_SCAN_RSP == pMsg->type)
1464 return csr_scan_sme_scan_response(pMac, pMsgBuf);
1465
1466 if (pMsg->type != eWNI_SME_UPPER_LAYER_ASSOC_CNF) {
1467 if (csr_is_any_session_in_connect_state(pMac)) {
1468 /*
1469 * In case of we are connected, we need to check whether
1470 * connect status changes because scan may also run
1471 * while connected.
1472 */
1473 csr_roam_check_for_link_status_change(pMac,
1474 (tSirSmeRsp *) pMsgBuf);
1475 } else {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07001476 sme_warn("Message [0x%04x] received in wrong state",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001477 pMsg->type);
1478 }
1479 return status;
1480 }
1481
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07001482 sme_debug("Scanning: ASSOC cnf can be given to upper layer");
Jeff Johnson172237b2017-11-07 15:32:59 -08001483 qdf_mem_set(&roamInfo, sizeof(struct csr_roam_info), 0);
Jeff Johnsoneddf5442017-10-04 10:55:53 -07001484 roam_info = &roamInfo;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001485 pUpperLayerAssocCnf = (tSirSmeAssocIndToUpperLayerCnf *) pMsgBuf;
1486 status = csr_roam_get_session_id_from_bssid(pMac,
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05301487 (struct qdf_mac_addr *)pUpperLayerAssocCnf->bssId,
1488 &sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001489 pSession = CSR_GET_SESSION(pMac, sessionId);
1490
1491 if (!pSession) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07001492 sme_err("session %d not found", sessionId);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301493 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001494 }
1495
1496 /* send the status code as Success */
Jeff Johnsoneddf5442017-10-04 10:55:53 -07001497 roam_info->statusCode = eSIR_SME_SUCCESS;
1498 roam_info->u.pConnectedProfile = &pSession->connectedProfile;
1499 roam_info->staId = (uint8_t) pUpperLayerAssocCnf->aid;
1500 roam_info->rsnIELen = (uint8_t) pUpperLayerAssocCnf->rsnIE.length;
1501 roam_info->prsnIE = pUpperLayerAssocCnf->rsnIE.rsnIEdata;
1502 roam_info->addIELen = (uint8_t) pUpperLayerAssocCnf->addIE.length;
1503 roam_info->paddIE = pUpperLayerAssocCnf->addIE.addIEdata;
1504 qdf_mem_copy(roam_info->peerMac.bytes,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001505 pUpperLayerAssocCnf->peerMacAddr,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301506 QDF_MAC_ADDR_SIZE);
Jeff Johnsoneddf5442017-10-04 10:55:53 -07001507 qdf_mem_copy(&roam_info->bssid.bytes, pUpperLayerAssocCnf->bssId,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301508 QDF_MAC_ADDR_SIZE);
Jeff Johnsoneddf5442017-10-04 10:55:53 -07001509 roam_info->wmmEnabledSta = pUpperLayerAssocCnf->wmmEnabledSta;
1510 if (CSR_IS_INFRA_AP(roam_info->u.pConnectedProfile)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001511 pMac->roam.roamSession[sessionId].connectState =
1512 eCSR_ASSOC_STATE_TYPE_INFRA_CONNECTED;
Jeff Johnsoneddf5442017-10-04 10:55:53 -07001513 roam_info->fReassocReq = pUpperLayerAssocCnf->reassocReq;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001514 status = csr_roam_call_callback(pMac, sessionId,
Jeff Johnsoneddf5442017-10-04 10:55:53 -07001515 roam_info, 0,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001516 eCSR_ROAM_INFRA_IND,
1517 eCSR_ROAM_RESULT_INFRA_ASSOCIATION_CNF);
1518 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001519 return status;
1520}
1521
Jeff Johnson00fa67d2016-10-14 08:07:36 -07001522static QDF_STATUS csr_add_pmkid_candidate_list(tpAniSirGlobal pMac,
1523 uint32_t sessionId,
1524 tSirBssDescription *pBssDesc,
1525 tDot11fBeaconIEs *pIes)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001526{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301527 QDF_STATUS status = QDF_STATUS_E_FAILURE;
gaurank kathpalia14e2f912017-08-31 14:51:45 +05301528 struct csr_roam_session *pSession = CSR_GET_SESSION(pMac, sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001529 tPmkidCandidateInfo *pmkid_info = NULL;
1530#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
1531 WLAN_HOST_DIAG_EVENT_DEF(secEvent,
1532 host_event_wlan_security_payload_type);
1533#endif /* FEATURE_WLAN_DIAG_SUPPORT_CSR */
1534 if (!pSession) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07001535 sme_err("session %d not found", sessionId);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301536 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001537 }
1538
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07001539 sme_debug("NumPmkidCandidate: %d", pSession->NumPmkidCandidate);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001540 if (!pIes)
1541 return status;
1542 /* check if this is a RSN BSS */
1543 if (!pIes->RSN.present)
1544 return status;
1545
1546 if (pSession->NumPmkidCandidate >= CSR_MAX_PMKID_ALLOWED)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301547 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001548
1549 /* BSS is capable of doing pre-authentication */
1550#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301551 qdf_mem_set(&secEvent, sizeof(host_event_wlan_security_payload_type),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001552 0);
1553 secEvent.eventId = WLAN_SECURITY_EVENT_PMKID_CANDIDATE_FOUND;
1554 secEvent.encryptionModeMulticast = (uint8_t)diag_enc_type_from_csr_type(
1555 pSession->connectedProfile.mcEncryptionType);
1556 secEvent.encryptionModeUnicast = (uint8_t)diag_enc_type_from_csr_type(
1557 pSession->connectedProfile.EncryptionType);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301558 qdf_mem_copy(secEvent.bssid, pSession->connectedProfile.bssid.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301559 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001560 secEvent.authMode = (uint8_t)diag_auth_type_from_csr_type(
1561 pSession->connectedProfile.AuthType);
1562 WLAN_HOST_DIAG_EVENT_REPORT(&secEvent, EVENT_WLAN_SECURITY);
1563#endif /* #ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR */
1564
1565 pmkid_info = &pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate];
1566 /* if yes, then add to PMKIDCandidateList */
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301567 qdf_mem_copy(pmkid_info->BSSID.bytes, pBssDesc->bssId,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301568 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001569 /* Bit 0 offirst byte - PreAuthentication Capability */
1570 if ((pIes->RSN.RSN_Cap[0] >> 0) & 0x1)
1571 pmkid_info->preAuthSupported = true;
1572 else
1573 pmkid_info->preAuthSupported = false;
1574 pSession->NumPmkidCandidate++;
1575 return status;
1576}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001577/*
1578 * This function checks whether new AP is found for the current connected
1579 * profile. If it is found, it return the sessionId, else it return invalid
1580 * sessionID
1581 */
Jeff Johnson00fa67d2016-10-14 08:07:36 -07001582static QDF_STATUS csr_process_bss_desc_for_pmkid_list(tpAniSirGlobal pMac,
1583 tSirBssDescription *pBssDesc,
1584 tDot11fBeaconIEs *pIes,
1585 uint8_t sessionId)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001586{
gaurank kathpalia14e2f912017-08-31 14:51:45 +05301587 struct csr_roam_session *pSession;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001588 tDot11fBeaconIEs *pIesLocal = pIes;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301589 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001590
1591 if (!(pIesLocal ||
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301592 QDF_IS_STATUS_SUCCESS(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001593 csr_get_parsed_bss_description_ies(pMac, pBssDesc,
1594 &pIesLocal))))
1595 return status;
1596
1597 if (!CSR_IS_SESSION_VALID(pMac, sessionId)) {
1598 if (!pIes)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301599 qdf_mem_free(pIesLocal);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001600 return status;
1601 }
1602
1603 pSession = CSR_GET_SESSION(pMac, sessionId);
1604 if (csr_is_conn_state_connected_infra(pMac, sessionId)
1605 && (eCSR_AUTH_TYPE_RSN == pSession->connectedProfile.AuthType)
1606 && csr_match_bss_to_connect_profile(pMac,
1607 &pSession->connectedProfile,
1608 pBssDesc, pIesLocal)) {
1609 /* This new BSS fits the current profile connected */
1610 status = csr_add_pmkid_candidate_list(pMac, sessionId,
1611 pBssDesc, pIesLocal);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301612 if (!QDF_IS_STATUS_SUCCESS(status))
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07001613 sme_err("csr_add_pmkid_candidate_list failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001614 else
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301615 status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001616 }
1617
1618 if (!pIes)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301619 qdf_mem_free(pIesLocal);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001620
1621 return status;
1622}
1623
1624#ifdef FEATURE_WLAN_WAPI
Jeff Johnson00fa67d2016-10-14 08:07:36 -07001625static QDF_STATUS csr_add_bkid_candidate_list(tpAniSirGlobal pMac,
1626 uint32_t sessionId,
1627 tSirBssDescription *pBssDesc,
1628 tDot11fBeaconIEs *pIes)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001629{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301630 QDF_STATUS status = QDF_STATUS_E_FAILURE;
gaurank kathpalia14e2f912017-08-31 14:51:45 +05301631 struct csr_roam_session *pSession = CSR_GET_SESSION(pMac, sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001632
1633 if (!pSession) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07001634 sme_err("session %d not found", sessionId);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301635 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001636 }
1637
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05301638 sme_debug("csr_add_bkid_candidate_list called pMac->scan.NumBkidCandidate: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001639 pSession->NumBkidCandidate);
1640 if (pIes) {
1641 /* check if this is a WAPI BSS */
1642 if (pIes->WAPI.present) {
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05301643 /* Check if the BSS is capable of doing
1644 * pre-authentication
1645 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001646 if (pSession->NumBkidCandidate < CSR_MAX_BKID_ALLOWED) {
1647
1648 /* if yes, then add to BKIDCandidateList */
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301649 qdf_mem_copy(pSession->
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001650 BkidCandidateInfo[pSession->
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05301651 NumBkidCandidate].
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001652 BSSID.bytes, pBssDesc->bssId,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301653 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001654 if (pIes->WAPI.preauth) {
1655 pSession->BkidCandidateInfo[pSession->
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05301656 NumBkidCandidate].
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001657 preAuthSupported = true;
1658 } else {
1659 pSession->BkidCandidateInfo[pSession->
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05301660 NumBkidCandidate].
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001661 preAuthSupported = false;
1662 }
1663 pSession->NumBkidCandidate++;
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05301664 } else
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301665 status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001666 }
1667 }
1668
1669 return status;
1670}
1671
1672/*
1673 * This function checks whether new AP is found for the current connected
1674 * profile, if so add to BKIDCandidateList
1675 */
Jeff Johnson00fa67d2016-10-14 08:07:36 -07001676static bool csr_process_bss_desc_for_bkid_list(tpAniSirGlobal pMac,
1677 tSirBssDescription *pBssDesc,
1678 tDot11fBeaconIEs *pIes)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001679{
1680 bool fRC = false;
1681 tDot11fBeaconIEs *pIesLocal = pIes;
1682 uint32_t sessionId;
gaurank kathpalia14e2f912017-08-31 14:51:45 +05301683 struct csr_roam_session *pSession;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301684 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001685
1686 if (!(pIesLocal ||
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301687 QDF_IS_STATUS_SUCCESS(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001688 csr_get_parsed_bss_description_ies(pMac, pBssDesc,
1689 &pIesLocal))))
1690 return fRC;
1691
1692 for (sessionId = 0; sessionId < CSR_ROAM_SESSION_MAX; sessionId++) {
1693 if (!CSR_IS_SESSION_VALID(pMac, sessionId))
1694 continue;
1695 pSession = CSR_GET_SESSION(pMac, sessionId);
1696 if (csr_is_conn_state_connected_infra(pMac, sessionId)
1697 && (eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE ==
1698 pSession->connectedProfile.AuthType)
1699 && csr_match_bss_to_connect_profile(pMac,
1700 &pSession->connectedProfile,
1701 pBssDesc, pIesLocal)) {
1702 /* this new BSS fits the current profile connected */
1703 status = csr_add_bkid_candidate_list(pMac, sessionId,
1704 pBssDesc, pIesLocal);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301705 if (QDF_IS_STATUS_SUCCESS(status))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001706 fRC = true;
1707 }
1708 }
1709 if (!pIes)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301710 qdf_mem_free(pIesLocal);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001711 return fRC;
1712}
1713
1714#endif
1715
Abhishek Singha92cf1e2017-11-02 17:04:11 +05301716static bool csr_scan_save_bss_description(tpAniSirGlobal
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05301717 pMac,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001718 tSirBssDescription *
1719 pBSSDescription,
1720 tDot11fBeaconIEs *pIes,
1721 uint8_t sessionId)
1722{
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05301723 struct tag_csrscan_result *pCsrBssDescription = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001724 uint32_t cbBSSDesc;
1725 uint32_t cbAllocated;
1726
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05301727 /* figure out how big the BSS description is (the BSSDesc->length does
1728 * NOT include the size of the length field itself).
1729 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001730 cbBSSDesc = pBSSDescription->length + sizeof(pBSSDescription->length);
1731
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05301732 cbAllocated = sizeof(struct tag_csrscan_result) + cbBSSDesc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001733
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301734 pCsrBssDescription = qdf_mem_malloc(cbAllocated);
Abhishek Singha92cf1e2017-11-02 17:04:11 +05301735 if (!pCsrBssDescription) {
1736 sme_err(" Failed to allocate memory for pCsrBssDescription");
1737 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001738 }
1739
Abhishek Singha92cf1e2017-11-02 17:04:11 +05301740 pCsrBssDescription->AgingCount =
1741 (int32_t) pMac->roam.configParam.agingCount;
1742 sme_debug(
1743 "Set Aging Count = %d for BSS " MAC_ADDRESS_STR " ",
1744 pCsrBssDescription->AgingCount,
1745 MAC_ADDR_ARRAY(pCsrBssDescription->Result.BssDescriptor.
1746 bssId));
1747 qdf_mem_copy(&pCsrBssDescription->Result.BssDescriptor,
1748 pBSSDescription, cbBSSDesc);
1749 csr_scan_add_result(pMac, pCsrBssDescription, pIes, sessionId);
1750
1751 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001752}
1753
1754/* Append a Bss Description... */
Abhishek Singha92cf1e2017-11-02 17:04:11 +05301755bool csr_scan_append_bss_description(tpAniSirGlobal pMac,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001756 tSirBssDescription *
1757 pSirBssDescription,
1758 tDot11fBeaconIEs *pIes,
1759 bool fForced, uint8_t sessionId)
1760{
Abhishek Singha92cf1e2017-11-02 17:04:11 +05301761 return csr_scan_save_bss_description(pMac,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001762 pSirBssDescription, pIes, sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001763}
1764
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05301765static void csr_purge_channel_power(tpAniSirGlobal pMac, tDblLinkList
1766 *pChannelList)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001767{
gaurank kathpalia14e2f912017-08-31 14:51:45 +05301768 struct csr_channel_powerinfo *pChannelSet;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001769 tListElem *pEntry;
1770
1771 csr_ll_lock(pChannelList);
1772 /*
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05301773 * Remove the channel sets from the learned list and put them
1774 * in the free list
1775 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001776 while ((pEntry = csr_ll_remove_head(pChannelList,
1777 LL_ACCESS_NOLOCK)) != NULL) {
gaurank kathpalia14e2f912017-08-31 14:51:45 +05301778 pChannelSet = GET_BASE_ADDR(pEntry,
1779 struct csr_channel_powerinfo, link);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001780 if (pChannelSet)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301781 qdf_mem_free(pChannelSet);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001782 }
1783 csr_ll_unlock(pChannelList);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001784}
1785
1786/*
1787 * Save the channelList into the ultimate storage as the final stage of channel
1788 * Input: pCountryInfo -- the country code (e.g. "USI"), channel list, and power
1789 * limit are all stored inside this data structure
1790 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301791QDF_STATUS csr_save_to_channel_power2_g_5_g(tpAniSirGlobal pMac,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001792 uint32_t tableSize,
1793 tSirMacChanInfo *channelTable)
1794{
1795 uint32_t i = tableSize / sizeof(tSirMacChanInfo);
1796 tSirMacChanInfo *pChannelInfo;
gaurank kathpalia14e2f912017-08-31 14:51:45 +05301797 struct csr_channel_powerinfo *pChannelSet;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001798 bool f2GHzInfoFound = false;
1799 bool f2GListPurged = false, f5GListPurged = false;
1800
1801 pChannelInfo = channelTable;
1802 /* atleast 3 bytes have to be remaining -- from "countryString" */
1803 while (i--) {
gaurank kathpalia14e2f912017-08-31 14:51:45 +05301804 pChannelSet = qdf_mem_malloc(sizeof(struct csr_channel_powerinfo));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001805 if (NULL == pChannelSet) {
1806 pChannelInfo++;
1807 continue;
1808 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001809 pChannelSet->firstChannel = pChannelInfo->firstChanNum;
1810 pChannelSet->numChannels = pChannelInfo->numChannels;
1811 /*
1812 * Now set the inter-channel offset based on the frequency band
1813 * the channel set lies in
1814 */
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001815 if ((WLAN_REG_IS_24GHZ_CH(pChannelSet->firstChannel)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001816 ((pChannelSet->firstChannel +
1817 (pChannelSet->numChannels - 1)) <=
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001818 WLAN_REG_MAX_24GHZ_CH_NUM)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001819 pChannelSet->interChannelOffset = 1;
1820 f2GHzInfoFound = true;
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001821 } else if ((WLAN_REG_IS_5GHZ_CH(pChannelSet->firstChannel))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001822 && ((pChannelSet->firstChannel +
1823 ((pChannelSet->numChannels - 1) * 4)) <=
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001824 WLAN_REG_MAX_5GHZ_CH_NUM)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001825 pChannelSet->interChannelOffset = 4;
1826 f2GHzInfoFound = false;
1827 } else {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07001828 sme_warn("Invalid Channel %d Present in Country IE",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001829 pChannelSet->firstChannel);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301830 qdf_mem_free(pChannelSet);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301831 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001832 }
Anurag Chouhan6d760662016-02-20 16:05:43 +05301833 pChannelSet->txPower = QDF_MIN(pChannelInfo->maxTxPower,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001834 pMac->roam.configParam.nTxPowerCap);
1835 if (f2GHzInfoFound) {
1836 if (!f2GListPurged) {
1837 /* purge previous results if found new */
1838 csr_purge_channel_power(pMac,
1839 &pMac->scan.
1840 channelPowerInfoList24);
1841 f2GListPurged = true;
1842 }
1843 if (CSR_IS_OPERATING_BG_BAND(pMac)) {
1844 /* add to the list of 2.4 GHz channel sets */
1845 csr_ll_insert_tail(&pMac->scan.
1846 channelPowerInfoList24,
1847 &pChannelSet->link,
1848 LL_ACCESS_LOCK);
1849 } else {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07001850 sme_debug(
1851 "Adding 11B/G ch in 11A. 1st ch %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001852 pChannelSet->firstChannel);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301853 qdf_mem_free(pChannelSet);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001854 }
1855 } else {
1856 /* 5GHz info found */
1857 if (!f5GListPurged) {
1858 /* purge previous results if found new */
1859 csr_purge_channel_power(pMac,
1860 &pMac->scan.
1861 channelPowerInfoList5G);
1862 f5GListPurged = true;
1863 }
1864 if (CSR_IS_OPERATING_A_BAND(pMac)) {
1865 /* add to the list of 5GHz channel sets */
1866 csr_ll_insert_tail(&pMac->scan.
1867 channelPowerInfoList5G,
1868 &pChannelSet->link,
1869 LL_ACCESS_LOCK);
1870 } else {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07001871 sme_debug(
1872 "Adding 11A ch in B/G. 1st ch %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001873 pChannelSet->firstChannel);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301874 qdf_mem_free(pChannelSet);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001875 }
1876 }
1877 pChannelInfo++; /* move to next entry */
1878 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301879 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001880}
1881
1882static void csr_clear_dfs_channel_list(tpAniSirGlobal pMac)
1883{
1884 tSirMbMsg *pMsg;
1885 uint16_t msgLen;
1886
1887 msgLen = (uint16_t) (sizeof(tSirMbMsg));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301888 pMsg = qdf_mem_malloc(msgLen);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001889 if (NULL != pMsg) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001890 pMsg->type = eWNI_SME_CLEAR_DFS_CHANNEL_LIST;
1891 pMsg->msgLen = msgLen;
Rajeev Kumard138ac52017-01-30 18:38:37 -08001892 umac_send_mb_message_to_mac(pMsg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001893 }
1894}
1895
1896void csr_apply_power2_current(tpAniSirGlobal pMac)
1897{
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07001898 sme_debug("Updating Cfg with power settings");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001899 csr_save_tx_power_to_cfg(pMac, &pMac->scan.channelPowerInfoList24,
1900 WNI_CFG_MAX_TX_POWER_2_4);
1901 csr_save_tx_power_to_cfg(pMac, &pMac->scan.channelPowerInfoList5G,
1902 WNI_CFG_MAX_TX_POWER_5);
1903}
1904
1905void csr_apply_channel_power_info_to_fw(tpAniSirGlobal mac_ctx,
gaurank kathpalia14e2f912017-08-31 14:51:45 +05301906 struct csr_channel *ch_lst,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001907 uint8_t *countryCode)
1908{
1909 int i;
1910 uint8_t num_ch = 0;
1911 uint8_t tempNumChannels = 0;
gaurank kathpalia14e2f912017-08-31 14:51:45 +05301912 struct csr_channel tmp_ch_lst;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001913
1914 if (ch_lst->numChannels) {
1915 tempNumChannels = CSR_MIN(ch_lst->numChannels,
1916 WNI_CFG_VALID_CHANNEL_LIST_LEN);
1917 for (i = 0; i < tempNumChannels; i++) {
1918 tmp_ch_lst.channelList[num_ch] = ch_lst->channelList[i];
1919 num_ch++;
1920 }
1921 tmp_ch_lst.numChannels = num_ch;
1922 /* Store the channel+power info in the global place: Cfg */
1923 csr_apply_power2_current(mac_ctx);
1924 csr_set_cfg_valid_channel_list(mac_ctx, tmp_ch_lst.channelList,
1925 tmp_ch_lst.numChannels);
1926 /*
1927 * extend scan capability, build a scan list based on the
1928 * channel list : channel# + active/passive scan
1929 */
1930 csr_set_cfg_scan_control_list(mac_ctx, countryCode,
1931 &tmp_ch_lst);
1932 /* Send msg to Lim to clear DFS channel list */
1933 csr_clear_dfs_channel_list(mac_ctx);
1934 } else {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07001935 sme_err("11D channel list is empty");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001936 }
1937 csr_set_cfg_country_code(mac_ctx, countryCode);
1938}
1939
1940#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
1941static void csr_diag_reset_country_information(tpAniSirGlobal pMac)
1942{
1943
1944 host_log_802_11d_pkt_type *p11dLog;
1945 int Index;
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05301946
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001947 WLAN_HOST_DIAG_LOG_ALLOC(p11dLog, host_log_802_11d_pkt_type,
1948 LOG_WLAN_80211D_C);
1949 if (!p11dLog)
1950 return;
1951
1952 p11dLog->eventId = WLAN_80211D_EVENT_RESET;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301953 qdf_mem_copy(p11dLog->countryCode, pMac->scan.countryCodeCurrent, 3);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001954 p11dLog->numChannel = pMac->scan.base_channels.numChannels;
1955 if (p11dLog->numChannel <= HOST_LOG_MAX_NUM_CHANNEL) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301956 qdf_mem_copy(p11dLog->Channels,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001957 pMac->scan.base_channels.channelList,
1958 p11dLog->numChannel);
1959 for (Index = 0;
1960 Index < pMac->scan.base_channels.numChannels;
1961 Index++) {
Anurag Chouhan6d760662016-02-20 16:05:43 +05301962 p11dLog->TxPwr[Index] = QDF_MIN(
Amar Singhal5cccafe2017-02-15 12:42:58 -08001963 pMac->scan.defaultPowerTable[Index].tx_power,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001964 pMac->roam.configParam.nTxPowerCap);
1965 }
1966 }
1967 if (!pMac->roam.configParam.Is11dSupportEnabled)
1968 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
1969 else
1970 p11dLog->supportMultipleDomain =
1971 WLAN_80211D_SUPPORT_MULTI_DOMAIN;
1972 WLAN_HOST_DIAG_LOG_REPORT(p11dLog);
1973}
1974#endif /* FEATURE_WLAN_DIAG_SUPPORT_CSR */
1975
1976/**
1977 * csr_apply_channel_power_info_wrapper() - sends channel info to fw
1978 * @pMac: main MAC data structure
1979 *
1980 * This function sends the channel power info to firmware
1981 *
1982 * Return: none
1983 */
1984void csr_apply_channel_power_info_wrapper(tpAniSirGlobal pMac)
1985{
1986
1987#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
1988 csr_diag_reset_country_information(pMac);
1989#endif /* FEATURE_WLAN_DIAG_SUPPORT_CSR */
1990 csr_prune_channel_list_for_mode(pMac, &pMac->scan.base_channels);
1991 csr_save_channel_power_for_band(pMac, false);
1992 csr_save_channel_power_for_band(pMac, true);
1993 /* apply the channel list, power settings, and the country code. */
1994 csr_apply_channel_power_info_to_fw(pMac,
1995 &pMac->scan.base_channels, pMac->scan.countryCodeCurrent);
1996 /* clear the 11d channel list */
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301997 qdf_mem_set(&pMac->scan.channels11d, sizeof(pMac->scan.channels11d), 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001998}
1999
2000void csr_clear_votes_for_country_info(tpAniSirGlobal pMac)
2001{
2002 pMac->scan.countryCodeCount = 0;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302003 qdf_mem_set(pMac->scan.votes11d,
gaurank kathpalia14e2f912017-08-31 14:51:45 +05302004 sizeof(struct csr_votes11d) * CSR_MAX_NUM_COUNTRY_CODE, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002005}
2006
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002007/**
2008 * csr_set_country_code() - Set country code
2009 * @pMac: main MAC data structure
2010 * @pCountry: ptr to Country Code
2011 *
2012 * This function sends the channel power info to firmware
2013 *
2014 * Return: none
2015 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302016QDF_STATUS csr_set_country_code(tpAniSirGlobal pMac, uint8_t *pCountry)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002017{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302018 QDF_STATUS status = QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002019 v_REGDOMAIN_t domainId;
2020
2021 if (pCountry) {
2022
2023 status = csr_get_regulatory_domain_for_country(pMac, pCountry,
Amar Singhala297bfa2015-10-15 15:07:29 -07002024 &domainId,
2025 SOURCE_USERSPACE);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302026 if (QDF_IS_STATUS_SUCCESS(status)) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302027 qdf_mem_copy(pMac->scan.countryCodeCurrent,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002028 pCountry,
2029 WNI_CFG_COUNTRY_CODE_LEN);
2030 csr_set_cfg_country_code(pMac, pCountry);
2031 }
2032 }
2033 return status;
2034}
2035
2036/* caller allocated memory for pNumChn and pChnPowerInfo */
2037/* As input, *pNumChn has the size of the array of pChnPowerInfo */
2038/* Upon return, *pNumChn has the number of channels assigned. */
Jeff Johnson00fa67d2016-10-14 08:07:36 -07002039static void csr_get_channel_power_info(tpAniSirGlobal pMac, tDblLinkList *list,
2040 uint32_t *num_ch,
2041 struct channel_power *chn_pwr_info)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002042{
2043 tListElem *entry;
2044 uint32_t chn_idx = 0, idx;
gaurank kathpalia14e2f912017-08-31 14:51:45 +05302045 struct csr_channel_powerinfo *ch_set;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002046
2047 /* Get 2.4Ghz first */
2048 entry = csr_ll_peek_head(list, LL_ACCESS_LOCK);
2049 while (entry && (chn_idx < *num_ch)) {
gaurank kathpalia14e2f912017-08-31 14:51:45 +05302050 ch_set = GET_BASE_ADDR(entry,
2051 struct csr_channel_powerinfo, link);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002052 for (idx = 0; (idx < ch_set->numChannels)
2053 && (chn_idx < *num_ch); idx++) {
Amar Singhala297bfa2015-10-15 15:07:29 -07002054 chn_pwr_info[chn_idx].chan_num =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002055 (uint8_t) (ch_set->firstChannel
2056 + (idx * ch_set->interChannelOffset));
Amar Singhal5cccafe2017-02-15 12:42:58 -08002057 chn_pwr_info[chn_idx++].tx_power = ch_set->txPower;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002058 }
2059 entry = csr_ll_next(list, entry, LL_ACCESS_LOCK);
2060 }
2061 *num_ch = chn_idx;
2062
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002063}
2064
2065#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
Jeff Johnson00fa67d2016-10-14 08:07:36 -07002066static void csr_diag_apply_country_info(tpAniSirGlobal mac_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002067{
2068 host_log_802_11d_pkt_type *p11dLog;
Amar Singhala297bfa2015-10-15 15:07:29 -07002069 struct channel_power chnPwrInfo[WNI_CFG_VALID_CHANNEL_LIST_LEN];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002070 uint32_t nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN, nTmp;
2071
2072 WLAN_HOST_DIAG_LOG_ALLOC(p11dLog, host_log_802_11d_pkt_type,
2073 LOG_WLAN_80211D_C);
2074 if (!p11dLog)
2075 return;
2076
2077 p11dLog->eventId = WLAN_80211D_EVENT_COUNTRY_SET;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302078 qdf_mem_copy(p11dLog->countryCode, mac_ctx->scan.countryCode11d, 3);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002079 p11dLog->numChannel = mac_ctx->scan.channels11d.numChannels;
2080 if (p11dLog->numChannel > HOST_LOG_MAX_NUM_CHANNEL)
2081 goto diag_end;
2082
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302083 qdf_mem_copy(p11dLog->Channels,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002084 mac_ctx->scan.channels11d.channelList,
2085 p11dLog->numChannel);
2086 csr_get_channel_power_info(mac_ctx,
2087 &mac_ctx->scan.channelPowerInfoList24,
2088 &nChnInfo, chnPwrInfo);
2089 nTmp = nChnInfo;
2090 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN - nTmp;
2091 csr_get_channel_power_info(mac_ctx,
2092 &mac_ctx->scan.channelPowerInfoList5G,
2093 &nChnInfo, &chnPwrInfo[nTmp]);
2094 for (nTmp = 0; nTmp < p11dLog->numChannel; nTmp++) {
2095 for (nChnInfo = 0;
2096 nChnInfo < WNI_CFG_VALID_CHANNEL_LIST_LEN;
2097 nChnInfo++) {
2098 if (p11dLog->Channels[nTmp] ==
Amar Singhala297bfa2015-10-15 15:07:29 -07002099 chnPwrInfo[nChnInfo].chan_num) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002100 p11dLog->TxPwr[nTmp] =
Amar Singhal5cccafe2017-02-15 12:42:58 -08002101 chnPwrInfo[nChnInfo].tx_power;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002102 break;
2103 }
2104 }
2105 }
2106diag_end:
2107 if (!mac_ctx->roam.configParam.Is11dSupportEnabled)
2108 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
2109 else
2110 p11dLog->supportMultipleDomain =
2111 WLAN_80211D_SUPPORT_MULTI_DOMAIN;
2112 WLAN_HOST_DIAG_LOG_REPORT(p11dLog);
2113}
2114#endif /* #ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR */
2115
2116/**
2117 * csr_apply_country_information() - apply country code information
2118 * @pMac: core MAC data structure
2119 *
2120 * This function programs the new country code
2121 *
2122 * Return: none
2123 */
2124void csr_apply_country_information(tpAniSirGlobal pMac)
2125{
2126 v_REGDOMAIN_t domainId;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302127 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002128
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07002129 if (!wlan_reg_11d_enabled_on_host(pMac->psoc)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002130 || 0 == pMac->scan.channelOf11dInfo)
2131 return;
2132 status = csr_get_regulatory_domain_for_country(pMac,
Amar Singhala297bfa2015-10-15 15:07:29 -07002133 pMac->scan.countryCode11d, &domainId, SOURCE_QUERY);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302134 if (!QDF_IS_STATUS_SUCCESS(status))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002135 return;
2136 /* Check whether we need to enforce default domain */
2137#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
2138 csr_diag_apply_country_info(pMac);
2139#endif /* #ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR */
2140
2141 if (pMac->scan.domainIdCurrent != domainId)
2142 return;
2143 if (pMac->scan.domainIdCurrent != domainId) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07002144 sme_debug("Domain Changed Old %d, new %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002145 pMac->scan.domainIdCurrent, domainId);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07002146 if (domainId >= REGDOMAIN_COUNT)
2147 sme_err("fail to set regId %d", domainId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002148 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002149 pMac->scan.domainIdCurrent = domainId;
2150 /* switch to active scans using this new channel list */
2151 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
2152}
2153
2154void csr_save_channel_power_for_band(tpAniSirGlobal pMac, bool fill_5f)
2155{
2156 uint32_t idx, count = 0;
2157 tSirMacChanInfo *chan_info;
2158 tSirMacChanInfo *ch_info_start;
2159 int32_t max_ch_idx;
2160 bool tmp_bool;
2161 uint8_t ch = 0;
2162
2163 max_ch_idx =
2164 (pMac->scan.base_channels.numChannels <
2165 WNI_CFG_VALID_CHANNEL_LIST_LEN) ?
2166 pMac->scan.base_channels.numChannels :
2167 WNI_CFG_VALID_CHANNEL_LIST_LEN;
2168
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302169 chan_info = qdf_mem_malloc(sizeof(tSirMacChanInfo) *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002170 WNI_CFG_VALID_CHANNEL_LIST_LEN);
2171 if (NULL == chan_info)
2172 return;
2173
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002174 ch_info_start = chan_info;
2175 for (idx = 0; idx < max_ch_idx; idx++) {
Amar Singhala297bfa2015-10-15 15:07:29 -07002176 ch = pMac->scan.defaultPowerTable[idx].chan_num;
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07002177 tmp_bool = (fill_5f && WLAN_REG_IS_5GHZ_CH(ch)) ||
2178 (!fill_5f && WLAN_REG_IS_24GHZ_CH(ch));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002179 if (!tmp_bool)
2180 continue;
2181
2182 if (count >= WNI_CFG_VALID_CHANNEL_LIST_LEN) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07002183 sme_warn("count: %d exceeded", count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002184 break;
2185 }
2186
2187 chan_info->firstChanNum =
Amar Singhala297bfa2015-10-15 15:07:29 -07002188 pMac->scan.defaultPowerTable[idx].chan_num;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002189 chan_info->numChannels = 1;
2190 chan_info->maxTxPower =
Amar Singhal5cccafe2017-02-15 12:42:58 -08002191 QDF_MIN(pMac->scan.defaultPowerTable[idx].tx_power,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002192 pMac->roam.configParam.nTxPowerCap);
2193 chan_info++;
2194 count++;
2195 }
2196 if (count) {
2197 csr_save_to_channel_power2_g_5_g(pMac,
2198 count * sizeof(tSirMacChanInfo), ch_info_start);
2199 }
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302200 qdf_mem_free(ch_info_start);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002201}
2202
2203bool csr_is_supported_channel(tpAniSirGlobal pMac, uint8_t channelId)
2204{
2205 bool fRet = false;
2206 uint32_t i;
2207
2208 for (i = 0; i < pMac->scan.base_channels.numChannels; i++) {
2209 if (channelId ==
2210 pMac->scan.base_channels.channelList[i]) {
2211 fRet = true;
2212 break;
2213 }
2214 }
2215
2216 return fRet;
2217}
2218
2219/*
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05302220 * 802.11D only: Gather 11d IE via beacon or Probe response and store them in
2221 * pAdapter->channels11d
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002222 */
2223bool csr_learn_11dcountry_information(tpAniSirGlobal pMac,
2224 tSirBssDescription *pSirBssDesc,
2225 tDot11fBeaconIEs *pIes, bool fForce)
2226{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302227 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002228 uint8_t *pCountryCodeSelected;
2229 bool fRet = false;
2230 v_REGDOMAIN_t domainId;
2231 tDot11fBeaconIEs *pIesLocal = pIes;
2232 bool useVoting = false;
2233
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002234 if ((NULL == pSirBssDesc) && (NULL == pIes))
2235 useVoting = true;
2236
2237 /* check if .11d support is enabled */
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07002238 if (!wlan_reg_11d_enabled_on_host(pMac->psoc))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002239 goto free_ie;
2240
2241 if (false == useVoting) {
2242 if (!pIesLocal &&
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302243 (!QDF_IS_STATUS_SUCCESS(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002244 csr_get_parsed_bss_description_ies(
2245 pMac, pSirBssDesc, &pIesLocal))))
2246 goto free_ie;
2247 /* check if country information element is present */
2248 if (!pIesLocal->Country.present)
2249 /* No country info */
2250 goto free_ie;
2251 status = csr_get_regulatory_domain_for_country(pMac,
2252 pIesLocal->Country.country, &domainId,
Amar Singhala297bfa2015-10-15 15:07:29 -07002253 SOURCE_QUERY);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302254 if (QDF_IS_STATUS_SUCCESS(status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002255 && (domainId == REGDOMAIN_WORLD))
2256 goto free_ie;
2257 } /* useVoting == false */
2258
2259 if (false == useVoting)
2260 pCountryCodeSelected = pIesLocal->Country.country;
2261 else
2262 pCountryCodeSelected = pMac->scan.countryCodeElected;
2263
Amar Singhalb6d0dc42016-10-19 09:45:05 -07002264 if (qdf_mem_cmp(pCountryCodeSelected, pMac->scan.countryCodeCurrent,
2265 CDS_COUNTRY_CODE_LEN) == 0) {
2266 qdf_mem_copy(pMac->scan.countryCode11d,
2267 pMac->scan.countryCodeCurrent,
2268 CDS_COUNTRY_CODE_LEN);
Amar Singhal9d5b1fe2016-10-16 20:16:05 -07002269 goto free_ie;
Amar Singhalb6d0dc42016-10-19 09:45:05 -07002270 }
Amar Singhal9d5b1fe2016-10-16 20:16:05 -07002271
Amar Singhal6edf9732016-11-20 21:43:40 -08002272 pMac->reg_hint_src = SOURCE_11D;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002273 status = csr_get_regulatory_domain_for_country(pMac,
Amar Singhala297bfa2015-10-15 15:07:29 -07002274 pCountryCodeSelected, &domainId, SOURCE_11D);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302275 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07002276 sme_err("fail to get regId %d", domainId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002277 fRet = false;
2278 goto free_ie;
2279 }
2280
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002281 fRet = true;
2282free_ie:
2283 if (!pIes && pIesLocal) {
2284 /* locally allocated */
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302285 qdf_mem_free(pIesLocal);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002286 }
2287 return fRet;
2288}
2289
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002290void csr_reinit_scan_cmd(tpAniSirGlobal pMac, tSmeCmd *pCommand)
2291{
2292 switch (pCommand->u.scanCmd.reason) {
2293 case eCsrScanAbortNormalScan:
2294 default:
2295 csr_scan_free_request(pMac, &pCommand->u.scanCmd.u.scanRequest);
2296 break;
2297 }
2298 if (pCommand->u.scanCmd.pToRoamProfile) {
2299 csr_release_profile(pMac, pCommand->u.scanCmd.pToRoamProfile);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302300 qdf_mem_free(pCommand->u.scanCmd.pToRoamProfile);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002301 }
gaurank kathpalia14e2f912017-08-31 14:51:45 +05302302 qdf_mem_set(&pCommand->u.scanCmd, sizeof(struct scan_cmd), 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002303}
2304
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002305#ifdef NAPIER_SCAN
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05302306static enum csr_scancomplete_nextcommand csr_scan_get_next_command_state(
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002307 tpAniSirGlobal mac_ctx,
2308 uint32_t session_id,
2309 eCsrScanStatus scan_status,
2310 uint8_t *chan)
2311{
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05302312 enum csr_scancomplete_nextcommand NextCommand = eCsrNextScanNothing;
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002313 int8_t channel;
gaurank kathpalia14e2f912017-08-31 14:51:45 +05302314 struct csr_roam_session *session;
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002315
Krunal Soni35a94532018-01-09 10:54:31 -08002316 if (!CSR_IS_SESSION_VALID(mac_ctx, session_id)) {
2317 sme_err("session %d is invalid", session_id);
2318 return NextCommand;
2319 }
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002320 session = CSR_GET_SESSION(mac_ctx, session_id);
2321 switch (session->scan_info.scan_reason) {
2322 case eCsrScanForSsid:
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07002323 sme_debug("Resp for Scan For Ssid");
Tushnim Bhattacharyya0c4ad2d2017-03-09 15:59:03 -08002324 channel = policy_mgr_search_and_check_for_session_conc(
2325 mac_ctx->psoc,
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002326 session_id,
2327 session->scan_info.profile);
2328 if ((!channel) || scan_status) {
2329 NextCommand = eCsrNexteScanForSsidFailure;
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07002330 sme_err("next Scan For Ssid Failure %d %d",
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002331 channel, scan_status);
2332 } else {
2333 NextCommand = eCsrNextCheckAllowConc;
2334 *chan = channel;
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07002335 sme_debug("next CheckAllowConc");
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002336 }
2337 break;
2338 default:
2339 NextCommand = eCsrNextScanNothing;
2340 break;
2341 }
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07002342 sme_debug("Next Command %d", NextCommand);
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002343 return NextCommand;
2344}
2345#else
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05302346static enum csr_scancomplete_nextcommand csr_scan_get_next_command_state(
Jeff Johnson00fa67d2016-10-14 08:07:36 -07002347 tpAniSirGlobal pMac,
2348 tSmeCmd *pCommand,
2349 bool fSuccess,
2350 uint8_t *chan)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002351{
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05302352 enum csr_scancomplete_nextcommand NextCommand = eCsrNextScanNothing;
Chandrasekaran, Manishekaref70c0d2015-10-20 19:54:55 +05302353 int8_t channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002354
2355 switch (pCommand->u.scanCmd.reason) {
2356 case eCsrScan11d1:
2357 NextCommand =
2358 (fSuccess) ? eCsrNext11dScan1Success :
2359 eCsrNext11dScan1Failure;
2360 break;
2361 case eCsrScan11d2:
2362 NextCommand =
2363 (fSuccess) ? eCsrNext11dScan2Success :
2364 eCsrNext11dScan2Failure;
2365 break;
2366 case eCsrScan11dDone:
2367 NextCommand = eCsrNext11dScanComplete;
2368 break;
2369 case eCsrScanLostLink1:
2370 NextCommand =
2371 (fSuccess) ? eCsrNextLostLinkScan1Success :
2372 eCsrNextLostLinkScan1Failed;
2373 break;
2374 case eCsrScanLostLink2:
2375 NextCommand =
2376 (fSuccess) ? eCsrNextLostLinkScan2Success :
2377 eCsrNextLostLinkScan2Failed;
2378 break;
2379 case eCsrScanLostLink3:
2380 NextCommand =
2381 (fSuccess) ? eCsrNextLostLinkScan3Success :
2382 eCsrNextLostLinkScan3Failed;
2383 break;
2384 case eCsrScanForSsid:
Krunal Soni3091bcc2016-06-23 12:28:21 -07002385 /* success:
Chandrasekaran, Manishekaref70c0d2015-10-20 19:54:55 +05302386 * set hw_mode success -> csr_scan_handle_search_for_ssid
2387 * set hw_mode fail -> csr_scan_handle_search_for_ssid_failure
2388 * failure: csr_scan_handle_search_for_ssid_failure
2389 */
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07002390 sme_debug("Resp for eCsrScanForSsid");
Tushnim Bhattacharyya0c4ad2d2017-03-09 15:59:03 -08002391 channel = policy_mgr_search_and_check_for_session_conc(
2392 pMac->psoc,
Krunal Soni3091bcc2016-06-23 12:28:21 -07002393 pCommand->sessionId,
2394 pCommand->u.scanCmd.pToRoamProfile);
2395 if ((!channel) || !fSuccess) {
2396 NextCommand = eCsrNexteScanForSsidFailure;
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07002397 sme_debug("next ScanForSsidFailure %d %d",
Krunal Soni3091bcc2016-06-23 12:28:21 -07002398 channel, fSuccess);
2399 } else {
2400 NextCommand = eCsrNextCheckAllowConc;
2401 *chan = channel;
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07002402 sme_debug("next CheckAllowConc");
Chandrasekaran, Manishekaref70c0d2015-10-20 19:54:55 +05302403 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002404 break;
2405 default:
2406 NextCommand = eCsrNextScanNothing;
2407 break;
2408 }
2409 return NextCommand;
2410}
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002411#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002412
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002413#ifndef NAPIER_SCAN
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002414/* Return whether the pCommand is finished. */
Jeff Johnson00fa67d2016-10-14 08:07:36 -07002415static bool csr_handle_scan11d1_failure(tpAniSirGlobal pMac, tSmeCmd *pCommand)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002416{
2417 bool fRet = true;
2418
2419 /* Apply back the default setting and passively scan one more time. */
2420 csr_apply_channel_power_info_wrapper(pMac);
2421 pCommand->u.scanCmd.reason = eCsrScan11d2;
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05302422 if (QDF_IS_STATUS_SUCCESS(csr_scan_channels(pMac, pCommand)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002423 fRet = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002424
2425 return fRet;
2426}
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002427#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002428#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
2429static void
Abhishek Singh6f56d212017-04-12 14:31:57 +05302430csr_diag_scan_complete(tpAniSirGlobal mac_ctx,
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002431 eCsrScanStatus scan_status)
2432{
2433 host_log_scan_pkt_type *pScanLog = NULL;
Abhishek Singh6f56d212017-04-12 14:31:57 +05302434 qdf_list_t *list = NULL;
2435 struct wlan_objmgr_pdev *pdev = NULL;
2436 struct scan_cache_node *cur_node = NULL;
2437 struct scan_cache_node *next_node = NULL;
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002438 int n = 0, c = 0;
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002439
2440 WLAN_HOST_DIAG_LOG_ALLOC(pScanLog,
2441 host_log_scan_pkt_type,
2442 LOG_WLAN_SCAN_C);
2443 if (!pScanLog)
2444 return;
2445
2446 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_RSP;
2447
2448 if (eCSR_SCAN_SUCCESS != scan_status) {
2449 pScanLog->status = WLAN_SCAN_STATUS_FAILURE;
2450 WLAN_HOST_DIAG_LOG_REPORT(pScanLog);
2451 return;
2452 }
Abhishek Singh6f56d212017-04-12 14:31:57 +05302453 pdev = wlan_objmgr_get_pdev_by_id(mac_ctx->psoc,
2454 0, WLAN_LEGACY_MAC_ID);
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002455
Abhishek Singh6f56d212017-04-12 14:31:57 +05302456 if (!pdev) {
2457 sme_err("pdev is NULL");
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002458 return;
2459 }
2460
Abhishek Singh6f56d212017-04-12 14:31:57 +05302461 list = ucfg_scan_get_result(pdev, NULL);
Krunal Soni35a94532018-01-09 10:54:31 -08002462 if (list)
2463 sme_debug("num_entries %d", qdf_list_size(list));
2464 if (!list || (list && !qdf_list_size(list))) {
Abhishek Singh6f56d212017-04-12 14:31:57 +05302465 sme_err("get scan result failed");
2466 WLAN_HOST_DIAG_LOG_REPORT(pScanLog);
2467 wlan_objmgr_pdev_release_ref(pdev, WLAN_LEGACY_MAC_ID);
Sandeep Puligilla2e233c62017-11-07 12:45:57 -08002468 if (list)
2469 ucfg_scan_purge_results(list);
Abhishek Singh6f56d212017-04-12 14:31:57 +05302470 return;
2471 }
2472
2473 qdf_list_peek_front(list,
2474 (qdf_list_node_t **) &cur_node);
2475 while (cur_node) {
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002476 if (n < HOST_LOG_MAX_NUM_BSSID) {
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002477 qdf_mem_copy(pScanLog->bssid[n],
Abhishek Singh6f56d212017-04-12 14:31:57 +05302478 cur_node->entry->bssid.bytes,
2479 QDF_MAC_ADDR_SIZE);
2480 if (cur_node->entry->ssid.length >
2481 WLAN_SSID_MAX_LEN)
2482 cur_node->entry->ssid.length =
2483 WLAN_SSID_MAX_LEN;
2484 qdf_mem_copy(pScanLog->ssid[n],
2485 cur_node->entry->ssid.ssid,
2486 cur_node->entry->ssid.length);
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002487 n++;
2488 }
2489 c++;
Abhishek Singh6f56d212017-04-12 14:31:57 +05302490 qdf_list_peek_next(
2491 list,
2492 (qdf_list_node_t *) cur_node,
2493 (qdf_list_node_t **) &next_node);
2494 cur_node = next_node;
2495 next_node = NULL;
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002496 }
2497 pScanLog->numSsid = (uint8_t) n;
2498 pScanLog->totalSsid = (uint8_t) c;
Abhishek Singh6f56d212017-04-12 14:31:57 +05302499 ucfg_scan_purge_results(list);
2500 wlan_objmgr_pdev_release_ref(pdev, WLAN_LEGACY_MAC_ID);
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002501 WLAN_HOST_DIAG_LOG_REPORT(pScanLog);
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002502}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002503#endif /* #ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR */
2504
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002505#ifdef NAPIER_SCAN
2506/**
Deepak Dhamdhere6f7fbbe2017-02-28 13:35:52 -08002507 * csr_saved_scan_cmd_free_fields() - Free internal fields of scan command
2508 *
2509 * @mac_ctx: Global MAC context
2510 * @saved_scan_cmd: Pointer to scan command
2511 *
2512 * Frees data structures allocated inside saved_scan_cmd and releases
2513 * the profile.
2514 * Return: None
2515 */
2516
2517void csr_saved_scan_cmd_free_fields(tpAniSirGlobal mac_ctx,
gaurank kathpalia14e2f912017-08-31 14:51:45 +05302518 struct csr_roam_session *session)
Deepak Dhamdhere6f7fbbe2017-02-28 13:35:52 -08002519{
2520 if (session->scan_info.profile) {
2521 csr_release_profile(mac_ctx,
2522 session->scan_info.profile);
2523 qdf_mem_free(session->scan_info.profile);
2524 session->scan_info.profile = NULL;
2525 }
2526
2527 if (session->scan_info.roambssentry) {
2528 qdf_mem_free(session->scan_info.roambssentry);
2529 session->scan_info.roambssentry = NULL;
2530 }
2531}
2532/**
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002533 * csr_save_profile() - Save the profile info from sme command
2534 * @mac_ctx: Global MAC context
2535 * @save_cmd: Pointer where the command will be saved
2536 * @command: Command from which the profile will be saved
2537 *
2538 * Saves the profile information from the SME's scan command
2539 *
2540 * Return: QDF_STATUS
2541 */
2542static QDF_STATUS csr_save_profile(tpAniSirGlobal mac_ctx,
2543 uint32_t session_id)
2544{
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05302545 struct tag_csrscan_result *scan_result;
2546 struct tag_csrscan_result *temp;
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002547 uint32_t bss_len;
gaurank kathpalia14e2f912017-08-31 14:51:45 +05302548 struct csr_roam_session *session;
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002549
Krunal Soni35a94532018-01-09 10:54:31 -08002550 /*
2551 * check the session's validity first, if session itself
2552 * is not valid then there is no point of releasing the memory
2553 * for invalid session (i.e. "goto error" case)
2554 */
2555 if (!CSR_IS_SESSION_VALID(mac_ctx, session_id)) {
2556 sme_err("session %d is invalid", session_id);
2557 return QDF_STATUS_E_FAILURE;
2558 }
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002559 session = CSR_GET_SESSION(mac_ctx, session_id);
2560 if (!session->scan_info.roambssentry)
2561 return QDF_STATUS_SUCCESS;
2562
2563 scan_result = GET_BASE_ADDR(session->scan_info.roambssentry,
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05302564 struct tag_csrscan_result, Link);
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002565
2566 bss_len = scan_result->Result.BssDescriptor.length +
2567 sizeof(scan_result->Result.BssDescriptor.length);
2568
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05302569 temp = qdf_mem_malloc(sizeof(struct tag_csrscan_result) + bss_len);
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002570 if (!temp) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07002571 sme_err("bss mem fail");
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002572 goto error;
2573 }
2574
2575 temp->AgingCount = scan_result->AgingCount;
2576 temp->preferValue = scan_result->preferValue;
2577 temp->capValue = scan_result->capValue;
2578 temp->ucEncryptionType = scan_result->ucEncryptionType;
2579 temp->mcEncryptionType = scan_result->mcEncryptionType;
2580 temp->authType = scan_result->authType;
2581 /* pvIes is unsued in success/failure */
2582 temp->Result.pvIes = NULL;
2583
2584 qdf_mem_copy(temp->Result.pvIes,
2585 scan_result->Result.pvIes,
2586 sizeof(*scan_result->Result.pvIes));
2587 temp->Result.ssId.length = scan_result->Result.ssId.length;
2588 qdf_mem_copy(temp->Result.ssId.ssId,
2589 scan_result->Result.ssId.ssId,
2590 sizeof(scan_result->Result.ssId.ssId));
2591 temp->Result.timer = scan_result->Result.timer;
2592 qdf_mem_copy(&temp->Result.BssDescriptor,
2593 &scan_result->Result.BssDescriptor,
2594 sizeof(temp->Result.BssDescriptor));
2595 temp->Link.last = temp->Link.next = NULL;
2596 session->scan_info.roambssentry = (tListElem *)temp;
2597
2598 return QDF_STATUS_SUCCESS;
2599error:
2600 csr_scan_handle_search_for_ssid_failure(mac_ctx,
2601 session_id);
Deepak Dhamdhere6f7fbbe2017-02-28 13:35:52 -08002602 csr_saved_scan_cmd_free_fields(mac_ctx, session);
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002603
2604 return QDF_STATUS_E_FAILURE;
2605}
2606
2607static void csr_handle_nxt_cmd(tpAniSirGlobal mac_ctx,
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05302608 enum csr_scancomplete_nextcommand nxt_cmd,
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002609 uint32_t session_id,
2610 uint8_t chan)
2611{
2612 QDF_STATUS status, ret;
2613
2614 switch (nxt_cmd) {
2615
2616 case eCsrNexteScanForSsidSuccess:
2617 csr_scan_handle_search_for_ssid(mac_ctx, session_id);
2618 break;
2619 case eCsrNexteScanForSsidFailure:
2620 csr_scan_handle_search_for_ssid_failure(mac_ctx, session_id);
2621 break;
2622 case eCsrNextCheckAllowConc:
Tushnim Bhattacharyya0c4ad2d2017-03-09 15:59:03 -08002623 ret = policy_mgr_current_connections_update(mac_ctx->psoc,
2624 session_id, chan,
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002625 SIR_UPDATE_REASON_HIDDEN_STA);
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07002626 sme_debug("chan: %d session: %d status: %d",
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002627 chan, session_id, ret);
2628
2629 status = csr_save_profile(mac_ctx, session_id);
2630 if (!QDF_IS_STATUS_SUCCESS(status)) {
2631 /* csr_save_profile should report error */
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07002632 sme_err("profile save failed %d", status);
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002633 return;
2634 }
2635
2636 if (QDF_STATUS_E_FAILURE == ret) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07002637 sme_err("conn update fail %d", chan);
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002638 csr_scan_handle_search_for_ssid_failure(mac_ctx,
2639 session_id);
2640 } else if ((QDF_STATUS_E_NOSUPPORT == ret) ||
2641 (QDF_STATUS_E_ALREADY == ret)) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07002642 sme_err("conn update ret %d", ret);
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002643 csr_scan_handle_search_for_ssid(mac_ctx, session_id);
2644 }
2645 /* Else: Set hw mode was issued and the saved connect would
2646 * be issued after set hw mode response
2647 */
2648 break;
2649 default:
2650 break;
2651 }
2652}
2653#else
Chandrasekaran, Manishekaref70c0d2015-10-20 19:54:55 +05302654/**
Deepak Dhamdhere6f7fbbe2017-02-28 13:35:52 -08002655 * csr_saved_scan_cmd_free_fields() - Free internal fields of scan command
2656 *
2657 * @mac_ctx: Global MAC context
2658 * @saved_scan_cmd: Pointer to scan command
2659 *
2660 * Frees data structures allocated inside saved_scan_cmd and releases
2661 * the profile.
2662 * Return: None
2663 */
2664
2665void csr_saved_scan_cmd_free_fields(tpAniSirGlobal mac_ctx,
2666 tSmeCmd *saved_scan_cmd)
2667{
2668 if (saved_scan_cmd->u.scanCmd.pToRoamProfile) {
2669 csr_release_profile(mac_ctx,
2670 saved_scan_cmd->u.scanCmd.pToRoamProfile);
2671 qdf_mem_free(saved_scan_cmd->u.scanCmd.pToRoamProfile);
2672 saved_scan_cmd->u.scanCmd.pToRoamProfile = NULL;
2673 }
2674 if (saved_scan_cmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList) {
2675 qdf_mem_free(saved_scan_cmd->u.scanCmd.u.
2676 scanRequest.SSIDs.SSIDList);
2677 saved_scan_cmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList = NULL;
2678 }
2679 if (saved_scan_cmd->u.roamCmd.pRoamBssEntry) {
2680 qdf_mem_free(saved_scan_cmd->u.roamCmd.pRoamBssEntry);
2681 saved_scan_cmd->u.roamCmd.pRoamBssEntry = NULL;
2682 }
2683}
2684
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002685static void
2686csr_handle_nxt_cmd(tpAniSirGlobal mac_ctx, tSmeCmd *pCommand,
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05302687 enum csr_scancomplete_nextcommand *nxt_cmd,
Chandrasekaran, Manishekaref70c0d2015-10-20 19:54:55 +05302688 bool *remove_cmd, uint32_t session_id,
2689 uint8_t chan)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002690{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302691 QDF_STATUS status, ret;
Chandrasekaran, Manishekaref70c0d2015-10-20 19:54:55 +05302692 tSmeCmd *save_cmd = NULL;
Naveen Rawat90542b32017-01-27 16:54:57 -08002693 tSmeCmd *saved_scan_cmd;
Chandrasekaran, Manishekaref70c0d2015-10-20 19:54:55 +05302694
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002695 switch (*nxt_cmd) {
2696 case eCsrNext11dScan1Success:
2697 case eCsrNext11dScan2Success:
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07002698 sme_debug(
2699 "11dScan1/3 produced results. Reissue Active scan");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002700 /*
2701 * if we found country information, no need to continue scanning
2702 * further, bail out
2703 */
2704 *remove_cmd = true;
2705 *nxt_cmd = eCsrNext11dScanComplete;
2706 break;
2707 case eCsrNext11dScan1Failure:
2708 /*
2709 * We are not done yet. 11d scan fail once. We will try to reset
2710 * anything and do it over again. The only meaningful thing for
2711 * this retry is that we cannot find 11d information after a
2712 * reset so we clear the "old" 11d info and give it once more
2713 * chance
2714 */
2715 *remove_cmd = csr_handle_scan11d1_failure(mac_ctx, pCommand);
2716 if (*remove_cmd)
2717 *nxt_cmd = eCsrNext11dScanComplete;
2718 break;
2719 case eCsrNextLostLinkScan1Success:
2720 status = csr_issue_roam_after_lostlink_scan(mac_ctx, session_id,
2721 eCsrLostLink1);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302722 if (!QDF_IS_STATUS_SUCCESS(status))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002723 csr_scan_handle_failed_lostlink1(mac_ctx, session_id);
2724 break;
2725 case eCsrNextLostLinkScan2Success:
2726 status = csr_issue_roam_after_lostlink_scan(mac_ctx, session_id,
2727 eCsrLostLink2);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302728 if (!QDF_IS_STATUS_SUCCESS(status))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002729 csr_scan_handle_failed_lostlink2(mac_ctx, session_id);
2730 break;
2731 case eCsrNextLostLinkScan3Success:
2732 status = csr_issue_roam_after_lostlink_scan(mac_ctx, session_id,
2733 eCsrLostLink3);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302734 if (!QDF_IS_STATUS_SUCCESS(status))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002735 csr_scan_handle_failed_lostlink3(mac_ctx, session_id);
2736 break;
2737 case eCsrNextLostLinkScan1Failed:
2738 csr_scan_handle_failed_lostlink1(mac_ctx, session_id);
2739 break;
2740 case eCsrNextLostLinkScan2Failed:
2741 csr_scan_handle_failed_lostlink2(mac_ctx, session_id);
2742 break;
2743 case eCsrNextLostLinkScan3Failed:
2744 csr_scan_handle_failed_lostlink3(mac_ctx, session_id);
2745 break;
2746 case eCsrNexteScanForSsidSuccess:
2747 csr_scan_handle_search_for_ssid(mac_ctx, pCommand);
2748 break;
2749 case eCsrNexteScanForSsidFailure:
2750 csr_scan_handle_search_for_ssid_failure(mac_ctx, pCommand);
2751 break;
Chandrasekaran, Manishekaref70c0d2015-10-20 19:54:55 +05302752 case eCsrNextCheckAllowConc:
Tushnim Bhattacharyya0c4ad2d2017-03-09 15:59:03 -08002753 ret = policy_mgr_current_connections_update(mac_ctx->psoc,
2754 pCommand->sessionId, chan,
Chandrasekaran, Manishekarce2172e2016-02-18 16:12:43 +05302755 SIR_UPDATE_REASON_HIDDEN_STA);
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07002756 sme_debug("chan: %d session: %d status: %d",
Chandrasekaran, Manishekaref70c0d2015-10-20 19:54:55 +05302757 chan, pCommand->sessionId, ret);
Naveen Rawat90542b32017-01-27 16:54:57 -08002758 saved_scan_cmd = (tSmeCmd *)mac_ctx->sme.saved_scan_cmd;
2759 if (saved_scan_cmd) {
Deepak Dhamdhere6f7fbbe2017-02-28 13:35:52 -08002760 csr_saved_scan_cmd_free_fields(mac_ctx,
2761 saved_scan_cmd);
Naveen Rawat90542b32017-01-27 16:54:57 -08002762 qdf_mem_free(saved_scan_cmd);
2763 saved_scan_cmd = NULL;
2764 sme_err(FL("memory should have been free. Check!"));
Chandrasekaran, Manishekaref70c0d2015-10-20 19:54:55 +05302765 }
2766
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302767 save_cmd = (tSmeCmd *) qdf_mem_malloc(sizeof(*pCommand));
Chandrasekaran, Manishekaref70c0d2015-10-20 19:54:55 +05302768 if (!save_cmd) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07002769 sme_err("save_cmd mem fail");
Chandrasekaran, Manishekaref70c0d2015-10-20 19:54:55 +05302770 goto error;
2771 }
2772
2773 status = csr_save_profile(mac_ctx, save_cmd, pCommand);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302774 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07002775 sme_err("profile save failed %d", status);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302776 qdf_mem_free(save_cmd);
Chandrasekaran, Manishekaref70c0d2015-10-20 19:54:55 +05302777 return;
2778 }
2779
2780 mac_ctx->sme.saved_scan_cmd = (void *)save_cmd;
2781
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302782 if (QDF_STATUS_E_FAILURE == ret) {
Chandrasekaran, Manishekaref70c0d2015-10-20 19:54:55 +05302783error:
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07002784 sme_err("conn update fail %d", chan);
Chandrasekaran, Manishekaref70c0d2015-10-20 19:54:55 +05302785 csr_scan_handle_search_for_ssid_failure(mac_ctx,
2786 pCommand);
2787 if (mac_ctx->sme.saved_scan_cmd) {
Deepak Dhamdhere6f7fbbe2017-02-28 13:35:52 -08002788 csr_saved_scan_cmd_free_fields(mac_ctx,
2789 mac_ctx->sme.saved_scan_cmd);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302790 qdf_mem_free(mac_ctx->sme.saved_scan_cmd);
Chandrasekaran, Manishekaref70c0d2015-10-20 19:54:55 +05302791 mac_ctx->sme.saved_scan_cmd = NULL;
2792 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302793 } else if ((QDF_STATUS_E_NOSUPPORT == ret) ||
2794 (QDF_STATUS_E_ALREADY == ret)) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07002795 sme_err("conn update ret %d", ret);
Chandrasekaran, Manishekaref70c0d2015-10-20 19:54:55 +05302796 csr_scan_handle_search_for_ssid(mac_ctx, pCommand);
2797 if (mac_ctx->sme.saved_scan_cmd) {
Deepak Dhamdhere6f7fbbe2017-02-28 13:35:52 -08002798 csr_saved_scan_cmd_free_fields(mac_ctx,
2799 mac_ctx->sme.saved_scan_cmd);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302800 qdf_mem_free(mac_ctx->sme.saved_scan_cmd);
Chandrasekaran, Manishekaref70c0d2015-10-20 19:54:55 +05302801 mac_ctx->sme.saved_scan_cmd = NULL;
2802 }
2803 }
Chandrasekaran, Manishekar78b98262015-11-06 15:22:46 +05302804 /* Else: Set hw mode was issued and the saved connect would
2805 * be issued after set hw mode response
2806 */
Chandrasekaran, Manishekaref70c0d2015-10-20 19:54:55 +05302807 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002808 default:
2809 break;
2810 }
2811}
2812
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002813#endif
Abhishek Singhe6857812017-03-10 18:20:06 +05302814
2815/* API will be removed after p2p component L0 */
2816QDF_STATUS csr_get_active_scan_entry(tpAniSirGlobal mac_ctx,
2817 uint32_t scan_id, tListElem **entry)
2818{
2819 QDF_STATUS status = QDF_STATUS_E_FAILURE;
2820 struct wlan_serialization_command *cmn_cmd;
2821 tSmeCmd *sme_cmd;
2822 uint32_t cmd_scan_id = 0;
2823
Abhishek Singhe6857812017-03-10 18:20:06 +05302824 csr_scan_active_ll_lock(mac_ctx);
2825
2826 if (csr_scan_active_ll_is_list_empty(mac_ctx, LL_ACCESS_NOLOCK)) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07002827 sme_err("Active list Empty scanId: %d", scan_id);
Abhishek Singhe6857812017-03-10 18:20:06 +05302828 csr_scan_active_ll_unlock(mac_ctx);
2829 return QDF_STATUS_SUCCESS;
2830 }
2831 cmn_cmd = wlan_serialization_peek_head_active_cmd_using_psoc(
2832 mac_ctx->psoc, true);
2833 while (cmn_cmd) {
2834 sme_cmd = cmn_cmd->umac_cmd;
2835 if (cmn_cmd->cmd_type == WLAN_SER_CMD_SCAN)
2836 cmd_scan_id = cmn_cmd->cmd_id;
2837 else if (cmn_cmd->cmd_type == WLAN_SER_CMD_REMAIN_ON_CHANNEL)
2838 cmd_scan_id = sme_cmd->u.remainChlCmd.scan_id;
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07002839 sme_debug("cmd_scan_id %d", cmd_scan_id);
Abhishek Singhe6857812017-03-10 18:20:06 +05302840 if ((cmn_cmd->cmd_type == WLAN_SER_CMD_REMAIN_ON_CHANNEL) &&
2841 (cmd_scan_id == scan_id)) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07002842 sme_debug("scanId Matched %d", scan_id);
Abhishek Singhe6857812017-03-10 18:20:06 +05302843 *entry = &sme_cmd->Link;
2844 csr_scan_active_ll_unlock(mac_ctx);
2845 return QDF_STATUS_SUCCESS;
2846 }
2847 cmn_cmd =
2848 wlan_serialization_get_active_list_next_node_using_psoc(
2849 mac_ctx->psoc, cmn_cmd, true);
2850 }
2851 csr_scan_active_ll_unlock(mac_ctx);
Abhishek Singhe6857812017-03-10 18:20:06 +05302852
2853 return status;
2854}
Abhishek Singhe6857812017-03-10 18:20:06 +05302855
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002856void csr_scan_callback(struct wlan_objmgr_vdev *vdev,
2857 struct scan_event *event, void *arg)
2858{
2859 eCsrScanStatus scan_status = eCSR_SCAN_FAILURE;
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05302860 enum csr_scancomplete_nextcommand NextCommand = eCsrNextScanNothing;
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002861 tpAniSirGlobal mac_ctx;
gaurank kathpalia14e2f912017-08-31 14:51:45 +05302862 struct csr_roam_session *session;
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002863 uint32_t session_id = 0;
2864 uint8_t chan = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002865
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002866 mac_ctx = (tpAniSirGlobal)arg;
2867 if ((event->type == SCAN_EVENT_TYPE_COMPLETED) &&
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05302868 ((event->reason == SCAN_REASON_CANCELLED) ||
2869 (event->reason == SCAN_REASON_TIMEDOUT) ||
2870 (event->reason == SCAN_REASON_INTERNAL_FAILURE)))
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002871 scan_status = eCSR_SCAN_FAILURE;
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05302872 else if ((event->type == SCAN_EVENT_TYPE_COMPLETED) &&
2873 (event->reason == SCAN_REASON_COMPLETED))
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002874 scan_status = eCSR_SCAN_SUCCESS;
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05302875 else
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002876 return;
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05302877
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002878 session_id = wlan_vdev_get_id(vdev);
Krunal Soni35a94532018-01-09 10:54:31 -08002879 if (!CSR_IS_SESSION_VALID(mac_ctx, session_id)) {
2880 sme_err("session %d is invalid", session_id);
2881 return;
2882 }
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002883 session = CSR_GET_SESSION(mac_ctx, session_id);
2884
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07002885 sme_debug("Scan Completion: status %d session %d scan_id %d",
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002886 scan_status, session_id, event->scan_id);
2887
2888 /* verify whether scan event is related to scan interested by CSR */
2889 if (session->scan_info.scan_id != event->scan_id) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07002890 sme_debug("Scan Completion on wrong scan_id %d, expected %d",
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002891 session->scan_info.scan_id, event->scan_id);
2892 return;
2893 }
2894#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
2895 csr_diag_scan_complete(mac_ctx, scan_status);
2896#endif
2897 NextCommand = csr_scan_get_next_command_state(mac_ctx,
2898 session_id, scan_status,
2899 &chan);
2900 /* We reuse the command here instead reissue a new command */
2901 csr_handle_nxt_cmd(mac_ctx, NextCommand,
2902 session_id, chan);
Sandeep Puligillab0e017c2017-06-09 18:09:55 -07002903
2904 if (session->scan_info.profile != NULL) {
2905 sme_debug("Free the profile scan_id %d", event->scan_id);
2906 csr_release_profile(mac_ctx, session->scan_info.profile);
2907 qdf_mem_free(session->scan_info.profile);
2908 session->scan_info.profile = NULL;
2909 }
2910
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08002911}
2912bool csr_scan_complete(tpAniSirGlobal pMac, tSirSmeScanRsp *pScanRsp)
2913{
2914 return true;
2915}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002916
2917/* Return whether last scan result is received */
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05302918static bool csr_scan_process_scan_results(tpAniSirGlobal pMac, tSmeCmd
2919 *pCommand, tSirSmeScanRsp *pScanRsp,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002920 bool *pfRemoveCommand)
2921{
2922 bool fRet = false, fRemoveCommand = false;
Amar Singhal83a047a2016-05-19 15:56:11 -07002923 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002924
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07002925 sme_debug("scan reason = %d, response status code = %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002926 pCommand->u.scanCmd.reason, pScanRsp->statusCode);
2927 fRemoveCommand = csr_scan_complete(pMac, pScanRsp);
2928 fRet = true;
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05302929 if (pfRemoveCommand)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002930 *pfRemoveCommand = fRemoveCommand;
Amar Singhal83a047a2016-05-19 15:56:11 -07002931
2932 /*
2933 * Currently SET_FCC_CHANNEL issues updated channel list to fw.
2934 * At the time of driver load, if scan is issued followed with
2935 * SET_FCC_CHANNEL, driver will send update channel list to fw.
2936 * Fw will stop ongoing scan because of that GUI will have very less
2937 * scan list.
2938 * Update channel list should be sent to fw once scan is done
2939 */
2940 if (pMac->scan.defer_update_channel_list) {
2941 status = csr_update_channel_list(pMac);
2942 if (!QDF_IS_STATUS_SUCCESS(status))
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07002943 sme_err("failed to update the supported channel list");
Amar Singhal83a047a2016-05-19 15:56:11 -07002944 pMac->scan.defer_update_channel_list = false;
2945 }
2946
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002947 return fRet;
2948}
2949
Jeff Johnson00fa67d2016-10-14 08:07:36 -07002950static bool csr_scan_is_wild_card_scan(tpAniSirGlobal pMac, tSmeCmd *pCommand)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002951{
Anurag Chouhan6d760662016-02-20 16:05:43 +05302952 uint8_t bssid[QDF_MAC_ADDR_SIZE] = {0};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002953 /*
2954 * It is not a wild card scan if the bssid is not broadcast and
2955 * the number of SSID is 1.
2956 */
Ankit Guptaa5076012016-09-14 11:32:19 -07002957 return ((!qdf_mem_cmp(pCommand->u.scanCmd.u.scanRequest.bssid.bytes,
2958 bssid, sizeof(struct qdf_mac_addr)))
2959 || (0xff == pCommand->u.scanCmd.u.scanRequest.bssid.bytes[0]))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002960 && (pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs != 1);
2961}
2962
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302963QDF_STATUS csr_scan_sme_scan_response(tpAniSirGlobal pMac,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002964 void *pMsgBuf)
2965{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302966 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002967 tListElem *pEntry = NULL;
2968 tSmeCmd *pCommand;
2969 eCsrScanStatus scanStatus;
2970 tSirSmeScanRsp *pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
2971 bool fRemoveCommand = true;
gaurank kathpalia14e2f912017-08-31 14:51:45 +05302972 enum csr_scan_reason reason = eCsrScanOther;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002973
2974 csr_get_active_scan_entry(pMac, pScanRsp->scan_id, &pEntry);
2975 if (!pEntry)
2976 goto error_handling;
2977
Jeff Johnsonc83eca92017-09-18 08:13:39 -07002978 sme_debug("Scan completion called:scan_id %d, entry = %pK",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002979 pScanRsp->scan_id, pEntry);
2980
2981 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
2982 if (eSmeCommandScan != pCommand->command)
2983 goto error_handling;
2984
2985 scanStatus = (eSIR_SME_SUCCESS == pScanRsp->statusCode) ?
2986 eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
2987 reason = pCommand->u.scanCmd.reason;
2988 switch (pCommand->u.scanCmd.reason) {
2989 case eCsrScanAbortNormalScan:
2990 break;
2991 case eCsrScanP2PFindPeer:
2992 scanStatus = (eSIR_SME_SUCCESS == pScanRsp->statusCode) ?
2993 eCSR_SCAN_FOUND_PEER : eCSR_SCAN_FAILURE;
2994 csr_scan_process_scan_results(pMac, pCommand, pScanRsp, NULL);
2995 break;
2996 default:
2997 if (csr_scan_process_scan_results(pMac, pCommand, pScanRsp,
2998 &fRemoveCommand)
2999 && csr_scan_is_wild_card_scan(pMac, pCommand)
3000 && !pCommand->u.scanCmd.u.scanRequest.p2pSearch) {
3001
3002 /* Age out logic will be taken care by the age out timer */
3003 }
3004 break;
3005 }
Krunal Soni81f068c2017-02-23 19:51:55 -08003006 if (fRemoveCommand) {
3007 pCommand->u.scanCmd.status = scanStatus;
3008 csr_release_command(pMac, pCommand);
3009 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003010 return status;
3011
3012error_handling:
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07003013 sme_err("Scan completion called, but no active SCAN command");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303014 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003015}
3016
3017tCsrScanResultInfo *csr_scan_result_get_first(tpAniSirGlobal pMac,
3018 tScanResultHandle hScanResult)
3019{
3020 tListElem *pEntry;
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05303021 struct tag_csrscan_result *pResult;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003022 tCsrScanResultInfo *pRet = NULL;
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05303023 struct scan_result_list *pResultList =
3024 (struct scan_result_list *) hScanResult;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003025
3026 if (pResultList) {
3027 csr_ll_lock(&pResultList->List);
3028 pEntry = csr_ll_peek_head(&pResultList->List, LL_ACCESS_NOLOCK);
3029 if (pEntry) {
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05303030 pResult = GET_BASE_ADDR(pEntry, struct
3031 tag_csrscan_result, Link);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003032 pRet = &pResult->Result;
3033 }
3034 pResultList->pCurEntry = pEntry;
3035 csr_ll_unlock(&pResultList->List);
3036 }
3037
3038 return pRet;
3039}
3040
3041tCsrScanResultInfo *csr_scan_result_get_next(tpAniSirGlobal pMac,
3042 tScanResultHandle hScanResult)
3043{
3044 tListElem *pEntry = NULL;
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05303045 struct tag_csrscan_result *pResult = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003046 tCsrScanResultInfo *pRet = NULL;
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05303047 struct scan_result_list *pResultList =
3048 (struct scan_result_list *) hScanResult;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003049
3050 if (!pResultList)
3051 return NULL;
3052
3053 csr_ll_lock(&pResultList->List);
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05303054 if (NULL == pResultList->pCurEntry)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003055 pEntry = csr_ll_peek_head(&pResultList->List, LL_ACCESS_NOLOCK);
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05303056 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003057 pEntry = csr_ll_next(&pResultList->List, pResultList->pCurEntry,
3058 LL_ACCESS_NOLOCK);
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05303059
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003060 if (pEntry) {
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05303061 pResult = GET_BASE_ADDR(pEntry, struct tag_csrscan_result,
3062 Link);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003063 pRet = &pResult->Result;
3064 }
3065 pResultList->pCurEntry = pEntry;
3066 csr_ll_unlock(&pResultList->List);
3067 return pRet;
3068}
3069
3070/*
3071 * This function moves the first BSS that matches the bssid to the
3072 * head of the result
3073 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303074QDF_STATUS csr_move_bss_to_head_from_bssid(tpAniSirGlobal pMac,
Anurag Chouhan6d760662016-02-20 16:05:43 +05303075 struct qdf_mac_addr *bssid,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003076 tScanResultHandle hScanResult)
3077{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303078 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05303079 struct scan_result_list *pResultList =
3080 (struct scan_result_list *) hScanResult;
3081 struct tag_csrscan_result *pResult = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003082 tListElem *pEntry = NULL;
3083
3084 if (!(pResultList && bssid))
3085 return status;
3086
3087 csr_ll_lock(&pResultList->List);
3088 pEntry = csr_ll_peek_head(&pResultList->List, LL_ACCESS_NOLOCK);
3089 while (pEntry) {
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05303090 pResult = GET_BASE_ADDR(pEntry, struct tag_csrscan_result,
3091 Link);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303092 if (!qdf_mem_cmp(bssid, pResult->Result.BssDescriptor.bssId,
Anurag Chouhan6d760662016-02-20 16:05:43 +05303093 sizeof(struct qdf_mac_addr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303094 status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003095 csr_ll_remove_entry(&pResultList->List, pEntry,
3096 LL_ACCESS_NOLOCK);
3097 csr_ll_insert_head(&pResultList->List, pEntry,
3098 LL_ACCESS_NOLOCK);
3099 break;
3100 }
3101 pEntry = csr_ll_next(&pResultList->List, pResultList->pCurEntry,
3102 LL_ACCESS_NOLOCK);
3103 }
3104 csr_ll_unlock(&pResultList->List);
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05303105
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003106 return status;
3107}
3108
Jeff Johnson00fa67d2016-10-14 08:07:36 -07003109static QDF_STATUS csr_send_mb_scan_req(tpAniSirGlobal pMac, uint16_t sessionId,
3110 tCsrScanRequest *pScanReq,
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05303111 struct tag_scanreq_param *pScanReqParam)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003112{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303113 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003114 tSirSmeScanReq *pMsg;
3115 uint16_t msgLen;
3116 tSirScanType scanType = pScanReq->scanType;
3117 uint32_t minChnTime; /* in units of milliseconds */
3118 uint32_t maxChnTime; /* in units of milliseconds */
3119 uint32_t i;
Anurag Chouhan6d760662016-02-20 16:05:43 +05303120 struct qdf_mac_addr selfmac;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003121
3122 msgLen = (uint16_t) (sizeof(tSirSmeScanReq) -
3123 sizeof(pMsg->channelList.channelNumber) +
3124 (sizeof(pMsg->channelList.channelNumber) *
3125 pScanReq->ChannelInfo.numOfChannels)) +
3126 (pScanReq->uIEFieldLen);
3127
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303128 pMsg = qdf_mem_malloc(msgLen);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003129 if (NULL == pMsg) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07003130 sme_err("memory allocation failed");
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05303131 sme_debug("Failed: SId: %d FirstMatch: %d UniqueResult: %d freshScan: %d hiddenSsid: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003132 sessionId, pScanReqParam->bReturnAfter1stMatch,
3133 pScanReqParam->fUniqueResult, pScanReqParam->freshScan,
3134 pScanReqParam->hiddenSsid);
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05303135 sme_debug("scanType: %s (%u) BSSType: %s (%u) numOfSSIDs: %d numOfChannels: %d requestType: %s (%d) p2pSearch: %d",
Rajeev Kumar43e25b12016-04-15 16:26:36 -07003136 sme_scan_type_to_string(pScanReq->scanType),
Sreelakshmi Konamki39acb132015-12-16 13:06:22 +05303137 pScanReq->scanType,
Rajeev Kumar43e25b12016-04-15 16:26:36 -07003138 sme_bss_type_to_string(pScanReq->BSSType),
Sreelakshmi Konamki39acb132015-12-16 13:06:22 +05303139 pScanReq->BSSType,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003140 pScanReq->SSIDs.numOfSSIDs,
3141 pScanReq->ChannelInfo.numOfChannels,
Sreelakshmi Konamki39acb132015-12-16 13:06:22 +05303142 sme_request_type_to_string(pScanReq->requestType),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003143 pScanReq->requestType, pScanReq->p2pSearch);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303144 return QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003145 }
3146
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003147 pMsg->messageType = eWNI_SME_SCAN_REQ;
3148 pMsg->length = msgLen;
3149 /* ToDO: Fill in session info when we need to do scan base on session */
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05303150 if (sessionId != CSR_SESSION_ID_INVALID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003151 pMsg->sessionId = sessionId;
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05303152 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003153 /* if sessionId == CSR_SESSION_ID_INVALID, then send the scan
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05303154 * request on first available session
3155 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003156 pMsg->sessionId = 0;
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05303157
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003158 if (pMsg->sessionId >= CSR_ROAM_SESSION_MAX)
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07003159 sme_err("Invalid Sme Session ID: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003160 pMsg->sessionId);
3161 pMsg->transactionId = 0;
3162 pMsg->dot11mode = (uint8_t) csr_translate_to_wni_cfg_dot11_mode(pMac,
3163 csr_find_best_phy_mode(pMac,
3164 pMac->roam.configParam.phyMode));
3165 pMsg->bssType = csr_translate_bsstype_to_mac_type(pScanReq->BSSType);
3166
3167 if (CSR_IS_SESSION_VALID(pMac, sessionId)) {
Anurag Chouhanc5548422016-02-24 18:33:27 +05303168 qdf_copy_macaddr(&selfmac,
Srinivas Girigowda2c6bf002015-09-24 11:43:31 -07003169 &pMac->roam.roamSession[sessionId].selfMacAddr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003170 } else {
3171 /*
3172 * Since we don't have session for the scanning, we find a valid
3173 * session. In case we fail to do so, get the WNI_CFG_STA_ID
3174 */
3175 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
3176 if (CSR_IS_SESSION_VALID(pMac, i)) {
Anurag Chouhanc5548422016-02-24 18:33:27 +05303177 qdf_copy_macaddr(&selfmac,
Srinivas Girigowda2c6bf002015-09-24 11:43:31 -07003178 &pMac->roam.roamSession[i].selfMacAddr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003179 break;
3180 }
3181 }
3182 if (CSR_ROAM_SESSION_MAX == i) {
Anurag Chouhan6d760662016-02-20 16:05:43 +05303183 uint32_t len = QDF_MAC_ADDR_SIZE;
Varun Reddy Yeturu7b2a6572017-06-15 11:07:28 -07003184 tSirRetStatus sir_status;
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05303185
Varun Reddy Yeturu7b2a6572017-06-15 11:07:28 -07003186 sir_status = wlan_cfg_get_str(pMac, WNI_CFG_STA_ID,
Srinivas Girigowda2c6bf002015-09-24 11:43:31 -07003187 selfmac.bytes, &len);
Varun Reddy Yeturu7b2a6572017-06-15 11:07:28 -07003188 if ((sir_status != eSIR_SUCCESS)
Anurag Chouhan6d760662016-02-20 16:05:43 +05303189 || (len < QDF_MAC_ADDR_SIZE)) {
Varun Reddy Yeturu7b2a6572017-06-15 11:07:28 -07003190 sme_err("Can't get self MAC: status:%d len:%d",
3191 sir_status, len);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303192 status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003193 goto send_scan_req;
3194 }
3195 }
3196 }
Anurag Chouhanc5548422016-02-24 18:33:27 +05303197 qdf_copy_macaddr(&pMsg->selfMacAddr, &selfmac);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003198
Anurag Chouhanc5548422016-02-24 18:33:27 +05303199 qdf_copy_macaddr(&pMsg->bssId, &pScanReq->bssid);
3200 if (qdf_is_macaddr_zero(&pScanReq->bssid))
3201 qdf_set_macaddr_broadcast(&pMsg->bssId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003202 else
Anurag Chouhanc5548422016-02-24 18:33:27 +05303203 qdf_copy_macaddr(&pMsg->bssId, &pScanReq->bssid);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003204 minChnTime = pScanReq->minChnTime;
3205 maxChnTime = pScanReq->maxChnTime;
3206
3207 /*
3208 * Verify the scan type first, if the scan is active scan, we need to
3209 * make sure we are allowed to do so. if 11d is enabled & we don't see
3210 * any beacon around, scan type falls back to passive. But in BT AMP STA
3211 * mode we need to send out a directed probe
3212 */
3213 if ((eSIR_PASSIVE_SCAN != scanType)
Sandeep Puligillaee029ad2015-10-26 18:58:00 -07003214 && (eCSR_SCAN_P2P_DISCOVERY != pScanReq->requestType)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003215 && (false == pMac->scan.fEnableBypass11d)) {
3216 scanType = pMac->scan.curScanType;
3217 if (eSIR_PASSIVE_SCAN == pMac->scan.curScanType) {
3218 if (minChnTime <
3219 pMac->roam.configParam.nPassiveMinChnTime) {
3220 minChnTime =
3221 pMac->roam.configParam.nPassiveMinChnTime;
3222 }
3223 if (maxChnTime <
3224 pMac->roam.configParam.nPassiveMaxChnTime) {
3225 maxChnTime =
3226 pMac->roam.configParam.nPassiveMaxChnTime;
3227 }
3228 }
3229 }
3230 pMsg->scanType = scanType;
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05303231 pMsg->scan_adaptive_dwell_mode = pScanReq->scan_adaptive_dwell_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003232
3233 pMsg->numSsid = (pScanReq->SSIDs.numOfSSIDs < SIR_SCAN_MAX_NUM_SSID) ?
3234 pScanReq->SSIDs.numOfSSIDs : SIR_SCAN_MAX_NUM_SSID;
3235 if ((pScanReq->SSIDs.numOfSSIDs != 0)
3236 && (eSIR_PASSIVE_SCAN != scanType)) {
3237 for (i = 0; i < pMsg->numSsid; i++) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303238 qdf_mem_copy(&pMsg->ssId[i],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003239 &pScanReq->SSIDs.SSIDList[i].SSID,
3240 sizeof(tSirMacSSid));
3241 }
3242 } else {
3243 /* Otherwise we scan all SSID and let the result filter later */
3244 for (i = 0; i < SIR_SCAN_MAX_NUM_SSID; i++)
3245 pMsg->ssId[i].length = 0;
3246 }
3247
3248 pMsg->minChannelTime = minChnTime;
3249 pMsg->maxChannelTime = maxChnTime;
3250 /* hidden SSID option */
3251 pMsg->hiddenSsid = pScanReqParam->hiddenSsid;
Agrawal Ashish17bb3902016-05-05 13:29:40 +05303252 /* maximum rest time */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003253 pMsg->restTime = pScanReq->restTime;
Agrawal Ashish17bb3902016-05-05 13:29:40 +05303254 /* Minimum rest time */
3255 pMsg->min_rest_time = pScanReq->min_rest_time;
3256 /* Idle time */
3257 pMsg->idle_time = pScanReq->idle_time;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003258 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
3259 /* All the scan results caching will be done by Roaming */
3260 /* We do not want LIM to do any caching of scan results, */
3261 /* so delete the LIM cache on all scan requests */
3262 pMsg->returnFreshResults = pScanReqParam->freshScan;
3263 /* Always ask for unique result */
3264 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
3265 pMsg->channelList.numChannels =
3266 (uint8_t) pScanReq->ChannelInfo.numOfChannels;
3267 if (pScanReq->ChannelInfo.numOfChannels) {
3268 /* Assuming the channelNumber is uint8_t (1 byte) */
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303269 qdf_mem_copy(pMsg->channelList.channelNumber,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003270 pScanReq->ChannelInfo.ChannelList,
3271 pScanReq->ChannelInfo.numOfChannels);
3272 }
3273
3274 pMsg->uIEFieldLen = (uint16_t) pScanReq->uIEFieldLen;
3275 pMsg->uIEFieldOffset = (uint16_t) (sizeof(tSirSmeScanReq) -
3276 sizeof(pMsg->channelList.channelNumber) +
3277 (sizeof(pMsg->channelList.channelNumber) *
3278 pScanReq->ChannelInfo.numOfChannels));
3279 if (pScanReq->uIEFieldLen != 0) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303280 qdf_mem_copy((uint8_t *) pMsg + pMsg->uIEFieldOffset,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003281 pScanReq->pIEField, pScanReq->uIEFieldLen);
3282 }
3283 pMsg->p2pSearch = pScanReq->p2pSearch;
3284 pMsg->scan_id = pScanReq->scan_id;
3285
3286send_scan_req:
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07003287 sme_debug(
3288 "scanId %d domainIdCurrent %d scanType %s (%d) bssType %s (%d) requestType %s (%d) numChannels %d",
Sreelakshmi Konamki39acb132015-12-16 13:06:22 +05303289 pMsg->scan_id, pMac->scan.domainIdCurrent,
Rajeev Kumar43e25b12016-04-15 16:26:36 -07003290 sme_scan_type_to_string(pMsg->scanType), pMsg->scanType,
3291 sme_bss_type_to_string(pMsg->bssType), pMsg->bssType,
Sreelakshmi Konamki39acb132015-12-16 13:06:22 +05303292 sme_request_type_to_string(pScanReq->requestType),
3293 pScanReq->requestType, pMsg->channelList.numChannels);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003294
3295 for (i = 0; i < pMsg->channelList.numChannels; i++) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07003296 sme_debug("channelNumber[%d]= %d", i,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003297 pMsg->channelList.channelNumber[i]);
3298 }
3299
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303300 if (QDF_IS_STATUS_SUCCESS(status)) {
Rajeev Kumard138ac52017-01-30 18:38:37 -08003301 status = umac_send_mb_message_to_mac(pMsg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003302 } else {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07003303 sme_err(
3304 "failed to send down scan req with status: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003305 status);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303306 qdf_mem_free(pMsg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003307 }
3308 return status;
3309}
3310
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003311#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3312static void csr_diag_scan_channels(tpAniSirGlobal pMac, tSmeCmd *pCommand)
3313{
3314 host_log_scan_pkt_type *pScanLog = NULL;
3315
3316 WLAN_HOST_DIAG_LOG_ALLOC(pScanLog,
3317 host_log_scan_pkt_type,
3318 LOG_WLAN_SCAN_C);
3319 if (!pScanLog)
3320 return;
3321
3322 if (eCsrScanProbeBss == pCommand->u.scanCmd.reason) {
3323 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
3324 } else {
3325 if ((eSIR_PASSIVE_SCAN !=
3326 pCommand->u.scanCmd.u.scanRequest.scanType)
3327 && (eSIR_PASSIVE_SCAN != pMac->scan.curScanType)) {
3328 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_REQ;
3329 } else {
3330 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_REQ;
3331 }
3332 }
3333 pScanLog->minChnTime =
3334 (uint8_t) pCommand->u.scanCmd.u.scanRequest.minChnTime;
3335 pScanLog->maxChnTime =
3336 (uint8_t) pCommand->u.scanCmd.u.scanRequest.maxChnTime;
3337 pScanLog->numChannel =
3338 (uint8_t) pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
3339 if (pScanLog->numChannel &&
3340 (pScanLog->numChannel < HOST_LOG_MAX_NUM_CHANNEL)) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303341 qdf_mem_copy(pScanLog->channels,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003342 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
3343 pScanLog->numChannel);
3344 }
3345 WLAN_HOST_DIAG_LOG_REPORT(pScanLog);
3346}
3347#else
3348#define csr_diag_scan_channels(tpAniSirGlobal pMac, tSmeCmd *pCommand) (void)0;
3349#endif /* #ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR */
3350
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05303351static QDF_STATUS csr_scan_channels(tpAniSirGlobal pMac, tSmeCmd *pCommand)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003352{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303353 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05303354 struct tag_scanreq_param scanReq;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003355
3356 /*
3357 * Don't delete cached results. Rome rssi based scan candidates may land
3358 * up in scan cache instead of LFR cache. They will be deleted upon
3359 * query
3360 */
3361 scanReq.freshScan = SIR_BG_SCAN_RETURN_FRESH_RESULTS;
3362 scanReq.fUniqueResult = true;
3363 scanReq.hiddenSsid = SIR_SCAN_NO_HIDDEN_SSID;
3364 if (eCsrScanForSsid == pCommand->u.scanCmd.reason) {
3365 scanReq.bReturnAfter1stMatch =
3366 CSR_SCAN_RETURN_AFTER_FIRST_MATCH;
3367 } else {
3368 /*
3369 * Basically do scan on all channels even for 11D 1st scan case
3370 */
3371 scanReq.bReturnAfter1stMatch =
3372 CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
3373 }
3374 if (eCsrScanProbeBss == pCommand->u.scanCmd.reason)
3375 scanReq.hiddenSsid = SIR_SCAN_HIDDEN_SSID_PE_DECISION;
3376 csr_diag_scan_channels(pMac, pCommand);
3377 csr_clear_votes_for_country_info(pMac);
3378 status = csr_send_mb_scan_req(pMac, pCommand->sessionId,
3379 &pCommand->u.scanCmd.u.scanRequest,
3380 &scanReq);
3381 return status;
3382}
3383
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303384static QDF_STATUS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003385csr_issue_user_scan(tpAniSirGlobal mac_ctx, tSmeCmd *cmd)
3386{
3387 int i, j;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303388 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003389 uint32_t len = 0;
3390 uint8_t *ch_lst = NULL;
3391 tCsrChannelInfo new_ch_info = { 0, NULL };
3392
3393 if (!mac_ctx->roam.configParam.fScanTwice)
3394 return csr_scan_channels(mac_ctx, cmd);
3395
3396 /* We scan 2.4 channel twice */
3397 if (cmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels
3398 && (NULL != cmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)) {
3399 len = cmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
3400 /* allocate twice the channel */
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303401 new_ch_info.ChannelList = (uint8_t *) qdf_mem_malloc(len * 2);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003402 ch_lst = cmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
3403 } else {
3404 /* get the valid channel list to scan all. */
3405 len = sizeof(mac_ctx->roam.validChannelList);
3406 status = csr_get_cfg_valid_channels(mac_ctx,
3407 (uint8_t *) mac_ctx->roam.validChannelList, &len);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303408 if (QDF_IS_STATUS_SUCCESS(status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003409 /* allocate twice the channel */
3410 new_ch_info.ChannelList =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303411 (uint8_t *) qdf_mem_malloc(len * 2);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003412 ch_lst = mac_ctx->roam.validChannelList;
3413 }
3414 }
3415 if (NULL == new_ch_info.ChannelList) {
3416 new_ch_info.numOfChannels = 0;
3417 } else {
3418 j = 0;
3419 for (i = 0; i < len; i++) {
3420 new_ch_info.ChannelList[j++] = ch_lst[i];
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07003421 if (WLAN_REG_MAX_24GHZ_CH_NUM >= ch_lst[i])
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003422 new_ch_info.ChannelList[j++] = ch_lst[i];
3423 }
3424 if (NULL !=
3425 cmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList) {
3426 /*
3427 * ch_lst points to the channellist from the command,
3428 * free it.
3429 */
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303430 qdf_mem_free(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003431 cmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
3432 cmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList =
3433 NULL;
3434 }
3435 cmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = j;
3436 cmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList =
3437 new_ch_info.ChannelList;
3438 }
3439
3440 return csr_scan_channels(mac_ctx, cmd);
3441}
3442
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303443QDF_STATUS csr_process_scan_command(tpAniSirGlobal pMac, tSmeCmd *pCommand)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003444{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303445 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003446
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07003447 sme_debug("starting SCAN cmd in %d state. reason %d",
3448 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId],
3449 pCommand->u.scanCmd.reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003450
3451 switch (pCommand->u.scanCmd.reason) {
3452 case eCsrScanUserRequest:
3453 status = csr_issue_user_scan(pMac, pCommand);
3454 break;
3455 default:
3456 status = csr_scan_channels(pMac, pCommand);
3457 break;
3458 }
3459
Krunal Soni81f068c2017-02-23 19:51:55 -08003460 if (!QDF_IS_STATUS_SUCCESS(status))
3461 pCommand->u.scanCmd.status = eCSR_SCAN_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003462
3463 return status;
3464}
3465
3466/**
3467 * csr_scan_copy_request_valid_channels_only() - scan request of valid channels
3468 * @mac_ctx : pointer to Global Mac Structure
3469 * @dst_req: pointer to tCsrScanRequest
3470 * @skip_dfs_chnl: 1 - skip dfs channel, 0 - don't skip dfs channel
3471 * @src_req: pointer to tCsrScanRequest
3472 *
3473 * This function makes a copy of scan request with valid channels
3474 *
3475 * Return: none
3476 */
3477static void csr_scan_copy_request_valid_channels_only(tpAniSirGlobal mac_ctx,
3478 tCsrScanRequest *dst_req, uint8_t skip_dfs_chnl,
3479 tCsrScanRequest *src_req)
3480{
3481 uint32_t index = 0;
3482 uint32_t new_index = 0;
Agrawal Ashish21ba2572016-09-03 16:40:10 +05303483 uint16_t unsafe_chan[NUM_CHANNELS];
3484 uint16_t unsafe_chan_cnt = 0;
3485 uint16_t cnt = 0;
3486 bool is_unsafe_chan;
3487 qdf_device_t qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
3488
3489 if (!qdf_ctx) {
3490 cds_err("qdf_ctx is NULL");
3491 return;
3492 }
3493 pld_get_wlan_unsafe_channel(qdf_ctx->dev, unsafe_chan,
3494 &unsafe_chan_cnt,
3495 sizeof(unsafe_chan));
3496
3497 if (mac_ctx->roam.configParam.sta_roam_policy.dfs_mode ==
3498 CSR_STA_ROAM_POLICY_DFS_DISABLED)
3499 skip_dfs_chnl = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003500
3501 for (index = 0; index < src_req->ChannelInfo.numOfChannels; index++) {
3502 /* Allow scan on valid channels only.
3503 * If it is p2p scan and valid channel list doesnt contain
3504 * social channels, enforce scan on social channels because
3505 * that is the only way to find p2p peers.
3506 * This can happen only if band is set to 5Ghz mode.
3507 */
Amar Singhal7a1726a2015-10-14 16:28:11 -07003508 if (src_req->ChannelInfo.ChannelList[index] <
Amar Singhal5cccafe2017-02-15 12:42:58 -08003509 WLAN_REG_MIN_11P_CH_NUM &&
3510 ((csr_roam_is_valid_channel(mac_ctx,
3511 src_req->ChannelInfo.ChannelList[index])) ||
3512 ((eCSR_SCAN_P2P_DISCOVERY == src_req->requestType) &&
3513 CSR_IS_SOCIAL_CHANNEL(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003514 src_req->ChannelInfo.ChannelList[index])))) {
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07003515 if (((src_req->skipDfsChnlInP2pSearch ||
3516 skip_dfs_chnl) && (CHANNEL_STATE_DFS ==
3517 wlan_reg_get_channel_state(mac_ctx->pdev,
Nishank Aggarwald18b6f42017-04-28 11:58:04 +05303518 src_req->ChannelInfo.ChannelList[index]))) &&
3519 (src_req->ChannelInfo.numOfChannels > 1)) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07003520 sme_debug(
3521 "reqType= %s (%d), numOfChannels=%d, ignoring DFS channel %d",
Sreelakshmi Konamki39acb132015-12-16 13:06:22 +05303522 sme_request_type_to_string(
3523 src_req->requestType),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003524 src_req->requestType,
3525 src_req->ChannelInfo.numOfChannels,
3526 src_req->ChannelInfo.ChannelList
3527 [index]);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003528 continue;
3529 }
Agrawal Ashish21ba2572016-09-03 16:40:10 +05303530 if (mac_ctx->roam.configParam.
3531 sta_roam_policy.skip_unsafe_channels &&
3532 unsafe_chan_cnt) {
3533 is_unsafe_chan = false;
3534 for (cnt = 0; cnt < unsafe_chan_cnt; cnt++) {
3535 if (unsafe_chan[cnt] ==
3536 src_req->ChannelInfo.
3537 ChannelList[index]) {
3538 is_unsafe_chan = true;
3539 break;
3540 }
3541 }
Agrawal, Ashish9f84c402016-11-30 16:19:44 +05303542 if (is_unsafe_chan &&
3543 ((CSR_IS_CHANNEL_24GHZ(
3544 src_req->ChannelInfo.
3545 ChannelList[index]) &&
3546 mac_ctx->roam.configParam.
3547 sta_roam_policy.sap_operating_band ==
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08003548 BAND_2G) ||
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07003549 (WLAN_REG_IS_5GHZ_CH(
Agrawal, Ashish9f84c402016-11-30 16:19:44 +05303550 src_req->ChannelInfo.
3551 ChannelList[index]) &&
3552 mac_ctx->roam.configParam.
3553 sta_roam_policy.sap_operating_band ==
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08003554 BAND_5G))) {
Agrawal Ashish21ba2572016-09-03 16:40:10 +05303555 QDF_TRACE(QDF_MODULE_ID_SME,
Abhishek Singh438cd7e2017-08-11 12:21:06 +05303556 QDF_TRACE_LEVEL_DEBUG,
Agrawal Ashish21ba2572016-09-03 16:40:10 +05303557 FL("ignoring unsafe channel %d"),
3558 src_req->ChannelInfo.
3559 ChannelList[index]);
3560 continue;
3561 }
3562 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003563
3564 dst_req->ChannelInfo.ChannelList[new_index] =
3565 src_req->ChannelInfo.ChannelList[index];
3566 new_index++;
3567 }
3568 }
3569 dst_req->ChannelInfo.numOfChannels = new_index;
3570}
3571
3572/**
Krunal Soni4274f362016-12-14 19:55:25 -08003573 * csr_scan_filter_given_chnl_band() - filter all channels which matches given
Krunal Soni80aabd42015-12-21 12:17:16 -08003574 * channel's band
3575 * @mac_ctx: pointer to mac context
Krunal Soni4274f362016-12-14 19:55:25 -08003576 * @channel: Given channel
Krunal Soni80aabd42015-12-21 12:17:16 -08003577 * @dst_req: destination scan request
3578 *
Krunal Soni4274f362016-12-14 19:55:25 -08003579 * when ever particular connection already exist, STA should not scan the
3580 * channels which fall under same band as given channel's band.
3581 * this routine will filter out those channels
Krunal Soni80aabd42015-12-21 12:17:16 -08003582 *
3583 * Return: true if success otherwise false for any failure
3584 */
Krunal Soni4274f362016-12-14 19:55:25 -08003585static bool csr_scan_filter_given_chnl_band(tpAniSirGlobal mac_ctx,
3586 uint8_t channel, tCsrScanRequest *dst_req) {
Krunal Soni80aabd42015-12-21 12:17:16 -08003587 uint8_t valid_chnl_list[WNI_CFG_VALID_CHANNEL_LIST_LEN] = {0};
Krunal Soni80aabd42015-12-21 12:17:16 -08003588 uint32_t filter_chnl_len = 0, i = 0;
3589 uint32_t valid_chnl_len = WNI_CFG_VALID_CHANNEL_LIST_LEN;
3590
Krunal Soni4274f362016-12-14 19:55:25 -08003591 if (!channel) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07003592 sme_debug("Nothing to filter as no IBSS session");
Krunal Soni80aabd42015-12-21 12:17:16 -08003593 return true;
3594 }
3595
3596 if (!dst_req) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07003597 sme_err("No valid scan requests");
Krunal Soni80aabd42015-12-21 12:17:16 -08003598 return false;
3599 }
3600 /*
3601 * In case of concurrent IBSS session exist, scan only
3602 * those channels which are not in IBSS channel's band.
3603 * In case if no-concurrent IBSS session exist then scan
3604 * full band
3605 */
Srinivas Girigowdaf326dfe2017-08-03 11:28:32 -07003606 if (dst_req->ChannelInfo.numOfChannels == 0) {
Krunal Soni80aabd42015-12-21 12:17:16 -08003607 csr_get_cfg_valid_channels(mac_ctx, valid_chnl_list,
3608 &valid_chnl_len);
3609 } else {
3610 valid_chnl_len = (WNI_CFG_VALID_CHANNEL_LIST_LEN >
3611 dst_req->ChannelInfo.numOfChannels) ?
3612 dst_req->ChannelInfo.numOfChannels :
3613 WNI_CFG_VALID_CHANNEL_LIST_LEN;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303614 qdf_mem_copy(valid_chnl_list, dst_req->ChannelInfo.ChannelList,
Krunal Soni80aabd42015-12-21 12:17:16 -08003615 valid_chnl_len);
3616 }
3617 for (i = 0; i < valid_chnl_len; i++) {
Amar Singhal5cccafe2017-02-15 12:42:58 -08003618 if (valid_chnl_list[i] >= WLAN_REG_MIN_11P_CH_NUM)
Krunal Soni80aabd42015-12-21 12:17:16 -08003619 continue;
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07003620 if (WLAN_REG_IS_5GHZ_CH(channel) &&
3621 WLAN_REG_IS_24GHZ_CH(valid_chnl_list[i])) {
Krunal Soni03a882b2016-01-13 15:59:52 -08003622 valid_chnl_list[filter_chnl_len] =
Krunal Soni80aabd42015-12-21 12:17:16 -08003623 valid_chnl_list[i];
3624 filter_chnl_len++;
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07003625 } else if (WLAN_REG_IS_24GHZ_CH(channel) &&
3626 WLAN_REG_IS_5GHZ_CH(valid_chnl_list[i])) {
Krunal Soni03a882b2016-01-13 15:59:52 -08003627 valid_chnl_list[filter_chnl_len] =
Krunal Soni80aabd42015-12-21 12:17:16 -08003628 valid_chnl_list[i];
3629 filter_chnl_len++;
3630 }
3631 }
3632 if (filter_chnl_len == 0) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07003633 sme_err("there no channels to scan due to IBSS session");
Krunal Soni80aabd42015-12-21 12:17:16 -08003634 return false;
3635 }
3636
3637 if (dst_req->ChannelInfo.ChannelList) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303638 qdf_mem_free(dst_req->ChannelInfo.ChannelList);
Krunal Soni80aabd42015-12-21 12:17:16 -08003639 dst_req->ChannelInfo.ChannelList = NULL;
3640 dst_req->ChannelInfo.numOfChannels = 0;
3641 }
3642
3643 dst_req->ChannelInfo.ChannelList =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303644 qdf_mem_malloc(filter_chnl_len *
Krunal Soni80aabd42015-12-21 12:17:16 -08003645 sizeof(*dst_req->ChannelInfo.ChannelList));
3646 dst_req->ChannelInfo.numOfChannels = filter_chnl_len;
3647 if (NULL == dst_req->ChannelInfo.ChannelList) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07003648 sme_err("Memory allocation failed");
Krunal Soni80aabd42015-12-21 12:17:16 -08003649 return false;
3650 }
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303651 qdf_mem_copy(dst_req->ChannelInfo.ChannelList, valid_chnl_list,
Krunal Soni80aabd42015-12-21 12:17:16 -08003652 filter_chnl_len);
3653 return true;
3654}
3655
3656/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003657 * csr_scan_copy_request() - Function to copy scan request
3658 * @mac_ctx : pointer to Global Mac Structure
3659 * @dst_req: pointer to tCsrScanRequest
3660 * @src_req: pointer to tCsrScanRequest
3661 *
3662 * This function makes a copy of scan request
3663 *
3664 * Return: 0 - Success, Error number - Failure
3665 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303666QDF_STATUS csr_scan_copy_request(tpAniSirGlobal mac_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003667 tCsrScanRequest *dst_req,
3668 tCsrScanRequest *src_req)
3669{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303670 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003671 uint32_t len = sizeof(mac_ctx->roam.validChannelList);
3672 uint32_t index = 0;
3673 uint32_t new_index = 0;
Amar Singhala297bfa2015-10-15 15:07:29 -07003674 enum channel_state channel_state;
Krunal Soni4274f362016-12-14 19:55:25 -08003675 uint8_t channel = 0;
Amar Singhala297bfa2015-10-15 15:07:29 -07003676
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003677 bool skip_dfs_chnl =
3678 mac_ctx->roam.configParam.initial_scan_no_dfs_chnl ||
3679 !mac_ctx->scan.fEnableDFSChnlScan;
3680
3681 status = csr_scan_free_request(mac_ctx, dst_req);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303682 if (!QDF_IS_STATUS_SUCCESS(status))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003683 goto complete;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303684 qdf_mem_copy(dst_req, src_req, sizeof(tCsrScanRequest));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003685 /* Re-initialize the pointers to NULL since we did a copy */
3686 dst_req->pIEField = NULL;
3687 dst_req->ChannelInfo.ChannelList = NULL;
3688 dst_req->SSIDs.SSIDList = NULL;
3689
3690 if (src_req->uIEFieldLen) {
3691 dst_req->pIEField =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303692 qdf_mem_malloc(src_req->uIEFieldLen);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003693 if (NULL == dst_req->pIEField) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303694 status = QDF_STATUS_E_NOMEM;
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07003695 sme_err("No memory for scanning IE fields");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003696 goto complete;
3697 } else {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303698 status = QDF_STATUS_SUCCESS;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303699 qdf_mem_copy(dst_req->pIEField, src_req->pIEField,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003700 src_req->uIEFieldLen);
3701 dst_req->uIEFieldLen = src_req->uIEFieldLen;
3702 }
3703 }
3704
3705 /* Allocate memory for IE field */
3706 if (src_req->ChannelInfo.numOfChannels == 0) {
3707 dst_req->ChannelInfo.ChannelList = NULL;
3708 dst_req->ChannelInfo.numOfChannels = 0;
3709 } else {
3710 dst_req->ChannelInfo.ChannelList =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303711 qdf_mem_malloc(src_req->ChannelInfo.numOfChannels *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003712 sizeof(*dst_req->ChannelInfo.ChannelList));
3713 if (NULL == dst_req->ChannelInfo.ChannelList) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303714 status = QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003715 dst_req->ChannelInfo.numOfChannels = 0;
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07003716 sme_err("No memory for scanning Channel List");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003717 goto complete;
3718 }
3719
3720 if ((src_req->scanType == eSIR_PASSIVE_SCAN) &&
3721 (src_req->requestType == eCSR_SCAN_REQUEST_11D_SCAN)) {
3722 for (index = 0; index < src_req->ChannelInfo.
3723 numOfChannels; index++) {
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07003724 channel_state = wlan_reg_get_channel_state(
3725 mac_ctx->pdev,
3726 src_req->ChannelInfo.
3727 ChannelList[index]);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003728 if (src_req->ChannelInfo.ChannelList[index] <
Amar Singhal5cccafe2017-02-15 12:42:58 -08003729 WLAN_REG_MIN_11P_CH_NUM &&
3730 ((CHANNEL_STATE_ENABLE ==
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07003731 channel_state) ||
3732 ((CHANNEL_STATE_DFS == channel_state) &&
3733 !skip_dfs_chnl))) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003734 dst_req->ChannelInfo.ChannelList
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07003735 [new_index] =
3736 src_req->
3737 ChannelInfo.
3738 ChannelList
3739 [index];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003740 new_index++;
3741 }
3742 }
3743 dst_req->ChannelInfo.numOfChannels = new_index;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303744 } else if (QDF_IS_STATUS_SUCCESS(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003745 csr_get_cfg_valid_channels(mac_ctx,
3746 mac_ctx->roam.validChannelList,
3747 &len))) {
3748 new_index = 0;
3749 mac_ctx->roam.numValidChannels = len;
3750 csr_scan_copy_request_valid_channels_only(mac_ctx,
3751 dst_req, skip_dfs_chnl,
3752 src_req);
3753 } else {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07003754 sme_err(
3755 "Couldn't get the valid Channel List, keeping requester's list");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003756 new_index = 0;
3757 for (index = 0; index < src_req->ChannelInfo.
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07003758 numOfChannels; index++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003759 if (src_req->ChannelInfo.ChannelList[index] <
Amar Singhal5cccafe2017-02-15 12:42:58 -08003760 WLAN_REG_MIN_11P_CH_NUM) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003761 dst_req->ChannelInfo.
3762 ChannelList[new_index] =
3763 src_req->ChannelInfo.
3764 ChannelList[index];
3765 new_index++;
3766 }
3767 }
3768 dst_req->ChannelInfo.numOfChannels =
3769 new_index;
3770 }
3771 } /* Allocate memory for Channel List */
Krunal Soni80aabd42015-12-21 12:17:16 -08003772
3773 /*
3774 * If IBSS concurrent connection exist, and if the scan
3775 * request comes from STA adapter then we need to filter
3776 * out IBSS channel's band otherwise it will cause issue
3777 * in IBSS+STA concurrency
Krunal Soni4274f362016-12-14 19:55:25 -08003778 *
3779 * If DFS SAP/GO concurrent connection exist, and if the scan
3780 * request comes from STA adapter then we need to filter
3781 * out SAP/GO channel's band otherwise it will cause issue in
3782 * SAP+STA concurrency
Krunal Soni80aabd42015-12-21 12:17:16 -08003783 */
Tushnim Bhattacharyya0c4ad2d2017-03-09 15:59:03 -08003784 if (policy_mgr_is_ibss_conn_exist(mac_ctx->psoc, &channel)) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07003785 sme_debug("Conc IBSS exist, channel list will be modified");
Tushnim Bhattacharyya0c4ad2d2017-03-09 15:59:03 -08003786 } else if (policy_mgr_is_any_dfs_beaconing_session_present(
3787 mac_ctx->psoc, &channel)) {
Krunal Soni4274f362016-12-14 19:55:25 -08003788 /*
3789 * 1) if agile & DFS scans are supported
3790 * 2) if hardware is DBS capable
3791 * 3) if current hw mode is non-dbs
3792 * if all above 3 conditions are true then don't skip any
3793 * channel from scan list
3794 */
Tushnim Bhattacharyya0c4ad2d2017-03-09 15:59:03 -08003795 if (true != policy_mgr_is_current_hwmode_dbs(mac_ctx->psoc) &&
3796 policy_mgr_get_dbs_plus_agile_scan_config(mac_ctx->psoc) &&
3797 policy_mgr_get_single_mac_scan_with_dfs_config(
3798 mac_ctx->psoc))
Krunal Soni4274f362016-12-14 19:55:25 -08003799 channel = 0;
3800 else
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07003801 sme_debug(
3802 "Conc DFS SAP/GO exist, channel list will be modified");
Krunal Soni80aabd42015-12-21 12:17:16 -08003803 }
3804
Krunal Soni4274f362016-12-14 19:55:25 -08003805 if ((channel > 0) &&
3806 (!csr_scan_filter_given_chnl_band(mac_ctx, channel, dst_req))) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07003807 sme_err("Can't filter channels due to IBSS/SAP DFS");
Krunal Soni80aabd42015-12-21 12:17:16 -08003808 goto complete;
3809 }
3810
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003811 if (src_req->SSIDs.numOfSSIDs == 0) {
3812 dst_req->SSIDs.numOfSSIDs = 0;
3813 dst_req->SSIDs.SSIDList = NULL;
3814 } else {
3815 dst_req->SSIDs.SSIDList =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303816 qdf_mem_malloc(src_req->SSIDs.numOfSSIDs *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003817 sizeof(*dst_req->SSIDs.SSIDList));
3818 if (NULL == dst_req->SSIDs.SSIDList)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303819 status = QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003820 else
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303821 status = QDF_STATUS_SUCCESS;
3822 if (QDF_IS_STATUS_SUCCESS(status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003823 dst_req->SSIDs.numOfSSIDs =
3824 src_req->SSIDs.numOfSSIDs;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303825 qdf_mem_copy(dst_req->SSIDs.SSIDList,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003826 src_req->SSIDs.SSIDList,
3827 src_req->SSIDs.numOfSSIDs *
3828 sizeof(*dst_req->SSIDs.SSIDList));
3829 } else {
3830 dst_req->SSIDs.numOfSSIDs = 0;
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07003831 sme_err("No memory for scanning SSID List");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003832 goto complete;
3833 }
3834 } /* Allocate memory for SSID List */
Sreelakshmi Konamki8b8257c2016-12-12 15:44:54 +05303835 qdf_mem_copy(&dst_req->bssid, &src_req->bssid,
3836 sizeof(struct qdf_mac_addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003837 dst_req->p2pSearch = src_req->p2pSearch;
3838 dst_req->skipDfsChnlInP2pSearch =
3839 src_req->skipDfsChnlInP2pSearch;
3840 dst_req->scan_id = src_req->scan_id;
3841 dst_req->timestamp = src_req->timestamp;
3842
3843complete:
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05303844 if (!QDF_IS_STATUS_SUCCESS(status))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003845 csr_scan_free_request(mac_ctx, dst_req);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003846
3847 return status;
3848}
3849
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303850QDF_STATUS csr_scan_free_request(tpAniSirGlobal pMac, tCsrScanRequest *pReq)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003851{
3852
3853 if (pReq->ChannelInfo.ChannelList) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303854 qdf_mem_free(pReq->ChannelInfo.ChannelList);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003855 pReq->ChannelInfo.ChannelList = NULL;
3856 }
3857 pReq->ChannelInfo.numOfChannels = 0;
3858 if (pReq->pIEField) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303859 qdf_mem_free(pReq->pIEField);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003860 pReq->pIEField = NULL;
3861 }
3862 pReq->uIEFieldLen = 0;
3863 if (pReq->SSIDs.SSIDList) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303864 qdf_mem_free(pReq->SSIDs.SSIDList);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003865 pReq->SSIDs.SSIDList = NULL;
3866 }
3867 pReq->SSIDs.numOfSSIDs = 0;
3868
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303869 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003870}
3871
3872void csr_scan_call_callback(tpAniSirGlobal pMac, tSmeCmd *pCommand,
3873 eCsrScanStatus scanStatus)
3874{
3875 if (pCommand->u.scanCmd.callback) {
Ratnam Rachurib7595a32016-11-04 16:58:53 +05303876 if (pCommand->u.scanCmd.abort_scan_indication) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07003877 sme_debug("scanDone due to abort");
Ratnam Rachurib7595a32016-11-04 16:58:53 +05303878 scanStatus = eCSR_SCAN_ABORT;
3879 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003880 pCommand->u.scanCmd.callback(pMac, pCommand->u.scanCmd.pContext,
3881 pCommand->sessionId,
3882 pCommand->u.scanCmd.scanID,
3883 scanStatus);
3884 } else {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07003885 sme_debug("Callback NULL!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003886 }
3887}
3888
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003889bool csr_scan_remove_fresh_scan_command(tpAniSirGlobal pMac, uint8_t sessionId)
3890{
3891 bool fRet = false;
3892 tListElem *pEntry, *pEntryTmp;
3893 tSmeCmd *pCommand;
3894 tDblLinkList localList;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003895
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303896 qdf_mem_zero(&localList, sizeof(tDblLinkList));
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303897 if (!QDF_IS_STATUS_SUCCESS(csr_ll_open(pMac->hHdd, &localList))) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07003898 sme_err("failed to open list");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003899 return fRet;
3900 }
3901
Krunal Soni81f068c2017-02-23 19:51:55 -08003902 csr_scan_pending_ll_lock(pMac);
3903 pEntry = csr_scan_pending_ll_peek_head(pMac, LL_ACCESS_NOLOCK);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003904 while (pEntry) {
Krunal Soni81f068c2017-02-23 19:51:55 -08003905 pEntryTmp = csr_scan_pending_ll_next(pMac, pEntry,
3906 LL_ACCESS_NOLOCK);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003907 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
3908 if (!((eSmeCommandScan == pCommand->command)
3909 && (sessionId == pCommand->sessionId))) {
3910 pEntry = pEntryTmp;
3911 continue;
3912 }
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07003913 sme_debug("-------- abort scan command reason = %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003914 pCommand->u.scanCmd.reason);
3915 /* The rest are fresh scan requests */
Krunal Soni81f068c2017-02-23 19:51:55 -08003916 if (csr_scan_pending_ll_remove_entry(pMac, pEntry,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003917 LL_ACCESS_NOLOCK)) {
3918 csr_ll_insert_tail(&localList, pEntry,
3919 LL_ACCESS_NOLOCK);
3920 }
3921 fRet = true;
3922 pEntry = pEntryTmp;
3923 }
3924
Krunal Soni81f068c2017-02-23 19:51:55 -08003925 csr_scan_pending_ll_unlock(pMac);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003926
3927 while ((pEntry = csr_ll_remove_head(&localList, LL_ACCESS_NOLOCK))) {
3928 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
3929 if (pCommand->u.scanCmd.callback) {
3930 /*
3931 * User scan request is pending, send response with
3932 * status eCSR_SCAN_ABORT
3933 */
3934 pCommand->u.scanCmd.callback(pMac,
3935 pCommand->u.scanCmd.pContext, sessionId,
3936 pCommand->u.scanCmd.scanID, eCSR_SCAN_ABORT);
3937 }
Krunal Sonidea45952017-02-15 11:58:15 -08003938 csr_release_command(pMac, pCommand);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003939 }
3940 csr_ll_close(&localList);
3941
3942 return fRet;
3943}
3944
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303945QDF_STATUS csr_scan_get_pmkid_candidate_list(tpAniSirGlobal pMac,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003946 uint32_t sessionId,
3947 tPmkidCandidateInfo *pPmkidList,
3948 uint32_t *pNumItems)
3949{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303950 QDF_STATUS status = QDF_STATUS_SUCCESS;
gaurank kathpalia14e2f912017-08-31 14:51:45 +05303951 struct csr_roam_session *pSession = CSR_GET_SESSION(pMac, sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003952 tCsrScanResultFilter *pScanFilter;
3953 tCsrScanResultInfo *pScanResult;
3954 tScanResultHandle hBSSList;
3955 uint32_t nItems = *pNumItems;
3956
3957 if (!pSession) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07003958 sme_err("session %d not found", sessionId);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303959 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003960 }
3961
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07003962 sme_debug("pMac->scan.NumPmkidCandidate = %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003963 pSession->NumPmkidCandidate);
3964 csr_reset_pmkid_candidate_list(pMac, sessionId);
3965 if (!(csr_is_conn_state_connected(pMac, sessionId)
3966 && pSession->pCurRoamProfile))
3967 return status;
3968
3969 *pNumItems = 0;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303970 pScanFilter = qdf_mem_malloc(sizeof(tCsrScanResultFilter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003971 if (NULL == pScanFilter)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303972 return QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003973
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003974 /* Here is the profile we need to connect to */
3975 status = csr_roam_prepare_filter_from_profile(pMac,
3976 pSession->pCurRoamProfile, pScanFilter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303977 if (!QDF_IS_STATUS_SUCCESS(status)) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303978 qdf_mem_free(pScanFilter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003979 return status;
3980 }
3981
3982 status = csr_scan_get_result(pMac, pScanFilter, &hBSSList);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303983 if (!QDF_IS_STATUS_SUCCESS(status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003984 csr_free_scan_filter(pMac, pScanFilter);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303985 qdf_mem_free(pScanFilter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003986 return status;
3987 }
3988
3989 if (pSession->NumPmkidCandidate < nItems) {
3990 pScanResult = csr_scan_result_get_next(pMac, hBSSList);
3991 while (pScanResult != NULL) {
3992 /* NumPmkidCandidate adds up here */
3993 csr_process_bss_desc_for_pmkid_list(pMac,
3994 &pScanResult->BssDescriptor,
3995 (tDot11fBeaconIEs *)(pScanResult->pvIes),
3996 sessionId);
3997 pScanResult = csr_scan_result_get_next(pMac, hBSSList);
3998 }
3999 }
4000
4001 if (pSession->NumPmkidCandidate) {
4002 *pNumItems = pSession->NumPmkidCandidate;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304003 qdf_mem_copy(pPmkidList, pSession->PmkidCandidateInfo,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004004 pSession->NumPmkidCandidate *
4005 sizeof(tPmkidCandidateInfo));
4006 }
4007
4008 csr_scan_result_purge(pMac, hBSSList);
4009 csr_free_scan_filter(pMac, pScanFilter);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304010 qdf_mem_free(pScanFilter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004011 return status;
4012}
4013
4014#ifdef FEATURE_WLAN_WAPI
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304015QDF_STATUS csr_scan_get_bkid_candidate_list(tpAniSirGlobal pMac,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004016 uint32_t sessionId,
4017 tBkidCandidateInfo *pBkidList,
4018 uint32_t *pNumItems)
4019{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304020 QDF_STATUS status = QDF_STATUS_SUCCESS;
gaurank kathpalia14e2f912017-08-31 14:51:45 +05304021 struct csr_roam_session *pSession = CSR_GET_SESSION(pMac, sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004022 tCsrScanResultFilter *pScanFilter;
4023 tCsrScanResultInfo *pScanResult;
4024 tScanResultHandle hBSSList;
4025 uint32_t nItems = *pNumItems;
4026
4027 if (!pSession) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07004028 sme_err("session %d not found", sessionId);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304029 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004030 }
4031
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07004032 sme_debug("pMac->scan.NumBkidCandidate = %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004033 pSession->NumBkidCandidate);
4034 csr_reset_bkid_candidate_list(pMac, sessionId);
4035 if (!(csr_is_conn_state_connected(pMac, sessionId)
4036 && pSession->pCurRoamProfile))
4037 return status;
4038
4039 *pNumItems = 0;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304040 pScanFilter = qdf_mem_malloc(sizeof(tCsrScanResultFilter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004041 if (NULL == pScanFilter)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304042 return QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004043
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004044 /* Here is the profile we need to connect to */
4045 status = csr_roam_prepare_filter_from_profile(pMac,
4046 pSession->pCurRoamProfile, pScanFilter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304047 if (!QDF_IS_STATUS_SUCCESS(status)) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304048 qdf_mem_free(pScanFilter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004049 return status;
4050 }
4051
4052 status = csr_scan_get_result(pMac, pScanFilter, &hBSSList);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304053 if (!QDF_IS_STATUS_SUCCESS(status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004054 csr_free_scan_filter(pMac, pScanFilter);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304055 qdf_mem_free(pScanFilter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004056 return status;
4057 }
4058
4059 if (pSession->NumBkidCandidate < nItems) {
4060 pScanResult = csr_scan_result_get_next(pMac, hBSSList);
4061 while (pScanResult != NULL) {
4062 /* pMac->scan.NumBkidCandidate adds up here */
4063 csr_process_bss_desc_for_bkid_list(pMac,
4064 &pScanResult->BssDescriptor,
4065 (tDot11fBeaconIEs *)(pScanResult->pvIes));
4066 pScanResult = csr_scan_result_get_next(pMac, hBSSList);
4067 }
4068 }
4069
4070 if (pSession->NumBkidCandidate) {
4071 *pNumItems = pSession->NumBkidCandidate;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304072 qdf_mem_copy(pBkidList, pSession->BkidCandidateInfo,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004073 pSession->NumBkidCandidate *
4074 sizeof(tBkidCandidateInfo));
4075 }
4076
4077 csr_scan_result_purge(pMac, hBSSList);
4078 csr_free_scan_filter(pMac, pScanFilter);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304079 qdf_mem_free(pScanFilter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004080 return status;
4081}
4082#endif /* FEATURE_WLAN_WAPI */
4083
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004084/**
4085 * csr_scan_for_ssid() - Function usually used for BSSs that suppresses SSID
4086 * @mac_ctx: Pointer to Global Mac structure
4087 * @profile: pointer to tCsrRoamProfile
4088 * @roam_id: variable representing roam id
4089 * @notify: boolean variable
4090 *
4091 * Function is usually used for BSSs that suppresses SSID so the profile
4092 * shall have one and only one SSID.
4093 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304094 * Return: Success - QDF_STATUS_SUCCESS, Failure - error number
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004095 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304096QDF_STATUS csr_scan_for_ssid(tpAniSirGlobal mac_ctx, uint32_t session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004097 tCsrRoamProfile *profile, uint32_t roam_id,
4098 bool notify)
4099{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304100 QDF_STATUS status = QDF_STATUS_E_INVAL;
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08004101 uint32_t num_ssid = profile->SSIDs.numOfSSIDs;
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08004102 struct scan_start_request *req;
4103 struct wlan_objmgr_vdev *vdev;
Himanshu Agarwal12445c12017-11-07 14:56:09 +05304104 uint8_t i, chan, num_chan = 0;
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08004105 wlan_scan_id scan_id;
gaurank kathpalia14e2f912017-08-31 14:51:45 +05304106 struct csr_roam_session *session = CSR_GET_SESSION(mac_ctx, session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004107
Krunal Soni35a94532018-01-09 10:54:31 -08004108 if (!CSR_IS_SESSION_VALID(mac_ctx, session_id)) {
4109 sme_err("session %d is invalid", session_id);
4110 return status;
4111 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004112 if (!(mac_ctx->scan.fScanEnable) && (num_ssid != 1)) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07004113 sme_err(
4114 "cannot scan because scanEnable (%d) or numSSID (%d) is invalid",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004115 mac_ctx->scan.fScanEnable, profile->SSIDs.numOfSSIDs);
4116 return status;
4117 }
4118
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08004119 session->scan_info.profile =
4120 qdf_mem_malloc(sizeof(tCsrRoamProfile));
4121 if (!session->scan_info.profile)
4122 status = QDF_STATUS_E_NOMEM;
4123 else
4124 status = csr_roam_copy_profile(mac_ctx,
4125 session->scan_info.profile,
4126 profile);
4127 if (!QDF_IS_STATUS_SUCCESS(status))
4128 goto error;
4129 scan_id = ucfg_scan_get_scan_id(mac_ctx->psoc);
4130 session->scan_info.scan_id = scan_id;
4131 session->scan_info.scan_reason = eCsrScanForSsid;
4132 session->scan_info.roam_id = roam_id;
4133 req = qdf_mem_malloc(sizeof(*req));
4134 if (!req) {
4135 QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_ERROR,
4136 FL("Failed to allocate memory"));
4137 goto error;
4138 }
4139 vdev = wlan_objmgr_get_vdev_by_macaddr_from_psoc(mac_ctx->psoc,
4140 session->selfMacAddr.bytes,
4141 WLAN_LEGACY_SME_ID);
4142 ucfg_scan_init_default_params(vdev, req);
4143 req->scan_req.dwell_time_active = 0;
4144 req->scan_req.scan_id = scan_id;
4145 req->scan_req.vdev_id = session_id;
4146 req->scan_req.scan_req_id = mac_ctx->scan.requester_id;
Deepak Dhamdhereca7315c2017-10-20 13:05:56 -07004147 req->scan_req.scan_f_passive = false;
4148 req->scan_req.scan_f_bcast_probe = false;
4149
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08004150
4151 if (QDF_P2P_CLIENT_MODE == profile->csrPersona)
4152 req->scan_req.scan_priority = SCAN_PRIORITY_HIGH;
4153
4154 /* Allocate memory for IE field */
4155 if (profile->pAddIEScan) {
4156 req->scan_req.extraie.ptr =
4157 qdf_mem_malloc(profile->nAddIEScanLength);
4158
4159 if (NULL == req->scan_req.extraie.ptr)
4160 status = QDF_STATUS_E_NOMEM;
4161 else
4162 status = QDF_STATUS_SUCCESS;
4163
4164 if (QDF_IS_STATUS_SUCCESS(status)) {
4165 qdf_mem_copy(req->scan_req.extraie.ptr,
4166 profile->pAddIEScan,
4167 profile->nAddIEScanLength);
4168 req->scan_req.extraie.len = profile->nAddIEScanLength;
4169 } else {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07004170 sme_err("No memory for scanning IE fields");
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08004171 }
4172 }
4173
4174 req->scan_req.num_bssid = 1;
4175 if (profile->BSSIDs.numOfBSSIDs == 1)
4176 qdf_copy_macaddr(&req->scan_req.bssid_list[0],
4177 profile->BSSIDs.bssid);
4178 else
4179 qdf_set_macaddr_broadcast(&req->scan_req.bssid_list[0]);
4180
4181 if (profile->ChannelInfo.numOfChannels) {
4182 for (i = 0; i < profile->ChannelInfo.numOfChannels; i++) {
4183 if (csr_roam_is_valid_channel(mac_ctx,
4184 profile->ChannelInfo.ChannelList[i])) {
4185 chan = profile->ChannelInfo.ChannelList[i];
Abhishek Singha394b6c2017-11-03 17:14:58 +05304186 req->scan_req.chan_list.chan[num_chan].freq =
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08004187 wlan_chan_to_freq(chan);
4188 num_chan++;
4189 }
4190 }
Abhishek Singha394b6c2017-11-03 17:14:58 +05304191 req->scan_req.chan_list.num_chan = num_chan;
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08004192 }
4193
4194 /* Extend it for multiple SSID */
4195 if (profile->SSIDs.numOfSSIDs) {
Sandeep Puligillac0f77442017-11-07 01:20:32 -08004196 if (profile->SSIDs.SSIDList[0].SSID.length > MAX_SSID_LEN) {
4197 sme_debug("wrong ssid length = %d",
4198 profile->SSIDs.SSIDList[0].SSID.length);
4199 status = QDF_STATUS_E_INVAL;
4200 goto error;
4201 }
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08004202 req->scan_req.num_ssids = 1;
4203 qdf_mem_copy(&req->scan_req.ssid[0].ssid,
4204 &profile->SSIDs.SSIDList[0].SSID.ssId,
4205 profile->SSIDs.SSIDList[0].SSID.length);
4206 req->scan_req.ssid[0].length =
4207 profile->SSIDs.SSIDList[0].SSID.length;
Himanshu Agarwal12445c12017-11-07 14:56:09 +05304208 sme_debug("scan for SSID = %.*s", req->scan_req.ssid[0].length,
4209 req->scan_req.ssid[0].ssid);
Sandeep Puligillaa330c8c2017-03-09 18:03:21 -08004210 }
4211 status = ucfg_scan_start(req);
4212 wlan_objmgr_vdev_release_ref(vdev, WLAN_LEGACY_SME_ID);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004213error:
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304214 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07004215 sme_err("failed to initiate scan with status: %d", status);
Sandeep Puligillab0e017c2017-06-09 18:09:55 -07004216 csr_release_profile(mac_ctx, session->scan_info.profile);
4217 qdf_mem_free(session->scan_info.profile);
4218 session->scan_info.profile = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004219 if (notify)
4220 csr_roam_call_callback(mac_ctx, session_id, NULL,
4221 roam_id, eCSR_ROAM_FAILED,
4222 eCSR_ROAM_RESULT_FAILURE);
4223 }
4224 return status;
4225}
4226
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05304227static void csr_set_cfg_valid_channel_list(tpAniSirGlobal pMac,
4228 uint8_t *pChannelList, uint8_t NumChannels)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004229{
4230 uint32_t dataLen = sizeof(uint8_t) * NumChannels;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304231 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004232
Abhishek Singh438cd7e2017-08-11 12:21:06 +05304233 QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004234 "%s: dump valid channel list(NumChannels(%d))",
4235 __func__, NumChannels);
Abhishek Singh438cd7e2017-08-11 12:21:06 +05304236 QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004237 pChannelList, NumChannels);
4238 cfg_set_str(pMac, WNI_CFG_VALID_CHANNEL_LIST, pChannelList,
4239 dataLen);
4240
Abhishek Singh438cd7e2017-08-11 12:21:06 +05304241 QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004242 "Scan offload is enabled, update default chan list");
4243 /*
4244 * disable fcc constraint since new country code
4245 * is being set
4246 */
4247 pMac->scan.fcc_constraint = false;
4248 status = csr_update_channel_list(pMac);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304249 if (QDF_STATUS_SUCCESS != status) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304250 QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004251 "failed to update the supported channel list");
4252 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004253}
4254
4255/*
4256 * The Tx power limits are saved in the cfg for future usage.
4257 */
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05304258static void csr_save_tx_power_to_cfg(tpAniSirGlobal pMac, tDblLinkList *pList,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004259 uint32_t cfgId)
4260{
4261 tListElem *pEntry;
4262 uint32_t cbLen = 0, dataLen, tmp_len;
gaurank kathpalia14e2f912017-08-31 14:51:45 +05304263 struct csr_channel_powerinfo *ch_set;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004264 uint32_t idx;
4265 tSirMacChanInfo *ch_pwr_set;
4266 uint8_t *pBuf = NULL;
4267
4268 /* allocate maximum space for all channels */
4269 dataLen = WNI_CFG_VALID_CHANNEL_LIST_LEN * sizeof(tSirMacChanInfo);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304270 pBuf = qdf_mem_malloc(dataLen);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004271 if (pBuf == NULL)
4272 return;
4273
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004274 ch_pwr_set = (tSirMacChanInfo *) (pBuf);
4275 pEntry = csr_ll_peek_head(pList, LL_ACCESS_LOCK);
4276 /*
4277 * write the tuples (startChan, numChan, txPower) for each channel found
4278 * in the channel power list.
4279 */
4280 while (pEntry) {
gaurank kathpalia14e2f912017-08-31 14:51:45 +05304281 ch_set = GET_BASE_ADDR(pEntry,
4282 struct csr_channel_powerinfo, link);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004283 if (1 != ch_set->interChannelOffset) {
4284 /*
4285 * we keep the 5G channel sets internally with an
4286 * interchannel offset of 4. Expand these to the right
4287 * format. (inter channel offset of 1 is the only option
4288 * for the triplets that 11d advertises.
4289 */
4290 tmp_len = cbLen + (ch_set->numChannels *
4291 sizeof(tSirMacChanInfo));
4292 if (tmp_len >= dataLen) {
4293 /*
4294 * expanding this entry will overflow our
4295 * allocation
4296 */
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07004297 sme_err(
4298 "Buffer overflow, start %d, num %d, offset %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004299 ch_set->firstChannel,
4300 ch_set->numChannels,
4301 ch_set->interChannelOffset);
4302 break;
4303 }
4304
4305 for (idx = 0; idx < ch_set->numChannels; idx++) {
4306 ch_pwr_set->firstChanNum = (tSirMacChanNum)
4307 (ch_set->firstChannel + (idx *
4308 ch_set->interChannelOffset));
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07004309 sme_debug(
4310 "Setting Channel Number %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004311 ch_pwr_set->firstChanNum);
4312 ch_pwr_set->numChannels = 1;
4313 ch_pwr_set->maxTxPower =
Anurag Chouhan6d760662016-02-20 16:05:43 +05304314 QDF_MIN(ch_set->txPower,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004315 pMac->roam.configParam.nTxPowerCap);
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07004316 sme_debug(
4317 "Setting Max Transmit Power %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004318 ch_pwr_set->maxTxPower);
4319 cbLen += sizeof(tSirMacChanInfo);
4320 ch_pwr_set++;
4321 }
4322 } else {
4323 if (cbLen >= dataLen) {
4324 /* this entry will overflow our allocation */
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07004325 sme_err(
4326 "Buffer overflow, start %d, num %d, offset %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004327 ch_set->firstChannel,
4328 ch_set->numChannels,
4329 ch_set->interChannelOffset);
4330 break;
4331 }
4332 ch_pwr_set->firstChanNum = ch_set->firstChannel;
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07004333 sme_debug("Setting Channel Number %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004334 ch_pwr_set->firstChanNum);
4335 ch_pwr_set->numChannels = ch_set->numChannels;
Anurag Chouhan6d760662016-02-20 16:05:43 +05304336 ch_pwr_set->maxTxPower = QDF_MIN(ch_set->txPower,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004337 pMac->roam.configParam.nTxPowerCap);
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07004338 sme_debug(
4339 "Setting Max Tx Power %d, nTxPower %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004340 ch_pwr_set->maxTxPower,
4341 pMac->roam.configParam.nTxPowerCap);
4342 cbLen += sizeof(tSirMacChanInfo);
4343 ch_pwr_set++;
4344 }
4345 pEntry = csr_ll_next(pList, pEntry, LL_ACCESS_LOCK);
4346 }
4347 if (cbLen)
4348 cfg_set_str(pMac, cfgId, (uint8_t *) pBuf, cbLen);
4349
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304350 qdf_mem_free(pBuf);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004351}
4352
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05304353static void csr_set_cfg_country_code(tpAniSirGlobal pMac, uint8_t *countryCode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004354{
4355 uint8_t cc[WNI_CFG_COUNTRY_CODE_LEN];
4356 /* v_REGDOMAIN_t DomainId */
4357
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07004358 sme_debug("Setting Country Code in Cfg %s", countryCode);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304359 qdf_mem_copy(cc, countryCode, WNI_CFG_COUNTRY_CODE_LEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004360
4361 /*
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05304362 * Don't program the bogus country codes that we created for Korea in
4363 * the MAC. if we see the bogus country codes, program the MAC with
4364 * the right country code.
4365 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004366 if (('K' == countryCode[0] && '1' == countryCode[1]) ||
4367 ('K' == countryCode[0] && '2' == countryCode[1]) ||
4368 ('K' == countryCode[0] && '3' == countryCode[1]) ||
4369 ('K' == countryCode[0] && '4' == countryCode[1])) {
4370 /*
4371 * replace the alternate Korea country codes, 'K1', 'K2', ..
4372 * with 'KR' for Korea
4373 */
4374 cc[1] = 'R';
4375 }
4376 cfg_set_str(pMac, WNI_CFG_COUNTRY_CODE, cc, WNI_CFG_COUNTRY_CODE_LEN);
4377
4378 /*
4379 * Need to let HALPHY know about the current domain so it can apply some
4380 * domain-specific settings (TX filter...)
4381 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004382}
4383
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304384QDF_STATUS csr_get_country_code(tpAniSirGlobal pMac, uint8_t *pBuf,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004385 uint8_t *pbLen)
4386{
Varun Reddy Yeturu7b2a6572017-06-15 11:07:28 -07004387 tSirRetStatus status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004388 uint32_t len;
4389
4390 if (pBuf && pbLen && (*pbLen >= WNI_CFG_COUNTRY_CODE_LEN)) {
4391 len = *pbLen;
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05304392 status = wlan_cfg_get_str(pMac, WNI_CFG_COUNTRY_CODE, pBuf,
4393 &len);
Varun Reddy Yeturu7b2a6572017-06-15 11:07:28 -07004394 if (status == eSIR_SUCCESS) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004395 *pbLen = (uint8_t) len;
Varun Reddy Yeturu7b2a6572017-06-15 11:07:28 -07004396 return QDF_STATUS_SUCCESS;
4397 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004398 }
4399
Varun Reddy Yeturu7b2a6572017-06-15 11:07:28 -07004400 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004401}
4402
4403void csr_set_cfg_scan_control_list(tpAniSirGlobal pMac, uint8_t *countryCode,
gaurank kathpalia14e2f912017-08-31 14:51:45 +05304404 struct csr_channel *pChannelList)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004405{
4406 uint8_t i, j;
4407 bool found = false;
4408 uint8_t *pControlList = NULL;
4409 uint32_t len = WNI_CFG_SCAN_CONTROL_LIST_LEN;
4410
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304411 pControlList = qdf_mem_malloc(WNI_CFG_SCAN_CONTROL_LIST_LEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004412 if (pControlList != NULL) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004413 if (IS_SIR_STATUS_SUCCESS(wlan_cfg_get_str(pMac,
4414 WNI_CFG_SCAN_CONTROL_LIST,
4415 pControlList, &len))) {
4416 for (i = 0; i < pChannelList->numChannels; i++) {
4417 for (j = 0; j < len; j += 2) {
4418 if (pControlList[j] ==
4419 pChannelList->channelList[i]) {
4420 found = true;
4421 break;
4422 }
4423 }
4424
4425 if (found) {
4426 /* insert a pair(channel#, flag) */
4427 pControlList[j + 1] =
4428 csr_get_scan_type(pMac,
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05304429 pControlList[j]);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004430 found = false; /* reset the flag */
4431 }
4432
4433 }
Abhishek Singh438cd7e2017-08-11 12:21:06 +05304434 QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004435 "%s: dump scan control list", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304436 QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_SME,
Abhishek Singh438cd7e2017-08-11 12:21:06 +05304437 QDF_TRACE_LEVEL_DEBUG, pControlList,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004438 len);
4439
4440 cfg_set_str(pMac, WNI_CFG_SCAN_CONTROL_LIST,
4441 pControlList, len);
4442 } /* Successfully getting scan control list */
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304443 qdf_mem_free(pControlList);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004444 } /* AllocateMemory */
4445}
4446
Sandeep Puligilladf6454a2016-10-21 16:10:59 -07004447
4448/**
4449 * csr_scan_abort_all_scans() - Abort scan on all Sessions
4450 * @mac_ctx: pointer to Global Mac structure
4451 * @reason: reason for cancelling scan
4452 *
4453 * Abort scan on all Sessions
4454 *
4455 * Return: QDF_STATUS
4456 */
4457QDF_STATUS csr_scan_abort_all_scans(tpAniSirGlobal mac_ctx,
4458 eCsrAbortReason reason)
4459{
4460 QDF_STATUS status = QDF_STATUS_SUCCESS;
4461 uint8_t session_id;
4462
4463 mac_ctx->scan.fDropScanCmd = true;
4464 for (session_id = 0; session_id < CSR_ROAM_SESSION_MAX; session_id++) {
4465 if (CSR_IS_SESSION_VALID(mac_ctx, session_id)) {
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +05304466 csr_remove_cmd_from_pending_list(
Sandeep Puligilladf6454a2016-10-21 16:10:59 -07004467 mac_ctx,
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +05304468 session_id, INVALID_SCAN_ID,
Sandeep Puligilladf6454a2016-10-21 16:10:59 -07004469 eSmeCommandScan);
4470 csr_abort_scan_from_active_list(mac_ctx,
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +05304471 session_id, INVALID_SCAN_ID, eSmeCommandScan,
4472 reason);
Sandeep Puligilladf6454a2016-10-21 16:10:59 -07004473 }
4474 }
4475 mac_ctx->scan.fDropScanCmd = false;
4476
4477 return status;
4478}
4479
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304480QDF_STATUS csr_scan_abort_mac_scan(tpAniSirGlobal pMac, uint8_t sessionId,
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +05304481 uint32_t scan_id, eCsrAbortReason reason)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004482{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304483 QDF_STATUS status = QDF_STATUS_SUCCESS;
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +05304484 QDF_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004485
4486 pMac->scan.fDropScanCmd = true;
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +05304487 ret = csr_remove_cmd_from_pending_list(pMac,
Krunal Soni81f068c2017-02-23 19:51:55 -08004488 sessionId, scan_id, eSmeCommandScan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004489 pMac->scan.fDropScanCmd = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004490
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +05304491 /*
4492 * If we are not able to find command for scan id in
4493 * pending list, check active list. Also if the session
4494 * id is valid then we have to check below active list.
4495 */
4496 if (ret != QDF_STATUS_SUCCESS ||
4497 sessionId != CSR_SESSION_ID_INVALID) {
4498 status = csr_abort_scan_from_active_list(pMac,
Krunal Soni81f068c2017-02-23 19:51:55 -08004499 sessionId, scan_id,
4500 eSmeCommandScan, reason);
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +05304501 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004502 return status;
4503}
Krunal Soni72dba662017-02-15 20:13:17 -08004504QDF_STATUS csr_remove_nonscan_cmd_from_pending_list(tpAniSirGlobal pMac,
4505 uint8_t sessionId,
4506 eSmeCommandType commandType)
4507{
4508 tDblLinkList localList;
4509 tListElem *pEntry;
4510 tSmeCmd *pCommand;
4511 tListElem *pEntryToRemove;
4512 QDF_STATUS status = QDF_STATUS_E_FAILURE;
4513
4514 qdf_mem_zero(&localList, sizeof(tDblLinkList));
4515 if (!QDF_IS_STATUS_SUCCESS(csr_ll_open(pMac->hHdd, &localList))) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07004516 sme_err("failed to open list");
Krunal Soni72dba662017-02-15 20:13:17 -08004517 return status;
4518 }
4519
4520 csr_nonscan_pending_ll_lock(pMac);
Krunal Sonia8270f52017-02-23 19:51:25 -08004521 pEntry = csr_nonscan_pending_ll_peek_head(pMac, LL_ACCESS_NOLOCK);
Krunal Soni72dba662017-02-15 20:13:17 -08004522
4523 /*
4524 * Have to make sure we don't loop back to the head of the list,
4525 * which will happen if the entry is NOT on the list
4526 */
4527 while (pEntry) {
4528 pEntryToRemove = pEntry;
4529 pEntry = csr_nonscan_pending_ll_next(pMac,
4530 pEntry, LL_ACCESS_NOLOCK);
4531 pCommand = GET_BASE_ADDR(pEntryToRemove, tSmeCmd, Link);
4532
4533 if ((pCommand->command == commandType) &&
4534 (pCommand->sessionId == sessionId)) {
4535 /* Remove that entry only */
4536 if (csr_nonscan_pending_ll_remove_entry(pMac,
4537 pEntryToRemove,
4538 LL_ACCESS_NOLOCK)) {
4539 csr_ll_insert_tail(&localList, pEntryToRemove,
4540 LL_ACCESS_NOLOCK);
4541 status = QDF_STATUS_SUCCESS;
4542 }
4543 }
4544 }
4545 csr_nonscan_pending_ll_unlock(pMac);
4546
4547 while ((pEntry = csr_ll_remove_head(&localList, LL_ACCESS_NOLOCK))) {
4548 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07004549 sme_debug("Sending abort for command ID %d",
Krunal Soni72dba662017-02-15 20:13:17 -08004550 (commandType == eSmeCommandScan) ? pCommand->u.
4551 scanCmd.scanID : sessionId);
Krunal Soni81f068c2017-02-23 19:51:55 -08004552 csr_release_command(pMac, pCommand);
Krunal Soni72dba662017-02-15 20:13:17 -08004553 }
4554
4555 csr_ll_close(&localList);
4556 return status;
4557}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004558
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +05304559QDF_STATUS csr_remove_cmd_from_pending_list(tpAniSirGlobal pMac,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004560 uint8_t sessionId,
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +05304561 uint32_t scan_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004562 eSmeCommandType commandType)
4563{
4564 tDblLinkList localList;
4565 tListElem *pEntry;
4566 tSmeCmd *pCommand;
4567 tListElem *pEntryToRemove;
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +05304568 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004569
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304570 qdf_mem_zero(&localList, sizeof(tDblLinkList));
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304571 if (!QDF_IS_STATUS_SUCCESS(csr_ll_open(pMac->hHdd, &localList))) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07004572 sme_err("failed to open list");
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +05304573 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004574 }
4575
Krunal Soni81f068c2017-02-23 19:51:55 -08004576 csr_scan_pending_ll_lock(pMac);
4577 pEntry = csr_scan_pending_ll_peek_head(pMac, LL_ACCESS_NOLOCK);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004578
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +05304579 /*
4580 * Have to make sure we don't loop back to the head of the list,
4581 * which will happen if the entry is NOT on the list
4582 */
4583 while (pEntry) {
4584 pEntryToRemove = pEntry;
Krunal Soni81f068c2017-02-23 19:51:55 -08004585 pEntry = csr_scan_pending_ll_next(pMac, pEntry,
4586 LL_ACCESS_NOLOCK);
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +05304587 pCommand = GET_BASE_ADDR(pEntryToRemove, tSmeCmd, Link);
4588
4589 if ((pCommand->command == commandType) &&
4590 (((commandType == eSmeCommandScan) &&
4591 (pCommand->u.scanCmd.scanID == scan_id)) ||
4592 (pCommand->sessionId == sessionId))) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004593 /* Remove that entry only */
Krunal Soni81f068c2017-02-23 19:51:55 -08004594 if (csr_scan_pending_ll_remove_entry(pMac,
4595 pEntryToRemove, LL_ACCESS_NOLOCK)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004596 csr_ll_insert_tail(&localList, pEntryToRemove,
4597 LL_ACCESS_NOLOCK);
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +05304598 status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004599 }
4600 }
4601 }
Krunal Soni81f068c2017-02-23 19:51:55 -08004602 csr_scan_pending_ll_unlock(pMac);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004603
4604 while ((pEntry = csr_ll_remove_head(&localList, LL_ACCESS_NOLOCK))) {
4605 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07004606 sme_debug("Sending abort for command ID %d",
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +05304607 (commandType == eSmeCommandScan) ? pCommand->u.
4608 scanCmd.scanID : sessionId);
Krunal Soni81f068c2017-02-23 19:51:55 -08004609 csr_release_command(pMac, pCommand);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004610 }
4611
4612 csr_ll_close(&localList);
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +05304613 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004614}
4615
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304616QDF_STATUS csr_scan_abort_scan_for_ssid(tpAniSirGlobal pMac, uint32_t sessionId)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004617{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304618 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004619
4620 pMac->scan.fDropScanCmd = true;
Krunal Soni81f068c2017-02-23 19:51:55 -08004621 csr_remove_scan_for_ssid_from_pending_list(pMac, sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004622 pMac->scan.fDropScanCmd = false;
Krunal Soni81f068c2017-02-23 19:51:55 -08004623 csr_abort_scan_from_active_list(pMac,
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +05304624 sessionId, INVALID_SCAN_ID, eSmeCommandScan,
4625 eCSR_SCAN_ABORT_SSID_ONLY);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004626 return status;
4627}
4628
4629void csr_remove_scan_for_ssid_from_pending_list(tpAniSirGlobal pMac,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004630 uint32_t sessionId)
4631{
4632 tDblLinkList localList;
4633 tListElem *pEntry;
4634 tSmeCmd *pCommand;
4635 tListElem *pEntryToRemove;
4636
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304637 qdf_mem_zero(&localList, sizeof(tDblLinkList));
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304638 if (!QDF_IS_STATUS_SUCCESS(csr_ll_open(pMac->hHdd, &localList))) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07004639 sme_err("failed to open list");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004640 return;
4641 }
Krunal Soni81f068c2017-02-23 19:51:55 -08004642 csr_scan_pending_ll_lock(pMac);
4643 if (!csr_scan_pending_ll_is_list_empty(pMac, LL_ACCESS_NOLOCK)) {
4644 pEntry = csr_scan_pending_ll_peek_head(pMac, LL_ACCESS_NOLOCK);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004645 /*
4646 * Have to make sure we don't loop back to the head of the list,
4647 * which will happen if the entry is NOT on the list...
4648 */
4649 while (pEntry) {
4650 pEntryToRemove = pEntry;
Krunal Soni81f068c2017-02-23 19:51:55 -08004651 pEntry = csr_scan_pending_ll_next(pMac, pEntry,
4652 LL_ACCESS_NOLOCK);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004653 pCommand = GET_BASE_ADDR(pEntryToRemove, tSmeCmd, Link);
4654
4655 if (!((eSmeCommandScan == pCommand->command) &&
4656 (sessionId == pCommand->sessionId)))
4657 continue;
4658 if (eCsrScanForSsid != pCommand->u.scanCmd.reason)
4659 continue;
4660 /* Remove that entry only */
Krunal Soni81f068c2017-02-23 19:51:55 -08004661 if (csr_scan_pending_ll_remove_entry(pMac,
4662 pEntryToRemove, LL_ACCESS_NOLOCK)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004663 csr_ll_insert_tail(&localList, pEntryToRemove,
4664 LL_ACCESS_NOLOCK);
4665 }
4666 }
4667 }
Krunal Soni81f068c2017-02-23 19:51:55 -08004668 csr_scan_pending_ll_unlock(pMac);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004669 while ((pEntry = csr_ll_remove_head(&localList, LL_ACCESS_NOLOCK))) {
4670 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
Krunal Soni81f068c2017-02-23 19:51:55 -08004671 csr_release_command(pMac, pCommand);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004672 }
4673 csr_ll_close(&localList);
4674}
4675
4676
4677/**
4678 * csr_send_scan_abort() - Sends scan abort command to firmware
4679 * @mac_ctx: Pointer to Global Mac structure
4680 * @session_id: CSR session identification
4681 * @scan_id: scan identifier
4682 *
4683 * .Sends scan abort command to firmware
4684 *
4685 * Return: None
4686 */
4687static void csr_send_scan_abort(tpAniSirGlobal mac_ctx,
4688 uint32_t session_id, uint32_t scan_id)
4689{
4690 tSirSmeScanAbortReq *msg;
4691 uint16_t msg_len;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304692 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004693
4694 msg_len = (uint16_t)(sizeof(tSirSmeScanAbortReq));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304695 msg = qdf_mem_malloc(msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004696 if (NULL == msg) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07004697 sme_err("Failed to alloc memory for SmeScanAbortReq");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004698 return;
4699 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004700 msg->type = eWNI_SME_SCAN_ABORT_IND;
4701 msg->msgLen = msg_len;
4702 msg->sessionId = session_id;
4703 msg->scan_id = scan_id;
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07004704 sme_debug(
4705 "Abort scan sent to Firmware scan_id %d session %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004706 scan_id, session_id);
Rajeev Kumard138ac52017-01-30 18:38:37 -08004707 status = umac_send_mb_message_to_mac(msg);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304708 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07004709 sme_err("Failed to send abort scan.scan_id %d session %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004710 scan_id, session_id);
4711 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004712}
4713
4714/**
4715 * csr_abort_scan_from_active_list() - Remove Scan command from active list
4716 * @mac_ctx: Pointer to Global Mac structure
4717 * @list: pointer to scan active list
4718 * @session_id: CSR session identification
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +05304719 * @scan_id: scan id
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004720 * @scan_cmd_type: scan command type
4721 * @abort_reason: abort reason
4722 *
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +05304723 * Remove Scan command from active scan list by matching either the scan id
4724 * or session id.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004725 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304726 * Return: Success - QDF_STATUS_SUCCESS, Failure - error number
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004727 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304728QDF_STATUS csr_abort_scan_from_active_list(tpAniSirGlobal mac_ctx,
Krunal Soni81f068c2017-02-23 19:51:55 -08004729 uint32_t session_id, uint32_t scan_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004730 eSmeCommandType scan_cmd_type, eCsrAbortReason abort_reason)
4731{
4732 tListElem *entry;
4733 tSmeCmd *cmd;
4734 tListElem *entry_remove;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304735 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004736
Krunal Soni81f068c2017-02-23 19:51:55 -08004737 csr_scan_active_ll_lock(mac_ctx);
4738 if (!csr_scan_active_ll_is_list_empty(mac_ctx, LL_ACCESS_NOLOCK)) {
4739 entry = csr_scan_active_ll_peek_head(mac_ctx, LL_ACCESS_NOLOCK);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004740 while (entry) {
4741 entry_remove = entry;
Krunal Soni81f068c2017-02-23 19:51:55 -08004742 entry = csr_scan_active_ll_next(mac_ctx, entry,
4743 LL_ACCESS_NOLOCK);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004744 cmd = GET_BASE_ADDR(entry_remove, tSmeCmd, Link);
4745
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004746 /*skip if abort reason is for SSID*/
4747 if ((abort_reason == eCSR_SCAN_ABORT_SSID_ONLY) &&
4748 (eCsrScanForSsid != cmd->u.scanCmd.reason))
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05304749 continue;
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +05304750 /*
4751 * Do not skip if command and either session id
4752 * or scan id is matched
4753 */
4754 if ((cmd->command == scan_cmd_type) &&
4755 ((cmd->u.scanCmd.scanID == scan_id) ||
4756 (cmd->sessionId == session_id))) {
4757 if (abort_reason ==
4758 eCSR_SCAN_ABORT_DUE_TO_BAND_CHANGE)
4759 cmd->u.scanCmd.abort_scan_indication =
Ratnam Rachurib7595a32016-11-04 16:58:53 +05304760 eCSR_SCAN_ABORT_DUE_TO_BAND_CHANGE;
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +05304761
4762 csr_send_scan_abort(mac_ctx, cmd->sessionId,
4763 cmd->u.scanCmd.scanID);
4764
4765 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004766 }
4767 }
Krunal Soni81f068c2017-02-23 19:51:55 -08004768 csr_scan_active_ll_unlock(mac_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004769
4770 return status;
4771}
4772
4773
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304774QDF_STATUS csr_scan_abort_mac_scan_not_for_connect(tpAniSirGlobal pMac,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004775 uint8_t sessionId)
4776{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304777 QDF_STATUS status = QDF_STATUS_SUCCESS;
Srinivas Girigowda4d65ebe2017-10-13 21:41:42 -07004778
Krunal Sonif3583022017-02-10 17:18:10 -08004779 if (!csr_is_scan_for_roam_command_active(pMac, sessionId)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004780 /*
4781 * Only abort the scan if it is not used for other roam/connect
4782 * purpose
4783 */
4784 status = csr_scan_abort_mac_scan(pMac, sessionId,
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +05304785 INVALID_SCAN_ID, eCSR_SCAN_ABORT_DEFAULT);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004786 }
4787 return status;
4788}
4789bool csr_roam_is_valid_channel(tpAniSirGlobal pMac, uint8_t channel)
4790{
4791 bool fValid = false;
4792 uint32_t idx_valid_ch;
4793 uint32_t len = pMac->roam.numValidChannels;
4794
4795 for (idx_valid_ch = 0; (idx_valid_ch < len); idx_valid_ch++) {
4796 if (channel == pMac->roam.validChannelList[idx_valid_ch]) {
4797 fValid = true;
4798 break;
4799 }
4800 }
4801 return fValid;
4802}
4803
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304804QDF_STATUS csr_scan_create_entry_in_scan_cache(tpAniSirGlobal pMac,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004805 uint32_t sessionId,
Anurag Chouhan6d760662016-02-20 16:05:43 +05304806 struct qdf_mac_addr bssid,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004807 uint8_t channel)
4808{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304809 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004810 tDot11fBeaconIEs *pNewIes = NULL;
gaurank kathpalia14e2f912017-08-31 14:51:45 +05304811 struct csr_roam_session *pSession = CSR_GET_SESSION(pMac, sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004812 tSirBssDescription *pNewBssDescriptor = NULL;
4813 uint32_t size = 0;
4814
4815 if (NULL == pSession) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304816 status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004817 return status;
4818 }
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07004819 sme_debug("Current bssid::"MAC_ADDRESS_STR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004820 MAC_ADDR_ARRAY(pSession->pConnectBssDesc->bssId));
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07004821 sme_debug("My bssid::"MAC_ADDRESS_STR" channel %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004822 MAC_ADDR_ARRAY(bssid.bytes), channel);
4823
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304824 if (!QDF_IS_STATUS_SUCCESS(csr_get_parsed_bss_description_ies(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004825 pMac, pSession->pConnectBssDesc,
4826 &pNewIes))) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07004827 sme_err("Failed to parse IEs");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304828 status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004829 goto free_mem;
4830 }
4831 size = pSession->pConnectBssDesc->length +
4832 sizeof(pSession->pConnectBssDesc->length);
4833 if (!size) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07004834 sme_err("length of bss descriptor is 0");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304835 status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004836 goto free_mem;
4837 }
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304838 pNewBssDescriptor = qdf_mem_malloc(size);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004839 if (NULL == pNewBssDescriptor) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07004840 sme_err("memory allocation failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304841 status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004842 goto free_mem;
4843 }
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304844 qdf_mem_copy(pNewBssDescriptor, pSession->pConnectBssDesc, size);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004845 /* change the BSSID & channel as passed */
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304846 qdf_mem_copy(pNewBssDescriptor->bssId, bssid.bytes,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004847 sizeof(tSirMacAddr));
4848 pNewBssDescriptor->channelId = channel;
Abhishek Singha92cf1e2017-11-02 17:04:11 +05304849 if (!csr_scan_append_bss_description(pMac, pNewBssDescriptor,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004850 pNewIes, true, sessionId)) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07004851 sme_err("csr_scan_append_bss_description failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304852 status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004853 goto free_mem;
4854 }
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07004855 sme_err("entry successfully added in scan cache");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004856
4857free_mem:
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05304858 if (pNewIes)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304859 qdf_mem_free(pNewIes);
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05304860
4861 if (pNewBssDescriptor)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304862 qdf_mem_free(pNewBssDescriptor);
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05304863
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004864 return status;
4865}
4866
4867#ifdef FEATURE_WLAN_ESE
4868/* Update the TSF with the difference in system time */
4869void update_cckmtsf(uint32_t *timeStamp0, uint32_t *timeStamp1,
Arun Khandavalli8a711cb2017-01-03 20:23:56 +05304870 uint64_t *incr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004871{
4872 uint64_t timeStamp64 = ((uint64_t) *timeStamp1 << 32) | (*timeStamp0);
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05304873
Arun Khandavalli8a711cb2017-01-03 20:23:56 +05304874 timeStamp64 = (uint64_t)(timeStamp64 + (*incr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004875 *timeStamp0 = (uint32_t) (timeStamp64 & 0xffffffff);
4876 *timeStamp1 = (uint32_t) ((timeStamp64 >> 32) & 0xffffffff);
4877}
4878#endif
4879
4880/**
4881 * csr_scan_save_roam_offload_ap_to_scan_cache
4882 * This function parses the received beacon/probe response
4883 * from the firmware as part of the roam synch indication.
4884 * The beacon or the probe response is parsed and is also
4885 * saved into the scan cache
4886 *
4887 * @param pMac Pointer to Global Mac
4888 * @param roam_sync_ind_ptr Roam Synch Indication from
4889 * firmware which also contains the beacon/probe
4890 * response
4891 * @return Status
4892 */
4893#ifdef WLAN_FEATURE_ROAM_OFFLOAD
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304894QDF_STATUS csr_scan_save_roam_offload_ap_to_scan_cache(tpAniSirGlobal pMac,
Varun Reddy Yeturud5939f82015-12-24 18:14:02 -08004895 roam_offload_synch_ind *roam_sync_ind_ptr,
4896 tpSirBssDescription bss_desc_ptr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004897{
4898 uint32_t length = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004899 tDot11fBeaconIEs *ies_local_ptr = NULL;
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05304900 struct tag_csrscan_result *scan_res_ptr = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004901 uint8_t session_id = roam_sync_ind_ptr->roamedVdevId;
4902
4903 length = roam_sync_ind_ptr->beaconProbeRespLength -
4904 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET);
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05304905 scan_res_ptr = qdf_mem_malloc(sizeof(struct tag_csrscan_result) +
4906 length);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004907 if (scan_res_ptr == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304908 QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004909 " fail to allocate memory for frame");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304910 return QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004911 }
4912
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304913 qdf_mem_copy(&scan_res_ptr->Result.BssDescriptor,
Varun Reddy Yeturud5939f82015-12-24 18:14:02 -08004914 bss_desc_ptr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004915 (sizeof(tSirBssDescription) + length));
4916 ies_local_ptr = (tDot11fBeaconIEs *)(scan_res_ptr->Result.pvIes);
4917 if (!ies_local_ptr &&
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304918 (!QDF_IS_STATUS_SUCCESS(csr_get_parsed_bss_description_ies(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004919 pMac, &scan_res_ptr->Result.
4920 BssDescriptor,
4921 &ies_local_ptr)))) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304922 QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004923 "%s:Cannot Parse IEs", __func__);
4924 csr_free_scan_result_entry(pMac, scan_res_ptr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304925 return QDF_STATUS_E_RESOURCES;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004926 }
4927
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07004928 sme_debug("LFR3:Add BSSID to scan cache" MAC_ADDRESS_STR,
Padma, Santhosh Kumarcd35f532016-12-27 12:07:39 +05304929 MAC_ADDR_ARRAY(scan_res_ptr->Result.BssDescriptor.bssId));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004930 csr_scan_add_result(pMac, scan_res_ptr, ies_local_ptr, session_id);
yeshwanth sriram guntuka67516632017-01-30 16:05:00 +05304931 if ((scan_res_ptr->Result.pvIes == NULL) && ies_local_ptr)
4932 qdf_mem_free(ies_local_ptr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304933 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004934}
4935#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004936/**
Naveen Rawat664a7cb2017-01-19 17:58:14 -08004937 * csr_get_fst_bssdescr_ptr() - This function returns the pointer to first bss
4938 * description from scan handle
4939 * @result_handle: an object for the result.
4940 *
4941 * Return: first bss descriptor from the scan handle.
4942 */
4943tpSirBssDescription csr_get_fst_bssdescr_ptr(tScanResultHandle result_handle)
4944{
4945 tListElem *first_element = NULL;
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05304946 struct tag_csrscan_result *scan_result = NULL;
4947 struct scan_result_list *bss_list =
4948 (struct scan_result_list *)result_handle;
Naveen Rawat664a7cb2017-01-19 17:58:14 -08004949
4950 if (NULL == bss_list) {
4951 QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_ERROR,
4952 FL("Empty bss_list"));
4953 return NULL;
4954 }
4955 if (csr_ll_is_list_empty(&bss_list->List, LL_ACCESS_NOLOCK)) {
4956 QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_ERROR,
4957 FL("bss_list->List is empty"));
Naveen Rawat664a7cb2017-01-19 17:58:14 -08004958 return NULL;
4959 }
4960 first_element = csr_ll_peek_head(&bss_list->List, LL_ACCESS_NOLOCK);
4961 if (NULL == first_element) {
4962 QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_ERROR,
4963 FL("peer head return NULL"));
4964 return NULL;
4965 }
4966
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05304967 scan_result = GET_BASE_ADDR(first_element, struct tag_csrscan_result,
4968 Link);
Naveen Rawat664a7cb2017-01-19 17:58:14 -08004969
4970 return &scan_result->Result.BssDescriptor;
4971}
4972
4973/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004974 * csr_get_bssdescr_from_scan_handle() - This function to extract
4975 * first bss description from scan handle
4976 * @result_handle: an object for the result.
4977 *
4978 * This function is written to extract first bss from scan handle.
4979 *
4980 * Return: first bss descriptor from the scan handle.
4981 */
4982tSirBssDescription*
4983csr_get_bssdescr_from_scan_handle(tScanResultHandle result_handle,
4984 tSirBssDescription *bss_descr)
4985{
4986 tListElem *first_element = NULL;
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05304987 struct tag_csrscan_result *scan_result = NULL;
4988 struct scan_result_list *bss_list =
4989 (struct scan_result_list *)result_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004990
4991 if (NULL == bss_list) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304992 QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004993 FL("Empty bss_list"));
4994 return NULL;
4995 }
4996 if (csr_ll_is_list_empty(&bss_list->List, LL_ACCESS_NOLOCK)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304997 QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004998 FL("bss_list->List is empty"));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304999 qdf_mem_free(bss_list);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005000 return NULL;
5001 }
5002 first_element = csr_ll_peek_head(&bss_list->List, LL_ACCESS_NOLOCK);
5003 if (first_element) {
5004 scan_result = GET_BASE_ADDR(first_element,
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05305005 struct tag_csrscan_result,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005006 Link);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305007 qdf_mem_copy(bss_descr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005008 &scan_result->Result.BssDescriptor,
5009 sizeof(tSirBssDescription));
5010 }
5011 return bss_descr;
5012}
5013
5014/**
5015 * scan_active_list_cmd_timeout_handle() - To handle scan active command timeout
5016 * @userData: scan context
5017 *
5018 * This routine is to handle scan active command timeout
5019 *
5020 * Return: None
5021 */
5022void csr_scan_active_list_timeout_handle(void *userData)
5023{
5024 tSmeCmd *scan_cmd = (tSmeCmd *) userData;
Anurag Chouhan6d760662016-02-20 16:05:43 +05305025 tHalHandle *hal_ctx = cds_get_context(QDF_MODULE_ID_PE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005026 tpAniSirGlobal mac_ctx;
5027 uint16_t scan_id;
5028 tSirSmeScanAbortReq *msg;
5029 uint16_t msg_len;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305030 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005031
5032 if (scan_cmd == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305033 QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005034 FL("Scan Timeout: Scan command is NULL"));
5035 return;
5036 }
Varun Reddy Yeturuf76f6de2015-11-17 21:33:53 -08005037 if (hal_ctx == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305038 QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_ERROR,
Varun Reddy Yeturuf76f6de2015-11-17 21:33:53 -08005039 FL("HAL Context is NULL"));
5040 return;
5041 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005042 mac_ctx = PMAC_STRUCT(hal_ctx);
5043 scan_id = scan_cmd->u.scanCmd.scanID;
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07005044 sme_err("Scan Timeout:Sending abort to Firmware ID %d session %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005045 scan_id, scan_cmd->sessionId);
5046 msg_len = (uint16_t)(sizeof(tSirSmeScanAbortReq));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305047 msg = qdf_mem_malloc(msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005048 if (NULL == msg) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07005049 sme_err("Failed to alloc memory for SmeScanAbortReq");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005050 return;
5051 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005052 msg->type = eWNI_SME_SCAN_ABORT_IND;
5053 msg->msgLen = msg_len;
5054 msg->sessionId = scan_cmd->sessionId;
5055 msg->scan_id = scan_id;
Rajeev Kumard138ac52017-01-30 18:38:37 -08005056 status = umac_send_mb_message_to_mac(msg);
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05305057 if (!QDF_IS_STATUS_SUCCESS(status))
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07005058 sme_err("Failed to post message to LIM");
Nishank Aggarwal778bf5d2017-04-01 17:07:56 +05305059
Krunal Soni81f068c2017-02-23 19:51:55 -08005060 scan_cmd->u.scanCmd.status = eCSR_SCAN_FAILURE;
5061 csr_release_command(mac_ctx, scan_cmd);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005062}
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305063
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305064static enum wlan_auth_type csr_covert_auth_type_new(eCsrAuthType auth)
5065{
5066 switch (auth) {
5067 case eCSR_AUTH_TYPE_NONE:
5068 case eCSR_AUTH_TYPE_OPEN_SYSTEM:
5069 return WLAN_AUTH_TYPE_OPEN_SYSTEM;
5070 case eCSR_AUTH_TYPE_SHARED_KEY:
5071 return WLAN_AUTH_TYPE_SHARED_KEY;
5072 case eCSR_AUTH_TYPE_AUTOSWITCH:
5073 return WLAN_AUTH_TYPE_AUTOSWITCH;
5074 case eCSR_AUTH_TYPE_WPA:
5075 return WLAN_AUTH_TYPE_WPA;
5076 case eCSR_AUTH_TYPE_WPA_PSK:
5077 return WLAN_AUTH_TYPE_WPA_PSK;
5078 case eCSR_AUTH_TYPE_WPA_NONE:
5079 return WLAN_AUTH_TYPE_WPA_NONE;
5080 case eCSR_AUTH_TYPE_RSN:
5081 return WLAN_AUTH_TYPE_RSN;
5082 case eCSR_AUTH_TYPE_RSN_PSK:
5083 return WLAN_AUTH_TYPE_RSN_PSK;
5084 case eCSR_AUTH_TYPE_FT_RSN:
5085 return WLAN_AUTH_TYPE_FT_RSN;
5086 case eCSR_AUTH_TYPE_FT_RSN_PSK:
5087 return WLAN_AUTH_TYPE_FT_RSN_PSK;
5088 case eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE:
5089 return WLAN_AUTH_TYPE_WAPI_WAI_CERTIFICATE;
5090 case eCSR_AUTH_TYPE_WAPI_WAI_PSK:
5091 return WLAN_AUTH_TYPE_WAPI_WAI_PSK;
5092 case eCSR_AUTH_TYPE_CCKM_WPA:
5093 return WLAN_AUTH_TYPE_CCKM_WPA;
5094 case eCSR_AUTH_TYPE_CCKM_RSN:
5095 return WLAN_AUTH_TYPE_CCKM_RSN;
5096 case eCSR_AUTH_TYPE_RSN_PSK_SHA256:
5097 return WLAN_AUTH_TYPE_RSN_PSK_SHA256;
5098 case eCSR_AUTH_TYPE_RSN_8021X_SHA256:
5099 return WLAN_AUTH_TYPE_RSN_8021X_SHA256;
Sridhar Selvaraj6cf642f2017-08-21 14:28:10 +05305100 case eCSR_AUTH_TYPE_FILS_SHA256:
5101 return WLAN_AUTH_TYPE_FILS_SHA256;
5102 case eCSR_AUTH_TYPE_FILS_SHA384:
5103 return WLAN_AUTH_TYPE_FILS_SHA384;
5104 case eCSR_AUTH_TYPE_FT_FILS_SHA256:
5105 return WLAN_AUTH_TYPE_FT_FILS_SHA256;
5106 case eCSR_AUTH_TYPE_FT_FILS_SHA384:
5107 return WLAN_AUTH_TYPE_FT_FILS_SHA384;
Abhishek Singh02cb9e02017-08-30 17:39:50 +05305108 case eCSR_AUTH_TYPE_DPP_RSN:
5109 return WLAN_AUTH_TYPE_DPP_RSN;
Padma, Santhosh Kumarc69ce072017-11-06 18:21:05 +05305110 case eCSR_AUTH_TYPE_OWE:
5111 return WLAN_AUTH_TYPE_OWE;
Padma, Santhosh Kumare587a5c2017-12-21 12:44:46 +05305112 case eCSR_AUTH_TYPE_SUITEB_EAP_SHA256:
5113 return WLAN_AUTH_TYPE_SUITEB_EAP_SHA256;
5114 case eCSR_AUTH_TYPE_SUITEB_EAP_SHA384:
5115 return WLAN_AUTH_TYPE_SUITEB_EAP_SHA384;
Padma, Santhosh Kumar07eb80b2017-07-05 16:10:06 +05305116 case eCSR_AUTH_TYPE_SAE:
5117 return WLAN_AUTH_TYPE_SAE;
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305118 case eCSR_NUM_OF_SUPPORT_AUTH_TYPE:
5119 default:
5120 return WLAN_AUTH_TYPE_OPEN_SYSTEM;
5121 }
5122}
5123
5124static eCsrAuthType csr_covert_auth_type_old(enum wlan_auth_type auth)
5125{
5126 switch (auth) {
5127 case WLAN_AUTH_TYPE_OPEN_SYSTEM:
5128 return eCSR_AUTH_TYPE_OPEN_SYSTEM;
5129 case WLAN_AUTH_TYPE_SHARED_KEY:
5130 return eCSR_AUTH_TYPE_SHARED_KEY;
5131 case WLAN_AUTH_TYPE_AUTOSWITCH:
5132 return eCSR_AUTH_TYPE_AUTOSWITCH;
5133 case WLAN_AUTH_TYPE_WPA:
5134 return eCSR_AUTH_TYPE_WPA;
5135 case WLAN_AUTH_TYPE_WPA_PSK:
5136 return eCSR_AUTH_TYPE_WPA_PSK;
5137 case WLAN_AUTH_TYPE_WPA_NONE:
5138 return eCSR_AUTH_TYPE_WPA_NONE;
5139 case WLAN_AUTH_TYPE_RSN:
5140 return eCSR_AUTH_TYPE_RSN;
5141 case WLAN_AUTH_TYPE_RSN_PSK:
5142 return eCSR_AUTH_TYPE_RSN_PSK;
5143 case WLAN_AUTH_TYPE_FT_RSN:
5144 return eCSR_AUTH_TYPE_FT_RSN;
5145 case WLAN_AUTH_TYPE_FT_RSN_PSK:
5146 return eCSR_AUTH_TYPE_FT_RSN_PSK;
5147 case WLAN_AUTH_TYPE_WAPI_WAI_CERTIFICATE:
5148 return eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE;
5149 case WLAN_AUTH_TYPE_WAPI_WAI_PSK:
5150 return eCSR_AUTH_TYPE_WAPI_WAI_PSK;
5151 case WLAN_AUTH_TYPE_CCKM_WPA:
5152 return eCSR_AUTH_TYPE_CCKM_WPA;
5153 case WLAN_AUTH_TYPE_CCKM_RSN:
5154 return eCSR_AUTH_TYPE_CCKM_RSN;
5155 case WLAN_AUTH_TYPE_RSN_PSK_SHA256:
5156 return eCSR_AUTH_TYPE_RSN_PSK_SHA256;
5157 case WLAN_AUTH_TYPE_RSN_8021X_SHA256:
5158 return eCSR_AUTH_TYPE_RSN_8021X_SHA256;
Sridhar Selvaraj6cf642f2017-08-21 14:28:10 +05305159 case WLAN_AUTH_TYPE_FILS_SHA256:
5160 return eCSR_AUTH_TYPE_FILS_SHA256;
5161 case WLAN_AUTH_TYPE_FILS_SHA384:
5162 return eCSR_AUTH_TYPE_FILS_SHA384;
5163 case WLAN_AUTH_TYPE_FT_FILS_SHA256:
5164 return eCSR_AUTH_TYPE_FT_FILS_SHA256;
5165 case WLAN_AUTH_TYPE_FT_FILS_SHA384:
5166 return eCSR_AUTH_TYPE_FT_FILS_SHA384;
Abhishek Singh02cb9e02017-08-30 17:39:50 +05305167 case WLAN_AUTH_TYPE_DPP_RSN:
5168 return eCSR_AUTH_TYPE_DPP_RSN;
Padma, Santhosh Kumarc69ce072017-11-06 18:21:05 +05305169 case WLAN_AUTH_TYPE_OWE:
5170 return eCSR_AUTH_TYPE_OWE;
Padma, Santhosh Kumare587a5c2017-12-21 12:44:46 +05305171 case WLAN_AUTH_TYPE_SUITEB_EAP_SHA256:
5172 return eCSR_AUTH_TYPE_SUITEB_EAP_SHA256;
5173 case WLAN_AUTH_TYPE_SUITEB_EAP_SHA384:
5174 return eCSR_AUTH_TYPE_SUITEB_EAP_SHA384;
Padma, Santhosh Kumar07eb80b2017-07-05 16:10:06 +05305175 case WLAN_AUTH_TYPE_SAE:
5176 return eCSR_AUTH_TYPE_SAE;
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305177 case WLAN_NUM_OF_SUPPORT_AUTH_TYPE:
5178 default:
5179 return eCSR_AUTH_TYPE_OPEN_SYSTEM;
5180 }
5181}
5182
5183static enum wlan_enc_type csr_covert_enc_type_new(eCsrEncryptionType enc)
5184{
5185 switch (enc) {
5186 case eCSR_ENCRYPT_TYPE_NONE:
5187 return WLAN_ENCRYPT_TYPE_NONE;
5188 case eCSR_ENCRYPT_TYPE_WEP40_STATICKEY:
5189 return WLAN_ENCRYPT_TYPE_WEP40_STATICKEY;
5190 case eCSR_ENCRYPT_TYPE_WEP104_STATICKEY:
5191 return WLAN_ENCRYPT_TYPE_WEP104_STATICKEY;
5192 case eCSR_ENCRYPT_TYPE_WEP40:
5193 return WLAN_ENCRYPT_TYPE_WEP40;
5194 case eCSR_ENCRYPT_TYPE_WEP104:
5195 return WLAN_ENCRYPT_TYPE_WEP104;
5196 case eCSR_ENCRYPT_TYPE_TKIP:
5197 return WLAN_ENCRYPT_TYPE_TKIP;
5198 case eCSR_ENCRYPT_TYPE_AES:
5199 return WLAN_ENCRYPT_TYPE_AES;
5200 case eCSR_ENCRYPT_TYPE_WPI:
5201 return WLAN_ENCRYPT_TYPE_WPI;
5202 case eCSR_ENCRYPT_TYPE_KRK:
5203 return WLAN_ENCRYPT_TYPE_KRK;
5204 case eCSR_ENCRYPT_TYPE_BTK:
5205 return WLAN_ENCRYPT_TYPE_BTK;
5206 case eCSR_ENCRYPT_TYPE_AES_CMAC:
5207 return WLAN_ENCRYPT_TYPE_AES_CMAC;
Mukul Sharma05504ac2017-06-08 12:35:53 +05305208 case eCSR_ENCRYPT_TYPE_AES_GCMP:
5209 return WLAN_ENCRYPT_TYPE_AES_GCMP;
5210 case eCSR_ENCRYPT_TYPE_AES_GCMP_256:
5211 return WLAN_ENCRYPT_TYPE_AES_GCMP_256;
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305212 case eCSR_ENCRYPT_TYPE_ANY:
5213 default:
5214 return WLAN_ENCRYPT_TYPE_NONE;
5215 }
5216}
5217
5218static eCsrEncryptionType csr_covert_enc_type_old(enum wlan_enc_type enc)
5219{
5220 switch (enc) {
5221 case WLAN_ENCRYPT_TYPE_NONE:
5222 return eCSR_ENCRYPT_TYPE_NONE;
5223 case WLAN_ENCRYPT_TYPE_WEP40_STATICKEY:
5224 return eCSR_ENCRYPT_TYPE_WEP40_STATICKEY;
5225 case WLAN_ENCRYPT_TYPE_WEP104_STATICKEY:
5226 return eCSR_ENCRYPT_TYPE_WEP104_STATICKEY;
5227 case WLAN_ENCRYPT_TYPE_WEP40:
5228 return eCSR_ENCRYPT_TYPE_WEP40;
5229 case WLAN_ENCRYPT_TYPE_WEP104:
5230 return eCSR_ENCRYPT_TYPE_WEP104;
5231 case WLAN_ENCRYPT_TYPE_TKIP:
5232 return eCSR_ENCRYPT_TYPE_TKIP;
5233 case WLAN_ENCRYPT_TYPE_AES:
5234 return eCSR_ENCRYPT_TYPE_AES;
5235 case WLAN_ENCRYPT_TYPE_WPI:
5236 return eCSR_ENCRYPT_TYPE_WPI;
5237 case WLAN_ENCRYPT_TYPE_KRK:
5238 return eCSR_ENCRYPT_TYPE_KRK;
5239 case WLAN_ENCRYPT_TYPE_BTK:
5240 return eCSR_ENCRYPT_TYPE_BTK;
5241 case WLAN_ENCRYPT_TYPE_AES_CMAC:
5242 return eCSR_ENCRYPT_TYPE_AES_CMAC;
Mukul Sharma05504ac2017-06-08 12:35:53 +05305243 case WLAN_ENCRYPT_TYPE_AES_GCMP:
5244 return eCSR_ENCRYPT_TYPE_AES_GCMP;
5245 case WLAN_ENCRYPT_TYPE_AES_GCMP_256:
5246 return eCSR_ENCRYPT_TYPE_AES_GCMP_256;
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305247 case WLAN_ENCRYPT_TYPE_ANY:
5248 default:
5249 return eCSR_ENCRYPT_TYPE_NONE;
5250 }
5251}
5252
Padma, Santhosh Kumar4117d7a2017-12-20 17:39:33 +05305253#ifdef WLAN_FEATURE_11W
5254/**
5255 * csr_update_pmf_cap: Updates PMF cap
5256 * @src_filter: Source filter
5257 * @dst_filter: Destination filter
5258 *
5259 * Return: None
5260 */
5261static void csr_update_pmf_cap(tCsrScanResultFilter *src_filter,
5262 struct scan_filter *dst_filter) {
5263
5264 if (src_filter->MFPCapable || src_filter->MFPEnabled)
5265 dst_filter->pmf_cap = WLAN_PMF_CAPABLE;
5266 if (src_filter->MFPRequired)
5267 dst_filter->pmf_cap = WLAN_PMF_REQUIRED;
5268}
5269#else
5270static inline void csr_update_pmf_cap(tCsrScanResultFilter *src_filter,
5271 struct scan_filter *dst_filter)
5272{}
5273#endif
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305274
5275static QDF_STATUS csr_prepare_scan_filter(tpAniSirGlobal mac_ctx,
5276 tCsrScanResultFilter *pFilter, struct scan_filter *filter)
5277{
5278 int i;
5279 uint32_t len = 0;
5280 QDF_STATUS status;
Tushnim Bhattacharyya0c4ad2d2017-03-09 15:59:03 -08005281 enum policy_mgr_con_mode new_mode;
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305282
5283 filter->num_of_bssid = pFilter->BSSIDs.numOfBSSIDs;
5284 if (filter->num_of_bssid > WLAN_SCAN_FILTER_NUM_BSSID)
5285 filter->num_of_bssid = WLAN_SCAN_FILTER_NUM_BSSID;
5286 for (i = 0; i < filter->num_of_bssid; i++)
5287 qdf_mem_copy(filter->bssid_list[i].bytes,
5288 pFilter->BSSIDs.bssid[i].bytes,
5289 QDF_MAC_ADDR_SIZE);
5290
5291 filter->num_of_ssid = pFilter->SSIDs.numOfSSIDs;
5292 if (filter->num_of_ssid > WLAN_SCAN_FILTER_NUM_SSID)
5293 filter->num_of_ssid = WLAN_SCAN_FILTER_NUM_SSID;
5294 for (i = 0; i < filter->num_of_ssid; i++) {
5295 filter->ssid_list[i].length =
5296 pFilter->SSIDs.SSIDList[i].SSID.length;
5297 qdf_mem_copy(filter->ssid_list[i].ssid,
5298 pFilter->SSIDs.SSIDList[i].SSID.ssId,
5299 filter->ssid_list[i].length);
5300 }
5301
5302 filter->num_of_channels =
5303 pFilter->ChannelInfo.numOfChannels;
5304 if (filter->num_of_channels > QDF_MAX_NUM_CHAN)
5305 filter->num_of_channels = QDF_MAX_NUM_CHAN;
5306 qdf_mem_copy(filter->channel_list,
5307 pFilter->ChannelInfo.ChannelList,
5308 filter->num_of_channels);
5309
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05305310 if (pFilter->realm_check) {
5311 filter->fils_scan_filter.realm_check = true;
5312 qdf_mem_copy(filter->fils_scan_filter.fils_realm,
5313 pFilter->fils_realm, REAM_HASH_LEN);
5314 }
5315
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305316 filter->num_of_auth =
5317 pFilter->authType.numEntries;
5318 if (filter->num_of_auth > WLAN_NUM_OF_SUPPORT_AUTH_TYPE)
5319 filter->num_of_auth = WLAN_NUM_OF_SUPPORT_AUTH_TYPE;
5320 for (i = 0; i < filter->num_of_auth; i++)
5321 filter->auth_type[i] =
5322 csr_covert_auth_type_new(pFilter->authType.authType[i]);
5323 filter->num_of_enc_type =
5324 pFilter->EncryptionType.numEntries;
5325 if (filter->num_of_enc_type > WLAN_NUM_OF_ENCRYPT_TYPE)
5326 filter->num_of_enc_type = WLAN_NUM_OF_ENCRYPT_TYPE;
5327 for (i = 0; i < filter->num_of_enc_type; i++)
5328 filter->enc_type[i] =
5329 csr_covert_enc_type_new(
5330 pFilter->EncryptionType.encryptionType[i]);
5331 filter->num_of_mc_enc_type =
5332 pFilter->mcEncryptionType.numEntries;
5333 if (filter->num_of_mc_enc_type > WLAN_NUM_OF_ENCRYPT_TYPE)
5334 filter->num_of_mc_enc_type = WLAN_NUM_OF_ENCRYPT_TYPE;
5335 for (i = 0; i < filter->num_of_mc_enc_type; i++)
5336 filter->mc_enc_type[i] =
5337 csr_covert_enc_type_new(
5338 pFilter->mcEncryptionType.encryptionType[i]);
5339
5340 qdf_mem_copy(filter->country,
5341 pFilter->countryCode, WNI_CFG_COUNTRY_CODE_LEN);
5342
gaurank kathpalia26900982017-12-19 13:57:48 +05305343 if (pFilter->bWPSAssociation || pFilter->bOSENAssociation)
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305344 filter->ignore_auth_enc_type = true;
5345
5346 filter->rrm_measurement_filter = pFilter->fMeasurement;
5347
5348 filter->mobility_domain = pFilter->MDID.mobilityDomain;
5349
5350 filter->p2p_results = pFilter->p2pResult;
5351
Padma, Santhosh Kumar4117d7a2017-12-20 17:39:33 +05305352 csr_update_pmf_cap(pFilter, filter);
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305353
5354 if (pFilter->BSSType == eCSR_BSS_TYPE_INFRASTRUCTURE)
5355 filter->bss_type = WLAN_TYPE_BSS;
5356 else if (pFilter->BSSType == eCSR_BSS_TYPE_IBSS ||
5357 pFilter->BSSType == eCSR_BSS_TYPE_START_IBSS)
5358 filter->bss_type = WLAN_TYPE_IBSS;
5359 else
5360 filter->bss_type = WLAN_TYPE_ANY;
5361
5362 filter->dot11_mode = pFilter->phyMode;
5363
gaurank kathpalia5efa73b2017-12-29 10:55:16 +05305364 // enable bss scoring for only STA mode
5365 if (pFilter->csrPersona == QDF_STA_MODE)
5366 filter->bss_scoring_required = true;
5367 else
5368 filter->bss_scoring_required = false;
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305369 if (!pFilter->BSSIDs.numOfBSSIDs) {
Tushnim Bhattacharyya0c4ad2d2017-03-09 15:59:03 -08005370 if (policy_mgr_map_concurrency_mode(
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305371 &pFilter->csrPersona, &new_mode)) {
Tushnim Bhattacharyya0c4ad2d2017-03-09 15:59:03 -08005372 status = policy_mgr_get_pcl(mac_ctx->psoc, new_mode,
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305373 filter->pcl_channel_list, &len,
Abhishek Singhb58164a2017-07-19 18:47:23 +05305374 filter->pcl_weight_list, QDF_MAX_NUM_CHAN);
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305375 filter->num_of_pcl_channels = (uint8_t)len;
5376 }
5377 }
Abhishek Singhb58164a2017-07-19 18:47:23 +05305378 qdf_mem_copy(filter->bssid_hint.bytes,
5379 pFilter->bssid_hint.bytes,
5380 QDF_MAC_ADDR_SIZE);
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305381
5382 return QDF_STATUS_SUCCESS;
5383}
5384
Sridhar Selvaraja44c19e2017-08-21 14:20:20 +05305385#ifdef WLAN_FEATURE_FILS_SK
5386/**
5387 * csr_update_bss_with_fils_data: Fill FILS params in bss desc from scan entry
5388 * @mac_ctx: mac context
5389 * @scan_entry: scan entry
5390 * @bss_descr: bss description
5391 */
5392static void csr_update_bss_with_fils_data(tpAniSirGlobal mac_ctx,
5393 struct scan_cache_entry *scan_entry,
5394 tSirBssDescription *bss_descr)
5395{
Krunal Soni35a94532018-01-09 10:54:31 -08005396 tDot11fIEfils_indication fils_indication = {0};
Sridhar Selvaraja44c19e2017-08-21 14:20:20 +05305397 struct sir_fils_indication fils_ind;
5398
5399 if (!scan_entry->ie_list.fils_indication)
5400 return;
5401
5402 dot11f_unpack_ie_fils_indication(mac_ctx,
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05305403 scan_entry->ie_list.fils_indication +
5404 SIR_FILS_IND_ELEM_OFFSET,
Sridhar Selvaraja44c19e2017-08-21 14:20:20 +05305405 *(scan_entry->ie_list.fils_indication + 1),
5406 &fils_indication, false);
5407
5408 update_fils_data(&fils_ind, &fils_indication);
5409 if (fils_ind.realm_identifier.realm_cnt > SIR_MAX_REALM_COUNT)
5410 fils_ind.realm_identifier.realm_cnt = SIR_MAX_REALM_COUNT;
5411
5412 bss_descr->fils_info_element.realm_cnt =
5413 fils_ind.realm_identifier.realm_cnt;
5414 qdf_mem_copy(bss_descr->fils_info_element.realm,
5415 fils_ind.realm_identifier.realm,
5416 bss_descr->fils_info_element.realm_cnt * SIR_REALM_LEN);
5417 if (fils_ind.cache_identifier.is_present) {
5418 bss_descr->fils_info_element.is_cache_id_present = true;
5419 qdf_mem_copy(bss_descr->fils_info_element.cache_id,
5420 fils_ind.cache_identifier.identifier, CACHE_ID_LEN);
5421 }
5422 if (fils_ind.is_fils_sk_auth_supported)
5423 bss_descr->fils_info_element.is_fils_sk_supported = true;
5424}
5425#else
5426static void csr_update_bss_with_fils_data(tpAniSirGlobal mac_ctx,
5427 struct scan_cache_entry *scan_entry,
5428 tSirBssDescription *bss_descr)
5429{ }
5430#endif
5431
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305432static QDF_STATUS csr_fill_bss_from_scan_entry(tpAniSirGlobal mac_ctx,
5433 struct scan_cache_entry *scan_entry,
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05305434 struct tag_csrscan_result **p_result)
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305435{
5436 tDot11fBeaconIEs *bcn_ies;
5437 tSirBssDescription *bss_desc;
5438 tCsrScanResultInfo *result_info;
5439 tpSirMacMgmtHdr hdr;
5440 uint8_t *ie_ptr;
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05305441 struct tag_csrscan_result *bss;
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305442 uint32_t bss_len, alloc_len, ie_len;
5443 QDF_STATUS status;
5444
5445 ie_len = util_scan_entry_ie_len(scan_entry);
5446 ie_ptr = util_scan_entry_ie_data(scan_entry);
5447
5448 hdr = (tpSirMacMgmtHdr)scan_entry->raw_frame.ptr;
5449
5450 bss_len = (uint16_t)(offsetof(tSirBssDescription,
5451 ieFields[0]) + ie_len);
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05305452 alloc_len = sizeof(struct tag_csrscan_result) + bss_len;
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305453 bss = qdf_mem_malloc(alloc_len);
5454
5455 if (!bss) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07005456 sme_err("could not allocate bss");
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305457 return QDF_STATUS_E_NOMEM;
5458 }
5459
5460 bss->AgingCount =
5461 (int32_t) mac_ctx->roam.configParam.agingCount;
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305462 bss->ucEncryptionType =
5463 csr_covert_enc_type_old(scan_entry->neg_sec_info.uc_enc);
5464 bss->mcEncryptionType =
5465 csr_covert_enc_type_old(scan_entry->neg_sec_info.mc_enc);
5466 bss->authType =
5467 csr_covert_auth_type_old(scan_entry->neg_sec_info.auth_type);
Abhishek Singhb58164a2017-07-19 18:47:23 +05305468 bss->bss_score = scan_entry->bss_score;
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305469
5470 result_info = &bss->Result;
5471 result_info->ssId.length = scan_entry->ssid.length;
5472 qdf_mem_copy(result_info->ssId.ssId,
5473 scan_entry->ssid.ssid,
5474 result_info->ssId.length);
5475 result_info->timer = scan_entry->hidden_ssid_timestamp;
5476
5477 bss_desc = &result_info->BssDescriptor;
5478
5479 bss_desc->length = (uint16_t) (offsetof(tSirBssDescription,
5480 ieFields[0]) - sizeof(bss_desc->length) + ie_len);
5481
5482 qdf_mem_copy(bss_desc->bssId,
5483 scan_entry->bssid.bytes,
5484 QDF_MAC_ADDR_SIZE);
Sandeep Puligilla1fcdb772017-02-22 21:14:59 -08005485 bss_desc->scansystimensec = scan_entry->scan_entry_time;
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305486 qdf_mem_copy(bss_desc->timeStamp,
5487 scan_entry->tsf_info.data, 8);
5488
5489 bss_desc->beaconInterval = scan_entry->bcn_int;
5490 bss_desc->capabilityInfo = scan_entry->cap_info.value;
5491
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07005492 if (WLAN_REG_IS_5GHZ_CH(scan_entry->channel.chan_idx))
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305493 bss_desc->nwType = eSIR_11A_NW_TYPE;
5494 else if (scan_entry->phy_mode == WLAN_PHYMODE_11B)
5495 bss_desc->nwType = eSIR_11B_NW_TYPE;
5496 else
5497 bss_desc->nwType = eSIR_11G_NW_TYPE;
5498
5499 bss_desc->rssi = scan_entry->rssi_raw;
5500 bss_desc->rssi_raw = scan_entry->rssi_raw;
5501
5502 /* channelId what peer sent in beacon/probersp. */
5503 bss_desc->channelId =
5504 scan_entry->channel.chan_idx;
5505 /* channelId on which we are parked at. */
5506 /* used only in scan case. */
5507 bss_desc->channelIdSelf =
5508 scan_entry->channel.chan_idx;
5509 bss_desc->rx_channel = bss_desc->channelIdSelf;
5510 bss_desc->received_time =
5511 scan_entry->scan_entry_time;
5512 bss_desc->startTSF[0] =
5513 mac_ctx->rrm.rrmPEContext.startTSF[0];
5514 bss_desc->startTSF[1] =
5515 mac_ctx->rrm.rrmPEContext.startTSF[1];
5516 bss_desc->parentTSF =
5517 scan_entry->rrm_parent_tsf;
5518 bss_desc->fProbeRsp = (scan_entry->frm_subtype ==
5519 IEEE80211_FC0_SUBTYPE_PROBE_RESP);
5520 bss_desc->seq_ctrl = hdr->seqControl;
5521 bss_desc->tsf_delta = scan_entry->tsf_delta;
5522
5523 qdf_mem_copy((uint8_t *) &bss_desc->ieFields,
5524 ie_ptr, ie_len);
5525
5526 status = csr_get_parsed_bss_description_ies(mac_ctx,
5527 bss_desc, &bcn_ies);
5528 if (QDF_IS_STATUS_ERROR(status)) {
5529 qdf_mem_free(bss);
5530 return status;
5531 }
5532 result_info->pvIes = bcn_ies;
5533
5534 if (bcn_ies->MobilityDomain.present) {
5535 bss_desc->mdiePresent = true;
5536 qdf_mem_copy((uint8_t *)&(bss_desc->mdie[0]),
5537 (uint8_t *)&(bcn_ies->MobilityDomain.MDID),
5538 sizeof(uint16_t));
5539 bss_desc->mdie[2] =
5540 ((bcn_ies->MobilityDomain.overDSCap << 0) |
5541 (bcn_ies->MobilityDomain.resourceReqCap << 1));
5542 }
5543#ifdef FEATURE_WLAN_ESE
5544 if (bcn_ies->QBSSLoad.present) {
5545 bss_desc->QBSSLoad_present = true;
5546 bss_desc->QBSSLoad_avail =
5547 bcn_ies->QBSSLoad.avail;
5548 }
5549#endif
Sridhar Selvaraja44c19e2017-08-21 14:20:20 +05305550 csr_update_bss_with_fils_data(mac_ctx, scan_entry, bss_desc);
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305551 if (scan_entry->alt_wcn_ie.ptr) {
5552 bss_desc->WscIeLen = scan_entry->alt_wcn_ie.len;
5553 qdf_mem_copy(bss_desc->WscIeProbeRsp,
5554 scan_entry->alt_wcn_ie.ptr,
5555 scan_entry->alt_wcn_ie.len);
5556 }
5557
5558 *p_result = bss;
5559 return QDF_STATUS_SUCCESS;
5560}
5561
5562static QDF_STATUS csr_parse_scan_list(tpAniSirGlobal mac_ctx,
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05305563 struct scan_result_list *ret_list,
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305564 qdf_list_t *scan_list)
5565{
5566 QDF_STATUS status = QDF_STATUS_SUCCESS;
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05305567 struct tag_csrscan_result *pResult = NULL;
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305568 struct scan_cache_node *cur_node = NULL;
5569 struct scan_cache_node *next_node = NULL;
5570
5571 status =
5572 qdf_list_peek_front(scan_list,
5573 (qdf_list_node_t **) &cur_node);
5574
5575 while (cur_node) {
5576 qdf_list_peek_next(
5577 scan_list,
5578 (qdf_list_node_t *) cur_node,
5579 (qdf_list_node_t **) &next_node);
5580 status = csr_fill_bss_from_scan_entry(mac_ctx,
5581 cur_node->entry, &pResult);
5582 if (QDF_IS_STATUS_ERROR(status))
5583 return status;
5584 if (pResult)
5585 csr_ll_insert_tail(&ret_list->List, &pResult->Link,
5586 LL_ACCESS_NOLOCK);
5587 cur_node = next_node;
5588 next_node = NULL;
5589 }
5590
5591 return status;
5592}
Abhishek Singhf3756fc2017-06-28 16:04:06 +05305593
5594/**
5595 * csr_remove_ap_due_to_rssi() - check if bss is present in
5596 * list of BSSID which rejected Assoc due to RSSI
5597 * @list: rssi based rejected BSS list
5598 * @bss_descr: pointer to bss description
5599 *
5600 * Check if the time interval indicated in last Assoc reject
5601 * has expired OR rssi has improved by margin indicated
5602 * in last Assoc reject. If any of the condition match remove
5603 * the AP from the avoid list, else do not try to conenct
5604 * to the AP
5605 *
5606 * Return: true if connection cannot be tried with AP else false
5607 */
5608static bool csr_remove_ap_due_to_rssi(qdf_list_t *list,
5609 tSirBssDescription *bss_descr)
5610{
5611 QDF_STATUS status;
5612 struct sir_rssi_disallow_lst *cur_node = NULL;
5613 qdf_list_node_t *cur_lst = NULL, *next_lst = NULL;
5614 qdf_time_t cur_time;
5615 uint32_t time_diff;
5616
5617 if (!qdf_list_size(list))
5618 return false;
5619
5620 cur_time = qdf_do_div(qdf_get_monotonic_boottime(),
5621 QDF_MC_TIMER_TO_MS_UNIT);
5622
5623 qdf_list_peek_front(list, &cur_lst);
5624 while (cur_lst) {
5625 cur_node = qdf_container_of(cur_lst,
5626 struct sir_rssi_disallow_lst, node);
5627
5628 qdf_list_peek_next(list, cur_lst, &next_lst);
5629
5630 time_diff = cur_time - cur_node->time_during_rejection;
5631 if ((time_diff > cur_node->retry_delay)) {
5632 sme_debug("Remove %pM as time diff %d is greater retry delay %d",
5633 cur_node->bssid.bytes, time_diff,
5634 cur_node->retry_delay);
5635 status = qdf_list_remove_node(list, cur_lst);
5636 if (QDF_IS_STATUS_SUCCESS(status))
5637 qdf_mem_free(cur_node);
5638 cur_lst = next_lst;
5639 next_lst = NULL;
5640 cur_node = NULL;
5641 continue;
5642 }
5643
5644 if (!qdf_mem_cmp(cur_node->bssid.bytes,
5645 bss_descr->bssId, QDF_MAC_ADDR_SIZE))
5646 break;
5647 cur_lst = next_lst;
5648 next_lst = NULL;
5649 cur_node = NULL;
5650 }
5651
5652 if (cur_node) {
5653 time_diff = cur_time - cur_node->time_during_rejection;
5654 if (!(time_diff > cur_node->retry_delay ||
5655 bss_descr->rssi_raw >= cur_node->expected_rssi)) {
5656 sme_err("Don't Attempt to connect %pM (time diff %d retry delay %d rssi %d expected rssi %d)",
5657 cur_node->bssid.bytes, time_diff,
5658 cur_node->retry_delay, bss_descr->rssi_raw,
5659 cur_node->expected_rssi);
5660 return true;
5661 }
5662 sme_debug("Remove %pM as time diff %d is greater retry delay %d or RSSI %d is greater than expected %d",
5663 cur_node->bssid.bytes, time_diff,
5664 cur_node->retry_delay,
5665 bss_descr->rssi_raw,
5666 cur_node->expected_rssi);
5667 status = qdf_list_remove_node(list, cur_lst);
5668 if (QDF_IS_STATUS_SUCCESS(status))
5669 qdf_mem_free(cur_node);
5670 }
5671
5672 return false;
5673}
5674
5675/**
5676 * csr_filter_ap_due_to_rssi_reject() - filter the AP who has sent
5677 * assoc reject due to RSSI if condition has not improved
5678 * @mac_ctx: mac context
5679 * @scan_list: candidate list for the connection
5680 *
5681 * Return: void
5682 */
5683static void csr_filter_ap_due_to_rssi_reject(tpAniSirGlobal mac_ctx,
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05305684 struct scan_result_list *scan_list)
Abhishek Singhf3756fc2017-06-28 16:04:06 +05305685{
5686 tListElem *cur_entry;
5687 tListElem *next_entry;
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05305688 struct tag_csrscan_result *scan_res;
Abhishek Singhf3756fc2017-06-28 16:04:06 +05305689 bool remove;
5690
5691 if (!scan_list ||
5692 !qdf_list_size(&mac_ctx->roam.rssi_disallow_bssid))
5693 return;
5694
5695 csr_ll_lock(&scan_list->List);
5696
5697 cur_entry = csr_ll_peek_head(&scan_list->List, LL_ACCESS_NOLOCK);
5698 while (cur_entry) {
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05305699 scan_res = GET_BASE_ADDR(cur_entry, struct tag_csrscan_result,
Abhishek Singhf3756fc2017-06-28 16:04:06 +05305700 Link);
5701 next_entry = csr_ll_next(&scan_list->List,
5702 cur_entry, LL_ACCESS_NOLOCK);
5703 remove = csr_remove_ap_due_to_rssi(
5704 &mac_ctx->roam.rssi_disallow_bssid,
5705 &scan_res->Result.BssDescriptor);
5706 if (remove) {
5707 csr_ll_remove_entry(&scan_list->List,
5708 cur_entry, LL_ACCESS_NOLOCK);
5709 csr_free_scan_result_entry(mac_ctx, scan_res);
5710 }
5711 cur_entry = next_entry;
5712 next_entry = NULL;
5713 }
5714 csr_ll_unlock(&scan_list->List);
5715
5716}
5717
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305718QDF_STATUS csr_scan_get_result(tpAniSirGlobal mac_ctx,
5719 tCsrScanResultFilter *pFilter,
5720 tScanResultHandle *results)
5721{
5722 QDF_STATUS status;
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05305723 struct scan_result_list *ret_list = NULL;
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305724 qdf_list_t *list = NULL;
5725 struct scan_filter filter = {0};
5726 struct wlan_objmgr_pdev *pdev = NULL;
5727
5728 if (results)
5729 *results = CSR_INVALID_SCANRESULT_HANDLE;
5730
5731 pdev = wlan_objmgr_get_pdev_by_id(mac_ctx->psoc,
5732 0, WLAN_LEGACY_MAC_ID);
5733
5734 if (!pdev) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07005735 sme_err("pdev is NULL");
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305736 return QDF_STATUS_E_INVAL;
5737 }
5738
5739 if (pFilter) {
5740 status = csr_prepare_scan_filter(mac_ctx, pFilter, &filter);
5741 if (QDF_IS_STATUS_ERROR(status)) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07005742 sme_err("Prepare filter failed");
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305743 goto error;
5744 }
5745 }
5746
5747 list = ucfg_scan_get_result(pdev,
5748 pFilter ? &filter : NULL);
Krunal Soni35a94532018-01-09 10:54:31 -08005749 if (list)
5750 sme_debug("num_entries %d", qdf_list_size(list));
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305751
Krunal Soni35a94532018-01-09 10:54:31 -08005752 if (!list || (list && !qdf_list_size(list))) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07005753 sme_err("get scan result failed");
Abhishek Singhd1d10b42017-06-07 16:12:01 +05305754 status = QDF_STATUS_E_NULL_VALUE;
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305755 goto error;
5756 }
5757
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05305758 ret_list = qdf_mem_malloc(sizeof(struct scan_result_list));
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305759 if (!ret_list) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07005760 sme_err("pRetList is NULL");
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305761 status = QDF_STATUS_E_NOMEM;
5762 goto error;
5763 }
5764
5765 csr_ll_open(mac_ctx->hHdd, &ret_list->List);
5766 ret_list->pCurEntry = NULL;
5767 status = csr_parse_scan_list(mac_ctx,
5768 ret_list, list);
Vignesh Viswanathan9dd88d32017-11-22 14:22:03 +05305769 sme_debug("status: %d No of BSS: %d",
5770 status, csr_ll_count(&ret_list->List));
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305771 if (QDF_IS_STATUS_ERROR(status) || !results)
5772 /* Fail or No one wants the result. */
5773 csr_scan_result_purge(mac_ctx, (tScanResultHandle) ret_list);
5774 else {
Abhishek Singhf3756fc2017-06-28 16:04:06 +05305775 if (pFilter)
5776 csr_filter_ap_due_to_rssi_reject(mac_ctx, ret_list);
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305777 if (!csr_ll_count(&ret_list->List)) {
5778 /* This mean that there is no match */
5779 csr_ll_close(&ret_list->List);
5780 qdf_mem_free(ret_list);
5781 status = QDF_STATUS_E_NULL_VALUE;
5782 } else if (results) {
5783 *results = ret_list;
5784 }
5785 }
5786
5787error:
5788 if (list)
5789 ucfg_scan_purge_results(list);
5790 if (pdev)
5791 wlan_objmgr_pdev_release_ref(pdev, WLAN_LEGACY_MAC_ID);
5792
5793 return status;
5794}
5795
Vignesh Viswanathan9dd88d32017-11-22 14:22:03 +05305796QDF_STATUS csr_scan_get_result_for_bssid(tpAniSirGlobal mac_ctx,
5797 struct qdf_mac_addr *bssid,
5798 tCsrScanResultInfo *res)
5799{
5800 QDF_STATUS status = QDF_STATUS_E_FAILURE;
5801 tCsrScanResultFilter *scan_filter = NULL;
5802 tScanResultHandle filtered_scan_result = NULL;
5803 tCsrScanResultInfo *scan_result;
5804
5805 if (!mac_ctx) {
5806 QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_ERROR,
5807 FL("mac_ctx is NULL"));
5808 return QDF_STATUS_E_FAILURE;
5809 }
5810
5811 scan_filter = qdf_mem_malloc(sizeof(tCsrScanResultFilter));
5812 if (!scan_filter) {
5813 sme_err("Failed to allocated memory for scan_filter");
5814 return QDF_STATUS_E_NOMEM;
5815 }
5816
Krunal Soni3fa80e22018-01-09 14:16:02 -08005817 scan_filter->BSSIDs.bssid = qdf_mem_malloc(sizeof(*bssid));
Vignesh Viswanathan9dd88d32017-11-22 14:22:03 +05305818 if (!scan_filter->BSSIDs.bssid) {
5819 sme_err("Failed to allocate memory for BSSIDs");
5820 status = QDF_STATUS_E_FAILURE;
5821 goto free_filter;
5822 }
5823
5824 scan_filter->BSSIDs.numOfBSSIDs = 1;
Krunal Soni3fa80e22018-01-09 14:16:02 -08005825 qdf_mem_copy(scan_filter->BSSIDs.bssid, bssid, sizeof(*bssid));
Vignesh Viswanathan9dd88d32017-11-22 14:22:03 +05305826
5827 status = csr_scan_get_result(mac_ctx, scan_filter,
5828 &filtered_scan_result);
5829
5830 if (!QDF_IS_STATUS_SUCCESS(status)) {
5831 sme_err("Failed to get scan result");
5832 goto free_filter;
5833 }
5834
5835 scan_result = csr_scan_result_get_first(mac_ctx, filtered_scan_result);
5836
5837 if (scan_result) {
5838 res->pvIes = NULL;
5839 res->ssId.length = scan_result->ssId.length;
5840 qdf_mem_copy(&res->ssId.ssId, &scan_result->ssId.ssId,
5841 res->ssId.length);
5842 res->timer = scan_result->timer;
5843 qdf_mem_copy(&res->BssDescriptor, &scan_result->BssDescriptor,
5844 sizeof(tSirBssDescription));
5845 status = QDF_STATUS_SUCCESS;
5846 } else {
5847 status = QDF_STATUS_E_FAILURE;
5848 }
5849
5850 csr_scan_result_purge(mac_ctx, filtered_scan_result);
5851
5852free_filter:
5853 csr_free_scan_filter(mac_ctx, scan_filter);
5854 if (scan_filter)
5855 qdf_mem_free(scan_filter);
5856
5857 return status;
5858}
5859
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305860static inline QDF_STATUS
5861csr_flush_scan_results(tpAniSirGlobal mac_ctx,
5862 struct scan_filter *filter)
5863{
5864 struct wlan_objmgr_pdev *pdev = NULL;
5865 QDF_STATUS status;
5866
5867 pdev = wlan_objmgr_get_pdev_by_id(mac_ctx->psoc,
5868 0, WLAN_LEGACY_MAC_ID);
5869 if (!pdev) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07005870 sme_err("pdev is NULL");
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305871 return QDF_STATUS_E_INVAL;
5872 }
5873 status = ucfg_scan_flush_results(pdev, filter);
5874
5875 wlan_objmgr_pdev_release_ref(pdev, WLAN_LEGACY_MAC_ID);
5876 return status;
5877}
5878
5879QDF_STATUS csr_scan_flush_result(tpAniSirGlobal mac_ctx)
5880{
5881
5882 if (csr_scan_flush_denied(mac_ctx)) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07005883 sme_err("scan flush denied in roam state");
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305884 return QDF_STATUS_E_FAILURE;
5885 }
5886
5887 return csr_flush_scan_results(mac_ctx, NULL);
5888}
5889
5890QDF_STATUS csr_scan_flush_selective_result(tpAniSirGlobal mac_ctx,
5891 bool flush_p2p)
5892{
5893 struct scan_filter filter = {0};
5894
5895 filter.p2p_results = flush_p2p;
5896 return csr_flush_scan_results(mac_ctx, &filter);
5897}
5898
5899static inline void csr_flush_bssid(tpAniSirGlobal mac_ctx,
5900 uint8_t *bssid)
5901{
5902 struct scan_filter filter = {0};
5903
5904 filter.num_of_bssid = 1;
5905 qdf_mem_copy(filter.bssid_list[0].bytes,
5906 bssid, QDF_MAC_ADDR_SIZE);
5907
5908 csr_flush_scan_results(mac_ctx, &filter);
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07005909 sme_debug("Removed BSS entry:%pM", bssid);
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305910}
5911
5912void csr_scan_flush_bss_entry(tpAniSirGlobal mac_ctx,
5913 tpSmeCsaOffloadInd csa_off_ind)
5914{
5915 csr_flush_bssid(mac_ctx,
5916 csa_off_ind->bssid.bytes);
5917}
5918
5919void csr_remove_bssid_from_scan_list(tpAniSirGlobal mac_ctx,
5920 tSirMacAddr bssid)
5921{
5922 csr_flush_bssid(mac_ctx, bssid);
5923}
5924
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305925QDF_STATUS csr_scan_process_single_bssdescr(tpAniSirGlobal mac_ctx,
5926 tSirBssDescription *bssdescr,
5927 uint32_t scan_id, uint32_t flags)
5928{
5929 /* Not needed now as scan module handle this*/
5930 return QDF_STATUS_SUCCESS;
5931}
5932
5933void csr_init_occupied_channels_list(tpAniSirGlobal mac_ctx,
5934 uint8_t sessionId)
5935{
5936 tScanResultHandle results;
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05305937 struct scan_result_list *scan_list = NULL;
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305938 QDF_STATUS status = QDF_STATUS_SUCCESS;
5939 tListElem *scan_entry = NULL;
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05305940 struct tag_csrscan_result *bss_desc = NULL;
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305941 tDot11fBeaconIEs *ie_ptr = NULL;
5942 tpCsrNeighborRoamControlInfo neighbor_roam_info =
5943 &mac_ctx->roam.neighborRoamInfo[sessionId];
5944
5945 if (neighbor_roam_info->cfgParams.channelInfo.numOfChannels) {
5946 /*
5947 * Ini file contains neighbor scan channel list, hence NO need
5948 * to build occupied channel list"
5949 */
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07005950 sme_debug("Ini contains neighbor scan ch list");
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305951 return;
5952 }
5953
5954 if (!csr_neighbor_roam_is_new_connected_profile(mac_ctx, sessionId)) {
5955 /*
5956 * Do not flush occupied list since current roam profile matches
5957 * previous
5958 */
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07005959 sme_debug("Current roam profile matches prev");
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305960 return;
5961 }
5962
5963 /* Empty occupied channels here */
5964 mac_ctx->scan.occupiedChannels[sessionId].numChannels = 0;
5965 mac_ctx->scan.roam_candidate_count[sessionId] = 0;
5966
5967 status = csr_scan_get_result(mac_ctx, NULL, &results);
5968 if (!QDF_IS_STATUS_SUCCESS(status))
5969 return;
5970 scan_list = results;
5971 csr_ll_lock(&scan_list->List);
5972 scan_entry = csr_ll_peek_head(&scan_list->List, LL_ACCESS_NOLOCK);
5973 while (scan_entry) {
Yeshwanth Sriram Guntuka36c09902017-09-26 11:34:26 +05305974 bss_desc = GET_BASE_ADDR(scan_entry, struct tag_csrscan_result,
5975 Link);
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305976 ie_ptr = (tDot11fBeaconIEs *) (bss_desc->Result.pvIes);
5977 if (!ie_ptr && !QDF_IS_STATUS_SUCCESS(
5978 csr_get_parsed_bss_description_ies(mac_ctx,
Ravi Joshib228f092017-05-04 19:54:45 -07005979 &bss_desc->Result.BssDescriptor, &ie_ptr))) {
5980 /* Pick next bss entry before continuing */
5981 scan_entry = csr_ll_next(&scan_list->List, scan_entry,
5982 LL_ACCESS_NOLOCK);
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305983 continue;
Ravi Joshib228f092017-05-04 19:54:45 -07005984 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +05305985 csr_scan_add_to_occupied_channels(mac_ctx, bss_desc, sessionId,
5986 &mac_ctx->scan.occupiedChannels[sessionId], ie_ptr,
5987 true);
5988 /*
5989 * Free the memory allocated for pIes in
5990 * csr_get_parsed_bss_description_ies
5991 */
5992 if ((bss_desc->Result.pvIes == NULL) && ie_ptr)
5993 qdf_mem_free(ie_ptr);
5994 scan_entry = csr_ll_next(&scan_list->List, scan_entry,
5995 LL_ACCESS_NOLOCK);
5996 }
5997 csr_ll_unlock(&scan_list->List);
5998
5999 csr_scan_result_purge(mac_ctx, scan_list);
6000}
6001
6002/**
6003 * csr_scan_filter_results: filter scan result based
6004 * on valid channel list number.
6005 * @mac_ctx: mac context
6006 *
6007 * Get scan result from scan list and Check Scan result channel number
6008 * with 11d channel list if channel number is found in 11d channel list
6009 * then do not remove scan result entry from scan list
6010 *
6011 * return: QDF Status
6012 */
6013QDF_STATUS csr_scan_filter_results(tpAniSirGlobal mac_ctx)
6014{
6015 QDF_STATUS status = QDF_STATUS_SUCCESS;
6016 uint32_t len = sizeof(mac_ctx->roam.validChannelList);
6017 struct wlan_objmgr_pdev *pdev = NULL;
6018
6019 pdev = wlan_objmgr_get_pdev_by_id(mac_ctx->psoc,
6020 0, WLAN_LEGACY_MAC_ID);
6021 if (!pdev) {
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07006022 sme_err("pdev is NULL");
Abhishek Singh6092fbb2017-01-25 18:10:31 +05306023 return QDF_STATUS_E_INVAL;
6024 }
6025 status = csr_get_cfg_valid_channels(mac_ctx,
6026 mac_ctx->roam.validChannelList,
6027 &len);
6028
6029 /* Get valid channels list from CFG */
6030 if (QDF_IS_STATUS_ERROR(status)) {
6031 wlan_objmgr_pdev_release_ref(pdev, WLAN_LEGACY_MAC_ID);
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07006032 sme_err("Failed to get Channel list from CFG");
Abhishek Singh6092fbb2017-01-25 18:10:31 +05306033 return status;
6034 }
Srinivas Girigowdaa454cfb2017-03-17 11:17:28 -07006035 sme_debug("No of valid channel %d", len);
Abhishek Singh6092fbb2017-01-25 18:10:31 +05306036
6037 ucfg_scan_filter_valid_channel(pdev,
6038 mac_ctx->roam.validChannelList, len);
6039 wlan_objmgr_pdev_release_ref(pdev, WLAN_LEGACY_MAC_ID);
6040 return QDF_STATUS_SUCCESS;
6041}