blob: 6f66e9dbe092a87b1469954c171455b0811c2a20 [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
Abhishek Singh72c2f4e2016-07-22 11:25:43 +05301749 csrRoamCallCallback(pMac, sessionId, NULL,
1750 pCommand->u.scanCmd.roamId,
1751 eCSR_ROAM_ASSOCIATION_FAILURE,
1752 eCSR_ROAM_RESULT_SCAN_FOR_SSID_FAILURE);
Jeff Johnson295189b2012-06-20 16:38:30 -07001753 //In case we have nothing else to do, restart idle scan
1754 if(csrIsConnStateDisconnected(pMac, sessionId) && !csrIsRoamCommandWaiting(pMac))
1755 {
1756 status = csrScanStartIdleScan(pMac);
1757 }
1758#ifdef FEATURE_WLAN_BTAMP_UT_RF
1759 //In case of WDS station, let it retry.
1760 if( CSR_IS_WDS_STA(pProfile) )
1761 {
1762 //Save the roma profile so we can retry
1763 csrFreeRoamProfile( pMac, sessionId );
Kiet Lam64c1b492013-07-12 13:56:44 +05301764 pSession->pCurRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1765 if ( NULL != pSession->pCurRoamProfile )
Jeff Johnson295189b2012-06-20 16:38:30 -07001766 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301767 vos_mem_set(pSession->pCurRoamProfilee, sizeof(tCsrRoamProfile), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001768 csrRoamCopyProfile(pMac, pSession->pCurRoamProfile, pProfile);
1769 }
1770 csrRoamStartJoinRetryTimer(pMac, sessionId, CSR_JOIN_RETRY_TIMEOUT_PERIOD);
1771 }
1772#endif
1773 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301774 if (pScanFilter)
Jeff Johnson295189b2012-06-20 16:38:30 -07001775 {
1776 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301777 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001778 }
1779
1780 return (status);
1781}
1782
1783
1784eHalStatus csrScanHandleSearchForSSIDFailure(tpAniSirGlobal pMac, tSmeCmd *pCommand)
1785{
1786 eHalStatus status = eHAL_STATUS_SUCCESS;
1787 tANI_U32 sessionId = pCommand->sessionId;
1788 tCsrRoamProfile *pProfile = pCommand->u.scanCmd.pToRoamProfile;
1789 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001790#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
1791 //if this scan is for LFR
1792 if(pMac->roam.neighborRoamInfo.uOsRequestedHandoff)
1793 {
1794 //notify LFR state m/c
1795 if(eHAL_STATUS_SUCCESS != csrNeighborRoamSssidScanDone(pMac, eHAL_STATUS_FAILURE))
1796 {
Mukul Sharma20aa6582014-08-07 21:36:12 +05301797 csrNeighborRoamStartLfrScan(pMac, REASON_OS_REQUESTED_ROAMING_NOW);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001798 }
1799 return eHAL_STATUS_SUCCESS;
1800 }
1801#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -07001802 if(!pSession)
1803 {
1804 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1805 return eHAL_STATUS_FAILURE;
1806 }
1807
Jeff Johnson295189b2012-06-20 16:38:30 -07001808#if defined(WLAN_DEBUG)
1809 if(pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs == 1)
1810 {
1811 char str[36];
Kiet Lam64c1b492013-07-12 13:56:44 +05301812 vos_mem_copy(str,
1813 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.ssId,
1814 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.length);
Jeff Johnson295189b2012-06-20 16:38:30 -07001815 str[pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.length] = 0;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001816 smsLog(pMac, LOGW, FL(" SSID = %s"), str);
Jeff Johnson295189b2012-06-20 16:38:30 -07001817 }
1818#endif
1819 //Check whether it is for start ibss. No need to do anything if it is a JOIN request
1820 if(pProfile && CSR_IS_START_IBSS(pProfile))
1821 {
1822 status = csrRoamIssueConnect(pMac, sessionId, pProfile, NULL, eCsrHddIssued,
1823 pCommand->u.scanCmd.roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1824 if(!HAL_STATUS_SUCCESS(status))
1825 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001826 smsLog(pMac, LOGE, FL("failed to issue startIBSS command with status = 0x%08X"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001827 csrRoamCallCallback(pMac, sessionId, NULL, pCommand->u.scanCmd.roamId, eCSR_ROAM_FAILED, eCSR_ROAM_RESULT_FAILURE);
1828 }
1829 }
1830 else
1831 {
1832 eCsrRoamResult roamResult = eCSR_ROAM_RESULT_FAILURE;
1833
1834 if(csrIsConnStateDisconnected(pMac, sessionId) &&
1835 !csrIsRoamCommandWaitingForSession(pMac, sessionId))
1836 {
1837 status = csrScanStartIdleScan(pMac);
1838 }
1839 if((NULL == pProfile) || !csrIsBssTypeIBSS(pProfile->BSSType))
1840 {
1841 //Only indicate assoc_completion if we indicate assoc_start.
1842 if(pSession->bRefAssocStartCnt > 0)
1843 {
1844 tCsrRoamInfo *pRoamInfo = NULL, roamInfo;
Kiet Lam64c1b492013-07-12 13:56:44 +05301845 vos_mem_set(&roamInfo, sizeof(tCsrRoamInfo), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001846 pRoamInfo = &roamInfo;
1847 if(pCommand->u.roamCmd.pRoamBssEntry)
1848 {
1849 tCsrScanResult *pScanResult =
1850 GET_BASE_ADDR(pCommand->u.roamCmd.pRoamBssEntry,
1851 tCsrScanResult, Link);
1852 roamInfo.pBssDesc = &pScanResult->Result.BssDescriptor;
1853 }
1854 roamInfo.statusCode = pSession->joinFailStatusCode.statusCode;
1855 roamInfo.reasonCode = pSession->joinFailStatusCode.reasonCode;
1856 pSession->bRefAssocStartCnt--;
1857 csrRoamCallCallback(pMac, sessionId, pRoamInfo,
1858 pCommand->u.scanCmd.roamId,
1859 eCSR_ROAM_ASSOCIATION_COMPLETION,
Abhishek Singh72c2f4e2016-07-22 11:25:43 +05301860 eCSR_ROAM_RESULT_SCAN_FOR_SSID_FAILURE);
Jeff Johnson295189b2012-06-20 16:38:30 -07001861 }
Madan Mohan Koyyalamudiee255f12012-09-28 15:41:19 -07001862 else
1863 {
1864 csrRoamCallCallback(pMac, sessionId, NULL,
1865 pCommand->u.scanCmd.roamId,
1866 eCSR_ROAM_ASSOCIATION_FAILURE,
Abhishek Singh72c2f4e2016-07-22 11:25:43 +05301867 eCSR_ROAM_RESULT_SCAN_FOR_SSID_FAILURE);
Madan Mohan Koyyalamudiee255f12012-09-28 15:41:19 -07001868 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001869#ifdef FEATURE_WLAN_BTAMP_UT_RF
1870 //In case of WDS station, let it retry.
1871 if( CSR_IS_WDS_STA(pProfile) )
1872 {
1873 //Save the roma profile so we can retry
1874 csrFreeRoamProfile( pMac, sessionId );
Kiet Lam64c1b492013-07-12 13:56:44 +05301875 pSession->pCurRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1876 if ( NULL != pSession->pCurRoamProfile )
Jeff Johnson295189b2012-06-20 16:38:30 -07001877 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301878 vos_mem_set(pSession->pCurRoamProfile, sizeof(tCsrRoamProfile), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001879 csrRoamCopyProfile(pMac, pSession->pCurRoamProfile, pProfile);
1880 }
1881 csrRoamStartJoinRetryTimer(pMac, sessionId, CSR_JOIN_RETRY_TIMEOUT_PERIOD);
1882 }
1883#endif
1884 }
1885 else
1886 {
1887 roamResult = eCSR_ROAM_RESULT_IBSS_START_FAILED;
1888 }
1889 csrRoamCompletion(pMac, sessionId, NULL, pCommand, roamResult, eANI_BOOLEAN_FALSE);
1890 }
1891
1892 return (status);
1893}
1894
1895
1896//After scan for cap changes, issue a roaming command to either reconnect to the AP or pick another one to connect
1897eHalStatus csrScanHandleCapChangeScanComplete(tpAniSirGlobal pMac, tANI_U32 sessionId)
1898{
1899 eHalStatus status = eHAL_STATUS_FAILURE;
1900 tScanResultHandle hBSSList = NULL;
1901 tCsrScanResultFilter *pScanFilter = NULL;
1902 tANI_U32 roamId = 0;
1903 tCsrRoamProfile *pProfile = NULL;
1904 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1905
1906 do
1907 {
1908 //Here is the profile we need to connect to
Kiet Lam64c1b492013-07-12 13:56:44 +05301909 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1910 if ( NULL == pScanFilter )
1911 status = eHAL_STATUS_FAILURE;
1912 else
1913 status = eHAL_STATUS_SUCCESS;
1914 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001915 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301916 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
1917 if (NULL == pSession) break;
1918 if (NULL == pSession->pCurRoamProfile)
Jeff Johnson295189b2012-06-20 16:38:30 -07001919 {
1920 pScanFilter->EncryptionType.numEntries = 1;
1921 pScanFilter->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_NONE;
1922 }
1923 else
1924 {
1925 //We have to make a copy of pCurRoamProfile because it will be free inside csrRoamIssueConnect
Kiet Lam64c1b492013-07-12 13:56:44 +05301926 pProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1927 if ( NULL == pProfile )
1928 status = eHAL_STATUS_FAILURE;
1929 else
1930 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001931 if(!HAL_STATUS_SUCCESS(status))
1932 break;
1933 status = csrRoamCopyProfile(pMac, pProfile, pSession->pCurRoamProfile);
1934 if(!HAL_STATUS_SUCCESS(status))
1935 break;
1936 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1937 }//We have a profile
1938 roamId = GET_NEXT_ROAM_ID(&pMac->roam);
1939 if(HAL_STATUS_SUCCESS(status))
1940 {
1941 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1942 if(HAL_STATUS_SUCCESS(status))
1943 {
1944 //we want to put the last connected BSS to the very beginning, if possible
1945 csrMoveBssToHeadFromBSSID(pMac, &pSession->connectedProfile.bssid, hBSSList);
1946 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList,
1947 eCsrCapsChange, 0, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1948 if(!HAL_STATUS_SUCCESS(status))
1949 {
1950 csrScanResultPurge(pMac, hBSSList);
1951 }
1952 }//Have scan result
1953 else
1954 {
Arif Hussaina7c8e412013-11-20 11:06:42 -08001955 smsLog(pMac, LOGW, FL("cannot find matching BSS of "
1956 MAC_ADDRESS_STR),
1957 MAC_ADDR_ARRAY(pSession->connectedProfile.bssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001958 //Disconnect
1959 csrRoamDisconnectInternal(pMac, sessionId, eCSR_DISCONNECT_REASON_UNSPECIFIED);
1960 }
1961 }
1962 }while(0);
1963 if(pScanFilter)
1964 {
1965 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301966 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001967 }
1968 if(NULL != pProfile)
1969 {
1970 csrReleaseProfile(pMac, pProfile);
Kiet Lam64c1b492013-07-12 13:56:44 +05301971 vos_mem_free(pProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07001972 }
1973
1974 return (status);
1975}
1976
1977
1978
1979eHalStatus csrScanResultPurge(tpAniSirGlobal pMac, tScanResultHandle hScanList)
1980{
1981 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
1982 tScanResultList *pScanList = (tScanResultList *)hScanList;
1983
1984 if(pScanList)
1985 {
1986 status = csrLLScanPurgeResult(pMac, &pScanList->List);
1987 csrLLClose(&pScanList->List);
Kiet Lam64c1b492013-07-12 13:56:44 +05301988 vos_mem_free(pScanList);
Jeff Johnson295189b2012-06-20 16:38:30 -07001989 }
1990 return (status);
1991}
1992
1993
1994static tANI_U32 csrGetBssPreferValue(tpAniSirGlobal pMac, int rssi)
1995{
1996 tANI_U32 ret = 0;
1997 int i = CSR_NUM_RSSI_CAT - 1;
1998
1999 while(i >= 0)
2000 {
2001 if(rssi >= pMac->roam.configParam.RSSICat[i])
2002 {
2003 ret = pMac->roam.configParam.BssPreferValue[i];
2004 break;
2005 }
2006 i--;
2007 };
2008
2009 return (ret);
2010}
2011
2012
2013//Return a CapValue base on the capabilities of a BSS
2014static tANI_U32 csrGetBssCapValue(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes)
2015{
2016 tANI_U32 ret = CSR_BSS_CAP_VALUE_NONE;
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08002017#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_ESE) || defined(FEATURE_WLAN_LFR)
Madan Mohan Koyyalamudid5026072012-11-30 14:56:21 -08002018 if(CSR_IS_ROAM_PREFER_5GHZ(pMac))
2019 {
2020 if((pBssDesc) && CSR_IS_CHANNEL_5GHZ(pBssDesc->channelId))
2021 {
2022 ret += CSR_BSS_CAP_VALUE_5GHZ;
2023 }
2024 }
2025#endif
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002026 /* if strict select 5GHz is non-zero then ignore the capability checking */
2027 if (pIes && !CSR_IS_SELECT_5GHZ_MARGIN(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -07002028 {
2029 //We only care about 11N capability
2030 if(pIes->HTCaps.present)
2031 {
2032 ret += CSR_BSS_CAP_VALUE_HT;
2033 }
2034 if(CSR_IS_QOS_BSS(pIes))
2035 {
2036 ret += CSR_BSS_CAP_VALUE_WMM;
2037 //Give advantage to UAPSD
2038 if(CSR_IS_UAPSD_BSS(pIes))
2039 {
2040 ret += CSR_BSS_CAP_VALUE_UAPSD;
2041 }
2042 }
2043 }
2044
2045 return (ret);
2046}
2047
Kapil Guptab3a981b2016-06-26 13:36:51 +05302048#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
2049
2050/* Calculate channel weight based on other APs RSSI and count for
2051 * PER based roaming */
2052static tANI_U32 GetPERRoamRssiCountWeight(tANI_S32 rssi, tANI_S32 count)
2053{
2054 tANI_S32 rssiWeight=0;
2055 tANI_S32 countWeight=0;
2056 tANI_S32 rssicountWeight=0;
2057
2058 rssiWeight = ROAMING_RSSI_WEIGHT * (rssi - MIN_RSSI)
2059 /(MAX_RSSI - MIN_RSSI);
2060
2061 if(rssiWeight > ROAMING_RSSI_WEIGHT)
2062 rssiWeight = ROAMING_RSSI_WEIGHT;
2063 else if (rssiWeight < 0)
2064 rssiWeight = 0;
2065
2066 countWeight = ROAM_AP_COUNT_WEIGHT * (count + ROAM_MIN_COUNT)
2067 /(ROAM_MAX_COUNT + ROAM_MIN_COUNT);
2068
2069 if(countWeight > ROAM_AP_COUNT_WEIGHT)
2070 countWeight = ROAM_AP_COUNT_WEIGHT;
2071
2072 rssicountWeight = ROAM_MAX_WEIGHT - (rssiWeight + countWeight);
2073
2074 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO_HIGH,
2075 FL("rssiWeight=%d, countWeight=%d, rssicountWeight=%d rssi=%d count=%d"),
2076 rssiWeight, countWeight, rssicountWeight, rssi, count);
2077
2078 return rssicountWeight;
2079}
2080
2081/* Calculate BSS score based on AP capabilty and channel condition
2082 * for PER based roaming */
2083static tANI_U32 calculateBssScore(tSirBssDescription *bssInfo,
2084 tANI_S32 best_rssi, tANI_S32 ap_cnt, tANI_S32 cca)
2085{
2086 tANI_S32 score = 0;
2087 tANI_S32 ap_load = 0;
2088 tANI_S32 normalised_width = PER_ROAM_20MHZ;
Sen, Devendra6940d0c2016-09-07 12:42:46 +05302089 tANI_S32 normalised_rssi = 0;
Kapil Guptab3a981b2016-06-26 13:36:51 +05302090 tANI_S32 channel_weight;
2091 if (bssInfo->rssi) {
2092 /* Calculate % of rssi we are getting
2093 * max = 100
2094 * min = 0
2095 * less than -40 = 100%
2096 * -40 - -55 = 80%
2097 * -55 - -65 = 60%
2098 * below that = 100 - value
2099 * TODO: a linear decrement function after PER_ROAM_GOOD_RSSI_WEIGHT
2100 * since throughput decrements linearly after PER_ROAM_GOOD_RSSI_WEIGHT
2101 **/
2102 if (bssInfo->rssi >= PER_EXCELENT_RSSI)
2103 normalised_rssi = PER_ROAM_EXCELLENT_RSSI_WEIGHT;
2104 else if (bssInfo->rssi >= PER_GOOD_RSSI)
2105 normalised_rssi = PER_ROAM_GOOD_RSSI_WEIGHT;
2106 else if (bssInfo->rssi >= PER_POOR_RSSI)
2107 normalised_rssi = PER_ROAM_BAD_RSSI_WEIGHT;
2108 else
2109 normalised_rssi = bssInfo->rssi - MIN_RSSI;
2110
2111 /* Calculate score part for rssi */
2112 score += (normalised_rssi * RSSI_WEIGHTAGE);
2113 }
2114
2115 if (bssInfo->HTCapsPresent) {
2116 score += PER_ROAM_MAX_WEIGHT * HT_CAPABILITY_WEIGHTAGE;
2117 }
2118 /* VHT caps are available */
2119 if (bssInfo->vhtCapsPresent) {
2120 score += PER_ROAM_MAX_WEIGHT * VHT_CAP_WEIGHTAGE;
2121 }
2122
2123 if (bssInfo->beacomformingCapable)
2124 score += PER_ROAM_MAX_WEIGHT * BEAMFORMING_CAP_WEIGHTAGE;
2125
2126 /* Channel width 20Mhz=30, 40Mhz=70, 80Mhz=100 */
2127 if (bssInfo->chanWidth == eHT_CHANNEL_WIDTH_80MHZ)
2128 normalised_width = PER_ROAM_80MHZ;
2129 else if (bssInfo->chanWidth == eHT_CHANNEL_WIDTH_40MHZ)
2130 normalised_width = PER_ROAM_40MHZ;
2131 else
2132 normalised_width = PER_ROAM_20MHZ;
2133 score += normalised_width * CHAN_WIDTH_WEIGHTAGE;
2134
2135 /* Channel Band, Channel Number */
2136 if (GetRFBand(bssInfo->channelId) == SIR_BAND_5_GHZ)
2137 score += PER_ROAM_MAX_WEIGHT * CHAN_BAND_WEIGHTAGE;
2138
2139 /* WMM emabled */
2140 if (bssInfo->wmeInfoPresent)
2141 score += PER_ROAM_MAX_WEIGHT * WMM_WEIGHTAGE;
2142
2143#if defined(FEATURE_WLAN_ESE) || defined(WLAN_FEATURE_ROAM_SCAN_OFFLOAD)
2144 /* AP load Ie */
2145 if (bssInfo->QBSSLoad_present) {
2146 /* calculate value in % */
2147 ap_load = (bssInfo->QBSS_ChanLoad * PER_ROAM_MAX_WEIGHT) / MAX_AP_LOAD;
2148 }
2149#endif
2150 //TODO we don't have this info for current AP, need to check
2151 /* if CCA consideration is off in configuration, FW will send 50% for
2152 every channel which should be considered as it is */
2153 if (ap_load)
2154 score += (100 - ap_load) * CCA_WEIGHTAGE;
2155 else
2156 score += (100 - cca) * CCA_WEIGHTAGE;
2157
2158 channel_weight = GetPERRoamRssiCountWeight(best_rssi, ap_cnt);
2159
2160 score += channel_weight * OTHER_AP_WEIGHT;
2161
2162 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO_LOW,
2163 FL("rssi=%d normalized_rssi=%d htcaps=%d vht=%d bw=%d channel=%d wmm=%d beamforming=%d ap_load=%d channel_weight=%d"),
2164 bssInfo->rssi, normalised_rssi, bssInfo->HTCapsPresent,
2165 bssInfo->vhtCapsPresent, bssInfo->chanWidth,
2166 bssInfo->channelId, bssInfo->wmeInfoPresent,
2167 bssInfo->beacomformingCapable, ap_load, channel_weight);
2168 return score;
2169}
2170
2171/* Calculate candidate AP score for PER based roaming */
2172static tANI_S32 csrFindCongestionScore (tpAniSirGlobal pMac, tCsrScanResult *pBss)
2173{
2174 tANI_S32 score = 0;
2175 tANI_S32 i;
2176 tANI_S32 candidateApCnt, best_rssi, other_ap_cnt;
2177 tANI_U32 current_timestamp;
2178 tpCsrNeighborRoamControlInfo pNeighborRoamInfo =
2179 &pMac->roam.neighborRoamInfo;
2180
2181 tSirBssDescription *bssInfo = &(pBss->Result.BssDescriptor);
2182 pBss->congestionScore = 0;
2183 for (i = 0; i < pMac->PERroamCandidatesCnt; i++)
2184 if (pMac->candidateChannelInfo[i].channelNumber ==
2185 pBss->Result.BssDescriptor.channelId)
2186 break;
2187
2188 if (i == SIR_PER_ROAM_MAX_CANDIDATE_CNT) {
2189 smsLog(pMac, LOGE,
2190 FL("candidate chan info not found for channel %d bssid "
2191 MAC_ADDRESS_STR), pBss->Result.BssDescriptor.channelId,
2192 MAC_ADDR_ARRAY(pBss->Result.BssDescriptor.bssId));
2193 return -1;
2194 }
2195
2196 /* find best RSSI of other AP in this channel */
2197 best_rssi = MIN_RSSI;
2198 for (other_ap_cnt = 0; other_ap_cnt <
2199 pMac->candidateChannelInfo[i].otherApCount; other_ap_cnt++) {
2200 if (pMac->candidateChannelInfo[i].otherApRssi[other_ap_cnt] > best_rssi)
2201 best_rssi = pMac->candidateChannelInfo[i].otherApRssi[other_ap_cnt];
2202 }
2203
2204 score = calculateBssScore(bssInfo, best_rssi,
2205 pMac->candidateChannelInfo[i].otherApCount,
2206 pMac->candidateChannelInfo[i].channelCCA);
2207 current_timestamp = jiffies_to_msecs(jiffies);
2208
2209 /* penalty logic */
2210
2211 /* In the previous list */
2212 for (candidateApCnt = 0; candidateApCnt <
2213 SIR_PER_ROAM_MAX_CANDIDATE_CNT; candidateApCnt++) {
2214 if (sirCompareMacAddr(pMac->previousRoamApInfo[candidateApCnt].bssAddr,
2215 pBss->Result.BssDescriptor.bssId) &&
2216 ((current_timestamp - pMac->previousRoamApInfo[candidateApCnt].timeStamp) <
2217 PENALTY_TIMEOUT)) {
2218 score = (score * PENALTY_REMAINING_SCORE)/PENALTY_TOTAL_SCORE;
2219 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
2220 FL("AP BSSID " MAC_ADDRESS_STR "adding penalty(in previous list)new score %d"),
2221 MAC_ADDR_ARRAY(pBss->Result.BssDescriptor.bssId),
2222 score);
2223 break;
2224 }
2225 }
2226 /* preauth failed last time */
2227 for (candidateApCnt = 0; candidateApCnt <
2228 MAX_NUM_PREAUTH_FAIL_LIST_ADDRESS; candidateApCnt++) {
2229 if (sirCompareMacAddr(pNeighborRoamInfo->FTRoamInfo.
2230 preAuthFailList.macAddress[candidateApCnt],
2231 pBss->Result.BssDescriptor.bssId)) {
2232 score = (score * PENALTY_REMAINING_SCORE)/PENALTY_TOTAL_SCORE;
2233 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
2234 FL("AP BSSID " MAC_ADDRESS_STR "adding penalty(previously auth failed)new score %d"),
2235 MAC_ADDR_ARRAY(pBss->Result.BssDescriptor.bssId),
2236 score);
2237 break;
2238 }
2239 }
2240 pBss->congestionScore = score;
2241
2242 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
2243 FL("AP BSSID " MAC_ADDRESS_STR " score %d channel %d"),
2244 MAC_ADDR_ARRAY(pBss->Result.BssDescriptor.bssId),
2245 score, pBss->Result.BssDescriptor.channelId);
2246 return 0;
2247}
2248
2249/* Calculate current AP score for PER based roaming */
2250static tANI_S32 csrFindSelfCongestionScore(tpAniSirGlobal pMac,
2251 tSirBssDescription *bssInfo)
2252{
2253 tANI_S32 i, best_rssi, other_ap_cnt;
2254 tANI_S32 score = 0;
Kapil Guptac6ac4772016-08-05 20:25:16 +05302255 tCsrRoamSession *pSession = CSR_GET_SESSION(pMac,
2256 pMac->roam.roamSession->sessionId);
2257
2258 if (pSession == NULL)
2259 return -1;
Kapil Guptab3a981b2016-06-26 13:36:51 +05302260
2261 for (i = 0; i <= pMac->PERroamCandidatesCnt; i++)
2262 if (pMac->candidateChannelInfo[i].channelNumber == bssInfo->channelId)
2263 break;
2264 if (i > pMac->PERroamCandidatesCnt) {
2265 /* home channel info is not present, no need to roam */
2266 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR,
2267 FL("home channel %d congestion info not present"),
2268 bssInfo->channelId);
2269 pMac->currentBssScore = PER_ROAM_MAX_BSS_SCORE;
2270 return -1;
2271 }
2272
2273 /* find best RSSI of other AP in this channel */
2274 best_rssi = MIN_RSSI;
2275 for (other_ap_cnt = 0; other_ap_cnt <
2276 pMac->candidateChannelInfo[i].otherApCount; other_ap_cnt++) {
2277 if (pMac->candidateChannelInfo[i].otherApRssi[other_ap_cnt] > best_rssi)
2278 best_rssi = pMac->candidateChannelInfo[i].otherApRssi[other_ap_cnt];
2279 }
2280
Kapil Guptac6ac4772016-08-05 20:25:16 +05302281 /* update latest RSSI for current AP */
2282 WLANTL_GetRssi(vos_get_global_context(VOS_MODULE_ID_SME, NULL),
2283 pSession->connectedInfo.staId,
2284 &bssInfo->rssi);
2285
Kapil Guptab3a981b2016-06-26 13:36:51 +05302286 score = calculateBssScore(bssInfo, best_rssi,
2287 pMac->candidateChannelInfo[i].otherApCount,
2288 pMac->candidateChannelInfo[i].channelCCA);
2289 pMac->currentBssScore = score;
2290 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
2291 FL("PER Roam Current AP score %d channel %d"),
2292 score, bssInfo->channelId);
2293 return 0;
2294}
2295
Kapil Guptab79e76f2016-09-12 20:04:37 +05302296
Kapil Guptab3a981b2016-06-26 13:36:51 +05302297static tANI_BOOLEAN csrIsBetterBssInCongestion(tCsrScanResult *pBss1,
2298 tCsrScanResult *pBss2)
2299{
2300 tANI_BOOLEAN ret;
2301
2302 if(CSR_IS_BETTER_PREFER_VALUE(pBss1->congestionScore,
2303 pBss2->congestionScore))
2304 ret = eANI_BOOLEAN_TRUE;
2305 else
2306 ret = eANI_BOOLEAN_FALSE;
2307
2308 return (ret);
2309}
2310#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002311
2312//To check whther pBss1 is better than pBss2
2313static tANI_BOOLEAN csrIsBetterBss(tCsrScanResult *pBss1, tCsrScanResult *pBss2)
2314{
2315 tANI_BOOLEAN ret;
2316
2317 if(CSR_IS_BETTER_PREFER_VALUE(pBss1->preferValue, pBss2->preferValue))
2318 {
2319 ret = eANI_BOOLEAN_TRUE;
2320 }
2321 else if(CSR_IS_EQUAL_PREFER_VALUE(pBss1->preferValue, pBss2->preferValue))
2322 {
2323 if(CSR_IS_BETTER_CAP_VALUE(pBss1->capValue, pBss2->capValue))
2324 {
2325 ret = eANI_BOOLEAN_TRUE;
2326 }
2327 else
2328 {
2329 ret = eANI_BOOLEAN_FALSE;
2330 }
2331 }
2332 else
2333 {
2334 ret = eANI_BOOLEAN_FALSE;
2335 }
2336
2337 return (ret);
2338}
2339
2340
Srikant Kuppa866893f2012-12-27 17:28:14 -08002341#ifdef FEATURE_WLAN_LFR
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002342//Add the channel to the occupiedChannels array
2343static void csrScanAddToOccupiedChannels(
Srikant Kuppa866893f2012-12-27 17:28:14 -08002344 tpAniSirGlobal pMac,
2345 tCsrScanResult *pResult,
2346 tCsrChannel *pOccupiedChannels,
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002347 tDot11fBeaconIEs *pIes)
2348{
2349 eHalStatus status;
2350 tANI_U8 channel;
2351 tANI_U8 numOccupiedChannels = pOccupiedChannels->numChannels;
2352 tANI_U8 *pOccupiedChannelList = pOccupiedChannels->channelList;
2353
2354 channel = pResult->Result.BssDescriptor.channelId;
2355
2356 if (!csrIsChannelPresentInList(pOccupiedChannelList, numOccupiedChannels, channel)
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08002357 && csrNeighborRoamConnectedProfileMatch(pMac, pResult, pIes))
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002358 {
Srikant Kuppa866893f2012-12-27 17:28:14 -08002359 status = csrAddToChannelListFront(pOccupiedChannelList, numOccupiedChannels, channel);
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002360 if(HAL_STATUS_SUCCESS(status))
Srikant Kuppa866893f2012-12-27 17:28:14 -08002361 {
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002362 pOccupiedChannels->numChannels++;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002363 smsLog(pMac, LOG2, FL("%s: added channel %d to the list (count=%d)"),
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08002364 __func__, channel, pOccupiedChannels->numChannels);
Srikant Kuppa866893f2012-12-27 17:28:14 -08002365 if (pOccupiedChannels->numChannels > CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN)
2366 pOccupiedChannels->numChannels = CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN;
2367 }
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002368 }
2369}
Mukul Sharma9e4e0f92015-02-13 18:45:20 +05302370
2371void csrAddChannelToOccupiedChannelList(tpAniSirGlobal pMac,
2372 tANI_U8 channel)
2373{
2374 eHalStatus status;
2375 tCsrChannel *pOccupiedChannels = &pMac->scan.occupiedChannels;
2376 tANI_U8 numOccupiedChannels = pOccupiedChannels->numChannels;
2377 tANI_U8 *pOccupiedChannelList = pOccupiedChannels->channelList;
2378 if (!csrIsChannelPresentInList(pOccupiedChannelList,
2379 numOccupiedChannels, channel))
2380 {
2381 status = csrAddToChannelListFront(pOccupiedChannelList,
2382 numOccupiedChannels, channel);
2383 if(HAL_STATUS_SUCCESS(status))
2384 {
2385 pOccupiedChannels->numChannels++;
2386 smsLog(pMac, LOG2, FL("added channel %d to the list (count=%d)"),
2387 channel, pOccupiedChannels->numChannels);
2388 if (pOccupiedChannels->numChannels >
2389 CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN)
2390 {
2391 pOccupiedChannels->numChannels =
2392 CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN;
2393 smsLog(pMac, LOG2,
2394 FL("trim no of Channels for Occ channel list"));
2395 }
2396 }
2397 }
2398}
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002399#endif
2400
Jeff Johnson295189b2012-06-20 16:38:30 -07002401//Put the BSS into the scan result list
2402//pIes can not be NULL
2403static void csrScanAddResult(tpAniSirGlobal pMac, tCsrScanResult *pResult, tDot11fBeaconIEs *pIes)
2404{
Srinivas28b5b4e2012-12-12 13:07:53 -08002405#ifdef FEATURE_WLAN_LFR
2406 tpCsrNeighborRoamControlInfo pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
2407#endif
2408
Jeff Johnson295189b2012-06-20 16:38:30 -07002409 pResult->preferValue = csrGetBssPreferValue(pMac, (int)pResult->Result.BssDescriptor.rssi);
2410 pResult->capValue = csrGetBssCapValue(pMac, &pResult->Result.BssDescriptor, pIes);
2411 csrLLInsertTail( &pMac->scan.scanResultList, &pResult->Link, LL_ACCESS_LOCK );
Srikant Kuppa866893f2012-12-27 17:28:14 -08002412#ifdef FEATURE_WLAN_LFR
Srinivas28b5b4e2012-12-12 13:07:53 -08002413 if(0 == pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels)
2414 {
2415 /* Build the occupied channel list, only if "gNeighborScanChannelList" is
2416 NOT set in the cfg.ini file */
2417 csrScanAddToOccupiedChannels(pMac, pResult, &pMac->scan.occupiedChannels, pIes);
2418 }
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002419#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002420}
2421
2422
2423eHalStatus csrScanGetResult(tpAniSirGlobal pMac, tCsrScanResultFilter *pFilter, tScanResultHandle *phResult)
2424{
2425 eHalStatus status;
2426 tScanResultList *pRetList;
2427 tCsrScanResult *pResult, *pBssDesc;
2428 tANI_U32 count = 0;
2429 tListElem *pEntry;
2430 tANI_U32 bssLen, allocLen;
2431 eCsrEncryptionType uc = eCSR_ENCRYPT_TYPE_NONE, mc = eCSR_ENCRYPT_TYPE_NONE;
2432 eCsrAuthType auth = eCSR_AUTH_TYPE_OPEN_SYSTEM;
2433 tDot11fBeaconIEs *pIes, *pNewIes;
2434 tANI_BOOLEAN fMatch;
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002435 tANI_U16 i = 0;
Kapil Guptab3a981b2016-06-26 13:36:51 +05302436 tCsrRoamSession *pSession = CSR_GET_SESSION(pMac,
2437 pMac->roam.roamSession->sessionId);
2438
Jeff Johnson295189b2012-06-20 16:38:30 -07002439 if(phResult)
2440 {
2441 *phResult = CSR_INVALID_SCANRESULT_HANDLE;
2442 }
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002443
2444 if (pMac->roam.configParam.nSelect5GHzMargin)
2445 {
2446 pMac->scan.inScanResultBestAPRssi = -128;
2447 csrLLLock(&pMac->scan.scanResultList);
2448
2449 /* Find out the best AP Rssi going thru the scan results */
2450 pEntry = csrLLPeekHead(&pMac->scan.scanResultList, LL_ACCESS_NOLOCK);
2451 while ( NULL != pEntry)
2452 {
2453 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002454 fMatch = FALSE;
2455
2456 if (pFilter)
2457 for(i = 0; i < pFilter->SSIDs.numOfSSIDs; i++)
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002458 {
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002459 fMatch = csrIsSsidMatch( pMac, pFilter->SSIDs.SSIDList[i].SSID.ssId, pFilter->SSIDs.SSIDList[i].SSID.length,
2460 pBssDesc->Result.ssId.ssId,
2461 pBssDesc->Result.ssId.length, eANI_BOOLEAN_TRUE );
2462 if (fMatch)
2463 {
2464 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
2465
2466 //At this time, pBssDescription->Result.pvIes may be NULL
2467 if( !pIes && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
2468 &pBssDesc->Result.BssDescriptor, &pIes))) )
2469 {
2470 continue;
2471 }
2472
2473 smsLog(pMac, LOG1, FL("SSID Matched"));
Leela Venkata Kiran Kumar Reddy Chiralae208a832014-04-27 22:34:25 -07002474
Leela Venkata Kiran Kumar Reddy Chiralaf257bef2014-04-11 18:48:12 -07002475 if ( pFilter->bOSENAssociation )
2476 {
2477 fMatch = TRUE;
2478 }
Leela Venkata Kiran Kumar Reddy Chiralae208a832014-04-27 22:34:25 -07002479 else
2480 {
Abhishek Singh658d4de2014-06-26 10:53:15 +05302481#ifdef WLAN_FEATURE_11W
Abhishek Singh3b56d3a2014-06-25 12:37:39 +05302482 fMatch = csrIsSecurityMatch(pMac, &pFilter->authType,
2483 &pFilter->EncryptionType,
2484 &pFilter->mcEncryptionType,
2485 &pFilter->MFPEnabled,
2486 &pFilter->MFPRequired,
2487 &pFilter->MFPCapable,
2488 &pBssDesc->Result.BssDescriptor,
2489 pIes, NULL, NULL, NULL );
Abhishek Singh658d4de2014-06-26 10:53:15 +05302490#else
2491 fMatch = csrIsSecurityMatch(pMac, &pFilter->authType,
2492 &pFilter->EncryptionType,
2493 &pFilter->mcEncryptionType,
2494 NULL, NULL, NULL,
2495 &pBssDesc->Result.BssDescriptor,
2496 pIes, NULL, NULL, NULL );
2497#endif
Leela Venkata Kiran Kumar Reddy Chiralae208a832014-04-27 22:34:25 -07002498 }
2499 if ((pBssDesc->Result.pvIes == NULL) && pIes)
2500 vos_mem_free(pIes);
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002501
2502 if (fMatch)
2503 smsLog(pMac, LOG1, FL(" Security Matched"));
2504 }
2505 }
2506
2507 if (fMatch && (pBssDesc->Result.BssDescriptor.rssi > pMac->scan.inScanResultBestAPRssi))
2508 {
2509 smsLog(pMac, LOG1, FL("Best AP Rssi changed from %d to %d"),
2510 pMac->scan.inScanResultBestAPRssi,
2511 pBssDesc->Result.BssDescriptor.rssi);
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002512 pMac->scan.inScanResultBestAPRssi = pBssDesc->Result.BssDescriptor.rssi;
2513 }
2514 pEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
2515 }
2516
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002517 if ( -128 != pMac->scan.inScanResultBestAPRssi)
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002518 {
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002519 smsLog(pMac, LOG1, FL("Best AP Rssi is %d"), pMac->scan.inScanResultBestAPRssi);
2520 /* Modify Rssi category based on best AP Rssi */
2521 csrAssignRssiForCategory(pMac, pMac->scan.inScanResultBestAPRssi, pMac->roam.configParam.bCatRssiOffset);
2522 pEntry = csrLLPeekHead(&pMac->scan.scanResultList, LL_ACCESS_NOLOCK);
2523 while ( NULL != pEntry)
2524 {
2525 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002526
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002527 /* re-assign preference value based on modified rssi bucket */
2528 pBssDesc->preferValue = csrGetBssPreferValue(pMac, (int)pBssDesc->Result.BssDescriptor.rssi);
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002529
Arif Hussaina7c8e412013-11-20 11:06:42 -08002530 smsLog(pMac, LOG2, FL("BSSID("MAC_ADDRESS_STR
Jeff Johnson123ed002013-11-22 17:39:55 -08002531 ") Rssi(%d) Chnl(%d) PrefVal(%u) SSID=%.*s"),
Arif Hussaina7c8e412013-11-20 11:06:42 -08002532 MAC_ADDR_ARRAY(pBssDesc->Result.BssDescriptor.bssId),
2533 pBssDesc->Result.BssDescriptor.rssi,
2534 pBssDesc->Result.BssDescriptor.channelId,
2535 pBssDesc->preferValue,
2536 pBssDesc->Result.ssId.length, pBssDesc->Result.ssId.ssId);
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002537
2538 pEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
2539 }
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002540 }
2541
2542 csrLLUnlock(&pMac->scan.scanResultList);
2543 }
2544
Kiet Lam64c1b492013-07-12 13:56:44 +05302545 pRetList = vos_mem_malloc(sizeof(tScanResultList));
2546 if ( NULL == pRetList )
2547 status = eHAL_STATUS_FAILURE;
2548 else
2549 status = eHAL_STATUS_SUCCESS;
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002550 if(HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07002551 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302552 vos_mem_set(pRetList, sizeof(tScanResultList), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002553 csrLLOpen(pMac->hHdd, &pRetList->List);
2554 pRetList->pCurEntry = NULL;
Kapil Guptab3a981b2016-06-26 13:36:51 +05302555#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
2556 if (pFilter && pFilter->isPERRoamScan)
2557 if (pSession && pSession->pConnectBssDesc)
2558 csrFindSelfCongestionScore(pMac,
2559 pSession->pConnectBssDesc);
2560#endif
2561
Jeff Johnson295189b2012-06-20 16:38:30 -07002562 csrLLLock(&pMac->scan.scanResultList);
2563 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
2564 while( pEntry )
2565 {
2566 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2567 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
2568 //if pBssDesc->Result.pvIes is NULL, we need to free any memory allocated by csrMatchBSS
2569 //for any error condition, otherwiase, it will be freed later.
2570 //reset
2571 fMatch = eANI_BOOLEAN_FALSE;
2572 pNewIes = NULL;
2573
2574 if(pFilter)
2575 {
2576 fMatch = csrMatchBSS(pMac, &pBssDesc->Result.BssDescriptor, pFilter, &auth, &uc, &mc, &pIes);
2577 if( NULL != pIes )
2578 {
2579 //Only save it when matching
2580 if(fMatch)
2581 {
2582 if( !pBssDesc->Result.pvIes )
2583 {
2584 //csrMatchBSS allocates the memory. Simply pass it and it is freed later
2585 pNewIes = pIes;
2586 }
2587 else
2588 {
2589 //The pIes is allocated by someone else. make a copy
2590 //Only to save parsed IEs if caller provides a filter. Most likely the caller
2591 //is using to for association, hence save the parsed IEs
Kiet Lam64c1b492013-07-12 13:56:44 +05302592 pNewIes = vos_mem_malloc(sizeof(tDot11fBeaconIEs));
2593 if ( NULL == pNewIes )
2594 status = eHAL_STATUS_FAILURE;
2595 else
2596 status = eHAL_STATUS_SUCCESS;
2597 if ( HAL_STATUS_SUCCESS( status ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07002598 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302599 vos_mem_copy(pNewIes, pIes, sizeof( tDot11fBeaconIEs ));
Jeff Johnson295189b2012-06-20 16:38:30 -07002600 }
2601 else
2602 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002603 smsLog(pMac, LOGE, FL(" fail to allocate memory for IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002604 //Need to free memory allocated by csrMatchBSS
2605 if( !pBssDesc->Result.pvIes )
2606 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302607 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07002608 }
2609 break;
2610 }
2611 }
2612 }//fMatch
2613 else if( !pBssDesc->Result.pvIes )
2614 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302615 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07002616 }
2617 }
2618 }
2619 if(NULL == pFilter || fMatch)
2620 {
2621 bssLen = pBssDesc->Result.BssDescriptor.length + sizeof(pBssDesc->Result.BssDescriptor.length);
2622 allocLen = sizeof( tCsrScanResult ) + bssLen;
Kiet Lam64c1b492013-07-12 13:56:44 +05302623 pResult = vos_mem_malloc(allocLen);
2624 if ( NULL == pResult )
2625 status = eHAL_STATUS_FAILURE;
2626 else
2627 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07002628 if(!HAL_STATUS_SUCCESS(status))
2629 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002630 smsLog(pMac, LOGE, FL(" fail to allocate memory for scan result, len=%d"), allocLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07002631 if(pNewIes)
2632 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302633 vos_mem_free(pNewIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07002634 }
2635 break;
2636 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302637 vos_mem_set(pResult, allocLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002638 pResult->capValue = pBssDesc->capValue;
2639 pResult->preferValue = pBssDesc->preferValue;
2640 pResult->ucEncryptionType = uc;
2641 pResult->mcEncryptionType = mc;
2642 pResult->authType = auth;
2643 pResult->Result.ssId = pBssDesc->Result.ssId;
Padma, Santhosh Kumare12fd982016-03-21 13:07:52 +05302644 pResult->Result.timer = pBssDesc->Result.timer;
Jeff Johnson295189b2012-06-20 16:38:30 -07002645 //save the pIes for later use
2646 pResult->Result.pvIes = pNewIes;
2647 //save bss description
Kiet Lam64c1b492013-07-12 13:56:44 +05302648 vos_mem_copy(&pResult->Result.BssDescriptor,
2649 &pBssDesc->Result.BssDescriptor, bssLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07002650 //No need to lock pRetList because it is locally allocated and no outside can access it at this time
2651 if(csrLLIsListEmpty(&pRetList->List, LL_ACCESS_NOLOCK))
2652 {
Kapil Guptab3a981b2016-06-26 13:36:51 +05302653#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
2654 if (pFilter && pFilter->isPERRoamScan) {
2655 csrFindCongestionScore(pMac, pResult);
2656 if (pResult->congestionScore > pMac->currentBssScore) {
2657 csrLLInsertTail(&pRetList->List, &pResult->Link,
2658 LL_ACCESS_NOLOCK);
2659 smsLog(pMac, LOGW,
2660 FL("added one entry in LL in PER Roam list"));
2661 }
2662 }
2663 else
2664#endif
2665 {
2666 csrLLInsertTail(&pRetList->List, &pResult->Link,
2667 LL_ACCESS_NOLOCK);
2668 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002669 }
2670 else
2671 {
2672 //To sort the list
2673 tListElem *pTmpEntry;
2674 tCsrScanResult *pTmpResult;
2675
2676 pTmpEntry = csrLLPeekHead(&pRetList->List, LL_ACCESS_NOLOCK);
2677 while(pTmpEntry)
2678 {
2679 pTmpResult = GET_BASE_ADDR( pTmpEntry, tCsrScanResult, Link );
Kapil Guptab3a981b2016-06-26 13:36:51 +05302680#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
2681 if (pFilter && pFilter->isPERRoamScan) {
2682 csrFindCongestionScore(pMac, pResult);
2683 if(csrIsBetterBssInCongestion(pResult, pTmpResult)&&
2684 (pResult->congestionScore > pMac->currentBssScore))
2685 {
2686 csrLLInsertEntry(&pRetList->List, pTmpEntry,
2687 &pResult->Link, LL_ACCESS_NOLOCK);
2688 smsLog(pMac, LOGW,
2689 FL("added another entry in LL in PER Roam list"));
2690 pResult = NULL;
2691 break;
2692 }
2693 pTmpEntry = csrLLNext(&pRetList->List,
2694 pTmpEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07002695 }
Kapil Guptab3a981b2016-06-26 13:36:51 +05302696 else
2697#endif
2698 {
2699 if(csrIsBetterBss(pResult, pTmpResult))
2700 {
2701 csrLLInsertEntry(&pRetList->List, pTmpEntry,
2702 &pResult->Link, LL_ACCESS_NOLOCK);
2703 //To indicate we are done
2704 pResult = NULL;
2705 break;
2706 }
2707 pTmpEntry = csrLLNext(&pRetList->List,
2708 pTmpEntry, LL_ACCESS_NOLOCK);
2709 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002710 }
2711 if(pResult != NULL)
Kapil Guptab3a981b2016-06-26 13:36:51 +05302712#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
2713 if ((pFilter && !pFilter->isPERRoamScan) ||
2714 (pFilter == NULL) ||
2715 (pResult->congestionScore > pMac->currentBssScore))
2716#endif
2717 {
2718 //This one is not better than any one
2719 csrLLInsertTail(&pRetList->List,
2720 &pResult->Link, LL_ACCESS_NOLOCK);
2721 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002722 }
2723 count++;
2724 }
2725 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK );
2726 }//while
2727 csrLLUnlock(&pMac->scan.scanResultList);
2728
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002729 smsLog(pMac, LOG2, FL("return %d BSS"), csrLLCount(&pRetList->List));
Jeff Johnson295189b2012-06-20 16:38:30 -07002730
2731 if( !HAL_STATUS_SUCCESS(status) || (phResult == NULL) )
2732 {
2733 //Fail or No one wants the result.
2734 csrScanResultPurge(pMac, (tScanResultHandle)pRetList);
2735 }
2736 else
2737 {
2738 if(0 == count)
2739 {
2740 //We are here meaning the there is no match
2741 csrLLClose(&pRetList->List);
Kiet Lam64c1b492013-07-12 13:56:44 +05302742 vos_mem_free(pRetList);
Jeff Johnson295189b2012-06-20 16:38:30 -07002743 status = eHAL_STATUS_E_NULL_VALUE;
Kapil Guptab3a981b2016-06-26 13:36:51 +05302744 smsLog(pMac, LOGW,
2745 FL("Nil scan results or no matching AP found"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002746 }
2747 else if(phResult)
2748 {
2749 *phResult = pRetList;
2750 }
2751 }
2752 }//Allocated pRetList
2753
2754 return (status);
2755}
2756
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002757/*
2758 * NOTE: This routine is being added to make
2759 * sure that scan results are not being flushed
2760 * while roaming. If the scan results are flushed,
2761 * we are unable to recover from
2762 * csrRoamRoamingStateDisassocRspProcessor.
2763 * If it is needed to remove this routine,
2764 * first ensure that we recover gracefully from
2765 * csrRoamRoamingStateDisassocRspProcessor if
2766 * csrScanGetResult returns with a failure because
2767 * of not being able to find the roaming BSS.
2768 */
2769tANI_U8 csrScanFlushDenied(tpAniSirGlobal pMac)
2770{
2771 switch(pMac->roam.neighborRoamInfo.neighborRoamState) {
2772 case eCSR_NEIGHBOR_ROAM_STATE_REPORT_SCAN:
2773 case eCSR_NEIGHBOR_ROAM_STATE_PREAUTHENTICATING:
2774 case eCSR_NEIGHBOR_ROAM_STATE_PREAUTH_DONE:
2775 case eCSR_NEIGHBOR_ROAM_STATE_REASSOCIATING:
2776 return (pMac->roam.neighborRoamInfo.neighborRoamState);
2777 default:
2778 return 0;
2779 }
2780}
2781
Jeff Johnson295189b2012-06-20 16:38:30 -07002782eHalStatus csrScanFlushResult(tpAniSirGlobal pMac)
2783{
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002784 tANI_U8 isFlushDenied = csrScanFlushDenied(pMac);
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302785 eHalStatus status = eHAL_STATUS_SUCCESS;
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002786 if (isFlushDenied) {
2787 smsLog(pMac, LOGW, "%s: scan flush denied in roam state %d",
2788 __func__, isFlushDenied);
2789 return eHAL_STATUS_FAILURE;
2790 }
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302791 csrLLScanPurgeResult( pMac, &pMac->scan.tempScanResults );
2792 csrLLScanPurgeResult( pMac, &pMac->scan.scanResultList );
2793 return( status );
Jeff Johnson295189b2012-06-20 16:38:30 -07002794}
2795
Mukul Sharma20aa6582014-08-07 21:36:12 +05302796eHalStatus csrScanFlushSelectiveResultForBand(tpAniSirGlobal pMac, v_BOOL_t flushP2P, tSirRFBand band)
2797{
2798 eHalStatus status = eHAL_STATUS_SUCCESS;
2799 tListElem *pEntry,*pFreeElem;
2800 tCsrScanResult *pBssDesc;
2801 tDblLinkList *pList = &pMac->scan.scanResultList;
2802
2803 csrLLLock(pList);
2804
2805 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK );
2806 while( pEntry != NULL)
2807 {
2808 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2809 if( (flushP2P == vos_mem_compare( pBssDesc->Result.ssId.ssId,
2810 "DIRECT-", 7)) &&
2811 (GetRFBand(pBssDesc->Result.BssDescriptor.channelId) == band)
2812 )
2813 {
2814 pFreeElem = pEntry;
2815 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2816 csrLLRemoveEntry(pList, pFreeElem, LL_ACCESS_NOLOCK);
2817 csrFreeScanResultEntry( pMac, pBssDesc );
2818 continue;
2819 }
2820 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2821 }
2822
2823 csrLLUnlock(pList);
2824
2825 return (status);
2826}
2827
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302828eHalStatus csrScanFlushSelectiveResult(tpAniSirGlobal pMac, v_BOOL_t flushP2P)
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002829{
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302830 eHalStatus status = eHAL_STATUS_SUCCESS;
2831 tListElem *pEntry,*pFreeElem;
2832 tCsrScanResult *pBssDesc;
2833 tDblLinkList *pList = &pMac->scan.scanResultList;
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002834
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302835 csrLLLock(pList);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002836
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302837 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK );
2838 while( pEntry != NULL)
2839 {
2840 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2841 if( flushP2P == vos_mem_compare( pBssDesc->Result.ssId.ssId,
2842 "DIRECT-", 7) )
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002843 {
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302844 pFreeElem = pEntry;
2845 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2846 csrLLRemoveEntry(pList, pFreeElem, LL_ACCESS_NOLOCK);
2847 csrFreeScanResultEntry( pMac, pBssDesc );
2848 continue;
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002849 }
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302850 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2851 }
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002852
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302853 csrLLUnlock(pList);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002854
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302855 return (status);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002856}
2857
Jeff Johnson295189b2012-06-20 16:38:30 -07002858/**
2859 * csrCheck11dChannel
2860 *
2861 *FUNCTION:
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302862 * This function is called from csrScanFilterResults function and
Jeff Johnson295189b2012-06-20 16:38:30 -07002863 * compare channel number with given channel list.
2864 *
2865 *LOGIC:
2866 * Check Scan result channel number with CFG channel list
2867 *
2868 *ASSUMPTIONS:
2869 *
2870 *
2871 *NOTE:
2872 *
2873 * @param channelId channel number
2874 * @param pChannelList Pointer to channel list
2875 * @param numChannels Number of channel in channel list
2876 *
2877 * @return Status
2878 */
2879
2880eHalStatus csrCheck11dChannel(tANI_U8 channelId, tANI_U8 *pChannelList, tANI_U32 numChannels)
2881{
2882 eHalStatus status = eHAL_STATUS_FAILURE;
2883 tANI_U8 i = 0;
2884
2885 for (i = 0; i < numChannels; i++)
2886 {
2887 if(pChannelList[ i ] == channelId)
2888 {
2889 status = eHAL_STATUS_SUCCESS;
2890 break;
2891 }
2892 }
2893 return status;
2894}
2895
2896/**
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302897 * csrScanFilterResults
Jeff Johnson295189b2012-06-20 16:38:30 -07002898 *
2899 *FUNCTION:
2900 * This function is called from csrApplyCountryInformation function and
2901 * filter scan result based on valid channel list number.
2902 *
2903 *LOGIC:
2904 * Get scan result from scan list and Check Scan result channel number
2905 * with 11d channel list if channel number is found in 11d channel list
2906 * then do not remove scan result entry from scan list
2907 *
2908 *ASSUMPTIONS:
2909 *
2910 *
2911 *NOTE:
2912 *
2913 * @param pMac Pointer to Global MAC structure
2914 *
2915 * @return Status
2916 */
2917
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302918eHalStatus csrScanFilterResults(tpAniSirGlobal pMac)
Jeff Johnson295189b2012-06-20 16:38:30 -07002919{
2920 eHalStatus status = eHAL_STATUS_SUCCESS;
2921 tListElem *pEntry,*pTempEntry;
2922 tCsrScanResult *pBssDesc;
2923 tANI_U32 len = sizeof(pMac->roam.validChannelList);
2924
2925 /* Get valid channels list from CFG */
2926 if (!HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac,
2927 pMac->roam.validChannelList, &len)))
2928 {
Agarwal Ashishe3cca2a2013-07-21 03:01:48 +05302929 smsLog( pMac, LOGE, "Failed to get Channel list from CFG");
Jeff Johnson295189b2012-06-20 16:38:30 -07002930 }
2931
2932 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
2933 while( pEntry )
2934 {
2935 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302936 pTempEntry = csrLLNext( &pMac->scan.scanResultList, pEntry,
Jeff Johnson295189b2012-06-20 16:38:30 -07002937 LL_ACCESS_LOCK );
2938 if(csrCheck11dChannel(pBssDesc->Result.BssDescriptor.channelId,
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302939 pMac->roam.validChannelList, len))
Jeff Johnson295189b2012-06-20 16:38:30 -07002940 {
2941 /* Remove Scan result which does not have 11d channel */
2942 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry,
2943 LL_ACCESS_LOCK ))
2944 {
2945 csrFreeScanResultEntry( pMac, pBssDesc );
2946 }
2947 }
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302948 pEntry = pTempEntry;
2949 }
2950
2951 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
2952 while( pEntry )
2953 {
2954 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2955 pTempEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry,
2956 LL_ACCESS_LOCK );
2957 if(csrCheck11dChannel(pBssDesc->Result.BssDescriptor.channelId,
2958 pMac->roam.validChannelList, len))
2959 {
2960 /* Remove Scan result which does not have 11d channel */
2961 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry,
2962 LL_ACCESS_LOCK ))
2963 {
2964 csrFreeScanResultEntry( pMac, pBssDesc );
2965 }
2966 }
2967 else
2968 {
2969 smsLog( pMac, LOG1, FL("%d is a Valid channel"),
2970 pBssDesc->Result.BssDescriptor.channelId);
2971 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002972 pEntry = pTempEntry;
2973 }
2974 return status;
2975}
2976
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05302977/**
2978 * csrScanFilterDFSResults
2979 *
2980 *FUNCTION:
2981 * This function filter BSSIDs on DFS channels from the scan results.
2982 *
2983 *LOGIC:
2984 * Get scan result from scan list and Check Scan result channel number
2985 * with 11d channel list if channel number is found in 11d channel list
2986 * and if fEnableDFSChnlScan is zero and if channel is DFS, then
2987 * remove scan result entry from scan list
2988 *
2989 *ASSUMPTIONS:
2990 *
2991 *NOTE:
2992 *
2993 * @param pMac Pointer to Global MAC structure
2994 *
2995 * @return Status
2996 */
2997
2998eHalStatus csrScanFilterDFSResults(tpAniSirGlobal pMac)
2999{
3000 eHalStatus status = eHAL_STATUS_SUCCESS;
3001 tListElem *pEntry,*pTempEntry;
3002 tCsrScanResult *pBssDesc;
3003
3004 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
3005 while( pEntry )
3006 {
3007 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3008 pTempEntry = csrLLNext( &pMac->scan.scanResultList, pEntry,
3009 LL_ACCESS_LOCK );
3010 if((pMac->scan.fEnableDFSChnlScan == DFS_CHNL_SCAN_DISABLED) &&
3011 CSR_IS_CHANNEL_DFS(pBssDesc->Result.BssDescriptor.channelId))
3012 {
3013 smsLog( pMac, LOG1, FL("%d is a DFS ch filtered from scan list"),
3014 pBssDesc->Result.BssDescriptor.channelId);
3015 /* Remove Scan result which does not have 11d channel */
3016 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry,
3017 LL_ACCESS_LOCK ))
3018 {
3019 csrFreeScanResultEntry( pMac, pBssDesc );
3020 }
3021 }
3022 else
3023 {
3024 smsLog( pMac, LOG1, FL("%d is a Valid channel"),
3025 pBssDesc->Result.BssDescriptor.channelId);
3026 }
3027 pEntry = pTempEntry;
3028 }
3029
3030 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
3031 while( pEntry )
3032 {
3033 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3034 pTempEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry,
3035 LL_ACCESS_LOCK );
3036
3037 if((pMac->scan.fEnableDFSChnlScan == DFS_CHNL_SCAN_DISABLED) &&
3038 CSR_IS_CHANNEL_DFS(pBssDesc->Result.BssDescriptor.channelId))
3039 {
3040 smsLog( pMac, LOG1, FL("%d is a DFS ch filtered from scan list"),
3041 pBssDesc->Result.BssDescriptor.channelId);
3042 /* Remove Scan result which does not have 11d channel */
3043 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry,
3044 LL_ACCESS_LOCK ))
3045 {
3046 csrFreeScanResultEntry( pMac, pBssDesc );
3047 }
3048 }
3049 else
3050 {
3051 smsLog( pMac, LOG1, FL("%d is a Valid channel"),
3052 pBssDesc->Result.BssDescriptor.channelId);
3053 }
3054 pEntry = pTempEntry;
3055 }
3056 return status;
3057}
3058
Jeff Johnson295189b2012-06-20 16:38:30 -07003059
3060eHalStatus csrScanCopyResultList(tpAniSirGlobal pMac, tScanResultHandle hIn, tScanResultHandle *phResult)
3061{
3062 eHalStatus status = eHAL_STATUS_SUCCESS;
3063 tScanResultList *pRetList, *pInList = (tScanResultList *)hIn;
3064 tCsrScanResult *pResult, *pScanResult;
3065 tANI_U32 count = 0;
3066 tListElem *pEntry;
3067 tANI_U32 bssLen, allocLen;
3068
3069 if(phResult)
3070 {
3071 *phResult = CSR_INVALID_SCANRESULT_HANDLE;
3072 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303073 pRetList = vos_mem_malloc(sizeof(tScanResultList));
3074 if ( NULL == pRetList )
3075 status = eHAL_STATUS_FAILURE;
3076 else
Jeff Johnson295189b2012-06-20 16:38:30 -07003077 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303078 vos_mem_set(pRetList, sizeof(tScanResultList), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003079 csrLLOpen(pMac->hHdd, &pRetList->List);
3080 pRetList->pCurEntry = NULL;
3081 csrLLLock(&pMac->scan.scanResultList);
3082 csrLLLock(&pInList->List);
3083
3084 pEntry = csrLLPeekHead( &pInList->List, LL_ACCESS_NOLOCK );
3085 while( pEntry )
3086 {
3087 pScanResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3088 bssLen = pScanResult->Result.BssDescriptor.length + sizeof(pScanResult->Result.BssDescriptor.length);
3089 allocLen = sizeof( tCsrScanResult ) + bssLen;
Kiet Lam64c1b492013-07-12 13:56:44 +05303090 pResult = vos_mem_malloc(allocLen);
3091 if ( NULL == pResult )
3092 status = eHAL_STATUS_FAILURE;
3093 else
3094 status = eHAL_STATUS_SUCCESS;
3095 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07003096 {
3097 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
3098 count = 0;
3099 break;
3100 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303101 vos_mem_set(pResult, allocLen , 0);
3102 vos_mem_copy(&pResult->Result.BssDescriptor, &pScanResult->Result.BssDescriptor, bssLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07003103 if( pScanResult->Result.pvIes )
3104 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303105 pResult->Result.pvIes = vos_mem_malloc(sizeof( tDot11fBeaconIEs ));
3106 if ( NULL == pResult->Result.pvIes )
3107 status = eHAL_STATUS_FAILURE;
3108 else
3109 status = eHAL_STATUS_SUCCESS;
3110 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07003111 {
3112 //Free the memory we allocate above first
Kiet Lam64c1b492013-07-12 13:56:44 +05303113 vos_mem_free(pResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07003114 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
3115 count = 0;
3116 break;
3117 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303118 vos_mem_copy(pResult->Result.pvIes, pScanResult->Result.pvIes,
3119 sizeof( tDot11fBeaconIEs ));
Jeff Johnson295189b2012-06-20 16:38:30 -07003120 }
3121 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_LOCK);
3122 count++;
3123 pEntry = csrLLNext( &pInList->List, pEntry, LL_ACCESS_NOLOCK );
3124 }//while
3125 csrLLUnlock(&pInList->List);
3126 csrLLUnlock(&pMac->scan.scanResultList);
3127
3128 if(HAL_STATUS_SUCCESS(status))
3129 {
3130 if(0 == count)
3131 {
3132 csrLLClose(&pRetList->List);
Kiet Lam64c1b492013-07-12 13:56:44 +05303133 vos_mem_free(pRetList);
Jeff Johnson295189b2012-06-20 16:38:30 -07003134 status = eHAL_STATUS_E_NULL_VALUE;
3135 }
3136 else if(phResult)
3137 {
3138 *phResult = pRetList;
3139 }
3140 }
3141 }//Allocated pRetList
3142
3143 return (status);
3144}
3145
3146
3147
3148eHalStatus csrScanningStateMsgProcessor( tpAniSirGlobal pMac, void *pMsgBuf )
3149{
3150 eHalStatus status = eHAL_STATUS_SUCCESS;
3151 tSirMbMsg *pMsg = (tSirMbMsg *)pMsgBuf;
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303152 tSirSmeDisConDoneInd *pDisConDoneInd;
Abhishek Singhf52182c2016-08-24 11:15:23 +05303153 tCsrRoamSession *pSession;
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303154 tCsrRoamInfo roamInfo = {0};
Jeff Johnson295189b2012-06-20 16:38:30 -07003155
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303156 if((eWNI_SME_SCAN_RSP == pMsg->type) ||
3157 (eWNI_SME_GET_SCANNED_CHANNEL_RSP == pMsg->type))
Jeff Johnson295189b2012-06-20 16:38:30 -07003158 {
3159 status = csrScanSmeScanResponse( pMac, pMsgBuf );
3160 }
3161 else
3162 {
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303163 switch (pMsg->type)
Jeff Johnson295189b2012-06-20 16:38:30 -07003164 {
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303165 case eWNI_SME_UPPER_LAYER_ASSOC_CNF:
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08003166 {
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303167 tSirSmeAssocIndToUpperLayerCnf *pUpperLayerAssocCnf;
3168 tCsrRoamInfo *pRoamInfo = NULL;
3169 tANI_U32 sessionId;
3170 eHalStatus status;
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08003171
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303172 smsLog( pMac, LOG1,
3173 FL("Scanning : ASSOCIATION confirmation can be given to upper layer "));
3174 pRoamInfo = &roamInfo;
3175 pUpperLayerAssocCnf = (tSirSmeAssocIndToUpperLayerCnf *)pMsgBuf;
3176 status = csrRoamGetSessionIdFromBSSID( pMac,
3177 (tCsrBssid *)pUpperLayerAssocCnf->bssId,
3178 &sessionId );
3179 pSession = CSR_GET_SESSION(pMac, sessionId);
3180
3181 if(!pSession)
3182 {
3183 smsLog(pMac, LOGE, FL("session %d not found "), sessionId);
3184 return eHAL_STATUS_FAILURE;
3185 }
3186
3187 //send the status code as Success
3188 pRoamInfo->statusCode = eSIR_SME_SUCCESS;
3189 pRoamInfo->u.pConnectedProfile = &pSession->connectedProfile;
3190 pRoamInfo->staId = (tANI_U8)pUpperLayerAssocCnf->aid;
3191 pRoamInfo->rsnIELen =
3192 (tANI_U8)pUpperLayerAssocCnf->rsnIE.length;
3193 pRoamInfo->prsnIE = pUpperLayerAssocCnf->rsnIE.rsnIEdata;
3194 pRoamInfo->addIELen =
3195 (tANI_U8)pUpperLayerAssocCnf->addIE.length;
3196 pRoamInfo->paddIE = pUpperLayerAssocCnf->addIE.addIEdata;
3197 vos_mem_copy(pRoamInfo->peerMac,
3198 pUpperLayerAssocCnf->peerMacAddr,
3199 sizeof(tSirMacAddr));
3200 vos_mem_copy(&pRoamInfo->bssid,
3201 pUpperLayerAssocCnf->bssId,
3202 sizeof(tCsrBssid));
3203 pRoamInfo->wmmEnabledSta = pUpperLayerAssocCnf->wmmEnabledSta;
Hardik Kantilal Patel1ba630f2014-11-21 04:32:05 +05303204#ifdef WLAN_FEATURE_AP_HT40_24G
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303205 pRoamInfo->HT40MHzIntoEnabledSta =
3206 pUpperLayerAssocCnf->HT40MHzIntoEnabledSta;
Hardik Kantilal Patel1ba630f2014-11-21 04:32:05 +05303207#endif
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303208 if(CSR_IS_INFRA_AP(pRoamInfo->u.pConnectedProfile) )
3209 {
3210 pMac->roam.roamSession[sessionId].connectState =
3211 eCSR_ASSOC_STATE_TYPE_INFRA_CONNECTED;
3212 pRoamInfo->fReassocReq = pUpperLayerAssocCnf->reassocReq;
3213 status = csrRoamCallCallback(pMac, sessionId, pRoamInfo,
3214 0, eCSR_ROAM_INFRA_IND,
3215 eCSR_ROAM_RESULT_INFRA_ASSOCIATION_CNF);
3216 }
3217 if(CSR_IS_WDS_AP( pRoamInfo->u.pConnectedProfile))
3218 {
3219 vos_sleep( 100 );
3220 pMac->roam.roamSession[sessionId].connectState =
3221 eCSR_ASSOC_STATE_TYPE_WDS_CONNECTED;//Sta
3222 status = csrRoamCallCallback(pMac, sessionId, pRoamInfo, 0,
3223 eCSR_ROAM_WDS_IND,
3224 eCSR_ROAM_RESULT_WDS_ASSOCIATION_IND);//Sta
3225 }
3226 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07003227 }
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303228 case eWNI_SME_DISCONNECT_DONE_IND:
3229 pDisConDoneInd = (tSirSmeDisConDoneInd *)(pMsg);
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08003230
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303231 smsLog( pMac, LOG1,
3232 FL("eWNI_SME_DISCONNECT_DONE_IND RC:%d"),
3233 pDisConDoneInd->reasonCode);
3234 if( CSR_IS_SESSION_VALID(pMac, pDisConDoneInd->sessionId))
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08003235 {
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303236 roamInfo.reasonCode = pDisConDoneInd->reasonCode;
3237 roamInfo.statusCode = eSIR_SME_STA_DISASSOCIATED;
3238 vos_mem_copy(roamInfo.peerMac, pDisConDoneInd->peerMacAddr,
3239 sizeof(tSirMacAddr));
3240 status = csrRoamCallCallback(pMac,
3241 pDisConDoneInd->sessionId,
3242 &roamInfo, 0,
3243 eCSR_ROAM_LOSTLINK,
3244 eCSR_ROAM_RESULT_DISASSOC_IND);
Abhishek Singhf52182c2016-08-24 11:15:23 +05303245 pSession = CSR_GET_SESSION(pMac,
3246 pDisConDoneInd->sessionId);
3247 /*
3248 * Update the previous state if
3249 * previous state was eCSR_ROAMING_STATE_JOINED
3250 * as we are disconnected and
3251 * currunt state is scanning
3252 */
3253 if (pSession &&
3254 !CSR_IS_INFRA_AP(&pSession->connectedProfile)
3255 && (eCSR_ROAMING_STATE_IDLE !=
3256 pMac->roam.prev_state[pDisConDoneInd->sessionId]))
3257 pMac->roam.prev_state[pDisConDoneInd->sessionId] =
3258 eCSR_ROAMING_STATE_IDLE;
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08003259 }
3260 else
3261 {
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303262 smsLog(pMac, LOGE, FL("Inactive session %d"),
3263 pDisConDoneInd->sessionId);
3264 status = eHAL_STATUS_FAILURE;
3265 }
3266 break;
3267
3268 default :
3269 if( csrIsAnySessionInConnectState( pMac ) )
3270 {
3271 /*In case of we are connected, we need to check whether connect
3272 * status changes because scan may also run while connected.
3273 */
3274 csrRoamCheckForLinkStatusChange( pMac, (tSirSmeRsp *)pMsgBuf );
3275 }
3276 else
3277 {
3278 smsLog( pMac, LOGW,
3279 "Message [0x%04x] received in state, when expecting Scan Response",
3280 pMsg->type );
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08003281 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003282 }
3283 }
3284
3285 return (status);
3286}
3287
3288
3289
3290void csrCheckNSaveWscIe(tpAniSirGlobal pMac, tSirBssDescription *pNewBssDescr, tSirBssDescription *pOldBssDescr)
3291{
3292 int idx, len;
3293 tANI_U8 *pbIe;
3294
3295 //If failed to remove, assuming someone else got it.
3296 if((pNewBssDescr->fProbeRsp != pOldBssDescr->fProbeRsp) &&
3297 (0 == pNewBssDescr->WscIeLen))
3298 {
3299 idx = 0;
3300 len = pOldBssDescr->length - sizeof(tSirBssDescription) +
3301 sizeof(tANI_U16) + sizeof(tANI_U32) - DOT11F_IE_WSCPROBERES_MIN_LEN - 2;
3302 pbIe = (tANI_U8 *)pOldBssDescr->ieFields;
3303 //Save WPS IE if it exists
3304 pNewBssDescr->WscIeLen = 0;
3305 while(idx < len)
3306 {
3307 if((DOT11F_EID_WSCPROBERES == pbIe[0]) &&
3308 (0x00 == pbIe[2]) && (0x50 == pbIe[3]) && (0xf2 == pbIe[4]) && (0x04 == pbIe[5]))
3309 {
3310 //Founrd it
3311 if((DOT11F_IE_WSCPROBERES_MAX_LEN - 2) >= pbIe[1])
3312 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303313 vos_mem_copy(pNewBssDescr->WscIeProbeRsp, pbIe, pbIe[1] + 2);
Jeff Johnson295189b2012-06-20 16:38:30 -07003314 pNewBssDescr->WscIeLen = pbIe[1] + 2;
3315 }
3316 break;
3317 }
3318 idx += pbIe[1] + 2;
3319 pbIe += pbIe[1] + 2;
3320 }
3321 }
3322}
3323
3324
3325
3326//pIes may be NULL
3327tANI_BOOLEAN csrRemoveDupBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDescr,
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05303328 tDot11fBeaconIEs *pIes, tAniSSID *pSsid, v_TIME_t *timer, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07003329{
3330 tListElem *pEntry;
3331
3332 tCsrScanResult *pBssDesc;
3333 tANI_BOOLEAN fRC = FALSE;
3334
3335 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
3336 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
3337 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
3338 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
3339
3340 while( pEntry )
3341 {
3342 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3343
3344 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
3345 // matches
3346 if ( csrIsDuplicateBssDescription( pMac, &pBssDesc->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07003347 pSirBssDescr, pIes, fForced ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003348 {
3349 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
3350 ((tANI_S32)pBssDesc->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
3351 // Remove the 'old' entry from the list....
3352 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry, LL_ACCESS_LOCK ) )
3353 {
3354 // !we need to free the memory associated with this node
3355 //If failed to remove, assuming someone else got it.
3356 *pSsid = pBssDesc->Result.ssId;
3357 *timer = pBssDesc->Result.timer;
3358 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pBssDesc->Result.BssDescriptor);
3359
3360 csrFreeScanResultEntry( pMac, pBssDesc );
3361 }
3362 else
3363 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003364 smsLog( pMac, LOGW, FL( " fail to remove entry" ) );
Jeff Johnson295189b2012-06-20 16:38:30 -07003365 }
3366 fRC = TRUE;
3367
3368 // If we found a match, we can stop looking through the list.
3369 break;
3370 }
3371
3372 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_LOCK );
3373 }
3374
3375 return fRC;
3376}
3377
3378
3379eHalStatus csrAddPMKIDCandidateList( tpAniSirGlobal pMac, tANI_U32 sessionId,
3380 tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes )
3381{
3382 eHalStatus status = eHAL_STATUS_FAILURE;
3383 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
3384
Jeff Johnson32d95a32012-09-10 13:15:23 -07003385 if(!pSession)
3386 {
3387 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
3388 return eHAL_STATUS_FAILURE;
3389 }
3390
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003391 smsLog(pMac, LOGW, "csrAddPMKIDCandidateList called pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07003392 if( pIes )
3393 {
3394 // check if this is a RSN BSS
3395 if( pIes->RSN.present )
3396 {
3397 // Check if the BSS is capable of doing pre-authentication
3398 if( pSession->NumPmkidCandidate < CSR_MAX_PMKID_ALLOWED )
3399 {
3400
3401#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3402 {
3403 WLAN_VOS_DIAG_EVENT_DEF(secEvent, vos_event_wlan_security_payload_type);
Kiet Lam64c1b492013-07-12 13:56:44 +05303404 vos_mem_set(&secEvent, sizeof(vos_event_wlan_security_payload_type), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003405 secEvent.eventId = WLAN_SECURITY_EVENT_PMKID_CANDIDATE_FOUND;
3406 secEvent.encryptionModeMulticast =
3407 (v_U8_t)diagEncTypeFromCSRType(pSession->connectedProfile.mcEncryptionType);
3408 secEvent.encryptionModeUnicast =
3409 (v_U8_t)diagEncTypeFromCSRType(pSession->connectedProfile.EncryptionType);
Kiet Lam64c1b492013-07-12 13:56:44 +05303410 vos_mem_copy(secEvent.bssid, pSession->connectedProfile.bssid, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07003411 secEvent.authMode =
3412 (v_U8_t)diagAuthTypeFromCSRType(pSession->connectedProfile.AuthType);
3413 WLAN_VOS_DIAG_EVENT_REPORT(&secEvent, EVENT_WLAN_SECURITY);
3414 }
3415#endif//#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3416
3417 // if yes, then add to PMKIDCandidateList
Kiet Lam64c1b492013-07-12 13:56:44 +05303418 vos_mem_copy(pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].BSSID,
3419 pBssDesc->bssId, WNI_CFG_BSSID_LEN);
3420 // Bit 0 offirst byte - PreAuthentication Capability
3421 if ( (pIes->RSN.RSN_Cap[0] >> 0) & 0x1 )
Jeff Johnson295189b2012-06-20 16:38:30 -07003422 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303423 pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].preAuthSupported
3424 = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003425 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303426 else
3427 {
3428 pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].preAuthSupported
3429 = eANI_BOOLEAN_FALSE;
3430 }
3431 pSession->NumPmkidCandidate++;
Jeff Johnson295189b2012-06-20 16:38:30 -07003432 }
3433 else
3434 {
3435 status = eHAL_STATUS_FAILURE;
3436 }
3437 }
3438 }
3439
3440 return (status);
3441}
3442
3443//This function checks whether new AP is found for the current connected profile
3444//If it is found, it return the sessionId, else it return invalid sessionID
3445tANI_U32 csrProcessBSSDescForPMKIDList(tpAniSirGlobal pMac,
3446 tSirBssDescription *pBssDesc,
3447 tDot11fBeaconIEs *pIes)
3448{
3449 tANI_U32 i, bRet = CSR_SESSION_ID_INVALID;
3450 tCsrRoamSession *pSession;
3451 tDot11fBeaconIEs *pIesLocal = pIes;
3452
3453 if( pIesLocal || HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIesLocal)) )
3454 {
3455 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
3456 {
3457 if( CSR_IS_SESSION_VALID( pMac, i ) )
3458 {
3459 pSession = CSR_GET_SESSION( pMac, i );
3460 if( csrIsConnStateConnectedInfra( pMac, i ) &&
3461 ( eCSR_AUTH_TYPE_RSN == pSession->connectedProfile.AuthType ) )
3462 {
3463 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile, pBssDesc, pIesLocal))
3464 {
3465 //this new BSS fits the current profile connected
3466 if(HAL_STATUS_SUCCESS(csrAddPMKIDCandidateList(pMac, i, pBssDesc, pIesLocal)))
3467 {
3468 bRet = i;
3469 }
3470 break;
3471 }
3472 }
3473 }
3474 }
3475 if( !pIes )
3476 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303477 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003478 }
3479 }
3480
3481 return (tANI_U8)bRet;
3482}
3483
3484#ifdef FEATURE_WLAN_WAPI
3485eHalStatus csrAddBKIDCandidateList( tpAniSirGlobal pMac, tANI_U32 sessionId,
3486 tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes )
3487{
3488 eHalStatus status = eHAL_STATUS_FAILURE;
3489 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
3490
Jeff Johnson32d95a32012-09-10 13:15:23 -07003491 if(!pSession)
3492 {
3493 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
3494 return eHAL_STATUS_FAILURE;
3495 }
3496
Kiet Lam64c1b492013-07-12 13:56:44 +05303497 smsLog(pMac, LOGW, "csrAddBKIDCandidateList called pMac->scan.NumBkidCandidate = %d",
3498 pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07003499 if( pIes )
3500 {
3501 // check if this is a WAPI BSS
3502 if( pIes->WAPI.present )
3503 {
3504 // Check if the BSS is capable of doing pre-authentication
3505 if( pSession->NumBkidCandidate < CSR_MAX_BKID_ALLOWED )
3506 {
3507
3508 // if yes, then add to BKIDCandidateList
Kiet Lam64c1b492013-07-12 13:56:44 +05303509 vos_mem_copy(pSession->BkidCandidateInfo[pSession->NumBkidCandidate].BSSID,
3510 pBssDesc->bssId, WNI_CFG_BSSID_LEN);
3511 if ( pIes->WAPI.preauth )
Jeff Johnson295189b2012-06-20 16:38:30 -07003512 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303513 pSession->BkidCandidateInfo[pSession->NumBkidCandidate].preAuthSupported
3514 = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003515 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303516 else
3517 {
3518 pSession->BkidCandidateInfo[pSession->NumBkidCandidate].preAuthSupported
3519 = eANI_BOOLEAN_FALSE;
3520 }
3521 pSession->NumBkidCandidate++;
Jeff Johnson295189b2012-06-20 16:38:30 -07003522 }
3523 else
3524 {
3525 status = eHAL_STATUS_FAILURE;
3526 }
3527 }
3528 }
3529
3530 return (status);
3531}
3532
3533//This function checks whether new AP is found for the current connected profile
3534//if so add to BKIDCandidateList
3535tANI_BOOLEAN csrProcessBSSDescForBKIDList(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
3536 tDot11fBeaconIEs *pIes)
3537{
3538 tANI_BOOLEAN fRC = FALSE;
3539 tDot11fBeaconIEs *pIesLocal = pIes;
3540 tANI_U32 sessionId;
3541 tCsrRoamSession *pSession;
3542
3543 if( pIesLocal || HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIesLocal)) )
3544 {
3545 for( sessionId = 0; sessionId < CSR_ROAM_SESSION_MAX; sessionId++ )
3546 {
3547 if( CSR_IS_SESSION_VALID( pMac, sessionId) )
3548 {
3549 pSession = CSR_GET_SESSION( pMac, sessionId );
3550 if( csrIsConnStateConnectedInfra( pMac, sessionId ) &&
3551 eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE == pSession->connectedProfile.AuthType)
3552 {
3553 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile,pBssDesc, pIesLocal))
3554 {
3555 //this new BSS fits the current profile connected
3556 if(HAL_STATUS_SUCCESS(csrAddBKIDCandidateList(pMac, sessionId, pBssDesc, pIesLocal)))
3557 {
3558 fRC = TRUE;
3559 }
3560 }
3561 }
3562 }
3563 }
3564 if(!pIes)
3565 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303566 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003567 }
3568
3569 }
3570 return fRC;
3571}
3572
3573#endif
3574
3575
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07003576static void csrMoveTempScanResultsToMainList( tpAniSirGlobal pMac, tANI_U8 reason )
Jeff Johnson295189b2012-06-20 16:38:30 -07003577{
3578 tListElem *pEntry;
3579 tCsrScanResult *pBssDescription;
Jeff Johnson295189b2012-06-20 16:38:30 -07003580 tANI_BOOLEAN fDupBss;
3581#ifdef FEATURE_WLAN_WAPI
3582 tANI_BOOLEAN fNewWapiBSSForCurConnection = eANI_BOOLEAN_FALSE;
3583#endif /* FEATURE_WLAN_WAPI */
3584 tDot11fBeaconIEs *pIesLocal = NULL;
3585 tANI_U32 sessionId = CSR_SESSION_ID_INVALID;
3586 tAniSSID tmpSsid;
3587 v_TIME_t timer=0;
Kapil Gupta2f2fae42016-09-15 15:29:47 +05303588 tANI_U8 occupied_chan_count = pMac->scan.occupiedChannels.numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -07003589
3590 tmpSsid.length = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07003591
3592 // remove the BSS descriptions from temporary list
3593 while( ( pEntry = csrLLRemoveTail( &pMac->scan.tempScanResults, LL_ACCESS_LOCK ) ) != NULL)
3594 {
3595 pBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3596
Vinay Krishna Eranna566365f2015-03-09 12:34:13 +05303597 smsLog( pMac, LOG2, "...Bssid= "MAC_ADDRESS_STR" chan= %d, rssi = -%d",
Arif Hussain24bafea2013-11-15 15:10:03 -08003598 MAC_ADDR_ARRAY(pBssDescription->Result.BssDescriptor.bssId),
Jeff Johnson295189b2012-06-20 16:38:30 -07003599 pBssDescription->Result.BssDescriptor.channelId,
3600 pBssDescription->Result.BssDescriptor.rssi * (-1) );
3601
3602 //At this time, pBssDescription->Result.pvIes may be NULL
3603 pIesLocal = (tDot11fBeaconIEs *)( pBssDescription->Result.pvIes );
3604 if( !pIesLocal && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pBssDescription->Result.BssDescriptor, &pIesLocal))) )
3605 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003606 smsLog(pMac, LOGE, FL(" Cannot pared IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003607 csrFreeScanResultEntry(pMac, pBssDescription);
3608 continue;
3609 }
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05303610 fDupBss = csrRemoveDupBssDescription( pMac, &pBssDescription->Result.BssDescriptor, pIesLocal, &tmpSsid, &timer, FALSE );
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07003611 //Check whether we have reach out limit, but don't lose the LFR candidates came from FW
3612 if( CSR_SCAN_IS_OVER_BSS_LIMIT(pMac)
3613#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
3614 && !( eCsrScanGetLfrResult == reason )
3615#endif
3616 )
Jeff Johnson295189b2012-06-20 16:38:30 -07003617 {
Deepthi Gowri50e2fa52016-03-17 15:30:53 +05303618 smsLog(pMac, LOG1, FL("########## BSS Limit reached ###########"));
3619 csrPurgeOldScanResults(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07003620 }
3621 // check for duplicate scan results
3622 if ( !fDupBss )
3623 {
3624 //Found a new BSS
3625 sessionId = csrProcessBSSDescForPMKIDList(pMac,
3626 &pBssDescription->Result.BssDescriptor, pIesLocal);
3627 if( CSR_SESSION_ID_INVALID != sessionId)
3628 {
3629 csrRoamCallCallback(pMac, sessionId, NULL, 0,
3630 eCSR_ROAM_SCAN_FOUND_NEW_BSS, eCSR_ROAM_RESULT_NONE);
3631 }
3632 }
3633 else
3634 {
3635 //Check if the new one has SSID it it, if not, use the older SSID if it exists.
3636 if( (0 == pBssDescription->Result.ssId.length) && tmpSsid.length )
3637 {
3638 //New BSS has a hidden SSID and old one has the SSID. Keep the SSID only
3639 //if diff of saved SSID time and current time is less than 1 min to avoid
3640 //side effect of saving SSID with old one is that if AP changes its SSID while remain
3641 //hidden, we may never see it and also to address the requirement of
3642 //When we remove hidden ssid from the profile i.e., forget the SSID via
3643 // GUI that SSID shouldn't see in the profile
3644 if( (vos_timer_get_system_time() - timer) <= HIDDEN_TIMER)
3645 {
3646 pBssDescription->Result.timer = timer;
3647 pBssDescription->Result.ssId = tmpSsid;
3648 }
3649 }
3650 }
3651
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303652 //Find a good AP for 11d info
3653 if ( csrIs11dSupported( pMac ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003654 {
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303655 // check if country information element is present
3656 if (pIesLocal->Country.present)
Jeff Johnson295189b2012-06-20 16:38:30 -07003657 {
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303658 csrAddVoteForCountryInfo(pMac, pIesLocal->Country.country);
3659 smsLog(pMac, LOGW, FL("11d AP Bssid " MAC_ADDRESS_STR
3660 " chan= %d, rssi = -%d, countryCode %c%c"),
3661 MAC_ADDR_ARRAY( pBssDescription->Result.BssDescriptor.bssId),
3662 pBssDescription->Result.BssDescriptor.channelId,
3663 pBssDescription->Result.BssDescriptor.rssi * (-1),
3664 pIesLocal->Country.country[0],pIesLocal->Country.country[1] );
3665 }
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303666
Jeff Johnson295189b2012-06-20 16:38:30 -07003667 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08003668
Jeff Johnson295189b2012-06-20 16:38:30 -07003669 // append to main list
3670 csrScanAddResult(pMac, pBssDescription, pIesLocal);
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303671 if ( (pBssDescription->Result.pvIes == NULL) && pIesLocal )
Jeff Johnson295189b2012-06-20 16:38:30 -07003672 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303673 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003674 }
3675 }
3676
Kapil Gupta2f2fae42016-09-15 15:29:47 +05303677#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
3678 if (sme_IsFeatureSupportedByFW(PER_BASED_ROAMING) &&
3679 (csrGetInfraSessionId(pMac) != -1) &&
3680 (pMac->scan.occupiedChannels.numChannels != occupied_chan_count))
3681 {
3682 /* Update FW with new list */
3683 smsLog(pMac, LOGW,
3684 FL("Updating occupied channel list, new chanNum %d"),
3685 pMac->scan.occupiedChannels.numChannels);
3686 csrRoamOffloadScan(pMac, ROAM_SCAN_OFFLOAD_UPDATE_CFG,
3687 REASON_CHANNEL_LIST_CHANGED);
3688 }
3689#endif
Sushant Kaushik6274de62015-05-01 16:31:23 +05303690 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
Tushnim Bhattacharyyaae317772013-10-23 18:55:38 -07003691 //we don't need to update CC while connected to an AP which is advertising CC already
3692 if (csrIs11dSupported(pMac))
3693 {
3694 tANI_U32 i;
3695 tCsrRoamSession *pSession;
3696
3697 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
3698 {
3699 if (CSR_IS_SESSION_VALID( pMac, i ) )
3700 {
3701 pSession = CSR_GET_SESSION( pMac, i );
3702 if (csrIsConnStateConnected(pMac, i))
3703 {
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303704 smsLog(pMac, LOGW, FL("No need for updating CC in"
3705 "connected state"));
3706 goto end;
Tushnim Bhattacharyyaae317772013-10-23 18:55:38 -07003707 }
3708 }
3709 }
Agrawal Ashishbd3a5932016-04-12 16:22:39 +05303710 if (csrElectedCountryInfo(pMac))
3711 csrLearnCountryInformation(pMac, NULL, NULL,
3712 eANI_BOOLEAN_TRUE);
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303713 }
3714
Tushnim Bhattacharyyaae317772013-10-23 18:55:38 -07003715end:
3716 //If we can find the current 11d info in any of the scan results, or
Jeff Johnson295189b2012-06-20 16:38:30 -07003717 // a good enough AP with the 11d info from the scan results then no need to
3718 // get into ambiguous state
3719 if(pMac->scan.fAmbiguous11dInfoFound)
3720 {
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303721 if((pMac->scan.fCurrent11dInfoMatch))
Jeff Johnson295189b2012-06-20 16:38:30 -07003722 {
3723 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
3724 }
3725 }
3726
3727#ifdef FEATURE_WLAN_WAPI
3728 if(fNewWapiBSSForCurConnection)
3729 {
3730 //remember it first
3731 csrRoamCallCallback(pMac, sessionId, NULL, 0, eCSR_ROAM_SCAN_FOUND_NEW_BSS, eCSR_ROAM_RESULT_NEW_WAPI_BSS);
3732 }
3733#endif /* FEATURE_WLAN_WAPI */
3734
3735 return;
3736}
3737
Deepthi Gowri50e2fa52016-03-17 15:30:53 +05303738void csrPurgeOldScanResults(tpAniSirGlobal pMac)
3739{
3740 tListElem *pEntry, *tmpEntry;
3741 tCsrScanResult *pResult, *oldest_bss = NULL;
Deepthi Gowri4480a3f2016-05-18 19:30:17 +05303742 v_TIME_t oldest_entry = 0;
3743 v_TIME_t curTime = vos_timer_get_system_time();
Deepthi Gowri50e2fa52016-03-17 15:30:53 +05303744
3745 csrLLLock(&pMac->scan.scanResultList);
3746 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
3747 while( pEntry )
3748 {
3749 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry,
3750 LL_ACCESS_NOLOCK);
3751 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3752 if((curTime -
3753 pResult->Result.BssDescriptor.nReceivedTime) > oldest_entry)
3754 {
3755 oldest_entry = curTime -
3756 pResult->Result.BssDescriptor.nReceivedTime;
3757 oldest_bss = pResult;
3758 }
3759 pEntry = tmpEntry;
3760 }
3761 if (oldest_bss)
3762 {
3763 //Free the old BSS Entries
3764 if( csrLLRemoveEntry(&pMac->scan.scanResultList,
3765 &oldest_bss->Link, LL_ACCESS_NOLOCK) )
3766 {
Deepthi Gowri6a08e312016-03-31 19:10:14 +05303767 smsLog(pMac, LOG1, FL(" Current time delta (%lu) of BSSID to be removed" MAC_ADDRESS_STR ),
Deepthi Gowri50e2fa52016-03-17 15:30:53 +05303768 (curTime - oldest_bss->Result.BssDescriptor.nReceivedTime),
3769 MAC_ADDR_ARRAY(oldest_bss->Result.BssDescriptor.bssId));
3770 csrFreeScanResultEntry(pMac, oldest_bss);
3771 }
3772 }
3773 csrLLUnlock(&pMac->scan.scanResultList);
3774}
Jeff Johnson295189b2012-06-20 16:38:30 -07003775
3776static tCsrScanResult *csrScanSaveBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pBSSDescription,
3777 tDot11fBeaconIEs *pIes)
3778{
3779 tCsrScanResult *pCsrBssDescription = NULL;
3780 tANI_U32 cbBSSDesc;
3781 tANI_U32 cbAllocated;
Sushant Kaushik6274de62015-05-01 16:31:23 +05303782 tListElem *pEntry;
Jeff Johnson295189b2012-06-20 16:38:30 -07003783
3784 // figure out how big the BSS description is (the BSSDesc->length does NOT
3785 // include the size of the length field itself).
3786 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
3787
3788 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
3789
Kiet Lam64c1b492013-07-12 13:56:44 +05303790 pCsrBssDescription = vos_mem_malloc(cbAllocated);
3791 if ( NULL != pCsrBssDescription )
Jeff Johnson295189b2012-06-20 16:38:30 -07003792 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303793 vos_mem_set(pCsrBssDescription, cbAllocated, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003794 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Kiet Lam64c1b492013-07-12 13:56:44 +05303795 vos_mem_copy(&pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc);
Jeff Johnson295189b2012-06-20 16:38:30 -07003796#if defined(VOSS_ENSBALED)
3797 VOS_ASSERT( pCsrBssDescription->Result.pvIes == NULL );
3798#endif
3799 csrScanAddResult(pMac, pCsrBssDescription, pIes);
Sushant Kaushik6274de62015-05-01 16:31:23 +05303800 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
Jeff Johnson295189b2012-06-20 16:38:30 -07003801 }
3802
3803 return( pCsrBssDescription );
3804}
3805
3806// Append a Bss Description...
3807tCsrScanResult *csrScanAppendBssDescription( tpAniSirGlobal pMac,
3808 tSirBssDescription *pSirBssDescription,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07003809 tDot11fBeaconIEs *pIes, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07003810{
3811 tCsrScanResult *pCsrBssDescription = NULL;
3812 tAniSSID tmpSsid;
3813 v_TIME_t timer = 0;
3814 int result;
3815
3816 tmpSsid.length = 0;
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07003817 result = csrRemoveDupBssDescription( pMac, pSirBssDescription, pIes, &tmpSsid, &timer, fForced );
Jeff Johnson295189b2012-06-20 16:38:30 -07003818 pCsrBssDescription = csrScanSaveBssDescription( pMac, pSirBssDescription, pIes );
3819 if (result && (pCsrBssDescription != NULL))
3820 {
3821 //Check if the new one has SSID it it, if not, use the older SSID if it exists.
3822 if( (0 == pCsrBssDescription->Result.ssId.length) && tmpSsid.length )
3823 {
3824 //New BSS has a hidden SSID and old one has the SSID. Keep the SSID only
3825 //if diff of saved SSID time and current time is less than 1 min to avoid
3826 //side effect of saving SSID with old one is that if AP changes its SSID while remain
3827 //hidden, we may never see it and also to address the requirement of
3828 //When we remove hidden ssid from the profile i.e., forget the SSID via
3829 // GUI that SSID shouldn't see in the profile
3830 if((vos_timer_get_system_time()-timer) <= HIDDEN_TIMER)
3831 {
3832 pCsrBssDescription->Result.ssId = tmpSsid;
3833 pCsrBssDescription->Result.timer = timer;
3834 }
3835 }
3836 }
3837
3838
3839 return( pCsrBssDescription );
3840}
3841
3842
3843
3844void csrPurgeChannelPower( tpAniSirGlobal pMac, tDblLinkList *pChannelList )
3845{
3846 tCsrChannelPowerInfo *pChannelSet;
3847 tListElem *pEntry;
3848
3849 csrLLLock(pChannelList);
3850 // Remove the channel sets from the learned list and put them in the free list
3851 while( ( pEntry = csrLLRemoveHead( pChannelList, LL_ACCESS_NOLOCK ) ) != NULL)
3852 {
3853 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3854 if( pChannelSet )
3855 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303856 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003857 }
3858 }
3859 csrLLUnlock(pChannelList);
3860 return;
3861}
3862
3863
3864/*
3865 * Save the channelList into the ultimate storage as the final stage of channel
3866 * Input: pCountryInfo -- the country code (e.g. "USI"), channel list, and power limit are all stored inside this data structure
3867 */
Jeff Johnsone7245742012-09-05 17:12:55 -07003868eHalStatus csrSaveToChannelPower2G_5G( tpAniSirGlobal pMac, tANI_U32 tableSize, tSirMacChanInfo *channelTable )
Jeff Johnson295189b2012-06-20 16:38:30 -07003869{
3870 tANI_U32 i = tableSize / sizeof( tSirMacChanInfo );
3871 tSirMacChanInfo *pChannelInfo;
3872 tCsrChannelPowerInfo *pChannelSet;
3873 tANI_BOOLEAN f2GHzInfoFound = FALSE;
3874 tANI_BOOLEAN f2GListPurged = FALSE, f5GListPurged = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003875
3876 pChannelInfo = channelTable;
3877 // atleast 3 bytes have to be remaining -- from "countryString"
3878 while ( i-- )
3879 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303880 pChannelSet = vos_mem_malloc(sizeof(tCsrChannelPowerInfo));
3881 if ( NULL != pChannelSet )
Jeff Johnson295189b2012-06-20 16:38:30 -07003882 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303883 vos_mem_set(pChannelSet, sizeof(tCsrChannelPowerInfo), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003884 pChannelSet->firstChannel = pChannelInfo->firstChanNum;
3885 pChannelSet->numChannels = pChannelInfo->numChannels;
3886
3887 // Now set the inter-channel offset based on the frequency band the channel set lies in
Jeff Johnsone7245742012-09-05 17:12:55 -07003888 if( (CSR_IS_CHANNEL_24GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003889 ((pChannelSet->firstChannel + (pChannelSet->numChannels - 1)) <= CSR_MAX_24GHz_CHANNEL_NUMBER) )
Jeff Johnsone7245742012-09-05 17:12:55 -07003890
Jeff Johnson295189b2012-06-20 16:38:30 -07003891 {
3892 pChannelSet->interChannelOffset = 1;
3893 f2GHzInfoFound = TRUE;
3894 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003895 else if ( (CSR_IS_CHANNEL_5GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003896 ((pChannelSet->firstChannel + ((pChannelSet->numChannels - 1) * 4)) <= CSR_MAX_5GHz_CHANNEL_NUMBER) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003897 {
3898 pChannelSet->interChannelOffset = 4;
3899 f2GHzInfoFound = FALSE;
3900 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003901 else
3902 {
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003903 smsLog( pMac, LOGW, FL("Invalid Channel %d Present in Country IE"),
Jeff Johnsone7245742012-09-05 17:12:55 -07003904 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303905 vos_mem_free(pChannelSet);
Jeff Johnsone7245742012-09-05 17:12:55 -07003906 return eHAL_STATUS_FAILURE;
3907 }
3908
Jeff Johnson295189b2012-06-20 16:38:30 -07003909 pChannelSet->txPower = CSR_ROAM_MIN( pChannelInfo->maxTxPower, pMac->roam.configParam.nTxPowerCap );
3910
3911 if( f2GHzInfoFound )
3912 {
3913 if( !f2GListPurged )
3914 {
3915 // purge previous results if found new
3916 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList24 );
3917 f2GListPurged = TRUE;
3918 }
3919
3920 if(CSR_IS_OPERATING_BG_BAND(pMac))
3921 {
3922 // add to the list of 2.4 GHz channel sets
3923 csrLLInsertTail( &pMac->scan.channelPowerInfoList24, &pChannelSet->link, LL_ACCESS_LOCK );
3924 }
3925 else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003926 smsLog( pMac, LOGW, FL("Adding 11B/G channels in 11A mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003927 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303928 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003929 }
3930 }
3931 else
3932 {
3933 // 5GHz info found
3934 if( !f5GListPurged )
3935 {
3936 // purge previous results if found new
3937 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList5G );
3938 f5GListPurged = TRUE;
3939 }
3940
3941 if(CSR_IS_OPERATING_A_BAND(pMac))
3942 {
3943 // add to the list of 5GHz channel sets
3944 csrLLInsertTail( &pMac->scan.channelPowerInfoList5G, &pChannelSet->link, LL_ACCESS_LOCK );
3945 }
3946 else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003947 smsLog( pMac, LOGW, FL("Adding 11A channels in B/G mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003948 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303949 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003950 }
3951 }
3952 }
3953
3954 pChannelInfo++; // move to next entry
3955 }
3956
Jeff Johnsone7245742012-09-05 17:12:55 -07003957 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07003958}
3959
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303960static void csrClearDfsChannelList( tpAniSirGlobal pMac )
3961{
3962 tSirMbMsg *pMsg;
3963 tANI_U16 msgLen;
Jeff Johnson295189b2012-06-20 16:38:30 -07003964
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303965 msgLen = (tANI_U16)(sizeof( tSirMbMsg ));
Kiet Lam64c1b492013-07-12 13:56:44 +05303966 pMsg = vos_mem_malloc(msgLen);
3967 if ( NULL != pMsg )
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303968 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303969 vos_mem_set((void *)pMsg, msgLen, 0);
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303970 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_CLEAR_DFS_CHANNEL_LIST);
3971 pMsg->msgLen = pal_cpu_to_be16(msgLen);
3972 palSendMBMessage(pMac->hHdd, pMsg);
3973 }
3974}
Jeff Johnson295189b2012-06-20 16:38:30 -07003975
3976void csrApplyPower2Current( tpAniSirGlobal pMac )
3977{
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003978 smsLog( pMac, LOG3, FL(" Updating Cfg with power settings"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003979 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList24, WNI_CFG_MAX_TX_POWER_2_4 );
3980 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList5G, WNI_CFG_MAX_TX_POWER_5 );
3981}
3982
3983
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003984void csrApplyChannelPowerCountryInfo( tpAniSirGlobal pMac, tCsrChannel *pChannelList, tANI_U8 *countryCode, tANI_BOOLEAN updateRiva)
Jeff Johnson295189b2012-06-20 16:38:30 -07003985{
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303986 int i, j, count, countryIndex = -1;
Jeff Johnson295189b2012-06-20 16:38:30 -07003987 tANI_U8 numChannels = 0;
3988 tANI_U8 tempNumChannels = 0;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303989 tANI_U8 channelIgnore = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003990 tCsrChannel ChannelList;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303991
Jeff Johnson295189b2012-06-20 16:38:30 -07003992 if( pChannelList->numChannels )
3993 {
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303994 for(count=0; count < MAX_COUNTRY_IGNORE; count++)
3995 {
3996 if(vos_mem_compare(countryCode, countryIgnoreList[count].countryCode,
3997 VOS_COUNTRY_CODE_LEN))
3998 {
3999 countryIndex = count;
4000 break;
4001 }
4002 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004003 tempNumChannels = CSR_MIN(pChannelList->numChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN);
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05304004
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304005 for(i=0; i < tempNumChannels; i++)
Jeff Johnson295189b2012-06-20 16:38:30 -07004006 {
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304007 channelIgnore = FALSE;
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05304008 if( countryIndex != -1 )
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304009 {
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05304010 for(j=0; j < countryIgnoreList[countryIndex].channelCount; j++)
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304011 {
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05304012 if( pChannelList->channelList[i] ==
4013 countryIgnoreList[countryIndex].channelList[j] )
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304014 {
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05304015 channelIgnore = TRUE;
4016 break;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304017 }
4018 }
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05304019 }
4020 if( FALSE == channelIgnore )
4021 {
4022 ChannelList.channelList[numChannels] = pChannelList->channelList[i];
4023 numChannels++;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304024 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004025 }
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304026 ChannelList.numChannels = numChannels;
Mahesh A Saptasagar1ed59582014-06-04 18:45:07 +05304027 csrApplyPower2Current( pMac ); // Store the channel+power info in the global place: Cfg
Jeff Johnson295189b2012-06-20 16:38:30 -07004028 csrSetCfgValidChannelList(pMac, ChannelList.channelList, ChannelList.numChannels);
4029 // extend scan capability
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304030 // build a scan list based on the channel list : channel# + active/passive scan
4031 csrSetCfgScanControlList(pMac, countryCode, &ChannelList);
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05304032 /*Send msg to Lim to clear DFS channel list */
4033 csrClearDfsChannelList(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07004034#ifdef FEATURE_WLAN_SCAN_PNO
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004035 if (updateRiva)
4036 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004037 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO, FL(" Sending 11d PNO info to Riva"));
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004038 // Send HAL UpdateScanParams message
4039 pmcUpdateScanParams(pMac, &(pMac->roam.configParam), &ChannelList, TRUE);
4040 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004041#endif // FEATURE_WLAN_SCAN_PNO
4042 }
4043 else
4044 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004045 smsLog( pMac, LOGE, FL(" 11D channel list is empty"));
Jeff Johnson295189b2012-06-20 16:38:30 -07004046 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004047 csrSetCfgCountryCode(pMac, countryCode);
4048}
4049
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004050void csrResetCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce, tANI_BOOLEAN updateRiva )
Jeff Johnson295189b2012-06-20 16:38:30 -07004051{
4052 if( fForce || (csrIs11dSupported( pMac ) && (!pMac->scan.f11dInfoReset)))
4053 {
4054
4055#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4056 {
4057 vos_log_802_11d_pkt_type *p11dLog;
4058 int Index;
4059
4060 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
4061 if(p11dLog)
4062 {
4063 p11dLog->eventId = WLAN_80211D_EVENT_RESET;
Kiet Lam64c1b492013-07-12 13:56:44 +05304064 vos_mem_copy(p11dLog->countryCode, pMac->scan.countryCodeCurrent, 3);
Jeff Johnson295189b2012-06-20 16:38:30 -07004065 p11dLog->numChannel = pMac->scan.base20MHzChannels.numChannels;
4066 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
4067 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304068 vos_mem_copy(p11dLog->Channels,
4069 pMac->scan.base20MHzChannels.channelList,
4070 p11dLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07004071 for (Index=0; Index < pMac->scan.base20MHzChannels.numChannels; Index++)
4072 {
4073 p11dLog->TxPwr[Index] = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
4074 }
4075 }
4076 if(!pMac->roam.configParam.Is11dSupportEnabled)
4077 {
4078 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
4079 }
4080 else if(pMac->roam.configParam.fEnforceDefaultDomain)
4081 {
4082 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
4083 }
4084 else
4085 {
4086 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
4087 }
4088 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
4089 }
4090 }
4091#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4092
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004093 csrPruneChannelListForMode(pMac, &pMac->scan.baseChannels);
4094 csrPruneChannelListForMode(pMac, &pMac->scan.base20MHzChannels);
4095
Jeff Johnson295189b2012-06-20 16:38:30 -07004096 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_FALSE);
4097 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_TRUE);
4098 // ... and apply the channel list, power settings, and the country code.
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004099 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.base20MHzChannels, pMac->scan.countryCodeCurrent, updateRiva );
Jeff Johnson295189b2012-06-20 16:38:30 -07004100 // clear the 11d channel list
Kiet Lam64c1b492013-07-12 13:56:44 +05304101 vos_mem_set(&pMac->scan.channels11d, sizeof(pMac->scan.channels11d), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004102 pMac->scan.f11dInfoReset = eANI_BOOLEAN_TRUE;
4103 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_FALSE;
4104 }
4105
4106 return;
4107}
4108
4109
4110eHalStatus csrResetCountryCodeInformation(tpAniSirGlobal pMac, tANI_BOOLEAN *pfRestartNeeded)
4111{
4112 eHalStatus status = eHAL_STATUS_SUCCESS;
4113 tANI_BOOLEAN fRestart = eANI_BOOLEAN_FALSE;
4114
4115 //Use the Country code and domain from EEPROM
Kiet Lam64c1b492013-07-12 13:56:44 +05304116 vos_mem_copy(pMac->scan.countryCodeCurrent, pMac->scan.countryCodeDefault,
4117 WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07004118 csrSetRegulatoryDomain(pMac, pMac->scan.domainIdCurrent, &fRestart);
Jeff Johnson43971f52012-07-17 12:26:56 -07004119 if( ((eANI_BOOLEAN_FALSE == fRestart) || (pfRestartNeeded == NULL) )
4120 && !csrIsInfraConnected(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -07004121 {
4122 //Only reset the country info if we don't need to restart
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004123 csrResetCountryInformation(pMac, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07004124 }
4125 if(pfRestartNeeded)
4126 {
4127 *pfRestartNeeded = fRestart;
4128 }
4129
4130 return (status);
4131}
4132
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05304133void csrClearVotesForCountryInfo(tpAniSirGlobal pMac)
4134{
4135 pMac->scan.countryCodeCount = 0;
4136 vos_mem_set(pMac->scan.votes11d,
4137 sizeof(tCsrVotes11d) * CSR_MAX_NUM_COUNTRY_CODE, 0);
4138}
4139
4140void csrAddVoteForCountryInfo(tpAniSirGlobal pMac, tANI_U8 *pCountryCode)
4141{
4142 tANI_BOOLEAN match = FALSE;
4143 tANI_U8 i;
4144
4145 /* convert to UPPER here so we are assured
4146 * the strings are always in upper case.
4147 */
4148 for( i = 0; i < 3; i++ )
4149 {
4150 pCountryCode[ i ] = (tANI_U8)csrToUpper( pCountryCode[ i ] );
4151 }
4152
4153 /* Some of the 'old' Cisco 350 series AP's advertise NA as the
4154 * country code (for North America ??). NA is not a valid country code
4155 * or domain so let's allow this by changing it to the proper
4156 * country code (which is US). We've also seen some NETGEAR AP's
4157 * that have "XX " as the country code with valid 2.4 GHz US channel
4158 * information. If we cannot find the country code advertised in the
4159 * 11d information element, let's default to US.
4160 */
4161
4162 if ( !HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry( pMac,
4163 pCountryCode, NULL,COUNTRY_QUERY ) ) )
4164 {
4165 pCountryCode[ 0 ] = '0';
4166 pCountryCode[ 1 ] = '0';
4167 }
4168
4169 /* We've seen some of the AP's improperly put a 0 for the
4170 * third character of the country code. spec says valid charcters are
4171 * 'O' (for outdoor), 'I' for Indoor, or ' ' (space; for either).
4172 * if we see a 0 in this third character, let's change it to a ' '.
4173 */
4174 if ( 0 == pCountryCode[ 2 ] )
4175 {
4176 pCountryCode[ 2 ] = ' ';
4177 }
4178
4179 for (i = 0; i < pMac->scan.countryCodeCount; i++)
4180 {
4181 match = (vos_mem_compare(pMac->scan.votes11d[i].countryCode,
4182 pCountryCode, 2));
4183 if(match)
4184 {
4185 break;
4186 }
4187 }
4188
4189 if (match)
4190 {
4191 pMac->scan.votes11d[i].votes++;
4192 }
4193 else
4194 {
4195 vos_mem_copy( pMac->scan.votes11d[pMac->scan.countryCodeCount].countryCode,
4196 pCountryCode, 3 );
4197 pMac->scan.votes11d[pMac->scan.countryCodeCount].votes = 1;
4198 pMac->scan.countryCodeCount++;
4199 }
4200
4201 return;
4202}
4203
4204tANI_BOOLEAN csrElectedCountryInfo(tpAniSirGlobal pMac)
4205{
4206 tANI_BOOLEAN fRet = FALSE;
4207 tANI_U8 maxVotes = 0;
4208 tANI_U8 i, j=0;
4209
4210 if (!pMac->scan.countryCodeCount)
4211 {
Agrawal Ashishbd3a5932016-04-12 16:22:39 +05304212 VOS_TRACE( VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_WARN,
4213 "No AP with 11d Country code is present in scan list");
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05304214 return fRet;
4215 }
4216 maxVotes = pMac->scan.votes11d[0].votes;
4217 fRet = TRUE;
4218
4219 for(i = 1; i < pMac->scan.countryCodeCount; i++)
4220 {
4221 /* If we have a tie for max votes for 2 different country codes,
4222 * pick random.we can put some more intelligence - TBD
4223 */
4224 if (maxVotes < pMac->scan.votes11d[i].votes)
4225 {
4226 VOS_TRACE( VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
4227 " Votes for Country %c%c : %d\n",
4228 pMac->scan.votes11d[i].countryCode[0],
4229 pMac->scan.votes11d[i].countryCode[1],
4230 pMac->scan.votes11d[i].votes);
4231
4232 maxVotes = pMac->scan.votes11d[i].votes;
4233 j = i;
4234 fRet = TRUE;
4235 }
4236
4237 }
4238 if (fRet)
4239 {
Rajesh Babu Prathipati20cdffa2014-07-01 22:24:59 +05304240 vos_mem_copy(pMac->scan.countryCodeElected,
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05304241 pMac->scan.votes11d[j].countryCode, WNI_CFG_COUNTRY_CODE_LEN);
Rajesh Babu Prathipati20cdffa2014-07-01 22:24:59 +05304242 vos_mem_copy(pMac->scan.countryCode11d,
Agarwal Ashish852b2c32014-05-23 17:13:25 +05304243 pMac->scan.votes11d[j].countryCode, WNI_CFG_COUNTRY_CODE_LEN);
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05304244 VOS_TRACE( VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
4245 "Selected Country is %c%c With count %d\n",
4246 pMac->scan.votes11d[j].countryCode[0],
4247 pMac->scan.votes11d[j].countryCode[1],
4248 pMac->scan.votes11d[j].votes);
4249 }
4250 return fRet;
4251}
Jeff Johnson295189b2012-06-20 16:38:30 -07004252
4253eHalStatus csrSetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pCountry, tANI_BOOLEAN *pfRestartNeeded)
4254{
4255 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
4256 v_REGDOMAIN_t domainId;
4257
4258 if(pCountry)
4259 {
Kiet Lam6c583332013-10-14 05:37:09 +05304260 status = csrGetRegulatoryDomainForCountry(pMac, pCountry, &domainId, COUNTRY_USER);
Jeff Johnson295189b2012-06-20 16:38:30 -07004261 if(HAL_STATUS_SUCCESS(status))
4262 {
4263 status = csrSetRegulatoryDomain(pMac, domainId, pfRestartNeeded);
4264 if(HAL_STATUS_SUCCESS(status))
4265 {
4266 //We don't need to check the pMac->roam.configParam.fEnforceDefaultDomain flag here,
4267 //csrSetRegulatoryDomain will fail if the country doesn't fit our domain criteria.
Kiet Lam64c1b492013-07-12 13:56:44 +05304268 vos_mem_copy(pMac->scan.countryCodeCurrent, pCountry, WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07004269 if((pfRestartNeeded == NULL) || !(*pfRestartNeeded))
4270 {
4271 //Simply set it to cfg. If we need to restart, restart will apply it to the CFG
4272 csrSetCfgCountryCode(pMac, pCountry);
4273 }
4274 }
4275 }
4276 }
4277
4278 return (status);
4279}
4280
4281
4282
4283//caller allocated memory for pNumChn and pChnPowerInfo
4284//As input, *pNumChn has the size of the array of pChnPowerInfo
4285//Upon return, *pNumChn has the number of channels assigned.
4286void csrGetChannelPowerInfo( tpAniSirGlobal pMac, tDblLinkList *pList,
4287 tANI_U32 *pNumChn, tChannelListWithPower *pChnPowerInfo)
4288{
4289 tListElem *pEntry;
4290 tANI_U32 chnIdx = 0, idx;
4291 tCsrChannelPowerInfo *pChannelSet;
4292
4293 //Get 2.4Ghz first
4294 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
4295 while( pEntry && (chnIdx < *pNumChn) )
4296 {
4297 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
4298 if ( 1 != pChannelSet->interChannelOffset )
4299 {
4300 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
4301 {
4302 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
4303 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
4304 }
4305 }
4306 else
4307 {
4308 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
4309 {
4310 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + idx);
4311 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
4312 }
4313 }
4314
4315 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
4316 }
4317 *pNumChn = chnIdx;
4318
4319 return ;
4320}
4321
4322
4323
4324void csrApplyCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce )
4325{
4326 v_REGDOMAIN_t domainId;
4327 eHalStatus status = eHAL_STATUS_SUCCESS;
4328
4329 do
4330 {
4331 if( !csrIs11dSupported( pMac ) || 0 == pMac->scan.channelOf11dInfo) break;
4332 if( pMac->scan.fAmbiguous11dInfoFound )
4333 {
4334 // ambiguous info found
4335 //Restore te default domain as well
Kiet Lam6c583332013-10-14 05:37:09 +05304336 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
4337 pMac, pMac->scan.countryCodeCurrent,
4338 &domainId, COUNTRY_QUERY)))
Jeff Johnson295189b2012-06-20 16:38:30 -07004339 {
4340 pMac->scan.domainIdCurrent = domainId;
4341 }
4342 else
4343 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004344 smsLog(pMac, LOGE, FL(" failed to get domain from currentCountryCode %02X%02X"),
Jeff Johnson295189b2012-06-20 16:38:30 -07004345 pMac->scan.countryCodeCurrent[0], pMac->scan.countryCodeCurrent[1]);
4346 }
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004347 csrResetCountryInformation( pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE );
Jeff Johnson295189b2012-06-20 16:38:30 -07004348 break;
4349 }
4350 if ( pMac->scan.f11dInfoApplied && !fForce ) break;
Kiet Lam6c583332013-10-14 05:37:09 +05304351 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
4352 pMac, pMac->scan.countryCode11d,
4353 &domainId, COUNTRY_QUERY)))
Jeff Johnson295189b2012-06-20 16:38:30 -07004354 {
4355 //Check whether we need to enforce default domain
4356 if( ( !pMac->roam.configParam.fEnforceDefaultDomain ) ||
4357 (pMac->scan.domainIdCurrent == domainId) )
4358 {
4359
4360#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4361 {
4362 vos_log_802_11d_pkt_type *p11dLog;
4363 tChannelListWithPower chnPwrInfo[WNI_CFG_VALID_CHANNEL_LIST_LEN];
4364 tANI_U32 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN, nTmp;
4365
4366 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
4367 if(p11dLog)
4368 {
4369 p11dLog->eventId = WLAN_80211D_EVENT_COUNTRY_SET;
Kiet Lam64c1b492013-07-12 13:56:44 +05304370 vos_mem_copy(p11dLog->countryCode, pMac->scan.countryCode11d, 3);
Jeff Johnson295189b2012-06-20 16:38:30 -07004371 p11dLog->numChannel = pMac->scan.channels11d.numChannels;
4372 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
4373 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304374 vos_mem_copy(p11dLog->Channels,
4375 pMac->scan.channels11d.channelList,
4376 p11dLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07004377 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList24,
4378 &nChnInfo, chnPwrInfo);
4379 nTmp = nChnInfo;
4380 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN - nTmp;
4381 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList5G,
4382 &nChnInfo, &chnPwrInfo[nTmp]);
4383 for(nTmp = 0; nTmp < p11dLog->numChannel; nTmp++)
4384 {
4385 for(nChnInfo = 0; nChnInfo < WNI_CFG_VALID_CHANNEL_LIST_LEN; nChnInfo++)
4386 {
4387 if(p11dLog->Channels[nTmp] == chnPwrInfo[nChnInfo].chanId)
4388 {
4389 p11dLog->TxPwr[nTmp] = chnPwrInfo[nChnInfo].pwr;
4390 break;
4391 }
4392 }
4393 }
4394 }
4395 if(!pMac->roam.configParam.Is11dSupportEnabled)
4396 {
4397 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
4398 }
4399 else if(pMac->roam.configParam.fEnforceDefaultDomain)
4400 {
4401 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
4402 }
4403 else
4404 {
4405 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
4406 }
4407 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
4408 }
4409 }
4410#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4411 if(pMac->scan.domainIdCurrent != domainId)
4412 {
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05304413 smsLog(pMac, LOGW, FL("Domain Changed Old %s (%d), new %s"),
4414 voss_DomainIdtoString(pMac->scan.domainIdCurrent),
4415 pMac->scan.domainIdCurrent,
4416 voss_DomainIdtoString(domainId));
Abhishek Singha306a442013-11-07 18:39:01 +05304417 status = WDA_SetRegDomain(pMac, domainId, eSIR_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07004418 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004419 if (status != eHAL_STATUS_SUCCESS)
4420 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004421 smsLog( pMac, LOGE, FL(" fail to set regId %d"), domainId );
Jeff Johnson295189b2012-06-20 16:38:30 -07004422 }
4423 pMac->scan.domainIdCurrent = domainId;
Kiet Lam6c583332013-10-14 05:37:09 +05304424#ifndef CONFIG_ENABLE_LINUX_REG
Kiet Lambb14e952013-11-19 14:58:29 +05304425 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.base20MHzChannels,
4426 pMac->scan.countryCodeCurrent, eANI_BOOLEAN_TRUE );
Kiet Lam6c583332013-10-14 05:37:09 +05304427#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004428 // switch to active scans using this new channel list
4429 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
4430 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_TRUE;
4431 pMac->scan.f11dInfoReset = eANI_BOOLEAN_FALSE;
4432 }
4433 }
4434
4435 } while( 0 );
4436
4437 return;
4438}
4439
4440
4441
4442tANI_BOOLEAN csrSave11dCountryString( tpAniSirGlobal pMac, tANI_U8 *pCountryCode,
4443 tANI_BOOLEAN fForce)
4444{
4445 tANI_BOOLEAN fCountryStringChanged = FALSE, fUnknownCountryCode = FALSE;
4446 tANI_U32 i;
Kiet Lam6c583332013-10-14 05:37:09 +05304447 v_REGDOMAIN_t regd;
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004448 tANI_BOOLEAN fCountryNotPresentInDriver = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004449
4450 // convert to UPPER here so we are assured the strings are always in upper case.
4451 for( i = 0; i < 3; i++ )
4452 {
4453 pCountryCode[ i ] = (tANI_U8)csrToUpper( pCountryCode[ i ] );
4454 }
4455
4456 // Some of the 'old' Cisco 350 series AP's advertise NA as the country code (for North America ??).
4457 // NA is not a valid country code or domain so let's allow this by changing it to the proper
4458 // country code (which is US). We've also seen some NETGEAR AP's that have "XX " as the country code
4459 // with valid 2.4 GHz US channel information. If we cannot find the country code advertised in the
4460 // 11d information element, let's default to US.
Kiet Lam6c583332013-10-14 05:37:09 +05304461 if ( !HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(pMac,
4462 pCountryCode,
4463 &regd,
4464 COUNTRY_QUERY) ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07004465 {
4466 // Check the enforcement first
4467 if( pMac->roam.configParam.fEnforceDefaultDomain || pMac->roam.configParam.fEnforceCountryCodeMatch )
4468 {
4469 fUnknownCountryCode = TRUE;
4470 }
4471 else
4472 {
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004473 fCountryNotPresentInDriver = TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004474 }
4475 }
Tushnim Bhattacharyyac3c1e8e2013-10-29 17:27:43 -07004476 //right now, even if we don't find the CC in driver we set to world. Making
4477 //sure countryCode11d doesn't get updated with the invalid CC, instead
4478 //reflect the world CC
4479 else if (REGDOMAIN_WORLD == regd)
4480 {
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004481 fCountryNotPresentInDriver = TRUE;
Tushnim Bhattacharyyac3c1e8e2013-10-29 17:27:43 -07004482 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004483
4484 // We've seen some of the AP's improperly put a 0 for the third character of the country code.
4485 // spec says valid charcters are 'O' (for outdoor), 'I' for Indoor, or ' ' (space; for either).
4486 // if we see a 0 in this third character, let's change it to a ' '.
4487 if ( 0 == pCountryCode[ 2 ] )
4488 {
4489 pCountryCode[ 2 ] = ' ';
4490 }
4491
4492 if( !fUnknownCountryCode )
4493 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304494 fCountryStringChanged = (!vos_mem_compare(pMac->scan.countryCode11d, pCountryCode, 2));
Jeff Johnson295189b2012-06-20 16:38:30 -07004495
4496
4497 if(( 0 == pMac->scan.countryCode11d[ 0 ] && 0 == pMac->scan.countryCode11d[ 1 ] )
4498 || (fForce))
4499 {
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004500 if (!fCountryNotPresentInDriver)
4501 {
4502 // this is the first .11d information
4503 vos_mem_copy(pMac->scan.countryCode11d, pCountryCode,
Kiet Lam64c1b492013-07-12 13:56:44 +05304504 sizeof( pMac->scan.countryCode11d ));
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004505
4506 }
4507 else
4508 {
4509 pMac->scan.countryCode11d[0] = '0';
4510 pMac->scan.countryCode11d[1] = '0';
4511 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004512 }
4513 }
4514
4515 return( fCountryStringChanged );
4516}
4517
4518
4519void csrSaveChannelPowerForBand( tpAniSirGlobal pMac, tANI_BOOLEAN fPopulate5GBand )
4520{
4521 tANI_U32 Index, count=0;
4522 tSirMacChanInfo *pChanInfo;
4523 tSirMacChanInfo *pChanInfoStart;
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08004524 tANI_S32 maxChannelIndex;
4525
4526 maxChannelIndex = ( pMac->scan.base20MHzChannels.numChannels < WNI_CFG_VALID_CHANNEL_LIST_LEN ) ?
4527 pMac->scan.base20MHzChannels.numChannels : WNI_CFG_VALID_CHANNEL_LIST_LEN ;
Jeff Johnson295189b2012-06-20 16:38:30 -07004528
Kiet Lam64c1b492013-07-12 13:56:44 +05304529 pChanInfo = vos_mem_malloc(sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN);
4530 if ( NULL != pChanInfo )
Jeff Johnson295189b2012-06-20 16:38:30 -07004531 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304532 vos_mem_set(pChanInfo, sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004533 pChanInfoStart = pChanInfo;
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08004534 for (Index=0; Index < maxChannelIndex; Index++)
Jeff Johnson295189b2012-06-20 16:38:30 -07004535 {
4536 if ((fPopulate5GBand && (CSR_IS_CHANNEL_5GHZ(pMac->scan.defaultPowerTable[Index].chanId))) ||
4537 (!fPopulate5GBand && (CSR_IS_CHANNEL_24GHZ(pMac->scan.defaultPowerTable[Index].chanId))) )
4538 {
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08004539 if(count >= WNI_CFG_VALID_CHANNEL_LIST_LEN)
4540 {
4541 smsLog( pMac, LOGW, FL(" csrSaveChannelPowerForBand, count exceeded, count = %d"), count);
4542 break;
4543 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004544 pChanInfo->firstChanNum = pMac->scan.defaultPowerTable[Index].chanId;
4545 pChanInfo->numChannels = 1;
4546 pChanInfo->maxTxPower = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
4547 pChanInfo++;
4548 count++;
4549 }
4550 }
4551 if(count)
4552 {
4553 csrSaveToChannelPower2G_5G( pMac, count * sizeof(tSirMacChanInfo), pChanInfoStart );
4554 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304555 vos_mem_free(pChanInfoStart);
Jeff Johnson295189b2012-06-20 16:38:30 -07004556 }
4557}
4558
4559
4560void csrSetOppositeBandChannelInfo( tpAniSirGlobal pMac )
4561{
4562 tANI_BOOLEAN fPopulate5GBand = FALSE;
4563
4564 do
4565 {
4566 // if this is not a dual band product, then we don't need to set the opposite
4567 // band info. We only work in one band so no need to look in the other band.
4568 if ( !CSR_IS_OPEARTING_DUAL_BAND( pMac ) ) break;
4569 // if we found channel info on the 5.0 band and...
4570 if ( CSR_IS_CHANNEL_5GHZ( pMac->scan.channelOf11dInfo ) )
4571 {
4572 // and the 2.4 band is empty, then populate the 2.4 channel info
Kiet Lam8d985a02013-10-11 03:39:41 +05304573 if ( !csrLLIsListEmpty( &pMac->scan.channelPowerInfoList24, LL_ACCESS_LOCK ) ) break;
Jeff Johnson295189b2012-06-20 16:38:30 -07004574 fPopulate5GBand = FALSE;
4575 }
4576 else
4577 {
4578 // else, we found channel info in the 2.4 GHz band. If the 5.0 band is empty
4579 // set the 5.0 band info from the 2.4 country code.
Kiet Lam8d985a02013-10-11 03:39:41 +05304580 if ( !csrLLIsListEmpty( &pMac->scan.channelPowerInfoList5G, LL_ACCESS_LOCK ) ) break;
Jeff Johnson295189b2012-06-20 16:38:30 -07004581 fPopulate5GBand = TRUE;
4582 }
4583 csrSaveChannelPowerForBand( pMac, fPopulate5GBand );
4584
4585 } while( 0 );
4586}
4587
4588
4589tANI_BOOLEAN csrIsSupportedChannel(tpAniSirGlobal pMac, tANI_U8 channelId)
4590{
4591 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
4592 tANI_U32 i;
4593
4594 //Make sure it is a channel that is in our supported list.
4595 for ( i = 0; i < pMac->scan.baseChannels.numChannels; i++ )
4596 {
4597 if ( channelId == pMac->scan.baseChannels.channelList[i] )
4598 {
4599 fRet = eANI_BOOLEAN_TRUE;
4600 break;
4601 }
4602 }
4603
4604 //If it is configured to limit a set of the channels
4605 if( fRet && pMac->roam.configParam.fEnforce11dChannels )
4606 {
4607 fRet = eANI_BOOLEAN_FALSE;
4608 for ( i = 0; i < pMac->scan.base20MHzChannels.numChannels; i++ )
4609 {
4610 if ( channelId == pMac->scan.base20MHzChannels.channelList[i] )
4611 {
4612 fRet = eANI_BOOLEAN_TRUE;
4613 break;
4614 }
4615 }
4616 }
4617
4618 return (fRet);
4619}
4620
4621
4622
4623//bSize specify the buffer size of pChannelList
4624tANI_U8 csrGetChannelListFromChannelSet( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 bSize, tCsrChannelPowerInfo *pChannelSet )
4625{
4626 tANI_U8 i, j = 0, chnId;
4627
4628 bSize = CSR_MIN(bSize, pChannelSet->numChannels);
4629 for( i = 0; i < bSize; i++ )
4630 {
4631 chnId = (tANI_U8)(pChannelSet->firstChannel + ( i * pChannelSet->interChannelOffset ));
4632 if ( csrIsSupportedChannel( pMac, chnId ) )
4633 {
4634 pChannelList[j++] = chnId;
4635 }
4636 }
4637
4638 return (j);
4639}
4640
4641
4642
4643//bSize -- specify the buffer size of pChannelList
4644void csrConstructCurrentValidChannelList( tpAniSirGlobal pMac, tDblLinkList *pChannelSetList,
4645 tANI_U8 *pChannelList, tANI_U8 bSize, tANI_U8 *pNumChannels )
4646{
4647 tListElem *pEntry;
4648 tCsrChannelPowerInfo *pChannelSet;
4649 tANI_U8 numChannels;
4650 tANI_U8 *pChannels;
4651
4652 if( pChannelSetList && pChannelList && pNumChannels )
4653 {
4654 pChannels = pChannelList;
4655 *pNumChannels = 0;
4656 pEntry = csrLLPeekHead( pChannelSetList, LL_ACCESS_LOCK );
4657 while( pEntry )
4658 {
4659 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
4660 numChannels = csrGetChannelListFromChannelSet( pMac, pChannels, bSize, pChannelSet );
4661 pChannels += numChannels;
4662 *pNumChannels += numChannels;
4663 pEntry = csrLLNext( pChannelSetList, pEntry, LL_ACCESS_LOCK );
4664 }
4665 }
4666}
4667
4668
4669/*
4670 * 802.11D only: Gather 11d IE via beacon or Probe response and store them in pAdapter->channels11d
4671*/
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304672tANI_BOOLEAN csrLearnCountryInformation( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc,
4673 tDot11fBeaconIEs *pIes, tANI_BOOLEAN fForce)
Jeff Johnson295189b2012-06-20 16:38:30 -07004674{
Agarwal Ashish60a37ee2014-05-28 17:20:20 +05304675 eHalStatus status;
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304676 tANI_U8 *pCountryCodeSelected;
Jeff Johnson295189b2012-06-20 16:38:30 -07004677 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
4678 v_REGDOMAIN_t domainId;
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304679 tDot11fBeaconIEs *pIesLocal = pIes;
4680 tANI_BOOLEAN useVoting = eANI_BOOLEAN_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004681
Jeff Johnson295189b2012-06-20 16:38:30 -07004682 if (VOS_STA_SAP_MODE == vos_get_conparam ())
4683 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07004684
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304685 if ((NULL == pSirBssDesc) && (NULL == pIes))
4686 useVoting = eANI_BOOLEAN_TRUE;
4687
Jeff Johnson295189b2012-06-20 16:38:30 -07004688 do
4689 {
4690 // check if .11d support is enabled
4691 if( !csrIs11dSupported( pMac ) ) break;
Agarwal Ashish60a37ee2014-05-28 17:20:20 +05304692
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304693 if (eANI_BOOLEAN_FALSE == useVoting)
4694 {
4695 if( !pIesLocal &&
4696 (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
4697 pSirBssDesc, &pIesLocal))))
4698 {
4699 break;
4700 }
4701 // check if country information element is present
4702 if(!pIesLocal->Country.present)
4703 {
4704 //No country info
4705 break;
4706 }
4707
4708 if( HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry
4709 (pMac, pIesLocal->Country.country, &domainId,
4710 COUNTRY_QUERY)) &&
4711 ( domainId == REGDOMAIN_WORLD))
4712 {
4713 break;
4714 }
4715 } //useVoting == eANI_BOOLEAN_FALSE
4716
4717 if (eANI_BOOLEAN_FALSE == useVoting)
4718 pCountryCodeSelected = pIesLocal->Country.country;
4719 else
4720 pCountryCodeSelected = pMac->scan.countryCodeElected;
4721
Kiet Lam8d985a02013-10-11 03:39:41 +05304722 status = csrGetRegulatoryDomainForCountry(pMac,
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304723 pCountryCodeSelected, &domainId, COUNTRY_IE);
Kiet Lam8d985a02013-10-11 03:39:41 +05304724 if ( status != eHAL_STATUS_SUCCESS )
4725 {
4726 smsLog( pMac, LOGE, FL(" fail to get regId %d"), domainId );
4727 fRet = eANI_BOOLEAN_FALSE;
4728 break;
4729 }
Agarwal Ashish7693f2d2014-07-18 18:03:58 +05304730
4731 /* updating 11d Country Code with Country code selected. */
4732
4733 vos_mem_copy(pMac->scan.countryCode11d,
4734 pCountryCodeSelected,
4735 WNI_CFG_COUNTRY_CODE_LEN);
4736
Agarwal Ashish60a37ee2014-05-28 17:20:20 +05304737#ifndef CONFIG_ENABLE_LINUX_REG
Venkata Prathyusha Kuntupalli316247e2013-03-15 17:45:25 -07004738 // Checking for Domain Id change
4739 if ( domainId != pMac->scan.domainIdCurrent )
4740 {
Kiet Lam8d985a02013-10-11 03:39:41 +05304741 vos_mem_copy(pMac->scan.countryCode11d,
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304742 pCountryCodeSelected,
Kiet Lam8d985a02013-10-11 03:39:41 +05304743 sizeof( pMac->scan.countryCode11d ) );
4744 /* Set Current Country code and Current Regulatory domain */
4745 status = csrSetRegulatoryDomain(pMac, domainId, NULL);
4746 if (eHAL_STATUS_SUCCESS != status)
4747 {
4748 smsLog(pMac, LOGE, "Set Reg Domain Fail %d", status);
4749 fRet = eANI_BOOLEAN_FALSE;
4750 return fRet;
4751 }
4752 //csrSetRegulatoryDomain will fail if the country doesn't fit our domain criteria.
4753 vos_mem_copy(pMac->scan.countryCodeCurrent,
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304754 pCountryCodeSelected, WNI_CFG_COUNTRY_CODE_LEN);
Kiet Lam8d985a02013-10-11 03:39:41 +05304755 //Simply set it to cfg.
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304756 csrSetCfgCountryCode(pMac, pCountryCodeSelected);
Kiet Lam8d985a02013-10-11 03:39:41 +05304757
4758 /* overwrite the defualt country code */
4759 vos_mem_copy(pMac->scan.countryCodeDefault,
4760 pMac->scan.countryCodeCurrent,
4761 WNI_CFG_COUNTRY_CODE_LEN);
4762 /* Set Current RegDomain */
Abhishek Singha306a442013-11-07 18:39:01 +05304763 status = WDA_SetRegDomain(pMac, domainId, eSIR_TRUE);
Kiet Lam8d985a02013-10-11 03:39:41 +05304764 if ( status != eHAL_STATUS_SUCCESS )
4765 {
4766 smsLog( pMac, LOGE, FL(" fail to Set regId %d"), domainId );
4767 fRet = eANI_BOOLEAN_FALSE;
4768 return fRet;
4769 }
4770 /* set to default domain ID */
Madan Mohan Koyyalamudi0e5922d2013-09-10 15:45:24 +05304771 pMac->scan.domainIdCurrent = domainId;
Kiet Lam8d985a02013-10-11 03:39:41 +05304772 /* get the channels based on new cc */
4773 status = csrInitGetChannels( pMac );
Jeff Johnson295189b2012-06-20 16:38:30 -07004774
Kiet Lam8d985a02013-10-11 03:39:41 +05304775 if ( status != eHAL_STATUS_SUCCESS )
4776 {
4777 smsLog( pMac, LOGE, FL(" fail to get Channels "));
4778 fRet = eANI_BOOLEAN_FALSE;
4779 return fRet;
4780 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004781
Kiet Lam8d985a02013-10-11 03:39:41 +05304782 /* reset info based on new cc, and we are done */
4783 csrResetCountryInformation(pMac, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
Agarwal Ashishfaef6692014-01-29 19:40:30 +05304784 /* Regulatory Domain Changed, Purge Only scan result
4785 * which does not have channel number belong to 11d
4786 * channel list
4787 */
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05304788 csrScanFilterResults(pMac);
Kiet Lam8d985a02013-10-11 03:39:41 +05304789 }
Kiet Lam6c583332013-10-14 05:37:09 +05304790#endif
4791 fRet = eANI_BOOLEAN_TRUE;
4792
Jeff Johnson295189b2012-06-20 16:38:30 -07004793 } while( 0 );
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304794
4795 if( !pIes && pIesLocal )
4796 {
4797 //locally allocated
4798 vos_mem_free(pIesLocal);
4799 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004800
4801 return( fRet );
4802}
4803
4804
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004805static void csrSaveScanResults( tpAniSirGlobal pMac, tANI_U8 reason )
Jeff Johnson295189b2012-06-20 16:38:30 -07004806{
4807 // initialize this to FALSE. profMoveInterimScanResultsToMainList() routine
4808 // will set this to the channel where an .11d beacon is seen
4809 pMac->scan.channelOf11dInfo = 0;
4810 // if we get any ambiguous .11d information then this will be set to TRUE
4811 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
4812 //Tush
4813 // if we get any ambiguous .11d information, then this will be set to TRUE
4814 // only if the applied 11d info could be found in one of the scan results
4815 pMac->scan.fCurrent11dInfoMatch = eANI_BOOLEAN_FALSE;
4816 // move the scan results from interim list to the main scan list
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004817 csrMoveTempScanResultsToMainList( pMac, reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07004818}
4819
4820
4821void csrReinitScanCmd(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4822{
4823 switch (pCommand->u.scanCmd.reason)
4824 {
4825 case eCsrScanSetBGScanParam:
4826 case eCsrScanAbortBgScan:
4827 if(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList)
4828 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304829 vos_mem_free(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList);
Jeff Johnson295189b2012-06-20 16:38:30 -07004830 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
4831 }
4832 break;
4833 case eCsrScanBGScanAbort:
4834 case eCsrScanBGScanEnable:
4835 case eCsrScanGetScanChnInfo:
4836 break;
4837 case eCsrScanAbortNormalScan:
4838 default:
4839 csrScanFreeRequest(pMac, &pCommand->u.scanCmd.u.scanRequest);
4840 break;
4841 }
4842 if(pCommand->u.scanCmd.pToRoamProfile)
4843 {
4844 csrReleaseProfile(pMac, pCommand->u.scanCmd.pToRoamProfile);
Kiet Lam64c1b492013-07-12 13:56:44 +05304845 vos_mem_free(pCommand->u.scanCmd.pToRoamProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07004846 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304847 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004848}
4849
4850
4851tANI_BOOLEAN csrGetRemainingChannelsFor11dScan( tpAniSirGlobal pMac, tANI_U8 *pChannels, tANI_U8 *pcChannels )
4852{
4853 tANI_U32 index11dChannels, index;
4854 tANI_U32 indexCurrentChannels;
4855 tANI_BOOLEAN fChannelAlreadyScanned;
4856 tANI_U32 len = sizeof(pMac->roam.validChannelList);
4857
4858 *pcChannels = 0;
4859 if ( CSR_IS_11D_INFO_FOUND(pMac) && csrRoamIsChannelValid(pMac, pMac->scan.channelOf11dInfo) )
4860 {
4861 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
4862 {
4863 //Find the channel index where we found the 11d info
4864 for(index = 0; index < len; index++)
4865 {
4866 if(pMac->scan.channelOf11dInfo == pMac->roam.validChannelList[index])
4867 break;
4868 }
4869 //check whether we found the channel index
4870 if(index < len)
4871 {
4872 // Now, look through the 11d channel list and create a list of all channels in the 11d list that are
4873 // NOT in the current channel list. This gives us a list of the new channels that have not been
4874 // scanned. We'll scan this new list so we have a complete set of scan results on all of the domain channels
4875 // initially.
4876 for ( index11dChannels = 0; index11dChannels < pMac->scan.channels11d.numChannels; index11dChannels++ )
4877 {
4878 fChannelAlreadyScanned = eANI_BOOLEAN_FALSE;
4879
4880 for( indexCurrentChannels = 0; indexCurrentChannels < index; indexCurrentChannels++ )
4881 {
4882 if ( pMac->roam.validChannelList[ indexCurrentChannels ] == pMac->scan.channels11d.channelList[ index11dChannels ] )
4883 {
4884 fChannelAlreadyScanned = eANI_BOOLEAN_TRUE;
4885 break;
4886 }
4887 }
4888
4889 if ( !fChannelAlreadyScanned )
4890 {
4891 pChannels[ *pcChannels ] = pMac->scan.channels11d.channelList[ index11dChannels ];
4892 ( *pcChannels )++;
4893 }
4894 }
4895 }
4896 }//GetCFG
4897 }
4898 return( *pcChannels );
4899}
4900
4901
4902eCsrScanCompleteNextCommand csrScanGetNextCommandState( tpAniSirGlobal pMac, tSmeCmd *pCommand, tANI_BOOLEAN fSuccess )
4903{
4904 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
4905
4906 switch( pCommand->u.scanCmd.reason )
4907 {
4908 case eCsrScan11d1:
4909 NextCommand = (fSuccess) ? eCsrNext11dScan1Success : eCsrNext11dScan1Failure;
4910 break;
4911 case eCsrScan11d2:
4912 NextCommand = (fSuccess) ? eCsrNext11dScan2Success : eCsrNext11dScan2Failure;
4913 break;
4914 case eCsrScan11dDone:
4915 NextCommand = eCsrNext11dScanComplete;
4916 break;
4917 case eCsrScanLostLink1:
4918 NextCommand = (fSuccess) ? eCsrNextLostLinkScan1Success : eCsrNextLostLinkScan1Failed;
4919 break;
4920 case eCsrScanLostLink2:
4921 NextCommand = (fSuccess) ? eCsrNextLostLinkScan2Success : eCsrNextLostLinkScan2Failed;
4922 break;
4923 case eCsrScanLostLink3:
4924 NextCommand = (fSuccess) ? eCsrNextLostLinkScan3Success : eCsrNextLostLinkScan3Failed;
4925 break;
4926 case eCsrScanForSsid:
4927 NextCommand = (fSuccess) ? eCsrNexteScanForSsidSuccess : eCsrNexteScanForSsidFailure;
4928 break;
4929 case eCsrScanForCapsChange:
4930 NextCommand = eCsrNextCapChangeScanComplete; //don't care success or not
4931 break;
4932 case eCsrScanIdleScan:
4933 NextCommand = eCsrNextIdleScanComplete;
4934 break;
4935 default:
4936 NextCommand = eCsrNextScanNothing;
4937 break;
4938 }
4939 return( NextCommand );
4940}
4941
4942
4943//Return whether the pCommand is finished.
4944tANI_BOOLEAN csrHandleScan11d1Failure(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4945{
4946 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
4947
4948 //Apply back the default setting and passively scan one more time.
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004949 csrResetCountryInformation(pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07004950 pCommand->u.scanCmd.reason = eCsrScan11d2;
4951 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
4952 {
4953 fRet = eANI_BOOLEAN_FALSE;
4954 }
4955
4956 return (fRet);
4957}
4958
4959
4960tANI_BOOLEAN csrHandleScan11dSuccess(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4961{
4962 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
4963 tANI_U8 *pChannels;
4964 tANI_U8 cChannels;
4965
Kiet Lam64c1b492013-07-12 13:56:44 +05304966 pChannels = vos_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
4967 if ( NULL != pChannels )
Jeff Johnson295189b2012-06-20 16:38:30 -07004968 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304969 vos_mem_set(pChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004970 if ( csrGetRemainingChannelsFor11dScan( pMac, pChannels, &cChannels ) )
4971 {
4972 pCommand->u.scanCmd.reason = eCsrScan11dDone;
4973 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
4974 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304975 vos_mem_free(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -07004976 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004977 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304978 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(cChannels);
4979 if ( NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07004980 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304981 vos_mem_copy(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
4982 pChannels, cChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07004983 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = cChannels;
4984 pCommand->u.scanCmd.u.scanRequest.requestType = eCSR_SCAN_REQUEST_FULL_SCAN;
4985 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
4986 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
4987 {
4988 //Reuse the same command buffer
4989 fRet = eANI_BOOLEAN_FALSE;
4990 }
4991 }
4992 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304993 vos_mem_free(pChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07004994 }
4995
4996 return (fRet);
4997}
4998
4999//Return whether the command should be removed
5000tANI_BOOLEAN csrScanComplete( tpAniSirGlobal pMac, tSirSmeScanRsp *pScanRsp )
5001{
5002 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
5003 tListElem *pEntry;
5004 tSmeCmd *pCommand;
5005 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
5006 tANI_BOOLEAN fSuccess;
5007
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305008 if (pMac->fScanOffload)
5009 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
5010 else
5011 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07005012
5013 if ( pEntry )
5014 {
5015 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
5016
5017 // If the head of the queue is Active and it is a SCAN command, remove
5018 // and put this on the Free queue.
5019 if ( eSmeCommandScan == pCommand->command )
5020 {
5021 tANI_U32 sessionId = pCommand->sessionId;
5022
5023 if(eSIR_SME_SUCCESS != pScanRsp->statusCode)
5024 {
5025 fSuccess = eANI_BOOLEAN_FALSE;
5026 }
5027 else
5028 {
5029 //pMac->scan.tempScanResults is not empty meaning the scan found something
5030 //This check only valid here because csrSaveScanresults is not yet called
5031 fSuccess = (!csrLLIsListEmpty(&pMac->scan.tempScanResults, LL_ACCESS_LOCK));
5032 }
Ratheesh S Pece1f832015-07-25 15:50:25 +05305033 if (pCommand->u.scanCmd.abortScanIndication &
5034 eCSR_SCAN_ABORT_DUE_TO_BAND_CHANGE)
Srinivas, Dasari187ca4e2014-02-07 12:40:09 +05305035 {
5036 /*
5037 * Scan aborted due to band change
5038 * The scan results need to be flushed
5039 */
5040 if (pCommand->u.scanCmd.callback
5041 != pMac->scan.callback11dScanDone)
5042 {
5043 smsLog(pMac, LOG1, FL("Filtering the scan results as the "
5044 "results may belong to wrong band"));
5045 csrScanFilterResults(pMac);
5046 }
5047 else
5048 {
5049 smsLog(pMac, LOG1, FL("11d_scan_done will flush the scan"
5050 " results"));
5051 }
Srinivas, Dasari187ca4e2014-02-07 12:40:09 +05305052 }
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005053 csrSaveScanResults(pMac, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07005054
Agrawal Ashishdf752672015-12-09 17:51:53 +05305055 /* filter scan result based on valid channel list number */
5056 if (pMac->scan.fcc_constraint)
5057 {
5058 smsLog(pMac, LOG1, FL("Clear BSS from invalid channels"));
5059 csrScanFilterResults(pMac);
5060 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005061#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5062 {
5063 vos_log_scan_pkt_type *pScanLog = NULL;
5064 tScanResultHandle hScanResult;
5065 tCsrScanResultInfo *pScanResult;
5066 tDot11fBeaconIEs *pIes;
5067 int n = 0, c = 0;
5068
5069 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
5070 if(pScanLog)
5071 {
5072 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
5073 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
5074 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
5075 {
5076 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_RSP;
5077 }
5078 else
5079 {
5080 if( eSIR_PASSIVE_SCAN != pMac->scan.curScanType )
5081 {
5082 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_RSP;
5083 }
5084 else
5085 {
5086 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_RSP;
5087 }
5088 }
5089 if(eSIR_SME_SUCCESS == pScanRsp->statusCode)
5090 {
5091 if(HAL_STATUS_SUCCESS(csrScanGetResult(pMac, NULL, &hScanResult)))
5092 {
5093 while(((pScanResult = csrScanResultGetNext(pMac, hScanResult)) != NULL))
5094 {
5095 if( n < VOS_LOG_MAX_NUM_BSSID )
5096 {
5097 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pScanResult->BssDescriptor, &pIes)))
5098 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005099 smsLog(pMac, LOGE, FL(" fail to parse IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07005100 break;
5101 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305102 vos_mem_copy(pScanLog->bssid[n],
5103 pScanResult->BssDescriptor.bssId, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07005104 if(pIes && pIes->SSID.present && VOS_LOG_MAX_SSID_SIZE >= pIes->SSID.num_ssid)
5105 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305106 vos_mem_copy(pScanLog->ssid[n],
5107 pIes->SSID.ssid, pIes->SSID.num_ssid);
Jeff Johnson295189b2012-06-20 16:38:30 -07005108 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305109 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07005110 n++;
5111 }
5112 c++;
5113 }
5114 pScanLog->numSsid = (v_U8_t)n;
5115 pScanLog->totalSsid = (v_U8_t)c;
5116 csrScanResultPurge(pMac, hScanResult);
5117 }
5118 }
5119 else
5120 {
5121 pScanLog->status = WLAN_SCAN_STATUS_FAILURE;
5122 }
5123 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
5124 }
5125 }
5126#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5127
5128 NextCommand = csrScanGetNextCommandState(pMac, pCommand, fSuccess);
5129 //We reuse the command here instead reissue a new command
5130 switch(NextCommand)
5131 {
5132 case eCsrNext11dScan1Success:
5133 case eCsrNext11dScan2Success:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005134 smsLog( pMac, LOG2, FL("11dScan1/3 produced results. Reissue Active scan..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07005135 // if we found country information, no need to continue scanning further, bail out
5136 fRemoveCommand = eANI_BOOLEAN_TRUE;
5137 NextCommand = eCsrNext11dScanComplete;
5138 break;
5139 case eCsrNext11dScan1Failure:
5140 //We are not done yet. 11d scan fail once. We will try to reset anything and do it over again
5141 //The only meaningful thing for this retry is that we cannot find 11d information after a reset so
5142 //we clear the "old" 11d info and give it once more chance
5143 fRemoveCommand = csrHandleScan11d1Failure(pMac, pCommand);
5144 if(fRemoveCommand)
5145 {
5146 NextCommand = eCsrNext11dScanComplete;
5147 }
5148 break;
5149 case eCsrNextLostLinkScan1Success:
5150 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink1)))
5151 {
5152 csrScanHandleFailedLostlink1(pMac, sessionId);
5153 }
5154 break;
5155 case eCsrNextLostLinkScan2Success:
5156 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink2)))
5157 {
5158 csrScanHandleFailedLostlink2(pMac, sessionId);
5159 }
5160 break;
5161 case eCsrNextLostLinkScan3Success:
5162 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink3)))
5163 {
5164 csrScanHandleFailedLostlink3(pMac, sessionId);
5165 }
5166 break;
5167 case eCsrNextLostLinkScan1Failed:
5168 csrScanHandleFailedLostlink1(pMac, sessionId);
5169 break;
5170 case eCsrNextLostLinkScan2Failed:
5171 csrScanHandleFailedLostlink2(pMac, sessionId);
5172 break;
5173 case eCsrNextLostLinkScan3Failed:
5174 csrScanHandleFailedLostlink3(pMac, sessionId);
5175 break;
5176 case eCsrNexteScanForSsidSuccess:
5177 csrScanHandleSearchForSSID(pMac, pCommand);
5178 break;
5179 case eCsrNexteScanForSsidFailure:
5180 csrScanHandleSearchForSSIDFailure(pMac, pCommand);
5181 break;
5182 case eCsrNextIdleScanComplete:
5183 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
5184 break;
5185 case eCsrNextCapChangeScanComplete:
5186 csrScanHandleCapChangeScanComplete(pMac, sessionId);
5187 break;
5188 default:
5189
5190 break;
5191 }
5192 }
5193 else
5194 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005195 smsLog( pMac, LOGW, FL("Scan Completion called but SCAN command is not ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07005196 fRemoveCommand = eANI_BOOLEAN_FALSE;
5197 }
5198 }
5199 else
5200 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005201 smsLog( pMac, LOGW, FL("Scan Completion called but NO commands are ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07005202 fRemoveCommand = eANI_BOOLEAN_FALSE;
5203 }
5204
5205 return( fRemoveCommand );
5206}
5207
5208
5209
5210static void csrScanRemoveDupBssDescriptionFromInterimList( tpAniSirGlobal pMac,
5211 tSirBssDescription *pSirBssDescr,
5212 tDot11fBeaconIEs *pIes)
5213{
5214 tListElem *pEntry;
5215 tCsrScanResult *pCsrBssDescription;
5216
5217 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
5218 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
5219 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
5220 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
5221 while( pEntry )
5222 {
5223 pCsrBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
5224
5225 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
5226 // matches
5227
5228 if ( csrIsDuplicateBssDescription( pMac, &pCsrBssDescription->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07005229 pSirBssDescr, pIes, FALSE ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07005230 {
5231 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
5232 ((tANI_S32)pCsrBssDescription->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
5233
5234 // Remove the 'old' entry from the list....
5235 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK ) )
5236 {
5237 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pCsrBssDescription->Result.BssDescriptor);
5238 // we need to free the memory associated with this node
5239 csrFreeScanResultEntry( pMac, pCsrBssDescription );
5240 }
5241
5242 // If we found a match, we can stop looking through the list.
5243 break;
5244 }
5245
5246 pEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK );
5247 }
5248}
5249
5250
5251
5252//Caller allocated memory pfNewBssForConn to return whether new candidate for
5253//current connection is found. Cannot be NULL
5254tCsrScanResult *csrScanSaveBssDescriptionToInterimList( tpAniSirGlobal pMac,
5255 tSirBssDescription *pBSSDescription,
5256 tDot11fBeaconIEs *pIes)
5257{
5258 tCsrScanResult *pCsrBssDescription = NULL;
5259 tANI_U32 cbBSSDesc;
5260 tANI_U32 cbAllocated;
Jeff Johnson295189b2012-06-20 16:38:30 -07005261
5262 // figure out how big the BSS description is (the BSSDesc->length does NOT
5263 // include the size of the length field itself).
5264 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
5265
5266 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
5267
Kiet Lam64c1b492013-07-12 13:56:44 +05305268 pCsrBssDescription = vos_mem_malloc(cbAllocated);
5269 if ( NULL != pCsrBssDescription )
Jeff Johnson295189b2012-06-20 16:38:30 -07005270 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305271 vos_mem_set(pCsrBssDescription, cbAllocated, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005272 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Kiet Lam64c1b492013-07-12 13:56:44 +05305273 vos_mem_copy(&pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc );
Jeff Johnson295189b2012-06-20 16:38:30 -07005274 //Save SSID separately for later use
5275 if( pIes->SSID.present && !csrIsNULLSSID(pIes->SSID.ssid, pIes->SSID.num_ssid) )
5276 {
5277 //SSID not hidden
Madan Mohan Koyyalamudi4e31b132012-11-02 13:13:52 -07005278 tANI_U32 len = pIes->SSID.num_ssid;
Jeff Johnson295189b2012-06-20 16:38:30 -07005279 if (len > SIR_MAC_MAX_SSID_LENGTH)
5280 {
5281 // truncate to fit in our struct
5282 len = SIR_MAC_MAX_SSID_LENGTH;
5283 }
5284 pCsrBssDescription->Result.ssId.length = len;
5285 pCsrBssDescription->Result.timer = vos_timer_get_system_time();
Kiet Lam64c1b492013-07-12 13:56:44 +05305286 vos_mem_copy(pCsrBssDescription->Result.ssId.ssId, pIes->SSID.ssid, len);
Jeff Johnson295189b2012-06-20 16:38:30 -07005287 }
5288 csrLLInsertTail( &pMac->scan.tempScanResults, &pCsrBssDescription->Link, LL_ACCESS_LOCK );
5289 }
5290
5291 return( pCsrBssDescription );
5292}
5293
5294
5295
5296
5297tANI_BOOLEAN csrIsDuplicateBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc1,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07005298 tSirBssDescription *pSirBssDesc2, tDot11fBeaconIEs *pIes2, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07005299{
5300 tANI_BOOLEAN fMatch = FALSE;
5301 tSirMacCapabilityInfo *pCap1, *pCap2;
5302 tDot11fBeaconIEs *pIes1 = NULL;
Jeff Johnsone7245742012-09-05 17:12:55 -07005303 tDot11fBeaconIEs *pIesTemp = pIes2;
Jeff Johnson295189b2012-06-20 16:38:30 -07005304
5305 pCap1 = (tSirMacCapabilityInfo *)&pSirBssDesc1->capabilityInfo;
5306 pCap2 = (tSirMacCapabilityInfo *)&pSirBssDesc2->capabilityInfo;
5307 if(pCap1->ess == pCap2->ess)
5308 {
5309 if (pCap1->ess &&
Jeff Johnsone7245742012-09-05 17:12:55 -07005310 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId)&&
Abhishek Singhe3fa11f2014-05-13 11:11:10 +05305311 (fForced || (vos_chan_to_band(pSirBssDesc1->channelId) == vos_chan_to_band((pSirBssDesc2->channelId)))))
Jeff Johnson295189b2012-06-20 16:38:30 -07005312 {
5313 fMatch = TRUE;
Jeff Johnsone7245742012-09-05 17:12:55 -07005314 // Check for SSID match, if exists
5315 do
5316 {
5317 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
5318 {
5319 break;
5320 }
5321 if( NULL == pIesTemp )
5322 {
5323 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
5324 {
5325 break;
5326 }
5327 }
5328 if(pIes1->SSID.present && pIesTemp->SSID.present)
5329 {
5330 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
5331 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
5332 }
5333 }while(0);
5334
Jeff Johnson295189b2012-06-20 16:38:30 -07005335 }
5336 else if (pCap1->ibss && (pSirBssDesc1->channelId == pSirBssDesc2->channelId))
5337 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005338
5339 do
5340 {
5341 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
5342 {
5343 break;
5344 }
5345 if( NULL == pIesTemp )
5346 {
5347 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
5348 {
5349 break;
5350 }
5351 }
5352 //Same channel cannot have same SSID for different IBSS
5353 if(pIes1->SSID.present && pIesTemp->SSID.present)
5354 {
5355 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
5356 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
5357 }
5358 }while(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005359 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005360 /* In case of P2P devices, ess and ibss will be set to zero */
5361 else if (!pCap1->ess &&
5362 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId))
5363 {
5364 fMatch = TRUE;
5365 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005366 }
5367
5368 if(pIes1)
5369 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305370 vos_mem_free(pIes1);
Jeff Johnson295189b2012-06-20 16:38:30 -07005371 }
Jeff Johnsone7245742012-09-05 17:12:55 -07005372
5373 if( (NULL == pIes2) && pIesTemp )
5374 {
5375 //locally allocated
Kiet Lam64c1b492013-07-12 13:56:44 +05305376 vos_mem_free(pIesTemp);
Jeff Johnsone7245742012-09-05 17:12:55 -07005377 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005378
5379 return( fMatch );
5380}
5381
5382
5383tANI_BOOLEAN csrIsNetworkTypeEqual( tSirBssDescription *pSirBssDesc1, tSirBssDescription *pSirBssDesc2 )
5384{
5385 return( pSirBssDesc1->nwType == pSirBssDesc2->nwType );
5386}
5387
5388
5389//to check whether the BSS matches the dot11Mode
5390static tANI_BOOLEAN csrScanIsBssAllowed(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
5391 tDot11fBeaconIEs *pIes)
5392{
5393 tANI_BOOLEAN fAllowed = eANI_BOOLEAN_FALSE;
5394 eCsrPhyMode phyMode;
5395
5396 if(HAL_STATUS_SUCCESS(csrGetPhyModeFromBss(pMac, pBssDesc, &phyMode, pIes)))
5397 {
5398 switch(pMac->roam.configParam.phyMode)
5399 {
5400 case eCSR_DOT11_MODE_11b:
5401 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
5402 break;
5403 case eCSR_DOT11_MODE_11g:
5404 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
5405 break;
5406 case eCSR_DOT11_MODE_11g_ONLY:
5407 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11g == phyMode);
5408 break;
5409 case eCSR_DOT11_MODE_11a:
5410 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11b != phyMode) && (eCSR_DOT11_MODE_11g != phyMode));
5411 break;
5412 case eCSR_DOT11_MODE_11n_ONLY:
5413 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11n == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
5414 break;
Jeff Johnsone7245742012-09-05 17:12:55 -07005415
5416#ifdef WLAN_FEATURE_11AC
5417 case eCSR_DOT11_MODE_11ac_ONLY:
5418 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11ac == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
5419 break;
5420#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005421 case eCSR_DOT11_MODE_11b_ONLY:
5422 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11b == phyMode);
5423 break;
5424 case eCSR_DOT11_MODE_11a_ONLY:
5425 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a == phyMode);
5426 break;
5427 case eCSR_DOT11_MODE_11n:
Jeff Johnsone7245742012-09-05 17:12:55 -07005428#ifdef WLAN_FEATURE_11AC
5429 case eCSR_DOT11_MODE_11ac:
5430#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005431 case eCSR_DOT11_MODE_TAURUS:
5432 default:
5433 fAllowed = eANI_BOOLEAN_TRUE;
5434 break;
5435 }
5436 }
5437
5438 return (fAllowed);
5439}
5440
5441
5442
5443//Return pIes to caller for future use when returning TRUE.
5444static tANI_BOOLEAN csrScanValidateScanResult( tpAniSirGlobal pMac, tANI_U8 *pChannels,
5445 tANI_U8 numChn, tSirBssDescription *pBssDesc,
5446 tDot11fBeaconIEs **ppIes )
5447{
5448 tANI_BOOLEAN fValidChannel = FALSE;
5449 tDot11fBeaconIEs *pIes = NULL;
5450 tANI_U8 index;
5451
5452 for( index = 0; index < numChn; index++ )
5453 {
5454 // This check relies on the fact that a single BSS description is returned in each
5455 // ScanRsp call, which is the way LIM implemented the scan req/rsp funtions. We changed
5456 // to this model when we ran with a large number of APs. If this were to change, then
5457 // this check would have to mess with removing the bssDescription from somewhere in an
5458 // arbitrary index in the bssDescription array.
5459 if ( pChannels[ index ] == pBssDesc->channelId )
5460 {
5461 fValidChannel = TRUE;
5462 break;
5463 }
5464 }
5465 *ppIes = NULL;
5466 if(fValidChannel)
5467 {
5468 if( HAL_STATUS_SUCCESS( csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIes) ) )
5469 {
5470 fValidChannel = csrScanIsBssAllowed(pMac, pBssDesc, pIes);
5471 if( fValidChannel )
5472 {
5473 *ppIes = pIes;
5474 }
5475 else
5476 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305477 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07005478 }
5479 }
5480 else
5481 {
5482 fValidChannel = FALSE;
5483 }
5484 }
5485
5486 return( fValidChannel );
5487}
5488
5489
5490//Return whether last scan result is received
5491static tANI_BOOLEAN csrScanProcessScanResults( tpAniSirGlobal pMac, tSmeCmd *pCommand,
5492 tSirSmeScanRsp *pScanRsp, tANI_BOOLEAN *pfRemoveCommand )
5493{
5494 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE, fRemoveCommand = eANI_BOOLEAN_FALSE;
5495 tDot11fBeaconIEs *pIes = NULL;
5496 tANI_U32 cbParsed;
5497 tSirBssDescription *pSirBssDescription;
5498 tANI_U32 cbBssDesc;
Agrawal Ashish4cc15bb2016-02-04 17:56:16 +05305499 eHalStatus status;
Jeff Johnson295189b2012-06-20 16:38:30 -07005500 tANI_U32 cbScanResult = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription )
5501 + sizeof(tSirBssDescription); //We need at least one CB
5502
5503 // don't consider the scan rsp to be valid if the status code is Scan Failure. Scan Failure
5504 // is returned when the scan could not find anything. so if we get scan failure return that
5505 // the scan response is invalid. Also check the lenght in the scan result for valid scan
5506 // BssDescriptions....
5507 do
5508 {
5509 if ( ( cbScanResult <= pScanRsp->length ) &&
5510 (( eSIR_SME_SUCCESS == pScanRsp->statusCode ) ||
5511 ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW == pScanRsp->statusCode ) ) )
5512 {
5513 tANI_U8 *pChannelList = NULL;
5514 tANI_U8 cChannels = 0;
5515
5516 //Different scan type can reach this point, we need to distinguish it
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005517#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5518 if( eCsrScanGetLfrResult == pCommand->u.scanCmd.reason )
5519 {
5520 pChannelList = NULL;
5521 cChannels = 0;
5522 }
5523 else
5524#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005525 if( eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason )
5526 {
5527 //eCsrScanSetBGScanParam uses different structure
5528 tCsrBGScanRequest *pBgScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
5529
5530 cChannels = pBgScanReq->ChannelInfo.numOfChannels;
5531 pChannelList = pBgScanReq->ChannelInfo.ChannelList;
5532 }
5533 else
5534 {
5535 //the rest use generic scan request
5536 cChannels = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
5537 pChannelList = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
5538 }
5539
5540 // if the scan result is not on one of the channels in the Valid channel list, then it
5541 // must have come from an AP on an overlapping channel (in the 2.4GHz band). In this case,
5542 // let's drop the scan result.
5543 //
5544 // The other situation is where the scan request is for a scan on a particular channel set
5545 // and the scan result is from a
5546
5547 // if the NumChannels is 0, then we are supposed to be scanning all channels. Use the full channel
5548 // list as the 'valid' channel list. Otherwise, use the specific channel list in the scan parms
5549 // as the valid channels.
5550 if ( 0 == cChannels )
5551 {
5552 tANI_U32 len = sizeof(pMac->roam.validChannelList);
5553
5554 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
5555 {
5556 pChannelList = pMac->roam.validChannelList;
5557 cChannels = (tANI_U8)len;
5558 }
5559 else
5560 {
5561 //Cannot continue
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005562 smsLog( pMac, LOGE, "CSR: Processing internal SCAN results...csrGetCfgValidChannels failed" );
Jeff Johnson295189b2012-06-20 16:38:30 -07005563 break;
5564 }
5565 }
5566
5567 smsLog( pMac, LOG2, "CSR: Processing internal SCAN results..." );
5568 cbParsed = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription );
5569 pSirBssDescription = pScanRsp->bssDescription;
5570 while( cbParsed < pScanRsp->length )
5571 {
5572 if ( csrScanValidateScanResult( pMac, pChannelList, cChannels, pSirBssDescription, &pIes ) )
5573 {
5574 csrScanRemoveDupBssDescriptionFromInterimList(pMac, pSirBssDescription, pIes);
5575 csrScanSaveBssDescriptionToInterimList( pMac, pSirBssDescription, pIes );
5576 if( eSIR_PASSIVE_SCAN == pMac->scan.curScanType )
5577 {
5578 if( csrIs11dSupported( pMac) )
5579 {
5580 //Check whether the BSS is acceptable base on 11d info and our configs.
5581 if( csrMatchCountryCode( pMac, NULL, pIes ) )
5582 {
5583 //Double check whether the channel is acceptable by us.
5584 if( csrIsSupportedChannel( pMac, pSirBssDescription->channelId ) )
5585 {
5586 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
5587 }
5588 }
5589 }
5590 else
5591 {
5592 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
5593 }
5594 }
5595 //Free the resource
Kiet Lam64c1b492013-07-12 13:56:44 +05305596 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07005597 }
5598 // skip over the BSS description to the next one...
5599 cbBssDesc = pSirBssDescription->length + sizeof( pSirBssDescription->length );
5600
5601 cbParsed += cbBssDesc;
5602 pSirBssDescription = (tSirBssDescription *)((tANI_U8 *)pSirBssDescription + cbBssDesc );
5603
5604 } //while
5605 }
5606 else
5607 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005608 smsLog( pMac, LOGW, " Scanrsp fail (0x%08X), length = %d (expected %d)",
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08005609 pScanRsp->statusCode, pScanRsp->length, cbScanResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07005610 //HO bg scan/probe failed no need to try autonomously
5611 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
5612 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005613#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5614 eCsrScanGetLfrResult == pCommand->u.scanCmd.reason ||
5615#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005616 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
5617 {
5618 fRemoveCommand = eANI_BOOLEAN_TRUE;
5619 }
5620 }
5621 }while(0);
5622 if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
5623 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005624 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 -07005625 fRemoveCommand = csrScanComplete( pMac, pScanRsp );
5626 fRet = eANI_BOOLEAN_TRUE;
5627 }//if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
5628 if(pfRemoveCommand)
5629 {
5630 *pfRemoveCommand = fRemoveCommand;
5631 }
5632
Agrawal Ashish4cc15bb2016-02-04 17:56:16 +05305633 /*
5634 * Currently SET_FCC_CHANNEL issues updated channel list to fw.
5635 * At the time of driver load, if scan is issued followed with
5636 * SET_FCC_CHANNEL, driver will send update channel list to fw.
5637 * Fw will stop ongoing scan because of that GUI will have very less
5638 * scan list.
5639 * Update channel list should be sent to fw once scan is done
5640 */
5641 if (pMac->scan.defer_update_channel_list) {
5642 status = csrUpdateChannelList(pMac);
5643 if (eHAL_STATUS_SUCCESS != status)
5644 smsLog(pMac, LOGE,
5645 FL( "failed to update the supported channel list"));
5646 pMac->scan.defer_update_channel_list = false;
5647 }
5648
Jeff Johnson295189b2012-06-20 16:38:30 -07005649#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305650 if (pMac->fScanOffload)
5651 return fRet;
5652
Jeff Johnson295189b2012-06-20 16:38:30 -07005653 if (!csrLLIsListEmpty( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK ))
5654 {
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005655 /* Pending scan commands in the list because the previous scan command
5656 * was split into a scan command on one channel + a scan command for all
5657 * remaining channels.
5658 *
5659 * Start timer to trigger processing of the next scan command.
Srikant Kuppa866893f2012-12-27 17:28:14 -08005660 * NOTE for LFR:
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305661 * Do not split scans if no concurrent infra connections are
Srikant Kuppa866893f2012-12-27 17:28:14 -08005662 * active and if the scan is a BG scan triggered by LFR (OR)
5663 * any scan if LFR is in the middle of a BG scan. Splitting
5664 * the scan is delaying the time it takes for LFR to find
5665 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005666 */
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305667 if ( (csrIsStaSessionConnected(pMac) &&
Srikant Kuppa866893f2012-12-27 17:28:14 -08005668#ifdef FEATURE_WLAN_LFR
5669 (csrIsConcurrentInfraConnected(pMac) ||
5670 ((pCommand->u.scanCmd.reason != eCsrScanBgScan) &&
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305671 (pMac->roam.neighborRoamInfo.neighborRoamState !=
Srikant Kuppa866893f2012-12-27 17:28:14 -08005672 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
5673#endif
5674 (pCommand->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305675 (csrIsP2pSessionConnected(pMac)) )
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005676 {
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005677 /* if active connected sessions present then continue to split scan
5678 * with specified interval between consecutive scans */
5679 csrSetDefaultScanTiming(pMac, pCommand->u.scanCmd.u.scanRequest.scanType, &(pCommand->u.scanCmd.u.scanRequest));
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05305680 vos_timer_start(&pMac->scan.hTimerStaApConcTimer,
5681 pCommand->u.scanCmd.u.scanRequest.restTime);
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005682 } else {
5683 /* if no connected sessions present then initiate next scan command immediately */
5684 /* minimum timer granularity is 10ms */
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05305685 vos_timer_start(&pMac->scan.hTimerStaApConcTimer, 10);
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005686 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005687 }
5688#endif
5689 return (fRet);
5690}
5691
5692
5693tANI_BOOLEAN csrScanIsWildCardScan( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5694{
5695 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
Kiet Lam64c1b492013-07-12 13:56:44 +05305696 tANI_BOOLEAN f = vos_mem_compare(pCommand->u.scanCmd.u.scanRequest.bssid,
5697 bssid, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07005698
5699 //It is not a wild card scan if the bssid is not broadcast and the number of SSID is 1.
5700 return ((tANI_BOOLEAN)( (f || (0xff == pCommand->u.scanCmd.u.scanRequest.bssid[0])) &&
5701 (pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs != 1) ));
5702}
5703
5704
5705eHalStatus csrScanSmeScanResponse( tpAniSirGlobal pMac, void *pMsgBuf )
5706{
5707 eHalStatus status = eHAL_STATUS_SUCCESS;
5708 tListElem *pEntry;
5709 tSmeCmd *pCommand;
5710 eCsrScanStatus scanStatus;
Sunkad, Anand Ningappa3ec8bf72016-02-05 15:13:30 +05305711 tSirSmeScanRsp *pScanRsp;
Jeff Johnson295189b2012-06-20 16:38:30 -07005712 tSmeGetScanChnRsp *pScanChnInfo;
5713 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
5714 eCsrScanReason reason = eCsrScanOther;
5715
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305716 if (pMac->fScanOffload)
5717 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList,
5718 LL_ACCESS_LOCK);
5719 else
5720 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07005721
5722 if ( pEntry )
5723 {
5724 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
5725 if ( eSmeCommandScan == pCommand->command )
5726 {
Deepthi Gowrife5340b2016-04-11 12:15:46 +05305727 /* Purge the scan results based on Aging */
5728 if (pEntry && pMac->scan.scanResultCfgAgingTime)
5729 csrPurgeScanResultByAge(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07005730 reason = pCommand->u.scanCmd.reason;
5731 switch(pCommand->u.scanCmd.reason)
5732 {
5733 case eCsrScanAbortBgScan:
5734 case eCsrScanAbortNormalScan:
5735 case eCsrScanBGScanAbort:
5736 case eCsrScanBGScanEnable:
Sunkad, Anand Ningappa3ec8bf72016-02-05 15:13:30 +05305737 pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
5738 scanStatus = (eSIR_SME_SUCCESS == pScanRsp->statusCode) ?
5739 eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005740 break;
5741 case eCsrScanGetScanChnInfo:
Deepthi Gowrife5340b2016-04-11 12:15:46 +05305742 pScanChnInfo = (tSmeGetScanChnRsp *)pMsgBuf;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005743 /*
5744 * status code not available in tSmeGetScanChnRsp, so
5745 * by default considereing it to be success
5746 */
5747 scanStatus = eSIR_SME_SUCCESS;
Deepthi Gowrife5340b2016-04-11 12:15:46 +05305748 csrScanAgeResults(pMac, pScanChnInfo);
Jeff Johnson295189b2012-06-20 16:38:30 -07005749 break;
5750 case eCsrScanForCapsChange:
Sunkad, Anand Ningappa3ec8bf72016-02-05 15:13:30 +05305751 pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
5752 scanStatus = (eSIR_SME_SUCCESS == pScanRsp->statusCode) ?
5753 eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005754 csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand );
5755 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005756 case eCsrScanP2PFindPeer:
Sunkad, Anand Ningappa3ec8bf72016-02-05 15:13:30 +05305757 pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
5758 scanStatus = ((eSIR_SME_SUCCESS == pScanRsp->statusCode) &&
5759 (pScanRsp->length > 50)) ? eCSR_SCAN_FOUND_PEER : eCSR_SCAN_FAILURE;
5760 csrScanProcessScanResults( pMac, pCommand, pScanRsp, NULL );
5761 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005762 case eCsrScanSetBGScanParam:
5763 default:
Sunkad, Anand Ningappa3ec8bf72016-02-05 15:13:30 +05305764 pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
5765 scanStatus = (eSIR_SME_SUCCESS == pScanRsp->statusCode) ?
5766 eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005767 if(csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand ))
5768 {
5769 //Not to get channel info if the scan is not a wildcard scan because
5770 //it may cause scan results got aged out incorrectly.
Ratheesh S Pece1f832015-07-25 15:50:25 +05305771 if(csrScanIsWildCardScan( pMac, pCommand ) &&
5772 (!pCommand->u.scanCmd.u.scanRequest.p2pSearch)
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005773#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5774 && (pCommand->u.scanCmd.reason != eCsrScanGetLfrResult)
5775#endif
5776 )
Jeff Johnson295189b2012-06-20 16:38:30 -07005777 {
Ratheesh S Pece1f832015-07-25 15:50:25 +05305778 csrScanGetScanChnInfo(pMac, pCommand);
Jeff Johnson295189b2012-06-20 16:38:30 -07005779 }
5780 }
5781 break;
5782 }//switch
5783 if(fRemoveCommand)
5784 {
5785
5786 csrReleaseScanCommand(pMac, pCommand, scanStatus);
5787
Sunkad, Anand Ningappa3ec8bf72016-02-05 15:13:30 +05305788 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005789 smeProcessPendingQueue( pMac );
5790 }
5791 else
5792 {
5793 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
5794 status = eHAL_STATUS_FAILURE;
5795 }
5796 }
5797 else
5798 {
5799 smsLog( pMac, LOGW, "CSR: Scan Completion called but NO commands are ACTIVE ..." );
5800 status = eHAL_STATUS_FAILURE;
5801 }
5802
5803 return (status);
5804}
5805
5806
5807
5808
5809tCsrScanResultInfo *csrScanResultGetFirst(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
5810{
5811 tListElem *pEntry;
5812 tCsrScanResult *pResult;
5813 tCsrScanResultInfo *pRet = NULL;
5814 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5815
5816 if(pResultList)
5817 {
5818 csrLLLock(&pResultList->List);
5819 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5820 if(pEntry)
5821 {
5822 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
5823 pRet = &pResult->Result;
5824 }
5825 pResultList->pCurEntry = pEntry;
5826 csrLLUnlock(&pResultList->List);
5827 }
5828
5829 return pRet;
5830}
5831
5832
5833tCsrScanResultInfo *csrScanResultGetNext(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
5834{
5835 tListElem *pEntry = NULL;
5836 tCsrScanResult *pResult = NULL;
5837 tCsrScanResultInfo *pRet = NULL;
5838 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5839
5840 if(pResultList)
5841 {
5842 csrLLLock(&pResultList->List);
5843 if(NULL == pResultList->pCurEntry)
5844 {
5845 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5846 }
5847 else
5848 {
5849 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
5850 }
5851 if(pEntry)
5852 {
5853 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
5854 pRet = &pResult->Result;
5855 }
5856 pResultList->pCurEntry = pEntry;
5857 csrLLUnlock(&pResultList->List);
5858 }
5859
5860 return pRet;
5861}
5862
5863
5864//This function moves the first BSS that matches the bssid to the head of the result
5865eHalStatus csrMoveBssToHeadFromBSSID(tpAniSirGlobal pMac, tCsrBssid *bssid, tScanResultHandle hScanResult)
5866{
5867 eHalStatus status = eHAL_STATUS_FAILURE;
5868 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5869 tCsrScanResult *pResult = NULL;
5870 tListElem *pEntry = NULL;
5871
5872 if(pResultList && bssid)
5873 {
5874 csrLLLock(&pResultList->List);
5875 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5876 while(pEntry)
5877 {
5878 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
Kiet Lam64c1b492013-07-12 13:56:44 +05305879 if (vos_mem_compare(bssid, pResult->Result.BssDescriptor.bssId, sizeof(tCsrBssid)))
Jeff Johnson295189b2012-06-20 16:38:30 -07005880 {
5881 status = eHAL_STATUS_SUCCESS;
5882 csrLLRemoveEntry(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
5883 csrLLInsertHead(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
5884 break;
5885 }
5886 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
5887 }
5888 csrLLUnlock(&pResultList->List);
5889 }
5890
5891 return (status);
5892}
5893
5894
5895//Remove the BSS if possible.
5896//Return -- TRUE == the BSS is remove. False == Fail to remove it
5897//This function is called when list lock is held. Be caution what functions it can call.
5898tANI_BOOLEAN csrScanAgeOutBss(tpAniSirGlobal pMac, tCsrScanResult *pResult)
5899{
5900 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
5901 tANI_U32 i;
5902 tCsrRoamSession *pSession;
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305903 tANI_BOOLEAN isConnBssfound = eANI_BOOLEAN_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005904
5905 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5906 {
5907 if( CSR_IS_SESSION_VALID( pMac, i ) )
5908 {
5909 pSession = CSR_GET_SESSION( pMac, i );
5910 //Not to remove the BSS we are connected to.
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305911 if(csrIsConnStateConnectedInfra(pMac, i) && (NULL != pSession->pConnectBssDesc) &&
5912 (csrIsDuplicateBssDescription(pMac, &pResult->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07005913 pSession->pConnectBssDesc, NULL, FALSE))
Jeff Johnson295189b2012-06-20 16:38:30 -07005914 )
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305915 {
5916 isConnBssfound = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005917 break;
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305918 }
5919 }
5920 }
5921
5922 if( isConnBssfound )
Jeff Johnson295189b2012-06-20 16:38:30 -07005923 {
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305924 //Reset the counter so that aging out of connected BSS won't hapeen too soon
Jeff Johnson295189b2012-06-20 16:38:30 -07005925 pResult->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Deepthi Gowri4480a3f2016-05-18 19:30:17 +05305926 pResult->Result.BssDescriptor.nReceivedTime =
5927 vos_timer_get_system_time();
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305928
5929 return (fRet);
5930 }
5931 else
5932 {
5933 smsLog(pMac, LOGW, "Aging out BSS "MAC_ADDRESS_STR" Channel %d",
5934 MAC_ADDR_ARRAY(pResult->Result.BssDescriptor.bssId),
5935 pResult->Result.BssDescriptor.channelId);
5936 //No need to hold the spin lock because caller should hold the lock for pMac->scan.scanResultList
5937 if( csrLLRemoveEntry(&pMac->scan.scanResultList, &pResult->Link, LL_ACCESS_NOLOCK) )
5938 {
5939 if (csrIsMacAddressEqual(pMac,
5940 (tCsrBssid *) pResult->Result.BssDescriptor.bssId,
5941 (tCsrBssid *) pMac->scan.currentCountryBssid))
5942 {
5943 smsLog(pMac, LOGW, "Aging out 11d BSS "MAC_ADDRESS_STR,
5944 MAC_ADDR_ARRAY(pResult->Result.BssDescriptor.bssId));
5945 pMac->scan.currentCountryRSSI = -128;
5946 }
5947 csrFreeScanResultEntry(pMac, pResult);
5948 fRet = eANI_BOOLEAN_TRUE;
5949 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005950 }
5951
5952 return (fRet);
5953}
5954
5955
5956eHalStatus csrScanAgeResults(tpAniSirGlobal pMac, tSmeGetScanChnRsp *pScanChnInfo)
5957{
5958 eHalStatus status = eHAL_STATUS_SUCCESS;
5959 tListElem *pEntry, *tmpEntry;
5960 tCsrScanResult *pResult;
5961 tLimScanChn *pChnInfo;
5962 tANI_U8 i;
5963
5964 csrLLLock(&pMac->scan.scanResultList);
5965 for(i = 0; i < pScanChnInfo->numChn; i++)
5966 {
5967 pChnInfo = &pScanChnInfo->scanChn[i];
5968 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
5969 while( pEntry )
5970 {
5971 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
5972 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
5973 if(pResult->Result.BssDescriptor.channelId == pChnInfo->channelId)
5974 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005975 if(pResult->AgingCount <= 0)
5976 {
5977 smsLog(pMac, LOGW, " age out due to ref count");
5978 csrScanAgeOutBss(pMac, pResult);
5979 }
Madan Mohan Koyyalamudib9d3dcc2012-09-28 16:47:50 -07005980 else
5981 {
5982 pResult->AgingCount--;
5983 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005984 }
5985 pEntry = tmpEntry;
5986 }
5987 }
5988 csrLLUnlock(&pMac->scan.scanResultList);
5989
5990 return (status);
5991}
5992
Abhishek Singhc640dbb2015-06-08 10:54:17 +05305993eHalStatus csrIbssAgeBss(tpAniSirGlobal pMac)
5994{
5995 eHalStatus status = eHAL_STATUS_SUCCESS;
5996 tListElem *pEntry, *tmpEntry;
5997 tCsrScanResult *pResult;
5998
5999 csrLLLock(&pMac->scan.scanResultList);
6000 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
6001 while( pEntry )
6002 {
6003 tmpEntry = csrLLNext(&pMac->scan.scanResultList,
6004 pEntry, LL_ACCESS_NOLOCK);
6005 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
6006
6007 smsLog(pMac, LOGW, FL(" age out due Forced IBSS leave"));
6008 csrScanAgeOutBss(pMac, pResult);
6009 pEntry = tmpEntry;
6010 }
6011 csrLLUnlock(&pMac->scan.scanResultList);
6012
6013 return (status);
6014}
Jeff Johnson295189b2012-06-20 16:38:30 -07006015
Abhishek Singh72c2f4e2016-07-22 11:25:43 +05306016/**
6017 * csr_remove_bssid_from_scan_list() - remove the bssid from
6018 * scan list
6019 * @pMac: mac context.
6020 * @bssid: bssid to be removed
6021 *
6022 * This function remove the given bssid from scan list.
6023 *
6024 * Return: void.
6025 */
6026void csr_remove_bssid_from_scan_list(tpAniSirGlobal pMac,
6027 tSirMacAddr bssid)
6028{
6029 tListElem *entry,*free_elem;
6030 tCsrScanResult *bss_desc;
6031 tDblLinkList *list = &pMac->scan.scanResultList;
6032
6033 csrLLLock(list);
6034 entry = csrLLPeekHead(list, LL_ACCESS_NOLOCK);
6035 while (entry != NULL) {
6036 bss_desc = GET_BASE_ADDR( entry, tCsrScanResult, Link);
6037 if (vos_mem_compare(bss_desc->Result.BssDescriptor.bssId,
6038 bssid, sizeof(tSirMacAddr))) {
6039 free_elem = entry;
6040 entry = csrLLNext(list, entry, LL_ACCESS_NOLOCK);
6041 csrLLRemoveEntry(list, free_elem, LL_ACCESS_NOLOCK);
6042 csrFreeScanResultEntry(pMac, bss_desc);
6043 smsLog(pMac, LOGW, FL("Removed BSS entry:%pM"),
6044 bssid);
6045 continue;
6046 }
6047 entry = csrLLNext(list, entry, LL_ACCESS_NOLOCK);
6048 }
6049 csrLLUnlock(list);
6050}
6051
Jeff Johnson295189b2012-06-20 16:38:30 -07006052eHalStatus csrSendMBScanReq( tpAniSirGlobal pMac, tANI_U16 sessionId,
6053 tCsrScanRequest *pScanReq, tScanReqParam *pScanReqParam )
6054{
6055 eHalStatus status = eHAL_STATUS_SUCCESS;
6056 tSirSmeScanReq *pMsg;
6057 tANI_U16 msgLen;
6058 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
6059 tSirScanType scanType = pScanReq->scanType;
6060 tANI_U32 minChnTime; //in units of milliseconds
6061 tANI_U32 maxChnTime; //in units of milliseconds
6062 tANI_U32 i;
6063 tANI_U8 selfMacAddr[WNI_CFG_BSSID_LEN];
6064 tANI_U8 *pSelfMac = NULL;
6065
6066 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
6067 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) +
6068 ( pScanReq->uIEFieldLen ) ;
6069
Kiet Lam64c1b492013-07-12 13:56:44 +05306070 pMsg = vos_mem_malloc(msgLen);
6071 if ( NULL == pMsg )
6072 status = eHAL_STATUS_FAILURE;
6073 else
6074 status = eHAL_STATUS_SUCCESS;
6075 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07006076 {
6077 do
6078 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306079 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006080 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
6081 pMsg->length = pal_cpu_to_be16(msgLen);
6082 //ToDO: Fill in session info when we need to do scan base on session.
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05306083 if ((pMac->fScanOffload) && (sessionId != CSR_SESSION_ID_INVALID))
6084 {
6085 pMsg->sessionId = sessionId;
6086 }
6087 else
6088 {
6089 /* if sessionId == CSR_SESSION_ID_INVALID, then send the scan
6090 request on first available session */
6091 pMsg->sessionId = 0;
6092 }
6093
Jeff Johnson295189b2012-06-20 16:38:30 -07006094 pMsg->transactionId = 0;
6095 pMsg->dot11mode = (tANI_U8) csrTranslateToWNICfgDot11Mode(pMac, csrFindBestPhyMode( pMac, pMac->roam.configParam.phyMode ));
6096 pMsg->bssType = pal_cpu_to_be32(csrTranslateBsstypeToMacType(pScanReq->BSSType));
6097
6098 if ( CSR_IS_SESSION_VALID( pMac, sessionId ) )
6099 {
6100 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[sessionId].selfMacAddr;
6101 }
6102 else
6103 {
6104 // Since we don't have session for the scanning, we find a valid session. In case we fail to
6105 // do so, get the WNI_CFG_STA_ID
6106 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
6107 {
6108 if( CSR_IS_SESSION_VALID( pMac, i ) )
6109 {
6110 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[i].selfMacAddr;
6111 break;
6112 }
6113 }
6114 if( CSR_ROAM_SESSION_MAX == i )
6115 {
6116 tANI_U32 len = WNI_CFG_BSSID_LEN;
6117 pSelfMac = selfMacAddr;
6118 status = ccmCfgGetStr( pMac, WNI_CFG_STA_ID, pSelfMac, &len );
6119 if( !HAL_STATUS_SUCCESS( status ) ||
6120 ( len < WNI_CFG_BSSID_LEN ) )
6121 {
6122 smsLog( pMac, LOGE, FL(" Can not get self MAC address from CFG status = %d"), status );
6123 //Force failed status
6124 status = eHAL_STATUS_FAILURE;
6125 break;
6126 }
6127 }
6128 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306129 vos_mem_copy((tANI_U8 *)pMsg->selfMacAddr, pSelfMac, sizeof(tSirMacAddr));
Jeff Johnson295189b2012-06-20 16:38:30 -07006130
6131 //sirCopyMacAddr
Kiet Lam64c1b492013-07-12 13:56:44 +05306132 vos_mem_copy((tANI_U8 *)pMsg->bssId, (tANI_U8 *)&pScanReq->bssid, sizeof(tSirMacAddr));
6133 if ( vos_mem_compare(pScanReq->bssid, bssid, sizeof(tCsrBssid)))
Jeff Johnson295189b2012-06-20 16:38:30 -07006134 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306135 vos_mem_set(pMsg->bssId, sizeof(tSirMacAddr), 0xff);
Jeff Johnson295189b2012-06-20 16:38:30 -07006136 }
6137 else
6138 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306139 vos_mem_copy(pMsg->bssId, pScanReq->bssid, WNI_CFG_BSSID_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07006140 }
6141 minChnTime = pScanReq->minChnTime;
6142 maxChnTime = pScanReq->maxChnTime;
6143
6144 //Verify the scan type first, if the scan is active scan, we need to make sure we
6145 //are allowed to do so.
6146 /* if 11d is enabled & we don't see any beacon around, scan type falls
6147 back to passive. But in BT AMP STA mode we need to send out a
6148 directed probe*/
6149 if( (eSIR_PASSIVE_SCAN != scanType) && (eCSR_SCAN_P2P_DISCOVERY != pScanReq->requestType)
6150 && (eCSR_BSS_TYPE_WDS_STA != pScanReq->BSSType)
6151 && (eANI_BOOLEAN_FALSE == pMac->scan.fEnableBypass11d))
6152 {
6153 scanType = pMac->scan.curScanType;
6154 if(eSIR_PASSIVE_SCAN == pMac->scan.curScanType)
6155 {
6156 if(minChnTime < pMac->roam.configParam.nPassiveMinChnTime)
6157 {
6158 minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
6159 }
6160 if(maxChnTime < pMac->roam.configParam.nPassiveMaxChnTime)
6161 {
6162 maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
6163 }
6164 }
6165 }
6166 pMsg->scanType = pal_cpu_to_be32(scanType);
6167
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306168 pMsg->numSsid =
6169 (pScanReq->SSIDs.numOfSSIDs < SIR_SCAN_MAX_NUM_SSID) ?
6170 pScanReq->SSIDs.numOfSSIDs : SIR_SCAN_MAX_NUM_SSID;
Jeff Johnson295189b2012-06-20 16:38:30 -07006171 if((pScanReq->SSIDs.numOfSSIDs != 0) && ( eSIR_PASSIVE_SCAN != scanType ))
6172 {
Jeff Johnson40b59aa2013-03-19 14:43:18 -07006173 for (i = 0; i < pMsg->numSsid; i++)
6174 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306175 vos_mem_copy(&pMsg->ssId[i],
6176 &pScanReq->SSIDs.SSIDList[i].SSID, sizeof(tSirMacSSid));
Jeff Johnson40b59aa2013-03-19 14:43:18 -07006177 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006178 }
6179 else
6180 {
6181 //Otherwise we scan all SSID and let the result filter later
Jeff Johnson40b59aa2013-03-19 14:43:18 -07006182 for (i = 0; i < SIR_SCAN_MAX_NUM_SSID; i++)
6183 {
6184 pMsg->ssId[i].length = 0;
6185 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006186 }
6187
Jeff Johnson295189b2012-06-20 16:38:30 -07006188 pMsg->minChannelTime = pal_cpu_to_be32(minChnTime);
6189 pMsg->maxChannelTime = pal_cpu_to_be32(maxChnTime);
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08006190 pMsg->minChannelTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
6191 pMsg->maxChannelTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07006192 //hidden SSID option
6193 pMsg->hiddenSsid = pScanReqParam->hiddenSsid;
6194 //rest time
6195 //pMsg->restTime = pScanReq->restTime;
6196 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
6197 // All the scan results caching will be done by Roaming
6198 // We do not want LIM to do any caching of scan results,
6199 // so delete the LIM cache on all scan requests
6200 pMsg->returnFreshResults = pScanReqParam->freshScan;
6201 //Always ask for unique result
6202 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
6203 pMsg->channelList.numChannels = (tANI_U8)pScanReq->ChannelInfo.numOfChannels;
6204 if(pScanReq->ChannelInfo.numOfChannels)
6205 {
6206 //Assuming the channelNumber is tANI_U8 (1 byte)
Kiet Lam64c1b492013-07-12 13:56:44 +05306207 vos_mem_copy(pMsg->channelList.channelNumber,
6208 pScanReq->ChannelInfo.ChannelList,
6209 pScanReq->ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07006210 }
6211
6212 pMsg->uIEFieldLen = (tANI_U16) pScanReq->uIEFieldLen;
6213 pMsg->uIEFieldOffset = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
6214 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) ;
6215 if(pScanReq->uIEFieldLen != 0)
6216 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306217 vos_mem_copy((tANI_U8 *)pMsg+pMsg->uIEFieldOffset, pScanReq->pIEField,
6218 pScanReq->uIEFieldLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07006219 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006220 pMsg->p2pSearch = pScanReq->p2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07006221
Madan Mohan Koyyalamudi9b876782012-10-11 16:22:51 -07006222 if (pScanReq->requestType == eCSR_SCAN_HO_BG_SCAN)
6223 {
6224 pMsg->backgroundScanMode = eSIR_ROAMING_SCAN;
6225 }
6226
Jeff Johnson295189b2012-06-20 16:38:30 -07006227 }while(0);
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05306228 smsLog(pMac, LOG1, FL("domainIdCurrent %s (%d) scanType %s (%d)"
6229 "bssType %s (%d), requestType %s(%d)"
6230 "numChannels %d"),
6231 voss_DomainIdtoString(pMac->scan.domainIdCurrent),
6232 pMac->scan.domainIdCurrent,
6233 lim_ScanTypetoString(pMsg->scanType), pMsg->scanType,
6234 lim_BssTypetoString(pMsg->bssType), pMsg->bssType,
6235 sme_requestTypetoString(pScanReq->requestType),
6236 pScanReq->requestType,
6237 pMsg->channelList.numChannels);
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08006238
6239 for(i = 0; i < pMsg->channelList.numChannels; i++)
6240 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006241 smsLog(pMac, LOG3, FL("channelNumber[%d]= %d"), i, pMsg->channelList.channelNumber[i]);
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08006242 }
6243
Jeff Johnson295189b2012-06-20 16:38:30 -07006244 if(HAL_STATUS_SUCCESS(status))
6245 {
6246 status = palSendMBMessage(pMac->hHdd, pMsg);
6247 }
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08006248 else
6249 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006250 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d"), status );
Kiet Lam64c1b492013-07-12 13:56:44 +05306251 vos_mem_free(pMsg);
Jeff Johnson295189b2012-06-20 16:38:30 -07006252 }
6253 }//Success allocated memory
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08006254 else
6255 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006256 smsLog( pMac, LOGE, FL(" memory allocation failure"));
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08006257 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006258
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306259 if(!HAL_STATUS_SUCCESS(status))
6260 {
6261 smsLog( pMac, LOG1, FL("Failed: SId: %d FirstMatch = %d"
6262 " UniqueResult = %d freshScan = %d hiddenSsid = %d"),
6263 sessionId, pScanReqParam->bReturnAfter1stMatch,
6264 pScanReqParam->fUniqueResult, pScanReqParam->freshScan,
6265 pScanReqParam->hiddenSsid );
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05306266 smsLog( pMac, LOG1, FL("scanType = %s (%d) BSSType = %s (%d) "
6267 "numOfSSIDs = %d numOfChannels = %d requestType = %s (%d)"
6268 " p2pSearch = %d\n"),
6269 lim_ScanTypetoString(pScanReq->scanType),
6270 pScanReq->scanType,
6271 lim_BssTypetoString(pScanReq->BSSType),
6272 pScanReq->BSSType,
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306273 pScanReq->SSIDs.numOfSSIDs,
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05306274 pScanReq->ChannelInfo.numOfChannels,
6275 sme_requestTypetoString(pScanReq->requestType),
6276 pScanReq->requestType,
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306277 pScanReq->p2pSearch );
6278
6279 }
6280
Jeff Johnson295189b2012-06-20 16:38:30 -07006281 return( status );
6282}
6283
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006284eHalStatus csrSendMBScanResultReq( tpAniSirGlobal pMac, tANI_U32 sessionId, tScanReqParam *pScanReqParam )
Jeff Johnson295189b2012-06-20 16:38:30 -07006285{
6286 eHalStatus status = eHAL_STATUS_SUCCESS;
6287 tSirSmeScanReq *pMsg;
6288 tANI_U16 msgLen;
6289
6290 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ));
Kiet Lam64c1b492013-07-12 13:56:44 +05306291 pMsg = vos_mem_malloc(msgLen);
6292 if ( NULL == pMsg )
6293 status = eHAL_STATUS_FAILURE;
6294 else
Jeff Johnson295189b2012-06-20 16:38:30 -07006295 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306296 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006297 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
6298 pMsg->length = pal_cpu_to_be16(msgLen);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006299 pMsg->sessionId = sessionId;
6300 pMsg->transactionId = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07006301 pMsg->returnFreshResults = pScanReqParam->freshScan;
6302 //Always ask for unique result
6303 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
6304 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
6305 status = palSendMBMessage(pMac->hHdd, pMsg);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006306 if (!HAL_STATUS_SUCCESS(status))
6307 {
6308 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d\n"), status );
6309 }
6310
Jeff Johnson295189b2012-06-20 16:38:30 -07006311 }
6312
6313 return( status );
6314}
6315
6316
6317
6318eHalStatus csrScanChannels( tpAniSirGlobal pMac, tSmeCmd *pCommand )
6319{
6320 eHalStatus status = eHAL_STATUS_FAILURE;
6321 tScanReqParam scanReq;
6322
6323 do
6324 {
6325 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE | TRUE;
6326 scanReq.fUniqueResult = TRUE;
6327 scanReq.hiddenSsid = SIR_SCAN_NO_HIDDEN_SSID;
6328 if(eCsrScanForSsid == pCommand->u.scanCmd.reason)
6329 {
6330 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_FIRST_MATCH;
6331 }
6332 else
6333 {
6334 // Basically do scan on all channels even for 11D 1st scan case.
6335 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
6336 }
6337 if((eCsrScanBgScan == pCommand->u.scanCmd.reason)||
6338 (eCsrScanProbeBss == pCommand->u.scanCmd.reason))
6339 {
6340 scanReq.hiddenSsid = SIR_SCAN_HIDDEN_SSID_PE_DECISION;
6341 }
6342
6343#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
6344 {
6345 vos_log_scan_pkt_type *pScanLog = NULL;
6346
6347 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
6348 if(pScanLog)
6349 {
6350 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
6351 eCsrScanProbeBss == pCommand->u.scanCmd.reason)
6352 {
6353 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
6354 }
6355 else
6356 {
6357 if( (eSIR_PASSIVE_SCAN != pCommand->u.scanCmd.u.scanRequest.scanType) &&
6358 (eSIR_PASSIVE_SCAN != pMac->scan.curScanType) )
6359 {
6360 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_REQ;
6361 }
6362 else
6363 {
6364 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_REQ;
6365 }
6366 }
6367 pScanLog->minChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.minChnTime;
6368 pScanLog->maxChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.maxChnTime;
6369 pScanLog->numChannel = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
6370 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
6371 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306372 vos_mem_copy(pScanLog->channels,
6373 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
6374 pScanLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07006375 }
6376 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
6377 }
6378 }
6379#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
6380
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05306381 csrClearVotesForCountryInfo(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07006382 status = csrSendMBScanReq(pMac, pCommand->sessionId,
6383 &pCommand->u.scanCmd.u.scanRequest, &scanReq);
6384 }while(0);
6385
6386 return( status );
6387}
6388
6389
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006390eHalStatus csrScanRetrieveResult(tpAniSirGlobal pMac, tSmeCmd *pCommand)
Jeff Johnson295189b2012-06-20 16:38:30 -07006391{
6392 eHalStatus status = eHAL_STATUS_FAILURE;
6393 tScanReqParam scanReq;
6394
6395 do
6396 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006397#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
6398 if (eCsrScanGetLfrResult == pCommand->u.scanCmd.reason)
6399 {
6400 //to get the LFR candidates from PE cache
6401 scanReq.freshScan = SIR_BG_SCAN_RETURN_LFR_CACHED_RESULTS|SIR_BG_SCAN_PURGE_LFR_RESULTS;
6402 scanReq.fUniqueResult = TRUE;
6403 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
6404 }
6405 else
6406#endif
6407 {
6408 //not a fresh scan
6409 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE;
6410 scanReq.fUniqueResult = TRUE;
6411 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
6412 }
6413 status = csrSendMBScanResultReq(pMac, pCommand->sessionId, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07006414 }while(0);
6415
6416 return (status);
6417}
6418
Siddharth Bhald8a95e82015-02-12 20:14:52 +05306419eHalStatus csrProcessMacAddrSpoofCommand( tpAniSirGlobal pMac, tSmeCmd *pCommand )
6420{
6421 tSirSpoofMacAddrReq *pMsg;
6422 tANI_U16 msgLen;
6423 eHalStatus status = eHAL_STATUS_FAILURE;
6424 do {
6425 msgLen = sizeof(tSirSpoofMacAddrReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07006426
Siddharth Bhald8a95e82015-02-12 20:14:52 +05306427 pMsg = vos_mem_malloc(msgLen);
6428 if ( NULL == pMsg )
6429 return eHAL_STATUS_FAILURE;
6430 pMsg->messageType= pal_cpu_to_be16((tANI_U16)eWNI_SME_MAC_SPOOF_ADDR_IND);
6431 pMsg->length= pal_cpu_to_be16(msgLen);
6432 // spoof mac address
6433 vos_mem_copy((tANI_U8 *)pMsg->macAddr,
6434 (tANI_U8 *)pCommand->u.macAddrSpoofCmd.macAddr, sizeof(tSirMacAddr));
6435 status = palSendMBMessage(pMac->hHdd, pMsg);
6436 } while( 0 );
6437 return( status );
6438}
Jeff Johnson295189b2012-06-20 16:38:30 -07006439
6440eHalStatus csrProcessScanCommand( tpAniSirGlobal pMac, tSmeCmd *pCommand )
6441{
6442 eHalStatus status = eHAL_STATUS_SUCCESS;
6443 tCsrChannelInfo newChannelInfo = {0, NULL};
6444 int i, j;
6445 tANI_U8 *pChannel = NULL;
6446 tANI_U32 len = 0;
6447
6448 // Transition to Scanning state...
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306449 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07006450 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306451 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
6452 {
Abhishek Singhf52182c2016-08-24 11:15:23 +05306453 pMac->roam.prev_state[i]=
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306454 csrRoamStateChange( pMac, eCSR_ROAMING_STATE_SCANNING, i);
6455 smsLog( pMac, LOG3, "starting SCAN command from %d state...."
Abhishek Singhf52182c2016-08-24 11:15:23 +05306456 " reason is %d", pMac->roam.prev_state[i],
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306457 pCommand->u.scanCmd.reason );
6458 }
6459 }
6460 else
6461 {
Abhishek Singhf52182c2016-08-24 11:15:23 +05306462 pMac->roam.prev_state[pCommand->sessionId] =
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306463 csrRoamStateChange(pMac, eCSR_ROAMING_STATE_SCANNING,
6464 pCommand->sessionId);
6465 smsLog( pMac, LOG3,
6466 "starting SCAN command from %d state.... reason is %d",
Abhishek Singhf52182c2016-08-24 11:15:23 +05306467 pMac->roam.prev_state[pCommand->sessionId],
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306468 pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07006469 }
6470
6471 switch(pCommand->u.scanCmd.reason)
6472 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006473#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
6474 case eCsrScanGetLfrResult:
6475#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006476 case eCsrScanGetResult:
6477 case eCsrScanForCapsChange: //For cap change, LIM already save BSS description
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006478 status = csrScanRetrieveResult(pMac, pCommand);
Jeff Johnson295189b2012-06-20 16:38:30 -07006479 break;
6480 case eCsrScanSetBGScanParam:
6481 status = csrProcessSetBGScanParam(pMac, pCommand);
6482 break;
6483 case eCsrScanBGScanAbort:
6484 status = csrSetCfgBackgroundScanPeriod(pMac, 0);
6485 break;
6486 case eCsrScanBGScanEnable:
6487 status = csrSetCfgBackgroundScanPeriod(pMac, pMac->roam.configParam.bgScanInterval);
6488 break;
6489 case eCsrScanGetScanChnInfo:
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05306490 status = csrScanGetScanChannelInfo(pMac, pCommand->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07006491 break;
6492 case eCsrScanUserRequest:
6493 if(pMac->roam.configParam.fScanTwice)
6494 {
6495 //We scan 2.4 channel twice
6496 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels &&
6497 (NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList))
6498 {
6499 len = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
6500 //allocate twice the channel
Mukul Sharmaa631e892014-08-28 15:38:51 +05306501 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(len * 2);
Jeff Johnson295189b2012-06-20 16:38:30 -07006502 pChannel = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
6503 }
6504 else
6505 {
6506 //get the valid channel list to scan all.
6507 len = sizeof(pMac->roam.validChannelList);
6508
6509 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
6510 {
6511 //allocate twice the channel
6512 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(len * 2);
6513 pChannel = pMac->roam.validChannelList;
6514 }
6515 }
6516 if(NULL == newChannelInfo.ChannelList)
6517 {
6518 newChannelInfo.numOfChannels = 0;
6519 }
6520 else
6521 {
6522 j = 0;
6523 for(i = 0; i < len; i++)
6524 {
6525 newChannelInfo.ChannelList[j++] = pChannel[i];
6526 if(CSR_MAX_24GHz_CHANNEL_NUMBER >= pChannel[i])
6527 {
6528 newChannelInfo.ChannelList[j++] = pChannel[i];
6529 }
6530 }
6531 if(NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
6532 {
6533 //pChannel points to the channellist from the command, free it.
6534 vos_mem_free(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -07006535 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07006536 }
6537 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = j;
6538 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = newChannelInfo.ChannelList;
6539 }
6540 } //if(pMac->roam.configParam.fScanTwice)
6541
6542 status = csrScanChannels(pMac, pCommand);
6543
6544 break;
6545 default:
6546 status = csrScanChannels(pMac, pCommand);
6547 break;
6548 }
6549
6550 if(!HAL_STATUS_SUCCESS(status))
6551 {
6552 csrReleaseScanCommand(pMac, pCommand, eCSR_SCAN_FAILURE);
6553 }
6554
6555 return (status);
6556}
6557
6558
6559eHalStatus csrScanSetBGScanparams(tpAniSirGlobal pMac, tCsrBGScanRequest *pScanReq)
6560{
6561 eHalStatus status = eHAL_STATUS_SUCCESS;
6562 tSmeCmd *pCommand = NULL;
6563
6564 if(pScanReq)
6565 {
6566 do
6567 {
6568 pCommand = csrGetCommandBuffer(pMac);
6569 if(!pCommand)
6570 {
6571 status = eHAL_STATUS_RESOURCES;
6572 break;
6573 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306574 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006575 pCommand->command = eSmeCommandScan;
6576 pCommand->u.scanCmd.reason = eCsrScanSetBGScanParam;
6577 pCommand->u.scanCmd.callback = NULL;
6578 pCommand->u.scanCmd.pContext = NULL;
Kiet Lam64c1b492013-07-12 13:56:44 +05306579 vos_mem_copy(&pCommand->u.scanCmd.u.bgScanRequest, pScanReq, sizeof(tCsrBGScanRequest));
Jeff Johnson295189b2012-06-20 16:38:30 -07006580 //we have to do the follow
6581 if(pScanReq->ChannelInfo.numOfChannels == 0)
6582 {
6583 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
6584 }
6585 else
6586 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306587 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList
6588 = vos_mem_malloc(pScanReq->ChannelInfo.numOfChannels);
6589 if ( NULL != pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07006590 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306591 vos_mem_copy(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList,
6592 pScanReq->ChannelInfo.ChannelList,
6593 pScanReq->ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07006594 }
6595 else
6596 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006597 smsLog(pMac, LOGE, FL("ran out of memory"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006598 csrReleaseCommandScan(pMac, pCommand);
Kiet Lam64c1b492013-07-12 13:56:44 +05306599 return eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006600 }
6601 }
6602
6603 //scan req for SSID
6604 if(pScanReq->SSID.length)
6605 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306606 vos_mem_copy(pCommand->u.scanCmd.u.bgScanRequest.SSID.ssId,
6607 pScanReq->SSID.ssId, pScanReq->SSID.length);
Jeff Johnson295189b2012-06-20 16:38:30 -07006608 pCommand->u.scanCmd.u.bgScanRequest.SSID.length = pScanReq->SSID.length;
6609
6610 }
6611 pCommand->u.scanCmd.u.bgScanRequest.maxChnTime= pScanReq->maxChnTime;
6612 pCommand->u.scanCmd.u.bgScanRequest.minChnTime = pScanReq->minChnTime;
6613 pCommand->u.scanCmd.u.bgScanRequest.scanInterval = pScanReq->scanInterval;
6614
6615
6616 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
6617 if( !HAL_STATUS_SUCCESS( status ) )
6618 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006619 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006620 csrReleaseCommandScan( pMac, pCommand );
6621 break;
6622 }
6623 }while(0);
6624 }
6625
6626 return (status);
6627}
6628
6629eHalStatus csrScanBGScanAbort( tpAniSirGlobal pMac )
6630{
6631 eHalStatus status = eHAL_STATUS_SUCCESS;
6632 tSmeCmd *pCommand = NULL;
6633
6634 do
6635 {
6636 pCommand = csrGetCommandBuffer(pMac);
6637 if(!pCommand)
6638 {
6639 status = eHAL_STATUS_RESOURCES;
6640 break;
6641 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306642 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006643 pCommand->command = eSmeCommandScan;
6644 pCommand->u.scanCmd.reason = eCsrScanBGScanAbort;
6645 pCommand->u.scanCmd.callback = NULL;
6646 pCommand->u.scanCmd.pContext = NULL;
6647 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
6648 if( !HAL_STATUS_SUCCESS( status ) )
6649 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006650 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006651 csrReleaseCommandScan( pMac, pCommand );
6652 break;
6653 }
6654 }while(0);
6655
6656 return (status);
6657}
6658
6659
6660//This will enable the background scan with the non-zero interval
6661eHalStatus csrScanBGScanEnable(tpAniSirGlobal pMac)
6662{
6663 eHalStatus status = eHAL_STATUS_SUCCESS;
6664 tSmeCmd *pCommand = NULL;
6665
6666 if(pMac->roam.configParam.bgScanInterval)
6667 {
6668 do
6669 {
6670 pCommand = csrGetCommandBuffer(pMac);
6671 if(!pCommand)
6672 {
6673 status = eHAL_STATUS_RESOURCES;
6674 break;
6675 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306676 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006677 pCommand->command = eSmeCommandScan;
6678 pCommand->u.scanCmd.reason = eCsrScanBGScanEnable;
6679 pCommand->u.scanCmd.callback = NULL;
6680 pCommand->u.scanCmd.pContext = NULL;
6681 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
6682 if( !HAL_STATUS_SUCCESS( status ) )
6683 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006684 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006685 csrReleaseCommandScan( pMac, pCommand );
6686 break;
6687 }
6688 }while(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006689 }
6690 else
6691 {
Sushant Kaushikb8dbb3f2015-04-29 17:03:37 +05306692 smsLog(pMac, LOGE, FL("cannot continue because the bgscan interval is 0"));
6693 status = eHAL_STATUS_INVALID_PARAMETER;
Jeff Johnson295189b2012-06-20 16:38:30 -07006694 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006695 return (status);
6696}
6697
6698
6699eHalStatus csrScanCopyRequest(tpAniSirGlobal pMac, tCsrScanRequest *pDstReq, tCsrScanRequest *pSrcReq)
6700{
6701 eHalStatus status = eHAL_STATUS_SUCCESS;
6702 tANI_U32 len = sizeof(pMac->roam.validChannelList);
6703 tANI_U32 index = 0;
6704 tANI_U32 new_index = 0;
Manjunathappa Prakashde7b2a52014-02-28 16:59:03 -08006705 eNVChannelEnabledType NVchannel_state;
Arif Hussain6af38622014-03-12 12:39:57 -07006706 tANI_U8 ch144_support = 0;
6707
6708 ch144_support = WDA_getFwWlanFeatCaps(WLAN_CH144);
Jeff Johnson295189b2012-06-20 16:38:30 -07006709
6710 do
6711 {
6712 status = csrScanFreeRequest(pMac, pDstReq);
6713 if(HAL_STATUS_SUCCESS(status))
6714 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306715 vos_mem_copy(pDstReq, pSrcReq, sizeof(tCsrScanRequest));
Gopichand Nakkalac7b1d3e2012-12-31 14:07:19 -08006716 /* Re-initialize the pointers to NULL since we did a copy */
6717 pDstReq->pIEField = NULL;
6718 pDstReq->ChannelInfo.ChannelList = NULL;
6719 pDstReq->SSIDs.SSIDList = NULL;
6720
Jeff Johnson295189b2012-06-20 16:38:30 -07006721 if(pSrcReq->uIEFieldLen == 0)
6722 {
6723 pDstReq->pIEField = NULL;
6724 }
6725 else
6726 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306727 pDstReq->pIEField = vos_mem_malloc(pSrcReq->uIEFieldLen);
6728 if ( NULL == pDstReq->pIEField )
Jeff Johnson295189b2012-06-20 16:38:30 -07006729 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306730 status = eHAL_STATUS_FAILURE;
6731 smsLog(pMac, LOGE, FL("No memory for scanning IE fields"));
6732 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07006733 }
6734 else
6735 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306736 status = eHAL_STATUS_SUCCESS;
6737 vos_mem_copy(pDstReq->pIEField, pSrcReq->pIEField,
6738 pSrcReq->uIEFieldLen);
6739 pDstReq->uIEFieldLen = pSrcReq->uIEFieldLen;
Jeff Johnson295189b2012-06-20 16:38:30 -07006740 }
6741 }//Allocate memory for IE field
6742 {
6743 if(pSrcReq->ChannelInfo.numOfChannels == 0)
6744 {
6745 pDstReq->ChannelInfo.ChannelList = NULL;
6746 pDstReq->ChannelInfo.numOfChannels = 0;
6747 }
6748 else
6749 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306750 pDstReq->ChannelInfo.ChannelList = vos_mem_malloc(
6751 pSrcReq->ChannelInfo.numOfChannels
6752 * sizeof(*pDstReq->ChannelInfo.ChannelList));
6753 if ( NULL == pDstReq->ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07006754 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306755 status = eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006756 pDstReq->ChannelInfo.numOfChannels = 0;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306757 smsLog(pMac, LOGE, FL("No memory for scanning Channel"
6758 " List"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006759 break;
6760 }
6761
6762 if((pSrcReq->scanType == eSIR_PASSIVE_SCAN) && (pSrcReq->requestType == eCSR_SCAN_REQUEST_11D_SCAN))
6763 {
6764 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
6765 {
Arif Hussain6af38622014-03-12 12:39:57 -07006766 /* Skip CH 144 if firmware support not present */
6767 if (pSrcReq->ChannelInfo.ChannelList[index] == 144 && !ch144_support)
6768 continue;
Agarwal Ashish8bd53ae2015-06-12 18:03:45 +05306769 /* Skip channel 12 and 13 when FCC constraint is true */
6770 if ((pMac->scan.fcc_constraint) &&
6771 ((pSrcReq->ChannelInfo.ChannelList[index] ==12) ||
6772 (pSrcReq->ChannelInfo.ChannelList[index] ==13)))
6773 {
6774 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
6775 FL("Ignoring channel : %d "),
6776 pSrcReq->ChannelInfo.ChannelList[index]);
6777 continue;
6778 }
Arif Hussain6af38622014-03-12 12:39:57 -07006779
Manjunathappa Prakashde7b2a52014-02-28 16:59:03 -08006780 NVchannel_state = vos_nv_getChannelEnabledState(
6781 pSrcReq->ChannelInfo.ChannelList[index]);
6782 if ((NV_CHANNEL_ENABLE == NVchannel_state) ||
6783 (NV_CHANNEL_DFS == NVchannel_state))
6784 {
6785 pDstReq->ChannelInfo.ChannelList[new_index] =
6786 pSrcReq->ChannelInfo.ChannelList[index];
6787 new_index++;
6788 }
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306789 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006790 pDstReq->ChannelInfo.numOfChannels = new_index;
6791 }
6792 else if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
6793 {
6794 new_index = 0;
6795 pMac->roam.numValidChannels = len;
c_hpothu0d5a7352014-03-22 12:30:25 +05306796
6797 /* Since in CsrScanRequest,value of pMac->scan.nextScanID
6798 * is incremented before calling CsrScanCopyRequest, as a
6799 * result pMac->scan.nextScanID is equal to ONE for the
Abhishek Singha2649232016-01-20 15:52:05 +05306800 * first scan. If number of channels is less than
6801 * max chan for dwell time no need to skip dfs
6802 * in first scan as anyway few channels will be scanned and
6803 * it will not take much time to display results on GUI.
c_hpothu0d5a7352014-03-22 12:30:25 +05306804 */
Abhishek Singha2649232016-01-20 15:52:05 +05306805 if (((pSrcReq->ChannelInfo.numOfChannels >=
6806 pMac->roam.configParam.max_chan_for_dwell_time_cfg) &&
6807 (pMac->roam.configParam.initialScanSkipDFSCh &&
6808 1 == pMac->scan.nextScanID)) ||(pMac->miracast_mode))
c_hpothu0d5a7352014-03-22 12:30:25 +05306809 {
6810 smsLog(pMac, LOG1,
6811 FL("Initial scan, scan only non-DFS channels"));
6812
6813 for (index = 0; index < pSrcReq->ChannelInfo.
6814 numOfChannels ; index++ )
6815 {
6816 if((csrRoamIsValidChannel(pMac, pSrcReq->ChannelInfo.
6817 ChannelList[index])))
6818 {
6819 /*Skiipping DFS Channels for 1st scan */
6820 if(NV_CHANNEL_DFS ==
6821 vos_nv_getChannelEnabledState(pSrcReq->ChannelInfo.
6822 ChannelList[index]))
6823 continue ;
6824
6825 pDstReq->ChannelInfo.ChannelList[new_index] =
6826 pSrcReq->ChannelInfo.ChannelList[index];
6827 new_index++;
6828
6829 }
6830 }
6831 pMac->roam.configParam.initialScanSkipDFSCh = 0;
6832 }
6833 else
6834 {
6835 for ( index = 0; index < pSrcReq->ChannelInfo.
6836 numOfChannels ; index++ )
Jeff Johnson295189b2012-06-20 16:38:30 -07006837 {
Arif Hussain6af38622014-03-12 12:39:57 -07006838 /* Skip CH 144 if firmware support not present */
6839 if (pSrcReq->ChannelInfo.ChannelList[index] == 144 && !ch144_support)
6840 continue;
6841
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -07006842 /* Allow scan on valid channels only.
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -07006843 */
Abhishek Singh2ec36ab2014-08-07 16:14:25 +05306844 if ( ( csrRoamIsValidChannel(pMac, pSrcReq->ChannelInfo.ChannelList[index]) ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07006845 {
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05306846 if( ((pSrcReq->skipDfsChnlInP2pSearch ||
6847 (pMac->scan.fEnableDFSChnlScan ==
6848 DFS_CHNL_SCAN_DISABLED)) &&
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08006849 (NV_CHANNEL_DFS == vos_nv_getChannelEnabledState(pSrcReq->ChannelInfo.ChannelList[index])) )
Srikant Kuppa866893f2012-12-27 17:28:14 -08006850#ifdef FEATURE_WLAN_LFR
6851 /*
6852 * If LFR is requesting a contiguous scan
6853 * (i.e. numOfChannels > 1), then ignore
6854 * DFS channels.
6855 * TODO: vos_nv_getChannelEnabledState is returning
6856 * 120, 124 and 128 as non-DFS channels. Hence, the
6857 * use of direct check for channels below.
6858 */
6859 || ((eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType) &&
6860 (pSrcReq->ChannelInfo.numOfChannels > 1) &&
Santhosh Kumar Padma9ccaaff2014-07-09 19:58:12 +05306861 (CSR_IS_CHANNEL_DFS(pSrcReq->ChannelInfo.ChannelList[index])) &&
6862 !pMac->roam.configParam.allowDFSChannelRoam)
Srikant Kuppa866893f2012-12-27 17:28:14 -08006863#endif
6864 )
6865 {
6866#ifdef FEATURE_WLAN_LFR
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05306867 smsLog(pMac, LOG2,
6868 FL(" reqType=%s (%d), numOfChannels=%d,"
6869 " ignoring DFS channel %d"),
6870 sme_requestTypetoString(pSrcReq->requestType),
6871 pSrcReq->requestType,
6872 pSrcReq->ChannelInfo.numOfChannels,
6873 pSrcReq->ChannelInfo.ChannelList[index]);
Srikant Kuppa866893f2012-12-27 17:28:14 -08006874#endif
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05306875 continue;
Srikant Kuppa866893f2012-12-27 17:28:14 -08006876 }
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08006877
Jeff Johnson295189b2012-06-20 16:38:30 -07006878 pDstReq->ChannelInfo.ChannelList[new_index] =
6879 pSrcReq->ChannelInfo.ChannelList[index];
6880 new_index++;
6881 }
6882 }
c_hpothu0d5a7352014-03-22 12:30:25 +05306883 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006884 pDstReq->ChannelInfo.numOfChannels = new_index;
Srikant Kuppa866893f2012-12-27 17:28:14 -08006885#ifdef FEATURE_WLAN_LFR
Abhishek Singh2ec36ab2014-08-07 16:14:25 +05306886 if ( ( ( eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType ) ||
6887 ( eCSR_SCAN_P2P_DISCOVERY == pSrcReq->requestType ) ) &&
6888 ( 0 == pDstReq->ChannelInfo.numOfChannels ) )
Srikant Kuppa866893f2012-12-27 17:28:14 -08006889 {
6890 /*
6891 * No valid channels found in the request.
6892 * Only perform scan on the channels passed
Abhishek Singh2ec36ab2014-08-07 16:14:25 +05306893 * pSrcReq if it is a eCSR_SCAN_HO_BG_SCAN or
6894 * eCSR_SCAN_P2P_DISCOVERY.
Srikant Kuppa866893f2012-12-27 17:28:14 -08006895 * Passing 0 to LIM will trigger a scan on
6896 * all valid channels which is not desirable.
6897 */
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306898 smsLog(pMac, LOGE, FL(" no valid channels found"
6899 " (request=%d)"), pSrcReq->requestType);
Srikant Kuppa866893f2012-12-27 17:28:14 -08006900 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
6901 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306902 smsLog(pMac, LOGE, FL("pSrcReq index=%d"
6903 " channel=%d"), index,
6904 pSrcReq->ChannelInfo.ChannelList[index]);
Srikant Kuppa866893f2012-12-27 17:28:14 -08006905 }
6906 status = eHAL_STATUS_FAILURE;
6907 break;
6908 }
6909#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006910 }
6911 else
6912 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306913 smsLog(pMac, LOGE, FL("Couldn't get the valid Channel"
6914 " List, keeping requester's list"));
Kiet Lam64c1b492013-07-12 13:56:44 +05306915 vos_mem_copy(pDstReq->ChannelInfo.ChannelList,
6916 pSrcReq->ChannelInfo.ChannelList,
6917 pSrcReq->ChannelInfo.numOfChannels
6918 * sizeof(*pDstReq->ChannelInfo.ChannelList));
Jeff Johnson295189b2012-06-20 16:38:30 -07006919 pDstReq->ChannelInfo.numOfChannels = pSrcReq->ChannelInfo.numOfChannels;
6920 }
6921 }//Allocate memory for Channel List
6922 }
6923 if(pSrcReq->SSIDs.numOfSSIDs == 0)
6924 {
6925 pDstReq->SSIDs.numOfSSIDs = 0;
6926 pDstReq->SSIDs.SSIDList = NULL;
6927 }
6928 else
6929 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306930 pDstReq->SSIDs.SSIDList = vos_mem_malloc(
6931 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
6932 if ( NULL == pDstReq->SSIDs.SSIDList )
6933 status = eHAL_STATUS_FAILURE;
6934 else
6935 status = eHAL_STATUS_SUCCESS;
6936 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07006937 {
6938 pDstReq->SSIDs.numOfSSIDs = pSrcReq->SSIDs.numOfSSIDs;
Kiet Lam64c1b492013-07-12 13:56:44 +05306939 vos_mem_copy(pDstReq->SSIDs.SSIDList,
6940 pSrcReq->SSIDs.SSIDList,
6941 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
Jeff Johnson295189b2012-06-20 16:38:30 -07006942 }
6943 else
6944 {
6945 pDstReq->SSIDs.numOfSSIDs = 0;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306946 smsLog(pMac, LOGE, FL("No memory for scanning SSID List"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006947 break;
6948 }
6949 }//Allocate memory for SSID List
Jeff Johnson295189b2012-06-20 16:38:30 -07006950 pDstReq->p2pSearch = pSrcReq->p2pSearch;
Jeff Johnsone7245742012-09-05 17:12:55 -07006951 pDstReq->skipDfsChnlInP2pSearch = pSrcReq->skipDfsChnlInP2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07006952
6953 }
6954 }while(0);
6955
6956 if(!HAL_STATUS_SUCCESS(status))
6957 {
6958 csrScanFreeRequest(pMac, pDstReq);
6959 }
6960
6961 return (status);
6962}
6963
6964
6965eHalStatus csrScanFreeRequest(tpAniSirGlobal pMac, tCsrScanRequest *pReq)
6966{
Jeff Johnson295189b2012-06-20 16:38:30 -07006967
6968 if(pReq->ChannelInfo.ChannelList)
6969 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306970 vos_mem_free(pReq->ChannelInfo.ChannelList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006971 pReq->ChannelInfo.ChannelList = NULL;
6972 }
6973 pReq->ChannelInfo.numOfChannels = 0;
6974 if(pReq->pIEField)
6975 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306976 vos_mem_free(pReq->pIEField);
Jeff Johnson295189b2012-06-20 16:38:30 -07006977 pReq->pIEField = NULL;
6978 }
6979 pReq->uIEFieldLen = 0;
6980 if(pReq->SSIDs.SSIDList)
6981 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306982 vos_mem_free(pReq->SSIDs.SSIDList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006983 pReq->SSIDs.SSIDList = NULL;
6984 }
6985 pReq->SSIDs.numOfSSIDs = 0;
6986
Kiet Lam64c1b492013-07-12 13:56:44 +05306987 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07006988}
6989
6990
6991void csrScanCallCallback(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
6992{
6993 if(pCommand->u.scanCmd.callback)
6994 {
Ratheesh S Pece1f832015-07-25 15:50:25 +05306995 if (pCommand->u.scanCmd.abortScanIndication){
6996 smsLog( pMac, LOG1, FL("scanDone due to abort"));
6997 scanStatus = eCSR_SCAN_ABORT;
6998 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006999// sme_ReleaseGlobalLock( &pMac->sme );
7000 pCommand->u.scanCmd.callback(pMac, pCommand->u.scanCmd.pContext, pCommand->u.scanCmd.scanID, scanStatus);
7001// sme_AcquireGlobalLock( &pMac->sme );
7002 } else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007003 smsLog( pMac, LOG2, "%s:%d - Callback NULL!!!", __func__, __LINE__);
Jeff Johnson295189b2012-06-20 16:38:30 -07007004 }
7005}
7006
7007
7008void csrScanStopTimers(tpAniSirGlobal pMac)
7009{
Jeff Johnson295189b2012-06-20 16:38:30 -07007010 csrScanStopIdleScanTimer(pMac);
7011 csrScanStopGetResultTimer(pMac);
7012}
7013
7014
7015eHalStatus csrScanStartGetResultTimer(tpAniSirGlobal pMac)
7016{
7017 eHalStatus status;
7018
7019 if(pMac->scan.fScanEnable)
7020 {
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05307021 status = vos_timer_start(&pMac->scan.hTimerGetResult, CSR_SCAN_GET_RESULT_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07007022 }
7023 else
7024 {
7025 status = eHAL_STATUS_FAILURE;
7026 }
7027
7028 return (status);
7029}
7030
7031
7032eHalStatus csrScanStopGetResultTimer(tpAniSirGlobal pMac)
7033{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05307034 return (vos_timer_stop(&pMac->scan.hTimerGetResult));
Jeff Johnson295189b2012-06-20 16:38:30 -07007035}
7036
7037
7038void csrScanGetResultTimerHandler(void *pv)
7039{
7040 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
7041
7042 csrScanRequestResult(pMac);
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05307043
7044 vos_timer_start(&pMac->scan.hTimerGetResult, CSR_SCAN_GET_RESULT_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07007045}
7046
7047#ifdef WLAN_AP_STA_CONCURRENCY
7048static void csrStaApConcTimerHandler(void *pv)
7049{
7050 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
7051 tListElem *pEntry;
7052 tSmeCmd *pScanCmd;
7053
7054 csrLLLock(&pMac->scan.scanCmdPendingList);
7055
7056 if ( NULL != ( pEntry = csrLLPeekHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) ) )
7057 {
7058 tCsrScanRequest scanReq;
7059 tSmeCmd *pSendScanCmd = NULL;
7060 tANI_U8 numChn = 0;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07007061 tANI_U8 nNumChanCombinedConc = 0;
Vinay Malekal05fdc812012-12-17 13:04:30 -08007062 tANI_U8 i, j;
Jeff Johnson295189b2012-06-20 16:38:30 -07007063 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
7064 tANI_U8 channelToScan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
7065 eHalStatus status;
7066
Jeff Johnson295189b2012-06-20 16:38:30 -07007067 pScanCmd = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7068 numChn = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08007069
7070 /* if any session is connected and the number of channels to scan is
7071 * greater than 1 then split the scan into multiple scan operations
7072 * on each individual channel else continue to perform scan on all
7073 * specified channels */
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08007074
7075 /* split scan if number of channels to scan is greater than 1 and
7076 * any one of the following:
7077 * - STA session is connected and the scan is not a P2P search
7078 * - any P2P session is connected
Srikant Kuppa866893f2012-12-27 17:28:14 -08007079 * Do not split scans if no concurrent infra connections are
7080 * active and if the scan is a BG scan triggered by LFR (OR)
7081 * any scan if LFR is in the middle of a BG scan. Splitting
7082 * the scan is delaying the time it takes for LFR to find
7083 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08007084 */
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07007085
7086 if((csrIsStaSessionConnected(pMac) &&
7087 !csrIsP2pSessionConnected(pMac)))
7088 {
7089 nNumChanCombinedConc = pMac->roam.configParam.nNumStaChanCombinedConc;
7090 }
7091 else if(csrIsP2pSessionConnected(pMac))
7092 {
7093 nNumChanCombinedConc = pMac->roam.configParam.nNumP2PChanCombinedConc;
7094 }
7095
7096 if ( (numChn > nNumChanCombinedConc) &&
Srikant Kuppa866893f2012-12-27 17:28:14 -08007097 ((csrIsStaSessionConnected(pMac) &&
7098#ifdef FEATURE_WLAN_LFR
7099 (csrIsConcurrentInfraConnected(pMac) ||
7100 ((pScanCmd->u.scanCmd.reason != eCsrScanBgScan) &&
7101 (pMac->roam.neighborRoamInfo.neighborRoamState !=
7102 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
7103#endif
7104 (pScanCmd->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08007105 (csrIsP2pSessionConnected(pMac))))
Jeff Johnson295189b2012-06-20 16:38:30 -07007106 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307107 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007108
7109 pSendScanCmd = csrGetCommandBuffer(pMac); //optimize this to use 2 command buffer only
7110 if (!pSendScanCmd)
7111 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007112 smsLog( pMac, LOGE, FL(" Failed to get Queue command buffer") );
Jeff Johnson295189b2012-06-20 16:38:30 -07007113 csrLLUnlock(&pMac->scan.scanCmdPendingList);
7114 return;
7115 }
7116 pSendScanCmd->command = pScanCmd->command;
7117 pSendScanCmd->sessionId = pScanCmd->sessionId;
7118 pSendScanCmd->u.scanCmd.callback = NULL;
7119 pSendScanCmd->u.scanCmd.pContext = pScanCmd->u.scanCmd.pContext;
7120 pSendScanCmd->u.scanCmd.reason = pScanCmd->u.scanCmd.reason;
7121 pSendScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
7122
Madan Mohan Koyyalamudiaf2a8b92012-10-09 14:58:07 -07007123 /* First copy all the parameters to local variable of scan request */
7124 csrScanCopyRequest(pMac, &scanReq, &pScanCmd->u.scanCmd.u.scanRequest);
7125
7126 /* Now modify the elements of local var scan request required to be modified for split scan */
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08007127 if(scanReq.ChannelInfo.ChannelList != NULL)
7128 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307129 vos_mem_free(scanReq.ChannelInfo.ChannelList);
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08007130 scanReq.ChannelInfo.ChannelList = NULL;
7131 }
7132
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07007133 pChnInfo->numOfChannels = nNumChanCombinedConc;
Kiet Lam64c1b492013-07-12 13:56:44 +05307134 vos_mem_copy(&channelToScan[0],
7135 &pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[0],
7136 pChnInfo->numOfChannels * sizeof(tANI_U8));//just send one channel
Jeff Johnson295189b2012-06-20 16:38:30 -07007137 pChnInfo->ChannelList = &channelToScan[0];
7138
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07007139 for (i = 0, j = nNumChanCombinedConc; i < (numChn-nNumChanCombinedConc); i++, j++)
Jeff Johnson295189b2012-06-20 16:38:30 -07007140 {
7141 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] =
Vinay Malekal05fdc812012-12-17 13:04:30 -08007142 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[j]; //Move all the channels one step
Jeff Johnson295189b2012-06-20 16:38:30 -07007143 }
7144
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07007145 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = numChn - nNumChanCombinedConc; //reduce outstanding # of channels to be scanned
Jeff Johnson295189b2012-06-20 16:38:30 -07007146
7147 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
c_hpothudbefd3e2014-04-28 15:59:47 +05307148
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -07007149 //Use concurrency values for min/maxChnTime.
7150 //We know csrIsAnySessionConnected(pMac) returns TRUE here
7151 csrSetDefaultScanTiming(pMac, scanReq.scanType, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07007152
7153 status = csrScanCopyRequest(pMac, &pSendScanCmd->u.scanCmd.u.scanRequest, &scanReq);
7154 if(!HAL_STATUS_SUCCESS(status))
7155 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007156 smsLog( pMac, LOGE, FL(" Failed to get copy csrScanRequest = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07007157 csrLLUnlock(&pMac->scan.scanCmdPendingList);
7158 return;
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08007159 }
7160 /* Clean the local scan variable */
7161 scanReq.ChannelInfo.ChannelList = NULL;
7162 scanReq.ChannelInfo.numOfChannels = 0;
7163 csrScanFreeRequest(pMac, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07007164 }
7165 else
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08007166 {
7167 /* no active connected session present or numChn == 1
7168 * scan all remaining channels */
Jeff Johnson295189b2012-06-20 16:38:30 -07007169 pSendScanCmd = pScanCmd;
7170 //remove this command from pending list
7171 if (csrLLRemoveHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) == NULL)
7172 { //In case between PeekHead and here, the entry got removed by another thread.
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007173 smsLog( pMac, LOGE, FL(" Failed to remove entry from scanCmdPendingList"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007174 }
7175
7176 }
7177 csrQueueSmeCommand(pMac, pSendScanCmd, eANI_BOOLEAN_FALSE);
7178
7179 }
7180
Jeff Johnson295189b2012-06-20 16:38:30 -07007181 csrLLUnlock(&pMac->scan.scanCmdPendingList);
7182
7183}
7184#endif
7185
Jeff Johnson295189b2012-06-20 16:38:30 -07007186//This function returns the maximum time a BSS is allowed in the scan result.
7187//The time varies base on connection and power saving factors.
7188//Not connected, No PS
7189//Not connected, with PS
7190//Connected w/o traffic, No PS
7191//Connected w/o traffic, with PS
7192//Connected w/ traffic, no PS -- Not supported
7193//Connected w/ traffic, with PS -- Not supported
7194//the return unit is in seconds.
7195tANI_U32 csrScanGetAgeOutTime(tpAniSirGlobal pMac)
7196{
7197 tANI_U32 nRet;
7198
7199 if(pMac->scan.nAgingCountDown)
7200 {
7201 //Calculate what should be the timeout value for this
7202 nRet = pMac->scan.nLastAgeTimeOut * pMac->scan.nAgingCountDown;
7203 pMac->scan.nAgingCountDown--;
7204 }
7205 else
7206 {
7207 if( csrIsAllSessionDisconnected( pMac ) )
7208 {
7209 if(pmcIsPowerSaveEnabled(pMac, ePMC_IDLE_MODE_POWER_SAVE))
7210 {
7211 nRet = pMac->roam.configParam.scanAgeTimeNCPS;
7212 }
7213 else
7214 {
7215 nRet = pMac->roam.configParam.scanAgeTimeNCNPS;
7216 }
7217 }
7218 else
7219 {
7220 if(pmcIsPowerSaveEnabled(pMac, ePMC_BEACON_MODE_POWER_SAVE))
7221 {
7222 nRet = pMac->roam.configParam.scanAgeTimeCPS;
7223 }
7224 else
7225 {
7226 nRet = pMac->roam.configParam.scanAgeTimeCNPS;
7227 }
7228 }
7229 //If state-change causing aging time out change, we want to delay it somewhat to avoid
7230 //unnecessary removal of BSS. This is mostly due to transition from connect to disconnect.
7231 if(pMac->scan.nLastAgeTimeOut > nRet)
7232 {
7233 if(nRet)
7234 {
7235 pMac->scan.nAgingCountDown = (pMac->scan.nLastAgeTimeOut / nRet);
7236 }
7237 pMac->scan.nLastAgeTimeOut = nRet;
7238 nRet *= pMac->scan.nAgingCountDown;
7239 }
7240 else
7241 {
7242 pMac->scan.nLastAgeTimeOut = nRet;
7243 }
7244 }
7245
7246 return (nRet);
7247}
7248
Deepthi Gowri6a08e312016-03-31 19:10:14 +05307249static void csrPurgeScanResultByAge(void *pv)
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08007250{
7251 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
7252 tListElem *pEntry, *tmpEntry;
7253 tCsrScanResult *pResult;
Deepthi Gowri4480a3f2016-05-18 19:30:17 +05307254 v_TIME_t ageOutTime =
7255 (v_TIME_t)(pMac->scan.scanResultCfgAgingTime * SYSTEM_TIME_SEC_TO_MSEC);
7256 v_TIME_t curTime = vos_timer_get_system_time();
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08007257
7258 csrLLLock(&pMac->scan.scanResultList);
7259 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
Deepthi Gowri6a08e312016-03-31 19:10:14 +05307260 smsLog(pMac, LOG1, FL("Ageout time=%lu"),ageOutTime);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08007261 while( pEntry )
7262 {
7263 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
7264 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
7265 if((curTime - pResult->Result.BssDescriptor.nReceivedTime) > ageOutTime)
7266 {
Deepthi Gowri50e2fa52016-03-17 15:30:53 +05307267 smsLog(pMac, LOG1, FL("age out due to time out for BSSID" MAC_ADDRESS_STR),
7268 MAC_ADDR_ARRAY(pResult->Result.BssDescriptor.bssId));
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08007269 csrScanAgeOutBss(pMac, pResult);
7270 }
7271 pEntry = tmpEntry;
7272 }
7273 csrLLUnlock(&pMac->scan.scanResultList);
7274}
Jeff Johnson295189b2012-06-20 16:38:30 -07007275
7276eHalStatus csrScanStartIdleScanTimer(tpAniSirGlobal pMac, tANI_U32 interval)
7277{
7278 eHalStatus status;
7279
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007280 smsLog(pMac, LOG1, " csrScanStartIdleScanTimer");
Jeff Johnson295189b2012-06-20 16:38:30 -07007281 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) && interval)
7282 {
7283 pMac->scan.nIdleScanTimeGap += interval;
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05307284 vos_timer_stop(&pMac->scan.hTimerIdleScan);
7285 status = vos_timer_start(&pMac->scan.hTimerIdleScan, interval/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07007286 if( !HAL_STATUS_SUCCESS(status) )
7287 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007288 smsLog(pMac, LOGE, " Fail to start Idle scan timer. status = %d interval = %d", status, interval);
Jeff Johnson295189b2012-06-20 16:38:30 -07007289 //This should not happen but set the flag to restart when ready
7290 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7291 }
7292 }
7293 else
7294 {
7295 if( pMac->scan.fScanEnable && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) )
7296 {
7297 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7298 }
7299 status = eHAL_STATUS_FAILURE;
7300 }
7301
7302 return (status);
7303}
7304
7305
7306eHalStatus csrScanStopIdleScanTimer(tpAniSirGlobal pMac)
7307{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05307308 return (vos_timer_stop(&pMac->scan.hTimerIdleScan));
Jeff Johnson295189b2012-06-20 16:38:30 -07007309}
7310
7311
7312//Stop CSR from asking for IMPS, This function doesn't disable IMPS from CSR
7313void csrScanSuspendIMPS( tpAniSirGlobal pMac )
7314{
7315 csrScanCancelIdleScan(pMac);
7316}
7317
7318
7319//Start CSR from asking for IMPS. This function doesn't trigger CSR to request entering IMPS
7320//because IMPS maybe disabled.
7321void csrScanResumeIMPS( tpAniSirGlobal pMac )
7322{
7323 csrScanStartIdleScan( pMac );
7324}
7325
7326
7327void csrScanIMPSCallback(void *callbackContext, eHalStatus status)
7328{
7329 tpAniSirGlobal pMac = PMAC_STRUCT( callbackContext );
7330
7331 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
7332 {
7333 if(pMac->roam.configParam.IsIdleScanEnabled)
7334 {
7335 if(HAL_STATUS_SUCCESS(status))
7336 {
7337 if(csrIsAllSessionDisconnected(pMac) && !csrIsRoamCommandWaiting(pMac))
7338 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007339 smsLog(pMac, LOGW, FL("starts idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007340 csrScanAllChannels(pMac, eCSR_SCAN_IDLE_MODE_SCAN);
7341 }
7342 else
7343 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007344 smsLog(pMac, LOGW, FL("cannot start idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007345 //even though we are in timer handle, calling stop timer will make sure the timer
7346 //doesn't get to restart.
7347 csrScanStopIdleScanTimer(pMac);
7348 }
7349 }
7350 else
7351 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007352 smsLog(pMac, LOGE, FL("sees not success status (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07007353 }
7354 }
7355 else
7356 {//we might need another flag to check if CSR needs to request imps at all
7357
7358 tANI_U32 nTime = 0;
7359
7360 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_FALSE;
7361 if(!HAL_STATUS_SUCCESS(csrScanTriggerIdleScan(pMac, &nTime)))
7362 {
7363 csrScanStartIdleScanTimer(pMac, nTime);
7364 }
7365 }
7366 }
7367}
7368
7369
Rashmi Ramanna68b309c2014-05-20 11:52:22 +05307370//Param: pTimeInterval -- Caller allocated memory in return, if failed, to specify the nxt time interval for
Jeff Johnson295189b2012-06-20 16:38:30 -07007371//idle scan timer interval
7372//Return: Not success -- meaning it cannot start IMPS, caller needs to start a timer for idle scan
7373eHalStatus csrScanTriggerIdleScan(tpAniSirGlobal pMac, tANI_U32 *pTimeInterval)
7374{
7375 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
7376
7377 //Do not trigger IMPS in case of concurrency
Agarwal Ashish5974ed32014-06-16 16:59:54 +05307378 if (vos_concurrent_open_sessions_running() &&
7379 csrIsAnySessionInConnectState(pMac))
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007380 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007381 smsLog( pMac, LOG1, FL("Cannot request IMPS because Concurrent Sessions Running") );
Jeff Johnson295189b2012-06-20 16:38:30 -07007382 return (status);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007383 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007384
7385 if(pTimeInterval)
7386 {
7387 *pTimeInterval = 0;
7388 }
7389
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007390 smsLog(pMac, LOG3, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007391 if( smeCommandPending( pMac ) )
7392 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007393 smsLog( pMac, LOG1, FL(" Cannot request IMPS because command pending") );
Jeff Johnson295189b2012-06-20 16:38:30 -07007394 //Not to enter IMPS because more work to do
7395 if(pTimeInterval)
7396 {
7397 *pTimeInterval = 0;
7398 }
7399 //restart when ready
7400 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7401
7402 return (status);
7403 }
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07007404 if (IsPmcImpsReqFailed (pMac))
7405 {
7406 if(pTimeInterval)
7407 {
7408 *pTimeInterval = 1000000; //usec
7409 }
7410 //restart when ready
7411 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07007412
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07007413 return status;
7414 }
Rashmi Ramanna68b309c2014-05-20 11:52:22 +05307415
7416 if ( !pMac->deferImps && pMac->fDeferIMPSTime )
7417 {
7418 smsLog( pMac, LOG1, FL("Defer IMPS for %dms as command processed"),
7419 pMac->fDeferIMPSTime);
Girish Gowli4f3775a2014-05-30 17:17:08 +05307420 if(pTimeInterval)
7421 {
7422 *pTimeInterval = pMac->fDeferIMPSTime * 1000; //usec
7423 }
Rashmi Ramanna68b309c2014-05-20 11:52:22 +05307424 pMac->deferImps = eANI_BOOLEAN_TRUE;
7425 return status;
7426 }
7427
Jeff Johnson295189b2012-06-20 16:38:30 -07007428 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
7429 /*&& pMac->roam.configParam.impsSleepTime*/)
7430 {
7431 //Stop get result timer because idle scan gets scan result out of PE
7432 csrScanStopGetResultTimer(pMac);
7433 if(pTimeInterval)
7434 {
7435 *pTimeInterval = pMac->roam.configParam.impsSleepTime;
7436 }
7437 //pmcRequestImps take a period in millisecond unit.
7438 status = pmcRequestImps(pMac, pMac->roam.configParam.impsSleepTime / PAL_TIMER_TO_MS_UNIT, csrScanIMPSCallback, pMac);
7439 if(!HAL_STATUS_SUCCESS(status))
7440 {
7441 if(eHAL_STATUS_PMC_ALREADY_IN_IMPS != status)
7442 {
7443 //Do restart the timer if CSR thinks it cannot do IMPS
7444 if( !csrCheckPSReady( pMac ) )
7445 {
7446 if(pTimeInterval)
7447 {
7448 *pTimeInterval = 0;
7449 }
7450 //Set the restart flag to true because that idle scan
7451 //can be restarted even though the timer will not be running
7452 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7453 }
7454 else
7455 {
7456 //For not now, we do a quicker retry
7457 if(pTimeInterval)
7458 {
7459 *pTimeInterval = CSR_IDLE_SCAN_WAIT_TIME;
7460 }
7461 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007462 smsLog(pMac, LOGW, FL("call pmcRequestImps and it returns status code (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07007463 }
7464 else
7465 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007466 smsLog(pMac, LOGW, FL("already in IMPS"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007467 //Since CSR is the only module to request for IMPS. If it is already in IMPS, CSR assumes
7468 //the callback will be called in the future. Should not happen though.
7469 status = eHAL_STATUS_SUCCESS;
7470 pMac->scan.nIdleScanTimeGap = 0;
7471 }
7472 }
7473 else
7474 {
7475 //requested so let's reset the value
7476 pMac->scan.nIdleScanTimeGap = 0;
7477 }
7478 }
7479
7480 return (status);
7481}
7482
7483
7484eHalStatus csrScanStartIdleScan(tpAniSirGlobal pMac)
7485{
7486 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
7487 tANI_U32 nTime = 0;
7488
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007489 smsLog(pMac, LOGW, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007490 if(pMac->roam.configParam.IsIdleScanEnabled)
7491 {
7492 //stop bg scan first
7493 csrScanBGScanAbort(pMac);
7494 //Stop get result timer because idle scan gets scan result out of PE
7495 csrScanStopGetResultTimer(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07007496 }
7497 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_FALSE;
7498 status = csrScanTriggerIdleScan(pMac, &nTime);
7499 if(!HAL_STATUS_SUCCESS(status))
7500 {
7501 csrScanStartIdleScanTimer(pMac, nTime);
7502 }
7503
7504 return (status);
7505}
7506
7507
7508void csrScanCancelIdleScan(tpAniSirGlobal pMac)
7509{
7510 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
7511 {
Agarwal Ashish5974ed32014-06-16 16:59:54 +05307512 if (vos_concurrent_open_sessions_running()) {
Jeff Johnson295189b2012-06-20 16:38:30 -07007513 return;
7514 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007515 smsLog(pMac, LOG1, " csrScanCancelIdleScan");
Jeff Johnson295189b2012-06-20 16:38:30 -07007516 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_TRUE;
7517 //Set the restart flag in case later on it is uncancelled
7518 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7519 csrScanStopIdleScanTimer(pMac);
7520 csrScanRemoveNotRoamingScanCommand(pMac);
7521 }
7522}
7523
7524
7525void csrScanIdleScanTimerHandler(void *pv)
7526{
7527 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
7528 eHalStatus status;
7529 tANI_U32 nTime = 0;
7530
7531 smsLog(pMac, LOGW, " csrScanIdleScanTimerHandler called ");
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07007532 pmcResetImpsFailStatus (pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07007533 status = csrScanTriggerIdleScan(pMac, &nTime);
7534 if(!HAL_STATUS_SUCCESS(status) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan))
7535 {
7536 //Check whether it is time to actually do an idle scan
7537 if(pMac->scan.nIdleScanTimeGap >= pMac->roam.configParam.impsSleepTime)
7538 {
7539 pMac->scan.nIdleScanTimeGap = 0;
7540 csrScanIMPSCallback(pMac, eHAL_STATUS_SUCCESS);
7541 }
7542 else
7543 {
7544 csrScanStartIdleScanTimer(pMac, nTime);
7545 }
7546 }
Rashmi Ramanna68b309c2014-05-20 11:52:22 +05307547 if(pMac->deferImps)
7548 {
7549 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7550 pMac->deferImps = eANI_BOOLEAN_FALSE;
7551 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007552}
7553
7554
7555
7556
7557tANI_BOOLEAN csrScanRemoveNotRoamingScanCommand(tpAniSirGlobal pMac)
7558{
7559 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
7560 tListElem *pEntry, *pEntryTmp;
7561 tSmeCmd *pCommand;
7562 tDblLinkList localList;
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307563 tDblLinkList *pCmdList;
Jeff Johnson295189b2012-06-20 16:38:30 -07007564
7565 vos_mem_zero(&localList, sizeof(tDblLinkList));
7566 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
7567 {
7568 smsLog(pMac, LOGE, FL(" failed to open list"));
7569 return fRet;
7570 }
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307571 if (!pMac->fScanOffload)
7572 pCmdList = &pMac->sme.smeCmdPendingList;
7573 else
7574 pCmdList = &pMac->sme.smeScanCmdPendingList;
Jeff Johnson295189b2012-06-20 16:38:30 -07007575
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307576 csrLLLock(pCmdList);
7577 pEntry = csrLLPeekHead(pCmdList, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007578 while(pEntry)
7579 {
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307580 pEntryTmp = csrLLNext(pCmdList, pEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007581 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7582 if( eSmeCommandScan == pCommand->command )
7583 {
7584 switch( pCommand->u.scanCmd.reason )
7585 {
7586 case eCsrScanIdleScan:
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307587 if( csrLLRemoveEntry(pCmdList, pEntry, LL_ACCESS_NOLOCK) )
Jeff Johnson295189b2012-06-20 16:38:30 -07007588 {
7589 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
7590 }
7591 fRet = eANI_BOOLEAN_TRUE;
7592 break;
7593
7594 default:
7595 break;
7596 } //switch
7597 }
7598 pEntry = pEntryTmp;
7599 }
7600
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307601 csrLLUnlock(pCmdList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007602
7603 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
7604 {
7605 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7606 csrReleaseCommandScan( pMac, pCommand );
7607 }
7608
7609 csrLLClose(&localList);
7610
7611 return (fRet);
7612}
7613
7614
7615tANI_BOOLEAN csrScanRemoveFreshScanCommand(tpAniSirGlobal pMac, tANI_U8 sessionId)
7616{
7617 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
7618 tListElem *pEntry, *pEntryTmp;
7619 tSmeCmd *pCommand;
7620 tDblLinkList localList;
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307621 tDblLinkList *pCmdList;
Jeff Johnson295189b2012-06-20 16:38:30 -07007622
7623 vos_mem_zero(&localList, sizeof(tDblLinkList));
7624 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
7625 {
7626 smsLog(pMac, LOGE, FL(" failed to open list"));
7627 return fRet;
7628 }
7629
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307630 if (!pMac->fScanOffload)
7631 pCmdList = &pMac->sme.smeCmdPendingList;
7632 else
7633 pCmdList = &pMac->sme.smeScanCmdPendingList;
7634
7635 csrLLLock(pCmdList);
7636 pEntry = csrLLPeekHead(pCmdList, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007637 while(pEntry)
7638 {
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307639 pEntryTmp = csrLLNext(pCmdList, pEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007640 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7641 if( (eSmeCommandScan == pCommand->command) && (sessionId == pCommand->sessionId) )
7642 {
7643 switch(pCommand->u.scanCmd.reason)
7644 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07007645#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
7646 case eCsrScanGetLfrResult:
7647#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07007648 case eCsrScanGetResult:
7649 case eCsrScanSetBGScanParam:
7650 case eCsrScanBGScanAbort:
7651 case eCsrScanBGScanEnable:
7652 case eCsrScanGetScanChnInfo:
7653 break;
7654 default:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007655 smsLog (pMac, LOGW, "%s: -------- abort scan command reason = %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007656 __func__, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07007657 //The rest are fresh scan requests
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307658 if( csrLLRemoveEntry(pCmdList, pEntry, LL_ACCESS_NOLOCK) )
Jeff Johnson295189b2012-06-20 16:38:30 -07007659 {
7660 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
7661 }
7662 fRet = eANI_BOOLEAN_TRUE;
7663 break;
7664 }
7665 }
7666 pEntry = pEntryTmp;
7667 }
7668
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307669 csrLLUnlock(pCmdList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007670
7671 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
7672 {
7673 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7674 if (pCommand->u.scanCmd.callback)
7675 {
7676 /* User scan request is pending,
7677 * send response with status eCSR_SCAN_ABORT*/
7678 pCommand->u.scanCmd.callback(pMac,
7679 pCommand->u.scanCmd.pContext,
7680 pCommand->u.scanCmd.scanID,
7681 eCSR_SCAN_ABORT);
7682 }
7683 csrReleaseCommandScan( pMac, pCommand );
7684 }
7685 csrLLClose(&localList);
7686
7687 return (fRet);
7688}
7689
7690
7691void csrReleaseScanCommand(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
7692{
7693 eCsrScanReason reason = pCommand->u.scanCmd.reason;
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307694 tANI_BOOLEAN status;
7695
7696 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07007697 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307698 tANI_U32 i;
7699 for(i = 0; i < CSR_ROAM_SESSION_MAX; i++)
Abhishek Singhf52182c2016-08-24 11:15:23 +05307700 csrRoamStateChange(pMac,
7701 pMac->roam.prev_state[i], i);
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307702 }
7703 else
7704 {
7705 csrRoamStateChange(pMac,
Abhishek Singhf52182c2016-08-24 11:15:23 +05307706 pMac->roam.prev_state[pCommand->sessionId],
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307707 pCommand->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07007708 }
7709
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307710 csrScanCallCallback(pMac, pCommand, scanStatus);
Jeff Johnson295189b2012-06-20 16:38:30 -07007711
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007712 smsLog(pMac, LOG3, " Remove Scan command reason = %d", reason);
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307713 if (pMac->fScanOffload)
7714 {
7715 status = csrLLRemoveEntry(&pMac->sme.smeScanCmdActiveList,
7716 &pCommand->Link, LL_ACCESS_LOCK);
7717 }
7718 else
7719 {
7720 status = csrLLRemoveEntry(&pMac->sme.smeCmdActiveList,
7721 &pCommand->Link, LL_ACCESS_LOCK);
7722 }
7723
7724 if(status)
Jeff Johnson295189b2012-06-20 16:38:30 -07007725 {
7726 csrReleaseCommandScan( pMac, pCommand );
7727 }
7728 else
7729 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307730 smsLog(pMac, LOGE,
7731 " ********csrReleaseScanCommand cannot release command reason %d",
7732 pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07007733 }
7734}
7735
7736
7737eHalStatus csrScanGetPMKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
7738 tPmkidCandidateInfo *pPmkidList, tANI_U32 *pNumItems )
7739{
7740 eHalStatus status = eHAL_STATUS_SUCCESS;
7741 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
7742
Jeff Johnson32d95a32012-09-10 13:15:23 -07007743 if(!pSession)
7744 {
7745 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
7746 return eHAL_STATUS_FAILURE;
7747 }
7748
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007749 smsLog(pMac, LOGW, " pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07007750 csrResetPMKIDCandidateList(pMac, sessionId);
7751 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
7752 {
7753 tCsrScanResultFilter *pScanFilter;
7754 tCsrScanResultInfo *pScanResult;
7755 tScanResultHandle hBSSList;
7756 tANI_U32 nItems = *pNumItems;
7757
7758 *pNumItems = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05307759 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
7760 if ( NULL == pScanFilter )
7761 status = eHAL_STATUS_FAILURE;
7762 else
Jeff Johnson295189b2012-06-20 16:38:30 -07007763 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307764 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007765 //Here is the profile we need to connect to
7766 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
7767 if(HAL_STATUS_SUCCESS(status))
7768 {
7769 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
7770 if(HAL_STATUS_SUCCESS(status))
7771 {
7772 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumPmkidCandidate < nItems))
7773 {
7774 //NumPmkidCandidate adds up here
7775 csrProcessBSSDescForPMKIDList(pMac, &pScanResult->BssDescriptor,
7776 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
7777 }
7778 if(pSession->NumPmkidCandidate)
7779 {
7780 *pNumItems = pSession->NumPmkidCandidate;
Kiet Lam64c1b492013-07-12 13:56:44 +05307781 vos_mem_copy(pPmkidList, pSession->PmkidCandidateInfo,
7782 pSession->NumPmkidCandidate * sizeof(tPmkidCandidateInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07007783 }
7784 csrScanResultPurge(pMac, hBSSList);
7785 }//Have scan result
7786 csrFreeScanFilter(pMac, pScanFilter);
7787 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307788 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07007789 }
7790 }
7791
7792 return (status);
7793}
7794
7795
7796
7797#ifdef FEATURE_WLAN_WAPI
7798eHalStatus csrScanGetBKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
7799 tBkidCandidateInfo *pBkidList, tANI_U32 *pNumItems )
7800{
7801 eHalStatus status = eHAL_STATUS_SUCCESS;
7802 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
7803
Jeff Johnson32d95a32012-09-10 13:15:23 -07007804 if(!pSession)
7805 {
7806 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
7807 return eHAL_STATUS_FAILURE;
7808 }
7809
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007810 smsLog(pMac, LOGW, " pMac->scan.NumBkidCandidate = %d", pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07007811 csrResetBKIDCandidateList(pMac, sessionId);
7812 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
7813 {
7814 tCsrScanResultFilter *pScanFilter;
7815 tCsrScanResultInfo *pScanResult;
7816 tScanResultHandle hBSSList;
7817 tANI_U32 nItems = *pNumItems;
7818 *pNumItems = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05307819 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
7820 if ( NULL == pScanFilter )
7821 status = eHAL_STATUS_FAILURE;
7822 else
Jeff Johnson295189b2012-06-20 16:38:30 -07007823 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307824 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007825 //Here is the profile we need to connect to
7826 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
7827 if(HAL_STATUS_SUCCESS(status))
7828 {
7829 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
7830 if(HAL_STATUS_SUCCESS(status))
7831 {
7832 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumBkidCandidate < nItems))
7833 {
7834 //pMac->scan.NumBkidCandidate adds up here
7835 csrProcessBSSDescForBKIDList(pMac, &pScanResult->BssDescriptor,
7836 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
7837
7838 }
7839 if(pSession->NumBkidCandidate)
7840 {
7841 *pNumItems = pSession->NumBkidCandidate;
Kiet Lam64c1b492013-07-12 13:56:44 +05307842 vos_mem_copy(pBkidList, pSession->BkidCandidateInfo, pSession->NumBkidCandidate * sizeof(tBkidCandidateInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07007843 }
7844 csrScanResultPurge(pMac, hBSSList);
7845 }//Have scan result
7846 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307847 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07007848 }
7849 }
7850
7851 return (status);
7852}
7853#endif /* FEATURE_WLAN_WAPI */
7854
Selvaraj, Sridhar32417ed2016-06-22 15:19:12 +05307855/**
7856 * csr_scan_request_set_chan_time() - Populate max and min
7857 * channel time in Scan request
7858 * @pMac - pointer to mac context
7859 * @pScanCmd - pointer to the Scan command
7860 *
7861 * Return - None
7862 */
7863#ifndef QCA_WIFI_ISOC
7864static void csr_scan_request_set_chan_time(tpAniSirGlobal pMac,
7865 tSmeCmd *pScanCmd)
7866{
7867 if (pMac->roam.neighborRoamInfo.handoffReqInfo.src
7868 == FASTREASSOC) {
7869 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime
7870 = MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL_FASTREASSOC;
7871 pScanCmd->u.scanCmd.u.scanRequest.minChnTime
7872 = MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL_FASTREASSOC;
7873 pMac->roam.neighborRoamInfo.handoffReqInfo.src = 0;
7874 } else {
7875 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime
7876 = MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7877 pScanCmd->u.scanCmd.u.scanRequest.minChnTime
7878 = MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7879 }
7880}
7881#else
7882static void csr_scan_request_set_chan_time(tpAniSirGlobal pMac,
7883 tSmeCmd *pScanCmd)
7884{
7885 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime
7886 = MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7887 pScanCmd->u.scanCmd.u.scanRequest.minChnTime
7888 = MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7889}
7890#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07007891
7892//This function is usually used for BSSs that suppresses SSID so the profile
7893//shall have one and only one SSID
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007894eHalStatus csrScanForSSID(tpAniSirGlobal pMac, tANI_U32 sessionId, tCsrRoamProfile *pProfile, tANI_U32 roamId, tANI_BOOLEAN notify)
Jeff Johnson295189b2012-06-20 16:38:30 -07007895{
7896 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
7897 tSmeCmd *pScanCmd = NULL;
7898 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
7899 tANI_U8 index = 0;
7900 tANI_U32 numSsid = pProfile->SSIDs.numOfSSIDs;
7901
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007902 smsLog(pMac, LOG2, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007903 //For WDS, we use the index 0. There must be at least one in there
7904 if( CSR_IS_WDS_STA( pProfile ) && numSsid )
7905 {
7906 numSsid = 1;
7907 }
7908 if(pMac->scan.fScanEnable && ( numSsid == 1 ) )
7909 {
7910 do
7911 {
7912 pScanCmd = csrGetCommandBuffer(pMac);
7913 if(!pScanCmd)
7914 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007915 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007916 break;
7917 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307918 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
7919 pScanCmd->u.scanCmd.pToRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
7920 if ( NULL == pScanCmd->u.scanCmd.pToRoamProfile )
krunal soni587bf012014-02-04 12:35:11 -08007921 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307922 status = eHAL_STATUS_FAILURE;
krunal soni587bf012014-02-04 12:35:11 -08007923 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307924 else
krunal soni587bf012014-02-04 12:35:11 -08007925 {
7926 status = csrRoamCopyProfile(pMac, pScanCmd->u.scanCmd.pToRoamProfile, pProfile);
7927 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007928 if(!HAL_STATUS_SUCCESS(status))
7929 break;
7930 pScanCmd->u.scanCmd.roamId = roamId;
7931 pScanCmd->command = eSmeCommandScan;
Jeff Johnsone7245742012-09-05 17:12:55 -07007932 pScanCmd->sessionId = (tANI_U8)sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07007933 pScanCmd->u.scanCmd.callback = NULL;
7934 pScanCmd->u.scanCmd.pContext = NULL;
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007935 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 -07007936 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Kiet Lam64c1b492013-07-12 13:56:44 +05307937 vos_mem_set(&pScanCmd->u.scanCmd.u.scanRequest, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007938 pScanCmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Jeff Johnson295189b2012-06-20 16:38:30 -07007939 pScanCmd->u.scanCmd.u.scanRequest.BSSType = pProfile->BSSType;
Jeff Johnsone7245742012-09-05 17:12:55 -07007940 // To avoid 11b rate in probe request Set p2pSearch flag as 1 for P2P Client Mode
7941 if(VOS_P2P_CLIENT_MODE == pProfile->csrPersona)
7942 {
7943 pScanCmd->u.scanCmd.u.scanRequest.p2pSearch = 1;
7944 }
Agarwal Ashish4f616132013-12-30 23:32:50 +05307945 if(pProfile->nAddIEScanLength)
Jeff Johnsone7245742012-09-05 17:12:55 -07007946 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307947 pScanCmd->u.scanCmd.u.scanRequest.pIEField = vos_mem_malloc(
7948 pProfile->nAddIEScanLength);
7949 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.pIEField )
7950 status = eHAL_STATUS_FAILURE;
7951 else
7952 status = eHAL_STATUS_SUCCESS;
7953 vos_mem_set(pScanCmd->u.scanCmd.u.scanRequest.pIEField,
7954 pProfile->nAddIEScanLength, 0);
7955 if (HAL_STATUS_SUCCESS(status))
Jeff Johnsone7245742012-09-05 17:12:55 -07007956 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307957 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.pIEField,
Agarwal Ashish4f616132013-12-30 23:32:50 +05307958 pProfile->addIEScan, pProfile->nAddIEScanLength);
Jeff Johnsone7245742012-09-05 17:12:55 -07007959 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = pProfile->nAddIEScanLength;
7960 }
7961 else
7962 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007963 smsLog(pMac, LOGE, "No memory for scanning IE fields");
Jeff Johnsone7245742012-09-05 17:12:55 -07007964 }
7965 } //Allocate memory for IE field
7966 else
7967 {
7968 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = 0;
7969 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07007970 /* For one channel be good enpugh time to receive beacon atleast */
7971 if( 1 == pProfile->ChannelInfo.numOfChannels )
7972 {
Selvaraj, Sridhar32417ed2016-06-22 15:19:12 +05307973 csr_scan_request_set_chan_time(pMac, pScanCmd);
7974 } else {
Kiet Lam64c1b492013-07-12 13:56:44 +05307975 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime =
7976 pMac->roam.configParam.nActiveMaxChnTime;
7977 pScanCmd->u.scanCmd.u.scanRequest.minChnTime =
7978 pMac->roam.configParam.nActiveMinChnTime;
Jeff Johnson32d95a32012-09-10 13:15:23 -07007979 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307980 pScanCmd->u.scanCmd.u.scanRequest.maxChnTimeBtc =
7981 pMac->roam.configParam.nActiveMaxChnTimeBtc;
7982 pScanCmd->u.scanCmd.u.scanRequest.minChnTimeBtc =
7983 pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07007984 if(pProfile->BSSIDs.numOfBSSIDs == 1)
7985 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307986 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.bssid,
7987 pProfile->BSSIDs.bssid, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07007988 }
7989 else
7990 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307991 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.bssid, bAddr, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07007992 }
7993 if(pProfile->ChannelInfo.numOfChannels)
7994 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307995 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(
7996 sizeof(*pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
7997 * pProfile->ChannelInfo.numOfChannels);
7998 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
7999 status = eHAL_STATUS_FAILURE;
8000 else
8001 status = eHAL_STATUS_SUCCESS;
8002 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
8003 if(HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07008004 {
8005 csrRoamIsChannelValid(pMac, pProfile->ChannelInfo.ChannelList[0]);
8006 for(index = 0; index < pProfile->ChannelInfo.numOfChannels; index++)
8007 {
8008 if(csrRoamIsValidChannel(pMac, pProfile->ChannelInfo.ChannelList[index]))
8009 {
8010 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels]
8011 = pProfile->ChannelInfo.ChannelList[index];
8012 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels++;
8013 }
8014 else
8015 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008016 smsLog(pMac, LOGW, FL("process a channel (%d) that is invalid"), pProfile->ChannelInfo.ChannelList[index]);
Jeff Johnson295189b2012-06-20 16:38:30 -07008017 }
8018
8019 }
8020 }
8021 else
8022 {
8023 break;
8024 }
8025
8026 }
8027 else
8028 {
8029 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
8030 }
8031 if(pProfile->SSIDs.numOfSSIDs)
8032 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308033 pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList = vos_mem_malloc(
8034 pProfile->SSIDs.numOfSSIDs * sizeof(tCsrSSIDInfo));
8035 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList )
8036 status = eHAL_STATUS_FAILURE;
8037 else
8038 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07008039 if(!HAL_STATUS_SUCCESS(status))
8040 {
8041 break;
8042 }
8043 pScanCmd->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 1;
Kiet Lam64c1b492013-07-12 13:56:44 +05308044 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList,
8045 pProfile->SSIDs.SSIDList, sizeof(tCsrSSIDInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07008046 }
8047 //Start process the command
8048 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
8049 if( !HAL_STATUS_SUCCESS( status ) )
8050 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008051 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07008052 break;
8053 }
8054 }while(0);
8055 if(!HAL_STATUS_SUCCESS(status))
8056 {
8057 if(pScanCmd)
8058 {
8059 csrReleaseCommandScan(pMac, pScanCmd);
8060 //TODO:free the memory that is allocated in this function
8061 }
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008062 if(notify)
8063 {
Jeff Johnson295189b2012-06-20 16:38:30 -07008064 csrRoamCallCallback(pMac, sessionId, NULL, roamId, eCSR_ROAM_FAILED, eCSR_ROAM_RESULT_FAILURE);
8065 }
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008066 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008067 }//valid
8068 else
8069 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008070 smsLog(pMac, LOGE, FL("cannot scan because scanEnable (%d) or numSSID (%d) is invalid"),
Jeff Johnson295189b2012-06-20 16:38:30 -07008071 pMac->scan.fScanEnable, pProfile->SSIDs.numOfSSIDs);
8072 }
8073
8074 return (status);
8075}
8076
8077
8078//Issue a scan base on the new capability infomation
8079//This should only happen when the associated AP changes its capability.
8080//After this scan is done, CSR reroams base on the new scan results
8081eHalStatus csrScanForCapabilityChange(tpAniSirGlobal pMac, tSirSmeApNewCaps *pNewCaps)
8082{
8083 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
8084 tSmeCmd *pScanCmd = NULL;
8085
8086 if(pNewCaps)
8087 {
8088 do
8089 {
8090 pScanCmd = csrGetCommandBuffer(pMac);
8091 if(!pScanCmd)
8092 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008093 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07008094 status = eHAL_STATUS_RESOURCES;
8095 break;
8096 }
Kiet Lam64c1b492013-07-12 13:56:44 +05308097 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008098 status = eHAL_STATUS_SUCCESS;
8099 pScanCmd->u.scanCmd.roamId = 0;
8100 pScanCmd->command = eSmeCommandScan;
8101 pScanCmd->u.scanCmd.callback = NULL;
8102 pScanCmd->u.scanCmd.pContext = NULL;
8103 pScanCmd->u.scanCmd.reason = eCsrScanForCapsChange;
8104 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
8105 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
8106 if( !HAL_STATUS_SUCCESS( status ) )
8107 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008108 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07008109 break;
8110 }
8111 }while(0);
8112 if(!HAL_STATUS_SUCCESS(status))
8113 {
8114 if(pScanCmd)
8115 {
8116 csrReleaseCommandScan(pMac, pScanCmd);
8117 }
8118 }
8119 }
8120
8121 return (status);
8122}
8123
8124
8125
8126void csrInitBGScanChannelList(tpAniSirGlobal pMac)
8127{
8128 tANI_U32 len = CSR_MIN(sizeof(pMac->roam.validChannelList), sizeof(pMac->scan.bgScanChannelList));
8129
Kiet Lam64c1b492013-07-12 13:56:44 +05308130 vos_mem_set(pMac->scan.bgScanChannelList, len, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008131 pMac->scan.numBGScanChannel = 0;
8132
8133 if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
8134 {
8135 pMac->roam.numValidChannels = len;
8136 pMac->scan.numBGScanChannel = (tANI_U8)CSR_MIN(len, WNI_CFG_BG_SCAN_CHANNEL_LIST_LEN);
Kiet Lam64c1b492013-07-12 13:56:44 +05308137 vos_mem_copy(pMac->scan.bgScanChannelList, pMac->roam.validChannelList,
8138 pMac->scan.numBGScanChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07008139 csrSetBGScanChannelList(pMac, pMac->scan.bgScanChannelList, pMac->scan.numBGScanChannel);
8140 }
8141}
8142
8143
8144//This function return TRUE if background scan channel list is adjusted.
8145//this function will only shrink the background scan channel list
8146tANI_BOOLEAN csrAdjustBGScanChannelList(tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels,
8147 tANI_U8 *pAdjustChannels, tANI_U8 *pNumAdjustChannels)
8148{
8149 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
8150 tANI_U8 i, j, count = *pNumAdjustChannels;
8151
8152 i = 0;
8153 while(i < count)
8154 {
8155 for(j = 0; j < NumChannels; j++)
8156 {
8157 if(pChannelList[j] == pAdjustChannels[i])
8158 break;
8159 }
8160 if(j == NumChannels)
8161 {
8162 //This channel is not in the list, remove it
8163 fRet = eANI_BOOLEAN_TRUE;
8164 count--;
8165 if(count - i)
8166 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308167 vos_mem_copy(&pAdjustChannels[i], &pAdjustChannels[i+1], count - i);
Jeff Johnson295189b2012-06-20 16:38:30 -07008168 }
8169 else
8170 {
8171 //already remove the last one. Done.
8172 break;
8173 }
8174 }
8175 else
8176 {
8177 i++;
8178 }
8179 }//while(i<count)
8180 *pNumAdjustChannels = count;
8181
8182 return (fRet);
8183}
8184
8185
8186//Get the list of the base channels to scan for passively 11d info
8187eHalStatus csrScanGetSupportedChannels( tpAniSirGlobal pMac )
8188{
8189 eHalStatus status = eHAL_STATUS_SUCCESS;
8190 int n = WNI_CFG_VALID_CHANNEL_LIST_LEN;
8191
8192 status = vos_nv_getSupportedChannels( pMac->scan.baseChannels.channelList, &n, NULL, NULL );
8193 if( HAL_STATUS_SUCCESS(status) )
8194 {
8195 pMac->scan.baseChannels.numChannels = (tANI_U8)n;
8196 }
8197 else
8198 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008199 smsLog( pMac, LOGE, FL(" failed") );
Jeff Johnson295189b2012-06-20 16:38:30 -07008200 pMac->scan.baseChannels.numChannels = 0;
8201 }
8202
8203 return ( status );
8204}
8205
8206//This function use the input pChannelList to validate the current saved channel list
8207eHalStatus csrSetBGScanChannelList( tpAniSirGlobal pMac, tANI_U8 *pAdjustChannels, tANI_U8 NumAdjustChannels)
8208{
8209 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumAdjustChannels;
8210
8211 return (ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pAdjustChannels, dataLen, NULL, eANI_BOOLEAN_FALSE));
8212}
8213
8214
8215void csrSetCfgValidChannelList( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels )
8216{
8217 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumChannels;
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05308218 eHalStatus status;
Jeff Johnson295189b2012-06-20 16:38:30 -07008219
Mihir Shete31c435d2014-02-12 13:13:34 +05308220 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
8221 "%s: dump valid channel list(NumChannels(%d))",
8222 __func__,NumChannels);
8223 VOS_TRACE_HEX_DUMP(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
8224 pChannelList, NumChannels);
8225
Jeff Johnson295189b2012-06-20 16:38:30 -07008226 ccmCfgSetStr(pMac, WNI_CFG_VALID_CHANNEL_LIST, pChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
Leela Venkata Kiran Kumar Reddy Chiralac6663f72014-02-03 21:04:58 -08008227#ifdef QCA_WIFI_2_0
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05308228 if (pMac->fScanOffload)
8229 {
8230 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
8231 "Scan offload is enabled, update default chan list");
Leela Venkata Kiran Kumar Reddy Chiralac6663f72014-02-03 21:04:58 -08008232 status = csrUpdateChannelList(pMac);
8233 }
8234#else
8235 status = csrUpdateChannelList(pMac);
8236#endif
8237
8238 if (eHAL_STATUS_SUCCESS != status)
8239 {
8240 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR,
8241 "failed to update the supported channel list");
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05308242 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008243 return;
8244}
8245
8246
8247
8248/*
8249 * The Tx power limits are saved in the cfg for future usage.
8250 */
8251void csrSaveTxPowerToCfg( tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 cfgId )
8252{
8253 tListElem *pEntry;
8254 tANI_U32 cbLen = 0, dataLen;
8255 tCsrChannelPowerInfo *pChannelSet;
8256 tANI_U32 idx;
8257 tSirMacChanInfo *pChannelPowerSet;
8258 tANI_U8 *pBuf = NULL;
8259
8260 //allocate maximum space for all channels
8261 dataLen = WNI_CFG_VALID_CHANNEL_LIST_LEN * sizeof(tSirMacChanInfo);
Kiet Lam64c1b492013-07-12 13:56:44 +05308262 if ( (pBuf = vos_mem_malloc(dataLen)) != NULL )
Jeff Johnson295189b2012-06-20 16:38:30 -07008263 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308264 vos_mem_set(pBuf, dataLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008265 pChannelPowerSet = (tSirMacChanInfo *)(pBuf);
8266
8267 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
8268 // write the tuples (startChan, numChan, txPower) for each channel found in the channel power list.
8269 while( pEntry )
8270 {
8271 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
8272 if ( 1 != pChannelSet->interChannelOffset )
8273 {
8274 // we keep the 5G channel sets internally with an interchannel offset of 4. Expand these
8275 // to the right format... (inter channel offset of 1 is the only option for the triplets
8276 // that 11d advertises.
8277 if ((cbLen + (pChannelSet->numChannels * sizeof(tSirMacChanInfo))) >= dataLen)
8278 {
8279 // expanding this entry will overflow our allocation
8280 smsLog(pMac, LOGE,
8281 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07008282 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07008283 pChannelSet->firstChannel,
8284 pChannelSet->numChannels,
8285 pChannelSet->interChannelOffset);
8286 break;
8287 }
8288
8289 for( idx = 0; idx < pChannelSet->numChannels; idx++ )
8290 {
8291 pChannelPowerSet->firstChanNum = (tSirMacChanNum)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008292 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07008293 pChannelPowerSet->numChannels = 1;
Jeff Johnson295189b2012-06-20 16:38:30 -07008294 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008295 smsLog(pMac, LOG3, " Setting Max Transmit Power %d", pChannelPowerSet->maxTxPower);
Jeff Johnson295189b2012-06-20 16:38:30 -07008296 cbLen += sizeof( tSirMacChanInfo );
8297 pChannelPowerSet++;
8298 }
8299 }
8300 else
8301 {
8302 if (cbLen >= dataLen)
8303 {
8304 // this entry will overflow our allocation
8305 smsLog(pMac, LOGE,
8306 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07008307 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07008308 pChannelSet->firstChannel,
8309 pChannelSet->numChannels,
8310 pChannelSet->interChannelOffset);
8311 break;
8312 }
8313 pChannelPowerSet->firstChanNum = pChannelSet->firstChannel;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008314 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07008315 pChannelPowerSet->numChannels = pChannelSet->numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -07008316 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008317 smsLog(pMac, LOG3, " Setting Max Transmit Power %d, nTxPower %d", pChannelPowerSet->maxTxPower,pMac->roam.configParam.nTxPowerCap );
Jeff Johnson295189b2012-06-20 16:38:30 -07008318
8319
8320 cbLen += sizeof( tSirMacChanInfo );
8321 pChannelPowerSet++;
8322 }
8323
8324 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
8325 }
8326
8327 if(cbLen)
8328 {
8329 ccmCfgSetStr(pMac, cfgId, (tANI_U8 *)pBuf, cbLen, NULL, eANI_BOOLEAN_FALSE);
8330 }
Kiet Lam64c1b492013-07-12 13:56:44 +05308331 vos_mem_free(pBuf);
Jeff Johnson295189b2012-06-20 16:38:30 -07008332 }//Allocate memory
8333}
8334
8335
8336void csrSetCfgCountryCode( tpAniSirGlobal pMac, tANI_U8 *countryCode )
8337{
8338 tANI_U8 cc[WNI_CFG_COUNTRY_CODE_LEN];
8339 ///v_REGDOMAIN_t DomainId;
8340
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008341 smsLog( pMac, LOG3, "Setting Country Code in Cfg from csrSetCfgCountryCode %s",countryCode );
Kiet Lam64c1b492013-07-12 13:56:44 +05308342 vos_mem_copy(cc, countryCode, WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07008343
8344 // don't program the bogus country codes that we created for Korea in the MAC. if we see
8345 // the bogus country codes, program the MAC with the right country code.
8346 if ( ( 'K' == countryCode[ 0 ] && '1' == countryCode[ 1 ] ) ||
8347 ( 'K' == countryCode[ 0 ] && '2' == countryCode[ 1 ] ) ||
8348 ( 'K' == countryCode[ 0 ] && '3' == countryCode[ 1 ] ) ||
8349 ( 'K' == countryCode[ 0 ] && '4' == countryCode[ 1 ] ) )
8350 {
8351 // replace the alternate Korea country codes, 'K1', 'K2', .. with 'KR' for Korea
8352 cc[ 1 ] = 'R';
8353 }
8354 ccmCfgSetStr(pMac, WNI_CFG_COUNTRY_CODE, cc, WNI_CFG_COUNTRY_CODE_LEN, NULL, eANI_BOOLEAN_FALSE);
8355
8356 //Need to let HALPHY know about the current domain so it can apply some
8357 //domain-specific settings (TX filter...)
8358 /*if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(pMac, cc, &DomainId)))
8359 {
8360 halPhySetRegDomain(pMac, DomainId);
8361 }*/
8362}
8363
8364
8365
8366eHalStatus csrGetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pBuf, tANI_U8 *pbLen)
8367{
8368 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
8369 tANI_U32 len;
8370
8371 if(pBuf && pbLen && (*pbLen >= WNI_CFG_COUNTRY_CODE_LEN))
8372 {
8373 len = *pbLen;
8374 status = ccmCfgGetStr(pMac, WNI_CFG_COUNTRY_CODE, pBuf, &len);
8375 if(HAL_STATUS_SUCCESS(status))
8376 {
8377 *pbLen = (tANI_U8)len;
8378 }
8379 }
8380
8381 return (status);
8382}
8383
8384
8385void csrSetCfgScanControlList( tpAniSirGlobal pMac, tANI_U8 *countryCode, tCsrChannel *pChannelList )
8386{
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05308387 tANI_U8 i, j, k;
Jeff Johnson295189b2012-06-20 16:38:30 -07008388 tANI_BOOLEAN found=FALSE;
8389 tANI_U8 *pControlList = NULL;
8390 tANI_U32 len = WNI_CFG_SCAN_CONTROL_LIST_LEN;
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05308391 tANI_U8 cfgActiveDFSChannels = 0;
8392 tANI_U8 *cfgActiveDFSChannelLIst = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07008393
Kiet Lam64c1b492013-07-12 13:56:44 +05308394 if ( (pControlList = vos_mem_malloc(WNI_CFG_SCAN_CONTROL_LIST_LEN)) != NULL )
Jeff Johnson295189b2012-06-20 16:38:30 -07008395 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308396 vos_mem_set((void *)pControlList, WNI_CFG_SCAN_CONTROL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008397 if(HAL_STATUS_SUCCESS(ccmCfgGetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, &len)))
8398 {
8399 for (i = 0; i < pChannelList->numChannels; i++)
8400 {
8401 for (j = 0; j < len; j += 2)
8402 {
8403 if (pControlList[j] == pChannelList->channelList[i])
8404 {
8405 found = TRUE;
8406 break;
8407 }
8408 }
8409
8410 if (found) // insert a pair(channel#, flag)
8411 {
Gopichand Nakkala392cbc12013-05-28 16:15:00 +05308412 pControlList[j+1] = csrGetScanType(pMac, pControlList[j]);
Jeff Johnson295189b2012-06-20 16:38:30 -07008413 found = FALSE; // reset the flag
Jeff Johnson295189b2012-06-20 16:38:30 -07008414
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05308415 // When DFS mode is 2, mark static channels as active
8416 if (pMac->scan.fEnableDFSChnlScan ==
8417 DFS_CHNL_SCAN_ENABLED_ACTIVE)
8418 {
8419 cfgActiveDFSChannels =
8420 pMac->roam.neighborRoamInfo.cfgParams.
8421 channelInfo.numOfChannels;
8422 cfgActiveDFSChannelLIst =
8423 pMac->roam.neighborRoamInfo.cfgParams.
8424 channelInfo.ChannelList;
8425 if (cfgActiveDFSChannelLIst)
8426 {
8427 for (k=0; k < cfgActiveDFSChannels; k++)
8428 {
8429 if(CSR_IS_CHANNEL_DFS(cfgActiveDFSChannelLIst[k])
8430 && (pControlList[j] ==
8431 cfgActiveDFSChannelLIst[k]))
8432 {
8433 pControlList[j+1] = eSIR_ACTIVE_SCAN;
8434 smsLog(pMac, LOG1, FL("Marked DFS ch %d"
8435 " as active"),
8436 cfgActiveDFSChannelLIst[k]);
8437 }
8438 }
8439 }
8440 }
8441 }
8442 }
8443
8444 smsLog(pMac, LOG1, FL("fEnableDFSChnlScan %d"),
8445 pMac->scan.fEnableDFSChnlScan);
Mihir Shete31c435d2014-02-12 13:13:34 +05308446 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
8447 "%s: dump scan control list",__func__);
8448 VOS_TRACE_HEX_DUMP(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
8449 pControlList, len);
8450
Jeff Johnson295189b2012-06-20 16:38:30 -07008451 ccmCfgSetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, len, NULL, eANI_BOOLEAN_FALSE);
8452 }//Successfully getting scan control list
Kiet Lam64c1b492013-07-12 13:56:44 +05308453 vos_mem_free(pControlList);
Jeff Johnson295189b2012-06-20 16:38:30 -07008454 }//AllocateMemory
8455}
8456
Jeff Johnson295189b2012-06-20 16:38:30 -07008457//if bgPeriod is 0, background scan is disabled. It is in millisecond units
8458eHalStatus csrSetCfgBackgroundScanPeriod(tpAniSirGlobal pMac, tANI_U32 bgPeriod)
8459{
8460 return (ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, bgPeriod, (tCcmCfgSetCallback) csrScanCcmCfgSetCallback, eANI_BOOLEAN_FALSE));
8461}
8462
8463
8464void csrScanCcmCfgSetCallback(tHalHandle hHal, tANI_S32 result)
8465{
8466 tListElem *pEntry = NULL;
8467 tSmeCmd *pCommand = NULL;
8468 tpAniSirGlobal pMac = PMAC_STRUCT( hHal );
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05308469 tDblLinkList *pCmdList ;
8470
8471 if (!pMac->fScanOffload)
8472 pCmdList = &pMac->sme.smeCmdActiveList;
8473 else
8474 pCmdList = &pMac->sme.smeScanCmdActiveList;
8475
8476 pEntry = csrLLPeekHead( pCmdList, LL_ACCESS_LOCK );
Jeff Johnson295189b2012-06-20 16:38:30 -07008477 if ( pEntry )
8478 {
8479 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8480 if ( eSmeCommandScan == pCommand->command )
8481 {
8482 eCsrScanStatus scanStatus = (CCM_IS_RESULT_SUCCESS(result)) ? eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
8483 csrReleaseScanCommand(pMac, pCommand, scanStatus);
8484 }
8485 else
8486 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008487 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
Jeff Johnson295189b2012-06-20 16:38:30 -07008488 }
8489 }
8490 smeProcessPendingQueue( pMac );
8491}
8492
8493eHalStatus csrProcessSetBGScanParam(tpAniSirGlobal pMac, tSmeCmd *pCommand)
8494{
8495 eHalStatus status;
8496 tCsrBGScanRequest *pScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
8497 tANI_U32 dataLen = sizeof( tANI_U8 ) * pScanReq->ChannelInfo.numOfChannels;
8498
8499 //***setcfg for background scan channel list
8500 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MINIMUM_CHANNEL_TIME, pScanReq->minChnTime, NULL, eANI_BOOLEAN_FALSE);
8501 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MAXIMUM_CHANNEL_TIME, pScanReq->maxChnTime, NULL, eANI_BOOLEAN_FALSE);
8502 //Not set the background scan interval if not connected because bd scan should not be run if not connected
8503 if(!csrIsAllSessionDisconnected(pMac))
8504 {
Jeff Johnson295189b2012-06-20 16:38:30 -07008505
8506#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
8507 {
8508 vos_log_scan_pkt_type *pScanLog = NULL;
8509
8510 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
8511 if(pScanLog)
8512 {
8513 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
8514 pScanLog->minChnTime = (v_U8_t)pScanReq->minChnTime;
8515 pScanLog->maxChnTime = (v_U8_t)pScanReq->maxChnTime;
8516 pScanLog->timeBetweenBgScan = (v_U8_t)pScanReq->scanInterval;
8517 pScanLog->numChannel = pScanReq->ChannelInfo.numOfChannels;
8518 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
8519 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308520 vos_mem_copy(pScanLog->channels,
8521 pScanReq->ChannelInfo.ChannelList,
8522 pScanLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07008523 }
8524 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
8525 }
8526 }
8527#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
8528
8529 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, pScanReq->scanInterval, NULL, eANI_BOOLEAN_FALSE);
8530 }
8531 else
8532 {
8533 //No need to stop aging because IDLE scan is still running
8534 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, 0, NULL, eANI_BOOLEAN_FALSE);
8535 }
8536
8537 if(pScanReq->SSID.length > WNI_CFG_SSID_LEN)
8538 {
8539 pScanReq->SSID.length = WNI_CFG_SSID_LEN;
8540 }
8541
8542 status = ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pScanReq->ChannelInfo.ChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
8543 status = ccmCfgSetStr(pMac, WNI_CFG_SSID, (tANI_U8 *)pScanReq->SSID.ssId, pScanReq->SSID.length, NULL, eANI_BOOLEAN_FALSE);
8544
8545
8546
8547 return (status);
8548}
8549
8550
c_hpothua3d45d52015-01-05 14:11:17 +05308551tSirAbortScanStatus csrScanAbortMacScan(tpAniSirGlobal pMac,
8552 tANI_U8 sessionId,
8553 eCsrAbortReason reason)
Jeff Johnson295189b2012-06-20 16:38:30 -07008554{
c_hpothua3d45d52015-01-05 14:11:17 +05308555 tSirAbortScanStatus abortScanStatus = eSIR_ABORT_ACTIVE_SCAN_LIST_EMPTY;
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308556 tSirSmeScanAbortReq *pMsg;
Jeff Johnson295189b2012-06-20 16:38:30 -07008557 tANI_U16 msgLen;
8558 tListElem *pEntry;
8559 tSmeCmd *pCommand;
8560
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308561 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07008562 {
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308563#ifdef WLAN_AP_STA_CONCURRENCY
8564 csrLLLock(&pMac->scan.scanCmdPendingList);
8565 while(NULL !=
8566 (pEntry = csrLLRemoveHead(&pMac->scan.scanCmdPendingList,
8567 LL_ACCESS_NOLOCK)))
8568 {
Jeff Johnson295189b2012-06-20 16:38:30 -07008569
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308570 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8571 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
8572 }
8573 csrLLUnlock(&pMac->scan.scanCmdPendingList);
Jeff Johnson295189b2012-06-20 16:38:30 -07008574#endif
8575
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308576 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
8577 csrRemoveCmdFromPendingList( pMac, &pMac->roam.roamCmdPendingList, eSmeCommandScan);
8578 csrRemoveCmdFromPendingList( pMac, &pMac->sme.smeCmdPendingList, eSmeCommandScan);
8579 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
8580
8581 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
8582 }
8583 else
8584 {
8585 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
8586 csrRemoveCmdWithSessionIdFromPendingList(pMac,
8587 sessionId,
8588 &pMac->sme.smeScanCmdPendingList,
8589 eSmeCommandScan);
8590 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
8591
8592 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
8593 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008594
8595 //We need to abort scan only if we are scanning
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308596 if(NULL != pEntry)
Jeff Johnson295189b2012-06-20 16:38:30 -07008597 {
8598 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308599 if(eSmeCommandScan == pCommand->command &&
8600 pCommand->sessionId == sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07008601 {
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308602 msgLen = (tANI_U16)(sizeof(tSirSmeScanAbortReq));
Kiet Lam64c1b492013-07-12 13:56:44 +05308603 pMsg = vos_mem_malloc(msgLen);
8604 if ( NULL == pMsg )
Jeff Johnson295189b2012-06-20 16:38:30 -07008605 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308606 smsLog(pMac, LOGE, FL("Failed to allocate memory for SmeScanAbortReq"));
c_hpothua3d45d52015-01-05 14:11:17 +05308607 abortScanStatus = eSIR_ABORT_SCAN_FAILURE;
Kiet Lam64c1b492013-07-12 13:56:44 +05308608 }
8609 else
8610 {
Ratheesh S Pece1f832015-07-25 15:50:25 +05308611 pCommand->u.scanCmd.abortScanIndication = eCSR_SCAN_ABORT_DEFAULT;
Srinivas, Dasari187ca4e2014-02-07 12:40:09 +05308612 if(reason == eCSR_SCAN_ABORT_DUE_TO_BAND_CHANGE)
8613 {
Ratheesh S Pece1f832015-07-25 15:50:25 +05308614 pCommand->u.scanCmd.abortScanIndication
8615 = eCSR_SCAN_ABORT_DUE_TO_BAND_CHANGE;
Srinivas, Dasari187ca4e2014-02-07 12:40:09 +05308616 }
Kiet Lam64c1b492013-07-12 13:56:44 +05308617 vos_mem_set((void *)pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008618 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_ABORT_IND);
8619 pMsg->msgLen = pal_cpu_to_be16(msgLen);
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308620 pMsg->sessionId = sessionId;
c_hpothua3d45d52015-01-05 14:11:17 +05308621 if (eHAL_STATUS_SUCCESS != palSendMBMessage(pMac->hHdd, pMsg))
8622 {
8623 smsLog(pMac, LOGE,
8624 FL("Failed to post eWNI_SME_SCAN_ABORT_IND"));
8625 abortScanStatus = eSIR_ABORT_SCAN_FAILURE;
Ratheesh S Pece1f832015-07-25 15:50:25 +05308626 pCommand->u.scanCmd.abortScanIndication = 0;
c_hpothua3d45d52015-01-05 14:11:17 +05308627 }
8628 else
8629 {
8630 abortScanStatus = eSIR_ABORT_ACTIVE_SCAN_LIST_NOT_EMPTY;
8631 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008632 }
8633 }
8634 }
8635
c_hpothua3d45d52015-01-05 14:11:17 +05308636 return(abortScanStatus);
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308637}
8638
8639void csrRemoveCmdWithSessionIdFromPendingList(tpAniSirGlobal pMac,
8640 tANI_U8 sessionId,
8641 tDblLinkList *pList,
8642 eSmeCommandType commandType)
8643{
8644 tDblLinkList localList;
8645 tListElem *pEntry;
8646 tSmeCmd *pCommand;
8647 tListElem *pEntryToRemove;
8648
8649 vos_mem_zero(&localList, sizeof(tDblLinkList));
8650 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
8651 {
8652 smsLog(pMac, LOGE, FL(" failed to open list"));
8653 return;
8654 }
8655
8656 csrLLLock(pList);
8657 if ((pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK)))
8658 {
8659
8660 /* Have to make sure we don't loop back to the head of the list,
8661 * which will happen if the entry is NOT on the list */
8662 while (pEntry)
8663 {
8664 pEntryToRemove = pEntry;
8665 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
8666 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
8667 if ((pCommand->command == commandType) &&
8668 (pCommand->sessionId == sessionId))
8669 {
8670 /* Remove that entry only */
8671 if (csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
8672 {
8673 csrLLInsertTail(&localList, pEntryToRemove,
8674 LL_ACCESS_NOLOCK);
8675 }
8676 }
8677 }
8678 }
8679 csrLLUnlock(pList);
8680
8681 while ((pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)))
8682 {
8683 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
8684 csrAbortCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
8685 }
8686
8687 csrLLClose(&localList);
Jeff Johnson295189b2012-06-20 16:38:30 -07008688}
8689
8690void csrRemoveCmdFromPendingList(tpAniSirGlobal pMac, tDblLinkList *pList,
8691 eSmeCommandType commandType )
8692{
8693 tDblLinkList localList;
8694 tListElem *pEntry;
8695 tSmeCmd *pCommand;
8696 tListElem *pEntryToRemove;
8697
8698 vos_mem_zero(&localList, sizeof(tDblLinkList));
8699 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
8700 {
8701 smsLog(pMac, LOGE, FL(" failed to open list"));
8702 return;
8703 }
8704
8705 csrLLLock(pList);
8706 if( !csrLLIsListEmpty( pList, LL_ACCESS_NOLOCK ) )
8707 {
8708 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK);
8709
8710 // Have to make sure we don't loop back to the head of the list, which will
8711 // happen if the entry is NOT on the list...
8712 while( pEntry )
8713 {
8714 pEntryToRemove = pEntry;
8715 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
8716 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
8717 if ( pCommand->command == commandType )
8718 {
8719 // Remove that entry only
8720 if(csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
8721 {
8722 csrLLInsertTail(&localList, pEntryToRemove, LL_ACCESS_NOLOCK);
8723 }
8724 }
8725 }
8726
8727
8728 }
8729 csrLLUnlock(pList);
8730
8731 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
8732 {
8733 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8734 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
8735 }
8736 csrLLClose(&localList);
8737
8738}
8739
Abhishek Singhdc2bfd42014-06-19 17:59:05 +05308740eHalStatus csrScanAbortScanForSSID(tpAniSirGlobal pMac, tANI_U32 sessionId)
8741{
8742 eHalStatus status = eHAL_STATUS_SUCCESS;
8743 tSirSmeScanAbortReq *pMsg;
8744 tANI_U16 msgLen;
8745 tListElem *pEntry;
8746 tSmeCmd *pCommand;
8747
8748 if (!pMac->fScanOffload)
8749 {
8750 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
8751#ifdef WLAN_AP_STA_CONCURRENCY
8752 csrRemoveScanForSSIDFromPendingList( pMac, &pMac->scan.scanCmdPendingList, sessionId);
8753#endif
8754 csrRemoveScanForSSIDFromPendingList( pMac, &pMac->roam.roamCmdPendingList, sessionId);
8755 csrRemoveScanForSSIDFromPendingList( pMac, &pMac->sme.smeCmdPendingList, sessionId);
8756 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
8757 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
8758 }
8759 else
8760 {
8761 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
8762 csrRemoveScanForSSIDFromPendingList( pMac, &pMac->sme.smeScanCmdPendingList, sessionId);
8763 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
8764 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
8765 }
8766
8767 if(NULL != pEntry)
8768 {
8769 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8770
8771 if ( (eSmeCommandScan == pCommand->command ) &&
8772 (sessionId == pCommand->sessionId))
8773 {
8774 if ( eCsrScanForSsid == pCommand->u.scanCmd.reason)
8775 {
8776 msgLen = (tANI_U16)(sizeof( tSirSmeScanAbortReq ));
8777 pMsg = vos_mem_malloc(msgLen);
8778 if ( NULL == pMsg )
8779 {
8780 status = eHAL_STATUS_FAILURE;
8781 smsLog(pMac, LOGE, FL("Failed to allocate memory for SmeScanAbortReq"));
8782 }
8783 else
8784 {
8785 vos_mem_zero((void *)pMsg, msgLen);
8786 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_ABORT_IND);
8787 pMsg->msgLen = pal_cpu_to_be16(msgLen);
8788 pMsg->sessionId = sessionId;
8789 status = palSendMBMessage(pMac->hHdd, pMsg);
8790 }
8791 }
8792 }
8793 }
8794 return( status );
8795}
8796
8797void csrRemoveScanForSSIDFromPendingList(tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 sessionId)
8798{
8799 tDblLinkList localList;
8800 tListElem *pEntry;
8801 tSmeCmd *pCommand;
8802 tListElem *pEntryToRemove;
8803
8804 vos_mem_zero(&localList, sizeof(tDblLinkList));
8805 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
8806 {
8807 smsLog(pMac, LOGE, FL(" failed to open list"));
8808 return;
8809 }
8810
8811 csrLLLock(pList);
8812 if( !csrLLIsListEmpty( pList, LL_ACCESS_NOLOCK ) )
8813 {
8814 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK);
8815
8816 // Have to make sure we don't loop back to the head of the list, which will
8817 // happen if the entry is NOT on the list...
8818 while( pEntry )
8819 {
8820 pEntryToRemove = pEntry;
8821 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
8822 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
8823 if ( (eSmeCommandScan == pCommand->command ) &&
8824 (sessionId == pCommand->sessionId) )
8825 {
8826 if ( eCsrScanForSsid == pCommand->u.scanCmd.reason)
8827 {
8828 // Remove that entry only
8829 if ( csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
8830 {
8831 csrLLInsertTail(&localList, pEntryToRemove, LL_ACCESS_NOLOCK);
8832 }
8833 }
8834 }
8835 }
8836 }
8837 csrLLUnlock(pList);
8838
8839 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
8840 {
8841 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8842 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
8843 }
8844 csrLLClose(&localList);
8845}
Jeff Johnson295189b2012-06-20 16:38:30 -07008846
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308847eHalStatus csrScanAbortMacScanNotForConnect(tpAniSirGlobal pMac,
8848 tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07008849{
8850 eHalStatus status = eHAL_STATUS_SUCCESS;
8851
8852 if( !csrIsScanForRoamCommandActive( pMac ) )
8853 {
8854 //Only abort the scan if it is not used for other roam/connect purpose
c_hpothua3d45d52015-01-05 14:11:17 +05308855 if (eSIR_ABORT_SCAN_FAILURE ==
8856 csrScanAbortMacScan(pMac, sessionId, eCSR_SCAN_ABORT_DEFAULT))
8857 {
8858 smsLog(pMac, LOGE, FL("fail to abort scan"));
8859 status = eHAL_STATUS_FAILURE;
8860 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008861 }
8862
8863 return (status);
8864}
8865
8866
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05308867eHalStatus csrScanGetScanChannelInfo(tpAniSirGlobal pMac, tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07008868{
8869 eHalStatus status = eHAL_STATUS_SUCCESS;
8870 tSirMbMsg *pMsg;
8871 tANI_U16 msgLen;
8872
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05308873 if (pMac->fScanOffload)
8874 msgLen = (tANI_U16)(sizeof(tSirSmeGetScanChanReq));
8875 else
8876 msgLen = (tANI_U16)(sizeof(tSirMbMsg));
8877
Kiet Lam64c1b492013-07-12 13:56:44 +05308878 pMsg = vos_mem_malloc(msgLen);
8879 if ( NULL == pMsg )
8880 status = eHAL_STATUS_FAILURE;
8881 else
Jeff Johnson295189b2012-06-20 16:38:30 -07008882 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308883 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008884 pMsg->type = eWNI_SME_GET_SCANNED_CHANNEL_REQ;
8885 pMsg->msgLen = msgLen;
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05308886 if (pMac->fScanOffload)
8887 ((tSirSmeGetScanChanReq *)pMsg)->sessionId = sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07008888 status = palSendMBMessage(pMac->hHdd, pMsg);
8889 }
8890
8891 return( status );
8892}
8893
8894tANI_BOOLEAN csrRoamIsValidChannel( tpAniSirGlobal pMac, tANI_U8 channel )
8895{
8896 tANI_BOOLEAN fValid = FALSE;
8897 tANI_U32 idxValidChannels;
8898 tANI_U32 len = pMac->roam.numValidChannels;
8899
8900 for ( idxValidChannels = 0; ( idxValidChannels < len ); idxValidChannels++ )
8901 {
8902 if ( channel == pMac->roam.validChannelList[ idxValidChannels ] )
8903 {
8904 fValid = TRUE;
8905 break;
8906 }
8907 }
8908
8909 return fValid;
8910}
8911
Manjunathappa Prakash4f1d5a52013-11-11 16:22:19 -08008912#ifdef FEATURE_WLAN_SCAN_PNO
Srikant Kuppa066904f2013-05-07 13:56:02 -07008913eHalStatus csrScanSavePreferredNetworkFound(tpAniSirGlobal pMac,
8914 tSirPrefNetworkFoundInd *pPrefNetworkFoundInd)
8915{
8916 v_U32_t uLen = 0;
8917 tpSirProbeRespBeacon pParsedFrame;
8918 tCsrScanResult *pScanResult = NULL;
8919 tSirBssDescription *pBssDescr = NULL;
8920 tANI_BOOLEAN fDupBss;
8921 tDot11fBeaconIEs *pIesLocal = NULL;
8922 tAniSSID tmpSsid;
8923 v_TIME_t timer=0;
8924 tpSirMacMgmtHdr macHeader = (tpSirMacMgmtHdr)pPrefNetworkFoundInd->data;
Abhishek Singhd3d4e022014-11-11 13:02:40 +05308925 boolean bFoundonAppliedChannel = FALSE;
8926 v_U32_t indx;
8927 u8 channelsAllowed[WNI_CFG_VALID_CHANNEL_LIST_LEN];
8928 v_U32_t numChannelsAllowed = WNI_CFG_VALID_CHANNEL_LIST_LEN;
Sushant Kaushik6274de62015-05-01 16:31:23 +05308929 tListElem *pEntry;
Abhishek Singhd3d4e022014-11-11 13:02:40 +05308930
Srikant Kuppa066904f2013-05-07 13:56:02 -07008931
8932 pParsedFrame =
Abhishek Singhc75726d2015-04-13 14:44:14 +05308933 (tpSirProbeRespBeacon)vos_mem_vmalloc(sizeof(tSirProbeRespBeacon));
Srikant Kuppa066904f2013-05-07 13:56:02 -07008934
8935 if (NULL == pParsedFrame)
8936 {
8937 smsLog(pMac, LOGE, FL(" fail to allocate memory for frame"));
8938 return eHAL_STATUS_RESOURCES;
8939 }
8940
8941 if ( pPrefNetworkFoundInd->frameLength <= SIR_MAC_HDR_LEN_3A )
8942 {
8943 smsLog(pMac, LOGE,
8944 FL("Not enough bytes in PNO indication probe resp frame! length=%d"),
8945 pPrefNetworkFoundInd->frameLength);
Abhishek Singhc75726d2015-04-13 14:44:14 +05308946 vos_mem_vfree(pParsedFrame);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008947 return eHAL_STATUS_FAILURE;
8948 }
8949
8950 if (sirConvertProbeFrame2Struct(pMac,
8951 &pPrefNetworkFoundInd->data[SIR_MAC_HDR_LEN_3A],
8952 pPrefNetworkFoundInd->frameLength - SIR_MAC_HDR_LEN_3A,
8953 pParsedFrame) != eSIR_SUCCESS ||
8954 !pParsedFrame->ssidPresent)
8955 {
8956 smsLog(pMac, LOGE,
8957 FL("Parse error ProbeResponse, length=%d"),
8958 pPrefNetworkFoundInd->frameLength);
Abhishek Singhc75726d2015-04-13 14:44:14 +05308959 vos_mem_vfree(pParsedFrame);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008960 return eHAL_STATUS_FAILURE;
8961 }
8962 //24 byte MAC header and 12 byte to ssid IE
8963 if (pPrefNetworkFoundInd->frameLength >
8964 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET))
8965 {
8966 uLen = pPrefNetworkFoundInd->frameLength -
8967 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET);
8968 }
8969
Kiet Lam64c1b492013-07-12 13:56:44 +05308970 pScanResult = vos_mem_malloc(sizeof(tCsrScanResult) + uLen);
8971 if ( NULL == pScanResult )
Srikant Kuppa066904f2013-05-07 13:56:02 -07008972 {
8973 smsLog(pMac, LOGE, FL(" fail to allocate memory for frame"));
8974 vos_mem_free(pParsedFrame);
8975 return eHAL_STATUS_RESOURCES;
8976 }
8977
Kiet Lam64c1b492013-07-12 13:56:44 +05308978 vos_mem_set(pScanResult, sizeof(tCsrScanResult) + uLen, 0);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008979 pBssDescr = &pScanResult->Result.BssDescriptor;
8980 /**
8981 * Length of BSS desription is without length of
8982 * length itself and length of pointer
8983 * that holds the next BSS description
8984 */
8985 pBssDescr->length = (tANI_U16)(
8986 sizeof(tSirBssDescription) - sizeof(tANI_U16) -
8987 sizeof(tANI_U32) + uLen);
8988 if (pParsedFrame->dsParamsPresent)
8989 {
8990 pBssDescr->channelId = pParsedFrame->channelNumber;
8991 }
8992 else if (pParsedFrame->HTInfo.present)
8993 {
8994 pBssDescr->channelId = pParsedFrame->HTInfo.primaryChannel;
8995 }
8996 else
8997 {
Mahesh A Saptasagaradd99792014-03-26 16:04:20 +05308998 /**
8999 * If Probe Responce received in PNO indication does not
9000 * contain DSParam IE or HT Info IE then add dummy channel
9001 * to the received BSS info so that Scan result received as
9002 * a part of PNO is updated to the supplicant. Specially
9003 * applicable in case of AP configured in 11A only mode.
9004 */
9005 if ((pMac->roam.configParam.bandCapability == eCSR_BAND_ALL) ||
9006 (pMac->roam.configParam.bandCapability == eCSR_BAND_24))
9007 {
9008 pBssDescr->channelId = 1;
9009 }
9010 else if(pMac->roam.configParam.bandCapability == eCSR_BAND_5G)
9011 {
9012 pBssDescr->channelId = 36;
9013 }
Abhishek Singhd3d4e022014-11-11 13:02:40 +05309014 /* Restrict the logic to ignore the pno indication for invalid channel
9015 * only if valid channel info is present in beacon/probe resp.
9016 * If no channel info is present in beacon/probe resp, always process
9017 * the pno indication.
9018 */
9019 bFoundonAppliedChannel = TRUE;
9020 }
9021
9022 if (0 != sme_GetCfgValidChannels(pMac, channelsAllowed, &numChannelsAllowed))
9023 {
9024 smsLog(pMac, LOGE, FL(" sme_GetCfgValidChannels failed "));
9025 csrFreeScanResultEntry(pMac, pScanResult);
Abhishek Singhc75726d2015-04-13 14:44:14 +05309026 vos_mem_vfree(pParsedFrame);
Abhishek Singhd3d4e022014-11-11 13:02:40 +05309027 return eHAL_STATUS_FAILURE;
9028 }
9029 /* Checking chhanelId with allowed channel list */
9030 for (indx = 0; indx < numChannelsAllowed; indx++)
9031 {
9032 if (pBssDescr->channelId == channelsAllowed[indx])
9033 {
9034 bFoundonAppliedChannel = TRUE;
9035 smsLog(pMac, LOG1, FL(" pno ind found on applied channel =%d\n "),
9036 pBssDescr->channelId);
9037 break;
9038 }
9039 }
9040 /* Ignore PNO indication if AP is on Invalid channel.
9041 */
9042 if(FALSE == bFoundonAppliedChannel)
9043 {
9044 smsLog(pMac, LOGW, FL(" prefered network found on invalid channel = %d"),
9045 pBssDescr->channelId);
9046 csrFreeScanResultEntry(pMac, pScanResult);
Abhishek Singhc75726d2015-04-13 14:44:14 +05309047 vos_mem_vfree(pParsedFrame);
Abhishek Singhd3d4e022014-11-11 13:02:40 +05309048 return eHAL_STATUS_FAILURE;
Srikant Kuppa066904f2013-05-07 13:56:02 -07009049 }
9050
9051 if ((pBssDescr->channelId > 0) && (pBssDescr->channelId < 15))
9052 {
9053 int i;
9054 // 11b or 11g packet
9055 // 11g iff extended Rate IE is present or
9056 // if there is an A rate in suppRate IE
9057 for (i = 0; i < pParsedFrame->supportedRates.numRates; i++)
9058 {
9059 if (sirIsArate(pParsedFrame->supportedRates.rate[i] & 0x7f))
9060 {
9061 pBssDescr->nwType = eSIR_11G_NW_TYPE;
9062 break;
9063 }
9064 }
9065 if (pParsedFrame->extendedRatesPresent)
9066 {
9067 pBssDescr->nwType = eSIR_11G_NW_TYPE;
9068 }
9069 }
9070 else
9071 {
9072 // 11a packet
9073 pBssDescr->nwType = eSIR_11A_NW_TYPE;
9074 }
9075
9076 pBssDescr->sinr = 0;
9077 pBssDescr->rssi = -1 * pPrefNetworkFoundInd->rssi;
9078 pBssDescr->beaconInterval = pParsedFrame->beaconInterval;
AnjaneeDevi Kapparapu4b043912014-02-18 13:22:35 +05309079 if (!pBssDescr->beaconInterval)
9080 {
9081 smsLog(pMac, LOGW,
9082 FL("Bcn Interval is Zero , default to 100" MAC_ADDRESS_STR),
9083 MAC_ADDR_ARRAY(pBssDescr->bssId) );
9084 pBssDescr->beaconInterval = 100;
9085 }
Srikant Kuppa066904f2013-05-07 13:56:02 -07009086 pBssDescr->timeStamp[0] = pParsedFrame->timeStamp[0];
9087 pBssDescr->timeStamp[1] = pParsedFrame->timeStamp[1];
9088 pBssDescr->capabilityInfo = *((tANI_U16 *)&pParsedFrame->capabilityInfo);
Kiet Lam64c1b492013-07-12 13:56:44 +05309089 vos_mem_copy((tANI_U8 *) &pBssDescr->bssId, (tANI_U8 *) macHeader->bssId, sizeof(tSirMacAddr));
Deepthi Gowri4480a3f2016-05-18 19:30:17 +05309090 pBssDescr->nReceivedTime = vos_timer_get_system_time();
Srikant Kuppa066904f2013-05-07 13:56:02 -07009091
Abhishek Singh195c03e2014-05-14 17:21:30 +05309092 smsLog( pMac, LOG1, FL("Bssid= "MAC_ADDRESS_STR
9093 " chan= %d, rssi = %d "),
Arif Hussain24bafea2013-11-15 15:10:03 -08009094 MAC_ADDR_ARRAY(pBssDescr->bssId),
Srikant Kuppa066904f2013-05-07 13:56:02 -07009095 pBssDescr->channelId,
Abhishek Singh195c03e2014-05-14 17:21:30 +05309096 pBssDescr->rssi);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009097
9098 //IEs
9099 if (uLen)
9100 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309101 vos_mem_copy(&pBssDescr->ieFields,
9102 pPrefNetworkFoundInd->data + (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET),
9103 uLen);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009104 }
9105
9106 pIesLocal = (tDot11fBeaconIEs *)( pScanResult->Result.pvIes );
9107 if ( !pIesLocal &&
9108 (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
9109 &pScanResult->Result.BssDescriptor, &pIesLocal))) )
9110 {
9111 smsLog(pMac, LOGE, FL(" Cannot parse IEs"));
9112 csrFreeScanResultEntry(pMac, pScanResult);
Abhishek Singhc75726d2015-04-13 14:44:14 +05309113 vos_mem_vfree(pParsedFrame);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009114 return eHAL_STATUS_RESOURCES;
9115 }
9116
9117 fDupBss = csrRemoveDupBssDescription( pMac,
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05309118 &pScanResult->Result.BssDescriptor, pIesLocal, &tmpSsid, &timer, FALSE);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009119 //Check whether we have reach out limit
9120 if ( CSR_SCAN_IS_OVER_BSS_LIMIT(pMac) )
9121 {
9122 //Limit reach
9123 smsLog(pMac, LOGE, FL(" BSS limit reached"));
9124 //Free the resources
9125 if( (pScanResult->Result.pvIes == NULL) && pIesLocal )
9126 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309127 vos_mem_free(pIesLocal);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009128 }
9129 csrFreeScanResultEntry(pMac, pScanResult);
9130 vos_mem_free(pParsedFrame);
9131 return eHAL_STATUS_RESOURCES;
9132 }
Nalla Kartheek71946422015-09-15 14:41:22 +05309133
9134 if ((macHeader->fc.type == SIR_MAC_MGMT_FRAME) &&
9135 (macHeader->fc.subType == SIR_MAC_MGMT_PROBE_RSP))
9136 {
9137 pScanResult->Result.BssDescriptor.fProbeRsp = 1;
9138 }
Srikant Kuppa066904f2013-05-07 13:56:02 -07009139 //Add to scan cache
9140 csrScanAddResult(pMac, pScanResult, pIesLocal);
Sushant Kaushik6274de62015-05-01 16:31:23 +05309141 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
Kiet Lamb537cfb2013-11-07 12:56:49 +05309142 if( (pScanResult->Result.pvIes == NULL) && pIesLocal )
9143 {
9144 vos_mem_free(pIesLocal);
9145 }
9146
Abhishek Singhc75726d2015-04-13 14:44:14 +05309147 vos_mem_vfree(pParsedFrame);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009148
9149 return eHAL_STATUS_SUCCESS;
9150}
Manjunathappa Prakash4f1d5a52013-11-11 16:22:19 -08009151#endif //FEATURE_WLAN_SCAN_PNO
Srikant Kuppa066904f2013-05-07 13:56:02 -07009152
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08009153#ifdef FEATURE_WLAN_LFR
9154void csrInitOccupiedChannelsList(tpAniSirGlobal pMac)
9155{
9156 tListElem *pEntry = NULL;
9157 tCsrScanResult *pBssDesc = NULL;
9158 tDot11fBeaconIEs *pIes = NULL;
Srinivas28b5b4e2012-12-12 13:07:53 -08009159 tpCsrNeighborRoamControlInfo pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
9160
9161 if (0 != pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels)
9162 {
9163 smsLog(pMac, LOG1, FL("%s: Ini file contains neighbor scan channel list,"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08009164 " hence NO need to build occupied channel list (numChannels = %d)"),
Srinivas28b5b4e2012-12-12 13:07:53 -08009165 __func__, pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels);
9166 return;
9167 }
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08009168
9169 if (!csrNeighborRoamIsNewConnectedProfile(pMac))
9170 {
9171 smsLog(pMac, LOG2, FL("%s: donot flush occupied list since current roam profile"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08009172 " matches previous (numChannels = %d)"),
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08009173 __func__, pMac->scan.occupiedChannels.numChannels);
9174 return;
9175 }
9176
9177 /* Empty occupied channels here */
9178 pMac->scan.occupiedChannels.numChannels = 0;
9179
9180 csrLLLock(&pMac->scan.scanResultList);
9181 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
9182 while( pEntry )
9183 {
9184 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
9185 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
9186
9187 //At this time, pBssDescription->Result.pvIes may be NULL
Srikant Kuppa866893f2012-12-27 17:28:14 -08009188 if( !pIes && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08009189 &pBssDesc->Result.BssDescriptor, &pIes))) )
9190 {
9191 continue;
9192 }
9193
9194 csrScanAddToOccupiedChannels(pMac, pBssDesc, &pMac->scan.occupiedChannels, pIes);
9195
9196 /*
9197 * Free the memory allocated for pIes in csrGetParsedBssDescriptionIEs
9198 */
9199 if( (pBssDesc->Result.pvIes == NULL) && pIes )
9200 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309201 vos_mem_free(pIes);
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08009202 }
9203
9204 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK );
9205 }//while
9206 csrLLUnlock(&pMac->scan.scanResultList);
Srikant Kuppa866893f2012-12-27 17:28:14 -08009207
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08009208}
9209#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009210
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009211eHalStatus csrScanCreateEntryInScanCache(tpAniSirGlobal pMac, tANI_U32 sessionId,
9212 tCsrBssid bssid, tANI_U8 channel)
9213{
9214 eHalStatus status = eHAL_STATUS_SUCCESS;
9215 tDot11fBeaconIEs *pNewIes = NULL;
9216 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
Praveen Kumar Sirisilla8bdfac42013-10-10 17:20:48 -07009217 tSirBssDescription *pNewBssDescriptor = NULL;
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009218 tANI_U32 size = 0;
9219
9220 if(NULL == pSession)
9221 {
9222 status = eHAL_STATUS_FAILURE;
9223 return status;
9224 }
9225 smsLog(pMac, LOG2, FL("csrScanCreateEntryInScanCache: Current bssid::"
Arif Hussain24bafea2013-11-15 15:10:03 -08009226 MAC_ADDRESS_STR),
9227 MAC_ADDR_ARRAY(pSession->pConnectBssDesc->bssId));
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009228 smsLog(pMac, LOG2, FL("csrScanCreateEntryInScanCache: My bssid::"
Arif Hussain24bafea2013-11-15 15:10:03 -08009229 MAC_ADDRESS_STR" channel %d"),
9230 MAC_ADDR_ARRAY(bssid), channel);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009231
9232 do
9233 {
9234 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
9235 pSession->pConnectBssDesc, &pNewIes)))
9236 {
9237 smsLog(pMac, LOGE, FL("%s: Failed to parse IEs"),
9238 __func__);
9239 status = eHAL_STATUS_FAILURE;
9240 break;
9241 }
9242
9243 size = pSession->pConnectBssDesc->length + sizeof(pSession->pConnectBssDesc->length);
Kiet Lam64c1b492013-07-12 13:56:44 +05309244 if (size)
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009245 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309246 pNewBssDescriptor = vos_mem_malloc(size);
9247 if ( NULL == pNewBssDescriptor )
9248 status = eHAL_STATUS_FAILURE;
9249 else
9250 status = eHAL_STATUS_SUCCESS;
9251 if (HAL_STATUS_SUCCESS(status))
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009252 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309253 vos_mem_copy(pNewBssDescriptor, pSession->pConnectBssDesc, size);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009254 }
9255 else
9256 {
9257 smsLog(pMac, LOGE, FL("%s: memory allocation failed"),
9258 __func__);
9259 status = eHAL_STATUS_FAILURE;
9260 break;
9261 }
9262
9263 //change the BSSID & channel as passed
Kiet Lam64c1b492013-07-12 13:56:44 +05309264 vos_mem_copy(pNewBssDescriptor->bssId, bssid, sizeof(tSirMacAddr));
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009265 pNewBssDescriptor->channelId = channel;
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07009266 if(NULL == csrScanAppendBssDescription( pMac, pNewBssDescriptor, pNewIes, TRUE ))
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009267 {
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07009268 smsLog(pMac, LOGE, FL("%s: csrScanAppendBssDescription failed"),
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009269 __func__);
9270 status = eHAL_STATUS_FAILURE;
9271 break;
9272 }
9273 }
9274 else
9275 {
9276 smsLog(pMac, LOGE, FL("%s: length of bss descriptor is 0"),
9277 __func__);
9278 status = eHAL_STATUS_FAILURE;
9279 break;
9280 }
9281 smsLog(pMac, LOGE, FL("%s: entry successfully added in scan cache"),
9282 __func__);
9283 }while(0);
9284
9285 if(pNewIes)
9286 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309287 vos_mem_free(pNewIes);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009288 }
9289 if(pNewBssDescriptor)
9290 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309291 vos_mem_free(pNewBssDescriptor);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009292 }
9293 return status;
9294}
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07009295
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08009296#ifdef FEATURE_WLAN_ESE
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07009297// Update the TSF with the difference in system time
9298void UpdateCCKMTSF(tANI_U32 *timeStamp0, tANI_U32 *timeStamp1, tANI_U32 *incr)
9299{
9300 tANI_U64 timeStamp64 = ((tANI_U64)*timeStamp1 << 32) | (*timeStamp0);
9301
9302 timeStamp64 = (tANI_U64)(timeStamp64 + (tANI_U64)*incr);
9303 *timeStamp0 = (tANI_U32)(timeStamp64 & 0xffffffff);
9304 *timeStamp1 = (tANI_U32)((timeStamp64 >> 32) & 0xffffffff);
9305}
9306#endif