blob: 1ccbf5ef5ac15399f568a62b58c3b5d24d830cf6 [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 }
Abhishek Singhadd13582016-09-29 17:00:03 +0530313 pScanRequest->max_chntime_btc_esco =
314 pMac->roam.configParam.max_chntime_btc_esco;
315 pScanRequest->min_chntime_btc_esco =
316 pMac->roam.configParam.min_chntime_btc_esco;
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700317
318 pScanRequest->restTime = pMac->roam.configParam.nRestTimeConc;
319
320 //Return so that fields set above will not be overwritten.
321 return;
322 }
323#endif
324
325 //This portion of the code executed if multi-session not supported
326 //(WLAN_AP_STA_CONCURRENCY not defined) or no multi-session.
327 //Use the "regular" (non-concurrency) default scan timing.
Abhishek Singh7fb7dc12014-11-06 17:44:05 +0530328 ccmCfgSetInt(pMac, WNI_CFG_PASSIVE_MAXIMUM_CHANNEL_TIME,
Kaushik, Sushant49758c12014-09-26 11:25:38 +0530329 pMac->roam.configParam.nPassiveMaxChnTime,
330 NULL,eANI_BOOLEAN_FALSE);
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700331 if(pScanRequest->scanType == eSIR_ACTIVE_SCAN)
332 {
333 pScanRequest->maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
334 pScanRequest->minChnTime = pMac->roam.configParam.nActiveMinChnTime;
335 }
336 else
337 {
338 pScanRequest->maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
339 pScanRequest->minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
340 }
Abhishek Singhadd13582016-09-29 17:00:03 +0530341 pScanRequest->max_chntime_btc_esco =
342 pMac->roam.configParam.max_chntime_btc_esco;
343 pScanRequest->min_chntime_btc_esco =
344 pMac->roam.configParam.min_chntime_btc_esco;
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700345
346#ifdef WLAN_AP_STA_CONCURRENCY
347 //No rest time if no sessions are connected.
348 pScanRequest->restTime = 0;
349#endif
350}
351
Jeff Johnson295189b2012-06-20 16:38:30 -0700352#ifdef WLAN_AP_STA_CONCURRENCY
353//Return SUCCESS is the command is queued, else returns eHAL_STATUS_FAILURE
354eHalStatus csrQueueScanRequest( tpAniSirGlobal pMac, tSmeCmd *pScanCmd )
355{
356 eHalStatus status = eHAL_STATUS_SUCCESS;
357
358 tANI_BOOLEAN fNoCmdPending;
359 tSmeCmd *pQueueScanCmd=NULL;
360 tSmeCmd *pSendScanCmd=NULL;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700361 tANI_U8 nNumChanCombinedConc = 0;
Gopichand Nakkala114718f2013-03-25 19:19:46 -0700362 if (NULL == pScanCmd)
363 {
364 smsLog (pMac, LOGE, FL("Scan Req cmd is NULL"));
365 return eHAL_STATUS_FAILURE;
366 }
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -0800367 /* split scan if any one of the following:
368 * - STA session is connected and the scan is not a P2P search
369 * - any P2P session is connected
Srikant Kuppa866893f2012-12-27 17:28:14 -0800370 * Do not split scans if no concurrent infra connections are
371 * active and if the scan is a BG scan triggered by LFR (OR)
372 * any scan if LFR is in the middle of a BG scan. Splitting
373 * the scan is delaying the time it takes for LFR to find
374 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -0800375 */
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700376
377 if(csrIsStaSessionConnected(pMac) &&
378 !csrIsP2pSessionConnected(pMac))
379 {
380 nNumChanCombinedConc = pMac->roam.configParam.nNumStaChanCombinedConc;
381 }
382 else if(csrIsP2pSessionConnected(pMac))
383 {
384 nNumChanCombinedConc = pMac->roam.configParam.nNumP2PChanCombinedConc;
385 }
Srikant Kuppa866893f2012-12-27 17:28:14 -0800386 if ( (csrIsStaSessionConnected(pMac) &&
387#ifdef FEATURE_WLAN_LFR
388 (csrIsConcurrentInfraConnected(pMac) ||
389 ((pScanCmd->u.scanCmd.reason != eCsrScanBgScan) &&
390 (pMac->roam.neighborRoamInfo.neighborRoamState !=
391 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
392#endif
393 (pScanCmd->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Vinay Malekal05fdc812012-12-17 13:04:30 -0800394 (csrIsP2pSessionConnected(pMac)) )
Jeff Johnson295189b2012-06-20 16:38:30 -0700395 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700396 tCsrScanRequest scanReq;
397 tANI_U8 numChn = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
398 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
399 tANI_U8 channelToScan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
Jeff Johnson295189b2012-06-20 16:38:30 -0700400 tANI_BOOLEAN bMemAlloc = eANI_BOOLEAN_FALSE;
401
402 if (numChn == 0)
403 {
404
405 numChn = pMac->scan.baseChannels.numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -0700406
Kiet Lam64c1b492013-07-12 13:56:44 +0530407 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(numChn);
408 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -0700409 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800410 smsLog( pMac, LOGE, FL(" Failed to get memory for channel list ") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800411 return eHAL_STATUS_FAILURE;
412 }
413 bMemAlloc = eANI_BOOLEAN_TRUE;
Kiet Lam64c1b492013-07-12 13:56:44 +0530414 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
415 pMac->scan.baseChannels.channelList, numChn);
416 status = eHAL_STATUS_SUCCESS;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800417 if( !HAL_STATUS_SUCCESS( status ) )
418 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530419 vos_mem_free(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800420 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800421 smsLog( pMac, LOGE, FL(" Failed to copy memory to channel list ") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800422 return eHAL_STATUS_FAILURE;
423 }
424 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = numChn;
425 }
Sushant Kaushik826de802014-05-08 18:04:11 +0530426 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
427 "%s: Total Number of channels to scan : %d "
428 "Splitted in group of %d ", __func__, numChn,
429 nNumChanCombinedConc);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800430 //Whenever we get a scan request with multiple channels we break it up into 2 requests
431 //First request for first channel to scan and second request to scan remaining channels
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700432 if ( numChn > nNumChanCombinedConc)
Vinay Malekal05fdc812012-12-17 13:04:30 -0800433 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530434 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800435
436 pQueueScanCmd = csrGetCommandBuffer(pMac); //optimize this to use 2 command buffer only
437 if (!pQueueScanCmd)
438 {
439 if (bMemAlloc)
Jeff Johnson295189b2012-06-20 16:38:30 -0700440 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530441 vos_mem_free(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800442 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
443
Jeff Johnson295189b2012-06-20 16:38:30 -0700444 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800445 smsLog( pMac, LOGE, FL(" Failed to get Queue command buffer") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800446 return eHAL_STATUS_FAILURE;
447 }
448 pQueueScanCmd->command = pScanCmd->command;
449 pQueueScanCmd->sessionId = pScanCmd->sessionId;
450 pQueueScanCmd->u.scanCmd.callback = pScanCmd->u.scanCmd.callback;
451 pQueueScanCmd->u.scanCmd.pContext = pScanCmd->u.scanCmd.pContext;
452 pQueueScanCmd->u.scanCmd.reason = pScanCmd->u.scanCmd.reason;
453 pQueueScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Jeff Johnson295189b2012-06-20 16:38:30 -0700454
Vinay Malekal05fdc812012-12-17 13:04:30 -0800455 /* First copy all the parameters to local variable of scan request */
456 csrScanCopyRequest(pMac, &scanReq, &pScanCmd->u.scanCmd.u.scanRequest);
Madan Mohan Koyyalamudiaf2a8b92012-10-09 14:58:07 -0700457
Vinay Malekal05fdc812012-12-17 13:04:30 -0800458 /* Now modify the elements of local var scan request required to be modified for split scan */
459 if(scanReq.ChannelInfo.ChannelList != NULL)
460 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530461 vos_mem_free(scanReq.ChannelInfo.ChannelList);
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -0800462 scanReq.ChannelInfo.ChannelList = NULL;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800463 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700464
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700465 pChnInfo->numOfChannels = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels - nNumChanCombinedConc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700466
Vinay Malekal05fdc812012-12-17 13:04:30 -0800467 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_WARN,
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +0530468 FL(" &channelToScan %p pScanCmd(%p) pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList(%p)numChn(%d)"),
469 &channelToScan[0], pScanCmd,
470 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList, numChn);
Jeff Johnson295189b2012-06-20 16:38:30 -0700471
Kiet Lam64c1b492013-07-12 13:56:44 +0530472 vos_mem_copy(&channelToScan[0],
473 &pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[
474 nNumChanCombinedConc],
475 pChnInfo->numOfChannels * sizeof(tANI_U8));
Vinay Malekal05fdc812012-12-17 13:04:30 -0800476
477 pChnInfo->ChannelList = &channelToScan[0];
478
479 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
c_hpothudbefd3e2014-04-28 15:59:47 +0530480
Vinay Malekal05fdc812012-12-17 13:04:30 -0800481 //Use concurrency values for min/maxChnTime.
482 //We know csrIsAnySessionConnected(pMac) returns TRUE here
483 csrSetDefaultScanTiming(pMac, scanReq.scanType, &scanReq);
484
485 status = csrScanCopyRequest(pMac, &pQueueScanCmd->u.scanCmd.u.scanRequest, &scanReq);
486
487 if(!HAL_STATUS_SUCCESS(status))
488 {
489 if (bMemAlloc)
490 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530491 vos_mem_free(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800492 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
493
494 }
495 if( scanReq.pIEField != NULL)
496 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530497 vos_mem_free(scanReq.pIEField);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800498 scanReq.pIEField = NULL;
499 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800500 smsLog( pMac, LOGE, FL(" Failed to get copy csrScanRequest = %d"), status );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800501 return eHAL_STATUS_FAILURE;
502 }
503 /* Clean the local scan variable */
504 scanReq.ChannelInfo.ChannelList = NULL;
505 scanReq.ChannelInfo.numOfChannels = 0;
506 csrScanFreeRequest(pMac, &scanReq);
507
508 /* setup the command to scan 2 channels */
509 pSendScanCmd = pScanCmd;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700510 pSendScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nNumChanCombinedConc;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800511 pSendScanCmd->u.scanCmd.u.scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
c_hpothudbefd3e2014-04-28 15:59:47 +0530512
Vinay Malekal05fdc812012-12-17 13:04:30 -0800513 //Use concurrency values for min/maxChnTime.
514 //We know csrIsAnySessionConnected(pMac) returns TRUE here
515 csrSetDefaultScanTiming(pMac, pSendScanCmd->u.scanCmd.u.scanRequest.scanType, &pSendScanCmd->u.scanCmd.u.scanRequest);
516 pSendScanCmd->u.scanCmd.callback = NULL;
517 } else {
518 pSendScanCmd = pScanCmd;
519 pSendScanCmd->u.scanCmd.u.scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
c_hpothudbefd3e2014-04-28 15:59:47 +0530520
Vinay Malekal05fdc812012-12-17 13:04:30 -0800521 //Use concurrency values for min/maxChnTime.
522 //We know csrIsAnySessionConnected(pMac) returns TRUE here
523 csrSetDefaultScanTiming(pMac, pSendScanCmd->u.scanCmd.u.scanRequest.scanType, &pSendScanCmd->u.scanCmd.u.scanRequest);
524 }
525
526 fNoCmdPending = csrLLIsListEmpty( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK );
527
528 //Logic Below is as follows
529 // If the scanCmdPendingList is empty then we directly send that command
530 // to smeCommandQueue else we buffer it in our scanCmdPendingList Queue
531 if( fNoCmdPending )
532 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700533 if (pQueueScanCmd != NULL)
534 {
Vinay Malekal05fdc812012-12-17 13:04:30 -0800535 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pQueueScanCmd->Link, LL_ACCESS_LOCK );
Jeff Johnson295189b2012-06-20 16:38:30 -0700536 }
537
538 if (pSendScanCmd != NULL)
539 {
540 return csrQueueSmeCommand(pMac, pSendScanCmd, eANI_BOOLEAN_FALSE);
541 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800542 }
543 else
544 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700545 if (pSendScanCmd != NULL)
546 {
547 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pSendScanCmd->Link, LL_ACCESS_LOCK );
548 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800549
Jeff Johnson295189b2012-06-20 16:38:30 -0700550 if (pQueueScanCmd != NULL)
551 {
552 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pQueueScanCmd->Link, LL_ACCESS_LOCK );
553 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800554 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700555 }
556 else
557 { //No concurrency case
Srikant Kuppa866893f2012-12-27 17:28:14 -0800558 smsLog( pMac, LOG2, FL("Queuing scan command (reason=%d, roamState=%d"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800559 " numOfChannels=%d)"),
Srikant Kuppa866893f2012-12-27 17:28:14 -0800560 pScanCmd->u.scanCmd.reason,
561 pMac->roam.neighborRoamInfo.neighborRoamState,
562 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -0700563 return csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
564 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700565
566 return ( status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700567}
568#endif
569
Jeff Johnsone7245742012-09-05 17:12:55 -0700570/* ---------------------------------------------------------------------------
571 \fn csrScan2GOnyRequest
572 \brief This function will update the scan request with only
Jeff Johnsonb88db982012-12-10 13:34:59 -0800573 2.4GHz valid channel list.
Jeff Johnsone7245742012-09-05 17:12:55 -0700574 \param pMac
575 \param pScanCmd
576 \param pScanRequest
577 \return None
578 -------------------------------------------------------------------------------*/
579static void csrScan2GOnyRequest(tpAniSirGlobal pMac,tSmeCmd *pScanCmd,
580 tCsrScanRequest *pScanRequest)
581{
582 tANI_U8 index, channelId, channelListSize = 0;
583 tANI_U8 channelList2G[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
584 static tANI_U8 validchannelList[CSR_MAX_2_4_GHZ_SUPPORTED_CHANNELS] = {0};
585
586 VOS_ASSERT(pScanCmd && pScanRequest);
Madan Mohan Koyyalamudi33ef6a22012-10-30 17:44:43 -0700587 /* To silence the KW tool null check is added */
588 if((pScanCmd == NULL) || (pScanRequest == NULL))
589 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800590 smsLog( pMac, LOGE, FL(" pScanCmd or pScanRequest is NULL "));
Madan Mohan Koyyalamudi33ef6a22012-10-30 17:44:43 -0700591 return;
592 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700593
594 if (pScanCmd->u.scanCmd.scanID ||
595 (eCSR_SCAN_REQUEST_FULL_SCAN != pScanRequest->requestType))
596 return;
597
598 //Contsruct valid Supported 2.4 GHz Channel List
599 for( index = 0; index < ARRAY_SIZE(channelList2G); index++ )
600 {
601 channelId = channelList2G[index];
602 if ( csrIsSupportedChannel( pMac, channelId ) )
603 {
604 validchannelList[channelListSize++] = channelId;
605 }
606 }
607
608 pScanRequest->ChannelInfo.numOfChannels = channelListSize;
609 pScanRequest->ChannelInfo.ChannelList = validchannelList;
610}
611
Jeff Johnson295189b2012-06-20 16:38:30 -0700612eHalStatus csrScanRequest(tpAniSirGlobal pMac, tANI_U16 sessionId,
613 tCsrScanRequest *pScanRequest, tANI_U32 *pScanRequestID,
614 csrScanCompleteCallback callback, void *pContext)
615{
616 eHalStatus status = eHAL_STATUS_FAILURE;
617 tSmeCmd *pScanCmd = NULL;
Madan Mohan Koyyalamudicb90bb22012-10-30 18:24:43 -0700618 eCsrConnectState ConnectState;
Deepthi Gowrie11da8c2016-02-04 18:18:39 +0530619
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800620 if(pScanRequest == NULL)
621 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800622 smsLog( pMac, LOGE, FL(" pScanRequest is NULL"));
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800623 VOS_ASSERT(0);
Kaushik, Sushant488df382014-03-05 11:43:47 +0530624 return eHAL_STATUS_FAILURE ;
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800625 }
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700626
Kiet Lamd1f3dc82013-11-05 20:45:04 +0530627 /* During group formation, the P2P client scans for GO with the specific SSID.
628 * There will be chances of GO switching to other channels because of scan or
629 * to STA channel in case of STA+GO MCC scenario. So to increase the possibility
630 * of client to find the GO, the dwell time of scan is increased to 100ms.
631 */
632 if(pScanRequest->p2pSearch)
633 {
Rashmi Ramanna6f7931c2013-12-20 09:04:12 +0530634 if(pScanRequest->SSIDs.numOfSSIDs)
Kiet Lamd1f3dc82013-11-05 20:45:04 +0530635 {
Rashmi Ramanna6f7931c2013-12-20 09:04:12 +0530636 //If the scan request is for specific SSId the length of SSID will be
637 //greater than 7 as SSID for p2p search contains "DIRECT-")
638 if(pScanRequest->SSIDs.SSIDList->SSID.length > DIRECT_SSID_LEN)
639 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530640 smsLog( pMac, LOG1, FL("P2P: Increasing the min and max Dwell"
641 " time to %d for specific SSID scan %.*s"),
642 MAX_CHN_TIME_TO_FIND_GO,
643 pScanRequest->SSIDs.SSIDList->SSID.length,
644 pScanRequest->SSIDs.SSIDList->SSID.ssId);
Rashmi Ramanna6f7931c2013-12-20 09:04:12 +0530645 pScanRequest->maxChnTime = MAX_CHN_TIME_TO_FIND_GO;
646 pScanRequest->minChnTime = MIN_CHN_TIME_TO_FIND_GO;
647 }
Kiet Lamd1f3dc82013-11-05 20:45:04 +0530648 }
649 }
650
Jeff Johnson295189b2012-06-20 16:38:30 -0700651 do
652 {
653 if(pMac->scan.fScanEnable)
654 {
655 pScanCmd = csrGetCommandBuffer(pMac);
656 if(pScanCmd)
657 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530658 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -0700659 pScanCmd->command = eSmeCommandScan;
660 pScanCmd->sessionId = sessionId;
661 pScanCmd->u.scanCmd.callback = callback;
662 pScanCmd->u.scanCmd.pContext = pContext;
663 if(eCSR_SCAN_REQUEST_11D_SCAN == pScanRequest->requestType)
664 {
665 pScanCmd->u.scanCmd.reason = eCsrScan11d1;
666 }
667 else if((eCSR_SCAN_REQUEST_FULL_SCAN == pScanRequest->requestType) ||
668 (eCSR_SCAN_P2P_DISCOVERY == pScanRequest->requestType)
669#ifdef SOFTAP_CHANNEL_RANGE
670 ||(eCSR_SCAN_SOFTAP_CHANNEL_RANGE == pScanRequest->requestType)
671#endif
672 )
673 {
674 pScanCmd->u.scanCmd.reason = eCsrScanUserRequest;
675 }
676 else if(eCSR_SCAN_HO_BG_SCAN == pScanRequest->requestType)
677 {
678 pScanCmd->u.scanCmd.reason = eCsrScanBgScan;
679 }
680 else if(eCSR_SCAN_HO_PROBE_SCAN == pScanRequest->requestType)
681 {
682 pScanCmd->u.scanCmd.reason = eCsrScanProbeBss;
683 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700684 else if(eCSR_SCAN_P2P_FIND_PEER == pScanRequest->requestType)
685 {
686 pScanCmd->u.scanCmd.reason = eCsrScanP2PFindPeer;
687 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700688 else
689 {
690 pScanCmd->u.scanCmd.reason = eCsrScanIdleScan;
691 }
692 if(pScanRequest->minChnTime == 0 && pScanRequest->maxChnTime == 0)
693 {
694 //The caller doesn't set the time correctly. Set it here
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530695 csrSetDefaultScanTiming(pMac, pScanRequest->scanType,
696 pScanRequest);
697 smsLog(pMac, LOG1, FL("Setting default min %d and max %d"
698 " ChnTime"), pScanRequest->minChnTime,
699 pScanRequest->maxChnTime);
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700700 }
701#ifdef WLAN_AP_STA_CONCURRENCY
702 if(pScanRequest->restTime == 0)
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800703 {
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700704 //Need to set restTime only if at least one session is connected
705 if(csrIsAnySessionConnected(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -0700706 {
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700707 pScanRequest->restTime = pMac->roam.configParam.nRestTimeConc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700708 }
709 }
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700710#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -0700711 /*For Standalone wlan : channel time will remain the same.
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530712 For BTC with A2DP up: Channel time = Channel time * 2, if station is not already associated.
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800713 This has been done to provide a larger scan window for faster connection during btc.Else Scan is seen
714 to take a long time.
715 For BTC with A2DP up: Channel time will not be doubled, if station is already associated.
716 */
Jeff Johnson32d95a32012-09-10 13:15:23 -0700717 status = csrRoamGetConnectState(pMac,sessionId,&ConnectState);
Srinivas Girigowdac84c57c2013-02-19 17:41:56 -0800718 if (HAL_STATUS_SUCCESS(status) &&
719 pMac->btc.fA2DPUp &&
Jeff Johnson32d95a32012-09-10 13:15:23 -0700720 (eCSR_ASSOC_STATE_TYPE_INFRA_ASSOCIATED != ConnectState) &&
721 (eCSR_ASSOC_STATE_TYPE_IBSS_CONNECTED != ConnectState))
722 {
723 pScanRequest->maxChnTime = pScanRequest->maxChnTime << 1;
724 pScanRequest->minChnTime = pScanRequest->minChnTime << 1;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530725 smsLog( pMac, LOG1, FL("BTC A2DP up, doubling max and min"
726 " ChnTime (Max=%d Min=%d)"),
727 pScanRequest->maxChnTime,
728 pScanRequest->minChnTime);
Jeff Johnson32d95a32012-09-10 13:15:23 -0700729 }
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800730
Abhishek Singhadd13582016-09-29 17:00:03 +0530731 pScanRequest->max_chntime_btc_esco =
732 pMac->roam.configParam.max_chntime_btc_esco;
733 pScanRequest->min_chntime_btc_esco =
734 pMac->roam.configParam.min_chntime_btc_esco;
Jeff Johnson295189b2012-06-20 16:38:30 -0700735 //Need to make the following atomic
736 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
737
738 if(pScanRequestID)
739 {
740 *pScanRequestID = pScanCmd->u.scanCmd.scanID;
741 }
742
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800743 // If it is the first scan request from HDD, CSR checks if it is for 11d.
Jeff Johnson295189b2012-06-20 16:38:30 -0700744 // If it is not, CSR will save the scan request in the pending cmd queue
745 // & issue an 11d scan request to PE.
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800746 if (((0 == pScanCmd->u.scanCmd.scanID)
Jeff Johnson295189b2012-06-20 16:38:30 -0700747 && (eCSR_SCAN_REQUEST_11D_SCAN != pScanRequest->requestType))
748#ifdef SOFTAP_CHANNEL_RANGE
749 && (eCSR_SCAN_SOFTAP_CHANNEL_RANGE != pScanRequest->requestType)
750#endif
751 && (eANI_BOOLEAN_FALSE == pMac->scan.fEnableBypass11d)
752 )
753 {
754 tSmeCmd *p11dScanCmd;
755 tCsrScanRequest scanReq;
756 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
757
Kiet Lam64c1b492013-07-12 13:56:44 +0530758 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -0700759
760 p11dScanCmd = csrGetCommandBuffer(pMac);
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800761 if (p11dScanCmd)
Jeff Johnson295189b2012-06-20 16:38:30 -0700762 {
763 tANI_U32 numChn = pMac->scan.baseChannels.numChannels;
764
Kiet Lam64c1b492013-07-12 13:56:44 +0530765 vos_mem_set(&p11dScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
766 pChnInfo->ChannelList = vos_mem_malloc(numChn);
767 if ( NULL == pChnInfo->ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -0700768 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530769 smsLog(pMac, LOGE, FL("Failed to allocate memory"));
770 status = eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -0700771 break;
772 }
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530773 vos_mem_copy(pChnInfo->ChannelList,
774 pMac->scan.baseChannels.channelList,
775 numChn);
Jeff Johnson295189b2012-06-20 16:38:30 -0700776 pChnInfo->numOfChannels = (tANI_U8)numChn;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530777
Jeff Johnson295189b2012-06-20 16:38:30 -0700778 p11dScanCmd->command = eSmeCommandScan;
Mihir Shetefc7ff5b2014-01-27 11:30:05 +0530779 p11dScanCmd->u.scanCmd.callback = pMac->scan.callback11dScanDone;
Jeff Johnson295189b2012-06-20 16:38:30 -0700780 p11dScanCmd->u.scanCmd.pContext = NULL;
c_hpothu0d5a7352014-03-22 12:30:25 +0530781 p11dScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID;
Jeff Johnson295189b2012-06-20 16:38:30 -0700782 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
783
784 if ( csrIs11dSupported(pMac) )
785 {
c_hpothudbefd3e2014-04-28 15:59:47 +0530786 scanReq.scanType = eSIR_PASSIVE_SCAN;
Jeff Johnson295189b2012-06-20 16:38:30 -0700787 scanReq.requestType = eCSR_SCAN_REQUEST_11D_SCAN;
788 p11dScanCmd->u.scanCmd.reason = eCsrScan11d1;
789 scanReq.maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
790 scanReq.minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
791 }
792 else
793 {
c_hpothudbefd3e2014-04-28 15:59:47 +0530794 scanReq.scanType = pScanRequest->scanType;
Jeff Johnson295189b2012-06-20 16:38:30 -0700795 scanReq.requestType = eCSR_SCAN_IDLE_MODE_SCAN;
796 p11dScanCmd->u.scanCmd.reason = eCsrScanIdleScan;
797 scanReq.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
798 scanReq.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800799
Abhishek Singhadd13582016-09-29 17:00:03 +0530800 scanReq.max_chntime_btc_esco =
801 pMac->roam.configParam.max_chntime_btc_esco;
802 scanReq.min_chntime_btc_esco =
803 pMac->roam.configParam.min_chntime_btc_esco;
Jeff Johnson295189b2012-06-20 16:38:30 -0700804 }
c_hpothu059edb02014-03-12 21:44:28 +0530805 if (pMac->roam.configParam.nInitialDwellTime)
806 {
807 scanReq.maxChnTime =
808 pMac->roam.configParam.nInitialDwellTime;
809 smsLog(pMac, LOG1, FL("11d scan, updating"
810 "dwell time for first scan %u"),
811 scanReq.maxChnTime);
812 }
Deepthi Gowrie11da8c2016-02-04 18:18:39 +0530813 if ((pScanCmd->u.scanCmd.reason == eCsrScanUserRequest)
814 && !(pScanRequest->p2pSearch)
Gupta, Kapilb79cda32015-12-30 20:36:33 +0530815 &&(pScanRequest->ChannelInfo.numOfChannels
816 < pMac->roam.configParam.
817 max_chan_for_dwell_time_cfg))
818 {
819 pScanRequest->maxChnTime =
820 pScanRequest->maxChnTime << 1;
821 pScanRequest->minChnTime =
822 pScanRequest->minChnTime << 1;
823 smsLog(pMac, LOG1,
824 FL("Double ChnTime (Max=%d Min=%d) numOfChannels=%d max_chan_for_dwell_time_cfg=%d"),
825 pScanRequest->maxChnTime,
826 pScanRequest->minChnTime,
827 pScanRequest->ChannelInfo.numOfChannels,
828 pMac->roam.configParam.
829 max_chan_for_dwell_time_cfg);
830 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700831
Jeff Johnson295189b2012-06-20 16:38:30 -0700832 status = csrScanCopyRequest(pMac, &p11dScanCmd->u.scanCmd.u.scanRequest, &scanReq);
833 //Free the channel list
Kiet Lam64c1b492013-07-12 13:56:44 +0530834 vos_mem_free(pChnInfo->ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -0700835 pChnInfo->ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -0700836
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800837 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700838 {
krunal soni5f112f02013-11-25 15:00:11 -0800839 pMac->scan.scanProfile.numOfChannels =
840 p11dScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -0700841 //Start process the command
842#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +0530843 if (!pMac->fScanOffload)
844 status = csrQueueScanRequest(pMac, p11dScanCmd);
845 else
846 status = csrQueueSmeCommand(pMac, p11dScanCmd,
847 eANI_BOOLEAN_FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -0700848#else
849 status = csrQueueSmeCommand(pMac, p11dScanCmd, eANI_BOOLEAN_FALSE);
850#endif
851 if( !HAL_STATUS_SUCCESS( status ) )
852 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530853 smsLog(pMac, LOGE, FL("Failed to send message"
854 " status = %d"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -0700855 break;
856 }
857 }
858 else
859 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530860 smsLog(pMac, LOGE, FL("csrScanCopyRequest failed"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700861 break;
862 }
863 }
864 else
865 {
866 //error
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530867 smsLog( pMac, LOGE, FL("p11dScanCmd failed") );
Jeff Johnson295189b2012-06-20 16:38:30 -0700868 break;
869 }
870 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700871
872 //Scan only 2G Channels if set in ini file
873 //This is mainly to reduce the First Scan duration
874 //Once we turn on Wifi
875 if(pMac->scan.fFirstScanOnly2GChnl)
876 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800877 smsLog( pMac, LOG1, FL("Scanning only 2G Channels during first scan"));
Jeff Johnsone7245742012-09-05 17:12:55 -0700878 csrScan2GOnyRequest(pMac, pScanCmd, pScanRequest);
879 }
880
c_hpothu059edb02014-03-12 21:44:28 +0530881 if (pMac->roam.configParam.nInitialDwellTime)
882 {
883 pScanRequest->maxChnTime =
884 pMac->roam.configParam.nInitialDwellTime;
885 pMac->roam.configParam.nInitialDwellTime = 0;
886 smsLog(pMac, LOG1,
887 FL("updating dwell time for first scan %u"),
888 pScanRequest->maxChnTime);
889 }
890
Deepthi Gowrie11da8c2016-02-04 18:18:39 +0530891 if ((pScanCmd->u.scanCmd.reason == eCsrScanUserRequest)
892 && !(pScanRequest->p2pSearch)
Gupta, Kapilb79cda32015-12-30 20:36:33 +0530893 && (pScanRequest->ChannelInfo.numOfChannels
894 < pMac->roam.configParam.max_chan_for_dwell_time_cfg))
895 {
896 pScanRequest->maxChnTime = pScanRequest->maxChnTime << 1;
897 pScanRequest->minChnTime = pScanRequest->minChnTime << 1;
898 smsLog(pMac, LOG1,
899 FL("Double ChnTime (Max=%d Min=%d) numOfChannels=%d max_chan_for_dwell_time_cfg=%d"),
900 pScanRequest->maxChnTime,
901 pScanRequest->minChnTime,
902 pScanRequest->ChannelInfo.numOfChannels,
903 pMac->roam.configParam.max_chan_for_dwell_time_cfg);
904 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700905 status = csrScanCopyRequest(pMac, &pScanCmd->u.scanCmd.u.scanRequest, pScanRequest);
906 if(HAL_STATUS_SUCCESS(status))
907 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530908 tCsrScanRequest *pTempScanReq =
909 &pScanCmd->u.scanCmd.u.scanRequest;
krunal soni5f112f02013-11-25 15:00:11 -0800910 pMac->scan.scanProfile.numOfChannels =
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530911 pTempScanReq->ChannelInfo.numOfChannels;
krunal soni5f112f02013-11-25 15:00:11 -0800912
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530913 smsLog( pMac, LOG1, FL(" SId=%d scanId=%d"
914 " Scan reason=%u numSSIDs=%d"
915 " numChan=%d P2P search=%d minCT=%d maxCT=%d"
916 " minCBtc=%d maxCBtx=%d"),
917 sessionId, pScanCmd->u.scanCmd.scanID,
918 pScanCmd->u.scanCmd.reason,
919 pTempScanReq->SSIDs.numOfSSIDs,
920 pTempScanReq->ChannelInfo.numOfChannels,
921 pTempScanReq->p2pSearch,
922 pTempScanReq->minChnTime,
923 pTempScanReq->maxChnTime,
Abhishek Singhadd13582016-09-29 17:00:03 +0530924 pTempScanReq->min_chntime_btc_esco,
925 pTempScanReq->max_chntime_btc_esco);
Jeff Johnson295189b2012-06-20 16:38:30 -0700926 //Start process the command
927#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +0530928 if (!pMac->fScanOffload)
929 status = csrQueueScanRequest(pMac,pScanCmd);
930 else
931 status = csrQueueSmeCommand(pMac, pScanCmd,
932 eANI_BOOLEAN_FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -0700933#else
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530934 status = csrQueueSmeCommand(pMac, pScanCmd,
935 eANI_BOOLEAN_FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -0700936#endif
937 if( !HAL_STATUS_SUCCESS( status ) )
938 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800939 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700940 break;
941 }
942 }
943 else
944 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800945 smsLog( pMac, LOGE, FL(" fail to copy request status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700946 break;
947 }
948 }
949 else
950 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800951 smsLog( pMac, LOGE, FL(" pScanCmd is NULL"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700952 break;
953 }
954 }
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530955 else
956 {
957 smsLog( pMac, LOGE, FL("SId: %d Scanning not enabled"
958 " Scan type=%u, numOfSSIDs=%d P2P search=%d"),
959 sessionId, pScanRequest->requestType,
960 pScanRequest->SSIDs.numOfSSIDs,
961 pScanRequest->p2pSearch );
962 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700963 } while(0);
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530964
965
Jeff Johnson295189b2012-06-20 16:38:30 -0700966 if(!HAL_STATUS_SUCCESS(status) && pScanCmd)
967 {
968 if( eCsrScanIdleScan == pScanCmd->u.scanCmd.reason )
969 {
970 //Set the flag back for restarting idle scan
971 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
972 }
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530973 smsLog( pMac, LOGE, FL(" SId: %d Failed with status=%d"
974 " Scan reason=%u numOfSSIDs=%d"
975 " P2P search=%d scanId=%d"),
976 sessionId, status, pScanCmd->u.scanCmd.reason,
977 pScanRequest->SSIDs.numOfSSIDs, pScanRequest->p2pSearch,
978 pScanCmd->u.scanCmd.scanID );
Jeff Johnson295189b2012-06-20 16:38:30 -0700979 csrReleaseCommandScan(pMac, pScanCmd);
980 }
981
982 return (status);
983}
984
985
986eHalStatus csrScanRequestResult(tpAniSirGlobal pMac)
987{
988 eHalStatus status = eHAL_STATUS_SUCCESS;
989 tSmeCmd *pScanCmd;
990
991 if(pMac->scan.fScanEnable)
992 {
993 pScanCmd = csrGetCommandBuffer(pMac);
994 if(pScanCmd)
995 {
996 pScanCmd->command = eSmeCommandScan;
Kiet Lam64c1b492013-07-12 13:56:44 +0530997 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -0700998 pScanCmd->u.scanCmd.callback = NULL;
999 pScanCmd->u.scanCmd.pContext = NULL;
1000 pScanCmd->u.scanCmd.reason = eCsrScanGetResult;
1001 //Need to make the following atomic
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07001002 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID; //let it wrap around
Jeff Johnson295189b2012-06-20 16:38:30 -07001003 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
1004 if( !HAL_STATUS_SUCCESS( status ) )
1005 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001006 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001007 csrReleaseCommandScan(pMac, pScanCmd);
1008 }
1009 }
1010 else
1011 {
1012 //log error
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001013 smsLog(pMac, LOGE, FL("can not obtain a common buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001014 status = eHAL_STATUS_RESOURCES;
1015 }
1016 }
1017
1018 return (status);
1019}
1020
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07001021#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
1022eHalStatus csrScanRequestLfrResult(tpAniSirGlobal pMac, tANI_U32 sessionId,
1023 csrScanCompleteCallback callback, void *pContext)
1024{
1025 eHalStatus status = eHAL_STATUS_SUCCESS;
1026 tSmeCmd *pScanCmd;
1027
1028 if (pMac->scan.fScanEnable)
1029 {
1030 pScanCmd = csrGetCommandBuffer(pMac);
1031 if (pScanCmd)
1032 {
1033 pScanCmd->command = eSmeCommandScan;
1034 pScanCmd->sessionId = sessionId;
Kiet Lam64c1b492013-07-12 13:56:44 +05301035 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07001036 pScanCmd->u.scanCmd.callback = callback;
1037 pScanCmd->u.scanCmd.pContext = pContext;
1038 pScanCmd->u.scanCmd.reason = eCsrScanGetLfrResult;
1039 //Need to make the following atomic
1040 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID; //let it wrap around
1041 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_TRUE);
1042 if ( !HAL_STATUS_SUCCESS( status ) )
1043 {
1044 smsLog( pMac, LOGE, FL(" fail to send message status = %d\n"), status );
1045 csrReleaseCommandScan(pMac, pScanCmd);
1046 }
1047 }
1048 else
1049 {
1050 //log error
1051 smsLog(pMac, LOGE, FL("can not obtain a common buffer\n"));
1052 status = eHAL_STATUS_RESOURCES;
1053 }
1054 }
1055
1056 return (status);
1057}
1058#endif //WLAN_FEATURE_ROAM_SCAN_OFFLOAD
Jeff Johnson295189b2012-06-20 16:38:30 -07001059
1060eHalStatus csrScanAllChannels(tpAniSirGlobal pMac, eCsrRequestType reqType)
1061{
1062 eHalStatus status = eHAL_STATUS_SUCCESS;
1063 tANI_U32 scanId;
1064 tCsrScanRequest scanReq;
1065
Kiet Lam64c1b492013-07-12 13:56:44 +05301066 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001067 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
1068 scanReq.scanType = eSIR_ACTIVE_SCAN;
1069 scanReq.requestType = reqType;
1070 scanReq.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1071 scanReq.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Abhishek Singhadd13582016-09-29 17:00:03 +05301072 scanReq.max_chntime_btc_esco =
1073 pMac->roam.configParam.max_chntime_btc_esco;
1074 scanReq.min_chntime_btc_esco =
1075 pMac->roam.configParam.min_chntime_btc_esco;
Jeff Johnson295189b2012-06-20 16:38:30 -07001076 //Scan with invalid sessionId.
1077 //This results in SME using the first available session to scan.
1078 status = csrScanRequest(pMac, CSR_SESSION_ID_INVALID, &scanReq,
1079 &scanId, NULL, NULL);
1080
1081 return (status);
1082}
1083
1084
1085
1086
1087eHalStatus csrIssueRoamAfterLostlinkScan(tpAniSirGlobal pMac, tANI_U32 sessionId, eCsrRoamReason reason)
1088{
1089 eHalStatus status = eHAL_STATUS_FAILURE;
1090 tScanResultHandle hBSSList = NULL;
1091 tCsrScanResultFilter *pScanFilter = NULL;
1092 tANI_U32 roamId = 0;
1093 tCsrRoamProfile *pProfile = NULL;
1094 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1095
Jeff Johnson32d95a32012-09-10 13:15:23 -07001096 if(!pSession)
1097 {
1098 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1099 return eHAL_STATUS_FAILURE;
1100 }
1101
Jeff Johnson295189b2012-06-20 16:38:30 -07001102 do
1103 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001104 smsLog(pMac, LOG1, " csrIssueRoamAfterLostlinkScan called");
Jeff Johnson295189b2012-06-20 16:38:30 -07001105 if(pSession->fCancelRoaming)
1106 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001107 smsLog(pMac, LOGW, " lostlink roaming is cancelled");
Jeff Johnson295189b2012-06-20 16:38:30 -07001108 csrScanStartIdleScan(pMac);
1109 status = eHAL_STATUS_SUCCESS;
1110 break;
1111 }
1112 //Here is the profile we need to connect to
Kiet Lam64c1b492013-07-12 13:56:44 +05301113 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1114 if ( NULL == pScanFilter)
1115 status = eHAL_STATUS_FAILURE;
1116 else
1117 status = eHAL_STATUS_SUCCESS;
1118 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001119 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301120 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001121 if(NULL == pSession->pCurRoamProfile)
1122 {
1123 pScanFilter->EncryptionType.numEntries = 1;
1124 pScanFilter->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_NONE;
1125 }
1126 else
1127 {
1128 //We have to make a copy of pCurRoamProfile because it will be free inside csrRoamIssueConnect
Kiet Lam64c1b492013-07-12 13:56:44 +05301129 pProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1130 if ( NULL == pProfile )
1131 status = eHAL_STATUS_FAILURE;
1132 else
1133 status = eHAL_STATUS_SUCCESS;
1134 if (!HAL_STATUS_SUCCESS(status))
1135 break;
1136 vos_mem_set(pProfile, sizeof(tCsrRoamProfile), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001137 status = csrRoamCopyProfile(pMac, pProfile, pSession->pCurRoamProfile);
1138 if(!HAL_STATUS_SUCCESS(status))
1139 break;
1140 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1141 }//We have a profile
1142 roamId = GET_NEXT_ROAM_ID(&pMac->roam);
1143 if(HAL_STATUS_SUCCESS(status))
1144 {
1145 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1146 if(HAL_STATUS_SUCCESS(status))
1147 {
1148 if(eCsrLostLink1 == reason)
1149 {
1150 //we want to put the last connected BSS to the very beginning, if possible
1151 csrMoveBssToHeadFromBSSID(pMac, &pSession->connectedProfile.bssid, hBSSList);
1152 }
1153 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList, reason,
1154 roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1155 if(!HAL_STATUS_SUCCESS(status))
1156 {
1157 csrScanResultPurge(pMac, hBSSList);
1158 }
1159 }//Have scan result
1160 }
1161 }while(0);
1162 if(pScanFilter)
1163 {
1164 //we need to free memory for filter if profile exists
1165 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301166 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001167 }
1168 if(NULL != pProfile)
1169 {
1170 csrReleaseProfile(pMac, pProfile);
Kiet Lam64c1b492013-07-12 13:56:44 +05301171 vos_mem_free(pProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07001172 }
1173
1174 return (status);
1175}
1176
1177
Ratheesh S Pece1f832015-07-25 15:50:25 +05301178eHalStatus csrScanGetScanChnInfo(tpAniSirGlobal pMac, tSmeCmd *pCommand)
Jeff Johnson295189b2012-06-20 16:38:30 -07001179{
1180 eHalStatus status = eHAL_STATUS_SUCCESS;
1181 tSmeCmd *pScanCmd;
1182
1183 if(pMac->scan.fScanEnable)
1184 {
1185 pScanCmd = csrGetCommandBuffer(pMac);
1186 if(pScanCmd)
1187 {
1188 pScanCmd->command = eSmeCommandScan;
Kiet Lam64c1b492013-07-12 13:56:44 +05301189 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001190 pScanCmd->u.scanCmd.reason = eCsrScanGetScanChnInfo;
1191 //Need to make the following atomic
1192 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Ratheesh S Pece1f832015-07-25 15:50:25 +05301193 pScanCmd->sessionId = pCommand->sessionId;
1194 if( pCommand->u.scanCmd.reason == eCsrScanUserRequest)
1195 {
1196 pScanCmd->u.scanCmd.callback = NULL;
1197 pScanCmd->u.scanCmd.pContext = NULL;
1198 } else {
1199 pScanCmd->u.scanCmd.callback = pCommand->u.scanCmd.callback;
1200 pScanCmd->u.scanCmd.pContext = pCommand->u.scanCmd.pContext;
1201 pScanCmd->u.scanCmd.abortScanIndication =
1202 pCommand->u.scanCmd.abortScanIndication;
1203 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001204 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
1205 if( !HAL_STATUS_SUCCESS( status ) )
1206 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001207 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001208 csrReleaseCommandScan(pMac, pScanCmd);
1209 }
1210 }
1211 else
1212 {
1213 //log error
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001214 smsLog(pMac, LOGE, FL("can not obtain a common buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001215 status = eHAL_STATUS_RESOURCES;
1216 }
1217 }
1218
1219 return (status);
1220}
1221
1222
1223eHalStatus csrScanHandleFailedLostlink1(tpAniSirGlobal pMac, tANI_U32 sessionId)
1224{
1225 eHalStatus status = eHAL_STATUS_FAILURE;
1226 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1227
Jeff Johnson32d95a32012-09-10 13:15:23 -07001228 if(!pSession)
1229 {
1230 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1231 return eHAL_STATUS_FAILURE;
1232 }
1233
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001234 smsLog(pMac, LOGW, " Lostlink scan 1 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001235 if(pSession->fCancelRoaming)
1236 {
1237 csrScanStartIdleScan(pMac);
1238 }
1239 else if(pSession->pCurRoamProfile)
1240 {
1241 //We fail lostlink1 but there may be other BSS in the cached result fit the profile. Give it a try first
1242 if(pSession->pCurRoamProfile->SSIDs.numOfSSIDs == 0 ||
1243 pSession->pCurRoamProfile->SSIDs.numOfSSIDs > 1)
1244 {
1245 //try lostlink scan2
1246 status = csrScanRequestLostLink2(pMac, sessionId);
1247 }
1248 else if(!pSession->pCurRoamProfile->ChannelInfo.ChannelList ||
1249 pSession->pCurRoamProfile->ChannelInfo.ChannelList[0] == 0)
1250 {
1251 //go straight to lostlink scan3
1252 status = csrScanRequestLostLink3(pMac, sessionId);
1253 }
1254 else
1255 {
1256 //we are done with lostlink
1257 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1258 {
1259 csrScanStartIdleScan(pMac);
1260 }
1261 status = eHAL_STATUS_SUCCESS;
1262 }
1263 }
1264 else
1265 {
1266 status = csrScanRequestLostLink3(pMac, sessionId);
1267 }
1268
1269 return (status);
1270}
1271
1272
1273
1274eHalStatus csrScanHandleFailedLostlink2(tpAniSirGlobal pMac, tANI_U32 sessionId)
1275{
1276 eHalStatus status = eHAL_STATUS_FAILURE;
1277 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1278
Jeff Johnson32d95a32012-09-10 13:15:23 -07001279 if(!pSession)
1280 {
1281 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1282 return eHAL_STATUS_FAILURE;
1283 }
1284
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001285 smsLog(pMac, LOGW, " Lostlink scan 2 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001286 if(pSession->fCancelRoaming)
1287 {
1288 csrScanStartIdleScan(pMac);
1289 }
1290 else if(!pSession->pCurRoamProfile || !pSession->pCurRoamProfile->ChannelInfo.ChannelList ||
1291 pSession->pCurRoamProfile->ChannelInfo.ChannelList[0] == 0)
1292 {
1293 //try lostlink scan3
1294 status = csrScanRequestLostLink3(pMac, sessionId);
1295 }
1296 else
1297 {
1298 //we are done with lostlink
1299 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1300 {
1301 csrScanStartIdleScan(pMac);
1302 }
1303 }
1304
1305 return (status);
1306}
1307
1308
1309
1310eHalStatus csrScanHandleFailedLostlink3(tpAniSirGlobal pMac, tANI_U32 sessionId)
1311{
1312 eHalStatus status = eHAL_STATUS_SUCCESS;
1313
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001314 smsLog(pMac, LOGW, " Lostlink scan 3 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001315 if(eANI_BOOLEAN_TRUE == csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1316 {
1317 //we are done with lostlink
1318 csrScanStartIdleScan(pMac);
1319 }
1320
1321 return (status);
1322}
1323
1324
1325
1326
1327//Lostlink1 scan is to actively scan the last connected profile's SSID on all matched BSS channels.
1328//If no roam profile (it should not), it is like lostlinkscan3
1329eHalStatus csrScanRequestLostLink1( tpAniSirGlobal pMac, tANI_U32 sessionId )
1330{
1331 eHalStatus status = eHAL_STATUS_SUCCESS;
1332 tSmeCmd *pCommand = NULL;
1333 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1334 tCsrScanResultFilter *pScanFilter = NULL;
1335 tScanResultHandle hBSSList = NULL;
1336 tCsrScanResultInfo *pScanResult = NULL;
1337 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1338
Jeff Johnson32d95a32012-09-10 13:15:23 -07001339 if(!pSession)
1340 {
1341 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1342 return eHAL_STATUS_FAILURE;
1343 }
1344
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001345 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001346 do
1347 {
1348 pCommand = csrGetCommandBuffer(pMac);
1349 if(!pCommand)
1350 {
1351 status = eHAL_STATUS_RESOURCES;
1352 break;
1353 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301354 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001355 pCommand->command = eSmeCommandScan;
1356 pCommand->sessionId = (tANI_U8)sessionId;
1357 pCommand->u.scanCmd.reason = eCsrScanLostLink1;
1358 pCommand->u.scanCmd.callback = NULL;
1359 pCommand->u.scanCmd.pContext = NULL;
1360 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1361 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Abhishek Singhadd13582016-09-29 17:00:03 +05301362 pCommand->u.scanCmd.u.scanRequest.max_chntime_btc_esco =
1363 pMac->roam.configParam.max_chntime_btc_esco;
1364 pCommand->u.scanCmd.u.scanRequest.min_chntime_btc_esco =
1365 pMac->roam.configParam.min_chntime_btc_esco;
Jeff Johnson295189b2012-06-20 16:38:30 -07001366 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
1367 if(pSession->connectedProfile.SSID.length)
1368 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301369 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList = vos_mem_malloc(sizeof(tCsrSSIDInfo));
1370 if ( NULL == pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList )
1371 status = eHAL_STATUS_FAILURE;
1372 else
1373 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001374 if(!HAL_STATUS_SUCCESS(status))
1375 {
1376 break;
1377 }
1378 pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 1;
Kiet Lam64c1b492013-07-12 13:56:44 +05301379 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID,
1380 &pSession->connectedProfile.SSID, sizeof(tSirMacSSid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001381 }
1382 else
1383 {
1384 pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 0;
1385 }
1386 if(pSession->pCurRoamProfile)
1387 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301388 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1389 if ( NULL == pScanFilter )
1390 status = eHAL_STATUS_FAILURE;
1391 else
1392 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001393 if(!HAL_STATUS_SUCCESS(status))
1394 {
1395 break;
1396 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301397 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001398 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
1399 if(!HAL_STATUS_SUCCESS(status))
1400 {
1401 break;
1402 }
1403 //Don't change variable status here because whether we can get result or not, the command goes to PE.
1404 //The status is also used to indicate whether the command is queued. Not success meaning not queue
1405 if(HAL_STATUS_SUCCESS((csrScanGetResult(pMac, pScanFilter, &hBSSList))) && hBSSList)
1406 {
1407 tANI_U8 i, nChn = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05301408 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList =
1409 vos_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
1410 if ( NULL == pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
1411 status = eHAL_STATUS_FAILURE;
1412 else
1413 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001414 if(!HAL_STATUS_SUCCESS(status))
1415 {
1416 break;
1417 }
1418 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) &&
1419 nChn < WNI_CFG_VALID_CHANNEL_LIST_LEN)
1420 {
1421 for(i = 0; i < nChn; i++)
1422 {
1423 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1424 pScanResult->BssDescriptor.channelId)
1425 {
1426 break;
1427 }
1428 }
1429 if(i == nChn)
1430 {
1431 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pScanResult->BssDescriptor.channelId;
1432 }
1433 }
1434 //Include the last connected BSS' channel
1435 if(csrRoamIsChannelValid(pMac, pSession->connectedProfile.operationChannel))
1436 {
1437 for(i = 0; i < nChn; i++)
1438 {
1439 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1440 pSession->connectedProfile.operationChannel)
1441 {
1442 break;
1443 }
1444 }
1445 if(i == nChn)
1446 {
1447 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pSession->connectedProfile.operationChannel;
1448 }
1449 }
1450 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nChn;
1451 }
1452 else
1453 {
1454 if(csrRoamIsChannelValid(pMac, pSession->connectedProfile.operationChannel))
1455 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301456 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(1);
1457 if ( NULL == pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
1458 status = eHAL_STATUS_FAILURE;
1459 else
1460 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001461 //just try the last connected channel
1462 if(HAL_STATUS_SUCCESS(status))
1463 {
1464 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[0] = pSession->connectedProfile.operationChannel;
1465 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 1;
1466 }
1467 else
1468 {
1469 break;
1470 }
1471 }
1472 }
1473 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301474 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001475 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
1476 if( !HAL_STATUS_SUCCESS( status ) )
1477 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001478 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001479 break;
1480 }
1481 } while( 0 );
1482
1483 if(!HAL_STATUS_SUCCESS(status))
1484 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001485 smsLog(pMac, LOGW, " csrScanRequestLostLink1 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001486 if(pCommand)
1487 {
1488 csrReleaseCommandScan(pMac, pCommand);
1489 }
1490 status = csrScanHandleFailedLostlink1( pMac, sessionId );
1491 }
1492 if(pScanFilter)
1493 {
1494 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301495 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001496 }
1497 if(hBSSList)
1498 {
1499 csrScanResultPurge(pMac, hBSSList);
1500 }
1501
1502 return( status );
1503}
1504
1505
1506//Lostlink2 scan is to actively scan the all SSIDs of the last roaming profile's on all matched BSS channels.
1507//Since MAC doesn't support multiple SSID, we scan all SSIDs and filter them afterwards
1508eHalStatus csrScanRequestLostLink2( tpAniSirGlobal pMac, tANI_U32 sessionId )
1509{
1510 eHalStatus status = eHAL_STATUS_SUCCESS;
1511 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1512 tCsrScanResultFilter *pScanFilter = NULL;
1513 tScanResultHandle hBSSList = NULL;
1514 tCsrScanResultInfo *pScanResult = NULL;
1515 tSmeCmd *pCommand = NULL;
1516 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1517
Jeff Johnson32d95a32012-09-10 13:15:23 -07001518 if(!pSession)
1519 {
1520 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1521 return eHAL_STATUS_FAILURE;
1522 }
1523
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001524 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001525 do
1526 {
1527 pCommand = csrGetCommandBuffer(pMac);
1528 if(!pCommand)
1529 {
1530 status = eHAL_STATUS_RESOURCES;
1531 break;
1532 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301533 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001534 pCommand->command = eSmeCommandScan;
1535 pCommand->sessionId = (tANI_U8)sessionId;
1536 pCommand->u.scanCmd.reason = eCsrScanLostLink2;
1537 pCommand->u.scanCmd.callback = NULL;
1538 pCommand->u.scanCmd.pContext = NULL;
1539 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1540 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Abhishek Singhadd13582016-09-29 17:00:03 +05301541 pCommand->u.scanCmd.u.scanRequest.max_chntime_btc_esco =
1542 pMac->roam.configParam.max_chntime_btc_esco;
1543 pCommand->u.scanCmd.u.scanRequest.min_chntime_btc_esco =
1544 pMac->roam.configParam.min_chntime_btc_esco;
Jeff Johnson295189b2012-06-20 16:38:30 -07001545 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
1546 if(pSession->pCurRoamProfile)
1547 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301548 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1549 if ( NULL == pScanFilter )
1550 status = eHAL_STATUS_FAILURE;
1551 else
1552 status = eHAL_STATUS_SUCCESS;
1553 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001554 {
1555 break;
1556 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301557 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001558 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
1559 if(!HAL_STATUS_SUCCESS(status))
1560 {
1561 break;
1562 }
1563 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1564 if(!HAL_STATUS_SUCCESS(status))
1565 {
1566 break;
1567 }
1568 if(hBSSList)
1569 {
1570 tANI_U8 i, nChn = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05301571 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList =
1572 vos_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
1573 if ( NULL == pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
1574 status = eHAL_STATUS_FAILURE;
1575 else
1576 status = eHAL_STATUS_SUCCESS;
1577 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001578 {
1579 break;
1580 }
1581 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) &&
1582 nChn < WNI_CFG_VALID_CHANNEL_LIST_LEN)
1583 {
1584 for(i = 0; i < nChn; i++)
1585 {
1586 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1587 pScanResult->BssDescriptor.channelId)
1588 {
1589 break;
1590 }
1591 }
1592 if(i == nChn)
1593 {
1594 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pScanResult->BssDescriptor.channelId;
1595 }
1596 }
1597 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nChn;
1598 }
1599 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301600 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001601 //Put to the head in pending queue
1602 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_TRUE);
1603 if( !HAL_STATUS_SUCCESS( status ) )
1604 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001605 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001606 break;
1607 }
1608 } while( 0 );
1609
1610 if(!HAL_STATUS_SUCCESS(status))
1611 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001612 smsLog(pMac, LOGW, " csrScanRequestLostLink2 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001613 if(pCommand)
1614 {
1615 csrReleaseCommandScan(pMac, pCommand);
1616 }
1617 status = csrScanHandleFailedLostlink2( pMac, sessionId );
1618 }
1619 if(pScanFilter)
1620 {
1621 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301622 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001623 }
1624 if(hBSSList)
1625 {
1626 csrScanResultPurge(pMac, hBSSList);
1627 }
1628
1629 return( status );
1630}
1631
1632
1633//To actively scan all valid channels
1634eHalStatus csrScanRequestLostLink3( tpAniSirGlobal pMac, tANI_U32 sessionId )
1635{
1636 eHalStatus status = eHAL_STATUS_SUCCESS;
1637 tSmeCmd *pCommand;
1638 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1639
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001640 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001641 do
1642 {
1643 pCommand = csrGetCommandBuffer(pMac);
1644 if(!pCommand)
1645 {
1646 status = eHAL_STATUS_RESOURCES;
1647 break;
1648 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301649 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001650 pCommand->command = eSmeCommandScan;
1651 pCommand->sessionId = (tANI_U8)sessionId;
1652 pCommand->u.scanCmd.reason = eCsrScanLostLink3;
1653 pCommand->u.scanCmd.callback = NULL;
1654 pCommand->u.scanCmd.pContext = NULL;
1655 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1656 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Abhishek Singhadd13582016-09-29 17:00:03 +05301657 pCommand->u.scanCmd.u.scanRequest.max_chntime_btc_esco =
1658 pMac->roam.configParam.max_chntime_btc_esco;
1659 pCommand->u.scanCmd.u.scanRequest.min_chntime_btc_esco =
1660 pMac->roam.configParam.min_chntime_btc_esco;
Jeff Johnson295189b2012-06-20 16:38:30 -07001661 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Kiet Lam64c1b492013-07-12 13:56:44 +05301662 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001663 //Put to the head of pending queue
1664 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_TRUE);
1665 if( !HAL_STATUS_SUCCESS( status ) )
1666 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001667 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001668 break;
1669 }
1670 } while( 0 );
1671 if(!HAL_STATUS_SUCCESS(status))
1672 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001673 smsLog(pMac, LOGW, " csrScanRequestLostLink3 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001674 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1675 {
1676 csrScanStartIdleScan(pMac);
1677 }
1678 if(pCommand)
1679 {
1680 csrReleaseCommandScan(pMac, pCommand);
1681 }
1682 }
1683
1684 return( status );
1685}
1686
1687
1688eHalStatus csrScanHandleSearchForSSID(tpAniSirGlobal pMac, tSmeCmd *pCommand)
1689{
1690 eHalStatus status = eHAL_STATUS_FAILURE;
1691 tScanResultHandle hBSSList = CSR_INVALID_SCANRESULT_HANDLE;
1692 tCsrScanResultFilter *pScanFilter = NULL;
1693 tCsrRoamProfile *pProfile = pCommand->u.scanCmd.pToRoamProfile;
1694 tANI_U32 sessionId = pCommand->sessionId;
Abhishek Singhd61b97a2015-12-17 15:23:52 +05301695 tCsrRoamSession *pSession = CSR_GET_SESSION(pMac, sessionId);
1696
Jeff Johnson295189b2012-06-20 16:38:30 -07001697 do
1698 {
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001699#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
1700 //if this scan is for LFR
1701 if(pMac->roam.neighborRoamInfo.uOsRequestedHandoff)
1702 {
1703 //notify LFR state m/c
1704 if(eHAL_STATUS_SUCCESS != csrNeighborRoamSssidScanDone(pMac, eHAL_STATUS_SUCCESS))
1705 {
Mukul Sharma20aa6582014-08-07 21:36:12 +05301706 csrNeighborRoamStartLfrScan(pMac, REASON_OS_REQUESTED_ROAMING_NOW);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001707 }
1708 status = eHAL_STATUS_SUCCESS;
1709 break;
1710 }
1711#endif
Abhishek Singhd61b97a2015-12-17 15:23:52 +05301712 if (!pSession)
1713 {
1714 smsLog(pMac, LOGE, FL("session %d not found"), sessionId);
1715 break;
1716 }
Abhishek Singhd18028d2016-02-11 17:45:54 +05301717 /* If Disconnect is already issued from HDD no need to issue connect
1718 * pSession->abortConnection will not be set in case of try
1719 * disconnect or hdd stop adaptor use connectState for these cases.
1720 */
1721 if (pSession->abortConnection ||
1722 (pMac->roam.roamSession[sessionId].connectState ==
1723 eCSR_ASSOC_STATE_TYPE_INFRA_DISCONNECTING))
Abhishek Singhd61b97a2015-12-17 15:23:52 +05301724 {
1725 smsLog(pMac, LOGE,
1726 FL("Disconnect in progress, no need to issue connect"));
1727 break;
1728 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001729 //If there is roam command waiting, ignore this roam because the newer roam command is the one to execute
1730 if(csrIsRoamCommandWaitingForSession(pMac, sessionId))
1731 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001732 smsLog(pMac, LOGW, FL(" aborts because roam command waiting"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001733 break;
1734 }
1735 if(pProfile == NULL)
1736 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301737 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1738 if ( NULL == pScanFilter )
1739 status = eHAL_STATUS_FAILURE;
1740 else
1741 status = eHAL_STATUS_SUCCESS;
1742 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001743 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301744 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001745 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1746 if(!HAL_STATUS_SUCCESS(status))
1747 break;
1748 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1749 if(!HAL_STATUS_SUCCESS(status))
1750 break;
1751 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList, eCsrHddIssued,
1752 pCommand->u.scanCmd.roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1753 if(!HAL_STATUS_SUCCESS(status))
1754 {
1755 break;
1756 }
1757 }while(0);
1758 if(!HAL_STATUS_SUCCESS(status))
1759 {
1760 if(CSR_INVALID_SCANRESULT_HANDLE != hBSSList)
1761 {
1762 csrScanResultPurge(pMac, hBSSList);
1763 }
1764 //We haven't done anything to this profile
Abhishek Singh72c2f4e2016-07-22 11:25:43 +05301765 csrRoamCallCallback(pMac, sessionId, NULL,
1766 pCommand->u.scanCmd.roamId,
1767 eCSR_ROAM_ASSOCIATION_FAILURE,
1768 eCSR_ROAM_RESULT_SCAN_FOR_SSID_FAILURE);
Jeff Johnson295189b2012-06-20 16:38:30 -07001769 //In case we have nothing else to do, restart idle scan
1770 if(csrIsConnStateDisconnected(pMac, sessionId) && !csrIsRoamCommandWaiting(pMac))
1771 {
1772 status = csrScanStartIdleScan(pMac);
1773 }
1774#ifdef FEATURE_WLAN_BTAMP_UT_RF
1775 //In case of WDS station, let it retry.
1776 if( CSR_IS_WDS_STA(pProfile) )
1777 {
1778 //Save the roma profile so we can retry
1779 csrFreeRoamProfile( pMac, sessionId );
Kiet Lam64c1b492013-07-12 13:56:44 +05301780 pSession->pCurRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1781 if ( NULL != pSession->pCurRoamProfile )
Jeff Johnson295189b2012-06-20 16:38:30 -07001782 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301783 vos_mem_set(pSession->pCurRoamProfilee, sizeof(tCsrRoamProfile), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001784 csrRoamCopyProfile(pMac, pSession->pCurRoamProfile, pProfile);
1785 }
1786 csrRoamStartJoinRetryTimer(pMac, sessionId, CSR_JOIN_RETRY_TIMEOUT_PERIOD);
1787 }
1788#endif
1789 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301790 if (pScanFilter)
Jeff Johnson295189b2012-06-20 16:38:30 -07001791 {
1792 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301793 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001794 }
1795
1796 return (status);
1797}
1798
1799
1800eHalStatus csrScanHandleSearchForSSIDFailure(tpAniSirGlobal pMac, tSmeCmd *pCommand)
1801{
1802 eHalStatus status = eHAL_STATUS_SUCCESS;
1803 tANI_U32 sessionId = pCommand->sessionId;
1804 tCsrRoamProfile *pProfile = pCommand->u.scanCmd.pToRoamProfile;
1805 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001806#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
1807 //if this scan is for LFR
1808 if(pMac->roam.neighborRoamInfo.uOsRequestedHandoff)
1809 {
1810 //notify LFR state m/c
1811 if(eHAL_STATUS_SUCCESS != csrNeighborRoamSssidScanDone(pMac, eHAL_STATUS_FAILURE))
1812 {
Mukul Sharma20aa6582014-08-07 21:36:12 +05301813 csrNeighborRoamStartLfrScan(pMac, REASON_OS_REQUESTED_ROAMING_NOW);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001814 }
1815 return eHAL_STATUS_SUCCESS;
1816 }
1817#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -07001818 if(!pSession)
1819 {
1820 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1821 return eHAL_STATUS_FAILURE;
1822 }
1823
Jeff Johnson295189b2012-06-20 16:38:30 -07001824#if defined(WLAN_DEBUG)
1825 if(pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs == 1)
1826 {
1827 char str[36];
Kiet Lam64c1b492013-07-12 13:56:44 +05301828 vos_mem_copy(str,
1829 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.ssId,
1830 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.length);
Jeff Johnson295189b2012-06-20 16:38:30 -07001831 str[pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.length] = 0;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001832 smsLog(pMac, LOGW, FL(" SSID = %s"), str);
Jeff Johnson295189b2012-06-20 16:38:30 -07001833 }
1834#endif
1835 //Check whether it is for start ibss. No need to do anything if it is a JOIN request
1836 if(pProfile && CSR_IS_START_IBSS(pProfile))
1837 {
1838 status = csrRoamIssueConnect(pMac, sessionId, pProfile, NULL, eCsrHddIssued,
1839 pCommand->u.scanCmd.roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1840 if(!HAL_STATUS_SUCCESS(status))
1841 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001842 smsLog(pMac, LOGE, FL("failed to issue startIBSS command with status = 0x%08X"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001843 csrRoamCallCallback(pMac, sessionId, NULL, pCommand->u.scanCmd.roamId, eCSR_ROAM_FAILED, eCSR_ROAM_RESULT_FAILURE);
1844 }
1845 }
1846 else
1847 {
1848 eCsrRoamResult roamResult = eCSR_ROAM_RESULT_FAILURE;
1849
1850 if(csrIsConnStateDisconnected(pMac, sessionId) &&
1851 !csrIsRoamCommandWaitingForSession(pMac, sessionId))
1852 {
1853 status = csrScanStartIdleScan(pMac);
1854 }
1855 if((NULL == pProfile) || !csrIsBssTypeIBSS(pProfile->BSSType))
1856 {
1857 //Only indicate assoc_completion if we indicate assoc_start.
1858 if(pSession->bRefAssocStartCnt > 0)
1859 {
1860 tCsrRoamInfo *pRoamInfo = NULL, roamInfo;
Kiet Lam64c1b492013-07-12 13:56:44 +05301861 vos_mem_set(&roamInfo, sizeof(tCsrRoamInfo), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001862 pRoamInfo = &roamInfo;
1863 if(pCommand->u.roamCmd.pRoamBssEntry)
1864 {
1865 tCsrScanResult *pScanResult =
1866 GET_BASE_ADDR(pCommand->u.roamCmd.pRoamBssEntry,
1867 tCsrScanResult, Link);
1868 roamInfo.pBssDesc = &pScanResult->Result.BssDescriptor;
1869 }
1870 roamInfo.statusCode = pSession->joinFailStatusCode.statusCode;
1871 roamInfo.reasonCode = pSession->joinFailStatusCode.reasonCode;
1872 pSession->bRefAssocStartCnt--;
1873 csrRoamCallCallback(pMac, sessionId, pRoamInfo,
1874 pCommand->u.scanCmd.roamId,
1875 eCSR_ROAM_ASSOCIATION_COMPLETION,
Abhishek Singh72c2f4e2016-07-22 11:25:43 +05301876 eCSR_ROAM_RESULT_SCAN_FOR_SSID_FAILURE);
Jeff Johnson295189b2012-06-20 16:38:30 -07001877 }
Madan Mohan Koyyalamudiee255f12012-09-28 15:41:19 -07001878 else
1879 {
1880 csrRoamCallCallback(pMac, sessionId, NULL,
1881 pCommand->u.scanCmd.roamId,
1882 eCSR_ROAM_ASSOCIATION_FAILURE,
Abhishek Singh72c2f4e2016-07-22 11:25:43 +05301883 eCSR_ROAM_RESULT_SCAN_FOR_SSID_FAILURE);
Madan Mohan Koyyalamudiee255f12012-09-28 15:41:19 -07001884 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001885#ifdef FEATURE_WLAN_BTAMP_UT_RF
1886 //In case of WDS station, let it retry.
1887 if( CSR_IS_WDS_STA(pProfile) )
1888 {
1889 //Save the roma profile so we can retry
1890 csrFreeRoamProfile( pMac, sessionId );
Kiet Lam64c1b492013-07-12 13:56:44 +05301891 pSession->pCurRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1892 if ( NULL != pSession->pCurRoamProfile )
Jeff Johnson295189b2012-06-20 16:38:30 -07001893 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301894 vos_mem_set(pSession->pCurRoamProfile, sizeof(tCsrRoamProfile), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001895 csrRoamCopyProfile(pMac, pSession->pCurRoamProfile, pProfile);
1896 }
1897 csrRoamStartJoinRetryTimer(pMac, sessionId, CSR_JOIN_RETRY_TIMEOUT_PERIOD);
1898 }
1899#endif
1900 }
1901 else
1902 {
1903 roamResult = eCSR_ROAM_RESULT_IBSS_START_FAILED;
1904 }
1905 csrRoamCompletion(pMac, sessionId, NULL, pCommand, roamResult, eANI_BOOLEAN_FALSE);
1906 }
1907
1908 return (status);
1909}
1910
1911
1912//After scan for cap changes, issue a roaming command to either reconnect to the AP or pick another one to connect
1913eHalStatus csrScanHandleCapChangeScanComplete(tpAniSirGlobal pMac, tANI_U32 sessionId)
1914{
1915 eHalStatus status = eHAL_STATUS_FAILURE;
1916 tScanResultHandle hBSSList = NULL;
1917 tCsrScanResultFilter *pScanFilter = NULL;
1918 tANI_U32 roamId = 0;
1919 tCsrRoamProfile *pProfile = NULL;
1920 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1921
1922 do
1923 {
1924 //Here is the profile we need to connect to
Kiet Lam64c1b492013-07-12 13:56:44 +05301925 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1926 if ( NULL == pScanFilter )
1927 status = eHAL_STATUS_FAILURE;
1928 else
1929 status = eHAL_STATUS_SUCCESS;
1930 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001931 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301932 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
1933 if (NULL == pSession) break;
1934 if (NULL == pSession->pCurRoamProfile)
Jeff Johnson295189b2012-06-20 16:38:30 -07001935 {
1936 pScanFilter->EncryptionType.numEntries = 1;
1937 pScanFilter->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_NONE;
1938 }
1939 else
1940 {
1941 //We have to make a copy of pCurRoamProfile because it will be free inside csrRoamIssueConnect
Kiet Lam64c1b492013-07-12 13:56:44 +05301942 pProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1943 if ( NULL == pProfile )
1944 status = eHAL_STATUS_FAILURE;
1945 else
1946 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001947 if(!HAL_STATUS_SUCCESS(status))
1948 break;
1949 status = csrRoamCopyProfile(pMac, pProfile, pSession->pCurRoamProfile);
1950 if(!HAL_STATUS_SUCCESS(status))
1951 break;
1952 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1953 }//We have a profile
1954 roamId = GET_NEXT_ROAM_ID(&pMac->roam);
1955 if(HAL_STATUS_SUCCESS(status))
1956 {
1957 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1958 if(HAL_STATUS_SUCCESS(status))
1959 {
1960 //we want to put the last connected BSS to the very beginning, if possible
1961 csrMoveBssToHeadFromBSSID(pMac, &pSession->connectedProfile.bssid, hBSSList);
1962 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList,
1963 eCsrCapsChange, 0, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1964 if(!HAL_STATUS_SUCCESS(status))
1965 {
1966 csrScanResultPurge(pMac, hBSSList);
1967 }
1968 }//Have scan result
1969 else
1970 {
Arif Hussaina7c8e412013-11-20 11:06:42 -08001971 smsLog(pMac, LOGW, FL("cannot find matching BSS of "
1972 MAC_ADDRESS_STR),
1973 MAC_ADDR_ARRAY(pSession->connectedProfile.bssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001974 //Disconnect
1975 csrRoamDisconnectInternal(pMac, sessionId, eCSR_DISCONNECT_REASON_UNSPECIFIED);
1976 }
1977 }
1978 }while(0);
1979 if(pScanFilter)
1980 {
1981 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301982 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001983 }
1984 if(NULL != pProfile)
1985 {
1986 csrReleaseProfile(pMac, pProfile);
Kiet Lam64c1b492013-07-12 13:56:44 +05301987 vos_mem_free(pProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07001988 }
1989
1990 return (status);
1991}
1992
1993
1994
1995eHalStatus csrScanResultPurge(tpAniSirGlobal pMac, tScanResultHandle hScanList)
1996{
1997 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
1998 tScanResultList *pScanList = (tScanResultList *)hScanList;
1999
2000 if(pScanList)
2001 {
2002 status = csrLLScanPurgeResult(pMac, &pScanList->List);
2003 csrLLClose(&pScanList->List);
Kiet Lam64c1b492013-07-12 13:56:44 +05302004 vos_mem_free(pScanList);
Jeff Johnson295189b2012-06-20 16:38:30 -07002005 }
2006 return (status);
2007}
2008
2009
2010static tANI_U32 csrGetBssPreferValue(tpAniSirGlobal pMac, int rssi)
2011{
2012 tANI_U32 ret = 0;
2013 int i = CSR_NUM_RSSI_CAT - 1;
2014
2015 while(i >= 0)
2016 {
2017 if(rssi >= pMac->roam.configParam.RSSICat[i])
2018 {
2019 ret = pMac->roam.configParam.BssPreferValue[i];
2020 break;
2021 }
2022 i--;
2023 };
2024
2025 return (ret);
2026}
2027
2028
2029//Return a CapValue base on the capabilities of a BSS
2030static tANI_U32 csrGetBssCapValue(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes)
2031{
2032 tANI_U32 ret = CSR_BSS_CAP_VALUE_NONE;
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08002033#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_ESE) || defined(FEATURE_WLAN_LFR)
Madan Mohan Koyyalamudid5026072012-11-30 14:56:21 -08002034 if(CSR_IS_ROAM_PREFER_5GHZ(pMac))
2035 {
2036 if((pBssDesc) && CSR_IS_CHANNEL_5GHZ(pBssDesc->channelId))
2037 {
2038 ret += CSR_BSS_CAP_VALUE_5GHZ;
2039 }
2040 }
2041#endif
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002042 /* if strict select 5GHz is non-zero then ignore the capability checking */
2043 if (pIes && !CSR_IS_SELECT_5GHZ_MARGIN(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -07002044 {
2045 //We only care about 11N capability
2046 if(pIes->HTCaps.present)
2047 {
2048 ret += CSR_BSS_CAP_VALUE_HT;
2049 }
2050 if(CSR_IS_QOS_BSS(pIes))
2051 {
2052 ret += CSR_BSS_CAP_VALUE_WMM;
2053 //Give advantage to UAPSD
2054 if(CSR_IS_UAPSD_BSS(pIes))
2055 {
2056 ret += CSR_BSS_CAP_VALUE_UAPSD;
2057 }
2058 }
2059 }
2060
2061 return (ret);
2062}
2063
Kapil Guptab3a981b2016-06-26 13:36:51 +05302064#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
2065
2066/* Calculate channel weight based on other APs RSSI and count for
2067 * PER based roaming */
2068static tANI_U32 GetPERRoamRssiCountWeight(tANI_S32 rssi, tANI_S32 count)
2069{
2070 tANI_S32 rssiWeight=0;
2071 tANI_S32 countWeight=0;
2072 tANI_S32 rssicountWeight=0;
2073
2074 rssiWeight = ROAMING_RSSI_WEIGHT * (rssi - MIN_RSSI)
2075 /(MAX_RSSI - MIN_RSSI);
2076
2077 if(rssiWeight > ROAMING_RSSI_WEIGHT)
2078 rssiWeight = ROAMING_RSSI_WEIGHT;
2079 else if (rssiWeight < 0)
2080 rssiWeight = 0;
2081
2082 countWeight = ROAM_AP_COUNT_WEIGHT * (count + ROAM_MIN_COUNT)
2083 /(ROAM_MAX_COUNT + ROAM_MIN_COUNT);
2084
2085 if(countWeight > ROAM_AP_COUNT_WEIGHT)
2086 countWeight = ROAM_AP_COUNT_WEIGHT;
2087
2088 rssicountWeight = ROAM_MAX_WEIGHT - (rssiWeight + countWeight);
2089
2090 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO_HIGH,
2091 FL("rssiWeight=%d, countWeight=%d, rssicountWeight=%d rssi=%d count=%d"),
2092 rssiWeight, countWeight, rssicountWeight, rssi, count);
2093
2094 return rssicountWeight;
2095}
2096
2097/* Calculate BSS score based on AP capabilty and channel condition
2098 * for PER based roaming */
2099static tANI_U32 calculateBssScore(tSirBssDescription *bssInfo,
2100 tANI_S32 best_rssi, tANI_S32 ap_cnt, tANI_S32 cca)
2101{
2102 tANI_S32 score = 0;
2103 tANI_S32 ap_load = 0;
2104 tANI_S32 normalised_width = PER_ROAM_20MHZ;
Sen, Devendra6940d0c2016-09-07 12:42:46 +05302105 tANI_S32 normalised_rssi = 0;
Kapil Guptab3a981b2016-06-26 13:36:51 +05302106 tANI_S32 channel_weight;
2107 if (bssInfo->rssi) {
2108 /* Calculate % of rssi we are getting
2109 * max = 100
2110 * min = 0
2111 * less than -40 = 100%
2112 * -40 - -55 = 80%
2113 * -55 - -65 = 60%
2114 * below that = 100 - value
2115 * TODO: a linear decrement function after PER_ROAM_GOOD_RSSI_WEIGHT
2116 * since throughput decrements linearly after PER_ROAM_GOOD_RSSI_WEIGHT
2117 **/
2118 if (bssInfo->rssi >= PER_EXCELENT_RSSI)
2119 normalised_rssi = PER_ROAM_EXCELLENT_RSSI_WEIGHT;
2120 else if (bssInfo->rssi >= PER_GOOD_RSSI)
2121 normalised_rssi = PER_ROAM_GOOD_RSSI_WEIGHT;
2122 else if (bssInfo->rssi >= PER_POOR_RSSI)
2123 normalised_rssi = PER_ROAM_BAD_RSSI_WEIGHT;
2124 else
2125 normalised_rssi = bssInfo->rssi - MIN_RSSI;
2126
2127 /* Calculate score part for rssi */
2128 score += (normalised_rssi * RSSI_WEIGHTAGE);
2129 }
2130
2131 if (bssInfo->HTCapsPresent) {
2132 score += PER_ROAM_MAX_WEIGHT * HT_CAPABILITY_WEIGHTAGE;
2133 }
2134 /* VHT caps are available */
2135 if (bssInfo->vhtCapsPresent) {
2136 score += PER_ROAM_MAX_WEIGHT * VHT_CAP_WEIGHTAGE;
2137 }
2138
2139 if (bssInfo->beacomformingCapable)
2140 score += PER_ROAM_MAX_WEIGHT * BEAMFORMING_CAP_WEIGHTAGE;
2141
2142 /* Channel width 20Mhz=30, 40Mhz=70, 80Mhz=100 */
2143 if (bssInfo->chanWidth == eHT_CHANNEL_WIDTH_80MHZ)
2144 normalised_width = PER_ROAM_80MHZ;
2145 else if (bssInfo->chanWidth == eHT_CHANNEL_WIDTH_40MHZ)
2146 normalised_width = PER_ROAM_40MHZ;
2147 else
2148 normalised_width = PER_ROAM_20MHZ;
2149 score += normalised_width * CHAN_WIDTH_WEIGHTAGE;
2150
2151 /* Channel Band, Channel Number */
2152 if (GetRFBand(bssInfo->channelId) == SIR_BAND_5_GHZ)
2153 score += PER_ROAM_MAX_WEIGHT * CHAN_BAND_WEIGHTAGE;
2154
2155 /* WMM emabled */
2156 if (bssInfo->wmeInfoPresent)
2157 score += PER_ROAM_MAX_WEIGHT * WMM_WEIGHTAGE;
2158
2159#if defined(FEATURE_WLAN_ESE) || defined(WLAN_FEATURE_ROAM_SCAN_OFFLOAD)
2160 /* AP load Ie */
2161 if (bssInfo->QBSSLoad_present) {
2162 /* calculate value in % */
2163 ap_load = (bssInfo->QBSS_ChanLoad * PER_ROAM_MAX_WEIGHT) / MAX_AP_LOAD;
2164 }
2165#endif
Kapil Guptab3a981b2016-06-26 13:36:51 +05302166 /* if CCA consideration is off in configuration, FW will send 50% for
2167 every channel which should be considered as it is */
2168 if (ap_load)
2169 score += (100 - ap_load) * CCA_WEIGHTAGE;
2170 else
2171 score += (100 - cca) * CCA_WEIGHTAGE;
2172
2173 channel_weight = GetPERRoamRssiCountWeight(best_rssi, ap_cnt);
2174
2175 score += channel_weight * OTHER_AP_WEIGHT;
2176
2177 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO_LOW,
2178 FL("rssi=%d normalized_rssi=%d htcaps=%d vht=%d bw=%d channel=%d wmm=%d beamforming=%d ap_load=%d channel_weight=%d"),
2179 bssInfo->rssi, normalised_rssi, bssInfo->HTCapsPresent,
2180 bssInfo->vhtCapsPresent, bssInfo->chanWidth,
2181 bssInfo->channelId, bssInfo->wmeInfoPresent,
2182 bssInfo->beacomformingCapable, ap_load, channel_weight);
2183 return score;
2184}
2185
2186/* Calculate candidate AP score for PER based roaming */
2187static tANI_S32 csrFindCongestionScore (tpAniSirGlobal pMac, tCsrScanResult *pBss)
2188{
2189 tANI_S32 score = 0;
2190 tANI_S32 i;
2191 tANI_S32 candidateApCnt, best_rssi, other_ap_cnt;
2192 tANI_U32 current_timestamp;
2193 tpCsrNeighborRoamControlInfo pNeighborRoamInfo =
2194 &pMac->roam.neighborRoamInfo;
2195
2196 tSirBssDescription *bssInfo = &(pBss->Result.BssDescriptor);
2197 pBss->congestionScore = 0;
2198 for (i = 0; i < pMac->PERroamCandidatesCnt; i++)
2199 if (pMac->candidateChannelInfo[i].channelNumber ==
2200 pBss->Result.BssDescriptor.channelId)
2201 break;
2202
2203 if (i == SIR_PER_ROAM_MAX_CANDIDATE_CNT) {
2204 smsLog(pMac, LOGE,
2205 FL("candidate chan info not found for channel %d bssid "
2206 MAC_ADDRESS_STR), pBss->Result.BssDescriptor.channelId,
2207 MAC_ADDR_ARRAY(pBss->Result.BssDescriptor.bssId));
2208 return -1;
2209 }
2210
Kapil Guptaa040e772016-09-15 19:03:45 +05302211 if (bssInfo->rssi < PER_BAD_RSSI) {
2212 smsLog(pMac, LOG1,
2213 FL("discrarding candidate due to low rssi=%d bssid "
2214 MAC_ADDRESS_STR), bssInfo->rssi,
2215 MAC_ADDR_ARRAY(pBss->Result.BssDescriptor.bssId));
2216 return 0;
2217 }
Kapil Guptab3a981b2016-06-26 13:36:51 +05302218 /* find best RSSI of other AP in this channel */
2219 best_rssi = MIN_RSSI;
2220 for (other_ap_cnt = 0; other_ap_cnt <
2221 pMac->candidateChannelInfo[i].otherApCount; other_ap_cnt++) {
2222 if (pMac->candidateChannelInfo[i].otherApRssi[other_ap_cnt] > best_rssi)
2223 best_rssi = pMac->candidateChannelInfo[i].otherApRssi[other_ap_cnt];
2224 }
2225
2226 score = calculateBssScore(bssInfo, best_rssi,
2227 pMac->candidateChannelInfo[i].otherApCount,
2228 pMac->candidateChannelInfo[i].channelCCA);
2229 current_timestamp = jiffies_to_msecs(jiffies);
2230
2231 /* penalty logic */
2232
2233 /* In the previous list */
2234 for (candidateApCnt = 0; candidateApCnt <
2235 SIR_PER_ROAM_MAX_CANDIDATE_CNT; candidateApCnt++) {
2236 if (sirCompareMacAddr(pMac->previousRoamApInfo[candidateApCnt].bssAddr,
2237 pBss->Result.BssDescriptor.bssId) &&
2238 ((current_timestamp - pMac->previousRoamApInfo[candidateApCnt].timeStamp) <
2239 PENALTY_TIMEOUT)) {
2240 score = (score * PENALTY_REMAINING_SCORE)/PENALTY_TOTAL_SCORE;
2241 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
2242 FL("AP BSSID " MAC_ADDRESS_STR "adding penalty(in previous list)new score %d"),
2243 MAC_ADDR_ARRAY(pBss->Result.BssDescriptor.bssId),
2244 score);
2245 break;
2246 }
2247 }
2248 /* preauth failed last time */
2249 for (candidateApCnt = 0; candidateApCnt <
2250 MAX_NUM_PREAUTH_FAIL_LIST_ADDRESS; candidateApCnt++) {
2251 if (sirCompareMacAddr(pNeighborRoamInfo->FTRoamInfo.
2252 preAuthFailList.macAddress[candidateApCnt],
2253 pBss->Result.BssDescriptor.bssId)) {
2254 score = (score * PENALTY_REMAINING_SCORE)/PENALTY_TOTAL_SCORE;
2255 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
2256 FL("AP BSSID " MAC_ADDRESS_STR "adding penalty(previously auth failed)new score %d"),
2257 MAC_ADDR_ARRAY(pBss->Result.BssDescriptor.bssId),
2258 score);
2259 break;
2260 }
2261 }
2262 pBss->congestionScore = score;
2263
2264 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
2265 FL("AP BSSID " MAC_ADDRESS_STR " score %d channel %d"),
2266 MAC_ADDR_ARRAY(pBss->Result.BssDescriptor.bssId),
2267 score, pBss->Result.BssDescriptor.channelId);
2268 return 0;
2269}
2270
2271/* Calculate current AP score for PER based roaming */
2272static tANI_S32 csrFindSelfCongestionScore(tpAniSirGlobal pMac,
2273 tSirBssDescription *bssInfo)
2274{
2275 tANI_S32 i, best_rssi, other_ap_cnt;
2276 tANI_S32 score = 0;
Kapil Guptac6ac4772016-08-05 20:25:16 +05302277 tCsrRoamSession *pSession = CSR_GET_SESSION(pMac,
2278 pMac->roam.roamSession->sessionId);
2279
2280 if (pSession == NULL)
2281 return -1;
Kapil Guptab3a981b2016-06-26 13:36:51 +05302282
2283 for (i = 0; i <= pMac->PERroamCandidatesCnt; i++)
2284 if (pMac->candidateChannelInfo[i].channelNumber == bssInfo->channelId)
2285 break;
2286 if (i > pMac->PERroamCandidatesCnt) {
2287 /* home channel info is not present, no need to roam */
2288 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR,
2289 FL("home channel %d congestion info not present"),
2290 bssInfo->channelId);
2291 pMac->currentBssScore = PER_ROAM_MAX_BSS_SCORE;
2292 return -1;
2293 }
2294
2295 /* find best RSSI of other AP in this channel */
2296 best_rssi = MIN_RSSI;
2297 for (other_ap_cnt = 0; other_ap_cnt <
2298 pMac->candidateChannelInfo[i].otherApCount; other_ap_cnt++) {
2299 if (pMac->candidateChannelInfo[i].otherApRssi[other_ap_cnt] > best_rssi)
2300 best_rssi = pMac->candidateChannelInfo[i].otherApRssi[other_ap_cnt];
2301 }
2302
Kapil Guptac6ac4772016-08-05 20:25:16 +05302303 /* update latest RSSI for current AP */
2304 WLANTL_GetRssi(vos_get_global_context(VOS_MODULE_ID_SME, NULL),
2305 pSession->connectedInfo.staId,
2306 &bssInfo->rssi);
2307
Kapil Guptab3a981b2016-06-26 13:36:51 +05302308 score = calculateBssScore(bssInfo, best_rssi,
2309 pMac->candidateChannelInfo[i].otherApCount,
2310 pMac->candidateChannelInfo[i].channelCCA);
2311 pMac->currentBssScore = score;
2312 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
2313 FL("PER Roam Current AP score %d channel %d"),
2314 score, bssInfo->channelId);
2315 return 0;
2316}
2317
Kapil Guptab79e76f2016-09-12 20:04:37 +05302318
Kapil Guptab3a981b2016-06-26 13:36:51 +05302319static tANI_BOOLEAN csrIsBetterBssInCongestion(tCsrScanResult *pBss1,
2320 tCsrScanResult *pBss2)
2321{
2322 tANI_BOOLEAN ret;
2323
2324 if(CSR_IS_BETTER_PREFER_VALUE(pBss1->congestionScore,
2325 pBss2->congestionScore))
2326 ret = eANI_BOOLEAN_TRUE;
2327 else
2328 ret = eANI_BOOLEAN_FALSE;
2329
2330 return (ret);
2331}
2332#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002333
2334//To check whther pBss1 is better than pBss2
2335static tANI_BOOLEAN csrIsBetterBss(tCsrScanResult *pBss1, tCsrScanResult *pBss2)
2336{
2337 tANI_BOOLEAN ret;
2338
2339 if(CSR_IS_BETTER_PREFER_VALUE(pBss1->preferValue, pBss2->preferValue))
2340 {
2341 ret = eANI_BOOLEAN_TRUE;
2342 }
2343 else if(CSR_IS_EQUAL_PREFER_VALUE(pBss1->preferValue, pBss2->preferValue))
2344 {
2345 if(CSR_IS_BETTER_CAP_VALUE(pBss1->capValue, pBss2->capValue))
2346 {
2347 ret = eANI_BOOLEAN_TRUE;
2348 }
2349 else
2350 {
2351 ret = eANI_BOOLEAN_FALSE;
2352 }
2353 }
2354 else
2355 {
2356 ret = eANI_BOOLEAN_FALSE;
2357 }
2358
2359 return (ret);
2360}
2361
2362
Srikant Kuppa866893f2012-12-27 17:28:14 -08002363#ifdef FEATURE_WLAN_LFR
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002364//Add the channel to the occupiedChannels array
2365static void csrScanAddToOccupiedChannels(
Srikant Kuppa866893f2012-12-27 17:28:14 -08002366 tpAniSirGlobal pMac,
2367 tCsrScanResult *pResult,
2368 tCsrChannel *pOccupiedChannels,
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002369 tDot11fBeaconIEs *pIes)
2370{
2371 eHalStatus status;
2372 tANI_U8 channel;
2373 tANI_U8 numOccupiedChannels = pOccupiedChannels->numChannels;
2374 tANI_U8 *pOccupiedChannelList = pOccupiedChannels->channelList;
2375
2376 channel = pResult->Result.BssDescriptor.channelId;
2377
2378 if (!csrIsChannelPresentInList(pOccupiedChannelList, numOccupiedChannels, channel)
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08002379 && csrNeighborRoamConnectedProfileMatch(pMac, pResult, pIes))
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002380 {
Srikant Kuppa866893f2012-12-27 17:28:14 -08002381 status = csrAddToChannelListFront(pOccupiedChannelList, numOccupiedChannels, channel);
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002382 if(HAL_STATUS_SUCCESS(status))
Srikant Kuppa866893f2012-12-27 17:28:14 -08002383 {
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002384 pOccupiedChannels->numChannels++;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002385 smsLog(pMac, LOG2, FL("%s: added channel %d to the list (count=%d)"),
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08002386 __func__, channel, pOccupiedChannels->numChannels);
Srikant Kuppa866893f2012-12-27 17:28:14 -08002387 if (pOccupiedChannels->numChannels > CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN)
2388 pOccupiedChannels->numChannels = CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN;
2389 }
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002390 }
2391}
Mukul Sharma9e4e0f92015-02-13 18:45:20 +05302392
2393void csrAddChannelToOccupiedChannelList(tpAniSirGlobal pMac,
2394 tANI_U8 channel)
2395{
2396 eHalStatus status;
2397 tCsrChannel *pOccupiedChannels = &pMac->scan.occupiedChannels;
2398 tANI_U8 numOccupiedChannels = pOccupiedChannels->numChannels;
2399 tANI_U8 *pOccupiedChannelList = pOccupiedChannels->channelList;
2400 if (!csrIsChannelPresentInList(pOccupiedChannelList,
2401 numOccupiedChannels, channel))
2402 {
2403 status = csrAddToChannelListFront(pOccupiedChannelList,
2404 numOccupiedChannels, channel);
2405 if(HAL_STATUS_SUCCESS(status))
2406 {
2407 pOccupiedChannels->numChannels++;
2408 smsLog(pMac, LOG2, FL("added channel %d to the list (count=%d)"),
2409 channel, pOccupiedChannels->numChannels);
2410 if (pOccupiedChannels->numChannels >
2411 CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN)
2412 {
2413 pOccupiedChannels->numChannels =
2414 CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN;
2415 smsLog(pMac, LOG2,
2416 FL("trim no of Channels for Occ channel list"));
2417 }
2418 }
2419 }
2420}
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002421#endif
2422
Jeff Johnson295189b2012-06-20 16:38:30 -07002423//Put the BSS into the scan result list
2424//pIes can not be NULL
2425static void csrScanAddResult(tpAniSirGlobal pMac, tCsrScanResult *pResult, tDot11fBeaconIEs *pIes)
2426{
Srinivas28b5b4e2012-12-12 13:07:53 -08002427#ifdef FEATURE_WLAN_LFR
2428 tpCsrNeighborRoamControlInfo pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
2429#endif
2430
Jeff Johnson295189b2012-06-20 16:38:30 -07002431 pResult->preferValue = csrGetBssPreferValue(pMac, (int)pResult->Result.BssDescriptor.rssi);
2432 pResult->capValue = csrGetBssCapValue(pMac, &pResult->Result.BssDescriptor, pIes);
2433 csrLLInsertTail( &pMac->scan.scanResultList, &pResult->Link, LL_ACCESS_LOCK );
Srikant Kuppa866893f2012-12-27 17:28:14 -08002434#ifdef FEATURE_WLAN_LFR
Srinivas28b5b4e2012-12-12 13:07:53 -08002435 if(0 == pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels)
2436 {
2437 /* Build the occupied channel list, only if "gNeighborScanChannelList" is
2438 NOT set in the cfg.ini file */
2439 csrScanAddToOccupiedChannels(pMac, pResult, &pMac->scan.occupiedChannels, pIes);
2440 }
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002441#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002442}
2443
2444
2445eHalStatus csrScanGetResult(tpAniSirGlobal pMac, tCsrScanResultFilter *pFilter, tScanResultHandle *phResult)
2446{
2447 eHalStatus status;
2448 tScanResultList *pRetList;
2449 tCsrScanResult *pResult, *pBssDesc;
2450 tANI_U32 count = 0;
2451 tListElem *pEntry;
2452 tANI_U32 bssLen, allocLen;
2453 eCsrEncryptionType uc = eCSR_ENCRYPT_TYPE_NONE, mc = eCSR_ENCRYPT_TYPE_NONE;
2454 eCsrAuthType auth = eCSR_AUTH_TYPE_OPEN_SYSTEM;
2455 tDot11fBeaconIEs *pIes, *pNewIes;
2456 tANI_BOOLEAN fMatch;
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002457 tANI_U16 i = 0;
Kapil Guptab3a981b2016-06-26 13:36:51 +05302458 tCsrRoamSession *pSession = CSR_GET_SESSION(pMac,
2459 pMac->roam.roamSession->sessionId);
2460
Jeff Johnson295189b2012-06-20 16:38:30 -07002461 if(phResult)
2462 {
2463 *phResult = CSR_INVALID_SCANRESULT_HANDLE;
2464 }
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002465
2466 if (pMac->roam.configParam.nSelect5GHzMargin)
2467 {
2468 pMac->scan.inScanResultBestAPRssi = -128;
2469 csrLLLock(&pMac->scan.scanResultList);
2470
2471 /* Find out the best AP Rssi going thru the scan results */
2472 pEntry = csrLLPeekHead(&pMac->scan.scanResultList, LL_ACCESS_NOLOCK);
2473 while ( NULL != pEntry)
2474 {
2475 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002476 fMatch = FALSE;
2477
2478 if (pFilter)
2479 for(i = 0; i < pFilter->SSIDs.numOfSSIDs; i++)
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002480 {
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002481 fMatch = csrIsSsidMatch( pMac, pFilter->SSIDs.SSIDList[i].SSID.ssId, pFilter->SSIDs.SSIDList[i].SSID.length,
2482 pBssDesc->Result.ssId.ssId,
2483 pBssDesc->Result.ssId.length, eANI_BOOLEAN_TRUE );
2484 if (fMatch)
2485 {
2486 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
2487
2488 //At this time, pBssDescription->Result.pvIes may be NULL
2489 if( !pIes && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
2490 &pBssDesc->Result.BssDescriptor, &pIes))) )
2491 {
2492 continue;
2493 }
2494
2495 smsLog(pMac, LOG1, FL("SSID Matched"));
Leela Venkata Kiran Kumar Reddy Chiralae208a832014-04-27 22:34:25 -07002496
Leela Venkata Kiran Kumar Reddy Chiralaf257bef2014-04-11 18:48:12 -07002497 if ( pFilter->bOSENAssociation )
2498 {
2499 fMatch = TRUE;
2500 }
Leela Venkata Kiran Kumar Reddy Chiralae208a832014-04-27 22:34:25 -07002501 else
2502 {
Abhishek Singh658d4de2014-06-26 10:53:15 +05302503#ifdef WLAN_FEATURE_11W
Abhishek Singh3b56d3a2014-06-25 12:37:39 +05302504 fMatch = csrIsSecurityMatch(pMac, &pFilter->authType,
2505 &pFilter->EncryptionType,
2506 &pFilter->mcEncryptionType,
2507 &pFilter->MFPEnabled,
2508 &pFilter->MFPRequired,
2509 &pFilter->MFPCapable,
2510 &pBssDesc->Result.BssDescriptor,
2511 pIes, NULL, NULL, NULL );
Abhishek Singh658d4de2014-06-26 10:53:15 +05302512#else
2513 fMatch = csrIsSecurityMatch(pMac, &pFilter->authType,
2514 &pFilter->EncryptionType,
2515 &pFilter->mcEncryptionType,
2516 NULL, NULL, NULL,
2517 &pBssDesc->Result.BssDescriptor,
2518 pIes, NULL, NULL, NULL );
2519#endif
Leela Venkata Kiran Kumar Reddy Chiralae208a832014-04-27 22:34:25 -07002520 }
2521 if ((pBssDesc->Result.pvIes == NULL) && pIes)
2522 vos_mem_free(pIes);
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002523
2524 if (fMatch)
2525 smsLog(pMac, LOG1, FL(" Security Matched"));
2526 }
2527 }
2528
2529 if (fMatch && (pBssDesc->Result.BssDescriptor.rssi > pMac->scan.inScanResultBestAPRssi))
2530 {
2531 smsLog(pMac, LOG1, FL("Best AP Rssi changed from %d to %d"),
2532 pMac->scan.inScanResultBestAPRssi,
2533 pBssDesc->Result.BssDescriptor.rssi);
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002534 pMac->scan.inScanResultBestAPRssi = pBssDesc->Result.BssDescriptor.rssi;
2535 }
2536 pEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
2537 }
2538
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002539 if ( -128 != pMac->scan.inScanResultBestAPRssi)
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002540 {
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002541 smsLog(pMac, LOG1, FL("Best AP Rssi is %d"), pMac->scan.inScanResultBestAPRssi);
2542 /* Modify Rssi category based on best AP Rssi */
2543 csrAssignRssiForCategory(pMac, pMac->scan.inScanResultBestAPRssi, pMac->roam.configParam.bCatRssiOffset);
2544 pEntry = csrLLPeekHead(&pMac->scan.scanResultList, LL_ACCESS_NOLOCK);
2545 while ( NULL != pEntry)
2546 {
2547 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002548
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002549 /* re-assign preference value based on modified rssi bucket */
2550 pBssDesc->preferValue = csrGetBssPreferValue(pMac, (int)pBssDesc->Result.BssDescriptor.rssi);
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002551
Arif Hussaina7c8e412013-11-20 11:06:42 -08002552 smsLog(pMac, LOG2, FL("BSSID("MAC_ADDRESS_STR
Jeff Johnson123ed002013-11-22 17:39:55 -08002553 ") Rssi(%d) Chnl(%d) PrefVal(%u) SSID=%.*s"),
Arif Hussaina7c8e412013-11-20 11:06:42 -08002554 MAC_ADDR_ARRAY(pBssDesc->Result.BssDescriptor.bssId),
2555 pBssDesc->Result.BssDescriptor.rssi,
2556 pBssDesc->Result.BssDescriptor.channelId,
2557 pBssDesc->preferValue,
2558 pBssDesc->Result.ssId.length, pBssDesc->Result.ssId.ssId);
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002559
2560 pEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
2561 }
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002562 }
2563
2564 csrLLUnlock(&pMac->scan.scanResultList);
2565 }
2566
Kiet Lam64c1b492013-07-12 13:56:44 +05302567 pRetList = vos_mem_malloc(sizeof(tScanResultList));
2568 if ( NULL == pRetList )
2569 status = eHAL_STATUS_FAILURE;
2570 else
2571 status = eHAL_STATUS_SUCCESS;
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002572 if(HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07002573 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302574 vos_mem_set(pRetList, sizeof(tScanResultList), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002575 csrLLOpen(pMac->hHdd, &pRetList->List);
2576 pRetList->pCurEntry = NULL;
Kapil Guptab3a981b2016-06-26 13:36:51 +05302577#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
2578 if (pFilter && pFilter->isPERRoamScan)
2579 if (pSession && pSession->pConnectBssDesc)
2580 csrFindSelfCongestionScore(pMac,
2581 pSession->pConnectBssDesc);
2582#endif
2583
Jeff Johnson295189b2012-06-20 16:38:30 -07002584 csrLLLock(&pMac->scan.scanResultList);
2585 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
2586 while( pEntry )
2587 {
2588 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2589 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
2590 //if pBssDesc->Result.pvIes is NULL, we need to free any memory allocated by csrMatchBSS
2591 //for any error condition, otherwiase, it will be freed later.
2592 //reset
2593 fMatch = eANI_BOOLEAN_FALSE;
2594 pNewIes = NULL;
2595
2596 if(pFilter)
2597 {
2598 fMatch = csrMatchBSS(pMac, &pBssDesc->Result.BssDescriptor, pFilter, &auth, &uc, &mc, &pIes);
2599 if( NULL != pIes )
2600 {
2601 //Only save it when matching
2602 if(fMatch)
2603 {
2604 if( !pBssDesc->Result.pvIes )
2605 {
2606 //csrMatchBSS allocates the memory. Simply pass it and it is freed later
2607 pNewIes = pIes;
2608 }
2609 else
2610 {
2611 //The pIes is allocated by someone else. make a copy
2612 //Only to save parsed IEs if caller provides a filter. Most likely the caller
2613 //is using to for association, hence save the parsed IEs
Kiet Lam64c1b492013-07-12 13:56:44 +05302614 pNewIes = vos_mem_malloc(sizeof(tDot11fBeaconIEs));
2615 if ( NULL == pNewIes )
2616 status = eHAL_STATUS_FAILURE;
2617 else
2618 status = eHAL_STATUS_SUCCESS;
2619 if ( HAL_STATUS_SUCCESS( status ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07002620 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302621 vos_mem_copy(pNewIes, pIes, sizeof( tDot11fBeaconIEs ));
Jeff Johnson295189b2012-06-20 16:38:30 -07002622 }
2623 else
2624 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002625 smsLog(pMac, LOGE, FL(" fail to allocate memory for IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002626 //Need to free memory allocated by csrMatchBSS
2627 if( !pBssDesc->Result.pvIes )
2628 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302629 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07002630 }
2631 break;
2632 }
2633 }
2634 }//fMatch
2635 else if( !pBssDesc->Result.pvIes )
2636 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302637 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07002638 }
2639 }
2640 }
2641 if(NULL == pFilter || fMatch)
2642 {
2643 bssLen = pBssDesc->Result.BssDescriptor.length + sizeof(pBssDesc->Result.BssDescriptor.length);
2644 allocLen = sizeof( tCsrScanResult ) + bssLen;
Kiet Lam64c1b492013-07-12 13:56:44 +05302645 pResult = vos_mem_malloc(allocLen);
2646 if ( NULL == pResult )
2647 status = eHAL_STATUS_FAILURE;
2648 else
2649 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07002650 if(!HAL_STATUS_SUCCESS(status))
2651 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002652 smsLog(pMac, LOGE, FL(" fail to allocate memory for scan result, len=%d"), allocLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07002653 if(pNewIes)
2654 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302655 vos_mem_free(pNewIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07002656 }
2657 break;
2658 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302659 vos_mem_set(pResult, allocLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002660 pResult->capValue = pBssDesc->capValue;
2661 pResult->preferValue = pBssDesc->preferValue;
2662 pResult->ucEncryptionType = uc;
2663 pResult->mcEncryptionType = mc;
2664 pResult->authType = auth;
2665 pResult->Result.ssId = pBssDesc->Result.ssId;
Padma, Santhosh Kumare12fd982016-03-21 13:07:52 +05302666 pResult->Result.timer = pBssDesc->Result.timer;
Jeff Johnson295189b2012-06-20 16:38:30 -07002667 //save the pIes for later use
2668 pResult->Result.pvIes = pNewIes;
2669 //save bss description
Kiet Lam64c1b492013-07-12 13:56:44 +05302670 vos_mem_copy(&pResult->Result.BssDescriptor,
2671 &pBssDesc->Result.BssDescriptor, bssLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07002672 //No need to lock pRetList because it is locally allocated and no outside can access it at this time
2673 if(csrLLIsListEmpty(&pRetList->List, LL_ACCESS_NOLOCK))
2674 {
Kapil Guptab3a981b2016-06-26 13:36:51 +05302675#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
2676 if (pFilter && pFilter->isPERRoamScan) {
2677 csrFindCongestionScore(pMac, pResult);
2678 if (pResult->congestionScore > pMac->currentBssScore) {
2679 csrLLInsertTail(&pRetList->List, &pResult->Link,
2680 LL_ACCESS_NOLOCK);
2681 smsLog(pMac, LOGW,
2682 FL("added one entry in LL in PER Roam list"));
2683 }
2684 }
2685 else
2686#endif
2687 {
2688 csrLLInsertTail(&pRetList->List, &pResult->Link,
2689 LL_ACCESS_NOLOCK);
2690 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002691 }
2692 else
2693 {
2694 //To sort the list
2695 tListElem *pTmpEntry;
2696 tCsrScanResult *pTmpResult;
2697
2698 pTmpEntry = csrLLPeekHead(&pRetList->List, LL_ACCESS_NOLOCK);
2699 while(pTmpEntry)
2700 {
2701 pTmpResult = GET_BASE_ADDR( pTmpEntry, tCsrScanResult, Link );
Kapil Guptab3a981b2016-06-26 13:36:51 +05302702#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
2703 if (pFilter && pFilter->isPERRoamScan) {
2704 csrFindCongestionScore(pMac, pResult);
2705 if(csrIsBetterBssInCongestion(pResult, pTmpResult)&&
2706 (pResult->congestionScore > pMac->currentBssScore))
2707 {
2708 csrLLInsertEntry(&pRetList->List, pTmpEntry,
2709 &pResult->Link, LL_ACCESS_NOLOCK);
2710 smsLog(pMac, LOGW,
2711 FL("added another entry in LL in PER Roam list"));
2712 pResult = NULL;
2713 break;
2714 }
2715 pTmpEntry = csrLLNext(&pRetList->List,
2716 pTmpEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07002717 }
Kapil Guptab3a981b2016-06-26 13:36:51 +05302718 else
2719#endif
2720 {
2721 if(csrIsBetterBss(pResult, pTmpResult))
2722 {
2723 csrLLInsertEntry(&pRetList->List, pTmpEntry,
2724 &pResult->Link, LL_ACCESS_NOLOCK);
2725 //To indicate we are done
2726 pResult = NULL;
2727 break;
2728 }
2729 pTmpEntry = csrLLNext(&pRetList->List,
2730 pTmpEntry, LL_ACCESS_NOLOCK);
2731 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002732 }
2733 if(pResult != NULL)
Kapil Guptab3a981b2016-06-26 13:36:51 +05302734#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
2735 if ((pFilter && !pFilter->isPERRoamScan) ||
2736 (pFilter == NULL) ||
2737 (pResult->congestionScore > pMac->currentBssScore))
2738#endif
2739 {
2740 //This one is not better than any one
2741 csrLLInsertTail(&pRetList->List,
2742 &pResult->Link, LL_ACCESS_NOLOCK);
2743 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002744 }
2745 count++;
2746 }
2747 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK );
2748 }//while
2749 csrLLUnlock(&pMac->scan.scanResultList);
2750
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002751 smsLog(pMac, LOG2, FL("return %d BSS"), csrLLCount(&pRetList->List));
Jeff Johnson295189b2012-06-20 16:38:30 -07002752
2753 if( !HAL_STATUS_SUCCESS(status) || (phResult == NULL) )
2754 {
2755 //Fail or No one wants the result.
2756 csrScanResultPurge(pMac, (tScanResultHandle)pRetList);
2757 }
2758 else
2759 {
2760 if(0 == count)
2761 {
2762 //We are here meaning the there is no match
2763 csrLLClose(&pRetList->List);
Kiet Lam64c1b492013-07-12 13:56:44 +05302764 vos_mem_free(pRetList);
Jeff Johnson295189b2012-06-20 16:38:30 -07002765 status = eHAL_STATUS_E_NULL_VALUE;
Kapil Guptab3a981b2016-06-26 13:36:51 +05302766 smsLog(pMac, LOGW,
2767 FL("Nil scan results or no matching AP found"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002768 }
2769 else if(phResult)
2770 {
2771 *phResult = pRetList;
2772 }
2773 }
2774 }//Allocated pRetList
2775
2776 return (status);
2777}
2778
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002779/*
2780 * NOTE: This routine is being added to make
2781 * sure that scan results are not being flushed
2782 * while roaming. If the scan results are flushed,
2783 * we are unable to recover from
2784 * csrRoamRoamingStateDisassocRspProcessor.
2785 * If it is needed to remove this routine,
2786 * first ensure that we recover gracefully from
2787 * csrRoamRoamingStateDisassocRspProcessor if
2788 * csrScanGetResult returns with a failure because
2789 * of not being able to find the roaming BSS.
2790 */
2791tANI_U8 csrScanFlushDenied(tpAniSirGlobal pMac)
2792{
2793 switch(pMac->roam.neighborRoamInfo.neighborRoamState) {
2794 case eCSR_NEIGHBOR_ROAM_STATE_REPORT_SCAN:
2795 case eCSR_NEIGHBOR_ROAM_STATE_PREAUTHENTICATING:
2796 case eCSR_NEIGHBOR_ROAM_STATE_PREAUTH_DONE:
2797 case eCSR_NEIGHBOR_ROAM_STATE_REASSOCIATING:
2798 return (pMac->roam.neighborRoamInfo.neighborRoamState);
2799 default:
2800 return 0;
2801 }
2802}
2803
Jeff Johnson295189b2012-06-20 16:38:30 -07002804eHalStatus csrScanFlushResult(tpAniSirGlobal pMac)
2805{
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002806 tANI_U8 isFlushDenied = csrScanFlushDenied(pMac);
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302807 eHalStatus status = eHAL_STATUS_SUCCESS;
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002808 if (isFlushDenied) {
2809 smsLog(pMac, LOGW, "%s: scan flush denied in roam state %d",
2810 __func__, isFlushDenied);
2811 return eHAL_STATUS_FAILURE;
2812 }
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302813 csrLLScanPurgeResult( pMac, &pMac->scan.tempScanResults );
2814 csrLLScanPurgeResult( pMac, &pMac->scan.scanResultList );
2815 return( status );
Jeff Johnson295189b2012-06-20 16:38:30 -07002816}
2817
Mukul Sharma20aa6582014-08-07 21:36:12 +05302818eHalStatus csrScanFlushSelectiveResultForBand(tpAniSirGlobal pMac, v_BOOL_t flushP2P, tSirRFBand band)
2819{
2820 eHalStatus status = eHAL_STATUS_SUCCESS;
2821 tListElem *pEntry,*pFreeElem;
2822 tCsrScanResult *pBssDesc;
2823 tDblLinkList *pList = &pMac->scan.scanResultList;
2824
2825 csrLLLock(pList);
2826
2827 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)) &&
2833 (GetRFBand(pBssDesc->Result.BssDescriptor.channelId) == band)
2834 )
2835 {
2836 pFreeElem = pEntry;
2837 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2838 csrLLRemoveEntry(pList, pFreeElem, LL_ACCESS_NOLOCK);
2839 csrFreeScanResultEntry( pMac, pBssDesc );
2840 continue;
2841 }
2842 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2843 }
2844
2845 csrLLUnlock(pList);
2846
2847 return (status);
2848}
2849
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302850eHalStatus csrScanFlushSelectiveResult(tpAniSirGlobal pMac, v_BOOL_t flushP2P)
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002851{
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302852 eHalStatus status = eHAL_STATUS_SUCCESS;
2853 tListElem *pEntry,*pFreeElem;
2854 tCsrScanResult *pBssDesc;
2855 tDblLinkList *pList = &pMac->scan.scanResultList;
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002856
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302857 csrLLLock(pList);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002858
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302859 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK );
2860 while( pEntry != NULL)
2861 {
2862 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2863 if( flushP2P == vos_mem_compare( pBssDesc->Result.ssId.ssId,
2864 "DIRECT-", 7) )
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002865 {
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302866 pFreeElem = pEntry;
2867 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2868 csrLLRemoveEntry(pList, pFreeElem, LL_ACCESS_NOLOCK);
2869 csrFreeScanResultEntry( pMac, pBssDesc );
2870 continue;
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002871 }
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302872 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2873 }
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002874
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302875 csrLLUnlock(pList);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002876
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302877 return (status);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002878}
2879
Jeff Johnson295189b2012-06-20 16:38:30 -07002880/**
2881 * csrCheck11dChannel
2882 *
2883 *FUNCTION:
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302884 * This function is called from csrScanFilterResults function and
Jeff Johnson295189b2012-06-20 16:38:30 -07002885 * compare channel number with given channel list.
2886 *
2887 *LOGIC:
2888 * Check Scan result channel number with CFG channel list
2889 *
2890 *ASSUMPTIONS:
2891 *
2892 *
2893 *NOTE:
2894 *
2895 * @param channelId channel number
2896 * @param pChannelList Pointer to channel list
2897 * @param numChannels Number of channel in channel list
2898 *
2899 * @return Status
2900 */
2901
2902eHalStatus csrCheck11dChannel(tANI_U8 channelId, tANI_U8 *pChannelList, tANI_U32 numChannels)
2903{
2904 eHalStatus status = eHAL_STATUS_FAILURE;
2905 tANI_U8 i = 0;
2906
2907 for (i = 0; i < numChannels; i++)
2908 {
2909 if(pChannelList[ i ] == channelId)
2910 {
2911 status = eHAL_STATUS_SUCCESS;
2912 break;
2913 }
2914 }
2915 return status;
2916}
2917
2918/**
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302919 * csrScanFilterResults
Jeff Johnson295189b2012-06-20 16:38:30 -07002920 *
2921 *FUNCTION:
2922 * This function is called from csrApplyCountryInformation function and
2923 * filter scan result based on valid channel list number.
2924 *
2925 *LOGIC:
2926 * Get scan result from scan list and Check Scan result channel number
2927 * with 11d channel list if channel number is found in 11d channel list
2928 * then do not remove scan result entry from scan list
2929 *
2930 *ASSUMPTIONS:
2931 *
2932 *
2933 *NOTE:
2934 *
2935 * @param pMac Pointer to Global MAC structure
2936 *
2937 * @return Status
2938 */
2939
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302940eHalStatus csrScanFilterResults(tpAniSirGlobal pMac)
Jeff Johnson295189b2012-06-20 16:38:30 -07002941{
2942 eHalStatus status = eHAL_STATUS_SUCCESS;
2943 tListElem *pEntry,*pTempEntry;
2944 tCsrScanResult *pBssDesc;
2945 tANI_U32 len = sizeof(pMac->roam.validChannelList);
2946
2947 /* Get valid channels list from CFG */
2948 if (!HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac,
2949 pMac->roam.validChannelList, &len)))
2950 {
Agarwal Ashishe3cca2a2013-07-21 03:01:48 +05302951 smsLog( pMac, LOGE, "Failed to get Channel list from CFG");
Jeff Johnson295189b2012-06-20 16:38:30 -07002952 }
2953
2954 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
2955 while( pEntry )
2956 {
2957 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302958 pTempEntry = csrLLNext( &pMac->scan.scanResultList, pEntry,
Jeff Johnson295189b2012-06-20 16:38:30 -07002959 LL_ACCESS_LOCK );
2960 if(csrCheck11dChannel(pBssDesc->Result.BssDescriptor.channelId,
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302961 pMac->roam.validChannelList, len))
Jeff Johnson295189b2012-06-20 16:38:30 -07002962 {
2963 /* Remove Scan result which does not have 11d channel */
2964 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry,
2965 LL_ACCESS_LOCK ))
2966 {
2967 csrFreeScanResultEntry( pMac, pBssDesc );
2968 }
2969 }
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302970 pEntry = pTempEntry;
2971 }
2972
2973 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
2974 while( pEntry )
2975 {
2976 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2977 pTempEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry,
2978 LL_ACCESS_LOCK );
2979 if(csrCheck11dChannel(pBssDesc->Result.BssDescriptor.channelId,
2980 pMac->roam.validChannelList, len))
2981 {
2982 /* Remove Scan result which does not have 11d channel */
2983 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry,
2984 LL_ACCESS_LOCK ))
2985 {
2986 csrFreeScanResultEntry( pMac, pBssDesc );
2987 }
2988 }
2989 else
2990 {
2991 smsLog( pMac, LOG1, FL("%d is a Valid channel"),
2992 pBssDesc->Result.BssDescriptor.channelId);
2993 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002994 pEntry = pTempEntry;
2995 }
2996 return status;
2997}
2998
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05302999/**
3000 * csrScanFilterDFSResults
3001 *
3002 *FUNCTION:
3003 * This function filter BSSIDs on DFS channels from the scan results.
3004 *
3005 *LOGIC:
3006 * Get scan result from scan list and Check Scan result channel number
3007 * with 11d channel list if channel number is found in 11d channel list
3008 * and if fEnableDFSChnlScan is zero and if channel is DFS, then
3009 * remove scan result entry from scan list
3010 *
3011 *ASSUMPTIONS:
3012 *
3013 *NOTE:
3014 *
3015 * @param pMac Pointer to Global MAC structure
3016 *
3017 * @return Status
3018 */
3019
3020eHalStatus csrScanFilterDFSResults(tpAniSirGlobal pMac)
3021{
3022 eHalStatus status = eHAL_STATUS_SUCCESS;
3023 tListElem *pEntry,*pTempEntry;
3024 tCsrScanResult *pBssDesc;
3025
3026 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
3027 while( pEntry )
3028 {
3029 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3030 pTempEntry = csrLLNext( &pMac->scan.scanResultList, pEntry,
3031 LL_ACCESS_LOCK );
3032 if((pMac->scan.fEnableDFSChnlScan == DFS_CHNL_SCAN_DISABLED) &&
3033 CSR_IS_CHANNEL_DFS(pBssDesc->Result.BssDescriptor.channelId))
3034 {
3035 smsLog( pMac, LOG1, FL("%d is a DFS ch filtered from scan list"),
3036 pBssDesc->Result.BssDescriptor.channelId);
3037 /* Remove Scan result which does not have 11d channel */
3038 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry,
3039 LL_ACCESS_LOCK ))
3040 {
3041 csrFreeScanResultEntry( pMac, pBssDesc );
3042 }
3043 }
3044 else
3045 {
3046 smsLog( pMac, LOG1, FL("%d is a Valid channel"),
3047 pBssDesc->Result.BssDescriptor.channelId);
3048 }
3049 pEntry = pTempEntry;
3050 }
3051
3052 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
3053 while( pEntry )
3054 {
3055 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3056 pTempEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry,
3057 LL_ACCESS_LOCK );
3058
3059 if((pMac->scan.fEnableDFSChnlScan == DFS_CHNL_SCAN_DISABLED) &&
3060 CSR_IS_CHANNEL_DFS(pBssDesc->Result.BssDescriptor.channelId))
3061 {
3062 smsLog( pMac, LOG1, FL("%d is a DFS ch filtered from scan list"),
3063 pBssDesc->Result.BssDescriptor.channelId);
3064 /* Remove Scan result which does not have 11d channel */
3065 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry,
3066 LL_ACCESS_LOCK ))
3067 {
3068 csrFreeScanResultEntry( pMac, pBssDesc );
3069 }
3070 }
3071 else
3072 {
3073 smsLog( pMac, LOG1, FL("%d is a Valid channel"),
3074 pBssDesc->Result.BssDescriptor.channelId);
3075 }
3076 pEntry = pTempEntry;
3077 }
3078 return status;
3079}
3080
Jeff Johnson295189b2012-06-20 16:38:30 -07003081
3082eHalStatus csrScanCopyResultList(tpAniSirGlobal pMac, tScanResultHandle hIn, tScanResultHandle *phResult)
3083{
3084 eHalStatus status = eHAL_STATUS_SUCCESS;
3085 tScanResultList *pRetList, *pInList = (tScanResultList *)hIn;
3086 tCsrScanResult *pResult, *pScanResult;
3087 tANI_U32 count = 0;
3088 tListElem *pEntry;
3089 tANI_U32 bssLen, allocLen;
3090
3091 if(phResult)
3092 {
3093 *phResult = CSR_INVALID_SCANRESULT_HANDLE;
3094 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303095 pRetList = vos_mem_malloc(sizeof(tScanResultList));
3096 if ( NULL == pRetList )
3097 status = eHAL_STATUS_FAILURE;
3098 else
Jeff Johnson295189b2012-06-20 16:38:30 -07003099 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303100 vos_mem_set(pRetList, sizeof(tScanResultList), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003101 csrLLOpen(pMac->hHdd, &pRetList->List);
3102 pRetList->pCurEntry = NULL;
3103 csrLLLock(&pMac->scan.scanResultList);
3104 csrLLLock(&pInList->List);
3105
3106 pEntry = csrLLPeekHead( &pInList->List, LL_ACCESS_NOLOCK );
3107 while( pEntry )
3108 {
3109 pScanResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3110 bssLen = pScanResult->Result.BssDescriptor.length + sizeof(pScanResult->Result.BssDescriptor.length);
3111 allocLen = sizeof( tCsrScanResult ) + bssLen;
Kiet Lam64c1b492013-07-12 13:56:44 +05303112 pResult = vos_mem_malloc(allocLen);
3113 if ( NULL == pResult )
3114 status = eHAL_STATUS_FAILURE;
3115 else
3116 status = eHAL_STATUS_SUCCESS;
3117 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07003118 {
3119 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
3120 count = 0;
3121 break;
3122 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303123 vos_mem_set(pResult, allocLen , 0);
3124 vos_mem_copy(&pResult->Result.BssDescriptor, &pScanResult->Result.BssDescriptor, bssLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07003125 if( pScanResult->Result.pvIes )
3126 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303127 pResult->Result.pvIes = vos_mem_malloc(sizeof( tDot11fBeaconIEs ));
3128 if ( NULL == pResult->Result.pvIes )
3129 status = eHAL_STATUS_FAILURE;
3130 else
3131 status = eHAL_STATUS_SUCCESS;
3132 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07003133 {
3134 //Free the memory we allocate above first
Kiet Lam64c1b492013-07-12 13:56:44 +05303135 vos_mem_free(pResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07003136 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
3137 count = 0;
3138 break;
3139 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303140 vos_mem_copy(pResult->Result.pvIes, pScanResult->Result.pvIes,
3141 sizeof( tDot11fBeaconIEs ));
Jeff Johnson295189b2012-06-20 16:38:30 -07003142 }
3143 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_LOCK);
3144 count++;
3145 pEntry = csrLLNext( &pInList->List, pEntry, LL_ACCESS_NOLOCK );
3146 }//while
3147 csrLLUnlock(&pInList->List);
3148 csrLLUnlock(&pMac->scan.scanResultList);
3149
3150 if(HAL_STATUS_SUCCESS(status))
3151 {
3152 if(0 == count)
3153 {
3154 csrLLClose(&pRetList->List);
Kiet Lam64c1b492013-07-12 13:56:44 +05303155 vos_mem_free(pRetList);
Jeff Johnson295189b2012-06-20 16:38:30 -07003156 status = eHAL_STATUS_E_NULL_VALUE;
3157 }
3158 else if(phResult)
3159 {
3160 *phResult = pRetList;
3161 }
3162 }
3163 }//Allocated pRetList
3164
3165 return (status);
3166}
3167
3168
3169
3170eHalStatus csrScanningStateMsgProcessor( tpAniSirGlobal pMac, void *pMsgBuf )
3171{
3172 eHalStatus status = eHAL_STATUS_SUCCESS;
3173 tSirMbMsg *pMsg = (tSirMbMsg *)pMsgBuf;
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303174 tSirSmeDisConDoneInd *pDisConDoneInd;
Abhishek Singhf52182c2016-08-24 11:15:23 +05303175 tCsrRoamSession *pSession;
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303176 tCsrRoamInfo roamInfo = {0};
Jeff Johnson295189b2012-06-20 16:38:30 -07003177
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303178 if((eWNI_SME_SCAN_RSP == pMsg->type) ||
3179 (eWNI_SME_GET_SCANNED_CHANNEL_RSP == pMsg->type))
Jeff Johnson295189b2012-06-20 16:38:30 -07003180 {
3181 status = csrScanSmeScanResponse( pMac, pMsgBuf );
3182 }
3183 else
3184 {
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303185 switch (pMsg->type)
Jeff Johnson295189b2012-06-20 16:38:30 -07003186 {
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303187 case eWNI_SME_UPPER_LAYER_ASSOC_CNF:
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08003188 {
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303189 tSirSmeAssocIndToUpperLayerCnf *pUpperLayerAssocCnf;
3190 tCsrRoamInfo *pRoamInfo = NULL;
3191 tANI_U32 sessionId;
3192 eHalStatus status;
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08003193
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303194 smsLog( pMac, LOG1,
3195 FL("Scanning : ASSOCIATION confirmation can be given to upper layer "));
3196 pRoamInfo = &roamInfo;
3197 pUpperLayerAssocCnf = (tSirSmeAssocIndToUpperLayerCnf *)pMsgBuf;
3198 status = csrRoamGetSessionIdFromBSSID( pMac,
3199 (tCsrBssid *)pUpperLayerAssocCnf->bssId,
3200 &sessionId );
3201 pSession = CSR_GET_SESSION(pMac, sessionId);
3202
3203 if(!pSession)
3204 {
3205 smsLog(pMac, LOGE, FL("session %d not found "), sessionId);
3206 return eHAL_STATUS_FAILURE;
3207 }
3208
3209 //send the status code as Success
3210 pRoamInfo->statusCode = eSIR_SME_SUCCESS;
3211 pRoamInfo->u.pConnectedProfile = &pSession->connectedProfile;
3212 pRoamInfo->staId = (tANI_U8)pUpperLayerAssocCnf->aid;
3213 pRoamInfo->rsnIELen =
3214 (tANI_U8)pUpperLayerAssocCnf->rsnIE.length;
3215 pRoamInfo->prsnIE = pUpperLayerAssocCnf->rsnIE.rsnIEdata;
3216 pRoamInfo->addIELen =
3217 (tANI_U8)pUpperLayerAssocCnf->addIE.length;
3218 pRoamInfo->paddIE = pUpperLayerAssocCnf->addIE.addIEdata;
3219 vos_mem_copy(pRoamInfo->peerMac,
3220 pUpperLayerAssocCnf->peerMacAddr,
3221 sizeof(tSirMacAddr));
3222 vos_mem_copy(&pRoamInfo->bssid,
3223 pUpperLayerAssocCnf->bssId,
3224 sizeof(tCsrBssid));
3225 pRoamInfo->wmmEnabledSta = pUpperLayerAssocCnf->wmmEnabledSta;
Hardik Kantilal Patel1ba630f2014-11-21 04:32:05 +05303226#ifdef WLAN_FEATURE_AP_HT40_24G
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303227 pRoamInfo->HT40MHzIntoEnabledSta =
3228 pUpperLayerAssocCnf->HT40MHzIntoEnabledSta;
Hardik Kantilal Patel1ba630f2014-11-21 04:32:05 +05303229#endif
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303230 if(CSR_IS_INFRA_AP(pRoamInfo->u.pConnectedProfile) )
3231 {
3232 pMac->roam.roamSession[sessionId].connectState =
3233 eCSR_ASSOC_STATE_TYPE_INFRA_CONNECTED;
3234 pRoamInfo->fReassocReq = pUpperLayerAssocCnf->reassocReq;
3235 status = csrRoamCallCallback(pMac, sessionId, pRoamInfo,
3236 0, eCSR_ROAM_INFRA_IND,
3237 eCSR_ROAM_RESULT_INFRA_ASSOCIATION_CNF);
3238 }
3239 if(CSR_IS_WDS_AP( pRoamInfo->u.pConnectedProfile))
3240 {
3241 vos_sleep( 100 );
3242 pMac->roam.roamSession[sessionId].connectState =
3243 eCSR_ASSOC_STATE_TYPE_WDS_CONNECTED;//Sta
3244 status = csrRoamCallCallback(pMac, sessionId, pRoamInfo, 0,
3245 eCSR_ROAM_WDS_IND,
3246 eCSR_ROAM_RESULT_WDS_ASSOCIATION_IND);//Sta
3247 }
3248 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07003249 }
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303250 case eWNI_SME_DISCONNECT_DONE_IND:
3251 pDisConDoneInd = (tSirSmeDisConDoneInd *)(pMsg);
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08003252
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303253 smsLog( pMac, LOG1,
3254 FL("eWNI_SME_DISCONNECT_DONE_IND RC:%d"),
3255 pDisConDoneInd->reasonCode);
Sreelakshmi Konamki033cf602016-10-12 15:30:14 +05303256 pSession = CSR_GET_SESSION(pMac,pDisConDoneInd->sessionId);
3257 if (pSession)
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08003258 {
Sreelakshmi Konamki033cf602016-10-12 15:30:14 +05303259 if( CSR_IS_SESSION_VALID(pMac, pDisConDoneInd->sessionId))
3260 {
3261 roamInfo.reasonCode = pDisConDoneInd->reasonCode;
3262 roamInfo.statusCode = eSIR_SME_STA_DISASSOCIATED;
3263 vos_mem_copy(roamInfo.peerMac, pDisConDoneInd->peerMacAddr,
3264 sizeof(tSirMacAddr));
3265 status = csrRoamCallCallback(pMac,
3266 pDisConDoneInd->sessionId,
3267 &roamInfo, 0,
3268 eCSR_ROAM_LOSTLINK,
3269 eCSR_ROAM_RESULT_DISASSOC_IND);
3270 /*
3271 * Update the previous state if
3272 * previous state was eCSR_ROAMING_STATE_JOINED
3273 * as we are disconnected and
3274 * currunt state is scanning
3275 */
3276 if (!CSR_IS_INFRA_AP(&pSession->connectedProfile)
3277 && (eCSR_ROAMING_STATE_IDLE !=
3278 pMac->roam.prev_state[pDisConDoneInd->sessionId]))
3279 pMac->roam.prev_state[pDisConDoneInd->sessionId] =
3280 eCSR_ROAMING_STATE_IDLE;
3281 }
3282 else
3283 {
3284 smsLog(pMac, LOGE, FL("Inactive session %d"),
Abhishek Singhf52182c2016-08-24 11:15:23 +05303285 pDisConDoneInd->sessionId);
Sreelakshmi Konamki033cf602016-10-12 15:30:14 +05303286 status = eHAL_STATUS_FAILURE;
3287 }
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08003288 }
3289 else
3290 {
Sreelakshmi Konamki033cf602016-10-12 15:30:14 +05303291 smsLog(pMac, LOGE, FL("Invalid session"));
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303292 status = eHAL_STATUS_FAILURE;
3293 }
3294 break;
3295
3296 default :
3297 if( csrIsAnySessionInConnectState( pMac ) )
3298 {
3299 /*In case of we are connected, we need to check whether connect
3300 * status changes because scan may also run while connected.
3301 */
3302 csrRoamCheckForLinkStatusChange( pMac, (tSirSmeRsp *)pMsgBuf );
3303 }
3304 else
3305 {
3306 smsLog( pMac, LOGW,
3307 "Message [0x%04x] received in state, when expecting Scan Response",
3308 pMsg->type );
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08003309 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003310 }
3311 }
3312
3313 return (status);
3314}
3315
3316
3317
3318void csrCheckNSaveWscIe(tpAniSirGlobal pMac, tSirBssDescription *pNewBssDescr, tSirBssDescription *pOldBssDescr)
3319{
3320 int idx, len;
3321 tANI_U8 *pbIe;
3322
3323 //If failed to remove, assuming someone else got it.
3324 if((pNewBssDescr->fProbeRsp != pOldBssDescr->fProbeRsp) &&
3325 (0 == pNewBssDescr->WscIeLen))
3326 {
3327 idx = 0;
Abhishek Singhbad2b322016-10-21 11:22:33 +05303328 len = GET_IE_LEN_IN_BSS(pOldBssDescr->length)
3329 - DOT11F_IE_WSCPROBERES_MIN_LEN - 2;
Jeff Johnson295189b2012-06-20 16:38:30 -07003330 pbIe = (tANI_U8 *)pOldBssDescr->ieFields;
3331 //Save WPS IE if it exists
3332 pNewBssDescr->WscIeLen = 0;
3333 while(idx < len)
3334 {
3335 if((DOT11F_EID_WSCPROBERES == pbIe[0]) &&
3336 (0x00 == pbIe[2]) && (0x50 == pbIe[3]) && (0xf2 == pbIe[4]) && (0x04 == pbIe[5]))
3337 {
3338 //Founrd it
3339 if((DOT11F_IE_WSCPROBERES_MAX_LEN - 2) >= pbIe[1])
3340 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303341 vos_mem_copy(pNewBssDescr->WscIeProbeRsp, pbIe, pbIe[1] + 2);
Jeff Johnson295189b2012-06-20 16:38:30 -07003342 pNewBssDescr->WscIeLen = pbIe[1] + 2;
3343 }
3344 break;
3345 }
3346 idx += pbIe[1] + 2;
3347 pbIe += pbIe[1] + 2;
3348 }
3349 }
3350}
3351
3352
3353
3354//pIes may be NULL
3355tANI_BOOLEAN csrRemoveDupBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDescr,
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05303356 tDot11fBeaconIEs *pIes, tAniSSID *pSsid, v_TIME_t *timer, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07003357{
3358 tListElem *pEntry;
3359
3360 tCsrScanResult *pBssDesc;
3361 tANI_BOOLEAN fRC = FALSE;
3362
3363 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
3364 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
3365 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
3366 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
3367
3368 while( pEntry )
3369 {
3370 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3371
3372 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
3373 // matches
3374 if ( csrIsDuplicateBssDescription( pMac, &pBssDesc->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07003375 pSirBssDescr, pIes, fForced ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003376 {
3377 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
3378 ((tANI_S32)pBssDesc->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
3379 // Remove the 'old' entry from the list....
3380 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry, LL_ACCESS_LOCK ) )
3381 {
3382 // !we need to free the memory associated with this node
3383 //If failed to remove, assuming someone else got it.
3384 *pSsid = pBssDesc->Result.ssId;
3385 *timer = pBssDesc->Result.timer;
3386 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pBssDesc->Result.BssDescriptor);
3387
3388 csrFreeScanResultEntry( pMac, pBssDesc );
3389 }
3390 else
3391 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003392 smsLog( pMac, LOGW, FL( " fail to remove entry" ) );
Jeff Johnson295189b2012-06-20 16:38:30 -07003393 }
3394 fRC = TRUE;
3395
3396 // If we found a match, we can stop looking through the list.
3397 break;
3398 }
3399
3400 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_LOCK );
3401 }
3402
3403 return fRC;
3404}
3405
3406
3407eHalStatus csrAddPMKIDCandidateList( tpAniSirGlobal pMac, tANI_U32 sessionId,
3408 tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes )
3409{
3410 eHalStatus status = eHAL_STATUS_FAILURE;
3411 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
3412
Jeff Johnson32d95a32012-09-10 13:15:23 -07003413 if(!pSession)
3414 {
3415 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
3416 return eHAL_STATUS_FAILURE;
3417 }
3418
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003419 smsLog(pMac, LOGW, "csrAddPMKIDCandidateList called pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07003420 if( pIes )
3421 {
3422 // check if this is a RSN BSS
3423 if( pIes->RSN.present )
3424 {
3425 // Check if the BSS is capable of doing pre-authentication
3426 if( pSession->NumPmkidCandidate < CSR_MAX_PMKID_ALLOWED )
3427 {
3428
3429#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3430 {
3431 WLAN_VOS_DIAG_EVENT_DEF(secEvent, vos_event_wlan_security_payload_type);
Kiet Lam64c1b492013-07-12 13:56:44 +05303432 vos_mem_set(&secEvent, sizeof(vos_event_wlan_security_payload_type), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003433 secEvent.eventId = WLAN_SECURITY_EVENT_PMKID_CANDIDATE_FOUND;
3434 secEvent.encryptionModeMulticast =
3435 (v_U8_t)diagEncTypeFromCSRType(pSession->connectedProfile.mcEncryptionType);
3436 secEvent.encryptionModeUnicast =
3437 (v_U8_t)diagEncTypeFromCSRType(pSession->connectedProfile.EncryptionType);
Kiet Lam64c1b492013-07-12 13:56:44 +05303438 vos_mem_copy(secEvent.bssid, pSession->connectedProfile.bssid, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07003439 secEvent.authMode =
3440 (v_U8_t)diagAuthTypeFromCSRType(pSession->connectedProfile.AuthType);
3441 WLAN_VOS_DIAG_EVENT_REPORT(&secEvent, EVENT_WLAN_SECURITY);
3442 }
3443#endif//#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3444
3445 // if yes, then add to PMKIDCandidateList
Kiet Lam64c1b492013-07-12 13:56:44 +05303446 vos_mem_copy(pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].BSSID,
3447 pBssDesc->bssId, WNI_CFG_BSSID_LEN);
3448 // Bit 0 offirst byte - PreAuthentication Capability
3449 if ( (pIes->RSN.RSN_Cap[0] >> 0) & 0x1 )
Jeff Johnson295189b2012-06-20 16:38:30 -07003450 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303451 pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].preAuthSupported
3452 = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003453 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303454 else
3455 {
3456 pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].preAuthSupported
3457 = eANI_BOOLEAN_FALSE;
3458 }
3459 pSession->NumPmkidCandidate++;
Jeff Johnson295189b2012-06-20 16:38:30 -07003460 }
3461 else
3462 {
3463 status = eHAL_STATUS_FAILURE;
3464 }
3465 }
3466 }
3467
3468 return (status);
3469}
3470
3471//This function checks whether new AP is found for the current connected profile
3472//If it is found, it return the sessionId, else it return invalid sessionID
3473tANI_U32 csrProcessBSSDescForPMKIDList(tpAniSirGlobal pMac,
3474 tSirBssDescription *pBssDesc,
3475 tDot11fBeaconIEs *pIes)
3476{
3477 tANI_U32 i, bRet = CSR_SESSION_ID_INVALID;
3478 tCsrRoamSession *pSession;
3479 tDot11fBeaconIEs *pIesLocal = pIes;
3480
3481 if( pIesLocal || HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIesLocal)) )
3482 {
3483 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
3484 {
3485 if( CSR_IS_SESSION_VALID( pMac, i ) )
3486 {
3487 pSession = CSR_GET_SESSION( pMac, i );
3488 if( csrIsConnStateConnectedInfra( pMac, i ) &&
3489 ( eCSR_AUTH_TYPE_RSN == pSession->connectedProfile.AuthType ) )
3490 {
3491 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile, pBssDesc, pIesLocal))
3492 {
3493 //this new BSS fits the current profile connected
3494 if(HAL_STATUS_SUCCESS(csrAddPMKIDCandidateList(pMac, i, pBssDesc, pIesLocal)))
3495 {
3496 bRet = i;
3497 }
3498 break;
3499 }
3500 }
3501 }
3502 }
3503 if( !pIes )
3504 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303505 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003506 }
3507 }
3508
3509 return (tANI_U8)bRet;
3510}
3511
3512#ifdef FEATURE_WLAN_WAPI
3513eHalStatus csrAddBKIDCandidateList( tpAniSirGlobal pMac, tANI_U32 sessionId,
3514 tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes )
3515{
3516 eHalStatus status = eHAL_STATUS_FAILURE;
3517 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
3518
Jeff Johnson32d95a32012-09-10 13:15:23 -07003519 if(!pSession)
3520 {
3521 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
3522 return eHAL_STATUS_FAILURE;
3523 }
3524
Kiet Lam64c1b492013-07-12 13:56:44 +05303525 smsLog(pMac, LOGW, "csrAddBKIDCandidateList called pMac->scan.NumBkidCandidate = %d",
3526 pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07003527 if( pIes )
3528 {
3529 // check if this is a WAPI BSS
3530 if( pIes->WAPI.present )
3531 {
3532 // Check if the BSS is capable of doing pre-authentication
3533 if( pSession->NumBkidCandidate < CSR_MAX_BKID_ALLOWED )
3534 {
3535
3536 // if yes, then add to BKIDCandidateList
Kiet Lam64c1b492013-07-12 13:56:44 +05303537 vos_mem_copy(pSession->BkidCandidateInfo[pSession->NumBkidCandidate].BSSID,
3538 pBssDesc->bssId, WNI_CFG_BSSID_LEN);
3539 if ( pIes->WAPI.preauth )
Jeff Johnson295189b2012-06-20 16:38:30 -07003540 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303541 pSession->BkidCandidateInfo[pSession->NumBkidCandidate].preAuthSupported
3542 = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003543 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303544 else
3545 {
3546 pSession->BkidCandidateInfo[pSession->NumBkidCandidate].preAuthSupported
3547 = eANI_BOOLEAN_FALSE;
3548 }
3549 pSession->NumBkidCandidate++;
Jeff Johnson295189b2012-06-20 16:38:30 -07003550 }
3551 else
3552 {
3553 status = eHAL_STATUS_FAILURE;
3554 }
3555 }
3556 }
3557
3558 return (status);
3559}
3560
3561//This function checks whether new AP is found for the current connected profile
3562//if so add to BKIDCandidateList
3563tANI_BOOLEAN csrProcessBSSDescForBKIDList(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
3564 tDot11fBeaconIEs *pIes)
3565{
3566 tANI_BOOLEAN fRC = FALSE;
3567 tDot11fBeaconIEs *pIesLocal = pIes;
3568 tANI_U32 sessionId;
3569 tCsrRoamSession *pSession;
3570
3571 if( pIesLocal || HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIesLocal)) )
3572 {
3573 for( sessionId = 0; sessionId < CSR_ROAM_SESSION_MAX; sessionId++ )
3574 {
3575 if( CSR_IS_SESSION_VALID( pMac, sessionId) )
3576 {
3577 pSession = CSR_GET_SESSION( pMac, sessionId );
3578 if( csrIsConnStateConnectedInfra( pMac, sessionId ) &&
3579 eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE == pSession->connectedProfile.AuthType)
3580 {
3581 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile,pBssDesc, pIesLocal))
3582 {
3583 //this new BSS fits the current profile connected
3584 if(HAL_STATUS_SUCCESS(csrAddBKIDCandidateList(pMac, sessionId, pBssDesc, pIesLocal)))
3585 {
3586 fRC = TRUE;
3587 }
3588 }
3589 }
3590 }
3591 }
3592 if(!pIes)
3593 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303594 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003595 }
3596
3597 }
3598 return fRC;
3599}
3600
3601#endif
3602
3603
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07003604static void csrMoveTempScanResultsToMainList( tpAniSirGlobal pMac, tANI_U8 reason )
Jeff Johnson295189b2012-06-20 16:38:30 -07003605{
3606 tListElem *pEntry;
3607 tCsrScanResult *pBssDescription;
Jeff Johnson295189b2012-06-20 16:38:30 -07003608 tANI_BOOLEAN fDupBss;
3609#ifdef FEATURE_WLAN_WAPI
3610 tANI_BOOLEAN fNewWapiBSSForCurConnection = eANI_BOOLEAN_FALSE;
3611#endif /* FEATURE_WLAN_WAPI */
3612 tDot11fBeaconIEs *pIesLocal = NULL;
3613 tANI_U32 sessionId = CSR_SESSION_ID_INVALID;
3614 tAniSSID tmpSsid;
3615 v_TIME_t timer=0;
Kapil Gupta2f2fae42016-09-15 15:29:47 +05303616 tANI_U8 occupied_chan_count = pMac->scan.occupiedChannels.numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -07003617
3618 tmpSsid.length = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07003619
3620 // remove the BSS descriptions from temporary list
3621 while( ( pEntry = csrLLRemoveTail( &pMac->scan.tempScanResults, LL_ACCESS_LOCK ) ) != NULL)
3622 {
3623 pBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3624
Vinay Krishna Eranna566365f2015-03-09 12:34:13 +05303625 smsLog( pMac, LOG2, "...Bssid= "MAC_ADDRESS_STR" chan= %d, rssi = -%d",
Arif Hussain24bafea2013-11-15 15:10:03 -08003626 MAC_ADDR_ARRAY(pBssDescription->Result.BssDescriptor.bssId),
Jeff Johnson295189b2012-06-20 16:38:30 -07003627 pBssDescription->Result.BssDescriptor.channelId,
3628 pBssDescription->Result.BssDescriptor.rssi * (-1) );
3629
3630 //At this time, pBssDescription->Result.pvIes may be NULL
3631 pIesLocal = (tDot11fBeaconIEs *)( pBssDescription->Result.pvIes );
3632 if( !pIesLocal && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pBssDescription->Result.BssDescriptor, &pIesLocal))) )
3633 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003634 smsLog(pMac, LOGE, FL(" Cannot pared IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003635 csrFreeScanResultEntry(pMac, pBssDescription);
3636 continue;
3637 }
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05303638 fDupBss = csrRemoveDupBssDescription( pMac, &pBssDescription->Result.BssDescriptor, pIesLocal, &tmpSsid, &timer, FALSE );
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07003639 //Check whether we have reach out limit, but don't lose the LFR candidates came from FW
3640 if( CSR_SCAN_IS_OVER_BSS_LIMIT(pMac)
3641#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
3642 && !( eCsrScanGetLfrResult == reason )
3643#endif
3644 )
Jeff Johnson295189b2012-06-20 16:38:30 -07003645 {
Deepthi Gowri50e2fa52016-03-17 15:30:53 +05303646 smsLog(pMac, LOG1, FL("########## BSS Limit reached ###########"));
3647 csrPurgeOldScanResults(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07003648 }
3649 // check for duplicate scan results
3650 if ( !fDupBss )
3651 {
3652 //Found a new BSS
3653 sessionId = csrProcessBSSDescForPMKIDList(pMac,
3654 &pBssDescription->Result.BssDescriptor, pIesLocal);
3655 if( CSR_SESSION_ID_INVALID != sessionId)
3656 {
3657 csrRoamCallCallback(pMac, sessionId, NULL, 0,
3658 eCSR_ROAM_SCAN_FOUND_NEW_BSS, eCSR_ROAM_RESULT_NONE);
3659 }
3660 }
3661 else
3662 {
3663 //Check if the new one has SSID it it, if not, use the older SSID if it exists.
3664 if( (0 == pBssDescription->Result.ssId.length) && tmpSsid.length )
3665 {
3666 //New BSS has a hidden SSID and old one has the SSID. Keep the SSID only
3667 //if diff of saved SSID time and current time is less than 1 min to avoid
3668 //side effect of saving SSID with old one is that if AP changes its SSID while remain
3669 //hidden, we may never see it and also to address the requirement of
3670 //When we remove hidden ssid from the profile i.e., forget the SSID via
3671 // GUI that SSID shouldn't see in the profile
3672 if( (vos_timer_get_system_time() - timer) <= HIDDEN_TIMER)
3673 {
3674 pBssDescription->Result.timer = timer;
3675 pBssDescription->Result.ssId = tmpSsid;
3676 }
3677 }
3678 }
3679
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303680 //Find a good AP for 11d info
3681 if ( csrIs11dSupported( pMac ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003682 {
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303683 // check if country information element is present
3684 if (pIesLocal->Country.present)
Jeff Johnson295189b2012-06-20 16:38:30 -07003685 {
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303686 csrAddVoteForCountryInfo(pMac, pIesLocal->Country.country);
3687 smsLog(pMac, LOGW, FL("11d AP Bssid " MAC_ADDRESS_STR
3688 " chan= %d, rssi = -%d, countryCode %c%c"),
3689 MAC_ADDR_ARRAY( pBssDescription->Result.BssDescriptor.bssId),
3690 pBssDescription->Result.BssDescriptor.channelId,
3691 pBssDescription->Result.BssDescriptor.rssi * (-1),
3692 pIesLocal->Country.country[0],pIesLocal->Country.country[1] );
3693 }
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303694
Jeff Johnson295189b2012-06-20 16:38:30 -07003695 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08003696
Jeff Johnson295189b2012-06-20 16:38:30 -07003697 // append to main list
3698 csrScanAddResult(pMac, pBssDescription, pIesLocal);
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303699 if ( (pBssDescription->Result.pvIes == NULL) && pIesLocal )
Jeff Johnson295189b2012-06-20 16:38:30 -07003700 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303701 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003702 }
3703 }
3704
Kapil Gupta2f2fae42016-09-15 15:29:47 +05303705#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
3706 if (sme_IsFeatureSupportedByFW(PER_BASED_ROAMING) &&
3707 (csrGetInfraSessionId(pMac) != -1) &&
3708 (pMac->scan.occupiedChannels.numChannels != occupied_chan_count))
3709 {
3710 /* Update FW with new list */
3711 smsLog(pMac, LOGW,
3712 FL("Updating occupied channel list, new chanNum %d"),
3713 pMac->scan.occupiedChannels.numChannels);
3714 csrRoamOffloadScan(pMac, ROAM_SCAN_OFFLOAD_UPDATE_CFG,
3715 REASON_CHANNEL_LIST_CHANGED);
3716 }
3717#endif
Sushant Kaushik6274de62015-05-01 16:31:23 +05303718 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
Tushnim Bhattacharyyaae317772013-10-23 18:55:38 -07003719 //we don't need to update CC while connected to an AP which is advertising CC already
3720 if (csrIs11dSupported(pMac))
3721 {
3722 tANI_U32 i;
3723 tCsrRoamSession *pSession;
3724
3725 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
3726 {
3727 if (CSR_IS_SESSION_VALID( pMac, i ) )
3728 {
3729 pSession = CSR_GET_SESSION( pMac, i );
3730 if (csrIsConnStateConnected(pMac, i))
3731 {
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303732 smsLog(pMac, LOGW, FL("No need for updating CC in"
3733 "connected state"));
3734 goto end;
Tushnim Bhattacharyyaae317772013-10-23 18:55:38 -07003735 }
3736 }
3737 }
Agrawal Ashishbd3a5932016-04-12 16:22:39 +05303738 if (csrElectedCountryInfo(pMac))
3739 csrLearnCountryInformation(pMac, NULL, NULL,
3740 eANI_BOOLEAN_TRUE);
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303741 }
3742
Tushnim Bhattacharyyaae317772013-10-23 18:55:38 -07003743end:
3744 //If we can find the current 11d info in any of the scan results, or
Jeff Johnson295189b2012-06-20 16:38:30 -07003745 // a good enough AP with the 11d info from the scan results then no need to
3746 // get into ambiguous state
3747 if(pMac->scan.fAmbiguous11dInfoFound)
3748 {
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303749 if((pMac->scan.fCurrent11dInfoMatch))
Jeff Johnson295189b2012-06-20 16:38:30 -07003750 {
3751 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
3752 }
3753 }
3754
3755#ifdef FEATURE_WLAN_WAPI
3756 if(fNewWapiBSSForCurConnection)
3757 {
3758 //remember it first
3759 csrRoamCallCallback(pMac, sessionId, NULL, 0, eCSR_ROAM_SCAN_FOUND_NEW_BSS, eCSR_ROAM_RESULT_NEW_WAPI_BSS);
3760 }
3761#endif /* FEATURE_WLAN_WAPI */
3762
3763 return;
3764}
3765
Deepthi Gowri50e2fa52016-03-17 15:30:53 +05303766void csrPurgeOldScanResults(tpAniSirGlobal pMac)
3767{
3768 tListElem *pEntry, *tmpEntry;
3769 tCsrScanResult *pResult, *oldest_bss = NULL;
Deepthi Gowri4480a3f2016-05-18 19:30:17 +05303770 v_TIME_t oldest_entry = 0;
3771 v_TIME_t curTime = vos_timer_get_system_time();
Deepthi Gowri50e2fa52016-03-17 15:30:53 +05303772
3773 csrLLLock(&pMac->scan.scanResultList);
3774 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
3775 while( pEntry )
3776 {
3777 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry,
3778 LL_ACCESS_NOLOCK);
3779 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3780 if((curTime -
3781 pResult->Result.BssDescriptor.nReceivedTime) > oldest_entry)
3782 {
3783 oldest_entry = curTime -
3784 pResult->Result.BssDescriptor.nReceivedTime;
3785 oldest_bss = pResult;
3786 }
3787 pEntry = tmpEntry;
3788 }
3789 if (oldest_bss)
3790 {
3791 //Free the old BSS Entries
3792 if( csrLLRemoveEntry(&pMac->scan.scanResultList,
3793 &oldest_bss->Link, LL_ACCESS_NOLOCK) )
3794 {
Deepthi Gowri6a08e312016-03-31 19:10:14 +05303795 smsLog(pMac, LOG1, FL(" Current time delta (%lu) of BSSID to be removed" MAC_ADDRESS_STR ),
Deepthi Gowri50e2fa52016-03-17 15:30:53 +05303796 (curTime - oldest_bss->Result.BssDescriptor.nReceivedTime),
3797 MAC_ADDR_ARRAY(oldest_bss->Result.BssDescriptor.bssId));
3798 csrFreeScanResultEntry(pMac, oldest_bss);
3799 }
3800 }
3801 csrLLUnlock(&pMac->scan.scanResultList);
3802}
Jeff Johnson295189b2012-06-20 16:38:30 -07003803
3804static tCsrScanResult *csrScanSaveBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pBSSDescription,
3805 tDot11fBeaconIEs *pIes)
3806{
3807 tCsrScanResult *pCsrBssDescription = NULL;
3808 tANI_U32 cbBSSDesc;
3809 tANI_U32 cbAllocated;
Sushant Kaushik6274de62015-05-01 16:31:23 +05303810 tListElem *pEntry;
Jeff Johnson295189b2012-06-20 16:38:30 -07003811
3812 // figure out how big the BSS description is (the BSSDesc->length does NOT
3813 // include the size of the length field itself).
3814 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
3815
3816 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
3817
Kiet Lam64c1b492013-07-12 13:56:44 +05303818 pCsrBssDescription = vos_mem_malloc(cbAllocated);
3819 if ( NULL != pCsrBssDescription )
Jeff Johnson295189b2012-06-20 16:38:30 -07003820 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303821 vos_mem_set(pCsrBssDescription, cbAllocated, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003822 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Kiet Lam64c1b492013-07-12 13:56:44 +05303823 vos_mem_copy(&pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc);
Jeff Johnson295189b2012-06-20 16:38:30 -07003824#if defined(VOSS_ENSBALED)
3825 VOS_ASSERT( pCsrBssDescription->Result.pvIes == NULL );
3826#endif
3827 csrScanAddResult(pMac, pCsrBssDescription, pIes);
Sushant Kaushik6274de62015-05-01 16:31:23 +05303828 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
Jeff Johnson295189b2012-06-20 16:38:30 -07003829 }
3830
3831 return( pCsrBssDescription );
3832}
3833
3834// Append a Bss Description...
3835tCsrScanResult *csrScanAppendBssDescription( tpAniSirGlobal pMac,
3836 tSirBssDescription *pSirBssDescription,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07003837 tDot11fBeaconIEs *pIes, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07003838{
3839 tCsrScanResult *pCsrBssDescription = NULL;
3840 tAniSSID tmpSsid;
3841 v_TIME_t timer = 0;
3842 int result;
3843
3844 tmpSsid.length = 0;
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07003845 result = csrRemoveDupBssDescription( pMac, pSirBssDescription, pIes, &tmpSsid, &timer, fForced );
Jeff Johnson295189b2012-06-20 16:38:30 -07003846 pCsrBssDescription = csrScanSaveBssDescription( pMac, pSirBssDescription, pIes );
3847 if (result && (pCsrBssDescription != NULL))
3848 {
3849 //Check if the new one has SSID it it, if not, use the older SSID if it exists.
3850 if( (0 == pCsrBssDescription->Result.ssId.length) && tmpSsid.length )
3851 {
3852 //New BSS has a hidden SSID and old one has the SSID. Keep the SSID only
3853 //if diff of saved SSID time and current time is less than 1 min to avoid
3854 //side effect of saving SSID with old one is that if AP changes its SSID while remain
3855 //hidden, we may never see it and also to address the requirement of
3856 //When we remove hidden ssid from the profile i.e., forget the SSID via
3857 // GUI that SSID shouldn't see in the profile
3858 if((vos_timer_get_system_time()-timer) <= HIDDEN_TIMER)
3859 {
3860 pCsrBssDescription->Result.ssId = tmpSsid;
3861 pCsrBssDescription->Result.timer = timer;
3862 }
3863 }
3864 }
3865
3866
3867 return( pCsrBssDescription );
3868}
3869
3870
3871
3872void csrPurgeChannelPower( tpAniSirGlobal pMac, tDblLinkList *pChannelList )
3873{
3874 tCsrChannelPowerInfo *pChannelSet;
3875 tListElem *pEntry;
3876
3877 csrLLLock(pChannelList);
3878 // Remove the channel sets from the learned list and put them in the free list
3879 while( ( pEntry = csrLLRemoveHead( pChannelList, LL_ACCESS_NOLOCK ) ) != NULL)
3880 {
3881 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3882 if( pChannelSet )
3883 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303884 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003885 }
3886 }
3887 csrLLUnlock(pChannelList);
3888 return;
3889}
3890
3891
3892/*
3893 * Save the channelList into the ultimate storage as the final stage of channel
3894 * Input: pCountryInfo -- the country code (e.g. "USI"), channel list, and power limit are all stored inside this data structure
3895 */
Jeff Johnsone7245742012-09-05 17:12:55 -07003896eHalStatus csrSaveToChannelPower2G_5G( tpAniSirGlobal pMac, tANI_U32 tableSize, tSirMacChanInfo *channelTable )
Jeff Johnson295189b2012-06-20 16:38:30 -07003897{
3898 tANI_U32 i = tableSize / sizeof( tSirMacChanInfo );
3899 tSirMacChanInfo *pChannelInfo;
3900 tCsrChannelPowerInfo *pChannelSet;
3901 tANI_BOOLEAN f2GHzInfoFound = FALSE;
3902 tANI_BOOLEAN f2GListPurged = FALSE, f5GListPurged = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003903
3904 pChannelInfo = channelTable;
3905 // atleast 3 bytes have to be remaining -- from "countryString"
3906 while ( i-- )
3907 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303908 pChannelSet = vos_mem_malloc(sizeof(tCsrChannelPowerInfo));
3909 if ( NULL != pChannelSet )
Jeff Johnson295189b2012-06-20 16:38:30 -07003910 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303911 vos_mem_set(pChannelSet, sizeof(tCsrChannelPowerInfo), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003912 pChannelSet->firstChannel = pChannelInfo->firstChanNum;
3913 pChannelSet->numChannels = pChannelInfo->numChannels;
3914
3915 // Now set the inter-channel offset based on the frequency band the channel set lies in
Jeff Johnsone7245742012-09-05 17:12:55 -07003916 if( (CSR_IS_CHANNEL_24GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003917 ((pChannelSet->firstChannel + (pChannelSet->numChannels - 1)) <= CSR_MAX_24GHz_CHANNEL_NUMBER) )
Jeff Johnsone7245742012-09-05 17:12:55 -07003918
Jeff Johnson295189b2012-06-20 16:38:30 -07003919 {
3920 pChannelSet->interChannelOffset = 1;
3921 f2GHzInfoFound = TRUE;
3922 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003923 else if ( (CSR_IS_CHANNEL_5GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003924 ((pChannelSet->firstChannel + ((pChannelSet->numChannels - 1) * 4)) <= CSR_MAX_5GHz_CHANNEL_NUMBER) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003925 {
3926 pChannelSet->interChannelOffset = 4;
3927 f2GHzInfoFound = FALSE;
3928 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003929 else
3930 {
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003931 smsLog( pMac, LOGW, FL("Invalid Channel %d Present in Country IE"),
Jeff Johnsone7245742012-09-05 17:12:55 -07003932 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303933 vos_mem_free(pChannelSet);
Jeff Johnsone7245742012-09-05 17:12:55 -07003934 return eHAL_STATUS_FAILURE;
3935 }
3936
Jeff Johnson295189b2012-06-20 16:38:30 -07003937 pChannelSet->txPower = CSR_ROAM_MIN( pChannelInfo->maxTxPower, pMac->roam.configParam.nTxPowerCap );
3938
3939 if( f2GHzInfoFound )
3940 {
3941 if( !f2GListPurged )
3942 {
3943 // purge previous results if found new
3944 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList24 );
3945 f2GListPurged = TRUE;
3946 }
3947
3948 if(CSR_IS_OPERATING_BG_BAND(pMac))
3949 {
3950 // add to the list of 2.4 GHz channel sets
3951 csrLLInsertTail( &pMac->scan.channelPowerInfoList24, &pChannelSet->link, LL_ACCESS_LOCK );
3952 }
3953 else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003954 smsLog( pMac, LOGW, FL("Adding 11B/G channels in 11A mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003955 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303956 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003957 }
3958 }
3959 else
3960 {
3961 // 5GHz info found
3962 if( !f5GListPurged )
3963 {
3964 // purge previous results if found new
3965 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList5G );
3966 f5GListPurged = TRUE;
3967 }
3968
3969 if(CSR_IS_OPERATING_A_BAND(pMac))
3970 {
3971 // add to the list of 5GHz channel sets
3972 csrLLInsertTail( &pMac->scan.channelPowerInfoList5G, &pChannelSet->link, LL_ACCESS_LOCK );
3973 }
3974 else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003975 smsLog( pMac, LOGW, FL("Adding 11A channels in B/G mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003976 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303977 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003978 }
3979 }
3980 }
3981
3982 pChannelInfo++; // move to next entry
3983 }
3984
Jeff Johnsone7245742012-09-05 17:12:55 -07003985 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07003986}
3987
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303988static void csrClearDfsChannelList( tpAniSirGlobal pMac )
3989{
3990 tSirMbMsg *pMsg;
3991 tANI_U16 msgLen;
Jeff Johnson295189b2012-06-20 16:38:30 -07003992
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303993 msgLen = (tANI_U16)(sizeof( tSirMbMsg ));
Kiet Lam64c1b492013-07-12 13:56:44 +05303994 pMsg = vos_mem_malloc(msgLen);
3995 if ( NULL != pMsg )
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303996 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303997 vos_mem_set((void *)pMsg, msgLen, 0);
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303998 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_CLEAR_DFS_CHANNEL_LIST);
3999 pMsg->msgLen = pal_cpu_to_be16(msgLen);
4000 palSendMBMessage(pMac->hHdd, pMsg);
4001 }
4002}
Jeff Johnson295189b2012-06-20 16:38:30 -07004003
4004void csrApplyPower2Current( tpAniSirGlobal pMac )
4005{
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004006 smsLog( pMac, LOG3, FL(" Updating Cfg with power settings"));
Jeff Johnson295189b2012-06-20 16:38:30 -07004007 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList24, WNI_CFG_MAX_TX_POWER_2_4 );
4008 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList5G, WNI_CFG_MAX_TX_POWER_5 );
4009}
4010
4011
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004012void csrApplyChannelPowerCountryInfo( tpAniSirGlobal pMac, tCsrChannel *pChannelList, tANI_U8 *countryCode, tANI_BOOLEAN updateRiva)
Jeff Johnson295189b2012-06-20 16:38:30 -07004013{
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304014 int i, j, count, countryIndex = -1;
Jeff Johnson295189b2012-06-20 16:38:30 -07004015 tANI_U8 numChannels = 0;
4016 tANI_U8 tempNumChannels = 0;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304017 tANI_U8 channelIgnore = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004018 tCsrChannel ChannelList;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304019
Jeff Johnson295189b2012-06-20 16:38:30 -07004020 if( pChannelList->numChannels )
4021 {
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304022 for(count=0; count < MAX_COUNTRY_IGNORE; count++)
4023 {
4024 if(vos_mem_compare(countryCode, countryIgnoreList[count].countryCode,
4025 VOS_COUNTRY_CODE_LEN))
4026 {
4027 countryIndex = count;
4028 break;
4029 }
4030 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004031 tempNumChannels = CSR_MIN(pChannelList->numChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN);
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05304032
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304033 for(i=0; i < tempNumChannels; i++)
Jeff Johnson295189b2012-06-20 16:38:30 -07004034 {
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304035 channelIgnore = FALSE;
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05304036 if( countryIndex != -1 )
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304037 {
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05304038 for(j=0; j < countryIgnoreList[countryIndex].channelCount; j++)
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304039 {
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05304040 if( pChannelList->channelList[i] ==
4041 countryIgnoreList[countryIndex].channelList[j] )
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304042 {
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05304043 channelIgnore = TRUE;
4044 break;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304045 }
4046 }
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05304047 }
4048 if( FALSE == channelIgnore )
4049 {
4050 ChannelList.channelList[numChannels] = pChannelList->channelList[i];
4051 numChannels++;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304052 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004053 }
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304054 ChannelList.numChannels = numChannels;
Mahesh A Saptasagar1ed59582014-06-04 18:45:07 +05304055 csrApplyPower2Current( pMac ); // Store the channel+power info in the global place: Cfg
Jeff Johnson295189b2012-06-20 16:38:30 -07004056 csrSetCfgValidChannelList(pMac, ChannelList.channelList, ChannelList.numChannels);
4057 // extend scan capability
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304058 // build a scan list based on the channel list : channel# + active/passive scan
4059 csrSetCfgScanControlList(pMac, countryCode, &ChannelList);
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05304060 /*Send msg to Lim to clear DFS channel list */
4061 csrClearDfsChannelList(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07004062#ifdef FEATURE_WLAN_SCAN_PNO
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004063 if (updateRiva)
4064 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004065 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO, FL(" Sending 11d PNO info to Riva"));
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004066 // Send HAL UpdateScanParams message
4067 pmcUpdateScanParams(pMac, &(pMac->roam.configParam), &ChannelList, TRUE);
4068 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004069#endif // FEATURE_WLAN_SCAN_PNO
4070 }
4071 else
4072 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004073 smsLog( pMac, LOGE, FL(" 11D channel list is empty"));
Jeff Johnson295189b2012-06-20 16:38:30 -07004074 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004075 csrSetCfgCountryCode(pMac, countryCode);
4076}
4077
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004078void csrResetCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce, tANI_BOOLEAN updateRiva )
Jeff Johnson295189b2012-06-20 16:38:30 -07004079{
4080 if( fForce || (csrIs11dSupported( pMac ) && (!pMac->scan.f11dInfoReset)))
4081 {
4082
4083#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4084 {
4085 vos_log_802_11d_pkt_type *p11dLog;
4086 int Index;
4087
4088 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
4089 if(p11dLog)
4090 {
4091 p11dLog->eventId = WLAN_80211D_EVENT_RESET;
Kiet Lam64c1b492013-07-12 13:56:44 +05304092 vos_mem_copy(p11dLog->countryCode, pMac->scan.countryCodeCurrent, 3);
Jeff Johnson295189b2012-06-20 16:38:30 -07004093 p11dLog->numChannel = pMac->scan.base20MHzChannels.numChannels;
4094 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
4095 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304096 vos_mem_copy(p11dLog->Channels,
4097 pMac->scan.base20MHzChannels.channelList,
4098 p11dLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07004099 for (Index=0; Index < pMac->scan.base20MHzChannels.numChannels; Index++)
4100 {
4101 p11dLog->TxPwr[Index] = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
4102 }
4103 }
4104 if(!pMac->roam.configParam.Is11dSupportEnabled)
4105 {
4106 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
4107 }
4108 else if(pMac->roam.configParam.fEnforceDefaultDomain)
4109 {
4110 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
4111 }
4112 else
4113 {
4114 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
4115 }
4116 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
4117 }
4118 }
4119#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4120
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004121 csrPruneChannelListForMode(pMac, &pMac->scan.baseChannels);
4122 csrPruneChannelListForMode(pMac, &pMac->scan.base20MHzChannels);
4123
Jeff Johnson295189b2012-06-20 16:38:30 -07004124 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_FALSE);
4125 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_TRUE);
4126 // ... and apply the channel list, power settings, and the country code.
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004127 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.base20MHzChannels, pMac->scan.countryCodeCurrent, updateRiva );
Jeff Johnson295189b2012-06-20 16:38:30 -07004128 // clear the 11d channel list
Kiet Lam64c1b492013-07-12 13:56:44 +05304129 vos_mem_set(&pMac->scan.channels11d, sizeof(pMac->scan.channels11d), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004130 pMac->scan.f11dInfoReset = eANI_BOOLEAN_TRUE;
4131 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_FALSE;
4132 }
4133
4134 return;
4135}
4136
4137
4138eHalStatus csrResetCountryCodeInformation(tpAniSirGlobal pMac, tANI_BOOLEAN *pfRestartNeeded)
4139{
4140 eHalStatus status = eHAL_STATUS_SUCCESS;
4141 tANI_BOOLEAN fRestart = eANI_BOOLEAN_FALSE;
4142
4143 //Use the Country code and domain from EEPROM
Kiet Lam64c1b492013-07-12 13:56:44 +05304144 vos_mem_copy(pMac->scan.countryCodeCurrent, pMac->scan.countryCodeDefault,
4145 WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07004146 csrSetRegulatoryDomain(pMac, pMac->scan.domainIdCurrent, &fRestart);
Jeff Johnson43971f52012-07-17 12:26:56 -07004147 if( ((eANI_BOOLEAN_FALSE == fRestart) || (pfRestartNeeded == NULL) )
4148 && !csrIsInfraConnected(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -07004149 {
4150 //Only reset the country info if we don't need to restart
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004151 csrResetCountryInformation(pMac, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07004152 }
4153 if(pfRestartNeeded)
4154 {
4155 *pfRestartNeeded = fRestart;
4156 }
4157
4158 return (status);
4159}
4160
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05304161void csrClearVotesForCountryInfo(tpAniSirGlobal pMac)
4162{
4163 pMac->scan.countryCodeCount = 0;
4164 vos_mem_set(pMac->scan.votes11d,
4165 sizeof(tCsrVotes11d) * CSR_MAX_NUM_COUNTRY_CODE, 0);
4166}
4167
4168void csrAddVoteForCountryInfo(tpAniSirGlobal pMac, tANI_U8 *pCountryCode)
4169{
4170 tANI_BOOLEAN match = FALSE;
4171 tANI_U8 i;
4172
4173 /* convert to UPPER here so we are assured
4174 * the strings are always in upper case.
4175 */
4176 for( i = 0; i < 3; i++ )
4177 {
4178 pCountryCode[ i ] = (tANI_U8)csrToUpper( pCountryCode[ i ] );
4179 }
4180
4181 /* Some of the 'old' Cisco 350 series AP's advertise NA as the
4182 * country code (for North America ??). NA is not a valid country code
4183 * or domain so let's allow this by changing it to the proper
4184 * country code (which is US). We've also seen some NETGEAR AP's
4185 * that have "XX " as the country code with valid 2.4 GHz US channel
4186 * information. If we cannot find the country code advertised in the
4187 * 11d information element, let's default to US.
4188 */
4189
4190 if ( !HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry( pMac,
4191 pCountryCode, NULL,COUNTRY_QUERY ) ) )
4192 {
4193 pCountryCode[ 0 ] = '0';
4194 pCountryCode[ 1 ] = '0';
4195 }
4196
4197 /* We've seen some of the AP's improperly put a 0 for the
4198 * third character of the country code. spec says valid charcters are
4199 * 'O' (for outdoor), 'I' for Indoor, or ' ' (space; for either).
4200 * if we see a 0 in this third character, let's change it to a ' '.
4201 */
4202 if ( 0 == pCountryCode[ 2 ] )
4203 {
4204 pCountryCode[ 2 ] = ' ';
4205 }
4206
4207 for (i = 0; i < pMac->scan.countryCodeCount; i++)
4208 {
4209 match = (vos_mem_compare(pMac->scan.votes11d[i].countryCode,
4210 pCountryCode, 2));
4211 if(match)
4212 {
4213 break;
4214 }
4215 }
4216
4217 if (match)
4218 {
4219 pMac->scan.votes11d[i].votes++;
4220 }
4221 else
4222 {
4223 vos_mem_copy( pMac->scan.votes11d[pMac->scan.countryCodeCount].countryCode,
4224 pCountryCode, 3 );
4225 pMac->scan.votes11d[pMac->scan.countryCodeCount].votes = 1;
4226 pMac->scan.countryCodeCount++;
4227 }
4228
4229 return;
4230}
4231
4232tANI_BOOLEAN csrElectedCountryInfo(tpAniSirGlobal pMac)
4233{
4234 tANI_BOOLEAN fRet = FALSE;
4235 tANI_U8 maxVotes = 0;
4236 tANI_U8 i, j=0;
4237
4238 if (!pMac->scan.countryCodeCount)
4239 {
Agrawal Ashishbd3a5932016-04-12 16:22:39 +05304240 VOS_TRACE( VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_WARN,
4241 "No AP with 11d Country code is present in scan list");
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05304242 return fRet;
4243 }
4244 maxVotes = pMac->scan.votes11d[0].votes;
4245 fRet = TRUE;
4246
4247 for(i = 1; i < pMac->scan.countryCodeCount; i++)
4248 {
4249 /* If we have a tie for max votes for 2 different country codes,
4250 * pick random.we can put some more intelligence - TBD
4251 */
4252 if (maxVotes < pMac->scan.votes11d[i].votes)
4253 {
4254 VOS_TRACE( VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
4255 " Votes for Country %c%c : %d\n",
4256 pMac->scan.votes11d[i].countryCode[0],
4257 pMac->scan.votes11d[i].countryCode[1],
4258 pMac->scan.votes11d[i].votes);
4259
4260 maxVotes = pMac->scan.votes11d[i].votes;
4261 j = i;
4262 fRet = TRUE;
4263 }
4264
4265 }
4266 if (fRet)
4267 {
Rajesh Babu Prathipati20cdffa2014-07-01 22:24:59 +05304268 vos_mem_copy(pMac->scan.countryCodeElected,
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05304269 pMac->scan.votes11d[j].countryCode, WNI_CFG_COUNTRY_CODE_LEN);
Rajesh Babu Prathipati20cdffa2014-07-01 22:24:59 +05304270 vos_mem_copy(pMac->scan.countryCode11d,
Agarwal Ashish852b2c32014-05-23 17:13:25 +05304271 pMac->scan.votes11d[j].countryCode, WNI_CFG_COUNTRY_CODE_LEN);
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05304272 VOS_TRACE( VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
4273 "Selected Country is %c%c With count %d\n",
4274 pMac->scan.votes11d[j].countryCode[0],
4275 pMac->scan.votes11d[j].countryCode[1],
4276 pMac->scan.votes11d[j].votes);
4277 }
4278 return fRet;
4279}
Jeff Johnson295189b2012-06-20 16:38:30 -07004280
4281eHalStatus csrSetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pCountry, tANI_BOOLEAN *pfRestartNeeded)
4282{
4283 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
4284 v_REGDOMAIN_t domainId;
4285
4286 if(pCountry)
4287 {
Kiet Lam6c583332013-10-14 05:37:09 +05304288 status = csrGetRegulatoryDomainForCountry(pMac, pCountry, &domainId, COUNTRY_USER);
Jeff Johnson295189b2012-06-20 16:38:30 -07004289 if(HAL_STATUS_SUCCESS(status))
4290 {
4291 status = csrSetRegulatoryDomain(pMac, domainId, pfRestartNeeded);
4292 if(HAL_STATUS_SUCCESS(status))
4293 {
4294 //We don't need to check the pMac->roam.configParam.fEnforceDefaultDomain flag here,
4295 //csrSetRegulatoryDomain will fail if the country doesn't fit our domain criteria.
Kiet Lam64c1b492013-07-12 13:56:44 +05304296 vos_mem_copy(pMac->scan.countryCodeCurrent, pCountry, WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07004297 if((pfRestartNeeded == NULL) || !(*pfRestartNeeded))
4298 {
4299 //Simply set it to cfg. If we need to restart, restart will apply it to the CFG
4300 csrSetCfgCountryCode(pMac, pCountry);
4301 }
4302 }
4303 }
4304 }
4305
4306 return (status);
4307}
4308
4309
4310
4311//caller allocated memory for pNumChn and pChnPowerInfo
4312//As input, *pNumChn has the size of the array of pChnPowerInfo
4313//Upon return, *pNumChn has the number of channels assigned.
4314void csrGetChannelPowerInfo( tpAniSirGlobal pMac, tDblLinkList *pList,
4315 tANI_U32 *pNumChn, tChannelListWithPower *pChnPowerInfo)
4316{
4317 tListElem *pEntry;
4318 tANI_U32 chnIdx = 0, idx;
4319 tCsrChannelPowerInfo *pChannelSet;
4320
4321 //Get 2.4Ghz first
4322 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
4323 while( pEntry && (chnIdx < *pNumChn) )
4324 {
4325 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
4326 if ( 1 != pChannelSet->interChannelOffset )
4327 {
4328 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
4329 {
4330 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
4331 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
4332 }
4333 }
4334 else
4335 {
4336 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
4337 {
4338 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + idx);
4339 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
4340 }
4341 }
4342
4343 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
4344 }
4345 *pNumChn = chnIdx;
4346
4347 return ;
4348}
4349
4350
4351
4352void csrApplyCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce )
4353{
4354 v_REGDOMAIN_t domainId;
4355 eHalStatus status = eHAL_STATUS_SUCCESS;
4356
4357 do
4358 {
4359 if( !csrIs11dSupported( pMac ) || 0 == pMac->scan.channelOf11dInfo) break;
4360 if( pMac->scan.fAmbiguous11dInfoFound )
4361 {
4362 // ambiguous info found
4363 //Restore te default domain as well
Kiet Lam6c583332013-10-14 05:37:09 +05304364 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
4365 pMac, pMac->scan.countryCodeCurrent,
4366 &domainId, COUNTRY_QUERY)))
Jeff Johnson295189b2012-06-20 16:38:30 -07004367 {
4368 pMac->scan.domainIdCurrent = domainId;
4369 }
4370 else
4371 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004372 smsLog(pMac, LOGE, FL(" failed to get domain from currentCountryCode %02X%02X"),
Jeff Johnson295189b2012-06-20 16:38:30 -07004373 pMac->scan.countryCodeCurrent[0], pMac->scan.countryCodeCurrent[1]);
4374 }
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004375 csrResetCountryInformation( pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE );
Jeff Johnson295189b2012-06-20 16:38:30 -07004376 break;
4377 }
4378 if ( pMac->scan.f11dInfoApplied && !fForce ) break;
Kiet Lam6c583332013-10-14 05:37:09 +05304379 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
4380 pMac, pMac->scan.countryCode11d,
4381 &domainId, COUNTRY_QUERY)))
Jeff Johnson295189b2012-06-20 16:38:30 -07004382 {
4383 //Check whether we need to enforce default domain
4384 if( ( !pMac->roam.configParam.fEnforceDefaultDomain ) ||
4385 (pMac->scan.domainIdCurrent == domainId) )
4386 {
4387
4388#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4389 {
4390 vos_log_802_11d_pkt_type *p11dLog;
4391 tChannelListWithPower chnPwrInfo[WNI_CFG_VALID_CHANNEL_LIST_LEN];
4392 tANI_U32 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN, nTmp;
4393
4394 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
4395 if(p11dLog)
4396 {
4397 p11dLog->eventId = WLAN_80211D_EVENT_COUNTRY_SET;
Kiet Lam64c1b492013-07-12 13:56:44 +05304398 vos_mem_copy(p11dLog->countryCode, pMac->scan.countryCode11d, 3);
Jeff Johnson295189b2012-06-20 16:38:30 -07004399 p11dLog->numChannel = pMac->scan.channels11d.numChannels;
4400 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
4401 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304402 vos_mem_copy(p11dLog->Channels,
4403 pMac->scan.channels11d.channelList,
4404 p11dLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07004405 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList24,
4406 &nChnInfo, chnPwrInfo);
4407 nTmp = nChnInfo;
4408 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN - nTmp;
4409 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList5G,
4410 &nChnInfo, &chnPwrInfo[nTmp]);
4411 for(nTmp = 0; nTmp < p11dLog->numChannel; nTmp++)
4412 {
4413 for(nChnInfo = 0; nChnInfo < WNI_CFG_VALID_CHANNEL_LIST_LEN; nChnInfo++)
4414 {
4415 if(p11dLog->Channels[nTmp] == chnPwrInfo[nChnInfo].chanId)
4416 {
4417 p11dLog->TxPwr[nTmp] = chnPwrInfo[nChnInfo].pwr;
4418 break;
4419 }
4420 }
4421 }
4422 }
4423 if(!pMac->roam.configParam.Is11dSupportEnabled)
4424 {
4425 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
4426 }
4427 else if(pMac->roam.configParam.fEnforceDefaultDomain)
4428 {
4429 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
4430 }
4431 else
4432 {
4433 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
4434 }
4435 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
4436 }
4437 }
4438#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4439 if(pMac->scan.domainIdCurrent != domainId)
4440 {
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05304441 smsLog(pMac, LOGW, FL("Domain Changed Old %s (%d), new %s"),
4442 voss_DomainIdtoString(pMac->scan.domainIdCurrent),
4443 pMac->scan.domainIdCurrent,
4444 voss_DomainIdtoString(domainId));
Abhishek Singha306a442013-11-07 18:39:01 +05304445 status = WDA_SetRegDomain(pMac, domainId, eSIR_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07004446 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004447 if (status != eHAL_STATUS_SUCCESS)
4448 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004449 smsLog( pMac, LOGE, FL(" fail to set regId %d"), domainId );
Jeff Johnson295189b2012-06-20 16:38:30 -07004450 }
4451 pMac->scan.domainIdCurrent = domainId;
Kiet Lam6c583332013-10-14 05:37:09 +05304452#ifndef CONFIG_ENABLE_LINUX_REG
Kiet Lambb14e952013-11-19 14:58:29 +05304453 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.base20MHzChannels,
4454 pMac->scan.countryCodeCurrent, eANI_BOOLEAN_TRUE );
Kiet Lam6c583332013-10-14 05:37:09 +05304455#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004456 // switch to active scans using this new channel list
4457 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
4458 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_TRUE;
4459 pMac->scan.f11dInfoReset = eANI_BOOLEAN_FALSE;
4460 }
4461 }
4462
4463 } while( 0 );
4464
4465 return;
4466}
4467
4468
4469
4470tANI_BOOLEAN csrSave11dCountryString( tpAniSirGlobal pMac, tANI_U8 *pCountryCode,
4471 tANI_BOOLEAN fForce)
4472{
4473 tANI_BOOLEAN fCountryStringChanged = FALSE, fUnknownCountryCode = FALSE;
4474 tANI_U32 i;
Kiet Lam6c583332013-10-14 05:37:09 +05304475 v_REGDOMAIN_t regd;
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004476 tANI_BOOLEAN fCountryNotPresentInDriver = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004477
4478 // convert to UPPER here so we are assured the strings are always in upper case.
4479 for( i = 0; i < 3; i++ )
4480 {
4481 pCountryCode[ i ] = (tANI_U8)csrToUpper( pCountryCode[ i ] );
4482 }
4483
4484 // Some of the 'old' Cisco 350 series AP's advertise NA as the country code (for North America ??).
4485 // NA is not a valid country code or domain so let's allow this by changing it to the proper
4486 // country code (which is US). We've also seen some NETGEAR AP's that have "XX " as the country code
4487 // with valid 2.4 GHz US channel information. If we cannot find the country code advertised in the
4488 // 11d information element, let's default to US.
Kiet Lam6c583332013-10-14 05:37:09 +05304489 if ( !HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(pMac,
4490 pCountryCode,
4491 &regd,
4492 COUNTRY_QUERY) ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07004493 {
4494 // Check the enforcement first
4495 if( pMac->roam.configParam.fEnforceDefaultDomain || pMac->roam.configParam.fEnforceCountryCodeMatch )
4496 {
4497 fUnknownCountryCode = TRUE;
4498 }
4499 else
4500 {
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004501 fCountryNotPresentInDriver = TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004502 }
4503 }
Tushnim Bhattacharyyac3c1e8e2013-10-29 17:27:43 -07004504 //right now, even if we don't find the CC in driver we set to world. Making
4505 //sure countryCode11d doesn't get updated with the invalid CC, instead
4506 //reflect the world CC
4507 else if (REGDOMAIN_WORLD == regd)
4508 {
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004509 fCountryNotPresentInDriver = TRUE;
Tushnim Bhattacharyyac3c1e8e2013-10-29 17:27:43 -07004510 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004511
4512 // We've seen some of the AP's improperly put a 0 for the third character of the country code.
4513 // spec says valid charcters are 'O' (for outdoor), 'I' for Indoor, or ' ' (space; for either).
4514 // if we see a 0 in this third character, let's change it to a ' '.
4515 if ( 0 == pCountryCode[ 2 ] )
4516 {
4517 pCountryCode[ 2 ] = ' ';
4518 }
4519
4520 if( !fUnknownCountryCode )
4521 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304522 fCountryStringChanged = (!vos_mem_compare(pMac->scan.countryCode11d, pCountryCode, 2));
Jeff Johnson295189b2012-06-20 16:38:30 -07004523
4524
4525 if(( 0 == pMac->scan.countryCode11d[ 0 ] && 0 == pMac->scan.countryCode11d[ 1 ] )
4526 || (fForce))
4527 {
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004528 if (!fCountryNotPresentInDriver)
4529 {
4530 // this is the first .11d information
4531 vos_mem_copy(pMac->scan.countryCode11d, pCountryCode,
Kiet Lam64c1b492013-07-12 13:56:44 +05304532 sizeof( pMac->scan.countryCode11d ));
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004533
4534 }
4535 else
4536 {
4537 pMac->scan.countryCode11d[0] = '0';
4538 pMac->scan.countryCode11d[1] = '0';
4539 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004540 }
4541 }
4542
4543 return( fCountryStringChanged );
4544}
4545
4546
4547void csrSaveChannelPowerForBand( tpAniSirGlobal pMac, tANI_BOOLEAN fPopulate5GBand )
4548{
4549 tANI_U32 Index, count=0;
4550 tSirMacChanInfo *pChanInfo;
4551 tSirMacChanInfo *pChanInfoStart;
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08004552 tANI_S32 maxChannelIndex;
4553
4554 maxChannelIndex = ( pMac->scan.base20MHzChannels.numChannels < WNI_CFG_VALID_CHANNEL_LIST_LEN ) ?
4555 pMac->scan.base20MHzChannels.numChannels : WNI_CFG_VALID_CHANNEL_LIST_LEN ;
Jeff Johnson295189b2012-06-20 16:38:30 -07004556
Kiet Lam64c1b492013-07-12 13:56:44 +05304557 pChanInfo = vos_mem_malloc(sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN);
4558 if ( NULL != pChanInfo )
Jeff Johnson295189b2012-06-20 16:38:30 -07004559 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304560 vos_mem_set(pChanInfo, sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004561 pChanInfoStart = pChanInfo;
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08004562 for (Index=0; Index < maxChannelIndex; Index++)
Jeff Johnson295189b2012-06-20 16:38:30 -07004563 {
4564 if ((fPopulate5GBand && (CSR_IS_CHANNEL_5GHZ(pMac->scan.defaultPowerTable[Index].chanId))) ||
4565 (!fPopulate5GBand && (CSR_IS_CHANNEL_24GHZ(pMac->scan.defaultPowerTable[Index].chanId))) )
4566 {
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08004567 if(count >= WNI_CFG_VALID_CHANNEL_LIST_LEN)
4568 {
4569 smsLog( pMac, LOGW, FL(" csrSaveChannelPowerForBand, count exceeded, count = %d"), count);
4570 break;
4571 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004572 pChanInfo->firstChanNum = pMac->scan.defaultPowerTable[Index].chanId;
4573 pChanInfo->numChannels = 1;
4574 pChanInfo->maxTxPower = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
4575 pChanInfo++;
4576 count++;
4577 }
4578 }
4579 if(count)
4580 {
4581 csrSaveToChannelPower2G_5G( pMac, count * sizeof(tSirMacChanInfo), pChanInfoStart );
4582 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304583 vos_mem_free(pChanInfoStart);
Jeff Johnson295189b2012-06-20 16:38:30 -07004584 }
4585}
4586
4587
4588void csrSetOppositeBandChannelInfo( tpAniSirGlobal pMac )
4589{
4590 tANI_BOOLEAN fPopulate5GBand = FALSE;
4591
4592 do
4593 {
4594 // if this is not a dual band product, then we don't need to set the opposite
4595 // band info. We only work in one band so no need to look in the other band.
4596 if ( !CSR_IS_OPEARTING_DUAL_BAND( pMac ) ) break;
4597 // if we found channel info on the 5.0 band and...
4598 if ( CSR_IS_CHANNEL_5GHZ( pMac->scan.channelOf11dInfo ) )
4599 {
4600 // and the 2.4 band is empty, then populate the 2.4 channel info
Kiet Lam8d985a02013-10-11 03:39:41 +05304601 if ( !csrLLIsListEmpty( &pMac->scan.channelPowerInfoList24, LL_ACCESS_LOCK ) ) break;
Jeff Johnson295189b2012-06-20 16:38:30 -07004602 fPopulate5GBand = FALSE;
4603 }
4604 else
4605 {
4606 // else, we found channel info in the 2.4 GHz band. If the 5.0 band is empty
4607 // set the 5.0 band info from the 2.4 country code.
Kiet Lam8d985a02013-10-11 03:39:41 +05304608 if ( !csrLLIsListEmpty( &pMac->scan.channelPowerInfoList5G, LL_ACCESS_LOCK ) ) break;
Jeff Johnson295189b2012-06-20 16:38:30 -07004609 fPopulate5GBand = TRUE;
4610 }
4611 csrSaveChannelPowerForBand( pMac, fPopulate5GBand );
4612
4613 } while( 0 );
4614}
4615
4616
4617tANI_BOOLEAN csrIsSupportedChannel(tpAniSirGlobal pMac, tANI_U8 channelId)
4618{
4619 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
4620 tANI_U32 i;
4621
4622 //Make sure it is a channel that is in our supported list.
4623 for ( i = 0; i < pMac->scan.baseChannels.numChannels; i++ )
4624 {
4625 if ( channelId == pMac->scan.baseChannels.channelList[i] )
4626 {
4627 fRet = eANI_BOOLEAN_TRUE;
4628 break;
4629 }
4630 }
4631
4632 //If it is configured to limit a set of the channels
4633 if( fRet && pMac->roam.configParam.fEnforce11dChannels )
4634 {
4635 fRet = eANI_BOOLEAN_FALSE;
4636 for ( i = 0; i < pMac->scan.base20MHzChannels.numChannels; i++ )
4637 {
4638 if ( channelId == pMac->scan.base20MHzChannels.channelList[i] )
4639 {
4640 fRet = eANI_BOOLEAN_TRUE;
4641 break;
4642 }
4643 }
4644 }
4645
4646 return (fRet);
4647}
4648
4649
4650
4651//bSize specify the buffer size of pChannelList
4652tANI_U8 csrGetChannelListFromChannelSet( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 bSize, tCsrChannelPowerInfo *pChannelSet )
4653{
4654 tANI_U8 i, j = 0, chnId;
4655
4656 bSize = CSR_MIN(bSize, pChannelSet->numChannels);
4657 for( i = 0; i < bSize; i++ )
4658 {
4659 chnId = (tANI_U8)(pChannelSet->firstChannel + ( i * pChannelSet->interChannelOffset ));
4660 if ( csrIsSupportedChannel( pMac, chnId ) )
4661 {
4662 pChannelList[j++] = chnId;
4663 }
4664 }
4665
4666 return (j);
4667}
4668
4669
4670
4671//bSize -- specify the buffer size of pChannelList
4672void csrConstructCurrentValidChannelList( tpAniSirGlobal pMac, tDblLinkList *pChannelSetList,
4673 tANI_U8 *pChannelList, tANI_U8 bSize, tANI_U8 *pNumChannels )
4674{
4675 tListElem *pEntry;
4676 tCsrChannelPowerInfo *pChannelSet;
4677 tANI_U8 numChannels;
4678 tANI_U8 *pChannels;
4679
4680 if( pChannelSetList && pChannelList && pNumChannels )
4681 {
4682 pChannels = pChannelList;
4683 *pNumChannels = 0;
4684 pEntry = csrLLPeekHead( pChannelSetList, LL_ACCESS_LOCK );
4685 while( pEntry )
4686 {
4687 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
4688 numChannels = csrGetChannelListFromChannelSet( pMac, pChannels, bSize, pChannelSet );
4689 pChannels += numChannels;
4690 *pNumChannels += numChannels;
4691 pEntry = csrLLNext( pChannelSetList, pEntry, LL_ACCESS_LOCK );
4692 }
4693 }
4694}
4695
4696
4697/*
4698 * 802.11D only: Gather 11d IE via beacon or Probe response and store them in pAdapter->channels11d
4699*/
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304700tANI_BOOLEAN csrLearnCountryInformation( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc,
4701 tDot11fBeaconIEs *pIes, tANI_BOOLEAN fForce)
Jeff Johnson295189b2012-06-20 16:38:30 -07004702{
Agarwal Ashish60a37ee2014-05-28 17:20:20 +05304703 eHalStatus status;
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304704 tANI_U8 *pCountryCodeSelected;
Jeff Johnson295189b2012-06-20 16:38:30 -07004705 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
4706 v_REGDOMAIN_t domainId;
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304707 tDot11fBeaconIEs *pIesLocal = pIes;
4708 tANI_BOOLEAN useVoting = eANI_BOOLEAN_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004709
Jeff Johnson295189b2012-06-20 16:38:30 -07004710 if (VOS_STA_SAP_MODE == vos_get_conparam ())
4711 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07004712
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304713 if ((NULL == pSirBssDesc) && (NULL == pIes))
4714 useVoting = eANI_BOOLEAN_TRUE;
4715
Jeff Johnson295189b2012-06-20 16:38:30 -07004716 do
4717 {
4718 // check if .11d support is enabled
4719 if( !csrIs11dSupported( pMac ) ) break;
Agarwal Ashish60a37ee2014-05-28 17:20:20 +05304720
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304721 if (eANI_BOOLEAN_FALSE == useVoting)
4722 {
4723 if( !pIesLocal &&
4724 (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
4725 pSirBssDesc, &pIesLocal))))
4726 {
4727 break;
4728 }
4729 // check if country information element is present
4730 if(!pIesLocal->Country.present)
4731 {
4732 //No country info
4733 break;
4734 }
4735
4736 if( HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry
4737 (pMac, pIesLocal->Country.country, &domainId,
4738 COUNTRY_QUERY)) &&
4739 ( domainId == REGDOMAIN_WORLD))
4740 {
4741 break;
4742 }
4743 } //useVoting == eANI_BOOLEAN_FALSE
4744
4745 if (eANI_BOOLEAN_FALSE == useVoting)
4746 pCountryCodeSelected = pIesLocal->Country.country;
4747 else
4748 pCountryCodeSelected = pMac->scan.countryCodeElected;
4749
Kiet Lam8d985a02013-10-11 03:39:41 +05304750 status = csrGetRegulatoryDomainForCountry(pMac,
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304751 pCountryCodeSelected, &domainId, COUNTRY_IE);
Kiet Lam8d985a02013-10-11 03:39:41 +05304752 if ( status != eHAL_STATUS_SUCCESS )
4753 {
4754 smsLog( pMac, LOGE, FL(" fail to get regId %d"), domainId );
4755 fRet = eANI_BOOLEAN_FALSE;
4756 break;
4757 }
Agarwal Ashish7693f2d2014-07-18 18:03:58 +05304758
4759 /* updating 11d Country Code with Country code selected. */
4760
4761 vos_mem_copy(pMac->scan.countryCode11d,
4762 pCountryCodeSelected,
4763 WNI_CFG_COUNTRY_CODE_LEN);
4764
Agarwal Ashish60a37ee2014-05-28 17:20:20 +05304765#ifndef CONFIG_ENABLE_LINUX_REG
Venkata Prathyusha Kuntupalli316247e2013-03-15 17:45:25 -07004766 // Checking for Domain Id change
4767 if ( domainId != pMac->scan.domainIdCurrent )
4768 {
Kiet Lam8d985a02013-10-11 03:39:41 +05304769 vos_mem_copy(pMac->scan.countryCode11d,
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304770 pCountryCodeSelected,
Kiet Lam8d985a02013-10-11 03:39:41 +05304771 sizeof( pMac->scan.countryCode11d ) );
4772 /* Set Current Country code and Current Regulatory domain */
4773 status = csrSetRegulatoryDomain(pMac, domainId, NULL);
4774 if (eHAL_STATUS_SUCCESS != status)
4775 {
4776 smsLog(pMac, LOGE, "Set Reg Domain Fail %d", status);
4777 fRet = eANI_BOOLEAN_FALSE;
4778 return fRet;
4779 }
4780 //csrSetRegulatoryDomain will fail if the country doesn't fit our domain criteria.
4781 vos_mem_copy(pMac->scan.countryCodeCurrent,
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304782 pCountryCodeSelected, WNI_CFG_COUNTRY_CODE_LEN);
Kiet Lam8d985a02013-10-11 03:39:41 +05304783 //Simply set it to cfg.
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304784 csrSetCfgCountryCode(pMac, pCountryCodeSelected);
Kiet Lam8d985a02013-10-11 03:39:41 +05304785
4786 /* overwrite the defualt country code */
4787 vos_mem_copy(pMac->scan.countryCodeDefault,
4788 pMac->scan.countryCodeCurrent,
4789 WNI_CFG_COUNTRY_CODE_LEN);
4790 /* Set Current RegDomain */
Abhishek Singha306a442013-11-07 18:39:01 +05304791 status = WDA_SetRegDomain(pMac, domainId, eSIR_TRUE);
Kiet Lam8d985a02013-10-11 03:39:41 +05304792 if ( status != eHAL_STATUS_SUCCESS )
4793 {
4794 smsLog( pMac, LOGE, FL(" fail to Set regId %d"), domainId );
4795 fRet = eANI_BOOLEAN_FALSE;
4796 return fRet;
4797 }
4798 /* set to default domain ID */
Madan Mohan Koyyalamudi0e5922d2013-09-10 15:45:24 +05304799 pMac->scan.domainIdCurrent = domainId;
Kiet Lam8d985a02013-10-11 03:39:41 +05304800 /* get the channels based on new cc */
4801 status = csrInitGetChannels( pMac );
Jeff Johnson295189b2012-06-20 16:38:30 -07004802
Kiet Lam8d985a02013-10-11 03:39:41 +05304803 if ( status != eHAL_STATUS_SUCCESS )
4804 {
4805 smsLog( pMac, LOGE, FL(" fail to get Channels "));
4806 fRet = eANI_BOOLEAN_FALSE;
4807 return fRet;
4808 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004809
Kiet Lam8d985a02013-10-11 03:39:41 +05304810 /* reset info based on new cc, and we are done */
4811 csrResetCountryInformation(pMac, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
Agarwal Ashishfaef6692014-01-29 19:40:30 +05304812 /* Regulatory Domain Changed, Purge Only scan result
4813 * which does not have channel number belong to 11d
4814 * channel list
4815 */
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05304816 csrScanFilterResults(pMac);
Kiet Lam8d985a02013-10-11 03:39:41 +05304817 }
Kiet Lam6c583332013-10-14 05:37:09 +05304818#endif
4819 fRet = eANI_BOOLEAN_TRUE;
4820
Jeff Johnson295189b2012-06-20 16:38:30 -07004821 } while( 0 );
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304822
4823 if( !pIes && pIesLocal )
4824 {
4825 //locally allocated
4826 vos_mem_free(pIesLocal);
4827 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004828
4829 return( fRet );
4830}
4831
4832
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004833static void csrSaveScanResults( tpAniSirGlobal pMac, tANI_U8 reason )
Jeff Johnson295189b2012-06-20 16:38:30 -07004834{
4835 // initialize this to FALSE. profMoveInterimScanResultsToMainList() routine
4836 // will set this to the channel where an .11d beacon is seen
4837 pMac->scan.channelOf11dInfo = 0;
4838 // if we get any ambiguous .11d information then this will be set to TRUE
4839 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
4840 //Tush
4841 // if we get any ambiguous .11d information, then this will be set to TRUE
4842 // only if the applied 11d info could be found in one of the scan results
4843 pMac->scan.fCurrent11dInfoMatch = eANI_BOOLEAN_FALSE;
4844 // move the scan results from interim list to the main scan list
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004845 csrMoveTempScanResultsToMainList( pMac, reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07004846}
4847
4848
4849void csrReinitScanCmd(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4850{
4851 switch (pCommand->u.scanCmd.reason)
4852 {
4853 case eCsrScanSetBGScanParam:
4854 case eCsrScanAbortBgScan:
4855 if(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList)
4856 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304857 vos_mem_free(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList);
Jeff Johnson295189b2012-06-20 16:38:30 -07004858 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
4859 }
4860 break;
4861 case eCsrScanBGScanAbort:
4862 case eCsrScanBGScanEnable:
4863 case eCsrScanGetScanChnInfo:
4864 break;
4865 case eCsrScanAbortNormalScan:
4866 default:
4867 csrScanFreeRequest(pMac, &pCommand->u.scanCmd.u.scanRequest);
4868 break;
4869 }
4870 if(pCommand->u.scanCmd.pToRoamProfile)
4871 {
4872 csrReleaseProfile(pMac, pCommand->u.scanCmd.pToRoamProfile);
Kiet Lam64c1b492013-07-12 13:56:44 +05304873 vos_mem_free(pCommand->u.scanCmd.pToRoamProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07004874 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304875 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004876}
4877
4878
4879tANI_BOOLEAN csrGetRemainingChannelsFor11dScan( tpAniSirGlobal pMac, tANI_U8 *pChannels, tANI_U8 *pcChannels )
4880{
4881 tANI_U32 index11dChannels, index;
4882 tANI_U32 indexCurrentChannels;
4883 tANI_BOOLEAN fChannelAlreadyScanned;
4884 tANI_U32 len = sizeof(pMac->roam.validChannelList);
4885
4886 *pcChannels = 0;
4887 if ( CSR_IS_11D_INFO_FOUND(pMac) && csrRoamIsChannelValid(pMac, pMac->scan.channelOf11dInfo) )
4888 {
4889 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
4890 {
4891 //Find the channel index where we found the 11d info
4892 for(index = 0; index < len; index++)
4893 {
4894 if(pMac->scan.channelOf11dInfo == pMac->roam.validChannelList[index])
4895 break;
4896 }
4897 //check whether we found the channel index
4898 if(index < len)
4899 {
4900 // Now, look through the 11d channel list and create a list of all channels in the 11d list that are
4901 // NOT in the current channel list. This gives us a list of the new channels that have not been
4902 // scanned. We'll scan this new list so we have a complete set of scan results on all of the domain channels
4903 // initially.
4904 for ( index11dChannels = 0; index11dChannels < pMac->scan.channels11d.numChannels; index11dChannels++ )
4905 {
4906 fChannelAlreadyScanned = eANI_BOOLEAN_FALSE;
4907
4908 for( indexCurrentChannels = 0; indexCurrentChannels < index; indexCurrentChannels++ )
4909 {
4910 if ( pMac->roam.validChannelList[ indexCurrentChannels ] == pMac->scan.channels11d.channelList[ index11dChannels ] )
4911 {
4912 fChannelAlreadyScanned = eANI_BOOLEAN_TRUE;
4913 break;
4914 }
4915 }
4916
4917 if ( !fChannelAlreadyScanned )
4918 {
4919 pChannels[ *pcChannels ] = pMac->scan.channels11d.channelList[ index11dChannels ];
4920 ( *pcChannels )++;
4921 }
4922 }
4923 }
4924 }//GetCFG
4925 }
4926 return( *pcChannels );
4927}
4928
4929
4930eCsrScanCompleteNextCommand csrScanGetNextCommandState( tpAniSirGlobal pMac, tSmeCmd *pCommand, tANI_BOOLEAN fSuccess )
4931{
4932 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
4933
4934 switch( pCommand->u.scanCmd.reason )
4935 {
4936 case eCsrScan11d1:
4937 NextCommand = (fSuccess) ? eCsrNext11dScan1Success : eCsrNext11dScan1Failure;
4938 break;
4939 case eCsrScan11d2:
4940 NextCommand = (fSuccess) ? eCsrNext11dScan2Success : eCsrNext11dScan2Failure;
4941 break;
4942 case eCsrScan11dDone:
4943 NextCommand = eCsrNext11dScanComplete;
4944 break;
4945 case eCsrScanLostLink1:
4946 NextCommand = (fSuccess) ? eCsrNextLostLinkScan1Success : eCsrNextLostLinkScan1Failed;
4947 break;
4948 case eCsrScanLostLink2:
4949 NextCommand = (fSuccess) ? eCsrNextLostLinkScan2Success : eCsrNextLostLinkScan2Failed;
4950 break;
4951 case eCsrScanLostLink3:
4952 NextCommand = (fSuccess) ? eCsrNextLostLinkScan3Success : eCsrNextLostLinkScan3Failed;
4953 break;
4954 case eCsrScanForSsid:
4955 NextCommand = (fSuccess) ? eCsrNexteScanForSsidSuccess : eCsrNexteScanForSsidFailure;
4956 break;
4957 case eCsrScanForCapsChange:
4958 NextCommand = eCsrNextCapChangeScanComplete; //don't care success or not
4959 break;
4960 case eCsrScanIdleScan:
4961 NextCommand = eCsrNextIdleScanComplete;
4962 break;
4963 default:
4964 NextCommand = eCsrNextScanNothing;
4965 break;
4966 }
4967 return( NextCommand );
4968}
4969
4970
4971//Return whether the pCommand is finished.
4972tANI_BOOLEAN csrHandleScan11d1Failure(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4973{
4974 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
4975
4976 //Apply back the default setting and passively scan one more time.
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004977 csrResetCountryInformation(pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07004978 pCommand->u.scanCmd.reason = eCsrScan11d2;
4979 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
4980 {
4981 fRet = eANI_BOOLEAN_FALSE;
4982 }
4983
4984 return (fRet);
4985}
4986
4987
4988tANI_BOOLEAN csrHandleScan11dSuccess(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4989{
4990 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
4991 tANI_U8 *pChannels;
4992 tANI_U8 cChannels;
4993
Kiet Lam64c1b492013-07-12 13:56:44 +05304994 pChannels = vos_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
4995 if ( NULL != pChannels )
Jeff Johnson295189b2012-06-20 16:38:30 -07004996 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304997 vos_mem_set(pChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004998 if ( csrGetRemainingChannelsFor11dScan( pMac, pChannels, &cChannels ) )
4999 {
5000 pCommand->u.scanCmd.reason = eCsrScan11dDone;
5001 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
5002 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305003 vos_mem_free(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -07005004 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07005005 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305006 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(cChannels);
5007 if ( NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07005008 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305009 vos_mem_copy(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
5010 pChannels, cChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07005011 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = cChannels;
5012 pCommand->u.scanCmd.u.scanRequest.requestType = eCSR_SCAN_REQUEST_FULL_SCAN;
5013 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
5014 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
5015 {
5016 //Reuse the same command buffer
5017 fRet = eANI_BOOLEAN_FALSE;
5018 }
5019 }
5020 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305021 vos_mem_free(pChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07005022 }
5023
5024 return (fRet);
5025}
5026
5027//Return whether the command should be removed
5028tANI_BOOLEAN csrScanComplete( tpAniSirGlobal pMac, tSirSmeScanRsp *pScanRsp )
5029{
5030 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
5031 tListElem *pEntry;
5032 tSmeCmd *pCommand;
5033 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
5034 tANI_BOOLEAN fSuccess;
5035
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305036 if (pMac->fScanOffload)
5037 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
5038 else
5039 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07005040
5041 if ( pEntry )
5042 {
5043 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
5044
5045 // If the head of the queue is Active and it is a SCAN command, remove
5046 // and put this on the Free queue.
5047 if ( eSmeCommandScan == pCommand->command )
5048 {
5049 tANI_U32 sessionId = pCommand->sessionId;
5050
5051 if(eSIR_SME_SUCCESS != pScanRsp->statusCode)
5052 {
5053 fSuccess = eANI_BOOLEAN_FALSE;
5054 }
5055 else
5056 {
5057 //pMac->scan.tempScanResults is not empty meaning the scan found something
5058 //This check only valid here because csrSaveScanresults is not yet called
5059 fSuccess = (!csrLLIsListEmpty(&pMac->scan.tempScanResults, LL_ACCESS_LOCK));
5060 }
Ratheesh S Pece1f832015-07-25 15:50:25 +05305061 if (pCommand->u.scanCmd.abortScanIndication &
5062 eCSR_SCAN_ABORT_DUE_TO_BAND_CHANGE)
Srinivas, Dasari187ca4e2014-02-07 12:40:09 +05305063 {
5064 /*
5065 * Scan aborted due to band change
5066 * The scan results need to be flushed
5067 */
5068 if (pCommand->u.scanCmd.callback
5069 != pMac->scan.callback11dScanDone)
5070 {
5071 smsLog(pMac, LOG1, FL("Filtering the scan results as the "
5072 "results may belong to wrong band"));
5073 csrScanFilterResults(pMac);
5074 }
5075 else
5076 {
5077 smsLog(pMac, LOG1, FL("11d_scan_done will flush the scan"
5078 " results"));
5079 }
Srinivas, Dasari187ca4e2014-02-07 12:40:09 +05305080 }
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005081 csrSaveScanResults(pMac, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07005082
Agrawal Ashishdf752672015-12-09 17:51:53 +05305083 /* filter scan result based on valid channel list number */
5084 if (pMac->scan.fcc_constraint)
5085 {
5086 smsLog(pMac, LOG1, FL("Clear BSS from invalid channels"));
5087 csrScanFilterResults(pMac);
5088 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005089#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5090 {
5091 vos_log_scan_pkt_type *pScanLog = NULL;
5092 tScanResultHandle hScanResult;
5093 tCsrScanResultInfo *pScanResult;
5094 tDot11fBeaconIEs *pIes;
5095 int n = 0, c = 0;
5096
5097 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
5098 if(pScanLog)
5099 {
5100 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
5101 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
5102 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
5103 {
5104 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_RSP;
5105 }
5106 else
5107 {
5108 if( eSIR_PASSIVE_SCAN != pMac->scan.curScanType )
5109 {
5110 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_RSP;
5111 }
5112 else
5113 {
5114 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_RSP;
5115 }
5116 }
5117 if(eSIR_SME_SUCCESS == pScanRsp->statusCode)
5118 {
5119 if(HAL_STATUS_SUCCESS(csrScanGetResult(pMac, NULL, &hScanResult)))
5120 {
5121 while(((pScanResult = csrScanResultGetNext(pMac, hScanResult)) != NULL))
5122 {
5123 if( n < VOS_LOG_MAX_NUM_BSSID )
5124 {
5125 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pScanResult->BssDescriptor, &pIes)))
5126 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005127 smsLog(pMac, LOGE, FL(" fail to parse IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07005128 break;
5129 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305130 vos_mem_copy(pScanLog->bssid[n],
5131 pScanResult->BssDescriptor.bssId, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07005132 if(pIes && pIes->SSID.present && VOS_LOG_MAX_SSID_SIZE >= pIes->SSID.num_ssid)
5133 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305134 vos_mem_copy(pScanLog->ssid[n],
5135 pIes->SSID.ssid, pIes->SSID.num_ssid);
Jeff Johnson295189b2012-06-20 16:38:30 -07005136 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305137 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07005138 n++;
5139 }
5140 c++;
5141 }
5142 pScanLog->numSsid = (v_U8_t)n;
5143 pScanLog->totalSsid = (v_U8_t)c;
5144 csrScanResultPurge(pMac, hScanResult);
5145 }
5146 }
5147 else
5148 {
5149 pScanLog->status = WLAN_SCAN_STATUS_FAILURE;
5150 }
5151 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
5152 }
5153 }
5154#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5155
5156 NextCommand = csrScanGetNextCommandState(pMac, pCommand, fSuccess);
5157 //We reuse the command here instead reissue a new command
5158 switch(NextCommand)
5159 {
5160 case eCsrNext11dScan1Success:
5161 case eCsrNext11dScan2Success:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005162 smsLog( pMac, LOG2, FL("11dScan1/3 produced results. Reissue Active scan..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07005163 // if we found country information, no need to continue scanning further, bail out
5164 fRemoveCommand = eANI_BOOLEAN_TRUE;
5165 NextCommand = eCsrNext11dScanComplete;
5166 break;
5167 case eCsrNext11dScan1Failure:
5168 //We are not done yet. 11d scan fail once. We will try to reset anything and do it over again
5169 //The only meaningful thing for this retry is that we cannot find 11d information after a reset so
5170 //we clear the "old" 11d info and give it once more chance
5171 fRemoveCommand = csrHandleScan11d1Failure(pMac, pCommand);
5172 if(fRemoveCommand)
5173 {
5174 NextCommand = eCsrNext11dScanComplete;
5175 }
5176 break;
5177 case eCsrNextLostLinkScan1Success:
5178 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink1)))
5179 {
5180 csrScanHandleFailedLostlink1(pMac, sessionId);
5181 }
5182 break;
5183 case eCsrNextLostLinkScan2Success:
5184 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink2)))
5185 {
5186 csrScanHandleFailedLostlink2(pMac, sessionId);
5187 }
5188 break;
5189 case eCsrNextLostLinkScan3Success:
5190 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink3)))
5191 {
5192 csrScanHandleFailedLostlink3(pMac, sessionId);
5193 }
5194 break;
5195 case eCsrNextLostLinkScan1Failed:
5196 csrScanHandleFailedLostlink1(pMac, sessionId);
5197 break;
5198 case eCsrNextLostLinkScan2Failed:
5199 csrScanHandleFailedLostlink2(pMac, sessionId);
5200 break;
5201 case eCsrNextLostLinkScan3Failed:
5202 csrScanHandleFailedLostlink3(pMac, sessionId);
5203 break;
5204 case eCsrNexteScanForSsidSuccess:
5205 csrScanHandleSearchForSSID(pMac, pCommand);
5206 break;
5207 case eCsrNexteScanForSsidFailure:
5208 csrScanHandleSearchForSSIDFailure(pMac, pCommand);
5209 break;
5210 case eCsrNextIdleScanComplete:
5211 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
5212 break;
5213 case eCsrNextCapChangeScanComplete:
5214 csrScanHandleCapChangeScanComplete(pMac, sessionId);
5215 break;
5216 default:
5217
5218 break;
5219 }
5220 }
5221 else
5222 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005223 smsLog( pMac, LOGW, FL("Scan Completion called but SCAN command is not ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07005224 fRemoveCommand = eANI_BOOLEAN_FALSE;
5225 }
5226 }
5227 else
5228 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005229 smsLog( pMac, LOGW, FL("Scan Completion called but NO commands are ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07005230 fRemoveCommand = eANI_BOOLEAN_FALSE;
5231 }
5232
5233 return( fRemoveCommand );
5234}
5235
5236
5237
5238static void csrScanRemoveDupBssDescriptionFromInterimList( tpAniSirGlobal pMac,
5239 tSirBssDescription *pSirBssDescr,
5240 tDot11fBeaconIEs *pIes)
5241{
5242 tListElem *pEntry;
5243 tCsrScanResult *pCsrBssDescription;
5244
5245 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
5246 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
5247 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
5248 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
5249 while( pEntry )
5250 {
5251 pCsrBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
5252
5253 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
5254 // matches
5255
5256 if ( csrIsDuplicateBssDescription( pMac, &pCsrBssDescription->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07005257 pSirBssDescr, pIes, FALSE ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07005258 {
5259 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
5260 ((tANI_S32)pCsrBssDescription->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
5261
5262 // Remove the 'old' entry from the list....
5263 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK ) )
5264 {
5265 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pCsrBssDescription->Result.BssDescriptor);
5266 // we need to free the memory associated with this node
5267 csrFreeScanResultEntry( pMac, pCsrBssDescription );
5268 }
5269
5270 // If we found a match, we can stop looking through the list.
5271 break;
5272 }
5273
5274 pEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK );
5275 }
5276}
5277
5278
5279
5280//Caller allocated memory pfNewBssForConn to return whether new candidate for
5281//current connection is found. Cannot be NULL
5282tCsrScanResult *csrScanSaveBssDescriptionToInterimList( tpAniSirGlobal pMac,
5283 tSirBssDescription *pBSSDescription,
5284 tDot11fBeaconIEs *pIes)
5285{
5286 tCsrScanResult *pCsrBssDescription = NULL;
5287 tANI_U32 cbBSSDesc;
5288 tANI_U32 cbAllocated;
Jeff Johnson295189b2012-06-20 16:38:30 -07005289
5290 // figure out how big the BSS description is (the BSSDesc->length does NOT
5291 // include the size of the length field itself).
5292 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
5293
5294 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
5295
Kiet Lam64c1b492013-07-12 13:56:44 +05305296 pCsrBssDescription = vos_mem_malloc(cbAllocated);
5297 if ( NULL != pCsrBssDescription )
Jeff Johnson295189b2012-06-20 16:38:30 -07005298 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305299 vos_mem_set(pCsrBssDescription, cbAllocated, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005300 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Kiet Lam64c1b492013-07-12 13:56:44 +05305301 vos_mem_copy(&pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc );
Jeff Johnson295189b2012-06-20 16:38:30 -07005302 //Save SSID separately for later use
5303 if( pIes->SSID.present && !csrIsNULLSSID(pIes->SSID.ssid, pIes->SSID.num_ssid) )
5304 {
5305 //SSID not hidden
Madan Mohan Koyyalamudi4e31b132012-11-02 13:13:52 -07005306 tANI_U32 len = pIes->SSID.num_ssid;
Jeff Johnson295189b2012-06-20 16:38:30 -07005307 if (len > SIR_MAC_MAX_SSID_LENGTH)
5308 {
5309 // truncate to fit in our struct
5310 len = SIR_MAC_MAX_SSID_LENGTH;
5311 }
5312 pCsrBssDescription->Result.ssId.length = len;
5313 pCsrBssDescription->Result.timer = vos_timer_get_system_time();
Kiet Lam64c1b492013-07-12 13:56:44 +05305314 vos_mem_copy(pCsrBssDescription->Result.ssId.ssId, pIes->SSID.ssid, len);
Jeff Johnson295189b2012-06-20 16:38:30 -07005315 }
5316 csrLLInsertTail( &pMac->scan.tempScanResults, &pCsrBssDescription->Link, LL_ACCESS_LOCK );
5317 }
5318
5319 return( pCsrBssDescription );
5320}
5321
5322
5323
5324
5325tANI_BOOLEAN csrIsDuplicateBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc1,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07005326 tSirBssDescription *pSirBssDesc2, tDot11fBeaconIEs *pIes2, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07005327{
5328 tANI_BOOLEAN fMatch = FALSE;
5329 tSirMacCapabilityInfo *pCap1, *pCap2;
5330 tDot11fBeaconIEs *pIes1 = NULL;
Jeff Johnsone7245742012-09-05 17:12:55 -07005331 tDot11fBeaconIEs *pIesTemp = pIes2;
Jeff Johnson295189b2012-06-20 16:38:30 -07005332
5333 pCap1 = (tSirMacCapabilityInfo *)&pSirBssDesc1->capabilityInfo;
5334 pCap2 = (tSirMacCapabilityInfo *)&pSirBssDesc2->capabilityInfo;
5335 if(pCap1->ess == pCap2->ess)
5336 {
5337 if (pCap1->ess &&
Jeff Johnsone7245742012-09-05 17:12:55 -07005338 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId)&&
Abhishek Singhe3fa11f2014-05-13 11:11:10 +05305339 (fForced || (vos_chan_to_band(pSirBssDesc1->channelId) == vos_chan_to_band((pSirBssDesc2->channelId)))))
Jeff Johnson295189b2012-06-20 16:38:30 -07005340 {
5341 fMatch = TRUE;
Jeff Johnsone7245742012-09-05 17:12:55 -07005342 // Check for SSID match, if exists
5343 do
5344 {
5345 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
5346 {
5347 break;
5348 }
5349 if( NULL == pIesTemp )
5350 {
5351 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
5352 {
5353 break;
5354 }
5355 }
5356 if(pIes1->SSID.present && pIesTemp->SSID.present)
5357 {
5358 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
5359 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
5360 }
5361 }while(0);
5362
Jeff Johnson295189b2012-06-20 16:38:30 -07005363 }
5364 else if (pCap1->ibss && (pSirBssDesc1->channelId == pSirBssDesc2->channelId))
5365 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005366
5367 do
5368 {
5369 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
5370 {
5371 break;
5372 }
5373 if( NULL == pIesTemp )
5374 {
5375 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
5376 {
5377 break;
5378 }
5379 }
5380 //Same channel cannot have same SSID for different IBSS
5381 if(pIes1->SSID.present && pIesTemp->SSID.present)
5382 {
5383 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
5384 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
5385 }
5386 }while(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005387 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005388 /* In case of P2P devices, ess and ibss will be set to zero */
5389 else if (!pCap1->ess &&
5390 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId))
5391 {
5392 fMatch = TRUE;
5393 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005394 }
5395
5396 if(pIes1)
5397 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305398 vos_mem_free(pIes1);
Jeff Johnson295189b2012-06-20 16:38:30 -07005399 }
Jeff Johnsone7245742012-09-05 17:12:55 -07005400
5401 if( (NULL == pIes2) && pIesTemp )
5402 {
5403 //locally allocated
Kiet Lam64c1b492013-07-12 13:56:44 +05305404 vos_mem_free(pIesTemp);
Jeff Johnsone7245742012-09-05 17:12:55 -07005405 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005406
5407 return( fMatch );
5408}
5409
5410
5411tANI_BOOLEAN csrIsNetworkTypeEqual( tSirBssDescription *pSirBssDesc1, tSirBssDescription *pSirBssDesc2 )
5412{
5413 return( pSirBssDesc1->nwType == pSirBssDesc2->nwType );
5414}
5415
5416
5417//to check whether the BSS matches the dot11Mode
5418static tANI_BOOLEAN csrScanIsBssAllowed(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
5419 tDot11fBeaconIEs *pIes)
5420{
5421 tANI_BOOLEAN fAllowed = eANI_BOOLEAN_FALSE;
5422 eCsrPhyMode phyMode;
5423
5424 if(HAL_STATUS_SUCCESS(csrGetPhyModeFromBss(pMac, pBssDesc, &phyMode, pIes)))
5425 {
5426 switch(pMac->roam.configParam.phyMode)
5427 {
5428 case eCSR_DOT11_MODE_11b:
5429 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
5430 break;
5431 case eCSR_DOT11_MODE_11g:
5432 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
5433 break;
5434 case eCSR_DOT11_MODE_11g_ONLY:
5435 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11g == phyMode);
5436 break;
5437 case eCSR_DOT11_MODE_11a:
5438 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11b != phyMode) && (eCSR_DOT11_MODE_11g != phyMode));
5439 break;
5440 case eCSR_DOT11_MODE_11n_ONLY:
5441 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11n == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
5442 break;
Jeff Johnsone7245742012-09-05 17:12:55 -07005443
5444#ifdef WLAN_FEATURE_11AC
5445 case eCSR_DOT11_MODE_11ac_ONLY:
5446 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11ac == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
5447 break;
5448#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005449 case eCSR_DOT11_MODE_11b_ONLY:
5450 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11b == phyMode);
5451 break;
5452 case eCSR_DOT11_MODE_11a_ONLY:
5453 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a == phyMode);
5454 break;
5455 case eCSR_DOT11_MODE_11n:
Jeff Johnsone7245742012-09-05 17:12:55 -07005456#ifdef WLAN_FEATURE_11AC
5457 case eCSR_DOT11_MODE_11ac:
5458#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005459 case eCSR_DOT11_MODE_TAURUS:
5460 default:
5461 fAllowed = eANI_BOOLEAN_TRUE;
5462 break;
5463 }
5464 }
5465
5466 return (fAllowed);
5467}
5468
5469
5470
5471//Return pIes to caller for future use when returning TRUE.
5472static tANI_BOOLEAN csrScanValidateScanResult( tpAniSirGlobal pMac, tANI_U8 *pChannels,
5473 tANI_U8 numChn, tSirBssDescription *pBssDesc,
5474 tDot11fBeaconIEs **ppIes )
5475{
5476 tANI_BOOLEAN fValidChannel = FALSE;
5477 tDot11fBeaconIEs *pIes = NULL;
5478 tANI_U8 index;
5479
5480 for( index = 0; index < numChn; index++ )
5481 {
5482 // This check relies on the fact that a single BSS description is returned in each
5483 // ScanRsp call, which is the way LIM implemented the scan req/rsp funtions. We changed
5484 // to this model when we ran with a large number of APs. If this were to change, then
5485 // this check would have to mess with removing the bssDescription from somewhere in an
5486 // arbitrary index in the bssDescription array.
5487 if ( pChannels[ index ] == pBssDesc->channelId )
5488 {
5489 fValidChannel = TRUE;
5490 break;
5491 }
5492 }
5493 *ppIes = NULL;
5494 if(fValidChannel)
5495 {
5496 if( HAL_STATUS_SUCCESS( csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIes) ) )
5497 {
5498 fValidChannel = csrScanIsBssAllowed(pMac, pBssDesc, pIes);
5499 if( fValidChannel )
5500 {
5501 *ppIes = pIes;
5502 }
5503 else
5504 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305505 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07005506 }
5507 }
5508 else
5509 {
5510 fValidChannel = FALSE;
5511 }
5512 }
5513
5514 return( fValidChannel );
5515}
5516
5517
5518//Return whether last scan result is received
5519static tANI_BOOLEAN csrScanProcessScanResults( tpAniSirGlobal pMac, tSmeCmd *pCommand,
5520 tSirSmeScanRsp *pScanRsp, tANI_BOOLEAN *pfRemoveCommand )
5521{
5522 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE, fRemoveCommand = eANI_BOOLEAN_FALSE;
5523 tDot11fBeaconIEs *pIes = NULL;
5524 tANI_U32 cbParsed;
5525 tSirBssDescription *pSirBssDescription;
5526 tANI_U32 cbBssDesc;
Agrawal Ashish4cc15bb2016-02-04 17:56:16 +05305527 eHalStatus status;
Jeff Johnson295189b2012-06-20 16:38:30 -07005528 tANI_U32 cbScanResult = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription )
5529 + sizeof(tSirBssDescription); //We need at least one CB
5530
5531 // don't consider the scan rsp to be valid if the status code is Scan Failure. Scan Failure
5532 // is returned when the scan could not find anything. so if we get scan failure return that
5533 // the scan response is invalid. Also check the lenght in the scan result for valid scan
5534 // BssDescriptions....
5535 do
5536 {
5537 if ( ( cbScanResult <= pScanRsp->length ) &&
5538 (( eSIR_SME_SUCCESS == pScanRsp->statusCode ) ||
5539 ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW == pScanRsp->statusCode ) ) )
5540 {
5541 tANI_U8 *pChannelList = NULL;
5542 tANI_U8 cChannels = 0;
5543
5544 //Different scan type can reach this point, we need to distinguish it
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005545#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5546 if( eCsrScanGetLfrResult == pCommand->u.scanCmd.reason )
5547 {
5548 pChannelList = NULL;
5549 cChannels = 0;
5550 }
5551 else
5552#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005553 if( eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason )
5554 {
5555 //eCsrScanSetBGScanParam uses different structure
5556 tCsrBGScanRequest *pBgScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
5557
5558 cChannels = pBgScanReq->ChannelInfo.numOfChannels;
5559 pChannelList = pBgScanReq->ChannelInfo.ChannelList;
5560 }
5561 else
5562 {
5563 //the rest use generic scan request
5564 cChannels = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
5565 pChannelList = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
5566 }
5567
5568 // if the scan result is not on one of the channels in the Valid channel list, then it
5569 // must have come from an AP on an overlapping channel (in the 2.4GHz band). In this case,
5570 // let's drop the scan result.
5571 //
5572 // The other situation is where the scan request is for a scan on a particular channel set
5573 // and the scan result is from a
5574
5575 // if the NumChannels is 0, then we are supposed to be scanning all channels. Use the full channel
5576 // list as the 'valid' channel list. Otherwise, use the specific channel list in the scan parms
5577 // as the valid channels.
5578 if ( 0 == cChannels )
5579 {
5580 tANI_U32 len = sizeof(pMac->roam.validChannelList);
5581
5582 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
5583 {
5584 pChannelList = pMac->roam.validChannelList;
5585 cChannels = (tANI_U8)len;
5586 }
5587 else
5588 {
5589 //Cannot continue
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005590 smsLog( pMac, LOGE, "CSR: Processing internal SCAN results...csrGetCfgValidChannels failed" );
Jeff Johnson295189b2012-06-20 16:38:30 -07005591 break;
5592 }
5593 }
5594
5595 smsLog( pMac, LOG2, "CSR: Processing internal SCAN results..." );
5596 cbParsed = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription );
5597 pSirBssDescription = pScanRsp->bssDescription;
5598 while( cbParsed < pScanRsp->length )
5599 {
5600 if ( csrScanValidateScanResult( pMac, pChannelList, cChannels, pSirBssDescription, &pIes ) )
5601 {
5602 csrScanRemoveDupBssDescriptionFromInterimList(pMac, pSirBssDescription, pIes);
5603 csrScanSaveBssDescriptionToInterimList( pMac, pSirBssDescription, pIes );
5604 if( eSIR_PASSIVE_SCAN == pMac->scan.curScanType )
5605 {
5606 if( csrIs11dSupported( pMac) )
5607 {
5608 //Check whether the BSS is acceptable base on 11d info and our configs.
5609 if( csrMatchCountryCode( pMac, NULL, pIes ) )
5610 {
5611 //Double check whether the channel is acceptable by us.
5612 if( csrIsSupportedChannel( pMac, pSirBssDescription->channelId ) )
5613 {
5614 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
5615 }
5616 }
5617 }
5618 else
5619 {
5620 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
5621 }
5622 }
5623 //Free the resource
Kiet Lam64c1b492013-07-12 13:56:44 +05305624 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07005625 }
5626 // skip over the BSS description to the next one...
5627 cbBssDesc = pSirBssDescription->length + sizeof( pSirBssDescription->length );
5628
5629 cbParsed += cbBssDesc;
5630 pSirBssDescription = (tSirBssDescription *)((tANI_U8 *)pSirBssDescription + cbBssDesc );
5631
5632 } //while
5633 }
5634 else
5635 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005636 smsLog( pMac, LOGW, " Scanrsp fail (0x%08X), length = %d (expected %d)",
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08005637 pScanRsp->statusCode, pScanRsp->length, cbScanResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07005638 //HO bg scan/probe failed no need to try autonomously
5639 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
5640 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005641#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5642 eCsrScanGetLfrResult == pCommand->u.scanCmd.reason ||
5643#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005644 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
5645 {
5646 fRemoveCommand = eANI_BOOLEAN_TRUE;
5647 }
5648 }
5649 }while(0);
5650 if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
5651 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005652 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 -07005653 fRemoveCommand = csrScanComplete( pMac, pScanRsp );
5654 fRet = eANI_BOOLEAN_TRUE;
5655 }//if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
5656 if(pfRemoveCommand)
5657 {
5658 *pfRemoveCommand = fRemoveCommand;
5659 }
5660
Agrawal Ashish4cc15bb2016-02-04 17:56:16 +05305661 /*
5662 * Currently SET_FCC_CHANNEL issues updated channel list to fw.
5663 * At the time of driver load, if scan is issued followed with
5664 * SET_FCC_CHANNEL, driver will send update channel list to fw.
5665 * Fw will stop ongoing scan because of that GUI will have very less
5666 * scan list.
5667 * Update channel list should be sent to fw once scan is done
5668 */
5669 if (pMac->scan.defer_update_channel_list) {
5670 status = csrUpdateChannelList(pMac);
5671 if (eHAL_STATUS_SUCCESS != status)
5672 smsLog(pMac, LOGE,
5673 FL( "failed to update the supported channel list"));
5674 pMac->scan.defer_update_channel_list = false;
5675 }
5676
Jeff Johnson295189b2012-06-20 16:38:30 -07005677#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305678 if (pMac->fScanOffload)
5679 return fRet;
5680
Jeff Johnson295189b2012-06-20 16:38:30 -07005681 if (!csrLLIsListEmpty( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK ))
5682 {
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005683 /* Pending scan commands in the list because the previous scan command
5684 * was split into a scan command on one channel + a scan command for all
5685 * remaining channels.
5686 *
5687 * Start timer to trigger processing of the next scan command.
Srikant Kuppa866893f2012-12-27 17:28:14 -08005688 * NOTE for LFR:
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305689 * Do not split scans if no concurrent infra connections are
Srikant Kuppa866893f2012-12-27 17:28:14 -08005690 * active and if the scan is a BG scan triggered by LFR (OR)
5691 * any scan if LFR is in the middle of a BG scan. Splitting
5692 * the scan is delaying the time it takes for LFR to find
5693 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005694 */
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305695 if ( (csrIsStaSessionConnected(pMac) &&
Srikant Kuppa866893f2012-12-27 17:28:14 -08005696#ifdef FEATURE_WLAN_LFR
5697 (csrIsConcurrentInfraConnected(pMac) ||
5698 ((pCommand->u.scanCmd.reason != eCsrScanBgScan) &&
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305699 (pMac->roam.neighborRoamInfo.neighborRoamState !=
Srikant Kuppa866893f2012-12-27 17:28:14 -08005700 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
5701#endif
5702 (pCommand->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305703 (csrIsP2pSessionConnected(pMac)) )
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005704 {
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005705 /* if active connected sessions present then continue to split scan
5706 * with specified interval between consecutive scans */
5707 csrSetDefaultScanTiming(pMac, pCommand->u.scanCmd.u.scanRequest.scanType, &(pCommand->u.scanCmd.u.scanRequest));
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05305708 vos_timer_start(&pMac->scan.hTimerStaApConcTimer,
5709 pCommand->u.scanCmd.u.scanRequest.restTime);
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005710 } else {
5711 /* if no connected sessions present then initiate next scan command immediately */
5712 /* minimum timer granularity is 10ms */
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05305713 vos_timer_start(&pMac->scan.hTimerStaApConcTimer, 10);
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005714 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005715 }
5716#endif
5717 return (fRet);
5718}
5719
5720
5721tANI_BOOLEAN csrScanIsWildCardScan( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5722{
5723 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
Kiet Lam64c1b492013-07-12 13:56:44 +05305724 tANI_BOOLEAN f = vos_mem_compare(pCommand->u.scanCmd.u.scanRequest.bssid,
5725 bssid, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07005726
5727 //It is not a wild card scan if the bssid is not broadcast and the number of SSID is 1.
5728 return ((tANI_BOOLEAN)( (f || (0xff == pCommand->u.scanCmd.u.scanRequest.bssid[0])) &&
5729 (pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs != 1) ));
5730}
5731
5732
5733eHalStatus csrScanSmeScanResponse( tpAniSirGlobal pMac, void *pMsgBuf )
5734{
5735 eHalStatus status = eHAL_STATUS_SUCCESS;
5736 tListElem *pEntry;
5737 tSmeCmd *pCommand;
5738 eCsrScanStatus scanStatus;
Sunkad, Anand Ningappa3ec8bf72016-02-05 15:13:30 +05305739 tSirSmeScanRsp *pScanRsp;
Jeff Johnson295189b2012-06-20 16:38:30 -07005740 tSmeGetScanChnRsp *pScanChnInfo;
5741 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
5742 eCsrScanReason reason = eCsrScanOther;
5743
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305744 if (pMac->fScanOffload)
5745 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList,
5746 LL_ACCESS_LOCK);
5747 else
5748 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07005749
5750 if ( pEntry )
5751 {
5752 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
5753 if ( eSmeCommandScan == pCommand->command )
5754 {
Deepthi Gowrife5340b2016-04-11 12:15:46 +05305755 /* Purge the scan results based on Aging */
5756 if (pEntry && pMac->scan.scanResultCfgAgingTime)
5757 csrPurgeScanResultByAge(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07005758 reason = pCommand->u.scanCmd.reason;
5759 switch(pCommand->u.scanCmd.reason)
5760 {
5761 case eCsrScanAbortBgScan:
5762 case eCsrScanAbortNormalScan:
5763 case eCsrScanBGScanAbort:
5764 case eCsrScanBGScanEnable:
Sunkad, Anand Ningappa3ec8bf72016-02-05 15:13:30 +05305765 pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
5766 scanStatus = (eSIR_SME_SUCCESS == pScanRsp->statusCode) ?
5767 eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005768 break;
5769 case eCsrScanGetScanChnInfo:
Deepthi Gowrife5340b2016-04-11 12:15:46 +05305770 pScanChnInfo = (tSmeGetScanChnRsp *)pMsgBuf;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005771 /*
5772 * status code not available in tSmeGetScanChnRsp, so
5773 * by default considereing it to be success
5774 */
5775 scanStatus = eSIR_SME_SUCCESS;
Deepthi Gowrife5340b2016-04-11 12:15:46 +05305776 csrScanAgeResults(pMac, pScanChnInfo);
Jeff Johnson295189b2012-06-20 16:38:30 -07005777 break;
5778 case eCsrScanForCapsChange:
Sunkad, Anand Ningappa3ec8bf72016-02-05 15:13:30 +05305779 pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
5780 scanStatus = (eSIR_SME_SUCCESS == pScanRsp->statusCode) ?
5781 eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005782 csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand );
5783 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005784 case eCsrScanP2PFindPeer:
Sunkad, Anand Ningappa3ec8bf72016-02-05 15:13:30 +05305785 pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
5786 scanStatus = ((eSIR_SME_SUCCESS == pScanRsp->statusCode) &&
5787 (pScanRsp->length > 50)) ? eCSR_SCAN_FOUND_PEER : eCSR_SCAN_FAILURE;
5788 csrScanProcessScanResults( pMac, pCommand, pScanRsp, NULL );
5789 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005790 case eCsrScanSetBGScanParam:
5791 default:
Sunkad, Anand Ningappa3ec8bf72016-02-05 15:13:30 +05305792 pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
5793 scanStatus = (eSIR_SME_SUCCESS == pScanRsp->statusCode) ?
5794 eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005795 if(csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand ))
5796 {
5797 //Not to get channel info if the scan is not a wildcard scan because
5798 //it may cause scan results got aged out incorrectly.
Ratheesh S Pece1f832015-07-25 15:50:25 +05305799 if(csrScanIsWildCardScan( pMac, pCommand ) &&
5800 (!pCommand->u.scanCmd.u.scanRequest.p2pSearch)
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005801#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5802 && (pCommand->u.scanCmd.reason != eCsrScanGetLfrResult)
5803#endif
5804 )
Jeff Johnson295189b2012-06-20 16:38:30 -07005805 {
Ratheesh S Pece1f832015-07-25 15:50:25 +05305806 csrScanGetScanChnInfo(pMac, pCommand);
Jeff Johnson295189b2012-06-20 16:38:30 -07005807 }
5808 }
5809 break;
5810 }//switch
5811 if(fRemoveCommand)
5812 {
5813
5814 csrReleaseScanCommand(pMac, pCommand, scanStatus);
5815
Sunkad, Anand Ningappa3ec8bf72016-02-05 15:13:30 +05305816 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005817 smeProcessPendingQueue( pMac );
5818 }
5819 else
5820 {
5821 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
5822 status = eHAL_STATUS_FAILURE;
5823 }
5824 }
5825 else
5826 {
5827 smsLog( pMac, LOGW, "CSR: Scan Completion called but NO commands are ACTIVE ..." );
5828 status = eHAL_STATUS_FAILURE;
5829 }
5830
5831 return (status);
5832}
5833
5834
5835
5836
5837tCsrScanResultInfo *csrScanResultGetFirst(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
5838{
5839 tListElem *pEntry;
5840 tCsrScanResult *pResult;
5841 tCsrScanResultInfo *pRet = NULL;
5842 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5843
5844 if(pResultList)
5845 {
5846 csrLLLock(&pResultList->List);
5847 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5848 if(pEntry)
5849 {
5850 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
5851 pRet = &pResult->Result;
5852 }
5853 pResultList->pCurEntry = pEntry;
5854 csrLLUnlock(&pResultList->List);
5855 }
5856
5857 return pRet;
5858}
5859
5860
5861tCsrScanResultInfo *csrScanResultGetNext(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
5862{
5863 tListElem *pEntry = NULL;
5864 tCsrScanResult *pResult = NULL;
5865 tCsrScanResultInfo *pRet = NULL;
5866 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5867
5868 if(pResultList)
5869 {
5870 csrLLLock(&pResultList->List);
5871 if(NULL == pResultList->pCurEntry)
5872 {
5873 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5874 }
5875 else
5876 {
5877 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
5878 }
5879 if(pEntry)
5880 {
5881 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
5882 pRet = &pResult->Result;
5883 }
5884 pResultList->pCurEntry = pEntry;
5885 csrLLUnlock(&pResultList->List);
5886 }
5887
5888 return pRet;
5889}
5890
5891
5892//This function moves the first BSS that matches the bssid to the head of the result
5893eHalStatus csrMoveBssToHeadFromBSSID(tpAniSirGlobal pMac, tCsrBssid *bssid, tScanResultHandle hScanResult)
5894{
5895 eHalStatus status = eHAL_STATUS_FAILURE;
5896 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5897 tCsrScanResult *pResult = NULL;
5898 tListElem *pEntry = NULL;
5899
5900 if(pResultList && bssid)
5901 {
5902 csrLLLock(&pResultList->List);
5903 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5904 while(pEntry)
5905 {
5906 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
Kiet Lam64c1b492013-07-12 13:56:44 +05305907 if (vos_mem_compare(bssid, pResult->Result.BssDescriptor.bssId, sizeof(tCsrBssid)))
Jeff Johnson295189b2012-06-20 16:38:30 -07005908 {
5909 status = eHAL_STATUS_SUCCESS;
5910 csrLLRemoveEntry(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
5911 csrLLInsertHead(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
5912 break;
5913 }
5914 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
5915 }
5916 csrLLUnlock(&pResultList->List);
5917 }
5918
5919 return (status);
5920}
5921
5922
5923//Remove the BSS if possible.
5924//Return -- TRUE == the BSS is remove. False == Fail to remove it
5925//This function is called when list lock is held. Be caution what functions it can call.
5926tANI_BOOLEAN csrScanAgeOutBss(tpAniSirGlobal pMac, tCsrScanResult *pResult)
5927{
5928 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
5929 tANI_U32 i;
5930 tCsrRoamSession *pSession;
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305931 tANI_BOOLEAN isConnBssfound = eANI_BOOLEAN_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005932
5933 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5934 {
5935 if( CSR_IS_SESSION_VALID( pMac, i ) )
5936 {
5937 pSession = CSR_GET_SESSION( pMac, i );
5938 //Not to remove the BSS we are connected to.
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305939 if(csrIsConnStateConnectedInfra(pMac, i) && (NULL != pSession->pConnectBssDesc) &&
5940 (csrIsDuplicateBssDescription(pMac, &pResult->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07005941 pSession->pConnectBssDesc, NULL, FALSE))
Jeff Johnson295189b2012-06-20 16:38:30 -07005942 )
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305943 {
5944 isConnBssfound = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005945 break;
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305946 }
5947 }
5948 }
5949
5950 if( isConnBssfound )
Jeff Johnson295189b2012-06-20 16:38:30 -07005951 {
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305952 //Reset the counter so that aging out of connected BSS won't hapeen too soon
Jeff Johnson295189b2012-06-20 16:38:30 -07005953 pResult->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Deepthi Gowri4480a3f2016-05-18 19:30:17 +05305954 pResult->Result.BssDescriptor.nReceivedTime =
5955 vos_timer_get_system_time();
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305956
5957 return (fRet);
5958 }
5959 else
5960 {
5961 smsLog(pMac, LOGW, "Aging out BSS "MAC_ADDRESS_STR" Channel %d",
5962 MAC_ADDR_ARRAY(pResult->Result.BssDescriptor.bssId),
5963 pResult->Result.BssDescriptor.channelId);
5964 //No need to hold the spin lock because caller should hold the lock for pMac->scan.scanResultList
5965 if( csrLLRemoveEntry(&pMac->scan.scanResultList, &pResult->Link, LL_ACCESS_NOLOCK) )
5966 {
5967 if (csrIsMacAddressEqual(pMac,
5968 (tCsrBssid *) pResult->Result.BssDescriptor.bssId,
5969 (tCsrBssid *) pMac->scan.currentCountryBssid))
5970 {
5971 smsLog(pMac, LOGW, "Aging out 11d BSS "MAC_ADDRESS_STR,
5972 MAC_ADDR_ARRAY(pResult->Result.BssDescriptor.bssId));
5973 pMac->scan.currentCountryRSSI = -128;
5974 }
5975 csrFreeScanResultEntry(pMac, pResult);
5976 fRet = eANI_BOOLEAN_TRUE;
5977 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005978 }
5979
5980 return (fRet);
5981}
5982
5983
5984eHalStatus csrScanAgeResults(tpAniSirGlobal pMac, tSmeGetScanChnRsp *pScanChnInfo)
5985{
5986 eHalStatus status = eHAL_STATUS_SUCCESS;
5987 tListElem *pEntry, *tmpEntry;
5988 tCsrScanResult *pResult;
5989 tLimScanChn *pChnInfo;
5990 tANI_U8 i;
5991
5992 csrLLLock(&pMac->scan.scanResultList);
5993 for(i = 0; i < pScanChnInfo->numChn; i++)
5994 {
5995 pChnInfo = &pScanChnInfo->scanChn[i];
5996 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
5997 while( pEntry )
5998 {
5999 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
6000 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
6001 if(pResult->Result.BssDescriptor.channelId == pChnInfo->channelId)
6002 {
Jeff Johnson295189b2012-06-20 16:38:30 -07006003 if(pResult->AgingCount <= 0)
6004 {
6005 smsLog(pMac, LOGW, " age out due to ref count");
6006 csrScanAgeOutBss(pMac, pResult);
6007 }
Madan Mohan Koyyalamudib9d3dcc2012-09-28 16:47:50 -07006008 else
6009 {
6010 pResult->AgingCount--;
6011 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006012 }
6013 pEntry = tmpEntry;
6014 }
6015 }
6016 csrLLUnlock(&pMac->scan.scanResultList);
6017
6018 return (status);
6019}
6020
Abhishek Singhc640dbb2015-06-08 10:54:17 +05306021eHalStatus csrIbssAgeBss(tpAniSirGlobal pMac)
6022{
6023 eHalStatus status = eHAL_STATUS_SUCCESS;
6024 tListElem *pEntry, *tmpEntry;
6025 tCsrScanResult *pResult;
6026
6027 csrLLLock(&pMac->scan.scanResultList);
6028 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
6029 while( pEntry )
6030 {
6031 tmpEntry = csrLLNext(&pMac->scan.scanResultList,
6032 pEntry, LL_ACCESS_NOLOCK);
6033 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
6034
6035 smsLog(pMac, LOGW, FL(" age out due Forced IBSS leave"));
6036 csrScanAgeOutBss(pMac, pResult);
6037 pEntry = tmpEntry;
6038 }
6039 csrLLUnlock(&pMac->scan.scanResultList);
6040
6041 return (status);
6042}
Jeff Johnson295189b2012-06-20 16:38:30 -07006043
Abhishek Singh72c2f4e2016-07-22 11:25:43 +05306044/**
6045 * csr_remove_bssid_from_scan_list() - remove the bssid from
6046 * scan list
6047 * @pMac: mac context.
6048 * @bssid: bssid to be removed
6049 *
6050 * This function remove the given bssid from scan list.
6051 *
6052 * Return: void.
6053 */
6054void csr_remove_bssid_from_scan_list(tpAniSirGlobal pMac,
6055 tSirMacAddr bssid)
6056{
6057 tListElem *entry,*free_elem;
6058 tCsrScanResult *bss_desc;
6059 tDblLinkList *list = &pMac->scan.scanResultList;
6060
6061 csrLLLock(list);
6062 entry = csrLLPeekHead(list, LL_ACCESS_NOLOCK);
6063 while (entry != NULL) {
6064 bss_desc = GET_BASE_ADDR( entry, tCsrScanResult, Link);
6065 if (vos_mem_compare(bss_desc->Result.BssDescriptor.bssId,
6066 bssid, sizeof(tSirMacAddr))) {
6067 free_elem = entry;
6068 entry = csrLLNext(list, entry, LL_ACCESS_NOLOCK);
6069 csrLLRemoveEntry(list, free_elem, LL_ACCESS_NOLOCK);
6070 csrFreeScanResultEntry(pMac, bss_desc);
6071 smsLog(pMac, LOGW, FL("Removed BSS entry:%pM"),
6072 bssid);
6073 continue;
6074 }
6075 entry = csrLLNext(list, entry, LL_ACCESS_NOLOCK);
6076 }
6077 csrLLUnlock(list);
6078}
6079
Jeff Johnson295189b2012-06-20 16:38:30 -07006080eHalStatus csrSendMBScanReq( tpAniSirGlobal pMac, tANI_U16 sessionId,
6081 tCsrScanRequest *pScanReq, tScanReqParam *pScanReqParam )
6082{
6083 eHalStatus status = eHAL_STATUS_SUCCESS;
6084 tSirSmeScanReq *pMsg;
6085 tANI_U16 msgLen;
6086 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
6087 tSirScanType scanType = pScanReq->scanType;
6088 tANI_U32 minChnTime; //in units of milliseconds
6089 tANI_U32 maxChnTime; //in units of milliseconds
6090 tANI_U32 i;
6091 tANI_U8 selfMacAddr[WNI_CFG_BSSID_LEN];
6092 tANI_U8 *pSelfMac = NULL;
6093
6094 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
6095 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) +
6096 ( pScanReq->uIEFieldLen ) ;
6097
Kiet Lam64c1b492013-07-12 13:56:44 +05306098 pMsg = vos_mem_malloc(msgLen);
6099 if ( NULL == pMsg )
6100 status = eHAL_STATUS_FAILURE;
6101 else
6102 status = eHAL_STATUS_SUCCESS;
6103 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07006104 {
6105 do
6106 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306107 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006108 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
6109 pMsg->length = pal_cpu_to_be16(msgLen);
6110 //ToDO: Fill in session info when we need to do scan base on session.
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05306111 if ((pMac->fScanOffload) && (sessionId != CSR_SESSION_ID_INVALID))
6112 {
6113 pMsg->sessionId = sessionId;
6114 }
6115 else
6116 {
6117 /* if sessionId == CSR_SESSION_ID_INVALID, then send the scan
6118 request on first available session */
6119 pMsg->sessionId = 0;
6120 }
6121
Jeff Johnson295189b2012-06-20 16:38:30 -07006122 pMsg->transactionId = 0;
6123 pMsg->dot11mode = (tANI_U8) csrTranslateToWNICfgDot11Mode(pMac, csrFindBestPhyMode( pMac, pMac->roam.configParam.phyMode ));
6124 pMsg->bssType = pal_cpu_to_be32(csrTranslateBsstypeToMacType(pScanReq->BSSType));
6125
6126 if ( CSR_IS_SESSION_VALID( pMac, sessionId ) )
6127 {
6128 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[sessionId].selfMacAddr;
6129 }
6130 else
6131 {
6132 // Since we don't have session for the scanning, we find a valid session. In case we fail to
6133 // do so, get the WNI_CFG_STA_ID
6134 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
6135 {
6136 if( CSR_IS_SESSION_VALID( pMac, i ) )
6137 {
6138 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[i].selfMacAddr;
6139 break;
6140 }
6141 }
6142 if( CSR_ROAM_SESSION_MAX == i )
6143 {
6144 tANI_U32 len = WNI_CFG_BSSID_LEN;
6145 pSelfMac = selfMacAddr;
6146 status = ccmCfgGetStr( pMac, WNI_CFG_STA_ID, pSelfMac, &len );
6147 if( !HAL_STATUS_SUCCESS( status ) ||
6148 ( len < WNI_CFG_BSSID_LEN ) )
6149 {
6150 smsLog( pMac, LOGE, FL(" Can not get self MAC address from CFG status = %d"), status );
6151 //Force failed status
6152 status = eHAL_STATUS_FAILURE;
6153 break;
6154 }
6155 }
6156 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306157 vos_mem_copy((tANI_U8 *)pMsg->selfMacAddr, pSelfMac, sizeof(tSirMacAddr));
Jeff Johnson295189b2012-06-20 16:38:30 -07006158
6159 //sirCopyMacAddr
Kiet Lam64c1b492013-07-12 13:56:44 +05306160 vos_mem_copy((tANI_U8 *)pMsg->bssId, (tANI_U8 *)&pScanReq->bssid, sizeof(tSirMacAddr));
6161 if ( vos_mem_compare(pScanReq->bssid, bssid, sizeof(tCsrBssid)))
Jeff Johnson295189b2012-06-20 16:38:30 -07006162 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306163 vos_mem_set(pMsg->bssId, sizeof(tSirMacAddr), 0xff);
Jeff Johnson295189b2012-06-20 16:38:30 -07006164 }
6165 else
6166 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306167 vos_mem_copy(pMsg->bssId, pScanReq->bssid, WNI_CFG_BSSID_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07006168 }
6169 minChnTime = pScanReq->minChnTime;
6170 maxChnTime = pScanReq->maxChnTime;
6171
6172 //Verify the scan type first, if the scan is active scan, we need to make sure we
6173 //are allowed to do so.
6174 /* if 11d is enabled & we don't see any beacon around, scan type falls
6175 back to passive. But in BT AMP STA mode we need to send out a
6176 directed probe*/
6177 if( (eSIR_PASSIVE_SCAN != scanType) && (eCSR_SCAN_P2P_DISCOVERY != pScanReq->requestType)
6178 && (eCSR_BSS_TYPE_WDS_STA != pScanReq->BSSType)
6179 && (eANI_BOOLEAN_FALSE == pMac->scan.fEnableBypass11d))
6180 {
6181 scanType = pMac->scan.curScanType;
6182 if(eSIR_PASSIVE_SCAN == pMac->scan.curScanType)
6183 {
6184 if(minChnTime < pMac->roam.configParam.nPassiveMinChnTime)
6185 {
6186 minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
6187 }
6188 if(maxChnTime < pMac->roam.configParam.nPassiveMaxChnTime)
6189 {
6190 maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
6191 }
6192 }
6193 }
6194 pMsg->scanType = pal_cpu_to_be32(scanType);
6195
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306196 pMsg->numSsid =
6197 (pScanReq->SSIDs.numOfSSIDs < SIR_SCAN_MAX_NUM_SSID) ?
6198 pScanReq->SSIDs.numOfSSIDs : SIR_SCAN_MAX_NUM_SSID;
Jeff Johnson295189b2012-06-20 16:38:30 -07006199 if((pScanReq->SSIDs.numOfSSIDs != 0) && ( eSIR_PASSIVE_SCAN != scanType ))
6200 {
Jeff Johnson40b59aa2013-03-19 14:43:18 -07006201 for (i = 0; i < pMsg->numSsid; i++)
6202 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306203 vos_mem_copy(&pMsg->ssId[i],
6204 &pScanReq->SSIDs.SSIDList[i].SSID, sizeof(tSirMacSSid));
Jeff Johnson40b59aa2013-03-19 14:43:18 -07006205 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006206 }
6207 else
6208 {
6209 //Otherwise we scan all SSID and let the result filter later
Jeff Johnson40b59aa2013-03-19 14:43:18 -07006210 for (i = 0; i < SIR_SCAN_MAX_NUM_SSID; i++)
6211 {
6212 pMsg->ssId[i].length = 0;
6213 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006214 }
6215
Jeff Johnson295189b2012-06-20 16:38:30 -07006216 pMsg->minChannelTime = pal_cpu_to_be32(minChnTime);
6217 pMsg->maxChannelTime = pal_cpu_to_be32(maxChnTime);
Abhishek Singhadd13582016-09-29 17:00:03 +05306218 pMsg->min_chntime_btc_esco =
6219 pMac->roam.configParam.min_chntime_btc_esco;
6220 pMsg->max_chntime_btc_esco =
6221 pMac->roam.configParam.max_chntime_btc_esco;
Jeff Johnson295189b2012-06-20 16:38:30 -07006222 //hidden SSID option
6223 pMsg->hiddenSsid = pScanReqParam->hiddenSsid;
6224 //rest time
6225 //pMsg->restTime = pScanReq->restTime;
6226 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
6227 // All the scan results caching will be done by Roaming
6228 // We do not want LIM to do any caching of scan results,
6229 // so delete the LIM cache on all scan requests
6230 pMsg->returnFreshResults = pScanReqParam->freshScan;
6231 //Always ask for unique result
6232 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
6233 pMsg->channelList.numChannels = (tANI_U8)pScanReq->ChannelInfo.numOfChannels;
6234 if(pScanReq->ChannelInfo.numOfChannels)
6235 {
6236 //Assuming the channelNumber is tANI_U8 (1 byte)
Kiet Lam64c1b492013-07-12 13:56:44 +05306237 vos_mem_copy(pMsg->channelList.channelNumber,
6238 pScanReq->ChannelInfo.ChannelList,
6239 pScanReq->ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07006240 }
6241
6242 pMsg->uIEFieldLen = (tANI_U16) pScanReq->uIEFieldLen;
6243 pMsg->uIEFieldOffset = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
6244 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) ;
6245 if(pScanReq->uIEFieldLen != 0)
6246 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306247 vos_mem_copy((tANI_U8 *)pMsg+pMsg->uIEFieldOffset, pScanReq->pIEField,
6248 pScanReq->uIEFieldLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07006249 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006250 pMsg->p2pSearch = pScanReq->p2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07006251
Madan Mohan Koyyalamudi9b876782012-10-11 16:22:51 -07006252 if (pScanReq->requestType == eCSR_SCAN_HO_BG_SCAN)
6253 {
6254 pMsg->backgroundScanMode = eSIR_ROAMING_SCAN;
6255 }
6256
Jeff Johnson295189b2012-06-20 16:38:30 -07006257 }while(0);
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05306258 smsLog(pMac, LOG1, FL("domainIdCurrent %s (%d) scanType %s (%d)"
6259 "bssType %s (%d), requestType %s(%d)"
6260 "numChannels %d"),
6261 voss_DomainIdtoString(pMac->scan.domainIdCurrent),
6262 pMac->scan.domainIdCurrent,
6263 lim_ScanTypetoString(pMsg->scanType), pMsg->scanType,
6264 lim_BssTypetoString(pMsg->bssType), pMsg->bssType,
6265 sme_requestTypetoString(pScanReq->requestType),
6266 pScanReq->requestType,
6267 pMsg->channelList.numChannels);
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08006268
6269 for(i = 0; i < pMsg->channelList.numChannels; i++)
6270 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006271 smsLog(pMac, LOG3, FL("channelNumber[%d]= %d"), i, pMsg->channelList.channelNumber[i]);
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08006272 }
6273
Jeff Johnson295189b2012-06-20 16:38:30 -07006274 if(HAL_STATUS_SUCCESS(status))
6275 {
6276 status = palSendMBMessage(pMac->hHdd, pMsg);
6277 }
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08006278 else
6279 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006280 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d"), status );
Kiet Lam64c1b492013-07-12 13:56:44 +05306281 vos_mem_free(pMsg);
Jeff Johnson295189b2012-06-20 16:38:30 -07006282 }
6283 }//Success allocated memory
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08006284 else
6285 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006286 smsLog( pMac, LOGE, FL(" memory allocation failure"));
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08006287 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006288
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306289 if(!HAL_STATUS_SUCCESS(status))
6290 {
6291 smsLog( pMac, LOG1, FL("Failed: SId: %d FirstMatch = %d"
6292 " UniqueResult = %d freshScan = %d hiddenSsid = %d"),
6293 sessionId, pScanReqParam->bReturnAfter1stMatch,
6294 pScanReqParam->fUniqueResult, pScanReqParam->freshScan,
6295 pScanReqParam->hiddenSsid );
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05306296 smsLog( pMac, LOG1, FL("scanType = %s (%d) BSSType = %s (%d) "
6297 "numOfSSIDs = %d numOfChannels = %d requestType = %s (%d)"
6298 " p2pSearch = %d\n"),
6299 lim_ScanTypetoString(pScanReq->scanType),
6300 pScanReq->scanType,
6301 lim_BssTypetoString(pScanReq->BSSType),
6302 pScanReq->BSSType,
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306303 pScanReq->SSIDs.numOfSSIDs,
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05306304 pScanReq->ChannelInfo.numOfChannels,
6305 sme_requestTypetoString(pScanReq->requestType),
6306 pScanReq->requestType,
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306307 pScanReq->p2pSearch );
6308
6309 }
6310
Jeff Johnson295189b2012-06-20 16:38:30 -07006311 return( status );
6312}
6313
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006314eHalStatus csrSendMBScanResultReq( tpAniSirGlobal pMac, tANI_U32 sessionId, tScanReqParam *pScanReqParam )
Jeff Johnson295189b2012-06-20 16:38:30 -07006315{
6316 eHalStatus status = eHAL_STATUS_SUCCESS;
6317 tSirSmeScanReq *pMsg;
6318 tANI_U16 msgLen;
6319
6320 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ));
Kiet Lam64c1b492013-07-12 13:56:44 +05306321 pMsg = vos_mem_malloc(msgLen);
6322 if ( NULL == pMsg )
6323 status = eHAL_STATUS_FAILURE;
6324 else
Jeff Johnson295189b2012-06-20 16:38:30 -07006325 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306326 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006327 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
6328 pMsg->length = pal_cpu_to_be16(msgLen);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006329 pMsg->sessionId = sessionId;
6330 pMsg->transactionId = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07006331 pMsg->returnFreshResults = pScanReqParam->freshScan;
6332 //Always ask for unique result
6333 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
6334 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
6335 status = palSendMBMessage(pMac->hHdd, pMsg);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006336 if (!HAL_STATUS_SUCCESS(status))
6337 {
6338 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d\n"), status );
6339 }
6340
Jeff Johnson295189b2012-06-20 16:38:30 -07006341 }
6342
6343 return( status );
6344}
6345
6346
6347
6348eHalStatus csrScanChannels( tpAniSirGlobal pMac, tSmeCmd *pCommand )
6349{
6350 eHalStatus status = eHAL_STATUS_FAILURE;
6351 tScanReqParam scanReq;
6352
6353 do
6354 {
6355 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE | TRUE;
6356 scanReq.fUniqueResult = TRUE;
6357 scanReq.hiddenSsid = SIR_SCAN_NO_HIDDEN_SSID;
6358 if(eCsrScanForSsid == pCommand->u.scanCmd.reason)
6359 {
6360 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_FIRST_MATCH;
6361 }
6362 else
6363 {
6364 // Basically do scan on all channels even for 11D 1st scan case.
6365 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
6366 }
6367 if((eCsrScanBgScan == pCommand->u.scanCmd.reason)||
6368 (eCsrScanProbeBss == pCommand->u.scanCmd.reason))
6369 {
6370 scanReq.hiddenSsid = SIR_SCAN_HIDDEN_SSID_PE_DECISION;
6371 }
6372
6373#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
6374 {
6375 vos_log_scan_pkt_type *pScanLog = NULL;
6376
6377 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
6378 if(pScanLog)
6379 {
6380 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
6381 eCsrScanProbeBss == pCommand->u.scanCmd.reason)
6382 {
6383 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
6384 }
6385 else
6386 {
6387 if( (eSIR_PASSIVE_SCAN != pCommand->u.scanCmd.u.scanRequest.scanType) &&
6388 (eSIR_PASSIVE_SCAN != pMac->scan.curScanType) )
6389 {
6390 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_REQ;
6391 }
6392 else
6393 {
6394 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_REQ;
6395 }
6396 }
6397 pScanLog->minChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.minChnTime;
6398 pScanLog->maxChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.maxChnTime;
6399 pScanLog->numChannel = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
6400 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
6401 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306402 vos_mem_copy(pScanLog->channels,
6403 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
6404 pScanLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07006405 }
6406 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
6407 }
6408 }
6409#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
6410
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05306411 csrClearVotesForCountryInfo(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07006412 status = csrSendMBScanReq(pMac, pCommand->sessionId,
6413 &pCommand->u.scanCmd.u.scanRequest, &scanReq);
6414 }while(0);
6415
6416 return( status );
6417}
6418
6419
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006420eHalStatus csrScanRetrieveResult(tpAniSirGlobal pMac, tSmeCmd *pCommand)
Jeff Johnson295189b2012-06-20 16:38:30 -07006421{
6422 eHalStatus status = eHAL_STATUS_FAILURE;
6423 tScanReqParam scanReq;
6424
6425 do
6426 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006427#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
6428 if (eCsrScanGetLfrResult == pCommand->u.scanCmd.reason)
6429 {
6430 //to get the LFR candidates from PE cache
6431 scanReq.freshScan = SIR_BG_SCAN_RETURN_LFR_CACHED_RESULTS|SIR_BG_SCAN_PURGE_LFR_RESULTS;
6432 scanReq.fUniqueResult = TRUE;
6433 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
6434 }
6435 else
6436#endif
6437 {
6438 //not a fresh scan
6439 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE;
6440 scanReq.fUniqueResult = TRUE;
6441 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
6442 }
6443 status = csrSendMBScanResultReq(pMac, pCommand->sessionId, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07006444 }while(0);
6445
6446 return (status);
6447}
6448
Siddharth Bhald8a95e82015-02-12 20:14:52 +05306449eHalStatus csrProcessMacAddrSpoofCommand( tpAniSirGlobal pMac, tSmeCmd *pCommand )
6450{
6451 tSirSpoofMacAddrReq *pMsg;
6452 tANI_U16 msgLen;
6453 eHalStatus status = eHAL_STATUS_FAILURE;
6454 do {
6455 msgLen = sizeof(tSirSpoofMacAddrReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07006456
Siddharth Bhald8a95e82015-02-12 20:14:52 +05306457 pMsg = vos_mem_malloc(msgLen);
6458 if ( NULL == pMsg )
6459 return eHAL_STATUS_FAILURE;
6460 pMsg->messageType= pal_cpu_to_be16((tANI_U16)eWNI_SME_MAC_SPOOF_ADDR_IND);
6461 pMsg->length= pal_cpu_to_be16(msgLen);
6462 // spoof mac address
6463 vos_mem_copy((tANI_U8 *)pMsg->macAddr,
6464 (tANI_U8 *)pCommand->u.macAddrSpoofCmd.macAddr, sizeof(tSirMacAddr));
6465 status = palSendMBMessage(pMac->hHdd, pMsg);
6466 } while( 0 );
6467 return( status );
6468}
Jeff Johnson295189b2012-06-20 16:38:30 -07006469
6470eHalStatus csrProcessScanCommand( tpAniSirGlobal pMac, tSmeCmd *pCommand )
6471{
6472 eHalStatus status = eHAL_STATUS_SUCCESS;
6473 tCsrChannelInfo newChannelInfo = {0, NULL};
6474 int i, j;
6475 tANI_U8 *pChannel = NULL;
6476 tANI_U32 len = 0;
6477
6478 // Transition to Scanning state...
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306479 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07006480 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306481 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
6482 {
Abhishek Singhf52182c2016-08-24 11:15:23 +05306483 pMac->roam.prev_state[i]=
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306484 csrRoamStateChange( pMac, eCSR_ROAMING_STATE_SCANNING, i);
6485 smsLog( pMac, LOG3, "starting SCAN command from %d state...."
Abhishek Singhf52182c2016-08-24 11:15:23 +05306486 " reason is %d", pMac->roam.prev_state[i],
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306487 pCommand->u.scanCmd.reason );
6488 }
6489 }
6490 else
6491 {
Abhishek Singhf52182c2016-08-24 11:15:23 +05306492 pMac->roam.prev_state[pCommand->sessionId] =
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306493 csrRoamStateChange(pMac, eCSR_ROAMING_STATE_SCANNING,
6494 pCommand->sessionId);
6495 smsLog( pMac, LOG3,
6496 "starting SCAN command from %d state.... reason is %d",
Abhishek Singhf52182c2016-08-24 11:15:23 +05306497 pMac->roam.prev_state[pCommand->sessionId],
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306498 pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07006499 }
6500
6501 switch(pCommand->u.scanCmd.reason)
6502 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006503#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
6504 case eCsrScanGetLfrResult:
6505#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006506 case eCsrScanGetResult:
6507 case eCsrScanForCapsChange: //For cap change, LIM already save BSS description
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006508 status = csrScanRetrieveResult(pMac, pCommand);
Jeff Johnson295189b2012-06-20 16:38:30 -07006509 break;
6510 case eCsrScanSetBGScanParam:
6511 status = csrProcessSetBGScanParam(pMac, pCommand);
6512 break;
6513 case eCsrScanBGScanAbort:
6514 status = csrSetCfgBackgroundScanPeriod(pMac, 0);
6515 break;
6516 case eCsrScanBGScanEnable:
6517 status = csrSetCfgBackgroundScanPeriod(pMac, pMac->roam.configParam.bgScanInterval);
6518 break;
6519 case eCsrScanGetScanChnInfo:
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05306520 status = csrScanGetScanChannelInfo(pMac, pCommand->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07006521 break;
6522 case eCsrScanUserRequest:
6523 if(pMac->roam.configParam.fScanTwice)
6524 {
6525 //We scan 2.4 channel twice
6526 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels &&
6527 (NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList))
6528 {
6529 len = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
6530 //allocate twice the channel
Mukul Sharmaa631e892014-08-28 15:38:51 +05306531 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(len * 2);
Jeff Johnson295189b2012-06-20 16:38:30 -07006532 pChannel = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
6533 }
6534 else
6535 {
6536 //get the valid channel list to scan all.
6537 len = sizeof(pMac->roam.validChannelList);
6538
6539 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
6540 {
6541 //allocate twice the channel
6542 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(len * 2);
6543 pChannel = pMac->roam.validChannelList;
6544 }
6545 }
6546 if(NULL == newChannelInfo.ChannelList)
6547 {
6548 newChannelInfo.numOfChannels = 0;
6549 }
6550 else
6551 {
6552 j = 0;
6553 for(i = 0; i < len; i++)
6554 {
6555 newChannelInfo.ChannelList[j++] = pChannel[i];
6556 if(CSR_MAX_24GHz_CHANNEL_NUMBER >= pChannel[i])
6557 {
6558 newChannelInfo.ChannelList[j++] = pChannel[i];
6559 }
6560 }
6561 if(NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
6562 {
6563 //pChannel points to the channellist from the command, free it.
6564 vos_mem_free(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -07006565 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07006566 }
6567 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = j;
6568 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = newChannelInfo.ChannelList;
6569 }
6570 } //if(pMac->roam.configParam.fScanTwice)
6571
6572 status = csrScanChannels(pMac, pCommand);
6573
6574 break;
6575 default:
6576 status = csrScanChannels(pMac, pCommand);
6577 break;
6578 }
6579
6580 if(!HAL_STATUS_SUCCESS(status))
6581 {
6582 csrReleaseScanCommand(pMac, pCommand, eCSR_SCAN_FAILURE);
6583 }
6584
6585 return (status);
6586}
6587
6588
6589eHalStatus csrScanSetBGScanparams(tpAniSirGlobal pMac, tCsrBGScanRequest *pScanReq)
6590{
6591 eHalStatus status = eHAL_STATUS_SUCCESS;
6592 tSmeCmd *pCommand = NULL;
6593
6594 if(pScanReq)
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 = eCsrScanSetBGScanParam;
6607 pCommand->u.scanCmd.callback = NULL;
6608 pCommand->u.scanCmd.pContext = NULL;
Kiet Lam64c1b492013-07-12 13:56:44 +05306609 vos_mem_copy(&pCommand->u.scanCmd.u.bgScanRequest, pScanReq, sizeof(tCsrBGScanRequest));
Jeff Johnson295189b2012-06-20 16:38:30 -07006610 //we have to do the follow
6611 if(pScanReq->ChannelInfo.numOfChannels == 0)
6612 {
6613 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
6614 }
6615 else
6616 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306617 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList
6618 = vos_mem_malloc(pScanReq->ChannelInfo.numOfChannels);
6619 if ( NULL != pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07006620 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306621 vos_mem_copy(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList,
6622 pScanReq->ChannelInfo.ChannelList,
6623 pScanReq->ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07006624 }
6625 else
6626 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006627 smsLog(pMac, LOGE, FL("ran out of memory"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006628 csrReleaseCommandScan(pMac, pCommand);
Kiet Lam64c1b492013-07-12 13:56:44 +05306629 return eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006630 }
6631 }
6632
6633 //scan req for SSID
6634 if(pScanReq->SSID.length)
6635 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306636 vos_mem_copy(pCommand->u.scanCmd.u.bgScanRequest.SSID.ssId,
6637 pScanReq->SSID.ssId, pScanReq->SSID.length);
Jeff Johnson295189b2012-06-20 16:38:30 -07006638 pCommand->u.scanCmd.u.bgScanRequest.SSID.length = pScanReq->SSID.length;
6639
6640 }
6641 pCommand->u.scanCmd.u.bgScanRequest.maxChnTime= pScanReq->maxChnTime;
6642 pCommand->u.scanCmd.u.bgScanRequest.minChnTime = pScanReq->minChnTime;
6643 pCommand->u.scanCmd.u.bgScanRequest.scanInterval = pScanReq->scanInterval;
6644
6645
6646 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
6647 if( !HAL_STATUS_SUCCESS( status ) )
6648 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006649 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006650 csrReleaseCommandScan( pMac, pCommand );
6651 break;
6652 }
6653 }while(0);
6654 }
6655
6656 return (status);
6657}
6658
6659eHalStatus csrScanBGScanAbort( tpAniSirGlobal pMac )
6660{
6661 eHalStatus status = eHAL_STATUS_SUCCESS;
6662 tSmeCmd *pCommand = NULL;
6663
6664 do
6665 {
6666 pCommand = csrGetCommandBuffer(pMac);
6667 if(!pCommand)
6668 {
6669 status = eHAL_STATUS_RESOURCES;
6670 break;
6671 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306672 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006673 pCommand->command = eSmeCommandScan;
6674 pCommand->u.scanCmd.reason = eCsrScanBGScanAbort;
6675 pCommand->u.scanCmd.callback = NULL;
6676 pCommand->u.scanCmd.pContext = NULL;
6677 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
6678 if( !HAL_STATUS_SUCCESS( status ) )
6679 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006680 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006681 csrReleaseCommandScan( pMac, pCommand );
6682 break;
6683 }
6684 }while(0);
6685
6686 return (status);
6687}
6688
6689
6690//This will enable the background scan with the non-zero interval
6691eHalStatus csrScanBGScanEnable(tpAniSirGlobal pMac)
6692{
6693 eHalStatus status = eHAL_STATUS_SUCCESS;
6694 tSmeCmd *pCommand = NULL;
6695
6696 if(pMac->roam.configParam.bgScanInterval)
6697 {
6698 do
6699 {
6700 pCommand = csrGetCommandBuffer(pMac);
6701 if(!pCommand)
6702 {
6703 status = eHAL_STATUS_RESOURCES;
6704 break;
6705 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306706 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006707 pCommand->command = eSmeCommandScan;
6708 pCommand->u.scanCmd.reason = eCsrScanBGScanEnable;
6709 pCommand->u.scanCmd.callback = NULL;
6710 pCommand->u.scanCmd.pContext = NULL;
6711 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
6712 if( !HAL_STATUS_SUCCESS( status ) )
6713 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006714 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006715 csrReleaseCommandScan( pMac, pCommand );
6716 break;
6717 }
6718 }while(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006719 }
6720 else
6721 {
Sushant Kaushikb8dbb3f2015-04-29 17:03:37 +05306722 smsLog(pMac, LOGE, FL("cannot continue because the bgscan interval is 0"));
6723 status = eHAL_STATUS_INVALID_PARAMETER;
Jeff Johnson295189b2012-06-20 16:38:30 -07006724 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006725 return (status);
6726}
6727
6728
6729eHalStatus csrScanCopyRequest(tpAniSirGlobal pMac, tCsrScanRequest *pDstReq, tCsrScanRequest *pSrcReq)
6730{
6731 eHalStatus status = eHAL_STATUS_SUCCESS;
6732 tANI_U32 len = sizeof(pMac->roam.validChannelList);
6733 tANI_U32 index = 0;
6734 tANI_U32 new_index = 0;
Manjunathappa Prakashde7b2a52014-02-28 16:59:03 -08006735 eNVChannelEnabledType NVchannel_state;
Arif Hussain6af38622014-03-12 12:39:57 -07006736 tANI_U8 ch144_support = 0;
6737
6738 ch144_support = WDA_getFwWlanFeatCaps(WLAN_CH144);
Jeff Johnson295189b2012-06-20 16:38:30 -07006739
6740 do
6741 {
6742 status = csrScanFreeRequest(pMac, pDstReq);
6743 if(HAL_STATUS_SUCCESS(status))
6744 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306745 vos_mem_copy(pDstReq, pSrcReq, sizeof(tCsrScanRequest));
Gopichand Nakkalac7b1d3e2012-12-31 14:07:19 -08006746 /* Re-initialize the pointers to NULL since we did a copy */
6747 pDstReq->pIEField = NULL;
6748 pDstReq->ChannelInfo.ChannelList = NULL;
6749 pDstReq->SSIDs.SSIDList = NULL;
6750
Jeff Johnson295189b2012-06-20 16:38:30 -07006751 if(pSrcReq->uIEFieldLen == 0)
6752 {
6753 pDstReq->pIEField = NULL;
6754 }
6755 else
6756 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306757 pDstReq->pIEField = vos_mem_malloc(pSrcReq->uIEFieldLen);
6758 if ( NULL == pDstReq->pIEField )
Jeff Johnson295189b2012-06-20 16:38:30 -07006759 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306760 status = eHAL_STATUS_FAILURE;
6761 smsLog(pMac, LOGE, FL("No memory for scanning IE fields"));
6762 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07006763 }
6764 else
6765 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306766 status = eHAL_STATUS_SUCCESS;
6767 vos_mem_copy(pDstReq->pIEField, pSrcReq->pIEField,
6768 pSrcReq->uIEFieldLen);
6769 pDstReq->uIEFieldLen = pSrcReq->uIEFieldLen;
Jeff Johnson295189b2012-06-20 16:38:30 -07006770 }
6771 }//Allocate memory for IE field
6772 {
6773 if(pSrcReq->ChannelInfo.numOfChannels == 0)
6774 {
6775 pDstReq->ChannelInfo.ChannelList = NULL;
6776 pDstReq->ChannelInfo.numOfChannels = 0;
6777 }
6778 else
6779 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306780 pDstReq->ChannelInfo.ChannelList = vos_mem_malloc(
6781 pSrcReq->ChannelInfo.numOfChannels
6782 * sizeof(*pDstReq->ChannelInfo.ChannelList));
6783 if ( NULL == pDstReq->ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07006784 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306785 status = eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006786 pDstReq->ChannelInfo.numOfChannels = 0;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306787 smsLog(pMac, LOGE, FL("No memory for scanning Channel"
6788 " List"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006789 break;
6790 }
6791
6792 if((pSrcReq->scanType == eSIR_PASSIVE_SCAN) && (pSrcReq->requestType == eCSR_SCAN_REQUEST_11D_SCAN))
6793 {
6794 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
6795 {
Arif Hussain6af38622014-03-12 12:39:57 -07006796 /* Skip CH 144 if firmware support not present */
6797 if (pSrcReq->ChannelInfo.ChannelList[index] == 144 && !ch144_support)
6798 continue;
Agarwal Ashish8bd53ae2015-06-12 18:03:45 +05306799 /* Skip channel 12 and 13 when FCC constraint is true */
6800 if ((pMac->scan.fcc_constraint) &&
6801 ((pSrcReq->ChannelInfo.ChannelList[index] ==12) ||
6802 (pSrcReq->ChannelInfo.ChannelList[index] ==13)))
6803 {
6804 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
6805 FL("Ignoring channel : %d "),
6806 pSrcReq->ChannelInfo.ChannelList[index]);
6807 continue;
6808 }
Arif Hussain6af38622014-03-12 12:39:57 -07006809
Manjunathappa Prakashde7b2a52014-02-28 16:59:03 -08006810 NVchannel_state = vos_nv_getChannelEnabledState(
6811 pSrcReq->ChannelInfo.ChannelList[index]);
6812 if ((NV_CHANNEL_ENABLE == NVchannel_state) ||
6813 (NV_CHANNEL_DFS == NVchannel_state))
6814 {
6815 pDstReq->ChannelInfo.ChannelList[new_index] =
6816 pSrcReq->ChannelInfo.ChannelList[index];
6817 new_index++;
6818 }
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306819 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006820 pDstReq->ChannelInfo.numOfChannels = new_index;
6821 }
6822 else if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
6823 {
6824 new_index = 0;
6825 pMac->roam.numValidChannels = len;
c_hpothu0d5a7352014-03-22 12:30:25 +05306826
6827 /* Since in CsrScanRequest,value of pMac->scan.nextScanID
6828 * is incremented before calling CsrScanCopyRequest, as a
6829 * result pMac->scan.nextScanID is equal to ONE for the
Abhishek Singha2649232016-01-20 15:52:05 +05306830 * first scan. If number of channels is less than
6831 * max chan for dwell time no need to skip dfs
6832 * in first scan as anyway few channels will be scanned and
6833 * it will not take much time to display results on GUI.
c_hpothu0d5a7352014-03-22 12:30:25 +05306834 */
Abhishek Singha2649232016-01-20 15:52:05 +05306835 if (((pSrcReq->ChannelInfo.numOfChannels >=
6836 pMac->roam.configParam.max_chan_for_dwell_time_cfg) &&
6837 (pMac->roam.configParam.initialScanSkipDFSCh &&
6838 1 == pMac->scan.nextScanID)) ||(pMac->miracast_mode))
c_hpothu0d5a7352014-03-22 12:30:25 +05306839 {
6840 smsLog(pMac, LOG1,
6841 FL("Initial scan, scan only non-DFS channels"));
6842
6843 for (index = 0; index < pSrcReq->ChannelInfo.
6844 numOfChannels ; index++ )
6845 {
6846 if((csrRoamIsValidChannel(pMac, pSrcReq->ChannelInfo.
6847 ChannelList[index])))
6848 {
6849 /*Skiipping DFS Channels for 1st scan */
6850 if(NV_CHANNEL_DFS ==
6851 vos_nv_getChannelEnabledState(pSrcReq->ChannelInfo.
6852 ChannelList[index]))
6853 continue ;
6854
6855 pDstReq->ChannelInfo.ChannelList[new_index] =
6856 pSrcReq->ChannelInfo.ChannelList[index];
6857 new_index++;
6858
6859 }
6860 }
6861 pMac->roam.configParam.initialScanSkipDFSCh = 0;
6862 }
6863 else
6864 {
6865 for ( index = 0; index < pSrcReq->ChannelInfo.
6866 numOfChannels ; index++ )
Jeff Johnson295189b2012-06-20 16:38:30 -07006867 {
Arif Hussain6af38622014-03-12 12:39:57 -07006868 /* Skip CH 144 if firmware support not present */
6869 if (pSrcReq->ChannelInfo.ChannelList[index] == 144 && !ch144_support)
6870 continue;
6871
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -07006872 /* Allow scan on valid channels only.
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -07006873 */
Abhishek Singh2ec36ab2014-08-07 16:14:25 +05306874 if ( ( csrRoamIsValidChannel(pMac, pSrcReq->ChannelInfo.ChannelList[index]) ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07006875 {
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05306876 if( ((pSrcReq->skipDfsChnlInP2pSearch ||
6877 (pMac->scan.fEnableDFSChnlScan ==
6878 DFS_CHNL_SCAN_DISABLED)) &&
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08006879 (NV_CHANNEL_DFS == vos_nv_getChannelEnabledState(pSrcReq->ChannelInfo.ChannelList[index])) )
Srikant Kuppa866893f2012-12-27 17:28:14 -08006880#ifdef FEATURE_WLAN_LFR
6881 /*
6882 * If LFR is requesting a contiguous scan
6883 * (i.e. numOfChannels > 1), then ignore
6884 * DFS channels.
6885 * TODO: vos_nv_getChannelEnabledState is returning
6886 * 120, 124 and 128 as non-DFS channels. Hence, the
6887 * use of direct check for channels below.
6888 */
6889 || ((eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType) &&
6890 (pSrcReq->ChannelInfo.numOfChannels > 1) &&
Santhosh Kumar Padma9ccaaff2014-07-09 19:58:12 +05306891 (CSR_IS_CHANNEL_DFS(pSrcReq->ChannelInfo.ChannelList[index])) &&
6892 !pMac->roam.configParam.allowDFSChannelRoam)
Srikant Kuppa866893f2012-12-27 17:28:14 -08006893#endif
6894 )
6895 {
6896#ifdef FEATURE_WLAN_LFR
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05306897 smsLog(pMac, LOG2,
6898 FL(" reqType=%s (%d), numOfChannels=%d,"
6899 " ignoring DFS channel %d"),
6900 sme_requestTypetoString(pSrcReq->requestType),
6901 pSrcReq->requestType,
6902 pSrcReq->ChannelInfo.numOfChannels,
6903 pSrcReq->ChannelInfo.ChannelList[index]);
Srikant Kuppa866893f2012-12-27 17:28:14 -08006904#endif
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05306905 continue;
Srikant Kuppa866893f2012-12-27 17:28:14 -08006906 }
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08006907
Jeff Johnson295189b2012-06-20 16:38:30 -07006908 pDstReq->ChannelInfo.ChannelList[new_index] =
6909 pSrcReq->ChannelInfo.ChannelList[index];
6910 new_index++;
6911 }
6912 }
c_hpothu0d5a7352014-03-22 12:30:25 +05306913 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006914 pDstReq->ChannelInfo.numOfChannels = new_index;
Srikant Kuppa866893f2012-12-27 17:28:14 -08006915#ifdef FEATURE_WLAN_LFR
Abhishek Singh2ec36ab2014-08-07 16:14:25 +05306916 if ( ( ( eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType ) ||
6917 ( eCSR_SCAN_P2P_DISCOVERY == pSrcReq->requestType ) ) &&
6918 ( 0 == pDstReq->ChannelInfo.numOfChannels ) )
Srikant Kuppa866893f2012-12-27 17:28:14 -08006919 {
6920 /*
6921 * No valid channels found in the request.
6922 * Only perform scan on the channels passed
Abhishek Singh2ec36ab2014-08-07 16:14:25 +05306923 * pSrcReq if it is a eCSR_SCAN_HO_BG_SCAN or
6924 * eCSR_SCAN_P2P_DISCOVERY.
Srikant Kuppa866893f2012-12-27 17:28:14 -08006925 * Passing 0 to LIM will trigger a scan on
6926 * all valid channels which is not desirable.
6927 */
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306928 smsLog(pMac, LOGE, FL(" no valid channels found"
6929 " (request=%d)"), pSrcReq->requestType);
Srikant Kuppa866893f2012-12-27 17:28:14 -08006930 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
6931 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306932 smsLog(pMac, LOGE, FL("pSrcReq index=%d"
6933 " channel=%d"), index,
6934 pSrcReq->ChannelInfo.ChannelList[index]);
Srikant Kuppa866893f2012-12-27 17:28:14 -08006935 }
6936 status = eHAL_STATUS_FAILURE;
6937 break;
6938 }
6939#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006940 }
6941 else
6942 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306943 smsLog(pMac, LOGE, FL("Couldn't get the valid Channel"
6944 " List, keeping requester's list"));
Kiet Lam64c1b492013-07-12 13:56:44 +05306945 vos_mem_copy(pDstReq->ChannelInfo.ChannelList,
6946 pSrcReq->ChannelInfo.ChannelList,
6947 pSrcReq->ChannelInfo.numOfChannels
6948 * sizeof(*pDstReq->ChannelInfo.ChannelList));
Jeff Johnson295189b2012-06-20 16:38:30 -07006949 pDstReq->ChannelInfo.numOfChannels = pSrcReq->ChannelInfo.numOfChannels;
6950 }
6951 }//Allocate memory for Channel List
6952 }
6953 if(pSrcReq->SSIDs.numOfSSIDs == 0)
6954 {
6955 pDstReq->SSIDs.numOfSSIDs = 0;
6956 pDstReq->SSIDs.SSIDList = NULL;
6957 }
6958 else
6959 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306960 pDstReq->SSIDs.SSIDList = vos_mem_malloc(
6961 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
6962 if ( NULL == pDstReq->SSIDs.SSIDList )
6963 status = eHAL_STATUS_FAILURE;
6964 else
6965 status = eHAL_STATUS_SUCCESS;
6966 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07006967 {
6968 pDstReq->SSIDs.numOfSSIDs = pSrcReq->SSIDs.numOfSSIDs;
Kiet Lam64c1b492013-07-12 13:56:44 +05306969 vos_mem_copy(pDstReq->SSIDs.SSIDList,
6970 pSrcReq->SSIDs.SSIDList,
6971 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
Jeff Johnson295189b2012-06-20 16:38:30 -07006972 }
6973 else
6974 {
6975 pDstReq->SSIDs.numOfSSIDs = 0;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306976 smsLog(pMac, LOGE, FL("No memory for scanning SSID List"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006977 break;
6978 }
6979 }//Allocate memory for SSID List
Jeff Johnson295189b2012-06-20 16:38:30 -07006980 pDstReq->p2pSearch = pSrcReq->p2pSearch;
Jeff Johnsone7245742012-09-05 17:12:55 -07006981 pDstReq->skipDfsChnlInP2pSearch = pSrcReq->skipDfsChnlInP2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07006982
6983 }
6984 }while(0);
6985
6986 if(!HAL_STATUS_SUCCESS(status))
6987 {
6988 csrScanFreeRequest(pMac, pDstReq);
6989 }
6990
6991 return (status);
6992}
6993
6994
6995eHalStatus csrScanFreeRequest(tpAniSirGlobal pMac, tCsrScanRequest *pReq)
6996{
Jeff Johnson295189b2012-06-20 16:38:30 -07006997
6998 if(pReq->ChannelInfo.ChannelList)
6999 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307000 vos_mem_free(pReq->ChannelInfo.ChannelList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007001 pReq->ChannelInfo.ChannelList = NULL;
7002 }
7003 pReq->ChannelInfo.numOfChannels = 0;
7004 if(pReq->pIEField)
7005 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307006 vos_mem_free(pReq->pIEField);
Jeff Johnson295189b2012-06-20 16:38:30 -07007007 pReq->pIEField = NULL;
7008 }
7009 pReq->uIEFieldLen = 0;
7010 if(pReq->SSIDs.SSIDList)
7011 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307012 vos_mem_free(pReq->SSIDs.SSIDList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007013 pReq->SSIDs.SSIDList = NULL;
7014 }
7015 pReq->SSIDs.numOfSSIDs = 0;
7016
Kiet Lam64c1b492013-07-12 13:56:44 +05307017 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07007018}
7019
7020
7021void csrScanCallCallback(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
7022{
7023 if(pCommand->u.scanCmd.callback)
7024 {
Ratheesh S Pece1f832015-07-25 15:50:25 +05307025 if (pCommand->u.scanCmd.abortScanIndication){
Kapil Guptac46b7542016-10-25 13:03:20 +05307026 if ((pCommand->u.scanCmd.reason != eCsrScanForSsid) ||
7027 (scanStatus != eCSR_SCAN_SUCCESS)) {
7028 smsLog( pMac, LOG1, FL("scanDone due to abort"));
7029 scanStatus = eCSR_SCAN_ABORT;
7030 }
Ratheesh S Pece1f832015-07-25 15:50:25 +05307031 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007032 pCommand->u.scanCmd.callback(pMac, pCommand->u.scanCmd.pContext, pCommand->u.scanCmd.scanID, scanStatus);
Jeff Johnson295189b2012-06-20 16:38:30 -07007033 } else {
Kapil Guptac46b7542016-10-25 13:03:20 +05307034 smsLog(pMac, LOG2,
7035 FL("Callback NULL cmd reason %d"),
7036 pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07007037 }
7038}
7039
7040
7041void csrScanStopTimers(tpAniSirGlobal pMac)
7042{
Jeff Johnson295189b2012-06-20 16:38:30 -07007043 csrScanStopIdleScanTimer(pMac);
7044 csrScanStopGetResultTimer(pMac);
7045}
7046
7047
7048eHalStatus csrScanStartGetResultTimer(tpAniSirGlobal pMac)
7049{
7050 eHalStatus status;
7051
7052 if(pMac->scan.fScanEnable)
7053 {
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05307054 status = vos_timer_start(&pMac->scan.hTimerGetResult, CSR_SCAN_GET_RESULT_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07007055 }
7056 else
7057 {
7058 status = eHAL_STATUS_FAILURE;
7059 }
7060
7061 return (status);
7062}
7063
7064
7065eHalStatus csrScanStopGetResultTimer(tpAniSirGlobal pMac)
7066{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05307067 return (vos_timer_stop(&pMac->scan.hTimerGetResult));
Jeff Johnson295189b2012-06-20 16:38:30 -07007068}
7069
7070
7071void csrScanGetResultTimerHandler(void *pv)
7072{
7073 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
7074
7075 csrScanRequestResult(pMac);
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05307076
7077 vos_timer_start(&pMac->scan.hTimerGetResult, CSR_SCAN_GET_RESULT_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07007078}
7079
7080#ifdef WLAN_AP_STA_CONCURRENCY
7081static void csrStaApConcTimerHandler(void *pv)
7082{
7083 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
7084 tListElem *pEntry;
7085 tSmeCmd *pScanCmd;
7086
7087 csrLLLock(&pMac->scan.scanCmdPendingList);
7088
7089 if ( NULL != ( pEntry = csrLLPeekHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) ) )
7090 {
7091 tCsrScanRequest scanReq;
7092 tSmeCmd *pSendScanCmd = NULL;
7093 tANI_U8 numChn = 0;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07007094 tANI_U8 nNumChanCombinedConc = 0;
Vinay Malekal05fdc812012-12-17 13:04:30 -08007095 tANI_U8 i, j;
Jeff Johnson295189b2012-06-20 16:38:30 -07007096 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
7097 tANI_U8 channelToScan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
7098 eHalStatus status;
7099
Jeff Johnson295189b2012-06-20 16:38:30 -07007100 pScanCmd = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7101 numChn = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08007102
7103 /* if any session is connected and the number of channels to scan is
7104 * greater than 1 then split the scan into multiple scan operations
7105 * on each individual channel else continue to perform scan on all
7106 * specified channels */
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08007107
7108 /* split scan if number of channels to scan is greater than 1 and
7109 * any one of the following:
7110 * - STA session is connected and the scan is not a P2P search
7111 * - any P2P session is connected
Srikant Kuppa866893f2012-12-27 17:28:14 -08007112 * Do not split scans if no concurrent infra connections are
7113 * active and if the scan is a BG scan triggered by LFR (OR)
7114 * any scan if LFR is in the middle of a BG scan. Splitting
7115 * the scan is delaying the time it takes for LFR to find
7116 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08007117 */
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07007118
7119 if((csrIsStaSessionConnected(pMac) &&
7120 !csrIsP2pSessionConnected(pMac)))
7121 {
7122 nNumChanCombinedConc = pMac->roam.configParam.nNumStaChanCombinedConc;
7123 }
7124 else if(csrIsP2pSessionConnected(pMac))
7125 {
7126 nNumChanCombinedConc = pMac->roam.configParam.nNumP2PChanCombinedConc;
7127 }
7128
7129 if ( (numChn > nNumChanCombinedConc) &&
Srikant Kuppa866893f2012-12-27 17:28:14 -08007130 ((csrIsStaSessionConnected(pMac) &&
7131#ifdef FEATURE_WLAN_LFR
7132 (csrIsConcurrentInfraConnected(pMac) ||
7133 ((pScanCmd->u.scanCmd.reason != eCsrScanBgScan) &&
7134 (pMac->roam.neighborRoamInfo.neighborRoamState !=
7135 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
7136#endif
7137 (pScanCmd->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08007138 (csrIsP2pSessionConnected(pMac))))
Jeff Johnson295189b2012-06-20 16:38:30 -07007139 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307140 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007141
7142 pSendScanCmd = csrGetCommandBuffer(pMac); //optimize this to use 2 command buffer only
7143 if (!pSendScanCmd)
7144 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007145 smsLog( pMac, LOGE, FL(" Failed to get Queue command buffer") );
Jeff Johnson295189b2012-06-20 16:38:30 -07007146 csrLLUnlock(&pMac->scan.scanCmdPendingList);
7147 return;
7148 }
7149 pSendScanCmd->command = pScanCmd->command;
7150 pSendScanCmd->sessionId = pScanCmd->sessionId;
7151 pSendScanCmd->u.scanCmd.callback = NULL;
7152 pSendScanCmd->u.scanCmd.pContext = pScanCmd->u.scanCmd.pContext;
7153 pSendScanCmd->u.scanCmd.reason = pScanCmd->u.scanCmd.reason;
7154 pSendScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
7155
Madan Mohan Koyyalamudiaf2a8b92012-10-09 14:58:07 -07007156 /* First copy all the parameters to local variable of scan request */
7157 csrScanCopyRequest(pMac, &scanReq, &pScanCmd->u.scanCmd.u.scanRequest);
7158
7159 /* Now modify the elements of local var scan request required to be modified for split scan */
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08007160 if(scanReq.ChannelInfo.ChannelList != NULL)
7161 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307162 vos_mem_free(scanReq.ChannelInfo.ChannelList);
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08007163 scanReq.ChannelInfo.ChannelList = NULL;
7164 }
7165
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07007166 pChnInfo->numOfChannels = nNumChanCombinedConc;
Kiet Lam64c1b492013-07-12 13:56:44 +05307167 vos_mem_copy(&channelToScan[0],
7168 &pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[0],
7169 pChnInfo->numOfChannels * sizeof(tANI_U8));//just send one channel
Jeff Johnson295189b2012-06-20 16:38:30 -07007170 pChnInfo->ChannelList = &channelToScan[0];
7171
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07007172 for (i = 0, j = nNumChanCombinedConc; i < (numChn-nNumChanCombinedConc); i++, j++)
Jeff Johnson295189b2012-06-20 16:38:30 -07007173 {
7174 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] =
Vinay Malekal05fdc812012-12-17 13:04:30 -08007175 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[j]; //Move all the channels one step
Jeff Johnson295189b2012-06-20 16:38:30 -07007176 }
7177
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07007178 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = numChn - nNumChanCombinedConc; //reduce outstanding # of channels to be scanned
Jeff Johnson295189b2012-06-20 16:38:30 -07007179
7180 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
c_hpothudbefd3e2014-04-28 15:59:47 +05307181
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -07007182 //Use concurrency values for min/maxChnTime.
7183 //We know csrIsAnySessionConnected(pMac) returns TRUE here
7184 csrSetDefaultScanTiming(pMac, scanReq.scanType, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07007185
7186 status = csrScanCopyRequest(pMac, &pSendScanCmd->u.scanCmd.u.scanRequest, &scanReq);
7187 if(!HAL_STATUS_SUCCESS(status))
7188 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007189 smsLog( pMac, LOGE, FL(" Failed to get copy csrScanRequest = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07007190 csrLLUnlock(&pMac->scan.scanCmdPendingList);
7191 return;
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08007192 }
7193 /* Clean the local scan variable */
7194 scanReq.ChannelInfo.ChannelList = NULL;
7195 scanReq.ChannelInfo.numOfChannels = 0;
7196 csrScanFreeRequest(pMac, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07007197 }
7198 else
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08007199 {
7200 /* no active connected session present or numChn == 1
7201 * scan all remaining channels */
Jeff Johnson295189b2012-06-20 16:38:30 -07007202 pSendScanCmd = pScanCmd;
7203 //remove this command from pending list
7204 if (csrLLRemoveHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) == NULL)
7205 { //In case between PeekHead and here, the entry got removed by another thread.
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007206 smsLog( pMac, LOGE, FL(" Failed to remove entry from scanCmdPendingList"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007207 }
7208
7209 }
7210 csrQueueSmeCommand(pMac, pSendScanCmd, eANI_BOOLEAN_FALSE);
7211
7212 }
7213
Jeff Johnson295189b2012-06-20 16:38:30 -07007214 csrLLUnlock(&pMac->scan.scanCmdPendingList);
7215
7216}
7217#endif
7218
Jeff Johnson295189b2012-06-20 16:38:30 -07007219//This function returns the maximum time a BSS is allowed in the scan result.
7220//The time varies base on connection and power saving factors.
7221//Not connected, No PS
7222//Not connected, with PS
7223//Connected w/o traffic, No PS
7224//Connected w/o traffic, with PS
7225//Connected w/ traffic, no PS -- Not supported
7226//Connected w/ traffic, with PS -- Not supported
7227//the return unit is in seconds.
7228tANI_U32 csrScanGetAgeOutTime(tpAniSirGlobal pMac)
7229{
7230 tANI_U32 nRet;
7231
7232 if(pMac->scan.nAgingCountDown)
7233 {
7234 //Calculate what should be the timeout value for this
7235 nRet = pMac->scan.nLastAgeTimeOut * pMac->scan.nAgingCountDown;
7236 pMac->scan.nAgingCountDown--;
7237 }
7238 else
7239 {
7240 if( csrIsAllSessionDisconnected( pMac ) )
7241 {
7242 if(pmcIsPowerSaveEnabled(pMac, ePMC_IDLE_MODE_POWER_SAVE))
7243 {
7244 nRet = pMac->roam.configParam.scanAgeTimeNCPS;
7245 }
7246 else
7247 {
7248 nRet = pMac->roam.configParam.scanAgeTimeNCNPS;
7249 }
7250 }
7251 else
7252 {
7253 if(pmcIsPowerSaveEnabled(pMac, ePMC_BEACON_MODE_POWER_SAVE))
7254 {
7255 nRet = pMac->roam.configParam.scanAgeTimeCPS;
7256 }
7257 else
7258 {
7259 nRet = pMac->roam.configParam.scanAgeTimeCNPS;
7260 }
7261 }
7262 //If state-change causing aging time out change, we want to delay it somewhat to avoid
7263 //unnecessary removal of BSS. This is mostly due to transition from connect to disconnect.
7264 if(pMac->scan.nLastAgeTimeOut > nRet)
7265 {
7266 if(nRet)
7267 {
7268 pMac->scan.nAgingCountDown = (pMac->scan.nLastAgeTimeOut / nRet);
7269 }
7270 pMac->scan.nLastAgeTimeOut = nRet;
7271 nRet *= pMac->scan.nAgingCountDown;
7272 }
7273 else
7274 {
7275 pMac->scan.nLastAgeTimeOut = nRet;
7276 }
7277 }
7278
7279 return (nRet);
7280}
7281
Deepthi Gowri6a08e312016-03-31 19:10:14 +05307282static void csrPurgeScanResultByAge(void *pv)
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08007283{
7284 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
7285 tListElem *pEntry, *tmpEntry;
7286 tCsrScanResult *pResult;
Deepthi Gowri4480a3f2016-05-18 19:30:17 +05307287 v_TIME_t ageOutTime =
7288 (v_TIME_t)(pMac->scan.scanResultCfgAgingTime * SYSTEM_TIME_SEC_TO_MSEC);
7289 v_TIME_t curTime = vos_timer_get_system_time();
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08007290
7291 csrLLLock(&pMac->scan.scanResultList);
7292 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
Deepthi Gowri6a08e312016-03-31 19:10:14 +05307293 smsLog(pMac, LOG1, FL("Ageout time=%lu"),ageOutTime);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08007294 while( pEntry )
7295 {
7296 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
7297 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
7298 if((curTime - pResult->Result.BssDescriptor.nReceivedTime) > ageOutTime)
7299 {
Deepthi Gowri50e2fa52016-03-17 15:30:53 +05307300 smsLog(pMac, LOG1, FL("age out due to time out for BSSID" MAC_ADDRESS_STR),
7301 MAC_ADDR_ARRAY(pResult->Result.BssDescriptor.bssId));
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08007302 csrScanAgeOutBss(pMac, pResult);
7303 }
7304 pEntry = tmpEntry;
7305 }
7306 csrLLUnlock(&pMac->scan.scanResultList);
7307}
Jeff Johnson295189b2012-06-20 16:38:30 -07007308
7309eHalStatus csrScanStartIdleScanTimer(tpAniSirGlobal pMac, tANI_U32 interval)
7310{
7311 eHalStatus status;
7312
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007313 smsLog(pMac, LOG1, " csrScanStartIdleScanTimer");
Jeff Johnson295189b2012-06-20 16:38:30 -07007314 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) && interval)
7315 {
7316 pMac->scan.nIdleScanTimeGap += interval;
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05307317 vos_timer_stop(&pMac->scan.hTimerIdleScan);
7318 status = vos_timer_start(&pMac->scan.hTimerIdleScan, interval/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07007319 if( !HAL_STATUS_SUCCESS(status) )
7320 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007321 smsLog(pMac, LOGE, " Fail to start Idle scan timer. status = %d interval = %d", status, interval);
Jeff Johnson295189b2012-06-20 16:38:30 -07007322 //This should not happen but set the flag to restart when ready
7323 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7324 }
7325 }
7326 else
7327 {
7328 if( pMac->scan.fScanEnable && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) )
7329 {
7330 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7331 }
7332 status = eHAL_STATUS_FAILURE;
7333 }
7334
7335 return (status);
7336}
7337
7338
7339eHalStatus csrScanStopIdleScanTimer(tpAniSirGlobal pMac)
7340{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05307341 return (vos_timer_stop(&pMac->scan.hTimerIdleScan));
Jeff Johnson295189b2012-06-20 16:38:30 -07007342}
7343
7344
7345//Stop CSR from asking for IMPS, This function doesn't disable IMPS from CSR
7346void csrScanSuspendIMPS( tpAniSirGlobal pMac )
7347{
7348 csrScanCancelIdleScan(pMac);
7349}
7350
7351
7352//Start CSR from asking for IMPS. This function doesn't trigger CSR to request entering IMPS
7353//because IMPS maybe disabled.
7354void csrScanResumeIMPS( tpAniSirGlobal pMac )
7355{
7356 csrScanStartIdleScan( pMac );
7357}
7358
7359
7360void csrScanIMPSCallback(void *callbackContext, eHalStatus status)
7361{
7362 tpAniSirGlobal pMac = PMAC_STRUCT( callbackContext );
7363
7364 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
7365 {
7366 if(pMac->roam.configParam.IsIdleScanEnabled)
7367 {
7368 if(HAL_STATUS_SUCCESS(status))
7369 {
7370 if(csrIsAllSessionDisconnected(pMac) && !csrIsRoamCommandWaiting(pMac))
7371 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007372 smsLog(pMac, LOGW, FL("starts idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007373 csrScanAllChannels(pMac, eCSR_SCAN_IDLE_MODE_SCAN);
7374 }
7375 else
7376 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007377 smsLog(pMac, LOGW, FL("cannot start idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007378 //even though we are in timer handle, calling stop timer will make sure the timer
7379 //doesn't get to restart.
7380 csrScanStopIdleScanTimer(pMac);
7381 }
7382 }
7383 else
7384 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007385 smsLog(pMac, LOGE, FL("sees not success status (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07007386 }
7387 }
7388 else
7389 {//we might need another flag to check if CSR needs to request imps at all
7390
7391 tANI_U32 nTime = 0;
7392
7393 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_FALSE;
7394 if(!HAL_STATUS_SUCCESS(csrScanTriggerIdleScan(pMac, &nTime)))
7395 {
7396 csrScanStartIdleScanTimer(pMac, nTime);
7397 }
7398 }
7399 }
7400}
7401
7402
Rashmi Ramanna68b309c2014-05-20 11:52:22 +05307403//Param: pTimeInterval -- Caller allocated memory in return, if failed, to specify the nxt time interval for
Jeff Johnson295189b2012-06-20 16:38:30 -07007404//idle scan timer interval
7405//Return: Not success -- meaning it cannot start IMPS, caller needs to start a timer for idle scan
7406eHalStatus csrScanTriggerIdleScan(tpAniSirGlobal pMac, tANI_U32 *pTimeInterval)
7407{
7408 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
7409
7410 //Do not trigger IMPS in case of concurrency
Agarwal Ashish5974ed32014-06-16 16:59:54 +05307411 if (vos_concurrent_open_sessions_running() &&
7412 csrIsAnySessionInConnectState(pMac))
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007413 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007414 smsLog( pMac, LOG1, FL("Cannot request IMPS because Concurrent Sessions Running") );
Jeff Johnson295189b2012-06-20 16:38:30 -07007415 return (status);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007416 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007417
7418 if(pTimeInterval)
7419 {
7420 *pTimeInterval = 0;
7421 }
7422
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007423 smsLog(pMac, LOG3, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007424 if( smeCommandPending( pMac ) )
7425 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007426 smsLog( pMac, LOG1, FL(" Cannot request IMPS because command pending") );
Jeff Johnson295189b2012-06-20 16:38:30 -07007427 //Not to enter IMPS because more work to do
7428 if(pTimeInterval)
7429 {
7430 *pTimeInterval = 0;
7431 }
7432 //restart when ready
7433 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7434
7435 return (status);
7436 }
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07007437 if (IsPmcImpsReqFailed (pMac))
7438 {
7439 if(pTimeInterval)
7440 {
7441 *pTimeInterval = 1000000; //usec
7442 }
7443 //restart when ready
7444 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07007445
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07007446 return status;
7447 }
Rashmi Ramanna68b309c2014-05-20 11:52:22 +05307448
7449 if ( !pMac->deferImps && pMac->fDeferIMPSTime )
7450 {
7451 smsLog( pMac, LOG1, FL("Defer IMPS for %dms as command processed"),
7452 pMac->fDeferIMPSTime);
Girish Gowli4f3775a2014-05-30 17:17:08 +05307453 if(pTimeInterval)
7454 {
7455 *pTimeInterval = pMac->fDeferIMPSTime * 1000; //usec
7456 }
Rashmi Ramanna68b309c2014-05-20 11:52:22 +05307457 pMac->deferImps = eANI_BOOLEAN_TRUE;
7458 return status;
7459 }
7460
Jeff Johnson295189b2012-06-20 16:38:30 -07007461 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
7462 /*&& pMac->roam.configParam.impsSleepTime*/)
7463 {
7464 //Stop get result timer because idle scan gets scan result out of PE
7465 csrScanStopGetResultTimer(pMac);
7466 if(pTimeInterval)
7467 {
7468 *pTimeInterval = pMac->roam.configParam.impsSleepTime;
7469 }
7470 //pmcRequestImps take a period in millisecond unit.
7471 status = pmcRequestImps(pMac, pMac->roam.configParam.impsSleepTime / PAL_TIMER_TO_MS_UNIT, csrScanIMPSCallback, pMac);
7472 if(!HAL_STATUS_SUCCESS(status))
7473 {
7474 if(eHAL_STATUS_PMC_ALREADY_IN_IMPS != status)
7475 {
7476 //Do restart the timer if CSR thinks it cannot do IMPS
7477 if( !csrCheckPSReady( pMac ) )
7478 {
7479 if(pTimeInterval)
7480 {
7481 *pTimeInterval = 0;
7482 }
7483 //Set the restart flag to true because that idle scan
7484 //can be restarted even though the timer will not be running
7485 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7486 }
7487 else
7488 {
7489 //For not now, we do a quicker retry
7490 if(pTimeInterval)
7491 {
7492 *pTimeInterval = CSR_IDLE_SCAN_WAIT_TIME;
7493 }
7494 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007495 smsLog(pMac, LOGW, FL("call pmcRequestImps and it returns status code (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07007496 }
7497 else
7498 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007499 smsLog(pMac, LOGW, FL("already in IMPS"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007500 //Since CSR is the only module to request for IMPS. If it is already in IMPS, CSR assumes
7501 //the callback will be called in the future. Should not happen though.
7502 status = eHAL_STATUS_SUCCESS;
7503 pMac->scan.nIdleScanTimeGap = 0;
7504 }
7505 }
7506 else
7507 {
7508 //requested so let's reset the value
7509 pMac->scan.nIdleScanTimeGap = 0;
7510 }
7511 }
7512
7513 return (status);
7514}
7515
7516
7517eHalStatus csrScanStartIdleScan(tpAniSirGlobal pMac)
7518{
7519 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
7520 tANI_U32 nTime = 0;
7521
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007522 smsLog(pMac, LOGW, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007523 if(pMac->roam.configParam.IsIdleScanEnabled)
7524 {
7525 //stop bg scan first
7526 csrScanBGScanAbort(pMac);
7527 //Stop get result timer because idle scan gets scan result out of PE
7528 csrScanStopGetResultTimer(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07007529 }
7530 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_FALSE;
7531 status = csrScanTriggerIdleScan(pMac, &nTime);
7532 if(!HAL_STATUS_SUCCESS(status))
7533 {
7534 csrScanStartIdleScanTimer(pMac, nTime);
7535 }
7536
7537 return (status);
7538}
7539
7540
7541void csrScanCancelIdleScan(tpAniSirGlobal pMac)
7542{
7543 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
7544 {
Agarwal Ashish5974ed32014-06-16 16:59:54 +05307545 if (vos_concurrent_open_sessions_running()) {
Jeff Johnson295189b2012-06-20 16:38:30 -07007546 return;
7547 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007548 smsLog(pMac, LOG1, " csrScanCancelIdleScan");
Jeff Johnson295189b2012-06-20 16:38:30 -07007549 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_TRUE;
7550 //Set the restart flag in case later on it is uncancelled
7551 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7552 csrScanStopIdleScanTimer(pMac);
7553 csrScanRemoveNotRoamingScanCommand(pMac);
7554 }
7555}
7556
7557
7558void csrScanIdleScanTimerHandler(void *pv)
7559{
7560 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
7561 eHalStatus status;
7562 tANI_U32 nTime = 0;
7563
7564 smsLog(pMac, LOGW, " csrScanIdleScanTimerHandler called ");
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07007565 pmcResetImpsFailStatus (pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07007566 status = csrScanTriggerIdleScan(pMac, &nTime);
7567 if(!HAL_STATUS_SUCCESS(status) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan))
7568 {
7569 //Check whether it is time to actually do an idle scan
7570 if(pMac->scan.nIdleScanTimeGap >= pMac->roam.configParam.impsSleepTime)
7571 {
7572 pMac->scan.nIdleScanTimeGap = 0;
7573 csrScanIMPSCallback(pMac, eHAL_STATUS_SUCCESS);
7574 }
7575 else
7576 {
7577 csrScanStartIdleScanTimer(pMac, nTime);
7578 }
7579 }
Rashmi Ramanna68b309c2014-05-20 11:52:22 +05307580 if(pMac->deferImps)
7581 {
7582 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7583 pMac->deferImps = eANI_BOOLEAN_FALSE;
7584 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007585}
7586
7587
7588
7589
7590tANI_BOOLEAN csrScanRemoveNotRoamingScanCommand(tpAniSirGlobal pMac)
7591{
7592 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
7593 tListElem *pEntry, *pEntryTmp;
7594 tSmeCmd *pCommand;
7595 tDblLinkList localList;
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307596 tDblLinkList *pCmdList;
Jeff Johnson295189b2012-06-20 16:38:30 -07007597
7598 vos_mem_zero(&localList, sizeof(tDblLinkList));
7599 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
7600 {
7601 smsLog(pMac, LOGE, FL(" failed to open list"));
7602 return fRet;
7603 }
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307604 if (!pMac->fScanOffload)
7605 pCmdList = &pMac->sme.smeCmdPendingList;
7606 else
7607 pCmdList = &pMac->sme.smeScanCmdPendingList;
Jeff Johnson295189b2012-06-20 16:38:30 -07007608
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307609 csrLLLock(pCmdList);
7610 pEntry = csrLLPeekHead(pCmdList, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007611 while(pEntry)
7612 {
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307613 pEntryTmp = csrLLNext(pCmdList, pEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007614 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7615 if( eSmeCommandScan == pCommand->command )
7616 {
7617 switch( pCommand->u.scanCmd.reason )
7618 {
7619 case eCsrScanIdleScan:
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 default:
7628 break;
7629 } //switch
7630 }
7631 pEntry = pEntryTmp;
7632 }
7633
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307634 csrLLUnlock(pCmdList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007635
7636 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
7637 {
7638 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7639 csrReleaseCommandScan( pMac, pCommand );
7640 }
7641
7642 csrLLClose(&localList);
7643
7644 return (fRet);
7645}
7646
7647
7648tANI_BOOLEAN csrScanRemoveFreshScanCommand(tpAniSirGlobal pMac, tANI_U8 sessionId)
7649{
7650 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
7651 tListElem *pEntry, *pEntryTmp;
7652 tSmeCmd *pCommand;
7653 tDblLinkList localList;
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307654 tDblLinkList *pCmdList;
Jeff Johnson295189b2012-06-20 16:38:30 -07007655
7656 vos_mem_zero(&localList, sizeof(tDblLinkList));
7657 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
7658 {
7659 smsLog(pMac, LOGE, FL(" failed to open list"));
7660 return fRet;
7661 }
7662
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307663 if (!pMac->fScanOffload)
7664 pCmdList = &pMac->sme.smeCmdPendingList;
7665 else
7666 pCmdList = &pMac->sme.smeScanCmdPendingList;
7667
7668 csrLLLock(pCmdList);
7669 pEntry = csrLLPeekHead(pCmdList, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007670 while(pEntry)
7671 {
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307672 pEntryTmp = csrLLNext(pCmdList, pEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007673 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7674 if( (eSmeCommandScan == pCommand->command) && (sessionId == pCommand->sessionId) )
7675 {
7676 switch(pCommand->u.scanCmd.reason)
7677 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07007678#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
7679 case eCsrScanGetLfrResult:
7680#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07007681 case eCsrScanGetResult:
7682 case eCsrScanSetBGScanParam:
7683 case eCsrScanBGScanAbort:
7684 case eCsrScanBGScanEnable:
7685 case eCsrScanGetScanChnInfo:
7686 break;
7687 default:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007688 smsLog (pMac, LOGW, "%s: -------- abort scan command reason = %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007689 __func__, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07007690 //The rest are fresh scan requests
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307691 if( csrLLRemoveEntry(pCmdList, pEntry, LL_ACCESS_NOLOCK) )
Jeff Johnson295189b2012-06-20 16:38:30 -07007692 {
7693 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
7694 }
7695 fRet = eANI_BOOLEAN_TRUE;
7696 break;
7697 }
7698 }
7699 pEntry = pEntryTmp;
7700 }
7701
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307702 csrLLUnlock(pCmdList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007703
7704 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
7705 {
7706 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7707 if (pCommand->u.scanCmd.callback)
7708 {
7709 /* User scan request is pending,
7710 * send response with status eCSR_SCAN_ABORT*/
7711 pCommand->u.scanCmd.callback(pMac,
7712 pCommand->u.scanCmd.pContext,
7713 pCommand->u.scanCmd.scanID,
7714 eCSR_SCAN_ABORT);
7715 }
7716 csrReleaseCommandScan( pMac, pCommand );
7717 }
7718 csrLLClose(&localList);
7719
7720 return (fRet);
7721}
7722
7723
7724void csrReleaseScanCommand(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
7725{
7726 eCsrScanReason reason = pCommand->u.scanCmd.reason;
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307727 tANI_BOOLEAN status;
7728
7729 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07007730 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307731 tANI_U32 i;
7732 for(i = 0; i < CSR_ROAM_SESSION_MAX; i++)
Abhishek Singhf52182c2016-08-24 11:15:23 +05307733 csrRoamStateChange(pMac,
7734 pMac->roam.prev_state[i], i);
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307735 }
7736 else
7737 {
7738 csrRoamStateChange(pMac,
Abhishek Singhf52182c2016-08-24 11:15:23 +05307739 pMac->roam.prev_state[pCommand->sessionId],
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307740 pCommand->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07007741 }
7742
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307743 csrScanCallCallback(pMac, pCommand, scanStatus);
Jeff Johnson295189b2012-06-20 16:38:30 -07007744
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007745 smsLog(pMac, LOG3, " Remove Scan command reason = %d", reason);
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307746 if (pMac->fScanOffload)
7747 {
7748 status = csrLLRemoveEntry(&pMac->sme.smeScanCmdActiveList,
7749 &pCommand->Link, LL_ACCESS_LOCK);
7750 }
7751 else
7752 {
7753 status = csrLLRemoveEntry(&pMac->sme.smeCmdActiveList,
7754 &pCommand->Link, LL_ACCESS_LOCK);
7755 }
7756
7757 if(status)
Jeff Johnson295189b2012-06-20 16:38:30 -07007758 {
7759 csrReleaseCommandScan( pMac, pCommand );
7760 }
7761 else
7762 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307763 smsLog(pMac, LOGE,
7764 " ********csrReleaseScanCommand cannot release command reason %d",
7765 pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07007766 }
7767}
7768
7769
7770eHalStatus csrScanGetPMKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
7771 tPmkidCandidateInfo *pPmkidList, tANI_U32 *pNumItems )
7772{
7773 eHalStatus status = eHAL_STATUS_SUCCESS;
7774 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
7775
Jeff Johnson32d95a32012-09-10 13:15:23 -07007776 if(!pSession)
7777 {
7778 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
7779 return eHAL_STATUS_FAILURE;
7780 }
7781
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007782 smsLog(pMac, LOGW, " pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07007783 csrResetPMKIDCandidateList(pMac, sessionId);
7784 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
7785 {
7786 tCsrScanResultFilter *pScanFilter;
7787 tCsrScanResultInfo *pScanResult;
7788 tScanResultHandle hBSSList;
7789 tANI_U32 nItems = *pNumItems;
7790
7791 *pNumItems = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05307792 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
7793 if ( NULL == pScanFilter )
7794 status = eHAL_STATUS_FAILURE;
7795 else
Jeff Johnson295189b2012-06-20 16:38:30 -07007796 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307797 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007798 //Here is the profile we need to connect to
7799 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
7800 if(HAL_STATUS_SUCCESS(status))
7801 {
7802 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
7803 if(HAL_STATUS_SUCCESS(status))
7804 {
7805 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumPmkidCandidate < nItems))
7806 {
7807 //NumPmkidCandidate adds up here
7808 csrProcessBSSDescForPMKIDList(pMac, &pScanResult->BssDescriptor,
7809 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
7810 }
7811 if(pSession->NumPmkidCandidate)
7812 {
7813 *pNumItems = pSession->NumPmkidCandidate;
Kiet Lam64c1b492013-07-12 13:56:44 +05307814 vos_mem_copy(pPmkidList, pSession->PmkidCandidateInfo,
7815 pSession->NumPmkidCandidate * sizeof(tPmkidCandidateInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07007816 }
7817 csrScanResultPurge(pMac, hBSSList);
7818 }//Have scan result
7819 csrFreeScanFilter(pMac, pScanFilter);
7820 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307821 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07007822 }
7823 }
7824
7825 return (status);
7826}
7827
7828
7829
7830#ifdef FEATURE_WLAN_WAPI
7831eHalStatus csrScanGetBKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
7832 tBkidCandidateInfo *pBkidList, tANI_U32 *pNumItems )
7833{
7834 eHalStatus status = eHAL_STATUS_SUCCESS;
7835 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
7836
Jeff Johnson32d95a32012-09-10 13:15:23 -07007837 if(!pSession)
7838 {
7839 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
7840 return eHAL_STATUS_FAILURE;
7841 }
7842
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007843 smsLog(pMac, LOGW, " pMac->scan.NumBkidCandidate = %d", pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07007844 csrResetBKIDCandidateList(pMac, sessionId);
7845 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
7846 {
7847 tCsrScanResultFilter *pScanFilter;
7848 tCsrScanResultInfo *pScanResult;
7849 tScanResultHandle hBSSList;
7850 tANI_U32 nItems = *pNumItems;
7851 *pNumItems = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05307852 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
7853 if ( NULL == pScanFilter )
7854 status = eHAL_STATUS_FAILURE;
7855 else
Jeff Johnson295189b2012-06-20 16:38:30 -07007856 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307857 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007858 //Here is the profile we need to connect to
7859 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
7860 if(HAL_STATUS_SUCCESS(status))
7861 {
7862 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
7863 if(HAL_STATUS_SUCCESS(status))
7864 {
7865 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumBkidCandidate < nItems))
7866 {
7867 //pMac->scan.NumBkidCandidate adds up here
7868 csrProcessBSSDescForBKIDList(pMac, &pScanResult->BssDescriptor,
7869 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
7870
7871 }
7872 if(pSession->NumBkidCandidate)
7873 {
7874 *pNumItems = pSession->NumBkidCandidate;
Kiet Lam64c1b492013-07-12 13:56:44 +05307875 vos_mem_copy(pBkidList, pSession->BkidCandidateInfo, pSession->NumBkidCandidate * sizeof(tBkidCandidateInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07007876 }
7877 csrScanResultPurge(pMac, hBSSList);
7878 }//Have scan result
7879 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307880 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07007881 }
7882 }
7883
7884 return (status);
7885}
7886#endif /* FEATURE_WLAN_WAPI */
7887
Selvaraj, Sridhar32417ed2016-06-22 15:19:12 +05307888/**
7889 * csr_scan_request_set_chan_time() - Populate max and min
7890 * channel time in Scan request
7891 * @pMac - pointer to mac context
7892 * @pScanCmd - pointer to the Scan command
7893 *
7894 * Return - None
7895 */
7896#ifndef QCA_WIFI_ISOC
7897static void csr_scan_request_set_chan_time(tpAniSirGlobal pMac,
7898 tSmeCmd *pScanCmd)
7899{
7900 if (pMac->roam.neighborRoamInfo.handoffReqInfo.src
7901 == FASTREASSOC) {
7902 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime
7903 = MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL_FASTREASSOC;
7904 pScanCmd->u.scanCmd.u.scanRequest.minChnTime
7905 = MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL_FASTREASSOC;
7906 pMac->roam.neighborRoamInfo.handoffReqInfo.src = 0;
7907 } else {
7908 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime
7909 = MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7910 pScanCmd->u.scanCmd.u.scanRequest.minChnTime
7911 = MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7912 }
7913}
7914#else
7915static void csr_scan_request_set_chan_time(tpAniSirGlobal pMac,
7916 tSmeCmd *pScanCmd)
7917{
7918 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime
7919 = MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7920 pScanCmd->u.scanCmd.u.scanRequest.minChnTime
7921 = MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7922}
7923#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07007924
Kapil Guptac46b7542016-10-25 13:03:20 +05307925/**
7926 * csr_ssid_scan_done_callback() - Callback to indicate
7927 * scan is done for ssid scan
7928 * @halHandle: handle to hal
7929 * @context: SSID scan context
7930 * @scanId: Scan id for the scheduled scan
7931 * @status: scan done status
7932 *
7933 * Return - eHalStatus
7934 */
7935static eHalStatus csr_ssid_scan_done_callback(tHalHandle halHandle,
7936 void *context,
7937 tANI_U32 scanId,
7938 eCsrScanStatus status)
7939{
7940 struct csr_scan_for_ssid_context *scan_context =
7941 (struct csr_scan_for_ssid_context *)context;
7942
7943 if (NULL == scan_context)
7944 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR,
7945 FL("scan for ssid context not found"));
7946
7947 if (eCSR_SCAN_ABORT == status)
7948 csrRoamCallCallback(scan_context->pMac, scan_context->sessionId,
7949 NULL, scan_context->roamId,
7950 eCSR_ROAM_ASSOCIATION_FAILURE,
7951 eCSR_ROAM_RESULT_SCAN_FOR_SSID_FAILURE);
7952 vos_mem_free(scan_context);
7953 return eHAL_STATUS_SUCCESS;
7954}
7955
Jeff Johnson295189b2012-06-20 16:38:30 -07007956//This function is usually used for BSSs that suppresses SSID so the profile
7957//shall have one and only one SSID
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007958eHalStatus csrScanForSSID(tpAniSirGlobal pMac, tANI_U32 sessionId, tCsrRoamProfile *pProfile, tANI_U32 roamId, tANI_BOOLEAN notify)
Jeff Johnson295189b2012-06-20 16:38:30 -07007959{
7960 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
7961 tSmeCmd *pScanCmd = NULL;
7962 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
7963 tANI_U8 index = 0;
7964 tANI_U32 numSsid = pProfile->SSIDs.numOfSSIDs;
Kapil Guptac46b7542016-10-25 13:03:20 +05307965 struct csr_scan_for_ssid_context *context;
Jeff Johnson295189b2012-06-20 16:38:30 -07007966
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007967 smsLog(pMac, LOG2, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007968 //For WDS, we use the index 0. There must be at least one in there
7969 if( CSR_IS_WDS_STA( pProfile ) && numSsid )
7970 {
7971 numSsid = 1;
7972 }
7973 if(pMac->scan.fScanEnable && ( numSsid == 1 ) )
7974 {
7975 do
7976 {
7977 pScanCmd = csrGetCommandBuffer(pMac);
7978 if(!pScanCmd)
7979 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007980 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007981 break;
7982 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307983 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
7984 pScanCmd->u.scanCmd.pToRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
7985 if ( NULL == pScanCmd->u.scanCmd.pToRoamProfile )
krunal soni587bf012014-02-04 12:35:11 -08007986 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307987 status = eHAL_STATUS_FAILURE;
krunal soni587bf012014-02-04 12:35:11 -08007988 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307989 else
krunal soni587bf012014-02-04 12:35:11 -08007990 {
7991 status = csrRoamCopyProfile(pMac, pScanCmd->u.scanCmd.pToRoamProfile, pProfile);
7992 }
Kapil Guptac46b7542016-10-25 13:03:20 +05307993 context = vos_mem_malloc(sizeof(*context));
7994 if (NULL == context)
7995 {
7996 smsLog(pMac, LOGE,
7997 "Failed to allocate memory for ssid scan context");
7998 status = eHAL_STATUS_FAILED_ALLOC;
7999 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008000 if(!HAL_STATUS_SUCCESS(status))
8001 break;
Kapil Guptac46b7542016-10-25 13:03:20 +05308002 context->pMac = pMac;
8003 context->sessionId = sessionId;
8004 context->roamId = roamId;
Jeff Johnson295189b2012-06-20 16:38:30 -07008005 pScanCmd->u.scanCmd.roamId = roamId;
8006 pScanCmd->command = eSmeCommandScan;
Jeff Johnsone7245742012-09-05 17:12:55 -07008007 pScanCmd->sessionId = (tANI_U8)sessionId;
Kapil Guptac46b7542016-10-25 13:03:20 +05308008 pScanCmd->u.scanCmd.callback = csr_ssid_scan_done_callback;
8009 pScanCmd->u.scanCmd.pContext = context;
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008010 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 -07008011 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Kiet Lam64c1b492013-07-12 13:56:44 +05308012 vos_mem_set(&pScanCmd->u.scanCmd.u.scanRequest, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008013 pScanCmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Jeff Johnson295189b2012-06-20 16:38:30 -07008014 pScanCmd->u.scanCmd.u.scanRequest.BSSType = pProfile->BSSType;
Jeff Johnsone7245742012-09-05 17:12:55 -07008015 // To avoid 11b rate in probe request Set p2pSearch flag as 1 for P2P Client Mode
8016 if(VOS_P2P_CLIENT_MODE == pProfile->csrPersona)
8017 {
8018 pScanCmd->u.scanCmd.u.scanRequest.p2pSearch = 1;
8019 }
Agarwal Ashish4f616132013-12-30 23:32:50 +05308020 if(pProfile->nAddIEScanLength)
Jeff Johnsone7245742012-09-05 17:12:55 -07008021 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308022 pScanCmd->u.scanCmd.u.scanRequest.pIEField = vos_mem_malloc(
8023 pProfile->nAddIEScanLength);
8024 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.pIEField )
8025 status = eHAL_STATUS_FAILURE;
8026 else
8027 status = eHAL_STATUS_SUCCESS;
8028 vos_mem_set(pScanCmd->u.scanCmd.u.scanRequest.pIEField,
8029 pProfile->nAddIEScanLength, 0);
8030 if (HAL_STATUS_SUCCESS(status))
Jeff Johnsone7245742012-09-05 17:12:55 -07008031 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308032 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.pIEField,
Agarwal Ashish4f616132013-12-30 23:32:50 +05308033 pProfile->addIEScan, pProfile->nAddIEScanLength);
Jeff Johnsone7245742012-09-05 17:12:55 -07008034 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = pProfile->nAddIEScanLength;
8035 }
8036 else
8037 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008038 smsLog(pMac, LOGE, "No memory for scanning IE fields");
Jeff Johnsone7245742012-09-05 17:12:55 -07008039 }
8040 } //Allocate memory for IE field
8041 else
8042 {
8043 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = 0;
8044 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07008045 /* For one channel be good enpugh time to receive beacon atleast */
8046 if( 1 == pProfile->ChannelInfo.numOfChannels )
8047 {
Selvaraj, Sridhar32417ed2016-06-22 15:19:12 +05308048 csr_scan_request_set_chan_time(pMac, pScanCmd);
8049 } else {
Kiet Lam64c1b492013-07-12 13:56:44 +05308050 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime =
8051 pMac->roam.configParam.nActiveMaxChnTime;
8052 pScanCmd->u.scanCmd.u.scanRequest.minChnTime =
8053 pMac->roam.configParam.nActiveMinChnTime;
Jeff Johnson32d95a32012-09-10 13:15:23 -07008054 }
Abhishek Singhadd13582016-09-29 17:00:03 +05308055 pScanCmd->u.scanCmd.u.scanRequest.max_chntime_btc_esco =
8056 pMac->roam.configParam.max_chntime_btc_esco;
8057 pScanCmd->u.scanCmd.u.scanRequest.min_chntime_btc_esco =
8058 pMac->roam.configParam.min_chntime_btc_esco;
Jeff Johnson295189b2012-06-20 16:38:30 -07008059 if(pProfile->BSSIDs.numOfBSSIDs == 1)
8060 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308061 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.bssid,
8062 pProfile->BSSIDs.bssid, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07008063 }
8064 else
8065 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308066 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.bssid, bAddr, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07008067 }
8068 if(pProfile->ChannelInfo.numOfChannels)
8069 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308070 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(
8071 sizeof(*pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
8072 * pProfile->ChannelInfo.numOfChannels);
8073 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
8074 status = eHAL_STATUS_FAILURE;
8075 else
8076 status = eHAL_STATUS_SUCCESS;
8077 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
8078 if(HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07008079 {
8080 csrRoamIsChannelValid(pMac, pProfile->ChannelInfo.ChannelList[0]);
8081 for(index = 0; index < pProfile->ChannelInfo.numOfChannels; index++)
8082 {
8083 if(csrRoamIsValidChannel(pMac, pProfile->ChannelInfo.ChannelList[index]))
8084 {
8085 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels]
8086 = pProfile->ChannelInfo.ChannelList[index];
8087 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels++;
8088 }
8089 else
8090 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008091 smsLog(pMac, LOGW, FL("process a channel (%d) that is invalid"), pProfile->ChannelInfo.ChannelList[index]);
Jeff Johnson295189b2012-06-20 16:38:30 -07008092 }
8093
8094 }
8095 }
8096 else
8097 {
8098 break;
8099 }
8100
8101 }
8102 else
8103 {
8104 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
8105 }
8106 if(pProfile->SSIDs.numOfSSIDs)
8107 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308108 pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList = vos_mem_malloc(
8109 pProfile->SSIDs.numOfSSIDs * sizeof(tCsrSSIDInfo));
8110 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList )
8111 status = eHAL_STATUS_FAILURE;
8112 else
8113 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07008114 if(!HAL_STATUS_SUCCESS(status))
8115 {
8116 break;
8117 }
8118 pScanCmd->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 1;
Kiet Lam64c1b492013-07-12 13:56:44 +05308119 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList,
8120 pProfile->SSIDs.SSIDList, sizeof(tCsrSSIDInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07008121 }
8122 //Start process the command
8123 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
8124 if( !HAL_STATUS_SUCCESS( status ) )
8125 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008126 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07008127 break;
8128 }
8129 }while(0);
8130 if(!HAL_STATUS_SUCCESS(status))
8131 {
8132 if(pScanCmd)
8133 {
8134 csrReleaseCommandScan(pMac, pScanCmd);
8135 //TODO:free the memory that is allocated in this function
8136 }
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008137 if(notify)
8138 {
Jeff Johnson295189b2012-06-20 16:38:30 -07008139 csrRoamCallCallback(pMac, sessionId, NULL, roamId, eCSR_ROAM_FAILED, eCSR_ROAM_RESULT_FAILURE);
8140 }
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008141 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008142 }//valid
8143 else
8144 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008145 smsLog(pMac, LOGE, FL("cannot scan because scanEnable (%d) or numSSID (%d) is invalid"),
Jeff Johnson295189b2012-06-20 16:38:30 -07008146 pMac->scan.fScanEnable, pProfile->SSIDs.numOfSSIDs);
8147 }
8148
8149 return (status);
8150}
8151
8152
8153//Issue a scan base on the new capability infomation
8154//This should only happen when the associated AP changes its capability.
8155//After this scan is done, CSR reroams base on the new scan results
8156eHalStatus csrScanForCapabilityChange(tpAniSirGlobal pMac, tSirSmeApNewCaps *pNewCaps)
8157{
8158 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
8159 tSmeCmd *pScanCmd = NULL;
8160
8161 if(pNewCaps)
8162 {
8163 do
8164 {
8165 pScanCmd = csrGetCommandBuffer(pMac);
8166 if(!pScanCmd)
8167 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008168 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07008169 status = eHAL_STATUS_RESOURCES;
8170 break;
8171 }
Kiet Lam64c1b492013-07-12 13:56:44 +05308172 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008173 status = eHAL_STATUS_SUCCESS;
8174 pScanCmd->u.scanCmd.roamId = 0;
8175 pScanCmd->command = eSmeCommandScan;
8176 pScanCmd->u.scanCmd.callback = NULL;
8177 pScanCmd->u.scanCmd.pContext = NULL;
8178 pScanCmd->u.scanCmd.reason = eCsrScanForCapsChange;
8179 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
8180 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
8181 if( !HAL_STATUS_SUCCESS( status ) )
8182 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008183 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07008184 break;
8185 }
8186 }while(0);
8187 if(!HAL_STATUS_SUCCESS(status))
8188 {
8189 if(pScanCmd)
8190 {
8191 csrReleaseCommandScan(pMac, pScanCmd);
8192 }
8193 }
8194 }
8195
8196 return (status);
8197}
8198
8199
8200
8201void csrInitBGScanChannelList(tpAniSirGlobal pMac)
8202{
8203 tANI_U32 len = CSR_MIN(sizeof(pMac->roam.validChannelList), sizeof(pMac->scan.bgScanChannelList));
8204
Kiet Lam64c1b492013-07-12 13:56:44 +05308205 vos_mem_set(pMac->scan.bgScanChannelList, len, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008206 pMac->scan.numBGScanChannel = 0;
8207
8208 if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
8209 {
8210 pMac->roam.numValidChannels = len;
8211 pMac->scan.numBGScanChannel = (tANI_U8)CSR_MIN(len, WNI_CFG_BG_SCAN_CHANNEL_LIST_LEN);
Kiet Lam64c1b492013-07-12 13:56:44 +05308212 vos_mem_copy(pMac->scan.bgScanChannelList, pMac->roam.validChannelList,
8213 pMac->scan.numBGScanChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07008214 csrSetBGScanChannelList(pMac, pMac->scan.bgScanChannelList, pMac->scan.numBGScanChannel);
8215 }
8216}
8217
8218
8219//This function return TRUE if background scan channel list is adjusted.
8220//this function will only shrink the background scan channel list
8221tANI_BOOLEAN csrAdjustBGScanChannelList(tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels,
8222 tANI_U8 *pAdjustChannels, tANI_U8 *pNumAdjustChannels)
8223{
8224 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
8225 tANI_U8 i, j, count = *pNumAdjustChannels;
8226
8227 i = 0;
8228 while(i < count)
8229 {
8230 for(j = 0; j < NumChannels; j++)
8231 {
8232 if(pChannelList[j] == pAdjustChannels[i])
8233 break;
8234 }
8235 if(j == NumChannels)
8236 {
8237 //This channel is not in the list, remove it
8238 fRet = eANI_BOOLEAN_TRUE;
8239 count--;
8240 if(count - i)
8241 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308242 vos_mem_copy(&pAdjustChannels[i], &pAdjustChannels[i+1], count - i);
Jeff Johnson295189b2012-06-20 16:38:30 -07008243 }
8244 else
8245 {
8246 //already remove the last one. Done.
8247 break;
8248 }
8249 }
8250 else
8251 {
8252 i++;
8253 }
8254 }//while(i<count)
8255 *pNumAdjustChannels = count;
8256
8257 return (fRet);
8258}
8259
8260
8261//Get the list of the base channels to scan for passively 11d info
8262eHalStatus csrScanGetSupportedChannels( tpAniSirGlobal pMac )
8263{
8264 eHalStatus status = eHAL_STATUS_SUCCESS;
8265 int n = WNI_CFG_VALID_CHANNEL_LIST_LEN;
8266
8267 status = vos_nv_getSupportedChannels( pMac->scan.baseChannels.channelList, &n, NULL, NULL );
8268 if( HAL_STATUS_SUCCESS(status) )
8269 {
8270 pMac->scan.baseChannels.numChannels = (tANI_U8)n;
8271 }
8272 else
8273 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008274 smsLog( pMac, LOGE, FL(" failed") );
Jeff Johnson295189b2012-06-20 16:38:30 -07008275 pMac->scan.baseChannels.numChannels = 0;
8276 }
8277
8278 return ( status );
8279}
8280
8281//This function use the input pChannelList to validate the current saved channel list
8282eHalStatus csrSetBGScanChannelList( tpAniSirGlobal pMac, tANI_U8 *pAdjustChannels, tANI_U8 NumAdjustChannels)
8283{
8284 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumAdjustChannels;
8285
8286 return (ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pAdjustChannels, dataLen, NULL, eANI_BOOLEAN_FALSE));
8287}
8288
8289
8290void csrSetCfgValidChannelList( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels )
8291{
8292 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumChannels;
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05308293 eHalStatus status;
Jeff Johnson295189b2012-06-20 16:38:30 -07008294
Mihir Shete31c435d2014-02-12 13:13:34 +05308295 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
8296 "%s: dump valid channel list(NumChannels(%d))",
8297 __func__,NumChannels);
8298 VOS_TRACE_HEX_DUMP(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
8299 pChannelList, NumChannels);
8300
Jeff Johnson295189b2012-06-20 16:38:30 -07008301 ccmCfgSetStr(pMac, WNI_CFG_VALID_CHANNEL_LIST, pChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
Leela Venkata Kiran Kumar Reddy Chiralac6663f72014-02-03 21:04:58 -08008302#ifdef QCA_WIFI_2_0
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05308303 if (pMac->fScanOffload)
8304 {
8305 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
8306 "Scan offload is enabled, update default chan list");
Leela Venkata Kiran Kumar Reddy Chiralac6663f72014-02-03 21:04:58 -08008307 status = csrUpdateChannelList(pMac);
8308 }
8309#else
8310 status = csrUpdateChannelList(pMac);
8311#endif
8312
8313 if (eHAL_STATUS_SUCCESS != status)
8314 {
8315 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR,
8316 "failed to update the supported channel list");
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05308317 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008318 return;
8319}
8320
8321
8322
8323/*
8324 * The Tx power limits are saved in the cfg for future usage.
8325 */
8326void csrSaveTxPowerToCfg( tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 cfgId )
8327{
8328 tListElem *pEntry;
8329 tANI_U32 cbLen = 0, dataLen;
8330 tCsrChannelPowerInfo *pChannelSet;
8331 tANI_U32 idx;
8332 tSirMacChanInfo *pChannelPowerSet;
8333 tANI_U8 *pBuf = NULL;
8334
8335 //allocate maximum space for all channels
8336 dataLen = WNI_CFG_VALID_CHANNEL_LIST_LEN * sizeof(tSirMacChanInfo);
Kiet Lam64c1b492013-07-12 13:56:44 +05308337 if ( (pBuf = vos_mem_malloc(dataLen)) != NULL )
Jeff Johnson295189b2012-06-20 16:38:30 -07008338 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308339 vos_mem_set(pBuf, dataLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008340 pChannelPowerSet = (tSirMacChanInfo *)(pBuf);
8341
8342 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
8343 // write the tuples (startChan, numChan, txPower) for each channel found in the channel power list.
8344 while( pEntry )
8345 {
8346 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
8347 if ( 1 != pChannelSet->interChannelOffset )
8348 {
8349 // we keep the 5G channel sets internally with an interchannel offset of 4. Expand these
8350 // to the right format... (inter channel offset of 1 is the only option for the triplets
8351 // that 11d advertises.
8352 if ((cbLen + (pChannelSet->numChannels * sizeof(tSirMacChanInfo))) >= dataLen)
8353 {
8354 // expanding this entry will overflow our allocation
8355 smsLog(pMac, LOGE,
8356 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07008357 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07008358 pChannelSet->firstChannel,
8359 pChannelSet->numChannels,
8360 pChannelSet->interChannelOffset);
8361 break;
8362 }
8363
8364 for( idx = 0; idx < pChannelSet->numChannels; idx++ )
8365 {
8366 pChannelPowerSet->firstChanNum = (tSirMacChanNum)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008367 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07008368 pChannelPowerSet->numChannels = 1;
Jeff Johnson295189b2012-06-20 16:38:30 -07008369 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008370 smsLog(pMac, LOG3, " Setting Max Transmit Power %d", pChannelPowerSet->maxTxPower);
Jeff Johnson295189b2012-06-20 16:38:30 -07008371 cbLen += sizeof( tSirMacChanInfo );
8372 pChannelPowerSet++;
8373 }
8374 }
8375 else
8376 {
8377 if (cbLen >= dataLen)
8378 {
8379 // this entry will overflow our allocation
8380 smsLog(pMac, LOGE,
8381 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07008382 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07008383 pChannelSet->firstChannel,
8384 pChannelSet->numChannels,
8385 pChannelSet->interChannelOffset);
8386 break;
8387 }
8388 pChannelPowerSet->firstChanNum = pChannelSet->firstChannel;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008389 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07008390 pChannelPowerSet->numChannels = pChannelSet->numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -07008391 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008392 smsLog(pMac, LOG3, " Setting Max Transmit Power %d, nTxPower %d", pChannelPowerSet->maxTxPower,pMac->roam.configParam.nTxPowerCap );
Jeff Johnson295189b2012-06-20 16:38:30 -07008393
8394
8395 cbLen += sizeof( tSirMacChanInfo );
8396 pChannelPowerSet++;
8397 }
8398
8399 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
8400 }
8401
8402 if(cbLen)
8403 {
8404 ccmCfgSetStr(pMac, cfgId, (tANI_U8 *)pBuf, cbLen, NULL, eANI_BOOLEAN_FALSE);
8405 }
Kiet Lam64c1b492013-07-12 13:56:44 +05308406 vos_mem_free(pBuf);
Jeff Johnson295189b2012-06-20 16:38:30 -07008407 }//Allocate memory
8408}
8409
8410
8411void csrSetCfgCountryCode( tpAniSirGlobal pMac, tANI_U8 *countryCode )
8412{
8413 tANI_U8 cc[WNI_CFG_COUNTRY_CODE_LEN];
8414 ///v_REGDOMAIN_t DomainId;
8415
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008416 smsLog( pMac, LOG3, "Setting Country Code in Cfg from csrSetCfgCountryCode %s",countryCode );
Kiet Lam64c1b492013-07-12 13:56:44 +05308417 vos_mem_copy(cc, countryCode, WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07008418
8419 // don't program the bogus country codes that we created for Korea in the MAC. if we see
8420 // the bogus country codes, program the MAC with the right country code.
8421 if ( ( 'K' == countryCode[ 0 ] && '1' == countryCode[ 1 ] ) ||
8422 ( 'K' == countryCode[ 0 ] && '2' == countryCode[ 1 ] ) ||
8423 ( 'K' == countryCode[ 0 ] && '3' == countryCode[ 1 ] ) ||
8424 ( 'K' == countryCode[ 0 ] && '4' == countryCode[ 1 ] ) )
8425 {
8426 // replace the alternate Korea country codes, 'K1', 'K2', .. with 'KR' for Korea
8427 cc[ 1 ] = 'R';
8428 }
8429 ccmCfgSetStr(pMac, WNI_CFG_COUNTRY_CODE, cc, WNI_CFG_COUNTRY_CODE_LEN, NULL, eANI_BOOLEAN_FALSE);
8430
8431 //Need to let HALPHY know about the current domain so it can apply some
8432 //domain-specific settings (TX filter...)
8433 /*if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(pMac, cc, &DomainId)))
8434 {
8435 halPhySetRegDomain(pMac, DomainId);
8436 }*/
8437}
8438
8439
8440
8441eHalStatus csrGetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pBuf, tANI_U8 *pbLen)
8442{
8443 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
8444 tANI_U32 len;
8445
8446 if(pBuf && pbLen && (*pbLen >= WNI_CFG_COUNTRY_CODE_LEN))
8447 {
8448 len = *pbLen;
8449 status = ccmCfgGetStr(pMac, WNI_CFG_COUNTRY_CODE, pBuf, &len);
8450 if(HAL_STATUS_SUCCESS(status))
8451 {
8452 *pbLen = (tANI_U8)len;
8453 }
8454 }
8455
8456 return (status);
8457}
8458
8459
8460void csrSetCfgScanControlList( tpAniSirGlobal pMac, tANI_U8 *countryCode, tCsrChannel *pChannelList )
8461{
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05308462 tANI_U8 i, j, k;
Jeff Johnson295189b2012-06-20 16:38:30 -07008463 tANI_BOOLEAN found=FALSE;
8464 tANI_U8 *pControlList = NULL;
8465 tANI_U32 len = WNI_CFG_SCAN_CONTROL_LIST_LEN;
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05308466 tANI_U8 cfgActiveDFSChannels = 0;
8467 tANI_U8 *cfgActiveDFSChannelLIst = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07008468
Kiet Lam64c1b492013-07-12 13:56:44 +05308469 if ( (pControlList = vos_mem_malloc(WNI_CFG_SCAN_CONTROL_LIST_LEN)) != NULL )
Jeff Johnson295189b2012-06-20 16:38:30 -07008470 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308471 vos_mem_set((void *)pControlList, WNI_CFG_SCAN_CONTROL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008472 if(HAL_STATUS_SUCCESS(ccmCfgGetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, &len)))
8473 {
8474 for (i = 0; i < pChannelList->numChannels; i++)
8475 {
8476 for (j = 0; j < len; j += 2)
8477 {
8478 if (pControlList[j] == pChannelList->channelList[i])
8479 {
8480 found = TRUE;
8481 break;
8482 }
8483 }
8484
8485 if (found) // insert a pair(channel#, flag)
8486 {
Gopichand Nakkala392cbc12013-05-28 16:15:00 +05308487 pControlList[j+1] = csrGetScanType(pMac, pControlList[j]);
Jeff Johnson295189b2012-06-20 16:38:30 -07008488 found = FALSE; // reset the flag
Jeff Johnson295189b2012-06-20 16:38:30 -07008489
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05308490 // When DFS mode is 2, mark static channels as active
8491 if (pMac->scan.fEnableDFSChnlScan ==
8492 DFS_CHNL_SCAN_ENABLED_ACTIVE)
8493 {
8494 cfgActiveDFSChannels =
8495 pMac->roam.neighborRoamInfo.cfgParams.
8496 channelInfo.numOfChannels;
8497 cfgActiveDFSChannelLIst =
8498 pMac->roam.neighborRoamInfo.cfgParams.
8499 channelInfo.ChannelList;
8500 if (cfgActiveDFSChannelLIst)
8501 {
8502 for (k=0; k < cfgActiveDFSChannels; k++)
8503 {
8504 if(CSR_IS_CHANNEL_DFS(cfgActiveDFSChannelLIst[k])
8505 && (pControlList[j] ==
8506 cfgActiveDFSChannelLIst[k]))
8507 {
8508 pControlList[j+1] = eSIR_ACTIVE_SCAN;
8509 smsLog(pMac, LOG1, FL("Marked DFS ch %d"
8510 " as active"),
8511 cfgActiveDFSChannelLIst[k]);
8512 }
8513 }
8514 }
8515 }
8516 }
8517 }
8518
8519 smsLog(pMac, LOG1, FL("fEnableDFSChnlScan %d"),
8520 pMac->scan.fEnableDFSChnlScan);
Mihir Shete31c435d2014-02-12 13:13:34 +05308521 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
8522 "%s: dump scan control list",__func__);
8523 VOS_TRACE_HEX_DUMP(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
8524 pControlList, len);
8525
Jeff Johnson295189b2012-06-20 16:38:30 -07008526 ccmCfgSetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, len, NULL, eANI_BOOLEAN_FALSE);
8527 }//Successfully getting scan control list
Kiet Lam64c1b492013-07-12 13:56:44 +05308528 vos_mem_free(pControlList);
Jeff Johnson295189b2012-06-20 16:38:30 -07008529 }//AllocateMemory
8530}
8531
Jeff Johnson295189b2012-06-20 16:38:30 -07008532//if bgPeriod is 0, background scan is disabled. It is in millisecond units
8533eHalStatus csrSetCfgBackgroundScanPeriod(tpAniSirGlobal pMac, tANI_U32 bgPeriod)
8534{
8535 return (ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, bgPeriod, (tCcmCfgSetCallback) csrScanCcmCfgSetCallback, eANI_BOOLEAN_FALSE));
8536}
8537
8538
8539void csrScanCcmCfgSetCallback(tHalHandle hHal, tANI_S32 result)
8540{
8541 tListElem *pEntry = NULL;
8542 tSmeCmd *pCommand = NULL;
8543 tpAniSirGlobal pMac = PMAC_STRUCT( hHal );
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05308544 tDblLinkList *pCmdList ;
8545
8546 if (!pMac->fScanOffload)
8547 pCmdList = &pMac->sme.smeCmdActiveList;
8548 else
8549 pCmdList = &pMac->sme.smeScanCmdActiveList;
8550
8551 pEntry = csrLLPeekHead( pCmdList, LL_ACCESS_LOCK );
Jeff Johnson295189b2012-06-20 16:38:30 -07008552 if ( pEntry )
8553 {
8554 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8555 if ( eSmeCommandScan == pCommand->command )
8556 {
8557 eCsrScanStatus scanStatus = (CCM_IS_RESULT_SUCCESS(result)) ? eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
8558 csrReleaseScanCommand(pMac, pCommand, scanStatus);
8559 }
8560 else
8561 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008562 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
Jeff Johnson295189b2012-06-20 16:38:30 -07008563 }
8564 }
8565 smeProcessPendingQueue( pMac );
8566}
8567
8568eHalStatus csrProcessSetBGScanParam(tpAniSirGlobal pMac, tSmeCmd *pCommand)
8569{
8570 eHalStatus status;
8571 tCsrBGScanRequest *pScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
8572 tANI_U32 dataLen = sizeof( tANI_U8 ) * pScanReq->ChannelInfo.numOfChannels;
8573
8574 //***setcfg for background scan channel list
8575 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MINIMUM_CHANNEL_TIME, pScanReq->minChnTime, NULL, eANI_BOOLEAN_FALSE);
8576 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MAXIMUM_CHANNEL_TIME, pScanReq->maxChnTime, NULL, eANI_BOOLEAN_FALSE);
8577 //Not set the background scan interval if not connected because bd scan should not be run if not connected
8578 if(!csrIsAllSessionDisconnected(pMac))
8579 {
Jeff Johnson295189b2012-06-20 16:38:30 -07008580
8581#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
8582 {
8583 vos_log_scan_pkt_type *pScanLog = NULL;
8584
8585 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
8586 if(pScanLog)
8587 {
8588 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
8589 pScanLog->minChnTime = (v_U8_t)pScanReq->minChnTime;
8590 pScanLog->maxChnTime = (v_U8_t)pScanReq->maxChnTime;
8591 pScanLog->timeBetweenBgScan = (v_U8_t)pScanReq->scanInterval;
8592 pScanLog->numChannel = pScanReq->ChannelInfo.numOfChannels;
8593 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
8594 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308595 vos_mem_copy(pScanLog->channels,
8596 pScanReq->ChannelInfo.ChannelList,
8597 pScanLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07008598 }
8599 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
8600 }
8601 }
8602#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
8603
8604 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, pScanReq->scanInterval, NULL, eANI_BOOLEAN_FALSE);
8605 }
8606 else
8607 {
8608 //No need to stop aging because IDLE scan is still running
8609 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, 0, NULL, eANI_BOOLEAN_FALSE);
8610 }
8611
8612 if(pScanReq->SSID.length > WNI_CFG_SSID_LEN)
8613 {
8614 pScanReq->SSID.length = WNI_CFG_SSID_LEN;
8615 }
8616
8617 status = ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pScanReq->ChannelInfo.ChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
8618 status = ccmCfgSetStr(pMac, WNI_CFG_SSID, (tANI_U8 *)pScanReq->SSID.ssId, pScanReq->SSID.length, NULL, eANI_BOOLEAN_FALSE);
8619
8620
8621
8622 return (status);
8623}
8624
8625
c_hpothua3d45d52015-01-05 14:11:17 +05308626tSirAbortScanStatus csrScanAbortMacScan(tpAniSirGlobal pMac,
8627 tANI_U8 sessionId,
8628 eCsrAbortReason reason)
Jeff Johnson295189b2012-06-20 16:38:30 -07008629{
c_hpothua3d45d52015-01-05 14:11:17 +05308630 tSirAbortScanStatus abortScanStatus = eSIR_ABORT_ACTIVE_SCAN_LIST_EMPTY;
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308631 tSirSmeScanAbortReq *pMsg;
Jeff Johnson295189b2012-06-20 16:38:30 -07008632 tANI_U16 msgLen;
8633 tListElem *pEntry;
8634 tSmeCmd *pCommand;
8635
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308636 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07008637 {
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308638#ifdef WLAN_AP_STA_CONCURRENCY
8639 csrLLLock(&pMac->scan.scanCmdPendingList);
8640 while(NULL !=
8641 (pEntry = csrLLRemoveHead(&pMac->scan.scanCmdPendingList,
8642 LL_ACCESS_NOLOCK)))
8643 {
Jeff Johnson295189b2012-06-20 16:38:30 -07008644
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308645 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8646 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
8647 }
8648 csrLLUnlock(&pMac->scan.scanCmdPendingList);
Jeff Johnson295189b2012-06-20 16:38:30 -07008649#endif
8650
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308651 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
8652 csrRemoveCmdFromPendingList( pMac, &pMac->roam.roamCmdPendingList, eSmeCommandScan);
8653 csrRemoveCmdFromPendingList( pMac, &pMac->sme.smeCmdPendingList, eSmeCommandScan);
8654 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
8655
8656 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
8657 }
8658 else
8659 {
8660 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
8661 csrRemoveCmdWithSessionIdFromPendingList(pMac,
8662 sessionId,
8663 &pMac->sme.smeScanCmdPendingList,
8664 eSmeCommandScan);
8665 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
8666
8667 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
8668 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008669
8670 //We need to abort scan only if we are scanning
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308671 if(NULL != pEntry)
Jeff Johnson295189b2012-06-20 16:38:30 -07008672 {
8673 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308674 if(eSmeCommandScan == pCommand->command &&
8675 pCommand->sessionId == sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07008676 {
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308677 msgLen = (tANI_U16)(sizeof(tSirSmeScanAbortReq));
Kiet Lam64c1b492013-07-12 13:56:44 +05308678 pMsg = vos_mem_malloc(msgLen);
8679 if ( NULL == pMsg )
Jeff Johnson295189b2012-06-20 16:38:30 -07008680 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308681 smsLog(pMac, LOGE, FL("Failed to allocate memory for SmeScanAbortReq"));
c_hpothua3d45d52015-01-05 14:11:17 +05308682 abortScanStatus = eSIR_ABORT_SCAN_FAILURE;
Kiet Lam64c1b492013-07-12 13:56:44 +05308683 }
8684 else
8685 {
Ratheesh S Pece1f832015-07-25 15:50:25 +05308686 pCommand->u.scanCmd.abortScanIndication = eCSR_SCAN_ABORT_DEFAULT;
Srinivas, Dasari187ca4e2014-02-07 12:40:09 +05308687 if(reason == eCSR_SCAN_ABORT_DUE_TO_BAND_CHANGE)
8688 {
Ratheesh S Pece1f832015-07-25 15:50:25 +05308689 pCommand->u.scanCmd.abortScanIndication
8690 = eCSR_SCAN_ABORT_DUE_TO_BAND_CHANGE;
Srinivas, Dasari187ca4e2014-02-07 12:40:09 +05308691 }
Kiet Lam64c1b492013-07-12 13:56:44 +05308692 vos_mem_set((void *)pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008693 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_ABORT_IND);
8694 pMsg->msgLen = pal_cpu_to_be16(msgLen);
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308695 pMsg->sessionId = sessionId;
c_hpothua3d45d52015-01-05 14:11:17 +05308696 if (eHAL_STATUS_SUCCESS != palSendMBMessage(pMac->hHdd, pMsg))
8697 {
8698 smsLog(pMac, LOGE,
8699 FL("Failed to post eWNI_SME_SCAN_ABORT_IND"));
8700 abortScanStatus = eSIR_ABORT_SCAN_FAILURE;
Ratheesh S Pece1f832015-07-25 15:50:25 +05308701 pCommand->u.scanCmd.abortScanIndication = 0;
c_hpothua3d45d52015-01-05 14:11:17 +05308702 }
8703 else
8704 {
8705 abortScanStatus = eSIR_ABORT_ACTIVE_SCAN_LIST_NOT_EMPTY;
8706 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008707 }
8708 }
8709 }
8710
c_hpothua3d45d52015-01-05 14:11:17 +05308711 return(abortScanStatus);
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308712}
8713
8714void csrRemoveCmdWithSessionIdFromPendingList(tpAniSirGlobal pMac,
8715 tANI_U8 sessionId,
8716 tDblLinkList *pList,
8717 eSmeCommandType commandType)
8718{
8719 tDblLinkList localList;
8720 tListElem *pEntry;
8721 tSmeCmd *pCommand;
8722 tListElem *pEntryToRemove;
8723
8724 vos_mem_zero(&localList, sizeof(tDblLinkList));
8725 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
8726 {
8727 smsLog(pMac, LOGE, FL(" failed to open list"));
8728 return;
8729 }
8730
8731 csrLLLock(pList);
8732 if ((pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK)))
8733 {
8734
8735 /* Have to make sure we don't loop back to the head of the list,
8736 * which will happen if the entry is NOT on the list */
8737 while (pEntry)
8738 {
8739 pEntryToRemove = pEntry;
8740 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
8741 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
8742 if ((pCommand->command == commandType) &&
8743 (pCommand->sessionId == sessionId))
8744 {
8745 /* Remove that entry only */
8746 if (csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
8747 {
8748 csrLLInsertTail(&localList, pEntryToRemove,
8749 LL_ACCESS_NOLOCK);
8750 }
8751 }
8752 }
8753 }
8754 csrLLUnlock(pList);
8755
8756 while ((pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)))
8757 {
8758 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
8759 csrAbortCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
8760 }
8761
8762 csrLLClose(&localList);
Jeff Johnson295189b2012-06-20 16:38:30 -07008763}
8764
8765void csrRemoveCmdFromPendingList(tpAniSirGlobal pMac, tDblLinkList *pList,
8766 eSmeCommandType commandType )
8767{
8768 tDblLinkList localList;
8769 tListElem *pEntry;
8770 tSmeCmd *pCommand;
8771 tListElem *pEntryToRemove;
8772
8773 vos_mem_zero(&localList, sizeof(tDblLinkList));
8774 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
8775 {
8776 smsLog(pMac, LOGE, FL(" failed to open list"));
8777 return;
8778 }
8779
8780 csrLLLock(pList);
8781 if( !csrLLIsListEmpty( pList, LL_ACCESS_NOLOCK ) )
8782 {
8783 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK);
8784
8785 // Have to make sure we don't loop back to the head of the list, which will
8786 // happen if the entry is NOT on the list...
8787 while( pEntry )
8788 {
8789 pEntryToRemove = pEntry;
8790 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
8791 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
8792 if ( pCommand->command == commandType )
8793 {
8794 // Remove that entry only
8795 if(csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
8796 {
8797 csrLLInsertTail(&localList, pEntryToRemove, LL_ACCESS_NOLOCK);
8798 }
8799 }
8800 }
8801
8802
8803 }
8804 csrLLUnlock(pList);
8805
8806 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
8807 {
8808 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8809 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
8810 }
8811 csrLLClose(&localList);
8812
8813}
8814
Abhishek Singhdc2bfd42014-06-19 17:59:05 +05308815eHalStatus csrScanAbortScanForSSID(tpAniSirGlobal pMac, tANI_U32 sessionId)
8816{
8817 eHalStatus status = eHAL_STATUS_SUCCESS;
8818 tSirSmeScanAbortReq *pMsg;
8819 tANI_U16 msgLen;
8820 tListElem *pEntry;
8821 tSmeCmd *pCommand;
8822
8823 if (!pMac->fScanOffload)
8824 {
8825 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
8826#ifdef WLAN_AP_STA_CONCURRENCY
8827 csrRemoveScanForSSIDFromPendingList( pMac, &pMac->scan.scanCmdPendingList, sessionId);
8828#endif
8829 csrRemoveScanForSSIDFromPendingList( pMac, &pMac->roam.roamCmdPendingList, sessionId);
8830 csrRemoveScanForSSIDFromPendingList( pMac, &pMac->sme.smeCmdPendingList, sessionId);
8831 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
8832 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
8833 }
8834 else
8835 {
8836 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
8837 csrRemoveScanForSSIDFromPendingList( pMac, &pMac->sme.smeScanCmdPendingList, sessionId);
8838 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
8839 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
8840 }
8841
8842 if(NULL != pEntry)
8843 {
8844 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8845
8846 if ( (eSmeCommandScan == pCommand->command ) &&
8847 (sessionId == pCommand->sessionId))
8848 {
8849 if ( eCsrScanForSsid == pCommand->u.scanCmd.reason)
8850 {
8851 msgLen = (tANI_U16)(sizeof( tSirSmeScanAbortReq ));
8852 pMsg = vos_mem_malloc(msgLen);
8853 if ( NULL == pMsg )
8854 {
8855 status = eHAL_STATUS_FAILURE;
8856 smsLog(pMac, LOGE, FL("Failed to allocate memory for SmeScanAbortReq"));
8857 }
8858 else
8859 {
8860 vos_mem_zero((void *)pMsg, msgLen);
8861 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_ABORT_IND);
8862 pMsg->msgLen = pal_cpu_to_be16(msgLen);
8863 pMsg->sessionId = sessionId;
8864 status = palSendMBMessage(pMac->hHdd, pMsg);
8865 }
8866 }
8867 }
8868 }
8869 return( status );
8870}
8871
8872void csrRemoveScanForSSIDFromPendingList(tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 sessionId)
8873{
8874 tDblLinkList localList;
8875 tListElem *pEntry;
8876 tSmeCmd *pCommand;
8877 tListElem *pEntryToRemove;
8878
8879 vos_mem_zero(&localList, sizeof(tDblLinkList));
8880 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
8881 {
8882 smsLog(pMac, LOGE, FL(" failed to open list"));
8883 return;
8884 }
8885
8886 csrLLLock(pList);
8887 if( !csrLLIsListEmpty( pList, LL_ACCESS_NOLOCK ) )
8888 {
8889 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK);
8890
8891 // Have to make sure we don't loop back to the head of the list, which will
8892 // happen if the entry is NOT on the list...
8893 while( pEntry )
8894 {
8895 pEntryToRemove = pEntry;
8896 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
8897 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
8898 if ( (eSmeCommandScan == pCommand->command ) &&
8899 (sessionId == pCommand->sessionId) )
8900 {
8901 if ( eCsrScanForSsid == pCommand->u.scanCmd.reason)
8902 {
8903 // Remove that entry only
8904 if ( csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
8905 {
8906 csrLLInsertTail(&localList, pEntryToRemove, LL_ACCESS_NOLOCK);
8907 }
8908 }
8909 }
8910 }
8911 }
8912 csrLLUnlock(pList);
8913
8914 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
8915 {
8916 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8917 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
8918 }
8919 csrLLClose(&localList);
8920}
Jeff Johnson295189b2012-06-20 16:38:30 -07008921
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308922eHalStatus csrScanAbortMacScanNotForConnect(tpAniSirGlobal pMac,
8923 tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07008924{
8925 eHalStatus status = eHAL_STATUS_SUCCESS;
8926
8927 if( !csrIsScanForRoamCommandActive( pMac ) )
8928 {
8929 //Only abort the scan if it is not used for other roam/connect purpose
c_hpothua3d45d52015-01-05 14:11:17 +05308930 if (eSIR_ABORT_SCAN_FAILURE ==
8931 csrScanAbortMacScan(pMac, sessionId, eCSR_SCAN_ABORT_DEFAULT))
8932 {
8933 smsLog(pMac, LOGE, FL("fail to abort scan"));
8934 status = eHAL_STATUS_FAILURE;
8935 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008936 }
8937
8938 return (status);
8939}
8940
8941
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05308942eHalStatus csrScanGetScanChannelInfo(tpAniSirGlobal pMac, tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07008943{
8944 eHalStatus status = eHAL_STATUS_SUCCESS;
8945 tSirMbMsg *pMsg;
8946 tANI_U16 msgLen;
8947
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05308948 if (pMac->fScanOffload)
8949 msgLen = (tANI_U16)(sizeof(tSirSmeGetScanChanReq));
8950 else
8951 msgLen = (tANI_U16)(sizeof(tSirMbMsg));
8952
Kiet Lam64c1b492013-07-12 13:56:44 +05308953 pMsg = vos_mem_malloc(msgLen);
8954 if ( NULL == pMsg )
8955 status = eHAL_STATUS_FAILURE;
8956 else
Jeff Johnson295189b2012-06-20 16:38:30 -07008957 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308958 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008959 pMsg->type = eWNI_SME_GET_SCANNED_CHANNEL_REQ;
8960 pMsg->msgLen = msgLen;
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05308961 if (pMac->fScanOffload)
8962 ((tSirSmeGetScanChanReq *)pMsg)->sessionId = sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07008963 status = palSendMBMessage(pMac->hHdd, pMsg);
8964 }
8965
8966 return( status );
8967}
8968
8969tANI_BOOLEAN csrRoamIsValidChannel( tpAniSirGlobal pMac, tANI_U8 channel )
8970{
8971 tANI_BOOLEAN fValid = FALSE;
8972 tANI_U32 idxValidChannels;
8973 tANI_U32 len = pMac->roam.numValidChannels;
8974
8975 for ( idxValidChannels = 0; ( idxValidChannels < len ); idxValidChannels++ )
8976 {
8977 if ( channel == pMac->roam.validChannelList[ idxValidChannels ] )
8978 {
8979 fValid = TRUE;
8980 break;
8981 }
8982 }
8983
8984 return fValid;
8985}
8986
Manjunathappa Prakash4f1d5a52013-11-11 16:22:19 -08008987#ifdef FEATURE_WLAN_SCAN_PNO
Srikant Kuppa066904f2013-05-07 13:56:02 -07008988eHalStatus csrScanSavePreferredNetworkFound(tpAniSirGlobal pMac,
8989 tSirPrefNetworkFoundInd *pPrefNetworkFoundInd)
8990{
8991 v_U32_t uLen = 0;
8992 tpSirProbeRespBeacon pParsedFrame;
8993 tCsrScanResult *pScanResult = NULL;
8994 tSirBssDescription *pBssDescr = NULL;
8995 tANI_BOOLEAN fDupBss;
8996 tDot11fBeaconIEs *pIesLocal = NULL;
8997 tAniSSID tmpSsid;
8998 v_TIME_t timer=0;
8999 tpSirMacMgmtHdr macHeader = (tpSirMacMgmtHdr)pPrefNetworkFoundInd->data;
Abhishek Singhd3d4e022014-11-11 13:02:40 +05309000 boolean bFoundonAppliedChannel = FALSE;
9001 v_U32_t indx;
9002 u8 channelsAllowed[WNI_CFG_VALID_CHANNEL_LIST_LEN];
9003 v_U32_t numChannelsAllowed = WNI_CFG_VALID_CHANNEL_LIST_LEN;
Sushant Kaushik6274de62015-05-01 16:31:23 +05309004 tListElem *pEntry;
Abhishek Singhd3d4e022014-11-11 13:02:40 +05309005
Srikant Kuppa066904f2013-05-07 13:56:02 -07009006
9007 pParsedFrame =
Abhishek Singhc75726d2015-04-13 14:44:14 +05309008 (tpSirProbeRespBeacon)vos_mem_vmalloc(sizeof(tSirProbeRespBeacon));
Srikant Kuppa066904f2013-05-07 13:56:02 -07009009
9010 if (NULL == pParsedFrame)
9011 {
9012 smsLog(pMac, LOGE, FL(" fail to allocate memory for frame"));
9013 return eHAL_STATUS_RESOURCES;
9014 }
9015
9016 if ( pPrefNetworkFoundInd->frameLength <= SIR_MAC_HDR_LEN_3A )
9017 {
9018 smsLog(pMac, LOGE,
9019 FL("Not enough bytes in PNO indication probe resp frame! length=%d"),
9020 pPrefNetworkFoundInd->frameLength);
Abhishek Singhc75726d2015-04-13 14:44:14 +05309021 vos_mem_vfree(pParsedFrame);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009022 return eHAL_STATUS_FAILURE;
9023 }
9024
9025 if (sirConvertProbeFrame2Struct(pMac,
9026 &pPrefNetworkFoundInd->data[SIR_MAC_HDR_LEN_3A],
9027 pPrefNetworkFoundInd->frameLength - SIR_MAC_HDR_LEN_3A,
9028 pParsedFrame) != eSIR_SUCCESS ||
9029 !pParsedFrame->ssidPresent)
9030 {
9031 smsLog(pMac, LOGE,
9032 FL("Parse error ProbeResponse, length=%d"),
9033 pPrefNetworkFoundInd->frameLength);
Abhishek Singhc75726d2015-04-13 14:44:14 +05309034 vos_mem_vfree(pParsedFrame);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009035 return eHAL_STATUS_FAILURE;
9036 }
9037 //24 byte MAC header and 12 byte to ssid IE
9038 if (pPrefNetworkFoundInd->frameLength >
9039 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET))
9040 {
9041 uLen = pPrefNetworkFoundInd->frameLength -
9042 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET);
9043 }
9044
Kiet Lam64c1b492013-07-12 13:56:44 +05309045 pScanResult = vos_mem_malloc(sizeof(tCsrScanResult) + uLen);
9046 if ( NULL == pScanResult )
Srikant Kuppa066904f2013-05-07 13:56:02 -07009047 {
9048 smsLog(pMac, LOGE, FL(" fail to allocate memory for frame"));
9049 vos_mem_free(pParsedFrame);
9050 return eHAL_STATUS_RESOURCES;
9051 }
9052
Kiet Lam64c1b492013-07-12 13:56:44 +05309053 vos_mem_set(pScanResult, sizeof(tCsrScanResult) + uLen, 0);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009054 pBssDescr = &pScanResult->Result.BssDescriptor;
9055 /**
9056 * Length of BSS desription is without length of
9057 * length itself and length of pointer
9058 * that holds the next BSS description
9059 */
9060 pBssDescr->length = (tANI_U16)(
Abhishek Singhbad2b322016-10-21 11:22:33 +05309061 ((uintptr_t)OFFSET_OF(tSirBssDescription, ieFields))
9062 - sizeof(pBssDescr->length) + uLen);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009063 if (pParsedFrame->dsParamsPresent)
9064 {
9065 pBssDescr->channelId = pParsedFrame->channelNumber;
9066 }
9067 else if (pParsedFrame->HTInfo.present)
9068 {
9069 pBssDescr->channelId = pParsedFrame->HTInfo.primaryChannel;
9070 }
9071 else
9072 {
Mahesh A Saptasagaradd99792014-03-26 16:04:20 +05309073 /**
9074 * If Probe Responce received in PNO indication does not
9075 * contain DSParam IE or HT Info IE then add dummy channel
9076 * to the received BSS info so that Scan result received as
9077 * a part of PNO is updated to the supplicant. Specially
9078 * applicable in case of AP configured in 11A only mode.
9079 */
9080 if ((pMac->roam.configParam.bandCapability == eCSR_BAND_ALL) ||
9081 (pMac->roam.configParam.bandCapability == eCSR_BAND_24))
9082 {
9083 pBssDescr->channelId = 1;
9084 }
9085 else if(pMac->roam.configParam.bandCapability == eCSR_BAND_5G)
9086 {
9087 pBssDescr->channelId = 36;
9088 }
Abhishek Singhd3d4e022014-11-11 13:02:40 +05309089 /* Restrict the logic to ignore the pno indication for invalid channel
9090 * only if valid channel info is present in beacon/probe resp.
9091 * If no channel info is present in beacon/probe resp, always process
9092 * the pno indication.
9093 */
9094 bFoundonAppliedChannel = TRUE;
9095 }
9096
9097 if (0 != sme_GetCfgValidChannels(pMac, channelsAllowed, &numChannelsAllowed))
9098 {
9099 smsLog(pMac, LOGE, FL(" sme_GetCfgValidChannels failed "));
9100 csrFreeScanResultEntry(pMac, pScanResult);
Abhishek Singhc75726d2015-04-13 14:44:14 +05309101 vos_mem_vfree(pParsedFrame);
Abhishek Singhd3d4e022014-11-11 13:02:40 +05309102 return eHAL_STATUS_FAILURE;
9103 }
9104 /* Checking chhanelId with allowed channel list */
9105 for (indx = 0; indx < numChannelsAllowed; indx++)
9106 {
9107 if (pBssDescr->channelId == channelsAllowed[indx])
9108 {
9109 bFoundonAppliedChannel = TRUE;
9110 smsLog(pMac, LOG1, FL(" pno ind found on applied channel =%d\n "),
9111 pBssDescr->channelId);
9112 break;
9113 }
9114 }
9115 /* Ignore PNO indication if AP is on Invalid channel.
9116 */
9117 if(FALSE == bFoundonAppliedChannel)
9118 {
9119 smsLog(pMac, LOGW, FL(" prefered network found on invalid channel = %d"),
9120 pBssDescr->channelId);
9121 csrFreeScanResultEntry(pMac, pScanResult);
Abhishek Singhc75726d2015-04-13 14:44:14 +05309122 vos_mem_vfree(pParsedFrame);
Abhishek Singhd3d4e022014-11-11 13:02:40 +05309123 return eHAL_STATUS_FAILURE;
Srikant Kuppa066904f2013-05-07 13:56:02 -07009124 }
9125
9126 if ((pBssDescr->channelId > 0) && (pBssDescr->channelId < 15))
9127 {
9128 int i;
9129 // 11b or 11g packet
9130 // 11g iff extended Rate IE is present or
9131 // if there is an A rate in suppRate IE
9132 for (i = 0; i < pParsedFrame->supportedRates.numRates; i++)
9133 {
9134 if (sirIsArate(pParsedFrame->supportedRates.rate[i] & 0x7f))
9135 {
9136 pBssDescr->nwType = eSIR_11G_NW_TYPE;
9137 break;
9138 }
9139 }
9140 if (pParsedFrame->extendedRatesPresent)
9141 {
9142 pBssDescr->nwType = eSIR_11G_NW_TYPE;
9143 }
9144 }
9145 else
9146 {
9147 // 11a packet
9148 pBssDescr->nwType = eSIR_11A_NW_TYPE;
9149 }
9150
9151 pBssDescr->sinr = 0;
9152 pBssDescr->rssi = -1 * pPrefNetworkFoundInd->rssi;
9153 pBssDescr->beaconInterval = pParsedFrame->beaconInterval;
AnjaneeDevi Kapparapu4b043912014-02-18 13:22:35 +05309154 if (!pBssDescr->beaconInterval)
9155 {
9156 smsLog(pMac, LOGW,
9157 FL("Bcn Interval is Zero , default to 100" MAC_ADDRESS_STR),
9158 MAC_ADDR_ARRAY(pBssDescr->bssId) );
9159 pBssDescr->beaconInterval = 100;
9160 }
Srikant Kuppa066904f2013-05-07 13:56:02 -07009161 pBssDescr->timeStamp[0] = pParsedFrame->timeStamp[0];
9162 pBssDescr->timeStamp[1] = pParsedFrame->timeStamp[1];
9163 pBssDescr->capabilityInfo = *((tANI_U16 *)&pParsedFrame->capabilityInfo);
Kiet Lam64c1b492013-07-12 13:56:44 +05309164 vos_mem_copy((tANI_U8 *) &pBssDescr->bssId, (tANI_U8 *) macHeader->bssId, sizeof(tSirMacAddr));
Deepthi Gowri4480a3f2016-05-18 19:30:17 +05309165 pBssDescr->nReceivedTime = vos_timer_get_system_time();
Srikant Kuppa066904f2013-05-07 13:56:02 -07009166
Abhishek Singh195c03e2014-05-14 17:21:30 +05309167 smsLog( pMac, LOG1, FL("Bssid= "MAC_ADDRESS_STR
9168 " chan= %d, rssi = %d "),
Arif Hussain24bafea2013-11-15 15:10:03 -08009169 MAC_ADDR_ARRAY(pBssDescr->bssId),
Srikant Kuppa066904f2013-05-07 13:56:02 -07009170 pBssDescr->channelId,
Abhishek Singh195c03e2014-05-14 17:21:30 +05309171 pBssDescr->rssi);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009172
9173 //IEs
9174 if (uLen)
9175 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309176 vos_mem_copy(&pBssDescr->ieFields,
9177 pPrefNetworkFoundInd->data + (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET),
9178 uLen);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009179 }
9180
9181 pIesLocal = (tDot11fBeaconIEs *)( pScanResult->Result.pvIes );
9182 if ( !pIesLocal &&
9183 (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
9184 &pScanResult->Result.BssDescriptor, &pIesLocal))) )
9185 {
9186 smsLog(pMac, LOGE, FL(" Cannot parse IEs"));
9187 csrFreeScanResultEntry(pMac, pScanResult);
Abhishek Singhc75726d2015-04-13 14:44:14 +05309188 vos_mem_vfree(pParsedFrame);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009189 return eHAL_STATUS_RESOURCES;
9190 }
9191
9192 fDupBss = csrRemoveDupBssDescription( pMac,
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05309193 &pScanResult->Result.BssDescriptor, pIesLocal, &tmpSsid, &timer, FALSE);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009194 //Check whether we have reach out limit
9195 if ( CSR_SCAN_IS_OVER_BSS_LIMIT(pMac) )
9196 {
9197 //Limit reach
9198 smsLog(pMac, LOGE, FL(" BSS limit reached"));
9199 //Free the resources
9200 if( (pScanResult->Result.pvIes == NULL) && pIesLocal )
9201 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309202 vos_mem_free(pIesLocal);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009203 }
9204 csrFreeScanResultEntry(pMac, pScanResult);
9205 vos_mem_free(pParsedFrame);
9206 return eHAL_STATUS_RESOURCES;
9207 }
Nalla Kartheek71946422015-09-15 14:41:22 +05309208
9209 if ((macHeader->fc.type == SIR_MAC_MGMT_FRAME) &&
9210 (macHeader->fc.subType == SIR_MAC_MGMT_PROBE_RSP))
9211 {
9212 pScanResult->Result.BssDescriptor.fProbeRsp = 1;
9213 }
Srikant Kuppa066904f2013-05-07 13:56:02 -07009214 //Add to scan cache
9215 csrScanAddResult(pMac, pScanResult, pIesLocal);
Sushant Kaushik6274de62015-05-01 16:31:23 +05309216 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
Kiet Lamb537cfb2013-11-07 12:56:49 +05309217 if( (pScanResult->Result.pvIes == NULL) && pIesLocal )
9218 {
9219 vos_mem_free(pIesLocal);
9220 }
9221
Abhishek Singhc75726d2015-04-13 14:44:14 +05309222 vos_mem_vfree(pParsedFrame);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009223
9224 return eHAL_STATUS_SUCCESS;
9225}
Manjunathappa Prakash4f1d5a52013-11-11 16:22:19 -08009226#endif //FEATURE_WLAN_SCAN_PNO
Srikant Kuppa066904f2013-05-07 13:56:02 -07009227
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08009228#ifdef FEATURE_WLAN_LFR
9229void csrInitOccupiedChannelsList(tpAniSirGlobal pMac)
9230{
9231 tListElem *pEntry = NULL;
9232 tCsrScanResult *pBssDesc = NULL;
9233 tDot11fBeaconIEs *pIes = NULL;
Srinivas28b5b4e2012-12-12 13:07:53 -08009234 tpCsrNeighborRoamControlInfo pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
9235
9236 if (0 != pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels)
9237 {
9238 smsLog(pMac, LOG1, FL("%s: Ini file contains neighbor scan channel list,"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08009239 " hence NO need to build occupied channel list (numChannels = %d)"),
Srinivas28b5b4e2012-12-12 13:07:53 -08009240 __func__, pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels);
9241 return;
9242 }
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08009243
9244 if (!csrNeighborRoamIsNewConnectedProfile(pMac))
9245 {
9246 smsLog(pMac, LOG2, FL("%s: donot flush occupied list since current roam profile"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08009247 " matches previous (numChannels = %d)"),
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08009248 __func__, pMac->scan.occupiedChannels.numChannels);
9249 return;
9250 }
9251
9252 /* Empty occupied channels here */
9253 pMac->scan.occupiedChannels.numChannels = 0;
9254
9255 csrLLLock(&pMac->scan.scanResultList);
9256 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
9257 while( pEntry )
9258 {
9259 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
9260 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
9261
9262 //At this time, pBssDescription->Result.pvIes may be NULL
Srikant Kuppa866893f2012-12-27 17:28:14 -08009263 if( !pIes && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08009264 &pBssDesc->Result.BssDescriptor, &pIes))) )
9265 {
9266 continue;
9267 }
9268
9269 csrScanAddToOccupiedChannels(pMac, pBssDesc, &pMac->scan.occupiedChannels, pIes);
9270
9271 /*
9272 * Free the memory allocated for pIes in csrGetParsedBssDescriptionIEs
9273 */
9274 if( (pBssDesc->Result.pvIes == NULL) && pIes )
9275 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309276 vos_mem_free(pIes);
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08009277 }
9278
9279 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK );
9280 }//while
9281 csrLLUnlock(&pMac->scan.scanResultList);
Srikant Kuppa866893f2012-12-27 17:28:14 -08009282
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08009283}
9284#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009285
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009286eHalStatus csrScanCreateEntryInScanCache(tpAniSirGlobal pMac, tANI_U32 sessionId,
9287 tCsrBssid bssid, tANI_U8 channel)
9288{
9289 eHalStatus status = eHAL_STATUS_SUCCESS;
9290 tDot11fBeaconIEs *pNewIes = NULL;
9291 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
Praveen Kumar Sirisilla8bdfac42013-10-10 17:20:48 -07009292 tSirBssDescription *pNewBssDescriptor = NULL;
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009293 tANI_U32 size = 0;
9294
9295 if(NULL == pSession)
9296 {
9297 status = eHAL_STATUS_FAILURE;
9298 return status;
9299 }
9300 smsLog(pMac, LOG2, FL("csrScanCreateEntryInScanCache: Current bssid::"
Arif Hussain24bafea2013-11-15 15:10:03 -08009301 MAC_ADDRESS_STR),
9302 MAC_ADDR_ARRAY(pSession->pConnectBssDesc->bssId));
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009303 smsLog(pMac, LOG2, FL("csrScanCreateEntryInScanCache: My bssid::"
Arif Hussain24bafea2013-11-15 15:10:03 -08009304 MAC_ADDRESS_STR" channel %d"),
9305 MAC_ADDR_ARRAY(bssid), channel);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009306
9307 do
9308 {
9309 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
9310 pSession->pConnectBssDesc, &pNewIes)))
9311 {
9312 smsLog(pMac, LOGE, FL("%s: Failed to parse IEs"),
9313 __func__);
9314 status = eHAL_STATUS_FAILURE;
9315 break;
9316 }
9317
9318 size = pSession->pConnectBssDesc->length + sizeof(pSession->pConnectBssDesc->length);
Kiet Lam64c1b492013-07-12 13:56:44 +05309319 if (size)
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009320 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309321 pNewBssDescriptor = vos_mem_malloc(size);
9322 if ( NULL == pNewBssDescriptor )
9323 status = eHAL_STATUS_FAILURE;
9324 else
9325 status = eHAL_STATUS_SUCCESS;
9326 if (HAL_STATUS_SUCCESS(status))
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009327 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309328 vos_mem_copy(pNewBssDescriptor, pSession->pConnectBssDesc, size);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009329 }
9330 else
9331 {
9332 smsLog(pMac, LOGE, FL("%s: memory allocation failed"),
9333 __func__);
9334 status = eHAL_STATUS_FAILURE;
9335 break;
9336 }
9337
9338 //change the BSSID & channel as passed
Kiet Lam64c1b492013-07-12 13:56:44 +05309339 vos_mem_copy(pNewBssDescriptor->bssId, bssid, sizeof(tSirMacAddr));
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009340 pNewBssDescriptor->channelId = channel;
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07009341 if(NULL == csrScanAppendBssDescription( pMac, pNewBssDescriptor, pNewIes, TRUE ))
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009342 {
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07009343 smsLog(pMac, LOGE, FL("%s: csrScanAppendBssDescription failed"),
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009344 __func__);
9345 status = eHAL_STATUS_FAILURE;
9346 break;
9347 }
9348 }
9349 else
9350 {
9351 smsLog(pMac, LOGE, FL("%s: length of bss descriptor is 0"),
9352 __func__);
9353 status = eHAL_STATUS_FAILURE;
9354 break;
9355 }
9356 smsLog(pMac, LOGE, FL("%s: entry successfully added in scan cache"),
9357 __func__);
9358 }while(0);
9359
9360 if(pNewIes)
9361 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309362 vos_mem_free(pNewIes);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009363 }
9364 if(pNewBssDescriptor)
9365 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309366 vos_mem_free(pNewBssDescriptor);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009367 }
9368 return status;
9369}
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07009370
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08009371#ifdef FEATURE_WLAN_ESE
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07009372// Update the TSF with the difference in system time
9373void UpdateCCKMTSF(tANI_U32 *timeStamp0, tANI_U32 *timeStamp1, tANI_U32 *incr)
9374{
9375 tANI_U64 timeStamp64 = ((tANI_U64)*timeStamp1 << 32) | (*timeStamp0);
9376
9377 timeStamp64 = (tANI_U64)(timeStamp64 + (tANI_U64)*incr);
9378 *timeStamp0 = (tANI_U32)(timeStamp64 & 0xffffffff);
9379 *timeStamp1 = (tANI_U32)((timeStamp64 >> 32) & 0xffffffff);
9380}
9381#endif