blob: 4eba38dc90a152013c40e8c441b78ce48978da56 [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Abhishek Singha2649232016-01-20 15:52:05 +05302 * Copyright (c) 2011-2016 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
Jeff Johnson32d95a32012-09-10 13:15:23 -070091#define MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL 140
92#define MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL 120
Selvaraj, Sridhar32417ed2016-06-22 15:19:12 +053093
94#ifndef QCA_WIFI_ISOC
95#define MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL_FASTREASSOC 30
96#define MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL_FASTREASSOC 20
97#endif
98
Madan Mohan Koyyalamudia53c4dc2012-11-13 10:35:42 -080099#define CSR_SCAN_OVERALL_SCORE( rssi ) \
100 (( rssi < CSR_SCAN_MAX_SCORE_VAL ) \
101 ? (CSR_SCAN_MAX_SCORE_VAL-rssi) : CSR_SCAN_MIN_SCORE_VAL)
Jeff Johnson295189b2012-06-20 16:38:30 -0700102
103
104#define CSR_SCAN_IS_OVER_BSS_LIMIT(pMac) \
105 ( (pMac)->scan.nBssLimit <= (csrLLCount(&(pMac)->scan.scanResultList)) )
106
Sushant Kaushikf4e085e2014-06-17 16:07:33 +0530107#define THIRTY_PERCENT(x) (x*30/100);
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +0530108
krunal soni5f112f02013-11-25 15:00:11 -0800109#define MANDATORY_BG_CHANNEL 11
110
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -0800111#ifndef CONFIG_ENABLE_LINUX_REG
Sushant Kaushikf4e085e2014-06-17 16:07:33 +0530112tCsrIgnoreChannels countryIgnoreList[MAX_COUNTRY_IGNORE] = {
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +0530113 { {'U','A'}, { 136, 140}, 2},
114 { {'T','W'}, { 36, 40, 44, 48, 52}, 5},
Madan Mohan Koyyalamudi28dd0422013-08-12 15:06:21 +0530115 { {'I','D'}, { 165}, 1 },
Wilson Yange3d2b292013-10-09 00:35:43 -0700116 { {'A','U'}, { 120, 124, 128}, 3 },
Wilson Yangce31eaf2013-11-11 14:40:34 -0800117 { {'A','R'}, { 120, 124, 128}, 3 }
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +0530118 };
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -0800119#else
Sushant Kaushikf4e085e2014-06-17 16:07:33 +0530120tCsrIgnoreChannels countryIgnoreList[MAX_COUNTRY_IGNORE] = { };
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -0800121#endif //CONFIG_ENABLE_LINUX_REG
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +0530122
Jeff Johnson295189b2012-06-20 16:38:30 -0700123//*** This is temporary work around. It need to call CCM api to get to CFG later
124/// Get string parameter value
125extern tSirRetStatus wlan_cfgGetStr(tpAniSirGlobal, tANI_U16, tANI_U8*, tANI_U32*);
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +0530126
Jeff Johnson295189b2012-06-20 16:38:30 -0700127void csrScanGetResultTimerHandler(void *);
Padma, Santhosh Kumar36183352016-11-08 17:48:34 +0530128void csr_handle_disable_scan(void *pv);
Deepthi Gowri6a08e312016-03-31 19:10:14 +0530129static void csrPurgeScanResultByAge(void *pv);
Jeff Johnson295189b2012-06-20 16:38:30 -0700130void csrScanIdleScanTimerHandler(void *);
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700131static void csrSetDefaultScanTiming( tpAniSirGlobal pMac, tSirScanType scanType, tCsrScanRequest *pScanRequest);
Jeff Johnson295189b2012-06-20 16:38:30 -0700132#ifdef WLAN_AP_STA_CONCURRENCY
133static void csrStaApConcTimerHandler(void *);
134#endif
Jeff Johnsone7245742012-09-05 17:12:55 -0700135tANI_BOOLEAN csrIsSupportedChannel(tpAniSirGlobal pMac, tANI_U8 channelId);
Jeff Johnson295189b2012-06-20 16:38:30 -0700136eHalStatus csrScanChannels( tpAniSirGlobal pMac, tSmeCmd *pCommand );
137void csrSetCfgValidChannelList( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels );
138void csrSaveTxPowerToCfg( tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 cfgId );
139void csrSetCfgCountryCode( tpAniSirGlobal pMac, tANI_U8 *countryCode );
140void csrPurgeChannelPower( tpAniSirGlobal pMac, tDblLinkList *pChannelList );
141//if bgPeriod is 0, background scan is disabled. It is in millisecond units
142eHalStatus csrSetCfgBackgroundScanPeriod(tpAniSirGlobal pMac, tANI_U32 bgPeriod);
143eHalStatus csrProcessSetBGScanParam(tpAniSirGlobal pMac, tSmeCmd *pCommand);
144void csrReleaseScanCommand(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus);
145static tANI_BOOLEAN csrScanValidateScanResult( tpAniSirGlobal pMac, tANI_U8 *pChannels,
146 tANI_U8 numChn, tSirBssDescription *pBssDesc,
147 tDot11fBeaconIEs **ppIes );
148eHalStatus csrSetBGScanChannelList( tpAniSirGlobal pMac, tANI_U8 *pAdjustChannels, tANI_U8 NumAdjustChannels);
149void csrReleaseCmdSingle(tpAniSirGlobal pMac, tSmeCmd *pCommand);
150tANI_BOOLEAN csrRoamIsValidChannel( tpAniSirGlobal pMac, tANI_U8 channel );
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700151void csrPruneChannelListForMode( tpAniSirGlobal pMac, tCsrChannel *pChannelList );
Deepthi Gowri50e2fa52016-03-17 15:30:53 +0530152void csrPurgeOldScanResults(tpAniSirGlobal pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -0700153
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -0700154
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -0700155
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -0700156
Madan Mohan Koyyalamudi923c1e12012-11-30 17:53:27 -0800157static void csrReleaseScanCmdPendingList(tpAniSirGlobal pMac)
158{
159 tListElem *pEntry;
160 tSmeCmd *pCommand;
161
162 while((pEntry = csrLLRemoveHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK)) != NULL)
163 {
164 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
165 if ( eSmeCsrCommandMask & pCommand->command )
166 {
167 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_TRUE );
168 }
169 else
170 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800171 smsLog(pMac, LOGE, FL("Error: Received command : %d"),pCommand->command);
Madan Mohan Koyyalamudi923c1e12012-11-30 17:53:27 -0800172 }
173 }
174}
Jeff Johnson295189b2012-06-20 16:38:30 -0700175//pResult is invalid calling this function.
176void csrFreeScanResultEntry( tpAniSirGlobal pMac, tCsrScanResult *pResult )
177{
178 if( NULL != pResult->Result.pvIes )
179 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530180 vos_mem_free(pResult->Result.pvIes);
Jeff Johnson295189b2012-06-20 16:38:30 -0700181 }
Kiet Lam64c1b492013-07-12 13:56:44 +0530182 vos_mem_free(pResult);
Jeff Johnson295189b2012-06-20 16:38:30 -0700183}
184
185
186static eHalStatus csrLLScanPurgeResult(tpAniSirGlobal pMac, tDblLinkList *pList)
187{
188 eHalStatus status = eHAL_STATUS_SUCCESS;
189 tListElem *pEntry;
190 tCsrScanResult *pBssDesc;
191
192 csrLLLock(pList);
193
194 while((pEntry = csrLLRemoveHead(pList, LL_ACCESS_NOLOCK)) != NULL)
195 {
196 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
197 csrFreeScanResultEntry( pMac, pBssDesc );
198 }
199
200 csrLLUnlock(pList);
201
202 return (status);
203}
204
Jeff Johnson295189b2012-06-20 16:38:30 -0700205eHalStatus csrScanOpen( tpAniSirGlobal pMac )
206{
207 eHalStatus status;
208
209 do
210 {
211 csrLLOpen(pMac->hHdd, &pMac->scan.scanResultList);
212 csrLLOpen(pMac->hHdd, &pMac->scan.tempScanResults);
213 csrLLOpen(pMac->hHdd, &pMac->scan.channelPowerInfoList24);
214 csrLLOpen(pMac->hHdd, &pMac->scan.channelPowerInfoList5G);
215#ifdef WLAN_AP_STA_CONCURRENCY
216 csrLLOpen(pMac->hHdd, &pMac->scan.scanCmdPendingList);
217#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700218 pMac->scan.fFullScanIssued = eANI_BOOLEAN_FALSE;
219 pMac->scan.nBssLimit = CSR_MAX_BSS_SUPPORT;
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530220 status = vos_timer_init(&pMac->scan.hTimerGetResult, VOS_TIMER_TYPE_SW, csrScanGetResultTimerHandler, pMac);
221 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700222 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800223 smsLog(pMac, LOGE, FL("cannot allocate memory for getResult timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700224 break;
225 }
226#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530227 status = vos_timer_init(&pMac->scan.hTimerStaApConcTimer, VOS_TIMER_TYPE_SW, csrStaApConcTimerHandler, pMac);
228 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700229 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800230 smsLog(pMac, LOGE, FL("cannot allocate memory for hTimerStaApConcTimer timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700231 break;
232 }
233#endif
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530234 status = vos_timer_init(&pMac->scan.hTimerIdleScan, VOS_TIMER_TYPE_SW, csrScanIdleScanTimerHandler, pMac);
235 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700236 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800237 smsLog(pMac, LOGE, FL("cannot allocate memory for idleScan timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700238 break;
239 }
Padma, Santhosh Kumar36183352016-11-08 17:48:34 +0530240 status = vos_timer_init(&pMac->scan.disable_scan_during_sco_timer,
241 VOS_TIMER_TYPE_SW,
242 csr_handle_disable_scan,
243 pMac);
244 if (!HAL_STATUS_SUCCESS(status)) {
245 smsLog(pMac, LOGE,
246 FL("cannot allocate memory for disable_scan_during_sco_timer"));
247 break;
248 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700249 }while(0);
250
251 return (status);
252}
253
254
255eHalStatus csrScanClose( tpAniSirGlobal pMac )
256{
Jeff Johnson295189b2012-06-20 16:38:30 -0700257 csrLLScanPurgeResult(pMac, &pMac->scan.tempScanResults);
258 csrLLScanPurgeResult(pMac, &pMac->scan.scanResultList);
259#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudi923c1e12012-11-30 17:53:27 -0800260 csrReleaseScanCmdPendingList(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -0700261#endif
262 csrLLClose(&pMac->scan.scanResultList);
263 csrLLClose(&pMac->scan.tempScanResults);
264#ifdef WLAN_AP_STA_CONCURRENCY
265 csrLLClose(&pMac->scan.scanCmdPendingList);
266#endif
267 csrPurgeChannelPower(pMac, &pMac->scan.channelPowerInfoList24);
268 csrPurgeChannelPower(pMac, &pMac->scan.channelPowerInfoList5G);
269 csrLLClose(&pMac->scan.channelPowerInfoList24);
270 csrLLClose(&pMac->scan.channelPowerInfoList5G);
271 csrScanDisable(pMac);
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530272 vos_timer_destroy(&pMac->scan.hTimerGetResult);
Jeff Johnson295189b2012-06-20 16:38:30 -0700273#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530274 vos_timer_destroy(&pMac->scan.hTimerStaApConcTimer);
Jeff Johnson295189b2012-06-20 16:38:30 -0700275#endif
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530276 vos_timer_destroy(&pMac->scan.hTimerIdleScan);
Padma, Santhosh Kumar36183352016-11-08 17:48:34 +0530277 vos_timer_destroy(&pMac->scan.disable_scan_during_sco_timer);
Jeff Johnson295189b2012-06-20 16:38:30 -0700278 return eHAL_STATUS_SUCCESS;
279}
280
281
282eHalStatus csrScanEnable( tpAniSirGlobal pMac )
283{
284
285 pMac->scan.fScanEnable = eANI_BOOLEAN_TRUE;
286 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
287
288 return eHAL_STATUS_SUCCESS;
289}
290
291
292eHalStatus csrScanDisable( tpAniSirGlobal pMac )
293{
294
295 csrScanStopTimers(pMac);
296 pMac->scan.fScanEnable = eANI_BOOLEAN_FALSE;
297
298 return eHAL_STATUS_SUCCESS;
299}
300
301
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700302//Set scan timing parameters according to state of other driver sessions
303//No validation of the parameters is performed.
304static void csrSetDefaultScanTiming( tpAniSirGlobal pMac, tSirScanType scanType, tCsrScanRequest *pScanRequest)
305{
306#ifdef WLAN_AP_STA_CONCURRENCY
307 if(csrIsAnySessionConnected(pMac))
308 {
Sushant Kaushika6fef4b2014-09-24 16:17:08 +0530309 //Reset passive scan time as per ini parameter.
Abhishek Singh7fb7dc12014-11-06 17:44:05 +0530310 ccmCfgSetInt(pMac, WNI_CFG_PASSIVE_MAXIMUM_CHANNEL_TIME,
Sushant Kaushika6fef4b2014-09-24 16:17:08 +0530311 pMac->roam.configParam.nPassiveMaxChnTimeConc,
312 NULL,eANI_BOOLEAN_FALSE);
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700313 //If multi-session, use the appropriate default scan times
314 if(scanType == eSIR_ACTIVE_SCAN)
315 {
316 pScanRequest->maxChnTime = pMac->roam.configParam.nActiveMaxChnTimeConc;
317 pScanRequest->minChnTime = pMac->roam.configParam.nActiveMinChnTimeConc;
318 }
319 else
320 {
321 pScanRequest->maxChnTime = pMac->roam.configParam.nPassiveMaxChnTimeConc;
322 pScanRequest->minChnTime = pMac->roam.configParam.nPassiveMinChnTimeConc;
323 }
Abhishek Singhadd13582016-09-29 17:00:03 +0530324 pScanRequest->max_chntime_btc_esco =
325 pMac->roam.configParam.max_chntime_btc_esco;
326 pScanRequest->min_chntime_btc_esco =
327 pMac->roam.configParam.min_chntime_btc_esco;
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700328
329 pScanRequest->restTime = pMac->roam.configParam.nRestTimeConc;
330
331 //Return so that fields set above will not be overwritten.
332 return;
333 }
334#endif
335
336 //This portion of the code executed if multi-session not supported
337 //(WLAN_AP_STA_CONCURRENCY not defined) or no multi-session.
338 //Use the "regular" (non-concurrency) default scan timing.
Abhishek Singh7fb7dc12014-11-06 17:44:05 +0530339 ccmCfgSetInt(pMac, WNI_CFG_PASSIVE_MAXIMUM_CHANNEL_TIME,
Kaushik, Sushant49758c12014-09-26 11:25:38 +0530340 pMac->roam.configParam.nPassiveMaxChnTime,
341 NULL,eANI_BOOLEAN_FALSE);
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700342 if(pScanRequest->scanType == eSIR_ACTIVE_SCAN)
343 {
344 pScanRequest->maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
345 pScanRequest->minChnTime = pMac->roam.configParam.nActiveMinChnTime;
346 }
347 else
348 {
349 pScanRequest->maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
350 pScanRequest->minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
351 }
Abhishek Singhadd13582016-09-29 17:00:03 +0530352 pScanRequest->max_chntime_btc_esco =
353 pMac->roam.configParam.max_chntime_btc_esco;
354 pScanRequest->min_chntime_btc_esco =
355 pMac->roam.configParam.min_chntime_btc_esco;
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700356
357#ifdef WLAN_AP_STA_CONCURRENCY
358 //No rest time if no sessions are connected.
359 pScanRequest->restTime = 0;
360#endif
361}
362
Jeff Johnson295189b2012-06-20 16:38:30 -0700363#ifdef WLAN_AP_STA_CONCURRENCY
364//Return SUCCESS is the command is queued, else returns eHAL_STATUS_FAILURE
365eHalStatus csrQueueScanRequest( tpAniSirGlobal pMac, tSmeCmd *pScanCmd )
366{
367 eHalStatus status = eHAL_STATUS_SUCCESS;
368
369 tANI_BOOLEAN fNoCmdPending;
370 tSmeCmd *pQueueScanCmd=NULL;
371 tSmeCmd *pSendScanCmd=NULL;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700372 tANI_U8 nNumChanCombinedConc = 0;
Gopichand Nakkala114718f2013-03-25 19:19:46 -0700373 if (NULL == pScanCmd)
374 {
375 smsLog (pMac, LOGE, FL("Scan Req cmd is NULL"));
376 return eHAL_STATUS_FAILURE;
377 }
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -0800378 /* split scan if any one of the following:
379 * - STA session is connected and the scan is not a P2P search
380 * - any P2P session is connected
Srikant Kuppa866893f2012-12-27 17:28:14 -0800381 * Do not split scans if no concurrent infra connections are
382 * active and if the scan is a BG scan triggered by LFR (OR)
383 * any scan if LFR is in the middle of a BG scan. Splitting
384 * the scan is delaying the time it takes for LFR to find
385 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -0800386 */
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700387
388 if(csrIsStaSessionConnected(pMac) &&
389 !csrIsP2pSessionConnected(pMac))
390 {
391 nNumChanCombinedConc = pMac->roam.configParam.nNumStaChanCombinedConc;
392 }
393 else if(csrIsP2pSessionConnected(pMac))
394 {
395 nNumChanCombinedConc = pMac->roam.configParam.nNumP2PChanCombinedConc;
396 }
Srikant Kuppa866893f2012-12-27 17:28:14 -0800397 if ( (csrIsStaSessionConnected(pMac) &&
398#ifdef FEATURE_WLAN_LFR
399 (csrIsConcurrentInfraConnected(pMac) ||
400 ((pScanCmd->u.scanCmd.reason != eCsrScanBgScan) &&
401 (pMac->roam.neighborRoamInfo.neighborRoamState !=
402 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
403#endif
404 (pScanCmd->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Vinay Malekal05fdc812012-12-17 13:04:30 -0800405 (csrIsP2pSessionConnected(pMac)) )
Jeff Johnson295189b2012-06-20 16:38:30 -0700406 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700407 tCsrScanRequest scanReq;
408 tANI_U8 numChn = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
409 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
410 tANI_U8 channelToScan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
Jeff Johnson295189b2012-06-20 16:38:30 -0700411 tANI_BOOLEAN bMemAlloc = eANI_BOOLEAN_FALSE;
412
413 if (numChn == 0)
414 {
415
416 numChn = pMac->scan.baseChannels.numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -0700417
Kiet Lam64c1b492013-07-12 13:56:44 +0530418 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(numChn);
419 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -0700420 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800421 smsLog( pMac, LOGE, FL(" Failed to get memory for channel list ") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800422 return eHAL_STATUS_FAILURE;
423 }
424 bMemAlloc = eANI_BOOLEAN_TRUE;
Kiet Lam64c1b492013-07-12 13:56:44 +0530425 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
426 pMac->scan.baseChannels.channelList, numChn);
427 status = eHAL_STATUS_SUCCESS;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800428 if( !HAL_STATUS_SUCCESS( status ) )
429 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530430 vos_mem_free(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800431 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800432 smsLog( pMac, LOGE, FL(" Failed to copy memory to channel list ") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800433 return eHAL_STATUS_FAILURE;
434 }
435 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = numChn;
436 }
Sushant Kaushik826de802014-05-08 18:04:11 +0530437 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
438 "%s: Total Number of channels to scan : %d "
439 "Splitted in group of %d ", __func__, numChn,
440 nNumChanCombinedConc);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800441 //Whenever we get a scan request with multiple channels we break it up into 2 requests
442 //First request for first channel to scan and second request to scan remaining channels
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700443 if ( numChn > nNumChanCombinedConc)
Vinay Malekal05fdc812012-12-17 13:04:30 -0800444 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530445 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800446
447 pQueueScanCmd = csrGetCommandBuffer(pMac); //optimize this to use 2 command buffer only
448 if (!pQueueScanCmd)
449 {
450 if (bMemAlloc)
Jeff Johnson295189b2012-06-20 16:38:30 -0700451 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530452 vos_mem_free(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800453 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
454
Jeff Johnson295189b2012-06-20 16:38:30 -0700455 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800456 smsLog( pMac, LOGE, FL(" Failed to get Queue command buffer") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800457 return eHAL_STATUS_FAILURE;
458 }
459 pQueueScanCmd->command = pScanCmd->command;
460 pQueueScanCmd->sessionId = pScanCmd->sessionId;
461 pQueueScanCmd->u.scanCmd.callback = pScanCmd->u.scanCmd.callback;
462 pQueueScanCmd->u.scanCmd.pContext = pScanCmd->u.scanCmd.pContext;
463 pQueueScanCmd->u.scanCmd.reason = pScanCmd->u.scanCmd.reason;
464 pQueueScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Jeff Johnson295189b2012-06-20 16:38:30 -0700465
Vinay Malekal05fdc812012-12-17 13:04:30 -0800466 /* First copy all the parameters to local variable of scan request */
467 csrScanCopyRequest(pMac, &scanReq, &pScanCmd->u.scanCmd.u.scanRequest);
Madan Mohan Koyyalamudiaf2a8b92012-10-09 14:58:07 -0700468
Vinay Malekal05fdc812012-12-17 13:04:30 -0800469 /* Now modify the elements of local var scan request required to be modified for split scan */
470 if(scanReq.ChannelInfo.ChannelList != NULL)
471 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530472 vos_mem_free(scanReq.ChannelInfo.ChannelList);
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -0800473 scanReq.ChannelInfo.ChannelList = NULL;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800474 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700475
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700476 pChnInfo->numOfChannels = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels - nNumChanCombinedConc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700477
Vinay Malekal05fdc812012-12-17 13:04:30 -0800478 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_WARN,
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +0530479 FL(" &channelToScan %p pScanCmd(%p) pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList(%p)numChn(%d)"),
480 &channelToScan[0], pScanCmd,
481 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList, numChn);
Jeff Johnson295189b2012-06-20 16:38:30 -0700482
Kiet Lam64c1b492013-07-12 13:56:44 +0530483 vos_mem_copy(&channelToScan[0],
484 &pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[
485 nNumChanCombinedConc],
486 pChnInfo->numOfChannels * sizeof(tANI_U8));
Vinay Malekal05fdc812012-12-17 13:04:30 -0800487
488 pChnInfo->ChannelList = &channelToScan[0];
489
490 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
c_hpothudbefd3e2014-04-28 15:59:47 +0530491
Vinay Malekal05fdc812012-12-17 13:04:30 -0800492 //Use concurrency values for min/maxChnTime.
493 //We know csrIsAnySessionConnected(pMac) returns TRUE here
494 csrSetDefaultScanTiming(pMac, scanReq.scanType, &scanReq);
495
496 status = csrScanCopyRequest(pMac, &pQueueScanCmd->u.scanCmd.u.scanRequest, &scanReq);
497
498 if(!HAL_STATUS_SUCCESS(status))
499 {
500 if (bMemAlloc)
501 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530502 vos_mem_free(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800503 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
504
505 }
506 if( scanReq.pIEField != NULL)
507 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530508 vos_mem_free(scanReq.pIEField);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800509 scanReq.pIEField = NULL;
510 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800511 smsLog( pMac, LOGE, FL(" Failed to get copy csrScanRequest = %d"), status );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800512 return eHAL_STATUS_FAILURE;
513 }
514 /* Clean the local scan variable */
515 scanReq.ChannelInfo.ChannelList = NULL;
516 scanReq.ChannelInfo.numOfChannels = 0;
517 csrScanFreeRequest(pMac, &scanReq);
518
519 /* setup the command to scan 2 channels */
520 pSendScanCmd = pScanCmd;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700521 pSendScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nNumChanCombinedConc;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800522 pSendScanCmd->u.scanCmd.u.scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
c_hpothudbefd3e2014-04-28 15:59:47 +0530523
Vinay Malekal05fdc812012-12-17 13:04:30 -0800524 //Use concurrency values for min/maxChnTime.
525 //We know csrIsAnySessionConnected(pMac) returns TRUE here
526 csrSetDefaultScanTiming(pMac, pSendScanCmd->u.scanCmd.u.scanRequest.scanType, &pSendScanCmd->u.scanCmd.u.scanRequest);
527 pSendScanCmd->u.scanCmd.callback = NULL;
528 } else {
529 pSendScanCmd = pScanCmd;
530 pSendScanCmd->u.scanCmd.u.scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
c_hpothudbefd3e2014-04-28 15:59:47 +0530531
Vinay Malekal05fdc812012-12-17 13:04:30 -0800532 //Use concurrency values for min/maxChnTime.
533 //We know csrIsAnySessionConnected(pMac) returns TRUE here
534 csrSetDefaultScanTiming(pMac, pSendScanCmd->u.scanCmd.u.scanRequest.scanType, &pSendScanCmd->u.scanCmd.u.scanRequest);
535 }
536
537 fNoCmdPending = csrLLIsListEmpty( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK );
538
539 //Logic Below is as follows
540 // If the scanCmdPendingList is empty then we directly send that command
541 // to smeCommandQueue else we buffer it in our scanCmdPendingList Queue
542 if( fNoCmdPending )
543 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700544 if (pQueueScanCmd != NULL)
545 {
Vinay Malekal05fdc812012-12-17 13:04:30 -0800546 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pQueueScanCmd->Link, LL_ACCESS_LOCK );
Jeff Johnson295189b2012-06-20 16:38:30 -0700547 }
548
549 if (pSendScanCmd != NULL)
550 {
551 return csrQueueSmeCommand(pMac, pSendScanCmd, eANI_BOOLEAN_FALSE);
552 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800553 }
554 else
555 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700556 if (pSendScanCmd != NULL)
557 {
558 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pSendScanCmd->Link, LL_ACCESS_LOCK );
559 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800560
Jeff Johnson295189b2012-06-20 16:38:30 -0700561 if (pQueueScanCmd != NULL)
562 {
563 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pQueueScanCmd->Link, LL_ACCESS_LOCK );
564 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800565 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700566 }
567 else
568 { //No concurrency case
Srikant Kuppa866893f2012-12-27 17:28:14 -0800569 smsLog( pMac, LOG2, FL("Queuing scan command (reason=%d, roamState=%d"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800570 " numOfChannels=%d)"),
Srikant Kuppa866893f2012-12-27 17:28:14 -0800571 pScanCmd->u.scanCmd.reason,
572 pMac->roam.neighborRoamInfo.neighborRoamState,
573 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -0700574 return csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
575 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700576
577 return ( status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700578}
579#endif
580
Jeff Johnsone7245742012-09-05 17:12:55 -0700581/* ---------------------------------------------------------------------------
582 \fn csrScan2GOnyRequest
583 \brief This function will update the scan request with only
Jeff Johnsonb88db982012-12-10 13:34:59 -0800584 2.4GHz valid channel list.
Jeff Johnsone7245742012-09-05 17:12:55 -0700585 \param pMac
586 \param pScanCmd
587 \param pScanRequest
588 \return None
589 -------------------------------------------------------------------------------*/
590static void csrScan2GOnyRequest(tpAniSirGlobal pMac,tSmeCmd *pScanCmd,
591 tCsrScanRequest *pScanRequest)
592{
593 tANI_U8 index, channelId, channelListSize = 0;
594 tANI_U8 channelList2G[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
595 static tANI_U8 validchannelList[CSR_MAX_2_4_GHZ_SUPPORTED_CHANNELS] = {0};
596
597 VOS_ASSERT(pScanCmd && pScanRequest);
Madan Mohan Koyyalamudi33ef6a22012-10-30 17:44:43 -0700598 /* To silence the KW tool null check is added */
599 if((pScanCmd == NULL) || (pScanRequest == NULL))
600 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800601 smsLog( pMac, LOGE, FL(" pScanCmd or pScanRequest is NULL "));
Madan Mohan Koyyalamudi33ef6a22012-10-30 17:44:43 -0700602 return;
603 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700604
605 if (pScanCmd->u.scanCmd.scanID ||
606 (eCSR_SCAN_REQUEST_FULL_SCAN != pScanRequest->requestType))
607 return;
608
609 //Contsruct valid Supported 2.4 GHz Channel List
610 for( index = 0; index < ARRAY_SIZE(channelList2G); index++ )
611 {
612 channelId = channelList2G[index];
613 if ( csrIsSupportedChannel( pMac, channelId ) )
614 {
615 validchannelList[channelListSize++] = channelId;
616 }
617 }
618
619 pScanRequest->ChannelInfo.numOfChannels = channelListSize;
620 pScanRequest->ChannelInfo.ChannelList = validchannelList;
621}
622
Jeff Johnson295189b2012-06-20 16:38:30 -0700623eHalStatus csrScanRequest(tpAniSirGlobal pMac, tANI_U16 sessionId,
624 tCsrScanRequest *pScanRequest, tANI_U32 *pScanRequestID,
625 csrScanCompleteCallback callback, void *pContext)
626{
627 eHalStatus status = eHAL_STATUS_FAILURE;
628 tSmeCmd *pScanCmd = NULL;
Madan Mohan Koyyalamudicb90bb22012-10-30 18:24:43 -0700629 eCsrConnectState ConnectState;
Deepthi Gowrie11da8c2016-02-04 18:18:39 +0530630
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800631 if(pScanRequest == NULL)
632 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800633 smsLog( pMac, LOGE, FL(" pScanRequest is NULL"));
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800634 VOS_ASSERT(0);
Kaushik, Sushant488df382014-03-05 11:43:47 +0530635 return eHAL_STATUS_FAILURE ;
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800636 }
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700637
Kiet Lamd1f3dc82013-11-05 20:45:04 +0530638 /* During group formation, the P2P client scans for GO with the specific SSID.
639 * There will be chances of GO switching to other channels because of scan or
640 * to STA channel in case of STA+GO MCC scenario. So to increase the possibility
641 * of client to find the GO, the dwell time of scan is increased to 100ms.
642 */
643 if(pScanRequest->p2pSearch)
644 {
Rashmi Ramanna6f7931c2013-12-20 09:04:12 +0530645 if(pScanRequest->SSIDs.numOfSSIDs)
Kiet Lamd1f3dc82013-11-05 20:45:04 +0530646 {
Rashmi Ramanna6f7931c2013-12-20 09:04:12 +0530647 //If the scan request is for specific SSId the length of SSID will be
648 //greater than 7 as SSID for p2p search contains "DIRECT-")
649 if(pScanRequest->SSIDs.SSIDList->SSID.length > DIRECT_SSID_LEN)
650 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530651 smsLog( pMac, LOG1, FL("P2P: Increasing the min and max Dwell"
652 " time to %d for specific SSID scan %.*s"),
653 MAX_CHN_TIME_TO_FIND_GO,
654 pScanRequest->SSIDs.SSIDList->SSID.length,
655 pScanRequest->SSIDs.SSIDList->SSID.ssId);
Rashmi Ramanna6f7931c2013-12-20 09:04:12 +0530656 pScanRequest->maxChnTime = MAX_CHN_TIME_TO_FIND_GO;
657 pScanRequest->minChnTime = MIN_CHN_TIME_TO_FIND_GO;
658 }
Kiet Lamd1f3dc82013-11-05 20:45:04 +0530659 }
660 }
661
Jeff Johnson295189b2012-06-20 16:38:30 -0700662 do
663 {
664 if(pMac->scan.fScanEnable)
665 {
666 pScanCmd = csrGetCommandBuffer(pMac);
667 if(pScanCmd)
668 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530669 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -0700670 pScanCmd->command = eSmeCommandScan;
671 pScanCmd->sessionId = sessionId;
672 pScanCmd->u.scanCmd.callback = callback;
673 pScanCmd->u.scanCmd.pContext = pContext;
674 if(eCSR_SCAN_REQUEST_11D_SCAN == pScanRequest->requestType)
675 {
676 pScanCmd->u.scanCmd.reason = eCsrScan11d1;
677 }
678 else if((eCSR_SCAN_REQUEST_FULL_SCAN == pScanRequest->requestType) ||
679 (eCSR_SCAN_P2P_DISCOVERY == pScanRequest->requestType)
680#ifdef SOFTAP_CHANNEL_RANGE
681 ||(eCSR_SCAN_SOFTAP_CHANNEL_RANGE == pScanRequest->requestType)
682#endif
683 )
684 {
685 pScanCmd->u.scanCmd.reason = eCsrScanUserRequest;
686 }
687 else if(eCSR_SCAN_HO_BG_SCAN == pScanRequest->requestType)
688 {
689 pScanCmd->u.scanCmd.reason = eCsrScanBgScan;
690 }
691 else if(eCSR_SCAN_HO_PROBE_SCAN == pScanRequest->requestType)
692 {
693 pScanCmd->u.scanCmd.reason = eCsrScanProbeBss;
694 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700695 else if(eCSR_SCAN_P2P_FIND_PEER == pScanRequest->requestType)
696 {
697 pScanCmd->u.scanCmd.reason = eCsrScanP2PFindPeer;
698 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700699 else
700 {
701 pScanCmd->u.scanCmd.reason = eCsrScanIdleScan;
702 }
703 if(pScanRequest->minChnTime == 0 && pScanRequest->maxChnTime == 0)
704 {
705 //The caller doesn't set the time correctly. Set it here
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530706 csrSetDefaultScanTiming(pMac, pScanRequest->scanType,
707 pScanRequest);
708 smsLog(pMac, LOG1, FL("Setting default min %d and max %d"
709 " ChnTime"), pScanRequest->minChnTime,
710 pScanRequest->maxChnTime);
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700711 }
712#ifdef WLAN_AP_STA_CONCURRENCY
713 if(pScanRequest->restTime == 0)
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800714 {
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700715 //Need to set restTime only if at least one session is connected
716 if(csrIsAnySessionConnected(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -0700717 {
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700718 pScanRequest->restTime = pMac->roam.configParam.nRestTimeConc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700719 }
720 }
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700721#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -0700722 /*For Standalone wlan : channel time will remain the same.
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530723 For BTC with A2DP up: Channel time = Channel time * 2, if station is not already associated.
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800724 This has been done to provide a larger scan window for faster connection during btc.Else Scan is seen
725 to take a long time.
726 For BTC with A2DP up: Channel time will not be doubled, if station is already associated.
727 */
Jeff Johnson32d95a32012-09-10 13:15:23 -0700728 status = csrRoamGetConnectState(pMac,sessionId,&ConnectState);
Srinivas Girigowdac84c57c2013-02-19 17:41:56 -0800729 if (HAL_STATUS_SUCCESS(status) &&
730 pMac->btc.fA2DPUp &&
Jeff Johnson32d95a32012-09-10 13:15:23 -0700731 (eCSR_ASSOC_STATE_TYPE_INFRA_ASSOCIATED != ConnectState) &&
732 (eCSR_ASSOC_STATE_TYPE_IBSS_CONNECTED != ConnectState))
733 {
734 pScanRequest->maxChnTime = pScanRequest->maxChnTime << 1;
735 pScanRequest->minChnTime = pScanRequest->minChnTime << 1;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530736 smsLog( pMac, LOG1, FL("BTC A2DP up, doubling max and min"
737 " ChnTime (Max=%d Min=%d)"),
738 pScanRequest->maxChnTime,
739 pScanRequest->minChnTime);
Jeff Johnson32d95a32012-09-10 13:15:23 -0700740 }
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800741
Abhishek Singhadd13582016-09-29 17:00:03 +0530742 pScanRequest->max_chntime_btc_esco =
743 pMac->roam.configParam.max_chntime_btc_esco;
744 pScanRequest->min_chntime_btc_esco =
745 pMac->roam.configParam.min_chntime_btc_esco;
Jeff Johnson295189b2012-06-20 16:38:30 -0700746 //Need to make the following atomic
747 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
748
749 if(pScanRequestID)
750 {
751 *pScanRequestID = pScanCmd->u.scanCmd.scanID;
752 }
753
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800754 // If it is the first scan request from HDD, CSR checks if it is for 11d.
Jeff Johnson295189b2012-06-20 16:38:30 -0700755 // If it is not, CSR will save the scan request in the pending cmd queue
756 // & issue an 11d scan request to PE.
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800757 if (((0 == pScanCmd->u.scanCmd.scanID)
Jeff Johnson295189b2012-06-20 16:38:30 -0700758 && (eCSR_SCAN_REQUEST_11D_SCAN != pScanRequest->requestType))
759#ifdef SOFTAP_CHANNEL_RANGE
760 && (eCSR_SCAN_SOFTAP_CHANNEL_RANGE != pScanRequest->requestType)
761#endif
762 && (eANI_BOOLEAN_FALSE == pMac->scan.fEnableBypass11d)
763 )
764 {
765 tSmeCmd *p11dScanCmd;
766 tCsrScanRequest scanReq;
767 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
768
Kiet Lam64c1b492013-07-12 13:56:44 +0530769 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -0700770
771 p11dScanCmd = csrGetCommandBuffer(pMac);
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800772 if (p11dScanCmd)
Jeff Johnson295189b2012-06-20 16:38:30 -0700773 {
774 tANI_U32 numChn = pMac->scan.baseChannels.numChannels;
775
Kiet Lam64c1b492013-07-12 13:56:44 +0530776 vos_mem_set(&p11dScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
777 pChnInfo->ChannelList = vos_mem_malloc(numChn);
778 if ( NULL == pChnInfo->ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -0700779 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530780 smsLog(pMac, LOGE, FL("Failed to allocate memory"));
781 status = eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -0700782 break;
783 }
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530784 vos_mem_copy(pChnInfo->ChannelList,
785 pMac->scan.baseChannels.channelList,
786 numChn);
Jeff Johnson295189b2012-06-20 16:38:30 -0700787 pChnInfo->numOfChannels = (tANI_U8)numChn;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530788
Jeff Johnson295189b2012-06-20 16:38:30 -0700789 p11dScanCmd->command = eSmeCommandScan;
Mihir Shetefc7ff5b2014-01-27 11:30:05 +0530790 p11dScanCmd->u.scanCmd.callback = pMac->scan.callback11dScanDone;
Jeff Johnson295189b2012-06-20 16:38:30 -0700791 p11dScanCmd->u.scanCmd.pContext = NULL;
c_hpothu0d5a7352014-03-22 12:30:25 +0530792 p11dScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID;
Jeff Johnson295189b2012-06-20 16:38:30 -0700793 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
794
795 if ( csrIs11dSupported(pMac) )
796 {
c_hpothudbefd3e2014-04-28 15:59:47 +0530797 scanReq.scanType = eSIR_PASSIVE_SCAN;
Jeff Johnson295189b2012-06-20 16:38:30 -0700798 scanReq.requestType = eCSR_SCAN_REQUEST_11D_SCAN;
799 p11dScanCmd->u.scanCmd.reason = eCsrScan11d1;
800 scanReq.maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
801 scanReq.minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
802 }
803 else
804 {
c_hpothudbefd3e2014-04-28 15:59:47 +0530805 scanReq.scanType = pScanRequest->scanType;
Jeff Johnson295189b2012-06-20 16:38:30 -0700806 scanReq.requestType = eCSR_SCAN_IDLE_MODE_SCAN;
807 p11dScanCmd->u.scanCmd.reason = eCsrScanIdleScan;
808 scanReq.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
809 scanReq.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800810
Abhishek Singhadd13582016-09-29 17:00:03 +0530811 scanReq.max_chntime_btc_esco =
812 pMac->roam.configParam.max_chntime_btc_esco;
813 scanReq.min_chntime_btc_esco =
814 pMac->roam.configParam.min_chntime_btc_esco;
Jeff Johnson295189b2012-06-20 16:38:30 -0700815 }
c_hpothu059edb02014-03-12 21:44:28 +0530816 if (pMac->roam.configParam.nInitialDwellTime)
817 {
818 scanReq.maxChnTime =
819 pMac->roam.configParam.nInitialDwellTime;
820 smsLog(pMac, LOG1, FL("11d scan, updating"
821 "dwell time for first scan %u"),
822 scanReq.maxChnTime);
823 }
Deepthi Gowrie11da8c2016-02-04 18:18:39 +0530824 if ((pScanCmd->u.scanCmd.reason == eCsrScanUserRequest)
825 && !(pScanRequest->p2pSearch)
Gupta, Kapilb79cda32015-12-30 20:36:33 +0530826 &&(pScanRequest->ChannelInfo.numOfChannels
827 < pMac->roam.configParam.
828 max_chan_for_dwell_time_cfg))
829 {
830 pScanRequest->maxChnTime =
831 pScanRequest->maxChnTime << 1;
832 pScanRequest->minChnTime =
833 pScanRequest->minChnTime << 1;
834 smsLog(pMac, LOG1,
835 FL("Double ChnTime (Max=%d Min=%d) numOfChannels=%d max_chan_for_dwell_time_cfg=%d"),
836 pScanRequest->maxChnTime,
837 pScanRequest->minChnTime,
838 pScanRequest->ChannelInfo.numOfChannels,
839 pMac->roam.configParam.
840 max_chan_for_dwell_time_cfg);
841 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700842
Jeff Johnson295189b2012-06-20 16:38:30 -0700843 status = csrScanCopyRequest(pMac, &p11dScanCmd->u.scanCmd.u.scanRequest, &scanReq);
844 //Free the channel list
Kiet Lam64c1b492013-07-12 13:56:44 +0530845 vos_mem_free(pChnInfo->ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -0700846 pChnInfo->ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -0700847
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800848 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700849 {
krunal soni5f112f02013-11-25 15:00:11 -0800850 pMac->scan.scanProfile.numOfChannels =
851 p11dScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -0700852 //Start process the command
853#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +0530854 if (!pMac->fScanOffload)
855 status = csrQueueScanRequest(pMac, p11dScanCmd);
856 else
857 status = csrQueueSmeCommand(pMac, p11dScanCmd,
858 eANI_BOOLEAN_FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -0700859#else
860 status = csrQueueSmeCommand(pMac, p11dScanCmd, eANI_BOOLEAN_FALSE);
861#endif
862 if( !HAL_STATUS_SUCCESS( status ) )
863 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530864 smsLog(pMac, LOGE, FL("Failed to send message"
865 " status = %d"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -0700866 break;
867 }
868 }
869 else
870 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530871 smsLog(pMac, LOGE, FL("csrScanCopyRequest failed"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700872 break;
873 }
874 }
875 else
876 {
877 //error
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530878 smsLog( pMac, LOGE, FL("p11dScanCmd failed") );
Jeff Johnson295189b2012-06-20 16:38:30 -0700879 break;
880 }
881 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700882
883 //Scan only 2G Channels if set in ini file
884 //This is mainly to reduce the First Scan duration
885 //Once we turn on Wifi
886 if(pMac->scan.fFirstScanOnly2GChnl)
887 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800888 smsLog( pMac, LOG1, FL("Scanning only 2G Channels during first scan"));
Jeff Johnsone7245742012-09-05 17:12:55 -0700889 csrScan2GOnyRequest(pMac, pScanCmd, pScanRequest);
890 }
891
c_hpothu059edb02014-03-12 21:44:28 +0530892 if (pMac->roam.configParam.nInitialDwellTime)
893 {
894 pScanRequest->maxChnTime =
895 pMac->roam.configParam.nInitialDwellTime;
896 pMac->roam.configParam.nInitialDwellTime = 0;
897 smsLog(pMac, LOG1,
898 FL("updating dwell time for first scan %u"),
899 pScanRequest->maxChnTime);
900 }
901
Deepthi Gowrie11da8c2016-02-04 18:18:39 +0530902 if ((pScanCmd->u.scanCmd.reason == eCsrScanUserRequest)
903 && !(pScanRequest->p2pSearch)
Gupta, Kapilb79cda32015-12-30 20:36:33 +0530904 && (pScanRequest->ChannelInfo.numOfChannels
905 < pMac->roam.configParam.max_chan_for_dwell_time_cfg))
906 {
907 pScanRequest->maxChnTime = pScanRequest->maxChnTime << 1;
908 pScanRequest->minChnTime = pScanRequest->minChnTime << 1;
909 smsLog(pMac, LOG1,
910 FL("Double ChnTime (Max=%d Min=%d) numOfChannels=%d max_chan_for_dwell_time_cfg=%d"),
911 pScanRequest->maxChnTime,
912 pScanRequest->minChnTime,
913 pScanRequest->ChannelInfo.numOfChannels,
914 pMac->roam.configParam.max_chan_for_dwell_time_cfg);
915 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700916 status = csrScanCopyRequest(pMac, &pScanCmd->u.scanCmd.u.scanRequest, pScanRequest);
917 if(HAL_STATUS_SUCCESS(status))
918 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530919 tCsrScanRequest *pTempScanReq =
920 &pScanCmd->u.scanCmd.u.scanRequest;
krunal soni5f112f02013-11-25 15:00:11 -0800921 pMac->scan.scanProfile.numOfChannels =
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530922 pTempScanReq->ChannelInfo.numOfChannels;
krunal soni5f112f02013-11-25 15:00:11 -0800923
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530924 smsLog( pMac, LOG1, FL(" SId=%d scanId=%d"
925 " Scan reason=%u numSSIDs=%d"
926 " numChan=%d P2P search=%d minCT=%d maxCT=%d"
927 " minCBtc=%d maxCBtx=%d"),
928 sessionId, pScanCmd->u.scanCmd.scanID,
929 pScanCmd->u.scanCmd.reason,
930 pTempScanReq->SSIDs.numOfSSIDs,
931 pTempScanReq->ChannelInfo.numOfChannels,
932 pTempScanReq->p2pSearch,
933 pTempScanReq->minChnTime,
934 pTempScanReq->maxChnTime,
Abhishek Singhadd13582016-09-29 17:00:03 +0530935 pTempScanReq->min_chntime_btc_esco,
936 pTempScanReq->max_chntime_btc_esco);
Jeff Johnson295189b2012-06-20 16:38:30 -0700937 //Start process the command
938#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +0530939 if (!pMac->fScanOffload)
940 status = csrQueueScanRequest(pMac,pScanCmd);
941 else
942 status = csrQueueSmeCommand(pMac, pScanCmd,
943 eANI_BOOLEAN_FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -0700944#else
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530945 status = csrQueueSmeCommand(pMac, pScanCmd,
946 eANI_BOOLEAN_FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -0700947#endif
948 if( !HAL_STATUS_SUCCESS( status ) )
949 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800950 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700951 break;
952 }
953 }
954 else
955 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800956 smsLog( pMac, LOGE, FL(" fail to copy request status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700957 break;
958 }
959 }
960 else
961 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800962 smsLog( pMac, LOGE, FL(" pScanCmd is NULL"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700963 break;
964 }
965 }
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530966 else
967 {
968 smsLog( pMac, LOGE, FL("SId: %d Scanning not enabled"
969 " Scan type=%u, numOfSSIDs=%d P2P search=%d"),
970 sessionId, pScanRequest->requestType,
971 pScanRequest->SSIDs.numOfSSIDs,
972 pScanRequest->p2pSearch );
973 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700974 } while(0);
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530975
976
Jeff Johnson295189b2012-06-20 16:38:30 -0700977 if(!HAL_STATUS_SUCCESS(status) && pScanCmd)
978 {
979 if( eCsrScanIdleScan == pScanCmd->u.scanCmd.reason )
980 {
981 //Set the flag back for restarting idle scan
982 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
983 }
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530984 smsLog( pMac, LOGE, FL(" SId: %d Failed with status=%d"
985 " Scan reason=%u numOfSSIDs=%d"
986 " P2P search=%d scanId=%d"),
987 sessionId, status, pScanCmd->u.scanCmd.reason,
988 pScanRequest->SSIDs.numOfSSIDs, pScanRequest->p2pSearch,
989 pScanCmd->u.scanCmd.scanID );
Jeff Johnson295189b2012-06-20 16:38:30 -0700990 csrReleaseCommandScan(pMac, pScanCmd);
991 }
992
993 return (status);
994}
995
996
997eHalStatus csrScanRequestResult(tpAniSirGlobal pMac)
998{
999 eHalStatus status = eHAL_STATUS_SUCCESS;
1000 tSmeCmd *pScanCmd;
1001
1002 if(pMac->scan.fScanEnable)
1003 {
1004 pScanCmd = csrGetCommandBuffer(pMac);
1005 if(pScanCmd)
1006 {
1007 pScanCmd->command = eSmeCommandScan;
Kiet Lam64c1b492013-07-12 13:56:44 +05301008 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001009 pScanCmd->u.scanCmd.callback = NULL;
1010 pScanCmd->u.scanCmd.pContext = NULL;
1011 pScanCmd->u.scanCmd.reason = eCsrScanGetResult;
1012 //Need to make the following atomic
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07001013 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID; //let it wrap around
Jeff Johnson295189b2012-06-20 16:38:30 -07001014 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
1015 if( !HAL_STATUS_SUCCESS( status ) )
1016 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001017 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001018 csrReleaseCommandScan(pMac, pScanCmd);
1019 }
1020 }
1021 else
1022 {
1023 //log error
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001024 smsLog(pMac, LOGE, FL("can not obtain a common buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001025 status = eHAL_STATUS_RESOURCES;
1026 }
1027 }
1028
1029 return (status);
1030}
1031
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07001032#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
1033eHalStatus csrScanRequestLfrResult(tpAniSirGlobal pMac, tANI_U32 sessionId,
1034 csrScanCompleteCallback callback, void *pContext)
1035{
1036 eHalStatus status = eHAL_STATUS_SUCCESS;
1037 tSmeCmd *pScanCmd;
1038
1039 if (pMac->scan.fScanEnable)
1040 {
1041 pScanCmd = csrGetCommandBuffer(pMac);
1042 if (pScanCmd)
1043 {
1044 pScanCmd->command = eSmeCommandScan;
1045 pScanCmd->sessionId = sessionId;
Kiet Lam64c1b492013-07-12 13:56:44 +05301046 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07001047 pScanCmd->u.scanCmd.callback = callback;
1048 pScanCmd->u.scanCmd.pContext = pContext;
1049 pScanCmd->u.scanCmd.reason = eCsrScanGetLfrResult;
1050 //Need to make the following atomic
1051 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID; //let it wrap around
1052 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_TRUE);
1053 if ( !HAL_STATUS_SUCCESS( status ) )
1054 {
1055 smsLog( pMac, LOGE, FL(" fail to send message status = %d\n"), status );
1056 csrReleaseCommandScan(pMac, pScanCmd);
1057 }
1058 }
1059 else
1060 {
1061 //log error
1062 smsLog(pMac, LOGE, FL("can not obtain a common buffer\n"));
1063 status = eHAL_STATUS_RESOURCES;
1064 }
1065 }
1066
1067 return (status);
1068}
1069#endif //WLAN_FEATURE_ROAM_SCAN_OFFLOAD
Jeff Johnson295189b2012-06-20 16:38:30 -07001070
1071eHalStatus csrScanAllChannels(tpAniSirGlobal pMac, eCsrRequestType reqType)
1072{
1073 eHalStatus status = eHAL_STATUS_SUCCESS;
1074 tANI_U32 scanId;
1075 tCsrScanRequest scanReq;
1076
Kiet Lam64c1b492013-07-12 13:56:44 +05301077 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001078 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
1079 scanReq.scanType = eSIR_ACTIVE_SCAN;
1080 scanReq.requestType = reqType;
1081 scanReq.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1082 scanReq.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Abhishek Singhadd13582016-09-29 17:00:03 +05301083 scanReq.max_chntime_btc_esco =
1084 pMac->roam.configParam.max_chntime_btc_esco;
1085 scanReq.min_chntime_btc_esco =
1086 pMac->roam.configParam.min_chntime_btc_esco;
Jeff Johnson295189b2012-06-20 16:38:30 -07001087 //Scan with invalid sessionId.
1088 //This results in SME using the first available session to scan.
1089 status = csrScanRequest(pMac, CSR_SESSION_ID_INVALID, &scanReq,
1090 &scanId, NULL, NULL);
1091
1092 return (status);
1093}
1094
1095
1096
1097
1098eHalStatus csrIssueRoamAfterLostlinkScan(tpAniSirGlobal pMac, tANI_U32 sessionId, eCsrRoamReason reason)
1099{
1100 eHalStatus status = eHAL_STATUS_FAILURE;
1101 tScanResultHandle hBSSList = NULL;
1102 tCsrScanResultFilter *pScanFilter = NULL;
1103 tANI_U32 roamId = 0;
1104 tCsrRoamProfile *pProfile = NULL;
1105 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1106
Jeff Johnson32d95a32012-09-10 13:15:23 -07001107 if(!pSession)
1108 {
1109 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1110 return eHAL_STATUS_FAILURE;
1111 }
1112
Jeff Johnson295189b2012-06-20 16:38:30 -07001113 do
1114 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001115 smsLog(pMac, LOG1, " csrIssueRoamAfterLostlinkScan called");
Jeff Johnson295189b2012-06-20 16:38:30 -07001116 if(pSession->fCancelRoaming)
1117 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001118 smsLog(pMac, LOGW, " lostlink roaming is cancelled");
Jeff Johnson295189b2012-06-20 16:38:30 -07001119 csrScanStartIdleScan(pMac);
1120 status = eHAL_STATUS_SUCCESS;
1121 break;
1122 }
1123 //Here is the profile we need to connect to
Kiet Lam64c1b492013-07-12 13:56:44 +05301124 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1125 if ( NULL == pScanFilter)
1126 status = eHAL_STATUS_FAILURE;
1127 else
1128 status = eHAL_STATUS_SUCCESS;
1129 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001130 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301131 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001132 if(NULL == pSession->pCurRoamProfile)
1133 {
1134 pScanFilter->EncryptionType.numEntries = 1;
1135 pScanFilter->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_NONE;
1136 }
1137 else
1138 {
1139 //We have to make a copy of pCurRoamProfile because it will be free inside csrRoamIssueConnect
Kiet Lam64c1b492013-07-12 13:56:44 +05301140 pProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1141 if ( NULL == pProfile )
1142 status = eHAL_STATUS_FAILURE;
1143 else
1144 status = eHAL_STATUS_SUCCESS;
1145 if (!HAL_STATUS_SUCCESS(status))
1146 break;
1147 vos_mem_set(pProfile, sizeof(tCsrRoamProfile), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001148 status = csrRoamCopyProfile(pMac, pProfile, pSession->pCurRoamProfile);
1149 if(!HAL_STATUS_SUCCESS(status))
1150 break;
1151 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1152 }//We have a profile
1153 roamId = GET_NEXT_ROAM_ID(&pMac->roam);
1154 if(HAL_STATUS_SUCCESS(status))
1155 {
1156 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1157 if(HAL_STATUS_SUCCESS(status))
1158 {
1159 if(eCsrLostLink1 == reason)
1160 {
1161 //we want to put the last connected BSS to the very beginning, if possible
1162 csrMoveBssToHeadFromBSSID(pMac, &pSession->connectedProfile.bssid, hBSSList);
1163 }
1164 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList, reason,
1165 roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1166 if(!HAL_STATUS_SUCCESS(status))
1167 {
1168 csrScanResultPurge(pMac, hBSSList);
1169 }
1170 }//Have scan result
1171 }
1172 }while(0);
1173 if(pScanFilter)
1174 {
1175 //we need to free memory for filter if profile exists
1176 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301177 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001178 }
1179 if(NULL != pProfile)
1180 {
1181 csrReleaseProfile(pMac, pProfile);
Kiet Lam64c1b492013-07-12 13:56:44 +05301182 vos_mem_free(pProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07001183 }
1184
1185 return (status);
1186}
1187
1188
Ratheesh S Pece1f832015-07-25 15:50:25 +05301189eHalStatus csrScanGetScanChnInfo(tpAniSirGlobal pMac, tSmeCmd *pCommand)
Jeff Johnson295189b2012-06-20 16:38:30 -07001190{
1191 eHalStatus status = eHAL_STATUS_SUCCESS;
1192 tSmeCmd *pScanCmd;
1193
1194 if(pMac->scan.fScanEnable)
1195 {
1196 pScanCmd = csrGetCommandBuffer(pMac);
1197 if(pScanCmd)
1198 {
1199 pScanCmd->command = eSmeCommandScan;
Kiet Lam64c1b492013-07-12 13:56:44 +05301200 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001201 pScanCmd->u.scanCmd.reason = eCsrScanGetScanChnInfo;
1202 //Need to make the following atomic
1203 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Ratheesh S Pece1f832015-07-25 15:50:25 +05301204 pScanCmd->sessionId = pCommand->sessionId;
1205 if( pCommand->u.scanCmd.reason == eCsrScanUserRequest)
1206 {
1207 pScanCmd->u.scanCmd.callback = NULL;
1208 pScanCmd->u.scanCmd.pContext = NULL;
1209 } else {
1210 pScanCmd->u.scanCmd.callback = pCommand->u.scanCmd.callback;
1211 pScanCmd->u.scanCmd.pContext = pCommand->u.scanCmd.pContext;
1212 pScanCmd->u.scanCmd.abortScanIndication =
1213 pCommand->u.scanCmd.abortScanIndication;
1214 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001215 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
1216 if( !HAL_STATUS_SUCCESS( status ) )
1217 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001218 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001219 csrReleaseCommandScan(pMac, pScanCmd);
1220 }
1221 }
1222 else
1223 {
1224 //log error
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001225 smsLog(pMac, LOGE, FL("can not obtain a common buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001226 status = eHAL_STATUS_RESOURCES;
1227 }
1228 }
1229
1230 return (status);
1231}
1232
1233
1234eHalStatus csrScanHandleFailedLostlink1(tpAniSirGlobal pMac, tANI_U32 sessionId)
1235{
1236 eHalStatus status = eHAL_STATUS_FAILURE;
1237 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1238
Jeff Johnson32d95a32012-09-10 13:15:23 -07001239 if(!pSession)
1240 {
1241 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1242 return eHAL_STATUS_FAILURE;
1243 }
1244
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001245 smsLog(pMac, LOGW, " Lostlink scan 1 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001246 if(pSession->fCancelRoaming)
1247 {
1248 csrScanStartIdleScan(pMac);
1249 }
1250 else if(pSession->pCurRoamProfile)
1251 {
1252 //We fail lostlink1 but there may be other BSS in the cached result fit the profile. Give it a try first
1253 if(pSession->pCurRoamProfile->SSIDs.numOfSSIDs == 0 ||
1254 pSession->pCurRoamProfile->SSIDs.numOfSSIDs > 1)
1255 {
1256 //try lostlink scan2
1257 status = csrScanRequestLostLink2(pMac, sessionId);
1258 }
1259 else if(!pSession->pCurRoamProfile->ChannelInfo.ChannelList ||
1260 pSession->pCurRoamProfile->ChannelInfo.ChannelList[0] == 0)
1261 {
1262 //go straight to lostlink scan3
1263 status = csrScanRequestLostLink3(pMac, sessionId);
1264 }
1265 else
1266 {
1267 //we are done with lostlink
1268 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1269 {
1270 csrScanStartIdleScan(pMac);
1271 }
1272 status = eHAL_STATUS_SUCCESS;
1273 }
1274 }
1275 else
1276 {
1277 status = csrScanRequestLostLink3(pMac, sessionId);
1278 }
1279
1280 return (status);
1281}
1282
1283
1284
1285eHalStatus csrScanHandleFailedLostlink2(tpAniSirGlobal pMac, tANI_U32 sessionId)
1286{
1287 eHalStatus status = eHAL_STATUS_FAILURE;
1288 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1289
Jeff Johnson32d95a32012-09-10 13:15:23 -07001290 if(!pSession)
1291 {
1292 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1293 return eHAL_STATUS_FAILURE;
1294 }
1295
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001296 smsLog(pMac, LOGW, " Lostlink scan 2 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001297 if(pSession->fCancelRoaming)
1298 {
1299 csrScanStartIdleScan(pMac);
1300 }
1301 else if(!pSession->pCurRoamProfile || !pSession->pCurRoamProfile->ChannelInfo.ChannelList ||
1302 pSession->pCurRoamProfile->ChannelInfo.ChannelList[0] == 0)
1303 {
1304 //try lostlink scan3
1305 status = csrScanRequestLostLink3(pMac, sessionId);
1306 }
1307 else
1308 {
1309 //we are done with lostlink
1310 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1311 {
1312 csrScanStartIdleScan(pMac);
1313 }
1314 }
1315
1316 return (status);
1317}
1318
1319
1320
1321eHalStatus csrScanHandleFailedLostlink3(tpAniSirGlobal pMac, tANI_U32 sessionId)
1322{
1323 eHalStatus status = eHAL_STATUS_SUCCESS;
1324
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001325 smsLog(pMac, LOGW, " Lostlink scan 3 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001326 if(eANI_BOOLEAN_TRUE == csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1327 {
1328 //we are done with lostlink
1329 csrScanStartIdleScan(pMac);
1330 }
1331
1332 return (status);
1333}
1334
1335
1336
1337
1338//Lostlink1 scan is to actively scan the last connected profile's SSID on all matched BSS channels.
1339//If no roam profile (it should not), it is like lostlinkscan3
1340eHalStatus csrScanRequestLostLink1( tpAniSirGlobal pMac, tANI_U32 sessionId )
1341{
1342 eHalStatus status = eHAL_STATUS_SUCCESS;
1343 tSmeCmd *pCommand = NULL;
1344 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1345 tCsrScanResultFilter *pScanFilter = NULL;
1346 tScanResultHandle hBSSList = NULL;
1347 tCsrScanResultInfo *pScanResult = NULL;
1348 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1349
Jeff Johnson32d95a32012-09-10 13:15:23 -07001350 if(!pSession)
1351 {
1352 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1353 return eHAL_STATUS_FAILURE;
1354 }
1355
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001356 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001357 do
1358 {
1359 pCommand = csrGetCommandBuffer(pMac);
1360 if(!pCommand)
1361 {
1362 status = eHAL_STATUS_RESOURCES;
1363 break;
1364 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301365 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001366 pCommand->command = eSmeCommandScan;
1367 pCommand->sessionId = (tANI_U8)sessionId;
1368 pCommand->u.scanCmd.reason = eCsrScanLostLink1;
1369 pCommand->u.scanCmd.callback = NULL;
1370 pCommand->u.scanCmd.pContext = NULL;
1371 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1372 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Abhishek Singhadd13582016-09-29 17:00:03 +05301373 pCommand->u.scanCmd.u.scanRequest.max_chntime_btc_esco =
1374 pMac->roam.configParam.max_chntime_btc_esco;
1375 pCommand->u.scanCmd.u.scanRequest.min_chntime_btc_esco =
1376 pMac->roam.configParam.min_chntime_btc_esco;
Jeff Johnson295189b2012-06-20 16:38:30 -07001377 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
1378 if(pSession->connectedProfile.SSID.length)
1379 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301380 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList = vos_mem_malloc(sizeof(tCsrSSIDInfo));
1381 if ( NULL == pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList )
1382 status = eHAL_STATUS_FAILURE;
1383 else
1384 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001385 if(!HAL_STATUS_SUCCESS(status))
1386 {
1387 break;
1388 }
1389 pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 1;
Kiet Lam64c1b492013-07-12 13:56:44 +05301390 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID,
1391 &pSession->connectedProfile.SSID, sizeof(tSirMacSSid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001392 }
1393 else
1394 {
1395 pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 0;
1396 }
1397 if(pSession->pCurRoamProfile)
1398 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301399 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1400 if ( NULL == pScanFilter )
1401 status = eHAL_STATUS_FAILURE;
1402 else
1403 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001404 if(!HAL_STATUS_SUCCESS(status))
1405 {
1406 break;
1407 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301408 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001409 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
1410 if(!HAL_STATUS_SUCCESS(status))
1411 {
1412 break;
1413 }
1414 //Don't change variable status here because whether we can get result or not, the command goes to PE.
1415 //The status is also used to indicate whether the command is queued. Not success meaning not queue
1416 if(HAL_STATUS_SUCCESS((csrScanGetResult(pMac, pScanFilter, &hBSSList))) && hBSSList)
1417 {
1418 tANI_U8 i, nChn = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05301419 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList =
1420 vos_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
1421 if ( NULL == pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
1422 status = eHAL_STATUS_FAILURE;
1423 else
1424 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001425 if(!HAL_STATUS_SUCCESS(status))
1426 {
1427 break;
1428 }
1429 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) &&
1430 nChn < WNI_CFG_VALID_CHANNEL_LIST_LEN)
1431 {
1432 for(i = 0; i < nChn; i++)
1433 {
1434 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1435 pScanResult->BssDescriptor.channelId)
1436 {
1437 break;
1438 }
1439 }
1440 if(i == nChn)
1441 {
1442 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pScanResult->BssDescriptor.channelId;
1443 }
1444 }
1445 //Include the last connected BSS' channel
1446 if(csrRoamIsChannelValid(pMac, pSession->connectedProfile.operationChannel))
1447 {
1448 for(i = 0; i < nChn; i++)
1449 {
1450 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1451 pSession->connectedProfile.operationChannel)
1452 {
1453 break;
1454 }
1455 }
1456 if(i == nChn)
1457 {
1458 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pSession->connectedProfile.operationChannel;
1459 }
1460 }
1461 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nChn;
1462 }
1463 else
1464 {
1465 if(csrRoamIsChannelValid(pMac, pSession->connectedProfile.operationChannel))
1466 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301467 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(1);
1468 if ( NULL == pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
1469 status = eHAL_STATUS_FAILURE;
1470 else
1471 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001472 //just try the last connected channel
1473 if(HAL_STATUS_SUCCESS(status))
1474 {
1475 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[0] = pSession->connectedProfile.operationChannel;
1476 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 1;
1477 }
1478 else
1479 {
1480 break;
1481 }
1482 }
1483 }
1484 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301485 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001486 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
1487 if( !HAL_STATUS_SUCCESS( status ) )
1488 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001489 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001490 break;
1491 }
1492 } while( 0 );
1493
1494 if(!HAL_STATUS_SUCCESS(status))
1495 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001496 smsLog(pMac, LOGW, " csrScanRequestLostLink1 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001497 if(pCommand)
1498 {
1499 csrReleaseCommandScan(pMac, pCommand);
1500 }
1501 status = csrScanHandleFailedLostlink1( pMac, sessionId );
1502 }
1503 if(pScanFilter)
1504 {
1505 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301506 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001507 }
1508 if(hBSSList)
1509 {
1510 csrScanResultPurge(pMac, hBSSList);
1511 }
1512
1513 return( status );
1514}
1515
1516
1517//Lostlink2 scan is to actively scan the all SSIDs of the last roaming profile's on all matched BSS channels.
1518//Since MAC doesn't support multiple SSID, we scan all SSIDs and filter them afterwards
1519eHalStatus csrScanRequestLostLink2( tpAniSirGlobal pMac, tANI_U32 sessionId )
1520{
1521 eHalStatus status = eHAL_STATUS_SUCCESS;
1522 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1523 tCsrScanResultFilter *pScanFilter = NULL;
1524 tScanResultHandle hBSSList = NULL;
1525 tCsrScanResultInfo *pScanResult = NULL;
1526 tSmeCmd *pCommand = NULL;
1527 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1528
Jeff Johnson32d95a32012-09-10 13:15:23 -07001529 if(!pSession)
1530 {
1531 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1532 return eHAL_STATUS_FAILURE;
1533 }
1534
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001535 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001536 do
1537 {
1538 pCommand = csrGetCommandBuffer(pMac);
1539 if(!pCommand)
1540 {
1541 status = eHAL_STATUS_RESOURCES;
1542 break;
1543 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301544 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001545 pCommand->command = eSmeCommandScan;
1546 pCommand->sessionId = (tANI_U8)sessionId;
1547 pCommand->u.scanCmd.reason = eCsrScanLostLink2;
1548 pCommand->u.scanCmd.callback = NULL;
1549 pCommand->u.scanCmd.pContext = NULL;
1550 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1551 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Abhishek Singhadd13582016-09-29 17:00:03 +05301552 pCommand->u.scanCmd.u.scanRequest.max_chntime_btc_esco =
1553 pMac->roam.configParam.max_chntime_btc_esco;
1554 pCommand->u.scanCmd.u.scanRequest.min_chntime_btc_esco =
1555 pMac->roam.configParam.min_chntime_btc_esco;
Jeff Johnson295189b2012-06-20 16:38:30 -07001556 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
1557 if(pSession->pCurRoamProfile)
1558 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301559 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1560 if ( NULL == pScanFilter )
1561 status = eHAL_STATUS_FAILURE;
1562 else
1563 status = eHAL_STATUS_SUCCESS;
1564 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001565 {
1566 break;
1567 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301568 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001569 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
1570 if(!HAL_STATUS_SUCCESS(status))
1571 {
1572 break;
1573 }
1574 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1575 if(!HAL_STATUS_SUCCESS(status))
1576 {
1577 break;
1578 }
1579 if(hBSSList)
1580 {
1581 tANI_U8 i, nChn = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05301582 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList =
1583 vos_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
1584 if ( NULL == pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
1585 status = eHAL_STATUS_FAILURE;
1586 else
1587 status = eHAL_STATUS_SUCCESS;
1588 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001589 {
1590 break;
1591 }
1592 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) &&
1593 nChn < WNI_CFG_VALID_CHANNEL_LIST_LEN)
1594 {
1595 for(i = 0; i < nChn; i++)
1596 {
1597 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1598 pScanResult->BssDescriptor.channelId)
1599 {
1600 break;
1601 }
1602 }
1603 if(i == nChn)
1604 {
1605 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pScanResult->BssDescriptor.channelId;
1606 }
1607 }
1608 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nChn;
1609 }
1610 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301611 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001612 //Put to the head in pending queue
1613 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_TRUE);
1614 if( !HAL_STATUS_SUCCESS( status ) )
1615 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001616 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001617 break;
1618 }
1619 } while( 0 );
1620
1621 if(!HAL_STATUS_SUCCESS(status))
1622 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001623 smsLog(pMac, LOGW, " csrScanRequestLostLink2 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001624 if(pCommand)
1625 {
1626 csrReleaseCommandScan(pMac, pCommand);
1627 }
1628 status = csrScanHandleFailedLostlink2( pMac, sessionId );
1629 }
1630 if(pScanFilter)
1631 {
1632 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301633 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001634 }
1635 if(hBSSList)
1636 {
1637 csrScanResultPurge(pMac, hBSSList);
1638 }
1639
1640 return( status );
1641}
1642
1643
1644//To actively scan all valid channels
1645eHalStatus csrScanRequestLostLink3( tpAniSirGlobal pMac, tANI_U32 sessionId )
1646{
1647 eHalStatus status = eHAL_STATUS_SUCCESS;
1648 tSmeCmd *pCommand;
1649 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1650
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001651 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001652 do
1653 {
1654 pCommand = csrGetCommandBuffer(pMac);
1655 if(!pCommand)
1656 {
1657 status = eHAL_STATUS_RESOURCES;
1658 break;
1659 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301660 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001661 pCommand->command = eSmeCommandScan;
1662 pCommand->sessionId = (tANI_U8)sessionId;
1663 pCommand->u.scanCmd.reason = eCsrScanLostLink3;
1664 pCommand->u.scanCmd.callback = NULL;
1665 pCommand->u.scanCmd.pContext = NULL;
1666 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1667 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Abhishek Singhadd13582016-09-29 17:00:03 +05301668 pCommand->u.scanCmd.u.scanRequest.max_chntime_btc_esco =
1669 pMac->roam.configParam.max_chntime_btc_esco;
1670 pCommand->u.scanCmd.u.scanRequest.min_chntime_btc_esco =
1671 pMac->roam.configParam.min_chntime_btc_esco;
Jeff Johnson295189b2012-06-20 16:38:30 -07001672 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Kiet Lam64c1b492013-07-12 13:56:44 +05301673 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001674 //Put to the head of pending queue
1675 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_TRUE);
1676 if( !HAL_STATUS_SUCCESS( status ) )
1677 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001678 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001679 break;
1680 }
1681 } while( 0 );
1682 if(!HAL_STATUS_SUCCESS(status))
1683 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001684 smsLog(pMac, LOGW, " csrScanRequestLostLink3 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001685 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1686 {
1687 csrScanStartIdleScan(pMac);
1688 }
1689 if(pCommand)
1690 {
1691 csrReleaseCommandScan(pMac, pCommand);
1692 }
1693 }
1694
1695 return( status );
1696}
1697
1698
1699eHalStatus csrScanHandleSearchForSSID(tpAniSirGlobal pMac, tSmeCmd *pCommand)
1700{
1701 eHalStatus status = eHAL_STATUS_FAILURE;
1702 tScanResultHandle hBSSList = CSR_INVALID_SCANRESULT_HANDLE;
1703 tCsrScanResultFilter *pScanFilter = NULL;
1704 tCsrRoamProfile *pProfile = pCommand->u.scanCmd.pToRoamProfile;
1705 tANI_U32 sessionId = pCommand->sessionId;
Abhishek Singhd61b97a2015-12-17 15:23:52 +05301706 tCsrRoamSession *pSession = CSR_GET_SESSION(pMac, sessionId);
1707
Jeff Johnson295189b2012-06-20 16:38:30 -07001708 do
1709 {
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001710#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
1711 //if this scan is for LFR
1712 if(pMac->roam.neighborRoamInfo.uOsRequestedHandoff)
1713 {
1714 //notify LFR state m/c
1715 if(eHAL_STATUS_SUCCESS != csrNeighborRoamSssidScanDone(pMac, eHAL_STATUS_SUCCESS))
1716 {
Mukul Sharma20aa6582014-08-07 21:36:12 +05301717 csrNeighborRoamStartLfrScan(pMac, REASON_OS_REQUESTED_ROAMING_NOW);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001718 }
1719 status = eHAL_STATUS_SUCCESS;
1720 break;
1721 }
1722#endif
Abhishek Singhd61b97a2015-12-17 15:23:52 +05301723 if (!pSession)
1724 {
1725 smsLog(pMac, LOGE, FL("session %d not found"), sessionId);
1726 break;
1727 }
Abhishek Singhd18028d2016-02-11 17:45:54 +05301728 /* If Disconnect is already issued from HDD no need to issue connect
1729 * pSession->abortConnection will not be set in case of try
1730 * disconnect or hdd stop adaptor use connectState for these cases.
1731 */
1732 if (pSession->abortConnection ||
1733 (pMac->roam.roamSession[sessionId].connectState ==
1734 eCSR_ASSOC_STATE_TYPE_INFRA_DISCONNECTING))
Abhishek Singhd61b97a2015-12-17 15:23:52 +05301735 {
1736 smsLog(pMac, LOGE,
1737 FL("Disconnect in progress, no need to issue connect"));
1738 break;
1739 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001740 //If there is roam command waiting, ignore this roam because the newer roam command is the one to execute
1741 if(csrIsRoamCommandWaitingForSession(pMac, sessionId))
1742 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001743 smsLog(pMac, LOGW, FL(" aborts because roam command waiting"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001744 break;
1745 }
1746 if(pProfile == NULL)
1747 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301748 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1749 if ( NULL == pScanFilter )
1750 status = eHAL_STATUS_FAILURE;
1751 else
1752 status = eHAL_STATUS_SUCCESS;
1753 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001754 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301755 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001756 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1757 if(!HAL_STATUS_SUCCESS(status))
1758 break;
1759 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1760 if(!HAL_STATUS_SUCCESS(status))
1761 break;
1762 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList, eCsrHddIssued,
1763 pCommand->u.scanCmd.roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1764 if(!HAL_STATUS_SUCCESS(status))
1765 {
1766 break;
1767 }
1768 }while(0);
1769 if(!HAL_STATUS_SUCCESS(status))
1770 {
1771 if(CSR_INVALID_SCANRESULT_HANDLE != hBSSList)
1772 {
1773 csrScanResultPurge(pMac, hBSSList);
1774 }
1775 //We haven't done anything to this profile
Abhishek Singh72c2f4e2016-07-22 11:25:43 +05301776 csrRoamCallCallback(pMac, sessionId, NULL,
1777 pCommand->u.scanCmd.roamId,
1778 eCSR_ROAM_ASSOCIATION_FAILURE,
1779 eCSR_ROAM_RESULT_SCAN_FOR_SSID_FAILURE);
Jeff Johnson295189b2012-06-20 16:38:30 -07001780 //In case we have nothing else to do, restart idle scan
1781 if(csrIsConnStateDisconnected(pMac, sessionId) && !csrIsRoamCommandWaiting(pMac))
1782 {
1783 status = csrScanStartIdleScan(pMac);
1784 }
1785#ifdef FEATURE_WLAN_BTAMP_UT_RF
1786 //In case of WDS station, let it retry.
1787 if( CSR_IS_WDS_STA(pProfile) )
1788 {
1789 //Save the roma profile so we can retry
1790 csrFreeRoamProfile( pMac, sessionId );
Kiet Lam64c1b492013-07-12 13:56:44 +05301791 pSession->pCurRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1792 if ( NULL != pSession->pCurRoamProfile )
Jeff Johnson295189b2012-06-20 16:38:30 -07001793 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301794 vos_mem_set(pSession->pCurRoamProfilee, sizeof(tCsrRoamProfile), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001795 csrRoamCopyProfile(pMac, pSession->pCurRoamProfile, pProfile);
1796 }
1797 csrRoamStartJoinRetryTimer(pMac, sessionId, CSR_JOIN_RETRY_TIMEOUT_PERIOD);
1798 }
1799#endif
1800 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301801 if (pScanFilter)
Jeff Johnson295189b2012-06-20 16:38:30 -07001802 {
1803 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301804 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001805 }
1806
1807 return (status);
1808}
1809
1810
1811eHalStatus csrScanHandleSearchForSSIDFailure(tpAniSirGlobal pMac, tSmeCmd *pCommand)
1812{
1813 eHalStatus status = eHAL_STATUS_SUCCESS;
1814 tANI_U32 sessionId = pCommand->sessionId;
1815 tCsrRoamProfile *pProfile = pCommand->u.scanCmd.pToRoamProfile;
1816 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001817#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
1818 //if this scan is for LFR
1819 if(pMac->roam.neighborRoamInfo.uOsRequestedHandoff)
1820 {
1821 //notify LFR state m/c
1822 if(eHAL_STATUS_SUCCESS != csrNeighborRoamSssidScanDone(pMac, eHAL_STATUS_FAILURE))
1823 {
Mukul Sharma20aa6582014-08-07 21:36:12 +05301824 csrNeighborRoamStartLfrScan(pMac, REASON_OS_REQUESTED_ROAMING_NOW);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001825 }
1826 return eHAL_STATUS_SUCCESS;
1827 }
1828#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -07001829 if(!pSession)
1830 {
1831 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1832 return eHAL_STATUS_FAILURE;
1833 }
1834
Jeff Johnson295189b2012-06-20 16:38:30 -07001835#if defined(WLAN_DEBUG)
1836 if(pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs == 1)
1837 {
1838 char str[36];
Kiet Lam64c1b492013-07-12 13:56:44 +05301839 vos_mem_copy(str,
1840 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.ssId,
1841 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.length);
Jeff Johnson295189b2012-06-20 16:38:30 -07001842 str[pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.length] = 0;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001843 smsLog(pMac, LOGW, FL(" SSID = %s"), str);
Jeff Johnson295189b2012-06-20 16:38:30 -07001844 }
1845#endif
1846 //Check whether it is for start ibss. No need to do anything if it is a JOIN request
1847 if(pProfile && CSR_IS_START_IBSS(pProfile))
1848 {
1849 status = csrRoamIssueConnect(pMac, sessionId, pProfile, NULL, eCsrHddIssued,
1850 pCommand->u.scanCmd.roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1851 if(!HAL_STATUS_SUCCESS(status))
1852 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001853 smsLog(pMac, LOGE, FL("failed to issue startIBSS command with status = 0x%08X"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001854 csrRoamCallCallback(pMac, sessionId, NULL, pCommand->u.scanCmd.roamId, eCSR_ROAM_FAILED, eCSR_ROAM_RESULT_FAILURE);
1855 }
1856 }
1857 else
1858 {
1859 eCsrRoamResult roamResult = eCSR_ROAM_RESULT_FAILURE;
1860
1861 if(csrIsConnStateDisconnected(pMac, sessionId) &&
1862 !csrIsRoamCommandWaitingForSession(pMac, sessionId))
1863 {
1864 status = csrScanStartIdleScan(pMac);
1865 }
1866 if((NULL == pProfile) || !csrIsBssTypeIBSS(pProfile->BSSType))
1867 {
1868 //Only indicate assoc_completion if we indicate assoc_start.
1869 if(pSession->bRefAssocStartCnt > 0)
1870 {
1871 tCsrRoamInfo *pRoamInfo = NULL, roamInfo;
Kiet Lam64c1b492013-07-12 13:56:44 +05301872 vos_mem_set(&roamInfo, sizeof(tCsrRoamInfo), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001873 pRoamInfo = &roamInfo;
1874 if(pCommand->u.roamCmd.pRoamBssEntry)
1875 {
1876 tCsrScanResult *pScanResult =
1877 GET_BASE_ADDR(pCommand->u.roamCmd.pRoamBssEntry,
1878 tCsrScanResult, Link);
1879 roamInfo.pBssDesc = &pScanResult->Result.BssDescriptor;
1880 }
1881 roamInfo.statusCode = pSession->joinFailStatusCode.statusCode;
1882 roamInfo.reasonCode = pSession->joinFailStatusCode.reasonCode;
1883 pSession->bRefAssocStartCnt--;
1884 csrRoamCallCallback(pMac, sessionId, pRoamInfo,
1885 pCommand->u.scanCmd.roamId,
1886 eCSR_ROAM_ASSOCIATION_COMPLETION,
Abhishek Singh72c2f4e2016-07-22 11:25:43 +05301887 eCSR_ROAM_RESULT_SCAN_FOR_SSID_FAILURE);
Jeff Johnson295189b2012-06-20 16:38:30 -07001888 }
Madan Mohan Koyyalamudiee255f12012-09-28 15:41:19 -07001889 else
1890 {
1891 csrRoamCallCallback(pMac, sessionId, NULL,
1892 pCommand->u.scanCmd.roamId,
1893 eCSR_ROAM_ASSOCIATION_FAILURE,
Abhishek Singh72c2f4e2016-07-22 11:25:43 +05301894 eCSR_ROAM_RESULT_SCAN_FOR_SSID_FAILURE);
Madan Mohan Koyyalamudiee255f12012-09-28 15:41:19 -07001895 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001896#ifdef FEATURE_WLAN_BTAMP_UT_RF
1897 //In case of WDS station, let it retry.
1898 if( CSR_IS_WDS_STA(pProfile) )
1899 {
1900 //Save the roma profile so we can retry
1901 csrFreeRoamProfile( pMac, sessionId );
Kiet Lam64c1b492013-07-12 13:56:44 +05301902 pSession->pCurRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1903 if ( NULL != pSession->pCurRoamProfile )
Jeff Johnson295189b2012-06-20 16:38:30 -07001904 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301905 vos_mem_set(pSession->pCurRoamProfile, sizeof(tCsrRoamProfile), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001906 csrRoamCopyProfile(pMac, pSession->pCurRoamProfile, pProfile);
1907 }
1908 csrRoamStartJoinRetryTimer(pMac, sessionId, CSR_JOIN_RETRY_TIMEOUT_PERIOD);
1909 }
1910#endif
1911 }
1912 else
1913 {
1914 roamResult = eCSR_ROAM_RESULT_IBSS_START_FAILED;
1915 }
1916 csrRoamCompletion(pMac, sessionId, NULL, pCommand, roamResult, eANI_BOOLEAN_FALSE);
1917 }
1918
1919 return (status);
1920}
1921
1922
1923//After scan for cap changes, issue a roaming command to either reconnect to the AP or pick another one to connect
1924eHalStatus csrScanHandleCapChangeScanComplete(tpAniSirGlobal pMac, tANI_U32 sessionId)
1925{
1926 eHalStatus status = eHAL_STATUS_FAILURE;
1927 tScanResultHandle hBSSList = NULL;
1928 tCsrScanResultFilter *pScanFilter = NULL;
1929 tANI_U32 roamId = 0;
1930 tCsrRoamProfile *pProfile = NULL;
1931 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1932
1933 do
1934 {
1935 //Here is the profile we need to connect to
Kiet Lam64c1b492013-07-12 13:56:44 +05301936 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1937 if ( NULL == pScanFilter )
1938 status = eHAL_STATUS_FAILURE;
1939 else
1940 status = eHAL_STATUS_SUCCESS;
1941 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001942 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301943 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
1944 if (NULL == pSession) break;
1945 if (NULL == pSession->pCurRoamProfile)
Jeff Johnson295189b2012-06-20 16:38:30 -07001946 {
1947 pScanFilter->EncryptionType.numEntries = 1;
1948 pScanFilter->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_NONE;
1949 }
1950 else
1951 {
1952 //We have to make a copy of pCurRoamProfile because it will be free inside csrRoamIssueConnect
Kiet Lam64c1b492013-07-12 13:56:44 +05301953 pProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1954 if ( NULL == pProfile )
1955 status = eHAL_STATUS_FAILURE;
1956 else
1957 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001958 if(!HAL_STATUS_SUCCESS(status))
1959 break;
1960 status = csrRoamCopyProfile(pMac, pProfile, pSession->pCurRoamProfile);
1961 if(!HAL_STATUS_SUCCESS(status))
1962 break;
1963 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1964 }//We have a profile
1965 roamId = GET_NEXT_ROAM_ID(&pMac->roam);
1966 if(HAL_STATUS_SUCCESS(status))
1967 {
1968 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1969 if(HAL_STATUS_SUCCESS(status))
1970 {
1971 //we want to put the last connected BSS to the very beginning, if possible
1972 csrMoveBssToHeadFromBSSID(pMac, &pSession->connectedProfile.bssid, hBSSList);
1973 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList,
1974 eCsrCapsChange, 0, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1975 if(!HAL_STATUS_SUCCESS(status))
1976 {
1977 csrScanResultPurge(pMac, hBSSList);
1978 }
1979 }//Have scan result
1980 else
1981 {
Arif Hussaina7c8e412013-11-20 11:06:42 -08001982 smsLog(pMac, LOGW, FL("cannot find matching BSS of "
1983 MAC_ADDRESS_STR),
1984 MAC_ADDR_ARRAY(pSession->connectedProfile.bssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001985 //Disconnect
1986 csrRoamDisconnectInternal(pMac, sessionId, eCSR_DISCONNECT_REASON_UNSPECIFIED);
1987 }
1988 }
1989 }while(0);
1990 if(pScanFilter)
1991 {
1992 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301993 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001994 }
1995 if(NULL != pProfile)
1996 {
1997 csrReleaseProfile(pMac, pProfile);
Kiet Lam64c1b492013-07-12 13:56:44 +05301998 vos_mem_free(pProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07001999 }
2000
2001 return (status);
2002}
2003
2004
2005
2006eHalStatus csrScanResultPurge(tpAniSirGlobal pMac, tScanResultHandle hScanList)
2007{
2008 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
2009 tScanResultList *pScanList = (tScanResultList *)hScanList;
2010
2011 if(pScanList)
2012 {
2013 status = csrLLScanPurgeResult(pMac, &pScanList->List);
2014 csrLLClose(&pScanList->List);
Kiet Lam64c1b492013-07-12 13:56:44 +05302015 vos_mem_free(pScanList);
Jeff Johnson295189b2012-06-20 16:38:30 -07002016 }
2017 return (status);
2018}
2019
2020
2021static tANI_U32 csrGetBssPreferValue(tpAniSirGlobal pMac, int rssi)
2022{
2023 tANI_U32 ret = 0;
2024 int i = CSR_NUM_RSSI_CAT - 1;
2025
2026 while(i >= 0)
2027 {
2028 if(rssi >= pMac->roam.configParam.RSSICat[i])
2029 {
2030 ret = pMac->roam.configParam.BssPreferValue[i];
2031 break;
2032 }
2033 i--;
2034 };
2035
2036 return (ret);
2037}
2038
2039
2040//Return a CapValue base on the capabilities of a BSS
2041static tANI_U32 csrGetBssCapValue(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes)
2042{
2043 tANI_U32 ret = CSR_BSS_CAP_VALUE_NONE;
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08002044#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_ESE) || defined(FEATURE_WLAN_LFR)
Madan Mohan Koyyalamudid5026072012-11-30 14:56:21 -08002045 if(CSR_IS_ROAM_PREFER_5GHZ(pMac))
2046 {
2047 if((pBssDesc) && CSR_IS_CHANNEL_5GHZ(pBssDesc->channelId))
2048 {
2049 ret += CSR_BSS_CAP_VALUE_5GHZ;
2050 }
2051 }
2052#endif
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002053 /* if strict select 5GHz is non-zero then ignore the capability checking */
2054 if (pIes && !CSR_IS_SELECT_5GHZ_MARGIN(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -07002055 {
2056 //We only care about 11N capability
2057 if(pIes->HTCaps.present)
2058 {
2059 ret += CSR_BSS_CAP_VALUE_HT;
2060 }
2061 if(CSR_IS_QOS_BSS(pIes))
2062 {
2063 ret += CSR_BSS_CAP_VALUE_WMM;
2064 //Give advantage to UAPSD
2065 if(CSR_IS_UAPSD_BSS(pIes))
2066 {
2067 ret += CSR_BSS_CAP_VALUE_UAPSD;
2068 }
2069 }
2070 }
2071
2072 return (ret);
2073}
2074
Kapil Guptab3a981b2016-06-26 13:36:51 +05302075#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
2076
2077/* Calculate channel weight based on other APs RSSI and count for
2078 * PER based roaming */
2079static tANI_U32 GetPERRoamRssiCountWeight(tANI_S32 rssi, tANI_S32 count)
2080{
2081 tANI_S32 rssiWeight=0;
2082 tANI_S32 countWeight=0;
2083 tANI_S32 rssicountWeight=0;
2084
2085 rssiWeight = ROAMING_RSSI_WEIGHT * (rssi - MIN_RSSI)
2086 /(MAX_RSSI - MIN_RSSI);
2087
2088 if(rssiWeight > ROAMING_RSSI_WEIGHT)
2089 rssiWeight = ROAMING_RSSI_WEIGHT;
2090 else if (rssiWeight < 0)
2091 rssiWeight = 0;
2092
2093 countWeight = ROAM_AP_COUNT_WEIGHT * (count + ROAM_MIN_COUNT)
2094 /(ROAM_MAX_COUNT + ROAM_MIN_COUNT);
2095
2096 if(countWeight > ROAM_AP_COUNT_WEIGHT)
2097 countWeight = ROAM_AP_COUNT_WEIGHT;
2098
2099 rssicountWeight = ROAM_MAX_WEIGHT - (rssiWeight + countWeight);
2100
2101 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO_HIGH,
2102 FL("rssiWeight=%d, countWeight=%d, rssicountWeight=%d rssi=%d count=%d"),
2103 rssiWeight, countWeight, rssicountWeight, rssi, count);
2104
2105 return rssicountWeight;
2106}
2107
2108/* Calculate BSS score based on AP capabilty and channel condition
2109 * for PER based roaming */
2110static tANI_U32 calculateBssScore(tSirBssDescription *bssInfo,
2111 tANI_S32 best_rssi, tANI_S32 ap_cnt, tANI_S32 cca)
2112{
2113 tANI_S32 score = 0;
2114 tANI_S32 ap_load = 0;
2115 tANI_S32 normalised_width = PER_ROAM_20MHZ;
Sen, Devendra6940d0c2016-09-07 12:42:46 +05302116 tANI_S32 normalised_rssi = 0;
Kapil Guptab3a981b2016-06-26 13:36:51 +05302117 tANI_S32 channel_weight;
2118 if (bssInfo->rssi) {
2119 /* Calculate % of rssi we are getting
2120 * max = 100
2121 * min = 0
2122 * less than -40 = 100%
2123 * -40 - -55 = 80%
2124 * -55 - -65 = 60%
2125 * below that = 100 - value
2126 * TODO: a linear decrement function after PER_ROAM_GOOD_RSSI_WEIGHT
2127 * since throughput decrements linearly after PER_ROAM_GOOD_RSSI_WEIGHT
2128 **/
2129 if (bssInfo->rssi >= PER_EXCELENT_RSSI)
2130 normalised_rssi = PER_ROAM_EXCELLENT_RSSI_WEIGHT;
2131 else if (bssInfo->rssi >= PER_GOOD_RSSI)
2132 normalised_rssi = PER_ROAM_GOOD_RSSI_WEIGHT;
2133 else if (bssInfo->rssi >= PER_POOR_RSSI)
2134 normalised_rssi = PER_ROAM_BAD_RSSI_WEIGHT;
2135 else
2136 normalised_rssi = bssInfo->rssi - MIN_RSSI;
2137
2138 /* Calculate score part for rssi */
2139 score += (normalised_rssi * RSSI_WEIGHTAGE);
2140 }
2141
2142 if (bssInfo->HTCapsPresent) {
2143 score += PER_ROAM_MAX_WEIGHT * HT_CAPABILITY_WEIGHTAGE;
2144 }
2145 /* VHT caps are available */
2146 if (bssInfo->vhtCapsPresent) {
2147 score += PER_ROAM_MAX_WEIGHT * VHT_CAP_WEIGHTAGE;
2148 }
2149
2150 if (bssInfo->beacomformingCapable)
2151 score += PER_ROAM_MAX_WEIGHT * BEAMFORMING_CAP_WEIGHTAGE;
2152
2153 /* Channel width 20Mhz=30, 40Mhz=70, 80Mhz=100 */
2154 if (bssInfo->chanWidth == eHT_CHANNEL_WIDTH_80MHZ)
2155 normalised_width = PER_ROAM_80MHZ;
2156 else if (bssInfo->chanWidth == eHT_CHANNEL_WIDTH_40MHZ)
2157 normalised_width = PER_ROAM_40MHZ;
2158 else
2159 normalised_width = PER_ROAM_20MHZ;
2160 score += normalised_width * CHAN_WIDTH_WEIGHTAGE;
2161
2162 /* Channel Band, Channel Number */
2163 if (GetRFBand(bssInfo->channelId) == SIR_BAND_5_GHZ)
2164 score += PER_ROAM_MAX_WEIGHT * CHAN_BAND_WEIGHTAGE;
2165
2166 /* WMM emabled */
2167 if (bssInfo->wmeInfoPresent)
2168 score += PER_ROAM_MAX_WEIGHT * WMM_WEIGHTAGE;
2169
2170#if defined(FEATURE_WLAN_ESE) || defined(WLAN_FEATURE_ROAM_SCAN_OFFLOAD)
2171 /* AP load Ie */
2172 if (bssInfo->QBSSLoad_present) {
2173 /* calculate value in % */
2174 ap_load = (bssInfo->QBSS_ChanLoad * PER_ROAM_MAX_WEIGHT) / MAX_AP_LOAD;
2175 }
2176#endif
Kapil Guptab3a981b2016-06-26 13:36:51 +05302177 /* if CCA consideration is off in configuration, FW will send 50% for
2178 every channel which should be considered as it is */
2179 if (ap_load)
2180 score += (100 - ap_load) * CCA_WEIGHTAGE;
2181 else
2182 score += (100 - cca) * CCA_WEIGHTAGE;
2183
2184 channel_weight = GetPERRoamRssiCountWeight(best_rssi, ap_cnt);
2185
2186 score += channel_weight * OTHER_AP_WEIGHT;
2187
2188 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO_LOW,
2189 FL("rssi=%d normalized_rssi=%d htcaps=%d vht=%d bw=%d channel=%d wmm=%d beamforming=%d ap_load=%d channel_weight=%d"),
2190 bssInfo->rssi, normalised_rssi, bssInfo->HTCapsPresent,
2191 bssInfo->vhtCapsPresent, bssInfo->chanWidth,
2192 bssInfo->channelId, bssInfo->wmeInfoPresent,
2193 bssInfo->beacomformingCapable, ap_load, channel_weight);
2194 return score;
2195}
2196
2197/* Calculate candidate AP score for PER based roaming */
2198static tANI_S32 csrFindCongestionScore (tpAniSirGlobal pMac, tCsrScanResult *pBss)
2199{
2200 tANI_S32 score = 0;
2201 tANI_S32 i;
2202 tANI_S32 candidateApCnt, best_rssi, other_ap_cnt;
2203 tANI_U32 current_timestamp;
2204 tpCsrNeighborRoamControlInfo pNeighborRoamInfo =
2205 &pMac->roam.neighborRoamInfo;
2206
2207 tSirBssDescription *bssInfo = &(pBss->Result.BssDescriptor);
2208 pBss->congestionScore = 0;
2209 for (i = 0; i < pMac->PERroamCandidatesCnt; i++)
2210 if (pMac->candidateChannelInfo[i].channelNumber ==
2211 pBss->Result.BssDescriptor.channelId)
2212 break;
2213
2214 if (i == SIR_PER_ROAM_MAX_CANDIDATE_CNT) {
2215 smsLog(pMac, LOGE,
2216 FL("candidate chan info not found for channel %d bssid "
2217 MAC_ADDRESS_STR), pBss->Result.BssDescriptor.channelId,
2218 MAC_ADDR_ARRAY(pBss->Result.BssDescriptor.bssId));
2219 return -1;
2220 }
2221
Kapil Gupta192d9d42016-11-25 16:24:13 +05302222 if (bssInfo->rssi < pMac->roam.configParam.PERMinRssiThresholdForRoam) {
Kapil Guptaa040e772016-09-15 19:03:45 +05302223 smsLog(pMac, LOG1,
2224 FL("discrarding candidate due to low rssi=%d bssid "
2225 MAC_ADDRESS_STR), bssInfo->rssi,
2226 MAC_ADDR_ARRAY(pBss->Result.BssDescriptor.bssId));
2227 return 0;
2228 }
Kapil Guptab3a981b2016-06-26 13:36:51 +05302229 /* find best RSSI of other AP in this channel */
2230 best_rssi = MIN_RSSI;
2231 for (other_ap_cnt = 0; other_ap_cnt <
2232 pMac->candidateChannelInfo[i].otherApCount; other_ap_cnt++) {
2233 if (pMac->candidateChannelInfo[i].otherApRssi[other_ap_cnt] > best_rssi)
2234 best_rssi = pMac->candidateChannelInfo[i].otherApRssi[other_ap_cnt];
2235 }
2236
2237 score = calculateBssScore(bssInfo, best_rssi,
2238 pMac->candidateChannelInfo[i].otherApCount,
2239 pMac->candidateChannelInfo[i].channelCCA);
2240 current_timestamp = jiffies_to_msecs(jiffies);
2241
2242 /* penalty logic */
2243
2244 /* In the previous list */
2245 for (candidateApCnt = 0; candidateApCnt <
2246 SIR_PER_ROAM_MAX_CANDIDATE_CNT; candidateApCnt++) {
2247 if (sirCompareMacAddr(pMac->previousRoamApInfo[candidateApCnt].bssAddr,
2248 pBss->Result.BssDescriptor.bssId) &&
2249 ((current_timestamp - pMac->previousRoamApInfo[candidateApCnt].timeStamp) <
2250 PENALTY_TIMEOUT)) {
2251 score = (score * PENALTY_REMAINING_SCORE)/PENALTY_TOTAL_SCORE;
2252 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
2253 FL("AP BSSID " MAC_ADDRESS_STR "adding penalty(in previous list)new score %d"),
2254 MAC_ADDR_ARRAY(pBss->Result.BssDescriptor.bssId),
2255 score);
2256 break;
2257 }
2258 }
2259 /* preauth failed last time */
2260 for (candidateApCnt = 0; candidateApCnt <
2261 MAX_NUM_PREAUTH_FAIL_LIST_ADDRESS; candidateApCnt++) {
2262 if (sirCompareMacAddr(pNeighborRoamInfo->FTRoamInfo.
2263 preAuthFailList.macAddress[candidateApCnt],
2264 pBss->Result.BssDescriptor.bssId)) {
2265 score = (score * PENALTY_REMAINING_SCORE)/PENALTY_TOTAL_SCORE;
2266 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
2267 FL("AP BSSID " MAC_ADDRESS_STR "adding penalty(previously auth failed)new score %d"),
2268 MAC_ADDR_ARRAY(pBss->Result.BssDescriptor.bssId),
2269 score);
2270 break;
2271 }
2272 }
2273 pBss->congestionScore = score;
2274
2275 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
2276 FL("AP BSSID " MAC_ADDRESS_STR " score %d channel %d"),
2277 MAC_ADDR_ARRAY(pBss->Result.BssDescriptor.bssId),
2278 score, pBss->Result.BssDescriptor.channelId);
2279 return 0;
2280}
2281
2282/* Calculate current AP score for PER based roaming */
2283static tANI_S32 csrFindSelfCongestionScore(tpAniSirGlobal pMac,
2284 tSirBssDescription *bssInfo)
2285{
2286 tANI_S32 i, best_rssi, other_ap_cnt;
2287 tANI_S32 score = 0;
Kapil Guptac6ac4772016-08-05 20:25:16 +05302288 tCsrRoamSession *pSession = CSR_GET_SESSION(pMac,
2289 pMac->roam.roamSession->sessionId);
2290
2291 if (pSession == NULL)
2292 return -1;
Kapil Guptab3a981b2016-06-26 13:36:51 +05302293
2294 for (i = 0; i <= pMac->PERroamCandidatesCnt; i++)
2295 if (pMac->candidateChannelInfo[i].channelNumber == bssInfo->channelId)
2296 break;
2297 if (i > pMac->PERroamCandidatesCnt) {
2298 /* home channel info is not present, no need to roam */
2299 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR,
2300 FL("home channel %d congestion info not present"),
2301 bssInfo->channelId);
2302 pMac->currentBssScore = PER_ROAM_MAX_BSS_SCORE;
2303 return -1;
2304 }
2305
2306 /* find best RSSI of other AP in this channel */
2307 best_rssi = MIN_RSSI;
2308 for (other_ap_cnt = 0; other_ap_cnt <
2309 pMac->candidateChannelInfo[i].otherApCount; other_ap_cnt++) {
2310 if (pMac->candidateChannelInfo[i].otherApRssi[other_ap_cnt] > best_rssi)
2311 best_rssi = pMac->candidateChannelInfo[i].otherApRssi[other_ap_cnt];
2312 }
2313
Kapil Guptac6ac4772016-08-05 20:25:16 +05302314 /* update latest RSSI for current AP */
2315 WLANTL_GetRssi(vos_get_global_context(VOS_MODULE_ID_SME, NULL),
2316 pSession->connectedInfo.staId,
2317 &bssInfo->rssi);
2318
Kapil Guptab3a981b2016-06-26 13:36:51 +05302319 score = calculateBssScore(bssInfo, best_rssi,
2320 pMac->candidateChannelInfo[i].otherApCount,
2321 pMac->candidateChannelInfo[i].channelCCA);
2322 pMac->currentBssScore = score;
2323 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
2324 FL("PER Roam Current AP score %d channel %d"),
2325 score, bssInfo->channelId);
2326 return 0;
2327}
2328
Kapil Guptab79e76f2016-09-12 20:04:37 +05302329
Kapil Guptab3a981b2016-06-26 13:36:51 +05302330static tANI_BOOLEAN csrIsBetterBssInCongestion(tCsrScanResult *pBss1,
2331 tCsrScanResult *pBss2)
2332{
2333 tANI_BOOLEAN ret;
2334
2335 if(CSR_IS_BETTER_PREFER_VALUE(pBss1->congestionScore,
2336 pBss2->congestionScore))
2337 ret = eANI_BOOLEAN_TRUE;
2338 else
2339 ret = eANI_BOOLEAN_FALSE;
2340
2341 return (ret);
2342}
2343#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002344
2345//To check whther pBss1 is better than pBss2
2346static tANI_BOOLEAN csrIsBetterBss(tCsrScanResult *pBss1, tCsrScanResult *pBss2)
2347{
2348 tANI_BOOLEAN ret;
2349
2350 if(CSR_IS_BETTER_PREFER_VALUE(pBss1->preferValue, pBss2->preferValue))
2351 {
2352 ret = eANI_BOOLEAN_TRUE;
2353 }
2354 else if(CSR_IS_EQUAL_PREFER_VALUE(pBss1->preferValue, pBss2->preferValue))
2355 {
2356 if(CSR_IS_BETTER_CAP_VALUE(pBss1->capValue, pBss2->capValue))
2357 {
2358 ret = eANI_BOOLEAN_TRUE;
2359 }
2360 else
2361 {
2362 ret = eANI_BOOLEAN_FALSE;
2363 }
2364 }
2365 else
2366 {
2367 ret = eANI_BOOLEAN_FALSE;
2368 }
2369
2370 return (ret);
2371}
2372
2373
Srikant Kuppa866893f2012-12-27 17:28:14 -08002374#ifdef FEATURE_WLAN_LFR
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002375//Add the channel to the occupiedChannels array
2376static void csrScanAddToOccupiedChannels(
Srikant Kuppa866893f2012-12-27 17:28:14 -08002377 tpAniSirGlobal pMac,
2378 tCsrScanResult *pResult,
2379 tCsrChannel *pOccupiedChannels,
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002380 tDot11fBeaconIEs *pIes)
2381{
2382 eHalStatus status;
2383 tANI_U8 channel;
2384 tANI_U8 numOccupiedChannels = pOccupiedChannels->numChannels;
2385 tANI_U8 *pOccupiedChannelList = pOccupiedChannels->channelList;
2386
2387 channel = pResult->Result.BssDescriptor.channelId;
2388
2389 if (!csrIsChannelPresentInList(pOccupiedChannelList, numOccupiedChannels, channel)
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08002390 && csrNeighborRoamConnectedProfileMatch(pMac, pResult, pIes))
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002391 {
Srikant Kuppa866893f2012-12-27 17:28:14 -08002392 status = csrAddToChannelListFront(pOccupiedChannelList, numOccupiedChannels, channel);
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002393 if(HAL_STATUS_SUCCESS(status))
Srikant Kuppa866893f2012-12-27 17:28:14 -08002394 {
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002395 pOccupiedChannels->numChannels++;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002396 smsLog(pMac, LOG2, FL("%s: added channel %d to the list (count=%d)"),
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08002397 __func__, channel, pOccupiedChannels->numChannels);
Srikant Kuppa866893f2012-12-27 17:28:14 -08002398 if (pOccupiedChannels->numChannels > CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN)
2399 pOccupiedChannels->numChannels = CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN;
2400 }
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002401 }
2402}
Mukul Sharma9e4e0f92015-02-13 18:45:20 +05302403
2404void csrAddChannelToOccupiedChannelList(tpAniSirGlobal pMac,
2405 tANI_U8 channel)
2406{
2407 eHalStatus status;
2408 tCsrChannel *pOccupiedChannels = &pMac->scan.occupiedChannels;
2409 tANI_U8 numOccupiedChannels = pOccupiedChannels->numChannels;
2410 tANI_U8 *pOccupiedChannelList = pOccupiedChannels->channelList;
2411 if (!csrIsChannelPresentInList(pOccupiedChannelList,
2412 numOccupiedChannels, channel))
2413 {
2414 status = csrAddToChannelListFront(pOccupiedChannelList,
2415 numOccupiedChannels, channel);
2416 if(HAL_STATUS_SUCCESS(status))
2417 {
2418 pOccupiedChannels->numChannels++;
2419 smsLog(pMac, LOG2, FL("added channel %d to the list (count=%d)"),
2420 channel, pOccupiedChannels->numChannels);
2421 if (pOccupiedChannels->numChannels >
2422 CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN)
2423 {
2424 pOccupiedChannels->numChannels =
2425 CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN;
2426 smsLog(pMac, LOG2,
2427 FL("trim no of Channels for Occ channel list"));
2428 }
2429 }
2430 }
2431}
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002432#endif
2433
Jeff Johnson295189b2012-06-20 16:38:30 -07002434//Put the BSS into the scan result list
2435//pIes can not be NULL
2436static void csrScanAddResult(tpAniSirGlobal pMac, tCsrScanResult *pResult, tDot11fBeaconIEs *pIes)
2437{
Srinivas28b5b4e2012-12-12 13:07:53 -08002438#ifdef FEATURE_WLAN_LFR
2439 tpCsrNeighborRoamControlInfo pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
2440#endif
2441
Jeff Johnson295189b2012-06-20 16:38:30 -07002442 pResult->preferValue = csrGetBssPreferValue(pMac, (int)pResult->Result.BssDescriptor.rssi);
2443 pResult->capValue = csrGetBssCapValue(pMac, &pResult->Result.BssDescriptor, pIes);
2444 csrLLInsertTail( &pMac->scan.scanResultList, &pResult->Link, LL_ACCESS_LOCK );
Srikant Kuppa866893f2012-12-27 17:28:14 -08002445#ifdef FEATURE_WLAN_LFR
Srinivas28b5b4e2012-12-12 13:07:53 -08002446 if(0 == pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels)
2447 {
2448 /* Build the occupied channel list, only if "gNeighborScanChannelList" is
2449 NOT set in the cfg.ini file */
2450 csrScanAddToOccupiedChannels(pMac, pResult, &pMac->scan.occupiedChannels, pIes);
2451 }
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002452#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002453}
2454
2455
2456eHalStatus csrScanGetResult(tpAniSirGlobal pMac, tCsrScanResultFilter *pFilter, tScanResultHandle *phResult)
2457{
2458 eHalStatus status;
2459 tScanResultList *pRetList;
2460 tCsrScanResult *pResult, *pBssDesc;
2461 tANI_U32 count = 0;
2462 tListElem *pEntry;
2463 tANI_U32 bssLen, allocLen;
2464 eCsrEncryptionType uc = eCSR_ENCRYPT_TYPE_NONE, mc = eCSR_ENCRYPT_TYPE_NONE;
2465 eCsrAuthType auth = eCSR_AUTH_TYPE_OPEN_SYSTEM;
2466 tDot11fBeaconIEs *pIes, *pNewIes;
2467 tANI_BOOLEAN fMatch;
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002468 tANI_U16 i = 0;
Kapil Guptab3a981b2016-06-26 13:36:51 +05302469 tCsrRoamSession *pSession = CSR_GET_SESSION(pMac,
2470 pMac->roam.roamSession->sessionId);
2471
Jeff Johnson295189b2012-06-20 16:38:30 -07002472 if(phResult)
2473 {
2474 *phResult = CSR_INVALID_SCANRESULT_HANDLE;
2475 }
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002476
2477 if (pMac->roam.configParam.nSelect5GHzMargin)
2478 {
2479 pMac->scan.inScanResultBestAPRssi = -128;
2480 csrLLLock(&pMac->scan.scanResultList);
2481
2482 /* Find out the best AP Rssi going thru the scan results */
2483 pEntry = csrLLPeekHead(&pMac->scan.scanResultList, LL_ACCESS_NOLOCK);
2484 while ( NULL != pEntry)
2485 {
2486 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002487 fMatch = FALSE;
2488
2489 if (pFilter)
2490 for(i = 0; i < pFilter->SSIDs.numOfSSIDs; i++)
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002491 {
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002492 fMatch = csrIsSsidMatch( pMac, pFilter->SSIDs.SSIDList[i].SSID.ssId, pFilter->SSIDs.SSIDList[i].SSID.length,
2493 pBssDesc->Result.ssId.ssId,
2494 pBssDesc->Result.ssId.length, eANI_BOOLEAN_TRUE );
2495 if (fMatch)
2496 {
2497 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
2498
2499 //At this time, pBssDescription->Result.pvIes may be NULL
2500 if( !pIes && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
2501 &pBssDesc->Result.BssDescriptor, &pIes))) )
2502 {
2503 continue;
2504 }
2505
2506 smsLog(pMac, LOG1, FL("SSID Matched"));
Leela Venkata Kiran Kumar Reddy Chiralae208a832014-04-27 22:34:25 -07002507
Leela Venkata Kiran Kumar Reddy Chiralaf257bef2014-04-11 18:48:12 -07002508 if ( pFilter->bOSENAssociation )
2509 {
2510 fMatch = TRUE;
2511 }
Leela Venkata Kiran Kumar Reddy Chiralae208a832014-04-27 22:34:25 -07002512 else
2513 {
Abhishek Singh658d4de2014-06-26 10:53:15 +05302514#ifdef WLAN_FEATURE_11W
Abhishek Singh3b56d3a2014-06-25 12:37:39 +05302515 fMatch = csrIsSecurityMatch(pMac, &pFilter->authType,
2516 &pFilter->EncryptionType,
2517 &pFilter->mcEncryptionType,
2518 &pFilter->MFPEnabled,
2519 &pFilter->MFPRequired,
2520 &pFilter->MFPCapable,
2521 &pBssDesc->Result.BssDescriptor,
2522 pIes, NULL, NULL, NULL );
Abhishek Singh658d4de2014-06-26 10:53:15 +05302523#else
2524 fMatch = csrIsSecurityMatch(pMac, &pFilter->authType,
2525 &pFilter->EncryptionType,
2526 &pFilter->mcEncryptionType,
2527 NULL, NULL, NULL,
2528 &pBssDesc->Result.BssDescriptor,
2529 pIes, NULL, NULL, NULL );
2530#endif
Leela Venkata Kiran Kumar Reddy Chiralae208a832014-04-27 22:34:25 -07002531 }
2532 if ((pBssDesc->Result.pvIes == NULL) && pIes)
2533 vos_mem_free(pIes);
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002534
2535 if (fMatch)
2536 smsLog(pMac, LOG1, FL(" Security Matched"));
2537 }
2538 }
2539
2540 if (fMatch && (pBssDesc->Result.BssDescriptor.rssi > pMac->scan.inScanResultBestAPRssi))
2541 {
2542 smsLog(pMac, LOG1, FL("Best AP Rssi changed from %d to %d"),
2543 pMac->scan.inScanResultBestAPRssi,
2544 pBssDesc->Result.BssDescriptor.rssi);
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002545 pMac->scan.inScanResultBestAPRssi = pBssDesc->Result.BssDescriptor.rssi;
2546 }
2547 pEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
2548 }
2549
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002550 if ( -128 != pMac->scan.inScanResultBestAPRssi)
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002551 {
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002552 smsLog(pMac, LOG1, FL("Best AP Rssi is %d"), pMac->scan.inScanResultBestAPRssi);
2553 /* Modify Rssi category based on best AP Rssi */
2554 csrAssignRssiForCategory(pMac, pMac->scan.inScanResultBestAPRssi, pMac->roam.configParam.bCatRssiOffset);
2555 pEntry = csrLLPeekHead(&pMac->scan.scanResultList, LL_ACCESS_NOLOCK);
2556 while ( NULL != pEntry)
2557 {
2558 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002559
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002560 /* re-assign preference value based on modified rssi bucket */
2561 pBssDesc->preferValue = csrGetBssPreferValue(pMac, (int)pBssDesc->Result.BssDescriptor.rssi);
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002562
Arif Hussaina7c8e412013-11-20 11:06:42 -08002563 smsLog(pMac, LOG2, FL("BSSID("MAC_ADDRESS_STR
Jeff Johnson123ed002013-11-22 17:39:55 -08002564 ") Rssi(%d) Chnl(%d) PrefVal(%u) SSID=%.*s"),
Arif Hussaina7c8e412013-11-20 11:06:42 -08002565 MAC_ADDR_ARRAY(pBssDesc->Result.BssDescriptor.bssId),
2566 pBssDesc->Result.BssDescriptor.rssi,
2567 pBssDesc->Result.BssDescriptor.channelId,
2568 pBssDesc->preferValue,
2569 pBssDesc->Result.ssId.length, pBssDesc->Result.ssId.ssId);
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002570
2571 pEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
2572 }
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002573 }
2574
2575 csrLLUnlock(&pMac->scan.scanResultList);
2576 }
2577
Kiet Lam64c1b492013-07-12 13:56:44 +05302578 pRetList = vos_mem_malloc(sizeof(tScanResultList));
2579 if ( NULL == pRetList )
2580 status = eHAL_STATUS_FAILURE;
2581 else
2582 status = eHAL_STATUS_SUCCESS;
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002583 if(HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07002584 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302585 vos_mem_set(pRetList, sizeof(tScanResultList), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002586 csrLLOpen(pMac->hHdd, &pRetList->List);
2587 pRetList->pCurEntry = NULL;
Kapil Guptab3a981b2016-06-26 13:36:51 +05302588#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
2589 if (pFilter && pFilter->isPERRoamScan)
2590 if (pSession && pSession->pConnectBssDesc)
2591 csrFindSelfCongestionScore(pMac,
2592 pSession->pConnectBssDesc);
2593#endif
2594
Jeff Johnson295189b2012-06-20 16:38:30 -07002595 csrLLLock(&pMac->scan.scanResultList);
2596 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
2597 while( pEntry )
2598 {
2599 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2600 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
2601 //if pBssDesc->Result.pvIes is NULL, we need to free any memory allocated by csrMatchBSS
2602 //for any error condition, otherwiase, it will be freed later.
2603 //reset
2604 fMatch = eANI_BOOLEAN_FALSE;
2605 pNewIes = NULL;
2606
2607 if(pFilter)
2608 {
2609 fMatch = csrMatchBSS(pMac, &pBssDesc->Result.BssDescriptor, pFilter, &auth, &uc, &mc, &pIes);
2610 if( NULL != pIes )
2611 {
2612 //Only save it when matching
2613 if(fMatch)
2614 {
2615 if( !pBssDesc->Result.pvIes )
2616 {
2617 //csrMatchBSS allocates the memory. Simply pass it and it is freed later
2618 pNewIes = pIes;
2619 }
2620 else
2621 {
2622 //The pIes is allocated by someone else. make a copy
2623 //Only to save parsed IEs if caller provides a filter. Most likely the caller
2624 //is using to for association, hence save the parsed IEs
Kiet Lam64c1b492013-07-12 13:56:44 +05302625 pNewIes = vos_mem_malloc(sizeof(tDot11fBeaconIEs));
2626 if ( NULL == pNewIes )
2627 status = eHAL_STATUS_FAILURE;
2628 else
2629 status = eHAL_STATUS_SUCCESS;
2630 if ( HAL_STATUS_SUCCESS( status ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07002631 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302632 vos_mem_copy(pNewIes, pIes, sizeof( tDot11fBeaconIEs ));
Jeff Johnson295189b2012-06-20 16:38:30 -07002633 }
2634 else
2635 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002636 smsLog(pMac, LOGE, FL(" fail to allocate memory for IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002637 //Need to free memory allocated by csrMatchBSS
2638 if( !pBssDesc->Result.pvIes )
2639 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302640 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07002641 }
2642 break;
2643 }
2644 }
2645 }//fMatch
2646 else if( !pBssDesc->Result.pvIes )
2647 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302648 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07002649 }
2650 }
2651 }
2652 if(NULL == pFilter || fMatch)
2653 {
2654 bssLen = pBssDesc->Result.BssDescriptor.length + sizeof(pBssDesc->Result.BssDescriptor.length);
2655 allocLen = sizeof( tCsrScanResult ) + bssLen;
Kiet Lam64c1b492013-07-12 13:56:44 +05302656 pResult = vos_mem_malloc(allocLen);
2657 if ( NULL == pResult )
2658 status = eHAL_STATUS_FAILURE;
2659 else
2660 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07002661 if(!HAL_STATUS_SUCCESS(status))
2662 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002663 smsLog(pMac, LOGE, FL(" fail to allocate memory for scan result, len=%d"), allocLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07002664 if(pNewIes)
2665 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302666 vos_mem_free(pNewIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07002667 }
2668 break;
2669 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302670 vos_mem_set(pResult, allocLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002671 pResult->capValue = pBssDesc->capValue;
2672 pResult->preferValue = pBssDesc->preferValue;
2673 pResult->ucEncryptionType = uc;
2674 pResult->mcEncryptionType = mc;
2675 pResult->authType = auth;
2676 pResult->Result.ssId = pBssDesc->Result.ssId;
Padma, Santhosh Kumare12fd982016-03-21 13:07:52 +05302677 pResult->Result.timer = pBssDesc->Result.timer;
Jeff Johnson295189b2012-06-20 16:38:30 -07002678 //save the pIes for later use
2679 pResult->Result.pvIes = pNewIes;
2680 //save bss description
Kiet Lam64c1b492013-07-12 13:56:44 +05302681 vos_mem_copy(&pResult->Result.BssDescriptor,
2682 &pBssDesc->Result.BssDescriptor, bssLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07002683 //No need to lock pRetList because it is locally allocated and no outside can access it at this time
2684 if(csrLLIsListEmpty(&pRetList->List, LL_ACCESS_NOLOCK))
2685 {
Kapil Guptab3a981b2016-06-26 13:36:51 +05302686#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
2687 if (pFilter && pFilter->isPERRoamScan) {
2688 csrFindCongestionScore(pMac, pResult);
2689 if (pResult->congestionScore > pMac->currentBssScore) {
2690 csrLLInsertTail(&pRetList->List, &pResult->Link,
2691 LL_ACCESS_NOLOCK);
2692 smsLog(pMac, LOGW,
2693 FL("added one entry in LL in PER Roam list"));
2694 }
2695 }
2696 else
2697#endif
2698 {
2699 csrLLInsertTail(&pRetList->List, &pResult->Link,
2700 LL_ACCESS_NOLOCK);
2701 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002702 }
2703 else
2704 {
2705 //To sort the list
2706 tListElem *pTmpEntry;
2707 tCsrScanResult *pTmpResult;
2708
2709 pTmpEntry = csrLLPeekHead(&pRetList->List, LL_ACCESS_NOLOCK);
2710 while(pTmpEntry)
2711 {
2712 pTmpResult = GET_BASE_ADDR( pTmpEntry, tCsrScanResult, Link );
Kapil Guptab3a981b2016-06-26 13:36:51 +05302713#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
2714 if (pFilter && pFilter->isPERRoamScan) {
2715 csrFindCongestionScore(pMac, pResult);
2716 if(csrIsBetterBssInCongestion(pResult, pTmpResult)&&
2717 (pResult->congestionScore > pMac->currentBssScore))
2718 {
2719 csrLLInsertEntry(&pRetList->List, pTmpEntry,
2720 &pResult->Link, LL_ACCESS_NOLOCK);
2721 smsLog(pMac, LOGW,
2722 FL("added another entry in LL in PER Roam list"));
2723 pResult = NULL;
2724 break;
2725 }
2726 pTmpEntry = csrLLNext(&pRetList->List,
2727 pTmpEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07002728 }
Kapil Guptab3a981b2016-06-26 13:36:51 +05302729 else
2730#endif
2731 {
2732 if(csrIsBetterBss(pResult, pTmpResult))
2733 {
2734 csrLLInsertEntry(&pRetList->List, pTmpEntry,
2735 &pResult->Link, LL_ACCESS_NOLOCK);
2736 //To indicate we are done
2737 pResult = NULL;
2738 break;
2739 }
2740 pTmpEntry = csrLLNext(&pRetList->List,
2741 pTmpEntry, LL_ACCESS_NOLOCK);
2742 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002743 }
2744 if(pResult != NULL)
Kapil Guptab3a981b2016-06-26 13:36:51 +05302745#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
2746 if ((pFilter && !pFilter->isPERRoamScan) ||
2747 (pFilter == NULL) ||
2748 (pResult->congestionScore > pMac->currentBssScore))
2749#endif
2750 {
2751 //This one is not better than any one
2752 csrLLInsertTail(&pRetList->List,
2753 &pResult->Link, LL_ACCESS_NOLOCK);
2754 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002755 }
2756 count++;
2757 }
2758 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK );
2759 }//while
2760 csrLLUnlock(&pMac->scan.scanResultList);
2761
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002762 smsLog(pMac, LOG2, FL("return %d BSS"), csrLLCount(&pRetList->List));
Jeff Johnson295189b2012-06-20 16:38:30 -07002763
2764 if( !HAL_STATUS_SUCCESS(status) || (phResult == NULL) )
2765 {
2766 //Fail or No one wants the result.
2767 csrScanResultPurge(pMac, (tScanResultHandle)pRetList);
2768 }
2769 else
2770 {
2771 if(0 == count)
2772 {
2773 //We are here meaning the there is no match
2774 csrLLClose(&pRetList->List);
Kiet Lam64c1b492013-07-12 13:56:44 +05302775 vos_mem_free(pRetList);
Jeff Johnson295189b2012-06-20 16:38:30 -07002776 status = eHAL_STATUS_E_NULL_VALUE;
Kapil Guptab3a981b2016-06-26 13:36:51 +05302777 smsLog(pMac, LOGW,
2778 FL("Nil scan results or no matching AP found"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002779 }
2780 else if(phResult)
2781 {
2782 *phResult = pRetList;
2783 }
2784 }
2785 }//Allocated pRetList
2786
2787 return (status);
2788}
2789
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002790/*
2791 * NOTE: This routine is being added to make
2792 * sure that scan results are not being flushed
2793 * while roaming. If the scan results are flushed,
2794 * we are unable to recover from
2795 * csrRoamRoamingStateDisassocRspProcessor.
2796 * If it is needed to remove this routine,
2797 * first ensure that we recover gracefully from
2798 * csrRoamRoamingStateDisassocRspProcessor if
2799 * csrScanGetResult returns with a failure because
2800 * of not being able to find the roaming BSS.
2801 */
2802tANI_U8 csrScanFlushDenied(tpAniSirGlobal pMac)
2803{
2804 switch(pMac->roam.neighborRoamInfo.neighborRoamState) {
2805 case eCSR_NEIGHBOR_ROAM_STATE_REPORT_SCAN:
2806 case eCSR_NEIGHBOR_ROAM_STATE_PREAUTHENTICATING:
2807 case eCSR_NEIGHBOR_ROAM_STATE_PREAUTH_DONE:
2808 case eCSR_NEIGHBOR_ROAM_STATE_REASSOCIATING:
2809 return (pMac->roam.neighborRoamInfo.neighborRoamState);
2810 default:
2811 return 0;
2812 }
2813}
2814
Jeff Johnson295189b2012-06-20 16:38:30 -07002815eHalStatus csrScanFlushResult(tpAniSirGlobal pMac)
2816{
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002817 tANI_U8 isFlushDenied = csrScanFlushDenied(pMac);
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302818 eHalStatus status = eHAL_STATUS_SUCCESS;
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002819 if (isFlushDenied) {
2820 smsLog(pMac, LOGW, "%s: scan flush denied in roam state %d",
2821 __func__, isFlushDenied);
2822 return eHAL_STATUS_FAILURE;
2823 }
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302824 csrLLScanPurgeResult( pMac, &pMac->scan.tempScanResults );
2825 csrLLScanPurgeResult( pMac, &pMac->scan.scanResultList );
2826 return( status );
Jeff Johnson295189b2012-06-20 16:38:30 -07002827}
2828
Mukul Sharma20aa6582014-08-07 21:36:12 +05302829eHalStatus csrScanFlushSelectiveResultForBand(tpAniSirGlobal pMac, v_BOOL_t flushP2P, tSirRFBand band)
2830{
2831 eHalStatus status = eHAL_STATUS_SUCCESS;
2832 tListElem *pEntry,*pFreeElem;
2833 tCsrScanResult *pBssDesc;
2834 tDblLinkList *pList = &pMac->scan.scanResultList;
2835
2836 csrLLLock(pList);
2837
2838 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK );
2839 while( pEntry != NULL)
2840 {
2841 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2842 if( (flushP2P == vos_mem_compare( pBssDesc->Result.ssId.ssId,
2843 "DIRECT-", 7)) &&
2844 (GetRFBand(pBssDesc->Result.BssDescriptor.channelId) == band)
2845 )
2846 {
2847 pFreeElem = pEntry;
2848 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2849 csrLLRemoveEntry(pList, pFreeElem, LL_ACCESS_NOLOCK);
2850 csrFreeScanResultEntry( pMac, pBssDesc );
2851 continue;
2852 }
2853 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2854 }
2855
2856 csrLLUnlock(pList);
2857
2858 return (status);
2859}
2860
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302861eHalStatus csrScanFlushSelectiveResult(tpAniSirGlobal pMac, v_BOOL_t flushP2P)
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002862{
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302863 eHalStatus status = eHAL_STATUS_SUCCESS;
2864 tListElem *pEntry,*pFreeElem;
2865 tCsrScanResult *pBssDesc;
2866 tDblLinkList *pList = &pMac->scan.scanResultList;
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002867
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302868 csrLLLock(pList);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002869
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302870 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK );
2871 while( pEntry != NULL)
2872 {
2873 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2874 if( flushP2P == vos_mem_compare( pBssDesc->Result.ssId.ssId,
2875 "DIRECT-", 7) )
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002876 {
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302877 pFreeElem = pEntry;
2878 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2879 csrLLRemoveEntry(pList, pFreeElem, LL_ACCESS_NOLOCK);
2880 csrFreeScanResultEntry( pMac, pBssDesc );
2881 continue;
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002882 }
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302883 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2884 }
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002885
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302886 csrLLUnlock(pList);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002887
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302888 return (status);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002889}
2890
Jeff Johnson295189b2012-06-20 16:38:30 -07002891/**
2892 * csrCheck11dChannel
2893 *
2894 *FUNCTION:
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302895 * This function is called from csrScanFilterResults function and
Jeff Johnson295189b2012-06-20 16:38:30 -07002896 * compare channel number with given channel list.
2897 *
2898 *LOGIC:
2899 * Check Scan result channel number with CFG channel list
2900 *
2901 *ASSUMPTIONS:
2902 *
2903 *
2904 *NOTE:
2905 *
2906 * @param channelId channel number
2907 * @param pChannelList Pointer to channel list
2908 * @param numChannels Number of channel in channel list
2909 *
2910 * @return Status
2911 */
2912
2913eHalStatus csrCheck11dChannel(tANI_U8 channelId, tANI_U8 *pChannelList, tANI_U32 numChannels)
2914{
2915 eHalStatus status = eHAL_STATUS_FAILURE;
2916 tANI_U8 i = 0;
2917
2918 for (i = 0; i < numChannels; i++)
2919 {
2920 if(pChannelList[ i ] == channelId)
2921 {
2922 status = eHAL_STATUS_SUCCESS;
2923 break;
2924 }
2925 }
2926 return status;
2927}
2928
2929/**
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302930 * csrScanFilterResults
Jeff Johnson295189b2012-06-20 16:38:30 -07002931 *
2932 *FUNCTION:
2933 * This function is called from csrApplyCountryInformation function and
2934 * filter scan result based on valid channel list number.
2935 *
2936 *LOGIC:
2937 * Get scan result from scan list and Check Scan result channel number
2938 * with 11d channel list if channel number is found in 11d channel list
2939 * then do not remove scan result entry from scan list
2940 *
2941 *ASSUMPTIONS:
2942 *
2943 *
2944 *NOTE:
2945 *
2946 * @param pMac Pointer to Global MAC structure
2947 *
2948 * @return Status
2949 */
2950
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302951eHalStatus csrScanFilterResults(tpAniSirGlobal pMac)
Jeff Johnson295189b2012-06-20 16:38:30 -07002952{
2953 eHalStatus status = eHAL_STATUS_SUCCESS;
2954 tListElem *pEntry,*pTempEntry;
2955 tCsrScanResult *pBssDesc;
2956 tANI_U32 len = sizeof(pMac->roam.validChannelList);
2957
2958 /* Get valid channels list from CFG */
2959 if (!HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac,
2960 pMac->roam.validChannelList, &len)))
2961 {
Agarwal Ashishe3cca2a2013-07-21 03:01:48 +05302962 smsLog( pMac, LOGE, "Failed to get Channel list from CFG");
Jeff Johnson295189b2012-06-20 16:38:30 -07002963 }
2964
2965 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
2966 while( pEntry )
2967 {
2968 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302969 pTempEntry = csrLLNext( &pMac->scan.scanResultList, pEntry,
Jeff Johnson295189b2012-06-20 16:38:30 -07002970 LL_ACCESS_LOCK );
2971 if(csrCheck11dChannel(pBssDesc->Result.BssDescriptor.channelId,
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302972 pMac->roam.validChannelList, len))
Jeff Johnson295189b2012-06-20 16:38:30 -07002973 {
2974 /* Remove Scan result which does not have 11d channel */
2975 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry,
2976 LL_ACCESS_LOCK ))
2977 {
2978 csrFreeScanResultEntry( pMac, pBssDesc );
2979 }
2980 }
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302981 pEntry = pTempEntry;
2982 }
2983
2984 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
2985 while( pEntry )
2986 {
2987 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2988 pTempEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry,
2989 LL_ACCESS_LOCK );
2990 if(csrCheck11dChannel(pBssDesc->Result.BssDescriptor.channelId,
2991 pMac->roam.validChannelList, len))
2992 {
2993 /* Remove Scan result which does not have 11d channel */
2994 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry,
2995 LL_ACCESS_LOCK ))
2996 {
2997 csrFreeScanResultEntry( pMac, pBssDesc );
2998 }
2999 }
3000 else
3001 {
3002 smsLog( pMac, LOG1, FL("%d is a Valid channel"),
3003 pBssDesc->Result.BssDescriptor.channelId);
3004 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003005 pEntry = pTempEntry;
3006 }
3007 return status;
3008}
3009
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05303010/**
3011 * csrScanFilterDFSResults
3012 *
3013 *FUNCTION:
3014 * This function filter BSSIDs on DFS channels from the scan results.
3015 *
3016 *LOGIC:
3017 * Get scan result from scan list and Check Scan result channel number
3018 * with 11d channel list if channel number is found in 11d channel list
3019 * and if fEnableDFSChnlScan is zero and if channel is DFS, then
3020 * remove scan result entry from scan list
3021 *
3022 *ASSUMPTIONS:
3023 *
3024 *NOTE:
3025 *
3026 * @param pMac Pointer to Global MAC structure
3027 *
3028 * @return Status
3029 */
3030
3031eHalStatus csrScanFilterDFSResults(tpAniSirGlobal pMac)
3032{
3033 eHalStatus status = eHAL_STATUS_SUCCESS;
3034 tListElem *pEntry,*pTempEntry;
3035 tCsrScanResult *pBssDesc;
3036
3037 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
3038 while( pEntry )
3039 {
3040 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3041 pTempEntry = csrLLNext( &pMac->scan.scanResultList, pEntry,
3042 LL_ACCESS_LOCK );
3043 if((pMac->scan.fEnableDFSChnlScan == DFS_CHNL_SCAN_DISABLED) &&
3044 CSR_IS_CHANNEL_DFS(pBssDesc->Result.BssDescriptor.channelId))
3045 {
3046 smsLog( pMac, LOG1, FL("%d is a DFS ch filtered from scan list"),
3047 pBssDesc->Result.BssDescriptor.channelId);
3048 /* Remove Scan result which does not have 11d channel */
3049 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry,
3050 LL_ACCESS_LOCK ))
3051 {
3052 csrFreeScanResultEntry( pMac, pBssDesc );
3053 }
3054 }
3055 else
3056 {
3057 smsLog( pMac, LOG1, FL("%d is a Valid channel"),
3058 pBssDesc->Result.BssDescriptor.channelId);
3059 }
3060 pEntry = pTempEntry;
3061 }
3062
3063 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
3064 while( pEntry )
3065 {
3066 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3067 pTempEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry,
3068 LL_ACCESS_LOCK );
3069
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.tempScanResults, 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 return status;
3090}
3091
Jeff Johnson295189b2012-06-20 16:38:30 -07003092
3093eHalStatus csrScanCopyResultList(tpAniSirGlobal pMac, tScanResultHandle hIn, tScanResultHandle *phResult)
3094{
3095 eHalStatus status = eHAL_STATUS_SUCCESS;
3096 tScanResultList *pRetList, *pInList = (tScanResultList *)hIn;
3097 tCsrScanResult *pResult, *pScanResult;
3098 tANI_U32 count = 0;
3099 tListElem *pEntry;
3100 tANI_U32 bssLen, allocLen;
3101
3102 if(phResult)
3103 {
3104 *phResult = CSR_INVALID_SCANRESULT_HANDLE;
3105 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303106 pRetList = vos_mem_malloc(sizeof(tScanResultList));
3107 if ( NULL == pRetList )
3108 status = eHAL_STATUS_FAILURE;
3109 else
Jeff Johnson295189b2012-06-20 16:38:30 -07003110 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303111 vos_mem_set(pRetList, sizeof(tScanResultList), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003112 csrLLOpen(pMac->hHdd, &pRetList->List);
3113 pRetList->pCurEntry = NULL;
3114 csrLLLock(&pMac->scan.scanResultList);
3115 csrLLLock(&pInList->List);
3116
3117 pEntry = csrLLPeekHead( &pInList->List, LL_ACCESS_NOLOCK );
3118 while( pEntry )
3119 {
3120 pScanResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3121 bssLen = pScanResult->Result.BssDescriptor.length + sizeof(pScanResult->Result.BssDescriptor.length);
3122 allocLen = sizeof( tCsrScanResult ) + bssLen;
Kiet Lam64c1b492013-07-12 13:56:44 +05303123 pResult = vos_mem_malloc(allocLen);
3124 if ( NULL == pResult )
3125 status = eHAL_STATUS_FAILURE;
3126 else
3127 status = eHAL_STATUS_SUCCESS;
3128 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07003129 {
3130 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
3131 count = 0;
3132 break;
3133 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303134 vos_mem_set(pResult, allocLen , 0);
3135 vos_mem_copy(&pResult->Result.BssDescriptor, &pScanResult->Result.BssDescriptor, bssLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07003136 if( pScanResult->Result.pvIes )
3137 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303138 pResult->Result.pvIes = vos_mem_malloc(sizeof( tDot11fBeaconIEs ));
3139 if ( NULL == pResult->Result.pvIes )
3140 status = eHAL_STATUS_FAILURE;
3141 else
3142 status = eHAL_STATUS_SUCCESS;
3143 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07003144 {
3145 //Free the memory we allocate above first
Kiet Lam64c1b492013-07-12 13:56:44 +05303146 vos_mem_free(pResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07003147 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
3148 count = 0;
3149 break;
3150 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303151 vos_mem_copy(pResult->Result.pvIes, pScanResult->Result.pvIes,
3152 sizeof( tDot11fBeaconIEs ));
Jeff Johnson295189b2012-06-20 16:38:30 -07003153 }
3154 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_LOCK);
3155 count++;
3156 pEntry = csrLLNext( &pInList->List, pEntry, LL_ACCESS_NOLOCK );
3157 }//while
3158 csrLLUnlock(&pInList->List);
3159 csrLLUnlock(&pMac->scan.scanResultList);
3160
3161 if(HAL_STATUS_SUCCESS(status))
3162 {
3163 if(0 == count)
3164 {
3165 csrLLClose(&pRetList->List);
Kiet Lam64c1b492013-07-12 13:56:44 +05303166 vos_mem_free(pRetList);
Jeff Johnson295189b2012-06-20 16:38:30 -07003167 status = eHAL_STATUS_E_NULL_VALUE;
3168 }
3169 else if(phResult)
3170 {
3171 *phResult = pRetList;
3172 }
3173 }
3174 }//Allocated pRetList
3175
3176 return (status);
3177}
3178
3179
3180
3181eHalStatus csrScanningStateMsgProcessor( tpAniSirGlobal pMac, void *pMsgBuf )
3182{
3183 eHalStatus status = eHAL_STATUS_SUCCESS;
3184 tSirMbMsg *pMsg = (tSirMbMsg *)pMsgBuf;
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303185 tSirSmeDisConDoneInd *pDisConDoneInd;
Abhishek Singhf52182c2016-08-24 11:15:23 +05303186 tCsrRoamSession *pSession;
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303187 tCsrRoamInfo roamInfo = {0};
Jeff Johnson295189b2012-06-20 16:38:30 -07003188
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303189 if((eWNI_SME_SCAN_RSP == pMsg->type) ||
3190 (eWNI_SME_GET_SCANNED_CHANNEL_RSP == pMsg->type))
Jeff Johnson295189b2012-06-20 16:38:30 -07003191 {
3192 status = csrScanSmeScanResponse( pMac, pMsgBuf );
3193 }
3194 else
3195 {
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303196 switch (pMsg->type)
Jeff Johnson295189b2012-06-20 16:38:30 -07003197 {
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303198 case eWNI_SME_UPPER_LAYER_ASSOC_CNF:
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08003199 {
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303200 tSirSmeAssocIndToUpperLayerCnf *pUpperLayerAssocCnf;
3201 tCsrRoamInfo *pRoamInfo = NULL;
3202 tANI_U32 sessionId;
3203 eHalStatus status;
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08003204
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303205 smsLog( pMac, LOG1,
3206 FL("Scanning : ASSOCIATION confirmation can be given to upper layer "));
3207 pRoamInfo = &roamInfo;
3208 pUpperLayerAssocCnf = (tSirSmeAssocIndToUpperLayerCnf *)pMsgBuf;
3209 status = csrRoamGetSessionIdFromBSSID( pMac,
3210 (tCsrBssid *)pUpperLayerAssocCnf->bssId,
3211 &sessionId );
3212 pSession = CSR_GET_SESSION(pMac, sessionId);
3213
3214 if(!pSession)
3215 {
3216 smsLog(pMac, LOGE, FL("session %d not found "), sessionId);
3217 return eHAL_STATUS_FAILURE;
3218 }
3219
3220 //send the status code as Success
3221 pRoamInfo->statusCode = eSIR_SME_SUCCESS;
3222 pRoamInfo->u.pConnectedProfile = &pSession->connectedProfile;
3223 pRoamInfo->staId = (tANI_U8)pUpperLayerAssocCnf->aid;
3224 pRoamInfo->rsnIELen =
3225 (tANI_U8)pUpperLayerAssocCnf->rsnIE.length;
3226 pRoamInfo->prsnIE = pUpperLayerAssocCnf->rsnIE.rsnIEdata;
3227 pRoamInfo->addIELen =
3228 (tANI_U8)pUpperLayerAssocCnf->addIE.length;
3229 pRoamInfo->paddIE = pUpperLayerAssocCnf->addIE.addIEdata;
3230 vos_mem_copy(pRoamInfo->peerMac,
3231 pUpperLayerAssocCnf->peerMacAddr,
3232 sizeof(tSirMacAddr));
3233 vos_mem_copy(&pRoamInfo->bssid,
3234 pUpperLayerAssocCnf->bssId,
3235 sizeof(tCsrBssid));
3236 pRoamInfo->wmmEnabledSta = pUpperLayerAssocCnf->wmmEnabledSta;
Hardik Kantilal Patel1ba630f2014-11-21 04:32:05 +05303237#ifdef WLAN_FEATURE_AP_HT40_24G
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303238 pRoamInfo->HT40MHzIntoEnabledSta =
3239 pUpperLayerAssocCnf->HT40MHzIntoEnabledSta;
Hardik Kantilal Patel1ba630f2014-11-21 04:32:05 +05303240#endif
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303241 if(CSR_IS_INFRA_AP(pRoamInfo->u.pConnectedProfile) )
3242 {
3243 pMac->roam.roamSession[sessionId].connectState =
3244 eCSR_ASSOC_STATE_TYPE_INFRA_CONNECTED;
3245 pRoamInfo->fReassocReq = pUpperLayerAssocCnf->reassocReq;
3246 status = csrRoamCallCallback(pMac, sessionId, pRoamInfo,
3247 0, eCSR_ROAM_INFRA_IND,
3248 eCSR_ROAM_RESULT_INFRA_ASSOCIATION_CNF);
3249 }
3250 if(CSR_IS_WDS_AP( pRoamInfo->u.pConnectedProfile))
3251 {
3252 vos_sleep( 100 );
3253 pMac->roam.roamSession[sessionId].connectState =
3254 eCSR_ASSOC_STATE_TYPE_WDS_CONNECTED;//Sta
3255 status = csrRoamCallCallback(pMac, sessionId, pRoamInfo, 0,
3256 eCSR_ROAM_WDS_IND,
3257 eCSR_ROAM_RESULT_WDS_ASSOCIATION_IND);//Sta
3258 }
3259 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07003260 }
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303261 case eWNI_SME_DISCONNECT_DONE_IND:
3262 pDisConDoneInd = (tSirSmeDisConDoneInd *)(pMsg);
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08003263
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303264 smsLog( pMac, LOG1,
3265 FL("eWNI_SME_DISCONNECT_DONE_IND RC:%d"),
3266 pDisConDoneInd->reasonCode);
Sreelakshmi Konamki033cf602016-10-12 15:30:14 +05303267 pSession = CSR_GET_SESSION(pMac,pDisConDoneInd->sessionId);
3268 if (pSession)
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08003269 {
Sreelakshmi Konamki033cf602016-10-12 15:30:14 +05303270 if( CSR_IS_SESSION_VALID(pMac, pDisConDoneInd->sessionId))
3271 {
3272 roamInfo.reasonCode = pDisConDoneInd->reasonCode;
3273 roamInfo.statusCode = eSIR_SME_STA_DISASSOCIATED;
3274 vos_mem_copy(roamInfo.peerMac, pDisConDoneInd->peerMacAddr,
3275 sizeof(tSirMacAddr));
3276 status = csrRoamCallCallback(pMac,
3277 pDisConDoneInd->sessionId,
3278 &roamInfo, 0,
3279 eCSR_ROAM_LOSTLINK,
3280 eCSR_ROAM_RESULT_DISASSOC_IND);
3281 /*
3282 * Update the previous state if
3283 * previous state was eCSR_ROAMING_STATE_JOINED
3284 * as we are disconnected and
3285 * currunt state is scanning
3286 */
3287 if (!CSR_IS_INFRA_AP(&pSession->connectedProfile)
3288 && (eCSR_ROAMING_STATE_IDLE !=
3289 pMac->roam.prev_state[pDisConDoneInd->sessionId]))
3290 pMac->roam.prev_state[pDisConDoneInd->sessionId] =
3291 eCSR_ROAMING_STATE_IDLE;
3292 }
3293 else
3294 {
3295 smsLog(pMac, LOGE, FL("Inactive session %d"),
Abhishek Singhf52182c2016-08-24 11:15:23 +05303296 pDisConDoneInd->sessionId);
Sreelakshmi Konamki033cf602016-10-12 15:30:14 +05303297 status = eHAL_STATUS_FAILURE;
3298 }
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08003299 }
3300 else
3301 {
Sreelakshmi Konamki033cf602016-10-12 15:30:14 +05303302 smsLog(pMac, LOGE, FL("Invalid session"));
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303303 status = eHAL_STATUS_FAILURE;
3304 }
3305 break;
3306
3307 default :
3308 if( csrIsAnySessionInConnectState( pMac ) )
3309 {
3310 /*In case of we are connected, we need to check whether connect
3311 * status changes because scan may also run while connected.
3312 */
3313 csrRoamCheckForLinkStatusChange( pMac, (tSirSmeRsp *)pMsgBuf );
3314 }
3315 else
3316 {
3317 smsLog( pMac, LOGW,
3318 "Message [0x%04x] received in state, when expecting Scan Response",
3319 pMsg->type );
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08003320 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003321 }
3322 }
3323
3324 return (status);
3325}
3326
3327
3328
3329void csrCheckNSaveWscIe(tpAniSirGlobal pMac, tSirBssDescription *pNewBssDescr, tSirBssDescription *pOldBssDescr)
3330{
3331 int idx, len;
3332 tANI_U8 *pbIe;
3333
3334 //If failed to remove, assuming someone else got it.
3335 if((pNewBssDescr->fProbeRsp != pOldBssDescr->fProbeRsp) &&
3336 (0 == pNewBssDescr->WscIeLen))
3337 {
3338 idx = 0;
Abhishek Singhbad2b322016-10-21 11:22:33 +05303339 len = GET_IE_LEN_IN_BSS(pOldBssDescr->length)
3340 - DOT11F_IE_WSCPROBERES_MIN_LEN - 2;
Jeff Johnson295189b2012-06-20 16:38:30 -07003341 pbIe = (tANI_U8 *)pOldBssDescr->ieFields;
3342 //Save WPS IE if it exists
3343 pNewBssDescr->WscIeLen = 0;
3344 while(idx < len)
3345 {
3346 if((DOT11F_EID_WSCPROBERES == pbIe[0]) &&
3347 (0x00 == pbIe[2]) && (0x50 == pbIe[3]) && (0xf2 == pbIe[4]) && (0x04 == pbIe[5]))
3348 {
3349 //Founrd it
3350 if((DOT11F_IE_WSCPROBERES_MAX_LEN - 2) >= pbIe[1])
3351 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303352 vos_mem_copy(pNewBssDescr->WscIeProbeRsp, pbIe, pbIe[1] + 2);
Jeff Johnson295189b2012-06-20 16:38:30 -07003353 pNewBssDescr->WscIeLen = pbIe[1] + 2;
3354 }
3355 break;
3356 }
3357 idx += pbIe[1] + 2;
3358 pbIe += pbIe[1] + 2;
3359 }
3360 }
3361}
3362
3363
3364
3365//pIes may be NULL
3366tANI_BOOLEAN csrRemoveDupBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDescr,
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05303367 tDot11fBeaconIEs *pIes, tAniSSID *pSsid, v_TIME_t *timer, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07003368{
3369 tListElem *pEntry;
3370
3371 tCsrScanResult *pBssDesc;
3372 tANI_BOOLEAN fRC = FALSE;
3373
3374 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
3375 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
3376 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
3377 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
3378
3379 while( pEntry )
3380 {
3381 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3382
3383 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
3384 // matches
3385 if ( csrIsDuplicateBssDescription( pMac, &pBssDesc->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07003386 pSirBssDescr, pIes, fForced ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003387 {
3388 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
3389 ((tANI_S32)pBssDesc->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
3390 // Remove the 'old' entry from the list....
3391 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry, LL_ACCESS_LOCK ) )
3392 {
3393 // !we need to free the memory associated with this node
3394 //If failed to remove, assuming someone else got it.
3395 *pSsid = pBssDesc->Result.ssId;
3396 *timer = pBssDesc->Result.timer;
3397 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pBssDesc->Result.BssDescriptor);
3398
3399 csrFreeScanResultEntry( pMac, pBssDesc );
3400 }
3401 else
3402 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003403 smsLog( pMac, LOGW, FL( " fail to remove entry" ) );
Jeff Johnson295189b2012-06-20 16:38:30 -07003404 }
3405 fRC = TRUE;
3406
3407 // If we found a match, we can stop looking through the list.
3408 break;
3409 }
3410
3411 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_LOCK );
3412 }
3413
3414 return fRC;
3415}
3416
3417
3418eHalStatus csrAddPMKIDCandidateList( tpAniSirGlobal pMac, tANI_U32 sessionId,
3419 tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes )
3420{
3421 eHalStatus status = eHAL_STATUS_FAILURE;
3422 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
3423
Jeff Johnson32d95a32012-09-10 13:15:23 -07003424 if(!pSession)
3425 {
3426 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
3427 return eHAL_STATUS_FAILURE;
3428 }
3429
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003430 smsLog(pMac, LOGW, "csrAddPMKIDCandidateList called pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07003431 if( pIes )
3432 {
3433 // check if this is a RSN BSS
3434 if( pIes->RSN.present )
3435 {
3436 // Check if the BSS is capable of doing pre-authentication
3437 if( pSession->NumPmkidCandidate < CSR_MAX_PMKID_ALLOWED )
3438 {
3439
3440#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3441 {
3442 WLAN_VOS_DIAG_EVENT_DEF(secEvent, vos_event_wlan_security_payload_type);
Kiet Lam64c1b492013-07-12 13:56:44 +05303443 vos_mem_set(&secEvent, sizeof(vos_event_wlan_security_payload_type), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003444 secEvent.eventId = WLAN_SECURITY_EVENT_PMKID_CANDIDATE_FOUND;
3445 secEvent.encryptionModeMulticast =
3446 (v_U8_t)diagEncTypeFromCSRType(pSession->connectedProfile.mcEncryptionType);
3447 secEvent.encryptionModeUnicast =
3448 (v_U8_t)diagEncTypeFromCSRType(pSession->connectedProfile.EncryptionType);
Kiet Lam64c1b492013-07-12 13:56:44 +05303449 vos_mem_copy(secEvent.bssid, pSession->connectedProfile.bssid, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07003450 secEvent.authMode =
3451 (v_U8_t)diagAuthTypeFromCSRType(pSession->connectedProfile.AuthType);
3452 WLAN_VOS_DIAG_EVENT_REPORT(&secEvent, EVENT_WLAN_SECURITY);
3453 }
3454#endif//#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3455
3456 // if yes, then add to PMKIDCandidateList
Kiet Lam64c1b492013-07-12 13:56:44 +05303457 vos_mem_copy(pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].BSSID,
3458 pBssDesc->bssId, WNI_CFG_BSSID_LEN);
3459 // Bit 0 offirst byte - PreAuthentication Capability
3460 if ( (pIes->RSN.RSN_Cap[0] >> 0) & 0x1 )
Jeff Johnson295189b2012-06-20 16:38:30 -07003461 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303462 pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].preAuthSupported
3463 = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003464 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303465 else
3466 {
3467 pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].preAuthSupported
3468 = eANI_BOOLEAN_FALSE;
3469 }
3470 pSession->NumPmkidCandidate++;
Jeff Johnson295189b2012-06-20 16:38:30 -07003471 }
3472 else
3473 {
3474 status = eHAL_STATUS_FAILURE;
3475 }
3476 }
3477 }
3478
3479 return (status);
3480}
3481
3482//This function checks whether new AP is found for the current connected profile
3483//If it is found, it return the sessionId, else it return invalid sessionID
3484tANI_U32 csrProcessBSSDescForPMKIDList(tpAniSirGlobal pMac,
3485 tSirBssDescription *pBssDesc,
3486 tDot11fBeaconIEs *pIes)
3487{
3488 tANI_U32 i, bRet = CSR_SESSION_ID_INVALID;
3489 tCsrRoamSession *pSession;
3490 tDot11fBeaconIEs *pIesLocal = pIes;
3491
3492 if( pIesLocal || HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIesLocal)) )
3493 {
3494 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
3495 {
3496 if( CSR_IS_SESSION_VALID( pMac, i ) )
3497 {
3498 pSession = CSR_GET_SESSION( pMac, i );
3499 if( csrIsConnStateConnectedInfra( pMac, i ) &&
3500 ( eCSR_AUTH_TYPE_RSN == pSession->connectedProfile.AuthType ) )
3501 {
3502 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile, pBssDesc, pIesLocal))
3503 {
3504 //this new BSS fits the current profile connected
3505 if(HAL_STATUS_SUCCESS(csrAddPMKIDCandidateList(pMac, i, pBssDesc, pIesLocal)))
3506 {
3507 bRet = i;
3508 }
3509 break;
3510 }
3511 }
3512 }
3513 }
3514 if( !pIes )
3515 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303516 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003517 }
3518 }
3519
3520 return (tANI_U8)bRet;
3521}
3522
3523#ifdef FEATURE_WLAN_WAPI
3524eHalStatus csrAddBKIDCandidateList( tpAniSirGlobal pMac, tANI_U32 sessionId,
3525 tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes )
3526{
3527 eHalStatus status = eHAL_STATUS_FAILURE;
3528 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
3529
Jeff Johnson32d95a32012-09-10 13:15:23 -07003530 if(!pSession)
3531 {
3532 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
3533 return eHAL_STATUS_FAILURE;
3534 }
3535
Kiet Lam64c1b492013-07-12 13:56:44 +05303536 smsLog(pMac, LOGW, "csrAddBKIDCandidateList called pMac->scan.NumBkidCandidate = %d",
3537 pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07003538 if( pIes )
3539 {
3540 // check if this is a WAPI BSS
3541 if( pIes->WAPI.present )
3542 {
3543 // Check if the BSS is capable of doing pre-authentication
3544 if( pSession->NumBkidCandidate < CSR_MAX_BKID_ALLOWED )
3545 {
3546
3547 // if yes, then add to BKIDCandidateList
Kiet Lam64c1b492013-07-12 13:56:44 +05303548 vos_mem_copy(pSession->BkidCandidateInfo[pSession->NumBkidCandidate].BSSID,
3549 pBssDesc->bssId, WNI_CFG_BSSID_LEN);
3550 if ( pIes->WAPI.preauth )
Jeff Johnson295189b2012-06-20 16:38:30 -07003551 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303552 pSession->BkidCandidateInfo[pSession->NumBkidCandidate].preAuthSupported
3553 = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003554 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303555 else
3556 {
3557 pSession->BkidCandidateInfo[pSession->NumBkidCandidate].preAuthSupported
3558 = eANI_BOOLEAN_FALSE;
3559 }
3560 pSession->NumBkidCandidate++;
Jeff Johnson295189b2012-06-20 16:38:30 -07003561 }
3562 else
3563 {
3564 status = eHAL_STATUS_FAILURE;
3565 }
3566 }
3567 }
3568
3569 return (status);
3570}
3571
3572//This function checks whether new AP is found for the current connected profile
3573//if so add to BKIDCandidateList
3574tANI_BOOLEAN csrProcessBSSDescForBKIDList(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
3575 tDot11fBeaconIEs *pIes)
3576{
3577 tANI_BOOLEAN fRC = FALSE;
3578 tDot11fBeaconIEs *pIesLocal = pIes;
3579 tANI_U32 sessionId;
3580 tCsrRoamSession *pSession;
3581
3582 if( pIesLocal || HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIesLocal)) )
3583 {
3584 for( sessionId = 0; sessionId < CSR_ROAM_SESSION_MAX; sessionId++ )
3585 {
3586 if( CSR_IS_SESSION_VALID( pMac, sessionId) )
3587 {
3588 pSession = CSR_GET_SESSION( pMac, sessionId );
3589 if( csrIsConnStateConnectedInfra( pMac, sessionId ) &&
3590 eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE == pSession->connectedProfile.AuthType)
3591 {
3592 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile,pBssDesc, pIesLocal))
3593 {
3594 //this new BSS fits the current profile connected
3595 if(HAL_STATUS_SUCCESS(csrAddBKIDCandidateList(pMac, sessionId, pBssDesc, pIesLocal)))
3596 {
3597 fRC = TRUE;
3598 }
3599 }
3600 }
3601 }
3602 }
3603 if(!pIes)
3604 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303605 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003606 }
3607
3608 }
3609 return fRC;
3610}
3611
3612#endif
3613
3614
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07003615static void csrMoveTempScanResultsToMainList( tpAniSirGlobal pMac, tANI_U8 reason )
Jeff Johnson295189b2012-06-20 16:38:30 -07003616{
3617 tListElem *pEntry;
3618 tCsrScanResult *pBssDescription;
Jeff Johnson295189b2012-06-20 16:38:30 -07003619 tANI_BOOLEAN fDupBss;
3620#ifdef FEATURE_WLAN_WAPI
3621 tANI_BOOLEAN fNewWapiBSSForCurConnection = eANI_BOOLEAN_FALSE;
3622#endif /* FEATURE_WLAN_WAPI */
3623 tDot11fBeaconIEs *pIesLocal = NULL;
3624 tANI_U32 sessionId = CSR_SESSION_ID_INVALID;
3625 tAniSSID tmpSsid;
3626 v_TIME_t timer=0;
Kapil Gupta2f2fae42016-09-15 15:29:47 +05303627 tANI_U8 occupied_chan_count = pMac->scan.occupiedChannels.numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -07003628
3629 tmpSsid.length = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07003630
3631 // remove the BSS descriptions from temporary list
3632 while( ( pEntry = csrLLRemoveTail( &pMac->scan.tempScanResults, LL_ACCESS_LOCK ) ) != NULL)
3633 {
3634 pBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3635
Vinay Krishna Eranna566365f2015-03-09 12:34:13 +05303636 smsLog( pMac, LOG2, "...Bssid= "MAC_ADDRESS_STR" chan= %d, rssi = -%d",
Arif Hussain24bafea2013-11-15 15:10:03 -08003637 MAC_ADDR_ARRAY(pBssDescription->Result.BssDescriptor.bssId),
Jeff Johnson295189b2012-06-20 16:38:30 -07003638 pBssDescription->Result.BssDescriptor.channelId,
3639 pBssDescription->Result.BssDescriptor.rssi * (-1) );
3640
3641 //At this time, pBssDescription->Result.pvIes may be NULL
3642 pIesLocal = (tDot11fBeaconIEs *)( pBssDescription->Result.pvIes );
3643 if( !pIesLocal && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pBssDescription->Result.BssDescriptor, &pIesLocal))) )
3644 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003645 smsLog(pMac, LOGE, FL(" Cannot pared IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003646 csrFreeScanResultEntry(pMac, pBssDescription);
3647 continue;
3648 }
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05303649 fDupBss = csrRemoveDupBssDescription( pMac, &pBssDescription->Result.BssDescriptor, pIesLocal, &tmpSsid, &timer, FALSE );
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07003650 //Check whether we have reach out limit, but don't lose the LFR candidates came from FW
3651 if( CSR_SCAN_IS_OVER_BSS_LIMIT(pMac)
3652#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
3653 && !( eCsrScanGetLfrResult == reason )
3654#endif
3655 )
Jeff Johnson295189b2012-06-20 16:38:30 -07003656 {
Deepthi Gowri50e2fa52016-03-17 15:30:53 +05303657 smsLog(pMac, LOG1, FL("########## BSS Limit reached ###########"));
3658 csrPurgeOldScanResults(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07003659 }
3660 // check for duplicate scan results
3661 if ( !fDupBss )
3662 {
3663 //Found a new BSS
3664 sessionId = csrProcessBSSDescForPMKIDList(pMac,
3665 &pBssDescription->Result.BssDescriptor, pIesLocal);
3666 if( CSR_SESSION_ID_INVALID != sessionId)
3667 {
3668 csrRoamCallCallback(pMac, sessionId, NULL, 0,
3669 eCSR_ROAM_SCAN_FOUND_NEW_BSS, eCSR_ROAM_RESULT_NONE);
3670 }
3671 }
3672 else
3673 {
3674 //Check if the new one has SSID it it, if not, use the older SSID if it exists.
3675 if( (0 == pBssDescription->Result.ssId.length) && tmpSsid.length )
3676 {
3677 //New BSS has a hidden SSID and old one has the SSID. Keep the SSID only
3678 //if diff of saved SSID time and current time is less than 1 min to avoid
3679 //side effect of saving SSID with old one is that if AP changes its SSID while remain
3680 //hidden, we may never see it and also to address the requirement of
3681 //When we remove hidden ssid from the profile i.e., forget the SSID via
3682 // GUI that SSID shouldn't see in the profile
3683 if( (vos_timer_get_system_time() - timer) <= HIDDEN_TIMER)
3684 {
3685 pBssDescription->Result.timer = timer;
3686 pBssDescription->Result.ssId = tmpSsid;
3687 }
3688 }
3689 }
3690
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303691 //Find a good AP for 11d info
3692 if ( csrIs11dSupported( pMac ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003693 {
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303694 // check if country information element is present
3695 if (pIesLocal->Country.present)
Jeff Johnson295189b2012-06-20 16:38:30 -07003696 {
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303697 csrAddVoteForCountryInfo(pMac, pIesLocal->Country.country);
3698 smsLog(pMac, LOGW, FL("11d AP Bssid " MAC_ADDRESS_STR
3699 " chan= %d, rssi = -%d, countryCode %c%c"),
3700 MAC_ADDR_ARRAY( pBssDescription->Result.BssDescriptor.bssId),
3701 pBssDescription->Result.BssDescriptor.channelId,
3702 pBssDescription->Result.BssDescriptor.rssi * (-1),
3703 pIesLocal->Country.country[0],pIesLocal->Country.country[1] );
3704 }
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303705
Jeff Johnson295189b2012-06-20 16:38:30 -07003706 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08003707
Jeff Johnson295189b2012-06-20 16:38:30 -07003708 // append to main list
3709 csrScanAddResult(pMac, pBssDescription, pIesLocal);
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303710 if ( (pBssDescription->Result.pvIes == NULL) && pIesLocal )
Jeff Johnson295189b2012-06-20 16:38:30 -07003711 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303712 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003713 }
3714 }
3715
Kapil Gupta2f2fae42016-09-15 15:29:47 +05303716#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
3717 if (sme_IsFeatureSupportedByFW(PER_BASED_ROAMING) &&
3718 (csrGetInfraSessionId(pMac) != -1) &&
3719 (pMac->scan.occupiedChannels.numChannels != occupied_chan_count))
3720 {
3721 /* Update FW with new list */
3722 smsLog(pMac, LOGW,
3723 FL("Updating occupied channel list, new chanNum %d"),
3724 pMac->scan.occupiedChannels.numChannels);
3725 csrRoamOffloadScan(pMac, ROAM_SCAN_OFFLOAD_UPDATE_CFG,
3726 REASON_CHANNEL_LIST_CHANGED);
3727 }
3728#endif
Sushant Kaushik6274de62015-05-01 16:31:23 +05303729 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
Tushnim Bhattacharyyaae317772013-10-23 18:55:38 -07003730 //we don't need to update CC while connected to an AP which is advertising CC already
3731 if (csrIs11dSupported(pMac))
3732 {
3733 tANI_U32 i;
3734 tCsrRoamSession *pSession;
3735
3736 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
3737 {
3738 if (CSR_IS_SESSION_VALID( pMac, i ) )
3739 {
3740 pSession = CSR_GET_SESSION( pMac, i );
3741 if (csrIsConnStateConnected(pMac, i))
3742 {
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303743 smsLog(pMac, LOGW, FL("No need for updating CC in"
3744 "connected state"));
3745 goto end;
Tushnim Bhattacharyyaae317772013-10-23 18:55:38 -07003746 }
3747 }
3748 }
Agrawal Ashishbd3a5932016-04-12 16:22:39 +05303749 if (csrElectedCountryInfo(pMac))
3750 csrLearnCountryInformation(pMac, NULL, NULL,
3751 eANI_BOOLEAN_TRUE);
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303752 }
3753
Tushnim Bhattacharyyaae317772013-10-23 18:55:38 -07003754end:
3755 //If we can find the current 11d info in any of the scan results, or
Jeff Johnson295189b2012-06-20 16:38:30 -07003756 // a good enough AP with the 11d info from the scan results then no need to
3757 // get into ambiguous state
3758 if(pMac->scan.fAmbiguous11dInfoFound)
3759 {
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303760 if((pMac->scan.fCurrent11dInfoMatch))
Jeff Johnson295189b2012-06-20 16:38:30 -07003761 {
3762 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
3763 }
3764 }
3765
3766#ifdef FEATURE_WLAN_WAPI
3767 if(fNewWapiBSSForCurConnection)
3768 {
3769 //remember it first
3770 csrRoamCallCallback(pMac, sessionId, NULL, 0, eCSR_ROAM_SCAN_FOUND_NEW_BSS, eCSR_ROAM_RESULT_NEW_WAPI_BSS);
3771 }
3772#endif /* FEATURE_WLAN_WAPI */
3773
3774 return;
3775}
3776
Deepthi Gowri50e2fa52016-03-17 15:30:53 +05303777void csrPurgeOldScanResults(tpAniSirGlobal pMac)
3778{
3779 tListElem *pEntry, *tmpEntry;
3780 tCsrScanResult *pResult, *oldest_bss = NULL;
Deepthi Gowri4480a3f2016-05-18 19:30:17 +05303781 v_TIME_t oldest_entry = 0;
3782 v_TIME_t curTime = vos_timer_get_system_time();
Deepthi Gowri50e2fa52016-03-17 15:30:53 +05303783
3784 csrLLLock(&pMac->scan.scanResultList);
3785 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
3786 while( pEntry )
3787 {
3788 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry,
3789 LL_ACCESS_NOLOCK);
3790 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3791 if((curTime -
3792 pResult->Result.BssDescriptor.nReceivedTime) > oldest_entry)
3793 {
3794 oldest_entry = curTime -
3795 pResult->Result.BssDescriptor.nReceivedTime;
3796 oldest_bss = pResult;
3797 }
3798 pEntry = tmpEntry;
3799 }
3800 if (oldest_bss)
3801 {
3802 //Free the old BSS Entries
3803 if( csrLLRemoveEntry(&pMac->scan.scanResultList,
3804 &oldest_bss->Link, LL_ACCESS_NOLOCK) )
3805 {
Deepthi Gowri6a08e312016-03-31 19:10:14 +05303806 smsLog(pMac, LOG1, FL(" Current time delta (%lu) of BSSID to be removed" MAC_ADDRESS_STR ),
Deepthi Gowri50e2fa52016-03-17 15:30:53 +05303807 (curTime - oldest_bss->Result.BssDescriptor.nReceivedTime),
3808 MAC_ADDR_ARRAY(oldest_bss->Result.BssDescriptor.bssId));
3809 csrFreeScanResultEntry(pMac, oldest_bss);
3810 }
3811 }
3812 csrLLUnlock(&pMac->scan.scanResultList);
3813}
Jeff Johnson295189b2012-06-20 16:38:30 -07003814
3815static tCsrScanResult *csrScanSaveBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pBSSDescription,
3816 tDot11fBeaconIEs *pIes)
3817{
3818 tCsrScanResult *pCsrBssDescription = NULL;
3819 tANI_U32 cbBSSDesc;
3820 tANI_U32 cbAllocated;
Sushant Kaushik6274de62015-05-01 16:31:23 +05303821 tListElem *pEntry;
Jeff Johnson295189b2012-06-20 16:38:30 -07003822
3823 // figure out how big the BSS description is (the BSSDesc->length does NOT
3824 // include the size of the length field itself).
3825 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
3826
3827 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
3828
Kiet Lam64c1b492013-07-12 13:56:44 +05303829 pCsrBssDescription = vos_mem_malloc(cbAllocated);
3830 if ( NULL != pCsrBssDescription )
Jeff Johnson295189b2012-06-20 16:38:30 -07003831 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303832 vos_mem_set(pCsrBssDescription, cbAllocated, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003833 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Kiet Lam64c1b492013-07-12 13:56:44 +05303834 vos_mem_copy(&pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc);
Jeff Johnson295189b2012-06-20 16:38:30 -07003835#if defined(VOSS_ENSBALED)
3836 VOS_ASSERT( pCsrBssDescription->Result.pvIes == NULL );
3837#endif
3838 csrScanAddResult(pMac, pCsrBssDescription, pIes);
Sushant Kaushik6274de62015-05-01 16:31:23 +05303839 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
Jeff Johnson295189b2012-06-20 16:38:30 -07003840 }
3841
3842 return( pCsrBssDescription );
3843}
3844
3845// Append a Bss Description...
3846tCsrScanResult *csrScanAppendBssDescription( tpAniSirGlobal pMac,
3847 tSirBssDescription *pSirBssDescription,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07003848 tDot11fBeaconIEs *pIes, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07003849{
3850 tCsrScanResult *pCsrBssDescription = NULL;
3851 tAniSSID tmpSsid;
3852 v_TIME_t timer = 0;
3853 int result;
3854
3855 tmpSsid.length = 0;
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07003856 result = csrRemoveDupBssDescription( pMac, pSirBssDescription, pIes, &tmpSsid, &timer, fForced );
Jeff Johnson295189b2012-06-20 16:38:30 -07003857 pCsrBssDescription = csrScanSaveBssDescription( pMac, pSirBssDescription, pIes );
3858 if (result && (pCsrBssDescription != NULL))
3859 {
3860 //Check if the new one has SSID it it, if not, use the older SSID if it exists.
3861 if( (0 == pCsrBssDescription->Result.ssId.length) && tmpSsid.length )
3862 {
3863 //New BSS has a hidden SSID and old one has the SSID. Keep the SSID only
3864 //if diff of saved SSID time and current time is less than 1 min to avoid
3865 //side effect of saving SSID with old one is that if AP changes its SSID while remain
3866 //hidden, we may never see it and also to address the requirement of
3867 //When we remove hidden ssid from the profile i.e., forget the SSID via
3868 // GUI that SSID shouldn't see in the profile
3869 if((vos_timer_get_system_time()-timer) <= HIDDEN_TIMER)
3870 {
3871 pCsrBssDescription->Result.ssId = tmpSsid;
3872 pCsrBssDescription->Result.timer = timer;
3873 }
3874 }
3875 }
3876
3877
3878 return( pCsrBssDescription );
3879}
3880
3881
3882
3883void csrPurgeChannelPower( tpAniSirGlobal pMac, tDblLinkList *pChannelList )
3884{
3885 tCsrChannelPowerInfo *pChannelSet;
3886 tListElem *pEntry;
3887
3888 csrLLLock(pChannelList);
3889 // Remove the channel sets from the learned list and put them in the free list
3890 while( ( pEntry = csrLLRemoveHead( pChannelList, LL_ACCESS_NOLOCK ) ) != NULL)
3891 {
3892 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3893 if( pChannelSet )
3894 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303895 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003896 }
3897 }
3898 csrLLUnlock(pChannelList);
3899 return;
3900}
3901
3902
3903/*
3904 * Save the channelList into the ultimate storage as the final stage of channel
3905 * Input: pCountryInfo -- the country code (e.g. "USI"), channel list, and power limit are all stored inside this data structure
3906 */
Jeff Johnsone7245742012-09-05 17:12:55 -07003907eHalStatus csrSaveToChannelPower2G_5G( tpAniSirGlobal pMac, tANI_U32 tableSize, tSirMacChanInfo *channelTable )
Jeff Johnson295189b2012-06-20 16:38:30 -07003908{
3909 tANI_U32 i = tableSize / sizeof( tSirMacChanInfo );
3910 tSirMacChanInfo *pChannelInfo;
3911 tCsrChannelPowerInfo *pChannelSet;
3912 tANI_BOOLEAN f2GHzInfoFound = FALSE;
3913 tANI_BOOLEAN f2GListPurged = FALSE, f5GListPurged = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003914
3915 pChannelInfo = channelTable;
3916 // atleast 3 bytes have to be remaining -- from "countryString"
3917 while ( i-- )
3918 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303919 pChannelSet = vos_mem_malloc(sizeof(tCsrChannelPowerInfo));
3920 if ( NULL != pChannelSet )
Jeff Johnson295189b2012-06-20 16:38:30 -07003921 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303922 vos_mem_set(pChannelSet, sizeof(tCsrChannelPowerInfo), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003923 pChannelSet->firstChannel = pChannelInfo->firstChanNum;
3924 pChannelSet->numChannels = pChannelInfo->numChannels;
3925
3926 // Now set the inter-channel offset based on the frequency band the channel set lies in
Jeff Johnsone7245742012-09-05 17:12:55 -07003927 if( (CSR_IS_CHANNEL_24GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003928 ((pChannelSet->firstChannel + (pChannelSet->numChannels - 1)) <= CSR_MAX_24GHz_CHANNEL_NUMBER) )
Jeff Johnsone7245742012-09-05 17:12:55 -07003929
Jeff Johnson295189b2012-06-20 16:38:30 -07003930 {
3931 pChannelSet->interChannelOffset = 1;
3932 f2GHzInfoFound = TRUE;
3933 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003934 else if ( (CSR_IS_CHANNEL_5GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003935 ((pChannelSet->firstChannel + ((pChannelSet->numChannels - 1) * 4)) <= CSR_MAX_5GHz_CHANNEL_NUMBER) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003936 {
3937 pChannelSet->interChannelOffset = 4;
3938 f2GHzInfoFound = FALSE;
3939 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003940 else
3941 {
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003942 smsLog( pMac, LOGW, FL("Invalid Channel %d Present in Country IE"),
Jeff Johnsone7245742012-09-05 17:12:55 -07003943 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303944 vos_mem_free(pChannelSet);
Jeff Johnsone7245742012-09-05 17:12:55 -07003945 return eHAL_STATUS_FAILURE;
3946 }
3947
Jeff Johnson295189b2012-06-20 16:38:30 -07003948 pChannelSet->txPower = CSR_ROAM_MIN( pChannelInfo->maxTxPower, pMac->roam.configParam.nTxPowerCap );
3949
3950 if( f2GHzInfoFound )
3951 {
3952 if( !f2GListPurged )
3953 {
3954 // purge previous results if found new
3955 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList24 );
3956 f2GListPurged = TRUE;
3957 }
3958
3959 if(CSR_IS_OPERATING_BG_BAND(pMac))
3960 {
3961 // add to the list of 2.4 GHz channel sets
3962 csrLLInsertTail( &pMac->scan.channelPowerInfoList24, &pChannelSet->link, LL_ACCESS_LOCK );
3963 }
3964 else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003965 smsLog( pMac, LOGW, FL("Adding 11B/G channels in 11A mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003966 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303967 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003968 }
3969 }
3970 else
3971 {
3972 // 5GHz info found
3973 if( !f5GListPurged )
3974 {
3975 // purge previous results if found new
3976 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList5G );
3977 f5GListPurged = TRUE;
3978 }
3979
3980 if(CSR_IS_OPERATING_A_BAND(pMac))
3981 {
3982 // add to the list of 5GHz channel sets
3983 csrLLInsertTail( &pMac->scan.channelPowerInfoList5G, &pChannelSet->link, LL_ACCESS_LOCK );
3984 }
3985 else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003986 smsLog( pMac, LOGW, FL("Adding 11A channels in B/G mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003987 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303988 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003989 }
3990 }
3991 }
3992
3993 pChannelInfo++; // move to next entry
3994 }
3995
Jeff Johnsone7245742012-09-05 17:12:55 -07003996 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07003997}
3998
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303999static void csrClearDfsChannelList( tpAniSirGlobal pMac )
4000{
4001 tSirMbMsg *pMsg;
4002 tANI_U16 msgLen;
Jeff Johnson295189b2012-06-20 16:38:30 -07004003
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05304004 msgLen = (tANI_U16)(sizeof( tSirMbMsg ));
Kiet Lam64c1b492013-07-12 13:56:44 +05304005 pMsg = vos_mem_malloc(msgLen);
4006 if ( NULL != pMsg )
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05304007 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304008 vos_mem_set((void *)pMsg, msgLen, 0);
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05304009 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_CLEAR_DFS_CHANNEL_LIST);
4010 pMsg->msgLen = pal_cpu_to_be16(msgLen);
4011 palSendMBMessage(pMac->hHdd, pMsg);
4012 }
4013}
Jeff Johnson295189b2012-06-20 16:38:30 -07004014
4015void csrApplyPower2Current( tpAniSirGlobal pMac )
4016{
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004017 smsLog( pMac, LOG3, FL(" Updating Cfg with power settings"));
Jeff Johnson295189b2012-06-20 16:38:30 -07004018 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList24, WNI_CFG_MAX_TX_POWER_2_4 );
4019 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList5G, WNI_CFG_MAX_TX_POWER_5 );
4020}
4021
4022
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004023void csrApplyChannelPowerCountryInfo( tpAniSirGlobal pMac, tCsrChannel *pChannelList, tANI_U8 *countryCode, tANI_BOOLEAN updateRiva)
Jeff Johnson295189b2012-06-20 16:38:30 -07004024{
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304025 int i, j, count, countryIndex = -1;
Jeff Johnson295189b2012-06-20 16:38:30 -07004026 tANI_U8 numChannels = 0;
4027 tANI_U8 tempNumChannels = 0;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304028 tANI_U8 channelIgnore = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004029 tCsrChannel ChannelList;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304030
Jeff Johnson295189b2012-06-20 16:38:30 -07004031 if( pChannelList->numChannels )
4032 {
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304033 for(count=0; count < MAX_COUNTRY_IGNORE; count++)
4034 {
4035 if(vos_mem_compare(countryCode, countryIgnoreList[count].countryCode,
4036 VOS_COUNTRY_CODE_LEN))
4037 {
4038 countryIndex = count;
4039 break;
4040 }
4041 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004042 tempNumChannels = CSR_MIN(pChannelList->numChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN);
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05304043
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304044 for(i=0; i < tempNumChannels; i++)
Jeff Johnson295189b2012-06-20 16:38:30 -07004045 {
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304046 channelIgnore = FALSE;
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05304047 if( countryIndex != -1 )
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304048 {
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05304049 for(j=0; j < countryIgnoreList[countryIndex].channelCount; j++)
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304050 {
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05304051 if( pChannelList->channelList[i] ==
4052 countryIgnoreList[countryIndex].channelList[j] )
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304053 {
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05304054 channelIgnore = TRUE;
4055 break;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304056 }
4057 }
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05304058 }
4059 if( FALSE == channelIgnore )
4060 {
4061 ChannelList.channelList[numChannels] = pChannelList->channelList[i];
4062 numChannels++;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304063 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004064 }
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304065 ChannelList.numChannels = numChannels;
Mahesh A Saptasagar1ed59582014-06-04 18:45:07 +05304066 csrApplyPower2Current( pMac ); // Store the channel+power info in the global place: Cfg
Jeff Johnson295189b2012-06-20 16:38:30 -07004067 csrSetCfgValidChannelList(pMac, ChannelList.channelList, ChannelList.numChannels);
4068 // extend scan capability
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304069 // build a scan list based on the channel list : channel# + active/passive scan
4070 csrSetCfgScanControlList(pMac, countryCode, &ChannelList);
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05304071 /*Send msg to Lim to clear DFS channel list */
4072 csrClearDfsChannelList(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07004073#ifdef FEATURE_WLAN_SCAN_PNO
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004074 if (updateRiva)
4075 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004076 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO, FL(" Sending 11d PNO info to Riva"));
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004077 // Send HAL UpdateScanParams message
4078 pmcUpdateScanParams(pMac, &(pMac->roam.configParam), &ChannelList, TRUE);
4079 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004080#endif // FEATURE_WLAN_SCAN_PNO
4081 }
4082 else
4083 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004084 smsLog( pMac, LOGE, FL(" 11D channel list is empty"));
Jeff Johnson295189b2012-06-20 16:38:30 -07004085 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004086 csrSetCfgCountryCode(pMac, countryCode);
4087}
4088
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004089void csrResetCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce, tANI_BOOLEAN updateRiva )
Jeff Johnson295189b2012-06-20 16:38:30 -07004090{
4091 if( fForce || (csrIs11dSupported( pMac ) && (!pMac->scan.f11dInfoReset)))
4092 {
4093
4094#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4095 {
4096 vos_log_802_11d_pkt_type *p11dLog;
4097 int Index;
4098
4099 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
4100 if(p11dLog)
4101 {
4102 p11dLog->eventId = WLAN_80211D_EVENT_RESET;
Kiet Lam64c1b492013-07-12 13:56:44 +05304103 vos_mem_copy(p11dLog->countryCode, pMac->scan.countryCodeCurrent, 3);
Jeff Johnson295189b2012-06-20 16:38:30 -07004104 p11dLog->numChannel = pMac->scan.base20MHzChannels.numChannels;
4105 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
4106 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304107 vos_mem_copy(p11dLog->Channels,
4108 pMac->scan.base20MHzChannels.channelList,
4109 p11dLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07004110 for (Index=0; Index < pMac->scan.base20MHzChannels.numChannels; Index++)
4111 {
4112 p11dLog->TxPwr[Index] = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
4113 }
4114 }
4115 if(!pMac->roam.configParam.Is11dSupportEnabled)
4116 {
4117 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
4118 }
4119 else if(pMac->roam.configParam.fEnforceDefaultDomain)
4120 {
4121 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
4122 }
4123 else
4124 {
4125 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
4126 }
4127 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
4128 }
4129 }
4130#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4131
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004132 csrPruneChannelListForMode(pMac, &pMac->scan.baseChannels);
4133 csrPruneChannelListForMode(pMac, &pMac->scan.base20MHzChannels);
4134
Jeff Johnson295189b2012-06-20 16:38:30 -07004135 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_FALSE);
4136 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_TRUE);
4137 // ... and apply the channel list, power settings, and the country code.
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004138 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.base20MHzChannels, pMac->scan.countryCodeCurrent, updateRiva );
Jeff Johnson295189b2012-06-20 16:38:30 -07004139 // clear the 11d channel list
Kiet Lam64c1b492013-07-12 13:56:44 +05304140 vos_mem_set(&pMac->scan.channels11d, sizeof(pMac->scan.channels11d), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004141 pMac->scan.f11dInfoReset = eANI_BOOLEAN_TRUE;
4142 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_FALSE;
4143 }
4144
4145 return;
4146}
4147
4148
4149eHalStatus csrResetCountryCodeInformation(tpAniSirGlobal pMac, tANI_BOOLEAN *pfRestartNeeded)
4150{
4151 eHalStatus status = eHAL_STATUS_SUCCESS;
4152 tANI_BOOLEAN fRestart = eANI_BOOLEAN_FALSE;
4153
4154 //Use the Country code and domain from EEPROM
Kiet Lam64c1b492013-07-12 13:56:44 +05304155 vos_mem_copy(pMac->scan.countryCodeCurrent, pMac->scan.countryCodeDefault,
4156 WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07004157 csrSetRegulatoryDomain(pMac, pMac->scan.domainIdCurrent, &fRestart);
Jeff Johnson43971f52012-07-17 12:26:56 -07004158 if( ((eANI_BOOLEAN_FALSE == fRestart) || (pfRestartNeeded == NULL) )
4159 && !csrIsInfraConnected(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -07004160 {
4161 //Only reset the country info if we don't need to restart
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004162 csrResetCountryInformation(pMac, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07004163 }
4164 if(pfRestartNeeded)
4165 {
4166 *pfRestartNeeded = fRestart;
4167 }
4168
4169 return (status);
4170}
4171
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05304172void csrClearVotesForCountryInfo(tpAniSirGlobal pMac)
4173{
4174 pMac->scan.countryCodeCount = 0;
4175 vos_mem_set(pMac->scan.votes11d,
4176 sizeof(tCsrVotes11d) * CSR_MAX_NUM_COUNTRY_CODE, 0);
4177}
4178
4179void csrAddVoteForCountryInfo(tpAniSirGlobal pMac, tANI_U8 *pCountryCode)
4180{
4181 tANI_BOOLEAN match = FALSE;
4182 tANI_U8 i;
4183
4184 /* convert to UPPER here so we are assured
4185 * the strings are always in upper case.
4186 */
4187 for( i = 0; i < 3; i++ )
4188 {
4189 pCountryCode[ i ] = (tANI_U8)csrToUpper( pCountryCode[ i ] );
4190 }
4191
4192 /* Some of the 'old' Cisco 350 series AP's advertise NA as the
4193 * country code (for North America ??). NA is not a valid country code
4194 * or domain so let's allow this by changing it to the proper
4195 * country code (which is US). We've also seen some NETGEAR AP's
4196 * that have "XX " as the country code with valid 2.4 GHz US channel
4197 * information. If we cannot find the country code advertised in the
4198 * 11d information element, let's default to US.
4199 */
4200
4201 if ( !HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry( pMac,
4202 pCountryCode, NULL,COUNTRY_QUERY ) ) )
4203 {
4204 pCountryCode[ 0 ] = '0';
4205 pCountryCode[ 1 ] = '0';
4206 }
4207
4208 /* We've seen some of the AP's improperly put a 0 for the
4209 * third character of the country code. spec says valid charcters are
4210 * 'O' (for outdoor), 'I' for Indoor, or ' ' (space; for either).
4211 * if we see a 0 in this third character, let's change it to a ' '.
4212 */
4213 if ( 0 == pCountryCode[ 2 ] )
4214 {
4215 pCountryCode[ 2 ] = ' ';
4216 }
4217
4218 for (i = 0; i < pMac->scan.countryCodeCount; i++)
4219 {
4220 match = (vos_mem_compare(pMac->scan.votes11d[i].countryCode,
4221 pCountryCode, 2));
4222 if(match)
4223 {
4224 break;
4225 }
4226 }
4227
4228 if (match)
4229 {
4230 pMac->scan.votes11d[i].votes++;
4231 }
4232 else
4233 {
4234 vos_mem_copy( pMac->scan.votes11d[pMac->scan.countryCodeCount].countryCode,
4235 pCountryCode, 3 );
4236 pMac->scan.votes11d[pMac->scan.countryCodeCount].votes = 1;
4237 pMac->scan.countryCodeCount++;
4238 }
4239
4240 return;
4241}
4242
4243tANI_BOOLEAN csrElectedCountryInfo(tpAniSirGlobal pMac)
4244{
4245 tANI_BOOLEAN fRet = FALSE;
4246 tANI_U8 maxVotes = 0;
4247 tANI_U8 i, j=0;
4248
4249 if (!pMac->scan.countryCodeCount)
4250 {
Agrawal Ashishbd3a5932016-04-12 16:22:39 +05304251 VOS_TRACE( VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_WARN,
4252 "No AP with 11d Country code is present in scan list");
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05304253 return fRet;
4254 }
4255 maxVotes = pMac->scan.votes11d[0].votes;
4256 fRet = TRUE;
4257
4258 for(i = 1; i < pMac->scan.countryCodeCount; i++)
4259 {
4260 /* If we have a tie for max votes for 2 different country codes,
4261 * pick random.we can put some more intelligence - TBD
4262 */
4263 if (maxVotes < pMac->scan.votes11d[i].votes)
4264 {
4265 VOS_TRACE( VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
4266 " Votes for Country %c%c : %d\n",
4267 pMac->scan.votes11d[i].countryCode[0],
4268 pMac->scan.votes11d[i].countryCode[1],
4269 pMac->scan.votes11d[i].votes);
4270
4271 maxVotes = pMac->scan.votes11d[i].votes;
4272 j = i;
4273 fRet = TRUE;
4274 }
4275
4276 }
4277 if (fRet)
4278 {
Rajesh Babu Prathipati20cdffa2014-07-01 22:24:59 +05304279 vos_mem_copy(pMac->scan.countryCodeElected,
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05304280 pMac->scan.votes11d[j].countryCode, WNI_CFG_COUNTRY_CODE_LEN);
Rajesh Babu Prathipati20cdffa2014-07-01 22:24:59 +05304281 vos_mem_copy(pMac->scan.countryCode11d,
Agarwal Ashish852b2c32014-05-23 17:13:25 +05304282 pMac->scan.votes11d[j].countryCode, WNI_CFG_COUNTRY_CODE_LEN);
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05304283 VOS_TRACE( VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
4284 "Selected Country is %c%c With count %d\n",
4285 pMac->scan.votes11d[j].countryCode[0],
4286 pMac->scan.votes11d[j].countryCode[1],
4287 pMac->scan.votes11d[j].votes);
4288 }
4289 return fRet;
4290}
Jeff Johnson295189b2012-06-20 16:38:30 -07004291
4292eHalStatus csrSetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pCountry, tANI_BOOLEAN *pfRestartNeeded)
4293{
4294 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
4295 v_REGDOMAIN_t domainId;
4296
4297 if(pCountry)
4298 {
Kiet Lam6c583332013-10-14 05:37:09 +05304299 status = csrGetRegulatoryDomainForCountry(pMac, pCountry, &domainId, COUNTRY_USER);
Jeff Johnson295189b2012-06-20 16:38:30 -07004300 if(HAL_STATUS_SUCCESS(status))
4301 {
4302 status = csrSetRegulatoryDomain(pMac, domainId, pfRestartNeeded);
4303 if(HAL_STATUS_SUCCESS(status))
4304 {
4305 //We don't need to check the pMac->roam.configParam.fEnforceDefaultDomain flag here,
4306 //csrSetRegulatoryDomain will fail if the country doesn't fit our domain criteria.
Kiet Lam64c1b492013-07-12 13:56:44 +05304307 vos_mem_copy(pMac->scan.countryCodeCurrent, pCountry, WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07004308 if((pfRestartNeeded == NULL) || !(*pfRestartNeeded))
4309 {
4310 //Simply set it to cfg. If we need to restart, restart will apply it to the CFG
4311 csrSetCfgCountryCode(pMac, pCountry);
4312 }
4313 }
4314 }
4315 }
4316
4317 return (status);
4318}
4319
4320
4321
4322//caller allocated memory for pNumChn and pChnPowerInfo
4323//As input, *pNumChn has the size of the array of pChnPowerInfo
4324//Upon return, *pNumChn has the number of channels assigned.
4325void csrGetChannelPowerInfo( tpAniSirGlobal pMac, tDblLinkList *pList,
4326 tANI_U32 *pNumChn, tChannelListWithPower *pChnPowerInfo)
4327{
4328 tListElem *pEntry;
4329 tANI_U32 chnIdx = 0, idx;
4330 tCsrChannelPowerInfo *pChannelSet;
4331
4332 //Get 2.4Ghz first
4333 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
4334 while( pEntry && (chnIdx < *pNumChn) )
4335 {
4336 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
4337 if ( 1 != pChannelSet->interChannelOffset )
4338 {
4339 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
4340 {
4341 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
4342 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
4343 }
4344 }
4345 else
4346 {
4347 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
4348 {
4349 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + idx);
4350 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
4351 }
4352 }
4353
4354 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
4355 }
4356 *pNumChn = chnIdx;
4357
4358 return ;
4359}
4360
4361
4362
4363void csrApplyCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce )
4364{
4365 v_REGDOMAIN_t domainId;
4366 eHalStatus status = eHAL_STATUS_SUCCESS;
4367
4368 do
4369 {
4370 if( !csrIs11dSupported( pMac ) || 0 == pMac->scan.channelOf11dInfo) break;
4371 if( pMac->scan.fAmbiguous11dInfoFound )
4372 {
4373 // ambiguous info found
4374 //Restore te default domain as well
Kiet Lam6c583332013-10-14 05:37:09 +05304375 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
4376 pMac, pMac->scan.countryCodeCurrent,
4377 &domainId, COUNTRY_QUERY)))
Jeff Johnson295189b2012-06-20 16:38:30 -07004378 {
4379 pMac->scan.domainIdCurrent = domainId;
4380 }
4381 else
4382 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004383 smsLog(pMac, LOGE, FL(" failed to get domain from currentCountryCode %02X%02X"),
Jeff Johnson295189b2012-06-20 16:38:30 -07004384 pMac->scan.countryCodeCurrent[0], pMac->scan.countryCodeCurrent[1]);
4385 }
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004386 csrResetCountryInformation( pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE );
Jeff Johnson295189b2012-06-20 16:38:30 -07004387 break;
4388 }
4389 if ( pMac->scan.f11dInfoApplied && !fForce ) break;
Kiet Lam6c583332013-10-14 05:37:09 +05304390 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
4391 pMac, pMac->scan.countryCode11d,
4392 &domainId, COUNTRY_QUERY)))
Jeff Johnson295189b2012-06-20 16:38:30 -07004393 {
4394 //Check whether we need to enforce default domain
4395 if( ( !pMac->roam.configParam.fEnforceDefaultDomain ) ||
4396 (pMac->scan.domainIdCurrent == domainId) )
4397 {
4398
4399#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4400 {
4401 vos_log_802_11d_pkt_type *p11dLog;
4402 tChannelListWithPower chnPwrInfo[WNI_CFG_VALID_CHANNEL_LIST_LEN];
4403 tANI_U32 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN, nTmp;
4404
4405 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
4406 if(p11dLog)
4407 {
4408 p11dLog->eventId = WLAN_80211D_EVENT_COUNTRY_SET;
Kiet Lam64c1b492013-07-12 13:56:44 +05304409 vos_mem_copy(p11dLog->countryCode, pMac->scan.countryCode11d, 3);
Jeff Johnson295189b2012-06-20 16:38:30 -07004410 p11dLog->numChannel = pMac->scan.channels11d.numChannels;
4411 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
4412 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304413 vos_mem_copy(p11dLog->Channels,
4414 pMac->scan.channels11d.channelList,
4415 p11dLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07004416 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList24,
4417 &nChnInfo, chnPwrInfo);
4418 nTmp = nChnInfo;
4419 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN - nTmp;
4420 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList5G,
4421 &nChnInfo, &chnPwrInfo[nTmp]);
4422 for(nTmp = 0; nTmp < p11dLog->numChannel; nTmp++)
4423 {
4424 for(nChnInfo = 0; nChnInfo < WNI_CFG_VALID_CHANNEL_LIST_LEN; nChnInfo++)
4425 {
4426 if(p11dLog->Channels[nTmp] == chnPwrInfo[nChnInfo].chanId)
4427 {
4428 p11dLog->TxPwr[nTmp] = chnPwrInfo[nChnInfo].pwr;
4429 break;
4430 }
4431 }
4432 }
4433 }
4434 if(!pMac->roam.configParam.Is11dSupportEnabled)
4435 {
4436 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
4437 }
4438 else if(pMac->roam.configParam.fEnforceDefaultDomain)
4439 {
4440 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
4441 }
4442 else
4443 {
4444 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
4445 }
4446 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
4447 }
4448 }
4449#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4450 if(pMac->scan.domainIdCurrent != domainId)
4451 {
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05304452 smsLog(pMac, LOGW, FL("Domain Changed Old %s (%d), new %s"),
4453 voss_DomainIdtoString(pMac->scan.domainIdCurrent),
4454 pMac->scan.domainIdCurrent,
4455 voss_DomainIdtoString(domainId));
Abhishek Singha306a442013-11-07 18:39:01 +05304456 status = WDA_SetRegDomain(pMac, domainId, eSIR_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07004457 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004458 if (status != eHAL_STATUS_SUCCESS)
4459 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004460 smsLog( pMac, LOGE, FL(" fail to set regId %d"), domainId );
Jeff Johnson295189b2012-06-20 16:38:30 -07004461 }
4462 pMac->scan.domainIdCurrent = domainId;
Kiet Lam6c583332013-10-14 05:37:09 +05304463#ifndef CONFIG_ENABLE_LINUX_REG
Kiet Lambb14e952013-11-19 14:58:29 +05304464 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.base20MHzChannels,
4465 pMac->scan.countryCodeCurrent, eANI_BOOLEAN_TRUE );
Kiet Lam6c583332013-10-14 05:37:09 +05304466#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004467 // switch to active scans using this new channel list
4468 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
4469 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_TRUE;
4470 pMac->scan.f11dInfoReset = eANI_BOOLEAN_FALSE;
4471 }
4472 }
4473
4474 } while( 0 );
4475
4476 return;
4477}
4478
4479
4480
4481tANI_BOOLEAN csrSave11dCountryString( tpAniSirGlobal pMac, tANI_U8 *pCountryCode,
4482 tANI_BOOLEAN fForce)
4483{
4484 tANI_BOOLEAN fCountryStringChanged = FALSE, fUnknownCountryCode = FALSE;
4485 tANI_U32 i;
Kiet Lam6c583332013-10-14 05:37:09 +05304486 v_REGDOMAIN_t regd;
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004487 tANI_BOOLEAN fCountryNotPresentInDriver = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004488
4489 // convert to UPPER here so we are assured the strings are always in upper case.
4490 for( i = 0; i < 3; i++ )
4491 {
4492 pCountryCode[ i ] = (tANI_U8)csrToUpper( pCountryCode[ i ] );
4493 }
4494
4495 // Some of the 'old' Cisco 350 series AP's advertise NA as the country code (for North America ??).
4496 // NA is not a valid country code or domain so let's allow this by changing it to the proper
4497 // country code (which is US). We've also seen some NETGEAR AP's that have "XX " as the country code
4498 // with valid 2.4 GHz US channel information. If we cannot find the country code advertised in the
4499 // 11d information element, let's default to US.
Kiet Lam6c583332013-10-14 05:37:09 +05304500 if ( !HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(pMac,
4501 pCountryCode,
4502 &regd,
4503 COUNTRY_QUERY) ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07004504 {
4505 // Check the enforcement first
4506 if( pMac->roam.configParam.fEnforceDefaultDomain || pMac->roam.configParam.fEnforceCountryCodeMatch )
4507 {
4508 fUnknownCountryCode = TRUE;
4509 }
4510 else
4511 {
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004512 fCountryNotPresentInDriver = TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004513 }
4514 }
Tushnim Bhattacharyyac3c1e8e2013-10-29 17:27:43 -07004515 //right now, even if we don't find the CC in driver we set to world. Making
4516 //sure countryCode11d doesn't get updated with the invalid CC, instead
4517 //reflect the world CC
4518 else if (REGDOMAIN_WORLD == regd)
4519 {
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004520 fCountryNotPresentInDriver = TRUE;
Tushnim Bhattacharyyac3c1e8e2013-10-29 17:27:43 -07004521 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004522
4523 // We've seen some of the AP's improperly put a 0 for the third character of the country code.
4524 // spec says valid charcters are 'O' (for outdoor), 'I' for Indoor, or ' ' (space; for either).
4525 // if we see a 0 in this third character, let's change it to a ' '.
4526 if ( 0 == pCountryCode[ 2 ] )
4527 {
4528 pCountryCode[ 2 ] = ' ';
4529 }
4530
4531 if( !fUnknownCountryCode )
4532 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304533 fCountryStringChanged = (!vos_mem_compare(pMac->scan.countryCode11d, pCountryCode, 2));
Jeff Johnson295189b2012-06-20 16:38:30 -07004534
4535
4536 if(( 0 == pMac->scan.countryCode11d[ 0 ] && 0 == pMac->scan.countryCode11d[ 1 ] )
4537 || (fForce))
4538 {
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004539 if (!fCountryNotPresentInDriver)
4540 {
4541 // this is the first .11d information
4542 vos_mem_copy(pMac->scan.countryCode11d, pCountryCode,
Kiet Lam64c1b492013-07-12 13:56:44 +05304543 sizeof( pMac->scan.countryCode11d ));
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004544
4545 }
4546 else
4547 {
4548 pMac->scan.countryCode11d[0] = '0';
4549 pMac->scan.countryCode11d[1] = '0';
4550 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004551 }
4552 }
4553
4554 return( fCountryStringChanged );
4555}
4556
4557
4558void csrSaveChannelPowerForBand( tpAniSirGlobal pMac, tANI_BOOLEAN fPopulate5GBand )
4559{
4560 tANI_U32 Index, count=0;
4561 tSirMacChanInfo *pChanInfo;
4562 tSirMacChanInfo *pChanInfoStart;
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08004563 tANI_S32 maxChannelIndex;
4564
4565 maxChannelIndex = ( pMac->scan.base20MHzChannels.numChannels < WNI_CFG_VALID_CHANNEL_LIST_LEN ) ?
4566 pMac->scan.base20MHzChannels.numChannels : WNI_CFG_VALID_CHANNEL_LIST_LEN ;
Jeff Johnson295189b2012-06-20 16:38:30 -07004567
Kiet Lam64c1b492013-07-12 13:56:44 +05304568 pChanInfo = vos_mem_malloc(sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN);
4569 if ( NULL != pChanInfo )
Jeff Johnson295189b2012-06-20 16:38:30 -07004570 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304571 vos_mem_set(pChanInfo, sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004572 pChanInfoStart = pChanInfo;
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08004573 for (Index=0; Index < maxChannelIndex; Index++)
Jeff Johnson295189b2012-06-20 16:38:30 -07004574 {
4575 if ((fPopulate5GBand && (CSR_IS_CHANNEL_5GHZ(pMac->scan.defaultPowerTable[Index].chanId))) ||
4576 (!fPopulate5GBand && (CSR_IS_CHANNEL_24GHZ(pMac->scan.defaultPowerTable[Index].chanId))) )
4577 {
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08004578 if(count >= WNI_CFG_VALID_CHANNEL_LIST_LEN)
4579 {
4580 smsLog( pMac, LOGW, FL(" csrSaveChannelPowerForBand, count exceeded, count = %d"), count);
4581 break;
4582 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004583 pChanInfo->firstChanNum = pMac->scan.defaultPowerTable[Index].chanId;
4584 pChanInfo->numChannels = 1;
4585 pChanInfo->maxTxPower = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
4586 pChanInfo++;
4587 count++;
4588 }
4589 }
4590 if(count)
4591 {
4592 csrSaveToChannelPower2G_5G( pMac, count * sizeof(tSirMacChanInfo), pChanInfoStart );
4593 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304594 vos_mem_free(pChanInfoStart);
Jeff Johnson295189b2012-06-20 16:38:30 -07004595 }
4596}
4597
4598
4599void csrSetOppositeBandChannelInfo( tpAniSirGlobal pMac )
4600{
4601 tANI_BOOLEAN fPopulate5GBand = FALSE;
4602
4603 do
4604 {
4605 // if this is not a dual band product, then we don't need to set the opposite
4606 // band info. We only work in one band so no need to look in the other band.
4607 if ( !CSR_IS_OPEARTING_DUAL_BAND( pMac ) ) break;
4608 // if we found channel info on the 5.0 band and...
4609 if ( CSR_IS_CHANNEL_5GHZ( pMac->scan.channelOf11dInfo ) )
4610 {
4611 // and the 2.4 band is empty, then populate the 2.4 channel info
Kiet Lam8d985a02013-10-11 03:39:41 +05304612 if ( !csrLLIsListEmpty( &pMac->scan.channelPowerInfoList24, LL_ACCESS_LOCK ) ) break;
Jeff Johnson295189b2012-06-20 16:38:30 -07004613 fPopulate5GBand = FALSE;
4614 }
4615 else
4616 {
4617 // else, we found channel info in the 2.4 GHz band. If the 5.0 band is empty
4618 // set the 5.0 band info from the 2.4 country code.
Kiet Lam8d985a02013-10-11 03:39:41 +05304619 if ( !csrLLIsListEmpty( &pMac->scan.channelPowerInfoList5G, LL_ACCESS_LOCK ) ) break;
Jeff Johnson295189b2012-06-20 16:38:30 -07004620 fPopulate5GBand = TRUE;
4621 }
4622 csrSaveChannelPowerForBand( pMac, fPopulate5GBand );
4623
4624 } while( 0 );
4625}
4626
4627
4628tANI_BOOLEAN csrIsSupportedChannel(tpAniSirGlobal pMac, tANI_U8 channelId)
4629{
4630 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
4631 tANI_U32 i;
4632
4633 //Make sure it is a channel that is in our supported list.
4634 for ( i = 0; i < pMac->scan.baseChannels.numChannels; i++ )
4635 {
4636 if ( channelId == pMac->scan.baseChannels.channelList[i] )
4637 {
4638 fRet = eANI_BOOLEAN_TRUE;
4639 break;
4640 }
4641 }
4642
4643 //If it is configured to limit a set of the channels
4644 if( fRet && pMac->roam.configParam.fEnforce11dChannels )
4645 {
4646 fRet = eANI_BOOLEAN_FALSE;
4647 for ( i = 0; i < pMac->scan.base20MHzChannels.numChannels; i++ )
4648 {
4649 if ( channelId == pMac->scan.base20MHzChannels.channelList[i] )
4650 {
4651 fRet = eANI_BOOLEAN_TRUE;
4652 break;
4653 }
4654 }
4655 }
4656
4657 return (fRet);
4658}
4659
4660
4661
4662//bSize specify the buffer size of pChannelList
4663tANI_U8 csrGetChannelListFromChannelSet( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 bSize, tCsrChannelPowerInfo *pChannelSet )
4664{
4665 tANI_U8 i, j = 0, chnId;
4666
4667 bSize = CSR_MIN(bSize, pChannelSet->numChannels);
4668 for( i = 0; i < bSize; i++ )
4669 {
4670 chnId = (tANI_U8)(pChannelSet->firstChannel + ( i * pChannelSet->interChannelOffset ));
4671 if ( csrIsSupportedChannel( pMac, chnId ) )
4672 {
4673 pChannelList[j++] = chnId;
4674 }
4675 }
4676
4677 return (j);
4678}
4679
4680
4681
4682//bSize -- specify the buffer size of pChannelList
4683void csrConstructCurrentValidChannelList( tpAniSirGlobal pMac, tDblLinkList *pChannelSetList,
4684 tANI_U8 *pChannelList, tANI_U8 bSize, tANI_U8 *pNumChannels )
4685{
4686 tListElem *pEntry;
4687 tCsrChannelPowerInfo *pChannelSet;
4688 tANI_U8 numChannels;
4689 tANI_U8 *pChannels;
4690
4691 if( pChannelSetList && pChannelList && pNumChannels )
4692 {
4693 pChannels = pChannelList;
4694 *pNumChannels = 0;
4695 pEntry = csrLLPeekHead( pChannelSetList, LL_ACCESS_LOCK );
4696 while( pEntry )
4697 {
4698 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
4699 numChannels = csrGetChannelListFromChannelSet( pMac, pChannels, bSize, pChannelSet );
4700 pChannels += numChannels;
4701 *pNumChannels += numChannels;
4702 pEntry = csrLLNext( pChannelSetList, pEntry, LL_ACCESS_LOCK );
4703 }
4704 }
4705}
4706
4707
4708/*
4709 * 802.11D only: Gather 11d IE via beacon or Probe response and store them in pAdapter->channels11d
4710*/
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304711tANI_BOOLEAN csrLearnCountryInformation( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc,
4712 tDot11fBeaconIEs *pIes, tANI_BOOLEAN fForce)
Jeff Johnson295189b2012-06-20 16:38:30 -07004713{
Agarwal Ashish60a37ee2014-05-28 17:20:20 +05304714 eHalStatus status;
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304715 tANI_U8 *pCountryCodeSelected;
Jeff Johnson295189b2012-06-20 16:38:30 -07004716 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
4717 v_REGDOMAIN_t domainId;
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304718 tDot11fBeaconIEs *pIesLocal = pIes;
4719 tANI_BOOLEAN useVoting = eANI_BOOLEAN_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004720
Jeff Johnson295189b2012-06-20 16:38:30 -07004721 if (VOS_STA_SAP_MODE == vos_get_conparam ())
4722 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07004723
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304724 if ((NULL == pSirBssDesc) && (NULL == pIes))
4725 useVoting = eANI_BOOLEAN_TRUE;
4726
Jeff Johnson295189b2012-06-20 16:38:30 -07004727 do
4728 {
4729 // check if .11d support is enabled
4730 if( !csrIs11dSupported( pMac ) ) break;
Agarwal Ashish60a37ee2014-05-28 17:20:20 +05304731
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304732 if (eANI_BOOLEAN_FALSE == useVoting)
4733 {
4734 if( !pIesLocal &&
4735 (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
4736 pSirBssDesc, &pIesLocal))))
4737 {
4738 break;
4739 }
4740 // check if country information element is present
4741 if(!pIesLocal->Country.present)
4742 {
4743 //No country info
4744 break;
4745 }
4746
4747 if( HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry
4748 (pMac, pIesLocal->Country.country, &domainId,
4749 COUNTRY_QUERY)) &&
4750 ( domainId == REGDOMAIN_WORLD))
4751 {
4752 break;
4753 }
4754 } //useVoting == eANI_BOOLEAN_FALSE
4755
4756 if (eANI_BOOLEAN_FALSE == useVoting)
4757 pCountryCodeSelected = pIesLocal->Country.country;
4758 else
4759 pCountryCodeSelected = pMac->scan.countryCodeElected;
4760
Kiet Lam8d985a02013-10-11 03:39:41 +05304761 status = csrGetRegulatoryDomainForCountry(pMac,
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304762 pCountryCodeSelected, &domainId, COUNTRY_IE);
Kiet Lam8d985a02013-10-11 03:39:41 +05304763 if ( status != eHAL_STATUS_SUCCESS )
4764 {
4765 smsLog( pMac, LOGE, FL(" fail to get regId %d"), domainId );
4766 fRet = eANI_BOOLEAN_FALSE;
4767 break;
4768 }
Agarwal Ashish7693f2d2014-07-18 18:03:58 +05304769
4770 /* updating 11d Country Code with Country code selected. */
4771
4772 vos_mem_copy(pMac->scan.countryCode11d,
4773 pCountryCodeSelected,
4774 WNI_CFG_COUNTRY_CODE_LEN);
4775
Agarwal Ashish60a37ee2014-05-28 17:20:20 +05304776#ifndef CONFIG_ENABLE_LINUX_REG
Venkata Prathyusha Kuntupalli316247e2013-03-15 17:45:25 -07004777 // Checking for Domain Id change
4778 if ( domainId != pMac->scan.domainIdCurrent )
4779 {
Kiet Lam8d985a02013-10-11 03:39:41 +05304780 vos_mem_copy(pMac->scan.countryCode11d,
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304781 pCountryCodeSelected,
Kiet Lam8d985a02013-10-11 03:39:41 +05304782 sizeof( pMac->scan.countryCode11d ) );
4783 /* Set Current Country code and Current Regulatory domain */
4784 status = csrSetRegulatoryDomain(pMac, domainId, NULL);
4785 if (eHAL_STATUS_SUCCESS != status)
4786 {
4787 smsLog(pMac, LOGE, "Set Reg Domain Fail %d", status);
4788 fRet = eANI_BOOLEAN_FALSE;
4789 return fRet;
4790 }
4791 //csrSetRegulatoryDomain will fail if the country doesn't fit our domain criteria.
4792 vos_mem_copy(pMac->scan.countryCodeCurrent,
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304793 pCountryCodeSelected, WNI_CFG_COUNTRY_CODE_LEN);
Kiet Lam8d985a02013-10-11 03:39:41 +05304794 //Simply set it to cfg.
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304795 csrSetCfgCountryCode(pMac, pCountryCodeSelected);
Kiet Lam8d985a02013-10-11 03:39:41 +05304796
4797 /* overwrite the defualt country code */
4798 vos_mem_copy(pMac->scan.countryCodeDefault,
4799 pMac->scan.countryCodeCurrent,
4800 WNI_CFG_COUNTRY_CODE_LEN);
4801 /* Set Current RegDomain */
Abhishek Singha306a442013-11-07 18:39:01 +05304802 status = WDA_SetRegDomain(pMac, domainId, eSIR_TRUE);
Kiet Lam8d985a02013-10-11 03:39:41 +05304803 if ( status != eHAL_STATUS_SUCCESS )
4804 {
4805 smsLog( pMac, LOGE, FL(" fail to Set regId %d"), domainId );
4806 fRet = eANI_BOOLEAN_FALSE;
4807 return fRet;
4808 }
4809 /* set to default domain ID */
Madan Mohan Koyyalamudi0e5922d2013-09-10 15:45:24 +05304810 pMac->scan.domainIdCurrent = domainId;
Kiet Lam8d985a02013-10-11 03:39:41 +05304811 /* get the channels based on new cc */
4812 status = csrInitGetChannels( pMac );
Jeff Johnson295189b2012-06-20 16:38:30 -07004813
Kiet Lam8d985a02013-10-11 03:39:41 +05304814 if ( status != eHAL_STATUS_SUCCESS )
4815 {
4816 smsLog( pMac, LOGE, FL(" fail to get Channels "));
4817 fRet = eANI_BOOLEAN_FALSE;
4818 return fRet;
4819 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004820
Kiet Lam8d985a02013-10-11 03:39:41 +05304821 /* reset info based on new cc, and we are done */
4822 csrResetCountryInformation(pMac, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
Agarwal Ashishfaef6692014-01-29 19:40:30 +05304823 /* Regulatory Domain Changed, Purge Only scan result
4824 * which does not have channel number belong to 11d
4825 * channel list
4826 */
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05304827 csrScanFilterResults(pMac);
Kiet Lam8d985a02013-10-11 03:39:41 +05304828 }
Kiet Lam6c583332013-10-14 05:37:09 +05304829#endif
4830 fRet = eANI_BOOLEAN_TRUE;
4831
Jeff Johnson295189b2012-06-20 16:38:30 -07004832 } while( 0 );
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304833
4834 if( !pIes && pIesLocal )
4835 {
4836 //locally allocated
4837 vos_mem_free(pIesLocal);
4838 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004839
4840 return( fRet );
4841}
4842
4843
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004844static void csrSaveScanResults( tpAniSirGlobal pMac, tANI_U8 reason )
Jeff Johnson295189b2012-06-20 16:38:30 -07004845{
4846 // initialize this to FALSE. profMoveInterimScanResultsToMainList() routine
4847 // will set this to the channel where an .11d beacon is seen
4848 pMac->scan.channelOf11dInfo = 0;
4849 // if we get any ambiguous .11d information then this will be set to TRUE
4850 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
4851 //Tush
4852 // if we get any ambiguous .11d information, then this will be set to TRUE
4853 // only if the applied 11d info could be found in one of the scan results
4854 pMac->scan.fCurrent11dInfoMatch = eANI_BOOLEAN_FALSE;
4855 // move the scan results from interim list to the main scan list
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004856 csrMoveTempScanResultsToMainList( pMac, reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07004857}
4858
4859
4860void csrReinitScanCmd(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4861{
4862 switch (pCommand->u.scanCmd.reason)
4863 {
4864 case eCsrScanSetBGScanParam:
4865 case eCsrScanAbortBgScan:
4866 if(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList)
4867 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304868 vos_mem_free(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList);
Jeff Johnson295189b2012-06-20 16:38:30 -07004869 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
4870 }
4871 break;
4872 case eCsrScanBGScanAbort:
4873 case eCsrScanBGScanEnable:
4874 case eCsrScanGetScanChnInfo:
4875 break;
4876 case eCsrScanAbortNormalScan:
4877 default:
4878 csrScanFreeRequest(pMac, &pCommand->u.scanCmd.u.scanRequest);
4879 break;
4880 }
4881 if(pCommand->u.scanCmd.pToRoamProfile)
4882 {
4883 csrReleaseProfile(pMac, pCommand->u.scanCmd.pToRoamProfile);
Kiet Lam64c1b492013-07-12 13:56:44 +05304884 vos_mem_free(pCommand->u.scanCmd.pToRoamProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07004885 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304886 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004887}
4888
4889
4890tANI_BOOLEAN csrGetRemainingChannelsFor11dScan( tpAniSirGlobal pMac, tANI_U8 *pChannels, tANI_U8 *pcChannels )
4891{
4892 tANI_U32 index11dChannels, index;
4893 tANI_U32 indexCurrentChannels;
4894 tANI_BOOLEAN fChannelAlreadyScanned;
4895 tANI_U32 len = sizeof(pMac->roam.validChannelList);
4896
4897 *pcChannels = 0;
4898 if ( CSR_IS_11D_INFO_FOUND(pMac) && csrRoamIsChannelValid(pMac, pMac->scan.channelOf11dInfo) )
4899 {
4900 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
4901 {
4902 //Find the channel index where we found the 11d info
4903 for(index = 0; index < len; index++)
4904 {
4905 if(pMac->scan.channelOf11dInfo == pMac->roam.validChannelList[index])
4906 break;
4907 }
4908 //check whether we found the channel index
4909 if(index < len)
4910 {
4911 // Now, look through the 11d channel list and create a list of all channels in the 11d list that are
4912 // NOT in the current channel list. This gives us a list of the new channels that have not been
4913 // scanned. We'll scan this new list so we have a complete set of scan results on all of the domain channels
4914 // initially.
4915 for ( index11dChannels = 0; index11dChannels < pMac->scan.channels11d.numChannels; index11dChannels++ )
4916 {
4917 fChannelAlreadyScanned = eANI_BOOLEAN_FALSE;
4918
4919 for( indexCurrentChannels = 0; indexCurrentChannels < index; indexCurrentChannels++ )
4920 {
4921 if ( pMac->roam.validChannelList[ indexCurrentChannels ] == pMac->scan.channels11d.channelList[ index11dChannels ] )
4922 {
4923 fChannelAlreadyScanned = eANI_BOOLEAN_TRUE;
4924 break;
4925 }
4926 }
4927
4928 if ( !fChannelAlreadyScanned )
4929 {
4930 pChannels[ *pcChannels ] = pMac->scan.channels11d.channelList[ index11dChannels ];
4931 ( *pcChannels )++;
4932 }
4933 }
4934 }
4935 }//GetCFG
4936 }
4937 return( *pcChannels );
4938}
4939
4940
4941eCsrScanCompleteNextCommand csrScanGetNextCommandState( tpAniSirGlobal pMac, tSmeCmd *pCommand, tANI_BOOLEAN fSuccess )
4942{
4943 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
4944
4945 switch( pCommand->u.scanCmd.reason )
4946 {
4947 case eCsrScan11d1:
4948 NextCommand = (fSuccess) ? eCsrNext11dScan1Success : eCsrNext11dScan1Failure;
4949 break;
4950 case eCsrScan11d2:
4951 NextCommand = (fSuccess) ? eCsrNext11dScan2Success : eCsrNext11dScan2Failure;
4952 break;
4953 case eCsrScan11dDone:
4954 NextCommand = eCsrNext11dScanComplete;
4955 break;
4956 case eCsrScanLostLink1:
4957 NextCommand = (fSuccess) ? eCsrNextLostLinkScan1Success : eCsrNextLostLinkScan1Failed;
4958 break;
4959 case eCsrScanLostLink2:
4960 NextCommand = (fSuccess) ? eCsrNextLostLinkScan2Success : eCsrNextLostLinkScan2Failed;
4961 break;
4962 case eCsrScanLostLink3:
4963 NextCommand = (fSuccess) ? eCsrNextLostLinkScan3Success : eCsrNextLostLinkScan3Failed;
4964 break;
4965 case eCsrScanForSsid:
4966 NextCommand = (fSuccess) ? eCsrNexteScanForSsidSuccess : eCsrNexteScanForSsidFailure;
4967 break;
4968 case eCsrScanForCapsChange:
4969 NextCommand = eCsrNextCapChangeScanComplete; //don't care success or not
4970 break;
4971 case eCsrScanIdleScan:
4972 NextCommand = eCsrNextIdleScanComplete;
4973 break;
4974 default:
4975 NextCommand = eCsrNextScanNothing;
4976 break;
4977 }
4978 return( NextCommand );
4979}
4980
4981
4982//Return whether the pCommand is finished.
4983tANI_BOOLEAN csrHandleScan11d1Failure(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4984{
4985 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
4986
4987 //Apply back the default setting and passively scan one more time.
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004988 csrResetCountryInformation(pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07004989 pCommand->u.scanCmd.reason = eCsrScan11d2;
4990 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
4991 {
4992 fRet = eANI_BOOLEAN_FALSE;
4993 }
4994
4995 return (fRet);
4996}
4997
4998
4999tANI_BOOLEAN csrHandleScan11dSuccess(tpAniSirGlobal pMac, tSmeCmd *pCommand)
5000{
5001 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
5002 tANI_U8 *pChannels;
5003 tANI_U8 cChannels;
5004
Kiet Lam64c1b492013-07-12 13:56:44 +05305005 pChannels = vos_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
5006 if ( NULL != pChannels )
Jeff Johnson295189b2012-06-20 16:38:30 -07005007 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305008 vos_mem_set(pChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005009 if ( csrGetRemainingChannelsFor11dScan( pMac, pChannels, &cChannels ) )
5010 {
5011 pCommand->u.scanCmd.reason = eCsrScan11dDone;
5012 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
5013 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305014 vos_mem_free(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -07005015 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07005016 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305017 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(cChannels);
5018 if ( NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07005019 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305020 vos_mem_copy(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
5021 pChannels, cChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07005022 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = cChannels;
5023 pCommand->u.scanCmd.u.scanRequest.requestType = eCSR_SCAN_REQUEST_FULL_SCAN;
5024 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
5025 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
5026 {
5027 //Reuse the same command buffer
5028 fRet = eANI_BOOLEAN_FALSE;
5029 }
5030 }
5031 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305032 vos_mem_free(pChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07005033 }
5034
5035 return (fRet);
5036}
5037
5038//Return whether the command should be removed
5039tANI_BOOLEAN csrScanComplete( tpAniSirGlobal pMac, tSirSmeScanRsp *pScanRsp )
5040{
5041 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
5042 tListElem *pEntry;
5043 tSmeCmd *pCommand;
5044 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
5045 tANI_BOOLEAN fSuccess;
5046
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305047 if (pMac->fScanOffload)
5048 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
5049 else
5050 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07005051
5052 if ( pEntry )
5053 {
5054 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
5055
5056 // If the head of the queue is Active and it is a SCAN command, remove
5057 // and put this on the Free queue.
5058 if ( eSmeCommandScan == pCommand->command )
5059 {
5060 tANI_U32 sessionId = pCommand->sessionId;
5061
5062 if(eSIR_SME_SUCCESS != pScanRsp->statusCode)
5063 {
5064 fSuccess = eANI_BOOLEAN_FALSE;
5065 }
5066 else
5067 {
5068 //pMac->scan.tempScanResults is not empty meaning the scan found something
5069 //This check only valid here because csrSaveScanresults is not yet called
5070 fSuccess = (!csrLLIsListEmpty(&pMac->scan.tempScanResults, LL_ACCESS_LOCK));
5071 }
Ratheesh S Pece1f832015-07-25 15:50:25 +05305072 if (pCommand->u.scanCmd.abortScanIndication &
5073 eCSR_SCAN_ABORT_DUE_TO_BAND_CHANGE)
Srinivas, Dasari187ca4e2014-02-07 12:40:09 +05305074 {
5075 /*
5076 * Scan aborted due to band change
5077 * The scan results need to be flushed
5078 */
5079 if (pCommand->u.scanCmd.callback
5080 != pMac->scan.callback11dScanDone)
5081 {
5082 smsLog(pMac, LOG1, FL("Filtering the scan results as the "
5083 "results may belong to wrong band"));
5084 csrScanFilterResults(pMac);
5085 }
5086 else
5087 {
5088 smsLog(pMac, LOG1, FL("11d_scan_done will flush the scan"
5089 " results"));
5090 }
Srinivas, Dasari187ca4e2014-02-07 12:40:09 +05305091 }
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005092 csrSaveScanResults(pMac, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07005093
Agrawal Ashishdf752672015-12-09 17:51:53 +05305094 /* filter scan result based on valid channel list number */
5095 if (pMac->scan.fcc_constraint)
5096 {
5097 smsLog(pMac, LOG1, FL("Clear BSS from invalid channels"));
5098 csrScanFilterResults(pMac);
5099 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005100#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5101 {
5102 vos_log_scan_pkt_type *pScanLog = NULL;
5103 tScanResultHandle hScanResult;
5104 tCsrScanResultInfo *pScanResult;
5105 tDot11fBeaconIEs *pIes;
5106 int n = 0, c = 0;
5107
5108 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
5109 if(pScanLog)
5110 {
5111 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
5112 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
5113 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
5114 {
5115 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_RSP;
5116 }
5117 else
5118 {
5119 if( eSIR_PASSIVE_SCAN != pMac->scan.curScanType )
5120 {
5121 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_RSP;
5122 }
5123 else
5124 {
5125 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_RSP;
5126 }
5127 }
5128 if(eSIR_SME_SUCCESS == pScanRsp->statusCode)
5129 {
5130 if(HAL_STATUS_SUCCESS(csrScanGetResult(pMac, NULL, &hScanResult)))
5131 {
5132 while(((pScanResult = csrScanResultGetNext(pMac, hScanResult)) != NULL))
5133 {
5134 if( n < VOS_LOG_MAX_NUM_BSSID )
5135 {
5136 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pScanResult->BssDescriptor, &pIes)))
5137 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005138 smsLog(pMac, LOGE, FL(" fail to parse IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07005139 break;
5140 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305141 vos_mem_copy(pScanLog->bssid[n],
5142 pScanResult->BssDescriptor.bssId, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07005143 if(pIes && pIes->SSID.present && VOS_LOG_MAX_SSID_SIZE >= pIes->SSID.num_ssid)
5144 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305145 vos_mem_copy(pScanLog->ssid[n],
5146 pIes->SSID.ssid, pIes->SSID.num_ssid);
Jeff Johnson295189b2012-06-20 16:38:30 -07005147 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305148 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07005149 n++;
5150 }
5151 c++;
5152 }
5153 pScanLog->numSsid = (v_U8_t)n;
5154 pScanLog->totalSsid = (v_U8_t)c;
5155 csrScanResultPurge(pMac, hScanResult);
5156 }
5157 }
5158 else
5159 {
5160 pScanLog->status = WLAN_SCAN_STATUS_FAILURE;
5161 }
5162 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
5163 }
5164 }
5165#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5166
5167 NextCommand = csrScanGetNextCommandState(pMac, pCommand, fSuccess);
5168 //We reuse the command here instead reissue a new command
5169 switch(NextCommand)
5170 {
5171 case eCsrNext11dScan1Success:
5172 case eCsrNext11dScan2Success:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005173 smsLog( pMac, LOG2, FL("11dScan1/3 produced results. Reissue Active scan..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07005174 // if we found country information, no need to continue scanning further, bail out
5175 fRemoveCommand = eANI_BOOLEAN_TRUE;
5176 NextCommand = eCsrNext11dScanComplete;
5177 break;
5178 case eCsrNext11dScan1Failure:
5179 //We are not done yet. 11d scan fail once. We will try to reset anything and do it over again
5180 //The only meaningful thing for this retry is that we cannot find 11d information after a reset so
5181 //we clear the "old" 11d info and give it once more chance
5182 fRemoveCommand = csrHandleScan11d1Failure(pMac, pCommand);
5183 if(fRemoveCommand)
5184 {
5185 NextCommand = eCsrNext11dScanComplete;
5186 }
5187 break;
5188 case eCsrNextLostLinkScan1Success:
5189 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink1)))
5190 {
5191 csrScanHandleFailedLostlink1(pMac, sessionId);
5192 }
5193 break;
5194 case eCsrNextLostLinkScan2Success:
5195 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink2)))
5196 {
5197 csrScanHandleFailedLostlink2(pMac, sessionId);
5198 }
5199 break;
5200 case eCsrNextLostLinkScan3Success:
5201 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink3)))
5202 {
5203 csrScanHandleFailedLostlink3(pMac, sessionId);
5204 }
5205 break;
5206 case eCsrNextLostLinkScan1Failed:
5207 csrScanHandleFailedLostlink1(pMac, sessionId);
5208 break;
5209 case eCsrNextLostLinkScan2Failed:
5210 csrScanHandleFailedLostlink2(pMac, sessionId);
5211 break;
5212 case eCsrNextLostLinkScan3Failed:
5213 csrScanHandleFailedLostlink3(pMac, sessionId);
5214 break;
5215 case eCsrNexteScanForSsidSuccess:
5216 csrScanHandleSearchForSSID(pMac, pCommand);
5217 break;
5218 case eCsrNexteScanForSsidFailure:
5219 csrScanHandleSearchForSSIDFailure(pMac, pCommand);
5220 break;
5221 case eCsrNextIdleScanComplete:
5222 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
5223 break;
5224 case eCsrNextCapChangeScanComplete:
5225 csrScanHandleCapChangeScanComplete(pMac, sessionId);
5226 break;
5227 default:
5228
5229 break;
5230 }
5231 }
5232 else
5233 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005234 smsLog( pMac, LOGW, FL("Scan Completion called but SCAN command is not ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07005235 fRemoveCommand = eANI_BOOLEAN_FALSE;
5236 }
5237 }
5238 else
5239 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005240 smsLog( pMac, LOGW, FL("Scan Completion called but NO commands are ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07005241 fRemoveCommand = eANI_BOOLEAN_FALSE;
5242 }
5243
5244 return( fRemoveCommand );
5245}
5246
5247
5248
5249static void csrScanRemoveDupBssDescriptionFromInterimList( tpAniSirGlobal pMac,
5250 tSirBssDescription *pSirBssDescr,
5251 tDot11fBeaconIEs *pIes)
5252{
5253 tListElem *pEntry;
5254 tCsrScanResult *pCsrBssDescription;
5255
5256 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
5257 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
5258 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
5259 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
5260 while( pEntry )
5261 {
5262 pCsrBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
5263
5264 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
5265 // matches
5266
5267 if ( csrIsDuplicateBssDescription( pMac, &pCsrBssDescription->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07005268 pSirBssDescr, pIes, FALSE ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07005269 {
5270 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
5271 ((tANI_S32)pCsrBssDescription->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
5272
5273 // Remove the 'old' entry from the list....
5274 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK ) )
5275 {
5276 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pCsrBssDescription->Result.BssDescriptor);
5277 // we need to free the memory associated with this node
5278 csrFreeScanResultEntry( pMac, pCsrBssDescription );
5279 }
5280
5281 // If we found a match, we can stop looking through the list.
5282 break;
5283 }
5284
5285 pEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK );
5286 }
5287}
5288
5289
5290
5291//Caller allocated memory pfNewBssForConn to return whether new candidate for
5292//current connection is found. Cannot be NULL
5293tCsrScanResult *csrScanSaveBssDescriptionToInterimList( tpAniSirGlobal pMac,
5294 tSirBssDescription *pBSSDescription,
5295 tDot11fBeaconIEs *pIes)
5296{
5297 tCsrScanResult *pCsrBssDescription = NULL;
5298 tANI_U32 cbBSSDesc;
5299 tANI_U32 cbAllocated;
Jeff Johnson295189b2012-06-20 16:38:30 -07005300
5301 // figure out how big the BSS description is (the BSSDesc->length does NOT
5302 // include the size of the length field itself).
5303 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
5304
5305 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
5306
Kiet Lam64c1b492013-07-12 13:56:44 +05305307 pCsrBssDescription = vos_mem_malloc(cbAllocated);
5308 if ( NULL != pCsrBssDescription )
Jeff Johnson295189b2012-06-20 16:38:30 -07005309 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305310 vos_mem_set(pCsrBssDescription, cbAllocated, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005311 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Kiet Lam64c1b492013-07-12 13:56:44 +05305312 vos_mem_copy(&pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc );
Jeff Johnson295189b2012-06-20 16:38:30 -07005313 //Save SSID separately for later use
5314 if( pIes->SSID.present && !csrIsNULLSSID(pIes->SSID.ssid, pIes->SSID.num_ssid) )
5315 {
5316 //SSID not hidden
Madan Mohan Koyyalamudi4e31b132012-11-02 13:13:52 -07005317 tANI_U32 len = pIes->SSID.num_ssid;
Jeff Johnson295189b2012-06-20 16:38:30 -07005318 if (len > SIR_MAC_MAX_SSID_LENGTH)
5319 {
5320 // truncate to fit in our struct
5321 len = SIR_MAC_MAX_SSID_LENGTH;
5322 }
5323 pCsrBssDescription->Result.ssId.length = len;
5324 pCsrBssDescription->Result.timer = vos_timer_get_system_time();
Kiet Lam64c1b492013-07-12 13:56:44 +05305325 vos_mem_copy(pCsrBssDescription->Result.ssId.ssId, pIes->SSID.ssid, len);
Jeff Johnson295189b2012-06-20 16:38:30 -07005326 }
5327 csrLLInsertTail( &pMac->scan.tempScanResults, &pCsrBssDescription->Link, LL_ACCESS_LOCK );
5328 }
5329
5330 return( pCsrBssDescription );
5331}
5332
5333
5334
5335
5336tANI_BOOLEAN csrIsDuplicateBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc1,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07005337 tSirBssDescription *pSirBssDesc2, tDot11fBeaconIEs *pIes2, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07005338{
5339 tANI_BOOLEAN fMatch = FALSE;
5340 tSirMacCapabilityInfo *pCap1, *pCap2;
5341 tDot11fBeaconIEs *pIes1 = NULL;
Jeff Johnsone7245742012-09-05 17:12:55 -07005342 tDot11fBeaconIEs *pIesTemp = pIes2;
Jeff Johnson295189b2012-06-20 16:38:30 -07005343
5344 pCap1 = (tSirMacCapabilityInfo *)&pSirBssDesc1->capabilityInfo;
5345 pCap2 = (tSirMacCapabilityInfo *)&pSirBssDesc2->capabilityInfo;
5346 if(pCap1->ess == pCap2->ess)
5347 {
5348 if (pCap1->ess &&
Jeff Johnsone7245742012-09-05 17:12:55 -07005349 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId)&&
Abhishek Singhe3fa11f2014-05-13 11:11:10 +05305350 (fForced || (vos_chan_to_band(pSirBssDesc1->channelId) == vos_chan_to_band((pSirBssDesc2->channelId)))))
Jeff Johnson295189b2012-06-20 16:38:30 -07005351 {
5352 fMatch = TRUE;
Jeff Johnsone7245742012-09-05 17:12:55 -07005353 // Check for SSID match, if exists
5354 do
5355 {
5356 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
5357 {
5358 break;
5359 }
5360 if( NULL == pIesTemp )
5361 {
5362 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
5363 {
5364 break;
5365 }
5366 }
5367 if(pIes1->SSID.present && pIesTemp->SSID.present)
5368 {
5369 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
5370 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
5371 }
5372 }while(0);
5373
Jeff Johnson295189b2012-06-20 16:38:30 -07005374 }
5375 else if (pCap1->ibss && (pSirBssDesc1->channelId == pSirBssDesc2->channelId))
5376 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005377
5378 do
5379 {
5380 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
5381 {
5382 break;
5383 }
5384 if( NULL == pIesTemp )
5385 {
5386 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
5387 {
5388 break;
5389 }
5390 }
5391 //Same channel cannot have same SSID for different IBSS
5392 if(pIes1->SSID.present && pIesTemp->SSID.present)
5393 {
5394 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
5395 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
5396 }
5397 }while(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005398 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005399 /* In case of P2P devices, ess and ibss will be set to zero */
5400 else if (!pCap1->ess &&
5401 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId))
5402 {
5403 fMatch = TRUE;
5404 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005405 }
5406
5407 if(pIes1)
5408 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305409 vos_mem_free(pIes1);
Jeff Johnson295189b2012-06-20 16:38:30 -07005410 }
Jeff Johnsone7245742012-09-05 17:12:55 -07005411
5412 if( (NULL == pIes2) && pIesTemp )
5413 {
5414 //locally allocated
Kiet Lam64c1b492013-07-12 13:56:44 +05305415 vos_mem_free(pIesTemp);
Jeff Johnsone7245742012-09-05 17:12:55 -07005416 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005417
5418 return( fMatch );
5419}
5420
5421
5422tANI_BOOLEAN csrIsNetworkTypeEqual( tSirBssDescription *pSirBssDesc1, tSirBssDescription *pSirBssDesc2 )
5423{
5424 return( pSirBssDesc1->nwType == pSirBssDesc2->nwType );
5425}
5426
5427
5428//to check whether the BSS matches the dot11Mode
5429static tANI_BOOLEAN csrScanIsBssAllowed(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
5430 tDot11fBeaconIEs *pIes)
5431{
5432 tANI_BOOLEAN fAllowed = eANI_BOOLEAN_FALSE;
5433 eCsrPhyMode phyMode;
5434
5435 if(HAL_STATUS_SUCCESS(csrGetPhyModeFromBss(pMac, pBssDesc, &phyMode, pIes)))
5436 {
5437 switch(pMac->roam.configParam.phyMode)
5438 {
5439 case eCSR_DOT11_MODE_11b:
5440 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
5441 break;
5442 case eCSR_DOT11_MODE_11g:
5443 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
5444 break;
5445 case eCSR_DOT11_MODE_11g_ONLY:
5446 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11g == phyMode);
5447 break;
5448 case eCSR_DOT11_MODE_11a:
5449 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11b != phyMode) && (eCSR_DOT11_MODE_11g != phyMode));
5450 break;
5451 case eCSR_DOT11_MODE_11n_ONLY:
5452 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11n == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
5453 break;
Jeff Johnsone7245742012-09-05 17:12:55 -07005454
5455#ifdef WLAN_FEATURE_11AC
5456 case eCSR_DOT11_MODE_11ac_ONLY:
5457 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11ac == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
5458 break;
5459#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005460 case eCSR_DOT11_MODE_11b_ONLY:
5461 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11b == phyMode);
5462 break;
5463 case eCSR_DOT11_MODE_11a_ONLY:
5464 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a == phyMode);
5465 break;
5466 case eCSR_DOT11_MODE_11n:
Jeff Johnsone7245742012-09-05 17:12:55 -07005467#ifdef WLAN_FEATURE_11AC
5468 case eCSR_DOT11_MODE_11ac:
5469#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005470 case eCSR_DOT11_MODE_TAURUS:
5471 default:
5472 fAllowed = eANI_BOOLEAN_TRUE;
5473 break;
5474 }
5475 }
5476
5477 return (fAllowed);
5478}
5479
5480
5481
5482//Return pIes to caller for future use when returning TRUE.
5483static tANI_BOOLEAN csrScanValidateScanResult( tpAniSirGlobal pMac, tANI_U8 *pChannels,
5484 tANI_U8 numChn, tSirBssDescription *pBssDesc,
5485 tDot11fBeaconIEs **ppIes )
5486{
5487 tANI_BOOLEAN fValidChannel = FALSE;
5488 tDot11fBeaconIEs *pIes = NULL;
5489 tANI_U8 index;
5490
5491 for( index = 0; index < numChn; index++ )
5492 {
5493 // This check relies on the fact that a single BSS description is returned in each
5494 // ScanRsp call, which is the way LIM implemented the scan req/rsp funtions. We changed
5495 // to this model when we ran with a large number of APs. If this were to change, then
5496 // this check would have to mess with removing the bssDescription from somewhere in an
5497 // arbitrary index in the bssDescription array.
5498 if ( pChannels[ index ] == pBssDesc->channelId )
5499 {
5500 fValidChannel = TRUE;
5501 break;
5502 }
5503 }
5504 *ppIes = NULL;
5505 if(fValidChannel)
5506 {
5507 if( HAL_STATUS_SUCCESS( csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIes) ) )
5508 {
5509 fValidChannel = csrScanIsBssAllowed(pMac, pBssDesc, pIes);
5510 if( fValidChannel )
5511 {
5512 *ppIes = pIes;
5513 }
5514 else
5515 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305516 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07005517 }
5518 }
5519 else
5520 {
5521 fValidChannel = FALSE;
5522 }
5523 }
5524
5525 return( fValidChannel );
5526}
5527
5528
5529//Return whether last scan result is received
5530static tANI_BOOLEAN csrScanProcessScanResults( tpAniSirGlobal pMac, tSmeCmd *pCommand,
5531 tSirSmeScanRsp *pScanRsp, tANI_BOOLEAN *pfRemoveCommand )
5532{
5533 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE, fRemoveCommand = eANI_BOOLEAN_FALSE;
5534 tDot11fBeaconIEs *pIes = NULL;
5535 tANI_U32 cbParsed;
5536 tSirBssDescription *pSirBssDescription;
5537 tANI_U32 cbBssDesc;
Agrawal Ashish4cc15bb2016-02-04 17:56:16 +05305538 eHalStatus status;
Jeff Johnson295189b2012-06-20 16:38:30 -07005539 tANI_U32 cbScanResult = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription )
5540 + sizeof(tSirBssDescription); //We need at least one CB
5541
5542 // don't consider the scan rsp to be valid if the status code is Scan Failure. Scan Failure
5543 // is returned when the scan could not find anything. so if we get scan failure return that
5544 // the scan response is invalid. Also check the lenght in the scan result for valid scan
5545 // BssDescriptions....
5546 do
5547 {
5548 if ( ( cbScanResult <= pScanRsp->length ) &&
5549 (( eSIR_SME_SUCCESS == pScanRsp->statusCode ) ||
5550 ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW == pScanRsp->statusCode ) ) )
5551 {
5552 tANI_U8 *pChannelList = NULL;
5553 tANI_U8 cChannels = 0;
5554
5555 //Different scan type can reach this point, we need to distinguish it
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005556#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5557 if( eCsrScanGetLfrResult == pCommand->u.scanCmd.reason )
5558 {
5559 pChannelList = NULL;
5560 cChannels = 0;
5561 }
5562 else
5563#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005564 if( eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason )
5565 {
5566 //eCsrScanSetBGScanParam uses different structure
5567 tCsrBGScanRequest *pBgScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
5568
5569 cChannels = pBgScanReq->ChannelInfo.numOfChannels;
5570 pChannelList = pBgScanReq->ChannelInfo.ChannelList;
5571 }
5572 else
5573 {
5574 //the rest use generic scan request
5575 cChannels = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
5576 pChannelList = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
5577 }
5578
5579 // if the scan result is not on one of the channels in the Valid channel list, then it
5580 // must have come from an AP on an overlapping channel (in the 2.4GHz band). In this case,
5581 // let's drop the scan result.
5582 //
5583 // The other situation is where the scan request is for a scan on a particular channel set
5584 // and the scan result is from a
5585
5586 // if the NumChannels is 0, then we are supposed to be scanning all channels. Use the full channel
5587 // list as the 'valid' channel list. Otherwise, use the specific channel list in the scan parms
5588 // as the valid channels.
5589 if ( 0 == cChannels )
5590 {
5591 tANI_U32 len = sizeof(pMac->roam.validChannelList);
5592
5593 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
5594 {
5595 pChannelList = pMac->roam.validChannelList;
5596 cChannels = (tANI_U8)len;
5597 }
5598 else
5599 {
5600 //Cannot continue
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005601 smsLog( pMac, LOGE, "CSR: Processing internal SCAN results...csrGetCfgValidChannels failed" );
Jeff Johnson295189b2012-06-20 16:38:30 -07005602 break;
5603 }
5604 }
5605
5606 smsLog( pMac, LOG2, "CSR: Processing internal SCAN results..." );
5607 cbParsed = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription );
5608 pSirBssDescription = pScanRsp->bssDescription;
5609 while( cbParsed < pScanRsp->length )
5610 {
5611 if ( csrScanValidateScanResult( pMac, pChannelList, cChannels, pSirBssDescription, &pIes ) )
5612 {
5613 csrScanRemoveDupBssDescriptionFromInterimList(pMac, pSirBssDescription, pIes);
5614 csrScanSaveBssDescriptionToInterimList( pMac, pSirBssDescription, pIes );
5615 if( eSIR_PASSIVE_SCAN == pMac->scan.curScanType )
5616 {
5617 if( csrIs11dSupported( pMac) )
5618 {
5619 //Check whether the BSS is acceptable base on 11d info and our configs.
5620 if( csrMatchCountryCode( pMac, NULL, pIes ) )
5621 {
5622 //Double check whether the channel is acceptable by us.
5623 if( csrIsSupportedChannel( pMac, pSirBssDescription->channelId ) )
5624 {
5625 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
5626 }
5627 }
5628 }
5629 else
5630 {
5631 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
5632 }
5633 }
5634 //Free the resource
Kiet Lam64c1b492013-07-12 13:56:44 +05305635 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07005636 }
5637 // skip over the BSS description to the next one...
5638 cbBssDesc = pSirBssDescription->length + sizeof( pSirBssDescription->length );
5639
5640 cbParsed += cbBssDesc;
5641 pSirBssDescription = (tSirBssDescription *)((tANI_U8 *)pSirBssDescription + cbBssDesc );
5642
5643 } //while
5644 }
5645 else
5646 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005647 smsLog( pMac, LOGW, " Scanrsp fail (0x%08X), length = %d (expected %d)",
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08005648 pScanRsp->statusCode, pScanRsp->length, cbScanResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07005649 //HO bg scan/probe failed no need to try autonomously
5650 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
5651 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005652#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5653 eCsrScanGetLfrResult == pCommand->u.scanCmd.reason ||
5654#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005655 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
5656 {
5657 fRemoveCommand = eANI_BOOLEAN_TRUE;
5658 }
5659 }
5660 }while(0);
5661 if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
5662 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005663 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 -07005664 fRemoveCommand = csrScanComplete( pMac, pScanRsp );
5665 fRet = eANI_BOOLEAN_TRUE;
5666 }//if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
5667 if(pfRemoveCommand)
5668 {
5669 *pfRemoveCommand = fRemoveCommand;
5670 }
5671
Agrawal Ashish4cc15bb2016-02-04 17:56:16 +05305672 /*
5673 * Currently SET_FCC_CHANNEL issues updated channel list to fw.
5674 * At the time of driver load, if scan is issued followed with
5675 * SET_FCC_CHANNEL, driver will send update channel list to fw.
5676 * Fw will stop ongoing scan because of that GUI will have very less
5677 * scan list.
5678 * Update channel list should be sent to fw once scan is done
5679 */
5680 if (pMac->scan.defer_update_channel_list) {
5681 status = csrUpdateChannelList(pMac);
5682 if (eHAL_STATUS_SUCCESS != status)
5683 smsLog(pMac, LOGE,
5684 FL( "failed to update the supported channel list"));
5685 pMac->scan.defer_update_channel_list = false;
5686 }
5687
Jeff Johnson295189b2012-06-20 16:38:30 -07005688#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305689 if (pMac->fScanOffload)
5690 return fRet;
5691
Jeff Johnson295189b2012-06-20 16:38:30 -07005692 if (!csrLLIsListEmpty( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK ))
5693 {
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005694 /* Pending scan commands in the list because the previous scan command
5695 * was split into a scan command on one channel + a scan command for all
5696 * remaining channels.
5697 *
5698 * Start timer to trigger processing of the next scan command.
Srikant Kuppa866893f2012-12-27 17:28:14 -08005699 * NOTE for LFR:
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305700 * Do not split scans if no concurrent infra connections are
Srikant Kuppa866893f2012-12-27 17:28:14 -08005701 * active and if the scan is a BG scan triggered by LFR (OR)
5702 * any scan if LFR is in the middle of a BG scan. Splitting
5703 * the scan is delaying the time it takes for LFR to find
5704 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005705 */
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305706 if ( (csrIsStaSessionConnected(pMac) &&
Srikant Kuppa866893f2012-12-27 17:28:14 -08005707#ifdef FEATURE_WLAN_LFR
5708 (csrIsConcurrentInfraConnected(pMac) ||
5709 ((pCommand->u.scanCmd.reason != eCsrScanBgScan) &&
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305710 (pMac->roam.neighborRoamInfo.neighborRoamState !=
Srikant Kuppa866893f2012-12-27 17:28:14 -08005711 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
5712#endif
5713 (pCommand->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305714 (csrIsP2pSessionConnected(pMac)) )
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005715 {
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005716 /* if active connected sessions present then continue to split scan
5717 * with specified interval between consecutive scans */
5718 csrSetDefaultScanTiming(pMac, pCommand->u.scanCmd.u.scanRequest.scanType, &(pCommand->u.scanCmd.u.scanRequest));
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05305719 vos_timer_start(&pMac->scan.hTimerStaApConcTimer,
5720 pCommand->u.scanCmd.u.scanRequest.restTime);
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005721 } else {
5722 /* if no connected sessions present then initiate next scan command immediately */
5723 /* minimum timer granularity is 10ms */
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05305724 vos_timer_start(&pMac->scan.hTimerStaApConcTimer, 10);
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005725 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005726 }
5727#endif
5728 return (fRet);
5729}
5730
5731
5732tANI_BOOLEAN csrScanIsWildCardScan( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5733{
5734 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
Kiet Lam64c1b492013-07-12 13:56:44 +05305735 tANI_BOOLEAN f = vos_mem_compare(pCommand->u.scanCmd.u.scanRequest.bssid,
5736 bssid, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07005737
5738 //It is not a wild card scan if the bssid is not broadcast and the number of SSID is 1.
5739 return ((tANI_BOOLEAN)( (f || (0xff == pCommand->u.scanCmd.u.scanRequest.bssid[0])) &&
5740 (pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs != 1) ));
5741}
5742
5743
5744eHalStatus csrScanSmeScanResponse( tpAniSirGlobal pMac, void *pMsgBuf )
5745{
5746 eHalStatus status = eHAL_STATUS_SUCCESS;
5747 tListElem *pEntry;
5748 tSmeCmd *pCommand;
5749 eCsrScanStatus scanStatus;
Sunkad, Anand Ningappa3ec8bf72016-02-05 15:13:30 +05305750 tSirSmeScanRsp *pScanRsp;
Jeff Johnson295189b2012-06-20 16:38:30 -07005751 tSmeGetScanChnRsp *pScanChnInfo;
5752 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
5753 eCsrScanReason reason = eCsrScanOther;
5754
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305755 if (pMac->fScanOffload)
5756 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList,
5757 LL_ACCESS_LOCK);
5758 else
5759 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07005760
5761 if ( pEntry )
5762 {
5763 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
5764 if ( eSmeCommandScan == pCommand->command )
5765 {
Deepthi Gowrife5340b2016-04-11 12:15:46 +05305766 /* Purge the scan results based on Aging */
5767 if (pEntry && pMac->scan.scanResultCfgAgingTime)
5768 csrPurgeScanResultByAge(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07005769 reason = pCommand->u.scanCmd.reason;
5770 switch(pCommand->u.scanCmd.reason)
5771 {
5772 case eCsrScanAbortBgScan:
5773 case eCsrScanAbortNormalScan:
5774 case eCsrScanBGScanAbort:
5775 case eCsrScanBGScanEnable:
Sunkad, Anand Ningappa3ec8bf72016-02-05 15:13:30 +05305776 pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
5777 scanStatus = (eSIR_SME_SUCCESS == pScanRsp->statusCode) ?
5778 eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005779 break;
5780 case eCsrScanGetScanChnInfo:
Deepthi Gowrife5340b2016-04-11 12:15:46 +05305781 pScanChnInfo = (tSmeGetScanChnRsp *)pMsgBuf;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005782 /*
5783 * status code not available in tSmeGetScanChnRsp, so
5784 * by default considereing it to be success
5785 */
5786 scanStatus = eSIR_SME_SUCCESS;
Deepthi Gowrife5340b2016-04-11 12:15:46 +05305787 csrScanAgeResults(pMac, pScanChnInfo);
Jeff Johnson295189b2012-06-20 16:38:30 -07005788 break;
5789 case eCsrScanForCapsChange:
Sunkad, Anand Ningappa3ec8bf72016-02-05 15:13:30 +05305790 pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
5791 scanStatus = (eSIR_SME_SUCCESS == pScanRsp->statusCode) ?
5792 eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005793 csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand );
5794 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005795 case eCsrScanP2PFindPeer:
Sunkad, Anand Ningappa3ec8bf72016-02-05 15:13:30 +05305796 pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
5797 scanStatus = ((eSIR_SME_SUCCESS == pScanRsp->statusCode) &&
5798 (pScanRsp->length > 50)) ? eCSR_SCAN_FOUND_PEER : eCSR_SCAN_FAILURE;
5799 csrScanProcessScanResults( pMac, pCommand, pScanRsp, NULL );
5800 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005801 case eCsrScanSetBGScanParam:
5802 default:
Sunkad, Anand Ningappa3ec8bf72016-02-05 15:13:30 +05305803 pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
5804 scanStatus = (eSIR_SME_SUCCESS == pScanRsp->statusCode) ?
5805 eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005806 if(csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand ))
5807 {
5808 //Not to get channel info if the scan is not a wildcard scan because
5809 //it may cause scan results got aged out incorrectly.
Ratheesh S Pece1f832015-07-25 15:50:25 +05305810 if(csrScanIsWildCardScan( pMac, pCommand ) &&
5811 (!pCommand->u.scanCmd.u.scanRequest.p2pSearch)
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005812#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5813 && (pCommand->u.scanCmd.reason != eCsrScanGetLfrResult)
5814#endif
5815 )
Jeff Johnson295189b2012-06-20 16:38:30 -07005816 {
Ratheesh S Pece1f832015-07-25 15:50:25 +05305817 csrScanGetScanChnInfo(pMac, pCommand);
Jeff Johnson295189b2012-06-20 16:38:30 -07005818 }
5819 }
5820 break;
5821 }//switch
5822 if(fRemoveCommand)
5823 {
5824
5825 csrReleaseScanCommand(pMac, pCommand, scanStatus);
5826
Sunkad, Anand Ningappa3ec8bf72016-02-05 15:13:30 +05305827 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005828 smeProcessPendingQueue( pMac );
5829 }
5830 else
5831 {
5832 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
5833 status = eHAL_STATUS_FAILURE;
5834 }
5835 }
5836 else
5837 {
5838 smsLog( pMac, LOGW, "CSR: Scan Completion called but NO commands are ACTIVE ..." );
5839 status = eHAL_STATUS_FAILURE;
5840 }
5841
5842 return (status);
5843}
5844
5845
5846
5847
5848tCsrScanResultInfo *csrScanResultGetFirst(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
5849{
5850 tListElem *pEntry;
5851 tCsrScanResult *pResult;
5852 tCsrScanResultInfo *pRet = NULL;
5853 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5854
5855 if(pResultList)
5856 {
5857 csrLLLock(&pResultList->List);
5858 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5859 if(pEntry)
5860 {
5861 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
5862 pRet = &pResult->Result;
5863 }
5864 pResultList->pCurEntry = pEntry;
5865 csrLLUnlock(&pResultList->List);
5866 }
5867
5868 return pRet;
5869}
5870
5871
5872tCsrScanResultInfo *csrScanResultGetNext(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
5873{
5874 tListElem *pEntry = NULL;
5875 tCsrScanResult *pResult = NULL;
5876 tCsrScanResultInfo *pRet = NULL;
5877 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5878
5879 if(pResultList)
5880 {
5881 csrLLLock(&pResultList->List);
5882 if(NULL == pResultList->pCurEntry)
5883 {
5884 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5885 }
5886 else
5887 {
5888 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
5889 }
5890 if(pEntry)
5891 {
5892 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
5893 pRet = &pResult->Result;
5894 }
5895 pResultList->pCurEntry = pEntry;
5896 csrLLUnlock(&pResultList->List);
5897 }
5898
5899 return pRet;
5900}
5901
5902
5903//This function moves the first BSS that matches the bssid to the head of the result
5904eHalStatus csrMoveBssToHeadFromBSSID(tpAniSirGlobal pMac, tCsrBssid *bssid, tScanResultHandle hScanResult)
5905{
5906 eHalStatus status = eHAL_STATUS_FAILURE;
5907 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5908 tCsrScanResult *pResult = NULL;
5909 tListElem *pEntry = NULL;
5910
5911 if(pResultList && bssid)
5912 {
5913 csrLLLock(&pResultList->List);
5914 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5915 while(pEntry)
5916 {
5917 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
Kiet Lam64c1b492013-07-12 13:56:44 +05305918 if (vos_mem_compare(bssid, pResult->Result.BssDescriptor.bssId, sizeof(tCsrBssid)))
Jeff Johnson295189b2012-06-20 16:38:30 -07005919 {
5920 status = eHAL_STATUS_SUCCESS;
5921 csrLLRemoveEntry(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
5922 csrLLInsertHead(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
5923 break;
5924 }
5925 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
5926 }
5927 csrLLUnlock(&pResultList->List);
5928 }
5929
5930 return (status);
5931}
5932
5933
5934//Remove the BSS if possible.
5935//Return -- TRUE == the BSS is remove. False == Fail to remove it
5936//This function is called when list lock is held. Be caution what functions it can call.
5937tANI_BOOLEAN csrScanAgeOutBss(tpAniSirGlobal pMac, tCsrScanResult *pResult)
5938{
5939 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
5940 tANI_U32 i;
5941 tCsrRoamSession *pSession;
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305942 tANI_BOOLEAN isConnBssfound = eANI_BOOLEAN_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005943
5944 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5945 {
5946 if( CSR_IS_SESSION_VALID( pMac, i ) )
5947 {
5948 pSession = CSR_GET_SESSION( pMac, i );
5949 //Not to remove the BSS we are connected to.
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305950 if(csrIsConnStateConnectedInfra(pMac, i) && (NULL != pSession->pConnectBssDesc) &&
5951 (csrIsDuplicateBssDescription(pMac, &pResult->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07005952 pSession->pConnectBssDesc, NULL, FALSE))
Jeff Johnson295189b2012-06-20 16:38:30 -07005953 )
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305954 {
5955 isConnBssfound = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005956 break;
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305957 }
5958 }
5959 }
5960
5961 if( isConnBssfound )
Jeff Johnson295189b2012-06-20 16:38:30 -07005962 {
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305963 //Reset the counter so that aging out of connected BSS won't hapeen too soon
Jeff Johnson295189b2012-06-20 16:38:30 -07005964 pResult->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Deepthi Gowri4480a3f2016-05-18 19:30:17 +05305965 pResult->Result.BssDescriptor.nReceivedTime =
5966 vos_timer_get_system_time();
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305967
5968 return (fRet);
5969 }
5970 else
5971 {
5972 smsLog(pMac, LOGW, "Aging out BSS "MAC_ADDRESS_STR" Channel %d",
5973 MAC_ADDR_ARRAY(pResult->Result.BssDescriptor.bssId),
5974 pResult->Result.BssDescriptor.channelId);
5975 //No need to hold the spin lock because caller should hold the lock for pMac->scan.scanResultList
5976 if( csrLLRemoveEntry(&pMac->scan.scanResultList, &pResult->Link, LL_ACCESS_NOLOCK) )
5977 {
5978 if (csrIsMacAddressEqual(pMac,
5979 (tCsrBssid *) pResult->Result.BssDescriptor.bssId,
5980 (tCsrBssid *) pMac->scan.currentCountryBssid))
5981 {
5982 smsLog(pMac, LOGW, "Aging out 11d BSS "MAC_ADDRESS_STR,
5983 MAC_ADDR_ARRAY(pResult->Result.BssDescriptor.bssId));
5984 pMac->scan.currentCountryRSSI = -128;
5985 }
5986 csrFreeScanResultEntry(pMac, pResult);
5987 fRet = eANI_BOOLEAN_TRUE;
5988 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005989 }
5990
5991 return (fRet);
5992}
5993
5994
5995eHalStatus csrScanAgeResults(tpAniSirGlobal pMac, tSmeGetScanChnRsp *pScanChnInfo)
5996{
5997 eHalStatus status = eHAL_STATUS_SUCCESS;
5998 tListElem *pEntry, *tmpEntry;
5999 tCsrScanResult *pResult;
6000 tLimScanChn *pChnInfo;
6001 tANI_U8 i;
6002
6003 csrLLLock(&pMac->scan.scanResultList);
6004 for(i = 0; i < pScanChnInfo->numChn; i++)
6005 {
6006 pChnInfo = &pScanChnInfo->scanChn[i];
6007 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
6008 while( pEntry )
6009 {
6010 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
6011 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
6012 if(pResult->Result.BssDescriptor.channelId == pChnInfo->channelId)
6013 {
Jeff Johnson295189b2012-06-20 16:38:30 -07006014 if(pResult->AgingCount <= 0)
6015 {
6016 smsLog(pMac, LOGW, " age out due to ref count");
6017 csrScanAgeOutBss(pMac, pResult);
6018 }
Madan Mohan Koyyalamudib9d3dcc2012-09-28 16:47:50 -07006019 else
6020 {
6021 pResult->AgingCount--;
6022 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006023 }
6024 pEntry = tmpEntry;
6025 }
6026 }
6027 csrLLUnlock(&pMac->scan.scanResultList);
6028
6029 return (status);
6030}
6031
Abhishek Singhc640dbb2015-06-08 10:54:17 +05306032eHalStatus csrIbssAgeBss(tpAniSirGlobal pMac)
6033{
6034 eHalStatus status = eHAL_STATUS_SUCCESS;
6035 tListElem *pEntry, *tmpEntry;
6036 tCsrScanResult *pResult;
6037
6038 csrLLLock(&pMac->scan.scanResultList);
6039 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
6040 while( pEntry )
6041 {
6042 tmpEntry = csrLLNext(&pMac->scan.scanResultList,
6043 pEntry, LL_ACCESS_NOLOCK);
6044 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
6045
6046 smsLog(pMac, LOGW, FL(" age out due Forced IBSS leave"));
6047 csrScanAgeOutBss(pMac, pResult);
6048 pEntry = tmpEntry;
6049 }
6050 csrLLUnlock(&pMac->scan.scanResultList);
6051
6052 return (status);
6053}
Jeff Johnson295189b2012-06-20 16:38:30 -07006054
Abhishek Singh72c2f4e2016-07-22 11:25:43 +05306055/**
6056 * csr_remove_bssid_from_scan_list() - remove the bssid from
6057 * scan list
6058 * @pMac: mac context.
6059 * @bssid: bssid to be removed
6060 *
6061 * This function remove the given bssid from scan list.
6062 *
6063 * Return: void.
6064 */
6065void csr_remove_bssid_from_scan_list(tpAniSirGlobal pMac,
6066 tSirMacAddr bssid)
6067{
6068 tListElem *entry,*free_elem;
6069 tCsrScanResult *bss_desc;
6070 tDblLinkList *list = &pMac->scan.scanResultList;
6071
6072 csrLLLock(list);
6073 entry = csrLLPeekHead(list, LL_ACCESS_NOLOCK);
6074 while (entry != NULL) {
6075 bss_desc = GET_BASE_ADDR( entry, tCsrScanResult, Link);
6076 if (vos_mem_compare(bss_desc->Result.BssDescriptor.bssId,
6077 bssid, sizeof(tSirMacAddr))) {
6078 free_elem = entry;
6079 entry = csrLLNext(list, entry, LL_ACCESS_NOLOCK);
6080 csrLLRemoveEntry(list, free_elem, LL_ACCESS_NOLOCK);
6081 csrFreeScanResultEntry(pMac, bss_desc);
6082 smsLog(pMac, LOGW, FL("Removed BSS entry:%pM"),
6083 bssid);
6084 continue;
6085 }
6086 entry = csrLLNext(list, entry, LL_ACCESS_NOLOCK);
6087 }
6088 csrLLUnlock(list);
6089}
6090
Jeff Johnson295189b2012-06-20 16:38:30 -07006091eHalStatus csrSendMBScanReq( tpAniSirGlobal pMac, tANI_U16 sessionId,
6092 tCsrScanRequest *pScanReq, tScanReqParam *pScanReqParam )
6093{
6094 eHalStatus status = eHAL_STATUS_SUCCESS;
6095 tSirSmeScanReq *pMsg;
6096 tANI_U16 msgLen;
6097 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
6098 tSirScanType scanType = pScanReq->scanType;
6099 tANI_U32 minChnTime; //in units of milliseconds
6100 tANI_U32 maxChnTime; //in units of milliseconds
6101 tANI_U32 i;
6102 tANI_U8 selfMacAddr[WNI_CFG_BSSID_LEN];
6103 tANI_U8 *pSelfMac = NULL;
6104
6105 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
6106 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) +
6107 ( pScanReq->uIEFieldLen ) ;
6108
Kiet Lam64c1b492013-07-12 13:56:44 +05306109 pMsg = vos_mem_malloc(msgLen);
6110 if ( NULL == pMsg )
6111 status = eHAL_STATUS_FAILURE;
6112 else
6113 status = eHAL_STATUS_SUCCESS;
6114 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07006115 {
6116 do
6117 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306118 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006119 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
6120 pMsg->length = pal_cpu_to_be16(msgLen);
6121 //ToDO: Fill in session info when we need to do scan base on session.
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05306122 if ((pMac->fScanOffload) && (sessionId != CSR_SESSION_ID_INVALID))
6123 {
6124 pMsg->sessionId = sessionId;
6125 }
6126 else
6127 {
6128 /* if sessionId == CSR_SESSION_ID_INVALID, then send the scan
6129 request on first available session */
6130 pMsg->sessionId = 0;
6131 }
6132
Jeff Johnson295189b2012-06-20 16:38:30 -07006133 pMsg->transactionId = 0;
6134 pMsg->dot11mode = (tANI_U8) csrTranslateToWNICfgDot11Mode(pMac, csrFindBestPhyMode( pMac, pMac->roam.configParam.phyMode ));
6135 pMsg->bssType = pal_cpu_to_be32(csrTranslateBsstypeToMacType(pScanReq->BSSType));
6136
6137 if ( CSR_IS_SESSION_VALID( pMac, sessionId ) )
6138 {
6139 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[sessionId].selfMacAddr;
6140 }
6141 else
6142 {
6143 // Since we don't have session for the scanning, we find a valid session. In case we fail to
6144 // do so, get the WNI_CFG_STA_ID
6145 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
6146 {
6147 if( CSR_IS_SESSION_VALID( pMac, i ) )
6148 {
6149 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[i].selfMacAddr;
6150 break;
6151 }
6152 }
6153 if( CSR_ROAM_SESSION_MAX == i )
6154 {
6155 tANI_U32 len = WNI_CFG_BSSID_LEN;
6156 pSelfMac = selfMacAddr;
6157 status = ccmCfgGetStr( pMac, WNI_CFG_STA_ID, pSelfMac, &len );
6158 if( !HAL_STATUS_SUCCESS( status ) ||
6159 ( len < WNI_CFG_BSSID_LEN ) )
6160 {
6161 smsLog( pMac, LOGE, FL(" Can not get self MAC address from CFG status = %d"), status );
6162 //Force failed status
6163 status = eHAL_STATUS_FAILURE;
6164 break;
6165 }
6166 }
6167 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306168 vos_mem_copy((tANI_U8 *)pMsg->selfMacAddr, pSelfMac, sizeof(tSirMacAddr));
Jeff Johnson295189b2012-06-20 16:38:30 -07006169
6170 //sirCopyMacAddr
Kiet Lam64c1b492013-07-12 13:56:44 +05306171 vos_mem_copy((tANI_U8 *)pMsg->bssId, (tANI_U8 *)&pScanReq->bssid, sizeof(tSirMacAddr));
6172 if ( vos_mem_compare(pScanReq->bssid, bssid, sizeof(tCsrBssid)))
Jeff Johnson295189b2012-06-20 16:38:30 -07006173 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306174 vos_mem_set(pMsg->bssId, sizeof(tSirMacAddr), 0xff);
Jeff Johnson295189b2012-06-20 16:38:30 -07006175 }
6176 else
6177 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306178 vos_mem_copy(pMsg->bssId, pScanReq->bssid, WNI_CFG_BSSID_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07006179 }
6180 minChnTime = pScanReq->minChnTime;
6181 maxChnTime = pScanReq->maxChnTime;
6182
6183 //Verify the scan type first, if the scan is active scan, we need to make sure we
6184 //are allowed to do so.
6185 /* if 11d is enabled & we don't see any beacon around, scan type falls
6186 back to passive. But in BT AMP STA mode we need to send out a
6187 directed probe*/
6188 if( (eSIR_PASSIVE_SCAN != scanType) && (eCSR_SCAN_P2P_DISCOVERY != pScanReq->requestType)
6189 && (eCSR_BSS_TYPE_WDS_STA != pScanReq->BSSType)
6190 && (eANI_BOOLEAN_FALSE == pMac->scan.fEnableBypass11d))
6191 {
6192 scanType = pMac->scan.curScanType;
6193 if(eSIR_PASSIVE_SCAN == pMac->scan.curScanType)
6194 {
6195 if(minChnTime < pMac->roam.configParam.nPassiveMinChnTime)
6196 {
6197 minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
6198 }
6199 if(maxChnTime < pMac->roam.configParam.nPassiveMaxChnTime)
6200 {
6201 maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
6202 }
6203 }
6204 }
6205 pMsg->scanType = pal_cpu_to_be32(scanType);
6206
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306207 pMsg->numSsid =
6208 (pScanReq->SSIDs.numOfSSIDs < SIR_SCAN_MAX_NUM_SSID) ?
6209 pScanReq->SSIDs.numOfSSIDs : SIR_SCAN_MAX_NUM_SSID;
Jeff Johnson295189b2012-06-20 16:38:30 -07006210 if((pScanReq->SSIDs.numOfSSIDs != 0) && ( eSIR_PASSIVE_SCAN != scanType ))
6211 {
Jeff Johnson40b59aa2013-03-19 14:43:18 -07006212 for (i = 0; i < pMsg->numSsid; i++)
6213 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306214 vos_mem_copy(&pMsg->ssId[i],
6215 &pScanReq->SSIDs.SSIDList[i].SSID, sizeof(tSirMacSSid));
Jeff Johnson40b59aa2013-03-19 14:43:18 -07006216 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006217 }
6218 else
6219 {
6220 //Otherwise we scan all SSID and let the result filter later
Jeff Johnson40b59aa2013-03-19 14:43:18 -07006221 for (i = 0; i < SIR_SCAN_MAX_NUM_SSID; i++)
6222 {
6223 pMsg->ssId[i].length = 0;
6224 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006225 }
6226
Jeff Johnson295189b2012-06-20 16:38:30 -07006227 pMsg->minChannelTime = pal_cpu_to_be32(minChnTime);
6228 pMsg->maxChannelTime = pal_cpu_to_be32(maxChnTime);
Abhishek Singhadd13582016-09-29 17:00:03 +05306229 pMsg->min_chntime_btc_esco =
6230 pMac->roam.configParam.min_chntime_btc_esco;
6231 pMsg->max_chntime_btc_esco =
6232 pMac->roam.configParam.max_chntime_btc_esco;
Jeff Johnson295189b2012-06-20 16:38:30 -07006233 //hidden SSID option
6234 pMsg->hiddenSsid = pScanReqParam->hiddenSsid;
6235 //rest time
6236 //pMsg->restTime = pScanReq->restTime;
6237 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
6238 // All the scan results caching will be done by Roaming
6239 // We do not want LIM to do any caching of scan results,
6240 // so delete the LIM cache on all scan requests
6241 pMsg->returnFreshResults = pScanReqParam->freshScan;
6242 //Always ask for unique result
6243 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
6244 pMsg->channelList.numChannels = (tANI_U8)pScanReq->ChannelInfo.numOfChannels;
6245 if(pScanReq->ChannelInfo.numOfChannels)
6246 {
6247 //Assuming the channelNumber is tANI_U8 (1 byte)
Kiet Lam64c1b492013-07-12 13:56:44 +05306248 vos_mem_copy(pMsg->channelList.channelNumber,
6249 pScanReq->ChannelInfo.ChannelList,
6250 pScanReq->ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07006251 }
6252
6253 pMsg->uIEFieldLen = (tANI_U16) pScanReq->uIEFieldLen;
6254 pMsg->uIEFieldOffset = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
6255 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) ;
6256 if(pScanReq->uIEFieldLen != 0)
6257 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306258 vos_mem_copy((tANI_U8 *)pMsg+pMsg->uIEFieldOffset, pScanReq->pIEField,
6259 pScanReq->uIEFieldLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07006260 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006261 pMsg->p2pSearch = pScanReq->p2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07006262
Madan Mohan Koyyalamudi9b876782012-10-11 16:22:51 -07006263 if (pScanReq->requestType == eCSR_SCAN_HO_BG_SCAN)
6264 {
6265 pMsg->backgroundScanMode = eSIR_ROAMING_SCAN;
6266 }
6267
Jeff Johnson295189b2012-06-20 16:38:30 -07006268 }while(0);
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05306269 smsLog(pMac, LOG1, FL("domainIdCurrent %s (%d) scanType %s (%d)"
6270 "bssType %s (%d), requestType %s(%d)"
6271 "numChannels %d"),
6272 voss_DomainIdtoString(pMac->scan.domainIdCurrent),
6273 pMac->scan.domainIdCurrent,
6274 lim_ScanTypetoString(pMsg->scanType), pMsg->scanType,
6275 lim_BssTypetoString(pMsg->bssType), pMsg->bssType,
6276 sme_requestTypetoString(pScanReq->requestType),
6277 pScanReq->requestType,
6278 pMsg->channelList.numChannels);
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08006279
6280 for(i = 0; i < pMsg->channelList.numChannels; i++)
6281 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006282 smsLog(pMac, LOG3, FL("channelNumber[%d]= %d"), i, pMsg->channelList.channelNumber[i]);
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08006283 }
6284
Jeff Johnson295189b2012-06-20 16:38:30 -07006285 if(HAL_STATUS_SUCCESS(status))
6286 {
6287 status = palSendMBMessage(pMac->hHdd, pMsg);
6288 }
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08006289 else
6290 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006291 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d"), status );
Kiet Lam64c1b492013-07-12 13:56:44 +05306292 vos_mem_free(pMsg);
Jeff Johnson295189b2012-06-20 16:38:30 -07006293 }
6294 }//Success allocated memory
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08006295 else
6296 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006297 smsLog( pMac, LOGE, FL(" memory allocation failure"));
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08006298 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006299
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306300 if(!HAL_STATUS_SUCCESS(status))
6301 {
6302 smsLog( pMac, LOG1, FL("Failed: SId: %d FirstMatch = %d"
6303 " UniqueResult = %d freshScan = %d hiddenSsid = %d"),
6304 sessionId, pScanReqParam->bReturnAfter1stMatch,
6305 pScanReqParam->fUniqueResult, pScanReqParam->freshScan,
6306 pScanReqParam->hiddenSsid );
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05306307 smsLog( pMac, LOG1, FL("scanType = %s (%d) BSSType = %s (%d) "
6308 "numOfSSIDs = %d numOfChannels = %d requestType = %s (%d)"
6309 " p2pSearch = %d\n"),
6310 lim_ScanTypetoString(pScanReq->scanType),
6311 pScanReq->scanType,
6312 lim_BssTypetoString(pScanReq->BSSType),
6313 pScanReq->BSSType,
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306314 pScanReq->SSIDs.numOfSSIDs,
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05306315 pScanReq->ChannelInfo.numOfChannels,
6316 sme_requestTypetoString(pScanReq->requestType),
6317 pScanReq->requestType,
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306318 pScanReq->p2pSearch );
6319
6320 }
6321
Jeff Johnson295189b2012-06-20 16:38:30 -07006322 return( status );
6323}
6324
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006325eHalStatus csrSendMBScanResultReq( tpAniSirGlobal pMac, tANI_U32 sessionId, tScanReqParam *pScanReqParam )
Jeff Johnson295189b2012-06-20 16:38:30 -07006326{
6327 eHalStatus status = eHAL_STATUS_SUCCESS;
6328 tSirSmeScanReq *pMsg;
6329 tANI_U16 msgLen;
6330
6331 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ));
Kiet Lam64c1b492013-07-12 13:56:44 +05306332 pMsg = vos_mem_malloc(msgLen);
6333 if ( NULL == pMsg )
6334 status = eHAL_STATUS_FAILURE;
6335 else
Jeff Johnson295189b2012-06-20 16:38:30 -07006336 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306337 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006338 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
6339 pMsg->length = pal_cpu_to_be16(msgLen);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006340 pMsg->sessionId = sessionId;
6341 pMsg->transactionId = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07006342 pMsg->returnFreshResults = pScanReqParam->freshScan;
6343 //Always ask for unique result
6344 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
6345 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
6346 status = palSendMBMessage(pMac->hHdd, pMsg);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006347 if (!HAL_STATUS_SUCCESS(status))
6348 {
6349 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d\n"), status );
6350 }
6351
Jeff Johnson295189b2012-06-20 16:38:30 -07006352 }
6353
6354 return( status );
6355}
6356
6357
6358
6359eHalStatus csrScanChannels( tpAniSirGlobal pMac, tSmeCmd *pCommand )
6360{
6361 eHalStatus status = eHAL_STATUS_FAILURE;
6362 tScanReqParam scanReq;
6363
6364 do
6365 {
6366 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE | TRUE;
6367 scanReq.fUniqueResult = TRUE;
6368 scanReq.hiddenSsid = SIR_SCAN_NO_HIDDEN_SSID;
6369 if(eCsrScanForSsid == pCommand->u.scanCmd.reason)
6370 {
6371 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_FIRST_MATCH;
6372 }
6373 else
6374 {
6375 // Basically do scan on all channels even for 11D 1st scan case.
6376 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
6377 }
6378 if((eCsrScanBgScan == pCommand->u.scanCmd.reason)||
6379 (eCsrScanProbeBss == pCommand->u.scanCmd.reason))
6380 {
6381 scanReq.hiddenSsid = SIR_SCAN_HIDDEN_SSID_PE_DECISION;
6382 }
6383
6384#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
6385 {
6386 vos_log_scan_pkt_type *pScanLog = NULL;
6387
6388 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
6389 if(pScanLog)
6390 {
6391 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
6392 eCsrScanProbeBss == pCommand->u.scanCmd.reason)
6393 {
6394 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
6395 }
6396 else
6397 {
6398 if( (eSIR_PASSIVE_SCAN != pCommand->u.scanCmd.u.scanRequest.scanType) &&
6399 (eSIR_PASSIVE_SCAN != pMac->scan.curScanType) )
6400 {
6401 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_REQ;
6402 }
6403 else
6404 {
6405 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_REQ;
6406 }
6407 }
6408 pScanLog->minChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.minChnTime;
6409 pScanLog->maxChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.maxChnTime;
6410 pScanLog->numChannel = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
6411 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
6412 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306413 vos_mem_copy(pScanLog->channels,
6414 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
6415 pScanLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07006416 }
6417 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
6418 }
6419 }
6420#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
6421
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05306422 csrClearVotesForCountryInfo(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07006423 status = csrSendMBScanReq(pMac, pCommand->sessionId,
6424 &pCommand->u.scanCmd.u.scanRequest, &scanReq);
6425 }while(0);
6426
6427 return( status );
6428}
6429
6430
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006431eHalStatus csrScanRetrieveResult(tpAniSirGlobal pMac, tSmeCmd *pCommand)
Jeff Johnson295189b2012-06-20 16:38:30 -07006432{
6433 eHalStatus status = eHAL_STATUS_FAILURE;
6434 tScanReqParam scanReq;
6435
6436 do
6437 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006438#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
6439 if (eCsrScanGetLfrResult == pCommand->u.scanCmd.reason)
6440 {
6441 //to get the LFR candidates from PE cache
6442 scanReq.freshScan = SIR_BG_SCAN_RETURN_LFR_CACHED_RESULTS|SIR_BG_SCAN_PURGE_LFR_RESULTS;
6443 scanReq.fUniqueResult = TRUE;
6444 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
6445 }
6446 else
6447#endif
6448 {
6449 //not a fresh scan
6450 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE;
6451 scanReq.fUniqueResult = TRUE;
6452 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
6453 }
6454 status = csrSendMBScanResultReq(pMac, pCommand->sessionId, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07006455 }while(0);
6456
6457 return (status);
6458}
6459
Siddharth Bhald8a95e82015-02-12 20:14:52 +05306460eHalStatus csrProcessMacAddrSpoofCommand( tpAniSirGlobal pMac, tSmeCmd *pCommand )
6461{
6462 tSirSpoofMacAddrReq *pMsg;
6463 tANI_U16 msgLen;
6464 eHalStatus status = eHAL_STATUS_FAILURE;
6465 do {
6466 msgLen = sizeof(tSirSpoofMacAddrReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07006467
Siddharth Bhald8a95e82015-02-12 20:14:52 +05306468 pMsg = vos_mem_malloc(msgLen);
6469 if ( NULL == pMsg )
6470 return eHAL_STATUS_FAILURE;
6471 pMsg->messageType= pal_cpu_to_be16((tANI_U16)eWNI_SME_MAC_SPOOF_ADDR_IND);
6472 pMsg->length= pal_cpu_to_be16(msgLen);
6473 // spoof mac address
6474 vos_mem_copy((tANI_U8 *)pMsg->macAddr,
6475 (tANI_U8 *)pCommand->u.macAddrSpoofCmd.macAddr, sizeof(tSirMacAddr));
6476 status = palSendMBMessage(pMac->hHdd, pMsg);
6477 } while( 0 );
6478 return( status );
6479}
Jeff Johnson295189b2012-06-20 16:38:30 -07006480
6481eHalStatus csrProcessScanCommand( tpAniSirGlobal pMac, tSmeCmd *pCommand )
6482{
6483 eHalStatus status = eHAL_STATUS_SUCCESS;
6484 tCsrChannelInfo newChannelInfo = {0, NULL};
6485 int i, j;
6486 tANI_U8 *pChannel = NULL;
6487 tANI_U32 len = 0;
6488
6489 // Transition to Scanning state...
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306490 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07006491 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306492 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
6493 {
Abhishek Singhf52182c2016-08-24 11:15:23 +05306494 pMac->roam.prev_state[i]=
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306495 csrRoamStateChange( pMac, eCSR_ROAMING_STATE_SCANNING, i);
6496 smsLog( pMac, LOG3, "starting SCAN command from %d state...."
Abhishek Singhf52182c2016-08-24 11:15:23 +05306497 " reason is %d", pMac->roam.prev_state[i],
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306498 pCommand->u.scanCmd.reason );
6499 }
6500 }
6501 else
6502 {
Abhishek Singhf52182c2016-08-24 11:15:23 +05306503 pMac->roam.prev_state[pCommand->sessionId] =
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306504 csrRoamStateChange(pMac, eCSR_ROAMING_STATE_SCANNING,
6505 pCommand->sessionId);
6506 smsLog( pMac, LOG3,
6507 "starting SCAN command from %d state.... reason is %d",
Abhishek Singhf52182c2016-08-24 11:15:23 +05306508 pMac->roam.prev_state[pCommand->sessionId],
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306509 pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07006510 }
6511
6512 switch(pCommand->u.scanCmd.reason)
6513 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006514#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
6515 case eCsrScanGetLfrResult:
6516#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006517 case eCsrScanGetResult:
6518 case eCsrScanForCapsChange: //For cap change, LIM already save BSS description
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006519 status = csrScanRetrieveResult(pMac, pCommand);
Jeff Johnson295189b2012-06-20 16:38:30 -07006520 break;
6521 case eCsrScanSetBGScanParam:
6522 status = csrProcessSetBGScanParam(pMac, pCommand);
6523 break;
6524 case eCsrScanBGScanAbort:
6525 status = csrSetCfgBackgroundScanPeriod(pMac, 0);
6526 break;
6527 case eCsrScanBGScanEnable:
6528 status = csrSetCfgBackgroundScanPeriod(pMac, pMac->roam.configParam.bgScanInterval);
6529 break;
6530 case eCsrScanGetScanChnInfo:
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05306531 status = csrScanGetScanChannelInfo(pMac, pCommand->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07006532 break;
6533 case eCsrScanUserRequest:
6534 if(pMac->roam.configParam.fScanTwice)
6535 {
6536 //We scan 2.4 channel twice
6537 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels &&
6538 (NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList))
6539 {
6540 len = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
6541 //allocate twice the channel
Mukul Sharmaa631e892014-08-28 15:38:51 +05306542 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(len * 2);
Jeff Johnson295189b2012-06-20 16:38:30 -07006543 pChannel = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
6544 }
6545 else
6546 {
6547 //get the valid channel list to scan all.
6548 len = sizeof(pMac->roam.validChannelList);
6549
6550 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
6551 {
6552 //allocate twice the channel
6553 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(len * 2);
6554 pChannel = pMac->roam.validChannelList;
6555 }
6556 }
6557 if(NULL == newChannelInfo.ChannelList)
6558 {
6559 newChannelInfo.numOfChannels = 0;
6560 }
6561 else
6562 {
6563 j = 0;
6564 for(i = 0; i < len; i++)
6565 {
6566 newChannelInfo.ChannelList[j++] = pChannel[i];
6567 if(CSR_MAX_24GHz_CHANNEL_NUMBER >= pChannel[i])
6568 {
6569 newChannelInfo.ChannelList[j++] = pChannel[i];
6570 }
6571 }
6572 if(NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
6573 {
6574 //pChannel points to the channellist from the command, free it.
6575 vos_mem_free(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -07006576 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07006577 }
6578 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = j;
6579 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = newChannelInfo.ChannelList;
6580 }
6581 } //if(pMac->roam.configParam.fScanTwice)
6582
6583 status = csrScanChannels(pMac, pCommand);
6584
6585 break;
6586 default:
6587 status = csrScanChannels(pMac, pCommand);
6588 break;
6589 }
6590
6591 if(!HAL_STATUS_SUCCESS(status))
6592 {
6593 csrReleaseScanCommand(pMac, pCommand, eCSR_SCAN_FAILURE);
6594 }
6595
6596 return (status);
6597}
6598
6599
6600eHalStatus csrScanSetBGScanparams(tpAniSirGlobal pMac, tCsrBGScanRequest *pScanReq)
6601{
6602 eHalStatus status = eHAL_STATUS_SUCCESS;
6603 tSmeCmd *pCommand = NULL;
6604
6605 if(pScanReq)
6606 {
6607 do
6608 {
6609 pCommand = csrGetCommandBuffer(pMac);
6610 if(!pCommand)
6611 {
6612 status = eHAL_STATUS_RESOURCES;
6613 break;
6614 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306615 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006616 pCommand->command = eSmeCommandScan;
6617 pCommand->u.scanCmd.reason = eCsrScanSetBGScanParam;
6618 pCommand->u.scanCmd.callback = NULL;
6619 pCommand->u.scanCmd.pContext = NULL;
Kiet Lam64c1b492013-07-12 13:56:44 +05306620 vos_mem_copy(&pCommand->u.scanCmd.u.bgScanRequest, pScanReq, sizeof(tCsrBGScanRequest));
Jeff Johnson295189b2012-06-20 16:38:30 -07006621 //we have to do the follow
6622 if(pScanReq->ChannelInfo.numOfChannels == 0)
6623 {
6624 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
6625 }
6626 else
6627 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306628 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList
6629 = vos_mem_malloc(pScanReq->ChannelInfo.numOfChannels);
6630 if ( NULL != pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07006631 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306632 vos_mem_copy(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList,
6633 pScanReq->ChannelInfo.ChannelList,
6634 pScanReq->ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07006635 }
6636 else
6637 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006638 smsLog(pMac, LOGE, FL("ran out of memory"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006639 csrReleaseCommandScan(pMac, pCommand);
Kiet Lam64c1b492013-07-12 13:56:44 +05306640 return eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006641 }
6642 }
6643
6644 //scan req for SSID
6645 if(pScanReq->SSID.length)
6646 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306647 vos_mem_copy(pCommand->u.scanCmd.u.bgScanRequest.SSID.ssId,
6648 pScanReq->SSID.ssId, pScanReq->SSID.length);
Jeff Johnson295189b2012-06-20 16:38:30 -07006649 pCommand->u.scanCmd.u.bgScanRequest.SSID.length = pScanReq->SSID.length;
6650
6651 }
6652 pCommand->u.scanCmd.u.bgScanRequest.maxChnTime= pScanReq->maxChnTime;
6653 pCommand->u.scanCmd.u.bgScanRequest.minChnTime = pScanReq->minChnTime;
6654 pCommand->u.scanCmd.u.bgScanRequest.scanInterval = pScanReq->scanInterval;
6655
6656
6657 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
6658 if( !HAL_STATUS_SUCCESS( status ) )
6659 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006660 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006661 csrReleaseCommandScan( pMac, pCommand );
6662 break;
6663 }
6664 }while(0);
6665 }
6666
6667 return (status);
6668}
6669
6670eHalStatus csrScanBGScanAbort( tpAniSirGlobal pMac )
6671{
6672 eHalStatus status = eHAL_STATUS_SUCCESS;
6673 tSmeCmd *pCommand = NULL;
6674
6675 do
6676 {
6677 pCommand = csrGetCommandBuffer(pMac);
6678 if(!pCommand)
6679 {
6680 status = eHAL_STATUS_RESOURCES;
6681 break;
6682 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306683 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006684 pCommand->command = eSmeCommandScan;
6685 pCommand->u.scanCmd.reason = eCsrScanBGScanAbort;
6686 pCommand->u.scanCmd.callback = NULL;
6687 pCommand->u.scanCmd.pContext = NULL;
6688 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
6689 if( !HAL_STATUS_SUCCESS( status ) )
6690 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006691 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006692 csrReleaseCommandScan( pMac, pCommand );
6693 break;
6694 }
6695 }while(0);
6696
6697 return (status);
6698}
6699
6700
6701//This will enable the background scan with the non-zero interval
6702eHalStatus csrScanBGScanEnable(tpAniSirGlobal pMac)
6703{
6704 eHalStatus status = eHAL_STATUS_SUCCESS;
6705 tSmeCmd *pCommand = NULL;
6706
6707 if(pMac->roam.configParam.bgScanInterval)
6708 {
6709 do
6710 {
6711 pCommand = csrGetCommandBuffer(pMac);
6712 if(!pCommand)
6713 {
6714 status = eHAL_STATUS_RESOURCES;
6715 break;
6716 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306717 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006718 pCommand->command = eSmeCommandScan;
6719 pCommand->u.scanCmd.reason = eCsrScanBGScanEnable;
6720 pCommand->u.scanCmd.callback = NULL;
6721 pCommand->u.scanCmd.pContext = NULL;
6722 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
6723 if( !HAL_STATUS_SUCCESS( status ) )
6724 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006725 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006726 csrReleaseCommandScan( pMac, pCommand );
6727 break;
6728 }
6729 }while(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006730 }
6731 else
6732 {
Sushant Kaushikb8dbb3f2015-04-29 17:03:37 +05306733 smsLog(pMac, LOGE, FL("cannot continue because the bgscan interval is 0"));
6734 status = eHAL_STATUS_INVALID_PARAMETER;
Jeff Johnson295189b2012-06-20 16:38:30 -07006735 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006736 return (status);
6737}
6738
6739
6740eHalStatus csrScanCopyRequest(tpAniSirGlobal pMac, tCsrScanRequest *pDstReq, tCsrScanRequest *pSrcReq)
6741{
6742 eHalStatus status = eHAL_STATUS_SUCCESS;
6743 tANI_U32 len = sizeof(pMac->roam.validChannelList);
6744 tANI_U32 index = 0;
6745 tANI_U32 new_index = 0;
Manjunathappa Prakashde7b2a52014-02-28 16:59:03 -08006746 eNVChannelEnabledType NVchannel_state;
Arif Hussain6af38622014-03-12 12:39:57 -07006747 tANI_U8 ch144_support = 0;
6748
6749 ch144_support = WDA_getFwWlanFeatCaps(WLAN_CH144);
Jeff Johnson295189b2012-06-20 16:38:30 -07006750
6751 do
6752 {
6753 status = csrScanFreeRequest(pMac, pDstReq);
6754 if(HAL_STATUS_SUCCESS(status))
6755 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306756 vos_mem_copy(pDstReq, pSrcReq, sizeof(tCsrScanRequest));
Gopichand Nakkalac7b1d3e2012-12-31 14:07:19 -08006757 /* Re-initialize the pointers to NULL since we did a copy */
6758 pDstReq->pIEField = NULL;
6759 pDstReq->ChannelInfo.ChannelList = NULL;
6760 pDstReq->SSIDs.SSIDList = NULL;
6761
Jeff Johnson295189b2012-06-20 16:38:30 -07006762 if(pSrcReq->uIEFieldLen == 0)
6763 {
6764 pDstReq->pIEField = NULL;
6765 }
6766 else
6767 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306768 pDstReq->pIEField = vos_mem_malloc(pSrcReq->uIEFieldLen);
6769 if ( NULL == pDstReq->pIEField )
Jeff Johnson295189b2012-06-20 16:38:30 -07006770 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306771 status = eHAL_STATUS_FAILURE;
6772 smsLog(pMac, LOGE, FL("No memory for scanning IE fields"));
6773 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07006774 }
6775 else
6776 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306777 status = eHAL_STATUS_SUCCESS;
6778 vos_mem_copy(pDstReq->pIEField, pSrcReq->pIEField,
6779 pSrcReq->uIEFieldLen);
6780 pDstReq->uIEFieldLen = pSrcReq->uIEFieldLen;
Jeff Johnson295189b2012-06-20 16:38:30 -07006781 }
6782 }//Allocate memory for IE field
6783 {
6784 if(pSrcReq->ChannelInfo.numOfChannels == 0)
6785 {
6786 pDstReq->ChannelInfo.ChannelList = NULL;
6787 pDstReq->ChannelInfo.numOfChannels = 0;
6788 }
6789 else
6790 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306791 pDstReq->ChannelInfo.ChannelList = vos_mem_malloc(
6792 pSrcReq->ChannelInfo.numOfChannels
6793 * sizeof(*pDstReq->ChannelInfo.ChannelList));
6794 if ( NULL == pDstReq->ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07006795 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306796 status = eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006797 pDstReq->ChannelInfo.numOfChannels = 0;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306798 smsLog(pMac, LOGE, FL("No memory for scanning Channel"
6799 " List"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006800 break;
6801 }
6802
6803 if((pSrcReq->scanType == eSIR_PASSIVE_SCAN) && (pSrcReq->requestType == eCSR_SCAN_REQUEST_11D_SCAN))
6804 {
6805 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
6806 {
Arif Hussain6af38622014-03-12 12:39:57 -07006807 /* Skip CH 144 if firmware support not present */
6808 if (pSrcReq->ChannelInfo.ChannelList[index] == 144 && !ch144_support)
6809 continue;
Agarwal Ashish8bd53ae2015-06-12 18:03:45 +05306810 /* Skip channel 12 and 13 when FCC constraint is true */
6811 if ((pMac->scan.fcc_constraint) &&
6812 ((pSrcReq->ChannelInfo.ChannelList[index] ==12) ||
6813 (pSrcReq->ChannelInfo.ChannelList[index] ==13)))
6814 {
6815 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
6816 FL("Ignoring channel : %d "),
6817 pSrcReq->ChannelInfo.ChannelList[index]);
6818 continue;
6819 }
Arif Hussain6af38622014-03-12 12:39:57 -07006820
Manjunathappa Prakashde7b2a52014-02-28 16:59:03 -08006821 NVchannel_state = vos_nv_getChannelEnabledState(
6822 pSrcReq->ChannelInfo.ChannelList[index]);
6823 if ((NV_CHANNEL_ENABLE == NVchannel_state) ||
6824 (NV_CHANNEL_DFS == NVchannel_state))
6825 {
6826 pDstReq->ChannelInfo.ChannelList[new_index] =
6827 pSrcReq->ChannelInfo.ChannelList[index];
6828 new_index++;
6829 }
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306830 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006831 pDstReq->ChannelInfo.numOfChannels = new_index;
6832 }
6833 else if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
6834 {
6835 new_index = 0;
6836 pMac->roam.numValidChannels = len;
c_hpothu0d5a7352014-03-22 12:30:25 +05306837
Deepthi Gowriecc93352016-11-09 16:58:47 +05306838 /* Since in CsrScanRequest,value of pMac->scan.
6839 * nextScanID is incremented before calling
6840 * CsrScanCopyRequest, as a result pMac->scan.
6841 * nextScanID is equal to ONE for the first scan.
6842 * If number of channels is less than max chan
6843 * for dwell time no need to skip dfs in first
6844 * scan as anyway few channels will be scanned
6845 * and it will not take much time to display
6846 * results on GUI.
6847 */
6848 if (((pSrcReq->ChannelInfo.numOfChannels >=
6849 pMac->roam.configParam.
6850 max_chan_for_dwell_time_cfg) &&
6851 (pMac->roam.configParam.
6852 initialScanSkipDFSCh &&
6853 1 == pMac->scan.nextScanID)) ||
6854 (pMac->miracast_mode))
c_hpothu0d5a7352014-03-22 12:30:25 +05306855 {
Deepthi Gowriecc93352016-11-09 16:58:47 +05306856 smsLog(pMac, LOG1,
6857 FL("Initial scan, scan only non-DFS channels"));
c_hpothu0d5a7352014-03-22 12:30:25 +05306858
Deepthi Gowriecc93352016-11-09 16:58:47 +05306859 for (index = 0; index < pSrcReq->ChannelInfo.
6860 numOfChannels ; index++ )
Jeff Johnson295189b2012-06-20 16:38:30 -07006861 {
Deepthi Gowriecc93352016-11-09 16:58:47 +05306862 if((csrRoamIsValidChannel(pMac,
6863 pSrcReq->ChannelInfo.
6864 ChannelList[index])))
Srikant Kuppa866893f2012-12-27 17:28:14 -08006865 {
Deepthi Gowriecc93352016-11-09 16:58:47 +05306866 /*Skiipping DFS Channels for 1st scan */
6867 if(NV_CHANNEL_DFS ==
6868 vos_nv_getChannelEnabledState(
6869 pSrcReq->ChannelInfo.
6870 ChannelList[index]))
6871 continue ;
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08006872
Deepthi Gowriecc93352016-11-09 16:58:47 +05306873 pDstReq->ChannelInfo.
6874 ChannelList[new_index] =
6875 pSrcReq->ChannelInfo.ChannelList[index];
6876 new_index++;
6877
6878 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006879 }
Deepthi Gowriecc93352016-11-09 16:58:47 +05306880 pMac->roam.configParam.initialScanSkipDFSCh = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07006881 }
Deepthi Gowriecc93352016-11-09 16:58:47 +05306882 else
6883 csrValidateScanChannels(pMac, pDstReq, pSrcReq,
6884 new_index, ch144_support);
Jeff Johnson295189b2012-06-20 16:38:30 -07006885 pDstReq->ChannelInfo.numOfChannels = new_index;
Srikant Kuppa866893f2012-12-27 17:28:14 -08006886#ifdef FEATURE_WLAN_LFR
Deepthi Gowriecc93352016-11-09 16:58:47 +05306887 if ( ( ( eCSR_SCAN_HO_BG_SCAN ==
6888 pSrcReq->requestType ) ||
6889 ( eCSR_SCAN_P2P_DISCOVERY ==
6890 pSrcReq->requestType ) ) &&
6891 ( 0 == pDstReq->ChannelInfo.numOfChannels ) )
Srikant Kuppa866893f2012-12-27 17:28:14 -08006892 {
6893 /*
6894 * No valid channels found in the request.
6895 * Only perform scan on the channels passed
Abhishek Singh2ec36ab2014-08-07 16:14:25 +05306896 * pSrcReq if it is a eCSR_SCAN_HO_BG_SCAN or
6897 * eCSR_SCAN_P2P_DISCOVERY.
Srikant Kuppa866893f2012-12-27 17:28:14 -08006898 * Passing 0 to LIM will trigger a scan on
6899 * all valid channels which is not desirable.
6900 */
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306901 smsLog(pMac, LOGE, FL(" no valid channels found"
Deepthi Gowriecc93352016-11-09 16:58:47 +05306902 " (request=%d)"), pSrcReq->requestType);
6903 for ( index = 0; index < pSrcReq->ChannelInfo.
6904 numOfChannels ; index++ )
Srikant Kuppa866893f2012-12-27 17:28:14 -08006905 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306906 smsLog(pMac, LOGE, FL("pSrcReq index=%d"
Deepthi Gowriecc93352016-11-09 16:58:47 +05306907 " channel=%d"), index,
6908 pSrcReq->ChannelInfo.ChannelList[index]);
Srikant Kuppa866893f2012-12-27 17:28:14 -08006909 }
6910 status = eHAL_STATUS_FAILURE;
6911 break;
Deepthi Gowriecc93352016-11-09 16:58:47 +05306912 }
Srikant Kuppa866893f2012-12-27 17:28:14 -08006913#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006914 }
6915 else
6916 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306917 smsLog(pMac, LOGE, FL("Couldn't get the valid Channel"
6918 " List, keeping requester's list"));
Kiet Lam64c1b492013-07-12 13:56:44 +05306919 vos_mem_copy(pDstReq->ChannelInfo.ChannelList,
6920 pSrcReq->ChannelInfo.ChannelList,
6921 pSrcReq->ChannelInfo.numOfChannels
Deepthi Gowriecc93352016-11-09 16:58:47 +05306922 * sizeof(*pDstReq->ChannelInfo.ChannelList));
6923 pDstReq->ChannelInfo.numOfChannels =
6924 pSrcReq->ChannelInfo.numOfChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -07006925 }
6926 }//Allocate memory for Channel List
6927 }
6928 if(pSrcReq->SSIDs.numOfSSIDs == 0)
6929 {
6930 pDstReq->SSIDs.numOfSSIDs = 0;
6931 pDstReq->SSIDs.SSIDList = NULL;
6932 }
6933 else
6934 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306935 pDstReq->SSIDs.SSIDList = vos_mem_malloc(
6936 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
6937 if ( NULL == pDstReq->SSIDs.SSIDList )
6938 status = eHAL_STATUS_FAILURE;
6939 else
6940 status = eHAL_STATUS_SUCCESS;
6941 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07006942 {
6943 pDstReq->SSIDs.numOfSSIDs = pSrcReq->SSIDs.numOfSSIDs;
Kiet Lam64c1b492013-07-12 13:56:44 +05306944 vos_mem_copy(pDstReq->SSIDs.SSIDList,
6945 pSrcReq->SSIDs.SSIDList,
6946 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
Jeff Johnson295189b2012-06-20 16:38:30 -07006947 }
6948 else
6949 {
6950 pDstReq->SSIDs.numOfSSIDs = 0;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306951 smsLog(pMac, LOGE, FL("No memory for scanning SSID List"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006952 break;
6953 }
6954 }//Allocate memory for SSID List
Jeff Johnson295189b2012-06-20 16:38:30 -07006955 pDstReq->p2pSearch = pSrcReq->p2pSearch;
Jeff Johnsone7245742012-09-05 17:12:55 -07006956 pDstReq->skipDfsChnlInP2pSearch = pSrcReq->skipDfsChnlInP2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07006957
6958 }
6959 }while(0);
6960
6961 if(!HAL_STATUS_SUCCESS(status))
6962 {
6963 csrScanFreeRequest(pMac, pDstReq);
6964 }
6965
6966 return (status);
6967}
6968
6969
6970eHalStatus csrScanFreeRequest(tpAniSirGlobal pMac, tCsrScanRequest *pReq)
6971{
Jeff Johnson295189b2012-06-20 16:38:30 -07006972
6973 if(pReq->ChannelInfo.ChannelList)
6974 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306975 vos_mem_free(pReq->ChannelInfo.ChannelList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006976 pReq->ChannelInfo.ChannelList = NULL;
6977 }
6978 pReq->ChannelInfo.numOfChannels = 0;
6979 if(pReq->pIEField)
6980 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306981 vos_mem_free(pReq->pIEField);
Jeff Johnson295189b2012-06-20 16:38:30 -07006982 pReq->pIEField = NULL;
6983 }
6984 pReq->uIEFieldLen = 0;
6985 if(pReq->SSIDs.SSIDList)
6986 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306987 vos_mem_free(pReq->SSIDs.SSIDList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006988 pReq->SSIDs.SSIDList = NULL;
6989 }
6990 pReq->SSIDs.numOfSSIDs = 0;
6991
Kiet Lam64c1b492013-07-12 13:56:44 +05306992 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07006993}
6994
6995
6996void csrScanCallCallback(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
6997{
6998 if(pCommand->u.scanCmd.callback)
6999 {
Ratheesh S Pece1f832015-07-25 15:50:25 +05307000 if (pCommand->u.scanCmd.abortScanIndication){
Kapil Guptac46b7542016-10-25 13:03:20 +05307001 if ((pCommand->u.scanCmd.reason != eCsrScanForSsid) ||
7002 (scanStatus != eCSR_SCAN_SUCCESS)) {
7003 smsLog( pMac, LOG1, FL("scanDone due to abort"));
7004 scanStatus = eCSR_SCAN_ABORT;
7005 }
Ratheesh S Pece1f832015-07-25 15:50:25 +05307006 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007007 pCommand->u.scanCmd.callback(pMac, pCommand->u.scanCmd.pContext, pCommand->u.scanCmd.scanID, scanStatus);
Jeff Johnson295189b2012-06-20 16:38:30 -07007008 } else {
Kapil Guptac46b7542016-10-25 13:03:20 +05307009 smsLog(pMac, LOG2,
7010 FL("Callback NULL cmd reason %d"),
7011 pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07007012 }
7013}
7014
7015
7016void csrScanStopTimers(tpAniSirGlobal pMac)
7017{
Jeff Johnson295189b2012-06-20 16:38:30 -07007018 csrScanStopIdleScanTimer(pMac);
7019 csrScanStopGetResultTimer(pMac);
7020}
7021
7022
7023eHalStatus csrScanStartGetResultTimer(tpAniSirGlobal pMac)
7024{
7025 eHalStatus status;
7026
7027 if(pMac->scan.fScanEnable)
7028 {
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05307029 status = vos_timer_start(&pMac->scan.hTimerGetResult, CSR_SCAN_GET_RESULT_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07007030 }
7031 else
7032 {
7033 status = eHAL_STATUS_FAILURE;
7034 }
7035
7036 return (status);
7037}
7038
7039
7040eHalStatus csrScanStopGetResultTimer(tpAniSirGlobal pMac)
7041{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05307042 return (vos_timer_stop(&pMac->scan.hTimerGetResult));
Jeff Johnson295189b2012-06-20 16:38:30 -07007043}
7044
7045
7046void csrScanGetResultTimerHandler(void *pv)
7047{
7048 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
7049
7050 csrScanRequestResult(pMac);
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05307051
7052 vos_timer_start(&pMac->scan.hTimerGetResult, CSR_SCAN_GET_RESULT_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07007053}
7054
Padma, Santhosh Kumar36183352016-11-08 17:48:34 +05307055
7056void csr_handle_disable_scan(void *pv)
7057{
7058 tpAniSirGlobal mac = PMAC_STRUCT(pv);
7059
7060 if (mac->scan.disable_scan_during_sco_timer_info.callback)
7061 mac->scan.disable_scan_during_sco_timer_info.callback(
7062 mac,
7063 mac->scan.disable_scan_during_sco_timer_info.dev,
7064 mac->scan.disable_scan_during_sco_timer_info.scan_id,
7065 eHAL_STATUS_SUCCESS);
7066 else
7067 smsLog(mac, LOGE, FL("Callback is NULL"));
7068}
7069
Jeff Johnson295189b2012-06-20 16:38:30 -07007070#ifdef WLAN_AP_STA_CONCURRENCY
7071static void csrStaApConcTimerHandler(void *pv)
7072{
7073 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
7074 tListElem *pEntry;
7075 tSmeCmd *pScanCmd;
7076
7077 csrLLLock(&pMac->scan.scanCmdPendingList);
7078
7079 if ( NULL != ( pEntry = csrLLPeekHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) ) )
7080 {
7081 tCsrScanRequest scanReq;
7082 tSmeCmd *pSendScanCmd = NULL;
7083 tANI_U8 numChn = 0;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07007084 tANI_U8 nNumChanCombinedConc = 0;
Vinay Malekal05fdc812012-12-17 13:04:30 -08007085 tANI_U8 i, j;
Jeff Johnson295189b2012-06-20 16:38:30 -07007086 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
7087 tANI_U8 channelToScan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
7088 eHalStatus status;
7089
Jeff Johnson295189b2012-06-20 16:38:30 -07007090 pScanCmd = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7091 numChn = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08007092
7093 /* if any session is connected and the number of channels to scan is
7094 * greater than 1 then split the scan into multiple scan operations
7095 * on each individual channel else continue to perform scan on all
7096 * specified channels */
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08007097
7098 /* split scan if number of channels to scan is greater than 1 and
7099 * any one of the following:
7100 * - STA session is connected and the scan is not a P2P search
7101 * - any P2P session is connected
Srikant Kuppa866893f2012-12-27 17:28:14 -08007102 * Do not split scans if no concurrent infra connections are
7103 * active and if the scan is a BG scan triggered by LFR (OR)
7104 * any scan if LFR is in the middle of a BG scan. Splitting
7105 * the scan is delaying the time it takes for LFR to find
7106 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08007107 */
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07007108
7109 if((csrIsStaSessionConnected(pMac) &&
7110 !csrIsP2pSessionConnected(pMac)))
7111 {
7112 nNumChanCombinedConc = pMac->roam.configParam.nNumStaChanCombinedConc;
7113 }
7114 else if(csrIsP2pSessionConnected(pMac))
7115 {
7116 nNumChanCombinedConc = pMac->roam.configParam.nNumP2PChanCombinedConc;
7117 }
7118
7119 if ( (numChn > nNumChanCombinedConc) &&
Srikant Kuppa866893f2012-12-27 17:28:14 -08007120 ((csrIsStaSessionConnected(pMac) &&
7121#ifdef FEATURE_WLAN_LFR
7122 (csrIsConcurrentInfraConnected(pMac) ||
7123 ((pScanCmd->u.scanCmd.reason != eCsrScanBgScan) &&
7124 (pMac->roam.neighborRoamInfo.neighborRoamState !=
7125 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
7126#endif
7127 (pScanCmd->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08007128 (csrIsP2pSessionConnected(pMac))))
Jeff Johnson295189b2012-06-20 16:38:30 -07007129 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307130 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007131
7132 pSendScanCmd = csrGetCommandBuffer(pMac); //optimize this to use 2 command buffer only
7133 if (!pSendScanCmd)
7134 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007135 smsLog( pMac, LOGE, FL(" Failed to get Queue command buffer") );
Jeff Johnson295189b2012-06-20 16:38:30 -07007136 csrLLUnlock(&pMac->scan.scanCmdPendingList);
7137 return;
7138 }
7139 pSendScanCmd->command = pScanCmd->command;
7140 pSendScanCmd->sessionId = pScanCmd->sessionId;
7141 pSendScanCmd->u.scanCmd.callback = NULL;
7142 pSendScanCmd->u.scanCmd.pContext = pScanCmd->u.scanCmd.pContext;
7143 pSendScanCmd->u.scanCmd.reason = pScanCmd->u.scanCmd.reason;
7144 pSendScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
7145
Madan Mohan Koyyalamudiaf2a8b92012-10-09 14:58:07 -07007146 /* First copy all the parameters to local variable of scan request */
7147 csrScanCopyRequest(pMac, &scanReq, &pScanCmd->u.scanCmd.u.scanRequest);
7148
7149 /* Now modify the elements of local var scan request required to be modified for split scan */
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08007150 if(scanReq.ChannelInfo.ChannelList != NULL)
7151 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307152 vos_mem_free(scanReq.ChannelInfo.ChannelList);
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08007153 scanReq.ChannelInfo.ChannelList = NULL;
7154 }
7155
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07007156 pChnInfo->numOfChannels = nNumChanCombinedConc;
Kiet Lam64c1b492013-07-12 13:56:44 +05307157 vos_mem_copy(&channelToScan[0],
7158 &pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[0],
7159 pChnInfo->numOfChannels * sizeof(tANI_U8));//just send one channel
Jeff Johnson295189b2012-06-20 16:38:30 -07007160 pChnInfo->ChannelList = &channelToScan[0];
7161
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07007162 for (i = 0, j = nNumChanCombinedConc; i < (numChn-nNumChanCombinedConc); i++, j++)
Jeff Johnson295189b2012-06-20 16:38:30 -07007163 {
7164 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] =
Vinay Malekal05fdc812012-12-17 13:04:30 -08007165 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[j]; //Move all the channels one step
Jeff Johnson295189b2012-06-20 16:38:30 -07007166 }
7167
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07007168 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = numChn - nNumChanCombinedConc; //reduce outstanding # of channels to be scanned
Jeff Johnson295189b2012-06-20 16:38:30 -07007169
7170 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
c_hpothudbefd3e2014-04-28 15:59:47 +05307171
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -07007172 //Use concurrency values for min/maxChnTime.
7173 //We know csrIsAnySessionConnected(pMac) returns TRUE here
7174 csrSetDefaultScanTiming(pMac, scanReq.scanType, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07007175
7176 status = csrScanCopyRequest(pMac, &pSendScanCmd->u.scanCmd.u.scanRequest, &scanReq);
7177 if(!HAL_STATUS_SUCCESS(status))
7178 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007179 smsLog( pMac, LOGE, FL(" Failed to get copy csrScanRequest = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07007180 csrLLUnlock(&pMac->scan.scanCmdPendingList);
7181 return;
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08007182 }
7183 /* Clean the local scan variable */
7184 scanReq.ChannelInfo.ChannelList = NULL;
7185 scanReq.ChannelInfo.numOfChannels = 0;
7186 csrScanFreeRequest(pMac, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07007187 }
7188 else
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08007189 {
7190 /* no active connected session present or numChn == 1
7191 * scan all remaining channels */
Jeff Johnson295189b2012-06-20 16:38:30 -07007192 pSendScanCmd = pScanCmd;
7193 //remove this command from pending list
7194 if (csrLLRemoveHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) == NULL)
7195 { //In case between PeekHead and here, the entry got removed by another thread.
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007196 smsLog( pMac, LOGE, FL(" Failed to remove entry from scanCmdPendingList"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007197 }
7198
7199 }
7200 csrQueueSmeCommand(pMac, pSendScanCmd, eANI_BOOLEAN_FALSE);
7201
7202 }
7203
Jeff Johnson295189b2012-06-20 16:38:30 -07007204 csrLLUnlock(&pMac->scan.scanCmdPendingList);
7205
7206}
7207#endif
7208
Jeff Johnson295189b2012-06-20 16:38:30 -07007209//This function returns the maximum time a BSS is allowed in the scan result.
7210//The time varies base on connection and power saving factors.
7211//Not connected, No PS
7212//Not connected, with PS
7213//Connected w/o traffic, No PS
7214//Connected w/o traffic, with PS
7215//Connected w/ traffic, no PS -- Not supported
7216//Connected w/ traffic, with PS -- Not supported
7217//the return unit is in seconds.
7218tANI_U32 csrScanGetAgeOutTime(tpAniSirGlobal pMac)
7219{
7220 tANI_U32 nRet;
7221
7222 if(pMac->scan.nAgingCountDown)
7223 {
7224 //Calculate what should be the timeout value for this
7225 nRet = pMac->scan.nLastAgeTimeOut * pMac->scan.nAgingCountDown;
7226 pMac->scan.nAgingCountDown--;
7227 }
7228 else
7229 {
7230 if( csrIsAllSessionDisconnected( pMac ) )
7231 {
7232 if(pmcIsPowerSaveEnabled(pMac, ePMC_IDLE_MODE_POWER_SAVE))
7233 {
7234 nRet = pMac->roam.configParam.scanAgeTimeNCPS;
7235 }
7236 else
7237 {
7238 nRet = pMac->roam.configParam.scanAgeTimeNCNPS;
7239 }
7240 }
7241 else
7242 {
7243 if(pmcIsPowerSaveEnabled(pMac, ePMC_BEACON_MODE_POWER_SAVE))
7244 {
7245 nRet = pMac->roam.configParam.scanAgeTimeCPS;
7246 }
7247 else
7248 {
7249 nRet = pMac->roam.configParam.scanAgeTimeCNPS;
7250 }
7251 }
7252 //If state-change causing aging time out change, we want to delay it somewhat to avoid
7253 //unnecessary removal of BSS. This is mostly due to transition from connect to disconnect.
7254 if(pMac->scan.nLastAgeTimeOut > nRet)
7255 {
7256 if(nRet)
7257 {
7258 pMac->scan.nAgingCountDown = (pMac->scan.nLastAgeTimeOut / nRet);
7259 }
7260 pMac->scan.nLastAgeTimeOut = nRet;
7261 nRet *= pMac->scan.nAgingCountDown;
7262 }
7263 else
7264 {
7265 pMac->scan.nLastAgeTimeOut = nRet;
7266 }
7267 }
7268
7269 return (nRet);
7270}
7271
Deepthi Gowri6a08e312016-03-31 19:10:14 +05307272static void csrPurgeScanResultByAge(void *pv)
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08007273{
7274 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
7275 tListElem *pEntry, *tmpEntry;
7276 tCsrScanResult *pResult;
Deepthi Gowri4480a3f2016-05-18 19:30:17 +05307277 v_TIME_t ageOutTime =
7278 (v_TIME_t)(pMac->scan.scanResultCfgAgingTime * SYSTEM_TIME_SEC_TO_MSEC);
7279 v_TIME_t curTime = vos_timer_get_system_time();
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08007280
7281 csrLLLock(&pMac->scan.scanResultList);
7282 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
Deepthi Gowri6a08e312016-03-31 19:10:14 +05307283 smsLog(pMac, LOG1, FL("Ageout time=%lu"),ageOutTime);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08007284 while( pEntry )
7285 {
7286 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
7287 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
7288 if((curTime - pResult->Result.BssDescriptor.nReceivedTime) > ageOutTime)
7289 {
Deepthi Gowri50e2fa52016-03-17 15:30:53 +05307290 smsLog(pMac, LOG1, FL("age out due to time out for BSSID" MAC_ADDRESS_STR),
7291 MAC_ADDR_ARRAY(pResult->Result.BssDescriptor.bssId));
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08007292 csrScanAgeOutBss(pMac, pResult);
7293 }
7294 pEntry = tmpEntry;
7295 }
7296 csrLLUnlock(&pMac->scan.scanResultList);
7297}
Jeff Johnson295189b2012-06-20 16:38:30 -07007298
7299eHalStatus csrScanStartIdleScanTimer(tpAniSirGlobal pMac, tANI_U32 interval)
7300{
7301 eHalStatus status;
7302
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007303 smsLog(pMac, LOG1, " csrScanStartIdleScanTimer");
Jeff Johnson295189b2012-06-20 16:38:30 -07007304 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) && interval)
7305 {
7306 pMac->scan.nIdleScanTimeGap += interval;
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05307307 vos_timer_stop(&pMac->scan.hTimerIdleScan);
7308 status = vos_timer_start(&pMac->scan.hTimerIdleScan, interval/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07007309 if( !HAL_STATUS_SUCCESS(status) )
7310 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007311 smsLog(pMac, LOGE, " Fail to start Idle scan timer. status = %d interval = %d", status, interval);
Jeff Johnson295189b2012-06-20 16:38:30 -07007312 //This should not happen but set the flag to restart when ready
7313 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7314 }
7315 }
7316 else
7317 {
7318 if( pMac->scan.fScanEnable && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) )
7319 {
7320 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7321 }
7322 status = eHAL_STATUS_FAILURE;
7323 }
7324
7325 return (status);
7326}
7327
7328
7329eHalStatus csrScanStopIdleScanTimer(tpAniSirGlobal pMac)
7330{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05307331 return (vos_timer_stop(&pMac->scan.hTimerIdleScan));
Jeff Johnson295189b2012-06-20 16:38:30 -07007332}
7333
7334
7335//Stop CSR from asking for IMPS, This function doesn't disable IMPS from CSR
7336void csrScanSuspendIMPS( tpAniSirGlobal pMac )
7337{
7338 csrScanCancelIdleScan(pMac);
7339}
7340
7341
7342//Start CSR from asking for IMPS. This function doesn't trigger CSR to request entering IMPS
7343//because IMPS maybe disabled.
7344void csrScanResumeIMPS( tpAniSirGlobal pMac )
7345{
7346 csrScanStartIdleScan( pMac );
7347}
7348
7349
7350void csrScanIMPSCallback(void *callbackContext, eHalStatus status)
7351{
7352 tpAniSirGlobal pMac = PMAC_STRUCT( callbackContext );
7353
7354 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
7355 {
7356 if(pMac->roam.configParam.IsIdleScanEnabled)
7357 {
7358 if(HAL_STATUS_SUCCESS(status))
7359 {
7360 if(csrIsAllSessionDisconnected(pMac) && !csrIsRoamCommandWaiting(pMac))
7361 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007362 smsLog(pMac, LOGW, FL("starts idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007363 csrScanAllChannels(pMac, eCSR_SCAN_IDLE_MODE_SCAN);
7364 }
7365 else
7366 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007367 smsLog(pMac, LOGW, FL("cannot start idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007368 //even though we are in timer handle, calling stop timer will make sure the timer
7369 //doesn't get to restart.
7370 csrScanStopIdleScanTimer(pMac);
7371 }
7372 }
7373 else
7374 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007375 smsLog(pMac, LOGE, FL("sees not success status (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07007376 }
7377 }
7378 else
7379 {//we might need another flag to check if CSR needs to request imps at all
7380
7381 tANI_U32 nTime = 0;
7382
7383 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_FALSE;
7384 if(!HAL_STATUS_SUCCESS(csrScanTriggerIdleScan(pMac, &nTime)))
7385 {
7386 csrScanStartIdleScanTimer(pMac, nTime);
7387 }
7388 }
7389 }
7390}
7391
7392
Rashmi Ramanna68b309c2014-05-20 11:52:22 +05307393//Param: pTimeInterval -- Caller allocated memory in return, if failed, to specify the nxt time interval for
Jeff Johnson295189b2012-06-20 16:38:30 -07007394//idle scan timer interval
7395//Return: Not success -- meaning it cannot start IMPS, caller needs to start a timer for idle scan
7396eHalStatus csrScanTriggerIdleScan(tpAniSirGlobal pMac, tANI_U32 *pTimeInterval)
7397{
7398 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
7399
7400 //Do not trigger IMPS in case of concurrency
Agarwal Ashish5974ed32014-06-16 16:59:54 +05307401 if (vos_concurrent_open_sessions_running() &&
7402 csrIsAnySessionInConnectState(pMac))
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007403 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007404 smsLog( pMac, LOG1, FL("Cannot request IMPS because Concurrent Sessions Running") );
Jeff Johnson295189b2012-06-20 16:38:30 -07007405 return (status);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007406 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007407
7408 if(pTimeInterval)
7409 {
7410 *pTimeInterval = 0;
7411 }
7412
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007413 smsLog(pMac, LOG3, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007414 if( smeCommandPending( pMac ) )
7415 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007416 smsLog( pMac, LOG1, FL(" Cannot request IMPS because command pending") );
Jeff Johnson295189b2012-06-20 16:38:30 -07007417 //Not to enter IMPS because more work to do
7418 if(pTimeInterval)
7419 {
7420 *pTimeInterval = 0;
7421 }
7422 //restart when ready
7423 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7424
7425 return (status);
7426 }
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07007427 if (IsPmcImpsReqFailed (pMac))
7428 {
7429 if(pTimeInterval)
7430 {
7431 *pTimeInterval = 1000000; //usec
7432 }
7433 //restart when ready
7434 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07007435
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07007436 return status;
7437 }
Rashmi Ramanna68b309c2014-05-20 11:52:22 +05307438
7439 if ( !pMac->deferImps && pMac->fDeferIMPSTime )
7440 {
7441 smsLog( pMac, LOG1, FL("Defer IMPS for %dms as command processed"),
7442 pMac->fDeferIMPSTime);
Girish Gowli4f3775a2014-05-30 17:17:08 +05307443 if(pTimeInterval)
7444 {
7445 *pTimeInterval = pMac->fDeferIMPSTime * 1000; //usec
7446 }
Rashmi Ramanna68b309c2014-05-20 11:52:22 +05307447 pMac->deferImps = eANI_BOOLEAN_TRUE;
7448 return status;
7449 }
7450
Jeff Johnson295189b2012-06-20 16:38:30 -07007451 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
7452 /*&& pMac->roam.configParam.impsSleepTime*/)
7453 {
7454 //Stop get result timer because idle scan gets scan result out of PE
7455 csrScanStopGetResultTimer(pMac);
7456 if(pTimeInterval)
7457 {
7458 *pTimeInterval = pMac->roam.configParam.impsSleepTime;
7459 }
7460 //pmcRequestImps take a period in millisecond unit.
7461 status = pmcRequestImps(pMac, pMac->roam.configParam.impsSleepTime / PAL_TIMER_TO_MS_UNIT, csrScanIMPSCallback, pMac);
7462 if(!HAL_STATUS_SUCCESS(status))
7463 {
7464 if(eHAL_STATUS_PMC_ALREADY_IN_IMPS != status)
7465 {
7466 //Do restart the timer if CSR thinks it cannot do IMPS
7467 if( !csrCheckPSReady( pMac ) )
7468 {
7469 if(pTimeInterval)
7470 {
7471 *pTimeInterval = 0;
7472 }
7473 //Set the restart flag to true because that idle scan
7474 //can be restarted even though the timer will not be running
7475 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7476 }
7477 else
7478 {
7479 //For not now, we do a quicker retry
7480 if(pTimeInterval)
7481 {
7482 *pTimeInterval = CSR_IDLE_SCAN_WAIT_TIME;
7483 }
7484 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007485 smsLog(pMac, LOGW, FL("call pmcRequestImps and it returns status code (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07007486 }
7487 else
7488 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007489 smsLog(pMac, LOGW, FL("already in IMPS"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007490 //Since CSR is the only module to request for IMPS. If it is already in IMPS, CSR assumes
7491 //the callback will be called in the future. Should not happen though.
7492 status = eHAL_STATUS_SUCCESS;
7493 pMac->scan.nIdleScanTimeGap = 0;
7494 }
7495 }
7496 else
7497 {
7498 //requested so let's reset the value
7499 pMac->scan.nIdleScanTimeGap = 0;
7500 }
7501 }
7502
7503 return (status);
7504}
7505
7506
7507eHalStatus csrScanStartIdleScan(tpAniSirGlobal pMac)
7508{
7509 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
7510 tANI_U32 nTime = 0;
7511
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007512 smsLog(pMac, LOGW, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007513 if(pMac->roam.configParam.IsIdleScanEnabled)
7514 {
7515 //stop bg scan first
7516 csrScanBGScanAbort(pMac);
7517 //Stop get result timer because idle scan gets scan result out of PE
7518 csrScanStopGetResultTimer(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07007519 }
7520 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_FALSE;
7521 status = csrScanTriggerIdleScan(pMac, &nTime);
7522 if(!HAL_STATUS_SUCCESS(status))
7523 {
7524 csrScanStartIdleScanTimer(pMac, nTime);
7525 }
7526
7527 return (status);
7528}
7529
7530
7531void csrScanCancelIdleScan(tpAniSirGlobal pMac)
7532{
7533 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
7534 {
Agarwal Ashish5974ed32014-06-16 16:59:54 +05307535 if (vos_concurrent_open_sessions_running()) {
Jeff Johnson295189b2012-06-20 16:38:30 -07007536 return;
7537 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007538 smsLog(pMac, LOG1, " csrScanCancelIdleScan");
Jeff Johnson295189b2012-06-20 16:38:30 -07007539 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_TRUE;
7540 //Set the restart flag in case later on it is uncancelled
7541 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7542 csrScanStopIdleScanTimer(pMac);
7543 csrScanRemoveNotRoamingScanCommand(pMac);
7544 }
7545}
7546
7547
7548void csrScanIdleScanTimerHandler(void *pv)
7549{
7550 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
7551 eHalStatus status;
7552 tANI_U32 nTime = 0;
7553
7554 smsLog(pMac, LOGW, " csrScanIdleScanTimerHandler called ");
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07007555 pmcResetImpsFailStatus (pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07007556 status = csrScanTriggerIdleScan(pMac, &nTime);
7557 if(!HAL_STATUS_SUCCESS(status) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan))
7558 {
7559 //Check whether it is time to actually do an idle scan
7560 if(pMac->scan.nIdleScanTimeGap >= pMac->roam.configParam.impsSleepTime)
7561 {
7562 pMac->scan.nIdleScanTimeGap = 0;
7563 csrScanIMPSCallback(pMac, eHAL_STATUS_SUCCESS);
7564 }
7565 else
7566 {
7567 csrScanStartIdleScanTimer(pMac, nTime);
7568 }
7569 }
Rashmi Ramanna68b309c2014-05-20 11:52:22 +05307570 if(pMac->deferImps)
7571 {
7572 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7573 pMac->deferImps = eANI_BOOLEAN_FALSE;
7574 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007575}
7576
7577
7578
7579
7580tANI_BOOLEAN csrScanRemoveNotRoamingScanCommand(tpAniSirGlobal pMac)
7581{
7582 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
7583 tListElem *pEntry, *pEntryTmp;
7584 tSmeCmd *pCommand;
7585 tDblLinkList localList;
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307586 tDblLinkList *pCmdList;
Jeff Johnson295189b2012-06-20 16:38:30 -07007587
7588 vos_mem_zero(&localList, sizeof(tDblLinkList));
7589 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
7590 {
7591 smsLog(pMac, LOGE, FL(" failed to open list"));
7592 return fRet;
7593 }
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307594 if (!pMac->fScanOffload)
7595 pCmdList = &pMac->sme.smeCmdPendingList;
7596 else
7597 pCmdList = &pMac->sme.smeScanCmdPendingList;
Jeff Johnson295189b2012-06-20 16:38:30 -07007598
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307599 csrLLLock(pCmdList);
7600 pEntry = csrLLPeekHead(pCmdList, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007601 while(pEntry)
7602 {
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307603 pEntryTmp = csrLLNext(pCmdList, pEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007604 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7605 if( eSmeCommandScan == pCommand->command )
7606 {
7607 switch( pCommand->u.scanCmd.reason )
7608 {
7609 case eCsrScanIdleScan:
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307610 if( csrLLRemoveEntry(pCmdList, pEntry, LL_ACCESS_NOLOCK) )
Jeff Johnson295189b2012-06-20 16:38:30 -07007611 {
7612 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
7613 }
7614 fRet = eANI_BOOLEAN_TRUE;
7615 break;
7616
7617 default:
7618 break;
7619 } //switch
7620 }
7621 pEntry = pEntryTmp;
7622 }
7623
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307624 csrLLUnlock(pCmdList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007625
7626 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
7627 {
7628 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7629 csrReleaseCommandScan( pMac, pCommand );
7630 }
7631
7632 csrLLClose(&localList);
7633
7634 return (fRet);
7635}
7636
7637
7638tANI_BOOLEAN csrScanRemoveFreshScanCommand(tpAniSirGlobal pMac, tANI_U8 sessionId)
7639{
7640 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
7641 tListElem *pEntry, *pEntryTmp;
7642 tSmeCmd *pCommand;
7643 tDblLinkList localList;
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307644 tDblLinkList *pCmdList;
Jeff Johnson295189b2012-06-20 16:38:30 -07007645
7646 vos_mem_zero(&localList, sizeof(tDblLinkList));
7647 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
7648 {
7649 smsLog(pMac, LOGE, FL(" failed to open list"));
7650 return fRet;
7651 }
7652
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307653 if (!pMac->fScanOffload)
7654 pCmdList = &pMac->sme.smeCmdPendingList;
7655 else
7656 pCmdList = &pMac->sme.smeScanCmdPendingList;
7657
7658 csrLLLock(pCmdList);
7659 pEntry = csrLLPeekHead(pCmdList, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007660 while(pEntry)
7661 {
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307662 pEntryTmp = csrLLNext(pCmdList, pEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007663 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7664 if( (eSmeCommandScan == pCommand->command) && (sessionId == pCommand->sessionId) )
7665 {
7666 switch(pCommand->u.scanCmd.reason)
7667 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07007668#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
7669 case eCsrScanGetLfrResult:
7670#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07007671 case eCsrScanGetResult:
7672 case eCsrScanSetBGScanParam:
7673 case eCsrScanBGScanAbort:
7674 case eCsrScanBGScanEnable:
7675 case eCsrScanGetScanChnInfo:
7676 break;
7677 default:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007678 smsLog (pMac, LOGW, "%s: -------- abort scan command reason = %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007679 __func__, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07007680 //The rest are fresh scan requests
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307681 if( csrLLRemoveEntry(pCmdList, pEntry, LL_ACCESS_NOLOCK) )
Jeff Johnson295189b2012-06-20 16:38:30 -07007682 {
7683 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
7684 }
7685 fRet = eANI_BOOLEAN_TRUE;
7686 break;
7687 }
7688 }
7689 pEntry = pEntryTmp;
7690 }
7691
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307692 csrLLUnlock(pCmdList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007693
7694 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
7695 {
7696 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7697 if (pCommand->u.scanCmd.callback)
7698 {
7699 /* User scan request is pending,
7700 * send response with status eCSR_SCAN_ABORT*/
7701 pCommand->u.scanCmd.callback(pMac,
7702 pCommand->u.scanCmd.pContext,
7703 pCommand->u.scanCmd.scanID,
7704 eCSR_SCAN_ABORT);
7705 }
7706 csrReleaseCommandScan( pMac, pCommand );
7707 }
7708 csrLLClose(&localList);
7709
7710 return (fRet);
7711}
7712
7713
7714void csrReleaseScanCommand(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
7715{
7716 eCsrScanReason reason = pCommand->u.scanCmd.reason;
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307717 tANI_BOOLEAN status;
7718
7719 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07007720 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307721 tANI_U32 i;
7722 for(i = 0; i < CSR_ROAM_SESSION_MAX; i++)
Abhishek Singhf52182c2016-08-24 11:15:23 +05307723 csrRoamStateChange(pMac,
7724 pMac->roam.prev_state[i], i);
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307725 }
7726 else
7727 {
7728 csrRoamStateChange(pMac,
Abhishek Singhf52182c2016-08-24 11:15:23 +05307729 pMac->roam.prev_state[pCommand->sessionId],
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307730 pCommand->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07007731 }
7732
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307733 csrScanCallCallback(pMac, pCommand, scanStatus);
Jeff Johnson295189b2012-06-20 16:38:30 -07007734
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007735 smsLog(pMac, LOG3, " Remove Scan command reason = %d", reason);
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307736 if (pMac->fScanOffload)
7737 {
7738 status = csrLLRemoveEntry(&pMac->sme.smeScanCmdActiveList,
7739 &pCommand->Link, LL_ACCESS_LOCK);
7740 }
7741 else
7742 {
7743 status = csrLLRemoveEntry(&pMac->sme.smeCmdActiveList,
7744 &pCommand->Link, LL_ACCESS_LOCK);
7745 }
7746
7747 if(status)
Jeff Johnson295189b2012-06-20 16:38:30 -07007748 {
7749 csrReleaseCommandScan( pMac, pCommand );
7750 }
7751 else
7752 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307753 smsLog(pMac, LOGE,
7754 " ********csrReleaseScanCommand cannot release command reason %d",
7755 pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07007756 }
7757}
7758
7759
7760eHalStatus csrScanGetPMKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
7761 tPmkidCandidateInfo *pPmkidList, tANI_U32 *pNumItems )
7762{
7763 eHalStatus status = eHAL_STATUS_SUCCESS;
7764 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
7765
Jeff Johnson32d95a32012-09-10 13:15:23 -07007766 if(!pSession)
7767 {
7768 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
7769 return eHAL_STATUS_FAILURE;
7770 }
7771
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007772 smsLog(pMac, LOGW, " pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07007773 csrResetPMKIDCandidateList(pMac, sessionId);
7774 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
7775 {
7776 tCsrScanResultFilter *pScanFilter;
7777 tCsrScanResultInfo *pScanResult;
7778 tScanResultHandle hBSSList;
7779 tANI_U32 nItems = *pNumItems;
7780
7781 *pNumItems = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05307782 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
7783 if ( NULL == pScanFilter )
7784 status = eHAL_STATUS_FAILURE;
7785 else
Jeff Johnson295189b2012-06-20 16:38:30 -07007786 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307787 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007788 //Here is the profile we need to connect to
7789 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
7790 if(HAL_STATUS_SUCCESS(status))
7791 {
7792 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
7793 if(HAL_STATUS_SUCCESS(status))
7794 {
7795 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumPmkidCandidate < nItems))
7796 {
7797 //NumPmkidCandidate adds up here
7798 csrProcessBSSDescForPMKIDList(pMac, &pScanResult->BssDescriptor,
7799 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
7800 }
7801 if(pSession->NumPmkidCandidate)
7802 {
7803 *pNumItems = pSession->NumPmkidCandidate;
Kiet Lam64c1b492013-07-12 13:56:44 +05307804 vos_mem_copy(pPmkidList, pSession->PmkidCandidateInfo,
7805 pSession->NumPmkidCandidate * sizeof(tPmkidCandidateInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07007806 }
7807 csrScanResultPurge(pMac, hBSSList);
7808 }//Have scan result
7809 csrFreeScanFilter(pMac, pScanFilter);
7810 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307811 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07007812 }
7813 }
7814
7815 return (status);
7816}
7817
7818
7819
7820#ifdef FEATURE_WLAN_WAPI
7821eHalStatus csrScanGetBKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
7822 tBkidCandidateInfo *pBkidList, tANI_U32 *pNumItems )
7823{
7824 eHalStatus status = eHAL_STATUS_SUCCESS;
7825 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
7826
Jeff Johnson32d95a32012-09-10 13:15:23 -07007827 if(!pSession)
7828 {
7829 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
7830 return eHAL_STATUS_FAILURE;
7831 }
7832
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007833 smsLog(pMac, LOGW, " pMac->scan.NumBkidCandidate = %d", pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07007834 csrResetBKIDCandidateList(pMac, sessionId);
7835 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
7836 {
7837 tCsrScanResultFilter *pScanFilter;
7838 tCsrScanResultInfo *pScanResult;
7839 tScanResultHandle hBSSList;
7840 tANI_U32 nItems = *pNumItems;
7841 *pNumItems = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05307842 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
7843 if ( NULL == pScanFilter )
7844 status = eHAL_STATUS_FAILURE;
7845 else
Jeff Johnson295189b2012-06-20 16:38:30 -07007846 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307847 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007848 //Here is the profile we need to connect to
7849 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
7850 if(HAL_STATUS_SUCCESS(status))
7851 {
7852 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
7853 if(HAL_STATUS_SUCCESS(status))
7854 {
7855 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumBkidCandidate < nItems))
7856 {
7857 //pMac->scan.NumBkidCandidate adds up here
7858 csrProcessBSSDescForBKIDList(pMac, &pScanResult->BssDescriptor,
7859 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
7860
7861 }
7862 if(pSession->NumBkidCandidate)
7863 {
7864 *pNumItems = pSession->NumBkidCandidate;
Kiet Lam64c1b492013-07-12 13:56:44 +05307865 vos_mem_copy(pBkidList, pSession->BkidCandidateInfo, pSession->NumBkidCandidate * sizeof(tBkidCandidateInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07007866 }
7867 csrScanResultPurge(pMac, hBSSList);
7868 }//Have scan result
7869 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307870 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07007871 }
7872 }
7873
7874 return (status);
7875}
7876#endif /* FEATURE_WLAN_WAPI */
7877
Selvaraj, Sridhar32417ed2016-06-22 15:19:12 +05307878/**
7879 * csr_scan_request_set_chan_time() - Populate max and min
7880 * channel time in Scan request
7881 * @pMac - pointer to mac context
7882 * @pScanCmd - pointer to the Scan command
7883 *
7884 * Return - None
7885 */
7886#ifndef QCA_WIFI_ISOC
7887static void csr_scan_request_set_chan_time(tpAniSirGlobal pMac,
7888 tSmeCmd *pScanCmd)
7889{
7890 if (pMac->roam.neighborRoamInfo.handoffReqInfo.src
7891 == FASTREASSOC) {
7892 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime
7893 = MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL_FASTREASSOC;
7894 pScanCmd->u.scanCmd.u.scanRequest.minChnTime
7895 = MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL_FASTREASSOC;
7896 pMac->roam.neighborRoamInfo.handoffReqInfo.src = 0;
7897 } else {
7898 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime
7899 = MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7900 pScanCmd->u.scanCmd.u.scanRequest.minChnTime
7901 = MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7902 }
7903}
7904#else
7905static void csr_scan_request_set_chan_time(tpAniSirGlobal pMac,
7906 tSmeCmd *pScanCmd)
7907{
7908 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime
7909 = MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7910 pScanCmd->u.scanCmd.u.scanRequest.minChnTime
7911 = MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7912}
7913#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07007914
Kapil Guptac46b7542016-10-25 13:03:20 +05307915/**
7916 * csr_ssid_scan_done_callback() - Callback to indicate
7917 * scan is done for ssid scan
7918 * @halHandle: handle to hal
7919 * @context: SSID scan context
7920 * @scanId: Scan id for the scheduled scan
7921 * @status: scan done status
7922 *
7923 * Return - eHalStatus
7924 */
7925static eHalStatus csr_ssid_scan_done_callback(tHalHandle halHandle,
7926 void *context,
7927 tANI_U32 scanId,
7928 eCsrScanStatus status)
7929{
7930 struct csr_scan_for_ssid_context *scan_context =
7931 (struct csr_scan_for_ssid_context *)context;
7932
Sreelakshmi Konamki5e329602016-11-21 12:02:44 +05307933 if (NULL == scan_context) {
Kapil Guptac46b7542016-10-25 13:03:20 +05307934 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR,
7935 FL("scan for ssid context not found"));
Sreelakshmi Konamki5e329602016-11-21 12:02:44 +05307936 return eHAL_STATUS_FAILURE;
7937 }
Kapil Guptac46b7542016-10-25 13:03:20 +05307938
7939 if (eCSR_SCAN_ABORT == status)
7940 csrRoamCallCallback(scan_context->pMac, scan_context->sessionId,
7941 NULL, scan_context->roamId,
7942 eCSR_ROAM_ASSOCIATION_FAILURE,
7943 eCSR_ROAM_RESULT_SCAN_FOR_SSID_FAILURE);
7944 vos_mem_free(scan_context);
7945 return eHAL_STATUS_SUCCESS;
7946}
7947
Jeff Johnson295189b2012-06-20 16:38:30 -07007948//This function is usually used for BSSs that suppresses SSID so the profile
7949//shall have one and only one SSID
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007950eHalStatus csrScanForSSID(tpAniSirGlobal pMac, tANI_U32 sessionId, tCsrRoamProfile *pProfile, tANI_U32 roamId, tANI_BOOLEAN notify)
Jeff Johnson295189b2012-06-20 16:38:30 -07007951{
7952 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
7953 tSmeCmd *pScanCmd = NULL;
7954 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
7955 tANI_U8 index = 0;
7956 tANI_U32 numSsid = pProfile->SSIDs.numOfSSIDs;
Kapil Guptac46b7542016-10-25 13:03:20 +05307957 struct csr_scan_for_ssid_context *context;
Jeff Johnson295189b2012-06-20 16:38:30 -07007958
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007959 smsLog(pMac, LOG2, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007960 //For WDS, we use the index 0. There must be at least one in there
7961 if( CSR_IS_WDS_STA( pProfile ) && numSsid )
7962 {
7963 numSsid = 1;
7964 }
7965 if(pMac->scan.fScanEnable && ( numSsid == 1 ) )
7966 {
7967 do
7968 {
7969 pScanCmd = csrGetCommandBuffer(pMac);
7970 if(!pScanCmd)
7971 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007972 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007973 break;
7974 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307975 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
7976 pScanCmd->u.scanCmd.pToRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
7977 if ( NULL == pScanCmd->u.scanCmd.pToRoamProfile )
krunal soni587bf012014-02-04 12:35:11 -08007978 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307979 status = eHAL_STATUS_FAILURE;
krunal soni587bf012014-02-04 12:35:11 -08007980 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307981 else
krunal soni587bf012014-02-04 12:35:11 -08007982 {
7983 status = csrRoamCopyProfile(pMac, pScanCmd->u.scanCmd.pToRoamProfile, pProfile);
7984 }
Kapil Guptac46b7542016-10-25 13:03:20 +05307985 context = vos_mem_malloc(sizeof(*context));
7986 if (NULL == context)
7987 {
7988 smsLog(pMac, LOGE,
7989 "Failed to allocate memory for ssid scan context");
7990 status = eHAL_STATUS_FAILED_ALLOC;
7991 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007992 if(!HAL_STATUS_SUCCESS(status))
7993 break;
Kapil Guptac46b7542016-10-25 13:03:20 +05307994 context->pMac = pMac;
7995 context->sessionId = sessionId;
7996 context->roamId = roamId;
Jeff Johnson295189b2012-06-20 16:38:30 -07007997 pScanCmd->u.scanCmd.roamId = roamId;
7998 pScanCmd->command = eSmeCommandScan;
Jeff Johnsone7245742012-09-05 17:12:55 -07007999 pScanCmd->sessionId = (tANI_U8)sessionId;
Kapil Guptac46b7542016-10-25 13:03:20 +05308000 pScanCmd->u.scanCmd.callback = csr_ssid_scan_done_callback;
8001 pScanCmd->u.scanCmd.pContext = context;
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008002 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 -07008003 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Kiet Lam64c1b492013-07-12 13:56:44 +05308004 vos_mem_set(&pScanCmd->u.scanCmd.u.scanRequest, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008005 pScanCmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Jeff Johnson295189b2012-06-20 16:38:30 -07008006 pScanCmd->u.scanCmd.u.scanRequest.BSSType = pProfile->BSSType;
Jeff Johnsone7245742012-09-05 17:12:55 -07008007 // To avoid 11b rate in probe request Set p2pSearch flag as 1 for P2P Client Mode
8008 if(VOS_P2P_CLIENT_MODE == pProfile->csrPersona)
8009 {
8010 pScanCmd->u.scanCmd.u.scanRequest.p2pSearch = 1;
8011 }
Agarwal Ashish4f616132013-12-30 23:32:50 +05308012 if(pProfile->nAddIEScanLength)
Jeff Johnsone7245742012-09-05 17:12:55 -07008013 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308014 pScanCmd->u.scanCmd.u.scanRequest.pIEField = vos_mem_malloc(
8015 pProfile->nAddIEScanLength);
8016 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.pIEField )
8017 status = eHAL_STATUS_FAILURE;
8018 else
8019 status = eHAL_STATUS_SUCCESS;
8020 vos_mem_set(pScanCmd->u.scanCmd.u.scanRequest.pIEField,
8021 pProfile->nAddIEScanLength, 0);
8022 if (HAL_STATUS_SUCCESS(status))
Jeff Johnsone7245742012-09-05 17:12:55 -07008023 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308024 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.pIEField,
Agarwal Ashish4f616132013-12-30 23:32:50 +05308025 pProfile->addIEScan, pProfile->nAddIEScanLength);
Jeff Johnsone7245742012-09-05 17:12:55 -07008026 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = pProfile->nAddIEScanLength;
8027 }
8028 else
8029 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008030 smsLog(pMac, LOGE, "No memory for scanning IE fields");
Jeff Johnsone7245742012-09-05 17:12:55 -07008031 }
8032 } //Allocate memory for IE field
8033 else
8034 {
8035 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = 0;
8036 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07008037 /* For one channel be good enpugh time to receive beacon atleast */
8038 if( 1 == pProfile->ChannelInfo.numOfChannels )
8039 {
Selvaraj, Sridhar32417ed2016-06-22 15:19:12 +05308040 csr_scan_request_set_chan_time(pMac, pScanCmd);
8041 } else {
Kiet Lam64c1b492013-07-12 13:56:44 +05308042 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime =
8043 pMac->roam.configParam.nActiveMaxChnTime;
8044 pScanCmd->u.scanCmd.u.scanRequest.minChnTime =
8045 pMac->roam.configParam.nActiveMinChnTime;
Jeff Johnson32d95a32012-09-10 13:15:23 -07008046 }
Abhishek Singhadd13582016-09-29 17:00:03 +05308047 pScanCmd->u.scanCmd.u.scanRequest.max_chntime_btc_esco =
8048 pMac->roam.configParam.max_chntime_btc_esco;
8049 pScanCmd->u.scanCmd.u.scanRequest.min_chntime_btc_esco =
8050 pMac->roam.configParam.min_chntime_btc_esco;
Jeff Johnson295189b2012-06-20 16:38:30 -07008051 if(pProfile->BSSIDs.numOfBSSIDs == 1)
8052 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308053 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.bssid,
8054 pProfile->BSSIDs.bssid, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07008055 }
8056 else
8057 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308058 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.bssid, bAddr, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07008059 }
8060 if(pProfile->ChannelInfo.numOfChannels)
8061 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308062 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(
8063 sizeof(*pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
8064 * pProfile->ChannelInfo.numOfChannels);
8065 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
8066 status = eHAL_STATUS_FAILURE;
8067 else
8068 status = eHAL_STATUS_SUCCESS;
8069 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
8070 if(HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07008071 {
8072 csrRoamIsChannelValid(pMac, pProfile->ChannelInfo.ChannelList[0]);
8073 for(index = 0; index < pProfile->ChannelInfo.numOfChannels; index++)
8074 {
8075 if(csrRoamIsValidChannel(pMac, pProfile->ChannelInfo.ChannelList[index]))
8076 {
8077 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels]
8078 = pProfile->ChannelInfo.ChannelList[index];
8079 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels++;
8080 }
8081 else
8082 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008083 smsLog(pMac, LOGW, FL("process a channel (%d) that is invalid"), pProfile->ChannelInfo.ChannelList[index]);
Jeff Johnson295189b2012-06-20 16:38:30 -07008084 }
8085
8086 }
8087 }
8088 else
8089 {
8090 break;
8091 }
8092
8093 }
8094 else
8095 {
8096 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
8097 }
8098 if(pProfile->SSIDs.numOfSSIDs)
8099 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308100 pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList = vos_mem_malloc(
8101 pProfile->SSIDs.numOfSSIDs * sizeof(tCsrSSIDInfo));
8102 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList )
8103 status = eHAL_STATUS_FAILURE;
8104 else
8105 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07008106 if(!HAL_STATUS_SUCCESS(status))
8107 {
8108 break;
8109 }
8110 pScanCmd->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 1;
Kiet Lam64c1b492013-07-12 13:56:44 +05308111 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList,
8112 pProfile->SSIDs.SSIDList, sizeof(tCsrSSIDInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07008113 }
8114 //Start process the command
8115 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
8116 if( !HAL_STATUS_SUCCESS( status ) )
8117 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008118 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07008119 break;
8120 }
8121 }while(0);
8122 if(!HAL_STATUS_SUCCESS(status))
8123 {
8124 if(pScanCmd)
8125 {
8126 csrReleaseCommandScan(pMac, pScanCmd);
8127 //TODO:free the memory that is allocated in this function
8128 }
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008129 if(notify)
8130 {
Jeff Johnson295189b2012-06-20 16:38:30 -07008131 csrRoamCallCallback(pMac, sessionId, NULL, roamId, eCSR_ROAM_FAILED, eCSR_ROAM_RESULT_FAILURE);
8132 }
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008133 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008134 }//valid
8135 else
8136 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008137 smsLog(pMac, LOGE, FL("cannot scan because scanEnable (%d) or numSSID (%d) is invalid"),
Jeff Johnson295189b2012-06-20 16:38:30 -07008138 pMac->scan.fScanEnable, pProfile->SSIDs.numOfSSIDs);
8139 }
8140
8141 return (status);
8142}
8143
8144
8145//Issue a scan base on the new capability infomation
8146//This should only happen when the associated AP changes its capability.
8147//After this scan is done, CSR reroams base on the new scan results
8148eHalStatus csrScanForCapabilityChange(tpAniSirGlobal pMac, tSirSmeApNewCaps *pNewCaps)
8149{
8150 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
8151 tSmeCmd *pScanCmd = NULL;
8152
8153 if(pNewCaps)
8154 {
8155 do
8156 {
8157 pScanCmd = csrGetCommandBuffer(pMac);
8158 if(!pScanCmd)
8159 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008160 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07008161 status = eHAL_STATUS_RESOURCES;
8162 break;
8163 }
Kiet Lam64c1b492013-07-12 13:56:44 +05308164 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008165 status = eHAL_STATUS_SUCCESS;
8166 pScanCmd->u.scanCmd.roamId = 0;
8167 pScanCmd->command = eSmeCommandScan;
8168 pScanCmd->u.scanCmd.callback = NULL;
8169 pScanCmd->u.scanCmd.pContext = NULL;
8170 pScanCmd->u.scanCmd.reason = eCsrScanForCapsChange;
8171 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
8172 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
8173 if( !HAL_STATUS_SUCCESS( status ) )
8174 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008175 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07008176 break;
8177 }
8178 }while(0);
8179 if(!HAL_STATUS_SUCCESS(status))
8180 {
8181 if(pScanCmd)
8182 {
8183 csrReleaseCommandScan(pMac, pScanCmd);
8184 }
8185 }
8186 }
8187
8188 return (status);
8189}
8190
8191
8192
8193void csrInitBGScanChannelList(tpAniSirGlobal pMac)
8194{
8195 tANI_U32 len = CSR_MIN(sizeof(pMac->roam.validChannelList), sizeof(pMac->scan.bgScanChannelList));
8196
Kiet Lam64c1b492013-07-12 13:56:44 +05308197 vos_mem_set(pMac->scan.bgScanChannelList, len, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008198 pMac->scan.numBGScanChannel = 0;
8199
8200 if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
8201 {
8202 pMac->roam.numValidChannels = len;
8203 pMac->scan.numBGScanChannel = (tANI_U8)CSR_MIN(len, WNI_CFG_BG_SCAN_CHANNEL_LIST_LEN);
Kiet Lam64c1b492013-07-12 13:56:44 +05308204 vos_mem_copy(pMac->scan.bgScanChannelList, pMac->roam.validChannelList,
8205 pMac->scan.numBGScanChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07008206 csrSetBGScanChannelList(pMac, pMac->scan.bgScanChannelList, pMac->scan.numBGScanChannel);
8207 }
8208}
8209
8210
8211//This function return TRUE if background scan channel list is adjusted.
8212//this function will only shrink the background scan channel list
8213tANI_BOOLEAN csrAdjustBGScanChannelList(tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels,
8214 tANI_U8 *pAdjustChannels, tANI_U8 *pNumAdjustChannels)
8215{
8216 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
8217 tANI_U8 i, j, count = *pNumAdjustChannels;
8218
8219 i = 0;
8220 while(i < count)
8221 {
8222 for(j = 0; j < NumChannels; j++)
8223 {
8224 if(pChannelList[j] == pAdjustChannels[i])
8225 break;
8226 }
8227 if(j == NumChannels)
8228 {
8229 //This channel is not in the list, remove it
8230 fRet = eANI_BOOLEAN_TRUE;
8231 count--;
8232 if(count - i)
8233 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308234 vos_mem_copy(&pAdjustChannels[i], &pAdjustChannels[i+1], count - i);
Jeff Johnson295189b2012-06-20 16:38:30 -07008235 }
8236 else
8237 {
8238 //already remove the last one. Done.
8239 break;
8240 }
8241 }
8242 else
8243 {
8244 i++;
8245 }
8246 }//while(i<count)
8247 *pNumAdjustChannels = count;
8248
8249 return (fRet);
8250}
8251
8252
8253//Get the list of the base channels to scan for passively 11d info
8254eHalStatus csrScanGetSupportedChannels( tpAniSirGlobal pMac )
8255{
8256 eHalStatus status = eHAL_STATUS_SUCCESS;
8257 int n = WNI_CFG_VALID_CHANNEL_LIST_LEN;
8258
8259 status = vos_nv_getSupportedChannels( pMac->scan.baseChannels.channelList, &n, NULL, NULL );
8260 if( HAL_STATUS_SUCCESS(status) )
8261 {
8262 pMac->scan.baseChannels.numChannels = (tANI_U8)n;
8263 }
8264 else
8265 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008266 smsLog( pMac, LOGE, FL(" failed") );
Jeff Johnson295189b2012-06-20 16:38:30 -07008267 pMac->scan.baseChannels.numChannels = 0;
8268 }
8269
8270 return ( status );
8271}
8272
8273//This function use the input pChannelList to validate the current saved channel list
8274eHalStatus csrSetBGScanChannelList( tpAniSirGlobal pMac, tANI_U8 *pAdjustChannels, tANI_U8 NumAdjustChannels)
8275{
8276 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumAdjustChannels;
8277
8278 return (ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pAdjustChannels, dataLen, NULL, eANI_BOOLEAN_FALSE));
8279}
8280
8281
8282void csrSetCfgValidChannelList( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels )
8283{
8284 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumChannels;
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05308285 eHalStatus status;
Jeff Johnson295189b2012-06-20 16:38:30 -07008286
Mihir Shete31c435d2014-02-12 13:13:34 +05308287 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
8288 "%s: dump valid channel list(NumChannels(%d))",
8289 __func__,NumChannels);
8290 VOS_TRACE_HEX_DUMP(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
8291 pChannelList, NumChannels);
8292
Jeff Johnson295189b2012-06-20 16:38:30 -07008293 ccmCfgSetStr(pMac, WNI_CFG_VALID_CHANNEL_LIST, pChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
Leela Venkata Kiran Kumar Reddy Chiralac6663f72014-02-03 21:04:58 -08008294#ifdef QCA_WIFI_2_0
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05308295 if (pMac->fScanOffload)
8296 {
8297 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
8298 "Scan offload is enabled, update default chan list");
Leela Venkata Kiran Kumar Reddy Chiralac6663f72014-02-03 21:04:58 -08008299 status = csrUpdateChannelList(pMac);
8300 }
8301#else
8302 status = csrUpdateChannelList(pMac);
8303#endif
8304
8305 if (eHAL_STATUS_SUCCESS != status)
8306 {
8307 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR,
8308 "failed to update the supported channel list");
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05308309 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008310 return;
8311}
8312
8313
8314
8315/*
8316 * The Tx power limits are saved in the cfg for future usage.
8317 */
8318void csrSaveTxPowerToCfg( tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 cfgId )
8319{
8320 tListElem *pEntry;
8321 tANI_U32 cbLen = 0, dataLen;
8322 tCsrChannelPowerInfo *pChannelSet;
8323 tANI_U32 idx;
8324 tSirMacChanInfo *pChannelPowerSet;
8325 tANI_U8 *pBuf = NULL;
8326
8327 //allocate maximum space for all channels
8328 dataLen = WNI_CFG_VALID_CHANNEL_LIST_LEN * sizeof(tSirMacChanInfo);
Kiet Lam64c1b492013-07-12 13:56:44 +05308329 if ( (pBuf = vos_mem_malloc(dataLen)) != NULL )
Jeff Johnson295189b2012-06-20 16:38:30 -07008330 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308331 vos_mem_set(pBuf, dataLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008332 pChannelPowerSet = (tSirMacChanInfo *)(pBuf);
8333
8334 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
8335 // write the tuples (startChan, numChan, txPower) for each channel found in the channel power list.
8336 while( pEntry )
8337 {
8338 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
8339 if ( 1 != pChannelSet->interChannelOffset )
8340 {
8341 // we keep the 5G channel sets internally with an interchannel offset of 4. Expand these
8342 // to the right format... (inter channel offset of 1 is the only option for the triplets
8343 // that 11d advertises.
8344 if ((cbLen + (pChannelSet->numChannels * sizeof(tSirMacChanInfo))) >= dataLen)
8345 {
8346 // expanding this entry will overflow our allocation
8347 smsLog(pMac, LOGE,
8348 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07008349 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07008350 pChannelSet->firstChannel,
8351 pChannelSet->numChannels,
8352 pChannelSet->interChannelOffset);
8353 break;
8354 }
8355
8356 for( idx = 0; idx < pChannelSet->numChannels; idx++ )
8357 {
8358 pChannelPowerSet->firstChanNum = (tSirMacChanNum)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008359 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07008360 pChannelPowerSet->numChannels = 1;
Jeff Johnson295189b2012-06-20 16:38:30 -07008361 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008362 smsLog(pMac, LOG3, " Setting Max Transmit Power %d", pChannelPowerSet->maxTxPower);
Jeff Johnson295189b2012-06-20 16:38:30 -07008363 cbLen += sizeof( tSirMacChanInfo );
8364 pChannelPowerSet++;
8365 }
8366 }
8367 else
8368 {
8369 if (cbLen >= dataLen)
8370 {
8371 // this entry will overflow our allocation
8372 smsLog(pMac, LOGE,
8373 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07008374 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07008375 pChannelSet->firstChannel,
8376 pChannelSet->numChannels,
8377 pChannelSet->interChannelOffset);
8378 break;
8379 }
8380 pChannelPowerSet->firstChanNum = pChannelSet->firstChannel;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008381 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07008382 pChannelPowerSet->numChannels = pChannelSet->numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -07008383 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008384 smsLog(pMac, LOG3, " Setting Max Transmit Power %d, nTxPower %d", pChannelPowerSet->maxTxPower,pMac->roam.configParam.nTxPowerCap );
Jeff Johnson295189b2012-06-20 16:38:30 -07008385
8386
8387 cbLen += sizeof( tSirMacChanInfo );
8388 pChannelPowerSet++;
8389 }
8390
8391 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
8392 }
8393
8394 if(cbLen)
8395 {
8396 ccmCfgSetStr(pMac, cfgId, (tANI_U8 *)pBuf, cbLen, NULL, eANI_BOOLEAN_FALSE);
8397 }
Kiet Lam64c1b492013-07-12 13:56:44 +05308398 vos_mem_free(pBuf);
Jeff Johnson295189b2012-06-20 16:38:30 -07008399 }//Allocate memory
8400}
8401
8402
8403void csrSetCfgCountryCode( tpAniSirGlobal pMac, tANI_U8 *countryCode )
8404{
8405 tANI_U8 cc[WNI_CFG_COUNTRY_CODE_LEN];
8406 ///v_REGDOMAIN_t DomainId;
8407
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008408 smsLog( pMac, LOG3, "Setting Country Code in Cfg from csrSetCfgCountryCode %s",countryCode );
Kiet Lam64c1b492013-07-12 13:56:44 +05308409 vos_mem_copy(cc, countryCode, WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07008410
8411 // don't program the bogus country codes that we created for Korea in the MAC. if we see
8412 // the bogus country codes, program the MAC with the right country code.
8413 if ( ( 'K' == countryCode[ 0 ] && '1' == countryCode[ 1 ] ) ||
8414 ( 'K' == countryCode[ 0 ] && '2' == countryCode[ 1 ] ) ||
8415 ( 'K' == countryCode[ 0 ] && '3' == countryCode[ 1 ] ) ||
8416 ( 'K' == countryCode[ 0 ] && '4' == countryCode[ 1 ] ) )
8417 {
8418 // replace the alternate Korea country codes, 'K1', 'K2', .. with 'KR' for Korea
8419 cc[ 1 ] = 'R';
8420 }
8421 ccmCfgSetStr(pMac, WNI_CFG_COUNTRY_CODE, cc, WNI_CFG_COUNTRY_CODE_LEN, NULL, eANI_BOOLEAN_FALSE);
8422
8423 //Need to let HALPHY know about the current domain so it can apply some
8424 //domain-specific settings (TX filter...)
8425 /*if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(pMac, cc, &DomainId)))
8426 {
8427 halPhySetRegDomain(pMac, DomainId);
8428 }*/
8429}
8430
8431
8432
8433eHalStatus csrGetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pBuf, tANI_U8 *pbLen)
8434{
8435 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
8436 tANI_U32 len;
8437
8438 if(pBuf && pbLen && (*pbLen >= WNI_CFG_COUNTRY_CODE_LEN))
8439 {
8440 len = *pbLen;
8441 status = ccmCfgGetStr(pMac, WNI_CFG_COUNTRY_CODE, pBuf, &len);
8442 if(HAL_STATUS_SUCCESS(status))
8443 {
8444 *pbLen = (tANI_U8)len;
8445 }
8446 }
8447
8448 return (status);
8449}
8450
8451
8452void csrSetCfgScanControlList( tpAniSirGlobal pMac, tANI_U8 *countryCode, tCsrChannel *pChannelList )
8453{
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05308454 tANI_U8 i, j, k;
Jeff Johnson295189b2012-06-20 16:38:30 -07008455 tANI_BOOLEAN found=FALSE;
8456 tANI_U8 *pControlList = NULL;
8457 tANI_U32 len = WNI_CFG_SCAN_CONTROL_LIST_LEN;
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05308458 tANI_U8 cfgActiveDFSChannels = 0;
8459 tANI_U8 *cfgActiveDFSChannelLIst = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07008460
Kiet Lam64c1b492013-07-12 13:56:44 +05308461 if ( (pControlList = vos_mem_malloc(WNI_CFG_SCAN_CONTROL_LIST_LEN)) != NULL )
Jeff Johnson295189b2012-06-20 16:38:30 -07008462 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308463 vos_mem_set((void *)pControlList, WNI_CFG_SCAN_CONTROL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008464 if(HAL_STATUS_SUCCESS(ccmCfgGetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, &len)))
8465 {
8466 for (i = 0; i < pChannelList->numChannels; i++)
8467 {
8468 for (j = 0; j < len; j += 2)
8469 {
8470 if (pControlList[j] == pChannelList->channelList[i])
8471 {
8472 found = TRUE;
8473 break;
8474 }
8475 }
8476
8477 if (found) // insert a pair(channel#, flag)
8478 {
Gopichand Nakkala392cbc12013-05-28 16:15:00 +05308479 pControlList[j+1] = csrGetScanType(pMac, pControlList[j]);
Jeff Johnson295189b2012-06-20 16:38:30 -07008480 found = FALSE; // reset the flag
Jeff Johnson295189b2012-06-20 16:38:30 -07008481
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05308482 // When DFS mode is 2, mark static channels as active
8483 if (pMac->scan.fEnableDFSChnlScan ==
8484 DFS_CHNL_SCAN_ENABLED_ACTIVE)
8485 {
8486 cfgActiveDFSChannels =
8487 pMac->roam.neighborRoamInfo.cfgParams.
8488 channelInfo.numOfChannels;
8489 cfgActiveDFSChannelLIst =
8490 pMac->roam.neighborRoamInfo.cfgParams.
8491 channelInfo.ChannelList;
8492 if (cfgActiveDFSChannelLIst)
8493 {
8494 for (k=0; k < cfgActiveDFSChannels; k++)
8495 {
8496 if(CSR_IS_CHANNEL_DFS(cfgActiveDFSChannelLIst[k])
8497 && (pControlList[j] ==
8498 cfgActiveDFSChannelLIst[k]))
8499 {
8500 pControlList[j+1] = eSIR_ACTIVE_SCAN;
8501 smsLog(pMac, LOG1, FL("Marked DFS ch %d"
8502 " as active"),
8503 cfgActiveDFSChannelLIst[k]);
8504 }
8505 }
8506 }
8507 }
8508 }
8509 }
8510
8511 smsLog(pMac, LOG1, FL("fEnableDFSChnlScan %d"),
8512 pMac->scan.fEnableDFSChnlScan);
Mihir Shete31c435d2014-02-12 13:13:34 +05308513 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
8514 "%s: dump scan control list",__func__);
8515 VOS_TRACE_HEX_DUMP(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
8516 pControlList, len);
8517
Jeff Johnson295189b2012-06-20 16:38:30 -07008518 ccmCfgSetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, len, NULL, eANI_BOOLEAN_FALSE);
8519 }//Successfully getting scan control list
Kiet Lam64c1b492013-07-12 13:56:44 +05308520 vos_mem_free(pControlList);
Jeff Johnson295189b2012-06-20 16:38:30 -07008521 }//AllocateMemory
8522}
8523
Jeff Johnson295189b2012-06-20 16:38:30 -07008524//if bgPeriod is 0, background scan is disabled. It is in millisecond units
8525eHalStatus csrSetCfgBackgroundScanPeriod(tpAniSirGlobal pMac, tANI_U32 bgPeriod)
8526{
8527 return (ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, bgPeriod, (tCcmCfgSetCallback) csrScanCcmCfgSetCallback, eANI_BOOLEAN_FALSE));
8528}
8529
8530
8531void csrScanCcmCfgSetCallback(tHalHandle hHal, tANI_S32 result)
8532{
8533 tListElem *pEntry = NULL;
8534 tSmeCmd *pCommand = NULL;
8535 tpAniSirGlobal pMac = PMAC_STRUCT( hHal );
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05308536 tDblLinkList *pCmdList ;
8537
8538 if (!pMac->fScanOffload)
8539 pCmdList = &pMac->sme.smeCmdActiveList;
8540 else
8541 pCmdList = &pMac->sme.smeScanCmdActiveList;
8542
8543 pEntry = csrLLPeekHead( pCmdList, LL_ACCESS_LOCK );
Jeff Johnson295189b2012-06-20 16:38:30 -07008544 if ( pEntry )
8545 {
8546 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8547 if ( eSmeCommandScan == pCommand->command )
8548 {
8549 eCsrScanStatus scanStatus = (CCM_IS_RESULT_SUCCESS(result)) ? eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
8550 csrReleaseScanCommand(pMac, pCommand, scanStatus);
8551 }
8552 else
8553 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008554 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
Jeff Johnson295189b2012-06-20 16:38:30 -07008555 }
8556 }
8557 smeProcessPendingQueue( pMac );
8558}
8559
8560eHalStatus csrProcessSetBGScanParam(tpAniSirGlobal pMac, tSmeCmd *pCommand)
8561{
8562 eHalStatus status;
8563 tCsrBGScanRequest *pScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
8564 tANI_U32 dataLen = sizeof( tANI_U8 ) * pScanReq->ChannelInfo.numOfChannels;
8565
8566 //***setcfg for background scan channel list
8567 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MINIMUM_CHANNEL_TIME, pScanReq->minChnTime, NULL, eANI_BOOLEAN_FALSE);
8568 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MAXIMUM_CHANNEL_TIME, pScanReq->maxChnTime, NULL, eANI_BOOLEAN_FALSE);
8569 //Not set the background scan interval if not connected because bd scan should not be run if not connected
8570 if(!csrIsAllSessionDisconnected(pMac))
8571 {
Jeff Johnson295189b2012-06-20 16:38:30 -07008572
8573#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
8574 {
8575 vos_log_scan_pkt_type *pScanLog = NULL;
8576
8577 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
8578 if(pScanLog)
8579 {
8580 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
8581 pScanLog->minChnTime = (v_U8_t)pScanReq->minChnTime;
8582 pScanLog->maxChnTime = (v_U8_t)pScanReq->maxChnTime;
8583 pScanLog->timeBetweenBgScan = (v_U8_t)pScanReq->scanInterval;
8584 pScanLog->numChannel = pScanReq->ChannelInfo.numOfChannels;
8585 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
8586 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308587 vos_mem_copy(pScanLog->channels,
8588 pScanReq->ChannelInfo.ChannelList,
8589 pScanLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07008590 }
8591 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
8592 }
8593 }
8594#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
8595
8596 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, pScanReq->scanInterval, NULL, eANI_BOOLEAN_FALSE);
8597 }
8598 else
8599 {
8600 //No need to stop aging because IDLE scan is still running
8601 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, 0, NULL, eANI_BOOLEAN_FALSE);
8602 }
8603
8604 if(pScanReq->SSID.length > WNI_CFG_SSID_LEN)
8605 {
8606 pScanReq->SSID.length = WNI_CFG_SSID_LEN;
8607 }
8608
8609 status = ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pScanReq->ChannelInfo.ChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
8610 status = ccmCfgSetStr(pMac, WNI_CFG_SSID, (tANI_U8 *)pScanReq->SSID.ssId, pScanReq->SSID.length, NULL, eANI_BOOLEAN_FALSE);
8611
8612
8613
8614 return (status);
8615}
8616
8617
c_hpothua3d45d52015-01-05 14:11:17 +05308618tSirAbortScanStatus csrScanAbortMacScan(tpAniSirGlobal pMac,
8619 tANI_U8 sessionId,
8620 eCsrAbortReason reason)
Jeff Johnson295189b2012-06-20 16:38:30 -07008621{
c_hpothua3d45d52015-01-05 14:11:17 +05308622 tSirAbortScanStatus abortScanStatus = eSIR_ABORT_ACTIVE_SCAN_LIST_EMPTY;
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308623 tSirSmeScanAbortReq *pMsg;
Jeff Johnson295189b2012-06-20 16:38:30 -07008624 tANI_U16 msgLen;
8625 tListElem *pEntry;
8626 tSmeCmd *pCommand;
8627
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308628 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07008629 {
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308630#ifdef WLAN_AP_STA_CONCURRENCY
8631 csrLLLock(&pMac->scan.scanCmdPendingList);
8632 while(NULL !=
8633 (pEntry = csrLLRemoveHead(&pMac->scan.scanCmdPendingList,
8634 LL_ACCESS_NOLOCK)))
8635 {
Jeff Johnson295189b2012-06-20 16:38:30 -07008636
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308637 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8638 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
8639 }
8640 csrLLUnlock(&pMac->scan.scanCmdPendingList);
Jeff Johnson295189b2012-06-20 16:38:30 -07008641#endif
8642
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308643 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
8644 csrRemoveCmdFromPendingList( pMac, &pMac->roam.roamCmdPendingList, eSmeCommandScan);
8645 csrRemoveCmdFromPendingList( pMac, &pMac->sme.smeCmdPendingList, eSmeCommandScan);
8646 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
8647
8648 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
8649 }
8650 else
8651 {
8652 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
8653 csrRemoveCmdWithSessionIdFromPendingList(pMac,
8654 sessionId,
8655 &pMac->sme.smeScanCmdPendingList,
8656 eSmeCommandScan);
8657 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
8658
8659 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
8660 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008661
8662 //We need to abort scan only if we are scanning
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308663 if(NULL != pEntry)
Jeff Johnson295189b2012-06-20 16:38:30 -07008664 {
8665 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308666 if(eSmeCommandScan == pCommand->command &&
8667 pCommand->sessionId == sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07008668 {
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308669 msgLen = (tANI_U16)(sizeof(tSirSmeScanAbortReq));
Kiet Lam64c1b492013-07-12 13:56:44 +05308670 pMsg = vos_mem_malloc(msgLen);
8671 if ( NULL == pMsg )
Jeff Johnson295189b2012-06-20 16:38:30 -07008672 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308673 smsLog(pMac, LOGE, FL("Failed to allocate memory for SmeScanAbortReq"));
c_hpothua3d45d52015-01-05 14:11:17 +05308674 abortScanStatus = eSIR_ABORT_SCAN_FAILURE;
Kiet Lam64c1b492013-07-12 13:56:44 +05308675 }
8676 else
8677 {
Ratheesh S Pece1f832015-07-25 15:50:25 +05308678 pCommand->u.scanCmd.abortScanIndication = eCSR_SCAN_ABORT_DEFAULT;
Srinivas, Dasari187ca4e2014-02-07 12:40:09 +05308679 if(reason == eCSR_SCAN_ABORT_DUE_TO_BAND_CHANGE)
8680 {
Ratheesh S Pece1f832015-07-25 15:50:25 +05308681 pCommand->u.scanCmd.abortScanIndication
8682 = eCSR_SCAN_ABORT_DUE_TO_BAND_CHANGE;
Srinivas, Dasari187ca4e2014-02-07 12:40:09 +05308683 }
Kiet Lam64c1b492013-07-12 13:56:44 +05308684 vos_mem_set((void *)pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008685 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_ABORT_IND);
8686 pMsg->msgLen = pal_cpu_to_be16(msgLen);
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308687 pMsg->sessionId = sessionId;
c_hpothua3d45d52015-01-05 14:11:17 +05308688 if (eHAL_STATUS_SUCCESS != palSendMBMessage(pMac->hHdd, pMsg))
8689 {
8690 smsLog(pMac, LOGE,
8691 FL("Failed to post eWNI_SME_SCAN_ABORT_IND"));
8692 abortScanStatus = eSIR_ABORT_SCAN_FAILURE;
Ratheesh S Pece1f832015-07-25 15:50:25 +05308693 pCommand->u.scanCmd.abortScanIndication = 0;
c_hpothua3d45d52015-01-05 14:11:17 +05308694 }
8695 else
8696 {
8697 abortScanStatus = eSIR_ABORT_ACTIVE_SCAN_LIST_NOT_EMPTY;
8698 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008699 }
8700 }
8701 }
8702
c_hpothua3d45d52015-01-05 14:11:17 +05308703 return(abortScanStatus);
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308704}
8705
8706void csrRemoveCmdWithSessionIdFromPendingList(tpAniSirGlobal pMac,
8707 tANI_U8 sessionId,
8708 tDblLinkList *pList,
8709 eSmeCommandType commandType)
8710{
8711 tDblLinkList localList;
8712 tListElem *pEntry;
8713 tSmeCmd *pCommand;
8714 tListElem *pEntryToRemove;
8715
8716 vos_mem_zero(&localList, sizeof(tDblLinkList));
8717 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
8718 {
8719 smsLog(pMac, LOGE, FL(" failed to open list"));
8720 return;
8721 }
8722
8723 csrLLLock(pList);
8724 if ((pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK)))
8725 {
8726
8727 /* Have to make sure we don't loop back to the head of the list,
8728 * which will happen if the entry is NOT on the list */
8729 while (pEntry)
8730 {
8731 pEntryToRemove = pEntry;
8732 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
8733 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
8734 if ((pCommand->command == commandType) &&
8735 (pCommand->sessionId == sessionId))
8736 {
8737 /* Remove that entry only */
8738 if (csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
8739 {
8740 csrLLInsertTail(&localList, pEntryToRemove,
8741 LL_ACCESS_NOLOCK);
8742 }
8743 }
8744 }
8745 }
8746 csrLLUnlock(pList);
8747
8748 while ((pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)))
8749 {
8750 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
8751 csrAbortCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
8752 }
8753
8754 csrLLClose(&localList);
Jeff Johnson295189b2012-06-20 16:38:30 -07008755}
8756
8757void csrRemoveCmdFromPendingList(tpAniSirGlobal pMac, tDblLinkList *pList,
8758 eSmeCommandType commandType )
8759{
8760 tDblLinkList localList;
8761 tListElem *pEntry;
8762 tSmeCmd *pCommand;
8763 tListElem *pEntryToRemove;
8764
8765 vos_mem_zero(&localList, sizeof(tDblLinkList));
8766 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
8767 {
8768 smsLog(pMac, LOGE, FL(" failed to open list"));
8769 return;
8770 }
8771
8772 csrLLLock(pList);
8773 if( !csrLLIsListEmpty( pList, LL_ACCESS_NOLOCK ) )
8774 {
8775 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK);
8776
8777 // Have to make sure we don't loop back to the head of the list, which will
8778 // happen if the entry is NOT on the list...
8779 while( pEntry )
8780 {
8781 pEntryToRemove = pEntry;
8782 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
8783 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
8784 if ( pCommand->command == commandType )
8785 {
8786 // Remove that entry only
8787 if(csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
8788 {
8789 csrLLInsertTail(&localList, pEntryToRemove, LL_ACCESS_NOLOCK);
8790 }
8791 }
8792 }
8793
8794
8795 }
8796 csrLLUnlock(pList);
8797
8798 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
8799 {
8800 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8801 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
8802 }
8803 csrLLClose(&localList);
8804
8805}
8806
Abhishek Singhdc2bfd42014-06-19 17:59:05 +05308807eHalStatus csrScanAbortScanForSSID(tpAniSirGlobal pMac, tANI_U32 sessionId)
8808{
8809 eHalStatus status = eHAL_STATUS_SUCCESS;
8810 tSirSmeScanAbortReq *pMsg;
8811 tANI_U16 msgLen;
8812 tListElem *pEntry;
8813 tSmeCmd *pCommand;
8814
8815 if (!pMac->fScanOffload)
8816 {
8817 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
8818#ifdef WLAN_AP_STA_CONCURRENCY
8819 csrRemoveScanForSSIDFromPendingList( pMac, &pMac->scan.scanCmdPendingList, sessionId);
8820#endif
8821 csrRemoveScanForSSIDFromPendingList( pMac, &pMac->roam.roamCmdPendingList, sessionId);
8822 csrRemoveScanForSSIDFromPendingList( pMac, &pMac->sme.smeCmdPendingList, sessionId);
8823 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
8824 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
8825 }
8826 else
8827 {
8828 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
8829 csrRemoveScanForSSIDFromPendingList( pMac, &pMac->sme.smeScanCmdPendingList, sessionId);
8830 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
8831 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
8832 }
8833
8834 if(NULL != pEntry)
8835 {
8836 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8837
8838 if ( (eSmeCommandScan == pCommand->command ) &&
8839 (sessionId == pCommand->sessionId))
8840 {
8841 if ( eCsrScanForSsid == pCommand->u.scanCmd.reason)
8842 {
8843 msgLen = (tANI_U16)(sizeof( tSirSmeScanAbortReq ));
8844 pMsg = vos_mem_malloc(msgLen);
8845 if ( NULL == pMsg )
8846 {
8847 status = eHAL_STATUS_FAILURE;
8848 smsLog(pMac, LOGE, FL("Failed to allocate memory for SmeScanAbortReq"));
8849 }
8850 else
8851 {
8852 vos_mem_zero((void *)pMsg, msgLen);
8853 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_ABORT_IND);
8854 pMsg->msgLen = pal_cpu_to_be16(msgLen);
8855 pMsg->sessionId = sessionId;
8856 status = palSendMBMessage(pMac->hHdd, pMsg);
8857 }
8858 }
8859 }
8860 }
8861 return( status );
8862}
8863
8864void csrRemoveScanForSSIDFromPendingList(tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 sessionId)
8865{
8866 tDblLinkList localList;
8867 tListElem *pEntry;
8868 tSmeCmd *pCommand;
8869 tListElem *pEntryToRemove;
8870
8871 vos_mem_zero(&localList, sizeof(tDblLinkList));
8872 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
8873 {
8874 smsLog(pMac, LOGE, FL(" failed to open list"));
8875 return;
8876 }
8877
8878 csrLLLock(pList);
8879 if( !csrLLIsListEmpty( pList, LL_ACCESS_NOLOCK ) )
8880 {
8881 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK);
8882
8883 // Have to make sure we don't loop back to the head of the list, which will
8884 // happen if the entry is NOT on the list...
8885 while( pEntry )
8886 {
8887 pEntryToRemove = pEntry;
8888 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
8889 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
8890 if ( (eSmeCommandScan == pCommand->command ) &&
8891 (sessionId == pCommand->sessionId) )
8892 {
8893 if ( eCsrScanForSsid == pCommand->u.scanCmd.reason)
8894 {
8895 // Remove that entry only
8896 if ( csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
8897 {
8898 csrLLInsertTail(&localList, pEntryToRemove, LL_ACCESS_NOLOCK);
8899 }
8900 }
8901 }
8902 }
8903 }
8904 csrLLUnlock(pList);
8905
8906 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
8907 {
8908 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8909 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
8910 }
8911 csrLLClose(&localList);
8912}
Jeff Johnson295189b2012-06-20 16:38:30 -07008913
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308914eHalStatus csrScanAbortMacScanNotForConnect(tpAniSirGlobal pMac,
8915 tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07008916{
8917 eHalStatus status = eHAL_STATUS_SUCCESS;
8918
8919 if( !csrIsScanForRoamCommandActive( pMac ) )
8920 {
8921 //Only abort the scan if it is not used for other roam/connect purpose
c_hpothua3d45d52015-01-05 14:11:17 +05308922 if (eSIR_ABORT_SCAN_FAILURE ==
8923 csrScanAbortMacScan(pMac, sessionId, eCSR_SCAN_ABORT_DEFAULT))
8924 {
8925 smsLog(pMac, LOGE, FL("fail to abort scan"));
8926 status = eHAL_STATUS_FAILURE;
8927 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008928 }
8929
8930 return (status);
8931}
8932
8933
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05308934eHalStatus csrScanGetScanChannelInfo(tpAniSirGlobal pMac, tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07008935{
8936 eHalStatus status = eHAL_STATUS_SUCCESS;
8937 tSirMbMsg *pMsg;
8938 tANI_U16 msgLen;
8939
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05308940 if (pMac->fScanOffload)
8941 msgLen = (tANI_U16)(sizeof(tSirSmeGetScanChanReq));
8942 else
8943 msgLen = (tANI_U16)(sizeof(tSirMbMsg));
8944
Kiet Lam64c1b492013-07-12 13:56:44 +05308945 pMsg = vos_mem_malloc(msgLen);
8946 if ( NULL == pMsg )
8947 status = eHAL_STATUS_FAILURE;
8948 else
Jeff Johnson295189b2012-06-20 16:38:30 -07008949 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308950 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008951 pMsg->type = eWNI_SME_GET_SCANNED_CHANNEL_REQ;
8952 pMsg->msgLen = msgLen;
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05308953 if (pMac->fScanOffload)
8954 ((tSirSmeGetScanChanReq *)pMsg)->sessionId = sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07008955 status = palSendMBMessage(pMac->hHdd, pMsg);
8956 }
8957
8958 return( status );
8959}
8960
8961tANI_BOOLEAN csrRoamIsValidChannel( tpAniSirGlobal pMac, tANI_U8 channel )
8962{
8963 tANI_BOOLEAN fValid = FALSE;
8964 tANI_U32 idxValidChannels;
8965 tANI_U32 len = pMac->roam.numValidChannels;
8966
8967 for ( idxValidChannels = 0; ( idxValidChannels < len ); idxValidChannels++ )
8968 {
8969 if ( channel == pMac->roam.validChannelList[ idxValidChannels ] )
8970 {
8971 fValid = TRUE;
8972 break;
8973 }
8974 }
8975
8976 return fValid;
8977}
8978
Manjunathappa Prakash4f1d5a52013-11-11 16:22:19 -08008979#ifdef FEATURE_WLAN_SCAN_PNO
Srikant Kuppa066904f2013-05-07 13:56:02 -07008980eHalStatus csrScanSavePreferredNetworkFound(tpAniSirGlobal pMac,
8981 tSirPrefNetworkFoundInd *pPrefNetworkFoundInd)
8982{
8983 v_U32_t uLen = 0;
8984 tpSirProbeRespBeacon pParsedFrame;
8985 tCsrScanResult *pScanResult = NULL;
8986 tSirBssDescription *pBssDescr = NULL;
8987 tANI_BOOLEAN fDupBss;
8988 tDot11fBeaconIEs *pIesLocal = NULL;
8989 tAniSSID tmpSsid;
8990 v_TIME_t timer=0;
8991 tpSirMacMgmtHdr macHeader = (tpSirMacMgmtHdr)pPrefNetworkFoundInd->data;
Abhishek Singhd3d4e022014-11-11 13:02:40 +05308992 boolean bFoundonAppliedChannel = FALSE;
8993 v_U32_t indx;
8994 u8 channelsAllowed[WNI_CFG_VALID_CHANNEL_LIST_LEN];
8995 v_U32_t numChannelsAllowed = WNI_CFG_VALID_CHANNEL_LIST_LEN;
Sushant Kaushik6274de62015-05-01 16:31:23 +05308996 tListElem *pEntry;
Abhishek Singhd3d4e022014-11-11 13:02:40 +05308997
Srikant Kuppa066904f2013-05-07 13:56:02 -07008998
8999 pParsedFrame =
Abhishek Singhc75726d2015-04-13 14:44:14 +05309000 (tpSirProbeRespBeacon)vos_mem_vmalloc(sizeof(tSirProbeRespBeacon));
Srikant Kuppa066904f2013-05-07 13:56:02 -07009001
9002 if (NULL == pParsedFrame)
9003 {
9004 smsLog(pMac, LOGE, FL(" fail to allocate memory for frame"));
9005 return eHAL_STATUS_RESOURCES;
9006 }
9007
9008 if ( pPrefNetworkFoundInd->frameLength <= SIR_MAC_HDR_LEN_3A )
9009 {
9010 smsLog(pMac, LOGE,
9011 FL("Not enough bytes in PNO indication probe resp frame! length=%d"),
9012 pPrefNetworkFoundInd->frameLength);
Abhishek Singhc75726d2015-04-13 14:44:14 +05309013 vos_mem_vfree(pParsedFrame);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009014 return eHAL_STATUS_FAILURE;
9015 }
9016
9017 if (sirConvertProbeFrame2Struct(pMac,
9018 &pPrefNetworkFoundInd->data[SIR_MAC_HDR_LEN_3A],
9019 pPrefNetworkFoundInd->frameLength - SIR_MAC_HDR_LEN_3A,
9020 pParsedFrame) != eSIR_SUCCESS ||
9021 !pParsedFrame->ssidPresent)
9022 {
9023 smsLog(pMac, LOGE,
9024 FL("Parse error ProbeResponse, length=%d"),
9025 pPrefNetworkFoundInd->frameLength);
Abhishek Singhc75726d2015-04-13 14:44:14 +05309026 vos_mem_vfree(pParsedFrame);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009027 return eHAL_STATUS_FAILURE;
9028 }
9029 //24 byte MAC header and 12 byte to ssid IE
9030 if (pPrefNetworkFoundInd->frameLength >
9031 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET))
9032 {
9033 uLen = pPrefNetworkFoundInd->frameLength -
9034 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET);
9035 }
9036
Kiet Lam64c1b492013-07-12 13:56:44 +05309037 pScanResult = vos_mem_malloc(sizeof(tCsrScanResult) + uLen);
9038 if ( NULL == pScanResult )
Srikant Kuppa066904f2013-05-07 13:56:02 -07009039 {
9040 smsLog(pMac, LOGE, FL(" fail to allocate memory for frame"));
9041 vos_mem_free(pParsedFrame);
9042 return eHAL_STATUS_RESOURCES;
9043 }
9044
Kiet Lam64c1b492013-07-12 13:56:44 +05309045 vos_mem_set(pScanResult, sizeof(tCsrScanResult) + uLen, 0);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009046 pBssDescr = &pScanResult->Result.BssDescriptor;
9047 /**
9048 * Length of BSS desription is without length of
9049 * length itself and length of pointer
9050 * that holds the next BSS description
9051 */
9052 pBssDescr->length = (tANI_U16)(
Abhishek Singhbad2b322016-10-21 11:22:33 +05309053 ((uintptr_t)OFFSET_OF(tSirBssDescription, ieFields))
9054 - sizeof(pBssDescr->length) + uLen);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009055 if (pParsedFrame->dsParamsPresent)
9056 {
9057 pBssDescr->channelId = pParsedFrame->channelNumber;
9058 }
9059 else if (pParsedFrame->HTInfo.present)
9060 {
9061 pBssDescr->channelId = pParsedFrame->HTInfo.primaryChannel;
9062 }
9063 else
9064 {
Mahesh A Saptasagaradd99792014-03-26 16:04:20 +05309065 /**
9066 * If Probe Responce received in PNO indication does not
9067 * contain DSParam IE or HT Info IE then add dummy channel
9068 * to the received BSS info so that Scan result received as
9069 * a part of PNO is updated to the supplicant. Specially
9070 * applicable in case of AP configured in 11A only mode.
9071 */
9072 if ((pMac->roam.configParam.bandCapability == eCSR_BAND_ALL) ||
9073 (pMac->roam.configParam.bandCapability == eCSR_BAND_24))
9074 {
9075 pBssDescr->channelId = 1;
9076 }
9077 else if(pMac->roam.configParam.bandCapability == eCSR_BAND_5G)
9078 {
9079 pBssDescr->channelId = 36;
9080 }
Abhishek Singhd3d4e022014-11-11 13:02:40 +05309081 /* Restrict the logic to ignore the pno indication for invalid channel
9082 * only if valid channel info is present in beacon/probe resp.
9083 * If no channel info is present in beacon/probe resp, always process
9084 * the pno indication.
9085 */
9086 bFoundonAppliedChannel = TRUE;
9087 }
9088
9089 if (0 != sme_GetCfgValidChannels(pMac, channelsAllowed, &numChannelsAllowed))
9090 {
9091 smsLog(pMac, LOGE, FL(" sme_GetCfgValidChannels failed "));
9092 csrFreeScanResultEntry(pMac, pScanResult);
Abhishek Singhc75726d2015-04-13 14:44:14 +05309093 vos_mem_vfree(pParsedFrame);
Abhishek Singhd3d4e022014-11-11 13:02:40 +05309094 return eHAL_STATUS_FAILURE;
9095 }
9096 /* Checking chhanelId with allowed channel list */
9097 for (indx = 0; indx < numChannelsAllowed; indx++)
9098 {
9099 if (pBssDescr->channelId == channelsAllowed[indx])
9100 {
9101 bFoundonAppliedChannel = TRUE;
9102 smsLog(pMac, LOG1, FL(" pno ind found on applied channel =%d\n "),
9103 pBssDescr->channelId);
9104 break;
9105 }
9106 }
9107 /* Ignore PNO indication if AP is on Invalid channel.
9108 */
9109 if(FALSE == bFoundonAppliedChannel)
9110 {
9111 smsLog(pMac, LOGW, FL(" prefered network found on invalid channel = %d"),
9112 pBssDescr->channelId);
9113 csrFreeScanResultEntry(pMac, pScanResult);
Abhishek Singhc75726d2015-04-13 14:44:14 +05309114 vos_mem_vfree(pParsedFrame);
Abhishek Singhd3d4e022014-11-11 13:02:40 +05309115 return eHAL_STATUS_FAILURE;
Srikant Kuppa066904f2013-05-07 13:56:02 -07009116 }
9117
9118 if ((pBssDescr->channelId > 0) && (pBssDescr->channelId < 15))
9119 {
9120 int i;
9121 // 11b or 11g packet
9122 // 11g iff extended Rate IE is present or
9123 // if there is an A rate in suppRate IE
9124 for (i = 0; i < pParsedFrame->supportedRates.numRates; i++)
9125 {
9126 if (sirIsArate(pParsedFrame->supportedRates.rate[i] & 0x7f))
9127 {
9128 pBssDescr->nwType = eSIR_11G_NW_TYPE;
9129 break;
9130 }
9131 }
9132 if (pParsedFrame->extendedRatesPresent)
9133 {
9134 pBssDescr->nwType = eSIR_11G_NW_TYPE;
9135 }
9136 }
9137 else
9138 {
9139 // 11a packet
9140 pBssDescr->nwType = eSIR_11A_NW_TYPE;
9141 }
9142
9143 pBssDescr->sinr = 0;
9144 pBssDescr->rssi = -1 * pPrefNetworkFoundInd->rssi;
9145 pBssDescr->beaconInterval = pParsedFrame->beaconInterval;
AnjaneeDevi Kapparapu4b043912014-02-18 13:22:35 +05309146 if (!pBssDescr->beaconInterval)
9147 {
9148 smsLog(pMac, LOGW,
9149 FL("Bcn Interval is Zero , default to 100" MAC_ADDRESS_STR),
9150 MAC_ADDR_ARRAY(pBssDescr->bssId) );
9151 pBssDescr->beaconInterval = 100;
9152 }
Srikant Kuppa066904f2013-05-07 13:56:02 -07009153 pBssDescr->timeStamp[0] = pParsedFrame->timeStamp[0];
9154 pBssDescr->timeStamp[1] = pParsedFrame->timeStamp[1];
9155 pBssDescr->capabilityInfo = *((tANI_U16 *)&pParsedFrame->capabilityInfo);
Kiet Lam64c1b492013-07-12 13:56:44 +05309156 vos_mem_copy((tANI_U8 *) &pBssDescr->bssId, (tANI_U8 *) macHeader->bssId, sizeof(tSirMacAddr));
Deepthi Gowri4480a3f2016-05-18 19:30:17 +05309157 pBssDescr->nReceivedTime = vos_timer_get_system_time();
Srikant Kuppa066904f2013-05-07 13:56:02 -07009158
Abhishek Singh195c03e2014-05-14 17:21:30 +05309159 smsLog( pMac, LOG1, FL("Bssid= "MAC_ADDRESS_STR
9160 " chan= %d, rssi = %d "),
Arif Hussain24bafea2013-11-15 15:10:03 -08009161 MAC_ADDR_ARRAY(pBssDescr->bssId),
Srikant Kuppa066904f2013-05-07 13:56:02 -07009162 pBssDescr->channelId,
Abhishek Singh195c03e2014-05-14 17:21:30 +05309163 pBssDescr->rssi);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009164
9165 //IEs
9166 if (uLen)
9167 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309168 vos_mem_copy(&pBssDescr->ieFields,
9169 pPrefNetworkFoundInd->data + (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET),
9170 uLen);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009171 }
9172
9173 pIesLocal = (tDot11fBeaconIEs *)( pScanResult->Result.pvIes );
9174 if ( !pIesLocal &&
9175 (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
9176 &pScanResult->Result.BssDescriptor, &pIesLocal))) )
9177 {
9178 smsLog(pMac, LOGE, FL(" Cannot parse IEs"));
9179 csrFreeScanResultEntry(pMac, pScanResult);
Abhishek Singhc75726d2015-04-13 14:44:14 +05309180 vos_mem_vfree(pParsedFrame);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009181 return eHAL_STATUS_RESOURCES;
9182 }
9183
9184 fDupBss = csrRemoveDupBssDescription( pMac,
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05309185 &pScanResult->Result.BssDescriptor, pIesLocal, &tmpSsid, &timer, FALSE);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009186 //Check whether we have reach out limit
9187 if ( CSR_SCAN_IS_OVER_BSS_LIMIT(pMac) )
9188 {
9189 //Limit reach
9190 smsLog(pMac, LOGE, FL(" BSS limit reached"));
9191 //Free the resources
9192 if( (pScanResult->Result.pvIes == NULL) && pIesLocal )
9193 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309194 vos_mem_free(pIesLocal);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009195 }
9196 csrFreeScanResultEntry(pMac, pScanResult);
9197 vos_mem_free(pParsedFrame);
9198 return eHAL_STATUS_RESOURCES;
9199 }
Nalla Kartheek71946422015-09-15 14:41:22 +05309200
9201 if ((macHeader->fc.type == SIR_MAC_MGMT_FRAME) &&
9202 (macHeader->fc.subType == SIR_MAC_MGMT_PROBE_RSP))
9203 {
9204 pScanResult->Result.BssDescriptor.fProbeRsp = 1;
9205 }
Srikant Kuppa066904f2013-05-07 13:56:02 -07009206 //Add to scan cache
9207 csrScanAddResult(pMac, pScanResult, pIesLocal);
Sushant Kaushik6274de62015-05-01 16:31:23 +05309208 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
Kiet Lamb537cfb2013-11-07 12:56:49 +05309209 if( (pScanResult->Result.pvIes == NULL) && pIesLocal )
9210 {
9211 vos_mem_free(pIesLocal);
9212 }
9213
Abhishek Singhc75726d2015-04-13 14:44:14 +05309214 vos_mem_vfree(pParsedFrame);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009215
9216 return eHAL_STATUS_SUCCESS;
9217}
Manjunathappa Prakash4f1d5a52013-11-11 16:22:19 -08009218#endif //FEATURE_WLAN_SCAN_PNO
Srikant Kuppa066904f2013-05-07 13:56:02 -07009219
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08009220#ifdef FEATURE_WLAN_LFR
9221void csrInitOccupiedChannelsList(tpAniSirGlobal pMac)
9222{
9223 tListElem *pEntry = NULL;
9224 tCsrScanResult *pBssDesc = NULL;
9225 tDot11fBeaconIEs *pIes = NULL;
Srinivas28b5b4e2012-12-12 13:07:53 -08009226 tpCsrNeighborRoamControlInfo pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
9227
9228 if (0 != pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels)
9229 {
9230 smsLog(pMac, LOG1, FL("%s: Ini file contains neighbor scan channel list,"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08009231 " hence NO need to build occupied channel list (numChannels = %d)"),
Srinivas28b5b4e2012-12-12 13:07:53 -08009232 __func__, pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels);
9233 return;
9234 }
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08009235
9236 if (!csrNeighborRoamIsNewConnectedProfile(pMac))
9237 {
9238 smsLog(pMac, LOG2, FL("%s: donot flush occupied list since current roam profile"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08009239 " matches previous (numChannels = %d)"),
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08009240 __func__, pMac->scan.occupiedChannels.numChannels);
9241 return;
9242 }
9243
9244 /* Empty occupied channels here */
9245 pMac->scan.occupiedChannels.numChannels = 0;
9246
9247 csrLLLock(&pMac->scan.scanResultList);
9248 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
9249 while( pEntry )
9250 {
9251 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
9252 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
9253
9254 //At this time, pBssDescription->Result.pvIes may be NULL
Srikant Kuppa866893f2012-12-27 17:28:14 -08009255 if( !pIes && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08009256 &pBssDesc->Result.BssDescriptor, &pIes))) )
9257 {
9258 continue;
9259 }
9260
9261 csrScanAddToOccupiedChannels(pMac, pBssDesc, &pMac->scan.occupiedChannels, pIes);
9262
9263 /*
9264 * Free the memory allocated for pIes in csrGetParsedBssDescriptionIEs
9265 */
9266 if( (pBssDesc->Result.pvIes == NULL) && pIes )
9267 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309268 vos_mem_free(pIes);
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08009269 }
9270
9271 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK );
9272 }//while
9273 csrLLUnlock(&pMac->scan.scanResultList);
Srikant Kuppa866893f2012-12-27 17:28:14 -08009274
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08009275}
9276#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009277
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009278eHalStatus csrScanCreateEntryInScanCache(tpAniSirGlobal pMac, tANI_U32 sessionId,
9279 tCsrBssid bssid, tANI_U8 channel)
9280{
9281 eHalStatus status = eHAL_STATUS_SUCCESS;
9282 tDot11fBeaconIEs *pNewIes = NULL;
9283 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
Praveen Kumar Sirisilla8bdfac42013-10-10 17:20:48 -07009284 tSirBssDescription *pNewBssDescriptor = NULL;
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009285 tANI_U32 size = 0;
9286
9287 if(NULL == pSession)
9288 {
9289 status = eHAL_STATUS_FAILURE;
9290 return status;
9291 }
9292 smsLog(pMac, LOG2, FL("csrScanCreateEntryInScanCache: Current bssid::"
Arif Hussain24bafea2013-11-15 15:10:03 -08009293 MAC_ADDRESS_STR),
9294 MAC_ADDR_ARRAY(pSession->pConnectBssDesc->bssId));
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009295 smsLog(pMac, LOG2, FL("csrScanCreateEntryInScanCache: My bssid::"
Arif Hussain24bafea2013-11-15 15:10:03 -08009296 MAC_ADDRESS_STR" channel %d"),
9297 MAC_ADDR_ARRAY(bssid), channel);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009298
9299 do
9300 {
9301 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
9302 pSession->pConnectBssDesc, &pNewIes)))
9303 {
9304 smsLog(pMac, LOGE, FL("%s: Failed to parse IEs"),
9305 __func__);
9306 status = eHAL_STATUS_FAILURE;
9307 break;
9308 }
9309
9310 size = pSession->pConnectBssDesc->length + sizeof(pSession->pConnectBssDesc->length);
Kiet Lam64c1b492013-07-12 13:56:44 +05309311 if (size)
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009312 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309313 pNewBssDescriptor = vos_mem_malloc(size);
9314 if ( NULL == pNewBssDescriptor )
9315 status = eHAL_STATUS_FAILURE;
9316 else
9317 status = eHAL_STATUS_SUCCESS;
9318 if (HAL_STATUS_SUCCESS(status))
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009319 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309320 vos_mem_copy(pNewBssDescriptor, pSession->pConnectBssDesc, size);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009321 }
9322 else
9323 {
9324 smsLog(pMac, LOGE, FL("%s: memory allocation failed"),
9325 __func__);
9326 status = eHAL_STATUS_FAILURE;
9327 break;
9328 }
9329
9330 //change the BSSID & channel as passed
Kiet Lam64c1b492013-07-12 13:56:44 +05309331 vos_mem_copy(pNewBssDescriptor->bssId, bssid, sizeof(tSirMacAddr));
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009332 pNewBssDescriptor->channelId = channel;
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07009333 if(NULL == csrScanAppendBssDescription( pMac, pNewBssDescriptor, pNewIes, TRUE ))
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009334 {
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07009335 smsLog(pMac, LOGE, FL("%s: csrScanAppendBssDescription failed"),
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009336 __func__);
9337 status = eHAL_STATUS_FAILURE;
9338 break;
9339 }
9340 }
9341 else
9342 {
9343 smsLog(pMac, LOGE, FL("%s: length of bss descriptor is 0"),
9344 __func__);
9345 status = eHAL_STATUS_FAILURE;
9346 break;
9347 }
9348 smsLog(pMac, LOGE, FL("%s: entry successfully added in scan cache"),
9349 __func__);
9350 }while(0);
9351
9352 if(pNewIes)
9353 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309354 vos_mem_free(pNewIes);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009355 }
9356 if(pNewBssDescriptor)
9357 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309358 vos_mem_free(pNewBssDescriptor);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009359 }
9360 return status;
9361}
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07009362
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08009363#ifdef FEATURE_WLAN_ESE
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07009364// Update the TSF with the difference in system time
9365void UpdateCCKMTSF(tANI_U32 *timeStamp0, tANI_U32 *timeStamp1, tANI_U32 *incr)
9366{
9367 tANI_U64 timeStamp64 = ((tANI_U64)*timeStamp1 << 32) | (*timeStamp0);
9368
9369 timeStamp64 = (tANI_U64)(timeStamp64 + (tANI_U64)*incr);
9370 *timeStamp0 = (tANI_U32)(timeStamp64 & 0xffffffff);
9371 *timeStamp1 = (tANI_U32)((timeStamp64 >> 32) & 0xffffffff);
9372}
9373#endif
Deepthi Gowriecc93352016-11-09 16:58:47 +05309374
9375void csrValidateScanChannels(tpAniSirGlobal pMac, tCsrScanRequest *pDstReq,
9376 tCsrScanRequest *pSrcReq, int new_index, tANI_U8 ch144_support)
9377{
9378
9379 int index;
9380 for ( index = 0; index < pSrcReq->ChannelInfo.
9381 numOfChannels ; index++ )
9382 {
9383 /* Skip CH 144 if firmware support not present */
9384 if (pSrcReq->ChannelInfo.ChannelList[index] == 144 && !ch144_support)
9385 continue;
9386
9387 /* Allow scan on valid channels only.
9388 */
9389 if ( ( csrRoamIsValidChannel(pMac,
9390 pSrcReq->ChannelInfo.ChannelList[index]) ) )
9391 {
9392 if( ((pSrcReq->skipDfsChnlInP2pSearch ||
9393 (pMac->scan.fEnableDFSChnlScan ==
9394 DFS_CHNL_SCAN_DISABLED)) &&
9395 (NV_CHANNEL_DFS == vos_nv_getChannelEnabledState(
9396 pSrcReq->ChannelInfo.ChannelList[index])) &&
9397 (pSrcReq->ChannelInfo.numOfChannels > 1))
9398#ifdef FEATURE_WLAN_LFR
9399 /*
9400 * If LFR is requesting a contiguous scan
9401 * (i.e. numOfChannels > 1), then ignore
9402 * DFS channels.
9403 * TODO: vos_nv_getChannelEnabledState is returning
9404 * 120, 124 and 128 as non-DFS channels. Hence, the
9405 * use of direct check for channels below.
9406 */
9407 || ((eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType) &&
9408 (pSrcReq->ChannelInfo.numOfChannels > 1) &&
9409 (CSR_IS_CHANNEL_DFS(
9410 pSrcReq->ChannelInfo.ChannelList[index])) &&
9411 !pMac->roam.configParam.allowDFSChannelRoam)
9412#endif
9413 )
9414 {
9415#ifdef FEATURE_WLAN_LFR
9416 smsLog(pMac, LOG1,
9417 FL(" reqType=%s (%d), numOfChannels=%d,"
9418 " ignoring DFS channel:%d"),
9419 sme_requestTypetoString(pSrcReq->requestType),
9420 pSrcReq->requestType,
9421 pSrcReq->ChannelInfo.numOfChannels,
9422 pSrcReq->ChannelInfo.ChannelList[index]);
9423#endif
9424 continue;
9425 }
9426
9427 pDstReq->ChannelInfo.ChannelList[new_index] =
9428 pSrcReq->ChannelInfo.ChannelList[index];
9429 new_index++;
9430 }
9431 }
9432}