blob: 6918de33b910544da3056fc321af3006e0e66bc5 [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Abhishek Singha2649232016-01-20 15:52:05 +05302 * Copyright (c) 2011-2016 The Linux Foundation. All rights reserved.
Kiet Lam0fb93dd2014-02-19 00:32:59 -08003 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
Gopichand Nakkala92f07d82013-01-08 21:16:34 -080020 */
Kiet Lam0fb93dd2014-02-19 00:32:59 -080021
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
Jeff Johnson40b59aa2013-03-19 14:43:18 -070028/** ------------------------------------------------------------------------- *
29 ------------------------------------------------------------------------- *
Jeff Johnson295189b2012-06-20 16:38:30 -070030
Jeff Johnson40b59aa2013-03-19 14:43:18 -070031
Jeff Johnson295189b2012-06-20 16:38:30 -070032 \file csrApiScan.c
Jeff Johnson40b59aa2013-03-19 14:43:18 -070033
Jeff Johnson295189b2012-06-20 16:38:30 -070034 Implementation for the Common Scan interfaces.
Jeff Johnson295189b2012-06-20 16:38:30 -070035 ========================================================================== */
36
37#include "aniGlobal.h"
38
39#include "palApi.h"
40#include "csrInsideApi.h"
41#include "smeInside.h"
42#include "smsDebug.h"
43
44#include "csrSupport.h"
45#include "wlan_qct_tl.h"
46
47#include "vos_diag_core_log.h"
48#include "vos_diag_core_event.h"
49
50#include "vos_nvitem.h"
Rajesh Babu Prathipati20cdffa2014-07-01 22:24:59 +053051#include "vos_memory.h"
Jeff Johnson295189b2012-06-20 16:38:30 -070052#include "wlan_qct_wda.h"
Abhishek Singhe3fa11f2014-05-13 11:11:10 +053053#include "vos_utils.h"
Jeff Johnson40b59aa2013-03-19 14:43:18 -070054
Kiet Lamd1f3dc82013-11-05 20:45:04 +053055#define MIN_CHN_TIME_TO_FIND_GO 100
56#define MAX_CHN_TIME_TO_FIND_GO 100
57#define DIRECT_SSID_LEN 7
Jeff Johnson295189b2012-06-20 16:38:30 -070058
Jeff Johnson295189b2012-06-20 16:38:30 -070059
60/* Purpose of HIDDEN_TIMER
61** When we remove hidden ssid from the profile i.e., forget the SSID via GUI that SSID shouldn't see in the profile
62** For above requirement we used timer limit, logic is explained below
63** Timer value is initialsed to current time when it receives corresponding probe response of hidden SSID (The probe request is
64** received regularly till SSID in the profile. Once it is removed from profile probe request is not sent.) when we receive probe response
65** for broadcast probe request, during update SSID with saved SSID we will diff current time with saved SSID time if it is greater than 1 min
66** then we are not updating with old one
67*/
68
69#define HIDDEN_TIMER (1*60*1000)
70#define CSR_SCAN_RESULT_RSSI_WEIGHT 80 // must be less than 100, represent the persentage of new RSSI
71
72/*---------------------------------------------------------------------------
73 PER filter constant fraction: it is a %
74---------------------------------------------------------------------------*/
75#define CSR_SCAN_PER_FILTER_FRAC 100
76
77/*---------------------------------------------------------------------------
78 RSSI filter constant fraction: it is a %
79---------------------------------------------------------------------------*/
80#define CSR_SCAN_RSSI_FILTER_FRAC 100
81
82/*---------------------------------------------------------------------------
83Convert RSSI into overall score: Since RSSI is in -dBm values, and the
84overall needs to be weighted inversely (where greater value means better
85system), we convert.
86RSSI *cannot* be more than 0xFF or less than 0 for meaningful WLAN operation
87---------------------------------------------------------------------------*/
88#define CSR_SCAN_MAX_SCORE_VAL 0xFF
89#define CSR_SCAN_MIN_SCORE_VAL 0x0
90#define CSR_SCAN_HANDOFF_DELTA 10
Jeff Johnson32d95a32012-09-10 13:15:23 -070091#define MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL 140
92#define MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL 120
Selvaraj, Sridhar32417ed2016-06-22 15:19:12 +053093
94#ifndef QCA_WIFI_ISOC
95#define MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL_FASTREASSOC 30
96#define MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL_FASTREASSOC 20
97#endif
98
Madan Mohan Koyyalamudia53c4dc2012-11-13 10:35:42 -080099#define CSR_SCAN_OVERALL_SCORE( rssi ) \
100 (( rssi < CSR_SCAN_MAX_SCORE_VAL ) \
101 ? (CSR_SCAN_MAX_SCORE_VAL-rssi) : CSR_SCAN_MIN_SCORE_VAL)
Jeff Johnson295189b2012-06-20 16:38:30 -0700102
103
104#define CSR_SCAN_IS_OVER_BSS_LIMIT(pMac) \
105 ( (pMac)->scan.nBssLimit <= (csrLLCount(&(pMac)->scan.scanResultList)) )
106
Sushant Kaushikf4e085e2014-06-17 16:07:33 +0530107#define THIRTY_PERCENT(x) (x*30/100);
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +0530108
krunal soni5f112f02013-11-25 15:00:11 -0800109#define MANDATORY_BG_CHANNEL 11
110
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -0800111#ifndef CONFIG_ENABLE_LINUX_REG
Sushant Kaushikf4e085e2014-06-17 16:07:33 +0530112tCsrIgnoreChannels countryIgnoreList[MAX_COUNTRY_IGNORE] = {
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +0530113 { {'U','A'}, { 136, 140}, 2},
114 { {'T','W'}, { 36, 40, 44, 48, 52}, 5},
Madan Mohan Koyyalamudi28dd0422013-08-12 15:06:21 +0530115 { {'I','D'}, { 165}, 1 },
Wilson Yange3d2b292013-10-09 00:35:43 -0700116 { {'A','U'}, { 120, 124, 128}, 3 },
Wilson Yangce31eaf2013-11-11 14:40:34 -0800117 { {'A','R'}, { 120, 124, 128}, 3 }
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +0530118 };
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -0800119#else
Sushant Kaushikf4e085e2014-06-17 16:07:33 +0530120tCsrIgnoreChannels countryIgnoreList[MAX_COUNTRY_IGNORE] = { };
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -0800121#endif //CONFIG_ENABLE_LINUX_REG
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +0530122
Jeff Johnson295189b2012-06-20 16:38:30 -0700123//*** This is temporary work around. It need to call CCM api to get to CFG later
124/// Get string parameter value
125extern tSirRetStatus wlan_cfgGetStr(tpAniSirGlobal, tANI_U16, tANI_U8*, tANI_U32*);
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +0530126
Jeff Johnson295189b2012-06-20 16:38:30 -0700127void csrScanGetResultTimerHandler(void *);
Deepthi Gowri6a08e312016-03-31 19:10:14 +0530128static void csrPurgeScanResultByAge(void *pv);
Jeff Johnson295189b2012-06-20 16:38:30 -0700129void csrScanIdleScanTimerHandler(void *);
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700130static void csrSetDefaultScanTiming( tpAniSirGlobal pMac, tSirScanType scanType, tCsrScanRequest *pScanRequest);
Jeff Johnson295189b2012-06-20 16:38:30 -0700131#ifdef WLAN_AP_STA_CONCURRENCY
132static void csrStaApConcTimerHandler(void *);
133#endif
Jeff Johnsone7245742012-09-05 17:12:55 -0700134tANI_BOOLEAN csrIsSupportedChannel(tpAniSirGlobal pMac, tANI_U8 channelId);
Jeff Johnson295189b2012-06-20 16:38:30 -0700135eHalStatus csrScanChannels( tpAniSirGlobal pMac, tSmeCmd *pCommand );
136void csrSetCfgValidChannelList( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels );
137void csrSaveTxPowerToCfg( tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 cfgId );
138void csrSetCfgCountryCode( tpAniSirGlobal pMac, tANI_U8 *countryCode );
139void csrPurgeChannelPower( tpAniSirGlobal pMac, tDblLinkList *pChannelList );
140//if bgPeriod is 0, background scan is disabled. It is in millisecond units
141eHalStatus csrSetCfgBackgroundScanPeriod(tpAniSirGlobal pMac, tANI_U32 bgPeriod);
142eHalStatus csrProcessSetBGScanParam(tpAniSirGlobal pMac, tSmeCmd *pCommand);
143void csrReleaseScanCommand(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus);
144static tANI_BOOLEAN csrScanValidateScanResult( tpAniSirGlobal pMac, tANI_U8 *pChannels,
145 tANI_U8 numChn, tSirBssDescription *pBssDesc,
146 tDot11fBeaconIEs **ppIes );
147eHalStatus csrSetBGScanChannelList( tpAniSirGlobal pMac, tANI_U8 *pAdjustChannels, tANI_U8 NumAdjustChannels);
148void csrReleaseCmdSingle(tpAniSirGlobal pMac, tSmeCmd *pCommand);
149tANI_BOOLEAN csrRoamIsValidChannel( tpAniSirGlobal pMac, tANI_U8 channel );
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700150void csrPruneChannelListForMode( tpAniSirGlobal pMac, tCsrChannel *pChannelList );
Deepthi Gowri50e2fa52016-03-17 15:30:53 +0530151void csrPurgeOldScanResults(tpAniSirGlobal pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -0700152
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -0700153
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -0700154
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -0700155
Madan Mohan Koyyalamudi923c1e12012-11-30 17:53:27 -0800156static void csrReleaseScanCmdPendingList(tpAniSirGlobal pMac)
157{
158 tListElem *pEntry;
159 tSmeCmd *pCommand;
160
161 while((pEntry = csrLLRemoveHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK)) != NULL)
162 {
163 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
164 if ( eSmeCsrCommandMask & pCommand->command )
165 {
166 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_TRUE );
167 }
168 else
169 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800170 smsLog(pMac, LOGE, FL("Error: Received command : %d"),pCommand->command);
Madan Mohan Koyyalamudi923c1e12012-11-30 17:53:27 -0800171 }
172 }
173}
Jeff Johnson295189b2012-06-20 16:38:30 -0700174//pResult is invalid calling this function.
175void csrFreeScanResultEntry( tpAniSirGlobal pMac, tCsrScanResult *pResult )
176{
177 if( NULL != pResult->Result.pvIes )
178 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530179 vos_mem_free(pResult->Result.pvIes);
Jeff Johnson295189b2012-06-20 16:38:30 -0700180 }
Kiet Lam64c1b492013-07-12 13:56:44 +0530181 vos_mem_free(pResult);
Jeff Johnson295189b2012-06-20 16:38:30 -0700182}
183
184
185static eHalStatus csrLLScanPurgeResult(tpAniSirGlobal pMac, tDblLinkList *pList)
186{
187 eHalStatus status = eHAL_STATUS_SUCCESS;
188 tListElem *pEntry;
189 tCsrScanResult *pBssDesc;
190
191 csrLLLock(pList);
192
193 while((pEntry = csrLLRemoveHead(pList, LL_ACCESS_NOLOCK)) != NULL)
194 {
195 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
196 csrFreeScanResultEntry( pMac, pBssDesc );
197 }
198
199 csrLLUnlock(pList);
200
201 return (status);
202}
203
Jeff Johnson295189b2012-06-20 16:38:30 -0700204eHalStatus csrScanOpen( tpAniSirGlobal pMac )
205{
206 eHalStatus status;
207
208 do
209 {
210 csrLLOpen(pMac->hHdd, &pMac->scan.scanResultList);
211 csrLLOpen(pMac->hHdd, &pMac->scan.tempScanResults);
212 csrLLOpen(pMac->hHdd, &pMac->scan.channelPowerInfoList24);
213 csrLLOpen(pMac->hHdd, &pMac->scan.channelPowerInfoList5G);
214#ifdef WLAN_AP_STA_CONCURRENCY
215 csrLLOpen(pMac->hHdd, &pMac->scan.scanCmdPendingList);
216#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700217 pMac->scan.fFullScanIssued = eANI_BOOLEAN_FALSE;
218 pMac->scan.nBssLimit = CSR_MAX_BSS_SUPPORT;
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530219 status = vos_timer_init(&pMac->scan.hTimerGetResult, VOS_TIMER_TYPE_SW, csrScanGetResultTimerHandler, pMac);
220 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700221 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800222 smsLog(pMac, LOGE, FL("cannot allocate memory for getResult timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700223 break;
224 }
225#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530226 status = vos_timer_init(&pMac->scan.hTimerStaApConcTimer, VOS_TIMER_TYPE_SW, csrStaApConcTimerHandler, pMac);
227 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700228 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800229 smsLog(pMac, LOGE, FL("cannot allocate memory for hTimerStaApConcTimer timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700230 break;
231 }
232#endif
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530233 status = vos_timer_init(&pMac->scan.hTimerIdleScan, VOS_TIMER_TYPE_SW, csrScanIdleScanTimerHandler, pMac);
234 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700235 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800236 smsLog(pMac, LOGE, FL("cannot allocate memory for idleScan timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700237 break;
238 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700239 }while(0);
240
241 return (status);
242}
243
244
245eHalStatus csrScanClose( tpAniSirGlobal pMac )
246{
Jeff Johnson295189b2012-06-20 16:38:30 -0700247 csrLLScanPurgeResult(pMac, &pMac->scan.tempScanResults);
248 csrLLScanPurgeResult(pMac, &pMac->scan.scanResultList);
249#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudi923c1e12012-11-30 17:53:27 -0800250 csrReleaseScanCmdPendingList(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -0700251#endif
252 csrLLClose(&pMac->scan.scanResultList);
253 csrLLClose(&pMac->scan.tempScanResults);
254#ifdef WLAN_AP_STA_CONCURRENCY
255 csrLLClose(&pMac->scan.scanCmdPendingList);
256#endif
257 csrPurgeChannelPower(pMac, &pMac->scan.channelPowerInfoList24);
258 csrPurgeChannelPower(pMac, &pMac->scan.channelPowerInfoList5G);
259 csrLLClose(&pMac->scan.channelPowerInfoList24);
260 csrLLClose(&pMac->scan.channelPowerInfoList5G);
261 csrScanDisable(pMac);
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530262 vos_timer_destroy(&pMac->scan.hTimerGetResult);
Jeff Johnson295189b2012-06-20 16:38:30 -0700263#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530264 vos_timer_destroy(&pMac->scan.hTimerStaApConcTimer);
Jeff Johnson295189b2012-06-20 16:38:30 -0700265#endif
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530266 vos_timer_destroy(&pMac->scan.hTimerIdleScan);
Jeff Johnson295189b2012-06-20 16:38:30 -0700267 return eHAL_STATUS_SUCCESS;
268}
269
270
271eHalStatus csrScanEnable( tpAniSirGlobal pMac )
272{
273
274 pMac->scan.fScanEnable = eANI_BOOLEAN_TRUE;
275 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
276
277 return eHAL_STATUS_SUCCESS;
278}
279
280
281eHalStatus csrScanDisable( tpAniSirGlobal pMac )
282{
283
284 csrScanStopTimers(pMac);
285 pMac->scan.fScanEnable = eANI_BOOLEAN_FALSE;
286
287 return eHAL_STATUS_SUCCESS;
288}
289
290
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700291//Set scan timing parameters according to state of other driver sessions
292//No validation of the parameters is performed.
293static void csrSetDefaultScanTiming( tpAniSirGlobal pMac, tSirScanType scanType, tCsrScanRequest *pScanRequest)
294{
295#ifdef WLAN_AP_STA_CONCURRENCY
296 if(csrIsAnySessionConnected(pMac))
297 {
Sushant Kaushika6fef4b2014-09-24 16:17:08 +0530298 //Reset passive scan time as per ini parameter.
Abhishek Singh7fb7dc12014-11-06 17:44:05 +0530299 ccmCfgSetInt(pMac, WNI_CFG_PASSIVE_MAXIMUM_CHANNEL_TIME,
Sushant Kaushika6fef4b2014-09-24 16:17:08 +0530300 pMac->roam.configParam.nPassiveMaxChnTimeConc,
301 NULL,eANI_BOOLEAN_FALSE);
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700302 //If multi-session, use the appropriate default scan times
303 if(scanType == eSIR_ACTIVE_SCAN)
304 {
305 pScanRequest->maxChnTime = pMac->roam.configParam.nActiveMaxChnTimeConc;
306 pScanRequest->minChnTime = pMac->roam.configParam.nActiveMinChnTimeConc;
307 }
308 else
309 {
310 pScanRequest->maxChnTime = pMac->roam.configParam.nPassiveMaxChnTimeConc;
311 pScanRequest->minChnTime = pMac->roam.configParam.nPassiveMinChnTimeConc;
312 }
Kiet Lam64c1b492013-07-12 13:56:44 +0530313 pScanRequest->maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
314 pScanRequest->minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700315
316 pScanRequest->restTime = pMac->roam.configParam.nRestTimeConc;
317
318 //Return so that fields set above will not be overwritten.
319 return;
320 }
321#endif
322
323 //This portion of the code executed if multi-session not supported
324 //(WLAN_AP_STA_CONCURRENCY not defined) or no multi-session.
325 //Use the "regular" (non-concurrency) default scan timing.
Abhishek Singh7fb7dc12014-11-06 17:44:05 +0530326 ccmCfgSetInt(pMac, WNI_CFG_PASSIVE_MAXIMUM_CHANNEL_TIME,
Kaushik, Sushant49758c12014-09-26 11:25:38 +0530327 pMac->roam.configParam.nPassiveMaxChnTime,
328 NULL,eANI_BOOLEAN_FALSE);
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700329 if(pScanRequest->scanType == eSIR_ACTIVE_SCAN)
330 {
331 pScanRequest->maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
332 pScanRequest->minChnTime = pMac->roam.configParam.nActiveMinChnTime;
333 }
334 else
335 {
336 pScanRequest->maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
337 pScanRequest->minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
338 }
Kiet Lam64c1b492013-07-12 13:56:44 +0530339 pScanRequest->maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
340 pScanRequest->minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700341
342#ifdef WLAN_AP_STA_CONCURRENCY
343 //No rest time if no sessions are connected.
344 pScanRequest->restTime = 0;
345#endif
346}
347
Jeff Johnson295189b2012-06-20 16:38:30 -0700348#ifdef WLAN_AP_STA_CONCURRENCY
349//Return SUCCESS is the command is queued, else returns eHAL_STATUS_FAILURE
350eHalStatus csrQueueScanRequest( tpAniSirGlobal pMac, tSmeCmd *pScanCmd )
351{
352 eHalStatus status = eHAL_STATUS_SUCCESS;
353
354 tANI_BOOLEAN fNoCmdPending;
355 tSmeCmd *pQueueScanCmd=NULL;
356 tSmeCmd *pSendScanCmd=NULL;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700357 tANI_U8 nNumChanCombinedConc = 0;
Gopichand Nakkala114718f2013-03-25 19:19:46 -0700358 if (NULL == pScanCmd)
359 {
360 smsLog (pMac, LOGE, FL("Scan Req cmd is NULL"));
361 return eHAL_STATUS_FAILURE;
362 }
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -0800363 /* split scan if any one of the following:
364 * - STA session is connected and the scan is not a P2P search
365 * - any P2P session is connected
Srikant Kuppa866893f2012-12-27 17:28:14 -0800366 * Do not split scans if no concurrent infra connections are
367 * active and if the scan is a BG scan triggered by LFR (OR)
368 * any scan if LFR is in the middle of a BG scan. Splitting
369 * the scan is delaying the time it takes for LFR to find
370 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -0800371 */
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700372
373 if(csrIsStaSessionConnected(pMac) &&
374 !csrIsP2pSessionConnected(pMac))
375 {
376 nNumChanCombinedConc = pMac->roam.configParam.nNumStaChanCombinedConc;
377 }
378 else if(csrIsP2pSessionConnected(pMac))
379 {
380 nNumChanCombinedConc = pMac->roam.configParam.nNumP2PChanCombinedConc;
381 }
Srikant Kuppa866893f2012-12-27 17:28:14 -0800382 if ( (csrIsStaSessionConnected(pMac) &&
383#ifdef FEATURE_WLAN_LFR
384 (csrIsConcurrentInfraConnected(pMac) ||
385 ((pScanCmd->u.scanCmd.reason != eCsrScanBgScan) &&
386 (pMac->roam.neighborRoamInfo.neighborRoamState !=
387 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
388#endif
389 (pScanCmd->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Vinay Malekal05fdc812012-12-17 13:04:30 -0800390 (csrIsP2pSessionConnected(pMac)) )
Jeff Johnson295189b2012-06-20 16:38:30 -0700391 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700392 tCsrScanRequest scanReq;
393 tANI_U8 numChn = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
394 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
395 tANI_U8 channelToScan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
Jeff Johnson295189b2012-06-20 16:38:30 -0700396 tANI_BOOLEAN bMemAlloc = eANI_BOOLEAN_FALSE;
397
398 if (numChn == 0)
399 {
400
401 numChn = pMac->scan.baseChannels.numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -0700402
Kiet Lam64c1b492013-07-12 13:56:44 +0530403 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(numChn);
404 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -0700405 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800406 smsLog( pMac, LOGE, FL(" Failed to get memory for channel list ") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800407 return eHAL_STATUS_FAILURE;
408 }
409 bMemAlloc = eANI_BOOLEAN_TRUE;
Kiet Lam64c1b492013-07-12 13:56:44 +0530410 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
411 pMac->scan.baseChannels.channelList, numChn);
412 status = eHAL_STATUS_SUCCESS;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800413 if( !HAL_STATUS_SUCCESS( status ) )
414 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530415 vos_mem_free(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800416 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800417 smsLog( pMac, LOGE, FL(" Failed to copy memory to channel list ") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800418 return eHAL_STATUS_FAILURE;
419 }
420 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = numChn;
421 }
Sushant Kaushik826de802014-05-08 18:04:11 +0530422 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
423 "%s: Total Number of channels to scan : %d "
424 "Splitted in group of %d ", __func__, numChn,
425 nNumChanCombinedConc);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800426 //Whenever we get a scan request with multiple channels we break it up into 2 requests
427 //First request for first channel to scan and second request to scan remaining channels
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700428 if ( numChn > nNumChanCombinedConc)
Vinay Malekal05fdc812012-12-17 13:04:30 -0800429 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530430 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800431
432 pQueueScanCmd = csrGetCommandBuffer(pMac); //optimize this to use 2 command buffer only
433 if (!pQueueScanCmd)
434 {
435 if (bMemAlloc)
Jeff Johnson295189b2012-06-20 16:38:30 -0700436 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530437 vos_mem_free(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800438 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
439
Jeff Johnson295189b2012-06-20 16:38:30 -0700440 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800441 smsLog( pMac, LOGE, FL(" Failed to get Queue command buffer") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800442 return eHAL_STATUS_FAILURE;
443 }
444 pQueueScanCmd->command = pScanCmd->command;
445 pQueueScanCmd->sessionId = pScanCmd->sessionId;
446 pQueueScanCmd->u.scanCmd.callback = pScanCmd->u.scanCmd.callback;
447 pQueueScanCmd->u.scanCmd.pContext = pScanCmd->u.scanCmd.pContext;
448 pQueueScanCmd->u.scanCmd.reason = pScanCmd->u.scanCmd.reason;
449 pQueueScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Jeff Johnson295189b2012-06-20 16:38:30 -0700450
Vinay Malekal05fdc812012-12-17 13:04:30 -0800451 /* First copy all the parameters to local variable of scan request */
452 csrScanCopyRequest(pMac, &scanReq, &pScanCmd->u.scanCmd.u.scanRequest);
Madan Mohan Koyyalamudiaf2a8b92012-10-09 14:58:07 -0700453
Vinay Malekal05fdc812012-12-17 13:04:30 -0800454 /* Now modify the elements of local var scan request required to be modified for split scan */
455 if(scanReq.ChannelInfo.ChannelList != NULL)
456 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530457 vos_mem_free(scanReq.ChannelInfo.ChannelList);
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -0800458 scanReq.ChannelInfo.ChannelList = NULL;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800459 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700460
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700461 pChnInfo->numOfChannels = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels - nNumChanCombinedConc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700462
Vinay Malekal05fdc812012-12-17 13:04:30 -0800463 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_WARN,
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +0530464 FL(" &channelToScan %p pScanCmd(%p) pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList(%p)numChn(%d)"),
465 &channelToScan[0], pScanCmd,
466 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList, numChn);
Jeff Johnson295189b2012-06-20 16:38:30 -0700467
Kiet Lam64c1b492013-07-12 13:56:44 +0530468 vos_mem_copy(&channelToScan[0],
469 &pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[
470 nNumChanCombinedConc],
471 pChnInfo->numOfChannels * sizeof(tANI_U8));
Vinay Malekal05fdc812012-12-17 13:04:30 -0800472
473 pChnInfo->ChannelList = &channelToScan[0];
474
475 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
c_hpothudbefd3e2014-04-28 15:59:47 +0530476
Vinay Malekal05fdc812012-12-17 13:04:30 -0800477 //Use concurrency values for min/maxChnTime.
478 //We know csrIsAnySessionConnected(pMac) returns TRUE here
479 csrSetDefaultScanTiming(pMac, scanReq.scanType, &scanReq);
480
481 status = csrScanCopyRequest(pMac, &pQueueScanCmd->u.scanCmd.u.scanRequest, &scanReq);
482
483 if(!HAL_STATUS_SUCCESS(status))
484 {
485 if (bMemAlloc)
486 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530487 vos_mem_free(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800488 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
489
490 }
491 if( scanReq.pIEField != NULL)
492 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530493 vos_mem_free(scanReq.pIEField);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800494 scanReq.pIEField = NULL;
495 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800496 smsLog( pMac, LOGE, FL(" Failed to get copy csrScanRequest = %d"), status );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800497 return eHAL_STATUS_FAILURE;
498 }
499 /* Clean the local scan variable */
500 scanReq.ChannelInfo.ChannelList = NULL;
501 scanReq.ChannelInfo.numOfChannels = 0;
502 csrScanFreeRequest(pMac, &scanReq);
503
504 /* setup the command to scan 2 channels */
505 pSendScanCmd = pScanCmd;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700506 pSendScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nNumChanCombinedConc;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800507 pSendScanCmd->u.scanCmd.u.scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
c_hpothudbefd3e2014-04-28 15:59:47 +0530508
Vinay Malekal05fdc812012-12-17 13:04:30 -0800509 //Use concurrency values for min/maxChnTime.
510 //We know csrIsAnySessionConnected(pMac) returns TRUE here
511 csrSetDefaultScanTiming(pMac, pSendScanCmd->u.scanCmd.u.scanRequest.scanType, &pSendScanCmd->u.scanCmd.u.scanRequest);
512 pSendScanCmd->u.scanCmd.callback = NULL;
513 } else {
514 pSendScanCmd = pScanCmd;
515 pSendScanCmd->u.scanCmd.u.scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
c_hpothudbefd3e2014-04-28 15:59:47 +0530516
Vinay Malekal05fdc812012-12-17 13:04:30 -0800517 //Use concurrency values for min/maxChnTime.
518 //We know csrIsAnySessionConnected(pMac) returns TRUE here
519 csrSetDefaultScanTiming(pMac, pSendScanCmd->u.scanCmd.u.scanRequest.scanType, &pSendScanCmd->u.scanCmd.u.scanRequest);
520 }
521
522 fNoCmdPending = csrLLIsListEmpty( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK );
523
524 //Logic Below is as follows
525 // If the scanCmdPendingList is empty then we directly send that command
526 // to smeCommandQueue else we buffer it in our scanCmdPendingList Queue
527 if( fNoCmdPending )
528 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700529 if (pQueueScanCmd != NULL)
530 {
Vinay Malekal05fdc812012-12-17 13:04:30 -0800531 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pQueueScanCmd->Link, LL_ACCESS_LOCK );
Jeff Johnson295189b2012-06-20 16:38:30 -0700532 }
533
534 if (pSendScanCmd != NULL)
535 {
536 return csrQueueSmeCommand(pMac, pSendScanCmd, eANI_BOOLEAN_FALSE);
537 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800538 }
539 else
540 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700541 if (pSendScanCmd != NULL)
542 {
543 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pSendScanCmd->Link, LL_ACCESS_LOCK );
544 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800545
Jeff Johnson295189b2012-06-20 16:38:30 -0700546 if (pQueueScanCmd != NULL)
547 {
548 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pQueueScanCmd->Link, LL_ACCESS_LOCK );
549 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800550 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700551 }
552 else
553 { //No concurrency case
Srikant Kuppa866893f2012-12-27 17:28:14 -0800554 smsLog( pMac, LOG2, FL("Queuing scan command (reason=%d, roamState=%d"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800555 " numOfChannels=%d)"),
Srikant Kuppa866893f2012-12-27 17:28:14 -0800556 pScanCmd->u.scanCmd.reason,
557 pMac->roam.neighborRoamInfo.neighborRoamState,
558 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -0700559 return csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
560 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700561
562 return ( status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700563}
564#endif
565
Jeff Johnsone7245742012-09-05 17:12:55 -0700566/* ---------------------------------------------------------------------------
567 \fn csrScan2GOnyRequest
568 \brief This function will update the scan request with only
Jeff Johnsonb88db982012-12-10 13:34:59 -0800569 2.4GHz valid channel list.
Jeff Johnsone7245742012-09-05 17:12:55 -0700570 \param pMac
571 \param pScanCmd
572 \param pScanRequest
573 \return None
574 -------------------------------------------------------------------------------*/
575static void csrScan2GOnyRequest(tpAniSirGlobal pMac,tSmeCmd *pScanCmd,
576 tCsrScanRequest *pScanRequest)
577{
578 tANI_U8 index, channelId, channelListSize = 0;
579 tANI_U8 channelList2G[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
580 static tANI_U8 validchannelList[CSR_MAX_2_4_GHZ_SUPPORTED_CHANNELS] = {0};
581
582 VOS_ASSERT(pScanCmd && pScanRequest);
Madan Mohan Koyyalamudi33ef6a22012-10-30 17:44:43 -0700583 /* To silence the KW tool null check is added */
584 if((pScanCmd == NULL) || (pScanRequest == NULL))
585 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800586 smsLog( pMac, LOGE, FL(" pScanCmd or pScanRequest is NULL "));
Madan Mohan Koyyalamudi33ef6a22012-10-30 17:44:43 -0700587 return;
588 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700589
590 if (pScanCmd->u.scanCmd.scanID ||
591 (eCSR_SCAN_REQUEST_FULL_SCAN != pScanRequest->requestType))
592 return;
593
594 //Contsruct valid Supported 2.4 GHz Channel List
595 for( index = 0; index < ARRAY_SIZE(channelList2G); index++ )
596 {
597 channelId = channelList2G[index];
598 if ( csrIsSupportedChannel( pMac, channelId ) )
599 {
600 validchannelList[channelListSize++] = channelId;
601 }
602 }
603
604 pScanRequest->ChannelInfo.numOfChannels = channelListSize;
605 pScanRequest->ChannelInfo.ChannelList = validchannelList;
606}
607
Jeff Johnson295189b2012-06-20 16:38:30 -0700608eHalStatus csrScanRequest(tpAniSirGlobal pMac, tANI_U16 sessionId,
609 tCsrScanRequest *pScanRequest, tANI_U32 *pScanRequestID,
610 csrScanCompleteCallback callback, void *pContext)
611{
612 eHalStatus status = eHAL_STATUS_FAILURE;
613 tSmeCmd *pScanCmd = NULL;
Madan Mohan Koyyalamudicb90bb22012-10-30 18:24:43 -0700614 eCsrConnectState ConnectState;
Deepthi Gowrie11da8c2016-02-04 18:18:39 +0530615
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800616 if(pScanRequest == NULL)
617 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800618 smsLog( pMac, LOGE, FL(" pScanRequest is NULL"));
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800619 VOS_ASSERT(0);
Kaushik, Sushant488df382014-03-05 11:43:47 +0530620 return eHAL_STATUS_FAILURE ;
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800621 }
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700622
Kiet Lamd1f3dc82013-11-05 20:45:04 +0530623 /* During group formation, the P2P client scans for GO with the specific SSID.
624 * There will be chances of GO switching to other channels because of scan or
625 * to STA channel in case of STA+GO MCC scenario. So to increase the possibility
626 * of client to find the GO, the dwell time of scan is increased to 100ms.
627 */
628 if(pScanRequest->p2pSearch)
629 {
Rashmi Ramanna6f7931c2013-12-20 09:04:12 +0530630 if(pScanRequest->SSIDs.numOfSSIDs)
Kiet Lamd1f3dc82013-11-05 20:45:04 +0530631 {
Rashmi Ramanna6f7931c2013-12-20 09:04:12 +0530632 //If the scan request is for specific SSId the length of SSID will be
633 //greater than 7 as SSID for p2p search contains "DIRECT-")
634 if(pScanRequest->SSIDs.SSIDList->SSID.length > DIRECT_SSID_LEN)
635 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530636 smsLog( pMac, LOG1, FL("P2P: Increasing the min and max Dwell"
637 " time to %d for specific SSID scan %.*s"),
638 MAX_CHN_TIME_TO_FIND_GO,
639 pScanRequest->SSIDs.SSIDList->SSID.length,
640 pScanRequest->SSIDs.SSIDList->SSID.ssId);
Rashmi Ramanna6f7931c2013-12-20 09:04:12 +0530641 pScanRequest->maxChnTime = MAX_CHN_TIME_TO_FIND_GO;
642 pScanRequest->minChnTime = MIN_CHN_TIME_TO_FIND_GO;
643 }
Kiet Lamd1f3dc82013-11-05 20:45:04 +0530644 }
645 }
646
Jeff Johnson295189b2012-06-20 16:38:30 -0700647 do
648 {
649 if(pMac->scan.fScanEnable)
650 {
651 pScanCmd = csrGetCommandBuffer(pMac);
652 if(pScanCmd)
653 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530654 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -0700655 pScanCmd->command = eSmeCommandScan;
656 pScanCmd->sessionId = sessionId;
657 pScanCmd->u.scanCmd.callback = callback;
658 pScanCmd->u.scanCmd.pContext = pContext;
659 if(eCSR_SCAN_REQUEST_11D_SCAN == pScanRequest->requestType)
660 {
661 pScanCmd->u.scanCmd.reason = eCsrScan11d1;
662 }
663 else if((eCSR_SCAN_REQUEST_FULL_SCAN == pScanRequest->requestType) ||
664 (eCSR_SCAN_P2P_DISCOVERY == pScanRequest->requestType)
665#ifdef SOFTAP_CHANNEL_RANGE
666 ||(eCSR_SCAN_SOFTAP_CHANNEL_RANGE == pScanRequest->requestType)
667#endif
668 )
669 {
670 pScanCmd->u.scanCmd.reason = eCsrScanUserRequest;
671 }
672 else if(eCSR_SCAN_HO_BG_SCAN == pScanRequest->requestType)
673 {
674 pScanCmd->u.scanCmd.reason = eCsrScanBgScan;
675 }
676 else if(eCSR_SCAN_HO_PROBE_SCAN == pScanRequest->requestType)
677 {
678 pScanCmd->u.scanCmd.reason = eCsrScanProbeBss;
679 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700680 else if(eCSR_SCAN_P2P_FIND_PEER == pScanRequest->requestType)
681 {
682 pScanCmd->u.scanCmd.reason = eCsrScanP2PFindPeer;
683 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700684 else
685 {
686 pScanCmd->u.scanCmd.reason = eCsrScanIdleScan;
687 }
688 if(pScanRequest->minChnTime == 0 && pScanRequest->maxChnTime == 0)
689 {
690 //The caller doesn't set the time correctly. Set it here
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530691 csrSetDefaultScanTiming(pMac, pScanRequest->scanType,
692 pScanRequest);
693 smsLog(pMac, LOG1, FL("Setting default min %d and max %d"
694 " ChnTime"), pScanRequest->minChnTime,
695 pScanRequest->maxChnTime);
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700696 }
697#ifdef WLAN_AP_STA_CONCURRENCY
698 if(pScanRequest->restTime == 0)
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800699 {
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700700 //Need to set restTime only if at least one session is connected
701 if(csrIsAnySessionConnected(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -0700702 {
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700703 pScanRequest->restTime = pMac->roam.configParam.nRestTimeConc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700704 }
705 }
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700706#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -0700707 /*For Standalone wlan : channel time will remain the same.
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530708 For BTC with A2DP up: Channel time = Channel time * 2, if station is not already associated.
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800709 This has been done to provide a larger scan window for faster connection during btc.Else Scan is seen
710 to take a long time.
711 For BTC with A2DP up: Channel time will not be doubled, if station is already associated.
712 */
Jeff Johnson32d95a32012-09-10 13:15:23 -0700713 status = csrRoamGetConnectState(pMac,sessionId,&ConnectState);
Srinivas Girigowdac84c57c2013-02-19 17:41:56 -0800714 if (HAL_STATUS_SUCCESS(status) &&
715 pMac->btc.fA2DPUp &&
Jeff Johnson32d95a32012-09-10 13:15:23 -0700716 (eCSR_ASSOC_STATE_TYPE_INFRA_ASSOCIATED != ConnectState) &&
717 (eCSR_ASSOC_STATE_TYPE_IBSS_CONNECTED != ConnectState))
718 {
719 pScanRequest->maxChnTime = pScanRequest->maxChnTime << 1;
720 pScanRequest->minChnTime = pScanRequest->minChnTime << 1;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530721 smsLog( pMac, LOG1, FL("BTC A2DP up, doubling max and min"
722 " ChnTime (Max=%d Min=%d)"),
723 pScanRequest->maxChnTime,
724 pScanRequest->minChnTime);
Jeff Johnson32d95a32012-09-10 13:15:23 -0700725 }
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800726
Kiet Lam64c1b492013-07-12 13:56:44 +0530727 pScanRequest->maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
728 pScanRequest->minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700729 //Need to make the following atomic
730 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
731
732 if(pScanRequestID)
733 {
734 *pScanRequestID = pScanCmd->u.scanCmd.scanID;
735 }
736
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800737 // If it is the first scan request from HDD, CSR checks if it is for 11d.
Jeff Johnson295189b2012-06-20 16:38:30 -0700738 // If it is not, CSR will save the scan request in the pending cmd queue
739 // & issue an 11d scan request to PE.
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800740 if (((0 == pScanCmd->u.scanCmd.scanID)
Jeff Johnson295189b2012-06-20 16:38:30 -0700741 && (eCSR_SCAN_REQUEST_11D_SCAN != pScanRequest->requestType))
742#ifdef SOFTAP_CHANNEL_RANGE
743 && (eCSR_SCAN_SOFTAP_CHANNEL_RANGE != pScanRequest->requestType)
744#endif
745 && (eANI_BOOLEAN_FALSE == pMac->scan.fEnableBypass11d)
746 )
747 {
748 tSmeCmd *p11dScanCmd;
749 tCsrScanRequest scanReq;
750 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
751
Kiet Lam64c1b492013-07-12 13:56:44 +0530752 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -0700753
754 p11dScanCmd = csrGetCommandBuffer(pMac);
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800755 if (p11dScanCmd)
Jeff Johnson295189b2012-06-20 16:38:30 -0700756 {
757 tANI_U32 numChn = pMac->scan.baseChannels.numChannels;
758
Kiet Lam64c1b492013-07-12 13:56:44 +0530759 vos_mem_set(&p11dScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
760 pChnInfo->ChannelList = vos_mem_malloc(numChn);
761 if ( NULL == pChnInfo->ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -0700762 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530763 smsLog(pMac, LOGE, FL("Failed to allocate memory"));
764 status = eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -0700765 break;
766 }
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530767 vos_mem_copy(pChnInfo->ChannelList,
768 pMac->scan.baseChannels.channelList,
769 numChn);
Jeff Johnson295189b2012-06-20 16:38:30 -0700770 pChnInfo->numOfChannels = (tANI_U8)numChn;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530771
Jeff Johnson295189b2012-06-20 16:38:30 -0700772 p11dScanCmd->command = eSmeCommandScan;
Mihir Shetefc7ff5b2014-01-27 11:30:05 +0530773 p11dScanCmd->u.scanCmd.callback = pMac->scan.callback11dScanDone;
Jeff Johnson295189b2012-06-20 16:38:30 -0700774 p11dScanCmd->u.scanCmd.pContext = NULL;
c_hpothu0d5a7352014-03-22 12:30:25 +0530775 p11dScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID;
Jeff Johnson295189b2012-06-20 16:38:30 -0700776 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
777
778 if ( csrIs11dSupported(pMac) )
779 {
c_hpothudbefd3e2014-04-28 15:59:47 +0530780 scanReq.scanType = eSIR_PASSIVE_SCAN;
Jeff Johnson295189b2012-06-20 16:38:30 -0700781 scanReq.requestType = eCSR_SCAN_REQUEST_11D_SCAN;
782 p11dScanCmd->u.scanCmd.reason = eCsrScan11d1;
783 scanReq.maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
784 scanReq.minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
785 }
786 else
787 {
c_hpothudbefd3e2014-04-28 15:59:47 +0530788 scanReq.scanType = pScanRequest->scanType;
Jeff Johnson295189b2012-06-20 16:38:30 -0700789 scanReq.requestType = eCSR_SCAN_IDLE_MODE_SCAN;
790 p11dScanCmd->u.scanCmd.reason = eCsrScanIdleScan;
791 scanReq.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
792 scanReq.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800793
Madan Mohan Koyyalamudi04a65f02013-07-26 13:58:38 +0530794 scanReq.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
795 scanReq.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700796 }
c_hpothu059edb02014-03-12 21:44:28 +0530797 if (pMac->roam.configParam.nInitialDwellTime)
798 {
799 scanReq.maxChnTime =
800 pMac->roam.configParam.nInitialDwellTime;
801 smsLog(pMac, LOG1, FL("11d scan, updating"
802 "dwell time for first scan %u"),
803 scanReq.maxChnTime);
804 }
Deepthi Gowrie11da8c2016-02-04 18:18:39 +0530805 if ((pScanCmd->u.scanCmd.reason == eCsrScanUserRequest)
806 && !(pScanRequest->p2pSearch)
Gupta, Kapilb79cda32015-12-30 20:36:33 +0530807 &&(pScanRequest->ChannelInfo.numOfChannels
808 < pMac->roam.configParam.
809 max_chan_for_dwell_time_cfg))
810 {
811 pScanRequest->maxChnTime =
812 pScanRequest->maxChnTime << 1;
813 pScanRequest->minChnTime =
814 pScanRequest->minChnTime << 1;
815 smsLog(pMac, LOG1,
816 FL("Double ChnTime (Max=%d Min=%d) numOfChannels=%d max_chan_for_dwell_time_cfg=%d"),
817 pScanRequest->maxChnTime,
818 pScanRequest->minChnTime,
819 pScanRequest->ChannelInfo.numOfChannels,
820 pMac->roam.configParam.
821 max_chan_for_dwell_time_cfg);
822 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700823
Jeff Johnson295189b2012-06-20 16:38:30 -0700824 status = csrScanCopyRequest(pMac, &p11dScanCmd->u.scanCmd.u.scanRequest, &scanReq);
825 //Free the channel list
Kiet Lam64c1b492013-07-12 13:56:44 +0530826 vos_mem_free(pChnInfo->ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -0700827 pChnInfo->ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -0700828
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800829 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700830 {
krunal soni5f112f02013-11-25 15:00:11 -0800831 pMac->scan.scanProfile.numOfChannels =
832 p11dScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -0700833 //Start process the command
834#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +0530835 if (!pMac->fScanOffload)
836 status = csrQueueScanRequest(pMac, p11dScanCmd);
837 else
838 status = csrQueueSmeCommand(pMac, p11dScanCmd,
839 eANI_BOOLEAN_FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -0700840#else
841 status = csrQueueSmeCommand(pMac, p11dScanCmd, eANI_BOOLEAN_FALSE);
842#endif
843 if( !HAL_STATUS_SUCCESS( status ) )
844 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530845 smsLog(pMac, LOGE, FL("Failed to send message"
846 " status = %d"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -0700847 break;
848 }
849 }
850 else
851 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530852 smsLog(pMac, LOGE, FL("csrScanCopyRequest failed"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700853 break;
854 }
855 }
856 else
857 {
858 //error
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530859 smsLog( pMac, LOGE, FL("p11dScanCmd failed") );
Jeff Johnson295189b2012-06-20 16:38:30 -0700860 break;
861 }
862 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700863
864 //Scan only 2G Channels if set in ini file
865 //This is mainly to reduce the First Scan duration
866 //Once we turn on Wifi
867 if(pMac->scan.fFirstScanOnly2GChnl)
868 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800869 smsLog( pMac, LOG1, FL("Scanning only 2G Channels during first scan"));
Jeff Johnsone7245742012-09-05 17:12:55 -0700870 csrScan2GOnyRequest(pMac, pScanCmd, pScanRequest);
871 }
872
c_hpothu059edb02014-03-12 21:44:28 +0530873 if (pMac->roam.configParam.nInitialDwellTime)
874 {
875 pScanRequest->maxChnTime =
876 pMac->roam.configParam.nInitialDwellTime;
877 pMac->roam.configParam.nInitialDwellTime = 0;
878 smsLog(pMac, LOG1,
879 FL("updating dwell time for first scan %u"),
880 pScanRequest->maxChnTime);
881 }
882
Deepthi Gowrie11da8c2016-02-04 18:18:39 +0530883 if ((pScanCmd->u.scanCmd.reason == eCsrScanUserRequest)
884 && !(pScanRequest->p2pSearch)
Gupta, Kapilb79cda32015-12-30 20:36:33 +0530885 && (pScanRequest->ChannelInfo.numOfChannels
886 < pMac->roam.configParam.max_chan_for_dwell_time_cfg))
887 {
888 pScanRequest->maxChnTime = pScanRequest->maxChnTime << 1;
889 pScanRequest->minChnTime = pScanRequest->minChnTime << 1;
890 smsLog(pMac, LOG1,
891 FL("Double ChnTime (Max=%d Min=%d) numOfChannels=%d max_chan_for_dwell_time_cfg=%d"),
892 pScanRequest->maxChnTime,
893 pScanRequest->minChnTime,
894 pScanRequest->ChannelInfo.numOfChannels,
895 pMac->roam.configParam.max_chan_for_dwell_time_cfg);
896 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700897 status = csrScanCopyRequest(pMac, &pScanCmd->u.scanCmd.u.scanRequest, pScanRequest);
898 if(HAL_STATUS_SUCCESS(status))
899 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530900 tCsrScanRequest *pTempScanReq =
901 &pScanCmd->u.scanCmd.u.scanRequest;
krunal soni5f112f02013-11-25 15:00:11 -0800902 pMac->scan.scanProfile.numOfChannels =
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530903 pTempScanReq->ChannelInfo.numOfChannels;
krunal soni5f112f02013-11-25 15:00:11 -0800904
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530905 smsLog( pMac, LOG1, FL(" SId=%d scanId=%d"
906 " Scan reason=%u numSSIDs=%d"
907 " numChan=%d P2P search=%d minCT=%d maxCT=%d"
908 " minCBtc=%d maxCBtx=%d"),
909 sessionId, pScanCmd->u.scanCmd.scanID,
910 pScanCmd->u.scanCmd.reason,
911 pTempScanReq->SSIDs.numOfSSIDs,
912 pTempScanReq->ChannelInfo.numOfChannels,
913 pTempScanReq->p2pSearch,
914 pTempScanReq->minChnTime,
915 pTempScanReq->maxChnTime,
916 pTempScanReq->minChnTimeBtc,
917 pTempScanReq->maxChnTimeBtc );
Jeff Johnson295189b2012-06-20 16:38:30 -0700918 //Start process the command
919#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +0530920 if (!pMac->fScanOffload)
921 status = csrQueueScanRequest(pMac,pScanCmd);
922 else
923 status = csrQueueSmeCommand(pMac, pScanCmd,
924 eANI_BOOLEAN_FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -0700925#else
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530926 status = csrQueueSmeCommand(pMac, pScanCmd,
927 eANI_BOOLEAN_FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -0700928#endif
929 if( !HAL_STATUS_SUCCESS( status ) )
930 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800931 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700932 break;
933 }
934 }
935 else
936 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800937 smsLog( pMac, LOGE, FL(" fail to copy request status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700938 break;
939 }
940 }
941 else
942 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800943 smsLog( pMac, LOGE, FL(" pScanCmd is NULL"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700944 break;
945 }
946 }
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530947 else
948 {
949 smsLog( pMac, LOGE, FL("SId: %d Scanning not enabled"
950 " Scan type=%u, numOfSSIDs=%d P2P search=%d"),
951 sessionId, pScanRequest->requestType,
952 pScanRequest->SSIDs.numOfSSIDs,
953 pScanRequest->p2pSearch );
954 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700955 } while(0);
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530956
957
Jeff Johnson295189b2012-06-20 16:38:30 -0700958 if(!HAL_STATUS_SUCCESS(status) && pScanCmd)
959 {
960 if( eCsrScanIdleScan == pScanCmd->u.scanCmd.reason )
961 {
962 //Set the flag back for restarting idle scan
963 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
964 }
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530965 smsLog( pMac, LOGE, FL(" SId: %d Failed with status=%d"
966 " Scan reason=%u numOfSSIDs=%d"
967 " P2P search=%d scanId=%d"),
968 sessionId, status, pScanCmd->u.scanCmd.reason,
969 pScanRequest->SSIDs.numOfSSIDs, pScanRequest->p2pSearch,
970 pScanCmd->u.scanCmd.scanID );
Jeff Johnson295189b2012-06-20 16:38:30 -0700971 csrReleaseCommandScan(pMac, pScanCmd);
972 }
973
974 return (status);
975}
976
977
978eHalStatus csrScanRequestResult(tpAniSirGlobal pMac)
979{
980 eHalStatus status = eHAL_STATUS_SUCCESS;
981 tSmeCmd *pScanCmd;
982
983 if(pMac->scan.fScanEnable)
984 {
985 pScanCmd = csrGetCommandBuffer(pMac);
986 if(pScanCmd)
987 {
988 pScanCmd->command = eSmeCommandScan;
Kiet Lam64c1b492013-07-12 13:56:44 +0530989 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -0700990 pScanCmd->u.scanCmd.callback = NULL;
991 pScanCmd->u.scanCmd.pContext = NULL;
992 pScanCmd->u.scanCmd.reason = eCsrScanGetResult;
993 //Need to make the following atomic
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -0700994 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID; //let it wrap around
Jeff Johnson295189b2012-06-20 16:38:30 -0700995 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
996 if( !HAL_STATUS_SUCCESS( status ) )
997 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800998 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700999 csrReleaseCommandScan(pMac, pScanCmd);
1000 }
1001 }
1002 else
1003 {
1004 //log error
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001005 smsLog(pMac, LOGE, FL("can not obtain a common buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001006 status = eHAL_STATUS_RESOURCES;
1007 }
1008 }
1009
1010 return (status);
1011}
1012
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07001013#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
1014eHalStatus csrScanRequestLfrResult(tpAniSirGlobal pMac, tANI_U32 sessionId,
1015 csrScanCompleteCallback callback, void *pContext)
1016{
1017 eHalStatus status = eHAL_STATUS_SUCCESS;
1018 tSmeCmd *pScanCmd;
1019
1020 if (pMac->scan.fScanEnable)
1021 {
1022 pScanCmd = csrGetCommandBuffer(pMac);
1023 if (pScanCmd)
1024 {
1025 pScanCmd->command = eSmeCommandScan;
1026 pScanCmd->sessionId = sessionId;
Kiet Lam64c1b492013-07-12 13:56:44 +05301027 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07001028 pScanCmd->u.scanCmd.callback = callback;
1029 pScanCmd->u.scanCmd.pContext = pContext;
1030 pScanCmd->u.scanCmd.reason = eCsrScanGetLfrResult;
1031 //Need to make the following atomic
1032 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID; //let it wrap around
1033 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_TRUE);
1034 if ( !HAL_STATUS_SUCCESS( status ) )
1035 {
1036 smsLog( pMac, LOGE, FL(" fail to send message status = %d\n"), status );
1037 csrReleaseCommandScan(pMac, pScanCmd);
1038 }
1039 }
1040 else
1041 {
1042 //log error
1043 smsLog(pMac, LOGE, FL("can not obtain a common buffer\n"));
1044 status = eHAL_STATUS_RESOURCES;
1045 }
1046 }
1047
1048 return (status);
1049}
1050#endif //WLAN_FEATURE_ROAM_SCAN_OFFLOAD
Jeff Johnson295189b2012-06-20 16:38:30 -07001051
1052eHalStatus csrScanAllChannels(tpAniSirGlobal pMac, eCsrRequestType reqType)
1053{
1054 eHalStatus status = eHAL_STATUS_SUCCESS;
1055 tANI_U32 scanId;
1056 tCsrScanRequest scanReq;
1057
Kiet Lam64c1b492013-07-12 13:56:44 +05301058 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001059 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
1060 scanReq.scanType = eSIR_ACTIVE_SCAN;
1061 scanReq.requestType = reqType;
1062 scanReq.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1063 scanReq.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001064 scanReq.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1065 scanReq.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001066 //Scan with invalid sessionId.
1067 //This results in SME using the first available session to scan.
1068 status = csrScanRequest(pMac, CSR_SESSION_ID_INVALID, &scanReq,
1069 &scanId, NULL, NULL);
1070
1071 return (status);
1072}
1073
1074
1075
1076
1077eHalStatus csrIssueRoamAfterLostlinkScan(tpAniSirGlobal pMac, tANI_U32 sessionId, eCsrRoamReason reason)
1078{
1079 eHalStatus status = eHAL_STATUS_FAILURE;
1080 tScanResultHandle hBSSList = NULL;
1081 tCsrScanResultFilter *pScanFilter = NULL;
1082 tANI_U32 roamId = 0;
1083 tCsrRoamProfile *pProfile = NULL;
1084 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1085
Jeff Johnson32d95a32012-09-10 13:15:23 -07001086 if(!pSession)
1087 {
1088 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1089 return eHAL_STATUS_FAILURE;
1090 }
1091
Jeff Johnson295189b2012-06-20 16:38:30 -07001092 do
1093 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001094 smsLog(pMac, LOG1, " csrIssueRoamAfterLostlinkScan called");
Jeff Johnson295189b2012-06-20 16:38:30 -07001095 if(pSession->fCancelRoaming)
1096 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001097 smsLog(pMac, LOGW, " lostlink roaming is cancelled");
Jeff Johnson295189b2012-06-20 16:38:30 -07001098 csrScanStartIdleScan(pMac);
1099 status = eHAL_STATUS_SUCCESS;
1100 break;
1101 }
1102 //Here is the profile we need to connect to
Kiet Lam64c1b492013-07-12 13:56:44 +05301103 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1104 if ( NULL == pScanFilter)
1105 status = eHAL_STATUS_FAILURE;
1106 else
1107 status = eHAL_STATUS_SUCCESS;
1108 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001109 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301110 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001111 if(NULL == pSession->pCurRoamProfile)
1112 {
1113 pScanFilter->EncryptionType.numEntries = 1;
1114 pScanFilter->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_NONE;
1115 }
1116 else
1117 {
1118 //We have to make a copy of pCurRoamProfile because it will be free inside csrRoamIssueConnect
Kiet Lam64c1b492013-07-12 13:56:44 +05301119 pProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1120 if ( NULL == pProfile )
1121 status = eHAL_STATUS_FAILURE;
1122 else
1123 status = eHAL_STATUS_SUCCESS;
1124 if (!HAL_STATUS_SUCCESS(status))
1125 break;
1126 vos_mem_set(pProfile, sizeof(tCsrRoamProfile), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001127 status = csrRoamCopyProfile(pMac, pProfile, pSession->pCurRoamProfile);
1128 if(!HAL_STATUS_SUCCESS(status))
1129 break;
1130 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1131 }//We have a profile
1132 roamId = GET_NEXT_ROAM_ID(&pMac->roam);
1133 if(HAL_STATUS_SUCCESS(status))
1134 {
1135 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1136 if(HAL_STATUS_SUCCESS(status))
1137 {
1138 if(eCsrLostLink1 == reason)
1139 {
1140 //we want to put the last connected BSS to the very beginning, if possible
1141 csrMoveBssToHeadFromBSSID(pMac, &pSession->connectedProfile.bssid, hBSSList);
1142 }
1143 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList, reason,
1144 roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1145 if(!HAL_STATUS_SUCCESS(status))
1146 {
1147 csrScanResultPurge(pMac, hBSSList);
1148 }
1149 }//Have scan result
1150 }
1151 }while(0);
1152 if(pScanFilter)
1153 {
1154 //we need to free memory for filter if profile exists
1155 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301156 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001157 }
1158 if(NULL != pProfile)
1159 {
1160 csrReleaseProfile(pMac, pProfile);
Kiet Lam64c1b492013-07-12 13:56:44 +05301161 vos_mem_free(pProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07001162 }
1163
1164 return (status);
1165}
1166
1167
Ratheesh S Pece1f832015-07-25 15:50:25 +05301168eHalStatus csrScanGetScanChnInfo(tpAniSirGlobal pMac, tSmeCmd *pCommand)
Jeff Johnson295189b2012-06-20 16:38:30 -07001169{
1170 eHalStatus status = eHAL_STATUS_SUCCESS;
1171 tSmeCmd *pScanCmd;
1172
1173 if(pMac->scan.fScanEnable)
1174 {
1175 pScanCmd = csrGetCommandBuffer(pMac);
1176 if(pScanCmd)
1177 {
1178 pScanCmd->command = eSmeCommandScan;
Kiet Lam64c1b492013-07-12 13:56:44 +05301179 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001180 pScanCmd->u.scanCmd.reason = eCsrScanGetScanChnInfo;
1181 //Need to make the following atomic
1182 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Ratheesh S Pece1f832015-07-25 15:50:25 +05301183 pScanCmd->sessionId = pCommand->sessionId;
1184 if( pCommand->u.scanCmd.reason == eCsrScanUserRequest)
1185 {
1186 pScanCmd->u.scanCmd.callback = NULL;
1187 pScanCmd->u.scanCmd.pContext = NULL;
1188 } else {
1189 pScanCmd->u.scanCmd.callback = pCommand->u.scanCmd.callback;
1190 pScanCmd->u.scanCmd.pContext = pCommand->u.scanCmd.pContext;
1191 pScanCmd->u.scanCmd.abortScanIndication =
1192 pCommand->u.scanCmd.abortScanIndication;
1193 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001194 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
1195 if( !HAL_STATUS_SUCCESS( status ) )
1196 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001197 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001198 csrReleaseCommandScan(pMac, pScanCmd);
1199 }
1200 }
1201 else
1202 {
1203 //log error
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001204 smsLog(pMac, LOGE, FL("can not obtain a common buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001205 status = eHAL_STATUS_RESOURCES;
1206 }
1207 }
1208
1209 return (status);
1210}
1211
1212
1213eHalStatus csrScanHandleFailedLostlink1(tpAniSirGlobal pMac, tANI_U32 sessionId)
1214{
1215 eHalStatus status = eHAL_STATUS_FAILURE;
1216 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1217
Jeff Johnson32d95a32012-09-10 13:15:23 -07001218 if(!pSession)
1219 {
1220 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1221 return eHAL_STATUS_FAILURE;
1222 }
1223
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001224 smsLog(pMac, LOGW, " Lostlink scan 1 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001225 if(pSession->fCancelRoaming)
1226 {
1227 csrScanStartIdleScan(pMac);
1228 }
1229 else if(pSession->pCurRoamProfile)
1230 {
1231 //We fail lostlink1 but there may be other BSS in the cached result fit the profile. Give it a try first
1232 if(pSession->pCurRoamProfile->SSIDs.numOfSSIDs == 0 ||
1233 pSession->pCurRoamProfile->SSIDs.numOfSSIDs > 1)
1234 {
1235 //try lostlink scan2
1236 status = csrScanRequestLostLink2(pMac, sessionId);
1237 }
1238 else if(!pSession->pCurRoamProfile->ChannelInfo.ChannelList ||
1239 pSession->pCurRoamProfile->ChannelInfo.ChannelList[0] == 0)
1240 {
1241 //go straight to lostlink scan3
1242 status = csrScanRequestLostLink3(pMac, sessionId);
1243 }
1244 else
1245 {
1246 //we are done with lostlink
1247 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1248 {
1249 csrScanStartIdleScan(pMac);
1250 }
1251 status = eHAL_STATUS_SUCCESS;
1252 }
1253 }
1254 else
1255 {
1256 status = csrScanRequestLostLink3(pMac, sessionId);
1257 }
1258
1259 return (status);
1260}
1261
1262
1263
1264eHalStatus csrScanHandleFailedLostlink2(tpAniSirGlobal pMac, tANI_U32 sessionId)
1265{
1266 eHalStatus status = eHAL_STATUS_FAILURE;
1267 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1268
Jeff Johnson32d95a32012-09-10 13:15:23 -07001269 if(!pSession)
1270 {
1271 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1272 return eHAL_STATUS_FAILURE;
1273 }
1274
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001275 smsLog(pMac, LOGW, " Lostlink scan 2 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001276 if(pSession->fCancelRoaming)
1277 {
1278 csrScanStartIdleScan(pMac);
1279 }
1280 else if(!pSession->pCurRoamProfile || !pSession->pCurRoamProfile->ChannelInfo.ChannelList ||
1281 pSession->pCurRoamProfile->ChannelInfo.ChannelList[0] == 0)
1282 {
1283 //try lostlink scan3
1284 status = csrScanRequestLostLink3(pMac, sessionId);
1285 }
1286 else
1287 {
1288 //we are done with lostlink
1289 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1290 {
1291 csrScanStartIdleScan(pMac);
1292 }
1293 }
1294
1295 return (status);
1296}
1297
1298
1299
1300eHalStatus csrScanHandleFailedLostlink3(tpAniSirGlobal pMac, tANI_U32 sessionId)
1301{
1302 eHalStatus status = eHAL_STATUS_SUCCESS;
1303
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001304 smsLog(pMac, LOGW, " Lostlink scan 3 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001305 if(eANI_BOOLEAN_TRUE == csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1306 {
1307 //we are done with lostlink
1308 csrScanStartIdleScan(pMac);
1309 }
1310
1311 return (status);
1312}
1313
1314
1315
1316
1317//Lostlink1 scan is to actively scan the last connected profile's SSID on all matched BSS channels.
1318//If no roam profile (it should not), it is like lostlinkscan3
1319eHalStatus csrScanRequestLostLink1( tpAniSirGlobal pMac, tANI_U32 sessionId )
1320{
1321 eHalStatus status = eHAL_STATUS_SUCCESS;
1322 tSmeCmd *pCommand = NULL;
1323 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1324 tCsrScanResultFilter *pScanFilter = NULL;
1325 tScanResultHandle hBSSList = NULL;
1326 tCsrScanResultInfo *pScanResult = NULL;
1327 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1328
Jeff Johnson32d95a32012-09-10 13:15:23 -07001329 if(!pSession)
1330 {
1331 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1332 return eHAL_STATUS_FAILURE;
1333 }
1334
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001335 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001336 do
1337 {
1338 pCommand = csrGetCommandBuffer(pMac);
1339 if(!pCommand)
1340 {
1341 status = eHAL_STATUS_RESOURCES;
1342 break;
1343 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301344 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001345 pCommand->command = eSmeCommandScan;
1346 pCommand->sessionId = (tANI_U8)sessionId;
1347 pCommand->u.scanCmd.reason = eCsrScanLostLink1;
1348 pCommand->u.scanCmd.callback = NULL;
1349 pCommand->u.scanCmd.pContext = NULL;
1350 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1351 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001352 pCommand->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1353 pCommand->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001354 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
1355 if(pSession->connectedProfile.SSID.length)
1356 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301357 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList = vos_mem_malloc(sizeof(tCsrSSIDInfo));
1358 if ( NULL == pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList )
1359 status = eHAL_STATUS_FAILURE;
1360 else
1361 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001362 if(!HAL_STATUS_SUCCESS(status))
1363 {
1364 break;
1365 }
1366 pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 1;
Kiet Lam64c1b492013-07-12 13:56:44 +05301367 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID,
1368 &pSession->connectedProfile.SSID, sizeof(tSirMacSSid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001369 }
1370 else
1371 {
1372 pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 0;
1373 }
1374 if(pSession->pCurRoamProfile)
1375 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301376 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1377 if ( NULL == pScanFilter )
1378 status = eHAL_STATUS_FAILURE;
1379 else
1380 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001381 if(!HAL_STATUS_SUCCESS(status))
1382 {
1383 break;
1384 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301385 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001386 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
1387 if(!HAL_STATUS_SUCCESS(status))
1388 {
1389 break;
1390 }
1391 //Don't change variable status here because whether we can get result or not, the command goes to PE.
1392 //The status is also used to indicate whether the command is queued. Not success meaning not queue
1393 if(HAL_STATUS_SUCCESS((csrScanGetResult(pMac, pScanFilter, &hBSSList))) && hBSSList)
1394 {
1395 tANI_U8 i, nChn = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05301396 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList =
1397 vos_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
1398 if ( NULL == pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
1399 status = eHAL_STATUS_FAILURE;
1400 else
1401 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001402 if(!HAL_STATUS_SUCCESS(status))
1403 {
1404 break;
1405 }
1406 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) &&
1407 nChn < WNI_CFG_VALID_CHANNEL_LIST_LEN)
1408 {
1409 for(i = 0; i < nChn; i++)
1410 {
1411 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1412 pScanResult->BssDescriptor.channelId)
1413 {
1414 break;
1415 }
1416 }
1417 if(i == nChn)
1418 {
1419 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pScanResult->BssDescriptor.channelId;
1420 }
1421 }
1422 //Include the last connected BSS' channel
1423 if(csrRoamIsChannelValid(pMac, pSession->connectedProfile.operationChannel))
1424 {
1425 for(i = 0; i < nChn; i++)
1426 {
1427 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1428 pSession->connectedProfile.operationChannel)
1429 {
1430 break;
1431 }
1432 }
1433 if(i == nChn)
1434 {
1435 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pSession->connectedProfile.operationChannel;
1436 }
1437 }
1438 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nChn;
1439 }
1440 else
1441 {
1442 if(csrRoamIsChannelValid(pMac, pSession->connectedProfile.operationChannel))
1443 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301444 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(1);
1445 if ( NULL == pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
1446 status = eHAL_STATUS_FAILURE;
1447 else
1448 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001449 //just try the last connected channel
1450 if(HAL_STATUS_SUCCESS(status))
1451 {
1452 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[0] = pSession->connectedProfile.operationChannel;
1453 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 1;
1454 }
1455 else
1456 {
1457 break;
1458 }
1459 }
1460 }
1461 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301462 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001463 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
1464 if( !HAL_STATUS_SUCCESS( status ) )
1465 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001466 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001467 break;
1468 }
1469 } while( 0 );
1470
1471 if(!HAL_STATUS_SUCCESS(status))
1472 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001473 smsLog(pMac, LOGW, " csrScanRequestLostLink1 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001474 if(pCommand)
1475 {
1476 csrReleaseCommandScan(pMac, pCommand);
1477 }
1478 status = csrScanHandleFailedLostlink1( pMac, sessionId );
1479 }
1480 if(pScanFilter)
1481 {
1482 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301483 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001484 }
1485 if(hBSSList)
1486 {
1487 csrScanResultPurge(pMac, hBSSList);
1488 }
1489
1490 return( status );
1491}
1492
1493
1494//Lostlink2 scan is to actively scan the all SSIDs of the last roaming profile's on all matched BSS channels.
1495//Since MAC doesn't support multiple SSID, we scan all SSIDs and filter them afterwards
1496eHalStatus csrScanRequestLostLink2( tpAniSirGlobal pMac, tANI_U32 sessionId )
1497{
1498 eHalStatus status = eHAL_STATUS_SUCCESS;
1499 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1500 tCsrScanResultFilter *pScanFilter = NULL;
1501 tScanResultHandle hBSSList = NULL;
1502 tCsrScanResultInfo *pScanResult = NULL;
1503 tSmeCmd *pCommand = NULL;
1504 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1505
Jeff Johnson32d95a32012-09-10 13:15:23 -07001506 if(!pSession)
1507 {
1508 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1509 return eHAL_STATUS_FAILURE;
1510 }
1511
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001512 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001513 do
1514 {
1515 pCommand = csrGetCommandBuffer(pMac);
1516 if(!pCommand)
1517 {
1518 status = eHAL_STATUS_RESOURCES;
1519 break;
1520 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301521 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001522 pCommand->command = eSmeCommandScan;
1523 pCommand->sessionId = (tANI_U8)sessionId;
1524 pCommand->u.scanCmd.reason = eCsrScanLostLink2;
1525 pCommand->u.scanCmd.callback = NULL;
1526 pCommand->u.scanCmd.pContext = NULL;
1527 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1528 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001529 pCommand->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1530 pCommand->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001531 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
1532 if(pSession->pCurRoamProfile)
1533 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301534 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1535 if ( NULL == pScanFilter )
1536 status = eHAL_STATUS_FAILURE;
1537 else
1538 status = eHAL_STATUS_SUCCESS;
1539 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001540 {
1541 break;
1542 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301543 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001544 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
1545 if(!HAL_STATUS_SUCCESS(status))
1546 {
1547 break;
1548 }
1549 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1550 if(!HAL_STATUS_SUCCESS(status))
1551 {
1552 break;
1553 }
1554 if(hBSSList)
1555 {
1556 tANI_U8 i, nChn = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05301557 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList =
1558 vos_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
1559 if ( NULL == pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
1560 status = eHAL_STATUS_FAILURE;
1561 else
1562 status = eHAL_STATUS_SUCCESS;
1563 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001564 {
1565 break;
1566 }
1567 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) &&
1568 nChn < WNI_CFG_VALID_CHANNEL_LIST_LEN)
1569 {
1570 for(i = 0; i < nChn; i++)
1571 {
1572 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1573 pScanResult->BssDescriptor.channelId)
1574 {
1575 break;
1576 }
1577 }
1578 if(i == nChn)
1579 {
1580 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pScanResult->BssDescriptor.channelId;
1581 }
1582 }
1583 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nChn;
1584 }
1585 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301586 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001587 //Put to the head in pending queue
1588 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_TRUE);
1589 if( !HAL_STATUS_SUCCESS( status ) )
1590 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001591 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001592 break;
1593 }
1594 } while( 0 );
1595
1596 if(!HAL_STATUS_SUCCESS(status))
1597 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001598 smsLog(pMac, LOGW, " csrScanRequestLostLink2 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001599 if(pCommand)
1600 {
1601 csrReleaseCommandScan(pMac, pCommand);
1602 }
1603 status = csrScanHandleFailedLostlink2( pMac, sessionId );
1604 }
1605 if(pScanFilter)
1606 {
1607 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301608 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001609 }
1610 if(hBSSList)
1611 {
1612 csrScanResultPurge(pMac, hBSSList);
1613 }
1614
1615 return( status );
1616}
1617
1618
1619//To actively scan all valid channels
1620eHalStatus csrScanRequestLostLink3( tpAniSirGlobal pMac, tANI_U32 sessionId )
1621{
1622 eHalStatus status = eHAL_STATUS_SUCCESS;
1623 tSmeCmd *pCommand;
1624 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1625
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001626 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001627 do
1628 {
1629 pCommand = csrGetCommandBuffer(pMac);
1630 if(!pCommand)
1631 {
1632 status = eHAL_STATUS_RESOURCES;
1633 break;
1634 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301635 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001636 pCommand->command = eSmeCommandScan;
1637 pCommand->sessionId = (tANI_U8)sessionId;
1638 pCommand->u.scanCmd.reason = eCsrScanLostLink3;
1639 pCommand->u.scanCmd.callback = NULL;
1640 pCommand->u.scanCmd.pContext = NULL;
1641 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1642 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001643 pCommand->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1644 pCommand->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001645 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Kiet Lam64c1b492013-07-12 13:56:44 +05301646 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001647 //Put to the head of pending queue
1648 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_TRUE);
1649 if( !HAL_STATUS_SUCCESS( status ) )
1650 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001651 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001652 break;
1653 }
1654 } while( 0 );
1655 if(!HAL_STATUS_SUCCESS(status))
1656 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001657 smsLog(pMac, LOGW, " csrScanRequestLostLink3 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001658 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1659 {
1660 csrScanStartIdleScan(pMac);
1661 }
1662 if(pCommand)
1663 {
1664 csrReleaseCommandScan(pMac, pCommand);
1665 }
1666 }
1667
1668 return( status );
1669}
1670
1671
1672eHalStatus csrScanHandleSearchForSSID(tpAniSirGlobal pMac, tSmeCmd *pCommand)
1673{
1674 eHalStatus status = eHAL_STATUS_FAILURE;
1675 tScanResultHandle hBSSList = CSR_INVALID_SCANRESULT_HANDLE;
1676 tCsrScanResultFilter *pScanFilter = NULL;
1677 tCsrRoamProfile *pProfile = pCommand->u.scanCmd.pToRoamProfile;
1678 tANI_U32 sessionId = pCommand->sessionId;
Abhishek Singhd61b97a2015-12-17 15:23:52 +05301679 tCsrRoamSession *pSession = CSR_GET_SESSION(pMac, sessionId);
1680
Jeff Johnson295189b2012-06-20 16:38:30 -07001681 do
1682 {
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001683#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
1684 //if this scan is for LFR
1685 if(pMac->roam.neighborRoamInfo.uOsRequestedHandoff)
1686 {
1687 //notify LFR state m/c
1688 if(eHAL_STATUS_SUCCESS != csrNeighborRoamSssidScanDone(pMac, eHAL_STATUS_SUCCESS))
1689 {
Mukul Sharma20aa6582014-08-07 21:36:12 +05301690 csrNeighborRoamStartLfrScan(pMac, REASON_OS_REQUESTED_ROAMING_NOW);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001691 }
1692 status = eHAL_STATUS_SUCCESS;
1693 break;
1694 }
1695#endif
Abhishek Singhd61b97a2015-12-17 15:23:52 +05301696 if (!pSession)
1697 {
1698 smsLog(pMac, LOGE, FL("session %d not found"), sessionId);
1699 break;
1700 }
Abhishek Singhd18028d2016-02-11 17:45:54 +05301701 /* If Disconnect is already issued from HDD no need to issue connect
1702 * pSession->abortConnection will not be set in case of try
1703 * disconnect or hdd stop adaptor use connectState for these cases.
1704 */
1705 if (pSession->abortConnection ||
1706 (pMac->roam.roamSession[sessionId].connectState ==
1707 eCSR_ASSOC_STATE_TYPE_INFRA_DISCONNECTING))
Abhishek Singhd61b97a2015-12-17 15:23:52 +05301708 {
1709 smsLog(pMac, LOGE,
1710 FL("Disconnect in progress, no need to issue connect"));
1711 break;
1712 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001713 //If there is roam command waiting, ignore this roam because the newer roam command is the one to execute
1714 if(csrIsRoamCommandWaitingForSession(pMac, sessionId))
1715 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001716 smsLog(pMac, LOGW, FL(" aborts because roam command waiting"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001717 break;
1718 }
1719 if(pProfile == NULL)
1720 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301721 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1722 if ( NULL == pScanFilter )
1723 status = eHAL_STATUS_FAILURE;
1724 else
1725 status = eHAL_STATUS_SUCCESS;
1726 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001727 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301728 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001729 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1730 if(!HAL_STATUS_SUCCESS(status))
1731 break;
1732 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1733 if(!HAL_STATUS_SUCCESS(status))
1734 break;
1735 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList, eCsrHddIssued,
1736 pCommand->u.scanCmd.roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1737 if(!HAL_STATUS_SUCCESS(status))
1738 {
1739 break;
1740 }
1741 }while(0);
1742 if(!HAL_STATUS_SUCCESS(status))
1743 {
1744 if(CSR_INVALID_SCANRESULT_HANDLE != hBSSList)
1745 {
1746 csrScanResultPurge(pMac, hBSSList);
1747 }
1748 //We haven't done anything to this profile
Abhishek Singh72c2f4e2016-07-22 11:25:43 +05301749 csrRoamCallCallback(pMac, sessionId, NULL,
1750 pCommand->u.scanCmd.roamId,
1751 eCSR_ROAM_ASSOCIATION_FAILURE,
1752 eCSR_ROAM_RESULT_SCAN_FOR_SSID_FAILURE);
Jeff Johnson295189b2012-06-20 16:38:30 -07001753 //In case we have nothing else to do, restart idle scan
1754 if(csrIsConnStateDisconnected(pMac, sessionId) && !csrIsRoamCommandWaiting(pMac))
1755 {
1756 status = csrScanStartIdleScan(pMac);
1757 }
1758#ifdef FEATURE_WLAN_BTAMP_UT_RF
1759 //In case of WDS station, let it retry.
1760 if( CSR_IS_WDS_STA(pProfile) )
1761 {
1762 //Save the roma profile so we can retry
1763 csrFreeRoamProfile( pMac, sessionId );
Kiet Lam64c1b492013-07-12 13:56:44 +05301764 pSession->pCurRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1765 if ( NULL != pSession->pCurRoamProfile )
Jeff Johnson295189b2012-06-20 16:38:30 -07001766 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301767 vos_mem_set(pSession->pCurRoamProfilee, sizeof(tCsrRoamProfile), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001768 csrRoamCopyProfile(pMac, pSession->pCurRoamProfile, pProfile);
1769 }
1770 csrRoamStartJoinRetryTimer(pMac, sessionId, CSR_JOIN_RETRY_TIMEOUT_PERIOD);
1771 }
1772#endif
1773 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301774 if (pScanFilter)
Jeff Johnson295189b2012-06-20 16:38:30 -07001775 {
1776 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301777 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001778 }
1779
1780 return (status);
1781}
1782
1783
1784eHalStatus csrScanHandleSearchForSSIDFailure(tpAniSirGlobal pMac, tSmeCmd *pCommand)
1785{
1786 eHalStatus status = eHAL_STATUS_SUCCESS;
1787 tANI_U32 sessionId = pCommand->sessionId;
1788 tCsrRoamProfile *pProfile = pCommand->u.scanCmd.pToRoamProfile;
1789 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001790#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
1791 //if this scan is for LFR
1792 if(pMac->roam.neighborRoamInfo.uOsRequestedHandoff)
1793 {
1794 //notify LFR state m/c
1795 if(eHAL_STATUS_SUCCESS != csrNeighborRoamSssidScanDone(pMac, eHAL_STATUS_FAILURE))
1796 {
Mukul Sharma20aa6582014-08-07 21:36:12 +05301797 csrNeighborRoamStartLfrScan(pMac, REASON_OS_REQUESTED_ROAMING_NOW);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001798 }
1799 return eHAL_STATUS_SUCCESS;
1800 }
1801#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -07001802 if(!pSession)
1803 {
1804 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1805 return eHAL_STATUS_FAILURE;
1806 }
1807
Jeff Johnson295189b2012-06-20 16:38:30 -07001808#if defined(WLAN_DEBUG)
1809 if(pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs == 1)
1810 {
1811 char str[36];
Kiet Lam64c1b492013-07-12 13:56:44 +05301812 vos_mem_copy(str,
1813 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.ssId,
1814 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.length);
Jeff Johnson295189b2012-06-20 16:38:30 -07001815 str[pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.length] = 0;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001816 smsLog(pMac, LOGW, FL(" SSID = %s"), str);
Jeff Johnson295189b2012-06-20 16:38:30 -07001817 }
1818#endif
1819 //Check whether it is for start ibss. No need to do anything if it is a JOIN request
1820 if(pProfile && CSR_IS_START_IBSS(pProfile))
1821 {
1822 status = csrRoamIssueConnect(pMac, sessionId, pProfile, NULL, eCsrHddIssued,
1823 pCommand->u.scanCmd.roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1824 if(!HAL_STATUS_SUCCESS(status))
1825 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001826 smsLog(pMac, LOGE, FL("failed to issue startIBSS command with status = 0x%08X"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001827 csrRoamCallCallback(pMac, sessionId, NULL, pCommand->u.scanCmd.roamId, eCSR_ROAM_FAILED, eCSR_ROAM_RESULT_FAILURE);
1828 }
1829 }
1830 else
1831 {
1832 eCsrRoamResult roamResult = eCSR_ROAM_RESULT_FAILURE;
1833
1834 if(csrIsConnStateDisconnected(pMac, sessionId) &&
1835 !csrIsRoamCommandWaitingForSession(pMac, sessionId))
1836 {
1837 status = csrScanStartIdleScan(pMac);
1838 }
1839 if((NULL == pProfile) || !csrIsBssTypeIBSS(pProfile->BSSType))
1840 {
1841 //Only indicate assoc_completion if we indicate assoc_start.
1842 if(pSession->bRefAssocStartCnt > 0)
1843 {
1844 tCsrRoamInfo *pRoamInfo = NULL, roamInfo;
Kiet Lam64c1b492013-07-12 13:56:44 +05301845 vos_mem_set(&roamInfo, sizeof(tCsrRoamInfo), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001846 pRoamInfo = &roamInfo;
1847 if(pCommand->u.roamCmd.pRoamBssEntry)
1848 {
1849 tCsrScanResult *pScanResult =
1850 GET_BASE_ADDR(pCommand->u.roamCmd.pRoamBssEntry,
1851 tCsrScanResult, Link);
1852 roamInfo.pBssDesc = &pScanResult->Result.BssDescriptor;
1853 }
1854 roamInfo.statusCode = pSession->joinFailStatusCode.statusCode;
1855 roamInfo.reasonCode = pSession->joinFailStatusCode.reasonCode;
1856 pSession->bRefAssocStartCnt--;
1857 csrRoamCallCallback(pMac, sessionId, pRoamInfo,
1858 pCommand->u.scanCmd.roamId,
1859 eCSR_ROAM_ASSOCIATION_COMPLETION,
Abhishek Singh72c2f4e2016-07-22 11:25:43 +05301860 eCSR_ROAM_RESULT_SCAN_FOR_SSID_FAILURE);
Jeff Johnson295189b2012-06-20 16:38:30 -07001861 }
Madan Mohan Koyyalamudiee255f12012-09-28 15:41:19 -07001862 else
1863 {
1864 csrRoamCallCallback(pMac, sessionId, NULL,
1865 pCommand->u.scanCmd.roamId,
1866 eCSR_ROAM_ASSOCIATION_FAILURE,
Abhishek Singh72c2f4e2016-07-22 11:25:43 +05301867 eCSR_ROAM_RESULT_SCAN_FOR_SSID_FAILURE);
Madan Mohan Koyyalamudiee255f12012-09-28 15:41:19 -07001868 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001869#ifdef FEATURE_WLAN_BTAMP_UT_RF
1870 //In case of WDS station, let it retry.
1871 if( CSR_IS_WDS_STA(pProfile) )
1872 {
1873 //Save the roma profile so we can retry
1874 csrFreeRoamProfile( pMac, sessionId );
Kiet Lam64c1b492013-07-12 13:56:44 +05301875 pSession->pCurRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1876 if ( NULL != pSession->pCurRoamProfile )
Jeff Johnson295189b2012-06-20 16:38:30 -07001877 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301878 vos_mem_set(pSession->pCurRoamProfile, sizeof(tCsrRoamProfile), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001879 csrRoamCopyProfile(pMac, pSession->pCurRoamProfile, pProfile);
1880 }
1881 csrRoamStartJoinRetryTimer(pMac, sessionId, CSR_JOIN_RETRY_TIMEOUT_PERIOD);
1882 }
1883#endif
1884 }
1885 else
1886 {
1887 roamResult = eCSR_ROAM_RESULT_IBSS_START_FAILED;
1888 }
1889 csrRoamCompletion(pMac, sessionId, NULL, pCommand, roamResult, eANI_BOOLEAN_FALSE);
1890 }
1891
1892 return (status);
1893}
1894
1895
1896//After scan for cap changes, issue a roaming command to either reconnect to the AP or pick another one to connect
1897eHalStatus csrScanHandleCapChangeScanComplete(tpAniSirGlobal pMac, tANI_U32 sessionId)
1898{
1899 eHalStatus status = eHAL_STATUS_FAILURE;
1900 tScanResultHandle hBSSList = NULL;
1901 tCsrScanResultFilter *pScanFilter = NULL;
1902 tANI_U32 roamId = 0;
1903 tCsrRoamProfile *pProfile = NULL;
1904 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1905
1906 do
1907 {
1908 //Here is the profile we need to connect to
Kiet Lam64c1b492013-07-12 13:56:44 +05301909 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1910 if ( NULL == pScanFilter )
1911 status = eHAL_STATUS_FAILURE;
1912 else
1913 status = eHAL_STATUS_SUCCESS;
1914 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001915 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301916 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
1917 if (NULL == pSession) break;
1918 if (NULL == pSession->pCurRoamProfile)
Jeff Johnson295189b2012-06-20 16:38:30 -07001919 {
1920 pScanFilter->EncryptionType.numEntries = 1;
1921 pScanFilter->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_NONE;
1922 }
1923 else
1924 {
1925 //We have to make a copy of pCurRoamProfile because it will be free inside csrRoamIssueConnect
Kiet Lam64c1b492013-07-12 13:56:44 +05301926 pProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1927 if ( NULL == pProfile )
1928 status = eHAL_STATUS_FAILURE;
1929 else
1930 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001931 if(!HAL_STATUS_SUCCESS(status))
1932 break;
1933 status = csrRoamCopyProfile(pMac, pProfile, pSession->pCurRoamProfile);
1934 if(!HAL_STATUS_SUCCESS(status))
1935 break;
1936 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1937 }//We have a profile
1938 roamId = GET_NEXT_ROAM_ID(&pMac->roam);
1939 if(HAL_STATUS_SUCCESS(status))
1940 {
1941 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1942 if(HAL_STATUS_SUCCESS(status))
1943 {
1944 //we want to put the last connected BSS to the very beginning, if possible
1945 csrMoveBssToHeadFromBSSID(pMac, &pSession->connectedProfile.bssid, hBSSList);
1946 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList,
1947 eCsrCapsChange, 0, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1948 if(!HAL_STATUS_SUCCESS(status))
1949 {
1950 csrScanResultPurge(pMac, hBSSList);
1951 }
1952 }//Have scan result
1953 else
1954 {
Arif Hussaina7c8e412013-11-20 11:06:42 -08001955 smsLog(pMac, LOGW, FL("cannot find matching BSS of "
1956 MAC_ADDRESS_STR),
1957 MAC_ADDR_ARRAY(pSession->connectedProfile.bssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001958 //Disconnect
1959 csrRoamDisconnectInternal(pMac, sessionId, eCSR_DISCONNECT_REASON_UNSPECIFIED);
1960 }
1961 }
1962 }while(0);
1963 if(pScanFilter)
1964 {
1965 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301966 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001967 }
1968 if(NULL != pProfile)
1969 {
1970 csrReleaseProfile(pMac, pProfile);
Kiet Lam64c1b492013-07-12 13:56:44 +05301971 vos_mem_free(pProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07001972 }
1973
1974 return (status);
1975}
1976
1977
1978
1979eHalStatus csrScanResultPurge(tpAniSirGlobal pMac, tScanResultHandle hScanList)
1980{
1981 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
1982 tScanResultList *pScanList = (tScanResultList *)hScanList;
1983
1984 if(pScanList)
1985 {
1986 status = csrLLScanPurgeResult(pMac, &pScanList->List);
1987 csrLLClose(&pScanList->List);
Kiet Lam64c1b492013-07-12 13:56:44 +05301988 vos_mem_free(pScanList);
Jeff Johnson295189b2012-06-20 16:38:30 -07001989 }
1990 return (status);
1991}
1992
1993
1994static tANI_U32 csrGetBssPreferValue(tpAniSirGlobal pMac, int rssi)
1995{
1996 tANI_U32 ret = 0;
1997 int i = CSR_NUM_RSSI_CAT - 1;
1998
1999 while(i >= 0)
2000 {
2001 if(rssi >= pMac->roam.configParam.RSSICat[i])
2002 {
2003 ret = pMac->roam.configParam.BssPreferValue[i];
2004 break;
2005 }
2006 i--;
2007 };
2008
2009 return (ret);
2010}
2011
2012
2013//Return a CapValue base on the capabilities of a BSS
2014static tANI_U32 csrGetBssCapValue(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes)
2015{
2016 tANI_U32 ret = CSR_BSS_CAP_VALUE_NONE;
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08002017#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_ESE) || defined(FEATURE_WLAN_LFR)
Madan Mohan Koyyalamudid5026072012-11-30 14:56:21 -08002018 if(CSR_IS_ROAM_PREFER_5GHZ(pMac))
2019 {
2020 if((pBssDesc) && CSR_IS_CHANNEL_5GHZ(pBssDesc->channelId))
2021 {
2022 ret += CSR_BSS_CAP_VALUE_5GHZ;
2023 }
2024 }
2025#endif
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002026 /* if strict select 5GHz is non-zero then ignore the capability checking */
2027 if (pIes && !CSR_IS_SELECT_5GHZ_MARGIN(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -07002028 {
2029 //We only care about 11N capability
2030 if(pIes->HTCaps.present)
2031 {
2032 ret += CSR_BSS_CAP_VALUE_HT;
2033 }
2034 if(CSR_IS_QOS_BSS(pIes))
2035 {
2036 ret += CSR_BSS_CAP_VALUE_WMM;
2037 //Give advantage to UAPSD
2038 if(CSR_IS_UAPSD_BSS(pIes))
2039 {
2040 ret += CSR_BSS_CAP_VALUE_UAPSD;
2041 }
2042 }
2043 }
2044
2045 return (ret);
2046}
2047
Kapil Guptab3a981b2016-06-26 13:36:51 +05302048#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
2049
2050/* Calculate channel weight based on other APs RSSI and count for
2051 * PER based roaming */
2052static tANI_U32 GetPERRoamRssiCountWeight(tANI_S32 rssi, tANI_S32 count)
2053{
2054 tANI_S32 rssiWeight=0;
2055 tANI_S32 countWeight=0;
2056 tANI_S32 rssicountWeight=0;
2057
2058 rssiWeight = ROAMING_RSSI_WEIGHT * (rssi - MIN_RSSI)
2059 /(MAX_RSSI - MIN_RSSI);
2060
2061 if(rssiWeight > ROAMING_RSSI_WEIGHT)
2062 rssiWeight = ROAMING_RSSI_WEIGHT;
2063 else if (rssiWeight < 0)
2064 rssiWeight = 0;
2065
2066 countWeight = ROAM_AP_COUNT_WEIGHT * (count + ROAM_MIN_COUNT)
2067 /(ROAM_MAX_COUNT + ROAM_MIN_COUNT);
2068
2069 if(countWeight > ROAM_AP_COUNT_WEIGHT)
2070 countWeight = ROAM_AP_COUNT_WEIGHT;
2071
2072 rssicountWeight = ROAM_MAX_WEIGHT - (rssiWeight + countWeight);
2073
2074 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO_HIGH,
2075 FL("rssiWeight=%d, countWeight=%d, rssicountWeight=%d rssi=%d count=%d"),
2076 rssiWeight, countWeight, rssicountWeight, rssi, count);
2077
2078 return rssicountWeight;
2079}
2080
2081/* Calculate BSS score based on AP capabilty and channel condition
2082 * for PER based roaming */
2083static tANI_U32 calculateBssScore(tSirBssDescription *bssInfo,
2084 tANI_S32 best_rssi, tANI_S32 ap_cnt, tANI_S32 cca)
2085{
2086 tANI_S32 score = 0;
2087 tANI_S32 ap_load = 0;
2088 tANI_S32 normalised_width = PER_ROAM_20MHZ;
Sen, Devendra6940d0c2016-09-07 12:42:46 +05302089 tANI_S32 normalised_rssi = 0;
Kapil Guptab3a981b2016-06-26 13:36:51 +05302090 tANI_S32 channel_weight;
2091 if (bssInfo->rssi) {
2092 /* Calculate % of rssi we are getting
2093 * max = 100
2094 * min = 0
2095 * less than -40 = 100%
2096 * -40 - -55 = 80%
2097 * -55 - -65 = 60%
2098 * below that = 100 - value
2099 * TODO: a linear decrement function after PER_ROAM_GOOD_RSSI_WEIGHT
2100 * since throughput decrements linearly after PER_ROAM_GOOD_RSSI_WEIGHT
2101 **/
2102 if (bssInfo->rssi >= PER_EXCELENT_RSSI)
2103 normalised_rssi = PER_ROAM_EXCELLENT_RSSI_WEIGHT;
2104 else if (bssInfo->rssi >= PER_GOOD_RSSI)
2105 normalised_rssi = PER_ROAM_GOOD_RSSI_WEIGHT;
2106 else if (bssInfo->rssi >= PER_POOR_RSSI)
2107 normalised_rssi = PER_ROAM_BAD_RSSI_WEIGHT;
2108 else
2109 normalised_rssi = bssInfo->rssi - MIN_RSSI;
2110
2111 /* Calculate score part for rssi */
2112 score += (normalised_rssi * RSSI_WEIGHTAGE);
2113 }
2114
2115 if (bssInfo->HTCapsPresent) {
2116 score += PER_ROAM_MAX_WEIGHT * HT_CAPABILITY_WEIGHTAGE;
2117 }
2118 /* VHT caps are available */
2119 if (bssInfo->vhtCapsPresent) {
2120 score += PER_ROAM_MAX_WEIGHT * VHT_CAP_WEIGHTAGE;
2121 }
2122
2123 if (bssInfo->beacomformingCapable)
2124 score += PER_ROAM_MAX_WEIGHT * BEAMFORMING_CAP_WEIGHTAGE;
2125
2126 /* Channel width 20Mhz=30, 40Mhz=70, 80Mhz=100 */
2127 if (bssInfo->chanWidth == eHT_CHANNEL_WIDTH_80MHZ)
2128 normalised_width = PER_ROAM_80MHZ;
2129 else if (bssInfo->chanWidth == eHT_CHANNEL_WIDTH_40MHZ)
2130 normalised_width = PER_ROAM_40MHZ;
2131 else
2132 normalised_width = PER_ROAM_20MHZ;
2133 score += normalised_width * CHAN_WIDTH_WEIGHTAGE;
2134
2135 /* Channel Band, Channel Number */
2136 if (GetRFBand(bssInfo->channelId) == SIR_BAND_5_GHZ)
2137 score += PER_ROAM_MAX_WEIGHT * CHAN_BAND_WEIGHTAGE;
2138
2139 /* WMM emabled */
2140 if (bssInfo->wmeInfoPresent)
2141 score += PER_ROAM_MAX_WEIGHT * WMM_WEIGHTAGE;
2142
2143#if defined(FEATURE_WLAN_ESE) || defined(WLAN_FEATURE_ROAM_SCAN_OFFLOAD)
2144 /* AP load Ie */
2145 if (bssInfo->QBSSLoad_present) {
2146 /* calculate value in % */
2147 ap_load = (bssInfo->QBSS_ChanLoad * PER_ROAM_MAX_WEIGHT) / MAX_AP_LOAD;
2148 }
2149#endif
2150 //TODO we don't have this info for current AP, need to check
2151 /* if CCA consideration is off in configuration, FW will send 50% for
2152 every channel which should be considered as it is */
2153 if (ap_load)
2154 score += (100 - ap_load) * CCA_WEIGHTAGE;
2155 else
2156 score += (100 - cca) * CCA_WEIGHTAGE;
2157
2158 channel_weight = GetPERRoamRssiCountWeight(best_rssi, ap_cnt);
2159
2160 score += channel_weight * OTHER_AP_WEIGHT;
2161
2162 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO_LOW,
2163 FL("rssi=%d normalized_rssi=%d htcaps=%d vht=%d bw=%d channel=%d wmm=%d beamforming=%d ap_load=%d channel_weight=%d"),
2164 bssInfo->rssi, normalised_rssi, bssInfo->HTCapsPresent,
2165 bssInfo->vhtCapsPresent, bssInfo->chanWidth,
2166 bssInfo->channelId, bssInfo->wmeInfoPresent,
2167 bssInfo->beacomformingCapable, ap_load, channel_weight);
2168 return score;
2169}
2170
2171/* Calculate candidate AP score for PER based roaming */
2172static tANI_S32 csrFindCongestionScore (tpAniSirGlobal pMac, tCsrScanResult *pBss)
2173{
2174 tANI_S32 score = 0;
2175 tANI_S32 i;
2176 tANI_S32 candidateApCnt, best_rssi, other_ap_cnt;
2177 tANI_U32 current_timestamp;
2178 tpCsrNeighborRoamControlInfo pNeighborRoamInfo =
2179 &pMac->roam.neighborRoamInfo;
2180
2181 tSirBssDescription *bssInfo = &(pBss->Result.BssDescriptor);
2182 pBss->congestionScore = 0;
2183 for (i = 0; i < pMac->PERroamCandidatesCnt; i++)
2184 if (pMac->candidateChannelInfo[i].channelNumber ==
2185 pBss->Result.BssDescriptor.channelId)
2186 break;
2187
2188 if (i == SIR_PER_ROAM_MAX_CANDIDATE_CNT) {
2189 smsLog(pMac, LOGE,
2190 FL("candidate chan info not found for channel %d bssid "
2191 MAC_ADDRESS_STR), pBss->Result.BssDescriptor.channelId,
2192 MAC_ADDR_ARRAY(pBss->Result.BssDescriptor.bssId));
2193 return -1;
2194 }
2195
2196 /* find best RSSI of other AP in this channel */
2197 best_rssi = MIN_RSSI;
2198 for (other_ap_cnt = 0; other_ap_cnt <
2199 pMac->candidateChannelInfo[i].otherApCount; other_ap_cnt++) {
2200 if (pMac->candidateChannelInfo[i].otherApRssi[other_ap_cnt] > best_rssi)
2201 best_rssi = pMac->candidateChannelInfo[i].otherApRssi[other_ap_cnt];
2202 }
2203
2204 score = calculateBssScore(bssInfo, best_rssi,
2205 pMac->candidateChannelInfo[i].otherApCount,
2206 pMac->candidateChannelInfo[i].channelCCA);
2207 current_timestamp = jiffies_to_msecs(jiffies);
2208
2209 /* penalty logic */
2210
2211 /* In the previous list */
2212 for (candidateApCnt = 0; candidateApCnt <
2213 SIR_PER_ROAM_MAX_CANDIDATE_CNT; candidateApCnt++) {
2214 if (sirCompareMacAddr(pMac->previousRoamApInfo[candidateApCnt].bssAddr,
2215 pBss->Result.BssDescriptor.bssId) &&
2216 ((current_timestamp - pMac->previousRoamApInfo[candidateApCnt].timeStamp) <
2217 PENALTY_TIMEOUT)) {
2218 score = (score * PENALTY_REMAINING_SCORE)/PENALTY_TOTAL_SCORE;
2219 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
2220 FL("AP BSSID " MAC_ADDRESS_STR "adding penalty(in previous list)new score %d"),
2221 MAC_ADDR_ARRAY(pBss->Result.BssDescriptor.bssId),
2222 score);
2223 break;
2224 }
2225 }
2226 /* preauth failed last time */
2227 for (candidateApCnt = 0; candidateApCnt <
2228 MAX_NUM_PREAUTH_FAIL_LIST_ADDRESS; candidateApCnt++) {
2229 if (sirCompareMacAddr(pNeighborRoamInfo->FTRoamInfo.
2230 preAuthFailList.macAddress[candidateApCnt],
2231 pBss->Result.BssDescriptor.bssId)) {
2232 score = (score * PENALTY_REMAINING_SCORE)/PENALTY_TOTAL_SCORE;
2233 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
2234 FL("AP BSSID " MAC_ADDRESS_STR "adding penalty(previously auth failed)new score %d"),
2235 MAC_ADDR_ARRAY(pBss->Result.BssDescriptor.bssId),
2236 score);
2237 break;
2238 }
2239 }
2240 pBss->congestionScore = score;
2241
2242 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
2243 FL("AP BSSID " MAC_ADDRESS_STR " score %d channel %d"),
2244 MAC_ADDR_ARRAY(pBss->Result.BssDescriptor.bssId),
2245 score, pBss->Result.BssDescriptor.channelId);
2246 return 0;
2247}
2248
2249/* Calculate current AP score for PER based roaming */
2250static tANI_S32 csrFindSelfCongestionScore(tpAniSirGlobal pMac,
2251 tSirBssDescription *bssInfo)
2252{
2253 tANI_S32 i, best_rssi, other_ap_cnt;
2254 tANI_S32 score = 0;
Kapil Guptac6ac4772016-08-05 20:25:16 +05302255 tCsrRoamSession *pSession = CSR_GET_SESSION(pMac,
2256 pMac->roam.roamSession->sessionId);
2257
2258 if (pSession == NULL)
2259 return -1;
Kapil Guptab3a981b2016-06-26 13:36:51 +05302260
2261 for (i = 0; i <= pMac->PERroamCandidatesCnt; i++)
2262 if (pMac->candidateChannelInfo[i].channelNumber == bssInfo->channelId)
2263 break;
2264 if (i > pMac->PERroamCandidatesCnt) {
2265 /* home channel info is not present, no need to roam */
2266 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR,
2267 FL("home channel %d congestion info not present"),
2268 bssInfo->channelId);
2269 pMac->currentBssScore = PER_ROAM_MAX_BSS_SCORE;
2270 return -1;
2271 }
2272
2273 /* find best RSSI of other AP in this channel */
2274 best_rssi = MIN_RSSI;
2275 for (other_ap_cnt = 0; other_ap_cnt <
2276 pMac->candidateChannelInfo[i].otherApCount; other_ap_cnt++) {
2277 if (pMac->candidateChannelInfo[i].otherApRssi[other_ap_cnt] > best_rssi)
2278 best_rssi = pMac->candidateChannelInfo[i].otherApRssi[other_ap_cnt];
2279 }
2280
Kapil Guptac6ac4772016-08-05 20:25:16 +05302281 /* update latest RSSI for current AP */
2282 WLANTL_GetRssi(vos_get_global_context(VOS_MODULE_ID_SME, NULL),
2283 pSession->connectedInfo.staId,
2284 &bssInfo->rssi);
2285
Kapil Guptab3a981b2016-06-26 13:36:51 +05302286 score = calculateBssScore(bssInfo, best_rssi,
2287 pMac->candidateChannelInfo[i].otherApCount,
2288 pMac->candidateChannelInfo[i].channelCCA);
2289 pMac->currentBssScore = score;
2290 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
2291 FL("PER Roam Current AP score %d channel %d"),
2292 score, bssInfo->channelId);
2293 return 0;
2294}
2295
Kapil Guptab79e76f2016-09-12 20:04:37 +05302296
Kapil Guptab3a981b2016-06-26 13:36:51 +05302297static tANI_BOOLEAN csrIsBetterBssInCongestion(tCsrScanResult *pBss1,
2298 tCsrScanResult *pBss2)
2299{
2300 tANI_BOOLEAN ret;
2301
2302 if(CSR_IS_BETTER_PREFER_VALUE(pBss1->congestionScore,
2303 pBss2->congestionScore))
2304 ret = eANI_BOOLEAN_TRUE;
2305 else
2306 ret = eANI_BOOLEAN_FALSE;
2307
2308 return (ret);
2309}
2310#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002311
2312//To check whther pBss1 is better than pBss2
2313static tANI_BOOLEAN csrIsBetterBss(tCsrScanResult *pBss1, tCsrScanResult *pBss2)
2314{
2315 tANI_BOOLEAN ret;
2316
2317 if(CSR_IS_BETTER_PREFER_VALUE(pBss1->preferValue, pBss2->preferValue))
2318 {
2319 ret = eANI_BOOLEAN_TRUE;
2320 }
2321 else if(CSR_IS_EQUAL_PREFER_VALUE(pBss1->preferValue, pBss2->preferValue))
2322 {
2323 if(CSR_IS_BETTER_CAP_VALUE(pBss1->capValue, pBss2->capValue))
2324 {
2325 ret = eANI_BOOLEAN_TRUE;
2326 }
2327 else
2328 {
2329 ret = eANI_BOOLEAN_FALSE;
2330 }
2331 }
2332 else
2333 {
2334 ret = eANI_BOOLEAN_FALSE;
2335 }
2336
2337 return (ret);
2338}
2339
2340
Srikant Kuppa866893f2012-12-27 17:28:14 -08002341#ifdef FEATURE_WLAN_LFR
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002342//Add the channel to the occupiedChannels array
2343static void csrScanAddToOccupiedChannels(
Srikant Kuppa866893f2012-12-27 17:28:14 -08002344 tpAniSirGlobal pMac,
2345 tCsrScanResult *pResult,
2346 tCsrChannel *pOccupiedChannels,
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002347 tDot11fBeaconIEs *pIes)
2348{
2349 eHalStatus status;
2350 tANI_U8 channel;
2351 tANI_U8 numOccupiedChannels = pOccupiedChannels->numChannels;
2352 tANI_U8 *pOccupiedChannelList = pOccupiedChannels->channelList;
2353
2354 channel = pResult->Result.BssDescriptor.channelId;
2355
2356 if (!csrIsChannelPresentInList(pOccupiedChannelList, numOccupiedChannels, channel)
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08002357 && csrNeighborRoamConnectedProfileMatch(pMac, pResult, pIes))
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002358 {
Srikant Kuppa866893f2012-12-27 17:28:14 -08002359 status = csrAddToChannelListFront(pOccupiedChannelList, numOccupiedChannels, channel);
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002360 if(HAL_STATUS_SUCCESS(status))
Srikant Kuppa866893f2012-12-27 17:28:14 -08002361 {
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002362 pOccupiedChannels->numChannels++;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002363 smsLog(pMac, LOG2, FL("%s: added channel %d to the list (count=%d)"),
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08002364 __func__, channel, pOccupiedChannels->numChannels);
Srikant Kuppa866893f2012-12-27 17:28:14 -08002365 if (pOccupiedChannels->numChannels > CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN)
2366 pOccupiedChannels->numChannels = CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN;
2367 }
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002368 }
2369}
Mukul Sharma9e4e0f92015-02-13 18:45:20 +05302370
2371void csrAddChannelToOccupiedChannelList(tpAniSirGlobal pMac,
2372 tANI_U8 channel)
2373{
2374 eHalStatus status;
2375 tCsrChannel *pOccupiedChannels = &pMac->scan.occupiedChannels;
2376 tANI_U8 numOccupiedChannels = pOccupiedChannels->numChannels;
2377 tANI_U8 *pOccupiedChannelList = pOccupiedChannels->channelList;
2378 if (!csrIsChannelPresentInList(pOccupiedChannelList,
2379 numOccupiedChannels, channel))
2380 {
2381 status = csrAddToChannelListFront(pOccupiedChannelList,
2382 numOccupiedChannels, channel);
2383 if(HAL_STATUS_SUCCESS(status))
2384 {
2385 pOccupiedChannels->numChannels++;
2386 smsLog(pMac, LOG2, FL("added channel %d to the list (count=%d)"),
2387 channel, pOccupiedChannels->numChannels);
2388 if (pOccupiedChannels->numChannels >
2389 CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN)
2390 {
2391 pOccupiedChannels->numChannels =
2392 CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN;
2393 smsLog(pMac, LOG2,
2394 FL("trim no of Channels for Occ channel list"));
2395 }
2396 }
2397 }
2398}
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002399#endif
2400
Jeff Johnson295189b2012-06-20 16:38:30 -07002401//Put the BSS into the scan result list
2402//pIes can not be NULL
2403static void csrScanAddResult(tpAniSirGlobal pMac, tCsrScanResult *pResult, tDot11fBeaconIEs *pIes)
2404{
Srinivas28b5b4e2012-12-12 13:07:53 -08002405#ifdef FEATURE_WLAN_LFR
2406 tpCsrNeighborRoamControlInfo pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
2407#endif
2408
Jeff Johnson295189b2012-06-20 16:38:30 -07002409 pResult->preferValue = csrGetBssPreferValue(pMac, (int)pResult->Result.BssDescriptor.rssi);
2410 pResult->capValue = csrGetBssCapValue(pMac, &pResult->Result.BssDescriptor, pIes);
2411 csrLLInsertTail( &pMac->scan.scanResultList, &pResult->Link, LL_ACCESS_LOCK );
Srikant Kuppa866893f2012-12-27 17:28:14 -08002412#ifdef FEATURE_WLAN_LFR
Srinivas28b5b4e2012-12-12 13:07:53 -08002413 if(0 == pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels)
2414 {
2415 /* Build the occupied channel list, only if "gNeighborScanChannelList" is
2416 NOT set in the cfg.ini file */
2417 csrScanAddToOccupiedChannels(pMac, pResult, &pMac->scan.occupiedChannels, pIes);
2418 }
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002419#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002420}
2421
2422
2423eHalStatus csrScanGetResult(tpAniSirGlobal pMac, tCsrScanResultFilter *pFilter, tScanResultHandle *phResult)
2424{
2425 eHalStatus status;
2426 tScanResultList *pRetList;
2427 tCsrScanResult *pResult, *pBssDesc;
2428 tANI_U32 count = 0;
2429 tListElem *pEntry;
2430 tANI_U32 bssLen, allocLen;
2431 eCsrEncryptionType uc = eCSR_ENCRYPT_TYPE_NONE, mc = eCSR_ENCRYPT_TYPE_NONE;
2432 eCsrAuthType auth = eCSR_AUTH_TYPE_OPEN_SYSTEM;
2433 tDot11fBeaconIEs *pIes, *pNewIes;
2434 tANI_BOOLEAN fMatch;
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002435 tANI_U16 i = 0;
Kapil Guptab3a981b2016-06-26 13:36:51 +05302436 tCsrRoamSession *pSession = CSR_GET_SESSION(pMac,
2437 pMac->roam.roamSession->sessionId);
2438
Jeff Johnson295189b2012-06-20 16:38:30 -07002439 if(phResult)
2440 {
2441 *phResult = CSR_INVALID_SCANRESULT_HANDLE;
2442 }
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002443
2444 if (pMac->roam.configParam.nSelect5GHzMargin)
2445 {
2446 pMac->scan.inScanResultBestAPRssi = -128;
2447 csrLLLock(&pMac->scan.scanResultList);
2448
2449 /* Find out the best AP Rssi going thru the scan results */
2450 pEntry = csrLLPeekHead(&pMac->scan.scanResultList, LL_ACCESS_NOLOCK);
2451 while ( NULL != pEntry)
2452 {
2453 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002454 fMatch = FALSE;
2455
2456 if (pFilter)
2457 for(i = 0; i < pFilter->SSIDs.numOfSSIDs; i++)
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002458 {
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002459 fMatch = csrIsSsidMatch( pMac, pFilter->SSIDs.SSIDList[i].SSID.ssId, pFilter->SSIDs.SSIDList[i].SSID.length,
2460 pBssDesc->Result.ssId.ssId,
2461 pBssDesc->Result.ssId.length, eANI_BOOLEAN_TRUE );
2462 if (fMatch)
2463 {
2464 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
2465
2466 //At this time, pBssDescription->Result.pvIes may be NULL
2467 if( !pIes && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
2468 &pBssDesc->Result.BssDescriptor, &pIes))) )
2469 {
2470 continue;
2471 }
2472
2473 smsLog(pMac, LOG1, FL("SSID Matched"));
Leela Venkata Kiran Kumar Reddy Chiralae208a832014-04-27 22:34:25 -07002474
Leela Venkata Kiran Kumar Reddy Chiralaf257bef2014-04-11 18:48:12 -07002475 if ( pFilter->bOSENAssociation )
2476 {
2477 fMatch = TRUE;
2478 }
Leela Venkata Kiran Kumar Reddy Chiralae208a832014-04-27 22:34:25 -07002479 else
2480 {
Abhishek Singh658d4de2014-06-26 10:53:15 +05302481#ifdef WLAN_FEATURE_11W
Abhishek Singh3b56d3a2014-06-25 12:37:39 +05302482 fMatch = csrIsSecurityMatch(pMac, &pFilter->authType,
2483 &pFilter->EncryptionType,
2484 &pFilter->mcEncryptionType,
2485 &pFilter->MFPEnabled,
2486 &pFilter->MFPRequired,
2487 &pFilter->MFPCapable,
2488 &pBssDesc->Result.BssDescriptor,
2489 pIes, NULL, NULL, NULL );
Abhishek Singh658d4de2014-06-26 10:53:15 +05302490#else
2491 fMatch = csrIsSecurityMatch(pMac, &pFilter->authType,
2492 &pFilter->EncryptionType,
2493 &pFilter->mcEncryptionType,
2494 NULL, NULL, NULL,
2495 &pBssDesc->Result.BssDescriptor,
2496 pIes, NULL, NULL, NULL );
2497#endif
Leela Venkata Kiran Kumar Reddy Chiralae208a832014-04-27 22:34:25 -07002498 }
2499 if ((pBssDesc->Result.pvIes == NULL) && pIes)
2500 vos_mem_free(pIes);
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002501
2502 if (fMatch)
2503 smsLog(pMac, LOG1, FL(" Security Matched"));
2504 }
2505 }
2506
2507 if (fMatch && (pBssDesc->Result.BssDescriptor.rssi > pMac->scan.inScanResultBestAPRssi))
2508 {
2509 smsLog(pMac, LOG1, FL("Best AP Rssi changed from %d to %d"),
2510 pMac->scan.inScanResultBestAPRssi,
2511 pBssDesc->Result.BssDescriptor.rssi);
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002512 pMac->scan.inScanResultBestAPRssi = pBssDesc->Result.BssDescriptor.rssi;
2513 }
2514 pEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
2515 }
2516
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002517 if ( -128 != pMac->scan.inScanResultBestAPRssi)
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002518 {
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002519 smsLog(pMac, LOG1, FL("Best AP Rssi is %d"), pMac->scan.inScanResultBestAPRssi);
2520 /* Modify Rssi category based on best AP Rssi */
2521 csrAssignRssiForCategory(pMac, pMac->scan.inScanResultBestAPRssi, pMac->roam.configParam.bCatRssiOffset);
2522 pEntry = csrLLPeekHead(&pMac->scan.scanResultList, LL_ACCESS_NOLOCK);
2523 while ( NULL != pEntry)
2524 {
2525 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002526
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002527 /* re-assign preference value based on modified rssi bucket */
2528 pBssDesc->preferValue = csrGetBssPreferValue(pMac, (int)pBssDesc->Result.BssDescriptor.rssi);
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002529
Arif Hussaina7c8e412013-11-20 11:06:42 -08002530 smsLog(pMac, LOG2, FL("BSSID("MAC_ADDRESS_STR
Jeff Johnson123ed002013-11-22 17:39:55 -08002531 ") Rssi(%d) Chnl(%d) PrefVal(%u) SSID=%.*s"),
Arif Hussaina7c8e412013-11-20 11:06:42 -08002532 MAC_ADDR_ARRAY(pBssDesc->Result.BssDescriptor.bssId),
2533 pBssDesc->Result.BssDescriptor.rssi,
2534 pBssDesc->Result.BssDescriptor.channelId,
2535 pBssDesc->preferValue,
2536 pBssDesc->Result.ssId.length, pBssDesc->Result.ssId.ssId);
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002537
2538 pEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
2539 }
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002540 }
2541
2542 csrLLUnlock(&pMac->scan.scanResultList);
2543 }
2544
Kiet Lam64c1b492013-07-12 13:56:44 +05302545 pRetList = vos_mem_malloc(sizeof(tScanResultList));
2546 if ( NULL == pRetList )
2547 status = eHAL_STATUS_FAILURE;
2548 else
2549 status = eHAL_STATUS_SUCCESS;
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002550 if(HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07002551 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302552 vos_mem_set(pRetList, sizeof(tScanResultList), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002553 csrLLOpen(pMac->hHdd, &pRetList->List);
2554 pRetList->pCurEntry = NULL;
Kapil Guptab3a981b2016-06-26 13:36:51 +05302555#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
2556 if (pFilter && pFilter->isPERRoamScan)
2557 if (pSession && pSession->pConnectBssDesc)
2558 csrFindSelfCongestionScore(pMac,
2559 pSession->pConnectBssDesc);
2560#endif
2561
Jeff Johnson295189b2012-06-20 16:38:30 -07002562 csrLLLock(&pMac->scan.scanResultList);
2563 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
2564 while( pEntry )
2565 {
2566 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2567 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
2568 //if pBssDesc->Result.pvIes is NULL, we need to free any memory allocated by csrMatchBSS
2569 //for any error condition, otherwiase, it will be freed later.
2570 //reset
2571 fMatch = eANI_BOOLEAN_FALSE;
2572 pNewIes = NULL;
2573
2574 if(pFilter)
2575 {
2576 fMatch = csrMatchBSS(pMac, &pBssDesc->Result.BssDescriptor, pFilter, &auth, &uc, &mc, &pIes);
2577 if( NULL != pIes )
2578 {
2579 //Only save it when matching
2580 if(fMatch)
2581 {
2582 if( !pBssDesc->Result.pvIes )
2583 {
2584 //csrMatchBSS allocates the memory. Simply pass it and it is freed later
2585 pNewIes = pIes;
2586 }
2587 else
2588 {
2589 //The pIes is allocated by someone else. make a copy
2590 //Only to save parsed IEs if caller provides a filter. Most likely the caller
2591 //is using to for association, hence save the parsed IEs
Kiet Lam64c1b492013-07-12 13:56:44 +05302592 pNewIes = vos_mem_malloc(sizeof(tDot11fBeaconIEs));
2593 if ( NULL == pNewIes )
2594 status = eHAL_STATUS_FAILURE;
2595 else
2596 status = eHAL_STATUS_SUCCESS;
2597 if ( HAL_STATUS_SUCCESS( status ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07002598 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302599 vos_mem_copy(pNewIes, pIes, sizeof( tDot11fBeaconIEs ));
Jeff Johnson295189b2012-06-20 16:38:30 -07002600 }
2601 else
2602 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002603 smsLog(pMac, LOGE, FL(" fail to allocate memory for IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002604 //Need to free memory allocated by csrMatchBSS
2605 if( !pBssDesc->Result.pvIes )
2606 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302607 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07002608 }
2609 break;
2610 }
2611 }
2612 }//fMatch
2613 else if( !pBssDesc->Result.pvIes )
2614 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302615 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07002616 }
2617 }
2618 }
2619 if(NULL == pFilter || fMatch)
2620 {
2621 bssLen = pBssDesc->Result.BssDescriptor.length + sizeof(pBssDesc->Result.BssDescriptor.length);
2622 allocLen = sizeof( tCsrScanResult ) + bssLen;
Kiet Lam64c1b492013-07-12 13:56:44 +05302623 pResult = vos_mem_malloc(allocLen);
2624 if ( NULL == pResult )
2625 status = eHAL_STATUS_FAILURE;
2626 else
2627 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07002628 if(!HAL_STATUS_SUCCESS(status))
2629 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002630 smsLog(pMac, LOGE, FL(" fail to allocate memory for scan result, len=%d"), allocLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07002631 if(pNewIes)
2632 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302633 vos_mem_free(pNewIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07002634 }
2635 break;
2636 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302637 vos_mem_set(pResult, allocLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002638 pResult->capValue = pBssDesc->capValue;
2639 pResult->preferValue = pBssDesc->preferValue;
2640 pResult->ucEncryptionType = uc;
2641 pResult->mcEncryptionType = mc;
2642 pResult->authType = auth;
2643 pResult->Result.ssId = pBssDesc->Result.ssId;
Padma, Santhosh Kumare12fd982016-03-21 13:07:52 +05302644 pResult->Result.timer = pBssDesc->Result.timer;
Jeff Johnson295189b2012-06-20 16:38:30 -07002645 //save the pIes for later use
2646 pResult->Result.pvIes = pNewIes;
2647 //save bss description
Kiet Lam64c1b492013-07-12 13:56:44 +05302648 vos_mem_copy(&pResult->Result.BssDescriptor,
2649 &pBssDesc->Result.BssDescriptor, bssLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07002650 //No need to lock pRetList because it is locally allocated and no outside can access it at this time
2651 if(csrLLIsListEmpty(&pRetList->List, LL_ACCESS_NOLOCK))
2652 {
Kapil Guptab3a981b2016-06-26 13:36:51 +05302653#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
2654 if (pFilter && pFilter->isPERRoamScan) {
2655 csrFindCongestionScore(pMac, pResult);
2656 if (pResult->congestionScore > pMac->currentBssScore) {
2657 csrLLInsertTail(&pRetList->List, &pResult->Link,
2658 LL_ACCESS_NOLOCK);
2659 smsLog(pMac, LOGW,
2660 FL("added one entry in LL in PER Roam list"));
2661 }
2662 }
2663 else
2664#endif
2665 {
2666 csrLLInsertTail(&pRetList->List, &pResult->Link,
2667 LL_ACCESS_NOLOCK);
2668 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002669 }
2670 else
2671 {
2672 //To sort the list
2673 tListElem *pTmpEntry;
2674 tCsrScanResult *pTmpResult;
2675
2676 pTmpEntry = csrLLPeekHead(&pRetList->List, LL_ACCESS_NOLOCK);
2677 while(pTmpEntry)
2678 {
2679 pTmpResult = GET_BASE_ADDR( pTmpEntry, tCsrScanResult, Link );
Kapil Guptab3a981b2016-06-26 13:36:51 +05302680#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
2681 if (pFilter && pFilter->isPERRoamScan) {
2682 csrFindCongestionScore(pMac, pResult);
2683 if(csrIsBetterBssInCongestion(pResult, pTmpResult)&&
2684 (pResult->congestionScore > pMac->currentBssScore))
2685 {
2686 csrLLInsertEntry(&pRetList->List, pTmpEntry,
2687 &pResult->Link, LL_ACCESS_NOLOCK);
2688 smsLog(pMac, LOGW,
2689 FL("added another entry in LL in PER Roam list"));
2690 pResult = NULL;
2691 break;
2692 }
2693 pTmpEntry = csrLLNext(&pRetList->List,
2694 pTmpEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07002695 }
Kapil Guptab3a981b2016-06-26 13:36:51 +05302696 else
2697#endif
2698 {
2699 if(csrIsBetterBss(pResult, pTmpResult))
2700 {
2701 csrLLInsertEntry(&pRetList->List, pTmpEntry,
2702 &pResult->Link, LL_ACCESS_NOLOCK);
2703 //To indicate we are done
2704 pResult = NULL;
2705 break;
2706 }
2707 pTmpEntry = csrLLNext(&pRetList->List,
2708 pTmpEntry, LL_ACCESS_NOLOCK);
2709 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002710 }
2711 if(pResult != NULL)
Kapil Guptab3a981b2016-06-26 13:36:51 +05302712#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
2713 if ((pFilter && !pFilter->isPERRoamScan) ||
2714 (pFilter == NULL) ||
2715 (pResult->congestionScore > pMac->currentBssScore))
2716#endif
2717 {
2718 //This one is not better than any one
2719 csrLLInsertTail(&pRetList->List,
2720 &pResult->Link, LL_ACCESS_NOLOCK);
2721 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002722 }
2723 count++;
2724 }
2725 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK );
2726 }//while
2727 csrLLUnlock(&pMac->scan.scanResultList);
2728
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002729 smsLog(pMac, LOG2, FL("return %d BSS"), csrLLCount(&pRetList->List));
Jeff Johnson295189b2012-06-20 16:38:30 -07002730
2731 if( !HAL_STATUS_SUCCESS(status) || (phResult == NULL) )
2732 {
2733 //Fail or No one wants the result.
2734 csrScanResultPurge(pMac, (tScanResultHandle)pRetList);
2735 }
2736 else
2737 {
2738 if(0 == count)
2739 {
2740 //We are here meaning the there is no match
2741 csrLLClose(&pRetList->List);
Kiet Lam64c1b492013-07-12 13:56:44 +05302742 vos_mem_free(pRetList);
Jeff Johnson295189b2012-06-20 16:38:30 -07002743 status = eHAL_STATUS_E_NULL_VALUE;
Kapil Guptab3a981b2016-06-26 13:36:51 +05302744 smsLog(pMac, LOGW,
2745 FL("Nil scan results or no matching AP found"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002746 }
2747 else if(phResult)
2748 {
2749 *phResult = pRetList;
2750 }
2751 }
2752 }//Allocated pRetList
2753
2754 return (status);
2755}
2756
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002757/*
2758 * NOTE: This routine is being added to make
2759 * sure that scan results are not being flushed
2760 * while roaming. If the scan results are flushed,
2761 * we are unable to recover from
2762 * csrRoamRoamingStateDisassocRspProcessor.
2763 * If it is needed to remove this routine,
2764 * first ensure that we recover gracefully from
2765 * csrRoamRoamingStateDisassocRspProcessor if
2766 * csrScanGetResult returns with a failure because
2767 * of not being able to find the roaming BSS.
2768 */
2769tANI_U8 csrScanFlushDenied(tpAniSirGlobal pMac)
2770{
2771 switch(pMac->roam.neighborRoamInfo.neighborRoamState) {
2772 case eCSR_NEIGHBOR_ROAM_STATE_REPORT_SCAN:
2773 case eCSR_NEIGHBOR_ROAM_STATE_PREAUTHENTICATING:
2774 case eCSR_NEIGHBOR_ROAM_STATE_PREAUTH_DONE:
2775 case eCSR_NEIGHBOR_ROAM_STATE_REASSOCIATING:
2776 return (pMac->roam.neighborRoamInfo.neighborRoamState);
2777 default:
2778 return 0;
2779 }
2780}
2781
Jeff Johnson295189b2012-06-20 16:38:30 -07002782eHalStatus csrScanFlushResult(tpAniSirGlobal pMac)
2783{
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002784 tANI_U8 isFlushDenied = csrScanFlushDenied(pMac);
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302785 eHalStatus status = eHAL_STATUS_SUCCESS;
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002786 if (isFlushDenied) {
2787 smsLog(pMac, LOGW, "%s: scan flush denied in roam state %d",
2788 __func__, isFlushDenied);
2789 return eHAL_STATUS_FAILURE;
2790 }
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302791 csrLLScanPurgeResult( pMac, &pMac->scan.tempScanResults );
2792 csrLLScanPurgeResult( pMac, &pMac->scan.scanResultList );
2793 return( status );
Jeff Johnson295189b2012-06-20 16:38:30 -07002794}
2795
Mukul Sharma20aa6582014-08-07 21:36:12 +05302796eHalStatus csrScanFlushSelectiveResultForBand(tpAniSirGlobal pMac, v_BOOL_t flushP2P, tSirRFBand band)
2797{
2798 eHalStatus status = eHAL_STATUS_SUCCESS;
2799 tListElem *pEntry,*pFreeElem;
2800 tCsrScanResult *pBssDesc;
2801 tDblLinkList *pList = &pMac->scan.scanResultList;
2802
2803 csrLLLock(pList);
2804
2805 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK );
2806 while( pEntry != NULL)
2807 {
2808 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2809 if( (flushP2P == vos_mem_compare( pBssDesc->Result.ssId.ssId,
2810 "DIRECT-", 7)) &&
2811 (GetRFBand(pBssDesc->Result.BssDescriptor.channelId) == band)
2812 )
2813 {
2814 pFreeElem = pEntry;
2815 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2816 csrLLRemoveEntry(pList, pFreeElem, LL_ACCESS_NOLOCK);
2817 csrFreeScanResultEntry( pMac, pBssDesc );
2818 continue;
2819 }
2820 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2821 }
2822
2823 csrLLUnlock(pList);
2824
2825 return (status);
2826}
2827
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302828eHalStatus csrScanFlushSelectiveResult(tpAniSirGlobal pMac, v_BOOL_t flushP2P)
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002829{
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302830 eHalStatus status = eHAL_STATUS_SUCCESS;
2831 tListElem *pEntry,*pFreeElem;
2832 tCsrScanResult *pBssDesc;
2833 tDblLinkList *pList = &pMac->scan.scanResultList;
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002834
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302835 csrLLLock(pList);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002836
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302837 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK );
2838 while( pEntry != NULL)
2839 {
2840 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2841 if( flushP2P == vos_mem_compare( pBssDesc->Result.ssId.ssId,
2842 "DIRECT-", 7) )
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002843 {
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302844 pFreeElem = pEntry;
2845 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2846 csrLLRemoveEntry(pList, pFreeElem, LL_ACCESS_NOLOCK);
2847 csrFreeScanResultEntry( pMac, pBssDesc );
2848 continue;
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002849 }
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302850 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2851 }
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002852
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302853 csrLLUnlock(pList);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002854
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302855 return (status);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002856}
2857
Jeff Johnson295189b2012-06-20 16:38:30 -07002858/**
2859 * csrCheck11dChannel
2860 *
2861 *FUNCTION:
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302862 * This function is called from csrScanFilterResults function and
Jeff Johnson295189b2012-06-20 16:38:30 -07002863 * compare channel number with given channel list.
2864 *
2865 *LOGIC:
2866 * Check Scan result channel number with CFG channel list
2867 *
2868 *ASSUMPTIONS:
2869 *
2870 *
2871 *NOTE:
2872 *
2873 * @param channelId channel number
2874 * @param pChannelList Pointer to channel list
2875 * @param numChannels Number of channel in channel list
2876 *
2877 * @return Status
2878 */
2879
2880eHalStatus csrCheck11dChannel(tANI_U8 channelId, tANI_U8 *pChannelList, tANI_U32 numChannels)
2881{
2882 eHalStatus status = eHAL_STATUS_FAILURE;
2883 tANI_U8 i = 0;
2884
2885 for (i = 0; i < numChannels; i++)
2886 {
2887 if(pChannelList[ i ] == channelId)
2888 {
2889 status = eHAL_STATUS_SUCCESS;
2890 break;
2891 }
2892 }
2893 return status;
2894}
2895
2896/**
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302897 * csrScanFilterResults
Jeff Johnson295189b2012-06-20 16:38:30 -07002898 *
2899 *FUNCTION:
2900 * This function is called from csrApplyCountryInformation function and
2901 * filter scan result based on valid channel list number.
2902 *
2903 *LOGIC:
2904 * Get scan result from scan list and Check Scan result channel number
2905 * with 11d channel list if channel number is found in 11d channel list
2906 * then do not remove scan result entry from scan list
2907 *
2908 *ASSUMPTIONS:
2909 *
2910 *
2911 *NOTE:
2912 *
2913 * @param pMac Pointer to Global MAC structure
2914 *
2915 * @return Status
2916 */
2917
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302918eHalStatus csrScanFilterResults(tpAniSirGlobal pMac)
Jeff Johnson295189b2012-06-20 16:38:30 -07002919{
2920 eHalStatus status = eHAL_STATUS_SUCCESS;
2921 tListElem *pEntry,*pTempEntry;
2922 tCsrScanResult *pBssDesc;
2923 tANI_U32 len = sizeof(pMac->roam.validChannelList);
2924
2925 /* Get valid channels list from CFG */
2926 if (!HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac,
2927 pMac->roam.validChannelList, &len)))
2928 {
Agarwal Ashishe3cca2a2013-07-21 03:01:48 +05302929 smsLog( pMac, LOGE, "Failed to get Channel list from CFG");
Jeff Johnson295189b2012-06-20 16:38:30 -07002930 }
2931
2932 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
2933 while( pEntry )
2934 {
2935 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302936 pTempEntry = csrLLNext( &pMac->scan.scanResultList, pEntry,
Jeff Johnson295189b2012-06-20 16:38:30 -07002937 LL_ACCESS_LOCK );
2938 if(csrCheck11dChannel(pBssDesc->Result.BssDescriptor.channelId,
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302939 pMac->roam.validChannelList, len))
Jeff Johnson295189b2012-06-20 16:38:30 -07002940 {
2941 /* Remove Scan result which does not have 11d channel */
2942 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry,
2943 LL_ACCESS_LOCK ))
2944 {
2945 csrFreeScanResultEntry( pMac, pBssDesc );
2946 }
2947 }
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302948 pEntry = pTempEntry;
2949 }
2950
2951 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
2952 while( pEntry )
2953 {
2954 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2955 pTempEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry,
2956 LL_ACCESS_LOCK );
2957 if(csrCheck11dChannel(pBssDesc->Result.BssDescriptor.channelId,
2958 pMac->roam.validChannelList, len))
2959 {
2960 /* Remove Scan result which does not have 11d channel */
2961 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry,
2962 LL_ACCESS_LOCK ))
2963 {
2964 csrFreeScanResultEntry( pMac, pBssDesc );
2965 }
2966 }
2967 else
2968 {
2969 smsLog( pMac, LOG1, FL("%d is a Valid channel"),
2970 pBssDesc->Result.BssDescriptor.channelId);
2971 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002972 pEntry = pTempEntry;
2973 }
2974 return status;
2975}
2976
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05302977/**
2978 * csrScanFilterDFSResults
2979 *
2980 *FUNCTION:
2981 * This function filter BSSIDs on DFS channels from the scan results.
2982 *
2983 *LOGIC:
2984 * Get scan result from scan list and Check Scan result channel number
2985 * with 11d channel list if channel number is found in 11d channel list
2986 * and if fEnableDFSChnlScan is zero and if channel is DFS, then
2987 * remove scan result entry from scan list
2988 *
2989 *ASSUMPTIONS:
2990 *
2991 *NOTE:
2992 *
2993 * @param pMac Pointer to Global MAC structure
2994 *
2995 * @return Status
2996 */
2997
2998eHalStatus csrScanFilterDFSResults(tpAniSirGlobal pMac)
2999{
3000 eHalStatus status = eHAL_STATUS_SUCCESS;
3001 tListElem *pEntry,*pTempEntry;
3002 tCsrScanResult *pBssDesc;
3003
3004 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
3005 while( pEntry )
3006 {
3007 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3008 pTempEntry = csrLLNext( &pMac->scan.scanResultList, pEntry,
3009 LL_ACCESS_LOCK );
3010 if((pMac->scan.fEnableDFSChnlScan == DFS_CHNL_SCAN_DISABLED) &&
3011 CSR_IS_CHANNEL_DFS(pBssDesc->Result.BssDescriptor.channelId))
3012 {
3013 smsLog( pMac, LOG1, FL("%d is a DFS ch filtered from scan list"),
3014 pBssDesc->Result.BssDescriptor.channelId);
3015 /* Remove Scan result which does not have 11d channel */
3016 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry,
3017 LL_ACCESS_LOCK ))
3018 {
3019 csrFreeScanResultEntry( pMac, pBssDesc );
3020 }
3021 }
3022 else
3023 {
3024 smsLog( pMac, LOG1, FL("%d is a Valid channel"),
3025 pBssDesc->Result.BssDescriptor.channelId);
3026 }
3027 pEntry = pTempEntry;
3028 }
3029
3030 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
3031 while( pEntry )
3032 {
3033 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3034 pTempEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry,
3035 LL_ACCESS_LOCK );
3036
3037 if((pMac->scan.fEnableDFSChnlScan == DFS_CHNL_SCAN_DISABLED) &&
3038 CSR_IS_CHANNEL_DFS(pBssDesc->Result.BssDescriptor.channelId))
3039 {
3040 smsLog( pMac, LOG1, FL("%d is a DFS ch filtered from scan list"),
3041 pBssDesc->Result.BssDescriptor.channelId);
3042 /* Remove Scan result which does not have 11d channel */
3043 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry,
3044 LL_ACCESS_LOCK ))
3045 {
3046 csrFreeScanResultEntry( pMac, pBssDesc );
3047 }
3048 }
3049 else
3050 {
3051 smsLog( pMac, LOG1, FL("%d is a Valid channel"),
3052 pBssDesc->Result.BssDescriptor.channelId);
3053 }
3054 pEntry = pTempEntry;
3055 }
3056 return status;
3057}
3058
Jeff Johnson295189b2012-06-20 16:38:30 -07003059
3060eHalStatus csrScanCopyResultList(tpAniSirGlobal pMac, tScanResultHandle hIn, tScanResultHandle *phResult)
3061{
3062 eHalStatus status = eHAL_STATUS_SUCCESS;
3063 tScanResultList *pRetList, *pInList = (tScanResultList *)hIn;
3064 tCsrScanResult *pResult, *pScanResult;
3065 tANI_U32 count = 0;
3066 tListElem *pEntry;
3067 tANI_U32 bssLen, allocLen;
3068
3069 if(phResult)
3070 {
3071 *phResult = CSR_INVALID_SCANRESULT_HANDLE;
3072 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303073 pRetList = vos_mem_malloc(sizeof(tScanResultList));
3074 if ( NULL == pRetList )
3075 status = eHAL_STATUS_FAILURE;
3076 else
Jeff Johnson295189b2012-06-20 16:38:30 -07003077 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303078 vos_mem_set(pRetList, sizeof(tScanResultList), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003079 csrLLOpen(pMac->hHdd, &pRetList->List);
3080 pRetList->pCurEntry = NULL;
3081 csrLLLock(&pMac->scan.scanResultList);
3082 csrLLLock(&pInList->List);
3083
3084 pEntry = csrLLPeekHead( &pInList->List, LL_ACCESS_NOLOCK );
3085 while( pEntry )
3086 {
3087 pScanResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3088 bssLen = pScanResult->Result.BssDescriptor.length + sizeof(pScanResult->Result.BssDescriptor.length);
3089 allocLen = sizeof( tCsrScanResult ) + bssLen;
Kiet Lam64c1b492013-07-12 13:56:44 +05303090 pResult = vos_mem_malloc(allocLen);
3091 if ( NULL == pResult )
3092 status = eHAL_STATUS_FAILURE;
3093 else
3094 status = eHAL_STATUS_SUCCESS;
3095 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07003096 {
3097 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
3098 count = 0;
3099 break;
3100 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303101 vos_mem_set(pResult, allocLen , 0);
3102 vos_mem_copy(&pResult->Result.BssDescriptor, &pScanResult->Result.BssDescriptor, bssLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07003103 if( pScanResult->Result.pvIes )
3104 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303105 pResult->Result.pvIes = vos_mem_malloc(sizeof( tDot11fBeaconIEs ));
3106 if ( NULL == pResult->Result.pvIes )
3107 status = eHAL_STATUS_FAILURE;
3108 else
3109 status = eHAL_STATUS_SUCCESS;
3110 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07003111 {
3112 //Free the memory we allocate above first
Kiet Lam64c1b492013-07-12 13:56:44 +05303113 vos_mem_free(pResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07003114 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
3115 count = 0;
3116 break;
3117 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303118 vos_mem_copy(pResult->Result.pvIes, pScanResult->Result.pvIes,
3119 sizeof( tDot11fBeaconIEs ));
Jeff Johnson295189b2012-06-20 16:38:30 -07003120 }
3121 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_LOCK);
3122 count++;
3123 pEntry = csrLLNext( &pInList->List, pEntry, LL_ACCESS_NOLOCK );
3124 }//while
3125 csrLLUnlock(&pInList->List);
3126 csrLLUnlock(&pMac->scan.scanResultList);
3127
3128 if(HAL_STATUS_SUCCESS(status))
3129 {
3130 if(0 == count)
3131 {
3132 csrLLClose(&pRetList->List);
Kiet Lam64c1b492013-07-12 13:56:44 +05303133 vos_mem_free(pRetList);
Jeff Johnson295189b2012-06-20 16:38:30 -07003134 status = eHAL_STATUS_E_NULL_VALUE;
3135 }
3136 else if(phResult)
3137 {
3138 *phResult = pRetList;
3139 }
3140 }
3141 }//Allocated pRetList
3142
3143 return (status);
3144}
3145
3146
3147
3148eHalStatus csrScanningStateMsgProcessor( tpAniSirGlobal pMac, void *pMsgBuf )
3149{
3150 eHalStatus status = eHAL_STATUS_SUCCESS;
3151 tSirMbMsg *pMsg = (tSirMbMsg *)pMsgBuf;
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303152 tSirSmeDisConDoneInd *pDisConDoneInd;
Abhishek Singhf52182c2016-08-24 11:15:23 +05303153 tCsrRoamSession *pSession;
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303154 tCsrRoamInfo roamInfo = {0};
Jeff Johnson295189b2012-06-20 16:38:30 -07003155
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303156 if((eWNI_SME_SCAN_RSP == pMsg->type) ||
3157 (eWNI_SME_GET_SCANNED_CHANNEL_RSP == pMsg->type))
Jeff Johnson295189b2012-06-20 16:38:30 -07003158 {
3159 status = csrScanSmeScanResponse( pMac, pMsgBuf );
3160 }
3161 else
3162 {
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303163 switch (pMsg->type)
Jeff Johnson295189b2012-06-20 16:38:30 -07003164 {
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303165 case eWNI_SME_UPPER_LAYER_ASSOC_CNF:
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08003166 {
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303167 tSirSmeAssocIndToUpperLayerCnf *pUpperLayerAssocCnf;
3168 tCsrRoamInfo *pRoamInfo = NULL;
3169 tANI_U32 sessionId;
3170 eHalStatus status;
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08003171
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303172 smsLog( pMac, LOG1,
3173 FL("Scanning : ASSOCIATION confirmation can be given to upper layer "));
3174 pRoamInfo = &roamInfo;
3175 pUpperLayerAssocCnf = (tSirSmeAssocIndToUpperLayerCnf *)pMsgBuf;
3176 status = csrRoamGetSessionIdFromBSSID( pMac,
3177 (tCsrBssid *)pUpperLayerAssocCnf->bssId,
3178 &sessionId );
3179 pSession = CSR_GET_SESSION(pMac, sessionId);
3180
3181 if(!pSession)
3182 {
3183 smsLog(pMac, LOGE, FL("session %d not found "), sessionId);
3184 return eHAL_STATUS_FAILURE;
3185 }
3186
3187 //send the status code as Success
3188 pRoamInfo->statusCode = eSIR_SME_SUCCESS;
3189 pRoamInfo->u.pConnectedProfile = &pSession->connectedProfile;
3190 pRoamInfo->staId = (tANI_U8)pUpperLayerAssocCnf->aid;
3191 pRoamInfo->rsnIELen =
3192 (tANI_U8)pUpperLayerAssocCnf->rsnIE.length;
3193 pRoamInfo->prsnIE = pUpperLayerAssocCnf->rsnIE.rsnIEdata;
3194 pRoamInfo->addIELen =
3195 (tANI_U8)pUpperLayerAssocCnf->addIE.length;
3196 pRoamInfo->paddIE = pUpperLayerAssocCnf->addIE.addIEdata;
3197 vos_mem_copy(pRoamInfo->peerMac,
3198 pUpperLayerAssocCnf->peerMacAddr,
3199 sizeof(tSirMacAddr));
3200 vos_mem_copy(&pRoamInfo->bssid,
3201 pUpperLayerAssocCnf->bssId,
3202 sizeof(tCsrBssid));
3203 pRoamInfo->wmmEnabledSta = pUpperLayerAssocCnf->wmmEnabledSta;
Hardik Kantilal Patel1ba630f2014-11-21 04:32:05 +05303204#ifdef WLAN_FEATURE_AP_HT40_24G
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303205 pRoamInfo->HT40MHzIntoEnabledSta =
3206 pUpperLayerAssocCnf->HT40MHzIntoEnabledSta;
Hardik Kantilal Patel1ba630f2014-11-21 04:32:05 +05303207#endif
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303208 if(CSR_IS_INFRA_AP(pRoamInfo->u.pConnectedProfile) )
3209 {
3210 pMac->roam.roamSession[sessionId].connectState =
3211 eCSR_ASSOC_STATE_TYPE_INFRA_CONNECTED;
3212 pRoamInfo->fReassocReq = pUpperLayerAssocCnf->reassocReq;
3213 status = csrRoamCallCallback(pMac, sessionId, pRoamInfo,
3214 0, eCSR_ROAM_INFRA_IND,
3215 eCSR_ROAM_RESULT_INFRA_ASSOCIATION_CNF);
3216 }
3217 if(CSR_IS_WDS_AP( pRoamInfo->u.pConnectedProfile))
3218 {
3219 vos_sleep( 100 );
3220 pMac->roam.roamSession[sessionId].connectState =
3221 eCSR_ASSOC_STATE_TYPE_WDS_CONNECTED;//Sta
3222 status = csrRoamCallCallback(pMac, sessionId, pRoamInfo, 0,
3223 eCSR_ROAM_WDS_IND,
3224 eCSR_ROAM_RESULT_WDS_ASSOCIATION_IND);//Sta
3225 }
3226 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07003227 }
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303228 case eWNI_SME_DISCONNECT_DONE_IND:
3229 pDisConDoneInd = (tSirSmeDisConDoneInd *)(pMsg);
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08003230
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303231 smsLog( pMac, LOG1,
3232 FL("eWNI_SME_DISCONNECT_DONE_IND RC:%d"),
3233 pDisConDoneInd->reasonCode);
3234 if( CSR_IS_SESSION_VALID(pMac, pDisConDoneInd->sessionId))
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08003235 {
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303236 roamInfo.reasonCode = pDisConDoneInd->reasonCode;
3237 roamInfo.statusCode = eSIR_SME_STA_DISASSOCIATED;
3238 vos_mem_copy(roamInfo.peerMac, pDisConDoneInd->peerMacAddr,
3239 sizeof(tSirMacAddr));
3240 status = csrRoamCallCallback(pMac,
3241 pDisConDoneInd->sessionId,
3242 &roamInfo, 0,
3243 eCSR_ROAM_LOSTLINK,
3244 eCSR_ROAM_RESULT_DISASSOC_IND);
Abhishek Singhf52182c2016-08-24 11:15:23 +05303245 pSession = CSR_GET_SESSION(pMac,
3246 pDisConDoneInd->sessionId);
3247 /*
3248 * Update the previous state if
3249 * previous state was eCSR_ROAMING_STATE_JOINED
3250 * as we are disconnected and
3251 * currunt state is scanning
3252 */
3253 if (pSession &&
3254 !CSR_IS_INFRA_AP(&pSession->connectedProfile)
3255 && (eCSR_ROAMING_STATE_IDLE !=
3256 pMac->roam.prev_state[pDisConDoneInd->sessionId]))
3257 pMac->roam.prev_state[pDisConDoneInd->sessionId] =
3258 eCSR_ROAMING_STATE_IDLE;
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08003259 }
3260 else
3261 {
Hanumantha Reddy Pothuladc095f32015-11-30 20:50:23 +05303262 smsLog(pMac, LOGE, FL("Inactive session %d"),
3263 pDisConDoneInd->sessionId);
3264 status = eHAL_STATUS_FAILURE;
3265 }
3266 break;
3267
3268 default :
3269 if( csrIsAnySessionInConnectState( pMac ) )
3270 {
3271 /*In case of we are connected, we need to check whether connect
3272 * status changes because scan may also run while connected.
3273 */
3274 csrRoamCheckForLinkStatusChange( pMac, (tSirSmeRsp *)pMsgBuf );
3275 }
3276 else
3277 {
3278 smsLog( pMac, LOGW,
3279 "Message [0x%04x] received in state, when expecting Scan Response",
3280 pMsg->type );
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08003281 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003282 }
3283 }
3284
3285 return (status);
3286}
3287
3288
3289
3290void csrCheckNSaveWscIe(tpAniSirGlobal pMac, tSirBssDescription *pNewBssDescr, tSirBssDescription *pOldBssDescr)
3291{
3292 int idx, len;
3293 tANI_U8 *pbIe;
3294
3295 //If failed to remove, assuming someone else got it.
3296 if((pNewBssDescr->fProbeRsp != pOldBssDescr->fProbeRsp) &&
3297 (0 == pNewBssDescr->WscIeLen))
3298 {
3299 idx = 0;
3300 len = pOldBssDescr->length - sizeof(tSirBssDescription) +
3301 sizeof(tANI_U16) + sizeof(tANI_U32) - DOT11F_IE_WSCPROBERES_MIN_LEN - 2;
3302 pbIe = (tANI_U8 *)pOldBssDescr->ieFields;
3303 //Save WPS IE if it exists
3304 pNewBssDescr->WscIeLen = 0;
3305 while(idx < len)
3306 {
3307 if((DOT11F_EID_WSCPROBERES == pbIe[0]) &&
3308 (0x00 == pbIe[2]) && (0x50 == pbIe[3]) && (0xf2 == pbIe[4]) && (0x04 == pbIe[5]))
3309 {
3310 //Founrd it
3311 if((DOT11F_IE_WSCPROBERES_MAX_LEN - 2) >= pbIe[1])
3312 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303313 vos_mem_copy(pNewBssDescr->WscIeProbeRsp, pbIe, pbIe[1] + 2);
Jeff Johnson295189b2012-06-20 16:38:30 -07003314 pNewBssDescr->WscIeLen = pbIe[1] + 2;
3315 }
3316 break;
3317 }
3318 idx += pbIe[1] + 2;
3319 pbIe += pbIe[1] + 2;
3320 }
3321 }
3322}
3323
3324
3325
3326//pIes may be NULL
3327tANI_BOOLEAN csrRemoveDupBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDescr,
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05303328 tDot11fBeaconIEs *pIes, tAniSSID *pSsid, v_TIME_t *timer, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07003329{
3330 tListElem *pEntry;
3331
3332 tCsrScanResult *pBssDesc;
3333 tANI_BOOLEAN fRC = FALSE;
3334
3335 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
3336 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
3337 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
3338 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
3339
3340 while( pEntry )
3341 {
3342 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3343
3344 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
3345 // matches
3346 if ( csrIsDuplicateBssDescription( pMac, &pBssDesc->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07003347 pSirBssDescr, pIes, fForced ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003348 {
3349 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
3350 ((tANI_S32)pBssDesc->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
3351 // Remove the 'old' entry from the list....
3352 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry, LL_ACCESS_LOCK ) )
3353 {
3354 // !we need to free the memory associated with this node
3355 //If failed to remove, assuming someone else got it.
3356 *pSsid = pBssDesc->Result.ssId;
3357 *timer = pBssDesc->Result.timer;
3358 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pBssDesc->Result.BssDescriptor);
3359
3360 csrFreeScanResultEntry( pMac, pBssDesc );
3361 }
3362 else
3363 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003364 smsLog( pMac, LOGW, FL( " fail to remove entry" ) );
Jeff Johnson295189b2012-06-20 16:38:30 -07003365 }
3366 fRC = TRUE;
3367
3368 // If we found a match, we can stop looking through the list.
3369 break;
3370 }
3371
3372 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_LOCK );
3373 }
3374
3375 return fRC;
3376}
3377
3378
3379eHalStatus csrAddPMKIDCandidateList( tpAniSirGlobal pMac, tANI_U32 sessionId,
3380 tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes )
3381{
3382 eHalStatus status = eHAL_STATUS_FAILURE;
3383 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
3384
Jeff Johnson32d95a32012-09-10 13:15:23 -07003385 if(!pSession)
3386 {
3387 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
3388 return eHAL_STATUS_FAILURE;
3389 }
3390
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003391 smsLog(pMac, LOGW, "csrAddPMKIDCandidateList called pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07003392 if( pIes )
3393 {
3394 // check if this is a RSN BSS
3395 if( pIes->RSN.present )
3396 {
3397 // Check if the BSS is capable of doing pre-authentication
3398 if( pSession->NumPmkidCandidate < CSR_MAX_PMKID_ALLOWED )
3399 {
3400
3401#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3402 {
3403 WLAN_VOS_DIAG_EVENT_DEF(secEvent, vos_event_wlan_security_payload_type);
Kiet Lam64c1b492013-07-12 13:56:44 +05303404 vos_mem_set(&secEvent, sizeof(vos_event_wlan_security_payload_type), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003405 secEvent.eventId = WLAN_SECURITY_EVENT_PMKID_CANDIDATE_FOUND;
3406 secEvent.encryptionModeMulticast =
3407 (v_U8_t)diagEncTypeFromCSRType(pSession->connectedProfile.mcEncryptionType);
3408 secEvent.encryptionModeUnicast =
3409 (v_U8_t)diagEncTypeFromCSRType(pSession->connectedProfile.EncryptionType);
Kiet Lam64c1b492013-07-12 13:56:44 +05303410 vos_mem_copy(secEvent.bssid, pSession->connectedProfile.bssid, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07003411 secEvent.authMode =
3412 (v_U8_t)diagAuthTypeFromCSRType(pSession->connectedProfile.AuthType);
3413 WLAN_VOS_DIAG_EVENT_REPORT(&secEvent, EVENT_WLAN_SECURITY);
3414 }
3415#endif//#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3416
3417 // if yes, then add to PMKIDCandidateList
Kiet Lam64c1b492013-07-12 13:56:44 +05303418 vos_mem_copy(pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].BSSID,
3419 pBssDesc->bssId, WNI_CFG_BSSID_LEN);
3420 // Bit 0 offirst byte - PreAuthentication Capability
3421 if ( (pIes->RSN.RSN_Cap[0] >> 0) & 0x1 )
Jeff Johnson295189b2012-06-20 16:38:30 -07003422 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303423 pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].preAuthSupported
3424 = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003425 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303426 else
3427 {
3428 pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].preAuthSupported
3429 = eANI_BOOLEAN_FALSE;
3430 }
3431 pSession->NumPmkidCandidate++;
Jeff Johnson295189b2012-06-20 16:38:30 -07003432 }
3433 else
3434 {
3435 status = eHAL_STATUS_FAILURE;
3436 }
3437 }
3438 }
3439
3440 return (status);
3441}
3442
3443//This function checks whether new AP is found for the current connected profile
3444//If it is found, it return the sessionId, else it return invalid sessionID
3445tANI_U32 csrProcessBSSDescForPMKIDList(tpAniSirGlobal pMac,
3446 tSirBssDescription *pBssDesc,
3447 tDot11fBeaconIEs *pIes)
3448{
3449 tANI_U32 i, bRet = CSR_SESSION_ID_INVALID;
3450 tCsrRoamSession *pSession;
3451 tDot11fBeaconIEs *pIesLocal = pIes;
3452
3453 if( pIesLocal || HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIesLocal)) )
3454 {
3455 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
3456 {
3457 if( CSR_IS_SESSION_VALID( pMac, i ) )
3458 {
3459 pSession = CSR_GET_SESSION( pMac, i );
3460 if( csrIsConnStateConnectedInfra( pMac, i ) &&
3461 ( eCSR_AUTH_TYPE_RSN == pSession->connectedProfile.AuthType ) )
3462 {
3463 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile, pBssDesc, pIesLocal))
3464 {
3465 //this new BSS fits the current profile connected
3466 if(HAL_STATUS_SUCCESS(csrAddPMKIDCandidateList(pMac, i, pBssDesc, pIesLocal)))
3467 {
3468 bRet = i;
3469 }
3470 break;
3471 }
3472 }
3473 }
3474 }
3475 if( !pIes )
3476 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303477 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003478 }
3479 }
3480
3481 return (tANI_U8)bRet;
3482}
3483
3484#ifdef FEATURE_WLAN_WAPI
3485eHalStatus csrAddBKIDCandidateList( tpAniSirGlobal pMac, tANI_U32 sessionId,
3486 tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes )
3487{
3488 eHalStatus status = eHAL_STATUS_FAILURE;
3489 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
3490
Jeff Johnson32d95a32012-09-10 13:15:23 -07003491 if(!pSession)
3492 {
3493 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
3494 return eHAL_STATUS_FAILURE;
3495 }
3496
Kiet Lam64c1b492013-07-12 13:56:44 +05303497 smsLog(pMac, LOGW, "csrAddBKIDCandidateList called pMac->scan.NumBkidCandidate = %d",
3498 pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07003499 if( pIes )
3500 {
3501 // check if this is a WAPI BSS
3502 if( pIes->WAPI.present )
3503 {
3504 // Check if the BSS is capable of doing pre-authentication
3505 if( pSession->NumBkidCandidate < CSR_MAX_BKID_ALLOWED )
3506 {
3507
3508 // if yes, then add to BKIDCandidateList
Kiet Lam64c1b492013-07-12 13:56:44 +05303509 vos_mem_copy(pSession->BkidCandidateInfo[pSession->NumBkidCandidate].BSSID,
3510 pBssDesc->bssId, WNI_CFG_BSSID_LEN);
3511 if ( pIes->WAPI.preauth )
Jeff Johnson295189b2012-06-20 16:38:30 -07003512 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303513 pSession->BkidCandidateInfo[pSession->NumBkidCandidate].preAuthSupported
3514 = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003515 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303516 else
3517 {
3518 pSession->BkidCandidateInfo[pSession->NumBkidCandidate].preAuthSupported
3519 = eANI_BOOLEAN_FALSE;
3520 }
3521 pSession->NumBkidCandidate++;
Jeff Johnson295189b2012-06-20 16:38:30 -07003522 }
3523 else
3524 {
3525 status = eHAL_STATUS_FAILURE;
3526 }
3527 }
3528 }
3529
3530 return (status);
3531}
3532
3533//This function checks whether new AP is found for the current connected profile
3534//if so add to BKIDCandidateList
3535tANI_BOOLEAN csrProcessBSSDescForBKIDList(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
3536 tDot11fBeaconIEs *pIes)
3537{
3538 tANI_BOOLEAN fRC = FALSE;
3539 tDot11fBeaconIEs *pIesLocal = pIes;
3540 tANI_U32 sessionId;
3541 tCsrRoamSession *pSession;
3542
3543 if( pIesLocal || HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIesLocal)) )
3544 {
3545 for( sessionId = 0; sessionId < CSR_ROAM_SESSION_MAX; sessionId++ )
3546 {
3547 if( CSR_IS_SESSION_VALID( pMac, sessionId) )
3548 {
3549 pSession = CSR_GET_SESSION( pMac, sessionId );
3550 if( csrIsConnStateConnectedInfra( pMac, sessionId ) &&
3551 eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE == pSession->connectedProfile.AuthType)
3552 {
3553 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile,pBssDesc, pIesLocal))
3554 {
3555 //this new BSS fits the current profile connected
3556 if(HAL_STATUS_SUCCESS(csrAddBKIDCandidateList(pMac, sessionId, pBssDesc, pIesLocal)))
3557 {
3558 fRC = TRUE;
3559 }
3560 }
3561 }
3562 }
3563 }
3564 if(!pIes)
3565 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303566 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003567 }
3568
3569 }
3570 return fRC;
3571}
3572
3573#endif
3574
3575
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07003576static void csrMoveTempScanResultsToMainList( tpAniSirGlobal pMac, tANI_U8 reason )
Jeff Johnson295189b2012-06-20 16:38:30 -07003577{
3578 tListElem *pEntry;
3579 tCsrScanResult *pBssDescription;
Jeff Johnson295189b2012-06-20 16:38:30 -07003580 tANI_BOOLEAN fDupBss;
3581#ifdef FEATURE_WLAN_WAPI
3582 tANI_BOOLEAN fNewWapiBSSForCurConnection = eANI_BOOLEAN_FALSE;
3583#endif /* FEATURE_WLAN_WAPI */
3584 tDot11fBeaconIEs *pIesLocal = NULL;
3585 tANI_U32 sessionId = CSR_SESSION_ID_INVALID;
3586 tAniSSID tmpSsid;
3587 v_TIME_t timer=0;
3588
3589 tmpSsid.length = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07003590
3591 // remove the BSS descriptions from temporary list
3592 while( ( pEntry = csrLLRemoveTail( &pMac->scan.tempScanResults, LL_ACCESS_LOCK ) ) != NULL)
3593 {
3594 pBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3595
Vinay Krishna Eranna566365f2015-03-09 12:34:13 +05303596 smsLog( pMac, LOG2, "...Bssid= "MAC_ADDRESS_STR" chan= %d, rssi = -%d",
Arif Hussain24bafea2013-11-15 15:10:03 -08003597 MAC_ADDR_ARRAY(pBssDescription->Result.BssDescriptor.bssId),
Jeff Johnson295189b2012-06-20 16:38:30 -07003598 pBssDescription->Result.BssDescriptor.channelId,
3599 pBssDescription->Result.BssDescriptor.rssi * (-1) );
3600
3601 //At this time, pBssDescription->Result.pvIes may be NULL
3602 pIesLocal = (tDot11fBeaconIEs *)( pBssDescription->Result.pvIes );
3603 if( !pIesLocal && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pBssDescription->Result.BssDescriptor, &pIesLocal))) )
3604 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003605 smsLog(pMac, LOGE, FL(" Cannot pared IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003606 csrFreeScanResultEntry(pMac, pBssDescription);
3607 continue;
3608 }
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05303609 fDupBss = csrRemoveDupBssDescription( pMac, &pBssDescription->Result.BssDescriptor, pIesLocal, &tmpSsid, &timer, FALSE );
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07003610 //Check whether we have reach out limit, but don't lose the LFR candidates came from FW
3611 if( CSR_SCAN_IS_OVER_BSS_LIMIT(pMac)
3612#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
3613 && !( eCsrScanGetLfrResult == reason )
3614#endif
3615 )
Jeff Johnson295189b2012-06-20 16:38:30 -07003616 {
Deepthi Gowri50e2fa52016-03-17 15:30:53 +05303617 smsLog(pMac, LOG1, FL("########## BSS Limit reached ###########"));
3618 csrPurgeOldScanResults(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07003619 }
3620 // check for duplicate scan results
3621 if ( !fDupBss )
3622 {
3623 //Found a new BSS
3624 sessionId = csrProcessBSSDescForPMKIDList(pMac,
3625 &pBssDescription->Result.BssDescriptor, pIesLocal);
3626 if( CSR_SESSION_ID_INVALID != sessionId)
3627 {
3628 csrRoamCallCallback(pMac, sessionId, NULL, 0,
3629 eCSR_ROAM_SCAN_FOUND_NEW_BSS, eCSR_ROAM_RESULT_NONE);
3630 }
3631 }
3632 else
3633 {
3634 //Check if the new one has SSID it it, if not, use the older SSID if it exists.
3635 if( (0 == pBssDescription->Result.ssId.length) && tmpSsid.length )
3636 {
3637 //New BSS has a hidden SSID and old one has the SSID. Keep the SSID only
3638 //if diff of saved SSID time and current time is less than 1 min to avoid
3639 //side effect of saving SSID with old one is that if AP changes its SSID while remain
3640 //hidden, we may never see it and also to address the requirement of
3641 //When we remove hidden ssid from the profile i.e., forget the SSID via
3642 // GUI that SSID shouldn't see in the profile
3643 if( (vos_timer_get_system_time() - timer) <= HIDDEN_TIMER)
3644 {
3645 pBssDescription->Result.timer = timer;
3646 pBssDescription->Result.ssId = tmpSsid;
3647 }
3648 }
3649 }
3650
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303651 //Find a good AP for 11d info
3652 if ( csrIs11dSupported( pMac ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003653 {
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303654 // check if country information element is present
3655 if (pIesLocal->Country.present)
Jeff Johnson295189b2012-06-20 16:38:30 -07003656 {
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303657 csrAddVoteForCountryInfo(pMac, pIesLocal->Country.country);
3658 smsLog(pMac, LOGW, FL("11d AP Bssid " MAC_ADDRESS_STR
3659 " chan= %d, rssi = -%d, countryCode %c%c"),
3660 MAC_ADDR_ARRAY( pBssDescription->Result.BssDescriptor.bssId),
3661 pBssDescription->Result.BssDescriptor.channelId,
3662 pBssDescription->Result.BssDescriptor.rssi * (-1),
3663 pIesLocal->Country.country[0],pIesLocal->Country.country[1] );
3664 }
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303665
Jeff Johnson295189b2012-06-20 16:38:30 -07003666 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08003667
Jeff Johnson295189b2012-06-20 16:38:30 -07003668 // append to main list
3669 csrScanAddResult(pMac, pBssDescription, pIesLocal);
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303670 if ( (pBssDescription->Result.pvIes == NULL) && pIesLocal )
Jeff Johnson295189b2012-06-20 16:38:30 -07003671 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303672 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003673 }
3674 }
3675
Sushant Kaushik6274de62015-05-01 16:31:23 +05303676 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
Tushnim Bhattacharyyaae317772013-10-23 18:55:38 -07003677 //we don't need to update CC while connected to an AP which is advertising CC already
3678 if (csrIs11dSupported(pMac))
3679 {
3680 tANI_U32 i;
3681 tCsrRoamSession *pSession;
3682
3683 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
3684 {
3685 if (CSR_IS_SESSION_VALID( pMac, i ) )
3686 {
3687 pSession = CSR_GET_SESSION( pMac, i );
3688 if (csrIsConnStateConnected(pMac, i))
3689 {
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303690 smsLog(pMac, LOGW, FL("No need for updating CC in"
3691 "connected state"));
3692 goto end;
Tushnim Bhattacharyyaae317772013-10-23 18:55:38 -07003693 }
3694 }
3695 }
Agrawal Ashishbd3a5932016-04-12 16:22:39 +05303696 if (csrElectedCountryInfo(pMac))
3697 csrLearnCountryInformation(pMac, NULL, NULL,
3698 eANI_BOOLEAN_TRUE);
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303699 }
3700
Tushnim Bhattacharyyaae317772013-10-23 18:55:38 -07003701end:
3702 //If we can find the current 11d info in any of the scan results, or
Jeff Johnson295189b2012-06-20 16:38:30 -07003703 // a good enough AP with the 11d info from the scan results then no need to
3704 // get into ambiguous state
3705 if(pMac->scan.fAmbiguous11dInfoFound)
3706 {
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303707 if((pMac->scan.fCurrent11dInfoMatch))
Jeff Johnson295189b2012-06-20 16:38:30 -07003708 {
3709 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
3710 }
3711 }
3712
3713#ifdef FEATURE_WLAN_WAPI
3714 if(fNewWapiBSSForCurConnection)
3715 {
3716 //remember it first
3717 csrRoamCallCallback(pMac, sessionId, NULL, 0, eCSR_ROAM_SCAN_FOUND_NEW_BSS, eCSR_ROAM_RESULT_NEW_WAPI_BSS);
3718 }
3719#endif /* FEATURE_WLAN_WAPI */
3720
3721 return;
3722}
3723
Deepthi Gowri50e2fa52016-03-17 15:30:53 +05303724void csrPurgeOldScanResults(tpAniSirGlobal pMac)
3725{
3726 tListElem *pEntry, *tmpEntry;
3727 tCsrScanResult *pResult, *oldest_bss = NULL;
Deepthi Gowri4480a3f2016-05-18 19:30:17 +05303728 v_TIME_t oldest_entry = 0;
3729 v_TIME_t curTime = vos_timer_get_system_time();
Deepthi Gowri50e2fa52016-03-17 15:30:53 +05303730
3731 csrLLLock(&pMac->scan.scanResultList);
3732 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
3733 while( pEntry )
3734 {
3735 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry,
3736 LL_ACCESS_NOLOCK);
3737 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3738 if((curTime -
3739 pResult->Result.BssDescriptor.nReceivedTime) > oldest_entry)
3740 {
3741 oldest_entry = curTime -
3742 pResult->Result.BssDescriptor.nReceivedTime;
3743 oldest_bss = pResult;
3744 }
3745 pEntry = tmpEntry;
3746 }
3747 if (oldest_bss)
3748 {
3749 //Free the old BSS Entries
3750 if( csrLLRemoveEntry(&pMac->scan.scanResultList,
3751 &oldest_bss->Link, LL_ACCESS_NOLOCK) )
3752 {
Deepthi Gowri6a08e312016-03-31 19:10:14 +05303753 smsLog(pMac, LOG1, FL(" Current time delta (%lu) of BSSID to be removed" MAC_ADDRESS_STR ),
Deepthi Gowri50e2fa52016-03-17 15:30:53 +05303754 (curTime - oldest_bss->Result.BssDescriptor.nReceivedTime),
3755 MAC_ADDR_ARRAY(oldest_bss->Result.BssDescriptor.bssId));
3756 csrFreeScanResultEntry(pMac, oldest_bss);
3757 }
3758 }
3759 csrLLUnlock(&pMac->scan.scanResultList);
3760}
Jeff Johnson295189b2012-06-20 16:38:30 -07003761
3762static tCsrScanResult *csrScanSaveBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pBSSDescription,
3763 tDot11fBeaconIEs *pIes)
3764{
3765 tCsrScanResult *pCsrBssDescription = NULL;
3766 tANI_U32 cbBSSDesc;
3767 tANI_U32 cbAllocated;
Sushant Kaushik6274de62015-05-01 16:31:23 +05303768 tListElem *pEntry;
Jeff Johnson295189b2012-06-20 16:38:30 -07003769
3770 // figure out how big the BSS description is (the BSSDesc->length does NOT
3771 // include the size of the length field itself).
3772 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
3773
3774 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
3775
Kiet Lam64c1b492013-07-12 13:56:44 +05303776 pCsrBssDescription = vos_mem_malloc(cbAllocated);
3777 if ( NULL != pCsrBssDescription )
Jeff Johnson295189b2012-06-20 16:38:30 -07003778 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303779 vos_mem_set(pCsrBssDescription, cbAllocated, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003780 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Kiet Lam64c1b492013-07-12 13:56:44 +05303781 vos_mem_copy(&pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc);
Jeff Johnson295189b2012-06-20 16:38:30 -07003782#if defined(VOSS_ENSBALED)
3783 VOS_ASSERT( pCsrBssDescription->Result.pvIes == NULL );
3784#endif
3785 csrScanAddResult(pMac, pCsrBssDescription, pIes);
Sushant Kaushik6274de62015-05-01 16:31:23 +05303786 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
Jeff Johnson295189b2012-06-20 16:38:30 -07003787 }
3788
3789 return( pCsrBssDescription );
3790}
3791
3792// Append a Bss Description...
3793tCsrScanResult *csrScanAppendBssDescription( tpAniSirGlobal pMac,
3794 tSirBssDescription *pSirBssDescription,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07003795 tDot11fBeaconIEs *pIes, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07003796{
3797 tCsrScanResult *pCsrBssDescription = NULL;
3798 tAniSSID tmpSsid;
3799 v_TIME_t timer = 0;
3800 int result;
3801
3802 tmpSsid.length = 0;
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07003803 result = csrRemoveDupBssDescription( pMac, pSirBssDescription, pIes, &tmpSsid, &timer, fForced );
Jeff Johnson295189b2012-06-20 16:38:30 -07003804 pCsrBssDescription = csrScanSaveBssDescription( pMac, pSirBssDescription, pIes );
3805 if (result && (pCsrBssDescription != NULL))
3806 {
3807 //Check if the new one has SSID it it, if not, use the older SSID if it exists.
3808 if( (0 == pCsrBssDescription->Result.ssId.length) && tmpSsid.length )
3809 {
3810 //New BSS has a hidden SSID and old one has the SSID. Keep the SSID only
3811 //if diff of saved SSID time and current time is less than 1 min to avoid
3812 //side effect of saving SSID with old one is that if AP changes its SSID while remain
3813 //hidden, we may never see it and also to address the requirement of
3814 //When we remove hidden ssid from the profile i.e., forget the SSID via
3815 // GUI that SSID shouldn't see in the profile
3816 if((vos_timer_get_system_time()-timer) <= HIDDEN_TIMER)
3817 {
3818 pCsrBssDescription->Result.ssId = tmpSsid;
3819 pCsrBssDescription->Result.timer = timer;
3820 }
3821 }
3822 }
3823
3824
3825 return( pCsrBssDescription );
3826}
3827
3828
3829
3830void csrPurgeChannelPower( tpAniSirGlobal pMac, tDblLinkList *pChannelList )
3831{
3832 tCsrChannelPowerInfo *pChannelSet;
3833 tListElem *pEntry;
3834
3835 csrLLLock(pChannelList);
3836 // Remove the channel sets from the learned list and put them in the free list
3837 while( ( pEntry = csrLLRemoveHead( pChannelList, LL_ACCESS_NOLOCK ) ) != NULL)
3838 {
3839 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3840 if( pChannelSet )
3841 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303842 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003843 }
3844 }
3845 csrLLUnlock(pChannelList);
3846 return;
3847}
3848
3849
3850/*
3851 * Save the channelList into the ultimate storage as the final stage of channel
3852 * Input: pCountryInfo -- the country code (e.g. "USI"), channel list, and power limit are all stored inside this data structure
3853 */
Jeff Johnsone7245742012-09-05 17:12:55 -07003854eHalStatus csrSaveToChannelPower2G_5G( tpAniSirGlobal pMac, tANI_U32 tableSize, tSirMacChanInfo *channelTable )
Jeff Johnson295189b2012-06-20 16:38:30 -07003855{
3856 tANI_U32 i = tableSize / sizeof( tSirMacChanInfo );
3857 tSirMacChanInfo *pChannelInfo;
3858 tCsrChannelPowerInfo *pChannelSet;
3859 tANI_BOOLEAN f2GHzInfoFound = FALSE;
3860 tANI_BOOLEAN f2GListPurged = FALSE, f5GListPurged = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003861
3862 pChannelInfo = channelTable;
3863 // atleast 3 bytes have to be remaining -- from "countryString"
3864 while ( i-- )
3865 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303866 pChannelSet = vos_mem_malloc(sizeof(tCsrChannelPowerInfo));
3867 if ( NULL != pChannelSet )
Jeff Johnson295189b2012-06-20 16:38:30 -07003868 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303869 vos_mem_set(pChannelSet, sizeof(tCsrChannelPowerInfo), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003870 pChannelSet->firstChannel = pChannelInfo->firstChanNum;
3871 pChannelSet->numChannels = pChannelInfo->numChannels;
3872
3873 // Now set the inter-channel offset based on the frequency band the channel set lies in
Jeff Johnsone7245742012-09-05 17:12:55 -07003874 if( (CSR_IS_CHANNEL_24GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003875 ((pChannelSet->firstChannel + (pChannelSet->numChannels - 1)) <= CSR_MAX_24GHz_CHANNEL_NUMBER) )
Jeff Johnsone7245742012-09-05 17:12:55 -07003876
Jeff Johnson295189b2012-06-20 16:38:30 -07003877 {
3878 pChannelSet->interChannelOffset = 1;
3879 f2GHzInfoFound = TRUE;
3880 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003881 else if ( (CSR_IS_CHANNEL_5GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003882 ((pChannelSet->firstChannel + ((pChannelSet->numChannels - 1) * 4)) <= CSR_MAX_5GHz_CHANNEL_NUMBER) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003883 {
3884 pChannelSet->interChannelOffset = 4;
3885 f2GHzInfoFound = FALSE;
3886 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003887 else
3888 {
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003889 smsLog( pMac, LOGW, FL("Invalid Channel %d Present in Country IE"),
Jeff Johnsone7245742012-09-05 17:12:55 -07003890 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303891 vos_mem_free(pChannelSet);
Jeff Johnsone7245742012-09-05 17:12:55 -07003892 return eHAL_STATUS_FAILURE;
3893 }
3894
Jeff Johnson295189b2012-06-20 16:38:30 -07003895 pChannelSet->txPower = CSR_ROAM_MIN( pChannelInfo->maxTxPower, pMac->roam.configParam.nTxPowerCap );
3896
3897 if( f2GHzInfoFound )
3898 {
3899 if( !f2GListPurged )
3900 {
3901 // purge previous results if found new
3902 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList24 );
3903 f2GListPurged = TRUE;
3904 }
3905
3906 if(CSR_IS_OPERATING_BG_BAND(pMac))
3907 {
3908 // add to the list of 2.4 GHz channel sets
3909 csrLLInsertTail( &pMac->scan.channelPowerInfoList24, &pChannelSet->link, LL_ACCESS_LOCK );
3910 }
3911 else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003912 smsLog( pMac, LOGW, FL("Adding 11B/G channels in 11A mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003913 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303914 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003915 }
3916 }
3917 else
3918 {
3919 // 5GHz info found
3920 if( !f5GListPurged )
3921 {
3922 // purge previous results if found new
3923 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList5G );
3924 f5GListPurged = TRUE;
3925 }
3926
3927 if(CSR_IS_OPERATING_A_BAND(pMac))
3928 {
3929 // add to the list of 5GHz channel sets
3930 csrLLInsertTail( &pMac->scan.channelPowerInfoList5G, &pChannelSet->link, LL_ACCESS_LOCK );
3931 }
3932 else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003933 smsLog( pMac, LOGW, FL("Adding 11A channels in B/G mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003934 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303935 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003936 }
3937 }
3938 }
3939
3940 pChannelInfo++; // move to next entry
3941 }
3942
Jeff Johnsone7245742012-09-05 17:12:55 -07003943 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07003944}
3945
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303946static void csrClearDfsChannelList( tpAniSirGlobal pMac )
3947{
3948 tSirMbMsg *pMsg;
3949 tANI_U16 msgLen;
Jeff Johnson295189b2012-06-20 16:38:30 -07003950
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303951 msgLen = (tANI_U16)(sizeof( tSirMbMsg ));
Kiet Lam64c1b492013-07-12 13:56:44 +05303952 pMsg = vos_mem_malloc(msgLen);
3953 if ( NULL != pMsg )
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303954 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303955 vos_mem_set((void *)pMsg, msgLen, 0);
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303956 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_CLEAR_DFS_CHANNEL_LIST);
3957 pMsg->msgLen = pal_cpu_to_be16(msgLen);
3958 palSendMBMessage(pMac->hHdd, pMsg);
3959 }
3960}
Jeff Johnson295189b2012-06-20 16:38:30 -07003961
3962void csrApplyPower2Current( tpAniSirGlobal pMac )
3963{
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003964 smsLog( pMac, LOG3, FL(" Updating Cfg with power settings"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003965 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList24, WNI_CFG_MAX_TX_POWER_2_4 );
3966 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList5G, WNI_CFG_MAX_TX_POWER_5 );
3967}
3968
3969
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003970void csrApplyChannelPowerCountryInfo( tpAniSirGlobal pMac, tCsrChannel *pChannelList, tANI_U8 *countryCode, tANI_BOOLEAN updateRiva)
Jeff Johnson295189b2012-06-20 16:38:30 -07003971{
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303972 int i, j, count, countryIndex = -1;
Jeff Johnson295189b2012-06-20 16:38:30 -07003973 tANI_U8 numChannels = 0;
3974 tANI_U8 tempNumChannels = 0;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303975 tANI_U8 channelIgnore = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003976 tCsrChannel ChannelList;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303977
Jeff Johnson295189b2012-06-20 16:38:30 -07003978 if( pChannelList->numChannels )
3979 {
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303980 for(count=0; count < MAX_COUNTRY_IGNORE; count++)
3981 {
3982 if(vos_mem_compare(countryCode, countryIgnoreList[count].countryCode,
3983 VOS_COUNTRY_CODE_LEN))
3984 {
3985 countryIndex = count;
3986 break;
3987 }
3988 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003989 tempNumChannels = CSR_MIN(pChannelList->numChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN);
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05303990
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303991 for(i=0; i < tempNumChannels; i++)
Jeff Johnson295189b2012-06-20 16:38:30 -07003992 {
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303993 channelIgnore = FALSE;
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05303994 if( countryIndex != -1 )
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303995 {
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05303996 for(j=0; j < countryIgnoreList[countryIndex].channelCount; j++)
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303997 {
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05303998 if( pChannelList->channelList[i] ==
3999 countryIgnoreList[countryIndex].channelList[j] )
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304000 {
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05304001 channelIgnore = TRUE;
4002 break;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304003 }
4004 }
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05304005 }
4006 if( FALSE == channelIgnore )
4007 {
4008 ChannelList.channelList[numChannels] = pChannelList->channelList[i];
4009 numChannels++;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304010 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004011 }
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304012 ChannelList.numChannels = numChannels;
Mahesh A Saptasagar1ed59582014-06-04 18:45:07 +05304013 csrApplyPower2Current( pMac ); // Store the channel+power info in the global place: Cfg
Jeff Johnson295189b2012-06-20 16:38:30 -07004014 csrSetCfgValidChannelList(pMac, ChannelList.channelList, ChannelList.numChannels);
4015 // extend scan capability
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05304016 // build a scan list based on the channel list : channel# + active/passive scan
4017 csrSetCfgScanControlList(pMac, countryCode, &ChannelList);
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05304018 /*Send msg to Lim to clear DFS channel list */
4019 csrClearDfsChannelList(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07004020#ifdef FEATURE_WLAN_SCAN_PNO
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004021 if (updateRiva)
4022 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004023 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO, FL(" Sending 11d PNO info to Riva"));
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004024 // Send HAL UpdateScanParams message
4025 pmcUpdateScanParams(pMac, &(pMac->roam.configParam), &ChannelList, TRUE);
4026 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004027#endif // FEATURE_WLAN_SCAN_PNO
4028 }
4029 else
4030 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004031 smsLog( pMac, LOGE, FL(" 11D channel list is empty"));
Jeff Johnson295189b2012-06-20 16:38:30 -07004032 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004033 csrSetCfgCountryCode(pMac, countryCode);
4034}
4035
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004036void csrResetCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce, tANI_BOOLEAN updateRiva )
Jeff Johnson295189b2012-06-20 16:38:30 -07004037{
4038 if( fForce || (csrIs11dSupported( pMac ) && (!pMac->scan.f11dInfoReset)))
4039 {
4040
4041#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4042 {
4043 vos_log_802_11d_pkt_type *p11dLog;
4044 int Index;
4045
4046 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
4047 if(p11dLog)
4048 {
4049 p11dLog->eventId = WLAN_80211D_EVENT_RESET;
Kiet Lam64c1b492013-07-12 13:56:44 +05304050 vos_mem_copy(p11dLog->countryCode, pMac->scan.countryCodeCurrent, 3);
Jeff Johnson295189b2012-06-20 16:38:30 -07004051 p11dLog->numChannel = pMac->scan.base20MHzChannels.numChannels;
4052 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
4053 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304054 vos_mem_copy(p11dLog->Channels,
4055 pMac->scan.base20MHzChannels.channelList,
4056 p11dLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07004057 for (Index=0; Index < pMac->scan.base20MHzChannels.numChannels; Index++)
4058 {
4059 p11dLog->TxPwr[Index] = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
4060 }
4061 }
4062 if(!pMac->roam.configParam.Is11dSupportEnabled)
4063 {
4064 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
4065 }
4066 else if(pMac->roam.configParam.fEnforceDefaultDomain)
4067 {
4068 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
4069 }
4070 else
4071 {
4072 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
4073 }
4074 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
4075 }
4076 }
4077#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4078
Jeff Johnson04dd8a82012-06-29 20:41:40 -07004079 csrPruneChannelListForMode(pMac, &pMac->scan.baseChannels);
4080 csrPruneChannelListForMode(pMac, &pMac->scan.base20MHzChannels);
4081
Jeff Johnson295189b2012-06-20 16:38:30 -07004082 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_FALSE);
4083 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_TRUE);
4084 // ... and apply the channel list, power settings, and the country code.
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004085 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.base20MHzChannels, pMac->scan.countryCodeCurrent, updateRiva );
Jeff Johnson295189b2012-06-20 16:38:30 -07004086 // clear the 11d channel list
Kiet Lam64c1b492013-07-12 13:56:44 +05304087 vos_mem_set(&pMac->scan.channels11d, sizeof(pMac->scan.channels11d), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004088 pMac->scan.f11dInfoReset = eANI_BOOLEAN_TRUE;
4089 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_FALSE;
4090 }
4091
4092 return;
4093}
4094
4095
4096eHalStatus csrResetCountryCodeInformation(tpAniSirGlobal pMac, tANI_BOOLEAN *pfRestartNeeded)
4097{
4098 eHalStatus status = eHAL_STATUS_SUCCESS;
4099 tANI_BOOLEAN fRestart = eANI_BOOLEAN_FALSE;
4100
4101 //Use the Country code and domain from EEPROM
Kiet Lam64c1b492013-07-12 13:56:44 +05304102 vos_mem_copy(pMac->scan.countryCodeCurrent, pMac->scan.countryCodeDefault,
4103 WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07004104 csrSetRegulatoryDomain(pMac, pMac->scan.domainIdCurrent, &fRestart);
Jeff Johnson43971f52012-07-17 12:26:56 -07004105 if( ((eANI_BOOLEAN_FALSE == fRestart) || (pfRestartNeeded == NULL) )
4106 && !csrIsInfraConnected(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -07004107 {
4108 //Only reset the country info if we don't need to restart
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004109 csrResetCountryInformation(pMac, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07004110 }
4111 if(pfRestartNeeded)
4112 {
4113 *pfRestartNeeded = fRestart;
4114 }
4115
4116 return (status);
4117}
4118
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05304119void csrClearVotesForCountryInfo(tpAniSirGlobal pMac)
4120{
4121 pMac->scan.countryCodeCount = 0;
4122 vos_mem_set(pMac->scan.votes11d,
4123 sizeof(tCsrVotes11d) * CSR_MAX_NUM_COUNTRY_CODE, 0);
4124}
4125
4126void csrAddVoteForCountryInfo(tpAniSirGlobal pMac, tANI_U8 *pCountryCode)
4127{
4128 tANI_BOOLEAN match = FALSE;
4129 tANI_U8 i;
4130
4131 /* convert to UPPER here so we are assured
4132 * the strings are always in upper case.
4133 */
4134 for( i = 0; i < 3; i++ )
4135 {
4136 pCountryCode[ i ] = (tANI_U8)csrToUpper( pCountryCode[ i ] );
4137 }
4138
4139 /* Some of the 'old' Cisco 350 series AP's advertise NA as the
4140 * country code (for North America ??). NA is not a valid country code
4141 * or domain so let's allow this by changing it to the proper
4142 * country code (which is US). We've also seen some NETGEAR AP's
4143 * that have "XX " as the country code with valid 2.4 GHz US channel
4144 * information. If we cannot find the country code advertised in the
4145 * 11d information element, let's default to US.
4146 */
4147
4148 if ( !HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry( pMac,
4149 pCountryCode, NULL,COUNTRY_QUERY ) ) )
4150 {
4151 pCountryCode[ 0 ] = '0';
4152 pCountryCode[ 1 ] = '0';
4153 }
4154
4155 /* We've seen some of the AP's improperly put a 0 for the
4156 * third character of the country code. spec says valid charcters are
4157 * 'O' (for outdoor), 'I' for Indoor, or ' ' (space; for either).
4158 * if we see a 0 in this third character, let's change it to a ' '.
4159 */
4160 if ( 0 == pCountryCode[ 2 ] )
4161 {
4162 pCountryCode[ 2 ] = ' ';
4163 }
4164
4165 for (i = 0; i < pMac->scan.countryCodeCount; i++)
4166 {
4167 match = (vos_mem_compare(pMac->scan.votes11d[i].countryCode,
4168 pCountryCode, 2));
4169 if(match)
4170 {
4171 break;
4172 }
4173 }
4174
4175 if (match)
4176 {
4177 pMac->scan.votes11d[i].votes++;
4178 }
4179 else
4180 {
4181 vos_mem_copy( pMac->scan.votes11d[pMac->scan.countryCodeCount].countryCode,
4182 pCountryCode, 3 );
4183 pMac->scan.votes11d[pMac->scan.countryCodeCount].votes = 1;
4184 pMac->scan.countryCodeCount++;
4185 }
4186
4187 return;
4188}
4189
4190tANI_BOOLEAN csrElectedCountryInfo(tpAniSirGlobal pMac)
4191{
4192 tANI_BOOLEAN fRet = FALSE;
4193 tANI_U8 maxVotes = 0;
4194 tANI_U8 i, j=0;
4195
4196 if (!pMac->scan.countryCodeCount)
4197 {
Agrawal Ashishbd3a5932016-04-12 16:22:39 +05304198 VOS_TRACE( VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_WARN,
4199 "No AP with 11d Country code is present in scan list");
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05304200 return fRet;
4201 }
4202 maxVotes = pMac->scan.votes11d[0].votes;
4203 fRet = TRUE;
4204
4205 for(i = 1; i < pMac->scan.countryCodeCount; i++)
4206 {
4207 /* If we have a tie for max votes for 2 different country codes,
4208 * pick random.we can put some more intelligence - TBD
4209 */
4210 if (maxVotes < pMac->scan.votes11d[i].votes)
4211 {
4212 VOS_TRACE( VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
4213 " Votes for Country %c%c : %d\n",
4214 pMac->scan.votes11d[i].countryCode[0],
4215 pMac->scan.votes11d[i].countryCode[1],
4216 pMac->scan.votes11d[i].votes);
4217
4218 maxVotes = pMac->scan.votes11d[i].votes;
4219 j = i;
4220 fRet = TRUE;
4221 }
4222
4223 }
4224 if (fRet)
4225 {
Rajesh Babu Prathipati20cdffa2014-07-01 22:24:59 +05304226 vos_mem_copy(pMac->scan.countryCodeElected,
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05304227 pMac->scan.votes11d[j].countryCode, WNI_CFG_COUNTRY_CODE_LEN);
Rajesh Babu Prathipati20cdffa2014-07-01 22:24:59 +05304228 vos_mem_copy(pMac->scan.countryCode11d,
Agarwal Ashish852b2c32014-05-23 17:13:25 +05304229 pMac->scan.votes11d[j].countryCode, WNI_CFG_COUNTRY_CODE_LEN);
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05304230 VOS_TRACE( VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
4231 "Selected Country is %c%c With count %d\n",
4232 pMac->scan.votes11d[j].countryCode[0],
4233 pMac->scan.votes11d[j].countryCode[1],
4234 pMac->scan.votes11d[j].votes);
4235 }
4236 return fRet;
4237}
Jeff Johnson295189b2012-06-20 16:38:30 -07004238
4239eHalStatus csrSetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pCountry, tANI_BOOLEAN *pfRestartNeeded)
4240{
4241 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
4242 v_REGDOMAIN_t domainId;
4243
4244 if(pCountry)
4245 {
Kiet Lam6c583332013-10-14 05:37:09 +05304246 status = csrGetRegulatoryDomainForCountry(pMac, pCountry, &domainId, COUNTRY_USER);
Jeff Johnson295189b2012-06-20 16:38:30 -07004247 if(HAL_STATUS_SUCCESS(status))
4248 {
4249 status = csrSetRegulatoryDomain(pMac, domainId, pfRestartNeeded);
4250 if(HAL_STATUS_SUCCESS(status))
4251 {
4252 //We don't need to check the pMac->roam.configParam.fEnforceDefaultDomain flag here,
4253 //csrSetRegulatoryDomain will fail if the country doesn't fit our domain criteria.
Kiet Lam64c1b492013-07-12 13:56:44 +05304254 vos_mem_copy(pMac->scan.countryCodeCurrent, pCountry, WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07004255 if((pfRestartNeeded == NULL) || !(*pfRestartNeeded))
4256 {
4257 //Simply set it to cfg. If we need to restart, restart will apply it to the CFG
4258 csrSetCfgCountryCode(pMac, pCountry);
4259 }
4260 }
4261 }
4262 }
4263
4264 return (status);
4265}
4266
4267
4268
4269//caller allocated memory for pNumChn and pChnPowerInfo
4270//As input, *pNumChn has the size of the array of pChnPowerInfo
4271//Upon return, *pNumChn has the number of channels assigned.
4272void csrGetChannelPowerInfo( tpAniSirGlobal pMac, tDblLinkList *pList,
4273 tANI_U32 *pNumChn, tChannelListWithPower *pChnPowerInfo)
4274{
4275 tListElem *pEntry;
4276 tANI_U32 chnIdx = 0, idx;
4277 tCsrChannelPowerInfo *pChannelSet;
4278
4279 //Get 2.4Ghz first
4280 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
4281 while( pEntry && (chnIdx < *pNumChn) )
4282 {
4283 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
4284 if ( 1 != pChannelSet->interChannelOffset )
4285 {
4286 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
4287 {
4288 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
4289 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
4290 }
4291 }
4292 else
4293 {
4294 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
4295 {
4296 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + idx);
4297 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
4298 }
4299 }
4300
4301 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
4302 }
4303 *pNumChn = chnIdx;
4304
4305 return ;
4306}
4307
4308
4309
4310void csrApplyCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce )
4311{
4312 v_REGDOMAIN_t domainId;
4313 eHalStatus status = eHAL_STATUS_SUCCESS;
4314
4315 do
4316 {
4317 if( !csrIs11dSupported( pMac ) || 0 == pMac->scan.channelOf11dInfo) break;
4318 if( pMac->scan.fAmbiguous11dInfoFound )
4319 {
4320 // ambiguous info found
4321 //Restore te default domain as well
Kiet Lam6c583332013-10-14 05:37:09 +05304322 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
4323 pMac, pMac->scan.countryCodeCurrent,
4324 &domainId, COUNTRY_QUERY)))
Jeff Johnson295189b2012-06-20 16:38:30 -07004325 {
4326 pMac->scan.domainIdCurrent = domainId;
4327 }
4328 else
4329 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004330 smsLog(pMac, LOGE, FL(" failed to get domain from currentCountryCode %02X%02X"),
Jeff Johnson295189b2012-06-20 16:38:30 -07004331 pMac->scan.countryCodeCurrent[0], pMac->scan.countryCodeCurrent[1]);
4332 }
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004333 csrResetCountryInformation( pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE );
Jeff Johnson295189b2012-06-20 16:38:30 -07004334 break;
4335 }
4336 if ( pMac->scan.f11dInfoApplied && !fForce ) break;
Kiet Lam6c583332013-10-14 05:37:09 +05304337 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
4338 pMac, pMac->scan.countryCode11d,
4339 &domainId, COUNTRY_QUERY)))
Jeff Johnson295189b2012-06-20 16:38:30 -07004340 {
4341 //Check whether we need to enforce default domain
4342 if( ( !pMac->roam.configParam.fEnforceDefaultDomain ) ||
4343 (pMac->scan.domainIdCurrent == domainId) )
4344 {
4345
4346#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4347 {
4348 vos_log_802_11d_pkt_type *p11dLog;
4349 tChannelListWithPower chnPwrInfo[WNI_CFG_VALID_CHANNEL_LIST_LEN];
4350 tANI_U32 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN, nTmp;
4351
4352 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
4353 if(p11dLog)
4354 {
4355 p11dLog->eventId = WLAN_80211D_EVENT_COUNTRY_SET;
Kiet Lam64c1b492013-07-12 13:56:44 +05304356 vos_mem_copy(p11dLog->countryCode, pMac->scan.countryCode11d, 3);
Jeff Johnson295189b2012-06-20 16:38:30 -07004357 p11dLog->numChannel = pMac->scan.channels11d.numChannels;
4358 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
4359 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304360 vos_mem_copy(p11dLog->Channels,
4361 pMac->scan.channels11d.channelList,
4362 p11dLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07004363 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList24,
4364 &nChnInfo, chnPwrInfo);
4365 nTmp = nChnInfo;
4366 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN - nTmp;
4367 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList5G,
4368 &nChnInfo, &chnPwrInfo[nTmp]);
4369 for(nTmp = 0; nTmp < p11dLog->numChannel; nTmp++)
4370 {
4371 for(nChnInfo = 0; nChnInfo < WNI_CFG_VALID_CHANNEL_LIST_LEN; nChnInfo++)
4372 {
4373 if(p11dLog->Channels[nTmp] == chnPwrInfo[nChnInfo].chanId)
4374 {
4375 p11dLog->TxPwr[nTmp] = chnPwrInfo[nChnInfo].pwr;
4376 break;
4377 }
4378 }
4379 }
4380 }
4381 if(!pMac->roam.configParam.Is11dSupportEnabled)
4382 {
4383 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
4384 }
4385 else if(pMac->roam.configParam.fEnforceDefaultDomain)
4386 {
4387 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
4388 }
4389 else
4390 {
4391 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
4392 }
4393 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
4394 }
4395 }
4396#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4397 if(pMac->scan.domainIdCurrent != domainId)
4398 {
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05304399 smsLog(pMac, LOGW, FL("Domain Changed Old %s (%d), new %s"),
4400 voss_DomainIdtoString(pMac->scan.domainIdCurrent),
4401 pMac->scan.domainIdCurrent,
4402 voss_DomainIdtoString(domainId));
Abhishek Singha306a442013-11-07 18:39:01 +05304403 status = WDA_SetRegDomain(pMac, domainId, eSIR_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07004404 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004405 if (status != eHAL_STATUS_SUCCESS)
4406 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004407 smsLog( pMac, LOGE, FL(" fail to set regId %d"), domainId );
Jeff Johnson295189b2012-06-20 16:38:30 -07004408 }
4409 pMac->scan.domainIdCurrent = domainId;
Kiet Lam6c583332013-10-14 05:37:09 +05304410#ifndef CONFIG_ENABLE_LINUX_REG
Kiet Lambb14e952013-11-19 14:58:29 +05304411 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.base20MHzChannels,
4412 pMac->scan.countryCodeCurrent, eANI_BOOLEAN_TRUE );
Kiet Lam6c583332013-10-14 05:37:09 +05304413#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004414 // switch to active scans using this new channel list
4415 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
4416 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_TRUE;
4417 pMac->scan.f11dInfoReset = eANI_BOOLEAN_FALSE;
4418 }
4419 }
4420
4421 } while( 0 );
4422
4423 return;
4424}
4425
4426
4427
4428tANI_BOOLEAN csrSave11dCountryString( tpAniSirGlobal pMac, tANI_U8 *pCountryCode,
4429 tANI_BOOLEAN fForce)
4430{
4431 tANI_BOOLEAN fCountryStringChanged = FALSE, fUnknownCountryCode = FALSE;
4432 tANI_U32 i;
Kiet Lam6c583332013-10-14 05:37:09 +05304433 v_REGDOMAIN_t regd;
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004434 tANI_BOOLEAN fCountryNotPresentInDriver = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004435
4436 // convert to UPPER here so we are assured the strings are always in upper case.
4437 for( i = 0; i < 3; i++ )
4438 {
4439 pCountryCode[ i ] = (tANI_U8)csrToUpper( pCountryCode[ i ] );
4440 }
4441
4442 // Some of the 'old' Cisco 350 series AP's advertise NA as the country code (for North America ??).
4443 // NA is not a valid country code or domain so let's allow this by changing it to the proper
4444 // country code (which is US). We've also seen some NETGEAR AP's that have "XX " as the country code
4445 // with valid 2.4 GHz US channel information. If we cannot find the country code advertised in the
4446 // 11d information element, let's default to US.
Kiet Lam6c583332013-10-14 05:37:09 +05304447 if ( !HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(pMac,
4448 pCountryCode,
4449 &regd,
4450 COUNTRY_QUERY) ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07004451 {
4452 // Check the enforcement first
4453 if( pMac->roam.configParam.fEnforceDefaultDomain || pMac->roam.configParam.fEnforceCountryCodeMatch )
4454 {
4455 fUnknownCountryCode = TRUE;
4456 }
4457 else
4458 {
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004459 fCountryNotPresentInDriver = TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004460 }
4461 }
Tushnim Bhattacharyyac3c1e8e2013-10-29 17:27:43 -07004462 //right now, even if we don't find the CC in driver we set to world. Making
4463 //sure countryCode11d doesn't get updated with the invalid CC, instead
4464 //reflect the world CC
4465 else if (REGDOMAIN_WORLD == regd)
4466 {
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004467 fCountryNotPresentInDriver = TRUE;
Tushnim Bhattacharyyac3c1e8e2013-10-29 17:27:43 -07004468 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004469
4470 // We've seen some of the AP's improperly put a 0 for the third character of the country code.
4471 // spec says valid charcters are 'O' (for outdoor), 'I' for Indoor, or ' ' (space; for either).
4472 // if we see a 0 in this third character, let's change it to a ' '.
4473 if ( 0 == pCountryCode[ 2 ] )
4474 {
4475 pCountryCode[ 2 ] = ' ';
4476 }
4477
4478 if( !fUnknownCountryCode )
4479 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304480 fCountryStringChanged = (!vos_mem_compare(pMac->scan.countryCode11d, pCountryCode, 2));
Jeff Johnson295189b2012-06-20 16:38:30 -07004481
4482
4483 if(( 0 == pMac->scan.countryCode11d[ 0 ] && 0 == pMac->scan.countryCode11d[ 1 ] )
4484 || (fForce))
4485 {
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004486 if (!fCountryNotPresentInDriver)
4487 {
4488 // this is the first .11d information
4489 vos_mem_copy(pMac->scan.countryCode11d, pCountryCode,
Kiet Lam64c1b492013-07-12 13:56:44 +05304490 sizeof( pMac->scan.countryCode11d ));
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004491
4492 }
4493 else
4494 {
4495 pMac->scan.countryCode11d[0] = '0';
4496 pMac->scan.countryCode11d[1] = '0';
4497 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004498 }
4499 }
4500
4501 return( fCountryStringChanged );
4502}
4503
4504
4505void csrSaveChannelPowerForBand( tpAniSirGlobal pMac, tANI_BOOLEAN fPopulate5GBand )
4506{
4507 tANI_U32 Index, count=0;
4508 tSirMacChanInfo *pChanInfo;
4509 tSirMacChanInfo *pChanInfoStart;
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08004510 tANI_S32 maxChannelIndex;
4511
4512 maxChannelIndex = ( pMac->scan.base20MHzChannels.numChannels < WNI_CFG_VALID_CHANNEL_LIST_LEN ) ?
4513 pMac->scan.base20MHzChannels.numChannels : WNI_CFG_VALID_CHANNEL_LIST_LEN ;
Jeff Johnson295189b2012-06-20 16:38:30 -07004514
Kiet Lam64c1b492013-07-12 13:56:44 +05304515 pChanInfo = vos_mem_malloc(sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN);
4516 if ( NULL != pChanInfo )
Jeff Johnson295189b2012-06-20 16:38:30 -07004517 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304518 vos_mem_set(pChanInfo, sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004519 pChanInfoStart = pChanInfo;
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08004520 for (Index=0; Index < maxChannelIndex; Index++)
Jeff Johnson295189b2012-06-20 16:38:30 -07004521 {
4522 if ((fPopulate5GBand && (CSR_IS_CHANNEL_5GHZ(pMac->scan.defaultPowerTable[Index].chanId))) ||
4523 (!fPopulate5GBand && (CSR_IS_CHANNEL_24GHZ(pMac->scan.defaultPowerTable[Index].chanId))) )
4524 {
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08004525 if(count >= WNI_CFG_VALID_CHANNEL_LIST_LEN)
4526 {
4527 smsLog( pMac, LOGW, FL(" csrSaveChannelPowerForBand, count exceeded, count = %d"), count);
4528 break;
4529 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004530 pChanInfo->firstChanNum = pMac->scan.defaultPowerTable[Index].chanId;
4531 pChanInfo->numChannels = 1;
4532 pChanInfo->maxTxPower = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
4533 pChanInfo++;
4534 count++;
4535 }
4536 }
4537 if(count)
4538 {
4539 csrSaveToChannelPower2G_5G( pMac, count * sizeof(tSirMacChanInfo), pChanInfoStart );
4540 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304541 vos_mem_free(pChanInfoStart);
Jeff Johnson295189b2012-06-20 16:38:30 -07004542 }
4543}
4544
4545
4546void csrSetOppositeBandChannelInfo( tpAniSirGlobal pMac )
4547{
4548 tANI_BOOLEAN fPopulate5GBand = FALSE;
4549
4550 do
4551 {
4552 // if this is not a dual band product, then we don't need to set the opposite
4553 // band info. We only work in one band so no need to look in the other band.
4554 if ( !CSR_IS_OPEARTING_DUAL_BAND( pMac ) ) break;
4555 // if we found channel info on the 5.0 band and...
4556 if ( CSR_IS_CHANNEL_5GHZ( pMac->scan.channelOf11dInfo ) )
4557 {
4558 // and the 2.4 band is empty, then populate the 2.4 channel info
Kiet Lam8d985a02013-10-11 03:39:41 +05304559 if ( !csrLLIsListEmpty( &pMac->scan.channelPowerInfoList24, LL_ACCESS_LOCK ) ) break;
Jeff Johnson295189b2012-06-20 16:38:30 -07004560 fPopulate5GBand = FALSE;
4561 }
4562 else
4563 {
4564 // else, we found channel info in the 2.4 GHz band. If the 5.0 band is empty
4565 // set the 5.0 band info from the 2.4 country code.
Kiet Lam8d985a02013-10-11 03:39:41 +05304566 if ( !csrLLIsListEmpty( &pMac->scan.channelPowerInfoList5G, LL_ACCESS_LOCK ) ) break;
Jeff Johnson295189b2012-06-20 16:38:30 -07004567 fPopulate5GBand = TRUE;
4568 }
4569 csrSaveChannelPowerForBand( pMac, fPopulate5GBand );
4570
4571 } while( 0 );
4572}
4573
4574
4575tANI_BOOLEAN csrIsSupportedChannel(tpAniSirGlobal pMac, tANI_U8 channelId)
4576{
4577 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
4578 tANI_U32 i;
4579
4580 //Make sure it is a channel that is in our supported list.
4581 for ( i = 0; i < pMac->scan.baseChannels.numChannels; i++ )
4582 {
4583 if ( channelId == pMac->scan.baseChannels.channelList[i] )
4584 {
4585 fRet = eANI_BOOLEAN_TRUE;
4586 break;
4587 }
4588 }
4589
4590 //If it is configured to limit a set of the channels
4591 if( fRet && pMac->roam.configParam.fEnforce11dChannels )
4592 {
4593 fRet = eANI_BOOLEAN_FALSE;
4594 for ( i = 0; i < pMac->scan.base20MHzChannels.numChannels; i++ )
4595 {
4596 if ( channelId == pMac->scan.base20MHzChannels.channelList[i] )
4597 {
4598 fRet = eANI_BOOLEAN_TRUE;
4599 break;
4600 }
4601 }
4602 }
4603
4604 return (fRet);
4605}
4606
4607
4608
4609//bSize specify the buffer size of pChannelList
4610tANI_U8 csrGetChannelListFromChannelSet( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 bSize, tCsrChannelPowerInfo *pChannelSet )
4611{
4612 tANI_U8 i, j = 0, chnId;
4613
4614 bSize = CSR_MIN(bSize, pChannelSet->numChannels);
4615 for( i = 0; i < bSize; i++ )
4616 {
4617 chnId = (tANI_U8)(pChannelSet->firstChannel + ( i * pChannelSet->interChannelOffset ));
4618 if ( csrIsSupportedChannel( pMac, chnId ) )
4619 {
4620 pChannelList[j++] = chnId;
4621 }
4622 }
4623
4624 return (j);
4625}
4626
4627
4628
4629//bSize -- specify the buffer size of pChannelList
4630void csrConstructCurrentValidChannelList( tpAniSirGlobal pMac, tDblLinkList *pChannelSetList,
4631 tANI_U8 *pChannelList, tANI_U8 bSize, tANI_U8 *pNumChannels )
4632{
4633 tListElem *pEntry;
4634 tCsrChannelPowerInfo *pChannelSet;
4635 tANI_U8 numChannels;
4636 tANI_U8 *pChannels;
4637
4638 if( pChannelSetList && pChannelList && pNumChannels )
4639 {
4640 pChannels = pChannelList;
4641 *pNumChannels = 0;
4642 pEntry = csrLLPeekHead( pChannelSetList, LL_ACCESS_LOCK );
4643 while( pEntry )
4644 {
4645 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
4646 numChannels = csrGetChannelListFromChannelSet( pMac, pChannels, bSize, pChannelSet );
4647 pChannels += numChannels;
4648 *pNumChannels += numChannels;
4649 pEntry = csrLLNext( pChannelSetList, pEntry, LL_ACCESS_LOCK );
4650 }
4651 }
4652}
4653
4654
4655/*
4656 * 802.11D only: Gather 11d IE via beacon or Probe response and store them in pAdapter->channels11d
4657*/
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304658tANI_BOOLEAN csrLearnCountryInformation( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc,
4659 tDot11fBeaconIEs *pIes, tANI_BOOLEAN fForce)
Jeff Johnson295189b2012-06-20 16:38:30 -07004660{
Agarwal Ashish60a37ee2014-05-28 17:20:20 +05304661 eHalStatus status;
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304662 tANI_U8 *pCountryCodeSelected;
Jeff Johnson295189b2012-06-20 16:38:30 -07004663 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
4664 v_REGDOMAIN_t domainId;
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304665 tDot11fBeaconIEs *pIesLocal = pIes;
4666 tANI_BOOLEAN useVoting = eANI_BOOLEAN_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004667
Jeff Johnson295189b2012-06-20 16:38:30 -07004668 if (VOS_STA_SAP_MODE == vos_get_conparam ())
4669 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07004670
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304671 if ((NULL == pSirBssDesc) && (NULL == pIes))
4672 useVoting = eANI_BOOLEAN_TRUE;
4673
Jeff Johnson295189b2012-06-20 16:38:30 -07004674 do
4675 {
4676 // check if .11d support is enabled
4677 if( !csrIs11dSupported( pMac ) ) break;
Agarwal Ashish60a37ee2014-05-28 17:20:20 +05304678
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304679 if (eANI_BOOLEAN_FALSE == useVoting)
4680 {
4681 if( !pIesLocal &&
4682 (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
4683 pSirBssDesc, &pIesLocal))))
4684 {
4685 break;
4686 }
4687 // check if country information element is present
4688 if(!pIesLocal->Country.present)
4689 {
4690 //No country info
4691 break;
4692 }
4693
4694 if( HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry
4695 (pMac, pIesLocal->Country.country, &domainId,
4696 COUNTRY_QUERY)) &&
4697 ( domainId == REGDOMAIN_WORLD))
4698 {
4699 break;
4700 }
4701 } //useVoting == eANI_BOOLEAN_FALSE
4702
4703 if (eANI_BOOLEAN_FALSE == useVoting)
4704 pCountryCodeSelected = pIesLocal->Country.country;
4705 else
4706 pCountryCodeSelected = pMac->scan.countryCodeElected;
4707
Kiet Lam8d985a02013-10-11 03:39:41 +05304708 status = csrGetRegulatoryDomainForCountry(pMac,
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304709 pCountryCodeSelected, &domainId, COUNTRY_IE);
Kiet Lam8d985a02013-10-11 03:39:41 +05304710 if ( status != eHAL_STATUS_SUCCESS )
4711 {
4712 smsLog( pMac, LOGE, FL(" fail to get regId %d"), domainId );
4713 fRet = eANI_BOOLEAN_FALSE;
4714 break;
4715 }
Agarwal Ashish7693f2d2014-07-18 18:03:58 +05304716
4717 /* updating 11d Country Code with Country code selected. */
4718
4719 vos_mem_copy(pMac->scan.countryCode11d,
4720 pCountryCodeSelected,
4721 WNI_CFG_COUNTRY_CODE_LEN);
4722
Agarwal Ashish60a37ee2014-05-28 17:20:20 +05304723#ifndef CONFIG_ENABLE_LINUX_REG
Venkata Prathyusha Kuntupalli316247e2013-03-15 17:45:25 -07004724 // Checking for Domain Id change
4725 if ( domainId != pMac->scan.domainIdCurrent )
4726 {
Kiet Lam8d985a02013-10-11 03:39:41 +05304727 vos_mem_copy(pMac->scan.countryCode11d,
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304728 pCountryCodeSelected,
Kiet Lam8d985a02013-10-11 03:39:41 +05304729 sizeof( pMac->scan.countryCode11d ) );
4730 /* Set Current Country code and Current Regulatory domain */
4731 status = csrSetRegulatoryDomain(pMac, domainId, NULL);
4732 if (eHAL_STATUS_SUCCESS != status)
4733 {
4734 smsLog(pMac, LOGE, "Set Reg Domain Fail %d", status);
4735 fRet = eANI_BOOLEAN_FALSE;
4736 return fRet;
4737 }
4738 //csrSetRegulatoryDomain will fail if the country doesn't fit our domain criteria.
4739 vos_mem_copy(pMac->scan.countryCodeCurrent,
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304740 pCountryCodeSelected, WNI_CFG_COUNTRY_CODE_LEN);
Kiet Lam8d985a02013-10-11 03:39:41 +05304741 //Simply set it to cfg.
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304742 csrSetCfgCountryCode(pMac, pCountryCodeSelected);
Kiet Lam8d985a02013-10-11 03:39:41 +05304743
4744 /* overwrite the defualt country code */
4745 vos_mem_copy(pMac->scan.countryCodeDefault,
4746 pMac->scan.countryCodeCurrent,
4747 WNI_CFG_COUNTRY_CODE_LEN);
4748 /* Set Current RegDomain */
Abhishek Singha306a442013-11-07 18:39:01 +05304749 status = WDA_SetRegDomain(pMac, domainId, eSIR_TRUE);
Kiet Lam8d985a02013-10-11 03:39:41 +05304750 if ( status != eHAL_STATUS_SUCCESS )
4751 {
4752 smsLog( pMac, LOGE, FL(" fail to Set regId %d"), domainId );
4753 fRet = eANI_BOOLEAN_FALSE;
4754 return fRet;
4755 }
4756 /* set to default domain ID */
Madan Mohan Koyyalamudi0e5922d2013-09-10 15:45:24 +05304757 pMac->scan.domainIdCurrent = domainId;
Kiet Lam8d985a02013-10-11 03:39:41 +05304758 /* get the channels based on new cc */
4759 status = csrInitGetChannels( pMac );
Jeff Johnson295189b2012-06-20 16:38:30 -07004760
Kiet Lam8d985a02013-10-11 03:39:41 +05304761 if ( status != eHAL_STATUS_SUCCESS )
4762 {
4763 smsLog( pMac, LOGE, FL(" fail to get Channels "));
4764 fRet = eANI_BOOLEAN_FALSE;
4765 return fRet;
4766 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004767
Kiet Lam8d985a02013-10-11 03:39:41 +05304768 /* reset info based on new cc, and we are done */
4769 csrResetCountryInformation(pMac, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
Agarwal Ashishfaef6692014-01-29 19:40:30 +05304770 /* Regulatory Domain Changed, Purge Only scan result
4771 * which does not have channel number belong to 11d
4772 * channel list
4773 */
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05304774 csrScanFilterResults(pMac);
Kiet Lam8d985a02013-10-11 03:39:41 +05304775 }
Kiet Lam6c583332013-10-14 05:37:09 +05304776#endif
4777 fRet = eANI_BOOLEAN_TRUE;
4778
Jeff Johnson295189b2012-06-20 16:38:30 -07004779 } while( 0 );
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304780
4781 if( !pIes && pIesLocal )
4782 {
4783 //locally allocated
4784 vos_mem_free(pIesLocal);
4785 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004786
4787 return( fRet );
4788}
4789
4790
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004791static void csrSaveScanResults( tpAniSirGlobal pMac, tANI_U8 reason )
Jeff Johnson295189b2012-06-20 16:38:30 -07004792{
4793 // initialize this to FALSE. profMoveInterimScanResultsToMainList() routine
4794 // will set this to the channel where an .11d beacon is seen
4795 pMac->scan.channelOf11dInfo = 0;
4796 // if we get any ambiguous .11d information then this will be set to TRUE
4797 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
4798 //Tush
4799 // if we get any ambiguous .11d information, then this will be set to TRUE
4800 // only if the applied 11d info could be found in one of the scan results
4801 pMac->scan.fCurrent11dInfoMatch = eANI_BOOLEAN_FALSE;
4802 // move the scan results from interim list to the main scan list
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004803 csrMoveTempScanResultsToMainList( pMac, reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07004804}
4805
4806
4807void csrReinitScanCmd(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4808{
4809 switch (pCommand->u.scanCmd.reason)
4810 {
4811 case eCsrScanSetBGScanParam:
4812 case eCsrScanAbortBgScan:
4813 if(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList)
4814 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304815 vos_mem_free(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList);
Jeff Johnson295189b2012-06-20 16:38:30 -07004816 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
4817 }
4818 break;
4819 case eCsrScanBGScanAbort:
4820 case eCsrScanBGScanEnable:
4821 case eCsrScanGetScanChnInfo:
4822 break;
4823 case eCsrScanAbortNormalScan:
4824 default:
4825 csrScanFreeRequest(pMac, &pCommand->u.scanCmd.u.scanRequest);
4826 break;
4827 }
4828 if(pCommand->u.scanCmd.pToRoamProfile)
4829 {
4830 csrReleaseProfile(pMac, pCommand->u.scanCmd.pToRoamProfile);
Kiet Lam64c1b492013-07-12 13:56:44 +05304831 vos_mem_free(pCommand->u.scanCmd.pToRoamProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07004832 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304833 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004834}
4835
4836
4837tANI_BOOLEAN csrGetRemainingChannelsFor11dScan( tpAniSirGlobal pMac, tANI_U8 *pChannels, tANI_U8 *pcChannels )
4838{
4839 tANI_U32 index11dChannels, index;
4840 tANI_U32 indexCurrentChannels;
4841 tANI_BOOLEAN fChannelAlreadyScanned;
4842 tANI_U32 len = sizeof(pMac->roam.validChannelList);
4843
4844 *pcChannels = 0;
4845 if ( CSR_IS_11D_INFO_FOUND(pMac) && csrRoamIsChannelValid(pMac, pMac->scan.channelOf11dInfo) )
4846 {
4847 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
4848 {
4849 //Find the channel index where we found the 11d info
4850 for(index = 0; index < len; index++)
4851 {
4852 if(pMac->scan.channelOf11dInfo == pMac->roam.validChannelList[index])
4853 break;
4854 }
4855 //check whether we found the channel index
4856 if(index < len)
4857 {
4858 // Now, look through the 11d channel list and create a list of all channels in the 11d list that are
4859 // NOT in the current channel list. This gives us a list of the new channels that have not been
4860 // scanned. We'll scan this new list so we have a complete set of scan results on all of the domain channels
4861 // initially.
4862 for ( index11dChannels = 0; index11dChannels < pMac->scan.channels11d.numChannels; index11dChannels++ )
4863 {
4864 fChannelAlreadyScanned = eANI_BOOLEAN_FALSE;
4865
4866 for( indexCurrentChannels = 0; indexCurrentChannels < index; indexCurrentChannels++ )
4867 {
4868 if ( pMac->roam.validChannelList[ indexCurrentChannels ] == pMac->scan.channels11d.channelList[ index11dChannels ] )
4869 {
4870 fChannelAlreadyScanned = eANI_BOOLEAN_TRUE;
4871 break;
4872 }
4873 }
4874
4875 if ( !fChannelAlreadyScanned )
4876 {
4877 pChannels[ *pcChannels ] = pMac->scan.channels11d.channelList[ index11dChannels ];
4878 ( *pcChannels )++;
4879 }
4880 }
4881 }
4882 }//GetCFG
4883 }
4884 return( *pcChannels );
4885}
4886
4887
4888eCsrScanCompleteNextCommand csrScanGetNextCommandState( tpAniSirGlobal pMac, tSmeCmd *pCommand, tANI_BOOLEAN fSuccess )
4889{
4890 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
4891
4892 switch( pCommand->u.scanCmd.reason )
4893 {
4894 case eCsrScan11d1:
4895 NextCommand = (fSuccess) ? eCsrNext11dScan1Success : eCsrNext11dScan1Failure;
4896 break;
4897 case eCsrScan11d2:
4898 NextCommand = (fSuccess) ? eCsrNext11dScan2Success : eCsrNext11dScan2Failure;
4899 break;
4900 case eCsrScan11dDone:
4901 NextCommand = eCsrNext11dScanComplete;
4902 break;
4903 case eCsrScanLostLink1:
4904 NextCommand = (fSuccess) ? eCsrNextLostLinkScan1Success : eCsrNextLostLinkScan1Failed;
4905 break;
4906 case eCsrScanLostLink2:
4907 NextCommand = (fSuccess) ? eCsrNextLostLinkScan2Success : eCsrNextLostLinkScan2Failed;
4908 break;
4909 case eCsrScanLostLink3:
4910 NextCommand = (fSuccess) ? eCsrNextLostLinkScan3Success : eCsrNextLostLinkScan3Failed;
4911 break;
4912 case eCsrScanForSsid:
4913 NextCommand = (fSuccess) ? eCsrNexteScanForSsidSuccess : eCsrNexteScanForSsidFailure;
4914 break;
4915 case eCsrScanForCapsChange:
4916 NextCommand = eCsrNextCapChangeScanComplete; //don't care success or not
4917 break;
4918 case eCsrScanIdleScan:
4919 NextCommand = eCsrNextIdleScanComplete;
4920 break;
4921 default:
4922 NextCommand = eCsrNextScanNothing;
4923 break;
4924 }
4925 return( NextCommand );
4926}
4927
4928
4929//Return whether the pCommand is finished.
4930tANI_BOOLEAN csrHandleScan11d1Failure(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4931{
4932 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
4933
4934 //Apply back the default setting and passively scan one more time.
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004935 csrResetCountryInformation(pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07004936 pCommand->u.scanCmd.reason = eCsrScan11d2;
4937 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
4938 {
4939 fRet = eANI_BOOLEAN_FALSE;
4940 }
4941
4942 return (fRet);
4943}
4944
4945
4946tANI_BOOLEAN csrHandleScan11dSuccess(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4947{
4948 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
4949 tANI_U8 *pChannels;
4950 tANI_U8 cChannels;
4951
Kiet Lam64c1b492013-07-12 13:56:44 +05304952 pChannels = vos_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
4953 if ( NULL != pChannels )
Jeff Johnson295189b2012-06-20 16:38:30 -07004954 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304955 vos_mem_set(pChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004956 if ( csrGetRemainingChannelsFor11dScan( pMac, pChannels, &cChannels ) )
4957 {
4958 pCommand->u.scanCmd.reason = eCsrScan11dDone;
4959 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
4960 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304961 vos_mem_free(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -07004962 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004963 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304964 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(cChannels);
4965 if ( NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07004966 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304967 vos_mem_copy(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
4968 pChannels, cChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07004969 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = cChannels;
4970 pCommand->u.scanCmd.u.scanRequest.requestType = eCSR_SCAN_REQUEST_FULL_SCAN;
4971 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
4972 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
4973 {
4974 //Reuse the same command buffer
4975 fRet = eANI_BOOLEAN_FALSE;
4976 }
4977 }
4978 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304979 vos_mem_free(pChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07004980 }
4981
4982 return (fRet);
4983}
4984
4985//Return whether the command should be removed
4986tANI_BOOLEAN csrScanComplete( tpAniSirGlobal pMac, tSirSmeScanRsp *pScanRsp )
4987{
4988 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
4989 tListElem *pEntry;
4990 tSmeCmd *pCommand;
4991 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
4992 tANI_BOOLEAN fSuccess;
4993
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05304994 if (pMac->fScanOffload)
4995 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
4996 else
4997 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07004998
4999 if ( pEntry )
5000 {
5001 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
5002
5003 // If the head of the queue is Active and it is a SCAN command, remove
5004 // and put this on the Free queue.
5005 if ( eSmeCommandScan == pCommand->command )
5006 {
5007 tANI_U32 sessionId = pCommand->sessionId;
5008
5009 if(eSIR_SME_SUCCESS != pScanRsp->statusCode)
5010 {
5011 fSuccess = eANI_BOOLEAN_FALSE;
5012 }
5013 else
5014 {
5015 //pMac->scan.tempScanResults is not empty meaning the scan found something
5016 //This check only valid here because csrSaveScanresults is not yet called
5017 fSuccess = (!csrLLIsListEmpty(&pMac->scan.tempScanResults, LL_ACCESS_LOCK));
5018 }
Ratheesh S Pece1f832015-07-25 15:50:25 +05305019 if (pCommand->u.scanCmd.abortScanIndication &
5020 eCSR_SCAN_ABORT_DUE_TO_BAND_CHANGE)
Srinivas, Dasari187ca4e2014-02-07 12:40:09 +05305021 {
5022 /*
5023 * Scan aborted due to band change
5024 * The scan results need to be flushed
5025 */
5026 if (pCommand->u.scanCmd.callback
5027 != pMac->scan.callback11dScanDone)
5028 {
5029 smsLog(pMac, LOG1, FL("Filtering the scan results as the "
5030 "results may belong to wrong band"));
5031 csrScanFilterResults(pMac);
5032 }
5033 else
5034 {
5035 smsLog(pMac, LOG1, FL("11d_scan_done will flush the scan"
5036 " results"));
5037 }
Srinivas, Dasari187ca4e2014-02-07 12:40:09 +05305038 }
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005039 csrSaveScanResults(pMac, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07005040
Agrawal Ashishdf752672015-12-09 17:51:53 +05305041 /* filter scan result based on valid channel list number */
5042 if (pMac->scan.fcc_constraint)
5043 {
5044 smsLog(pMac, LOG1, FL("Clear BSS from invalid channels"));
5045 csrScanFilterResults(pMac);
5046 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005047#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5048 {
5049 vos_log_scan_pkt_type *pScanLog = NULL;
5050 tScanResultHandle hScanResult;
5051 tCsrScanResultInfo *pScanResult;
5052 tDot11fBeaconIEs *pIes;
5053 int n = 0, c = 0;
5054
5055 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
5056 if(pScanLog)
5057 {
5058 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
5059 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
5060 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
5061 {
5062 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_RSP;
5063 }
5064 else
5065 {
5066 if( eSIR_PASSIVE_SCAN != pMac->scan.curScanType )
5067 {
5068 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_RSP;
5069 }
5070 else
5071 {
5072 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_RSP;
5073 }
5074 }
5075 if(eSIR_SME_SUCCESS == pScanRsp->statusCode)
5076 {
5077 if(HAL_STATUS_SUCCESS(csrScanGetResult(pMac, NULL, &hScanResult)))
5078 {
5079 while(((pScanResult = csrScanResultGetNext(pMac, hScanResult)) != NULL))
5080 {
5081 if( n < VOS_LOG_MAX_NUM_BSSID )
5082 {
5083 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pScanResult->BssDescriptor, &pIes)))
5084 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005085 smsLog(pMac, LOGE, FL(" fail to parse IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07005086 break;
5087 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305088 vos_mem_copy(pScanLog->bssid[n],
5089 pScanResult->BssDescriptor.bssId, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07005090 if(pIes && pIes->SSID.present && VOS_LOG_MAX_SSID_SIZE >= pIes->SSID.num_ssid)
5091 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305092 vos_mem_copy(pScanLog->ssid[n],
5093 pIes->SSID.ssid, pIes->SSID.num_ssid);
Jeff Johnson295189b2012-06-20 16:38:30 -07005094 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305095 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07005096 n++;
5097 }
5098 c++;
5099 }
5100 pScanLog->numSsid = (v_U8_t)n;
5101 pScanLog->totalSsid = (v_U8_t)c;
5102 csrScanResultPurge(pMac, hScanResult);
5103 }
5104 }
5105 else
5106 {
5107 pScanLog->status = WLAN_SCAN_STATUS_FAILURE;
5108 }
5109 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
5110 }
5111 }
5112#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5113
5114 NextCommand = csrScanGetNextCommandState(pMac, pCommand, fSuccess);
5115 //We reuse the command here instead reissue a new command
5116 switch(NextCommand)
5117 {
5118 case eCsrNext11dScan1Success:
5119 case eCsrNext11dScan2Success:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005120 smsLog( pMac, LOG2, FL("11dScan1/3 produced results. Reissue Active scan..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07005121 // if we found country information, no need to continue scanning further, bail out
5122 fRemoveCommand = eANI_BOOLEAN_TRUE;
5123 NextCommand = eCsrNext11dScanComplete;
5124 break;
5125 case eCsrNext11dScan1Failure:
5126 //We are not done yet. 11d scan fail once. We will try to reset anything and do it over again
5127 //The only meaningful thing for this retry is that we cannot find 11d information after a reset so
5128 //we clear the "old" 11d info and give it once more chance
5129 fRemoveCommand = csrHandleScan11d1Failure(pMac, pCommand);
5130 if(fRemoveCommand)
5131 {
5132 NextCommand = eCsrNext11dScanComplete;
5133 }
5134 break;
5135 case eCsrNextLostLinkScan1Success:
5136 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink1)))
5137 {
5138 csrScanHandleFailedLostlink1(pMac, sessionId);
5139 }
5140 break;
5141 case eCsrNextLostLinkScan2Success:
5142 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink2)))
5143 {
5144 csrScanHandleFailedLostlink2(pMac, sessionId);
5145 }
5146 break;
5147 case eCsrNextLostLinkScan3Success:
5148 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink3)))
5149 {
5150 csrScanHandleFailedLostlink3(pMac, sessionId);
5151 }
5152 break;
5153 case eCsrNextLostLinkScan1Failed:
5154 csrScanHandleFailedLostlink1(pMac, sessionId);
5155 break;
5156 case eCsrNextLostLinkScan2Failed:
5157 csrScanHandleFailedLostlink2(pMac, sessionId);
5158 break;
5159 case eCsrNextLostLinkScan3Failed:
5160 csrScanHandleFailedLostlink3(pMac, sessionId);
5161 break;
5162 case eCsrNexteScanForSsidSuccess:
5163 csrScanHandleSearchForSSID(pMac, pCommand);
5164 break;
5165 case eCsrNexteScanForSsidFailure:
5166 csrScanHandleSearchForSSIDFailure(pMac, pCommand);
5167 break;
5168 case eCsrNextIdleScanComplete:
5169 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
5170 break;
5171 case eCsrNextCapChangeScanComplete:
5172 csrScanHandleCapChangeScanComplete(pMac, sessionId);
5173 break;
5174 default:
5175
5176 break;
5177 }
5178 }
5179 else
5180 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005181 smsLog( pMac, LOGW, FL("Scan Completion called but SCAN command is not ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07005182 fRemoveCommand = eANI_BOOLEAN_FALSE;
5183 }
5184 }
5185 else
5186 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005187 smsLog( pMac, LOGW, FL("Scan Completion called but NO commands are ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07005188 fRemoveCommand = eANI_BOOLEAN_FALSE;
5189 }
5190
5191 return( fRemoveCommand );
5192}
5193
5194
5195
5196static void csrScanRemoveDupBssDescriptionFromInterimList( tpAniSirGlobal pMac,
5197 tSirBssDescription *pSirBssDescr,
5198 tDot11fBeaconIEs *pIes)
5199{
5200 tListElem *pEntry;
5201 tCsrScanResult *pCsrBssDescription;
5202
5203 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
5204 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
5205 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
5206 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
5207 while( pEntry )
5208 {
5209 pCsrBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
5210
5211 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
5212 // matches
5213
5214 if ( csrIsDuplicateBssDescription( pMac, &pCsrBssDescription->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07005215 pSirBssDescr, pIes, FALSE ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07005216 {
5217 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
5218 ((tANI_S32)pCsrBssDescription->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
5219
5220 // Remove the 'old' entry from the list....
5221 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK ) )
5222 {
5223 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pCsrBssDescription->Result.BssDescriptor);
5224 // we need to free the memory associated with this node
5225 csrFreeScanResultEntry( pMac, pCsrBssDescription );
5226 }
5227
5228 // If we found a match, we can stop looking through the list.
5229 break;
5230 }
5231
5232 pEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK );
5233 }
5234}
5235
5236
5237
5238//Caller allocated memory pfNewBssForConn to return whether new candidate for
5239//current connection is found. Cannot be NULL
5240tCsrScanResult *csrScanSaveBssDescriptionToInterimList( tpAniSirGlobal pMac,
5241 tSirBssDescription *pBSSDescription,
5242 tDot11fBeaconIEs *pIes)
5243{
5244 tCsrScanResult *pCsrBssDescription = NULL;
5245 tANI_U32 cbBSSDesc;
5246 tANI_U32 cbAllocated;
Jeff Johnson295189b2012-06-20 16:38:30 -07005247
5248 // figure out how big the BSS description is (the BSSDesc->length does NOT
5249 // include the size of the length field itself).
5250 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
5251
5252 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
5253
Kiet Lam64c1b492013-07-12 13:56:44 +05305254 pCsrBssDescription = vos_mem_malloc(cbAllocated);
5255 if ( NULL != pCsrBssDescription )
Jeff Johnson295189b2012-06-20 16:38:30 -07005256 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305257 vos_mem_set(pCsrBssDescription, cbAllocated, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005258 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Kiet Lam64c1b492013-07-12 13:56:44 +05305259 vos_mem_copy(&pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc );
Jeff Johnson295189b2012-06-20 16:38:30 -07005260 //Save SSID separately for later use
5261 if( pIes->SSID.present && !csrIsNULLSSID(pIes->SSID.ssid, pIes->SSID.num_ssid) )
5262 {
5263 //SSID not hidden
Madan Mohan Koyyalamudi4e31b132012-11-02 13:13:52 -07005264 tANI_U32 len = pIes->SSID.num_ssid;
Jeff Johnson295189b2012-06-20 16:38:30 -07005265 if (len > SIR_MAC_MAX_SSID_LENGTH)
5266 {
5267 // truncate to fit in our struct
5268 len = SIR_MAC_MAX_SSID_LENGTH;
5269 }
5270 pCsrBssDescription->Result.ssId.length = len;
5271 pCsrBssDescription->Result.timer = vos_timer_get_system_time();
Kiet Lam64c1b492013-07-12 13:56:44 +05305272 vos_mem_copy(pCsrBssDescription->Result.ssId.ssId, pIes->SSID.ssid, len);
Jeff Johnson295189b2012-06-20 16:38:30 -07005273 }
5274 csrLLInsertTail( &pMac->scan.tempScanResults, &pCsrBssDescription->Link, LL_ACCESS_LOCK );
5275 }
5276
5277 return( pCsrBssDescription );
5278}
5279
5280
5281
5282
5283tANI_BOOLEAN csrIsDuplicateBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc1,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07005284 tSirBssDescription *pSirBssDesc2, tDot11fBeaconIEs *pIes2, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07005285{
5286 tANI_BOOLEAN fMatch = FALSE;
5287 tSirMacCapabilityInfo *pCap1, *pCap2;
5288 tDot11fBeaconIEs *pIes1 = NULL;
Jeff Johnsone7245742012-09-05 17:12:55 -07005289 tDot11fBeaconIEs *pIesTemp = pIes2;
Jeff Johnson295189b2012-06-20 16:38:30 -07005290
5291 pCap1 = (tSirMacCapabilityInfo *)&pSirBssDesc1->capabilityInfo;
5292 pCap2 = (tSirMacCapabilityInfo *)&pSirBssDesc2->capabilityInfo;
5293 if(pCap1->ess == pCap2->ess)
5294 {
5295 if (pCap1->ess &&
Jeff Johnsone7245742012-09-05 17:12:55 -07005296 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId)&&
Abhishek Singhe3fa11f2014-05-13 11:11:10 +05305297 (fForced || (vos_chan_to_band(pSirBssDesc1->channelId) == vos_chan_to_band((pSirBssDesc2->channelId)))))
Jeff Johnson295189b2012-06-20 16:38:30 -07005298 {
5299 fMatch = TRUE;
Jeff Johnsone7245742012-09-05 17:12:55 -07005300 // Check for SSID match, if exists
5301 do
5302 {
5303 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
5304 {
5305 break;
5306 }
5307 if( NULL == pIesTemp )
5308 {
5309 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
5310 {
5311 break;
5312 }
5313 }
5314 if(pIes1->SSID.present && pIesTemp->SSID.present)
5315 {
5316 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
5317 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
5318 }
5319 }while(0);
5320
Jeff Johnson295189b2012-06-20 16:38:30 -07005321 }
5322 else if (pCap1->ibss && (pSirBssDesc1->channelId == pSirBssDesc2->channelId))
5323 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005324
5325 do
5326 {
5327 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
5328 {
5329 break;
5330 }
5331 if( NULL == pIesTemp )
5332 {
5333 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
5334 {
5335 break;
5336 }
5337 }
5338 //Same channel cannot have same SSID for different IBSS
5339 if(pIes1->SSID.present && pIesTemp->SSID.present)
5340 {
5341 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
5342 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
5343 }
5344 }while(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005345 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005346 /* In case of P2P devices, ess and ibss will be set to zero */
5347 else if (!pCap1->ess &&
5348 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId))
5349 {
5350 fMatch = TRUE;
5351 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005352 }
5353
5354 if(pIes1)
5355 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305356 vos_mem_free(pIes1);
Jeff Johnson295189b2012-06-20 16:38:30 -07005357 }
Jeff Johnsone7245742012-09-05 17:12:55 -07005358
5359 if( (NULL == pIes2) && pIesTemp )
5360 {
5361 //locally allocated
Kiet Lam64c1b492013-07-12 13:56:44 +05305362 vos_mem_free(pIesTemp);
Jeff Johnsone7245742012-09-05 17:12:55 -07005363 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005364
5365 return( fMatch );
5366}
5367
5368
5369tANI_BOOLEAN csrIsNetworkTypeEqual( tSirBssDescription *pSirBssDesc1, tSirBssDescription *pSirBssDesc2 )
5370{
5371 return( pSirBssDesc1->nwType == pSirBssDesc2->nwType );
5372}
5373
5374
5375//to check whether the BSS matches the dot11Mode
5376static tANI_BOOLEAN csrScanIsBssAllowed(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
5377 tDot11fBeaconIEs *pIes)
5378{
5379 tANI_BOOLEAN fAllowed = eANI_BOOLEAN_FALSE;
5380 eCsrPhyMode phyMode;
5381
5382 if(HAL_STATUS_SUCCESS(csrGetPhyModeFromBss(pMac, pBssDesc, &phyMode, pIes)))
5383 {
5384 switch(pMac->roam.configParam.phyMode)
5385 {
5386 case eCSR_DOT11_MODE_11b:
5387 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
5388 break;
5389 case eCSR_DOT11_MODE_11g:
5390 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
5391 break;
5392 case eCSR_DOT11_MODE_11g_ONLY:
5393 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11g == phyMode);
5394 break;
5395 case eCSR_DOT11_MODE_11a:
5396 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11b != phyMode) && (eCSR_DOT11_MODE_11g != phyMode));
5397 break;
5398 case eCSR_DOT11_MODE_11n_ONLY:
5399 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11n == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
5400 break;
Jeff Johnsone7245742012-09-05 17:12:55 -07005401
5402#ifdef WLAN_FEATURE_11AC
5403 case eCSR_DOT11_MODE_11ac_ONLY:
5404 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11ac == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
5405 break;
5406#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005407 case eCSR_DOT11_MODE_11b_ONLY:
5408 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11b == phyMode);
5409 break;
5410 case eCSR_DOT11_MODE_11a_ONLY:
5411 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a == phyMode);
5412 break;
5413 case eCSR_DOT11_MODE_11n:
Jeff Johnsone7245742012-09-05 17:12:55 -07005414#ifdef WLAN_FEATURE_11AC
5415 case eCSR_DOT11_MODE_11ac:
5416#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005417 case eCSR_DOT11_MODE_TAURUS:
5418 default:
5419 fAllowed = eANI_BOOLEAN_TRUE;
5420 break;
5421 }
5422 }
5423
5424 return (fAllowed);
5425}
5426
5427
5428
5429//Return pIes to caller for future use when returning TRUE.
5430static tANI_BOOLEAN csrScanValidateScanResult( tpAniSirGlobal pMac, tANI_U8 *pChannels,
5431 tANI_U8 numChn, tSirBssDescription *pBssDesc,
5432 tDot11fBeaconIEs **ppIes )
5433{
5434 tANI_BOOLEAN fValidChannel = FALSE;
5435 tDot11fBeaconIEs *pIes = NULL;
5436 tANI_U8 index;
5437
5438 for( index = 0; index < numChn; index++ )
5439 {
5440 // This check relies on the fact that a single BSS description is returned in each
5441 // ScanRsp call, which is the way LIM implemented the scan req/rsp funtions. We changed
5442 // to this model when we ran with a large number of APs. If this were to change, then
5443 // this check would have to mess with removing the bssDescription from somewhere in an
5444 // arbitrary index in the bssDescription array.
5445 if ( pChannels[ index ] == pBssDesc->channelId )
5446 {
5447 fValidChannel = TRUE;
5448 break;
5449 }
5450 }
5451 *ppIes = NULL;
5452 if(fValidChannel)
5453 {
5454 if( HAL_STATUS_SUCCESS( csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIes) ) )
5455 {
5456 fValidChannel = csrScanIsBssAllowed(pMac, pBssDesc, pIes);
5457 if( fValidChannel )
5458 {
5459 *ppIes = pIes;
5460 }
5461 else
5462 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305463 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07005464 }
5465 }
5466 else
5467 {
5468 fValidChannel = FALSE;
5469 }
5470 }
5471
5472 return( fValidChannel );
5473}
5474
5475
5476//Return whether last scan result is received
5477static tANI_BOOLEAN csrScanProcessScanResults( tpAniSirGlobal pMac, tSmeCmd *pCommand,
5478 tSirSmeScanRsp *pScanRsp, tANI_BOOLEAN *pfRemoveCommand )
5479{
5480 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE, fRemoveCommand = eANI_BOOLEAN_FALSE;
5481 tDot11fBeaconIEs *pIes = NULL;
5482 tANI_U32 cbParsed;
5483 tSirBssDescription *pSirBssDescription;
5484 tANI_U32 cbBssDesc;
Agrawal Ashish4cc15bb2016-02-04 17:56:16 +05305485 eHalStatus status;
Jeff Johnson295189b2012-06-20 16:38:30 -07005486 tANI_U32 cbScanResult = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription )
5487 + sizeof(tSirBssDescription); //We need at least one CB
5488
5489 // don't consider the scan rsp to be valid if the status code is Scan Failure. Scan Failure
5490 // is returned when the scan could not find anything. so if we get scan failure return that
5491 // the scan response is invalid. Also check the lenght in the scan result for valid scan
5492 // BssDescriptions....
5493 do
5494 {
5495 if ( ( cbScanResult <= pScanRsp->length ) &&
5496 (( eSIR_SME_SUCCESS == pScanRsp->statusCode ) ||
5497 ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW == pScanRsp->statusCode ) ) )
5498 {
5499 tANI_U8 *pChannelList = NULL;
5500 tANI_U8 cChannels = 0;
5501
5502 //Different scan type can reach this point, we need to distinguish it
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005503#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5504 if( eCsrScanGetLfrResult == pCommand->u.scanCmd.reason )
5505 {
5506 pChannelList = NULL;
5507 cChannels = 0;
5508 }
5509 else
5510#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005511 if( eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason )
5512 {
5513 //eCsrScanSetBGScanParam uses different structure
5514 tCsrBGScanRequest *pBgScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
5515
5516 cChannels = pBgScanReq->ChannelInfo.numOfChannels;
5517 pChannelList = pBgScanReq->ChannelInfo.ChannelList;
5518 }
5519 else
5520 {
5521 //the rest use generic scan request
5522 cChannels = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
5523 pChannelList = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
5524 }
5525
5526 // if the scan result is not on one of the channels in the Valid channel list, then it
5527 // must have come from an AP on an overlapping channel (in the 2.4GHz band). In this case,
5528 // let's drop the scan result.
5529 //
5530 // The other situation is where the scan request is for a scan on a particular channel set
5531 // and the scan result is from a
5532
5533 // if the NumChannels is 0, then we are supposed to be scanning all channels. Use the full channel
5534 // list as the 'valid' channel list. Otherwise, use the specific channel list in the scan parms
5535 // as the valid channels.
5536 if ( 0 == cChannels )
5537 {
5538 tANI_U32 len = sizeof(pMac->roam.validChannelList);
5539
5540 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
5541 {
5542 pChannelList = pMac->roam.validChannelList;
5543 cChannels = (tANI_U8)len;
5544 }
5545 else
5546 {
5547 //Cannot continue
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005548 smsLog( pMac, LOGE, "CSR: Processing internal SCAN results...csrGetCfgValidChannels failed" );
Jeff Johnson295189b2012-06-20 16:38:30 -07005549 break;
5550 }
5551 }
5552
5553 smsLog( pMac, LOG2, "CSR: Processing internal SCAN results..." );
5554 cbParsed = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription );
5555 pSirBssDescription = pScanRsp->bssDescription;
5556 while( cbParsed < pScanRsp->length )
5557 {
5558 if ( csrScanValidateScanResult( pMac, pChannelList, cChannels, pSirBssDescription, &pIes ) )
5559 {
5560 csrScanRemoveDupBssDescriptionFromInterimList(pMac, pSirBssDescription, pIes);
5561 csrScanSaveBssDescriptionToInterimList( pMac, pSirBssDescription, pIes );
5562 if( eSIR_PASSIVE_SCAN == pMac->scan.curScanType )
5563 {
5564 if( csrIs11dSupported( pMac) )
5565 {
5566 //Check whether the BSS is acceptable base on 11d info and our configs.
5567 if( csrMatchCountryCode( pMac, NULL, pIes ) )
5568 {
5569 //Double check whether the channel is acceptable by us.
5570 if( csrIsSupportedChannel( pMac, pSirBssDescription->channelId ) )
5571 {
5572 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
5573 }
5574 }
5575 }
5576 else
5577 {
5578 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
5579 }
5580 }
5581 //Free the resource
Kiet Lam64c1b492013-07-12 13:56:44 +05305582 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07005583 }
5584 // skip over the BSS description to the next one...
5585 cbBssDesc = pSirBssDescription->length + sizeof( pSirBssDescription->length );
5586
5587 cbParsed += cbBssDesc;
5588 pSirBssDescription = (tSirBssDescription *)((tANI_U8 *)pSirBssDescription + cbBssDesc );
5589
5590 } //while
5591 }
5592 else
5593 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005594 smsLog( pMac, LOGW, " Scanrsp fail (0x%08X), length = %d (expected %d)",
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08005595 pScanRsp->statusCode, pScanRsp->length, cbScanResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07005596 //HO bg scan/probe failed no need to try autonomously
5597 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
5598 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005599#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5600 eCsrScanGetLfrResult == pCommand->u.scanCmd.reason ||
5601#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005602 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
5603 {
5604 fRemoveCommand = eANI_BOOLEAN_TRUE;
5605 }
5606 }
5607 }while(0);
5608 if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
5609 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005610 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 -07005611 fRemoveCommand = csrScanComplete( pMac, pScanRsp );
5612 fRet = eANI_BOOLEAN_TRUE;
5613 }//if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
5614 if(pfRemoveCommand)
5615 {
5616 *pfRemoveCommand = fRemoveCommand;
5617 }
5618
Agrawal Ashish4cc15bb2016-02-04 17:56:16 +05305619 /*
5620 * Currently SET_FCC_CHANNEL issues updated channel list to fw.
5621 * At the time of driver load, if scan is issued followed with
5622 * SET_FCC_CHANNEL, driver will send update channel list to fw.
5623 * Fw will stop ongoing scan because of that GUI will have very less
5624 * scan list.
5625 * Update channel list should be sent to fw once scan is done
5626 */
5627 if (pMac->scan.defer_update_channel_list) {
5628 status = csrUpdateChannelList(pMac);
5629 if (eHAL_STATUS_SUCCESS != status)
5630 smsLog(pMac, LOGE,
5631 FL( "failed to update the supported channel list"));
5632 pMac->scan.defer_update_channel_list = false;
5633 }
5634
Jeff Johnson295189b2012-06-20 16:38:30 -07005635#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305636 if (pMac->fScanOffload)
5637 return fRet;
5638
Jeff Johnson295189b2012-06-20 16:38:30 -07005639 if (!csrLLIsListEmpty( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK ))
5640 {
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005641 /* Pending scan commands in the list because the previous scan command
5642 * was split into a scan command on one channel + a scan command for all
5643 * remaining channels.
5644 *
5645 * Start timer to trigger processing of the next scan command.
Srikant Kuppa866893f2012-12-27 17:28:14 -08005646 * NOTE for LFR:
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305647 * Do not split scans if no concurrent infra connections are
Srikant Kuppa866893f2012-12-27 17:28:14 -08005648 * active and if the scan is a BG scan triggered by LFR (OR)
5649 * any scan if LFR is in the middle of a BG scan. Splitting
5650 * the scan is delaying the time it takes for LFR to find
5651 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005652 */
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305653 if ( (csrIsStaSessionConnected(pMac) &&
Srikant Kuppa866893f2012-12-27 17:28:14 -08005654#ifdef FEATURE_WLAN_LFR
5655 (csrIsConcurrentInfraConnected(pMac) ||
5656 ((pCommand->u.scanCmd.reason != eCsrScanBgScan) &&
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305657 (pMac->roam.neighborRoamInfo.neighborRoamState !=
Srikant Kuppa866893f2012-12-27 17:28:14 -08005658 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
5659#endif
5660 (pCommand->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305661 (csrIsP2pSessionConnected(pMac)) )
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005662 {
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005663 /* if active connected sessions present then continue to split scan
5664 * with specified interval between consecutive scans */
5665 csrSetDefaultScanTiming(pMac, pCommand->u.scanCmd.u.scanRequest.scanType, &(pCommand->u.scanCmd.u.scanRequest));
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05305666 vos_timer_start(&pMac->scan.hTimerStaApConcTimer,
5667 pCommand->u.scanCmd.u.scanRequest.restTime);
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005668 } else {
5669 /* if no connected sessions present then initiate next scan command immediately */
5670 /* minimum timer granularity is 10ms */
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05305671 vos_timer_start(&pMac->scan.hTimerStaApConcTimer, 10);
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005672 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005673 }
5674#endif
5675 return (fRet);
5676}
5677
5678
5679tANI_BOOLEAN csrScanIsWildCardScan( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5680{
5681 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
Kiet Lam64c1b492013-07-12 13:56:44 +05305682 tANI_BOOLEAN f = vos_mem_compare(pCommand->u.scanCmd.u.scanRequest.bssid,
5683 bssid, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07005684
5685 //It is not a wild card scan if the bssid is not broadcast and the number of SSID is 1.
5686 return ((tANI_BOOLEAN)( (f || (0xff == pCommand->u.scanCmd.u.scanRequest.bssid[0])) &&
5687 (pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs != 1) ));
5688}
5689
5690
5691eHalStatus csrScanSmeScanResponse( tpAniSirGlobal pMac, void *pMsgBuf )
5692{
5693 eHalStatus status = eHAL_STATUS_SUCCESS;
5694 tListElem *pEntry;
5695 tSmeCmd *pCommand;
5696 eCsrScanStatus scanStatus;
Sunkad, Anand Ningappa3ec8bf72016-02-05 15:13:30 +05305697 tSirSmeScanRsp *pScanRsp;
Jeff Johnson295189b2012-06-20 16:38:30 -07005698 tSmeGetScanChnRsp *pScanChnInfo;
5699 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
5700 eCsrScanReason reason = eCsrScanOther;
5701
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305702 if (pMac->fScanOffload)
5703 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList,
5704 LL_ACCESS_LOCK);
5705 else
5706 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07005707
5708 if ( pEntry )
5709 {
5710 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
5711 if ( eSmeCommandScan == pCommand->command )
5712 {
Deepthi Gowrife5340b2016-04-11 12:15:46 +05305713 /* Purge the scan results based on Aging */
5714 if (pEntry && pMac->scan.scanResultCfgAgingTime)
5715 csrPurgeScanResultByAge(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07005716 reason = pCommand->u.scanCmd.reason;
5717 switch(pCommand->u.scanCmd.reason)
5718 {
5719 case eCsrScanAbortBgScan:
5720 case eCsrScanAbortNormalScan:
5721 case eCsrScanBGScanAbort:
5722 case eCsrScanBGScanEnable:
Sunkad, Anand Ningappa3ec8bf72016-02-05 15:13:30 +05305723 pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
5724 scanStatus = (eSIR_SME_SUCCESS == pScanRsp->statusCode) ?
5725 eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005726 break;
5727 case eCsrScanGetScanChnInfo:
Deepthi Gowrife5340b2016-04-11 12:15:46 +05305728 pScanChnInfo = (tSmeGetScanChnRsp *)pMsgBuf;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005729 /*
5730 * status code not available in tSmeGetScanChnRsp, so
5731 * by default considereing it to be success
5732 */
5733 scanStatus = eSIR_SME_SUCCESS;
Deepthi Gowrife5340b2016-04-11 12:15:46 +05305734 csrScanAgeResults(pMac, pScanChnInfo);
Jeff Johnson295189b2012-06-20 16:38:30 -07005735 break;
5736 case eCsrScanForCapsChange:
Sunkad, Anand Ningappa3ec8bf72016-02-05 15:13:30 +05305737 pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
5738 scanStatus = (eSIR_SME_SUCCESS == pScanRsp->statusCode) ?
5739 eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005740 csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand );
5741 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005742 case eCsrScanP2PFindPeer:
Sunkad, Anand Ningappa3ec8bf72016-02-05 15:13:30 +05305743 pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
5744 scanStatus = ((eSIR_SME_SUCCESS == pScanRsp->statusCode) &&
5745 (pScanRsp->length > 50)) ? eCSR_SCAN_FOUND_PEER : eCSR_SCAN_FAILURE;
5746 csrScanProcessScanResults( pMac, pCommand, pScanRsp, NULL );
5747 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005748 case eCsrScanSetBGScanParam:
5749 default:
Sunkad, Anand Ningappa3ec8bf72016-02-05 15:13:30 +05305750 pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
5751 scanStatus = (eSIR_SME_SUCCESS == pScanRsp->statusCode) ?
5752 eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005753 if(csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand ))
5754 {
5755 //Not to get channel info if the scan is not a wildcard scan because
5756 //it may cause scan results got aged out incorrectly.
Ratheesh S Pece1f832015-07-25 15:50:25 +05305757 if(csrScanIsWildCardScan( pMac, pCommand ) &&
5758 (!pCommand->u.scanCmd.u.scanRequest.p2pSearch)
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005759#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5760 && (pCommand->u.scanCmd.reason != eCsrScanGetLfrResult)
5761#endif
5762 )
Jeff Johnson295189b2012-06-20 16:38:30 -07005763 {
Ratheesh S Pece1f832015-07-25 15:50:25 +05305764 csrScanGetScanChnInfo(pMac, pCommand);
Jeff Johnson295189b2012-06-20 16:38:30 -07005765 }
5766 }
5767 break;
5768 }//switch
5769 if(fRemoveCommand)
5770 {
5771
5772 csrReleaseScanCommand(pMac, pCommand, scanStatus);
5773
Sunkad, Anand Ningappa3ec8bf72016-02-05 15:13:30 +05305774 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005775 smeProcessPendingQueue( pMac );
5776 }
5777 else
5778 {
5779 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
5780 status = eHAL_STATUS_FAILURE;
5781 }
5782 }
5783 else
5784 {
5785 smsLog( pMac, LOGW, "CSR: Scan Completion called but NO commands are ACTIVE ..." );
5786 status = eHAL_STATUS_FAILURE;
5787 }
5788
5789 return (status);
5790}
5791
5792
5793
5794
5795tCsrScanResultInfo *csrScanResultGetFirst(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
5796{
5797 tListElem *pEntry;
5798 tCsrScanResult *pResult;
5799 tCsrScanResultInfo *pRet = NULL;
5800 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5801
5802 if(pResultList)
5803 {
5804 csrLLLock(&pResultList->List);
5805 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5806 if(pEntry)
5807 {
5808 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
5809 pRet = &pResult->Result;
5810 }
5811 pResultList->pCurEntry = pEntry;
5812 csrLLUnlock(&pResultList->List);
5813 }
5814
5815 return pRet;
5816}
5817
5818
5819tCsrScanResultInfo *csrScanResultGetNext(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
5820{
5821 tListElem *pEntry = NULL;
5822 tCsrScanResult *pResult = NULL;
5823 tCsrScanResultInfo *pRet = NULL;
5824 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5825
5826 if(pResultList)
5827 {
5828 csrLLLock(&pResultList->List);
5829 if(NULL == pResultList->pCurEntry)
5830 {
5831 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5832 }
5833 else
5834 {
5835 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
5836 }
5837 if(pEntry)
5838 {
5839 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
5840 pRet = &pResult->Result;
5841 }
5842 pResultList->pCurEntry = pEntry;
5843 csrLLUnlock(&pResultList->List);
5844 }
5845
5846 return pRet;
5847}
5848
5849
5850//This function moves the first BSS that matches the bssid to the head of the result
5851eHalStatus csrMoveBssToHeadFromBSSID(tpAniSirGlobal pMac, tCsrBssid *bssid, tScanResultHandle hScanResult)
5852{
5853 eHalStatus status = eHAL_STATUS_FAILURE;
5854 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5855 tCsrScanResult *pResult = NULL;
5856 tListElem *pEntry = NULL;
5857
5858 if(pResultList && bssid)
5859 {
5860 csrLLLock(&pResultList->List);
5861 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5862 while(pEntry)
5863 {
5864 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
Kiet Lam64c1b492013-07-12 13:56:44 +05305865 if (vos_mem_compare(bssid, pResult->Result.BssDescriptor.bssId, sizeof(tCsrBssid)))
Jeff Johnson295189b2012-06-20 16:38:30 -07005866 {
5867 status = eHAL_STATUS_SUCCESS;
5868 csrLLRemoveEntry(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
5869 csrLLInsertHead(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
5870 break;
5871 }
5872 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
5873 }
5874 csrLLUnlock(&pResultList->List);
5875 }
5876
5877 return (status);
5878}
5879
5880
5881//Remove the BSS if possible.
5882//Return -- TRUE == the BSS is remove. False == Fail to remove it
5883//This function is called when list lock is held. Be caution what functions it can call.
5884tANI_BOOLEAN csrScanAgeOutBss(tpAniSirGlobal pMac, tCsrScanResult *pResult)
5885{
5886 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
5887 tANI_U32 i;
5888 tCsrRoamSession *pSession;
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305889 tANI_BOOLEAN isConnBssfound = eANI_BOOLEAN_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005890
5891 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5892 {
5893 if( CSR_IS_SESSION_VALID( pMac, i ) )
5894 {
5895 pSession = CSR_GET_SESSION( pMac, i );
5896 //Not to remove the BSS we are connected to.
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305897 if(csrIsConnStateConnectedInfra(pMac, i) && (NULL != pSession->pConnectBssDesc) &&
5898 (csrIsDuplicateBssDescription(pMac, &pResult->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07005899 pSession->pConnectBssDesc, NULL, FALSE))
Jeff Johnson295189b2012-06-20 16:38:30 -07005900 )
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305901 {
5902 isConnBssfound = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005903 break;
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305904 }
5905 }
5906 }
5907
5908 if( isConnBssfound )
Jeff Johnson295189b2012-06-20 16:38:30 -07005909 {
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305910 //Reset the counter so that aging out of connected BSS won't hapeen too soon
Jeff Johnson295189b2012-06-20 16:38:30 -07005911 pResult->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Deepthi Gowri4480a3f2016-05-18 19:30:17 +05305912 pResult->Result.BssDescriptor.nReceivedTime =
5913 vos_timer_get_system_time();
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305914
5915 return (fRet);
5916 }
5917 else
5918 {
5919 smsLog(pMac, LOGW, "Aging out BSS "MAC_ADDRESS_STR" Channel %d",
5920 MAC_ADDR_ARRAY(pResult->Result.BssDescriptor.bssId),
5921 pResult->Result.BssDescriptor.channelId);
5922 //No need to hold the spin lock because caller should hold the lock for pMac->scan.scanResultList
5923 if( csrLLRemoveEntry(&pMac->scan.scanResultList, &pResult->Link, LL_ACCESS_NOLOCK) )
5924 {
5925 if (csrIsMacAddressEqual(pMac,
5926 (tCsrBssid *) pResult->Result.BssDescriptor.bssId,
5927 (tCsrBssid *) pMac->scan.currentCountryBssid))
5928 {
5929 smsLog(pMac, LOGW, "Aging out 11d BSS "MAC_ADDRESS_STR,
5930 MAC_ADDR_ARRAY(pResult->Result.BssDescriptor.bssId));
5931 pMac->scan.currentCountryRSSI = -128;
5932 }
5933 csrFreeScanResultEntry(pMac, pResult);
5934 fRet = eANI_BOOLEAN_TRUE;
5935 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005936 }
5937
5938 return (fRet);
5939}
5940
5941
5942eHalStatus csrScanAgeResults(tpAniSirGlobal pMac, tSmeGetScanChnRsp *pScanChnInfo)
5943{
5944 eHalStatus status = eHAL_STATUS_SUCCESS;
5945 tListElem *pEntry, *tmpEntry;
5946 tCsrScanResult *pResult;
5947 tLimScanChn *pChnInfo;
5948 tANI_U8 i;
5949
5950 csrLLLock(&pMac->scan.scanResultList);
5951 for(i = 0; i < pScanChnInfo->numChn; i++)
5952 {
5953 pChnInfo = &pScanChnInfo->scanChn[i];
5954 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
5955 while( pEntry )
5956 {
5957 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
5958 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
5959 if(pResult->Result.BssDescriptor.channelId == pChnInfo->channelId)
5960 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005961 if(pResult->AgingCount <= 0)
5962 {
5963 smsLog(pMac, LOGW, " age out due to ref count");
5964 csrScanAgeOutBss(pMac, pResult);
5965 }
Madan Mohan Koyyalamudib9d3dcc2012-09-28 16:47:50 -07005966 else
5967 {
5968 pResult->AgingCount--;
5969 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005970 }
5971 pEntry = tmpEntry;
5972 }
5973 }
5974 csrLLUnlock(&pMac->scan.scanResultList);
5975
5976 return (status);
5977}
5978
Abhishek Singhc640dbb2015-06-08 10:54:17 +05305979eHalStatus csrIbssAgeBss(tpAniSirGlobal pMac)
5980{
5981 eHalStatus status = eHAL_STATUS_SUCCESS;
5982 tListElem *pEntry, *tmpEntry;
5983 tCsrScanResult *pResult;
5984
5985 csrLLLock(&pMac->scan.scanResultList);
5986 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
5987 while( pEntry )
5988 {
5989 tmpEntry = csrLLNext(&pMac->scan.scanResultList,
5990 pEntry, LL_ACCESS_NOLOCK);
5991 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
5992
5993 smsLog(pMac, LOGW, FL(" age out due Forced IBSS leave"));
5994 csrScanAgeOutBss(pMac, pResult);
5995 pEntry = tmpEntry;
5996 }
5997 csrLLUnlock(&pMac->scan.scanResultList);
5998
5999 return (status);
6000}
Jeff Johnson295189b2012-06-20 16:38:30 -07006001
Abhishek Singh72c2f4e2016-07-22 11:25:43 +05306002/**
6003 * csr_remove_bssid_from_scan_list() - remove the bssid from
6004 * scan list
6005 * @pMac: mac context.
6006 * @bssid: bssid to be removed
6007 *
6008 * This function remove the given bssid from scan list.
6009 *
6010 * Return: void.
6011 */
6012void csr_remove_bssid_from_scan_list(tpAniSirGlobal pMac,
6013 tSirMacAddr bssid)
6014{
6015 tListElem *entry,*free_elem;
6016 tCsrScanResult *bss_desc;
6017 tDblLinkList *list = &pMac->scan.scanResultList;
6018
6019 csrLLLock(list);
6020 entry = csrLLPeekHead(list, LL_ACCESS_NOLOCK);
6021 while (entry != NULL) {
6022 bss_desc = GET_BASE_ADDR( entry, tCsrScanResult, Link);
6023 if (vos_mem_compare(bss_desc->Result.BssDescriptor.bssId,
6024 bssid, sizeof(tSirMacAddr))) {
6025 free_elem = entry;
6026 entry = csrLLNext(list, entry, LL_ACCESS_NOLOCK);
6027 csrLLRemoveEntry(list, free_elem, LL_ACCESS_NOLOCK);
6028 csrFreeScanResultEntry(pMac, bss_desc);
6029 smsLog(pMac, LOGW, FL("Removed BSS entry:%pM"),
6030 bssid);
6031 continue;
6032 }
6033 entry = csrLLNext(list, entry, LL_ACCESS_NOLOCK);
6034 }
6035 csrLLUnlock(list);
6036}
6037
Jeff Johnson295189b2012-06-20 16:38:30 -07006038eHalStatus csrSendMBScanReq( tpAniSirGlobal pMac, tANI_U16 sessionId,
6039 tCsrScanRequest *pScanReq, tScanReqParam *pScanReqParam )
6040{
6041 eHalStatus status = eHAL_STATUS_SUCCESS;
6042 tSirSmeScanReq *pMsg;
6043 tANI_U16 msgLen;
6044 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
6045 tSirScanType scanType = pScanReq->scanType;
6046 tANI_U32 minChnTime; //in units of milliseconds
6047 tANI_U32 maxChnTime; //in units of milliseconds
6048 tANI_U32 i;
6049 tANI_U8 selfMacAddr[WNI_CFG_BSSID_LEN];
6050 tANI_U8 *pSelfMac = NULL;
6051
6052 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
6053 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) +
6054 ( pScanReq->uIEFieldLen ) ;
6055
Kiet Lam64c1b492013-07-12 13:56:44 +05306056 pMsg = vos_mem_malloc(msgLen);
6057 if ( NULL == pMsg )
6058 status = eHAL_STATUS_FAILURE;
6059 else
6060 status = eHAL_STATUS_SUCCESS;
6061 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07006062 {
6063 do
6064 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306065 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006066 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
6067 pMsg->length = pal_cpu_to_be16(msgLen);
6068 //ToDO: Fill in session info when we need to do scan base on session.
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05306069 if ((pMac->fScanOffload) && (sessionId != CSR_SESSION_ID_INVALID))
6070 {
6071 pMsg->sessionId = sessionId;
6072 }
6073 else
6074 {
6075 /* if sessionId == CSR_SESSION_ID_INVALID, then send the scan
6076 request on first available session */
6077 pMsg->sessionId = 0;
6078 }
6079
Jeff Johnson295189b2012-06-20 16:38:30 -07006080 pMsg->transactionId = 0;
6081 pMsg->dot11mode = (tANI_U8) csrTranslateToWNICfgDot11Mode(pMac, csrFindBestPhyMode( pMac, pMac->roam.configParam.phyMode ));
6082 pMsg->bssType = pal_cpu_to_be32(csrTranslateBsstypeToMacType(pScanReq->BSSType));
6083
6084 if ( CSR_IS_SESSION_VALID( pMac, sessionId ) )
6085 {
6086 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[sessionId].selfMacAddr;
6087 }
6088 else
6089 {
6090 // Since we don't have session for the scanning, we find a valid session. In case we fail to
6091 // do so, get the WNI_CFG_STA_ID
6092 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
6093 {
6094 if( CSR_IS_SESSION_VALID( pMac, i ) )
6095 {
6096 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[i].selfMacAddr;
6097 break;
6098 }
6099 }
6100 if( CSR_ROAM_SESSION_MAX == i )
6101 {
6102 tANI_U32 len = WNI_CFG_BSSID_LEN;
6103 pSelfMac = selfMacAddr;
6104 status = ccmCfgGetStr( pMac, WNI_CFG_STA_ID, pSelfMac, &len );
6105 if( !HAL_STATUS_SUCCESS( status ) ||
6106 ( len < WNI_CFG_BSSID_LEN ) )
6107 {
6108 smsLog( pMac, LOGE, FL(" Can not get self MAC address from CFG status = %d"), status );
6109 //Force failed status
6110 status = eHAL_STATUS_FAILURE;
6111 break;
6112 }
6113 }
6114 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306115 vos_mem_copy((tANI_U8 *)pMsg->selfMacAddr, pSelfMac, sizeof(tSirMacAddr));
Jeff Johnson295189b2012-06-20 16:38:30 -07006116
6117 //sirCopyMacAddr
Kiet Lam64c1b492013-07-12 13:56:44 +05306118 vos_mem_copy((tANI_U8 *)pMsg->bssId, (tANI_U8 *)&pScanReq->bssid, sizeof(tSirMacAddr));
6119 if ( vos_mem_compare(pScanReq->bssid, bssid, sizeof(tCsrBssid)))
Jeff Johnson295189b2012-06-20 16:38:30 -07006120 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306121 vos_mem_set(pMsg->bssId, sizeof(tSirMacAddr), 0xff);
Jeff Johnson295189b2012-06-20 16:38:30 -07006122 }
6123 else
6124 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306125 vos_mem_copy(pMsg->bssId, pScanReq->bssid, WNI_CFG_BSSID_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07006126 }
6127 minChnTime = pScanReq->minChnTime;
6128 maxChnTime = pScanReq->maxChnTime;
6129
6130 //Verify the scan type first, if the scan is active scan, we need to make sure we
6131 //are allowed to do so.
6132 /* if 11d is enabled & we don't see any beacon around, scan type falls
6133 back to passive. But in BT AMP STA mode we need to send out a
6134 directed probe*/
6135 if( (eSIR_PASSIVE_SCAN != scanType) && (eCSR_SCAN_P2P_DISCOVERY != pScanReq->requestType)
6136 && (eCSR_BSS_TYPE_WDS_STA != pScanReq->BSSType)
6137 && (eANI_BOOLEAN_FALSE == pMac->scan.fEnableBypass11d))
6138 {
6139 scanType = pMac->scan.curScanType;
6140 if(eSIR_PASSIVE_SCAN == pMac->scan.curScanType)
6141 {
6142 if(minChnTime < pMac->roam.configParam.nPassiveMinChnTime)
6143 {
6144 minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
6145 }
6146 if(maxChnTime < pMac->roam.configParam.nPassiveMaxChnTime)
6147 {
6148 maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
6149 }
6150 }
6151 }
6152 pMsg->scanType = pal_cpu_to_be32(scanType);
6153
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306154 pMsg->numSsid =
6155 (pScanReq->SSIDs.numOfSSIDs < SIR_SCAN_MAX_NUM_SSID) ?
6156 pScanReq->SSIDs.numOfSSIDs : SIR_SCAN_MAX_NUM_SSID;
Jeff Johnson295189b2012-06-20 16:38:30 -07006157 if((pScanReq->SSIDs.numOfSSIDs != 0) && ( eSIR_PASSIVE_SCAN != scanType ))
6158 {
Jeff Johnson40b59aa2013-03-19 14:43:18 -07006159 for (i = 0; i < pMsg->numSsid; i++)
6160 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306161 vos_mem_copy(&pMsg->ssId[i],
6162 &pScanReq->SSIDs.SSIDList[i].SSID, sizeof(tSirMacSSid));
Jeff Johnson40b59aa2013-03-19 14:43:18 -07006163 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006164 }
6165 else
6166 {
6167 //Otherwise we scan all SSID and let the result filter later
Jeff Johnson40b59aa2013-03-19 14:43:18 -07006168 for (i = 0; i < SIR_SCAN_MAX_NUM_SSID; i++)
6169 {
6170 pMsg->ssId[i].length = 0;
6171 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006172 }
6173
Jeff Johnson295189b2012-06-20 16:38:30 -07006174 pMsg->minChannelTime = pal_cpu_to_be32(minChnTime);
6175 pMsg->maxChannelTime = pal_cpu_to_be32(maxChnTime);
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08006176 pMsg->minChannelTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
6177 pMsg->maxChannelTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07006178 //hidden SSID option
6179 pMsg->hiddenSsid = pScanReqParam->hiddenSsid;
6180 //rest time
6181 //pMsg->restTime = pScanReq->restTime;
6182 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
6183 // All the scan results caching will be done by Roaming
6184 // We do not want LIM to do any caching of scan results,
6185 // so delete the LIM cache on all scan requests
6186 pMsg->returnFreshResults = pScanReqParam->freshScan;
6187 //Always ask for unique result
6188 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
6189 pMsg->channelList.numChannels = (tANI_U8)pScanReq->ChannelInfo.numOfChannels;
6190 if(pScanReq->ChannelInfo.numOfChannels)
6191 {
6192 //Assuming the channelNumber is tANI_U8 (1 byte)
Kiet Lam64c1b492013-07-12 13:56:44 +05306193 vos_mem_copy(pMsg->channelList.channelNumber,
6194 pScanReq->ChannelInfo.ChannelList,
6195 pScanReq->ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07006196 }
6197
6198 pMsg->uIEFieldLen = (tANI_U16) pScanReq->uIEFieldLen;
6199 pMsg->uIEFieldOffset = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
6200 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) ;
6201 if(pScanReq->uIEFieldLen != 0)
6202 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306203 vos_mem_copy((tANI_U8 *)pMsg+pMsg->uIEFieldOffset, pScanReq->pIEField,
6204 pScanReq->uIEFieldLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07006205 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006206 pMsg->p2pSearch = pScanReq->p2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07006207
Madan Mohan Koyyalamudi9b876782012-10-11 16:22:51 -07006208 if (pScanReq->requestType == eCSR_SCAN_HO_BG_SCAN)
6209 {
6210 pMsg->backgroundScanMode = eSIR_ROAMING_SCAN;
6211 }
6212
Jeff Johnson295189b2012-06-20 16:38:30 -07006213 }while(0);
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05306214 smsLog(pMac, LOG1, FL("domainIdCurrent %s (%d) scanType %s (%d)"
6215 "bssType %s (%d), requestType %s(%d)"
6216 "numChannels %d"),
6217 voss_DomainIdtoString(pMac->scan.domainIdCurrent),
6218 pMac->scan.domainIdCurrent,
6219 lim_ScanTypetoString(pMsg->scanType), pMsg->scanType,
6220 lim_BssTypetoString(pMsg->bssType), pMsg->bssType,
6221 sme_requestTypetoString(pScanReq->requestType),
6222 pScanReq->requestType,
6223 pMsg->channelList.numChannels);
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08006224
6225 for(i = 0; i < pMsg->channelList.numChannels; i++)
6226 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006227 smsLog(pMac, LOG3, FL("channelNumber[%d]= %d"), i, pMsg->channelList.channelNumber[i]);
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08006228 }
6229
Jeff Johnson295189b2012-06-20 16:38:30 -07006230 if(HAL_STATUS_SUCCESS(status))
6231 {
6232 status = palSendMBMessage(pMac->hHdd, pMsg);
6233 }
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08006234 else
6235 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006236 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d"), status );
Kiet Lam64c1b492013-07-12 13:56:44 +05306237 vos_mem_free(pMsg);
Jeff Johnson295189b2012-06-20 16:38:30 -07006238 }
6239 }//Success allocated memory
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08006240 else
6241 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006242 smsLog( pMac, LOGE, FL(" memory allocation failure"));
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08006243 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006244
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306245 if(!HAL_STATUS_SUCCESS(status))
6246 {
6247 smsLog( pMac, LOG1, FL("Failed: SId: %d FirstMatch = %d"
6248 " UniqueResult = %d freshScan = %d hiddenSsid = %d"),
6249 sessionId, pScanReqParam->bReturnAfter1stMatch,
6250 pScanReqParam->fUniqueResult, pScanReqParam->freshScan,
6251 pScanReqParam->hiddenSsid );
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05306252 smsLog( pMac, LOG1, FL("scanType = %s (%d) BSSType = %s (%d) "
6253 "numOfSSIDs = %d numOfChannels = %d requestType = %s (%d)"
6254 " p2pSearch = %d\n"),
6255 lim_ScanTypetoString(pScanReq->scanType),
6256 pScanReq->scanType,
6257 lim_BssTypetoString(pScanReq->BSSType),
6258 pScanReq->BSSType,
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306259 pScanReq->SSIDs.numOfSSIDs,
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05306260 pScanReq->ChannelInfo.numOfChannels,
6261 sme_requestTypetoString(pScanReq->requestType),
6262 pScanReq->requestType,
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306263 pScanReq->p2pSearch );
6264
6265 }
6266
Jeff Johnson295189b2012-06-20 16:38:30 -07006267 return( status );
6268}
6269
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006270eHalStatus csrSendMBScanResultReq( tpAniSirGlobal pMac, tANI_U32 sessionId, tScanReqParam *pScanReqParam )
Jeff Johnson295189b2012-06-20 16:38:30 -07006271{
6272 eHalStatus status = eHAL_STATUS_SUCCESS;
6273 tSirSmeScanReq *pMsg;
6274 tANI_U16 msgLen;
6275
6276 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ));
Kiet Lam64c1b492013-07-12 13:56:44 +05306277 pMsg = vos_mem_malloc(msgLen);
6278 if ( NULL == pMsg )
6279 status = eHAL_STATUS_FAILURE;
6280 else
Jeff Johnson295189b2012-06-20 16:38:30 -07006281 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306282 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006283 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
6284 pMsg->length = pal_cpu_to_be16(msgLen);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006285 pMsg->sessionId = sessionId;
6286 pMsg->transactionId = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07006287 pMsg->returnFreshResults = pScanReqParam->freshScan;
6288 //Always ask for unique result
6289 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
6290 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
6291 status = palSendMBMessage(pMac->hHdd, pMsg);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006292 if (!HAL_STATUS_SUCCESS(status))
6293 {
6294 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d\n"), status );
6295 }
6296
Jeff Johnson295189b2012-06-20 16:38:30 -07006297 }
6298
6299 return( status );
6300}
6301
6302
6303
6304eHalStatus csrScanChannels( tpAniSirGlobal pMac, tSmeCmd *pCommand )
6305{
6306 eHalStatus status = eHAL_STATUS_FAILURE;
6307 tScanReqParam scanReq;
6308
6309 do
6310 {
6311 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE | TRUE;
6312 scanReq.fUniqueResult = TRUE;
6313 scanReq.hiddenSsid = SIR_SCAN_NO_HIDDEN_SSID;
6314 if(eCsrScanForSsid == pCommand->u.scanCmd.reason)
6315 {
6316 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_FIRST_MATCH;
6317 }
6318 else
6319 {
6320 // Basically do scan on all channels even for 11D 1st scan case.
6321 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
6322 }
6323 if((eCsrScanBgScan == pCommand->u.scanCmd.reason)||
6324 (eCsrScanProbeBss == pCommand->u.scanCmd.reason))
6325 {
6326 scanReq.hiddenSsid = SIR_SCAN_HIDDEN_SSID_PE_DECISION;
6327 }
6328
6329#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
6330 {
6331 vos_log_scan_pkt_type *pScanLog = NULL;
6332
6333 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
6334 if(pScanLog)
6335 {
6336 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
6337 eCsrScanProbeBss == pCommand->u.scanCmd.reason)
6338 {
6339 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
6340 }
6341 else
6342 {
6343 if( (eSIR_PASSIVE_SCAN != pCommand->u.scanCmd.u.scanRequest.scanType) &&
6344 (eSIR_PASSIVE_SCAN != pMac->scan.curScanType) )
6345 {
6346 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_REQ;
6347 }
6348 else
6349 {
6350 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_REQ;
6351 }
6352 }
6353 pScanLog->minChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.minChnTime;
6354 pScanLog->maxChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.maxChnTime;
6355 pScanLog->numChannel = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
6356 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
6357 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306358 vos_mem_copy(pScanLog->channels,
6359 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
6360 pScanLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07006361 }
6362 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
6363 }
6364 }
6365#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
6366
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05306367 csrClearVotesForCountryInfo(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07006368 status = csrSendMBScanReq(pMac, pCommand->sessionId,
6369 &pCommand->u.scanCmd.u.scanRequest, &scanReq);
6370 }while(0);
6371
6372 return( status );
6373}
6374
6375
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006376eHalStatus csrScanRetrieveResult(tpAniSirGlobal pMac, tSmeCmd *pCommand)
Jeff Johnson295189b2012-06-20 16:38:30 -07006377{
6378 eHalStatus status = eHAL_STATUS_FAILURE;
6379 tScanReqParam scanReq;
6380
6381 do
6382 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006383#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
6384 if (eCsrScanGetLfrResult == pCommand->u.scanCmd.reason)
6385 {
6386 //to get the LFR candidates from PE cache
6387 scanReq.freshScan = SIR_BG_SCAN_RETURN_LFR_CACHED_RESULTS|SIR_BG_SCAN_PURGE_LFR_RESULTS;
6388 scanReq.fUniqueResult = TRUE;
6389 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
6390 }
6391 else
6392#endif
6393 {
6394 //not a fresh scan
6395 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE;
6396 scanReq.fUniqueResult = TRUE;
6397 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
6398 }
6399 status = csrSendMBScanResultReq(pMac, pCommand->sessionId, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07006400 }while(0);
6401
6402 return (status);
6403}
6404
Siddharth Bhald8a95e82015-02-12 20:14:52 +05306405eHalStatus csrProcessMacAddrSpoofCommand( tpAniSirGlobal pMac, tSmeCmd *pCommand )
6406{
6407 tSirSpoofMacAddrReq *pMsg;
6408 tANI_U16 msgLen;
6409 eHalStatus status = eHAL_STATUS_FAILURE;
6410 do {
6411 msgLen = sizeof(tSirSpoofMacAddrReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07006412
Siddharth Bhald8a95e82015-02-12 20:14:52 +05306413 pMsg = vos_mem_malloc(msgLen);
6414 if ( NULL == pMsg )
6415 return eHAL_STATUS_FAILURE;
6416 pMsg->messageType= pal_cpu_to_be16((tANI_U16)eWNI_SME_MAC_SPOOF_ADDR_IND);
6417 pMsg->length= pal_cpu_to_be16(msgLen);
6418 // spoof mac address
6419 vos_mem_copy((tANI_U8 *)pMsg->macAddr,
6420 (tANI_U8 *)pCommand->u.macAddrSpoofCmd.macAddr, sizeof(tSirMacAddr));
6421 status = palSendMBMessage(pMac->hHdd, pMsg);
6422 } while( 0 );
6423 return( status );
6424}
Jeff Johnson295189b2012-06-20 16:38:30 -07006425
6426eHalStatus csrProcessScanCommand( tpAniSirGlobal pMac, tSmeCmd *pCommand )
6427{
6428 eHalStatus status = eHAL_STATUS_SUCCESS;
6429 tCsrChannelInfo newChannelInfo = {0, NULL};
6430 int i, j;
6431 tANI_U8 *pChannel = NULL;
6432 tANI_U32 len = 0;
6433
6434 // Transition to Scanning state...
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306435 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07006436 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306437 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
6438 {
Abhishek Singhf52182c2016-08-24 11:15:23 +05306439 pMac->roam.prev_state[i]=
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306440 csrRoamStateChange( pMac, eCSR_ROAMING_STATE_SCANNING, i);
6441 smsLog( pMac, LOG3, "starting SCAN command from %d state...."
Abhishek Singhf52182c2016-08-24 11:15:23 +05306442 " reason is %d", pMac->roam.prev_state[i],
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306443 pCommand->u.scanCmd.reason );
6444 }
6445 }
6446 else
6447 {
Abhishek Singhf52182c2016-08-24 11:15:23 +05306448 pMac->roam.prev_state[pCommand->sessionId] =
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306449 csrRoamStateChange(pMac, eCSR_ROAMING_STATE_SCANNING,
6450 pCommand->sessionId);
6451 smsLog( pMac, LOG3,
6452 "starting SCAN command from %d state.... reason is %d",
Abhishek Singhf52182c2016-08-24 11:15:23 +05306453 pMac->roam.prev_state[pCommand->sessionId],
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306454 pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07006455 }
6456
6457 switch(pCommand->u.scanCmd.reason)
6458 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006459#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
6460 case eCsrScanGetLfrResult:
6461#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006462 case eCsrScanGetResult:
6463 case eCsrScanForCapsChange: //For cap change, LIM already save BSS description
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006464 status = csrScanRetrieveResult(pMac, pCommand);
Jeff Johnson295189b2012-06-20 16:38:30 -07006465 break;
6466 case eCsrScanSetBGScanParam:
6467 status = csrProcessSetBGScanParam(pMac, pCommand);
6468 break;
6469 case eCsrScanBGScanAbort:
6470 status = csrSetCfgBackgroundScanPeriod(pMac, 0);
6471 break;
6472 case eCsrScanBGScanEnable:
6473 status = csrSetCfgBackgroundScanPeriod(pMac, pMac->roam.configParam.bgScanInterval);
6474 break;
6475 case eCsrScanGetScanChnInfo:
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05306476 status = csrScanGetScanChannelInfo(pMac, pCommand->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07006477 break;
6478 case eCsrScanUserRequest:
6479 if(pMac->roam.configParam.fScanTwice)
6480 {
6481 //We scan 2.4 channel twice
6482 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels &&
6483 (NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList))
6484 {
6485 len = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
6486 //allocate twice the channel
Mukul Sharmaa631e892014-08-28 15:38:51 +05306487 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(len * 2);
Jeff Johnson295189b2012-06-20 16:38:30 -07006488 pChannel = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
6489 }
6490 else
6491 {
6492 //get the valid channel list to scan all.
6493 len = sizeof(pMac->roam.validChannelList);
6494
6495 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
6496 {
6497 //allocate twice the channel
6498 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(len * 2);
6499 pChannel = pMac->roam.validChannelList;
6500 }
6501 }
6502 if(NULL == newChannelInfo.ChannelList)
6503 {
6504 newChannelInfo.numOfChannels = 0;
6505 }
6506 else
6507 {
6508 j = 0;
6509 for(i = 0; i < len; i++)
6510 {
6511 newChannelInfo.ChannelList[j++] = pChannel[i];
6512 if(CSR_MAX_24GHz_CHANNEL_NUMBER >= pChannel[i])
6513 {
6514 newChannelInfo.ChannelList[j++] = pChannel[i];
6515 }
6516 }
6517 if(NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
6518 {
6519 //pChannel points to the channellist from the command, free it.
6520 vos_mem_free(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -07006521 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07006522 }
6523 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = j;
6524 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = newChannelInfo.ChannelList;
6525 }
6526 } //if(pMac->roam.configParam.fScanTwice)
6527
6528 status = csrScanChannels(pMac, pCommand);
6529
6530 break;
6531 default:
6532 status = csrScanChannels(pMac, pCommand);
6533 break;
6534 }
6535
6536 if(!HAL_STATUS_SUCCESS(status))
6537 {
6538 csrReleaseScanCommand(pMac, pCommand, eCSR_SCAN_FAILURE);
6539 }
6540
6541 return (status);
6542}
6543
6544
6545eHalStatus csrScanSetBGScanparams(tpAniSirGlobal pMac, tCsrBGScanRequest *pScanReq)
6546{
6547 eHalStatus status = eHAL_STATUS_SUCCESS;
6548 tSmeCmd *pCommand = NULL;
6549
6550 if(pScanReq)
6551 {
6552 do
6553 {
6554 pCommand = csrGetCommandBuffer(pMac);
6555 if(!pCommand)
6556 {
6557 status = eHAL_STATUS_RESOURCES;
6558 break;
6559 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306560 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006561 pCommand->command = eSmeCommandScan;
6562 pCommand->u.scanCmd.reason = eCsrScanSetBGScanParam;
6563 pCommand->u.scanCmd.callback = NULL;
6564 pCommand->u.scanCmd.pContext = NULL;
Kiet Lam64c1b492013-07-12 13:56:44 +05306565 vos_mem_copy(&pCommand->u.scanCmd.u.bgScanRequest, pScanReq, sizeof(tCsrBGScanRequest));
Jeff Johnson295189b2012-06-20 16:38:30 -07006566 //we have to do the follow
6567 if(pScanReq->ChannelInfo.numOfChannels == 0)
6568 {
6569 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
6570 }
6571 else
6572 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306573 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList
6574 = vos_mem_malloc(pScanReq->ChannelInfo.numOfChannels);
6575 if ( NULL != pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07006576 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306577 vos_mem_copy(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList,
6578 pScanReq->ChannelInfo.ChannelList,
6579 pScanReq->ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07006580 }
6581 else
6582 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006583 smsLog(pMac, LOGE, FL("ran out of memory"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006584 csrReleaseCommandScan(pMac, pCommand);
Kiet Lam64c1b492013-07-12 13:56:44 +05306585 return eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006586 }
6587 }
6588
6589 //scan req for SSID
6590 if(pScanReq->SSID.length)
6591 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306592 vos_mem_copy(pCommand->u.scanCmd.u.bgScanRequest.SSID.ssId,
6593 pScanReq->SSID.ssId, pScanReq->SSID.length);
Jeff Johnson295189b2012-06-20 16:38:30 -07006594 pCommand->u.scanCmd.u.bgScanRequest.SSID.length = pScanReq->SSID.length;
6595
6596 }
6597 pCommand->u.scanCmd.u.bgScanRequest.maxChnTime= pScanReq->maxChnTime;
6598 pCommand->u.scanCmd.u.bgScanRequest.minChnTime = pScanReq->minChnTime;
6599 pCommand->u.scanCmd.u.bgScanRequest.scanInterval = pScanReq->scanInterval;
6600
6601
6602 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
6603 if( !HAL_STATUS_SUCCESS( status ) )
6604 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006605 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006606 csrReleaseCommandScan( pMac, pCommand );
6607 break;
6608 }
6609 }while(0);
6610 }
6611
6612 return (status);
6613}
6614
6615eHalStatus csrScanBGScanAbort( tpAniSirGlobal pMac )
6616{
6617 eHalStatus status = eHAL_STATUS_SUCCESS;
6618 tSmeCmd *pCommand = NULL;
6619
6620 do
6621 {
6622 pCommand = csrGetCommandBuffer(pMac);
6623 if(!pCommand)
6624 {
6625 status = eHAL_STATUS_RESOURCES;
6626 break;
6627 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306628 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006629 pCommand->command = eSmeCommandScan;
6630 pCommand->u.scanCmd.reason = eCsrScanBGScanAbort;
6631 pCommand->u.scanCmd.callback = NULL;
6632 pCommand->u.scanCmd.pContext = NULL;
6633 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
6634 if( !HAL_STATUS_SUCCESS( status ) )
6635 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006636 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006637 csrReleaseCommandScan( pMac, pCommand );
6638 break;
6639 }
6640 }while(0);
6641
6642 return (status);
6643}
6644
6645
6646//This will enable the background scan with the non-zero interval
6647eHalStatus csrScanBGScanEnable(tpAniSirGlobal pMac)
6648{
6649 eHalStatus status = eHAL_STATUS_SUCCESS;
6650 tSmeCmd *pCommand = NULL;
6651
6652 if(pMac->roam.configParam.bgScanInterval)
6653 {
6654 do
6655 {
6656 pCommand = csrGetCommandBuffer(pMac);
6657 if(!pCommand)
6658 {
6659 status = eHAL_STATUS_RESOURCES;
6660 break;
6661 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306662 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006663 pCommand->command = eSmeCommandScan;
6664 pCommand->u.scanCmd.reason = eCsrScanBGScanEnable;
6665 pCommand->u.scanCmd.callback = NULL;
6666 pCommand->u.scanCmd.pContext = NULL;
6667 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
6668 if( !HAL_STATUS_SUCCESS( status ) )
6669 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006670 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006671 csrReleaseCommandScan( pMac, pCommand );
6672 break;
6673 }
6674 }while(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006675 }
6676 else
6677 {
Sushant Kaushikb8dbb3f2015-04-29 17:03:37 +05306678 smsLog(pMac, LOGE, FL("cannot continue because the bgscan interval is 0"));
6679 status = eHAL_STATUS_INVALID_PARAMETER;
Jeff Johnson295189b2012-06-20 16:38:30 -07006680 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006681 return (status);
6682}
6683
6684
6685eHalStatus csrScanCopyRequest(tpAniSirGlobal pMac, tCsrScanRequest *pDstReq, tCsrScanRequest *pSrcReq)
6686{
6687 eHalStatus status = eHAL_STATUS_SUCCESS;
6688 tANI_U32 len = sizeof(pMac->roam.validChannelList);
6689 tANI_U32 index = 0;
6690 tANI_U32 new_index = 0;
Manjunathappa Prakashde7b2a52014-02-28 16:59:03 -08006691 eNVChannelEnabledType NVchannel_state;
Arif Hussain6af38622014-03-12 12:39:57 -07006692 tANI_U8 ch144_support = 0;
6693
6694 ch144_support = WDA_getFwWlanFeatCaps(WLAN_CH144);
Jeff Johnson295189b2012-06-20 16:38:30 -07006695
6696 do
6697 {
6698 status = csrScanFreeRequest(pMac, pDstReq);
6699 if(HAL_STATUS_SUCCESS(status))
6700 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306701 vos_mem_copy(pDstReq, pSrcReq, sizeof(tCsrScanRequest));
Gopichand Nakkalac7b1d3e2012-12-31 14:07:19 -08006702 /* Re-initialize the pointers to NULL since we did a copy */
6703 pDstReq->pIEField = NULL;
6704 pDstReq->ChannelInfo.ChannelList = NULL;
6705 pDstReq->SSIDs.SSIDList = NULL;
6706
Jeff Johnson295189b2012-06-20 16:38:30 -07006707 if(pSrcReq->uIEFieldLen == 0)
6708 {
6709 pDstReq->pIEField = NULL;
6710 }
6711 else
6712 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306713 pDstReq->pIEField = vos_mem_malloc(pSrcReq->uIEFieldLen);
6714 if ( NULL == pDstReq->pIEField )
Jeff Johnson295189b2012-06-20 16:38:30 -07006715 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306716 status = eHAL_STATUS_FAILURE;
6717 smsLog(pMac, LOGE, FL("No memory for scanning IE fields"));
6718 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07006719 }
6720 else
6721 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306722 status = eHAL_STATUS_SUCCESS;
6723 vos_mem_copy(pDstReq->pIEField, pSrcReq->pIEField,
6724 pSrcReq->uIEFieldLen);
6725 pDstReq->uIEFieldLen = pSrcReq->uIEFieldLen;
Jeff Johnson295189b2012-06-20 16:38:30 -07006726 }
6727 }//Allocate memory for IE field
6728 {
6729 if(pSrcReq->ChannelInfo.numOfChannels == 0)
6730 {
6731 pDstReq->ChannelInfo.ChannelList = NULL;
6732 pDstReq->ChannelInfo.numOfChannels = 0;
6733 }
6734 else
6735 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306736 pDstReq->ChannelInfo.ChannelList = vos_mem_malloc(
6737 pSrcReq->ChannelInfo.numOfChannels
6738 * sizeof(*pDstReq->ChannelInfo.ChannelList));
6739 if ( NULL == pDstReq->ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07006740 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306741 status = eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006742 pDstReq->ChannelInfo.numOfChannels = 0;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306743 smsLog(pMac, LOGE, FL("No memory for scanning Channel"
6744 " List"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006745 break;
6746 }
6747
6748 if((pSrcReq->scanType == eSIR_PASSIVE_SCAN) && (pSrcReq->requestType == eCSR_SCAN_REQUEST_11D_SCAN))
6749 {
6750 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
6751 {
Arif Hussain6af38622014-03-12 12:39:57 -07006752 /* Skip CH 144 if firmware support not present */
6753 if (pSrcReq->ChannelInfo.ChannelList[index] == 144 && !ch144_support)
6754 continue;
Agarwal Ashish8bd53ae2015-06-12 18:03:45 +05306755 /* Skip channel 12 and 13 when FCC constraint is true */
6756 if ((pMac->scan.fcc_constraint) &&
6757 ((pSrcReq->ChannelInfo.ChannelList[index] ==12) ||
6758 (pSrcReq->ChannelInfo.ChannelList[index] ==13)))
6759 {
6760 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
6761 FL("Ignoring channel : %d "),
6762 pSrcReq->ChannelInfo.ChannelList[index]);
6763 continue;
6764 }
Arif Hussain6af38622014-03-12 12:39:57 -07006765
Manjunathappa Prakashde7b2a52014-02-28 16:59:03 -08006766 NVchannel_state = vos_nv_getChannelEnabledState(
6767 pSrcReq->ChannelInfo.ChannelList[index]);
6768 if ((NV_CHANNEL_ENABLE == NVchannel_state) ||
6769 (NV_CHANNEL_DFS == NVchannel_state))
6770 {
6771 pDstReq->ChannelInfo.ChannelList[new_index] =
6772 pSrcReq->ChannelInfo.ChannelList[index];
6773 new_index++;
6774 }
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306775 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006776 pDstReq->ChannelInfo.numOfChannels = new_index;
6777 }
6778 else if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
6779 {
6780 new_index = 0;
6781 pMac->roam.numValidChannels = len;
c_hpothu0d5a7352014-03-22 12:30:25 +05306782
6783 /* Since in CsrScanRequest,value of pMac->scan.nextScanID
6784 * is incremented before calling CsrScanCopyRequest, as a
6785 * result pMac->scan.nextScanID is equal to ONE for the
Abhishek Singha2649232016-01-20 15:52:05 +05306786 * first scan. If number of channels is less than
6787 * max chan for dwell time no need to skip dfs
6788 * in first scan as anyway few channels will be scanned and
6789 * it will not take much time to display results on GUI.
c_hpothu0d5a7352014-03-22 12:30:25 +05306790 */
Abhishek Singha2649232016-01-20 15:52:05 +05306791 if (((pSrcReq->ChannelInfo.numOfChannels >=
6792 pMac->roam.configParam.max_chan_for_dwell_time_cfg) &&
6793 (pMac->roam.configParam.initialScanSkipDFSCh &&
6794 1 == pMac->scan.nextScanID)) ||(pMac->miracast_mode))
c_hpothu0d5a7352014-03-22 12:30:25 +05306795 {
6796 smsLog(pMac, LOG1,
6797 FL("Initial scan, scan only non-DFS channels"));
6798
6799 for (index = 0; index < pSrcReq->ChannelInfo.
6800 numOfChannels ; index++ )
6801 {
6802 if((csrRoamIsValidChannel(pMac, pSrcReq->ChannelInfo.
6803 ChannelList[index])))
6804 {
6805 /*Skiipping DFS Channels for 1st scan */
6806 if(NV_CHANNEL_DFS ==
6807 vos_nv_getChannelEnabledState(pSrcReq->ChannelInfo.
6808 ChannelList[index]))
6809 continue ;
6810
6811 pDstReq->ChannelInfo.ChannelList[new_index] =
6812 pSrcReq->ChannelInfo.ChannelList[index];
6813 new_index++;
6814
6815 }
6816 }
6817 pMac->roam.configParam.initialScanSkipDFSCh = 0;
6818 }
6819 else
6820 {
6821 for ( index = 0; index < pSrcReq->ChannelInfo.
6822 numOfChannels ; index++ )
Jeff Johnson295189b2012-06-20 16:38:30 -07006823 {
Arif Hussain6af38622014-03-12 12:39:57 -07006824 /* Skip CH 144 if firmware support not present */
6825 if (pSrcReq->ChannelInfo.ChannelList[index] == 144 && !ch144_support)
6826 continue;
6827
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -07006828 /* Allow scan on valid channels only.
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -07006829 */
Abhishek Singh2ec36ab2014-08-07 16:14:25 +05306830 if ( ( csrRoamIsValidChannel(pMac, pSrcReq->ChannelInfo.ChannelList[index]) ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07006831 {
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05306832 if( ((pSrcReq->skipDfsChnlInP2pSearch ||
6833 (pMac->scan.fEnableDFSChnlScan ==
6834 DFS_CHNL_SCAN_DISABLED)) &&
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08006835 (NV_CHANNEL_DFS == vos_nv_getChannelEnabledState(pSrcReq->ChannelInfo.ChannelList[index])) )
Srikant Kuppa866893f2012-12-27 17:28:14 -08006836#ifdef FEATURE_WLAN_LFR
6837 /*
6838 * If LFR is requesting a contiguous scan
6839 * (i.e. numOfChannels > 1), then ignore
6840 * DFS channels.
6841 * TODO: vos_nv_getChannelEnabledState is returning
6842 * 120, 124 and 128 as non-DFS channels. Hence, the
6843 * use of direct check for channels below.
6844 */
6845 || ((eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType) &&
6846 (pSrcReq->ChannelInfo.numOfChannels > 1) &&
Santhosh Kumar Padma9ccaaff2014-07-09 19:58:12 +05306847 (CSR_IS_CHANNEL_DFS(pSrcReq->ChannelInfo.ChannelList[index])) &&
6848 !pMac->roam.configParam.allowDFSChannelRoam)
Srikant Kuppa866893f2012-12-27 17:28:14 -08006849#endif
6850 )
6851 {
6852#ifdef FEATURE_WLAN_LFR
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05306853 smsLog(pMac, LOG2,
6854 FL(" reqType=%s (%d), numOfChannels=%d,"
6855 " ignoring DFS channel %d"),
6856 sme_requestTypetoString(pSrcReq->requestType),
6857 pSrcReq->requestType,
6858 pSrcReq->ChannelInfo.numOfChannels,
6859 pSrcReq->ChannelInfo.ChannelList[index]);
Srikant Kuppa866893f2012-12-27 17:28:14 -08006860#endif
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05306861 continue;
Srikant Kuppa866893f2012-12-27 17:28:14 -08006862 }
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08006863
Jeff Johnson295189b2012-06-20 16:38:30 -07006864 pDstReq->ChannelInfo.ChannelList[new_index] =
6865 pSrcReq->ChannelInfo.ChannelList[index];
6866 new_index++;
6867 }
6868 }
c_hpothu0d5a7352014-03-22 12:30:25 +05306869 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006870 pDstReq->ChannelInfo.numOfChannels = new_index;
Srikant Kuppa866893f2012-12-27 17:28:14 -08006871#ifdef FEATURE_WLAN_LFR
Abhishek Singh2ec36ab2014-08-07 16:14:25 +05306872 if ( ( ( eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType ) ||
6873 ( eCSR_SCAN_P2P_DISCOVERY == pSrcReq->requestType ) ) &&
6874 ( 0 == pDstReq->ChannelInfo.numOfChannels ) )
Srikant Kuppa866893f2012-12-27 17:28:14 -08006875 {
6876 /*
6877 * No valid channels found in the request.
6878 * Only perform scan on the channels passed
Abhishek Singh2ec36ab2014-08-07 16:14:25 +05306879 * pSrcReq if it is a eCSR_SCAN_HO_BG_SCAN or
6880 * eCSR_SCAN_P2P_DISCOVERY.
Srikant Kuppa866893f2012-12-27 17:28:14 -08006881 * Passing 0 to LIM will trigger a scan on
6882 * all valid channels which is not desirable.
6883 */
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306884 smsLog(pMac, LOGE, FL(" no valid channels found"
6885 " (request=%d)"), pSrcReq->requestType);
Srikant Kuppa866893f2012-12-27 17:28:14 -08006886 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
6887 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306888 smsLog(pMac, LOGE, FL("pSrcReq index=%d"
6889 " channel=%d"), index,
6890 pSrcReq->ChannelInfo.ChannelList[index]);
Srikant Kuppa866893f2012-12-27 17:28:14 -08006891 }
6892 status = eHAL_STATUS_FAILURE;
6893 break;
6894 }
6895#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006896 }
6897 else
6898 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306899 smsLog(pMac, LOGE, FL("Couldn't get the valid Channel"
6900 " List, keeping requester's list"));
Kiet Lam64c1b492013-07-12 13:56:44 +05306901 vos_mem_copy(pDstReq->ChannelInfo.ChannelList,
6902 pSrcReq->ChannelInfo.ChannelList,
6903 pSrcReq->ChannelInfo.numOfChannels
6904 * sizeof(*pDstReq->ChannelInfo.ChannelList));
Jeff Johnson295189b2012-06-20 16:38:30 -07006905 pDstReq->ChannelInfo.numOfChannels = pSrcReq->ChannelInfo.numOfChannels;
6906 }
6907 }//Allocate memory for Channel List
6908 }
6909 if(pSrcReq->SSIDs.numOfSSIDs == 0)
6910 {
6911 pDstReq->SSIDs.numOfSSIDs = 0;
6912 pDstReq->SSIDs.SSIDList = NULL;
6913 }
6914 else
6915 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306916 pDstReq->SSIDs.SSIDList = vos_mem_malloc(
6917 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
6918 if ( NULL == pDstReq->SSIDs.SSIDList )
6919 status = eHAL_STATUS_FAILURE;
6920 else
6921 status = eHAL_STATUS_SUCCESS;
6922 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07006923 {
6924 pDstReq->SSIDs.numOfSSIDs = pSrcReq->SSIDs.numOfSSIDs;
Kiet Lam64c1b492013-07-12 13:56:44 +05306925 vos_mem_copy(pDstReq->SSIDs.SSIDList,
6926 pSrcReq->SSIDs.SSIDList,
6927 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
Jeff Johnson295189b2012-06-20 16:38:30 -07006928 }
6929 else
6930 {
6931 pDstReq->SSIDs.numOfSSIDs = 0;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306932 smsLog(pMac, LOGE, FL("No memory for scanning SSID List"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006933 break;
6934 }
6935 }//Allocate memory for SSID List
Jeff Johnson295189b2012-06-20 16:38:30 -07006936 pDstReq->p2pSearch = pSrcReq->p2pSearch;
Jeff Johnsone7245742012-09-05 17:12:55 -07006937 pDstReq->skipDfsChnlInP2pSearch = pSrcReq->skipDfsChnlInP2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07006938
6939 }
6940 }while(0);
6941
6942 if(!HAL_STATUS_SUCCESS(status))
6943 {
6944 csrScanFreeRequest(pMac, pDstReq);
6945 }
6946
6947 return (status);
6948}
6949
6950
6951eHalStatus csrScanFreeRequest(tpAniSirGlobal pMac, tCsrScanRequest *pReq)
6952{
Jeff Johnson295189b2012-06-20 16:38:30 -07006953
6954 if(pReq->ChannelInfo.ChannelList)
6955 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306956 vos_mem_free(pReq->ChannelInfo.ChannelList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006957 pReq->ChannelInfo.ChannelList = NULL;
6958 }
6959 pReq->ChannelInfo.numOfChannels = 0;
6960 if(pReq->pIEField)
6961 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306962 vos_mem_free(pReq->pIEField);
Jeff Johnson295189b2012-06-20 16:38:30 -07006963 pReq->pIEField = NULL;
6964 }
6965 pReq->uIEFieldLen = 0;
6966 if(pReq->SSIDs.SSIDList)
6967 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306968 vos_mem_free(pReq->SSIDs.SSIDList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006969 pReq->SSIDs.SSIDList = NULL;
6970 }
6971 pReq->SSIDs.numOfSSIDs = 0;
6972
Kiet Lam64c1b492013-07-12 13:56:44 +05306973 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07006974}
6975
6976
6977void csrScanCallCallback(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
6978{
6979 if(pCommand->u.scanCmd.callback)
6980 {
Ratheesh S Pece1f832015-07-25 15:50:25 +05306981 if (pCommand->u.scanCmd.abortScanIndication){
6982 smsLog( pMac, LOG1, FL("scanDone due to abort"));
6983 scanStatus = eCSR_SCAN_ABORT;
6984 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006985// sme_ReleaseGlobalLock( &pMac->sme );
6986 pCommand->u.scanCmd.callback(pMac, pCommand->u.scanCmd.pContext, pCommand->u.scanCmd.scanID, scanStatus);
6987// sme_AcquireGlobalLock( &pMac->sme );
6988 } else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006989 smsLog( pMac, LOG2, "%s:%d - Callback NULL!!!", __func__, __LINE__);
Jeff Johnson295189b2012-06-20 16:38:30 -07006990 }
6991}
6992
6993
6994void csrScanStopTimers(tpAniSirGlobal pMac)
6995{
Jeff Johnson295189b2012-06-20 16:38:30 -07006996 csrScanStopIdleScanTimer(pMac);
6997 csrScanStopGetResultTimer(pMac);
6998}
6999
7000
7001eHalStatus csrScanStartGetResultTimer(tpAniSirGlobal pMac)
7002{
7003 eHalStatus status;
7004
7005 if(pMac->scan.fScanEnable)
7006 {
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05307007 status = vos_timer_start(&pMac->scan.hTimerGetResult, CSR_SCAN_GET_RESULT_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07007008 }
7009 else
7010 {
7011 status = eHAL_STATUS_FAILURE;
7012 }
7013
7014 return (status);
7015}
7016
7017
7018eHalStatus csrScanStopGetResultTimer(tpAniSirGlobal pMac)
7019{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05307020 return (vos_timer_stop(&pMac->scan.hTimerGetResult));
Jeff Johnson295189b2012-06-20 16:38:30 -07007021}
7022
7023
7024void csrScanGetResultTimerHandler(void *pv)
7025{
7026 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
7027
7028 csrScanRequestResult(pMac);
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05307029
7030 vos_timer_start(&pMac->scan.hTimerGetResult, CSR_SCAN_GET_RESULT_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07007031}
7032
7033#ifdef WLAN_AP_STA_CONCURRENCY
7034static void csrStaApConcTimerHandler(void *pv)
7035{
7036 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
7037 tListElem *pEntry;
7038 tSmeCmd *pScanCmd;
7039
7040 csrLLLock(&pMac->scan.scanCmdPendingList);
7041
7042 if ( NULL != ( pEntry = csrLLPeekHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) ) )
7043 {
7044 tCsrScanRequest scanReq;
7045 tSmeCmd *pSendScanCmd = NULL;
7046 tANI_U8 numChn = 0;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07007047 tANI_U8 nNumChanCombinedConc = 0;
Vinay Malekal05fdc812012-12-17 13:04:30 -08007048 tANI_U8 i, j;
Jeff Johnson295189b2012-06-20 16:38:30 -07007049 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
7050 tANI_U8 channelToScan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
7051 eHalStatus status;
7052
Jeff Johnson295189b2012-06-20 16:38:30 -07007053 pScanCmd = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7054 numChn = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08007055
7056 /* if any session is connected and the number of channels to scan is
7057 * greater than 1 then split the scan into multiple scan operations
7058 * on each individual channel else continue to perform scan on all
7059 * specified channels */
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08007060
7061 /* split scan if number of channels to scan is greater than 1 and
7062 * any one of the following:
7063 * - STA session is connected and the scan is not a P2P search
7064 * - any P2P session is connected
Srikant Kuppa866893f2012-12-27 17:28:14 -08007065 * Do not split scans if no concurrent infra connections are
7066 * active and if the scan is a BG scan triggered by LFR (OR)
7067 * any scan if LFR is in the middle of a BG scan. Splitting
7068 * the scan is delaying the time it takes for LFR to find
7069 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08007070 */
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07007071
7072 if((csrIsStaSessionConnected(pMac) &&
7073 !csrIsP2pSessionConnected(pMac)))
7074 {
7075 nNumChanCombinedConc = pMac->roam.configParam.nNumStaChanCombinedConc;
7076 }
7077 else if(csrIsP2pSessionConnected(pMac))
7078 {
7079 nNumChanCombinedConc = pMac->roam.configParam.nNumP2PChanCombinedConc;
7080 }
7081
7082 if ( (numChn > nNumChanCombinedConc) &&
Srikant Kuppa866893f2012-12-27 17:28:14 -08007083 ((csrIsStaSessionConnected(pMac) &&
7084#ifdef FEATURE_WLAN_LFR
7085 (csrIsConcurrentInfraConnected(pMac) ||
7086 ((pScanCmd->u.scanCmd.reason != eCsrScanBgScan) &&
7087 (pMac->roam.neighborRoamInfo.neighborRoamState !=
7088 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
7089#endif
7090 (pScanCmd->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08007091 (csrIsP2pSessionConnected(pMac))))
Jeff Johnson295189b2012-06-20 16:38:30 -07007092 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307093 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007094
7095 pSendScanCmd = csrGetCommandBuffer(pMac); //optimize this to use 2 command buffer only
7096 if (!pSendScanCmd)
7097 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007098 smsLog( pMac, LOGE, FL(" Failed to get Queue command buffer") );
Jeff Johnson295189b2012-06-20 16:38:30 -07007099 csrLLUnlock(&pMac->scan.scanCmdPendingList);
7100 return;
7101 }
7102 pSendScanCmd->command = pScanCmd->command;
7103 pSendScanCmd->sessionId = pScanCmd->sessionId;
7104 pSendScanCmd->u.scanCmd.callback = NULL;
7105 pSendScanCmd->u.scanCmd.pContext = pScanCmd->u.scanCmd.pContext;
7106 pSendScanCmd->u.scanCmd.reason = pScanCmd->u.scanCmd.reason;
7107 pSendScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
7108
Madan Mohan Koyyalamudiaf2a8b92012-10-09 14:58:07 -07007109 /* First copy all the parameters to local variable of scan request */
7110 csrScanCopyRequest(pMac, &scanReq, &pScanCmd->u.scanCmd.u.scanRequest);
7111
7112 /* Now modify the elements of local var scan request required to be modified for split scan */
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08007113 if(scanReq.ChannelInfo.ChannelList != NULL)
7114 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307115 vos_mem_free(scanReq.ChannelInfo.ChannelList);
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08007116 scanReq.ChannelInfo.ChannelList = NULL;
7117 }
7118
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07007119 pChnInfo->numOfChannels = nNumChanCombinedConc;
Kiet Lam64c1b492013-07-12 13:56:44 +05307120 vos_mem_copy(&channelToScan[0],
7121 &pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[0],
7122 pChnInfo->numOfChannels * sizeof(tANI_U8));//just send one channel
Jeff Johnson295189b2012-06-20 16:38:30 -07007123 pChnInfo->ChannelList = &channelToScan[0];
7124
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07007125 for (i = 0, j = nNumChanCombinedConc; i < (numChn-nNumChanCombinedConc); i++, j++)
Jeff Johnson295189b2012-06-20 16:38:30 -07007126 {
7127 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] =
Vinay Malekal05fdc812012-12-17 13:04:30 -08007128 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[j]; //Move all the channels one step
Jeff Johnson295189b2012-06-20 16:38:30 -07007129 }
7130
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07007131 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = numChn - nNumChanCombinedConc; //reduce outstanding # of channels to be scanned
Jeff Johnson295189b2012-06-20 16:38:30 -07007132
7133 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
c_hpothudbefd3e2014-04-28 15:59:47 +05307134
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -07007135 //Use concurrency values for min/maxChnTime.
7136 //We know csrIsAnySessionConnected(pMac) returns TRUE here
7137 csrSetDefaultScanTiming(pMac, scanReq.scanType, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07007138
7139 status = csrScanCopyRequest(pMac, &pSendScanCmd->u.scanCmd.u.scanRequest, &scanReq);
7140 if(!HAL_STATUS_SUCCESS(status))
7141 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007142 smsLog( pMac, LOGE, FL(" Failed to get copy csrScanRequest = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07007143 csrLLUnlock(&pMac->scan.scanCmdPendingList);
7144 return;
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08007145 }
7146 /* Clean the local scan variable */
7147 scanReq.ChannelInfo.ChannelList = NULL;
7148 scanReq.ChannelInfo.numOfChannels = 0;
7149 csrScanFreeRequest(pMac, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07007150 }
7151 else
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08007152 {
7153 /* no active connected session present or numChn == 1
7154 * scan all remaining channels */
Jeff Johnson295189b2012-06-20 16:38:30 -07007155 pSendScanCmd = pScanCmd;
7156 //remove this command from pending list
7157 if (csrLLRemoveHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) == NULL)
7158 { //In case between PeekHead and here, the entry got removed by another thread.
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007159 smsLog( pMac, LOGE, FL(" Failed to remove entry from scanCmdPendingList"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007160 }
7161
7162 }
7163 csrQueueSmeCommand(pMac, pSendScanCmd, eANI_BOOLEAN_FALSE);
7164
7165 }
7166
Jeff Johnson295189b2012-06-20 16:38:30 -07007167 csrLLUnlock(&pMac->scan.scanCmdPendingList);
7168
7169}
7170#endif
7171
Jeff Johnson295189b2012-06-20 16:38:30 -07007172//This function returns the maximum time a BSS is allowed in the scan result.
7173//The time varies base on connection and power saving factors.
7174//Not connected, No PS
7175//Not connected, with PS
7176//Connected w/o traffic, No PS
7177//Connected w/o traffic, with PS
7178//Connected w/ traffic, no PS -- Not supported
7179//Connected w/ traffic, with PS -- Not supported
7180//the return unit is in seconds.
7181tANI_U32 csrScanGetAgeOutTime(tpAniSirGlobal pMac)
7182{
7183 tANI_U32 nRet;
7184
7185 if(pMac->scan.nAgingCountDown)
7186 {
7187 //Calculate what should be the timeout value for this
7188 nRet = pMac->scan.nLastAgeTimeOut * pMac->scan.nAgingCountDown;
7189 pMac->scan.nAgingCountDown--;
7190 }
7191 else
7192 {
7193 if( csrIsAllSessionDisconnected( pMac ) )
7194 {
7195 if(pmcIsPowerSaveEnabled(pMac, ePMC_IDLE_MODE_POWER_SAVE))
7196 {
7197 nRet = pMac->roam.configParam.scanAgeTimeNCPS;
7198 }
7199 else
7200 {
7201 nRet = pMac->roam.configParam.scanAgeTimeNCNPS;
7202 }
7203 }
7204 else
7205 {
7206 if(pmcIsPowerSaveEnabled(pMac, ePMC_BEACON_MODE_POWER_SAVE))
7207 {
7208 nRet = pMac->roam.configParam.scanAgeTimeCPS;
7209 }
7210 else
7211 {
7212 nRet = pMac->roam.configParam.scanAgeTimeCNPS;
7213 }
7214 }
7215 //If state-change causing aging time out change, we want to delay it somewhat to avoid
7216 //unnecessary removal of BSS. This is mostly due to transition from connect to disconnect.
7217 if(pMac->scan.nLastAgeTimeOut > nRet)
7218 {
7219 if(nRet)
7220 {
7221 pMac->scan.nAgingCountDown = (pMac->scan.nLastAgeTimeOut / nRet);
7222 }
7223 pMac->scan.nLastAgeTimeOut = nRet;
7224 nRet *= pMac->scan.nAgingCountDown;
7225 }
7226 else
7227 {
7228 pMac->scan.nLastAgeTimeOut = nRet;
7229 }
7230 }
7231
7232 return (nRet);
7233}
7234
Deepthi Gowri6a08e312016-03-31 19:10:14 +05307235static void csrPurgeScanResultByAge(void *pv)
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08007236{
7237 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
7238 tListElem *pEntry, *tmpEntry;
7239 tCsrScanResult *pResult;
Deepthi Gowri4480a3f2016-05-18 19:30:17 +05307240 v_TIME_t ageOutTime =
7241 (v_TIME_t)(pMac->scan.scanResultCfgAgingTime * SYSTEM_TIME_SEC_TO_MSEC);
7242 v_TIME_t curTime = vos_timer_get_system_time();
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08007243
7244 csrLLLock(&pMac->scan.scanResultList);
7245 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
Deepthi Gowri6a08e312016-03-31 19:10:14 +05307246 smsLog(pMac, LOG1, FL("Ageout time=%lu"),ageOutTime);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08007247 while( pEntry )
7248 {
7249 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
7250 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
7251 if((curTime - pResult->Result.BssDescriptor.nReceivedTime) > ageOutTime)
7252 {
Deepthi Gowri50e2fa52016-03-17 15:30:53 +05307253 smsLog(pMac, LOG1, FL("age out due to time out for BSSID" MAC_ADDRESS_STR),
7254 MAC_ADDR_ARRAY(pResult->Result.BssDescriptor.bssId));
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08007255 csrScanAgeOutBss(pMac, pResult);
7256 }
7257 pEntry = tmpEntry;
7258 }
7259 csrLLUnlock(&pMac->scan.scanResultList);
7260}
Jeff Johnson295189b2012-06-20 16:38:30 -07007261
7262eHalStatus csrScanStartIdleScanTimer(tpAniSirGlobal pMac, tANI_U32 interval)
7263{
7264 eHalStatus status;
7265
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007266 smsLog(pMac, LOG1, " csrScanStartIdleScanTimer");
Jeff Johnson295189b2012-06-20 16:38:30 -07007267 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) && interval)
7268 {
7269 pMac->scan.nIdleScanTimeGap += interval;
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05307270 vos_timer_stop(&pMac->scan.hTimerIdleScan);
7271 status = vos_timer_start(&pMac->scan.hTimerIdleScan, interval/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07007272 if( !HAL_STATUS_SUCCESS(status) )
7273 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007274 smsLog(pMac, LOGE, " Fail to start Idle scan timer. status = %d interval = %d", status, interval);
Jeff Johnson295189b2012-06-20 16:38:30 -07007275 //This should not happen but set the flag to restart when ready
7276 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7277 }
7278 }
7279 else
7280 {
7281 if( pMac->scan.fScanEnable && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) )
7282 {
7283 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7284 }
7285 status = eHAL_STATUS_FAILURE;
7286 }
7287
7288 return (status);
7289}
7290
7291
7292eHalStatus csrScanStopIdleScanTimer(tpAniSirGlobal pMac)
7293{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05307294 return (vos_timer_stop(&pMac->scan.hTimerIdleScan));
Jeff Johnson295189b2012-06-20 16:38:30 -07007295}
7296
7297
7298//Stop CSR from asking for IMPS, This function doesn't disable IMPS from CSR
7299void csrScanSuspendIMPS( tpAniSirGlobal pMac )
7300{
7301 csrScanCancelIdleScan(pMac);
7302}
7303
7304
7305//Start CSR from asking for IMPS. This function doesn't trigger CSR to request entering IMPS
7306//because IMPS maybe disabled.
7307void csrScanResumeIMPS( tpAniSirGlobal pMac )
7308{
7309 csrScanStartIdleScan( pMac );
7310}
7311
7312
7313void csrScanIMPSCallback(void *callbackContext, eHalStatus status)
7314{
7315 tpAniSirGlobal pMac = PMAC_STRUCT( callbackContext );
7316
7317 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
7318 {
7319 if(pMac->roam.configParam.IsIdleScanEnabled)
7320 {
7321 if(HAL_STATUS_SUCCESS(status))
7322 {
7323 if(csrIsAllSessionDisconnected(pMac) && !csrIsRoamCommandWaiting(pMac))
7324 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007325 smsLog(pMac, LOGW, FL("starts idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007326 csrScanAllChannels(pMac, eCSR_SCAN_IDLE_MODE_SCAN);
7327 }
7328 else
7329 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007330 smsLog(pMac, LOGW, FL("cannot start idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007331 //even though we are in timer handle, calling stop timer will make sure the timer
7332 //doesn't get to restart.
7333 csrScanStopIdleScanTimer(pMac);
7334 }
7335 }
7336 else
7337 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007338 smsLog(pMac, LOGE, FL("sees not success status (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07007339 }
7340 }
7341 else
7342 {//we might need another flag to check if CSR needs to request imps at all
7343
7344 tANI_U32 nTime = 0;
7345
7346 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_FALSE;
7347 if(!HAL_STATUS_SUCCESS(csrScanTriggerIdleScan(pMac, &nTime)))
7348 {
7349 csrScanStartIdleScanTimer(pMac, nTime);
7350 }
7351 }
7352 }
7353}
7354
7355
Rashmi Ramanna68b309c2014-05-20 11:52:22 +05307356//Param: pTimeInterval -- Caller allocated memory in return, if failed, to specify the nxt time interval for
Jeff Johnson295189b2012-06-20 16:38:30 -07007357//idle scan timer interval
7358//Return: Not success -- meaning it cannot start IMPS, caller needs to start a timer for idle scan
7359eHalStatus csrScanTriggerIdleScan(tpAniSirGlobal pMac, tANI_U32 *pTimeInterval)
7360{
7361 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
7362
7363 //Do not trigger IMPS in case of concurrency
Agarwal Ashish5974ed32014-06-16 16:59:54 +05307364 if (vos_concurrent_open_sessions_running() &&
7365 csrIsAnySessionInConnectState(pMac))
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007366 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007367 smsLog( pMac, LOG1, FL("Cannot request IMPS because Concurrent Sessions Running") );
Jeff Johnson295189b2012-06-20 16:38:30 -07007368 return (status);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07007369 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007370
7371 if(pTimeInterval)
7372 {
7373 *pTimeInterval = 0;
7374 }
7375
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007376 smsLog(pMac, LOG3, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007377 if( smeCommandPending( pMac ) )
7378 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007379 smsLog( pMac, LOG1, FL(" Cannot request IMPS because command pending") );
Jeff Johnson295189b2012-06-20 16:38:30 -07007380 //Not to enter IMPS because more work to do
7381 if(pTimeInterval)
7382 {
7383 *pTimeInterval = 0;
7384 }
7385 //restart when ready
7386 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7387
7388 return (status);
7389 }
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07007390 if (IsPmcImpsReqFailed (pMac))
7391 {
7392 if(pTimeInterval)
7393 {
7394 *pTimeInterval = 1000000; //usec
7395 }
7396 //restart when ready
7397 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07007398
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07007399 return status;
7400 }
Rashmi Ramanna68b309c2014-05-20 11:52:22 +05307401
7402 if ( !pMac->deferImps && pMac->fDeferIMPSTime )
7403 {
7404 smsLog( pMac, LOG1, FL("Defer IMPS for %dms as command processed"),
7405 pMac->fDeferIMPSTime);
Girish Gowli4f3775a2014-05-30 17:17:08 +05307406 if(pTimeInterval)
7407 {
7408 *pTimeInterval = pMac->fDeferIMPSTime * 1000; //usec
7409 }
Rashmi Ramanna68b309c2014-05-20 11:52:22 +05307410 pMac->deferImps = eANI_BOOLEAN_TRUE;
7411 return status;
7412 }
7413
Jeff Johnson295189b2012-06-20 16:38:30 -07007414 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
7415 /*&& pMac->roam.configParam.impsSleepTime*/)
7416 {
7417 //Stop get result timer because idle scan gets scan result out of PE
7418 csrScanStopGetResultTimer(pMac);
7419 if(pTimeInterval)
7420 {
7421 *pTimeInterval = pMac->roam.configParam.impsSleepTime;
7422 }
7423 //pmcRequestImps take a period in millisecond unit.
7424 status = pmcRequestImps(pMac, pMac->roam.configParam.impsSleepTime / PAL_TIMER_TO_MS_UNIT, csrScanIMPSCallback, pMac);
7425 if(!HAL_STATUS_SUCCESS(status))
7426 {
7427 if(eHAL_STATUS_PMC_ALREADY_IN_IMPS != status)
7428 {
7429 //Do restart the timer if CSR thinks it cannot do IMPS
7430 if( !csrCheckPSReady( pMac ) )
7431 {
7432 if(pTimeInterval)
7433 {
7434 *pTimeInterval = 0;
7435 }
7436 //Set the restart flag to true because that idle scan
7437 //can be restarted even though the timer will not be running
7438 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7439 }
7440 else
7441 {
7442 //For not now, we do a quicker retry
7443 if(pTimeInterval)
7444 {
7445 *pTimeInterval = CSR_IDLE_SCAN_WAIT_TIME;
7446 }
7447 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007448 smsLog(pMac, LOGW, FL("call pmcRequestImps and it returns status code (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07007449 }
7450 else
7451 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007452 smsLog(pMac, LOGW, FL("already in IMPS"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007453 //Since CSR is the only module to request for IMPS. If it is already in IMPS, CSR assumes
7454 //the callback will be called in the future. Should not happen though.
7455 status = eHAL_STATUS_SUCCESS;
7456 pMac->scan.nIdleScanTimeGap = 0;
7457 }
7458 }
7459 else
7460 {
7461 //requested so let's reset the value
7462 pMac->scan.nIdleScanTimeGap = 0;
7463 }
7464 }
7465
7466 return (status);
7467}
7468
7469
7470eHalStatus csrScanStartIdleScan(tpAniSirGlobal pMac)
7471{
7472 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
7473 tANI_U32 nTime = 0;
7474
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007475 smsLog(pMac, LOGW, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007476 if(pMac->roam.configParam.IsIdleScanEnabled)
7477 {
7478 //stop bg scan first
7479 csrScanBGScanAbort(pMac);
7480 //Stop get result timer because idle scan gets scan result out of PE
7481 csrScanStopGetResultTimer(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07007482 }
7483 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_FALSE;
7484 status = csrScanTriggerIdleScan(pMac, &nTime);
7485 if(!HAL_STATUS_SUCCESS(status))
7486 {
7487 csrScanStartIdleScanTimer(pMac, nTime);
7488 }
7489
7490 return (status);
7491}
7492
7493
7494void csrScanCancelIdleScan(tpAniSirGlobal pMac)
7495{
7496 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
7497 {
Agarwal Ashish5974ed32014-06-16 16:59:54 +05307498 if (vos_concurrent_open_sessions_running()) {
Jeff Johnson295189b2012-06-20 16:38:30 -07007499 return;
7500 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007501 smsLog(pMac, LOG1, " csrScanCancelIdleScan");
Jeff Johnson295189b2012-06-20 16:38:30 -07007502 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_TRUE;
7503 //Set the restart flag in case later on it is uncancelled
7504 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7505 csrScanStopIdleScanTimer(pMac);
7506 csrScanRemoveNotRoamingScanCommand(pMac);
7507 }
7508}
7509
7510
7511void csrScanIdleScanTimerHandler(void *pv)
7512{
7513 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
7514 eHalStatus status;
7515 tANI_U32 nTime = 0;
7516
7517 smsLog(pMac, LOGW, " csrScanIdleScanTimerHandler called ");
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07007518 pmcResetImpsFailStatus (pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07007519 status = csrScanTriggerIdleScan(pMac, &nTime);
7520 if(!HAL_STATUS_SUCCESS(status) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan))
7521 {
7522 //Check whether it is time to actually do an idle scan
7523 if(pMac->scan.nIdleScanTimeGap >= pMac->roam.configParam.impsSleepTime)
7524 {
7525 pMac->scan.nIdleScanTimeGap = 0;
7526 csrScanIMPSCallback(pMac, eHAL_STATUS_SUCCESS);
7527 }
7528 else
7529 {
7530 csrScanStartIdleScanTimer(pMac, nTime);
7531 }
7532 }
Rashmi Ramanna68b309c2014-05-20 11:52:22 +05307533 if(pMac->deferImps)
7534 {
7535 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7536 pMac->deferImps = eANI_BOOLEAN_FALSE;
7537 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007538}
7539
7540
7541
7542
7543tANI_BOOLEAN csrScanRemoveNotRoamingScanCommand(tpAniSirGlobal pMac)
7544{
7545 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
7546 tListElem *pEntry, *pEntryTmp;
7547 tSmeCmd *pCommand;
7548 tDblLinkList localList;
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307549 tDblLinkList *pCmdList;
Jeff Johnson295189b2012-06-20 16:38:30 -07007550
7551 vos_mem_zero(&localList, sizeof(tDblLinkList));
7552 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
7553 {
7554 smsLog(pMac, LOGE, FL(" failed to open list"));
7555 return fRet;
7556 }
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307557 if (!pMac->fScanOffload)
7558 pCmdList = &pMac->sme.smeCmdPendingList;
7559 else
7560 pCmdList = &pMac->sme.smeScanCmdPendingList;
Jeff Johnson295189b2012-06-20 16:38:30 -07007561
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307562 csrLLLock(pCmdList);
7563 pEntry = csrLLPeekHead(pCmdList, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007564 while(pEntry)
7565 {
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307566 pEntryTmp = csrLLNext(pCmdList, pEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007567 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7568 if( eSmeCommandScan == pCommand->command )
7569 {
7570 switch( pCommand->u.scanCmd.reason )
7571 {
7572 case eCsrScanIdleScan:
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307573 if( csrLLRemoveEntry(pCmdList, pEntry, LL_ACCESS_NOLOCK) )
Jeff Johnson295189b2012-06-20 16:38:30 -07007574 {
7575 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
7576 }
7577 fRet = eANI_BOOLEAN_TRUE;
7578 break;
7579
7580 default:
7581 break;
7582 } //switch
7583 }
7584 pEntry = pEntryTmp;
7585 }
7586
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307587 csrLLUnlock(pCmdList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007588
7589 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
7590 {
7591 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7592 csrReleaseCommandScan( pMac, pCommand );
7593 }
7594
7595 csrLLClose(&localList);
7596
7597 return (fRet);
7598}
7599
7600
7601tANI_BOOLEAN csrScanRemoveFreshScanCommand(tpAniSirGlobal pMac, tANI_U8 sessionId)
7602{
7603 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
7604 tListElem *pEntry, *pEntryTmp;
7605 tSmeCmd *pCommand;
7606 tDblLinkList localList;
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307607 tDblLinkList *pCmdList;
Jeff Johnson295189b2012-06-20 16:38:30 -07007608
7609 vos_mem_zero(&localList, sizeof(tDblLinkList));
7610 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
7611 {
7612 smsLog(pMac, LOGE, FL(" failed to open list"));
7613 return fRet;
7614 }
7615
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307616 if (!pMac->fScanOffload)
7617 pCmdList = &pMac->sme.smeCmdPendingList;
7618 else
7619 pCmdList = &pMac->sme.smeScanCmdPendingList;
7620
7621 csrLLLock(pCmdList);
7622 pEntry = csrLLPeekHead(pCmdList, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007623 while(pEntry)
7624 {
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307625 pEntryTmp = csrLLNext(pCmdList, pEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007626 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7627 if( (eSmeCommandScan == pCommand->command) && (sessionId == pCommand->sessionId) )
7628 {
7629 switch(pCommand->u.scanCmd.reason)
7630 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07007631#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
7632 case eCsrScanGetLfrResult:
7633#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07007634 case eCsrScanGetResult:
7635 case eCsrScanSetBGScanParam:
7636 case eCsrScanBGScanAbort:
7637 case eCsrScanBGScanEnable:
7638 case eCsrScanGetScanChnInfo:
7639 break;
7640 default:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007641 smsLog (pMac, LOGW, "%s: -------- abort scan command reason = %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007642 __func__, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07007643 //The rest are fresh scan requests
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307644 if( csrLLRemoveEntry(pCmdList, pEntry, LL_ACCESS_NOLOCK) )
Jeff Johnson295189b2012-06-20 16:38:30 -07007645 {
7646 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
7647 }
7648 fRet = eANI_BOOLEAN_TRUE;
7649 break;
7650 }
7651 }
7652 pEntry = pEntryTmp;
7653 }
7654
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307655 csrLLUnlock(pCmdList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007656
7657 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
7658 {
7659 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7660 if (pCommand->u.scanCmd.callback)
7661 {
7662 /* User scan request is pending,
7663 * send response with status eCSR_SCAN_ABORT*/
7664 pCommand->u.scanCmd.callback(pMac,
7665 pCommand->u.scanCmd.pContext,
7666 pCommand->u.scanCmd.scanID,
7667 eCSR_SCAN_ABORT);
7668 }
7669 csrReleaseCommandScan( pMac, pCommand );
7670 }
7671 csrLLClose(&localList);
7672
7673 return (fRet);
7674}
7675
7676
7677void csrReleaseScanCommand(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
7678{
7679 eCsrScanReason reason = pCommand->u.scanCmd.reason;
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307680 tANI_BOOLEAN status;
7681
7682 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07007683 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307684 tANI_U32 i;
7685 for(i = 0; i < CSR_ROAM_SESSION_MAX; i++)
Abhishek Singhf52182c2016-08-24 11:15:23 +05307686 csrRoamStateChange(pMac,
7687 pMac->roam.prev_state[i], i);
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307688 }
7689 else
7690 {
7691 csrRoamStateChange(pMac,
Abhishek Singhf52182c2016-08-24 11:15:23 +05307692 pMac->roam.prev_state[pCommand->sessionId],
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307693 pCommand->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07007694 }
7695
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307696 csrScanCallCallback(pMac, pCommand, scanStatus);
Jeff Johnson295189b2012-06-20 16:38:30 -07007697
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007698 smsLog(pMac, LOG3, " Remove Scan command reason = %d", reason);
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307699 if (pMac->fScanOffload)
7700 {
7701 status = csrLLRemoveEntry(&pMac->sme.smeScanCmdActiveList,
7702 &pCommand->Link, LL_ACCESS_LOCK);
7703 }
7704 else
7705 {
7706 status = csrLLRemoveEntry(&pMac->sme.smeCmdActiveList,
7707 &pCommand->Link, LL_ACCESS_LOCK);
7708 }
7709
7710 if(status)
Jeff Johnson295189b2012-06-20 16:38:30 -07007711 {
7712 csrReleaseCommandScan( pMac, pCommand );
7713 }
7714 else
7715 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307716 smsLog(pMac, LOGE,
7717 " ********csrReleaseScanCommand cannot release command reason %d",
7718 pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07007719 }
7720}
7721
7722
7723eHalStatus csrScanGetPMKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
7724 tPmkidCandidateInfo *pPmkidList, tANI_U32 *pNumItems )
7725{
7726 eHalStatus status = eHAL_STATUS_SUCCESS;
7727 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
7728
Jeff Johnson32d95a32012-09-10 13:15:23 -07007729 if(!pSession)
7730 {
7731 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
7732 return eHAL_STATUS_FAILURE;
7733 }
7734
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007735 smsLog(pMac, LOGW, " pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07007736 csrResetPMKIDCandidateList(pMac, sessionId);
7737 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
7738 {
7739 tCsrScanResultFilter *pScanFilter;
7740 tCsrScanResultInfo *pScanResult;
7741 tScanResultHandle hBSSList;
7742 tANI_U32 nItems = *pNumItems;
7743
7744 *pNumItems = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05307745 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
7746 if ( NULL == pScanFilter )
7747 status = eHAL_STATUS_FAILURE;
7748 else
Jeff Johnson295189b2012-06-20 16:38:30 -07007749 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307750 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007751 //Here is the profile we need to connect to
7752 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
7753 if(HAL_STATUS_SUCCESS(status))
7754 {
7755 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
7756 if(HAL_STATUS_SUCCESS(status))
7757 {
7758 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumPmkidCandidate < nItems))
7759 {
7760 //NumPmkidCandidate adds up here
7761 csrProcessBSSDescForPMKIDList(pMac, &pScanResult->BssDescriptor,
7762 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
7763 }
7764 if(pSession->NumPmkidCandidate)
7765 {
7766 *pNumItems = pSession->NumPmkidCandidate;
Kiet Lam64c1b492013-07-12 13:56:44 +05307767 vos_mem_copy(pPmkidList, pSession->PmkidCandidateInfo,
7768 pSession->NumPmkidCandidate * sizeof(tPmkidCandidateInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07007769 }
7770 csrScanResultPurge(pMac, hBSSList);
7771 }//Have scan result
7772 csrFreeScanFilter(pMac, pScanFilter);
7773 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307774 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07007775 }
7776 }
7777
7778 return (status);
7779}
7780
7781
7782
7783#ifdef FEATURE_WLAN_WAPI
7784eHalStatus csrScanGetBKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
7785 tBkidCandidateInfo *pBkidList, tANI_U32 *pNumItems )
7786{
7787 eHalStatus status = eHAL_STATUS_SUCCESS;
7788 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
7789
Jeff Johnson32d95a32012-09-10 13:15:23 -07007790 if(!pSession)
7791 {
7792 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
7793 return eHAL_STATUS_FAILURE;
7794 }
7795
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007796 smsLog(pMac, LOGW, " pMac->scan.NumBkidCandidate = %d", pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07007797 csrResetBKIDCandidateList(pMac, sessionId);
7798 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
7799 {
7800 tCsrScanResultFilter *pScanFilter;
7801 tCsrScanResultInfo *pScanResult;
7802 tScanResultHandle hBSSList;
7803 tANI_U32 nItems = *pNumItems;
7804 *pNumItems = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05307805 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
7806 if ( NULL == pScanFilter )
7807 status = eHAL_STATUS_FAILURE;
7808 else
Jeff Johnson295189b2012-06-20 16:38:30 -07007809 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307810 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007811 //Here is the profile we need to connect to
7812 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
7813 if(HAL_STATUS_SUCCESS(status))
7814 {
7815 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
7816 if(HAL_STATUS_SUCCESS(status))
7817 {
7818 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumBkidCandidate < nItems))
7819 {
7820 //pMac->scan.NumBkidCandidate adds up here
7821 csrProcessBSSDescForBKIDList(pMac, &pScanResult->BssDescriptor,
7822 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
7823
7824 }
7825 if(pSession->NumBkidCandidate)
7826 {
7827 *pNumItems = pSession->NumBkidCandidate;
Kiet Lam64c1b492013-07-12 13:56:44 +05307828 vos_mem_copy(pBkidList, pSession->BkidCandidateInfo, pSession->NumBkidCandidate * sizeof(tBkidCandidateInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07007829 }
7830 csrScanResultPurge(pMac, hBSSList);
7831 }//Have scan result
7832 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307833 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07007834 }
7835 }
7836
7837 return (status);
7838}
7839#endif /* FEATURE_WLAN_WAPI */
7840
Selvaraj, Sridhar32417ed2016-06-22 15:19:12 +05307841/**
7842 * csr_scan_request_set_chan_time() - Populate max and min
7843 * channel time in Scan request
7844 * @pMac - pointer to mac context
7845 * @pScanCmd - pointer to the Scan command
7846 *
7847 * Return - None
7848 */
7849#ifndef QCA_WIFI_ISOC
7850static void csr_scan_request_set_chan_time(tpAniSirGlobal pMac,
7851 tSmeCmd *pScanCmd)
7852{
7853 if (pMac->roam.neighborRoamInfo.handoffReqInfo.src
7854 == FASTREASSOC) {
7855 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime
7856 = MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL_FASTREASSOC;
7857 pScanCmd->u.scanCmd.u.scanRequest.minChnTime
7858 = MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL_FASTREASSOC;
7859 pMac->roam.neighborRoamInfo.handoffReqInfo.src = 0;
7860 } else {
7861 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime
7862 = MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7863 pScanCmd->u.scanCmd.u.scanRequest.minChnTime
7864 = MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7865 }
7866}
7867#else
7868static void csr_scan_request_set_chan_time(tpAniSirGlobal pMac,
7869 tSmeCmd *pScanCmd)
7870{
7871 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime
7872 = MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7873 pScanCmd->u.scanCmd.u.scanRequest.minChnTime
7874 = MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7875}
7876#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07007877
7878//This function is usually used for BSSs that suppresses SSID so the profile
7879//shall have one and only one SSID
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007880eHalStatus csrScanForSSID(tpAniSirGlobal pMac, tANI_U32 sessionId, tCsrRoamProfile *pProfile, tANI_U32 roamId, tANI_BOOLEAN notify)
Jeff Johnson295189b2012-06-20 16:38:30 -07007881{
7882 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
7883 tSmeCmd *pScanCmd = NULL;
7884 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
7885 tANI_U8 index = 0;
7886 tANI_U32 numSsid = pProfile->SSIDs.numOfSSIDs;
7887
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007888 smsLog(pMac, LOG2, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007889 //For WDS, we use the index 0. There must be at least one in there
7890 if( CSR_IS_WDS_STA( pProfile ) && numSsid )
7891 {
7892 numSsid = 1;
7893 }
7894 if(pMac->scan.fScanEnable && ( numSsid == 1 ) )
7895 {
7896 do
7897 {
7898 pScanCmd = csrGetCommandBuffer(pMac);
7899 if(!pScanCmd)
7900 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007901 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007902 break;
7903 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307904 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
7905 pScanCmd->u.scanCmd.pToRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
7906 if ( NULL == pScanCmd->u.scanCmd.pToRoamProfile )
krunal soni587bf012014-02-04 12:35:11 -08007907 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307908 status = eHAL_STATUS_FAILURE;
krunal soni587bf012014-02-04 12:35:11 -08007909 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307910 else
krunal soni587bf012014-02-04 12:35:11 -08007911 {
7912 status = csrRoamCopyProfile(pMac, pScanCmd->u.scanCmd.pToRoamProfile, pProfile);
7913 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007914 if(!HAL_STATUS_SUCCESS(status))
7915 break;
7916 pScanCmd->u.scanCmd.roamId = roamId;
7917 pScanCmd->command = eSmeCommandScan;
Jeff Johnsone7245742012-09-05 17:12:55 -07007918 pScanCmd->sessionId = (tANI_U8)sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07007919 pScanCmd->u.scanCmd.callback = NULL;
7920 pScanCmd->u.scanCmd.pContext = NULL;
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007921 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 -07007922 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Kiet Lam64c1b492013-07-12 13:56:44 +05307923 vos_mem_set(&pScanCmd->u.scanCmd.u.scanRequest, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007924 pScanCmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Jeff Johnson295189b2012-06-20 16:38:30 -07007925 pScanCmd->u.scanCmd.u.scanRequest.BSSType = pProfile->BSSType;
Jeff Johnsone7245742012-09-05 17:12:55 -07007926 // To avoid 11b rate in probe request Set p2pSearch flag as 1 for P2P Client Mode
7927 if(VOS_P2P_CLIENT_MODE == pProfile->csrPersona)
7928 {
7929 pScanCmd->u.scanCmd.u.scanRequest.p2pSearch = 1;
7930 }
Agarwal Ashish4f616132013-12-30 23:32:50 +05307931 if(pProfile->nAddIEScanLength)
Jeff Johnsone7245742012-09-05 17:12:55 -07007932 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307933 pScanCmd->u.scanCmd.u.scanRequest.pIEField = vos_mem_malloc(
7934 pProfile->nAddIEScanLength);
7935 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.pIEField )
7936 status = eHAL_STATUS_FAILURE;
7937 else
7938 status = eHAL_STATUS_SUCCESS;
7939 vos_mem_set(pScanCmd->u.scanCmd.u.scanRequest.pIEField,
7940 pProfile->nAddIEScanLength, 0);
7941 if (HAL_STATUS_SUCCESS(status))
Jeff Johnsone7245742012-09-05 17:12:55 -07007942 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307943 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.pIEField,
Agarwal Ashish4f616132013-12-30 23:32:50 +05307944 pProfile->addIEScan, pProfile->nAddIEScanLength);
Jeff Johnsone7245742012-09-05 17:12:55 -07007945 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = pProfile->nAddIEScanLength;
7946 }
7947 else
7948 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007949 smsLog(pMac, LOGE, "No memory for scanning IE fields");
Jeff Johnsone7245742012-09-05 17:12:55 -07007950 }
7951 } //Allocate memory for IE field
7952 else
7953 {
7954 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = 0;
7955 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07007956 /* For one channel be good enpugh time to receive beacon atleast */
7957 if( 1 == pProfile->ChannelInfo.numOfChannels )
7958 {
Selvaraj, Sridhar32417ed2016-06-22 15:19:12 +05307959 csr_scan_request_set_chan_time(pMac, pScanCmd);
7960 } else {
Kiet Lam64c1b492013-07-12 13:56:44 +05307961 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime =
7962 pMac->roam.configParam.nActiveMaxChnTime;
7963 pScanCmd->u.scanCmd.u.scanRequest.minChnTime =
7964 pMac->roam.configParam.nActiveMinChnTime;
Jeff Johnson32d95a32012-09-10 13:15:23 -07007965 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307966 pScanCmd->u.scanCmd.u.scanRequest.maxChnTimeBtc =
7967 pMac->roam.configParam.nActiveMaxChnTimeBtc;
7968 pScanCmd->u.scanCmd.u.scanRequest.minChnTimeBtc =
7969 pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07007970 if(pProfile->BSSIDs.numOfBSSIDs == 1)
7971 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307972 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.bssid,
7973 pProfile->BSSIDs.bssid, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07007974 }
7975 else
7976 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307977 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.bssid, bAddr, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07007978 }
7979 if(pProfile->ChannelInfo.numOfChannels)
7980 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307981 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(
7982 sizeof(*pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
7983 * pProfile->ChannelInfo.numOfChannels);
7984 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
7985 status = eHAL_STATUS_FAILURE;
7986 else
7987 status = eHAL_STATUS_SUCCESS;
7988 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
7989 if(HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07007990 {
7991 csrRoamIsChannelValid(pMac, pProfile->ChannelInfo.ChannelList[0]);
7992 for(index = 0; index < pProfile->ChannelInfo.numOfChannels; index++)
7993 {
7994 if(csrRoamIsValidChannel(pMac, pProfile->ChannelInfo.ChannelList[index]))
7995 {
7996 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels]
7997 = pProfile->ChannelInfo.ChannelList[index];
7998 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels++;
7999 }
8000 else
8001 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008002 smsLog(pMac, LOGW, FL("process a channel (%d) that is invalid"), pProfile->ChannelInfo.ChannelList[index]);
Jeff Johnson295189b2012-06-20 16:38:30 -07008003 }
8004
8005 }
8006 }
8007 else
8008 {
8009 break;
8010 }
8011
8012 }
8013 else
8014 {
8015 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
8016 }
8017 if(pProfile->SSIDs.numOfSSIDs)
8018 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308019 pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList = vos_mem_malloc(
8020 pProfile->SSIDs.numOfSSIDs * sizeof(tCsrSSIDInfo));
8021 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList )
8022 status = eHAL_STATUS_FAILURE;
8023 else
8024 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07008025 if(!HAL_STATUS_SUCCESS(status))
8026 {
8027 break;
8028 }
8029 pScanCmd->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 1;
Kiet Lam64c1b492013-07-12 13:56:44 +05308030 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList,
8031 pProfile->SSIDs.SSIDList, sizeof(tCsrSSIDInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07008032 }
8033 //Start process the command
8034 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
8035 if( !HAL_STATUS_SUCCESS( status ) )
8036 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008037 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07008038 break;
8039 }
8040 }while(0);
8041 if(!HAL_STATUS_SUCCESS(status))
8042 {
8043 if(pScanCmd)
8044 {
8045 csrReleaseCommandScan(pMac, pScanCmd);
8046 //TODO:free the memory that is allocated in this function
8047 }
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008048 if(notify)
8049 {
Jeff Johnson295189b2012-06-20 16:38:30 -07008050 csrRoamCallCallback(pMac, sessionId, NULL, roamId, eCSR_ROAM_FAILED, eCSR_ROAM_RESULT_FAILURE);
8051 }
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008052 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008053 }//valid
8054 else
8055 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008056 smsLog(pMac, LOGE, FL("cannot scan because scanEnable (%d) or numSSID (%d) is invalid"),
Jeff Johnson295189b2012-06-20 16:38:30 -07008057 pMac->scan.fScanEnable, pProfile->SSIDs.numOfSSIDs);
8058 }
8059
8060 return (status);
8061}
8062
8063
8064//Issue a scan base on the new capability infomation
8065//This should only happen when the associated AP changes its capability.
8066//After this scan is done, CSR reroams base on the new scan results
8067eHalStatus csrScanForCapabilityChange(tpAniSirGlobal pMac, tSirSmeApNewCaps *pNewCaps)
8068{
8069 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
8070 tSmeCmd *pScanCmd = NULL;
8071
8072 if(pNewCaps)
8073 {
8074 do
8075 {
8076 pScanCmd = csrGetCommandBuffer(pMac);
8077 if(!pScanCmd)
8078 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008079 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07008080 status = eHAL_STATUS_RESOURCES;
8081 break;
8082 }
Kiet Lam64c1b492013-07-12 13:56:44 +05308083 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008084 status = eHAL_STATUS_SUCCESS;
8085 pScanCmd->u.scanCmd.roamId = 0;
8086 pScanCmd->command = eSmeCommandScan;
8087 pScanCmd->u.scanCmd.callback = NULL;
8088 pScanCmd->u.scanCmd.pContext = NULL;
8089 pScanCmd->u.scanCmd.reason = eCsrScanForCapsChange;
8090 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
8091 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
8092 if( !HAL_STATUS_SUCCESS( status ) )
8093 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008094 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07008095 break;
8096 }
8097 }while(0);
8098 if(!HAL_STATUS_SUCCESS(status))
8099 {
8100 if(pScanCmd)
8101 {
8102 csrReleaseCommandScan(pMac, pScanCmd);
8103 }
8104 }
8105 }
8106
8107 return (status);
8108}
8109
8110
8111
8112void csrInitBGScanChannelList(tpAniSirGlobal pMac)
8113{
8114 tANI_U32 len = CSR_MIN(sizeof(pMac->roam.validChannelList), sizeof(pMac->scan.bgScanChannelList));
8115
Kiet Lam64c1b492013-07-12 13:56:44 +05308116 vos_mem_set(pMac->scan.bgScanChannelList, len, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008117 pMac->scan.numBGScanChannel = 0;
8118
8119 if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
8120 {
8121 pMac->roam.numValidChannels = len;
8122 pMac->scan.numBGScanChannel = (tANI_U8)CSR_MIN(len, WNI_CFG_BG_SCAN_CHANNEL_LIST_LEN);
Kiet Lam64c1b492013-07-12 13:56:44 +05308123 vos_mem_copy(pMac->scan.bgScanChannelList, pMac->roam.validChannelList,
8124 pMac->scan.numBGScanChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07008125 csrSetBGScanChannelList(pMac, pMac->scan.bgScanChannelList, pMac->scan.numBGScanChannel);
8126 }
8127}
8128
8129
8130//This function return TRUE if background scan channel list is adjusted.
8131//this function will only shrink the background scan channel list
8132tANI_BOOLEAN csrAdjustBGScanChannelList(tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels,
8133 tANI_U8 *pAdjustChannels, tANI_U8 *pNumAdjustChannels)
8134{
8135 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
8136 tANI_U8 i, j, count = *pNumAdjustChannels;
8137
8138 i = 0;
8139 while(i < count)
8140 {
8141 for(j = 0; j < NumChannels; j++)
8142 {
8143 if(pChannelList[j] == pAdjustChannels[i])
8144 break;
8145 }
8146 if(j == NumChannels)
8147 {
8148 //This channel is not in the list, remove it
8149 fRet = eANI_BOOLEAN_TRUE;
8150 count--;
8151 if(count - i)
8152 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308153 vos_mem_copy(&pAdjustChannels[i], &pAdjustChannels[i+1], count - i);
Jeff Johnson295189b2012-06-20 16:38:30 -07008154 }
8155 else
8156 {
8157 //already remove the last one. Done.
8158 break;
8159 }
8160 }
8161 else
8162 {
8163 i++;
8164 }
8165 }//while(i<count)
8166 *pNumAdjustChannels = count;
8167
8168 return (fRet);
8169}
8170
8171
8172//Get the list of the base channels to scan for passively 11d info
8173eHalStatus csrScanGetSupportedChannels( tpAniSirGlobal pMac )
8174{
8175 eHalStatus status = eHAL_STATUS_SUCCESS;
8176 int n = WNI_CFG_VALID_CHANNEL_LIST_LEN;
8177
8178 status = vos_nv_getSupportedChannels( pMac->scan.baseChannels.channelList, &n, NULL, NULL );
8179 if( HAL_STATUS_SUCCESS(status) )
8180 {
8181 pMac->scan.baseChannels.numChannels = (tANI_U8)n;
8182 }
8183 else
8184 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008185 smsLog( pMac, LOGE, FL(" failed") );
Jeff Johnson295189b2012-06-20 16:38:30 -07008186 pMac->scan.baseChannels.numChannels = 0;
8187 }
8188
8189 return ( status );
8190}
8191
8192//This function use the input pChannelList to validate the current saved channel list
8193eHalStatus csrSetBGScanChannelList( tpAniSirGlobal pMac, tANI_U8 *pAdjustChannels, tANI_U8 NumAdjustChannels)
8194{
8195 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumAdjustChannels;
8196
8197 return (ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pAdjustChannels, dataLen, NULL, eANI_BOOLEAN_FALSE));
8198}
8199
8200
8201void csrSetCfgValidChannelList( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels )
8202{
8203 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumChannels;
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05308204 eHalStatus status;
Jeff Johnson295189b2012-06-20 16:38:30 -07008205
Mihir Shete31c435d2014-02-12 13:13:34 +05308206 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
8207 "%s: dump valid channel list(NumChannels(%d))",
8208 __func__,NumChannels);
8209 VOS_TRACE_HEX_DUMP(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
8210 pChannelList, NumChannels);
8211
Jeff Johnson295189b2012-06-20 16:38:30 -07008212 ccmCfgSetStr(pMac, WNI_CFG_VALID_CHANNEL_LIST, pChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
Leela Venkata Kiran Kumar Reddy Chiralac6663f72014-02-03 21:04:58 -08008213#ifdef QCA_WIFI_2_0
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05308214 if (pMac->fScanOffload)
8215 {
8216 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
8217 "Scan offload is enabled, update default chan list");
Leela Venkata Kiran Kumar Reddy Chiralac6663f72014-02-03 21:04:58 -08008218 status = csrUpdateChannelList(pMac);
8219 }
8220#else
8221 status = csrUpdateChannelList(pMac);
8222#endif
8223
8224 if (eHAL_STATUS_SUCCESS != status)
8225 {
8226 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR,
8227 "failed to update the supported channel list");
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05308228 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008229 return;
8230}
8231
8232
8233
8234/*
8235 * The Tx power limits are saved in the cfg for future usage.
8236 */
8237void csrSaveTxPowerToCfg( tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 cfgId )
8238{
8239 tListElem *pEntry;
8240 tANI_U32 cbLen = 0, dataLen;
8241 tCsrChannelPowerInfo *pChannelSet;
8242 tANI_U32 idx;
8243 tSirMacChanInfo *pChannelPowerSet;
8244 tANI_U8 *pBuf = NULL;
8245
8246 //allocate maximum space for all channels
8247 dataLen = WNI_CFG_VALID_CHANNEL_LIST_LEN * sizeof(tSirMacChanInfo);
Kiet Lam64c1b492013-07-12 13:56:44 +05308248 if ( (pBuf = vos_mem_malloc(dataLen)) != NULL )
Jeff Johnson295189b2012-06-20 16:38:30 -07008249 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308250 vos_mem_set(pBuf, dataLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008251 pChannelPowerSet = (tSirMacChanInfo *)(pBuf);
8252
8253 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
8254 // write the tuples (startChan, numChan, txPower) for each channel found in the channel power list.
8255 while( pEntry )
8256 {
8257 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
8258 if ( 1 != pChannelSet->interChannelOffset )
8259 {
8260 // we keep the 5G channel sets internally with an interchannel offset of 4. Expand these
8261 // to the right format... (inter channel offset of 1 is the only option for the triplets
8262 // that 11d advertises.
8263 if ((cbLen + (pChannelSet->numChannels * sizeof(tSirMacChanInfo))) >= dataLen)
8264 {
8265 // expanding this entry will overflow our allocation
8266 smsLog(pMac, LOGE,
8267 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07008268 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07008269 pChannelSet->firstChannel,
8270 pChannelSet->numChannels,
8271 pChannelSet->interChannelOffset);
8272 break;
8273 }
8274
8275 for( idx = 0; idx < pChannelSet->numChannels; idx++ )
8276 {
8277 pChannelPowerSet->firstChanNum = (tSirMacChanNum)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008278 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07008279 pChannelPowerSet->numChannels = 1;
Jeff Johnson295189b2012-06-20 16:38:30 -07008280 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008281 smsLog(pMac, LOG3, " Setting Max Transmit Power %d", pChannelPowerSet->maxTxPower);
Jeff Johnson295189b2012-06-20 16:38:30 -07008282 cbLen += sizeof( tSirMacChanInfo );
8283 pChannelPowerSet++;
8284 }
8285 }
8286 else
8287 {
8288 if (cbLen >= dataLen)
8289 {
8290 // this entry will overflow our allocation
8291 smsLog(pMac, LOGE,
8292 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07008293 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07008294 pChannelSet->firstChannel,
8295 pChannelSet->numChannels,
8296 pChannelSet->interChannelOffset);
8297 break;
8298 }
8299 pChannelPowerSet->firstChanNum = pChannelSet->firstChannel;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008300 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07008301 pChannelPowerSet->numChannels = pChannelSet->numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -07008302 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008303 smsLog(pMac, LOG3, " Setting Max Transmit Power %d, nTxPower %d", pChannelPowerSet->maxTxPower,pMac->roam.configParam.nTxPowerCap );
Jeff Johnson295189b2012-06-20 16:38:30 -07008304
8305
8306 cbLen += sizeof( tSirMacChanInfo );
8307 pChannelPowerSet++;
8308 }
8309
8310 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
8311 }
8312
8313 if(cbLen)
8314 {
8315 ccmCfgSetStr(pMac, cfgId, (tANI_U8 *)pBuf, cbLen, NULL, eANI_BOOLEAN_FALSE);
8316 }
Kiet Lam64c1b492013-07-12 13:56:44 +05308317 vos_mem_free(pBuf);
Jeff Johnson295189b2012-06-20 16:38:30 -07008318 }//Allocate memory
8319}
8320
8321
8322void csrSetCfgCountryCode( tpAniSirGlobal pMac, tANI_U8 *countryCode )
8323{
8324 tANI_U8 cc[WNI_CFG_COUNTRY_CODE_LEN];
8325 ///v_REGDOMAIN_t DomainId;
8326
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008327 smsLog( pMac, LOG3, "Setting Country Code in Cfg from csrSetCfgCountryCode %s",countryCode );
Kiet Lam64c1b492013-07-12 13:56:44 +05308328 vos_mem_copy(cc, countryCode, WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07008329
8330 // don't program the bogus country codes that we created for Korea in the MAC. if we see
8331 // the bogus country codes, program the MAC with the right country code.
8332 if ( ( 'K' == countryCode[ 0 ] && '1' == countryCode[ 1 ] ) ||
8333 ( 'K' == countryCode[ 0 ] && '2' == countryCode[ 1 ] ) ||
8334 ( 'K' == countryCode[ 0 ] && '3' == countryCode[ 1 ] ) ||
8335 ( 'K' == countryCode[ 0 ] && '4' == countryCode[ 1 ] ) )
8336 {
8337 // replace the alternate Korea country codes, 'K1', 'K2', .. with 'KR' for Korea
8338 cc[ 1 ] = 'R';
8339 }
8340 ccmCfgSetStr(pMac, WNI_CFG_COUNTRY_CODE, cc, WNI_CFG_COUNTRY_CODE_LEN, NULL, eANI_BOOLEAN_FALSE);
8341
8342 //Need to let HALPHY know about the current domain so it can apply some
8343 //domain-specific settings (TX filter...)
8344 /*if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(pMac, cc, &DomainId)))
8345 {
8346 halPhySetRegDomain(pMac, DomainId);
8347 }*/
8348}
8349
8350
8351
8352eHalStatus csrGetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pBuf, tANI_U8 *pbLen)
8353{
8354 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
8355 tANI_U32 len;
8356
8357 if(pBuf && pbLen && (*pbLen >= WNI_CFG_COUNTRY_CODE_LEN))
8358 {
8359 len = *pbLen;
8360 status = ccmCfgGetStr(pMac, WNI_CFG_COUNTRY_CODE, pBuf, &len);
8361 if(HAL_STATUS_SUCCESS(status))
8362 {
8363 *pbLen = (tANI_U8)len;
8364 }
8365 }
8366
8367 return (status);
8368}
8369
8370
8371void csrSetCfgScanControlList( tpAniSirGlobal pMac, tANI_U8 *countryCode, tCsrChannel *pChannelList )
8372{
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05308373 tANI_U8 i, j, k;
Jeff Johnson295189b2012-06-20 16:38:30 -07008374 tANI_BOOLEAN found=FALSE;
8375 tANI_U8 *pControlList = NULL;
8376 tANI_U32 len = WNI_CFG_SCAN_CONTROL_LIST_LEN;
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05308377 tANI_U8 cfgActiveDFSChannels = 0;
8378 tANI_U8 *cfgActiveDFSChannelLIst = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07008379
Kiet Lam64c1b492013-07-12 13:56:44 +05308380 if ( (pControlList = vos_mem_malloc(WNI_CFG_SCAN_CONTROL_LIST_LEN)) != NULL )
Jeff Johnson295189b2012-06-20 16:38:30 -07008381 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308382 vos_mem_set((void *)pControlList, WNI_CFG_SCAN_CONTROL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008383 if(HAL_STATUS_SUCCESS(ccmCfgGetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, &len)))
8384 {
8385 for (i = 0; i < pChannelList->numChannels; i++)
8386 {
8387 for (j = 0; j < len; j += 2)
8388 {
8389 if (pControlList[j] == pChannelList->channelList[i])
8390 {
8391 found = TRUE;
8392 break;
8393 }
8394 }
8395
8396 if (found) // insert a pair(channel#, flag)
8397 {
Gopichand Nakkala392cbc12013-05-28 16:15:00 +05308398 pControlList[j+1] = csrGetScanType(pMac, pControlList[j]);
Jeff Johnson295189b2012-06-20 16:38:30 -07008399 found = FALSE; // reset the flag
Jeff Johnson295189b2012-06-20 16:38:30 -07008400
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05308401 // When DFS mode is 2, mark static channels as active
8402 if (pMac->scan.fEnableDFSChnlScan ==
8403 DFS_CHNL_SCAN_ENABLED_ACTIVE)
8404 {
8405 cfgActiveDFSChannels =
8406 pMac->roam.neighborRoamInfo.cfgParams.
8407 channelInfo.numOfChannels;
8408 cfgActiveDFSChannelLIst =
8409 pMac->roam.neighborRoamInfo.cfgParams.
8410 channelInfo.ChannelList;
8411 if (cfgActiveDFSChannelLIst)
8412 {
8413 for (k=0; k < cfgActiveDFSChannels; k++)
8414 {
8415 if(CSR_IS_CHANNEL_DFS(cfgActiveDFSChannelLIst[k])
8416 && (pControlList[j] ==
8417 cfgActiveDFSChannelLIst[k]))
8418 {
8419 pControlList[j+1] = eSIR_ACTIVE_SCAN;
8420 smsLog(pMac, LOG1, FL("Marked DFS ch %d"
8421 " as active"),
8422 cfgActiveDFSChannelLIst[k]);
8423 }
8424 }
8425 }
8426 }
8427 }
8428 }
8429
8430 smsLog(pMac, LOG1, FL("fEnableDFSChnlScan %d"),
8431 pMac->scan.fEnableDFSChnlScan);
Mihir Shete31c435d2014-02-12 13:13:34 +05308432 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
8433 "%s: dump scan control list",__func__);
8434 VOS_TRACE_HEX_DUMP(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
8435 pControlList, len);
8436
Jeff Johnson295189b2012-06-20 16:38:30 -07008437 ccmCfgSetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, len, NULL, eANI_BOOLEAN_FALSE);
8438 }//Successfully getting scan control list
Kiet Lam64c1b492013-07-12 13:56:44 +05308439 vos_mem_free(pControlList);
Jeff Johnson295189b2012-06-20 16:38:30 -07008440 }//AllocateMemory
8441}
8442
Jeff Johnson295189b2012-06-20 16:38:30 -07008443//if bgPeriod is 0, background scan is disabled. It is in millisecond units
8444eHalStatus csrSetCfgBackgroundScanPeriod(tpAniSirGlobal pMac, tANI_U32 bgPeriod)
8445{
8446 return (ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, bgPeriod, (tCcmCfgSetCallback) csrScanCcmCfgSetCallback, eANI_BOOLEAN_FALSE));
8447}
8448
8449
8450void csrScanCcmCfgSetCallback(tHalHandle hHal, tANI_S32 result)
8451{
8452 tListElem *pEntry = NULL;
8453 tSmeCmd *pCommand = NULL;
8454 tpAniSirGlobal pMac = PMAC_STRUCT( hHal );
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05308455 tDblLinkList *pCmdList ;
8456
8457 if (!pMac->fScanOffload)
8458 pCmdList = &pMac->sme.smeCmdActiveList;
8459 else
8460 pCmdList = &pMac->sme.smeScanCmdActiveList;
8461
8462 pEntry = csrLLPeekHead( pCmdList, LL_ACCESS_LOCK );
Jeff Johnson295189b2012-06-20 16:38:30 -07008463 if ( pEntry )
8464 {
8465 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8466 if ( eSmeCommandScan == pCommand->command )
8467 {
8468 eCsrScanStatus scanStatus = (CCM_IS_RESULT_SUCCESS(result)) ? eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
8469 csrReleaseScanCommand(pMac, pCommand, scanStatus);
8470 }
8471 else
8472 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008473 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
Jeff Johnson295189b2012-06-20 16:38:30 -07008474 }
8475 }
8476 smeProcessPendingQueue( pMac );
8477}
8478
8479eHalStatus csrProcessSetBGScanParam(tpAniSirGlobal pMac, tSmeCmd *pCommand)
8480{
8481 eHalStatus status;
8482 tCsrBGScanRequest *pScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
8483 tANI_U32 dataLen = sizeof( tANI_U8 ) * pScanReq->ChannelInfo.numOfChannels;
8484
8485 //***setcfg for background scan channel list
8486 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MINIMUM_CHANNEL_TIME, pScanReq->minChnTime, NULL, eANI_BOOLEAN_FALSE);
8487 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MAXIMUM_CHANNEL_TIME, pScanReq->maxChnTime, NULL, eANI_BOOLEAN_FALSE);
8488 //Not set the background scan interval if not connected because bd scan should not be run if not connected
8489 if(!csrIsAllSessionDisconnected(pMac))
8490 {
Jeff Johnson295189b2012-06-20 16:38:30 -07008491
8492#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
8493 {
8494 vos_log_scan_pkt_type *pScanLog = NULL;
8495
8496 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
8497 if(pScanLog)
8498 {
8499 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
8500 pScanLog->minChnTime = (v_U8_t)pScanReq->minChnTime;
8501 pScanLog->maxChnTime = (v_U8_t)pScanReq->maxChnTime;
8502 pScanLog->timeBetweenBgScan = (v_U8_t)pScanReq->scanInterval;
8503 pScanLog->numChannel = pScanReq->ChannelInfo.numOfChannels;
8504 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
8505 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308506 vos_mem_copy(pScanLog->channels,
8507 pScanReq->ChannelInfo.ChannelList,
8508 pScanLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07008509 }
8510 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
8511 }
8512 }
8513#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
8514
8515 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, pScanReq->scanInterval, NULL, eANI_BOOLEAN_FALSE);
8516 }
8517 else
8518 {
8519 //No need to stop aging because IDLE scan is still running
8520 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, 0, NULL, eANI_BOOLEAN_FALSE);
8521 }
8522
8523 if(pScanReq->SSID.length > WNI_CFG_SSID_LEN)
8524 {
8525 pScanReq->SSID.length = WNI_CFG_SSID_LEN;
8526 }
8527
8528 status = ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pScanReq->ChannelInfo.ChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
8529 status = ccmCfgSetStr(pMac, WNI_CFG_SSID, (tANI_U8 *)pScanReq->SSID.ssId, pScanReq->SSID.length, NULL, eANI_BOOLEAN_FALSE);
8530
8531
8532
8533 return (status);
8534}
8535
8536
c_hpothua3d45d52015-01-05 14:11:17 +05308537tSirAbortScanStatus csrScanAbortMacScan(tpAniSirGlobal pMac,
8538 tANI_U8 sessionId,
8539 eCsrAbortReason reason)
Jeff Johnson295189b2012-06-20 16:38:30 -07008540{
c_hpothua3d45d52015-01-05 14:11:17 +05308541 tSirAbortScanStatus abortScanStatus = eSIR_ABORT_ACTIVE_SCAN_LIST_EMPTY;
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308542 tSirSmeScanAbortReq *pMsg;
Jeff Johnson295189b2012-06-20 16:38:30 -07008543 tANI_U16 msgLen;
8544 tListElem *pEntry;
8545 tSmeCmd *pCommand;
8546
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308547 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07008548 {
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308549#ifdef WLAN_AP_STA_CONCURRENCY
8550 csrLLLock(&pMac->scan.scanCmdPendingList);
8551 while(NULL !=
8552 (pEntry = csrLLRemoveHead(&pMac->scan.scanCmdPendingList,
8553 LL_ACCESS_NOLOCK)))
8554 {
Jeff Johnson295189b2012-06-20 16:38:30 -07008555
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308556 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8557 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
8558 }
8559 csrLLUnlock(&pMac->scan.scanCmdPendingList);
Jeff Johnson295189b2012-06-20 16:38:30 -07008560#endif
8561
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308562 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
8563 csrRemoveCmdFromPendingList( pMac, &pMac->roam.roamCmdPendingList, eSmeCommandScan);
8564 csrRemoveCmdFromPendingList( pMac, &pMac->sme.smeCmdPendingList, eSmeCommandScan);
8565 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
8566
8567 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
8568 }
8569 else
8570 {
8571 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
8572 csrRemoveCmdWithSessionIdFromPendingList(pMac,
8573 sessionId,
8574 &pMac->sme.smeScanCmdPendingList,
8575 eSmeCommandScan);
8576 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
8577
8578 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
8579 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008580
8581 //We need to abort scan only if we are scanning
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308582 if(NULL != pEntry)
Jeff Johnson295189b2012-06-20 16:38:30 -07008583 {
8584 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308585 if(eSmeCommandScan == pCommand->command &&
8586 pCommand->sessionId == sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07008587 {
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308588 msgLen = (tANI_U16)(sizeof(tSirSmeScanAbortReq));
Kiet Lam64c1b492013-07-12 13:56:44 +05308589 pMsg = vos_mem_malloc(msgLen);
8590 if ( NULL == pMsg )
Jeff Johnson295189b2012-06-20 16:38:30 -07008591 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308592 smsLog(pMac, LOGE, FL("Failed to allocate memory for SmeScanAbortReq"));
c_hpothua3d45d52015-01-05 14:11:17 +05308593 abortScanStatus = eSIR_ABORT_SCAN_FAILURE;
Kiet Lam64c1b492013-07-12 13:56:44 +05308594 }
8595 else
8596 {
Ratheesh S Pece1f832015-07-25 15:50:25 +05308597 pCommand->u.scanCmd.abortScanIndication = eCSR_SCAN_ABORT_DEFAULT;
Srinivas, Dasari187ca4e2014-02-07 12:40:09 +05308598 if(reason == eCSR_SCAN_ABORT_DUE_TO_BAND_CHANGE)
8599 {
Ratheesh S Pece1f832015-07-25 15:50:25 +05308600 pCommand->u.scanCmd.abortScanIndication
8601 = eCSR_SCAN_ABORT_DUE_TO_BAND_CHANGE;
Srinivas, Dasari187ca4e2014-02-07 12:40:09 +05308602 }
Kiet Lam64c1b492013-07-12 13:56:44 +05308603 vos_mem_set((void *)pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008604 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_ABORT_IND);
8605 pMsg->msgLen = pal_cpu_to_be16(msgLen);
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308606 pMsg->sessionId = sessionId;
c_hpothua3d45d52015-01-05 14:11:17 +05308607 if (eHAL_STATUS_SUCCESS != palSendMBMessage(pMac->hHdd, pMsg))
8608 {
8609 smsLog(pMac, LOGE,
8610 FL("Failed to post eWNI_SME_SCAN_ABORT_IND"));
8611 abortScanStatus = eSIR_ABORT_SCAN_FAILURE;
Ratheesh S Pece1f832015-07-25 15:50:25 +05308612 pCommand->u.scanCmd.abortScanIndication = 0;
c_hpothua3d45d52015-01-05 14:11:17 +05308613 }
8614 else
8615 {
8616 abortScanStatus = eSIR_ABORT_ACTIVE_SCAN_LIST_NOT_EMPTY;
8617 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008618 }
8619 }
8620 }
8621
c_hpothua3d45d52015-01-05 14:11:17 +05308622 return(abortScanStatus);
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308623}
8624
8625void csrRemoveCmdWithSessionIdFromPendingList(tpAniSirGlobal pMac,
8626 tANI_U8 sessionId,
8627 tDblLinkList *pList,
8628 eSmeCommandType commandType)
8629{
8630 tDblLinkList localList;
8631 tListElem *pEntry;
8632 tSmeCmd *pCommand;
8633 tListElem *pEntryToRemove;
8634
8635 vos_mem_zero(&localList, sizeof(tDblLinkList));
8636 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
8637 {
8638 smsLog(pMac, LOGE, FL(" failed to open list"));
8639 return;
8640 }
8641
8642 csrLLLock(pList);
8643 if ((pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK)))
8644 {
8645
8646 /* Have to make sure we don't loop back to the head of the list,
8647 * which will happen if the entry is NOT on the list */
8648 while (pEntry)
8649 {
8650 pEntryToRemove = pEntry;
8651 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
8652 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
8653 if ((pCommand->command == commandType) &&
8654 (pCommand->sessionId == sessionId))
8655 {
8656 /* Remove that entry only */
8657 if (csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
8658 {
8659 csrLLInsertTail(&localList, pEntryToRemove,
8660 LL_ACCESS_NOLOCK);
8661 }
8662 }
8663 }
8664 }
8665 csrLLUnlock(pList);
8666
8667 while ((pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)))
8668 {
8669 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
8670 csrAbortCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
8671 }
8672
8673 csrLLClose(&localList);
Jeff Johnson295189b2012-06-20 16:38:30 -07008674}
8675
8676void csrRemoveCmdFromPendingList(tpAniSirGlobal pMac, tDblLinkList *pList,
8677 eSmeCommandType commandType )
8678{
8679 tDblLinkList localList;
8680 tListElem *pEntry;
8681 tSmeCmd *pCommand;
8682 tListElem *pEntryToRemove;
8683
8684 vos_mem_zero(&localList, sizeof(tDblLinkList));
8685 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
8686 {
8687 smsLog(pMac, LOGE, FL(" failed to open list"));
8688 return;
8689 }
8690
8691 csrLLLock(pList);
8692 if( !csrLLIsListEmpty( pList, LL_ACCESS_NOLOCK ) )
8693 {
8694 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK);
8695
8696 // Have to make sure we don't loop back to the head of the list, which will
8697 // happen if the entry is NOT on the list...
8698 while( pEntry )
8699 {
8700 pEntryToRemove = pEntry;
8701 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
8702 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
8703 if ( pCommand->command == commandType )
8704 {
8705 // Remove that entry only
8706 if(csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
8707 {
8708 csrLLInsertTail(&localList, pEntryToRemove, LL_ACCESS_NOLOCK);
8709 }
8710 }
8711 }
8712
8713
8714 }
8715 csrLLUnlock(pList);
8716
8717 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
8718 {
8719 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8720 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
8721 }
8722 csrLLClose(&localList);
8723
8724}
8725
Abhishek Singhdc2bfd42014-06-19 17:59:05 +05308726eHalStatus csrScanAbortScanForSSID(tpAniSirGlobal pMac, tANI_U32 sessionId)
8727{
8728 eHalStatus status = eHAL_STATUS_SUCCESS;
8729 tSirSmeScanAbortReq *pMsg;
8730 tANI_U16 msgLen;
8731 tListElem *pEntry;
8732 tSmeCmd *pCommand;
8733
8734 if (!pMac->fScanOffload)
8735 {
8736 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
8737#ifdef WLAN_AP_STA_CONCURRENCY
8738 csrRemoveScanForSSIDFromPendingList( pMac, &pMac->scan.scanCmdPendingList, sessionId);
8739#endif
8740 csrRemoveScanForSSIDFromPendingList( pMac, &pMac->roam.roamCmdPendingList, sessionId);
8741 csrRemoveScanForSSIDFromPendingList( pMac, &pMac->sme.smeCmdPendingList, sessionId);
8742 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
8743 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
8744 }
8745 else
8746 {
8747 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
8748 csrRemoveScanForSSIDFromPendingList( pMac, &pMac->sme.smeScanCmdPendingList, sessionId);
8749 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
8750 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
8751 }
8752
8753 if(NULL != pEntry)
8754 {
8755 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8756
8757 if ( (eSmeCommandScan == pCommand->command ) &&
8758 (sessionId == pCommand->sessionId))
8759 {
8760 if ( eCsrScanForSsid == pCommand->u.scanCmd.reason)
8761 {
8762 msgLen = (tANI_U16)(sizeof( tSirSmeScanAbortReq ));
8763 pMsg = vos_mem_malloc(msgLen);
8764 if ( NULL == pMsg )
8765 {
8766 status = eHAL_STATUS_FAILURE;
8767 smsLog(pMac, LOGE, FL("Failed to allocate memory for SmeScanAbortReq"));
8768 }
8769 else
8770 {
8771 vos_mem_zero((void *)pMsg, msgLen);
8772 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_ABORT_IND);
8773 pMsg->msgLen = pal_cpu_to_be16(msgLen);
8774 pMsg->sessionId = sessionId;
8775 status = palSendMBMessage(pMac->hHdd, pMsg);
8776 }
8777 }
8778 }
8779 }
8780 return( status );
8781}
8782
8783void csrRemoveScanForSSIDFromPendingList(tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 sessionId)
8784{
8785 tDblLinkList localList;
8786 tListElem *pEntry;
8787 tSmeCmd *pCommand;
8788 tListElem *pEntryToRemove;
8789
8790 vos_mem_zero(&localList, sizeof(tDblLinkList));
8791 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
8792 {
8793 smsLog(pMac, LOGE, FL(" failed to open list"));
8794 return;
8795 }
8796
8797 csrLLLock(pList);
8798 if( !csrLLIsListEmpty( pList, LL_ACCESS_NOLOCK ) )
8799 {
8800 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK);
8801
8802 // Have to make sure we don't loop back to the head of the list, which will
8803 // happen if the entry is NOT on the list...
8804 while( pEntry )
8805 {
8806 pEntryToRemove = pEntry;
8807 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
8808 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
8809 if ( (eSmeCommandScan == pCommand->command ) &&
8810 (sessionId == pCommand->sessionId) )
8811 {
8812 if ( eCsrScanForSsid == pCommand->u.scanCmd.reason)
8813 {
8814 // Remove that entry only
8815 if ( csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
8816 {
8817 csrLLInsertTail(&localList, pEntryToRemove, LL_ACCESS_NOLOCK);
8818 }
8819 }
8820 }
8821 }
8822 }
8823 csrLLUnlock(pList);
8824
8825 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
8826 {
8827 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8828 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
8829 }
8830 csrLLClose(&localList);
8831}
Jeff Johnson295189b2012-06-20 16:38:30 -07008832
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308833eHalStatus csrScanAbortMacScanNotForConnect(tpAniSirGlobal pMac,
8834 tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07008835{
8836 eHalStatus status = eHAL_STATUS_SUCCESS;
8837
8838 if( !csrIsScanForRoamCommandActive( pMac ) )
8839 {
8840 //Only abort the scan if it is not used for other roam/connect purpose
c_hpothua3d45d52015-01-05 14:11:17 +05308841 if (eSIR_ABORT_SCAN_FAILURE ==
8842 csrScanAbortMacScan(pMac, sessionId, eCSR_SCAN_ABORT_DEFAULT))
8843 {
8844 smsLog(pMac, LOGE, FL("fail to abort scan"));
8845 status = eHAL_STATUS_FAILURE;
8846 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008847 }
8848
8849 return (status);
8850}
8851
8852
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05308853eHalStatus csrScanGetScanChannelInfo(tpAniSirGlobal pMac, tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07008854{
8855 eHalStatus status = eHAL_STATUS_SUCCESS;
8856 tSirMbMsg *pMsg;
8857 tANI_U16 msgLen;
8858
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05308859 if (pMac->fScanOffload)
8860 msgLen = (tANI_U16)(sizeof(tSirSmeGetScanChanReq));
8861 else
8862 msgLen = (tANI_U16)(sizeof(tSirMbMsg));
8863
Kiet Lam64c1b492013-07-12 13:56:44 +05308864 pMsg = vos_mem_malloc(msgLen);
8865 if ( NULL == pMsg )
8866 status = eHAL_STATUS_FAILURE;
8867 else
Jeff Johnson295189b2012-06-20 16:38:30 -07008868 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308869 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008870 pMsg->type = eWNI_SME_GET_SCANNED_CHANNEL_REQ;
8871 pMsg->msgLen = msgLen;
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05308872 if (pMac->fScanOffload)
8873 ((tSirSmeGetScanChanReq *)pMsg)->sessionId = sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07008874 status = palSendMBMessage(pMac->hHdd, pMsg);
8875 }
8876
8877 return( status );
8878}
8879
8880tANI_BOOLEAN csrRoamIsValidChannel( tpAniSirGlobal pMac, tANI_U8 channel )
8881{
8882 tANI_BOOLEAN fValid = FALSE;
8883 tANI_U32 idxValidChannels;
8884 tANI_U32 len = pMac->roam.numValidChannels;
8885
8886 for ( idxValidChannels = 0; ( idxValidChannels < len ); idxValidChannels++ )
8887 {
8888 if ( channel == pMac->roam.validChannelList[ idxValidChannels ] )
8889 {
8890 fValid = TRUE;
8891 break;
8892 }
8893 }
8894
8895 return fValid;
8896}
8897
Manjunathappa Prakash4f1d5a52013-11-11 16:22:19 -08008898#ifdef FEATURE_WLAN_SCAN_PNO
Srikant Kuppa066904f2013-05-07 13:56:02 -07008899eHalStatus csrScanSavePreferredNetworkFound(tpAniSirGlobal pMac,
8900 tSirPrefNetworkFoundInd *pPrefNetworkFoundInd)
8901{
8902 v_U32_t uLen = 0;
8903 tpSirProbeRespBeacon pParsedFrame;
8904 tCsrScanResult *pScanResult = NULL;
8905 tSirBssDescription *pBssDescr = NULL;
8906 tANI_BOOLEAN fDupBss;
8907 tDot11fBeaconIEs *pIesLocal = NULL;
8908 tAniSSID tmpSsid;
8909 v_TIME_t timer=0;
8910 tpSirMacMgmtHdr macHeader = (tpSirMacMgmtHdr)pPrefNetworkFoundInd->data;
Abhishek Singhd3d4e022014-11-11 13:02:40 +05308911 boolean bFoundonAppliedChannel = FALSE;
8912 v_U32_t indx;
8913 u8 channelsAllowed[WNI_CFG_VALID_CHANNEL_LIST_LEN];
8914 v_U32_t numChannelsAllowed = WNI_CFG_VALID_CHANNEL_LIST_LEN;
Sushant Kaushik6274de62015-05-01 16:31:23 +05308915 tListElem *pEntry;
Abhishek Singhd3d4e022014-11-11 13:02:40 +05308916
Srikant Kuppa066904f2013-05-07 13:56:02 -07008917
8918 pParsedFrame =
Abhishek Singhc75726d2015-04-13 14:44:14 +05308919 (tpSirProbeRespBeacon)vos_mem_vmalloc(sizeof(tSirProbeRespBeacon));
Srikant Kuppa066904f2013-05-07 13:56:02 -07008920
8921 if (NULL == pParsedFrame)
8922 {
8923 smsLog(pMac, LOGE, FL(" fail to allocate memory for frame"));
8924 return eHAL_STATUS_RESOURCES;
8925 }
8926
8927 if ( pPrefNetworkFoundInd->frameLength <= SIR_MAC_HDR_LEN_3A )
8928 {
8929 smsLog(pMac, LOGE,
8930 FL("Not enough bytes in PNO indication probe resp frame! length=%d"),
8931 pPrefNetworkFoundInd->frameLength);
Abhishek Singhc75726d2015-04-13 14:44:14 +05308932 vos_mem_vfree(pParsedFrame);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008933 return eHAL_STATUS_FAILURE;
8934 }
8935
8936 if (sirConvertProbeFrame2Struct(pMac,
8937 &pPrefNetworkFoundInd->data[SIR_MAC_HDR_LEN_3A],
8938 pPrefNetworkFoundInd->frameLength - SIR_MAC_HDR_LEN_3A,
8939 pParsedFrame) != eSIR_SUCCESS ||
8940 !pParsedFrame->ssidPresent)
8941 {
8942 smsLog(pMac, LOGE,
8943 FL("Parse error ProbeResponse, length=%d"),
8944 pPrefNetworkFoundInd->frameLength);
Abhishek Singhc75726d2015-04-13 14:44:14 +05308945 vos_mem_vfree(pParsedFrame);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008946 return eHAL_STATUS_FAILURE;
8947 }
8948 //24 byte MAC header and 12 byte to ssid IE
8949 if (pPrefNetworkFoundInd->frameLength >
8950 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET))
8951 {
8952 uLen = pPrefNetworkFoundInd->frameLength -
8953 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET);
8954 }
8955
Kiet Lam64c1b492013-07-12 13:56:44 +05308956 pScanResult = vos_mem_malloc(sizeof(tCsrScanResult) + uLen);
8957 if ( NULL == pScanResult )
Srikant Kuppa066904f2013-05-07 13:56:02 -07008958 {
8959 smsLog(pMac, LOGE, FL(" fail to allocate memory for frame"));
8960 vos_mem_free(pParsedFrame);
8961 return eHAL_STATUS_RESOURCES;
8962 }
8963
Kiet Lam64c1b492013-07-12 13:56:44 +05308964 vos_mem_set(pScanResult, sizeof(tCsrScanResult) + uLen, 0);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008965 pBssDescr = &pScanResult->Result.BssDescriptor;
8966 /**
8967 * Length of BSS desription is without length of
8968 * length itself and length of pointer
8969 * that holds the next BSS description
8970 */
8971 pBssDescr->length = (tANI_U16)(
8972 sizeof(tSirBssDescription) - sizeof(tANI_U16) -
8973 sizeof(tANI_U32) + uLen);
8974 if (pParsedFrame->dsParamsPresent)
8975 {
8976 pBssDescr->channelId = pParsedFrame->channelNumber;
8977 }
8978 else if (pParsedFrame->HTInfo.present)
8979 {
8980 pBssDescr->channelId = pParsedFrame->HTInfo.primaryChannel;
8981 }
8982 else
8983 {
Mahesh A Saptasagaradd99792014-03-26 16:04:20 +05308984 /**
8985 * If Probe Responce received in PNO indication does not
8986 * contain DSParam IE or HT Info IE then add dummy channel
8987 * to the received BSS info so that Scan result received as
8988 * a part of PNO is updated to the supplicant. Specially
8989 * applicable in case of AP configured in 11A only mode.
8990 */
8991 if ((pMac->roam.configParam.bandCapability == eCSR_BAND_ALL) ||
8992 (pMac->roam.configParam.bandCapability == eCSR_BAND_24))
8993 {
8994 pBssDescr->channelId = 1;
8995 }
8996 else if(pMac->roam.configParam.bandCapability == eCSR_BAND_5G)
8997 {
8998 pBssDescr->channelId = 36;
8999 }
Abhishek Singhd3d4e022014-11-11 13:02:40 +05309000 /* Restrict the logic to ignore the pno indication for invalid channel
9001 * only if valid channel info is present in beacon/probe resp.
9002 * If no channel info is present in beacon/probe resp, always process
9003 * the pno indication.
9004 */
9005 bFoundonAppliedChannel = TRUE;
9006 }
9007
9008 if (0 != sme_GetCfgValidChannels(pMac, channelsAllowed, &numChannelsAllowed))
9009 {
9010 smsLog(pMac, LOGE, FL(" sme_GetCfgValidChannels failed "));
9011 csrFreeScanResultEntry(pMac, pScanResult);
Abhishek Singhc75726d2015-04-13 14:44:14 +05309012 vos_mem_vfree(pParsedFrame);
Abhishek Singhd3d4e022014-11-11 13:02:40 +05309013 return eHAL_STATUS_FAILURE;
9014 }
9015 /* Checking chhanelId with allowed channel list */
9016 for (indx = 0; indx < numChannelsAllowed; indx++)
9017 {
9018 if (pBssDescr->channelId == channelsAllowed[indx])
9019 {
9020 bFoundonAppliedChannel = TRUE;
9021 smsLog(pMac, LOG1, FL(" pno ind found on applied channel =%d\n "),
9022 pBssDescr->channelId);
9023 break;
9024 }
9025 }
9026 /* Ignore PNO indication if AP is on Invalid channel.
9027 */
9028 if(FALSE == bFoundonAppliedChannel)
9029 {
9030 smsLog(pMac, LOGW, FL(" prefered network found on invalid channel = %d"),
9031 pBssDescr->channelId);
9032 csrFreeScanResultEntry(pMac, pScanResult);
Abhishek Singhc75726d2015-04-13 14:44:14 +05309033 vos_mem_vfree(pParsedFrame);
Abhishek Singhd3d4e022014-11-11 13:02:40 +05309034 return eHAL_STATUS_FAILURE;
Srikant Kuppa066904f2013-05-07 13:56:02 -07009035 }
9036
9037 if ((pBssDescr->channelId > 0) && (pBssDescr->channelId < 15))
9038 {
9039 int i;
9040 // 11b or 11g packet
9041 // 11g iff extended Rate IE is present or
9042 // if there is an A rate in suppRate IE
9043 for (i = 0; i < pParsedFrame->supportedRates.numRates; i++)
9044 {
9045 if (sirIsArate(pParsedFrame->supportedRates.rate[i] & 0x7f))
9046 {
9047 pBssDescr->nwType = eSIR_11G_NW_TYPE;
9048 break;
9049 }
9050 }
9051 if (pParsedFrame->extendedRatesPresent)
9052 {
9053 pBssDescr->nwType = eSIR_11G_NW_TYPE;
9054 }
9055 }
9056 else
9057 {
9058 // 11a packet
9059 pBssDescr->nwType = eSIR_11A_NW_TYPE;
9060 }
9061
9062 pBssDescr->sinr = 0;
9063 pBssDescr->rssi = -1 * pPrefNetworkFoundInd->rssi;
9064 pBssDescr->beaconInterval = pParsedFrame->beaconInterval;
AnjaneeDevi Kapparapu4b043912014-02-18 13:22:35 +05309065 if (!pBssDescr->beaconInterval)
9066 {
9067 smsLog(pMac, LOGW,
9068 FL("Bcn Interval is Zero , default to 100" MAC_ADDRESS_STR),
9069 MAC_ADDR_ARRAY(pBssDescr->bssId) );
9070 pBssDescr->beaconInterval = 100;
9071 }
Srikant Kuppa066904f2013-05-07 13:56:02 -07009072 pBssDescr->timeStamp[0] = pParsedFrame->timeStamp[0];
9073 pBssDescr->timeStamp[1] = pParsedFrame->timeStamp[1];
9074 pBssDescr->capabilityInfo = *((tANI_U16 *)&pParsedFrame->capabilityInfo);
Kiet Lam64c1b492013-07-12 13:56:44 +05309075 vos_mem_copy((tANI_U8 *) &pBssDescr->bssId, (tANI_U8 *) macHeader->bssId, sizeof(tSirMacAddr));
Deepthi Gowri4480a3f2016-05-18 19:30:17 +05309076 pBssDescr->nReceivedTime = vos_timer_get_system_time();
Srikant Kuppa066904f2013-05-07 13:56:02 -07009077
Abhishek Singh195c03e2014-05-14 17:21:30 +05309078 smsLog( pMac, LOG1, FL("Bssid= "MAC_ADDRESS_STR
9079 " chan= %d, rssi = %d "),
Arif Hussain24bafea2013-11-15 15:10:03 -08009080 MAC_ADDR_ARRAY(pBssDescr->bssId),
Srikant Kuppa066904f2013-05-07 13:56:02 -07009081 pBssDescr->channelId,
Abhishek Singh195c03e2014-05-14 17:21:30 +05309082 pBssDescr->rssi);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009083
9084 //IEs
9085 if (uLen)
9086 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309087 vos_mem_copy(&pBssDescr->ieFields,
9088 pPrefNetworkFoundInd->data + (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET),
9089 uLen);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009090 }
9091
9092 pIesLocal = (tDot11fBeaconIEs *)( pScanResult->Result.pvIes );
9093 if ( !pIesLocal &&
9094 (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
9095 &pScanResult->Result.BssDescriptor, &pIesLocal))) )
9096 {
9097 smsLog(pMac, LOGE, FL(" Cannot parse IEs"));
9098 csrFreeScanResultEntry(pMac, pScanResult);
Abhishek Singhc75726d2015-04-13 14:44:14 +05309099 vos_mem_vfree(pParsedFrame);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009100 return eHAL_STATUS_RESOURCES;
9101 }
9102
9103 fDupBss = csrRemoveDupBssDescription( pMac,
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05309104 &pScanResult->Result.BssDescriptor, pIesLocal, &tmpSsid, &timer, FALSE);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009105 //Check whether we have reach out limit
9106 if ( CSR_SCAN_IS_OVER_BSS_LIMIT(pMac) )
9107 {
9108 //Limit reach
9109 smsLog(pMac, LOGE, FL(" BSS limit reached"));
9110 //Free the resources
9111 if( (pScanResult->Result.pvIes == NULL) && pIesLocal )
9112 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309113 vos_mem_free(pIesLocal);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009114 }
9115 csrFreeScanResultEntry(pMac, pScanResult);
9116 vos_mem_free(pParsedFrame);
9117 return eHAL_STATUS_RESOURCES;
9118 }
Nalla Kartheek71946422015-09-15 14:41:22 +05309119
9120 if ((macHeader->fc.type == SIR_MAC_MGMT_FRAME) &&
9121 (macHeader->fc.subType == SIR_MAC_MGMT_PROBE_RSP))
9122 {
9123 pScanResult->Result.BssDescriptor.fProbeRsp = 1;
9124 }
Srikant Kuppa066904f2013-05-07 13:56:02 -07009125 //Add to scan cache
9126 csrScanAddResult(pMac, pScanResult, pIesLocal);
Sushant Kaushik6274de62015-05-01 16:31:23 +05309127 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
Kiet Lamb537cfb2013-11-07 12:56:49 +05309128 if( (pScanResult->Result.pvIes == NULL) && pIesLocal )
9129 {
9130 vos_mem_free(pIesLocal);
9131 }
9132
Abhishek Singhc75726d2015-04-13 14:44:14 +05309133 vos_mem_vfree(pParsedFrame);
Srikant Kuppa066904f2013-05-07 13:56:02 -07009134
9135 return eHAL_STATUS_SUCCESS;
9136}
Manjunathappa Prakash4f1d5a52013-11-11 16:22:19 -08009137#endif //FEATURE_WLAN_SCAN_PNO
Srikant Kuppa066904f2013-05-07 13:56:02 -07009138
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08009139#ifdef FEATURE_WLAN_LFR
9140void csrInitOccupiedChannelsList(tpAniSirGlobal pMac)
9141{
9142 tListElem *pEntry = NULL;
9143 tCsrScanResult *pBssDesc = NULL;
9144 tDot11fBeaconIEs *pIes = NULL;
Srinivas28b5b4e2012-12-12 13:07:53 -08009145 tpCsrNeighborRoamControlInfo pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
9146
9147 if (0 != pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels)
9148 {
9149 smsLog(pMac, LOG1, FL("%s: Ini file contains neighbor scan channel list,"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08009150 " hence NO need to build occupied channel list (numChannels = %d)"),
Srinivas28b5b4e2012-12-12 13:07:53 -08009151 __func__, pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels);
9152 return;
9153 }
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08009154
9155 if (!csrNeighborRoamIsNewConnectedProfile(pMac))
9156 {
9157 smsLog(pMac, LOG2, FL("%s: donot flush occupied list since current roam profile"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08009158 " matches previous (numChannels = %d)"),
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08009159 __func__, pMac->scan.occupiedChannels.numChannels);
9160 return;
9161 }
9162
9163 /* Empty occupied channels here */
9164 pMac->scan.occupiedChannels.numChannels = 0;
9165
9166 csrLLLock(&pMac->scan.scanResultList);
9167 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
9168 while( pEntry )
9169 {
9170 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
9171 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
9172
9173 //At this time, pBssDescription->Result.pvIes may be NULL
Srikant Kuppa866893f2012-12-27 17:28:14 -08009174 if( !pIes && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08009175 &pBssDesc->Result.BssDescriptor, &pIes))) )
9176 {
9177 continue;
9178 }
9179
9180 csrScanAddToOccupiedChannels(pMac, pBssDesc, &pMac->scan.occupiedChannels, pIes);
9181
9182 /*
9183 * Free the memory allocated for pIes in csrGetParsedBssDescriptionIEs
9184 */
9185 if( (pBssDesc->Result.pvIes == NULL) && pIes )
9186 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309187 vos_mem_free(pIes);
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08009188 }
9189
9190 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK );
9191 }//while
9192 csrLLUnlock(&pMac->scan.scanResultList);
Srikant Kuppa866893f2012-12-27 17:28:14 -08009193
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08009194}
9195#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07009196
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009197eHalStatus csrScanCreateEntryInScanCache(tpAniSirGlobal pMac, tANI_U32 sessionId,
9198 tCsrBssid bssid, tANI_U8 channel)
9199{
9200 eHalStatus status = eHAL_STATUS_SUCCESS;
9201 tDot11fBeaconIEs *pNewIes = NULL;
9202 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
Praveen Kumar Sirisilla8bdfac42013-10-10 17:20:48 -07009203 tSirBssDescription *pNewBssDescriptor = NULL;
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009204 tANI_U32 size = 0;
9205
9206 if(NULL == pSession)
9207 {
9208 status = eHAL_STATUS_FAILURE;
9209 return status;
9210 }
9211 smsLog(pMac, LOG2, FL("csrScanCreateEntryInScanCache: Current bssid::"
Arif Hussain24bafea2013-11-15 15:10:03 -08009212 MAC_ADDRESS_STR),
9213 MAC_ADDR_ARRAY(pSession->pConnectBssDesc->bssId));
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009214 smsLog(pMac, LOG2, FL("csrScanCreateEntryInScanCache: My bssid::"
Arif Hussain24bafea2013-11-15 15:10:03 -08009215 MAC_ADDRESS_STR" channel %d"),
9216 MAC_ADDR_ARRAY(bssid), channel);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009217
9218 do
9219 {
9220 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
9221 pSession->pConnectBssDesc, &pNewIes)))
9222 {
9223 smsLog(pMac, LOGE, FL("%s: Failed to parse IEs"),
9224 __func__);
9225 status = eHAL_STATUS_FAILURE;
9226 break;
9227 }
9228
9229 size = pSession->pConnectBssDesc->length + sizeof(pSession->pConnectBssDesc->length);
Kiet Lam64c1b492013-07-12 13:56:44 +05309230 if (size)
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009231 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309232 pNewBssDescriptor = vos_mem_malloc(size);
9233 if ( NULL == pNewBssDescriptor )
9234 status = eHAL_STATUS_FAILURE;
9235 else
9236 status = eHAL_STATUS_SUCCESS;
9237 if (HAL_STATUS_SUCCESS(status))
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009238 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309239 vos_mem_copy(pNewBssDescriptor, pSession->pConnectBssDesc, size);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009240 }
9241 else
9242 {
9243 smsLog(pMac, LOGE, FL("%s: memory allocation failed"),
9244 __func__);
9245 status = eHAL_STATUS_FAILURE;
9246 break;
9247 }
9248
9249 //change the BSSID & channel as passed
Kiet Lam64c1b492013-07-12 13:56:44 +05309250 vos_mem_copy(pNewBssDescriptor->bssId, bssid, sizeof(tSirMacAddr));
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009251 pNewBssDescriptor->channelId = channel;
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07009252 if(NULL == csrScanAppendBssDescription( pMac, pNewBssDescriptor, pNewIes, TRUE ))
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009253 {
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07009254 smsLog(pMac, LOGE, FL("%s: csrScanAppendBssDescription failed"),
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009255 __func__);
9256 status = eHAL_STATUS_FAILURE;
9257 break;
9258 }
9259 }
9260 else
9261 {
9262 smsLog(pMac, LOGE, FL("%s: length of bss descriptor is 0"),
9263 __func__);
9264 status = eHAL_STATUS_FAILURE;
9265 break;
9266 }
9267 smsLog(pMac, LOGE, FL("%s: entry successfully added in scan cache"),
9268 __func__);
9269 }while(0);
9270
9271 if(pNewIes)
9272 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309273 vos_mem_free(pNewIes);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009274 }
9275 if(pNewBssDescriptor)
9276 {
Kiet Lam64c1b492013-07-12 13:56:44 +05309277 vos_mem_free(pNewBssDescriptor);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07009278 }
9279 return status;
9280}
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07009281
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08009282#ifdef FEATURE_WLAN_ESE
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07009283// Update the TSF with the difference in system time
9284void UpdateCCKMTSF(tANI_U32 *timeStamp0, tANI_U32 *timeStamp1, tANI_U32 *incr)
9285{
9286 tANI_U64 timeStamp64 = ((tANI_U64)*timeStamp1 << 32) | (*timeStamp0);
9287
9288 timeStamp64 = (tANI_U64)(timeStamp64 + (tANI_U64)*incr);
9289 *timeStamp0 = (tANI_U32)(timeStamp64 & 0xffffffff);
9290 *timeStamp1 = (tANI_U32)((timeStamp64 >> 32) & 0xffffffff);
9291}
9292#endif