blob: 3c5aa4be14065e5f945cda2b7217044a8b5a1c4f [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 *);
Deepthi Gowri6a08e312016-03-31 19:10:14 +0530128static void csrPurgeScanResultByAge(void *pv);
Jeff Johnson295189b2012-06-20 16:38:30 -0700129void csrScanIdleScanTimerHandler(void *);
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700130static void csrSetDefaultScanTiming( tpAniSirGlobal pMac, tSirScanType scanType, tCsrScanRequest *pScanRequest);
Jeff Johnson295189b2012-06-20 16:38:30 -0700131#ifdef WLAN_AP_STA_CONCURRENCY
132static void csrStaApConcTimerHandler(void *);
133#endif
Jeff Johnsone7245742012-09-05 17:12:55 -0700134tANI_BOOLEAN csrIsSupportedChannel(tpAniSirGlobal pMac, tANI_U8 channelId);
Jeff Johnson295189b2012-06-20 16:38:30 -0700135eHalStatus csrScanChannels( tpAniSirGlobal pMac, tSmeCmd *pCommand );
136void csrSetCfgValidChannelList( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels );
137void csrSaveTxPowerToCfg( tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 cfgId );
138void csrSetCfgCountryCode( tpAniSirGlobal pMac, tANI_U8 *countryCode );
139void csrPurgeChannelPower( tpAniSirGlobal pMac, tDblLinkList *pChannelList );
140//if bgPeriod is 0, background scan is disabled. It is in millisecond units
141eHalStatus csrSetCfgBackgroundScanPeriod(tpAniSirGlobal pMac, tANI_U32 bgPeriod);
142eHalStatus csrProcessSetBGScanParam(tpAniSirGlobal pMac, tSmeCmd *pCommand);
143void csrReleaseScanCommand(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus);
144static tANI_BOOLEAN csrScanValidateScanResult( tpAniSirGlobal pMac, tANI_U8 *pChannels,
145 tANI_U8 numChn, tSirBssDescription *pBssDesc,
146 tDot11fBeaconIEs **ppIes );
147eHalStatus csrSetBGScanChannelList( tpAniSirGlobal pMac, tANI_U8 *pAdjustChannels, tANI_U8 NumAdjustChannels);
148void csrReleaseCmdSingle(tpAniSirGlobal pMac, tSmeCmd *pCommand);
149tANI_BOOLEAN csrRoamIsValidChannel( tpAniSirGlobal pMac, tANI_U8 channel );
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700150void csrPruneChannelListForMode( tpAniSirGlobal pMac, tCsrChannel *pChannelList );
Deepthi Gowri50e2fa52016-03-17 15:30:53 +0530151void csrPurgeOldScanResults(tpAniSirGlobal pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -0700152
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -0700153
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -0700154
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -0700155
Madan Mohan Koyyalamudi923c1e12012-11-30 17:53:27 -0800156static void csrReleaseScanCmdPendingList(tpAniSirGlobal pMac)
157{
158 tListElem *pEntry;
159 tSmeCmd *pCommand;
160
161 while((pEntry = csrLLRemoveHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK)) != NULL)
162 {
163 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
164 if ( eSmeCsrCommandMask & pCommand->command )
165 {
166 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_TRUE );
167 }
168 else
169 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800170 smsLog(pMac, LOGE, FL("Error: Received command : %d"),pCommand->command);
Madan Mohan Koyyalamudi923c1e12012-11-30 17:53:27 -0800171 }
172 }
173}
Jeff Johnson295189b2012-06-20 16:38:30 -0700174//pResult is invalid calling this function.
175void csrFreeScanResultEntry( tpAniSirGlobal pMac, tCsrScanResult *pResult )
176{
177 if( NULL != pResult->Result.pvIes )
178 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530179 vos_mem_free(pResult->Result.pvIes);
Jeff Johnson295189b2012-06-20 16:38:30 -0700180 }
Kiet Lam64c1b492013-07-12 13:56:44 +0530181 vos_mem_free(pResult);
Jeff Johnson295189b2012-06-20 16:38:30 -0700182}
183
184
185static eHalStatus csrLLScanPurgeResult(tpAniSirGlobal pMac, tDblLinkList *pList)
186{
187 eHalStatus status = eHAL_STATUS_SUCCESS;
188 tListElem *pEntry;
189 tCsrScanResult *pBssDesc;
190
191 csrLLLock(pList);
192
193 while((pEntry = csrLLRemoveHead(pList, LL_ACCESS_NOLOCK)) != NULL)
194 {
195 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
196 csrFreeScanResultEntry( pMac, pBssDesc );
197 }
198
199 csrLLUnlock(pList);
200
201 return (status);
202}
203
Jeff Johnson295189b2012-06-20 16:38:30 -0700204eHalStatus csrScanOpen( tpAniSirGlobal pMac )
205{
206 eHalStatus status;
207
208 do
209 {
210 csrLLOpen(pMac->hHdd, &pMac->scan.scanResultList);
211 csrLLOpen(pMac->hHdd, &pMac->scan.tempScanResults);
212 csrLLOpen(pMac->hHdd, &pMac->scan.channelPowerInfoList24);
213 csrLLOpen(pMac->hHdd, &pMac->scan.channelPowerInfoList5G);
214#ifdef WLAN_AP_STA_CONCURRENCY
215 csrLLOpen(pMac->hHdd, &pMac->scan.scanCmdPendingList);
216#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700217 pMac->scan.fFullScanIssued = eANI_BOOLEAN_FALSE;
218 pMac->scan.nBssLimit = CSR_MAX_BSS_SUPPORT;
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530219 status = vos_timer_init(&pMac->scan.hTimerGetResult, VOS_TIMER_TYPE_SW, csrScanGetResultTimerHandler, pMac);
220 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700221 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800222 smsLog(pMac, LOGE, FL("cannot allocate memory for getResult timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700223 break;
224 }
225#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530226 status = vos_timer_init(&pMac->scan.hTimerStaApConcTimer, VOS_TIMER_TYPE_SW, csrStaApConcTimerHandler, pMac);
227 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700228 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800229 smsLog(pMac, LOGE, FL("cannot allocate memory for hTimerStaApConcTimer timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700230 break;
231 }
232#endif
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530233 status = vos_timer_init(&pMac->scan.hTimerIdleScan, VOS_TIMER_TYPE_SW, csrScanIdleScanTimerHandler, pMac);
234 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700235 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800236 smsLog(pMac, LOGE, FL("cannot allocate memory for idleScan timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700237 break;
238 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700239 }while(0);
240
241 return (status);
242}
243
244
245eHalStatus csrScanClose( tpAniSirGlobal pMac )
246{
Jeff Johnson295189b2012-06-20 16:38:30 -0700247 csrLLScanPurgeResult(pMac, &pMac->scan.tempScanResults);
248 csrLLScanPurgeResult(pMac, &pMac->scan.scanResultList);
249#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudi923c1e12012-11-30 17:53:27 -0800250 csrReleaseScanCmdPendingList(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -0700251#endif
252 csrLLClose(&pMac->scan.scanResultList);
253 csrLLClose(&pMac->scan.tempScanResults);
254#ifdef WLAN_AP_STA_CONCURRENCY
255 csrLLClose(&pMac->scan.scanCmdPendingList);
256#endif
257 csrPurgeChannelPower(pMac, &pMac->scan.channelPowerInfoList24);
258 csrPurgeChannelPower(pMac, &pMac->scan.channelPowerInfoList5G);
259 csrLLClose(&pMac->scan.channelPowerInfoList24);
260 csrLLClose(&pMac->scan.channelPowerInfoList5G);
261 csrScanDisable(pMac);
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530262 vos_timer_destroy(&pMac->scan.hTimerGetResult);
Jeff Johnson295189b2012-06-20 16:38:30 -0700263#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530264 vos_timer_destroy(&pMac->scan.hTimerStaApConcTimer);
Jeff Johnson295189b2012-06-20 16:38:30 -0700265#endif
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530266 vos_timer_destroy(&pMac->scan.hTimerIdleScan);
Jeff Johnson295189b2012-06-20 16:38:30 -0700267 return eHAL_STATUS_SUCCESS;
268}
269
270
271eHalStatus csrScanEnable( tpAniSirGlobal pMac )
272{
273
274 pMac->scan.fScanEnable = eANI_BOOLEAN_TRUE;
275 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
276
277 return eHAL_STATUS_SUCCESS;
278}
279
280
281eHalStatus csrScanDisable( tpAniSirGlobal pMac )
282{
283
284 csrScanStopTimers(pMac);
285 pMac->scan.fScanEnable = eANI_BOOLEAN_FALSE;
286
287 return eHAL_STATUS_SUCCESS;
288}
289
290
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700291//Set scan timing parameters according to state of other driver sessions
292//No validation of the parameters is performed.
293static void csrSetDefaultScanTiming( tpAniSirGlobal pMac, tSirScanType scanType, tCsrScanRequest *pScanRequest)
294{
295#ifdef WLAN_AP_STA_CONCURRENCY
296 if(csrIsAnySessionConnected(pMac))
297 {
Sushant Kaushika6fef4b2014-09-24 16:17:08 +0530298 //Reset passive scan time as per ini parameter.
Abhishek Singh7fb7dc12014-11-06 17:44:05 +0530299 ccmCfgSetInt(pMac, WNI_CFG_PASSIVE_MAXIMUM_CHANNEL_TIME,
Sushant Kaushika6fef4b2014-09-24 16:17:08 +0530300 pMac->roam.configParam.nPassiveMaxChnTimeConc,
301 NULL,eANI_BOOLEAN_FALSE);
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700302 //If multi-session, use the appropriate default scan times
303 if(scanType == eSIR_ACTIVE_SCAN)
304 {
305 pScanRequest->maxChnTime = pMac->roam.configParam.nActiveMaxChnTimeConc;
306 pScanRequest->minChnTime = pMac->roam.configParam.nActiveMinChnTimeConc;
307 }
308 else
309 {
310 pScanRequest->maxChnTime = pMac->roam.configParam.nPassiveMaxChnTimeConc;
311 pScanRequest->minChnTime = pMac->roam.configParam.nPassiveMinChnTimeConc;
312 }
Kiet Lam64c1b492013-07-12 13:56:44 +0530313 pScanRequest->maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
314 pScanRequest->minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700315
316 pScanRequest->restTime = pMac->roam.configParam.nRestTimeConc;
317
318 //Return so that fields set above will not be overwritten.
319 return;
320 }
321#endif
322
323 //This portion of the code executed if multi-session not supported
324 //(WLAN_AP_STA_CONCURRENCY not defined) or no multi-session.
325 //Use the "regular" (non-concurrency) default scan timing.
Abhishek Singh7fb7dc12014-11-06 17:44:05 +0530326 ccmCfgSetInt(pMac, WNI_CFG_PASSIVE_MAXIMUM_CHANNEL_TIME,
Kaushik, Sushant49758c12014-09-26 11:25:38 +0530327 pMac->roam.configParam.nPassiveMaxChnTime,
328 NULL,eANI_BOOLEAN_FALSE);
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700329 if(pScanRequest->scanType == eSIR_ACTIVE_SCAN)
330 {
331 pScanRequest->maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
332 pScanRequest->minChnTime = pMac->roam.configParam.nActiveMinChnTime;
333 }
334 else
335 {
336 pScanRequest->maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
337 pScanRequest->minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
338 }
Kiet Lam64c1b492013-07-12 13:56:44 +0530339 pScanRequest->maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
340 pScanRequest->minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700341
342#ifdef WLAN_AP_STA_CONCURRENCY
343 //No rest time if no sessions are connected.
344 pScanRequest->restTime = 0;
345#endif
346}
347
Jeff Johnson295189b2012-06-20 16:38:30 -0700348#ifdef WLAN_AP_STA_CONCURRENCY
349//Return SUCCESS is the command is queued, else returns eHAL_STATUS_FAILURE
350eHalStatus csrQueueScanRequest( tpAniSirGlobal pMac, tSmeCmd *pScanCmd )
351{
352 eHalStatus status = eHAL_STATUS_SUCCESS;
353
354 tANI_BOOLEAN fNoCmdPending;
355 tSmeCmd *pQueueScanCmd=NULL;
356 tSmeCmd *pSendScanCmd=NULL;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700357 tANI_U8 nNumChanCombinedConc = 0;
Gopichand Nakkala114718f2013-03-25 19:19:46 -0700358 if (NULL == pScanCmd)
359 {
360 smsLog (pMac, LOGE, FL("Scan Req cmd is NULL"));
361 return eHAL_STATUS_FAILURE;
362 }
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -0800363 /* split scan if any one of the following:
364 * - STA session is connected and the scan is not a P2P search
365 * - any P2P session is connected
Srikant Kuppa866893f2012-12-27 17:28:14 -0800366 * Do not split scans if no concurrent infra connections are
367 * active and if the scan is a BG scan triggered by LFR (OR)
368 * any scan if LFR is in the middle of a BG scan. Splitting
369 * the scan is delaying the time it takes for LFR to find
370 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -0800371 */
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700372
373 if(csrIsStaSessionConnected(pMac) &&
374 !csrIsP2pSessionConnected(pMac))
375 {
376 nNumChanCombinedConc = pMac->roam.configParam.nNumStaChanCombinedConc;
377 }
378 else if(csrIsP2pSessionConnected(pMac))
379 {
380 nNumChanCombinedConc = pMac->roam.configParam.nNumP2PChanCombinedConc;
381 }
Srikant Kuppa866893f2012-12-27 17:28:14 -0800382 if ( (csrIsStaSessionConnected(pMac) &&
383#ifdef FEATURE_WLAN_LFR
384 (csrIsConcurrentInfraConnected(pMac) ||
385 ((pScanCmd->u.scanCmd.reason != eCsrScanBgScan) &&
386 (pMac->roam.neighborRoamInfo.neighborRoamState !=
387 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
388#endif
389 (pScanCmd->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Vinay Malekal05fdc812012-12-17 13:04:30 -0800390 (csrIsP2pSessionConnected(pMac)) )
Jeff Johnson295189b2012-06-20 16:38:30 -0700391 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700392 tCsrScanRequest scanReq;
393 tANI_U8 numChn = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
394 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
395 tANI_U8 channelToScan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
Jeff Johnson295189b2012-06-20 16:38:30 -0700396 tANI_BOOLEAN bMemAlloc = eANI_BOOLEAN_FALSE;
397
398 if (numChn == 0)
399 {
400
401 numChn = pMac->scan.baseChannels.numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -0700402
Kiet Lam64c1b492013-07-12 13:56:44 +0530403 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(numChn);
404 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -0700405 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800406 smsLog( pMac, LOGE, FL(" Failed to get memory for channel list ") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800407 return eHAL_STATUS_FAILURE;
408 }
409 bMemAlloc = eANI_BOOLEAN_TRUE;
Kiet Lam64c1b492013-07-12 13:56:44 +0530410 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
411 pMac->scan.baseChannels.channelList, numChn);
412 status = eHAL_STATUS_SUCCESS;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800413 if( !HAL_STATUS_SUCCESS( status ) )
414 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530415 vos_mem_free(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800416 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800417 smsLog( pMac, LOGE, FL(" Failed to copy memory to channel list ") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800418 return eHAL_STATUS_FAILURE;
419 }
420 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = numChn;
421 }
Sushant Kaushik826de802014-05-08 18:04:11 +0530422 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
423 "%s: Total Number of channels to scan : %d "
424 "Splitted in group of %d ", __func__, numChn,
425 nNumChanCombinedConc);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800426 //Whenever we get a scan request with multiple channels we break it up into 2 requests
427 //First request for first channel to scan and second request to scan remaining channels
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700428 if ( numChn > nNumChanCombinedConc)
Vinay Malekal05fdc812012-12-17 13:04:30 -0800429 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530430 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800431
432 pQueueScanCmd = csrGetCommandBuffer(pMac); //optimize this to use 2 command buffer only
433 if (!pQueueScanCmd)
434 {
435 if (bMemAlloc)
Jeff Johnson295189b2012-06-20 16:38:30 -0700436 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530437 vos_mem_free(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800438 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
439
Jeff Johnson295189b2012-06-20 16:38:30 -0700440 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800441 smsLog( pMac, LOGE, FL(" Failed to get Queue command buffer") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800442 return eHAL_STATUS_FAILURE;
443 }
444 pQueueScanCmd->command = pScanCmd->command;
445 pQueueScanCmd->sessionId = pScanCmd->sessionId;
446 pQueueScanCmd->u.scanCmd.callback = pScanCmd->u.scanCmd.callback;
447 pQueueScanCmd->u.scanCmd.pContext = pScanCmd->u.scanCmd.pContext;
448 pQueueScanCmd->u.scanCmd.reason = pScanCmd->u.scanCmd.reason;
449 pQueueScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Jeff Johnson295189b2012-06-20 16:38:30 -0700450
Vinay Malekal05fdc812012-12-17 13:04:30 -0800451 /* First copy all the parameters to local variable of scan request */
452 csrScanCopyRequest(pMac, &scanReq, &pScanCmd->u.scanCmd.u.scanRequest);
Madan Mohan Koyyalamudiaf2a8b92012-10-09 14:58:07 -0700453
Vinay Malekal05fdc812012-12-17 13:04:30 -0800454 /* Now modify the elements of local var scan request required to be modified for split scan */
455 if(scanReq.ChannelInfo.ChannelList != NULL)
456 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530457 vos_mem_free(scanReq.ChannelInfo.ChannelList);
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -0800458 scanReq.ChannelInfo.ChannelList = NULL;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800459 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700460
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700461 pChnInfo->numOfChannels = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels - nNumChanCombinedConc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700462
Vinay Malekal05fdc812012-12-17 13:04:30 -0800463 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_WARN,
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +0530464 FL(" &channelToScan %p pScanCmd(%p) pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList(%p)numChn(%d)"),
465 &channelToScan[0], pScanCmd,
466 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList, numChn);
Jeff Johnson295189b2012-06-20 16:38:30 -0700467
Kiet Lam64c1b492013-07-12 13:56:44 +0530468 vos_mem_copy(&channelToScan[0],
469 &pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[
470 nNumChanCombinedConc],
471 pChnInfo->numOfChannels * sizeof(tANI_U8));
Vinay Malekal05fdc812012-12-17 13:04:30 -0800472
473 pChnInfo->ChannelList = &channelToScan[0];
474
475 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
c_hpothudbefd3e2014-04-28 15:59:47 +0530476
Vinay Malekal05fdc812012-12-17 13:04:30 -0800477 //Use concurrency values for min/maxChnTime.
478 //We know csrIsAnySessionConnected(pMac) returns TRUE here
479 csrSetDefaultScanTiming(pMac, scanReq.scanType, &scanReq);
480
481 status = csrScanCopyRequest(pMac, &pQueueScanCmd->u.scanCmd.u.scanRequest, &scanReq);
482
483 if(!HAL_STATUS_SUCCESS(status))
484 {
485 if (bMemAlloc)
486 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530487 vos_mem_free(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800488 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
489
490 }
491 if( scanReq.pIEField != NULL)
492 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530493 vos_mem_free(scanReq.pIEField);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800494 scanReq.pIEField = NULL;
495 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800496 smsLog( pMac, LOGE, FL(" Failed to get copy csrScanRequest = %d"), status );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800497 return eHAL_STATUS_FAILURE;
498 }
499 /* Clean the local scan variable */
500 scanReq.ChannelInfo.ChannelList = NULL;
501 scanReq.ChannelInfo.numOfChannels = 0;
502 csrScanFreeRequest(pMac, &scanReq);
503
504 /* setup the command to scan 2 channels */
505 pSendScanCmd = pScanCmd;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700506 pSendScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nNumChanCombinedConc;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800507 pSendScanCmd->u.scanCmd.u.scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
c_hpothudbefd3e2014-04-28 15:59:47 +0530508
Vinay Malekal05fdc812012-12-17 13:04:30 -0800509 //Use concurrency values for min/maxChnTime.
510 //We know csrIsAnySessionConnected(pMac) returns TRUE here
511 csrSetDefaultScanTiming(pMac, pSendScanCmd->u.scanCmd.u.scanRequest.scanType, &pSendScanCmd->u.scanCmd.u.scanRequest);
512 pSendScanCmd->u.scanCmd.callback = NULL;
513 } else {
514 pSendScanCmd = pScanCmd;
515 pSendScanCmd->u.scanCmd.u.scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
c_hpothudbefd3e2014-04-28 15:59:47 +0530516
Vinay Malekal05fdc812012-12-17 13:04:30 -0800517 //Use concurrency values for min/maxChnTime.
518 //We know csrIsAnySessionConnected(pMac) returns TRUE here
519 csrSetDefaultScanTiming(pMac, pSendScanCmd->u.scanCmd.u.scanRequest.scanType, &pSendScanCmd->u.scanCmd.u.scanRequest);
520 }
521
522 fNoCmdPending = csrLLIsListEmpty( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK );
523
524 //Logic Below is as follows
525 // If the scanCmdPendingList is empty then we directly send that command
526 // to smeCommandQueue else we buffer it in our scanCmdPendingList Queue
527 if( fNoCmdPending )
528 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700529 if (pQueueScanCmd != NULL)
530 {
Vinay Malekal05fdc812012-12-17 13:04:30 -0800531 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pQueueScanCmd->Link, LL_ACCESS_LOCK );
Jeff Johnson295189b2012-06-20 16:38:30 -0700532 }
533
534 if (pSendScanCmd != NULL)
535 {
536 return csrQueueSmeCommand(pMac, pSendScanCmd, eANI_BOOLEAN_FALSE);
537 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800538 }
539 else
540 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700541 if (pSendScanCmd != NULL)
542 {
543 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pSendScanCmd->Link, LL_ACCESS_LOCK );
544 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800545
Jeff Johnson295189b2012-06-20 16:38:30 -0700546 if (pQueueScanCmd != NULL)
547 {
548 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pQueueScanCmd->Link, LL_ACCESS_LOCK );
549 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800550 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700551 }
552 else
553 { //No concurrency case
Srikant Kuppa866893f2012-12-27 17:28:14 -0800554 smsLog( pMac, LOG2, FL("Queuing scan command (reason=%d, roamState=%d"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800555 " numOfChannels=%d)"),
Srikant Kuppa866893f2012-12-27 17:28:14 -0800556 pScanCmd->u.scanCmd.reason,
557 pMac->roam.neighborRoamInfo.neighborRoamState,
558 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -0700559 return csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
560 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700561
562 return ( status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700563}
564#endif
565
Jeff Johnsone7245742012-09-05 17:12:55 -0700566/* ---------------------------------------------------------------------------
567 \fn csrScan2GOnyRequest
568 \brief This function will update the scan request with only
Jeff Johnsonb88db982012-12-10 13:34:59 -0800569 2.4GHz valid channel list.
Jeff Johnsone7245742012-09-05 17:12:55 -0700570 \param pMac
571 \param pScanCmd
572 \param pScanRequest
573 \return None
574 -------------------------------------------------------------------------------*/
575static void csrScan2GOnyRequest(tpAniSirGlobal pMac,tSmeCmd *pScanCmd,
576 tCsrScanRequest *pScanRequest)
577{
578 tANI_U8 index, channelId, channelListSize = 0;
579 tANI_U8 channelList2G[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
580 static tANI_U8 validchannelList[CSR_MAX_2_4_GHZ_SUPPORTED_CHANNELS] = {0};
581
582 VOS_ASSERT(pScanCmd && pScanRequest);
Madan Mohan Koyyalamudi33ef6a22012-10-30 17:44:43 -0700583 /* To silence the KW tool null check is added */
584 if((pScanCmd == NULL) || (pScanRequest == NULL))
585 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800586 smsLog( pMac, LOGE, FL(" pScanCmd or pScanRequest is NULL "));
Madan Mohan Koyyalamudi33ef6a22012-10-30 17:44:43 -0700587 return;
588 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700589
590 if (pScanCmd->u.scanCmd.scanID ||
591 (eCSR_SCAN_REQUEST_FULL_SCAN != pScanRequest->requestType))
592 return;
593
594 //Contsruct valid Supported 2.4 GHz Channel List
595 for( index = 0; index < ARRAY_SIZE(channelList2G); index++ )
596 {
597 channelId = channelList2G[index];
598 if ( csrIsSupportedChannel( pMac, channelId ) )
599 {
600 validchannelList[channelListSize++] = channelId;
601 }
602 }
603
604 pScanRequest->ChannelInfo.numOfChannels = channelListSize;
605 pScanRequest->ChannelInfo.ChannelList = validchannelList;
606}
607
Jeff Johnson295189b2012-06-20 16:38:30 -0700608eHalStatus csrScanRequest(tpAniSirGlobal pMac, tANI_U16 sessionId,
609 tCsrScanRequest *pScanRequest, tANI_U32 *pScanRequestID,
610 csrScanCompleteCallback callback, void *pContext)
611{
612 eHalStatus status = eHAL_STATUS_FAILURE;
613 tSmeCmd *pScanCmd = NULL;
Madan Mohan Koyyalamudicb90bb22012-10-30 18:24:43 -0700614 eCsrConnectState ConnectState;
Deepthi Gowrie11da8c2016-02-04 18:18:39 +0530615
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800616 if(pScanRequest == NULL)
617 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800618 smsLog( pMac, LOGE, FL(" pScanRequest is NULL"));
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800619 VOS_ASSERT(0);
Kaushik, Sushant488df382014-03-05 11:43:47 +0530620 return eHAL_STATUS_FAILURE ;
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800621 }
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700622
Kiet Lamd1f3dc82013-11-05 20:45:04 +0530623 /* During group formation, the P2P client scans for GO with the specific SSID.
624 * There will be chances of GO switching to other channels because of scan or
625 * to STA channel in case of STA+GO MCC scenario. So to increase the possibility
626 * of client to find the GO, the dwell time of scan is increased to 100ms.
627 */
628 if(pScanRequest->p2pSearch)
629 {
Rashmi Ramanna6f7931c2013-12-20 09:04:12 +0530630 if(pScanRequest->SSIDs.numOfSSIDs)
Kiet Lamd1f3dc82013-11-05 20:45:04 +0530631 {
Rashmi Ramanna6f7931c2013-12-20 09:04:12 +0530632 //If the scan request is for specific SSId the length of SSID will be
633 //greater than 7 as SSID for p2p search contains "DIRECT-")
634 if(pScanRequest->SSIDs.SSIDList->SSID.length > DIRECT_SSID_LEN)
635 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530636 smsLog( pMac, LOG1, FL("P2P: Increasing the min and max Dwell"
637 " time to %d for specific SSID scan %.*s"),
638 MAX_CHN_TIME_TO_FIND_GO,
639 pScanRequest->SSIDs.SSIDList->SSID.length,
640 pScanRequest->SSIDs.SSIDList->SSID.ssId);
Rashmi Ramanna6f7931c2013-12-20 09:04:12 +0530641 pScanRequest->maxChnTime = MAX_CHN_TIME_TO_FIND_GO;
642 pScanRequest->minChnTime = MIN_CHN_TIME_TO_FIND_GO;
643 }
Kiet Lamd1f3dc82013-11-05 20:45:04 +0530644 }
645 }
646
Jeff Johnson295189b2012-06-20 16:38:30 -0700647 do
648 {
649 if(pMac->scan.fScanEnable)
650 {
651 pScanCmd = csrGetCommandBuffer(pMac);
652 if(pScanCmd)
653 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530654 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -0700655 pScanCmd->command = eSmeCommandScan;
656 pScanCmd->sessionId = sessionId;
657 pScanCmd->u.scanCmd.callback = callback;
658 pScanCmd->u.scanCmd.pContext = pContext;
659 if(eCSR_SCAN_REQUEST_11D_SCAN == pScanRequest->requestType)
660 {
661 pScanCmd->u.scanCmd.reason = eCsrScan11d1;
662 }
663 else if((eCSR_SCAN_REQUEST_FULL_SCAN == pScanRequest->requestType) ||
664 (eCSR_SCAN_P2P_DISCOVERY == pScanRequest->requestType)
665#ifdef SOFTAP_CHANNEL_RANGE
666 ||(eCSR_SCAN_SOFTAP_CHANNEL_RANGE == pScanRequest->requestType)
667#endif
668 )
669 {
670 pScanCmd->u.scanCmd.reason = eCsrScanUserRequest;
671 }
672 else if(eCSR_SCAN_HO_BG_SCAN == pScanRequest->requestType)
673 {
674 pScanCmd->u.scanCmd.reason = eCsrScanBgScan;
675 }
676 else if(eCSR_SCAN_HO_PROBE_SCAN == pScanRequest->requestType)
677 {
678 pScanCmd->u.scanCmd.reason = eCsrScanProbeBss;
679 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700680 else if(eCSR_SCAN_P2P_FIND_PEER == pScanRequest->requestType)
681 {
682 pScanCmd->u.scanCmd.reason = eCsrScanP2PFindPeer;
683 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700684 else
685 {
686 pScanCmd->u.scanCmd.reason = eCsrScanIdleScan;
687 }
688 if(pScanRequest->minChnTime == 0 && pScanRequest->maxChnTime == 0)
689 {
690 //The caller doesn't set the time correctly. Set it here
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530691 csrSetDefaultScanTiming(pMac, pScanRequest->scanType,
692 pScanRequest);
693 smsLog(pMac, LOG1, FL("Setting default min %d and max %d"
694 " ChnTime"), pScanRequest->minChnTime,
695 pScanRequest->maxChnTime);
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700696 }
697#ifdef WLAN_AP_STA_CONCURRENCY
698 if(pScanRequest->restTime == 0)
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800699 {
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700700 //Need to set restTime only if at least one session is connected
701 if(csrIsAnySessionConnected(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -0700702 {
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700703 pScanRequest->restTime = pMac->roam.configParam.nRestTimeConc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700704 }
705 }
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700706#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -0700707 /*For Standalone wlan : channel time will remain the same.
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530708 For BTC with A2DP up: Channel time = Channel time * 2, if station is not already associated.
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800709 This has been done to provide a larger scan window for faster connection during btc.Else Scan is seen
710 to take a long time.
711 For BTC with A2DP up: Channel time will not be doubled, if station is already associated.
712 */
Jeff Johnson32d95a32012-09-10 13:15:23 -0700713 status = csrRoamGetConnectState(pMac,sessionId,&ConnectState);
Srinivas Girigowdac84c57c2013-02-19 17:41:56 -0800714 if (HAL_STATUS_SUCCESS(status) &&
715 pMac->btc.fA2DPUp &&
Jeff Johnson32d95a32012-09-10 13:15:23 -0700716 (eCSR_ASSOC_STATE_TYPE_INFRA_ASSOCIATED != ConnectState) &&
717 (eCSR_ASSOC_STATE_TYPE_IBSS_CONNECTED != ConnectState))
718 {
719 pScanRequest->maxChnTime = pScanRequest->maxChnTime << 1;
720 pScanRequest->minChnTime = pScanRequest->minChnTime << 1;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530721 smsLog( pMac, LOG1, FL("BTC A2DP up, doubling max and min"
722 " ChnTime (Max=%d Min=%d)"),
723 pScanRequest->maxChnTime,
724 pScanRequest->minChnTime);
Jeff Johnson32d95a32012-09-10 13:15:23 -0700725 }
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800726
Kiet Lam64c1b492013-07-12 13:56:44 +0530727 pScanRequest->maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
728 pScanRequest->minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700729 //Need to make the following atomic
730 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
731
732 if(pScanRequestID)
733 {
734 *pScanRequestID = pScanCmd->u.scanCmd.scanID;
735 }
736
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800737 // If it is the first scan request from HDD, CSR checks if it is for 11d.
Jeff Johnson295189b2012-06-20 16:38:30 -0700738 // If it is not, CSR will save the scan request in the pending cmd queue
739 // & issue an 11d scan request to PE.
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800740 if (((0 == pScanCmd->u.scanCmd.scanID)
Jeff Johnson295189b2012-06-20 16:38:30 -0700741 && (eCSR_SCAN_REQUEST_11D_SCAN != pScanRequest->requestType))
742#ifdef SOFTAP_CHANNEL_RANGE
743 && (eCSR_SCAN_SOFTAP_CHANNEL_RANGE != pScanRequest->requestType)
744#endif
745 && (eANI_BOOLEAN_FALSE == pMac->scan.fEnableBypass11d)
746 )
747 {
748 tSmeCmd *p11dScanCmd;
749 tCsrScanRequest scanReq;
750 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
751
Kiet Lam64c1b492013-07-12 13:56:44 +0530752 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -0700753
754 p11dScanCmd = csrGetCommandBuffer(pMac);
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800755 if (p11dScanCmd)
Jeff Johnson295189b2012-06-20 16:38:30 -0700756 {
757 tANI_U32 numChn = pMac->scan.baseChannels.numChannels;
758
Kiet Lam64c1b492013-07-12 13:56:44 +0530759 vos_mem_set(&p11dScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
760 pChnInfo->ChannelList = vos_mem_malloc(numChn);
761 if ( NULL == pChnInfo->ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -0700762 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530763 smsLog(pMac, LOGE, FL("Failed to allocate memory"));
764 status = eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -0700765 break;
766 }
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530767 vos_mem_copy(pChnInfo->ChannelList,
768 pMac->scan.baseChannels.channelList,
769 numChn);
Jeff Johnson295189b2012-06-20 16:38:30 -0700770 pChnInfo->numOfChannels = (tANI_U8)numChn;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530771
Jeff Johnson295189b2012-06-20 16:38:30 -0700772 p11dScanCmd->command = eSmeCommandScan;
Mihir Shetefc7ff5b2014-01-27 11:30:05 +0530773 p11dScanCmd->u.scanCmd.callback = pMac->scan.callback11dScanDone;
Jeff Johnson295189b2012-06-20 16:38:30 -0700774 p11dScanCmd->u.scanCmd.pContext = NULL;
c_hpothu0d5a7352014-03-22 12:30:25 +0530775 p11dScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID;
Jeff Johnson295189b2012-06-20 16:38:30 -0700776 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
777
778 if ( csrIs11dSupported(pMac) )
779 {
c_hpothudbefd3e2014-04-28 15:59:47 +0530780 scanReq.scanType = eSIR_PASSIVE_SCAN;
Jeff Johnson295189b2012-06-20 16:38:30 -0700781 scanReq.requestType = eCSR_SCAN_REQUEST_11D_SCAN;
782 p11dScanCmd->u.scanCmd.reason = eCsrScan11d1;
783 scanReq.maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
784 scanReq.minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
785 }
786 else
787 {
c_hpothudbefd3e2014-04-28 15:59:47 +0530788 scanReq.scanType = pScanRequest->scanType;
Jeff Johnson295189b2012-06-20 16:38:30 -0700789 scanReq.requestType = eCSR_SCAN_IDLE_MODE_SCAN;
790 p11dScanCmd->u.scanCmd.reason = eCsrScanIdleScan;
791 scanReq.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
792 scanReq.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800793
Madan Mohan Koyyalamudi04a65f02013-07-26 13:58:38 +0530794 scanReq.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
795 scanReq.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700796 }
c_hpothu059edb02014-03-12 21:44:28 +0530797 if (pMac->roam.configParam.nInitialDwellTime)
798 {
799 scanReq.maxChnTime =
800 pMac->roam.configParam.nInitialDwellTime;
801 smsLog(pMac, LOG1, FL("11d scan, updating"
802 "dwell time for first scan %u"),
803 scanReq.maxChnTime);
804 }
Deepthi Gowrie11da8c2016-02-04 18:18:39 +0530805 if ((pScanCmd->u.scanCmd.reason == eCsrScanUserRequest)
806 && !(pScanRequest->p2pSearch)
Gupta, Kapilb79cda32015-12-30 20:36:33 +0530807 &&(pScanRequest->ChannelInfo.numOfChannels
808 < pMac->roam.configParam.
809 max_chan_for_dwell_time_cfg))
810 {
811 pScanRequest->maxChnTime =
812 pScanRequest->maxChnTime << 1;
813 pScanRequest->minChnTime =
814 pScanRequest->minChnTime << 1;
815 smsLog(pMac, LOG1,
816 FL("Double ChnTime (Max=%d Min=%d) numOfChannels=%d max_chan_for_dwell_time_cfg=%d"),
817 pScanRequest->maxChnTime,
818 pScanRequest->minChnTime,
819 pScanRequest->ChannelInfo.numOfChannels,
820 pMac->roam.configParam.
821 max_chan_for_dwell_time_cfg);
822 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700823
Jeff Johnson295189b2012-06-20 16:38:30 -0700824 status = csrScanCopyRequest(pMac, &p11dScanCmd->u.scanCmd.u.scanRequest, &scanReq);
825 //Free the channel list
Kiet Lam64c1b492013-07-12 13:56:44 +0530826 vos_mem_free(pChnInfo->ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -0700827 pChnInfo->ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -0700828
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800829 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700830 {
krunal soni5f112f02013-11-25 15:00:11 -0800831 pMac->scan.scanProfile.numOfChannels =
832 p11dScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -0700833 //Start process the command
834#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +0530835 if (!pMac->fScanOffload)
836 status = csrQueueScanRequest(pMac, p11dScanCmd);
837 else
838 status = csrQueueSmeCommand(pMac, p11dScanCmd,
839 eANI_BOOLEAN_FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -0700840#else
841 status = csrQueueSmeCommand(pMac, p11dScanCmd, eANI_BOOLEAN_FALSE);
842#endif
843 if( !HAL_STATUS_SUCCESS( status ) )
844 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530845 smsLog(pMac, LOGE, FL("Failed to send message"
846 " status = %d"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -0700847 break;
848 }
849 }
850 else
851 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530852 smsLog(pMac, LOGE, FL("csrScanCopyRequest failed"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700853 break;
854 }
855 }
856 else
857 {
858 //error
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530859 smsLog( pMac, LOGE, FL("p11dScanCmd failed") );
Jeff Johnson295189b2012-06-20 16:38:30 -0700860 break;
861 }
862 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700863
864 //Scan only 2G Channels if set in ini file
865 //This is mainly to reduce the First Scan duration
866 //Once we turn on Wifi
867 if(pMac->scan.fFirstScanOnly2GChnl)
868 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800869 smsLog( pMac, LOG1, FL("Scanning only 2G Channels during first scan"));
Jeff Johnsone7245742012-09-05 17:12:55 -0700870 csrScan2GOnyRequest(pMac, pScanCmd, pScanRequest);
871 }
872
c_hpothu059edb02014-03-12 21:44:28 +0530873 if (pMac->roam.configParam.nInitialDwellTime)
874 {
875 pScanRequest->maxChnTime =
876 pMac->roam.configParam.nInitialDwellTime;
877 pMac->roam.configParam.nInitialDwellTime = 0;
878 smsLog(pMac, LOG1,
879 FL("updating dwell time for first scan %u"),
880 pScanRequest->maxChnTime);
881 }
882
Deepthi Gowrie11da8c2016-02-04 18:18:39 +0530883 if ((pScanCmd->u.scanCmd.reason == eCsrScanUserRequest)
884 && !(pScanRequest->p2pSearch)
Gupta, Kapilb79cda32015-12-30 20:36:33 +0530885 && (pScanRequest->ChannelInfo.numOfChannels
886 < pMac->roam.configParam.max_chan_for_dwell_time_cfg))
887 {
888 pScanRequest->maxChnTime = pScanRequest->maxChnTime << 1;
889 pScanRequest->minChnTime = pScanRequest->minChnTime << 1;
890 smsLog(pMac, LOG1,
891 FL("Double ChnTime (Max=%d Min=%d) numOfChannels=%d max_chan_for_dwell_time_cfg=%d"),
892 pScanRequest->maxChnTime,
893 pScanRequest->minChnTime,
894 pScanRequest->ChannelInfo.numOfChannels,
895 pMac->roam.configParam.max_chan_for_dwell_time_cfg);
896 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700897 status = csrScanCopyRequest(pMac, &pScanCmd->u.scanCmd.u.scanRequest, pScanRequest);
898 if(HAL_STATUS_SUCCESS(status))
899 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530900 tCsrScanRequest *pTempScanReq =
901 &pScanCmd->u.scanCmd.u.scanRequest;
krunal soni5f112f02013-11-25 15:00:11 -0800902 pMac->scan.scanProfile.numOfChannels =
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530903 pTempScanReq->ChannelInfo.numOfChannels;
krunal soni5f112f02013-11-25 15:00:11 -0800904
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530905 smsLog( pMac, LOG1, FL(" SId=%d scanId=%d"
906 " Scan reason=%u numSSIDs=%d"
907 " numChan=%d P2P search=%d minCT=%d maxCT=%d"
908 " minCBtc=%d maxCBtx=%d"),
909 sessionId, pScanCmd->u.scanCmd.scanID,
910 pScanCmd->u.scanCmd.reason,
911 pTempScanReq->SSIDs.numOfSSIDs,
912 pTempScanReq->ChannelInfo.numOfChannels,
913 pTempScanReq->p2pSearch,
914 pTempScanReq->minChnTime,
915 pTempScanReq->maxChnTime,
916 pTempScanReq->minChnTimeBtc,
917 pTempScanReq->maxChnTimeBtc );
Jeff Johnson295189b2012-06-20 16:38:30 -0700918 //Start process the command
919#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +0530920 if (!pMac->fScanOffload)
921 status = csrQueueScanRequest(pMac,pScanCmd);
922 else
923 status = csrQueueSmeCommand(pMac, pScanCmd,
924 eANI_BOOLEAN_FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -0700925#else
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530926 status = csrQueueSmeCommand(pMac, pScanCmd,
927 eANI_BOOLEAN_FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -0700928#endif
929 if( !HAL_STATUS_SUCCESS( status ) )
930 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800931 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700932 break;
933 }
934 }
935 else
936 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800937 smsLog( pMac, LOGE, FL(" fail to copy request status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700938 break;
939 }
940 }
941 else
942 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800943 smsLog( pMac, LOGE, FL(" pScanCmd is NULL"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700944 break;
945 }
946 }
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530947 else
948 {
949 smsLog( pMac, LOGE, FL("SId: %d Scanning not enabled"
950 " Scan type=%u, numOfSSIDs=%d P2P search=%d"),
951 sessionId, pScanRequest->requestType,
952 pScanRequest->SSIDs.numOfSSIDs,
953 pScanRequest->p2pSearch );
954 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700955 } while(0);
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530956
957
Jeff Johnson295189b2012-06-20 16:38:30 -0700958 if(!HAL_STATUS_SUCCESS(status) && pScanCmd)
959 {
960 if( eCsrScanIdleScan == pScanCmd->u.scanCmd.reason )
961 {
962 //Set the flag back for restarting idle scan
963 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
964 }
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530965 smsLog( pMac, LOGE, FL(" SId: %d Failed with status=%d"
966 " Scan reason=%u numOfSSIDs=%d"
967 " P2P search=%d scanId=%d"),
968 sessionId, status, pScanCmd->u.scanCmd.reason,
969 pScanRequest->SSIDs.numOfSSIDs, pScanRequest->p2pSearch,
970 pScanCmd->u.scanCmd.scanID );
Jeff Johnson295189b2012-06-20 16:38:30 -0700971 csrReleaseCommandScan(pMac, pScanCmd);
972 }
973
974 return (status);
975}
976
977
978eHalStatus csrScanRequestResult(tpAniSirGlobal pMac)
979{
980 eHalStatus status = eHAL_STATUS_SUCCESS;
981 tSmeCmd *pScanCmd;
982
983 if(pMac->scan.fScanEnable)
984 {
985 pScanCmd = csrGetCommandBuffer(pMac);
986 if(pScanCmd)
987 {
988 pScanCmd->command = eSmeCommandScan;
Kiet Lam64c1b492013-07-12 13:56:44 +0530989 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -0700990 pScanCmd->u.scanCmd.callback = NULL;
991 pScanCmd->u.scanCmd.pContext = NULL;
992 pScanCmd->u.scanCmd.reason = eCsrScanGetResult;
993 //Need to make the following atomic
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -0700994 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID; //let it wrap around
Jeff Johnson295189b2012-06-20 16:38:30 -0700995 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
996 if( !HAL_STATUS_SUCCESS( status ) )
997 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800998 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700999 csrReleaseCommandScan(pMac, pScanCmd);
1000 }
1001 }
1002 else
1003 {
1004 //log error
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001005 smsLog(pMac, LOGE, FL("can not obtain a common buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001006 status = eHAL_STATUS_RESOURCES;
1007 }
1008 }
1009
1010 return (status);
1011}
1012
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07001013#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
1014eHalStatus csrScanRequestLfrResult(tpAniSirGlobal pMac, tANI_U32 sessionId,
1015 csrScanCompleteCallback callback, void *pContext)
1016{
1017 eHalStatus status = eHAL_STATUS_SUCCESS;
1018 tSmeCmd *pScanCmd;
1019
1020 if (pMac->scan.fScanEnable)
1021 {
1022 pScanCmd = csrGetCommandBuffer(pMac);
1023 if (pScanCmd)
1024 {
1025 pScanCmd->command = eSmeCommandScan;
1026 pScanCmd->sessionId = sessionId;
Kiet Lam64c1b492013-07-12 13:56:44 +05301027 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07001028 pScanCmd->u.scanCmd.callback = callback;
1029 pScanCmd->u.scanCmd.pContext = pContext;
1030 pScanCmd->u.scanCmd.reason = eCsrScanGetLfrResult;
1031 //Need to make the following atomic
1032 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID; //let it wrap around
1033 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_TRUE);
1034 if ( !HAL_STATUS_SUCCESS( status ) )
1035 {
1036 smsLog( pMac, LOGE, FL(" fail to send message status = %d\n"), status );
1037 csrReleaseCommandScan(pMac, pScanCmd);
1038 }
1039 }
1040 else
1041 {
1042 //log error
1043 smsLog(pMac, LOGE, FL("can not obtain a common buffer\n"));
1044 status = eHAL_STATUS_RESOURCES;
1045 }
1046 }
1047
1048 return (status);
1049}
1050#endif //WLAN_FEATURE_ROAM_SCAN_OFFLOAD
Jeff Johnson295189b2012-06-20 16:38:30 -07001051
1052eHalStatus csrScanAllChannels(tpAniSirGlobal pMac, eCsrRequestType reqType)
1053{
1054 eHalStatus status = eHAL_STATUS_SUCCESS;
1055 tANI_U32 scanId;
1056 tCsrScanRequest scanReq;
1057
Kiet Lam64c1b492013-07-12 13:56:44 +05301058 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001059 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
1060 scanReq.scanType = eSIR_ACTIVE_SCAN;
1061 scanReq.requestType = reqType;
1062 scanReq.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1063 scanReq.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001064 scanReq.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1065 scanReq.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001066 //Scan with invalid sessionId.
1067 //This results in SME using the first available session to scan.
1068 status = csrScanRequest(pMac, CSR_SESSION_ID_INVALID, &scanReq,
1069 &scanId, NULL, NULL);
1070
1071 return (status);
1072}
1073
1074
1075
1076
1077eHalStatus csrIssueRoamAfterLostlinkScan(tpAniSirGlobal pMac, tANI_U32 sessionId, eCsrRoamReason reason)
1078{
1079 eHalStatus status = eHAL_STATUS_FAILURE;
1080 tScanResultHandle hBSSList = NULL;
1081 tCsrScanResultFilter *pScanFilter = NULL;
1082 tANI_U32 roamId = 0;
1083 tCsrRoamProfile *pProfile = NULL;
1084 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1085
Jeff Johnson32d95a32012-09-10 13:15:23 -07001086 if(!pSession)
1087 {
1088 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1089 return eHAL_STATUS_FAILURE;
1090 }
1091
Jeff Johnson295189b2012-06-20 16:38:30 -07001092 do
1093 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001094 smsLog(pMac, LOG1, " csrIssueRoamAfterLostlinkScan called");
Jeff Johnson295189b2012-06-20 16:38:30 -07001095 if(pSession->fCancelRoaming)
1096 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001097 smsLog(pMac, LOGW, " lostlink roaming is cancelled");
Jeff Johnson295189b2012-06-20 16:38:30 -07001098 csrScanStartIdleScan(pMac);
1099 status = eHAL_STATUS_SUCCESS;
1100 break;
1101 }
1102 //Here is the profile we need to connect to
Kiet Lam64c1b492013-07-12 13:56:44 +05301103 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1104 if ( NULL == pScanFilter)
1105 status = eHAL_STATUS_FAILURE;
1106 else
1107 status = eHAL_STATUS_SUCCESS;
1108 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001109 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301110 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001111 if(NULL == pSession->pCurRoamProfile)
1112 {
1113 pScanFilter->EncryptionType.numEntries = 1;
1114 pScanFilter->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_NONE;
1115 }
1116 else
1117 {
1118 //We have to make a copy of pCurRoamProfile because it will be free inside csrRoamIssueConnect
Kiet Lam64c1b492013-07-12 13:56:44 +05301119 pProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1120 if ( NULL == pProfile )
1121 status = eHAL_STATUS_FAILURE;
1122 else
1123 status = eHAL_STATUS_SUCCESS;
1124 if (!HAL_STATUS_SUCCESS(status))
1125 break;
1126 vos_mem_set(pProfile, sizeof(tCsrRoamProfile), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001127 status = csrRoamCopyProfile(pMac, pProfile, pSession->pCurRoamProfile);
1128 if(!HAL_STATUS_SUCCESS(status))
1129 break;
1130 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1131 }//We have a profile
1132 roamId = GET_NEXT_ROAM_ID(&pMac->roam);
1133 if(HAL_STATUS_SUCCESS(status))
1134 {
1135 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1136 if(HAL_STATUS_SUCCESS(status))
1137 {
1138 if(eCsrLostLink1 == reason)
1139 {
1140 //we want to put the last connected BSS to the very beginning, if possible
1141 csrMoveBssToHeadFromBSSID(pMac, &pSession->connectedProfile.bssid, hBSSList);
1142 }
1143 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList, reason,
1144 roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1145 if(!HAL_STATUS_SUCCESS(status))
1146 {
1147 csrScanResultPurge(pMac, hBSSList);
1148 }
1149 }//Have scan result
1150 }
1151 }while(0);
1152 if(pScanFilter)
1153 {
1154 //we need to free memory for filter if profile exists
1155 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301156 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001157 }
1158 if(NULL != pProfile)
1159 {
1160 csrReleaseProfile(pMac, pProfile);
Kiet Lam64c1b492013-07-12 13:56:44 +05301161 vos_mem_free(pProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07001162 }
1163
1164 return (status);
1165}
1166
1167
Ratheesh S Pece1f832015-07-25 15:50:25 +05301168eHalStatus csrScanGetScanChnInfo(tpAniSirGlobal pMac, tSmeCmd *pCommand)
Jeff Johnson295189b2012-06-20 16:38:30 -07001169{
1170 eHalStatus status = eHAL_STATUS_SUCCESS;
1171 tSmeCmd *pScanCmd;
1172
1173 if(pMac->scan.fScanEnable)
1174 {
1175 pScanCmd = csrGetCommandBuffer(pMac);
1176 if(pScanCmd)
1177 {
1178 pScanCmd->command = eSmeCommandScan;
Kiet Lam64c1b492013-07-12 13:56:44 +05301179 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001180 pScanCmd->u.scanCmd.reason = eCsrScanGetScanChnInfo;
1181 //Need to make the following atomic
1182 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Ratheesh S Pece1f832015-07-25 15:50:25 +05301183 pScanCmd->sessionId = pCommand->sessionId;
1184 if( pCommand->u.scanCmd.reason == eCsrScanUserRequest)
1185 {
1186 pScanCmd->u.scanCmd.callback = NULL;
1187 pScanCmd->u.scanCmd.pContext = NULL;
1188 } else {
1189 pScanCmd->u.scanCmd.callback = pCommand->u.scanCmd.callback;
1190 pScanCmd->u.scanCmd.pContext = pCommand->u.scanCmd.pContext;
1191 pScanCmd->u.scanCmd.abortScanIndication =
1192 pCommand->u.scanCmd.abortScanIndication;
1193 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001194 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
1195 if( !HAL_STATUS_SUCCESS( status ) )
1196 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001197 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001198 csrReleaseCommandScan(pMac, pScanCmd);
1199 }
1200 }
1201 else
1202 {
1203 //log error
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001204 smsLog(pMac, LOGE, FL("can not obtain a common buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001205 status = eHAL_STATUS_RESOURCES;
1206 }
1207 }
1208
1209 return (status);
1210}
1211
1212
1213eHalStatus csrScanHandleFailedLostlink1(tpAniSirGlobal pMac, tANI_U32 sessionId)
1214{
1215 eHalStatus status = eHAL_STATUS_FAILURE;
1216 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1217
Jeff Johnson32d95a32012-09-10 13:15:23 -07001218 if(!pSession)
1219 {
1220 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1221 return eHAL_STATUS_FAILURE;
1222 }
1223
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001224 smsLog(pMac, LOGW, " Lostlink scan 1 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001225 if(pSession->fCancelRoaming)
1226 {
1227 csrScanStartIdleScan(pMac);
1228 }
1229 else if(pSession->pCurRoamProfile)
1230 {
1231 //We fail lostlink1 but there may be other BSS in the cached result fit the profile. Give it a try first
1232 if(pSession->pCurRoamProfile->SSIDs.numOfSSIDs == 0 ||
1233 pSession->pCurRoamProfile->SSIDs.numOfSSIDs > 1)
1234 {
1235 //try lostlink scan2
1236 status = csrScanRequestLostLink2(pMac, sessionId);
1237 }
1238 else if(!pSession->pCurRoamProfile->ChannelInfo.ChannelList ||
1239 pSession->pCurRoamProfile->ChannelInfo.ChannelList[0] == 0)
1240 {
1241 //go straight to lostlink scan3
1242 status = csrScanRequestLostLink3(pMac, sessionId);
1243 }
1244 else
1245 {
1246 //we are done with lostlink
1247 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1248 {
1249 csrScanStartIdleScan(pMac);
1250 }
1251 status = eHAL_STATUS_SUCCESS;
1252 }
1253 }
1254 else
1255 {
1256 status = csrScanRequestLostLink3(pMac, sessionId);
1257 }
1258
1259 return (status);
1260}
1261
1262
1263
1264eHalStatus csrScanHandleFailedLostlink2(tpAniSirGlobal pMac, tANI_U32 sessionId)
1265{
1266 eHalStatus status = eHAL_STATUS_FAILURE;
1267 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1268
Jeff Johnson32d95a32012-09-10 13:15:23 -07001269 if(!pSession)
1270 {
1271 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1272 return eHAL_STATUS_FAILURE;
1273 }
1274
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001275 smsLog(pMac, LOGW, " Lostlink scan 2 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001276 if(pSession->fCancelRoaming)
1277 {
1278 csrScanStartIdleScan(pMac);
1279 }
1280 else if(!pSession->pCurRoamProfile || !pSession->pCurRoamProfile->ChannelInfo.ChannelList ||
1281 pSession->pCurRoamProfile->ChannelInfo.ChannelList[0] == 0)
1282 {
1283 //try lostlink scan3
1284 status = csrScanRequestLostLink3(pMac, sessionId);
1285 }
1286 else
1287 {
1288 //we are done with lostlink
1289 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1290 {
1291 csrScanStartIdleScan(pMac);
1292 }
1293 }
1294
1295 return (status);
1296}
1297
1298
1299
1300eHalStatus csrScanHandleFailedLostlink3(tpAniSirGlobal pMac, tANI_U32 sessionId)
1301{
1302 eHalStatus status = eHAL_STATUS_SUCCESS;
1303
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001304 smsLog(pMac, LOGW, " Lostlink scan 3 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001305 if(eANI_BOOLEAN_TRUE == csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1306 {
1307 //we are done with lostlink
1308 csrScanStartIdleScan(pMac);
1309 }
1310
1311 return (status);
1312}
1313
1314
1315
1316
1317//Lostlink1 scan is to actively scan the last connected profile's SSID on all matched BSS channels.
1318//If no roam profile (it should not), it is like lostlinkscan3
1319eHalStatus csrScanRequestLostLink1( tpAniSirGlobal pMac, tANI_U32 sessionId )
1320{
1321 eHalStatus status = eHAL_STATUS_SUCCESS;
1322 tSmeCmd *pCommand = NULL;
1323 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1324 tCsrScanResultFilter *pScanFilter = NULL;
1325 tScanResultHandle hBSSList = NULL;
1326 tCsrScanResultInfo *pScanResult = NULL;
1327 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1328
Jeff Johnson32d95a32012-09-10 13:15:23 -07001329 if(!pSession)
1330 {
1331 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1332 return eHAL_STATUS_FAILURE;
1333 }
1334
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001335 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001336 do
1337 {
1338 pCommand = csrGetCommandBuffer(pMac);
1339 if(!pCommand)
1340 {
1341 status = eHAL_STATUS_RESOURCES;
1342 break;
1343 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301344 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001345 pCommand->command = eSmeCommandScan;
1346 pCommand->sessionId = (tANI_U8)sessionId;
1347 pCommand->u.scanCmd.reason = eCsrScanLostLink1;
1348 pCommand->u.scanCmd.callback = NULL;
1349 pCommand->u.scanCmd.pContext = NULL;
1350 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1351 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001352 pCommand->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1353 pCommand->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001354 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
1355 if(pSession->connectedProfile.SSID.length)
1356 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301357 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList = vos_mem_malloc(sizeof(tCsrSSIDInfo));
1358 if ( NULL == pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList )
1359 status = eHAL_STATUS_FAILURE;
1360 else
1361 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001362 if(!HAL_STATUS_SUCCESS(status))
1363 {
1364 break;
1365 }
1366 pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 1;
Kiet Lam64c1b492013-07-12 13:56:44 +05301367 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID,
1368 &pSession->connectedProfile.SSID, sizeof(tSirMacSSid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001369 }
1370 else
1371 {
1372 pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 0;
1373 }
1374 if(pSession->pCurRoamProfile)
1375 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301376 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1377 if ( NULL == pScanFilter )
1378 status = eHAL_STATUS_FAILURE;
1379 else
1380 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001381 if(!HAL_STATUS_SUCCESS(status))
1382 {
1383 break;
1384 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301385 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001386 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
1387 if(!HAL_STATUS_SUCCESS(status))
1388 {
1389 break;
1390 }
1391 //Don't change variable status here because whether we can get result or not, the command goes to PE.
1392 //The status is also used to indicate whether the command is queued. Not success meaning not queue
1393 if(HAL_STATUS_SUCCESS((csrScanGetResult(pMac, pScanFilter, &hBSSList))) && hBSSList)
1394 {
1395 tANI_U8 i, nChn = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05301396 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList =
1397 vos_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
1398 if ( NULL == pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
1399 status = eHAL_STATUS_FAILURE;
1400 else
1401 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001402 if(!HAL_STATUS_SUCCESS(status))
1403 {
1404 break;
1405 }
1406 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) &&
1407 nChn < WNI_CFG_VALID_CHANNEL_LIST_LEN)
1408 {
1409 for(i = 0; i < nChn; i++)
1410 {
1411 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1412 pScanResult->BssDescriptor.channelId)
1413 {
1414 break;
1415 }
1416 }
1417 if(i == nChn)
1418 {
1419 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pScanResult->BssDescriptor.channelId;
1420 }
1421 }
1422 //Include the last connected BSS' channel
1423 if(csrRoamIsChannelValid(pMac, pSession->connectedProfile.operationChannel))
1424 {
1425 for(i = 0; i < nChn; i++)
1426 {
1427 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1428 pSession->connectedProfile.operationChannel)
1429 {
1430 break;
1431 }
1432 }
1433 if(i == nChn)
1434 {
1435 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pSession->connectedProfile.operationChannel;
1436 }
1437 }
1438 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nChn;
1439 }
1440 else
1441 {
1442 if(csrRoamIsChannelValid(pMac, pSession->connectedProfile.operationChannel))
1443 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301444 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(1);
1445 if ( NULL == pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
1446 status = eHAL_STATUS_FAILURE;
1447 else
1448 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001449 //just try the last connected channel
1450 if(HAL_STATUS_SUCCESS(status))
1451 {
1452 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[0] = pSession->connectedProfile.operationChannel;
1453 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 1;
1454 }
1455 else
1456 {
1457 break;
1458 }
1459 }
1460 }
1461 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301462 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001463 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
1464 if( !HAL_STATUS_SUCCESS( status ) )
1465 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001466 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001467 break;
1468 }
1469 } while( 0 );
1470
1471 if(!HAL_STATUS_SUCCESS(status))
1472 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001473 smsLog(pMac, LOGW, " csrScanRequestLostLink1 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001474 if(pCommand)
1475 {
1476 csrReleaseCommandScan(pMac, pCommand);
1477 }
1478 status = csrScanHandleFailedLostlink1( pMac, sessionId );
1479 }
1480 if(pScanFilter)
1481 {
1482 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301483 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001484 }
1485 if(hBSSList)
1486 {
1487 csrScanResultPurge(pMac, hBSSList);
1488 }
1489
1490 return( status );
1491}
1492
1493
1494//Lostlink2 scan is to actively scan the all SSIDs of the last roaming profile's on all matched BSS channels.
1495//Since MAC doesn't support multiple SSID, we scan all SSIDs and filter them afterwards
1496eHalStatus csrScanRequestLostLink2( tpAniSirGlobal pMac, tANI_U32 sessionId )
1497{
1498 eHalStatus status = eHAL_STATUS_SUCCESS;
1499 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1500 tCsrScanResultFilter *pScanFilter = NULL;
1501 tScanResultHandle hBSSList = NULL;
1502 tCsrScanResultInfo *pScanResult = NULL;
1503 tSmeCmd *pCommand = NULL;
1504 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1505
Jeff Johnson32d95a32012-09-10 13:15:23 -07001506 if(!pSession)
1507 {
1508 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1509 return eHAL_STATUS_FAILURE;
1510 }
1511
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001512 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001513 do
1514 {
1515 pCommand = csrGetCommandBuffer(pMac);
1516 if(!pCommand)
1517 {
1518 status = eHAL_STATUS_RESOURCES;
1519 break;
1520 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301521 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001522 pCommand->command = eSmeCommandScan;
1523 pCommand->sessionId = (tANI_U8)sessionId;
1524 pCommand->u.scanCmd.reason = eCsrScanLostLink2;
1525 pCommand->u.scanCmd.callback = NULL;
1526 pCommand->u.scanCmd.pContext = NULL;
1527 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1528 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001529 pCommand->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1530 pCommand->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001531 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
1532 if(pSession->pCurRoamProfile)
1533 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301534 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1535 if ( NULL == pScanFilter )
1536 status = eHAL_STATUS_FAILURE;
1537 else
1538 status = eHAL_STATUS_SUCCESS;
1539 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001540 {
1541 break;
1542 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301543 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001544 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
1545 if(!HAL_STATUS_SUCCESS(status))
1546 {
1547 break;
1548 }
1549 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1550 if(!HAL_STATUS_SUCCESS(status))
1551 {
1552 break;
1553 }
1554 if(hBSSList)
1555 {
1556 tANI_U8 i, nChn = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05301557 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList =
1558 vos_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
1559 if ( NULL == pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
1560 status = eHAL_STATUS_FAILURE;
1561 else
1562 status = eHAL_STATUS_SUCCESS;
1563 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001564 {
1565 break;
1566 }
1567 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) &&
1568 nChn < WNI_CFG_VALID_CHANNEL_LIST_LEN)
1569 {
1570 for(i = 0; i < nChn; i++)
1571 {
1572 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1573 pScanResult->BssDescriptor.channelId)
1574 {
1575 break;
1576 }
1577 }
1578 if(i == nChn)
1579 {
1580 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pScanResult->BssDescriptor.channelId;
1581 }
1582 }
1583 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nChn;
1584 }
1585 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301586 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001587 //Put to the head in pending queue
1588 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_TRUE);
1589 if( !HAL_STATUS_SUCCESS( status ) )
1590 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001591 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001592 break;
1593 }
1594 } while( 0 );
1595
1596 if(!HAL_STATUS_SUCCESS(status))
1597 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001598 smsLog(pMac, LOGW, " csrScanRequestLostLink2 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001599 if(pCommand)
1600 {
1601 csrReleaseCommandScan(pMac, pCommand);
1602 }
1603 status = csrScanHandleFailedLostlink2( pMac, sessionId );
1604 }
1605 if(pScanFilter)
1606 {
1607 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301608 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001609 }
1610 if(hBSSList)
1611 {
1612 csrScanResultPurge(pMac, hBSSList);
1613 }
1614
1615 return( status );
1616}
1617
1618
1619//To actively scan all valid channels
1620eHalStatus csrScanRequestLostLink3( tpAniSirGlobal pMac, tANI_U32 sessionId )
1621{
1622 eHalStatus status = eHAL_STATUS_SUCCESS;
1623 tSmeCmd *pCommand;
1624 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1625
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001626 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001627 do
1628 {
1629 pCommand = csrGetCommandBuffer(pMac);
1630 if(!pCommand)
1631 {
1632 status = eHAL_STATUS_RESOURCES;
1633 break;
1634 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301635 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001636 pCommand->command = eSmeCommandScan;
1637 pCommand->sessionId = (tANI_U8)sessionId;
1638 pCommand->u.scanCmd.reason = eCsrScanLostLink3;
1639 pCommand->u.scanCmd.callback = NULL;
1640 pCommand->u.scanCmd.pContext = NULL;
1641 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1642 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001643 pCommand->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1644 pCommand->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001645 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Kiet Lam64c1b492013-07-12 13:56:44 +05301646 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001647 //Put to the head of pending queue
1648 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_TRUE);
1649 if( !HAL_STATUS_SUCCESS( status ) )
1650 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001651 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001652 break;
1653 }
1654 } while( 0 );
1655 if(!HAL_STATUS_SUCCESS(status))
1656 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001657 smsLog(pMac, LOGW, " csrScanRequestLostLink3 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001658 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1659 {
1660 csrScanStartIdleScan(pMac);
1661 }
1662 if(pCommand)
1663 {
1664 csrReleaseCommandScan(pMac, pCommand);
1665 }
1666 }
1667
1668 return( status );
1669}
1670
1671
1672eHalStatus csrScanHandleSearchForSSID(tpAniSirGlobal pMac, tSmeCmd *pCommand)
1673{
1674 eHalStatus status = eHAL_STATUS_FAILURE;
1675 tScanResultHandle hBSSList = CSR_INVALID_SCANRESULT_HANDLE;
1676 tCsrScanResultFilter *pScanFilter = NULL;
1677 tCsrRoamProfile *pProfile = pCommand->u.scanCmd.pToRoamProfile;
1678 tANI_U32 sessionId = pCommand->sessionId;
Abhishek Singhd61b97a2015-12-17 15:23:52 +05301679 tCsrRoamSession *pSession = CSR_GET_SESSION(pMac, sessionId);
1680
Jeff Johnson295189b2012-06-20 16:38:30 -07001681 do
1682 {
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001683#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
1684 //if this scan is for LFR
1685 if(pMac->roam.neighborRoamInfo.uOsRequestedHandoff)
1686 {
1687 //notify LFR state m/c
1688 if(eHAL_STATUS_SUCCESS != csrNeighborRoamSssidScanDone(pMac, eHAL_STATUS_SUCCESS))
1689 {
Mukul Sharma20aa6582014-08-07 21:36:12 +05301690 csrNeighborRoamStartLfrScan(pMac, REASON_OS_REQUESTED_ROAMING_NOW);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001691 }
1692 status = eHAL_STATUS_SUCCESS;
1693 break;
1694 }
1695#endif
Abhishek Singhd61b97a2015-12-17 15:23:52 +05301696 if (!pSession)
1697 {
1698 smsLog(pMac, LOGE, FL("session %d not found"), sessionId);
1699 break;
1700 }
Abhishek Singhd18028d2016-02-11 17:45:54 +05301701 /* If Disconnect is already issued from HDD no need to issue connect
1702 * pSession->abortConnection will not be set in case of try
1703 * disconnect or hdd stop adaptor use connectState for these cases.
1704 */
1705 if (pSession->abortConnection ||
1706 (pMac->roam.roamSession[sessionId].connectState ==
1707 eCSR_ASSOC_STATE_TYPE_INFRA_DISCONNECTING))
Abhishek Singhd61b97a2015-12-17 15:23:52 +05301708 {
1709 smsLog(pMac, LOGE,
1710 FL("Disconnect in progress, no need to issue connect"));
1711 break;
1712 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001713 //If there is roam command waiting, ignore this roam because the newer roam command is the one to execute
1714 if(csrIsRoamCommandWaitingForSession(pMac, sessionId))
1715 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001716 smsLog(pMac, LOGW, FL(" aborts because roam command waiting"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001717 break;
1718 }
1719 if(pProfile == NULL)
1720 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301721 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1722 if ( NULL == pScanFilter )
1723 status = eHAL_STATUS_FAILURE;
1724 else
1725 status = eHAL_STATUS_SUCCESS;
1726 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001727 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301728 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001729 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1730 if(!HAL_STATUS_SUCCESS(status))
1731 break;
1732 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1733 if(!HAL_STATUS_SUCCESS(status))
1734 break;
1735 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList, eCsrHddIssued,
1736 pCommand->u.scanCmd.roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1737 if(!HAL_STATUS_SUCCESS(status))
1738 {
1739 break;
1740 }
1741 }while(0);
1742 if(!HAL_STATUS_SUCCESS(status))
1743 {
1744 if(CSR_INVALID_SCANRESULT_HANDLE != hBSSList)
1745 {
1746 csrScanResultPurge(pMac, hBSSList);
1747 }
1748 //We haven't done anything to this profile
1749 csrRoamCallCallback(pMac, sessionId, NULL, pCommand->u.scanCmd.roamId,
1750 eCSR_ROAM_ASSOCIATION_FAILURE, eCSR_ROAM_RESULT_FAILURE);
1751 //In case we have nothing else to do, restart idle scan
1752 if(csrIsConnStateDisconnected(pMac, sessionId) && !csrIsRoamCommandWaiting(pMac))
1753 {
1754 status = csrScanStartIdleScan(pMac);
1755 }
1756#ifdef FEATURE_WLAN_BTAMP_UT_RF
1757 //In case of WDS station, let it retry.
1758 if( CSR_IS_WDS_STA(pProfile) )
1759 {
1760 //Save the roma profile so we can retry
1761 csrFreeRoamProfile( pMac, sessionId );
Kiet Lam64c1b492013-07-12 13:56:44 +05301762 pSession->pCurRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1763 if ( NULL != pSession->pCurRoamProfile )
Jeff Johnson295189b2012-06-20 16:38:30 -07001764 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301765 vos_mem_set(pSession->pCurRoamProfilee, sizeof(tCsrRoamProfile), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001766 csrRoamCopyProfile(pMac, pSession->pCurRoamProfile, pProfile);
1767 }
1768 csrRoamStartJoinRetryTimer(pMac, sessionId, CSR_JOIN_RETRY_TIMEOUT_PERIOD);
1769 }
1770#endif
1771 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301772 if (pScanFilter)
Jeff Johnson295189b2012-06-20 16:38:30 -07001773 {
1774 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301775 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001776 }
1777
1778 return (status);
1779}
1780
1781
1782eHalStatus csrScanHandleSearchForSSIDFailure(tpAniSirGlobal pMac, tSmeCmd *pCommand)
1783{
1784 eHalStatus status = eHAL_STATUS_SUCCESS;
1785 tANI_U32 sessionId = pCommand->sessionId;
1786 tCsrRoamProfile *pProfile = pCommand->u.scanCmd.pToRoamProfile;
1787 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001788#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
1789 //if this scan is for LFR
1790 if(pMac->roam.neighborRoamInfo.uOsRequestedHandoff)
1791 {
1792 //notify LFR state m/c
1793 if(eHAL_STATUS_SUCCESS != csrNeighborRoamSssidScanDone(pMac, eHAL_STATUS_FAILURE))
1794 {
Mukul Sharma20aa6582014-08-07 21:36:12 +05301795 csrNeighborRoamStartLfrScan(pMac, REASON_OS_REQUESTED_ROAMING_NOW);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001796 }
1797 return eHAL_STATUS_SUCCESS;
1798 }
1799#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -07001800 if(!pSession)
1801 {
1802 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1803 return eHAL_STATUS_FAILURE;
1804 }
1805
Jeff Johnson295189b2012-06-20 16:38:30 -07001806#if defined(WLAN_DEBUG)
1807 if(pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs == 1)
1808 {
1809 char str[36];
Kiet Lam64c1b492013-07-12 13:56:44 +05301810 vos_mem_copy(str,
1811 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.ssId,
1812 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.length);
Jeff Johnson295189b2012-06-20 16:38:30 -07001813 str[pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.length] = 0;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001814 smsLog(pMac, LOGW, FL(" SSID = %s"), str);
Jeff Johnson295189b2012-06-20 16:38:30 -07001815 }
1816#endif
1817 //Check whether it is for start ibss. No need to do anything if it is a JOIN request
1818 if(pProfile && CSR_IS_START_IBSS(pProfile))
1819 {
1820 status = csrRoamIssueConnect(pMac, sessionId, pProfile, NULL, eCsrHddIssued,
1821 pCommand->u.scanCmd.roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1822 if(!HAL_STATUS_SUCCESS(status))
1823 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001824 smsLog(pMac, LOGE, FL("failed to issue startIBSS command with status = 0x%08X"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001825 csrRoamCallCallback(pMac, sessionId, NULL, pCommand->u.scanCmd.roamId, eCSR_ROAM_FAILED, eCSR_ROAM_RESULT_FAILURE);
1826 }
1827 }
1828 else
1829 {
1830 eCsrRoamResult roamResult = eCSR_ROAM_RESULT_FAILURE;
1831
1832 if(csrIsConnStateDisconnected(pMac, sessionId) &&
1833 !csrIsRoamCommandWaitingForSession(pMac, sessionId))
1834 {
1835 status = csrScanStartIdleScan(pMac);
1836 }
1837 if((NULL == pProfile) || !csrIsBssTypeIBSS(pProfile->BSSType))
1838 {
1839 //Only indicate assoc_completion if we indicate assoc_start.
1840 if(pSession->bRefAssocStartCnt > 0)
1841 {
1842 tCsrRoamInfo *pRoamInfo = NULL, roamInfo;
Kiet Lam64c1b492013-07-12 13:56:44 +05301843 vos_mem_set(&roamInfo, sizeof(tCsrRoamInfo), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001844 pRoamInfo = &roamInfo;
1845 if(pCommand->u.roamCmd.pRoamBssEntry)
1846 {
1847 tCsrScanResult *pScanResult =
1848 GET_BASE_ADDR(pCommand->u.roamCmd.pRoamBssEntry,
1849 tCsrScanResult, Link);
1850 roamInfo.pBssDesc = &pScanResult->Result.BssDescriptor;
1851 }
1852 roamInfo.statusCode = pSession->joinFailStatusCode.statusCode;
1853 roamInfo.reasonCode = pSession->joinFailStatusCode.reasonCode;
1854 pSession->bRefAssocStartCnt--;
1855 csrRoamCallCallback(pMac, sessionId, pRoamInfo,
1856 pCommand->u.scanCmd.roamId,
1857 eCSR_ROAM_ASSOCIATION_COMPLETION,
1858 eCSR_ROAM_RESULT_FAILURE);
1859 }
Madan Mohan Koyyalamudiee255f12012-09-28 15:41:19 -07001860 else
1861 {
1862 csrRoamCallCallback(pMac, sessionId, NULL,
1863 pCommand->u.scanCmd.roamId,
1864 eCSR_ROAM_ASSOCIATION_FAILURE,
1865 eCSR_ROAM_RESULT_FAILURE);
1866 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001867#ifdef FEATURE_WLAN_BTAMP_UT_RF
1868 //In case of WDS station, let it retry.
1869 if( CSR_IS_WDS_STA(pProfile) )
1870 {
1871 //Save the roma profile so we can retry
1872 csrFreeRoamProfile( pMac, sessionId );
Kiet Lam64c1b492013-07-12 13:56:44 +05301873 pSession->pCurRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1874 if ( NULL != pSession->pCurRoamProfile )
Jeff Johnson295189b2012-06-20 16:38:30 -07001875 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301876 vos_mem_set(pSession->pCurRoamProfile, sizeof(tCsrRoamProfile), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001877 csrRoamCopyProfile(pMac, pSession->pCurRoamProfile, pProfile);
1878 }
1879 csrRoamStartJoinRetryTimer(pMac, sessionId, CSR_JOIN_RETRY_TIMEOUT_PERIOD);
1880 }
1881#endif
1882 }
1883 else
1884 {
1885 roamResult = eCSR_ROAM_RESULT_IBSS_START_FAILED;
1886 }
1887 csrRoamCompletion(pMac, sessionId, NULL, pCommand, roamResult, eANI_BOOLEAN_FALSE);
1888 }
1889
1890 return (status);
1891}
1892
1893
1894//After scan for cap changes, issue a roaming command to either reconnect to the AP or pick another one to connect
1895eHalStatus csrScanHandleCapChangeScanComplete(tpAniSirGlobal pMac, tANI_U32 sessionId)
1896{
1897 eHalStatus status = eHAL_STATUS_FAILURE;
1898 tScanResultHandle hBSSList = NULL;
1899 tCsrScanResultFilter *pScanFilter = NULL;
1900 tANI_U32 roamId = 0;
1901 tCsrRoamProfile *pProfile = NULL;
1902 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1903
1904 do
1905 {
1906 //Here is the profile we need to connect to
Kiet Lam64c1b492013-07-12 13:56:44 +05301907 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1908 if ( NULL == pScanFilter )
1909 status = eHAL_STATUS_FAILURE;
1910 else
1911 status = eHAL_STATUS_SUCCESS;
1912 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001913 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301914 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
1915 if (NULL == pSession) break;
1916 if (NULL == pSession->pCurRoamProfile)
Jeff Johnson295189b2012-06-20 16:38:30 -07001917 {
1918 pScanFilter->EncryptionType.numEntries = 1;
1919 pScanFilter->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_NONE;
1920 }
1921 else
1922 {
1923 //We have to make a copy of pCurRoamProfile because it will be free inside csrRoamIssueConnect
Kiet Lam64c1b492013-07-12 13:56:44 +05301924 pProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1925 if ( NULL == pProfile )
1926 status = eHAL_STATUS_FAILURE;
1927 else
1928 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001929 if(!HAL_STATUS_SUCCESS(status))
1930 break;
1931 status = csrRoamCopyProfile(pMac, pProfile, pSession->pCurRoamProfile);
1932 if(!HAL_STATUS_SUCCESS(status))
1933 break;
1934 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1935 }//We have a profile
1936 roamId = GET_NEXT_ROAM_ID(&pMac->roam);
1937 if(HAL_STATUS_SUCCESS(status))
1938 {
1939 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1940 if(HAL_STATUS_SUCCESS(status))
1941 {
1942 //we want to put the last connected BSS to the very beginning, if possible
1943 csrMoveBssToHeadFromBSSID(pMac, &pSession->connectedProfile.bssid, hBSSList);
1944 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList,
1945 eCsrCapsChange, 0, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1946 if(!HAL_STATUS_SUCCESS(status))
1947 {
1948 csrScanResultPurge(pMac, hBSSList);
1949 }
1950 }//Have scan result
1951 else
1952 {
Arif Hussaina7c8e412013-11-20 11:06:42 -08001953 smsLog(pMac, LOGW, FL("cannot find matching BSS of "
1954 MAC_ADDRESS_STR),
1955 MAC_ADDR_ARRAY(pSession->connectedProfile.bssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001956 //Disconnect
1957 csrRoamDisconnectInternal(pMac, sessionId, eCSR_DISCONNECT_REASON_UNSPECIFIED);
1958 }
1959 }
1960 }while(0);
1961 if(pScanFilter)
1962 {
1963 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301964 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001965 }
1966 if(NULL != pProfile)
1967 {
1968 csrReleaseProfile(pMac, pProfile);
Kiet Lam64c1b492013-07-12 13:56:44 +05301969 vos_mem_free(pProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07001970 }
1971
1972 return (status);
1973}
1974
1975
1976
1977eHalStatus csrScanResultPurge(tpAniSirGlobal pMac, tScanResultHandle hScanList)
1978{
1979 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
1980 tScanResultList *pScanList = (tScanResultList *)hScanList;
1981
1982 if(pScanList)
1983 {
1984 status = csrLLScanPurgeResult(pMac, &pScanList->List);
1985 csrLLClose(&pScanList->List);
Kiet Lam64c1b492013-07-12 13:56:44 +05301986 vos_mem_free(pScanList);
Jeff Johnson295189b2012-06-20 16:38:30 -07001987 }
1988 return (status);
1989}
1990
1991
1992static tANI_U32 csrGetBssPreferValue(tpAniSirGlobal pMac, int rssi)
1993{
1994 tANI_U32 ret = 0;
1995 int i = CSR_NUM_RSSI_CAT - 1;
1996
1997 while(i >= 0)
1998 {
1999 if(rssi >= pMac->roam.configParam.RSSICat[i])
2000 {
2001 ret = pMac->roam.configParam.BssPreferValue[i];
2002 break;
2003 }
2004 i--;
2005 };
2006
2007 return (ret);
2008}
2009
2010
2011//Return a CapValue base on the capabilities of a BSS
2012static tANI_U32 csrGetBssCapValue(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes)
2013{
2014 tANI_U32 ret = CSR_BSS_CAP_VALUE_NONE;
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08002015#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_ESE) || defined(FEATURE_WLAN_LFR)
Madan Mohan Koyyalamudid5026072012-11-30 14:56:21 -08002016 if(CSR_IS_ROAM_PREFER_5GHZ(pMac))
2017 {
2018 if((pBssDesc) && CSR_IS_CHANNEL_5GHZ(pBssDesc->channelId))
2019 {
2020 ret += CSR_BSS_CAP_VALUE_5GHZ;
2021 }
2022 }
2023#endif
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002024 /* if strict select 5GHz is non-zero then ignore the capability checking */
2025 if (pIes && !CSR_IS_SELECT_5GHZ_MARGIN(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -07002026 {
2027 //We only care about 11N capability
2028 if(pIes->HTCaps.present)
2029 {
2030 ret += CSR_BSS_CAP_VALUE_HT;
2031 }
2032 if(CSR_IS_QOS_BSS(pIes))
2033 {
2034 ret += CSR_BSS_CAP_VALUE_WMM;
2035 //Give advantage to UAPSD
2036 if(CSR_IS_UAPSD_BSS(pIes))
2037 {
2038 ret += CSR_BSS_CAP_VALUE_UAPSD;
2039 }
2040 }
2041 }
2042
2043 return (ret);
2044}
2045
Kapil Guptab3a981b2016-06-26 13:36:51 +05302046#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
2047
2048/* Calculate channel weight based on other APs RSSI and count for
2049 * PER based roaming */
2050static tANI_U32 GetPERRoamRssiCountWeight(tANI_S32 rssi, tANI_S32 count)
2051{
2052 tANI_S32 rssiWeight=0;
2053 tANI_S32 countWeight=0;
2054 tANI_S32 rssicountWeight=0;
2055
2056 rssiWeight = ROAMING_RSSI_WEIGHT * (rssi - MIN_RSSI)
2057 /(MAX_RSSI - MIN_RSSI);
2058
2059 if(rssiWeight > ROAMING_RSSI_WEIGHT)
2060 rssiWeight = ROAMING_RSSI_WEIGHT;
2061 else if (rssiWeight < 0)
2062 rssiWeight = 0;
2063
2064 countWeight = ROAM_AP_COUNT_WEIGHT * (count + ROAM_MIN_COUNT)
2065 /(ROAM_MAX_COUNT + ROAM_MIN_COUNT);
2066
2067 if(countWeight > ROAM_AP_COUNT_WEIGHT)
2068 countWeight = ROAM_AP_COUNT_WEIGHT;
2069
2070 rssicountWeight = ROAM_MAX_WEIGHT - (rssiWeight + countWeight);
2071
2072 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO_HIGH,
2073 FL("rssiWeight=%d, countWeight=%d, rssicountWeight=%d rssi=%d count=%d"),
2074 rssiWeight, countWeight, rssicountWeight, rssi, count);
2075
2076 return rssicountWeight;
2077}
2078
2079/* Calculate BSS score based on AP capabilty and channel condition
2080 * for PER based roaming */
2081static tANI_U32 calculateBssScore(tSirBssDescription *bssInfo,
2082 tANI_S32 best_rssi, tANI_S32 ap_cnt, tANI_S32 cca)
2083{
2084 tANI_S32 score = 0;
2085 tANI_S32 ap_load = 0;
2086 tANI_S32 normalised_width = PER_ROAM_20MHZ;
2087 tANI_S32 normalised_rssi;
2088 tANI_S32 channel_weight;
2089 if (bssInfo->rssi) {
2090 /* Calculate % of rssi we are getting
2091 * max = 100
2092 * min = 0
2093 * less than -40 = 100%
2094 * -40 - -55 = 80%
2095 * -55 - -65 = 60%
2096 * below that = 100 - value
2097 * TODO: a linear decrement function after PER_ROAM_GOOD_RSSI_WEIGHT
2098 * since throughput decrements linearly after PER_ROAM_GOOD_RSSI_WEIGHT
2099 **/
2100 if (bssInfo->rssi >= PER_EXCELENT_RSSI)
2101 normalised_rssi = PER_ROAM_EXCELLENT_RSSI_WEIGHT;
2102 else if (bssInfo->rssi >= PER_GOOD_RSSI)
2103 normalised_rssi = PER_ROAM_GOOD_RSSI_WEIGHT;
2104 else if (bssInfo->rssi >= PER_POOR_RSSI)
2105 normalised_rssi = PER_ROAM_BAD_RSSI_WEIGHT;
2106 else
2107 normalised_rssi = bssInfo->rssi - MIN_RSSI;
2108
2109 /* Calculate score part for rssi */
2110 score += (normalised_rssi * RSSI_WEIGHTAGE);
2111 }
2112
2113 if (bssInfo->HTCapsPresent) {
2114 score += PER_ROAM_MAX_WEIGHT * HT_CAPABILITY_WEIGHTAGE;
2115 }
2116 /* VHT caps are available */
2117 if (bssInfo->vhtCapsPresent) {
2118 score += PER_ROAM_MAX_WEIGHT * VHT_CAP_WEIGHTAGE;
2119 }
2120
2121 if (bssInfo->beacomformingCapable)
2122 score += PER_ROAM_MAX_WEIGHT * BEAMFORMING_CAP_WEIGHTAGE;
2123
2124 /* Channel width 20Mhz=30, 40Mhz=70, 80Mhz=100 */
2125 if (bssInfo->chanWidth == eHT_CHANNEL_WIDTH_80MHZ)
2126 normalised_width = PER_ROAM_80MHZ;
2127 else if (bssInfo->chanWidth == eHT_CHANNEL_WIDTH_40MHZ)
2128 normalised_width = PER_ROAM_40MHZ;
2129 else
2130 normalised_width = PER_ROAM_20MHZ;
2131 score += normalised_width * CHAN_WIDTH_WEIGHTAGE;
2132
2133 /* Channel Band, Channel Number */
2134 if (GetRFBand(bssInfo->channelId) == SIR_BAND_5_GHZ)
2135 score += PER_ROAM_MAX_WEIGHT * CHAN_BAND_WEIGHTAGE;
2136
2137 /* WMM emabled */
2138 if (bssInfo->wmeInfoPresent)
2139 score += PER_ROAM_MAX_WEIGHT * WMM_WEIGHTAGE;
2140
2141#if defined(FEATURE_WLAN_ESE) || defined(WLAN_FEATURE_ROAM_SCAN_OFFLOAD)
2142 /* AP load Ie */
2143 if (bssInfo->QBSSLoad_present) {
2144 /* calculate value in % */
2145 ap_load = (bssInfo->QBSS_ChanLoad * PER_ROAM_MAX_WEIGHT) / MAX_AP_LOAD;
2146 }
2147#endif
2148 //TODO we don't have this info for current AP, need to check
2149 /* if CCA consideration is off in configuration, FW will send 50% for
2150 every channel which should be considered as it is */
2151 if (ap_load)
2152 score += (100 - ap_load) * CCA_WEIGHTAGE;
2153 else
2154 score += (100 - cca) * CCA_WEIGHTAGE;
2155
2156 channel_weight = GetPERRoamRssiCountWeight(best_rssi, ap_cnt);
2157
2158 score += channel_weight * OTHER_AP_WEIGHT;
2159
2160 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO_LOW,
2161 FL("rssi=%d normalized_rssi=%d htcaps=%d vht=%d bw=%d channel=%d wmm=%d beamforming=%d ap_load=%d channel_weight=%d"),
2162 bssInfo->rssi, normalised_rssi, bssInfo->HTCapsPresent,
2163 bssInfo->vhtCapsPresent, bssInfo->chanWidth,
2164 bssInfo->channelId, bssInfo->wmeInfoPresent,
2165 bssInfo->beacomformingCapable, ap_load, channel_weight);
2166 return score;
2167}
2168
2169/* Calculate candidate AP score for PER based roaming */
2170static tANI_S32 csrFindCongestionScore (tpAniSirGlobal pMac, tCsrScanResult *pBss)
2171{
2172 tANI_S32 score = 0;
2173 tANI_S32 i;
2174 tANI_S32 candidateApCnt, best_rssi, other_ap_cnt;
2175 tANI_U32 current_timestamp;
2176 tpCsrNeighborRoamControlInfo pNeighborRoamInfo =
2177 &pMac->roam.neighborRoamInfo;
2178
2179 tSirBssDescription *bssInfo = &(pBss->Result.BssDescriptor);
2180 pBss->congestionScore = 0;
2181 for (i = 0; i < pMac->PERroamCandidatesCnt; i++)
2182 if (pMac->candidateChannelInfo[i].channelNumber ==
2183 pBss->Result.BssDescriptor.channelId)
2184 break;
2185
2186 if (i == SIR_PER_ROAM_MAX_CANDIDATE_CNT) {
2187 smsLog(pMac, LOGE,
2188 FL("candidate chan info not found for channel %d bssid "
2189 MAC_ADDRESS_STR), pBss->Result.BssDescriptor.channelId,
2190 MAC_ADDR_ARRAY(pBss->Result.BssDescriptor.bssId));
2191 return -1;
2192 }
2193
2194 /* find best RSSI of other AP in this channel */
2195 best_rssi = MIN_RSSI;
2196 for (other_ap_cnt = 0; other_ap_cnt <
2197 pMac->candidateChannelInfo[i].otherApCount; other_ap_cnt++) {
2198 if (pMac->candidateChannelInfo[i].otherApRssi[other_ap_cnt] > best_rssi)
2199 best_rssi = pMac->candidateChannelInfo[i].otherApRssi[other_ap_cnt];
2200 }
2201
2202 score = calculateBssScore(bssInfo, best_rssi,
2203 pMac->candidateChannelInfo[i].otherApCount,
2204 pMac->candidateChannelInfo[i].channelCCA);
2205 current_timestamp = jiffies_to_msecs(jiffies);
2206
2207 /* penalty logic */
2208
2209 /* In the previous list */
2210 for (candidateApCnt = 0; candidateApCnt <
2211 SIR_PER_ROAM_MAX_CANDIDATE_CNT; candidateApCnt++) {
2212 if (sirCompareMacAddr(pMac->previousRoamApInfo[candidateApCnt].bssAddr,
2213 pBss->Result.BssDescriptor.bssId) &&
2214 ((current_timestamp - pMac->previousRoamApInfo[candidateApCnt].timeStamp) <
2215 PENALTY_TIMEOUT)) {
2216 score = (score * PENALTY_REMAINING_SCORE)/PENALTY_TOTAL_SCORE;
2217 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
2218 FL("AP BSSID " MAC_ADDRESS_STR "adding penalty(in previous list)new score %d"),
2219 MAC_ADDR_ARRAY(pBss->Result.BssDescriptor.bssId),
2220 score);
2221 break;
2222 }
2223 }
2224 /* preauth failed last time */
2225 for (candidateApCnt = 0; candidateApCnt <
2226 MAX_NUM_PREAUTH_FAIL_LIST_ADDRESS; candidateApCnt++) {
2227 if (sirCompareMacAddr(pNeighborRoamInfo->FTRoamInfo.
2228 preAuthFailList.macAddress[candidateApCnt],
2229 pBss->Result.BssDescriptor.bssId)) {
2230 score = (score * PENALTY_REMAINING_SCORE)/PENALTY_TOTAL_SCORE;
2231 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
2232 FL("AP BSSID " MAC_ADDRESS_STR "adding penalty(previously auth failed)new score %d"),
2233 MAC_ADDR_ARRAY(pBss->Result.BssDescriptor.bssId),
2234 score);
2235 break;
2236 }
2237 }
2238 pBss->congestionScore = score;
2239
2240 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
2241 FL("AP BSSID " MAC_ADDRESS_STR " score %d channel %d"),
2242 MAC_ADDR_ARRAY(pBss->Result.BssDescriptor.bssId),
2243 score, pBss->Result.BssDescriptor.channelId);
2244 return 0;
2245}
2246
2247/* Calculate current AP score for PER based roaming */
2248static tANI_S32 csrFindSelfCongestionScore(tpAniSirGlobal pMac,
2249 tSirBssDescription *bssInfo)
2250{
2251 tANI_S32 i, best_rssi, other_ap_cnt;
2252 tANI_S32 score = 0;
2253
2254 for (i = 0; i <= pMac->PERroamCandidatesCnt; i++)
2255 if (pMac->candidateChannelInfo[i].channelNumber == bssInfo->channelId)
2256 break;
2257 if (i > pMac->PERroamCandidatesCnt) {
2258 /* home channel info is not present, no need to roam */
2259 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR,
2260 FL("home channel %d congestion info not present"),
2261 bssInfo->channelId);
2262 pMac->currentBssScore = PER_ROAM_MAX_BSS_SCORE;
2263 return -1;
2264 }
2265
2266 /* find best RSSI of other AP in this channel */
2267 best_rssi = MIN_RSSI;
2268 for (other_ap_cnt = 0; other_ap_cnt <
2269 pMac->candidateChannelInfo[i].otherApCount; other_ap_cnt++) {
2270 if (pMac->candidateChannelInfo[i].otherApRssi[other_ap_cnt] > best_rssi)
2271 best_rssi = pMac->candidateChannelInfo[i].otherApRssi[other_ap_cnt];
2272 }
2273
2274 score = calculateBssScore(bssInfo, best_rssi,
2275 pMac->candidateChannelInfo[i].otherApCount,
2276 pMac->candidateChannelInfo[i].channelCCA);
2277 pMac->currentBssScore = score;
2278 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
2279 FL("PER Roam Current AP score %d channel %d"),
2280 score, bssInfo->channelId);
2281 return 0;
2282}
2283
2284
2285static tANI_BOOLEAN csrIsBetterBssInCongestion(tCsrScanResult *pBss1,
2286 tCsrScanResult *pBss2)
2287{
2288 tANI_BOOLEAN ret;
2289
2290 if(CSR_IS_BETTER_PREFER_VALUE(pBss1->congestionScore,
2291 pBss2->congestionScore))
2292 ret = eANI_BOOLEAN_TRUE;
2293 else
2294 ret = eANI_BOOLEAN_FALSE;
2295
2296 return (ret);
2297}
2298#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002299
2300//To check whther pBss1 is better than pBss2
2301static tANI_BOOLEAN csrIsBetterBss(tCsrScanResult *pBss1, tCsrScanResult *pBss2)
2302{
2303 tANI_BOOLEAN ret;
2304
2305 if(CSR_IS_BETTER_PREFER_VALUE(pBss1->preferValue, pBss2->preferValue))
2306 {
2307 ret = eANI_BOOLEAN_TRUE;
2308 }
2309 else if(CSR_IS_EQUAL_PREFER_VALUE(pBss1->preferValue, pBss2->preferValue))
2310 {
2311 if(CSR_IS_BETTER_CAP_VALUE(pBss1->capValue, pBss2->capValue))
2312 {
2313 ret = eANI_BOOLEAN_TRUE;
2314 }
2315 else
2316 {
2317 ret = eANI_BOOLEAN_FALSE;
2318 }
2319 }
2320 else
2321 {
2322 ret = eANI_BOOLEAN_FALSE;
2323 }
2324
2325 return (ret);
2326}
2327
2328
Srikant Kuppa866893f2012-12-27 17:28:14 -08002329#ifdef FEATURE_WLAN_LFR
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002330//Add the channel to the occupiedChannels array
2331static void csrScanAddToOccupiedChannels(
Srikant Kuppa866893f2012-12-27 17:28:14 -08002332 tpAniSirGlobal pMac,
2333 tCsrScanResult *pResult,
2334 tCsrChannel *pOccupiedChannels,
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002335 tDot11fBeaconIEs *pIes)
2336{
2337 eHalStatus status;
2338 tANI_U8 channel;
2339 tANI_U8 numOccupiedChannels = pOccupiedChannels->numChannels;
2340 tANI_U8 *pOccupiedChannelList = pOccupiedChannels->channelList;
2341
2342 channel = pResult->Result.BssDescriptor.channelId;
2343
2344 if (!csrIsChannelPresentInList(pOccupiedChannelList, numOccupiedChannels, channel)
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08002345 && csrNeighborRoamConnectedProfileMatch(pMac, pResult, pIes))
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002346 {
Srikant Kuppa866893f2012-12-27 17:28:14 -08002347 status = csrAddToChannelListFront(pOccupiedChannelList, numOccupiedChannels, channel);
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002348 if(HAL_STATUS_SUCCESS(status))
Srikant Kuppa866893f2012-12-27 17:28:14 -08002349 {
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002350 pOccupiedChannels->numChannels++;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002351 smsLog(pMac, LOG2, FL("%s: added channel %d to the list (count=%d)"),
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08002352 __func__, channel, pOccupiedChannels->numChannels);
Srikant Kuppa866893f2012-12-27 17:28:14 -08002353 if (pOccupiedChannels->numChannels > CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN)
2354 pOccupiedChannels->numChannels = CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN;
2355 }
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002356 }
2357}
Mukul Sharma9e4e0f92015-02-13 18:45:20 +05302358
2359void csrAddChannelToOccupiedChannelList(tpAniSirGlobal pMac,
2360 tANI_U8 channel)
2361{
2362 eHalStatus status;
2363 tCsrChannel *pOccupiedChannels = &pMac->scan.occupiedChannels;
2364 tANI_U8 numOccupiedChannels = pOccupiedChannels->numChannels;
2365 tANI_U8 *pOccupiedChannelList = pOccupiedChannels->channelList;
2366 if (!csrIsChannelPresentInList(pOccupiedChannelList,
2367 numOccupiedChannels, channel))
2368 {
2369 status = csrAddToChannelListFront(pOccupiedChannelList,
2370 numOccupiedChannels, channel);
2371 if(HAL_STATUS_SUCCESS(status))
2372 {
2373 pOccupiedChannels->numChannels++;
2374 smsLog(pMac, LOG2, FL("added channel %d to the list (count=%d)"),
2375 channel, pOccupiedChannels->numChannels);
2376 if (pOccupiedChannels->numChannels >
2377 CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN)
2378 {
2379 pOccupiedChannels->numChannels =
2380 CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN;
2381 smsLog(pMac, LOG2,
2382 FL("trim no of Channels for Occ channel list"));
2383 }
2384 }
2385 }
2386}
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002387#endif
2388
Jeff Johnson295189b2012-06-20 16:38:30 -07002389//Put the BSS into the scan result list
2390//pIes can not be NULL
2391static void csrScanAddResult(tpAniSirGlobal pMac, tCsrScanResult *pResult, tDot11fBeaconIEs *pIes)
2392{
Srinivas28b5b4e2012-12-12 13:07:53 -08002393#ifdef FEATURE_WLAN_LFR
2394 tpCsrNeighborRoamControlInfo pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
2395#endif
2396
Jeff Johnson295189b2012-06-20 16:38:30 -07002397 pResult->preferValue = csrGetBssPreferValue(pMac, (int)pResult->Result.BssDescriptor.rssi);
2398 pResult->capValue = csrGetBssCapValue(pMac, &pResult->Result.BssDescriptor, pIes);
2399 csrLLInsertTail( &pMac->scan.scanResultList, &pResult->Link, LL_ACCESS_LOCK );
Srikant Kuppa866893f2012-12-27 17:28:14 -08002400#ifdef FEATURE_WLAN_LFR
Srinivas28b5b4e2012-12-12 13:07:53 -08002401 if(0 == pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels)
2402 {
2403 /* Build the occupied channel list, only if "gNeighborScanChannelList" is
2404 NOT set in the cfg.ini file */
2405 csrScanAddToOccupiedChannels(pMac, pResult, &pMac->scan.occupiedChannels, pIes);
2406 }
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002407#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002408}
2409
2410
2411eHalStatus csrScanGetResult(tpAniSirGlobal pMac, tCsrScanResultFilter *pFilter, tScanResultHandle *phResult)
2412{
2413 eHalStatus status;
2414 tScanResultList *pRetList;
2415 tCsrScanResult *pResult, *pBssDesc;
2416 tANI_U32 count = 0;
2417 tListElem *pEntry;
2418 tANI_U32 bssLen, allocLen;
2419 eCsrEncryptionType uc = eCSR_ENCRYPT_TYPE_NONE, mc = eCSR_ENCRYPT_TYPE_NONE;
2420 eCsrAuthType auth = eCSR_AUTH_TYPE_OPEN_SYSTEM;
2421 tDot11fBeaconIEs *pIes, *pNewIes;
2422 tANI_BOOLEAN fMatch;
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002423 tANI_U16 i = 0;
Kapil Guptab3a981b2016-06-26 13:36:51 +05302424 tCsrRoamSession *pSession = CSR_GET_SESSION(pMac,
2425 pMac->roam.roamSession->sessionId);
2426
Jeff Johnson295189b2012-06-20 16:38:30 -07002427 if(phResult)
2428 {
2429 *phResult = CSR_INVALID_SCANRESULT_HANDLE;
2430 }
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002431
2432 if (pMac->roam.configParam.nSelect5GHzMargin)
2433 {
2434 pMac->scan.inScanResultBestAPRssi = -128;
2435 csrLLLock(&pMac->scan.scanResultList);
2436
2437 /* Find out the best AP Rssi going thru the scan results */
2438 pEntry = csrLLPeekHead(&pMac->scan.scanResultList, LL_ACCESS_NOLOCK);
2439 while ( NULL != pEntry)
2440 {
2441 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002442 fMatch = FALSE;
2443
2444 if (pFilter)
2445 for(i = 0; i < pFilter->SSIDs.numOfSSIDs; i++)
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002446 {
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002447 fMatch = csrIsSsidMatch( pMac, pFilter->SSIDs.SSIDList[i].SSID.ssId, pFilter->SSIDs.SSIDList[i].SSID.length,
2448 pBssDesc->Result.ssId.ssId,
2449 pBssDesc->Result.ssId.length, eANI_BOOLEAN_TRUE );
2450 if (fMatch)
2451 {
2452 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
2453
2454 //At this time, pBssDescription->Result.pvIes may be NULL
2455 if( !pIes && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
2456 &pBssDesc->Result.BssDescriptor, &pIes))) )
2457 {
2458 continue;
2459 }
2460
2461 smsLog(pMac, LOG1, FL("SSID Matched"));
Leela Venkata Kiran Kumar Reddy Chiralae208a832014-04-27 22:34:25 -07002462
Leela Venkata Kiran Kumar Reddy Chiralaf257bef2014-04-11 18:48:12 -07002463 if ( pFilter->bOSENAssociation )
2464 {
2465 fMatch = TRUE;
2466 }
Leela Venkata Kiran Kumar Reddy Chiralae208a832014-04-27 22:34:25 -07002467 else
2468 {
Abhishek Singh658d4de2014-06-26 10:53:15 +05302469#ifdef WLAN_FEATURE_11W
Abhishek Singh3b56d3a2014-06-25 12:37:39 +05302470 fMatch = csrIsSecurityMatch(pMac, &pFilter->authType,
2471 &pFilter->EncryptionType,
2472 &pFilter->mcEncryptionType,
2473 &pFilter->MFPEnabled,
2474 &pFilter->MFPRequired,
2475 &pFilter->MFPCapable,
2476 &pBssDesc->Result.BssDescriptor,
2477 pIes, NULL, NULL, NULL );
Abhishek Singh658d4de2014-06-26 10:53:15 +05302478#else
2479 fMatch = csrIsSecurityMatch(pMac, &pFilter->authType,
2480 &pFilter->EncryptionType,
2481 &pFilter->mcEncryptionType,
2482 NULL, NULL, NULL,
2483 &pBssDesc->Result.BssDescriptor,
2484 pIes, NULL, NULL, NULL );
2485#endif
Leela Venkata Kiran Kumar Reddy Chiralae208a832014-04-27 22:34:25 -07002486 }
2487 if ((pBssDesc->Result.pvIes == NULL) && pIes)
2488 vos_mem_free(pIes);
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002489
2490 if (fMatch)
2491 smsLog(pMac, LOG1, FL(" Security Matched"));
2492 }
2493 }
2494
2495 if (fMatch && (pBssDesc->Result.BssDescriptor.rssi > pMac->scan.inScanResultBestAPRssi))
2496 {
2497 smsLog(pMac, LOG1, FL("Best AP Rssi changed from %d to %d"),
2498 pMac->scan.inScanResultBestAPRssi,
2499 pBssDesc->Result.BssDescriptor.rssi);
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002500 pMac->scan.inScanResultBestAPRssi = pBssDesc->Result.BssDescriptor.rssi;
2501 }
2502 pEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
2503 }
2504
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002505 if ( -128 != pMac->scan.inScanResultBestAPRssi)
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002506 {
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002507 smsLog(pMac, LOG1, FL("Best AP Rssi is %d"), pMac->scan.inScanResultBestAPRssi);
2508 /* Modify Rssi category based on best AP Rssi */
2509 csrAssignRssiForCategory(pMac, pMac->scan.inScanResultBestAPRssi, pMac->roam.configParam.bCatRssiOffset);
2510 pEntry = csrLLPeekHead(&pMac->scan.scanResultList, LL_ACCESS_NOLOCK);
2511 while ( NULL != pEntry)
2512 {
2513 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002514
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002515 /* re-assign preference value based on modified rssi bucket */
2516 pBssDesc->preferValue = csrGetBssPreferValue(pMac, (int)pBssDesc->Result.BssDescriptor.rssi);
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002517
Arif Hussaina7c8e412013-11-20 11:06:42 -08002518 smsLog(pMac, LOG2, FL("BSSID("MAC_ADDRESS_STR
Jeff Johnson123ed002013-11-22 17:39:55 -08002519 ") Rssi(%d) Chnl(%d) PrefVal(%u) SSID=%.*s"),
Arif Hussaina7c8e412013-11-20 11:06:42 -08002520 MAC_ADDR_ARRAY(pBssDesc->Result.BssDescriptor.bssId),
2521 pBssDesc->Result.BssDescriptor.rssi,
2522 pBssDesc->Result.BssDescriptor.channelId,
2523 pBssDesc->preferValue,
2524 pBssDesc->Result.ssId.length, pBssDesc->Result.ssId.ssId);
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002525
2526 pEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
2527 }
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002528 }
2529
2530 csrLLUnlock(&pMac->scan.scanResultList);
2531 }
2532
Kiet Lam64c1b492013-07-12 13:56:44 +05302533 pRetList = vos_mem_malloc(sizeof(tScanResultList));
2534 if ( NULL == pRetList )
2535 status = eHAL_STATUS_FAILURE;
2536 else
2537 status = eHAL_STATUS_SUCCESS;
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002538 if(HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07002539 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302540 vos_mem_set(pRetList, sizeof(tScanResultList), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002541 csrLLOpen(pMac->hHdd, &pRetList->List);
2542 pRetList->pCurEntry = NULL;
Kapil Guptab3a981b2016-06-26 13:36:51 +05302543#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
2544 if (pFilter && pFilter->isPERRoamScan)
2545 if (pSession && pSession->pConnectBssDesc)
2546 csrFindSelfCongestionScore(pMac,
2547 pSession->pConnectBssDesc);
2548#endif
2549
Jeff Johnson295189b2012-06-20 16:38:30 -07002550 csrLLLock(&pMac->scan.scanResultList);
2551 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
2552 while( pEntry )
2553 {
2554 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2555 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
2556 //if pBssDesc->Result.pvIes is NULL, we need to free any memory allocated by csrMatchBSS
2557 //for any error condition, otherwiase, it will be freed later.
2558 //reset
2559 fMatch = eANI_BOOLEAN_FALSE;
2560 pNewIes = NULL;
2561
2562 if(pFilter)
2563 {
2564 fMatch = csrMatchBSS(pMac, &pBssDesc->Result.BssDescriptor, pFilter, &auth, &uc, &mc, &pIes);
2565 if( NULL != pIes )
2566 {
2567 //Only save it when matching
2568 if(fMatch)
2569 {
2570 if( !pBssDesc->Result.pvIes )
2571 {
2572 //csrMatchBSS allocates the memory. Simply pass it and it is freed later
2573 pNewIes = pIes;
2574 }
2575 else
2576 {
2577 //The pIes is allocated by someone else. make a copy
2578 //Only to save parsed IEs if caller provides a filter. Most likely the caller
2579 //is using to for association, hence save the parsed IEs
Kiet Lam64c1b492013-07-12 13:56:44 +05302580 pNewIes = vos_mem_malloc(sizeof(tDot11fBeaconIEs));
2581 if ( NULL == pNewIes )
2582 status = eHAL_STATUS_FAILURE;
2583 else
2584 status = eHAL_STATUS_SUCCESS;
2585 if ( HAL_STATUS_SUCCESS( status ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07002586 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302587 vos_mem_copy(pNewIes, pIes, sizeof( tDot11fBeaconIEs ));
Jeff Johnson295189b2012-06-20 16:38:30 -07002588 }
2589 else
2590 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002591 smsLog(pMac, LOGE, FL(" fail to allocate memory for IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002592 //Need to free memory allocated by csrMatchBSS
2593 if( !pBssDesc->Result.pvIes )
2594 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302595 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07002596 }
2597 break;
2598 }
2599 }
2600 }//fMatch
2601 else if( !pBssDesc->Result.pvIes )
2602 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302603 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07002604 }
2605 }
2606 }
2607 if(NULL == pFilter || fMatch)
2608 {
2609 bssLen = pBssDesc->Result.BssDescriptor.length + sizeof(pBssDesc->Result.BssDescriptor.length);
2610 allocLen = sizeof( tCsrScanResult ) + bssLen;
Kiet Lam64c1b492013-07-12 13:56:44 +05302611 pResult = vos_mem_malloc(allocLen);
2612 if ( NULL == pResult )
2613 status = eHAL_STATUS_FAILURE;
2614 else
2615 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07002616 if(!HAL_STATUS_SUCCESS(status))
2617 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002618 smsLog(pMac, LOGE, FL(" fail to allocate memory for scan result, len=%d"), allocLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07002619 if(pNewIes)
2620 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302621 vos_mem_free(pNewIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07002622 }
2623 break;
2624 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302625 vos_mem_set(pResult, allocLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002626 pResult->capValue = pBssDesc->capValue;
2627 pResult->preferValue = pBssDesc->preferValue;
2628 pResult->ucEncryptionType = uc;
2629 pResult->mcEncryptionType = mc;
2630 pResult->authType = auth;
2631 pResult->Result.ssId = pBssDesc->Result.ssId;
Padma, Santhosh Kumare12fd982016-03-21 13:07:52 +05302632 pResult->Result.timer = pBssDesc->Result.timer;
Jeff Johnson295189b2012-06-20 16:38:30 -07002633 //save the pIes for later use
2634 pResult->Result.pvIes = pNewIes;
2635 //save bss description
Kiet Lam64c1b492013-07-12 13:56:44 +05302636 vos_mem_copy(&pResult->Result.BssDescriptor,
2637 &pBssDesc->Result.BssDescriptor, bssLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07002638 //No need to lock pRetList because it is locally allocated and no outside can access it at this time
2639 if(csrLLIsListEmpty(&pRetList->List, LL_ACCESS_NOLOCK))
2640 {
Kapil Guptab3a981b2016-06-26 13:36:51 +05302641#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
2642 if (pFilter && pFilter->isPERRoamScan) {
2643 csrFindCongestionScore(pMac, pResult);
2644 if (pResult->congestionScore > pMac->currentBssScore) {
2645 csrLLInsertTail(&pRetList->List, &pResult->Link,
2646 LL_ACCESS_NOLOCK);
2647 smsLog(pMac, LOGW,
2648 FL("added one entry in LL in PER Roam list"));
2649 }
2650 }
2651 else
2652#endif
2653 {
2654 csrLLInsertTail(&pRetList->List, &pResult->Link,
2655 LL_ACCESS_NOLOCK);
2656 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002657 }
2658 else
2659 {
2660 //To sort the list
2661 tListElem *pTmpEntry;
2662 tCsrScanResult *pTmpResult;
2663
2664 pTmpEntry = csrLLPeekHead(&pRetList->List, LL_ACCESS_NOLOCK);
2665 while(pTmpEntry)
2666 {
2667 pTmpResult = GET_BASE_ADDR( pTmpEntry, tCsrScanResult, Link );
Kapil Guptab3a981b2016-06-26 13:36:51 +05302668#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
2669 if (pFilter && pFilter->isPERRoamScan) {
2670 csrFindCongestionScore(pMac, pResult);
2671 if(csrIsBetterBssInCongestion(pResult, pTmpResult)&&
2672 (pResult->congestionScore > pMac->currentBssScore))
2673 {
2674 csrLLInsertEntry(&pRetList->List, pTmpEntry,
2675 &pResult->Link, LL_ACCESS_NOLOCK);
2676 smsLog(pMac, LOGW,
2677 FL("added another entry in LL in PER Roam list"));
2678 pResult = NULL;
2679 break;
2680 }
2681 pTmpEntry = csrLLNext(&pRetList->List,
2682 pTmpEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07002683 }
Kapil Guptab3a981b2016-06-26 13:36:51 +05302684 else
2685#endif
2686 {
2687 if(csrIsBetterBss(pResult, pTmpResult))
2688 {
2689 csrLLInsertEntry(&pRetList->List, pTmpEntry,
2690 &pResult->Link, LL_ACCESS_NOLOCK);
2691 //To indicate we are done
2692 pResult = NULL;
2693 break;
2694 }
2695 pTmpEntry = csrLLNext(&pRetList->List,
2696 pTmpEntry, LL_ACCESS_NOLOCK);
2697 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002698 }
2699 if(pResult != NULL)
Kapil Guptab3a981b2016-06-26 13:36:51 +05302700#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
2701 if ((pFilter && !pFilter->isPERRoamScan) ||
2702 (pFilter == NULL) ||
2703 (pResult->congestionScore > pMac->currentBssScore))
2704#endif
2705 {
2706 //This one is not better than any one
2707 csrLLInsertTail(&pRetList->List,
2708 &pResult->Link, LL_ACCESS_NOLOCK);
2709 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002710 }
2711 count++;
2712 }
2713 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK );
2714 }//while
2715 csrLLUnlock(&pMac->scan.scanResultList);
2716
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002717 smsLog(pMac, LOG2, FL("return %d BSS"), csrLLCount(&pRetList->List));
Jeff Johnson295189b2012-06-20 16:38:30 -07002718
2719 if( !HAL_STATUS_SUCCESS(status) || (phResult == NULL) )
2720 {
2721 //Fail or No one wants the result.
2722 csrScanResultPurge(pMac, (tScanResultHandle)pRetList);
2723 }
2724 else
2725 {
2726 if(0 == count)
2727 {
2728 //We are here meaning the there is no match
2729 csrLLClose(&pRetList->List);
Kiet Lam64c1b492013-07-12 13:56:44 +05302730 vos_mem_free(pRetList);
Jeff Johnson295189b2012-06-20 16:38:30 -07002731 status = eHAL_STATUS_E_NULL_VALUE;
Kapil Guptab3a981b2016-06-26 13:36:51 +05302732 smsLog(pMac, LOGW,
2733 FL("Nil scan results or no matching AP found"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002734 }
2735 else if(phResult)
2736 {
2737 *phResult = pRetList;
2738 }
2739 }
2740 }//Allocated pRetList
2741
2742 return (status);
2743}
2744
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002745/*
2746 * NOTE: This routine is being added to make
2747 * sure that scan results are not being flushed
2748 * while roaming. If the scan results are flushed,
2749 * we are unable to recover from
2750 * csrRoamRoamingStateDisassocRspProcessor.
2751 * If it is needed to remove this routine,
2752 * first ensure that we recover gracefully from
2753 * csrRoamRoamingStateDisassocRspProcessor if
2754 * csrScanGetResult returns with a failure because
2755 * of not being able to find the roaming BSS.
2756 */
2757tANI_U8 csrScanFlushDenied(tpAniSirGlobal pMac)
2758{
2759 switch(pMac->roam.neighborRoamInfo.neighborRoamState) {
2760 case eCSR_NEIGHBOR_ROAM_STATE_REPORT_SCAN:
2761 case eCSR_NEIGHBOR_ROAM_STATE_PREAUTHENTICATING:
2762 case eCSR_NEIGHBOR_ROAM_STATE_PREAUTH_DONE:
2763 case eCSR_NEIGHBOR_ROAM_STATE_REASSOCIATING:
2764 return (pMac->roam.neighborRoamInfo.neighborRoamState);
2765 default:
2766 return 0;
2767 }
2768}
2769
Jeff Johnson295189b2012-06-20 16:38:30 -07002770eHalStatus csrScanFlushResult(tpAniSirGlobal pMac)
2771{
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002772 tANI_U8 isFlushDenied = csrScanFlushDenied(pMac);
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302773 eHalStatus status = eHAL_STATUS_SUCCESS;
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002774 if (isFlushDenied) {
2775 smsLog(pMac, LOGW, "%s: scan flush denied in roam state %d",
2776 __func__, isFlushDenied);
2777 return eHAL_STATUS_FAILURE;
2778 }
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302779 csrLLScanPurgeResult( pMac, &pMac->scan.tempScanResults );
2780 csrLLScanPurgeResult( pMac, &pMac->scan.scanResultList );
2781 return( status );
Jeff Johnson295189b2012-06-20 16:38:30 -07002782}
2783
Mukul Sharma20aa6582014-08-07 21:36:12 +05302784eHalStatus csrScanFlushSelectiveResultForBand(tpAniSirGlobal pMac, v_BOOL_t flushP2P, tSirRFBand band)
2785{
2786 eHalStatus status = eHAL_STATUS_SUCCESS;
2787 tListElem *pEntry,*pFreeElem;
2788 tCsrScanResult *pBssDesc;
2789 tDblLinkList *pList = &pMac->scan.scanResultList;
2790
2791 csrLLLock(pList);
2792
2793 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK );
2794 while( pEntry != NULL)
2795 {
2796 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2797 if( (flushP2P == vos_mem_compare( pBssDesc->Result.ssId.ssId,
2798 "DIRECT-", 7)) &&
2799 (GetRFBand(pBssDesc->Result.BssDescriptor.channelId) == band)
2800 )
2801 {
2802 pFreeElem = pEntry;
2803 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2804 csrLLRemoveEntry(pList, pFreeElem, LL_ACCESS_NOLOCK);
2805 csrFreeScanResultEntry( pMac, pBssDesc );
2806 continue;
2807 }
2808 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2809 }
2810
2811 csrLLUnlock(pList);
2812
2813 return (status);
2814}
2815
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302816eHalStatus csrScanFlushSelectiveResult(tpAniSirGlobal pMac, v_BOOL_t flushP2P)
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002817{
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302818 eHalStatus status = eHAL_STATUS_SUCCESS;
2819 tListElem *pEntry,*pFreeElem;
2820 tCsrScanResult *pBssDesc;
2821 tDblLinkList *pList = &pMac->scan.scanResultList;
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002822
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302823 csrLLLock(pList);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002824
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302825 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK );
2826 while( pEntry != NULL)
2827 {
2828 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2829 if( flushP2P == vos_mem_compare( pBssDesc->Result.ssId.ssId,
2830 "DIRECT-", 7) )
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002831 {
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302832 pFreeElem = pEntry;
2833 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2834 csrLLRemoveEntry(pList, pFreeElem, LL_ACCESS_NOLOCK);
2835 csrFreeScanResultEntry( pMac, pBssDesc );
2836 continue;
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002837 }
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302838 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2839 }
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002840
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302841 csrLLUnlock(pList);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002842
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302843 return (status);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002844}
2845
Jeff Johnson295189b2012-06-20 16:38:30 -07002846/**
2847 * csrCheck11dChannel
2848 *
2849 *FUNCTION:
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302850 * This function is called from csrScanFilterResults function and
Jeff Johnson295189b2012-06-20 16:38:30 -07002851 * compare channel number with given channel list.
2852 *
2853 *LOGIC:
2854 * Check Scan result channel number with CFG channel list
2855 *
2856 *ASSUMPTIONS:
2857 *
2858 *
2859 *NOTE:
2860 *
2861 * @param channelId channel number
2862 * @param pChannelList Pointer to channel list
2863 * @param numChannels Number of channel in channel list
2864 *
2865 * @return Status
2866 */
2867
2868eHalStatus csrCheck11dChannel(tANI_U8 channelId, tANI_U8 *pChannelList, tANI_U32 numChannels)
2869{
2870 eHalStatus status = eHAL_STATUS_FAILURE;
2871 tANI_U8 i = 0;
2872
2873 for (i = 0; i < numChannels; i++)
2874 {
2875 if(pChannelList[ i ] == channelId)
2876 {
2877 status = eHAL_STATUS_SUCCESS;
2878 break;
2879 }
2880 }
2881 return status;
2882}
2883
2884/**
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302885 * csrScanFilterResults
Jeff Johnson295189b2012-06-20 16:38:30 -07002886 *
2887 *FUNCTION:
2888 * This function is called from csrApplyCountryInformation function and
2889 * filter scan result based on valid channel list number.
2890 *
2891 *LOGIC:
2892 * Get scan result from scan list and Check Scan result channel number
2893 * with 11d channel list if channel number is found in 11d channel list
2894 * then do not remove scan result entry from scan list
2895 *
2896 *ASSUMPTIONS:
2897 *
2898 *
2899 *NOTE:
2900 *
2901 * @param pMac Pointer to Global MAC structure
2902 *
2903 * @return Status
2904 */
2905
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302906eHalStatus csrScanFilterResults(tpAniSirGlobal pMac)
Jeff Johnson295189b2012-06-20 16:38:30 -07002907{
2908 eHalStatus status = eHAL_STATUS_SUCCESS;
2909 tListElem *pEntry,*pTempEntry;
2910 tCsrScanResult *pBssDesc;
2911 tANI_U32 len = sizeof(pMac->roam.validChannelList);
2912
2913 /* Get valid channels list from CFG */
2914 if (!HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac,
2915 pMac->roam.validChannelList, &len)))
2916 {
Agarwal Ashishe3cca2a2013-07-21 03:01:48 +05302917 smsLog( pMac, LOGE, "Failed to get Channel list from CFG");
Jeff Johnson295189b2012-06-20 16:38:30 -07002918 }
2919
2920 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
2921 while( pEntry )
2922 {
2923 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302924 pTempEntry = csrLLNext( &pMac->scan.scanResultList, pEntry,
Jeff Johnson295189b2012-06-20 16:38:30 -07002925 LL_ACCESS_LOCK );
2926 if(csrCheck11dChannel(pBssDesc->Result.BssDescriptor.channelId,
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302927 pMac->roam.validChannelList, len))
Jeff Johnson295189b2012-06-20 16:38:30 -07002928 {
2929 /* Remove Scan result which does not have 11d channel */
2930 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry,
2931 LL_ACCESS_LOCK ))
2932 {
2933 csrFreeScanResultEntry( pMac, pBssDesc );
2934 }
2935 }
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302936 pEntry = pTempEntry;
2937 }
2938
2939 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
2940 while( pEntry )
2941 {
2942 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2943 pTempEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry,
2944 LL_ACCESS_LOCK );
2945 if(csrCheck11dChannel(pBssDesc->Result.BssDescriptor.channelId,
2946 pMac->roam.validChannelList, len))
2947 {
2948 /* Remove Scan result which does not have 11d channel */
2949 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry,
2950 LL_ACCESS_LOCK ))
2951 {
2952 csrFreeScanResultEntry( pMac, pBssDesc );
2953 }
2954 }
2955 else
2956 {
2957 smsLog( pMac, LOG1, FL("%d is a Valid channel"),
2958 pBssDesc->Result.BssDescriptor.channelId);
2959 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002960 pEntry = pTempEntry;
2961 }
2962 return status;
2963}
2964
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05302965/**
2966 * csrScanFilterDFSResults
2967 *
2968 *FUNCTION:
2969 * This function filter BSSIDs on DFS channels from the scan results.
2970 *
2971 *LOGIC:
2972 * Get scan result from scan list and Check Scan result channel number
2973 * with 11d channel list if channel number is found in 11d channel list
2974 * and if fEnableDFSChnlScan is zero and if channel is DFS, then
2975 * remove scan result entry from scan list
2976 *
2977 *ASSUMPTIONS:
2978 *
2979 *NOTE:
2980 *
2981 * @param pMac Pointer to Global MAC structure
2982 *
2983 * @return Status
2984 */
2985
2986eHalStatus csrScanFilterDFSResults(tpAniSirGlobal pMac)
2987{
2988 eHalStatus status = eHAL_STATUS_SUCCESS;
2989 tListElem *pEntry,*pTempEntry;
2990 tCsrScanResult *pBssDesc;
2991
2992 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
2993 while( pEntry )
2994 {
2995 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2996 pTempEntry = csrLLNext( &pMac->scan.scanResultList, pEntry,
2997 LL_ACCESS_LOCK );
2998 if((pMac->scan.fEnableDFSChnlScan == DFS_CHNL_SCAN_DISABLED) &&
2999 CSR_IS_CHANNEL_DFS(pBssDesc->Result.BssDescriptor.channelId))
3000 {
3001 smsLog( pMac, LOG1, FL("%d is a DFS ch filtered from scan list"),
3002 pBssDesc->Result.BssDescriptor.channelId);
3003 /* Remove Scan result which does not have 11d channel */
3004 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry,
3005 LL_ACCESS_LOCK ))
3006 {
3007 csrFreeScanResultEntry( pMac, pBssDesc );
3008 }
3009 }
3010 else
3011 {
3012 smsLog( pMac, LOG1, FL("%d is a Valid channel"),
3013 pBssDesc->Result.BssDescriptor.channelId);
3014 }
3015 pEntry = pTempEntry;
3016 }
3017
3018 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
3019 while( pEntry )
3020 {
3021 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3022 pTempEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry,
3023 LL_ACCESS_LOCK );
3024
3025 if((pMac->scan.fEnableDFSChnlScan == DFS_CHNL_SCAN_DISABLED) &&
3026 CSR_IS_CHANNEL_DFS(pBssDesc->Result.BssDescriptor.channelId))
3027 {
3028 smsLog( pMac, LOG1, FL("%d is a DFS ch filtered from scan list"),
3029 pBssDesc->Result.BssDescriptor.channelId);
3030 /* Remove Scan result which does not have 11d channel */
3031 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry,
3032 LL_ACCESS_LOCK ))
3033 {
3034 csrFreeScanResultEntry( pMac, pBssDesc );
3035 }
3036 }
3037 else
3038 {
3039 smsLog( pMac, LOG1, FL("%d is a Valid channel"),
3040 pBssDesc->Result.BssDescriptor.channelId);
3041 }
3042 pEntry = pTempEntry;
3043 }
3044 return status;
3045}
3046
Jeff Johnson295189b2012-06-20 16:38:30 -07003047
3048eHalStatus csrScanCopyResultList(tpAniSirGlobal pMac, tScanResultHandle hIn, tScanResultHandle *phResult)
3049{
3050 eHalStatus status = eHAL_STATUS_SUCCESS;
3051 tScanResultList *pRetList, *pInList = (tScanResultList *)hIn;
3052 tCsrScanResult *pResult, *pScanResult;
3053 tANI_U32 count = 0;
3054 tListElem *pEntry;
3055 tANI_U32 bssLen, allocLen;
3056
3057 if(phResult)
3058 {
3059 *phResult = CSR_INVALID_SCANRESULT_HANDLE;
3060 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303061 pRetList = vos_mem_malloc(sizeof(tScanResultList));
3062 if ( NULL == pRetList )
3063 status = eHAL_STATUS_FAILURE;
3064 else
Jeff Johnson295189b2012-06-20 16:38:30 -07003065 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303066 vos_mem_set(pRetList, sizeof(tScanResultList), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003067 csrLLOpen(pMac->hHdd, &pRetList->List);
3068 pRetList->pCurEntry = NULL;
3069 csrLLLock(&pMac->scan.scanResultList);
3070 csrLLLock(&pInList->List);
3071
3072 pEntry = csrLLPeekHead( &pInList->List, LL_ACCESS_NOLOCK );
3073 while( pEntry )
3074 {
3075 pScanResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3076 bssLen = pScanResult->Result.BssDescriptor.length + sizeof(pScanResult->Result.BssDescriptor.length);
3077 allocLen = sizeof( tCsrScanResult ) + bssLen;
Kiet Lam64c1b492013-07-12 13:56:44 +05303078 pResult = vos_mem_malloc(allocLen);
3079 if ( NULL == pResult )
3080 status = eHAL_STATUS_FAILURE;
3081 else
3082 status = eHAL_STATUS_SUCCESS;
3083 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07003084 {
3085 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
3086 count = 0;
3087 break;
3088 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303089 vos_mem_set(pResult, allocLen , 0);
3090 vos_mem_copy(&pResult->Result.BssDescriptor, &pScanResult->Result.BssDescriptor, bssLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07003091 if( pScanResult->Result.pvIes )
3092 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303093 pResult->Result.pvIes = vos_mem_malloc(sizeof( tDot11fBeaconIEs ));
3094 if ( NULL == pResult->Result.pvIes )
3095 status = eHAL_STATUS_FAILURE;
3096 else
3097 status = eHAL_STATUS_SUCCESS;
3098 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07003099 {
3100 //Free the memory we allocate above first
Kiet Lam64c1b492013-07-12 13:56:44 +05303101 vos_mem_free(pResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07003102 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
3103 count = 0;
3104 break;
3105 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303106 vos_mem_copy(pResult->Result.pvIes, pScanResult->Result.pvIes,
3107 sizeof( tDot11fBeaconIEs ));
Jeff Johnson295189b2012-06-20 16:38:30 -07003108 }
3109 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_LOCK);
3110 count++;
3111 pEntry = csrLLNext( &pInList->List, pEntry, LL_ACCESS_NOLOCK );
3112 }//while
3113 csrLLUnlock(&pInList->List);
3114 csrLLUnlock(&pMac->scan.scanResultList);
3115
3116 if(HAL_STATUS_SUCCESS(status))
3117 {
3118 if(0 == count)
3119 {
3120 csrLLClose(&pRetList->List);
Kiet Lam64c1b492013-07-12 13:56:44 +05303121 vos_mem_free(pRetList);
Jeff Johnson295189b2012-06-20 16:38:30 -07003122 status = eHAL_STATUS_E_NULL_VALUE;
3123 }
3124 else if(phResult)
3125 {
3126 *phResult = pRetList;
3127 }
3128 }
3129 }//Allocated pRetList
3130
3131 return (status);
3132}
3133
3134
3135
3136eHalStatus csrScanningStateMsgProcessor( tpAniSirGlobal pMac, void *pMsgBuf )
3137{
3138 eHalStatus status = eHAL_STATUS_SUCCESS;
3139 tSirMbMsg *pMsg = (tSirMbMsg *)pMsgBuf;
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303140 tSirSmeDisConDoneInd *pDisConDoneInd;
3141 tCsrRoamInfo roamInfo = {0};
Jeff Johnson295189b2012-06-20 16:38:30 -07003142
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303143 if((eWNI_SME_SCAN_RSP == pMsg->type) ||
3144 (eWNI_SME_GET_SCANNED_CHANNEL_RSP == pMsg->type))
Jeff Johnson295189b2012-06-20 16:38:30 -07003145 {
3146 status = csrScanSmeScanResponse( pMac, pMsgBuf );
3147 }
3148 else
3149 {
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303150 switch (pMsg->type)
Jeff Johnson295189b2012-06-20 16:38:30 -07003151 {
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303152 case eWNI_SME_UPPER_LAYER_ASSOC_CNF:
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08003153 {
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303154 tCsrRoamSession *pSession;
3155 tSirSmeAssocIndToUpperLayerCnf *pUpperLayerAssocCnf;
3156 tCsrRoamInfo *pRoamInfo = NULL;
3157 tANI_U32 sessionId;
3158 eHalStatus status;
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08003159
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303160 smsLog( pMac, LOG1,
3161 FL("Scanning : ASSOCIATION confirmation can be given to upper layer "));
3162 pRoamInfo = &roamInfo;
3163 pUpperLayerAssocCnf = (tSirSmeAssocIndToUpperLayerCnf *)pMsgBuf;
3164 status = csrRoamGetSessionIdFromBSSID( pMac,
3165 (tCsrBssid *)pUpperLayerAssocCnf->bssId,
3166 &sessionId );
3167 pSession = CSR_GET_SESSION(pMac, sessionId);
3168
3169 if(!pSession)
3170 {
3171 smsLog(pMac, LOGE, FL("session %d not found "), sessionId);
3172 return eHAL_STATUS_FAILURE;
3173 }
3174
3175 //send the status code as Success
3176 pRoamInfo->statusCode = eSIR_SME_SUCCESS;
3177 pRoamInfo->u.pConnectedProfile = &pSession->connectedProfile;
3178 pRoamInfo->staId = (tANI_U8)pUpperLayerAssocCnf->aid;
3179 pRoamInfo->rsnIELen =
3180 (tANI_U8)pUpperLayerAssocCnf->rsnIE.length;
3181 pRoamInfo->prsnIE = pUpperLayerAssocCnf->rsnIE.rsnIEdata;
3182 pRoamInfo->addIELen =
3183 (tANI_U8)pUpperLayerAssocCnf->addIE.length;
3184 pRoamInfo->paddIE = pUpperLayerAssocCnf->addIE.addIEdata;
3185 vos_mem_copy(pRoamInfo->peerMac,
3186 pUpperLayerAssocCnf->peerMacAddr,
3187 sizeof(tSirMacAddr));
3188 vos_mem_copy(&pRoamInfo->bssid,
3189 pUpperLayerAssocCnf->bssId,
3190 sizeof(tCsrBssid));
3191 pRoamInfo->wmmEnabledSta = pUpperLayerAssocCnf->wmmEnabledSta;
Hardik Kantilal Patel1ba630f2014-11-21 04:32:05 +05303192#ifdef WLAN_FEATURE_AP_HT40_24G
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303193 pRoamInfo->HT40MHzIntoEnabledSta =
3194 pUpperLayerAssocCnf->HT40MHzIntoEnabledSta;
Hardik Kantilal Patel1ba630f2014-11-21 04:32:05 +05303195#endif
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303196 if(CSR_IS_INFRA_AP(pRoamInfo->u.pConnectedProfile) )
3197 {
3198 pMac->roam.roamSession[sessionId].connectState =
3199 eCSR_ASSOC_STATE_TYPE_INFRA_CONNECTED;
3200 pRoamInfo->fReassocReq = pUpperLayerAssocCnf->reassocReq;
3201 status = csrRoamCallCallback(pMac, sessionId, pRoamInfo,
3202 0, eCSR_ROAM_INFRA_IND,
3203 eCSR_ROAM_RESULT_INFRA_ASSOCIATION_CNF);
3204 }
3205 if(CSR_IS_WDS_AP( pRoamInfo->u.pConnectedProfile))
3206 {
3207 vos_sleep( 100 );
3208 pMac->roam.roamSession[sessionId].connectState =
3209 eCSR_ASSOC_STATE_TYPE_WDS_CONNECTED;//Sta
3210 status = csrRoamCallCallback(pMac, sessionId, pRoamInfo, 0,
3211 eCSR_ROAM_WDS_IND,
3212 eCSR_ROAM_RESULT_WDS_ASSOCIATION_IND);//Sta
3213 }
3214 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07003215 }
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303216 case eWNI_SME_DISCONNECT_DONE_IND:
3217 pDisConDoneInd = (tSirSmeDisConDoneInd *)(pMsg);
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08003218
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303219 smsLog( pMac, LOG1,
3220 FL("eWNI_SME_DISCONNECT_DONE_IND RC:%d"),
3221 pDisConDoneInd->reasonCode);
3222 if( CSR_IS_SESSION_VALID(pMac, pDisConDoneInd->sessionId))
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08003223 {
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303224 roamInfo.reasonCode = pDisConDoneInd->reasonCode;
3225 roamInfo.statusCode = eSIR_SME_STA_DISASSOCIATED;
3226 vos_mem_copy(roamInfo.peerMac, pDisConDoneInd->peerMacAddr,
3227 sizeof(tSirMacAddr));
3228 status = csrRoamCallCallback(pMac,
3229 pDisConDoneInd->sessionId,
3230 &roamInfo, 0,
3231 eCSR_ROAM_LOSTLINK,
3232 eCSR_ROAM_RESULT_DISASSOC_IND);
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08003233 }
3234 else
3235 {
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303236 smsLog(pMac, LOGE, FL("Inactive session %d"),
3237 pDisConDoneInd->sessionId);
3238 status = eHAL_STATUS_FAILURE;
3239 }
3240 break;
3241
3242 default :
3243 if( csrIsAnySessionInConnectState( pMac ) )
3244 {
3245 /*In case of we are connected, we need to check whether connect
3246 * status changes because scan may also run while connected.
3247 */
3248 csrRoamCheckForLinkStatusChange( pMac, (tSirSmeRsp *)pMsgBuf );
3249 }
3250 else
3251 {
3252 smsLog( pMac, LOGW,
3253 "Message [0x%04x] received in state, when expecting Scan Response",
3254 pMsg->type );
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08003255 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003256 }
3257 }
3258
3259 return (status);
3260}
3261
3262
3263
3264void csrCheckNSaveWscIe(tpAniSirGlobal pMac, tSirBssDescription *pNewBssDescr, tSirBssDescription *pOldBssDescr)
3265{
3266 int idx, len;
3267 tANI_U8 *pbIe;
3268
3269 //If failed to remove, assuming someone else got it.
3270 if((pNewBssDescr->fProbeRsp != pOldBssDescr->fProbeRsp) &&
3271 (0 == pNewBssDescr->WscIeLen))
3272 {
3273 idx = 0;
3274 len = pOldBssDescr->length - sizeof(tSirBssDescription) +
3275 sizeof(tANI_U16) + sizeof(tANI_U32) - DOT11F_IE_WSCPROBERES_MIN_LEN - 2;
3276 pbIe = (tANI_U8 *)pOldBssDescr->ieFields;
3277 //Save WPS IE if it exists
3278 pNewBssDescr->WscIeLen = 0;
3279 while(idx < len)
3280 {
3281 if((DOT11F_EID_WSCPROBERES == pbIe[0]) &&
3282 (0x00 == pbIe[2]) && (0x50 == pbIe[3]) && (0xf2 == pbIe[4]) && (0x04 == pbIe[5]))
3283 {
3284 //Founrd it
3285 if((DOT11F_IE_WSCPROBERES_MAX_LEN - 2) >= pbIe[1])
3286 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303287 vos_mem_copy(pNewBssDescr->WscIeProbeRsp, pbIe, pbIe[1] + 2);
Jeff Johnson295189b2012-06-20 16:38:30 -07003288 pNewBssDescr->WscIeLen = pbIe[1] + 2;
3289 }
3290 break;
3291 }
3292 idx += pbIe[1] + 2;
3293 pbIe += pbIe[1] + 2;
3294 }
3295 }
3296}
3297
3298
3299
3300//pIes may be NULL
3301tANI_BOOLEAN csrRemoveDupBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDescr,
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05303302 tDot11fBeaconIEs *pIes, tAniSSID *pSsid, v_TIME_t *timer, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07003303{
3304 tListElem *pEntry;
3305
3306 tCsrScanResult *pBssDesc;
3307 tANI_BOOLEAN fRC = FALSE;
3308
3309 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
3310 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
3311 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
3312 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
3313
3314 while( pEntry )
3315 {
3316 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3317
3318 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
3319 // matches
3320 if ( csrIsDuplicateBssDescription( pMac, &pBssDesc->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07003321 pSirBssDescr, pIes, fForced ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003322 {
3323 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
3324 ((tANI_S32)pBssDesc->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
3325 // Remove the 'old' entry from the list....
3326 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry, LL_ACCESS_LOCK ) )
3327 {
3328 // !we need to free the memory associated with this node
3329 //If failed to remove, assuming someone else got it.
3330 *pSsid = pBssDesc->Result.ssId;
3331 *timer = pBssDesc->Result.timer;
3332 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pBssDesc->Result.BssDescriptor);
3333
3334 csrFreeScanResultEntry( pMac, pBssDesc );
3335 }
3336 else
3337 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003338 smsLog( pMac, LOGW, FL( " fail to remove entry" ) );
Jeff Johnson295189b2012-06-20 16:38:30 -07003339 }
3340 fRC = TRUE;
3341
3342 // If we found a match, we can stop looking through the list.
3343 break;
3344 }
3345
3346 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_LOCK );
3347 }
3348
3349 return fRC;
3350}
3351
3352
3353eHalStatus csrAddPMKIDCandidateList( tpAniSirGlobal pMac, tANI_U32 sessionId,
3354 tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes )
3355{
3356 eHalStatus status = eHAL_STATUS_FAILURE;
3357 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
3358
Jeff Johnson32d95a32012-09-10 13:15:23 -07003359 if(!pSession)
3360 {
3361 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
3362 return eHAL_STATUS_FAILURE;
3363 }
3364
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003365 smsLog(pMac, LOGW, "csrAddPMKIDCandidateList called pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07003366 if( pIes )
3367 {
3368 // check if this is a RSN BSS
3369 if( pIes->RSN.present )
3370 {
3371 // Check if the BSS is capable of doing pre-authentication
3372 if( pSession->NumPmkidCandidate < CSR_MAX_PMKID_ALLOWED )
3373 {
3374
3375#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3376 {
3377 WLAN_VOS_DIAG_EVENT_DEF(secEvent, vos_event_wlan_security_payload_type);
Kiet Lam64c1b492013-07-12 13:56:44 +05303378 vos_mem_set(&secEvent, sizeof(vos_event_wlan_security_payload_type), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003379 secEvent.eventId = WLAN_SECURITY_EVENT_PMKID_CANDIDATE_FOUND;
3380 secEvent.encryptionModeMulticast =
3381 (v_U8_t)diagEncTypeFromCSRType(pSession->connectedProfile.mcEncryptionType);
3382 secEvent.encryptionModeUnicast =
3383 (v_U8_t)diagEncTypeFromCSRType(pSession->connectedProfile.EncryptionType);
Kiet Lam64c1b492013-07-12 13:56:44 +05303384 vos_mem_copy(secEvent.bssid, pSession->connectedProfile.bssid, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07003385 secEvent.authMode =
3386 (v_U8_t)diagAuthTypeFromCSRType(pSession->connectedProfile.AuthType);
3387 WLAN_VOS_DIAG_EVENT_REPORT(&secEvent, EVENT_WLAN_SECURITY);
3388 }
3389#endif//#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3390
3391 // if yes, then add to PMKIDCandidateList
Kiet Lam64c1b492013-07-12 13:56:44 +05303392 vos_mem_copy(pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].BSSID,
3393 pBssDesc->bssId, WNI_CFG_BSSID_LEN);
3394 // Bit 0 offirst byte - PreAuthentication Capability
3395 if ( (pIes->RSN.RSN_Cap[0] >> 0) & 0x1 )
Jeff Johnson295189b2012-06-20 16:38:30 -07003396 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303397 pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].preAuthSupported
3398 = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003399 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303400 else
3401 {
3402 pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].preAuthSupported
3403 = eANI_BOOLEAN_FALSE;
3404 }
3405 pSession->NumPmkidCandidate++;
Jeff Johnson295189b2012-06-20 16:38:30 -07003406 }
3407 else
3408 {
3409 status = eHAL_STATUS_FAILURE;
3410 }
3411 }
3412 }
3413
3414 return (status);
3415}
3416
3417//This function checks whether new AP is found for the current connected profile
3418//If it is found, it return the sessionId, else it return invalid sessionID
3419tANI_U32 csrProcessBSSDescForPMKIDList(tpAniSirGlobal pMac,
3420 tSirBssDescription *pBssDesc,
3421 tDot11fBeaconIEs *pIes)
3422{
3423 tANI_U32 i, bRet = CSR_SESSION_ID_INVALID;
3424 tCsrRoamSession *pSession;
3425 tDot11fBeaconIEs *pIesLocal = pIes;
3426
3427 if( pIesLocal || HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIesLocal)) )
3428 {
3429 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
3430 {
3431 if( CSR_IS_SESSION_VALID( pMac, i ) )
3432 {
3433 pSession = CSR_GET_SESSION( pMac, i );
3434 if( csrIsConnStateConnectedInfra( pMac, i ) &&
3435 ( eCSR_AUTH_TYPE_RSN == pSession->connectedProfile.AuthType ) )
3436 {
3437 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile, pBssDesc, pIesLocal))
3438 {
3439 //this new BSS fits the current profile connected
3440 if(HAL_STATUS_SUCCESS(csrAddPMKIDCandidateList(pMac, i, pBssDesc, pIesLocal)))
3441 {
3442 bRet = i;
3443 }
3444 break;
3445 }
3446 }
3447 }
3448 }
3449 if( !pIes )
3450 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303451 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003452 }
3453 }
3454
3455 return (tANI_U8)bRet;
3456}
3457
3458#ifdef FEATURE_WLAN_WAPI
3459eHalStatus csrAddBKIDCandidateList( tpAniSirGlobal pMac, tANI_U32 sessionId,
3460 tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes )
3461{
3462 eHalStatus status = eHAL_STATUS_FAILURE;
3463 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
3464
Jeff Johnson32d95a32012-09-10 13:15:23 -07003465 if(!pSession)
3466 {
3467 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
3468 return eHAL_STATUS_FAILURE;
3469 }
3470
Kiet Lam64c1b492013-07-12 13:56:44 +05303471 smsLog(pMac, LOGW, "csrAddBKIDCandidateList called pMac->scan.NumBkidCandidate = %d",
3472 pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07003473 if( pIes )
3474 {
3475 // check if this is a WAPI BSS
3476 if( pIes->WAPI.present )
3477 {
3478 // Check if the BSS is capable of doing pre-authentication
3479 if( pSession->NumBkidCandidate < CSR_MAX_BKID_ALLOWED )
3480 {
3481
3482 // if yes, then add to BKIDCandidateList
Kiet Lam64c1b492013-07-12 13:56:44 +05303483 vos_mem_copy(pSession->BkidCandidateInfo[pSession->NumBkidCandidate].BSSID,
3484 pBssDesc->bssId, WNI_CFG_BSSID_LEN);
3485 if ( pIes->WAPI.preauth )
Jeff Johnson295189b2012-06-20 16:38:30 -07003486 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303487 pSession->BkidCandidateInfo[pSession->NumBkidCandidate].preAuthSupported
3488 = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003489 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303490 else
3491 {
3492 pSession->BkidCandidateInfo[pSession->NumBkidCandidate].preAuthSupported
3493 = eANI_BOOLEAN_FALSE;
3494 }
3495 pSession->NumBkidCandidate++;
Jeff Johnson295189b2012-06-20 16:38:30 -07003496 }
3497 else
3498 {
3499 status = eHAL_STATUS_FAILURE;
3500 }
3501 }
3502 }
3503
3504 return (status);
3505}
3506
3507//This function checks whether new AP is found for the current connected profile
3508//if so add to BKIDCandidateList
3509tANI_BOOLEAN csrProcessBSSDescForBKIDList(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
3510 tDot11fBeaconIEs *pIes)
3511{
3512 tANI_BOOLEAN fRC = FALSE;
3513 tDot11fBeaconIEs *pIesLocal = pIes;
3514 tANI_U32 sessionId;
3515 tCsrRoamSession *pSession;
3516
3517 if( pIesLocal || HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIesLocal)) )
3518 {
3519 for( sessionId = 0; sessionId < CSR_ROAM_SESSION_MAX; sessionId++ )
3520 {
3521 if( CSR_IS_SESSION_VALID( pMac, sessionId) )
3522 {
3523 pSession = CSR_GET_SESSION( pMac, sessionId );
3524 if( csrIsConnStateConnectedInfra( pMac, sessionId ) &&
3525 eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE == pSession->connectedProfile.AuthType)
3526 {
3527 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile,pBssDesc, pIesLocal))
3528 {
3529 //this new BSS fits the current profile connected
3530 if(HAL_STATUS_SUCCESS(csrAddBKIDCandidateList(pMac, sessionId, pBssDesc, pIesLocal)))
3531 {
3532 fRC = TRUE;
3533 }
3534 }
3535 }
3536 }
3537 }
3538 if(!pIes)
3539 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303540 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003541 }
3542
3543 }
3544 return fRC;
3545}
3546
3547#endif
3548
3549
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07003550static void csrMoveTempScanResultsToMainList( tpAniSirGlobal pMac, tANI_U8 reason )
Jeff Johnson295189b2012-06-20 16:38:30 -07003551{
3552 tListElem *pEntry;
3553 tCsrScanResult *pBssDescription;
Jeff Johnson295189b2012-06-20 16:38:30 -07003554 tANI_BOOLEAN fDupBss;
3555#ifdef FEATURE_WLAN_WAPI
3556 tANI_BOOLEAN fNewWapiBSSForCurConnection = eANI_BOOLEAN_FALSE;
3557#endif /* FEATURE_WLAN_WAPI */
3558 tDot11fBeaconIEs *pIesLocal = NULL;
3559 tANI_U32 sessionId = CSR_SESSION_ID_INVALID;
3560 tAniSSID tmpSsid;
3561 v_TIME_t timer=0;
3562
3563 tmpSsid.length = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07003564
3565 // remove the BSS descriptions from temporary list
3566 while( ( pEntry = csrLLRemoveTail( &pMac->scan.tempScanResults, LL_ACCESS_LOCK ) ) != NULL)
3567 {
3568 pBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3569
Vinay Krishna Eranna566365f2015-03-09 12:34:13 +05303570 smsLog( pMac, LOG2, "...Bssid= "MAC_ADDRESS_STR" chan= %d, rssi = -%d",
Arif Hussain24bafea2013-11-15 15:10:03 -08003571 MAC_ADDR_ARRAY(pBssDescription->Result.BssDescriptor.bssId),
Jeff Johnson295189b2012-06-20 16:38:30 -07003572 pBssDescription->Result.BssDescriptor.channelId,
3573 pBssDescription->Result.BssDescriptor.rssi * (-1) );
3574
3575 //At this time, pBssDescription->Result.pvIes may be NULL
3576 pIesLocal = (tDot11fBeaconIEs *)( pBssDescription->Result.pvIes );
3577 if( !pIesLocal && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pBssDescription->Result.BssDescriptor, &pIesLocal))) )
3578 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003579 smsLog(pMac, LOGE, FL(" Cannot pared IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003580 csrFreeScanResultEntry(pMac, pBssDescription);
3581 continue;
3582 }
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05303583 fDupBss = csrRemoveDupBssDescription( pMac, &pBssDescription->Result.BssDescriptor, pIesLocal, &tmpSsid, &timer, FALSE );
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07003584 //Check whether we have reach out limit, but don't lose the LFR candidates came from FW
3585 if( CSR_SCAN_IS_OVER_BSS_LIMIT(pMac)
3586#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
3587 && !( eCsrScanGetLfrResult == reason )
3588#endif
3589 )
Jeff Johnson295189b2012-06-20 16:38:30 -07003590 {
Deepthi Gowri50e2fa52016-03-17 15:30:53 +05303591 smsLog(pMac, LOG1, FL("########## BSS Limit reached ###########"));
3592 csrPurgeOldScanResults(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07003593 }
3594 // check for duplicate scan results
3595 if ( !fDupBss )
3596 {
3597 //Found a new BSS
3598 sessionId = csrProcessBSSDescForPMKIDList(pMac,
3599 &pBssDescription->Result.BssDescriptor, pIesLocal);
3600 if( CSR_SESSION_ID_INVALID != sessionId)
3601 {
3602 csrRoamCallCallback(pMac, sessionId, NULL, 0,
3603 eCSR_ROAM_SCAN_FOUND_NEW_BSS, eCSR_ROAM_RESULT_NONE);
3604 }
3605 }
3606 else
3607 {
3608 //Check if the new one has SSID it it, if not, use the older SSID if it exists.
3609 if( (0 == pBssDescription->Result.ssId.length) && tmpSsid.length )
3610 {
3611 //New BSS has a hidden SSID and old one has the SSID. Keep the SSID only
3612 //if diff of saved SSID time and current time is less than 1 min to avoid
3613 //side effect of saving SSID with old one is that if AP changes its SSID while remain
3614 //hidden, we may never see it and also to address the requirement of
3615 //When we remove hidden ssid from the profile i.e., forget the SSID via
3616 // GUI that SSID shouldn't see in the profile
3617 if( (vos_timer_get_system_time() - timer) <= HIDDEN_TIMER)
3618 {
3619 pBssDescription->Result.timer = timer;
3620 pBssDescription->Result.ssId = tmpSsid;
3621 }
3622 }
3623 }
3624
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303625 //Find a good AP for 11d info
3626 if ( csrIs11dSupported( pMac ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003627 {
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303628 // check if country information element is present
3629 if (pIesLocal->Country.present)
Jeff Johnson295189b2012-06-20 16:38:30 -07003630 {
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303631 csrAddVoteForCountryInfo(pMac, pIesLocal->Country.country);
3632 smsLog(pMac, LOGW, FL("11d AP Bssid " MAC_ADDRESS_STR
3633 " chan= %d, rssi = -%d, countryCode %c%c"),
3634 MAC_ADDR_ARRAY( pBssDescription->Result.BssDescriptor.bssId),
3635 pBssDescription->Result.BssDescriptor.channelId,
3636 pBssDescription->Result.BssDescriptor.rssi * (-1),
3637 pIesLocal->Country.country[0],pIesLocal->Country.country[1] );
3638 }
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303639
Jeff Johnson295189b2012-06-20 16:38:30 -07003640 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08003641
Jeff Johnson295189b2012-06-20 16:38:30 -07003642 // append to main list
3643 csrScanAddResult(pMac, pBssDescription, pIesLocal);
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303644 if ( (pBssDescription->Result.pvIes == NULL) && pIesLocal )
Jeff Johnson295189b2012-06-20 16:38:30 -07003645 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303646 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003647 }
3648 }
3649
Sushant Kaushik6274de62015-05-01 16:31:23 +05303650 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
Tushnim Bhattacharyyaae317772013-10-23 18:55:38 -07003651 //we don't need to update CC while connected to an AP which is advertising CC already
3652 if (csrIs11dSupported(pMac))
3653 {
3654 tANI_U32 i;
3655 tCsrRoamSession *pSession;
3656
3657 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
3658 {
3659 if (CSR_IS_SESSION_VALID( pMac, i ) )
3660 {
3661 pSession = CSR_GET_SESSION( pMac, i );
3662 if (csrIsConnStateConnected(pMac, i))
3663 {
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303664 smsLog(pMac, LOGW, FL("No need for updating CC in"
3665 "connected state"));
3666 goto end;
Tushnim Bhattacharyyaae317772013-10-23 18:55:38 -07003667 }
3668 }
3669 }
Agrawal Ashishbd3a5932016-04-12 16:22:39 +05303670 if (csrElectedCountryInfo(pMac))
3671 csrLearnCountryInformation(pMac, NULL, NULL,
3672 eANI_BOOLEAN_TRUE);
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303673 }
3674
Tushnim Bhattacharyyaae317772013-10-23 18:55:38 -07003675end:
3676 //If we can find the current 11d info in any of the scan results, or
Jeff Johnson295189b2012-06-20 16:38:30 -07003677 // a good enough AP with the 11d info from the scan results then no need to
3678 // get into ambiguous state
3679 if(pMac->scan.fAmbiguous11dInfoFound)
3680 {
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303681 if((pMac->scan.fCurrent11dInfoMatch))
Jeff Johnson295189b2012-06-20 16:38:30 -07003682 {
3683 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
3684 }
3685 }
3686
3687#ifdef FEATURE_WLAN_WAPI
3688 if(fNewWapiBSSForCurConnection)
3689 {
3690 //remember it first
3691 csrRoamCallCallback(pMac, sessionId, NULL, 0, eCSR_ROAM_SCAN_FOUND_NEW_BSS, eCSR_ROAM_RESULT_NEW_WAPI_BSS);
3692 }
3693#endif /* FEATURE_WLAN_WAPI */
3694
3695 return;
3696}
3697
Deepthi Gowri50e2fa52016-03-17 15:30:53 +05303698void csrPurgeOldScanResults(tpAniSirGlobal pMac)
3699{
3700 tListElem *pEntry, *tmpEntry;
3701 tCsrScanResult *pResult, *oldest_bss = NULL;
Deepthi Gowri4480a3f2016-05-18 19:30:17 +05303702 v_TIME_t oldest_entry = 0;
3703 v_TIME_t curTime = vos_timer_get_system_time();
Deepthi Gowri50e2fa52016-03-17 15:30:53 +05303704
3705 csrLLLock(&pMac->scan.scanResultList);
3706 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
3707 while( pEntry )
3708 {
3709 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry,
3710 LL_ACCESS_NOLOCK);
3711 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3712 if((curTime -
3713 pResult->Result.BssDescriptor.nReceivedTime) > oldest_entry)
3714 {
3715 oldest_entry = curTime -
3716 pResult->Result.BssDescriptor.nReceivedTime;
3717 oldest_bss = pResult;
3718 }
3719 pEntry = tmpEntry;
3720 }
3721 if (oldest_bss)
3722 {
3723 //Free the old BSS Entries
3724 if( csrLLRemoveEntry(&pMac->scan.scanResultList,
3725 &oldest_bss->Link, LL_ACCESS_NOLOCK) )
3726 {
Deepthi Gowri6a08e312016-03-31 19:10:14 +05303727 smsLog(pMac, LOG1, FL(" Current time delta (%lu) of BSSID to be removed" MAC_ADDRESS_STR ),
Deepthi Gowri50e2fa52016-03-17 15:30:53 +05303728 (curTime - oldest_bss->Result.BssDescriptor.nReceivedTime),
3729 MAC_ADDR_ARRAY(oldest_bss->Result.BssDescriptor.bssId));
3730 csrFreeScanResultEntry(pMac, oldest_bss);
3731 }
3732 }
3733 csrLLUnlock(&pMac->scan.scanResultList);
3734}
Jeff Johnson295189b2012-06-20 16:38:30 -07003735
3736static tCsrScanResult *csrScanSaveBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pBSSDescription,
3737 tDot11fBeaconIEs *pIes)
3738{
3739 tCsrScanResult *pCsrBssDescription = NULL;
3740 tANI_U32 cbBSSDesc;
3741 tANI_U32 cbAllocated;
Sushant Kaushik6274de62015-05-01 16:31:23 +05303742 tListElem *pEntry;
Jeff Johnson295189b2012-06-20 16:38:30 -07003743
3744 // figure out how big the BSS description is (the BSSDesc->length does NOT
3745 // include the size of the length field itself).
3746 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
3747
3748 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
3749
Kiet Lam64c1b492013-07-12 13:56:44 +05303750 pCsrBssDescription = vos_mem_malloc(cbAllocated);
3751 if ( NULL != pCsrBssDescription )
Jeff Johnson295189b2012-06-20 16:38:30 -07003752 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303753 vos_mem_set(pCsrBssDescription, cbAllocated, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003754 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Kiet Lam64c1b492013-07-12 13:56:44 +05303755 vos_mem_copy(&pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc);
Jeff Johnson295189b2012-06-20 16:38:30 -07003756#if defined(VOSS_ENSBALED)
3757 VOS_ASSERT( pCsrBssDescription->Result.pvIes == NULL );
3758#endif
3759 csrScanAddResult(pMac, pCsrBssDescription, pIes);
Sushant Kaushik6274de62015-05-01 16:31:23 +05303760 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
Jeff Johnson295189b2012-06-20 16:38:30 -07003761 }
3762
3763 return( pCsrBssDescription );
3764}
3765
3766// Append a Bss Description...
3767tCsrScanResult *csrScanAppendBssDescription( tpAniSirGlobal pMac,
3768 tSirBssDescription *pSirBssDescription,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07003769 tDot11fBeaconIEs *pIes, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07003770{
3771 tCsrScanResult *pCsrBssDescription = NULL;
3772 tAniSSID tmpSsid;
3773 v_TIME_t timer = 0;
3774 int result;
3775
3776 tmpSsid.length = 0;
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07003777 result = csrRemoveDupBssDescription( pMac, pSirBssDescription, pIes, &tmpSsid, &timer, fForced );
Jeff Johnson295189b2012-06-20 16:38:30 -07003778 pCsrBssDescription = csrScanSaveBssDescription( pMac, pSirBssDescription, pIes );
3779 if (result && (pCsrBssDescription != NULL))
3780 {
3781 //Check if the new one has SSID it it, if not, use the older SSID if it exists.
3782 if( (0 == pCsrBssDescription->Result.ssId.length) && tmpSsid.length )
3783 {
3784 //New BSS has a hidden SSID and old one has the SSID. Keep the SSID only
3785 //if diff of saved SSID time and current time is less than 1 min to avoid
3786 //side effect of saving SSID with old one is that if AP changes its SSID while remain
3787 //hidden, we may never see it and also to address the requirement of
3788 //When we remove hidden ssid from the profile i.e., forget the SSID via
3789 // GUI that SSID shouldn't see in the profile
3790 if((vos_timer_get_system_time()-timer) <= HIDDEN_TIMER)
3791 {
3792 pCsrBssDescription->Result.ssId = tmpSsid;
3793 pCsrBssDescription->Result.timer = timer;
3794 }
3795 }
3796 }
3797
3798
3799 return( pCsrBssDescription );
3800}
3801
3802
3803
3804void csrPurgeChannelPower( tpAniSirGlobal pMac, tDblLinkList *pChannelList )
3805{
3806 tCsrChannelPowerInfo *pChannelSet;
3807 tListElem *pEntry;
3808
3809 csrLLLock(pChannelList);
3810 // Remove the channel sets from the learned list and put them in the free list
3811 while( ( pEntry = csrLLRemoveHead( pChannelList, LL_ACCESS_NOLOCK ) ) != NULL)
3812 {
3813 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3814 if( pChannelSet )
3815 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303816 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003817 }
3818 }
3819 csrLLUnlock(pChannelList);
3820 return;
3821}
3822
3823
3824/*
3825 * Save the channelList into the ultimate storage as the final stage of channel
3826 * Input: pCountryInfo -- the country code (e.g. "USI"), channel list, and power limit are all stored inside this data structure
3827 */
Jeff Johnsone7245742012-09-05 17:12:55 -07003828eHalStatus csrSaveToChannelPower2G_5G( tpAniSirGlobal pMac, tANI_U32 tableSize, tSirMacChanInfo *channelTable )
Jeff Johnson295189b2012-06-20 16:38:30 -07003829{
3830 tANI_U32 i = tableSize / sizeof( tSirMacChanInfo );
3831 tSirMacChanInfo *pChannelInfo;
3832 tCsrChannelPowerInfo *pChannelSet;
3833 tANI_BOOLEAN f2GHzInfoFound = FALSE;
3834 tANI_BOOLEAN f2GListPurged = FALSE, f5GListPurged = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003835
3836 pChannelInfo = channelTable;
3837 // atleast 3 bytes have to be remaining -- from "countryString"
3838 while ( i-- )
3839 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303840 pChannelSet = vos_mem_malloc(sizeof(tCsrChannelPowerInfo));
3841 if ( NULL != pChannelSet )
Jeff Johnson295189b2012-06-20 16:38:30 -07003842 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303843 vos_mem_set(pChannelSet, sizeof(tCsrChannelPowerInfo), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003844 pChannelSet->firstChannel = pChannelInfo->firstChanNum;
3845 pChannelSet->numChannels = pChannelInfo->numChannels;
3846
3847 // Now set the inter-channel offset based on the frequency band the channel set lies in
Jeff Johnsone7245742012-09-05 17:12:55 -07003848 if( (CSR_IS_CHANNEL_24GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003849 ((pChannelSet->firstChannel + (pChannelSet->numChannels - 1)) <= CSR_MAX_24GHz_CHANNEL_NUMBER) )
Jeff Johnsone7245742012-09-05 17:12:55 -07003850
Jeff Johnson295189b2012-06-20 16:38:30 -07003851 {
3852 pChannelSet->interChannelOffset = 1;
3853 f2GHzInfoFound = TRUE;
3854 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003855 else if ( (CSR_IS_CHANNEL_5GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003856 ((pChannelSet->firstChannel + ((pChannelSet->numChannels - 1) * 4)) <= CSR_MAX_5GHz_CHANNEL_NUMBER) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003857 {
3858 pChannelSet->interChannelOffset = 4;
3859 f2GHzInfoFound = FALSE;
3860 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003861 else
3862 {
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003863 smsLog( pMac, LOGW, FL("Invalid Channel %d Present in Country IE"),
Jeff Johnsone7245742012-09-05 17:12:55 -07003864 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303865 vos_mem_free(pChannelSet);
Jeff Johnsone7245742012-09-05 17:12:55 -07003866 return eHAL_STATUS_FAILURE;
3867 }
3868
Jeff Johnson295189b2012-06-20 16:38:30 -07003869 pChannelSet->txPower = CSR_ROAM_MIN( pChannelInfo->maxTxPower, pMac->roam.configParam.nTxPowerCap );
3870
3871 if( f2GHzInfoFound )
3872 {
3873 if( !f2GListPurged )
3874 {
3875 // purge previous results if found new
3876 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList24 );
3877 f2GListPurged = TRUE;
3878 }
3879
3880 if(CSR_IS_OPERATING_BG_BAND(pMac))
3881 {
3882 // add to the list of 2.4 GHz channel sets
3883 csrLLInsertTail( &pMac->scan.channelPowerInfoList24, &pChannelSet->link, LL_ACCESS_LOCK );
3884 }
3885 else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003886 smsLog( pMac, LOGW, FL("Adding 11B/G channels in 11A mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003887 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303888 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003889 }
3890 }
3891 else
3892 {
3893 // 5GHz info found
3894 if( !f5GListPurged )
3895 {
3896 // purge previous results if found new
3897 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList5G );
3898 f5GListPurged = TRUE;
3899 }
3900
3901 if(CSR_IS_OPERATING_A_BAND(pMac))
3902 {
3903 // add to the list of 5GHz channel sets
3904 csrLLInsertTail( &pMac->scan.channelPowerInfoList5G, &pChannelSet->link, LL_ACCESS_LOCK );
3905 }
3906 else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003907 smsLog( pMac, LOGW, FL("Adding 11A channels in B/G mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003908 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303909 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003910 }
3911 }
3912 }
3913
3914 pChannelInfo++; // move to next entry
3915 }
3916
Jeff Johnsone7245742012-09-05 17:12:55 -07003917 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07003918}
3919
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303920static void csrClearDfsChannelList( tpAniSirGlobal pMac )
3921{
3922 tSirMbMsg *pMsg;
3923 tANI_U16 msgLen;
Jeff Johnson295189b2012-06-20 16:38:30 -07003924
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303925 msgLen = (tANI_U16)(sizeof( tSirMbMsg ));
Kiet Lam64c1b492013-07-12 13:56:44 +05303926 pMsg = vos_mem_malloc(msgLen);
3927 if ( NULL != pMsg )
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303928 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303929 vos_mem_set((void *)pMsg, msgLen, 0);
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303930 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_CLEAR_DFS_CHANNEL_LIST);
3931 pMsg->msgLen = pal_cpu_to_be16(msgLen);
3932 palSendMBMessage(pMac->hHdd, pMsg);
3933 }
3934}
Jeff Johnson295189b2012-06-20 16:38:30 -07003935
3936void csrApplyPower2Current( tpAniSirGlobal pMac )
3937{
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003938 smsLog( pMac, LOG3, FL(" Updating Cfg with power settings"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003939 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList24, WNI_CFG_MAX_TX_POWER_2_4 );
3940 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList5G, WNI_CFG_MAX_TX_POWER_5 );
3941}
3942
3943
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003944void csrApplyChannelPowerCountryInfo( tpAniSirGlobal pMac, tCsrChannel *pChannelList, tANI_U8 *countryCode, tANI_BOOLEAN updateRiva)
Jeff Johnson295189b2012-06-20 16:38:30 -07003945{
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303946 int i, j, count, countryIndex = -1;
Jeff Johnson295189b2012-06-20 16:38:30 -07003947 tANI_U8 numChannels = 0;
3948 tANI_U8 tempNumChannels = 0;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303949 tANI_U8 channelIgnore = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003950 tCsrChannel ChannelList;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303951
Jeff Johnson295189b2012-06-20 16:38:30 -07003952 if( pChannelList->numChannels )
3953 {
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303954 for(count=0; count < MAX_COUNTRY_IGNORE; count++)
3955 {
3956 if(vos_mem_compare(countryCode, countryIgnoreList[count].countryCode,
3957 VOS_COUNTRY_CODE_LEN))
3958 {
3959 countryIndex = count;
3960 break;
3961 }
3962 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003963 tempNumChannels = CSR_MIN(pChannelList->numChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN);
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05303964
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303965 for(i=0; i < tempNumChannels; i++)
Jeff Johnson295189b2012-06-20 16:38:30 -07003966 {
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303967 channelIgnore = FALSE;
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05303968 if( countryIndex != -1 )
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303969 {
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05303970 for(j=0; j < countryIgnoreList[countryIndex].channelCount; j++)
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303971 {
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05303972 if( pChannelList->channelList[i] ==
3973 countryIgnoreList[countryIndex].channelList[j] )
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303974 {
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05303975 channelIgnore = TRUE;
3976 break;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303977 }
3978 }
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05303979 }
3980 if( FALSE == channelIgnore )
3981 {
3982 ChannelList.channelList[numChannels] = pChannelList->channelList[i];
3983 numChannels++;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303984 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003985 }
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303986 ChannelList.numChannels = numChannels;
Mahesh A Saptasagar1ed59582014-06-04 18:45:07 +05303987 csrApplyPower2Current( pMac ); // Store the channel+power info in the global place: Cfg
Jeff Johnson295189b2012-06-20 16:38:30 -07003988 csrSetCfgValidChannelList(pMac, ChannelList.channelList, ChannelList.numChannels);
3989 // extend scan capability
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303990 // build a scan list based on the channel list : channel# + active/passive scan
3991 csrSetCfgScanControlList(pMac, countryCode, &ChannelList);
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303992 /*Send msg to Lim to clear DFS channel list */
3993 csrClearDfsChannelList(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07003994#ifdef FEATURE_WLAN_SCAN_PNO
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003995 if (updateRiva)
3996 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003997 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO, FL(" Sending 11d PNO info to Riva"));
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003998 // Send HAL UpdateScanParams message
3999 pmcUpdateScanParams(pMac, &(pMac->roam.configParam), &ChannelList, TRUE);
4000 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004001#endif // FEATURE_WLAN_SCAN_PNO
4002 }
4003 else
4004 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004005 smsLog( pMac, LOGE, FL(" 11D channel list is empty"));
Jeff Johnson295189b2012-06-20 16:38:30 -07004006 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004007 csrSetCfgCountryCode(pMac, countryCode);
4008}
4009
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004010void csrResetCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce, tANI_BOOLEAN updateRiva )
Jeff Johnson295189b2012-06-20 16:38:30 -07004011{
4012 if( fForce || (csrIs11dSupported( pMac ) && (!pMac->scan.f11dInfoReset)))
4013 {
4014
4015#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4016 {
4017 vos_log_802_11d_pkt_type *p11dLog;
4018 int Index;
4019
4020 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
4021 if(p11dLog)
4022 {
4023 p11dLog->eventId = WLAN_80211D_EVENT_RESET;
Kiet Lam64c1b492013-07-12 13:56:44 +05304024 vos_mem_copy(p11dLog->countryCode, pMac->scan.countryCodeCurrent, 3);
Jeff Johnson295189b2012-06-20 16:38:30 -07004025 p11dLog->numChannel = pMac->scan.base20MHzChannels.numChannels;
4026 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
4027 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304028 vos_mem_copy(p11dLog->Channels,
4029 pMac->scan.base20MHzChannels.channelList,
4030 p11dLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07004031 for (Index=0; Index < pMac->scan.base20MHzChannels.numChannels; Index++)
4032 {
4033 p11dLog->TxPwr[Index] = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
4034 }
4035 }
4036 if(!pMac->roam.configParam.Is11dSupportEnabled)
4037 {
4038 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
4039 }
4040 else if(pMac->roam.configParam.fEnforceDefaultDomain)
4041 {
4042 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
4043 }
4044 else
4045 {
4046 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
4047 }
4048 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
4049 }
4050 }
4051#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4052
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004053 csrPruneChannelListForMode(pMac, &pMac->scan.baseChannels);
4054 csrPruneChannelListForMode(pMac, &pMac->scan.base20MHzChannels);
4055
Jeff Johnson295189b2012-06-20 16:38:30 -07004056 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_FALSE);
4057 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_TRUE);
4058 // ... and apply the channel list, power settings, and the country code.
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004059 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.base20MHzChannels, pMac->scan.countryCodeCurrent, updateRiva );
Jeff Johnson295189b2012-06-20 16:38:30 -07004060 // clear the 11d channel list
Kiet Lam64c1b492013-07-12 13:56:44 +05304061 vos_mem_set(&pMac->scan.channels11d, sizeof(pMac->scan.channels11d), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004062 pMac->scan.f11dInfoReset = eANI_BOOLEAN_TRUE;
4063 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_FALSE;
4064 }
4065
4066 return;
4067}
4068
4069
4070eHalStatus csrResetCountryCodeInformation(tpAniSirGlobal pMac, tANI_BOOLEAN *pfRestartNeeded)
4071{
4072 eHalStatus status = eHAL_STATUS_SUCCESS;
4073 tANI_BOOLEAN fRestart = eANI_BOOLEAN_FALSE;
4074
4075 //Use the Country code and domain from EEPROM
Kiet Lam64c1b492013-07-12 13:56:44 +05304076 vos_mem_copy(pMac->scan.countryCodeCurrent, pMac->scan.countryCodeDefault,
4077 WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07004078 csrSetRegulatoryDomain(pMac, pMac->scan.domainIdCurrent, &fRestart);
Jeff Johnson43971f52012-07-17 12:26:56 -07004079 if( ((eANI_BOOLEAN_FALSE == fRestart) || (pfRestartNeeded == NULL) )
4080 && !csrIsInfraConnected(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -07004081 {
4082 //Only reset the country info if we don't need to restart
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004083 csrResetCountryInformation(pMac, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07004084 }
4085 if(pfRestartNeeded)
4086 {
4087 *pfRestartNeeded = fRestart;
4088 }
4089
4090 return (status);
4091}
4092
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05304093void csrClearVotesForCountryInfo(tpAniSirGlobal pMac)
4094{
4095 pMac->scan.countryCodeCount = 0;
4096 vos_mem_set(pMac->scan.votes11d,
4097 sizeof(tCsrVotes11d) * CSR_MAX_NUM_COUNTRY_CODE, 0);
4098}
4099
4100void csrAddVoteForCountryInfo(tpAniSirGlobal pMac, tANI_U8 *pCountryCode)
4101{
4102 tANI_BOOLEAN match = FALSE;
4103 tANI_U8 i;
4104
4105 /* convert to UPPER here so we are assured
4106 * the strings are always in upper case.
4107 */
4108 for( i = 0; i < 3; i++ )
4109 {
4110 pCountryCode[ i ] = (tANI_U8)csrToUpper( pCountryCode[ i ] );
4111 }
4112
4113 /* Some of the 'old' Cisco 350 series AP's advertise NA as the
4114 * country code (for North America ??). NA is not a valid country code
4115 * or domain so let's allow this by changing it to the proper
4116 * country code (which is US). We've also seen some NETGEAR AP's
4117 * that have "XX " as the country code with valid 2.4 GHz US channel
4118 * information. If we cannot find the country code advertised in the
4119 * 11d information element, let's default to US.
4120 */
4121
4122 if ( !HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry( pMac,
4123 pCountryCode, NULL,COUNTRY_QUERY ) ) )
4124 {
4125 pCountryCode[ 0 ] = '0';
4126 pCountryCode[ 1 ] = '0';
4127 }
4128
4129 /* We've seen some of the AP's improperly put a 0 for the
4130 * third character of the country code. spec says valid charcters are
4131 * 'O' (for outdoor), 'I' for Indoor, or ' ' (space; for either).
4132 * if we see a 0 in this third character, let's change it to a ' '.
4133 */
4134 if ( 0 == pCountryCode[ 2 ] )
4135 {
4136 pCountryCode[ 2 ] = ' ';
4137 }
4138
4139 for (i = 0; i < pMac->scan.countryCodeCount; i++)
4140 {
4141 match = (vos_mem_compare(pMac->scan.votes11d[i].countryCode,
4142 pCountryCode, 2));
4143 if(match)
4144 {
4145 break;
4146 }
4147 }
4148
4149 if (match)
4150 {
4151 pMac->scan.votes11d[i].votes++;
4152 }
4153 else
4154 {
4155 vos_mem_copy( pMac->scan.votes11d[pMac->scan.countryCodeCount].countryCode,
4156 pCountryCode, 3 );
4157 pMac->scan.votes11d[pMac->scan.countryCodeCount].votes = 1;
4158 pMac->scan.countryCodeCount++;
4159 }
4160
4161 return;
4162}
4163
4164tANI_BOOLEAN csrElectedCountryInfo(tpAniSirGlobal pMac)
4165{
4166 tANI_BOOLEAN fRet = FALSE;
4167 tANI_U8 maxVotes = 0;
4168 tANI_U8 i, j=0;
4169
4170 if (!pMac->scan.countryCodeCount)
4171 {
Agrawal Ashishbd3a5932016-04-12 16:22:39 +05304172 VOS_TRACE( VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_WARN,
4173 "No AP with 11d Country code is present in scan list");
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05304174 return fRet;
4175 }
4176 maxVotes = pMac->scan.votes11d[0].votes;
4177 fRet = TRUE;
4178
4179 for(i = 1; i < pMac->scan.countryCodeCount; i++)
4180 {
4181 /* If we have a tie for max votes for 2 different country codes,
4182 * pick random.we can put some more intelligence - TBD
4183 */
4184 if (maxVotes < pMac->scan.votes11d[i].votes)
4185 {
4186 VOS_TRACE( VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
4187 " Votes for Country %c%c : %d\n",
4188 pMac->scan.votes11d[i].countryCode[0],
4189 pMac->scan.votes11d[i].countryCode[1],
4190 pMac->scan.votes11d[i].votes);
4191
4192 maxVotes = pMac->scan.votes11d[i].votes;
4193 j = i;
4194 fRet = TRUE;
4195 }
4196
4197 }
4198 if (fRet)
4199 {
Rajesh Babu Prathipati20cdffa2014-07-01 22:24:59 +05304200 vos_mem_copy(pMac->scan.countryCodeElected,
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05304201 pMac->scan.votes11d[j].countryCode, WNI_CFG_COUNTRY_CODE_LEN);
Rajesh Babu Prathipati20cdffa2014-07-01 22:24:59 +05304202 vos_mem_copy(pMac->scan.countryCode11d,
Agarwal Ashish852b2c32014-05-23 17:13:25 +05304203 pMac->scan.votes11d[j].countryCode, WNI_CFG_COUNTRY_CODE_LEN);
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05304204 VOS_TRACE( VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
4205 "Selected Country is %c%c With count %d\n",
4206 pMac->scan.votes11d[j].countryCode[0],
4207 pMac->scan.votes11d[j].countryCode[1],
4208 pMac->scan.votes11d[j].votes);
4209 }
4210 return fRet;
4211}
Jeff Johnson295189b2012-06-20 16:38:30 -07004212
4213eHalStatus csrSetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pCountry, tANI_BOOLEAN *pfRestartNeeded)
4214{
4215 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
4216 v_REGDOMAIN_t domainId;
4217
4218 if(pCountry)
4219 {
Kiet Lam6c583332013-10-14 05:37:09 +05304220 status = csrGetRegulatoryDomainForCountry(pMac, pCountry, &domainId, COUNTRY_USER);
Jeff Johnson295189b2012-06-20 16:38:30 -07004221 if(HAL_STATUS_SUCCESS(status))
4222 {
4223 status = csrSetRegulatoryDomain(pMac, domainId, pfRestartNeeded);
4224 if(HAL_STATUS_SUCCESS(status))
4225 {
4226 //We don't need to check the pMac->roam.configParam.fEnforceDefaultDomain flag here,
4227 //csrSetRegulatoryDomain will fail if the country doesn't fit our domain criteria.
Kiet Lam64c1b492013-07-12 13:56:44 +05304228 vos_mem_copy(pMac->scan.countryCodeCurrent, pCountry, WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07004229 if((pfRestartNeeded == NULL) || !(*pfRestartNeeded))
4230 {
4231 //Simply set it to cfg. If we need to restart, restart will apply it to the CFG
4232 csrSetCfgCountryCode(pMac, pCountry);
4233 }
4234 }
4235 }
4236 }
4237
4238 return (status);
4239}
4240
4241
4242
4243//caller allocated memory for pNumChn and pChnPowerInfo
4244//As input, *pNumChn has the size of the array of pChnPowerInfo
4245//Upon return, *pNumChn has the number of channels assigned.
4246void csrGetChannelPowerInfo( tpAniSirGlobal pMac, tDblLinkList *pList,
4247 tANI_U32 *pNumChn, tChannelListWithPower *pChnPowerInfo)
4248{
4249 tListElem *pEntry;
4250 tANI_U32 chnIdx = 0, idx;
4251 tCsrChannelPowerInfo *pChannelSet;
4252
4253 //Get 2.4Ghz first
4254 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
4255 while( pEntry && (chnIdx < *pNumChn) )
4256 {
4257 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
4258 if ( 1 != pChannelSet->interChannelOffset )
4259 {
4260 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
4261 {
4262 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
4263 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
4264 }
4265 }
4266 else
4267 {
4268 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
4269 {
4270 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + idx);
4271 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
4272 }
4273 }
4274
4275 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
4276 }
4277 *pNumChn = chnIdx;
4278
4279 return ;
4280}
4281
4282
4283
4284void csrApplyCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce )
4285{
4286 v_REGDOMAIN_t domainId;
4287 eHalStatus status = eHAL_STATUS_SUCCESS;
4288
4289 do
4290 {
4291 if( !csrIs11dSupported( pMac ) || 0 == pMac->scan.channelOf11dInfo) break;
4292 if( pMac->scan.fAmbiguous11dInfoFound )
4293 {
4294 // ambiguous info found
4295 //Restore te default domain as well
Kiet Lam6c583332013-10-14 05:37:09 +05304296 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
4297 pMac, pMac->scan.countryCodeCurrent,
4298 &domainId, COUNTRY_QUERY)))
Jeff Johnson295189b2012-06-20 16:38:30 -07004299 {
4300 pMac->scan.domainIdCurrent = domainId;
4301 }
4302 else
4303 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004304 smsLog(pMac, LOGE, FL(" failed to get domain from currentCountryCode %02X%02X"),
Jeff Johnson295189b2012-06-20 16:38:30 -07004305 pMac->scan.countryCodeCurrent[0], pMac->scan.countryCodeCurrent[1]);
4306 }
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004307 csrResetCountryInformation( pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE );
Jeff Johnson295189b2012-06-20 16:38:30 -07004308 break;
4309 }
4310 if ( pMac->scan.f11dInfoApplied && !fForce ) break;
Kiet Lam6c583332013-10-14 05:37:09 +05304311 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
4312 pMac, pMac->scan.countryCode11d,
4313 &domainId, COUNTRY_QUERY)))
Jeff Johnson295189b2012-06-20 16:38:30 -07004314 {
4315 //Check whether we need to enforce default domain
4316 if( ( !pMac->roam.configParam.fEnforceDefaultDomain ) ||
4317 (pMac->scan.domainIdCurrent == domainId) )
4318 {
4319
4320#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4321 {
4322 vos_log_802_11d_pkt_type *p11dLog;
4323 tChannelListWithPower chnPwrInfo[WNI_CFG_VALID_CHANNEL_LIST_LEN];
4324 tANI_U32 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN, nTmp;
4325
4326 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
4327 if(p11dLog)
4328 {
4329 p11dLog->eventId = WLAN_80211D_EVENT_COUNTRY_SET;
Kiet Lam64c1b492013-07-12 13:56:44 +05304330 vos_mem_copy(p11dLog->countryCode, pMac->scan.countryCode11d, 3);
Jeff Johnson295189b2012-06-20 16:38:30 -07004331 p11dLog->numChannel = pMac->scan.channels11d.numChannels;
4332 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
4333 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304334 vos_mem_copy(p11dLog->Channels,
4335 pMac->scan.channels11d.channelList,
4336 p11dLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07004337 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList24,
4338 &nChnInfo, chnPwrInfo);
4339 nTmp = nChnInfo;
4340 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN - nTmp;
4341 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList5G,
4342 &nChnInfo, &chnPwrInfo[nTmp]);
4343 for(nTmp = 0; nTmp < p11dLog->numChannel; nTmp++)
4344 {
4345 for(nChnInfo = 0; nChnInfo < WNI_CFG_VALID_CHANNEL_LIST_LEN; nChnInfo++)
4346 {
4347 if(p11dLog->Channels[nTmp] == chnPwrInfo[nChnInfo].chanId)
4348 {
4349 p11dLog->TxPwr[nTmp] = chnPwrInfo[nChnInfo].pwr;
4350 break;
4351 }
4352 }
4353 }
4354 }
4355 if(!pMac->roam.configParam.Is11dSupportEnabled)
4356 {
4357 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
4358 }
4359 else if(pMac->roam.configParam.fEnforceDefaultDomain)
4360 {
4361 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
4362 }
4363 else
4364 {
4365 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
4366 }
4367 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
4368 }
4369 }
4370#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4371 if(pMac->scan.domainIdCurrent != domainId)
4372 {
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05304373 smsLog(pMac, LOGW, FL("Domain Changed Old %s (%d), new %s"),
4374 voss_DomainIdtoString(pMac->scan.domainIdCurrent),
4375 pMac->scan.domainIdCurrent,
4376 voss_DomainIdtoString(domainId));
Abhishek Singha306a442013-11-07 18:39:01 +05304377 status = WDA_SetRegDomain(pMac, domainId, eSIR_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07004378 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004379 if (status != eHAL_STATUS_SUCCESS)
4380 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004381 smsLog( pMac, LOGE, FL(" fail to set regId %d"), domainId );
Jeff Johnson295189b2012-06-20 16:38:30 -07004382 }
4383 pMac->scan.domainIdCurrent = domainId;
Kiet Lam6c583332013-10-14 05:37:09 +05304384#ifndef CONFIG_ENABLE_LINUX_REG
Kiet Lambb14e952013-11-19 14:58:29 +05304385 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.base20MHzChannels,
4386 pMac->scan.countryCodeCurrent, eANI_BOOLEAN_TRUE );
Kiet Lam6c583332013-10-14 05:37:09 +05304387#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004388 // switch to active scans using this new channel list
4389 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
4390 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_TRUE;
4391 pMac->scan.f11dInfoReset = eANI_BOOLEAN_FALSE;
4392 }
4393 }
4394
4395 } while( 0 );
4396
4397 return;
4398}
4399
4400
4401
4402tANI_BOOLEAN csrSave11dCountryString( tpAniSirGlobal pMac, tANI_U8 *pCountryCode,
4403 tANI_BOOLEAN fForce)
4404{
4405 tANI_BOOLEAN fCountryStringChanged = FALSE, fUnknownCountryCode = FALSE;
4406 tANI_U32 i;
Kiet Lam6c583332013-10-14 05:37:09 +05304407 v_REGDOMAIN_t regd;
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004408 tANI_BOOLEAN fCountryNotPresentInDriver = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004409
4410 // convert to UPPER here so we are assured the strings are always in upper case.
4411 for( i = 0; i < 3; i++ )
4412 {
4413 pCountryCode[ i ] = (tANI_U8)csrToUpper( pCountryCode[ i ] );
4414 }
4415
4416 // Some of the 'old' Cisco 350 series AP's advertise NA as the country code (for North America ??).
4417 // NA is not a valid country code or domain so let's allow this by changing it to the proper
4418 // country code (which is US). We've also seen some NETGEAR AP's that have "XX " as the country code
4419 // with valid 2.4 GHz US channel information. If we cannot find the country code advertised in the
4420 // 11d information element, let's default to US.
Kiet Lam6c583332013-10-14 05:37:09 +05304421 if ( !HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(pMac,
4422 pCountryCode,
4423 &regd,
4424 COUNTRY_QUERY) ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07004425 {
4426 // Check the enforcement first
4427 if( pMac->roam.configParam.fEnforceDefaultDomain || pMac->roam.configParam.fEnforceCountryCodeMatch )
4428 {
4429 fUnknownCountryCode = TRUE;
4430 }
4431 else
4432 {
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004433 fCountryNotPresentInDriver = TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004434 }
4435 }
Tushnim Bhattacharyyac3c1e8e2013-10-29 17:27:43 -07004436 //right now, even if we don't find the CC in driver we set to world. Making
4437 //sure countryCode11d doesn't get updated with the invalid CC, instead
4438 //reflect the world CC
4439 else if (REGDOMAIN_WORLD == regd)
4440 {
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004441 fCountryNotPresentInDriver = TRUE;
Tushnim Bhattacharyyac3c1e8e2013-10-29 17:27:43 -07004442 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004443
4444 // We've seen some of the AP's improperly put a 0 for the third character of the country code.
4445 // spec says valid charcters are 'O' (for outdoor), 'I' for Indoor, or ' ' (space; for either).
4446 // if we see a 0 in this third character, let's change it to a ' '.
4447 if ( 0 == pCountryCode[ 2 ] )
4448 {
4449 pCountryCode[ 2 ] = ' ';
4450 }
4451
4452 if( !fUnknownCountryCode )
4453 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304454 fCountryStringChanged = (!vos_mem_compare(pMac->scan.countryCode11d, pCountryCode, 2));
Jeff Johnson295189b2012-06-20 16:38:30 -07004455
4456
4457 if(( 0 == pMac->scan.countryCode11d[ 0 ] && 0 == pMac->scan.countryCode11d[ 1 ] )
4458 || (fForce))
4459 {
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004460 if (!fCountryNotPresentInDriver)
4461 {
4462 // this is the first .11d information
4463 vos_mem_copy(pMac->scan.countryCode11d, pCountryCode,
Kiet Lam64c1b492013-07-12 13:56:44 +05304464 sizeof( pMac->scan.countryCode11d ));
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004465
4466 }
4467 else
4468 {
4469 pMac->scan.countryCode11d[0] = '0';
4470 pMac->scan.countryCode11d[1] = '0';
4471 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004472 }
4473 }
4474
4475 return( fCountryStringChanged );
4476}
4477
4478
4479void csrSaveChannelPowerForBand( tpAniSirGlobal pMac, tANI_BOOLEAN fPopulate5GBand )
4480{
4481 tANI_U32 Index, count=0;
4482 tSirMacChanInfo *pChanInfo;
4483 tSirMacChanInfo *pChanInfoStart;
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08004484 tANI_S32 maxChannelIndex;
4485
4486 maxChannelIndex = ( pMac->scan.base20MHzChannels.numChannels < WNI_CFG_VALID_CHANNEL_LIST_LEN ) ?
4487 pMac->scan.base20MHzChannels.numChannels : WNI_CFG_VALID_CHANNEL_LIST_LEN ;
Jeff Johnson295189b2012-06-20 16:38:30 -07004488
Kiet Lam64c1b492013-07-12 13:56:44 +05304489 pChanInfo = vos_mem_malloc(sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN);
4490 if ( NULL != pChanInfo )
Jeff Johnson295189b2012-06-20 16:38:30 -07004491 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304492 vos_mem_set(pChanInfo, sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004493 pChanInfoStart = pChanInfo;
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08004494 for (Index=0; Index < maxChannelIndex; Index++)
Jeff Johnson295189b2012-06-20 16:38:30 -07004495 {
4496 if ((fPopulate5GBand && (CSR_IS_CHANNEL_5GHZ(pMac->scan.defaultPowerTable[Index].chanId))) ||
4497 (!fPopulate5GBand && (CSR_IS_CHANNEL_24GHZ(pMac->scan.defaultPowerTable[Index].chanId))) )
4498 {
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08004499 if(count >= WNI_CFG_VALID_CHANNEL_LIST_LEN)
4500 {
4501 smsLog( pMac, LOGW, FL(" csrSaveChannelPowerForBand, count exceeded, count = %d"), count);
4502 break;
4503 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004504 pChanInfo->firstChanNum = pMac->scan.defaultPowerTable[Index].chanId;
4505 pChanInfo->numChannels = 1;
4506 pChanInfo->maxTxPower = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
4507 pChanInfo++;
4508 count++;
4509 }
4510 }
4511 if(count)
4512 {
4513 csrSaveToChannelPower2G_5G( pMac, count * sizeof(tSirMacChanInfo), pChanInfoStart );
4514 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304515 vos_mem_free(pChanInfoStart);
Jeff Johnson295189b2012-06-20 16:38:30 -07004516 }
4517}
4518
4519
4520void csrSetOppositeBandChannelInfo( tpAniSirGlobal pMac )
4521{
4522 tANI_BOOLEAN fPopulate5GBand = FALSE;
4523
4524 do
4525 {
4526 // if this is not a dual band product, then we don't need to set the opposite
4527 // band info. We only work in one band so no need to look in the other band.
4528 if ( !CSR_IS_OPEARTING_DUAL_BAND( pMac ) ) break;
4529 // if we found channel info on the 5.0 band and...
4530 if ( CSR_IS_CHANNEL_5GHZ( pMac->scan.channelOf11dInfo ) )
4531 {
4532 // and the 2.4 band is empty, then populate the 2.4 channel info
Kiet Lam8d985a02013-10-11 03:39:41 +05304533 if ( !csrLLIsListEmpty( &pMac->scan.channelPowerInfoList24, LL_ACCESS_LOCK ) ) break;
Jeff Johnson295189b2012-06-20 16:38:30 -07004534 fPopulate5GBand = FALSE;
4535 }
4536 else
4537 {
4538 // else, we found channel info in the 2.4 GHz band. If the 5.0 band is empty
4539 // set the 5.0 band info from the 2.4 country code.
Kiet Lam8d985a02013-10-11 03:39:41 +05304540 if ( !csrLLIsListEmpty( &pMac->scan.channelPowerInfoList5G, LL_ACCESS_LOCK ) ) break;
Jeff Johnson295189b2012-06-20 16:38:30 -07004541 fPopulate5GBand = TRUE;
4542 }
4543 csrSaveChannelPowerForBand( pMac, fPopulate5GBand );
4544
4545 } while( 0 );
4546}
4547
4548
4549tANI_BOOLEAN csrIsSupportedChannel(tpAniSirGlobal pMac, tANI_U8 channelId)
4550{
4551 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
4552 tANI_U32 i;
4553
4554 //Make sure it is a channel that is in our supported list.
4555 for ( i = 0; i < pMac->scan.baseChannels.numChannels; i++ )
4556 {
4557 if ( channelId == pMac->scan.baseChannels.channelList[i] )
4558 {
4559 fRet = eANI_BOOLEAN_TRUE;
4560 break;
4561 }
4562 }
4563
4564 //If it is configured to limit a set of the channels
4565 if( fRet && pMac->roam.configParam.fEnforce11dChannels )
4566 {
4567 fRet = eANI_BOOLEAN_FALSE;
4568 for ( i = 0; i < pMac->scan.base20MHzChannels.numChannels; i++ )
4569 {
4570 if ( channelId == pMac->scan.base20MHzChannels.channelList[i] )
4571 {
4572 fRet = eANI_BOOLEAN_TRUE;
4573 break;
4574 }
4575 }
4576 }
4577
4578 return (fRet);
4579}
4580
4581
4582
4583//bSize specify the buffer size of pChannelList
4584tANI_U8 csrGetChannelListFromChannelSet( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 bSize, tCsrChannelPowerInfo *pChannelSet )
4585{
4586 tANI_U8 i, j = 0, chnId;
4587
4588 bSize = CSR_MIN(bSize, pChannelSet->numChannels);
4589 for( i = 0; i < bSize; i++ )
4590 {
4591 chnId = (tANI_U8)(pChannelSet->firstChannel + ( i * pChannelSet->interChannelOffset ));
4592 if ( csrIsSupportedChannel( pMac, chnId ) )
4593 {
4594 pChannelList[j++] = chnId;
4595 }
4596 }
4597
4598 return (j);
4599}
4600
4601
4602
4603//bSize -- specify the buffer size of pChannelList
4604void csrConstructCurrentValidChannelList( tpAniSirGlobal pMac, tDblLinkList *pChannelSetList,
4605 tANI_U8 *pChannelList, tANI_U8 bSize, tANI_U8 *pNumChannels )
4606{
4607 tListElem *pEntry;
4608 tCsrChannelPowerInfo *pChannelSet;
4609 tANI_U8 numChannels;
4610 tANI_U8 *pChannels;
4611
4612 if( pChannelSetList && pChannelList && pNumChannels )
4613 {
4614 pChannels = pChannelList;
4615 *pNumChannels = 0;
4616 pEntry = csrLLPeekHead( pChannelSetList, LL_ACCESS_LOCK );
4617 while( pEntry )
4618 {
4619 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
4620 numChannels = csrGetChannelListFromChannelSet( pMac, pChannels, bSize, pChannelSet );
4621 pChannels += numChannels;
4622 *pNumChannels += numChannels;
4623 pEntry = csrLLNext( pChannelSetList, pEntry, LL_ACCESS_LOCK );
4624 }
4625 }
4626}
4627
4628
4629/*
4630 * 802.11D only: Gather 11d IE via beacon or Probe response and store them in pAdapter->channels11d
4631*/
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304632tANI_BOOLEAN csrLearnCountryInformation( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc,
4633 tDot11fBeaconIEs *pIes, tANI_BOOLEAN fForce)
Jeff Johnson295189b2012-06-20 16:38:30 -07004634{
Agarwal Ashish60a37ee2014-05-28 17:20:20 +05304635 eHalStatus status;
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304636 tANI_U8 *pCountryCodeSelected;
Jeff Johnson295189b2012-06-20 16:38:30 -07004637 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
4638 v_REGDOMAIN_t domainId;
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304639 tDot11fBeaconIEs *pIesLocal = pIes;
4640 tANI_BOOLEAN useVoting = eANI_BOOLEAN_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004641
Jeff Johnson295189b2012-06-20 16:38:30 -07004642 if (VOS_STA_SAP_MODE == vos_get_conparam ())
4643 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07004644
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304645 if ((NULL == pSirBssDesc) && (NULL == pIes))
4646 useVoting = eANI_BOOLEAN_TRUE;
4647
Jeff Johnson295189b2012-06-20 16:38:30 -07004648 do
4649 {
4650 // check if .11d support is enabled
4651 if( !csrIs11dSupported( pMac ) ) break;
Agarwal Ashish60a37ee2014-05-28 17:20:20 +05304652
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304653 if (eANI_BOOLEAN_FALSE == useVoting)
4654 {
4655 if( !pIesLocal &&
4656 (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
4657 pSirBssDesc, &pIesLocal))))
4658 {
4659 break;
4660 }
4661 // check if country information element is present
4662 if(!pIesLocal->Country.present)
4663 {
4664 //No country info
4665 break;
4666 }
4667
4668 if( HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry
4669 (pMac, pIesLocal->Country.country, &domainId,
4670 COUNTRY_QUERY)) &&
4671 ( domainId == REGDOMAIN_WORLD))
4672 {
4673 break;
4674 }
4675 } //useVoting == eANI_BOOLEAN_FALSE
4676
4677 if (eANI_BOOLEAN_FALSE == useVoting)
4678 pCountryCodeSelected = pIesLocal->Country.country;
4679 else
4680 pCountryCodeSelected = pMac->scan.countryCodeElected;
4681
Kiet Lam8d985a02013-10-11 03:39:41 +05304682 status = csrGetRegulatoryDomainForCountry(pMac,
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304683 pCountryCodeSelected, &domainId, COUNTRY_IE);
Kiet Lam8d985a02013-10-11 03:39:41 +05304684 if ( status != eHAL_STATUS_SUCCESS )
4685 {
4686 smsLog( pMac, LOGE, FL(" fail to get regId %d"), domainId );
4687 fRet = eANI_BOOLEAN_FALSE;
4688 break;
4689 }
Agarwal Ashish7693f2d2014-07-18 18:03:58 +05304690
4691 /* updating 11d Country Code with Country code selected. */
4692
4693 vos_mem_copy(pMac->scan.countryCode11d,
4694 pCountryCodeSelected,
4695 WNI_CFG_COUNTRY_CODE_LEN);
4696
Agarwal Ashish60a37ee2014-05-28 17:20:20 +05304697#ifndef CONFIG_ENABLE_LINUX_REG
Venkata Prathyusha Kuntupalli316247e2013-03-15 17:45:25 -07004698 // Checking for Domain Id change
4699 if ( domainId != pMac->scan.domainIdCurrent )
4700 {
Kiet Lam8d985a02013-10-11 03:39:41 +05304701 vos_mem_copy(pMac->scan.countryCode11d,
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304702 pCountryCodeSelected,
Kiet Lam8d985a02013-10-11 03:39:41 +05304703 sizeof( pMac->scan.countryCode11d ) );
4704 /* Set Current Country code and Current Regulatory domain */
4705 status = csrSetRegulatoryDomain(pMac, domainId, NULL);
4706 if (eHAL_STATUS_SUCCESS != status)
4707 {
4708 smsLog(pMac, LOGE, "Set Reg Domain Fail %d", status);
4709 fRet = eANI_BOOLEAN_FALSE;
4710 return fRet;
4711 }
4712 //csrSetRegulatoryDomain will fail if the country doesn't fit our domain criteria.
4713 vos_mem_copy(pMac->scan.countryCodeCurrent,
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304714 pCountryCodeSelected, WNI_CFG_COUNTRY_CODE_LEN);
Kiet Lam8d985a02013-10-11 03:39:41 +05304715 //Simply set it to cfg.
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304716 csrSetCfgCountryCode(pMac, pCountryCodeSelected);
Kiet Lam8d985a02013-10-11 03:39:41 +05304717
4718 /* overwrite the defualt country code */
4719 vos_mem_copy(pMac->scan.countryCodeDefault,
4720 pMac->scan.countryCodeCurrent,
4721 WNI_CFG_COUNTRY_CODE_LEN);
4722 /* Set Current RegDomain */
Abhishek Singha306a442013-11-07 18:39:01 +05304723 status = WDA_SetRegDomain(pMac, domainId, eSIR_TRUE);
Kiet Lam8d985a02013-10-11 03:39:41 +05304724 if ( status != eHAL_STATUS_SUCCESS )
4725 {
4726 smsLog( pMac, LOGE, FL(" fail to Set regId %d"), domainId );
4727 fRet = eANI_BOOLEAN_FALSE;
4728 return fRet;
4729 }
4730 /* set to default domain ID */
Madan Mohan Koyyalamudi0e5922d2013-09-10 15:45:24 +05304731 pMac->scan.domainIdCurrent = domainId;
Kiet Lam8d985a02013-10-11 03:39:41 +05304732 /* get the channels based on new cc */
4733 status = csrInitGetChannels( pMac );
Jeff Johnson295189b2012-06-20 16:38:30 -07004734
Kiet Lam8d985a02013-10-11 03:39:41 +05304735 if ( status != eHAL_STATUS_SUCCESS )
4736 {
4737 smsLog( pMac, LOGE, FL(" fail to get Channels "));
4738 fRet = eANI_BOOLEAN_FALSE;
4739 return fRet;
4740 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004741
Kiet Lam8d985a02013-10-11 03:39:41 +05304742 /* reset info based on new cc, and we are done */
4743 csrResetCountryInformation(pMac, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
Agarwal Ashishfaef6692014-01-29 19:40:30 +05304744 /* Regulatory Domain Changed, Purge Only scan result
4745 * which does not have channel number belong to 11d
4746 * channel list
4747 */
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05304748 csrScanFilterResults(pMac);
Kiet Lam8d985a02013-10-11 03:39:41 +05304749 }
Kiet Lam6c583332013-10-14 05:37:09 +05304750#endif
4751 fRet = eANI_BOOLEAN_TRUE;
4752
Jeff Johnson295189b2012-06-20 16:38:30 -07004753 } while( 0 );
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304754
4755 if( !pIes && pIesLocal )
4756 {
4757 //locally allocated
4758 vos_mem_free(pIesLocal);
4759 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004760
4761 return( fRet );
4762}
4763
4764
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004765static void csrSaveScanResults( tpAniSirGlobal pMac, tANI_U8 reason )
Jeff Johnson295189b2012-06-20 16:38:30 -07004766{
4767 // initialize this to FALSE. profMoveInterimScanResultsToMainList() routine
4768 // will set this to the channel where an .11d beacon is seen
4769 pMac->scan.channelOf11dInfo = 0;
4770 // if we get any ambiguous .11d information then this will be set to TRUE
4771 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
4772 //Tush
4773 // if we get any ambiguous .11d information, then this will be set to TRUE
4774 // only if the applied 11d info could be found in one of the scan results
4775 pMac->scan.fCurrent11dInfoMatch = eANI_BOOLEAN_FALSE;
4776 // move the scan results from interim list to the main scan list
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004777 csrMoveTempScanResultsToMainList( pMac, reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07004778}
4779
4780
4781void csrReinitScanCmd(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4782{
4783 switch (pCommand->u.scanCmd.reason)
4784 {
4785 case eCsrScanSetBGScanParam:
4786 case eCsrScanAbortBgScan:
4787 if(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList)
4788 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304789 vos_mem_free(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList);
Jeff Johnson295189b2012-06-20 16:38:30 -07004790 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
4791 }
4792 break;
4793 case eCsrScanBGScanAbort:
4794 case eCsrScanBGScanEnable:
4795 case eCsrScanGetScanChnInfo:
4796 break;
4797 case eCsrScanAbortNormalScan:
4798 default:
4799 csrScanFreeRequest(pMac, &pCommand->u.scanCmd.u.scanRequest);
4800 break;
4801 }
4802 if(pCommand->u.scanCmd.pToRoamProfile)
4803 {
4804 csrReleaseProfile(pMac, pCommand->u.scanCmd.pToRoamProfile);
Kiet Lam64c1b492013-07-12 13:56:44 +05304805 vos_mem_free(pCommand->u.scanCmd.pToRoamProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07004806 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304807 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004808}
4809
4810
4811tANI_BOOLEAN csrGetRemainingChannelsFor11dScan( tpAniSirGlobal pMac, tANI_U8 *pChannels, tANI_U8 *pcChannels )
4812{
4813 tANI_U32 index11dChannels, index;
4814 tANI_U32 indexCurrentChannels;
4815 tANI_BOOLEAN fChannelAlreadyScanned;
4816 tANI_U32 len = sizeof(pMac->roam.validChannelList);
4817
4818 *pcChannels = 0;
4819 if ( CSR_IS_11D_INFO_FOUND(pMac) && csrRoamIsChannelValid(pMac, pMac->scan.channelOf11dInfo) )
4820 {
4821 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
4822 {
4823 //Find the channel index where we found the 11d info
4824 for(index = 0; index < len; index++)
4825 {
4826 if(pMac->scan.channelOf11dInfo == pMac->roam.validChannelList[index])
4827 break;
4828 }
4829 //check whether we found the channel index
4830 if(index < len)
4831 {
4832 // Now, look through the 11d channel list and create a list of all channels in the 11d list that are
4833 // NOT in the current channel list. This gives us a list of the new channels that have not been
4834 // scanned. We'll scan this new list so we have a complete set of scan results on all of the domain channels
4835 // initially.
4836 for ( index11dChannels = 0; index11dChannels < pMac->scan.channels11d.numChannels; index11dChannels++ )
4837 {
4838 fChannelAlreadyScanned = eANI_BOOLEAN_FALSE;
4839
4840 for( indexCurrentChannels = 0; indexCurrentChannels < index; indexCurrentChannels++ )
4841 {
4842 if ( pMac->roam.validChannelList[ indexCurrentChannels ] == pMac->scan.channels11d.channelList[ index11dChannels ] )
4843 {
4844 fChannelAlreadyScanned = eANI_BOOLEAN_TRUE;
4845 break;
4846 }
4847 }
4848
4849 if ( !fChannelAlreadyScanned )
4850 {
4851 pChannels[ *pcChannels ] = pMac->scan.channels11d.channelList[ index11dChannels ];
4852 ( *pcChannels )++;
4853 }
4854 }
4855 }
4856 }//GetCFG
4857 }
4858 return( *pcChannels );
4859}
4860
4861
4862eCsrScanCompleteNextCommand csrScanGetNextCommandState( tpAniSirGlobal pMac, tSmeCmd *pCommand, tANI_BOOLEAN fSuccess )
4863{
4864 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
4865
4866 switch( pCommand->u.scanCmd.reason )
4867 {
4868 case eCsrScan11d1:
4869 NextCommand = (fSuccess) ? eCsrNext11dScan1Success : eCsrNext11dScan1Failure;
4870 break;
4871 case eCsrScan11d2:
4872 NextCommand = (fSuccess) ? eCsrNext11dScan2Success : eCsrNext11dScan2Failure;
4873 break;
4874 case eCsrScan11dDone:
4875 NextCommand = eCsrNext11dScanComplete;
4876 break;
4877 case eCsrScanLostLink1:
4878 NextCommand = (fSuccess) ? eCsrNextLostLinkScan1Success : eCsrNextLostLinkScan1Failed;
4879 break;
4880 case eCsrScanLostLink2:
4881 NextCommand = (fSuccess) ? eCsrNextLostLinkScan2Success : eCsrNextLostLinkScan2Failed;
4882 break;
4883 case eCsrScanLostLink3:
4884 NextCommand = (fSuccess) ? eCsrNextLostLinkScan3Success : eCsrNextLostLinkScan3Failed;
4885 break;
4886 case eCsrScanForSsid:
4887 NextCommand = (fSuccess) ? eCsrNexteScanForSsidSuccess : eCsrNexteScanForSsidFailure;
4888 break;
4889 case eCsrScanForCapsChange:
4890 NextCommand = eCsrNextCapChangeScanComplete; //don't care success or not
4891 break;
4892 case eCsrScanIdleScan:
4893 NextCommand = eCsrNextIdleScanComplete;
4894 break;
4895 default:
4896 NextCommand = eCsrNextScanNothing;
4897 break;
4898 }
4899 return( NextCommand );
4900}
4901
4902
4903//Return whether the pCommand is finished.
4904tANI_BOOLEAN csrHandleScan11d1Failure(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4905{
4906 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
4907
4908 //Apply back the default setting and passively scan one more time.
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004909 csrResetCountryInformation(pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07004910 pCommand->u.scanCmd.reason = eCsrScan11d2;
4911 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
4912 {
4913 fRet = eANI_BOOLEAN_FALSE;
4914 }
4915
4916 return (fRet);
4917}
4918
4919
4920tANI_BOOLEAN csrHandleScan11dSuccess(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4921{
4922 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
4923 tANI_U8 *pChannels;
4924 tANI_U8 cChannels;
4925
Kiet Lam64c1b492013-07-12 13:56:44 +05304926 pChannels = vos_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
4927 if ( NULL != pChannels )
Jeff Johnson295189b2012-06-20 16:38:30 -07004928 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304929 vos_mem_set(pChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004930 if ( csrGetRemainingChannelsFor11dScan( pMac, pChannels, &cChannels ) )
4931 {
4932 pCommand->u.scanCmd.reason = eCsrScan11dDone;
4933 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
4934 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304935 vos_mem_free(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -07004936 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004937 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304938 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(cChannels);
4939 if ( NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07004940 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304941 vos_mem_copy(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
4942 pChannels, cChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07004943 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = cChannels;
4944 pCommand->u.scanCmd.u.scanRequest.requestType = eCSR_SCAN_REQUEST_FULL_SCAN;
4945 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
4946 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
4947 {
4948 //Reuse the same command buffer
4949 fRet = eANI_BOOLEAN_FALSE;
4950 }
4951 }
4952 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304953 vos_mem_free(pChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07004954 }
4955
4956 return (fRet);
4957}
4958
4959//Return whether the command should be removed
4960tANI_BOOLEAN csrScanComplete( tpAniSirGlobal pMac, tSirSmeScanRsp *pScanRsp )
4961{
4962 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
4963 tListElem *pEntry;
4964 tSmeCmd *pCommand;
4965 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
4966 tANI_BOOLEAN fSuccess;
4967
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05304968 if (pMac->fScanOffload)
4969 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
4970 else
4971 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07004972
4973 if ( pEntry )
4974 {
4975 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
4976
4977 // If the head of the queue is Active and it is a SCAN command, remove
4978 // and put this on the Free queue.
4979 if ( eSmeCommandScan == pCommand->command )
4980 {
4981 tANI_U32 sessionId = pCommand->sessionId;
4982
4983 if(eSIR_SME_SUCCESS != pScanRsp->statusCode)
4984 {
4985 fSuccess = eANI_BOOLEAN_FALSE;
4986 }
4987 else
4988 {
4989 //pMac->scan.tempScanResults is not empty meaning the scan found something
4990 //This check only valid here because csrSaveScanresults is not yet called
4991 fSuccess = (!csrLLIsListEmpty(&pMac->scan.tempScanResults, LL_ACCESS_LOCK));
4992 }
Ratheesh S Pece1f832015-07-25 15:50:25 +05304993 if (pCommand->u.scanCmd.abortScanIndication &
4994 eCSR_SCAN_ABORT_DUE_TO_BAND_CHANGE)
Srinivas, Dasari187ca4e2014-02-07 12:40:09 +05304995 {
4996 /*
4997 * Scan aborted due to band change
4998 * The scan results need to be flushed
4999 */
5000 if (pCommand->u.scanCmd.callback
5001 != pMac->scan.callback11dScanDone)
5002 {
5003 smsLog(pMac, LOG1, FL("Filtering the scan results as the "
5004 "results may belong to wrong band"));
5005 csrScanFilterResults(pMac);
5006 }
5007 else
5008 {
5009 smsLog(pMac, LOG1, FL("11d_scan_done will flush the scan"
5010 " results"));
5011 }
Srinivas, Dasari187ca4e2014-02-07 12:40:09 +05305012 }
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005013 csrSaveScanResults(pMac, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07005014
Agrawal Ashishdf752672015-12-09 17:51:53 +05305015 /* filter scan result based on valid channel list number */
5016 if (pMac->scan.fcc_constraint)
5017 {
5018 smsLog(pMac, LOG1, FL("Clear BSS from invalid channels"));
5019 csrScanFilterResults(pMac);
5020 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005021#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5022 {
5023 vos_log_scan_pkt_type *pScanLog = NULL;
5024 tScanResultHandle hScanResult;
5025 tCsrScanResultInfo *pScanResult;
5026 tDot11fBeaconIEs *pIes;
5027 int n = 0, c = 0;
5028
5029 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
5030 if(pScanLog)
5031 {
5032 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
5033 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
5034 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
5035 {
5036 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_RSP;
5037 }
5038 else
5039 {
5040 if( eSIR_PASSIVE_SCAN != pMac->scan.curScanType )
5041 {
5042 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_RSP;
5043 }
5044 else
5045 {
5046 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_RSP;
5047 }
5048 }
5049 if(eSIR_SME_SUCCESS == pScanRsp->statusCode)
5050 {
5051 if(HAL_STATUS_SUCCESS(csrScanGetResult(pMac, NULL, &hScanResult)))
5052 {
5053 while(((pScanResult = csrScanResultGetNext(pMac, hScanResult)) != NULL))
5054 {
5055 if( n < VOS_LOG_MAX_NUM_BSSID )
5056 {
5057 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pScanResult->BssDescriptor, &pIes)))
5058 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005059 smsLog(pMac, LOGE, FL(" fail to parse IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07005060 break;
5061 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305062 vos_mem_copy(pScanLog->bssid[n],
5063 pScanResult->BssDescriptor.bssId, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07005064 if(pIes && pIes->SSID.present && VOS_LOG_MAX_SSID_SIZE >= pIes->SSID.num_ssid)
5065 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305066 vos_mem_copy(pScanLog->ssid[n],
5067 pIes->SSID.ssid, pIes->SSID.num_ssid);
Jeff Johnson295189b2012-06-20 16:38:30 -07005068 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305069 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07005070 n++;
5071 }
5072 c++;
5073 }
5074 pScanLog->numSsid = (v_U8_t)n;
5075 pScanLog->totalSsid = (v_U8_t)c;
5076 csrScanResultPurge(pMac, hScanResult);
5077 }
5078 }
5079 else
5080 {
5081 pScanLog->status = WLAN_SCAN_STATUS_FAILURE;
5082 }
5083 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
5084 }
5085 }
5086#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5087
5088 NextCommand = csrScanGetNextCommandState(pMac, pCommand, fSuccess);
5089 //We reuse the command here instead reissue a new command
5090 switch(NextCommand)
5091 {
5092 case eCsrNext11dScan1Success:
5093 case eCsrNext11dScan2Success:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005094 smsLog( pMac, LOG2, FL("11dScan1/3 produced results. Reissue Active scan..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07005095 // if we found country information, no need to continue scanning further, bail out
5096 fRemoveCommand = eANI_BOOLEAN_TRUE;
5097 NextCommand = eCsrNext11dScanComplete;
5098 break;
5099 case eCsrNext11dScan1Failure:
5100 //We are not done yet. 11d scan fail once. We will try to reset anything and do it over again
5101 //The only meaningful thing for this retry is that we cannot find 11d information after a reset so
5102 //we clear the "old" 11d info and give it once more chance
5103 fRemoveCommand = csrHandleScan11d1Failure(pMac, pCommand);
5104 if(fRemoveCommand)
5105 {
5106 NextCommand = eCsrNext11dScanComplete;
5107 }
5108 break;
5109 case eCsrNextLostLinkScan1Success:
5110 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink1)))
5111 {
5112 csrScanHandleFailedLostlink1(pMac, sessionId);
5113 }
5114 break;
5115 case eCsrNextLostLinkScan2Success:
5116 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink2)))
5117 {
5118 csrScanHandleFailedLostlink2(pMac, sessionId);
5119 }
5120 break;
5121 case eCsrNextLostLinkScan3Success:
5122 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink3)))
5123 {
5124 csrScanHandleFailedLostlink3(pMac, sessionId);
5125 }
5126 break;
5127 case eCsrNextLostLinkScan1Failed:
5128 csrScanHandleFailedLostlink1(pMac, sessionId);
5129 break;
5130 case eCsrNextLostLinkScan2Failed:
5131 csrScanHandleFailedLostlink2(pMac, sessionId);
5132 break;
5133 case eCsrNextLostLinkScan3Failed:
5134 csrScanHandleFailedLostlink3(pMac, sessionId);
5135 break;
5136 case eCsrNexteScanForSsidSuccess:
5137 csrScanHandleSearchForSSID(pMac, pCommand);
5138 break;
5139 case eCsrNexteScanForSsidFailure:
5140 csrScanHandleSearchForSSIDFailure(pMac, pCommand);
5141 break;
5142 case eCsrNextIdleScanComplete:
5143 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
5144 break;
5145 case eCsrNextCapChangeScanComplete:
5146 csrScanHandleCapChangeScanComplete(pMac, sessionId);
5147 break;
5148 default:
5149
5150 break;
5151 }
5152 }
5153 else
5154 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005155 smsLog( pMac, LOGW, FL("Scan Completion called but SCAN command is not ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07005156 fRemoveCommand = eANI_BOOLEAN_FALSE;
5157 }
5158 }
5159 else
5160 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005161 smsLog( pMac, LOGW, FL("Scan Completion called but NO commands are ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07005162 fRemoveCommand = eANI_BOOLEAN_FALSE;
5163 }
5164
5165 return( fRemoveCommand );
5166}
5167
5168
5169
5170static void csrScanRemoveDupBssDescriptionFromInterimList( tpAniSirGlobal pMac,
5171 tSirBssDescription *pSirBssDescr,
5172 tDot11fBeaconIEs *pIes)
5173{
5174 tListElem *pEntry;
5175 tCsrScanResult *pCsrBssDescription;
5176
5177 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
5178 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
5179 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
5180 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
5181 while( pEntry )
5182 {
5183 pCsrBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
5184
5185 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
5186 // matches
5187
5188 if ( csrIsDuplicateBssDescription( pMac, &pCsrBssDescription->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07005189 pSirBssDescr, pIes, FALSE ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07005190 {
5191 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
5192 ((tANI_S32)pCsrBssDescription->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
5193
5194 // Remove the 'old' entry from the list....
5195 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK ) )
5196 {
5197 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pCsrBssDescription->Result.BssDescriptor);
5198 // we need to free the memory associated with this node
5199 csrFreeScanResultEntry( pMac, pCsrBssDescription );
5200 }
5201
5202 // If we found a match, we can stop looking through the list.
5203 break;
5204 }
5205
5206 pEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK );
5207 }
5208}
5209
5210
5211
5212//Caller allocated memory pfNewBssForConn to return whether new candidate for
5213//current connection is found. Cannot be NULL
5214tCsrScanResult *csrScanSaveBssDescriptionToInterimList( tpAniSirGlobal pMac,
5215 tSirBssDescription *pBSSDescription,
5216 tDot11fBeaconIEs *pIes)
5217{
5218 tCsrScanResult *pCsrBssDescription = NULL;
5219 tANI_U32 cbBSSDesc;
5220 tANI_U32 cbAllocated;
Jeff Johnson295189b2012-06-20 16:38:30 -07005221
5222 // figure out how big the BSS description is (the BSSDesc->length does NOT
5223 // include the size of the length field itself).
5224 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
5225
5226 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
5227
Kiet Lam64c1b492013-07-12 13:56:44 +05305228 pCsrBssDescription = vos_mem_malloc(cbAllocated);
5229 if ( NULL != pCsrBssDescription )
Jeff Johnson295189b2012-06-20 16:38:30 -07005230 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305231 vos_mem_set(pCsrBssDescription, cbAllocated, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005232 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Kiet Lam64c1b492013-07-12 13:56:44 +05305233 vos_mem_copy(&pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc );
Jeff Johnson295189b2012-06-20 16:38:30 -07005234 //Save SSID separately for later use
5235 if( pIes->SSID.present && !csrIsNULLSSID(pIes->SSID.ssid, pIes->SSID.num_ssid) )
5236 {
5237 //SSID not hidden
Madan Mohan Koyyalamudi4e31b132012-11-02 13:13:52 -07005238 tANI_U32 len = pIes->SSID.num_ssid;
Jeff Johnson295189b2012-06-20 16:38:30 -07005239 if (len > SIR_MAC_MAX_SSID_LENGTH)
5240 {
5241 // truncate to fit in our struct
5242 len = SIR_MAC_MAX_SSID_LENGTH;
5243 }
5244 pCsrBssDescription->Result.ssId.length = len;
5245 pCsrBssDescription->Result.timer = vos_timer_get_system_time();
Kiet Lam64c1b492013-07-12 13:56:44 +05305246 vos_mem_copy(pCsrBssDescription->Result.ssId.ssId, pIes->SSID.ssid, len);
Jeff Johnson295189b2012-06-20 16:38:30 -07005247 }
5248 csrLLInsertTail( &pMac->scan.tempScanResults, &pCsrBssDescription->Link, LL_ACCESS_LOCK );
5249 }
5250
5251 return( pCsrBssDescription );
5252}
5253
5254
5255
5256
5257tANI_BOOLEAN csrIsDuplicateBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc1,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07005258 tSirBssDescription *pSirBssDesc2, tDot11fBeaconIEs *pIes2, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07005259{
5260 tANI_BOOLEAN fMatch = FALSE;
5261 tSirMacCapabilityInfo *pCap1, *pCap2;
5262 tDot11fBeaconIEs *pIes1 = NULL;
Jeff Johnsone7245742012-09-05 17:12:55 -07005263 tDot11fBeaconIEs *pIesTemp = pIes2;
Jeff Johnson295189b2012-06-20 16:38:30 -07005264
5265 pCap1 = (tSirMacCapabilityInfo *)&pSirBssDesc1->capabilityInfo;
5266 pCap2 = (tSirMacCapabilityInfo *)&pSirBssDesc2->capabilityInfo;
5267 if(pCap1->ess == pCap2->ess)
5268 {
5269 if (pCap1->ess &&
Jeff Johnsone7245742012-09-05 17:12:55 -07005270 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId)&&
Abhishek Singhe3fa11f2014-05-13 11:11:10 +05305271 (fForced || (vos_chan_to_band(pSirBssDesc1->channelId) == vos_chan_to_band((pSirBssDesc2->channelId)))))
Jeff Johnson295189b2012-06-20 16:38:30 -07005272 {
5273 fMatch = TRUE;
Jeff Johnsone7245742012-09-05 17:12:55 -07005274 // Check for SSID match, if exists
5275 do
5276 {
5277 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
5278 {
5279 break;
5280 }
5281 if( NULL == pIesTemp )
5282 {
5283 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
5284 {
5285 break;
5286 }
5287 }
5288 if(pIes1->SSID.present && pIesTemp->SSID.present)
5289 {
5290 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
5291 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
5292 }
5293 }while(0);
5294
Jeff Johnson295189b2012-06-20 16:38:30 -07005295 }
5296 else if (pCap1->ibss && (pSirBssDesc1->channelId == pSirBssDesc2->channelId))
5297 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005298
5299 do
5300 {
5301 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
5302 {
5303 break;
5304 }
5305 if( NULL == pIesTemp )
5306 {
5307 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
5308 {
5309 break;
5310 }
5311 }
5312 //Same channel cannot have same SSID for different IBSS
5313 if(pIes1->SSID.present && pIesTemp->SSID.present)
5314 {
5315 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
5316 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
5317 }
5318 }while(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005319 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005320 /* In case of P2P devices, ess and ibss will be set to zero */
5321 else if (!pCap1->ess &&
5322 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId))
5323 {
5324 fMatch = TRUE;
5325 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005326 }
5327
5328 if(pIes1)
5329 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305330 vos_mem_free(pIes1);
Jeff Johnson295189b2012-06-20 16:38:30 -07005331 }
Jeff Johnsone7245742012-09-05 17:12:55 -07005332
5333 if( (NULL == pIes2) && pIesTemp )
5334 {
5335 //locally allocated
Kiet Lam64c1b492013-07-12 13:56:44 +05305336 vos_mem_free(pIesTemp);
Jeff Johnsone7245742012-09-05 17:12:55 -07005337 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005338
5339 return( fMatch );
5340}
5341
5342
5343tANI_BOOLEAN csrIsNetworkTypeEqual( tSirBssDescription *pSirBssDesc1, tSirBssDescription *pSirBssDesc2 )
5344{
5345 return( pSirBssDesc1->nwType == pSirBssDesc2->nwType );
5346}
5347
5348
5349//to check whether the BSS matches the dot11Mode
5350static tANI_BOOLEAN csrScanIsBssAllowed(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
5351 tDot11fBeaconIEs *pIes)
5352{
5353 tANI_BOOLEAN fAllowed = eANI_BOOLEAN_FALSE;
5354 eCsrPhyMode phyMode;
5355
5356 if(HAL_STATUS_SUCCESS(csrGetPhyModeFromBss(pMac, pBssDesc, &phyMode, pIes)))
5357 {
5358 switch(pMac->roam.configParam.phyMode)
5359 {
5360 case eCSR_DOT11_MODE_11b:
5361 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
5362 break;
5363 case eCSR_DOT11_MODE_11g:
5364 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
5365 break;
5366 case eCSR_DOT11_MODE_11g_ONLY:
5367 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11g == phyMode);
5368 break;
5369 case eCSR_DOT11_MODE_11a:
5370 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11b != phyMode) && (eCSR_DOT11_MODE_11g != phyMode));
5371 break;
5372 case eCSR_DOT11_MODE_11n_ONLY:
5373 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11n == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
5374 break;
Jeff Johnsone7245742012-09-05 17:12:55 -07005375
5376#ifdef WLAN_FEATURE_11AC
5377 case eCSR_DOT11_MODE_11ac_ONLY:
5378 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11ac == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
5379 break;
5380#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005381 case eCSR_DOT11_MODE_11b_ONLY:
5382 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11b == phyMode);
5383 break;
5384 case eCSR_DOT11_MODE_11a_ONLY:
5385 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a == phyMode);
5386 break;
5387 case eCSR_DOT11_MODE_11n:
Jeff Johnsone7245742012-09-05 17:12:55 -07005388#ifdef WLAN_FEATURE_11AC
5389 case eCSR_DOT11_MODE_11ac:
5390#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005391 case eCSR_DOT11_MODE_TAURUS:
5392 default:
5393 fAllowed = eANI_BOOLEAN_TRUE;
5394 break;
5395 }
5396 }
5397
5398 return (fAllowed);
5399}
5400
5401
5402
5403//Return pIes to caller for future use when returning TRUE.
5404static tANI_BOOLEAN csrScanValidateScanResult( tpAniSirGlobal pMac, tANI_U8 *pChannels,
5405 tANI_U8 numChn, tSirBssDescription *pBssDesc,
5406 tDot11fBeaconIEs **ppIes )
5407{
5408 tANI_BOOLEAN fValidChannel = FALSE;
5409 tDot11fBeaconIEs *pIes = NULL;
5410 tANI_U8 index;
5411
5412 for( index = 0; index < numChn; index++ )
5413 {
5414 // This check relies on the fact that a single BSS description is returned in each
5415 // ScanRsp call, which is the way LIM implemented the scan req/rsp funtions. We changed
5416 // to this model when we ran with a large number of APs. If this were to change, then
5417 // this check would have to mess with removing the bssDescription from somewhere in an
5418 // arbitrary index in the bssDescription array.
5419 if ( pChannels[ index ] == pBssDesc->channelId )
5420 {
5421 fValidChannel = TRUE;
5422 break;
5423 }
5424 }
5425 *ppIes = NULL;
5426 if(fValidChannel)
5427 {
5428 if( HAL_STATUS_SUCCESS( csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIes) ) )
5429 {
5430 fValidChannel = csrScanIsBssAllowed(pMac, pBssDesc, pIes);
5431 if( fValidChannel )
5432 {
5433 *ppIes = pIes;
5434 }
5435 else
5436 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305437 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07005438 }
5439 }
5440 else
5441 {
5442 fValidChannel = FALSE;
5443 }
5444 }
5445
5446 return( fValidChannel );
5447}
5448
5449
5450//Return whether last scan result is received
5451static tANI_BOOLEAN csrScanProcessScanResults( tpAniSirGlobal pMac, tSmeCmd *pCommand,
5452 tSirSmeScanRsp *pScanRsp, tANI_BOOLEAN *pfRemoveCommand )
5453{
5454 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE, fRemoveCommand = eANI_BOOLEAN_FALSE;
5455 tDot11fBeaconIEs *pIes = NULL;
5456 tANI_U32 cbParsed;
5457 tSirBssDescription *pSirBssDescription;
5458 tANI_U32 cbBssDesc;
5459 tANI_U32 cbScanResult = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription )
5460 + sizeof(tSirBssDescription); //We need at least one CB
5461
5462 // don't consider the scan rsp to be valid if the status code is Scan Failure. Scan Failure
5463 // is returned when the scan could not find anything. so if we get scan failure return that
5464 // the scan response is invalid. Also check the lenght in the scan result for valid scan
5465 // BssDescriptions....
5466 do
5467 {
5468 if ( ( cbScanResult <= pScanRsp->length ) &&
5469 (( eSIR_SME_SUCCESS == pScanRsp->statusCode ) ||
5470 ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW == pScanRsp->statusCode ) ) )
5471 {
5472 tANI_U8 *pChannelList = NULL;
5473 tANI_U8 cChannels = 0;
5474
5475 //Different scan type can reach this point, we need to distinguish it
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005476#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5477 if( eCsrScanGetLfrResult == pCommand->u.scanCmd.reason )
5478 {
5479 pChannelList = NULL;
5480 cChannels = 0;
5481 }
5482 else
5483#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005484 if( eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason )
5485 {
5486 //eCsrScanSetBGScanParam uses different structure
5487 tCsrBGScanRequest *pBgScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
5488
5489 cChannels = pBgScanReq->ChannelInfo.numOfChannels;
5490 pChannelList = pBgScanReq->ChannelInfo.ChannelList;
5491 }
5492 else
5493 {
5494 //the rest use generic scan request
5495 cChannels = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
5496 pChannelList = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
5497 }
5498
5499 // if the scan result is not on one of the channels in the Valid channel list, then it
5500 // must have come from an AP on an overlapping channel (in the 2.4GHz band). In this case,
5501 // let's drop the scan result.
5502 //
5503 // The other situation is where the scan request is for a scan on a particular channel set
5504 // and the scan result is from a
5505
5506 // if the NumChannels is 0, then we are supposed to be scanning all channels. Use the full channel
5507 // list as the 'valid' channel list. Otherwise, use the specific channel list in the scan parms
5508 // as the valid channels.
5509 if ( 0 == cChannels )
5510 {
5511 tANI_U32 len = sizeof(pMac->roam.validChannelList);
5512
5513 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
5514 {
5515 pChannelList = pMac->roam.validChannelList;
5516 cChannels = (tANI_U8)len;
5517 }
5518 else
5519 {
5520 //Cannot continue
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005521 smsLog( pMac, LOGE, "CSR: Processing internal SCAN results...csrGetCfgValidChannels failed" );
Jeff Johnson295189b2012-06-20 16:38:30 -07005522 break;
5523 }
5524 }
5525
5526 smsLog( pMac, LOG2, "CSR: Processing internal SCAN results..." );
5527 cbParsed = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription );
5528 pSirBssDescription = pScanRsp->bssDescription;
5529 while( cbParsed < pScanRsp->length )
5530 {
5531 if ( csrScanValidateScanResult( pMac, pChannelList, cChannels, pSirBssDescription, &pIes ) )
5532 {
5533 csrScanRemoveDupBssDescriptionFromInterimList(pMac, pSirBssDescription, pIes);
5534 csrScanSaveBssDescriptionToInterimList( pMac, pSirBssDescription, pIes );
5535 if( eSIR_PASSIVE_SCAN == pMac->scan.curScanType )
5536 {
5537 if( csrIs11dSupported( pMac) )
5538 {
5539 //Check whether the BSS is acceptable base on 11d info and our configs.
5540 if( csrMatchCountryCode( pMac, NULL, pIes ) )
5541 {
5542 //Double check whether the channel is acceptable by us.
5543 if( csrIsSupportedChannel( pMac, pSirBssDescription->channelId ) )
5544 {
5545 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
5546 }
5547 }
5548 }
5549 else
5550 {
5551 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
5552 }
5553 }
5554 //Free the resource
Kiet Lam64c1b492013-07-12 13:56:44 +05305555 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07005556 }
5557 // skip over the BSS description to the next one...
5558 cbBssDesc = pSirBssDescription->length + sizeof( pSirBssDescription->length );
5559
5560 cbParsed += cbBssDesc;
5561 pSirBssDescription = (tSirBssDescription *)((tANI_U8 *)pSirBssDescription + cbBssDesc );
5562
5563 } //while
5564 }
5565 else
5566 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005567 smsLog( pMac, LOGW, " Scanrsp fail (0x%08X), length = %d (expected %d)",
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08005568 pScanRsp->statusCode, pScanRsp->length, cbScanResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07005569 //HO bg scan/probe failed no need to try autonomously
5570 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
5571 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005572#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5573 eCsrScanGetLfrResult == pCommand->u.scanCmd.reason ||
5574#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005575 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
5576 {
5577 fRemoveCommand = eANI_BOOLEAN_TRUE;
5578 }
5579 }
5580 }while(0);
5581 if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
5582 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005583 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 -07005584 fRemoveCommand = csrScanComplete( pMac, pScanRsp );
5585 fRet = eANI_BOOLEAN_TRUE;
5586 }//if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
5587 if(pfRemoveCommand)
5588 {
5589 *pfRemoveCommand = fRemoveCommand;
5590 }
5591
5592#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305593 if (pMac->fScanOffload)
5594 return fRet;
5595
Jeff Johnson295189b2012-06-20 16:38:30 -07005596 if (!csrLLIsListEmpty( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK ))
5597 {
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005598 /* Pending scan commands in the list because the previous scan command
5599 * was split into a scan command on one channel + a scan command for all
5600 * remaining channels.
5601 *
5602 * Start timer to trigger processing of the next scan command.
Srikant Kuppa866893f2012-12-27 17:28:14 -08005603 * NOTE for LFR:
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305604 * Do not split scans if no concurrent infra connections are
Srikant Kuppa866893f2012-12-27 17:28:14 -08005605 * active and if the scan is a BG scan triggered by LFR (OR)
5606 * any scan if LFR is in the middle of a BG scan. Splitting
5607 * the scan is delaying the time it takes for LFR to find
5608 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005609 */
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305610 if ( (csrIsStaSessionConnected(pMac) &&
Srikant Kuppa866893f2012-12-27 17:28:14 -08005611#ifdef FEATURE_WLAN_LFR
5612 (csrIsConcurrentInfraConnected(pMac) ||
5613 ((pCommand->u.scanCmd.reason != eCsrScanBgScan) &&
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305614 (pMac->roam.neighborRoamInfo.neighborRoamState !=
Srikant Kuppa866893f2012-12-27 17:28:14 -08005615 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
5616#endif
5617 (pCommand->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305618 (csrIsP2pSessionConnected(pMac)) )
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005619 {
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005620 /* if active connected sessions present then continue to split scan
5621 * with specified interval between consecutive scans */
5622 csrSetDefaultScanTiming(pMac, pCommand->u.scanCmd.u.scanRequest.scanType, &(pCommand->u.scanCmd.u.scanRequest));
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05305623 vos_timer_start(&pMac->scan.hTimerStaApConcTimer,
5624 pCommand->u.scanCmd.u.scanRequest.restTime);
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005625 } else {
5626 /* if no connected sessions present then initiate next scan command immediately */
5627 /* minimum timer granularity is 10ms */
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05305628 vos_timer_start(&pMac->scan.hTimerStaApConcTimer, 10);
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005629 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005630 }
5631#endif
5632 return (fRet);
5633}
5634
5635
5636tANI_BOOLEAN csrScanIsWildCardScan( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5637{
5638 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
Kiet Lam64c1b492013-07-12 13:56:44 +05305639 tANI_BOOLEAN f = vos_mem_compare(pCommand->u.scanCmd.u.scanRequest.bssid,
5640 bssid, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07005641
5642 //It is not a wild card scan if the bssid is not broadcast and the number of SSID is 1.
5643 return ((tANI_BOOLEAN)( (f || (0xff == pCommand->u.scanCmd.u.scanRequest.bssid[0])) &&
5644 (pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs != 1) ));
5645}
5646
5647
5648eHalStatus csrScanSmeScanResponse( tpAniSirGlobal pMac, void *pMsgBuf )
5649{
5650 eHalStatus status = eHAL_STATUS_SUCCESS;
5651 tListElem *pEntry;
5652 tSmeCmd *pCommand;
5653 eCsrScanStatus scanStatus;
Sunkad, Anand Ningappa3ec8bf72016-02-05 15:13:30 +05305654 tSirSmeScanRsp *pScanRsp;
Jeff Johnson295189b2012-06-20 16:38:30 -07005655 tSmeGetScanChnRsp *pScanChnInfo;
5656 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
5657 eCsrScanReason reason = eCsrScanOther;
5658
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305659 if (pMac->fScanOffload)
5660 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList,
5661 LL_ACCESS_LOCK);
5662 else
5663 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07005664
5665 if ( pEntry )
5666 {
5667 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
5668 if ( eSmeCommandScan == pCommand->command )
5669 {
Deepthi Gowrife5340b2016-04-11 12:15:46 +05305670 /* Purge the scan results based on Aging */
5671 if (pEntry && pMac->scan.scanResultCfgAgingTime)
5672 csrPurgeScanResultByAge(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07005673 reason = pCommand->u.scanCmd.reason;
5674 switch(pCommand->u.scanCmd.reason)
5675 {
5676 case eCsrScanAbortBgScan:
5677 case eCsrScanAbortNormalScan:
5678 case eCsrScanBGScanAbort:
5679 case eCsrScanBGScanEnable:
Sunkad, Anand Ningappa3ec8bf72016-02-05 15:13:30 +05305680 pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
5681 scanStatus = (eSIR_SME_SUCCESS == pScanRsp->statusCode) ?
5682 eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005683 break;
5684 case eCsrScanGetScanChnInfo:
Deepthi Gowrife5340b2016-04-11 12:15:46 +05305685 pScanChnInfo = (tSmeGetScanChnRsp *)pMsgBuf;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005686 /*
5687 * status code not available in tSmeGetScanChnRsp, so
5688 * by default considereing it to be success
5689 */
5690 scanStatus = eSIR_SME_SUCCESS;
Deepthi Gowrife5340b2016-04-11 12:15:46 +05305691 csrScanAgeResults(pMac, pScanChnInfo);
Jeff Johnson295189b2012-06-20 16:38:30 -07005692 break;
5693 case eCsrScanForCapsChange:
Sunkad, Anand Ningappa3ec8bf72016-02-05 15:13:30 +05305694 pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
5695 scanStatus = (eSIR_SME_SUCCESS == pScanRsp->statusCode) ?
5696 eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005697 csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand );
5698 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005699 case eCsrScanP2PFindPeer:
Sunkad, Anand Ningappa3ec8bf72016-02-05 15:13:30 +05305700 pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
5701 scanStatus = ((eSIR_SME_SUCCESS == pScanRsp->statusCode) &&
5702 (pScanRsp->length > 50)) ? eCSR_SCAN_FOUND_PEER : eCSR_SCAN_FAILURE;
5703 csrScanProcessScanResults( pMac, pCommand, pScanRsp, NULL );
5704 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005705 case eCsrScanSetBGScanParam:
5706 default:
Sunkad, Anand Ningappa3ec8bf72016-02-05 15:13:30 +05305707 pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
5708 scanStatus = (eSIR_SME_SUCCESS == pScanRsp->statusCode) ?
5709 eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005710 if(csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand ))
5711 {
5712 //Not to get channel info if the scan is not a wildcard scan because
5713 //it may cause scan results got aged out incorrectly.
Ratheesh S Pece1f832015-07-25 15:50:25 +05305714 if(csrScanIsWildCardScan( pMac, pCommand ) &&
5715 (!pCommand->u.scanCmd.u.scanRequest.p2pSearch)
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005716#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5717 && (pCommand->u.scanCmd.reason != eCsrScanGetLfrResult)
5718#endif
5719 )
Jeff Johnson295189b2012-06-20 16:38:30 -07005720 {
Ratheesh S Pece1f832015-07-25 15:50:25 +05305721 csrScanGetScanChnInfo(pMac, pCommand);
Jeff Johnson295189b2012-06-20 16:38:30 -07005722 }
5723 }
5724 break;
5725 }//switch
5726 if(fRemoveCommand)
5727 {
5728
5729 csrReleaseScanCommand(pMac, pCommand, scanStatus);
5730
Sunkad, Anand Ningappa3ec8bf72016-02-05 15:13:30 +05305731 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005732 smeProcessPendingQueue( pMac );
5733 }
5734 else
5735 {
5736 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
5737 status = eHAL_STATUS_FAILURE;
5738 }
5739 }
5740 else
5741 {
5742 smsLog( pMac, LOGW, "CSR: Scan Completion called but NO commands are ACTIVE ..." );
5743 status = eHAL_STATUS_FAILURE;
5744 }
5745
5746 return (status);
5747}
5748
5749
5750
5751
5752tCsrScanResultInfo *csrScanResultGetFirst(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
5753{
5754 tListElem *pEntry;
5755 tCsrScanResult *pResult;
5756 tCsrScanResultInfo *pRet = NULL;
5757 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5758
5759 if(pResultList)
5760 {
5761 csrLLLock(&pResultList->List);
5762 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5763 if(pEntry)
5764 {
5765 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
5766 pRet = &pResult->Result;
5767 }
5768 pResultList->pCurEntry = pEntry;
5769 csrLLUnlock(&pResultList->List);
5770 }
5771
5772 return pRet;
5773}
5774
5775
5776tCsrScanResultInfo *csrScanResultGetNext(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
5777{
5778 tListElem *pEntry = NULL;
5779 tCsrScanResult *pResult = NULL;
5780 tCsrScanResultInfo *pRet = NULL;
5781 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5782
5783 if(pResultList)
5784 {
5785 csrLLLock(&pResultList->List);
5786 if(NULL == pResultList->pCurEntry)
5787 {
5788 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5789 }
5790 else
5791 {
5792 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
5793 }
5794 if(pEntry)
5795 {
5796 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
5797 pRet = &pResult->Result;
5798 }
5799 pResultList->pCurEntry = pEntry;
5800 csrLLUnlock(&pResultList->List);
5801 }
5802
5803 return pRet;
5804}
5805
5806
5807//This function moves the first BSS that matches the bssid to the head of the result
5808eHalStatus csrMoveBssToHeadFromBSSID(tpAniSirGlobal pMac, tCsrBssid *bssid, tScanResultHandle hScanResult)
5809{
5810 eHalStatus status = eHAL_STATUS_FAILURE;
5811 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5812 tCsrScanResult *pResult = NULL;
5813 tListElem *pEntry = NULL;
5814
5815 if(pResultList && bssid)
5816 {
5817 csrLLLock(&pResultList->List);
5818 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5819 while(pEntry)
5820 {
5821 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
Kiet Lam64c1b492013-07-12 13:56:44 +05305822 if (vos_mem_compare(bssid, pResult->Result.BssDescriptor.bssId, sizeof(tCsrBssid)))
Jeff Johnson295189b2012-06-20 16:38:30 -07005823 {
5824 status = eHAL_STATUS_SUCCESS;
5825 csrLLRemoveEntry(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
5826 csrLLInsertHead(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
5827 break;
5828 }
5829 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
5830 }
5831 csrLLUnlock(&pResultList->List);
5832 }
5833
5834 return (status);
5835}
5836
5837
5838//Remove the BSS if possible.
5839//Return -- TRUE == the BSS is remove. False == Fail to remove it
5840//This function is called when list lock is held. Be caution what functions it can call.
5841tANI_BOOLEAN csrScanAgeOutBss(tpAniSirGlobal pMac, tCsrScanResult *pResult)
5842{
5843 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
5844 tANI_U32 i;
5845 tCsrRoamSession *pSession;
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305846 tANI_BOOLEAN isConnBssfound = eANI_BOOLEAN_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005847
5848 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5849 {
5850 if( CSR_IS_SESSION_VALID( pMac, i ) )
5851 {
5852 pSession = CSR_GET_SESSION( pMac, i );
5853 //Not to remove the BSS we are connected to.
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305854 if(csrIsConnStateConnectedInfra(pMac, i) && (NULL != pSession->pConnectBssDesc) &&
5855 (csrIsDuplicateBssDescription(pMac, &pResult->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07005856 pSession->pConnectBssDesc, NULL, FALSE))
Jeff Johnson295189b2012-06-20 16:38:30 -07005857 )
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305858 {
5859 isConnBssfound = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005860 break;
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305861 }
5862 }
5863 }
5864
5865 if( isConnBssfound )
Jeff Johnson295189b2012-06-20 16:38:30 -07005866 {
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305867 //Reset the counter so that aging out of connected BSS won't hapeen too soon
Jeff Johnson295189b2012-06-20 16:38:30 -07005868 pResult->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Deepthi Gowri4480a3f2016-05-18 19:30:17 +05305869 pResult->Result.BssDescriptor.nReceivedTime =
5870 vos_timer_get_system_time();
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305871
5872 return (fRet);
5873 }
5874 else
5875 {
5876 smsLog(pMac, LOGW, "Aging out BSS "MAC_ADDRESS_STR" Channel %d",
5877 MAC_ADDR_ARRAY(pResult->Result.BssDescriptor.bssId),
5878 pResult->Result.BssDescriptor.channelId);
5879 //No need to hold the spin lock because caller should hold the lock for pMac->scan.scanResultList
5880 if( csrLLRemoveEntry(&pMac->scan.scanResultList, &pResult->Link, LL_ACCESS_NOLOCK) )
5881 {
5882 if (csrIsMacAddressEqual(pMac,
5883 (tCsrBssid *) pResult->Result.BssDescriptor.bssId,
5884 (tCsrBssid *) pMac->scan.currentCountryBssid))
5885 {
5886 smsLog(pMac, LOGW, "Aging out 11d BSS "MAC_ADDRESS_STR,
5887 MAC_ADDR_ARRAY(pResult->Result.BssDescriptor.bssId));
5888 pMac->scan.currentCountryRSSI = -128;
5889 }
5890 csrFreeScanResultEntry(pMac, pResult);
5891 fRet = eANI_BOOLEAN_TRUE;
5892 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005893 }
5894
5895 return (fRet);
5896}
5897
5898
5899eHalStatus csrScanAgeResults(tpAniSirGlobal pMac, tSmeGetScanChnRsp *pScanChnInfo)
5900{
5901 eHalStatus status = eHAL_STATUS_SUCCESS;
5902 tListElem *pEntry, *tmpEntry;
5903 tCsrScanResult *pResult;
5904 tLimScanChn *pChnInfo;
5905 tANI_U8 i;
5906
5907 csrLLLock(&pMac->scan.scanResultList);
5908 for(i = 0; i < pScanChnInfo->numChn; i++)
5909 {
5910 pChnInfo = &pScanChnInfo->scanChn[i];
5911 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
5912 while( pEntry )
5913 {
5914 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
5915 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
5916 if(pResult->Result.BssDescriptor.channelId == pChnInfo->channelId)
5917 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005918 if(pResult->AgingCount <= 0)
5919 {
5920 smsLog(pMac, LOGW, " age out due to ref count");
5921 csrScanAgeOutBss(pMac, pResult);
5922 }
Madan Mohan Koyyalamudib9d3dcc2012-09-28 16:47:50 -07005923 else
5924 {
5925 pResult->AgingCount--;
5926 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005927 }
5928 pEntry = tmpEntry;
5929 }
5930 }
5931 csrLLUnlock(&pMac->scan.scanResultList);
5932
5933 return (status);
5934}
5935
Abhishek Singhc640dbb2015-06-08 10:54:17 +05305936eHalStatus csrIbssAgeBss(tpAniSirGlobal pMac)
5937{
5938 eHalStatus status = eHAL_STATUS_SUCCESS;
5939 tListElem *pEntry, *tmpEntry;
5940 tCsrScanResult *pResult;
5941
5942 csrLLLock(&pMac->scan.scanResultList);
5943 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
5944 while( pEntry )
5945 {
5946 tmpEntry = csrLLNext(&pMac->scan.scanResultList,
5947 pEntry, LL_ACCESS_NOLOCK);
5948 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
5949
5950 smsLog(pMac, LOGW, FL(" age out due Forced IBSS leave"));
5951 csrScanAgeOutBss(pMac, pResult);
5952 pEntry = tmpEntry;
5953 }
5954 csrLLUnlock(&pMac->scan.scanResultList);
5955
5956 return (status);
5957}
Jeff Johnson295189b2012-06-20 16:38:30 -07005958
5959eHalStatus csrSendMBScanReq( tpAniSirGlobal pMac, tANI_U16 sessionId,
5960 tCsrScanRequest *pScanReq, tScanReqParam *pScanReqParam )
5961{
5962 eHalStatus status = eHAL_STATUS_SUCCESS;
5963 tSirSmeScanReq *pMsg;
5964 tANI_U16 msgLen;
5965 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
5966 tSirScanType scanType = pScanReq->scanType;
5967 tANI_U32 minChnTime; //in units of milliseconds
5968 tANI_U32 maxChnTime; //in units of milliseconds
5969 tANI_U32 i;
5970 tANI_U8 selfMacAddr[WNI_CFG_BSSID_LEN];
5971 tANI_U8 *pSelfMac = NULL;
5972
5973 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
5974 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) +
5975 ( pScanReq->uIEFieldLen ) ;
5976
Kiet Lam64c1b492013-07-12 13:56:44 +05305977 pMsg = vos_mem_malloc(msgLen);
5978 if ( NULL == pMsg )
5979 status = eHAL_STATUS_FAILURE;
5980 else
5981 status = eHAL_STATUS_SUCCESS;
5982 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07005983 {
5984 do
5985 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305986 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005987 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
5988 pMsg->length = pal_cpu_to_be16(msgLen);
5989 //ToDO: Fill in session info when we need to do scan base on session.
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05305990 if ((pMac->fScanOffload) && (sessionId != CSR_SESSION_ID_INVALID))
5991 {
5992 pMsg->sessionId = sessionId;
5993 }
5994 else
5995 {
5996 /* if sessionId == CSR_SESSION_ID_INVALID, then send the scan
5997 request on first available session */
5998 pMsg->sessionId = 0;
5999 }
6000
Jeff Johnson295189b2012-06-20 16:38:30 -07006001 pMsg->transactionId = 0;
6002 pMsg->dot11mode = (tANI_U8) csrTranslateToWNICfgDot11Mode(pMac, csrFindBestPhyMode( pMac, pMac->roam.configParam.phyMode ));
6003 pMsg->bssType = pal_cpu_to_be32(csrTranslateBsstypeToMacType(pScanReq->BSSType));
6004
6005 if ( CSR_IS_SESSION_VALID( pMac, sessionId ) )
6006 {
6007 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[sessionId].selfMacAddr;
6008 }
6009 else
6010 {
6011 // Since we don't have session for the scanning, we find a valid session. In case we fail to
6012 // do so, get the WNI_CFG_STA_ID
6013 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
6014 {
6015 if( CSR_IS_SESSION_VALID( pMac, i ) )
6016 {
6017 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[i].selfMacAddr;
6018 break;
6019 }
6020 }
6021 if( CSR_ROAM_SESSION_MAX == i )
6022 {
6023 tANI_U32 len = WNI_CFG_BSSID_LEN;
6024 pSelfMac = selfMacAddr;
6025 status = ccmCfgGetStr( pMac, WNI_CFG_STA_ID, pSelfMac, &len );
6026 if( !HAL_STATUS_SUCCESS( status ) ||
6027 ( len < WNI_CFG_BSSID_LEN ) )
6028 {
6029 smsLog( pMac, LOGE, FL(" Can not get self MAC address from CFG status = %d"), status );
6030 //Force failed status
6031 status = eHAL_STATUS_FAILURE;
6032 break;
6033 }
6034 }
6035 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306036 vos_mem_copy((tANI_U8 *)pMsg->selfMacAddr, pSelfMac, sizeof(tSirMacAddr));
Jeff Johnson295189b2012-06-20 16:38:30 -07006037
6038 //sirCopyMacAddr
Kiet Lam64c1b492013-07-12 13:56:44 +05306039 vos_mem_copy((tANI_U8 *)pMsg->bssId, (tANI_U8 *)&pScanReq->bssid, sizeof(tSirMacAddr));
6040 if ( vos_mem_compare(pScanReq->bssid, bssid, sizeof(tCsrBssid)))
Jeff Johnson295189b2012-06-20 16:38:30 -07006041 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306042 vos_mem_set(pMsg->bssId, sizeof(tSirMacAddr), 0xff);
Jeff Johnson295189b2012-06-20 16:38:30 -07006043 }
6044 else
6045 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306046 vos_mem_copy(pMsg->bssId, pScanReq->bssid, WNI_CFG_BSSID_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07006047 }
6048 minChnTime = pScanReq->minChnTime;
6049 maxChnTime = pScanReq->maxChnTime;
6050
6051 //Verify the scan type first, if the scan is active scan, we need to make sure we
6052 //are allowed to do so.
6053 /* if 11d is enabled & we don't see any beacon around, scan type falls
6054 back to passive. But in BT AMP STA mode we need to send out a
6055 directed probe*/
6056 if( (eSIR_PASSIVE_SCAN != scanType) && (eCSR_SCAN_P2P_DISCOVERY != pScanReq->requestType)
6057 && (eCSR_BSS_TYPE_WDS_STA != pScanReq->BSSType)
6058 && (eANI_BOOLEAN_FALSE == pMac->scan.fEnableBypass11d))
6059 {
6060 scanType = pMac->scan.curScanType;
6061 if(eSIR_PASSIVE_SCAN == pMac->scan.curScanType)
6062 {
6063 if(minChnTime < pMac->roam.configParam.nPassiveMinChnTime)
6064 {
6065 minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
6066 }
6067 if(maxChnTime < pMac->roam.configParam.nPassiveMaxChnTime)
6068 {
6069 maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
6070 }
6071 }
6072 }
6073 pMsg->scanType = pal_cpu_to_be32(scanType);
6074
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306075 pMsg->numSsid =
6076 (pScanReq->SSIDs.numOfSSIDs < SIR_SCAN_MAX_NUM_SSID) ?
6077 pScanReq->SSIDs.numOfSSIDs : SIR_SCAN_MAX_NUM_SSID;
Jeff Johnson295189b2012-06-20 16:38:30 -07006078 if((pScanReq->SSIDs.numOfSSIDs != 0) && ( eSIR_PASSIVE_SCAN != scanType ))
6079 {
Jeff Johnson40b59aa2013-03-19 14:43:18 -07006080 for (i = 0; i < pMsg->numSsid; i++)
6081 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306082 vos_mem_copy(&pMsg->ssId[i],
6083 &pScanReq->SSIDs.SSIDList[i].SSID, sizeof(tSirMacSSid));
Jeff Johnson40b59aa2013-03-19 14:43:18 -07006084 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006085 }
6086 else
6087 {
6088 //Otherwise we scan all SSID and let the result filter later
Jeff Johnson40b59aa2013-03-19 14:43:18 -07006089 for (i = 0; i < SIR_SCAN_MAX_NUM_SSID; i++)
6090 {
6091 pMsg->ssId[i].length = 0;
6092 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006093 }
6094
Jeff Johnson295189b2012-06-20 16:38:30 -07006095 pMsg->minChannelTime = pal_cpu_to_be32(minChnTime);
6096 pMsg->maxChannelTime = pal_cpu_to_be32(maxChnTime);
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08006097 pMsg->minChannelTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
6098 pMsg->maxChannelTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07006099 //hidden SSID option
6100 pMsg->hiddenSsid = pScanReqParam->hiddenSsid;
6101 //rest time
6102 //pMsg->restTime = pScanReq->restTime;
6103 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
6104 // All the scan results caching will be done by Roaming
6105 // We do not want LIM to do any caching of scan results,
6106 // so delete the LIM cache on all scan requests
6107 pMsg->returnFreshResults = pScanReqParam->freshScan;
6108 //Always ask for unique result
6109 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
6110 pMsg->channelList.numChannels = (tANI_U8)pScanReq->ChannelInfo.numOfChannels;
6111 if(pScanReq->ChannelInfo.numOfChannels)
6112 {
6113 //Assuming the channelNumber is tANI_U8 (1 byte)
Kiet Lam64c1b492013-07-12 13:56:44 +05306114 vos_mem_copy(pMsg->channelList.channelNumber,
6115 pScanReq->ChannelInfo.ChannelList,
6116 pScanReq->ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07006117 }
6118
6119 pMsg->uIEFieldLen = (tANI_U16) pScanReq->uIEFieldLen;
6120 pMsg->uIEFieldOffset = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
6121 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) ;
6122 if(pScanReq->uIEFieldLen != 0)
6123 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306124 vos_mem_copy((tANI_U8 *)pMsg+pMsg->uIEFieldOffset, pScanReq->pIEField,
6125 pScanReq->uIEFieldLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07006126 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006127 pMsg->p2pSearch = pScanReq->p2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07006128
Madan Mohan Koyyalamudi9b876782012-10-11 16:22:51 -07006129 if (pScanReq->requestType == eCSR_SCAN_HO_BG_SCAN)
6130 {
6131 pMsg->backgroundScanMode = eSIR_ROAMING_SCAN;
6132 }
6133
Jeff Johnson295189b2012-06-20 16:38:30 -07006134 }while(0);
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05306135 smsLog(pMac, LOG1, FL("domainIdCurrent %s (%d) scanType %s (%d)"
6136 "bssType %s (%d), requestType %s(%d)"
6137 "numChannels %d"),
6138 voss_DomainIdtoString(pMac->scan.domainIdCurrent),
6139 pMac->scan.domainIdCurrent,
6140 lim_ScanTypetoString(pMsg->scanType), pMsg->scanType,
6141 lim_BssTypetoString(pMsg->bssType), pMsg->bssType,
6142 sme_requestTypetoString(pScanReq->requestType),
6143 pScanReq->requestType,
6144 pMsg->channelList.numChannels);
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08006145
6146 for(i = 0; i < pMsg->channelList.numChannels; i++)
6147 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006148 smsLog(pMac, LOG3, FL("channelNumber[%d]= %d"), i, pMsg->channelList.channelNumber[i]);
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08006149 }
6150
Jeff Johnson295189b2012-06-20 16:38:30 -07006151 if(HAL_STATUS_SUCCESS(status))
6152 {
6153 status = palSendMBMessage(pMac->hHdd, pMsg);
6154 }
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08006155 else
6156 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006157 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d"), status );
Kiet Lam64c1b492013-07-12 13:56:44 +05306158 vos_mem_free(pMsg);
Jeff Johnson295189b2012-06-20 16:38:30 -07006159 }
6160 }//Success allocated memory
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08006161 else
6162 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006163 smsLog( pMac, LOGE, FL(" memory allocation failure"));
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08006164 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006165
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306166 if(!HAL_STATUS_SUCCESS(status))
6167 {
6168 smsLog( pMac, LOG1, FL("Failed: SId: %d FirstMatch = %d"
6169 " UniqueResult = %d freshScan = %d hiddenSsid = %d"),
6170 sessionId, pScanReqParam->bReturnAfter1stMatch,
6171 pScanReqParam->fUniqueResult, pScanReqParam->freshScan,
6172 pScanReqParam->hiddenSsid );
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05306173 smsLog( pMac, LOG1, FL("scanType = %s (%d) BSSType = %s (%d) "
6174 "numOfSSIDs = %d numOfChannels = %d requestType = %s (%d)"
6175 " p2pSearch = %d\n"),
6176 lim_ScanTypetoString(pScanReq->scanType),
6177 pScanReq->scanType,
6178 lim_BssTypetoString(pScanReq->BSSType),
6179 pScanReq->BSSType,
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306180 pScanReq->SSIDs.numOfSSIDs,
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05306181 pScanReq->ChannelInfo.numOfChannels,
6182 sme_requestTypetoString(pScanReq->requestType),
6183 pScanReq->requestType,
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306184 pScanReq->p2pSearch );
6185
6186 }
6187
Jeff Johnson295189b2012-06-20 16:38:30 -07006188 return( status );
6189}
6190
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006191eHalStatus csrSendMBScanResultReq( tpAniSirGlobal pMac, tANI_U32 sessionId, tScanReqParam *pScanReqParam )
Jeff Johnson295189b2012-06-20 16:38:30 -07006192{
6193 eHalStatus status = eHAL_STATUS_SUCCESS;
6194 tSirSmeScanReq *pMsg;
6195 tANI_U16 msgLen;
6196
6197 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ));
Kiet Lam64c1b492013-07-12 13:56:44 +05306198 pMsg = vos_mem_malloc(msgLen);
6199 if ( NULL == pMsg )
6200 status = eHAL_STATUS_FAILURE;
6201 else
Jeff Johnson295189b2012-06-20 16:38:30 -07006202 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306203 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006204 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
6205 pMsg->length = pal_cpu_to_be16(msgLen);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006206 pMsg->sessionId = sessionId;
6207 pMsg->transactionId = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07006208 pMsg->returnFreshResults = pScanReqParam->freshScan;
6209 //Always ask for unique result
6210 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
6211 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
6212 status = palSendMBMessage(pMac->hHdd, pMsg);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006213 if (!HAL_STATUS_SUCCESS(status))
6214 {
6215 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d\n"), status );
6216 }
6217
Jeff Johnson295189b2012-06-20 16:38:30 -07006218 }
6219
6220 return( status );
6221}
6222
6223
6224
6225eHalStatus csrScanChannels( tpAniSirGlobal pMac, tSmeCmd *pCommand )
6226{
6227 eHalStatus status = eHAL_STATUS_FAILURE;
6228 tScanReqParam scanReq;
6229
6230 do
6231 {
6232 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE | TRUE;
6233 scanReq.fUniqueResult = TRUE;
6234 scanReq.hiddenSsid = SIR_SCAN_NO_HIDDEN_SSID;
6235 if(eCsrScanForSsid == pCommand->u.scanCmd.reason)
6236 {
6237 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_FIRST_MATCH;
6238 }
6239 else
6240 {
6241 // Basically do scan on all channels even for 11D 1st scan case.
6242 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
6243 }
6244 if((eCsrScanBgScan == pCommand->u.scanCmd.reason)||
6245 (eCsrScanProbeBss == pCommand->u.scanCmd.reason))
6246 {
6247 scanReq.hiddenSsid = SIR_SCAN_HIDDEN_SSID_PE_DECISION;
6248 }
6249
6250#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
6251 {
6252 vos_log_scan_pkt_type *pScanLog = NULL;
6253
6254 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
6255 if(pScanLog)
6256 {
6257 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
6258 eCsrScanProbeBss == pCommand->u.scanCmd.reason)
6259 {
6260 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
6261 }
6262 else
6263 {
6264 if( (eSIR_PASSIVE_SCAN != pCommand->u.scanCmd.u.scanRequest.scanType) &&
6265 (eSIR_PASSIVE_SCAN != pMac->scan.curScanType) )
6266 {
6267 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_REQ;
6268 }
6269 else
6270 {
6271 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_REQ;
6272 }
6273 }
6274 pScanLog->minChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.minChnTime;
6275 pScanLog->maxChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.maxChnTime;
6276 pScanLog->numChannel = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
6277 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
6278 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306279 vos_mem_copy(pScanLog->channels,
6280 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
6281 pScanLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07006282 }
6283 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
6284 }
6285 }
6286#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
6287
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05306288 csrClearVotesForCountryInfo(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07006289 status = csrSendMBScanReq(pMac, pCommand->sessionId,
6290 &pCommand->u.scanCmd.u.scanRequest, &scanReq);
6291 }while(0);
6292
6293 return( status );
6294}
6295
6296
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006297eHalStatus csrScanRetrieveResult(tpAniSirGlobal pMac, tSmeCmd *pCommand)
Jeff Johnson295189b2012-06-20 16:38:30 -07006298{
6299 eHalStatus status = eHAL_STATUS_FAILURE;
6300 tScanReqParam scanReq;
6301
6302 do
6303 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006304#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
6305 if (eCsrScanGetLfrResult == pCommand->u.scanCmd.reason)
6306 {
6307 //to get the LFR candidates from PE cache
6308 scanReq.freshScan = SIR_BG_SCAN_RETURN_LFR_CACHED_RESULTS|SIR_BG_SCAN_PURGE_LFR_RESULTS;
6309 scanReq.fUniqueResult = TRUE;
6310 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
6311 }
6312 else
6313#endif
6314 {
6315 //not a fresh scan
6316 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE;
6317 scanReq.fUniqueResult = TRUE;
6318 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
6319 }
6320 status = csrSendMBScanResultReq(pMac, pCommand->sessionId, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07006321 }while(0);
6322
6323 return (status);
6324}
6325
Siddharth Bhald8a95e82015-02-12 20:14:52 +05306326eHalStatus csrProcessMacAddrSpoofCommand( tpAniSirGlobal pMac, tSmeCmd *pCommand )
6327{
6328 tSirSpoofMacAddrReq *pMsg;
6329 tANI_U16 msgLen;
6330 eHalStatus status = eHAL_STATUS_FAILURE;
6331 do {
6332 msgLen = sizeof(tSirSpoofMacAddrReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07006333
Siddharth Bhald8a95e82015-02-12 20:14:52 +05306334 pMsg = vos_mem_malloc(msgLen);
6335 if ( NULL == pMsg )
6336 return eHAL_STATUS_FAILURE;
6337 pMsg->messageType= pal_cpu_to_be16((tANI_U16)eWNI_SME_MAC_SPOOF_ADDR_IND);
6338 pMsg->length= pal_cpu_to_be16(msgLen);
6339 // spoof mac address
6340 vos_mem_copy((tANI_U8 *)pMsg->macAddr,
6341 (tANI_U8 *)pCommand->u.macAddrSpoofCmd.macAddr, sizeof(tSirMacAddr));
6342 status = palSendMBMessage(pMac->hHdd, pMsg);
6343 } while( 0 );
6344 return( status );
6345}
Jeff Johnson295189b2012-06-20 16:38:30 -07006346
6347eHalStatus csrProcessScanCommand( tpAniSirGlobal pMac, tSmeCmd *pCommand )
6348{
6349 eHalStatus status = eHAL_STATUS_SUCCESS;
6350 tCsrChannelInfo newChannelInfo = {0, NULL};
6351 int i, j;
6352 tANI_U8 *pChannel = NULL;
6353 tANI_U32 len = 0;
6354
6355 // Transition to Scanning state...
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306356 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07006357 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306358 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
6359 {
6360 pCommand->u.scanCmd.lastRoamState[i] =
6361 csrRoamStateChange( pMac, eCSR_ROAMING_STATE_SCANNING, i);
6362 smsLog( pMac, LOG3, "starting SCAN command from %d state...."
6363 " reason is %d", pCommand->u.scanCmd.lastRoamState[i],
6364 pCommand->u.scanCmd.reason );
6365 }
6366 }
6367 else
6368 {
6369 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId] =
6370 csrRoamStateChange(pMac, eCSR_ROAMING_STATE_SCANNING,
6371 pCommand->sessionId);
6372 smsLog( pMac, LOG3,
6373 "starting SCAN command from %d state.... reason is %d",
6374 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId],
6375 pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07006376 }
6377
6378 switch(pCommand->u.scanCmd.reason)
6379 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006380#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
6381 case eCsrScanGetLfrResult:
6382#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006383 case eCsrScanGetResult:
6384 case eCsrScanForCapsChange: //For cap change, LIM already save BSS description
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006385 status = csrScanRetrieveResult(pMac, pCommand);
Jeff Johnson295189b2012-06-20 16:38:30 -07006386 break;
6387 case eCsrScanSetBGScanParam:
6388 status = csrProcessSetBGScanParam(pMac, pCommand);
6389 break;
6390 case eCsrScanBGScanAbort:
6391 status = csrSetCfgBackgroundScanPeriod(pMac, 0);
6392 break;
6393 case eCsrScanBGScanEnable:
6394 status = csrSetCfgBackgroundScanPeriod(pMac, pMac->roam.configParam.bgScanInterval);
6395 break;
6396 case eCsrScanGetScanChnInfo:
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05306397 status = csrScanGetScanChannelInfo(pMac, pCommand->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07006398 break;
6399 case eCsrScanUserRequest:
6400 if(pMac->roam.configParam.fScanTwice)
6401 {
6402 //We scan 2.4 channel twice
6403 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels &&
6404 (NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList))
6405 {
6406 len = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
6407 //allocate twice the channel
Mukul Sharmaa631e892014-08-28 15:38:51 +05306408 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(len * 2);
Jeff Johnson295189b2012-06-20 16:38:30 -07006409 pChannel = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
6410 }
6411 else
6412 {
6413 //get the valid channel list to scan all.
6414 len = sizeof(pMac->roam.validChannelList);
6415
6416 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
6417 {
6418 //allocate twice the channel
6419 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(len * 2);
6420 pChannel = pMac->roam.validChannelList;
6421 }
6422 }
6423 if(NULL == newChannelInfo.ChannelList)
6424 {
6425 newChannelInfo.numOfChannels = 0;
6426 }
6427 else
6428 {
6429 j = 0;
6430 for(i = 0; i < len; i++)
6431 {
6432 newChannelInfo.ChannelList[j++] = pChannel[i];
6433 if(CSR_MAX_24GHz_CHANNEL_NUMBER >= pChannel[i])
6434 {
6435 newChannelInfo.ChannelList[j++] = pChannel[i];
6436 }
6437 }
6438 if(NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
6439 {
6440 //pChannel points to the channellist from the command, free it.
6441 vos_mem_free(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -07006442 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07006443 }
6444 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = j;
6445 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = newChannelInfo.ChannelList;
6446 }
6447 } //if(pMac->roam.configParam.fScanTwice)
6448
6449 status = csrScanChannels(pMac, pCommand);
6450
6451 break;
6452 default:
6453 status = csrScanChannels(pMac, pCommand);
6454 break;
6455 }
6456
6457 if(!HAL_STATUS_SUCCESS(status))
6458 {
6459 csrReleaseScanCommand(pMac, pCommand, eCSR_SCAN_FAILURE);
6460 }
6461
6462 return (status);
6463}
6464
6465
6466eHalStatus csrScanSetBGScanparams(tpAniSirGlobal pMac, tCsrBGScanRequest *pScanReq)
6467{
6468 eHalStatus status = eHAL_STATUS_SUCCESS;
6469 tSmeCmd *pCommand = NULL;
6470
6471 if(pScanReq)
6472 {
6473 do
6474 {
6475 pCommand = csrGetCommandBuffer(pMac);
6476 if(!pCommand)
6477 {
6478 status = eHAL_STATUS_RESOURCES;
6479 break;
6480 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306481 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006482 pCommand->command = eSmeCommandScan;
6483 pCommand->u.scanCmd.reason = eCsrScanSetBGScanParam;
6484 pCommand->u.scanCmd.callback = NULL;
6485 pCommand->u.scanCmd.pContext = NULL;
Kiet Lam64c1b492013-07-12 13:56:44 +05306486 vos_mem_copy(&pCommand->u.scanCmd.u.bgScanRequest, pScanReq, sizeof(tCsrBGScanRequest));
Jeff Johnson295189b2012-06-20 16:38:30 -07006487 //we have to do the follow
6488 if(pScanReq->ChannelInfo.numOfChannels == 0)
6489 {
6490 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
6491 }
6492 else
6493 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306494 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList
6495 = vos_mem_malloc(pScanReq->ChannelInfo.numOfChannels);
6496 if ( NULL != pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07006497 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306498 vos_mem_copy(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList,
6499 pScanReq->ChannelInfo.ChannelList,
6500 pScanReq->ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07006501 }
6502 else
6503 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006504 smsLog(pMac, LOGE, FL("ran out of memory"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006505 csrReleaseCommandScan(pMac, pCommand);
Kiet Lam64c1b492013-07-12 13:56:44 +05306506 return eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006507 }
6508 }
6509
6510 //scan req for SSID
6511 if(pScanReq->SSID.length)
6512 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306513 vos_mem_copy(pCommand->u.scanCmd.u.bgScanRequest.SSID.ssId,
6514 pScanReq->SSID.ssId, pScanReq->SSID.length);
Jeff Johnson295189b2012-06-20 16:38:30 -07006515 pCommand->u.scanCmd.u.bgScanRequest.SSID.length = pScanReq->SSID.length;
6516
6517 }
6518 pCommand->u.scanCmd.u.bgScanRequest.maxChnTime= pScanReq->maxChnTime;
6519 pCommand->u.scanCmd.u.bgScanRequest.minChnTime = pScanReq->minChnTime;
6520 pCommand->u.scanCmd.u.bgScanRequest.scanInterval = pScanReq->scanInterval;
6521
6522
6523 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
6524 if( !HAL_STATUS_SUCCESS( status ) )
6525 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006526 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006527 csrReleaseCommandScan( pMac, pCommand );
6528 break;
6529 }
6530 }while(0);
6531 }
6532
6533 return (status);
6534}
6535
6536eHalStatus csrScanBGScanAbort( tpAniSirGlobal pMac )
6537{
6538 eHalStatus status = eHAL_STATUS_SUCCESS;
6539 tSmeCmd *pCommand = NULL;
6540
6541 do
6542 {
6543 pCommand = csrGetCommandBuffer(pMac);
6544 if(!pCommand)
6545 {
6546 status = eHAL_STATUS_RESOURCES;
6547 break;
6548 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306549 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006550 pCommand->command = eSmeCommandScan;
6551 pCommand->u.scanCmd.reason = eCsrScanBGScanAbort;
6552 pCommand->u.scanCmd.callback = NULL;
6553 pCommand->u.scanCmd.pContext = NULL;
6554 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
6555 if( !HAL_STATUS_SUCCESS( status ) )
6556 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006557 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006558 csrReleaseCommandScan( pMac, pCommand );
6559 break;
6560 }
6561 }while(0);
6562
6563 return (status);
6564}
6565
6566
6567//This will enable the background scan with the non-zero interval
6568eHalStatus csrScanBGScanEnable(tpAniSirGlobal pMac)
6569{
6570 eHalStatus status = eHAL_STATUS_SUCCESS;
6571 tSmeCmd *pCommand = NULL;
6572
6573 if(pMac->roam.configParam.bgScanInterval)
6574 {
6575 do
6576 {
6577 pCommand = csrGetCommandBuffer(pMac);
6578 if(!pCommand)
6579 {
6580 status = eHAL_STATUS_RESOURCES;
6581 break;
6582 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306583 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006584 pCommand->command = eSmeCommandScan;
6585 pCommand->u.scanCmd.reason = eCsrScanBGScanEnable;
6586 pCommand->u.scanCmd.callback = NULL;
6587 pCommand->u.scanCmd.pContext = NULL;
6588 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
6589 if( !HAL_STATUS_SUCCESS( status ) )
6590 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006591 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006592 csrReleaseCommandScan( pMac, pCommand );
6593 break;
6594 }
6595 }while(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006596 }
6597 else
6598 {
Sushant Kaushikb8dbb3f2015-04-29 17:03:37 +05306599 smsLog(pMac, LOGE, FL("cannot continue because the bgscan interval is 0"));
6600 status = eHAL_STATUS_INVALID_PARAMETER;
Jeff Johnson295189b2012-06-20 16:38:30 -07006601 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006602 return (status);
6603}
6604
6605
6606eHalStatus csrScanCopyRequest(tpAniSirGlobal pMac, tCsrScanRequest *pDstReq, tCsrScanRequest *pSrcReq)
6607{
6608 eHalStatus status = eHAL_STATUS_SUCCESS;
6609 tANI_U32 len = sizeof(pMac->roam.validChannelList);
6610 tANI_U32 index = 0;
6611 tANI_U32 new_index = 0;
Manjunathappa Prakashde7b2a52014-02-28 16:59:03 -08006612 eNVChannelEnabledType NVchannel_state;
Arif Hussain6af38622014-03-12 12:39:57 -07006613 tANI_U8 ch144_support = 0;
6614
6615 ch144_support = WDA_getFwWlanFeatCaps(WLAN_CH144);
Jeff Johnson295189b2012-06-20 16:38:30 -07006616
6617 do
6618 {
6619 status = csrScanFreeRequest(pMac, pDstReq);
6620 if(HAL_STATUS_SUCCESS(status))
6621 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306622 vos_mem_copy(pDstReq, pSrcReq, sizeof(tCsrScanRequest));
Gopichand Nakkalac7b1d3e2012-12-31 14:07:19 -08006623 /* Re-initialize the pointers to NULL since we did a copy */
6624 pDstReq->pIEField = NULL;
6625 pDstReq->ChannelInfo.ChannelList = NULL;
6626 pDstReq->SSIDs.SSIDList = NULL;
6627
Jeff Johnson295189b2012-06-20 16:38:30 -07006628 if(pSrcReq->uIEFieldLen == 0)
6629 {
6630 pDstReq->pIEField = NULL;
6631 }
6632 else
6633 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306634 pDstReq->pIEField = vos_mem_malloc(pSrcReq->uIEFieldLen);
6635 if ( NULL == pDstReq->pIEField )
Jeff Johnson295189b2012-06-20 16:38:30 -07006636 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306637 status = eHAL_STATUS_FAILURE;
6638 smsLog(pMac, LOGE, FL("No memory for scanning IE fields"));
6639 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07006640 }
6641 else
6642 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306643 status = eHAL_STATUS_SUCCESS;
6644 vos_mem_copy(pDstReq->pIEField, pSrcReq->pIEField,
6645 pSrcReq->uIEFieldLen);
6646 pDstReq->uIEFieldLen = pSrcReq->uIEFieldLen;
Jeff Johnson295189b2012-06-20 16:38:30 -07006647 }
6648 }//Allocate memory for IE field
6649 {
6650 if(pSrcReq->ChannelInfo.numOfChannels == 0)
6651 {
6652 pDstReq->ChannelInfo.ChannelList = NULL;
6653 pDstReq->ChannelInfo.numOfChannels = 0;
6654 }
6655 else
6656 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306657 pDstReq->ChannelInfo.ChannelList = vos_mem_malloc(
6658 pSrcReq->ChannelInfo.numOfChannels
6659 * sizeof(*pDstReq->ChannelInfo.ChannelList));
6660 if ( NULL == pDstReq->ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07006661 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306662 status = eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006663 pDstReq->ChannelInfo.numOfChannels = 0;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306664 smsLog(pMac, LOGE, FL("No memory for scanning Channel"
6665 " List"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006666 break;
6667 }
6668
6669 if((pSrcReq->scanType == eSIR_PASSIVE_SCAN) && (pSrcReq->requestType == eCSR_SCAN_REQUEST_11D_SCAN))
6670 {
6671 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
6672 {
Arif Hussain6af38622014-03-12 12:39:57 -07006673 /* Skip CH 144 if firmware support not present */
6674 if (pSrcReq->ChannelInfo.ChannelList[index] == 144 && !ch144_support)
6675 continue;
Agarwal Ashish8bd53ae2015-06-12 18:03:45 +05306676 /* Skip channel 12 and 13 when FCC constraint is true */
6677 if ((pMac->scan.fcc_constraint) &&
6678 ((pSrcReq->ChannelInfo.ChannelList[index] ==12) ||
6679 (pSrcReq->ChannelInfo.ChannelList[index] ==13)))
6680 {
6681 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
6682 FL("Ignoring channel : %d "),
6683 pSrcReq->ChannelInfo.ChannelList[index]);
6684 continue;
6685 }
Arif Hussain6af38622014-03-12 12:39:57 -07006686
Manjunathappa Prakashde7b2a52014-02-28 16:59:03 -08006687 NVchannel_state = vos_nv_getChannelEnabledState(
6688 pSrcReq->ChannelInfo.ChannelList[index]);
6689 if ((NV_CHANNEL_ENABLE == NVchannel_state) ||
6690 (NV_CHANNEL_DFS == NVchannel_state))
6691 {
6692 pDstReq->ChannelInfo.ChannelList[new_index] =
6693 pSrcReq->ChannelInfo.ChannelList[index];
6694 new_index++;
6695 }
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306696 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006697 pDstReq->ChannelInfo.numOfChannels = new_index;
6698 }
6699 else if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
6700 {
6701 new_index = 0;
6702 pMac->roam.numValidChannels = len;
c_hpothu0d5a7352014-03-22 12:30:25 +05306703
6704 /* Since in CsrScanRequest,value of pMac->scan.nextScanID
6705 * is incremented before calling CsrScanCopyRequest, as a
6706 * result pMac->scan.nextScanID is equal to ONE for the
Abhishek Singha2649232016-01-20 15:52:05 +05306707 * first scan. If number of channels is less than
6708 * max chan for dwell time no need to skip dfs
6709 * in first scan as anyway few channels will be scanned and
6710 * it will not take much time to display results on GUI.
c_hpothu0d5a7352014-03-22 12:30:25 +05306711 */
Abhishek Singha2649232016-01-20 15:52:05 +05306712 if (((pSrcReq->ChannelInfo.numOfChannels >=
6713 pMac->roam.configParam.max_chan_for_dwell_time_cfg) &&
6714 (pMac->roam.configParam.initialScanSkipDFSCh &&
6715 1 == pMac->scan.nextScanID)) ||(pMac->miracast_mode))
c_hpothu0d5a7352014-03-22 12:30:25 +05306716 {
6717 smsLog(pMac, LOG1,
6718 FL("Initial scan, scan only non-DFS channels"));
6719
6720 for (index = 0; index < pSrcReq->ChannelInfo.
6721 numOfChannels ; index++ )
6722 {
6723 if((csrRoamIsValidChannel(pMac, pSrcReq->ChannelInfo.
6724 ChannelList[index])))
6725 {
6726 /*Skiipping DFS Channels for 1st scan */
6727 if(NV_CHANNEL_DFS ==
6728 vos_nv_getChannelEnabledState(pSrcReq->ChannelInfo.
6729 ChannelList[index]))
6730 continue ;
6731
6732 pDstReq->ChannelInfo.ChannelList[new_index] =
6733 pSrcReq->ChannelInfo.ChannelList[index];
6734 new_index++;
6735
6736 }
6737 }
6738 pMac->roam.configParam.initialScanSkipDFSCh = 0;
6739 }
6740 else
6741 {
6742 for ( index = 0; index < pSrcReq->ChannelInfo.
6743 numOfChannels ; index++ )
Jeff Johnson295189b2012-06-20 16:38:30 -07006744 {
Arif Hussain6af38622014-03-12 12:39:57 -07006745 /* Skip CH 144 if firmware support not present */
6746 if (pSrcReq->ChannelInfo.ChannelList[index] == 144 && !ch144_support)
6747 continue;
6748
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -07006749 /* Allow scan on valid channels only.
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -07006750 */
Abhishek Singh2ec36ab2014-08-07 16:14:25 +05306751 if ( ( csrRoamIsValidChannel(pMac, pSrcReq->ChannelInfo.ChannelList[index]) ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07006752 {
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05306753 if( ((pSrcReq->skipDfsChnlInP2pSearch ||
6754 (pMac->scan.fEnableDFSChnlScan ==
6755 DFS_CHNL_SCAN_DISABLED)) &&
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08006756 (NV_CHANNEL_DFS == vos_nv_getChannelEnabledState(pSrcReq->ChannelInfo.ChannelList[index])) )
Srikant Kuppa866893f2012-12-27 17:28:14 -08006757#ifdef FEATURE_WLAN_LFR
6758 /*
6759 * If LFR is requesting a contiguous scan
6760 * (i.e. numOfChannels > 1), then ignore
6761 * DFS channels.
6762 * TODO: vos_nv_getChannelEnabledState is returning
6763 * 120, 124 and 128 as non-DFS channels. Hence, the
6764 * use of direct check for channels below.
6765 */
6766 || ((eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType) &&
6767 (pSrcReq->ChannelInfo.numOfChannels > 1) &&
Santhosh Kumar Padma9ccaaff2014-07-09 19:58:12 +05306768 (CSR_IS_CHANNEL_DFS(pSrcReq->ChannelInfo.ChannelList[index])) &&
6769 !pMac->roam.configParam.allowDFSChannelRoam)
Srikant Kuppa866893f2012-12-27 17:28:14 -08006770#endif
6771 )
6772 {
6773#ifdef FEATURE_WLAN_LFR
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05306774 smsLog(pMac, LOG2,
6775 FL(" reqType=%s (%d), numOfChannels=%d,"
6776 " ignoring DFS channel %d"),
6777 sme_requestTypetoString(pSrcReq->requestType),
6778 pSrcReq->requestType,
6779 pSrcReq->ChannelInfo.numOfChannels,
6780 pSrcReq->ChannelInfo.ChannelList[index]);
Srikant Kuppa866893f2012-12-27 17:28:14 -08006781#endif
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05306782 continue;
Srikant Kuppa866893f2012-12-27 17:28:14 -08006783 }
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08006784
Jeff Johnson295189b2012-06-20 16:38:30 -07006785 pDstReq->ChannelInfo.ChannelList[new_index] =
6786 pSrcReq->ChannelInfo.ChannelList[index];
6787 new_index++;
6788 }
6789 }
c_hpothu0d5a7352014-03-22 12:30:25 +05306790 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006791 pDstReq->ChannelInfo.numOfChannels = new_index;
Srikant Kuppa866893f2012-12-27 17:28:14 -08006792#ifdef FEATURE_WLAN_LFR
Abhishek Singh2ec36ab2014-08-07 16:14:25 +05306793 if ( ( ( eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType ) ||
6794 ( eCSR_SCAN_P2P_DISCOVERY == pSrcReq->requestType ) ) &&
6795 ( 0 == pDstReq->ChannelInfo.numOfChannels ) )
Srikant Kuppa866893f2012-12-27 17:28:14 -08006796 {
6797 /*
6798 * No valid channels found in the request.
6799 * Only perform scan on the channels passed
Abhishek Singh2ec36ab2014-08-07 16:14:25 +05306800 * pSrcReq if it is a eCSR_SCAN_HO_BG_SCAN or
6801 * eCSR_SCAN_P2P_DISCOVERY.
Srikant Kuppa866893f2012-12-27 17:28:14 -08006802 * Passing 0 to LIM will trigger a scan on
6803 * all valid channels which is not desirable.
6804 */
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306805 smsLog(pMac, LOGE, FL(" no valid channels found"
6806 " (request=%d)"), pSrcReq->requestType);
Srikant Kuppa866893f2012-12-27 17:28:14 -08006807 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
6808 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306809 smsLog(pMac, LOGE, FL("pSrcReq index=%d"
6810 " channel=%d"), index,
6811 pSrcReq->ChannelInfo.ChannelList[index]);
Srikant Kuppa866893f2012-12-27 17:28:14 -08006812 }
6813 status = eHAL_STATUS_FAILURE;
6814 break;
6815 }
6816#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006817 }
6818 else
6819 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306820 smsLog(pMac, LOGE, FL("Couldn't get the valid Channel"
6821 " List, keeping requester's list"));
Kiet Lam64c1b492013-07-12 13:56:44 +05306822 vos_mem_copy(pDstReq->ChannelInfo.ChannelList,
6823 pSrcReq->ChannelInfo.ChannelList,
6824 pSrcReq->ChannelInfo.numOfChannels
6825 * sizeof(*pDstReq->ChannelInfo.ChannelList));
Jeff Johnson295189b2012-06-20 16:38:30 -07006826 pDstReq->ChannelInfo.numOfChannels = pSrcReq->ChannelInfo.numOfChannels;
6827 }
6828 }//Allocate memory for Channel List
6829 }
6830 if(pSrcReq->SSIDs.numOfSSIDs == 0)
6831 {
6832 pDstReq->SSIDs.numOfSSIDs = 0;
6833 pDstReq->SSIDs.SSIDList = NULL;
6834 }
6835 else
6836 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306837 pDstReq->SSIDs.SSIDList = vos_mem_malloc(
6838 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
6839 if ( NULL == pDstReq->SSIDs.SSIDList )
6840 status = eHAL_STATUS_FAILURE;
6841 else
6842 status = eHAL_STATUS_SUCCESS;
6843 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07006844 {
6845 pDstReq->SSIDs.numOfSSIDs = pSrcReq->SSIDs.numOfSSIDs;
Kiet Lam64c1b492013-07-12 13:56:44 +05306846 vos_mem_copy(pDstReq->SSIDs.SSIDList,
6847 pSrcReq->SSIDs.SSIDList,
6848 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
Jeff Johnson295189b2012-06-20 16:38:30 -07006849 }
6850 else
6851 {
6852 pDstReq->SSIDs.numOfSSIDs = 0;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306853 smsLog(pMac, LOGE, FL("No memory for scanning SSID List"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006854 break;
6855 }
6856 }//Allocate memory for SSID List
Jeff Johnson295189b2012-06-20 16:38:30 -07006857 pDstReq->p2pSearch = pSrcReq->p2pSearch;
Jeff Johnsone7245742012-09-05 17:12:55 -07006858 pDstReq->skipDfsChnlInP2pSearch = pSrcReq->skipDfsChnlInP2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07006859
6860 }
6861 }while(0);
6862
6863 if(!HAL_STATUS_SUCCESS(status))
6864 {
6865 csrScanFreeRequest(pMac, pDstReq);
6866 }
6867
6868 return (status);
6869}
6870
6871
6872eHalStatus csrScanFreeRequest(tpAniSirGlobal pMac, tCsrScanRequest *pReq)
6873{
Jeff Johnson295189b2012-06-20 16:38:30 -07006874
6875 if(pReq->ChannelInfo.ChannelList)
6876 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306877 vos_mem_free(pReq->ChannelInfo.ChannelList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006878 pReq->ChannelInfo.ChannelList = NULL;
6879 }
6880 pReq->ChannelInfo.numOfChannels = 0;
6881 if(pReq->pIEField)
6882 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306883 vos_mem_free(pReq->pIEField);
Jeff Johnson295189b2012-06-20 16:38:30 -07006884 pReq->pIEField = NULL;
6885 }
6886 pReq->uIEFieldLen = 0;
6887 if(pReq->SSIDs.SSIDList)
6888 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306889 vos_mem_free(pReq->SSIDs.SSIDList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006890 pReq->SSIDs.SSIDList = NULL;
6891 }
6892 pReq->SSIDs.numOfSSIDs = 0;
6893
Kiet Lam64c1b492013-07-12 13:56:44 +05306894 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07006895}
6896
6897
6898void csrScanCallCallback(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
6899{
6900 if(pCommand->u.scanCmd.callback)
6901 {
Ratheesh S Pece1f832015-07-25 15:50:25 +05306902 if (pCommand->u.scanCmd.abortScanIndication){
6903 smsLog( pMac, LOG1, FL("scanDone due to abort"));
6904 scanStatus = eCSR_SCAN_ABORT;
6905 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006906// sme_ReleaseGlobalLock( &pMac->sme );
6907 pCommand->u.scanCmd.callback(pMac, pCommand->u.scanCmd.pContext, pCommand->u.scanCmd.scanID, scanStatus);
6908// sme_AcquireGlobalLock( &pMac->sme );
6909 } else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006910 smsLog( pMac, LOG2, "%s:%d - Callback NULL!!!", __func__, __LINE__);
Jeff Johnson295189b2012-06-20 16:38:30 -07006911 }
6912}
6913
6914
6915void csrScanStopTimers(tpAniSirGlobal pMac)
6916{
Jeff Johnson295189b2012-06-20 16:38:30 -07006917 csrScanStopIdleScanTimer(pMac);
6918 csrScanStopGetResultTimer(pMac);
6919}
6920
6921
6922eHalStatus csrScanStartGetResultTimer(tpAniSirGlobal pMac)
6923{
6924 eHalStatus status;
6925
6926 if(pMac->scan.fScanEnable)
6927 {
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306928 status = vos_timer_start(&pMac->scan.hTimerGetResult, CSR_SCAN_GET_RESULT_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006929 }
6930 else
6931 {
6932 status = eHAL_STATUS_FAILURE;
6933 }
6934
6935 return (status);
6936}
6937
6938
6939eHalStatus csrScanStopGetResultTimer(tpAniSirGlobal pMac)
6940{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306941 return (vos_timer_stop(&pMac->scan.hTimerGetResult));
Jeff Johnson295189b2012-06-20 16:38:30 -07006942}
6943
6944
6945void csrScanGetResultTimerHandler(void *pv)
6946{
6947 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6948
6949 csrScanRequestResult(pMac);
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306950
6951 vos_timer_start(&pMac->scan.hTimerGetResult, CSR_SCAN_GET_RESULT_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006952}
6953
6954#ifdef WLAN_AP_STA_CONCURRENCY
6955static void csrStaApConcTimerHandler(void *pv)
6956{
6957 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6958 tListElem *pEntry;
6959 tSmeCmd *pScanCmd;
6960
6961 csrLLLock(&pMac->scan.scanCmdPendingList);
6962
6963 if ( NULL != ( pEntry = csrLLPeekHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) ) )
6964 {
6965 tCsrScanRequest scanReq;
6966 tSmeCmd *pSendScanCmd = NULL;
6967 tANI_U8 numChn = 0;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006968 tANI_U8 nNumChanCombinedConc = 0;
Vinay Malekal05fdc812012-12-17 13:04:30 -08006969 tANI_U8 i, j;
Jeff Johnson295189b2012-06-20 16:38:30 -07006970 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
6971 tANI_U8 channelToScan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
6972 eHalStatus status;
6973
Jeff Johnson295189b2012-06-20 16:38:30 -07006974 pScanCmd = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
6975 numChn = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08006976
6977 /* if any session is connected and the number of channels to scan is
6978 * greater than 1 then split the scan into multiple scan operations
6979 * on each individual channel else continue to perform scan on all
6980 * specified channels */
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08006981
6982 /* split scan if number of channels to scan is greater than 1 and
6983 * any one of the following:
6984 * - STA session is connected and the scan is not a P2P search
6985 * - any P2P session is connected
Srikant Kuppa866893f2012-12-27 17:28:14 -08006986 * Do not split scans if no concurrent infra connections are
6987 * active and if the scan is a BG scan triggered by LFR (OR)
6988 * any scan if LFR is in the middle of a BG scan. Splitting
6989 * the scan is delaying the time it takes for LFR to find
6990 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08006991 */
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006992
6993 if((csrIsStaSessionConnected(pMac) &&
6994 !csrIsP2pSessionConnected(pMac)))
6995 {
6996 nNumChanCombinedConc = pMac->roam.configParam.nNumStaChanCombinedConc;
6997 }
6998 else if(csrIsP2pSessionConnected(pMac))
6999 {
7000 nNumChanCombinedConc = pMac->roam.configParam.nNumP2PChanCombinedConc;
7001 }
7002
7003 if ( (numChn > nNumChanCombinedConc) &&
Srikant Kuppa866893f2012-12-27 17:28:14 -08007004 ((csrIsStaSessionConnected(pMac) &&
7005#ifdef FEATURE_WLAN_LFR
7006 (csrIsConcurrentInfraConnected(pMac) ||
7007 ((pScanCmd->u.scanCmd.reason != eCsrScanBgScan) &&
7008 (pMac->roam.neighborRoamInfo.neighborRoamState !=
7009 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
7010#endif
7011 (pScanCmd->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08007012 (csrIsP2pSessionConnected(pMac))))
Jeff Johnson295189b2012-06-20 16:38:30 -07007013 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307014 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007015
7016 pSendScanCmd = csrGetCommandBuffer(pMac); //optimize this to use 2 command buffer only
7017 if (!pSendScanCmd)
7018 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007019 smsLog( pMac, LOGE, FL(" Failed to get Queue command buffer") );
Jeff Johnson295189b2012-06-20 16:38:30 -07007020 csrLLUnlock(&pMac->scan.scanCmdPendingList);
7021 return;
7022 }
7023 pSendScanCmd->command = pScanCmd->command;
7024 pSendScanCmd->sessionId = pScanCmd->sessionId;
7025 pSendScanCmd->u.scanCmd.callback = NULL;
7026 pSendScanCmd->u.scanCmd.pContext = pScanCmd->u.scanCmd.pContext;
7027 pSendScanCmd->u.scanCmd.reason = pScanCmd->u.scanCmd.reason;
7028 pSendScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
7029
Madan Mohan Koyyalamudiaf2a8b92012-10-09 14:58:07 -07007030 /* First copy all the parameters to local variable of scan request */
7031 csrScanCopyRequest(pMac, &scanReq, &pScanCmd->u.scanCmd.u.scanRequest);
7032
7033 /* Now modify the elements of local var scan request required to be modified for split scan */
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08007034 if(scanReq.ChannelInfo.ChannelList != NULL)
7035 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307036 vos_mem_free(scanReq.ChannelInfo.ChannelList);
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08007037 scanReq.ChannelInfo.ChannelList = NULL;
7038 }
7039
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07007040 pChnInfo->numOfChannels = nNumChanCombinedConc;
Kiet Lam64c1b492013-07-12 13:56:44 +05307041 vos_mem_copy(&channelToScan[0],
7042 &pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[0],
7043 pChnInfo->numOfChannels * sizeof(tANI_U8));//just send one channel
Jeff Johnson295189b2012-06-20 16:38:30 -07007044 pChnInfo->ChannelList = &channelToScan[0];
7045
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07007046 for (i = 0, j = nNumChanCombinedConc; i < (numChn-nNumChanCombinedConc); i++, j++)
Jeff Johnson295189b2012-06-20 16:38:30 -07007047 {
7048 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] =
Vinay Malekal05fdc812012-12-17 13:04:30 -08007049 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[j]; //Move all the channels one step
Jeff Johnson295189b2012-06-20 16:38:30 -07007050 }
7051
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07007052 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = numChn - nNumChanCombinedConc; //reduce outstanding # of channels to be scanned
Jeff Johnson295189b2012-06-20 16:38:30 -07007053
7054 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
c_hpothudbefd3e2014-04-28 15:59:47 +05307055
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -07007056 //Use concurrency values for min/maxChnTime.
7057 //We know csrIsAnySessionConnected(pMac) returns TRUE here
7058 csrSetDefaultScanTiming(pMac, scanReq.scanType, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07007059
7060 status = csrScanCopyRequest(pMac, &pSendScanCmd->u.scanCmd.u.scanRequest, &scanReq);
7061 if(!HAL_STATUS_SUCCESS(status))
7062 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007063 smsLog( pMac, LOGE, FL(" Failed to get copy csrScanRequest = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07007064 csrLLUnlock(&pMac->scan.scanCmdPendingList);
7065 return;
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08007066 }
7067 /* Clean the local scan variable */
7068 scanReq.ChannelInfo.ChannelList = NULL;
7069 scanReq.ChannelInfo.numOfChannels = 0;
7070 csrScanFreeRequest(pMac, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07007071 }
7072 else
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08007073 {
7074 /* no active connected session present or numChn == 1
7075 * scan all remaining channels */
Jeff Johnson295189b2012-06-20 16:38:30 -07007076 pSendScanCmd = pScanCmd;
7077 //remove this command from pending list
7078 if (csrLLRemoveHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) == NULL)
7079 { //In case between PeekHead and here, the entry got removed by another thread.
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007080 smsLog( pMac, LOGE, FL(" Failed to remove entry from scanCmdPendingList"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007081 }
7082
7083 }
7084 csrQueueSmeCommand(pMac, pSendScanCmd, eANI_BOOLEAN_FALSE);
7085
7086 }
7087
Jeff Johnson295189b2012-06-20 16:38:30 -07007088 csrLLUnlock(&pMac->scan.scanCmdPendingList);
7089
7090}
7091#endif
7092
Jeff Johnson295189b2012-06-20 16:38:30 -07007093//This function returns the maximum time a BSS is allowed in the scan result.
7094//The time varies base on connection and power saving factors.
7095//Not connected, No PS
7096//Not connected, with PS
7097//Connected w/o traffic, No PS
7098//Connected w/o traffic, with PS
7099//Connected w/ traffic, no PS -- Not supported
7100//Connected w/ traffic, with PS -- Not supported
7101//the return unit is in seconds.
7102tANI_U32 csrScanGetAgeOutTime(tpAniSirGlobal pMac)
7103{
7104 tANI_U32 nRet;
7105
7106 if(pMac->scan.nAgingCountDown)
7107 {
7108 //Calculate what should be the timeout value for this
7109 nRet = pMac->scan.nLastAgeTimeOut * pMac->scan.nAgingCountDown;
7110 pMac->scan.nAgingCountDown--;
7111 }
7112 else
7113 {
7114 if( csrIsAllSessionDisconnected( pMac ) )
7115 {
7116 if(pmcIsPowerSaveEnabled(pMac, ePMC_IDLE_MODE_POWER_SAVE))
7117 {
7118 nRet = pMac->roam.configParam.scanAgeTimeNCPS;
7119 }
7120 else
7121 {
7122 nRet = pMac->roam.configParam.scanAgeTimeNCNPS;
7123 }
7124 }
7125 else
7126 {
7127 if(pmcIsPowerSaveEnabled(pMac, ePMC_BEACON_MODE_POWER_SAVE))
7128 {
7129 nRet = pMac->roam.configParam.scanAgeTimeCPS;
7130 }
7131 else
7132 {
7133 nRet = pMac->roam.configParam.scanAgeTimeCNPS;
7134 }
7135 }
7136 //If state-change causing aging time out change, we want to delay it somewhat to avoid
7137 //unnecessary removal of BSS. This is mostly due to transition from connect to disconnect.
7138 if(pMac->scan.nLastAgeTimeOut > nRet)
7139 {
7140 if(nRet)
7141 {
7142 pMac->scan.nAgingCountDown = (pMac->scan.nLastAgeTimeOut / nRet);
7143 }
7144 pMac->scan.nLastAgeTimeOut = nRet;
7145 nRet *= pMac->scan.nAgingCountDown;
7146 }
7147 else
7148 {
7149 pMac->scan.nLastAgeTimeOut = nRet;
7150 }
7151 }
7152
7153 return (nRet);
7154}
7155
Deepthi Gowri6a08e312016-03-31 19:10:14 +05307156static void csrPurgeScanResultByAge(void *pv)
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08007157{
7158 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
7159 tListElem *pEntry, *tmpEntry;
7160 tCsrScanResult *pResult;
Deepthi Gowri4480a3f2016-05-18 19:30:17 +05307161 v_TIME_t ageOutTime =
7162 (v_TIME_t)(pMac->scan.scanResultCfgAgingTime * SYSTEM_TIME_SEC_TO_MSEC);
7163 v_TIME_t curTime = vos_timer_get_system_time();
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08007164
7165 csrLLLock(&pMac->scan.scanResultList);
7166 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
Deepthi Gowri6a08e312016-03-31 19:10:14 +05307167 smsLog(pMac, LOG1, FL("Ageout time=%lu"),ageOutTime);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08007168 while( pEntry )
7169 {
7170 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
7171 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
7172 if((curTime - pResult->Result.BssDescriptor.nReceivedTime) > ageOutTime)
7173 {
Deepthi Gowri50e2fa52016-03-17 15:30:53 +05307174 smsLog(pMac, LOG1, FL("age out due to time out for BSSID" MAC_ADDRESS_STR),
7175 MAC_ADDR_ARRAY(pResult->Result.BssDescriptor.bssId));
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08007176 csrScanAgeOutBss(pMac, pResult);
7177 }
7178 pEntry = tmpEntry;
7179 }
7180 csrLLUnlock(&pMac->scan.scanResultList);
7181}
Jeff Johnson295189b2012-06-20 16:38:30 -07007182
7183eHalStatus csrScanStartIdleScanTimer(tpAniSirGlobal pMac, tANI_U32 interval)
7184{
7185 eHalStatus status;
7186
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007187 smsLog(pMac, LOG1, " csrScanStartIdleScanTimer");
Jeff Johnson295189b2012-06-20 16:38:30 -07007188 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) && interval)
7189 {
7190 pMac->scan.nIdleScanTimeGap += interval;
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05307191 vos_timer_stop(&pMac->scan.hTimerIdleScan);
7192 status = vos_timer_start(&pMac->scan.hTimerIdleScan, interval/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07007193 if( !HAL_STATUS_SUCCESS(status) )
7194 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007195 smsLog(pMac, LOGE, " Fail to start Idle scan timer. status = %d interval = %d", status, interval);
Jeff Johnson295189b2012-06-20 16:38:30 -07007196 //This should not happen but set the flag to restart when ready
7197 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7198 }
7199 }
7200 else
7201 {
7202 if( pMac->scan.fScanEnable && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) )
7203 {
7204 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7205 }
7206 status = eHAL_STATUS_FAILURE;
7207 }
7208
7209 return (status);
7210}
7211
7212
7213eHalStatus csrScanStopIdleScanTimer(tpAniSirGlobal pMac)
7214{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05307215 return (vos_timer_stop(&pMac->scan.hTimerIdleScan));
Jeff Johnson295189b2012-06-20 16:38:30 -07007216}
7217
7218
7219//Stop CSR from asking for IMPS, This function doesn't disable IMPS from CSR
7220void csrScanSuspendIMPS( tpAniSirGlobal pMac )
7221{
7222 csrScanCancelIdleScan(pMac);
7223}
7224
7225
7226//Start CSR from asking for IMPS. This function doesn't trigger CSR to request entering IMPS
7227//because IMPS maybe disabled.
7228void csrScanResumeIMPS( tpAniSirGlobal pMac )
7229{
7230 csrScanStartIdleScan( pMac );
7231}
7232
7233
7234void csrScanIMPSCallback(void *callbackContext, eHalStatus status)
7235{
7236 tpAniSirGlobal pMac = PMAC_STRUCT( callbackContext );
7237
7238 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
7239 {
7240 if(pMac->roam.configParam.IsIdleScanEnabled)
7241 {
7242 if(HAL_STATUS_SUCCESS(status))
7243 {
7244 if(csrIsAllSessionDisconnected(pMac) && !csrIsRoamCommandWaiting(pMac))
7245 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007246 smsLog(pMac, LOGW, FL("starts idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007247 csrScanAllChannels(pMac, eCSR_SCAN_IDLE_MODE_SCAN);
7248 }
7249 else
7250 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007251 smsLog(pMac, LOGW, FL("cannot start idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007252 //even though we are in timer handle, calling stop timer will make sure the timer
7253 //doesn't get to restart.
7254 csrScanStopIdleScanTimer(pMac);
7255 }
7256 }
7257 else
7258 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007259 smsLog(pMac, LOGE, FL("sees not success status (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07007260 }
7261 }
7262 else
7263 {//we might need another flag to check if CSR needs to request imps at all
7264
7265 tANI_U32 nTime = 0;
7266
7267 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_FALSE;
7268 if(!HAL_STATUS_SUCCESS(csrScanTriggerIdleScan(pMac, &nTime)))
7269 {
7270 csrScanStartIdleScanTimer(pMac, nTime);
7271 }
7272 }
7273 }
7274}
7275
7276
Rashmi Ramanna68b309c2014-05-20 11:52:22 +05307277//Param: pTimeInterval -- Caller allocated memory in return, if failed, to specify the nxt time interval for
Jeff Johnson295189b2012-06-20 16:38:30 -07007278//idle scan timer interval
7279//Return: Not success -- meaning it cannot start IMPS, caller needs to start a timer for idle scan
7280eHalStatus csrScanTriggerIdleScan(tpAniSirGlobal pMac, tANI_U32 *pTimeInterval)
7281{
7282 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
7283
7284 //Do not trigger IMPS in case of concurrency
Agarwal Ashish5974ed32014-06-16 16:59:54 +05307285 if (vos_concurrent_open_sessions_running() &&
7286 csrIsAnySessionInConnectState(pMac))
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007287 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007288 smsLog( pMac, LOG1, FL("Cannot request IMPS because Concurrent Sessions Running") );
Jeff Johnson295189b2012-06-20 16:38:30 -07007289 return (status);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007290 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007291
7292 if(pTimeInterval)
7293 {
7294 *pTimeInterval = 0;
7295 }
7296
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007297 smsLog(pMac, LOG3, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007298 if( smeCommandPending( pMac ) )
7299 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007300 smsLog( pMac, LOG1, FL(" Cannot request IMPS because command pending") );
Jeff Johnson295189b2012-06-20 16:38:30 -07007301 //Not to enter IMPS because more work to do
7302 if(pTimeInterval)
7303 {
7304 *pTimeInterval = 0;
7305 }
7306 //restart when ready
7307 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7308
7309 return (status);
7310 }
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07007311 if (IsPmcImpsReqFailed (pMac))
7312 {
7313 if(pTimeInterval)
7314 {
7315 *pTimeInterval = 1000000; //usec
7316 }
7317 //restart when ready
7318 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07007319
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07007320 return status;
7321 }
Rashmi Ramanna68b309c2014-05-20 11:52:22 +05307322
7323 if ( !pMac->deferImps && pMac->fDeferIMPSTime )
7324 {
7325 smsLog( pMac, LOG1, FL("Defer IMPS for %dms as command processed"),
7326 pMac->fDeferIMPSTime);
Girish Gowli4f3775a2014-05-30 17:17:08 +05307327 if(pTimeInterval)
7328 {
7329 *pTimeInterval = pMac->fDeferIMPSTime * 1000; //usec
7330 }
Rashmi Ramanna68b309c2014-05-20 11:52:22 +05307331 pMac->deferImps = eANI_BOOLEAN_TRUE;
7332 return status;
7333 }
7334
Jeff Johnson295189b2012-06-20 16:38:30 -07007335 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
7336 /*&& pMac->roam.configParam.impsSleepTime*/)
7337 {
7338 //Stop get result timer because idle scan gets scan result out of PE
7339 csrScanStopGetResultTimer(pMac);
7340 if(pTimeInterval)
7341 {
7342 *pTimeInterval = pMac->roam.configParam.impsSleepTime;
7343 }
7344 //pmcRequestImps take a period in millisecond unit.
7345 status = pmcRequestImps(pMac, pMac->roam.configParam.impsSleepTime / PAL_TIMER_TO_MS_UNIT, csrScanIMPSCallback, pMac);
7346 if(!HAL_STATUS_SUCCESS(status))
7347 {
7348 if(eHAL_STATUS_PMC_ALREADY_IN_IMPS != status)
7349 {
7350 //Do restart the timer if CSR thinks it cannot do IMPS
7351 if( !csrCheckPSReady( pMac ) )
7352 {
7353 if(pTimeInterval)
7354 {
7355 *pTimeInterval = 0;
7356 }
7357 //Set the restart flag to true because that idle scan
7358 //can be restarted even though the timer will not be running
7359 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7360 }
7361 else
7362 {
7363 //For not now, we do a quicker retry
7364 if(pTimeInterval)
7365 {
7366 *pTimeInterval = CSR_IDLE_SCAN_WAIT_TIME;
7367 }
7368 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007369 smsLog(pMac, LOGW, FL("call pmcRequestImps and it returns status code (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07007370 }
7371 else
7372 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007373 smsLog(pMac, LOGW, FL("already in IMPS"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007374 //Since CSR is the only module to request for IMPS. If it is already in IMPS, CSR assumes
7375 //the callback will be called in the future. Should not happen though.
7376 status = eHAL_STATUS_SUCCESS;
7377 pMac->scan.nIdleScanTimeGap = 0;
7378 }
7379 }
7380 else
7381 {
7382 //requested so let's reset the value
7383 pMac->scan.nIdleScanTimeGap = 0;
7384 }
7385 }
7386
7387 return (status);
7388}
7389
7390
7391eHalStatus csrScanStartIdleScan(tpAniSirGlobal pMac)
7392{
7393 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
7394 tANI_U32 nTime = 0;
7395
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007396 smsLog(pMac, LOGW, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007397 if(pMac->roam.configParam.IsIdleScanEnabled)
7398 {
7399 //stop bg scan first
7400 csrScanBGScanAbort(pMac);
7401 //Stop get result timer because idle scan gets scan result out of PE
7402 csrScanStopGetResultTimer(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07007403 }
7404 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_FALSE;
7405 status = csrScanTriggerIdleScan(pMac, &nTime);
7406 if(!HAL_STATUS_SUCCESS(status))
7407 {
7408 csrScanStartIdleScanTimer(pMac, nTime);
7409 }
7410
7411 return (status);
7412}
7413
7414
7415void csrScanCancelIdleScan(tpAniSirGlobal pMac)
7416{
7417 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
7418 {
Agarwal Ashish5974ed32014-06-16 16:59:54 +05307419 if (vos_concurrent_open_sessions_running()) {
Jeff Johnson295189b2012-06-20 16:38:30 -07007420 return;
7421 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007422 smsLog(pMac, LOG1, " csrScanCancelIdleScan");
Jeff Johnson295189b2012-06-20 16:38:30 -07007423 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_TRUE;
7424 //Set the restart flag in case later on it is uncancelled
7425 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7426 csrScanStopIdleScanTimer(pMac);
7427 csrScanRemoveNotRoamingScanCommand(pMac);
7428 }
7429}
7430
7431
7432void csrScanIdleScanTimerHandler(void *pv)
7433{
7434 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
7435 eHalStatus status;
7436 tANI_U32 nTime = 0;
7437
7438 smsLog(pMac, LOGW, " csrScanIdleScanTimerHandler called ");
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07007439 pmcResetImpsFailStatus (pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07007440 status = csrScanTriggerIdleScan(pMac, &nTime);
7441 if(!HAL_STATUS_SUCCESS(status) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan))
7442 {
7443 //Check whether it is time to actually do an idle scan
7444 if(pMac->scan.nIdleScanTimeGap >= pMac->roam.configParam.impsSleepTime)
7445 {
7446 pMac->scan.nIdleScanTimeGap = 0;
7447 csrScanIMPSCallback(pMac, eHAL_STATUS_SUCCESS);
7448 }
7449 else
7450 {
7451 csrScanStartIdleScanTimer(pMac, nTime);
7452 }
7453 }
Rashmi Ramanna68b309c2014-05-20 11:52:22 +05307454 if(pMac->deferImps)
7455 {
7456 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7457 pMac->deferImps = eANI_BOOLEAN_FALSE;
7458 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007459}
7460
7461
7462
7463
7464tANI_BOOLEAN csrScanRemoveNotRoamingScanCommand(tpAniSirGlobal pMac)
7465{
7466 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
7467 tListElem *pEntry, *pEntryTmp;
7468 tSmeCmd *pCommand;
7469 tDblLinkList localList;
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307470 tDblLinkList *pCmdList;
Jeff Johnson295189b2012-06-20 16:38:30 -07007471
7472 vos_mem_zero(&localList, sizeof(tDblLinkList));
7473 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
7474 {
7475 smsLog(pMac, LOGE, FL(" failed to open list"));
7476 return fRet;
7477 }
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307478 if (!pMac->fScanOffload)
7479 pCmdList = &pMac->sme.smeCmdPendingList;
7480 else
7481 pCmdList = &pMac->sme.smeScanCmdPendingList;
Jeff Johnson295189b2012-06-20 16:38:30 -07007482
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307483 csrLLLock(pCmdList);
7484 pEntry = csrLLPeekHead(pCmdList, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007485 while(pEntry)
7486 {
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307487 pEntryTmp = csrLLNext(pCmdList, pEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007488 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7489 if( eSmeCommandScan == pCommand->command )
7490 {
7491 switch( pCommand->u.scanCmd.reason )
7492 {
7493 case eCsrScanIdleScan:
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307494 if( csrLLRemoveEntry(pCmdList, pEntry, LL_ACCESS_NOLOCK) )
Jeff Johnson295189b2012-06-20 16:38:30 -07007495 {
7496 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
7497 }
7498 fRet = eANI_BOOLEAN_TRUE;
7499 break;
7500
7501 default:
7502 break;
7503 } //switch
7504 }
7505 pEntry = pEntryTmp;
7506 }
7507
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307508 csrLLUnlock(pCmdList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007509
7510 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
7511 {
7512 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7513 csrReleaseCommandScan( pMac, pCommand );
7514 }
7515
7516 csrLLClose(&localList);
7517
7518 return (fRet);
7519}
7520
7521
7522tANI_BOOLEAN csrScanRemoveFreshScanCommand(tpAniSirGlobal pMac, tANI_U8 sessionId)
7523{
7524 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
7525 tListElem *pEntry, *pEntryTmp;
7526 tSmeCmd *pCommand;
7527 tDblLinkList localList;
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307528 tDblLinkList *pCmdList;
Jeff Johnson295189b2012-06-20 16:38:30 -07007529
7530 vos_mem_zero(&localList, sizeof(tDblLinkList));
7531 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
7532 {
7533 smsLog(pMac, LOGE, FL(" failed to open list"));
7534 return fRet;
7535 }
7536
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307537 if (!pMac->fScanOffload)
7538 pCmdList = &pMac->sme.smeCmdPendingList;
7539 else
7540 pCmdList = &pMac->sme.smeScanCmdPendingList;
7541
7542 csrLLLock(pCmdList);
7543 pEntry = csrLLPeekHead(pCmdList, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007544 while(pEntry)
7545 {
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307546 pEntryTmp = csrLLNext(pCmdList, pEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007547 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7548 if( (eSmeCommandScan == pCommand->command) && (sessionId == pCommand->sessionId) )
7549 {
7550 switch(pCommand->u.scanCmd.reason)
7551 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07007552#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
7553 case eCsrScanGetLfrResult:
7554#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07007555 case eCsrScanGetResult:
7556 case eCsrScanSetBGScanParam:
7557 case eCsrScanBGScanAbort:
7558 case eCsrScanBGScanEnable:
7559 case eCsrScanGetScanChnInfo:
7560 break;
7561 default:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007562 smsLog (pMac, LOGW, "%s: -------- abort scan command reason = %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007563 __func__, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07007564 //The rest are fresh scan requests
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307565 if( csrLLRemoveEntry(pCmdList, pEntry, LL_ACCESS_NOLOCK) )
Jeff Johnson295189b2012-06-20 16:38:30 -07007566 {
7567 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
7568 }
7569 fRet = eANI_BOOLEAN_TRUE;
7570 break;
7571 }
7572 }
7573 pEntry = pEntryTmp;
7574 }
7575
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307576 csrLLUnlock(pCmdList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007577
7578 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
7579 {
7580 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7581 if (pCommand->u.scanCmd.callback)
7582 {
7583 /* User scan request is pending,
7584 * send response with status eCSR_SCAN_ABORT*/
7585 pCommand->u.scanCmd.callback(pMac,
7586 pCommand->u.scanCmd.pContext,
7587 pCommand->u.scanCmd.scanID,
7588 eCSR_SCAN_ABORT);
7589 }
7590 csrReleaseCommandScan( pMac, pCommand );
7591 }
7592 csrLLClose(&localList);
7593
7594 return (fRet);
7595}
7596
7597
7598void csrReleaseScanCommand(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
7599{
7600 eCsrScanReason reason = pCommand->u.scanCmd.reason;
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307601 tANI_BOOLEAN status;
7602
7603 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07007604 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307605 tANI_U32 i;
7606 for(i = 0; i < CSR_ROAM_SESSION_MAX; i++)
7607 csrRoamStateChange(pMac, pCommand->u.scanCmd.lastRoamState[i], i);
7608 }
7609 else
7610 {
7611 csrRoamStateChange(pMac,
7612 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId],
7613 pCommand->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07007614 }
7615
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307616 csrScanCallCallback(pMac, pCommand, scanStatus);
Jeff Johnson295189b2012-06-20 16:38:30 -07007617
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007618 smsLog(pMac, LOG3, " Remove Scan command reason = %d", reason);
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307619 if (pMac->fScanOffload)
7620 {
7621 status = csrLLRemoveEntry(&pMac->sme.smeScanCmdActiveList,
7622 &pCommand->Link, LL_ACCESS_LOCK);
7623 }
7624 else
7625 {
7626 status = csrLLRemoveEntry(&pMac->sme.smeCmdActiveList,
7627 &pCommand->Link, LL_ACCESS_LOCK);
7628 }
7629
7630 if(status)
Jeff Johnson295189b2012-06-20 16:38:30 -07007631 {
7632 csrReleaseCommandScan( pMac, pCommand );
7633 }
7634 else
7635 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307636 smsLog(pMac, LOGE,
7637 " ********csrReleaseScanCommand cannot release command reason %d",
7638 pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07007639 }
7640}
7641
7642
7643eHalStatus csrScanGetPMKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
7644 tPmkidCandidateInfo *pPmkidList, tANI_U32 *pNumItems )
7645{
7646 eHalStatus status = eHAL_STATUS_SUCCESS;
7647 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
7648
Jeff Johnson32d95a32012-09-10 13:15:23 -07007649 if(!pSession)
7650 {
7651 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
7652 return eHAL_STATUS_FAILURE;
7653 }
7654
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007655 smsLog(pMac, LOGW, " pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07007656 csrResetPMKIDCandidateList(pMac, sessionId);
7657 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
7658 {
7659 tCsrScanResultFilter *pScanFilter;
7660 tCsrScanResultInfo *pScanResult;
7661 tScanResultHandle hBSSList;
7662 tANI_U32 nItems = *pNumItems;
7663
7664 *pNumItems = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05307665 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
7666 if ( NULL == pScanFilter )
7667 status = eHAL_STATUS_FAILURE;
7668 else
Jeff Johnson295189b2012-06-20 16:38:30 -07007669 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307670 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007671 //Here is the profile we need to connect to
7672 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
7673 if(HAL_STATUS_SUCCESS(status))
7674 {
7675 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
7676 if(HAL_STATUS_SUCCESS(status))
7677 {
7678 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumPmkidCandidate < nItems))
7679 {
7680 //NumPmkidCandidate adds up here
7681 csrProcessBSSDescForPMKIDList(pMac, &pScanResult->BssDescriptor,
7682 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
7683 }
7684 if(pSession->NumPmkidCandidate)
7685 {
7686 *pNumItems = pSession->NumPmkidCandidate;
Kiet Lam64c1b492013-07-12 13:56:44 +05307687 vos_mem_copy(pPmkidList, pSession->PmkidCandidateInfo,
7688 pSession->NumPmkidCandidate * sizeof(tPmkidCandidateInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07007689 }
7690 csrScanResultPurge(pMac, hBSSList);
7691 }//Have scan result
7692 csrFreeScanFilter(pMac, pScanFilter);
7693 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307694 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07007695 }
7696 }
7697
7698 return (status);
7699}
7700
7701
7702
7703#ifdef FEATURE_WLAN_WAPI
7704eHalStatus csrScanGetBKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
7705 tBkidCandidateInfo *pBkidList, tANI_U32 *pNumItems )
7706{
7707 eHalStatus status = eHAL_STATUS_SUCCESS;
7708 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
7709
Jeff Johnson32d95a32012-09-10 13:15:23 -07007710 if(!pSession)
7711 {
7712 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
7713 return eHAL_STATUS_FAILURE;
7714 }
7715
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007716 smsLog(pMac, LOGW, " pMac->scan.NumBkidCandidate = %d", pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07007717 csrResetBKIDCandidateList(pMac, sessionId);
7718 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
7719 {
7720 tCsrScanResultFilter *pScanFilter;
7721 tCsrScanResultInfo *pScanResult;
7722 tScanResultHandle hBSSList;
7723 tANI_U32 nItems = *pNumItems;
7724 *pNumItems = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05307725 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
7726 if ( NULL == pScanFilter )
7727 status = eHAL_STATUS_FAILURE;
7728 else
Jeff Johnson295189b2012-06-20 16:38:30 -07007729 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307730 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007731 //Here is the profile we need to connect to
7732 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
7733 if(HAL_STATUS_SUCCESS(status))
7734 {
7735 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
7736 if(HAL_STATUS_SUCCESS(status))
7737 {
7738 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumBkidCandidate < nItems))
7739 {
7740 //pMac->scan.NumBkidCandidate adds up here
7741 csrProcessBSSDescForBKIDList(pMac, &pScanResult->BssDescriptor,
7742 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
7743
7744 }
7745 if(pSession->NumBkidCandidate)
7746 {
7747 *pNumItems = pSession->NumBkidCandidate;
Kiet Lam64c1b492013-07-12 13:56:44 +05307748 vos_mem_copy(pBkidList, pSession->BkidCandidateInfo, pSession->NumBkidCandidate * sizeof(tBkidCandidateInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07007749 }
7750 csrScanResultPurge(pMac, hBSSList);
7751 }//Have scan result
7752 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307753 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07007754 }
7755 }
7756
7757 return (status);
7758}
7759#endif /* FEATURE_WLAN_WAPI */
7760
Selvaraj, Sridhar32417ed2016-06-22 15:19:12 +05307761/**
7762 * csr_scan_request_set_chan_time() - Populate max and min
7763 * channel time in Scan request
7764 * @pMac - pointer to mac context
7765 * @pScanCmd - pointer to the Scan command
7766 *
7767 * Return - None
7768 */
7769#ifndef QCA_WIFI_ISOC
7770static void csr_scan_request_set_chan_time(tpAniSirGlobal pMac,
7771 tSmeCmd *pScanCmd)
7772{
7773 if (pMac->roam.neighborRoamInfo.handoffReqInfo.src
7774 == FASTREASSOC) {
7775 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime
7776 = MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL_FASTREASSOC;
7777 pScanCmd->u.scanCmd.u.scanRequest.minChnTime
7778 = MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL_FASTREASSOC;
7779 pMac->roam.neighborRoamInfo.handoffReqInfo.src = 0;
7780 } else {
7781 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime
7782 = MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7783 pScanCmd->u.scanCmd.u.scanRequest.minChnTime
7784 = MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7785 }
7786}
7787#else
7788static void csr_scan_request_set_chan_time(tpAniSirGlobal pMac,
7789 tSmeCmd *pScanCmd)
7790{
7791 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime
7792 = MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7793 pScanCmd->u.scanCmd.u.scanRequest.minChnTime
7794 = MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7795}
7796#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07007797
7798//This function is usually used for BSSs that suppresses SSID so the profile
7799//shall have one and only one SSID
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007800eHalStatus csrScanForSSID(tpAniSirGlobal pMac, tANI_U32 sessionId, tCsrRoamProfile *pProfile, tANI_U32 roamId, tANI_BOOLEAN notify)
Jeff Johnson295189b2012-06-20 16:38:30 -07007801{
7802 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
7803 tSmeCmd *pScanCmd = NULL;
7804 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
7805 tANI_U8 index = 0;
7806 tANI_U32 numSsid = pProfile->SSIDs.numOfSSIDs;
7807
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007808 smsLog(pMac, LOG2, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007809 //For WDS, we use the index 0. There must be at least one in there
7810 if( CSR_IS_WDS_STA( pProfile ) && numSsid )
7811 {
7812 numSsid = 1;
7813 }
7814 if(pMac->scan.fScanEnable && ( numSsid == 1 ) )
7815 {
7816 do
7817 {
7818 pScanCmd = csrGetCommandBuffer(pMac);
7819 if(!pScanCmd)
7820 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007821 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007822 break;
7823 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307824 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
7825 pScanCmd->u.scanCmd.pToRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
7826 if ( NULL == pScanCmd->u.scanCmd.pToRoamProfile )
krunal soni587bf012014-02-04 12:35:11 -08007827 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307828 status = eHAL_STATUS_FAILURE;
krunal soni587bf012014-02-04 12:35:11 -08007829 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307830 else
krunal soni587bf012014-02-04 12:35:11 -08007831 {
7832 status = csrRoamCopyProfile(pMac, pScanCmd->u.scanCmd.pToRoamProfile, pProfile);
7833 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007834 if(!HAL_STATUS_SUCCESS(status))
7835 break;
7836 pScanCmd->u.scanCmd.roamId = roamId;
7837 pScanCmd->command = eSmeCommandScan;
Jeff Johnsone7245742012-09-05 17:12:55 -07007838 pScanCmd->sessionId = (tANI_U8)sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07007839 pScanCmd->u.scanCmd.callback = NULL;
7840 pScanCmd->u.scanCmd.pContext = NULL;
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007841 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 -07007842 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Kiet Lam64c1b492013-07-12 13:56:44 +05307843 vos_mem_set(&pScanCmd->u.scanCmd.u.scanRequest, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007844 pScanCmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Jeff Johnson295189b2012-06-20 16:38:30 -07007845 pScanCmd->u.scanCmd.u.scanRequest.BSSType = pProfile->BSSType;
Jeff Johnsone7245742012-09-05 17:12:55 -07007846 // To avoid 11b rate in probe request Set p2pSearch flag as 1 for P2P Client Mode
7847 if(VOS_P2P_CLIENT_MODE == pProfile->csrPersona)
7848 {
7849 pScanCmd->u.scanCmd.u.scanRequest.p2pSearch = 1;
7850 }
Agarwal Ashish4f616132013-12-30 23:32:50 +05307851 if(pProfile->nAddIEScanLength)
Jeff Johnsone7245742012-09-05 17:12:55 -07007852 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307853 pScanCmd->u.scanCmd.u.scanRequest.pIEField = vos_mem_malloc(
7854 pProfile->nAddIEScanLength);
7855 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.pIEField )
7856 status = eHAL_STATUS_FAILURE;
7857 else
7858 status = eHAL_STATUS_SUCCESS;
7859 vos_mem_set(pScanCmd->u.scanCmd.u.scanRequest.pIEField,
7860 pProfile->nAddIEScanLength, 0);
7861 if (HAL_STATUS_SUCCESS(status))
Jeff Johnsone7245742012-09-05 17:12:55 -07007862 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307863 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.pIEField,
Agarwal Ashish4f616132013-12-30 23:32:50 +05307864 pProfile->addIEScan, pProfile->nAddIEScanLength);
Jeff Johnsone7245742012-09-05 17:12:55 -07007865 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = pProfile->nAddIEScanLength;
7866 }
7867 else
7868 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007869 smsLog(pMac, LOGE, "No memory for scanning IE fields");
Jeff Johnsone7245742012-09-05 17:12:55 -07007870 }
7871 } //Allocate memory for IE field
7872 else
7873 {
7874 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = 0;
7875 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07007876 /* For one channel be good enpugh time to receive beacon atleast */
7877 if( 1 == pProfile->ChannelInfo.numOfChannels )
7878 {
Selvaraj, Sridhar32417ed2016-06-22 15:19:12 +05307879 csr_scan_request_set_chan_time(pMac, pScanCmd);
7880 } else {
Kiet Lam64c1b492013-07-12 13:56:44 +05307881 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime =
7882 pMac->roam.configParam.nActiveMaxChnTime;
7883 pScanCmd->u.scanCmd.u.scanRequest.minChnTime =
7884 pMac->roam.configParam.nActiveMinChnTime;
Jeff Johnson32d95a32012-09-10 13:15:23 -07007885 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307886 pScanCmd->u.scanCmd.u.scanRequest.maxChnTimeBtc =
7887 pMac->roam.configParam.nActiveMaxChnTimeBtc;
7888 pScanCmd->u.scanCmd.u.scanRequest.minChnTimeBtc =
7889 pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07007890 if(pProfile->BSSIDs.numOfBSSIDs == 1)
7891 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307892 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.bssid,
7893 pProfile->BSSIDs.bssid, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07007894 }
7895 else
7896 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307897 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.bssid, bAddr, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07007898 }
7899 if(pProfile->ChannelInfo.numOfChannels)
7900 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307901 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(
7902 sizeof(*pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
7903 * pProfile->ChannelInfo.numOfChannels);
7904 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
7905 status = eHAL_STATUS_FAILURE;
7906 else
7907 status = eHAL_STATUS_SUCCESS;
7908 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
7909 if(HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07007910 {
7911 csrRoamIsChannelValid(pMac, pProfile->ChannelInfo.ChannelList[0]);
7912 for(index = 0; index < pProfile->ChannelInfo.numOfChannels; index++)
7913 {
7914 if(csrRoamIsValidChannel(pMac, pProfile->ChannelInfo.ChannelList[index]))
7915 {
7916 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels]
7917 = pProfile->ChannelInfo.ChannelList[index];
7918 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels++;
7919 }
7920 else
7921 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007922 smsLog(pMac, LOGW, FL("process a channel (%d) that is invalid"), pProfile->ChannelInfo.ChannelList[index]);
Jeff Johnson295189b2012-06-20 16:38:30 -07007923 }
7924
7925 }
7926 }
7927 else
7928 {
7929 break;
7930 }
7931
7932 }
7933 else
7934 {
7935 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
7936 }
7937 if(pProfile->SSIDs.numOfSSIDs)
7938 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307939 pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList = vos_mem_malloc(
7940 pProfile->SSIDs.numOfSSIDs * sizeof(tCsrSSIDInfo));
7941 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList )
7942 status = eHAL_STATUS_FAILURE;
7943 else
7944 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07007945 if(!HAL_STATUS_SUCCESS(status))
7946 {
7947 break;
7948 }
7949 pScanCmd->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 1;
Kiet Lam64c1b492013-07-12 13:56:44 +05307950 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList,
7951 pProfile->SSIDs.SSIDList, sizeof(tCsrSSIDInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07007952 }
7953 //Start process the command
7954 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
7955 if( !HAL_STATUS_SUCCESS( status ) )
7956 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007957 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07007958 break;
7959 }
7960 }while(0);
7961 if(!HAL_STATUS_SUCCESS(status))
7962 {
7963 if(pScanCmd)
7964 {
7965 csrReleaseCommandScan(pMac, pScanCmd);
7966 //TODO:free the memory that is allocated in this function
7967 }
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007968 if(notify)
7969 {
Jeff Johnson295189b2012-06-20 16:38:30 -07007970 csrRoamCallCallback(pMac, sessionId, NULL, roamId, eCSR_ROAM_FAILED, eCSR_ROAM_RESULT_FAILURE);
7971 }
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007972 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007973 }//valid
7974 else
7975 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007976 smsLog(pMac, LOGE, FL("cannot scan because scanEnable (%d) or numSSID (%d) is invalid"),
Jeff Johnson295189b2012-06-20 16:38:30 -07007977 pMac->scan.fScanEnable, pProfile->SSIDs.numOfSSIDs);
7978 }
7979
7980 return (status);
7981}
7982
7983
7984//Issue a scan base on the new capability infomation
7985//This should only happen when the associated AP changes its capability.
7986//After this scan is done, CSR reroams base on the new scan results
7987eHalStatus csrScanForCapabilityChange(tpAniSirGlobal pMac, tSirSmeApNewCaps *pNewCaps)
7988{
7989 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
7990 tSmeCmd *pScanCmd = NULL;
7991
7992 if(pNewCaps)
7993 {
7994 do
7995 {
7996 pScanCmd = csrGetCommandBuffer(pMac);
7997 if(!pScanCmd)
7998 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007999 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07008000 status = eHAL_STATUS_RESOURCES;
8001 break;
8002 }
Kiet Lam64c1b492013-07-12 13:56:44 +05308003 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008004 status = eHAL_STATUS_SUCCESS;
8005 pScanCmd->u.scanCmd.roamId = 0;
8006 pScanCmd->command = eSmeCommandScan;
8007 pScanCmd->u.scanCmd.callback = NULL;
8008 pScanCmd->u.scanCmd.pContext = NULL;
8009 pScanCmd->u.scanCmd.reason = eCsrScanForCapsChange;
8010 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
8011 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
8012 if( !HAL_STATUS_SUCCESS( status ) )
8013 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008014 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07008015 break;
8016 }
8017 }while(0);
8018 if(!HAL_STATUS_SUCCESS(status))
8019 {
8020 if(pScanCmd)
8021 {
8022 csrReleaseCommandScan(pMac, pScanCmd);
8023 }
8024 }
8025 }
8026
8027 return (status);
8028}
8029
8030
8031
8032void csrInitBGScanChannelList(tpAniSirGlobal pMac)
8033{
8034 tANI_U32 len = CSR_MIN(sizeof(pMac->roam.validChannelList), sizeof(pMac->scan.bgScanChannelList));
8035
Kiet Lam64c1b492013-07-12 13:56:44 +05308036 vos_mem_set(pMac->scan.bgScanChannelList, len, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008037 pMac->scan.numBGScanChannel = 0;
8038
8039 if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
8040 {
8041 pMac->roam.numValidChannels = len;
8042 pMac->scan.numBGScanChannel = (tANI_U8)CSR_MIN(len, WNI_CFG_BG_SCAN_CHANNEL_LIST_LEN);
Kiet Lam64c1b492013-07-12 13:56:44 +05308043 vos_mem_copy(pMac->scan.bgScanChannelList, pMac->roam.validChannelList,
8044 pMac->scan.numBGScanChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07008045 csrSetBGScanChannelList(pMac, pMac->scan.bgScanChannelList, pMac->scan.numBGScanChannel);
8046 }
8047}
8048
8049
8050//This function return TRUE if background scan channel list is adjusted.
8051//this function will only shrink the background scan channel list
8052tANI_BOOLEAN csrAdjustBGScanChannelList(tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels,
8053 tANI_U8 *pAdjustChannels, tANI_U8 *pNumAdjustChannels)
8054{
8055 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
8056 tANI_U8 i, j, count = *pNumAdjustChannels;
8057
8058 i = 0;
8059 while(i < count)
8060 {
8061 for(j = 0; j < NumChannels; j++)
8062 {
8063 if(pChannelList[j] == pAdjustChannels[i])
8064 break;
8065 }
8066 if(j == NumChannels)
8067 {
8068 //This channel is not in the list, remove it
8069 fRet = eANI_BOOLEAN_TRUE;
8070 count--;
8071 if(count - i)
8072 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308073 vos_mem_copy(&pAdjustChannels[i], &pAdjustChannels[i+1], count - i);
Jeff Johnson295189b2012-06-20 16:38:30 -07008074 }
8075 else
8076 {
8077 //already remove the last one. Done.
8078 break;
8079 }
8080 }
8081 else
8082 {
8083 i++;
8084 }
8085 }//while(i<count)
8086 *pNumAdjustChannels = count;
8087
8088 return (fRet);
8089}
8090
8091
8092//Get the list of the base channels to scan for passively 11d info
8093eHalStatus csrScanGetSupportedChannels( tpAniSirGlobal pMac )
8094{
8095 eHalStatus status = eHAL_STATUS_SUCCESS;
8096 int n = WNI_CFG_VALID_CHANNEL_LIST_LEN;
8097
8098 status = vos_nv_getSupportedChannels( pMac->scan.baseChannels.channelList, &n, NULL, NULL );
8099 if( HAL_STATUS_SUCCESS(status) )
8100 {
8101 pMac->scan.baseChannels.numChannels = (tANI_U8)n;
8102 }
8103 else
8104 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008105 smsLog( pMac, LOGE, FL(" failed") );
Jeff Johnson295189b2012-06-20 16:38:30 -07008106 pMac->scan.baseChannels.numChannels = 0;
8107 }
8108
8109 return ( status );
8110}
8111
8112//This function use the input pChannelList to validate the current saved channel list
8113eHalStatus csrSetBGScanChannelList( tpAniSirGlobal pMac, tANI_U8 *pAdjustChannels, tANI_U8 NumAdjustChannels)
8114{
8115 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumAdjustChannels;
8116
8117 return (ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pAdjustChannels, dataLen, NULL, eANI_BOOLEAN_FALSE));
8118}
8119
8120
8121void csrSetCfgValidChannelList( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels )
8122{
8123 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumChannels;
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05308124 eHalStatus status;
Jeff Johnson295189b2012-06-20 16:38:30 -07008125
Mihir Shete31c435d2014-02-12 13:13:34 +05308126 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
8127 "%s: dump valid channel list(NumChannels(%d))",
8128 __func__,NumChannels);
8129 VOS_TRACE_HEX_DUMP(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
8130 pChannelList, NumChannels);
8131
Jeff Johnson295189b2012-06-20 16:38:30 -07008132 ccmCfgSetStr(pMac, WNI_CFG_VALID_CHANNEL_LIST, pChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
Leela Venkata Kiran Kumar Reddy Chiralac6663f72014-02-03 21:04:58 -08008133#ifdef QCA_WIFI_2_0
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05308134 if (pMac->fScanOffload)
8135 {
8136 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
8137 "Scan offload is enabled, update default chan list");
Leela Venkata Kiran Kumar Reddy Chiralac6663f72014-02-03 21:04:58 -08008138 status = csrUpdateChannelList(pMac);
8139 }
8140#else
8141 status = csrUpdateChannelList(pMac);
8142#endif
8143
8144 if (eHAL_STATUS_SUCCESS != status)
8145 {
8146 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR,
8147 "failed to update the supported channel list");
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05308148 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008149 return;
8150}
8151
8152
8153
8154/*
8155 * The Tx power limits are saved in the cfg for future usage.
8156 */
8157void csrSaveTxPowerToCfg( tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 cfgId )
8158{
8159 tListElem *pEntry;
8160 tANI_U32 cbLen = 0, dataLen;
8161 tCsrChannelPowerInfo *pChannelSet;
8162 tANI_U32 idx;
8163 tSirMacChanInfo *pChannelPowerSet;
8164 tANI_U8 *pBuf = NULL;
8165
8166 //allocate maximum space for all channels
8167 dataLen = WNI_CFG_VALID_CHANNEL_LIST_LEN * sizeof(tSirMacChanInfo);
Kiet Lam64c1b492013-07-12 13:56:44 +05308168 if ( (pBuf = vos_mem_malloc(dataLen)) != NULL )
Jeff Johnson295189b2012-06-20 16:38:30 -07008169 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308170 vos_mem_set(pBuf, dataLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008171 pChannelPowerSet = (tSirMacChanInfo *)(pBuf);
8172
8173 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
8174 // write the tuples (startChan, numChan, txPower) for each channel found in the channel power list.
8175 while( pEntry )
8176 {
8177 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
8178 if ( 1 != pChannelSet->interChannelOffset )
8179 {
8180 // we keep the 5G channel sets internally with an interchannel offset of 4. Expand these
8181 // to the right format... (inter channel offset of 1 is the only option for the triplets
8182 // that 11d advertises.
8183 if ((cbLen + (pChannelSet->numChannels * sizeof(tSirMacChanInfo))) >= dataLen)
8184 {
8185 // expanding this entry will overflow our allocation
8186 smsLog(pMac, LOGE,
8187 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07008188 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07008189 pChannelSet->firstChannel,
8190 pChannelSet->numChannels,
8191 pChannelSet->interChannelOffset);
8192 break;
8193 }
8194
8195 for( idx = 0; idx < pChannelSet->numChannels; idx++ )
8196 {
8197 pChannelPowerSet->firstChanNum = (tSirMacChanNum)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008198 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07008199 pChannelPowerSet->numChannels = 1;
Jeff Johnson295189b2012-06-20 16:38:30 -07008200 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008201 smsLog(pMac, LOG3, " Setting Max Transmit Power %d", pChannelPowerSet->maxTxPower);
Jeff Johnson295189b2012-06-20 16:38:30 -07008202 cbLen += sizeof( tSirMacChanInfo );
8203 pChannelPowerSet++;
8204 }
8205 }
8206 else
8207 {
8208 if (cbLen >= dataLen)
8209 {
8210 // this entry will overflow our allocation
8211 smsLog(pMac, LOGE,
8212 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07008213 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07008214 pChannelSet->firstChannel,
8215 pChannelSet->numChannels,
8216 pChannelSet->interChannelOffset);
8217 break;
8218 }
8219 pChannelPowerSet->firstChanNum = pChannelSet->firstChannel;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008220 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07008221 pChannelPowerSet->numChannels = pChannelSet->numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -07008222 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008223 smsLog(pMac, LOG3, " Setting Max Transmit Power %d, nTxPower %d", pChannelPowerSet->maxTxPower,pMac->roam.configParam.nTxPowerCap );
Jeff Johnson295189b2012-06-20 16:38:30 -07008224
8225
8226 cbLen += sizeof( tSirMacChanInfo );
8227 pChannelPowerSet++;
8228 }
8229
8230 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
8231 }
8232
8233 if(cbLen)
8234 {
8235 ccmCfgSetStr(pMac, cfgId, (tANI_U8 *)pBuf, cbLen, NULL, eANI_BOOLEAN_FALSE);
8236 }
Kiet Lam64c1b492013-07-12 13:56:44 +05308237 vos_mem_free(pBuf);
Jeff Johnson295189b2012-06-20 16:38:30 -07008238 }//Allocate memory
8239}
8240
8241
8242void csrSetCfgCountryCode( tpAniSirGlobal pMac, tANI_U8 *countryCode )
8243{
8244 tANI_U8 cc[WNI_CFG_COUNTRY_CODE_LEN];
8245 ///v_REGDOMAIN_t DomainId;
8246
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008247 smsLog( pMac, LOG3, "Setting Country Code in Cfg from csrSetCfgCountryCode %s",countryCode );
Kiet Lam64c1b492013-07-12 13:56:44 +05308248 vos_mem_copy(cc, countryCode, WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07008249
8250 // don't program the bogus country codes that we created for Korea in the MAC. if we see
8251 // the bogus country codes, program the MAC with the right country code.
8252 if ( ( 'K' == countryCode[ 0 ] && '1' == countryCode[ 1 ] ) ||
8253 ( 'K' == countryCode[ 0 ] && '2' == countryCode[ 1 ] ) ||
8254 ( 'K' == countryCode[ 0 ] && '3' == countryCode[ 1 ] ) ||
8255 ( 'K' == countryCode[ 0 ] && '4' == countryCode[ 1 ] ) )
8256 {
8257 // replace the alternate Korea country codes, 'K1', 'K2', .. with 'KR' for Korea
8258 cc[ 1 ] = 'R';
8259 }
8260 ccmCfgSetStr(pMac, WNI_CFG_COUNTRY_CODE, cc, WNI_CFG_COUNTRY_CODE_LEN, NULL, eANI_BOOLEAN_FALSE);
8261
8262 //Need to let HALPHY know about the current domain so it can apply some
8263 //domain-specific settings (TX filter...)
8264 /*if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(pMac, cc, &DomainId)))
8265 {
8266 halPhySetRegDomain(pMac, DomainId);
8267 }*/
8268}
8269
8270
8271
8272eHalStatus csrGetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pBuf, tANI_U8 *pbLen)
8273{
8274 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
8275 tANI_U32 len;
8276
8277 if(pBuf && pbLen && (*pbLen >= WNI_CFG_COUNTRY_CODE_LEN))
8278 {
8279 len = *pbLen;
8280 status = ccmCfgGetStr(pMac, WNI_CFG_COUNTRY_CODE, pBuf, &len);
8281 if(HAL_STATUS_SUCCESS(status))
8282 {
8283 *pbLen = (tANI_U8)len;
8284 }
8285 }
8286
8287 return (status);
8288}
8289
8290
8291void csrSetCfgScanControlList( tpAniSirGlobal pMac, tANI_U8 *countryCode, tCsrChannel *pChannelList )
8292{
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05308293 tANI_U8 i, j, k;
Jeff Johnson295189b2012-06-20 16:38:30 -07008294 tANI_BOOLEAN found=FALSE;
8295 tANI_U8 *pControlList = NULL;
8296 tANI_U32 len = WNI_CFG_SCAN_CONTROL_LIST_LEN;
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05308297 tANI_U8 cfgActiveDFSChannels = 0;
8298 tANI_U8 *cfgActiveDFSChannelLIst = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07008299
Kiet Lam64c1b492013-07-12 13:56:44 +05308300 if ( (pControlList = vos_mem_malloc(WNI_CFG_SCAN_CONTROL_LIST_LEN)) != NULL )
Jeff Johnson295189b2012-06-20 16:38:30 -07008301 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308302 vos_mem_set((void *)pControlList, WNI_CFG_SCAN_CONTROL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008303 if(HAL_STATUS_SUCCESS(ccmCfgGetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, &len)))
8304 {
8305 for (i = 0; i < pChannelList->numChannels; i++)
8306 {
8307 for (j = 0; j < len; j += 2)
8308 {
8309 if (pControlList[j] == pChannelList->channelList[i])
8310 {
8311 found = TRUE;
8312 break;
8313 }
8314 }
8315
8316 if (found) // insert a pair(channel#, flag)
8317 {
Gopichand Nakkala392cbc12013-05-28 16:15:00 +05308318 pControlList[j+1] = csrGetScanType(pMac, pControlList[j]);
Jeff Johnson295189b2012-06-20 16:38:30 -07008319 found = FALSE; // reset the flag
Jeff Johnson295189b2012-06-20 16:38:30 -07008320
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05308321 // When DFS mode is 2, mark static channels as active
8322 if (pMac->scan.fEnableDFSChnlScan ==
8323 DFS_CHNL_SCAN_ENABLED_ACTIVE)
8324 {
8325 cfgActiveDFSChannels =
8326 pMac->roam.neighborRoamInfo.cfgParams.
8327 channelInfo.numOfChannels;
8328 cfgActiveDFSChannelLIst =
8329 pMac->roam.neighborRoamInfo.cfgParams.
8330 channelInfo.ChannelList;
8331 if (cfgActiveDFSChannelLIst)
8332 {
8333 for (k=0; k < cfgActiveDFSChannels; k++)
8334 {
8335 if(CSR_IS_CHANNEL_DFS(cfgActiveDFSChannelLIst[k])
8336 && (pControlList[j] ==
8337 cfgActiveDFSChannelLIst[k]))
8338 {
8339 pControlList[j+1] = eSIR_ACTIVE_SCAN;
8340 smsLog(pMac, LOG1, FL("Marked DFS ch %d"
8341 " as active"),
8342 cfgActiveDFSChannelLIst[k]);
8343 }
8344 }
8345 }
8346 }
8347 }
8348 }
8349
8350 smsLog(pMac, LOG1, FL("fEnableDFSChnlScan %d"),
8351 pMac->scan.fEnableDFSChnlScan);
Mihir Shete31c435d2014-02-12 13:13:34 +05308352 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
8353 "%s: dump scan control list",__func__);
8354 VOS_TRACE_HEX_DUMP(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
8355 pControlList, len);
8356
Jeff Johnson295189b2012-06-20 16:38:30 -07008357 ccmCfgSetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, len, NULL, eANI_BOOLEAN_FALSE);
8358 }//Successfully getting scan control list
Kiet Lam64c1b492013-07-12 13:56:44 +05308359 vos_mem_free(pControlList);
Jeff Johnson295189b2012-06-20 16:38:30 -07008360 }//AllocateMemory
8361}
8362
Jeff Johnson295189b2012-06-20 16:38:30 -07008363//if bgPeriod is 0, background scan is disabled. It is in millisecond units
8364eHalStatus csrSetCfgBackgroundScanPeriod(tpAniSirGlobal pMac, tANI_U32 bgPeriod)
8365{
8366 return (ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, bgPeriod, (tCcmCfgSetCallback) csrScanCcmCfgSetCallback, eANI_BOOLEAN_FALSE));
8367}
8368
8369
8370void csrScanCcmCfgSetCallback(tHalHandle hHal, tANI_S32 result)
8371{
8372 tListElem *pEntry = NULL;
8373 tSmeCmd *pCommand = NULL;
8374 tpAniSirGlobal pMac = PMAC_STRUCT( hHal );
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05308375 tDblLinkList *pCmdList ;
8376
8377 if (!pMac->fScanOffload)
8378 pCmdList = &pMac->sme.smeCmdActiveList;
8379 else
8380 pCmdList = &pMac->sme.smeScanCmdActiveList;
8381
8382 pEntry = csrLLPeekHead( pCmdList, LL_ACCESS_LOCK );
Jeff Johnson295189b2012-06-20 16:38:30 -07008383 if ( pEntry )
8384 {
8385 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8386 if ( eSmeCommandScan == pCommand->command )
8387 {
8388 eCsrScanStatus scanStatus = (CCM_IS_RESULT_SUCCESS(result)) ? eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
8389 csrReleaseScanCommand(pMac, pCommand, scanStatus);
8390 }
8391 else
8392 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008393 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
Jeff Johnson295189b2012-06-20 16:38:30 -07008394 }
8395 }
8396 smeProcessPendingQueue( pMac );
8397}
8398
8399eHalStatus csrProcessSetBGScanParam(tpAniSirGlobal pMac, tSmeCmd *pCommand)
8400{
8401 eHalStatus status;
8402 tCsrBGScanRequest *pScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
8403 tANI_U32 dataLen = sizeof( tANI_U8 ) * pScanReq->ChannelInfo.numOfChannels;
8404
8405 //***setcfg for background scan channel list
8406 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MINIMUM_CHANNEL_TIME, pScanReq->minChnTime, NULL, eANI_BOOLEAN_FALSE);
8407 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MAXIMUM_CHANNEL_TIME, pScanReq->maxChnTime, NULL, eANI_BOOLEAN_FALSE);
8408 //Not set the background scan interval if not connected because bd scan should not be run if not connected
8409 if(!csrIsAllSessionDisconnected(pMac))
8410 {
Jeff Johnson295189b2012-06-20 16:38:30 -07008411
8412#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
8413 {
8414 vos_log_scan_pkt_type *pScanLog = NULL;
8415
8416 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
8417 if(pScanLog)
8418 {
8419 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
8420 pScanLog->minChnTime = (v_U8_t)pScanReq->minChnTime;
8421 pScanLog->maxChnTime = (v_U8_t)pScanReq->maxChnTime;
8422 pScanLog->timeBetweenBgScan = (v_U8_t)pScanReq->scanInterval;
8423 pScanLog->numChannel = pScanReq->ChannelInfo.numOfChannels;
8424 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
8425 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308426 vos_mem_copy(pScanLog->channels,
8427 pScanReq->ChannelInfo.ChannelList,
8428 pScanLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07008429 }
8430 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
8431 }
8432 }
8433#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
8434
8435 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, pScanReq->scanInterval, NULL, eANI_BOOLEAN_FALSE);
8436 }
8437 else
8438 {
8439 //No need to stop aging because IDLE scan is still running
8440 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, 0, NULL, eANI_BOOLEAN_FALSE);
8441 }
8442
8443 if(pScanReq->SSID.length > WNI_CFG_SSID_LEN)
8444 {
8445 pScanReq->SSID.length = WNI_CFG_SSID_LEN;
8446 }
8447
8448 status = ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pScanReq->ChannelInfo.ChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
8449 status = ccmCfgSetStr(pMac, WNI_CFG_SSID, (tANI_U8 *)pScanReq->SSID.ssId, pScanReq->SSID.length, NULL, eANI_BOOLEAN_FALSE);
8450
8451
8452
8453 return (status);
8454}
8455
8456
c_hpothua3d45d52015-01-05 14:11:17 +05308457tSirAbortScanStatus csrScanAbortMacScan(tpAniSirGlobal pMac,
8458 tANI_U8 sessionId,
8459 eCsrAbortReason reason)
Jeff Johnson295189b2012-06-20 16:38:30 -07008460{
c_hpothua3d45d52015-01-05 14:11:17 +05308461 tSirAbortScanStatus abortScanStatus = eSIR_ABORT_ACTIVE_SCAN_LIST_EMPTY;
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308462 tSirSmeScanAbortReq *pMsg;
Jeff Johnson295189b2012-06-20 16:38:30 -07008463 tANI_U16 msgLen;
8464 tListElem *pEntry;
8465 tSmeCmd *pCommand;
8466
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308467 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07008468 {
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308469#ifdef WLAN_AP_STA_CONCURRENCY
8470 csrLLLock(&pMac->scan.scanCmdPendingList);
8471 while(NULL !=
8472 (pEntry = csrLLRemoveHead(&pMac->scan.scanCmdPendingList,
8473 LL_ACCESS_NOLOCK)))
8474 {
Jeff Johnson295189b2012-06-20 16:38:30 -07008475
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308476 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8477 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
8478 }
8479 csrLLUnlock(&pMac->scan.scanCmdPendingList);
Jeff Johnson295189b2012-06-20 16:38:30 -07008480#endif
8481
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308482 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
8483 csrRemoveCmdFromPendingList( pMac, &pMac->roam.roamCmdPendingList, eSmeCommandScan);
8484 csrRemoveCmdFromPendingList( pMac, &pMac->sme.smeCmdPendingList, eSmeCommandScan);
8485 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
8486
8487 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
8488 }
8489 else
8490 {
8491 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
8492 csrRemoveCmdWithSessionIdFromPendingList(pMac,
8493 sessionId,
8494 &pMac->sme.smeScanCmdPendingList,
8495 eSmeCommandScan);
8496 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
8497
8498 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
8499 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008500
8501 //We need to abort scan only if we are scanning
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308502 if(NULL != pEntry)
Jeff Johnson295189b2012-06-20 16:38:30 -07008503 {
8504 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308505 if(eSmeCommandScan == pCommand->command &&
8506 pCommand->sessionId == sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07008507 {
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308508 msgLen = (tANI_U16)(sizeof(tSirSmeScanAbortReq));
Kiet Lam64c1b492013-07-12 13:56:44 +05308509 pMsg = vos_mem_malloc(msgLen);
8510 if ( NULL == pMsg )
Jeff Johnson295189b2012-06-20 16:38:30 -07008511 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308512 smsLog(pMac, LOGE, FL("Failed to allocate memory for SmeScanAbortReq"));
c_hpothua3d45d52015-01-05 14:11:17 +05308513 abortScanStatus = eSIR_ABORT_SCAN_FAILURE;
Kiet Lam64c1b492013-07-12 13:56:44 +05308514 }
8515 else
8516 {
Ratheesh S Pece1f832015-07-25 15:50:25 +05308517 pCommand->u.scanCmd.abortScanIndication = eCSR_SCAN_ABORT_DEFAULT;
Srinivas, Dasari187ca4e2014-02-07 12:40:09 +05308518 if(reason == eCSR_SCAN_ABORT_DUE_TO_BAND_CHANGE)
8519 {
Ratheesh S Pece1f832015-07-25 15:50:25 +05308520 pCommand->u.scanCmd.abortScanIndication
8521 = eCSR_SCAN_ABORT_DUE_TO_BAND_CHANGE;
Srinivas, Dasari187ca4e2014-02-07 12:40:09 +05308522 }
Kiet Lam64c1b492013-07-12 13:56:44 +05308523 vos_mem_set((void *)pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008524 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_ABORT_IND);
8525 pMsg->msgLen = pal_cpu_to_be16(msgLen);
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308526 pMsg->sessionId = sessionId;
c_hpothua3d45d52015-01-05 14:11:17 +05308527 if (eHAL_STATUS_SUCCESS != palSendMBMessage(pMac->hHdd, pMsg))
8528 {
8529 smsLog(pMac, LOGE,
8530 FL("Failed to post eWNI_SME_SCAN_ABORT_IND"));
8531 abortScanStatus = eSIR_ABORT_SCAN_FAILURE;
Ratheesh S Pece1f832015-07-25 15:50:25 +05308532 pCommand->u.scanCmd.abortScanIndication = 0;
c_hpothua3d45d52015-01-05 14:11:17 +05308533 }
8534 else
8535 {
8536 abortScanStatus = eSIR_ABORT_ACTIVE_SCAN_LIST_NOT_EMPTY;
8537 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008538 }
8539 }
8540 }
8541
c_hpothua3d45d52015-01-05 14:11:17 +05308542 return(abortScanStatus);
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308543}
8544
8545void csrRemoveCmdWithSessionIdFromPendingList(tpAniSirGlobal pMac,
8546 tANI_U8 sessionId,
8547 tDblLinkList *pList,
8548 eSmeCommandType commandType)
8549{
8550 tDblLinkList localList;
8551 tListElem *pEntry;
8552 tSmeCmd *pCommand;
8553 tListElem *pEntryToRemove;
8554
8555 vos_mem_zero(&localList, sizeof(tDblLinkList));
8556 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
8557 {
8558 smsLog(pMac, LOGE, FL(" failed to open list"));
8559 return;
8560 }
8561
8562 csrLLLock(pList);
8563 if ((pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK)))
8564 {
8565
8566 /* Have to make sure we don't loop back to the head of the list,
8567 * which will happen if the entry is NOT on the list */
8568 while (pEntry)
8569 {
8570 pEntryToRemove = pEntry;
8571 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
8572 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
8573 if ((pCommand->command == commandType) &&
8574 (pCommand->sessionId == sessionId))
8575 {
8576 /* Remove that entry only */
8577 if (csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
8578 {
8579 csrLLInsertTail(&localList, pEntryToRemove,
8580 LL_ACCESS_NOLOCK);
8581 }
8582 }
8583 }
8584 }
8585 csrLLUnlock(pList);
8586
8587 while ((pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)))
8588 {
8589 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
8590 csrAbortCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
8591 }
8592
8593 csrLLClose(&localList);
Jeff Johnson295189b2012-06-20 16:38:30 -07008594}
8595
8596void csrRemoveCmdFromPendingList(tpAniSirGlobal pMac, tDblLinkList *pList,
8597 eSmeCommandType commandType )
8598{
8599 tDblLinkList localList;
8600 tListElem *pEntry;
8601 tSmeCmd *pCommand;
8602 tListElem *pEntryToRemove;
8603
8604 vos_mem_zero(&localList, sizeof(tDblLinkList));
8605 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
8606 {
8607 smsLog(pMac, LOGE, FL(" failed to open list"));
8608 return;
8609 }
8610
8611 csrLLLock(pList);
8612 if( !csrLLIsListEmpty( pList, LL_ACCESS_NOLOCK ) )
8613 {
8614 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK);
8615
8616 // Have to make sure we don't loop back to the head of the list, which will
8617 // happen if the entry is NOT on the list...
8618 while( pEntry )
8619 {
8620 pEntryToRemove = pEntry;
8621 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
8622 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
8623 if ( pCommand->command == commandType )
8624 {
8625 // Remove that entry only
8626 if(csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
8627 {
8628 csrLLInsertTail(&localList, pEntryToRemove, LL_ACCESS_NOLOCK);
8629 }
8630 }
8631 }
8632
8633
8634 }
8635 csrLLUnlock(pList);
8636
8637 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
8638 {
8639 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8640 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
8641 }
8642 csrLLClose(&localList);
8643
8644}
8645
Abhishek Singhdc2bfd42014-06-19 17:59:05 +05308646eHalStatus csrScanAbortScanForSSID(tpAniSirGlobal pMac, tANI_U32 sessionId)
8647{
8648 eHalStatus status = eHAL_STATUS_SUCCESS;
8649 tSirSmeScanAbortReq *pMsg;
8650 tANI_U16 msgLen;
8651 tListElem *pEntry;
8652 tSmeCmd *pCommand;
8653
8654 if (!pMac->fScanOffload)
8655 {
8656 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
8657#ifdef WLAN_AP_STA_CONCURRENCY
8658 csrRemoveScanForSSIDFromPendingList( pMac, &pMac->scan.scanCmdPendingList, sessionId);
8659#endif
8660 csrRemoveScanForSSIDFromPendingList( pMac, &pMac->roam.roamCmdPendingList, sessionId);
8661 csrRemoveScanForSSIDFromPendingList( pMac, &pMac->sme.smeCmdPendingList, sessionId);
8662 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
8663 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
8664 }
8665 else
8666 {
8667 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
8668 csrRemoveScanForSSIDFromPendingList( pMac, &pMac->sme.smeScanCmdPendingList, sessionId);
8669 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
8670 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
8671 }
8672
8673 if(NULL != pEntry)
8674 {
8675 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8676
8677 if ( (eSmeCommandScan == pCommand->command ) &&
8678 (sessionId == pCommand->sessionId))
8679 {
8680 if ( eCsrScanForSsid == pCommand->u.scanCmd.reason)
8681 {
8682 msgLen = (tANI_U16)(sizeof( tSirSmeScanAbortReq ));
8683 pMsg = vos_mem_malloc(msgLen);
8684 if ( NULL == pMsg )
8685 {
8686 status = eHAL_STATUS_FAILURE;
8687 smsLog(pMac, LOGE, FL("Failed to allocate memory for SmeScanAbortReq"));
8688 }
8689 else
8690 {
8691 vos_mem_zero((void *)pMsg, msgLen);
8692 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_ABORT_IND);
8693 pMsg->msgLen = pal_cpu_to_be16(msgLen);
8694 pMsg->sessionId = sessionId;
8695 status = palSendMBMessage(pMac->hHdd, pMsg);
8696 }
8697 }
8698 }
8699 }
8700 return( status );
8701}
8702
8703void csrRemoveScanForSSIDFromPendingList(tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 sessionId)
8704{
8705 tDblLinkList localList;
8706 tListElem *pEntry;
8707 tSmeCmd *pCommand;
8708 tListElem *pEntryToRemove;
8709
8710 vos_mem_zero(&localList, sizeof(tDblLinkList));
8711 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
8712 {
8713 smsLog(pMac, LOGE, FL(" failed to open list"));
8714 return;
8715 }
8716
8717 csrLLLock(pList);
8718 if( !csrLLIsListEmpty( pList, LL_ACCESS_NOLOCK ) )
8719 {
8720 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK);
8721
8722 // Have to make sure we don't loop back to the head of the list, which will
8723 // happen if the entry is NOT on the list...
8724 while( pEntry )
8725 {
8726 pEntryToRemove = pEntry;
8727 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
8728 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
8729 if ( (eSmeCommandScan == pCommand->command ) &&
8730 (sessionId == pCommand->sessionId) )
8731 {
8732 if ( eCsrScanForSsid == pCommand->u.scanCmd.reason)
8733 {
8734 // Remove that entry only
8735 if ( csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
8736 {
8737 csrLLInsertTail(&localList, pEntryToRemove, LL_ACCESS_NOLOCK);
8738 }
8739 }
8740 }
8741 }
8742 }
8743 csrLLUnlock(pList);
8744
8745 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
8746 {
8747 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8748 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
8749 }
8750 csrLLClose(&localList);
8751}
Jeff Johnson295189b2012-06-20 16:38:30 -07008752
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308753eHalStatus csrScanAbortMacScanNotForConnect(tpAniSirGlobal pMac,
8754 tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07008755{
8756 eHalStatus status = eHAL_STATUS_SUCCESS;
8757
8758 if( !csrIsScanForRoamCommandActive( pMac ) )
8759 {
8760 //Only abort the scan if it is not used for other roam/connect purpose
c_hpothua3d45d52015-01-05 14:11:17 +05308761 if (eSIR_ABORT_SCAN_FAILURE ==
8762 csrScanAbortMacScan(pMac, sessionId, eCSR_SCAN_ABORT_DEFAULT))
8763 {
8764 smsLog(pMac, LOGE, FL("fail to abort scan"));
8765 status = eHAL_STATUS_FAILURE;
8766 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008767 }
8768
8769 return (status);
8770}
8771
8772
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05308773eHalStatus csrScanGetScanChannelInfo(tpAniSirGlobal pMac, tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07008774{
8775 eHalStatus status = eHAL_STATUS_SUCCESS;
8776 tSirMbMsg *pMsg;
8777 tANI_U16 msgLen;
8778
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05308779 if (pMac->fScanOffload)
8780 msgLen = (tANI_U16)(sizeof(tSirSmeGetScanChanReq));
8781 else
8782 msgLen = (tANI_U16)(sizeof(tSirMbMsg));
8783
Kiet Lam64c1b492013-07-12 13:56:44 +05308784 pMsg = vos_mem_malloc(msgLen);
8785 if ( NULL == pMsg )
8786 status = eHAL_STATUS_FAILURE;
8787 else
Jeff Johnson295189b2012-06-20 16:38:30 -07008788 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308789 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008790 pMsg->type = eWNI_SME_GET_SCANNED_CHANNEL_REQ;
8791 pMsg->msgLen = msgLen;
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05308792 if (pMac->fScanOffload)
8793 ((tSirSmeGetScanChanReq *)pMsg)->sessionId = sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07008794 status = palSendMBMessage(pMac->hHdd, pMsg);
8795 }
8796
8797 return( status );
8798}
8799
8800tANI_BOOLEAN csrRoamIsValidChannel( tpAniSirGlobal pMac, tANI_U8 channel )
8801{
8802 tANI_BOOLEAN fValid = FALSE;
8803 tANI_U32 idxValidChannels;
8804 tANI_U32 len = pMac->roam.numValidChannels;
8805
8806 for ( idxValidChannels = 0; ( idxValidChannels < len ); idxValidChannels++ )
8807 {
8808 if ( channel == pMac->roam.validChannelList[ idxValidChannels ] )
8809 {
8810 fValid = TRUE;
8811 break;
8812 }
8813 }
8814
8815 return fValid;
8816}
8817
Manjunathappa Prakash4f1d5a52013-11-11 16:22:19 -08008818#ifdef FEATURE_WLAN_SCAN_PNO
Srikant Kuppa066904f2013-05-07 13:56:02 -07008819eHalStatus csrScanSavePreferredNetworkFound(tpAniSirGlobal pMac,
8820 tSirPrefNetworkFoundInd *pPrefNetworkFoundInd)
8821{
8822 v_U32_t uLen = 0;
8823 tpSirProbeRespBeacon pParsedFrame;
8824 tCsrScanResult *pScanResult = NULL;
8825 tSirBssDescription *pBssDescr = NULL;
8826 tANI_BOOLEAN fDupBss;
8827 tDot11fBeaconIEs *pIesLocal = NULL;
8828 tAniSSID tmpSsid;
8829 v_TIME_t timer=0;
8830 tpSirMacMgmtHdr macHeader = (tpSirMacMgmtHdr)pPrefNetworkFoundInd->data;
Abhishek Singhd3d4e022014-11-11 13:02:40 +05308831 boolean bFoundonAppliedChannel = FALSE;
8832 v_U32_t indx;
8833 u8 channelsAllowed[WNI_CFG_VALID_CHANNEL_LIST_LEN];
8834 v_U32_t numChannelsAllowed = WNI_CFG_VALID_CHANNEL_LIST_LEN;
Sushant Kaushik6274de62015-05-01 16:31:23 +05308835 tListElem *pEntry;
Abhishek Singhd3d4e022014-11-11 13:02:40 +05308836
Srikant Kuppa066904f2013-05-07 13:56:02 -07008837
8838 pParsedFrame =
Abhishek Singhc75726d2015-04-13 14:44:14 +05308839 (tpSirProbeRespBeacon)vos_mem_vmalloc(sizeof(tSirProbeRespBeacon));
Srikant Kuppa066904f2013-05-07 13:56:02 -07008840
8841 if (NULL == pParsedFrame)
8842 {
8843 smsLog(pMac, LOGE, FL(" fail to allocate memory for frame"));
8844 return eHAL_STATUS_RESOURCES;
8845 }
8846
8847 if ( pPrefNetworkFoundInd->frameLength <= SIR_MAC_HDR_LEN_3A )
8848 {
8849 smsLog(pMac, LOGE,
8850 FL("Not enough bytes in PNO indication probe resp frame! length=%d"),
8851 pPrefNetworkFoundInd->frameLength);
Abhishek Singhc75726d2015-04-13 14:44:14 +05308852 vos_mem_vfree(pParsedFrame);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008853 return eHAL_STATUS_FAILURE;
8854 }
8855
8856 if (sirConvertProbeFrame2Struct(pMac,
8857 &pPrefNetworkFoundInd->data[SIR_MAC_HDR_LEN_3A],
8858 pPrefNetworkFoundInd->frameLength - SIR_MAC_HDR_LEN_3A,
8859 pParsedFrame) != eSIR_SUCCESS ||
8860 !pParsedFrame->ssidPresent)
8861 {
8862 smsLog(pMac, LOGE,
8863 FL("Parse error ProbeResponse, length=%d"),
8864 pPrefNetworkFoundInd->frameLength);
Abhishek Singhc75726d2015-04-13 14:44:14 +05308865 vos_mem_vfree(pParsedFrame);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008866 return eHAL_STATUS_FAILURE;
8867 }
8868 //24 byte MAC header and 12 byte to ssid IE
8869 if (pPrefNetworkFoundInd->frameLength >
8870 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET))
8871 {
8872 uLen = pPrefNetworkFoundInd->frameLength -
8873 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET);
8874 }
8875
Kiet Lam64c1b492013-07-12 13:56:44 +05308876 pScanResult = vos_mem_malloc(sizeof(tCsrScanResult) + uLen);
8877 if ( NULL == pScanResult )
Srikant Kuppa066904f2013-05-07 13:56:02 -07008878 {
8879 smsLog(pMac, LOGE, FL(" fail to allocate memory for frame"));
8880 vos_mem_free(pParsedFrame);
8881 return eHAL_STATUS_RESOURCES;
8882 }
8883
Kiet Lam64c1b492013-07-12 13:56:44 +05308884 vos_mem_set(pScanResult, sizeof(tCsrScanResult) + uLen, 0);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008885 pBssDescr = &pScanResult->Result.BssDescriptor;
8886 /**
8887 * Length of BSS desription is without length of
8888 * length itself and length of pointer
8889 * that holds the next BSS description
8890 */
8891 pBssDescr->length = (tANI_U16)(
8892 sizeof(tSirBssDescription) - sizeof(tANI_U16) -
8893 sizeof(tANI_U32) + uLen);
8894 if (pParsedFrame->dsParamsPresent)
8895 {
8896 pBssDescr->channelId = pParsedFrame->channelNumber;
8897 }
8898 else if (pParsedFrame->HTInfo.present)
8899 {
8900 pBssDescr->channelId = pParsedFrame->HTInfo.primaryChannel;
8901 }
8902 else
8903 {
Mahesh A Saptasagaradd99792014-03-26 16:04:20 +05308904 /**
8905 * If Probe Responce received in PNO indication does not
8906 * contain DSParam IE or HT Info IE then add dummy channel
8907 * to the received BSS info so that Scan result received as
8908 * a part of PNO is updated to the supplicant. Specially
8909 * applicable in case of AP configured in 11A only mode.
8910 */
8911 if ((pMac->roam.configParam.bandCapability == eCSR_BAND_ALL) ||
8912 (pMac->roam.configParam.bandCapability == eCSR_BAND_24))
8913 {
8914 pBssDescr->channelId = 1;
8915 }
8916 else if(pMac->roam.configParam.bandCapability == eCSR_BAND_5G)
8917 {
8918 pBssDescr->channelId = 36;
8919 }
Abhishek Singhd3d4e022014-11-11 13:02:40 +05308920 /* Restrict the logic to ignore the pno indication for invalid channel
8921 * only if valid channel info is present in beacon/probe resp.
8922 * If no channel info is present in beacon/probe resp, always process
8923 * the pno indication.
8924 */
8925 bFoundonAppliedChannel = TRUE;
8926 }
8927
8928 if (0 != sme_GetCfgValidChannels(pMac, channelsAllowed, &numChannelsAllowed))
8929 {
8930 smsLog(pMac, LOGE, FL(" sme_GetCfgValidChannels failed "));
8931 csrFreeScanResultEntry(pMac, pScanResult);
Abhishek Singhc75726d2015-04-13 14:44:14 +05308932 vos_mem_vfree(pParsedFrame);
Abhishek Singhd3d4e022014-11-11 13:02:40 +05308933 return eHAL_STATUS_FAILURE;
8934 }
8935 /* Checking chhanelId with allowed channel list */
8936 for (indx = 0; indx < numChannelsAllowed; indx++)
8937 {
8938 if (pBssDescr->channelId == channelsAllowed[indx])
8939 {
8940 bFoundonAppliedChannel = TRUE;
8941 smsLog(pMac, LOG1, FL(" pno ind found on applied channel =%d\n "),
8942 pBssDescr->channelId);
8943 break;
8944 }
8945 }
8946 /* Ignore PNO indication if AP is on Invalid channel.
8947 */
8948 if(FALSE == bFoundonAppliedChannel)
8949 {
8950 smsLog(pMac, LOGW, FL(" prefered network found on invalid channel = %d"),
8951 pBssDescr->channelId);
8952 csrFreeScanResultEntry(pMac, pScanResult);
Abhishek Singhc75726d2015-04-13 14:44:14 +05308953 vos_mem_vfree(pParsedFrame);
Abhishek Singhd3d4e022014-11-11 13:02:40 +05308954 return eHAL_STATUS_FAILURE;
Srikant Kuppa066904f2013-05-07 13:56:02 -07008955 }
8956
8957 if ((pBssDescr->channelId > 0) && (pBssDescr->channelId < 15))
8958 {
8959 int i;
8960 // 11b or 11g packet
8961 // 11g iff extended Rate IE is present or
8962 // if there is an A rate in suppRate IE
8963 for (i = 0; i < pParsedFrame->supportedRates.numRates; i++)
8964 {
8965 if (sirIsArate(pParsedFrame->supportedRates.rate[i] & 0x7f))
8966 {
8967 pBssDescr->nwType = eSIR_11G_NW_TYPE;
8968 break;
8969 }
8970 }
8971 if (pParsedFrame->extendedRatesPresent)
8972 {
8973 pBssDescr->nwType = eSIR_11G_NW_TYPE;
8974 }
8975 }
8976 else
8977 {
8978 // 11a packet
8979 pBssDescr->nwType = eSIR_11A_NW_TYPE;
8980 }
8981
8982 pBssDescr->sinr = 0;
8983 pBssDescr->rssi = -1 * pPrefNetworkFoundInd->rssi;
8984 pBssDescr->beaconInterval = pParsedFrame->beaconInterval;
AnjaneeDevi Kapparapu4b043912014-02-18 13:22:35 +05308985 if (!pBssDescr->beaconInterval)
8986 {
8987 smsLog(pMac, LOGW,
8988 FL("Bcn Interval is Zero , default to 100" MAC_ADDRESS_STR),
8989 MAC_ADDR_ARRAY(pBssDescr->bssId) );
8990 pBssDescr->beaconInterval = 100;
8991 }
Srikant Kuppa066904f2013-05-07 13:56:02 -07008992 pBssDescr->timeStamp[0] = pParsedFrame->timeStamp[0];
8993 pBssDescr->timeStamp[1] = pParsedFrame->timeStamp[1];
8994 pBssDescr->capabilityInfo = *((tANI_U16 *)&pParsedFrame->capabilityInfo);
Kiet Lam64c1b492013-07-12 13:56:44 +05308995 vos_mem_copy((tANI_U8 *) &pBssDescr->bssId, (tANI_U8 *) macHeader->bssId, sizeof(tSirMacAddr));
Deepthi Gowri4480a3f2016-05-18 19:30:17 +05308996 pBssDescr->nReceivedTime = vos_timer_get_system_time();
Srikant Kuppa066904f2013-05-07 13:56:02 -07008997
Abhishek Singh195c03e2014-05-14 17:21:30 +05308998 smsLog( pMac, LOG1, FL("Bssid= "MAC_ADDRESS_STR
8999 " chan= %d, rssi = %d "),
Arif Hussain24bafea2013-11-15 15:10:03 -08009000 MAC_ADDR_ARRAY(pBssDescr->bssId),
Srikant Kuppa066904f2013-05-07 13:56:02 -07009001 pBssDescr->channelId,
Abhishek Singh195c03e2014-05-14 17:21:30 +05309002 pBssDescr->rssi);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009003
9004 //IEs
9005 if (uLen)
9006 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309007 vos_mem_copy(&pBssDescr->ieFields,
9008 pPrefNetworkFoundInd->data + (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET),
9009 uLen);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009010 }
9011
9012 pIesLocal = (tDot11fBeaconIEs *)( pScanResult->Result.pvIes );
9013 if ( !pIesLocal &&
9014 (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
9015 &pScanResult->Result.BssDescriptor, &pIesLocal))) )
9016 {
9017 smsLog(pMac, LOGE, FL(" Cannot parse IEs"));
9018 csrFreeScanResultEntry(pMac, pScanResult);
Abhishek Singhc75726d2015-04-13 14:44:14 +05309019 vos_mem_vfree(pParsedFrame);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009020 return eHAL_STATUS_RESOURCES;
9021 }
9022
9023 fDupBss = csrRemoveDupBssDescription( pMac,
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05309024 &pScanResult->Result.BssDescriptor, pIesLocal, &tmpSsid, &timer, FALSE);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009025 //Check whether we have reach out limit
9026 if ( CSR_SCAN_IS_OVER_BSS_LIMIT(pMac) )
9027 {
9028 //Limit reach
9029 smsLog(pMac, LOGE, FL(" BSS limit reached"));
9030 //Free the resources
9031 if( (pScanResult->Result.pvIes == NULL) && pIesLocal )
9032 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309033 vos_mem_free(pIesLocal);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009034 }
9035 csrFreeScanResultEntry(pMac, pScanResult);
9036 vos_mem_free(pParsedFrame);
9037 return eHAL_STATUS_RESOURCES;
9038 }
Nalla Kartheek71946422015-09-15 14:41:22 +05309039
9040 if ((macHeader->fc.type == SIR_MAC_MGMT_FRAME) &&
9041 (macHeader->fc.subType == SIR_MAC_MGMT_PROBE_RSP))
9042 {
9043 pScanResult->Result.BssDescriptor.fProbeRsp = 1;
9044 }
Srikant Kuppa066904f2013-05-07 13:56:02 -07009045 //Add to scan cache
9046 csrScanAddResult(pMac, pScanResult, pIesLocal);
Sushant Kaushik6274de62015-05-01 16:31:23 +05309047 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
Kiet Lamb537cfb2013-11-07 12:56:49 +05309048 if( (pScanResult->Result.pvIes == NULL) && pIesLocal )
9049 {
9050 vos_mem_free(pIesLocal);
9051 }
9052
Abhishek Singhc75726d2015-04-13 14:44:14 +05309053 vos_mem_vfree(pParsedFrame);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009054
9055 return eHAL_STATUS_SUCCESS;
9056}
Manjunathappa Prakash4f1d5a52013-11-11 16:22:19 -08009057#endif //FEATURE_WLAN_SCAN_PNO
Srikant Kuppa066904f2013-05-07 13:56:02 -07009058
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08009059#ifdef FEATURE_WLAN_LFR
9060void csrInitOccupiedChannelsList(tpAniSirGlobal pMac)
9061{
9062 tListElem *pEntry = NULL;
9063 tCsrScanResult *pBssDesc = NULL;
9064 tDot11fBeaconIEs *pIes = NULL;
Srinivas28b5b4e2012-12-12 13:07:53 -08009065 tpCsrNeighborRoamControlInfo pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
9066
9067 if (0 != pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels)
9068 {
9069 smsLog(pMac, LOG1, FL("%s: Ini file contains neighbor scan channel list,"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08009070 " hence NO need to build occupied channel list (numChannels = %d)"),
Srinivas28b5b4e2012-12-12 13:07:53 -08009071 __func__, pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels);
9072 return;
9073 }
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08009074
9075 if (!csrNeighborRoamIsNewConnectedProfile(pMac))
9076 {
9077 smsLog(pMac, LOG2, FL("%s: donot flush occupied list since current roam profile"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08009078 " matches previous (numChannels = %d)"),
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08009079 __func__, pMac->scan.occupiedChannels.numChannels);
9080 return;
9081 }
9082
9083 /* Empty occupied channels here */
9084 pMac->scan.occupiedChannels.numChannels = 0;
9085
9086 csrLLLock(&pMac->scan.scanResultList);
9087 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
9088 while( pEntry )
9089 {
9090 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
9091 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
9092
9093 //At this time, pBssDescription->Result.pvIes may be NULL
Srikant Kuppa866893f2012-12-27 17:28:14 -08009094 if( !pIes && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08009095 &pBssDesc->Result.BssDescriptor, &pIes))) )
9096 {
9097 continue;
9098 }
9099
9100 csrScanAddToOccupiedChannels(pMac, pBssDesc, &pMac->scan.occupiedChannels, pIes);
9101
9102 /*
9103 * Free the memory allocated for pIes in csrGetParsedBssDescriptionIEs
9104 */
9105 if( (pBssDesc->Result.pvIes == NULL) && pIes )
9106 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309107 vos_mem_free(pIes);
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08009108 }
9109
9110 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK );
9111 }//while
9112 csrLLUnlock(&pMac->scan.scanResultList);
Srikant Kuppa866893f2012-12-27 17:28:14 -08009113
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08009114}
9115#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009116
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009117eHalStatus csrScanCreateEntryInScanCache(tpAniSirGlobal pMac, tANI_U32 sessionId,
9118 tCsrBssid bssid, tANI_U8 channel)
9119{
9120 eHalStatus status = eHAL_STATUS_SUCCESS;
9121 tDot11fBeaconIEs *pNewIes = NULL;
9122 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
Praveen Kumar Sirisilla8bdfac42013-10-10 17:20:48 -07009123 tSirBssDescription *pNewBssDescriptor = NULL;
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009124 tANI_U32 size = 0;
9125
9126 if(NULL == pSession)
9127 {
9128 status = eHAL_STATUS_FAILURE;
9129 return status;
9130 }
9131 smsLog(pMac, LOG2, FL("csrScanCreateEntryInScanCache: Current bssid::"
Arif Hussain24bafea2013-11-15 15:10:03 -08009132 MAC_ADDRESS_STR),
9133 MAC_ADDR_ARRAY(pSession->pConnectBssDesc->bssId));
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009134 smsLog(pMac, LOG2, FL("csrScanCreateEntryInScanCache: My bssid::"
Arif Hussain24bafea2013-11-15 15:10:03 -08009135 MAC_ADDRESS_STR" channel %d"),
9136 MAC_ADDR_ARRAY(bssid), channel);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009137
9138 do
9139 {
9140 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
9141 pSession->pConnectBssDesc, &pNewIes)))
9142 {
9143 smsLog(pMac, LOGE, FL("%s: Failed to parse IEs"),
9144 __func__);
9145 status = eHAL_STATUS_FAILURE;
9146 break;
9147 }
9148
9149 size = pSession->pConnectBssDesc->length + sizeof(pSession->pConnectBssDesc->length);
Kiet Lam64c1b492013-07-12 13:56:44 +05309150 if (size)
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009151 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309152 pNewBssDescriptor = vos_mem_malloc(size);
9153 if ( NULL == pNewBssDescriptor )
9154 status = eHAL_STATUS_FAILURE;
9155 else
9156 status = eHAL_STATUS_SUCCESS;
9157 if (HAL_STATUS_SUCCESS(status))
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009158 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309159 vos_mem_copy(pNewBssDescriptor, pSession->pConnectBssDesc, size);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009160 }
9161 else
9162 {
9163 smsLog(pMac, LOGE, FL("%s: memory allocation failed"),
9164 __func__);
9165 status = eHAL_STATUS_FAILURE;
9166 break;
9167 }
9168
9169 //change the BSSID & channel as passed
Kiet Lam64c1b492013-07-12 13:56:44 +05309170 vos_mem_copy(pNewBssDescriptor->bssId, bssid, sizeof(tSirMacAddr));
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009171 pNewBssDescriptor->channelId = channel;
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07009172 if(NULL == csrScanAppendBssDescription( pMac, pNewBssDescriptor, pNewIes, TRUE ))
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009173 {
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07009174 smsLog(pMac, LOGE, FL("%s: csrScanAppendBssDescription failed"),
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009175 __func__);
9176 status = eHAL_STATUS_FAILURE;
9177 break;
9178 }
9179 }
9180 else
9181 {
9182 smsLog(pMac, LOGE, FL("%s: length of bss descriptor is 0"),
9183 __func__);
9184 status = eHAL_STATUS_FAILURE;
9185 break;
9186 }
9187 smsLog(pMac, LOGE, FL("%s: entry successfully added in scan cache"),
9188 __func__);
9189 }while(0);
9190
9191 if(pNewIes)
9192 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309193 vos_mem_free(pNewIes);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009194 }
9195 if(pNewBssDescriptor)
9196 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309197 vos_mem_free(pNewBssDescriptor);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009198 }
9199 return status;
9200}
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07009201
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08009202#ifdef FEATURE_WLAN_ESE
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07009203// Update the TSF with the difference in system time
9204void UpdateCCKMTSF(tANI_U32 *timeStamp0, tANI_U32 *timeStamp1, tANI_U32 *incr)
9205{
9206 tANI_U64 timeStamp64 = ((tANI_U64)*timeStamp1 << 32) | (*timeStamp0);
9207
9208 timeStamp64 = (tANI_U64)(timeStamp64 + (tANI_U64)*incr);
9209 *timeStamp0 = (tANI_U32)(timeStamp64 & 0xffffffff);
9210 *timeStamp1 = (tANI_U32)((timeStamp64 >> 32) & 0xffffffff);
9211}
9212#endif