blob: 4fe60957a55a28643b01299bba238aba089841b2 [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Padma, Santhosh Kumar0eeb7752018-07-04 18:52:27 +05302 * Copyright (c) 2011-2018 The Linux Foundation. All rights reserved.
Kiet Lam0fb93dd2014-02-19 00:32:59 -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.
Gopichand Nakkala92f07d82013-01-08 21:16:34 -080020 */
Kiet Lam0fb93dd2014-02-19 00:32:59 -080021
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
Jeff Johnson40b59aa2013-03-19 14:43:18 -070028/** ------------------------------------------------------------------------- *
29 ------------------------------------------------------------------------- *
Jeff Johnson295189b2012-06-20 16:38:30 -070030
Jeff Johnson40b59aa2013-03-19 14:43:18 -070031
Jeff Johnson295189b2012-06-20 16:38:30 -070032 \file csrApiScan.c
Jeff Johnson40b59aa2013-03-19 14:43:18 -070033
Jeff Johnson295189b2012-06-20 16:38:30 -070034 Implementation for the Common Scan interfaces.
Jeff Johnson295189b2012-06-20 16:38:30 -070035 ========================================================================== */
36
37#include "aniGlobal.h"
38
39#include "palApi.h"
40#include "csrInsideApi.h"
41#include "smeInside.h"
42#include "smsDebug.h"
43
44#include "csrSupport.h"
45#include "wlan_qct_tl.h"
46
47#include "vos_diag_core_log.h"
48#include "vos_diag_core_event.h"
49
50#include "vos_nvitem.h"
Rajesh Babu Prathipati20cdffa2014-07-01 22:24:59 +053051#include "vos_memory.h"
Jeff Johnson295189b2012-06-20 16:38:30 -070052#include "wlan_qct_wda.h"
Abhishek Singhe3fa11f2014-05-13 11:11:10 +053053#include "vos_utils.h"
Jeff Johnson40b59aa2013-03-19 14:43:18 -070054
Kiet Lamd1f3dc82013-11-05 20:45:04 +053055#define MIN_CHN_TIME_TO_FIND_GO 100
56#define MAX_CHN_TIME_TO_FIND_GO 100
57#define DIRECT_SSID_LEN 7
Jeff Johnson295189b2012-06-20 16:38:30 -070058
Jeff Johnson295189b2012-06-20 16:38:30 -070059
60/* Purpose of HIDDEN_TIMER
61** When we remove hidden ssid from the profile i.e., forget the SSID via GUI that SSID shouldn't see in the profile
62** For above requirement we used timer limit, logic is explained below
63** Timer value is initialsed to current time when it receives corresponding probe response of hidden SSID (The probe request is
64** received regularly till SSID in the profile. Once it is removed from profile probe request is not sent.) when we receive probe response
65** for broadcast probe request, during update SSID with saved SSID we will diff current time with saved SSID time if it is greater than 1 min
66** then we are not updating with old one
67*/
68
69#define HIDDEN_TIMER (1*60*1000)
70#define CSR_SCAN_RESULT_RSSI_WEIGHT 80 // must be less than 100, represent the persentage of new RSSI
71
72/*---------------------------------------------------------------------------
73 PER filter constant fraction: it is a %
74---------------------------------------------------------------------------*/
75#define CSR_SCAN_PER_FILTER_FRAC 100
76
77/*---------------------------------------------------------------------------
78 RSSI filter constant fraction: it is a %
79---------------------------------------------------------------------------*/
80#define CSR_SCAN_RSSI_FILTER_FRAC 100
81
82/*---------------------------------------------------------------------------
83Convert RSSI into overall score: Since RSSI is in -dBm values, and the
84overall needs to be weighted inversely (where greater value means better
85system), we convert.
86RSSI *cannot* be more than 0xFF or less than 0 for meaningful WLAN operation
87---------------------------------------------------------------------------*/
88#define CSR_SCAN_MAX_SCORE_VAL 0xFF
89#define CSR_SCAN_MIN_SCORE_VAL 0x0
90#define CSR_SCAN_HANDOFF_DELTA 10
Abhishek Singh5deecd12017-06-12 11:08:40 +053091
92#define CSR_PURGE_RSSI_THRESHOLD -70
93
Jeff Johnson32d95a32012-09-10 13:15:23 -070094#define MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL 140
95#define MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL 120
Selvaraj, Sridhar32417ed2016-06-22 15:19:12 +053096
97#ifndef QCA_WIFI_ISOC
98#define MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL_FASTREASSOC 30
99#define MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL_FASTREASSOC 20
100#endif
101
Madan Mohan Koyyalamudia53c4dc2012-11-13 10:35:42 -0800102#define CSR_SCAN_OVERALL_SCORE( rssi ) \
103 (( rssi < CSR_SCAN_MAX_SCORE_VAL ) \
104 ? (CSR_SCAN_MAX_SCORE_VAL-rssi) : CSR_SCAN_MIN_SCORE_VAL)
Jeff Johnson295189b2012-06-20 16:38:30 -0700105
106
107#define CSR_SCAN_IS_OVER_BSS_LIMIT(pMac) \
108 ( (pMac)->scan.nBssLimit <= (csrLLCount(&(pMac)->scan.scanResultList)) )
109
Sushant Kaushikf4e085e2014-06-17 16:07:33 +0530110#define THIRTY_PERCENT(x) (x*30/100);
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +0530111
krunal soni5f112f02013-11-25 15:00:11 -0800112#define MANDATORY_BG_CHANNEL 11
113
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -0800114#ifndef CONFIG_ENABLE_LINUX_REG
Sushant Kaushikf4e085e2014-06-17 16:07:33 +0530115tCsrIgnoreChannels countryIgnoreList[MAX_COUNTRY_IGNORE] = {
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +0530116 { {'U','A'}, { 136, 140}, 2},
117 { {'T','W'}, { 36, 40, 44, 48, 52}, 5},
Madan Mohan Koyyalamudi28dd0422013-08-12 15:06:21 +0530118 { {'I','D'}, { 165}, 1 },
Wilson Yange3d2b292013-10-09 00:35:43 -0700119 { {'A','U'}, { 120, 124, 128}, 3 },
Wilson Yangce31eaf2013-11-11 14:40:34 -0800120 { {'A','R'}, { 120, 124, 128}, 3 }
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +0530121 };
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -0800122#else
Sushant Kaushikf4e085e2014-06-17 16:07:33 +0530123tCsrIgnoreChannels countryIgnoreList[MAX_COUNTRY_IGNORE] = { };
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -0800124#endif //CONFIG_ENABLE_LINUX_REG
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +0530125
Jeff Johnson295189b2012-06-20 16:38:30 -0700126//*** This is temporary work around. It need to call CCM api to get to CFG later
127/// Get string parameter value
128extern tSirRetStatus wlan_cfgGetStr(tpAniSirGlobal, tANI_U16, tANI_U8*, tANI_U32*);
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +0530129
Jeff Johnson295189b2012-06-20 16:38:30 -0700130void csrScanGetResultTimerHandler(void *);
Padma, Santhosh Kumar36183352016-11-08 17:48:34 +0530131void csr_handle_disable_scan(void *pv);
Deepthi Gowri6a08e312016-03-31 19:10:14 +0530132static void csrPurgeScanResultByAge(void *pv);
Jeff Johnson295189b2012-06-20 16:38:30 -0700133void csrScanIdleScanTimerHandler(void *);
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700134static void csrSetDefaultScanTiming( tpAniSirGlobal pMac, tSirScanType scanType, tCsrScanRequest *pScanRequest);
Jeff Johnson295189b2012-06-20 16:38:30 -0700135#ifdef WLAN_AP_STA_CONCURRENCY
136static void csrStaApConcTimerHandler(void *);
137#endif
Jeff Johnsone7245742012-09-05 17:12:55 -0700138tANI_BOOLEAN csrIsSupportedChannel(tpAniSirGlobal pMac, tANI_U8 channelId);
Jeff Johnson295189b2012-06-20 16:38:30 -0700139eHalStatus csrScanChannels( tpAniSirGlobal pMac, tSmeCmd *pCommand );
140void csrSetCfgValidChannelList( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels );
141void csrSaveTxPowerToCfg( tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 cfgId );
142void csrSetCfgCountryCode( tpAniSirGlobal pMac, tANI_U8 *countryCode );
143void csrPurgeChannelPower( tpAniSirGlobal pMac, tDblLinkList *pChannelList );
144//if bgPeriod is 0, background scan is disabled. It is in millisecond units
145eHalStatus csrSetCfgBackgroundScanPeriod(tpAniSirGlobal pMac, tANI_U32 bgPeriod);
146eHalStatus csrProcessSetBGScanParam(tpAniSirGlobal pMac, tSmeCmd *pCommand);
147void csrReleaseScanCommand(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus);
148static tANI_BOOLEAN csrScanValidateScanResult( tpAniSirGlobal pMac, tANI_U8 *pChannels,
149 tANI_U8 numChn, tSirBssDescription *pBssDesc,
150 tDot11fBeaconIEs **ppIes );
151eHalStatus csrSetBGScanChannelList( tpAniSirGlobal pMac, tANI_U8 *pAdjustChannels, tANI_U8 NumAdjustChannels);
152void csrReleaseCmdSingle(tpAniSirGlobal pMac, tSmeCmd *pCommand);
153tANI_BOOLEAN csrRoamIsValidChannel( tpAniSirGlobal pMac, tANI_U8 channel );
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700154void csrPruneChannelListForMode( tpAniSirGlobal pMac, tCsrChannel *pChannelList );
Abhishek Singh5deecd12017-06-12 11:08:40 +0530155void csrPurgeScanResults(tpAniSirGlobal pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -0700156
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -0700157
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -0700158
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -0700159
Madan Mohan Koyyalamudi923c1e12012-11-30 17:53:27 -0800160static void csrReleaseScanCmdPendingList(tpAniSirGlobal pMac)
161{
162 tListElem *pEntry;
163 tSmeCmd *pCommand;
164
165 while((pEntry = csrLLRemoveHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK)) != NULL)
166 {
167 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
168 if ( eSmeCsrCommandMask & pCommand->command )
169 {
170 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_TRUE );
171 }
172 else
173 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800174 smsLog(pMac, LOGE, FL("Error: Received command : %d"),pCommand->command);
Madan Mohan Koyyalamudi923c1e12012-11-30 17:53:27 -0800175 }
176 }
177}
Jeff Johnson295189b2012-06-20 16:38:30 -0700178//pResult is invalid calling this function.
179void csrFreeScanResultEntry( tpAniSirGlobal pMac, tCsrScanResult *pResult )
180{
181 if( NULL != pResult->Result.pvIes )
182 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530183 vos_mem_free(pResult->Result.pvIes);
Jeff Johnson295189b2012-06-20 16:38:30 -0700184 }
Kiet Lam64c1b492013-07-12 13:56:44 +0530185 vos_mem_free(pResult);
Jeff Johnson295189b2012-06-20 16:38:30 -0700186}
187
188
189static eHalStatus csrLLScanPurgeResult(tpAniSirGlobal pMac, tDblLinkList *pList)
190{
191 eHalStatus status = eHAL_STATUS_SUCCESS;
192 tListElem *pEntry;
193 tCsrScanResult *pBssDesc;
194
195 csrLLLock(pList);
196
197 while((pEntry = csrLLRemoveHead(pList, LL_ACCESS_NOLOCK)) != NULL)
198 {
199 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
200 csrFreeScanResultEntry( pMac, pBssDesc );
201 }
202
203 csrLLUnlock(pList);
204
205 return (status);
206}
207
Jeff Johnson295189b2012-06-20 16:38:30 -0700208eHalStatus csrScanOpen( tpAniSirGlobal pMac )
209{
210 eHalStatus status;
211
212 do
213 {
214 csrLLOpen(pMac->hHdd, &pMac->scan.scanResultList);
215 csrLLOpen(pMac->hHdd, &pMac->scan.tempScanResults);
216 csrLLOpen(pMac->hHdd, &pMac->scan.channelPowerInfoList24);
217 csrLLOpen(pMac->hHdd, &pMac->scan.channelPowerInfoList5G);
218#ifdef WLAN_AP_STA_CONCURRENCY
219 csrLLOpen(pMac->hHdd, &pMac->scan.scanCmdPendingList);
220#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700221 pMac->scan.fFullScanIssued = eANI_BOOLEAN_FALSE;
222 pMac->scan.nBssLimit = CSR_MAX_BSS_SUPPORT;
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530223 status = vos_timer_init(&pMac->scan.hTimerGetResult, VOS_TIMER_TYPE_SW, csrScanGetResultTimerHandler, pMac);
224 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700225 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800226 smsLog(pMac, LOGE, FL("cannot allocate memory for getResult timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700227 break;
228 }
229#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530230 status = vos_timer_init(&pMac->scan.hTimerStaApConcTimer, VOS_TIMER_TYPE_SW, csrStaApConcTimerHandler, pMac);
231 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700232 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800233 smsLog(pMac, LOGE, FL("cannot allocate memory for hTimerStaApConcTimer timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700234 break;
235 }
236#endif
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530237 status = vos_timer_init(&pMac->scan.hTimerIdleScan, VOS_TIMER_TYPE_SW, csrScanIdleScanTimerHandler, pMac);
238 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700239 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800240 smsLog(pMac, LOGE, FL("cannot allocate memory for idleScan timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700241 break;
242 }
Padma, Santhosh Kumar36183352016-11-08 17:48:34 +0530243 status = vos_timer_init(&pMac->scan.disable_scan_during_sco_timer,
244 VOS_TIMER_TYPE_SW,
245 csr_handle_disable_scan,
246 pMac);
247 if (!HAL_STATUS_SUCCESS(status)) {
248 smsLog(pMac, LOGE,
249 FL("cannot allocate memory for disable_scan_during_sco_timer"));
250 break;
251 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700252 }while(0);
253
254 return (status);
255}
256
257
258eHalStatus csrScanClose( tpAniSirGlobal pMac )
259{
Jeff Johnson295189b2012-06-20 16:38:30 -0700260 csrLLScanPurgeResult(pMac, &pMac->scan.tempScanResults);
261 csrLLScanPurgeResult(pMac, &pMac->scan.scanResultList);
262#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudi923c1e12012-11-30 17:53:27 -0800263 csrReleaseScanCmdPendingList(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -0700264#endif
265 csrLLClose(&pMac->scan.scanResultList);
266 csrLLClose(&pMac->scan.tempScanResults);
267#ifdef WLAN_AP_STA_CONCURRENCY
268 csrLLClose(&pMac->scan.scanCmdPendingList);
269#endif
270 csrPurgeChannelPower(pMac, &pMac->scan.channelPowerInfoList24);
271 csrPurgeChannelPower(pMac, &pMac->scan.channelPowerInfoList5G);
272 csrLLClose(&pMac->scan.channelPowerInfoList24);
273 csrLLClose(&pMac->scan.channelPowerInfoList5G);
274 csrScanDisable(pMac);
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530275 vos_timer_destroy(&pMac->scan.hTimerGetResult);
Jeff Johnson295189b2012-06-20 16:38:30 -0700276#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530277 vos_timer_destroy(&pMac->scan.hTimerStaApConcTimer);
Jeff Johnson295189b2012-06-20 16:38:30 -0700278#endif
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530279 vos_timer_destroy(&pMac->scan.hTimerIdleScan);
Padma, Santhosh Kumar36183352016-11-08 17:48:34 +0530280 vos_timer_destroy(&pMac->scan.disable_scan_during_sco_timer);
Jeff Johnson295189b2012-06-20 16:38:30 -0700281 return eHAL_STATUS_SUCCESS;
282}
283
284
285eHalStatus csrScanEnable( tpAniSirGlobal pMac )
286{
287
288 pMac->scan.fScanEnable = eANI_BOOLEAN_TRUE;
289 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
290
291 return eHAL_STATUS_SUCCESS;
292}
293
294
295eHalStatus csrScanDisable( tpAniSirGlobal pMac )
296{
297
298 csrScanStopTimers(pMac);
299 pMac->scan.fScanEnable = eANI_BOOLEAN_FALSE;
300
301 return eHAL_STATUS_SUCCESS;
302}
303
304
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700305//Set scan timing parameters according to state of other driver sessions
306//No validation of the parameters is performed.
307static void csrSetDefaultScanTiming( tpAniSirGlobal pMac, tSirScanType scanType, tCsrScanRequest *pScanRequest)
308{
309#ifdef WLAN_AP_STA_CONCURRENCY
310 if(csrIsAnySessionConnected(pMac))
311 {
Sushant Kaushika6fef4b2014-09-24 16:17:08 +0530312 //Reset passive scan time as per ini parameter.
Abhishek Singh7fb7dc12014-11-06 17:44:05 +0530313 ccmCfgSetInt(pMac, WNI_CFG_PASSIVE_MAXIMUM_CHANNEL_TIME,
Sushant Kaushika6fef4b2014-09-24 16:17:08 +0530314 pMac->roam.configParam.nPassiveMaxChnTimeConc,
315 NULL,eANI_BOOLEAN_FALSE);
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700316 //If multi-session, use the appropriate default scan times
317 if(scanType == eSIR_ACTIVE_SCAN)
318 {
319 pScanRequest->maxChnTime = pMac->roam.configParam.nActiveMaxChnTimeConc;
320 pScanRequest->minChnTime = pMac->roam.configParam.nActiveMinChnTimeConc;
321 }
322 else
323 {
324 pScanRequest->maxChnTime = pMac->roam.configParam.nPassiveMaxChnTimeConc;
325 pScanRequest->minChnTime = pMac->roam.configParam.nPassiveMinChnTimeConc;
326 }
Abhishek Singhadd13582016-09-29 17:00:03 +0530327 pScanRequest->max_chntime_btc_esco =
328 pMac->roam.configParam.max_chntime_btc_esco;
329 pScanRequest->min_chntime_btc_esco =
330 pMac->roam.configParam.min_chntime_btc_esco;
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700331
332 pScanRequest->restTime = pMac->roam.configParam.nRestTimeConc;
333
334 //Return so that fields set above will not be overwritten.
335 return;
336 }
337#endif
338
339 //This portion of the code executed if multi-session not supported
340 //(WLAN_AP_STA_CONCURRENCY not defined) or no multi-session.
341 //Use the "regular" (non-concurrency) default scan timing.
Abhishek Singh7fb7dc12014-11-06 17:44:05 +0530342 ccmCfgSetInt(pMac, WNI_CFG_PASSIVE_MAXIMUM_CHANNEL_TIME,
Kaushik, Sushant49758c12014-09-26 11:25:38 +0530343 pMac->roam.configParam.nPassiveMaxChnTime,
344 NULL,eANI_BOOLEAN_FALSE);
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700345 if(pScanRequest->scanType == eSIR_ACTIVE_SCAN)
346 {
347 pScanRequest->maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
348 pScanRequest->minChnTime = pMac->roam.configParam.nActiveMinChnTime;
349 }
350 else
351 {
352 pScanRequest->maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
353 pScanRequest->minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
354 }
Abhishek Singhadd13582016-09-29 17:00:03 +0530355 pScanRequest->max_chntime_btc_esco =
356 pMac->roam.configParam.max_chntime_btc_esco;
357 pScanRequest->min_chntime_btc_esco =
358 pMac->roam.configParam.min_chntime_btc_esco;
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700359
360#ifdef WLAN_AP_STA_CONCURRENCY
361 //No rest time if no sessions are connected.
362 pScanRequest->restTime = 0;
363#endif
364}
365
Jeff Johnson295189b2012-06-20 16:38:30 -0700366#ifdef WLAN_AP_STA_CONCURRENCY
367//Return SUCCESS is the command is queued, else returns eHAL_STATUS_FAILURE
368eHalStatus csrQueueScanRequest( tpAniSirGlobal pMac, tSmeCmd *pScanCmd )
369{
370 eHalStatus status = eHAL_STATUS_SUCCESS;
371
372 tANI_BOOLEAN fNoCmdPending;
373 tSmeCmd *pQueueScanCmd=NULL;
374 tSmeCmd *pSendScanCmd=NULL;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700375 tANI_U8 nNumChanCombinedConc = 0;
Gopichand Nakkala114718f2013-03-25 19:19:46 -0700376 if (NULL == pScanCmd)
377 {
378 smsLog (pMac, LOGE, FL("Scan Req cmd is NULL"));
379 return eHAL_STATUS_FAILURE;
380 }
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -0800381 /* split scan if any one of the following:
382 * - STA session is connected and the scan is not a P2P search
383 * - any P2P session is connected
Yeshwanth Sriram Guntuka7ea10b02018-09-05 17:35:44 +0530384 * - STA+SAP. In STA+SAP concurrency, scan requests received on
385 * STA interface when not in connected state are not split.
386 * This can result in large time gap between successive beacons
387 * sent by SAP.
Srikant Kuppa866893f2012-12-27 17:28:14 -0800388 * Do not split scans if no concurrent infra connections are
389 * active and if the scan is a BG scan triggered by LFR (OR)
390 * any scan if LFR is in the middle of a BG scan. Splitting
391 * the scan is delaying the time it takes for LFR to find
392 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -0800393 */
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700394
Yeshwanth Sriram Guntuka7ea10b02018-09-05 17:35:44 +0530395 if (csrIsInfraApStarted(pMac))
396 {
397 nNumChanCombinedConc = 1;
398 }
399 else if(csrIsStaSessionConnected(pMac) &&
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700400 !csrIsP2pSessionConnected(pMac))
401 {
402 nNumChanCombinedConc = pMac->roam.configParam.nNumStaChanCombinedConc;
403 }
404 else if(csrIsP2pSessionConnected(pMac))
405 {
406 nNumChanCombinedConc = pMac->roam.configParam.nNumP2PChanCombinedConc;
407 }
Srikant Kuppa866893f2012-12-27 17:28:14 -0800408 if ( (csrIsStaSessionConnected(pMac) &&
409#ifdef FEATURE_WLAN_LFR
410 (csrIsConcurrentInfraConnected(pMac) ||
411 ((pScanCmd->u.scanCmd.reason != eCsrScanBgScan) &&
412 (pMac->roam.neighborRoamInfo.neighborRoamState !=
413 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
414#endif
415 (pScanCmd->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Vinay Malekal05fdc812012-12-17 13:04:30 -0800416 (csrIsP2pSessionConnected(pMac)) )
Jeff Johnson295189b2012-06-20 16:38:30 -0700417 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700418 tCsrScanRequest scanReq;
419 tANI_U8 numChn = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
420 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
421 tANI_U8 channelToScan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
Jeff Johnson295189b2012-06-20 16:38:30 -0700422 tANI_BOOLEAN bMemAlloc = eANI_BOOLEAN_FALSE;
423
424 if (numChn == 0)
425 {
426
427 numChn = pMac->scan.baseChannels.numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -0700428
Kiet Lam64c1b492013-07-12 13:56:44 +0530429 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(numChn);
430 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -0700431 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800432 smsLog( pMac, LOGE, FL(" Failed to get memory for channel list ") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800433 return eHAL_STATUS_FAILURE;
434 }
435 bMemAlloc = eANI_BOOLEAN_TRUE;
Kiet Lam64c1b492013-07-12 13:56:44 +0530436 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
437 pMac->scan.baseChannels.channelList, numChn);
438 status = eHAL_STATUS_SUCCESS;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800439 if( !HAL_STATUS_SUCCESS( status ) )
440 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530441 vos_mem_free(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800442 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800443 smsLog( pMac, LOGE, FL(" Failed to copy memory to channel list ") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800444 return eHAL_STATUS_FAILURE;
445 }
446 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = numChn;
447 }
Sushant Kaushik826de802014-05-08 18:04:11 +0530448 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
449 "%s: Total Number of channels to scan : %d "
450 "Splitted in group of %d ", __func__, numChn,
451 nNumChanCombinedConc);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800452 //Whenever we get a scan request with multiple channels we break it up into 2 requests
453 //First request for first channel to scan and second request to scan remaining channels
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700454 if ( numChn > nNumChanCombinedConc)
Vinay Malekal05fdc812012-12-17 13:04:30 -0800455 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530456 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800457
458 pQueueScanCmd = csrGetCommandBuffer(pMac); //optimize this to use 2 command buffer only
459 if (!pQueueScanCmd)
460 {
461 if (bMemAlloc)
Jeff Johnson295189b2012-06-20 16:38:30 -0700462 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530463 vos_mem_free(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800464 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
465
Jeff Johnson295189b2012-06-20 16:38:30 -0700466 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800467 smsLog( pMac, LOGE, FL(" Failed to get Queue command buffer") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800468 return eHAL_STATUS_FAILURE;
469 }
470 pQueueScanCmd->command = pScanCmd->command;
471 pQueueScanCmd->sessionId = pScanCmd->sessionId;
472 pQueueScanCmd->u.scanCmd.callback = pScanCmd->u.scanCmd.callback;
473 pQueueScanCmd->u.scanCmd.pContext = pScanCmd->u.scanCmd.pContext;
474 pQueueScanCmd->u.scanCmd.reason = pScanCmd->u.scanCmd.reason;
475 pQueueScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Jeff Johnson295189b2012-06-20 16:38:30 -0700476
Vinay Malekal05fdc812012-12-17 13:04:30 -0800477 /* First copy all the parameters to local variable of scan request */
478 csrScanCopyRequest(pMac, &scanReq, &pScanCmd->u.scanCmd.u.scanRequest);
Madan Mohan Koyyalamudiaf2a8b92012-10-09 14:58:07 -0700479
Vinay Malekal05fdc812012-12-17 13:04:30 -0800480 /* Now modify the elements of local var scan request required to be modified for split scan */
481 if(scanReq.ChannelInfo.ChannelList != NULL)
482 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530483 vos_mem_free(scanReq.ChannelInfo.ChannelList);
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -0800484 scanReq.ChannelInfo.ChannelList = NULL;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800485 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700486
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700487 pChnInfo->numOfChannels = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels - nNumChanCombinedConc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700488
Vinay Malekal05fdc812012-12-17 13:04:30 -0800489 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_WARN,
Jeff Johnson89477502017-09-19 08:35:23 -0700490 FL(" &channelToScan %pK pScanCmd(%pK) pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList(%pK)numChn(%d)"),
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +0530491 &channelToScan[0], pScanCmd,
492 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList, numChn);
Jeff Johnson295189b2012-06-20 16:38:30 -0700493
Kiet Lam64c1b492013-07-12 13:56:44 +0530494 vos_mem_copy(&channelToScan[0],
495 &pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[
496 nNumChanCombinedConc],
497 pChnInfo->numOfChannels * sizeof(tANI_U8));
Vinay Malekal05fdc812012-12-17 13:04:30 -0800498
499 pChnInfo->ChannelList = &channelToScan[0];
500
501 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
c_hpothudbefd3e2014-04-28 15:59:47 +0530502
Vinay Malekal05fdc812012-12-17 13:04:30 -0800503 //Use concurrency values for min/maxChnTime.
504 //We know csrIsAnySessionConnected(pMac) returns TRUE here
505 csrSetDefaultScanTiming(pMac, scanReq.scanType, &scanReq);
506
507 status = csrScanCopyRequest(pMac, &pQueueScanCmd->u.scanCmd.u.scanRequest, &scanReq);
508
509 if(!HAL_STATUS_SUCCESS(status))
510 {
511 if (bMemAlloc)
512 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530513 vos_mem_free(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800514 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
515
516 }
517 if( scanReq.pIEField != NULL)
518 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530519 vos_mem_free(scanReq.pIEField);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800520 scanReq.pIEField = NULL;
521 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800522 smsLog( pMac, LOGE, FL(" Failed to get copy csrScanRequest = %d"), status );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800523 return eHAL_STATUS_FAILURE;
524 }
525 /* Clean the local scan variable */
526 scanReq.ChannelInfo.ChannelList = NULL;
527 scanReq.ChannelInfo.numOfChannels = 0;
528 csrScanFreeRequest(pMac, &scanReq);
529
530 /* setup the command to scan 2 channels */
531 pSendScanCmd = pScanCmd;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700532 pSendScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nNumChanCombinedConc;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800533 pSendScanCmd->u.scanCmd.u.scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
c_hpothudbefd3e2014-04-28 15:59:47 +0530534
Vinay Malekal05fdc812012-12-17 13:04:30 -0800535 //Use concurrency values for min/maxChnTime.
536 //We know csrIsAnySessionConnected(pMac) returns TRUE here
537 csrSetDefaultScanTiming(pMac, pSendScanCmd->u.scanCmd.u.scanRequest.scanType, &pSendScanCmd->u.scanCmd.u.scanRequest);
538 pSendScanCmd->u.scanCmd.callback = NULL;
539 } else {
540 pSendScanCmd = pScanCmd;
541 pSendScanCmd->u.scanCmd.u.scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
c_hpothudbefd3e2014-04-28 15:59:47 +0530542
Vinay Malekal05fdc812012-12-17 13:04:30 -0800543 //Use concurrency values for min/maxChnTime.
544 //We know csrIsAnySessionConnected(pMac) returns TRUE here
545 csrSetDefaultScanTiming(pMac, pSendScanCmd->u.scanCmd.u.scanRequest.scanType, &pSendScanCmd->u.scanCmd.u.scanRequest);
546 }
547
548 fNoCmdPending = csrLLIsListEmpty( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK );
549
550 //Logic Below is as follows
551 // If the scanCmdPendingList is empty then we directly send that command
552 // to smeCommandQueue else we buffer it in our scanCmdPendingList Queue
553 if( fNoCmdPending )
554 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700555 if (pQueueScanCmd != NULL)
556 {
Vinay Malekal05fdc812012-12-17 13:04:30 -0800557 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pQueueScanCmd->Link, LL_ACCESS_LOCK );
Jeff Johnson295189b2012-06-20 16:38:30 -0700558 }
559
560 if (pSendScanCmd != NULL)
561 {
562 return csrQueueSmeCommand(pMac, pSendScanCmd, eANI_BOOLEAN_FALSE);
563 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800564 }
565 else
566 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700567 if (pSendScanCmd != NULL)
568 {
569 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pSendScanCmd->Link, LL_ACCESS_LOCK );
570 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800571
Jeff Johnson295189b2012-06-20 16:38:30 -0700572 if (pQueueScanCmd != NULL)
573 {
574 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pQueueScanCmd->Link, LL_ACCESS_LOCK );
575 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800576 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700577 }
578 else
579 { //No concurrency case
Srikant Kuppa866893f2012-12-27 17:28:14 -0800580 smsLog( pMac, LOG2, FL("Queuing scan command (reason=%d, roamState=%d"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800581 " numOfChannels=%d)"),
Srikant Kuppa866893f2012-12-27 17:28:14 -0800582 pScanCmd->u.scanCmd.reason,
583 pMac->roam.neighborRoamInfo.neighborRoamState,
584 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -0700585 return csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
586 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700587
588 return ( status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700589}
590#endif
591
Jeff Johnsone7245742012-09-05 17:12:55 -0700592/* ---------------------------------------------------------------------------
593 \fn csrScan2GOnyRequest
594 \brief This function will update the scan request with only
Jeff Johnsonb88db982012-12-10 13:34:59 -0800595 2.4GHz valid channel list.
Jeff Johnsone7245742012-09-05 17:12:55 -0700596 \param pMac
597 \param pScanCmd
598 \param pScanRequest
599 \return None
600 -------------------------------------------------------------------------------*/
601static void csrScan2GOnyRequest(tpAniSirGlobal pMac,tSmeCmd *pScanCmd,
602 tCsrScanRequest *pScanRequest)
603{
604 tANI_U8 index, channelId, channelListSize = 0;
605 tANI_U8 channelList2G[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
606 static tANI_U8 validchannelList[CSR_MAX_2_4_GHZ_SUPPORTED_CHANNELS] = {0};
607
608 VOS_ASSERT(pScanCmd && pScanRequest);
Madan Mohan Koyyalamudi33ef6a22012-10-30 17:44:43 -0700609 /* To silence the KW tool null check is added */
610 if((pScanCmd == NULL) || (pScanRequest == NULL))
611 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800612 smsLog( pMac, LOGE, FL(" pScanCmd or pScanRequest is NULL "));
Madan Mohan Koyyalamudi33ef6a22012-10-30 17:44:43 -0700613 return;
614 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700615
616 if (pScanCmd->u.scanCmd.scanID ||
617 (eCSR_SCAN_REQUEST_FULL_SCAN != pScanRequest->requestType))
618 return;
619
620 //Contsruct valid Supported 2.4 GHz Channel List
621 for( index = 0; index < ARRAY_SIZE(channelList2G); index++ )
622 {
623 channelId = channelList2G[index];
624 if ( csrIsSupportedChannel( pMac, channelId ) )
625 {
626 validchannelList[channelListSize++] = channelId;
627 }
628 }
629
630 pScanRequest->ChannelInfo.numOfChannels = channelListSize;
631 pScanRequest->ChannelInfo.ChannelList = validchannelList;
632}
633
Jeff Johnson295189b2012-06-20 16:38:30 -0700634eHalStatus csrScanRequest(tpAniSirGlobal pMac, tANI_U16 sessionId,
635 tCsrScanRequest *pScanRequest, tANI_U32 *pScanRequestID,
636 csrScanCompleteCallback callback, void *pContext)
637{
638 eHalStatus status = eHAL_STATUS_FAILURE;
639 tSmeCmd *pScanCmd = NULL;
Madan Mohan Koyyalamudicb90bb22012-10-30 18:24:43 -0700640 eCsrConnectState ConnectState;
Deepthi Gowrie11da8c2016-02-04 18:18:39 +0530641
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800642 if(pScanRequest == NULL)
643 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800644 smsLog( pMac, LOGE, FL(" pScanRequest is NULL"));
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800645 VOS_ASSERT(0);
Kaushik, Sushant488df382014-03-05 11:43:47 +0530646 return eHAL_STATUS_FAILURE ;
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800647 }
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700648
Kiet Lamd1f3dc82013-11-05 20:45:04 +0530649 /* During group formation, the P2P client scans for GO with the specific SSID.
650 * There will be chances of GO switching to other channels because of scan or
651 * to STA channel in case of STA+GO MCC scenario. So to increase the possibility
652 * of client to find the GO, the dwell time of scan is increased to 100ms.
653 */
654 if(pScanRequest->p2pSearch)
655 {
Rashmi Ramanna6f7931c2013-12-20 09:04:12 +0530656 if(pScanRequest->SSIDs.numOfSSIDs)
Kiet Lamd1f3dc82013-11-05 20:45:04 +0530657 {
Rashmi Ramanna6f7931c2013-12-20 09:04:12 +0530658 //If the scan request is for specific SSId the length of SSID will be
659 //greater than 7 as SSID for p2p search contains "DIRECT-")
660 if(pScanRequest->SSIDs.SSIDList->SSID.length > DIRECT_SSID_LEN)
661 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530662 smsLog( pMac, LOG1, FL("P2P: Increasing the min and max Dwell"
663 " time to %d for specific SSID scan %.*s"),
664 MAX_CHN_TIME_TO_FIND_GO,
665 pScanRequest->SSIDs.SSIDList->SSID.length,
666 pScanRequest->SSIDs.SSIDList->SSID.ssId);
Rashmi Ramanna6f7931c2013-12-20 09:04:12 +0530667 pScanRequest->maxChnTime = MAX_CHN_TIME_TO_FIND_GO;
668 pScanRequest->minChnTime = MIN_CHN_TIME_TO_FIND_GO;
669 }
Kiet Lamd1f3dc82013-11-05 20:45:04 +0530670 }
671 }
672
Jeff Johnson295189b2012-06-20 16:38:30 -0700673 do
674 {
675 if(pMac->scan.fScanEnable)
676 {
677 pScanCmd = csrGetCommandBuffer(pMac);
678 if(pScanCmd)
679 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530680 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -0700681 pScanCmd->command = eSmeCommandScan;
682 pScanCmd->sessionId = sessionId;
683 pScanCmd->u.scanCmd.callback = callback;
684 pScanCmd->u.scanCmd.pContext = pContext;
685 if(eCSR_SCAN_REQUEST_11D_SCAN == pScanRequest->requestType)
686 {
687 pScanCmd->u.scanCmd.reason = eCsrScan11d1;
688 }
689 else if((eCSR_SCAN_REQUEST_FULL_SCAN == pScanRequest->requestType) ||
690 (eCSR_SCAN_P2P_DISCOVERY == pScanRequest->requestType)
691#ifdef SOFTAP_CHANNEL_RANGE
692 ||(eCSR_SCAN_SOFTAP_CHANNEL_RANGE == pScanRequest->requestType)
693#endif
694 )
695 {
696 pScanCmd->u.scanCmd.reason = eCsrScanUserRequest;
697 }
698 else if(eCSR_SCAN_HO_BG_SCAN == pScanRequest->requestType)
699 {
700 pScanCmd->u.scanCmd.reason = eCsrScanBgScan;
701 }
702 else if(eCSR_SCAN_HO_PROBE_SCAN == pScanRequest->requestType)
703 {
704 pScanCmd->u.scanCmd.reason = eCsrScanProbeBss;
705 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700706 else if(eCSR_SCAN_P2P_FIND_PEER == pScanRequest->requestType)
707 {
708 pScanCmd->u.scanCmd.reason = eCsrScanP2PFindPeer;
709 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700710 else
711 {
712 pScanCmd->u.scanCmd.reason = eCsrScanIdleScan;
713 }
714 if(pScanRequest->minChnTime == 0 && pScanRequest->maxChnTime == 0)
715 {
716 //The caller doesn't set the time correctly. Set it here
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530717 csrSetDefaultScanTiming(pMac, pScanRequest->scanType,
718 pScanRequest);
719 smsLog(pMac, LOG1, FL("Setting default min %d and max %d"
720 " ChnTime"), pScanRequest->minChnTime,
721 pScanRequest->maxChnTime);
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700722 }
723#ifdef WLAN_AP_STA_CONCURRENCY
724 if(pScanRequest->restTime == 0)
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800725 {
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700726 //Need to set restTime only if at least one session is connected
727 if(csrIsAnySessionConnected(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -0700728 {
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700729 pScanRequest->restTime = pMac->roam.configParam.nRestTimeConc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700730 }
731 }
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700732#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -0700733 /*For Standalone wlan : channel time will remain the same.
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530734 For BTC with A2DP up: Channel time = Channel time * 2, if station is not already associated.
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800735 This has been done to provide a larger scan window for faster connection during btc.Else Scan is seen
736 to take a long time.
737 For BTC with A2DP up: Channel time will not be doubled, if station is already associated.
738 */
Jeff Johnson32d95a32012-09-10 13:15:23 -0700739 status = csrRoamGetConnectState(pMac,sessionId,&ConnectState);
Srinivas Girigowdac84c57c2013-02-19 17:41:56 -0800740 if (HAL_STATUS_SUCCESS(status) &&
741 pMac->btc.fA2DPUp &&
Jeff Johnson32d95a32012-09-10 13:15:23 -0700742 (eCSR_ASSOC_STATE_TYPE_INFRA_ASSOCIATED != ConnectState) &&
743 (eCSR_ASSOC_STATE_TYPE_IBSS_CONNECTED != ConnectState))
744 {
745 pScanRequest->maxChnTime = pScanRequest->maxChnTime << 1;
746 pScanRequest->minChnTime = pScanRequest->minChnTime << 1;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530747 smsLog( pMac, LOG1, FL("BTC A2DP up, doubling max and min"
748 " ChnTime (Max=%d Min=%d)"),
749 pScanRequest->maxChnTime,
750 pScanRequest->minChnTime);
Jeff Johnson32d95a32012-09-10 13:15:23 -0700751 }
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800752
Abhishek Singhadd13582016-09-29 17:00:03 +0530753 pScanRequest->max_chntime_btc_esco =
754 pMac->roam.configParam.max_chntime_btc_esco;
755 pScanRequest->min_chntime_btc_esco =
756 pMac->roam.configParam.min_chntime_btc_esco;
Jeff Johnson295189b2012-06-20 16:38:30 -0700757 //Need to make the following atomic
758 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
759
760 if(pScanRequestID)
761 {
762 *pScanRequestID = pScanCmd->u.scanCmd.scanID;
763 }
764
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800765 // If it is the first scan request from HDD, CSR checks if it is for 11d.
Jeff Johnson295189b2012-06-20 16:38:30 -0700766 // If it is not, CSR will save the scan request in the pending cmd queue
767 // & issue an 11d scan request to PE.
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800768 if (((0 == pScanCmd->u.scanCmd.scanID)
Jeff Johnson295189b2012-06-20 16:38:30 -0700769 && (eCSR_SCAN_REQUEST_11D_SCAN != pScanRequest->requestType))
770#ifdef SOFTAP_CHANNEL_RANGE
771 && (eCSR_SCAN_SOFTAP_CHANNEL_RANGE != pScanRequest->requestType)
772#endif
773 && (eANI_BOOLEAN_FALSE == pMac->scan.fEnableBypass11d)
774 )
775 {
776 tSmeCmd *p11dScanCmd;
777 tCsrScanRequest scanReq;
778 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
779
Kiet Lam64c1b492013-07-12 13:56:44 +0530780 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -0700781
782 p11dScanCmd = csrGetCommandBuffer(pMac);
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800783 if (p11dScanCmd)
Jeff Johnson295189b2012-06-20 16:38:30 -0700784 {
785 tANI_U32 numChn = pMac->scan.baseChannels.numChannels;
786
Kiet Lam64c1b492013-07-12 13:56:44 +0530787 vos_mem_set(&p11dScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
788 pChnInfo->ChannelList = vos_mem_malloc(numChn);
789 if ( NULL == pChnInfo->ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -0700790 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530791 smsLog(pMac, LOGE, FL("Failed to allocate memory"));
792 status = eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -0700793 break;
794 }
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530795 vos_mem_copy(pChnInfo->ChannelList,
796 pMac->scan.baseChannels.channelList,
797 numChn);
Jeff Johnson295189b2012-06-20 16:38:30 -0700798 pChnInfo->numOfChannels = (tANI_U8)numChn;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530799
Jeff Johnson295189b2012-06-20 16:38:30 -0700800 p11dScanCmd->command = eSmeCommandScan;
Mihir Shetefc7ff5b2014-01-27 11:30:05 +0530801 p11dScanCmd->u.scanCmd.callback = pMac->scan.callback11dScanDone;
Jeff Johnson295189b2012-06-20 16:38:30 -0700802 p11dScanCmd->u.scanCmd.pContext = NULL;
c_hpothu0d5a7352014-03-22 12:30:25 +0530803 p11dScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID;
Jeff Johnson295189b2012-06-20 16:38:30 -0700804 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
805
806 if ( csrIs11dSupported(pMac) )
807 {
c_hpothudbefd3e2014-04-28 15:59:47 +0530808 scanReq.scanType = eSIR_PASSIVE_SCAN;
Jeff Johnson295189b2012-06-20 16:38:30 -0700809 scanReq.requestType = eCSR_SCAN_REQUEST_11D_SCAN;
810 p11dScanCmd->u.scanCmd.reason = eCsrScan11d1;
811 scanReq.maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
812 scanReq.minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
813 }
814 else
815 {
c_hpothudbefd3e2014-04-28 15:59:47 +0530816 scanReq.scanType = pScanRequest->scanType;
Jeff Johnson295189b2012-06-20 16:38:30 -0700817 scanReq.requestType = eCSR_SCAN_IDLE_MODE_SCAN;
818 p11dScanCmd->u.scanCmd.reason = eCsrScanIdleScan;
819 scanReq.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
820 scanReq.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800821
Abhishek Singhadd13582016-09-29 17:00:03 +0530822 scanReq.max_chntime_btc_esco =
823 pMac->roam.configParam.max_chntime_btc_esco;
824 scanReq.min_chntime_btc_esco =
825 pMac->roam.configParam.min_chntime_btc_esco;
Jeff Johnson295189b2012-06-20 16:38:30 -0700826 }
c_hpothu059edb02014-03-12 21:44:28 +0530827 if (pMac->roam.configParam.nInitialDwellTime)
828 {
829 scanReq.maxChnTime =
830 pMac->roam.configParam.nInitialDwellTime;
831 smsLog(pMac, LOG1, FL("11d scan, updating"
832 "dwell time for first scan %u"),
833 scanReq.maxChnTime);
834 }
Deepthi Gowrie11da8c2016-02-04 18:18:39 +0530835 if ((pScanCmd->u.scanCmd.reason == eCsrScanUserRequest)
836 && !(pScanRequest->p2pSearch)
Gupta, Kapilb79cda32015-12-30 20:36:33 +0530837 &&(pScanRequest->ChannelInfo.numOfChannels
838 < pMac->roam.configParam.
839 max_chan_for_dwell_time_cfg))
840 {
841 pScanRequest->maxChnTime =
842 pScanRequest->maxChnTime << 1;
843 pScanRequest->minChnTime =
844 pScanRequest->minChnTime << 1;
845 smsLog(pMac, LOG1,
846 FL("Double ChnTime (Max=%d Min=%d) numOfChannels=%d max_chan_for_dwell_time_cfg=%d"),
847 pScanRequest->maxChnTime,
848 pScanRequest->minChnTime,
849 pScanRequest->ChannelInfo.numOfChannels,
850 pMac->roam.configParam.
851 max_chan_for_dwell_time_cfg);
852 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700853
Jeff Johnson295189b2012-06-20 16:38:30 -0700854 status = csrScanCopyRequest(pMac, &p11dScanCmd->u.scanCmd.u.scanRequest, &scanReq);
855 //Free the channel list
Kiet Lam64c1b492013-07-12 13:56:44 +0530856 vos_mem_free(pChnInfo->ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -0700857 pChnInfo->ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -0700858
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800859 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700860 {
krunal soni5f112f02013-11-25 15:00:11 -0800861 pMac->scan.scanProfile.numOfChannels =
862 p11dScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -0700863 //Start process the command
864#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +0530865 if (!pMac->fScanOffload)
866 status = csrQueueScanRequest(pMac, p11dScanCmd);
867 else
868 status = csrQueueSmeCommand(pMac, p11dScanCmd,
869 eANI_BOOLEAN_FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -0700870#else
871 status = csrQueueSmeCommand(pMac, p11dScanCmd, eANI_BOOLEAN_FALSE);
872#endif
873 if( !HAL_STATUS_SUCCESS( status ) )
874 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530875 smsLog(pMac, LOGE, FL("Failed to send message"
876 " status = %d"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -0700877 break;
878 }
879 }
880 else
881 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530882 smsLog(pMac, LOGE, FL("csrScanCopyRequest failed"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700883 break;
884 }
885 }
886 else
887 {
888 //error
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530889 smsLog( pMac, LOGE, FL("p11dScanCmd failed") );
Jeff Johnson295189b2012-06-20 16:38:30 -0700890 break;
891 }
892 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700893
894 //Scan only 2G Channels if set in ini file
895 //This is mainly to reduce the First Scan duration
896 //Once we turn on Wifi
897 if(pMac->scan.fFirstScanOnly2GChnl)
898 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800899 smsLog( pMac, LOG1, FL("Scanning only 2G Channels during first scan"));
Jeff Johnsone7245742012-09-05 17:12:55 -0700900 csrScan2GOnyRequest(pMac, pScanCmd, pScanRequest);
901 }
902
c_hpothu059edb02014-03-12 21:44:28 +0530903 if (pMac->roam.configParam.nInitialDwellTime)
904 {
905 pScanRequest->maxChnTime =
906 pMac->roam.configParam.nInitialDwellTime;
907 pMac->roam.configParam.nInitialDwellTime = 0;
908 smsLog(pMac, LOG1,
909 FL("updating dwell time for first scan %u"),
910 pScanRequest->maxChnTime);
911 }
912
Deepthi Gowrie11da8c2016-02-04 18:18:39 +0530913 if ((pScanCmd->u.scanCmd.reason == eCsrScanUserRequest)
914 && !(pScanRequest->p2pSearch)
Gupta, Kapilb79cda32015-12-30 20:36:33 +0530915 && (pScanRequest->ChannelInfo.numOfChannels
916 < pMac->roam.configParam.max_chan_for_dwell_time_cfg))
917 {
918 pScanRequest->maxChnTime = pScanRequest->maxChnTime << 1;
919 pScanRequest->minChnTime = pScanRequest->minChnTime << 1;
920 smsLog(pMac, LOG1,
921 FL("Double ChnTime (Max=%d Min=%d) numOfChannels=%d max_chan_for_dwell_time_cfg=%d"),
922 pScanRequest->maxChnTime,
923 pScanRequest->minChnTime,
924 pScanRequest->ChannelInfo.numOfChannels,
925 pMac->roam.configParam.max_chan_for_dwell_time_cfg);
926 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700927 status = csrScanCopyRequest(pMac, &pScanCmd->u.scanCmd.u.scanRequest, pScanRequest);
928 if(HAL_STATUS_SUCCESS(status))
929 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530930 tCsrScanRequest *pTempScanReq =
931 &pScanCmd->u.scanCmd.u.scanRequest;
krunal soni5f112f02013-11-25 15:00:11 -0800932 pMac->scan.scanProfile.numOfChannels =
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530933 pTempScanReq->ChannelInfo.numOfChannels;
krunal soni5f112f02013-11-25 15:00:11 -0800934
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530935 smsLog( pMac, LOG1, FL(" SId=%d scanId=%d"
936 " Scan reason=%u numSSIDs=%d"
937 " numChan=%d P2P search=%d minCT=%d maxCT=%d"
938 " minCBtc=%d maxCBtx=%d"),
939 sessionId, pScanCmd->u.scanCmd.scanID,
940 pScanCmd->u.scanCmd.reason,
941 pTempScanReq->SSIDs.numOfSSIDs,
942 pTempScanReq->ChannelInfo.numOfChannels,
943 pTempScanReq->p2pSearch,
944 pTempScanReq->minChnTime,
945 pTempScanReq->maxChnTime,
Abhishek Singhadd13582016-09-29 17:00:03 +0530946 pTempScanReq->min_chntime_btc_esco,
947 pTempScanReq->max_chntime_btc_esco);
Jeff Johnson295189b2012-06-20 16:38:30 -0700948 //Start process the command
949#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +0530950 if (!pMac->fScanOffload)
951 status = csrQueueScanRequest(pMac,pScanCmd);
952 else
953 status = csrQueueSmeCommand(pMac, pScanCmd,
954 eANI_BOOLEAN_FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -0700955#else
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530956 status = csrQueueSmeCommand(pMac, pScanCmd,
957 eANI_BOOLEAN_FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -0700958#endif
959 if( !HAL_STATUS_SUCCESS( status ) )
960 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800961 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700962 break;
963 }
964 }
965 else
966 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800967 smsLog( pMac, LOGE, FL(" fail to copy request status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700968 break;
969 }
970 }
971 else
972 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800973 smsLog( pMac, LOGE, FL(" pScanCmd is NULL"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700974 break;
975 }
976 }
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530977 else
978 {
979 smsLog( pMac, LOGE, FL("SId: %d Scanning not enabled"
980 " Scan type=%u, numOfSSIDs=%d P2P search=%d"),
981 sessionId, pScanRequest->requestType,
982 pScanRequest->SSIDs.numOfSSIDs,
983 pScanRequest->p2pSearch );
984 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700985 } while(0);
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530986
987
Jeff Johnson295189b2012-06-20 16:38:30 -0700988 if(!HAL_STATUS_SUCCESS(status) && pScanCmd)
989 {
990 if( eCsrScanIdleScan == pScanCmd->u.scanCmd.reason )
991 {
992 //Set the flag back for restarting idle scan
993 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
994 }
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530995 smsLog( pMac, LOGE, FL(" SId: %d Failed with status=%d"
996 " Scan reason=%u numOfSSIDs=%d"
997 " P2P search=%d scanId=%d"),
998 sessionId, status, pScanCmd->u.scanCmd.reason,
999 pScanRequest->SSIDs.numOfSSIDs, pScanRequest->p2pSearch,
1000 pScanCmd->u.scanCmd.scanID );
Jeff Johnson295189b2012-06-20 16:38:30 -07001001 csrReleaseCommandScan(pMac, pScanCmd);
1002 }
1003
1004 return (status);
1005}
1006
1007
1008eHalStatus csrScanRequestResult(tpAniSirGlobal pMac)
1009{
1010 eHalStatus status = eHAL_STATUS_SUCCESS;
1011 tSmeCmd *pScanCmd;
1012
1013 if(pMac->scan.fScanEnable)
1014 {
1015 pScanCmd = csrGetCommandBuffer(pMac);
1016 if(pScanCmd)
1017 {
1018 pScanCmd->command = eSmeCommandScan;
Kiet Lam64c1b492013-07-12 13:56:44 +05301019 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001020 pScanCmd->u.scanCmd.callback = NULL;
1021 pScanCmd->u.scanCmd.pContext = NULL;
1022 pScanCmd->u.scanCmd.reason = eCsrScanGetResult;
1023 //Need to make the following atomic
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07001024 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID; //let it wrap around
Jeff Johnson295189b2012-06-20 16:38:30 -07001025 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
1026 if( !HAL_STATUS_SUCCESS( status ) )
1027 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001028 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001029 csrReleaseCommandScan(pMac, pScanCmd);
1030 }
1031 }
1032 else
1033 {
1034 //log error
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001035 smsLog(pMac, LOGE, FL("can not obtain a common buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001036 status = eHAL_STATUS_RESOURCES;
1037 }
1038 }
1039
1040 return (status);
1041}
1042
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07001043#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
1044eHalStatus csrScanRequestLfrResult(tpAniSirGlobal pMac, tANI_U32 sessionId,
1045 csrScanCompleteCallback callback, void *pContext)
1046{
1047 eHalStatus status = eHAL_STATUS_SUCCESS;
1048 tSmeCmd *pScanCmd;
1049
1050 if (pMac->scan.fScanEnable)
1051 {
1052 pScanCmd = csrGetCommandBuffer(pMac);
1053 if (pScanCmd)
1054 {
1055 pScanCmd->command = eSmeCommandScan;
1056 pScanCmd->sessionId = sessionId;
Kiet Lam64c1b492013-07-12 13:56:44 +05301057 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07001058 pScanCmd->u.scanCmd.callback = callback;
1059 pScanCmd->u.scanCmd.pContext = pContext;
1060 pScanCmd->u.scanCmd.reason = eCsrScanGetLfrResult;
1061 //Need to make the following atomic
1062 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID; //let it wrap around
1063 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_TRUE);
1064 if ( !HAL_STATUS_SUCCESS( status ) )
1065 {
1066 smsLog( pMac, LOGE, FL(" fail to send message status = %d\n"), status );
1067 csrReleaseCommandScan(pMac, pScanCmd);
1068 }
1069 }
1070 else
1071 {
1072 //log error
1073 smsLog(pMac, LOGE, FL("can not obtain a common buffer\n"));
1074 status = eHAL_STATUS_RESOURCES;
1075 }
1076 }
1077
1078 return (status);
1079}
1080#endif //WLAN_FEATURE_ROAM_SCAN_OFFLOAD
Jeff Johnson295189b2012-06-20 16:38:30 -07001081
1082eHalStatus csrScanAllChannels(tpAniSirGlobal pMac, eCsrRequestType reqType)
1083{
1084 eHalStatus status = eHAL_STATUS_SUCCESS;
1085 tANI_U32 scanId;
1086 tCsrScanRequest scanReq;
1087
Kiet Lam64c1b492013-07-12 13:56:44 +05301088 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001089 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
1090 scanReq.scanType = eSIR_ACTIVE_SCAN;
1091 scanReq.requestType = reqType;
1092 scanReq.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1093 scanReq.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Abhishek Singhadd13582016-09-29 17:00:03 +05301094 scanReq.max_chntime_btc_esco =
1095 pMac->roam.configParam.max_chntime_btc_esco;
1096 scanReq.min_chntime_btc_esco =
1097 pMac->roam.configParam.min_chntime_btc_esco;
Jeff Johnson295189b2012-06-20 16:38:30 -07001098 //Scan with invalid sessionId.
1099 //This results in SME using the first available session to scan.
1100 status = csrScanRequest(pMac, CSR_SESSION_ID_INVALID, &scanReq,
1101 &scanId, NULL, NULL);
1102
1103 return (status);
1104}
1105
1106
1107
1108
1109eHalStatus csrIssueRoamAfterLostlinkScan(tpAniSirGlobal pMac, tANI_U32 sessionId, eCsrRoamReason reason)
1110{
1111 eHalStatus status = eHAL_STATUS_FAILURE;
1112 tScanResultHandle hBSSList = NULL;
1113 tCsrScanResultFilter *pScanFilter = NULL;
1114 tANI_U32 roamId = 0;
1115 tCsrRoamProfile *pProfile = NULL;
1116 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1117
Jeff Johnson32d95a32012-09-10 13:15:23 -07001118 if(!pSession)
1119 {
1120 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1121 return eHAL_STATUS_FAILURE;
1122 }
1123
Jeff Johnson295189b2012-06-20 16:38:30 -07001124 do
1125 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001126 smsLog(pMac, LOG1, " csrIssueRoamAfterLostlinkScan called");
Jeff Johnson295189b2012-06-20 16:38:30 -07001127 if(pSession->fCancelRoaming)
1128 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001129 smsLog(pMac, LOGW, " lostlink roaming is cancelled");
Jeff Johnson295189b2012-06-20 16:38:30 -07001130 csrScanStartIdleScan(pMac);
1131 status = eHAL_STATUS_SUCCESS;
1132 break;
1133 }
1134 //Here is the profile we need to connect to
Kiet Lam64c1b492013-07-12 13:56:44 +05301135 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1136 if ( NULL == pScanFilter)
1137 status = eHAL_STATUS_FAILURE;
1138 else
1139 status = eHAL_STATUS_SUCCESS;
1140 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001141 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301142 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001143 if(NULL == pSession->pCurRoamProfile)
1144 {
1145 pScanFilter->EncryptionType.numEntries = 1;
1146 pScanFilter->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_NONE;
1147 }
1148 else
1149 {
1150 //We have to make a copy of pCurRoamProfile because it will be free inside csrRoamIssueConnect
Kiet Lam64c1b492013-07-12 13:56:44 +05301151 pProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1152 if ( NULL == pProfile )
1153 status = eHAL_STATUS_FAILURE;
1154 else
1155 status = eHAL_STATUS_SUCCESS;
1156 if (!HAL_STATUS_SUCCESS(status))
1157 break;
1158 vos_mem_set(pProfile, sizeof(tCsrRoamProfile), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001159 status = csrRoamCopyProfile(pMac, pProfile, pSession->pCurRoamProfile);
1160 if(!HAL_STATUS_SUCCESS(status))
1161 break;
1162 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1163 }//We have a profile
1164 roamId = GET_NEXT_ROAM_ID(&pMac->roam);
1165 if(HAL_STATUS_SUCCESS(status))
1166 {
1167 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1168 if(HAL_STATUS_SUCCESS(status))
1169 {
1170 if(eCsrLostLink1 == reason)
1171 {
1172 //we want to put the last connected BSS to the very beginning, if possible
1173 csrMoveBssToHeadFromBSSID(pMac, &pSession->connectedProfile.bssid, hBSSList);
1174 }
1175 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList, reason,
1176 roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1177 if(!HAL_STATUS_SUCCESS(status))
1178 {
1179 csrScanResultPurge(pMac, hBSSList);
1180 }
1181 }//Have scan result
1182 }
1183 }while(0);
1184 if(pScanFilter)
1185 {
1186 //we need to free memory for filter if profile exists
1187 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301188 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001189 }
1190 if(NULL != pProfile)
1191 {
1192 csrReleaseProfile(pMac, pProfile);
Kiet Lam64c1b492013-07-12 13:56:44 +05301193 vos_mem_free(pProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07001194 }
1195
1196 return (status);
1197}
1198
1199
Ratheesh S Pece1f832015-07-25 15:50:25 +05301200eHalStatus csrScanGetScanChnInfo(tpAniSirGlobal pMac, tSmeCmd *pCommand)
Jeff Johnson295189b2012-06-20 16:38:30 -07001201{
1202 eHalStatus status = eHAL_STATUS_SUCCESS;
1203 tSmeCmd *pScanCmd;
1204
1205 if(pMac->scan.fScanEnable)
1206 {
1207 pScanCmd = csrGetCommandBuffer(pMac);
1208 if(pScanCmd)
1209 {
1210 pScanCmd->command = eSmeCommandScan;
Kiet Lam64c1b492013-07-12 13:56:44 +05301211 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001212 pScanCmd->u.scanCmd.reason = eCsrScanGetScanChnInfo;
1213 //Need to make the following atomic
1214 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Ratheesh S Pece1f832015-07-25 15:50:25 +05301215 pScanCmd->sessionId = pCommand->sessionId;
1216 if( pCommand->u.scanCmd.reason == eCsrScanUserRequest)
1217 {
1218 pScanCmd->u.scanCmd.callback = NULL;
1219 pScanCmd->u.scanCmd.pContext = NULL;
1220 } else {
1221 pScanCmd->u.scanCmd.callback = pCommand->u.scanCmd.callback;
1222 pScanCmd->u.scanCmd.pContext = pCommand->u.scanCmd.pContext;
1223 pScanCmd->u.scanCmd.abortScanIndication =
1224 pCommand->u.scanCmd.abortScanIndication;
1225 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001226 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
1227 if( !HAL_STATUS_SUCCESS( status ) )
1228 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001229 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001230 csrReleaseCommandScan(pMac, pScanCmd);
1231 }
1232 }
1233 else
1234 {
1235 //log error
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001236 smsLog(pMac, LOGE, FL("can not obtain a common buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001237 status = eHAL_STATUS_RESOURCES;
1238 }
1239 }
1240
1241 return (status);
1242}
1243
1244
1245eHalStatus csrScanHandleFailedLostlink1(tpAniSirGlobal pMac, tANI_U32 sessionId)
1246{
1247 eHalStatus status = eHAL_STATUS_FAILURE;
1248 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1249
Jeff Johnson32d95a32012-09-10 13:15:23 -07001250 if(!pSession)
1251 {
1252 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1253 return eHAL_STATUS_FAILURE;
1254 }
1255
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001256 smsLog(pMac, LOGW, " Lostlink scan 1 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001257 if(pSession->fCancelRoaming)
1258 {
1259 csrScanStartIdleScan(pMac);
1260 }
1261 else if(pSession->pCurRoamProfile)
1262 {
1263 //We fail lostlink1 but there may be other BSS in the cached result fit the profile. Give it a try first
1264 if(pSession->pCurRoamProfile->SSIDs.numOfSSIDs == 0 ||
1265 pSession->pCurRoamProfile->SSIDs.numOfSSIDs > 1)
1266 {
1267 //try lostlink scan2
1268 status = csrScanRequestLostLink2(pMac, sessionId);
1269 }
1270 else if(!pSession->pCurRoamProfile->ChannelInfo.ChannelList ||
1271 pSession->pCurRoamProfile->ChannelInfo.ChannelList[0] == 0)
1272 {
1273 //go straight to lostlink scan3
1274 status = csrScanRequestLostLink3(pMac, sessionId);
1275 }
1276 else
1277 {
1278 //we are done with lostlink
1279 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1280 {
1281 csrScanStartIdleScan(pMac);
1282 }
1283 status = eHAL_STATUS_SUCCESS;
1284 }
1285 }
1286 else
1287 {
1288 status = csrScanRequestLostLink3(pMac, sessionId);
1289 }
1290
1291 return (status);
1292}
1293
1294
1295
1296eHalStatus csrScanHandleFailedLostlink2(tpAniSirGlobal pMac, tANI_U32 sessionId)
1297{
1298 eHalStatus status = eHAL_STATUS_FAILURE;
1299 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1300
Jeff Johnson32d95a32012-09-10 13:15:23 -07001301 if(!pSession)
1302 {
1303 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1304 return eHAL_STATUS_FAILURE;
1305 }
1306
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001307 smsLog(pMac, LOGW, " Lostlink scan 2 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001308 if(pSession->fCancelRoaming)
1309 {
1310 csrScanStartIdleScan(pMac);
1311 }
1312 else if(!pSession->pCurRoamProfile || !pSession->pCurRoamProfile->ChannelInfo.ChannelList ||
1313 pSession->pCurRoamProfile->ChannelInfo.ChannelList[0] == 0)
1314 {
1315 //try lostlink scan3
1316 status = csrScanRequestLostLink3(pMac, sessionId);
1317 }
1318 else
1319 {
1320 //we are done with lostlink
1321 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1322 {
1323 csrScanStartIdleScan(pMac);
1324 }
1325 }
1326
1327 return (status);
1328}
1329
1330
1331
1332eHalStatus csrScanHandleFailedLostlink3(tpAniSirGlobal pMac, tANI_U32 sessionId)
1333{
1334 eHalStatus status = eHAL_STATUS_SUCCESS;
1335
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001336 smsLog(pMac, LOGW, " Lostlink scan 3 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001337 if(eANI_BOOLEAN_TRUE == csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1338 {
1339 //we are done with lostlink
1340 csrScanStartIdleScan(pMac);
1341 }
1342
1343 return (status);
1344}
1345
1346
1347
1348
1349//Lostlink1 scan is to actively scan the last connected profile's SSID on all matched BSS channels.
1350//If no roam profile (it should not), it is like lostlinkscan3
1351eHalStatus csrScanRequestLostLink1( tpAniSirGlobal pMac, tANI_U32 sessionId )
1352{
1353 eHalStatus status = eHAL_STATUS_SUCCESS;
1354 tSmeCmd *pCommand = NULL;
1355 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1356 tCsrScanResultFilter *pScanFilter = NULL;
1357 tScanResultHandle hBSSList = NULL;
1358 tCsrScanResultInfo *pScanResult = NULL;
1359 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1360
Jeff Johnson32d95a32012-09-10 13:15:23 -07001361 if(!pSession)
1362 {
1363 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1364 return eHAL_STATUS_FAILURE;
1365 }
1366
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001367 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001368 do
1369 {
1370 pCommand = csrGetCommandBuffer(pMac);
1371 if(!pCommand)
1372 {
1373 status = eHAL_STATUS_RESOURCES;
1374 break;
1375 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301376 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001377 pCommand->command = eSmeCommandScan;
1378 pCommand->sessionId = (tANI_U8)sessionId;
1379 pCommand->u.scanCmd.reason = eCsrScanLostLink1;
1380 pCommand->u.scanCmd.callback = NULL;
1381 pCommand->u.scanCmd.pContext = NULL;
1382 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1383 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Abhishek Singhadd13582016-09-29 17:00:03 +05301384 pCommand->u.scanCmd.u.scanRequest.max_chntime_btc_esco =
1385 pMac->roam.configParam.max_chntime_btc_esco;
1386 pCommand->u.scanCmd.u.scanRequest.min_chntime_btc_esco =
1387 pMac->roam.configParam.min_chntime_btc_esco;
Jeff Johnson295189b2012-06-20 16:38:30 -07001388 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
1389 if(pSession->connectedProfile.SSID.length)
1390 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301391 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList = vos_mem_malloc(sizeof(tCsrSSIDInfo));
1392 if ( NULL == pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList )
1393 status = eHAL_STATUS_FAILURE;
1394 else
1395 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001396 if(!HAL_STATUS_SUCCESS(status))
1397 {
1398 break;
1399 }
1400 pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 1;
Kiet Lam64c1b492013-07-12 13:56:44 +05301401 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID,
1402 &pSession->connectedProfile.SSID, sizeof(tSirMacSSid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001403 }
1404 else
1405 {
1406 pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 0;
1407 }
1408 if(pSession->pCurRoamProfile)
1409 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301410 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1411 if ( NULL == pScanFilter )
1412 status = eHAL_STATUS_FAILURE;
1413 else
1414 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001415 if(!HAL_STATUS_SUCCESS(status))
1416 {
1417 break;
1418 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301419 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001420 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
1421 if(!HAL_STATUS_SUCCESS(status))
1422 {
1423 break;
1424 }
1425 //Don't change variable status here because whether we can get result or not, the command goes to PE.
1426 //The status is also used to indicate whether the command is queued. Not success meaning not queue
1427 if(HAL_STATUS_SUCCESS((csrScanGetResult(pMac, pScanFilter, &hBSSList))) && hBSSList)
1428 {
1429 tANI_U8 i, nChn = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05301430 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList =
1431 vos_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
1432 if ( NULL == pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
1433 status = eHAL_STATUS_FAILURE;
1434 else
1435 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001436 if(!HAL_STATUS_SUCCESS(status))
1437 {
1438 break;
1439 }
1440 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) &&
1441 nChn < WNI_CFG_VALID_CHANNEL_LIST_LEN)
1442 {
1443 for(i = 0; i < nChn; i++)
1444 {
1445 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1446 pScanResult->BssDescriptor.channelId)
1447 {
1448 break;
1449 }
1450 }
1451 if(i == nChn)
1452 {
1453 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pScanResult->BssDescriptor.channelId;
1454 }
1455 }
1456 //Include the last connected BSS' channel
1457 if(csrRoamIsChannelValid(pMac, pSession->connectedProfile.operationChannel))
1458 {
1459 for(i = 0; i < nChn; i++)
1460 {
1461 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1462 pSession->connectedProfile.operationChannel)
1463 {
1464 break;
1465 }
1466 }
1467 if(i == nChn)
1468 {
1469 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pSession->connectedProfile.operationChannel;
1470 }
1471 }
1472 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nChn;
1473 }
1474 else
1475 {
1476 if(csrRoamIsChannelValid(pMac, pSession->connectedProfile.operationChannel))
1477 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301478 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(1);
1479 if ( NULL == pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
1480 status = eHAL_STATUS_FAILURE;
1481 else
1482 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001483 //just try the last connected channel
1484 if(HAL_STATUS_SUCCESS(status))
1485 {
1486 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[0] = pSession->connectedProfile.operationChannel;
1487 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 1;
1488 }
1489 else
1490 {
1491 break;
1492 }
1493 }
1494 }
1495 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301496 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001497 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
1498 if( !HAL_STATUS_SUCCESS( status ) )
1499 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001500 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001501 break;
1502 }
1503 } while( 0 );
1504
1505 if(!HAL_STATUS_SUCCESS(status))
1506 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001507 smsLog(pMac, LOGW, " csrScanRequestLostLink1 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001508 if(pCommand)
1509 {
1510 csrReleaseCommandScan(pMac, pCommand);
1511 }
1512 status = csrScanHandleFailedLostlink1( pMac, sessionId );
1513 }
1514 if(pScanFilter)
1515 {
1516 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301517 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001518 }
1519 if(hBSSList)
1520 {
1521 csrScanResultPurge(pMac, hBSSList);
1522 }
1523
1524 return( status );
1525}
1526
1527
1528//Lostlink2 scan is to actively scan the all SSIDs of the last roaming profile's on all matched BSS channels.
1529//Since MAC doesn't support multiple SSID, we scan all SSIDs and filter them afterwards
1530eHalStatus csrScanRequestLostLink2( tpAniSirGlobal pMac, tANI_U32 sessionId )
1531{
1532 eHalStatus status = eHAL_STATUS_SUCCESS;
1533 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1534 tCsrScanResultFilter *pScanFilter = NULL;
1535 tScanResultHandle hBSSList = NULL;
1536 tCsrScanResultInfo *pScanResult = NULL;
1537 tSmeCmd *pCommand = NULL;
1538 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1539
Jeff Johnson32d95a32012-09-10 13:15:23 -07001540 if(!pSession)
1541 {
1542 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1543 return eHAL_STATUS_FAILURE;
1544 }
1545
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001546 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001547 do
1548 {
1549 pCommand = csrGetCommandBuffer(pMac);
1550 if(!pCommand)
1551 {
1552 status = eHAL_STATUS_RESOURCES;
1553 break;
1554 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301555 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001556 pCommand->command = eSmeCommandScan;
1557 pCommand->sessionId = (tANI_U8)sessionId;
1558 pCommand->u.scanCmd.reason = eCsrScanLostLink2;
1559 pCommand->u.scanCmd.callback = NULL;
1560 pCommand->u.scanCmd.pContext = NULL;
1561 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1562 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Abhishek Singhadd13582016-09-29 17:00:03 +05301563 pCommand->u.scanCmd.u.scanRequest.max_chntime_btc_esco =
1564 pMac->roam.configParam.max_chntime_btc_esco;
1565 pCommand->u.scanCmd.u.scanRequest.min_chntime_btc_esco =
1566 pMac->roam.configParam.min_chntime_btc_esco;
Jeff Johnson295189b2012-06-20 16:38:30 -07001567 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
1568 if(pSession->pCurRoamProfile)
1569 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301570 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1571 if ( NULL == pScanFilter )
1572 status = eHAL_STATUS_FAILURE;
1573 else
1574 status = eHAL_STATUS_SUCCESS;
1575 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001576 {
1577 break;
1578 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301579 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001580 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
1581 if(!HAL_STATUS_SUCCESS(status))
1582 {
1583 break;
1584 }
1585 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1586 if(!HAL_STATUS_SUCCESS(status))
1587 {
1588 break;
1589 }
1590 if(hBSSList)
1591 {
1592 tANI_U8 i, nChn = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05301593 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList =
1594 vos_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
1595 if ( NULL == pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
1596 status = eHAL_STATUS_FAILURE;
1597 else
1598 status = eHAL_STATUS_SUCCESS;
1599 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001600 {
1601 break;
1602 }
1603 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) &&
1604 nChn < WNI_CFG_VALID_CHANNEL_LIST_LEN)
1605 {
1606 for(i = 0; i < nChn; i++)
1607 {
1608 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1609 pScanResult->BssDescriptor.channelId)
1610 {
1611 break;
1612 }
1613 }
1614 if(i == nChn)
1615 {
1616 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pScanResult->BssDescriptor.channelId;
1617 }
1618 }
1619 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nChn;
1620 }
1621 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301622 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001623 //Put to the head in pending queue
1624 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_TRUE);
1625 if( !HAL_STATUS_SUCCESS( status ) )
1626 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001627 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001628 break;
1629 }
1630 } while( 0 );
1631
1632 if(!HAL_STATUS_SUCCESS(status))
1633 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001634 smsLog(pMac, LOGW, " csrScanRequestLostLink2 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001635 if(pCommand)
1636 {
1637 csrReleaseCommandScan(pMac, pCommand);
1638 }
1639 status = csrScanHandleFailedLostlink2( pMac, sessionId );
1640 }
1641 if(pScanFilter)
1642 {
1643 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301644 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001645 }
1646 if(hBSSList)
1647 {
1648 csrScanResultPurge(pMac, hBSSList);
1649 }
1650
1651 return( status );
1652}
1653
1654
1655//To actively scan all valid channels
1656eHalStatus csrScanRequestLostLink3( tpAniSirGlobal pMac, tANI_U32 sessionId )
1657{
1658 eHalStatus status = eHAL_STATUS_SUCCESS;
1659 tSmeCmd *pCommand;
1660 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1661
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001662 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001663 do
1664 {
1665 pCommand = csrGetCommandBuffer(pMac);
1666 if(!pCommand)
1667 {
1668 status = eHAL_STATUS_RESOURCES;
1669 break;
1670 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301671 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001672 pCommand->command = eSmeCommandScan;
1673 pCommand->sessionId = (tANI_U8)sessionId;
1674 pCommand->u.scanCmd.reason = eCsrScanLostLink3;
1675 pCommand->u.scanCmd.callback = NULL;
1676 pCommand->u.scanCmd.pContext = NULL;
1677 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1678 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Abhishek Singhadd13582016-09-29 17:00:03 +05301679 pCommand->u.scanCmd.u.scanRequest.max_chntime_btc_esco =
1680 pMac->roam.configParam.max_chntime_btc_esco;
1681 pCommand->u.scanCmd.u.scanRequest.min_chntime_btc_esco =
1682 pMac->roam.configParam.min_chntime_btc_esco;
Jeff Johnson295189b2012-06-20 16:38:30 -07001683 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Kiet Lam64c1b492013-07-12 13:56:44 +05301684 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001685 //Put to the head of pending queue
1686 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_TRUE);
1687 if( !HAL_STATUS_SUCCESS( status ) )
1688 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001689 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001690 break;
1691 }
1692 } while( 0 );
1693 if(!HAL_STATUS_SUCCESS(status))
1694 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001695 smsLog(pMac, LOGW, " csrScanRequestLostLink3 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001696 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1697 {
1698 csrScanStartIdleScan(pMac);
1699 }
1700 if(pCommand)
1701 {
1702 csrReleaseCommandScan(pMac, pCommand);
1703 }
1704 }
1705
1706 return( status );
1707}
1708
1709
1710eHalStatus csrScanHandleSearchForSSID(tpAniSirGlobal pMac, tSmeCmd *pCommand)
1711{
1712 eHalStatus status = eHAL_STATUS_FAILURE;
1713 tScanResultHandle hBSSList = CSR_INVALID_SCANRESULT_HANDLE;
1714 tCsrScanResultFilter *pScanFilter = NULL;
1715 tCsrRoamProfile *pProfile = pCommand->u.scanCmd.pToRoamProfile;
1716 tANI_U32 sessionId = pCommand->sessionId;
Abhishek Singhd61b97a2015-12-17 15:23:52 +05301717 tCsrRoamSession *pSession = CSR_GET_SESSION(pMac, sessionId);
1718
Jeff Johnson295189b2012-06-20 16:38:30 -07001719 do
1720 {
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001721#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
1722 //if this scan is for LFR
1723 if(pMac->roam.neighborRoamInfo.uOsRequestedHandoff)
1724 {
1725 //notify LFR state m/c
1726 if(eHAL_STATUS_SUCCESS != csrNeighborRoamSssidScanDone(pMac, eHAL_STATUS_SUCCESS))
1727 {
Mukul Sharma20aa6582014-08-07 21:36:12 +05301728 csrNeighborRoamStartLfrScan(pMac, REASON_OS_REQUESTED_ROAMING_NOW);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001729 }
1730 status = eHAL_STATUS_SUCCESS;
1731 break;
1732 }
1733#endif
Abhishek Singhd61b97a2015-12-17 15:23:52 +05301734 if (!pSession)
1735 {
1736 smsLog(pMac, LOGE, FL("session %d not found"), sessionId);
1737 break;
1738 }
Abhishek Singh5de9efd2017-06-15 10:22:39 +05301739 /* If Disconnect is already issued from HDD no need to issue connect */
1740 if (pSession->abortConnection)
Abhishek Singhd61b97a2015-12-17 15:23:52 +05301741 {
1742 smsLog(pMac, LOGE,
1743 FL("Disconnect in progress, no need to issue connect"));
1744 break;
1745 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001746 //If there is roam command waiting, ignore this roam because the newer roam command is the one to execute
1747 if(csrIsRoamCommandWaitingForSession(pMac, sessionId))
1748 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001749 smsLog(pMac, LOGW, FL(" aborts because roam command waiting"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001750 break;
1751 }
1752 if(pProfile == NULL)
1753 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301754 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1755 if ( NULL == pScanFilter )
1756 status = eHAL_STATUS_FAILURE;
1757 else
1758 status = eHAL_STATUS_SUCCESS;
1759 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001760 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301761 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001762 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1763 if(!HAL_STATUS_SUCCESS(status))
1764 break;
1765 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1766 if(!HAL_STATUS_SUCCESS(status))
1767 break;
1768 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList, eCsrHddIssued,
1769 pCommand->u.scanCmd.roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1770 if(!HAL_STATUS_SUCCESS(status))
1771 {
1772 break;
1773 }
1774 }while(0);
1775 if(!HAL_STATUS_SUCCESS(status))
1776 {
1777 if(CSR_INVALID_SCANRESULT_HANDLE != hBSSList)
1778 {
1779 csrScanResultPurge(pMac, hBSSList);
1780 }
1781 //We haven't done anything to this profile
Abhishek Singh72c2f4e2016-07-22 11:25:43 +05301782 csrRoamCallCallback(pMac, sessionId, NULL,
1783 pCommand->u.scanCmd.roamId,
1784 eCSR_ROAM_ASSOCIATION_FAILURE,
1785 eCSR_ROAM_RESULT_SCAN_FOR_SSID_FAILURE);
Jeff Johnson295189b2012-06-20 16:38:30 -07001786 //In case we have nothing else to do, restart idle scan
1787 if(csrIsConnStateDisconnected(pMac, sessionId) && !csrIsRoamCommandWaiting(pMac))
1788 {
1789 status = csrScanStartIdleScan(pMac);
1790 }
1791#ifdef FEATURE_WLAN_BTAMP_UT_RF
1792 //In case of WDS station, let it retry.
1793 if( CSR_IS_WDS_STA(pProfile) )
1794 {
1795 //Save the roma profile so we can retry
1796 csrFreeRoamProfile( pMac, sessionId );
Kiet Lam64c1b492013-07-12 13:56:44 +05301797 pSession->pCurRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1798 if ( NULL != pSession->pCurRoamProfile )
Jeff Johnson295189b2012-06-20 16:38:30 -07001799 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301800 vos_mem_set(pSession->pCurRoamProfilee, sizeof(tCsrRoamProfile), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001801 csrRoamCopyProfile(pMac, pSession->pCurRoamProfile, pProfile);
1802 }
1803 csrRoamStartJoinRetryTimer(pMac, sessionId, CSR_JOIN_RETRY_TIMEOUT_PERIOD);
1804 }
1805#endif
1806 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301807 if (pScanFilter)
Jeff Johnson295189b2012-06-20 16:38:30 -07001808 {
1809 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301810 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001811 }
1812
1813 return (status);
1814}
1815
1816
1817eHalStatus csrScanHandleSearchForSSIDFailure(tpAniSirGlobal pMac, tSmeCmd *pCommand)
1818{
1819 eHalStatus status = eHAL_STATUS_SUCCESS;
1820 tANI_U32 sessionId = pCommand->sessionId;
1821 tCsrRoamProfile *pProfile = pCommand->u.scanCmd.pToRoamProfile;
1822 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001823#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
1824 //if this scan is for LFR
1825 if(pMac->roam.neighborRoamInfo.uOsRequestedHandoff)
1826 {
1827 //notify LFR state m/c
1828 if(eHAL_STATUS_SUCCESS != csrNeighborRoamSssidScanDone(pMac, eHAL_STATUS_FAILURE))
1829 {
Mukul Sharma20aa6582014-08-07 21:36:12 +05301830 csrNeighborRoamStartLfrScan(pMac, REASON_OS_REQUESTED_ROAMING_NOW);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001831 }
1832 return eHAL_STATUS_SUCCESS;
1833 }
1834#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -07001835 if(!pSession)
1836 {
1837 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1838 return eHAL_STATUS_FAILURE;
1839 }
1840
Jeff Johnson295189b2012-06-20 16:38:30 -07001841#if defined(WLAN_DEBUG)
1842 if(pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs == 1)
1843 {
1844 char str[36];
Kiet Lam64c1b492013-07-12 13:56:44 +05301845 vos_mem_copy(str,
1846 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.ssId,
1847 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.length);
Jeff Johnson295189b2012-06-20 16:38:30 -07001848 str[pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.length] = 0;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001849 smsLog(pMac, LOGW, FL(" SSID = %s"), str);
Jeff Johnson295189b2012-06-20 16:38:30 -07001850 }
1851#endif
1852 //Check whether it is for start ibss. No need to do anything if it is a JOIN request
1853 if(pProfile && CSR_IS_START_IBSS(pProfile))
1854 {
1855 status = csrRoamIssueConnect(pMac, sessionId, pProfile, NULL, eCsrHddIssued,
1856 pCommand->u.scanCmd.roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1857 if(!HAL_STATUS_SUCCESS(status))
1858 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001859 smsLog(pMac, LOGE, FL("failed to issue startIBSS command with status = 0x%08X"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001860 csrRoamCallCallback(pMac, sessionId, NULL, pCommand->u.scanCmd.roamId, eCSR_ROAM_FAILED, eCSR_ROAM_RESULT_FAILURE);
1861 }
1862 }
1863 else
1864 {
1865 eCsrRoamResult roamResult = eCSR_ROAM_RESULT_FAILURE;
1866
1867 if(csrIsConnStateDisconnected(pMac, sessionId) &&
1868 !csrIsRoamCommandWaitingForSession(pMac, sessionId))
1869 {
1870 status = csrScanStartIdleScan(pMac);
1871 }
1872 if((NULL == pProfile) || !csrIsBssTypeIBSS(pProfile->BSSType))
1873 {
1874 //Only indicate assoc_completion if we indicate assoc_start.
1875 if(pSession->bRefAssocStartCnt > 0)
1876 {
1877 tCsrRoamInfo *pRoamInfo = NULL, roamInfo;
Kiet Lam64c1b492013-07-12 13:56:44 +05301878 vos_mem_set(&roamInfo, sizeof(tCsrRoamInfo), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001879 pRoamInfo = &roamInfo;
1880 if(pCommand->u.roamCmd.pRoamBssEntry)
1881 {
1882 tCsrScanResult *pScanResult =
1883 GET_BASE_ADDR(pCommand->u.roamCmd.pRoamBssEntry,
1884 tCsrScanResult, Link);
1885 roamInfo.pBssDesc = &pScanResult->Result.BssDescriptor;
1886 }
1887 roamInfo.statusCode = pSession->joinFailStatusCode.statusCode;
1888 roamInfo.reasonCode = pSession->joinFailStatusCode.reasonCode;
1889 pSession->bRefAssocStartCnt--;
1890 csrRoamCallCallback(pMac, sessionId, pRoamInfo,
1891 pCommand->u.scanCmd.roamId,
1892 eCSR_ROAM_ASSOCIATION_COMPLETION,
Abhishek Singh72c2f4e2016-07-22 11:25:43 +05301893 eCSR_ROAM_RESULT_SCAN_FOR_SSID_FAILURE);
Jeff Johnson295189b2012-06-20 16:38:30 -07001894 }
Madan Mohan Koyyalamudiee255f12012-09-28 15:41:19 -07001895 else
1896 {
1897 csrRoamCallCallback(pMac, sessionId, NULL,
1898 pCommand->u.scanCmd.roamId,
1899 eCSR_ROAM_ASSOCIATION_FAILURE,
Abhishek Singh72c2f4e2016-07-22 11:25:43 +05301900 eCSR_ROAM_RESULT_SCAN_FOR_SSID_FAILURE);
Madan Mohan Koyyalamudiee255f12012-09-28 15:41:19 -07001901 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001902#ifdef FEATURE_WLAN_BTAMP_UT_RF
1903 //In case of WDS station, let it retry.
1904 if( CSR_IS_WDS_STA(pProfile) )
1905 {
1906 //Save the roma profile so we can retry
1907 csrFreeRoamProfile( pMac, sessionId );
Kiet Lam64c1b492013-07-12 13:56:44 +05301908 pSession->pCurRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1909 if ( NULL != pSession->pCurRoamProfile )
Jeff Johnson295189b2012-06-20 16:38:30 -07001910 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301911 vos_mem_set(pSession->pCurRoamProfile, sizeof(tCsrRoamProfile), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001912 csrRoamCopyProfile(pMac, pSession->pCurRoamProfile, pProfile);
1913 }
1914 csrRoamStartJoinRetryTimer(pMac, sessionId, CSR_JOIN_RETRY_TIMEOUT_PERIOD);
1915 }
1916#endif
1917 }
1918 else
1919 {
1920 roamResult = eCSR_ROAM_RESULT_IBSS_START_FAILED;
1921 }
1922 csrRoamCompletion(pMac, sessionId, NULL, pCommand, roamResult, eANI_BOOLEAN_FALSE);
1923 }
1924
1925 return (status);
1926}
1927
1928
1929//After scan for cap changes, issue a roaming command to either reconnect to the AP or pick another one to connect
1930eHalStatus csrScanHandleCapChangeScanComplete(tpAniSirGlobal pMac, tANI_U32 sessionId)
1931{
1932 eHalStatus status = eHAL_STATUS_FAILURE;
1933 tScanResultHandle hBSSList = NULL;
1934 tCsrScanResultFilter *pScanFilter = NULL;
1935 tANI_U32 roamId = 0;
1936 tCsrRoamProfile *pProfile = NULL;
1937 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1938
1939 do
1940 {
1941 //Here is the profile we need to connect to
Kiet Lam64c1b492013-07-12 13:56:44 +05301942 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1943 if ( NULL == pScanFilter )
1944 status = eHAL_STATUS_FAILURE;
1945 else
1946 status = eHAL_STATUS_SUCCESS;
1947 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001948 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301949 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
1950 if (NULL == pSession) break;
1951 if (NULL == pSession->pCurRoamProfile)
Jeff Johnson295189b2012-06-20 16:38:30 -07001952 {
1953 pScanFilter->EncryptionType.numEntries = 1;
1954 pScanFilter->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_NONE;
1955 }
1956 else
1957 {
1958 //We have to make a copy of pCurRoamProfile because it will be free inside csrRoamIssueConnect
Kiet Lam64c1b492013-07-12 13:56:44 +05301959 pProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1960 if ( NULL == pProfile )
1961 status = eHAL_STATUS_FAILURE;
1962 else
1963 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001964 if(!HAL_STATUS_SUCCESS(status))
1965 break;
1966 status = csrRoamCopyProfile(pMac, pProfile, pSession->pCurRoamProfile);
1967 if(!HAL_STATUS_SUCCESS(status))
1968 break;
1969 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1970 }//We have a profile
1971 roamId = GET_NEXT_ROAM_ID(&pMac->roam);
1972 if(HAL_STATUS_SUCCESS(status))
1973 {
1974 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1975 if(HAL_STATUS_SUCCESS(status))
1976 {
1977 //we want to put the last connected BSS to the very beginning, if possible
1978 csrMoveBssToHeadFromBSSID(pMac, &pSession->connectedProfile.bssid, hBSSList);
1979 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList,
1980 eCsrCapsChange, 0, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1981 if(!HAL_STATUS_SUCCESS(status))
1982 {
1983 csrScanResultPurge(pMac, hBSSList);
1984 }
1985 }//Have scan result
1986 else
1987 {
Arif Hussaina7c8e412013-11-20 11:06:42 -08001988 smsLog(pMac, LOGW, FL("cannot find matching BSS of "
1989 MAC_ADDRESS_STR),
1990 MAC_ADDR_ARRAY(pSession->connectedProfile.bssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001991 //Disconnect
1992 csrRoamDisconnectInternal(pMac, sessionId, eCSR_DISCONNECT_REASON_UNSPECIFIED);
1993 }
1994 }
1995 }while(0);
1996 if(pScanFilter)
1997 {
1998 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301999 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07002000 }
2001 if(NULL != pProfile)
2002 {
2003 csrReleaseProfile(pMac, pProfile);
Kiet Lam64c1b492013-07-12 13:56:44 +05302004 vos_mem_free(pProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07002005 }
2006
2007 return (status);
2008}
2009
2010
2011
2012eHalStatus csrScanResultPurge(tpAniSirGlobal pMac, tScanResultHandle hScanList)
2013{
2014 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
2015 tScanResultList *pScanList = (tScanResultList *)hScanList;
2016
2017 if(pScanList)
2018 {
2019 status = csrLLScanPurgeResult(pMac, &pScanList->List);
2020 csrLLClose(&pScanList->List);
Kiet Lam64c1b492013-07-12 13:56:44 +05302021 vos_mem_free(pScanList);
Jeff Johnson295189b2012-06-20 16:38:30 -07002022 }
2023 return (status);
2024}
2025
2026
2027static tANI_U32 csrGetBssPreferValue(tpAniSirGlobal pMac, int rssi)
2028{
2029 tANI_U32 ret = 0;
2030 int i = CSR_NUM_RSSI_CAT - 1;
2031
2032 while(i >= 0)
2033 {
2034 if(rssi >= pMac->roam.configParam.RSSICat[i])
2035 {
2036 ret = pMac->roam.configParam.BssPreferValue[i];
2037 break;
2038 }
2039 i--;
2040 };
2041
2042 return (ret);
2043}
2044
2045
2046//Return a CapValue base on the capabilities of a BSS
2047static tANI_U32 csrGetBssCapValue(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes)
2048{
2049 tANI_U32 ret = CSR_BSS_CAP_VALUE_NONE;
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08002050#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_ESE) || defined(FEATURE_WLAN_LFR)
Madan Mohan Koyyalamudid5026072012-11-30 14:56:21 -08002051 if(CSR_IS_ROAM_PREFER_5GHZ(pMac))
2052 {
2053 if((pBssDesc) && CSR_IS_CHANNEL_5GHZ(pBssDesc->channelId))
2054 {
2055 ret += CSR_BSS_CAP_VALUE_5GHZ;
2056 }
2057 }
2058#endif
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002059 /* if strict select 5GHz is non-zero then ignore the capability checking */
2060 if (pIes && !CSR_IS_SELECT_5GHZ_MARGIN(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -07002061 {
2062 //We only care about 11N capability
2063 if(pIes->HTCaps.present)
2064 {
2065 ret += CSR_BSS_CAP_VALUE_HT;
2066 }
2067 if(CSR_IS_QOS_BSS(pIes))
2068 {
2069 ret += CSR_BSS_CAP_VALUE_WMM;
2070 //Give advantage to UAPSD
2071 if(CSR_IS_UAPSD_BSS(pIes))
2072 {
2073 ret += CSR_BSS_CAP_VALUE_UAPSD;
2074 }
2075 }
2076 }
2077
2078 return (ret);
2079}
2080
Kapil Guptab3a981b2016-06-26 13:36:51 +05302081#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
2082
2083/* Calculate channel weight based on other APs RSSI and count for
2084 * PER based roaming */
2085static tANI_U32 GetPERRoamRssiCountWeight(tANI_S32 rssi, tANI_S32 count)
2086{
2087 tANI_S32 rssiWeight=0;
2088 tANI_S32 countWeight=0;
2089 tANI_S32 rssicountWeight=0;
2090
2091 rssiWeight = ROAMING_RSSI_WEIGHT * (rssi - MIN_RSSI)
2092 /(MAX_RSSI - MIN_RSSI);
2093
2094 if(rssiWeight > ROAMING_RSSI_WEIGHT)
2095 rssiWeight = ROAMING_RSSI_WEIGHT;
2096 else if (rssiWeight < 0)
2097 rssiWeight = 0;
2098
2099 countWeight = ROAM_AP_COUNT_WEIGHT * (count + ROAM_MIN_COUNT)
2100 /(ROAM_MAX_COUNT + ROAM_MIN_COUNT);
2101
2102 if(countWeight > ROAM_AP_COUNT_WEIGHT)
2103 countWeight = ROAM_AP_COUNT_WEIGHT;
2104
2105 rssicountWeight = ROAM_MAX_WEIGHT - (rssiWeight + countWeight);
2106
2107 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO_HIGH,
2108 FL("rssiWeight=%d, countWeight=%d, rssicountWeight=%d rssi=%d count=%d"),
2109 rssiWeight, countWeight, rssicountWeight, rssi, count);
2110
2111 return rssicountWeight;
2112}
2113
2114/* Calculate BSS score based on AP capabilty and channel condition
2115 * for PER based roaming */
2116static tANI_U32 calculateBssScore(tSirBssDescription *bssInfo,
2117 tANI_S32 best_rssi, tANI_S32 ap_cnt, tANI_S32 cca)
2118{
2119 tANI_S32 score = 0;
2120 tANI_S32 ap_load = 0;
2121 tANI_S32 normalised_width = PER_ROAM_20MHZ;
Sen, Devendra6940d0c2016-09-07 12:42:46 +05302122 tANI_S32 normalised_rssi = 0;
Kapil Guptab3a981b2016-06-26 13:36:51 +05302123 tANI_S32 channel_weight;
2124 if (bssInfo->rssi) {
2125 /* Calculate % of rssi we are getting
2126 * max = 100
2127 * min = 0
2128 * less than -40 = 100%
2129 * -40 - -55 = 80%
2130 * -55 - -65 = 60%
2131 * below that = 100 - value
2132 * TODO: a linear decrement function after PER_ROAM_GOOD_RSSI_WEIGHT
2133 * since throughput decrements linearly after PER_ROAM_GOOD_RSSI_WEIGHT
2134 **/
2135 if (bssInfo->rssi >= PER_EXCELENT_RSSI)
2136 normalised_rssi = PER_ROAM_EXCELLENT_RSSI_WEIGHT;
2137 else if (bssInfo->rssi >= PER_GOOD_RSSI)
2138 normalised_rssi = PER_ROAM_GOOD_RSSI_WEIGHT;
2139 else if (bssInfo->rssi >= PER_POOR_RSSI)
2140 normalised_rssi = PER_ROAM_BAD_RSSI_WEIGHT;
2141 else
2142 normalised_rssi = bssInfo->rssi - MIN_RSSI;
2143
2144 /* Calculate score part for rssi */
2145 score += (normalised_rssi * RSSI_WEIGHTAGE);
2146 }
2147
2148 if (bssInfo->HTCapsPresent) {
2149 score += PER_ROAM_MAX_WEIGHT * HT_CAPABILITY_WEIGHTAGE;
2150 }
2151 /* VHT caps are available */
2152 if (bssInfo->vhtCapsPresent) {
2153 score += PER_ROAM_MAX_WEIGHT * VHT_CAP_WEIGHTAGE;
2154 }
2155
2156 if (bssInfo->beacomformingCapable)
2157 score += PER_ROAM_MAX_WEIGHT * BEAMFORMING_CAP_WEIGHTAGE;
2158
2159 /* Channel width 20Mhz=30, 40Mhz=70, 80Mhz=100 */
2160 if (bssInfo->chanWidth == eHT_CHANNEL_WIDTH_80MHZ)
2161 normalised_width = PER_ROAM_80MHZ;
2162 else if (bssInfo->chanWidth == eHT_CHANNEL_WIDTH_40MHZ)
2163 normalised_width = PER_ROAM_40MHZ;
2164 else
2165 normalised_width = PER_ROAM_20MHZ;
2166 score += normalised_width * CHAN_WIDTH_WEIGHTAGE;
2167
2168 /* Channel Band, Channel Number */
2169 if (GetRFBand(bssInfo->channelId) == SIR_BAND_5_GHZ)
2170 score += PER_ROAM_MAX_WEIGHT * CHAN_BAND_WEIGHTAGE;
2171
2172 /* WMM emabled */
2173 if (bssInfo->wmeInfoPresent)
2174 score += PER_ROAM_MAX_WEIGHT * WMM_WEIGHTAGE;
2175
2176#if defined(FEATURE_WLAN_ESE) || defined(WLAN_FEATURE_ROAM_SCAN_OFFLOAD)
2177 /* AP load Ie */
2178 if (bssInfo->QBSSLoad_present) {
2179 /* calculate value in % */
2180 ap_load = (bssInfo->QBSS_ChanLoad * PER_ROAM_MAX_WEIGHT) / MAX_AP_LOAD;
2181 }
2182#endif
Kapil Guptab3a981b2016-06-26 13:36:51 +05302183 /* if CCA consideration is off in configuration, FW will send 50% for
2184 every channel which should be considered as it is */
2185 if (ap_load)
2186 score += (100 - ap_load) * CCA_WEIGHTAGE;
2187 else
2188 score += (100 - cca) * CCA_WEIGHTAGE;
2189
2190 channel_weight = GetPERRoamRssiCountWeight(best_rssi, ap_cnt);
2191
2192 score += channel_weight * OTHER_AP_WEIGHT;
2193
2194 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO_LOW,
2195 FL("rssi=%d normalized_rssi=%d htcaps=%d vht=%d bw=%d channel=%d wmm=%d beamforming=%d ap_load=%d channel_weight=%d"),
2196 bssInfo->rssi, normalised_rssi, bssInfo->HTCapsPresent,
2197 bssInfo->vhtCapsPresent, bssInfo->chanWidth,
2198 bssInfo->channelId, bssInfo->wmeInfoPresent,
2199 bssInfo->beacomformingCapable, ap_load, channel_weight);
2200 return score;
2201}
2202
2203/* Calculate candidate AP score for PER based roaming */
2204static tANI_S32 csrFindCongestionScore (tpAniSirGlobal pMac, tCsrScanResult *pBss)
2205{
2206 tANI_S32 score = 0;
2207 tANI_S32 i;
2208 tANI_S32 candidateApCnt, best_rssi, other_ap_cnt;
2209 tANI_U32 current_timestamp;
2210 tpCsrNeighborRoamControlInfo pNeighborRoamInfo =
2211 &pMac->roam.neighborRoamInfo;
2212
2213 tSirBssDescription *bssInfo = &(pBss->Result.BssDescriptor);
2214 pBss->congestionScore = 0;
2215 for (i = 0; i < pMac->PERroamCandidatesCnt; i++)
2216 if (pMac->candidateChannelInfo[i].channelNumber ==
2217 pBss->Result.BssDescriptor.channelId)
2218 break;
2219
2220 if (i == SIR_PER_ROAM_MAX_CANDIDATE_CNT) {
2221 smsLog(pMac, LOGE,
2222 FL("candidate chan info not found for channel %d bssid "
2223 MAC_ADDRESS_STR), pBss->Result.BssDescriptor.channelId,
2224 MAC_ADDR_ARRAY(pBss->Result.BssDescriptor.bssId));
2225 return -1;
2226 }
2227
Kapil Gupta192d9d42016-11-25 16:24:13 +05302228 if (bssInfo->rssi < pMac->roam.configParam.PERMinRssiThresholdForRoam) {
Kapil Guptaa040e772016-09-15 19:03:45 +05302229 smsLog(pMac, LOG1,
Kapil Guptae2b5c092017-02-06 15:04:47 +05302230 FL("discarding candidate due to low rssi=%d than %d, bssid "
Kapil Guptaa040e772016-09-15 19:03:45 +05302231 MAC_ADDRESS_STR), bssInfo->rssi,
Kapil Guptae2b5c092017-02-06 15:04:47 +05302232 pMac->roam.configParam.PERMinRssiThresholdForRoam,
Kapil Guptaa040e772016-09-15 19:03:45 +05302233 MAC_ADDR_ARRAY(pBss->Result.BssDescriptor.bssId));
2234 return 0;
2235 }
Kapil Guptab3a981b2016-06-26 13:36:51 +05302236 /* find best RSSI of other AP in this channel */
2237 best_rssi = MIN_RSSI;
2238 for (other_ap_cnt = 0; other_ap_cnt <
2239 pMac->candidateChannelInfo[i].otherApCount; other_ap_cnt++) {
2240 if (pMac->candidateChannelInfo[i].otherApRssi[other_ap_cnt] > best_rssi)
2241 best_rssi = pMac->candidateChannelInfo[i].otherApRssi[other_ap_cnt];
2242 }
2243
2244 score = calculateBssScore(bssInfo, best_rssi,
2245 pMac->candidateChannelInfo[i].otherApCount,
2246 pMac->candidateChannelInfo[i].channelCCA);
2247 current_timestamp = jiffies_to_msecs(jiffies);
2248
2249 /* penalty logic */
2250
2251 /* In the previous list */
2252 for (candidateApCnt = 0; candidateApCnt <
2253 SIR_PER_ROAM_MAX_CANDIDATE_CNT; candidateApCnt++) {
2254 if (sirCompareMacAddr(pMac->previousRoamApInfo[candidateApCnt].bssAddr,
2255 pBss->Result.BssDescriptor.bssId) &&
2256 ((current_timestamp - pMac->previousRoamApInfo[candidateApCnt].timeStamp) <
2257 PENALTY_TIMEOUT)) {
2258 score = (score * PENALTY_REMAINING_SCORE)/PENALTY_TOTAL_SCORE;
2259 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
2260 FL("AP BSSID " MAC_ADDRESS_STR "adding penalty(in previous list)new score %d"),
2261 MAC_ADDR_ARRAY(pBss->Result.BssDescriptor.bssId),
2262 score);
2263 break;
2264 }
2265 }
2266 /* preauth failed last time */
2267 for (candidateApCnt = 0; candidateApCnt <
2268 MAX_NUM_PREAUTH_FAIL_LIST_ADDRESS; candidateApCnt++) {
2269 if (sirCompareMacAddr(pNeighborRoamInfo->FTRoamInfo.
2270 preAuthFailList.macAddress[candidateApCnt],
2271 pBss->Result.BssDescriptor.bssId)) {
2272 score = (score * PENALTY_REMAINING_SCORE)/PENALTY_TOTAL_SCORE;
2273 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
2274 FL("AP BSSID " MAC_ADDRESS_STR "adding penalty(previously auth failed)new score %d"),
2275 MAC_ADDR_ARRAY(pBss->Result.BssDescriptor.bssId),
2276 score);
2277 break;
2278 }
2279 }
2280 pBss->congestionScore = score;
2281
2282 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
2283 FL("AP BSSID " MAC_ADDRESS_STR " score %d channel %d"),
2284 MAC_ADDR_ARRAY(pBss->Result.BssDescriptor.bssId),
2285 score, pBss->Result.BssDescriptor.channelId);
2286 return 0;
2287}
2288
2289/* Calculate current AP score for PER based roaming */
2290static tANI_S32 csrFindSelfCongestionScore(tpAniSirGlobal pMac,
2291 tSirBssDescription *bssInfo)
2292{
2293 tANI_S32 i, best_rssi, other_ap_cnt;
2294 tANI_S32 score = 0;
Kapil Guptac6ac4772016-08-05 20:25:16 +05302295 tCsrRoamSession *pSession = CSR_GET_SESSION(pMac,
2296 pMac->roam.roamSession->sessionId);
2297
2298 if (pSession == NULL)
2299 return -1;
Kapil Guptab3a981b2016-06-26 13:36:51 +05302300
Kapil Guptac3c48262017-03-09 18:05:51 +05302301 if (bssInfo->rssi < pMac->roam.configParam.PERMinRssiThresholdForRoam) {
2302 smsLog(pMac, LOG1,
2303 FL("Current AP has low rssi=%d than %d"), bssInfo->rssi,
2304 pMac->roam.configParam.PERMinRssiThresholdForRoam);
2305 /*
2306 * Make Current candidate score as zero which will cause roaming
2307 * in low RSSI scenarios
2308 */
2309 pMac->currentBssScore = 0;
2310 return 0;
2311 }
2312
Kapil Guptab3a981b2016-06-26 13:36:51 +05302313 for (i = 0; i <= pMac->PERroamCandidatesCnt; i++)
2314 if (pMac->candidateChannelInfo[i].channelNumber == bssInfo->channelId)
2315 break;
2316 if (i > pMac->PERroamCandidatesCnt) {
2317 /* home channel info is not present, no need to roam */
2318 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR,
2319 FL("home channel %d congestion info not present"),
2320 bssInfo->channelId);
2321 pMac->currentBssScore = PER_ROAM_MAX_BSS_SCORE;
2322 return -1;
2323 }
2324
2325 /* find best RSSI of other AP in this channel */
2326 best_rssi = MIN_RSSI;
2327 for (other_ap_cnt = 0; other_ap_cnt <
2328 pMac->candidateChannelInfo[i].otherApCount; other_ap_cnt++) {
2329 if (pMac->candidateChannelInfo[i].otherApRssi[other_ap_cnt] > best_rssi)
2330 best_rssi = pMac->candidateChannelInfo[i].otherApRssi[other_ap_cnt];
2331 }
2332
Kapil Guptac6ac4772016-08-05 20:25:16 +05302333 /* update latest RSSI for current AP */
2334 WLANTL_GetRssi(vos_get_global_context(VOS_MODULE_ID_SME, NULL),
2335 pSession->connectedInfo.staId,
2336 &bssInfo->rssi);
2337
Kapil Guptab3a981b2016-06-26 13:36:51 +05302338 score = calculateBssScore(bssInfo, best_rssi,
2339 pMac->candidateChannelInfo[i].otherApCount,
2340 pMac->candidateChannelInfo[i].channelCCA);
2341 pMac->currentBssScore = score;
2342 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
2343 FL("PER Roam Current AP score %d channel %d"),
2344 score, bssInfo->channelId);
2345 return 0;
2346}
2347
Kapil Guptab79e76f2016-09-12 20:04:37 +05302348
Kapil Guptab3a981b2016-06-26 13:36:51 +05302349static tANI_BOOLEAN csrIsBetterBssInCongestion(tCsrScanResult *pBss1,
2350 tCsrScanResult *pBss2)
2351{
2352 tANI_BOOLEAN ret;
2353
2354 if(CSR_IS_BETTER_PREFER_VALUE(pBss1->congestionScore,
2355 pBss2->congestionScore))
2356 ret = eANI_BOOLEAN_TRUE;
2357 else
2358 ret = eANI_BOOLEAN_FALSE;
2359
2360 return (ret);
2361}
2362#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002363
2364//To check whther pBss1 is better than pBss2
2365static tANI_BOOLEAN csrIsBetterBss(tCsrScanResult *pBss1, tCsrScanResult *pBss2)
2366{
2367 tANI_BOOLEAN ret;
2368
2369 if(CSR_IS_BETTER_PREFER_VALUE(pBss1->preferValue, pBss2->preferValue))
2370 {
2371 ret = eANI_BOOLEAN_TRUE;
2372 }
2373 else if(CSR_IS_EQUAL_PREFER_VALUE(pBss1->preferValue, pBss2->preferValue))
2374 {
2375 if(CSR_IS_BETTER_CAP_VALUE(pBss1->capValue, pBss2->capValue))
2376 {
2377 ret = eANI_BOOLEAN_TRUE;
2378 }
2379 else
2380 {
2381 ret = eANI_BOOLEAN_FALSE;
2382 }
2383 }
2384 else
2385 {
2386 ret = eANI_BOOLEAN_FALSE;
2387 }
2388
2389 return (ret);
2390}
2391
2392
Srikant Kuppa866893f2012-12-27 17:28:14 -08002393#ifdef FEATURE_WLAN_LFR
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002394//Add the channel to the occupiedChannels array
2395static void csrScanAddToOccupiedChannels(
Srikant Kuppa866893f2012-12-27 17:28:14 -08002396 tpAniSirGlobal pMac,
2397 tCsrScanResult *pResult,
2398 tCsrChannel *pOccupiedChannels,
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002399 tDot11fBeaconIEs *pIes)
2400{
2401 eHalStatus status;
2402 tANI_U8 channel;
2403 tANI_U8 numOccupiedChannels = pOccupiedChannels->numChannels;
2404 tANI_U8 *pOccupiedChannelList = pOccupiedChannels->channelList;
2405
2406 channel = pResult->Result.BssDescriptor.channelId;
2407
2408 if (!csrIsChannelPresentInList(pOccupiedChannelList, numOccupiedChannels, channel)
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08002409 && csrNeighborRoamConnectedProfileMatch(pMac, pResult, pIes))
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002410 {
Srikant Kuppa866893f2012-12-27 17:28:14 -08002411 status = csrAddToChannelListFront(pOccupiedChannelList, numOccupiedChannels, channel);
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002412 if(HAL_STATUS_SUCCESS(status))
Srikant Kuppa866893f2012-12-27 17:28:14 -08002413 {
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002414 pOccupiedChannels->numChannels++;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002415 smsLog(pMac, LOG2, FL("%s: added channel %d to the list (count=%d)"),
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08002416 __func__, channel, pOccupiedChannels->numChannels);
Srikant Kuppa866893f2012-12-27 17:28:14 -08002417 if (pOccupiedChannels->numChannels > CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN)
2418 pOccupiedChannels->numChannels = CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN;
2419 }
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002420 }
2421}
Mukul Sharma9e4e0f92015-02-13 18:45:20 +05302422
2423void csrAddChannelToOccupiedChannelList(tpAniSirGlobal pMac,
2424 tANI_U8 channel)
2425{
2426 eHalStatus status;
2427 tCsrChannel *pOccupiedChannels = &pMac->scan.occupiedChannels;
2428 tANI_U8 numOccupiedChannels = pOccupiedChannels->numChannels;
2429 tANI_U8 *pOccupiedChannelList = pOccupiedChannels->channelList;
2430 if (!csrIsChannelPresentInList(pOccupiedChannelList,
2431 numOccupiedChannels, channel))
2432 {
2433 status = csrAddToChannelListFront(pOccupiedChannelList,
2434 numOccupiedChannels, channel);
2435 if(HAL_STATUS_SUCCESS(status))
2436 {
2437 pOccupiedChannels->numChannels++;
2438 smsLog(pMac, LOG2, FL("added channel %d to the list (count=%d)"),
2439 channel, pOccupiedChannels->numChannels);
2440 if (pOccupiedChannels->numChannels >
2441 CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN)
2442 {
2443 pOccupiedChannels->numChannels =
2444 CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN;
2445 smsLog(pMac, LOG2,
2446 FL("trim no of Channels for Occ channel list"));
2447 }
2448 }
2449 }
2450}
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002451#endif
2452
Jeff Johnson295189b2012-06-20 16:38:30 -07002453//Put the BSS into the scan result list
2454//pIes can not be NULL
2455static void csrScanAddResult(tpAniSirGlobal pMac, tCsrScanResult *pResult, tDot11fBeaconIEs *pIes)
2456{
Srinivas28b5b4e2012-12-12 13:07:53 -08002457#ifdef FEATURE_WLAN_LFR
2458 tpCsrNeighborRoamControlInfo pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
2459#endif
2460
Jeff Johnson295189b2012-06-20 16:38:30 -07002461 pResult->preferValue = csrGetBssPreferValue(pMac, (int)pResult->Result.BssDescriptor.rssi);
2462 pResult->capValue = csrGetBssCapValue(pMac, &pResult->Result.BssDescriptor, pIes);
2463 csrLLInsertTail( &pMac->scan.scanResultList, &pResult->Link, LL_ACCESS_LOCK );
Srikant Kuppa866893f2012-12-27 17:28:14 -08002464#ifdef FEATURE_WLAN_LFR
Srinivas28b5b4e2012-12-12 13:07:53 -08002465 if(0 == pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels)
2466 {
2467 /* Build the occupied channel list, only if "gNeighborScanChannelList" is
2468 NOT set in the cfg.ini file */
2469 csrScanAddToOccupiedChannels(pMac, pResult, &pMac->scan.occupiedChannels, pIes);
2470 }
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002471#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002472}
2473
2474
2475eHalStatus csrScanGetResult(tpAniSirGlobal pMac, tCsrScanResultFilter *pFilter, tScanResultHandle *phResult)
2476{
2477 eHalStatus status;
2478 tScanResultList *pRetList;
2479 tCsrScanResult *pResult, *pBssDesc;
2480 tANI_U32 count = 0;
2481 tListElem *pEntry;
2482 tANI_U32 bssLen, allocLen;
2483 eCsrEncryptionType uc = eCSR_ENCRYPT_TYPE_NONE, mc = eCSR_ENCRYPT_TYPE_NONE;
2484 eCsrAuthType auth = eCSR_AUTH_TYPE_OPEN_SYSTEM;
2485 tDot11fBeaconIEs *pIes, *pNewIes;
2486 tANI_BOOLEAN fMatch;
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002487 tANI_U16 i = 0;
Kapil Guptab3a981b2016-06-26 13:36:51 +05302488 tCsrRoamSession *pSession = CSR_GET_SESSION(pMac,
2489 pMac->roam.roamSession->sessionId);
2490
Jeff Johnson295189b2012-06-20 16:38:30 -07002491 if(phResult)
2492 {
2493 *phResult = CSR_INVALID_SCANRESULT_HANDLE;
2494 }
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002495
2496 if (pMac->roam.configParam.nSelect5GHzMargin)
2497 {
2498 pMac->scan.inScanResultBestAPRssi = -128;
2499 csrLLLock(&pMac->scan.scanResultList);
2500
2501 /* Find out the best AP Rssi going thru the scan results */
2502 pEntry = csrLLPeekHead(&pMac->scan.scanResultList, LL_ACCESS_NOLOCK);
2503 while ( NULL != pEntry)
2504 {
2505 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002506 fMatch = FALSE;
2507
2508 if (pFilter)
2509 for(i = 0; i < pFilter->SSIDs.numOfSSIDs; i++)
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002510 {
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002511 fMatch = csrIsSsidMatch( pMac, pFilter->SSIDs.SSIDList[i].SSID.ssId, pFilter->SSIDs.SSIDList[i].SSID.length,
2512 pBssDesc->Result.ssId.ssId,
2513 pBssDesc->Result.ssId.length, eANI_BOOLEAN_TRUE );
2514 if (fMatch)
2515 {
2516 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
2517
2518 //At this time, pBssDescription->Result.pvIes may be NULL
2519 if( !pIes && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
2520 &pBssDesc->Result.BssDescriptor, &pIes))) )
2521 {
2522 continue;
2523 }
2524
2525 smsLog(pMac, LOG1, FL("SSID Matched"));
Leela Venkata Kiran Kumar Reddy Chiralae208a832014-04-27 22:34:25 -07002526
Leela Venkata Kiran Kumar Reddy Chiralaf257bef2014-04-11 18:48:12 -07002527 if ( pFilter->bOSENAssociation )
2528 {
2529 fMatch = TRUE;
2530 }
Leela Venkata Kiran Kumar Reddy Chiralae208a832014-04-27 22:34:25 -07002531 else
2532 {
Abhishek Singh658d4de2014-06-26 10:53:15 +05302533#ifdef WLAN_FEATURE_11W
Abhishek Singh3b56d3a2014-06-25 12:37:39 +05302534 fMatch = csrIsSecurityMatch(pMac, &pFilter->authType,
2535 &pFilter->EncryptionType,
2536 &pFilter->mcEncryptionType,
2537 &pFilter->MFPEnabled,
2538 &pFilter->MFPRequired,
2539 &pFilter->MFPCapable,
2540 &pBssDesc->Result.BssDescriptor,
2541 pIes, NULL, NULL, NULL );
Abhishek Singh658d4de2014-06-26 10:53:15 +05302542#else
2543 fMatch = csrIsSecurityMatch(pMac, &pFilter->authType,
2544 &pFilter->EncryptionType,
2545 &pFilter->mcEncryptionType,
2546 NULL, NULL, NULL,
2547 &pBssDesc->Result.BssDescriptor,
2548 pIes, NULL, NULL, NULL );
2549#endif
Leela Venkata Kiran Kumar Reddy Chiralae208a832014-04-27 22:34:25 -07002550 }
2551 if ((pBssDesc->Result.pvIes == NULL) && pIes)
2552 vos_mem_free(pIes);
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002553
2554 if (fMatch)
2555 smsLog(pMac, LOG1, FL(" Security Matched"));
2556 }
2557 }
2558
2559 if (fMatch && (pBssDesc->Result.BssDescriptor.rssi > pMac->scan.inScanResultBestAPRssi))
2560 {
2561 smsLog(pMac, LOG1, FL("Best AP Rssi changed from %d to %d"),
2562 pMac->scan.inScanResultBestAPRssi,
2563 pBssDesc->Result.BssDescriptor.rssi);
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002564 pMac->scan.inScanResultBestAPRssi = pBssDesc->Result.BssDescriptor.rssi;
2565 }
2566 pEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
2567 }
2568
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002569 if ( -128 != pMac->scan.inScanResultBestAPRssi)
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002570 {
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002571 smsLog(pMac, LOG1, FL("Best AP Rssi is %d"), pMac->scan.inScanResultBestAPRssi);
2572 /* Modify Rssi category based on best AP Rssi */
2573 csrAssignRssiForCategory(pMac, pMac->scan.inScanResultBestAPRssi, pMac->roam.configParam.bCatRssiOffset);
2574 pEntry = csrLLPeekHead(&pMac->scan.scanResultList, LL_ACCESS_NOLOCK);
2575 while ( NULL != pEntry)
2576 {
2577 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002578
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002579 /* re-assign preference value based on modified rssi bucket */
2580 pBssDesc->preferValue = csrGetBssPreferValue(pMac, (int)pBssDesc->Result.BssDescriptor.rssi);
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002581
Arif Hussaina7c8e412013-11-20 11:06:42 -08002582 smsLog(pMac, LOG2, FL("BSSID("MAC_ADDRESS_STR
Jeff Johnson123ed002013-11-22 17:39:55 -08002583 ") Rssi(%d) Chnl(%d) PrefVal(%u) SSID=%.*s"),
Arif Hussaina7c8e412013-11-20 11:06:42 -08002584 MAC_ADDR_ARRAY(pBssDesc->Result.BssDescriptor.bssId),
2585 pBssDesc->Result.BssDescriptor.rssi,
2586 pBssDesc->Result.BssDescriptor.channelId,
2587 pBssDesc->preferValue,
2588 pBssDesc->Result.ssId.length, pBssDesc->Result.ssId.ssId);
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002589
2590 pEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
2591 }
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002592 }
2593
2594 csrLLUnlock(&pMac->scan.scanResultList);
2595 }
2596
Kiet Lam64c1b492013-07-12 13:56:44 +05302597 pRetList = vos_mem_malloc(sizeof(tScanResultList));
2598 if ( NULL == pRetList )
2599 status = eHAL_STATUS_FAILURE;
2600 else
2601 status = eHAL_STATUS_SUCCESS;
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002602 if(HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07002603 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302604 vos_mem_set(pRetList, sizeof(tScanResultList), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002605 csrLLOpen(pMac->hHdd, &pRetList->List);
2606 pRetList->pCurEntry = NULL;
Kapil Guptab3a981b2016-06-26 13:36:51 +05302607#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
2608 if (pFilter && pFilter->isPERRoamScan)
2609 if (pSession && pSession->pConnectBssDesc)
2610 csrFindSelfCongestionScore(pMac,
2611 pSession->pConnectBssDesc);
2612#endif
2613
Jeff Johnson295189b2012-06-20 16:38:30 -07002614 csrLLLock(&pMac->scan.scanResultList);
2615 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
2616 while( pEntry )
2617 {
2618 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2619 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
2620 //if pBssDesc->Result.pvIes is NULL, we need to free any memory allocated by csrMatchBSS
2621 //for any error condition, otherwiase, it will be freed later.
2622 //reset
2623 fMatch = eANI_BOOLEAN_FALSE;
2624 pNewIes = NULL;
2625
2626 if(pFilter)
2627 {
2628 fMatch = csrMatchBSS(pMac, &pBssDesc->Result.BssDescriptor, pFilter, &auth, &uc, &mc, &pIes);
2629 if( NULL != pIes )
2630 {
2631 //Only save it when matching
2632 if(fMatch)
2633 {
2634 if( !pBssDesc->Result.pvIes )
2635 {
2636 //csrMatchBSS allocates the memory. Simply pass it and it is freed later
2637 pNewIes = pIes;
2638 }
2639 else
2640 {
2641 //The pIes is allocated by someone else. make a copy
2642 //Only to save parsed IEs if caller provides a filter. Most likely the caller
2643 //is using to for association, hence save the parsed IEs
Kiet Lam64c1b492013-07-12 13:56:44 +05302644 pNewIes = vos_mem_malloc(sizeof(tDot11fBeaconIEs));
2645 if ( NULL == pNewIes )
2646 status = eHAL_STATUS_FAILURE;
2647 else
2648 status = eHAL_STATUS_SUCCESS;
2649 if ( HAL_STATUS_SUCCESS( status ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07002650 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302651 vos_mem_copy(pNewIes, pIes, sizeof( tDot11fBeaconIEs ));
Jeff Johnson295189b2012-06-20 16:38:30 -07002652 }
2653 else
2654 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002655 smsLog(pMac, LOGE, FL(" fail to allocate memory for IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002656 //Need to free memory allocated by csrMatchBSS
2657 if( !pBssDesc->Result.pvIes )
2658 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302659 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07002660 }
2661 break;
2662 }
2663 }
2664 }//fMatch
2665 else if( !pBssDesc->Result.pvIes )
2666 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302667 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07002668 }
2669 }
2670 }
2671 if(NULL == pFilter || fMatch)
2672 {
2673 bssLen = pBssDesc->Result.BssDescriptor.length + sizeof(pBssDesc->Result.BssDescriptor.length);
2674 allocLen = sizeof( tCsrScanResult ) + bssLen;
Kiet Lam64c1b492013-07-12 13:56:44 +05302675 pResult = vos_mem_malloc(allocLen);
2676 if ( NULL == pResult )
2677 status = eHAL_STATUS_FAILURE;
2678 else
2679 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07002680 if(!HAL_STATUS_SUCCESS(status))
2681 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002682 smsLog(pMac, LOGE, FL(" fail to allocate memory for scan result, len=%d"), allocLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07002683 if(pNewIes)
2684 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302685 vos_mem_free(pNewIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07002686 }
2687 break;
2688 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302689 vos_mem_set(pResult, allocLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002690 pResult->capValue = pBssDesc->capValue;
2691 pResult->preferValue = pBssDesc->preferValue;
2692 pResult->ucEncryptionType = uc;
2693 pResult->mcEncryptionType = mc;
2694 pResult->authType = auth;
2695 pResult->Result.ssId = pBssDesc->Result.ssId;
Padma, Santhosh Kumare12fd982016-03-21 13:07:52 +05302696 pResult->Result.timer = pBssDesc->Result.timer;
Jeff Johnson295189b2012-06-20 16:38:30 -07002697 //save the pIes for later use
2698 pResult->Result.pvIes = pNewIes;
2699 //save bss description
Kiet Lam64c1b492013-07-12 13:56:44 +05302700 vos_mem_copy(&pResult->Result.BssDescriptor,
2701 &pBssDesc->Result.BssDescriptor, bssLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07002702 //No need to lock pRetList because it is locally allocated and no outside can access it at this time
2703 if(csrLLIsListEmpty(&pRetList->List, LL_ACCESS_NOLOCK))
2704 {
Kapil Guptab3a981b2016-06-26 13:36:51 +05302705#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
2706 if (pFilter && pFilter->isPERRoamScan) {
2707 csrFindCongestionScore(pMac, pResult);
2708 if (pResult->congestionScore > pMac->currentBssScore) {
2709 csrLLInsertTail(&pRetList->List, &pResult->Link,
2710 LL_ACCESS_NOLOCK);
2711 smsLog(pMac, LOGW,
2712 FL("added one entry in LL in PER Roam list"));
2713 }
2714 }
2715 else
2716#endif
2717 {
2718 csrLLInsertTail(&pRetList->List, &pResult->Link,
2719 LL_ACCESS_NOLOCK);
2720 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002721 }
Abhishek Singhb3e376c2017-01-04 15:27:13 +05302722 /* bssid hint AP should be on head */
2723 else if (pFilter &&
2724 vos_mem_compare(pResult->Result.BssDescriptor.bssId,
2725 pFilter->bssid_hint, VOS_MAC_ADDR_SIZE))
2726 {
2727 csrLLInsertHead(&pRetList->List,
2728 &pResult->Link, LL_ACCESS_NOLOCK);
2729 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002730 else
2731 {
2732 //To sort the list
2733 tListElem *pTmpEntry;
2734 tCsrScanResult *pTmpResult;
2735
2736 pTmpEntry = csrLLPeekHead(&pRetList->List, LL_ACCESS_NOLOCK);
2737 while(pTmpEntry)
2738 {
2739 pTmpResult = GET_BASE_ADDR( pTmpEntry, tCsrScanResult, Link );
Abhishek Singhb3e376c2017-01-04 15:27:13 +05302740 /* Skip the bssid hint AP, as it should be on head */
Abhishek Singh78f494b2017-01-24 10:07:08 +05302741 if (pFilter && vos_mem_compare(
2742 pTmpResult->Result.BssDescriptor.bssId,
Abhishek Singhb3e376c2017-01-04 15:27:13 +05302743 pFilter->bssid_hint, VOS_MAC_ADDR_SIZE)) {
2744 pTmpEntry = csrLLNext(&pRetList->List,
2745 pTmpEntry, LL_ACCESS_NOLOCK);
2746 continue;
2747 }
Kapil Guptab3a981b2016-06-26 13:36:51 +05302748#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
2749 if (pFilter && pFilter->isPERRoamScan) {
2750 csrFindCongestionScore(pMac, pResult);
2751 if(csrIsBetterBssInCongestion(pResult, pTmpResult)&&
2752 (pResult->congestionScore > pMac->currentBssScore))
2753 {
2754 csrLLInsertEntry(&pRetList->List, pTmpEntry,
2755 &pResult->Link, LL_ACCESS_NOLOCK);
2756 smsLog(pMac, LOGW,
2757 FL("added another entry in LL in PER Roam list"));
2758 pResult = NULL;
2759 break;
2760 }
2761 pTmpEntry = csrLLNext(&pRetList->List,
2762 pTmpEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07002763 }
Kapil Guptab3a981b2016-06-26 13:36:51 +05302764 else
2765#endif
2766 {
2767 if(csrIsBetterBss(pResult, pTmpResult))
2768 {
2769 csrLLInsertEntry(&pRetList->List, pTmpEntry,
2770 &pResult->Link, LL_ACCESS_NOLOCK);
2771 //To indicate we are done
2772 pResult = NULL;
2773 break;
2774 }
2775 pTmpEntry = csrLLNext(&pRetList->List,
2776 pTmpEntry, LL_ACCESS_NOLOCK);
2777 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002778 }
2779 if(pResult != NULL)
Kapil Guptab3a981b2016-06-26 13:36:51 +05302780#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
2781 if ((pFilter && !pFilter->isPERRoamScan) ||
2782 (pFilter == NULL) ||
2783 (pResult->congestionScore > pMac->currentBssScore))
2784#endif
2785 {
2786 //This one is not better than any one
2787 csrLLInsertTail(&pRetList->List,
2788 &pResult->Link, LL_ACCESS_NOLOCK);
2789 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002790 }
2791 count++;
2792 }
2793 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK );
2794 }//while
2795 csrLLUnlock(&pMac->scan.scanResultList);
2796
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002797 smsLog(pMac, LOG2, FL("return %d BSS"), csrLLCount(&pRetList->List));
Jeff Johnson295189b2012-06-20 16:38:30 -07002798
2799 if( !HAL_STATUS_SUCCESS(status) || (phResult == NULL) )
2800 {
2801 //Fail or No one wants the result.
2802 csrScanResultPurge(pMac, (tScanResultHandle)pRetList);
2803 }
2804 else
2805 {
2806 if(0 == count)
2807 {
2808 //We are here meaning the there is no match
2809 csrLLClose(&pRetList->List);
Kiet Lam64c1b492013-07-12 13:56:44 +05302810 vos_mem_free(pRetList);
Jeff Johnson295189b2012-06-20 16:38:30 -07002811 status = eHAL_STATUS_E_NULL_VALUE;
Kapil Guptab3a981b2016-06-26 13:36:51 +05302812 smsLog(pMac, LOGW,
2813 FL("Nil scan results or no matching AP found"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002814 }
2815 else if(phResult)
2816 {
2817 *phResult = pRetList;
2818 }
2819 }
2820 }//Allocated pRetList
2821
2822 return (status);
2823}
2824
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002825/*
2826 * NOTE: This routine is being added to make
2827 * sure that scan results are not being flushed
2828 * while roaming. If the scan results are flushed,
2829 * we are unable to recover from
2830 * csrRoamRoamingStateDisassocRspProcessor.
2831 * If it is needed to remove this routine,
2832 * first ensure that we recover gracefully from
2833 * csrRoamRoamingStateDisassocRspProcessor if
2834 * csrScanGetResult returns with a failure because
2835 * of not being able to find the roaming BSS.
2836 */
2837tANI_U8 csrScanFlushDenied(tpAniSirGlobal pMac)
2838{
2839 switch(pMac->roam.neighborRoamInfo.neighborRoamState) {
2840 case eCSR_NEIGHBOR_ROAM_STATE_REPORT_SCAN:
2841 case eCSR_NEIGHBOR_ROAM_STATE_PREAUTHENTICATING:
2842 case eCSR_NEIGHBOR_ROAM_STATE_PREAUTH_DONE:
2843 case eCSR_NEIGHBOR_ROAM_STATE_REASSOCIATING:
2844 return (pMac->roam.neighborRoamInfo.neighborRoamState);
2845 default:
2846 return 0;
2847 }
2848}
2849
Jeff Johnson295189b2012-06-20 16:38:30 -07002850eHalStatus csrScanFlushResult(tpAniSirGlobal pMac)
2851{
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002852 tANI_U8 isFlushDenied = csrScanFlushDenied(pMac);
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302853 eHalStatus status = eHAL_STATUS_SUCCESS;
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002854 if (isFlushDenied) {
2855 smsLog(pMac, LOGW, "%s: scan flush denied in roam state %d",
2856 __func__, isFlushDenied);
2857 return eHAL_STATUS_FAILURE;
2858 }
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302859 csrLLScanPurgeResult( pMac, &pMac->scan.tempScanResults );
2860 csrLLScanPurgeResult( pMac, &pMac->scan.scanResultList );
2861 return( status );
Jeff Johnson295189b2012-06-20 16:38:30 -07002862}
2863
Mukul Sharma20aa6582014-08-07 21:36:12 +05302864eHalStatus csrScanFlushSelectiveResultForBand(tpAniSirGlobal pMac, v_BOOL_t flushP2P, tSirRFBand band)
2865{
2866 eHalStatus status = eHAL_STATUS_SUCCESS;
2867 tListElem *pEntry,*pFreeElem;
2868 tCsrScanResult *pBssDesc;
2869 tDblLinkList *pList = &pMac->scan.scanResultList;
2870
2871 csrLLLock(pList);
2872
2873 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK );
2874 while( pEntry != NULL)
2875 {
2876 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2877 if( (flushP2P == vos_mem_compare( pBssDesc->Result.ssId.ssId,
2878 "DIRECT-", 7)) &&
2879 (GetRFBand(pBssDesc->Result.BssDescriptor.channelId) == band)
2880 )
2881 {
2882 pFreeElem = pEntry;
2883 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2884 csrLLRemoveEntry(pList, pFreeElem, LL_ACCESS_NOLOCK);
2885 csrFreeScanResultEntry( pMac, pBssDesc );
2886 continue;
2887 }
2888 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2889 }
2890
2891 csrLLUnlock(pList);
2892
2893 return (status);
2894}
2895
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302896eHalStatus csrScanFlushSelectiveResult(tpAniSirGlobal pMac, v_BOOL_t flushP2P)
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002897{
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302898 eHalStatus status = eHAL_STATUS_SUCCESS;
2899 tListElem *pEntry,*pFreeElem;
2900 tCsrScanResult *pBssDesc;
2901 tDblLinkList *pList = &pMac->scan.scanResultList;
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002902
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302903 csrLLLock(pList);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002904
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302905 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK );
2906 while( pEntry != NULL)
2907 {
2908 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2909 if( flushP2P == vos_mem_compare( pBssDesc->Result.ssId.ssId,
2910 "DIRECT-", 7) )
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002911 {
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302912 pFreeElem = pEntry;
2913 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2914 csrLLRemoveEntry(pList, pFreeElem, LL_ACCESS_NOLOCK);
2915 csrFreeScanResultEntry( pMac, pBssDesc );
2916 continue;
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002917 }
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302918 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2919 }
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002920
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302921 csrLLUnlock(pList);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002922
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302923 return (status);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002924}
2925
Padma, Santhosh Kumar0eeb7752018-07-04 18:52:27 +05302926eHalStatus csrScanFlushSelectiveSsid(tpAniSirGlobal pMac, tANI_U8 *ssId,
2927 tANI_U8 ssIdLen)
2928{
2929 eHalStatus status = eHAL_STATUS_SUCCESS;
2930 tListElem *pEntry,*pFreeElem;
2931 tCsrScanResult *pBssDesc;
2932 tDblLinkList *pList = &pMac->scan.scanResultList;
2933
2934 csrLLLock(pList);
2935
2936 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK );
2937 while( pEntry != NULL)
2938 {
2939 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2940 if(vos_mem_compare(pBssDesc->Result.ssId.ssId,
2941 ssId, ssIdLen) )
2942 {
2943 pFreeElem = pEntry;
2944 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2945 csrLLRemoveEntry(pList, pFreeElem, LL_ACCESS_NOLOCK);
2946 csrFreeScanResultEntry( pMac, pBssDesc );
2947 continue;
2948 }
2949 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2950 }
2951
2952 csrLLUnlock(pList);
2953
2954 return (status);
2955}
2956
Jeff Johnson295189b2012-06-20 16:38:30 -07002957/**
2958 * csrCheck11dChannel
2959 *
2960 *FUNCTION:
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302961 * This function is called from csrScanFilterResults function and
Jeff Johnson295189b2012-06-20 16:38:30 -07002962 * compare channel number with given channel list.
2963 *
2964 *LOGIC:
2965 * Check Scan result channel number with CFG channel list
2966 *
2967 *ASSUMPTIONS:
2968 *
2969 *
2970 *NOTE:
2971 *
2972 * @param channelId channel number
2973 * @param pChannelList Pointer to channel list
2974 * @param numChannels Number of channel in channel list
2975 *
2976 * @return Status
2977 */
2978
2979eHalStatus csrCheck11dChannel(tANI_U8 channelId, tANI_U8 *pChannelList, tANI_U32 numChannels)
2980{
2981 eHalStatus status = eHAL_STATUS_FAILURE;
2982 tANI_U8 i = 0;
2983
2984 for (i = 0; i < numChannels; i++)
2985 {
2986 if(pChannelList[ i ] == channelId)
2987 {
2988 status = eHAL_STATUS_SUCCESS;
2989 break;
2990 }
2991 }
2992 return status;
2993}
2994
2995/**
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302996 * csrScanFilterResults
Jeff Johnson295189b2012-06-20 16:38:30 -07002997 *
2998 *FUNCTION:
2999 * This function is called from csrApplyCountryInformation function and
3000 * filter scan result based on valid channel list number.
3001 *
3002 *LOGIC:
3003 * Get scan result from scan list and Check Scan result channel number
3004 * with 11d channel list if channel number is found in 11d channel list
3005 * then do not remove scan result entry from scan list
3006 *
3007 *ASSUMPTIONS:
3008 *
3009 *
3010 *NOTE:
3011 *
3012 * @param pMac Pointer to Global MAC structure
3013 *
3014 * @return Status
3015 */
3016
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05303017eHalStatus csrScanFilterResults(tpAniSirGlobal pMac)
Jeff Johnson295189b2012-06-20 16:38:30 -07003018{
3019 eHalStatus status = eHAL_STATUS_SUCCESS;
3020 tListElem *pEntry,*pTempEntry;
3021 tCsrScanResult *pBssDesc;
3022 tANI_U32 len = sizeof(pMac->roam.validChannelList);
3023
3024 /* Get valid channels list from CFG */
3025 if (!HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac,
3026 pMac->roam.validChannelList, &len)))
3027 {
Agarwal Ashishe3cca2a2013-07-21 03:01:48 +05303028 smsLog( pMac, LOGE, "Failed to get Channel list from CFG");
Jeff Johnson295189b2012-06-20 16:38:30 -07003029 }
3030
3031 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
3032 while( pEntry )
3033 {
3034 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05303035 pTempEntry = csrLLNext( &pMac->scan.scanResultList, pEntry,
Jeff Johnson295189b2012-06-20 16:38:30 -07003036 LL_ACCESS_LOCK );
3037 if(csrCheck11dChannel(pBssDesc->Result.BssDescriptor.channelId,
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05303038 pMac->roam.validChannelList, len))
Jeff Johnson295189b2012-06-20 16:38:30 -07003039 {
3040 /* Remove Scan result which does not have 11d channel */
3041 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry,
3042 LL_ACCESS_LOCK ))
3043 {
3044 csrFreeScanResultEntry( pMac, pBssDesc );
3045 }
3046 }
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05303047 pEntry = pTempEntry;
3048 }
3049
3050 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
3051 while( pEntry )
3052 {
3053 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3054 pTempEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry,
3055 LL_ACCESS_LOCK );
3056 if(csrCheck11dChannel(pBssDesc->Result.BssDescriptor.channelId,
3057 pMac->roam.validChannelList, len))
3058 {
3059 /* Remove Scan result which does not have 11d channel */
3060 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry,
3061 LL_ACCESS_LOCK ))
3062 {
3063 csrFreeScanResultEntry( pMac, pBssDesc );
3064 }
3065 }
3066 else
3067 {
3068 smsLog( pMac, LOG1, FL("%d is a Valid channel"),
3069 pBssDesc->Result.BssDescriptor.channelId);
3070 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003071 pEntry = pTempEntry;
3072 }
3073 return status;
3074}
3075
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05303076/**
3077 * csrScanFilterDFSResults
3078 *
3079 *FUNCTION:
3080 * This function filter BSSIDs on DFS channels from the scan results.
3081 *
3082 *LOGIC:
3083 * Get scan result from scan list and Check Scan result channel number
3084 * with 11d channel list if channel number is found in 11d channel list
3085 * and if fEnableDFSChnlScan is zero and if channel is DFS, then
3086 * remove scan result entry from scan list
3087 *
3088 *ASSUMPTIONS:
3089 *
3090 *NOTE:
3091 *
3092 * @param pMac Pointer to Global MAC structure
3093 *
3094 * @return Status
3095 */
3096
3097eHalStatus csrScanFilterDFSResults(tpAniSirGlobal pMac)
3098{
3099 eHalStatus status = eHAL_STATUS_SUCCESS;
3100 tListElem *pEntry,*pTempEntry;
3101 tCsrScanResult *pBssDesc;
3102
3103 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
3104 while( pEntry )
3105 {
3106 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3107 pTempEntry = csrLLNext( &pMac->scan.scanResultList, pEntry,
3108 LL_ACCESS_LOCK );
3109 if((pMac->scan.fEnableDFSChnlScan == DFS_CHNL_SCAN_DISABLED) &&
3110 CSR_IS_CHANNEL_DFS(pBssDesc->Result.BssDescriptor.channelId))
3111 {
3112 smsLog( pMac, LOG1, FL("%d is a DFS ch filtered from scan list"),
3113 pBssDesc->Result.BssDescriptor.channelId);
3114 /* Remove Scan result which does not have 11d channel */
3115 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry,
3116 LL_ACCESS_LOCK ))
3117 {
3118 csrFreeScanResultEntry( pMac, pBssDesc );
3119 }
3120 }
3121 else
3122 {
3123 smsLog( pMac, LOG1, FL("%d is a Valid channel"),
3124 pBssDesc->Result.BssDescriptor.channelId);
3125 }
3126 pEntry = pTempEntry;
3127 }
3128
3129 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
3130 while( pEntry )
3131 {
3132 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3133 pTempEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry,
3134 LL_ACCESS_LOCK );
3135
3136 if((pMac->scan.fEnableDFSChnlScan == DFS_CHNL_SCAN_DISABLED) &&
3137 CSR_IS_CHANNEL_DFS(pBssDesc->Result.BssDescriptor.channelId))
3138 {
3139 smsLog( pMac, LOG1, FL("%d is a DFS ch filtered from scan list"),
3140 pBssDesc->Result.BssDescriptor.channelId);
3141 /* Remove Scan result which does not have 11d channel */
3142 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry,
3143 LL_ACCESS_LOCK ))
3144 {
3145 csrFreeScanResultEntry( pMac, pBssDesc );
3146 }
3147 }
3148 else
3149 {
3150 smsLog( pMac, LOG1, FL("%d is a Valid channel"),
3151 pBssDesc->Result.BssDescriptor.channelId);
3152 }
3153 pEntry = pTempEntry;
3154 }
3155 return status;
3156}
3157
Jeff Johnson295189b2012-06-20 16:38:30 -07003158
3159eHalStatus csrScanCopyResultList(tpAniSirGlobal pMac, tScanResultHandle hIn, tScanResultHandle *phResult)
3160{
3161 eHalStatus status = eHAL_STATUS_SUCCESS;
3162 tScanResultList *pRetList, *pInList = (tScanResultList *)hIn;
3163 tCsrScanResult *pResult, *pScanResult;
3164 tANI_U32 count = 0;
3165 tListElem *pEntry;
3166 tANI_U32 bssLen, allocLen;
3167
3168 if(phResult)
3169 {
3170 *phResult = CSR_INVALID_SCANRESULT_HANDLE;
3171 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303172 pRetList = vos_mem_malloc(sizeof(tScanResultList));
3173 if ( NULL == pRetList )
3174 status = eHAL_STATUS_FAILURE;
3175 else
Jeff Johnson295189b2012-06-20 16:38:30 -07003176 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303177 vos_mem_set(pRetList, sizeof(tScanResultList), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003178 csrLLOpen(pMac->hHdd, &pRetList->List);
3179 pRetList->pCurEntry = NULL;
3180 csrLLLock(&pMac->scan.scanResultList);
3181 csrLLLock(&pInList->List);
3182
3183 pEntry = csrLLPeekHead( &pInList->List, LL_ACCESS_NOLOCK );
3184 while( pEntry )
3185 {
3186 pScanResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3187 bssLen = pScanResult->Result.BssDescriptor.length + sizeof(pScanResult->Result.BssDescriptor.length);
3188 allocLen = sizeof( tCsrScanResult ) + bssLen;
Kiet Lam64c1b492013-07-12 13:56:44 +05303189 pResult = vos_mem_malloc(allocLen);
3190 if ( NULL == pResult )
3191 status = eHAL_STATUS_FAILURE;
3192 else
3193 status = eHAL_STATUS_SUCCESS;
3194 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07003195 {
3196 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
3197 count = 0;
3198 break;
3199 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303200 vos_mem_set(pResult, allocLen , 0);
3201 vos_mem_copy(&pResult->Result.BssDescriptor, &pScanResult->Result.BssDescriptor, bssLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07003202 if( pScanResult->Result.pvIes )
3203 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303204 pResult->Result.pvIes = vos_mem_malloc(sizeof( tDot11fBeaconIEs ));
3205 if ( NULL == pResult->Result.pvIes )
3206 status = eHAL_STATUS_FAILURE;
3207 else
3208 status = eHAL_STATUS_SUCCESS;
3209 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07003210 {
3211 //Free the memory we allocate above first
Kiet Lam64c1b492013-07-12 13:56:44 +05303212 vos_mem_free(pResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07003213 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
3214 count = 0;
3215 break;
3216 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303217 vos_mem_copy(pResult->Result.pvIes, pScanResult->Result.pvIes,
3218 sizeof( tDot11fBeaconIEs ));
Jeff Johnson295189b2012-06-20 16:38:30 -07003219 }
3220 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_LOCK);
3221 count++;
3222 pEntry = csrLLNext( &pInList->List, pEntry, LL_ACCESS_NOLOCK );
3223 }//while
3224 csrLLUnlock(&pInList->List);
3225 csrLLUnlock(&pMac->scan.scanResultList);
3226
3227 if(HAL_STATUS_SUCCESS(status))
3228 {
3229 if(0 == count)
3230 {
3231 csrLLClose(&pRetList->List);
Kiet Lam64c1b492013-07-12 13:56:44 +05303232 vos_mem_free(pRetList);
Jeff Johnson295189b2012-06-20 16:38:30 -07003233 status = eHAL_STATUS_E_NULL_VALUE;
3234 }
3235 else if(phResult)
3236 {
3237 *phResult = pRetList;
3238 }
3239 }
3240 }//Allocated pRetList
3241
3242 return (status);
3243}
3244
3245
3246
3247eHalStatus csrScanningStateMsgProcessor( tpAniSirGlobal pMac, void *pMsgBuf )
3248{
3249 eHalStatus status = eHAL_STATUS_SUCCESS;
3250 tSirMbMsg *pMsg = (tSirMbMsg *)pMsgBuf;
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303251 tSirSmeDisConDoneInd *pDisConDoneInd;
Abhishek Singhf52182c2016-08-24 11:15:23 +05303252 tCsrRoamSession *pSession;
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303253 tCsrRoamInfo roamInfo = {0};
Jeff Johnson295189b2012-06-20 16:38:30 -07003254
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303255 if((eWNI_SME_SCAN_RSP == pMsg->type) ||
3256 (eWNI_SME_GET_SCANNED_CHANNEL_RSP == pMsg->type))
Jeff Johnson295189b2012-06-20 16:38:30 -07003257 {
3258 status = csrScanSmeScanResponse( pMac, pMsgBuf );
3259 }
3260 else
3261 {
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303262 switch (pMsg->type)
Jeff Johnson295189b2012-06-20 16:38:30 -07003263 {
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303264 case eWNI_SME_UPPER_LAYER_ASSOC_CNF:
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08003265 {
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303266 tSirSmeAssocIndToUpperLayerCnf *pUpperLayerAssocCnf;
3267 tCsrRoamInfo *pRoamInfo = NULL;
3268 tANI_U32 sessionId;
3269 eHalStatus status;
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08003270
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303271 smsLog( pMac, LOG1,
3272 FL("Scanning : ASSOCIATION confirmation can be given to upper layer "));
3273 pRoamInfo = &roamInfo;
3274 pUpperLayerAssocCnf = (tSirSmeAssocIndToUpperLayerCnf *)pMsgBuf;
3275 status = csrRoamGetSessionIdFromBSSID( pMac,
3276 (tCsrBssid *)pUpperLayerAssocCnf->bssId,
3277 &sessionId );
3278 pSession = CSR_GET_SESSION(pMac, sessionId);
3279
3280 if(!pSession)
3281 {
3282 smsLog(pMac, LOGE, FL("session %d not found "), sessionId);
3283 return eHAL_STATUS_FAILURE;
3284 }
3285
3286 //send the status code as Success
3287 pRoamInfo->statusCode = eSIR_SME_SUCCESS;
3288 pRoamInfo->u.pConnectedProfile = &pSession->connectedProfile;
3289 pRoamInfo->staId = (tANI_U8)pUpperLayerAssocCnf->aid;
3290 pRoamInfo->rsnIELen =
3291 (tANI_U8)pUpperLayerAssocCnf->rsnIE.length;
3292 pRoamInfo->prsnIE = pUpperLayerAssocCnf->rsnIE.rsnIEdata;
3293 pRoamInfo->addIELen =
3294 (tANI_U8)pUpperLayerAssocCnf->addIE.length;
3295 pRoamInfo->paddIE = pUpperLayerAssocCnf->addIE.addIEdata;
3296 vos_mem_copy(pRoamInfo->peerMac,
3297 pUpperLayerAssocCnf->peerMacAddr,
3298 sizeof(tSirMacAddr));
3299 vos_mem_copy(&pRoamInfo->bssid,
3300 pUpperLayerAssocCnf->bssId,
3301 sizeof(tCsrBssid));
3302 pRoamInfo->wmmEnabledSta = pUpperLayerAssocCnf->wmmEnabledSta;
Hardik Kantilal Patel1ba630f2014-11-21 04:32:05 +05303303#ifdef WLAN_FEATURE_AP_HT40_24G
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303304 pRoamInfo->HT40MHzIntoEnabledSta =
3305 pUpperLayerAssocCnf->HT40MHzIntoEnabledSta;
Hardik Kantilal Patel1ba630f2014-11-21 04:32:05 +05303306#endif
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303307 if(CSR_IS_INFRA_AP(pRoamInfo->u.pConnectedProfile) )
3308 {
3309 pMac->roam.roamSession[sessionId].connectState =
3310 eCSR_ASSOC_STATE_TYPE_INFRA_CONNECTED;
3311 pRoamInfo->fReassocReq = pUpperLayerAssocCnf->reassocReq;
3312 status = csrRoamCallCallback(pMac, sessionId, pRoamInfo,
3313 0, eCSR_ROAM_INFRA_IND,
3314 eCSR_ROAM_RESULT_INFRA_ASSOCIATION_CNF);
3315 }
3316 if(CSR_IS_WDS_AP( pRoamInfo->u.pConnectedProfile))
3317 {
3318 vos_sleep( 100 );
3319 pMac->roam.roamSession[sessionId].connectState =
3320 eCSR_ASSOC_STATE_TYPE_WDS_CONNECTED;//Sta
3321 status = csrRoamCallCallback(pMac, sessionId, pRoamInfo, 0,
3322 eCSR_ROAM_WDS_IND,
3323 eCSR_ROAM_RESULT_WDS_ASSOCIATION_IND);//Sta
3324 }
3325 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07003326 }
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303327 case eWNI_SME_DISCONNECT_DONE_IND:
3328 pDisConDoneInd = (tSirSmeDisConDoneInd *)(pMsg);
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08003329
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303330 smsLog( pMac, LOG1,
3331 FL("eWNI_SME_DISCONNECT_DONE_IND RC:%d"),
3332 pDisConDoneInd->reasonCode);
Sreelakshmi Konamki033cf602016-10-12 15:30:14 +05303333 pSession = CSR_GET_SESSION(pMac,pDisConDoneInd->sessionId);
3334 if (pSession)
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08003335 {
Sreelakshmi Konamki033cf602016-10-12 15:30:14 +05303336 if( CSR_IS_SESSION_VALID(pMac, pDisConDoneInd->sessionId))
3337 {
3338 roamInfo.reasonCode = pDisConDoneInd->reasonCode;
3339 roamInfo.statusCode = eSIR_SME_STA_DISASSOCIATED;
3340 vos_mem_copy(roamInfo.peerMac, pDisConDoneInd->peerMacAddr,
3341 sizeof(tSirMacAddr));
3342 status = csrRoamCallCallback(pMac,
3343 pDisConDoneInd->sessionId,
3344 &roamInfo, 0,
3345 eCSR_ROAM_LOSTLINK,
3346 eCSR_ROAM_RESULT_DISASSOC_IND);
3347 /*
3348 * Update the previous state if
3349 * previous state was eCSR_ROAMING_STATE_JOINED
3350 * as we are disconnected and
3351 * currunt state is scanning
3352 */
3353 if (!CSR_IS_INFRA_AP(&pSession->connectedProfile)
3354 && (eCSR_ROAMING_STATE_IDLE !=
3355 pMac->roam.prev_state[pDisConDoneInd->sessionId]))
3356 pMac->roam.prev_state[pDisConDoneInd->sessionId] =
3357 eCSR_ROAMING_STATE_IDLE;
3358 }
3359 else
3360 {
3361 smsLog(pMac, LOGE, FL("Inactive session %d"),
Abhishek Singhf52182c2016-08-24 11:15:23 +05303362 pDisConDoneInd->sessionId);
Sreelakshmi Konamki033cf602016-10-12 15:30:14 +05303363 status = eHAL_STATUS_FAILURE;
3364 }
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08003365 }
3366 else
3367 {
Sreelakshmi Konamki033cf602016-10-12 15:30:14 +05303368 smsLog(pMac, LOGE, FL("Invalid session"));
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303369 status = eHAL_STATUS_FAILURE;
3370 }
3371 break;
3372
3373 default :
3374 if( csrIsAnySessionInConnectState( pMac ) )
3375 {
3376 /*In case of we are connected, we need to check whether connect
3377 * status changes because scan may also run while connected.
3378 */
3379 csrRoamCheckForLinkStatusChange( pMac, (tSirSmeRsp *)pMsgBuf );
3380 }
3381 else
3382 {
3383 smsLog( pMac, LOGW,
3384 "Message [0x%04x] received in state, when expecting Scan Response",
3385 pMsg->type );
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08003386 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003387 }
3388 }
3389
3390 return (status);
3391}
3392
Abhishek Singh02b08ed2018-09-26 15:04:58 +05303393void csrCheckNSaveWscIe(tpAniSirGlobal pMac, tSirBssDescription *pNewBssDescr,tSirBssDescription *pOldBssDescr)
Jeff Johnson295189b2012-06-20 16:38:30 -07003394{
Abhishek Singh02b08ed2018-09-26 15:04:58 +05303395 int elem_id, len, elem_len;
Jeff Johnson295189b2012-06-20 16:38:30 -07003396 tANI_U8 *pbIe;
3397
3398 //If failed to remove, assuming someone else got it.
3399 if((pNewBssDescr->fProbeRsp != pOldBssDescr->fProbeRsp) &&
3400 (0 == pNewBssDescr->WscIeLen))
3401 {
Abhishek Singh02b08ed2018-09-26 15:04:58 +05303402 len = GET_IE_LEN_IN_BSS(pOldBssDescr->length);
Jeff Johnson295189b2012-06-20 16:38:30 -07003403 pbIe = (tANI_U8 *)pOldBssDescr->ieFields;
3404 //Save WPS IE if it exists
3405 pNewBssDescr->WscIeLen = 0;
Abhishek Singh02b08ed2018-09-26 15:04:58 +05303406 while (len >= 2)
Jeff Johnson295189b2012-06-20 16:38:30 -07003407 {
Abhishek Singh02b08ed2018-09-26 15:04:58 +05303408 elem_id = pbIe[0];
3409 elem_len = pbIe[1];
3410 len -= 2;
3411 if (elem_len > len) {
3412 smsLog(pMac, LOGW, FL("Invalid eid: %d elem_len: %d left: %d"),
3413 elem_id, elem_len, len);
3414 return;
Jeff Johnson295189b2012-06-20 16:38:30 -07003415 }
Abhishek Singh02b08ed2018-09-26 15:04:58 +05303416 if ((elem_id == DOT11F_EID_WSCPROBERES) &&
3417 (elem_len >= DOT11F_IE_WSCPROBERES_MIN_LEN) &&
3418 ((pbIe[2] == 0x00) && (pbIe[3] == 0x50) && (pbIe[4] == 0xf2) &&
3419 (pbIe[5] == 0x04)))
3420 {
3421 if((elem_len + 2) <= WSCIE_PROBE_RSP_LEN)
3422 {
3423 vos_mem_copy(pNewBssDescr->WscIeProbeRsp,
3424 pbIe, elem_len + 2);
3425 pNewBssDescr->WscIeLen = elem_len + 2;
3426 }
3427 return;
3428 }
3429 len -= elem_len;
3430 pbIe += (elem_len + 2);
Jeff Johnson295189b2012-06-20 16:38:30 -07003431 }
3432 }
3433}
3434
3435
3436
3437//pIes may be NULL
3438tANI_BOOLEAN csrRemoveDupBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDescr,
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05303439 tDot11fBeaconIEs *pIes, tAniSSID *pSsid, v_TIME_t *timer, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07003440{
3441 tListElem *pEntry;
3442
3443 tCsrScanResult *pBssDesc;
3444 tANI_BOOLEAN fRC = FALSE;
Abhishek Singh56c29812018-06-12 14:07:52 +05303445 tDot11fBeaconIEs *temp_ie = pIes;
3446
3447 if (!temp_ie)
3448 csrGetParsedBssDescriptionIEs(pMac, pSirBssDescr, &temp_ie);
Jeff Johnson295189b2012-06-20 16:38:30 -07003449
3450 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
3451 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
3452 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
3453 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
3454
3455 while( pEntry )
3456 {
3457 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3458
3459 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
3460 // matches
Abhishek Singh56c29812018-06-12 14:07:52 +05303461 if (csrIsDuplicateBssDescription(pMac, &pBssDesc->Result.BssDescriptor,
3462 pSirBssDescr, temp_ie, fForced))
Jeff Johnson295189b2012-06-20 16:38:30 -07003463 {
Abhishek Singh56c29812018-06-12 14:07:52 +05303464 /*
3465 * Due to Rx sensitivity issue, sometime beacons are seen on
3466 * adjacent channel so workaround in software is needed. If DS
3467 * params or HT info are present driver can get proper channel
3468 * info from these IEs and the older RSSI values are used in new
3469 * entry.
3470 *
3471 * For the cases where DS params and HT info is not present,
3472 * driver needs to check below conditions to update proper
3473 * channel so that the older RSSI and channel values are used in
3474 * new entry:
3475 * -- The old entry channel and new entry channel are not same
3476 * -- RSSI is below 15db or more from old value, this indicate
3477 * that the signal has leaked in adjacent channel
3478 */
3479 if (!pSirBssDescr->fProbeRsp &&
3480 (temp_ie && !temp_ie->DSParams.present &&
3481 !temp_ie->HTInfo.present) &&
3482 (pSirBssDescr->channelId !=
3483 pBssDesc->Result.BssDescriptor.channelId) &&
3484 ((pBssDesc->Result.BssDescriptor.rssi - pSirBssDescr->rssi) >
3485 SIR_ADJACENT_CHANNEL_RSSI_DIFF_THRESHOLD)) {
3486 pSirBssDescr->channelId =
3487 pBssDesc->Result.BssDescriptor.channelId;
3488 pSirBssDescr->rssi =
3489 pBssDesc->Result.BssDescriptor.rssi;
3490 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003491 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
3492 ((tANI_S32)pBssDesc->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
3493 // Remove the 'old' entry from the list....
3494 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry, LL_ACCESS_LOCK ) )
3495 {
3496 // !we need to free the memory associated with this node
3497 //If failed to remove, assuming someone else got it.
3498 *pSsid = pBssDesc->Result.ssId;
3499 *timer = pBssDesc->Result.timer;
3500 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pBssDesc->Result.BssDescriptor);
3501
3502 csrFreeScanResultEntry( pMac, pBssDesc );
3503 }
3504 else
3505 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003506 smsLog( pMac, LOGW, FL( " fail to remove entry" ) );
Jeff Johnson295189b2012-06-20 16:38:30 -07003507 }
3508 fRC = TRUE;
3509
3510 // If we found a match, we can stop looking through the list.
3511 break;
3512 }
3513
3514 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_LOCK );
3515 }
3516
Abhishek Singh56c29812018-06-12 14:07:52 +05303517 if (!pIes && temp_ie)
3518 vos_mem_free(temp_ie);
3519
Jeff Johnson295189b2012-06-20 16:38:30 -07003520 return fRC;
3521}
3522
3523
3524eHalStatus csrAddPMKIDCandidateList( tpAniSirGlobal pMac, tANI_U32 sessionId,
3525 tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes )
3526{
3527 eHalStatus status = eHAL_STATUS_FAILURE;
3528 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
3529
Jeff Johnson32d95a32012-09-10 13:15:23 -07003530 if(!pSession)
3531 {
3532 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
3533 return eHAL_STATUS_FAILURE;
3534 }
3535
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003536 smsLog(pMac, LOGW, "csrAddPMKIDCandidateList called pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07003537 if( pIes )
3538 {
3539 // check if this is a RSN BSS
3540 if( pIes->RSN.present )
3541 {
3542 // Check if the BSS is capable of doing pre-authentication
3543 if( pSession->NumPmkidCandidate < CSR_MAX_PMKID_ALLOWED )
3544 {
3545
3546#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3547 {
3548 WLAN_VOS_DIAG_EVENT_DEF(secEvent, vos_event_wlan_security_payload_type);
Kiet Lam64c1b492013-07-12 13:56:44 +05303549 vos_mem_set(&secEvent, sizeof(vos_event_wlan_security_payload_type), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003550 secEvent.eventId = WLAN_SECURITY_EVENT_PMKID_CANDIDATE_FOUND;
3551 secEvent.encryptionModeMulticast =
3552 (v_U8_t)diagEncTypeFromCSRType(pSession->connectedProfile.mcEncryptionType);
3553 secEvent.encryptionModeUnicast =
3554 (v_U8_t)diagEncTypeFromCSRType(pSession->connectedProfile.EncryptionType);
Kiet Lam64c1b492013-07-12 13:56:44 +05303555 vos_mem_copy(secEvent.bssid, pSession->connectedProfile.bssid, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07003556 secEvent.authMode =
3557 (v_U8_t)diagAuthTypeFromCSRType(pSession->connectedProfile.AuthType);
3558 WLAN_VOS_DIAG_EVENT_REPORT(&secEvent, EVENT_WLAN_SECURITY);
3559 }
3560#endif//#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3561
3562 // if yes, then add to PMKIDCandidateList
Kiet Lam64c1b492013-07-12 13:56:44 +05303563 vos_mem_copy(pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].BSSID,
3564 pBssDesc->bssId, WNI_CFG_BSSID_LEN);
3565 // Bit 0 offirst byte - PreAuthentication Capability
3566 if ( (pIes->RSN.RSN_Cap[0] >> 0) & 0x1 )
Jeff Johnson295189b2012-06-20 16:38:30 -07003567 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303568 pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].preAuthSupported
3569 = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003570 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303571 else
3572 {
3573 pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].preAuthSupported
3574 = eANI_BOOLEAN_FALSE;
3575 }
3576 pSession->NumPmkidCandidate++;
Jeff Johnson295189b2012-06-20 16:38:30 -07003577 }
3578 else
3579 {
3580 status = eHAL_STATUS_FAILURE;
3581 }
3582 }
3583 }
3584
3585 return (status);
3586}
3587
3588//This function checks whether new AP is found for the current connected profile
3589//If it is found, it return the sessionId, else it return invalid sessionID
3590tANI_U32 csrProcessBSSDescForPMKIDList(tpAniSirGlobal pMac,
3591 tSirBssDescription *pBssDesc,
3592 tDot11fBeaconIEs *pIes)
3593{
3594 tANI_U32 i, bRet = CSR_SESSION_ID_INVALID;
3595 tCsrRoamSession *pSession;
3596 tDot11fBeaconIEs *pIesLocal = pIes;
3597
3598 if( pIesLocal || HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIesLocal)) )
3599 {
3600 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
3601 {
3602 if( CSR_IS_SESSION_VALID( pMac, i ) )
3603 {
3604 pSession = CSR_GET_SESSION( pMac, i );
3605 if( csrIsConnStateConnectedInfra( pMac, i ) &&
3606 ( eCSR_AUTH_TYPE_RSN == pSession->connectedProfile.AuthType ) )
3607 {
3608 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile, pBssDesc, pIesLocal))
3609 {
3610 //this new BSS fits the current profile connected
3611 if(HAL_STATUS_SUCCESS(csrAddPMKIDCandidateList(pMac, i, pBssDesc, pIesLocal)))
3612 {
3613 bRet = i;
3614 }
3615 break;
3616 }
3617 }
3618 }
3619 }
3620 if( !pIes )
3621 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303622 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003623 }
3624 }
3625
3626 return (tANI_U8)bRet;
3627}
3628
3629#ifdef FEATURE_WLAN_WAPI
3630eHalStatus csrAddBKIDCandidateList( tpAniSirGlobal pMac, tANI_U32 sessionId,
3631 tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes )
3632{
3633 eHalStatus status = eHAL_STATUS_FAILURE;
3634 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
3635
Jeff Johnson32d95a32012-09-10 13:15:23 -07003636 if(!pSession)
3637 {
3638 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
3639 return eHAL_STATUS_FAILURE;
3640 }
3641
Kiet Lam64c1b492013-07-12 13:56:44 +05303642 smsLog(pMac, LOGW, "csrAddBKIDCandidateList called pMac->scan.NumBkidCandidate = %d",
3643 pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07003644 if( pIes )
3645 {
3646 // check if this is a WAPI BSS
3647 if( pIes->WAPI.present )
3648 {
3649 // Check if the BSS is capable of doing pre-authentication
3650 if( pSession->NumBkidCandidate < CSR_MAX_BKID_ALLOWED )
3651 {
3652
3653 // if yes, then add to BKIDCandidateList
Kiet Lam64c1b492013-07-12 13:56:44 +05303654 vos_mem_copy(pSession->BkidCandidateInfo[pSession->NumBkidCandidate].BSSID,
3655 pBssDesc->bssId, WNI_CFG_BSSID_LEN);
3656 if ( pIes->WAPI.preauth )
Jeff Johnson295189b2012-06-20 16:38:30 -07003657 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303658 pSession->BkidCandidateInfo[pSession->NumBkidCandidate].preAuthSupported
3659 = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003660 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303661 else
3662 {
3663 pSession->BkidCandidateInfo[pSession->NumBkidCandidate].preAuthSupported
3664 = eANI_BOOLEAN_FALSE;
3665 }
3666 pSession->NumBkidCandidate++;
Jeff Johnson295189b2012-06-20 16:38:30 -07003667 }
3668 else
3669 {
3670 status = eHAL_STATUS_FAILURE;
3671 }
3672 }
3673 }
3674
3675 return (status);
3676}
3677
3678//This function checks whether new AP is found for the current connected profile
3679//if so add to BKIDCandidateList
3680tANI_BOOLEAN csrProcessBSSDescForBKIDList(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
3681 tDot11fBeaconIEs *pIes)
3682{
3683 tANI_BOOLEAN fRC = FALSE;
3684 tDot11fBeaconIEs *pIesLocal = pIes;
3685 tANI_U32 sessionId;
3686 tCsrRoamSession *pSession;
3687
3688 if( pIesLocal || HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIesLocal)) )
3689 {
3690 for( sessionId = 0; sessionId < CSR_ROAM_SESSION_MAX; sessionId++ )
3691 {
3692 if( CSR_IS_SESSION_VALID( pMac, sessionId) )
3693 {
3694 pSession = CSR_GET_SESSION( pMac, sessionId );
3695 if( csrIsConnStateConnectedInfra( pMac, sessionId ) &&
3696 eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE == pSession->connectedProfile.AuthType)
3697 {
3698 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile,pBssDesc, pIesLocal))
3699 {
3700 //this new BSS fits the current profile connected
3701 if(HAL_STATUS_SUCCESS(csrAddBKIDCandidateList(pMac, sessionId, pBssDesc, pIesLocal)))
3702 {
3703 fRC = TRUE;
3704 }
3705 }
3706 }
3707 }
3708 }
3709 if(!pIes)
3710 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303711 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003712 }
3713
3714 }
3715 return fRC;
3716}
3717
3718#endif
3719
3720
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07003721static void csrMoveTempScanResultsToMainList( tpAniSirGlobal pMac, tANI_U8 reason )
Jeff Johnson295189b2012-06-20 16:38:30 -07003722{
3723 tListElem *pEntry;
3724 tCsrScanResult *pBssDescription;
Jeff Johnson295189b2012-06-20 16:38:30 -07003725 tANI_BOOLEAN fDupBss;
3726#ifdef FEATURE_WLAN_WAPI
3727 tANI_BOOLEAN fNewWapiBSSForCurConnection = eANI_BOOLEAN_FALSE;
3728#endif /* FEATURE_WLAN_WAPI */
3729 tDot11fBeaconIEs *pIesLocal = NULL;
3730 tANI_U32 sessionId = CSR_SESSION_ID_INVALID;
3731 tAniSSID tmpSsid;
3732 v_TIME_t timer=0;
Kapil Gupta2f2fae42016-09-15 15:29:47 +05303733 tANI_U8 occupied_chan_count = pMac->scan.occupiedChannels.numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -07003734
3735 tmpSsid.length = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07003736
3737 // remove the BSS descriptions from temporary list
3738 while( ( pEntry = csrLLRemoveTail( &pMac->scan.tempScanResults, LL_ACCESS_LOCK ) ) != NULL)
3739 {
3740 pBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3741
Vinay Krishna Eranna566365f2015-03-09 12:34:13 +05303742 smsLog( pMac, LOG2, "...Bssid= "MAC_ADDRESS_STR" chan= %d, rssi = -%d",
Arif Hussain24bafea2013-11-15 15:10:03 -08003743 MAC_ADDR_ARRAY(pBssDescription->Result.BssDescriptor.bssId),
Jeff Johnson295189b2012-06-20 16:38:30 -07003744 pBssDescription->Result.BssDescriptor.channelId,
3745 pBssDescription->Result.BssDescriptor.rssi * (-1) );
3746
3747 //At this time, pBssDescription->Result.pvIes may be NULL
3748 pIesLocal = (tDot11fBeaconIEs *)( pBssDescription->Result.pvIes );
3749 if( !pIesLocal && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pBssDescription->Result.BssDescriptor, &pIesLocal))) )
3750 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003751 smsLog(pMac, LOGE, FL(" Cannot pared IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003752 csrFreeScanResultEntry(pMac, pBssDescription);
3753 continue;
3754 }
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05303755 fDupBss = csrRemoveDupBssDescription( pMac, &pBssDescription->Result.BssDescriptor, pIesLocal, &tmpSsid, &timer, FALSE );
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07003756 //Check whether we have reach out limit, but don't lose the LFR candidates came from FW
3757 if( CSR_SCAN_IS_OVER_BSS_LIMIT(pMac)
3758#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
3759 && !( eCsrScanGetLfrResult == reason )
3760#endif
3761 )
Jeff Johnson295189b2012-06-20 16:38:30 -07003762 {
Deepthi Gowri50e2fa52016-03-17 15:30:53 +05303763 smsLog(pMac, LOG1, FL("########## BSS Limit reached ###########"));
Abhishek Singh5deecd12017-06-12 11:08:40 +05303764 csrPurgeScanResults(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07003765 }
3766 // check for duplicate scan results
3767 if ( !fDupBss )
3768 {
3769 //Found a new BSS
3770 sessionId = csrProcessBSSDescForPMKIDList(pMac,
3771 &pBssDescription->Result.BssDescriptor, pIesLocal);
3772 if( CSR_SESSION_ID_INVALID != sessionId)
3773 {
3774 csrRoamCallCallback(pMac, sessionId, NULL, 0,
3775 eCSR_ROAM_SCAN_FOUND_NEW_BSS, eCSR_ROAM_RESULT_NONE);
3776 }
3777 }
3778 else
3779 {
3780 //Check if the new one has SSID it it, if not, use the older SSID if it exists.
3781 if( (0 == pBssDescription->Result.ssId.length) && tmpSsid.length )
3782 {
3783 //New BSS has a hidden SSID and old one has the SSID. Keep the SSID only
3784 //if diff of saved SSID time and current time is less than 1 min to avoid
3785 //side effect of saving SSID with old one is that if AP changes its SSID while remain
3786 //hidden, we may never see it and also to address the requirement of
3787 //When we remove hidden ssid from the profile i.e., forget the SSID via
3788 // GUI that SSID shouldn't see in the profile
3789 if( (vos_timer_get_system_time() - timer) <= HIDDEN_TIMER)
3790 {
3791 pBssDescription->Result.timer = timer;
3792 pBssDescription->Result.ssId = tmpSsid;
3793 }
3794 }
3795 }
3796
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303797 //Find a good AP for 11d info
3798 if ( csrIs11dSupported( pMac ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003799 {
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303800 // check if country information element is present
3801 if (pIesLocal->Country.present)
Jeff Johnson295189b2012-06-20 16:38:30 -07003802 {
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303803 csrAddVoteForCountryInfo(pMac, pIesLocal->Country.country);
3804 smsLog(pMac, LOGW, FL("11d AP Bssid " MAC_ADDRESS_STR
3805 " chan= %d, rssi = -%d, countryCode %c%c"),
3806 MAC_ADDR_ARRAY( pBssDescription->Result.BssDescriptor.bssId),
3807 pBssDescription->Result.BssDescriptor.channelId,
3808 pBssDescription->Result.BssDescriptor.rssi * (-1),
3809 pIesLocal->Country.country[0],pIesLocal->Country.country[1] );
3810 }
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303811
Jeff Johnson295189b2012-06-20 16:38:30 -07003812 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08003813
Jeff Johnson295189b2012-06-20 16:38:30 -07003814 // append to main list
3815 csrScanAddResult(pMac, pBssDescription, pIesLocal);
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303816 if ( (pBssDescription->Result.pvIes == NULL) && pIesLocal )
Jeff Johnson295189b2012-06-20 16:38:30 -07003817 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303818 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003819 }
3820 }
3821
Kapil Gupta2f2fae42016-09-15 15:29:47 +05303822#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
3823 if (sme_IsFeatureSupportedByFW(PER_BASED_ROAMING) &&
3824 (csrGetInfraSessionId(pMac) != -1) &&
3825 (pMac->scan.occupiedChannels.numChannels != occupied_chan_count))
3826 {
3827 /* Update FW with new list */
3828 smsLog(pMac, LOGW,
3829 FL("Updating occupied channel list, new chanNum %d"),
3830 pMac->scan.occupiedChannels.numChannels);
3831 csrRoamOffloadScan(pMac, ROAM_SCAN_OFFLOAD_UPDATE_CFG,
3832 REASON_CHANNEL_LIST_CHANGED);
3833 }
3834#endif
Sushant Kaushik6274de62015-05-01 16:31:23 +05303835 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
Tushnim Bhattacharyyaae317772013-10-23 18:55:38 -07003836 //we don't need to update CC while connected to an AP which is advertising CC already
3837 if (csrIs11dSupported(pMac))
3838 {
3839 tANI_U32 i;
3840 tCsrRoamSession *pSession;
3841
3842 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
3843 {
3844 if (CSR_IS_SESSION_VALID( pMac, i ) )
3845 {
3846 pSession = CSR_GET_SESSION( pMac, i );
3847 if (csrIsConnStateConnected(pMac, i))
3848 {
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303849 smsLog(pMac, LOGW, FL("No need for updating CC in"
3850 "connected state"));
3851 goto end;
Tushnim Bhattacharyyaae317772013-10-23 18:55:38 -07003852 }
3853 }
3854 }
Agrawal Ashishbd3a5932016-04-12 16:22:39 +05303855 if (csrElectedCountryInfo(pMac))
3856 csrLearnCountryInformation(pMac, NULL, NULL,
3857 eANI_BOOLEAN_TRUE);
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303858 }
3859
Tushnim Bhattacharyyaae317772013-10-23 18:55:38 -07003860end:
3861 //If we can find the current 11d info in any of the scan results, or
Jeff Johnson295189b2012-06-20 16:38:30 -07003862 // a good enough AP with the 11d info from the scan results then no need to
3863 // get into ambiguous state
3864 if(pMac->scan.fAmbiguous11dInfoFound)
3865 {
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303866 if((pMac->scan.fCurrent11dInfoMatch))
Jeff Johnson295189b2012-06-20 16:38:30 -07003867 {
3868 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
3869 }
3870 }
3871
3872#ifdef FEATURE_WLAN_WAPI
3873 if(fNewWapiBSSForCurConnection)
3874 {
3875 //remember it first
3876 csrRoamCallCallback(pMac, sessionId, NULL, 0, eCSR_ROAM_SCAN_FOUND_NEW_BSS, eCSR_ROAM_RESULT_NEW_WAPI_BSS);
3877 }
3878#endif /* FEATURE_WLAN_WAPI */
3879
3880 return;
3881}
3882
Abhishek Singh5deecd12017-06-12 11:08:40 +05303883/**
3884 * csrPurgeScanResults() - This function removes scan entry based
3885 * on RSSI or AGE
3886 * @pMac: pointer to Global MAC structure
3887 *
3888 * This function removes scan entry based on RSSI or AGE.
3889 * If an scan entry with RSSI less than CSR_PURGE_RSSI_THRESHOLD,
3890 * the scan entry is removed else oldest entry is removed.
3891 *
3892 * Return: None
3893 */
3894void csrPurgeScanResults(tpAniSirGlobal pMac)
Deepthi Gowri50e2fa52016-03-17 15:30:53 +05303895{
3896 tListElem *pEntry, *tmpEntry;
Abhishek Singh5deecd12017-06-12 11:08:40 +05303897 tCsrScanResult *pResult, *oldest_bss = NULL, *weakest_bss = NULL;
Deepthi Gowri4480a3f2016-05-18 19:30:17 +05303898 v_TIME_t oldest_entry = 0;
3899 v_TIME_t curTime = vos_timer_get_system_time();
Abhishek Singh5deecd12017-06-12 11:08:40 +05303900 tANI_S8 weakest_rssi = 0;
Deepthi Gowri50e2fa52016-03-17 15:30:53 +05303901
3902 csrLLLock(&pMac->scan.scanResultList);
3903 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
Abhishek Singh5deecd12017-06-12 11:08:40 +05303904 while(pEntry)
Deepthi Gowri50e2fa52016-03-17 15:30:53 +05303905 {
3906 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry,
3907 LL_ACCESS_NOLOCK);
3908 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3909 if((curTime -
3910 pResult->Result.BssDescriptor.nReceivedTime) > oldest_entry)
3911 {
3912 oldest_entry = curTime -
3913 pResult->Result.BssDescriptor.nReceivedTime;
3914 oldest_bss = pResult;
3915 }
Abhishek Singh5deecd12017-06-12 11:08:40 +05303916 if (pResult->Result.BssDescriptor.rssi < weakest_rssi)
3917 {
3918 weakest_rssi = pResult->Result.BssDescriptor.rssi;
3919 weakest_bss = pResult;
3920 }
Deepthi Gowri50e2fa52016-03-17 15:30:53 +05303921 pEntry = tmpEntry;
3922 }
3923 if (oldest_bss)
3924 {
Abhishek Singh5deecd12017-06-12 11:08:40 +05303925 tCsrScanResult *bss_to_remove;
3926
3927 if (weakest_rssi < CSR_PURGE_RSSI_THRESHOLD)
3928 bss_to_remove = weakest_bss;
3929 else
3930 bss_to_remove = oldest_bss;
3931
Deepthi Gowri50e2fa52016-03-17 15:30:53 +05303932 //Free the old BSS Entries
Abhishek Singh5deecd12017-06-12 11:08:40 +05303933 if(csrLLRemoveEntry(&pMac->scan.scanResultList,
3934 &bss_to_remove->Link, LL_ACCESS_NOLOCK))
Deepthi Gowri50e2fa52016-03-17 15:30:53 +05303935 {
Abhishek Singh5deecd12017-06-12 11:08:40 +05303936 smsLog(pMac, LOG1,
3937 FL("BSSID: "MAC_ADDRESS_STR" Removed, time delta (%lu) RSSI %d"),
3938 MAC_ADDR_ARRAY(
3939 bss_to_remove->Result.BssDescriptor.bssId),
3940 (curTime -
3941 bss_to_remove->Result.BssDescriptor.nReceivedTime),
3942 bss_to_remove->Result.BssDescriptor.rssi);
3943 csrFreeScanResultEntry(pMac, bss_to_remove);
Deepthi Gowri50e2fa52016-03-17 15:30:53 +05303944 }
3945 }
3946 csrLLUnlock(&pMac->scan.scanResultList);
3947}
Jeff Johnson295189b2012-06-20 16:38:30 -07003948
3949static tCsrScanResult *csrScanSaveBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pBSSDescription,
3950 tDot11fBeaconIEs *pIes)
3951{
3952 tCsrScanResult *pCsrBssDescription = NULL;
3953 tANI_U32 cbBSSDesc;
3954 tANI_U32 cbAllocated;
Sushant Kaushik6274de62015-05-01 16:31:23 +05303955 tListElem *pEntry;
Jeff Johnson295189b2012-06-20 16:38:30 -07003956
3957 // figure out how big the BSS description is (the BSSDesc->length does NOT
3958 // include the size of the length field itself).
3959 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
3960
3961 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
3962
Kiet Lam64c1b492013-07-12 13:56:44 +05303963 pCsrBssDescription = vos_mem_malloc(cbAllocated);
3964 if ( NULL != pCsrBssDescription )
Jeff Johnson295189b2012-06-20 16:38:30 -07003965 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303966 vos_mem_set(pCsrBssDescription, cbAllocated, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003967 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Kiet Lam64c1b492013-07-12 13:56:44 +05303968 vos_mem_copy(&pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc);
Jeff Johnson295189b2012-06-20 16:38:30 -07003969#if defined(VOSS_ENSBALED)
3970 VOS_ASSERT( pCsrBssDescription->Result.pvIes == NULL );
3971#endif
3972 csrScanAddResult(pMac, pCsrBssDescription, pIes);
Sushant Kaushik6274de62015-05-01 16:31:23 +05303973 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
Jeff Johnson295189b2012-06-20 16:38:30 -07003974 }
3975
3976 return( pCsrBssDescription );
3977}
3978
3979// Append a Bss Description...
3980tCsrScanResult *csrScanAppendBssDescription( tpAniSirGlobal pMac,
3981 tSirBssDescription *pSirBssDescription,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07003982 tDot11fBeaconIEs *pIes, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07003983{
3984 tCsrScanResult *pCsrBssDescription = NULL;
3985 tAniSSID tmpSsid;
3986 v_TIME_t timer = 0;
3987 int result;
3988
3989 tmpSsid.length = 0;
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07003990 result = csrRemoveDupBssDescription( pMac, pSirBssDescription, pIes, &tmpSsid, &timer, fForced );
Jeff Johnson295189b2012-06-20 16:38:30 -07003991 pCsrBssDescription = csrScanSaveBssDescription( pMac, pSirBssDescription, pIes );
3992 if (result && (pCsrBssDescription != NULL))
3993 {
3994 //Check if the new one has SSID it it, if not, use the older SSID if it exists.
3995 if( (0 == pCsrBssDescription->Result.ssId.length) && tmpSsid.length )
3996 {
3997 //New BSS has a hidden SSID and old one has the SSID. Keep the SSID only
3998 //if diff of saved SSID time and current time is less than 1 min to avoid
3999 //side effect of saving SSID with old one is that if AP changes its SSID while remain
4000 //hidden, we may never see it and also to address the requirement of
4001 //When we remove hidden ssid from the profile i.e., forget the SSID via
4002 // GUI that SSID shouldn't see in the profile
4003 if((vos_timer_get_system_time()-timer) <= HIDDEN_TIMER)
4004 {
4005 pCsrBssDescription->Result.ssId = tmpSsid;
4006 pCsrBssDescription->Result.timer = timer;
4007 }
4008 }
4009 }
4010
4011
4012 return( pCsrBssDescription );
4013}
4014
4015
4016
4017void csrPurgeChannelPower( tpAniSirGlobal pMac, tDblLinkList *pChannelList )
4018{
4019 tCsrChannelPowerInfo *pChannelSet;
4020 tListElem *pEntry;
4021
4022 csrLLLock(pChannelList);
4023 // Remove the channel sets from the learned list and put them in the free list
4024 while( ( pEntry = csrLLRemoveHead( pChannelList, LL_ACCESS_NOLOCK ) ) != NULL)
4025 {
4026 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
4027 if( pChannelSet )
4028 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304029 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07004030 }
4031 }
4032 csrLLUnlock(pChannelList);
4033 return;
4034}
4035
4036
4037/*
4038 * Save the channelList into the ultimate storage as the final stage of channel
4039 * Input: pCountryInfo -- the country code (e.g. "USI"), channel list, and power limit are all stored inside this data structure
4040 */
Jeff Johnsone7245742012-09-05 17:12:55 -07004041eHalStatus csrSaveToChannelPower2G_5G( tpAniSirGlobal pMac, tANI_U32 tableSize, tSirMacChanInfo *channelTable )
Jeff Johnson295189b2012-06-20 16:38:30 -07004042{
4043 tANI_U32 i = tableSize / sizeof( tSirMacChanInfo );
4044 tSirMacChanInfo *pChannelInfo;
4045 tCsrChannelPowerInfo *pChannelSet;
4046 tANI_BOOLEAN f2GHzInfoFound = FALSE;
4047 tANI_BOOLEAN f2GListPurged = FALSE, f5GListPurged = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004048
4049 pChannelInfo = channelTable;
4050 // atleast 3 bytes have to be remaining -- from "countryString"
4051 while ( i-- )
4052 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304053 pChannelSet = vos_mem_malloc(sizeof(tCsrChannelPowerInfo));
4054 if ( NULL != pChannelSet )
Jeff Johnson295189b2012-06-20 16:38:30 -07004055 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304056 vos_mem_set(pChannelSet, sizeof(tCsrChannelPowerInfo), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004057 pChannelSet->firstChannel = pChannelInfo->firstChanNum;
4058 pChannelSet->numChannels = pChannelInfo->numChannels;
4059
4060 // Now set the inter-channel offset based on the frequency band the channel set lies in
Jeff Johnsone7245742012-09-05 17:12:55 -07004061 if( (CSR_IS_CHANNEL_24GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07004062 ((pChannelSet->firstChannel + (pChannelSet->numChannels - 1)) <= CSR_MAX_24GHz_CHANNEL_NUMBER) )
Jeff Johnsone7245742012-09-05 17:12:55 -07004063
Jeff Johnson295189b2012-06-20 16:38:30 -07004064 {
4065 pChannelSet->interChannelOffset = 1;
4066 f2GHzInfoFound = TRUE;
4067 }
Jeff Johnsone7245742012-09-05 17:12:55 -07004068 else if ( (CSR_IS_CHANNEL_5GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07004069 ((pChannelSet->firstChannel + ((pChannelSet->numChannels - 1) * 4)) <= CSR_MAX_5GHz_CHANNEL_NUMBER) )
Jeff Johnson295189b2012-06-20 16:38:30 -07004070 {
4071 pChannelSet->interChannelOffset = 4;
4072 f2GHzInfoFound = FALSE;
4073 }
Jeff Johnsone7245742012-09-05 17:12:55 -07004074 else
4075 {
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07004076 smsLog( pMac, LOGW, FL("Invalid Channel %d Present in Country IE"),
Jeff Johnsone7245742012-09-05 17:12:55 -07004077 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05304078 vos_mem_free(pChannelSet);
Jeff Johnsone7245742012-09-05 17:12:55 -07004079 return eHAL_STATUS_FAILURE;
4080 }
4081
Jeff Johnson295189b2012-06-20 16:38:30 -07004082 pChannelSet->txPower = CSR_ROAM_MIN( pChannelInfo->maxTxPower, pMac->roam.configParam.nTxPowerCap );
4083
4084 if( f2GHzInfoFound )
4085 {
4086 if( !f2GListPurged )
4087 {
4088 // purge previous results if found new
4089 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList24 );
4090 f2GListPurged = TRUE;
4091 }
4092
4093 if(CSR_IS_OPERATING_BG_BAND(pMac))
4094 {
4095 // add to the list of 2.4 GHz channel sets
4096 csrLLInsertTail( &pMac->scan.channelPowerInfoList24, &pChannelSet->link, LL_ACCESS_LOCK );
4097 }
4098 else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004099 smsLog( pMac, LOGW, FL("Adding 11B/G channels in 11A mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07004100 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05304101 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07004102 }
4103 }
4104 else
4105 {
4106 // 5GHz info found
4107 if( !f5GListPurged )
4108 {
4109 // purge previous results if found new
4110 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList5G );
4111 f5GListPurged = TRUE;
4112 }
4113
4114 if(CSR_IS_OPERATING_A_BAND(pMac))
4115 {
4116 // add to the list of 5GHz channel sets
4117 csrLLInsertTail( &pMac->scan.channelPowerInfoList5G, &pChannelSet->link, LL_ACCESS_LOCK );
4118 }
4119 else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004120 smsLog( pMac, LOGW, FL("Adding 11A channels in B/G mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07004121 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05304122 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07004123 }
4124 }
4125 }
4126
4127 pChannelInfo++; // move to next entry
4128 }
4129
Jeff Johnsone7245742012-09-05 17:12:55 -07004130 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07004131}
4132
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05304133static void csrClearDfsChannelList( tpAniSirGlobal pMac )
4134{
4135 tSirMbMsg *pMsg;
4136 tANI_U16 msgLen;
Jeff Johnson295189b2012-06-20 16:38:30 -07004137
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05304138 msgLen = (tANI_U16)(sizeof( tSirMbMsg ));
Kiet Lam64c1b492013-07-12 13:56:44 +05304139 pMsg = vos_mem_malloc(msgLen);
4140 if ( NULL != pMsg )
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05304141 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304142 vos_mem_set((void *)pMsg, msgLen, 0);
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05304143 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_CLEAR_DFS_CHANNEL_LIST);
4144 pMsg->msgLen = pal_cpu_to_be16(msgLen);
4145 palSendMBMessage(pMac->hHdd, pMsg);
4146 }
4147}
Jeff Johnson295189b2012-06-20 16:38:30 -07004148
4149void csrApplyPower2Current( tpAniSirGlobal pMac )
4150{
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004151 smsLog( pMac, LOG3, FL(" Updating Cfg with power settings"));
Jeff Johnson295189b2012-06-20 16:38:30 -07004152 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList24, WNI_CFG_MAX_TX_POWER_2_4 );
4153 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList5G, WNI_CFG_MAX_TX_POWER_5 );
4154}
4155
4156
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004157void csrApplyChannelPowerCountryInfo( tpAniSirGlobal pMac, tCsrChannel *pChannelList, tANI_U8 *countryCode, tANI_BOOLEAN updateRiva)
Jeff Johnson295189b2012-06-20 16:38:30 -07004158{
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304159 int i, j, count, countryIndex = -1;
Jeff Johnson295189b2012-06-20 16:38:30 -07004160 tANI_U8 numChannels = 0;
4161 tANI_U8 tempNumChannels = 0;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304162 tANI_U8 channelIgnore = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004163 tCsrChannel ChannelList;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304164
Jeff Johnson295189b2012-06-20 16:38:30 -07004165 if( pChannelList->numChannels )
4166 {
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304167 for(count=0; count < MAX_COUNTRY_IGNORE; count++)
4168 {
4169 if(vos_mem_compare(countryCode, countryIgnoreList[count].countryCode,
4170 VOS_COUNTRY_CODE_LEN))
4171 {
4172 countryIndex = count;
4173 break;
4174 }
4175 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004176 tempNumChannels = CSR_MIN(pChannelList->numChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN);
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05304177
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304178 for(i=0; i < tempNumChannels; i++)
Jeff Johnson295189b2012-06-20 16:38:30 -07004179 {
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304180 channelIgnore = FALSE;
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05304181 if( countryIndex != -1 )
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304182 {
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05304183 for(j=0; j < countryIgnoreList[countryIndex].channelCount; j++)
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304184 {
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05304185 if( pChannelList->channelList[i] ==
4186 countryIgnoreList[countryIndex].channelList[j] )
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304187 {
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05304188 channelIgnore = TRUE;
4189 break;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304190 }
4191 }
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05304192 }
4193 if( FALSE == channelIgnore )
4194 {
4195 ChannelList.channelList[numChannels] = pChannelList->channelList[i];
4196 numChannels++;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304197 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004198 }
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304199 ChannelList.numChannels = numChannels;
Mahesh A Saptasagar1ed59582014-06-04 18:45:07 +05304200 csrApplyPower2Current( pMac ); // Store the channel+power info in the global place: Cfg
Jeff Johnson295189b2012-06-20 16:38:30 -07004201 csrSetCfgValidChannelList(pMac, ChannelList.channelList, ChannelList.numChannels);
4202 // extend scan capability
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304203 // build a scan list based on the channel list : channel# + active/passive scan
4204 csrSetCfgScanControlList(pMac, countryCode, &ChannelList);
Jeff Johnson295189b2012-06-20 16:38:30 -07004205#ifdef FEATURE_WLAN_SCAN_PNO
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004206 if (updateRiva)
4207 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004208 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO, FL(" Sending 11d PNO info to Riva"));
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004209 // Send HAL UpdateScanParams message
4210 pmcUpdateScanParams(pMac, &(pMac->roam.configParam), &ChannelList, TRUE);
4211 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004212#endif // FEATURE_WLAN_SCAN_PNO
4213 }
4214 else
4215 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004216 smsLog( pMac, LOGE, FL(" 11D channel list is empty"));
Jeff Johnson295189b2012-06-20 16:38:30 -07004217 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004218 csrSetCfgCountryCode(pMac, countryCode);
4219}
4220
Sourav Mohapatra3dd5dba2018-03-26 15:12:47 +05304221void csrUpdateFCCChannelList(tpAniSirGlobal pMac)
4222{
4223 tCsrChannel ChannelList;
4224 tANI_U8 chnlIndx = 0;
4225 int i;
4226
4227 for ( i = 0; i < pMac->scan.base20MHzChannels.numChannels; i++ )
4228 {
4229 if (pMac->scan.fcc_constraint &&
4230 ((pMac->scan.base20MHzChannels.channelList[i] == 12) ||
4231 (pMac->scan.base20MHzChannels.channelList[i] == 13)))
4232 {
4233 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
4234 FL("removing channel %d"),
4235 pMac->scan.base20MHzChannels.channelList[i]);
4236 continue;
4237 }
4238 ChannelList.channelList[chnlIndx] =
4239 pMac->scan.base20MHzChannels.channelList[i];
4240 chnlIndx++;
4241 }
4242 csrSetCfgValidChannelList(pMac, ChannelList.channelList, chnlIndx);
4243 csrScanFilterResults(pMac);
4244}
4245
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004246void csrResetCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce, tANI_BOOLEAN updateRiva )
Jeff Johnson295189b2012-06-20 16:38:30 -07004247{
4248 if( fForce || (csrIs11dSupported( pMac ) && (!pMac->scan.f11dInfoReset)))
4249 {
4250
4251#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4252 {
4253 vos_log_802_11d_pkt_type *p11dLog;
4254 int Index;
4255
4256 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
4257 if(p11dLog)
4258 {
4259 p11dLog->eventId = WLAN_80211D_EVENT_RESET;
Kiet Lam64c1b492013-07-12 13:56:44 +05304260 vos_mem_copy(p11dLog->countryCode, pMac->scan.countryCodeCurrent, 3);
Jeff Johnson295189b2012-06-20 16:38:30 -07004261 p11dLog->numChannel = pMac->scan.base20MHzChannels.numChannels;
4262 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
4263 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304264 vos_mem_copy(p11dLog->Channels,
4265 pMac->scan.base20MHzChannels.channelList,
4266 p11dLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07004267 for (Index=0; Index < pMac->scan.base20MHzChannels.numChannels; Index++)
4268 {
4269 p11dLog->TxPwr[Index] = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
4270 }
4271 }
4272 if(!pMac->roam.configParam.Is11dSupportEnabled)
4273 {
4274 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
4275 }
4276 else if(pMac->roam.configParam.fEnforceDefaultDomain)
4277 {
4278 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
4279 }
4280 else
4281 {
4282 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
4283 }
4284 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
4285 }
4286 }
4287#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4288
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004289 csrPruneChannelListForMode(pMac, &pMac->scan.baseChannels);
4290 csrPruneChannelListForMode(pMac, &pMac->scan.base20MHzChannels);
4291
Jeff Johnson295189b2012-06-20 16:38:30 -07004292 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_FALSE);
4293 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_TRUE);
4294 // ... and apply the channel list, power settings, and the country code.
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004295 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.base20MHzChannels, pMac->scan.countryCodeCurrent, updateRiva );
Jeff Johnson295189b2012-06-20 16:38:30 -07004296 // clear the 11d channel list
Kiet Lam64c1b492013-07-12 13:56:44 +05304297 vos_mem_set(&pMac->scan.channels11d, sizeof(pMac->scan.channels11d), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004298 pMac->scan.f11dInfoReset = eANI_BOOLEAN_TRUE;
4299 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_FALSE;
4300 }
4301
4302 return;
4303}
4304
4305
4306eHalStatus csrResetCountryCodeInformation(tpAniSirGlobal pMac, tANI_BOOLEAN *pfRestartNeeded)
4307{
4308 eHalStatus status = eHAL_STATUS_SUCCESS;
4309 tANI_BOOLEAN fRestart = eANI_BOOLEAN_FALSE;
4310
4311 //Use the Country code and domain from EEPROM
Kiet Lam64c1b492013-07-12 13:56:44 +05304312 vos_mem_copy(pMac->scan.countryCodeCurrent, pMac->scan.countryCodeDefault,
4313 WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07004314 csrSetRegulatoryDomain(pMac, pMac->scan.domainIdCurrent, &fRestart);
Jeff Johnson43971f52012-07-17 12:26:56 -07004315 if( ((eANI_BOOLEAN_FALSE == fRestart) || (pfRestartNeeded == NULL) )
4316 && !csrIsInfraConnected(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -07004317 {
4318 //Only reset the country info if we don't need to restart
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004319 csrResetCountryInformation(pMac, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07004320 }
4321 if(pfRestartNeeded)
4322 {
4323 *pfRestartNeeded = fRestart;
4324 }
4325
4326 return (status);
4327}
4328
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05304329void csrClearVotesForCountryInfo(tpAniSirGlobal pMac)
4330{
4331 pMac->scan.countryCodeCount = 0;
4332 vos_mem_set(pMac->scan.votes11d,
4333 sizeof(tCsrVotes11d) * CSR_MAX_NUM_COUNTRY_CODE, 0);
4334}
4335
4336void csrAddVoteForCountryInfo(tpAniSirGlobal pMac, tANI_U8 *pCountryCode)
4337{
4338 tANI_BOOLEAN match = FALSE;
4339 tANI_U8 i;
4340
4341 /* convert to UPPER here so we are assured
4342 * the strings are always in upper case.
4343 */
4344 for( i = 0; i < 3; i++ )
4345 {
4346 pCountryCode[ i ] = (tANI_U8)csrToUpper( pCountryCode[ i ] );
4347 }
4348
4349 /* Some of the 'old' Cisco 350 series AP's advertise NA as the
4350 * country code (for North America ??). NA is not a valid country code
4351 * or domain so let's allow this by changing it to the proper
4352 * country code (which is US). We've also seen some NETGEAR AP's
4353 * that have "XX " as the country code with valid 2.4 GHz US channel
4354 * information. If we cannot find the country code advertised in the
4355 * 11d information element, let's default to US.
4356 */
4357
4358 if ( !HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry( pMac,
4359 pCountryCode, NULL,COUNTRY_QUERY ) ) )
4360 {
4361 pCountryCode[ 0 ] = '0';
4362 pCountryCode[ 1 ] = '0';
4363 }
4364
4365 /* We've seen some of the AP's improperly put a 0 for the
4366 * third character of the country code. spec says valid charcters are
4367 * 'O' (for outdoor), 'I' for Indoor, or ' ' (space; for either).
4368 * if we see a 0 in this third character, let's change it to a ' '.
4369 */
4370 if ( 0 == pCountryCode[ 2 ] )
4371 {
4372 pCountryCode[ 2 ] = ' ';
4373 }
4374
4375 for (i = 0; i < pMac->scan.countryCodeCount; i++)
4376 {
4377 match = (vos_mem_compare(pMac->scan.votes11d[i].countryCode,
4378 pCountryCode, 2));
4379 if(match)
4380 {
4381 break;
4382 }
4383 }
4384
4385 if (match)
4386 {
4387 pMac->scan.votes11d[i].votes++;
4388 }
4389 else
4390 {
4391 vos_mem_copy( pMac->scan.votes11d[pMac->scan.countryCodeCount].countryCode,
4392 pCountryCode, 3 );
4393 pMac->scan.votes11d[pMac->scan.countryCodeCount].votes = 1;
4394 pMac->scan.countryCodeCount++;
4395 }
4396
4397 return;
4398}
4399
4400tANI_BOOLEAN csrElectedCountryInfo(tpAniSirGlobal pMac)
4401{
4402 tANI_BOOLEAN fRet = FALSE;
4403 tANI_U8 maxVotes = 0;
4404 tANI_U8 i, j=0;
4405
4406 if (!pMac->scan.countryCodeCount)
4407 {
Agrawal Ashishbd3a5932016-04-12 16:22:39 +05304408 VOS_TRACE( VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_WARN,
4409 "No AP with 11d Country code is present in scan list");
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05304410 return fRet;
4411 }
4412 maxVotes = pMac->scan.votes11d[0].votes;
4413 fRet = TRUE;
4414
4415 for(i = 1; i < pMac->scan.countryCodeCount; i++)
4416 {
4417 /* If we have a tie for max votes for 2 different country codes,
4418 * pick random.we can put some more intelligence - TBD
4419 */
4420 if (maxVotes < pMac->scan.votes11d[i].votes)
4421 {
4422 VOS_TRACE( VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
4423 " Votes for Country %c%c : %d\n",
4424 pMac->scan.votes11d[i].countryCode[0],
4425 pMac->scan.votes11d[i].countryCode[1],
4426 pMac->scan.votes11d[i].votes);
4427
4428 maxVotes = pMac->scan.votes11d[i].votes;
4429 j = i;
4430 fRet = TRUE;
4431 }
4432
4433 }
4434 if (fRet)
4435 {
Rajesh Babu Prathipati20cdffa2014-07-01 22:24:59 +05304436 vos_mem_copy(pMac->scan.countryCodeElected,
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05304437 pMac->scan.votes11d[j].countryCode, WNI_CFG_COUNTRY_CODE_LEN);
Rajesh Babu Prathipati20cdffa2014-07-01 22:24:59 +05304438 vos_mem_copy(pMac->scan.countryCode11d,
Agarwal Ashish852b2c32014-05-23 17:13:25 +05304439 pMac->scan.votes11d[j].countryCode, WNI_CFG_COUNTRY_CODE_LEN);
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05304440 VOS_TRACE( VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
4441 "Selected Country is %c%c With count %d\n",
4442 pMac->scan.votes11d[j].countryCode[0],
4443 pMac->scan.votes11d[j].countryCode[1],
4444 pMac->scan.votes11d[j].votes);
4445 }
4446 return fRet;
4447}
Jeff Johnson295189b2012-06-20 16:38:30 -07004448
4449eHalStatus csrSetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pCountry, tANI_BOOLEAN *pfRestartNeeded)
4450{
4451 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
4452 v_REGDOMAIN_t domainId;
4453
4454 if(pCountry)
4455 {
Kiet Lam6c583332013-10-14 05:37:09 +05304456 status = csrGetRegulatoryDomainForCountry(pMac, pCountry, &domainId, COUNTRY_USER);
Jeff Johnson295189b2012-06-20 16:38:30 -07004457 if(HAL_STATUS_SUCCESS(status))
4458 {
4459 status = csrSetRegulatoryDomain(pMac, domainId, pfRestartNeeded);
4460 if(HAL_STATUS_SUCCESS(status))
4461 {
4462 //We don't need to check the pMac->roam.configParam.fEnforceDefaultDomain flag here,
4463 //csrSetRegulatoryDomain will fail if the country doesn't fit our domain criteria.
Kiet Lam64c1b492013-07-12 13:56:44 +05304464 vos_mem_copy(pMac->scan.countryCodeCurrent, pCountry, WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07004465 if((pfRestartNeeded == NULL) || !(*pfRestartNeeded))
4466 {
4467 //Simply set it to cfg. If we need to restart, restart will apply it to the CFG
4468 csrSetCfgCountryCode(pMac, pCountry);
4469 }
4470 }
4471 }
4472 }
4473
4474 return (status);
4475}
4476
4477
4478
4479//caller allocated memory for pNumChn and pChnPowerInfo
4480//As input, *pNumChn has the size of the array of pChnPowerInfo
4481//Upon return, *pNumChn has the number of channels assigned.
4482void csrGetChannelPowerInfo( tpAniSirGlobal pMac, tDblLinkList *pList,
4483 tANI_U32 *pNumChn, tChannelListWithPower *pChnPowerInfo)
4484{
4485 tListElem *pEntry;
4486 tANI_U32 chnIdx = 0, idx;
4487 tCsrChannelPowerInfo *pChannelSet;
4488
4489 //Get 2.4Ghz first
4490 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
4491 while( pEntry && (chnIdx < *pNumChn) )
4492 {
4493 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
4494 if ( 1 != pChannelSet->interChannelOffset )
4495 {
4496 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
4497 {
4498 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
4499 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
4500 }
4501 }
4502 else
4503 {
4504 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
4505 {
4506 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + idx);
4507 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
4508 }
4509 }
4510
4511 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
4512 }
4513 *pNumChn = chnIdx;
4514
4515 return ;
4516}
4517
4518
4519
4520void csrApplyCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce )
4521{
4522 v_REGDOMAIN_t domainId;
4523 eHalStatus status = eHAL_STATUS_SUCCESS;
4524
4525 do
4526 {
4527 if( !csrIs11dSupported( pMac ) || 0 == pMac->scan.channelOf11dInfo) break;
4528 if( pMac->scan.fAmbiguous11dInfoFound )
4529 {
4530 // ambiguous info found
4531 //Restore te default domain as well
Kiet Lam6c583332013-10-14 05:37:09 +05304532 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
4533 pMac, pMac->scan.countryCodeCurrent,
4534 &domainId, COUNTRY_QUERY)))
Jeff Johnson295189b2012-06-20 16:38:30 -07004535 {
4536 pMac->scan.domainIdCurrent = domainId;
4537 }
4538 else
4539 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004540 smsLog(pMac, LOGE, FL(" failed to get domain from currentCountryCode %02X%02X"),
Jeff Johnson295189b2012-06-20 16:38:30 -07004541 pMac->scan.countryCodeCurrent[0], pMac->scan.countryCodeCurrent[1]);
4542 }
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004543 csrResetCountryInformation( pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE );
Jeff Johnson295189b2012-06-20 16:38:30 -07004544 break;
4545 }
4546 if ( pMac->scan.f11dInfoApplied && !fForce ) break;
Kiet Lam6c583332013-10-14 05:37:09 +05304547 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
4548 pMac, pMac->scan.countryCode11d,
4549 &domainId, COUNTRY_QUERY)))
Jeff Johnson295189b2012-06-20 16:38:30 -07004550 {
4551 //Check whether we need to enforce default domain
4552 if( ( !pMac->roam.configParam.fEnforceDefaultDomain ) ||
4553 (pMac->scan.domainIdCurrent == domainId) )
4554 {
4555
4556#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4557 {
4558 vos_log_802_11d_pkt_type *p11dLog;
4559 tChannelListWithPower chnPwrInfo[WNI_CFG_VALID_CHANNEL_LIST_LEN];
4560 tANI_U32 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN, nTmp;
4561
4562 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
4563 if(p11dLog)
4564 {
4565 p11dLog->eventId = WLAN_80211D_EVENT_COUNTRY_SET;
Kiet Lam64c1b492013-07-12 13:56:44 +05304566 vos_mem_copy(p11dLog->countryCode, pMac->scan.countryCode11d, 3);
Jeff Johnson295189b2012-06-20 16:38:30 -07004567 p11dLog->numChannel = pMac->scan.channels11d.numChannels;
4568 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
4569 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304570 vos_mem_copy(p11dLog->Channels,
4571 pMac->scan.channels11d.channelList,
4572 p11dLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07004573 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList24,
4574 &nChnInfo, chnPwrInfo);
4575 nTmp = nChnInfo;
4576 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN - nTmp;
4577 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList5G,
4578 &nChnInfo, &chnPwrInfo[nTmp]);
4579 for(nTmp = 0; nTmp < p11dLog->numChannel; nTmp++)
4580 {
4581 for(nChnInfo = 0; nChnInfo < WNI_CFG_VALID_CHANNEL_LIST_LEN; nChnInfo++)
4582 {
4583 if(p11dLog->Channels[nTmp] == chnPwrInfo[nChnInfo].chanId)
4584 {
4585 p11dLog->TxPwr[nTmp] = chnPwrInfo[nChnInfo].pwr;
4586 break;
4587 }
4588 }
4589 }
4590 }
4591 if(!pMac->roam.configParam.Is11dSupportEnabled)
4592 {
4593 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
4594 }
4595 else if(pMac->roam.configParam.fEnforceDefaultDomain)
4596 {
4597 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
4598 }
4599 else
4600 {
4601 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
4602 }
4603 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
4604 }
4605 }
4606#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4607 if(pMac->scan.domainIdCurrent != domainId)
4608 {
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05304609 smsLog(pMac, LOGW, FL("Domain Changed Old %s (%d), new %s"),
4610 voss_DomainIdtoString(pMac->scan.domainIdCurrent),
4611 pMac->scan.domainIdCurrent,
4612 voss_DomainIdtoString(domainId));
Abhishek Singha306a442013-11-07 18:39:01 +05304613 status = WDA_SetRegDomain(pMac, domainId, eSIR_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07004614 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004615 if (status != eHAL_STATUS_SUCCESS)
4616 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004617 smsLog( pMac, LOGE, FL(" fail to set regId %d"), domainId );
Jeff Johnson295189b2012-06-20 16:38:30 -07004618 }
4619 pMac->scan.domainIdCurrent = domainId;
Kiet Lam6c583332013-10-14 05:37:09 +05304620#ifndef CONFIG_ENABLE_LINUX_REG
Kiet Lambb14e952013-11-19 14:58:29 +05304621 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.base20MHzChannels,
4622 pMac->scan.countryCodeCurrent, eANI_BOOLEAN_TRUE );
Kiet Lam6c583332013-10-14 05:37:09 +05304623#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004624 // switch to active scans using this new channel list
4625 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
4626 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_TRUE;
4627 pMac->scan.f11dInfoReset = eANI_BOOLEAN_FALSE;
4628 }
4629 }
4630
4631 } while( 0 );
4632
4633 return;
4634}
4635
4636
4637
4638tANI_BOOLEAN csrSave11dCountryString( tpAniSirGlobal pMac, tANI_U8 *pCountryCode,
4639 tANI_BOOLEAN fForce)
4640{
4641 tANI_BOOLEAN fCountryStringChanged = FALSE, fUnknownCountryCode = FALSE;
4642 tANI_U32 i;
Kiet Lam6c583332013-10-14 05:37:09 +05304643 v_REGDOMAIN_t regd;
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004644 tANI_BOOLEAN fCountryNotPresentInDriver = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004645
4646 // convert to UPPER here so we are assured the strings are always in upper case.
4647 for( i = 0; i < 3; i++ )
4648 {
4649 pCountryCode[ i ] = (tANI_U8)csrToUpper( pCountryCode[ i ] );
4650 }
4651
4652 // Some of the 'old' Cisco 350 series AP's advertise NA as the country code (for North America ??).
4653 // NA is not a valid country code or domain so let's allow this by changing it to the proper
4654 // country code (which is US). We've also seen some NETGEAR AP's that have "XX " as the country code
4655 // with valid 2.4 GHz US channel information. If we cannot find the country code advertised in the
4656 // 11d information element, let's default to US.
Kiet Lam6c583332013-10-14 05:37:09 +05304657 if ( !HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(pMac,
4658 pCountryCode,
4659 &regd,
4660 COUNTRY_QUERY) ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07004661 {
4662 // Check the enforcement first
4663 if( pMac->roam.configParam.fEnforceDefaultDomain || pMac->roam.configParam.fEnforceCountryCodeMatch )
4664 {
4665 fUnknownCountryCode = TRUE;
4666 }
4667 else
4668 {
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004669 fCountryNotPresentInDriver = TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004670 }
4671 }
Tushnim Bhattacharyyac3c1e8e2013-10-29 17:27:43 -07004672 //right now, even if we don't find the CC in driver we set to world. Making
4673 //sure countryCode11d doesn't get updated with the invalid CC, instead
4674 //reflect the world CC
4675 else if (REGDOMAIN_WORLD == regd)
4676 {
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004677 fCountryNotPresentInDriver = TRUE;
Tushnim Bhattacharyyac3c1e8e2013-10-29 17:27:43 -07004678 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004679
4680 // We've seen some of the AP's improperly put a 0 for the third character of the country code.
4681 // spec says valid charcters are 'O' (for outdoor), 'I' for Indoor, or ' ' (space; for either).
4682 // if we see a 0 in this third character, let's change it to a ' '.
4683 if ( 0 == pCountryCode[ 2 ] )
4684 {
4685 pCountryCode[ 2 ] = ' ';
4686 }
4687
4688 if( !fUnknownCountryCode )
4689 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304690 fCountryStringChanged = (!vos_mem_compare(pMac->scan.countryCode11d, pCountryCode, 2));
Jeff Johnson295189b2012-06-20 16:38:30 -07004691
4692
4693 if(( 0 == pMac->scan.countryCode11d[ 0 ] && 0 == pMac->scan.countryCode11d[ 1 ] )
4694 || (fForce))
4695 {
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004696 if (!fCountryNotPresentInDriver)
4697 {
4698 // this is the first .11d information
4699 vos_mem_copy(pMac->scan.countryCode11d, pCountryCode,
Kiet Lam64c1b492013-07-12 13:56:44 +05304700 sizeof( pMac->scan.countryCode11d ));
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004701
4702 }
4703 else
4704 {
4705 pMac->scan.countryCode11d[0] = '0';
4706 pMac->scan.countryCode11d[1] = '0';
4707 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004708 }
4709 }
4710
4711 return( fCountryStringChanged );
4712}
4713
4714
4715void csrSaveChannelPowerForBand( tpAniSirGlobal pMac, tANI_BOOLEAN fPopulate5GBand )
4716{
4717 tANI_U32 Index, count=0;
4718 tSirMacChanInfo *pChanInfo;
4719 tSirMacChanInfo *pChanInfoStart;
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08004720 tANI_S32 maxChannelIndex;
4721
4722 maxChannelIndex = ( pMac->scan.base20MHzChannels.numChannels < WNI_CFG_VALID_CHANNEL_LIST_LEN ) ?
4723 pMac->scan.base20MHzChannels.numChannels : WNI_CFG_VALID_CHANNEL_LIST_LEN ;
Jeff Johnson295189b2012-06-20 16:38:30 -07004724
Kiet Lam64c1b492013-07-12 13:56:44 +05304725 pChanInfo = vos_mem_malloc(sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN);
4726 if ( NULL != pChanInfo )
Jeff Johnson295189b2012-06-20 16:38:30 -07004727 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304728 vos_mem_set(pChanInfo, sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004729 pChanInfoStart = pChanInfo;
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08004730 for (Index=0; Index < maxChannelIndex; Index++)
Jeff Johnson295189b2012-06-20 16:38:30 -07004731 {
4732 if ((fPopulate5GBand && (CSR_IS_CHANNEL_5GHZ(pMac->scan.defaultPowerTable[Index].chanId))) ||
4733 (!fPopulate5GBand && (CSR_IS_CHANNEL_24GHZ(pMac->scan.defaultPowerTable[Index].chanId))) )
4734 {
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08004735 if(count >= WNI_CFG_VALID_CHANNEL_LIST_LEN)
4736 {
4737 smsLog( pMac, LOGW, FL(" csrSaveChannelPowerForBand, count exceeded, count = %d"), count);
4738 break;
4739 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004740 pChanInfo->firstChanNum = pMac->scan.defaultPowerTable[Index].chanId;
4741 pChanInfo->numChannels = 1;
4742 pChanInfo->maxTxPower = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
4743 pChanInfo++;
4744 count++;
4745 }
4746 }
4747 if(count)
4748 {
4749 csrSaveToChannelPower2G_5G( pMac, count * sizeof(tSirMacChanInfo), pChanInfoStart );
4750 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304751 vos_mem_free(pChanInfoStart);
Jeff Johnson295189b2012-06-20 16:38:30 -07004752 }
4753}
4754
4755
4756void csrSetOppositeBandChannelInfo( tpAniSirGlobal pMac )
4757{
4758 tANI_BOOLEAN fPopulate5GBand = FALSE;
4759
4760 do
4761 {
4762 // if this is not a dual band product, then we don't need to set the opposite
4763 // band info. We only work in one band so no need to look in the other band.
4764 if ( !CSR_IS_OPEARTING_DUAL_BAND( pMac ) ) break;
4765 // if we found channel info on the 5.0 band and...
4766 if ( CSR_IS_CHANNEL_5GHZ( pMac->scan.channelOf11dInfo ) )
4767 {
4768 // and the 2.4 band is empty, then populate the 2.4 channel info
Kiet Lam8d985a02013-10-11 03:39:41 +05304769 if ( !csrLLIsListEmpty( &pMac->scan.channelPowerInfoList24, LL_ACCESS_LOCK ) ) break;
Jeff Johnson295189b2012-06-20 16:38:30 -07004770 fPopulate5GBand = FALSE;
4771 }
4772 else
4773 {
4774 // else, we found channel info in the 2.4 GHz band. If the 5.0 band is empty
4775 // set the 5.0 band info from the 2.4 country code.
Kiet Lam8d985a02013-10-11 03:39:41 +05304776 if ( !csrLLIsListEmpty( &pMac->scan.channelPowerInfoList5G, LL_ACCESS_LOCK ) ) break;
Jeff Johnson295189b2012-06-20 16:38:30 -07004777 fPopulate5GBand = TRUE;
4778 }
4779 csrSaveChannelPowerForBand( pMac, fPopulate5GBand );
4780
4781 } while( 0 );
4782}
4783
4784
4785tANI_BOOLEAN csrIsSupportedChannel(tpAniSirGlobal pMac, tANI_U8 channelId)
4786{
4787 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
4788 tANI_U32 i;
4789
4790 //Make sure it is a channel that is in our supported list.
4791 for ( i = 0; i < pMac->scan.baseChannels.numChannels; i++ )
4792 {
4793 if ( channelId == pMac->scan.baseChannels.channelList[i] )
4794 {
4795 fRet = eANI_BOOLEAN_TRUE;
4796 break;
4797 }
4798 }
4799
4800 //If it is configured to limit a set of the channels
4801 if( fRet && pMac->roam.configParam.fEnforce11dChannels )
4802 {
4803 fRet = eANI_BOOLEAN_FALSE;
4804 for ( i = 0; i < pMac->scan.base20MHzChannels.numChannels; i++ )
4805 {
4806 if ( channelId == pMac->scan.base20MHzChannels.channelList[i] )
4807 {
4808 fRet = eANI_BOOLEAN_TRUE;
4809 break;
4810 }
4811 }
4812 }
4813
4814 return (fRet);
4815}
4816
4817
4818
4819//bSize specify the buffer size of pChannelList
4820tANI_U8 csrGetChannelListFromChannelSet( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 bSize, tCsrChannelPowerInfo *pChannelSet )
4821{
4822 tANI_U8 i, j = 0, chnId;
4823
4824 bSize = CSR_MIN(bSize, pChannelSet->numChannels);
4825 for( i = 0; i < bSize; i++ )
4826 {
4827 chnId = (tANI_U8)(pChannelSet->firstChannel + ( i * pChannelSet->interChannelOffset ));
4828 if ( csrIsSupportedChannel( pMac, chnId ) )
4829 {
4830 pChannelList[j++] = chnId;
4831 }
4832 }
4833
4834 return (j);
4835}
4836
4837
4838
4839//bSize -- specify the buffer size of pChannelList
4840void csrConstructCurrentValidChannelList( tpAniSirGlobal pMac, tDblLinkList *pChannelSetList,
4841 tANI_U8 *pChannelList, tANI_U8 bSize, tANI_U8 *pNumChannels )
4842{
4843 tListElem *pEntry;
4844 tCsrChannelPowerInfo *pChannelSet;
4845 tANI_U8 numChannels;
4846 tANI_U8 *pChannels;
4847
4848 if( pChannelSetList && pChannelList && pNumChannels )
4849 {
4850 pChannels = pChannelList;
4851 *pNumChannels = 0;
4852 pEntry = csrLLPeekHead( pChannelSetList, LL_ACCESS_LOCK );
4853 while( pEntry )
4854 {
4855 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
4856 numChannels = csrGetChannelListFromChannelSet( pMac, pChannels, bSize, pChannelSet );
4857 pChannels += numChannels;
4858 *pNumChannels += numChannels;
4859 pEntry = csrLLNext( pChannelSetList, pEntry, LL_ACCESS_LOCK );
4860 }
4861 }
4862}
4863
4864
4865/*
4866 * 802.11D only: Gather 11d IE via beacon or Probe response and store them in pAdapter->channels11d
4867*/
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304868tANI_BOOLEAN csrLearnCountryInformation( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc,
4869 tDot11fBeaconIEs *pIes, tANI_BOOLEAN fForce)
Jeff Johnson295189b2012-06-20 16:38:30 -07004870{
Agarwal Ashish60a37ee2014-05-28 17:20:20 +05304871 eHalStatus status;
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304872 tANI_U8 *pCountryCodeSelected;
Jeff Johnson295189b2012-06-20 16:38:30 -07004873 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
4874 v_REGDOMAIN_t domainId;
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304875 tDot11fBeaconIEs *pIesLocal = pIes;
4876 tANI_BOOLEAN useVoting = eANI_BOOLEAN_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004877
Jeff Johnson295189b2012-06-20 16:38:30 -07004878 if (VOS_STA_SAP_MODE == vos_get_conparam ())
4879 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07004880
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304881 if ((NULL == pSirBssDesc) && (NULL == pIes))
4882 useVoting = eANI_BOOLEAN_TRUE;
4883
Jeff Johnson295189b2012-06-20 16:38:30 -07004884 do
4885 {
4886 // check if .11d support is enabled
4887 if( !csrIs11dSupported( pMac ) ) break;
Agarwal Ashish60a37ee2014-05-28 17:20:20 +05304888
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304889 if (eANI_BOOLEAN_FALSE == useVoting)
4890 {
4891 if( !pIesLocal &&
4892 (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
4893 pSirBssDesc, &pIesLocal))))
4894 {
4895 break;
4896 }
4897 // check if country information element is present
4898 if(!pIesLocal->Country.present)
4899 {
4900 //No country info
4901 break;
4902 }
4903
4904 if( HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry
4905 (pMac, pIesLocal->Country.country, &domainId,
4906 COUNTRY_QUERY)) &&
4907 ( domainId == REGDOMAIN_WORLD))
4908 {
4909 break;
4910 }
4911 } //useVoting == eANI_BOOLEAN_FALSE
4912
4913 if (eANI_BOOLEAN_FALSE == useVoting)
4914 pCountryCodeSelected = pIesLocal->Country.country;
4915 else
4916 pCountryCodeSelected = pMac->scan.countryCodeElected;
4917
Kiet Lam8d985a02013-10-11 03:39:41 +05304918 status = csrGetRegulatoryDomainForCountry(pMac,
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304919 pCountryCodeSelected, &domainId, COUNTRY_IE);
Kiet Lam8d985a02013-10-11 03:39:41 +05304920 if ( status != eHAL_STATUS_SUCCESS )
4921 {
4922 smsLog( pMac, LOGE, FL(" fail to get regId %d"), domainId );
4923 fRet = eANI_BOOLEAN_FALSE;
4924 break;
4925 }
Agarwal Ashish7693f2d2014-07-18 18:03:58 +05304926
4927 /* updating 11d Country Code with Country code selected. */
4928
4929 vos_mem_copy(pMac->scan.countryCode11d,
4930 pCountryCodeSelected,
4931 WNI_CFG_COUNTRY_CODE_LEN);
4932
Agarwal Ashish60a37ee2014-05-28 17:20:20 +05304933#ifndef CONFIG_ENABLE_LINUX_REG
Venkata Prathyusha Kuntupalli316247e2013-03-15 17:45:25 -07004934 // Checking for Domain Id change
4935 if ( domainId != pMac->scan.domainIdCurrent )
4936 {
Kiet Lam8d985a02013-10-11 03:39:41 +05304937 vos_mem_copy(pMac->scan.countryCode11d,
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304938 pCountryCodeSelected,
Kiet Lam8d985a02013-10-11 03:39:41 +05304939 sizeof( pMac->scan.countryCode11d ) );
4940 /* Set Current Country code and Current Regulatory domain */
4941 status = csrSetRegulatoryDomain(pMac, domainId, NULL);
4942 if (eHAL_STATUS_SUCCESS != status)
4943 {
4944 smsLog(pMac, LOGE, "Set Reg Domain Fail %d", status);
4945 fRet = eANI_BOOLEAN_FALSE;
4946 return fRet;
4947 }
4948 //csrSetRegulatoryDomain will fail if the country doesn't fit our domain criteria.
4949 vos_mem_copy(pMac->scan.countryCodeCurrent,
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304950 pCountryCodeSelected, WNI_CFG_COUNTRY_CODE_LEN);
Kiet Lam8d985a02013-10-11 03:39:41 +05304951 //Simply set it to cfg.
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304952 csrSetCfgCountryCode(pMac, pCountryCodeSelected);
Kiet Lam8d985a02013-10-11 03:39:41 +05304953
4954 /* overwrite the defualt country code */
4955 vos_mem_copy(pMac->scan.countryCodeDefault,
4956 pMac->scan.countryCodeCurrent,
4957 WNI_CFG_COUNTRY_CODE_LEN);
4958 /* Set Current RegDomain */
Abhishek Singha306a442013-11-07 18:39:01 +05304959 status = WDA_SetRegDomain(pMac, domainId, eSIR_TRUE);
Kiet Lam8d985a02013-10-11 03:39:41 +05304960 if ( status != eHAL_STATUS_SUCCESS )
4961 {
4962 smsLog( pMac, LOGE, FL(" fail to Set regId %d"), domainId );
4963 fRet = eANI_BOOLEAN_FALSE;
4964 return fRet;
4965 }
4966 /* set to default domain ID */
Madan Mohan Koyyalamudi0e5922d2013-09-10 15:45:24 +05304967 pMac->scan.domainIdCurrent = domainId;
Kiet Lam8d985a02013-10-11 03:39:41 +05304968 /* get the channels based on new cc */
4969 status = csrInitGetChannels( pMac );
Jeff Johnson295189b2012-06-20 16:38:30 -07004970
Kiet Lam8d985a02013-10-11 03:39:41 +05304971 if ( status != eHAL_STATUS_SUCCESS )
4972 {
4973 smsLog( pMac, LOGE, FL(" fail to get Channels "));
4974 fRet = eANI_BOOLEAN_FALSE;
4975 return fRet;
4976 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004977
Kiet Lam8d985a02013-10-11 03:39:41 +05304978 /* reset info based on new cc, and we are done */
4979 csrResetCountryInformation(pMac, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
Agarwal Ashishfaef6692014-01-29 19:40:30 +05304980 /* Regulatory Domain Changed, Purge Only scan result
4981 * which does not have channel number belong to 11d
4982 * channel list
4983 */
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05304984 csrScanFilterResults(pMac);
Kiet Lam8d985a02013-10-11 03:39:41 +05304985 }
Kiet Lam6c583332013-10-14 05:37:09 +05304986#endif
4987 fRet = eANI_BOOLEAN_TRUE;
4988
Jeff Johnson295189b2012-06-20 16:38:30 -07004989 } while( 0 );
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304990
4991 if( !pIes && pIesLocal )
4992 {
4993 //locally allocated
4994 vos_mem_free(pIesLocal);
4995 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004996
4997 return( fRet );
4998}
4999
5000
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005001static void csrSaveScanResults( tpAniSirGlobal pMac, tANI_U8 reason )
Jeff Johnson295189b2012-06-20 16:38:30 -07005002{
5003 // initialize this to FALSE. profMoveInterimScanResultsToMainList() routine
5004 // will set this to the channel where an .11d beacon is seen
5005 pMac->scan.channelOf11dInfo = 0;
5006 // if we get any ambiguous .11d information then this will be set to TRUE
5007 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
5008 //Tush
5009 // if we get any ambiguous .11d information, then this will be set to TRUE
5010 // only if the applied 11d info could be found in one of the scan results
5011 pMac->scan.fCurrent11dInfoMatch = eANI_BOOLEAN_FALSE;
5012 // move the scan results from interim list to the main scan list
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005013 csrMoveTempScanResultsToMainList( pMac, reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07005014}
5015
5016
5017void csrReinitScanCmd(tpAniSirGlobal pMac, tSmeCmd *pCommand)
5018{
5019 switch (pCommand->u.scanCmd.reason)
5020 {
5021 case eCsrScanSetBGScanParam:
5022 case eCsrScanAbortBgScan:
5023 if(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList)
5024 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305025 vos_mem_free(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList);
Jeff Johnson295189b2012-06-20 16:38:30 -07005026 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
5027 }
5028 break;
5029 case eCsrScanBGScanAbort:
5030 case eCsrScanBGScanEnable:
5031 case eCsrScanGetScanChnInfo:
5032 break;
5033 case eCsrScanAbortNormalScan:
5034 default:
5035 csrScanFreeRequest(pMac, &pCommand->u.scanCmd.u.scanRequest);
5036 break;
5037 }
5038 if(pCommand->u.scanCmd.pToRoamProfile)
5039 {
5040 csrReleaseProfile(pMac, pCommand->u.scanCmd.pToRoamProfile);
Kiet Lam64c1b492013-07-12 13:56:44 +05305041 vos_mem_free(pCommand->u.scanCmd.pToRoamProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07005042 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305043 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005044}
5045
5046
5047tANI_BOOLEAN csrGetRemainingChannelsFor11dScan( tpAniSirGlobal pMac, tANI_U8 *pChannels, tANI_U8 *pcChannels )
5048{
5049 tANI_U32 index11dChannels, index;
5050 tANI_U32 indexCurrentChannels;
5051 tANI_BOOLEAN fChannelAlreadyScanned;
5052 tANI_U32 len = sizeof(pMac->roam.validChannelList);
5053
5054 *pcChannels = 0;
5055 if ( CSR_IS_11D_INFO_FOUND(pMac) && csrRoamIsChannelValid(pMac, pMac->scan.channelOf11dInfo) )
5056 {
5057 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
5058 {
5059 //Find the channel index where we found the 11d info
5060 for(index = 0; index < len; index++)
5061 {
5062 if(pMac->scan.channelOf11dInfo == pMac->roam.validChannelList[index])
5063 break;
5064 }
5065 //check whether we found the channel index
5066 if(index < len)
5067 {
5068 // Now, look through the 11d channel list and create a list of all channels in the 11d list that are
5069 // NOT in the current channel list. This gives us a list of the new channels that have not been
5070 // scanned. We'll scan this new list so we have a complete set of scan results on all of the domain channels
5071 // initially.
5072 for ( index11dChannels = 0; index11dChannels < pMac->scan.channels11d.numChannels; index11dChannels++ )
5073 {
5074 fChannelAlreadyScanned = eANI_BOOLEAN_FALSE;
5075
5076 for( indexCurrentChannels = 0; indexCurrentChannels < index; indexCurrentChannels++ )
5077 {
5078 if ( pMac->roam.validChannelList[ indexCurrentChannels ] == pMac->scan.channels11d.channelList[ index11dChannels ] )
5079 {
5080 fChannelAlreadyScanned = eANI_BOOLEAN_TRUE;
5081 break;
5082 }
5083 }
5084
5085 if ( !fChannelAlreadyScanned )
5086 {
5087 pChannels[ *pcChannels ] = pMac->scan.channels11d.channelList[ index11dChannels ];
5088 ( *pcChannels )++;
5089 }
5090 }
5091 }
5092 }//GetCFG
5093 }
5094 return( *pcChannels );
5095}
5096
5097
5098eCsrScanCompleteNextCommand csrScanGetNextCommandState( tpAniSirGlobal pMac, tSmeCmd *pCommand, tANI_BOOLEAN fSuccess )
5099{
5100 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
5101
5102 switch( pCommand->u.scanCmd.reason )
5103 {
5104 case eCsrScan11d1:
5105 NextCommand = (fSuccess) ? eCsrNext11dScan1Success : eCsrNext11dScan1Failure;
5106 break;
5107 case eCsrScan11d2:
5108 NextCommand = (fSuccess) ? eCsrNext11dScan2Success : eCsrNext11dScan2Failure;
5109 break;
5110 case eCsrScan11dDone:
5111 NextCommand = eCsrNext11dScanComplete;
5112 break;
5113 case eCsrScanLostLink1:
5114 NextCommand = (fSuccess) ? eCsrNextLostLinkScan1Success : eCsrNextLostLinkScan1Failed;
5115 break;
5116 case eCsrScanLostLink2:
5117 NextCommand = (fSuccess) ? eCsrNextLostLinkScan2Success : eCsrNextLostLinkScan2Failed;
5118 break;
5119 case eCsrScanLostLink3:
5120 NextCommand = (fSuccess) ? eCsrNextLostLinkScan3Success : eCsrNextLostLinkScan3Failed;
5121 break;
5122 case eCsrScanForSsid:
5123 NextCommand = (fSuccess) ? eCsrNexteScanForSsidSuccess : eCsrNexteScanForSsidFailure;
5124 break;
5125 case eCsrScanForCapsChange:
5126 NextCommand = eCsrNextCapChangeScanComplete; //don't care success or not
5127 break;
5128 case eCsrScanIdleScan:
5129 NextCommand = eCsrNextIdleScanComplete;
5130 break;
5131 default:
5132 NextCommand = eCsrNextScanNothing;
5133 break;
5134 }
5135 return( NextCommand );
5136}
5137
5138
5139//Return whether the pCommand is finished.
5140tANI_BOOLEAN csrHandleScan11d1Failure(tpAniSirGlobal pMac, tSmeCmd *pCommand)
5141{
5142 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
5143
5144 //Apply back the default setting and passively scan one more time.
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08005145 csrResetCountryInformation(pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07005146 pCommand->u.scanCmd.reason = eCsrScan11d2;
5147 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
5148 {
5149 fRet = eANI_BOOLEAN_FALSE;
5150 }
5151
5152 return (fRet);
5153}
5154
5155
5156tANI_BOOLEAN csrHandleScan11dSuccess(tpAniSirGlobal pMac, tSmeCmd *pCommand)
5157{
5158 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
5159 tANI_U8 *pChannels;
5160 tANI_U8 cChannels;
5161
Kiet Lam64c1b492013-07-12 13:56:44 +05305162 pChannels = vos_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
5163 if ( NULL != pChannels )
Jeff Johnson295189b2012-06-20 16:38:30 -07005164 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305165 vos_mem_set(pChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005166 if ( csrGetRemainingChannelsFor11dScan( pMac, pChannels, &cChannels ) )
5167 {
5168 pCommand->u.scanCmd.reason = eCsrScan11dDone;
5169 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
5170 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305171 vos_mem_free(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -07005172 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07005173 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305174 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(cChannels);
5175 if ( NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07005176 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305177 vos_mem_copy(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
5178 pChannels, cChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07005179 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = cChannels;
5180 pCommand->u.scanCmd.u.scanRequest.requestType = eCSR_SCAN_REQUEST_FULL_SCAN;
5181 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
5182 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
5183 {
5184 //Reuse the same command buffer
5185 fRet = eANI_BOOLEAN_FALSE;
5186 }
5187 }
5188 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305189 vos_mem_free(pChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07005190 }
5191
5192 return (fRet);
5193}
5194
5195//Return whether the command should be removed
5196tANI_BOOLEAN csrScanComplete( tpAniSirGlobal pMac, tSirSmeScanRsp *pScanRsp )
5197{
5198 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
5199 tListElem *pEntry;
5200 tSmeCmd *pCommand;
5201 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
5202 tANI_BOOLEAN fSuccess;
5203
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305204 if (pMac->fScanOffload)
5205 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
5206 else
5207 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07005208
5209 if ( pEntry )
5210 {
5211 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
5212
5213 // If the head of the queue is Active and it is a SCAN command, remove
5214 // and put this on the Free queue.
5215 if ( eSmeCommandScan == pCommand->command )
5216 {
5217 tANI_U32 sessionId = pCommand->sessionId;
5218
5219 if(eSIR_SME_SUCCESS != pScanRsp->statusCode)
5220 {
5221 fSuccess = eANI_BOOLEAN_FALSE;
5222 }
5223 else
5224 {
5225 //pMac->scan.tempScanResults is not empty meaning the scan found something
5226 //This check only valid here because csrSaveScanresults is not yet called
5227 fSuccess = (!csrLLIsListEmpty(&pMac->scan.tempScanResults, LL_ACCESS_LOCK));
5228 }
Ratheesh S Pece1f832015-07-25 15:50:25 +05305229 if (pCommand->u.scanCmd.abortScanIndication &
5230 eCSR_SCAN_ABORT_DUE_TO_BAND_CHANGE)
Srinivas, Dasari187ca4e2014-02-07 12:40:09 +05305231 {
5232 /*
5233 * Scan aborted due to band change
5234 * The scan results need to be flushed
5235 */
5236 if (pCommand->u.scanCmd.callback
5237 != pMac->scan.callback11dScanDone)
5238 {
5239 smsLog(pMac, LOG1, FL("Filtering the scan results as the "
5240 "results may belong to wrong band"));
5241 csrScanFilterResults(pMac);
5242 }
5243 else
5244 {
5245 smsLog(pMac, LOG1, FL("11d_scan_done will flush the scan"
5246 " results"));
5247 }
Srinivas, Dasari187ca4e2014-02-07 12:40:09 +05305248 }
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005249 csrSaveScanResults(pMac, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07005250
Agrawal Ashishdf752672015-12-09 17:51:53 +05305251 /* filter scan result based on valid channel list number */
5252 if (pMac->scan.fcc_constraint)
5253 {
5254 smsLog(pMac, LOG1, FL("Clear BSS from invalid channels"));
5255 csrScanFilterResults(pMac);
5256 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005257#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5258 {
5259 vos_log_scan_pkt_type *pScanLog = NULL;
5260 tScanResultHandle hScanResult;
5261 tCsrScanResultInfo *pScanResult;
5262 tDot11fBeaconIEs *pIes;
5263 int n = 0, c = 0;
5264
5265 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
5266 if(pScanLog)
5267 {
5268 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
5269 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
5270 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
5271 {
5272 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_RSP;
5273 }
5274 else
5275 {
5276 if( eSIR_PASSIVE_SCAN != pMac->scan.curScanType )
5277 {
5278 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_RSP;
5279 }
5280 else
5281 {
5282 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_RSP;
5283 }
5284 }
5285 if(eSIR_SME_SUCCESS == pScanRsp->statusCode)
5286 {
5287 if(HAL_STATUS_SUCCESS(csrScanGetResult(pMac, NULL, &hScanResult)))
5288 {
5289 while(((pScanResult = csrScanResultGetNext(pMac, hScanResult)) != NULL))
5290 {
5291 if( n < VOS_LOG_MAX_NUM_BSSID )
5292 {
5293 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pScanResult->BssDescriptor, &pIes)))
5294 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005295 smsLog(pMac, LOGE, FL(" fail to parse IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07005296 break;
5297 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305298 vos_mem_copy(pScanLog->bssid[n],
5299 pScanResult->BssDescriptor.bssId, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07005300 if(pIes && pIes->SSID.present && VOS_LOG_MAX_SSID_SIZE >= pIes->SSID.num_ssid)
5301 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305302 vos_mem_copy(pScanLog->ssid[n],
5303 pIes->SSID.ssid, pIes->SSID.num_ssid);
Jeff Johnson295189b2012-06-20 16:38:30 -07005304 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305305 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07005306 n++;
5307 }
5308 c++;
5309 }
5310 pScanLog->numSsid = (v_U8_t)n;
5311 pScanLog->totalSsid = (v_U8_t)c;
5312 csrScanResultPurge(pMac, hScanResult);
5313 }
5314 }
5315 else
5316 {
5317 pScanLog->status = WLAN_SCAN_STATUS_FAILURE;
5318 }
5319 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
5320 }
5321 }
5322#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5323
5324 NextCommand = csrScanGetNextCommandState(pMac, pCommand, fSuccess);
5325 //We reuse the command here instead reissue a new command
5326 switch(NextCommand)
5327 {
5328 case eCsrNext11dScan1Success:
5329 case eCsrNext11dScan2Success:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005330 smsLog( pMac, LOG2, FL("11dScan1/3 produced results. Reissue Active scan..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07005331 // if we found country information, no need to continue scanning further, bail out
5332 fRemoveCommand = eANI_BOOLEAN_TRUE;
5333 NextCommand = eCsrNext11dScanComplete;
5334 break;
5335 case eCsrNext11dScan1Failure:
5336 //We are not done yet. 11d scan fail once. We will try to reset anything and do it over again
5337 //The only meaningful thing for this retry is that we cannot find 11d information after a reset so
5338 //we clear the "old" 11d info and give it once more chance
5339 fRemoveCommand = csrHandleScan11d1Failure(pMac, pCommand);
5340 if(fRemoveCommand)
5341 {
5342 NextCommand = eCsrNext11dScanComplete;
5343 }
5344 break;
5345 case eCsrNextLostLinkScan1Success:
5346 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink1)))
5347 {
5348 csrScanHandleFailedLostlink1(pMac, sessionId);
5349 }
5350 break;
5351 case eCsrNextLostLinkScan2Success:
5352 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink2)))
5353 {
5354 csrScanHandleFailedLostlink2(pMac, sessionId);
5355 }
5356 break;
5357 case eCsrNextLostLinkScan3Success:
5358 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink3)))
5359 {
5360 csrScanHandleFailedLostlink3(pMac, sessionId);
5361 }
5362 break;
5363 case eCsrNextLostLinkScan1Failed:
5364 csrScanHandleFailedLostlink1(pMac, sessionId);
5365 break;
5366 case eCsrNextLostLinkScan2Failed:
5367 csrScanHandleFailedLostlink2(pMac, sessionId);
5368 break;
5369 case eCsrNextLostLinkScan3Failed:
5370 csrScanHandleFailedLostlink3(pMac, sessionId);
5371 break;
5372 case eCsrNexteScanForSsidSuccess:
5373 csrScanHandleSearchForSSID(pMac, pCommand);
5374 break;
5375 case eCsrNexteScanForSsidFailure:
5376 csrScanHandleSearchForSSIDFailure(pMac, pCommand);
5377 break;
5378 case eCsrNextIdleScanComplete:
5379 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
5380 break;
5381 case eCsrNextCapChangeScanComplete:
5382 csrScanHandleCapChangeScanComplete(pMac, sessionId);
5383 break;
5384 default:
5385
5386 break;
5387 }
5388 }
5389 else
5390 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005391 smsLog( pMac, LOGW, FL("Scan Completion called but SCAN command is not ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07005392 fRemoveCommand = eANI_BOOLEAN_FALSE;
5393 }
5394 }
5395 else
5396 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005397 smsLog( pMac, LOGW, FL("Scan Completion called but NO commands are ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07005398 fRemoveCommand = eANI_BOOLEAN_FALSE;
5399 }
5400
5401 return( fRemoveCommand );
5402}
5403
5404
Jeff Johnson295189b2012-06-20 16:38:30 -07005405static void csrScanRemoveDupBssDescriptionFromInterimList( tpAniSirGlobal pMac,
5406 tSirBssDescription *pSirBssDescr,
5407 tDot11fBeaconIEs *pIes)
5408{
5409 tListElem *pEntry;
5410 tCsrScanResult *pCsrBssDescription;
Abhishek Singh56c29812018-06-12 14:07:52 +05305411 tDot11fBeaconIEs *temp_ie = pIes;
5412
5413 if (!temp_ie)
5414 csrGetParsedBssDescriptionIEs(pMac, pSirBssDescr, &temp_ie);
Jeff Johnson295189b2012-06-20 16:38:30 -07005415
5416 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
5417 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
5418 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
5419 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
5420 while( pEntry )
5421 {
5422 pCsrBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
5423
5424 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
5425 // matches
5426
Abhishek Singh56c29812018-06-12 14:07:52 +05305427 if (csrIsDuplicateBssDescription(pMac,
5428 &pCsrBssDescription->Result.BssDescriptor,
5429 pSirBssDescr, temp_ie, FALSE))
Jeff Johnson295189b2012-06-20 16:38:30 -07005430 {
Abhishek Singh56c29812018-06-12 14:07:52 +05305431 /*
5432 * Due to Rx sensitivity issue, sometime beacons are seen on
5433 * adjacent channel so workaround in software is needed. If DS
5434 * params or HT info are present driver can get proper channel
5435 * info from these IEs and the older RSSI values are used in new
5436 * entry.
5437 *
5438 * For the cases where DS params and HT info is not present,
5439 * driver needs to check below conditions to update proper
5440 * channel so that the older RSSI and channel values are used in
5441 * new entry:
5442 * -- The old entry channel and new entry channel are not same
5443 * -- RSSI is below 15db or more from old value, this indicate
5444 * that the signal has leaked in adjacent channel
5445 */
5446 if (!pSirBssDescr->fProbeRsp &&
5447 (temp_ie && !temp_ie->DSParams.present &&
5448 !temp_ie->HTInfo.present) &&
5449 (pSirBssDescr->channelId !=
5450 pCsrBssDescription->Result.BssDescriptor.channelId) &&
5451 ((pCsrBssDescription->Result.BssDescriptor.rssi -
5452 pSirBssDescr->rssi) >
5453 SIR_ADJACENT_CHANNEL_RSSI_DIFF_THRESHOLD)) {
5454 pSirBssDescr->channelId =
5455 pCsrBssDescription->Result.BssDescriptor.channelId;
5456 pSirBssDescr->rssi =
5457 pCsrBssDescription->Result.BssDescriptor.rssi;
5458 }
5459
Jeff Johnson295189b2012-06-20 16:38:30 -07005460 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
5461 ((tANI_S32)pCsrBssDescription->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
5462
5463 // Remove the 'old' entry from the list....
5464 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK ) )
5465 {
5466 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pCsrBssDescription->Result.BssDescriptor);
5467 // we need to free the memory associated with this node
5468 csrFreeScanResultEntry( pMac, pCsrBssDescription );
5469 }
5470
5471 // If we found a match, we can stop looking through the list.
5472 break;
5473 }
5474
5475 pEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK );
5476 }
Abhishek Singh56c29812018-06-12 14:07:52 +05305477
5478 if (!pIes && temp_ie)
5479 vos_mem_free(temp_ie);
Jeff Johnson295189b2012-06-20 16:38:30 -07005480}
5481
5482
5483
5484//Caller allocated memory pfNewBssForConn to return whether new candidate for
5485//current connection is found. Cannot be NULL
5486tCsrScanResult *csrScanSaveBssDescriptionToInterimList( tpAniSirGlobal pMac,
5487 tSirBssDescription *pBSSDescription,
5488 tDot11fBeaconIEs *pIes)
5489{
5490 tCsrScanResult *pCsrBssDescription = NULL;
5491 tANI_U32 cbBSSDesc;
5492 tANI_U32 cbAllocated;
Jeff Johnson295189b2012-06-20 16:38:30 -07005493
5494 // figure out how big the BSS description is (the BSSDesc->length does NOT
5495 // include the size of the length field itself).
5496 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
5497
5498 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
5499
Kiet Lam64c1b492013-07-12 13:56:44 +05305500 pCsrBssDescription = vos_mem_malloc(cbAllocated);
5501 if ( NULL != pCsrBssDescription )
Jeff Johnson295189b2012-06-20 16:38:30 -07005502 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305503 vos_mem_set(pCsrBssDescription, cbAllocated, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005504 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Kiet Lam64c1b492013-07-12 13:56:44 +05305505 vos_mem_copy(&pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc );
Jeff Johnson295189b2012-06-20 16:38:30 -07005506 //Save SSID separately for later use
5507 if( pIes->SSID.present && !csrIsNULLSSID(pIes->SSID.ssid, pIes->SSID.num_ssid) )
5508 {
5509 //SSID not hidden
Madan Mohan Koyyalamudi4e31b132012-11-02 13:13:52 -07005510 tANI_U32 len = pIes->SSID.num_ssid;
Jeff Johnson295189b2012-06-20 16:38:30 -07005511 if (len > SIR_MAC_MAX_SSID_LENGTH)
5512 {
5513 // truncate to fit in our struct
5514 len = SIR_MAC_MAX_SSID_LENGTH;
5515 }
5516 pCsrBssDescription->Result.ssId.length = len;
5517 pCsrBssDescription->Result.timer = vos_timer_get_system_time();
Kiet Lam64c1b492013-07-12 13:56:44 +05305518 vos_mem_copy(pCsrBssDescription->Result.ssId.ssId, pIes->SSID.ssid, len);
Jeff Johnson295189b2012-06-20 16:38:30 -07005519 }
5520 csrLLInsertTail( &pMac->scan.tempScanResults, &pCsrBssDescription->Link, LL_ACCESS_LOCK );
5521 }
5522
5523 return( pCsrBssDescription );
5524}
5525
5526
5527
5528
5529tANI_BOOLEAN csrIsDuplicateBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc1,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07005530 tSirBssDescription *pSirBssDesc2, tDot11fBeaconIEs *pIes2, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07005531{
5532 tANI_BOOLEAN fMatch = FALSE;
5533 tSirMacCapabilityInfo *pCap1, *pCap2;
5534 tDot11fBeaconIEs *pIes1 = NULL;
Jeff Johnsone7245742012-09-05 17:12:55 -07005535 tDot11fBeaconIEs *pIesTemp = pIes2;
Jeff Johnson295189b2012-06-20 16:38:30 -07005536
5537 pCap1 = (tSirMacCapabilityInfo *)&pSirBssDesc1->capabilityInfo;
5538 pCap2 = (tSirMacCapabilityInfo *)&pSirBssDesc2->capabilityInfo;
5539 if(pCap1->ess == pCap2->ess)
5540 {
5541 if (pCap1->ess &&
Jeff Johnsone7245742012-09-05 17:12:55 -07005542 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId)&&
Abhishek Singhe3fa11f2014-05-13 11:11:10 +05305543 (fForced || (vos_chan_to_band(pSirBssDesc1->channelId) == vos_chan_to_band((pSirBssDesc2->channelId)))))
Jeff Johnson295189b2012-06-20 16:38:30 -07005544 {
5545 fMatch = TRUE;
Jeff Johnsone7245742012-09-05 17:12:55 -07005546 // Check for SSID match, if exists
5547 do
5548 {
5549 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
5550 {
5551 break;
5552 }
5553 if( NULL == pIesTemp )
5554 {
5555 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
5556 {
5557 break;
5558 }
5559 }
5560 if(pIes1->SSID.present && pIesTemp->SSID.present)
5561 {
5562 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
5563 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
5564 }
5565 }while(0);
5566
Jeff Johnson295189b2012-06-20 16:38:30 -07005567 }
5568 else if (pCap1->ibss && (pSirBssDesc1->channelId == pSirBssDesc2->channelId))
5569 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005570
5571 do
5572 {
5573 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
5574 {
5575 break;
5576 }
5577 if( NULL == pIesTemp )
5578 {
5579 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
5580 {
5581 break;
5582 }
5583 }
5584 //Same channel cannot have same SSID for different IBSS
5585 if(pIes1->SSID.present && pIesTemp->SSID.present)
5586 {
5587 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
5588 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
5589 }
5590 }while(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005591 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005592 /* In case of P2P devices, ess and ibss will be set to zero */
5593 else if (!pCap1->ess &&
5594 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId))
5595 {
5596 fMatch = TRUE;
5597 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005598 }
5599
5600 if(pIes1)
5601 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305602 vos_mem_free(pIes1);
Jeff Johnson295189b2012-06-20 16:38:30 -07005603 }
Jeff Johnsone7245742012-09-05 17:12:55 -07005604
5605 if( (NULL == pIes2) && pIesTemp )
5606 {
5607 //locally allocated
Kiet Lam64c1b492013-07-12 13:56:44 +05305608 vos_mem_free(pIesTemp);
Jeff Johnsone7245742012-09-05 17:12:55 -07005609 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005610
5611 return( fMatch );
5612}
5613
5614
5615tANI_BOOLEAN csrIsNetworkTypeEqual( tSirBssDescription *pSirBssDesc1, tSirBssDescription *pSirBssDesc2 )
5616{
5617 return( pSirBssDesc1->nwType == pSirBssDesc2->nwType );
5618}
5619
5620
5621//to check whether the BSS matches the dot11Mode
5622static tANI_BOOLEAN csrScanIsBssAllowed(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
5623 tDot11fBeaconIEs *pIes)
5624{
5625 tANI_BOOLEAN fAllowed = eANI_BOOLEAN_FALSE;
5626 eCsrPhyMode phyMode;
5627
5628 if(HAL_STATUS_SUCCESS(csrGetPhyModeFromBss(pMac, pBssDesc, &phyMode, pIes)))
5629 {
5630 switch(pMac->roam.configParam.phyMode)
5631 {
5632 case eCSR_DOT11_MODE_11b:
5633 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
5634 break;
5635 case eCSR_DOT11_MODE_11g:
5636 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
5637 break;
5638 case eCSR_DOT11_MODE_11g_ONLY:
5639 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11g == phyMode);
5640 break;
5641 case eCSR_DOT11_MODE_11a:
5642 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11b != phyMode) && (eCSR_DOT11_MODE_11g != phyMode));
5643 break;
5644 case eCSR_DOT11_MODE_11n_ONLY:
5645 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11n == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
5646 break;
Jeff Johnsone7245742012-09-05 17:12:55 -07005647
5648#ifdef WLAN_FEATURE_11AC
5649 case eCSR_DOT11_MODE_11ac_ONLY:
5650 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11ac == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
5651 break;
5652#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005653 case eCSR_DOT11_MODE_11b_ONLY:
5654 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11b == phyMode);
5655 break;
5656 case eCSR_DOT11_MODE_11a_ONLY:
5657 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a == phyMode);
5658 break;
5659 case eCSR_DOT11_MODE_11n:
Jeff Johnsone7245742012-09-05 17:12:55 -07005660#ifdef WLAN_FEATURE_11AC
5661 case eCSR_DOT11_MODE_11ac:
5662#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005663 case eCSR_DOT11_MODE_TAURUS:
5664 default:
5665 fAllowed = eANI_BOOLEAN_TRUE;
5666 break;
5667 }
5668 }
5669
5670 return (fAllowed);
5671}
5672
5673
5674
5675//Return pIes to caller for future use when returning TRUE.
5676static tANI_BOOLEAN csrScanValidateScanResult( tpAniSirGlobal pMac, tANI_U8 *pChannels,
5677 tANI_U8 numChn, tSirBssDescription *pBssDesc,
5678 tDot11fBeaconIEs **ppIes )
5679{
5680 tANI_BOOLEAN fValidChannel = FALSE;
5681 tDot11fBeaconIEs *pIes = NULL;
5682 tANI_U8 index;
5683
5684 for( index = 0; index < numChn; index++ )
5685 {
5686 // This check relies on the fact that a single BSS description is returned in each
5687 // ScanRsp call, which is the way LIM implemented the scan req/rsp funtions. We changed
5688 // to this model when we ran with a large number of APs. If this were to change, then
5689 // this check would have to mess with removing the bssDescription from somewhere in an
5690 // arbitrary index in the bssDescription array.
5691 if ( pChannels[ index ] == pBssDesc->channelId )
5692 {
5693 fValidChannel = TRUE;
5694 break;
5695 }
5696 }
5697 *ppIes = NULL;
5698 if(fValidChannel)
5699 {
5700 if( HAL_STATUS_SUCCESS( csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIes) ) )
5701 {
5702 fValidChannel = csrScanIsBssAllowed(pMac, pBssDesc, pIes);
5703 if( fValidChannel )
5704 {
5705 *ppIes = pIes;
5706 }
5707 else
5708 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305709 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07005710 }
5711 }
5712 else
5713 {
5714 fValidChannel = FALSE;
5715 }
5716 }
5717
5718 return( fValidChannel );
5719}
5720
5721
5722//Return whether last scan result is received
5723static tANI_BOOLEAN csrScanProcessScanResults( tpAniSirGlobal pMac, tSmeCmd *pCommand,
5724 tSirSmeScanRsp *pScanRsp, tANI_BOOLEAN *pfRemoveCommand )
5725{
5726 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE, fRemoveCommand = eANI_BOOLEAN_FALSE;
5727 tDot11fBeaconIEs *pIes = NULL;
5728 tANI_U32 cbParsed;
5729 tSirBssDescription *pSirBssDescription;
5730 tANI_U32 cbBssDesc;
Agrawal Ashish4cc15bb2016-02-04 17:56:16 +05305731 eHalStatus status;
Jeff Johnson295189b2012-06-20 16:38:30 -07005732 tANI_U32 cbScanResult = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription )
5733 + sizeof(tSirBssDescription); //We need at least one CB
5734
5735 // don't consider the scan rsp to be valid if the status code is Scan Failure. Scan Failure
5736 // is returned when the scan could not find anything. so if we get scan failure return that
5737 // the scan response is invalid. Also check the lenght in the scan result for valid scan
5738 // BssDescriptions....
5739 do
5740 {
5741 if ( ( cbScanResult <= pScanRsp->length ) &&
5742 (( eSIR_SME_SUCCESS == pScanRsp->statusCode ) ||
5743 ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW == pScanRsp->statusCode ) ) )
5744 {
5745 tANI_U8 *pChannelList = NULL;
5746 tANI_U8 cChannels = 0;
5747
5748 //Different scan type can reach this point, we need to distinguish it
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005749#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5750 if( eCsrScanGetLfrResult == pCommand->u.scanCmd.reason )
5751 {
5752 pChannelList = NULL;
5753 cChannels = 0;
5754 }
5755 else
5756#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005757 if( eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason )
5758 {
5759 //eCsrScanSetBGScanParam uses different structure
5760 tCsrBGScanRequest *pBgScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
5761
5762 cChannels = pBgScanReq->ChannelInfo.numOfChannels;
5763 pChannelList = pBgScanReq->ChannelInfo.ChannelList;
5764 }
5765 else
5766 {
5767 //the rest use generic scan request
5768 cChannels = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
5769 pChannelList = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
5770 }
5771
5772 // if the scan result is not on one of the channels in the Valid channel list, then it
5773 // must have come from an AP on an overlapping channel (in the 2.4GHz band). In this case,
5774 // let's drop the scan result.
5775 //
5776 // The other situation is where the scan request is for a scan on a particular channel set
5777 // and the scan result is from a
5778
5779 // if the NumChannels is 0, then we are supposed to be scanning all channels. Use the full channel
5780 // list as the 'valid' channel list. Otherwise, use the specific channel list in the scan parms
5781 // as the valid channels.
5782 if ( 0 == cChannels )
5783 {
5784 tANI_U32 len = sizeof(pMac->roam.validChannelList);
5785
5786 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
5787 {
5788 pChannelList = pMac->roam.validChannelList;
5789 cChannels = (tANI_U8)len;
5790 }
5791 else
5792 {
5793 //Cannot continue
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005794 smsLog( pMac, LOGE, "CSR: Processing internal SCAN results...csrGetCfgValidChannels failed" );
Jeff Johnson295189b2012-06-20 16:38:30 -07005795 break;
5796 }
5797 }
5798
5799 smsLog( pMac, LOG2, "CSR: Processing internal SCAN results..." );
5800 cbParsed = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription );
5801 pSirBssDescription = pScanRsp->bssDescription;
5802 while( cbParsed < pScanRsp->length )
5803 {
5804 if ( csrScanValidateScanResult( pMac, pChannelList, cChannels, pSirBssDescription, &pIes ) )
5805 {
5806 csrScanRemoveDupBssDescriptionFromInterimList(pMac, pSirBssDescription, pIes);
5807 csrScanSaveBssDescriptionToInterimList( pMac, pSirBssDescription, pIes );
5808 if( eSIR_PASSIVE_SCAN == pMac->scan.curScanType )
5809 {
5810 if( csrIs11dSupported( pMac) )
5811 {
5812 //Check whether the BSS is acceptable base on 11d info and our configs.
5813 if( csrMatchCountryCode( pMac, NULL, pIes ) )
5814 {
5815 //Double check whether the channel is acceptable by us.
5816 if( csrIsSupportedChannel( pMac, pSirBssDescription->channelId ) )
5817 {
5818 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
5819 }
5820 }
5821 }
5822 else
5823 {
5824 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
5825 }
5826 }
5827 //Free the resource
Kiet Lam64c1b492013-07-12 13:56:44 +05305828 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07005829 }
5830 // skip over the BSS description to the next one...
5831 cbBssDesc = pSirBssDescription->length + sizeof( pSirBssDescription->length );
5832
5833 cbParsed += cbBssDesc;
5834 pSirBssDescription = (tSirBssDescription *)((tANI_U8 *)pSirBssDescription + cbBssDesc );
5835
5836 } //while
5837 }
5838 else
5839 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005840 smsLog( pMac, LOGW, " Scanrsp fail (0x%08X), length = %d (expected %d)",
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08005841 pScanRsp->statusCode, pScanRsp->length, cbScanResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07005842 //HO bg scan/probe failed no need to try autonomously
5843 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
5844 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005845#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5846 eCsrScanGetLfrResult == pCommand->u.scanCmd.reason ||
5847#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005848 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
5849 {
5850 fRemoveCommand = eANI_BOOLEAN_TRUE;
5851 }
5852 }
5853 }while(0);
5854 if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
5855 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005856 smsLog(pMac, LOG1, " Scan received %d unique BSS scan reason is %d", csrLLCount(&pMac->scan.tempScanResults), pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07005857 fRemoveCommand = csrScanComplete( pMac, pScanRsp );
5858 fRet = eANI_BOOLEAN_TRUE;
5859 }//if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
5860 if(pfRemoveCommand)
5861 {
5862 *pfRemoveCommand = fRemoveCommand;
5863 }
5864
Agrawal Ashish4cc15bb2016-02-04 17:56:16 +05305865 /*
5866 * Currently SET_FCC_CHANNEL issues updated channel list to fw.
5867 * At the time of driver load, if scan is issued followed with
5868 * SET_FCC_CHANNEL, driver will send update channel list to fw.
5869 * Fw will stop ongoing scan because of that GUI will have very less
5870 * scan list.
5871 * Update channel list should be sent to fw once scan is done
5872 */
5873 if (pMac->scan.defer_update_channel_list) {
5874 status = csrUpdateChannelList(pMac);
5875 if (eHAL_STATUS_SUCCESS != status)
5876 smsLog(pMac, LOGE,
5877 FL( "failed to update the supported channel list"));
5878 pMac->scan.defer_update_channel_list = false;
5879 }
5880
Jeff Johnson295189b2012-06-20 16:38:30 -07005881#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305882 if (pMac->fScanOffload)
5883 return fRet;
5884
Jeff Johnson295189b2012-06-20 16:38:30 -07005885 if (!csrLLIsListEmpty( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK ))
5886 {
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005887 /* Pending scan commands in the list because the previous scan command
5888 * was split into a scan command on one channel + a scan command for all
5889 * remaining channels.
5890 *
5891 * Start timer to trigger processing of the next scan command.
Srikant Kuppa866893f2012-12-27 17:28:14 -08005892 * NOTE for LFR:
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305893 * Do not split scans if no concurrent infra connections are
Srikant Kuppa866893f2012-12-27 17:28:14 -08005894 * active and if the scan is a BG scan triggered by LFR (OR)
5895 * any scan if LFR is in the middle of a BG scan. Splitting
5896 * the scan is delaying the time it takes for LFR to find
5897 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005898 */
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305899 if ( (csrIsStaSessionConnected(pMac) &&
Srikant Kuppa866893f2012-12-27 17:28:14 -08005900#ifdef FEATURE_WLAN_LFR
5901 (csrIsConcurrentInfraConnected(pMac) ||
5902 ((pCommand->u.scanCmd.reason != eCsrScanBgScan) &&
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305903 (pMac->roam.neighborRoamInfo.neighborRoamState !=
Srikant Kuppa866893f2012-12-27 17:28:14 -08005904 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
5905#endif
5906 (pCommand->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305907 (csrIsP2pSessionConnected(pMac)) )
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005908 {
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005909 /* if active connected sessions present then continue to split scan
5910 * with specified interval between consecutive scans */
5911 csrSetDefaultScanTiming(pMac, pCommand->u.scanCmd.u.scanRequest.scanType, &(pCommand->u.scanCmd.u.scanRequest));
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05305912 vos_timer_start(&pMac->scan.hTimerStaApConcTimer,
5913 pCommand->u.scanCmd.u.scanRequest.restTime);
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005914 } else {
5915 /* if no connected sessions present then initiate next scan command immediately */
5916 /* minimum timer granularity is 10ms */
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05305917 vos_timer_start(&pMac->scan.hTimerStaApConcTimer, 10);
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005918 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005919 }
5920#endif
5921 return (fRet);
5922}
5923
5924
5925tANI_BOOLEAN csrScanIsWildCardScan( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5926{
5927 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
Kiet Lam64c1b492013-07-12 13:56:44 +05305928 tANI_BOOLEAN f = vos_mem_compare(pCommand->u.scanCmd.u.scanRequest.bssid,
5929 bssid, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07005930
5931 //It is not a wild card scan if the bssid is not broadcast and the number of SSID is 1.
5932 return ((tANI_BOOLEAN)( (f || (0xff == pCommand->u.scanCmd.u.scanRequest.bssid[0])) &&
5933 (pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs != 1) ));
5934}
5935
5936
5937eHalStatus csrScanSmeScanResponse( tpAniSirGlobal pMac, void *pMsgBuf )
5938{
5939 eHalStatus status = eHAL_STATUS_SUCCESS;
5940 tListElem *pEntry;
5941 tSmeCmd *pCommand;
5942 eCsrScanStatus scanStatus;
Sunkad, Anand Ningappa3ec8bf72016-02-05 15:13:30 +05305943 tSirSmeScanRsp *pScanRsp;
Jeff Johnson295189b2012-06-20 16:38:30 -07005944 tSmeGetScanChnRsp *pScanChnInfo;
5945 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
5946 eCsrScanReason reason = eCsrScanOther;
5947
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305948 if (pMac->fScanOffload)
5949 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList,
5950 LL_ACCESS_LOCK);
5951 else
5952 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07005953
5954 if ( pEntry )
5955 {
5956 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
5957 if ( eSmeCommandScan == pCommand->command )
5958 {
Deepthi Gowrife5340b2016-04-11 12:15:46 +05305959 /* Purge the scan results based on Aging */
5960 if (pEntry && pMac->scan.scanResultCfgAgingTime)
5961 csrPurgeScanResultByAge(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07005962 reason = pCommand->u.scanCmd.reason;
5963 switch(pCommand->u.scanCmd.reason)
5964 {
5965 case eCsrScanAbortBgScan:
5966 case eCsrScanAbortNormalScan:
5967 case eCsrScanBGScanAbort:
5968 case eCsrScanBGScanEnable:
Sunkad, Anand Ningappa3ec8bf72016-02-05 15:13:30 +05305969 pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
5970 scanStatus = (eSIR_SME_SUCCESS == pScanRsp->statusCode) ?
5971 eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005972 break;
5973 case eCsrScanGetScanChnInfo:
Deepthi Gowrife5340b2016-04-11 12:15:46 +05305974 pScanChnInfo = (tSmeGetScanChnRsp *)pMsgBuf;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005975 /*
5976 * status code not available in tSmeGetScanChnRsp, so
5977 * by default considereing it to be success
5978 */
5979 scanStatus = eSIR_SME_SUCCESS;
Deepthi Gowrife5340b2016-04-11 12:15:46 +05305980 csrScanAgeResults(pMac, pScanChnInfo);
Jeff Johnson295189b2012-06-20 16:38:30 -07005981 break;
5982 case eCsrScanForCapsChange:
Sunkad, Anand Ningappa3ec8bf72016-02-05 15:13:30 +05305983 pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
5984 scanStatus = (eSIR_SME_SUCCESS == pScanRsp->statusCode) ?
5985 eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005986 csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand );
5987 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005988 case eCsrScanP2PFindPeer:
Sunkad, Anand Ningappa3ec8bf72016-02-05 15:13:30 +05305989 pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
5990 scanStatus = ((eSIR_SME_SUCCESS == pScanRsp->statusCode) &&
5991 (pScanRsp->length > 50)) ? eCSR_SCAN_FOUND_PEER : eCSR_SCAN_FAILURE;
5992 csrScanProcessScanResults( pMac, pCommand, pScanRsp, NULL );
5993 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005994 case eCsrScanSetBGScanParam:
5995 default:
Sunkad, Anand Ningappa3ec8bf72016-02-05 15:13:30 +05305996 pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
5997 scanStatus = (eSIR_SME_SUCCESS == pScanRsp->statusCode) ?
5998 eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005999 if(csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand ))
6000 {
6001 //Not to get channel info if the scan is not a wildcard scan because
6002 //it may cause scan results got aged out incorrectly.
Ratheesh S Pece1f832015-07-25 15:50:25 +05306003 if(csrScanIsWildCardScan( pMac, pCommand ) &&
6004 (!pCommand->u.scanCmd.u.scanRequest.p2pSearch)
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006005#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
6006 && (pCommand->u.scanCmd.reason != eCsrScanGetLfrResult)
6007#endif
6008 )
Jeff Johnson295189b2012-06-20 16:38:30 -07006009 {
Ratheesh S Pece1f832015-07-25 15:50:25 +05306010 csrScanGetScanChnInfo(pMac, pCommand);
Jeff Johnson295189b2012-06-20 16:38:30 -07006011 }
6012 }
6013 break;
6014 }//switch
6015 if(fRemoveCommand)
6016 {
6017
6018 csrReleaseScanCommand(pMac, pCommand, scanStatus);
6019
Sunkad, Anand Ningappa3ec8bf72016-02-05 15:13:30 +05306020 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006021 smeProcessPendingQueue( pMac );
6022 }
6023 else
6024 {
6025 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
6026 status = eHAL_STATUS_FAILURE;
6027 }
6028 }
6029 else
6030 {
6031 smsLog( pMac, LOGW, "CSR: Scan Completion called but NO commands are ACTIVE ..." );
6032 status = eHAL_STATUS_FAILURE;
6033 }
6034
6035 return (status);
6036}
6037
6038
6039
6040
6041tCsrScanResultInfo *csrScanResultGetFirst(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
6042{
6043 tListElem *pEntry;
6044 tCsrScanResult *pResult;
6045 tCsrScanResultInfo *pRet = NULL;
6046 tScanResultList *pResultList = (tScanResultList *)hScanResult;
6047
6048 if(pResultList)
6049 {
6050 csrLLLock(&pResultList->List);
6051 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
6052 if(pEntry)
6053 {
6054 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
6055 pRet = &pResult->Result;
6056 }
6057 pResultList->pCurEntry = pEntry;
6058 csrLLUnlock(&pResultList->List);
6059 }
6060
6061 return pRet;
6062}
6063
6064
6065tCsrScanResultInfo *csrScanResultGetNext(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
6066{
6067 tListElem *pEntry = NULL;
6068 tCsrScanResult *pResult = NULL;
6069 tCsrScanResultInfo *pRet = NULL;
6070 tScanResultList *pResultList = (tScanResultList *)hScanResult;
6071
6072 if(pResultList)
6073 {
6074 csrLLLock(&pResultList->List);
6075 if(NULL == pResultList->pCurEntry)
6076 {
6077 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
6078 }
6079 else
6080 {
6081 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
6082 }
6083 if(pEntry)
6084 {
6085 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
6086 pRet = &pResult->Result;
6087 }
6088 pResultList->pCurEntry = pEntry;
6089 csrLLUnlock(&pResultList->List);
6090 }
6091
6092 return pRet;
6093}
6094
6095
6096//This function moves the first BSS that matches the bssid to the head of the result
6097eHalStatus csrMoveBssToHeadFromBSSID(tpAniSirGlobal pMac, tCsrBssid *bssid, tScanResultHandle hScanResult)
6098{
6099 eHalStatus status = eHAL_STATUS_FAILURE;
6100 tScanResultList *pResultList = (tScanResultList *)hScanResult;
6101 tCsrScanResult *pResult = NULL;
6102 tListElem *pEntry = NULL;
6103
6104 if(pResultList && bssid)
6105 {
6106 csrLLLock(&pResultList->List);
6107 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
6108 while(pEntry)
6109 {
6110 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
Kiet Lam64c1b492013-07-12 13:56:44 +05306111 if (vos_mem_compare(bssid, pResult->Result.BssDescriptor.bssId, sizeof(tCsrBssid)))
Jeff Johnson295189b2012-06-20 16:38:30 -07006112 {
6113 status = eHAL_STATUS_SUCCESS;
6114 csrLLRemoveEntry(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
6115 csrLLInsertHead(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
6116 break;
6117 }
6118 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
6119 }
6120 csrLLUnlock(&pResultList->List);
6121 }
6122
6123 return (status);
6124}
6125
6126
6127//Remove the BSS if possible.
6128//Return -- TRUE == the BSS is remove. False == Fail to remove it
6129//This function is called when list lock is held. Be caution what functions it can call.
6130tANI_BOOLEAN csrScanAgeOutBss(tpAniSirGlobal pMac, tCsrScanResult *pResult)
6131{
6132 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
6133 tANI_U32 i;
6134 tCsrRoamSession *pSession;
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05306135 tANI_BOOLEAN isConnBssfound = eANI_BOOLEAN_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006136
6137 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
6138 {
6139 if( CSR_IS_SESSION_VALID( pMac, i ) )
6140 {
6141 pSession = CSR_GET_SESSION( pMac, i );
6142 //Not to remove the BSS we are connected to.
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05306143 if(csrIsConnStateConnectedInfra(pMac, i) && (NULL != pSession->pConnectBssDesc) &&
6144 (csrIsDuplicateBssDescription(pMac, &pResult->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07006145 pSession->pConnectBssDesc, NULL, FALSE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006146 )
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05306147 {
6148 isConnBssfound = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006149 break;
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05306150 }
6151 }
6152 }
6153
6154 if( isConnBssfound )
Jeff Johnson295189b2012-06-20 16:38:30 -07006155 {
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05306156 //Reset the counter so that aging out of connected BSS won't hapeen too soon
Jeff Johnson295189b2012-06-20 16:38:30 -07006157 pResult->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Deepthi Gowri4480a3f2016-05-18 19:30:17 +05306158 pResult->Result.BssDescriptor.nReceivedTime =
6159 vos_timer_get_system_time();
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05306160
6161 return (fRet);
6162 }
6163 else
6164 {
6165 smsLog(pMac, LOGW, "Aging out BSS "MAC_ADDRESS_STR" Channel %d",
6166 MAC_ADDR_ARRAY(pResult->Result.BssDescriptor.bssId),
6167 pResult->Result.BssDescriptor.channelId);
6168 //No need to hold the spin lock because caller should hold the lock for pMac->scan.scanResultList
6169 if( csrLLRemoveEntry(&pMac->scan.scanResultList, &pResult->Link, LL_ACCESS_NOLOCK) )
6170 {
6171 if (csrIsMacAddressEqual(pMac,
6172 (tCsrBssid *) pResult->Result.BssDescriptor.bssId,
6173 (tCsrBssid *) pMac->scan.currentCountryBssid))
6174 {
6175 smsLog(pMac, LOGW, "Aging out 11d BSS "MAC_ADDRESS_STR,
6176 MAC_ADDR_ARRAY(pResult->Result.BssDescriptor.bssId));
6177 pMac->scan.currentCountryRSSI = -128;
6178 }
6179 csrFreeScanResultEntry(pMac, pResult);
6180 fRet = eANI_BOOLEAN_TRUE;
6181 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006182 }
6183
6184 return (fRet);
6185}
6186
6187
6188eHalStatus csrScanAgeResults(tpAniSirGlobal pMac, tSmeGetScanChnRsp *pScanChnInfo)
6189{
6190 eHalStatus status = eHAL_STATUS_SUCCESS;
6191 tListElem *pEntry, *tmpEntry;
6192 tCsrScanResult *pResult;
6193 tLimScanChn *pChnInfo;
6194 tANI_U8 i;
6195
6196 csrLLLock(&pMac->scan.scanResultList);
6197 for(i = 0; i < pScanChnInfo->numChn; i++)
6198 {
6199 pChnInfo = &pScanChnInfo->scanChn[i];
6200 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
6201 while( pEntry )
6202 {
6203 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
6204 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
6205 if(pResult->Result.BssDescriptor.channelId == pChnInfo->channelId)
6206 {
Jeff Johnson295189b2012-06-20 16:38:30 -07006207 if(pResult->AgingCount <= 0)
6208 {
6209 smsLog(pMac, LOGW, " age out due to ref count");
6210 csrScanAgeOutBss(pMac, pResult);
6211 }
Madan Mohan Koyyalamudib9d3dcc2012-09-28 16:47:50 -07006212 else
6213 {
6214 pResult->AgingCount--;
6215 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006216 }
6217 pEntry = tmpEntry;
6218 }
6219 }
6220 csrLLUnlock(&pMac->scan.scanResultList);
6221
6222 return (status);
6223}
6224
Abhishek Singhc640dbb2015-06-08 10:54:17 +05306225eHalStatus csrIbssAgeBss(tpAniSirGlobal pMac)
6226{
6227 eHalStatus status = eHAL_STATUS_SUCCESS;
6228 tListElem *pEntry, *tmpEntry;
6229 tCsrScanResult *pResult;
6230
6231 csrLLLock(&pMac->scan.scanResultList);
6232 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
6233 while( pEntry )
6234 {
6235 tmpEntry = csrLLNext(&pMac->scan.scanResultList,
6236 pEntry, LL_ACCESS_NOLOCK);
6237 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
6238
6239 smsLog(pMac, LOGW, FL(" age out due Forced IBSS leave"));
6240 csrScanAgeOutBss(pMac, pResult);
6241 pEntry = tmpEntry;
6242 }
6243 csrLLUnlock(&pMac->scan.scanResultList);
6244
6245 return (status);
6246}
Jeff Johnson295189b2012-06-20 16:38:30 -07006247
Abhishek Singh72c2f4e2016-07-22 11:25:43 +05306248/**
6249 * csr_remove_bssid_from_scan_list() - remove the bssid from
6250 * scan list
6251 * @pMac: mac context.
6252 * @bssid: bssid to be removed
6253 *
6254 * This function remove the given bssid from scan list.
6255 *
6256 * Return: void.
6257 */
6258void csr_remove_bssid_from_scan_list(tpAniSirGlobal pMac,
6259 tSirMacAddr bssid)
6260{
6261 tListElem *entry,*free_elem;
6262 tCsrScanResult *bss_desc;
6263 tDblLinkList *list = &pMac->scan.scanResultList;
6264
6265 csrLLLock(list);
6266 entry = csrLLPeekHead(list, LL_ACCESS_NOLOCK);
6267 while (entry != NULL) {
6268 bss_desc = GET_BASE_ADDR( entry, tCsrScanResult, Link);
6269 if (vos_mem_compare(bss_desc->Result.BssDescriptor.bssId,
6270 bssid, sizeof(tSirMacAddr))) {
6271 free_elem = entry;
6272 entry = csrLLNext(list, entry, LL_ACCESS_NOLOCK);
6273 csrLLRemoveEntry(list, free_elem, LL_ACCESS_NOLOCK);
6274 csrFreeScanResultEntry(pMac, bss_desc);
6275 smsLog(pMac, LOGW, FL("Removed BSS entry:%pM"),
6276 bssid);
6277 continue;
6278 }
6279 entry = csrLLNext(list, entry, LL_ACCESS_NOLOCK);
6280 }
6281 csrLLUnlock(list);
6282}
6283
Jeff Johnson295189b2012-06-20 16:38:30 -07006284eHalStatus csrSendMBScanReq( tpAniSirGlobal pMac, tANI_U16 sessionId,
6285 tCsrScanRequest *pScanReq, tScanReqParam *pScanReqParam )
6286{
6287 eHalStatus status = eHAL_STATUS_SUCCESS;
6288 tSirSmeScanReq *pMsg;
6289 tANI_U16 msgLen;
6290 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
6291 tSirScanType scanType = pScanReq->scanType;
6292 tANI_U32 minChnTime; //in units of milliseconds
6293 tANI_U32 maxChnTime; //in units of milliseconds
6294 tANI_U32 i;
6295 tANI_U8 selfMacAddr[WNI_CFG_BSSID_LEN];
6296 tANI_U8 *pSelfMac = NULL;
6297
6298 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
6299 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) +
6300 ( pScanReq->uIEFieldLen ) ;
6301
Kiet Lam64c1b492013-07-12 13:56:44 +05306302 pMsg = vos_mem_malloc(msgLen);
6303 if ( NULL == pMsg )
6304 status = eHAL_STATUS_FAILURE;
6305 else
6306 status = eHAL_STATUS_SUCCESS;
6307 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07006308 {
6309 do
6310 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306311 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006312 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
6313 pMsg->length = pal_cpu_to_be16(msgLen);
6314 //ToDO: Fill in session info when we need to do scan base on session.
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05306315 if ((pMac->fScanOffload) && (sessionId != CSR_SESSION_ID_INVALID))
6316 {
6317 pMsg->sessionId = sessionId;
6318 }
6319 else
6320 {
6321 /* if sessionId == CSR_SESSION_ID_INVALID, then send the scan
6322 request on first available session */
6323 pMsg->sessionId = 0;
6324 }
6325
Jeff Johnson295189b2012-06-20 16:38:30 -07006326 pMsg->transactionId = 0;
6327 pMsg->dot11mode = (tANI_U8) csrTranslateToWNICfgDot11Mode(pMac, csrFindBestPhyMode( pMac, pMac->roam.configParam.phyMode ));
6328 pMsg->bssType = pal_cpu_to_be32(csrTranslateBsstypeToMacType(pScanReq->BSSType));
6329
6330 if ( CSR_IS_SESSION_VALID( pMac, sessionId ) )
6331 {
6332 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[sessionId].selfMacAddr;
6333 }
6334 else
6335 {
6336 // Since we don't have session for the scanning, we find a valid session. In case we fail to
6337 // do so, get the WNI_CFG_STA_ID
6338 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
6339 {
6340 if( CSR_IS_SESSION_VALID( pMac, i ) )
6341 {
6342 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[i].selfMacAddr;
6343 break;
6344 }
6345 }
6346 if( CSR_ROAM_SESSION_MAX == i )
6347 {
6348 tANI_U32 len = WNI_CFG_BSSID_LEN;
6349 pSelfMac = selfMacAddr;
6350 status = ccmCfgGetStr( pMac, WNI_CFG_STA_ID, pSelfMac, &len );
6351 if( !HAL_STATUS_SUCCESS( status ) ||
6352 ( len < WNI_CFG_BSSID_LEN ) )
6353 {
6354 smsLog( pMac, LOGE, FL(" Can not get self MAC address from CFG status = %d"), status );
6355 //Force failed status
6356 status = eHAL_STATUS_FAILURE;
6357 break;
6358 }
6359 }
6360 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306361 vos_mem_copy((tANI_U8 *)pMsg->selfMacAddr, pSelfMac, sizeof(tSirMacAddr));
Jeff Johnson295189b2012-06-20 16:38:30 -07006362
6363 //sirCopyMacAddr
Kiet Lam64c1b492013-07-12 13:56:44 +05306364 vos_mem_copy((tANI_U8 *)pMsg->bssId, (tANI_U8 *)&pScanReq->bssid, sizeof(tSirMacAddr));
6365 if ( vos_mem_compare(pScanReq->bssid, bssid, sizeof(tCsrBssid)))
Jeff Johnson295189b2012-06-20 16:38:30 -07006366 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306367 vos_mem_set(pMsg->bssId, sizeof(tSirMacAddr), 0xff);
Jeff Johnson295189b2012-06-20 16:38:30 -07006368 }
6369 else
6370 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306371 vos_mem_copy(pMsg->bssId, pScanReq->bssid, WNI_CFG_BSSID_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07006372 }
6373 minChnTime = pScanReq->minChnTime;
6374 maxChnTime = pScanReq->maxChnTime;
6375
6376 //Verify the scan type first, if the scan is active scan, we need to make sure we
6377 //are allowed to do so.
6378 /* if 11d is enabled & we don't see any beacon around, scan type falls
6379 back to passive. But in BT AMP STA mode we need to send out a
6380 directed probe*/
6381 if( (eSIR_PASSIVE_SCAN != scanType) && (eCSR_SCAN_P2P_DISCOVERY != pScanReq->requestType)
6382 && (eCSR_BSS_TYPE_WDS_STA != pScanReq->BSSType)
6383 && (eANI_BOOLEAN_FALSE == pMac->scan.fEnableBypass11d))
6384 {
6385 scanType = pMac->scan.curScanType;
6386 if(eSIR_PASSIVE_SCAN == pMac->scan.curScanType)
6387 {
6388 if(minChnTime < pMac->roam.configParam.nPassiveMinChnTime)
6389 {
6390 minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
6391 }
6392 if(maxChnTime < pMac->roam.configParam.nPassiveMaxChnTime)
6393 {
6394 maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
6395 }
6396 }
6397 }
6398 pMsg->scanType = pal_cpu_to_be32(scanType);
6399
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306400 pMsg->numSsid =
6401 (pScanReq->SSIDs.numOfSSIDs < SIR_SCAN_MAX_NUM_SSID) ?
6402 pScanReq->SSIDs.numOfSSIDs : SIR_SCAN_MAX_NUM_SSID;
Jeff Johnson295189b2012-06-20 16:38:30 -07006403 if((pScanReq->SSIDs.numOfSSIDs != 0) && ( eSIR_PASSIVE_SCAN != scanType ))
6404 {
Jeff Johnson40b59aa2013-03-19 14:43:18 -07006405 for (i = 0; i < pMsg->numSsid; i++)
6406 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306407 vos_mem_copy(&pMsg->ssId[i],
6408 &pScanReq->SSIDs.SSIDList[i].SSID, sizeof(tSirMacSSid));
Jeff Johnson40b59aa2013-03-19 14:43:18 -07006409 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006410 }
6411 else
6412 {
6413 //Otherwise we scan all SSID and let the result filter later
Jeff Johnson40b59aa2013-03-19 14:43:18 -07006414 for (i = 0; i < SIR_SCAN_MAX_NUM_SSID; i++)
6415 {
6416 pMsg->ssId[i].length = 0;
6417 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006418 }
6419
Jeff Johnson295189b2012-06-20 16:38:30 -07006420 pMsg->minChannelTime = pal_cpu_to_be32(minChnTime);
6421 pMsg->maxChannelTime = pal_cpu_to_be32(maxChnTime);
Abhishek Singhadd13582016-09-29 17:00:03 +05306422 pMsg->min_chntime_btc_esco =
6423 pMac->roam.configParam.min_chntime_btc_esco;
6424 pMsg->max_chntime_btc_esco =
6425 pMac->roam.configParam.max_chntime_btc_esco;
Jeff Johnson295189b2012-06-20 16:38:30 -07006426 //hidden SSID option
6427 pMsg->hiddenSsid = pScanReqParam->hiddenSsid;
6428 //rest time
6429 //pMsg->restTime = pScanReq->restTime;
6430 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
6431 // All the scan results caching will be done by Roaming
6432 // We do not want LIM to do any caching of scan results,
6433 // so delete the LIM cache on all scan requests
6434 pMsg->returnFreshResults = pScanReqParam->freshScan;
6435 //Always ask for unique result
6436 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
6437 pMsg->channelList.numChannels = (tANI_U8)pScanReq->ChannelInfo.numOfChannels;
6438 if(pScanReq->ChannelInfo.numOfChannels)
6439 {
6440 //Assuming the channelNumber is tANI_U8 (1 byte)
Kiet Lam64c1b492013-07-12 13:56:44 +05306441 vos_mem_copy(pMsg->channelList.channelNumber,
6442 pScanReq->ChannelInfo.ChannelList,
6443 pScanReq->ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07006444 }
6445
6446 pMsg->uIEFieldLen = (tANI_U16) pScanReq->uIEFieldLen;
6447 pMsg->uIEFieldOffset = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
6448 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) ;
6449 if(pScanReq->uIEFieldLen != 0)
6450 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306451 vos_mem_copy((tANI_U8 *)pMsg+pMsg->uIEFieldOffset, pScanReq->pIEField,
6452 pScanReq->uIEFieldLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07006453 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006454 pMsg->p2pSearch = pScanReq->p2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07006455
Madan Mohan Koyyalamudi9b876782012-10-11 16:22:51 -07006456 if (pScanReq->requestType == eCSR_SCAN_HO_BG_SCAN)
6457 {
6458 pMsg->backgroundScanMode = eSIR_ROAMING_SCAN;
6459 }
6460
Jeff Johnson295189b2012-06-20 16:38:30 -07006461 }while(0);
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05306462 smsLog(pMac, LOG1, FL("domainIdCurrent %s (%d) scanType %s (%d)"
6463 "bssType %s (%d), requestType %s(%d)"
6464 "numChannels %d"),
6465 voss_DomainIdtoString(pMac->scan.domainIdCurrent),
6466 pMac->scan.domainIdCurrent,
6467 lim_ScanTypetoString(pMsg->scanType), pMsg->scanType,
6468 lim_BssTypetoString(pMsg->bssType), pMsg->bssType,
6469 sme_requestTypetoString(pScanReq->requestType),
6470 pScanReq->requestType,
6471 pMsg->channelList.numChannels);
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08006472
6473 for(i = 0; i < pMsg->channelList.numChannels; i++)
6474 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006475 smsLog(pMac, LOG3, FL("channelNumber[%d]= %d"), i, pMsg->channelList.channelNumber[i]);
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08006476 }
6477
Jeff Johnson295189b2012-06-20 16:38:30 -07006478 if(HAL_STATUS_SUCCESS(status))
6479 {
6480 status = palSendMBMessage(pMac->hHdd, pMsg);
6481 }
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08006482 else
6483 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006484 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d"), status );
Kiet Lam64c1b492013-07-12 13:56:44 +05306485 vos_mem_free(pMsg);
Jeff Johnson295189b2012-06-20 16:38:30 -07006486 }
6487 }//Success allocated memory
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08006488 else
6489 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006490 smsLog( pMac, LOGE, FL(" memory allocation failure"));
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08006491 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006492
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306493 if(!HAL_STATUS_SUCCESS(status))
6494 {
6495 smsLog( pMac, LOG1, FL("Failed: SId: %d FirstMatch = %d"
6496 " UniqueResult = %d freshScan = %d hiddenSsid = %d"),
6497 sessionId, pScanReqParam->bReturnAfter1stMatch,
6498 pScanReqParam->fUniqueResult, pScanReqParam->freshScan,
6499 pScanReqParam->hiddenSsid );
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05306500 smsLog( pMac, LOG1, FL("scanType = %s (%d) BSSType = %s (%d) "
6501 "numOfSSIDs = %d numOfChannels = %d requestType = %s (%d)"
6502 " p2pSearch = %d\n"),
6503 lim_ScanTypetoString(pScanReq->scanType),
6504 pScanReq->scanType,
6505 lim_BssTypetoString(pScanReq->BSSType),
6506 pScanReq->BSSType,
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306507 pScanReq->SSIDs.numOfSSIDs,
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05306508 pScanReq->ChannelInfo.numOfChannels,
6509 sme_requestTypetoString(pScanReq->requestType),
6510 pScanReq->requestType,
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306511 pScanReq->p2pSearch );
6512
6513 }
6514
Jeff Johnson295189b2012-06-20 16:38:30 -07006515 return( status );
6516}
6517
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006518eHalStatus csrSendMBScanResultReq( tpAniSirGlobal pMac, tANI_U32 sessionId, tScanReqParam *pScanReqParam )
Jeff Johnson295189b2012-06-20 16:38:30 -07006519{
6520 eHalStatus status = eHAL_STATUS_SUCCESS;
6521 tSirSmeScanReq *pMsg;
6522 tANI_U16 msgLen;
6523
6524 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ));
Kiet Lam64c1b492013-07-12 13:56:44 +05306525 pMsg = vos_mem_malloc(msgLen);
6526 if ( NULL == pMsg )
6527 status = eHAL_STATUS_FAILURE;
6528 else
Jeff Johnson295189b2012-06-20 16:38:30 -07006529 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306530 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006531 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
6532 pMsg->length = pal_cpu_to_be16(msgLen);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006533 pMsg->sessionId = sessionId;
6534 pMsg->transactionId = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07006535 pMsg->returnFreshResults = pScanReqParam->freshScan;
6536 //Always ask for unique result
6537 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
6538 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
6539 status = palSendMBMessage(pMac->hHdd, pMsg);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006540 if (!HAL_STATUS_SUCCESS(status))
6541 {
6542 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d\n"), status );
6543 }
6544
Jeff Johnson295189b2012-06-20 16:38:30 -07006545 }
6546
6547 return( status );
6548}
6549
6550
6551
6552eHalStatus csrScanChannels( tpAniSirGlobal pMac, tSmeCmd *pCommand )
6553{
6554 eHalStatus status = eHAL_STATUS_FAILURE;
6555 tScanReqParam scanReq;
6556
6557 do
6558 {
6559 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE | TRUE;
6560 scanReq.fUniqueResult = TRUE;
6561 scanReq.hiddenSsid = SIR_SCAN_NO_HIDDEN_SSID;
6562 if(eCsrScanForSsid == pCommand->u.scanCmd.reason)
6563 {
6564 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_FIRST_MATCH;
6565 }
6566 else
6567 {
6568 // Basically do scan on all channels even for 11D 1st scan case.
6569 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
6570 }
6571 if((eCsrScanBgScan == pCommand->u.scanCmd.reason)||
6572 (eCsrScanProbeBss == pCommand->u.scanCmd.reason))
6573 {
6574 scanReq.hiddenSsid = SIR_SCAN_HIDDEN_SSID_PE_DECISION;
6575 }
6576
6577#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
6578 {
6579 vos_log_scan_pkt_type *pScanLog = NULL;
6580
6581 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
6582 if(pScanLog)
6583 {
6584 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
6585 eCsrScanProbeBss == pCommand->u.scanCmd.reason)
6586 {
6587 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
6588 }
6589 else
6590 {
6591 if( (eSIR_PASSIVE_SCAN != pCommand->u.scanCmd.u.scanRequest.scanType) &&
6592 (eSIR_PASSIVE_SCAN != pMac->scan.curScanType) )
6593 {
6594 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_REQ;
6595 }
6596 else
6597 {
6598 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_REQ;
6599 }
6600 }
6601 pScanLog->minChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.minChnTime;
6602 pScanLog->maxChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.maxChnTime;
6603 pScanLog->numChannel = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
6604 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
6605 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306606 vos_mem_copy(pScanLog->channels,
6607 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
6608 pScanLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07006609 }
6610 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
6611 }
6612 }
6613#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
6614
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05306615 csrClearVotesForCountryInfo(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07006616 status = csrSendMBScanReq(pMac, pCommand->sessionId,
6617 &pCommand->u.scanCmd.u.scanRequest, &scanReq);
6618 }while(0);
6619
6620 return( status );
6621}
6622
6623
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006624eHalStatus csrScanRetrieveResult(tpAniSirGlobal pMac, tSmeCmd *pCommand)
Jeff Johnson295189b2012-06-20 16:38:30 -07006625{
6626 eHalStatus status = eHAL_STATUS_FAILURE;
6627 tScanReqParam scanReq;
6628
6629 do
6630 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006631#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
6632 if (eCsrScanGetLfrResult == pCommand->u.scanCmd.reason)
6633 {
6634 //to get the LFR candidates from PE cache
6635 scanReq.freshScan = SIR_BG_SCAN_RETURN_LFR_CACHED_RESULTS|SIR_BG_SCAN_PURGE_LFR_RESULTS;
6636 scanReq.fUniqueResult = TRUE;
6637 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
6638 }
6639 else
6640#endif
6641 {
6642 //not a fresh scan
6643 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE;
6644 scanReq.fUniqueResult = TRUE;
6645 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
6646 }
6647 status = csrSendMBScanResultReq(pMac, pCommand->sessionId, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07006648 }while(0);
6649
6650 return (status);
6651}
6652
Siddharth Bhald8a95e82015-02-12 20:14:52 +05306653eHalStatus csrProcessMacAddrSpoofCommand( tpAniSirGlobal pMac, tSmeCmd *pCommand )
6654{
6655 tSirSpoofMacAddrReq *pMsg;
6656 tANI_U16 msgLen;
6657 eHalStatus status = eHAL_STATUS_FAILURE;
6658 do {
6659 msgLen = sizeof(tSirSpoofMacAddrReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07006660
Siddharth Bhald8a95e82015-02-12 20:14:52 +05306661 pMsg = vos_mem_malloc(msgLen);
6662 if ( NULL == pMsg )
6663 return eHAL_STATUS_FAILURE;
6664 pMsg->messageType= pal_cpu_to_be16((tANI_U16)eWNI_SME_MAC_SPOOF_ADDR_IND);
6665 pMsg->length= pal_cpu_to_be16(msgLen);
6666 // spoof mac address
6667 vos_mem_copy((tANI_U8 *)pMsg->macAddr,
6668 (tANI_U8 *)pCommand->u.macAddrSpoofCmd.macAddr, sizeof(tSirMacAddr));
6669 status = palSendMBMessage(pMac->hHdd, pMsg);
6670 } while( 0 );
6671 return( status );
6672}
Jeff Johnson295189b2012-06-20 16:38:30 -07006673
6674eHalStatus csrProcessScanCommand( tpAniSirGlobal pMac, tSmeCmd *pCommand )
6675{
6676 eHalStatus status = eHAL_STATUS_SUCCESS;
6677 tCsrChannelInfo newChannelInfo = {0, NULL};
6678 int i, j;
6679 tANI_U8 *pChannel = NULL;
6680 tANI_U32 len = 0;
6681
6682 // Transition to Scanning state...
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306683 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07006684 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306685 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
6686 {
Abhishek Singhf52182c2016-08-24 11:15:23 +05306687 pMac->roam.prev_state[i]=
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306688 csrRoamStateChange( pMac, eCSR_ROAMING_STATE_SCANNING, i);
6689 smsLog( pMac, LOG3, "starting SCAN command from %d state...."
Abhishek Singhf52182c2016-08-24 11:15:23 +05306690 " reason is %d", pMac->roam.prev_state[i],
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306691 pCommand->u.scanCmd.reason );
6692 }
6693 }
6694 else
6695 {
Abhishek Singhf52182c2016-08-24 11:15:23 +05306696 pMac->roam.prev_state[pCommand->sessionId] =
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306697 csrRoamStateChange(pMac, eCSR_ROAMING_STATE_SCANNING,
6698 pCommand->sessionId);
6699 smsLog( pMac, LOG3,
6700 "starting SCAN command from %d state.... reason is %d",
Abhishek Singhf52182c2016-08-24 11:15:23 +05306701 pMac->roam.prev_state[pCommand->sessionId],
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306702 pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07006703 }
6704
6705 switch(pCommand->u.scanCmd.reason)
6706 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006707#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
6708 case eCsrScanGetLfrResult:
6709#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006710 case eCsrScanGetResult:
6711 case eCsrScanForCapsChange: //For cap change, LIM already save BSS description
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006712 status = csrScanRetrieveResult(pMac, pCommand);
Jeff Johnson295189b2012-06-20 16:38:30 -07006713 break;
6714 case eCsrScanSetBGScanParam:
6715 status = csrProcessSetBGScanParam(pMac, pCommand);
6716 break;
6717 case eCsrScanBGScanAbort:
6718 status = csrSetCfgBackgroundScanPeriod(pMac, 0);
6719 break;
6720 case eCsrScanBGScanEnable:
6721 status = csrSetCfgBackgroundScanPeriod(pMac, pMac->roam.configParam.bgScanInterval);
6722 break;
6723 case eCsrScanGetScanChnInfo:
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05306724 status = csrScanGetScanChannelInfo(pMac, pCommand->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07006725 break;
6726 case eCsrScanUserRequest:
6727 if(pMac->roam.configParam.fScanTwice)
6728 {
6729 //We scan 2.4 channel twice
6730 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels &&
6731 (NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList))
6732 {
6733 len = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
6734 //allocate twice the channel
Mukul Sharmaa631e892014-08-28 15:38:51 +05306735 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(len * 2);
Jeff Johnson295189b2012-06-20 16:38:30 -07006736 pChannel = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
6737 }
6738 else
6739 {
6740 //get the valid channel list to scan all.
6741 len = sizeof(pMac->roam.validChannelList);
6742
6743 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
6744 {
6745 //allocate twice the channel
6746 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(len * 2);
6747 pChannel = pMac->roam.validChannelList;
6748 }
6749 }
6750 if(NULL == newChannelInfo.ChannelList)
6751 {
6752 newChannelInfo.numOfChannels = 0;
6753 }
6754 else
6755 {
6756 j = 0;
6757 for(i = 0; i < len; i++)
6758 {
6759 newChannelInfo.ChannelList[j++] = pChannel[i];
6760 if(CSR_MAX_24GHz_CHANNEL_NUMBER >= pChannel[i])
6761 {
6762 newChannelInfo.ChannelList[j++] = pChannel[i];
6763 }
6764 }
6765 if(NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
6766 {
6767 //pChannel points to the channellist from the command, free it.
6768 vos_mem_free(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -07006769 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07006770 }
6771 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = j;
6772 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = newChannelInfo.ChannelList;
6773 }
6774 } //if(pMac->roam.configParam.fScanTwice)
6775
6776 status = csrScanChannels(pMac, pCommand);
6777
6778 break;
6779 default:
6780 status = csrScanChannels(pMac, pCommand);
6781 break;
6782 }
6783
6784 if(!HAL_STATUS_SUCCESS(status))
6785 {
6786 csrReleaseScanCommand(pMac, pCommand, eCSR_SCAN_FAILURE);
6787 }
6788
6789 return (status);
6790}
6791
6792
6793eHalStatus csrScanSetBGScanparams(tpAniSirGlobal pMac, tCsrBGScanRequest *pScanReq)
6794{
6795 eHalStatus status = eHAL_STATUS_SUCCESS;
6796 tSmeCmd *pCommand = NULL;
6797
6798 if(pScanReq)
6799 {
6800 do
6801 {
6802 pCommand = csrGetCommandBuffer(pMac);
6803 if(!pCommand)
6804 {
6805 status = eHAL_STATUS_RESOURCES;
6806 break;
6807 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306808 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006809 pCommand->command = eSmeCommandScan;
6810 pCommand->u.scanCmd.reason = eCsrScanSetBGScanParam;
6811 pCommand->u.scanCmd.callback = NULL;
6812 pCommand->u.scanCmd.pContext = NULL;
Kiet Lam64c1b492013-07-12 13:56:44 +05306813 vos_mem_copy(&pCommand->u.scanCmd.u.bgScanRequest, pScanReq, sizeof(tCsrBGScanRequest));
Jeff Johnson295189b2012-06-20 16:38:30 -07006814 //we have to do the follow
6815 if(pScanReq->ChannelInfo.numOfChannels == 0)
6816 {
6817 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
6818 }
6819 else
6820 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306821 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList
6822 = vos_mem_malloc(pScanReq->ChannelInfo.numOfChannels);
6823 if ( NULL != pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07006824 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306825 vos_mem_copy(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList,
6826 pScanReq->ChannelInfo.ChannelList,
6827 pScanReq->ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07006828 }
6829 else
6830 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006831 smsLog(pMac, LOGE, FL("ran out of memory"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006832 csrReleaseCommandScan(pMac, pCommand);
Kiet Lam64c1b492013-07-12 13:56:44 +05306833 return eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006834 }
6835 }
6836
6837 //scan req for SSID
6838 if(pScanReq->SSID.length)
6839 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306840 vos_mem_copy(pCommand->u.scanCmd.u.bgScanRequest.SSID.ssId,
6841 pScanReq->SSID.ssId, pScanReq->SSID.length);
Jeff Johnson295189b2012-06-20 16:38:30 -07006842 pCommand->u.scanCmd.u.bgScanRequest.SSID.length = pScanReq->SSID.length;
6843
6844 }
6845 pCommand->u.scanCmd.u.bgScanRequest.maxChnTime= pScanReq->maxChnTime;
6846 pCommand->u.scanCmd.u.bgScanRequest.minChnTime = pScanReq->minChnTime;
6847 pCommand->u.scanCmd.u.bgScanRequest.scanInterval = pScanReq->scanInterval;
6848
6849
6850 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
6851 if( !HAL_STATUS_SUCCESS( status ) )
6852 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006853 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006854 csrReleaseCommandScan( pMac, pCommand );
6855 break;
6856 }
6857 }while(0);
6858 }
6859
6860 return (status);
6861}
6862
6863eHalStatus csrScanBGScanAbort( tpAniSirGlobal pMac )
6864{
6865 eHalStatus status = eHAL_STATUS_SUCCESS;
6866 tSmeCmd *pCommand = NULL;
6867
6868 do
6869 {
6870 pCommand = csrGetCommandBuffer(pMac);
6871 if(!pCommand)
6872 {
6873 status = eHAL_STATUS_RESOURCES;
6874 break;
6875 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306876 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006877 pCommand->command = eSmeCommandScan;
6878 pCommand->u.scanCmd.reason = eCsrScanBGScanAbort;
6879 pCommand->u.scanCmd.callback = NULL;
6880 pCommand->u.scanCmd.pContext = NULL;
6881 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
6882 if( !HAL_STATUS_SUCCESS( status ) )
6883 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006884 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006885 csrReleaseCommandScan( pMac, pCommand );
6886 break;
6887 }
6888 }while(0);
6889
6890 return (status);
6891}
6892
6893
6894//This will enable the background scan with the non-zero interval
6895eHalStatus csrScanBGScanEnable(tpAniSirGlobal pMac)
6896{
6897 eHalStatus status = eHAL_STATUS_SUCCESS;
6898 tSmeCmd *pCommand = NULL;
6899
6900 if(pMac->roam.configParam.bgScanInterval)
6901 {
6902 do
6903 {
6904 pCommand = csrGetCommandBuffer(pMac);
6905 if(!pCommand)
6906 {
6907 status = eHAL_STATUS_RESOURCES;
6908 break;
6909 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306910 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006911 pCommand->command = eSmeCommandScan;
6912 pCommand->u.scanCmd.reason = eCsrScanBGScanEnable;
6913 pCommand->u.scanCmd.callback = NULL;
6914 pCommand->u.scanCmd.pContext = NULL;
6915 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
6916 if( !HAL_STATUS_SUCCESS( status ) )
6917 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006918 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006919 csrReleaseCommandScan( pMac, pCommand );
6920 break;
6921 }
6922 }while(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006923 }
6924 else
6925 {
Sushant Kaushikb8dbb3f2015-04-29 17:03:37 +05306926 smsLog(pMac, LOGE, FL("cannot continue because the bgscan interval is 0"));
6927 status = eHAL_STATUS_INVALID_PARAMETER;
Jeff Johnson295189b2012-06-20 16:38:30 -07006928 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006929 return (status);
6930}
6931
6932
6933eHalStatus csrScanCopyRequest(tpAniSirGlobal pMac, tCsrScanRequest *pDstReq, tCsrScanRequest *pSrcReq)
6934{
6935 eHalStatus status = eHAL_STATUS_SUCCESS;
6936 tANI_U32 len = sizeof(pMac->roam.validChannelList);
6937 tANI_U32 index = 0;
6938 tANI_U32 new_index = 0;
Manjunathappa Prakashde7b2a52014-02-28 16:59:03 -08006939 eNVChannelEnabledType NVchannel_state;
Arif Hussain6af38622014-03-12 12:39:57 -07006940 tANI_U8 ch144_support = 0;
6941
6942 ch144_support = WDA_getFwWlanFeatCaps(WLAN_CH144);
Jeff Johnson295189b2012-06-20 16:38:30 -07006943
6944 do
6945 {
6946 status = csrScanFreeRequest(pMac, pDstReq);
6947 if(HAL_STATUS_SUCCESS(status))
6948 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306949 vos_mem_copy(pDstReq, pSrcReq, sizeof(tCsrScanRequest));
Gopichand Nakkalac7b1d3e2012-12-31 14:07:19 -08006950 /* Re-initialize the pointers to NULL since we did a copy */
6951 pDstReq->pIEField = NULL;
6952 pDstReq->ChannelInfo.ChannelList = NULL;
6953 pDstReq->SSIDs.SSIDList = NULL;
6954
Jeff Johnson295189b2012-06-20 16:38:30 -07006955 if(pSrcReq->uIEFieldLen == 0)
6956 {
6957 pDstReq->pIEField = NULL;
6958 }
6959 else
6960 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306961 pDstReq->pIEField = vos_mem_malloc(pSrcReq->uIEFieldLen);
6962 if ( NULL == pDstReq->pIEField )
Jeff Johnson295189b2012-06-20 16:38:30 -07006963 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306964 status = eHAL_STATUS_FAILURE;
6965 smsLog(pMac, LOGE, FL("No memory for scanning IE fields"));
6966 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07006967 }
6968 else
6969 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306970 status = eHAL_STATUS_SUCCESS;
6971 vos_mem_copy(pDstReq->pIEField, pSrcReq->pIEField,
6972 pSrcReq->uIEFieldLen);
6973 pDstReq->uIEFieldLen = pSrcReq->uIEFieldLen;
Jeff Johnson295189b2012-06-20 16:38:30 -07006974 }
6975 }//Allocate memory for IE field
6976 {
6977 if(pSrcReq->ChannelInfo.numOfChannels == 0)
6978 {
6979 pDstReq->ChannelInfo.ChannelList = NULL;
6980 pDstReq->ChannelInfo.numOfChannels = 0;
6981 }
6982 else
6983 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306984 pDstReq->ChannelInfo.ChannelList = vos_mem_malloc(
6985 pSrcReq->ChannelInfo.numOfChannels
6986 * sizeof(*pDstReq->ChannelInfo.ChannelList));
6987 if ( NULL == pDstReq->ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07006988 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306989 status = eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006990 pDstReq->ChannelInfo.numOfChannels = 0;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306991 smsLog(pMac, LOGE, FL("No memory for scanning Channel"
6992 " List"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006993 break;
6994 }
6995
6996 if((pSrcReq->scanType == eSIR_PASSIVE_SCAN) && (pSrcReq->requestType == eCSR_SCAN_REQUEST_11D_SCAN))
6997 {
6998 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
6999 {
Arif Hussain6af38622014-03-12 12:39:57 -07007000 /* Skip CH 144 if firmware support not present */
7001 if (pSrcReq->ChannelInfo.ChannelList[index] == 144 && !ch144_support)
7002 continue;
Agarwal Ashish8bd53ae2015-06-12 18:03:45 +05307003 /* Skip channel 12 and 13 when FCC constraint is true */
7004 if ((pMac->scan.fcc_constraint) &&
7005 ((pSrcReq->ChannelInfo.ChannelList[index] ==12) ||
7006 (pSrcReq->ChannelInfo.ChannelList[index] ==13)))
7007 {
7008 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
7009 FL("Ignoring channel : %d "),
7010 pSrcReq->ChannelInfo.ChannelList[index]);
7011 continue;
7012 }
Arif Hussain6af38622014-03-12 12:39:57 -07007013
Manjunathappa Prakashde7b2a52014-02-28 16:59:03 -08007014 NVchannel_state = vos_nv_getChannelEnabledState(
7015 pSrcReq->ChannelInfo.ChannelList[index]);
7016 if ((NV_CHANNEL_ENABLE == NVchannel_state) ||
7017 (NV_CHANNEL_DFS == NVchannel_state))
7018 {
7019 pDstReq->ChannelInfo.ChannelList[new_index] =
7020 pSrcReq->ChannelInfo.ChannelList[index];
7021 new_index++;
7022 }
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05307023 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007024 pDstReq->ChannelInfo.numOfChannels = new_index;
7025 }
7026 else if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
7027 {
7028 new_index = 0;
7029 pMac->roam.numValidChannels = len;
c_hpothu0d5a7352014-03-22 12:30:25 +05307030
Deepthi Gowriecc93352016-11-09 16:58:47 +05307031 /* Since in CsrScanRequest,value of pMac->scan.
7032 * nextScanID is incremented before calling
7033 * CsrScanCopyRequest, as a result pMac->scan.
7034 * nextScanID is equal to ONE for the first scan.
7035 * If number of channels is less than max chan
7036 * for dwell time no need to skip dfs in first
7037 * scan as anyway few channels will be scanned
7038 * and it will not take much time to display
7039 * results on GUI.
7040 */
7041 if (((pSrcReq->ChannelInfo.numOfChannels >=
7042 pMac->roam.configParam.
7043 max_chan_for_dwell_time_cfg) &&
7044 (pMac->roam.configParam.
7045 initialScanSkipDFSCh &&
7046 1 == pMac->scan.nextScanID)) ||
7047 (pMac->miracast_mode))
c_hpothu0d5a7352014-03-22 12:30:25 +05307048 {
Deepthi Gowriecc93352016-11-09 16:58:47 +05307049 smsLog(pMac, LOG1,
7050 FL("Initial scan, scan only non-DFS channels"));
c_hpothu0d5a7352014-03-22 12:30:25 +05307051
Deepthi Gowriecc93352016-11-09 16:58:47 +05307052 for (index = 0; index < pSrcReq->ChannelInfo.
7053 numOfChannels ; index++ )
Jeff Johnson295189b2012-06-20 16:38:30 -07007054 {
Deepthi Gowriecc93352016-11-09 16:58:47 +05307055 if((csrRoamIsValidChannel(pMac,
7056 pSrcReq->ChannelInfo.
7057 ChannelList[index])))
Srikant Kuppa866893f2012-12-27 17:28:14 -08007058 {
Deepthi Gowriecc93352016-11-09 16:58:47 +05307059 /*Skiipping DFS Channels for 1st scan */
7060 if(NV_CHANNEL_DFS ==
7061 vos_nv_getChannelEnabledState(
7062 pSrcReq->ChannelInfo.
7063 ChannelList[index]))
7064 continue ;
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08007065
Deepthi Gowriecc93352016-11-09 16:58:47 +05307066 pDstReq->ChannelInfo.
7067 ChannelList[new_index] =
7068 pSrcReq->ChannelInfo.ChannelList[index];
7069 new_index++;
7070
7071 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007072 }
Deepthi Gowriecc93352016-11-09 16:58:47 +05307073 pMac->roam.configParam.initialScanSkipDFSCh = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07007074 }
Deepthi Gowriecc93352016-11-09 16:58:47 +05307075 else
7076 csrValidateScanChannels(pMac, pDstReq, pSrcReq,
Nishank Aggarwal42f76502017-02-16 12:00:19 +05307077 &new_index, ch144_support);
Jeff Johnson295189b2012-06-20 16:38:30 -07007078 pDstReq->ChannelInfo.numOfChannels = new_index;
Srikant Kuppa866893f2012-12-27 17:28:14 -08007079#ifdef FEATURE_WLAN_LFR
Deepthi Gowriecc93352016-11-09 16:58:47 +05307080 if ( ( ( eCSR_SCAN_HO_BG_SCAN ==
7081 pSrcReq->requestType ) ||
7082 ( eCSR_SCAN_P2P_DISCOVERY ==
7083 pSrcReq->requestType ) ) &&
7084 ( 0 == pDstReq->ChannelInfo.numOfChannels ) )
Srikant Kuppa866893f2012-12-27 17:28:14 -08007085 {
7086 /*
7087 * No valid channels found in the request.
7088 * Only perform scan on the channels passed
Abhishek Singh2ec36ab2014-08-07 16:14:25 +05307089 * pSrcReq if it is a eCSR_SCAN_HO_BG_SCAN or
7090 * eCSR_SCAN_P2P_DISCOVERY.
Srikant Kuppa866893f2012-12-27 17:28:14 -08007091 * Passing 0 to LIM will trigger a scan on
7092 * all valid channels which is not desirable.
7093 */
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05307094 smsLog(pMac, LOGE, FL(" no valid channels found"
Deepthi Gowriecc93352016-11-09 16:58:47 +05307095 " (request=%d)"), pSrcReq->requestType);
7096 for ( index = 0; index < pSrcReq->ChannelInfo.
7097 numOfChannels ; index++ )
Srikant Kuppa866893f2012-12-27 17:28:14 -08007098 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05307099 smsLog(pMac, LOGE, FL("pSrcReq index=%d"
Deepthi Gowriecc93352016-11-09 16:58:47 +05307100 " channel=%d"), index,
7101 pSrcReq->ChannelInfo.ChannelList[index]);
Srikant Kuppa866893f2012-12-27 17:28:14 -08007102 }
7103 status = eHAL_STATUS_FAILURE;
7104 break;
Deepthi Gowriecc93352016-11-09 16:58:47 +05307105 }
Srikant Kuppa866893f2012-12-27 17:28:14 -08007106#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07007107 }
7108 else
7109 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05307110 smsLog(pMac, LOGE, FL("Couldn't get the valid Channel"
7111 " List, keeping requester's list"));
Kiet Lam64c1b492013-07-12 13:56:44 +05307112 vos_mem_copy(pDstReq->ChannelInfo.ChannelList,
7113 pSrcReq->ChannelInfo.ChannelList,
7114 pSrcReq->ChannelInfo.numOfChannels
Deepthi Gowriecc93352016-11-09 16:58:47 +05307115 * sizeof(*pDstReq->ChannelInfo.ChannelList));
7116 pDstReq->ChannelInfo.numOfChannels =
7117 pSrcReq->ChannelInfo.numOfChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -07007118 }
7119 }//Allocate memory for Channel List
7120 }
7121 if(pSrcReq->SSIDs.numOfSSIDs == 0)
7122 {
7123 pDstReq->SSIDs.numOfSSIDs = 0;
7124 pDstReq->SSIDs.SSIDList = NULL;
7125 }
7126 else
7127 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307128 pDstReq->SSIDs.SSIDList = vos_mem_malloc(
7129 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
7130 if ( NULL == pDstReq->SSIDs.SSIDList )
7131 status = eHAL_STATUS_FAILURE;
7132 else
7133 status = eHAL_STATUS_SUCCESS;
7134 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07007135 {
7136 pDstReq->SSIDs.numOfSSIDs = pSrcReq->SSIDs.numOfSSIDs;
Kiet Lam64c1b492013-07-12 13:56:44 +05307137 vos_mem_copy(pDstReq->SSIDs.SSIDList,
7138 pSrcReq->SSIDs.SSIDList,
7139 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
Jeff Johnson295189b2012-06-20 16:38:30 -07007140 }
7141 else
7142 {
7143 pDstReq->SSIDs.numOfSSIDs = 0;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05307144 smsLog(pMac, LOGE, FL("No memory for scanning SSID List"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007145 break;
7146 }
7147 }//Allocate memory for SSID List
Jeff Johnson295189b2012-06-20 16:38:30 -07007148 pDstReq->p2pSearch = pSrcReq->p2pSearch;
Jeff Johnsone7245742012-09-05 17:12:55 -07007149 pDstReq->skipDfsChnlInP2pSearch = pSrcReq->skipDfsChnlInP2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07007150
7151 }
7152 }while(0);
7153
7154 if(!HAL_STATUS_SUCCESS(status))
7155 {
7156 csrScanFreeRequest(pMac, pDstReq);
7157 }
7158
7159 return (status);
7160}
7161
7162
7163eHalStatus csrScanFreeRequest(tpAniSirGlobal pMac, tCsrScanRequest *pReq)
7164{
Jeff Johnson295189b2012-06-20 16:38:30 -07007165
7166 if(pReq->ChannelInfo.ChannelList)
7167 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307168 vos_mem_free(pReq->ChannelInfo.ChannelList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007169 pReq->ChannelInfo.ChannelList = NULL;
7170 }
7171 pReq->ChannelInfo.numOfChannels = 0;
7172 if(pReq->pIEField)
7173 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307174 vos_mem_free(pReq->pIEField);
Jeff Johnson295189b2012-06-20 16:38:30 -07007175 pReq->pIEField = NULL;
7176 }
7177 pReq->uIEFieldLen = 0;
7178 if(pReq->SSIDs.SSIDList)
7179 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307180 vos_mem_free(pReq->SSIDs.SSIDList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007181 pReq->SSIDs.SSIDList = NULL;
7182 }
7183 pReq->SSIDs.numOfSSIDs = 0;
7184
Kiet Lam64c1b492013-07-12 13:56:44 +05307185 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07007186}
7187
7188
7189void csrScanCallCallback(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
7190{
7191 if(pCommand->u.scanCmd.callback)
7192 {
Ratheesh S Pece1f832015-07-25 15:50:25 +05307193 if (pCommand->u.scanCmd.abortScanIndication){
Kapil Guptac46b7542016-10-25 13:03:20 +05307194 if ((pCommand->u.scanCmd.reason != eCsrScanForSsid) ||
7195 (scanStatus != eCSR_SCAN_SUCCESS)) {
7196 smsLog( pMac, LOG1, FL("scanDone due to abort"));
7197 scanStatus = eCSR_SCAN_ABORT;
7198 }
Ratheesh S Pece1f832015-07-25 15:50:25 +05307199 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007200 pCommand->u.scanCmd.callback(pMac, pCommand->u.scanCmd.pContext, pCommand->u.scanCmd.scanID, scanStatus);
Jeff Johnson295189b2012-06-20 16:38:30 -07007201 } else {
Kapil Guptac46b7542016-10-25 13:03:20 +05307202 smsLog(pMac, LOG2,
7203 FL("Callback NULL cmd reason %d"),
7204 pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07007205 }
7206}
7207
7208
7209void csrScanStopTimers(tpAniSirGlobal pMac)
7210{
Jeff Johnson295189b2012-06-20 16:38:30 -07007211 csrScanStopIdleScanTimer(pMac);
7212 csrScanStopGetResultTimer(pMac);
7213}
7214
7215
7216eHalStatus csrScanStartGetResultTimer(tpAniSirGlobal pMac)
7217{
7218 eHalStatus status;
7219
7220 if(pMac->scan.fScanEnable)
7221 {
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05307222 status = vos_timer_start(&pMac->scan.hTimerGetResult, CSR_SCAN_GET_RESULT_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07007223 }
7224 else
7225 {
7226 status = eHAL_STATUS_FAILURE;
7227 }
7228
7229 return (status);
7230}
7231
7232
7233eHalStatus csrScanStopGetResultTimer(tpAniSirGlobal pMac)
7234{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05307235 return (vos_timer_stop(&pMac->scan.hTimerGetResult));
Jeff Johnson295189b2012-06-20 16:38:30 -07007236}
7237
7238
7239void csrScanGetResultTimerHandler(void *pv)
7240{
7241 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
7242
7243 csrScanRequestResult(pMac);
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05307244
7245 vos_timer_start(&pMac->scan.hTimerGetResult, CSR_SCAN_GET_RESULT_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07007246}
7247
Padma, Santhosh Kumar36183352016-11-08 17:48:34 +05307248
7249void csr_handle_disable_scan(void *pv)
7250{
7251 tpAniSirGlobal mac = PMAC_STRUCT(pv);
7252
7253 if (mac->scan.disable_scan_during_sco_timer_info.callback)
7254 mac->scan.disable_scan_during_sco_timer_info.callback(
7255 mac,
7256 mac->scan.disable_scan_during_sco_timer_info.dev,
7257 mac->scan.disable_scan_during_sco_timer_info.scan_id,
7258 eHAL_STATUS_SUCCESS);
7259 else
7260 smsLog(mac, LOGE, FL("Callback is NULL"));
7261}
7262
Jeff Johnson295189b2012-06-20 16:38:30 -07007263#ifdef WLAN_AP_STA_CONCURRENCY
7264static void csrStaApConcTimerHandler(void *pv)
7265{
7266 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
7267 tListElem *pEntry;
7268 tSmeCmd *pScanCmd;
7269
7270 csrLLLock(&pMac->scan.scanCmdPendingList);
7271
7272 if ( NULL != ( pEntry = csrLLPeekHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) ) )
7273 {
7274 tCsrScanRequest scanReq;
7275 tSmeCmd *pSendScanCmd = NULL;
7276 tANI_U8 numChn = 0;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07007277 tANI_U8 nNumChanCombinedConc = 0;
Vinay Malekal05fdc812012-12-17 13:04:30 -08007278 tANI_U8 i, j;
Jeff Johnson295189b2012-06-20 16:38:30 -07007279 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
7280 tANI_U8 channelToScan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
7281 eHalStatus status;
7282
Jeff Johnson295189b2012-06-20 16:38:30 -07007283 pScanCmd = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7284 numChn = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08007285
7286 /* if any session is connected and the number of channels to scan is
7287 * greater than 1 then split the scan into multiple scan operations
7288 * on each individual channel else continue to perform scan on all
7289 * specified channels */
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08007290
7291 /* split scan if number of channels to scan is greater than 1 and
7292 * any one of the following:
7293 * - STA session is connected and the scan is not a P2P search
7294 * - any P2P session is connected
Yeshwanth Sriram Guntuka7ea10b02018-09-05 17:35:44 +05307295 * - STA+SAP. In STA+SAP concurrency, scan requests received on
7296 * STA interface when not in connected state are not split.
7297 * This can result in large time gap between successive beacons
7298 * sent by SAP.
Srikant Kuppa866893f2012-12-27 17:28:14 -08007299 * Do not split scans if no concurrent infra connections are
7300 * active and if the scan is a BG scan triggered by LFR (OR)
7301 * any scan if LFR is in the middle of a BG scan. Splitting
7302 * the scan is delaying the time it takes for LFR to find
7303 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08007304 */
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07007305
Yeshwanth Sriram Guntuka7ea10b02018-09-05 17:35:44 +05307306 if (csrIsInfraApStarted(pMac))
7307 {
7308 nNumChanCombinedConc = 1;
7309 }
7310 else if((csrIsStaSessionConnected(pMac) &&
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07007311 !csrIsP2pSessionConnected(pMac)))
7312 {
7313 nNumChanCombinedConc = pMac->roam.configParam.nNumStaChanCombinedConc;
7314 }
7315 else if(csrIsP2pSessionConnected(pMac))
7316 {
7317 nNumChanCombinedConc = pMac->roam.configParam.nNumP2PChanCombinedConc;
7318 }
7319
7320 if ( (numChn > nNumChanCombinedConc) &&
Srikant Kuppa866893f2012-12-27 17:28:14 -08007321 ((csrIsStaSessionConnected(pMac) &&
7322#ifdef FEATURE_WLAN_LFR
7323 (csrIsConcurrentInfraConnected(pMac) ||
7324 ((pScanCmd->u.scanCmd.reason != eCsrScanBgScan) &&
7325 (pMac->roam.neighborRoamInfo.neighborRoamState !=
7326 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
7327#endif
7328 (pScanCmd->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08007329 (csrIsP2pSessionConnected(pMac))))
Jeff Johnson295189b2012-06-20 16:38:30 -07007330 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307331 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007332
7333 pSendScanCmd = csrGetCommandBuffer(pMac); //optimize this to use 2 command buffer only
7334 if (!pSendScanCmd)
7335 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007336 smsLog( pMac, LOGE, FL(" Failed to get Queue command buffer") );
Jeff Johnson295189b2012-06-20 16:38:30 -07007337 csrLLUnlock(&pMac->scan.scanCmdPendingList);
7338 return;
7339 }
7340 pSendScanCmd->command = pScanCmd->command;
7341 pSendScanCmd->sessionId = pScanCmd->sessionId;
7342 pSendScanCmd->u.scanCmd.callback = NULL;
7343 pSendScanCmd->u.scanCmd.pContext = pScanCmd->u.scanCmd.pContext;
7344 pSendScanCmd->u.scanCmd.reason = pScanCmd->u.scanCmd.reason;
7345 pSendScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
7346
Madan Mohan Koyyalamudiaf2a8b92012-10-09 14:58:07 -07007347 /* First copy all the parameters to local variable of scan request */
7348 csrScanCopyRequest(pMac, &scanReq, &pScanCmd->u.scanCmd.u.scanRequest);
7349
7350 /* Now modify the elements of local var scan request required to be modified for split scan */
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08007351 if(scanReq.ChannelInfo.ChannelList != NULL)
7352 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307353 vos_mem_free(scanReq.ChannelInfo.ChannelList);
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08007354 scanReq.ChannelInfo.ChannelList = NULL;
7355 }
7356
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07007357 pChnInfo->numOfChannels = nNumChanCombinedConc;
Kiet Lam64c1b492013-07-12 13:56:44 +05307358 vos_mem_copy(&channelToScan[0],
7359 &pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[0],
7360 pChnInfo->numOfChannels * sizeof(tANI_U8));//just send one channel
Jeff Johnson295189b2012-06-20 16:38:30 -07007361 pChnInfo->ChannelList = &channelToScan[0];
7362
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07007363 for (i = 0, j = nNumChanCombinedConc; i < (numChn-nNumChanCombinedConc); i++, j++)
Jeff Johnson295189b2012-06-20 16:38:30 -07007364 {
7365 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] =
Vinay Malekal05fdc812012-12-17 13:04:30 -08007366 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[j]; //Move all the channels one step
Jeff Johnson295189b2012-06-20 16:38:30 -07007367 }
7368
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07007369 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = numChn - nNumChanCombinedConc; //reduce outstanding # of channels to be scanned
Jeff Johnson295189b2012-06-20 16:38:30 -07007370
7371 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
c_hpothudbefd3e2014-04-28 15:59:47 +05307372
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -07007373 //Use concurrency values for min/maxChnTime.
7374 //We know csrIsAnySessionConnected(pMac) returns TRUE here
7375 csrSetDefaultScanTiming(pMac, scanReq.scanType, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07007376
7377 status = csrScanCopyRequest(pMac, &pSendScanCmd->u.scanCmd.u.scanRequest, &scanReq);
7378 if(!HAL_STATUS_SUCCESS(status))
7379 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007380 smsLog( pMac, LOGE, FL(" Failed to get copy csrScanRequest = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07007381 csrLLUnlock(&pMac->scan.scanCmdPendingList);
7382 return;
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08007383 }
7384 /* Clean the local scan variable */
7385 scanReq.ChannelInfo.ChannelList = NULL;
7386 scanReq.ChannelInfo.numOfChannels = 0;
7387 csrScanFreeRequest(pMac, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07007388 }
7389 else
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08007390 {
7391 /* no active connected session present or numChn == 1
7392 * scan all remaining channels */
Jeff Johnson295189b2012-06-20 16:38:30 -07007393 pSendScanCmd = pScanCmd;
7394 //remove this command from pending list
7395 if (csrLLRemoveHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) == NULL)
7396 { //In case between PeekHead and here, the entry got removed by another thread.
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007397 smsLog( pMac, LOGE, FL(" Failed to remove entry from scanCmdPendingList"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007398 }
7399
7400 }
7401 csrQueueSmeCommand(pMac, pSendScanCmd, eANI_BOOLEAN_FALSE);
7402
7403 }
7404
Jeff Johnson295189b2012-06-20 16:38:30 -07007405 csrLLUnlock(&pMac->scan.scanCmdPendingList);
7406
7407}
7408#endif
7409
Jeff Johnson295189b2012-06-20 16:38:30 -07007410//This function returns the maximum time a BSS is allowed in the scan result.
7411//The time varies base on connection and power saving factors.
7412//Not connected, No PS
7413//Not connected, with PS
7414//Connected w/o traffic, No PS
7415//Connected w/o traffic, with PS
7416//Connected w/ traffic, no PS -- Not supported
7417//Connected w/ traffic, with PS -- Not supported
7418//the return unit is in seconds.
7419tANI_U32 csrScanGetAgeOutTime(tpAniSirGlobal pMac)
7420{
7421 tANI_U32 nRet;
7422
7423 if(pMac->scan.nAgingCountDown)
7424 {
7425 //Calculate what should be the timeout value for this
7426 nRet = pMac->scan.nLastAgeTimeOut * pMac->scan.nAgingCountDown;
7427 pMac->scan.nAgingCountDown--;
7428 }
7429 else
7430 {
7431 if( csrIsAllSessionDisconnected( pMac ) )
7432 {
7433 if(pmcIsPowerSaveEnabled(pMac, ePMC_IDLE_MODE_POWER_SAVE))
7434 {
7435 nRet = pMac->roam.configParam.scanAgeTimeNCPS;
7436 }
7437 else
7438 {
7439 nRet = pMac->roam.configParam.scanAgeTimeNCNPS;
7440 }
7441 }
7442 else
7443 {
7444 if(pmcIsPowerSaveEnabled(pMac, ePMC_BEACON_MODE_POWER_SAVE))
7445 {
7446 nRet = pMac->roam.configParam.scanAgeTimeCPS;
7447 }
7448 else
7449 {
7450 nRet = pMac->roam.configParam.scanAgeTimeCNPS;
7451 }
7452 }
7453 //If state-change causing aging time out change, we want to delay it somewhat to avoid
7454 //unnecessary removal of BSS. This is mostly due to transition from connect to disconnect.
7455 if(pMac->scan.nLastAgeTimeOut > nRet)
7456 {
7457 if(nRet)
7458 {
7459 pMac->scan.nAgingCountDown = (pMac->scan.nLastAgeTimeOut / nRet);
7460 }
7461 pMac->scan.nLastAgeTimeOut = nRet;
7462 nRet *= pMac->scan.nAgingCountDown;
7463 }
7464 else
7465 {
7466 pMac->scan.nLastAgeTimeOut = nRet;
7467 }
7468 }
7469
7470 return (nRet);
7471}
7472
Deepthi Gowri6a08e312016-03-31 19:10:14 +05307473static void csrPurgeScanResultByAge(void *pv)
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08007474{
7475 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
7476 tListElem *pEntry, *tmpEntry;
7477 tCsrScanResult *pResult;
Deepthi Gowri4480a3f2016-05-18 19:30:17 +05307478 v_TIME_t ageOutTime =
7479 (v_TIME_t)(pMac->scan.scanResultCfgAgingTime * SYSTEM_TIME_SEC_TO_MSEC);
7480 v_TIME_t curTime = vos_timer_get_system_time();
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08007481
7482 csrLLLock(&pMac->scan.scanResultList);
7483 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
Deepthi Gowri6a08e312016-03-31 19:10:14 +05307484 smsLog(pMac, LOG1, FL("Ageout time=%lu"),ageOutTime);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08007485 while( pEntry )
7486 {
7487 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
7488 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
7489 if((curTime - pResult->Result.BssDescriptor.nReceivedTime) > ageOutTime)
7490 {
Deepthi Gowri50e2fa52016-03-17 15:30:53 +05307491 smsLog(pMac, LOG1, FL("age out due to time out for BSSID" MAC_ADDRESS_STR),
7492 MAC_ADDR_ARRAY(pResult->Result.BssDescriptor.bssId));
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08007493 csrScanAgeOutBss(pMac, pResult);
7494 }
7495 pEntry = tmpEntry;
7496 }
7497 csrLLUnlock(&pMac->scan.scanResultList);
7498}
Jeff Johnson295189b2012-06-20 16:38:30 -07007499
7500eHalStatus csrScanStartIdleScanTimer(tpAniSirGlobal pMac, tANI_U32 interval)
7501{
7502 eHalStatus status;
7503
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007504 smsLog(pMac, LOG1, " csrScanStartIdleScanTimer");
Jeff Johnson295189b2012-06-20 16:38:30 -07007505 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) && interval)
7506 {
7507 pMac->scan.nIdleScanTimeGap += interval;
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05307508 vos_timer_stop(&pMac->scan.hTimerIdleScan);
7509 status = vos_timer_start(&pMac->scan.hTimerIdleScan, interval/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07007510 if( !HAL_STATUS_SUCCESS(status) )
7511 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007512 smsLog(pMac, LOGE, " Fail to start Idle scan timer. status = %d interval = %d", status, interval);
Jeff Johnson295189b2012-06-20 16:38:30 -07007513 //This should not happen but set the flag to restart when ready
7514 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7515 }
7516 }
7517 else
7518 {
7519 if( pMac->scan.fScanEnable && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) )
7520 {
7521 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7522 }
7523 status = eHAL_STATUS_FAILURE;
7524 }
7525
7526 return (status);
7527}
7528
7529
7530eHalStatus csrScanStopIdleScanTimer(tpAniSirGlobal pMac)
7531{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05307532 return (vos_timer_stop(&pMac->scan.hTimerIdleScan));
Jeff Johnson295189b2012-06-20 16:38:30 -07007533}
7534
7535
7536//Stop CSR from asking for IMPS, This function doesn't disable IMPS from CSR
7537void csrScanSuspendIMPS( tpAniSirGlobal pMac )
7538{
7539 csrScanCancelIdleScan(pMac);
7540}
7541
7542
7543//Start CSR from asking for IMPS. This function doesn't trigger CSR to request entering IMPS
7544//because IMPS maybe disabled.
7545void csrScanResumeIMPS( tpAniSirGlobal pMac )
7546{
7547 csrScanStartIdleScan( pMac );
7548}
7549
7550
7551void csrScanIMPSCallback(void *callbackContext, eHalStatus status)
7552{
7553 tpAniSirGlobal pMac = PMAC_STRUCT( callbackContext );
7554
7555 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
7556 {
7557 if(pMac->roam.configParam.IsIdleScanEnabled)
7558 {
7559 if(HAL_STATUS_SUCCESS(status))
7560 {
7561 if(csrIsAllSessionDisconnected(pMac) && !csrIsRoamCommandWaiting(pMac))
7562 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007563 smsLog(pMac, LOGW, FL("starts idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007564 csrScanAllChannels(pMac, eCSR_SCAN_IDLE_MODE_SCAN);
7565 }
7566 else
7567 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007568 smsLog(pMac, LOGW, FL("cannot start idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007569 //even though we are in timer handle, calling stop timer will make sure the timer
7570 //doesn't get to restart.
7571 csrScanStopIdleScanTimer(pMac);
7572 }
7573 }
7574 else
7575 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007576 smsLog(pMac, LOGE, FL("sees not success status (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07007577 }
7578 }
7579 else
7580 {//we might need another flag to check if CSR needs to request imps at all
7581
7582 tANI_U32 nTime = 0;
7583
7584 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_FALSE;
7585 if(!HAL_STATUS_SUCCESS(csrScanTriggerIdleScan(pMac, &nTime)))
7586 {
7587 csrScanStartIdleScanTimer(pMac, nTime);
7588 }
7589 }
7590 }
7591}
7592
7593
Rashmi Ramanna68b309c2014-05-20 11:52:22 +05307594//Param: pTimeInterval -- Caller allocated memory in return, if failed, to specify the nxt time interval for
Jeff Johnson295189b2012-06-20 16:38:30 -07007595//idle scan timer interval
7596//Return: Not success -- meaning it cannot start IMPS, caller needs to start a timer for idle scan
7597eHalStatus csrScanTriggerIdleScan(tpAniSirGlobal pMac, tANI_U32 *pTimeInterval)
7598{
7599 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
7600
7601 //Do not trigger IMPS in case of concurrency
Agarwal Ashish5974ed32014-06-16 16:59:54 +05307602 if (vos_concurrent_open_sessions_running() &&
7603 csrIsAnySessionInConnectState(pMac))
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007604 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007605 smsLog( pMac, LOG1, FL("Cannot request IMPS because Concurrent Sessions Running") );
Jeff Johnson295189b2012-06-20 16:38:30 -07007606 return (status);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007607 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007608
7609 if(pTimeInterval)
7610 {
7611 *pTimeInterval = 0;
7612 }
7613
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007614 smsLog(pMac, LOG3, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007615 if( smeCommandPending( pMac ) )
7616 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007617 smsLog( pMac, LOG1, FL(" Cannot request IMPS because command pending") );
Jeff Johnson295189b2012-06-20 16:38:30 -07007618 //Not to enter IMPS because more work to do
7619 if(pTimeInterval)
7620 {
7621 *pTimeInterval = 0;
7622 }
7623 //restart when ready
7624 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7625
7626 return (status);
7627 }
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07007628 if (IsPmcImpsReqFailed (pMac))
7629 {
7630 if(pTimeInterval)
7631 {
7632 *pTimeInterval = 1000000; //usec
7633 }
7634 //restart when ready
7635 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07007636
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07007637 return status;
7638 }
Rashmi Ramanna68b309c2014-05-20 11:52:22 +05307639
7640 if ( !pMac->deferImps && pMac->fDeferIMPSTime )
7641 {
7642 smsLog( pMac, LOG1, FL("Defer IMPS for %dms as command processed"),
7643 pMac->fDeferIMPSTime);
Girish Gowli4f3775a2014-05-30 17:17:08 +05307644 if(pTimeInterval)
7645 {
7646 *pTimeInterval = pMac->fDeferIMPSTime * 1000; //usec
7647 }
Rashmi Ramanna68b309c2014-05-20 11:52:22 +05307648 pMac->deferImps = eANI_BOOLEAN_TRUE;
7649 return status;
7650 }
7651
Jeff Johnson295189b2012-06-20 16:38:30 -07007652 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
7653 /*&& pMac->roam.configParam.impsSleepTime*/)
7654 {
7655 //Stop get result timer because idle scan gets scan result out of PE
7656 csrScanStopGetResultTimer(pMac);
7657 if(pTimeInterval)
7658 {
7659 *pTimeInterval = pMac->roam.configParam.impsSleepTime;
7660 }
7661 //pmcRequestImps take a period in millisecond unit.
7662 status = pmcRequestImps(pMac, pMac->roam.configParam.impsSleepTime / PAL_TIMER_TO_MS_UNIT, csrScanIMPSCallback, pMac);
7663 if(!HAL_STATUS_SUCCESS(status))
7664 {
7665 if(eHAL_STATUS_PMC_ALREADY_IN_IMPS != status)
7666 {
7667 //Do restart the timer if CSR thinks it cannot do IMPS
7668 if( !csrCheckPSReady( pMac ) )
7669 {
7670 if(pTimeInterval)
7671 {
7672 *pTimeInterval = 0;
7673 }
7674 //Set the restart flag to true because that idle scan
7675 //can be restarted even though the timer will not be running
7676 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7677 }
7678 else
7679 {
7680 //For not now, we do a quicker retry
7681 if(pTimeInterval)
7682 {
7683 *pTimeInterval = CSR_IDLE_SCAN_WAIT_TIME;
7684 }
7685 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007686 smsLog(pMac, LOGW, FL("call pmcRequestImps and it returns status code (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07007687 }
7688 else
7689 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007690 smsLog(pMac, LOGW, FL("already in IMPS"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007691 //Since CSR is the only module to request for IMPS. If it is already in IMPS, CSR assumes
7692 //the callback will be called in the future. Should not happen though.
7693 status = eHAL_STATUS_SUCCESS;
7694 pMac->scan.nIdleScanTimeGap = 0;
7695 }
7696 }
7697 else
7698 {
7699 //requested so let's reset the value
7700 pMac->scan.nIdleScanTimeGap = 0;
7701 }
7702 }
7703
7704 return (status);
7705}
7706
7707
7708eHalStatus csrScanStartIdleScan(tpAniSirGlobal pMac)
7709{
7710 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
7711 tANI_U32 nTime = 0;
7712
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007713 smsLog(pMac, LOGW, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007714 if(pMac->roam.configParam.IsIdleScanEnabled)
7715 {
7716 //stop bg scan first
7717 csrScanBGScanAbort(pMac);
7718 //Stop get result timer because idle scan gets scan result out of PE
7719 csrScanStopGetResultTimer(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07007720 }
7721 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_FALSE;
7722 status = csrScanTriggerIdleScan(pMac, &nTime);
7723 if(!HAL_STATUS_SUCCESS(status))
7724 {
7725 csrScanStartIdleScanTimer(pMac, nTime);
7726 }
7727
7728 return (status);
7729}
7730
7731
7732void csrScanCancelIdleScan(tpAniSirGlobal pMac)
7733{
7734 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
7735 {
Agarwal Ashish5974ed32014-06-16 16:59:54 +05307736 if (vos_concurrent_open_sessions_running()) {
Jeff Johnson295189b2012-06-20 16:38:30 -07007737 return;
7738 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007739 smsLog(pMac, LOG1, " csrScanCancelIdleScan");
Jeff Johnson295189b2012-06-20 16:38:30 -07007740 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_TRUE;
7741 //Set the restart flag in case later on it is uncancelled
7742 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7743 csrScanStopIdleScanTimer(pMac);
7744 csrScanRemoveNotRoamingScanCommand(pMac);
7745 }
7746}
7747
7748
7749void csrScanIdleScanTimerHandler(void *pv)
7750{
7751 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
7752 eHalStatus status;
7753 tANI_U32 nTime = 0;
7754
7755 smsLog(pMac, LOGW, " csrScanIdleScanTimerHandler called ");
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07007756 pmcResetImpsFailStatus (pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07007757 status = csrScanTriggerIdleScan(pMac, &nTime);
7758 if(!HAL_STATUS_SUCCESS(status) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan))
7759 {
7760 //Check whether it is time to actually do an idle scan
7761 if(pMac->scan.nIdleScanTimeGap >= pMac->roam.configParam.impsSleepTime)
7762 {
7763 pMac->scan.nIdleScanTimeGap = 0;
7764 csrScanIMPSCallback(pMac, eHAL_STATUS_SUCCESS);
7765 }
7766 else
7767 {
7768 csrScanStartIdleScanTimer(pMac, nTime);
7769 }
7770 }
Rashmi Ramanna68b309c2014-05-20 11:52:22 +05307771 if(pMac->deferImps)
7772 {
7773 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7774 pMac->deferImps = eANI_BOOLEAN_FALSE;
7775 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007776}
7777
7778
7779
7780
7781tANI_BOOLEAN csrScanRemoveNotRoamingScanCommand(tpAniSirGlobal pMac)
7782{
7783 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
7784 tListElem *pEntry, *pEntryTmp;
7785 tSmeCmd *pCommand;
7786 tDblLinkList localList;
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307787 tDblLinkList *pCmdList;
Jeff Johnson295189b2012-06-20 16:38:30 -07007788
7789 vos_mem_zero(&localList, sizeof(tDblLinkList));
7790 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
7791 {
7792 smsLog(pMac, LOGE, FL(" failed to open list"));
7793 return fRet;
7794 }
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307795 if (!pMac->fScanOffload)
7796 pCmdList = &pMac->sme.smeCmdPendingList;
7797 else
7798 pCmdList = &pMac->sme.smeScanCmdPendingList;
Jeff Johnson295189b2012-06-20 16:38:30 -07007799
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307800 csrLLLock(pCmdList);
7801 pEntry = csrLLPeekHead(pCmdList, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007802 while(pEntry)
7803 {
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307804 pEntryTmp = csrLLNext(pCmdList, pEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007805 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7806 if( eSmeCommandScan == pCommand->command )
7807 {
7808 switch( pCommand->u.scanCmd.reason )
7809 {
7810 case eCsrScanIdleScan:
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307811 if( csrLLRemoveEntry(pCmdList, pEntry, LL_ACCESS_NOLOCK) )
Jeff Johnson295189b2012-06-20 16:38:30 -07007812 {
7813 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
7814 }
7815 fRet = eANI_BOOLEAN_TRUE;
7816 break;
7817
7818 default:
7819 break;
7820 } //switch
7821 }
7822 pEntry = pEntryTmp;
7823 }
7824
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307825 csrLLUnlock(pCmdList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007826
7827 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
7828 {
7829 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7830 csrReleaseCommandScan( pMac, pCommand );
7831 }
7832
7833 csrLLClose(&localList);
7834
7835 return (fRet);
7836}
7837
7838
7839tANI_BOOLEAN csrScanRemoveFreshScanCommand(tpAniSirGlobal pMac, tANI_U8 sessionId)
7840{
7841 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
7842 tListElem *pEntry, *pEntryTmp;
7843 tSmeCmd *pCommand;
7844 tDblLinkList localList;
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307845 tDblLinkList *pCmdList;
Jeff Johnson295189b2012-06-20 16:38:30 -07007846
7847 vos_mem_zero(&localList, sizeof(tDblLinkList));
7848 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
7849 {
7850 smsLog(pMac, LOGE, FL(" failed to open list"));
7851 return fRet;
7852 }
7853
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307854 if (!pMac->fScanOffload)
7855 pCmdList = &pMac->sme.smeCmdPendingList;
7856 else
7857 pCmdList = &pMac->sme.smeScanCmdPendingList;
7858
7859 csrLLLock(pCmdList);
7860 pEntry = csrLLPeekHead(pCmdList, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007861 while(pEntry)
7862 {
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307863 pEntryTmp = csrLLNext(pCmdList, pEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007864 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7865 if( (eSmeCommandScan == pCommand->command) && (sessionId == pCommand->sessionId) )
7866 {
7867 switch(pCommand->u.scanCmd.reason)
7868 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07007869#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
7870 case eCsrScanGetLfrResult:
7871#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07007872 case eCsrScanGetResult:
7873 case eCsrScanSetBGScanParam:
7874 case eCsrScanBGScanAbort:
7875 case eCsrScanBGScanEnable:
7876 case eCsrScanGetScanChnInfo:
7877 break;
7878 default:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007879 smsLog (pMac, LOGW, "%s: -------- abort scan command reason = %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007880 __func__, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07007881 //The rest are fresh scan requests
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307882 if( csrLLRemoveEntry(pCmdList, pEntry, LL_ACCESS_NOLOCK) )
Jeff Johnson295189b2012-06-20 16:38:30 -07007883 {
7884 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
7885 }
7886 fRet = eANI_BOOLEAN_TRUE;
7887 break;
7888 }
7889 }
7890 pEntry = pEntryTmp;
7891 }
7892
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307893 csrLLUnlock(pCmdList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007894
7895 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
7896 {
7897 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7898 if (pCommand->u.scanCmd.callback)
7899 {
7900 /* User scan request is pending,
7901 * send response with status eCSR_SCAN_ABORT*/
7902 pCommand->u.scanCmd.callback(pMac,
7903 pCommand->u.scanCmd.pContext,
7904 pCommand->u.scanCmd.scanID,
7905 eCSR_SCAN_ABORT);
7906 }
7907 csrReleaseCommandScan( pMac, pCommand );
7908 }
7909 csrLLClose(&localList);
7910
7911 return (fRet);
7912}
7913
7914
7915void csrReleaseScanCommand(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
7916{
7917 eCsrScanReason reason = pCommand->u.scanCmd.reason;
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307918 tANI_BOOLEAN status;
7919
7920 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07007921 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307922 tANI_U32 i;
7923 for(i = 0; i < CSR_ROAM_SESSION_MAX; i++)
Abhishek Singhf52182c2016-08-24 11:15:23 +05307924 csrRoamStateChange(pMac,
7925 pMac->roam.prev_state[i], i);
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307926 }
7927 else
7928 {
7929 csrRoamStateChange(pMac,
Abhishek Singhf52182c2016-08-24 11:15:23 +05307930 pMac->roam.prev_state[pCommand->sessionId],
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307931 pCommand->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07007932 }
7933
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307934 csrScanCallCallback(pMac, pCommand, scanStatus);
Jeff Johnson295189b2012-06-20 16:38:30 -07007935
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007936 smsLog(pMac, LOG3, " Remove Scan command reason = %d", reason);
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307937 if (pMac->fScanOffload)
7938 {
7939 status = csrLLRemoveEntry(&pMac->sme.smeScanCmdActiveList,
7940 &pCommand->Link, LL_ACCESS_LOCK);
7941 }
7942 else
7943 {
7944 status = csrLLRemoveEntry(&pMac->sme.smeCmdActiveList,
7945 &pCommand->Link, LL_ACCESS_LOCK);
7946 }
7947
7948 if(status)
Jeff Johnson295189b2012-06-20 16:38:30 -07007949 {
7950 csrReleaseCommandScan( pMac, pCommand );
7951 }
7952 else
7953 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307954 smsLog(pMac, LOGE,
7955 " ********csrReleaseScanCommand cannot release command reason %d",
7956 pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07007957 }
7958}
7959
7960
7961eHalStatus csrScanGetPMKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
7962 tPmkidCandidateInfo *pPmkidList, tANI_U32 *pNumItems )
7963{
7964 eHalStatus status = eHAL_STATUS_SUCCESS;
7965 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
7966
Jeff Johnson32d95a32012-09-10 13:15:23 -07007967 if(!pSession)
7968 {
7969 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
7970 return eHAL_STATUS_FAILURE;
7971 }
7972
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007973 smsLog(pMac, LOGW, " pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07007974 csrResetPMKIDCandidateList(pMac, sessionId);
7975 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
7976 {
7977 tCsrScanResultFilter *pScanFilter;
7978 tCsrScanResultInfo *pScanResult;
7979 tScanResultHandle hBSSList;
7980 tANI_U32 nItems = *pNumItems;
7981
7982 *pNumItems = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05307983 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
7984 if ( NULL == pScanFilter )
7985 status = eHAL_STATUS_FAILURE;
7986 else
Jeff Johnson295189b2012-06-20 16:38:30 -07007987 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307988 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007989 //Here is the profile we need to connect to
7990 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
7991 if(HAL_STATUS_SUCCESS(status))
7992 {
7993 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
7994 if(HAL_STATUS_SUCCESS(status))
7995 {
7996 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumPmkidCandidate < nItems))
7997 {
7998 //NumPmkidCandidate adds up here
7999 csrProcessBSSDescForPMKIDList(pMac, &pScanResult->BssDescriptor,
8000 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
8001 }
8002 if(pSession->NumPmkidCandidate)
8003 {
8004 *pNumItems = pSession->NumPmkidCandidate;
Kiet Lam64c1b492013-07-12 13:56:44 +05308005 vos_mem_copy(pPmkidList, pSession->PmkidCandidateInfo,
8006 pSession->NumPmkidCandidate * sizeof(tPmkidCandidateInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07008007 }
8008 csrScanResultPurge(pMac, hBSSList);
8009 }//Have scan result
8010 csrFreeScanFilter(pMac, pScanFilter);
8011 }
Kiet Lam64c1b492013-07-12 13:56:44 +05308012 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07008013 }
8014 }
8015
8016 return (status);
8017}
8018
8019
8020
8021#ifdef FEATURE_WLAN_WAPI
8022eHalStatus csrScanGetBKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
8023 tBkidCandidateInfo *pBkidList, tANI_U32 *pNumItems )
8024{
8025 eHalStatus status = eHAL_STATUS_SUCCESS;
8026 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
8027
Jeff Johnson32d95a32012-09-10 13:15:23 -07008028 if(!pSession)
8029 {
8030 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
8031 return eHAL_STATUS_FAILURE;
8032 }
8033
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008034 smsLog(pMac, LOGW, " pMac->scan.NumBkidCandidate = %d", pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07008035 csrResetBKIDCandidateList(pMac, sessionId);
8036 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
8037 {
8038 tCsrScanResultFilter *pScanFilter;
8039 tCsrScanResultInfo *pScanResult;
8040 tScanResultHandle hBSSList;
8041 tANI_U32 nItems = *pNumItems;
8042 *pNumItems = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05308043 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
8044 if ( NULL == pScanFilter )
8045 status = eHAL_STATUS_FAILURE;
8046 else
Jeff Johnson295189b2012-06-20 16:38:30 -07008047 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308048 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008049 //Here is the profile we need to connect to
8050 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
8051 if(HAL_STATUS_SUCCESS(status))
8052 {
8053 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
8054 if(HAL_STATUS_SUCCESS(status))
8055 {
8056 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumBkidCandidate < nItems))
8057 {
8058 //pMac->scan.NumBkidCandidate adds up here
8059 csrProcessBSSDescForBKIDList(pMac, &pScanResult->BssDescriptor,
8060 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
8061
8062 }
8063 if(pSession->NumBkidCandidate)
8064 {
8065 *pNumItems = pSession->NumBkidCandidate;
Kiet Lam64c1b492013-07-12 13:56:44 +05308066 vos_mem_copy(pBkidList, pSession->BkidCandidateInfo, pSession->NumBkidCandidate * sizeof(tBkidCandidateInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07008067 }
8068 csrScanResultPurge(pMac, hBSSList);
8069 }//Have scan result
8070 }
Kiet Lam64c1b492013-07-12 13:56:44 +05308071 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07008072 }
8073 }
8074
8075 return (status);
8076}
8077#endif /* FEATURE_WLAN_WAPI */
8078
Selvaraj, Sridhar32417ed2016-06-22 15:19:12 +05308079/**
8080 * csr_scan_request_set_chan_time() - Populate max and min
8081 * channel time in Scan request
8082 * @pMac - pointer to mac context
8083 * @pScanCmd - pointer to the Scan command
8084 *
8085 * Return - None
8086 */
8087#ifndef QCA_WIFI_ISOC
8088static void csr_scan_request_set_chan_time(tpAniSirGlobal pMac,
8089 tSmeCmd *pScanCmd)
8090{
8091 if (pMac->roam.neighborRoamInfo.handoffReqInfo.src
8092 == FASTREASSOC) {
8093 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime
8094 = MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL_FASTREASSOC;
8095 pScanCmd->u.scanCmd.u.scanRequest.minChnTime
8096 = MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL_FASTREASSOC;
8097 pMac->roam.neighborRoamInfo.handoffReqInfo.src = 0;
8098 } else {
8099 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime
8100 = MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL;
8101 pScanCmd->u.scanCmd.u.scanRequest.minChnTime
8102 = MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL;
8103 }
8104}
8105#else
8106static void csr_scan_request_set_chan_time(tpAniSirGlobal pMac,
8107 tSmeCmd *pScanCmd)
8108{
8109 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime
8110 = MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL;
8111 pScanCmd->u.scanCmd.u.scanRequest.minChnTime
8112 = MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL;
8113}
8114#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07008115
Kapil Guptac46b7542016-10-25 13:03:20 +05308116/**
8117 * csr_ssid_scan_done_callback() - Callback to indicate
8118 * scan is done for ssid scan
8119 * @halHandle: handle to hal
8120 * @context: SSID scan context
8121 * @scanId: Scan id for the scheduled scan
8122 * @status: scan done status
8123 *
8124 * Return - eHalStatus
8125 */
8126static eHalStatus csr_ssid_scan_done_callback(tHalHandle halHandle,
8127 void *context,
8128 tANI_U32 scanId,
8129 eCsrScanStatus status)
8130{
8131 struct csr_scan_for_ssid_context *scan_context =
8132 (struct csr_scan_for_ssid_context *)context;
8133
Sreelakshmi Konamki5e329602016-11-21 12:02:44 +05308134 if (NULL == scan_context) {
Kapil Guptac46b7542016-10-25 13:03:20 +05308135 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR,
8136 FL("scan for ssid context not found"));
Sreelakshmi Konamki5e329602016-11-21 12:02:44 +05308137 return eHAL_STATUS_FAILURE;
8138 }
Kapil Guptac46b7542016-10-25 13:03:20 +05308139
8140 if (eCSR_SCAN_ABORT == status)
8141 csrRoamCallCallback(scan_context->pMac, scan_context->sessionId,
8142 NULL, scan_context->roamId,
8143 eCSR_ROAM_ASSOCIATION_FAILURE,
8144 eCSR_ROAM_RESULT_SCAN_FOR_SSID_FAILURE);
8145 vos_mem_free(scan_context);
8146 return eHAL_STATUS_SUCCESS;
8147}
8148
Jeff Johnson295189b2012-06-20 16:38:30 -07008149//This function is usually used for BSSs that suppresses SSID so the profile
8150//shall have one and only one SSID
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008151eHalStatus csrScanForSSID(tpAniSirGlobal pMac, tANI_U32 sessionId, tCsrRoamProfile *pProfile, tANI_U32 roamId, tANI_BOOLEAN notify)
Jeff Johnson295189b2012-06-20 16:38:30 -07008152{
8153 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
8154 tSmeCmd *pScanCmd = NULL;
8155 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
8156 tANI_U8 index = 0;
8157 tANI_U32 numSsid = pProfile->SSIDs.numOfSSIDs;
Kapil Guptac46b7542016-10-25 13:03:20 +05308158 struct csr_scan_for_ssid_context *context;
Jeff Johnson295189b2012-06-20 16:38:30 -07008159
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008160 smsLog(pMac, LOG2, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07008161 //For WDS, we use the index 0. There must be at least one in there
8162 if( CSR_IS_WDS_STA( pProfile ) && numSsid )
8163 {
8164 numSsid = 1;
8165 }
8166 if(pMac->scan.fScanEnable && ( numSsid == 1 ) )
8167 {
8168 do
8169 {
8170 pScanCmd = csrGetCommandBuffer(pMac);
8171 if(!pScanCmd)
8172 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008173 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07008174 break;
8175 }
Kiet Lam64c1b492013-07-12 13:56:44 +05308176 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
8177 pScanCmd->u.scanCmd.pToRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
8178 if ( NULL == pScanCmd->u.scanCmd.pToRoamProfile )
krunal soni587bf012014-02-04 12:35:11 -08008179 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308180 status = eHAL_STATUS_FAILURE;
krunal soni587bf012014-02-04 12:35:11 -08008181 }
Kiet Lam64c1b492013-07-12 13:56:44 +05308182 else
krunal soni587bf012014-02-04 12:35:11 -08008183 {
8184 status = csrRoamCopyProfile(pMac, pScanCmd->u.scanCmd.pToRoamProfile, pProfile);
8185 }
Kapil Guptac46b7542016-10-25 13:03:20 +05308186 context = vos_mem_malloc(sizeof(*context));
8187 if (NULL == context)
8188 {
8189 smsLog(pMac, LOGE,
8190 "Failed to allocate memory for ssid scan context");
8191 status = eHAL_STATUS_FAILED_ALLOC;
8192 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008193 if(!HAL_STATUS_SUCCESS(status))
8194 break;
Kapil Guptac46b7542016-10-25 13:03:20 +05308195 context->pMac = pMac;
8196 context->sessionId = sessionId;
8197 context->roamId = roamId;
Jeff Johnson295189b2012-06-20 16:38:30 -07008198 pScanCmd->u.scanCmd.roamId = roamId;
8199 pScanCmd->command = eSmeCommandScan;
Jeff Johnsone7245742012-09-05 17:12:55 -07008200 pScanCmd->sessionId = (tANI_U8)sessionId;
Kapil Guptac46b7542016-10-25 13:03:20 +05308201 pScanCmd->u.scanCmd.callback = csr_ssid_scan_done_callback;
8202 pScanCmd->u.scanCmd.pContext = context;
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008203 pScanCmd->u.scanCmd.reason = eCsrScanForSsid;//Need to check: might need a new reason for SSID scan for LFR during multisession with p2p
Jeff Johnson295189b2012-06-20 16:38:30 -07008204 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Kiet Lam64c1b492013-07-12 13:56:44 +05308205 vos_mem_set(&pScanCmd->u.scanCmd.u.scanRequest, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008206 pScanCmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Jeff Johnson295189b2012-06-20 16:38:30 -07008207 pScanCmd->u.scanCmd.u.scanRequest.BSSType = pProfile->BSSType;
Jeff Johnsone7245742012-09-05 17:12:55 -07008208 // To avoid 11b rate in probe request Set p2pSearch flag as 1 for P2P Client Mode
8209 if(VOS_P2P_CLIENT_MODE == pProfile->csrPersona)
8210 {
8211 pScanCmd->u.scanCmd.u.scanRequest.p2pSearch = 1;
8212 }
Agarwal Ashish4f616132013-12-30 23:32:50 +05308213 if(pProfile->nAddIEScanLength)
Jeff Johnsone7245742012-09-05 17:12:55 -07008214 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308215 pScanCmd->u.scanCmd.u.scanRequest.pIEField = vos_mem_malloc(
8216 pProfile->nAddIEScanLength);
8217 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.pIEField )
8218 status = eHAL_STATUS_FAILURE;
8219 else
8220 status = eHAL_STATUS_SUCCESS;
8221 vos_mem_set(pScanCmd->u.scanCmd.u.scanRequest.pIEField,
8222 pProfile->nAddIEScanLength, 0);
8223 if (HAL_STATUS_SUCCESS(status))
Jeff Johnsone7245742012-09-05 17:12:55 -07008224 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308225 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.pIEField,
Agarwal Ashish4f616132013-12-30 23:32:50 +05308226 pProfile->addIEScan, pProfile->nAddIEScanLength);
Jeff Johnsone7245742012-09-05 17:12:55 -07008227 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = pProfile->nAddIEScanLength;
8228 }
8229 else
8230 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008231 smsLog(pMac, LOGE, "No memory for scanning IE fields");
Jeff Johnsone7245742012-09-05 17:12:55 -07008232 }
8233 } //Allocate memory for IE field
8234 else
8235 {
8236 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = 0;
8237 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07008238 /* For one channel be good enpugh time to receive beacon atleast */
8239 if( 1 == pProfile->ChannelInfo.numOfChannels )
8240 {
Selvaraj, Sridhar32417ed2016-06-22 15:19:12 +05308241 csr_scan_request_set_chan_time(pMac, pScanCmd);
8242 } else {
Kiet Lam64c1b492013-07-12 13:56:44 +05308243 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime =
8244 pMac->roam.configParam.nActiveMaxChnTime;
8245 pScanCmd->u.scanCmd.u.scanRequest.minChnTime =
8246 pMac->roam.configParam.nActiveMinChnTime;
Jeff Johnson32d95a32012-09-10 13:15:23 -07008247 }
Abhishek Singhadd13582016-09-29 17:00:03 +05308248 pScanCmd->u.scanCmd.u.scanRequest.max_chntime_btc_esco =
8249 pMac->roam.configParam.max_chntime_btc_esco;
8250 pScanCmd->u.scanCmd.u.scanRequest.min_chntime_btc_esco =
8251 pMac->roam.configParam.min_chntime_btc_esco;
Jeff Johnson295189b2012-06-20 16:38:30 -07008252 if(pProfile->BSSIDs.numOfBSSIDs == 1)
8253 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308254 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.bssid,
8255 pProfile->BSSIDs.bssid, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07008256 }
8257 else
8258 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308259 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.bssid, bAddr, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07008260 }
8261 if(pProfile->ChannelInfo.numOfChannels)
8262 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308263 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(
8264 sizeof(*pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
8265 * pProfile->ChannelInfo.numOfChannels);
8266 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
8267 status = eHAL_STATUS_FAILURE;
8268 else
8269 status = eHAL_STATUS_SUCCESS;
8270 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
8271 if(HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07008272 {
8273 csrRoamIsChannelValid(pMac, pProfile->ChannelInfo.ChannelList[0]);
8274 for(index = 0; index < pProfile->ChannelInfo.numOfChannels; index++)
8275 {
8276 if(csrRoamIsValidChannel(pMac, pProfile->ChannelInfo.ChannelList[index]))
8277 {
8278 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels]
8279 = pProfile->ChannelInfo.ChannelList[index];
8280 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels++;
8281 }
8282 else
8283 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008284 smsLog(pMac, LOGW, FL("process a channel (%d) that is invalid"), pProfile->ChannelInfo.ChannelList[index]);
Jeff Johnson295189b2012-06-20 16:38:30 -07008285 }
8286
8287 }
8288 }
8289 else
8290 {
8291 break;
8292 }
8293
8294 }
8295 else
8296 {
8297 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
8298 }
8299 if(pProfile->SSIDs.numOfSSIDs)
8300 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308301 pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList = vos_mem_malloc(
8302 pProfile->SSIDs.numOfSSIDs * sizeof(tCsrSSIDInfo));
8303 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList )
8304 status = eHAL_STATUS_FAILURE;
8305 else
8306 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07008307 if(!HAL_STATUS_SUCCESS(status))
8308 {
8309 break;
8310 }
8311 pScanCmd->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 1;
Kiet Lam64c1b492013-07-12 13:56:44 +05308312 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList,
8313 pProfile->SSIDs.SSIDList, sizeof(tCsrSSIDInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07008314 }
8315 //Start process the command
8316 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
8317 if( !HAL_STATUS_SUCCESS( status ) )
8318 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008319 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07008320 break;
8321 }
8322 }while(0);
8323 if(!HAL_STATUS_SUCCESS(status))
8324 {
8325 if(pScanCmd)
8326 {
8327 csrReleaseCommandScan(pMac, pScanCmd);
8328 //TODO:free the memory that is allocated in this function
8329 }
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008330 if(notify)
8331 {
Jeff Johnson295189b2012-06-20 16:38:30 -07008332 csrRoamCallCallback(pMac, sessionId, NULL, roamId, eCSR_ROAM_FAILED, eCSR_ROAM_RESULT_FAILURE);
8333 }
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008334 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008335 }//valid
8336 else
8337 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008338 smsLog(pMac, LOGE, FL("cannot scan because scanEnable (%d) or numSSID (%d) is invalid"),
Jeff Johnson295189b2012-06-20 16:38:30 -07008339 pMac->scan.fScanEnable, pProfile->SSIDs.numOfSSIDs);
8340 }
8341
8342 return (status);
8343}
8344
8345
8346//Issue a scan base on the new capability infomation
8347//This should only happen when the associated AP changes its capability.
8348//After this scan is done, CSR reroams base on the new scan results
8349eHalStatus csrScanForCapabilityChange(tpAniSirGlobal pMac, tSirSmeApNewCaps *pNewCaps)
8350{
8351 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
8352 tSmeCmd *pScanCmd = NULL;
8353
8354 if(pNewCaps)
8355 {
8356 do
8357 {
8358 pScanCmd = csrGetCommandBuffer(pMac);
8359 if(!pScanCmd)
8360 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008361 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07008362 status = eHAL_STATUS_RESOURCES;
8363 break;
8364 }
Kiet Lam64c1b492013-07-12 13:56:44 +05308365 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008366 status = eHAL_STATUS_SUCCESS;
8367 pScanCmd->u.scanCmd.roamId = 0;
8368 pScanCmd->command = eSmeCommandScan;
8369 pScanCmd->u.scanCmd.callback = NULL;
8370 pScanCmd->u.scanCmd.pContext = NULL;
8371 pScanCmd->u.scanCmd.reason = eCsrScanForCapsChange;
8372 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
8373 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
8374 if( !HAL_STATUS_SUCCESS( status ) )
8375 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008376 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07008377 break;
8378 }
8379 }while(0);
8380 if(!HAL_STATUS_SUCCESS(status))
8381 {
8382 if(pScanCmd)
8383 {
8384 csrReleaseCommandScan(pMac, pScanCmd);
8385 }
8386 }
8387 }
8388
8389 return (status);
8390}
8391
8392
8393
8394void csrInitBGScanChannelList(tpAniSirGlobal pMac)
8395{
8396 tANI_U32 len = CSR_MIN(sizeof(pMac->roam.validChannelList), sizeof(pMac->scan.bgScanChannelList));
8397
Kiet Lam64c1b492013-07-12 13:56:44 +05308398 vos_mem_set(pMac->scan.bgScanChannelList, len, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008399 pMac->scan.numBGScanChannel = 0;
8400
8401 if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
8402 {
8403 pMac->roam.numValidChannels = len;
8404 pMac->scan.numBGScanChannel = (tANI_U8)CSR_MIN(len, WNI_CFG_BG_SCAN_CHANNEL_LIST_LEN);
Kiet Lam64c1b492013-07-12 13:56:44 +05308405 vos_mem_copy(pMac->scan.bgScanChannelList, pMac->roam.validChannelList,
8406 pMac->scan.numBGScanChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07008407 csrSetBGScanChannelList(pMac, pMac->scan.bgScanChannelList, pMac->scan.numBGScanChannel);
8408 }
8409}
8410
8411
8412//This function return TRUE if background scan channel list is adjusted.
8413//this function will only shrink the background scan channel list
8414tANI_BOOLEAN csrAdjustBGScanChannelList(tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels,
8415 tANI_U8 *pAdjustChannels, tANI_U8 *pNumAdjustChannels)
8416{
8417 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
8418 tANI_U8 i, j, count = *pNumAdjustChannels;
8419
8420 i = 0;
8421 while(i < count)
8422 {
8423 for(j = 0; j < NumChannels; j++)
8424 {
8425 if(pChannelList[j] == pAdjustChannels[i])
8426 break;
8427 }
8428 if(j == NumChannels)
8429 {
8430 //This channel is not in the list, remove it
8431 fRet = eANI_BOOLEAN_TRUE;
8432 count--;
8433 if(count - i)
8434 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308435 vos_mem_copy(&pAdjustChannels[i], &pAdjustChannels[i+1], count - i);
Jeff Johnson295189b2012-06-20 16:38:30 -07008436 }
8437 else
8438 {
8439 //already remove the last one. Done.
8440 break;
8441 }
8442 }
8443 else
8444 {
8445 i++;
8446 }
8447 }//while(i<count)
8448 *pNumAdjustChannels = count;
8449
8450 return (fRet);
8451}
8452
8453
8454//Get the list of the base channels to scan for passively 11d info
8455eHalStatus csrScanGetSupportedChannels( tpAniSirGlobal pMac )
8456{
8457 eHalStatus status = eHAL_STATUS_SUCCESS;
8458 int n = WNI_CFG_VALID_CHANNEL_LIST_LEN;
8459
8460 status = vos_nv_getSupportedChannels( pMac->scan.baseChannels.channelList, &n, NULL, NULL );
8461 if( HAL_STATUS_SUCCESS(status) )
8462 {
8463 pMac->scan.baseChannels.numChannels = (tANI_U8)n;
8464 }
8465 else
8466 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008467 smsLog( pMac, LOGE, FL(" failed") );
Jeff Johnson295189b2012-06-20 16:38:30 -07008468 pMac->scan.baseChannels.numChannels = 0;
8469 }
8470
8471 return ( status );
8472}
8473
8474//This function use the input pChannelList to validate the current saved channel list
8475eHalStatus csrSetBGScanChannelList( tpAniSirGlobal pMac, tANI_U8 *pAdjustChannels, tANI_U8 NumAdjustChannels)
8476{
8477 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumAdjustChannels;
8478
8479 return (ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pAdjustChannels, dataLen, NULL, eANI_BOOLEAN_FALSE));
8480}
8481
8482
8483void csrSetCfgValidChannelList( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels )
8484{
8485 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumChannels;
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05308486 eHalStatus status;
Jeff Johnson295189b2012-06-20 16:38:30 -07008487
Mihir Shete31c435d2014-02-12 13:13:34 +05308488 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
8489 "%s: dump valid channel list(NumChannels(%d))",
8490 __func__,NumChannels);
8491 VOS_TRACE_HEX_DUMP(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
8492 pChannelList, NumChannels);
8493
Jeff Johnson295189b2012-06-20 16:38:30 -07008494 ccmCfgSetStr(pMac, WNI_CFG_VALID_CHANNEL_LIST, pChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
Leela Venkata Kiran Kumar Reddy Chiralac6663f72014-02-03 21:04:58 -08008495#ifdef QCA_WIFI_2_0
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05308496 if (pMac->fScanOffload)
8497 {
8498 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
8499 "Scan offload is enabled, update default chan list");
Leela Venkata Kiran Kumar Reddy Chiralac6663f72014-02-03 21:04:58 -08008500 status = csrUpdateChannelList(pMac);
8501 }
8502#else
8503 status = csrUpdateChannelList(pMac);
8504#endif
8505
8506 if (eHAL_STATUS_SUCCESS != status)
8507 {
8508 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR,
8509 "failed to update the supported channel list");
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05308510 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008511 return;
8512}
8513
8514
8515
8516/*
8517 * The Tx power limits are saved in the cfg for future usage.
8518 */
8519void csrSaveTxPowerToCfg( tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 cfgId )
8520{
8521 tListElem *pEntry;
8522 tANI_U32 cbLen = 0, dataLen;
8523 tCsrChannelPowerInfo *pChannelSet;
8524 tANI_U32 idx;
8525 tSirMacChanInfo *pChannelPowerSet;
8526 tANI_U8 *pBuf = NULL;
8527
8528 //allocate maximum space for all channels
8529 dataLen = WNI_CFG_VALID_CHANNEL_LIST_LEN * sizeof(tSirMacChanInfo);
Kiet Lam64c1b492013-07-12 13:56:44 +05308530 if ( (pBuf = vos_mem_malloc(dataLen)) != NULL )
Jeff Johnson295189b2012-06-20 16:38:30 -07008531 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308532 vos_mem_set(pBuf, dataLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008533 pChannelPowerSet = (tSirMacChanInfo *)(pBuf);
8534
8535 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
8536 // write the tuples (startChan, numChan, txPower) for each channel found in the channel power list.
8537 while( pEntry )
8538 {
8539 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
8540 if ( 1 != pChannelSet->interChannelOffset )
8541 {
8542 // we keep the 5G channel sets internally with an interchannel offset of 4. Expand these
8543 // to the right format... (inter channel offset of 1 is the only option for the triplets
8544 // that 11d advertises.
8545 if ((cbLen + (pChannelSet->numChannels * sizeof(tSirMacChanInfo))) >= dataLen)
8546 {
8547 // expanding this entry will overflow our allocation
8548 smsLog(pMac, LOGE,
8549 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07008550 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07008551 pChannelSet->firstChannel,
8552 pChannelSet->numChannels,
8553 pChannelSet->interChannelOffset);
8554 break;
8555 }
8556
8557 for( idx = 0; idx < pChannelSet->numChannels; idx++ )
8558 {
8559 pChannelPowerSet->firstChanNum = (tSirMacChanNum)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008560 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07008561 pChannelPowerSet->numChannels = 1;
Jeff Johnson295189b2012-06-20 16:38:30 -07008562 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008563 smsLog(pMac, LOG3, " Setting Max Transmit Power %d", pChannelPowerSet->maxTxPower);
Jeff Johnson295189b2012-06-20 16:38:30 -07008564 cbLen += sizeof( tSirMacChanInfo );
8565 pChannelPowerSet++;
8566 }
8567 }
8568 else
8569 {
8570 if (cbLen >= dataLen)
8571 {
8572 // this entry will overflow our allocation
8573 smsLog(pMac, LOGE,
8574 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07008575 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07008576 pChannelSet->firstChannel,
8577 pChannelSet->numChannels,
8578 pChannelSet->interChannelOffset);
8579 break;
8580 }
8581 pChannelPowerSet->firstChanNum = pChannelSet->firstChannel;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008582 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07008583 pChannelPowerSet->numChannels = pChannelSet->numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -07008584 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008585 smsLog(pMac, LOG3, " Setting Max Transmit Power %d, nTxPower %d", pChannelPowerSet->maxTxPower,pMac->roam.configParam.nTxPowerCap );
Jeff Johnson295189b2012-06-20 16:38:30 -07008586
8587
8588 cbLen += sizeof( tSirMacChanInfo );
8589 pChannelPowerSet++;
8590 }
8591
8592 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
8593 }
8594
8595 if(cbLen)
8596 {
8597 ccmCfgSetStr(pMac, cfgId, (tANI_U8 *)pBuf, cbLen, NULL, eANI_BOOLEAN_FALSE);
8598 }
Kiet Lam64c1b492013-07-12 13:56:44 +05308599 vos_mem_free(pBuf);
Jeff Johnson295189b2012-06-20 16:38:30 -07008600 }//Allocate memory
8601}
8602
8603
8604void csrSetCfgCountryCode( tpAniSirGlobal pMac, tANI_U8 *countryCode )
8605{
8606 tANI_U8 cc[WNI_CFG_COUNTRY_CODE_LEN];
8607 ///v_REGDOMAIN_t DomainId;
8608
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008609 smsLog( pMac, LOG3, "Setting Country Code in Cfg from csrSetCfgCountryCode %s",countryCode );
Kiet Lam64c1b492013-07-12 13:56:44 +05308610 vos_mem_copy(cc, countryCode, WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07008611
8612 // don't program the bogus country codes that we created for Korea in the MAC. if we see
8613 // the bogus country codes, program the MAC with the right country code.
8614 if ( ( 'K' == countryCode[ 0 ] && '1' == countryCode[ 1 ] ) ||
8615 ( 'K' == countryCode[ 0 ] && '2' == countryCode[ 1 ] ) ||
8616 ( 'K' == countryCode[ 0 ] && '3' == countryCode[ 1 ] ) ||
8617 ( 'K' == countryCode[ 0 ] && '4' == countryCode[ 1 ] ) )
8618 {
8619 // replace the alternate Korea country codes, 'K1', 'K2', .. with 'KR' for Korea
8620 cc[ 1 ] = 'R';
8621 }
8622 ccmCfgSetStr(pMac, WNI_CFG_COUNTRY_CODE, cc, WNI_CFG_COUNTRY_CODE_LEN, NULL, eANI_BOOLEAN_FALSE);
8623
8624 //Need to let HALPHY know about the current domain so it can apply some
8625 //domain-specific settings (TX filter...)
8626 /*if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(pMac, cc, &DomainId)))
8627 {
8628 halPhySetRegDomain(pMac, DomainId);
8629 }*/
8630}
8631
8632
8633
8634eHalStatus csrGetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pBuf, tANI_U8 *pbLen)
8635{
8636 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
8637 tANI_U32 len;
8638
8639 if(pBuf && pbLen && (*pbLen >= WNI_CFG_COUNTRY_CODE_LEN))
8640 {
8641 len = *pbLen;
8642 status = ccmCfgGetStr(pMac, WNI_CFG_COUNTRY_CODE, pBuf, &len);
8643 if(HAL_STATUS_SUCCESS(status))
8644 {
8645 *pbLen = (tANI_U8)len;
8646 }
8647 }
8648
8649 return (status);
8650}
8651
8652
8653void csrSetCfgScanControlList( tpAniSirGlobal pMac, tANI_U8 *countryCode, tCsrChannel *pChannelList )
8654{
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05308655 tANI_U8 i, j, k;
Jeff Johnson295189b2012-06-20 16:38:30 -07008656 tANI_BOOLEAN found=FALSE;
8657 tANI_U8 *pControlList = NULL;
8658 tANI_U32 len = WNI_CFG_SCAN_CONTROL_LIST_LEN;
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05308659 tANI_U8 cfgActiveDFSChannels = 0;
8660 tANI_U8 *cfgActiveDFSChannelLIst = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07008661
Kiet Lam64c1b492013-07-12 13:56:44 +05308662 if ( (pControlList = vos_mem_malloc(WNI_CFG_SCAN_CONTROL_LIST_LEN)) != NULL )
Jeff Johnson295189b2012-06-20 16:38:30 -07008663 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308664 vos_mem_set((void *)pControlList, WNI_CFG_SCAN_CONTROL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008665 if(HAL_STATUS_SUCCESS(ccmCfgGetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, &len)))
8666 {
8667 for (i = 0; i < pChannelList->numChannels; i++)
8668 {
8669 for (j = 0; j < len; j += 2)
8670 {
8671 if (pControlList[j] == pChannelList->channelList[i])
8672 {
8673 found = TRUE;
8674 break;
8675 }
8676 }
8677
8678 if (found) // insert a pair(channel#, flag)
8679 {
Gopichand Nakkala392cbc12013-05-28 16:15:00 +05308680 pControlList[j+1] = csrGetScanType(pMac, pControlList[j]);
Jeff Johnson295189b2012-06-20 16:38:30 -07008681 found = FALSE; // reset the flag
Jeff Johnson295189b2012-06-20 16:38:30 -07008682
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05308683 // When DFS mode is 2, mark static channels as active
8684 if (pMac->scan.fEnableDFSChnlScan ==
8685 DFS_CHNL_SCAN_ENABLED_ACTIVE)
8686 {
8687 cfgActiveDFSChannels =
8688 pMac->roam.neighborRoamInfo.cfgParams.
8689 channelInfo.numOfChannels;
8690 cfgActiveDFSChannelLIst =
8691 pMac->roam.neighborRoamInfo.cfgParams.
8692 channelInfo.ChannelList;
8693 if (cfgActiveDFSChannelLIst)
8694 {
8695 for (k=0; k < cfgActiveDFSChannels; k++)
8696 {
8697 if(CSR_IS_CHANNEL_DFS(cfgActiveDFSChannelLIst[k])
8698 && (pControlList[j] ==
8699 cfgActiveDFSChannelLIst[k]))
8700 {
8701 pControlList[j+1] = eSIR_ACTIVE_SCAN;
8702 smsLog(pMac, LOG1, FL("Marked DFS ch %d"
8703 " as active"),
8704 cfgActiveDFSChannelLIst[k]);
8705 }
8706 }
8707 }
8708 }
8709 }
8710 }
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05308711 smsLog(pMac, LOG1, FL("fEnableDFSChnlScan %d"),
8712 pMac->scan.fEnableDFSChnlScan);
Mihir Shete31c435d2014-02-12 13:13:34 +05308713 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
8714 "%s: dump scan control list",__func__);
8715 VOS_TRACE_HEX_DUMP(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
8716 pControlList, len);
8717
Jeff Johnson295189b2012-06-20 16:38:30 -07008718 ccmCfgSetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, len, NULL, eANI_BOOLEAN_FALSE);
8719 }//Successfully getting scan control list
Kiet Lam64c1b492013-07-12 13:56:44 +05308720 vos_mem_free(pControlList);
Jeff Johnson295189b2012-06-20 16:38:30 -07008721 }//AllocateMemory
Abhishek Singh6fcdf652016-11-23 10:59:12 +05308722
8723 /* Send msg to Lim to clear DFS channel list */
8724 smsLog(pMac, LOG1, FL("csrClearDfsChannelList"));
8725 csrClearDfsChannelList(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07008726}
8727
Jeff Johnson295189b2012-06-20 16:38:30 -07008728//if bgPeriod is 0, background scan is disabled. It is in millisecond units
8729eHalStatus csrSetCfgBackgroundScanPeriod(tpAniSirGlobal pMac, tANI_U32 bgPeriod)
8730{
8731 return (ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, bgPeriod, (tCcmCfgSetCallback) csrScanCcmCfgSetCallback, eANI_BOOLEAN_FALSE));
8732}
8733
8734
8735void csrScanCcmCfgSetCallback(tHalHandle hHal, tANI_S32 result)
8736{
8737 tListElem *pEntry = NULL;
8738 tSmeCmd *pCommand = NULL;
8739 tpAniSirGlobal pMac = PMAC_STRUCT( hHal );
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05308740 tDblLinkList *pCmdList ;
8741
8742 if (!pMac->fScanOffload)
8743 pCmdList = &pMac->sme.smeCmdActiveList;
8744 else
8745 pCmdList = &pMac->sme.smeScanCmdActiveList;
8746
8747 pEntry = csrLLPeekHead( pCmdList, LL_ACCESS_LOCK );
Jeff Johnson295189b2012-06-20 16:38:30 -07008748 if ( pEntry )
8749 {
8750 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8751 if ( eSmeCommandScan == pCommand->command )
8752 {
8753 eCsrScanStatus scanStatus = (CCM_IS_RESULT_SUCCESS(result)) ? eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
8754 csrReleaseScanCommand(pMac, pCommand, scanStatus);
8755 }
8756 else
8757 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008758 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
Jeff Johnson295189b2012-06-20 16:38:30 -07008759 }
8760 }
8761 smeProcessPendingQueue( pMac );
8762}
8763
8764eHalStatus csrProcessSetBGScanParam(tpAniSirGlobal pMac, tSmeCmd *pCommand)
8765{
8766 eHalStatus status;
8767 tCsrBGScanRequest *pScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
8768 tANI_U32 dataLen = sizeof( tANI_U8 ) * pScanReq->ChannelInfo.numOfChannels;
8769
8770 //***setcfg for background scan channel list
8771 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MINIMUM_CHANNEL_TIME, pScanReq->minChnTime, NULL, eANI_BOOLEAN_FALSE);
8772 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MAXIMUM_CHANNEL_TIME, pScanReq->maxChnTime, NULL, eANI_BOOLEAN_FALSE);
8773 //Not set the background scan interval if not connected because bd scan should not be run if not connected
8774 if(!csrIsAllSessionDisconnected(pMac))
8775 {
Jeff Johnson295189b2012-06-20 16:38:30 -07008776
8777#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
8778 {
8779 vos_log_scan_pkt_type *pScanLog = NULL;
8780
8781 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
8782 if(pScanLog)
8783 {
8784 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
8785 pScanLog->minChnTime = (v_U8_t)pScanReq->minChnTime;
8786 pScanLog->maxChnTime = (v_U8_t)pScanReq->maxChnTime;
8787 pScanLog->timeBetweenBgScan = (v_U8_t)pScanReq->scanInterval;
8788 pScanLog->numChannel = pScanReq->ChannelInfo.numOfChannels;
8789 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
8790 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308791 vos_mem_copy(pScanLog->channels,
8792 pScanReq->ChannelInfo.ChannelList,
8793 pScanLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07008794 }
8795 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
8796 }
8797 }
8798#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
8799
8800 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, pScanReq->scanInterval, NULL, eANI_BOOLEAN_FALSE);
8801 }
8802 else
8803 {
8804 //No need to stop aging because IDLE scan is still running
8805 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, 0, NULL, eANI_BOOLEAN_FALSE);
8806 }
8807
8808 if(pScanReq->SSID.length > WNI_CFG_SSID_LEN)
8809 {
8810 pScanReq->SSID.length = WNI_CFG_SSID_LEN;
8811 }
8812
8813 status = ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pScanReq->ChannelInfo.ChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
8814 status = ccmCfgSetStr(pMac, WNI_CFG_SSID, (tANI_U8 *)pScanReq->SSID.ssId, pScanReq->SSID.length, NULL, eANI_BOOLEAN_FALSE);
8815
8816
8817
8818 return (status);
8819}
8820
8821
c_hpothua3d45d52015-01-05 14:11:17 +05308822tSirAbortScanStatus csrScanAbortMacScan(tpAniSirGlobal pMac,
8823 tANI_U8 sessionId,
8824 eCsrAbortReason reason)
Jeff Johnson295189b2012-06-20 16:38:30 -07008825{
c_hpothua3d45d52015-01-05 14:11:17 +05308826 tSirAbortScanStatus abortScanStatus = eSIR_ABORT_ACTIVE_SCAN_LIST_EMPTY;
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308827 tSirSmeScanAbortReq *pMsg;
Jeff Johnson295189b2012-06-20 16:38:30 -07008828 tANI_U16 msgLen;
8829 tListElem *pEntry;
8830 tSmeCmd *pCommand;
8831
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308832 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07008833 {
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308834#ifdef WLAN_AP_STA_CONCURRENCY
8835 csrLLLock(&pMac->scan.scanCmdPendingList);
8836 while(NULL !=
8837 (pEntry = csrLLRemoveHead(&pMac->scan.scanCmdPendingList,
8838 LL_ACCESS_NOLOCK)))
8839 {
Jeff Johnson295189b2012-06-20 16:38:30 -07008840
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308841 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8842 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
8843 }
8844 csrLLUnlock(&pMac->scan.scanCmdPendingList);
Jeff Johnson295189b2012-06-20 16:38:30 -07008845#endif
8846
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308847 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
8848 csrRemoveCmdFromPendingList( pMac, &pMac->roam.roamCmdPendingList, eSmeCommandScan);
8849 csrRemoveCmdFromPendingList( pMac, &pMac->sme.smeCmdPendingList, eSmeCommandScan);
8850 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
8851
8852 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
8853 }
8854 else
8855 {
8856 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
8857 csrRemoveCmdWithSessionIdFromPendingList(pMac,
8858 sessionId,
8859 &pMac->sme.smeScanCmdPendingList,
8860 eSmeCommandScan);
8861 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
8862
8863 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
8864 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008865
8866 //We need to abort scan only if we are scanning
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308867 if(NULL != pEntry)
Jeff Johnson295189b2012-06-20 16:38:30 -07008868 {
8869 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308870 if(eSmeCommandScan == pCommand->command &&
8871 pCommand->sessionId == sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07008872 {
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308873 msgLen = (tANI_U16)(sizeof(tSirSmeScanAbortReq));
Kiet Lam64c1b492013-07-12 13:56:44 +05308874 pMsg = vos_mem_malloc(msgLen);
8875 if ( NULL == pMsg )
Jeff Johnson295189b2012-06-20 16:38:30 -07008876 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308877 smsLog(pMac, LOGE, FL("Failed to allocate memory for SmeScanAbortReq"));
c_hpothua3d45d52015-01-05 14:11:17 +05308878 abortScanStatus = eSIR_ABORT_SCAN_FAILURE;
Kiet Lam64c1b492013-07-12 13:56:44 +05308879 }
8880 else
8881 {
Ratheesh S Pece1f832015-07-25 15:50:25 +05308882 pCommand->u.scanCmd.abortScanIndication = eCSR_SCAN_ABORT_DEFAULT;
Srinivas, Dasari187ca4e2014-02-07 12:40:09 +05308883 if(reason == eCSR_SCAN_ABORT_DUE_TO_BAND_CHANGE)
8884 {
Ratheesh S Pece1f832015-07-25 15:50:25 +05308885 pCommand->u.scanCmd.abortScanIndication
8886 = eCSR_SCAN_ABORT_DUE_TO_BAND_CHANGE;
Srinivas, Dasari187ca4e2014-02-07 12:40:09 +05308887 }
Kiet Lam64c1b492013-07-12 13:56:44 +05308888 vos_mem_set((void *)pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008889 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_ABORT_IND);
8890 pMsg->msgLen = pal_cpu_to_be16(msgLen);
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308891 pMsg->sessionId = sessionId;
c_hpothua3d45d52015-01-05 14:11:17 +05308892 if (eHAL_STATUS_SUCCESS != palSendMBMessage(pMac->hHdd, pMsg))
8893 {
8894 smsLog(pMac, LOGE,
8895 FL("Failed to post eWNI_SME_SCAN_ABORT_IND"));
8896 abortScanStatus = eSIR_ABORT_SCAN_FAILURE;
Ratheesh S Pece1f832015-07-25 15:50:25 +05308897 pCommand->u.scanCmd.abortScanIndication = 0;
c_hpothua3d45d52015-01-05 14:11:17 +05308898 }
8899 else
8900 {
8901 abortScanStatus = eSIR_ABORT_ACTIVE_SCAN_LIST_NOT_EMPTY;
8902 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008903 }
8904 }
8905 }
8906
c_hpothua3d45d52015-01-05 14:11:17 +05308907 return(abortScanStatus);
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308908}
8909
8910void csrRemoveCmdWithSessionIdFromPendingList(tpAniSirGlobal pMac,
8911 tANI_U8 sessionId,
8912 tDblLinkList *pList,
8913 eSmeCommandType commandType)
8914{
8915 tDblLinkList localList;
8916 tListElem *pEntry;
8917 tSmeCmd *pCommand;
8918 tListElem *pEntryToRemove;
8919
8920 vos_mem_zero(&localList, sizeof(tDblLinkList));
8921 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
8922 {
8923 smsLog(pMac, LOGE, FL(" failed to open list"));
8924 return;
8925 }
8926
8927 csrLLLock(pList);
8928 if ((pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK)))
8929 {
8930
8931 /* Have to make sure we don't loop back to the head of the list,
8932 * which will happen if the entry is NOT on the list */
8933 while (pEntry)
8934 {
8935 pEntryToRemove = pEntry;
8936 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
8937 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
8938 if ((pCommand->command == commandType) &&
8939 (pCommand->sessionId == sessionId))
8940 {
8941 /* Remove that entry only */
8942 if (csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
8943 {
8944 csrLLInsertTail(&localList, pEntryToRemove,
8945 LL_ACCESS_NOLOCK);
8946 }
8947 }
8948 }
8949 }
8950 csrLLUnlock(pList);
8951
8952 while ((pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)))
8953 {
8954 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
8955 csrAbortCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
8956 }
8957
8958 csrLLClose(&localList);
Jeff Johnson295189b2012-06-20 16:38:30 -07008959}
8960
8961void csrRemoveCmdFromPendingList(tpAniSirGlobal pMac, tDblLinkList *pList,
8962 eSmeCommandType commandType )
8963{
8964 tDblLinkList localList;
8965 tListElem *pEntry;
8966 tSmeCmd *pCommand;
8967 tListElem *pEntryToRemove;
8968
8969 vos_mem_zero(&localList, sizeof(tDblLinkList));
8970 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
8971 {
8972 smsLog(pMac, LOGE, FL(" failed to open list"));
8973 return;
8974 }
8975
8976 csrLLLock(pList);
8977 if( !csrLLIsListEmpty( pList, LL_ACCESS_NOLOCK ) )
8978 {
8979 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK);
8980
8981 // Have to make sure we don't loop back to the head of the list, which will
8982 // happen if the entry is NOT on the list...
8983 while( pEntry )
8984 {
8985 pEntryToRemove = pEntry;
8986 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
8987 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
8988 if ( pCommand->command == commandType )
8989 {
8990 // Remove that entry only
8991 if(csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
8992 {
8993 csrLLInsertTail(&localList, pEntryToRemove, LL_ACCESS_NOLOCK);
8994 }
8995 }
8996 }
8997
8998
8999 }
9000 csrLLUnlock(pList);
9001
9002 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
9003 {
9004 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
9005 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
9006 }
9007 csrLLClose(&localList);
9008
9009}
9010
Abhishek Singhdc2bfd42014-06-19 17:59:05 +05309011eHalStatus csrScanAbortScanForSSID(tpAniSirGlobal pMac, tANI_U32 sessionId)
9012{
9013 eHalStatus status = eHAL_STATUS_SUCCESS;
9014 tSirSmeScanAbortReq *pMsg;
9015 tANI_U16 msgLen;
9016 tListElem *pEntry;
9017 tSmeCmd *pCommand;
9018
9019 if (!pMac->fScanOffload)
9020 {
9021 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
9022#ifdef WLAN_AP_STA_CONCURRENCY
9023 csrRemoveScanForSSIDFromPendingList( pMac, &pMac->scan.scanCmdPendingList, sessionId);
9024#endif
9025 csrRemoveScanForSSIDFromPendingList( pMac, &pMac->roam.roamCmdPendingList, sessionId);
9026 csrRemoveScanForSSIDFromPendingList( pMac, &pMac->sme.smeCmdPendingList, sessionId);
9027 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
9028 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
9029 }
9030 else
9031 {
9032 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
9033 csrRemoveScanForSSIDFromPendingList( pMac, &pMac->sme.smeScanCmdPendingList, sessionId);
9034 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
9035 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
9036 }
9037
9038 if(NULL != pEntry)
9039 {
9040 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
9041
9042 if ( (eSmeCommandScan == pCommand->command ) &&
9043 (sessionId == pCommand->sessionId))
9044 {
9045 if ( eCsrScanForSsid == pCommand->u.scanCmd.reason)
9046 {
9047 msgLen = (tANI_U16)(sizeof( tSirSmeScanAbortReq ));
9048 pMsg = vos_mem_malloc(msgLen);
9049 if ( NULL == pMsg )
9050 {
9051 status = eHAL_STATUS_FAILURE;
9052 smsLog(pMac, LOGE, FL("Failed to allocate memory for SmeScanAbortReq"));
9053 }
9054 else
9055 {
9056 vos_mem_zero((void *)pMsg, msgLen);
9057 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_ABORT_IND);
9058 pMsg->msgLen = pal_cpu_to_be16(msgLen);
9059 pMsg->sessionId = sessionId;
9060 status = palSendMBMessage(pMac->hHdd, pMsg);
9061 }
9062 }
9063 }
9064 }
9065 return( status );
9066}
9067
9068void csrRemoveScanForSSIDFromPendingList(tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 sessionId)
9069{
9070 tDblLinkList localList;
9071 tListElem *pEntry;
9072 tSmeCmd *pCommand;
9073 tListElem *pEntryToRemove;
9074
9075 vos_mem_zero(&localList, sizeof(tDblLinkList));
9076 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
9077 {
9078 smsLog(pMac, LOGE, FL(" failed to open list"));
9079 return;
9080 }
9081
9082 csrLLLock(pList);
9083 if( !csrLLIsListEmpty( pList, LL_ACCESS_NOLOCK ) )
9084 {
9085 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK);
9086
9087 // Have to make sure we don't loop back to the head of the list, which will
9088 // happen if the entry is NOT on the list...
9089 while( pEntry )
9090 {
9091 pEntryToRemove = pEntry;
9092 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
9093 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
9094 if ( (eSmeCommandScan == pCommand->command ) &&
9095 (sessionId == pCommand->sessionId) )
9096 {
9097 if ( eCsrScanForSsid == pCommand->u.scanCmd.reason)
9098 {
9099 // Remove that entry only
9100 if ( csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
9101 {
9102 csrLLInsertTail(&localList, pEntryToRemove, LL_ACCESS_NOLOCK);
9103 }
9104 }
9105 }
9106 }
9107 }
9108 csrLLUnlock(pList);
9109
9110 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
9111 {
9112 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
9113 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
9114 }
9115 csrLLClose(&localList);
9116}
Jeff Johnson295189b2012-06-20 16:38:30 -07009117
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05309118eHalStatus csrScanAbortMacScanNotForConnect(tpAniSirGlobal pMac,
9119 tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07009120{
9121 eHalStatus status = eHAL_STATUS_SUCCESS;
9122
9123 if( !csrIsScanForRoamCommandActive( pMac ) )
9124 {
9125 //Only abort the scan if it is not used for other roam/connect purpose
c_hpothua3d45d52015-01-05 14:11:17 +05309126 if (eSIR_ABORT_SCAN_FAILURE ==
9127 csrScanAbortMacScan(pMac, sessionId, eCSR_SCAN_ABORT_DEFAULT))
9128 {
9129 smsLog(pMac, LOGE, FL("fail to abort scan"));
9130 status = eHAL_STATUS_FAILURE;
9131 }
Jeff Johnson295189b2012-06-20 16:38:30 -07009132 }
9133
9134 return (status);
9135}
9136
9137
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05309138eHalStatus csrScanGetScanChannelInfo(tpAniSirGlobal pMac, tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07009139{
9140 eHalStatus status = eHAL_STATUS_SUCCESS;
9141 tSirMbMsg *pMsg;
9142 tANI_U16 msgLen;
9143
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05309144 if (pMac->fScanOffload)
9145 msgLen = (tANI_U16)(sizeof(tSirSmeGetScanChanReq));
9146 else
9147 msgLen = (tANI_U16)(sizeof(tSirMbMsg));
9148
Kiet Lam64c1b492013-07-12 13:56:44 +05309149 pMsg = vos_mem_malloc(msgLen);
9150 if ( NULL == pMsg )
9151 status = eHAL_STATUS_FAILURE;
9152 else
Jeff Johnson295189b2012-06-20 16:38:30 -07009153 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309154 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07009155 pMsg->type = eWNI_SME_GET_SCANNED_CHANNEL_REQ;
9156 pMsg->msgLen = msgLen;
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05309157 if (pMac->fScanOffload)
9158 ((tSirSmeGetScanChanReq *)pMsg)->sessionId = sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07009159 status = palSendMBMessage(pMac->hHdd, pMsg);
9160 }
9161
9162 return( status );
9163}
9164
9165tANI_BOOLEAN csrRoamIsValidChannel( tpAniSirGlobal pMac, tANI_U8 channel )
9166{
9167 tANI_BOOLEAN fValid = FALSE;
9168 tANI_U32 idxValidChannels;
9169 tANI_U32 len = pMac->roam.numValidChannels;
9170
9171 for ( idxValidChannels = 0; ( idxValidChannels < len ); idxValidChannels++ )
9172 {
9173 if ( channel == pMac->roam.validChannelList[ idxValidChannels ] )
9174 {
9175 fValid = TRUE;
9176 break;
9177 }
9178 }
9179
9180 return fValid;
9181}
9182
Manjunathappa Prakash4f1d5a52013-11-11 16:22:19 -08009183#ifdef FEATURE_WLAN_SCAN_PNO
Srikant Kuppa066904f2013-05-07 13:56:02 -07009184eHalStatus csrScanSavePreferredNetworkFound(tpAniSirGlobal pMac,
9185 tSirPrefNetworkFoundInd *pPrefNetworkFoundInd)
9186{
9187 v_U32_t uLen = 0;
9188 tpSirProbeRespBeacon pParsedFrame;
9189 tCsrScanResult *pScanResult = NULL;
9190 tSirBssDescription *pBssDescr = NULL;
9191 tANI_BOOLEAN fDupBss;
9192 tDot11fBeaconIEs *pIesLocal = NULL;
9193 tAniSSID tmpSsid;
9194 v_TIME_t timer=0;
9195 tpSirMacMgmtHdr macHeader = (tpSirMacMgmtHdr)pPrefNetworkFoundInd->data;
Abhishek Singhd3d4e022014-11-11 13:02:40 +05309196 boolean bFoundonAppliedChannel = FALSE;
9197 v_U32_t indx;
9198 u8 channelsAllowed[WNI_CFG_VALID_CHANNEL_LIST_LEN];
9199 v_U32_t numChannelsAllowed = WNI_CFG_VALID_CHANNEL_LIST_LEN;
Sushant Kaushik6274de62015-05-01 16:31:23 +05309200 tListElem *pEntry;
Abhishek Singhd3d4e022014-11-11 13:02:40 +05309201
Srikant Kuppa066904f2013-05-07 13:56:02 -07009202
9203 pParsedFrame =
Abhishek Singhc75726d2015-04-13 14:44:14 +05309204 (tpSirProbeRespBeacon)vos_mem_vmalloc(sizeof(tSirProbeRespBeacon));
Srikant Kuppa066904f2013-05-07 13:56:02 -07009205
9206 if (NULL == pParsedFrame)
9207 {
9208 smsLog(pMac, LOGE, FL(" fail to allocate memory for frame"));
9209 return eHAL_STATUS_RESOURCES;
9210 }
9211
9212 if ( pPrefNetworkFoundInd->frameLength <= SIR_MAC_HDR_LEN_3A )
9213 {
9214 smsLog(pMac, LOGE,
9215 FL("Not enough bytes in PNO indication probe resp frame! length=%d"),
9216 pPrefNetworkFoundInd->frameLength);
Abhishek Singhc75726d2015-04-13 14:44:14 +05309217 vos_mem_vfree(pParsedFrame);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009218 return eHAL_STATUS_FAILURE;
9219 }
9220
9221 if (sirConvertProbeFrame2Struct(pMac,
9222 &pPrefNetworkFoundInd->data[SIR_MAC_HDR_LEN_3A],
9223 pPrefNetworkFoundInd->frameLength - SIR_MAC_HDR_LEN_3A,
9224 pParsedFrame) != eSIR_SUCCESS ||
9225 !pParsedFrame->ssidPresent)
9226 {
9227 smsLog(pMac, LOGE,
9228 FL("Parse error ProbeResponse, length=%d"),
9229 pPrefNetworkFoundInd->frameLength);
Abhishek Singhc75726d2015-04-13 14:44:14 +05309230 vos_mem_vfree(pParsedFrame);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009231 return eHAL_STATUS_FAILURE;
9232 }
9233 //24 byte MAC header and 12 byte to ssid IE
9234 if (pPrefNetworkFoundInd->frameLength >
9235 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET))
9236 {
9237 uLen = pPrefNetworkFoundInd->frameLength -
9238 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET);
9239 }
9240
Yeshwanth Sriram Guntuka1a102552018-08-10 15:33:26 +05309241 if (uLen > (UINT_MAX - sizeof(tCsrScanResult))) {
9242 smsLog(pMac, LOGE, FL("Incorrect len: %d, may leads to int overflow, uLen %d"),
9243 pPrefNetworkFoundInd->frameLength, uLen);
9244 vos_mem_vfree(pParsedFrame);
9245 return eHAL_STATUS_FAILURE;
9246 }
9247
Kiet Lam64c1b492013-07-12 13:56:44 +05309248 pScanResult = vos_mem_malloc(sizeof(tCsrScanResult) + uLen);
9249 if ( NULL == pScanResult )
Srikant Kuppa066904f2013-05-07 13:56:02 -07009250 {
9251 smsLog(pMac, LOGE, FL(" fail to allocate memory for frame"));
9252 vos_mem_free(pParsedFrame);
9253 return eHAL_STATUS_RESOURCES;
9254 }
9255
Kiet Lam64c1b492013-07-12 13:56:44 +05309256 vos_mem_set(pScanResult, sizeof(tCsrScanResult) + uLen, 0);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009257 pBssDescr = &pScanResult->Result.BssDescriptor;
9258 /**
9259 * Length of BSS desription is without length of
9260 * length itself and length of pointer
9261 * that holds the next BSS description
9262 */
9263 pBssDescr->length = (tANI_U16)(
Abhishek Singhbad2b322016-10-21 11:22:33 +05309264 ((uintptr_t)OFFSET_OF(tSirBssDescription, ieFields))
9265 - sizeof(pBssDescr->length) + uLen);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009266 if (pParsedFrame->dsParamsPresent)
9267 {
9268 pBssDescr->channelId = pParsedFrame->channelNumber;
9269 }
9270 else if (pParsedFrame->HTInfo.present)
9271 {
9272 pBssDescr->channelId = pParsedFrame->HTInfo.primaryChannel;
9273 }
9274 else
9275 {
Mahesh A Saptasagaradd99792014-03-26 16:04:20 +05309276 /**
9277 * If Probe Responce received in PNO indication does not
9278 * contain DSParam IE or HT Info IE then add dummy channel
9279 * to the received BSS info so that Scan result received as
9280 * a part of PNO is updated to the supplicant. Specially
9281 * applicable in case of AP configured in 11A only mode.
9282 */
9283 if ((pMac->roam.configParam.bandCapability == eCSR_BAND_ALL) ||
9284 (pMac->roam.configParam.bandCapability == eCSR_BAND_24))
9285 {
9286 pBssDescr->channelId = 1;
9287 }
9288 else if(pMac->roam.configParam.bandCapability == eCSR_BAND_5G)
9289 {
9290 pBssDescr->channelId = 36;
9291 }
Abhishek Singhd3d4e022014-11-11 13:02:40 +05309292 /* Restrict the logic to ignore the pno indication for invalid channel
9293 * only if valid channel info is present in beacon/probe resp.
9294 * If no channel info is present in beacon/probe resp, always process
9295 * the pno indication.
9296 */
9297 bFoundonAppliedChannel = TRUE;
9298 }
9299
9300 if (0 != sme_GetCfgValidChannels(pMac, channelsAllowed, &numChannelsAllowed))
9301 {
9302 smsLog(pMac, LOGE, FL(" sme_GetCfgValidChannels failed "));
9303 csrFreeScanResultEntry(pMac, pScanResult);
Abhishek Singhc75726d2015-04-13 14:44:14 +05309304 vos_mem_vfree(pParsedFrame);
Abhishek Singhd3d4e022014-11-11 13:02:40 +05309305 return eHAL_STATUS_FAILURE;
9306 }
9307 /* Checking chhanelId with allowed channel list */
9308 for (indx = 0; indx < numChannelsAllowed; indx++)
9309 {
9310 if (pBssDescr->channelId == channelsAllowed[indx])
9311 {
9312 bFoundonAppliedChannel = TRUE;
9313 smsLog(pMac, LOG1, FL(" pno ind found on applied channel =%d\n "),
9314 pBssDescr->channelId);
9315 break;
9316 }
9317 }
9318 /* Ignore PNO indication if AP is on Invalid channel.
9319 */
9320 if(FALSE == bFoundonAppliedChannel)
9321 {
9322 smsLog(pMac, LOGW, FL(" prefered network found on invalid channel = %d"),
9323 pBssDescr->channelId);
9324 csrFreeScanResultEntry(pMac, pScanResult);
Abhishek Singhc75726d2015-04-13 14:44:14 +05309325 vos_mem_vfree(pParsedFrame);
Abhishek Singhd3d4e022014-11-11 13:02:40 +05309326 return eHAL_STATUS_FAILURE;
Srikant Kuppa066904f2013-05-07 13:56:02 -07009327 }
9328
9329 if ((pBssDescr->channelId > 0) && (pBssDescr->channelId < 15))
9330 {
9331 int i;
9332 // 11b or 11g packet
9333 // 11g iff extended Rate IE is present or
9334 // if there is an A rate in suppRate IE
9335 for (i = 0; i < pParsedFrame->supportedRates.numRates; i++)
9336 {
9337 if (sirIsArate(pParsedFrame->supportedRates.rate[i] & 0x7f))
9338 {
9339 pBssDescr->nwType = eSIR_11G_NW_TYPE;
9340 break;
9341 }
9342 }
9343 if (pParsedFrame->extendedRatesPresent)
9344 {
9345 pBssDescr->nwType = eSIR_11G_NW_TYPE;
9346 }
9347 }
9348 else
9349 {
9350 // 11a packet
9351 pBssDescr->nwType = eSIR_11A_NW_TYPE;
9352 }
9353
9354 pBssDescr->sinr = 0;
9355 pBssDescr->rssi = -1 * pPrefNetworkFoundInd->rssi;
9356 pBssDescr->beaconInterval = pParsedFrame->beaconInterval;
AnjaneeDevi Kapparapu4b043912014-02-18 13:22:35 +05309357 if (!pBssDescr->beaconInterval)
9358 {
9359 smsLog(pMac, LOGW,
9360 FL("Bcn Interval is Zero , default to 100" MAC_ADDRESS_STR),
9361 MAC_ADDR_ARRAY(pBssDescr->bssId) );
9362 pBssDescr->beaconInterval = 100;
9363 }
Srikant Kuppa066904f2013-05-07 13:56:02 -07009364 pBssDescr->timeStamp[0] = pParsedFrame->timeStamp[0];
9365 pBssDescr->timeStamp[1] = pParsedFrame->timeStamp[1];
9366 pBssDescr->capabilityInfo = *((tANI_U16 *)&pParsedFrame->capabilityInfo);
Kiet Lam64c1b492013-07-12 13:56:44 +05309367 vos_mem_copy((tANI_U8 *) &pBssDescr->bssId, (tANI_U8 *) macHeader->bssId, sizeof(tSirMacAddr));
Deepthi Gowri4480a3f2016-05-18 19:30:17 +05309368 pBssDescr->nReceivedTime = vos_timer_get_system_time();
Srikant Kuppa066904f2013-05-07 13:56:02 -07009369
Sreelakshmi Konamki9866a8c2017-02-10 12:45:27 +05309370#ifdef WLAN_FEATURE_VOWIFI_11R
9371 // MobilityDomain
9372 pBssDescr->mdie[0] = 0;
9373 pBssDescr->mdie[1] = 0;
9374 pBssDescr->mdie[2] = 0;
9375 pBssDescr->mdiePresent = FALSE;
9376 // If mdie is present in the probe resp we fill it in the bss description
9377 if(pParsedFrame->mdiePresent)
9378 {
9379 pBssDescr->mdiePresent = TRUE;
9380 pBssDescr->mdie[0] = pParsedFrame->mdie[0];
9381 pBssDescr->mdie[1] = pParsedFrame->mdie[1];
9382 pBssDescr->mdie[2] = pParsedFrame->mdie[2];
9383 }
9384 smsLog(pMac, LOG1, FL("mdie=%02x%02x%02x"),
9385 (unsigned int)pBssDescr->mdie[0], (unsigned int)pBssDescr->mdie[1],
9386 (unsigned int)pBssDescr->mdie[2]);
9387#endif
9388
Abhishek Singh195c03e2014-05-14 17:21:30 +05309389 smsLog( pMac, LOG1, FL("Bssid= "MAC_ADDRESS_STR
9390 " chan= %d, rssi = %d "),
Arif Hussain24bafea2013-11-15 15:10:03 -08009391 MAC_ADDR_ARRAY(pBssDescr->bssId),
Srikant Kuppa066904f2013-05-07 13:56:02 -07009392 pBssDescr->channelId,
Abhishek Singh195c03e2014-05-14 17:21:30 +05309393 pBssDescr->rssi);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009394
9395 //IEs
9396 if (uLen)
9397 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309398 vos_mem_copy(&pBssDescr->ieFields,
9399 pPrefNetworkFoundInd->data + (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET),
9400 uLen);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009401 }
9402
9403 pIesLocal = (tDot11fBeaconIEs *)( pScanResult->Result.pvIes );
9404 if ( !pIesLocal &&
9405 (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
9406 &pScanResult->Result.BssDescriptor, &pIesLocal))) )
9407 {
9408 smsLog(pMac, LOGE, FL(" Cannot parse IEs"));
9409 csrFreeScanResultEntry(pMac, pScanResult);
Abhishek Singhc75726d2015-04-13 14:44:14 +05309410 vos_mem_vfree(pParsedFrame);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009411 return eHAL_STATUS_RESOURCES;
9412 }
9413
9414 fDupBss = csrRemoveDupBssDescription( pMac,
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05309415 &pScanResult->Result.BssDescriptor, pIesLocal, &tmpSsid, &timer, FALSE);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009416 //Check whether we have reach out limit
9417 if ( CSR_SCAN_IS_OVER_BSS_LIMIT(pMac) )
9418 {
9419 //Limit reach
9420 smsLog(pMac, LOGE, FL(" BSS limit reached"));
9421 //Free the resources
9422 if( (pScanResult->Result.pvIes == NULL) && pIesLocal )
9423 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309424 vos_mem_free(pIesLocal);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009425 }
9426 csrFreeScanResultEntry(pMac, pScanResult);
9427 vos_mem_free(pParsedFrame);
9428 return eHAL_STATUS_RESOURCES;
9429 }
Nalla Kartheek71946422015-09-15 14:41:22 +05309430
9431 if ((macHeader->fc.type == SIR_MAC_MGMT_FRAME) &&
9432 (macHeader->fc.subType == SIR_MAC_MGMT_PROBE_RSP))
9433 {
9434 pScanResult->Result.BssDescriptor.fProbeRsp = 1;
9435 }
Srikant Kuppa066904f2013-05-07 13:56:02 -07009436 //Add to scan cache
9437 csrScanAddResult(pMac, pScanResult, pIesLocal);
Sushant Kaushik6274de62015-05-01 16:31:23 +05309438 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
Kiet Lamb537cfb2013-11-07 12:56:49 +05309439 if( (pScanResult->Result.pvIes == NULL) && pIesLocal )
9440 {
9441 vos_mem_free(pIesLocal);
9442 }
9443
Abhishek Singhc75726d2015-04-13 14:44:14 +05309444 vos_mem_vfree(pParsedFrame);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009445
9446 return eHAL_STATUS_SUCCESS;
9447}
Manjunathappa Prakash4f1d5a52013-11-11 16:22:19 -08009448#endif //FEATURE_WLAN_SCAN_PNO
Srikant Kuppa066904f2013-05-07 13:56:02 -07009449
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08009450#ifdef FEATURE_WLAN_LFR
9451void csrInitOccupiedChannelsList(tpAniSirGlobal pMac)
9452{
9453 tListElem *pEntry = NULL;
9454 tCsrScanResult *pBssDesc = NULL;
9455 tDot11fBeaconIEs *pIes = NULL;
Srinivas28b5b4e2012-12-12 13:07:53 -08009456 tpCsrNeighborRoamControlInfo pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
9457
9458 if (0 != pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels)
9459 {
9460 smsLog(pMac, LOG1, FL("%s: Ini file contains neighbor scan channel list,"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08009461 " hence NO need to build occupied channel list (numChannels = %d)"),
Srinivas28b5b4e2012-12-12 13:07:53 -08009462 __func__, pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels);
9463 return;
9464 }
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08009465
9466 if (!csrNeighborRoamIsNewConnectedProfile(pMac))
9467 {
9468 smsLog(pMac, LOG2, FL("%s: donot flush occupied list since current roam profile"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08009469 " matches previous (numChannels = %d)"),
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08009470 __func__, pMac->scan.occupiedChannels.numChannels);
9471 return;
9472 }
9473
9474 /* Empty occupied channels here */
9475 pMac->scan.occupiedChannels.numChannels = 0;
9476
9477 csrLLLock(&pMac->scan.scanResultList);
9478 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
9479 while( pEntry )
9480 {
9481 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
9482 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
9483
9484 //At this time, pBssDescription->Result.pvIes may be NULL
Srikant Kuppa866893f2012-12-27 17:28:14 -08009485 if( !pIes && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08009486 &pBssDesc->Result.BssDescriptor, &pIes))) )
9487 {
9488 continue;
9489 }
9490
9491 csrScanAddToOccupiedChannels(pMac, pBssDesc, &pMac->scan.occupiedChannels, pIes);
9492
9493 /*
9494 * Free the memory allocated for pIes in csrGetParsedBssDescriptionIEs
9495 */
9496 if( (pBssDesc->Result.pvIes == NULL) && pIes )
9497 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309498 vos_mem_free(pIes);
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08009499 }
9500
9501 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK );
9502 }//while
9503 csrLLUnlock(&pMac->scan.scanResultList);
Srikant Kuppa866893f2012-12-27 17:28:14 -08009504
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08009505}
9506#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009507
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009508eHalStatus csrScanCreateEntryInScanCache(tpAniSirGlobal pMac, tANI_U32 sessionId,
9509 tCsrBssid bssid, tANI_U8 channel)
9510{
9511 eHalStatus status = eHAL_STATUS_SUCCESS;
9512 tDot11fBeaconIEs *pNewIes = NULL;
9513 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
Praveen Kumar Sirisilla8bdfac42013-10-10 17:20:48 -07009514 tSirBssDescription *pNewBssDescriptor = NULL;
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009515 tANI_U32 size = 0;
9516
9517 if(NULL == pSession)
9518 {
9519 status = eHAL_STATUS_FAILURE;
9520 return status;
9521 }
9522 smsLog(pMac, LOG2, FL("csrScanCreateEntryInScanCache: Current bssid::"
Arif Hussain24bafea2013-11-15 15:10:03 -08009523 MAC_ADDRESS_STR),
9524 MAC_ADDR_ARRAY(pSession->pConnectBssDesc->bssId));
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009525 smsLog(pMac, LOG2, FL("csrScanCreateEntryInScanCache: My bssid::"
Arif Hussain24bafea2013-11-15 15:10:03 -08009526 MAC_ADDRESS_STR" channel %d"),
9527 MAC_ADDR_ARRAY(bssid), channel);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009528
9529 do
9530 {
9531 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
9532 pSession->pConnectBssDesc, &pNewIes)))
9533 {
9534 smsLog(pMac, LOGE, FL("%s: Failed to parse IEs"),
9535 __func__);
9536 status = eHAL_STATUS_FAILURE;
9537 break;
9538 }
9539
9540 size = pSession->pConnectBssDesc->length + sizeof(pSession->pConnectBssDesc->length);
Kiet Lam64c1b492013-07-12 13:56:44 +05309541 if (size)
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009542 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309543 pNewBssDescriptor = vos_mem_malloc(size);
9544 if ( NULL == pNewBssDescriptor )
9545 status = eHAL_STATUS_FAILURE;
9546 else
9547 status = eHAL_STATUS_SUCCESS;
9548 if (HAL_STATUS_SUCCESS(status))
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009549 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309550 vos_mem_copy(pNewBssDescriptor, pSession->pConnectBssDesc, size);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009551 }
9552 else
9553 {
9554 smsLog(pMac, LOGE, FL("%s: memory allocation failed"),
9555 __func__);
9556 status = eHAL_STATUS_FAILURE;
9557 break;
9558 }
9559
9560 //change the BSSID & channel as passed
Kiet Lam64c1b492013-07-12 13:56:44 +05309561 vos_mem_copy(pNewBssDescriptor->bssId, bssid, sizeof(tSirMacAddr));
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009562 pNewBssDescriptor->channelId = channel;
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07009563 if(NULL == csrScanAppendBssDescription( pMac, pNewBssDescriptor, pNewIes, TRUE ))
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009564 {
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07009565 smsLog(pMac, LOGE, FL("%s: csrScanAppendBssDescription failed"),
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009566 __func__);
9567 status = eHAL_STATUS_FAILURE;
9568 break;
9569 }
9570 }
9571 else
9572 {
9573 smsLog(pMac, LOGE, FL("%s: length of bss descriptor is 0"),
9574 __func__);
9575 status = eHAL_STATUS_FAILURE;
9576 break;
9577 }
9578 smsLog(pMac, LOGE, FL("%s: entry successfully added in scan cache"),
9579 __func__);
9580 }while(0);
9581
9582 if(pNewIes)
9583 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309584 vos_mem_free(pNewIes);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009585 }
9586 if(pNewBssDescriptor)
9587 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309588 vos_mem_free(pNewBssDescriptor);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009589 }
9590 return status;
9591}
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07009592
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08009593#ifdef FEATURE_WLAN_ESE
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07009594// Update the TSF with the difference in system time
9595void UpdateCCKMTSF(tANI_U32 *timeStamp0, tANI_U32 *timeStamp1, tANI_U32 *incr)
9596{
9597 tANI_U64 timeStamp64 = ((tANI_U64)*timeStamp1 << 32) | (*timeStamp0);
9598
9599 timeStamp64 = (tANI_U64)(timeStamp64 + (tANI_U64)*incr);
9600 *timeStamp0 = (tANI_U32)(timeStamp64 & 0xffffffff);
9601 *timeStamp1 = (tANI_U32)((timeStamp64 >> 32) & 0xffffffff);
9602}
9603#endif
Deepthi Gowriecc93352016-11-09 16:58:47 +05309604
9605void csrValidateScanChannels(tpAniSirGlobal pMac, tCsrScanRequest *pDstReq,
Nishank Aggarwal42f76502017-02-16 12:00:19 +05309606 tCsrScanRequest *pSrcReq, tANI_U32 *new_index, tANI_U8 ch144_support)
Deepthi Gowriecc93352016-11-09 16:58:47 +05309607{
9608
9609 int index;
9610 for ( index = 0; index < pSrcReq->ChannelInfo.
9611 numOfChannels ; index++ )
9612 {
9613 /* Skip CH 144 if firmware support not present */
9614 if (pSrcReq->ChannelInfo.ChannelList[index] == 144 && !ch144_support)
9615 continue;
9616
9617 /* Allow scan on valid channels only.
9618 */
9619 if ( ( csrRoamIsValidChannel(pMac,
9620 pSrcReq->ChannelInfo.ChannelList[index]) ) )
9621 {
9622 if( ((pSrcReq->skipDfsChnlInP2pSearch ||
9623 (pMac->scan.fEnableDFSChnlScan ==
9624 DFS_CHNL_SCAN_DISABLED)) &&
9625 (NV_CHANNEL_DFS == vos_nv_getChannelEnabledState(
9626 pSrcReq->ChannelInfo.ChannelList[index])) &&
9627 (pSrcReq->ChannelInfo.numOfChannels > 1))
9628#ifdef FEATURE_WLAN_LFR
9629 /*
9630 * If LFR is requesting a contiguous scan
9631 * (i.e. numOfChannels > 1), then ignore
9632 * DFS channels.
9633 * TODO: vos_nv_getChannelEnabledState is returning
9634 * 120, 124 and 128 as non-DFS channels. Hence, the
9635 * use of direct check for channels below.
9636 */
9637 || ((eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType) &&
9638 (pSrcReq->ChannelInfo.numOfChannels > 1) &&
9639 (CSR_IS_CHANNEL_DFS(
9640 pSrcReq->ChannelInfo.ChannelList[index])) &&
9641 !pMac->roam.configParam.allowDFSChannelRoam)
9642#endif
9643 )
9644 {
9645#ifdef FEATURE_WLAN_LFR
9646 smsLog(pMac, LOG1,
9647 FL(" reqType=%s (%d), numOfChannels=%d,"
9648 " ignoring DFS channel:%d"),
9649 sme_requestTypetoString(pSrcReq->requestType),
9650 pSrcReq->requestType,
9651 pSrcReq->ChannelInfo.numOfChannels,
9652 pSrcReq->ChannelInfo.ChannelList[index]);
9653#endif
9654 continue;
9655 }
9656
Nishank Aggarwal42f76502017-02-16 12:00:19 +05309657 pDstReq->ChannelInfo.ChannelList[*new_index] =
Deepthi Gowriecc93352016-11-09 16:58:47 +05309658 pSrcReq->ChannelInfo.ChannelList[index];
Nishank Aggarwal42f76502017-02-16 12:00:19 +05309659 (*new_index)++;
Deepthi Gowriecc93352016-11-09 16:58:47 +05309660 }
9661 }
9662}