blob: b7c58b499377cd63dc9738649e4525501796e56c [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Abhishek Singhb3e376c2017-01-04 15:27:13 +05302 * Copyright (c) 2011-2017 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
Srikant Kuppa866893f2012-12-27 17:28:14 -0800384 * Do not split scans if no concurrent infra connections are
385 * active and if the scan is a BG scan triggered by LFR (OR)
386 * any scan if LFR is in the middle of a BG scan. Splitting
387 * the scan is delaying the time it takes for LFR to find
388 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -0800389 */
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700390
391 if(csrIsStaSessionConnected(pMac) &&
392 !csrIsP2pSessionConnected(pMac))
393 {
394 nNumChanCombinedConc = pMac->roam.configParam.nNumStaChanCombinedConc;
395 }
396 else if(csrIsP2pSessionConnected(pMac))
397 {
398 nNumChanCombinedConc = pMac->roam.configParam.nNumP2PChanCombinedConc;
399 }
Srikant Kuppa866893f2012-12-27 17:28:14 -0800400 if ( (csrIsStaSessionConnected(pMac) &&
401#ifdef FEATURE_WLAN_LFR
402 (csrIsConcurrentInfraConnected(pMac) ||
403 ((pScanCmd->u.scanCmd.reason != eCsrScanBgScan) &&
404 (pMac->roam.neighborRoamInfo.neighborRoamState !=
405 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
406#endif
407 (pScanCmd->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Vinay Malekal05fdc812012-12-17 13:04:30 -0800408 (csrIsP2pSessionConnected(pMac)) )
Jeff Johnson295189b2012-06-20 16:38:30 -0700409 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700410 tCsrScanRequest scanReq;
411 tANI_U8 numChn = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
412 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
413 tANI_U8 channelToScan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
Jeff Johnson295189b2012-06-20 16:38:30 -0700414 tANI_BOOLEAN bMemAlloc = eANI_BOOLEAN_FALSE;
415
416 if (numChn == 0)
417 {
418
419 numChn = pMac->scan.baseChannels.numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -0700420
Kiet Lam64c1b492013-07-12 13:56:44 +0530421 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(numChn);
422 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -0700423 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800424 smsLog( pMac, LOGE, FL(" Failed to get memory for channel list ") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800425 return eHAL_STATUS_FAILURE;
426 }
427 bMemAlloc = eANI_BOOLEAN_TRUE;
Kiet Lam64c1b492013-07-12 13:56:44 +0530428 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
429 pMac->scan.baseChannels.channelList, numChn);
430 status = eHAL_STATUS_SUCCESS;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800431 if( !HAL_STATUS_SUCCESS( status ) )
432 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530433 vos_mem_free(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800434 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800435 smsLog( pMac, LOGE, FL(" Failed to copy memory to channel list ") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800436 return eHAL_STATUS_FAILURE;
437 }
438 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = numChn;
439 }
Sushant Kaushik826de802014-05-08 18:04:11 +0530440 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
441 "%s: Total Number of channels to scan : %d "
442 "Splitted in group of %d ", __func__, numChn,
443 nNumChanCombinedConc);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800444 //Whenever we get a scan request with multiple channels we break it up into 2 requests
445 //First request for first channel to scan and second request to scan remaining channels
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700446 if ( numChn > nNumChanCombinedConc)
Vinay Malekal05fdc812012-12-17 13:04:30 -0800447 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530448 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800449
450 pQueueScanCmd = csrGetCommandBuffer(pMac); //optimize this to use 2 command buffer only
451 if (!pQueueScanCmd)
452 {
453 if (bMemAlloc)
Jeff Johnson295189b2012-06-20 16:38:30 -0700454 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530455 vos_mem_free(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800456 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
457
Jeff Johnson295189b2012-06-20 16:38:30 -0700458 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800459 smsLog( pMac, LOGE, FL(" Failed to get Queue command buffer") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800460 return eHAL_STATUS_FAILURE;
461 }
462 pQueueScanCmd->command = pScanCmd->command;
463 pQueueScanCmd->sessionId = pScanCmd->sessionId;
464 pQueueScanCmd->u.scanCmd.callback = pScanCmd->u.scanCmd.callback;
465 pQueueScanCmd->u.scanCmd.pContext = pScanCmd->u.scanCmd.pContext;
466 pQueueScanCmd->u.scanCmd.reason = pScanCmd->u.scanCmd.reason;
467 pQueueScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Jeff Johnson295189b2012-06-20 16:38:30 -0700468
Vinay Malekal05fdc812012-12-17 13:04:30 -0800469 /* First copy all the parameters to local variable of scan request */
470 csrScanCopyRequest(pMac, &scanReq, &pScanCmd->u.scanCmd.u.scanRequest);
Madan Mohan Koyyalamudiaf2a8b92012-10-09 14:58:07 -0700471
Vinay Malekal05fdc812012-12-17 13:04:30 -0800472 /* Now modify the elements of local var scan request required to be modified for split scan */
473 if(scanReq.ChannelInfo.ChannelList != NULL)
474 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530475 vos_mem_free(scanReq.ChannelInfo.ChannelList);
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -0800476 scanReq.ChannelInfo.ChannelList = NULL;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800477 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700478
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700479 pChnInfo->numOfChannels = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels - nNumChanCombinedConc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700480
Vinay Malekal05fdc812012-12-17 13:04:30 -0800481 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_WARN,
Jeff Johnson89477502017-09-19 08:35:23 -0700482 FL(" &channelToScan %pK pScanCmd(%pK) pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList(%pK)numChn(%d)"),
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +0530483 &channelToScan[0], pScanCmd,
484 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList, numChn);
Jeff Johnson295189b2012-06-20 16:38:30 -0700485
Kiet Lam64c1b492013-07-12 13:56:44 +0530486 vos_mem_copy(&channelToScan[0],
487 &pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[
488 nNumChanCombinedConc],
489 pChnInfo->numOfChannels * sizeof(tANI_U8));
Vinay Malekal05fdc812012-12-17 13:04:30 -0800490
491 pChnInfo->ChannelList = &channelToScan[0];
492
493 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
c_hpothudbefd3e2014-04-28 15:59:47 +0530494
Vinay Malekal05fdc812012-12-17 13:04:30 -0800495 //Use concurrency values for min/maxChnTime.
496 //We know csrIsAnySessionConnected(pMac) returns TRUE here
497 csrSetDefaultScanTiming(pMac, scanReq.scanType, &scanReq);
498
499 status = csrScanCopyRequest(pMac, &pQueueScanCmd->u.scanCmd.u.scanRequest, &scanReq);
500
501 if(!HAL_STATUS_SUCCESS(status))
502 {
503 if (bMemAlloc)
504 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530505 vos_mem_free(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800506 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
507
508 }
509 if( scanReq.pIEField != NULL)
510 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530511 vos_mem_free(scanReq.pIEField);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800512 scanReq.pIEField = NULL;
513 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800514 smsLog( pMac, LOGE, FL(" Failed to get copy csrScanRequest = %d"), status );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800515 return eHAL_STATUS_FAILURE;
516 }
517 /* Clean the local scan variable */
518 scanReq.ChannelInfo.ChannelList = NULL;
519 scanReq.ChannelInfo.numOfChannels = 0;
520 csrScanFreeRequest(pMac, &scanReq);
521
522 /* setup the command to scan 2 channels */
523 pSendScanCmd = pScanCmd;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700524 pSendScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nNumChanCombinedConc;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800525 pSendScanCmd->u.scanCmd.u.scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
c_hpothudbefd3e2014-04-28 15:59:47 +0530526
Vinay Malekal05fdc812012-12-17 13:04:30 -0800527 //Use concurrency values for min/maxChnTime.
528 //We know csrIsAnySessionConnected(pMac) returns TRUE here
529 csrSetDefaultScanTiming(pMac, pSendScanCmd->u.scanCmd.u.scanRequest.scanType, &pSendScanCmd->u.scanCmd.u.scanRequest);
530 pSendScanCmd->u.scanCmd.callback = NULL;
531 } else {
532 pSendScanCmd = pScanCmd;
533 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 }
539
540 fNoCmdPending = csrLLIsListEmpty( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK );
541
542 //Logic Below is as follows
543 // If the scanCmdPendingList is empty then we directly send that command
544 // to smeCommandQueue else we buffer it in our scanCmdPendingList Queue
545 if( fNoCmdPending )
546 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700547 if (pQueueScanCmd != NULL)
548 {
Vinay Malekal05fdc812012-12-17 13:04:30 -0800549 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pQueueScanCmd->Link, LL_ACCESS_LOCK );
Jeff Johnson295189b2012-06-20 16:38:30 -0700550 }
551
552 if (pSendScanCmd != NULL)
553 {
554 return csrQueueSmeCommand(pMac, pSendScanCmd, eANI_BOOLEAN_FALSE);
555 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800556 }
557 else
558 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700559 if (pSendScanCmd != NULL)
560 {
561 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pSendScanCmd->Link, LL_ACCESS_LOCK );
562 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800563
Jeff Johnson295189b2012-06-20 16:38:30 -0700564 if (pQueueScanCmd != NULL)
565 {
566 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pQueueScanCmd->Link, LL_ACCESS_LOCK );
567 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800568 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700569 }
570 else
571 { //No concurrency case
Srikant Kuppa866893f2012-12-27 17:28:14 -0800572 smsLog( pMac, LOG2, FL("Queuing scan command (reason=%d, roamState=%d"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800573 " numOfChannels=%d)"),
Srikant Kuppa866893f2012-12-27 17:28:14 -0800574 pScanCmd->u.scanCmd.reason,
575 pMac->roam.neighborRoamInfo.neighborRoamState,
576 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -0700577 return csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
578 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700579
580 return ( status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700581}
582#endif
583
Jeff Johnsone7245742012-09-05 17:12:55 -0700584/* ---------------------------------------------------------------------------
585 \fn csrScan2GOnyRequest
586 \brief This function will update the scan request with only
Jeff Johnsonb88db982012-12-10 13:34:59 -0800587 2.4GHz valid channel list.
Jeff Johnsone7245742012-09-05 17:12:55 -0700588 \param pMac
589 \param pScanCmd
590 \param pScanRequest
591 \return None
592 -------------------------------------------------------------------------------*/
593static void csrScan2GOnyRequest(tpAniSirGlobal pMac,tSmeCmd *pScanCmd,
594 tCsrScanRequest *pScanRequest)
595{
596 tANI_U8 index, channelId, channelListSize = 0;
597 tANI_U8 channelList2G[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
598 static tANI_U8 validchannelList[CSR_MAX_2_4_GHZ_SUPPORTED_CHANNELS] = {0};
599
600 VOS_ASSERT(pScanCmd && pScanRequest);
Madan Mohan Koyyalamudi33ef6a22012-10-30 17:44:43 -0700601 /* To silence the KW tool null check is added */
602 if((pScanCmd == NULL) || (pScanRequest == NULL))
603 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800604 smsLog( pMac, LOGE, FL(" pScanCmd or pScanRequest is NULL "));
Madan Mohan Koyyalamudi33ef6a22012-10-30 17:44:43 -0700605 return;
606 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700607
608 if (pScanCmd->u.scanCmd.scanID ||
609 (eCSR_SCAN_REQUEST_FULL_SCAN != pScanRequest->requestType))
610 return;
611
612 //Contsruct valid Supported 2.4 GHz Channel List
613 for( index = 0; index < ARRAY_SIZE(channelList2G); index++ )
614 {
615 channelId = channelList2G[index];
616 if ( csrIsSupportedChannel( pMac, channelId ) )
617 {
618 validchannelList[channelListSize++] = channelId;
619 }
620 }
621
622 pScanRequest->ChannelInfo.numOfChannels = channelListSize;
623 pScanRequest->ChannelInfo.ChannelList = validchannelList;
624}
625
Jeff Johnson295189b2012-06-20 16:38:30 -0700626eHalStatus csrScanRequest(tpAniSirGlobal pMac, tANI_U16 sessionId,
627 tCsrScanRequest *pScanRequest, tANI_U32 *pScanRequestID,
628 csrScanCompleteCallback callback, void *pContext)
629{
630 eHalStatus status = eHAL_STATUS_FAILURE;
631 tSmeCmd *pScanCmd = NULL;
Madan Mohan Koyyalamudicb90bb22012-10-30 18:24:43 -0700632 eCsrConnectState ConnectState;
Deepthi Gowrie11da8c2016-02-04 18:18:39 +0530633
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800634 if(pScanRequest == NULL)
635 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800636 smsLog( pMac, LOGE, FL(" pScanRequest is NULL"));
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800637 VOS_ASSERT(0);
Kaushik, Sushant488df382014-03-05 11:43:47 +0530638 return eHAL_STATUS_FAILURE ;
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800639 }
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700640
Kiet Lamd1f3dc82013-11-05 20:45:04 +0530641 /* During group formation, the P2P client scans for GO with the specific SSID.
642 * There will be chances of GO switching to other channels because of scan or
643 * to STA channel in case of STA+GO MCC scenario. So to increase the possibility
644 * of client to find the GO, the dwell time of scan is increased to 100ms.
645 */
646 if(pScanRequest->p2pSearch)
647 {
Rashmi Ramanna6f7931c2013-12-20 09:04:12 +0530648 if(pScanRequest->SSIDs.numOfSSIDs)
Kiet Lamd1f3dc82013-11-05 20:45:04 +0530649 {
Rashmi Ramanna6f7931c2013-12-20 09:04:12 +0530650 //If the scan request is for specific SSId the length of SSID will be
651 //greater than 7 as SSID for p2p search contains "DIRECT-")
652 if(pScanRequest->SSIDs.SSIDList->SSID.length > DIRECT_SSID_LEN)
653 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530654 smsLog( pMac, LOG1, FL("P2P: Increasing the min and max Dwell"
655 " time to %d for specific SSID scan %.*s"),
656 MAX_CHN_TIME_TO_FIND_GO,
657 pScanRequest->SSIDs.SSIDList->SSID.length,
658 pScanRequest->SSIDs.SSIDList->SSID.ssId);
Rashmi Ramanna6f7931c2013-12-20 09:04:12 +0530659 pScanRequest->maxChnTime = MAX_CHN_TIME_TO_FIND_GO;
660 pScanRequest->minChnTime = MIN_CHN_TIME_TO_FIND_GO;
661 }
Kiet Lamd1f3dc82013-11-05 20:45:04 +0530662 }
663 }
664
Jeff Johnson295189b2012-06-20 16:38:30 -0700665 do
666 {
667 if(pMac->scan.fScanEnable)
668 {
669 pScanCmd = csrGetCommandBuffer(pMac);
670 if(pScanCmd)
671 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530672 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -0700673 pScanCmd->command = eSmeCommandScan;
674 pScanCmd->sessionId = sessionId;
675 pScanCmd->u.scanCmd.callback = callback;
676 pScanCmd->u.scanCmd.pContext = pContext;
677 if(eCSR_SCAN_REQUEST_11D_SCAN == pScanRequest->requestType)
678 {
679 pScanCmd->u.scanCmd.reason = eCsrScan11d1;
680 }
681 else if((eCSR_SCAN_REQUEST_FULL_SCAN == pScanRequest->requestType) ||
682 (eCSR_SCAN_P2P_DISCOVERY == pScanRequest->requestType)
683#ifdef SOFTAP_CHANNEL_RANGE
684 ||(eCSR_SCAN_SOFTAP_CHANNEL_RANGE == pScanRequest->requestType)
685#endif
686 )
687 {
688 pScanCmd->u.scanCmd.reason = eCsrScanUserRequest;
689 }
690 else if(eCSR_SCAN_HO_BG_SCAN == pScanRequest->requestType)
691 {
692 pScanCmd->u.scanCmd.reason = eCsrScanBgScan;
693 }
694 else if(eCSR_SCAN_HO_PROBE_SCAN == pScanRequest->requestType)
695 {
696 pScanCmd->u.scanCmd.reason = eCsrScanProbeBss;
697 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700698 else if(eCSR_SCAN_P2P_FIND_PEER == pScanRequest->requestType)
699 {
700 pScanCmd->u.scanCmd.reason = eCsrScanP2PFindPeer;
701 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700702 else
703 {
704 pScanCmd->u.scanCmd.reason = eCsrScanIdleScan;
705 }
706 if(pScanRequest->minChnTime == 0 && pScanRequest->maxChnTime == 0)
707 {
708 //The caller doesn't set the time correctly. Set it here
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530709 csrSetDefaultScanTiming(pMac, pScanRequest->scanType,
710 pScanRequest);
711 smsLog(pMac, LOG1, FL("Setting default min %d and max %d"
712 " ChnTime"), pScanRequest->minChnTime,
713 pScanRequest->maxChnTime);
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700714 }
715#ifdef WLAN_AP_STA_CONCURRENCY
716 if(pScanRequest->restTime == 0)
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800717 {
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700718 //Need to set restTime only if at least one session is connected
719 if(csrIsAnySessionConnected(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -0700720 {
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700721 pScanRequest->restTime = pMac->roam.configParam.nRestTimeConc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700722 }
723 }
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700724#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -0700725 /*For Standalone wlan : channel time will remain the same.
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530726 For BTC with A2DP up: Channel time = Channel time * 2, if station is not already associated.
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800727 This has been done to provide a larger scan window for faster connection during btc.Else Scan is seen
728 to take a long time.
729 For BTC with A2DP up: Channel time will not be doubled, if station is already associated.
730 */
Jeff Johnson32d95a32012-09-10 13:15:23 -0700731 status = csrRoamGetConnectState(pMac,sessionId,&ConnectState);
Srinivas Girigowdac84c57c2013-02-19 17:41:56 -0800732 if (HAL_STATUS_SUCCESS(status) &&
733 pMac->btc.fA2DPUp &&
Jeff Johnson32d95a32012-09-10 13:15:23 -0700734 (eCSR_ASSOC_STATE_TYPE_INFRA_ASSOCIATED != ConnectState) &&
735 (eCSR_ASSOC_STATE_TYPE_IBSS_CONNECTED != ConnectState))
736 {
737 pScanRequest->maxChnTime = pScanRequest->maxChnTime << 1;
738 pScanRequest->minChnTime = pScanRequest->minChnTime << 1;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530739 smsLog( pMac, LOG1, FL("BTC A2DP up, doubling max and min"
740 " ChnTime (Max=%d Min=%d)"),
741 pScanRequest->maxChnTime,
742 pScanRequest->minChnTime);
Jeff Johnson32d95a32012-09-10 13:15:23 -0700743 }
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800744
Abhishek Singhadd13582016-09-29 17:00:03 +0530745 pScanRequest->max_chntime_btc_esco =
746 pMac->roam.configParam.max_chntime_btc_esco;
747 pScanRequest->min_chntime_btc_esco =
748 pMac->roam.configParam.min_chntime_btc_esco;
Jeff Johnson295189b2012-06-20 16:38:30 -0700749 //Need to make the following atomic
750 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
751
752 if(pScanRequestID)
753 {
754 *pScanRequestID = pScanCmd->u.scanCmd.scanID;
755 }
756
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800757 // If it is the first scan request from HDD, CSR checks if it is for 11d.
Jeff Johnson295189b2012-06-20 16:38:30 -0700758 // If it is not, CSR will save the scan request in the pending cmd queue
759 // & issue an 11d scan request to PE.
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800760 if (((0 == pScanCmd->u.scanCmd.scanID)
Jeff Johnson295189b2012-06-20 16:38:30 -0700761 && (eCSR_SCAN_REQUEST_11D_SCAN != pScanRequest->requestType))
762#ifdef SOFTAP_CHANNEL_RANGE
763 && (eCSR_SCAN_SOFTAP_CHANNEL_RANGE != pScanRequest->requestType)
764#endif
765 && (eANI_BOOLEAN_FALSE == pMac->scan.fEnableBypass11d)
766 )
767 {
768 tSmeCmd *p11dScanCmd;
769 tCsrScanRequest scanReq;
770 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
771
Kiet Lam64c1b492013-07-12 13:56:44 +0530772 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -0700773
774 p11dScanCmd = csrGetCommandBuffer(pMac);
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800775 if (p11dScanCmd)
Jeff Johnson295189b2012-06-20 16:38:30 -0700776 {
777 tANI_U32 numChn = pMac->scan.baseChannels.numChannels;
778
Kiet Lam64c1b492013-07-12 13:56:44 +0530779 vos_mem_set(&p11dScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
780 pChnInfo->ChannelList = vos_mem_malloc(numChn);
781 if ( NULL == pChnInfo->ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -0700782 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530783 smsLog(pMac, LOGE, FL("Failed to allocate memory"));
784 status = eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -0700785 break;
786 }
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530787 vos_mem_copy(pChnInfo->ChannelList,
788 pMac->scan.baseChannels.channelList,
789 numChn);
Jeff Johnson295189b2012-06-20 16:38:30 -0700790 pChnInfo->numOfChannels = (tANI_U8)numChn;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530791
Jeff Johnson295189b2012-06-20 16:38:30 -0700792 p11dScanCmd->command = eSmeCommandScan;
Mihir Shetefc7ff5b2014-01-27 11:30:05 +0530793 p11dScanCmd->u.scanCmd.callback = pMac->scan.callback11dScanDone;
Jeff Johnson295189b2012-06-20 16:38:30 -0700794 p11dScanCmd->u.scanCmd.pContext = NULL;
c_hpothu0d5a7352014-03-22 12:30:25 +0530795 p11dScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID;
Jeff Johnson295189b2012-06-20 16:38:30 -0700796 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
797
798 if ( csrIs11dSupported(pMac) )
799 {
c_hpothudbefd3e2014-04-28 15:59:47 +0530800 scanReq.scanType = eSIR_PASSIVE_SCAN;
Jeff Johnson295189b2012-06-20 16:38:30 -0700801 scanReq.requestType = eCSR_SCAN_REQUEST_11D_SCAN;
802 p11dScanCmd->u.scanCmd.reason = eCsrScan11d1;
803 scanReq.maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
804 scanReq.minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
805 }
806 else
807 {
c_hpothudbefd3e2014-04-28 15:59:47 +0530808 scanReq.scanType = pScanRequest->scanType;
Jeff Johnson295189b2012-06-20 16:38:30 -0700809 scanReq.requestType = eCSR_SCAN_IDLE_MODE_SCAN;
810 p11dScanCmd->u.scanCmd.reason = eCsrScanIdleScan;
811 scanReq.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
812 scanReq.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800813
Abhishek Singhadd13582016-09-29 17:00:03 +0530814 scanReq.max_chntime_btc_esco =
815 pMac->roam.configParam.max_chntime_btc_esco;
816 scanReq.min_chntime_btc_esco =
817 pMac->roam.configParam.min_chntime_btc_esco;
Jeff Johnson295189b2012-06-20 16:38:30 -0700818 }
c_hpothu059edb02014-03-12 21:44:28 +0530819 if (pMac->roam.configParam.nInitialDwellTime)
820 {
821 scanReq.maxChnTime =
822 pMac->roam.configParam.nInitialDwellTime;
823 smsLog(pMac, LOG1, FL("11d scan, updating"
824 "dwell time for first scan %u"),
825 scanReq.maxChnTime);
826 }
Deepthi Gowrie11da8c2016-02-04 18:18:39 +0530827 if ((pScanCmd->u.scanCmd.reason == eCsrScanUserRequest)
828 && !(pScanRequest->p2pSearch)
Gupta, Kapilb79cda32015-12-30 20:36:33 +0530829 &&(pScanRequest->ChannelInfo.numOfChannels
830 < pMac->roam.configParam.
831 max_chan_for_dwell_time_cfg))
832 {
833 pScanRequest->maxChnTime =
834 pScanRequest->maxChnTime << 1;
835 pScanRequest->minChnTime =
836 pScanRequest->minChnTime << 1;
837 smsLog(pMac, LOG1,
838 FL("Double ChnTime (Max=%d Min=%d) numOfChannels=%d max_chan_for_dwell_time_cfg=%d"),
839 pScanRequest->maxChnTime,
840 pScanRequest->minChnTime,
841 pScanRequest->ChannelInfo.numOfChannels,
842 pMac->roam.configParam.
843 max_chan_for_dwell_time_cfg);
844 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700845
Jeff Johnson295189b2012-06-20 16:38:30 -0700846 status = csrScanCopyRequest(pMac, &p11dScanCmd->u.scanCmd.u.scanRequest, &scanReq);
847 //Free the channel list
Kiet Lam64c1b492013-07-12 13:56:44 +0530848 vos_mem_free(pChnInfo->ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -0700849 pChnInfo->ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -0700850
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800851 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700852 {
krunal soni5f112f02013-11-25 15:00:11 -0800853 pMac->scan.scanProfile.numOfChannels =
854 p11dScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -0700855 //Start process the command
856#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +0530857 if (!pMac->fScanOffload)
858 status = csrQueueScanRequest(pMac, p11dScanCmd);
859 else
860 status = csrQueueSmeCommand(pMac, p11dScanCmd,
861 eANI_BOOLEAN_FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -0700862#else
863 status = csrQueueSmeCommand(pMac, p11dScanCmd, eANI_BOOLEAN_FALSE);
864#endif
865 if( !HAL_STATUS_SUCCESS( status ) )
866 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530867 smsLog(pMac, LOGE, FL("Failed to send message"
868 " status = %d"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -0700869 break;
870 }
871 }
872 else
873 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530874 smsLog(pMac, LOGE, FL("csrScanCopyRequest failed"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700875 break;
876 }
877 }
878 else
879 {
880 //error
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530881 smsLog( pMac, LOGE, FL("p11dScanCmd failed") );
Jeff Johnson295189b2012-06-20 16:38:30 -0700882 break;
883 }
884 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700885
886 //Scan only 2G Channels if set in ini file
887 //This is mainly to reduce the First Scan duration
888 //Once we turn on Wifi
889 if(pMac->scan.fFirstScanOnly2GChnl)
890 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800891 smsLog( pMac, LOG1, FL("Scanning only 2G Channels during first scan"));
Jeff Johnsone7245742012-09-05 17:12:55 -0700892 csrScan2GOnyRequest(pMac, pScanCmd, pScanRequest);
893 }
894
c_hpothu059edb02014-03-12 21:44:28 +0530895 if (pMac->roam.configParam.nInitialDwellTime)
896 {
897 pScanRequest->maxChnTime =
898 pMac->roam.configParam.nInitialDwellTime;
899 pMac->roam.configParam.nInitialDwellTime = 0;
900 smsLog(pMac, LOG1,
901 FL("updating dwell time for first scan %u"),
902 pScanRequest->maxChnTime);
903 }
904
Deepthi Gowrie11da8c2016-02-04 18:18:39 +0530905 if ((pScanCmd->u.scanCmd.reason == eCsrScanUserRequest)
906 && !(pScanRequest->p2pSearch)
Gupta, Kapilb79cda32015-12-30 20:36:33 +0530907 && (pScanRequest->ChannelInfo.numOfChannels
908 < pMac->roam.configParam.max_chan_for_dwell_time_cfg))
909 {
910 pScanRequest->maxChnTime = pScanRequest->maxChnTime << 1;
911 pScanRequest->minChnTime = pScanRequest->minChnTime << 1;
912 smsLog(pMac, LOG1,
913 FL("Double ChnTime (Max=%d Min=%d) numOfChannels=%d max_chan_for_dwell_time_cfg=%d"),
914 pScanRequest->maxChnTime,
915 pScanRequest->minChnTime,
916 pScanRequest->ChannelInfo.numOfChannels,
917 pMac->roam.configParam.max_chan_for_dwell_time_cfg);
918 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700919 status = csrScanCopyRequest(pMac, &pScanCmd->u.scanCmd.u.scanRequest, pScanRequest);
920 if(HAL_STATUS_SUCCESS(status))
921 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530922 tCsrScanRequest *pTempScanReq =
923 &pScanCmd->u.scanCmd.u.scanRequest;
krunal soni5f112f02013-11-25 15:00:11 -0800924 pMac->scan.scanProfile.numOfChannels =
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530925 pTempScanReq->ChannelInfo.numOfChannels;
krunal soni5f112f02013-11-25 15:00:11 -0800926
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530927 smsLog( pMac, LOG1, FL(" SId=%d scanId=%d"
928 " Scan reason=%u numSSIDs=%d"
929 " numChan=%d P2P search=%d minCT=%d maxCT=%d"
930 " minCBtc=%d maxCBtx=%d"),
931 sessionId, pScanCmd->u.scanCmd.scanID,
932 pScanCmd->u.scanCmd.reason,
933 pTempScanReq->SSIDs.numOfSSIDs,
934 pTempScanReq->ChannelInfo.numOfChannels,
935 pTempScanReq->p2pSearch,
936 pTempScanReq->minChnTime,
937 pTempScanReq->maxChnTime,
Abhishek Singhadd13582016-09-29 17:00:03 +0530938 pTempScanReq->min_chntime_btc_esco,
939 pTempScanReq->max_chntime_btc_esco);
Jeff Johnson295189b2012-06-20 16:38:30 -0700940 //Start process the command
941#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +0530942 if (!pMac->fScanOffload)
943 status = csrQueueScanRequest(pMac,pScanCmd);
944 else
945 status = csrQueueSmeCommand(pMac, pScanCmd,
946 eANI_BOOLEAN_FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -0700947#else
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530948 status = csrQueueSmeCommand(pMac, pScanCmd,
949 eANI_BOOLEAN_FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -0700950#endif
951 if( !HAL_STATUS_SUCCESS( status ) )
952 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800953 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700954 break;
955 }
956 }
957 else
958 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800959 smsLog( pMac, LOGE, FL(" fail to copy request status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700960 break;
961 }
962 }
963 else
964 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800965 smsLog( pMac, LOGE, FL(" pScanCmd is NULL"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700966 break;
967 }
968 }
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530969 else
970 {
971 smsLog( pMac, LOGE, FL("SId: %d Scanning not enabled"
972 " Scan type=%u, numOfSSIDs=%d P2P search=%d"),
973 sessionId, pScanRequest->requestType,
974 pScanRequest->SSIDs.numOfSSIDs,
975 pScanRequest->p2pSearch );
976 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700977 } while(0);
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530978
979
Jeff Johnson295189b2012-06-20 16:38:30 -0700980 if(!HAL_STATUS_SUCCESS(status) && pScanCmd)
981 {
982 if( eCsrScanIdleScan == pScanCmd->u.scanCmd.reason )
983 {
984 //Set the flag back for restarting idle scan
985 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
986 }
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530987 smsLog( pMac, LOGE, FL(" SId: %d Failed with status=%d"
988 " Scan reason=%u numOfSSIDs=%d"
989 " P2P search=%d scanId=%d"),
990 sessionId, status, pScanCmd->u.scanCmd.reason,
991 pScanRequest->SSIDs.numOfSSIDs, pScanRequest->p2pSearch,
992 pScanCmd->u.scanCmd.scanID );
Jeff Johnson295189b2012-06-20 16:38:30 -0700993 csrReleaseCommandScan(pMac, pScanCmd);
994 }
995
996 return (status);
997}
998
999
1000eHalStatus csrScanRequestResult(tpAniSirGlobal pMac)
1001{
1002 eHalStatus status = eHAL_STATUS_SUCCESS;
1003 tSmeCmd *pScanCmd;
1004
1005 if(pMac->scan.fScanEnable)
1006 {
1007 pScanCmd = csrGetCommandBuffer(pMac);
1008 if(pScanCmd)
1009 {
1010 pScanCmd->command = eSmeCommandScan;
Kiet Lam64c1b492013-07-12 13:56:44 +05301011 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001012 pScanCmd->u.scanCmd.callback = NULL;
1013 pScanCmd->u.scanCmd.pContext = NULL;
1014 pScanCmd->u.scanCmd.reason = eCsrScanGetResult;
1015 //Need to make the following atomic
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07001016 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID; //let it wrap around
Jeff Johnson295189b2012-06-20 16:38:30 -07001017 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
1018 if( !HAL_STATUS_SUCCESS( status ) )
1019 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001020 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001021 csrReleaseCommandScan(pMac, pScanCmd);
1022 }
1023 }
1024 else
1025 {
1026 //log error
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001027 smsLog(pMac, LOGE, FL("can not obtain a common buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001028 status = eHAL_STATUS_RESOURCES;
1029 }
1030 }
1031
1032 return (status);
1033}
1034
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07001035#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
1036eHalStatus csrScanRequestLfrResult(tpAniSirGlobal pMac, tANI_U32 sessionId,
1037 csrScanCompleteCallback callback, void *pContext)
1038{
1039 eHalStatus status = eHAL_STATUS_SUCCESS;
1040 tSmeCmd *pScanCmd;
1041
1042 if (pMac->scan.fScanEnable)
1043 {
1044 pScanCmd = csrGetCommandBuffer(pMac);
1045 if (pScanCmd)
1046 {
1047 pScanCmd->command = eSmeCommandScan;
1048 pScanCmd->sessionId = sessionId;
Kiet Lam64c1b492013-07-12 13:56:44 +05301049 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07001050 pScanCmd->u.scanCmd.callback = callback;
1051 pScanCmd->u.scanCmd.pContext = pContext;
1052 pScanCmd->u.scanCmd.reason = eCsrScanGetLfrResult;
1053 //Need to make the following atomic
1054 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID; //let it wrap around
1055 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_TRUE);
1056 if ( !HAL_STATUS_SUCCESS( status ) )
1057 {
1058 smsLog( pMac, LOGE, FL(" fail to send message status = %d\n"), status );
1059 csrReleaseCommandScan(pMac, pScanCmd);
1060 }
1061 }
1062 else
1063 {
1064 //log error
1065 smsLog(pMac, LOGE, FL("can not obtain a common buffer\n"));
1066 status = eHAL_STATUS_RESOURCES;
1067 }
1068 }
1069
1070 return (status);
1071}
1072#endif //WLAN_FEATURE_ROAM_SCAN_OFFLOAD
Jeff Johnson295189b2012-06-20 16:38:30 -07001073
1074eHalStatus csrScanAllChannels(tpAniSirGlobal pMac, eCsrRequestType reqType)
1075{
1076 eHalStatus status = eHAL_STATUS_SUCCESS;
1077 tANI_U32 scanId;
1078 tCsrScanRequest scanReq;
1079
Kiet Lam64c1b492013-07-12 13:56:44 +05301080 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001081 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
1082 scanReq.scanType = eSIR_ACTIVE_SCAN;
1083 scanReq.requestType = reqType;
1084 scanReq.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1085 scanReq.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Abhishek Singhadd13582016-09-29 17:00:03 +05301086 scanReq.max_chntime_btc_esco =
1087 pMac->roam.configParam.max_chntime_btc_esco;
1088 scanReq.min_chntime_btc_esco =
1089 pMac->roam.configParam.min_chntime_btc_esco;
Jeff Johnson295189b2012-06-20 16:38:30 -07001090 //Scan with invalid sessionId.
1091 //This results in SME using the first available session to scan.
1092 status = csrScanRequest(pMac, CSR_SESSION_ID_INVALID, &scanReq,
1093 &scanId, NULL, NULL);
1094
1095 return (status);
1096}
1097
1098
1099
1100
1101eHalStatus csrIssueRoamAfterLostlinkScan(tpAniSirGlobal pMac, tANI_U32 sessionId, eCsrRoamReason reason)
1102{
1103 eHalStatus status = eHAL_STATUS_FAILURE;
1104 tScanResultHandle hBSSList = NULL;
1105 tCsrScanResultFilter *pScanFilter = NULL;
1106 tANI_U32 roamId = 0;
1107 tCsrRoamProfile *pProfile = NULL;
1108 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1109
Jeff Johnson32d95a32012-09-10 13:15:23 -07001110 if(!pSession)
1111 {
1112 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1113 return eHAL_STATUS_FAILURE;
1114 }
1115
Jeff Johnson295189b2012-06-20 16:38:30 -07001116 do
1117 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001118 smsLog(pMac, LOG1, " csrIssueRoamAfterLostlinkScan called");
Jeff Johnson295189b2012-06-20 16:38:30 -07001119 if(pSession->fCancelRoaming)
1120 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001121 smsLog(pMac, LOGW, " lostlink roaming is cancelled");
Jeff Johnson295189b2012-06-20 16:38:30 -07001122 csrScanStartIdleScan(pMac);
1123 status = eHAL_STATUS_SUCCESS;
1124 break;
1125 }
1126 //Here is the profile we need to connect to
Kiet Lam64c1b492013-07-12 13:56:44 +05301127 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1128 if ( NULL == pScanFilter)
1129 status = eHAL_STATUS_FAILURE;
1130 else
1131 status = eHAL_STATUS_SUCCESS;
1132 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001133 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301134 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001135 if(NULL == pSession->pCurRoamProfile)
1136 {
1137 pScanFilter->EncryptionType.numEntries = 1;
1138 pScanFilter->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_NONE;
1139 }
1140 else
1141 {
1142 //We have to make a copy of pCurRoamProfile because it will be free inside csrRoamIssueConnect
Kiet Lam64c1b492013-07-12 13:56:44 +05301143 pProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1144 if ( NULL == pProfile )
1145 status = eHAL_STATUS_FAILURE;
1146 else
1147 status = eHAL_STATUS_SUCCESS;
1148 if (!HAL_STATUS_SUCCESS(status))
1149 break;
1150 vos_mem_set(pProfile, sizeof(tCsrRoamProfile), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001151 status = csrRoamCopyProfile(pMac, pProfile, pSession->pCurRoamProfile);
1152 if(!HAL_STATUS_SUCCESS(status))
1153 break;
1154 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1155 }//We have a profile
1156 roamId = GET_NEXT_ROAM_ID(&pMac->roam);
1157 if(HAL_STATUS_SUCCESS(status))
1158 {
1159 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1160 if(HAL_STATUS_SUCCESS(status))
1161 {
1162 if(eCsrLostLink1 == reason)
1163 {
1164 //we want to put the last connected BSS to the very beginning, if possible
1165 csrMoveBssToHeadFromBSSID(pMac, &pSession->connectedProfile.bssid, hBSSList);
1166 }
1167 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList, reason,
1168 roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1169 if(!HAL_STATUS_SUCCESS(status))
1170 {
1171 csrScanResultPurge(pMac, hBSSList);
1172 }
1173 }//Have scan result
1174 }
1175 }while(0);
1176 if(pScanFilter)
1177 {
1178 //we need to free memory for filter if profile exists
1179 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301180 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001181 }
1182 if(NULL != pProfile)
1183 {
1184 csrReleaseProfile(pMac, pProfile);
Kiet Lam64c1b492013-07-12 13:56:44 +05301185 vos_mem_free(pProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07001186 }
1187
1188 return (status);
1189}
1190
1191
Ratheesh S Pece1f832015-07-25 15:50:25 +05301192eHalStatus csrScanGetScanChnInfo(tpAniSirGlobal pMac, tSmeCmd *pCommand)
Jeff Johnson295189b2012-06-20 16:38:30 -07001193{
1194 eHalStatus status = eHAL_STATUS_SUCCESS;
1195 tSmeCmd *pScanCmd;
1196
1197 if(pMac->scan.fScanEnable)
1198 {
1199 pScanCmd = csrGetCommandBuffer(pMac);
1200 if(pScanCmd)
1201 {
1202 pScanCmd->command = eSmeCommandScan;
Kiet Lam64c1b492013-07-12 13:56:44 +05301203 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001204 pScanCmd->u.scanCmd.reason = eCsrScanGetScanChnInfo;
1205 //Need to make the following atomic
1206 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Ratheesh S Pece1f832015-07-25 15:50:25 +05301207 pScanCmd->sessionId = pCommand->sessionId;
1208 if( pCommand->u.scanCmd.reason == eCsrScanUserRequest)
1209 {
1210 pScanCmd->u.scanCmd.callback = NULL;
1211 pScanCmd->u.scanCmd.pContext = NULL;
1212 } else {
1213 pScanCmd->u.scanCmd.callback = pCommand->u.scanCmd.callback;
1214 pScanCmd->u.scanCmd.pContext = pCommand->u.scanCmd.pContext;
1215 pScanCmd->u.scanCmd.abortScanIndication =
1216 pCommand->u.scanCmd.abortScanIndication;
1217 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001218 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
1219 if( !HAL_STATUS_SUCCESS( status ) )
1220 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001221 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001222 csrReleaseCommandScan(pMac, pScanCmd);
1223 }
1224 }
1225 else
1226 {
1227 //log error
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001228 smsLog(pMac, LOGE, FL("can not obtain a common buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001229 status = eHAL_STATUS_RESOURCES;
1230 }
1231 }
1232
1233 return (status);
1234}
1235
1236
1237eHalStatus csrScanHandleFailedLostlink1(tpAniSirGlobal pMac, tANI_U32 sessionId)
1238{
1239 eHalStatus status = eHAL_STATUS_FAILURE;
1240 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1241
Jeff Johnson32d95a32012-09-10 13:15:23 -07001242 if(!pSession)
1243 {
1244 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1245 return eHAL_STATUS_FAILURE;
1246 }
1247
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001248 smsLog(pMac, LOGW, " Lostlink scan 1 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001249 if(pSession->fCancelRoaming)
1250 {
1251 csrScanStartIdleScan(pMac);
1252 }
1253 else if(pSession->pCurRoamProfile)
1254 {
1255 //We fail lostlink1 but there may be other BSS in the cached result fit the profile. Give it a try first
1256 if(pSession->pCurRoamProfile->SSIDs.numOfSSIDs == 0 ||
1257 pSession->pCurRoamProfile->SSIDs.numOfSSIDs > 1)
1258 {
1259 //try lostlink scan2
1260 status = csrScanRequestLostLink2(pMac, sessionId);
1261 }
1262 else if(!pSession->pCurRoamProfile->ChannelInfo.ChannelList ||
1263 pSession->pCurRoamProfile->ChannelInfo.ChannelList[0] == 0)
1264 {
1265 //go straight to lostlink scan3
1266 status = csrScanRequestLostLink3(pMac, sessionId);
1267 }
1268 else
1269 {
1270 //we are done with lostlink
1271 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1272 {
1273 csrScanStartIdleScan(pMac);
1274 }
1275 status = eHAL_STATUS_SUCCESS;
1276 }
1277 }
1278 else
1279 {
1280 status = csrScanRequestLostLink3(pMac, sessionId);
1281 }
1282
1283 return (status);
1284}
1285
1286
1287
1288eHalStatus csrScanHandleFailedLostlink2(tpAniSirGlobal pMac, tANI_U32 sessionId)
1289{
1290 eHalStatus status = eHAL_STATUS_FAILURE;
1291 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1292
Jeff Johnson32d95a32012-09-10 13:15:23 -07001293 if(!pSession)
1294 {
1295 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1296 return eHAL_STATUS_FAILURE;
1297 }
1298
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001299 smsLog(pMac, LOGW, " Lostlink scan 2 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001300 if(pSession->fCancelRoaming)
1301 {
1302 csrScanStartIdleScan(pMac);
1303 }
1304 else if(!pSession->pCurRoamProfile || !pSession->pCurRoamProfile->ChannelInfo.ChannelList ||
1305 pSession->pCurRoamProfile->ChannelInfo.ChannelList[0] == 0)
1306 {
1307 //try lostlink scan3
1308 status = csrScanRequestLostLink3(pMac, sessionId);
1309 }
1310 else
1311 {
1312 //we are done with lostlink
1313 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1314 {
1315 csrScanStartIdleScan(pMac);
1316 }
1317 }
1318
1319 return (status);
1320}
1321
1322
1323
1324eHalStatus csrScanHandleFailedLostlink3(tpAniSirGlobal pMac, tANI_U32 sessionId)
1325{
1326 eHalStatus status = eHAL_STATUS_SUCCESS;
1327
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001328 smsLog(pMac, LOGW, " Lostlink scan 3 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001329 if(eANI_BOOLEAN_TRUE == csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1330 {
1331 //we are done with lostlink
1332 csrScanStartIdleScan(pMac);
1333 }
1334
1335 return (status);
1336}
1337
1338
1339
1340
1341//Lostlink1 scan is to actively scan the last connected profile's SSID on all matched BSS channels.
1342//If no roam profile (it should not), it is like lostlinkscan3
1343eHalStatus csrScanRequestLostLink1( tpAniSirGlobal pMac, tANI_U32 sessionId )
1344{
1345 eHalStatus status = eHAL_STATUS_SUCCESS;
1346 tSmeCmd *pCommand = NULL;
1347 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1348 tCsrScanResultFilter *pScanFilter = NULL;
1349 tScanResultHandle hBSSList = NULL;
1350 tCsrScanResultInfo *pScanResult = NULL;
1351 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1352
Jeff Johnson32d95a32012-09-10 13:15:23 -07001353 if(!pSession)
1354 {
1355 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1356 return eHAL_STATUS_FAILURE;
1357 }
1358
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001359 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001360 do
1361 {
1362 pCommand = csrGetCommandBuffer(pMac);
1363 if(!pCommand)
1364 {
1365 status = eHAL_STATUS_RESOURCES;
1366 break;
1367 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301368 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001369 pCommand->command = eSmeCommandScan;
1370 pCommand->sessionId = (tANI_U8)sessionId;
1371 pCommand->u.scanCmd.reason = eCsrScanLostLink1;
1372 pCommand->u.scanCmd.callback = NULL;
1373 pCommand->u.scanCmd.pContext = NULL;
1374 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1375 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Abhishek Singhadd13582016-09-29 17:00:03 +05301376 pCommand->u.scanCmd.u.scanRequest.max_chntime_btc_esco =
1377 pMac->roam.configParam.max_chntime_btc_esco;
1378 pCommand->u.scanCmd.u.scanRequest.min_chntime_btc_esco =
1379 pMac->roam.configParam.min_chntime_btc_esco;
Jeff Johnson295189b2012-06-20 16:38:30 -07001380 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
1381 if(pSession->connectedProfile.SSID.length)
1382 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301383 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList = vos_mem_malloc(sizeof(tCsrSSIDInfo));
1384 if ( NULL == pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList )
1385 status = eHAL_STATUS_FAILURE;
1386 else
1387 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001388 if(!HAL_STATUS_SUCCESS(status))
1389 {
1390 break;
1391 }
1392 pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 1;
Kiet Lam64c1b492013-07-12 13:56:44 +05301393 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID,
1394 &pSession->connectedProfile.SSID, sizeof(tSirMacSSid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001395 }
1396 else
1397 {
1398 pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 0;
1399 }
1400 if(pSession->pCurRoamProfile)
1401 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301402 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1403 if ( NULL == pScanFilter )
1404 status = eHAL_STATUS_FAILURE;
1405 else
1406 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001407 if(!HAL_STATUS_SUCCESS(status))
1408 {
1409 break;
1410 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301411 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001412 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
1413 if(!HAL_STATUS_SUCCESS(status))
1414 {
1415 break;
1416 }
1417 //Don't change variable status here because whether we can get result or not, the command goes to PE.
1418 //The status is also used to indicate whether the command is queued. Not success meaning not queue
1419 if(HAL_STATUS_SUCCESS((csrScanGetResult(pMac, pScanFilter, &hBSSList))) && hBSSList)
1420 {
1421 tANI_U8 i, nChn = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05301422 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList =
1423 vos_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
1424 if ( NULL == pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
1425 status = eHAL_STATUS_FAILURE;
1426 else
1427 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001428 if(!HAL_STATUS_SUCCESS(status))
1429 {
1430 break;
1431 }
1432 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) &&
1433 nChn < WNI_CFG_VALID_CHANNEL_LIST_LEN)
1434 {
1435 for(i = 0; i < nChn; i++)
1436 {
1437 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1438 pScanResult->BssDescriptor.channelId)
1439 {
1440 break;
1441 }
1442 }
1443 if(i == nChn)
1444 {
1445 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pScanResult->BssDescriptor.channelId;
1446 }
1447 }
1448 //Include the last connected BSS' channel
1449 if(csrRoamIsChannelValid(pMac, pSession->connectedProfile.operationChannel))
1450 {
1451 for(i = 0; i < nChn; i++)
1452 {
1453 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1454 pSession->connectedProfile.operationChannel)
1455 {
1456 break;
1457 }
1458 }
1459 if(i == nChn)
1460 {
1461 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pSession->connectedProfile.operationChannel;
1462 }
1463 }
1464 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nChn;
1465 }
1466 else
1467 {
1468 if(csrRoamIsChannelValid(pMac, pSession->connectedProfile.operationChannel))
1469 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301470 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(1);
1471 if ( NULL == pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
1472 status = eHAL_STATUS_FAILURE;
1473 else
1474 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001475 //just try the last connected channel
1476 if(HAL_STATUS_SUCCESS(status))
1477 {
1478 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[0] = pSession->connectedProfile.operationChannel;
1479 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 1;
1480 }
1481 else
1482 {
1483 break;
1484 }
1485 }
1486 }
1487 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301488 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001489 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
1490 if( !HAL_STATUS_SUCCESS( status ) )
1491 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001492 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001493 break;
1494 }
1495 } while( 0 );
1496
1497 if(!HAL_STATUS_SUCCESS(status))
1498 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001499 smsLog(pMac, LOGW, " csrScanRequestLostLink1 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001500 if(pCommand)
1501 {
1502 csrReleaseCommandScan(pMac, pCommand);
1503 }
1504 status = csrScanHandleFailedLostlink1( pMac, sessionId );
1505 }
1506 if(pScanFilter)
1507 {
1508 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301509 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001510 }
1511 if(hBSSList)
1512 {
1513 csrScanResultPurge(pMac, hBSSList);
1514 }
1515
1516 return( status );
1517}
1518
1519
1520//Lostlink2 scan is to actively scan the all SSIDs of the last roaming profile's on all matched BSS channels.
1521//Since MAC doesn't support multiple SSID, we scan all SSIDs and filter them afterwards
1522eHalStatus csrScanRequestLostLink2( tpAniSirGlobal pMac, tANI_U32 sessionId )
1523{
1524 eHalStatus status = eHAL_STATUS_SUCCESS;
1525 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1526 tCsrScanResultFilter *pScanFilter = NULL;
1527 tScanResultHandle hBSSList = NULL;
1528 tCsrScanResultInfo *pScanResult = NULL;
1529 tSmeCmd *pCommand = NULL;
1530 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1531
Jeff Johnson32d95a32012-09-10 13:15:23 -07001532 if(!pSession)
1533 {
1534 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1535 return eHAL_STATUS_FAILURE;
1536 }
1537
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001538 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001539 do
1540 {
1541 pCommand = csrGetCommandBuffer(pMac);
1542 if(!pCommand)
1543 {
1544 status = eHAL_STATUS_RESOURCES;
1545 break;
1546 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301547 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001548 pCommand->command = eSmeCommandScan;
1549 pCommand->sessionId = (tANI_U8)sessionId;
1550 pCommand->u.scanCmd.reason = eCsrScanLostLink2;
1551 pCommand->u.scanCmd.callback = NULL;
1552 pCommand->u.scanCmd.pContext = NULL;
1553 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1554 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Abhishek Singhadd13582016-09-29 17:00:03 +05301555 pCommand->u.scanCmd.u.scanRequest.max_chntime_btc_esco =
1556 pMac->roam.configParam.max_chntime_btc_esco;
1557 pCommand->u.scanCmd.u.scanRequest.min_chntime_btc_esco =
1558 pMac->roam.configParam.min_chntime_btc_esco;
Jeff Johnson295189b2012-06-20 16:38:30 -07001559 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
1560 if(pSession->pCurRoamProfile)
1561 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301562 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1563 if ( NULL == pScanFilter )
1564 status = eHAL_STATUS_FAILURE;
1565 else
1566 status = eHAL_STATUS_SUCCESS;
1567 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001568 {
1569 break;
1570 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301571 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001572 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
1573 if(!HAL_STATUS_SUCCESS(status))
1574 {
1575 break;
1576 }
1577 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1578 if(!HAL_STATUS_SUCCESS(status))
1579 {
1580 break;
1581 }
1582 if(hBSSList)
1583 {
1584 tANI_U8 i, nChn = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05301585 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList =
1586 vos_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
1587 if ( NULL == pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
1588 status = eHAL_STATUS_FAILURE;
1589 else
1590 status = eHAL_STATUS_SUCCESS;
1591 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001592 {
1593 break;
1594 }
1595 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) &&
1596 nChn < WNI_CFG_VALID_CHANNEL_LIST_LEN)
1597 {
1598 for(i = 0; i < nChn; i++)
1599 {
1600 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1601 pScanResult->BssDescriptor.channelId)
1602 {
1603 break;
1604 }
1605 }
1606 if(i == nChn)
1607 {
1608 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pScanResult->BssDescriptor.channelId;
1609 }
1610 }
1611 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nChn;
1612 }
1613 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301614 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001615 //Put to the head in pending queue
1616 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_TRUE);
1617 if( !HAL_STATUS_SUCCESS( status ) )
1618 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001619 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001620 break;
1621 }
1622 } while( 0 );
1623
1624 if(!HAL_STATUS_SUCCESS(status))
1625 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001626 smsLog(pMac, LOGW, " csrScanRequestLostLink2 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001627 if(pCommand)
1628 {
1629 csrReleaseCommandScan(pMac, pCommand);
1630 }
1631 status = csrScanHandleFailedLostlink2( pMac, sessionId );
1632 }
1633 if(pScanFilter)
1634 {
1635 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301636 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001637 }
1638 if(hBSSList)
1639 {
1640 csrScanResultPurge(pMac, hBSSList);
1641 }
1642
1643 return( status );
1644}
1645
1646
1647//To actively scan all valid channels
1648eHalStatus csrScanRequestLostLink3( tpAniSirGlobal pMac, tANI_U32 sessionId )
1649{
1650 eHalStatus status = eHAL_STATUS_SUCCESS;
1651 tSmeCmd *pCommand;
1652 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1653
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001654 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001655 do
1656 {
1657 pCommand = csrGetCommandBuffer(pMac);
1658 if(!pCommand)
1659 {
1660 status = eHAL_STATUS_RESOURCES;
1661 break;
1662 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301663 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001664 pCommand->command = eSmeCommandScan;
1665 pCommand->sessionId = (tANI_U8)sessionId;
1666 pCommand->u.scanCmd.reason = eCsrScanLostLink3;
1667 pCommand->u.scanCmd.callback = NULL;
1668 pCommand->u.scanCmd.pContext = NULL;
1669 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1670 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Abhishek Singhadd13582016-09-29 17:00:03 +05301671 pCommand->u.scanCmd.u.scanRequest.max_chntime_btc_esco =
1672 pMac->roam.configParam.max_chntime_btc_esco;
1673 pCommand->u.scanCmd.u.scanRequest.min_chntime_btc_esco =
1674 pMac->roam.configParam.min_chntime_btc_esco;
Jeff Johnson295189b2012-06-20 16:38:30 -07001675 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Kiet Lam64c1b492013-07-12 13:56:44 +05301676 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001677 //Put to the head of pending queue
1678 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_TRUE);
1679 if( !HAL_STATUS_SUCCESS( status ) )
1680 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001681 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001682 break;
1683 }
1684 } while( 0 );
1685 if(!HAL_STATUS_SUCCESS(status))
1686 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001687 smsLog(pMac, LOGW, " csrScanRequestLostLink3 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001688 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1689 {
1690 csrScanStartIdleScan(pMac);
1691 }
1692 if(pCommand)
1693 {
1694 csrReleaseCommandScan(pMac, pCommand);
1695 }
1696 }
1697
1698 return( status );
1699}
1700
1701
1702eHalStatus csrScanHandleSearchForSSID(tpAniSirGlobal pMac, tSmeCmd *pCommand)
1703{
1704 eHalStatus status = eHAL_STATUS_FAILURE;
1705 tScanResultHandle hBSSList = CSR_INVALID_SCANRESULT_HANDLE;
1706 tCsrScanResultFilter *pScanFilter = NULL;
1707 tCsrRoamProfile *pProfile = pCommand->u.scanCmd.pToRoamProfile;
1708 tANI_U32 sessionId = pCommand->sessionId;
Abhishek Singhd61b97a2015-12-17 15:23:52 +05301709 tCsrRoamSession *pSession = CSR_GET_SESSION(pMac, sessionId);
1710
Jeff Johnson295189b2012-06-20 16:38:30 -07001711 do
1712 {
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001713#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
1714 //if this scan is for LFR
1715 if(pMac->roam.neighborRoamInfo.uOsRequestedHandoff)
1716 {
1717 //notify LFR state m/c
1718 if(eHAL_STATUS_SUCCESS != csrNeighborRoamSssidScanDone(pMac, eHAL_STATUS_SUCCESS))
1719 {
Mukul Sharma20aa6582014-08-07 21:36:12 +05301720 csrNeighborRoamStartLfrScan(pMac, REASON_OS_REQUESTED_ROAMING_NOW);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001721 }
1722 status = eHAL_STATUS_SUCCESS;
1723 break;
1724 }
1725#endif
Abhishek Singhd61b97a2015-12-17 15:23:52 +05301726 if (!pSession)
1727 {
1728 smsLog(pMac, LOGE, FL("session %d not found"), sessionId);
1729 break;
1730 }
Abhishek Singh5de9efd2017-06-15 10:22:39 +05301731 /* If Disconnect is already issued from HDD no need to issue connect */
1732 if (pSession->abortConnection)
Abhishek Singhd61b97a2015-12-17 15:23:52 +05301733 {
1734 smsLog(pMac, LOGE,
1735 FL("Disconnect in progress, no need to issue connect"));
1736 break;
1737 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001738 //If there is roam command waiting, ignore this roam because the newer roam command is the one to execute
1739 if(csrIsRoamCommandWaitingForSession(pMac, sessionId))
1740 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001741 smsLog(pMac, LOGW, FL(" aborts because roam command waiting"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001742 break;
1743 }
1744 if(pProfile == NULL)
1745 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301746 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1747 if ( NULL == pScanFilter )
1748 status = eHAL_STATUS_FAILURE;
1749 else
1750 status = eHAL_STATUS_SUCCESS;
1751 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001752 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301753 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001754 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1755 if(!HAL_STATUS_SUCCESS(status))
1756 break;
1757 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1758 if(!HAL_STATUS_SUCCESS(status))
1759 break;
1760 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList, eCsrHddIssued,
1761 pCommand->u.scanCmd.roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1762 if(!HAL_STATUS_SUCCESS(status))
1763 {
1764 break;
1765 }
1766 }while(0);
1767 if(!HAL_STATUS_SUCCESS(status))
1768 {
1769 if(CSR_INVALID_SCANRESULT_HANDLE != hBSSList)
1770 {
1771 csrScanResultPurge(pMac, hBSSList);
1772 }
1773 //We haven't done anything to this profile
Abhishek Singh72c2f4e2016-07-22 11:25:43 +05301774 csrRoamCallCallback(pMac, sessionId, NULL,
1775 pCommand->u.scanCmd.roamId,
1776 eCSR_ROAM_ASSOCIATION_FAILURE,
1777 eCSR_ROAM_RESULT_SCAN_FOR_SSID_FAILURE);
Jeff Johnson295189b2012-06-20 16:38:30 -07001778 //In case we have nothing else to do, restart idle scan
1779 if(csrIsConnStateDisconnected(pMac, sessionId) && !csrIsRoamCommandWaiting(pMac))
1780 {
1781 status = csrScanStartIdleScan(pMac);
1782 }
1783#ifdef FEATURE_WLAN_BTAMP_UT_RF
1784 //In case of WDS station, let it retry.
1785 if( CSR_IS_WDS_STA(pProfile) )
1786 {
1787 //Save the roma profile so we can retry
1788 csrFreeRoamProfile( pMac, sessionId );
Kiet Lam64c1b492013-07-12 13:56:44 +05301789 pSession->pCurRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1790 if ( NULL != pSession->pCurRoamProfile )
Jeff Johnson295189b2012-06-20 16:38:30 -07001791 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301792 vos_mem_set(pSession->pCurRoamProfilee, sizeof(tCsrRoamProfile), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001793 csrRoamCopyProfile(pMac, pSession->pCurRoamProfile, pProfile);
1794 }
1795 csrRoamStartJoinRetryTimer(pMac, sessionId, CSR_JOIN_RETRY_TIMEOUT_PERIOD);
1796 }
1797#endif
1798 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301799 if (pScanFilter)
Jeff Johnson295189b2012-06-20 16:38:30 -07001800 {
1801 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301802 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001803 }
1804
1805 return (status);
1806}
1807
1808
1809eHalStatus csrScanHandleSearchForSSIDFailure(tpAniSirGlobal pMac, tSmeCmd *pCommand)
1810{
1811 eHalStatus status = eHAL_STATUS_SUCCESS;
1812 tANI_U32 sessionId = pCommand->sessionId;
1813 tCsrRoamProfile *pProfile = pCommand->u.scanCmd.pToRoamProfile;
1814 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001815#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
1816 //if this scan is for LFR
1817 if(pMac->roam.neighborRoamInfo.uOsRequestedHandoff)
1818 {
1819 //notify LFR state m/c
1820 if(eHAL_STATUS_SUCCESS != csrNeighborRoamSssidScanDone(pMac, eHAL_STATUS_FAILURE))
1821 {
Mukul Sharma20aa6582014-08-07 21:36:12 +05301822 csrNeighborRoamStartLfrScan(pMac, REASON_OS_REQUESTED_ROAMING_NOW);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001823 }
1824 return eHAL_STATUS_SUCCESS;
1825 }
1826#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -07001827 if(!pSession)
1828 {
1829 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1830 return eHAL_STATUS_FAILURE;
1831 }
1832
Jeff Johnson295189b2012-06-20 16:38:30 -07001833#if defined(WLAN_DEBUG)
1834 if(pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs == 1)
1835 {
1836 char str[36];
Kiet Lam64c1b492013-07-12 13:56:44 +05301837 vos_mem_copy(str,
1838 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.ssId,
1839 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.length);
Jeff Johnson295189b2012-06-20 16:38:30 -07001840 str[pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.length] = 0;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001841 smsLog(pMac, LOGW, FL(" SSID = %s"), str);
Jeff Johnson295189b2012-06-20 16:38:30 -07001842 }
1843#endif
1844 //Check whether it is for start ibss. No need to do anything if it is a JOIN request
1845 if(pProfile && CSR_IS_START_IBSS(pProfile))
1846 {
1847 status = csrRoamIssueConnect(pMac, sessionId, pProfile, NULL, eCsrHddIssued,
1848 pCommand->u.scanCmd.roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1849 if(!HAL_STATUS_SUCCESS(status))
1850 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001851 smsLog(pMac, LOGE, FL("failed to issue startIBSS command with status = 0x%08X"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001852 csrRoamCallCallback(pMac, sessionId, NULL, pCommand->u.scanCmd.roamId, eCSR_ROAM_FAILED, eCSR_ROAM_RESULT_FAILURE);
1853 }
1854 }
1855 else
1856 {
1857 eCsrRoamResult roamResult = eCSR_ROAM_RESULT_FAILURE;
1858
1859 if(csrIsConnStateDisconnected(pMac, sessionId) &&
1860 !csrIsRoamCommandWaitingForSession(pMac, sessionId))
1861 {
1862 status = csrScanStartIdleScan(pMac);
1863 }
1864 if((NULL == pProfile) || !csrIsBssTypeIBSS(pProfile->BSSType))
1865 {
1866 //Only indicate assoc_completion if we indicate assoc_start.
1867 if(pSession->bRefAssocStartCnt > 0)
1868 {
1869 tCsrRoamInfo *pRoamInfo = NULL, roamInfo;
Kiet Lam64c1b492013-07-12 13:56:44 +05301870 vos_mem_set(&roamInfo, sizeof(tCsrRoamInfo), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001871 pRoamInfo = &roamInfo;
1872 if(pCommand->u.roamCmd.pRoamBssEntry)
1873 {
1874 tCsrScanResult *pScanResult =
1875 GET_BASE_ADDR(pCommand->u.roamCmd.pRoamBssEntry,
1876 tCsrScanResult, Link);
1877 roamInfo.pBssDesc = &pScanResult->Result.BssDescriptor;
1878 }
1879 roamInfo.statusCode = pSession->joinFailStatusCode.statusCode;
1880 roamInfo.reasonCode = pSession->joinFailStatusCode.reasonCode;
1881 pSession->bRefAssocStartCnt--;
1882 csrRoamCallCallback(pMac, sessionId, pRoamInfo,
1883 pCommand->u.scanCmd.roamId,
1884 eCSR_ROAM_ASSOCIATION_COMPLETION,
Abhishek Singh72c2f4e2016-07-22 11:25:43 +05301885 eCSR_ROAM_RESULT_SCAN_FOR_SSID_FAILURE);
Jeff Johnson295189b2012-06-20 16:38:30 -07001886 }
Madan Mohan Koyyalamudiee255f12012-09-28 15:41:19 -07001887 else
1888 {
1889 csrRoamCallCallback(pMac, sessionId, NULL,
1890 pCommand->u.scanCmd.roamId,
1891 eCSR_ROAM_ASSOCIATION_FAILURE,
Abhishek Singh72c2f4e2016-07-22 11:25:43 +05301892 eCSR_ROAM_RESULT_SCAN_FOR_SSID_FAILURE);
Madan Mohan Koyyalamudiee255f12012-09-28 15:41:19 -07001893 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001894#ifdef FEATURE_WLAN_BTAMP_UT_RF
1895 //In case of WDS station, let it retry.
1896 if( CSR_IS_WDS_STA(pProfile) )
1897 {
1898 //Save the roma profile so we can retry
1899 csrFreeRoamProfile( pMac, sessionId );
Kiet Lam64c1b492013-07-12 13:56:44 +05301900 pSession->pCurRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1901 if ( NULL != pSession->pCurRoamProfile )
Jeff Johnson295189b2012-06-20 16:38:30 -07001902 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301903 vos_mem_set(pSession->pCurRoamProfile, sizeof(tCsrRoamProfile), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001904 csrRoamCopyProfile(pMac, pSession->pCurRoamProfile, pProfile);
1905 }
1906 csrRoamStartJoinRetryTimer(pMac, sessionId, CSR_JOIN_RETRY_TIMEOUT_PERIOD);
1907 }
1908#endif
1909 }
1910 else
1911 {
1912 roamResult = eCSR_ROAM_RESULT_IBSS_START_FAILED;
1913 }
1914 csrRoamCompletion(pMac, sessionId, NULL, pCommand, roamResult, eANI_BOOLEAN_FALSE);
1915 }
1916
1917 return (status);
1918}
1919
1920
1921//After scan for cap changes, issue a roaming command to either reconnect to the AP or pick another one to connect
1922eHalStatus csrScanHandleCapChangeScanComplete(tpAniSirGlobal pMac, tANI_U32 sessionId)
1923{
1924 eHalStatus status = eHAL_STATUS_FAILURE;
1925 tScanResultHandle hBSSList = NULL;
1926 tCsrScanResultFilter *pScanFilter = NULL;
1927 tANI_U32 roamId = 0;
1928 tCsrRoamProfile *pProfile = NULL;
1929 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1930
1931 do
1932 {
1933 //Here is the profile we need to connect to
Kiet Lam64c1b492013-07-12 13:56:44 +05301934 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1935 if ( NULL == pScanFilter )
1936 status = eHAL_STATUS_FAILURE;
1937 else
1938 status = eHAL_STATUS_SUCCESS;
1939 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001940 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301941 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
1942 if (NULL == pSession) break;
1943 if (NULL == pSession->pCurRoamProfile)
Jeff Johnson295189b2012-06-20 16:38:30 -07001944 {
1945 pScanFilter->EncryptionType.numEntries = 1;
1946 pScanFilter->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_NONE;
1947 }
1948 else
1949 {
1950 //We have to make a copy of pCurRoamProfile because it will be free inside csrRoamIssueConnect
Kiet Lam64c1b492013-07-12 13:56:44 +05301951 pProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1952 if ( NULL == pProfile )
1953 status = eHAL_STATUS_FAILURE;
1954 else
1955 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001956 if(!HAL_STATUS_SUCCESS(status))
1957 break;
1958 status = csrRoamCopyProfile(pMac, pProfile, pSession->pCurRoamProfile);
1959 if(!HAL_STATUS_SUCCESS(status))
1960 break;
1961 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1962 }//We have a profile
1963 roamId = GET_NEXT_ROAM_ID(&pMac->roam);
1964 if(HAL_STATUS_SUCCESS(status))
1965 {
1966 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1967 if(HAL_STATUS_SUCCESS(status))
1968 {
1969 //we want to put the last connected BSS to the very beginning, if possible
1970 csrMoveBssToHeadFromBSSID(pMac, &pSession->connectedProfile.bssid, hBSSList);
1971 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList,
1972 eCsrCapsChange, 0, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1973 if(!HAL_STATUS_SUCCESS(status))
1974 {
1975 csrScanResultPurge(pMac, hBSSList);
1976 }
1977 }//Have scan result
1978 else
1979 {
Arif Hussaina7c8e412013-11-20 11:06:42 -08001980 smsLog(pMac, LOGW, FL("cannot find matching BSS of "
1981 MAC_ADDRESS_STR),
1982 MAC_ADDR_ARRAY(pSession->connectedProfile.bssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001983 //Disconnect
1984 csrRoamDisconnectInternal(pMac, sessionId, eCSR_DISCONNECT_REASON_UNSPECIFIED);
1985 }
1986 }
1987 }while(0);
1988 if(pScanFilter)
1989 {
1990 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301991 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001992 }
1993 if(NULL != pProfile)
1994 {
1995 csrReleaseProfile(pMac, pProfile);
Kiet Lam64c1b492013-07-12 13:56:44 +05301996 vos_mem_free(pProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07001997 }
1998
1999 return (status);
2000}
2001
2002
2003
2004eHalStatus csrScanResultPurge(tpAniSirGlobal pMac, tScanResultHandle hScanList)
2005{
2006 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
2007 tScanResultList *pScanList = (tScanResultList *)hScanList;
2008
2009 if(pScanList)
2010 {
2011 status = csrLLScanPurgeResult(pMac, &pScanList->List);
2012 csrLLClose(&pScanList->List);
Kiet Lam64c1b492013-07-12 13:56:44 +05302013 vos_mem_free(pScanList);
Jeff Johnson295189b2012-06-20 16:38:30 -07002014 }
2015 return (status);
2016}
2017
2018
2019static tANI_U32 csrGetBssPreferValue(tpAniSirGlobal pMac, int rssi)
2020{
2021 tANI_U32 ret = 0;
2022 int i = CSR_NUM_RSSI_CAT - 1;
2023
2024 while(i >= 0)
2025 {
2026 if(rssi >= pMac->roam.configParam.RSSICat[i])
2027 {
2028 ret = pMac->roam.configParam.BssPreferValue[i];
2029 break;
2030 }
2031 i--;
2032 };
2033
2034 return (ret);
2035}
2036
2037
2038//Return a CapValue base on the capabilities of a BSS
2039static tANI_U32 csrGetBssCapValue(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes)
2040{
2041 tANI_U32 ret = CSR_BSS_CAP_VALUE_NONE;
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08002042#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_ESE) || defined(FEATURE_WLAN_LFR)
Madan Mohan Koyyalamudid5026072012-11-30 14:56:21 -08002043 if(CSR_IS_ROAM_PREFER_5GHZ(pMac))
2044 {
2045 if((pBssDesc) && CSR_IS_CHANNEL_5GHZ(pBssDesc->channelId))
2046 {
2047 ret += CSR_BSS_CAP_VALUE_5GHZ;
2048 }
2049 }
2050#endif
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002051 /* if strict select 5GHz is non-zero then ignore the capability checking */
2052 if (pIes && !CSR_IS_SELECT_5GHZ_MARGIN(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -07002053 {
2054 //We only care about 11N capability
2055 if(pIes->HTCaps.present)
2056 {
2057 ret += CSR_BSS_CAP_VALUE_HT;
2058 }
2059 if(CSR_IS_QOS_BSS(pIes))
2060 {
2061 ret += CSR_BSS_CAP_VALUE_WMM;
2062 //Give advantage to UAPSD
2063 if(CSR_IS_UAPSD_BSS(pIes))
2064 {
2065 ret += CSR_BSS_CAP_VALUE_UAPSD;
2066 }
2067 }
2068 }
2069
2070 return (ret);
2071}
2072
Kapil Guptab3a981b2016-06-26 13:36:51 +05302073#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
2074
2075/* Calculate channel weight based on other APs RSSI and count for
2076 * PER based roaming */
2077static tANI_U32 GetPERRoamRssiCountWeight(tANI_S32 rssi, tANI_S32 count)
2078{
2079 tANI_S32 rssiWeight=0;
2080 tANI_S32 countWeight=0;
2081 tANI_S32 rssicountWeight=0;
2082
2083 rssiWeight = ROAMING_RSSI_WEIGHT * (rssi - MIN_RSSI)
2084 /(MAX_RSSI - MIN_RSSI);
2085
2086 if(rssiWeight > ROAMING_RSSI_WEIGHT)
2087 rssiWeight = ROAMING_RSSI_WEIGHT;
2088 else if (rssiWeight < 0)
2089 rssiWeight = 0;
2090
2091 countWeight = ROAM_AP_COUNT_WEIGHT * (count + ROAM_MIN_COUNT)
2092 /(ROAM_MAX_COUNT + ROAM_MIN_COUNT);
2093
2094 if(countWeight > ROAM_AP_COUNT_WEIGHT)
2095 countWeight = ROAM_AP_COUNT_WEIGHT;
2096
2097 rssicountWeight = ROAM_MAX_WEIGHT - (rssiWeight + countWeight);
2098
2099 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO_HIGH,
2100 FL("rssiWeight=%d, countWeight=%d, rssicountWeight=%d rssi=%d count=%d"),
2101 rssiWeight, countWeight, rssicountWeight, rssi, count);
2102
2103 return rssicountWeight;
2104}
2105
2106/* Calculate BSS score based on AP capabilty and channel condition
2107 * for PER based roaming */
2108static tANI_U32 calculateBssScore(tSirBssDescription *bssInfo,
2109 tANI_S32 best_rssi, tANI_S32 ap_cnt, tANI_S32 cca)
2110{
2111 tANI_S32 score = 0;
2112 tANI_S32 ap_load = 0;
2113 tANI_S32 normalised_width = PER_ROAM_20MHZ;
Sen, Devendra6940d0c2016-09-07 12:42:46 +05302114 tANI_S32 normalised_rssi = 0;
Kapil Guptab3a981b2016-06-26 13:36:51 +05302115 tANI_S32 channel_weight;
2116 if (bssInfo->rssi) {
2117 /* Calculate % of rssi we are getting
2118 * max = 100
2119 * min = 0
2120 * less than -40 = 100%
2121 * -40 - -55 = 80%
2122 * -55 - -65 = 60%
2123 * below that = 100 - value
2124 * TODO: a linear decrement function after PER_ROAM_GOOD_RSSI_WEIGHT
2125 * since throughput decrements linearly after PER_ROAM_GOOD_RSSI_WEIGHT
2126 **/
2127 if (bssInfo->rssi >= PER_EXCELENT_RSSI)
2128 normalised_rssi = PER_ROAM_EXCELLENT_RSSI_WEIGHT;
2129 else if (bssInfo->rssi >= PER_GOOD_RSSI)
2130 normalised_rssi = PER_ROAM_GOOD_RSSI_WEIGHT;
2131 else if (bssInfo->rssi >= PER_POOR_RSSI)
2132 normalised_rssi = PER_ROAM_BAD_RSSI_WEIGHT;
2133 else
2134 normalised_rssi = bssInfo->rssi - MIN_RSSI;
2135
2136 /* Calculate score part for rssi */
2137 score += (normalised_rssi * RSSI_WEIGHTAGE);
2138 }
2139
2140 if (bssInfo->HTCapsPresent) {
2141 score += PER_ROAM_MAX_WEIGHT * HT_CAPABILITY_WEIGHTAGE;
2142 }
2143 /* VHT caps are available */
2144 if (bssInfo->vhtCapsPresent) {
2145 score += PER_ROAM_MAX_WEIGHT * VHT_CAP_WEIGHTAGE;
2146 }
2147
2148 if (bssInfo->beacomformingCapable)
2149 score += PER_ROAM_MAX_WEIGHT * BEAMFORMING_CAP_WEIGHTAGE;
2150
2151 /* Channel width 20Mhz=30, 40Mhz=70, 80Mhz=100 */
2152 if (bssInfo->chanWidth == eHT_CHANNEL_WIDTH_80MHZ)
2153 normalised_width = PER_ROAM_80MHZ;
2154 else if (bssInfo->chanWidth == eHT_CHANNEL_WIDTH_40MHZ)
2155 normalised_width = PER_ROAM_40MHZ;
2156 else
2157 normalised_width = PER_ROAM_20MHZ;
2158 score += normalised_width * CHAN_WIDTH_WEIGHTAGE;
2159
2160 /* Channel Band, Channel Number */
2161 if (GetRFBand(bssInfo->channelId) == SIR_BAND_5_GHZ)
2162 score += PER_ROAM_MAX_WEIGHT * CHAN_BAND_WEIGHTAGE;
2163
2164 /* WMM emabled */
2165 if (bssInfo->wmeInfoPresent)
2166 score += PER_ROAM_MAX_WEIGHT * WMM_WEIGHTAGE;
2167
2168#if defined(FEATURE_WLAN_ESE) || defined(WLAN_FEATURE_ROAM_SCAN_OFFLOAD)
2169 /* AP load Ie */
2170 if (bssInfo->QBSSLoad_present) {
2171 /* calculate value in % */
2172 ap_load = (bssInfo->QBSS_ChanLoad * PER_ROAM_MAX_WEIGHT) / MAX_AP_LOAD;
2173 }
2174#endif
Kapil Guptab3a981b2016-06-26 13:36:51 +05302175 /* if CCA consideration is off in configuration, FW will send 50% for
2176 every channel which should be considered as it is */
2177 if (ap_load)
2178 score += (100 - ap_load) * CCA_WEIGHTAGE;
2179 else
2180 score += (100 - cca) * CCA_WEIGHTAGE;
2181
2182 channel_weight = GetPERRoamRssiCountWeight(best_rssi, ap_cnt);
2183
2184 score += channel_weight * OTHER_AP_WEIGHT;
2185
2186 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO_LOW,
2187 FL("rssi=%d normalized_rssi=%d htcaps=%d vht=%d bw=%d channel=%d wmm=%d beamforming=%d ap_load=%d channel_weight=%d"),
2188 bssInfo->rssi, normalised_rssi, bssInfo->HTCapsPresent,
2189 bssInfo->vhtCapsPresent, bssInfo->chanWidth,
2190 bssInfo->channelId, bssInfo->wmeInfoPresent,
2191 bssInfo->beacomformingCapable, ap_load, channel_weight);
2192 return score;
2193}
2194
2195/* Calculate candidate AP score for PER based roaming */
2196static tANI_S32 csrFindCongestionScore (tpAniSirGlobal pMac, tCsrScanResult *pBss)
2197{
2198 tANI_S32 score = 0;
2199 tANI_S32 i;
2200 tANI_S32 candidateApCnt, best_rssi, other_ap_cnt;
2201 tANI_U32 current_timestamp;
2202 tpCsrNeighborRoamControlInfo pNeighborRoamInfo =
2203 &pMac->roam.neighborRoamInfo;
2204
2205 tSirBssDescription *bssInfo = &(pBss->Result.BssDescriptor);
2206 pBss->congestionScore = 0;
2207 for (i = 0; i < pMac->PERroamCandidatesCnt; i++)
2208 if (pMac->candidateChannelInfo[i].channelNumber ==
2209 pBss->Result.BssDescriptor.channelId)
2210 break;
2211
2212 if (i == SIR_PER_ROAM_MAX_CANDIDATE_CNT) {
2213 smsLog(pMac, LOGE,
2214 FL("candidate chan info not found for channel %d bssid "
2215 MAC_ADDRESS_STR), pBss->Result.BssDescriptor.channelId,
2216 MAC_ADDR_ARRAY(pBss->Result.BssDescriptor.bssId));
2217 return -1;
2218 }
2219
Kapil Gupta192d9d42016-11-25 16:24:13 +05302220 if (bssInfo->rssi < pMac->roam.configParam.PERMinRssiThresholdForRoam) {
Kapil Guptaa040e772016-09-15 19:03:45 +05302221 smsLog(pMac, LOG1,
Kapil Guptae2b5c092017-02-06 15:04:47 +05302222 FL("discarding candidate due to low rssi=%d than %d, bssid "
Kapil Guptaa040e772016-09-15 19:03:45 +05302223 MAC_ADDRESS_STR), bssInfo->rssi,
Kapil Guptae2b5c092017-02-06 15:04:47 +05302224 pMac->roam.configParam.PERMinRssiThresholdForRoam,
Kapil Guptaa040e772016-09-15 19:03:45 +05302225 MAC_ADDR_ARRAY(pBss->Result.BssDescriptor.bssId));
2226 return 0;
2227 }
Kapil Guptab3a981b2016-06-26 13:36:51 +05302228 /* find best RSSI of other AP in this channel */
2229 best_rssi = MIN_RSSI;
2230 for (other_ap_cnt = 0; other_ap_cnt <
2231 pMac->candidateChannelInfo[i].otherApCount; other_ap_cnt++) {
2232 if (pMac->candidateChannelInfo[i].otherApRssi[other_ap_cnt] > best_rssi)
2233 best_rssi = pMac->candidateChannelInfo[i].otherApRssi[other_ap_cnt];
2234 }
2235
2236 score = calculateBssScore(bssInfo, best_rssi,
2237 pMac->candidateChannelInfo[i].otherApCount,
2238 pMac->candidateChannelInfo[i].channelCCA);
2239 current_timestamp = jiffies_to_msecs(jiffies);
2240
2241 /* penalty logic */
2242
2243 /* In the previous list */
2244 for (candidateApCnt = 0; candidateApCnt <
2245 SIR_PER_ROAM_MAX_CANDIDATE_CNT; candidateApCnt++) {
2246 if (sirCompareMacAddr(pMac->previousRoamApInfo[candidateApCnt].bssAddr,
2247 pBss->Result.BssDescriptor.bssId) &&
2248 ((current_timestamp - pMac->previousRoamApInfo[candidateApCnt].timeStamp) <
2249 PENALTY_TIMEOUT)) {
2250 score = (score * PENALTY_REMAINING_SCORE)/PENALTY_TOTAL_SCORE;
2251 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
2252 FL("AP BSSID " MAC_ADDRESS_STR "adding penalty(in previous list)new score %d"),
2253 MAC_ADDR_ARRAY(pBss->Result.BssDescriptor.bssId),
2254 score);
2255 break;
2256 }
2257 }
2258 /* preauth failed last time */
2259 for (candidateApCnt = 0; candidateApCnt <
2260 MAX_NUM_PREAUTH_FAIL_LIST_ADDRESS; candidateApCnt++) {
2261 if (sirCompareMacAddr(pNeighborRoamInfo->FTRoamInfo.
2262 preAuthFailList.macAddress[candidateApCnt],
2263 pBss->Result.BssDescriptor.bssId)) {
2264 score = (score * PENALTY_REMAINING_SCORE)/PENALTY_TOTAL_SCORE;
2265 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
2266 FL("AP BSSID " MAC_ADDRESS_STR "adding penalty(previously auth failed)new score %d"),
2267 MAC_ADDR_ARRAY(pBss->Result.BssDescriptor.bssId),
2268 score);
2269 break;
2270 }
2271 }
2272 pBss->congestionScore = score;
2273
2274 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
2275 FL("AP BSSID " MAC_ADDRESS_STR " score %d channel %d"),
2276 MAC_ADDR_ARRAY(pBss->Result.BssDescriptor.bssId),
2277 score, pBss->Result.BssDescriptor.channelId);
2278 return 0;
2279}
2280
2281/* Calculate current AP score for PER based roaming */
2282static tANI_S32 csrFindSelfCongestionScore(tpAniSirGlobal pMac,
2283 tSirBssDescription *bssInfo)
2284{
2285 tANI_S32 i, best_rssi, other_ap_cnt;
2286 tANI_S32 score = 0;
Kapil Guptac6ac4772016-08-05 20:25:16 +05302287 tCsrRoamSession *pSession = CSR_GET_SESSION(pMac,
2288 pMac->roam.roamSession->sessionId);
2289
2290 if (pSession == NULL)
2291 return -1;
Kapil Guptab3a981b2016-06-26 13:36:51 +05302292
Kapil Guptac3c48262017-03-09 18:05:51 +05302293 if (bssInfo->rssi < pMac->roam.configParam.PERMinRssiThresholdForRoam) {
2294 smsLog(pMac, LOG1,
2295 FL("Current AP has low rssi=%d than %d"), bssInfo->rssi,
2296 pMac->roam.configParam.PERMinRssiThresholdForRoam);
2297 /*
2298 * Make Current candidate score as zero which will cause roaming
2299 * in low RSSI scenarios
2300 */
2301 pMac->currentBssScore = 0;
2302 return 0;
2303 }
2304
Kapil Guptab3a981b2016-06-26 13:36:51 +05302305 for (i = 0; i <= pMac->PERroamCandidatesCnt; i++)
2306 if (pMac->candidateChannelInfo[i].channelNumber == bssInfo->channelId)
2307 break;
2308 if (i > pMac->PERroamCandidatesCnt) {
2309 /* home channel info is not present, no need to roam */
2310 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR,
2311 FL("home channel %d congestion info not present"),
2312 bssInfo->channelId);
2313 pMac->currentBssScore = PER_ROAM_MAX_BSS_SCORE;
2314 return -1;
2315 }
2316
2317 /* find best RSSI of other AP in this channel */
2318 best_rssi = MIN_RSSI;
2319 for (other_ap_cnt = 0; other_ap_cnt <
2320 pMac->candidateChannelInfo[i].otherApCount; other_ap_cnt++) {
2321 if (pMac->candidateChannelInfo[i].otherApRssi[other_ap_cnt] > best_rssi)
2322 best_rssi = pMac->candidateChannelInfo[i].otherApRssi[other_ap_cnt];
2323 }
2324
Kapil Guptac6ac4772016-08-05 20:25:16 +05302325 /* update latest RSSI for current AP */
2326 WLANTL_GetRssi(vos_get_global_context(VOS_MODULE_ID_SME, NULL),
2327 pSession->connectedInfo.staId,
2328 &bssInfo->rssi);
2329
Kapil Guptab3a981b2016-06-26 13:36:51 +05302330 score = calculateBssScore(bssInfo, best_rssi,
2331 pMac->candidateChannelInfo[i].otherApCount,
2332 pMac->candidateChannelInfo[i].channelCCA);
2333 pMac->currentBssScore = score;
2334 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
2335 FL("PER Roam Current AP score %d channel %d"),
2336 score, bssInfo->channelId);
2337 return 0;
2338}
2339
Kapil Guptab79e76f2016-09-12 20:04:37 +05302340
Kapil Guptab3a981b2016-06-26 13:36:51 +05302341static tANI_BOOLEAN csrIsBetterBssInCongestion(tCsrScanResult *pBss1,
2342 tCsrScanResult *pBss2)
2343{
2344 tANI_BOOLEAN ret;
2345
2346 if(CSR_IS_BETTER_PREFER_VALUE(pBss1->congestionScore,
2347 pBss2->congestionScore))
2348 ret = eANI_BOOLEAN_TRUE;
2349 else
2350 ret = eANI_BOOLEAN_FALSE;
2351
2352 return (ret);
2353}
2354#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002355
2356//To check whther pBss1 is better than pBss2
2357static tANI_BOOLEAN csrIsBetterBss(tCsrScanResult *pBss1, tCsrScanResult *pBss2)
2358{
2359 tANI_BOOLEAN ret;
2360
2361 if(CSR_IS_BETTER_PREFER_VALUE(pBss1->preferValue, pBss2->preferValue))
2362 {
2363 ret = eANI_BOOLEAN_TRUE;
2364 }
2365 else if(CSR_IS_EQUAL_PREFER_VALUE(pBss1->preferValue, pBss2->preferValue))
2366 {
2367 if(CSR_IS_BETTER_CAP_VALUE(pBss1->capValue, pBss2->capValue))
2368 {
2369 ret = eANI_BOOLEAN_TRUE;
2370 }
2371 else
2372 {
2373 ret = eANI_BOOLEAN_FALSE;
2374 }
2375 }
2376 else
2377 {
2378 ret = eANI_BOOLEAN_FALSE;
2379 }
2380
2381 return (ret);
2382}
2383
2384
Srikant Kuppa866893f2012-12-27 17:28:14 -08002385#ifdef FEATURE_WLAN_LFR
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002386//Add the channel to the occupiedChannels array
2387static void csrScanAddToOccupiedChannels(
Srikant Kuppa866893f2012-12-27 17:28:14 -08002388 tpAniSirGlobal pMac,
2389 tCsrScanResult *pResult,
2390 tCsrChannel *pOccupiedChannels,
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002391 tDot11fBeaconIEs *pIes)
2392{
2393 eHalStatus status;
2394 tANI_U8 channel;
2395 tANI_U8 numOccupiedChannels = pOccupiedChannels->numChannels;
2396 tANI_U8 *pOccupiedChannelList = pOccupiedChannels->channelList;
2397
2398 channel = pResult->Result.BssDescriptor.channelId;
2399
2400 if (!csrIsChannelPresentInList(pOccupiedChannelList, numOccupiedChannels, channel)
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08002401 && csrNeighborRoamConnectedProfileMatch(pMac, pResult, pIes))
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002402 {
Srikant Kuppa866893f2012-12-27 17:28:14 -08002403 status = csrAddToChannelListFront(pOccupiedChannelList, numOccupiedChannels, channel);
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002404 if(HAL_STATUS_SUCCESS(status))
Srikant Kuppa866893f2012-12-27 17:28:14 -08002405 {
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002406 pOccupiedChannels->numChannels++;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002407 smsLog(pMac, LOG2, FL("%s: added channel %d to the list (count=%d)"),
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08002408 __func__, channel, pOccupiedChannels->numChannels);
Srikant Kuppa866893f2012-12-27 17:28:14 -08002409 if (pOccupiedChannels->numChannels > CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN)
2410 pOccupiedChannels->numChannels = CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN;
2411 }
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002412 }
2413}
Mukul Sharma9e4e0f92015-02-13 18:45:20 +05302414
2415void csrAddChannelToOccupiedChannelList(tpAniSirGlobal pMac,
2416 tANI_U8 channel)
2417{
2418 eHalStatus status;
2419 tCsrChannel *pOccupiedChannels = &pMac->scan.occupiedChannels;
2420 tANI_U8 numOccupiedChannels = pOccupiedChannels->numChannels;
2421 tANI_U8 *pOccupiedChannelList = pOccupiedChannels->channelList;
2422 if (!csrIsChannelPresentInList(pOccupiedChannelList,
2423 numOccupiedChannels, channel))
2424 {
2425 status = csrAddToChannelListFront(pOccupiedChannelList,
2426 numOccupiedChannels, channel);
2427 if(HAL_STATUS_SUCCESS(status))
2428 {
2429 pOccupiedChannels->numChannels++;
2430 smsLog(pMac, LOG2, FL("added channel %d to the list (count=%d)"),
2431 channel, pOccupiedChannels->numChannels);
2432 if (pOccupiedChannels->numChannels >
2433 CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN)
2434 {
2435 pOccupiedChannels->numChannels =
2436 CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN;
2437 smsLog(pMac, LOG2,
2438 FL("trim no of Channels for Occ channel list"));
2439 }
2440 }
2441 }
2442}
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002443#endif
2444
Jeff Johnson295189b2012-06-20 16:38:30 -07002445//Put the BSS into the scan result list
2446//pIes can not be NULL
2447static void csrScanAddResult(tpAniSirGlobal pMac, tCsrScanResult *pResult, tDot11fBeaconIEs *pIes)
2448{
Srinivas28b5b4e2012-12-12 13:07:53 -08002449#ifdef FEATURE_WLAN_LFR
2450 tpCsrNeighborRoamControlInfo pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
2451#endif
2452
Jeff Johnson295189b2012-06-20 16:38:30 -07002453 pResult->preferValue = csrGetBssPreferValue(pMac, (int)pResult->Result.BssDescriptor.rssi);
2454 pResult->capValue = csrGetBssCapValue(pMac, &pResult->Result.BssDescriptor, pIes);
2455 csrLLInsertTail( &pMac->scan.scanResultList, &pResult->Link, LL_ACCESS_LOCK );
Srikant Kuppa866893f2012-12-27 17:28:14 -08002456#ifdef FEATURE_WLAN_LFR
Srinivas28b5b4e2012-12-12 13:07:53 -08002457 if(0 == pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels)
2458 {
2459 /* Build the occupied channel list, only if "gNeighborScanChannelList" is
2460 NOT set in the cfg.ini file */
2461 csrScanAddToOccupiedChannels(pMac, pResult, &pMac->scan.occupiedChannels, pIes);
2462 }
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002463#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002464}
2465
2466
2467eHalStatus csrScanGetResult(tpAniSirGlobal pMac, tCsrScanResultFilter *pFilter, tScanResultHandle *phResult)
2468{
2469 eHalStatus status;
2470 tScanResultList *pRetList;
2471 tCsrScanResult *pResult, *pBssDesc;
2472 tANI_U32 count = 0;
2473 tListElem *pEntry;
2474 tANI_U32 bssLen, allocLen;
2475 eCsrEncryptionType uc = eCSR_ENCRYPT_TYPE_NONE, mc = eCSR_ENCRYPT_TYPE_NONE;
2476 eCsrAuthType auth = eCSR_AUTH_TYPE_OPEN_SYSTEM;
2477 tDot11fBeaconIEs *pIes, *pNewIes;
2478 tANI_BOOLEAN fMatch;
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002479 tANI_U16 i = 0;
Kapil Guptab3a981b2016-06-26 13:36:51 +05302480 tCsrRoamSession *pSession = CSR_GET_SESSION(pMac,
2481 pMac->roam.roamSession->sessionId);
2482
Jeff Johnson295189b2012-06-20 16:38:30 -07002483 if(phResult)
2484 {
2485 *phResult = CSR_INVALID_SCANRESULT_HANDLE;
2486 }
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002487
2488 if (pMac->roam.configParam.nSelect5GHzMargin)
2489 {
2490 pMac->scan.inScanResultBestAPRssi = -128;
2491 csrLLLock(&pMac->scan.scanResultList);
2492
2493 /* Find out the best AP Rssi going thru the scan results */
2494 pEntry = csrLLPeekHead(&pMac->scan.scanResultList, LL_ACCESS_NOLOCK);
2495 while ( NULL != pEntry)
2496 {
2497 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002498 fMatch = FALSE;
2499
2500 if (pFilter)
2501 for(i = 0; i < pFilter->SSIDs.numOfSSIDs; i++)
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002502 {
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002503 fMatch = csrIsSsidMatch( pMac, pFilter->SSIDs.SSIDList[i].SSID.ssId, pFilter->SSIDs.SSIDList[i].SSID.length,
2504 pBssDesc->Result.ssId.ssId,
2505 pBssDesc->Result.ssId.length, eANI_BOOLEAN_TRUE );
2506 if (fMatch)
2507 {
2508 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
2509
2510 //At this time, pBssDescription->Result.pvIes may be NULL
2511 if( !pIes && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
2512 &pBssDesc->Result.BssDescriptor, &pIes))) )
2513 {
2514 continue;
2515 }
2516
2517 smsLog(pMac, LOG1, FL("SSID Matched"));
Leela Venkata Kiran Kumar Reddy Chiralae208a832014-04-27 22:34:25 -07002518
Leela Venkata Kiran Kumar Reddy Chiralaf257bef2014-04-11 18:48:12 -07002519 if ( pFilter->bOSENAssociation )
2520 {
2521 fMatch = TRUE;
2522 }
Leela Venkata Kiran Kumar Reddy Chiralae208a832014-04-27 22:34:25 -07002523 else
2524 {
Abhishek Singh658d4de2014-06-26 10:53:15 +05302525#ifdef WLAN_FEATURE_11W
Abhishek Singh3b56d3a2014-06-25 12:37:39 +05302526 fMatch = csrIsSecurityMatch(pMac, &pFilter->authType,
2527 &pFilter->EncryptionType,
2528 &pFilter->mcEncryptionType,
2529 &pFilter->MFPEnabled,
2530 &pFilter->MFPRequired,
2531 &pFilter->MFPCapable,
2532 &pBssDesc->Result.BssDescriptor,
2533 pIes, NULL, NULL, NULL );
Abhishek Singh658d4de2014-06-26 10:53:15 +05302534#else
2535 fMatch = csrIsSecurityMatch(pMac, &pFilter->authType,
2536 &pFilter->EncryptionType,
2537 &pFilter->mcEncryptionType,
2538 NULL, NULL, NULL,
2539 &pBssDesc->Result.BssDescriptor,
2540 pIes, NULL, NULL, NULL );
2541#endif
Leela Venkata Kiran Kumar Reddy Chiralae208a832014-04-27 22:34:25 -07002542 }
2543 if ((pBssDesc->Result.pvIes == NULL) && pIes)
2544 vos_mem_free(pIes);
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002545
2546 if (fMatch)
2547 smsLog(pMac, LOG1, FL(" Security Matched"));
2548 }
2549 }
2550
2551 if (fMatch && (pBssDesc->Result.BssDescriptor.rssi > pMac->scan.inScanResultBestAPRssi))
2552 {
2553 smsLog(pMac, LOG1, FL("Best AP Rssi changed from %d to %d"),
2554 pMac->scan.inScanResultBestAPRssi,
2555 pBssDesc->Result.BssDescriptor.rssi);
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002556 pMac->scan.inScanResultBestAPRssi = pBssDesc->Result.BssDescriptor.rssi;
2557 }
2558 pEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
2559 }
2560
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002561 if ( -128 != pMac->scan.inScanResultBestAPRssi)
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002562 {
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002563 smsLog(pMac, LOG1, FL("Best AP Rssi is %d"), pMac->scan.inScanResultBestAPRssi);
2564 /* Modify Rssi category based on best AP Rssi */
2565 csrAssignRssiForCategory(pMac, pMac->scan.inScanResultBestAPRssi, pMac->roam.configParam.bCatRssiOffset);
2566 pEntry = csrLLPeekHead(&pMac->scan.scanResultList, LL_ACCESS_NOLOCK);
2567 while ( NULL != pEntry)
2568 {
2569 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002570
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002571 /* re-assign preference value based on modified rssi bucket */
2572 pBssDesc->preferValue = csrGetBssPreferValue(pMac, (int)pBssDesc->Result.BssDescriptor.rssi);
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002573
Arif Hussaina7c8e412013-11-20 11:06:42 -08002574 smsLog(pMac, LOG2, FL("BSSID("MAC_ADDRESS_STR
Jeff Johnson123ed002013-11-22 17:39:55 -08002575 ") Rssi(%d) Chnl(%d) PrefVal(%u) SSID=%.*s"),
Arif Hussaina7c8e412013-11-20 11:06:42 -08002576 MAC_ADDR_ARRAY(pBssDesc->Result.BssDescriptor.bssId),
2577 pBssDesc->Result.BssDescriptor.rssi,
2578 pBssDesc->Result.BssDescriptor.channelId,
2579 pBssDesc->preferValue,
2580 pBssDesc->Result.ssId.length, pBssDesc->Result.ssId.ssId);
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002581
2582 pEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
2583 }
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002584 }
2585
2586 csrLLUnlock(&pMac->scan.scanResultList);
2587 }
2588
Kiet Lam64c1b492013-07-12 13:56:44 +05302589 pRetList = vos_mem_malloc(sizeof(tScanResultList));
2590 if ( NULL == pRetList )
2591 status = eHAL_STATUS_FAILURE;
2592 else
2593 status = eHAL_STATUS_SUCCESS;
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002594 if(HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07002595 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302596 vos_mem_set(pRetList, sizeof(tScanResultList), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002597 csrLLOpen(pMac->hHdd, &pRetList->List);
2598 pRetList->pCurEntry = NULL;
Kapil Guptab3a981b2016-06-26 13:36:51 +05302599#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
2600 if (pFilter && pFilter->isPERRoamScan)
2601 if (pSession && pSession->pConnectBssDesc)
2602 csrFindSelfCongestionScore(pMac,
2603 pSession->pConnectBssDesc);
2604#endif
2605
Jeff Johnson295189b2012-06-20 16:38:30 -07002606 csrLLLock(&pMac->scan.scanResultList);
2607 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
2608 while( pEntry )
2609 {
2610 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2611 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
2612 //if pBssDesc->Result.pvIes is NULL, we need to free any memory allocated by csrMatchBSS
2613 //for any error condition, otherwiase, it will be freed later.
2614 //reset
2615 fMatch = eANI_BOOLEAN_FALSE;
2616 pNewIes = NULL;
2617
2618 if(pFilter)
2619 {
2620 fMatch = csrMatchBSS(pMac, &pBssDesc->Result.BssDescriptor, pFilter, &auth, &uc, &mc, &pIes);
2621 if( NULL != pIes )
2622 {
2623 //Only save it when matching
2624 if(fMatch)
2625 {
2626 if( !pBssDesc->Result.pvIes )
2627 {
2628 //csrMatchBSS allocates the memory. Simply pass it and it is freed later
2629 pNewIes = pIes;
2630 }
2631 else
2632 {
2633 //The pIes is allocated by someone else. make a copy
2634 //Only to save parsed IEs if caller provides a filter. Most likely the caller
2635 //is using to for association, hence save the parsed IEs
Kiet Lam64c1b492013-07-12 13:56:44 +05302636 pNewIes = vos_mem_malloc(sizeof(tDot11fBeaconIEs));
2637 if ( NULL == pNewIes )
2638 status = eHAL_STATUS_FAILURE;
2639 else
2640 status = eHAL_STATUS_SUCCESS;
2641 if ( HAL_STATUS_SUCCESS( status ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07002642 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302643 vos_mem_copy(pNewIes, pIes, sizeof( tDot11fBeaconIEs ));
Jeff Johnson295189b2012-06-20 16:38:30 -07002644 }
2645 else
2646 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002647 smsLog(pMac, LOGE, FL(" fail to allocate memory for IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002648 //Need to free memory allocated by csrMatchBSS
2649 if( !pBssDesc->Result.pvIes )
2650 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302651 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07002652 }
2653 break;
2654 }
2655 }
2656 }//fMatch
2657 else 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 }
2662 }
2663 if(NULL == pFilter || fMatch)
2664 {
2665 bssLen = pBssDesc->Result.BssDescriptor.length + sizeof(pBssDesc->Result.BssDescriptor.length);
2666 allocLen = sizeof( tCsrScanResult ) + bssLen;
Kiet Lam64c1b492013-07-12 13:56:44 +05302667 pResult = vos_mem_malloc(allocLen);
2668 if ( NULL == pResult )
2669 status = eHAL_STATUS_FAILURE;
2670 else
2671 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07002672 if(!HAL_STATUS_SUCCESS(status))
2673 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002674 smsLog(pMac, LOGE, FL(" fail to allocate memory for scan result, len=%d"), allocLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07002675 if(pNewIes)
2676 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302677 vos_mem_free(pNewIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07002678 }
2679 break;
2680 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302681 vos_mem_set(pResult, allocLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002682 pResult->capValue = pBssDesc->capValue;
2683 pResult->preferValue = pBssDesc->preferValue;
2684 pResult->ucEncryptionType = uc;
2685 pResult->mcEncryptionType = mc;
2686 pResult->authType = auth;
2687 pResult->Result.ssId = pBssDesc->Result.ssId;
Padma, Santhosh Kumare12fd982016-03-21 13:07:52 +05302688 pResult->Result.timer = pBssDesc->Result.timer;
Jeff Johnson295189b2012-06-20 16:38:30 -07002689 //save the pIes for later use
2690 pResult->Result.pvIes = pNewIes;
2691 //save bss description
Kiet Lam64c1b492013-07-12 13:56:44 +05302692 vos_mem_copy(&pResult->Result.BssDescriptor,
2693 &pBssDesc->Result.BssDescriptor, bssLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07002694 //No need to lock pRetList because it is locally allocated and no outside can access it at this time
2695 if(csrLLIsListEmpty(&pRetList->List, LL_ACCESS_NOLOCK))
2696 {
Kapil Guptab3a981b2016-06-26 13:36:51 +05302697#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
2698 if (pFilter && pFilter->isPERRoamScan) {
2699 csrFindCongestionScore(pMac, pResult);
2700 if (pResult->congestionScore > pMac->currentBssScore) {
2701 csrLLInsertTail(&pRetList->List, &pResult->Link,
2702 LL_ACCESS_NOLOCK);
2703 smsLog(pMac, LOGW,
2704 FL("added one entry in LL in PER Roam list"));
2705 }
2706 }
2707 else
2708#endif
2709 {
2710 csrLLInsertTail(&pRetList->List, &pResult->Link,
2711 LL_ACCESS_NOLOCK);
2712 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002713 }
Abhishek Singhb3e376c2017-01-04 15:27:13 +05302714 /* bssid hint AP should be on head */
2715 else if (pFilter &&
2716 vos_mem_compare(pResult->Result.BssDescriptor.bssId,
2717 pFilter->bssid_hint, VOS_MAC_ADDR_SIZE))
2718 {
2719 csrLLInsertHead(&pRetList->List,
2720 &pResult->Link, LL_ACCESS_NOLOCK);
2721 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002722 else
2723 {
2724 //To sort the list
2725 tListElem *pTmpEntry;
2726 tCsrScanResult *pTmpResult;
2727
2728 pTmpEntry = csrLLPeekHead(&pRetList->List, LL_ACCESS_NOLOCK);
2729 while(pTmpEntry)
2730 {
2731 pTmpResult = GET_BASE_ADDR( pTmpEntry, tCsrScanResult, Link );
Abhishek Singhb3e376c2017-01-04 15:27:13 +05302732 /* Skip the bssid hint AP, as it should be on head */
Abhishek Singh78f494b2017-01-24 10:07:08 +05302733 if (pFilter && vos_mem_compare(
2734 pTmpResult->Result.BssDescriptor.bssId,
Abhishek Singhb3e376c2017-01-04 15:27:13 +05302735 pFilter->bssid_hint, VOS_MAC_ADDR_SIZE)) {
2736 pTmpEntry = csrLLNext(&pRetList->List,
2737 pTmpEntry, LL_ACCESS_NOLOCK);
2738 continue;
2739 }
Kapil Guptab3a981b2016-06-26 13:36:51 +05302740#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
2741 if (pFilter && pFilter->isPERRoamScan) {
2742 csrFindCongestionScore(pMac, pResult);
2743 if(csrIsBetterBssInCongestion(pResult, pTmpResult)&&
2744 (pResult->congestionScore > pMac->currentBssScore))
2745 {
2746 csrLLInsertEntry(&pRetList->List, pTmpEntry,
2747 &pResult->Link, LL_ACCESS_NOLOCK);
2748 smsLog(pMac, LOGW,
2749 FL("added another entry in LL in PER Roam list"));
2750 pResult = NULL;
2751 break;
2752 }
2753 pTmpEntry = csrLLNext(&pRetList->List,
2754 pTmpEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07002755 }
Kapil Guptab3a981b2016-06-26 13:36:51 +05302756 else
2757#endif
2758 {
2759 if(csrIsBetterBss(pResult, pTmpResult))
2760 {
2761 csrLLInsertEntry(&pRetList->List, pTmpEntry,
2762 &pResult->Link, LL_ACCESS_NOLOCK);
2763 //To indicate we are done
2764 pResult = NULL;
2765 break;
2766 }
2767 pTmpEntry = csrLLNext(&pRetList->List,
2768 pTmpEntry, LL_ACCESS_NOLOCK);
2769 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002770 }
2771 if(pResult != NULL)
Kapil Guptab3a981b2016-06-26 13:36:51 +05302772#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
2773 if ((pFilter && !pFilter->isPERRoamScan) ||
2774 (pFilter == NULL) ||
2775 (pResult->congestionScore > pMac->currentBssScore))
2776#endif
2777 {
2778 //This one is not better than any one
2779 csrLLInsertTail(&pRetList->List,
2780 &pResult->Link, LL_ACCESS_NOLOCK);
2781 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002782 }
2783 count++;
2784 }
2785 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK );
2786 }//while
2787 csrLLUnlock(&pMac->scan.scanResultList);
2788
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002789 smsLog(pMac, LOG2, FL("return %d BSS"), csrLLCount(&pRetList->List));
Jeff Johnson295189b2012-06-20 16:38:30 -07002790
2791 if( !HAL_STATUS_SUCCESS(status) || (phResult == NULL) )
2792 {
2793 //Fail or No one wants the result.
2794 csrScanResultPurge(pMac, (tScanResultHandle)pRetList);
2795 }
2796 else
2797 {
2798 if(0 == count)
2799 {
2800 //We are here meaning the there is no match
2801 csrLLClose(&pRetList->List);
Kiet Lam64c1b492013-07-12 13:56:44 +05302802 vos_mem_free(pRetList);
Jeff Johnson295189b2012-06-20 16:38:30 -07002803 status = eHAL_STATUS_E_NULL_VALUE;
Kapil Guptab3a981b2016-06-26 13:36:51 +05302804 smsLog(pMac, LOGW,
2805 FL("Nil scan results or no matching AP found"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002806 }
2807 else if(phResult)
2808 {
2809 *phResult = pRetList;
2810 }
2811 }
2812 }//Allocated pRetList
2813
2814 return (status);
2815}
2816
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002817/*
2818 * NOTE: This routine is being added to make
2819 * sure that scan results are not being flushed
2820 * while roaming. If the scan results are flushed,
2821 * we are unable to recover from
2822 * csrRoamRoamingStateDisassocRspProcessor.
2823 * If it is needed to remove this routine,
2824 * first ensure that we recover gracefully from
2825 * csrRoamRoamingStateDisassocRspProcessor if
2826 * csrScanGetResult returns with a failure because
2827 * of not being able to find the roaming BSS.
2828 */
2829tANI_U8 csrScanFlushDenied(tpAniSirGlobal pMac)
2830{
2831 switch(pMac->roam.neighborRoamInfo.neighborRoamState) {
2832 case eCSR_NEIGHBOR_ROAM_STATE_REPORT_SCAN:
2833 case eCSR_NEIGHBOR_ROAM_STATE_PREAUTHENTICATING:
2834 case eCSR_NEIGHBOR_ROAM_STATE_PREAUTH_DONE:
2835 case eCSR_NEIGHBOR_ROAM_STATE_REASSOCIATING:
2836 return (pMac->roam.neighborRoamInfo.neighborRoamState);
2837 default:
2838 return 0;
2839 }
2840}
2841
Jeff Johnson295189b2012-06-20 16:38:30 -07002842eHalStatus csrScanFlushResult(tpAniSirGlobal pMac)
2843{
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002844 tANI_U8 isFlushDenied = csrScanFlushDenied(pMac);
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302845 eHalStatus status = eHAL_STATUS_SUCCESS;
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002846 if (isFlushDenied) {
2847 smsLog(pMac, LOGW, "%s: scan flush denied in roam state %d",
2848 __func__, isFlushDenied);
2849 return eHAL_STATUS_FAILURE;
2850 }
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302851 csrLLScanPurgeResult( pMac, &pMac->scan.tempScanResults );
2852 csrLLScanPurgeResult( pMac, &pMac->scan.scanResultList );
2853 return( status );
Jeff Johnson295189b2012-06-20 16:38:30 -07002854}
2855
Mukul Sharma20aa6582014-08-07 21:36:12 +05302856eHalStatus csrScanFlushSelectiveResultForBand(tpAniSirGlobal pMac, v_BOOL_t flushP2P, tSirRFBand band)
2857{
2858 eHalStatus status = eHAL_STATUS_SUCCESS;
2859 tListElem *pEntry,*pFreeElem;
2860 tCsrScanResult *pBssDesc;
2861 tDblLinkList *pList = &pMac->scan.scanResultList;
2862
2863 csrLLLock(pList);
2864
2865 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK );
2866 while( pEntry != NULL)
2867 {
2868 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2869 if( (flushP2P == vos_mem_compare( pBssDesc->Result.ssId.ssId,
2870 "DIRECT-", 7)) &&
2871 (GetRFBand(pBssDesc->Result.BssDescriptor.channelId) == band)
2872 )
2873 {
2874 pFreeElem = pEntry;
2875 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2876 csrLLRemoveEntry(pList, pFreeElem, LL_ACCESS_NOLOCK);
2877 csrFreeScanResultEntry( pMac, pBssDesc );
2878 continue;
2879 }
2880 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2881 }
2882
2883 csrLLUnlock(pList);
2884
2885 return (status);
2886}
2887
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302888eHalStatus csrScanFlushSelectiveResult(tpAniSirGlobal pMac, v_BOOL_t flushP2P)
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002889{
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302890 eHalStatus status = eHAL_STATUS_SUCCESS;
2891 tListElem *pEntry,*pFreeElem;
2892 tCsrScanResult *pBssDesc;
2893 tDblLinkList *pList = &pMac->scan.scanResultList;
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002894
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302895 csrLLLock(pList);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002896
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302897 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK );
2898 while( pEntry != NULL)
2899 {
2900 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2901 if( flushP2P == vos_mem_compare( pBssDesc->Result.ssId.ssId,
2902 "DIRECT-", 7) )
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002903 {
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302904 pFreeElem = pEntry;
2905 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2906 csrLLRemoveEntry(pList, pFreeElem, LL_ACCESS_NOLOCK);
2907 csrFreeScanResultEntry( pMac, pBssDesc );
2908 continue;
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002909 }
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302910 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2911 }
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002912
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302913 csrLLUnlock(pList);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002914
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302915 return (status);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002916}
2917
Jeff Johnson295189b2012-06-20 16:38:30 -07002918/**
2919 * csrCheck11dChannel
2920 *
2921 *FUNCTION:
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302922 * This function is called from csrScanFilterResults function and
Jeff Johnson295189b2012-06-20 16:38:30 -07002923 * compare channel number with given channel list.
2924 *
2925 *LOGIC:
2926 * Check Scan result channel number with CFG channel list
2927 *
2928 *ASSUMPTIONS:
2929 *
2930 *
2931 *NOTE:
2932 *
2933 * @param channelId channel number
2934 * @param pChannelList Pointer to channel list
2935 * @param numChannels Number of channel in channel list
2936 *
2937 * @return Status
2938 */
2939
2940eHalStatus csrCheck11dChannel(tANI_U8 channelId, tANI_U8 *pChannelList, tANI_U32 numChannels)
2941{
2942 eHalStatus status = eHAL_STATUS_FAILURE;
2943 tANI_U8 i = 0;
2944
2945 for (i = 0; i < numChannels; i++)
2946 {
2947 if(pChannelList[ i ] == channelId)
2948 {
2949 status = eHAL_STATUS_SUCCESS;
2950 break;
2951 }
2952 }
2953 return status;
2954}
2955
2956/**
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302957 * csrScanFilterResults
Jeff Johnson295189b2012-06-20 16:38:30 -07002958 *
2959 *FUNCTION:
2960 * This function is called from csrApplyCountryInformation function and
2961 * filter scan result based on valid channel list number.
2962 *
2963 *LOGIC:
2964 * Get scan result from scan list and Check Scan result channel number
2965 * with 11d channel list if channel number is found in 11d channel list
2966 * then do not remove scan result entry from scan list
2967 *
2968 *ASSUMPTIONS:
2969 *
2970 *
2971 *NOTE:
2972 *
2973 * @param pMac Pointer to Global MAC structure
2974 *
2975 * @return Status
2976 */
2977
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302978eHalStatus csrScanFilterResults(tpAniSirGlobal pMac)
Jeff Johnson295189b2012-06-20 16:38:30 -07002979{
2980 eHalStatus status = eHAL_STATUS_SUCCESS;
2981 tListElem *pEntry,*pTempEntry;
2982 tCsrScanResult *pBssDesc;
2983 tANI_U32 len = sizeof(pMac->roam.validChannelList);
2984
2985 /* Get valid channels list from CFG */
2986 if (!HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac,
2987 pMac->roam.validChannelList, &len)))
2988 {
Agarwal Ashishe3cca2a2013-07-21 03:01:48 +05302989 smsLog( pMac, LOGE, "Failed to get Channel list from CFG");
Jeff Johnson295189b2012-06-20 16:38:30 -07002990 }
2991
2992 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
2993 while( pEntry )
2994 {
2995 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302996 pTempEntry = csrLLNext( &pMac->scan.scanResultList, pEntry,
Jeff Johnson295189b2012-06-20 16:38:30 -07002997 LL_ACCESS_LOCK );
2998 if(csrCheck11dChannel(pBssDesc->Result.BssDescriptor.channelId,
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302999 pMac->roam.validChannelList, len))
Jeff Johnson295189b2012-06-20 16:38:30 -07003000 {
3001 /* Remove Scan result which does not have 11d channel */
3002 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry,
3003 LL_ACCESS_LOCK ))
3004 {
3005 csrFreeScanResultEntry( pMac, pBssDesc );
3006 }
3007 }
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05303008 pEntry = pTempEntry;
3009 }
3010
3011 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
3012 while( pEntry )
3013 {
3014 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3015 pTempEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry,
3016 LL_ACCESS_LOCK );
3017 if(csrCheck11dChannel(pBssDesc->Result.BssDescriptor.channelId,
3018 pMac->roam.validChannelList, len))
3019 {
3020 /* Remove Scan result which does not have 11d channel */
3021 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry,
3022 LL_ACCESS_LOCK ))
3023 {
3024 csrFreeScanResultEntry( pMac, pBssDesc );
3025 }
3026 }
3027 else
3028 {
3029 smsLog( pMac, LOG1, FL("%d is a Valid channel"),
3030 pBssDesc->Result.BssDescriptor.channelId);
3031 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003032 pEntry = pTempEntry;
3033 }
3034 return status;
3035}
3036
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05303037/**
3038 * csrScanFilterDFSResults
3039 *
3040 *FUNCTION:
3041 * This function filter BSSIDs on DFS channels from the scan results.
3042 *
3043 *LOGIC:
3044 * Get scan result from scan list and Check Scan result channel number
3045 * with 11d channel list if channel number is found in 11d channel list
3046 * and if fEnableDFSChnlScan is zero and if channel is DFS, then
3047 * remove scan result entry from scan list
3048 *
3049 *ASSUMPTIONS:
3050 *
3051 *NOTE:
3052 *
3053 * @param pMac Pointer to Global MAC structure
3054 *
3055 * @return Status
3056 */
3057
3058eHalStatus csrScanFilterDFSResults(tpAniSirGlobal pMac)
3059{
3060 eHalStatus status = eHAL_STATUS_SUCCESS;
3061 tListElem *pEntry,*pTempEntry;
3062 tCsrScanResult *pBssDesc;
3063
3064 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
3065 while( pEntry )
3066 {
3067 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3068 pTempEntry = csrLLNext( &pMac->scan.scanResultList, pEntry,
3069 LL_ACCESS_LOCK );
3070 if((pMac->scan.fEnableDFSChnlScan == DFS_CHNL_SCAN_DISABLED) &&
3071 CSR_IS_CHANNEL_DFS(pBssDesc->Result.BssDescriptor.channelId))
3072 {
3073 smsLog( pMac, LOG1, FL("%d is a DFS ch filtered from scan list"),
3074 pBssDesc->Result.BssDescriptor.channelId);
3075 /* Remove Scan result which does not have 11d channel */
3076 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry,
3077 LL_ACCESS_LOCK ))
3078 {
3079 csrFreeScanResultEntry( pMac, pBssDesc );
3080 }
3081 }
3082 else
3083 {
3084 smsLog( pMac, LOG1, FL("%d is a Valid channel"),
3085 pBssDesc->Result.BssDescriptor.channelId);
3086 }
3087 pEntry = pTempEntry;
3088 }
3089
3090 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
3091 while( pEntry )
3092 {
3093 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3094 pTempEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry,
3095 LL_ACCESS_LOCK );
3096
3097 if((pMac->scan.fEnableDFSChnlScan == DFS_CHNL_SCAN_DISABLED) &&
3098 CSR_IS_CHANNEL_DFS(pBssDesc->Result.BssDescriptor.channelId))
3099 {
3100 smsLog( pMac, LOG1, FL("%d is a DFS ch filtered from scan list"),
3101 pBssDesc->Result.BssDescriptor.channelId);
3102 /* Remove Scan result which does not have 11d channel */
3103 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry,
3104 LL_ACCESS_LOCK ))
3105 {
3106 csrFreeScanResultEntry( pMac, pBssDesc );
3107 }
3108 }
3109 else
3110 {
3111 smsLog( pMac, LOG1, FL("%d is a Valid channel"),
3112 pBssDesc->Result.BssDescriptor.channelId);
3113 }
3114 pEntry = pTempEntry;
3115 }
3116 return status;
3117}
3118
Jeff Johnson295189b2012-06-20 16:38:30 -07003119
3120eHalStatus csrScanCopyResultList(tpAniSirGlobal pMac, tScanResultHandle hIn, tScanResultHandle *phResult)
3121{
3122 eHalStatus status = eHAL_STATUS_SUCCESS;
3123 tScanResultList *pRetList, *pInList = (tScanResultList *)hIn;
3124 tCsrScanResult *pResult, *pScanResult;
3125 tANI_U32 count = 0;
3126 tListElem *pEntry;
3127 tANI_U32 bssLen, allocLen;
3128
3129 if(phResult)
3130 {
3131 *phResult = CSR_INVALID_SCANRESULT_HANDLE;
3132 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303133 pRetList = vos_mem_malloc(sizeof(tScanResultList));
3134 if ( NULL == pRetList )
3135 status = eHAL_STATUS_FAILURE;
3136 else
Jeff Johnson295189b2012-06-20 16:38:30 -07003137 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303138 vos_mem_set(pRetList, sizeof(tScanResultList), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003139 csrLLOpen(pMac->hHdd, &pRetList->List);
3140 pRetList->pCurEntry = NULL;
3141 csrLLLock(&pMac->scan.scanResultList);
3142 csrLLLock(&pInList->List);
3143
3144 pEntry = csrLLPeekHead( &pInList->List, LL_ACCESS_NOLOCK );
3145 while( pEntry )
3146 {
3147 pScanResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3148 bssLen = pScanResult->Result.BssDescriptor.length + sizeof(pScanResult->Result.BssDescriptor.length);
3149 allocLen = sizeof( tCsrScanResult ) + bssLen;
Kiet Lam64c1b492013-07-12 13:56:44 +05303150 pResult = vos_mem_malloc(allocLen);
3151 if ( NULL == pResult )
3152 status = eHAL_STATUS_FAILURE;
3153 else
3154 status = eHAL_STATUS_SUCCESS;
3155 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07003156 {
3157 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
3158 count = 0;
3159 break;
3160 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303161 vos_mem_set(pResult, allocLen , 0);
3162 vos_mem_copy(&pResult->Result.BssDescriptor, &pScanResult->Result.BssDescriptor, bssLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07003163 if( pScanResult->Result.pvIes )
3164 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303165 pResult->Result.pvIes = vos_mem_malloc(sizeof( tDot11fBeaconIEs ));
3166 if ( NULL == pResult->Result.pvIes )
3167 status = eHAL_STATUS_FAILURE;
3168 else
3169 status = eHAL_STATUS_SUCCESS;
3170 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07003171 {
3172 //Free the memory we allocate above first
Kiet Lam64c1b492013-07-12 13:56:44 +05303173 vos_mem_free(pResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07003174 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
3175 count = 0;
3176 break;
3177 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303178 vos_mem_copy(pResult->Result.pvIes, pScanResult->Result.pvIes,
3179 sizeof( tDot11fBeaconIEs ));
Jeff Johnson295189b2012-06-20 16:38:30 -07003180 }
3181 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_LOCK);
3182 count++;
3183 pEntry = csrLLNext( &pInList->List, pEntry, LL_ACCESS_NOLOCK );
3184 }//while
3185 csrLLUnlock(&pInList->List);
3186 csrLLUnlock(&pMac->scan.scanResultList);
3187
3188 if(HAL_STATUS_SUCCESS(status))
3189 {
3190 if(0 == count)
3191 {
3192 csrLLClose(&pRetList->List);
Kiet Lam64c1b492013-07-12 13:56:44 +05303193 vos_mem_free(pRetList);
Jeff Johnson295189b2012-06-20 16:38:30 -07003194 status = eHAL_STATUS_E_NULL_VALUE;
3195 }
3196 else if(phResult)
3197 {
3198 *phResult = pRetList;
3199 }
3200 }
3201 }//Allocated pRetList
3202
3203 return (status);
3204}
3205
3206
3207
3208eHalStatus csrScanningStateMsgProcessor( tpAniSirGlobal pMac, void *pMsgBuf )
3209{
3210 eHalStatus status = eHAL_STATUS_SUCCESS;
3211 tSirMbMsg *pMsg = (tSirMbMsg *)pMsgBuf;
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303212 tSirSmeDisConDoneInd *pDisConDoneInd;
Abhishek Singhf52182c2016-08-24 11:15:23 +05303213 tCsrRoamSession *pSession;
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303214 tCsrRoamInfo roamInfo = {0};
Jeff Johnson295189b2012-06-20 16:38:30 -07003215
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303216 if((eWNI_SME_SCAN_RSP == pMsg->type) ||
3217 (eWNI_SME_GET_SCANNED_CHANNEL_RSP == pMsg->type))
Jeff Johnson295189b2012-06-20 16:38:30 -07003218 {
3219 status = csrScanSmeScanResponse( pMac, pMsgBuf );
3220 }
3221 else
3222 {
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303223 switch (pMsg->type)
Jeff Johnson295189b2012-06-20 16:38:30 -07003224 {
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303225 case eWNI_SME_UPPER_LAYER_ASSOC_CNF:
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08003226 {
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303227 tSirSmeAssocIndToUpperLayerCnf *pUpperLayerAssocCnf;
3228 tCsrRoamInfo *pRoamInfo = NULL;
3229 tANI_U32 sessionId;
3230 eHalStatus status;
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08003231
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303232 smsLog( pMac, LOG1,
3233 FL("Scanning : ASSOCIATION confirmation can be given to upper layer "));
3234 pRoamInfo = &roamInfo;
3235 pUpperLayerAssocCnf = (tSirSmeAssocIndToUpperLayerCnf *)pMsgBuf;
3236 status = csrRoamGetSessionIdFromBSSID( pMac,
3237 (tCsrBssid *)pUpperLayerAssocCnf->bssId,
3238 &sessionId );
3239 pSession = CSR_GET_SESSION(pMac, sessionId);
3240
3241 if(!pSession)
3242 {
3243 smsLog(pMac, LOGE, FL("session %d not found "), sessionId);
3244 return eHAL_STATUS_FAILURE;
3245 }
3246
3247 //send the status code as Success
3248 pRoamInfo->statusCode = eSIR_SME_SUCCESS;
3249 pRoamInfo->u.pConnectedProfile = &pSession->connectedProfile;
3250 pRoamInfo->staId = (tANI_U8)pUpperLayerAssocCnf->aid;
3251 pRoamInfo->rsnIELen =
3252 (tANI_U8)pUpperLayerAssocCnf->rsnIE.length;
3253 pRoamInfo->prsnIE = pUpperLayerAssocCnf->rsnIE.rsnIEdata;
3254 pRoamInfo->addIELen =
3255 (tANI_U8)pUpperLayerAssocCnf->addIE.length;
3256 pRoamInfo->paddIE = pUpperLayerAssocCnf->addIE.addIEdata;
3257 vos_mem_copy(pRoamInfo->peerMac,
3258 pUpperLayerAssocCnf->peerMacAddr,
3259 sizeof(tSirMacAddr));
3260 vos_mem_copy(&pRoamInfo->bssid,
3261 pUpperLayerAssocCnf->bssId,
3262 sizeof(tCsrBssid));
3263 pRoamInfo->wmmEnabledSta = pUpperLayerAssocCnf->wmmEnabledSta;
Hardik Kantilal Patel1ba630f2014-11-21 04:32:05 +05303264#ifdef WLAN_FEATURE_AP_HT40_24G
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303265 pRoamInfo->HT40MHzIntoEnabledSta =
3266 pUpperLayerAssocCnf->HT40MHzIntoEnabledSta;
Hardik Kantilal Patel1ba630f2014-11-21 04:32:05 +05303267#endif
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303268 if(CSR_IS_INFRA_AP(pRoamInfo->u.pConnectedProfile) )
3269 {
3270 pMac->roam.roamSession[sessionId].connectState =
3271 eCSR_ASSOC_STATE_TYPE_INFRA_CONNECTED;
3272 pRoamInfo->fReassocReq = pUpperLayerAssocCnf->reassocReq;
3273 status = csrRoamCallCallback(pMac, sessionId, pRoamInfo,
3274 0, eCSR_ROAM_INFRA_IND,
3275 eCSR_ROAM_RESULT_INFRA_ASSOCIATION_CNF);
3276 }
3277 if(CSR_IS_WDS_AP( pRoamInfo->u.pConnectedProfile))
3278 {
3279 vos_sleep( 100 );
3280 pMac->roam.roamSession[sessionId].connectState =
3281 eCSR_ASSOC_STATE_TYPE_WDS_CONNECTED;//Sta
3282 status = csrRoamCallCallback(pMac, sessionId, pRoamInfo, 0,
3283 eCSR_ROAM_WDS_IND,
3284 eCSR_ROAM_RESULT_WDS_ASSOCIATION_IND);//Sta
3285 }
3286 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07003287 }
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303288 case eWNI_SME_DISCONNECT_DONE_IND:
3289 pDisConDoneInd = (tSirSmeDisConDoneInd *)(pMsg);
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08003290
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303291 smsLog( pMac, LOG1,
3292 FL("eWNI_SME_DISCONNECT_DONE_IND RC:%d"),
3293 pDisConDoneInd->reasonCode);
Sreelakshmi Konamki033cf602016-10-12 15:30:14 +05303294 pSession = CSR_GET_SESSION(pMac,pDisConDoneInd->sessionId);
3295 if (pSession)
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08003296 {
Sreelakshmi Konamki033cf602016-10-12 15:30:14 +05303297 if( CSR_IS_SESSION_VALID(pMac, pDisConDoneInd->sessionId))
3298 {
3299 roamInfo.reasonCode = pDisConDoneInd->reasonCode;
3300 roamInfo.statusCode = eSIR_SME_STA_DISASSOCIATED;
3301 vos_mem_copy(roamInfo.peerMac, pDisConDoneInd->peerMacAddr,
3302 sizeof(tSirMacAddr));
3303 status = csrRoamCallCallback(pMac,
3304 pDisConDoneInd->sessionId,
3305 &roamInfo, 0,
3306 eCSR_ROAM_LOSTLINK,
3307 eCSR_ROAM_RESULT_DISASSOC_IND);
3308 /*
3309 * Update the previous state if
3310 * previous state was eCSR_ROAMING_STATE_JOINED
3311 * as we are disconnected and
3312 * currunt state is scanning
3313 */
3314 if (!CSR_IS_INFRA_AP(&pSession->connectedProfile)
3315 && (eCSR_ROAMING_STATE_IDLE !=
3316 pMac->roam.prev_state[pDisConDoneInd->sessionId]))
3317 pMac->roam.prev_state[pDisConDoneInd->sessionId] =
3318 eCSR_ROAMING_STATE_IDLE;
3319 }
3320 else
3321 {
3322 smsLog(pMac, LOGE, FL("Inactive session %d"),
Abhishek Singhf52182c2016-08-24 11:15:23 +05303323 pDisConDoneInd->sessionId);
Sreelakshmi Konamki033cf602016-10-12 15:30:14 +05303324 status = eHAL_STATUS_FAILURE;
3325 }
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08003326 }
3327 else
3328 {
Sreelakshmi Konamki033cf602016-10-12 15:30:14 +05303329 smsLog(pMac, LOGE, FL("Invalid session"));
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303330 status = eHAL_STATUS_FAILURE;
3331 }
3332 break;
3333
3334 default :
3335 if( csrIsAnySessionInConnectState( pMac ) )
3336 {
3337 /*In case of we are connected, we need to check whether connect
3338 * status changes because scan may also run while connected.
3339 */
3340 csrRoamCheckForLinkStatusChange( pMac, (tSirSmeRsp *)pMsgBuf );
3341 }
3342 else
3343 {
3344 smsLog( pMac, LOGW,
3345 "Message [0x%04x] received in state, when expecting Scan Response",
3346 pMsg->type );
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08003347 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003348 }
3349 }
3350
3351 return (status);
3352}
3353
3354
3355
3356void csrCheckNSaveWscIe(tpAniSirGlobal pMac, tSirBssDescription *pNewBssDescr, tSirBssDescription *pOldBssDescr)
3357{
3358 int idx, len;
3359 tANI_U8 *pbIe;
3360
3361 //If failed to remove, assuming someone else got it.
3362 if((pNewBssDescr->fProbeRsp != pOldBssDescr->fProbeRsp) &&
3363 (0 == pNewBssDescr->WscIeLen))
3364 {
3365 idx = 0;
Abhishek Singhbad2b322016-10-21 11:22:33 +05303366 len = GET_IE_LEN_IN_BSS(pOldBssDescr->length)
3367 - DOT11F_IE_WSCPROBERES_MIN_LEN - 2;
Jeff Johnson295189b2012-06-20 16:38:30 -07003368 pbIe = (tANI_U8 *)pOldBssDescr->ieFields;
3369 //Save WPS IE if it exists
3370 pNewBssDescr->WscIeLen = 0;
3371 while(idx < len)
3372 {
3373 if((DOT11F_EID_WSCPROBERES == pbIe[0]) &&
3374 (0x00 == pbIe[2]) && (0x50 == pbIe[3]) && (0xf2 == pbIe[4]) && (0x04 == pbIe[5]))
3375 {
3376 //Founrd it
3377 if((DOT11F_IE_WSCPROBERES_MAX_LEN - 2) >= pbIe[1])
3378 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303379 vos_mem_copy(pNewBssDescr->WscIeProbeRsp, pbIe, pbIe[1] + 2);
Jeff Johnson295189b2012-06-20 16:38:30 -07003380 pNewBssDescr->WscIeLen = pbIe[1] + 2;
3381 }
3382 break;
3383 }
3384 idx += pbIe[1] + 2;
3385 pbIe += pbIe[1] + 2;
3386 }
3387 }
3388}
3389
3390
3391
3392//pIes may be NULL
3393tANI_BOOLEAN csrRemoveDupBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDescr,
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05303394 tDot11fBeaconIEs *pIes, tAniSSID *pSsid, v_TIME_t *timer, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07003395{
3396 tListElem *pEntry;
3397
3398 tCsrScanResult *pBssDesc;
3399 tANI_BOOLEAN fRC = FALSE;
Abhishek Singh56c29812018-06-12 14:07:52 +05303400 tDot11fBeaconIEs *temp_ie = pIes;
3401
3402 if (!temp_ie)
3403 csrGetParsedBssDescriptionIEs(pMac, pSirBssDescr, &temp_ie);
Jeff Johnson295189b2012-06-20 16:38:30 -07003404
3405 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
3406 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
3407 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
3408 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
3409
3410 while( pEntry )
3411 {
3412 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3413
3414 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
3415 // matches
Abhishek Singh56c29812018-06-12 14:07:52 +05303416 if (csrIsDuplicateBssDescription(pMac, &pBssDesc->Result.BssDescriptor,
3417 pSirBssDescr, temp_ie, fForced))
Jeff Johnson295189b2012-06-20 16:38:30 -07003418 {
Abhishek Singh56c29812018-06-12 14:07:52 +05303419 /*
3420 * Due to Rx sensitivity issue, sometime beacons are seen on
3421 * adjacent channel so workaround in software is needed. If DS
3422 * params or HT info are present driver can get proper channel
3423 * info from these IEs and the older RSSI values are used in new
3424 * entry.
3425 *
3426 * For the cases where DS params and HT info is not present,
3427 * driver needs to check below conditions to update proper
3428 * channel so that the older RSSI and channel values are used in
3429 * new entry:
3430 * -- The old entry channel and new entry channel are not same
3431 * -- RSSI is below 15db or more from old value, this indicate
3432 * that the signal has leaked in adjacent channel
3433 */
3434 if (!pSirBssDescr->fProbeRsp &&
3435 (temp_ie && !temp_ie->DSParams.present &&
3436 !temp_ie->HTInfo.present) &&
3437 (pSirBssDescr->channelId !=
3438 pBssDesc->Result.BssDescriptor.channelId) &&
3439 ((pBssDesc->Result.BssDescriptor.rssi - pSirBssDescr->rssi) >
3440 SIR_ADJACENT_CHANNEL_RSSI_DIFF_THRESHOLD)) {
3441 pSirBssDescr->channelId =
3442 pBssDesc->Result.BssDescriptor.channelId;
3443 pSirBssDescr->rssi =
3444 pBssDesc->Result.BssDescriptor.rssi;
3445 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003446 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
3447 ((tANI_S32)pBssDesc->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
3448 // Remove the 'old' entry from the list....
3449 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry, LL_ACCESS_LOCK ) )
3450 {
3451 // !we need to free the memory associated with this node
3452 //If failed to remove, assuming someone else got it.
3453 *pSsid = pBssDesc->Result.ssId;
3454 *timer = pBssDesc->Result.timer;
3455 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pBssDesc->Result.BssDescriptor);
3456
3457 csrFreeScanResultEntry( pMac, pBssDesc );
3458 }
3459 else
3460 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003461 smsLog( pMac, LOGW, FL( " fail to remove entry" ) );
Jeff Johnson295189b2012-06-20 16:38:30 -07003462 }
3463 fRC = TRUE;
3464
3465 // If we found a match, we can stop looking through the list.
3466 break;
3467 }
3468
3469 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_LOCK );
3470 }
3471
Abhishek Singh56c29812018-06-12 14:07:52 +05303472 if (!pIes && temp_ie)
3473 vos_mem_free(temp_ie);
3474
Jeff Johnson295189b2012-06-20 16:38:30 -07003475 return fRC;
3476}
3477
3478
3479eHalStatus csrAddPMKIDCandidateList( tpAniSirGlobal pMac, tANI_U32 sessionId,
3480 tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes )
3481{
3482 eHalStatus status = eHAL_STATUS_FAILURE;
3483 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
3484
Jeff Johnson32d95a32012-09-10 13:15:23 -07003485 if(!pSession)
3486 {
3487 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
3488 return eHAL_STATUS_FAILURE;
3489 }
3490
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003491 smsLog(pMac, LOGW, "csrAddPMKIDCandidateList called pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07003492 if( pIes )
3493 {
3494 // check if this is a RSN BSS
3495 if( pIes->RSN.present )
3496 {
3497 // Check if the BSS is capable of doing pre-authentication
3498 if( pSession->NumPmkidCandidate < CSR_MAX_PMKID_ALLOWED )
3499 {
3500
3501#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3502 {
3503 WLAN_VOS_DIAG_EVENT_DEF(secEvent, vos_event_wlan_security_payload_type);
Kiet Lam64c1b492013-07-12 13:56:44 +05303504 vos_mem_set(&secEvent, sizeof(vos_event_wlan_security_payload_type), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003505 secEvent.eventId = WLAN_SECURITY_EVENT_PMKID_CANDIDATE_FOUND;
3506 secEvent.encryptionModeMulticast =
3507 (v_U8_t)diagEncTypeFromCSRType(pSession->connectedProfile.mcEncryptionType);
3508 secEvent.encryptionModeUnicast =
3509 (v_U8_t)diagEncTypeFromCSRType(pSession->connectedProfile.EncryptionType);
Kiet Lam64c1b492013-07-12 13:56:44 +05303510 vos_mem_copy(secEvent.bssid, pSession->connectedProfile.bssid, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07003511 secEvent.authMode =
3512 (v_U8_t)diagAuthTypeFromCSRType(pSession->connectedProfile.AuthType);
3513 WLAN_VOS_DIAG_EVENT_REPORT(&secEvent, EVENT_WLAN_SECURITY);
3514 }
3515#endif//#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3516
3517 // if yes, then add to PMKIDCandidateList
Kiet Lam64c1b492013-07-12 13:56:44 +05303518 vos_mem_copy(pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].BSSID,
3519 pBssDesc->bssId, WNI_CFG_BSSID_LEN);
3520 // Bit 0 offirst byte - PreAuthentication Capability
3521 if ( (pIes->RSN.RSN_Cap[0] >> 0) & 0x1 )
Jeff Johnson295189b2012-06-20 16:38:30 -07003522 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303523 pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].preAuthSupported
3524 = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003525 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303526 else
3527 {
3528 pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].preAuthSupported
3529 = eANI_BOOLEAN_FALSE;
3530 }
3531 pSession->NumPmkidCandidate++;
Jeff Johnson295189b2012-06-20 16:38:30 -07003532 }
3533 else
3534 {
3535 status = eHAL_STATUS_FAILURE;
3536 }
3537 }
3538 }
3539
3540 return (status);
3541}
3542
3543//This function checks whether new AP is found for the current connected profile
3544//If it is found, it return the sessionId, else it return invalid sessionID
3545tANI_U32 csrProcessBSSDescForPMKIDList(tpAniSirGlobal pMac,
3546 tSirBssDescription *pBssDesc,
3547 tDot11fBeaconIEs *pIes)
3548{
3549 tANI_U32 i, bRet = CSR_SESSION_ID_INVALID;
3550 tCsrRoamSession *pSession;
3551 tDot11fBeaconIEs *pIesLocal = pIes;
3552
3553 if( pIesLocal || HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIesLocal)) )
3554 {
3555 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
3556 {
3557 if( CSR_IS_SESSION_VALID( pMac, i ) )
3558 {
3559 pSession = CSR_GET_SESSION( pMac, i );
3560 if( csrIsConnStateConnectedInfra( pMac, i ) &&
3561 ( eCSR_AUTH_TYPE_RSN == pSession->connectedProfile.AuthType ) )
3562 {
3563 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile, pBssDesc, pIesLocal))
3564 {
3565 //this new BSS fits the current profile connected
3566 if(HAL_STATUS_SUCCESS(csrAddPMKIDCandidateList(pMac, i, pBssDesc, pIesLocal)))
3567 {
3568 bRet = i;
3569 }
3570 break;
3571 }
3572 }
3573 }
3574 }
3575 if( !pIes )
3576 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303577 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003578 }
3579 }
3580
3581 return (tANI_U8)bRet;
3582}
3583
3584#ifdef FEATURE_WLAN_WAPI
3585eHalStatus csrAddBKIDCandidateList( tpAniSirGlobal pMac, tANI_U32 sessionId,
3586 tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes )
3587{
3588 eHalStatus status = eHAL_STATUS_FAILURE;
3589 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
3590
Jeff Johnson32d95a32012-09-10 13:15:23 -07003591 if(!pSession)
3592 {
3593 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
3594 return eHAL_STATUS_FAILURE;
3595 }
3596
Kiet Lam64c1b492013-07-12 13:56:44 +05303597 smsLog(pMac, LOGW, "csrAddBKIDCandidateList called pMac->scan.NumBkidCandidate = %d",
3598 pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07003599 if( pIes )
3600 {
3601 // check if this is a WAPI BSS
3602 if( pIes->WAPI.present )
3603 {
3604 // Check if the BSS is capable of doing pre-authentication
3605 if( pSession->NumBkidCandidate < CSR_MAX_BKID_ALLOWED )
3606 {
3607
3608 // if yes, then add to BKIDCandidateList
Kiet Lam64c1b492013-07-12 13:56:44 +05303609 vos_mem_copy(pSession->BkidCandidateInfo[pSession->NumBkidCandidate].BSSID,
3610 pBssDesc->bssId, WNI_CFG_BSSID_LEN);
3611 if ( pIes->WAPI.preauth )
Jeff Johnson295189b2012-06-20 16:38:30 -07003612 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303613 pSession->BkidCandidateInfo[pSession->NumBkidCandidate].preAuthSupported
3614 = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003615 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303616 else
3617 {
3618 pSession->BkidCandidateInfo[pSession->NumBkidCandidate].preAuthSupported
3619 = eANI_BOOLEAN_FALSE;
3620 }
3621 pSession->NumBkidCandidate++;
Jeff Johnson295189b2012-06-20 16:38:30 -07003622 }
3623 else
3624 {
3625 status = eHAL_STATUS_FAILURE;
3626 }
3627 }
3628 }
3629
3630 return (status);
3631}
3632
3633//This function checks whether new AP is found for the current connected profile
3634//if so add to BKIDCandidateList
3635tANI_BOOLEAN csrProcessBSSDescForBKIDList(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
3636 tDot11fBeaconIEs *pIes)
3637{
3638 tANI_BOOLEAN fRC = FALSE;
3639 tDot11fBeaconIEs *pIesLocal = pIes;
3640 tANI_U32 sessionId;
3641 tCsrRoamSession *pSession;
3642
3643 if( pIesLocal || HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIesLocal)) )
3644 {
3645 for( sessionId = 0; sessionId < CSR_ROAM_SESSION_MAX; sessionId++ )
3646 {
3647 if( CSR_IS_SESSION_VALID( pMac, sessionId) )
3648 {
3649 pSession = CSR_GET_SESSION( pMac, sessionId );
3650 if( csrIsConnStateConnectedInfra( pMac, sessionId ) &&
3651 eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE == pSession->connectedProfile.AuthType)
3652 {
3653 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile,pBssDesc, pIesLocal))
3654 {
3655 //this new BSS fits the current profile connected
3656 if(HAL_STATUS_SUCCESS(csrAddBKIDCandidateList(pMac, sessionId, pBssDesc, pIesLocal)))
3657 {
3658 fRC = TRUE;
3659 }
3660 }
3661 }
3662 }
3663 }
3664 if(!pIes)
3665 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303666 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003667 }
3668
3669 }
3670 return fRC;
3671}
3672
3673#endif
3674
3675
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07003676static void csrMoveTempScanResultsToMainList( tpAniSirGlobal pMac, tANI_U8 reason )
Jeff Johnson295189b2012-06-20 16:38:30 -07003677{
3678 tListElem *pEntry;
3679 tCsrScanResult *pBssDescription;
Jeff Johnson295189b2012-06-20 16:38:30 -07003680 tANI_BOOLEAN fDupBss;
3681#ifdef FEATURE_WLAN_WAPI
3682 tANI_BOOLEAN fNewWapiBSSForCurConnection = eANI_BOOLEAN_FALSE;
3683#endif /* FEATURE_WLAN_WAPI */
3684 tDot11fBeaconIEs *pIesLocal = NULL;
3685 tANI_U32 sessionId = CSR_SESSION_ID_INVALID;
3686 tAniSSID tmpSsid;
3687 v_TIME_t timer=0;
Kapil Gupta2f2fae42016-09-15 15:29:47 +05303688 tANI_U8 occupied_chan_count = pMac->scan.occupiedChannels.numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -07003689
3690 tmpSsid.length = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07003691
3692 // remove the BSS descriptions from temporary list
3693 while( ( pEntry = csrLLRemoveTail( &pMac->scan.tempScanResults, LL_ACCESS_LOCK ) ) != NULL)
3694 {
3695 pBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3696
Vinay Krishna Eranna566365f2015-03-09 12:34:13 +05303697 smsLog( pMac, LOG2, "...Bssid= "MAC_ADDRESS_STR" chan= %d, rssi = -%d",
Arif Hussain24bafea2013-11-15 15:10:03 -08003698 MAC_ADDR_ARRAY(pBssDescription->Result.BssDescriptor.bssId),
Jeff Johnson295189b2012-06-20 16:38:30 -07003699 pBssDescription->Result.BssDescriptor.channelId,
3700 pBssDescription->Result.BssDescriptor.rssi * (-1) );
3701
3702 //At this time, pBssDescription->Result.pvIes may be NULL
3703 pIesLocal = (tDot11fBeaconIEs *)( pBssDescription->Result.pvIes );
3704 if( !pIesLocal && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pBssDescription->Result.BssDescriptor, &pIesLocal))) )
3705 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003706 smsLog(pMac, LOGE, FL(" Cannot pared IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003707 csrFreeScanResultEntry(pMac, pBssDescription);
3708 continue;
3709 }
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05303710 fDupBss = csrRemoveDupBssDescription( pMac, &pBssDescription->Result.BssDescriptor, pIesLocal, &tmpSsid, &timer, FALSE );
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07003711 //Check whether we have reach out limit, but don't lose the LFR candidates came from FW
3712 if( CSR_SCAN_IS_OVER_BSS_LIMIT(pMac)
3713#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
3714 && !( eCsrScanGetLfrResult == reason )
3715#endif
3716 )
Jeff Johnson295189b2012-06-20 16:38:30 -07003717 {
Deepthi Gowri50e2fa52016-03-17 15:30:53 +05303718 smsLog(pMac, LOG1, FL("########## BSS Limit reached ###########"));
Abhishek Singh5deecd12017-06-12 11:08:40 +05303719 csrPurgeScanResults(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07003720 }
3721 // check for duplicate scan results
3722 if ( !fDupBss )
3723 {
3724 //Found a new BSS
3725 sessionId = csrProcessBSSDescForPMKIDList(pMac,
3726 &pBssDescription->Result.BssDescriptor, pIesLocal);
3727 if( CSR_SESSION_ID_INVALID != sessionId)
3728 {
3729 csrRoamCallCallback(pMac, sessionId, NULL, 0,
3730 eCSR_ROAM_SCAN_FOUND_NEW_BSS, eCSR_ROAM_RESULT_NONE);
3731 }
3732 }
3733 else
3734 {
3735 //Check if the new one has SSID it it, if not, use the older SSID if it exists.
3736 if( (0 == pBssDescription->Result.ssId.length) && tmpSsid.length )
3737 {
3738 //New BSS has a hidden SSID and old one has the SSID. Keep the SSID only
3739 //if diff of saved SSID time and current time is less than 1 min to avoid
3740 //side effect of saving SSID with old one is that if AP changes its SSID while remain
3741 //hidden, we may never see it and also to address the requirement of
3742 //When we remove hidden ssid from the profile i.e., forget the SSID via
3743 // GUI that SSID shouldn't see in the profile
3744 if( (vos_timer_get_system_time() - timer) <= HIDDEN_TIMER)
3745 {
3746 pBssDescription->Result.timer = timer;
3747 pBssDescription->Result.ssId = tmpSsid;
3748 }
3749 }
3750 }
3751
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303752 //Find a good AP for 11d info
3753 if ( csrIs11dSupported( pMac ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003754 {
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303755 // check if country information element is present
3756 if (pIesLocal->Country.present)
Jeff Johnson295189b2012-06-20 16:38:30 -07003757 {
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303758 csrAddVoteForCountryInfo(pMac, pIesLocal->Country.country);
3759 smsLog(pMac, LOGW, FL("11d AP Bssid " MAC_ADDRESS_STR
3760 " chan= %d, rssi = -%d, countryCode %c%c"),
3761 MAC_ADDR_ARRAY( pBssDescription->Result.BssDescriptor.bssId),
3762 pBssDescription->Result.BssDescriptor.channelId,
3763 pBssDescription->Result.BssDescriptor.rssi * (-1),
3764 pIesLocal->Country.country[0],pIesLocal->Country.country[1] );
3765 }
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303766
Jeff Johnson295189b2012-06-20 16:38:30 -07003767 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08003768
Jeff Johnson295189b2012-06-20 16:38:30 -07003769 // append to main list
3770 csrScanAddResult(pMac, pBssDescription, pIesLocal);
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303771 if ( (pBssDescription->Result.pvIes == NULL) && pIesLocal )
Jeff Johnson295189b2012-06-20 16:38:30 -07003772 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303773 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003774 }
3775 }
3776
Kapil Gupta2f2fae42016-09-15 15:29:47 +05303777#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
3778 if (sme_IsFeatureSupportedByFW(PER_BASED_ROAMING) &&
3779 (csrGetInfraSessionId(pMac) != -1) &&
3780 (pMac->scan.occupiedChannels.numChannels != occupied_chan_count))
3781 {
3782 /* Update FW with new list */
3783 smsLog(pMac, LOGW,
3784 FL("Updating occupied channel list, new chanNum %d"),
3785 pMac->scan.occupiedChannels.numChannels);
3786 csrRoamOffloadScan(pMac, ROAM_SCAN_OFFLOAD_UPDATE_CFG,
3787 REASON_CHANNEL_LIST_CHANGED);
3788 }
3789#endif
Sushant Kaushik6274de62015-05-01 16:31:23 +05303790 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
Tushnim Bhattacharyyaae317772013-10-23 18:55:38 -07003791 //we don't need to update CC while connected to an AP which is advertising CC already
3792 if (csrIs11dSupported(pMac))
3793 {
3794 tANI_U32 i;
3795 tCsrRoamSession *pSession;
3796
3797 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
3798 {
3799 if (CSR_IS_SESSION_VALID( pMac, i ) )
3800 {
3801 pSession = CSR_GET_SESSION( pMac, i );
3802 if (csrIsConnStateConnected(pMac, i))
3803 {
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303804 smsLog(pMac, LOGW, FL("No need for updating CC in"
3805 "connected state"));
3806 goto end;
Tushnim Bhattacharyyaae317772013-10-23 18:55:38 -07003807 }
3808 }
3809 }
Agrawal Ashishbd3a5932016-04-12 16:22:39 +05303810 if (csrElectedCountryInfo(pMac))
3811 csrLearnCountryInformation(pMac, NULL, NULL,
3812 eANI_BOOLEAN_TRUE);
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303813 }
3814
Tushnim Bhattacharyyaae317772013-10-23 18:55:38 -07003815end:
3816 //If we can find the current 11d info in any of the scan results, or
Jeff Johnson295189b2012-06-20 16:38:30 -07003817 // a good enough AP with the 11d info from the scan results then no need to
3818 // get into ambiguous state
3819 if(pMac->scan.fAmbiguous11dInfoFound)
3820 {
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303821 if((pMac->scan.fCurrent11dInfoMatch))
Jeff Johnson295189b2012-06-20 16:38:30 -07003822 {
3823 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
3824 }
3825 }
3826
3827#ifdef FEATURE_WLAN_WAPI
3828 if(fNewWapiBSSForCurConnection)
3829 {
3830 //remember it first
3831 csrRoamCallCallback(pMac, sessionId, NULL, 0, eCSR_ROAM_SCAN_FOUND_NEW_BSS, eCSR_ROAM_RESULT_NEW_WAPI_BSS);
3832 }
3833#endif /* FEATURE_WLAN_WAPI */
3834
3835 return;
3836}
3837
Abhishek Singh5deecd12017-06-12 11:08:40 +05303838/**
3839 * csrPurgeScanResults() - This function removes scan entry based
3840 * on RSSI or AGE
3841 * @pMac: pointer to Global MAC structure
3842 *
3843 * This function removes scan entry based on RSSI or AGE.
3844 * If an scan entry with RSSI less than CSR_PURGE_RSSI_THRESHOLD,
3845 * the scan entry is removed else oldest entry is removed.
3846 *
3847 * Return: None
3848 */
3849void csrPurgeScanResults(tpAniSirGlobal pMac)
Deepthi Gowri50e2fa52016-03-17 15:30:53 +05303850{
3851 tListElem *pEntry, *tmpEntry;
Abhishek Singh5deecd12017-06-12 11:08:40 +05303852 tCsrScanResult *pResult, *oldest_bss = NULL, *weakest_bss = NULL;
Deepthi Gowri4480a3f2016-05-18 19:30:17 +05303853 v_TIME_t oldest_entry = 0;
3854 v_TIME_t curTime = vos_timer_get_system_time();
Abhishek Singh5deecd12017-06-12 11:08:40 +05303855 tANI_S8 weakest_rssi = 0;
Deepthi Gowri50e2fa52016-03-17 15:30:53 +05303856
3857 csrLLLock(&pMac->scan.scanResultList);
3858 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
Abhishek Singh5deecd12017-06-12 11:08:40 +05303859 while(pEntry)
Deepthi Gowri50e2fa52016-03-17 15:30:53 +05303860 {
3861 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry,
3862 LL_ACCESS_NOLOCK);
3863 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3864 if((curTime -
3865 pResult->Result.BssDescriptor.nReceivedTime) > oldest_entry)
3866 {
3867 oldest_entry = curTime -
3868 pResult->Result.BssDescriptor.nReceivedTime;
3869 oldest_bss = pResult;
3870 }
Abhishek Singh5deecd12017-06-12 11:08:40 +05303871 if (pResult->Result.BssDescriptor.rssi < weakest_rssi)
3872 {
3873 weakest_rssi = pResult->Result.BssDescriptor.rssi;
3874 weakest_bss = pResult;
3875 }
Deepthi Gowri50e2fa52016-03-17 15:30:53 +05303876 pEntry = tmpEntry;
3877 }
3878 if (oldest_bss)
3879 {
Abhishek Singh5deecd12017-06-12 11:08:40 +05303880 tCsrScanResult *bss_to_remove;
3881
3882 if (weakest_rssi < CSR_PURGE_RSSI_THRESHOLD)
3883 bss_to_remove = weakest_bss;
3884 else
3885 bss_to_remove = oldest_bss;
3886
Deepthi Gowri50e2fa52016-03-17 15:30:53 +05303887 //Free the old BSS Entries
Abhishek Singh5deecd12017-06-12 11:08:40 +05303888 if(csrLLRemoveEntry(&pMac->scan.scanResultList,
3889 &bss_to_remove->Link, LL_ACCESS_NOLOCK))
Deepthi Gowri50e2fa52016-03-17 15:30:53 +05303890 {
Abhishek Singh5deecd12017-06-12 11:08:40 +05303891 smsLog(pMac, LOG1,
3892 FL("BSSID: "MAC_ADDRESS_STR" Removed, time delta (%lu) RSSI %d"),
3893 MAC_ADDR_ARRAY(
3894 bss_to_remove->Result.BssDescriptor.bssId),
3895 (curTime -
3896 bss_to_remove->Result.BssDescriptor.nReceivedTime),
3897 bss_to_remove->Result.BssDescriptor.rssi);
3898 csrFreeScanResultEntry(pMac, bss_to_remove);
Deepthi Gowri50e2fa52016-03-17 15:30:53 +05303899 }
3900 }
3901 csrLLUnlock(&pMac->scan.scanResultList);
3902}
Jeff Johnson295189b2012-06-20 16:38:30 -07003903
3904static tCsrScanResult *csrScanSaveBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pBSSDescription,
3905 tDot11fBeaconIEs *pIes)
3906{
3907 tCsrScanResult *pCsrBssDescription = NULL;
3908 tANI_U32 cbBSSDesc;
3909 tANI_U32 cbAllocated;
Sushant Kaushik6274de62015-05-01 16:31:23 +05303910 tListElem *pEntry;
Jeff Johnson295189b2012-06-20 16:38:30 -07003911
3912 // figure out how big the BSS description is (the BSSDesc->length does NOT
3913 // include the size of the length field itself).
3914 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
3915
3916 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
3917
Kiet Lam64c1b492013-07-12 13:56:44 +05303918 pCsrBssDescription = vos_mem_malloc(cbAllocated);
3919 if ( NULL != pCsrBssDescription )
Jeff Johnson295189b2012-06-20 16:38:30 -07003920 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303921 vos_mem_set(pCsrBssDescription, cbAllocated, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003922 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Kiet Lam64c1b492013-07-12 13:56:44 +05303923 vos_mem_copy(&pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc);
Jeff Johnson295189b2012-06-20 16:38:30 -07003924#if defined(VOSS_ENSBALED)
3925 VOS_ASSERT( pCsrBssDescription->Result.pvIes == NULL );
3926#endif
3927 csrScanAddResult(pMac, pCsrBssDescription, pIes);
Sushant Kaushik6274de62015-05-01 16:31:23 +05303928 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
Jeff Johnson295189b2012-06-20 16:38:30 -07003929 }
3930
3931 return( pCsrBssDescription );
3932}
3933
3934// Append a Bss Description...
3935tCsrScanResult *csrScanAppendBssDescription( tpAniSirGlobal pMac,
3936 tSirBssDescription *pSirBssDescription,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07003937 tDot11fBeaconIEs *pIes, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07003938{
3939 tCsrScanResult *pCsrBssDescription = NULL;
3940 tAniSSID tmpSsid;
3941 v_TIME_t timer = 0;
3942 int result;
3943
3944 tmpSsid.length = 0;
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07003945 result = csrRemoveDupBssDescription( pMac, pSirBssDescription, pIes, &tmpSsid, &timer, fForced );
Jeff Johnson295189b2012-06-20 16:38:30 -07003946 pCsrBssDescription = csrScanSaveBssDescription( pMac, pSirBssDescription, pIes );
3947 if (result && (pCsrBssDescription != NULL))
3948 {
3949 //Check if the new one has SSID it it, if not, use the older SSID if it exists.
3950 if( (0 == pCsrBssDescription->Result.ssId.length) && tmpSsid.length )
3951 {
3952 //New BSS has a hidden SSID and old one has the SSID. Keep the SSID only
3953 //if diff of saved SSID time and current time is less than 1 min to avoid
3954 //side effect of saving SSID with old one is that if AP changes its SSID while remain
3955 //hidden, we may never see it and also to address the requirement of
3956 //When we remove hidden ssid from the profile i.e., forget the SSID via
3957 // GUI that SSID shouldn't see in the profile
3958 if((vos_timer_get_system_time()-timer) <= HIDDEN_TIMER)
3959 {
3960 pCsrBssDescription->Result.ssId = tmpSsid;
3961 pCsrBssDescription->Result.timer = timer;
3962 }
3963 }
3964 }
3965
3966
3967 return( pCsrBssDescription );
3968}
3969
3970
3971
3972void csrPurgeChannelPower( tpAniSirGlobal pMac, tDblLinkList *pChannelList )
3973{
3974 tCsrChannelPowerInfo *pChannelSet;
3975 tListElem *pEntry;
3976
3977 csrLLLock(pChannelList);
3978 // Remove the channel sets from the learned list and put them in the free list
3979 while( ( pEntry = csrLLRemoveHead( pChannelList, LL_ACCESS_NOLOCK ) ) != NULL)
3980 {
3981 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3982 if( pChannelSet )
3983 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303984 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003985 }
3986 }
3987 csrLLUnlock(pChannelList);
3988 return;
3989}
3990
3991
3992/*
3993 * Save the channelList into the ultimate storage as the final stage of channel
3994 * Input: pCountryInfo -- the country code (e.g. "USI"), channel list, and power limit are all stored inside this data structure
3995 */
Jeff Johnsone7245742012-09-05 17:12:55 -07003996eHalStatus csrSaveToChannelPower2G_5G( tpAniSirGlobal pMac, tANI_U32 tableSize, tSirMacChanInfo *channelTable )
Jeff Johnson295189b2012-06-20 16:38:30 -07003997{
3998 tANI_U32 i = tableSize / sizeof( tSirMacChanInfo );
3999 tSirMacChanInfo *pChannelInfo;
4000 tCsrChannelPowerInfo *pChannelSet;
4001 tANI_BOOLEAN f2GHzInfoFound = FALSE;
4002 tANI_BOOLEAN f2GListPurged = FALSE, f5GListPurged = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004003
4004 pChannelInfo = channelTable;
4005 // atleast 3 bytes have to be remaining -- from "countryString"
4006 while ( i-- )
4007 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304008 pChannelSet = vos_mem_malloc(sizeof(tCsrChannelPowerInfo));
4009 if ( NULL != pChannelSet )
Jeff Johnson295189b2012-06-20 16:38:30 -07004010 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304011 vos_mem_set(pChannelSet, sizeof(tCsrChannelPowerInfo), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004012 pChannelSet->firstChannel = pChannelInfo->firstChanNum;
4013 pChannelSet->numChannels = pChannelInfo->numChannels;
4014
4015 // Now set the inter-channel offset based on the frequency band the channel set lies in
Jeff Johnsone7245742012-09-05 17:12:55 -07004016 if( (CSR_IS_CHANNEL_24GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07004017 ((pChannelSet->firstChannel + (pChannelSet->numChannels - 1)) <= CSR_MAX_24GHz_CHANNEL_NUMBER) )
Jeff Johnsone7245742012-09-05 17:12:55 -07004018
Jeff Johnson295189b2012-06-20 16:38:30 -07004019 {
4020 pChannelSet->interChannelOffset = 1;
4021 f2GHzInfoFound = TRUE;
4022 }
Jeff Johnsone7245742012-09-05 17:12:55 -07004023 else if ( (CSR_IS_CHANNEL_5GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07004024 ((pChannelSet->firstChannel + ((pChannelSet->numChannels - 1) * 4)) <= CSR_MAX_5GHz_CHANNEL_NUMBER) )
Jeff Johnson295189b2012-06-20 16:38:30 -07004025 {
4026 pChannelSet->interChannelOffset = 4;
4027 f2GHzInfoFound = FALSE;
4028 }
Jeff Johnsone7245742012-09-05 17:12:55 -07004029 else
4030 {
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07004031 smsLog( pMac, LOGW, FL("Invalid Channel %d Present in Country IE"),
Jeff Johnsone7245742012-09-05 17:12:55 -07004032 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05304033 vos_mem_free(pChannelSet);
Jeff Johnsone7245742012-09-05 17:12:55 -07004034 return eHAL_STATUS_FAILURE;
4035 }
4036
Jeff Johnson295189b2012-06-20 16:38:30 -07004037 pChannelSet->txPower = CSR_ROAM_MIN( pChannelInfo->maxTxPower, pMac->roam.configParam.nTxPowerCap );
4038
4039 if( f2GHzInfoFound )
4040 {
4041 if( !f2GListPurged )
4042 {
4043 // purge previous results if found new
4044 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList24 );
4045 f2GListPurged = TRUE;
4046 }
4047
4048 if(CSR_IS_OPERATING_BG_BAND(pMac))
4049 {
4050 // add to the list of 2.4 GHz channel sets
4051 csrLLInsertTail( &pMac->scan.channelPowerInfoList24, &pChannelSet->link, LL_ACCESS_LOCK );
4052 }
4053 else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004054 smsLog( pMac, LOGW, FL("Adding 11B/G channels in 11A mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07004055 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05304056 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07004057 }
4058 }
4059 else
4060 {
4061 // 5GHz info found
4062 if( !f5GListPurged )
4063 {
4064 // purge previous results if found new
4065 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList5G );
4066 f5GListPurged = TRUE;
4067 }
4068
4069 if(CSR_IS_OPERATING_A_BAND(pMac))
4070 {
4071 // add to the list of 5GHz channel sets
4072 csrLLInsertTail( &pMac->scan.channelPowerInfoList5G, &pChannelSet->link, LL_ACCESS_LOCK );
4073 }
4074 else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004075 smsLog( pMac, LOGW, FL("Adding 11A channels in B/G mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07004076 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05304077 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07004078 }
4079 }
4080 }
4081
4082 pChannelInfo++; // move to next entry
4083 }
4084
Jeff Johnsone7245742012-09-05 17:12:55 -07004085 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07004086}
4087
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05304088static void csrClearDfsChannelList( tpAniSirGlobal pMac )
4089{
4090 tSirMbMsg *pMsg;
4091 tANI_U16 msgLen;
Jeff Johnson295189b2012-06-20 16:38:30 -07004092
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05304093 msgLen = (tANI_U16)(sizeof( tSirMbMsg ));
Kiet Lam64c1b492013-07-12 13:56:44 +05304094 pMsg = vos_mem_malloc(msgLen);
4095 if ( NULL != pMsg )
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05304096 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304097 vos_mem_set((void *)pMsg, msgLen, 0);
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05304098 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_CLEAR_DFS_CHANNEL_LIST);
4099 pMsg->msgLen = pal_cpu_to_be16(msgLen);
4100 palSendMBMessage(pMac->hHdd, pMsg);
4101 }
4102}
Jeff Johnson295189b2012-06-20 16:38:30 -07004103
4104void csrApplyPower2Current( tpAniSirGlobal pMac )
4105{
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004106 smsLog( pMac, LOG3, FL(" Updating Cfg with power settings"));
Jeff Johnson295189b2012-06-20 16:38:30 -07004107 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList24, WNI_CFG_MAX_TX_POWER_2_4 );
4108 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList5G, WNI_CFG_MAX_TX_POWER_5 );
4109}
4110
4111
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004112void csrApplyChannelPowerCountryInfo( tpAniSirGlobal pMac, tCsrChannel *pChannelList, tANI_U8 *countryCode, tANI_BOOLEAN updateRiva)
Jeff Johnson295189b2012-06-20 16:38:30 -07004113{
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304114 int i, j, count, countryIndex = -1;
Jeff Johnson295189b2012-06-20 16:38:30 -07004115 tANI_U8 numChannels = 0;
4116 tANI_U8 tempNumChannels = 0;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304117 tANI_U8 channelIgnore = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004118 tCsrChannel ChannelList;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304119
Jeff Johnson295189b2012-06-20 16:38:30 -07004120 if( pChannelList->numChannels )
4121 {
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304122 for(count=0; count < MAX_COUNTRY_IGNORE; count++)
4123 {
4124 if(vos_mem_compare(countryCode, countryIgnoreList[count].countryCode,
4125 VOS_COUNTRY_CODE_LEN))
4126 {
4127 countryIndex = count;
4128 break;
4129 }
4130 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004131 tempNumChannels = CSR_MIN(pChannelList->numChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN);
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05304132
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304133 for(i=0; i < tempNumChannels; i++)
Jeff Johnson295189b2012-06-20 16:38:30 -07004134 {
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304135 channelIgnore = FALSE;
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05304136 if( countryIndex != -1 )
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304137 {
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05304138 for(j=0; j < countryIgnoreList[countryIndex].channelCount; j++)
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304139 {
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05304140 if( pChannelList->channelList[i] ==
4141 countryIgnoreList[countryIndex].channelList[j] )
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304142 {
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05304143 channelIgnore = TRUE;
4144 break;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304145 }
4146 }
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05304147 }
4148 if( FALSE == channelIgnore )
4149 {
4150 ChannelList.channelList[numChannels] = pChannelList->channelList[i];
4151 numChannels++;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304152 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004153 }
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304154 ChannelList.numChannels = numChannels;
Mahesh A Saptasagar1ed59582014-06-04 18:45:07 +05304155 csrApplyPower2Current( pMac ); // Store the channel+power info in the global place: Cfg
Jeff Johnson295189b2012-06-20 16:38:30 -07004156 csrSetCfgValidChannelList(pMac, ChannelList.channelList, ChannelList.numChannels);
4157 // extend scan capability
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304158 // build a scan list based on the channel list : channel# + active/passive scan
4159 csrSetCfgScanControlList(pMac, countryCode, &ChannelList);
Jeff Johnson295189b2012-06-20 16:38:30 -07004160#ifdef FEATURE_WLAN_SCAN_PNO
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004161 if (updateRiva)
4162 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004163 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO, FL(" Sending 11d PNO info to Riva"));
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004164 // Send HAL UpdateScanParams message
4165 pmcUpdateScanParams(pMac, &(pMac->roam.configParam), &ChannelList, TRUE);
4166 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004167#endif // FEATURE_WLAN_SCAN_PNO
4168 }
4169 else
4170 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004171 smsLog( pMac, LOGE, FL(" 11D channel list is empty"));
Jeff Johnson295189b2012-06-20 16:38:30 -07004172 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004173 csrSetCfgCountryCode(pMac, countryCode);
4174}
4175
Sourav Mohapatra3dd5dba2018-03-26 15:12:47 +05304176void csrUpdateFCCChannelList(tpAniSirGlobal pMac)
4177{
4178 tCsrChannel ChannelList;
4179 tANI_U8 chnlIndx = 0;
4180 int i;
4181
4182 for ( i = 0; i < pMac->scan.base20MHzChannels.numChannels; i++ )
4183 {
4184 if (pMac->scan.fcc_constraint &&
4185 ((pMac->scan.base20MHzChannels.channelList[i] == 12) ||
4186 (pMac->scan.base20MHzChannels.channelList[i] == 13)))
4187 {
4188 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
4189 FL("removing channel %d"),
4190 pMac->scan.base20MHzChannels.channelList[i]);
4191 continue;
4192 }
4193 ChannelList.channelList[chnlIndx] =
4194 pMac->scan.base20MHzChannels.channelList[i];
4195 chnlIndx++;
4196 }
4197 csrSetCfgValidChannelList(pMac, ChannelList.channelList, chnlIndx);
4198 csrScanFilterResults(pMac);
4199}
4200
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004201void csrResetCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce, tANI_BOOLEAN updateRiva )
Jeff Johnson295189b2012-06-20 16:38:30 -07004202{
4203 if( fForce || (csrIs11dSupported( pMac ) && (!pMac->scan.f11dInfoReset)))
4204 {
4205
4206#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4207 {
4208 vos_log_802_11d_pkt_type *p11dLog;
4209 int Index;
4210
4211 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
4212 if(p11dLog)
4213 {
4214 p11dLog->eventId = WLAN_80211D_EVENT_RESET;
Kiet Lam64c1b492013-07-12 13:56:44 +05304215 vos_mem_copy(p11dLog->countryCode, pMac->scan.countryCodeCurrent, 3);
Jeff Johnson295189b2012-06-20 16:38:30 -07004216 p11dLog->numChannel = pMac->scan.base20MHzChannels.numChannels;
4217 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
4218 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304219 vos_mem_copy(p11dLog->Channels,
4220 pMac->scan.base20MHzChannels.channelList,
4221 p11dLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07004222 for (Index=0; Index < pMac->scan.base20MHzChannels.numChannels; Index++)
4223 {
4224 p11dLog->TxPwr[Index] = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
4225 }
4226 }
4227 if(!pMac->roam.configParam.Is11dSupportEnabled)
4228 {
4229 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
4230 }
4231 else if(pMac->roam.configParam.fEnforceDefaultDomain)
4232 {
4233 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
4234 }
4235 else
4236 {
4237 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
4238 }
4239 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
4240 }
4241 }
4242#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4243
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004244 csrPruneChannelListForMode(pMac, &pMac->scan.baseChannels);
4245 csrPruneChannelListForMode(pMac, &pMac->scan.base20MHzChannels);
4246
Jeff Johnson295189b2012-06-20 16:38:30 -07004247 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_FALSE);
4248 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_TRUE);
4249 // ... and apply the channel list, power settings, and the country code.
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004250 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.base20MHzChannels, pMac->scan.countryCodeCurrent, updateRiva );
Jeff Johnson295189b2012-06-20 16:38:30 -07004251 // clear the 11d channel list
Kiet Lam64c1b492013-07-12 13:56:44 +05304252 vos_mem_set(&pMac->scan.channels11d, sizeof(pMac->scan.channels11d), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004253 pMac->scan.f11dInfoReset = eANI_BOOLEAN_TRUE;
4254 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_FALSE;
4255 }
4256
4257 return;
4258}
4259
4260
4261eHalStatus csrResetCountryCodeInformation(tpAniSirGlobal pMac, tANI_BOOLEAN *pfRestartNeeded)
4262{
4263 eHalStatus status = eHAL_STATUS_SUCCESS;
4264 tANI_BOOLEAN fRestart = eANI_BOOLEAN_FALSE;
4265
4266 //Use the Country code and domain from EEPROM
Kiet Lam64c1b492013-07-12 13:56:44 +05304267 vos_mem_copy(pMac->scan.countryCodeCurrent, pMac->scan.countryCodeDefault,
4268 WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07004269 csrSetRegulatoryDomain(pMac, pMac->scan.domainIdCurrent, &fRestart);
Jeff Johnson43971f52012-07-17 12:26:56 -07004270 if( ((eANI_BOOLEAN_FALSE == fRestart) || (pfRestartNeeded == NULL) )
4271 && !csrIsInfraConnected(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -07004272 {
4273 //Only reset the country info if we don't need to restart
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004274 csrResetCountryInformation(pMac, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07004275 }
4276 if(pfRestartNeeded)
4277 {
4278 *pfRestartNeeded = fRestart;
4279 }
4280
4281 return (status);
4282}
4283
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05304284void csrClearVotesForCountryInfo(tpAniSirGlobal pMac)
4285{
4286 pMac->scan.countryCodeCount = 0;
4287 vos_mem_set(pMac->scan.votes11d,
4288 sizeof(tCsrVotes11d) * CSR_MAX_NUM_COUNTRY_CODE, 0);
4289}
4290
4291void csrAddVoteForCountryInfo(tpAniSirGlobal pMac, tANI_U8 *pCountryCode)
4292{
4293 tANI_BOOLEAN match = FALSE;
4294 tANI_U8 i;
4295
4296 /* convert to UPPER here so we are assured
4297 * the strings are always in upper case.
4298 */
4299 for( i = 0; i < 3; i++ )
4300 {
4301 pCountryCode[ i ] = (tANI_U8)csrToUpper( pCountryCode[ i ] );
4302 }
4303
4304 /* Some of the 'old' Cisco 350 series AP's advertise NA as the
4305 * country code (for North America ??). NA is not a valid country code
4306 * or domain so let's allow this by changing it to the proper
4307 * country code (which is US). We've also seen some NETGEAR AP's
4308 * that have "XX " as the country code with valid 2.4 GHz US channel
4309 * information. If we cannot find the country code advertised in the
4310 * 11d information element, let's default to US.
4311 */
4312
4313 if ( !HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry( pMac,
4314 pCountryCode, NULL,COUNTRY_QUERY ) ) )
4315 {
4316 pCountryCode[ 0 ] = '0';
4317 pCountryCode[ 1 ] = '0';
4318 }
4319
4320 /* We've seen some of the AP's improperly put a 0 for the
4321 * third character of the country code. spec says valid charcters are
4322 * 'O' (for outdoor), 'I' for Indoor, or ' ' (space; for either).
4323 * if we see a 0 in this third character, let's change it to a ' '.
4324 */
4325 if ( 0 == pCountryCode[ 2 ] )
4326 {
4327 pCountryCode[ 2 ] = ' ';
4328 }
4329
4330 for (i = 0; i < pMac->scan.countryCodeCount; i++)
4331 {
4332 match = (vos_mem_compare(pMac->scan.votes11d[i].countryCode,
4333 pCountryCode, 2));
4334 if(match)
4335 {
4336 break;
4337 }
4338 }
4339
4340 if (match)
4341 {
4342 pMac->scan.votes11d[i].votes++;
4343 }
4344 else
4345 {
4346 vos_mem_copy( pMac->scan.votes11d[pMac->scan.countryCodeCount].countryCode,
4347 pCountryCode, 3 );
4348 pMac->scan.votes11d[pMac->scan.countryCodeCount].votes = 1;
4349 pMac->scan.countryCodeCount++;
4350 }
4351
4352 return;
4353}
4354
4355tANI_BOOLEAN csrElectedCountryInfo(tpAniSirGlobal pMac)
4356{
4357 tANI_BOOLEAN fRet = FALSE;
4358 tANI_U8 maxVotes = 0;
4359 tANI_U8 i, j=0;
4360
4361 if (!pMac->scan.countryCodeCount)
4362 {
Agrawal Ashishbd3a5932016-04-12 16:22:39 +05304363 VOS_TRACE( VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_WARN,
4364 "No AP with 11d Country code is present in scan list");
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05304365 return fRet;
4366 }
4367 maxVotes = pMac->scan.votes11d[0].votes;
4368 fRet = TRUE;
4369
4370 for(i = 1; i < pMac->scan.countryCodeCount; i++)
4371 {
4372 /* If we have a tie for max votes for 2 different country codes,
4373 * pick random.we can put some more intelligence - TBD
4374 */
4375 if (maxVotes < pMac->scan.votes11d[i].votes)
4376 {
4377 VOS_TRACE( VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
4378 " Votes for Country %c%c : %d\n",
4379 pMac->scan.votes11d[i].countryCode[0],
4380 pMac->scan.votes11d[i].countryCode[1],
4381 pMac->scan.votes11d[i].votes);
4382
4383 maxVotes = pMac->scan.votes11d[i].votes;
4384 j = i;
4385 fRet = TRUE;
4386 }
4387
4388 }
4389 if (fRet)
4390 {
Rajesh Babu Prathipati20cdffa2014-07-01 22:24:59 +05304391 vos_mem_copy(pMac->scan.countryCodeElected,
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05304392 pMac->scan.votes11d[j].countryCode, WNI_CFG_COUNTRY_CODE_LEN);
Rajesh Babu Prathipati20cdffa2014-07-01 22:24:59 +05304393 vos_mem_copy(pMac->scan.countryCode11d,
Agarwal Ashish852b2c32014-05-23 17:13:25 +05304394 pMac->scan.votes11d[j].countryCode, WNI_CFG_COUNTRY_CODE_LEN);
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05304395 VOS_TRACE( VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
4396 "Selected Country is %c%c With count %d\n",
4397 pMac->scan.votes11d[j].countryCode[0],
4398 pMac->scan.votes11d[j].countryCode[1],
4399 pMac->scan.votes11d[j].votes);
4400 }
4401 return fRet;
4402}
Jeff Johnson295189b2012-06-20 16:38:30 -07004403
4404eHalStatus csrSetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pCountry, tANI_BOOLEAN *pfRestartNeeded)
4405{
4406 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
4407 v_REGDOMAIN_t domainId;
4408
4409 if(pCountry)
4410 {
Kiet Lam6c583332013-10-14 05:37:09 +05304411 status = csrGetRegulatoryDomainForCountry(pMac, pCountry, &domainId, COUNTRY_USER);
Jeff Johnson295189b2012-06-20 16:38:30 -07004412 if(HAL_STATUS_SUCCESS(status))
4413 {
4414 status = csrSetRegulatoryDomain(pMac, domainId, pfRestartNeeded);
4415 if(HAL_STATUS_SUCCESS(status))
4416 {
4417 //We don't need to check the pMac->roam.configParam.fEnforceDefaultDomain flag here,
4418 //csrSetRegulatoryDomain will fail if the country doesn't fit our domain criteria.
Kiet Lam64c1b492013-07-12 13:56:44 +05304419 vos_mem_copy(pMac->scan.countryCodeCurrent, pCountry, WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07004420 if((pfRestartNeeded == NULL) || !(*pfRestartNeeded))
4421 {
4422 //Simply set it to cfg. If we need to restart, restart will apply it to the CFG
4423 csrSetCfgCountryCode(pMac, pCountry);
4424 }
4425 }
4426 }
4427 }
4428
4429 return (status);
4430}
4431
4432
4433
4434//caller allocated memory for pNumChn and pChnPowerInfo
4435//As input, *pNumChn has the size of the array of pChnPowerInfo
4436//Upon return, *pNumChn has the number of channels assigned.
4437void csrGetChannelPowerInfo( tpAniSirGlobal pMac, tDblLinkList *pList,
4438 tANI_U32 *pNumChn, tChannelListWithPower *pChnPowerInfo)
4439{
4440 tListElem *pEntry;
4441 tANI_U32 chnIdx = 0, idx;
4442 tCsrChannelPowerInfo *pChannelSet;
4443
4444 //Get 2.4Ghz first
4445 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
4446 while( pEntry && (chnIdx < *pNumChn) )
4447 {
4448 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
4449 if ( 1 != pChannelSet->interChannelOffset )
4450 {
4451 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
4452 {
4453 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
4454 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
4455 }
4456 }
4457 else
4458 {
4459 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
4460 {
4461 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + idx);
4462 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
4463 }
4464 }
4465
4466 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
4467 }
4468 *pNumChn = chnIdx;
4469
4470 return ;
4471}
4472
4473
4474
4475void csrApplyCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce )
4476{
4477 v_REGDOMAIN_t domainId;
4478 eHalStatus status = eHAL_STATUS_SUCCESS;
4479
4480 do
4481 {
4482 if( !csrIs11dSupported( pMac ) || 0 == pMac->scan.channelOf11dInfo) break;
4483 if( pMac->scan.fAmbiguous11dInfoFound )
4484 {
4485 // ambiguous info found
4486 //Restore te default domain as well
Kiet Lam6c583332013-10-14 05:37:09 +05304487 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
4488 pMac, pMac->scan.countryCodeCurrent,
4489 &domainId, COUNTRY_QUERY)))
Jeff Johnson295189b2012-06-20 16:38:30 -07004490 {
4491 pMac->scan.domainIdCurrent = domainId;
4492 }
4493 else
4494 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004495 smsLog(pMac, LOGE, FL(" failed to get domain from currentCountryCode %02X%02X"),
Jeff Johnson295189b2012-06-20 16:38:30 -07004496 pMac->scan.countryCodeCurrent[0], pMac->scan.countryCodeCurrent[1]);
4497 }
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004498 csrResetCountryInformation( pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE );
Jeff Johnson295189b2012-06-20 16:38:30 -07004499 break;
4500 }
4501 if ( pMac->scan.f11dInfoApplied && !fForce ) break;
Kiet Lam6c583332013-10-14 05:37:09 +05304502 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
4503 pMac, pMac->scan.countryCode11d,
4504 &domainId, COUNTRY_QUERY)))
Jeff Johnson295189b2012-06-20 16:38:30 -07004505 {
4506 //Check whether we need to enforce default domain
4507 if( ( !pMac->roam.configParam.fEnforceDefaultDomain ) ||
4508 (pMac->scan.domainIdCurrent == domainId) )
4509 {
4510
4511#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4512 {
4513 vos_log_802_11d_pkt_type *p11dLog;
4514 tChannelListWithPower chnPwrInfo[WNI_CFG_VALID_CHANNEL_LIST_LEN];
4515 tANI_U32 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN, nTmp;
4516
4517 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
4518 if(p11dLog)
4519 {
4520 p11dLog->eventId = WLAN_80211D_EVENT_COUNTRY_SET;
Kiet Lam64c1b492013-07-12 13:56:44 +05304521 vos_mem_copy(p11dLog->countryCode, pMac->scan.countryCode11d, 3);
Jeff Johnson295189b2012-06-20 16:38:30 -07004522 p11dLog->numChannel = pMac->scan.channels11d.numChannels;
4523 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
4524 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304525 vos_mem_copy(p11dLog->Channels,
4526 pMac->scan.channels11d.channelList,
4527 p11dLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07004528 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList24,
4529 &nChnInfo, chnPwrInfo);
4530 nTmp = nChnInfo;
4531 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN - nTmp;
4532 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList5G,
4533 &nChnInfo, &chnPwrInfo[nTmp]);
4534 for(nTmp = 0; nTmp < p11dLog->numChannel; nTmp++)
4535 {
4536 for(nChnInfo = 0; nChnInfo < WNI_CFG_VALID_CHANNEL_LIST_LEN; nChnInfo++)
4537 {
4538 if(p11dLog->Channels[nTmp] == chnPwrInfo[nChnInfo].chanId)
4539 {
4540 p11dLog->TxPwr[nTmp] = chnPwrInfo[nChnInfo].pwr;
4541 break;
4542 }
4543 }
4544 }
4545 }
4546 if(!pMac->roam.configParam.Is11dSupportEnabled)
4547 {
4548 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
4549 }
4550 else if(pMac->roam.configParam.fEnforceDefaultDomain)
4551 {
4552 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
4553 }
4554 else
4555 {
4556 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
4557 }
4558 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
4559 }
4560 }
4561#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4562 if(pMac->scan.domainIdCurrent != domainId)
4563 {
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05304564 smsLog(pMac, LOGW, FL("Domain Changed Old %s (%d), new %s"),
4565 voss_DomainIdtoString(pMac->scan.domainIdCurrent),
4566 pMac->scan.domainIdCurrent,
4567 voss_DomainIdtoString(domainId));
Abhishek Singha306a442013-11-07 18:39:01 +05304568 status = WDA_SetRegDomain(pMac, domainId, eSIR_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07004569 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004570 if (status != eHAL_STATUS_SUCCESS)
4571 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004572 smsLog( pMac, LOGE, FL(" fail to set regId %d"), domainId );
Jeff Johnson295189b2012-06-20 16:38:30 -07004573 }
4574 pMac->scan.domainIdCurrent = domainId;
Kiet Lam6c583332013-10-14 05:37:09 +05304575#ifndef CONFIG_ENABLE_LINUX_REG
Kiet Lambb14e952013-11-19 14:58:29 +05304576 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.base20MHzChannels,
4577 pMac->scan.countryCodeCurrent, eANI_BOOLEAN_TRUE );
Kiet Lam6c583332013-10-14 05:37:09 +05304578#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004579 // switch to active scans using this new channel list
4580 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
4581 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_TRUE;
4582 pMac->scan.f11dInfoReset = eANI_BOOLEAN_FALSE;
4583 }
4584 }
4585
4586 } while( 0 );
4587
4588 return;
4589}
4590
4591
4592
4593tANI_BOOLEAN csrSave11dCountryString( tpAniSirGlobal pMac, tANI_U8 *pCountryCode,
4594 tANI_BOOLEAN fForce)
4595{
4596 tANI_BOOLEAN fCountryStringChanged = FALSE, fUnknownCountryCode = FALSE;
4597 tANI_U32 i;
Kiet Lam6c583332013-10-14 05:37:09 +05304598 v_REGDOMAIN_t regd;
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004599 tANI_BOOLEAN fCountryNotPresentInDriver = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004600
4601 // convert to UPPER here so we are assured the strings are always in upper case.
4602 for( i = 0; i < 3; i++ )
4603 {
4604 pCountryCode[ i ] = (tANI_U8)csrToUpper( pCountryCode[ i ] );
4605 }
4606
4607 // Some of the 'old' Cisco 350 series AP's advertise NA as the country code (for North America ??).
4608 // NA is not a valid country code or domain so let's allow this by changing it to the proper
4609 // country code (which is US). We've also seen some NETGEAR AP's that have "XX " as the country code
4610 // with valid 2.4 GHz US channel information. If we cannot find the country code advertised in the
4611 // 11d information element, let's default to US.
Kiet Lam6c583332013-10-14 05:37:09 +05304612 if ( !HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(pMac,
4613 pCountryCode,
4614 &regd,
4615 COUNTRY_QUERY) ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07004616 {
4617 // Check the enforcement first
4618 if( pMac->roam.configParam.fEnforceDefaultDomain || pMac->roam.configParam.fEnforceCountryCodeMatch )
4619 {
4620 fUnknownCountryCode = TRUE;
4621 }
4622 else
4623 {
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004624 fCountryNotPresentInDriver = TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004625 }
4626 }
Tushnim Bhattacharyyac3c1e8e2013-10-29 17:27:43 -07004627 //right now, even if we don't find the CC in driver we set to world. Making
4628 //sure countryCode11d doesn't get updated with the invalid CC, instead
4629 //reflect the world CC
4630 else if (REGDOMAIN_WORLD == regd)
4631 {
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004632 fCountryNotPresentInDriver = TRUE;
Tushnim Bhattacharyyac3c1e8e2013-10-29 17:27:43 -07004633 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004634
4635 // We've seen some of the AP's improperly put a 0 for the third character of the country code.
4636 // spec says valid charcters are 'O' (for outdoor), 'I' for Indoor, or ' ' (space; for either).
4637 // if we see a 0 in this third character, let's change it to a ' '.
4638 if ( 0 == pCountryCode[ 2 ] )
4639 {
4640 pCountryCode[ 2 ] = ' ';
4641 }
4642
4643 if( !fUnknownCountryCode )
4644 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304645 fCountryStringChanged = (!vos_mem_compare(pMac->scan.countryCode11d, pCountryCode, 2));
Jeff Johnson295189b2012-06-20 16:38:30 -07004646
4647
4648 if(( 0 == pMac->scan.countryCode11d[ 0 ] && 0 == pMac->scan.countryCode11d[ 1 ] )
4649 || (fForce))
4650 {
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004651 if (!fCountryNotPresentInDriver)
4652 {
4653 // this is the first .11d information
4654 vos_mem_copy(pMac->scan.countryCode11d, pCountryCode,
Kiet Lam64c1b492013-07-12 13:56:44 +05304655 sizeof( pMac->scan.countryCode11d ));
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004656
4657 }
4658 else
4659 {
4660 pMac->scan.countryCode11d[0] = '0';
4661 pMac->scan.countryCode11d[1] = '0';
4662 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004663 }
4664 }
4665
4666 return( fCountryStringChanged );
4667}
4668
4669
4670void csrSaveChannelPowerForBand( tpAniSirGlobal pMac, tANI_BOOLEAN fPopulate5GBand )
4671{
4672 tANI_U32 Index, count=0;
4673 tSirMacChanInfo *pChanInfo;
4674 tSirMacChanInfo *pChanInfoStart;
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08004675 tANI_S32 maxChannelIndex;
4676
4677 maxChannelIndex = ( pMac->scan.base20MHzChannels.numChannels < WNI_CFG_VALID_CHANNEL_LIST_LEN ) ?
4678 pMac->scan.base20MHzChannels.numChannels : WNI_CFG_VALID_CHANNEL_LIST_LEN ;
Jeff Johnson295189b2012-06-20 16:38:30 -07004679
Kiet Lam64c1b492013-07-12 13:56:44 +05304680 pChanInfo = vos_mem_malloc(sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN);
4681 if ( NULL != pChanInfo )
Jeff Johnson295189b2012-06-20 16:38:30 -07004682 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304683 vos_mem_set(pChanInfo, sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004684 pChanInfoStart = pChanInfo;
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08004685 for (Index=0; Index < maxChannelIndex; Index++)
Jeff Johnson295189b2012-06-20 16:38:30 -07004686 {
4687 if ((fPopulate5GBand && (CSR_IS_CHANNEL_5GHZ(pMac->scan.defaultPowerTable[Index].chanId))) ||
4688 (!fPopulate5GBand && (CSR_IS_CHANNEL_24GHZ(pMac->scan.defaultPowerTable[Index].chanId))) )
4689 {
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08004690 if(count >= WNI_CFG_VALID_CHANNEL_LIST_LEN)
4691 {
4692 smsLog( pMac, LOGW, FL(" csrSaveChannelPowerForBand, count exceeded, count = %d"), count);
4693 break;
4694 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004695 pChanInfo->firstChanNum = pMac->scan.defaultPowerTable[Index].chanId;
4696 pChanInfo->numChannels = 1;
4697 pChanInfo->maxTxPower = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
4698 pChanInfo++;
4699 count++;
4700 }
4701 }
4702 if(count)
4703 {
4704 csrSaveToChannelPower2G_5G( pMac, count * sizeof(tSirMacChanInfo), pChanInfoStart );
4705 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304706 vos_mem_free(pChanInfoStart);
Jeff Johnson295189b2012-06-20 16:38:30 -07004707 }
4708}
4709
4710
4711void csrSetOppositeBandChannelInfo( tpAniSirGlobal pMac )
4712{
4713 tANI_BOOLEAN fPopulate5GBand = FALSE;
4714
4715 do
4716 {
4717 // if this is not a dual band product, then we don't need to set the opposite
4718 // band info. We only work in one band so no need to look in the other band.
4719 if ( !CSR_IS_OPEARTING_DUAL_BAND( pMac ) ) break;
4720 // if we found channel info on the 5.0 band and...
4721 if ( CSR_IS_CHANNEL_5GHZ( pMac->scan.channelOf11dInfo ) )
4722 {
4723 // and the 2.4 band is empty, then populate the 2.4 channel info
Kiet Lam8d985a02013-10-11 03:39:41 +05304724 if ( !csrLLIsListEmpty( &pMac->scan.channelPowerInfoList24, LL_ACCESS_LOCK ) ) break;
Jeff Johnson295189b2012-06-20 16:38:30 -07004725 fPopulate5GBand = FALSE;
4726 }
4727 else
4728 {
4729 // else, we found channel info in the 2.4 GHz band. If the 5.0 band is empty
4730 // set the 5.0 band info from the 2.4 country code.
Kiet Lam8d985a02013-10-11 03:39:41 +05304731 if ( !csrLLIsListEmpty( &pMac->scan.channelPowerInfoList5G, LL_ACCESS_LOCK ) ) break;
Jeff Johnson295189b2012-06-20 16:38:30 -07004732 fPopulate5GBand = TRUE;
4733 }
4734 csrSaveChannelPowerForBand( pMac, fPopulate5GBand );
4735
4736 } while( 0 );
4737}
4738
4739
4740tANI_BOOLEAN csrIsSupportedChannel(tpAniSirGlobal pMac, tANI_U8 channelId)
4741{
4742 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
4743 tANI_U32 i;
4744
4745 //Make sure it is a channel that is in our supported list.
4746 for ( i = 0; i < pMac->scan.baseChannels.numChannels; i++ )
4747 {
4748 if ( channelId == pMac->scan.baseChannels.channelList[i] )
4749 {
4750 fRet = eANI_BOOLEAN_TRUE;
4751 break;
4752 }
4753 }
4754
4755 //If it is configured to limit a set of the channels
4756 if( fRet && pMac->roam.configParam.fEnforce11dChannels )
4757 {
4758 fRet = eANI_BOOLEAN_FALSE;
4759 for ( i = 0; i < pMac->scan.base20MHzChannels.numChannels; i++ )
4760 {
4761 if ( channelId == pMac->scan.base20MHzChannels.channelList[i] )
4762 {
4763 fRet = eANI_BOOLEAN_TRUE;
4764 break;
4765 }
4766 }
4767 }
4768
4769 return (fRet);
4770}
4771
4772
4773
4774//bSize specify the buffer size of pChannelList
4775tANI_U8 csrGetChannelListFromChannelSet( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 bSize, tCsrChannelPowerInfo *pChannelSet )
4776{
4777 tANI_U8 i, j = 0, chnId;
4778
4779 bSize = CSR_MIN(bSize, pChannelSet->numChannels);
4780 for( i = 0; i < bSize; i++ )
4781 {
4782 chnId = (tANI_U8)(pChannelSet->firstChannel + ( i * pChannelSet->interChannelOffset ));
4783 if ( csrIsSupportedChannel( pMac, chnId ) )
4784 {
4785 pChannelList[j++] = chnId;
4786 }
4787 }
4788
4789 return (j);
4790}
4791
4792
4793
4794//bSize -- specify the buffer size of pChannelList
4795void csrConstructCurrentValidChannelList( tpAniSirGlobal pMac, tDblLinkList *pChannelSetList,
4796 tANI_U8 *pChannelList, tANI_U8 bSize, tANI_U8 *pNumChannels )
4797{
4798 tListElem *pEntry;
4799 tCsrChannelPowerInfo *pChannelSet;
4800 tANI_U8 numChannels;
4801 tANI_U8 *pChannels;
4802
4803 if( pChannelSetList && pChannelList && pNumChannels )
4804 {
4805 pChannels = pChannelList;
4806 *pNumChannels = 0;
4807 pEntry = csrLLPeekHead( pChannelSetList, LL_ACCESS_LOCK );
4808 while( pEntry )
4809 {
4810 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
4811 numChannels = csrGetChannelListFromChannelSet( pMac, pChannels, bSize, pChannelSet );
4812 pChannels += numChannels;
4813 *pNumChannels += numChannels;
4814 pEntry = csrLLNext( pChannelSetList, pEntry, LL_ACCESS_LOCK );
4815 }
4816 }
4817}
4818
4819
4820/*
4821 * 802.11D only: Gather 11d IE via beacon or Probe response and store them in pAdapter->channels11d
4822*/
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304823tANI_BOOLEAN csrLearnCountryInformation( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc,
4824 tDot11fBeaconIEs *pIes, tANI_BOOLEAN fForce)
Jeff Johnson295189b2012-06-20 16:38:30 -07004825{
Agarwal Ashish60a37ee2014-05-28 17:20:20 +05304826 eHalStatus status;
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304827 tANI_U8 *pCountryCodeSelected;
Jeff Johnson295189b2012-06-20 16:38:30 -07004828 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
4829 v_REGDOMAIN_t domainId;
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304830 tDot11fBeaconIEs *pIesLocal = pIes;
4831 tANI_BOOLEAN useVoting = eANI_BOOLEAN_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004832
Jeff Johnson295189b2012-06-20 16:38:30 -07004833 if (VOS_STA_SAP_MODE == vos_get_conparam ())
4834 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07004835
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304836 if ((NULL == pSirBssDesc) && (NULL == pIes))
4837 useVoting = eANI_BOOLEAN_TRUE;
4838
Jeff Johnson295189b2012-06-20 16:38:30 -07004839 do
4840 {
4841 // check if .11d support is enabled
4842 if( !csrIs11dSupported( pMac ) ) break;
Agarwal Ashish60a37ee2014-05-28 17:20:20 +05304843
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304844 if (eANI_BOOLEAN_FALSE == useVoting)
4845 {
4846 if( !pIesLocal &&
4847 (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
4848 pSirBssDesc, &pIesLocal))))
4849 {
4850 break;
4851 }
4852 // check if country information element is present
4853 if(!pIesLocal->Country.present)
4854 {
4855 //No country info
4856 break;
4857 }
4858
4859 if( HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry
4860 (pMac, pIesLocal->Country.country, &domainId,
4861 COUNTRY_QUERY)) &&
4862 ( domainId == REGDOMAIN_WORLD))
4863 {
4864 break;
4865 }
4866 } //useVoting == eANI_BOOLEAN_FALSE
4867
4868 if (eANI_BOOLEAN_FALSE == useVoting)
4869 pCountryCodeSelected = pIesLocal->Country.country;
4870 else
4871 pCountryCodeSelected = pMac->scan.countryCodeElected;
4872
Kiet Lam8d985a02013-10-11 03:39:41 +05304873 status = csrGetRegulatoryDomainForCountry(pMac,
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304874 pCountryCodeSelected, &domainId, COUNTRY_IE);
Kiet Lam8d985a02013-10-11 03:39:41 +05304875 if ( status != eHAL_STATUS_SUCCESS )
4876 {
4877 smsLog( pMac, LOGE, FL(" fail to get regId %d"), domainId );
4878 fRet = eANI_BOOLEAN_FALSE;
4879 break;
4880 }
Agarwal Ashish7693f2d2014-07-18 18:03:58 +05304881
4882 /* updating 11d Country Code with Country code selected. */
4883
4884 vos_mem_copy(pMac->scan.countryCode11d,
4885 pCountryCodeSelected,
4886 WNI_CFG_COUNTRY_CODE_LEN);
4887
Agarwal Ashish60a37ee2014-05-28 17:20:20 +05304888#ifndef CONFIG_ENABLE_LINUX_REG
Venkata Prathyusha Kuntupalli316247e2013-03-15 17:45:25 -07004889 // Checking for Domain Id change
4890 if ( domainId != pMac->scan.domainIdCurrent )
4891 {
Kiet Lam8d985a02013-10-11 03:39:41 +05304892 vos_mem_copy(pMac->scan.countryCode11d,
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304893 pCountryCodeSelected,
Kiet Lam8d985a02013-10-11 03:39:41 +05304894 sizeof( pMac->scan.countryCode11d ) );
4895 /* Set Current Country code and Current Regulatory domain */
4896 status = csrSetRegulatoryDomain(pMac, domainId, NULL);
4897 if (eHAL_STATUS_SUCCESS != status)
4898 {
4899 smsLog(pMac, LOGE, "Set Reg Domain Fail %d", status);
4900 fRet = eANI_BOOLEAN_FALSE;
4901 return fRet;
4902 }
4903 //csrSetRegulatoryDomain will fail if the country doesn't fit our domain criteria.
4904 vos_mem_copy(pMac->scan.countryCodeCurrent,
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304905 pCountryCodeSelected, WNI_CFG_COUNTRY_CODE_LEN);
Kiet Lam8d985a02013-10-11 03:39:41 +05304906 //Simply set it to cfg.
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304907 csrSetCfgCountryCode(pMac, pCountryCodeSelected);
Kiet Lam8d985a02013-10-11 03:39:41 +05304908
4909 /* overwrite the defualt country code */
4910 vos_mem_copy(pMac->scan.countryCodeDefault,
4911 pMac->scan.countryCodeCurrent,
4912 WNI_CFG_COUNTRY_CODE_LEN);
4913 /* Set Current RegDomain */
Abhishek Singha306a442013-11-07 18:39:01 +05304914 status = WDA_SetRegDomain(pMac, domainId, eSIR_TRUE);
Kiet Lam8d985a02013-10-11 03:39:41 +05304915 if ( status != eHAL_STATUS_SUCCESS )
4916 {
4917 smsLog( pMac, LOGE, FL(" fail to Set regId %d"), domainId );
4918 fRet = eANI_BOOLEAN_FALSE;
4919 return fRet;
4920 }
4921 /* set to default domain ID */
Madan Mohan Koyyalamudi0e5922d2013-09-10 15:45:24 +05304922 pMac->scan.domainIdCurrent = domainId;
Kiet Lam8d985a02013-10-11 03:39:41 +05304923 /* get the channels based on new cc */
4924 status = csrInitGetChannels( pMac );
Jeff Johnson295189b2012-06-20 16:38:30 -07004925
Kiet Lam8d985a02013-10-11 03:39:41 +05304926 if ( status != eHAL_STATUS_SUCCESS )
4927 {
4928 smsLog( pMac, LOGE, FL(" fail to get Channels "));
4929 fRet = eANI_BOOLEAN_FALSE;
4930 return fRet;
4931 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004932
Kiet Lam8d985a02013-10-11 03:39:41 +05304933 /* reset info based on new cc, and we are done */
4934 csrResetCountryInformation(pMac, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
Agarwal Ashishfaef6692014-01-29 19:40:30 +05304935 /* Regulatory Domain Changed, Purge Only scan result
4936 * which does not have channel number belong to 11d
4937 * channel list
4938 */
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05304939 csrScanFilterResults(pMac);
Kiet Lam8d985a02013-10-11 03:39:41 +05304940 }
Kiet Lam6c583332013-10-14 05:37:09 +05304941#endif
4942 fRet = eANI_BOOLEAN_TRUE;
4943
Jeff Johnson295189b2012-06-20 16:38:30 -07004944 } while( 0 );
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304945
4946 if( !pIes && pIesLocal )
4947 {
4948 //locally allocated
4949 vos_mem_free(pIesLocal);
4950 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004951
4952 return( fRet );
4953}
4954
4955
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004956static void csrSaveScanResults( tpAniSirGlobal pMac, tANI_U8 reason )
Jeff Johnson295189b2012-06-20 16:38:30 -07004957{
4958 // initialize this to FALSE. profMoveInterimScanResultsToMainList() routine
4959 // will set this to the channel where an .11d beacon is seen
4960 pMac->scan.channelOf11dInfo = 0;
4961 // if we get any ambiguous .11d information then this will be set to TRUE
4962 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
4963 //Tush
4964 // if we get any ambiguous .11d information, then this will be set to TRUE
4965 // only if the applied 11d info could be found in one of the scan results
4966 pMac->scan.fCurrent11dInfoMatch = eANI_BOOLEAN_FALSE;
4967 // move the scan results from interim list to the main scan list
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004968 csrMoveTempScanResultsToMainList( pMac, reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07004969}
4970
4971
4972void csrReinitScanCmd(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4973{
4974 switch (pCommand->u.scanCmd.reason)
4975 {
4976 case eCsrScanSetBGScanParam:
4977 case eCsrScanAbortBgScan:
4978 if(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList)
4979 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304980 vos_mem_free(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList);
Jeff Johnson295189b2012-06-20 16:38:30 -07004981 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
4982 }
4983 break;
4984 case eCsrScanBGScanAbort:
4985 case eCsrScanBGScanEnable:
4986 case eCsrScanGetScanChnInfo:
4987 break;
4988 case eCsrScanAbortNormalScan:
4989 default:
4990 csrScanFreeRequest(pMac, &pCommand->u.scanCmd.u.scanRequest);
4991 break;
4992 }
4993 if(pCommand->u.scanCmd.pToRoamProfile)
4994 {
4995 csrReleaseProfile(pMac, pCommand->u.scanCmd.pToRoamProfile);
Kiet Lam64c1b492013-07-12 13:56:44 +05304996 vos_mem_free(pCommand->u.scanCmd.pToRoamProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07004997 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304998 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004999}
5000
5001
5002tANI_BOOLEAN csrGetRemainingChannelsFor11dScan( tpAniSirGlobal pMac, tANI_U8 *pChannels, tANI_U8 *pcChannels )
5003{
5004 tANI_U32 index11dChannels, index;
5005 tANI_U32 indexCurrentChannels;
5006 tANI_BOOLEAN fChannelAlreadyScanned;
5007 tANI_U32 len = sizeof(pMac->roam.validChannelList);
5008
5009 *pcChannels = 0;
5010 if ( CSR_IS_11D_INFO_FOUND(pMac) && csrRoamIsChannelValid(pMac, pMac->scan.channelOf11dInfo) )
5011 {
5012 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
5013 {
5014 //Find the channel index where we found the 11d info
5015 for(index = 0; index < len; index++)
5016 {
5017 if(pMac->scan.channelOf11dInfo == pMac->roam.validChannelList[index])
5018 break;
5019 }
5020 //check whether we found the channel index
5021 if(index < len)
5022 {
5023 // Now, look through the 11d channel list and create a list of all channels in the 11d list that are
5024 // NOT in the current channel list. This gives us a list of the new channels that have not been
5025 // scanned. We'll scan this new list so we have a complete set of scan results on all of the domain channels
5026 // initially.
5027 for ( index11dChannels = 0; index11dChannels < pMac->scan.channels11d.numChannels; index11dChannels++ )
5028 {
5029 fChannelAlreadyScanned = eANI_BOOLEAN_FALSE;
5030
5031 for( indexCurrentChannels = 0; indexCurrentChannels < index; indexCurrentChannels++ )
5032 {
5033 if ( pMac->roam.validChannelList[ indexCurrentChannels ] == pMac->scan.channels11d.channelList[ index11dChannels ] )
5034 {
5035 fChannelAlreadyScanned = eANI_BOOLEAN_TRUE;
5036 break;
5037 }
5038 }
5039
5040 if ( !fChannelAlreadyScanned )
5041 {
5042 pChannels[ *pcChannels ] = pMac->scan.channels11d.channelList[ index11dChannels ];
5043 ( *pcChannels )++;
5044 }
5045 }
5046 }
5047 }//GetCFG
5048 }
5049 return( *pcChannels );
5050}
5051
5052
5053eCsrScanCompleteNextCommand csrScanGetNextCommandState( tpAniSirGlobal pMac, tSmeCmd *pCommand, tANI_BOOLEAN fSuccess )
5054{
5055 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
5056
5057 switch( pCommand->u.scanCmd.reason )
5058 {
5059 case eCsrScan11d1:
5060 NextCommand = (fSuccess) ? eCsrNext11dScan1Success : eCsrNext11dScan1Failure;
5061 break;
5062 case eCsrScan11d2:
5063 NextCommand = (fSuccess) ? eCsrNext11dScan2Success : eCsrNext11dScan2Failure;
5064 break;
5065 case eCsrScan11dDone:
5066 NextCommand = eCsrNext11dScanComplete;
5067 break;
5068 case eCsrScanLostLink1:
5069 NextCommand = (fSuccess) ? eCsrNextLostLinkScan1Success : eCsrNextLostLinkScan1Failed;
5070 break;
5071 case eCsrScanLostLink2:
5072 NextCommand = (fSuccess) ? eCsrNextLostLinkScan2Success : eCsrNextLostLinkScan2Failed;
5073 break;
5074 case eCsrScanLostLink3:
5075 NextCommand = (fSuccess) ? eCsrNextLostLinkScan3Success : eCsrNextLostLinkScan3Failed;
5076 break;
5077 case eCsrScanForSsid:
5078 NextCommand = (fSuccess) ? eCsrNexteScanForSsidSuccess : eCsrNexteScanForSsidFailure;
5079 break;
5080 case eCsrScanForCapsChange:
5081 NextCommand = eCsrNextCapChangeScanComplete; //don't care success or not
5082 break;
5083 case eCsrScanIdleScan:
5084 NextCommand = eCsrNextIdleScanComplete;
5085 break;
5086 default:
5087 NextCommand = eCsrNextScanNothing;
5088 break;
5089 }
5090 return( NextCommand );
5091}
5092
5093
5094//Return whether the pCommand is finished.
5095tANI_BOOLEAN csrHandleScan11d1Failure(tpAniSirGlobal pMac, tSmeCmd *pCommand)
5096{
5097 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
5098
5099 //Apply back the default setting and passively scan one more time.
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08005100 csrResetCountryInformation(pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07005101 pCommand->u.scanCmd.reason = eCsrScan11d2;
5102 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
5103 {
5104 fRet = eANI_BOOLEAN_FALSE;
5105 }
5106
5107 return (fRet);
5108}
5109
5110
5111tANI_BOOLEAN csrHandleScan11dSuccess(tpAniSirGlobal pMac, tSmeCmd *pCommand)
5112{
5113 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
5114 tANI_U8 *pChannels;
5115 tANI_U8 cChannels;
5116
Kiet Lam64c1b492013-07-12 13:56:44 +05305117 pChannels = vos_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
5118 if ( NULL != pChannels )
Jeff Johnson295189b2012-06-20 16:38:30 -07005119 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305120 vos_mem_set(pChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005121 if ( csrGetRemainingChannelsFor11dScan( pMac, pChannels, &cChannels ) )
5122 {
5123 pCommand->u.scanCmd.reason = eCsrScan11dDone;
5124 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
5125 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305126 vos_mem_free(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -07005127 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07005128 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305129 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(cChannels);
5130 if ( NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07005131 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305132 vos_mem_copy(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
5133 pChannels, cChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07005134 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = cChannels;
5135 pCommand->u.scanCmd.u.scanRequest.requestType = eCSR_SCAN_REQUEST_FULL_SCAN;
5136 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
5137 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
5138 {
5139 //Reuse the same command buffer
5140 fRet = eANI_BOOLEAN_FALSE;
5141 }
5142 }
5143 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305144 vos_mem_free(pChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07005145 }
5146
5147 return (fRet);
5148}
5149
5150//Return whether the command should be removed
5151tANI_BOOLEAN csrScanComplete( tpAniSirGlobal pMac, tSirSmeScanRsp *pScanRsp )
5152{
5153 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
5154 tListElem *pEntry;
5155 tSmeCmd *pCommand;
5156 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
5157 tANI_BOOLEAN fSuccess;
5158
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305159 if (pMac->fScanOffload)
5160 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
5161 else
5162 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07005163
5164 if ( pEntry )
5165 {
5166 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
5167
5168 // If the head of the queue is Active and it is a SCAN command, remove
5169 // and put this on the Free queue.
5170 if ( eSmeCommandScan == pCommand->command )
5171 {
5172 tANI_U32 sessionId = pCommand->sessionId;
5173
5174 if(eSIR_SME_SUCCESS != pScanRsp->statusCode)
5175 {
5176 fSuccess = eANI_BOOLEAN_FALSE;
5177 }
5178 else
5179 {
5180 //pMac->scan.tempScanResults is not empty meaning the scan found something
5181 //This check only valid here because csrSaveScanresults is not yet called
5182 fSuccess = (!csrLLIsListEmpty(&pMac->scan.tempScanResults, LL_ACCESS_LOCK));
5183 }
Ratheesh S Pece1f832015-07-25 15:50:25 +05305184 if (pCommand->u.scanCmd.abortScanIndication &
5185 eCSR_SCAN_ABORT_DUE_TO_BAND_CHANGE)
Srinivas, Dasari187ca4e2014-02-07 12:40:09 +05305186 {
5187 /*
5188 * Scan aborted due to band change
5189 * The scan results need to be flushed
5190 */
5191 if (pCommand->u.scanCmd.callback
5192 != pMac->scan.callback11dScanDone)
5193 {
5194 smsLog(pMac, LOG1, FL("Filtering the scan results as the "
5195 "results may belong to wrong band"));
5196 csrScanFilterResults(pMac);
5197 }
5198 else
5199 {
5200 smsLog(pMac, LOG1, FL("11d_scan_done will flush the scan"
5201 " results"));
5202 }
Srinivas, Dasari187ca4e2014-02-07 12:40:09 +05305203 }
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005204 csrSaveScanResults(pMac, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07005205
Agrawal Ashishdf752672015-12-09 17:51:53 +05305206 /* filter scan result based on valid channel list number */
5207 if (pMac->scan.fcc_constraint)
5208 {
5209 smsLog(pMac, LOG1, FL("Clear BSS from invalid channels"));
5210 csrScanFilterResults(pMac);
5211 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005212#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5213 {
5214 vos_log_scan_pkt_type *pScanLog = NULL;
5215 tScanResultHandle hScanResult;
5216 tCsrScanResultInfo *pScanResult;
5217 tDot11fBeaconIEs *pIes;
5218 int n = 0, c = 0;
5219
5220 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
5221 if(pScanLog)
5222 {
5223 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
5224 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
5225 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
5226 {
5227 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_RSP;
5228 }
5229 else
5230 {
5231 if( eSIR_PASSIVE_SCAN != pMac->scan.curScanType )
5232 {
5233 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_RSP;
5234 }
5235 else
5236 {
5237 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_RSP;
5238 }
5239 }
5240 if(eSIR_SME_SUCCESS == pScanRsp->statusCode)
5241 {
5242 if(HAL_STATUS_SUCCESS(csrScanGetResult(pMac, NULL, &hScanResult)))
5243 {
5244 while(((pScanResult = csrScanResultGetNext(pMac, hScanResult)) != NULL))
5245 {
5246 if( n < VOS_LOG_MAX_NUM_BSSID )
5247 {
5248 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pScanResult->BssDescriptor, &pIes)))
5249 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005250 smsLog(pMac, LOGE, FL(" fail to parse IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07005251 break;
5252 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305253 vos_mem_copy(pScanLog->bssid[n],
5254 pScanResult->BssDescriptor.bssId, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07005255 if(pIes && pIes->SSID.present && VOS_LOG_MAX_SSID_SIZE >= pIes->SSID.num_ssid)
5256 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305257 vos_mem_copy(pScanLog->ssid[n],
5258 pIes->SSID.ssid, pIes->SSID.num_ssid);
Jeff Johnson295189b2012-06-20 16:38:30 -07005259 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305260 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07005261 n++;
5262 }
5263 c++;
5264 }
5265 pScanLog->numSsid = (v_U8_t)n;
5266 pScanLog->totalSsid = (v_U8_t)c;
5267 csrScanResultPurge(pMac, hScanResult);
5268 }
5269 }
5270 else
5271 {
5272 pScanLog->status = WLAN_SCAN_STATUS_FAILURE;
5273 }
5274 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
5275 }
5276 }
5277#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5278
5279 NextCommand = csrScanGetNextCommandState(pMac, pCommand, fSuccess);
5280 //We reuse the command here instead reissue a new command
5281 switch(NextCommand)
5282 {
5283 case eCsrNext11dScan1Success:
5284 case eCsrNext11dScan2Success:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005285 smsLog( pMac, LOG2, FL("11dScan1/3 produced results. Reissue Active scan..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07005286 // if we found country information, no need to continue scanning further, bail out
5287 fRemoveCommand = eANI_BOOLEAN_TRUE;
5288 NextCommand = eCsrNext11dScanComplete;
5289 break;
5290 case eCsrNext11dScan1Failure:
5291 //We are not done yet. 11d scan fail once. We will try to reset anything and do it over again
5292 //The only meaningful thing for this retry is that we cannot find 11d information after a reset so
5293 //we clear the "old" 11d info and give it once more chance
5294 fRemoveCommand = csrHandleScan11d1Failure(pMac, pCommand);
5295 if(fRemoveCommand)
5296 {
5297 NextCommand = eCsrNext11dScanComplete;
5298 }
5299 break;
5300 case eCsrNextLostLinkScan1Success:
5301 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink1)))
5302 {
5303 csrScanHandleFailedLostlink1(pMac, sessionId);
5304 }
5305 break;
5306 case eCsrNextLostLinkScan2Success:
5307 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink2)))
5308 {
5309 csrScanHandleFailedLostlink2(pMac, sessionId);
5310 }
5311 break;
5312 case eCsrNextLostLinkScan3Success:
5313 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink3)))
5314 {
5315 csrScanHandleFailedLostlink3(pMac, sessionId);
5316 }
5317 break;
5318 case eCsrNextLostLinkScan1Failed:
5319 csrScanHandleFailedLostlink1(pMac, sessionId);
5320 break;
5321 case eCsrNextLostLinkScan2Failed:
5322 csrScanHandleFailedLostlink2(pMac, sessionId);
5323 break;
5324 case eCsrNextLostLinkScan3Failed:
5325 csrScanHandleFailedLostlink3(pMac, sessionId);
5326 break;
5327 case eCsrNexteScanForSsidSuccess:
5328 csrScanHandleSearchForSSID(pMac, pCommand);
5329 break;
5330 case eCsrNexteScanForSsidFailure:
5331 csrScanHandleSearchForSSIDFailure(pMac, pCommand);
5332 break;
5333 case eCsrNextIdleScanComplete:
5334 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
5335 break;
5336 case eCsrNextCapChangeScanComplete:
5337 csrScanHandleCapChangeScanComplete(pMac, sessionId);
5338 break;
5339 default:
5340
5341 break;
5342 }
5343 }
5344 else
5345 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005346 smsLog( pMac, LOGW, FL("Scan Completion called but SCAN command is not ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07005347 fRemoveCommand = eANI_BOOLEAN_FALSE;
5348 }
5349 }
5350 else
5351 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005352 smsLog( pMac, LOGW, FL("Scan Completion called but NO commands are ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07005353 fRemoveCommand = eANI_BOOLEAN_FALSE;
5354 }
5355
5356 return( fRemoveCommand );
5357}
5358
5359
Jeff Johnson295189b2012-06-20 16:38:30 -07005360static void csrScanRemoveDupBssDescriptionFromInterimList( tpAniSirGlobal pMac,
5361 tSirBssDescription *pSirBssDescr,
5362 tDot11fBeaconIEs *pIes)
5363{
5364 tListElem *pEntry;
5365 tCsrScanResult *pCsrBssDescription;
Abhishek Singh56c29812018-06-12 14:07:52 +05305366 tDot11fBeaconIEs *temp_ie = pIes;
5367
5368 if (!temp_ie)
5369 csrGetParsedBssDescriptionIEs(pMac, pSirBssDescr, &temp_ie);
Jeff Johnson295189b2012-06-20 16:38:30 -07005370
5371 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
5372 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
5373 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
5374 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
5375 while( pEntry )
5376 {
5377 pCsrBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
5378
5379 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
5380 // matches
5381
Abhishek Singh56c29812018-06-12 14:07:52 +05305382 if (csrIsDuplicateBssDescription(pMac,
5383 &pCsrBssDescription->Result.BssDescriptor,
5384 pSirBssDescr, temp_ie, FALSE))
Jeff Johnson295189b2012-06-20 16:38:30 -07005385 {
Abhishek Singh56c29812018-06-12 14:07:52 +05305386 /*
5387 * Due to Rx sensitivity issue, sometime beacons are seen on
5388 * adjacent channel so workaround in software is needed. If DS
5389 * params or HT info are present driver can get proper channel
5390 * info from these IEs and the older RSSI values are used in new
5391 * entry.
5392 *
5393 * For the cases where DS params and HT info is not present,
5394 * driver needs to check below conditions to update proper
5395 * channel so that the older RSSI and channel values are used in
5396 * new entry:
5397 * -- The old entry channel and new entry channel are not same
5398 * -- RSSI is below 15db or more from old value, this indicate
5399 * that the signal has leaked in adjacent channel
5400 */
5401 if (!pSirBssDescr->fProbeRsp &&
5402 (temp_ie && !temp_ie->DSParams.present &&
5403 !temp_ie->HTInfo.present) &&
5404 (pSirBssDescr->channelId !=
5405 pCsrBssDescription->Result.BssDescriptor.channelId) &&
5406 ((pCsrBssDescription->Result.BssDescriptor.rssi -
5407 pSirBssDescr->rssi) >
5408 SIR_ADJACENT_CHANNEL_RSSI_DIFF_THRESHOLD)) {
5409 pSirBssDescr->channelId =
5410 pCsrBssDescription->Result.BssDescriptor.channelId;
5411 pSirBssDescr->rssi =
5412 pCsrBssDescription->Result.BssDescriptor.rssi;
5413 }
5414
Jeff Johnson295189b2012-06-20 16:38:30 -07005415 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
5416 ((tANI_S32)pCsrBssDescription->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
5417
5418 // Remove the 'old' entry from the list....
5419 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK ) )
5420 {
5421 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pCsrBssDescription->Result.BssDescriptor);
5422 // we need to free the memory associated with this node
5423 csrFreeScanResultEntry( pMac, pCsrBssDescription );
5424 }
5425
5426 // If we found a match, we can stop looking through the list.
5427 break;
5428 }
5429
5430 pEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK );
5431 }
Abhishek Singh56c29812018-06-12 14:07:52 +05305432
5433 if (!pIes && temp_ie)
5434 vos_mem_free(temp_ie);
Jeff Johnson295189b2012-06-20 16:38:30 -07005435}
5436
5437
5438
5439//Caller allocated memory pfNewBssForConn to return whether new candidate for
5440//current connection is found. Cannot be NULL
5441tCsrScanResult *csrScanSaveBssDescriptionToInterimList( tpAniSirGlobal pMac,
5442 tSirBssDescription *pBSSDescription,
5443 tDot11fBeaconIEs *pIes)
5444{
5445 tCsrScanResult *pCsrBssDescription = NULL;
5446 tANI_U32 cbBSSDesc;
5447 tANI_U32 cbAllocated;
Jeff Johnson295189b2012-06-20 16:38:30 -07005448
5449 // figure out how big the BSS description is (the BSSDesc->length does NOT
5450 // include the size of the length field itself).
5451 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
5452
5453 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
5454
Kiet Lam64c1b492013-07-12 13:56:44 +05305455 pCsrBssDescription = vos_mem_malloc(cbAllocated);
5456 if ( NULL != pCsrBssDescription )
Jeff Johnson295189b2012-06-20 16:38:30 -07005457 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305458 vos_mem_set(pCsrBssDescription, cbAllocated, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005459 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Kiet Lam64c1b492013-07-12 13:56:44 +05305460 vos_mem_copy(&pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc );
Jeff Johnson295189b2012-06-20 16:38:30 -07005461 //Save SSID separately for later use
5462 if( pIes->SSID.present && !csrIsNULLSSID(pIes->SSID.ssid, pIes->SSID.num_ssid) )
5463 {
5464 //SSID not hidden
Madan Mohan Koyyalamudi4e31b132012-11-02 13:13:52 -07005465 tANI_U32 len = pIes->SSID.num_ssid;
Jeff Johnson295189b2012-06-20 16:38:30 -07005466 if (len > SIR_MAC_MAX_SSID_LENGTH)
5467 {
5468 // truncate to fit in our struct
5469 len = SIR_MAC_MAX_SSID_LENGTH;
5470 }
5471 pCsrBssDescription->Result.ssId.length = len;
5472 pCsrBssDescription->Result.timer = vos_timer_get_system_time();
Kiet Lam64c1b492013-07-12 13:56:44 +05305473 vos_mem_copy(pCsrBssDescription->Result.ssId.ssId, pIes->SSID.ssid, len);
Jeff Johnson295189b2012-06-20 16:38:30 -07005474 }
5475 csrLLInsertTail( &pMac->scan.tempScanResults, &pCsrBssDescription->Link, LL_ACCESS_LOCK );
5476 }
5477
5478 return( pCsrBssDescription );
5479}
5480
5481
5482
5483
5484tANI_BOOLEAN csrIsDuplicateBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc1,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07005485 tSirBssDescription *pSirBssDesc2, tDot11fBeaconIEs *pIes2, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07005486{
5487 tANI_BOOLEAN fMatch = FALSE;
5488 tSirMacCapabilityInfo *pCap1, *pCap2;
5489 tDot11fBeaconIEs *pIes1 = NULL;
Jeff Johnsone7245742012-09-05 17:12:55 -07005490 tDot11fBeaconIEs *pIesTemp = pIes2;
Jeff Johnson295189b2012-06-20 16:38:30 -07005491
5492 pCap1 = (tSirMacCapabilityInfo *)&pSirBssDesc1->capabilityInfo;
5493 pCap2 = (tSirMacCapabilityInfo *)&pSirBssDesc2->capabilityInfo;
5494 if(pCap1->ess == pCap2->ess)
5495 {
5496 if (pCap1->ess &&
Jeff Johnsone7245742012-09-05 17:12:55 -07005497 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId)&&
Abhishek Singhe3fa11f2014-05-13 11:11:10 +05305498 (fForced || (vos_chan_to_band(pSirBssDesc1->channelId) == vos_chan_to_band((pSirBssDesc2->channelId)))))
Jeff Johnson295189b2012-06-20 16:38:30 -07005499 {
5500 fMatch = TRUE;
Jeff Johnsone7245742012-09-05 17:12:55 -07005501 // Check for SSID match, if exists
5502 do
5503 {
5504 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
5505 {
5506 break;
5507 }
5508 if( NULL == pIesTemp )
5509 {
5510 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
5511 {
5512 break;
5513 }
5514 }
5515 if(pIes1->SSID.present && pIesTemp->SSID.present)
5516 {
5517 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
5518 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
5519 }
5520 }while(0);
5521
Jeff Johnson295189b2012-06-20 16:38:30 -07005522 }
5523 else if (pCap1->ibss && (pSirBssDesc1->channelId == pSirBssDesc2->channelId))
5524 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005525
5526 do
5527 {
5528 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
5529 {
5530 break;
5531 }
5532 if( NULL == pIesTemp )
5533 {
5534 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
5535 {
5536 break;
5537 }
5538 }
5539 //Same channel cannot have same SSID for different IBSS
5540 if(pIes1->SSID.present && pIesTemp->SSID.present)
5541 {
5542 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
5543 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
5544 }
5545 }while(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005546 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005547 /* In case of P2P devices, ess and ibss will be set to zero */
5548 else if (!pCap1->ess &&
5549 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId))
5550 {
5551 fMatch = TRUE;
5552 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005553 }
5554
5555 if(pIes1)
5556 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305557 vos_mem_free(pIes1);
Jeff Johnson295189b2012-06-20 16:38:30 -07005558 }
Jeff Johnsone7245742012-09-05 17:12:55 -07005559
5560 if( (NULL == pIes2) && pIesTemp )
5561 {
5562 //locally allocated
Kiet Lam64c1b492013-07-12 13:56:44 +05305563 vos_mem_free(pIesTemp);
Jeff Johnsone7245742012-09-05 17:12:55 -07005564 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005565
5566 return( fMatch );
5567}
5568
5569
5570tANI_BOOLEAN csrIsNetworkTypeEqual( tSirBssDescription *pSirBssDesc1, tSirBssDescription *pSirBssDesc2 )
5571{
5572 return( pSirBssDesc1->nwType == pSirBssDesc2->nwType );
5573}
5574
5575
5576//to check whether the BSS matches the dot11Mode
5577static tANI_BOOLEAN csrScanIsBssAllowed(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
5578 tDot11fBeaconIEs *pIes)
5579{
5580 tANI_BOOLEAN fAllowed = eANI_BOOLEAN_FALSE;
5581 eCsrPhyMode phyMode;
5582
5583 if(HAL_STATUS_SUCCESS(csrGetPhyModeFromBss(pMac, pBssDesc, &phyMode, pIes)))
5584 {
5585 switch(pMac->roam.configParam.phyMode)
5586 {
5587 case eCSR_DOT11_MODE_11b:
5588 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
5589 break;
5590 case eCSR_DOT11_MODE_11g:
5591 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
5592 break;
5593 case eCSR_DOT11_MODE_11g_ONLY:
5594 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11g == phyMode);
5595 break;
5596 case eCSR_DOT11_MODE_11a:
5597 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11b != phyMode) && (eCSR_DOT11_MODE_11g != phyMode));
5598 break;
5599 case eCSR_DOT11_MODE_11n_ONLY:
5600 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11n == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
5601 break;
Jeff Johnsone7245742012-09-05 17:12:55 -07005602
5603#ifdef WLAN_FEATURE_11AC
5604 case eCSR_DOT11_MODE_11ac_ONLY:
5605 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11ac == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
5606 break;
5607#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005608 case eCSR_DOT11_MODE_11b_ONLY:
5609 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11b == phyMode);
5610 break;
5611 case eCSR_DOT11_MODE_11a_ONLY:
5612 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a == phyMode);
5613 break;
5614 case eCSR_DOT11_MODE_11n:
Jeff Johnsone7245742012-09-05 17:12:55 -07005615#ifdef WLAN_FEATURE_11AC
5616 case eCSR_DOT11_MODE_11ac:
5617#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005618 case eCSR_DOT11_MODE_TAURUS:
5619 default:
5620 fAllowed = eANI_BOOLEAN_TRUE;
5621 break;
5622 }
5623 }
5624
5625 return (fAllowed);
5626}
5627
5628
5629
5630//Return pIes to caller for future use when returning TRUE.
5631static tANI_BOOLEAN csrScanValidateScanResult( tpAniSirGlobal pMac, tANI_U8 *pChannels,
5632 tANI_U8 numChn, tSirBssDescription *pBssDesc,
5633 tDot11fBeaconIEs **ppIes )
5634{
5635 tANI_BOOLEAN fValidChannel = FALSE;
5636 tDot11fBeaconIEs *pIes = NULL;
5637 tANI_U8 index;
5638
5639 for( index = 0; index < numChn; index++ )
5640 {
5641 // This check relies on the fact that a single BSS description is returned in each
5642 // ScanRsp call, which is the way LIM implemented the scan req/rsp funtions. We changed
5643 // to this model when we ran with a large number of APs. If this were to change, then
5644 // this check would have to mess with removing the bssDescription from somewhere in an
5645 // arbitrary index in the bssDescription array.
5646 if ( pChannels[ index ] == pBssDesc->channelId )
5647 {
5648 fValidChannel = TRUE;
5649 break;
5650 }
5651 }
5652 *ppIes = NULL;
5653 if(fValidChannel)
5654 {
5655 if( HAL_STATUS_SUCCESS( csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIes) ) )
5656 {
5657 fValidChannel = csrScanIsBssAllowed(pMac, pBssDesc, pIes);
5658 if( fValidChannel )
5659 {
5660 *ppIes = pIes;
5661 }
5662 else
5663 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305664 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07005665 }
5666 }
5667 else
5668 {
5669 fValidChannel = FALSE;
5670 }
5671 }
5672
5673 return( fValidChannel );
5674}
5675
5676
5677//Return whether last scan result is received
5678static tANI_BOOLEAN csrScanProcessScanResults( tpAniSirGlobal pMac, tSmeCmd *pCommand,
5679 tSirSmeScanRsp *pScanRsp, tANI_BOOLEAN *pfRemoveCommand )
5680{
5681 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE, fRemoveCommand = eANI_BOOLEAN_FALSE;
5682 tDot11fBeaconIEs *pIes = NULL;
5683 tANI_U32 cbParsed;
5684 tSirBssDescription *pSirBssDescription;
5685 tANI_U32 cbBssDesc;
Agrawal Ashish4cc15bb2016-02-04 17:56:16 +05305686 eHalStatus status;
Jeff Johnson295189b2012-06-20 16:38:30 -07005687 tANI_U32 cbScanResult = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription )
5688 + sizeof(tSirBssDescription); //We need at least one CB
5689
5690 // don't consider the scan rsp to be valid if the status code is Scan Failure. Scan Failure
5691 // is returned when the scan could not find anything. so if we get scan failure return that
5692 // the scan response is invalid. Also check the lenght in the scan result for valid scan
5693 // BssDescriptions....
5694 do
5695 {
5696 if ( ( cbScanResult <= pScanRsp->length ) &&
5697 (( eSIR_SME_SUCCESS == pScanRsp->statusCode ) ||
5698 ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW == pScanRsp->statusCode ) ) )
5699 {
5700 tANI_U8 *pChannelList = NULL;
5701 tANI_U8 cChannels = 0;
5702
5703 //Different scan type can reach this point, we need to distinguish it
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005704#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5705 if( eCsrScanGetLfrResult == pCommand->u.scanCmd.reason )
5706 {
5707 pChannelList = NULL;
5708 cChannels = 0;
5709 }
5710 else
5711#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005712 if( eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason )
5713 {
5714 //eCsrScanSetBGScanParam uses different structure
5715 tCsrBGScanRequest *pBgScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
5716
5717 cChannels = pBgScanReq->ChannelInfo.numOfChannels;
5718 pChannelList = pBgScanReq->ChannelInfo.ChannelList;
5719 }
5720 else
5721 {
5722 //the rest use generic scan request
5723 cChannels = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
5724 pChannelList = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
5725 }
5726
5727 // if the scan result is not on one of the channels in the Valid channel list, then it
5728 // must have come from an AP on an overlapping channel (in the 2.4GHz band). In this case,
5729 // let's drop the scan result.
5730 //
5731 // The other situation is where the scan request is for a scan on a particular channel set
5732 // and the scan result is from a
5733
5734 // if the NumChannels is 0, then we are supposed to be scanning all channels. Use the full channel
5735 // list as the 'valid' channel list. Otherwise, use the specific channel list in the scan parms
5736 // as the valid channels.
5737 if ( 0 == cChannels )
5738 {
5739 tANI_U32 len = sizeof(pMac->roam.validChannelList);
5740
5741 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
5742 {
5743 pChannelList = pMac->roam.validChannelList;
5744 cChannels = (tANI_U8)len;
5745 }
5746 else
5747 {
5748 //Cannot continue
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005749 smsLog( pMac, LOGE, "CSR: Processing internal SCAN results...csrGetCfgValidChannels failed" );
Jeff Johnson295189b2012-06-20 16:38:30 -07005750 break;
5751 }
5752 }
5753
5754 smsLog( pMac, LOG2, "CSR: Processing internal SCAN results..." );
5755 cbParsed = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription );
5756 pSirBssDescription = pScanRsp->bssDescription;
5757 while( cbParsed < pScanRsp->length )
5758 {
5759 if ( csrScanValidateScanResult( pMac, pChannelList, cChannels, pSirBssDescription, &pIes ) )
5760 {
5761 csrScanRemoveDupBssDescriptionFromInterimList(pMac, pSirBssDescription, pIes);
5762 csrScanSaveBssDescriptionToInterimList( pMac, pSirBssDescription, pIes );
5763 if( eSIR_PASSIVE_SCAN == pMac->scan.curScanType )
5764 {
5765 if( csrIs11dSupported( pMac) )
5766 {
5767 //Check whether the BSS is acceptable base on 11d info and our configs.
5768 if( csrMatchCountryCode( pMac, NULL, pIes ) )
5769 {
5770 //Double check whether the channel is acceptable by us.
5771 if( csrIsSupportedChannel( pMac, pSirBssDescription->channelId ) )
5772 {
5773 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
5774 }
5775 }
5776 }
5777 else
5778 {
5779 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
5780 }
5781 }
5782 //Free the resource
Kiet Lam64c1b492013-07-12 13:56:44 +05305783 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07005784 }
5785 // skip over the BSS description to the next one...
5786 cbBssDesc = pSirBssDescription->length + sizeof( pSirBssDescription->length );
5787
5788 cbParsed += cbBssDesc;
5789 pSirBssDescription = (tSirBssDescription *)((tANI_U8 *)pSirBssDescription + cbBssDesc );
5790
5791 } //while
5792 }
5793 else
5794 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005795 smsLog( pMac, LOGW, " Scanrsp fail (0x%08X), length = %d (expected %d)",
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08005796 pScanRsp->statusCode, pScanRsp->length, cbScanResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07005797 //HO bg scan/probe failed no need to try autonomously
5798 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
5799 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005800#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5801 eCsrScanGetLfrResult == pCommand->u.scanCmd.reason ||
5802#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005803 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
5804 {
5805 fRemoveCommand = eANI_BOOLEAN_TRUE;
5806 }
5807 }
5808 }while(0);
5809 if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
5810 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005811 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 -07005812 fRemoveCommand = csrScanComplete( pMac, pScanRsp );
5813 fRet = eANI_BOOLEAN_TRUE;
5814 }//if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
5815 if(pfRemoveCommand)
5816 {
5817 *pfRemoveCommand = fRemoveCommand;
5818 }
5819
Agrawal Ashish4cc15bb2016-02-04 17:56:16 +05305820 /*
5821 * Currently SET_FCC_CHANNEL issues updated channel list to fw.
5822 * At the time of driver load, if scan is issued followed with
5823 * SET_FCC_CHANNEL, driver will send update channel list to fw.
5824 * Fw will stop ongoing scan because of that GUI will have very less
5825 * scan list.
5826 * Update channel list should be sent to fw once scan is done
5827 */
5828 if (pMac->scan.defer_update_channel_list) {
5829 status = csrUpdateChannelList(pMac);
5830 if (eHAL_STATUS_SUCCESS != status)
5831 smsLog(pMac, LOGE,
5832 FL( "failed to update the supported channel list"));
5833 pMac->scan.defer_update_channel_list = false;
5834 }
5835
Jeff Johnson295189b2012-06-20 16:38:30 -07005836#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305837 if (pMac->fScanOffload)
5838 return fRet;
5839
Jeff Johnson295189b2012-06-20 16:38:30 -07005840 if (!csrLLIsListEmpty( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK ))
5841 {
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005842 /* Pending scan commands in the list because the previous scan command
5843 * was split into a scan command on one channel + a scan command for all
5844 * remaining channels.
5845 *
5846 * Start timer to trigger processing of the next scan command.
Srikant Kuppa866893f2012-12-27 17:28:14 -08005847 * NOTE for LFR:
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305848 * Do not split scans if no concurrent infra connections are
Srikant Kuppa866893f2012-12-27 17:28:14 -08005849 * active and if the scan is a BG scan triggered by LFR (OR)
5850 * any scan if LFR is in the middle of a BG scan. Splitting
5851 * the scan is delaying the time it takes for LFR to find
5852 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005853 */
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305854 if ( (csrIsStaSessionConnected(pMac) &&
Srikant Kuppa866893f2012-12-27 17:28:14 -08005855#ifdef FEATURE_WLAN_LFR
5856 (csrIsConcurrentInfraConnected(pMac) ||
5857 ((pCommand->u.scanCmd.reason != eCsrScanBgScan) &&
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305858 (pMac->roam.neighborRoamInfo.neighborRoamState !=
Srikant Kuppa866893f2012-12-27 17:28:14 -08005859 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
5860#endif
5861 (pCommand->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305862 (csrIsP2pSessionConnected(pMac)) )
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005863 {
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005864 /* if active connected sessions present then continue to split scan
5865 * with specified interval between consecutive scans */
5866 csrSetDefaultScanTiming(pMac, pCommand->u.scanCmd.u.scanRequest.scanType, &(pCommand->u.scanCmd.u.scanRequest));
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05305867 vos_timer_start(&pMac->scan.hTimerStaApConcTimer,
5868 pCommand->u.scanCmd.u.scanRequest.restTime);
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005869 } else {
5870 /* if no connected sessions present then initiate next scan command immediately */
5871 /* minimum timer granularity is 10ms */
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05305872 vos_timer_start(&pMac->scan.hTimerStaApConcTimer, 10);
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005873 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005874 }
5875#endif
5876 return (fRet);
5877}
5878
5879
5880tANI_BOOLEAN csrScanIsWildCardScan( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5881{
5882 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
Kiet Lam64c1b492013-07-12 13:56:44 +05305883 tANI_BOOLEAN f = vos_mem_compare(pCommand->u.scanCmd.u.scanRequest.bssid,
5884 bssid, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07005885
5886 //It is not a wild card scan if the bssid is not broadcast and the number of SSID is 1.
5887 return ((tANI_BOOLEAN)( (f || (0xff == pCommand->u.scanCmd.u.scanRequest.bssid[0])) &&
5888 (pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs != 1) ));
5889}
5890
5891
5892eHalStatus csrScanSmeScanResponse( tpAniSirGlobal pMac, void *pMsgBuf )
5893{
5894 eHalStatus status = eHAL_STATUS_SUCCESS;
5895 tListElem *pEntry;
5896 tSmeCmd *pCommand;
5897 eCsrScanStatus scanStatus;
Sunkad, Anand Ningappa3ec8bf72016-02-05 15:13:30 +05305898 tSirSmeScanRsp *pScanRsp;
Jeff Johnson295189b2012-06-20 16:38:30 -07005899 tSmeGetScanChnRsp *pScanChnInfo;
5900 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
5901 eCsrScanReason reason = eCsrScanOther;
5902
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305903 if (pMac->fScanOffload)
5904 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList,
5905 LL_ACCESS_LOCK);
5906 else
5907 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07005908
5909 if ( pEntry )
5910 {
5911 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
5912 if ( eSmeCommandScan == pCommand->command )
5913 {
Deepthi Gowrife5340b2016-04-11 12:15:46 +05305914 /* Purge the scan results based on Aging */
5915 if (pEntry && pMac->scan.scanResultCfgAgingTime)
5916 csrPurgeScanResultByAge(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07005917 reason = pCommand->u.scanCmd.reason;
5918 switch(pCommand->u.scanCmd.reason)
5919 {
5920 case eCsrScanAbortBgScan:
5921 case eCsrScanAbortNormalScan:
5922 case eCsrScanBGScanAbort:
5923 case eCsrScanBGScanEnable:
Sunkad, Anand Ningappa3ec8bf72016-02-05 15:13:30 +05305924 pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
5925 scanStatus = (eSIR_SME_SUCCESS == pScanRsp->statusCode) ?
5926 eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005927 break;
5928 case eCsrScanGetScanChnInfo:
Deepthi Gowrife5340b2016-04-11 12:15:46 +05305929 pScanChnInfo = (tSmeGetScanChnRsp *)pMsgBuf;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005930 /*
5931 * status code not available in tSmeGetScanChnRsp, so
5932 * by default considereing it to be success
5933 */
5934 scanStatus = eSIR_SME_SUCCESS;
Deepthi Gowrife5340b2016-04-11 12:15:46 +05305935 csrScanAgeResults(pMac, pScanChnInfo);
Jeff Johnson295189b2012-06-20 16:38:30 -07005936 break;
5937 case eCsrScanForCapsChange:
Sunkad, Anand Ningappa3ec8bf72016-02-05 15:13:30 +05305938 pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
5939 scanStatus = (eSIR_SME_SUCCESS == pScanRsp->statusCode) ?
5940 eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005941 csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand );
5942 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005943 case eCsrScanP2PFindPeer:
Sunkad, Anand Ningappa3ec8bf72016-02-05 15:13:30 +05305944 pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
5945 scanStatus = ((eSIR_SME_SUCCESS == pScanRsp->statusCode) &&
5946 (pScanRsp->length > 50)) ? eCSR_SCAN_FOUND_PEER : eCSR_SCAN_FAILURE;
5947 csrScanProcessScanResults( pMac, pCommand, pScanRsp, NULL );
5948 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005949 case eCsrScanSetBGScanParam:
5950 default:
Sunkad, Anand Ningappa3ec8bf72016-02-05 15:13:30 +05305951 pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
5952 scanStatus = (eSIR_SME_SUCCESS == pScanRsp->statusCode) ?
5953 eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005954 if(csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand ))
5955 {
5956 //Not to get channel info if the scan is not a wildcard scan because
5957 //it may cause scan results got aged out incorrectly.
Ratheesh S Pece1f832015-07-25 15:50:25 +05305958 if(csrScanIsWildCardScan( pMac, pCommand ) &&
5959 (!pCommand->u.scanCmd.u.scanRequest.p2pSearch)
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005960#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5961 && (pCommand->u.scanCmd.reason != eCsrScanGetLfrResult)
5962#endif
5963 )
Jeff Johnson295189b2012-06-20 16:38:30 -07005964 {
Ratheesh S Pece1f832015-07-25 15:50:25 +05305965 csrScanGetScanChnInfo(pMac, pCommand);
Jeff Johnson295189b2012-06-20 16:38:30 -07005966 }
5967 }
5968 break;
5969 }//switch
5970 if(fRemoveCommand)
5971 {
5972
5973 csrReleaseScanCommand(pMac, pCommand, scanStatus);
5974
Sunkad, Anand Ningappa3ec8bf72016-02-05 15:13:30 +05305975 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005976 smeProcessPendingQueue( pMac );
5977 }
5978 else
5979 {
5980 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
5981 status = eHAL_STATUS_FAILURE;
5982 }
5983 }
5984 else
5985 {
5986 smsLog( pMac, LOGW, "CSR: Scan Completion called but NO commands are ACTIVE ..." );
5987 status = eHAL_STATUS_FAILURE;
5988 }
5989
5990 return (status);
5991}
5992
5993
5994
5995
5996tCsrScanResultInfo *csrScanResultGetFirst(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
5997{
5998 tListElem *pEntry;
5999 tCsrScanResult *pResult;
6000 tCsrScanResultInfo *pRet = NULL;
6001 tScanResultList *pResultList = (tScanResultList *)hScanResult;
6002
6003 if(pResultList)
6004 {
6005 csrLLLock(&pResultList->List);
6006 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
6007 if(pEntry)
6008 {
6009 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
6010 pRet = &pResult->Result;
6011 }
6012 pResultList->pCurEntry = pEntry;
6013 csrLLUnlock(&pResultList->List);
6014 }
6015
6016 return pRet;
6017}
6018
6019
6020tCsrScanResultInfo *csrScanResultGetNext(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
6021{
6022 tListElem *pEntry = NULL;
6023 tCsrScanResult *pResult = NULL;
6024 tCsrScanResultInfo *pRet = NULL;
6025 tScanResultList *pResultList = (tScanResultList *)hScanResult;
6026
6027 if(pResultList)
6028 {
6029 csrLLLock(&pResultList->List);
6030 if(NULL == pResultList->pCurEntry)
6031 {
6032 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
6033 }
6034 else
6035 {
6036 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
6037 }
6038 if(pEntry)
6039 {
6040 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
6041 pRet = &pResult->Result;
6042 }
6043 pResultList->pCurEntry = pEntry;
6044 csrLLUnlock(&pResultList->List);
6045 }
6046
6047 return pRet;
6048}
6049
6050
6051//This function moves the first BSS that matches the bssid to the head of the result
6052eHalStatus csrMoveBssToHeadFromBSSID(tpAniSirGlobal pMac, tCsrBssid *bssid, tScanResultHandle hScanResult)
6053{
6054 eHalStatus status = eHAL_STATUS_FAILURE;
6055 tScanResultList *pResultList = (tScanResultList *)hScanResult;
6056 tCsrScanResult *pResult = NULL;
6057 tListElem *pEntry = NULL;
6058
6059 if(pResultList && bssid)
6060 {
6061 csrLLLock(&pResultList->List);
6062 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
6063 while(pEntry)
6064 {
6065 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
Kiet Lam64c1b492013-07-12 13:56:44 +05306066 if (vos_mem_compare(bssid, pResult->Result.BssDescriptor.bssId, sizeof(tCsrBssid)))
Jeff Johnson295189b2012-06-20 16:38:30 -07006067 {
6068 status = eHAL_STATUS_SUCCESS;
6069 csrLLRemoveEntry(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
6070 csrLLInsertHead(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
6071 break;
6072 }
6073 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
6074 }
6075 csrLLUnlock(&pResultList->List);
6076 }
6077
6078 return (status);
6079}
6080
6081
6082//Remove the BSS if possible.
6083//Return -- TRUE == the BSS is remove. False == Fail to remove it
6084//This function is called when list lock is held. Be caution what functions it can call.
6085tANI_BOOLEAN csrScanAgeOutBss(tpAniSirGlobal pMac, tCsrScanResult *pResult)
6086{
6087 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
6088 tANI_U32 i;
6089 tCsrRoamSession *pSession;
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05306090 tANI_BOOLEAN isConnBssfound = eANI_BOOLEAN_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006091
6092 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
6093 {
6094 if( CSR_IS_SESSION_VALID( pMac, i ) )
6095 {
6096 pSession = CSR_GET_SESSION( pMac, i );
6097 //Not to remove the BSS we are connected to.
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05306098 if(csrIsConnStateConnectedInfra(pMac, i) && (NULL != pSession->pConnectBssDesc) &&
6099 (csrIsDuplicateBssDescription(pMac, &pResult->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07006100 pSession->pConnectBssDesc, NULL, FALSE))
Jeff Johnson295189b2012-06-20 16:38:30 -07006101 )
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05306102 {
6103 isConnBssfound = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006104 break;
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05306105 }
6106 }
6107 }
6108
6109 if( isConnBssfound )
Jeff Johnson295189b2012-06-20 16:38:30 -07006110 {
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05306111 //Reset the counter so that aging out of connected BSS won't hapeen too soon
Jeff Johnson295189b2012-06-20 16:38:30 -07006112 pResult->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Deepthi Gowri4480a3f2016-05-18 19:30:17 +05306113 pResult->Result.BssDescriptor.nReceivedTime =
6114 vos_timer_get_system_time();
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05306115
6116 return (fRet);
6117 }
6118 else
6119 {
6120 smsLog(pMac, LOGW, "Aging out BSS "MAC_ADDRESS_STR" Channel %d",
6121 MAC_ADDR_ARRAY(pResult->Result.BssDescriptor.bssId),
6122 pResult->Result.BssDescriptor.channelId);
6123 //No need to hold the spin lock because caller should hold the lock for pMac->scan.scanResultList
6124 if( csrLLRemoveEntry(&pMac->scan.scanResultList, &pResult->Link, LL_ACCESS_NOLOCK) )
6125 {
6126 if (csrIsMacAddressEqual(pMac,
6127 (tCsrBssid *) pResult->Result.BssDescriptor.bssId,
6128 (tCsrBssid *) pMac->scan.currentCountryBssid))
6129 {
6130 smsLog(pMac, LOGW, "Aging out 11d BSS "MAC_ADDRESS_STR,
6131 MAC_ADDR_ARRAY(pResult->Result.BssDescriptor.bssId));
6132 pMac->scan.currentCountryRSSI = -128;
6133 }
6134 csrFreeScanResultEntry(pMac, pResult);
6135 fRet = eANI_BOOLEAN_TRUE;
6136 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006137 }
6138
6139 return (fRet);
6140}
6141
6142
6143eHalStatus csrScanAgeResults(tpAniSirGlobal pMac, tSmeGetScanChnRsp *pScanChnInfo)
6144{
6145 eHalStatus status = eHAL_STATUS_SUCCESS;
6146 tListElem *pEntry, *tmpEntry;
6147 tCsrScanResult *pResult;
6148 tLimScanChn *pChnInfo;
6149 tANI_U8 i;
6150
6151 csrLLLock(&pMac->scan.scanResultList);
6152 for(i = 0; i < pScanChnInfo->numChn; i++)
6153 {
6154 pChnInfo = &pScanChnInfo->scanChn[i];
6155 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
6156 while( pEntry )
6157 {
6158 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
6159 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
6160 if(pResult->Result.BssDescriptor.channelId == pChnInfo->channelId)
6161 {
Jeff Johnson295189b2012-06-20 16:38:30 -07006162 if(pResult->AgingCount <= 0)
6163 {
6164 smsLog(pMac, LOGW, " age out due to ref count");
6165 csrScanAgeOutBss(pMac, pResult);
6166 }
Madan Mohan Koyyalamudib9d3dcc2012-09-28 16:47:50 -07006167 else
6168 {
6169 pResult->AgingCount--;
6170 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006171 }
6172 pEntry = tmpEntry;
6173 }
6174 }
6175 csrLLUnlock(&pMac->scan.scanResultList);
6176
6177 return (status);
6178}
6179
Abhishek Singhc640dbb2015-06-08 10:54:17 +05306180eHalStatus csrIbssAgeBss(tpAniSirGlobal pMac)
6181{
6182 eHalStatus status = eHAL_STATUS_SUCCESS;
6183 tListElem *pEntry, *tmpEntry;
6184 tCsrScanResult *pResult;
6185
6186 csrLLLock(&pMac->scan.scanResultList);
6187 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
6188 while( pEntry )
6189 {
6190 tmpEntry = csrLLNext(&pMac->scan.scanResultList,
6191 pEntry, LL_ACCESS_NOLOCK);
6192 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
6193
6194 smsLog(pMac, LOGW, FL(" age out due Forced IBSS leave"));
6195 csrScanAgeOutBss(pMac, pResult);
6196 pEntry = tmpEntry;
6197 }
6198 csrLLUnlock(&pMac->scan.scanResultList);
6199
6200 return (status);
6201}
Jeff Johnson295189b2012-06-20 16:38:30 -07006202
Abhishek Singh72c2f4e2016-07-22 11:25:43 +05306203/**
6204 * csr_remove_bssid_from_scan_list() - remove the bssid from
6205 * scan list
6206 * @pMac: mac context.
6207 * @bssid: bssid to be removed
6208 *
6209 * This function remove the given bssid from scan list.
6210 *
6211 * Return: void.
6212 */
6213void csr_remove_bssid_from_scan_list(tpAniSirGlobal pMac,
6214 tSirMacAddr bssid)
6215{
6216 tListElem *entry,*free_elem;
6217 tCsrScanResult *bss_desc;
6218 tDblLinkList *list = &pMac->scan.scanResultList;
6219
6220 csrLLLock(list);
6221 entry = csrLLPeekHead(list, LL_ACCESS_NOLOCK);
6222 while (entry != NULL) {
6223 bss_desc = GET_BASE_ADDR( entry, tCsrScanResult, Link);
6224 if (vos_mem_compare(bss_desc->Result.BssDescriptor.bssId,
6225 bssid, sizeof(tSirMacAddr))) {
6226 free_elem = entry;
6227 entry = csrLLNext(list, entry, LL_ACCESS_NOLOCK);
6228 csrLLRemoveEntry(list, free_elem, LL_ACCESS_NOLOCK);
6229 csrFreeScanResultEntry(pMac, bss_desc);
6230 smsLog(pMac, LOGW, FL("Removed BSS entry:%pM"),
6231 bssid);
6232 continue;
6233 }
6234 entry = csrLLNext(list, entry, LL_ACCESS_NOLOCK);
6235 }
6236 csrLLUnlock(list);
6237}
6238
Jeff Johnson295189b2012-06-20 16:38:30 -07006239eHalStatus csrSendMBScanReq( tpAniSirGlobal pMac, tANI_U16 sessionId,
6240 tCsrScanRequest *pScanReq, tScanReqParam *pScanReqParam )
6241{
6242 eHalStatus status = eHAL_STATUS_SUCCESS;
6243 tSirSmeScanReq *pMsg;
6244 tANI_U16 msgLen;
6245 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
6246 tSirScanType scanType = pScanReq->scanType;
6247 tANI_U32 minChnTime; //in units of milliseconds
6248 tANI_U32 maxChnTime; //in units of milliseconds
6249 tANI_U32 i;
6250 tANI_U8 selfMacAddr[WNI_CFG_BSSID_LEN];
6251 tANI_U8 *pSelfMac = NULL;
6252
6253 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
6254 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) +
6255 ( pScanReq->uIEFieldLen ) ;
6256
Kiet Lam64c1b492013-07-12 13:56:44 +05306257 pMsg = vos_mem_malloc(msgLen);
6258 if ( NULL == pMsg )
6259 status = eHAL_STATUS_FAILURE;
6260 else
6261 status = eHAL_STATUS_SUCCESS;
6262 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07006263 {
6264 do
6265 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306266 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006267 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
6268 pMsg->length = pal_cpu_to_be16(msgLen);
6269 //ToDO: Fill in session info when we need to do scan base on session.
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05306270 if ((pMac->fScanOffload) && (sessionId != CSR_SESSION_ID_INVALID))
6271 {
6272 pMsg->sessionId = sessionId;
6273 }
6274 else
6275 {
6276 /* if sessionId == CSR_SESSION_ID_INVALID, then send the scan
6277 request on first available session */
6278 pMsg->sessionId = 0;
6279 }
6280
Jeff Johnson295189b2012-06-20 16:38:30 -07006281 pMsg->transactionId = 0;
6282 pMsg->dot11mode = (tANI_U8) csrTranslateToWNICfgDot11Mode(pMac, csrFindBestPhyMode( pMac, pMac->roam.configParam.phyMode ));
6283 pMsg->bssType = pal_cpu_to_be32(csrTranslateBsstypeToMacType(pScanReq->BSSType));
6284
6285 if ( CSR_IS_SESSION_VALID( pMac, sessionId ) )
6286 {
6287 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[sessionId].selfMacAddr;
6288 }
6289 else
6290 {
6291 // Since we don't have session for the scanning, we find a valid session. In case we fail to
6292 // do so, get the WNI_CFG_STA_ID
6293 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
6294 {
6295 if( CSR_IS_SESSION_VALID( pMac, i ) )
6296 {
6297 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[i].selfMacAddr;
6298 break;
6299 }
6300 }
6301 if( CSR_ROAM_SESSION_MAX == i )
6302 {
6303 tANI_U32 len = WNI_CFG_BSSID_LEN;
6304 pSelfMac = selfMacAddr;
6305 status = ccmCfgGetStr( pMac, WNI_CFG_STA_ID, pSelfMac, &len );
6306 if( !HAL_STATUS_SUCCESS( status ) ||
6307 ( len < WNI_CFG_BSSID_LEN ) )
6308 {
6309 smsLog( pMac, LOGE, FL(" Can not get self MAC address from CFG status = %d"), status );
6310 //Force failed status
6311 status = eHAL_STATUS_FAILURE;
6312 break;
6313 }
6314 }
6315 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306316 vos_mem_copy((tANI_U8 *)pMsg->selfMacAddr, pSelfMac, sizeof(tSirMacAddr));
Jeff Johnson295189b2012-06-20 16:38:30 -07006317
6318 //sirCopyMacAddr
Kiet Lam64c1b492013-07-12 13:56:44 +05306319 vos_mem_copy((tANI_U8 *)pMsg->bssId, (tANI_U8 *)&pScanReq->bssid, sizeof(tSirMacAddr));
6320 if ( vos_mem_compare(pScanReq->bssid, bssid, sizeof(tCsrBssid)))
Jeff Johnson295189b2012-06-20 16:38:30 -07006321 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306322 vos_mem_set(pMsg->bssId, sizeof(tSirMacAddr), 0xff);
Jeff Johnson295189b2012-06-20 16:38:30 -07006323 }
6324 else
6325 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306326 vos_mem_copy(pMsg->bssId, pScanReq->bssid, WNI_CFG_BSSID_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07006327 }
6328 minChnTime = pScanReq->minChnTime;
6329 maxChnTime = pScanReq->maxChnTime;
6330
6331 //Verify the scan type first, if the scan is active scan, we need to make sure we
6332 //are allowed to do so.
6333 /* if 11d is enabled & we don't see any beacon around, scan type falls
6334 back to passive. But in BT AMP STA mode we need to send out a
6335 directed probe*/
6336 if( (eSIR_PASSIVE_SCAN != scanType) && (eCSR_SCAN_P2P_DISCOVERY != pScanReq->requestType)
6337 && (eCSR_BSS_TYPE_WDS_STA != pScanReq->BSSType)
6338 && (eANI_BOOLEAN_FALSE == pMac->scan.fEnableBypass11d))
6339 {
6340 scanType = pMac->scan.curScanType;
6341 if(eSIR_PASSIVE_SCAN == pMac->scan.curScanType)
6342 {
6343 if(minChnTime < pMac->roam.configParam.nPassiveMinChnTime)
6344 {
6345 minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
6346 }
6347 if(maxChnTime < pMac->roam.configParam.nPassiveMaxChnTime)
6348 {
6349 maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
6350 }
6351 }
6352 }
6353 pMsg->scanType = pal_cpu_to_be32(scanType);
6354
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306355 pMsg->numSsid =
6356 (pScanReq->SSIDs.numOfSSIDs < SIR_SCAN_MAX_NUM_SSID) ?
6357 pScanReq->SSIDs.numOfSSIDs : SIR_SCAN_MAX_NUM_SSID;
Jeff Johnson295189b2012-06-20 16:38:30 -07006358 if((pScanReq->SSIDs.numOfSSIDs != 0) && ( eSIR_PASSIVE_SCAN != scanType ))
6359 {
Jeff Johnson40b59aa2013-03-19 14:43:18 -07006360 for (i = 0; i < pMsg->numSsid; i++)
6361 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306362 vos_mem_copy(&pMsg->ssId[i],
6363 &pScanReq->SSIDs.SSIDList[i].SSID, sizeof(tSirMacSSid));
Jeff Johnson40b59aa2013-03-19 14:43:18 -07006364 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006365 }
6366 else
6367 {
6368 //Otherwise we scan all SSID and let the result filter later
Jeff Johnson40b59aa2013-03-19 14:43:18 -07006369 for (i = 0; i < SIR_SCAN_MAX_NUM_SSID; i++)
6370 {
6371 pMsg->ssId[i].length = 0;
6372 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006373 }
6374
Jeff Johnson295189b2012-06-20 16:38:30 -07006375 pMsg->minChannelTime = pal_cpu_to_be32(minChnTime);
6376 pMsg->maxChannelTime = pal_cpu_to_be32(maxChnTime);
Abhishek Singhadd13582016-09-29 17:00:03 +05306377 pMsg->min_chntime_btc_esco =
6378 pMac->roam.configParam.min_chntime_btc_esco;
6379 pMsg->max_chntime_btc_esco =
6380 pMac->roam.configParam.max_chntime_btc_esco;
Jeff Johnson295189b2012-06-20 16:38:30 -07006381 //hidden SSID option
6382 pMsg->hiddenSsid = pScanReqParam->hiddenSsid;
6383 //rest time
6384 //pMsg->restTime = pScanReq->restTime;
6385 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
6386 // All the scan results caching will be done by Roaming
6387 // We do not want LIM to do any caching of scan results,
6388 // so delete the LIM cache on all scan requests
6389 pMsg->returnFreshResults = pScanReqParam->freshScan;
6390 //Always ask for unique result
6391 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
6392 pMsg->channelList.numChannels = (tANI_U8)pScanReq->ChannelInfo.numOfChannels;
6393 if(pScanReq->ChannelInfo.numOfChannels)
6394 {
6395 //Assuming the channelNumber is tANI_U8 (1 byte)
Kiet Lam64c1b492013-07-12 13:56:44 +05306396 vos_mem_copy(pMsg->channelList.channelNumber,
6397 pScanReq->ChannelInfo.ChannelList,
6398 pScanReq->ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07006399 }
6400
6401 pMsg->uIEFieldLen = (tANI_U16) pScanReq->uIEFieldLen;
6402 pMsg->uIEFieldOffset = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
6403 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) ;
6404 if(pScanReq->uIEFieldLen != 0)
6405 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306406 vos_mem_copy((tANI_U8 *)pMsg+pMsg->uIEFieldOffset, pScanReq->pIEField,
6407 pScanReq->uIEFieldLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07006408 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006409 pMsg->p2pSearch = pScanReq->p2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07006410
Madan Mohan Koyyalamudi9b876782012-10-11 16:22:51 -07006411 if (pScanReq->requestType == eCSR_SCAN_HO_BG_SCAN)
6412 {
6413 pMsg->backgroundScanMode = eSIR_ROAMING_SCAN;
6414 }
6415
Jeff Johnson295189b2012-06-20 16:38:30 -07006416 }while(0);
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05306417 smsLog(pMac, LOG1, FL("domainIdCurrent %s (%d) scanType %s (%d)"
6418 "bssType %s (%d), requestType %s(%d)"
6419 "numChannels %d"),
6420 voss_DomainIdtoString(pMac->scan.domainIdCurrent),
6421 pMac->scan.domainIdCurrent,
6422 lim_ScanTypetoString(pMsg->scanType), pMsg->scanType,
6423 lim_BssTypetoString(pMsg->bssType), pMsg->bssType,
6424 sme_requestTypetoString(pScanReq->requestType),
6425 pScanReq->requestType,
6426 pMsg->channelList.numChannels);
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08006427
6428 for(i = 0; i < pMsg->channelList.numChannels; i++)
6429 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006430 smsLog(pMac, LOG3, FL("channelNumber[%d]= %d"), i, pMsg->channelList.channelNumber[i]);
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08006431 }
6432
Jeff Johnson295189b2012-06-20 16:38:30 -07006433 if(HAL_STATUS_SUCCESS(status))
6434 {
6435 status = palSendMBMessage(pMac->hHdd, pMsg);
6436 }
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08006437 else
6438 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006439 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d"), status );
Kiet Lam64c1b492013-07-12 13:56:44 +05306440 vos_mem_free(pMsg);
Jeff Johnson295189b2012-06-20 16:38:30 -07006441 }
6442 }//Success allocated memory
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08006443 else
6444 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006445 smsLog( pMac, LOGE, FL(" memory allocation failure"));
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08006446 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006447
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306448 if(!HAL_STATUS_SUCCESS(status))
6449 {
6450 smsLog( pMac, LOG1, FL("Failed: SId: %d FirstMatch = %d"
6451 " UniqueResult = %d freshScan = %d hiddenSsid = %d"),
6452 sessionId, pScanReqParam->bReturnAfter1stMatch,
6453 pScanReqParam->fUniqueResult, pScanReqParam->freshScan,
6454 pScanReqParam->hiddenSsid );
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05306455 smsLog( pMac, LOG1, FL("scanType = %s (%d) BSSType = %s (%d) "
6456 "numOfSSIDs = %d numOfChannels = %d requestType = %s (%d)"
6457 " p2pSearch = %d\n"),
6458 lim_ScanTypetoString(pScanReq->scanType),
6459 pScanReq->scanType,
6460 lim_BssTypetoString(pScanReq->BSSType),
6461 pScanReq->BSSType,
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306462 pScanReq->SSIDs.numOfSSIDs,
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05306463 pScanReq->ChannelInfo.numOfChannels,
6464 sme_requestTypetoString(pScanReq->requestType),
6465 pScanReq->requestType,
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306466 pScanReq->p2pSearch );
6467
6468 }
6469
Jeff Johnson295189b2012-06-20 16:38:30 -07006470 return( status );
6471}
6472
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006473eHalStatus csrSendMBScanResultReq( tpAniSirGlobal pMac, tANI_U32 sessionId, tScanReqParam *pScanReqParam )
Jeff Johnson295189b2012-06-20 16:38:30 -07006474{
6475 eHalStatus status = eHAL_STATUS_SUCCESS;
6476 tSirSmeScanReq *pMsg;
6477 tANI_U16 msgLen;
6478
6479 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ));
Kiet Lam64c1b492013-07-12 13:56:44 +05306480 pMsg = vos_mem_malloc(msgLen);
6481 if ( NULL == pMsg )
6482 status = eHAL_STATUS_FAILURE;
6483 else
Jeff Johnson295189b2012-06-20 16:38:30 -07006484 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306485 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006486 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
6487 pMsg->length = pal_cpu_to_be16(msgLen);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006488 pMsg->sessionId = sessionId;
6489 pMsg->transactionId = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07006490 pMsg->returnFreshResults = pScanReqParam->freshScan;
6491 //Always ask for unique result
6492 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
6493 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
6494 status = palSendMBMessage(pMac->hHdd, pMsg);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006495 if (!HAL_STATUS_SUCCESS(status))
6496 {
6497 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d\n"), status );
6498 }
6499
Jeff Johnson295189b2012-06-20 16:38:30 -07006500 }
6501
6502 return( status );
6503}
6504
6505
6506
6507eHalStatus csrScanChannels( tpAniSirGlobal pMac, tSmeCmd *pCommand )
6508{
6509 eHalStatus status = eHAL_STATUS_FAILURE;
6510 tScanReqParam scanReq;
6511
6512 do
6513 {
6514 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE | TRUE;
6515 scanReq.fUniqueResult = TRUE;
6516 scanReq.hiddenSsid = SIR_SCAN_NO_HIDDEN_SSID;
6517 if(eCsrScanForSsid == pCommand->u.scanCmd.reason)
6518 {
6519 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_FIRST_MATCH;
6520 }
6521 else
6522 {
6523 // Basically do scan on all channels even for 11D 1st scan case.
6524 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
6525 }
6526 if((eCsrScanBgScan == pCommand->u.scanCmd.reason)||
6527 (eCsrScanProbeBss == pCommand->u.scanCmd.reason))
6528 {
6529 scanReq.hiddenSsid = SIR_SCAN_HIDDEN_SSID_PE_DECISION;
6530 }
6531
6532#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
6533 {
6534 vos_log_scan_pkt_type *pScanLog = NULL;
6535
6536 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
6537 if(pScanLog)
6538 {
6539 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
6540 eCsrScanProbeBss == pCommand->u.scanCmd.reason)
6541 {
6542 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
6543 }
6544 else
6545 {
6546 if( (eSIR_PASSIVE_SCAN != pCommand->u.scanCmd.u.scanRequest.scanType) &&
6547 (eSIR_PASSIVE_SCAN != pMac->scan.curScanType) )
6548 {
6549 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_REQ;
6550 }
6551 else
6552 {
6553 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_REQ;
6554 }
6555 }
6556 pScanLog->minChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.minChnTime;
6557 pScanLog->maxChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.maxChnTime;
6558 pScanLog->numChannel = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
6559 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
6560 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306561 vos_mem_copy(pScanLog->channels,
6562 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
6563 pScanLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07006564 }
6565 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
6566 }
6567 }
6568#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
6569
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05306570 csrClearVotesForCountryInfo(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07006571 status = csrSendMBScanReq(pMac, pCommand->sessionId,
6572 &pCommand->u.scanCmd.u.scanRequest, &scanReq);
6573 }while(0);
6574
6575 return( status );
6576}
6577
6578
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006579eHalStatus csrScanRetrieveResult(tpAniSirGlobal pMac, tSmeCmd *pCommand)
Jeff Johnson295189b2012-06-20 16:38:30 -07006580{
6581 eHalStatus status = eHAL_STATUS_FAILURE;
6582 tScanReqParam scanReq;
6583
6584 do
6585 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006586#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
6587 if (eCsrScanGetLfrResult == pCommand->u.scanCmd.reason)
6588 {
6589 //to get the LFR candidates from PE cache
6590 scanReq.freshScan = SIR_BG_SCAN_RETURN_LFR_CACHED_RESULTS|SIR_BG_SCAN_PURGE_LFR_RESULTS;
6591 scanReq.fUniqueResult = TRUE;
6592 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
6593 }
6594 else
6595#endif
6596 {
6597 //not a fresh scan
6598 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE;
6599 scanReq.fUniqueResult = TRUE;
6600 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
6601 }
6602 status = csrSendMBScanResultReq(pMac, pCommand->sessionId, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07006603 }while(0);
6604
6605 return (status);
6606}
6607
Siddharth Bhald8a95e82015-02-12 20:14:52 +05306608eHalStatus csrProcessMacAddrSpoofCommand( tpAniSirGlobal pMac, tSmeCmd *pCommand )
6609{
6610 tSirSpoofMacAddrReq *pMsg;
6611 tANI_U16 msgLen;
6612 eHalStatus status = eHAL_STATUS_FAILURE;
6613 do {
6614 msgLen = sizeof(tSirSpoofMacAddrReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07006615
Siddharth Bhald8a95e82015-02-12 20:14:52 +05306616 pMsg = vos_mem_malloc(msgLen);
6617 if ( NULL == pMsg )
6618 return eHAL_STATUS_FAILURE;
6619 pMsg->messageType= pal_cpu_to_be16((tANI_U16)eWNI_SME_MAC_SPOOF_ADDR_IND);
6620 pMsg->length= pal_cpu_to_be16(msgLen);
6621 // spoof mac address
6622 vos_mem_copy((tANI_U8 *)pMsg->macAddr,
6623 (tANI_U8 *)pCommand->u.macAddrSpoofCmd.macAddr, sizeof(tSirMacAddr));
6624 status = palSendMBMessage(pMac->hHdd, pMsg);
6625 } while( 0 );
6626 return( status );
6627}
Jeff Johnson295189b2012-06-20 16:38:30 -07006628
6629eHalStatus csrProcessScanCommand( tpAniSirGlobal pMac, tSmeCmd *pCommand )
6630{
6631 eHalStatus status = eHAL_STATUS_SUCCESS;
6632 tCsrChannelInfo newChannelInfo = {0, NULL};
6633 int i, j;
6634 tANI_U8 *pChannel = NULL;
6635 tANI_U32 len = 0;
6636
6637 // Transition to Scanning state...
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306638 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07006639 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306640 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
6641 {
Abhishek Singhf52182c2016-08-24 11:15:23 +05306642 pMac->roam.prev_state[i]=
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306643 csrRoamStateChange( pMac, eCSR_ROAMING_STATE_SCANNING, i);
6644 smsLog( pMac, LOG3, "starting SCAN command from %d state...."
Abhishek Singhf52182c2016-08-24 11:15:23 +05306645 " reason is %d", pMac->roam.prev_state[i],
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306646 pCommand->u.scanCmd.reason );
6647 }
6648 }
6649 else
6650 {
Abhishek Singhf52182c2016-08-24 11:15:23 +05306651 pMac->roam.prev_state[pCommand->sessionId] =
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306652 csrRoamStateChange(pMac, eCSR_ROAMING_STATE_SCANNING,
6653 pCommand->sessionId);
6654 smsLog( pMac, LOG3,
6655 "starting SCAN command from %d state.... reason is %d",
Abhishek Singhf52182c2016-08-24 11:15:23 +05306656 pMac->roam.prev_state[pCommand->sessionId],
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306657 pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07006658 }
6659
6660 switch(pCommand->u.scanCmd.reason)
6661 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006662#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
6663 case eCsrScanGetLfrResult:
6664#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006665 case eCsrScanGetResult:
6666 case eCsrScanForCapsChange: //For cap change, LIM already save BSS description
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006667 status = csrScanRetrieveResult(pMac, pCommand);
Jeff Johnson295189b2012-06-20 16:38:30 -07006668 break;
6669 case eCsrScanSetBGScanParam:
6670 status = csrProcessSetBGScanParam(pMac, pCommand);
6671 break;
6672 case eCsrScanBGScanAbort:
6673 status = csrSetCfgBackgroundScanPeriod(pMac, 0);
6674 break;
6675 case eCsrScanBGScanEnable:
6676 status = csrSetCfgBackgroundScanPeriod(pMac, pMac->roam.configParam.bgScanInterval);
6677 break;
6678 case eCsrScanGetScanChnInfo:
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05306679 status = csrScanGetScanChannelInfo(pMac, pCommand->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07006680 break;
6681 case eCsrScanUserRequest:
6682 if(pMac->roam.configParam.fScanTwice)
6683 {
6684 //We scan 2.4 channel twice
6685 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels &&
6686 (NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList))
6687 {
6688 len = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
6689 //allocate twice the channel
Mukul Sharmaa631e892014-08-28 15:38:51 +05306690 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(len * 2);
Jeff Johnson295189b2012-06-20 16:38:30 -07006691 pChannel = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
6692 }
6693 else
6694 {
6695 //get the valid channel list to scan all.
6696 len = sizeof(pMac->roam.validChannelList);
6697
6698 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
6699 {
6700 //allocate twice the channel
6701 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(len * 2);
6702 pChannel = pMac->roam.validChannelList;
6703 }
6704 }
6705 if(NULL == newChannelInfo.ChannelList)
6706 {
6707 newChannelInfo.numOfChannels = 0;
6708 }
6709 else
6710 {
6711 j = 0;
6712 for(i = 0; i < len; i++)
6713 {
6714 newChannelInfo.ChannelList[j++] = pChannel[i];
6715 if(CSR_MAX_24GHz_CHANNEL_NUMBER >= pChannel[i])
6716 {
6717 newChannelInfo.ChannelList[j++] = pChannel[i];
6718 }
6719 }
6720 if(NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
6721 {
6722 //pChannel points to the channellist from the command, free it.
6723 vos_mem_free(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -07006724 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07006725 }
6726 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = j;
6727 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = newChannelInfo.ChannelList;
6728 }
6729 } //if(pMac->roam.configParam.fScanTwice)
6730
6731 status = csrScanChannels(pMac, pCommand);
6732
6733 break;
6734 default:
6735 status = csrScanChannels(pMac, pCommand);
6736 break;
6737 }
6738
6739 if(!HAL_STATUS_SUCCESS(status))
6740 {
6741 csrReleaseScanCommand(pMac, pCommand, eCSR_SCAN_FAILURE);
6742 }
6743
6744 return (status);
6745}
6746
6747
6748eHalStatus csrScanSetBGScanparams(tpAniSirGlobal pMac, tCsrBGScanRequest *pScanReq)
6749{
6750 eHalStatus status = eHAL_STATUS_SUCCESS;
6751 tSmeCmd *pCommand = NULL;
6752
6753 if(pScanReq)
6754 {
6755 do
6756 {
6757 pCommand = csrGetCommandBuffer(pMac);
6758 if(!pCommand)
6759 {
6760 status = eHAL_STATUS_RESOURCES;
6761 break;
6762 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306763 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006764 pCommand->command = eSmeCommandScan;
6765 pCommand->u.scanCmd.reason = eCsrScanSetBGScanParam;
6766 pCommand->u.scanCmd.callback = NULL;
6767 pCommand->u.scanCmd.pContext = NULL;
Kiet Lam64c1b492013-07-12 13:56:44 +05306768 vos_mem_copy(&pCommand->u.scanCmd.u.bgScanRequest, pScanReq, sizeof(tCsrBGScanRequest));
Jeff Johnson295189b2012-06-20 16:38:30 -07006769 //we have to do the follow
6770 if(pScanReq->ChannelInfo.numOfChannels == 0)
6771 {
6772 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
6773 }
6774 else
6775 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306776 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList
6777 = vos_mem_malloc(pScanReq->ChannelInfo.numOfChannels);
6778 if ( NULL != pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07006779 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306780 vos_mem_copy(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList,
6781 pScanReq->ChannelInfo.ChannelList,
6782 pScanReq->ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07006783 }
6784 else
6785 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006786 smsLog(pMac, LOGE, FL("ran out of memory"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006787 csrReleaseCommandScan(pMac, pCommand);
Kiet Lam64c1b492013-07-12 13:56:44 +05306788 return eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006789 }
6790 }
6791
6792 //scan req for SSID
6793 if(pScanReq->SSID.length)
6794 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306795 vos_mem_copy(pCommand->u.scanCmd.u.bgScanRequest.SSID.ssId,
6796 pScanReq->SSID.ssId, pScanReq->SSID.length);
Jeff Johnson295189b2012-06-20 16:38:30 -07006797 pCommand->u.scanCmd.u.bgScanRequest.SSID.length = pScanReq->SSID.length;
6798
6799 }
6800 pCommand->u.scanCmd.u.bgScanRequest.maxChnTime= pScanReq->maxChnTime;
6801 pCommand->u.scanCmd.u.bgScanRequest.minChnTime = pScanReq->minChnTime;
6802 pCommand->u.scanCmd.u.bgScanRequest.scanInterval = pScanReq->scanInterval;
6803
6804
6805 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
6806 if( !HAL_STATUS_SUCCESS( status ) )
6807 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006808 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006809 csrReleaseCommandScan( pMac, pCommand );
6810 break;
6811 }
6812 }while(0);
6813 }
6814
6815 return (status);
6816}
6817
6818eHalStatus csrScanBGScanAbort( tpAniSirGlobal pMac )
6819{
6820 eHalStatus status = eHAL_STATUS_SUCCESS;
6821 tSmeCmd *pCommand = NULL;
6822
6823 do
6824 {
6825 pCommand = csrGetCommandBuffer(pMac);
6826 if(!pCommand)
6827 {
6828 status = eHAL_STATUS_RESOURCES;
6829 break;
6830 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306831 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006832 pCommand->command = eSmeCommandScan;
6833 pCommand->u.scanCmd.reason = eCsrScanBGScanAbort;
6834 pCommand->u.scanCmd.callback = NULL;
6835 pCommand->u.scanCmd.pContext = NULL;
6836 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
6837 if( !HAL_STATUS_SUCCESS( status ) )
6838 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006839 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006840 csrReleaseCommandScan( pMac, pCommand );
6841 break;
6842 }
6843 }while(0);
6844
6845 return (status);
6846}
6847
6848
6849//This will enable the background scan with the non-zero interval
6850eHalStatus csrScanBGScanEnable(tpAniSirGlobal pMac)
6851{
6852 eHalStatus status = eHAL_STATUS_SUCCESS;
6853 tSmeCmd *pCommand = NULL;
6854
6855 if(pMac->roam.configParam.bgScanInterval)
6856 {
6857 do
6858 {
6859 pCommand = csrGetCommandBuffer(pMac);
6860 if(!pCommand)
6861 {
6862 status = eHAL_STATUS_RESOURCES;
6863 break;
6864 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306865 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006866 pCommand->command = eSmeCommandScan;
6867 pCommand->u.scanCmd.reason = eCsrScanBGScanEnable;
6868 pCommand->u.scanCmd.callback = NULL;
6869 pCommand->u.scanCmd.pContext = NULL;
6870 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
6871 if( !HAL_STATUS_SUCCESS( status ) )
6872 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006873 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006874 csrReleaseCommandScan( pMac, pCommand );
6875 break;
6876 }
6877 }while(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006878 }
6879 else
6880 {
Sushant Kaushikb8dbb3f2015-04-29 17:03:37 +05306881 smsLog(pMac, LOGE, FL("cannot continue because the bgscan interval is 0"));
6882 status = eHAL_STATUS_INVALID_PARAMETER;
Jeff Johnson295189b2012-06-20 16:38:30 -07006883 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006884 return (status);
6885}
6886
6887
6888eHalStatus csrScanCopyRequest(tpAniSirGlobal pMac, tCsrScanRequest *pDstReq, tCsrScanRequest *pSrcReq)
6889{
6890 eHalStatus status = eHAL_STATUS_SUCCESS;
6891 tANI_U32 len = sizeof(pMac->roam.validChannelList);
6892 tANI_U32 index = 0;
6893 tANI_U32 new_index = 0;
Manjunathappa Prakashde7b2a52014-02-28 16:59:03 -08006894 eNVChannelEnabledType NVchannel_state;
Arif Hussain6af38622014-03-12 12:39:57 -07006895 tANI_U8 ch144_support = 0;
6896
6897 ch144_support = WDA_getFwWlanFeatCaps(WLAN_CH144);
Jeff Johnson295189b2012-06-20 16:38:30 -07006898
6899 do
6900 {
6901 status = csrScanFreeRequest(pMac, pDstReq);
6902 if(HAL_STATUS_SUCCESS(status))
6903 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306904 vos_mem_copy(pDstReq, pSrcReq, sizeof(tCsrScanRequest));
Gopichand Nakkalac7b1d3e2012-12-31 14:07:19 -08006905 /* Re-initialize the pointers to NULL since we did a copy */
6906 pDstReq->pIEField = NULL;
6907 pDstReq->ChannelInfo.ChannelList = NULL;
6908 pDstReq->SSIDs.SSIDList = NULL;
6909
Jeff Johnson295189b2012-06-20 16:38:30 -07006910 if(pSrcReq->uIEFieldLen == 0)
6911 {
6912 pDstReq->pIEField = NULL;
6913 }
6914 else
6915 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306916 pDstReq->pIEField = vos_mem_malloc(pSrcReq->uIEFieldLen);
6917 if ( NULL == pDstReq->pIEField )
Jeff Johnson295189b2012-06-20 16:38:30 -07006918 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306919 status = eHAL_STATUS_FAILURE;
6920 smsLog(pMac, LOGE, FL("No memory for scanning IE fields"));
6921 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07006922 }
6923 else
6924 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306925 status = eHAL_STATUS_SUCCESS;
6926 vos_mem_copy(pDstReq->pIEField, pSrcReq->pIEField,
6927 pSrcReq->uIEFieldLen);
6928 pDstReq->uIEFieldLen = pSrcReq->uIEFieldLen;
Jeff Johnson295189b2012-06-20 16:38:30 -07006929 }
6930 }//Allocate memory for IE field
6931 {
6932 if(pSrcReq->ChannelInfo.numOfChannels == 0)
6933 {
6934 pDstReq->ChannelInfo.ChannelList = NULL;
6935 pDstReq->ChannelInfo.numOfChannels = 0;
6936 }
6937 else
6938 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306939 pDstReq->ChannelInfo.ChannelList = vos_mem_malloc(
6940 pSrcReq->ChannelInfo.numOfChannels
6941 * sizeof(*pDstReq->ChannelInfo.ChannelList));
6942 if ( NULL == pDstReq->ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07006943 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306944 status = eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006945 pDstReq->ChannelInfo.numOfChannels = 0;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306946 smsLog(pMac, LOGE, FL("No memory for scanning Channel"
6947 " List"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006948 break;
6949 }
6950
6951 if((pSrcReq->scanType == eSIR_PASSIVE_SCAN) && (pSrcReq->requestType == eCSR_SCAN_REQUEST_11D_SCAN))
6952 {
6953 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
6954 {
Arif Hussain6af38622014-03-12 12:39:57 -07006955 /* Skip CH 144 if firmware support not present */
6956 if (pSrcReq->ChannelInfo.ChannelList[index] == 144 && !ch144_support)
6957 continue;
Agarwal Ashish8bd53ae2015-06-12 18:03:45 +05306958 /* Skip channel 12 and 13 when FCC constraint is true */
6959 if ((pMac->scan.fcc_constraint) &&
6960 ((pSrcReq->ChannelInfo.ChannelList[index] ==12) ||
6961 (pSrcReq->ChannelInfo.ChannelList[index] ==13)))
6962 {
6963 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
6964 FL("Ignoring channel : %d "),
6965 pSrcReq->ChannelInfo.ChannelList[index]);
6966 continue;
6967 }
Arif Hussain6af38622014-03-12 12:39:57 -07006968
Manjunathappa Prakashde7b2a52014-02-28 16:59:03 -08006969 NVchannel_state = vos_nv_getChannelEnabledState(
6970 pSrcReq->ChannelInfo.ChannelList[index]);
6971 if ((NV_CHANNEL_ENABLE == NVchannel_state) ||
6972 (NV_CHANNEL_DFS == NVchannel_state))
6973 {
6974 pDstReq->ChannelInfo.ChannelList[new_index] =
6975 pSrcReq->ChannelInfo.ChannelList[index];
6976 new_index++;
6977 }
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306978 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006979 pDstReq->ChannelInfo.numOfChannels = new_index;
6980 }
6981 else if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
6982 {
6983 new_index = 0;
6984 pMac->roam.numValidChannels = len;
c_hpothu0d5a7352014-03-22 12:30:25 +05306985
Deepthi Gowriecc93352016-11-09 16:58:47 +05306986 /* Since in CsrScanRequest,value of pMac->scan.
6987 * nextScanID is incremented before calling
6988 * CsrScanCopyRequest, as a result pMac->scan.
6989 * nextScanID is equal to ONE for the first scan.
6990 * If number of channels is less than max chan
6991 * for dwell time no need to skip dfs in first
6992 * scan as anyway few channels will be scanned
6993 * and it will not take much time to display
6994 * results on GUI.
6995 */
6996 if (((pSrcReq->ChannelInfo.numOfChannels >=
6997 pMac->roam.configParam.
6998 max_chan_for_dwell_time_cfg) &&
6999 (pMac->roam.configParam.
7000 initialScanSkipDFSCh &&
7001 1 == pMac->scan.nextScanID)) ||
7002 (pMac->miracast_mode))
c_hpothu0d5a7352014-03-22 12:30:25 +05307003 {
Deepthi Gowriecc93352016-11-09 16:58:47 +05307004 smsLog(pMac, LOG1,
7005 FL("Initial scan, scan only non-DFS channels"));
c_hpothu0d5a7352014-03-22 12:30:25 +05307006
Deepthi Gowriecc93352016-11-09 16:58:47 +05307007 for (index = 0; index < pSrcReq->ChannelInfo.
7008 numOfChannels ; index++ )
Jeff Johnson295189b2012-06-20 16:38:30 -07007009 {
Deepthi Gowriecc93352016-11-09 16:58:47 +05307010 if((csrRoamIsValidChannel(pMac,
7011 pSrcReq->ChannelInfo.
7012 ChannelList[index])))
Srikant Kuppa866893f2012-12-27 17:28:14 -08007013 {
Deepthi Gowriecc93352016-11-09 16:58:47 +05307014 /*Skiipping DFS Channels for 1st scan */
7015 if(NV_CHANNEL_DFS ==
7016 vos_nv_getChannelEnabledState(
7017 pSrcReq->ChannelInfo.
7018 ChannelList[index]))
7019 continue ;
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08007020
Deepthi Gowriecc93352016-11-09 16:58:47 +05307021 pDstReq->ChannelInfo.
7022 ChannelList[new_index] =
7023 pSrcReq->ChannelInfo.ChannelList[index];
7024 new_index++;
7025
7026 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007027 }
Deepthi Gowriecc93352016-11-09 16:58:47 +05307028 pMac->roam.configParam.initialScanSkipDFSCh = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07007029 }
Deepthi Gowriecc93352016-11-09 16:58:47 +05307030 else
7031 csrValidateScanChannels(pMac, pDstReq, pSrcReq,
Nishank Aggarwal42f76502017-02-16 12:00:19 +05307032 &new_index, ch144_support);
Jeff Johnson295189b2012-06-20 16:38:30 -07007033 pDstReq->ChannelInfo.numOfChannels = new_index;
Srikant Kuppa866893f2012-12-27 17:28:14 -08007034#ifdef FEATURE_WLAN_LFR
Deepthi Gowriecc93352016-11-09 16:58:47 +05307035 if ( ( ( eCSR_SCAN_HO_BG_SCAN ==
7036 pSrcReq->requestType ) ||
7037 ( eCSR_SCAN_P2P_DISCOVERY ==
7038 pSrcReq->requestType ) ) &&
7039 ( 0 == pDstReq->ChannelInfo.numOfChannels ) )
Srikant Kuppa866893f2012-12-27 17:28:14 -08007040 {
7041 /*
7042 * No valid channels found in the request.
7043 * Only perform scan on the channels passed
Abhishek Singh2ec36ab2014-08-07 16:14:25 +05307044 * pSrcReq if it is a eCSR_SCAN_HO_BG_SCAN or
7045 * eCSR_SCAN_P2P_DISCOVERY.
Srikant Kuppa866893f2012-12-27 17:28:14 -08007046 * Passing 0 to LIM will trigger a scan on
7047 * all valid channels which is not desirable.
7048 */
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05307049 smsLog(pMac, LOGE, FL(" no valid channels found"
Deepthi Gowriecc93352016-11-09 16:58:47 +05307050 " (request=%d)"), pSrcReq->requestType);
7051 for ( index = 0; index < pSrcReq->ChannelInfo.
7052 numOfChannels ; index++ )
Srikant Kuppa866893f2012-12-27 17:28:14 -08007053 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05307054 smsLog(pMac, LOGE, FL("pSrcReq index=%d"
Deepthi Gowriecc93352016-11-09 16:58:47 +05307055 " channel=%d"), index,
7056 pSrcReq->ChannelInfo.ChannelList[index]);
Srikant Kuppa866893f2012-12-27 17:28:14 -08007057 }
7058 status = eHAL_STATUS_FAILURE;
7059 break;
Deepthi Gowriecc93352016-11-09 16:58:47 +05307060 }
Srikant Kuppa866893f2012-12-27 17:28:14 -08007061#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07007062 }
7063 else
7064 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05307065 smsLog(pMac, LOGE, FL("Couldn't get the valid Channel"
7066 " List, keeping requester's list"));
Kiet Lam64c1b492013-07-12 13:56:44 +05307067 vos_mem_copy(pDstReq->ChannelInfo.ChannelList,
7068 pSrcReq->ChannelInfo.ChannelList,
7069 pSrcReq->ChannelInfo.numOfChannels
Deepthi Gowriecc93352016-11-09 16:58:47 +05307070 * sizeof(*pDstReq->ChannelInfo.ChannelList));
7071 pDstReq->ChannelInfo.numOfChannels =
7072 pSrcReq->ChannelInfo.numOfChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -07007073 }
7074 }//Allocate memory for Channel List
7075 }
7076 if(pSrcReq->SSIDs.numOfSSIDs == 0)
7077 {
7078 pDstReq->SSIDs.numOfSSIDs = 0;
7079 pDstReq->SSIDs.SSIDList = NULL;
7080 }
7081 else
7082 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307083 pDstReq->SSIDs.SSIDList = vos_mem_malloc(
7084 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
7085 if ( NULL == pDstReq->SSIDs.SSIDList )
7086 status = eHAL_STATUS_FAILURE;
7087 else
7088 status = eHAL_STATUS_SUCCESS;
7089 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07007090 {
7091 pDstReq->SSIDs.numOfSSIDs = pSrcReq->SSIDs.numOfSSIDs;
Kiet Lam64c1b492013-07-12 13:56:44 +05307092 vos_mem_copy(pDstReq->SSIDs.SSIDList,
7093 pSrcReq->SSIDs.SSIDList,
7094 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
Jeff Johnson295189b2012-06-20 16:38:30 -07007095 }
7096 else
7097 {
7098 pDstReq->SSIDs.numOfSSIDs = 0;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05307099 smsLog(pMac, LOGE, FL("No memory for scanning SSID List"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007100 break;
7101 }
7102 }//Allocate memory for SSID List
Jeff Johnson295189b2012-06-20 16:38:30 -07007103 pDstReq->p2pSearch = pSrcReq->p2pSearch;
Jeff Johnsone7245742012-09-05 17:12:55 -07007104 pDstReq->skipDfsChnlInP2pSearch = pSrcReq->skipDfsChnlInP2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07007105
7106 }
7107 }while(0);
7108
7109 if(!HAL_STATUS_SUCCESS(status))
7110 {
7111 csrScanFreeRequest(pMac, pDstReq);
7112 }
7113
7114 return (status);
7115}
7116
7117
7118eHalStatus csrScanFreeRequest(tpAniSirGlobal pMac, tCsrScanRequest *pReq)
7119{
Jeff Johnson295189b2012-06-20 16:38:30 -07007120
7121 if(pReq->ChannelInfo.ChannelList)
7122 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307123 vos_mem_free(pReq->ChannelInfo.ChannelList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007124 pReq->ChannelInfo.ChannelList = NULL;
7125 }
7126 pReq->ChannelInfo.numOfChannels = 0;
7127 if(pReq->pIEField)
7128 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307129 vos_mem_free(pReq->pIEField);
Jeff Johnson295189b2012-06-20 16:38:30 -07007130 pReq->pIEField = NULL;
7131 }
7132 pReq->uIEFieldLen = 0;
7133 if(pReq->SSIDs.SSIDList)
7134 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307135 vos_mem_free(pReq->SSIDs.SSIDList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007136 pReq->SSIDs.SSIDList = NULL;
7137 }
7138 pReq->SSIDs.numOfSSIDs = 0;
7139
Kiet Lam64c1b492013-07-12 13:56:44 +05307140 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07007141}
7142
7143
7144void csrScanCallCallback(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
7145{
7146 if(pCommand->u.scanCmd.callback)
7147 {
Ratheesh S Pece1f832015-07-25 15:50:25 +05307148 if (pCommand->u.scanCmd.abortScanIndication){
Kapil Guptac46b7542016-10-25 13:03:20 +05307149 if ((pCommand->u.scanCmd.reason != eCsrScanForSsid) ||
7150 (scanStatus != eCSR_SCAN_SUCCESS)) {
7151 smsLog( pMac, LOG1, FL("scanDone due to abort"));
7152 scanStatus = eCSR_SCAN_ABORT;
7153 }
Ratheesh S Pece1f832015-07-25 15:50:25 +05307154 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007155 pCommand->u.scanCmd.callback(pMac, pCommand->u.scanCmd.pContext, pCommand->u.scanCmd.scanID, scanStatus);
Jeff Johnson295189b2012-06-20 16:38:30 -07007156 } else {
Kapil Guptac46b7542016-10-25 13:03:20 +05307157 smsLog(pMac, LOG2,
7158 FL("Callback NULL cmd reason %d"),
7159 pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07007160 }
7161}
7162
7163
7164void csrScanStopTimers(tpAniSirGlobal pMac)
7165{
Jeff Johnson295189b2012-06-20 16:38:30 -07007166 csrScanStopIdleScanTimer(pMac);
7167 csrScanStopGetResultTimer(pMac);
7168}
7169
7170
7171eHalStatus csrScanStartGetResultTimer(tpAniSirGlobal pMac)
7172{
7173 eHalStatus status;
7174
7175 if(pMac->scan.fScanEnable)
7176 {
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05307177 status = vos_timer_start(&pMac->scan.hTimerGetResult, CSR_SCAN_GET_RESULT_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07007178 }
7179 else
7180 {
7181 status = eHAL_STATUS_FAILURE;
7182 }
7183
7184 return (status);
7185}
7186
7187
7188eHalStatus csrScanStopGetResultTimer(tpAniSirGlobal pMac)
7189{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05307190 return (vos_timer_stop(&pMac->scan.hTimerGetResult));
Jeff Johnson295189b2012-06-20 16:38:30 -07007191}
7192
7193
7194void csrScanGetResultTimerHandler(void *pv)
7195{
7196 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
7197
7198 csrScanRequestResult(pMac);
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05307199
7200 vos_timer_start(&pMac->scan.hTimerGetResult, CSR_SCAN_GET_RESULT_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07007201}
7202
Padma, Santhosh Kumar36183352016-11-08 17:48:34 +05307203
7204void csr_handle_disable_scan(void *pv)
7205{
7206 tpAniSirGlobal mac = PMAC_STRUCT(pv);
7207
7208 if (mac->scan.disable_scan_during_sco_timer_info.callback)
7209 mac->scan.disable_scan_during_sco_timer_info.callback(
7210 mac,
7211 mac->scan.disable_scan_during_sco_timer_info.dev,
7212 mac->scan.disable_scan_during_sco_timer_info.scan_id,
7213 eHAL_STATUS_SUCCESS);
7214 else
7215 smsLog(mac, LOGE, FL("Callback is NULL"));
7216}
7217
Jeff Johnson295189b2012-06-20 16:38:30 -07007218#ifdef WLAN_AP_STA_CONCURRENCY
7219static void csrStaApConcTimerHandler(void *pv)
7220{
7221 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
7222 tListElem *pEntry;
7223 tSmeCmd *pScanCmd;
7224
7225 csrLLLock(&pMac->scan.scanCmdPendingList);
7226
7227 if ( NULL != ( pEntry = csrLLPeekHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) ) )
7228 {
7229 tCsrScanRequest scanReq;
7230 tSmeCmd *pSendScanCmd = NULL;
7231 tANI_U8 numChn = 0;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07007232 tANI_U8 nNumChanCombinedConc = 0;
Vinay Malekal05fdc812012-12-17 13:04:30 -08007233 tANI_U8 i, j;
Jeff Johnson295189b2012-06-20 16:38:30 -07007234 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
7235 tANI_U8 channelToScan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
7236 eHalStatus status;
7237
Jeff Johnson295189b2012-06-20 16:38:30 -07007238 pScanCmd = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7239 numChn = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08007240
7241 /* if any session is connected and the number of channels to scan is
7242 * greater than 1 then split the scan into multiple scan operations
7243 * on each individual channel else continue to perform scan on all
7244 * specified channels */
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08007245
7246 /* split scan if number of channels to scan is greater than 1 and
7247 * any one of the following:
7248 * - STA session is connected and the scan is not a P2P search
7249 * - any P2P session is connected
Srikant Kuppa866893f2012-12-27 17:28:14 -08007250 * Do not split scans if no concurrent infra connections are
7251 * active and if the scan is a BG scan triggered by LFR (OR)
7252 * any scan if LFR is in the middle of a BG scan. Splitting
7253 * the scan is delaying the time it takes for LFR to find
7254 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08007255 */
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07007256
7257 if((csrIsStaSessionConnected(pMac) &&
7258 !csrIsP2pSessionConnected(pMac)))
7259 {
7260 nNumChanCombinedConc = pMac->roam.configParam.nNumStaChanCombinedConc;
7261 }
7262 else if(csrIsP2pSessionConnected(pMac))
7263 {
7264 nNumChanCombinedConc = pMac->roam.configParam.nNumP2PChanCombinedConc;
7265 }
7266
7267 if ( (numChn > nNumChanCombinedConc) &&
Srikant Kuppa866893f2012-12-27 17:28:14 -08007268 ((csrIsStaSessionConnected(pMac) &&
7269#ifdef FEATURE_WLAN_LFR
7270 (csrIsConcurrentInfraConnected(pMac) ||
7271 ((pScanCmd->u.scanCmd.reason != eCsrScanBgScan) &&
7272 (pMac->roam.neighborRoamInfo.neighborRoamState !=
7273 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
7274#endif
7275 (pScanCmd->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08007276 (csrIsP2pSessionConnected(pMac))))
Jeff Johnson295189b2012-06-20 16:38:30 -07007277 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307278 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007279
7280 pSendScanCmd = csrGetCommandBuffer(pMac); //optimize this to use 2 command buffer only
7281 if (!pSendScanCmd)
7282 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007283 smsLog( pMac, LOGE, FL(" Failed to get Queue command buffer") );
Jeff Johnson295189b2012-06-20 16:38:30 -07007284 csrLLUnlock(&pMac->scan.scanCmdPendingList);
7285 return;
7286 }
7287 pSendScanCmd->command = pScanCmd->command;
7288 pSendScanCmd->sessionId = pScanCmd->sessionId;
7289 pSendScanCmd->u.scanCmd.callback = NULL;
7290 pSendScanCmd->u.scanCmd.pContext = pScanCmd->u.scanCmd.pContext;
7291 pSendScanCmd->u.scanCmd.reason = pScanCmd->u.scanCmd.reason;
7292 pSendScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
7293
Madan Mohan Koyyalamudiaf2a8b92012-10-09 14:58:07 -07007294 /* First copy all the parameters to local variable of scan request */
7295 csrScanCopyRequest(pMac, &scanReq, &pScanCmd->u.scanCmd.u.scanRequest);
7296
7297 /* Now modify the elements of local var scan request required to be modified for split scan */
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08007298 if(scanReq.ChannelInfo.ChannelList != NULL)
7299 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307300 vos_mem_free(scanReq.ChannelInfo.ChannelList);
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08007301 scanReq.ChannelInfo.ChannelList = NULL;
7302 }
7303
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07007304 pChnInfo->numOfChannels = nNumChanCombinedConc;
Kiet Lam64c1b492013-07-12 13:56:44 +05307305 vos_mem_copy(&channelToScan[0],
7306 &pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[0],
7307 pChnInfo->numOfChannels * sizeof(tANI_U8));//just send one channel
Jeff Johnson295189b2012-06-20 16:38:30 -07007308 pChnInfo->ChannelList = &channelToScan[0];
7309
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07007310 for (i = 0, j = nNumChanCombinedConc; i < (numChn-nNumChanCombinedConc); i++, j++)
Jeff Johnson295189b2012-06-20 16:38:30 -07007311 {
7312 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] =
Vinay Malekal05fdc812012-12-17 13:04:30 -08007313 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[j]; //Move all the channels one step
Jeff Johnson295189b2012-06-20 16:38:30 -07007314 }
7315
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07007316 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = numChn - nNumChanCombinedConc; //reduce outstanding # of channels to be scanned
Jeff Johnson295189b2012-06-20 16:38:30 -07007317
7318 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
c_hpothudbefd3e2014-04-28 15:59:47 +05307319
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -07007320 //Use concurrency values for min/maxChnTime.
7321 //We know csrIsAnySessionConnected(pMac) returns TRUE here
7322 csrSetDefaultScanTiming(pMac, scanReq.scanType, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07007323
7324 status = csrScanCopyRequest(pMac, &pSendScanCmd->u.scanCmd.u.scanRequest, &scanReq);
7325 if(!HAL_STATUS_SUCCESS(status))
7326 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007327 smsLog( pMac, LOGE, FL(" Failed to get copy csrScanRequest = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07007328 csrLLUnlock(&pMac->scan.scanCmdPendingList);
7329 return;
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08007330 }
7331 /* Clean the local scan variable */
7332 scanReq.ChannelInfo.ChannelList = NULL;
7333 scanReq.ChannelInfo.numOfChannels = 0;
7334 csrScanFreeRequest(pMac, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07007335 }
7336 else
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08007337 {
7338 /* no active connected session present or numChn == 1
7339 * scan all remaining channels */
Jeff Johnson295189b2012-06-20 16:38:30 -07007340 pSendScanCmd = pScanCmd;
7341 //remove this command from pending list
7342 if (csrLLRemoveHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) == NULL)
7343 { //In case between PeekHead and here, the entry got removed by another thread.
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007344 smsLog( pMac, LOGE, FL(" Failed to remove entry from scanCmdPendingList"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007345 }
7346
7347 }
7348 csrQueueSmeCommand(pMac, pSendScanCmd, eANI_BOOLEAN_FALSE);
7349
7350 }
7351
Jeff Johnson295189b2012-06-20 16:38:30 -07007352 csrLLUnlock(&pMac->scan.scanCmdPendingList);
7353
7354}
7355#endif
7356
Jeff Johnson295189b2012-06-20 16:38:30 -07007357//This function returns the maximum time a BSS is allowed in the scan result.
7358//The time varies base on connection and power saving factors.
7359//Not connected, No PS
7360//Not connected, with PS
7361//Connected w/o traffic, No PS
7362//Connected w/o traffic, with PS
7363//Connected w/ traffic, no PS -- Not supported
7364//Connected w/ traffic, with PS -- Not supported
7365//the return unit is in seconds.
7366tANI_U32 csrScanGetAgeOutTime(tpAniSirGlobal pMac)
7367{
7368 tANI_U32 nRet;
7369
7370 if(pMac->scan.nAgingCountDown)
7371 {
7372 //Calculate what should be the timeout value for this
7373 nRet = pMac->scan.nLastAgeTimeOut * pMac->scan.nAgingCountDown;
7374 pMac->scan.nAgingCountDown--;
7375 }
7376 else
7377 {
7378 if( csrIsAllSessionDisconnected( pMac ) )
7379 {
7380 if(pmcIsPowerSaveEnabled(pMac, ePMC_IDLE_MODE_POWER_SAVE))
7381 {
7382 nRet = pMac->roam.configParam.scanAgeTimeNCPS;
7383 }
7384 else
7385 {
7386 nRet = pMac->roam.configParam.scanAgeTimeNCNPS;
7387 }
7388 }
7389 else
7390 {
7391 if(pmcIsPowerSaveEnabled(pMac, ePMC_BEACON_MODE_POWER_SAVE))
7392 {
7393 nRet = pMac->roam.configParam.scanAgeTimeCPS;
7394 }
7395 else
7396 {
7397 nRet = pMac->roam.configParam.scanAgeTimeCNPS;
7398 }
7399 }
7400 //If state-change causing aging time out change, we want to delay it somewhat to avoid
7401 //unnecessary removal of BSS. This is mostly due to transition from connect to disconnect.
7402 if(pMac->scan.nLastAgeTimeOut > nRet)
7403 {
7404 if(nRet)
7405 {
7406 pMac->scan.nAgingCountDown = (pMac->scan.nLastAgeTimeOut / nRet);
7407 }
7408 pMac->scan.nLastAgeTimeOut = nRet;
7409 nRet *= pMac->scan.nAgingCountDown;
7410 }
7411 else
7412 {
7413 pMac->scan.nLastAgeTimeOut = nRet;
7414 }
7415 }
7416
7417 return (nRet);
7418}
7419
Deepthi Gowri6a08e312016-03-31 19:10:14 +05307420static void csrPurgeScanResultByAge(void *pv)
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08007421{
7422 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
7423 tListElem *pEntry, *tmpEntry;
7424 tCsrScanResult *pResult;
Deepthi Gowri4480a3f2016-05-18 19:30:17 +05307425 v_TIME_t ageOutTime =
7426 (v_TIME_t)(pMac->scan.scanResultCfgAgingTime * SYSTEM_TIME_SEC_TO_MSEC);
7427 v_TIME_t curTime = vos_timer_get_system_time();
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08007428
7429 csrLLLock(&pMac->scan.scanResultList);
7430 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
Deepthi Gowri6a08e312016-03-31 19:10:14 +05307431 smsLog(pMac, LOG1, FL("Ageout time=%lu"),ageOutTime);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08007432 while( pEntry )
7433 {
7434 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
7435 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
7436 if((curTime - pResult->Result.BssDescriptor.nReceivedTime) > ageOutTime)
7437 {
Deepthi Gowri50e2fa52016-03-17 15:30:53 +05307438 smsLog(pMac, LOG1, FL("age out due to time out for BSSID" MAC_ADDRESS_STR),
7439 MAC_ADDR_ARRAY(pResult->Result.BssDescriptor.bssId));
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08007440 csrScanAgeOutBss(pMac, pResult);
7441 }
7442 pEntry = tmpEntry;
7443 }
7444 csrLLUnlock(&pMac->scan.scanResultList);
7445}
Jeff Johnson295189b2012-06-20 16:38:30 -07007446
7447eHalStatus csrScanStartIdleScanTimer(tpAniSirGlobal pMac, tANI_U32 interval)
7448{
7449 eHalStatus status;
7450
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007451 smsLog(pMac, LOG1, " csrScanStartIdleScanTimer");
Jeff Johnson295189b2012-06-20 16:38:30 -07007452 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) && interval)
7453 {
7454 pMac->scan.nIdleScanTimeGap += interval;
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05307455 vos_timer_stop(&pMac->scan.hTimerIdleScan);
7456 status = vos_timer_start(&pMac->scan.hTimerIdleScan, interval/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07007457 if( !HAL_STATUS_SUCCESS(status) )
7458 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007459 smsLog(pMac, LOGE, " Fail to start Idle scan timer. status = %d interval = %d", status, interval);
Jeff Johnson295189b2012-06-20 16:38:30 -07007460 //This should not happen but set the flag to restart when ready
7461 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7462 }
7463 }
7464 else
7465 {
7466 if( pMac->scan.fScanEnable && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) )
7467 {
7468 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7469 }
7470 status = eHAL_STATUS_FAILURE;
7471 }
7472
7473 return (status);
7474}
7475
7476
7477eHalStatus csrScanStopIdleScanTimer(tpAniSirGlobal pMac)
7478{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05307479 return (vos_timer_stop(&pMac->scan.hTimerIdleScan));
Jeff Johnson295189b2012-06-20 16:38:30 -07007480}
7481
7482
7483//Stop CSR from asking for IMPS, This function doesn't disable IMPS from CSR
7484void csrScanSuspendIMPS( tpAniSirGlobal pMac )
7485{
7486 csrScanCancelIdleScan(pMac);
7487}
7488
7489
7490//Start CSR from asking for IMPS. This function doesn't trigger CSR to request entering IMPS
7491//because IMPS maybe disabled.
7492void csrScanResumeIMPS( tpAniSirGlobal pMac )
7493{
7494 csrScanStartIdleScan( pMac );
7495}
7496
7497
7498void csrScanIMPSCallback(void *callbackContext, eHalStatus status)
7499{
7500 tpAniSirGlobal pMac = PMAC_STRUCT( callbackContext );
7501
7502 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
7503 {
7504 if(pMac->roam.configParam.IsIdleScanEnabled)
7505 {
7506 if(HAL_STATUS_SUCCESS(status))
7507 {
7508 if(csrIsAllSessionDisconnected(pMac) && !csrIsRoamCommandWaiting(pMac))
7509 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007510 smsLog(pMac, LOGW, FL("starts idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007511 csrScanAllChannels(pMac, eCSR_SCAN_IDLE_MODE_SCAN);
7512 }
7513 else
7514 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007515 smsLog(pMac, LOGW, FL("cannot start idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007516 //even though we are in timer handle, calling stop timer will make sure the timer
7517 //doesn't get to restart.
7518 csrScanStopIdleScanTimer(pMac);
7519 }
7520 }
7521 else
7522 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007523 smsLog(pMac, LOGE, FL("sees not success status (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07007524 }
7525 }
7526 else
7527 {//we might need another flag to check if CSR needs to request imps at all
7528
7529 tANI_U32 nTime = 0;
7530
7531 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_FALSE;
7532 if(!HAL_STATUS_SUCCESS(csrScanTriggerIdleScan(pMac, &nTime)))
7533 {
7534 csrScanStartIdleScanTimer(pMac, nTime);
7535 }
7536 }
7537 }
7538}
7539
7540
Rashmi Ramanna68b309c2014-05-20 11:52:22 +05307541//Param: pTimeInterval -- Caller allocated memory in return, if failed, to specify the nxt time interval for
Jeff Johnson295189b2012-06-20 16:38:30 -07007542//idle scan timer interval
7543//Return: Not success -- meaning it cannot start IMPS, caller needs to start a timer for idle scan
7544eHalStatus csrScanTriggerIdleScan(tpAniSirGlobal pMac, tANI_U32 *pTimeInterval)
7545{
7546 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
7547
7548 //Do not trigger IMPS in case of concurrency
Agarwal Ashish5974ed32014-06-16 16:59:54 +05307549 if (vos_concurrent_open_sessions_running() &&
7550 csrIsAnySessionInConnectState(pMac))
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007551 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007552 smsLog( pMac, LOG1, FL("Cannot request IMPS because Concurrent Sessions Running") );
Jeff Johnson295189b2012-06-20 16:38:30 -07007553 return (status);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007554 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007555
7556 if(pTimeInterval)
7557 {
7558 *pTimeInterval = 0;
7559 }
7560
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007561 smsLog(pMac, LOG3, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007562 if( smeCommandPending( pMac ) )
7563 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007564 smsLog( pMac, LOG1, FL(" Cannot request IMPS because command pending") );
Jeff Johnson295189b2012-06-20 16:38:30 -07007565 //Not to enter IMPS because more work to do
7566 if(pTimeInterval)
7567 {
7568 *pTimeInterval = 0;
7569 }
7570 //restart when ready
7571 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7572
7573 return (status);
7574 }
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07007575 if (IsPmcImpsReqFailed (pMac))
7576 {
7577 if(pTimeInterval)
7578 {
7579 *pTimeInterval = 1000000; //usec
7580 }
7581 //restart when ready
7582 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07007583
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07007584 return status;
7585 }
Rashmi Ramanna68b309c2014-05-20 11:52:22 +05307586
7587 if ( !pMac->deferImps && pMac->fDeferIMPSTime )
7588 {
7589 smsLog( pMac, LOG1, FL("Defer IMPS for %dms as command processed"),
7590 pMac->fDeferIMPSTime);
Girish Gowli4f3775a2014-05-30 17:17:08 +05307591 if(pTimeInterval)
7592 {
7593 *pTimeInterval = pMac->fDeferIMPSTime * 1000; //usec
7594 }
Rashmi Ramanna68b309c2014-05-20 11:52:22 +05307595 pMac->deferImps = eANI_BOOLEAN_TRUE;
7596 return status;
7597 }
7598
Jeff Johnson295189b2012-06-20 16:38:30 -07007599 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
7600 /*&& pMac->roam.configParam.impsSleepTime*/)
7601 {
7602 //Stop get result timer because idle scan gets scan result out of PE
7603 csrScanStopGetResultTimer(pMac);
7604 if(pTimeInterval)
7605 {
7606 *pTimeInterval = pMac->roam.configParam.impsSleepTime;
7607 }
7608 //pmcRequestImps take a period in millisecond unit.
7609 status = pmcRequestImps(pMac, pMac->roam.configParam.impsSleepTime / PAL_TIMER_TO_MS_UNIT, csrScanIMPSCallback, pMac);
7610 if(!HAL_STATUS_SUCCESS(status))
7611 {
7612 if(eHAL_STATUS_PMC_ALREADY_IN_IMPS != status)
7613 {
7614 //Do restart the timer if CSR thinks it cannot do IMPS
7615 if( !csrCheckPSReady( pMac ) )
7616 {
7617 if(pTimeInterval)
7618 {
7619 *pTimeInterval = 0;
7620 }
7621 //Set the restart flag to true because that idle scan
7622 //can be restarted even though the timer will not be running
7623 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7624 }
7625 else
7626 {
7627 //For not now, we do a quicker retry
7628 if(pTimeInterval)
7629 {
7630 *pTimeInterval = CSR_IDLE_SCAN_WAIT_TIME;
7631 }
7632 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007633 smsLog(pMac, LOGW, FL("call pmcRequestImps and it returns status code (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07007634 }
7635 else
7636 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007637 smsLog(pMac, LOGW, FL("already in IMPS"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007638 //Since CSR is the only module to request for IMPS. If it is already in IMPS, CSR assumes
7639 //the callback will be called in the future. Should not happen though.
7640 status = eHAL_STATUS_SUCCESS;
7641 pMac->scan.nIdleScanTimeGap = 0;
7642 }
7643 }
7644 else
7645 {
7646 //requested so let's reset the value
7647 pMac->scan.nIdleScanTimeGap = 0;
7648 }
7649 }
7650
7651 return (status);
7652}
7653
7654
7655eHalStatus csrScanStartIdleScan(tpAniSirGlobal pMac)
7656{
7657 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
7658 tANI_U32 nTime = 0;
7659
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007660 smsLog(pMac, LOGW, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007661 if(pMac->roam.configParam.IsIdleScanEnabled)
7662 {
7663 //stop bg scan first
7664 csrScanBGScanAbort(pMac);
7665 //Stop get result timer because idle scan gets scan result out of PE
7666 csrScanStopGetResultTimer(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07007667 }
7668 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_FALSE;
7669 status = csrScanTriggerIdleScan(pMac, &nTime);
7670 if(!HAL_STATUS_SUCCESS(status))
7671 {
7672 csrScanStartIdleScanTimer(pMac, nTime);
7673 }
7674
7675 return (status);
7676}
7677
7678
7679void csrScanCancelIdleScan(tpAniSirGlobal pMac)
7680{
7681 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
7682 {
Agarwal Ashish5974ed32014-06-16 16:59:54 +05307683 if (vos_concurrent_open_sessions_running()) {
Jeff Johnson295189b2012-06-20 16:38:30 -07007684 return;
7685 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007686 smsLog(pMac, LOG1, " csrScanCancelIdleScan");
Jeff Johnson295189b2012-06-20 16:38:30 -07007687 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_TRUE;
7688 //Set the restart flag in case later on it is uncancelled
7689 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7690 csrScanStopIdleScanTimer(pMac);
7691 csrScanRemoveNotRoamingScanCommand(pMac);
7692 }
7693}
7694
7695
7696void csrScanIdleScanTimerHandler(void *pv)
7697{
7698 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
7699 eHalStatus status;
7700 tANI_U32 nTime = 0;
7701
7702 smsLog(pMac, LOGW, " csrScanIdleScanTimerHandler called ");
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07007703 pmcResetImpsFailStatus (pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07007704 status = csrScanTriggerIdleScan(pMac, &nTime);
7705 if(!HAL_STATUS_SUCCESS(status) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan))
7706 {
7707 //Check whether it is time to actually do an idle scan
7708 if(pMac->scan.nIdleScanTimeGap >= pMac->roam.configParam.impsSleepTime)
7709 {
7710 pMac->scan.nIdleScanTimeGap = 0;
7711 csrScanIMPSCallback(pMac, eHAL_STATUS_SUCCESS);
7712 }
7713 else
7714 {
7715 csrScanStartIdleScanTimer(pMac, nTime);
7716 }
7717 }
Rashmi Ramanna68b309c2014-05-20 11:52:22 +05307718 if(pMac->deferImps)
7719 {
7720 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7721 pMac->deferImps = eANI_BOOLEAN_FALSE;
7722 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007723}
7724
7725
7726
7727
7728tANI_BOOLEAN csrScanRemoveNotRoamingScanCommand(tpAniSirGlobal pMac)
7729{
7730 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
7731 tListElem *pEntry, *pEntryTmp;
7732 tSmeCmd *pCommand;
7733 tDblLinkList localList;
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307734 tDblLinkList *pCmdList;
Jeff Johnson295189b2012-06-20 16:38:30 -07007735
7736 vos_mem_zero(&localList, sizeof(tDblLinkList));
7737 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
7738 {
7739 smsLog(pMac, LOGE, FL(" failed to open list"));
7740 return fRet;
7741 }
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307742 if (!pMac->fScanOffload)
7743 pCmdList = &pMac->sme.smeCmdPendingList;
7744 else
7745 pCmdList = &pMac->sme.smeScanCmdPendingList;
Jeff Johnson295189b2012-06-20 16:38:30 -07007746
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307747 csrLLLock(pCmdList);
7748 pEntry = csrLLPeekHead(pCmdList, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007749 while(pEntry)
7750 {
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307751 pEntryTmp = csrLLNext(pCmdList, pEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007752 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7753 if( eSmeCommandScan == pCommand->command )
7754 {
7755 switch( pCommand->u.scanCmd.reason )
7756 {
7757 case eCsrScanIdleScan:
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307758 if( csrLLRemoveEntry(pCmdList, pEntry, LL_ACCESS_NOLOCK) )
Jeff Johnson295189b2012-06-20 16:38:30 -07007759 {
7760 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
7761 }
7762 fRet = eANI_BOOLEAN_TRUE;
7763 break;
7764
7765 default:
7766 break;
7767 } //switch
7768 }
7769 pEntry = pEntryTmp;
7770 }
7771
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307772 csrLLUnlock(pCmdList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007773
7774 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
7775 {
7776 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7777 csrReleaseCommandScan( pMac, pCommand );
7778 }
7779
7780 csrLLClose(&localList);
7781
7782 return (fRet);
7783}
7784
7785
7786tANI_BOOLEAN csrScanRemoveFreshScanCommand(tpAniSirGlobal pMac, tANI_U8 sessionId)
7787{
7788 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
7789 tListElem *pEntry, *pEntryTmp;
7790 tSmeCmd *pCommand;
7791 tDblLinkList localList;
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307792 tDblLinkList *pCmdList;
Jeff Johnson295189b2012-06-20 16:38:30 -07007793
7794 vos_mem_zero(&localList, sizeof(tDblLinkList));
7795 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
7796 {
7797 smsLog(pMac, LOGE, FL(" failed to open list"));
7798 return fRet;
7799 }
7800
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307801 if (!pMac->fScanOffload)
7802 pCmdList = &pMac->sme.smeCmdPendingList;
7803 else
7804 pCmdList = &pMac->sme.smeScanCmdPendingList;
7805
7806 csrLLLock(pCmdList);
7807 pEntry = csrLLPeekHead(pCmdList, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007808 while(pEntry)
7809 {
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307810 pEntryTmp = csrLLNext(pCmdList, pEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007811 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7812 if( (eSmeCommandScan == pCommand->command) && (sessionId == pCommand->sessionId) )
7813 {
7814 switch(pCommand->u.scanCmd.reason)
7815 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07007816#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
7817 case eCsrScanGetLfrResult:
7818#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07007819 case eCsrScanGetResult:
7820 case eCsrScanSetBGScanParam:
7821 case eCsrScanBGScanAbort:
7822 case eCsrScanBGScanEnable:
7823 case eCsrScanGetScanChnInfo:
7824 break;
7825 default:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007826 smsLog (pMac, LOGW, "%s: -------- abort scan command reason = %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007827 __func__, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07007828 //The rest are fresh scan requests
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307829 if( csrLLRemoveEntry(pCmdList, pEntry, LL_ACCESS_NOLOCK) )
Jeff Johnson295189b2012-06-20 16:38:30 -07007830 {
7831 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
7832 }
7833 fRet = eANI_BOOLEAN_TRUE;
7834 break;
7835 }
7836 }
7837 pEntry = pEntryTmp;
7838 }
7839
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307840 csrLLUnlock(pCmdList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007841
7842 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
7843 {
7844 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7845 if (pCommand->u.scanCmd.callback)
7846 {
7847 /* User scan request is pending,
7848 * send response with status eCSR_SCAN_ABORT*/
7849 pCommand->u.scanCmd.callback(pMac,
7850 pCommand->u.scanCmd.pContext,
7851 pCommand->u.scanCmd.scanID,
7852 eCSR_SCAN_ABORT);
7853 }
7854 csrReleaseCommandScan( pMac, pCommand );
7855 }
7856 csrLLClose(&localList);
7857
7858 return (fRet);
7859}
7860
7861
7862void csrReleaseScanCommand(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
7863{
7864 eCsrScanReason reason = pCommand->u.scanCmd.reason;
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307865 tANI_BOOLEAN status;
7866
7867 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07007868 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307869 tANI_U32 i;
7870 for(i = 0; i < CSR_ROAM_SESSION_MAX; i++)
Abhishek Singhf52182c2016-08-24 11:15:23 +05307871 csrRoamStateChange(pMac,
7872 pMac->roam.prev_state[i], i);
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307873 }
7874 else
7875 {
7876 csrRoamStateChange(pMac,
Abhishek Singhf52182c2016-08-24 11:15:23 +05307877 pMac->roam.prev_state[pCommand->sessionId],
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307878 pCommand->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07007879 }
7880
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307881 csrScanCallCallback(pMac, pCommand, scanStatus);
Jeff Johnson295189b2012-06-20 16:38:30 -07007882
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007883 smsLog(pMac, LOG3, " Remove Scan command reason = %d", reason);
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307884 if (pMac->fScanOffload)
7885 {
7886 status = csrLLRemoveEntry(&pMac->sme.smeScanCmdActiveList,
7887 &pCommand->Link, LL_ACCESS_LOCK);
7888 }
7889 else
7890 {
7891 status = csrLLRemoveEntry(&pMac->sme.smeCmdActiveList,
7892 &pCommand->Link, LL_ACCESS_LOCK);
7893 }
7894
7895 if(status)
Jeff Johnson295189b2012-06-20 16:38:30 -07007896 {
7897 csrReleaseCommandScan( pMac, pCommand );
7898 }
7899 else
7900 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307901 smsLog(pMac, LOGE,
7902 " ********csrReleaseScanCommand cannot release command reason %d",
7903 pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07007904 }
7905}
7906
7907
7908eHalStatus csrScanGetPMKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
7909 tPmkidCandidateInfo *pPmkidList, tANI_U32 *pNumItems )
7910{
7911 eHalStatus status = eHAL_STATUS_SUCCESS;
7912 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
7913
Jeff Johnson32d95a32012-09-10 13:15:23 -07007914 if(!pSession)
7915 {
7916 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
7917 return eHAL_STATUS_FAILURE;
7918 }
7919
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007920 smsLog(pMac, LOGW, " pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07007921 csrResetPMKIDCandidateList(pMac, sessionId);
7922 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
7923 {
7924 tCsrScanResultFilter *pScanFilter;
7925 tCsrScanResultInfo *pScanResult;
7926 tScanResultHandle hBSSList;
7927 tANI_U32 nItems = *pNumItems;
7928
7929 *pNumItems = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05307930 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
7931 if ( NULL == pScanFilter )
7932 status = eHAL_STATUS_FAILURE;
7933 else
Jeff Johnson295189b2012-06-20 16:38:30 -07007934 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307935 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007936 //Here is the profile we need to connect to
7937 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
7938 if(HAL_STATUS_SUCCESS(status))
7939 {
7940 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
7941 if(HAL_STATUS_SUCCESS(status))
7942 {
7943 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumPmkidCandidate < nItems))
7944 {
7945 //NumPmkidCandidate adds up here
7946 csrProcessBSSDescForPMKIDList(pMac, &pScanResult->BssDescriptor,
7947 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
7948 }
7949 if(pSession->NumPmkidCandidate)
7950 {
7951 *pNumItems = pSession->NumPmkidCandidate;
Kiet Lam64c1b492013-07-12 13:56:44 +05307952 vos_mem_copy(pPmkidList, pSession->PmkidCandidateInfo,
7953 pSession->NumPmkidCandidate * sizeof(tPmkidCandidateInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07007954 }
7955 csrScanResultPurge(pMac, hBSSList);
7956 }//Have scan result
7957 csrFreeScanFilter(pMac, pScanFilter);
7958 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307959 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07007960 }
7961 }
7962
7963 return (status);
7964}
7965
7966
7967
7968#ifdef FEATURE_WLAN_WAPI
7969eHalStatus csrScanGetBKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
7970 tBkidCandidateInfo *pBkidList, tANI_U32 *pNumItems )
7971{
7972 eHalStatus status = eHAL_STATUS_SUCCESS;
7973 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
7974
Jeff Johnson32d95a32012-09-10 13:15:23 -07007975 if(!pSession)
7976 {
7977 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
7978 return eHAL_STATUS_FAILURE;
7979 }
7980
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007981 smsLog(pMac, LOGW, " pMac->scan.NumBkidCandidate = %d", pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07007982 csrResetBKIDCandidateList(pMac, sessionId);
7983 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
7984 {
7985 tCsrScanResultFilter *pScanFilter;
7986 tCsrScanResultInfo *pScanResult;
7987 tScanResultHandle hBSSList;
7988 tANI_U32 nItems = *pNumItems;
7989 *pNumItems = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05307990 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
7991 if ( NULL == pScanFilter )
7992 status = eHAL_STATUS_FAILURE;
7993 else
Jeff Johnson295189b2012-06-20 16:38:30 -07007994 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307995 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007996 //Here is the profile we need to connect to
7997 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
7998 if(HAL_STATUS_SUCCESS(status))
7999 {
8000 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
8001 if(HAL_STATUS_SUCCESS(status))
8002 {
8003 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumBkidCandidate < nItems))
8004 {
8005 //pMac->scan.NumBkidCandidate adds up here
8006 csrProcessBSSDescForBKIDList(pMac, &pScanResult->BssDescriptor,
8007 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
8008
8009 }
8010 if(pSession->NumBkidCandidate)
8011 {
8012 *pNumItems = pSession->NumBkidCandidate;
Kiet Lam64c1b492013-07-12 13:56:44 +05308013 vos_mem_copy(pBkidList, pSession->BkidCandidateInfo, pSession->NumBkidCandidate * sizeof(tBkidCandidateInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07008014 }
8015 csrScanResultPurge(pMac, hBSSList);
8016 }//Have scan result
8017 }
Kiet Lam64c1b492013-07-12 13:56:44 +05308018 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07008019 }
8020 }
8021
8022 return (status);
8023}
8024#endif /* FEATURE_WLAN_WAPI */
8025
Selvaraj, Sridhar32417ed2016-06-22 15:19:12 +05308026/**
8027 * csr_scan_request_set_chan_time() - Populate max and min
8028 * channel time in Scan request
8029 * @pMac - pointer to mac context
8030 * @pScanCmd - pointer to the Scan command
8031 *
8032 * Return - None
8033 */
8034#ifndef QCA_WIFI_ISOC
8035static void csr_scan_request_set_chan_time(tpAniSirGlobal pMac,
8036 tSmeCmd *pScanCmd)
8037{
8038 if (pMac->roam.neighborRoamInfo.handoffReqInfo.src
8039 == FASTREASSOC) {
8040 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime
8041 = MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL_FASTREASSOC;
8042 pScanCmd->u.scanCmd.u.scanRequest.minChnTime
8043 = MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL_FASTREASSOC;
8044 pMac->roam.neighborRoamInfo.handoffReqInfo.src = 0;
8045 } else {
8046 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime
8047 = MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL;
8048 pScanCmd->u.scanCmd.u.scanRequest.minChnTime
8049 = MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL;
8050 }
8051}
8052#else
8053static void csr_scan_request_set_chan_time(tpAniSirGlobal pMac,
8054 tSmeCmd *pScanCmd)
8055{
8056 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime
8057 = MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL;
8058 pScanCmd->u.scanCmd.u.scanRequest.minChnTime
8059 = MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL;
8060}
8061#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07008062
Kapil Guptac46b7542016-10-25 13:03:20 +05308063/**
8064 * csr_ssid_scan_done_callback() - Callback to indicate
8065 * scan is done for ssid scan
8066 * @halHandle: handle to hal
8067 * @context: SSID scan context
8068 * @scanId: Scan id for the scheduled scan
8069 * @status: scan done status
8070 *
8071 * Return - eHalStatus
8072 */
8073static eHalStatus csr_ssid_scan_done_callback(tHalHandle halHandle,
8074 void *context,
8075 tANI_U32 scanId,
8076 eCsrScanStatus status)
8077{
8078 struct csr_scan_for_ssid_context *scan_context =
8079 (struct csr_scan_for_ssid_context *)context;
8080
Sreelakshmi Konamki5e329602016-11-21 12:02:44 +05308081 if (NULL == scan_context) {
Kapil Guptac46b7542016-10-25 13:03:20 +05308082 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR,
8083 FL("scan for ssid context not found"));
Sreelakshmi Konamki5e329602016-11-21 12:02:44 +05308084 return eHAL_STATUS_FAILURE;
8085 }
Kapil Guptac46b7542016-10-25 13:03:20 +05308086
8087 if (eCSR_SCAN_ABORT == status)
8088 csrRoamCallCallback(scan_context->pMac, scan_context->sessionId,
8089 NULL, scan_context->roamId,
8090 eCSR_ROAM_ASSOCIATION_FAILURE,
8091 eCSR_ROAM_RESULT_SCAN_FOR_SSID_FAILURE);
8092 vos_mem_free(scan_context);
8093 return eHAL_STATUS_SUCCESS;
8094}
8095
Jeff Johnson295189b2012-06-20 16:38:30 -07008096//This function is usually used for BSSs that suppresses SSID so the profile
8097//shall have one and only one SSID
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008098eHalStatus csrScanForSSID(tpAniSirGlobal pMac, tANI_U32 sessionId, tCsrRoamProfile *pProfile, tANI_U32 roamId, tANI_BOOLEAN notify)
Jeff Johnson295189b2012-06-20 16:38:30 -07008099{
8100 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
8101 tSmeCmd *pScanCmd = NULL;
8102 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
8103 tANI_U8 index = 0;
8104 tANI_U32 numSsid = pProfile->SSIDs.numOfSSIDs;
Kapil Guptac46b7542016-10-25 13:03:20 +05308105 struct csr_scan_for_ssid_context *context;
Jeff Johnson295189b2012-06-20 16:38:30 -07008106
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008107 smsLog(pMac, LOG2, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07008108 //For WDS, we use the index 0. There must be at least one in there
8109 if( CSR_IS_WDS_STA( pProfile ) && numSsid )
8110 {
8111 numSsid = 1;
8112 }
8113 if(pMac->scan.fScanEnable && ( numSsid == 1 ) )
8114 {
8115 do
8116 {
8117 pScanCmd = csrGetCommandBuffer(pMac);
8118 if(!pScanCmd)
8119 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008120 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07008121 break;
8122 }
Kiet Lam64c1b492013-07-12 13:56:44 +05308123 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
8124 pScanCmd->u.scanCmd.pToRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
8125 if ( NULL == pScanCmd->u.scanCmd.pToRoamProfile )
krunal soni587bf012014-02-04 12:35:11 -08008126 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308127 status = eHAL_STATUS_FAILURE;
krunal soni587bf012014-02-04 12:35:11 -08008128 }
Kiet Lam64c1b492013-07-12 13:56:44 +05308129 else
krunal soni587bf012014-02-04 12:35:11 -08008130 {
8131 status = csrRoamCopyProfile(pMac, pScanCmd->u.scanCmd.pToRoamProfile, pProfile);
8132 }
Kapil Guptac46b7542016-10-25 13:03:20 +05308133 context = vos_mem_malloc(sizeof(*context));
8134 if (NULL == context)
8135 {
8136 smsLog(pMac, LOGE,
8137 "Failed to allocate memory for ssid scan context");
8138 status = eHAL_STATUS_FAILED_ALLOC;
8139 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008140 if(!HAL_STATUS_SUCCESS(status))
8141 break;
Kapil Guptac46b7542016-10-25 13:03:20 +05308142 context->pMac = pMac;
8143 context->sessionId = sessionId;
8144 context->roamId = roamId;
Jeff Johnson295189b2012-06-20 16:38:30 -07008145 pScanCmd->u.scanCmd.roamId = roamId;
8146 pScanCmd->command = eSmeCommandScan;
Jeff Johnsone7245742012-09-05 17:12:55 -07008147 pScanCmd->sessionId = (tANI_U8)sessionId;
Kapil Guptac46b7542016-10-25 13:03:20 +05308148 pScanCmd->u.scanCmd.callback = csr_ssid_scan_done_callback;
8149 pScanCmd->u.scanCmd.pContext = context;
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008150 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 -07008151 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Kiet Lam64c1b492013-07-12 13:56:44 +05308152 vos_mem_set(&pScanCmd->u.scanCmd.u.scanRequest, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008153 pScanCmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Jeff Johnson295189b2012-06-20 16:38:30 -07008154 pScanCmd->u.scanCmd.u.scanRequest.BSSType = pProfile->BSSType;
Jeff Johnsone7245742012-09-05 17:12:55 -07008155 // To avoid 11b rate in probe request Set p2pSearch flag as 1 for P2P Client Mode
8156 if(VOS_P2P_CLIENT_MODE == pProfile->csrPersona)
8157 {
8158 pScanCmd->u.scanCmd.u.scanRequest.p2pSearch = 1;
8159 }
Agarwal Ashish4f616132013-12-30 23:32:50 +05308160 if(pProfile->nAddIEScanLength)
Jeff Johnsone7245742012-09-05 17:12:55 -07008161 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308162 pScanCmd->u.scanCmd.u.scanRequest.pIEField = vos_mem_malloc(
8163 pProfile->nAddIEScanLength);
8164 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.pIEField )
8165 status = eHAL_STATUS_FAILURE;
8166 else
8167 status = eHAL_STATUS_SUCCESS;
8168 vos_mem_set(pScanCmd->u.scanCmd.u.scanRequest.pIEField,
8169 pProfile->nAddIEScanLength, 0);
8170 if (HAL_STATUS_SUCCESS(status))
Jeff Johnsone7245742012-09-05 17:12:55 -07008171 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308172 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.pIEField,
Agarwal Ashish4f616132013-12-30 23:32:50 +05308173 pProfile->addIEScan, pProfile->nAddIEScanLength);
Jeff Johnsone7245742012-09-05 17:12:55 -07008174 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = pProfile->nAddIEScanLength;
8175 }
8176 else
8177 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008178 smsLog(pMac, LOGE, "No memory for scanning IE fields");
Jeff Johnsone7245742012-09-05 17:12:55 -07008179 }
8180 } //Allocate memory for IE field
8181 else
8182 {
8183 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = 0;
8184 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07008185 /* For one channel be good enpugh time to receive beacon atleast */
8186 if( 1 == pProfile->ChannelInfo.numOfChannels )
8187 {
Selvaraj, Sridhar32417ed2016-06-22 15:19:12 +05308188 csr_scan_request_set_chan_time(pMac, pScanCmd);
8189 } else {
Kiet Lam64c1b492013-07-12 13:56:44 +05308190 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime =
8191 pMac->roam.configParam.nActiveMaxChnTime;
8192 pScanCmd->u.scanCmd.u.scanRequest.minChnTime =
8193 pMac->roam.configParam.nActiveMinChnTime;
Jeff Johnson32d95a32012-09-10 13:15:23 -07008194 }
Abhishek Singhadd13582016-09-29 17:00:03 +05308195 pScanCmd->u.scanCmd.u.scanRequest.max_chntime_btc_esco =
8196 pMac->roam.configParam.max_chntime_btc_esco;
8197 pScanCmd->u.scanCmd.u.scanRequest.min_chntime_btc_esco =
8198 pMac->roam.configParam.min_chntime_btc_esco;
Jeff Johnson295189b2012-06-20 16:38:30 -07008199 if(pProfile->BSSIDs.numOfBSSIDs == 1)
8200 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308201 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.bssid,
8202 pProfile->BSSIDs.bssid, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07008203 }
8204 else
8205 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308206 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.bssid, bAddr, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07008207 }
8208 if(pProfile->ChannelInfo.numOfChannels)
8209 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308210 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(
8211 sizeof(*pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
8212 * pProfile->ChannelInfo.numOfChannels);
8213 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
8214 status = eHAL_STATUS_FAILURE;
8215 else
8216 status = eHAL_STATUS_SUCCESS;
8217 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
8218 if(HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07008219 {
8220 csrRoamIsChannelValid(pMac, pProfile->ChannelInfo.ChannelList[0]);
8221 for(index = 0; index < pProfile->ChannelInfo.numOfChannels; index++)
8222 {
8223 if(csrRoamIsValidChannel(pMac, pProfile->ChannelInfo.ChannelList[index]))
8224 {
8225 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels]
8226 = pProfile->ChannelInfo.ChannelList[index];
8227 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels++;
8228 }
8229 else
8230 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008231 smsLog(pMac, LOGW, FL("process a channel (%d) that is invalid"), pProfile->ChannelInfo.ChannelList[index]);
Jeff Johnson295189b2012-06-20 16:38:30 -07008232 }
8233
8234 }
8235 }
8236 else
8237 {
8238 break;
8239 }
8240
8241 }
8242 else
8243 {
8244 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
8245 }
8246 if(pProfile->SSIDs.numOfSSIDs)
8247 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308248 pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList = vos_mem_malloc(
8249 pProfile->SSIDs.numOfSSIDs * sizeof(tCsrSSIDInfo));
8250 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList )
8251 status = eHAL_STATUS_FAILURE;
8252 else
8253 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07008254 if(!HAL_STATUS_SUCCESS(status))
8255 {
8256 break;
8257 }
8258 pScanCmd->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 1;
Kiet Lam64c1b492013-07-12 13:56:44 +05308259 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList,
8260 pProfile->SSIDs.SSIDList, sizeof(tCsrSSIDInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07008261 }
8262 //Start process the command
8263 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
8264 if( !HAL_STATUS_SUCCESS( status ) )
8265 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008266 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07008267 break;
8268 }
8269 }while(0);
8270 if(!HAL_STATUS_SUCCESS(status))
8271 {
8272 if(pScanCmd)
8273 {
8274 csrReleaseCommandScan(pMac, pScanCmd);
8275 //TODO:free the memory that is allocated in this function
8276 }
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008277 if(notify)
8278 {
Jeff Johnson295189b2012-06-20 16:38:30 -07008279 csrRoamCallCallback(pMac, sessionId, NULL, roamId, eCSR_ROAM_FAILED, eCSR_ROAM_RESULT_FAILURE);
8280 }
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008281 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008282 }//valid
8283 else
8284 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008285 smsLog(pMac, LOGE, FL("cannot scan because scanEnable (%d) or numSSID (%d) is invalid"),
Jeff Johnson295189b2012-06-20 16:38:30 -07008286 pMac->scan.fScanEnable, pProfile->SSIDs.numOfSSIDs);
8287 }
8288
8289 return (status);
8290}
8291
8292
8293//Issue a scan base on the new capability infomation
8294//This should only happen when the associated AP changes its capability.
8295//After this scan is done, CSR reroams base on the new scan results
8296eHalStatus csrScanForCapabilityChange(tpAniSirGlobal pMac, tSirSmeApNewCaps *pNewCaps)
8297{
8298 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
8299 tSmeCmd *pScanCmd = NULL;
8300
8301 if(pNewCaps)
8302 {
8303 do
8304 {
8305 pScanCmd = csrGetCommandBuffer(pMac);
8306 if(!pScanCmd)
8307 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008308 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07008309 status = eHAL_STATUS_RESOURCES;
8310 break;
8311 }
Kiet Lam64c1b492013-07-12 13:56:44 +05308312 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008313 status = eHAL_STATUS_SUCCESS;
8314 pScanCmd->u.scanCmd.roamId = 0;
8315 pScanCmd->command = eSmeCommandScan;
8316 pScanCmd->u.scanCmd.callback = NULL;
8317 pScanCmd->u.scanCmd.pContext = NULL;
8318 pScanCmd->u.scanCmd.reason = eCsrScanForCapsChange;
8319 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
8320 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
8321 if( !HAL_STATUS_SUCCESS( status ) )
8322 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008323 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07008324 break;
8325 }
8326 }while(0);
8327 if(!HAL_STATUS_SUCCESS(status))
8328 {
8329 if(pScanCmd)
8330 {
8331 csrReleaseCommandScan(pMac, pScanCmd);
8332 }
8333 }
8334 }
8335
8336 return (status);
8337}
8338
8339
8340
8341void csrInitBGScanChannelList(tpAniSirGlobal pMac)
8342{
8343 tANI_U32 len = CSR_MIN(sizeof(pMac->roam.validChannelList), sizeof(pMac->scan.bgScanChannelList));
8344
Kiet Lam64c1b492013-07-12 13:56:44 +05308345 vos_mem_set(pMac->scan.bgScanChannelList, len, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008346 pMac->scan.numBGScanChannel = 0;
8347
8348 if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
8349 {
8350 pMac->roam.numValidChannels = len;
8351 pMac->scan.numBGScanChannel = (tANI_U8)CSR_MIN(len, WNI_CFG_BG_SCAN_CHANNEL_LIST_LEN);
Kiet Lam64c1b492013-07-12 13:56:44 +05308352 vos_mem_copy(pMac->scan.bgScanChannelList, pMac->roam.validChannelList,
8353 pMac->scan.numBGScanChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07008354 csrSetBGScanChannelList(pMac, pMac->scan.bgScanChannelList, pMac->scan.numBGScanChannel);
8355 }
8356}
8357
8358
8359//This function return TRUE if background scan channel list is adjusted.
8360//this function will only shrink the background scan channel list
8361tANI_BOOLEAN csrAdjustBGScanChannelList(tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels,
8362 tANI_U8 *pAdjustChannels, tANI_U8 *pNumAdjustChannels)
8363{
8364 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
8365 tANI_U8 i, j, count = *pNumAdjustChannels;
8366
8367 i = 0;
8368 while(i < count)
8369 {
8370 for(j = 0; j < NumChannels; j++)
8371 {
8372 if(pChannelList[j] == pAdjustChannels[i])
8373 break;
8374 }
8375 if(j == NumChannels)
8376 {
8377 //This channel is not in the list, remove it
8378 fRet = eANI_BOOLEAN_TRUE;
8379 count--;
8380 if(count - i)
8381 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308382 vos_mem_copy(&pAdjustChannels[i], &pAdjustChannels[i+1], count - i);
Jeff Johnson295189b2012-06-20 16:38:30 -07008383 }
8384 else
8385 {
8386 //already remove the last one. Done.
8387 break;
8388 }
8389 }
8390 else
8391 {
8392 i++;
8393 }
8394 }//while(i<count)
8395 *pNumAdjustChannels = count;
8396
8397 return (fRet);
8398}
8399
8400
8401//Get the list of the base channels to scan for passively 11d info
8402eHalStatus csrScanGetSupportedChannels( tpAniSirGlobal pMac )
8403{
8404 eHalStatus status = eHAL_STATUS_SUCCESS;
8405 int n = WNI_CFG_VALID_CHANNEL_LIST_LEN;
8406
8407 status = vos_nv_getSupportedChannels( pMac->scan.baseChannels.channelList, &n, NULL, NULL );
8408 if( HAL_STATUS_SUCCESS(status) )
8409 {
8410 pMac->scan.baseChannels.numChannels = (tANI_U8)n;
8411 }
8412 else
8413 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008414 smsLog( pMac, LOGE, FL(" failed") );
Jeff Johnson295189b2012-06-20 16:38:30 -07008415 pMac->scan.baseChannels.numChannels = 0;
8416 }
8417
8418 return ( status );
8419}
8420
8421//This function use the input pChannelList to validate the current saved channel list
8422eHalStatus csrSetBGScanChannelList( tpAniSirGlobal pMac, tANI_U8 *pAdjustChannels, tANI_U8 NumAdjustChannels)
8423{
8424 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumAdjustChannels;
8425
8426 return (ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pAdjustChannels, dataLen, NULL, eANI_BOOLEAN_FALSE));
8427}
8428
8429
8430void csrSetCfgValidChannelList( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels )
8431{
8432 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumChannels;
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05308433 eHalStatus status;
Jeff Johnson295189b2012-06-20 16:38:30 -07008434
Mihir Shete31c435d2014-02-12 13:13:34 +05308435 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
8436 "%s: dump valid channel list(NumChannels(%d))",
8437 __func__,NumChannels);
8438 VOS_TRACE_HEX_DUMP(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
8439 pChannelList, NumChannels);
8440
Jeff Johnson295189b2012-06-20 16:38:30 -07008441 ccmCfgSetStr(pMac, WNI_CFG_VALID_CHANNEL_LIST, pChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
Leela Venkata Kiran Kumar Reddy Chiralac6663f72014-02-03 21:04:58 -08008442#ifdef QCA_WIFI_2_0
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05308443 if (pMac->fScanOffload)
8444 {
8445 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
8446 "Scan offload is enabled, update default chan list");
Leela Venkata Kiran Kumar Reddy Chiralac6663f72014-02-03 21:04:58 -08008447 status = csrUpdateChannelList(pMac);
8448 }
8449#else
8450 status = csrUpdateChannelList(pMac);
8451#endif
8452
8453 if (eHAL_STATUS_SUCCESS != status)
8454 {
8455 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR,
8456 "failed to update the supported channel list");
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05308457 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008458 return;
8459}
8460
8461
8462
8463/*
8464 * The Tx power limits are saved in the cfg for future usage.
8465 */
8466void csrSaveTxPowerToCfg( tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 cfgId )
8467{
8468 tListElem *pEntry;
8469 tANI_U32 cbLen = 0, dataLen;
8470 tCsrChannelPowerInfo *pChannelSet;
8471 tANI_U32 idx;
8472 tSirMacChanInfo *pChannelPowerSet;
8473 tANI_U8 *pBuf = NULL;
8474
8475 //allocate maximum space for all channels
8476 dataLen = WNI_CFG_VALID_CHANNEL_LIST_LEN * sizeof(tSirMacChanInfo);
Kiet Lam64c1b492013-07-12 13:56:44 +05308477 if ( (pBuf = vos_mem_malloc(dataLen)) != NULL )
Jeff Johnson295189b2012-06-20 16:38:30 -07008478 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308479 vos_mem_set(pBuf, dataLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008480 pChannelPowerSet = (tSirMacChanInfo *)(pBuf);
8481
8482 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
8483 // write the tuples (startChan, numChan, txPower) for each channel found in the channel power list.
8484 while( pEntry )
8485 {
8486 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
8487 if ( 1 != pChannelSet->interChannelOffset )
8488 {
8489 // we keep the 5G channel sets internally with an interchannel offset of 4. Expand these
8490 // to the right format... (inter channel offset of 1 is the only option for the triplets
8491 // that 11d advertises.
8492 if ((cbLen + (pChannelSet->numChannels * sizeof(tSirMacChanInfo))) >= dataLen)
8493 {
8494 // expanding this entry will overflow our allocation
8495 smsLog(pMac, LOGE,
8496 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07008497 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07008498 pChannelSet->firstChannel,
8499 pChannelSet->numChannels,
8500 pChannelSet->interChannelOffset);
8501 break;
8502 }
8503
8504 for( idx = 0; idx < pChannelSet->numChannels; idx++ )
8505 {
8506 pChannelPowerSet->firstChanNum = (tSirMacChanNum)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008507 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07008508 pChannelPowerSet->numChannels = 1;
Jeff Johnson295189b2012-06-20 16:38:30 -07008509 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008510 smsLog(pMac, LOG3, " Setting Max Transmit Power %d", pChannelPowerSet->maxTxPower);
Jeff Johnson295189b2012-06-20 16:38:30 -07008511 cbLen += sizeof( tSirMacChanInfo );
8512 pChannelPowerSet++;
8513 }
8514 }
8515 else
8516 {
8517 if (cbLen >= dataLen)
8518 {
8519 // this entry will overflow our allocation
8520 smsLog(pMac, LOGE,
8521 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07008522 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07008523 pChannelSet->firstChannel,
8524 pChannelSet->numChannels,
8525 pChannelSet->interChannelOffset);
8526 break;
8527 }
8528 pChannelPowerSet->firstChanNum = pChannelSet->firstChannel;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008529 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07008530 pChannelPowerSet->numChannels = pChannelSet->numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -07008531 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008532 smsLog(pMac, LOG3, " Setting Max Transmit Power %d, nTxPower %d", pChannelPowerSet->maxTxPower,pMac->roam.configParam.nTxPowerCap );
Jeff Johnson295189b2012-06-20 16:38:30 -07008533
8534
8535 cbLen += sizeof( tSirMacChanInfo );
8536 pChannelPowerSet++;
8537 }
8538
8539 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
8540 }
8541
8542 if(cbLen)
8543 {
8544 ccmCfgSetStr(pMac, cfgId, (tANI_U8 *)pBuf, cbLen, NULL, eANI_BOOLEAN_FALSE);
8545 }
Kiet Lam64c1b492013-07-12 13:56:44 +05308546 vos_mem_free(pBuf);
Jeff Johnson295189b2012-06-20 16:38:30 -07008547 }//Allocate memory
8548}
8549
8550
8551void csrSetCfgCountryCode( tpAniSirGlobal pMac, tANI_U8 *countryCode )
8552{
8553 tANI_U8 cc[WNI_CFG_COUNTRY_CODE_LEN];
8554 ///v_REGDOMAIN_t DomainId;
8555
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008556 smsLog( pMac, LOG3, "Setting Country Code in Cfg from csrSetCfgCountryCode %s",countryCode );
Kiet Lam64c1b492013-07-12 13:56:44 +05308557 vos_mem_copy(cc, countryCode, WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07008558
8559 // don't program the bogus country codes that we created for Korea in the MAC. if we see
8560 // the bogus country codes, program the MAC with the right country code.
8561 if ( ( 'K' == countryCode[ 0 ] && '1' == countryCode[ 1 ] ) ||
8562 ( 'K' == countryCode[ 0 ] && '2' == countryCode[ 1 ] ) ||
8563 ( 'K' == countryCode[ 0 ] && '3' == countryCode[ 1 ] ) ||
8564 ( 'K' == countryCode[ 0 ] && '4' == countryCode[ 1 ] ) )
8565 {
8566 // replace the alternate Korea country codes, 'K1', 'K2', .. with 'KR' for Korea
8567 cc[ 1 ] = 'R';
8568 }
8569 ccmCfgSetStr(pMac, WNI_CFG_COUNTRY_CODE, cc, WNI_CFG_COUNTRY_CODE_LEN, NULL, eANI_BOOLEAN_FALSE);
8570
8571 //Need to let HALPHY know about the current domain so it can apply some
8572 //domain-specific settings (TX filter...)
8573 /*if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(pMac, cc, &DomainId)))
8574 {
8575 halPhySetRegDomain(pMac, DomainId);
8576 }*/
8577}
8578
8579
8580
8581eHalStatus csrGetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pBuf, tANI_U8 *pbLen)
8582{
8583 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
8584 tANI_U32 len;
8585
8586 if(pBuf && pbLen && (*pbLen >= WNI_CFG_COUNTRY_CODE_LEN))
8587 {
8588 len = *pbLen;
8589 status = ccmCfgGetStr(pMac, WNI_CFG_COUNTRY_CODE, pBuf, &len);
8590 if(HAL_STATUS_SUCCESS(status))
8591 {
8592 *pbLen = (tANI_U8)len;
8593 }
8594 }
8595
8596 return (status);
8597}
8598
8599
8600void csrSetCfgScanControlList( tpAniSirGlobal pMac, tANI_U8 *countryCode, tCsrChannel *pChannelList )
8601{
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05308602 tANI_U8 i, j, k;
Jeff Johnson295189b2012-06-20 16:38:30 -07008603 tANI_BOOLEAN found=FALSE;
8604 tANI_U8 *pControlList = NULL;
8605 tANI_U32 len = WNI_CFG_SCAN_CONTROL_LIST_LEN;
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05308606 tANI_U8 cfgActiveDFSChannels = 0;
8607 tANI_U8 *cfgActiveDFSChannelLIst = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07008608
Kiet Lam64c1b492013-07-12 13:56:44 +05308609 if ( (pControlList = vos_mem_malloc(WNI_CFG_SCAN_CONTROL_LIST_LEN)) != NULL )
Jeff Johnson295189b2012-06-20 16:38:30 -07008610 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308611 vos_mem_set((void *)pControlList, WNI_CFG_SCAN_CONTROL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008612 if(HAL_STATUS_SUCCESS(ccmCfgGetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, &len)))
8613 {
8614 for (i = 0; i < pChannelList->numChannels; i++)
8615 {
8616 for (j = 0; j < len; j += 2)
8617 {
8618 if (pControlList[j] == pChannelList->channelList[i])
8619 {
8620 found = TRUE;
8621 break;
8622 }
8623 }
8624
8625 if (found) // insert a pair(channel#, flag)
8626 {
Gopichand Nakkala392cbc12013-05-28 16:15:00 +05308627 pControlList[j+1] = csrGetScanType(pMac, pControlList[j]);
Jeff Johnson295189b2012-06-20 16:38:30 -07008628 found = FALSE; // reset the flag
Jeff Johnson295189b2012-06-20 16:38:30 -07008629
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05308630 // When DFS mode is 2, mark static channels as active
8631 if (pMac->scan.fEnableDFSChnlScan ==
8632 DFS_CHNL_SCAN_ENABLED_ACTIVE)
8633 {
8634 cfgActiveDFSChannels =
8635 pMac->roam.neighborRoamInfo.cfgParams.
8636 channelInfo.numOfChannels;
8637 cfgActiveDFSChannelLIst =
8638 pMac->roam.neighborRoamInfo.cfgParams.
8639 channelInfo.ChannelList;
8640 if (cfgActiveDFSChannelLIst)
8641 {
8642 for (k=0; k < cfgActiveDFSChannels; k++)
8643 {
8644 if(CSR_IS_CHANNEL_DFS(cfgActiveDFSChannelLIst[k])
8645 && (pControlList[j] ==
8646 cfgActiveDFSChannelLIst[k]))
8647 {
8648 pControlList[j+1] = eSIR_ACTIVE_SCAN;
8649 smsLog(pMac, LOG1, FL("Marked DFS ch %d"
8650 " as active"),
8651 cfgActiveDFSChannelLIst[k]);
8652 }
8653 }
8654 }
8655 }
8656 }
8657 }
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05308658 smsLog(pMac, LOG1, FL("fEnableDFSChnlScan %d"),
8659 pMac->scan.fEnableDFSChnlScan);
Mihir Shete31c435d2014-02-12 13:13:34 +05308660 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
8661 "%s: dump scan control list",__func__);
8662 VOS_TRACE_HEX_DUMP(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
8663 pControlList, len);
8664
Jeff Johnson295189b2012-06-20 16:38:30 -07008665 ccmCfgSetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, len, NULL, eANI_BOOLEAN_FALSE);
8666 }//Successfully getting scan control list
Kiet Lam64c1b492013-07-12 13:56:44 +05308667 vos_mem_free(pControlList);
Jeff Johnson295189b2012-06-20 16:38:30 -07008668 }//AllocateMemory
Abhishek Singh6fcdf652016-11-23 10:59:12 +05308669
8670 /* Send msg to Lim to clear DFS channel list */
8671 smsLog(pMac, LOG1, FL("csrClearDfsChannelList"));
8672 csrClearDfsChannelList(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07008673}
8674
Jeff Johnson295189b2012-06-20 16:38:30 -07008675//if bgPeriod is 0, background scan is disabled. It is in millisecond units
8676eHalStatus csrSetCfgBackgroundScanPeriod(tpAniSirGlobal pMac, tANI_U32 bgPeriod)
8677{
8678 return (ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, bgPeriod, (tCcmCfgSetCallback) csrScanCcmCfgSetCallback, eANI_BOOLEAN_FALSE));
8679}
8680
8681
8682void csrScanCcmCfgSetCallback(tHalHandle hHal, tANI_S32 result)
8683{
8684 tListElem *pEntry = NULL;
8685 tSmeCmd *pCommand = NULL;
8686 tpAniSirGlobal pMac = PMAC_STRUCT( hHal );
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05308687 tDblLinkList *pCmdList ;
8688
8689 if (!pMac->fScanOffload)
8690 pCmdList = &pMac->sme.smeCmdActiveList;
8691 else
8692 pCmdList = &pMac->sme.smeScanCmdActiveList;
8693
8694 pEntry = csrLLPeekHead( pCmdList, LL_ACCESS_LOCK );
Jeff Johnson295189b2012-06-20 16:38:30 -07008695 if ( pEntry )
8696 {
8697 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8698 if ( eSmeCommandScan == pCommand->command )
8699 {
8700 eCsrScanStatus scanStatus = (CCM_IS_RESULT_SUCCESS(result)) ? eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
8701 csrReleaseScanCommand(pMac, pCommand, scanStatus);
8702 }
8703 else
8704 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008705 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
Jeff Johnson295189b2012-06-20 16:38:30 -07008706 }
8707 }
8708 smeProcessPendingQueue( pMac );
8709}
8710
8711eHalStatus csrProcessSetBGScanParam(tpAniSirGlobal pMac, tSmeCmd *pCommand)
8712{
8713 eHalStatus status;
8714 tCsrBGScanRequest *pScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
8715 tANI_U32 dataLen = sizeof( tANI_U8 ) * pScanReq->ChannelInfo.numOfChannels;
8716
8717 //***setcfg for background scan channel list
8718 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MINIMUM_CHANNEL_TIME, pScanReq->minChnTime, NULL, eANI_BOOLEAN_FALSE);
8719 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MAXIMUM_CHANNEL_TIME, pScanReq->maxChnTime, NULL, eANI_BOOLEAN_FALSE);
8720 //Not set the background scan interval if not connected because bd scan should not be run if not connected
8721 if(!csrIsAllSessionDisconnected(pMac))
8722 {
Jeff Johnson295189b2012-06-20 16:38:30 -07008723
8724#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
8725 {
8726 vos_log_scan_pkt_type *pScanLog = NULL;
8727
8728 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
8729 if(pScanLog)
8730 {
8731 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
8732 pScanLog->minChnTime = (v_U8_t)pScanReq->minChnTime;
8733 pScanLog->maxChnTime = (v_U8_t)pScanReq->maxChnTime;
8734 pScanLog->timeBetweenBgScan = (v_U8_t)pScanReq->scanInterval;
8735 pScanLog->numChannel = pScanReq->ChannelInfo.numOfChannels;
8736 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
8737 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308738 vos_mem_copy(pScanLog->channels,
8739 pScanReq->ChannelInfo.ChannelList,
8740 pScanLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07008741 }
8742 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
8743 }
8744 }
8745#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
8746
8747 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, pScanReq->scanInterval, NULL, eANI_BOOLEAN_FALSE);
8748 }
8749 else
8750 {
8751 //No need to stop aging because IDLE scan is still running
8752 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, 0, NULL, eANI_BOOLEAN_FALSE);
8753 }
8754
8755 if(pScanReq->SSID.length > WNI_CFG_SSID_LEN)
8756 {
8757 pScanReq->SSID.length = WNI_CFG_SSID_LEN;
8758 }
8759
8760 status = ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pScanReq->ChannelInfo.ChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
8761 status = ccmCfgSetStr(pMac, WNI_CFG_SSID, (tANI_U8 *)pScanReq->SSID.ssId, pScanReq->SSID.length, NULL, eANI_BOOLEAN_FALSE);
8762
8763
8764
8765 return (status);
8766}
8767
8768
c_hpothua3d45d52015-01-05 14:11:17 +05308769tSirAbortScanStatus csrScanAbortMacScan(tpAniSirGlobal pMac,
8770 tANI_U8 sessionId,
8771 eCsrAbortReason reason)
Jeff Johnson295189b2012-06-20 16:38:30 -07008772{
c_hpothua3d45d52015-01-05 14:11:17 +05308773 tSirAbortScanStatus abortScanStatus = eSIR_ABORT_ACTIVE_SCAN_LIST_EMPTY;
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308774 tSirSmeScanAbortReq *pMsg;
Jeff Johnson295189b2012-06-20 16:38:30 -07008775 tANI_U16 msgLen;
8776 tListElem *pEntry;
8777 tSmeCmd *pCommand;
8778
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308779 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07008780 {
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308781#ifdef WLAN_AP_STA_CONCURRENCY
8782 csrLLLock(&pMac->scan.scanCmdPendingList);
8783 while(NULL !=
8784 (pEntry = csrLLRemoveHead(&pMac->scan.scanCmdPendingList,
8785 LL_ACCESS_NOLOCK)))
8786 {
Jeff Johnson295189b2012-06-20 16:38:30 -07008787
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308788 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8789 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
8790 }
8791 csrLLUnlock(&pMac->scan.scanCmdPendingList);
Jeff Johnson295189b2012-06-20 16:38:30 -07008792#endif
8793
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308794 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
8795 csrRemoveCmdFromPendingList( pMac, &pMac->roam.roamCmdPendingList, eSmeCommandScan);
8796 csrRemoveCmdFromPendingList( pMac, &pMac->sme.smeCmdPendingList, eSmeCommandScan);
8797 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
8798
8799 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
8800 }
8801 else
8802 {
8803 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
8804 csrRemoveCmdWithSessionIdFromPendingList(pMac,
8805 sessionId,
8806 &pMac->sme.smeScanCmdPendingList,
8807 eSmeCommandScan);
8808 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
8809
8810 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
8811 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008812
8813 //We need to abort scan only if we are scanning
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308814 if(NULL != pEntry)
Jeff Johnson295189b2012-06-20 16:38:30 -07008815 {
8816 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308817 if(eSmeCommandScan == pCommand->command &&
8818 pCommand->sessionId == sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07008819 {
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308820 msgLen = (tANI_U16)(sizeof(tSirSmeScanAbortReq));
Kiet Lam64c1b492013-07-12 13:56:44 +05308821 pMsg = vos_mem_malloc(msgLen);
8822 if ( NULL == pMsg )
Jeff Johnson295189b2012-06-20 16:38:30 -07008823 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308824 smsLog(pMac, LOGE, FL("Failed to allocate memory for SmeScanAbortReq"));
c_hpothua3d45d52015-01-05 14:11:17 +05308825 abortScanStatus = eSIR_ABORT_SCAN_FAILURE;
Kiet Lam64c1b492013-07-12 13:56:44 +05308826 }
8827 else
8828 {
Ratheesh S Pece1f832015-07-25 15:50:25 +05308829 pCommand->u.scanCmd.abortScanIndication = eCSR_SCAN_ABORT_DEFAULT;
Srinivas, Dasari187ca4e2014-02-07 12:40:09 +05308830 if(reason == eCSR_SCAN_ABORT_DUE_TO_BAND_CHANGE)
8831 {
Ratheesh S Pece1f832015-07-25 15:50:25 +05308832 pCommand->u.scanCmd.abortScanIndication
8833 = eCSR_SCAN_ABORT_DUE_TO_BAND_CHANGE;
Srinivas, Dasari187ca4e2014-02-07 12:40:09 +05308834 }
Kiet Lam64c1b492013-07-12 13:56:44 +05308835 vos_mem_set((void *)pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008836 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_ABORT_IND);
8837 pMsg->msgLen = pal_cpu_to_be16(msgLen);
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308838 pMsg->sessionId = sessionId;
c_hpothua3d45d52015-01-05 14:11:17 +05308839 if (eHAL_STATUS_SUCCESS != palSendMBMessage(pMac->hHdd, pMsg))
8840 {
8841 smsLog(pMac, LOGE,
8842 FL("Failed to post eWNI_SME_SCAN_ABORT_IND"));
8843 abortScanStatus = eSIR_ABORT_SCAN_FAILURE;
Ratheesh S Pece1f832015-07-25 15:50:25 +05308844 pCommand->u.scanCmd.abortScanIndication = 0;
c_hpothua3d45d52015-01-05 14:11:17 +05308845 }
8846 else
8847 {
8848 abortScanStatus = eSIR_ABORT_ACTIVE_SCAN_LIST_NOT_EMPTY;
8849 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008850 }
8851 }
8852 }
8853
c_hpothua3d45d52015-01-05 14:11:17 +05308854 return(abortScanStatus);
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308855}
8856
8857void csrRemoveCmdWithSessionIdFromPendingList(tpAniSirGlobal pMac,
8858 tANI_U8 sessionId,
8859 tDblLinkList *pList,
8860 eSmeCommandType commandType)
8861{
8862 tDblLinkList localList;
8863 tListElem *pEntry;
8864 tSmeCmd *pCommand;
8865 tListElem *pEntryToRemove;
8866
8867 vos_mem_zero(&localList, sizeof(tDblLinkList));
8868 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
8869 {
8870 smsLog(pMac, LOGE, FL(" failed to open list"));
8871 return;
8872 }
8873
8874 csrLLLock(pList);
8875 if ((pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK)))
8876 {
8877
8878 /* Have to make sure we don't loop back to the head of the list,
8879 * which will happen if the entry is NOT on the list */
8880 while (pEntry)
8881 {
8882 pEntryToRemove = pEntry;
8883 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
8884 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
8885 if ((pCommand->command == commandType) &&
8886 (pCommand->sessionId == sessionId))
8887 {
8888 /* Remove that entry only */
8889 if (csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
8890 {
8891 csrLLInsertTail(&localList, pEntryToRemove,
8892 LL_ACCESS_NOLOCK);
8893 }
8894 }
8895 }
8896 }
8897 csrLLUnlock(pList);
8898
8899 while ((pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)))
8900 {
8901 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
8902 csrAbortCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
8903 }
8904
8905 csrLLClose(&localList);
Jeff Johnson295189b2012-06-20 16:38:30 -07008906}
8907
8908void csrRemoveCmdFromPendingList(tpAniSirGlobal pMac, tDblLinkList *pList,
8909 eSmeCommandType commandType )
8910{
8911 tDblLinkList localList;
8912 tListElem *pEntry;
8913 tSmeCmd *pCommand;
8914 tListElem *pEntryToRemove;
8915
8916 vos_mem_zero(&localList, sizeof(tDblLinkList));
8917 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
8918 {
8919 smsLog(pMac, LOGE, FL(" failed to open list"));
8920 return;
8921 }
8922
8923 csrLLLock(pList);
8924 if( !csrLLIsListEmpty( pList, LL_ACCESS_NOLOCK ) )
8925 {
8926 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK);
8927
8928 // Have to make sure we don't loop back to the head of the list, which will
8929 // happen if the entry is NOT on the list...
8930 while( pEntry )
8931 {
8932 pEntryToRemove = pEntry;
8933 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
8934 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
8935 if ( pCommand->command == commandType )
8936 {
8937 // Remove that entry only
8938 if(csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
8939 {
8940 csrLLInsertTail(&localList, pEntryToRemove, LL_ACCESS_NOLOCK);
8941 }
8942 }
8943 }
8944
8945
8946 }
8947 csrLLUnlock(pList);
8948
8949 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
8950 {
8951 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8952 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
8953 }
8954 csrLLClose(&localList);
8955
8956}
8957
Abhishek Singhdc2bfd42014-06-19 17:59:05 +05308958eHalStatus csrScanAbortScanForSSID(tpAniSirGlobal pMac, tANI_U32 sessionId)
8959{
8960 eHalStatus status = eHAL_STATUS_SUCCESS;
8961 tSirSmeScanAbortReq *pMsg;
8962 tANI_U16 msgLen;
8963 tListElem *pEntry;
8964 tSmeCmd *pCommand;
8965
8966 if (!pMac->fScanOffload)
8967 {
8968 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
8969#ifdef WLAN_AP_STA_CONCURRENCY
8970 csrRemoveScanForSSIDFromPendingList( pMac, &pMac->scan.scanCmdPendingList, sessionId);
8971#endif
8972 csrRemoveScanForSSIDFromPendingList( pMac, &pMac->roam.roamCmdPendingList, sessionId);
8973 csrRemoveScanForSSIDFromPendingList( pMac, &pMac->sme.smeCmdPendingList, sessionId);
8974 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
8975 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
8976 }
8977 else
8978 {
8979 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
8980 csrRemoveScanForSSIDFromPendingList( pMac, &pMac->sme.smeScanCmdPendingList, sessionId);
8981 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
8982 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
8983 }
8984
8985 if(NULL != pEntry)
8986 {
8987 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8988
8989 if ( (eSmeCommandScan == pCommand->command ) &&
8990 (sessionId == pCommand->sessionId))
8991 {
8992 if ( eCsrScanForSsid == pCommand->u.scanCmd.reason)
8993 {
8994 msgLen = (tANI_U16)(sizeof( tSirSmeScanAbortReq ));
8995 pMsg = vos_mem_malloc(msgLen);
8996 if ( NULL == pMsg )
8997 {
8998 status = eHAL_STATUS_FAILURE;
8999 smsLog(pMac, LOGE, FL("Failed to allocate memory for SmeScanAbortReq"));
9000 }
9001 else
9002 {
9003 vos_mem_zero((void *)pMsg, msgLen);
9004 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_ABORT_IND);
9005 pMsg->msgLen = pal_cpu_to_be16(msgLen);
9006 pMsg->sessionId = sessionId;
9007 status = palSendMBMessage(pMac->hHdd, pMsg);
9008 }
9009 }
9010 }
9011 }
9012 return( status );
9013}
9014
9015void csrRemoveScanForSSIDFromPendingList(tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 sessionId)
9016{
9017 tDblLinkList localList;
9018 tListElem *pEntry;
9019 tSmeCmd *pCommand;
9020 tListElem *pEntryToRemove;
9021
9022 vos_mem_zero(&localList, sizeof(tDblLinkList));
9023 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
9024 {
9025 smsLog(pMac, LOGE, FL(" failed to open list"));
9026 return;
9027 }
9028
9029 csrLLLock(pList);
9030 if( !csrLLIsListEmpty( pList, LL_ACCESS_NOLOCK ) )
9031 {
9032 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK);
9033
9034 // Have to make sure we don't loop back to the head of the list, which will
9035 // happen if the entry is NOT on the list...
9036 while( pEntry )
9037 {
9038 pEntryToRemove = pEntry;
9039 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
9040 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
9041 if ( (eSmeCommandScan == pCommand->command ) &&
9042 (sessionId == pCommand->sessionId) )
9043 {
9044 if ( eCsrScanForSsid == pCommand->u.scanCmd.reason)
9045 {
9046 // Remove that entry only
9047 if ( csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
9048 {
9049 csrLLInsertTail(&localList, pEntryToRemove, LL_ACCESS_NOLOCK);
9050 }
9051 }
9052 }
9053 }
9054 }
9055 csrLLUnlock(pList);
9056
9057 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
9058 {
9059 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
9060 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
9061 }
9062 csrLLClose(&localList);
9063}
Jeff Johnson295189b2012-06-20 16:38:30 -07009064
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05309065eHalStatus csrScanAbortMacScanNotForConnect(tpAniSirGlobal pMac,
9066 tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07009067{
9068 eHalStatus status = eHAL_STATUS_SUCCESS;
9069
9070 if( !csrIsScanForRoamCommandActive( pMac ) )
9071 {
9072 //Only abort the scan if it is not used for other roam/connect purpose
c_hpothua3d45d52015-01-05 14:11:17 +05309073 if (eSIR_ABORT_SCAN_FAILURE ==
9074 csrScanAbortMacScan(pMac, sessionId, eCSR_SCAN_ABORT_DEFAULT))
9075 {
9076 smsLog(pMac, LOGE, FL("fail to abort scan"));
9077 status = eHAL_STATUS_FAILURE;
9078 }
Jeff Johnson295189b2012-06-20 16:38:30 -07009079 }
9080
9081 return (status);
9082}
9083
9084
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05309085eHalStatus csrScanGetScanChannelInfo(tpAniSirGlobal pMac, tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07009086{
9087 eHalStatus status = eHAL_STATUS_SUCCESS;
9088 tSirMbMsg *pMsg;
9089 tANI_U16 msgLen;
9090
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05309091 if (pMac->fScanOffload)
9092 msgLen = (tANI_U16)(sizeof(tSirSmeGetScanChanReq));
9093 else
9094 msgLen = (tANI_U16)(sizeof(tSirMbMsg));
9095
Kiet Lam64c1b492013-07-12 13:56:44 +05309096 pMsg = vos_mem_malloc(msgLen);
9097 if ( NULL == pMsg )
9098 status = eHAL_STATUS_FAILURE;
9099 else
Jeff Johnson295189b2012-06-20 16:38:30 -07009100 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309101 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07009102 pMsg->type = eWNI_SME_GET_SCANNED_CHANNEL_REQ;
9103 pMsg->msgLen = msgLen;
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05309104 if (pMac->fScanOffload)
9105 ((tSirSmeGetScanChanReq *)pMsg)->sessionId = sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07009106 status = palSendMBMessage(pMac->hHdd, pMsg);
9107 }
9108
9109 return( status );
9110}
9111
9112tANI_BOOLEAN csrRoamIsValidChannel( tpAniSirGlobal pMac, tANI_U8 channel )
9113{
9114 tANI_BOOLEAN fValid = FALSE;
9115 tANI_U32 idxValidChannels;
9116 tANI_U32 len = pMac->roam.numValidChannels;
9117
9118 for ( idxValidChannels = 0; ( idxValidChannels < len ); idxValidChannels++ )
9119 {
9120 if ( channel == pMac->roam.validChannelList[ idxValidChannels ] )
9121 {
9122 fValid = TRUE;
9123 break;
9124 }
9125 }
9126
9127 return fValid;
9128}
9129
Manjunathappa Prakash4f1d5a52013-11-11 16:22:19 -08009130#ifdef FEATURE_WLAN_SCAN_PNO
Srikant Kuppa066904f2013-05-07 13:56:02 -07009131eHalStatus csrScanSavePreferredNetworkFound(tpAniSirGlobal pMac,
9132 tSirPrefNetworkFoundInd *pPrefNetworkFoundInd)
9133{
9134 v_U32_t uLen = 0;
9135 tpSirProbeRespBeacon pParsedFrame;
9136 tCsrScanResult *pScanResult = NULL;
9137 tSirBssDescription *pBssDescr = NULL;
9138 tANI_BOOLEAN fDupBss;
9139 tDot11fBeaconIEs *pIesLocal = NULL;
9140 tAniSSID tmpSsid;
9141 v_TIME_t timer=0;
9142 tpSirMacMgmtHdr macHeader = (tpSirMacMgmtHdr)pPrefNetworkFoundInd->data;
Abhishek Singhd3d4e022014-11-11 13:02:40 +05309143 boolean bFoundonAppliedChannel = FALSE;
9144 v_U32_t indx;
9145 u8 channelsAllowed[WNI_CFG_VALID_CHANNEL_LIST_LEN];
9146 v_U32_t numChannelsAllowed = WNI_CFG_VALID_CHANNEL_LIST_LEN;
Sushant Kaushik6274de62015-05-01 16:31:23 +05309147 tListElem *pEntry;
Abhishek Singhd3d4e022014-11-11 13:02:40 +05309148
Srikant Kuppa066904f2013-05-07 13:56:02 -07009149
9150 pParsedFrame =
Abhishek Singhc75726d2015-04-13 14:44:14 +05309151 (tpSirProbeRespBeacon)vos_mem_vmalloc(sizeof(tSirProbeRespBeacon));
Srikant Kuppa066904f2013-05-07 13:56:02 -07009152
9153 if (NULL == pParsedFrame)
9154 {
9155 smsLog(pMac, LOGE, FL(" fail to allocate memory for frame"));
9156 return eHAL_STATUS_RESOURCES;
9157 }
9158
9159 if ( pPrefNetworkFoundInd->frameLength <= SIR_MAC_HDR_LEN_3A )
9160 {
9161 smsLog(pMac, LOGE,
9162 FL("Not enough bytes in PNO indication probe resp frame! length=%d"),
9163 pPrefNetworkFoundInd->frameLength);
Abhishek Singhc75726d2015-04-13 14:44:14 +05309164 vos_mem_vfree(pParsedFrame);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009165 return eHAL_STATUS_FAILURE;
9166 }
9167
9168 if (sirConvertProbeFrame2Struct(pMac,
9169 &pPrefNetworkFoundInd->data[SIR_MAC_HDR_LEN_3A],
9170 pPrefNetworkFoundInd->frameLength - SIR_MAC_HDR_LEN_3A,
9171 pParsedFrame) != eSIR_SUCCESS ||
9172 !pParsedFrame->ssidPresent)
9173 {
9174 smsLog(pMac, LOGE,
9175 FL("Parse error ProbeResponse, length=%d"),
9176 pPrefNetworkFoundInd->frameLength);
Abhishek Singhc75726d2015-04-13 14:44:14 +05309177 vos_mem_vfree(pParsedFrame);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009178 return eHAL_STATUS_FAILURE;
9179 }
9180 //24 byte MAC header and 12 byte to ssid IE
9181 if (pPrefNetworkFoundInd->frameLength >
9182 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET))
9183 {
9184 uLen = pPrefNetworkFoundInd->frameLength -
9185 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET);
9186 }
9187
Kiet Lam64c1b492013-07-12 13:56:44 +05309188 pScanResult = vos_mem_malloc(sizeof(tCsrScanResult) + uLen);
9189 if ( NULL == pScanResult )
Srikant Kuppa066904f2013-05-07 13:56:02 -07009190 {
9191 smsLog(pMac, LOGE, FL(" fail to allocate memory for frame"));
9192 vos_mem_free(pParsedFrame);
9193 return eHAL_STATUS_RESOURCES;
9194 }
9195
Kiet Lam64c1b492013-07-12 13:56:44 +05309196 vos_mem_set(pScanResult, sizeof(tCsrScanResult) + uLen, 0);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009197 pBssDescr = &pScanResult->Result.BssDescriptor;
9198 /**
9199 * Length of BSS desription is without length of
9200 * length itself and length of pointer
9201 * that holds the next BSS description
9202 */
9203 pBssDescr->length = (tANI_U16)(
Abhishek Singhbad2b322016-10-21 11:22:33 +05309204 ((uintptr_t)OFFSET_OF(tSirBssDescription, ieFields))
9205 - sizeof(pBssDescr->length) + uLen);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009206 if (pParsedFrame->dsParamsPresent)
9207 {
9208 pBssDescr->channelId = pParsedFrame->channelNumber;
9209 }
9210 else if (pParsedFrame->HTInfo.present)
9211 {
9212 pBssDescr->channelId = pParsedFrame->HTInfo.primaryChannel;
9213 }
9214 else
9215 {
Mahesh A Saptasagaradd99792014-03-26 16:04:20 +05309216 /**
9217 * If Probe Responce received in PNO indication does not
9218 * contain DSParam IE or HT Info IE then add dummy channel
9219 * to the received BSS info so that Scan result received as
9220 * a part of PNO is updated to the supplicant. Specially
9221 * applicable in case of AP configured in 11A only mode.
9222 */
9223 if ((pMac->roam.configParam.bandCapability == eCSR_BAND_ALL) ||
9224 (pMac->roam.configParam.bandCapability == eCSR_BAND_24))
9225 {
9226 pBssDescr->channelId = 1;
9227 }
9228 else if(pMac->roam.configParam.bandCapability == eCSR_BAND_5G)
9229 {
9230 pBssDescr->channelId = 36;
9231 }
Abhishek Singhd3d4e022014-11-11 13:02:40 +05309232 /* Restrict the logic to ignore the pno indication for invalid channel
9233 * only if valid channel info is present in beacon/probe resp.
9234 * If no channel info is present in beacon/probe resp, always process
9235 * the pno indication.
9236 */
9237 bFoundonAppliedChannel = TRUE;
9238 }
9239
9240 if (0 != sme_GetCfgValidChannels(pMac, channelsAllowed, &numChannelsAllowed))
9241 {
9242 smsLog(pMac, LOGE, FL(" sme_GetCfgValidChannels failed "));
9243 csrFreeScanResultEntry(pMac, pScanResult);
Abhishek Singhc75726d2015-04-13 14:44:14 +05309244 vos_mem_vfree(pParsedFrame);
Abhishek Singhd3d4e022014-11-11 13:02:40 +05309245 return eHAL_STATUS_FAILURE;
9246 }
9247 /* Checking chhanelId with allowed channel list */
9248 for (indx = 0; indx < numChannelsAllowed; indx++)
9249 {
9250 if (pBssDescr->channelId == channelsAllowed[indx])
9251 {
9252 bFoundonAppliedChannel = TRUE;
9253 smsLog(pMac, LOG1, FL(" pno ind found on applied channel =%d\n "),
9254 pBssDescr->channelId);
9255 break;
9256 }
9257 }
9258 /* Ignore PNO indication if AP is on Invalid channel.
9259 */
9260 if(FALSE == bFoundonAppliedChannel)
9261 {
9262 smsLog(pMac, LOGW, FL(" prefered network found on invalid channel = %d"),
9263 pBssDescr->channelId);
9264 csrFreeScanResultEntry(pMac, pScanResult);
Abhishek Singhc75726d2015-04-13 14:44:14 +05309265 vos_mem_vfree(pParsedFrame);
Abhishek Singhd3d4e022014-11-11 13:02:40 +05309266 return eHAL_STATUS_FAILURE;
Srikant Kuppa066904f2013-05-07 13:56:02 -07009267 }
9268
9269 if ((pBssDescr->channelId > 0) && (pBssDescr->channelId < 15))
9270 {
9271 int i;
9272 // 11b or 11g packet
9273 // 11g iff extended Rate IE is present or
9274 // if there is an A rate in suppRate IE
9275 for (i = 0; i < pParsedFrame->supportedRates.numRates; i++)
9276 {
9277 if (sirIsArate(pParsedFrame->supportedRates.rate[i] & 0x7f))
9278 {
9279 pBssDescr->nwType = eSIR_11G_NW_TYPE;
9280 break;
9281 }
9282 }
9283 if (pParsedFrame->extendedRatesPresent)
9284 {
9285 pBssDescr->nwType = eSIR_11G_NW_TYPE;
9286 }
9287 }
9288 else
9289 {
9290 // 11a packet
9291 pBssDescr->nwType = eSIR_11A_NW_TYPE;
9292 }
9293
9294 pBssDescr->sinr = 0;
9295 pBssDescr->rssi = -1 * pPrefNetworkFoundInd->rssi;
9296 pBssDescr->beaconInterval = pParsedFrame->beaconInterval;
AnjaneeDevi Kapparapu4b043912014-02-18 13:22:35 +05309297 if (!pBssDescr->beaconInterval)
9298 {
9299 smsLog(pMac, LOGW,
9300 FL("Bcn Interval is Zero , default to 100" MAC_ADDRESS_STR),
9301 MAC_ADDR_ARRAY(pBssDescr->bssId) );
9302 pBssDescr->beaconInterval = 100;
9303 }
Srikant Kuppa066904f2013-05-07 13:56:02 -07009304 pBssDescr->timeStamp[0] = pParsedFrame->timeStamp[0];
9305 pBssDescr->timeStamp[1] = pParsedFrame->timeStamp[1];
9306 pBssDescr->capabilityInfo = *((tANI_U16 *)&pParsedFrame->capabilityInfo);
Kiet Lam64c1b492013-07-12 13:56:44 +05309307 vos_mem_copy((tANI_U8 *) &pBssDescr->bssId, (tANI_U8 *) macHeader->bssId, sizeof(tSirMacAddr));
Deepthi Gowri4480a3f2016-05-18 19:30:17 +05309308 pBssDescr->nReceivedTime = vos_timer_get_system_time();
Srikant Kuppa066904f2013-05-07 13:56:02 -07009309
Sreelakshmi Konamki9866a8c2017-02-10 12:45:27 +05309310#ifdef WLAN_FEATURE_VOWIFI_11R
9311 // MobilityDomain
9312 pBssDescr->mdie[0] = 0;
9313 pBssDescr->mdie[1] = 0;
9314 pBssDescr->mdie[2] = 0;
9315 pBssDescr->mdiePresent = FALSE;
9316 // If mdie is present in the probe resp we fill it in the bss description
9317 if(pParsedFrame->mdiePresent)
9318 {
9319 pBssDescr->mdiePresent = TRUE;
9320 pBssDescr->mdie[0] = pParsedFrame->mdie[0];
9321 pBssDescr->mdie[1] = pParsedFrame->mdie[1];
9322 pBssDescr->mdie[2] = pParsedFrame->mdie[2];
9323 }
9324 smsLog(pMac, LOG1, FL("mdie=%02x%02x%02x"),
9325 (unsigned int)pBssDescr->mdie[0], (unsigned int)pBssDescr->mdie[1],
9326 (unsigned int)pBssDescr->mdie[2]);
9327#endif
9328
Abhishek Singh195c03e2014-05-14 17:21:30 +05309329 smsLog( pMac, LOG1, FL("Bssid= "MAC_ADDRESS_STR
9330 " chan= %d, rssi = %d "),
Arif Hussain24bafea2013-11-15 15:10:03 -08009331 MAC_ADDR_ARRAY(pBssDescr->bssId),
Srikant Kuppa066904f2013-05-07 13:56:02 -07009332 pBssDescr->channelId,
Abhishek Singh195c03e2014-05-14 17:21:30 +05309333 pBssDescr->rssi);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009334
9335 //IEs
9336 if (uLen)
9337 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309338 vos_mem_copy(&pBssDescr->ieFields,
9339 pPrefNetworkFoundInd->data + (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET),
9340 uLen);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009341 }
9342
9343 pIesLocal = (tDot11fBeaconIEs *)( pScanResult->Result.pvIes );
9344 if ( !pIesLocal &&
9345 (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
9346 &pScanResult->Result.BssDescriptor, &pIesLocal))) )
9347 {
9348 smsLog(pMac, LOGE, FL(" Cannot parse IEs"));
9349 csrFreeScanResultEntry(pMac, pScanResult);
Abhishek Singhc75726d2015-04-13 14:44:14 +05309350 vos_mem_vfree(pParsedFrame);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009351 return eHAL_STATUS_RESOURCES;
9352 }
9353
9354 fDupBss = csrRemoveDupBssDescription( pMac,
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05309355 &pScanResult->Result.BssDescriptor, pIesLocal, &tmpSsid, &timer, FALSE);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009356 //Check whether we have reach out limit
9357 if ( CSR_SCAN_IS_OVER_BSS_LIMIT(pMac) )
9358 {
9359 //Limit reach
9360 smsLog(pMac, LOGE, FL(" BSS limit reached"));
9361 //Free the resources
9362 if( (pScanResult->Result.pvIes == NULL) && pIesLocal )
9363 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309364 vos_mem_free(pIesLocal);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009365 }
9366 csrFreeScanResultEntry(pMac, pScanResult);
9367 vos_mem_free(pParsedFrame);
9368 return eHAL_STATUS_RESOURCES;
9369 }
Nalla Kartheek71946422015-09-15 14:41:22 +05309370
9371 if ((macHeader->fc.type == SIR_MAC_MGMT_FRAME) &&
9372 (macHeader->fc.subType == SIR_MAC_MGMT_PROBE_RSP))
9373 {
9374 pScanResult->Result.BssDescriptor.fProbeRsp = 1;
9375 }
Srikant Kuppa066904f2013-05-07 13:56:02 -07009376 //Add to scan cache
9377 csrScanAddResult(pMac, pScanResult, pIesLocal);
Sushant Kaushik6274de62015-05-01 16:31:23 +05309378 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
Kiet Lamb537cfb2013-11-07 12:56:49 +05309379 if( (pScanResult->Result.pvIes == NULL) && pIesLocal )
9380 {
9381 vos_mem_free(pIesLocal);
9382 }
9383
Abhishek Singhc75726d2015-04-13 14:44:14 +05309384 vos_mem_vfree(pParsedFrame);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009385
9386 return eHAL_STATUS_SUCCESS;
9387}
Manjunathappa Prakash4f1d5a52013-11-11 16:22:19 -08009388#endif //FEATURE_WLAN_SCAN_PNO
Srikant Kuppa066904f2013-05-07 13:56:02 -07009389
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08009390#ifdef FEATURE_WLAN_LFR
9391void csrInitOccupiedChannelsList(tpAniSirGlobal pMac)
9392{
9393 tListElem *pEntry = NULL;
9394 tCsrScanResult *pBssDesc = NULL;
9395 tDot11fBeaconIEs *pIes = NULL;
Srinivas28b5b4e2012-12-12 13:07:53 -08009396 tpCsrNeighborRoamControlInfo pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
9397
9398 if (0 != pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels)
9399 {
9400 smsLog(pMac, LOG1, FL("%s: Ini file contains neighbor scan channel list,"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08009401 " hence NO need to build occupied channel list (numChannels = %d)"),
Srinivas28b5b4e2012-12-12 13:07:53 -08009402 __func__, pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels);
9403 return;
9404 }
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08009405
9406 if (!csrNeighborRoamIsNewConnectedProfile(pMac))
9407 {
9408 smsLog(pMac, LOG2, FL("%s: donot flush occupied list since current roam profile"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08009409 " matches previous (numChannels = %d)"),
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08009410 __func__, pMac->scan.occupiedChannels.numChannels);
9411 return;
9412 }
9413
9414 /* Empty occupied channels here */
9415 pMac->scan.occupiedChannels.numChannels = 0;
9416
9417 csrLLLock(&pMac->scan.scanResultList);
9418 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
9419 while( pEntry )
9420 {
9421 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
9422 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
9423
9424 //At this time, pBssDescription->Result.pvIes may be NULL
Srikant Kuppa866893f2012-12-27 17:28:14 -08009425 if( !pIes && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08009426 &pBssDesc->Result.BssDescriptor, &pIes))) )
9427 {
9428 continue;
9429 }
9430
9431 csrScanAddToOccupiedChannels(pMac, pBssDesc, &pMac->scan.occupiedChannels, pIes);
9432
9433 /*
9434 * Free the memory allocated for pIes in csrGetParsedBssDescriptionIEs
9435 */
9436 if( (pBssDesc->Result.pvIes == NULL) && pIes )
9437 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309438 vos_mem_free(pIes);
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08009439 }
9440
9441 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK );
9442 }//while
9443 csrLLUnlock(&pMac->scan.scanResultList);
Srikant Kuppa866893f2012-12-27 17:28:14 -08009444
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08009445}
9446#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009447
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009448eHalStatus csrScanCreateEntryInScanCache(tpAniSirGlobal pMac, tANI_U32 sessionId,
9449 tCsrBssid bssid, tANI_U8 channel)
9450{
9451 eHalStatus status = eHAL_STATUS_SUCCESS;
9452 tDot11fBeaconIEs *pNewIes = NULL;
9453 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
Praveen Kumar Sirisilla8bdfac42013-10-10 17:20:48 -07009454 tSirBssDescription *pNewBssDescriptor = NULL;
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009455 tANI_U32 size = 0;
9456
9457 if(NULL == pSession)
9458 {
9459 status = eHAL_STATUS_FAILURE;
9460 return status;
9461 }
9462 smsLog(pMac, LOG2, FL("csrScanCreateEntryInScanCache: Current bssid::"
Arif Hussain24bafea2013-11-15 15:10:03 -08009463 MAC_ADDRESS_STR),
9464 MAC_ADDR_ARRAY(pSession->pConnectBssDesc->bssId));
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009465 smsLog(pMac, LOG2, FL("csrScanCreateEntryInScanCache: My bssid::"
Arif Hussain24bafea2013-11-15 15:10:03 -08009466 MAC_ADDRESS_STR" channel %d"),
9467 MAC_ADDR_ARRAY(bssid), channel);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009468
9469 do
9470 {
9471 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
9472 pSession->pConnectBssDesc, &pNewIes)))
9473 {
9474 smsLog(pMac, LOGE, FL("%s: Failed to parse IEs"),
9475 __func__);
9476 status = eHAL_STATUS_FAILURE;
9477 break;
9478 }
9479
9480 size = pSession->pConnectBssDesc->length + sizeof(pSession->pConnectBssDesc->length);
Kiet Lam64c1b492013-07-12 13:56:44 +05309481 if (size)
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009482 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309483 pNewBssDescriptor = vos_mem_malloc(size);
9484 if ( NULL == pNewBssDescriptor )
9485 status = eHAL_STATUS_FAILURE;
9486 else
9487 status = eHAL_STATUS_SUCCESS;
9488 if (HAL_STATUS_SUCCESS(status))
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009489 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309490 vos_mem_copy(pNewBssDescriptor, pSession->pConnectBssDesc, size);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009491 }
9492 else
9493 {
9494 smsLog(pMac, LOGE, FL("%s: memory allocation failed"),
9495 __func__);
9496 status = eHAL_STATUS_FAILURE;
9497 break;
9498 }
9499
9500 //change the BSSID & channel as passed
Kiet Lam64c1b492013-07-12 13:56:44 +05309501 vos_mem_copy(pNewBssDescriptor->bssId, bssid, sizeof(tSirMacAddr));
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009502 pNewBssDescriptor->channelId = channel;
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07009503 if(NULL == csrScanAppendBssDescription( pMac, pNewBssDescriptor, pNewIes, TRUE ))
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009504 {
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07009505 smsLog(pMac, LOGE, FL("%s: csrScanAppendBssDescription failed"),
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009506 __func__);
9507 status = eHAL_STATUS_FAILURE;
9508 break;
9509 }
9510 }
9511 else
9512 {
9513 smsLog(pMac, LOGE, FL("%s: length of bss descriptor is 0"),
9514 __func__);
9515 status = eHAL_STATUS_FAILURE;
9516 break;
9517 }
9518 smsLog(pMac, LOGE, FL("%s: entry successfully added in scan cache"),
9519 __func__);
9520 }while(0);
9521
9522 if(pNewIes)
9523 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309524 vos_mem_free(pNewIes);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009525 }
9526 if(pNewBssDescriptor)
9527 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309528 vos_mem_free(pNewBssDescriptor);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009529 }
9530 return status;
9531}
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07009532
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08009533#ifdef FEATURE_WLAN_ESE
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07009534// Update the TSF with the difference in system time
9535void UpdateCCKMTSF(tANI_U32 *timeStamp0, tANI_U32 *timeStamp1, tANI_U32 *incr)
9536{
9537 tANI_U64 timeStamp64 = ((tANI_U64)*timeStamp1 << 32) | (*timeStamp0);
9538
9539 timeStamp64 = (tANI_U64)(timeStamp64 + (tANI_U64)*incr);
9540 *timeStamp0 = (tANI_U32)(timeStamp64 & 0xffffffff);
9541 *timeStamp1 = (tANI_U32)((timeStamp64 >> 32) & 0xffffffff);
9542}
9543#endif
Deepthi Gowriecc93352016-11-09 16:58:47 +05309544
9545void csrValidateScanChannels(tpAniSirGlobal pMac, tCsrScanRequest *pDstReq,
Nishank Aggarwal42f76502017-02-16 12:00:19 +05309546 tCsrScanRequest *pSrcReq, tANI_U32 *new_index, tANI_U8 ch144_support)
Deepthi Gowriecc93352016-11-09 16:58:47 +05309547{
9548
9549 int index;
9550 for ( index = 0; index < pSrcReq->ChannelInfo.
9551 numOfChannels ; index++ )
9552 {
9553 /* Skip CH 144 if firmware support not present */
9554 if (pSrcReq->ChannelInfo.ChannelList[index] == 144 && !ch144_support)
9555 continue;
9556
9557 /* Allow scan on valid channels only.
9558 */
9559 if ( ( csrRoamIsValidChannel(pMac,
9560 pSrcReq->ChannelInfo.ChannelList[index]) ) )
9561 {
9562 if( ((pSrcReq->skipDfsChnlInP2pSearch ||
9563 (pMac->scan.fEnableDFSChnlScan ==
9564 DFS_CHNL_SCAN_DISABLED)) &&
9565 (NV_CHANNEL_DFS == vos_nv_getChannelEnabledState(
9566 pSrcReq->ChannelInfo.ChannelList[index])) &&
9567 (pSrcReq->ChannelInfo.numOfChannels > 1))
9568#ifdef FEATURE_WLAN_LFR
9569 /*
9570 * If LFR is requesting a contiguous scan
9571 * (i.e. numOfChannels > 1), then ignore
9572 * DFS channels.
9573 * TODO: vos_nv_getChannelEnabledState is returning
9574 * 120, 124 and 128 as non-DFS channels. Hence, the
9575 * use of direct check for channels below.
9576 */
9577 || ((eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType) &&
9578 (pSrcReq->ChannelInfo.numOfChannels > 1) &&
9579 (CSR_IS_CHANNEL_DFS(
9580 pSrcReq->ChannelInfo.ChannelList[index])) &&
9581 !pMac->roam.configParam.allowDFSChannelRoam)
9582#endif
9583 )
9584 {
9585#ifdef FEATURE_WLAN_LFR
9586 smsLog(pMac, LOG1,
9587 FL(" reqType=%s (%d), numOfChannels=%d,"
9588 " ignoring DFS channel:%d"),
9589 sme_requestTypetoString(pSrcReq->requestType),
9590 pSrcReq->requestType,
9591 pSrcReq->ChannelInfo.numOfChannels,
9592 pSrcReq->ChannelInfo.ChannelList[index]);
9593#endif
9594 continue;
9595 }
9596
Nishank Aggarwal42f76502017-02-16 12:00:19 +05309597 pDstReq->ChannelInfo.ChannelList[*new_index] =
Deepthi Gowriecc93352016-11-09 16:58:47 +05309598 pSrcReq->ChannelInfo.ChannelList[index];
Nishank Aggarwal42f76502017-02-16 12:00:19 +05309599 (*new_index)++;
Deepthi Gowriecc93352016-11-09 16:58:47 +05309600 }
9601 }
9602}