blob: 623ff6d982420a00297d2eda56b89da8653ec6f1 [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;
2089 tANI_S32 normalised_rssi;
2090 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;
2255
2256 for (i = 0; i <= pMac->PERroamCandidatesCnt; i++)
2257 if (pMac->candidateChannelInfo[i].channelNumber == bssInfo->channelId)
2258 break;
2259 if (i > pMac->PERroamCandidatesCnt) {
2260 /* home channel info is not present, no need to roam */
2261 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR,
2262 FL("home channel %d congestion info not present"),
2263 bssInfo->channelId);
2264 pMac->currentBssScore = PER_ROAM_MAX_BSS_SCORE;
2265 return -1;
2266 }
2267
2268 /* find best RSSI of other AP in this channel */
2269 best_rssi = MIN_RSSI;
2270 for (other_ap_cnt = 0; other_ap_cnt <
2271 pMac->candidateChannelInfo[i].otherApCount; other_ap_cnt++) {
2272 if (pMac->candidateChannelInfo[i].otherApRssi[other_ap_cnt] > best_rssi)
2273 best_rssi = pMac->candidateChannelInfo[i].otherApRssi[other_ap_cnt];
2274 }
2275
2276 score = calculateBssScore(bssInfo, best_rssi,
2277 pMac->candidateChannelInfo[i].otherApCount,
2278 pMac->candidateChannelInfo[i].channelCCA);
2279 pMac->currentBssScore = score;
2280 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
2281 FL("PER Roam Current AP score %d channel %d"),
2282 score, bssInfo->channelId);
2283 return 0;
2284}
2285
2286
2287static tANI_BOOLEAN csrIsBetterBssInCongestion(tCsrScanResult *pBss1,
2288 tCsrScanResult *pBss2)
2289{
2290 tANI_BOOLEAN ret;
2291
2292 if(CSR_IS_BETTER_PREFER_VALUE(pBss1->congestionScore,
2293 pBss2->congestionScore))
2294 ret = eANI_BOOLEAN_TRUE;
2295 else
2296 ret = eANI_BOOLEAN_FALSE;
2297
2298 return (ret);
2299}
2300#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002301
2302//To check whther pBss1 is better than pBss2
2303static tANI_BOOLEAN csrIsBetterBss(tCsrScanResult *pBss1, tCsrScanResult *pBss2)
2304{
2305 tANI_BOOLEAN ret;
2306
2307 if(CSR_IS_BETTER_PREFER_VALUE(pBss1->preferValue, pBss2->preferValue))
2308 {
2309 ret = eANI_BOOLEAN_TRUE;
2310 }
2311 else if(CSR_IS_EQUAL_PREFER_VALUE(pBss1->preferValue, pBss2->preferValue))
2312 {
2313 if(CSR_IS_BETTER_CAP_VALUE(pBss1->capValue, pBss2->capValue))
2314 {
2315 ret = eANI_BOOLEAN_TRUE;
2316 }
2317 else
2318 {
2319 ret = eANI_BOOLEAN_FALSE;
2320 }
2321 }
2322 else
2323 {
2324 ret = eANI_BOOLEAN_FALSE;
2325 }
2326
2327 return (ret);
2328}
2329
2330
Srikant Kuppa866893f2012-12-27 17:28:14 -08002331#ifdef FEATURE_WLAN_LFR
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002332//Add the channel to the occupiedChannels array
2333static void csrScanAddToOccupiedChannels(
Srikant Kuppa866893f2012-12-27 17:28:14 -08002334 tpAniSirGlobal pMac,
2335 tCsrScanResult *pResult,
2336 tCsrChannel *pOccupiedChannels,
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002337 tDot11fBeaconIEs *pIes)
2338{
2339 eHalStatus status;
2340 tANI_U8 channel;
2341 tANI_U8 numOccupiedChannels = pOccupiedChannels->numChannels;
2342 tANI_U8 *pOccupiedChannelList = pOccupiedChannels->channelList;
2343
2344 channel = pResult->Result.BssDescriptor.channelId;
2345
2346 if (!csrIsChannelPresentInList(pOccupiedChannelList, numOccupiedChannels, channel)
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08002347 && csrNeighborRoamConnectedProfileMatch(pMac, pResult, pIes))
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002348 {
Srikant Kuppa866893f2012-12-27 17:28:14 -08002349 status = csrAddToChannelListFront(pOccupiedChannelList, numOccupiedChannels, channel);
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002350 if(HAL_STATUS_SUCCESS(status))
Srikant Kuppa866893f2012-12-27 17:28:14 -08002351 {
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002352 pOccupiedChannels->numChannels++;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002353 smsLog(pMac, LOG2, FL("%s: added channel %d to the list (count=%d)"),
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08002354 __func__, channel, pOccupiedChannels->numChannels);
Srikant Kuppa866893f2012-12-27 17:28:14 -08002355 if (pOccupiedChannels->numChannels > CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN)
2356 pOccupiedChannels->numChannels = CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN;
2357 }
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002358 }
2359}
Mukul Sharma9e4e0f92015-02-13 18:45:20 +05302360
2361void csrAddChannelToOccupiedChannelList(tpAniSirGlobal pMac,
2362 tANI_U8 channel)
2363{
2364 eHalStatus status;
2365 tCsrChannel *pOccupiedChannels = &pMac->scan.occupiedChannels;
2366 tANI_U8 numOccupiedChannels = pOccupiedChannels->numChannels;
2367 tANI_U8 *pOccupiedChannelList = pOccupiedChannels->channelList;
2368 if (!csrIsChannelPresentInList(pOccupiedChannelList,
2369 numOccupiedChannels, channel))
2370 {
2371 status = csrAddToChannelListFront(pOccupiedChannelList,
2372 numOccupiedChannels, channel);
2373 if(HAL_STATUS_SUCCESS(status))
2374 {
2375 pOccupiedChannels->numChannels++;
2376 smsLog(pMac, LOG2, FL("added channel %d to the list (count=%d)"),
2377 channel, pOccupiedChannels->numChannels);
2378 if (pOccupiedChannels->numChannels >
2379 CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN)
2380 {
2381 pOccupiedChannels->numChannels =
2382 CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN;
2383 smsLog(pMac, LOG2,
2384 FL("trim no of Channels for Occ channel list"));
2385 }
2386 }
2387 }
2388}
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002389#endif
2390
Jeff Johnson295189b2012-06-20 16:38:30 -07002391//Put the BSS into the scan result list
2392//pIes can not be NULL
2393static void csrScanAddResult(tpAniSirGlobal pMac, tCsrScanResult *pResult, tDot11fBeaconIEs *pIes)
2394{
Srinivas28b5b4e2012-12-12 13:07:53 -08002395#ifdef FEATURE_WLAN_LFR
2396 tpCsrNeighborRoamControlInfo pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
2397#endif
2398
Jeff Johnson295189b2012-06-20 16:38:30 -07002399 pResult->preferValue = csrGetBssPreferValue(pMac, (int)pResult->Result.BssDescriptor.rssi);
2400 pResult->capValue = csrGetBssCapValue(pMac, &pResult->Result.BssDescriptor, pIes);
2401 csrLLInsertTail( &pMac->scan.scanResultList, &pResult->Link, LL_ACCESS_LOCK );
Srikant Kuppa866893f2012-12-27 17:28:14 -08002402#ifdef FEATURE_WLAN_LFR
Srinivas28b5b4e2012-12-12 13:07:53 -08002403 if(0 == pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels)
2404 {
2405 /* Build the occupied channel list, only if "gNeighborScanChannelList" is
2406 NOT set in the cfg.ini file */
2407 csrScanAddToOccupiedChannels(pMac, pResult, &pMac->scan.occupiedChannels, pIes);
2408 }
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002409#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002410}
2411
2412
2413eHalStatus csrScanGetResult(tpAniSirGlobal pMac, tCsrScanResultFilter *pFilter, tScanResultHandle *phResult)
2414{
2415 eHalStatus status;
2416 tScanResultList *pRetList;
2417 tCsrScanResult *pResult, *pBssDesc;
2418 tANI_U32 count = 0;
2419 tListElem *pEntry;
2420 tANI_U32 bssLen, allocLen;
2421 eCsrEncryptionType uc = eCSR_ENCRYPT_TYPE_NONE, mc = eCSR_ENCRYPT_TYPE_NONE;
2422 eCsrAuthType auth = eCSR_AUTH_TYPE_OPEN_SYSTEM;
2423 tDot11fBeaconIEs *pIes, *pNewIes;
2424 tANI_BOOLEAN fMatch;
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002425 tANI_U16 i = 0;
Kapil Guptab3a981b2016-06-26 13:36:51 +05302426 tCsrRoamSession *pSession = CSR_GET_SESSION(pMac,
2427 pMac->roam.roamSession->sessionId);
2428
Jeff Johnson295189b2012-06-20 16:38:30 -07002429 if(phResult)
2430 {
2431 *phResult = CSR_INVALID_SCANRESULT_HANDLE;
2432 }
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002433
2434 if (pMac->roam.configParam.nSelect5GHzMargin)
2435 {
2436 pMac->scan.inScanResultBestAPRssi = -128;
2437 csrLLLock(&pMac->scan.scanResultList);
2438
2439 /* Find out the best AP Rssi going thru the scan results */
2440 pEntry = csrLLPeekHead(&pMac->scan.scanResultList, LL_ACCESS_NOLOCK);
2441 while ( NULL != pEntry)
2442 {
2443 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002444 fMatch = FALSE;
2445
2446 if (pFilter)
2447 for(i = 0; i < pFilter->SSIDs.numOfSSIDs; i++)
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002448 {
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002449 fMatch = csrIsSsidMatch( pMac, pFilter->SSIDs.SSIDList[i].SSID.ssId, pFilter->SSIDs.SSIDList[i].SSID.length,
2450 pBssDesc->Result.ssId.ssId,
2451 pBssDesc->Result.ssId.length, eANI_BOOLEAN_TRUE );
2452 if (fMatch)
2453 {
2454 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
2455
2456 //At this time, pBssDescription->Result.pvIes may be NULL
2457 if( !pIes && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
2458 &pBssDesc->Result.BssDescriptor, &pIes))) )
2459 {
2460 continue;
2461 }
2462
2463 smsLog(pMac, LOG1, FL("SSID Matched"));
Leela Venkata Kiran Kumar Reddy Chiralae208a832014-04-27 22:34:25 -07002464
Leela Venkata Kiran Kumar Reddy Chiralaf257bef2014-04-11 18:48:12 -07002465 if ( pFilter->bOSENAssociation )
2466 {
2467 fMatch = TRUE;
2468 }
Leela Venkata Kiran Kumar Reddy Chiralae208a832014-04-27 22:34:25 -07002469 else
2470 {
Abhishek Singh658d4de2014-06-26 10:53:15 +05302471#ifdef WLAN_FEATURE_11W
Abhishek Singh3b56d3a2014-06-25 12:37:39 +05302472 fMatch = csrIsSecurityMatch(pMac, &pFilter->authType,
2473 &pFilter->EncryptionType,
2474 &pFilter->mcEncryptionType,
2475 &pFilter->MFPEnabled,
2476 &pFilter->MFPRequired,
2477 &pFilter->MFPCapable,
2478 &pBssDesc->Result.BssDescriptor,
2479 pIes, NULL, NULL, NULL );
Abhishek Singh658d4de2014-06-26 10:53:15 +05302480#else
2481 fMatch = csrIsSecurityMatch(pMac, &pFilter->authType,
2482 &pFilter->EncryptionType,
2483 &pFilter->mcEncryptionType,
2484 NULL, NULL, NULL,
2485 &pBssDesc->Result.BssDescriptor,
2486 pIes, NULL, NULL, NULL );
2487#endif
Leela Venkata Kiran Kumar Reddy Chiralae208a832014-04-27 22:34:25 -07002488 }
2489 if ((pBssDesc->Result.pvIes == NULL) && pIes)
2490 vos_mem_free(pIes);
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002491
2492 if (fMatch)
2493 smsLog(pMac, LOG1, FL(" Security Matched"));
2494 }
2495 }
2496
2497 if (fMatch && (pBssDesc->Result.BssDescriptor.rssi > pMac->scan.inScanResultBestAPRssi))
2498 {
2499 smsLog(pMac, LOG1, FL("Best AP Rssi changed from %d to %d"),
2500 pMac->scan.inScanResultBestAPRssi,
2501 pBssDesc->Result.BssDescriptor.rssi);
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002502 pMac->scan.inScanResultBestAPRssi = pBssDesc->Result.BssDescriptor.rssi;
2503 }
2504 pEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
2505 }
2506
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002507 if ( -128 != pMac->scan.inScanResultBestAPRssi)
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002508 {
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002509 smsLog(pMac, LOG1, FL("Best AP Rssi is %d"), pMac->scan.inScanResultBestAPRssi);
2510 /* Modify Rssi category based on best AP Rssi */
2511 csrAssignRssiForCategory(pMac, pMac->scan.inScanResultBestAPRssi, pMac->roam.configParam.bCatRssiOffset);
2512 pEntry = csrLLPeekHead(&pMac->scan.scanResultList, LL_ACCESS_NOLOCK);
2513 while ( NULL != pEntry)
2514 {
2515 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002516
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002517 /* re-assign preference value based on modified rssi bucket */
2518 pBssDesc->preferValue = csrGetBssPreferValue(pMac, (int)pBssDesc->Result.BssDescriptor.rssi);
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002519
Arif Hussaina7c8e412013-11-20 11:06:42 -08002520 smsLog(pMac, LOG2, FL("BSSID("MAC_ADDRESS_STR
Jeff Johnson123ed002013-11-22 17:39:55 -08002521 ") Rssi(%d) Chnl(%d) PrefVal(%u) SSID=%.*s"),
Arif Hussaina7c8e412013-11-20 11:06:42 -08002522 MAC_ADDR_ARRAY(pBssDesc->Result.BssDescriptor.bssId),
2523 pBssDesc->Result.BssDescriptor.rssi,
2524 pBssDesc->Result.BssDescriptor.channelId,
2525 pBssDesc->preferValue,
2526 pBssDesc->Result.ssId.length, pBssDesc->Result.ssId.ssId);
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002527
2528 pEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
2529 }
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002530 }
2531
2532 csrLLUnlock(&pMac->scan.scanResultList);
2533 }
2534
Kiet Lam64c1b492013-07-12 13:56:44 +05302535 pRetList = vos_mem_malloc(sizeof(tScanResultList));
2536 if ( NULL == pRetList )
2537 status = eHAL_STATUS_FAILURE;
2538 else
2539 status = eHAL_STATUS_SUCCESS;
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002540 if(HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07002541 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302542 vos_mem_set(pRetList, sizeof(tScanResultList), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002543 csrLLOpen(pMac->hHdd, &pRetList->List);
2544 pRetList->pCurEntry = NULL;
Kapil Guptab3a981b2016-06-26 13:36:51 +05302545#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
2546 if (pFilter && pFilter->isPERRoamScan)
2547 if (pSession && pSession->pConnectBssDesc)
2548 csrFindSelfCongestionScore(pMac,
2549 pSession->pConnectBssDesc);
2550#endif
2551
Jeff Johnson295189b2012-06-20 16:38:30 -07002552 csrLLLock(&pMac->scan.scanResultList);
2553 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
2554 while( pEntry )
2555 {
2556 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2557 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
2558 //if pBssDesc->Result.pvIes is NULL, we need to free any memory allocated by csrMatchBSS
2559 //for any error condition, otherwiase, it will be freed later.
2560 //reset
2561 fMatch = eANI_BOOLEAN_FALSE;
2562 pNewIes = NULL;
2563
2564 if(pFilter)
2565 {
2566 fMatch = csrMatchBSS(pMac, &pBssDesc->Result.BssDescriptor, pFilter, &auth, &uc, &mc, &pIes);
2567 if( NULL != pIes )
2568 {
2569 //Only save it when matching
2570 if(fMatch)
2571 {
2572 if( !pBssDesc->Result.pvIes )
2573 {
2574 //csrMatchBSS allocates the memory. Simply pass it and it is freed later
2575 pNewIes = pIes;
2576 }
2577 else
2578 {
2579 //The pIes is allocated by someone else. make a copy
2580 //Only to save parsed IEs if caller provides a filter. Most likely the caller
2581 //is using to for association, hence save the parsed IEs
Kiet Lam64c1b492013-07-12 13:56:44 +05302582 pNewIes = vos_mem_malloc(sizeof(tDot11fBeaconIEs));
2583 if ( NULL == pNewIes )
2584 status = eHAL_STATUS_FAILURE;
2585 else
2586 status = eHAL_STATUS_SUCCESS;
2587 if ( HAL_STATUS_SUCCESS( status ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07002588 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302589 vos_mem_copy(pNewIes, pIes, sizeof( tDot11fBeaconIEs ));
Jeff Johnson295189b2012-06-20 16:38:30 -07002590 }
2591 else
2592 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002593 smsLog(pMac, LOGE, FL(" fail to allocate memory for IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002594 //Need to free memory allocated by csrMatchBSS
2595 if( !pBssDesc->Result.pvIes )
2596 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302597 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07002598 }
2599 break;
2600 }
2601 }
2602 }//fMatch
2603 else if( !pBssDesc->Result.pvIes )
2604 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302605 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07002606 }
2607 }
2608 }
2609 if(NULL == pFilter || fMatch)
2610 {
2611 bssLen = pBssDesc->Result.BssDescriptor.length + sizeof(pBssDesc->Result.BssDescriptor.length);
2612 allocLen = sizeof( tCsrScanResult ) + bssLen;
Kiet Lam64c1b492013-07-12 13:56:44 +05302613 pResult = vos_mem_malloc(allocLen);
2614 if ( NULL == pResult )
2615 status = eHAL_STATUS_FAILURE;
2616 else
2617 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07002618 if(!HAL_STATUS_SUCCESS(status))
2619 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002620 smsLog(pMac, LOGE, FL(" fail to allocate memory for scan result, len=%d"), allocLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07002621 if(pNewIes)
2622 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302623 vos_mem_free(pNewIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07002624 }
2625 break;
2626 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302627 vos_mem_set(pResult, allocLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002628 pResult->capValue = pBssDesc->capValue;
2629 pResult->preferValue = pBssDesc->preferValue;
2630 pResult->ucEncryptionType = uc;
2631 pResult->mcEncryptionType = mc;
2632 pResult->authType = auth;
2633 pResult->Result.ssId = pBssDesc->Result.ssId;
Padma, Santhosh Kumare12fd982016-03-21 13:07:52 +05302634 pResult->Result.timer = pBssDesc->Result.timer;
Jeff Johnson295189b2012-06-20 16:38:30 -07002635 //save the pIes for later use
2636 pResult->Result.pvIes = pNewIes;
2637 //save bss description
Kiet Lam64c1b492013-07-12 13:56:44 +05302638 vos_mem_copy(&pResult->Result.BssDescriptor,
2639 &pBssDesc->Result.BssDescriptor, bssLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07002640 //No need to lock pRetList because it is locally allocated and no outside can access it at this time
2641 if(csrLLIsListEmpty(&pRetList->List, LL_ACCESS_NOLOCK))
2642 {
Kapil Guptab3a981b2016-06-26 13:36:51 +05302643#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
2644 if (pFilter && pFilter->isPERRoamScan) {
2645 csrFindCongestionScore(pMac, pResult);
2646 if (pResult->congestionScore > pMac->currentBssScore) {
2647 csrLLInsertTail(&pRetList->List, &pResult->Link,
2648 LL_ACCESS_NOLOCK);
2649 smsLog(pMac, LOGW,
2650 FL("added one entry in LL in PER Roam list"));
2651 }
2652 }
2653 else
2654#endif
2655 {
2656 csrLLInsertTail(&pRetList->List, &pResult->Link,
2657 LL_ACCESS_NOLOCK);
2658 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002659 }
2660 else
2661 {
2662 //To sort the list
2663 tListElem *pTmpEntry;
2664 tCsrScanResult *pTmpResult;
2665
2666 pTmpEntry = csrLLPeekHead(&pRetList->List, LL_ACCESS_NOLOCK);
2667 while(pTmpEntry)
2668 {
2669 pTmpResult = GET_BASE_ADDR( pTmpEntry, tCsrScanResult, Link );
Kapil Guptab3a981b2016-06-26 13:36:51 +05302670#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
2671 if (pFilter && pFilter->isPERRoamScan) {
2672 csrFindCongestionScore(pMac, pResult);
2673 if(csrIsBetterBssInCongestion(pResult, pTmpResult)&&
2674 (pResult->congestionScore > pMac->currentBssScore))
2675 {
2676 csrLLInsertEntry(&pRetList->List, pTmpEntry,
2677 &pResult->Link, LL_ACCESS_NOLOCK);
2678 smsLog(pMac, LOGW,
2679 FL("added another entry in LL in PER Roam list"));
2680 pResult = NULL;
2681 break;
2682 }
2683 pTmpEntry = csrLLNext(&pRetList->List,
2684 pTmpEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07002685 }
Kapil Guptab3a981b2016-06-26 13:36:51 +05302686 else
2687#endif
2688 {
2689 if(csrIsBetterBss(pResult, pTmpResult))
2690 {
2691 csrLLInsertEntry(&pRetList->List, pTmpEntry,
2692 &pResult->Link, LL_ACCESS_NOLOCK);
2693 //To indicate we are done
2694 pResult = NULL;
2695 break;
2696 }
2697 pTmpEntry = csrLLNext(&pRetList->List,
2698 pTmpEntry, LL_ACCESS_NOLOCK);
2699 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002700 }
2701 if(pResult != NULL)
Kapil Guptab3a981b2016-06-26 13:36:51 +05302702#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
2703 if ((pFilter && !pFilter->isPERRoamScan) ||
2704 (pFilter == NULL) ||
2705 (pResult->congestionScore > pMac->currentBssScore))
2706#endif
2707 {
2708 //This one is not better than any one
2709 csrLLInsertTail(&pRetList->List,
2710 &pResult->Link, LL_ACCESS_NOLOCK);
2711 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002712 }
2713 count++;
2714 }
2715 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK );
2716 }//while
2717 csrLLUnlock(&pMac->scan.scanResultList);
2718
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002719 smsLog(pMac, LOG2, FL("return %d BSS"), csrLLCount(&pRetList->List));
Jeff Johnson295189b2012-06-20 16:38:30 -07002720
2721 if( !HAL_STATUS_SUCCESS(status) || (phResult == NULL) )
2722 {
2723 //Fail or No one wants the result.
2724 csrScanResultPurge(pMac, (tScanResultHandle)pRetList);
2725 }
2726 else
2727 {
2728 if(0 == count)
2729 {
2730 //We are here meaning the there is no match
2731 csrLLClose(&pRetList->List);
Kiet Lam64c1b492013-07-12 13:56:44 +05302732 vos_mem_free(pRetList);
Jeff Johnson295189b2012-06-20 16:38:30 -07002733 status = eHAL_STATUS_E_NULL_VALUE;
Kapil Guptab3a981b2016-06-26 13:36:51 +05302734 smsLog(pMac, LOGW,
2735 FL("Nil scan results or no matching AP found"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002736 }
2737 else if(phResult)
2738 {
2739 *phResult = pRetList;
2740 }
2741 }
2742 }//Allocated pRetList
2743
2744 return (status);
2745}
2746
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002747/*
2748 * NOTE: This routine is being added to make
2749 * sure that scan results are not being flushed
2750 * while roaming. If the scan results are flushed,
2751 * we are unable to recover from
2752 * csrRoamRoamingStateDisassocRspProcessor.
2753 * If it is needed to remove this routine,
2754 * first ensure that we recover gracefully from
2755 * csrRoamRoamingStateDisassocRspProcessor if
2756 * csrScanGetResult returns with a failure because
2757 * of not being able to find the roaming BSS.
2758 */
2759tANI_U8 csrScanFlushDenied(tpAniSirGlobal pMac)
2760{
2761 switch(pMac->roam.neighborRoamInfo.neighborRoamState) {
2762 case eCSR_NEIGHBOR_ROAM_STATE_REPORT_SCAN:
2763 case eCSR_NEIGHBOR_ROAM_STATE_PREAUTHENTICATING:
2764 case eCSR_NEIGHBOR_ROAM_STATE_PREAUTH_DONE:
2765 case eCSR_NEIGHBOR_ROAM_STATE_REASSOCIATING:
2766 return (pMac->roam.neighborRoamInfo.neighborRoamState);
2767 default:
2768 return 0;
2769 }
2770}
2771
Jeff Johnson295189b2012-06-20 16:38:30 -07002772eHalStatus csrScanFlushResult(tpAniSirGlobal pMac)
2773{
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002774 tANI_U8 isFlushDenied = csrScanFlushDenied(pMac);
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302775 eHalStatus status = eHAL_STATUS_SUCCESS;
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002776 if (isFlushDenied) {
2777 smsLog(pMac, LOGW, "%s: scan flush denied in roam state %d",
2778 __func__, isFlushDenied);
2779 return eHAL_STATUS_FAILURE;
2780 }
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302781 csrLLScanPurgeResult( pMac, &pMac->scan.tempScanResults );
2782 csrLLScanPurgeResult( pMac, &pMac->scan.scanResultList );
2783 return( status );
Jeff Johnson295189b2012-06-20 16:38:30 -07002784}
2785
Mukul Sharma20aa6582014-08-07 21:36:12 +05302786eHalStatus csrScanFlushSelectiveResultForBand(tpAniSirGlobal pMac, v_BOOL_t flushP2P, tSirRFBand band)
2787{
2788 eHalStatus status = eHAL_STATUS_SUCCESS;
2789 tListElem *pEntry,*pFreeElem;
2790 tCsrScanResult *pBssDesc;
2791 tDblLinkList *pList = &pMac->scan.scanResultList;
2792
2793 csrLLLock(pList);
2794
2795 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK );
2796 while( pEntry != NULL)
2797 {
2798 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2799 if( (flushP2P == vos_mem_compare( pBssDesc->Result.ssId.ssId,
2800 "DIRECT-", 7)) &&
2801 (GetRFBand(pBssDesc->Result.BssDescriptor.channelId) == band)
2802 )
2803 {
2804 pFreeElem = pEntry;
2805 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2806 csrLLRemoveEntry(pList, pFreeElem, LL_ACCESS_NOLOCK);
2807 csrFreeScanResultEntry( pMac, pBssDesc );
2808 continue;
2809 }
2810 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2811 }
2812
2813 csrLLUnlock(pList);
2814
2815 return (status);
2816}
2817
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302818eHalStatus csrScanFlushSelectiveResult(tpAniSirGlobal pMac, v_BOOL_t flushP2P)
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002819{
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302820 eHalStatus status = eHAL_STATUS_SUCCESS;
2821 tListElem *pEntry,*pFreeElem;
2822 tCsrScanResult *pBssDesc;
2823 tDblLinkList *pList = &pMac->scan.scanResultList;
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002824
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302825 csrLLLock(pList);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002826
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302827 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK );
2828 while( pEntry != NULL)
2829 {
2830 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2831 if( flushP2P == vos_mem_compare( pBssDesc->Result.ssId.ssId,
2832 "DIRECT-", 7) )
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002833 {
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302834 pFreeElem = pEntry;
2835 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2836 csrLLRemoveEntry(pList, pFreeElem, LL_ACCESS_NOLOCK);
2837 csrFreeScanResultEntry( pMac, pBssDesc );
2838 continue;
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002839 }
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302840 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2841 }
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002842
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302843 csrLLUnlock(pList);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002844
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302845 return (status);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002846}
2847
Jeff Johnson295189b2012-06-20 16:38:30 -07002848/**
2849 * csrCheck11dChannel
2850 *
2851 *FUNCTION:
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302852 * This function is called from csrScanFilterResults function and
Jeff Johnson295189b2012-06-20 16:38:30 -07002853 * compare channel number with given channel list.
2854 *
2855 *LOGIC:
2856 * Check Scan result channel number with CFG channel list
2857 *
2858 *ASSUMPTIONS:
2859 *
2860 *
2861 *NOTE:
2862 *
2863 * @param channelId channel number
2864 * @param pChannelList Pointer to channel list
2865 * @param numChannels Number of channel in channel list
2866 *
2867 * @return Status
2868 */
2869
2870eHalStatus csrCheck11dChannel(tANI_U8 channelId, tANI_U8 *pChannelList, tANI_U32 numChannels)
2871{
2872 eHalStatus status = eHAL_STATUS_FAILURE;
2873 tANI_U8 i = 0;
2874
2875 for (i = 0; i < numChannels; i++)
2876 {
2877 if(pChannelList[ i ] == channelId)
2878 {
2879 status = eHAL_STATUS_SUCCESS;
2880 break;
2881 }
2882 }
2883 return status;
2884}
2885
2886/**
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302887 * csrScanFilterResults
Jeff Johnson295189b2012-06-20 16:38:30 -07002888 *
2889 *FUNCTION:
2890 * This function is called from csrApplyCountryInformation function and
2891 * filter scan result based on valid channel list number.
2892 *
2893 *LOGIC:
2894 * Get scan result from scan list and Check Scan result channel number
2895 * with 11d channel list if channel number is found in 11d channel list
2896 * then do not remove scan result entry from scan list
2897 *
2898 *ASSUMPTIONS:
2899 *
2900 *
2901 *NOTE:
2902 *
2903 * @param pMac Pointer to Global MAC structure
2904 *
2905 * @return Status
2906 */
2907
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302908eHalStatus csrScanFilterResults(tpAniSirGlobal pMac)
Jeff Johnson295189b2012-06-20 16:38:30 -07002909{
2910 eHalStatus status = eHAL_STATUS_SUCCESS;
2911 tListElem *pEntry,*pTempEntry;
2912 tCsrScanResult *pBssDesc;
2913 tANI_U32 len = sizeof(pMac->roam.validChannelList);
2914
2915 /* Get valid channels list from CFG */
2916 if (!HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac,
2917 pMac->roam.validChannelList, &len)))
2918 {
Agarwal Ashishe3cca2a2013-07-21 03:01:48 +05302919 smsLog( pMac, LOGE, "Failed to get Channel list from CFG");
Jeff Johnson295189b2012-06-20 16:38:30 -07002920 }
2921
2922 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
2923 while( pEntry )
2924 {
2925 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302926 pTempEntry = csrLLNext( &pMac->scan.scanResultList, pEntry,
Jeff Johnson295189b2012-06-20 16:38:30 -07002927 LL_ACCESS_LOCK );
2928 if(csrCheck11dChannel(pBssDesc->Result.BssDescriptor.channelId,
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302929 pMac->roam.validChannelList, len))
Jeff Johnson295189b2012-06-20 16:38:30 -07002930 {
2931 /* Remove Scan result which does not have 11d channel */
2932 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry,
2933 LL_ACCESS_LOCK ))
2934 {
2935 csrFreeScanResultEntry( pMac, pBssDesc );
2936 }
2937 }
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302938 pEntry = pTempEntry;
2939 }
2940
2941 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
2942 while( pEntry )
2943 {
2944 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2945 pTempEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry,
2946 LL_ACCESS_LOCK );
2947 if(csrCheck11dChannel(pBssDesc->Result.BssDescriptor.channelId,
2948 pMac->roam.validChannelList, len))
2949 {
2950 /* Remove Scan result which does not have 11d channel */
2951 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry,
2952 LL_ACCESS_LOCK ))
2953 {
2954 csrFreeScanResultEntry( pMac, pBssDesc );
2955 }
2956 }
2957 else
2958 {
2959 smsLog( pMac, LOG1, FL("%d is a Valid channel"),
2960 pBssDesc->Result.BssDescriptor.channelId);
2961 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002962 pEntry = pTempEntry;
2963 }
2964 return status;
2965}
2966
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05302967/**
2968 * csrScanFilterDFSResults
2969 *
2970 *FUNCTION:
2971 * This function filter BSSIDs on DFS channels from the scan results.
2972 *
2973 *LOGIC:
2974 * Get scan result from scan list and Check Scan result channel number
2975 * with 11d channel list if channel number is found in 11d channel list
2976 * and if fEnableDFSChnlScan is zero and if channel is DFS, then
2977 * remove scan result entry from scan list
2978 *
2979 *ASSUMPTIONS:
2980 *
2981 *NOTE:
2982 *
2983 * @param pMac Pointer to Global MAC structure
2984 *
2985 * @return Status
2986 */
2987
2988eHalStatus csrScanFilterDFSResults(tpAniSirGlobal pMac)
2989{
2990 eHalStatus status = eHAL_STATUS_SUCCESS;
2991 tListElem *pEntry,*pTempEntry;
2992 tCsrScanResult *pBssDesc;
2993
2994 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
2995 while( pEntry )
2996 {
2997 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2998 pTempEntry = csrLLNext( &pMac->scan.scanResultList, pEntry,
2999 LL_ACCESS_LOCK );
3000 if((pMac->scan.fEnableDFSChnlScan == DFS_CHNL_SCAN_DISABLED) &&
3001 CSR_IS_CHANNEL_DFS(pBssDesc->Result.BssDescriptor.channelId))
3002 {
3003 smsLog( pMac, LOG1, FL("%d is a DFS ch filtered from scan list"),
3004 pBssDesc->Result.BssDescriptor.channelId);
3005 /* Remove Scan result which does not have 11d channel */
3006 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry,
3007 LL_ACCESS_LOCK ))
3008 {
3009 csrFreeScanResultEntry( pMac, pBssDesc );
3010 }
3011 }
3012 else
3013 {
3014 smsLog( pMac, LOG1, FL("%d is a Valid channel"),
3015 pBssDesc->Result.BssDescriptor.channelId);
3016 }
3017 pEntry = pTempEntry;
3018 }
3019
3020 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
3021 while( pEntry )
3022 {
3023 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3024 pTempEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry,
3025 LL_ACCESS_LOCK );
3026
3027 if((pMac->scan.fEnableDFSChnlScan == DFS_CHNL_SCAN_DISABLED) &&
3028 CSR_IS_CHANNEL_DFS(pBssDesc->Result.BssDescriptor.channelId))
3029 {
3030 smsLog( pMac, LOG1, FL("%d is a DFS ch filtered from scan list"),
3031 pBssDesc->Result.BssDescriptor.channelId);
3032 /* Remove Scan result which does not have 11d channel */
3033 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry,
3034 LL_ACCESS_LOCK ))
3035 {
3036 csrFreeScanResultEntry( pMac, pBssDesc );
3037 }
3038 }
3039 else
3040 {
3041 smsLog( pMac, LOG1, FL("%d is a Valid channel"),
3042 pBssDesc->Result.BssDescriptor.channelId);
3043 }
3044 pEntry = pTempEntry;
3045 }
3046 return status;
3047}
3048
Jeff Johnson295189b2012-06-20 16:38:30 -07003049
3050eHalStatus csrScanCopyResultList(tpAniSirGlobal pMac, tScanResultHandle hIn, tScanResultHandle *phResult)
3051{
3052 eHalStatus status = eHAL_STATUS_SUCCESS;
3053 tScanResultList *pRetList, *pInList = (tScanResultList *)hIn;
3054 tCsrScanResult *pResult, *pScanResult;
3055 tANI_U32 count = 0;
3056 tListElem *pEntry;
3057 tANI_U32 bssLen, allocLen;
3058
3059 if(phResult)
3060 {
3061 *phResult = CSR_INVALID_SCANRESULT_HANDLE;
3062 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303063 pRetList = vos_mem_malloc(sizeof(tScanResultList));
3064 if ( NULL == pRetList )
3065 status = eHAL_STATUS_FAILURE;
3066 else
Jeff Johnson295189b2012-06-20 16:38:30 -07003067 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303068 vos_mem_set(pRetList, sizeof(tScanResultList), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003069 csrLLOpen(pMac->hHdd, &pRetList->List);
3070 pRetList->pCurEntry = NULL;
3071 csrLLLock(&pMac->scan.scanResultList);
3072 csrLLLock(&pInList->List);
3073
3074 pEntry = csrLLPeekHead( &pInList->List, LL_ACCESS_NOLOCK );
3075 while( pEntry )
3076 {
3077 pScanResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3078 bssLen = pScanResult->Result.BssDescriptor.length + sizeof(pScanResult->Result.BssDescriptor.length);
3079 allocLen = sizeof( tCsrScanResult ) + bssLen;
Kiet Lam64c1b492013-07-12 13:56:44 +05303080 pResult = vos_mem_malloc(allocLen);
3081 if ( NULL == pResult )
3082 status = eHAL_STATUS_FAILURE;
3083 else
3084 status = eHAL_STATUS_SUCCESS;
3085 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07003086 {
3087 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
3088 count = 0;
3089 break;
3090 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303091 vos_mem_set(pResult, allocLen , 0);
3092 vos_mem_copy(&pResult->Result.BssDescriptor, &pScanResult->Result.BssDescriptor, bssLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07003093 if( pScanResult->Result.pvIes )
3094 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303095 pResult->Result.pvIes = vos_mem_malloc(sizeof( tDot11fBeaconIEs ));
3096 if ( NULL == pResult->Result.pvIes )
3097 status = eHAL_STATUS_FAILURE;
3098 else
3099 status = eHAL_STATUS_SUCCESS;
3100 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07003101 {
3102 //Free the memory we allocate above first
Kiet Lam64c1b492013-07-12 13:56:44 +05303103 vos_mem_free(pResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07003104 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
3105 count = 0;
3106 break;
3107 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303108 vos_mem_copy(pResult->Result.pvIes, pScanResult->Result.pvIes,
3109 sizeof( tDot11fBeaconIEs ));
Jeff Johnson295189b2012-06-20 16:38:30 -07003110 }
3111 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_LOCK);
3112 count++;
3113 pEntry = csrLLNext( &pInList->List, pEntry, LL_ACCESS_NOLOCK );
3114 }//while
3115 csrLLUnlock(&pInList->List);
3116 csrLLUnlock(&pMac->scan.scanResultList);
3117
3118 if(HAL_STATUS_SUCCESS(status))
3119 {
3120 if(0 == count)
3121 {
3122 csrLLClose(&pRetList->List);
Kiet Lam64c1b492013-07-12 13:56:44 +05303123 vos_mem_free(pRetList);
Jeff Johnson295189b2012-06-20 16:38:30 -07003124 status = eHAL_STATUS_E_NULL_VALUE;
3125 }
3126 else if(phResult)
3127 {
3128 *phResult = pRetList;
3129 }
3130 }
3131 }//Allocated pRetList
3132
3133 return (status);
3134}
3135
3136
3137
3138eHalStatus csrScanningStateMsgProcessor( tpAniSirGlobal pMac, void *pMsgBuf )
3139{
3140 eHalStatus status = eHAL_STATUS_SUCCESS;
3141 tSirMbMsg *pMsg = (tSirMbMsg *)pMsgBuf;
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303142 tSirSmeDisConDoneInd *pDisConDoneInd;
3143 tCsrRoamInfo roamInfo = {0};
Jeff Johnson295189b2012-06-20 16:38:30 -07003144
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303145 if((eWNI_SME_SCAN_RSP == pMsg->type) ||
3146 (eWNI_SME_GET_SCANNED_CHANNEL_RSP == pMsg->type))
Jeff Johnson295189b2012-06-20 16:38:30 -07003147 {
3148 status = csrScanSmeScanResponse( pMac, pMsgBuf );
3149 }
3150 else
3151 {
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303152 switch (pMsg->type)
Jeff Johnson295189b2012-06-20 16:38:30 -07003153 {
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303154 case eWNI_SME_UPPER_LAYER_ASSOC_CNF:
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08003155 {
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303156 tCsrRoamSession *pSession;
3157 tSirSmeAssocIndToUpperLayerCnf *pUpperLayerAssocCnf;
3158 tCsrRoamInfo *pRoamInfo = NULL;
3159 tANI_U32 sessionId;
3160 eHalStatus status;
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08003161
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303162 smsLog( pMac, LOG1,
3163 FL("Scanning : ASSOCIATION confirmation can be given to upper layer "));
3164 pRoamInfo = &roamInfo;
3165 pUpperLayerAssocCnf = (tSirSmeAssocIndToUpperLayerCnf *)pMsgBuf;
3166 status = csrRoamGetSessionIdFromBSSID( pMac,
3167 (tCsrBssid *)pUpperLayerAssocCnf->bssId,
3168 &sessionId );
3169 pSession = CSR_GET_SESSION(pMac, sessionId);
3170
3171 if(!pSession)
3172 {
3173 smsLog(pMac, LOGE, FL("session %d not found "), sessionId);
3174 return eHAL_STATUS_FAILURE;
3175 }
3176
3177 //send the status code as Success
3178 pRoamInfo->statusCode = eSIR_SME_SUCCESS;
3179 pRoamInfo->u.pConnectedProfile = &pSession->connectedProfile;
3180 pRoamInfo->staId = (tANI_U8)pUpperLayerAssocCnf->aid;
3181 pRoamInfo->rsnIELen =
3182 (tANI_U8)pUpperLayerAssocCnf->rsnIE.length;
3183 pRoamInfo->prsnIE = pUpperLayerAssocCnf->rsnIE.rsnIEdata;
3184 pRoamInfo->addIELen =
3185 (tANI_U8)pUpperLayerAssocCnf->addIE.length;
3186 pRoamInfo->paddIE = pUpperLayerAssocCnf->addIE.addIEdata;
3187 vos_mem_copy(pRoamInfo->peerMac,
3188 pUpperLayerAssocCnf->peerMacAddr,
3189 sizeof(tSirMacAddr));
3190 vos_mem_copy(&pRoamInfo->bssid,
3191 pUpperLayerAssocCnf->bssId,
3192 sizeof(tCsrBssid));
3193 pRoamInfo->wmmEnabledSta = pUpperLayerAssocCnf->wmmEnabledSta;
Hardik Kantilal Patel1ba630f2014-11-21 04:32:05 +05303194#ifdef WLAN_FEATURE_AP_HT40_24G
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303195 pRoamInfo->HT40MHzIntoEnabledSta =
3196 pUpperLayerAssocCnf->HT40MHzIntoEnabledSta;
Hardik Kantilal Patel1ba630f2014-11-21 04:32:05 +05303197#endif
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303198 if(CSR_IS_INFRA_AP(pRoamInfo->u.pConnectedProfile) )
3199 {
3200 pMac->roam.roamSession[sessionId].connectState =
3201 eCSR_ASSOC_STATE_TYPE_INFRA_CONNECTED;
3202 pRoamInfo->fReassocReq = pUpperLayerAssocCnf->reassocReq;
3203 status = csrRoamCallCallback(pMac, sessionId, pRoamInfo,
3204 0, eCSR_ROAM_INFRA_IND,
3205 eCSR_ROAM_RESULT_INFRA_ASSOCIATION_CNF);
3206 }
3207 if(CSR_IS_WDS_AP( pRoamInfo->u.pConnectedProfile))
3208 {
3209 vos_sleep( 100 );
3210 pMac->roam.roamSession[sessionId].connectState =
3211 eCSR_ASSOC_STATE_TYPE_WDS_CONNECTED;//Sta
3212 status = csrRoamCallCallback(pMac, sessionId, pRoamInfo, 0,
3213 eCSR_ROAM_WDS_IND,
3214 eCSR_ROAM_RESULT_WDS_ASSOCIATION_IND);//Sta
3215 }
3216 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07003217 }
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303218 case eWNI_SME_DISCONNECT_DONE_IND:
3219 pDisConDoneInd = (tSirSmeDisConDoneInd *)(pMsg);
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08003220
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303221 smsLog( pMac, LOG1,
3222 FL("eWNI_SME_DISCONNECT_DONE_IND RC:%d"),
3223 pDisConDoneInd->reasonCode);
3224 if( CSR_IS_SESSION_VALID(pMac, pDisConDoneInd->sessionId))
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08003225 {
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303226 roamInfo.reasonCode = pDisConDoneInd->reasonCode;
3227 roamInfo.statusCode = eSIR_SME_STA_DISASSOCIATED;
3228 vos_mem_copy(roamInfo.peerMac, pDisConDoneInd->peerMacAddr,
3229 sizeof(tSirMacAddr));
3230 status = csrRoamCallCallback(pMac,
3231 pDisConDoneInd->sessionId,
3232 &roamInfo, 0,
3233 eCSR_ROAM_LOSTLINK,
3234 eCSR_ROAM_RESULT_DISASSOC_IND);
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08003235 }
3236 else
3237 {
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303238 smsLog(pMac, LOGE, FL("Inactive session %d"),
3239 pDisConDoneInd->sessionId);
3240 status = eHAL_STATUS_FAILURE;
3241 }
3242 break;
3243
3244 default :
3245 if( csrIsAnySessionInConnectState( pMac ) )
3246 {
3247 /*In case of we are connected, we need to check whether connect
3248 * status changes because scan may also run while connected.
3249 */
3250 csrRoamCheckForLinkStatusChange( pMac, (tSirSmeRsp *)pMsgBuf );
3251 }
3252 else
3253 {
3254 smsLog( pMac, LOGW,
3255 "Message [0x%04x] received in state, when expecting Scan Response",
3256 pMsg->type );
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08003257 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003258 }
3259 }
3260
3261 return (status);
3262}
3263
3264
3265
3266void csrCheckNSaveWscIe(tpAniSirGlobal pMac, tSirBssDescription *pNewBssDescr, tSirBssDescription *pOldBssDescr)
3267{
3268 int idx, len;
3269 tANI_U8 *pbIe;
3270
3271 //If failed to remove, assuming someone else got it.
3272 if((pNewBssDescr->fProbeRsp != pOldBssDescr->fProbeRsp) &&
3273 (0 == pNewBssDescr->WscIeLen))
3274 {
3275 idx = 0;
3276 len = pOldBssDescr->length - sizeof(tSirBssDescription) +
3277 sizeof(tANI_U16) + sizeof(tANI_U32) - DOT11F_IE_WSCPROBERES_MIN_LEN - 2;
3278 pbIe = (tANI_U8 *)pOldBssDescr->ieFields;
3279 //Save WPS IE if it exists
3280 pNewBssDescr->WscIeLen = 0;
3281 while(idx < len)
3282 {
3283 if((DOT11F_EID_WSCPROBERES == pbIe[0]) &&
3284 (0x00 == pbIe[2]) && (0x50 == pbIe[3]) && (0xf2 == pbIe[4]) && (0x04 == pbIe[5]))
3285 {
3286 //Founrd it
3287 if((DOT11F_IE_WSCPROBERES_MAX_LEN - 2) >= pbIe[1])
3288 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303289 vos_mem_copy(pNewBssDescr->WscIeProbeRsp, pbIe, pbIe[1] + 2);
Jeff Johnson295189b2012-06-20 16:38:30 -07003290 pNewBssDescr->WscIeLen = pbIe[1] + 2;
3291 }
3292 break;
3293 }
3294 idx += pbIe[1] + 2;
3295 pbIe += pbIe[1] + 2;
3296 }
3297 }
3298}
3299
3300
3301
3302//pIes may be NULL
3303tANI_BOOLEAN csrRemoveDupBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDescr,
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05303304 tDot11fBeaconIEs *pIes, tAniSSID *pSsid, v_TIME_t *timer, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07003305{
3306 tListElem *pEntry;
3307
3308 tCsrScanResult *pBssDesc;
3309 tANI_BOOLEAN fRC = FALSE;
3310
3311 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
3312 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
3313 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
3314 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
3315
3316 while( pEntry )
3317 {
3318 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3319
3320 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
3321 // matches
3322 if ( csrIsDuplicateBssDescription( pMac, &pBssDesc->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07003323 pSirBssDescr, pIes, fForced ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003324 {
3325 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
3326 ((tANI_S32)pBssDesc->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
3327 // Remove the 'old' entry from the list....
3328 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry, LL_ACCESS_LOCK ) )
3329 {
3330 // !we need to free the memory associated with this node
3331 //If failed to remove, assuming someone else got it.
3332 *pSsid = pBssDesc->Result.ssId;
3333 *timer = pBssDesc->Result.timer;
3334 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pBssDesc->Result.BssDescriptor);
3335
3336 csrFreeScanResultEntry( pMac, pBssDesc );
3337 }
3338 else
3339 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003340 smsLog( pMac, LOGW, FL( " fail to remove entry" ) );
Jeff Johnson295189b2012-06-20 16:38:30 -07003341 }
3342 fRC = TRUE;
3343
3344 // If we found a match, we can stop looking through the list.
3345 break;
3346 }
3347
3348 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_LOCK );
3349 }
3350
3351 return fRC;
3352}
3353
3354
3355eHalStatus csrAddPMKIDCandidateList( tpAniSirGlobal pMac, tANI_U32 sessionId,
3356 tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes )
3357{
3358 eHalStatus status = eHAL_STATUS_FAILURE;
3359 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
3360
Jeff Johnson32d95a32012-09-10 13:15:23 -07003361 if(!pSession)
3362 {
3363 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
3364 return eHAL_STATUS_FAILURE;
3365 }
3366
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003367 smsLog(pMac, LOGW, "csrAddPMKIDCandidateList called pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07003368 if( pIes )
3369 {
3370 // check if this is a RSN BSS
3371 if( pIes->RSN.present )
3372 {
3373 // Check if the BSS is capable of doing pre-authentication
3374 if( pSession->NumPmkidCandidate < CSR_MAX_PMKID_ALLOWED )
3375 {
3376
3377#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3378 {
3379 WLAN_VOS_DIAG_EVENT_DEF(secEvent, vos_event_wlan_security_payload_type);
Kiet Lam64c1b492013-07-12 13:56:44 +05303380 vos_mem_set(&secEvent, sizeof(vos_event_wlan_security_payload_type), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003381 secEvent.eventId = WLAN_SECURITY_EVENT_PMKID_CANDIDATE_FOUND;
3382 secEvent.encryptionModeMulticast =
3383 (v_U8_t)diagEncTypeFromCSRType(pSession->connectedProfile.mcEncryptionType);
3384 secEvent.encryptionModeUnicast =
3385 (v_U8_t)diagEncTypeFromCSRType(pSession->connectedProfile.EncryptionType);
Kiet Lam64c1b492013-07-12 13:56:44 +05303386 vos_mem_copy(secEvent.bssid, pSession->connectedProfile.bssid, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07003387 secEvent.authMode =
3388 (v_U8_t)diagAuthTypeFromCSRType(pSession->connectedProfile.AuthType);
3389 WLAN_VOS_DIAG_EVENT_REPORT(&secEvent, EVENT_WLAN_SECURITY);
3390 }
3391#endif//#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3392
3393 // if yes, then add to PMKIDCandidateList
Kiet Lam64c1b492013-07-12 13:56:44 +05303394 vos_mem_copy(pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].BSSID,
3395 pBssDesc->bssId, WNI_CFG_BSSID_LEN);
3396 // Bit 0 offirst byte - PreAuthentication Capability
3397 if ( (pIes->RSN.RSN_Cap[0] >> 0) & 0x1 )
Jeff Johnson295189b2012-06-20 16:38:30 -07003398 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303399 pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].preAuthSupported
3400 = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003401 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303402 else
3403 {
3404 pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].preAuthSupported
3405 = eANI_BOOLEAN_FALSE;
3406 }
3407 pSession->NumPmkidCandidate++;
Jeff Johnson295189b2012-06-20 16:38:30 -07003408 }
3409 else
3410 {
3411 status = eHAL_STATUS_FAILURE;
3412 }
3413 }
3414 }
3415
3416 return (status);
3417}
3418
3419//This function checks whether new AP is found for the current connected profile
3420//If it is found, it return the sessionId, else it return invalid sessionID
3421tANI_U32 csrProcessBSSDescForPMKIDList(tpAniSirGlobal pMac,
3422 tSirBssDescription *pBssDesc,
3423 tDot11fBeaconIEs *pIes)
3424{
3425 tANI_U32 i, bRet = CSR_SESSION_ID_INVALID;
3426 tCsrRoamSession *pSession;
3427 tDot11fBeaconIEs *pIesLocal = pIes;
3428
3429 if( pIesLocal || HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIesLocal)) )
3430 {
3431 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
3432 {
3433 if( CSR_IS_SESSION_VALID( pMac, i ) )
3434 {
3435 pSession = CSR_GET_SESSION( pMac, i );
3436 if( csrIsConnStateConnectedInfra( pMac, i ) &&
3437 ( eCSR_AUTH_TYPE_RSN == pSession->connectedProfile.AuthType ) )
3438 {
3439 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile, pBssDesc, pIesLocal))
3440 {
3441 //this new BSS fits the current profile connected
3442 if(HAL_STATUS_SUCCESS(csrAddPMKIDCandidateList(pMac, i, pBssDesc, pIesLocal)))
3443 {
3444 bRet = i;
3445 }
3446 break;
3447 }
3448 }
3449 }
3450 }
3451 if( !pIes )
3452 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303453 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003454 }
3455 }
3456
3457 return (tANI_U8)bRet;
3458}
3459
3460#ifdef FEATURE_WLAN_WAPI
3461eHalStatus csrAddBKIDCandidateList( tpAniSirGlobal pMac, tANI_U32 sessionId,
3462 tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes )
3463{
3464 eHalStatus status = eHAL_STATUS_FAILURE;
3465 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
3466
Jeff Johnson32d95a32012-09-10 13:15:23 -07003467 if(!pSession)
3468 {
3469 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
3470 return eHAL_STATUS_FAILURE;
3471 }
3472
Kiet Lam64c1b492013-07-12 13:56:44 +05303473 smsLog(pMac, LOGW, "csrAddBKIDCandidateList called pMac->scan.NumBkidCandidate = %d",
3474 pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07003475 if( pIes )
3476 {
3477 // check if this is a WAPI BSS
3478 if( pIes->WAPI.present )
3479 {
3480 // Check if the BSS is capable of doing pre-authentication
3481 if( pSession->NumBkidCandidate < CSR_MAX_BKID_ALLOWED )
3482 {
3483
3484 // if yes, then add to BKIDCandidateList
Kiet Lam64c1b492013-07-12 13:56:44 +05303485 vos_mem_copy(pSession->BkidCandidateInfo[pSession->NumBkidCandidate].BSSID,
3486 pBssDesc->bssId, WNI_CFG_BSSID_LEN);
3487 if ( pIes->WAPI.preauth )
Jeff Johnson295189b2012-06-20 16:38:30 -07003488 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303489 pSession->BkidCandidateInfo[pSession->NumBkidCandidate].preAuthSupported
3490 = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003491 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303492 else
3493 {
3494 pSession->BkidCandidateInfo[pSession->NumBkidCandidate].preAuthSupported
3495 = eANI_BOOLEAN_FALSE;
3496 }
3497 pSession->NumBkidCandidate++;
Jeff Johnson295189b2012-06-20 16:38:30 -07003498 }
3499 else
3500 {
3501 status = eHAL_STATUS_FAILURE;
3502 }
3503 }
3504 }
3505
3506 return (status);
3507}
3508
3509//This function checks whether new AP is found for the current connected profile
3510//if so add to BKIDCandidateList
3511tANI_BOOLEAN csrProcessBSSDescForBKIDList(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
3512 tDot11fBeaconIEs *pIes)
3513{
3514 tANI_BOOLEAN fRC = FALSE;
3515 tDot11fBeaconIEs *pIesLocal = pIes;
3516 tANI_U32 sessionId;
3517 tCsrRoamSession *pSession;
3518
3519 if( pIesLocal || HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIesLocal)) )
3520 {
3521 for( sessionId = 0; sessionId < CSR_ROAM_SESSION_MAX; sessionId++ )
3522 {
3523 if( CSR_IS_SESSION_VALID( pMac, sessionId) )
3524 {
3525 pSession = CSR_GET_SESSION( pMac, sessionId );
3526 if( csrIsConnStateConnectedInfra( pMac, sessionId ) &&
3527 eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE == pSession->connectedProfile.AuthType)
3528 {
3529 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile,pBssDesc, pIesLocal))
3530 {
3531 //this new BSS fits the current profile connected
3532 if(HAL_STATUS_SUCCESS(csrAddBKIDCandidateList(pMac, sessionId, pBssDesc, pIesLocal)))
3533 {
3534 fRC = TRUE;
3535 }
3536 }
3537 }
3538 }
3539 }
3540 if(!pIes)
3541 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303542 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003543 }
3544
3545 }
3546 return fRC;
3547}
3548
3549#endif
3550
3551
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07003552static void csrMoveTempScanResultsToMainList( tpAniSirGlobal pMac, tANI_U8 reason )
Jeff Johnson295189b2012-06-20 16:38:30 -07003553{
3554 tListElem *pEntry;
3555 tCsrScanResult *pBssDescription;
Jeff Johnson295189b2012-06-20 16:38:30 -07003556 tANI_BOOLEAN fDupBss;
3557#ifdef FEATURE_WLAN_WAPI
3558 tANI_BOOLEAN fNewWapiBSSForCurConnection = eANI_BOOLEAN_FALSE;
3559#endif /* FEATURE_WLAN_WAPI */
3560 tDot11fBeaconIEs *pIesLocal = NULL;
3561 tANI_U32 sessionId = CSR_SESSION_ID_INVALID;
3562 tAniSSID tmpSsid;
3563 v_TIME_t timer=0;
3564
3565 tmpSsid.length = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07003566
3567 // remove the BSS descriptions from temporary list
3568 while( ( pEntry = csrLLRemoveTail( &pMac->scan.tempScanResults, LL_ACCESS_LOCK ) ) != NULL)
3569 {
3570 pBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3571
Vinay Krishna Eranna566365f2015-03-09 12:34:13 +05303572 smsLog( pMac, LOG2, "...Bssid= "MAC_ADDRESS_STR" chan= %d, rssi = -%d",
Arif Hussain24bafea2013-11-15 15:10:03 -08003573 MAC_ADDR_ARRAY(pBssDescription->Result.BssDescriptor.bssId),
Jeff Johnson295189b2012-06-20 16:38:30 -07003574 pBssDescription->Result.BssDescriptor.channelId,
3575 pBssDescription->Result.BssDescriptor.rssi * (-1) );
3576
3577 //At this time, pBssDescription->Result.pvIes may be NULL
3578 pIesLocal = (tDot11fBeaconIEs *)( pBssDescription->Result.pvIes );
3579 if( !pIesLocal && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pBssDescription->Result.BssDescriptor, &pIesLocal))) )
3580 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003581 smsLog(pMac, LOGE, FL(" Cannot pared IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003582 csrFreeScanResultEntry(pMac, pBssDescription);
3583 continue;
3584 }
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05303585 fDupBss = csrRemoveDupBssDescription( pMac, &pBssDescription->Result.BssDescriptor, pIesLocal, &tmpSsid, &timer, FALSE );
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07003586 //Check whether we have reach out limit, but don't lose the LFR candidates came from FW
3587 if( CSR_SCAN_IS_OVER_BSS_LIMIT(pMac)
3588#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
3589 && !( eCsrScanGetLfrResult == reason )
3590#endif
3591 )
Jeff Johnson295189b2012-06-20 16:38:30 -07003592 {
Deepthi Gowri50e2fa52016-03-17 15:30:53 +05303593 smsLog(pMac, LOG1, FL("########## BSS Limit reached ###########"));
3594 csrPurgeOldScanResults(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07003595 }
3596 // check for duplicate scan results
3597 if ( !fDupBss )
3598 {
3599 //Found a new BSS
3600 sessionId = csrProcessBSSDescForPMKIDList(pMac,
3601 &pBssDescription->Result.BssDescriptor, pIesLocal);
3602 if( CSR_SESSION_ID_INVALID != sessionId)
3603 {
3604 csrRoamCallCallback(pMac, sessionId, NULL, 0,
3605 eCSR_ROAM_SCAN_FOUND_NEW_BSS, eCSR_ROAM_RESULT_NONE);
3606 }
3607 }
3608 else
3609 {
3610 //Check if the new one has SSID it it, if not, use the older SSID if it exists.
3611 if( (0 == pBssDescription->Result.ssId.length) && tmpSsid.length )
3612 {
3613 //New BSS has a hidden SSID and old one has the SSID. Keep the SSID only
3614 //if diff of saved SSID time and current time is less than 1 min to avoid
3615 //side effect of saving SSID with old one is that if AP changes its SSID while remain
3616 //hidden, we may never see it and also to address the requirement of
3617 //When we remove hidden ssid from the profile i.e., forget the SSID via
3618 // GUI that SSID shouldn't see in the profile
3619 if( (vos_timer_get_system_time() - timer) <= HIDDEN_TIMER)
3620 {
3621 pBssDescription->Result.timer = timer;
3622 pBssDescription->Result.ssId = tmpSsid;
3623 }
3624 }
3625 }
3626
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303627 //Find a good AP for 11d info
3628 if ( csrIs11dSupported( pMac ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003629 {
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303630 // check if country information element is present
3631 if (pIesLocal->Country.present)
Jeff Johnson295189b2012-06-20 16:38:30 -07003632 {
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303633 csrAddVoteForCountryInfo(pMac, pIesLocal->Country.country);
3634 smsLog(pMac, LOGW, FL("11d AP Bssid " MAC_ADDRESS_STR
3635 " chan= %d, rssi = -%d, countryCode %c%c"),
3636 MAC_ADDR_ARRAY( pBssDescription->Result.BssDescriptor.bssId),
3637 pBssDescription->Result.BssDescriptor.channelId,
3638 pBssDescription->Result.BssDescriptor.rssi * (-1),
3639 pIesLocal->Country.country[0],pIesLocal->Country.country[1] );
3640 }
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303641
Jeff Johnson295189b2012-06-20 16:38:30 -07003642 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08003643
Jeff Johnson295189b2012-06-20 16:38:30 -07003644 // append to main list
3645 csrScanAddResult(pMac, pBssDescription, pIesLocal);
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303646 if ( (pBssDescription->Result.pvIes == NULL) && pIesLocal )
Jeff Johnson295189b2012-06-20 16:38:30 -07003647 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303648 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003649 }
3650 }
3651
Sushant Kaushik6274de62015-05-01 16:31:23 +05303652 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
Tushnim Bhattacharyyaae317772013-10-23 18:55:38 -07003653 //we don't need to update CC while connected to an AP which is advertising CC already
3654 if (csrIs11dSupported(pMac))
3655 {
3656 tANI_U32 i;
3657 tCsrRoamSession *pSession;
3658
3659 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
3660 {
3661 if (CSR_IS_SESSION_VALID( pMac, i ) )
3662 {
3663 pSession = CSR_GET_SESSION( pMac, i );
3664 if (csrIsConnStateConnected(pMac, i))
3665 {
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303666 smsLog(pMac, LOGW, FL("No need for updating CC in"
3667 "connected state"));
3668 goto end;
Tushnim Bhattacharyyaae317772013-10-23 18:55:38 -07003669 }
3670 }
3671 }
Agrawal Ashishbd3a5932016-04-12 16:22:39 +05303672 if (csrElectedCountryInfo(pMac))
3673 csrLearnCountryInformation(pMac, NULL, NULL,
3674 eANI_BOOLEAN_TRUE);
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303675 }
3676
Tushnim Bhattacharyyaae317772013-10-23 18:55:38 -07003677end:
3678 //If we can find the current 11d info in any of the scan results, or
Jeff Johnson295189b2012-06-20 16:38:30 -07003679 // a good enough AP with the 11d info from the scan results then no need to
3680 // get into ambiguous state
3681 if(pMac->scan.fAmbiguous11dInfoFound)
3682 {
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303683 if((pMac->scan.fCurrent11dInfoMatch))
Jeff Johnson295189b2012-06-20 16:38:30 -07003684 {
3685 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
3686 }
3687 }
3688
3689#ifdef FEATURE_WLAN_WAPI
3690 if(fNewWapiBSSForCurConnection)
3691 {
3692 //remember it first
3693 csrRoamCallCallback(pMac, sessionId, NULL, 0, eCSR_ROAM_SCAN_FOUND_NEW_BSS, eCSR_ROAM_RESULT_NEW_WAPI_BSS);
3694 }
3695#endif /* FEATURE_WLAN_WAPI */
3696
3697 return;
3698}
3699
Deepthi Gowri50e2fa52016-03-17 15:30:53 +05303700void csrPurgeOldScanResults(tpAniSirGlobal pMac)
3701{
3702 tListElem *pEntry, *tmpEntry;
3703 tCsrScanResult *pResult, *oldest_bss = NULL;
Deepthi Gowri4480a3f2016-05-18 19:30:17 +05303704 v_TIME_t oldest_entry = 0;
3705 v_TIME_t curTime = vos_timer_get_system_time();
Deepthi Gowri50e2fa52016-03-17 15:30:53 +05303706
3707 csrLLLock(&pMac->scan.scanResultList);
3708 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
3709 while( pEntry )
3710 {
3711 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry,
3712 LL_ACCESS_NOLOCK);
3713 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3714 if((curTime -
3715 pResult->Result.BssDescriptor.nReceivedTime) > oldest_entry)
3716 {
3717 oldest_entry = curTime -
3718 pResult->Result.BssDescriptor.nReceivedTime;
3719 oldest_bss = pResult;
3720 }
3721 pEntry = tmpEntry;
3722 }
3723 if (oldest_bss)
3724 {
3725 //Free the old BSS Entries
3726 if( csrLLRemoveEntry(&pMac->scan.scanResultList,
3727 &oldest_bss->Link, LL_ACCESS_NOLOCK) )
3728 {
Deepthi Gowri6a08e312016-03-31 19:10:14 +05303729 smsLog(pMac, LOG1, FL(" Current time delta (%lu) of BSSID to be removed" MAC_ADDRESS_STR ),
Deepthi Gowri50e2fa52016-03-17 15:30:53 +05303730 (curTime - oldest_bss->Result.BssDescriptor.nReceivedTime),
3731 MAC_ADDR_ARRAY(oldest_bss->Result.BssDescriptor.bssId));
3732 csrFreeScanResultEntry(pMac, oldest_bss);
3733 }
3734 }
3735 csrLLUnlock(&pMac->scan.scanResultList);
3736}
Jeff Johnson295189b2012-06-20 16:38:30 -07003737
3738static tCsrScanResult *csrScanSaveBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pBSSDescription,
3739 tDot11fBeaconIEs *pIes)
3740{
3741 tCsrScanResult *pCsrBssDescription = NULL;
3742 tANI_U32 cbBSSDesc;
3743 tANI_U32 cbAllocated;
Sushant Kaushik6274de62015-05-01 16:31:23 +05303744 tListElem *pEntry;
Jeff Johnson295189b2012-06-20 16:38:30 -07003745
3746 // figure out how big the BSS description is (the BSSDesc->length does NOT
3747 // include the size of the length field itself).
3748 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
3749
3750 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
3751
Kiet Lam64c1b492013-07-12 13:56:44 +05303752 pCsrBssDescription = vos_mem_malloc(cbAllocated);
3753 if ( NULL != pCsrBssDescription )
Jeff Johnson295189b2012-06-20 16:38:30 -07003754 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303755 vos_mem_set(pCsrBssDescription, cbAllocated, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003756 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Kiet Lam64c1b492013-07-12 13:56:44 +05303757 vos_mem_copy(&pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc);
Jeff Johnson295189b2012-06-20 16:38:30 -07003758#if defined(VOSS_ENSBALED)
3759 VOS_ASSERT( pCsrBssDescription->Result.pvIes == NULL );
3760#endif
3761 csrScanAddResult(pMac, pCsrBssDescription, pIes);
Sushant Kaushik6274de62015-05-01 16:31:23 +05303762 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
Jeff Johnson295189b2012-06-20 16:38:30 -07003763 }
3764
3765 return( pCsrBssDescription );
3766}
3767
3768// Append a Bss Description...
3769tCsrScanResult *csrScanAppendBssDescription( tpAniSirGlobal pMac,
3770 tSirBssDescription *pSirBssDescription,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07003771 tDot11fBeaconIEs *pIes, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07003772{
3773 tCsrScanResult *pCsrBssDescription = NULL;
3774 tAniSSID tmpSsid;
3775 v_TIME_t timer = 0;
3776 int result;
3777
3778 tmpSsid.length = 0;
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07003779 result = csrRemoveDupBssDescription( pMac, pSirBssDescription, pIes, &tmpSsid, &timer, fForced );
Jeff Johnson295189b2012-06-20 16:38:30 -07003780 pCsrBssDescription = csrScanSaveBssDescription( pMac, pSirBssDescription, pIes );
3781 if (result && (pCsrBssDescription != NULL))
3782 {
3783 //Check if the new one has SSID it it, if not, use the older SSID if it exists.
3784 if( (0 == pCsrBssDescription->Result.ssId.length) && tmpSsid.length )
3785 {
3786 //New BSS has a hidden SSID and old one has the SSID. Keep the SSID only
3787 //if diff of saved SSID time and current time is less than 1 min to avoid
3788 //side effect of saving SSID with old one is that if AP changes its SSID while remain
3789 //hidden, we may never see it and also to address the requirement of
3790 //When we remove hidden ssid from the profile i.e., forget the SSID via
3791 // GUI that SSID shouldn't see in the profile
3792 if((vos_timer_get_system_time()-timer) <= HIDDEN_TIMER)
3793 {
3794 pCsrBssDescription->Result.ssId = tmpSsid;
3795 pCsrBssDescription->Result.timer = timer;
3796 }
3797 }
3798 }
3799
3800
3801 return( pCsrBssDescription );
3802}
3803
3804
3805
3806void csrPurgeChannelPower( tpAniSirGlobal pMac, tDblLinkList *pChannelList )
3807{
3808 tCsrChannelPowerInfo *pChannelSet;
3809 tListElem *pEntry;
3810
3811 csrLLLock(pChannelList);
3812 // Remove the channel sets from the learned list and put them in the free list
3813 while( ( pEntry = csrLLRemoveHead( pChannelList, LL_ACCESS_NOLOCK ) ) != NULL)
3814 {
3815 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3816 if( pChannelSet )
3817 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303818 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003819 }
3820 }
3821 csrLLUnlock(pChannelList);
3822 return;
3823}
3824
3825
3826/*
3827 * Save the channelList into the ultimate storage as the final stage of channel
3828 * Input: pCountryInfo -- the country code (e.g. "USI"), channel list, and power limit are all stored inside this data structure
3829 */
Jeff Johnsone7245742012-09-05 17:12:55 -07003830eHalStatus csrSaveToChannelPower2G_5G( tpAniSirGlobal pMac, tANI_U32 tableSize, tSirMacChanInfo *channelTable )
Jeff Johnson295189b2012-06-20 16:38:30 -07003831{
3832 tANI_U32 i = tableSize / sizeof( tSirMacChanInfo );
3833 tSirMacChanInfo *pChannelInfo;
3834 tCsrChannelPowerInfo *pChannelSet;
3835 tANI_BOOLEAN f2GHzInfoFound = FALSE;
3836 tANI_BOOLEAN f2GListPurged = FALSE, f5GListPurged = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003837
3838 pChannelInfo = channelTable;
3839 // atleast 3 bytes have to be remaining -- from "countryString"
3840 while ( i-- )
3841 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303842 pChannelSet = vos_mem_malloc(sizeof(tCsrChannelPowerInfo));
3843 if ( NULL != pChannelSet )
Jeff Johnson295189b2012-06-20 16:38:30 -07003844 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303845 vos_mem_set(pChannelSet, sizeof(tCsrChannelPowerInfo), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003846 pChannelSet->firstChannel = pChannelInfo->firstChanNum;
3847 pChannelSet->numChannels = pChannelInfo->numChannels;
3848
3849 // Now set the inter-channel offset based on the frequency band the channel set lies in
Jeff Johnsone7245742012-09-05 17:12:55 -07003850 if( (CSR_IS_CHANNEL_24GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003851 ((pChannelSet->firstChannel + (pChannelSet->numChannels - 1)) <= CSR_MAX_24GHz_CHANNEL_NUMBER) )
Jeff Johnsone7245742012-09-05 17:12:55 -07003852
Jeff Johnson295189b2012-06-20 16:38:30 -07003853 {
3854 pChannelSet->interChannelOffset = 1;
3855 f2GHzInfoFound = TRUE;
3856 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003857 else if ( (CSR_IS_CHANNEL_5GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003858 ((pChannelSet->firstChannel + ((pChannelSet->numChannels - 1) * 4)) <= CSR_MAX_5GHz_CHANNEL_NUMBER) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003859 {
3860 pChannelSet->interChannelOffset = 4;
3861 f2GHzInfoFound = FALSE;
3862 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003863 else
3864 {
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003865 smsLog( pMac, LOGW, FL("Invalid Channel %d Present in Country IE"),
Jeff Johnsone7245742012-09-05 17:12:55 -07003866 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303867 vos_mem_free(pChannelSet);
Jeff Johnsone7245742012-09-05 17:12:55 -07003868 return eHAL_STATUS_FAILURE;
3869 }
3870
Jeff Johnson295189b2012-06-20 16:38:30 -07003871 pChannelSet->txPower = CSR_ROAM_MIN( pChannelInfo->maxTxPower, pMac->roam.configParam.nTxPowerCap );
3872
3873 if( f2GHzInfoFound )
3874 {
3875 if( !f2GListPurged )
3876 {
3877 // purge previous results if found new
3878 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList24 );
3879 f2GListPurged = TRUE;
3880 }
3881
3882 if(CSR_IS_OPERATING_BG_BAND(pMac))
3883 {
3884 // add to the list of 2.4 GHz channel sets
3885 csrLLInsertTail( &pMac->scan.channelPowerInfoList24, &pChannelSet->link, LL_ACCESS_LOCK );
3886 }
3887 else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003888 smsLog( pMac, LOGW, FL("Adding 11B/G channels in 11A mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003889 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303890 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003891 }
3892 }
3893 else
3894 {
3895 // 5GHz info found
3896 if( !f5GListPurged )
3897 {
3898 // purge previous results if found new
3899 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList5G );
3900 f5GListPurged = TRUE;
3901 }
3902
3903 if(CSR_IS_OPERATING_A_BAND(pMac))
3904 {
3905 // add to the list of 5GHz channel sets
3906 csrLLInsertTail( &pMac->scan.channelPowerInfoList5G, &pChannelSet->link, LL_ACCESS_LOCK );
3907 }
3908 else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003909 smsLog( pMac, LOGW, FL("Adding 11A channels in B/G mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003910 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303911 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003912 }
3913 }
3914 }
3915
3916 pChannelInfo++; // move to next entry
3917 }
3918
Jeff Johnsone7245742012-09-05 17:12:55 -07003919 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07003920}
3921
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303922static void csrClearDfsChannelList( tpAniSirGlobal pMac )
3923{
3924 tSirMbMsg *pMsg;
3925 tANI_U16 msgLen;
Jeff Johnson295189b2012-06-20 16:38:30 -07003926
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303927 msgLen = (tANI_U16)(sizeof( tSirMbMsg ));
Kiet Lam64c1b492013-07-12 13:56:44 +05303928 pMsg = vos_mem_malloc(msgLen);
3929 if ( NULL != pMsg )
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303930 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303931 vos_mem_set((void *)pMsg, msgLen, 0);
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303932 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_CLEAR_DFS_CHANNEL_LIST);
3933 pMsg->msgLen = pal_cpu_to_be16(msgLen);
3934 palSendMBMessage(pMac->hHdd, pMsg);
3935 }
3936}
Jeff Johnson295189b2012-06-20 16:38:30 -07003937
3938void csrApplyPower2Current( tpAniSirGlobal pMac )
3939{
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003940 smsLog( pMac, LOG3, FL(" Updating Cfg with power settings"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003941 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList24, WNI_CFG_MAX_TX_POWER_2_4 );
3942 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList5G, WNI_CFG_MAX_TX_POWER_5 );
3943}
3944
3945
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003946void csrApplyChannelPowerCountryInfo( tpAniSirGlobal pMac, tCsrChannel *pChannelList, tANI_U8 *countryCode, tANI_BOOLEAN updateRiva)
Jeff Johnson295189b2012-06-20 16:38:30 -07003947{
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303948 int i, j, count, countryIndex = -1;
Jeff Johnson295189b2012-06-20 16:38:30 -07003949 tANI_U8 numChannels = 0;
3950 tANI_U8 tempNumChannels = 0;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303951 tANI_U8 channelIgnore = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003952 tCsrChannel ChannelList;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303953
Jeff Johnson295189b2012-06-20 16:38:30 -07003954 if( pChannelList->numChannels )
3955 {
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303956 for(count=0; count < MAX_COUNTRY_IGNORE; count++)
3957 {
3958 if(vos_mem_compare(countryCode, countryIgnoreList[count].countryCode,
3959 VOS_COUNTRY_CODE_LEN))
3960 {
3961 countryIndex = count;
3962 break;
3963 }
3964 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003965 tempNumChannels = CSR_MIN(pChannelList->numChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN);
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05303966
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303967 for(i=0; i < tempNumChannels; i++)
Jeff Johnson295189b2012-06-20 16:38:30 -07003968 {
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303969 channelIgnore = FALSE;
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05303970 if( countryIndex != -1 )
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303971 {
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05303972 for(j=0; j < countryIgnoreList[countryIndex].channelCount; j++)
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303973 {
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05303974 if( pChannelList->channelList[i] ==
3975 countryIgnoreList[countryIndex].channelList[j] )
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303976 {
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05303977 channelIgnore = TRUE;
3978 break;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303979 }
3980 }
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05303981 }
3982 if( FALSE == channelIgnore )
3983 {
3984 ChannelList.channelList[numChannels] = pChannelList->channelList[i];
3985 numChannels++;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303986 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003987 }
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303988 ChannelList.numChannels = numChannels;
Mahesh A Saptasagar1ed59582014-06-04 18:45:07 +05303989 csrApplyPower2Current( pMac ); // Store the channel+power info in the global place: Cfg
Jeff Johnson295189b2012-06-20 16:38:30 -07003990 csrSetCfgValidChannelList(pMac, ChannelList.channelList, ChannelList.numChannels);
3991 // extend scan capability
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303992 // build a scan list based on the channel list : channel# + active/passive scan
3993 csrSetCfgScanControlList(pMac, countryCode, &ChannelList);
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303994 /*Send msg to Lim to clear DFS channel list */
3995 csrClearDfsChannelList(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07003996#ifdef FEATURE_WLAN_SCAN_PNO
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003997 if (updateRiva)
3998 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003999 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO, FL(" Sending 11d PNO info to Riva"));
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004000 // Send HAL UpdateScanParams message
4001 pmcUpdateScanParams(pMac, &(pMac->roam.configParam), &ChannelList, TRUE);
4002 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004003#endif // FEATURE_WLAN_SCAN_PNO
4004 }
4005 else
4006 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004007 smsLog( pMac, LOGE, FL(" 11D channel list is empty"));
Jeff Johnson295189b2012-06-20 16:38:30 -07004008 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004009 csrSetCfgCountryCode(pMac, countryCode);
4010}
4011
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004012void csrResetCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce, tANI_BOOLEAN updateRiva )
Jeff Johnson295189b2012-06-20 16:38:30 -07004013{
4014 if( fForce || (csrIs11dSupported( pMac ) && (!pMac->scan.f11dInfoReset)))
4015 {
4016
4017#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4018 {
4019 vos_log_802_11d_pkt_type *p11dLog;
4020 int Index;
4021
4022 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
4023 if(p11dLog)
4024 {
4025 p11dLog->eventId = WLAN_80211D_EVENT_RESET;
Kiet Lam64c1b492013-07-12 13:56:44 +05304026 vos_mem_copy(p11dLog->countryCode, pMac->scan.countryCodeCurrent, 3);
Jeff Johnson295189b2012-06-20 16:38:30 -07004027 p11dLog->numChannel = pMac->scan.base20MHzChannels.numChannels;
4028 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
4029 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304030 vos_mem_copy(p11dLog->Channels,
4031 pMac->scan.base20MHzChannels.channelList,
4032 p11dLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07004033 for (Index=0; Index < pMac->scan.base20MHzChannels.numChannels; Index++)
4034 {
4035 p11dLog->TxPwr[Index] = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
4036 }
4037 }
4038 if(!pMac->roam.configParam.Is11dSupportEnabled)
4039 {
4040 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
4041 }
4042 else if(pMac->roam.configParam.fEnforceDefaultDomain)
4043 {
4044 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
4045 }
4046 else
4047 {
4048 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
4049 }
4050 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
4051 }
4052 }
4053#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4054
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004055 csrPruneChannelListForMode(pMac, &pMac->scan.baseChannels);
4056 csrPruneChannelListForMode(pMac, &pMac->scan.base20MHzChannels);
4057
Jeff Johnson295189b2012-06-20 16:38:30 -07004058 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_FALSE);
4059 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_TRUE);
4060 // ... and apply the channel list, power settings, and the country code.
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004061 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.base20MHzChannels, pMac->scan.countryCodeCurrent, updateRiva );
Jeff Johnson295189b2012-06-20 16:38:30 -07004062 // clear the 11d channel list
Kiet Lam64c1b492013-07-12 13:56:44 +05304063 vos_mem_set(&pMac->scan.channels11d, sizeof(pMac->scan.channels11d), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004064 pMac->scan.f11dInfoReset = eANI_BOOLEAN_TRUE;
4065 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_FALSE;
4066 }
4067
4068 return;
4069}
4070
4071
4072eHalStatus csrResetCountryCodeInformation(tpAniSirGlobal pMac, tANI_BOOLEAN *pfRestartNeeded)
4073{
4074 eHalStatus status = eHAL_STATUS_SUCCESS;
4075 tANI_BOOLEAN fRestart = eANI_BOOLEAN_FALSE;
4076
4077 //Use the Country code and domain from EEPROM
Kiet Lam64c1b492013-07-12 13:56:44 +05304078 vos_mem_copy(pMac->scan.countryCodeCurrent, pMac->scan.countryCodeDefault,
4079 WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07004080 csrSetRegulatoryDomain(pMac, pMac->scan.domainIdCurrent, &fRestart);
Jeff Johnson43971f52012-07-17 12:26:56 -07004081 if( ((eANI_BOOLEAN_FALSE == fRestart) || (pfRestartNeeded == NULL) )
4082 && !csrIsInfraConnected(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -07004083 {
4084 //Only reset the country info if we don't need to restart
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004085 csrResetCountryInformation(pMac, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07004086 }
4087 if(pfRestartNeeded)
4088 {
4089 *pfRestartNeeded = fRestart;
4090 }
4091
4092 return (status);
4093}
4094
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05304095void csrClearVotesForCountryInfo(tpAniSirGlobal pMac)
4096{
4097 pMac->scan.countryCodeCount = 0;
4098 vos_mem_set(pMac->scan.votes11d,
4099 sizeof(tCsrVotes11d) * CSR_MAX_NUM_COUNTRY_CODE, 0);
4100}
4101
4102void csrAddVoteForCountryInfo(tpAniSirGlobal pMac, tANI_U8 *pCountryCode)
4103{
4104 tANI_BOOLEAN match = FALSE;
4105 tANI_U8 i;
4106
4107 /* convert to UPPER here so we are assured
4108 * the strings are always in upper case.
4109 */
4110 for( i = 0; i < 3; i++ )
4111 {
4112 pCountryCode[ i ] = (tANI_U8)csrToUpper( pCountryCode[ i ] );
4113 }
4114
4115 /* Some of the 'old' Cisco 350 series AP's advertise NA as the
4116 * country code (for North America ??). NA is not a valid country code
4117 * or domain so let's allow this by changing it to the proper
4118 * country code (which is US). We've also seen some NETGEAR AP's
4119 * that have "XX " as the country code with valid 2.4 GHz US channel
4120 * information. If we cannot find the country code advertised in the
4121 * 11d information element, let's default to US.
4122 */
4123
4124 if ( !HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry( pMac,
4125 pCountryCode, NULL,COUNTRY_QUERY ) ) )
4126 {
4127 pCountryCode[ 0 ] = '0';
4128 pCountryCode[ 1 ] = '0';
4129 }
4130
4131 /* We've seen some of the AP's improperly put a 0 for the
4132 * third character of the country code. spec says valid charcters are
4133 * 'O' (for outdoor), 'I' for Indoor, or ' ' (space; for either).
4134 * if we see a 0 in this third character, let's change it to a ' '.
4135 */
4136 if ( 0 == pCountryCode[ 2 ] )
4137 {
4138 pCountryCode[ 2 ] = ' ';
4139 }
4140
4141 for (i = 0; i < pMac->scan.countryCodeCount; i++)
4142 {
4143 match = (vos_mem_compare(pMac->scan.votes11d[i].countryCode,
4144 pCountryCode, 2));
4145 if(match)
4146 {
4147 break;
4148 }
4149 }
4150
4151 if (match)
4152 {
4153 pMac->scan.votes11d[i].votes++;
4154 }
4155 else
4156 {
4157 vos_mem_copy( pMac->scan.votes11d[pMac->scan.countryCodeCount].countryCode,
4158 pCountryCode, 3 );
4159 pMac->scan.votes11d[pMac->scan.countryCodeCount].votes = 1;
4160 pMac->scan.countryCodeCount++;
4161 }
4162
4163 return;
4164}
4165
4166tANI_BOOLEAN csrElectedCountryInfo(tpAniSirGlobal pMac)
4167{
4168 tANI_BOOLEAN fRet = FALSE;
4169 tANI_U8 maxVotes = 0;
4170 tANI_U8 i, j=0;
4171
4172 if (!pMac->scan.countryCodeCount)
4173 {
Agrawal Ashishbd3a5932016-04-12 16:22:39 +05304174 VOS_TRACE( VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_WARN,
4175 "No AP with 11d Country code is present in scan list");
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05304176 return fRet;
4177 }
4178 maxVotes = pMac->scan.votes11d[0].votes;
4179 fRet = TRUE;
4180
4181 for(i = 1; i < pMac->scan.countryCodeCount; i++)
4182 {
4183 /* If we have a tie for max votes for 2 different country codes,
4184 * pick random.we can put some more intelligence - TBD
4185 */
4186 if (maxVotes < pMac->scan.votes11d[i].votes)
4187 {
4188 VOS_TRACE( VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
4189 " Votes for Country %c%c : %d\n",
4190 pMac->scan.votes11d[i].countryCode[0],
4191 pMac->scan.votes11d[i].countryCode[1],
4192 pMac->scan.votes11d[i].votes);
4193
4194 maxVotes = pMac->scan.votes11d[i].votes;
4195 j = i;
4196 fRet = TRUE;
4197 }
4198
4199 }
4200 if (fRet)
4201 {
Rajesh Babu Prathipati20cdffa2014-07-01 22:24:59 +05304202 vos_mem_copy(pMac->scan.countryCodeElected,
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05304203 pMac->scan.votes11d[j].countryCode, WNI_CFG_COUNTRY_CODE_LEN);
Rajesh Babu Prathipati20cdffa2014-07-01 22:24:59 +05304204 vos_mem_copy(pMac->scan.countryCode11d,
Agarwal Ashish852b2c32014-05-23 17:13:25 +05304205 pMac->scan.votes11d[j].countryCode, WNI_CFG_COUNTRY_CODE_LEN);
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05304206 VOS_TRACE( VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
4207 "Selected Country is %c%c With count %d\n",
4208 pMac->scan.votes11d[j].countryCode[0],
4209 pMac->scan.votes11d[j].countryCode[1],
4210 pMac->scan.votes11d[j].votes);
4211 }
4212 return fRet;
4213}
Jeff Johnson295189b2012-06-20 16:38:30 -07004214
4215eHalStatus csrSetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pCountry, tANI_BOOLEAN *pfRestartNeeded)
4216{
4217 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
4218 v_REGDOMAIN_t domainId;
4219
4220 if(pCountry)
4221 {
Kiet Lam6c583332013-10-14 05:37:09 +05304222 status = csrGetRegulatoryDomainForCountry(pMac, pCountry, &domainId, COUNTRY_USER);
Jeff Johnson295189b2012-06-20 16:38:30 -07004223 if(HAL_STATUS_SUCCESS(status))
4224 {
4225 status = csrSetRegulatoryDomain(pMac, domainId, pfRestartNeeded);
4226 if(HAL_STATUS_SUCCESS(status))
4227 {
4228 //We don't need to check the pMac->roam.configParam.fEnforceDefaultDomain flag here,
4229 //csrSetRegulatoryDomain will fail if the country doesn't fit our domain criteria.
Kiet Lam64c1b492013-07-12 13:56:44 +05304230 vos_mem_copy(pMac->scan.countryCodeCurrent, pCountry, WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07004231 if((pfRestartNeeded == NULL) || !(*pfRestartNeeded))
4232 {
4233 //Simply set it to cfg. If we need to restart, restart will apply it to the CFG
4234 csrSetCfgCountryCode(pMac, pCountry);
4235 }
4236 }
4237 }
4238 }
4239
4240 return (status);
4241}
4242
4243
4244
4245//caller allocated memory for pNumChn and pChnPowerInfo
4246//As input, *pNumChn has the size of the array of pChnPowerInfo
4247//Upon return, *pNumChn has the number of channels assigned.
4248void csrGetChannelPowerInfo( tpAniSirGlobal pMac, tDblLinkList *pList,
4249 tANI_U32 *pNumChn, tChannelListWithPower *pChnPowerInfo)
4250{
4251 tListElem *pEntry;
4252 tANI_U32 chnIdx = 0, idx;
4253 tCsrChannelPowerInfo *pChannelSet;
4254
4255 //Get 2.4Ghz first
4256 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
4257 while( pEntry && (chnIdx < *pNumChn) )
4258 {
4259 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
4260 if ( 1 != pChannelSet->interChannelOffset )
4261 {
4262 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
4263 {
4264 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
4265 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
4266 }
4267 }
4268 else
4269 {
4270 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
4271 {
4272 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + idx);
4273 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
4274 }
4275 }
4276
4277 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
4278 }
4279 *pNumChn = chnIdx;
4280
4281 return ;
4282}
4283
4284
4285
4286void csrApplyCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce )
4287{
4288 v_REGDOMAIN_t domainId;
4289 eHalStatus status = eHAL_STATUS_SUCCESS;
4290
4291 do
4292 {
4293 if( !csrIs11dSupported( pMac ) || 0 == pMac->scan.channelOf11dInfo) break;
4294 if( pMac->scan.fAmbiguous11dInfoFound )
4295 {
4296 // ambiguous info found
4297 //Restore te default domain as well
Kiet Lam6c583332013-10-14 05:37:09 +05304298 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
4299 pMac, pMac->scan.countryCodeCurrent,
4300 &domainId, COUNTRY_QUERY)))
Jeff Johnson295189b2012-06-20 16:38:30 -07004301 {
4302 pMac->scan.domainIdCurrent = domainId;
4303 }
4304 else
4305 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004306 smsLog(pMac, LOGE, FL(" failed to get domain from currentCountryCode %02X%02X"),
Jeff Johnson295189b2012-06-20 16:38:30 -07004307 pMac->scan.countryCodeCurrent[0], pMac->scan.countryCodeCurrent[1]);
4308 }
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004309 csrResetCountryInformation( pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE );
Jeff Johnson295189b2012-06-20 16:38:30 -07004310 break;
4311 }
4312 if ( pMac->scan.f11dInfoApplied && !fForce ) break;
Kiet Lam6c583332013-10-14 05:37:09 +05304313 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
4314 pMac, pMac->scan.countryCode11d,
4315 &domainId, COUNTRY_QUERY)))
Jeff Johnson295189b2012-06-20 16:38:30 -07004316 {
4317 //Check whether we need to enforce default domain
4318 if( ( !pMac->roam.configParam.fEnforceDefaultDomain ) ||
4319 (pMac->scan.domainIdCurrent == domainId) )
4320 {
4321
4322#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4323 {
4324 vos_log_802_11d_pkt_type *p11dLog;
4325 tChannelListWithPower chnPwrInfo[WNI_CFG_VALID_CHANNEL_LIST_LEN];
4326 tANI_U32 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN, nTmp;
4327
4328 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
4329 if(p11dLog)
4330 {
4331 p11dLog->eventId = WLAN_80211D_EVENT_COUNTRY_SET;
Kiet Lam64c1b492013-07-12 13:56:44 +05304332 vos_mem_copy(p11dLog->countryCode, pMac->scan.countryCode11d, 3);
Jeff Johnson295189b2012-06-20 16:38:30 -07004333 p11dLog->numChannel = pMac->scan.channels11d.numChannels;
4334 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
4335 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304336 vos_mem_copy(p11dLog->Channels,
4337 pMac->scan.channels11d.channelList,
4338 p11dLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07004339 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList24,
4340 &nChnInfo, chnPwrInfo);
4341 nTmp = nChnInfo;
4342 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN - nTmp;
4343 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList5G,
4344 &nChnInfo, &chnPwrInfo[nTmp]);
4345 for(nTmp = 0; nTmp < p11dLog->numChannel; nTmp++)
4346 {
4347 for(nChnInfo = 0; nChnInfo < WNI_CFG_VALID_CHANNEL_LIST_LEN; nChnInfo++)
4348 {
4349 if(p11dLog->Channels[nTmp] == chnPwrInfo[nChnInfo].chanId)
4350 {
4351 p11dLog->TxPwr[nTmp] = chnPwrInfo[nChnInfo].pwr;
4352 break;
4353 }
4354 }
4355 }
4356 }
4357 if(!pMac->roam.configParam.Is11dSupportEnabled)
4358 {
4359 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
4360 }
4361 else if(pMac->roam.configParam.fEnforceDefaultDomain)
4362 {
4363 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
4364 }
4365 else
4366 {
4367 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
4368 }
4369 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
4370 }
4371 }
4372#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4373 if(pMac->scan.domainIdCurrent != domainId)
4374 {
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05304375 smsLog(pMac, LOGW, FL("Domain Changed Old %s (%d), new %s"),
4376 voss_DomainIdtoString(pMac->scan.domainIdCurrent),
4377 pMac->scan.domainIdCurrent,
4378 voss_DomainIdtoString(domainId));
Abhishek Singha306a442013-11-07 18:39:01 +05304379 status = WDA_SetRegDomain(pMac, domainId, eSIR_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07004380 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004381 if (status != eHAL_STATUS_SUCCESS)
4382 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004383 smsLog( pMac, LOGE, FL(" fail to set regId %d"), domainId );
Jeff Johnson295189b2012-06-20 16:38:30 -07004384 }
4385 pMac->scan.domainIdCurrent = domainId;
Kiet Lam6c583332013-10-14 05:37:09 +05304386#ifndef CONFIG_ENABLE_LINUX_REG
Kiet Lambb14e952013-11-19 14:58:29 +05304387 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.base20MHzChannels,
4388 pMac->scan.countryCodeCurrent, eANI_BOOLEAN_TRUE );
Kiet Lam6c583332013-10-14 05:37:09 +05304389#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004390 // switch to active scans using this new channel list
4391 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
4392 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_TRUE;
4393 pMac->scan.f11dInfoReset = eANI_BOOLEAN_FALSE;
4394 }
4395 }
4396
4397 } while( 0 );
4398
4399 return;
4400}
4401
4402
4403
4404tANI_BOOLEAN csrSave11dCountryString( tpAniSirGlobal pMac, tANI_U8 *pCountryCode,
4405 tANI_BOOLEAN fForce)
4406{
4407 tANI_BOOLEAN fCountryStringChanged = FALSE, fUnknownCountryCode = FALSE;
4408 tANI_U32 i;
Kiet Lam6c583332013-10-14 05:37:09 +05304409 v_REGDOMAIN_t regd;
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004410 tANI_BOOLEAN fCountryNotPresentInDriver = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004411
4412 // convert to UPPER here so we are assured the strings are always in upper case.
4413 for( i = 0; i < 3; i++ )
4414 {
4415 pCountryCode[ i ] = (tANI_U8)csrToUpper( pCountryCode[ i ] );
4416 }
4417
4418 // Some of the 'old' Cisco 350 series AP's advertise NA as the country code (for North America ??).
4419 // NA is not a valid country code or domain so let's allow this by changing it to the proper
4420 // country code (which is US). We've also seen some NETGEAR AP's that have "XX " as the country code
4421 // with valid 2.4 GHz US channel information. If we cannot find the country code advertised in the
4422 // 11d information element, let's default to US.
Kiet Lam6c583332013-10-14 05:37:09 +05304423 if ( !HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(pMac,
4424 pCountryCode,
4425 &regd,
4426 COUNTRY_QUERY) ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07004427 {
4428 // Check the enforcement first
4429 if( pMac->roam.configParam.fEnforceDefaultDomain || pMac->roam.configParam.fEnforceCountryCodeMatch )
4430 {
4431 fUnknownCountryCode = TRUE;
4432 }
4433 else
4434 {
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004435 fCountryNotPresentInDriver = TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004436 }
4437 }
Tushnim Bhattacharyyac3c1e8e2013-10-29 17:27:43 -07004438 //right now, even if we don't find the CC in driver we set to world. Making
4439 //sure countryCode11d doesn't get updated with the invalid CC, instead
4440 //reflect the world CC
4441 else if (REGDOMAIN_WORLD == regd)
4442 {
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004443 fCountryNotPresentInDriver = TRUE;
Tushnim Bhattacharyyac3c1e8e2013-10-29 17:27:43 -07004444 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004445
4446 // We've seen some of the AP's improperly put a 0 for the third character of the country code.
4447 // spec says valid charcters are 'O' (for outdoor), 'I' for Indoor, or ' ' (space; for either).
4448 // if we see a 0 in this third character, let's change it to a ' '.
4449 if ( 0 == pCountryCode[ 2 ] )
4450 {
4451 pCountryCode[ 2 ] = ' ';
4452 }
4453
4454 if( !fUnknownCountryCode )
4455 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304456 fCountryStringChanged = (!vos_mem_compare(pMac->scan.countryCode11d, pCountryCode, 2));
Jeff Johnson295189b2012-06-20 16:38:30 -07004457
4458
4459 if(( 0 == pMac->scan.countryCode11d[ 0 ] && 0 == pMac->scan.countryCode11d[ 1 ] )
4460 || (fForce))
4461 {
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004462 if (!fCountryNotPresentInDriver)
4463 {
4464 // this is the first .11d information
4465 vos_mem_copy(pMac->scan.countryCode11d, pCountryCode,
Kiet Lam64c1b492013-07-12 13:56:44 +05304466 sizeof( pMac->scan.countryCode11d ));
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004467
4468 }
4469 else
4470 {
4471 pMac->scan.countryCode11d[0] = '0';
4472 pMac->scan.countryCode11d[1] = '0';
4473 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004474 }
4475 }
4476
4477 return( fCountryStringChanged );
4478}
4479
4480
4481void csrSaveChannelPowerForBand( tpAniSirGlobal pMac, tANI_BOOLEAN fPopulate5GBand )
4482{
4483 tANI_U32 Index, count=0;
4484 tSirMacChanInfo *pChanInfo;
4485 tSirMacChanInfo *pChanInfoStart;
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08004486 tANI_S32 maxChannelIndex;
4487
4488 maxChannelIndex = ( pMac->scan.base20MHzChannels.numChannels < WNI_CFG_VALID_CHANNEL_LIST_LEN ) ?
4489 pMac->scan.base20MHzChannels.numChannels : WNI_CFG_VALID_CHANNEL_LIST_LEN ;
Jeff Johnson295189b2012-06-20 16:38:30 -07004490
Kiet Lam64c1b492013-07-12 13:56:44 +05304491 pChanInfo = vos_mem_malloc(sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN);
4492 if ( NULL != pChanInfo )
Jeff Johnson295189b2012-06-20 16:38:30 -07004493 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304494 vos_mem_set(pChanInfo, sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004495 pChanInfoStart = pChanInfo;
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08004496 for (Index=0; Index < maxChannelIndex; Index++)
Jeff Johnson295189b2012-06-20 16:38:30 -07004497 {
4498 if ((fPopulate5GBand && (CSR_IS_CHANNEL_5GHZ(pMac->scan.defaultPowerTable[Index].chanId))) ||
4499 (!fPopulate5GBand && (CSR_IS_CHANNEL_24GHZ(pMac->scan.defaultPowerTable[Index].chanId))) )
4500 {
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08004501 if(count >= WNI_CFG_VALID_CHANNEL_LIST_LEN)
4502 {
4503 smsLog( pMac, LOGW, FL(" csrSaveChannelPowerForBand, count exceeded, count = %d"), count);
4504 break;
4505 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004506 pChanInfo->firstChanNum = pMac->scan.defaultPowerTable[Index].chanId;
4507 pChanInfo->numChannels = 1;
4508 pChanInfo->maxTxPower = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
4509 pChanInfo++;
4510 count++;
4511 }
4512 }
4513 if(count)
4514 {
4515 csrSaveToChannelPower2G_5G( pMac, count * sizeof(tSirMacChanInfo), pChanInfoStart );
4516 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304517 vos_mem_free(pChanInfoStart);
Jeff Johnson295189b2012-06-20 16:38:30 -07004518 }
4519}
4520
4521
4522void csrSetOppositeBandChannelInfo( tpAniSirGlobal pMac )
4523{
4524 tANI_BOOLEAN fPopulate5GBand = FALSE;
4525
4526 do
4527 {
4528 // if this is not a dual band product, then we don't need to set the opposite
4529 // band info. We only work in one band so no need to look in the other band.
4530 if ( !CSR_IS_OPEARTING_DUAL_BAND( pMac ) ) break;
4531 // if we found channel info on the 5.0 band and...
4532 if ( CSR_IS_CHANNEL_5GHZ( pMac->scan.channelOf11dInfo ) )
4533 {
4534 // and the 2.4 band is empty, then populate the 2.4 channel info
Kiet Lam8d985a02013-10-11 03:39:41 +05304535 if ( !csrLLIsListEmpty( &pMac->scan.channelPowerInfoList24, LL_ACCESS_LOCK ) ) break;
Jeff Johnson295189b2012-06-20 16:38:30 -07004536 fPopulate5GBand = FALSE;
4537 }
4538 else
4539 {
4540 // else, we found channel info in the 2.4 GHz band. If the 5.0 band is empty
4541 // set the 5.0 band info from the 2.4 country code.
Kiet Lam8d985a02013-10-11 03:39:41 +05304542 if ( !csrLLIsListEmpty( &pMac->scan.channelPowerInfoList5G, LL_ACCESS_LOCK ) ) break;
Jeff Johnson295189b2012-06-20 16:38:30 -07004543 fPopulate5GBand = TRUE;
4544 }
4545 csrSaveChannelPowerForBand( pMac, fPopulate5GBand );
4546
4547 } while( 0 );
4548}
4549
4550
4551tANI_BOOLEAN csrIsSupportedChannel(tpAniSirGlobal pMac, tANI_U8 channelId)
4552{
4553 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
4554 tANI_U32 i;
4555
4556 //Make sure it is a channel that is in our supported list.
4557 for ( i = 0; i < pMac->scan.baseChannels.numChannels; i++ )
4558 {
4559 if ( channelId == pMac->scan.baseChannels.channelList[i] )
4560 {
4561 fRet = eANI_BOOLEAN_TRUE;
4562 break;
4563 }
4564 }
4565
4566 //If it is configured to limit a set of the channels
4567 if( fRet && pMac->roam.configParam.fEnforce11dChannels )
4568 {
4569 fRet = eANI_BOOLEAN_FALSE;
4570 for ( i = 0; i < pMac->scan.base20MHzChannels.numChannels; i++ )
4571 {
4572 if ( channelId == pMac->scan.base20MHzChannels.channelList[i] )
4573 {
4574 fRet = eANI_BOOLEAN_TRUE;
4575 break;
4576 }
4577 }
4578 }
4579
4580 return (fRet);
4581}
4582
4583
4584
4585//bSize specify the buffer size of pChannelList
4586tANI_U8 csrGetChannelListFromChannelSet( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 bSize, tCsrChannelPowerInfo *pChannelSet )
4587{
4588 tANI_U8 i, j = 0, chnId;
4589
4590 bSize = CSR_MIN(bSize, pChannelSet->numChannels);
4591 for( i = 0; i < bSize; i++ )
4592 {
4593 chnId = (tANI_U8)(pChannelSet->firstChannel + ( i * pChannelSet->interChannelOffset ));
4594 if ( csrIsSupportedChannel( pMac, chnId ) )
4595 {
4596 pChannelList[j++] = chnId;
4597 }
4598 }
4599
4600 return (j);
4601}
4602
4603
4604
4605//bSize -- specify the buffer size of pChannelList
4606void csrConstructCurrentValidChannelList( tpAniSirGlobal pMac, tDblLinkList *pChannelSetList,
4607 tANI_U8 *pChannelList, tANI_U8 bSize, tANI_U8 *pNumChannels )
4608{
4609 tListElem *pEntry;
4610 tCsrChannelPowerInfo *pChannelSet;
4611 tANI_U8 numChannels;
4612 tANI_U8 *pChannels;
4613
4614 if( pChannelSetList && pChannelList && pNumChannels )
4615 {
4616 pChannels = pChannelList;
4617 *pNumChannels = 0;
4618 pEntry = csrLLPeekHead( pChannelSetList, LL_ACCESS_LOCK );
4619 while( pEntry )
4620 {
4621 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
4622 numChannels = csrGetChannelListFromChannelSet( pMac, pChannels, bSize, pChannelSet );
4623 pChannels += numChannels;
4624 *pNumChannels += numChannels;
4625 pEntry = csrLLNext( pChannelSetList, pEntry, LL_ACCESS_LOCK );
4626 }
4627 }
4628}
4629
4630
4631/*
4632 * 802.11D only: Gather 11d IE via beacon or Probe response and store them in pAdapter->channels11d
4633*/
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304634tANI_BOOLEAN csrLearnCountryInformation( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc,
4635 tDot11fBeaconIEs *pIes, tANI_BOOLEAN fForce)
Jeff Johnson295189b2012-06-20 16:38:30 -07004636{
Agarwal Ashish60a37ee2014-05-28 17:20:20 +05304637 eHalStatus status;
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304638 tANI_U8 *pCountryCodeSelected;
Jeff Johnson295189b2012-06-20 16:38:30 -07004639 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
4640 v_REGDOMAIN_t domainId;
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304641 tDot11fBeaconIEs *pIesLocal = pIes;
4642 tANI_BOOLEAN useVoting = eANI_BOOLEAN_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004643
Jeff Johnson295189b2012-06-20 16:38:30 -07004644 if (VOS_STA_SAP_MODE == vos_get_conparam ())
4645 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07004646
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304647 if ((NULL == pSirBssDesc) && (NULL == pIes))
4648 useVoting = eANI_BOOLEAN_TRUE;
4649
Jeff Johnson295189b2012-06-20 16:38:30 -07004650 do
4651 {
4652 // check if .11d support is enabled
4653 if( !csrIs11dSupported( pMac ) ) break;
Agarwal Ashish60a37ee2014-05-28 17:20:20 +05304654
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304655 if (eANI_BOOLEAN_FALSE == useVoting)
4656 {
4657 if( !pIesLocal &&
4658 (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
4659 pSirBssDesc, &pIesLocal))))
4660 {
4661 break;
4662 }
4663 // check if country information element is present
4664 if(!pIesLocal->Country.present)
4665 {
4666 //No country info
4667 break;
4668 }
4669
4670 if( HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry
4671 (pMac, pIesLocal->Country.country, &domainId,
4672 COUNTRY_QUERY)) &&
4673 ( domainId == REGDOMAIN_WORLD))
4674 {
4675 break;
4676 }
4677 } //useVoting == eANI_BOOLEAN_FALSE
4678
4679 if (eANI_BOOLEAN_FALSE == useVoting)
4680 pCountryCodeSelected = pIesLocal->Country.country;
4681 else
4682 pCountryCodeSelected = pMac->scan.countryCodeElected;
4683
Kiet Lam8d985a02013-10-11 03:39:41 +05304684 status = csrGetRegulatoryDomainForCountry(pMac,
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304685 pCountryCodeSelected, &domainId, COUNTRY_IE);
Kiet Lam8d985a02013-10-11 03:39:41 +05304686 if ( status != eHAL_STATUS_SUCCESS )
4687 {
4688 smsLog( pMac, LOGE, FL(" fail to get regId %d"), domainId );
4689 fRet = eANI_BOOLEAN_FALSE;
4690 break;
4691 }
Agarwal Ashish7693f2d2014-07-18 18:03:58 +05304692
4693 /* updating 11d Country Code with Country code selected. */
4694
4695 vos_mem_copy(pMac->scan.countryCode11d,
4696 pCountryCodeSelected,
4697 WNI_CFG_COUNTRY_CODE_LEN);
4698
Agarwal Ashish60a37ee2014-05-28 17:20:20 +05304699#ifndef CONFIG_ENABLE_LINUX_REG
Venkata Prathyusha Kuntupalli316247e2013-03-15 17:45:25 -07004700 // Checking for Domain Id change
4701 if ( domainId != pMac->scan.domainIdCurrent )
4702 {
Kiet Lam8d985a02013-10-11 03:39:41 +05304703 vos_mem_copy(pMac->scan.countryCode11d,
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304704 pCountryCodeSelected,
Kiet Lam8d985a02013-10-11 03:39:41 +05304705 sizeof( pMac->scan.countryCode11d ) );
4706 /* Set Current Country code and Current Regulatory domain */
4707 status = csrSetRegulatoryDomain(pMac, domainId, NULL);
4708 if (eHAL_STATUS_SUCCESS != status)
4709 {
4710 smsLog(pMac, LOGE, "Set Reg Domain Fail %d", status);
4711 fRet = eANI_BOOLEAN_FALSE;
4712 return fRet;
4713 }
4714 //csrSetRegulatoryDomain will fail if the country doesn't fit our domain criteria.
4715 vos_mem_copy(pMac->scan.countryCodeCurrent,
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304716 pCountryCodeSelected, WNI_CFG_COUNTRY_CODE_LEN);
Kiet Lam8d985a02013-10-11 03:39:41 +05304717 //Simply set it to cfg.
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304718 csrSetCfgCountryCode(pMac, pCountryCodeSelected);
Kiet Lam8d985a02013-10-11 03:39:41 +05304719
4720 /* overwrite the defualt country code */
4721 vos_mem_copy(pMac->scan.countryCodeDefault,
4722 pMac->scan.countryCodeCurrent,
4723 WNI_CFG_COUNTRY_CODE_LEN);
4724 /* Set Current RegDomain */
Abhishek Singha306a442013-11-07 18:39:01 +05304725 status = WDA_SetRegDomain(pMac, domainId, eSIR_TRUE);
Kiet Lam8d985a02013-10-11 03:39:41 +05304726 if ( status != eHAL_STATUS_SUCCESS )
4727 {
4728 smsLog( pMac, LOGE, FL(" fail to Set regId %d"), domainId );
4729 fRet = eANI_BOOLEAN_FALSE;
4730 return fRet;
4731 }
4732 /* set to default domain ID */
Madan Mohan Koyyalamudi0e5922d2013-09-10 15:45:24 +05304733 pMac->scan.domainIdCurrent = domainId;
Kiet Lam8d985a02013-10-11 03:39:41 +05304734 /* get the channels based on new cc */
4735 status = csrInitGetChannels( pMac );
Jeff Johnson295189b2012-06-20 16:38:30 -07004736
Kiet Lam8d985a02013-10-11 03:39:41 +05304737 if ( status != eHAL_STATUS_SUCCESS )
4738 {
4739 smsLog( pMac, LOGE, FL(" fail to get Channels "));
4740 fRet = eANI_BOOLEAN_FALSE;
4741 return fRet;
4742 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004743
Kiet Lam8d985a02013-10-11 03:39:41 +05304744 /* reset info based on new cc, and we are done */
4745 csrResetCountryInformation(pMac, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
Agarwal Ashishfaef6692014-01-29 19:40:30 +05304746 /* Regulatory Domain Changed, Purge Only scan result
4747 * which does not have channel number belong to 11d
4748 * channel list
4749 */
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05304750 csrScanFilterResults(pMac);
Kiet Lam8d985a02013-10-11 03:39:41 +05304751 }
Kiet Lam6c583332013-10-14 05:37:09 +05304752#endif
4753 fRet = eANI_BOOLEAN_TRUE;
4754
Jeff Johnson295189b2012-06-20 16:38:30 -07004755 } while( 0 );
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304756
4757 if( !pIes && pIesLocal )
4758 {
4759 //locally allocated
4760 vos_mem_free(pIesLocal);
4761 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004762
4763 return( fRet );
4764}
4765
4766
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004767static void csrSaveScanResults( tpAniSirGlobal pMac, tANI_U8 reason )
Jeff Johnson295189b2012-06-20 16:38:30 -07004768{
4769 // initialize this to FALSE. profMoveInterimScanResultsToMainList() routine
4770 // will set this to the channel where an .11d beacon is seen
4771 pMac->scan.channelOf11dInfo = 0;
4772 // if we get any ambiguous .11d information then this will be set to TRUE
4773 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
4774 //Tush
4775 // if we get any ambiguous .11d information, then this will be set to TRUE
4776 // only if the applied 11d info could be found in one of the scan results
4777 pMac->scan.fCurrent11dInfoMatch = eANI_BOOLEAN_FALSE;
4778 // move the scan results from interim list to the main scan list
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004779 csrMoveTempScanResultsToMainList( pMac, reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07004780}
4781
4782
4783void csrReinitScanCmd(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4784{
4785 switch (pCommand->u.scanCmd.reason)
4786 {
4787 case eCsrScanSetBGScanParam:
4788 case eCsrScanAbortBgScan:
4789 if(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList)
4790 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304791 vos_mem_free(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList);
Jeff Johnson295189b2012-06-20 16:38:30 -07004792 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
4793 }
4794 break;
4795 case eCsrScanBGScanAbort:
4796 case eCsrScanBGScanEnable:
4797 case eCsrScanGetScanChnInfo:
4798 break;
4799 case eCsrScanAbortNormalScan:
4800 default:
4801 csrScanFreeRequest(pMac, &pCommand->u.scanCmd.u.scanRequest);
4802 break;
4803 }
4804 if(pCommand->u.scanCmd.pToRoamProfile)
4805 {
4806 csrReleaseProfile(pMac, pCommand->u.scanCmd.pToRoamProfile);
Kiet Lam64c1b492013-07-12 13:56:44 +05304807 vos_mem_free(pCommand->u.scanCmd.pToRoamProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07004808 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304809 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004810}
4811
4812
4813tANI_BOOLEAN csrGetRemainingChannelsFor11dScan( tpAniSirGlobal pMac, tANI_U8 *pChannels, tANI_U8 *pcChannels )
4814{
4815 tANI_U32 index11dChannels, index;
4816 tANI_U32 indexCurrentChannels;
4817 tANI_BOOLEAN fChannelAlreadyScanned;
4818 tANI_U32 len = sizeof(pMac->roam.validChannelList);
4819
4820 *pcChannels = 0;
4821 if ( CSR_IS_11D_INFO_FOUND(pMac) && csrRoamIsChannelValid(pMac, pMac->scan.channelOf11dInfo) )
4822 {
4823 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
4824 {
4825 //Find the channel index where we found the 11d info
4826 for(index = 0; index < len; index++)
4827 {
4828 if(pMac->scan.channelOf11dInfo == pMac->roam.validChannelList[index])
4829 break;
4830 }
4831 //check whether we found the channel index
4832 if(index < len)
4833 {
4834 // Now, look through the 11d channel list and create a list of all channels in the 11d list that are
4835 // NOT in the current channel list. This gives us a list of the new channels that have not been
4836 // scanned. We'll scan this new list so we have a complete set of scan results on all of the domain channels
4837 // initially.
4838 for ( index11dChannels = 0; index11dChannels < pMac->scan.channels11d.numChannels; index11dChannels++ )
4839 {
4840 fChannelAlreadyScanned = eANI_BOOLEAN_FALSE;
4841
4842 for( indexCurrentChannels = 0; indexCurrentChannels < index; indexCurrentChannels++ )
4843 {
4844 if ( pMac->roam.validChannelList[ indexCurrentChannels ] == pMac->scan.channels11d.channelList[ index11dChannels ] )
4845 {
4846 fChannelAlreadyScanned = eANI_BOOLEAN_TRUE;
4847 break;
4848 }
4849 }
4850
4851 if ( !fChannelAlreadyScanned )
4852 {
4853 pChannels[ *pcChannels ] = pMac->scan.channels11d.channelList[ index11dChannels ];
4854 ( *pcChannels )++;
4855 }
4856 }
4857 }
4858 }//GetCFG
4859 }
4860 return( *pcChannels );
4861}
4862
4863
4864eCsrScanCompleteNextCommand csrScanGetNextCommandState( tpAniSirGlobal pMac, tSmeCmd *pCommand, tANI_BOOLEAN fSuccess )
4865{
4866 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
4867
4868 switch( pCommand->u.scanCmd.reason )
4869 {
4870 case eCsrScan11d1:
4871 NextCommand = (fSuccess) ? eCsrNext11dScan1Success : eCsrNext11dScan1Failure;
4872 break;
4873 case eCsrScan11d2:
4874 NextCommand = (fSuccess) ? eCsrNext11dScan2Success : eCsrNext11dScan2Failure;
4875 break;
4876 case eCsrScan11dDone:
4877 NextCommand = eCsrNext11dScanComplete;
4878 break;
4879 case eCsrScanLostLink1:
4880 NextCommand = (fSuccess) ? eCsrNextLostLinkScan1Success : eCsrNextLostLinkScan1Failed;
4881 break;
4882 case eCsrScanLostLink2:
4883 NextCommand = (fSuccess) ? eCsrNextLostLinkScan2Success : eCsrNextLostLinkScan2Failed;
4884 break;
4885 case eCsrScanLostLink3:
4886 NextCommand = (fSuccess) ? eCsrNextLostLinkScan3Success : eCsrNextLostLinkScan3Failed;
4887 break;
4888 case eCsrScanForSsid:
4889 NextCommand = (fSuccess) ? eCsrNexteScanForSsidSuccess : eCsrNexteScanForSsidFailure;
4890 break;
4891 case eCsrScanForCapsChange:
4892 NextCommand = eCsrNextCapChangeScanComplete; //don't care success or not
4893 break;
4894 case eCsrScanIdleScan:
4895 NextCommand = eCsrNextIdleScanComplete;
4896 break;
4897 default:
4898 NextCommand = eCsrNextScanNothing;
4899 break;
4900 }
4901 return( NextCommand );
4902}
4903
4904
4905//Return whether the pCommand is finished.
4906tANI_BOOLEAN csrHandleScan11d1Failure(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4907{
4908 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
4909
4910 //Apply back the default setting and passively scan one more time.
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004911 csrResetCountryInformation(pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07004912 pCommand->u.scanCmd.reason = eCsrScan11d2;
4913 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
4914 {
4915 fRet = eANI_BOOLEAN_FALSE;
4916 }
4917
4918 return (fRet);
4919}
4920
4921
4922tANI_BOOLEAN csrHandleScan11dSuccess(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4923{
4924 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
4925 tANI_U8 *pChannels;
4926 tANI_U8 cChannels;
4927
Kiet Lam64c1b492013-07-12 13:56:44 +05304928 pChannels = vos_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
4929 if ( NULL != pChannels )
Jeff Johnson295189b2012-06-20 16:38:30 -07004930 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304931 vos_mem_set(pChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004932 if ( csrGetRemainingChannelsFor11dScan( pMac, pChannels, &cChannels ) )
4933 {
4934 pCommand->u.scanCmd.reason = eCsrScan11dDone;
4935 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
4936 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304937 vos_mem_free(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -07004938 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004939 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304940 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(cChannels);
4941 if ( NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07004942 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304943 vos_mem_copy(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
4944 pChannels, cChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07004945 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = cChannels;
4946 pCommand->u.scanCmd.u.scanRequest.requestType = eCSR_SCAN_REQUEST_FULL_SCAN;
4947 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
4948 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
4949 {
4950 //Reuse the same command buffer
4951 fRet = eANI_BOOLEAN_FALSE;
4952 }
4953 }
4954 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304955 vos_mem_free(pChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07004956 }
4957
4958 return (fRet);
4959}
4960
4961//Return whether the command should be removed
4962tANI_BOOLEAN csrScanComplete( tpAniSirGlobal pMac, tSirSmeScanRsp *pScanRsp )
4963{
4964 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
4965 tListElem *pEntry;
4966 tSmeCmd *pCommand;
4967 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
4968 tANI_BOOLEAN fSuccess;
4969
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05304970 if (pMac->fScanOffload)
4971 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
4972 else
4973 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07004974
4975 if ( pEntry )
4976 {
4977 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
4978
4979 // If the head of the queue is Active and it is a SCAN command, remove
4980 // and put this on the Free queue.
4981 if ( eSmeCommandScan == pCommand->command )
4982 {
4983 tANI_U32 sessionId = pCommand->sessionId;
4984
4985 if(eSIR_SME_SUCCESS != pScanRsp->statusCode)
4986 {
4987 fSuccess = eANI_BOOLEAN_FALSE;
4988 }
4989 else
4990 {
4991 //pMac->scan.tempScanResults is not empty meaning the scan found something
4992 //This check only valid here because csrSaveScanresults is not yet called
4993 fSuccess = (!csrLLIsListEmpty(&pMac->scan.tempScanResults, LL_ACCESS_LOCK));
4994 }
Ratheesh S Pece1f832015-07-25 15:50:25 +05304995 if (pCommand->u.scanCmd.abortScanIndication &
4996 eCSR_SCAN_ABORT_DUE_TO_BAND_CHANGE)
Srinivas, Dasari187ca4e2014-02-07 12:40:09 +05304997 {
4998 /*
4999 * Scan aborted due to band change
5000 * The scan results need to be flushed
5001 */
5002 if (pCommand->u.scanCmd.callback
5003 != pMac->scan.callback11dScanDone)
5004 {
5005 smsLog(pMac, LOG1, FL("Filtering the scan results as the "
5006 "results may belong to wrong band"));
5007 csrScanFilterResults(pMac);
5008 }
5009 else
5010 {
5011 smsLog(pMac, LOG1, FL("11d_scan_done will flush the scan"
5012 " results"));
5013 }
Srinivas, Dasari187ca4e2014-02-07 12:40:09 +05305014 }
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005015 csrSaveScanResults(pMac, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07005016
Agrawal Ashishdf752672015-12-09 17:51:53 +05305017 /* filter scan result based on valid channel list number */
5018 if (pMac->scan.fcc_constraint)
5019 {
5020 smsLog(pMac, LOG1, FL("Clear BSS from invalid channels"));
5021 csrScanFilterResults(pMac);
5022 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005023#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5024 {
5025 vos_log_scan_pkt_type *pScanLog = NULL;
5026 tScanResultHandle hScanResult;
5027 tCsrScanResultInfo *pScanResult;
5028 tDot11fBeaconIEs *pIes;
5029 int n = 0, c = 0;
5030
5031 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
5032 if(pScanLog)
5033 {
5034 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
5035 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
5036 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
5037 {
5038 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_RSP;
5039 }
5040 else
5041 {
5042 if( eSIR_PASSIVE_SCAN != pMac->scan.curScanType )
5043 {
5044 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_RSP;
5045 }
5046 else
5047 {
5048 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_RSP;
5049 }
5050 }
5051 if(eSIR_SME_SUCCESS == pScanRsp->statusCode)
5052 {
5053 if(HAL_STATUS_SUCCESS(csrScanGetResult(pMac, NULL, &hScanResult)))
5054 {
5055 while(((pScanResult = csrScanResultGetNext(pMac, hScanResult)) != NULL))
5056 {
5057 if( n < VOS_LOG_MAX_NUM_BSSID )
5058 {
5059 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pScanResult->BssDescriptor, &pIes)))
5060 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005061 smsLog(pMac, LOGE, FL(" fail to parse IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07005062 break;
5063 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305064 vos_mem_copy(pScanLog->bssid[n],
5065 pScanResult->BssDescriptor.bssId, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07005066 if(pIes && pIes->SSID.present && VOS_LOG_MAX_SSID_SIZE >= pIes->SSID.num_ssid)
5067 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305068 vos_mem_copy(pScanLog->ssid[n],
5069 pIes->SSID.ssid, pIes->SSID.num_ssid);
Jeff Johnson295189b2012-06-20 16:38:30 -07005070 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305071 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07005072 n++;
5073 }
5074 c++;
5075 }
5076 pScanLog->numSsid = (v_U8_t)n;
5077 pScanLog->totalSsid = (v_U8_t)c;
5078 csrScanResultPurge(pMac, hScanResult);
5079 }
5080 }
5081 else
5082 {
5083 pScanLog->status = WLAN_SCAN_STATUS_FAILURE;
5084 }
5085 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
5086 }
5087 }
5088#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5089
5090 NextCommand = csrScanGetNextCommandState(pMac, pCommand, fSuccess);
5091 //We reuse the command here instead reissue a new command
5092 switch(NextCommand)
5093 {
5094 case eCsrNext11dScan1Success:
5095 case eCsrNext11dScan2Success:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005096 smsLog( pMac, LOG2, FL("11dScan1/3 produced results. Reissue Active scan..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07005097 // if we found country information, no need to continue scanning further, bail out
5098 fRemoveCommand = eANI_BOOLEAN_TRUE;
5099 NextCommand = eCsrNext11dScanComplete;
5100 break;
5101 case eCsrNext11dScan1Failure:
5102 //We are not done yet. 11d scan fail once. We will try to reset anything and do it over again
5103 //The only meaningful thing for this retry is that we cannot find 11d information after a reset so
5104 //we clear the "old" 11d info and give it once more chance
5105 fRemoveCommand = csrHandleScan11d1Failure(pMac, pCommand);
5106 if(fRemoveCommand)
5107 {
5108 NextCommand = eCsrNext11dScanComplete;
5109 }
5110 break;
5111 case eCsrNextLostLinkScan1Success:
5112 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink1)))
5113 {
5114 csrScanHandleFailedLostlink1(pMac, sessionId);
5115 }
5116 break;
5117 case eCsrNextLostLinkScan2Success:
5118 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink2)))
5119 {
5120 csrScanHandleFailedLostlink2(pMac, sessionId);
5121 }
5122 break;
5123 case eCsrNextLostLinkScan3Success:
5124 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink3)))
5125 {
5126 csrScanHandleFailedLostlink3(pMac, sessionId);
5127 }
5128 break;
5129 case eCsrNextLostLinkScan1Failed:
5130 csrScanHandleFailedLostlink1(pMac, sessionId);
5131 break;
5132 case eCsrNextLostLinkScan2Failed:
5133 csrScanHandleFailedLostlink2(pMac, sessionId);
5134 break;
5135 case eCsrNextLostLinkScan3Failed:
5136 csrScanHandleFailedLostlink3(pMac, sessionId);
5137 break;
5138 case eCsrNexteScanForSsidSuccess:
5139 csrScanHandleSearchForSSID(pMac, pCommand);
5140 break;
5141 case eCsrNexteScanForSsidFailure:
5142 csrScanHandleSearchForSSIDFailure(pMac, pCommand);
5143 break;
5144 case eCsrNextIdleScanComplete:
5145 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
5146 break;
5147 case eCsrNextCapChangeScanComplete:
5148 csrScanHandleCapChangeScanComplete(pMac, sessionId);
5149 break;
5150 default:
5151
5152 break;
5153 }
5154 }
5155 else
5156 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005157 smsLog( pMac, LOGW, FL("Scan Completion called but SCAN command is not ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07005158 fRemoveCommand = eANI_BOOLEAN_FALSE;
5159 }
5160 }
5161 else
5162 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005163 smsLog( pMac, LOGW, FL("Scan Completion called but NO commands are ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07005164 fRemoveCommand = eANI_BOOLEAN_FALSE;
5165 }
5166
5167 return( fRemoveCommand );
5168}
5169
5170
5171
5172static void csrScanRemoveDupBssDescriptionFromInterimList( tpAniSirGlobal pMac,
5173 tSirBssDescription *pSirBssDescr,
5174 tDot11fBeaconIEs *pIes)
5175{
5176 tListElem *pEntry;
5177 tCsrScanResult *pCsrBssDescription;
5178
5179 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
5180 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
5181 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
5182 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
5183 while( pEntry )
5184 {
5185 pCsrBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
5186
5187 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
5188 // matches
5189
5190 if ( csrIsDuplicateBssDescription( pMac, &pCsrBssDescription->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07005191 pSirBssDescr, pIes, FALSE ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07005192 {
5193 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
5194 ((tANI_S32)pCsrBssDescription->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
5195
5196 // Remove the 'old' entry from the list....
5197 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK ) )
5198 {
5199 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pCsrBssDescription->Result.BssDescriptor);
5200 // we need to free the memory associated with this node
5201 csrFreeScanResultEntry( pMac, pCsrBssDescription );
5202 }
5203
5204 // If we found a match, we can stop looking through the list.
5205 break;
5206 }
5207
5208 pEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK );
5209 }
5210}
5211
5212
5213
5214//Caller allocated memory pfNewBssForConn to return whether new candidate for
5215//current connection is found. Cannot be NULL
5216tCsrScanResult *csrScanSaveBssDescriptionToInterimList( tpAniSirGlobal pMac,
5217 tSirBssDescription *pBSSDescription,
5218 tDot11fBeaconIEs *pIes)
5219{
5220 tCsrScanResult *pCsrBssDescription = NULL;
5221 tANI_U32 cbBSSDesc;
5222 tANI_U32 cbAllocated;
Jeff Johnson295189b2012-06-20 16:38:30 -07005223
5224 // figure out how big the BSS description is (the BSSDesc->length does NOT
5225 // include the size of the length field itself).
5226 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
5227
5228 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
5229
Kiet Lam64c1b492013-07-12 13:56:44 +05305230 pCsrBssDescription = vos_mem_malloc(cbAllocated);
5231 if ( NULL != pCsrBssDescription )
Jeff Johnson295189b2012-06-20 16:38:30 -07005232 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305233 vos_mem_set(pCsrBssDescription, cbAllocated, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005234 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Kiet Lam64c1b492013-07-12 13:56:44 +05305235 vos_mem_copy(&pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc );
Jeff Johnson295189b2012-06-20 16:38:30 -07005236 //Save SSID separately for later use
5237 if( pIes->SSID.present && !csrIsNULLSSID(pIes->SSID.ssid, pIes->SSID.num_ssid) )
5238 {
5239 //SSID not hidden
Madan Mohan Koyyalamudi4e31b132012-11-02 13:13:52 -07005240 tANI_U32 len = pIes->SSID.num_ssid;
Jeff Johnson295189b2012-06-20 16:38:30 -07005241 if (len > SIR_MAC_MAX_SSID_LENGTH)
5242 {
5243 // truncate to fit in our struct
5244 len = SIR_MAC_MAX_SSID_LENGTH;
5245 }
5246 pCsrBssDescription->Result.ssId.length = len;
5247 pCsrBssDescription->Result.timer = vos_timer_get_system_time();
Kiet Lam64c1b492013-07-12 13:56:44 +05305248 vos_mem_copy(pCsrBssDescription->Result.ssId.ssId, pIes->SSID.ssid, len);
Jeff Johnson295189b2012-06-20 16:38:30 -07005249 }
5250 csrLLInsertTail( &pMac->scan.tempScanResults, &pCsrBssDescription->Link, LL_ACCESS_LOCK );
5251 }
5252
5253 return( pCsrBssDescription );
5254}
5255
5256
5257
5258
5259tANI_BOOLEAN csrIsDuplicateBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc1,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07005260 tSirBssDescription *pSirBssDesc2, tDot11fBeaconIEs *pIes2, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07005261{
5262 tANI_BOOLEAN fMatch = FALSE;
5263 tSirMacCapabilityInfo *pCap1, *pCap2;
5264 tDot11fBeaconIEs *pIes1 = NULL;
Jeff Johnsone7245742012-09-05 17:12:55 -07005265 tDot11fBeaconIEs *pIesTemp = pIes2;
Jeff Johnson295189b2012-06-20 16:38:30 -07005266
5267 pCap1 = (tSirMacCapabilityInfo *)&pSirBssDesc1->capabilityInfo;
5268 pCap2 = (tSirMacCapabilityInfo *)&pSirBssDesc2->capabilityInfo;
5269 if(pCap1->ess == pCap2->ess)
5270 {
5271 if (pCap1->ess &&
Jeff Johnsone7245742012-09-05 17:12:55 -07005272 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId)&&
Abhishek Singhe3fa11f2014-05-13 11:11:10 +05305273 (fForced || (vos_chan_to_band(pSirBssDesc1->channelId) == vos_chan_to_band((pSirBssDesc2->channelId)))))
Jeff Johnson295189b2012-06-20 16:38:30 -07005274 {
5275 fMatch = TRUE;
Jeff Johnsone7245742012-09-05 17:12:55 -07005276 // Check for SSID match, if exists
5277 do
5278 {
5279 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
5280 {
5281 break;
5282 }
5283 if( NULL == pIesTemp )
5284 {
5285 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
5286 {
5287 break;
5288 }
5289 }
5290 if(pIes1->SSID.present && pIesTemp->SSID.present)
5291 {
5292 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
5293 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
5294 }
5295 }while(0);
5296
Jeff Johnson295189b2012-06-20 16:38:30 -07005297 }
5298 else if (pCap1->ibss && (pSirBssDesc1->channelId == pSirBssDesc2->channelId))
5299 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005300
5301 do
5302 {
5303 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
5304 {
5305 break;
5306 }
5307 if( NULL == pIesTemp )
5308 {
5309 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
5310 {
5311 break;
5312 }
5313 }
5314 //Same channel cannot have same SSID for different IBSS
5315 if(pIes1->SSID.present && pIesTemp->SSID.present)
5316 {
5317 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
5318 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
5319 }
5320 }while(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005321 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005322 /* In case of P2P devices, ess and ibss will be set to zero */
5323 else if (!pCap1->ess &&
5324 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId))
5325 {
5326 fMatch = TRUE;
5327 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005328 }
5329
5330 if(pIes1)
5331 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305332 vos_mem_free(pIes1);
Jeff Johnson295189b2012-06-20 16:38:30 -07005333 }
Jeff Johnsone7245742012-09-05 17:12:55 -07005334
5335 if( (NULL == pIes2) && pIesTemp )
5336 {
5337 //locally allocated
Kiet Lam64c1b492013-07-12 13:56:44 +05305338 vos_mem_free(pIesTemp);
Jeff Johnsone7245742012-09-05 17:12:55 -07005339 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005340
5341 return( fMatch );
5342}
5343
5344
5345tANI_BOOLEAN csrIsNetworkTypeEqual( tSirBssDescription *pSirBssDesc1, tSirBssDescription *pSirBssDesc2 )
5346{
5347 return( pSirBssDesc1->nwType == pSirBssDesc2->nwType );
5348}
5349
5350
5351//to check whether the BSS matches the dot11Mode
5352static tANI_BOOLEAN csrScanIsBssAllowed(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
5353 tDot11fBeaconIEs *pIes)
5354{
5355 tANI_BOOLEAN fAllowed = eANI_BOOLEAN_FALSE;
5356 eCsrPhyMode phyMode;
5357
5358 if(HAL_STATUS_SUCCESS(csrGetPhyModeFromBss(pMac, pBssDesc, &phyMode, pIes)))
5359 {
5360 switch(pMac->roam.configParam.phyMode)
5361 {
5362 case eCSR_DOT11_MODE_11b:
5363 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
5364 break;
5365 case eCSR_DOT11_MODE_11g:
5366 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
5367 break;
5368 case eCSR_DOT11_MODE_11g_ONLY:
5369 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11g == phyMode);
5370 break;
5371 case eCSR_DOT11_MODE_11a:
5372 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11b != phyMode) && (eCSR_DOT11_MODE_11g != phyMode));
5373 break;
5374 case eCSR_DOT11_MODE_11n_ONLY:
5375 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11n == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
5376 break;
Jeff Johnsone7245742012-09-05 17:12:55 -07005377
5378#ifdef WLAN_FEATURE_11AC
5379 case eCSR_DOT11_MODE_11ac_ONLY:
5380 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11ac == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
5381 break;
5382#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005383 case eCSR_DOT11_MODE_11b_ONLY:
5384 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11b == phyMode);
5385 break;
5386 case eCSR_DOT11_MODE_11a_ONLY:
5387 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a == phyMode);
5388 break;
5389 case eCSR_DOT11_MODE_11n:
Jeff Johnsone7245742012-09-05 17:12:55 -07005390#ifdef WLAN_FEATURE_11AC
5391 case eCSR_DOT11_MODE_11ac:
5392#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005393 case eCSR_DOT11_MODE_TAURUS:
5394 default:
5395 fAllowed = eANI_BOOLEAN_TRUE;
5396 break;
5397 }
5398 }
5399
5400 return (fAllowed);
5401}
5402
5403
5404
5405//Return pIes to caller for future use when returning TRUE.
5406static tANI_BOOLEAN csrScanValidateScanResult( tpAniSirGlobal pMac, tANI_U8 *pChannels,
5407 tANI_U8 numChn, tSirBssDescription *pBssDesc,
5408 tDot11fBeaconIEs **ppIes )
5409{
5410 tANI_BOOLEAN fValidChannel = FALSE;
5411 tDot11fBeaconIEs *pIes = NULL;
5412 tANI_U8 index;
5413
5414 for( index = 0; index < numChn; index++ )
5415 {
5416 // This check relies on the fact that a single BSS description is returned in each
5417 // ScanRsp call, which is the way LIM implemented the scan req/rsp funtions. We changed
5418 // to this model when we ran with a large number of APs. If this were to change, then
5419 // this check would have to mess with removing the bssDescription from somewhere in an
5420 // arbitrary index in the bssDescription array.
5421 if ( pChannels[ index ] == pBssDesc->channelId )
5422 {
5423 fValidChannel = TRUE;
5424 break;
5425 }
5426 }
5427 *ppIes = NULL;
5428 if(fValidChannel)
5429 {
5430 if( HAL_STATUS_SUCCESS( csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIes) ) )
5431 {
5432 fValidChannel = csrScanIsBssAllowed(pMac, pBssDesc, pIes);
5433 if( fValidChannel )
5434 {
5435 *ppIes = pIes;
5436 }
5437 else
5438 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305439 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07005440 }
5441 }
5442 else
5443 {
5444 fValidChannel = FALSE;
5445 }
5446 }
5447
5448 return( fValidChannel );
5449}
5450
5451
5452//Return whether last scan result is received
5453static tANI_BOOLEAN csrScanProcessScanResults( tpAniSirGlobal pMac, tSmeCmd *pCommand,
5454 tSirSmeScanRsp *pScanRsp, tANI_BOOLEAN *pfRemoveCommand )
5455{
5456 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE, fRemoveCommand = eANI_BOOLEAN_FALSE;
5457 tDot11fBeaconIEs *pIes = NULL;
5458 tANI_U32 cbParsed;
5459 tSirBssDescription *pSirBssDescription;
5460 tANI_U32 cbBssDesc;
Agrawal Ashish4cc15bb2016-02-04 17:56:16 +05305461 eHalStatus status;
Jeff Johnson295189b2012-06-20 16:38:30 -07005462 tANI_U32 cbScanResult = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription )
5463 + sizeof(tSirBssDescription); //We need at least one CB
5464
5465 // don't consider the scan rsp to be valid if the status code is Scan Failure. Scan Failure
5466 // is returned when the scan could not find anything. so if we get scan failure return that
5467 // the scan response is invalid. Also check the lenght in the scan result for valid scan
5468 // BssDescriptions....
5469 do
5470 {
5471 if ( ( cbScanResult <= pScanRsp->length ) &&
5472 (( eSIR_SME_SUCCESS == pScanRsp->statusCode ) ||
5473 ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW == pScanRsp->statusCode ) ) )
5474 {
5475 tANI_U8 *pChannelList = NULL;
5476 tANI_U8 cChannels = 0;
5477
5478 //Different scan type can reach this point, we need to distinguish it
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005479#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5480 if( eCsrScanGetLfrResult == pCommand->u.scanCmd.reason )
5481 {
5482 pChannelList = NULL;
5483 cChannels = 0;
5484 }
5485 else
5486#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005487 if( eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason )
5488 {
5489 //eCsrScanSetBGScanParam uses different structure
5490 tCsrBGScanRequest *pBgScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
5491
5492 cChannels = pBgScanReq->ChannelInfo.numOfChannels;
5493 pChannelList = pBgScanReq->ChannelInfo.ChannelList;
5494 }
5495 else
5496 {
5497 //the rest use generic scan request
5498 cChannels = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
5499 pChannelList = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
5500 }
5501
5502 // if the scan result is not on one of the channels in the Valid channel list, then it
5503 // must have come from an AP on an overlapping channel (in the 2.4GHz band). In this case,
5504 // let's drop the scan result.
5505 //
5506 // The other situation is where the scan request is for a scan on a particular channel set
5507 // and the scan result is from a
5508
5509 // if the NumChannels is 0, then we are supposed to be scanning all channels. Use the full channel
5510 // list as the 'valid' channel list. Otherwise, use the specific channel list in the scan parms
5511 // as the valid channels.
5512 if ( 0 == cChannels )
5513 {
5514 tANI_U32 len = sizeof(pMac->roam.validChannelList);
5515
5516 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
5517 {
5518 pChannelList = pMac->roam.validChannelList;
5519 cChannels = (tANI_U8)len;
5520 }
5521 else
5522 {
5523 //Cannot continue
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005524 smsLog( pMac, LOGE, "CSR: Processing internal SCAN results...csrGetCfgValidChannels failed" );
Jeff Johnson295189b2012-06-20 16:38:30 -07005525 break;
5526 }
5527 }
5528
5529 smsLog( pMac, LOG2, "CSR: Processing internal SCAN results..." );
5530 cbParsed = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription );
5531 pSirBssDescription = pScanRsp->bssDescription;
5532 while( cbParsed < pScanRsp->length )
5533 {
5534 if ( csrScanValidateScanResult( pMac, pChannelList, cChannels, pSirBssDescription, &pIes ) )
5535 {
5536 csrScanRemoveDupBssDescriptionFromInterimList(pMac, pSirBssDescription, pIes);
5537 csrScanSaveBssDescriptionToInterimList( pMac, pSirBssDescription, pIes );
5538 if( eSIR_PASSIVE_SCAN == pMac->scan.curScanType )
5539 {
5540 if( csrIs11dSupported( pMac) )
5541 {
5542 //Check whether the BSS is acceptable base on 11d info and our configs.
5543 if( csrMatchCountryCode( pMac, NULL, pIes ) )
5544 {
5545 //Double check whether the channel is acceptable by us.
5546 if( csrIsSupportedChannel( pMac, pSirBssDescription->channelId ) )
5547 {
5548 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
5549 }
5550 }
5551 }
5552 else
5553 {
5554 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
5555 }
5556 }
5557 //Free the resource
Kiet Lam64c1b492013-07-12 13:56:44 +05305558 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07005559 }
5560 // skip over the BSS description to the next one...
5561 cbBssDesc = pSirBssDescription->length + sizeof( pSirBssDescription->length );
5562
5563 cbParsed += cbBssDesc;
5564 pSirBssDescription = (tSirBssDescription *)((tANI_U8 *)pSirBssDescription + cbBssDesc );
5565
5566 } //while
5567 }
5568 else
5569 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005570 smsLog( pMac, LOGW, " Scanrsp fail (0x%08X), length = %d (expected %d)",
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08005571 pScanRsp->statusCode, pScanRsp->length, cbScanResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07005572 //HO bg scan/probe failed no need to try autonomously
5573 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
5574 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005575#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5576 eCsrScanGetLfrResult == pCommand->u.scanCmd.reason ||
5577#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005578 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
5579 {
5580 fRemoveCommand = eANI_BOOLEAN_TRUE;
5581 }
5582 }
5583 }while(0);
5584 if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
5585 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005586 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 -07005587 fRemoveCommand = csrScanComplete( pMac, pScanRsp );
5588 fRet = eANI_BOOLEAN_TRUE;
5589 }//if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
5590 if(pfRemoveCommand)
5591 {
5592 *pfRemoveCommand = fRemoveCommand;
5593 }
5594
Agrawal Ashish4cc15bb2016-02-04 17:56:16 +05305595 /*
5596 * Currently SET_FCC_CHANNEL issues updated channel list to fw.
5597 * At the time of driver load, if scan is issued followed with
5598 * SET_FCC_CHANNEL, driver will send update channel list to fw.
5599 * Fw will stop ongoing scan because of that GUI will have very less
5600 * scan list.
5601 * Update channel list should be sent to fw once scan is done
5602 */
5603 if (pMac->scan.defer_update_channel_list) {
5604 status = csrUpdateChannelList(pMac);
5605 if (eHAL_STATUS_SUCCESS != status)
5606 smsLog(pMac, LOGE,
5607 FL( "failed to update the supported channel list"));
5608 pMac->scan.defer_update_channel_list = false;
5609 }
5610
Jeff Johnson295189b2012-06-20 16:38:30 -07005611#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305612 if (pMac->fScanOffload)
5613 return fRet;
5614
Jeff Johnson295189b2012-06-20 16:38:30 -07005615 if (!csrLLIsListEmpty( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK ))
5616 {
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005617 /* Pending scan commands in the list because the previous scan command
5618 * was split into a scan command on one channel + a scan command for all
5619 * remaining channels.
5620 *
5621 * Start timer to trigger processing of the next scan command.
Srikant Kuppa866893f2012-12-27 17:28:14 -08005622 * NOTE for LFR:
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305623 * Do not split scans if no concurrent infra connections are
Srikant Kuppa866893f2012-12-27 17:28:14 -08005624 * active and if the scan is a BG scan triggered by LFR (OR)
5625 * any scan if LFR is in the middle of a BG scan. Splitting
5626 * the scan is delaying the time it takes for LFR to find
5627 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005628 */
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305629 if ( (csrIsStaSessionConnected(pMac) &&
Srikant Kuppa866893f2012-12-27 17:28:14 -08005630#ifdef FEATURE_WLAN_LFR
5631 (csrIsConcurrentInfraConnected(pMac) ||
5632 ((pCommand->u.scanCmd.reason != eCsrScanBgScan) &&
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305633 (pMac->roam.neighborRoamInfo.neighborRoamState !=
Srikant Kuppa866893f2012-12-27 17:28:14 -08005634 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
5635#endif
5636 (pCommand->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305637 (csrIsP2pSessionConnected(pMac)) )
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005638 {
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005639 /* if active connected sessions present then continue to split scan
5640 * with specified interval between consecutive scans */
5641 csrSetDefaultScanTiming(pMac, pCommand->u.scanCmd.u.scanRequest.scanType, &(pCommand->u.scanCmd.u.scanRequest));
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05305642 vos_timer_start(&pMac->scan.hTimerStaApConcTimer,
5643 pCommand->u.scanCmd.u.scanRequest.restTime);
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005644 } else {
5645 /* if no connected sessions present then initiate next scan command immediately */
5646 /* minimum timer granularity is 10ms */
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05305647 vos_timer_start(&pMac->scan.hTimerStaApConcTimer, 10);
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005648 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005649 }
5650#endif
5651 return (fRet);
5652}
5653
5654
5655tANI_BOOLEAN csrScanIsWildCardScan( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5656{
5657 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
Kiet Lam64c1b492013-07-12 13:56:44 +05305658 tANI_BOOLEAN f = vos_mem_compare(pCommand->u.scanCmd.u.scanRequest.bssid,
5659 bssid, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07005660
5661 //It is not a wild card scan if the bssid is not broadcast and the number of SSID is 1.
5662 return ((tANI_BOOLEAN)( (f || (0xff == pCommand->u.scanCmd.u.scanRequest.bssid[0])) &&
5663 (pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs != 1) ));
5664}
5665
5666
5667eHalStatus csrScanSmeScanResponse( tpAniSirGlobal pMac, void *pMsgBuf )
5668{
5669 eHalStatus status = eHAL_STATUS_SUCCESS;
5670 tListElem *pEntry;
5671 tSmeCmd *pCommand;
5672 eCsrScanStatus scanStatus;
Sunkad, Anand Ningappa3ec8bf72016-02-05 15:13:30 +05305673 tSirSmeScanRsp *pScanRsp;
Jeff Johnson295189b2012-06-20 16:38:30 -07005674 tSmeGetScanChnRsp *pScanChnInfo;
5675 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
5676 eCsrScanReason reason = eCsrScanOther;
5677
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305678 if (pMac->fScanOffload)
5679 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList,
5680 LL_ACCESS_LOCK);
5681 else
5682 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07005683
5684 if ( pEntry )
5685 {
5686 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
5687 if ( eSmeCommandScan == pCommand->command )
5688 {
Deepthi Gowrife5340b2016-04-11 12:15:46 +05305689 /* Purge the scan results based on Aging */
5690 if (pEntry && pMac->scan.scanResultCfgAgingTime)
5691 csrPurgeScanResultByAge(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07005692 reason = pCommand->u.scanCmd.reason;
5693 switch(pCommand->u.scanCmd.reason)
5694 {
5695 case eCsrScanAbortBgScan:
5696 case eCsrScanAbortNormalScan:
5697 case eCsrScanBGScanAbort:
5698 case eCsrScanBGScanEnable:
Sunkad, Anand Ningappa3ec8bf72016-02-05 15:13:30 +05305699 pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
5700 scanStatus = (eSIR_SME_SUCCESS == pScanRsp->statusCode) ?
5701 eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005702 break;
5703 case eCsrScanGetScanChnInfo:
Deepthi Gowrife5340b2016-04-11 12:15:46 +05305704 pScanChnInfo = (tSmeGetScanChnRsp *)pMsgBuf;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005705 /*
5706 * status code not available in tSmeGetScanChnRsp, so
5707 * by default considereing it to be success
5708 */
5709 scanStatus = eSIR_SME_SUCCESS;
Deepthi Gowrife5340b2016-04-11 12:15:46 +05305710 csrScanAgeResults(pMac, pScanChnInfo);
Jeff Johnson295189b2012-06-20 16:38:30 -07005711 break;
5712 case eCsrScanForCapsChange:
Sunkad, Anand Ningappa3ec8bf72016-02-05 15:13:30 +05305713 pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
5714 scanStatus = (eSIR_SME_SUCCESS == pScanRsp->statusCode) ?
5715 eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005716 csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand );
5717 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005718 case eCsrScanP2PFindPeer:
Sunkad, Anand Ningappa3ec8bf72016-02-05 15:13:30 +05305719 pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
5720 scanStatus = ((eSIR_SME_SUCCESS == pScanRsp->statusCode) &&
5721 (pScanRsp->length > 50)) ? eCSR_SCAN_FOUND_PEER : eCSR_SCAN_FAILURE;
5722 csrScanProcessScanResults( pMac, pCommand, pScanRsp, NULL );
5723 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005724 case eCsrScanSetBGScanParam:
5725 default:
Sunkad, Anand Ningappa3ec8bf72016-02-05 15:13:30 +05305726 pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
5727 scanStatus = (eSIR_SME_SUCCESS == pScanRsp->statusCode) ?
5728 eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005729 if(csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand ))
5730 {
5731 //Not to get channel info if the scan is not a wildcard scan because
5732 //it may cause scan results got aged out incorrectly.
Ratheesh S Pece1f832015-07-25 15:50:25 +05305733 if(csrScanIsWildCardScan( pMac, pCommand ) &&
5734 (!pCommand->u.scanCmd.u.scanRequest.p2pSearch)
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005735#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5736 && (pCommand->u.scanCmd.reason != eCsrScanGetLfrResult)
5737#endif
5738 )
Jeff Johnson295189b2012-06-20 16:38:30 -07005739 {
Ratheesh S Pece1f832015-07-25 15:50:25 +05305740 csrScanGetScanChnInfo(pMac, pCommand);
Jeff Johnson295189b2012-06-20 16:38:30 -07005741 }
5742 }
5743 break;
5744 }//switch
5745 if(fRemoveCommand)
5746 {
5747
5748 csrReleaseScanCommand(pMac, pCommand, scanStatus);
5749
Sunkad, Anand Ningappa3ec8bf72016-02-05 15:13:30 +05305750 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005751 smeProcessPendingQueue( pMac );
5752 }
5753 else
5754 {
5755 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
5756 status = eHAL_STATUS_FAILURE;
5757 }
5758 }
5759 else
5760 {
5761 smsLog( pMac, LOGW, "CSR: Scan Completion called but NO commands are ACTIVE ..." );
5762 status = eHAL_STATUS_FAILURE;
5763 }
5764
5765 return (status);
5766}
5767
5768
5769
5770
5771tCsrScanResultInfo *csrScanResultGetFirst(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
5772{
5773 tListElem *pEntry;
5774 tCsrScanResult *pResult;
5775 tCsrScanResultInfo *pRet = NULL;
5776 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5777
5778 if(pResultList)
5779 {
5780 csrLLLock(&pResultList->List);
5781 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5782 if(pEntry)
5783 {
5784 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
5785 pRet = &pResult->Result;
5786 }
5787 pResultList->pCurEntry = pEntry;
5788 csrLLUnlock(&pResultList->List);
5789 }
5790
5791 return pRet;
5792}
5793
5794
5795tCsrScanResultInfo *csrScanResultGetNext(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
5796{
5797 tListElem *pEntry = NULL;
5798 tCsrScanResult *pResult = NULL;
5799 tCsrScanResultInfo *pRet = NULL;
5800 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5801
5802 if(pResultList)
5803 {
5804 csrLLLock(&pResultList->List);
5805 if(NULL == pResultList->pCurEntry)
5806 {
5807 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5808 }
5809 else
5810 {
5811 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
5812 }
5813 if(pEntry)
5814 {
5815 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
5816 pRet = &pResult->Result;
5817 }
5818 pResultList->pCurEntry = pEntry;
5819 csrLLUnlock(&pResultList->List);
5820 }
5821
5822 return pRet;
5823}
5824
5825
5826//This function moves the first BSS that matches the bssid to the head of the result
5827eHalStatus csrMoveBssToHeadFromBSSID(tpAniSirGlobal pMac, tCsrBssid *bssid, tScanResultHandle hScanResult)
5828{
5829 eHalStatus status = eHAL_STATUS_FAILURE;
5830 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5831 tCsrScanResult *pResult = NULL;
5832 tListElem *pEntry = NULL;
5833
5834 if(pResultList && bssid)
5835 {
5836 csrLLLock(&pResultList->List);
5837 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5838 while(pEntry)
5839 {
5840 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
Kiet Lam64c1b492013-07-12 13:56:44 +05305841 if (vos_mem_compare(bssid, pResult->Result.BssDescriptor.bssId, sizeof(tCsrBssid)))
Jeff Johnson295189b2012-06-20 16:38:30 -07005842 {
5843 status = eHAL_STATUS_SUCCESS;
5844 csrLLRemoveEntry(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
5845 csrLLInsertHead(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
5846 break;
5847 }
5848 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
5849 }
5850 csrLLUnlock(&pResultList->List);
5851 }
5852
5853 return (status);
5854}
5855
5856
5857//Remove the BSS if possible.
5858//Return -- TRUE == the BSS is remove. False == Fail to remove it
5859//This function is called when list lock is held. Be caution what functions it can call.
5860tANI_BOOLEAN csrScanAgeOutBss(tpAniSirGlobal pMac, tCsrScanResult *pResult)
5861{
5862 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
5863 tANI_U32 i;
5864 tCsrRoamSession *pSession;
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305865 tANI_BOOLEAN isConnBssfound = eANI_BOOLEAN_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005866
5867 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5868 {
5869 if( CSR_IS_SESSION_VALID( pMac, i ) )
5870 {
5871 pSession = CSR_GET_SESSION( pMac, i );
5872 //Not to remove the BSS we are connected to.
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305873 if(csrIsConnStateConnectedInfra(pMac, i) && (NULL != pSession->pConnectBssDesc) &&
5874 (csrIsDuplicateBssDescription(pMac, &pResult->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07005875 pSession->pConnectBssDesc, NULL, FALSE))
Jeff Johnson295189b2012-06-20 16:38:30 -07005876 )
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305877 {
5878 isConnBssfound = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005879 break;
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305880 }
5881 }
5882 }
5883
5884 if( isConnBssfound )
Jeff Johnson295189b2012-06-20 16:38:30 -07005885 {
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305886 //Reset the counter so that aging out of connected BSS won't hapeen too soon
Jeff Johnson295189b2012-06-20 16:38:30 -07005887 pResult->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Deepthi Gowri4480a3f2016-05-18 19:30:17 +05305888 pResult->Result.BssDescriptor.nReceivedTime =
5889 vos_timer_get_system_time();
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305890
5891 return (fRet);
5892 }
5893 else
5894 {
5895 smsLog(pMac, LOGW, "Aging out BSS "MAC_ADDRESS_STR" Channel %d",
5896 MAC_ADDR_ARRAY(pResult->Result.BssDescriptor.bssId),
5897 pResult->Result.BssDescriptor.channelId);
5898 //No need to hold the spin lock because caller should hold the lock for pMac->scan.scanResultList
5899 if( csrLLRemoveEntry(&pMac->scan.scanResultList, &pResult->Link, LL_ACCESS_NOLOCK) )
5900 {
5901 if (csrIsMacAddressEqual(pMac,
5902 (tCsrBssid *) pResult->Result.BssDescriptor.bssId,
5903 (tCsrBssid *) pMac->scan.currentCountryBssid))
5904 {
5905 smsLog(pMac, LOGW, "Aging out 11d BSS "MAC_ADDRESS_STR,
5906 MAC_ADDR_ARRAY(pResult->Result.BssDescriptor.bssId));
5907 pMac->scan.currentCountryRSSI = -128;
5908 }
5909 csrFreeScanResultEntry(pMac, pResult);
5910 fRet = eANI_BOOLEAN_TRUE;
5911 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005912 }
5913
5914 return (fRet);
5915}
5916
5917
5918eHalStatus csrScanAgeResults(tpAniSirGlobal pMac, tSmeGetScanChnRsp *pScanChnInfo)
5919{
5920 eHalStatus status = eHAL_STATUS_SUCCESS;
5921 tListElem *pEntry, *tmpEntry;
5922 tCsrScanResult *pResult;
5923 tLimScanChn *pChnInfo;
5924 tANI_U8 i;
5925
5926 csrLLLock(&pMac->scan.scanResultList);
5927 for(i = 0; i < pScanChnInfo->numChn; i++)
5928 {
5929 pChnInfo = &pScanChnInfo->scanChn[i];
5930 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
5931 while( pEntry )
5932 {
5933 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
5934 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
5935 if(pResult->Result.BssDescriptor.channelId == pChnInfo->channelId)
5936 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005937 if(pResult->AgingCount <= 0)
5938 {
5939 smsLog(pMac, LOGW, " age out due to ref count");
5940 csrScanAgeOutBss(pMac, pResult);
5941 }
Madan Mohan Koyyalamudib9d3dcc2012-09-28 16:47:50 -07005942 else
5943 {
5944 pResult->AgingCount--;
5945 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005946 }
5947 pEntry = tmpEntry;
5948 }
5949 }
5950 csrLLUnlock(&pMac->scan.scanResultList);
5951
5952 return (status);
5953}
5954
Abhishek Singhc640dbb2015-06-08 10:54:17 +05305955eHalStatus csrIbssAgeBss(tpAniSirGlobal pMac)
5956{
5957 eHalStatus status = eHAL_STATUS_SUCCESS;
5958 tListElem *pEntry, *tmpEntry;
5959 tCsrScanResult *pResult;
5960
5961 csrLLLock(&pMac->scan.scanResultList);
5962 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
5963 while( pEntry )
5964 {
5965 tmpEntry = csrLLNext(&pMac->scan.scanResultList,
5966 pEntry, LL_ACCESS_NOLOCK);
5967 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
5968
5969 smsLog(pMac, LOGW, FL(" age out due Forced IBSS leave"));
5970 csrScanAgeOutBss(pMac, pResult);
5971 pEntry = tmpEntry;
5972 }
5973 csrLLUnlock(&pMac->scan.scanResultList);
5974
5975 return (status);
5976}
Jeff Johnson295189b2012-06-20 16:38:30 -07005977
Abhishek Singh72c2f4e2016-07-22 11:25:43 +05305978/**
5979 * csr_remove_bssid_from_scan_list() - remove the bssid from
5980 * scan list
5981 * @pMac: mac context.
5982 * @bssid: bssid to be removed
5983 *
5984 * This function remove the given bssid from scan list.
5985 *
5986 * Return: void.
5987 */
5988void csr_remove_bssid_from_scan_list(tpAniSirGlobal pMac,
5989 tSirMacAddr bssid)
5990{
5991 tListElem *entry,*free_elem;
5992 tCsrScanResult *bss_desc;
5993 tDblLinkList *list = &pMac->scan.scanResultList;
5994
5995 csrLLLock(list);
5996 entry = csrLLPeekHead(list, LL_ACCESS_NOLOCK);
5997 while (entry != NULL) {
5998 bss_desc = GET_BASE_ADDR( entry, tCsrScanResult, Link);
5999 if (vos_mem_compare(bss_desc->Result.BssDescriptor.bssId,
6000 bssid, sizeof(tSirMacAddr))) {
6001 free_elem = entry;
6002 entry = csrLLNext(list, entry, LL_ACCESS_NOLOCK);
6003 csrLLRemoveEntry(list, free_elem, LL_ACCESS_NOLOCK);
6004 csrFreeScanResultEntry(pMac, bss_desc);
6005 smsLog(pMac, LOGW, FL("Removed BSS entry:%pM"),
6006 bssid);
6007 continue;
6008 }
6009 entry = csrLLNext(list, entry, LL_ACCESS_NOLOCK);
6010 }
6011 csrLLUnlock(list);
6012}
6013
Jeff Johnson295189b2012-06-20 16:38:30 -07006014eHalStatus csrSendMBScanReq( tpAniSirGlobal pMac, tANI_U16 sessionId,
6015 tCsrScanRequest *pScanReq, tScanReqParam *pScanReqParam )
6016{
6017 eHalStatus status = eHAL_STATUS_SUCCESS;
6018 tSirSmeScanReq *pMsg;
6019 tANI_U16 msgLen;
6020 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
6021 tSirScanType scanType = pScanReq->scanType;
6022 tANI_U32 minChnTime; //in units of milliseconds
6023 tANI_U32 maxChnTime; //in units of milliseconds
6024 tANI_U32 i;
6025 tANI_U8 selfMacAddr[WNI_CFG_BSSID_LEN];
6026 tANI_U8 *pSelfMac = NULL;
6027
6028 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
6029 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) +
6030 ( pScanReq->uIEFieldLen ) ;
6031
Kiet Lam64c1b492013-07-12 13:56:44 +05306032 pMsg = vos_mem_malloc(msgLen);
6033 if ( NULL == pMsg )
6034 status = eHAL_STATUS_FAILURE;
6035 else
6036 status = eHAL_STATUS_SUCCESS;
6037 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07006038 {
6039 do
6040 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306041 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006042 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
6043 pMsg->length = pal_cpu_to_be16(msgLen);
6044 //ToDO: Fill in session info when we need to do scan base on session.
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05306045 if ((pMac->fScanOffload) && (sessionId != CSR_SESSION_ID_INVALID))
6046 {
6047 pMsg->sessionId = sessionId;
6048 }
6049 else
6050 {
6051 /* if sessionId == CSR_SESSION_ID_INVALID, then send the scan
6052 request on first available session */
6053 pMsg->sessionId = 0;
6054 }
6055
Jeff Johnson295189b2012-06-20 16:38:30 -07006056 pMsg->transactionId = 0;
6057 pMsg->dot11mode = (tANI_U8) csrTranslateToWNICfgDot11Mode(pMac, csrFindBestPhyMode( pMac, pMac->roam.configParam.phyMode ));
6058 pMsg->bssType = pal_cpu_to_be32(csrTranslateBsstypeToMacType(pScanReq->BSSType));
6059
6060 if ( CSR_IS_SESSION_VALID( pMac, sessionId ) )
6061 {
6062 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[sessionId].selfMacAddr;
6063 }
6064 else
6065 {
6066 // Since we don't have session for the scanning, we find a valid session. In case we fail to
6067 // do so, get the WNI_CFG_STA_ID
6068 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
6069 {
6070 if( CSR_IS_SESSION_VALID( pMac, i ) )
6071 {
6072 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[i].selfMacAddr;
6073 break;
6074 }
6075 }
6076 if( CSR_ROAM_SESSION_MAX == i )
6077 {
6078 tANI_U32 len = WNI_CFG_BSSID_LEN;
6079 pSelfMac = selfMacAddr;
6080 status = ccmCfgGetStr( pMac, WNI_CFG_STA_ID, pSelfMac, &len );
6081 if( !HAL_STATUS_SUCCESS( status ) ||
6082 ( len < WNI_CFG_BSSID_LEN ) )
6083 {
6084 smsLog( pMac, LOGE, FL(" Can not get self MAC address from CFG status = %d"), status );
6085 //Force failed status
6086 status = eHAL_STATUS_FAILURE;
6087 break;
6088 }
6089 }
6090 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306091 vos_mem_copy((tANI_U8 *)pMsg->selfMacAddr, pSelfMac, sizeof(tSirMacAddr));
Jeff Johnson295189b2012-06-20 16:38:30 -07006092
6093 //sirCopyMacAddr
Kiet Lam64c1b492013-07-12 13:56:44 +05306094 vos_mem_copy((tANI_U8 *)pMsg->bssId, (tANI_U8 *)&pScanReq->bssid, sizeof(tSirMacAddr));
6095 if ( vos_mem_compare(pScanReq->bssid, bssid, sizeof(tCsrBssid)))
Jeff Johnson295189b2012-06-20 16:38:30 -07006096 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306097 vos_mem_set(pMsg->bssId, sizeof(tSirMacAddr), 0xff);
Jeff Johnson295189b2012-06-20 16:38:30 -07006098 }
6099 else
6100 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306101 vos_mem_copy(pMsg->bssId, pScanReq->bssid, WNI_CFG_BSSID_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07006102 }
6103 minChnTime = pScanReq->minChnTime;
6104 maxChnTime = pScanReq->maxChnTime;
6105
6106 //Verify the scan type first, if the scan is active scan, we need to make sure we
6107 //are allowed to do so.
6108 /* if 11d is enabled & we don't see any beacon around, scan type falls
6109 back to passive. But in BT AMP STA mode we need to send out a
6110 directed probe*/
6111 if( (eSIR_PASSIVE_SCAN != scanType) && (eCSR_SCAN_P2P_DISCOVERY != pScanReq->requestType)
6112 && (eCSR_BSS_TYPE_WDS_STA != pScanReq->BSSType)
6113 && (eANI_BOOLEAN_FALSE == pMac->scan.fEnableBypass11d))
6114 {
6115 scanType = pMac->scan.curScanType;
6116 if(eSIR_PASSIVE_SCAN == pMac->scan.curScanType)
6117 {
6118 if(minChnTime < pMac->roam.configParam.nPassiveMinChnTime)
6119 {
6120 minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
6121 }
6122 if(maxChnTime < pMac->roam.configParam.nPassiveMaxChnTime)
6123 {
6124 maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
6125 }
6126 }
6127 }
6128 pMsg->scanType = pal_cpu_to_be32(scanType);
6129
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306130 pMsg->numSsid =
6131 (pScanReq->SSIDs.numOfSSIDs < SIR_SCAN_MAX_NUM_SSID) ?
6132 pScanReq->SSIDs.numOfSSIDs : SIR_SCAN_MAX_NUM_SSID;
Jeff Johnson295189b2012-06-20 16:38:30 -07006133 if((pScanReq->SSIDs.numOfSSIDs != 0) && ( eSIR_PASSIVE_SCAN != scanType ))
6134 {
Jeff Johnson40b59aa2013-03-19 14:43:18 -07006135 for (i = 0; i < pMsg->numSsid; i++)
6136 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306137 vos_mem_copy(&pMsg->ssId[i],
6138 &pScanReq->SSIDs.SSIDList[i].SSID, sizeof(tSirMacSSid));
Jeff Johnson40b59aa2013-03-19 14:43:18 -07006139 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006140 }
6141 else
6142 {
6143 //Otherwise we scan all SSID and let the result filter later
Jeff Johnson40b59aa2013-03-19 14:43:18 -07006144 for (i = 0; i < SIR_SCAN_MAX_NUM_SSID; i++)
6145 {
6146 pMsg->ssId[i].length = 0;
6147 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006148 }
6149
Jeff Johnson295189b2012-06-20 16:38:30 -07006150 pMsg->minChannelTime = pal_cpu_to_be32(minChnTime);
6151 pMsg->maxChannelTime = pal_cpu_to_be32(maxChnTime);
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08006152 pMsg->minChannelTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
6153 pMsg->maxChannelTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07006154 //hidden SSID option
6155 pMsg->hiddenSsid = pScanReqParam->hiddenSsid;
6156 //rest time
6157 //pMsg->restTime = pScanReq->restTime;
6158 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
6159 // All the scan results caching will be done by Roaming
6160 // We do not want LIM to do any caching of scan results,
6161 // so delete the LIM cache on all scan requests
6162 pMsg->returnFreshResults = pScanReqParam->freshScan;
6163 //Always ask for unique result
6164 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
6165 pMsg->channelList.numChannels = (tANI_U8)pScanReq->ChannelInfo.numOfChannels;
6166 if(pScanReq->ChannelInfo.numOfChannels)
6167 {
6168 //Assuming the channelNumber is tANI_U8 (1 byte)
Kiet Lam64c1b492013-07-12 13:56:44 +05306169 vos_mem_copy(pMsg->channelList.channelNumber,
6170 pScanReq->ChannelInfo.ChannelList,
6171 pScanReq->ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07006172 }
6173
6174 pMsg->uIEFieldLen = (tANI_U16) pScanReq->uIEFieldLen;
6175 pMsg->uIEFieldOffset = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
6176 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) ;
6177 if(pScanReq->uIEFieldLen != 0)
6178 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306179 vos_mem_copy((tANI_U8 *)pMsg+pMsg->uIEFieldOffset, pScanReq->pIEField,
6180 pScanReq->uIEFieldLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07006181 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006182 pMsg->p2pSearch = pScanReq->p2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07006183
Madan Mohan Koyyalamudi9b876782012-10-11 16:22:51 -07006184 if (pScanReq->requestType == eCSR_SCAN_HO_BG_SCAN)
6185 {
6186 pMsg->backgroundScanMode = eSIR_ROAMING_SCAN;
6187 }
6188
Jeff Johnson295189b2012-06-20 16:38:30 -07006189 }while(0);
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05306190 smsLog(pMac, LOG1, FL("domainIdCurrent %s (%d) scanType %s (%d)"
6191 "bssType %s (%d), requestType %s(%d)"
6192 "numChannels %d"),
6193 voss_DomainIdtoString(pMac->scan.domainIdCurrent),
6194 pMac->scan.domainIdCurrent,
6195 lim_ScanTypetoString(pMsg->scanType), pMsg->scanType,
6196 lim_BssTypetoString(pMsg->bssType), pMsg->bssType,
6197 sme_requestTypetoString(pScanReq->requestType),
6198 pScanReq->requestType,
6199 pMsg->channelList.numChannels);
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08006200
6201 for(i = 0; i < pMsg->channelList.numChannels; i++)
6202 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006203 smsLog(pMac, LOG3, FL("channelNumber[%d]= %d"), i, pMsg->channelList.channelNumber[i]);
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08006204 }
6205
Jeff Johnson295189b2012-06-20 16:38:30 -07006206 if(HAL_STATUS_SUCCESS(status))
6207 {
6208 status = palSendMBMessage(pMac->hHdd, pMsg);
6209 }
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08006210 else
6211 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006212 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d"), status );
Kiet Lam64c1b492013-07-12 13:56:44 +05306213 vos_mem_free(pMsg);
Jeff Johnson295189b2012-06-20 16:38:30 -07006214 }
6215 }//Success allocated memory
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08006216 else
6217 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006218 smsLog( pMac, LOGE, FL(" memory allocation failure"));
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08006219 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006220
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306221 if(!HAL_STATUS_SUCCESS(status))
6222 {
6223 smsLog( pMac, LOG1, FL("Failed: SId: %d FirstMatch = %d"
6224 " UniqueResult = %d freshScan = %d hiddenSsid = %d"),
6225 sessionId, pScanReqParam->bReturnAfter1stMatch,
6226 pScanReqParam->fUniqueResult, pScanReqParam->freshScan,
6227 pScanReqParam->hiddenSsid );
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05306228 smsLog( pMac, LOG1, FL("scanType = %s (%d) BSSType = %s (%d) "
6229 "numOfSSIDs = %d numOfChannels = %d requestType = %s (%d)"
6230 " p2pSearch = %d\n"),
6231 lim_ScanTypetoString(pScanReq->scanType),
6232 pScanReq->scanType,
6233 lim_BssTypetoString(pScanReq->BSSType),
6234 pScanReq->BSSType,
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306235 pScanReq->SSIDs.numOfSSIDs,
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05306236 pScanReq->ChannelInfo.numOfChannels,
6237 sme_requestTypetoString(pScanReq->requestType),
6238 pScanReq->requestType,
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306239 pScanReq->p2pSearch );
6240
6241 }
6242
Jeff Johnson295189b2012-06-20 16:38:30 -07006243 return( status );
6244}
6245
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006246eHalStatus csrSendMBScanResultReq( tpAniSirGlobal pMac, tANI_U32 sessionId, tScanReqParam *pScanReqParam )
Jeff Johnson295189b2012-06-20 16:38:30 -07006247{
6248 eHalStatus status = eHAL_STATUS_SUCCESS;
6249 tSirSmeScanReq *pMsg;
6250 tANI_U16 msgLen;
6251
6252 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ));
Kiet Lam64c1b492013-07-12 13:56:44 +05306253 pMsg = vos_mem_malloc(msgLen);
6254 if ( NULL == pMsg )
6255 status = eHAL_STATUS_FAILURE;
6256 else
Jeff Johnson295189b2012-06-20 16:38:30 -07006257 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306258 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006259 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
6260 pMsg->length = pal_cpu_to_be16(msgLen);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006261 pMsg->sessionId = sessionId;
6262 pMsg->transactionId = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07006263 pMsg->returnFreshResults = pScanReqParam->freshScan;
6264 //Always ask for unique result
6265 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
6266 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
6267 status = palSendMBMessage(pMac->hHdd, pMsg);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006268 if (!HAL_STATUS_SUCCESS(status))
6269 {
6270 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d\n"), status );
6271 }
6272
Jeff Johnson295189b2012-06-20 16:38:30 -07006273 }
6274
6275 return( status );
6276}
6277
6278
6279
6280eHalStatus csrScanChannels( tpAniSirGlobal pMac, tSmeCmd *pCommand )
6281{
6282 eHalStatus status = eHAL_STATUS_FAILURE;
6283 tScanReqParam scanReq;
6284
6285 do
6286 {
6287 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE | TRUE;
6288 scanReq.fUniqueResult = TRUE;
6289 scanReq.hiddenSsid = SIR_SCAN_NO_HIDDEN_SSID;
6290 if(eCsrScanForSsid == pCommand->u.scanCmd.reason)
6291 {
6292 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_FIRST_MATCH;
6293 }
6294 else
6295 {
6296 // Basically do scan on all channels even for 11D 1st scan case.
6297 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
6298 }
6299 if((eCsrScanBgScan == pCommand->u.scanCmd.reason)||
6300 (eCsrScanProbeBss == pCommand->u.scanCmd.reason))
6301 {
6302 scanReq.hiddenSsid = SIR_SCAN_HIDDEN_SSID_PE_DECISION;
6303 }
6304
6305#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
6306 {
6307 vos_log_scan_pkt_type *pScanLog = NULL;
6308
6309 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
6310 if(pScanLog)
6311 {
6312 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
6313 eCsrScanProbeBss == pCommand->u.scanCmd.reason)
6314 {
6315 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
6316 }
6317 else
6318 {
6319 if( (eSIR_PASSIVE_SCAN != pCommand->u.scanCmd.u.scanRequest.scanType) &&
6320 (eSIR_PASSIVE_SCAN != pMac->scan.curScanType) )
6321 {
6322 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_REQ;
6323 }
6324 else
6325 {
6326 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_REQ;
6327 }
6328 }
6329 pScanLog->minChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.minChnTime;
6330 pScanLog->maxChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.maxChnTime;
6331 pScanLog->numChannel = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
6332 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
6333 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306334 vos_mem_copy(pScanLog->channels,
6335 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
6336 pScanLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07006337 }
6338 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
6339 }
6340 }
6341#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
6342
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05306343 csrClearVotesForCountryInfo(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07006344 status = csrSendMBScanReq(pMac, pCommand->sessionId,
6345 &pCommand->u.scanCmd.u.scanRequest, &scanReq);
6346 }while(0);
6347
6348 return( status );
6349}
6350
6351
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006352eHalStatus csrScanRetrieveResult(tpAniSirGlobal pMac, tSmeCmd *pCommand)
Jeff Johnson295189b2012-06-20 16:38:30 -07006353{
6354 eHalStatus status = eHAL_STATUS_FAILURE;
6355 tScanReqParam scanReq;
6356
6357 do
6358 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006359#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
6360 if (eCsrScanGetLfrResult == pCommand->u.scanCmd.reason)
6361 {
6362 //to get the LFR candidates from PE cache
6363 scanReq.freshScan = SIR_BG_SCAN_RETURN_LFR_CACHED_RESULTS|SIR_BG_SCAN_PURGE_LFR_RESULTS;
6364 scanReq.fUniqueResult = TRUE;
6365 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
6366 }
6367 else
6368#endif
6369 {
6370 //not a fresh scan
6371 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE;
6372 scanReq.fUniqueResult = TRUE;
6373 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
6374 }
6375 status = csrSendMBScanResultReq(pMac, pCommand->sessionId, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07006376 }while(0);
6377
6378 return (status);
6379}
6380
Siddharth Bhald8a95e82015-02-12 20:14:52 +05306381eHalStatus csrProcessMacAddrSpoofCommand( tpAniSirGlobal pMac, tSmeCmd *pCommand )
6382{
6383 tSirSpoofMacAddrReq *pMsg;
6384 tANI_U16 msgLen;
6385 eHalStatus status = eHAL_STATUS_FAILURE;
6386 do {
6387 msgLen = sizeof(tSirSpoofMacAddrReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07006388
Siddharth Bhald8a95e82015-02-12 20:14:52 +05306389 pMsg = vos_mem_malloc(msgLen);
6390 if ( NULL == pMsg )
6391 return eHAL_STATUS_FAILURE;
6392 pMsg->messageType= pal_cpu_to_be16((tANI_U16)eWNI_SME_MAC_SPOOF_ADDR_IND);
6393 pMsg->length= pal_cpu_to_be16(msgLen);
6394 // spoof mac address
6395 vos_mem_copy((tANI_U8 *)pMsg->macAddr,
6396 (tANI_U8 *)pCommand->u.macAddrSpoofCmd.macAddr, sizeof(tSirMacAddr));
6397 status = palSendMBMessage(pMac->hHdd, pMsg);
6398 } while( 0 );
6399 return( status );
6400}
Jeff Johnson295189b2012-06-20 16:38:30 -07006401
6402eHalStatus csrProcessScanCommand( tpAniSirGlobal pMac, tSmeCmd *pCommand )
6403{
6404 eHalStatus status = eHAL_STATUS_SUCCESS;
6405 tCsrChannelInfo newChannelInfo = {0, NULL};
6406 int i, j;
6407 tANI_U8 *pChannel = NULL;
6408 tANI_U32 len = 0;
6409
6410 // Transition to Scanning state...
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306411 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07006412 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306413 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
6414 {
6415 pCommand->u.scanCmd.lastRoamState[i] =
6416 csrRoamStateChange( pMac, eCSR_ROAMING_STATE_SCANNING, i);
6417 smsLog( pMac, LOG3, "starting SCAN command from %d state...."
6418 " reason is %d", pCommand->u.scanCmd.lastRoamState[i],
6419 pCommand->u.scanCmd.reason );
6420 }
6421 }
6422 else
6423 {
6424 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId] =
6425 csrRoamStateChange(pMac, eCSR_ROAMING_STATE_SCANNING,
6426 pCommand->sessionId);
6427 smsLog( pMac, LOG3,
6428 "starting SCAN command from %d state.... reason is %d",
6429 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId],
6430 pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07006431 }
6432
6433 switch(pCommand->u.scanCmd.reason)
6434 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006435#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
6436 case eCsrScanGetLfrResult:
6437#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006438 case eCsrScanGetResult:
6439 case eCsrScanForCapsChange: //For cap change, LIM already save BSS description
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006440 status = csrScanRetrieveResult(pMac, pCommand);
Jeff Johnson295189b2012-06-20 16:38:30 -07006441 break;
6442 case eCsrScanSetBGScanParam:
6443 status = csrProcessSetBGScanParam(pMac, pCommand);
6444 break;
6445 case eCsrScanBGScanAbort:
6446 status = csrSetCfgBackgroundScanPeriod(pMac, 0);
6447 break;
6448 case eCsrScanBGScanEnable:
6449 status = csrSetCfgBackgroundScanPeriod(pMac, pMac->roam.configParam.bgScanInterval);
6450 break;
6451 case eCsrScanGetScanChnInfo:
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05306452 status = csrScanGetScanChannelInfo(pMac, pCommand->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07006453 break;
6454 case eCsrScanUserRequest:
6455 if(pMac->roam.configParam.fScanTwice)
6456 {
6457 //We scan 2.4 channel twice
6458 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels &&
6459 (NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList))
6460 {
6461 len = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
6462 //allocate twice the channel
Mukul Sharmaa631e892014-08-28 15:38:51 +05306463 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(len * 2);
Jeff Johnson295189b2012-06-20 16:38:30 -07006464 pChannel = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
6465 }
6466 else
6467 {
6468 //get the valid channel list to scan all.
6469 len = sizeof(pMac->roam.validChannelList);
6470
6471 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
6472 {
6473 //allocate twice the channel
6474 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(len * 2);
6475 pChannel = pMac->roam.validChannelList;
6476 }
6477 }
6478 if(NULL == newChannelInfo.ChannelList)
6479 {
6480 newChannelInfo.numOfChannels = 0;
6481 }
6482 else
6483 {
6484 j = 0;
6485 for(i = 0; i < len; i++)
6486 {
6487 newChannelInfo.ChannelList[j++] = pChannel[i];
6488 if(CSR_MAX_24GHz_CHANNEL_NUMBER >= pChannel[i])
6489 {
6490 newChannelInfo.ChannelList[j++] = pChannel[i];
6491 }
6492 }
6493 if(NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
6494 {
6495 //pChannel points to the channellist from the command, free it.
6496 vos_mem_free(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -07006497 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07006498 }
6499 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = j;
6500 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = newChannelInfo.ChannelList;
6501 }
6502 } //if(pMac->roam.configParam.fScanTwice)
6503
6504 status = csrScanChannels(pMac, pCommand);
6505
6506 break;
6507 default:
6508 status = csrScanChannels(pMac, pCommand);
6509 break;
6510 }
6511
6512 if(!HAL_STATUS_SUCCESS(status))
6513 {
6514 csrReleaseScanCommand(pMac, pCommand, eCSR_SCAN_FAILURE);
6515 }
6516
6517 return (status);
6518}
6519
6520
6521eHalStatus csrScanSetBGScanparams(tpAniSirGlobal pMac, tCsrBGScanRequest *pScanReq)
6522{
6523 eHalStatus status = eHAL_STATUS_SUCCESS;
6524 tSmeCmd *pCommand = NULL;
6525
6526 if(pScanReq)
6527 {
6528 do
6529 {
6530 pCommand = csrGetCommandBuffer(pMac);
6531 if(!pCommand)
6532 {
6533 status = eHAL_STATUS_RESOURCES;
6534 break;
6535 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306536 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006537 pCommand->command = eSmeCommandScan;
6538 pCommand->u.scanCmd.reason = eCsrScanSetBGScanParam;
6539 pCommand->u.scanCmd.callback = NULL;
6540 pCommand->u.scanCmd.pContext = NULL;
Kiet Lam64c1b492013-07-12 13:56:44 +05306541 vos_mem_copy(&pCommand->u.scanCmd.u.bgScanRequest, pScanReq, sizeof(tCsrBGScanRequest));
Jeff Johnson295189b2012-06-20 16:38:30 -07006542 //we have to do the follow
6543 if(pScanReq->ChannelInfo.numOfChannels == 0)
6544 {
6545 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
6546 }
6547 else
6548 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306549 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList
6550 = vos_mem_malloc(pScanReq->ChannelInfo.numOfChannels);
6551 if ( NULL != pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07006552 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306553 vos_mem_copy(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList,
6554 pScanReq->ChannelInfo.ChannelList,
6555 pScanReq->ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07006556 }
6557 else
6558 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006559 smsLog(pMac, LOGE, FL("ran out of memory"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006560 csrReleaseCommandScan(pMac, pCommand);
Kiet Lam64c1b492013-07-12 13:56:44 +05306561 return eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006562 }
6563 }
6564
6565 //scan req for SSID
6566 if(pScanReq->SSID.length)
6567 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306568 vos_mem_copy(pCommand->u.scanCmd.u.bgScanRequest.SSID.ssId,
6569 pScanReq->SSID.ssId, pScanReq->SSID.length);
Jeff Johnson295189b2012-06-20 16:38:30 -07006570 pCommand->u.scanCmd.u.bgScanRequest.SSID.length = pScanReq->SSID.length;
6571
6572 }
6573 pCommand->u.scanCmd.u.bgScanRequest.maxChnTime= pScanReq->maxChnTime;
6574 pCommand->u.scanCmd.u.bgScanRequest.minChnTime = pScanReq->minChnTime;
6575 pCommand->u.scanCmd.u.bgScanRequest.scanInterval = pScanReq->scanInterval;
6576
6577
6578 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
6579 if( !HAL_STATUS_SUCCESS( status ) )
6580 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006581 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006582 csrReleaseCommandScan( pMac, pCommand );
6583 break;
6584 }
6585 }while(0);
6586 }
6587
6588 return (status);
6589}
6590
6591eHalStatus csrScanBGScanAbort( tpAniSirGlobal pMac )
6592{
6593 eHalStatus status = eHAL_STATUS_SUCCESS;
6594 tSmeCmd *pCommand = NULL;
6595
6596 do
6597 {
6598 pCommand = csrGetCommandBuffer(pMac);
6599 if(!pCommand)
6600 {
6601 status = eHAL_STATUS_RESOURCES;
6602 break;
6603 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306604 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006605 pCommand->command = eSmeCommandScan;
6606 pCommand->u.scanCmd.reason = eCsrScanBGScanAbort;
6607 pCommand->u.scanCmd.callback = NULL;
6608 pCommand->u.scanCmd.pContext = NULL;
6609 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
6610 if( !HAL_STATUS_SUCCESS( status ) )
6611 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006612 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006613 csrReleaseCommandScan( pMac, pCommand );
6614 break;
6615 }
6616 }while(0);
6617
6618 return (status);
6619}
6620
6621
6622//This will enable the background scan with the non-zero interval
6623eHalStatus csrScanBGScanEnable(tpAniSirGlobal pMac)
6624{
6625 eHalStatus status = eHAL_STATUS_SUCCESS;
6626 tSmeCmd *pCommand = NULL;
6627
6628 if(pMac->roam.configParam.bgScanInterval)
6629 {
6630 do
6631 {
6632 pCommand = csrGetCommandBuffer(pMac);
6633 if(!pCommand)
6634 {
6635 status = eHAL_STATUS_RESOURCES;
6636 break;
6637 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306638 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006639 pCommand->command = eSmeCommandScan;
6640 pCommand->u.scanCmd.reason = eCsrScanBGScanEnable;
6641 pCommand->u.scanCmd.callback = NULL;
6642 pCommand->u.scanCmd.pContext = NULL;
6643 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
6644 if( !HAL_STATUS_SUCCESS( status ) )
6645 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006646 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006647 csrReleaseCommandScan( pMac, pCommand );
6648 break;
6649 }
6650 }while(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006651 }
6652 else
6653 {
Sushant Kaushikb8dbb3f2015-04-29 17:03:37 +05306654 smsLog(pMac, LOGE, FL("cannot continue because the bgscan interval is 0"));
6655 status = eHAL_STATUS_INVALID_PARAMETER;
Jeff Johnson295189b2012-06-20 16:38:30 -07006656 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006657 return (status);
6658}
6659
6660
6661eHalStatus csrScanCopyRequest(tpAniSirGlobal pMac, tCsrScanRequest *pDstReq, tCsrScanRequest *pSrcReq)
6662{
6663 eHalStatus status = eHAL_STATUS_SUCCESS;
6664 tANI_U32 len = sizeof(pMac->roam.validChannelList);
6665 tANI_U32 index = 0;
6666 tANI_U32 new_index = 0;
Manjunathappa Prakashde7b2a52014-02-28 16:59:03 -08006667 eNVChannelEnabledType NVchannel_state;
Arif Hussain6af38622014-03-12 12:39:57 -07006668 tANI_U8 ch144_support = 0;
6669
6670 ch144_support = WDA_getFwWlanFeatCaps(WLAN_CH144);
Jeff Johnson295189b2012-06-20 16:38:30 -07006671
6672 do
6673 {
6674 status = csrScanFreeRequest(pMac, pDstReq);
6675 if(HAL_STATUS_SUCCESS(status))
6676 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306677 vos_mem_copy(pDstReq, pSrcReq, sizeof(tCsrScanRequest));
Gopichand Nakkalac7b1d3e2012-12-31 14:07:19 -08006678 /* Re-initialize the pointers to NULL since we did a copy */
6679 pDstReq->pIEField = NULL;
6680 pDstReq->ChannelInfo.ChannelList = NULL;
6681 pDstReq->SSIDs.SSIDList = NULL;
6682
Jeff Johnson295189b2012-06-20 16:38:30 -07006683 if(pSrcReq->uIEFieldLen == 0)
6684 {
6685 pDstReq->pIEField = NULL;
6686 }
6687 else
6688 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306689 pDstReq->pIEField = vos_mem_malloc(pSrcReq->uIEFieldLen);
6690 if ( NULL == pDstReq->pIEField )
Jeff Johnson295189b2012-06-20 16:38:30 -07006691 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306692 status = eHAL_STATUS_FAILURE;
6693 smsLog(pMac, LOGE, FL("No memory for scanning IE fields"));
6694 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07006695 }
6696 else
6697 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306698 status = eHAL_STATUS_SUCCESS;
6699 vos_mem_copy(pDstReq->pIEField, pSrcReq->pIEField,
6700 pSrcReq->uIEFieldLen);
6701 pDstReq->uIEFieldLen = pSrcReq->uIEFieldLen;
Jeff Johnson295189b2012-06-20 16:38:30 -07006702 }
6703 }//Allocate memory for IE field
6704 {
6705 if(pSrcReq->ChannelInfo.numOfChannels == 0)
6706 {
6707 pDstReq->ChannelInfo.ChannelList = NULL;
6708 pDstReq->ChannelInfo.numOfChannels = 0;
6709 }
6710 else
6711 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306712 pDstReq->ChannelInfo.ChannelList = vos_mem_malloc(
6713 pSrcReq->ChannelInfo.numOfChannels
6714 * sizeof(*pDstReq->ChannelInfo.ChannelList));
6715 if ( NULL == pDstReq->ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07006716 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306717 status = eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006718 pDstReq->ChannelInfo.numOfChannels = 0;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306719 smsLog(pMac, LOGE, FL("No memory for scanning Channel"
6720 " List"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006721 break;
6722 }
6723
6724 if((pSrcReq->scanType == eSIR_PASSIVE_SCAN) && (pSrcReq->requestType == eCSR_SCAN_REQUEST_11D_SCAN))
6725 {
6726 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
6727 {
Arif Hussain6af38622014-03-12 12:39:57 -07006728 /* Skip CH 144 if firmware support not present */
6729 if (pSrcReq->ChannelInfo.ChannelList[index] == 144 && !ch144_support)
6730 continue;
Agarwal Ashish8bd53ae2015-06-12 18:03:45 +05306731 /* Skip channel 12 and 13 when FCC constraint is true */
6732 if ((pMac->scan.fcc_constraint) &&
6733 ((pSrcReq->ChannelInfo.ChannelList[index] ==12) ||
6734 (pSrcReq->ChannelInfo.ChannelList[index] ==13)))
6735 {
6736 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
6737 FL("Ignoring channel : %d "),
6738 pSrcReq->ChannelInfo.ChannelList[index]);
6739 continue;
6740 }
Arif Hussain6af38622014-03-12 12:39:57 -07006741
Manjunathappa Prakashde7b2a52014-02-28 16:59:03 -08006742 NVchannel_state = vos_nv_getChannelEnabledState(
6743 pSrcReq->ChannelInfo.ChannelList[index]);
6744 if ((NV_CHANNEL_ENABLE == NVchannel_state) ||
6745 (NV_CHANNEL_DFS == NVchannel_state))
6746 {
6747 pDstReq->ChannelInfo.ChannelList[new_index] =
6748 pSrcReq->ChannelInfo.ChannelList[index];
6749 new_index++;
6750 }
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306751 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006752 pDstReq->ChannelInfo.numOfChannels = new_index;
6753 }
6754 else if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
6755 {
6756 new_index = 0;
6757 pMac->roam.numValidChannels = len;
c_hpothu0d5a7352014-03-22 12:30:25 +05306758
6759 /* Since in CsrScanRequest,value of pMac->scan.nextScanID
6760 * is incremented before calling CsrScanCopyRequest, as a
6761 * result pMac->scan.nextScanID is equal to ONE for the
Abhishek Singha2649232016-01-20 15:52:05 +05306762 * first scan. If number of channels is less than
6763 * max chan for dwell time no need to skip dfs
6764 * in first scan as anyway few channels will be scanned and
6765 * it will not take much time to display results on GUI.
c_hpothu0d5a7352014-03-22 12:30:25 +05306766 */
Abhishek Singha2649232016-01-20 15:52:05 +05306767 if (((pSrcReq->ChannelInfo.numOfChannels >=
6768 pMac->roam.configParam.max_chan_for_dwell_time_cfg) &&
6769 (pMac->roam.configParam.initialScanSkipDFSCh &&
6770 1 == pMac->scan.nextScanID)) ||(pMac->miracast_mode))
c_hpothu0d5a7352014-03-22 12:30:25 +05306771 {
6772 smsLog(pMac, LOG1,
6773 FL("Initial scan, scan only non-DFS channels"));
6774
6775 for (index = 0; index < pSrcReq->ChannelInfo.
6776 numOfChannels ; index++ )
6777 {
6778 if((csrRoamIsValidChannel(pMac, pSrcReq->ChannelInfo.
6779 ChannelList[index])))
6780 {
6781 /*Skiipping DFS Channels for 1st scan */
6782 if(NV_CHANNEL_DFS ==
6783 vos_nv_getChannelEnabledState(pSrcReq->ChannelInfo.
6784 ChannelList[index]))
6785 continue ;
6786
6787 pDstReq->ChannelInfo.ChannelList[new_index] =
6788 pSrcReq->ChannelInfo.ChannelList[index];
6789 new_index++;
6790
6791 }
6792 }
6793 pMac->roam.configParam.initialScanSkipDFSCh = 0;
6794 }
6795 else
6796 {
6797 for ( index = 0; index < pSrcReq->ChannelInfo.
6798 numOfChannels ; index++ )
Jeff Johnson295189b2012-06-20 16:38:30 -07006799 {
Arif Hussain6af38622014-03-12 12:39:57 -07006800 /* Skip CH 144 if firmware support not present */
6801 if (pSrcReq->ChannelInfo.ChannelList[index] == 144 && !ch144_support)
6802 continue;
6803
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -07006804 /* Allow scan on valid channels only.
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -07006805 */
Abhishek Singh2ec36ab2014-08-07 16:14:25 +05306806 if ( ( csrRoamIsValidChannel(pMac, pSrcReq->ChannelInfo.ChannelList[index]) ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07006807 {
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05306808 if( ((pSrcReq->skipDfsChnlInP2pSearch ||
6809 (pMac->scan.fEnableDFSChnlScan ==
6810 DFS_CHNL_SCAN_DISABLED)) &&
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08006811 (NV_CHANNEL_DFS == vos_nv_getChannelEnabledState(pSrcReq->ChannelInfo.ChannelList[index])) )
Srikant Kuppa866893f2012-12-27 17:28:14 -08006812#ifdef FEATURE_WLAN_LFR
6813 /*
6814 * If LFR is requesting a contiguous scan
6815 * (i.e. numOfChannels > 1), then ignore
6816 * DFS channels.
6817 * TODO: vos_nv_getChannelEnabledState is returning
6818 * 120, 124 and 128 as non-DFS channels. Hence, the
6819 * use of direct check for channels below.
6820 */
6821 || ((eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType) &&
6822 (pSrcReq->ChannelInfo.numOfChannels > 1) &&
Santhosh Kumar Padma9ccaaff2014-07-09 19:58:12 +05306823 (CSR_IS_CHANNEL_DFS(pSrcReq->ChannelInfo.ChannelList[index])) &&
6824 !pMac->roam.configParam.allowDFSChannelRoam)
Srikant Kuppa866893f2012-12-27 17:28:14 -08006825#endif
6826 )
6827 {
6828#ifdef FEATURE_WLAN_LFR
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05306829 smsLog(pMac, LOG2,
6830 FL(" reqType=%s (%d), numOfChannels=%d,"
6831 " ignoring DFS channel %d"),
6832 sme_requestTypetoString(pSrcReq->requestType),
6833 pSrcReq->requestType,
6834 pSrcReq->ChannelInfo.numOfChannels,
6835 pSrcReq->ChannelInfo.ChannelList[index]);
Srikant Kuppa866893f2012-12-27 17:28:14 -08006836#endif
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05306837 continue;
Srikant Kuppa866893f2012-12-27 17:28:14 -08006838 }
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08006839
Jeff Johnson295189b2012-06-20 16:38:30 -07006840 pDstReq->ChannelInfo.ChannelList[new_index] =
6841 pSrcReq->ChannelInfo.ChannelList[index];
6842 new_index++;
6843 }
6844 }
c_hpothu0d5a7352014-03-22 12:30:25 +05306845 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006846 pDstReq->ChannelInfo.numOfChannels = new_index;
Srikant Kuppa866893f2012-12-27 17:28:14 -08006847#ifdef FEATURE_WLAN_LFR
Abhishek Singh2ec36ab2014-08-07 16:14:25 +05306848 if ( ( ( eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType ) ||
6849 ( eCSR_SCAN_P2P_DISCOVERY == pSrcReq->requestType ) ) &&
6850 ( 0 == pDstReq->ChannelInfo.numOfChannels ) )
Srikant Kuppa866893f2012-12-27 17:28:14 -08006851 {
6852 /*
6853 * No valid channels found in the request.
6854 * Only perform scan on the channels passed
Abhishek Singh2ec36ab2014-08-07 16:14:25 +05306855 * pSrcReq if it is a eCSR_SCAN_HO_BG_SCAN or
6856 * eCSR_SCAN_P2P_DISCOVERY.
Srikant Kuppa866893f2012-12-27 17:28:14 -08006857 * Passing 0 to LIM will trigger a scan on
6858 * all valid channels which is not desirable.
6859 */
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306860 smsLog(pMac, LOGE, FL(" no valid channels found"
6861 " (request=%d)"), pSrcReq->requestType);
Srikant Kuppa866893f2012-12-27 17:28:14 -08006862 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
6863 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306864 smsLog(pMac, LOGE, FL("pSrcReq index=%d"
6865 " channel=%d"), index,
6866 pSrcReq->ChannelInfo.ChannelList[index]);
Srikant Kuppa866893f2012-12-27 17:28:14 -08006867 }
6868 status = eHAL_STATUS_FAILURE;
6869 break;
6870 }
6871#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006872 }
6873 else
6874 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306875 smsLog(pMac, LOGE, FL("Couldn't get the valid Channel"
6876 " List, keeping requester's list"));
Kiet Lam64c1b492013-07-12 13:56:44 +05306877 vos_mem_copy(pDstReq->ChannelInfo.ChannelList,
6878 pSrcReq->ChannelInfo.ChannelList,
6879 pSrcReq->ChannelInfo.numOfChannels
6880 * sizeof(*pDstReq->ChannelInfo.ChannelList));
Jeff Johnson295189b2012-06-20 16:38:30 -07006881 pDstReq->ChannelInfo.numOfChannels = pSrcReq->ChannelInfo.numOfChannels;
6882 }
6883 }//Allocate memory for Channel List
6884 }
6885 if(pSrcReq->SSIDs.numOfSSIDs == 0)
6886 {
6887 pDstReq->SSIDs.numOfSSIDs = 0;
6888 pDstReq->SSIDs.SSIDList = NULL;
6889 }
6890 else
6891 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306892 pDstReq->SSIDs.SSIDList = vos_mem_malloc(
6893 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
6894 if ( NULL == pDstReq->SSIDs.SSIDList )
6895 status = eHAL_STATUS_FAILURE;
6896 else
6897 status = eHAL_STATUS_SUCCESS;
6898 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07006899 {
6900 pDstReq->SSIDs.numOfSSIDs = pSrcReq->SSIDs.numOfSSIDs;
Kiet Lam64c1b492013-07-12 13:56:44 +05306901 vos_mem_copy(pDstReq->SSIDs.SSIDList,
6902 pSrcReq->SSIDs.SSIDList,
6903 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
Jeff Johnson295189b2012-06-20 16:38:30 -07006904 }
6905 else
6906 {
6907 pDstReq->SSIDs.numOfSSIDs = 0;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306908 smsLog(pMac, LOGE, FL("No memory for scanning SSID List"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006909 break;
6910 }
6911 }//Allocate memory for SSID List
Jeff Johnson295189b2012-06-20 16:38:30 -07006912 pDstReq->p2pSearch = pSrcReq->p2pSearch;
Jeff Johnsone7245742012-09-05 17:12:55 -07006913 pDstReq->skipDfsChnlInP2pSearch = pSrcReq->skipDfsChnlInP2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07006914
6915 }
6916 }while(0);
6917
6918 if(!HAL_STATUS_SUCCESS(status))
6919 {
6920 csrScanFreeRequest(pMac, pDstReq);
6921 }
6922
6923 return (status);
6924}
6925
6926
6927eHalStatus csrScanFreeRequest(tpAniSirGlobal pMac, tCsrScanRequest *pReq)
6928{
Jeff Johnson295189b2012-06-20 16:38:30 -07006929
6930 if(pReq->ChannelInfo.ChannelList)
6931 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306932 vos_mem_free(pReq->ChannelInfo.ChannelList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006933 pReq->ChannelInfo.ChannelList = NULL;
6934 }
6935 pReq->ChannelInfo.numOfChannels = 0;
6936 if(pReq->pIEField)
6937 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306938 vos_mem_free(pReq->pIEField);
Jeff Johnson295189b2012-06-20 16:38:30 -07006939 pReq->pIEField = NULL;
6940 }
6941 pReq->uIEFieldLen = 0;
6942 if(pReq->SSIDs.SSIDList)
6943 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306944 vos_mem_free(pReq->SSIDs.SSIDList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006945 pReq->SSIDs.SSIDList = NULL;
6946 }
6947 pReq->SSIDs.numOfSSIDs = 0;
6948
Kiet Lam64c1b492013-07-12 13:56:44 +05306949 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07006950}
6951
6952
6953void csrScanCallCallback(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
6954{
6955 if(pCommand->u.scanCmd.callback)
6956 {
Ratheesh S Pece1f832015-07-25 15:50:25 +05306957 if (pCommand->u.scanCmd.abortScanIndication){
6958 smsLog( pMac, LOG1, FL("scanDone due to abort"));
6959 scanStatus = eCSR_SCAN_ABORT;
6960 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006961// sme_ReleaseGlobalLock( &pMac->sme );
6962 pCommand->u.scanCmd.callback(pMac, pCommand->u.scanCmd.pContext, pCommand->u.scanCmd.scanID, scanStatus);
6963// sme_AcquireGlobalLock( &pMac->sme );
6964 } else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006965 smsLog( pMac, LOG2, "%s:%d - Callback NULL!!!", __func__, __LINE__);
Jeff Johnson295189b2012-06-20 16:38:30 -07006966 }
6967}
6968
6969
6970void csrScanStopTimers(tpAniSirGlobal pMac)
6971{
Jeff Johnson295189b2012-06-20 16:38:30 -07006972 csrScanStopIdleScanTimer(pMac);
6973 csrScanStopGetResultTimer(pMac);
6974}
6975
6976
6977eHalStatus csrScanStartGetResultTimer(tpAniSirGlobal pMac)
6978{
6979 eHalStatus status;
6980
6981 if(pMac->scan.fScanEnable)
6982 {
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306983 status = vos_timer_start(&pMac->scan.hTimerGetResult, CSR_SCAN_GET_RESULT_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006984 }
6985 else
6986 {
6987 status = eHAL_STATUS_FAILURE;
6988 }
6989
6990 return (status);
6991}
6992
6993
6994eHalStatus csrScanStopGetResultTimer(tpAniSirGlobal pMac)
6995{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306996 return (vos_timer_stop(&pMac->scan.hTimerGetResult));
Jeff Johnson295189b2012-06-20 16:38:30 -07006997}
6998
6999
7000void csrScanGetResultTimerHandler(void *pv)
7001{
7002 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
7003
7004 csrScanRequestResult(pMac);
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05307005
7006 vos_timer_start(&pMac->scan.hTimerGetResult, CSR_SCAN_GET_RESULT_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07007007}
7008
7009#ifdef WLAN_AP_STA_CONCURRENCY
7010static void csrStaApConcTimerHandler(void *pv)
7011{
7012 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
7013 tListElem *pEntry;
7014 tSmeCmd *pScanCmd;
7015
7016 csrLLLock(&pMac->scan.scanCmdPendingList);
7017
7018 if ( NULL != ( pEntry = csrLLPeekHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) ) )
7019 {
7020 tCsrScanRequest scanReq;
7021 tSmeCmd *pSendScanCmd = NULL;
7022 tANI_U8 numChn = 0;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07007023 tANI_U8 nNumChanCombinedConc = 0;
Vinay Malekal05fdc812012-12-17 13:04:30 -08007024 tANI_U8 i, j;
Jeff Johnson295189b2012-06-20 16:38:30 -07007025 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
7026 tANI_U8 channelToScan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
7027 eHalStatus status;
7028
Jeff Johnson295189b2012-06-20 16:38:30 -07007029 pScanCmd = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7030 numChn = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08007031
7032 /* if any session is connected and the number of channels to scan is
7033 * greater than 1 then split the scan into multiple scan operations
7034 * on each individual channel else continue to perform scan on all
7035 * specified channels */
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08007036
7037 /* split scan if number of channels to scan is greater than 1 and
7038 * any one of the following:
7039 * - STA session is connected and the scan is not a P2P search
7040 * - any P2P session is connected
Srikant Kuppa866893f2012-12-27 17:28:14 -08007041 * Do not split scans if no concurrent infra connections are
7042 * active and if the scan is a BG scan triggered by LFR (OR)
7043 * any scan if LFR is in the middle of a BG scan. Splitting
7044 * the scan is delaying the time it takes for LFR to find
7045 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08007046 */
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07007047
7048 if((csrIsStaSessionConnected(pMac) &&
7049 !csrIsP2pSessionConnected(pMac)))
7050 {
7051 nNumChanCombinedConc = pMac->roam.configParam.nNumStaChanCombinedConc;
7052 }
7053 else if(csrIsP2pSessionConnected(pMac))
7054 {
7055 nNumChanCombinedConc = pMac->roam.configParam.nNumP2PChanCombinedConc;
7056 }
7057
7058 if ( (numChn > nNumChanCombinedConc) &&
Srikant Kuppa866893f2012-12-27 17:28:14 -08007059 ((csrIsStaSessionConnected(pMac) &&
7060#ifdef FEATURE_WLAN_LFR
7061 (csrIsConcurrentInfraConnected(pMac) ||
7062 ((pScanCmd->u.scanCmd.reason != eCsrScanBgScan) &&
7063 (pMac->roam.neighborRoamInfo.neighborRoamState !=
7064 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
7065#endif
7066 (pScanCmd->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08007067 (csrIsP2pSessionConnected(pMac))))
Jeff Johnson295189b2012-06-20 16:38:30 -07007068 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307069 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007070
7071 pSendScanCmd = csrGetCommandBuffer(pMac); //optimize this to use 2 command buffer only
7072 if (!pSendScanCmd)
7073 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007074 smsLog( pMac, LOGE, FL(" Failed to get Queue command buffer") );
Jeff Johnson295189b2012-06-20 16:38:30 -07007075 csrLLUnlock(&pMac->scan.scanCmdPendingList);
7076 return;
7077 }
7078 pSendScanCmd->command = pScanCmd->command;
7079 pSendScanCmd->sessionId = pScanCmd->sessionId;
7080 pSendScanCmd->u.scanCmd.callback = NULL;
7081 pSendScanCmd->u.scanCmd.pContext = pScanCmd->u.scanCmd.pContext;
7082 pSendScanCmd->u.scanCmd.reason = pScanCmd->u.scanCmd.reason;
7083 pSendScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
7084
Madan Mohan Koyyalamudiaf2a8b92012-10-09 14:58:07 -07007085 /* First copy all the parameters to local variable of scan request */
7086 csrScanCopyRequest(pMac, &scanReq, &pScanCmd->u.scanCmd.u.scanRequest);
7087
7088 /* Now modify the elements of local var scan request required to be modified for split scan */
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08007089 if(scanReq.ChannelInfo.ChannelList != NULL)
7090 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307091 vos_mem_free(scanReq.ChannelInfo.ChannelList);
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08007092 scanReq.ChannelInfo.ChannelList = NULL;
7093 }
7094
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07007095 pChnInfo->numOfChannels = nNumChanCombinedConc;
Kiet Lam64c1b492013-07-12 13:56:44 +05307096 vos_mem_copy(&channelToScan[0],
7097 &pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[0],
7098 pChnInfo->numOfChannels * sizeof(tANI_U8));//just send one channel
Jeff Johnson295189b2012-06-20 16:38:30 -07007099 pChnInfo->ChannelList = &channelToScan[0];
7100
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07007101 for (i = 0, j = nNumChanCombinedConc; i < (numChn-nNumChanCombinedConc); i++, j++)
Jeff Johnson295189b2012-06-20 16:38:30 -07007102 {
7103 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] =
Vinay Malekal05fdc812012-12-17 13:04:30 -08007104 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[j]; //Move all the channels one step
Jeff Johnson295189b2012-06-20 16:38:30 -07007105 }
7106
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07007107 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = numChn - nNumChanCombinedConc; //reduce outstanding # of channels to be scanned
Jeff Johnson295189b2012-06-20 16:38:30 -07007108
7109 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
c_hpothudbefd3e2014-04-28 15:59:47 +05307110
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -07007111 //Use concurrency values for min/maxChnTime.
7112 //We know csrIsAnySessionConnected(pMac) returns TRUE here
7113 csrSetDefaultScanTiming(pMac, scanReq.scanType, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07007114
7115 status = csrScanCopyRequest(pMac, &pSendScanCmd->u.scanCmd.u.scanRequest, &scanReq);
7116 if(!HAL_STATUS_SUCCESS(status))
7117 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007118 smsLog( pMac, LOGE, FL(" Failed to get copy csrScanRequest = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07007119 csrLLUnlock(&pMac->scan.scanCmdPendingList);
7120 return;
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08007121 }
7122 /* Clean the local scan variable */
7123 scanReq.ChannelInfo.ChannelList = NULL;
7124 scanReq.ChannelInfo.numOfChannels = 0;
7125 csrScanFreeRequest(pMac, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07007126 }
7127 else
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08007128 {
7129 /* no active connected session present or numChn == 1
7130 * scan all remaining channels */
Jeff Johnson295189b2012-06-20 16:38:30 -07007131 pSendScanCmd = pScanCmd;
7132 //remove this command from pending list
7133 if (csrLLRemoveHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) == NULL)
7134 { //In case between PeekHead and here, the entry got removed by another thread.
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007135 smsLog( pMac, LOGE, FL(" Failed to remove entry from scanCmdPendingList"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007136 }
7137
7138 }
7139 csrQueueSmeCommand(pMac, pSendScanCmd, eANI_BOOLEAN_FALSE);
7140
7141 }
7142
Jeff Johnson295189b2012-06-20 16:38:30 -07007143 csrLLUnlock(&pMac->scan.scanCmdPendingList);
7144
7145}
7146#endif
7147
Jeff Johnson295189b2012-06-20 16:38:30 -07007148//This function returns the maximum time a BSS is allowed in the scan result.
7149//The time varies base on connection and power saving factors.
7150//Not connected, No PS
7151//Not connected, with PS
7152//Connected w/o traffic, No PS
7153//Connected w/o traffic, with PS
7154//Connected w/ traffic, no PS -- Not supported
7155//Connected w/ traffic, with PS -- Not supported
7156//the return unit is in seconds.
7157tANI_U32 csrScanGetAgeOutTime(tpAniSirGlobal pMac)
7158{
7159 tANI_U32 nRet;
7160
7161 if(pMac->scan.nAgingCountDown)
7162 {
7163 //Calculate what should be the timeout value for this
7164 nRet = pMac->scan.nLastAgeTimeOut * pMac->scan.nAgingCountDown;
7165 pMac->scan.nAgingCountDown--;
7166 }
7167 else
7168 {
7169 if( csrIsAllSessionDisconnected( pMac ) )
7170 {
7171 if(pmcIsPowerSaveEnabled(pMac, ePMC_IDLE_MODE_POWER_SAVE))
7172 {
7173 nRet = pMac->roam.configParam.scanAgeTimeNCPS;
7174 }
7175 else
7176 {
7177 nRet = pMac->roam.configParam.scanAgeTimeNCNPS;
7178 }
7179 }
7180 else
7181 {
7182 if(pmcIsPowerSaveEnabled(pMac, ePMC_BEACON_MODE_POWER_SAVE))
7183 {
7184 nRet = pMac->roam.configParam.scanAgeTimeCPS;
7185 }
7186 else
7187 {
7188 nRet = pMac->roam.configParam.scanAgeTimeCNPS;
7189 }
7190 }
7191 //If state-change causing aging time out change, we want to delay it somewhat to avoid
7192 //unnecessary removal of BSS. This is mostly due to transition from connect to disconnect.
7193 if(pMac->scan.nLastAgeTimeOut > nRet)
7194 {
7195 if(nRet)
7196 {
7197 pMac->scan.nAgingCountDown = (pMac->scan.nLastAgeTimeOut / nRet);
7198 }
7199 pMac->scan.nLastAgeTimeOut = nRet;
7200 nRet *= pMac->scan.nAgingCountDown;
7201 }
7202 else
7203 {
7204 pMac->scan.nLastAgeTimeOut = nRet;
7205 }
7206 }
7207
7208 return (nRet);
7209}
7210
Deepthi Gowri6a08e312016-03-31 19:10:14 +05307211static void csrPurgeScanResultByAge(void *pv)
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08007212{
7213 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
7214 tListElem *pEntry, *tmpEntry;
7215 tCsrScanResult *pResult;
Deepthi Gowri4480a3f2016-05-18 19:30:17 +05307216 v_TIME_t ageOutTime =
7217 (v_TIME_t)(pMac->scan.scanResultCfgAgingTime * SYSTEM_TIME_SEC_TO_MSEC);
7218 v_TIME_t curTime = vos_timer_get_system_time();
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08007219
7220 csrLLLock(&pMac->scan.scanResultList);
7221 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
Deepthi Gowri6a08e312016-03-31 19:10:14 +05307222 smsLog(pMac, LOG1, FL("Ageout time=%lu"),ageOutTime);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08007223 while( pEntry )
7224 {
7225 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
7226 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
7227 if((curTime - pResult->Result.BssDescriptor.nReceivedTime) > ageOutTime)
7228 {
Deepthi Gowri50e2fa52016-03-17 15:30:53 +05307229 smsLog(pMac, LOG1, FL("age out due to time out for BSSID" MAC_ADDRESS_STR),
7230 MAC_ADDR_ARRAY(pResult->Result.BssDescriptor.bssId));
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08007231 csrScanAgeOutBss(pMac, pResult);
7232 }
7233 pEntry = tmpEntry;
7234 }
7235 csrLLUnlock(&pMac->scan.scanResultList);
7236}
Jeff Johnson295189b2012-06-20 16:38:30 -07007237
7238eHalStatus csrScanStartIdleScanTimer(tpAniSirGlobal pMac, tANI_U32 interval)
7239{
7240 eHalStatus status;
7241
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007242 smsLog(pMac, LOG1, " csrScanStartIdleScanTimer");
Jeff Johnson295189b2012-06-20 16:38:30 -07007243 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) && interval)
7244 {
7245 pMac->scan.nIdleScanTimeGap += interval;
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05307246 vos_timer_stop(&pMac->scan.hTimerIdleScan);
7247 status = vos_timer_start(&pMac->scan.hTimerIdleScan, interval/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07007248 if( !HAL_STATUS_SUCCESS(status) )
7249 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007250 smsLog(pMac, LOGE, " Fail to start Idle scan timer. status = %d interval = %d", status, interval);
Jeff Johnson295189b2012-06-20 16:38:30 -07007251 //This should not happen but set the flag to restart when ready
7252 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7253 }
7254 }
7255 else
7256 {
7257 if( pMac->scan.fScanEnable && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) )
7258 {
7259 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7260 }
7261 status = eHAL_STATUS_FAILURE;
7262 }
7263
7264 return (status);
7265}
7266
7267
7268eHalStatus csrScanStopIdleScanTimer(tpAniSirGlobal pMac)
7269{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05307270 return (vos_timer_stop(&pMac->scan.hTimerIdleScan));
Jeff Johnson295189b2012-06-20 16:38:30 -07007271}
7272
7273
7274//Stop CSR from asking for IMPS, This function doesn't disable IMPS from CSR
7275void csrScanSuspendIMPS( tpAniSirGlobal pMac )
7276{
7277 csrScanCancelIdleScan(pMac);
7278}
7279
7280
7281//Start CSR from asking for IMPS. This function doesn't trigger CSR to request entering IMPS
7282//because IMPS maybe disabled.
7283void csrScanResumeIMPS( tpAniSirGlobal pMac )
7284{
7285 csrScanStartIdleScan( pMac );
7286}
7287
7288
7289void csrScanIMPSCallback(void *callbackContext, eHalStatus status)
7290{
7291 tpAniSirGlobal pMac = PMAC_STRUCT( callbackContext );
7292
7293 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
7294 {
7295 if(pMac->roam.configParam.IsIdleScanEnabled)
7296 {
7297 if(HAL_STATUS_SUCCESS(status))
7298 {
7299 if(csrIsAllSessionDisconnected(pMac) && !csrIsRoamCommandWaiting(pMac))
7300 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007301 smsLog(pMac, LOGW, FL("starts idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007302 csrScanAllChannels(pMac, eCSR_SCAN_IDLE_MODE_SCAN);
7303 }
7304 else
7305 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007306 smsLog(pMac, LOGW, FL("cannot start idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007307 //even though we are in timer handle, calling stop timer will make sure the timer
7308 //doesn't get to restart.
7309 csrScanStopIdleScanTimer(pMac);
7310 }
7311 }
7312 else
7313 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007314 smsLog(pMac, LOGE, FL("sees not success status (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07007315 }
7316 }
7317 else
7318 {//we might need another flag to check if CSR needs to request imps at all
7319
7320 tANI_U32 nTime = 0;
7321
7322 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_FALSE;
7323 if(!HAL_STATUS_SUCCESS(csrScanTriggerIdleScan(pMac, &nTime)))
7324 {
7325 csrScanStartIdleScanTimer(pMac, nTime);
7326 }
7327 }
7328 }
7329}
7330
7331
Rashmi Ramanna68b309c2014-05-20 11:52:22 +05307332//Param: pTimeInterval -- Caller allocated memory in return, if failed, to specify the nxt time interval for
Jeff Johnson295189b2012-06-20 16:38:30 -07007333//idle scan timer interval
7334//Return: Not success -- meaning it cannot start IMPS, caller needs to start a timer for idle scan
7335eHalStatus csrScanTriggerIdleScan(tpAniSirGlobal pMac, tANI_U32 *pTimeInterval)
7336{
7337 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
7338
7339 //Do not trigger IMPS in case of concurrency
Agarwal Ashish5974ed32014-06-16 16:59:54 +05307340 if (vos_concurrent_open_sessions_running() &&
7341 csrIsAnySessionInConnectState(pMac))
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007342 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007343 smsLog( pMac, LOG1, FL("Cannot request IMPS because Concurrent Sessions Running") );
Jeff Johnson295189b2012-06-20 16:38:30 -07007344 return (status);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007345 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007346
7347 if(pTimeInterval)
7348 {
7349 *pTimeInterval = 0;
7350 }
7351
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007352 smsLog(pMac, LOG3, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007353 if( smeCommandPending( pMac ) )
7354 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007355 smsLog( pMac, LOG1, FL(" Cannot request IMPS because command pending") );
Jeff Johnson295189b2012-06-20 16:38:30 -07007356 //Not to enter IMPS because more work to do
7357 if(pTimeInterval)
7358 {
7359 *pTimeInterval = 0;
7360 }
7361 //restart when ready
7362 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7363
7364 return (status);
7365 }
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07007366 if (IsPmcImpsReqFailed (pMac))
7367 {
7368 if(pTimeInterval)
7369 {
7370 *pTimeInterval = 1000000; //usec
7371 }
7372 //restart when ready
7373 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07007374
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07007375 return status;
7376 }
Rashmi Ramanna68b309c2014-05-20 11:52:22 +05307377
7378 if ( !pMac->deferImps && pMac->fDeferIMPSTime )
7379 {
7380 smsLog( pMac, LOG1, FL("Defer IMPS for %dms as command processed"),
7381 pMac->fDeferIMPSTime);
Girish Gowli4f3775a2014-05-30 17:17:08 +05307382 if(pTimeInterval)
7383 {
7384 *pTimeInterval = pMac->fDeferIMPSTime * 1000; //usec
7385 }
Rashmi Ramanna68b309c2014-05-20 11:52:22 +05307386 pMac->deferImps = eANI_BOOLEAN_TRUE;
7387 return status;
7388 }
7389
Jeff Johnson295189b2012-06-20 16:38:30 -07007390 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
7391 /*&& pMac->roam.configParam.impsSleepTime*/)
7392 {
7393 //Stop get result timer because idle scan gets scan result out of PE
7394 csrScanStopGetResultTimer(pMac);
7395 if(pTimeInterval)
7396 {
7397 *pTimeInterval = pMac->roam.configParam.impsSleepTime;
7398 }
7399 //pmcRequestImps take a period in millisecond unit.
7400 status = pmcRequestImps(pMac, pMac->roam.configParam.impsSleepTime / PAL_TIMER_TO_MS_UNIT, csrScanIMPSCallback, pMac);
7401 if(!HAL_STATUS_SUCCESS(status))
7402 {
7403 if(eHAL_STATUS_PMC_ALREADY_IN_IMPS != status)
7404 {
7405 //Do restart the timer if CSR thinks it cannot do IMPS
7406 if( !csrCheckPSReady( pMac ) )
7407 {
7408 if(pTimeInterval)
7409 {
7410 *pTimeInterval = 0;
7411 }
7412 //Set the restart flag to true because that idle scan
7413 //can be restarted even though the timer will not be running
7414 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7415 }
7416 else
7417 {
7418 //For not now, we do a quicker retry
7419 if(pTimeInterval)
7420 {
7421 *pTimeInterval = CSR_IDLE_SCAN_WAIT_TIME;
7422 }
7423 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007424 smsLog(pMac, LOGW, FL("call pmcRequestImps and it returns status code (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07007425 }
7426 else
7427 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007428 smsLog(pMac, LOGW, FL("already in IMPS"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007429 //Since CSR is the only module to request for IMPS. If it is already in IMPS, CSR assumes
7430 //the callback will be called in the future. Should not happen though.
7431 status = eHAL_STATUS_SUCCESS;
7432 pMac->scan.nIdleScanTimeGap = 0;
7433 }
7434 }
7435 else
7436 {
7437 //requested so let's reset the value
7438 pMac->scan.nIdleScanTimeGap = 0;
7439 }
7440 }
7441
7442 return (status);
7443}
7444
7445
7446eHalStatus csrScanStartIdleScan(tpAniSirGlobal pMac)
7447{
7448 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
7449 tANI_U32 nTime = 0;
7450
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007451 smsLog(pMac, LOGW, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007452 if(pMac->roam.configParam.IsIdleScanEnabled)
7453 {
7454 //stop bg scan first
7455 csrScanBGScanAbort(pMac);
7456 //Stop get result timer because idle scan gets scan result out of PE
7457 csrScanStopGetResultTimer(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07007458 }
7459 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_FALSE;
7460 status = csrScanTriggerIdleScan(pMac, &nTime);
7461 if(!HAL_STATUS_SUCCESS(status))
7462 {
7463 csrScanStartIdleScanTimer(pMac, nTime);
7464 }
7465
7466 return (status);
7467}
7468
7469
7470void csrScanCancelIdleScan(tpAniSirGlobal pMac)
7471{
7472 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
7473 {
Agarwal Ashish5974ed32014-06-16 16:59:54 +05307474 if (vos_concurrent_open_sessions_running()) {
Jeff Johnson295189b2012-06-20 16:38:30 -07007475 return;
7476 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007477 smsLog(pMac, LOG1, " csrScanCancelIdleScan");
Jeff Johnson295189b2012-06-20 16:38:30 -07007478 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_TRUE;
7479 //Set the restart flag in case later on it is uncancelled
7480 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7481 csrScanStopIdleScanTimer(pMac);
7482 csrScanRemoveNotRoamingScanCommand(pMac);
7483 }
7484}
7485
7486
7487void csrScanIdleScanTimerHandler(void *pv)
7488{
7489 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
7490 eHalStatus status;
7491 tANI_U32 nTime = 0;
7492
7493 smsLog(pMac, LOGW, " csrScanIdleScanTimerHandler called ");
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07007494 pmcResetImpsFailStatus (pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07007495 status = csrScanTriggerIdleScan(pMac, &nTime);
7496 if(!HAL_STATUS_SUCCESS(status) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan))
7497 {
7498 //Check whether it is time to actually do an idle scan
7499 if(pMac->scan.nIdleScanTimeGap >= pMac->roam.configParam.impsSleepTime)
7500 {
7501 pMac->scan.nIdleScanTimeGap = 0;
7502 csrScanIMPSCallback(pMac, eHAL_STATUS_SUCCESS);
7503 }
7504 else
7505 {
7506 csrScanStartIdleScanTimer(pMac, nTime);
7507 }
7508 }
Rashmi Ramanna68b309c2014-05-20 11:52:22 +05307509 if(pMac->deferImps)
7510 {
7511 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7512 pMac->deferImps = eANI_BOOLEAN_FALSE;
7513 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007514}
7515
7516
7517
7518
7519tANI_BOOLEAN csrScanRemoveNotRoamingScanCommand(tpAniSirGlobal pMac)
7520{
7521 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
7522 tListElem *pEntry, *pEntryTmp;
7523 tSmeCmd *pCommand;
7524 tDblLinkList localList;
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307525 tDblLinkList *pCmdList;
Jeff Johnson295189b2012-06-20 16:38:30 -07007526
7527 vos_mem_zero(&localList, sizeof(tDblLinkList));
7528 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
7529 {
7530 smsLog(pMac, LOGE, FL(" failed to open list"));
7531 return fRet;
7532 }
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307533 if (!pMac->fScanOffload)
7534 pCmdList = &pMac->sme.smeCmdPendingList;
7535 else
7536 pCmdList = &pMac->sme.smeScanCmdPendingList;
Jeff Johnson295189b2012-06-20 16:38:30 -07007537
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307538 csrLLLock(pCmdList);
7539 pEntry = csrLLPeekHead(pCmdList, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007540 while(pEntry)
7541 {
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307542 pEntryTmp = csrLLNext(pCmdList, pEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007543 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7544 if( eSmeCommandScan == pCommand->command )
7545 {
7546 switch( pCommand->u.scanCmd.reason )
7547 {
7548 case eCsrScanIdleScan:
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307549 if( csrLLRemoveEntry(pCmdList, pEntry, LL_ACCESS_NOLOCK) )
Jeff Johnson295189b2012-06-20 16:38:30 -07007550 {
7551 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
7552 }
7553 fRet = eANI_BOOLEAN_TRUE;
7554 break;
7555
7556 default:
7557 break;
7558 } //switch
7559 }
7560 pEntry = pEntryTmp;
7561 }
7562
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307563 csrLLUnlock(pCmdList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007564
7565 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
7566 {
7567 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7568 csrReleaseCommandScan( pMac, pCommand );
7569 }
7570
7571 csrLLClose(&localList);
7572
7573 return (fRet);
7574}
7575
7576
7577tANI_BOOLEAN csrScanRemoveFreshScanCommand(tpAniSirGlobal pMac, tANI_U8 sessionId)
7578{
7579 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
7580 tListElem *pEntry, *pEntryTmp;
7581 tSmeCmd *pCommand;
7582 tDblLinkList localList;
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307583 tDblLinkList *pCmdList;
Jeff Johnson295189b2012-06-20 16:38:30 -07007584
7585 vos_mem_zero(&localList, sizeof(tDblLinkList));
7586 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
7587 {
7588 smsLog(pMac, LOGE, FL(" failed to open list"));
7589 return fRet;
7590 }
7591
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307592 if (!pMac->fScanOffload)
7593 pCmdList = &pMac->sme.smeCmdPendingList;
7594 else
7595 pCmdList = &pMac->sme.smeScanCmdPendingList;
7596
7597 csrLLLock(pCmdList);
7598 pEntry = csrLLPeekHead(pCmdList, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007599 while(pEntry)
7600 {
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307601 pEntryTmp = csrLLNext(pCmdList, pEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007602 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7603 if( (eSmeCommandScan == pCommand->command) && (sessionId == pCommand->sessionId) )
7604 {
7605 switch(pCommand->u.scanCmd.reason)
7606 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07007607#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
7608 case eCsrScanGetLfrResult:
7609#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07007610 case eCsrScanGetResult:
7611 case eCsrScanSetBGScanParam:
7612 case eCsrScanBGScanAbort:
7613 case eCsrScanBGScanEnable:
7614 case eCsrScanGetScanChnInfo:
7615 break;
7616 default:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007617 smsLog (pMac, LOGW, "%s: -------- abort scan command reason = %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007618 __func__, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07007619 //The rest are fresh scan requests
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307620 if( csrLLRemoveEntry(pCmdList, pEntry, LL_ACCESS_NOLOCK) )
Jeff Johnson295189b2012-06-20 16:38:30 -07007621 {
7622 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
7623 }
7624 fRet = eANI_BOOLEAN_TRUE;
7625 break;
7626 }
7627 }
7628 pEntry = pEntryTmp;
7629 }
7630
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307631 csrLLUnlock(pCmdList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007632
7633 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
7634 {
7635 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7636 if (pCommand->u.scanCmd.callback)
7637 {
7638 /* User scan request is pending,
7639 * send response with status eCSR_SCAN_ABORT*/
7640 pCommand->u.scanCmd.callback(pMac,
7641 pCommand->u.scanCmd.pContext,
7642 pCommand->u.scanCmd.scanID,
7643 eCSR_SCAN_ABORT);
7644 }
7645 csrReleaseCommandScan( pMac, pCommand );
7646 }
7647 csrLLClose(&localList);
7648
7649 return (fRet);
7650}
7651
7652
7653void csrReleaseScanCommand(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
7654{
7655 eCsrScanReason reason = pCommand->u.scanCmd.reason;
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307656 tANI_BOOLEAN status;
7657
7658 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07007659 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307660 tANI_U32 i;
7661 for(i = 0; i < CSR_ROAM_SESSION_MAX; i++)
7662 csrRoamStateChange(pMac, pCommand->u.scanCmd.lastRoamState[i], i);
7663 }
7664 else
7665 {
7666 csrRoamStateChange(pMac,
7667 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId],
7668 pCommand->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07007669 }
7670
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307671 csrScanCallCallback(pMac, pCommand, scanStatus);
Jeff Johnson295189b2012-06-20 16:38:30 -07007672
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007673 smsLog(pMac, LOG3, " Remove Scan command reason = %d", reason);
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307674 if (pMac->fScanOffload)
7675 {
7676 status = csrLLRemoveEntry(&pMac->sme.smeScanCmdActiveList,
7677 &pCommand->Link, LL_ACCESS_LOCK);
7678 }
7679 else
7680 {
7681 status = csrLLRemoveEntry(&pMac->sme.smeCmdActiveList,
7682 &pCommand->Link, LL_ACCESS_LOCK);
7683 }
7684
7685 if(status)
Jeff Johnson295189b2012-06-20 16:38:30 -07007686 {
7687 csrReleaseCommandScan( pMac, pCommand );
7688 }
7689 else
7690 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307691 smsLog(pMac, LOGE,
7692 " ********csrReleaseScanCommand cannot release command reason %d",
7693 pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07007694 }
7695}
7696
7697
7698eHalStatus csrScanGetPMKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
7699 tPmkidCandidateInfo *pPmkidList, tANI_U32 *pNumItems )
7700{
7701 eHalStatus status = eHAL_STATUS_SUCCESS;
7702 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
7703
Jeff Johnson32d95a32012-09-10 13:15:23 -07007704 if(!pSession)
7705 {
7706 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
7707 return eHAL_STATUS_FAILURE;
7708 }
7709
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007710 smsLog(pMac, LOGW, " pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07007711 csrResetPMKIDCandidateList(pMac, sessionId);
7712 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
7713 {
7714 tCsrScanResultFilter *pScanFilter;
7715 tCsrScanResultInfo *pScanResult;
7716 tScanResultHandle hBSSList;
7717 tANI_U32 nItems = *pNumItems;
7718
7719 *pNumItems = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05307720 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
7721 if ( NULL == pScanFilter )
7722 status = eHAL_STATUS_FAILURE;
7723 else
Jeff Johnson295189b2012-06-20 16:38:30 -07007724 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307725 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007726 //Here is the profile we need to connect to
7727 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
7728 if(HAL_STATUS_SUCCESS(status))
7729 {
7730 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
7731 if(HAL_STATUS_SUCCESS(status))
7732 {
7733 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumPmkidCandidate < nItems))
7734 {
7735 //NumPmkidCandidate adds up here
7736 csrProcessBSSDescForPMKIDList(pMac, &pScanResult->BssDescriptor,
7737 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
7738 }
7739 if(pSession->NumPmkidCandidate)
7740 {
7741 *pNumItems = pSession->NumPmkidCandidate;
Kiet Lam64c1b492013-07-12 13:56:44 +05307742 vos_mem_copy(pPmkidList, pSession->PmkidCandidateInfo,
7743 pSession->NumPmkidCandidate * sizeof(tPmkidCandidateInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07007744 }
7745 csrScanResultPurge(pMac, hBSSList);
7746 }//Have scan result
7747 csrFreeScanFilter(pMac, pScanFilter);
7748 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307749 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07007750 }
7751 }
7752
7753 return (status);
7754}
7755
7756
7757
7758#ifdef FEATURE_WLAN_WAPI
7759eHalStatus csrScanGetBKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
7760 tBkidCandidateInfo *pBkidList, tANI_U32 *pNumItems )
7761{
7762 eHalStatus status = eHAL_STATUS_SUCCESS;
7763 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
7764
Jeff Johnson32d95a32012-09-10 13:15:23 -07007765 if(!pSession)
7766 {
7767 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
7768 return eHAL_STATUS_FAILURE;
7769 }
7770
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007771 smsLog(pMac, LOGW, " pMac->scan.NumBkidCandidate = %d", pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07007772 csrResetBKIDCandidateList(pMac, sessionId);
7773 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
7774 {
7775 tCsrScanResultFilter *pScanFilter;
7776 tCsrScanResultInfo *pScanResult;
7777 tScanResultHandle hBSSList;
7778 tANI_U32 nItems = *pNumItems;
7779 *pNumItems = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05307780 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
7781 if ( NULL == pScanFilter )
7782 status = eHAL_STATUS_FAILURE;
7783 else
Jeff Johnson295189b2012-06-20 16:38:30 -07007784 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307785 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007786 //Here is the profile we need to connect to
7787 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
7788 if(HAL_STATUS_SUCCESS(status))
7789 {
7790 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
7791 if(HAL_STATUS_SUCCESS(status))
7792 {
7793 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumBkidCandidate < nItems))
7794 {
7795 //pMac->scan.NumBkidCandidate adds up here
7796 csrProcessBSSDescForBKIDList(pMac, &pScanResult->BssDescriptor,
7797 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
7798
7799 }
7800 if(pSession->NumBkidCandidate)
7801 {
7802 *pNumItems = pSession->NumBkidCandidate;
Kiet Lam64c1b492013-07-12 13:56:44 +05307803 vos_mem_copy(pBkidList, pSession->BkidCandidateInfo, pSession->NumBkidCandidate * sizeof(tBkidCandidateInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07007804 }
7805 csrScanResultPurge(pMac, hBSSList);
7806 }//Have scan result
7807 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307808 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07007809 }
7810 }
7811
7812 return (status);
7813}
7814#endif /* FEATURE_WLAN_WAPI */
7815
Selvaraj, Sridhar32417ed2016-06-22 15:19:12 +05307816/**
7817 * csr_scan_request_set_chan_time() - Populate max and min
7818 * channel time in Scan request
7819 * @pMac - pointer to mac context
7820 * @pScanCmd - pointer to the Scan command
7821 *
7822 * Return - None
7823 */
7824#ifndef QCA_WIFI_ISOC
7825static void csr_scan_request_set_chan_time(tpAniSirGlobal pMac,
7826 tSmeCmd *pScanCmd)
7827{
7828 if (pMac->roam.neighborRoamInfo.handoffReqInfo.src
7829 == FASTREASSOC) {
7830 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime
7831 = MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL_FASTREASSOC;
7832 pScanCmd->u.scanCmd.u.scanRequest.minChnTime
7833 = MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL_FASTREASSOC;
7834 pMac->roam.neighborRoamInfo.handoffReqInfo.src = 0;
7835 } else {
7836 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime
7837 = MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7838 pScanCmd->u.scanCmd.u.scanRequest.minChnTime
7839 = MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7840 }
7841}
7842#else
7843static void csr_scan_request_set_chan_time(tpAniSirGlobal pMac,
7844 tSmeCmd *pScanCmd)
7845{
7846 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime
7847 = MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7848 pScanCmd->u.scanCmd.u.scanRequest.minChnTime
7849 = MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7850}
7851#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07007852
7853//This function is usually used for BSSs that suppresses SSID so the profile
7854//shall have one and only one SSID
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007855eHalStatus csrScanForSSID(tpAniSirGlobal pMac, tANI_U32 sessionId, tCsrRoamProfile *pProfile, tANI_U32 roamId, tANI_BOOLEAN notify)
Jeff Johnson295189b2012-06-20 16:38:30 -07007856{
7857 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
7858 tSmeCmd *pScanCmd = NULL;
7859 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
7860 tANI_U8 index = 0;
7861 tANI_U32 numSsid = pProfile->SSIDs.numOfSSIDs;
7862
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007863 smsLog(pMac, LOG2, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007864 //For WDS, we use the index 0. There must be at least one in there
7865 if( CSR_IS_WDS_STA( pProfile ) && numSsid )
7866 {
7867 numSsid = 1;
7868 }
7869 if(pMac->scan.fScanEnable && ( numSsid == 1 ) )
7870 {
7871 do
7872 {
7873 pScanCmd = csrGetCommandBuffer(pMac);
7874 if(!pScanCmd)
7875 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007876 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007877 break;
7878 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307879 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
7880 pScanCmd->u.scanCmd.pToRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
7881 if ( NULL == pScanCmd->u.scanCmd.pToRoamProfile )
krunal soni587bf012014-02-04 12:35:11 -08007882 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307883 status = eHAL_STATUS_FAILURE;
krunal soni587bf012014-02-04 12:35:11 -08007884 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307885 else
krunal soni587bf012014-02-04 12:35:11 -08007886 {
7887 status = csrRoamCopyProfile(pMac, pScanCmd->u.scanCmd.pToRoamProfile, pProfile);
7888 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007889 if(!HAL_STATUS_SUCCESS(status))
7890 break;
7891 pScanCmd->u.scanCmd.roamId = roamId;
7892 pScanCmd->command = eSmeCommandScan;
Jeff Johnsone7245742012-09-05 17:12:55 -07007893 pScanCmd->sessionId = (tANI_U8)sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07007894 pScanCmd->u.scanCmd.callback = NULL;
7895 pScanCmd->u.scanCmd.pContext = NULL;
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007896 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 -07007897 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Kiet Lam64c1b492013-07-12 13:56:44 +05307898 vos_mem_set(&pScanCmd->u.scanCmd.u.scanRequest, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007899 pScanCmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Jeff Johnson295189b2012-06-20 16:38:30 -07007900 pScanCmd->u.scanCmd.u.scanRequest.BSSType = pProfile->BSSType;
Jeff Johnsone7245742012-09-05 17:12:55 -07007901 // To avoid 11b rate in probe request Set p2pSearch flag as 1 for P2P Client Mode
7902 if(VOS_P2P_CLIENT_MODE == pProfile->csrPersona)
7903 {
7904 pScanCmd->u.scanCmd.u.scanRequest.p2pSearch = 1;
7905 }
Agarwal Ashish4f616132013-12-30 23:32:50 +05307906 if(pProfile->nAddIEScanLength)
Jeff Johnsone7245742012-09-05 17:12:55 -07007907 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307908 pScanCmd->u.scanCmd.u.scanRequest.pIEField = vos_mem_malloc(
7909 pProfile->nAddIEScanLength);
7910 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.pIEField )
7911 status = eHAL_STATUS_FAILURE;
7912 else
7913 status = eHAL_STATUS_SUCCESS;
7914 vos_mem_set(pScanCmd->u.scanCmd.u.scanRequest.pIEField,
7915 pProfile->nAddIEScanLength, 0);
7916 if (HAL_STATUS_SUCCESS(status))
Jeff Johnsone7245742012-09-05 17:12:55 -07007917 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307918 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.pIEField,
Agarwal Ashish4f616132013-12-30 23:32:50 +05307919 pProfile->addIEScan, pProfile->nAddIEScanLength);
Jeff Johnsone7245742012-09-05 17:12:55 -07007920 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = pProfile->nAddIEScanLength;
7921 }
7922 else
7923 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007924 smsLog(pMac, LOGE, "No memory for scanning IE fields");
Jeff Johnsone7245742012-09-05 17:12:55 -07007925 }
7926 } //Allocate memory for IE field
7927 else
7928 {
7929 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = 0;
7930 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07007931 /* For one channel be good enpugh time to receive beacon atleast */
7932 if( 1 == pProfile->ChannelInfo.numOfChannels )
7933 {
Selvaraj, Sridhar32417ed2016-06-22 15:19:12 +05307934 csr_scan_request_set_chan_time(pMac, pScanCmd);
7935 } else {
Kiet Lam64c1b492013-07-12 13:56:44 +05307936 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime =
7937 pMac->roam.configParam.nActiveMaxChnTime;
7938 pScanCmd->u.scanCmd.u.scanRequest.minChnTime =
7939 pMac->roam.configParam.nActiveMinChnTime;
Jeff Johnson32d95a32012-09-10 13:15:23 -07007940 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307941 pScanCmd->u.scanCmd.u.scanRequest.maxChnTimeBtc =
7942 pMac->roam.configParam.nActiveMaxChnTimeBtc;
7943 pScanCmd->u.scanCmd.u.scanRequest.minChnTimeBtc =
7944 pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07007945 if(pProfile->BSSIDs.numOfBSSIDs == 1)
7946 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307947 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.bssid,
7948 pProfile->BSSIDs.bssid, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07007949 }
7950 else
7951 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307952 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.bssid, bAddr, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07007953 }
7954 if(pProfile->ChannelInfo.numOfChannels)
7955 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307956 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(
7957 sizeof(*pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
7958 * pProfile->ChannelInfo.numOfChannels);
7959 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
7960 status = eHAL_STATUS_FAILURE;
7961 else
7962 status = eHAL_STATUS_SUCCESS;
7963 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
7964 if(HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07007965 {
7966 csrRoamIsChannelValid(pMac, pProfile->ChannelInfo.ChannelList[0]);
7967 for(index = 0; index < pProfile->ChannelInfo.numOfChannels; index++)
7968 {
7969 if(csrRoamIsValidChannel(pMac, pProfile->ChannelInfo.ChannelList[index]))
7970 {
7971 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels]
7972 = pProfile->ChannelInfo.ChannelList[index];
7973 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels++;
7974 }
7975 else
7976 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007977 smsLog(pMac, LOGW, FL("process a channel (%d) that is invalid"), pProfile->ChannelInfo.ChannelList[index]);
Jeff Johnson295189b2012-06-20 16:38:30 -07007978 }
7979
7980 }
7981 }
7982 else
7983 {
7984 break;
7985 }
7986
7987 }
7988 else
7989 {
7990 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
7991 }
7992 if(pProfile->SSIDs.numOfSSIDs)
7993 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307994 pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList = vos_mem_malloc(
7995 pProfile->SSIDs.numOfSSIDs * sizeof(tCsrSSIDInfo));
7996 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList )
7997 status = eHAL_STATUS_FAILURE;
7998 else
7999 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07008000 if(!HAL_STATUS_SUCCESS(status))
8001 {
8002 break;
8003 }
8004 pScanCmd->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 1;
Kiet Lam64c1b492013-07-12 13:56:44 +05308005 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList,
8006 pProfile->SSIDs.SSIDList, sizeof(tCsrSSIDInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07008007 }
8008 //Start process the command
8009 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
8010 if( !HAL_STATUS_SUCCESS( status ) )
8011 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008012 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07008013 break;
8014 }
8015 }while(0);
8016 if(!HAL_STATUS_SUCCESS(status))
8017 {
8018 if(pScanCmd)
8019 {
8020 csrReleaseCommandScan(pMac, pScanCmd);
8021 //TODO:free the memory that is allocated in this function
8022 }
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008023 if(notify)
8024 {
Jeff Johnson295189b2012-06-20 16:38:30 -07008025 csrRoamCallCallback(pMac, sessionId, NULL, roamId, eCSR_ROAM_FAILED, eCSR_ROAM_RESULT_FAILURE);
8026 }
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008027 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008028 }//valid
8029 else
8030 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008031 smsLog(pMac, LOGE, FL("cannot scan because scanEnable (%d) or numSSID (%d) is invalid"),
Jeff Johnson295189b2012-06-20 16:38:30 -07008032 pMac->scan.fScanEnable, pProfile->SSIDs.numOfSSIDs);
8033 }
8034
8035 return (status);
8036}
8037
8038
8039//Issue a scan base on the new capability infomation
8040//This should only happen when the associated AP changes its capability.
8041//After this scan is done, CSR reroams base on the new scan results
8042eHalStatus csrScanForCapabilityChange(tpAniSirGlobal pMac, tSirSmeApNewCaps *pNewCaps)
8043{
8044 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
8045 tSmeCmd *pScanCmd = NULL;
8046
8047 if(pNewCaps)
8048 {
8049 do
8050 {
8051 pScanCmd = csrGetCommandBuffer(pMac);
8052 if(!pScanCmd)
8053 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008054 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07008055 status = eHAL_STATUS_RESOURCES;
8056 break;
8057 }
Kiet Lam64c1b492013-07-12 13:56:44 +05308058 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008059 status = eHAL_STATUS_SUCCESS;
8060 pScanCmd->u.scanCmd.roamId = 0;
8061 pScanCmd->command = eSmeCommandScan;
8062 pScanCmd->u.scanCmd.callback = NULL;
8063 pScanCmd->u.scanCmd.pContext = NULL;
8064 pScanCmd->u.scanCmd.reason = eCsrScanForCapsChange;
8065 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
8066 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
8067 if( !HAL_STATUS_SUCCESS( status ) )
8068 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008069 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07008070 break;
8071 }
8072 }while(0);
8073 if(!HAL_STATUS_SUCCESS(status))
8074 {
8075 if(pScanCmd)
8076 {
8077 csrReleaseCommandScan(pMac, pScanCmd);
8078 }
8079 }
8080 }
8081
8082 return (status);
8083}
8084
8085
8086
8087void csrInitBGScanChannelList(tpAniSirGlobal pMac)
8088{
8089 tANI_U32 len = CSR_MIN(sizeof(pMac->roam.validChannelList), sizeof(pMac->scan.bgScanChannelList));
8090
Kiet Lam64c1b492013-07-12 13:56:44 +05308091 vos_mem_set(pMac->scan.bgScanChannelList, len, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008092 pMac->scan.numBGScanChannel = 0;
8093
8094 if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
8095 {
8096 pMac->roam.numValidChannels = len;
8097 pMac->scan.numBGScanChannel = (tANI_U8)CSR_MIN(len, WNI_CFG_BG_SCAN_CHANNEL_LIST_LEN);
Kiet Lam64c1b492013-07-12 13:56:44 +05308098 vos_mem_copy(pMac->scan.bgScanChannelList, pMac->roam.validChannelList,
8099 pMac->scan.numBGScanChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07008100 csrSetBGScanChannelList(pMac, pMac->scan.bgScanChannelList, pMac->scan.numBGScanChannel);
8101 }
8102}
8103
8104
8105//This function return TRUE if background scan channel list is adjusted.
8106//this function will only shrink the background scan channel list
8107tANI_BOOLEAN csrAdjustBGScanChannelList(tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels,
8108 tANI_U8 *pAdjustChannels, tANI_U8 *pNumAdjustChannels)
8109{
8110 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
8111 tANI_U8 i, j, count = *pNumAdjustChannels;
8112
8113 i = 0;
8114 while(i < count)
8115 {
8116 for(j = 0; j < NumChannels; j++)
8117 {
8118 if(pChannelList[j] == pAdjustChannels[i])
8119 break;
8120 }
8121 if(j == NumChannels)
8122 {
8123 //This channel is not in the list, remove it
8124 fRet = eANI_BOOLEAN_TRUE;
8125 count--;
8126 if(count - i)
8127 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308128 vos_mem_copy(&pAdjustChannels[i], &pAdjustChannels[i+1], count - i);
Jeff Johnson295189b2012-06-20 16:38:30 -07008129 }
8130 else
8131 {
8132 //already remove the last one. Done.
8133 break;
8134 }
8135 }
8136 else
8137 {
8138 i++;
8139 }
8140 }//while(i<count)
8141 *pNumAdjustChannels = count;
8142
8143 return (fRet);
8144}
8145
8146
8147//Get the list of the base channels to scan for passively 11d info
8148eHalStatus csrScanGetSupportedChannels( tpAniSirGlobal pMac )
8149{
8150 eHalStatus status = eHAL_STATUS_SUCCESS;
8151 int n = WNI_CFG_VALID_CHANNEL_LIST_LEN;
8152
8153 status = vos_nv_getSupportedChannels( pMac->scan.baseChannels.channelList, &n, NULL, NULL );
8154 if( HAL_STATUS_SUCCESS(status) )
8155 {
8156 pMac->scan.baseChannels.numChannels = (tANI_U8)n;
8157 }
8158 else
8159 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008160 smsLog( pMac, LOGE, FL(" failed") );
Jeff Johnson295189b2012-06-20 16:38:30 -07008161 pMac->scan.baseChannels.numChannels = 0;
8162 }
8163
8164 return ( status );
8165}
8166
8167//This function use the input pChannelList to validate the current saved channel list
8168eHalStatus csrSetBGScanChannelList( tpAniSirGlobal pMac, tANI_U8 *pAdjustChannels, tANI_U8 NumAdjustChannels)
8169{
8170 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumAdjustChannels;
8171
8172 return (ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pAdjustChannels, dataLen, NULL, eANI_BOOLEAN_FALSE));
8173}
8174
8175
8176void csrSetCfgValidChannelList( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels )
8177{
8178 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumChannels;
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05308179 eHalStatus status;
Jeff Johnson295189b2012-06-20 16:38:30 -07008180
Mihir Shete31c435d2014-02-12 13:13:34 +05308181 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
8182 "%s: dump valid channel list(NumChannels(%d))",
8183 __func__,NumChannels);
8184 VOS_TRACE_HEX_DUMP(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
8185 pChannelList, NumChannels);
8186
Jeff Johnson295189b2012-06-20 16:38:30 -07008187 ccmCfgSetStr(pMac, WNI_CFG_VALID_CHANNEL_LIST, pChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
Leela Venkata Kiran Kumar Reddy Chiralac6663f72014-02-03 21:04:58 -08008188#ifdef QCA_WIFI_2_0
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05308189 if (pMac->fScanOffload)
8190 {
8191 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
8192 "Scan offload is enabled, update default chan list");
Leela Venkata Kiran Kumar Reddy Chiralac6663f72014-02-03 21:04:58 -08008193 status = csrUpdateChannelList(pMac);
8194 }
8195#else
8196 status = csrUpdateChannelList(pMac);
8197#endif
8198
8199 if (eHAL_STATUS_SUCCESS != status)
8200 {
8201 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR,
8202 "failed to update the supported channel list");
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05308203 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008204 return;
8205}
8206
8207
8208
8209/*
8210 * The Tx power limits are saved in the cfg for future usage.
8211 */
8212void csrSaveTxPowerToCfg( tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 cfgId )
8213{
8214 tListElem *pEntry;
8215 tANI_U32 cbLen = 0, dataLen;
8216 tCsrChannelPowerInfo *pChannelSet;
8217 tANI_U32 idx;
8218 tSirMacChanInfo *pChannelPowerSet;
8219 tANI_U8 *pBuf = NULL;
8220
8221 //allocate maximum space for all channels
8222 dataLen = WNI_CFG_VALID_CHANNEL_LIST_LEN * sizeof(tSirMacChanInfo);
Kiet Lam64c1b492013-07-12 13:56:44 +05308223 if ( (pBuf = vos_mem_malloc(dataLen)) != NULL )
Jeff Johnson295189b2012-06-20 16:38:30 -07008224 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308225 vos_mem_set(pBuf, dataLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008226 pChannelPowerSet = (tSirMacChanInfo *)(pBuf);
8227
8228 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
8229 // write the tuples (startChan, numChan, txPower) for each channel found in the channel power list.
8230 while( pEntry )
8231 {
8232 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
8233 if ( 1 != pChannelSet->interChannelOffset )
8234 {
8235 // we keep the 5G channel sets internally with an interchannel offset of 4. Expand these
8236 // to the right format... (inter channel offset of 1 is the only option for the triplets
8237 // that 11d advertises.
8238 if ((cbLen + (pChannelSet->numChannels * sizeof(tSirMacChanInfo))) >= dataLen)
8239 {
8240 // expanding this entry will overflow our allocation
8241 smsLog(pMac, LOGE,
8242 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07008243 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07008244 pChannelSet->firstChannel,
8245 pChannelSet->numChannels,
8246 pChannelSet->interChannelOffset);
8247 break;
8248 }
8249
8250 for( idx = 0; idx < pChannelSet->numChannels; idx++ )
8251 {
8252 pChannelPowerSet->firstChanNum = (tSirMacChanNum)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008253 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07008254 pChannelPowerSet->numChannels = 1;
Jeff Johnson295189b2012-06-20 16:38:30 -07008255 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008256 smsLog(pMac, LOG3, " Setting Max Transmit Power %d", pChannelPowerSet->maxTxPower);
Jeff Johnson295189b2012-06-20 16:38:30 -07008257 cbLen += sizeof( tSirMacChanInfo );
8258 pChannelPowerSet++;
8259 }
8260 }
8261 else
8262 {
8263 if (cbLen >= dataLen)
8264 {
8265 // this entry will overflow our allocation
8266 smsLog(pMac, LOGE,
8267 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07008268 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07008269 pChannelSet->firstChannel,
8270 pChannelSet->numChannels,
8271 pChannelSet->interChannelOffset);
8272 break;
8273 }
8274 pChannelPowerSet->firstChanNum = pChannelSet->firstChannel;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008275 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07008276 pChannelPowerSet->numChannels = pChannelSet->numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -07008277 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008278 smsLog(pMac, LOG3, " Setting Max Transmit Power %d, nTxPower %d", pChannelPowerSet->maxTxPower,pMac->roam.configParam.nTxPowerCap );
Jeff Johnson295189b2012-06-20 16:38:30 -07008279
8280
8281 cbLen += sizeof( tSirMacChanInfo );
8282 pChannelPowerSet++;
8283 }
8284
8285 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
8286 }
8287
8288 if(cbLen)
8289 {
8290 ccmCfgSetStr(pMac, cfgId, (tANI_U8 *)pBuf, cbLen, NULL, eANI_BOOLEAN_FALSE);
8291 }
Kiet Lam64c1b492013-07-12 13:56:44 +05308292 vos_mem_free(pBuf);
Jeff Johnson295189b2012-06-20 16:38:30 -07008293 }//Allocate memory
8294}
8295
8296
8297void csrSetCfgCountryCode( tpAniSirGlobal pMac, tANI_U8 *countryCode )
8298{
8299 tANI_U8 cc[WNI_CFG_COUNTRY_CODE_LEN];
8300 ///v_REGDOMAIN_t DomainId;
8301
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008302 smsLog( pMac, LOG3, "Setting Country Code in Cfg from csrSetCfgCountryCode %s",countryCode );
Kiet Lam64c1b492013-07-12 13:56:44 +05308303 vos_mem_copy(cc, countryCode, WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07008304
8305 // don't program the bogus country codes that we created for Korea in the MAC. if we see
8306 // the bogus country codes, program the MAC with the right country code.
8307 if ( ( 'K' == countryCode[ 0 ] && '1' == countryCode[ 1 ] ) ||
8308 ( 'K' == countryCode[ 0 ] && '2' == countryCode[ 1 ] ) ||
8309 ( 'K' == countryCode[ 0 ] && '3' == countryCode[ 1 ] ) ||
8310 ( 'K' == countryCode[ 0 ] && '4' == countryCode[ 1 ] ) )
8311 {
8312 // replace the alternate Korea country codes, 'K1', 'K2', .. with 'KR' for Korea
8313 cc[ 1 ] = 'R';
8314 }
8315 ccmCfgSetStr(pMac, WNI_CFG_COUNTRY_CODE, cc, WNI_CFG_COUNTRY_CODE_LEN, NULL, eANI_BOOLEAN_FALSE);
8316
8317 //Need to let HALPHY know about the current domain so it can apply some
8318 //domain-specific settings (TX filter...)
8319 /*if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(pMac, cc, &DomainId)))
8320 {
8321 halPhySetRegDomain(pMac, DomainId);
8322 }*/
8323}
8324
8325
8326
8327eHalStatus csrGetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pBuf, tANI_U8 *pbLen)
8328{
8329 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
8330 tANI_U32 len;
8331
8332 if(pBuf && pbLen && (*pbLen >= WNI_CFG_COUNTRY_CODE_LEN))
8333 {
8334 len = *pbLen;
8335 status = ccmCfgGetStr(pMac, WNI_CFG_COUNTRY_CODE, pBuf, &len);
8336 if(HAL_STATUS_SUCCESS(status))
8337 {
8338 *pbLen = (tANI_U8)len;
8339 }
8340 }
8341
8342 return (status);
8343}
8344
8345
8346void csrSetCfgScanControlList( tpAniSirGlobal pMac, tANI_U8 *countryCode, tCsrChannel *pChannelList )
8347{
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05308348 tANI_U8 i, j, k;
Jeff Johnson295189b2012-06-20 16:38:30 -07008349 tANI_BOOLEAN found=FALSE;
8350 tANI_U8 *pControlList = NULL;
8351 tANI_U32 len = WNI_CFG_SCAN_CONTROL_LIST_LEN;
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05308352 tANI_U8 cfgActiveDFSChannels = 0;
8353 tANI_U8 *cfgActiveDFSChannelLIst = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07008354
Kiet Lam64c1b492013-07-12 13:56:44 +05308355 if ( (pControlList = vos_mem_malloc(WNI_CFG_SCAN_CONTROL_LIST_LEN)) != NULL )
Jeff Johnson295189b2012-06-20 16:38:30 -07008356 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308357 vos_mem_set((void *)pControlList, WNI_CFG_SCAN_CONTROL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008358 if(HAL_STATUS_SUCCESS(ccmCfgGetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, &len)))
8359 {
8360 for (i = 0; i < pChannelList->numChannels; i++)
8361 {
8362 for (j = 0; j < len; j += 2)
8363 {
8364 if (pControlList[j] == pChannelList->channelList[i])
8365 {
8366 found = TRUE;
8367 break;
8368 }
8369 }
8370
8371 if (found) // insert a pair(channel#, flag)
8372 {
Gopichand Nakkala392cbc12013-05-28 16:15:00 +05308373 pControlList[j+1] = csrGetScanType(pMac, pControlList[j]);
Jeff Johnson295189b2012-06-20 16:38:30 -07008374 found = FALSE; // reset the flag
Jeff Johnson295189b2012-06-20 16:38:30 -07008375
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05308376 // When DFS mode is 2, mark static channels as active
8377 if (pMac->scan.fEnableDFSChnlScan ==
8378 DFS_CHNL_SCAN_ENABLED_ACTIVE)
8379 {
8380 cfgActiveDFSChannels =
8381 pMac->roam.neighborRoamInfo.cfgParams.
8382 channelInfo.numOfChannels;
8383 cfgActiveDFSChannelLIst =
8384 pMac->roam.neighborRoamInfo.cfgParams.
8385 channelInfo.ChannelList;
8386 if (cfgActiveDFSChannelLIst)
8387 {
8388 for (k=0; k < cfgActiveDFSChannels; k++)
8389 {
8390 if(CSR_IS_CHANNEL_DFS(cfgActiveDFSChannelLIst[k])
8391 && (pControlList[j] ==
8392 cfgActiveDFSChannelLIst[k]))
8393 {
8394 pControlList[j+1] = eSIR_ACTIVE_SCAN;
8395 smsLog(pMac, LOG1, FL("Marked DFS ch %d"
8396 " as active"),
8397 cfgActiveDFSChannelLIst[k]);
8398 }
8399 }
8400 }
8401 }
8402 }
8403 }
8404
8405 smsLog(pMac, LOG1, FL("fEnableDFSChnlScan %d"),
8406 pMac->scan.fEnableDFSChnlScan);
Mihir Shete31c435d2014-02-12 13:13:34 +05308407 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
8408 "%s: dump scan control list",__func__);
8409 VOS_TRACE_HEX_DUMP(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
8410 pControlList, len);
8411
Jeff Johnson295189b2012-06-20 16:38:30 -07008412 ccmCfgSetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, len, NULL, eANI_BOOLEAN_FALSE);
8413 }//Successfully getting scan control list
Kiet Lam64c1b492013-07-12 13:56:44 +05308414 vos_mem_free(pControlList);
Jeff Johnson295189b2012-06-20 16:38:30 -07008415 }//AllocateMemory
8416}
8417
Jeff Johnson295189b2012-06-20 16:38:30 -07008418//if bgPeriod is 0, background scan is disabled. It is in millisecond units
8419eHalStatus csrSetCfgBackgroundScanPeriod(tpAniSirGlobal pMac, tANI_U32 bgPeriod)
8420{
8421 return (ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, bgPeriod, (tCcmCfgSetCallback) csrScanCcmCfgSetCallback, eANI_BOOLEAN_FALSE));
8422}
8423
8424
8425void csrScanCcmCfgSetCallback(tHalHandle hHal, tANI_S32 result)
8426{
8427 tListElem *pEntry = NULL;
8428 tSmeCmd *pCommand = NULL;
8429 tpAniSirGlobal pMac = PMAC_STRUCT( hHal );
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05308430 tDblLinkList *pCmdList ;
8431
8432 if (!pMac->fScanOffload)
8433 pCmdList = &pMac->sme.smeCmdActiveList;
8434 else
8435 pCmdList = &pMac->sme.smeScanCmdActiveList;
8436
8437 pEntry = csrLLPeekHead( pCmdList, LL_ACCESS_LOCK );
Jeff Johnson295189b2012-06-20 16:38:30 -07008438 if ( pEntry )
8439 {
8440 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8441 if ( eSmeCommandScan == pCommand->command )
8442 {
8443 eCsrScanStatus scanStatus = (CCM_IS_RESULT_SUCCESS(result)) ? eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
8444 csrReleaseScanCommand(pMac, pCommand, scanStatus);
8445 }
8446 else
8447 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008448 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
Jeff Johnson295189b2012-06-20 16:38:30 -07008449 }
8450 }
8451 smeProcessPendingQueue( pMac );
8452}
8453
8454eHalStatus csrProcessSetBGScanParam(tpAniSirGlobal pMac, tSmeCmd *pCommand)
8455{
8456 eHalStatus status;
8457 tCsrBGScanRequest *pScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
8458 tANI_U32 dataLen = sizeof( tANI_U8 ) * pScanReq->ChannelInfo.numOfChannels;
8459
8460 //***setcfg for background scan channel list
8461 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MINIMUM_CHANNEL_TIME, pScanReq->minChnTime, NULL, eANI_BOOLEAN_FALSE);
8462 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MAXIMUM_CHANNEL_TIME, pScanReq->maxChnTime, NULL, eANI_BOOLEAN_FALSE);
8463 //Not set the background scan interval if not connected because bd scan should not be run if not connected
8464 if(!csrIsAllSessionDisconnected(pMac))
8465 {
Jeff Johnson295189b2012-06-20 16:38:30 -07008466
8467#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
8468 {
8469 vos_log_scan_pkt_type *pScanLog = NULL;
8470
8471 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
8472 if(pScanLog)
8473 {
8474 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
8475 pScanLog->minChnTime = (v_U8_t)pScanReq->minChnTime;
8476 pScanLog->maxChnTime = (v_U8_t)pScanReq->maxChnTime;
8477 pScanLog->timeBetweenBgScan = (v_U8_t)pScanReq->scanInterval;
8478 pScanLog->numChannel = pScanReq->ChannelInfo.numOfChannels;
8479 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
8480 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308481 vos_mem_copy(pScanLog->channels,
8482 pScanReq->ChannelInfo.ChannelList,
8483 pScanLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07008484 }
8485 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
8486 }
8487 }
8488#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
8489
8490 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, pScanReq->scanInterval, NULL, eANI_BOOLEAN_FALSE);
8491 }
8492 else
8493 {
8494 //No need to stop aging because IDLE scan is still running
8495 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, 0, NULL, eANI_BOOLEAN_FALSE);
8496 }
8497
8498 if(pScanReq->SSID.length > WNI_CFG_SSID_LEN)
8499 {
8500 pScanReq->SSID.length = WNI_CFG_SSID_LEN;
8501 }
8502
8503 status = ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pScanReq->ChannelInfo.ChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
8504 status = ccmCfgSetStr(pMac, WNI_CFG_SSID, (tANI_U8 *)pScanReq->SSID.ssId, pScanReq->SSID.length, NULL, eANI_BOOLEAN_FALSE);
8505
8506
8507
8508 return (status);
8509}
8510
8511
c_hpothua3d45d52015-01-05 14:11:17 +05308512tSirAbortScanStatus csrScanAbortMacScan(tpAniSirGlobal pMac,
8513 tANI_U8 sessionId,
8514 eCsrAbortReason reason)
Jeff Johnson295189b2012-06-20 16:38:30 -07008515{
c_hpothua3d45d52015-01-05 14:11:17 +05308516 tSirAbortScanStatus abortScanStatus = eSIR_ABORT_ACTIVE_SCAN_LIST_EMPTY;
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308517 tSirSmeScanAbortReq *pMsg;
Jeff Johnson295189b2012-06-20 16:38:30 -07008518 tANI_U16 msgLen;
8519 tListElem *pEntry;
8520 tSmeCmd *pCommand;
8521
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308522 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07008523 {
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308524#ifdef WLAN_AP_STA_CONCURRENCY
8525 csrLLLock(&pMac->scan.scanCmdPendingList);
8526 while(NULL !=
8527 (pEntry = csrLLRemoveHead(&pMac->scan.scanCmdPendingList,
8528 LL_ACCESS_NOLOCK)))
8529 {
Jeff Johnson295189b2012-06-20 16:38:30 -07008530
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308531 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8532 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
8533 }
8534 csrLLUnlock(&pMac->scan.scanCmdPendingList);
Jeff Johnson295189b2012-06-20 16:38:30 -07008535#endif
8536
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308537 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
8538 csrRemoveCmdFromPendingList( pMac, &pMac->roam.roamCmdPendingList, eSmeCommandScan);
8539 csrRemoveCmdFromPendingList( pMac, &pMac->sme.smeCmdPendingList, eSmeCommandScan);
8540 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
8541
8542 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
8543 }
8544 else
8545 {
8546 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
8547 csrRemoveCmdWithSessionIdFromPendingList(pMac,
8548 sessionId,
8549 &pMac->sme.smeScanCmdPendingList,
8550 eSmeCommandScan);
8551 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
8552
8553 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
8554 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008555
8556 //We need to abort scan only if we are scanning
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308557 if(NULL != pEntry)
Jeff Johnson295189b2012-06-20 16:38:30 -07008558 {
8559 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308560 if(eSmeCommandScan == pCommand->command &&
8561 pCommand->sessionId == sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07008562 {
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308563 msgLen = (tANI_U16)(sizeof(tSirSmeScanAbortReq));
Kiet Lam64c1b492013-07-12 13:56:44 +05308564 pMsg = vos_mem_malloc(msgLen);
8565 if ( NULL == pMsg )
Jeff Johnson295189b2012-06-20 16:38:30 -07008566 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308567 smsLog(pMac, LOGE, FL("Failed to allocate memory for SmeScanAbortReq"));
c_hpothua3d45d52015-01-05 14:11:17 +05308568 abortScanStatus = eSIR_ABORT_SCAN_FAILURE;
Kiet Lam64c1b492013-07-12 13:56:44 +05308569 }
8570 else
8571 {
Ratheesh S Pece1f832015-07-25 15:50:25 +05308572 pCommand->u.scanCmd.abortScanIndication = eCSR_SCAN_ABORT_DEFAULT;
Srinivas, Dasari187ca4e2014-02-07 12:40:09 +05308573 if(reason == eCSR_SCAN_ABORT_DUE_TO_BAND_CHANGE)
8574 {
Ratheesh S Pece1f832015-07-25 15:50:25 +05308575 pCommand->u.scanCmd.abortScanIndication
8576 = eCSR_SCAN_ABORT_DUE_TO_BAND_CHANGE;
Srinivas, Dasari187ca4e2014-02-07 12:40:09 +05308577 }
Kiet Lam64c1b492013-07-12 13:56:44 +05308578 vos_mem_set((void *)pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008579 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_ABORT_IND);
8580 pMsg->msgLen = pal_cpu_to_be16(msgLen);
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308581 pMsg->sessionId = sessionId;
c_hpothua3d45d52015-01-05 14:11:17 +05308582 if (eHAL_STATUS_SUCCESS != palSendMBMessage(pMac->hHdd, pMsg))
8583 {
8584 smsLog(pMac, LOGE,
8585 FL("Failed to post eWNI_SME_SCAN_ABORT_IND"));
8586 abortScanStatus = eSIR_ABORT_SCAN_FAILURE;
Ratheesh S Pece1f832015-07-25 15:50:25 +05308587 pCommand->u.scanCmd.abortScanIndication = 0;
c_hpothua3d45d52015-01-05 14:11:17 +05308588 }
8589 else
8590 {
8591 abortScanStatus = eSIR_ABORT_ACTIVE_SCAN_LIST_NOT_EMPTY;
8592 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008593 }
8594 }
8595 }
8596
c_hpothua3d45d52015-01-05 14:11:17 +05308597 return(abortScanStatus);
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308598}
8599
8600void csrRemoveCmdWithSessionIdFromPendingList(tpAniSirGlobal pMac,
8601 tANI_U8 sessionId,
8602 tDblLinkList *pList,
8603 eSmeCommandType commandType)
8604{
8605 tDblLinkList localList;
8606 tListElem *pEntry;
8607 tSmeCmd *pCommand;
8608 tListElem *pEntryToRemove;
8609
8610 vos_mem_zero(&localList, sizeof(tDblLinkList));
8611 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
8612 {
8613 smsLog(pMac, LOGE, FL(" failed to open list"));
8614 return;
8615 }
8616
8617 csrLLLock(pList);
8618 if ((pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK)))
8619 {
8620
8621 /* Have to make sure we don't loop back to the head of the list,
8622 * which will happen if the entry is NOT on the list */
8623 while (pEntry)
8624 {
8625 pEntryToRemove = pEntry;
8626 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
8627 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
8628 if ((pCommand->command == commandType) &&
8629 (pCommand->sessionId == sessionId))
8630 {
8631 /* Remove that entry only */
8632 if (csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
8633 {
8634 csrLLInsertTail(&localList, pEntryToRemove,
8635 LL_ACCESS_NOLOCK);
8636 }
8637 }
8638 }
8639 }
8640 csrLLUnlock(pList);
8641
8642 while ((pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)))
8643 {
8644 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
8645 csrAbortCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
8646 }
8647
8648 csrLLClose(&localList);
Jeff Johnson295189b2012-06-20 16:38:30 -07008649}
8650
8651void csrRemoveCmdFromPendingList(tpAniSirGlobal pMac, tDblLinkList *pList,
8652 eSmeCommandType commandType )
8653{
8654 tDblLinkList localList;
8655 tListElem *pEntry;
8656 tSmeCmd *pCommand;
8657 tListElem *pEntryToRemove;
8658
8659 vos_mem_zero(&localList, sizeof(tDblLinkList));
8660 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
8661 {
8662 smsLog(pMac, LOGE, FL(" failed to open list"));
8663 return;
8664 }
8665
8666 csrLLLock(pList);
8667 if( !csrLLIsListEmpty( pList, LL_ACCESS_NOLOCK ) )
8668 {
8669 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK);
8670
8671 // Have to make sure we don't loop back to the head of the list, which will
8672 // happen if the entry is NOT on the list...
8673 while( pEntry )
8674 {
8675 pEntryToRemove = pEntry;
8676 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
8677 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
8678 if ( pCommand->command == commandType )
8679 {
8680 // Remove that entry only
8681 if(csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
8682 {
8683 csrLLInsertTail(&localList, pEntryToRemove, LL_ACCESS_NOLOCK);
8684 }
8685 }
8686 }
8687
8688
8689 }
8690 csrLLUnlock(pList);
8691
8692 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
8693 {
8694 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8695 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
8696 }
8697 csrLLClose(&localList);
8698
8699}
8700
Abhishek Singhdc2bfd42014-06-19 17:59:05 +05308701eHalStatus csrScanAbortScanForSSID(tpAniSirGlobal pMac, tANI_U32 sessionId)
8702{
8703 eHalStatus status = eHAL_STATUS_SUCCESS;
8704 tSirSmeScanAbortReq *pMsg;
8705 tANI_U16 msgLen;
8706 tListElem *pEntry;
8707 tSmeCmd *pCommand;
8708
8709 if (!pMac->fScanOffload)
8710 {
8711 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
8712#ifdef WLAN_AP_STA_CONCURRENCY
8713 csrRemoveScanForSSIDFromPendingList( pMac, &pMac->scan.scanCmdPendingList, sessionId);
8714#endif
8715 csrRemoveScanForSSIDFromPendingList( pMac, &pMac->roam.roamCmdPendingList, sessionId);
8716 csrRemoveScanForSSIDFromPendingList( pMac, &pMac->sme.smeCmdPendingList, sessionId);
8717 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
8718 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
8719 }
8720 else
8721 {
8722 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
8723 csrRemoveScanForSSIDFromPendingList( pMac, &pMac->sme.smeScanCmdPendingList, sessionId);
8724 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
8725 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
8726 }
8727
8728 if(NULL != pEntry)
8729 {
8730 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8731
8732 if ( (eSmeCommandScan == pCommand->command ) &&
8733 (sessionId == pCommand->sessionId))
8734 {
8735 if ( eCsrScanForSsid == pCommand->u.scanCmd.reason)
8736 {
8737 msgLen = (tANI_U16)(sizeof( tSirSmeScanAbortReq ));
8738 pMsg = vos_mem_malloc(msgLen);
8739 if ( NULL == pMsg )
8740 {
8741 status = eHAL_STATUS_FAILURE;
8742 smsLog(pMac, LOGE, FL("Failed to allocate memory for SmeScanAbortReq"));
8743 }
8744 else
8745 {
8746 vos_mem_zero((void *)pMsg, msgLen);
8747 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_ABORT_IND);
8748 pMsg->msgLen = pal_cpu_to_be16(msgLen);
8749 pMsg->sessionId = sessionId;
8750 status = palSendMBMessage(pMac->hHdd, pMsg);
8751 }
8752 }
8753 }
8754 }
8755 return( status );
8756}
8757
8758void csrRemoveScanForSSIDFromPendingList(tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 sessionId)
8759{
8760 tDblLinkList localList;
8761 tListElem *pEntry;
8762 tSmeCmd *pCommand;
8763 tListElem *pEntryToRemove;
8764
8765 vos_mem_zero(&localList, sizeof(tDblLinkList));
8766 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
8767 {
8768 smsLog(pMac, LOGE, FL(" failed to open list"));
8769 return;
8770 }
8771
8772 csrLLLock(pList);
8773 if( !csrLLIsListEmpty( pList, LL_ACCESS_NOLOCK ) )
8774 {
8775 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK);
8776
8777 // Have to make sure we don't loop back to the head of the list, which will
8778 // happen if the entry is NOT on the list...
8779 while( pEntry )
8780 {
8781 pEntryToRemove = pEntry;
8782 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
8783 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
8784 if ( (eSmeCommandScan == pCommand->command ) &&
8785 (sessionId == pCommand->sessionId) )
8786 {
8787 if ( eCsrScanForSsid == pCommand->u.scanCmd.reason)
8788 {
8789 // Remove that entry only
8790 if ( csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
8791 {
8792 csrLLInsertTail(&localList, pEntryToRemove, LL_ACCESS_NOLOCK);
8793 }
8794 }
8795 }
8796 }
8797 }
8798 csrLLUnlock(pList);
8799
8800 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
8801 {
8802 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8803 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
8804 }
8805 csrLLClose(&localList);
8806}
Jeff Johnson295189b2012-06-20 16:38:30 -07008807
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308808eHalStatus csrScanAbortMacScanNotForConnect(tpAniSirGlobal pMac,
8809 tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07008810{
8811 eHalStatus status = eHAL_STATUS_SUCCESS;
8812
8813 if( !csrIsScanForRoamCommandActive( pMac ) )
8814 {
8815 //Only abort the scan if it is not used for other roam/connect purpose
c_hpothua3d45d52015-01-05 14:11:17 +05308816 if (eSIR_ABORT_SCAN_FAILURE ==
8817 csrScanAbortMacScan(pMac, sessionId, eCSR_SCAN_ABORT_DEFAULT))
8818 {
8819 smsLog(pMac, LOGE, FL("fail to abort scan"));
8820 status = eHAL_STATUS_FAILURE;
8821 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008822 }
8823
8824 return (status);
8825}
8826
8827
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05308828eHalStatus csrScanGetScanChannelInfo(tpAniSirGlobal pMac, tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07008829{
8830 eHalStatus status = eHAL_STATUS_SUCCESS;
8831 tSirMbMsg *pMsg;
8832 tANI_U16 msgLen;
8833
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05308834 if (pMac->fScanOffload)
8835 msgLen = (tANI_U16)(sizeof(tSirSmeGetScanChanReq));
8836 else
8837 msgLen = (tANI_U16)(sizeof(tSirMbMsg));
8838
Kiet Lam64c1b492013-07-12 13:56:44 +05308839 pMsg = vos_mem_malloc(msgLen);
8840 if ( NULL == pMsg )
8841 status = eHAL_STATUS_FAILURE;
8842 else
Jeff Johnson295189b2012-06-20 16:38:30 -07008843 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308844 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008845 pMsg->type = eWNI_SME_GET_SCANNED_CHANNEL_REQ;
8846 pMsg->msgLen = msgLen;
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05308847 if (pMac->fScanOffload)
8848 ((tSirSmeGetScanChanReq *)pMsg)->sessionId = sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07008849 status = palSendMBMessage(pMac->hHdd, pMsg);
8850 }
8851
8852 return( status );
8853}
8854
8855tANI_BOOLEAN csrRoamIsValidChannel( tpAniSirGlobal pMac, tANI_U8 channel )
8856{
8857 tANI_BOOLEAN fValid = FALSE;
8858 tANI_U32 idxValidChannels;
8859 tANI_U32 len = pMac->roam.numValidChannels;
8860
8861 for ( idxValidChannels = 0; ( idxValidChannels < len ); idxValidChannels++ )
8862 {
8863 if ( channel == pMac->roam.validChannelList[ idxValidChannels ] )
8864 {
8865 fValid = TRUE;
8866 break;
8867 }
8868 }
8869
8870 return fValid;
8871}
8872
Manjunathappa Prakash4f1d5a52013-11-11 16:22:19 -08008873#ifdef FEATURE_WLAN_SCAN_PNO
Srikant Kuppa066904f2013-05-07 13:56:02 -07008874eHalStatus csrScanSavePreferredNetworkFound(tpAniSirGlobal pMac,
8875 tSirPrefNetworkFoundInd *pPrefNetworkFoundInd)
8876{
8877 v_U32_t uLen = 0;
8878 tpSirProbeRespBeacon pParsedFrame;
8879 tCsrScanResult *pScanResult = NULL;
8880 tSirBssDescription *pBssDescr = NULL;
8881 tANI_BOOLEAN fDupBss;
8882 tDot11fBeaconIEs *pIesLocal = NULL;
8883 tAniSSID tmpSsid;
8884 v_TIME_t timer=0;
8885 tpSirMacMgmtHdr macHeader = (tpSirMacMgmtHdr)pPrefNetworkFoundInd->data;
Abhishek Singhd3d4e022014-11-11 13:02:40 +05308886 boolean bFoundonAppliedChannel = FALSE;
8887 v_U32_t indx;
8888 u8 channelsAllowed[WNI_CFG_VALID_CHANNEL_LIST_LEN];
8889 v_U32_t numChannelsAllowed = WNI_CFG_VALID_CHANNEL_LIST_LEN;
Sushant Kaushik6274de62015-05-01 16:31:23 +05308890 tListElem *pEntry;
Abhishek Singhd3d4e022014-11-11 13:02:40 +05308891
Srikant Kuppa066904f2013-05-07 13:56:02 -07008892
8893 pParsedFrame =
Abhishek Singhc75726d2015-04-13 14:44:14 +05308894 (tpSirProbeRespBeacon)vos_mem_vmalloc(sizeof(tSirProbeRespBeacon));
Srikant Kuppa066904f2013-05-07 13:56:02 -07008895
8896 if (NULL == pParsedFrame)
8897 {
8898 smsLog(pMac, LOGE, FL(" fail to allocate memory for frame"));
8899 return eHAL_STATUS_RESOURCES;
8900 }
8901
8902 if ( pPrefNetworkFoundInd->frameLength <= SIR_MAC_HDR_LEN_3A )
8903 {
8904 smsLog(pMac, LOGE,
8905 FL("Not enough bytes in PNO indication probe resp frame! length=%d"),
8906 pPrefNetworkFoundInd->frameLength);
Abhishek Singhc75726d2015-04-13 14:44:14 +05308907 vos_mem_vfree(pParsedFrame);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008908 return eHAL_STATUS_FAILURE;
8909 }
8910
8911 if (sirConvertProbeFrame2Struct(pMac,
8912 &pPrefNetworkFoundInd->data[SIR_MAC_HDR_LEN_3A],
8913 pPrefNetworkFoundInd->frameLength - SIR_MAC_HDR_LEN_3A,
8914 pParsedFrame) != eSIR_SUCCESS ||
8915 !pParsedFrame->ssidPresent)
8916 {
8917 smsLog(pMac, LOGE,
8918 FL("Parse error ProbeResponse, length=%d"),
8919 pPrefNetworkFoundInd->frameLength);
Abhishek Singhc75726d2015-04-13 14:44:14 +05308920 vos_mem_vfree(pParsedFrame);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008921 return eHAL_STATUS_FAILURE;
8922 }
8923 //24 byte MAC header and 12 byte to ssid IE
8924 if (pPrefNetworkFoundInd->frameLength >
8925 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET))
8926 {
8927 uLen = pPrefNetworkFoundInd->frameLength -
8928 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET);
8929 }
8930
Kiet Lam64c1b492013-07-12 13:56:44 +05308931 pScanResult = vos_mem_malloc(sizeof(tCsrScanResult) + uLen);
8932 if ( NULL == pScanResult )
Srikant Kuppa066904f2013-05-07 13:56:02 -07008933 {
8934 smsLog(pMac, LOGE, FL(" fail to allocate memory for frame"));
8935 vos_mem_free(pParsedFrame);
8936 return eHAL_STATUS_RESOURCES;
8937 }
8938
Kiet Lam64c1b492013-07-12 13:56:44 +05308939 vos_mem_set(pScanResult, sizeof(tCsrScanResult) + uLen, 0);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008940 pBssDescr = &pScanResult->Result.BssDescriptor;
8941 /**
8942 * Length of BSS desription is without length of
8943 * length itself and length of pointer
8944 * that holds the next BSS description
8945 */
8946 pBssDescr->length = (tANI_U16)(
8947 sizeof(tSirBssDescription) - sizeof(tANI_U16) -
8948 sizeof(tANI_U32) + uLen);
8949 if (pParsedFrame->dsParamsPresent)
8950 {
8951 pBssDescr->channelId = pParsedFrame->channelNumber;
8952 }
8953 else if (pParsedFrame->HTInfo.present)
8954 {
8955 pBssDescr->channelId = pParsedFrame->HTInfo.primaryChannel;
8956 }
8957 else
8958 {
Mahesh A Saptasagaradd99792014-03-26 16:04:20 +05308959 /**
8960 * If Probe Responce received in PNO indication does not
8961 * contain DSParam IE or HT Info IE then add dummy channel
8962 * to the received BSS info so that Scan result received as
8963 * a part of PNO is updated to the supplicant. Specially
8964 * applicable in case of AP configured in 11A only mode.
8965 */
8966 if ((pMac->roam.configParam.bandCapability == eCSR_BAND_ALL) ||
8967 (pMac->roam.configParam.bandCapability == eCSR_BAND_24))
8968 {
8969 pBssDescr->channelId = 1;
8970 }
8971 else if(pMac->roam.configParam.bandCapability == eCSR_BAND_5G)
8972 {
8973 pBssDescr->channelId = 36;
8974 }
Abhishek Singhd3d4e022014-11-11 13:02:40 +05308975 /* Restrict the logic to ignore the pno indication for invalid channel
8976 * only if valid channel info is present in beacon/probe resp.
8977 * If no channel info is present in beacon/probe resp, always process
8978 * the pno indication.
8979 */
8980 bFoundonAppliedChannel = TRUE;
8981 }
8982
8983 if (0 != sme_GetCfgValidChannels(pMac, channelsAllowed, &numChannelsAllowed))
8984 {
8985 smsLog(pMac, LOGE, FL(" sme_GetCfgValidChannels failed "));
8986 csrFreeScanResultEntry(pMac, pScanResult);
Abhishek Singhc75726d2015-04-13 14:44:14 +05308987 vos_mem_vfree(pParsedFrame);
Abhishek Singhd3d4e022014-11-11 13:02:40 +05308988 return eHAL_STATUS_FAILURE;
8989 }
8990 /* Checking chhanelId with allowed channel list */
8991 for (indx = 0; indx < numChannelsAllowed; indx++)
8992 {
8993 if (pBssDescr->channelId == channelsAllowed[indx])
8994 {
8995 bFoundonAppliedChannel = TRUE;
8996 smsLog(pMac, LOG1, FL(" pno ind found on applied channel =%d\n "),
8997 pBssDescr->channelId);
8998 break;
8999 }
9000 }
9001 /* Ignore PNO indication if AP is on Invalid channel.
9002 */
9003 if(FALSE == bFoundonAppliedChannel)
9004 {
9005 smsLog(pMac, LOGW, FL(" prefered network found on invalid channel = %d"),
9006 pBssDescr->channelId);
9007 csrFreeScanResultEntry(pMac, pScanResult);
Abhishek Singhc75726d2015-04-13 14:44:14 +05309008 vos_mem_vfree(pParsedFrame);
Abhishek Singhd3d4e022014-11-11 13:02:40 +05309009 return eHAL_STATUS_FAILURE;
Srikant Kuppa066904f2013-05-07 13:56:02 -07009010 }
9011
9012 if ((pBssDescr->channelId > 0) && (pBssDescr->channelId < 15))
9013 {
9014 int i;
9015 // 11b or 11g packet
9016 // 11g iff extended Rate IE is present or
9017 // if there is an A rate in suppRate IE
9018 for (i = 0; i < pParsedFrame->supportedRates.numRates; i++)
9019 {
9020 if (sirIsArate(pParsedFrame->supportedRates.rate[i] & 0x7f))
9021 {
9022 pBssDescr->nwType = eSIR_11G_NW_TYPE;
9023 break;
9024 }
9025 }
9026 if (pParsedFrame->extendedRatesPresent)
9027 {
9028 pBssDescr->nwType = eSIR_11G_NW_TYPE;
9029 }
9030 }
9031 else
9032 {
9033 // 11a packet
9034 pBssDescr->nwType = eSIR_11A_NW_TYPE;
9035 }
9036
9037 pBssDescr->sinr = 0;
9038 pBssDescr->rssi = -1 * pPrefNetworkFoundInd->rssi;
9039 pBssDescr->beaconInterval = pParsedFrame->beaconInterval;
AnjaneeDevi Kapparapu4b043912014-02-18 13:22:35 +05309040 if (!pBssDescr->beaconInterval)
9041 {
9042 smsLog(pMac, LOGW,
9043 FL("Bcn Interval is Zero , default to 100" MAC_ADDRESS_STR),
9044 MAC_ADDR_ARRAY(pBssDescr->bssId) );
9045 pBssDescr->beaconInterval = 100;
9046 }
Srikant Kuppa066904f2013-05-07 13:56:02 -07009047 pBssDescr->timeStamp[0] = pParsedFrame->timeStamp[0];
9048 pBssDescr->timeStamp[1] = pParsedFrame->timeStamp[1];
9049 pBssDescr->capabilityInfo = *((tANI_U16 *)&pParsedFrame->capabilityInfo);
Kiet Lam64c1b492013-07-12 13:56:44 +05309050 vos_mem_copy((tANI_U8 *) &pBssDescr->bssId, (tANI_U8 *) macHeader->bssId, sizeof(tSirMacAddr));
Deepthi Gowri4480a3f2016-05-18 19:30:17 +05309051 pBssDescr->nReceivedTime = vos_timer_get_system_time();
Srikant Kuppa066904f2013-05-07 13:56:02 -07009052
Abhishek Singh195c03e2014-05-14 17:21:30 +05309053 smsLog( pMac, LOG1, FL("Bssid= "MAC_ADDRESS_STR
9054 " chan= %d, rssi = %d "),
Arif Hussain24bafea2013-11-15 15:10:03 -08009055 MAC_ADDR_ARRAY(pBssDescr->bssId),
Srikant Kuppa066904f2013-05-07 13:56:02 -07009056 pBssDescr->channelId,
Abhishek Singh195c03e2014-05-14 17:21:30 +05309057 pBssDescr->rssi);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009058
9059 //IEs
9060 if (uLen)
9061 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309062 vos_mem_copy(&pBssDescr->ieFields,
9063 pPrefNetworkFoundInd->data + (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET),
9064 uLen);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009065 }
9066
9067 pIesLocal = (tDot11fBeaconIEs *)( pScanResult->Result.pvIes );
9068 if ( !pIesLocal &&
9069 (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
9070 &pScanResult->Result.BssDescriptor, &pIesLocal))) )
9071 {
9072 smsLog(pMac, LOGE, FL(" Cannot parse IEs"));
9073 csrFreeScanResultEntry(pMac, pScanResult);
Abhishek Singhc75726d2015-04-13 14:44:14 +05309074 vos_mem_vfree(pParsedFrame);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009075 return eHAL_STATUS_RESOURCES;
9076 }
9077
9078 fDupBss = csrRemoveDupBssDescription( pMac,
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05309079 &pScanResult->Result.BssDescriptor, pIesLocal, &tmpSsid, &timer, FALSE);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009080 //Check whether we have reach out limit
9081 if ( CSR_SCAN_IS_OVER_BSS_LIMIT(pMac) )
9082 {
9083 //Limit reach
9084 smsLog(pMac, LOGE, FL(" BSS limit reached"));
9085 //Free the resources
9086 if( (pScanResult->Result.pvIes == NULL) && pIesLocal )
9087 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309088 vos_mem_free(pIesLocal);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009089 }
9090 csrFreeScanResultEntry(pMac, pScanResult);
9091 vos_mem_free(pParsedFrame);
9092 return eHAL_STATUS_RESOURCES;
9093 }
Nalla Kartheek71946422015-09-15 14:41:22 +05309094
9095 if ((macHeader->fc.type == SIR_MAC_MGMT_FRAME) &&
9096 (macHeader->fc.subType == SIR_MAC_MGMT_PROBE_RSP))
9097 {
9098 pScanResult->Result.BssDescriptor.fProbeRsp = 1;
9099 }
Srikant Kuppa066904f2013-05-07 13:56:02 -07009100 //Add to scan cache
9101 csrScanAddResult(pMac, pScanResult, pIesLocal);
Sushant Kaushik6274de62015-05-01 16:31:23 +05309102 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
Kiet Lamb537cfb2013-11-07 12:56:49 +05309103 if( (pScanResult->Result.pvIes == NULL) && pIesLocal )
9104 {
9105 vos_mem_free(pIesLocal);
9106 }
9107
Abhishek Singhc75726d2015-04-13 14:44:14 +05309108 vos_mem_vfree(pParsedFrame);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009109
9110 return eHAL_STATUS_SUCCESS;
9111}
Manjunathappa Prakash4f1d5a52013-11-11 16:22:19 -08009112#endif //FEATURE_WLAN_SCAN_PNO
Srikant Kuppa066904f2013-05-07 13:56:02 -07009113
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08009114#ifdef FEATURE_WLAN_LFR
9115void csrInitOccupiedChannelsList(tpAniSirGlobal pMac)
9116{
9117 tListElem *pEntry = NULL;
9118 tCsrScanResult *pBssDesc = NULL;
9119 tDot11fBeaconIEs *pIes = NULL;
Srinivas28b5b4e2012-12-12 13:07:53 -08009120 tpCsrNeighborRoamControlInfo pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
9121
9122 if (0 != pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels)
9123 {
9124 smsLog(pMac, LOG1, FL("%s: Ini file contains neighbor scan channel list,"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08009125 " hence NO need to build occupied channel list (numChannels = %d)"),
Srinivas28b5b4e2012-12-12 13:07:53 -08009126 __func__, pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels);
9127 return;
9128 }
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08009129
9130 if (!csrNeighborRoamIsNewConnectedProfile(pMac))
9131 {
9132 smsLog(pMac, LOG2, FL("%s: donot flush occupied list since current roam profile"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08009133 " matches previous (numChannels = %d)"),
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08009134 __func__, pMac->scan.occupiedChannels.numChannels);
9135 return;
9136 }
9137
9138 /* Empty occupied channels here */
9139 pMac->scan.occupiedChannels.numChannels = 0;
9140
9141 csrLLLock(&pMac->scan.scanResultList);
9142 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
9143 while( pEntry )
9144 {
9145 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
9146 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
9147
9148 //At this time, pBssDescription->Result.pvIes may be NULL
Srikant Kuppa866893f2012-12-27 17:28:14 -08009149 if( !pIes && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08009150 &pBssDesc->Result.BssDescriptor, &pIes))) )
9151 {
9152 continue;
9153 }
9154
9155 csrScanAddToOccupiedChannels(pMac, pBssDesc, &pMac->scan.occupiedChannels, pIes);
9156
9157 /*
9158 * Free the memory allocated for pIes in csrGetParsedBssDescriptionIEs
9159 */
9160 if( (pBssDesc->Result.pvIes == NULL) && pIes )
9161 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309162 vos_mem_free(pIes);
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08009163 }
9164
9165 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK );
9166 }//while
9167 csrLLUnlock(&pMac->scan.scanResultList);
Srikant Kuppa866893f2012-12-27 17:28:14 -08009168
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08009169}
9170#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009171
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009172eHalStatus csrScanCreateEntryInScanCache(tpAniSirGlobal pMac, tANI_U32 sessionId,
9173 tCsrBssid bssid, tANI_U8 channel)
9174{
9175 eHalStatus status = eHAL_STATUS_SUCCESS;
9176 tDot11fBeaconIEs *pNewIes = NULL;
9177 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
Praveen Kumar Sirisilla8bdfac42013-10-10 17:20:48 -07009178 tSirBssDescription *pNewBssDescriptor = NULL;
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009179 tANI_U32 size = 0;
9180
9181 if(NULL == pSession)
9182 {
9183 status = eHAL_STATUS_FAILURE;
9184 return status;
9185 }
9186 smsLog(pMac, LOG2, FL("csrScanCreateEntryInScanCache: Current bssid::"
Arif Hussain24bafea2013-11-15 15:10:03 -08009187 MAC_ADDRESS_STR),
9188 MAC_ADDR_ARRAY(pSession->pConnectBssDesc->bssId));
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009189 smsLog(pMac, LOG2, FL("csrScanCreateEntryInScanCache: My bssid::"
Arif Hussain24bafea2013-11-15 15:10:03 -08009190 MAC_ADDRESS_STR" channel %d"),
9191 MAC_ADDR_ARRAY(bssid), channel);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009192
9193 do
9194 {
9195 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
9196 pSession->pConnectBssDesc, &pNewIes)))
9197 {
9198 smsLog(pMac, LOGE, FL("%s: Failed to parse IEs"),
9199 __func__);
9200 status = eHAL_STATUS_FAILURE;
9201 break;
9202 }
9203
9204 size = pSession->pConnectBssDesc->length + sizeof(pSession->pConnectBssDesc->length);
Kiet Lam64c1b492013-07-12 13:56:44 +05309205 if (size)
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009206 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309207 pNewBssDescriptor = vos_mem_malloc(size);
9208 if ( NULL == pNewBssDescriptor )
9209 status = eHAL_STATUS_FAILURE;
9210 else
9211 status = eHAL_STATUS_SUCCESS;
9212 if (HAL_STATUS_SUCCESS(status))
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009213 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309214 vos_mem_copy(pNewBssDescriptor, pSession->pConnectBssDesc, size);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009215 }
9216 else
9217 {
9218 smsLog(pMac, LOGE, FL("%s: memory allocation failed"),
9219 __func__);
9220 status = eHAL_STATUS_FAILURE;
9221 break;
9222 }
9223
9224 //change the BSSID & channel as passed
Kiet Lam64c1b492013-07-12 13:56:44 +05309225 vos_mem_copy(pNewBssDescriptor->bssId, bssid, sizeof(tSirMacAddr));
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009226 pNewBssDescriptor->channelId = channel;
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07009227 if(NULL == csrScanAppendBssDescription( pMac, pNewBssDescriptor, pNewIes, TRUE ))
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009228 {
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07009229 smsLog(pMac, LOGE, FL("%s: csrScanAppendBssDescription failed"),
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009230 __func__);
9231 status = eHAL_STATUS_FAILURE;
9232 break;
9233 }
9234 }
9235 else
9236 {
9237 smsLog(pMac, LOGE, FL("%s: length of bss descriptor is 0"),
9238 __func__);
9239 status = eHAL_STATUS_FAILURE;
9240 break;
9241 }
9242 smsLog(pMac, LOGE, FL("%s: entry successfully added in scan cache"),
9243 __func__);
9244 }while(0);
9245
9246 if(pNewIes)
9247 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309248 vos_mem_free(pNewIes);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009249 }
9250 if(pNewBssDescriptor)
9251 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309252 vos_mem_free(pNewBssDescriptor);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009253 }
9254 return status;
9255}
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07009256
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08009257#ifdef FEATURE_WLAN_ESE
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07009258// Update the TSF with the difference in system time
9259void UpdateCCKMTSF(tANI_U32 *timeStamp0, tANI_U32 *timeStamp1, tANI_U32 *incr)
9260{
9261 tANI_U64 timeStamp64 = ((tANI_U64)*timeStamp1 << 32) | (*timeStamp0);
9262
9263 timeStamp64 = (tANI_U64)(timeStamp64 + (tANI_U64)*incr);
9264 *timeStamp0 = (tANI_U32)(timeStamp64 & 0xffffffff);
9265 *timeStamp1 = (tANI_U32)((timeStamp64 >> 32) & 0xffffffff);
9266}
9267#endif