blob: 4fb7eea32d907d1962f2046f6614cd9350f444cf [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Siddharth Bhald8a95e82015-02-12 20:14:52 +05302 * Copyright (c) 2012-2015 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
Madan Mohan Koyyalamudia53c4dc2012-11-13 10:35:42 -080093#define CSR_SCAN_OVERALL_SCORE( rssi ) \
94 (( rssi < CSR_SCAN_MAX_SCORE_VAL ) \
95 ? (CSR_SCAN_MAX_SCORE_VAL-rssi) : CSR_SCAN_MIN_SCORE_VAL)
Jeff Johnson295189b2012-06-20 16:38:30 -070096
97
98#define CSR_SCAN_IS_OVER_BSS_LIMIT(pMac) \
99 ( (pMac)->scan.nBssLimit <= (csrLLCount(&(pMac)->scan.scanResultList)) )
100
Sushant Kaushikf4e085e2014-06-17 16:07:33 +0530101#define THIRTY_PERCENT(x) (x*30/100);
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +0530102
krunal soni5f112f02013-11-25 15:00:11 -0800103#define MANDATORY_BG_CHANNEL 11
104
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -0800105#ifndef CONFIG_ENABLE_LINUX_REG
Sushant Kaushikf4e085e2014-06-17 16:07:33 +0530106tCsrIgnoreChannels countryIgnoreList[MAX_COUNTRY_IGNORE] = {
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +0530107 { {'U','A'}, { 136, 140}, 2},
108 { {'T','W'}, { 36, 40, 44, 48, 52}, 5},
Madan Mohan Koyyalamudi28dd0422013-08-12 15:06:21 +0530109 { {'I','D'}, { 165}, 1 },
Wilson Yange3d2b292013-10-09 00:35:43 -0700110 { {'A','U'}, { 120, 124, 128}, 3 },
Wilson Yangce31eaf2013-11-11 14:40:34 -0800111 { {'A','R'}, { 120, 124, 128}, 3 }
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +0530112 };
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -0800113#else
Sushant Kaushikf4e085e2014-06-17 16:07:33 +0530114tCsrIgnoreChannels countryIgnoreList[MAX_COUNTRY_IGNORE] = { };
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -0800115#endif //CONFIG_ENABLE_LINUX_REG
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +0530116
Jeff Johnson295189b2012-06-20 16:38:30 -0700117//*** This is temporary work around. It need to call CCM api to get to CFG later
118/// Get string parameter value
119extern tSirRetStatus wlan_cfgGetStr(tpAniSirGlobal, tANI_U16, tANI_U8*, tANI_U32*);
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +0530120
Jeff Johnson295189b2012-06-20 16:38:30 -0700121void csrScanGetResultTimerHandler(void *);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -0800122static void csrScanResultCfgAgingTimerHandler(void *pv);
Jeff Johnson295189b2012-06-20 16:38:30 -0700123void csrScanIdleScanTimerHandler(void *);
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700124static void csrSetDefaultScanTiming( tpAniSirGlobal pMac, tSirScanType scanType, tCsrScanRequest *pScanRequest);
Jeff Johnson295189b2012-06-20 16:38:30 -0700125#ifdef WLAN_AP_STA_CONCURRENCY
126static void csrStaApConcTimerHandler(void *);
127#endif
Jeff Johnsone7245742012-09-05 17:12:55 -0700128tANI_BOOLEAN csrIsSupportedChannel(tpAniSirGlobal pMac, tANI_U8 channelId);
Jeff Johnson295189b2012-06-20 16:38:30 -0700129eHalStatus csrScanChannels( tpAniSirGlobal pMac, tSmeCmd *pCommand );
130void csrSetCfgValidChannelList( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels );
131void csrSaveTxPowerToCfg( tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 cfgId );
132void csrSetCfgCountryCode( tpAniSirGlobal pMac, tANI_U8 *countryCode );
133void csrPurgeChannelPower( tpAniSirGlobal pMac, tDblLinkList *pChannelList );
134//if bgPeriod is 0, background scan is disabled. It is in millisecond units
135eHalStatus csrSetCfgBackgroundScanPeriod(tpAniSirGlobal pMac, tANI_U32 bgPeriod);
136eHalStatus csrProcessSetBGScanParam(tpAniSirGlobal pMac, tSmeCmd *pCommand);
137void csrReleaseScanCommand(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus);
138static tANI_BOOLEAN csrScanValidateScanResult( tpAniSirGlobal pMac, tANI_U8 *pChannels,
139 tANI_U8 numChn, tSirBssDescription *pBssDesc,
140 tDot11fBeaconIEs **ppIes );
141eHalStatus csrSetBGScanChannelList( tpAniSirGlobal pMac, tANI_U8 *pAdjustChannels, tANI_U8 NumAdjustChannels);
142void csrReleaseCmdSingle(tpAniSirGlobal pMac, tSmeCmd *pCommand);
143tANI_BOOLEAN csrRoamIsValidChannel( tpAniSirGlobal pMac, tANI_U8 channel );
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700144void csrPruneChannelListForMode( tpAniSirGlobal pMac, tCsrChannel *pChannelList );
Jeff Johnson295189b2012-06-20 16:38:30 -0700145
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -0700146
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -0700147
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -0700148
Madan Mohan Koyyalamudi923c1e12012-11-30 17:53:27 -0800149static void csrReleaseScanCmdPendingList(tpAniSirGlobal pMac)
150{
151 tListElem *pEntry;
152 tSmeCmd *pCommand;
153
154 while((pEntry = csrLLRemoveHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK)) != NULL)
155 {
156 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
157 if ( eSmeCsrCommandMask & pCommand->command )
158 {
159 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_TRUE );
160 }
161 else
162 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800163 smsLog(pMac, LOGE, FL("Error: Received command : %d"),pCommand->command);
Madan Mohan Koyyalamudi923c1e12012-11-30 17:53:27 -0800164 }
165 }
166}
Jeff Johnson295189b2012-06-20 16:38:30 -0700167//pResult is invalid calling this function.
168void csrFreeScanResultEntry( tpAniSirGlobal pMac, tCsrScanResult *pResult )
169{
170 if( NULL != pResult->Result.pvIes )
171 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530172 vos_mem_free(pResult->Result.pvIes);
Jeff Johnson295189b2012-06-20 16:38:30 -0700173 }
Kiet Lam64c1b492013-07-12 13:56:44 +0530174 vos_mem_free(pResult);
Jeff Johnson295189b2012-06-20 16:38:30 -0700175}
176
177
178static eHalStatus csrLLScanPurgeResult(tpAniSirGlobal pMac, tDblLinkList *pList)
179{
180 eHalStatus status = eHAL_STATUS_SUCCESS;
181 tListElem *pEntry;
182 tCsrScanResult *pBssDesc;
183
184 csrLLLock(pList);
185
186 while((pEntry = csrLLRemoveHead(pList, LL_ACCESS_NOLOCK)) != NULL)
187 {
188 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
189 csrFreeScanResultEntry( pMac, pBssDesc );
190 }
191
192 csrLLUnlock(pList);
193
194 return (status);
195}
196
Jeff Johnson295189b2012-06-20 16:38:30 -0700197eHalStatus csrScanOpen( tpAniSirGlobal pMac )
198{
199 eHalStatus status;
200
201 do
202 {
203 csrLLOpen(pMac->hHdd, &pMac->scan.scanResultList);
204 csrLLOpen(pMac->hHdd, &pMac->scan.tempScanResults);
205 csrLLOpen(pMac->hHdd, &pMac->scan.channelPowerInfoList24);
206 csrLLOpen(pMac->hHdd, &pMac->scan.channelPowerInfoList5G);
207#ifdef WLAN_AP_STA_CONCURRENCY
208 csrLLOpen(pMac->hHdd, &pMac->scan.scanCmdPendingList);
209#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700210 pMac->scan.fFullScanIssued = eANI_BOOLEAN_FALSE;
211 pMac->scan.nBssLimit = CSR_MAX_BSS_SUPPORT;
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530212 status = vos_timer_init(&pMac->scan.hTimerGetResult, VOS_TIMER_TYPE_SW, csrScanGetResultTimerHandler, pMac);
213 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700214 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800215 smsLog(pMac, LOGE, FL("cannot allocate memory for getResult timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700216 break;
217 }
218#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530219 status = vos_timer_init(&pMac->scan.hTimerStaApConcTimer, VOS_TIMER_TYPE_SW, csrStaApConcTimerHandler, 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 hTimerStaApConcTimer timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700223 break;
224 }
225#endif
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530226 status = vos_timer_init(&pMac->scan.hTimerIdleScan, VOS_TIMER_TYPE_SW, csrScanIdleScanTimerHandler, 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 idleScan timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700230 break;
231 }
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530232 status = vos_timer_init(&pMac->scan.hTimerResultCfgAging, VOS_TIMER_TYPE_SW,
233 csrScanResultCfgAgingTimerHandler, pMac);
234 if (!HAL_STATUS_SUCCESS(status))
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -0800235 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800236 smsLog(pMac, LOGE, FL("cannot allocate memory for CFG ResultAging timer"));
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -0800237 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.hTimerResultCfgAging);
263 vos_timer_destroy(&pMac->scan.hTimerGetResult);
Jeff Johnson295189b2012-06-20 16:38:30 -0700264#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530265 vos_timer_destroy(&pMac->scan.hTimerStaApConcTimer);
Jeff Johnson295189b2012-06-20 16:38:30 -0700266#endif
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530267 vos_timer_destroy(&pMac->scan.hTimerIdleScan);
Jeff Johnson295189b2012-06-20 16:38:30 -0700268 return eHAL_STATUS_SUCCESS;
269}
270
271
272eHalStatus csrScanEnable( tpAniSirGlobal pMac )
273{
274
275 pMac->scan.fScanEnable = eANI_BOOLEAN_TRUE;
276 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
277
278 return eHAL_STATUS_SUCCESS;
279}
280
281
282eHalStatus csrScanDisable( tpAniSirGlobal pMac )
283{
284
285 csrScanStopTimers(pMac);
286 pMac->scan.fScanEnable = eANI_BOOLEAN_FALSE;
287
288 return eHAL_STATUS_SUCCESS;
289}
290
291
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700292//Set scan timing parameters according to state of other driver sessions
293//No validation of the parameters is performed.
294static void csrSetDefaultScanTiming( tpAniSirGlobal pMac, tSirScanType scanType, tCsrScanRequest *pScanRequest)
295{
296#ifdef WLAN_AP_STA_CONCURRENCY
297 if(csrIsAnySessionConnected(pMac))
298 {
Sushant Kaushika6fef4b2014-09-24 16:17:08 +0530299 //Reset passive scan time as per ini parameter.
Abhishek Singh7fb7dc12014-11-06 17:44:05 +0530300 ccmCfgSetInt(pMac, WNI_CFG_PASSIVE_MAXIMUM_CHANNEL_TIME,
Sushant Kaushika6fef4b2014-09-24 16:17:08 +0530301 pMac->roam.configParam.nPassiveMaxChnTimeConc,
302 NULL,eANI_BOOLEAN_FALSE);
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700303 //If multi-session, use the appropriate default scan times
304 if(scanType == eSIR_ACTIVE_SCAN)
305 {
306 pScanRequest->maxChnTime = pMac->roam.configParam.nActiveMaxChnTimeConc;
307 pScanRequest->minChnTime = pMac->roam.configParam.nActiveMinChnTimeConc;
308 }
309 else
310 {
311 pScanRequest->maxChnTime = pMac->roam.configParam.nPassiveMaxChnTimeConc;
312 pScanRequest->minChnTime = pMac->roam.configParam.nPassiveMinChnTimeConc;
313 }
Kiet Lam64c1b492013-07-12 13:56:44 +0530314 pScanRequest->maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
315 pScanRequest->minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700316
317 pScanRequest->restTime = pMac->roam.configParam.nRestTimeConc;
318
319 //Return so that fields set above will not be overwritten.
320 return;
321 }
322#endif
323
324 //This portion of the code executed if multi-session not supported
325 //(WLAN_AP_STA_CONCURRENCY not defined) or no multi-session.
326 //Use the "regular" (non-concurrency) default scan timing.
Abhishek Singh7fb7dc12014-11-06 17:44:05 +0530327 ccmCfgSetInt(pMac, WNI_CFG_PASSIVE_MAXIMUM_CHANNEL_TIME,
Kaushik, Sushant49758c12014-09-26 11:25:38 +0530328 pMac->roam.configParam.nPassiveMaxChnTime,
329 NULL,eANI_BOOLEAN_FALSE);
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700330 if(pScanRequest->scanType == eSIR_ACTIVE_SCAN)
331 {
332 pScanRequest->maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
333 pScanRequest->minChnTime = pMac->roam.configParam.nActiveMinChnTime;
334 }
335 else
336 {
337 pScanRequest->maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
338 pScanRequest->minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
339 }
Kiet Lam64c1b492013-07-12 13:56:44 +0530340 pScanRequest->maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
341 pScanRequest->minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700342
343#ifdef WLAN_AP_STA_CONCURRENCY
344 //No rest time if no sessions are connected.
345 pScanRequest->restTime = 0;
346#endif
347}
348
Jeff Johnson295189b2012-06-20 16:38:30 -0700349#ifdef WLAN_AP_STA_CONCURRENCY
350//Return SUCCESS is the command is queued, else returns eHAL_STATUS_FAILURE
351eHalStatus csrQueueScanRequest( tpAniSirGlobal pMac, tSmeCmd *pScanCmd )
352{
353 eHalStatus status = eHAL_STATUS_SUCCESS;
354
355 tANI_BOOLEAN fNoCmdPending;
356 tSmeCmd *pQueueScanCmd=NULL;
357 tSmeCmd *pSendScanCmd=NULL;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700358 tANI_U8 nNumChanCombinedConc = 0;
Gopichand Nakkala114718f2013-03-25 19:19:46 -0700359 if (NULL == pScanCmd)
360 {
361 smsLog (pMac, LOGE, FL("Scan Req cmd is NULL"));
362 return eHAL_STATUS_FAILURE;
363 }
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -0800364 /* split scan if any one of the following:
365 * - STA session is connected and the scan is not a P2P search
366 * - any P2P session is connected
Srikant Kuppa866893f2012-12-27 17:28:14 -0800367 * Do not split scans if no concurrent infra connections are
368 * active and if the scan is a BG scan triggered by LFR (OR)
369 * any scan if LFR is in the middle of a BG scan. Splitting
370 * the scan is delaying the time it takes for LFR to find
371 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -0800372 */
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700373
374 if(csrIsStaSessionConnected(pMac) &&
375 !csrIsP2pSessionConnected(pMac))
376 {
377 nNumChanCombinedConc = pMac->roam.configParam.nNumStaChanCombinedConc;
378 }
379 else if(csrIsP2pSessionConnected(pMac))
380 {
381 nNumChanCombinedConc = pMac->roam.configParam.nNumP2PChanCombinedConc;
382 }
Srikant Kuppa866893f2012-12-27 17:28:14 -0800383 if ( (csrIsStaSessionConnected(pMac) &&
384#ifdef FEATURE_WLAN_LFR
385 (csrIsConcurrentInfraConnected(pMac) ||
386 ((pScanCmd->u.scanCmd.reason != eCsrScanBgScan) &&
387 (pMac->roam.neighborRoamInfo.neighborRoamState !=
388 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
389#endif
390 (pScanCmd->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Vinay Malekal05fdc812012-12-17 13:04:30 -0800391 (csrIsP2pSessionConnected(pMac)) )
Jeff Johnson295189b2012-06-20 16:38:30 -0700392 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700393 tCsrScanRequest scanReq;
394 tANI_U8 numChn = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
395 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
396 tANI_U8 channelToScan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
Jeff Johnson295189b2012-06-20 16:38:30 -0700397 tANI_BOOLEAN bMemAlloc = eANI_BOOLEAN_FALSE;
398
399 if (numChn == 0)
400 {
401
402 numChn = pMac->scan.baseChannels.numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -0700403
Kiet Lam64c1b492013-07-12 13:56:44 +0530404 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(numChn);
405 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -0700406 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800407 smsLog( pMac, LOGE, FL(" Failed to get memory for channel list ") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800408 return eHAL_STATUS_FAILURE;
409 }
410 bMemAlloc = eANI_BOOLEAN_TRUE;
Kiet Lam64c1b492013-07-12 13:56:44 +0530411 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
412 pMac->scan.baseChannels.channelList, numChn);
413 status = eHAL_STATUS_SUCCESS;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800414 if( !HAL_STATUS_SUCCESS( status ) )
415 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530416 vos_mem_free(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800417 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800418 smsLog( pMac, LOGE, FL(" Failed to copy memory to channel list ") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800419 return eHAL_STATUS_FAILURE;
420 }
421 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = numChn;
422 }
Sushant Kaushik826de802014-05-08 18:04:11 +0530423 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
424 "%s: Total Number of channels to scan : %d "
425 "Splitted in group of %d ", __func__, numChn,
426 nNumChanCombinedConc);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800427 //Whenever we get a scan request with multiple channels we break it up into 2 requests
428 //First request for first channel to scan and second request to scan remaining channels
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700429 if ( numChn > nNumChanCombinedConc)
Vinay Malekal05fdc812012-12-17 13:04:30 -0800430 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530431 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800432
433 pQueueScanCmd = csrGetCommandBuffer(pMac); //optimize this to use 2 command buffer only
434 if (!pQueueScanCmd)
435 {
436 if (bMemAlloc)
Jeff Johnson295189b2012-06-20 16:38:30 -0700437 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530438 vos_mem_free(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800439 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
440
Jeff Johnson295189b2012-06-20 16:38:30 -0700441 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800442 smsLog( pMac, LOGE, FL(" Failed to get Queue command buffer") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800443 return eHAL_STATUS_FAILURE;
444 }
445 pQueueScanCmd->command = pScanCmd->command;
446 pQueueScanCmd->sessionId = pScanCmd->sessionId;
447 pQueueScanCmd->u.scanCmd.callback = pScanCmd->u.scanCmd.callback;
448 pQueueScanCmd->u.scanCmd.pContext = pScanCmd->u.scanCmd.pContext;
449 pQueueScanCmd->u.scanCmd.reason = pScanCmd->u.scanCmd.reason;
450 pQueueScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Jeff Johnson295189b2012-06-20 16:38:30 -0700451
Vinay Malekal05fdc812012-12-17 13:04:30 -0800452 /* First copy all the parameters to local variable of scan request */
453 csrScanCopyRequest(pMac, &scanReq, &pScanCmd->u.scanCmd.u.scanRequest);
Madan Mohan Koyyalamudiaf2a8b92012-10-09 14:58:07 -0700454
Vinay Malekal05fdc812012-12-17 13:04:30 -0800455 /* Now modify the elements of local var scan request required to be modified for split scan */
456 if(scanReq.ChannelInfo.ChannelList != NULL)
457 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530458 vos_mem_free(scanReq.ChannelInfo.ChannelList);
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -0800459 scanReq.ChannelInfo.ChannelList = NULL;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800460 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700461
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700462 pChnInfo->numOfChannels = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels - nNumChanCombinedConc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700463
Vinay Malekal05fdc812012-12-17 13:04:30 -0800464 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_WARN,
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +0530465 FL(" &channelToScan %p pScanCmd(%p) pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList(%p)numChn(%d)"),
466 &channelToScan[0], pScanCmd,
467 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList, numChn);
Jeff Johnson295189b2012-06-20 16:38:30 -0700468
Kiet Lam64c1b492013-07-12 13:56:44 +0530469 vos_mem_copy(&channelToScan[0],
470 &pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[
471 nNumChanCombinedConc],
472 pChnInfo->numOfChannels * sizeof(tANI_U8));
Vinay Malekal05fdc812012-12-17 13:04:30 -0800473
474 pChnInfo->ChannelList = &channelToScan[0];
475
476 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
c_hpothudbefd3e2014-04-28 15:59:47 +0530477
Vinay Malekal05fdc812012-12-17 13:04:30 -0800478 //Use concurrency values for min/maxChnTime.
479 //We know csrIsAnySessionConnected(pMac) returns TRUE here
480 csrSetDefaultScanTiming(pMac, scanReq.scanType, &scanReq);
481
482 status = csrScanCopyRequest(pMac, &pQueueScanCmd->u.scanCmd.u.scanRequest, &scanReq);
483
484 if(!HAL_STATUS_SUCCESS(status))
485 {
486 if (bMemAlloc)
487 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530488 vos_mem_free(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800489 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
490
491 }
492 if( scanReq.pIEField != NULL)
493 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530494 vos_mem_free(scanReq.pIEField);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800495 scanReq.pIEField = NULL;
496 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800497 smsLog( pMac, LOGE, FL(" Failed to get copy csrScanRequest = %d"), status );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800498 return eHAL_STATUS_FAILURE;
499 }
500 /* Clean the local scan variable */
501 scanReq.ChannelInfo.ChannelList = NULL;
502 scanReq.ChannelInfo.numOfChannels = 0;
503 csrScanFreeRequest(pMac, &scanReq);
504
505 /* setup the command to scan 2 channels */
506 pSendScanCmd = pScanCmd;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700507 pSendScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nNumChanCombinedConc;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800508 pSendScanCmd->u.scanCmd.u.scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
c_hpothudbefd3e2014-04-28 15:59:47 +0530509
Vinay Malekal05fdc812012-12-17 13:04:30 -0800510 //Use concurrency values for min/maxChnTime.
511 //We know csrIsAnySessionConnected(pMac) returns TRUE here
512 csrSetDefaultScanTiming(pMac, pSendScanCmd->u.scanCmd.u.scanRequest.scanType, &pSendScanCmd->u.scanCmd.u.scanRequest);
513 pSendScanCmd->u.scanCmd.callback = NULL;
514 } else {
515 pSendScanCmd = pScanCmd;
516 pSendScanCmd->u.scanCmd.u.scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
c_hpothudbefd3e2014-04-28 15:59:47 +0530517
Vinay Malekal05fdc812012-12-17 13:04:30 -0800518 //Use concurrency values for min/maxChnTime.
519 //We know csrIsAnySessionConnected(pMac) returns TRUE here
520 csrSetDefaultScanTiming(pMac, pSendScanCmd->u.scanCmd.u.scanRequest.scanType, &pSendScanCmd->u.scanCmd.u.scanRequest);
521 }
522
523 fNoCmdPending = csrLLIsListEmpty( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK );
524
525 //Logic Below is as follows
526 // If the scanCmdPendingList is empty then we directly send that command
527 // to smeCommandQueue else we buffer it in our scanCmdPendingList Queue
528 if( fNoCmdPending )
529 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700530 if (pQueueScanCmd != NULL)
531 {
Vinay Malekal05fdc812012-12-17 13:04:30 -0800532 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pQueueScanCmd->Link, LL_ACCESS_LOCK );
Jeff Johnson295189b2012-06-20 16:38:30 -0700533 }
534
535 if (pSendScanCmd != NULL)
536 {
537 return csrQueueSmeCommand(pMac, pSendScanCmd, eANI_BOOLEAN_FALSE);
538 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800539 }
540 else
541 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700542 if (pSendScanCmd != NULL)
543 {
544 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pSendScanCmd->Link, LL_ACCESS_LOCK );
545 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800546
Jeff Johnson295189b2012-06-20 16:38:30 -0700547 if (pQueueScanCmd != NULL)
548 {
549 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pQueueScanCmd->Link, LL_ACCESS_LOCK );
550 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800551 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700552 }
553 else
554 { //No concurrency case
Srikant Kuppa866893f2012-12-27 17:28:14 -0800555 smsLog( pMac, LOG2, FL("Queuing scan command (reason=%d, roamState=%d"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800556 " numOfChannels=%d)"),
Srikant Kuppa866893f2012-12-27 17:28:14 -0800557 pScanCmd->u.scanCmd.reason,
558 pMac->roam.neighborRoamInfo.neighborRoamState,
559 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -0700560 return csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
561 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700562
563 return ( status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700564}
565#endif
566
Jeff Johnsone7245742012-09-05 17:12:55 -0700567/* ---------------------------------------------------------------------------
568 \fn csrScan2GOnyRequest
569 \brief This function will update the scan request with only
Jeff Johnsonb88db982012-12-10 13:34:59 -0800570 2.4GHz valid channel list.
Jeff Johnsone7245742012-09-05 17:12:55 -0700571 \param pMac
572 \param pScanCmd
573 \param pScanRequest
574 \return None
575 -------------------------------------------------------------------------------*/
576static void csrScan2GOnyRequest(tpAniSirGlobal pMac,tSmeCmd *pScanCmd,
577 tCsrScanRequest *pScanRequest)
578{
579 tANI_U8 index, channelId, channelListSize = 0;
580 tANI_U8 channelList2G[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
581 static tANI_U8 validchannelList[CSR_MAX_2_4_GHZ_SUPPORTED_CHANNELS] = {0};
582
583 VOS_ASSERT(pScanCmd && pScanRequest);
Madan Mohan Koyyalamudi33ef6a22012-10-30 17:44:43 -0700584 /* To silence the KW tool null check is added */
585 if((pScanCmd == NULL) || (pScanRequest == NULL))
586 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800587 smsLog( pMac, LOGE, FL(" pScanCmd or pScanRequest is NULL "));
Madan Mohan Koyyalamudi33ef6a22012-10-30 17:44:43 -0700588 return;
589 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700590
591 if (pScanCmd->u.scanCmd.scanID ||
592 (eCSR_SCAN_REQUEST_FULL_SCAN != pScanRequest->requestType))
593 return;
594
595 //Contsruct valid Supported 2.4 GHz Channel List
596 for( index = 0; index < ARRAY_SIZE(channelList2G); index++ )
597 {
598 channelId = channelList2G[index];
599 if ( csrIsSupportedChannel( pMac, channelId ) )
600 {
601 validchannelList[channelListSize++] = channelId;
602 }
603 }
604
605 pScanRequest->ChannelInfo.numOfChannels = channelListSize;
606 pScanRequest->ChannelInfo.ChannelList = validchannelList;
607}
608
Jeff Johnson295189b2012-06-20 16:38:30 -0700609eHalStatus csrScanRequest(tpAniSirGlobal pMac, tANI_U16 sessionId,
610 tCsrScanRequest *pScanRequest, tANI_U32 *pScanRequestID,
611 csrScanCompleteCallback callback, void *pContext)
612{
613 eHalStatus status = eHAL_STATUS_FAILURE;
614 tSmeCmd *pScanCmd = NULL;
Madan Mohan Koyyalamudicb90bb22012-10-30 18:24:43 -0700615 eCsrConnectState ConnectState;
Jeff Johnson295189b2012-06-20 16:38:30 -0700616
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800617 if(pScanRequest == NULL)
618 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800619 smsLog( pMac, LOGE, FL(" pScanRequest is NULL"));
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800620 VOS_ASSERT(0);
Kaushik, Sushant488df382014-03-05 11:43:47 +0530621 return eHAL_STATUS_FAILURE ;
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800622 }
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700623
Kiet Lamd1f3dc82013-11-05 20:45:04 +0530624 /* During group formation, the P2P client scans for GO with the specific SSID.
625 * There will be chances of GO switching to other channels because of scan or
626 * to STA channel in case of STA+GO MCC scenario. So to increase the possibility
627 * of client to find the GO, the dwell time of scan is increased to 100ms.
628 */
629 if(pScanRequest->p2pSearch)
630 {
Rashmi Ramanna6f7931c2013-12-20 09:04:12 +0530631 if(pScanRequest->SSIDs.numOfSSIDs)
Kiet Lamd1f3dc82013-11-05 20:45:04 +0530632 {
Rashmi Ramanna6f7931c2013-12-20 09:04:12 +0530633 //If the scan request is for specific SSId the length of SSID will be
634 //greater than 7 as SSID for p2p search contains "DIRECT-")
635 if(pScanRequest->SSIDs.SSIDList->SSID.length > DIRECT_SSID_LEN)
636 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530637 smsLog( pMac, LOG1, FL("P2P: Increasing the min and max Dwell"
638 " time to %d for specific SSID scan %.*s"),
639 MAX_CHN_TIME_TO_FIND_GO,
640 pScanRequest->SSIDs.SSIDList->SSID.length,
641 pScanRequest->SSIDs.SSIDList->SSID.ssId);
Rashmi Ramanna6f7931c2013-12-20 09:04:12 +0530642 pScanRequest->maxChnTime = MAX_CHN_TIME_TO_FIND_GO;
643 pScanRequest->minChnTime = MIN_CHN_TIME_TO_FIND_GO;
644 }
Kiet Lamd1f3dc82013-11-05 20:45:04 +0530645 }
646 }
647
Jeff Johnson295189b2012-06-20 16:38:30 -0700648 do
649 {
650 if(pMac->scan.fScanEnable)
651 {
652 pScanCmd = csrGetCommandBuffer(pMac);
653 if(pScanCmd)
654 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530655 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -0700656 pScanCmd->command = eSmeCommandScan;
657 pScanCmd->sessionId = sessionId;
658 pScanCmd->u.scanCmd.callback = callback;
659 pScanCmd->u.scanCmd.pContext = pContext;
660 if(eCSR_SCAN_REQUEST_11D_SCAN == pScanRequest->requestType)
661 {
662 pScanCmd->u.scanCmd.reason = eCsrScan11d1;
663 }
664 else if((eCSR_SCAN_REQUEST_FULL_SCAN == pScanRequest->requestType) ||
665 (eCSR_SCAN_P2P_DISCOVERY == pScanRequest->requestType)
666#ifdef SOFTAP_CHANNEL_RANGE
667 ||(eCSR_SCAN_SOFTAP_CHANNEL_RANGE == pScanRequest->requestType)
668#endif
669 )
670 {
671 pScanCmd->u.scanCmd.reason = eCsrScanUserRequest;
672 }
673 else if(eCSR_SCAN_HO_BG_SCAN == pScanRequest->requestType)
674 {
675 pScanCmd->u.scanCmd.reason = eCsrScanBgScan;
676 }
677 else if(eCSR_SCAN_HO_PROBE_SCAN == pScanRequest->requestType)
678 {
679 pScanCmd->u.scanCmd.reason = eCsrScanProbeBss;
680 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700681 else if(eCSR_SCAN_P2P_FIND_PEER == pScanRequest->requestType)
682 {
683 pScanCmd->u.scanCmd.reason = eCsrScanP2PFindPeer;
684 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700685 else
686 {
687 pScanCmd->u.scanCmd.reason = eCsrScanIdleScan;
688 }
689 if(pScanRequest->minChnTime == 0 && pScanRequest->maxChnTime == 0)
690 {
691 //The caller doesn't set the time correctly. Set it here
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530692 csrSetDefaultScanTiming(pMac, pScanRequest->scanType,
693 pScanRequest);
694 smsLog(pMac, LOG1, FL("Setting default min %d and max %d"
695 " ChnTime"), pScanRequest->minChnTime,
696 pScanRequest->maxChnTime);
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700697 }
698#ifdef WLAN_AP_STA_CONCURRENCY
699 if(pScanRequest->restTime == 0)
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800700 {
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700701 //Need to set restTime only if at least one session is connected
702 if(csrIsAnySessionConnected(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -0700703 {
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700704 pScanRequest->restTime = pMac->roam.configParam.nRestTimeConc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700705 }
706 }
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700707#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -0700708 /*For Standalone wlan : channel time will remain the same.
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530709 For BTC with A2DP up: Channel time = Channel time * 2, if station is not already associated.
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800710 This has been done to provide a larger scan window for faster connection during btc.Else Scan is seen
711 to take a long time.
712 For BTC with A2DP up: Channel time will not be doubled, if station is already associated.
713 */
Jeff Johnson32d95a32012-09-10 13:15:23 -0700714 status = csrRoamGetConnectState(pMac,sessionId,&ConnectState);
Srinivas Girigowdac84c57c2013-02-19 17:41:56 -0800715 if (HAL_STATUS_SUCCESS(status) &&
716 pMac->btc.fA2DPUp &&
Jeff Johnson32d95a32012-09-10 13:15:23 -0700717 (eCSR_ASSOC_STATE_TYPE_INFRA_ASSOCIATED != ConnectState) &&
718 (eCSR_ASSOC_STATE_TYPE_IBSS_CONNECTED != ConnectState))
719 {
720 pScanRequest->maxChnTime = pScanRequest->maxChnTime << 1;
721 pScanRequest->minChnTime = pScanRequest->minChnTime << 1;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530722 smsLog( pMac, LOG1, FL("BTC A2DP up, doubling max and min"
723 " ChnTime (Max=%d Min=%d)"),
724 pScanRequest->maxChnTime,
725 pScanRequest->minChnTime);
Jeff Johnson32d95a32012-09-10 13:15:23 -0700726 }
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800727
Kiet Lam64c1b492013-07-12 13:56:44 +0530728 pScanRequest->maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
729 pScanRequest->minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700730 //Need to make the following atomic
731 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
732
733 if(pScanRequestID)
734 {
735 *pScanRequestID = pScanCmd->u.scanCmd.scanID;
736 }
737
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800738 // If it is the first scan request from HDD, CSR checks if it is for 11d.
Jeff Johnson295189b2012-06-20 16:38:30 -0700739 // If it is not, CSR will save the scan request in the pending cmd queue
740 // & issue an 11d scan request to PE.
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800741 if (((0 == pScanCmd->u.scanCmd.scanID)
Jeff Johnson295189b2012-06-20 16:38:30 -0700742 && (eCSR_SCAN_REQUEST_11D_SCAN != pScanRequest->requestType))
743#ifdef SOFTAP_CHANNEL_RANGE
744 && (eCSR_SCAN_SOFTAP_CHANNEL_RANGE != pScanRequest->requestType)
745#endif
746 && (eANI_BOOLEAN_FALSE == pMac->scan.fEnableBypass11d)
747 )
748 {
749 tSmeCmd *p11dScanCmd;
750 tCsrScanRequest scanReq;
751 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
752
Kiet Lam64c1b492013-07-12 13:56:44 +0530753 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -0700754
755 p11dScanCmd = csrGetCommandBuffer(pMac);
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800756 if (p11dScanCmd)
Jeff Johnson295189b2012-06-20 16:38:30 -0700757 {
758 tANI_U32 numChn = pMac->scan.baseChannels.numChannels;
759
Kiet Lam64c1b492013-07-12 13:56:44 +0530760 vos_mem_set(&p11dScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
761 pChnInfo->ChannelList = vos_mem_malloc(numChn);
762 if ( NULL == pChnInfo->ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -0700763 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530764 smsLog(pMac, LOGE, FL("Failed to allocate memory"));
765 status = eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -0700766 break;
767 }
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530768 vos_mem_copy(pChnInfo->ChannelList,
769 pMac->scan.baseChannels.channelList,
770 numChn);
Jeff Johnson295189b2012-06-20 16:38:30 -0700771 pChnInfo->numOfChannels = (tANI_U8)numChn;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530772
Jeff Johnson295189b2012-06-20 16:38:30 -0700773 p11dScanCmd->command = eSmeCommandScan;
Mihir Shetefc7ff5b2014-01-27 11:30:05 +0530774 p11dScanCmd->u.scanCmd.callback = pMac->scan.callback11dScanDone;
Jeff Johnson295189b2012-06-20 16:38:30 -0700775 p11dScanCmd->u.scanCmd.pContext = NULL;
c_hpothu0d5a7352014-03-22 12:30:25 +0530776 p11dScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID;
Jeff Johnson295189b2012-06-20 16:38:30 -0700777 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
778
779 if ( csrIs11dSupported(pMac) )
780 {
c_hpothudbefd3e2014-04-28 15:59:47 +0530781 scanReq.scanType = eSIR_PASSIVE_SCAN;
Jeff Johnson295189b2012-06-20 16:38:30 -0700782 scanReq.requestType = eCSR_SCAN_REQUEST_11D_SCAN;
783 p11dScanCmd->u.scanCmd.reason = eCsrScan11d1;
784 scanReq.maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
785 scanReq.minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
786 }
787 else
788 {
c_hpothudbefd3e2014-04-28 15:59:47 +0530789 scanReq.scanType = pScanRequest->scanType;
Jeff Johnson295189b2012-06-20 16:38:30 -0700790 scanReq.requestType = eCSR_SCAN_IDLE_MODE_SCAN;
791 p11dScanCmd->u.scanCmd.reason = eCsrScanIdleScan;
792 scanReq.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
793 scanReq.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800794
Madan Mohan Koyyalamudi04a65f02013-07-26 13:58:38 +0530795 scanReq.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
796 scanReq.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700797 }
c_hpothu059edb02014-03-12 21:44:28 +0530798 if (pMac->roam.configParam.nInitialDwellTime)
799 {
800 scanReq.maxChnTime =
801 pMac->roam.configParam.nInitialDwellTime;
802 smsLog(pMac, LOG1, FL("11d scan, updating"
803 "dwell time for first scan %u"),
804 scanReq.maxChnTime);
805 }
Gupta, Kapil01be56b2015-12-30 20:36:33 +0530806 if (!(pScanRequest->p2pSearch)
807 &&(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
Gupta, Kapil01be56b2015-12-30 20:36:33 +0530883 if (!(pScanRequest->p2pSearch)
884 && (pScanRequest->ChannelInfo.numOfChannels
885 < pMac->roam.configParam.max_chan_for_dwell_time_cfg))
886 {
887 pScanRequest->maxChnTime = pScanRequest->maxChnTime << 1;
888 pScanRequest->minChnTime = pScanRequest->minChnTime << 1;
889 smsLog(pMac, LOG1,
890 FL("Double ChnTime (Max=%d Min=%d) numOfChannels=%d max_chan_for_dwell_time_cfg=%d"),
891 pScanRequest->maxChnTime,
892 pScanRequest->minChnTime,
893 pScanRequest->ChannelInfo.numOfChannels,
894 pMac->roam.configParam.max_chan_for_dwell_time_cfg);
895 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700896 status = csrScanCopyRequest(pMac, &pScanCmd->u.scanCmd.u.scanRequest, pScanRequest);
897 if(HAL_STATUS_SUCCESS(status))
898 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530899 tCsrScanRequest *pTempScanReq =
900 &pScanCmd->u.scanCmd.u.scanRequest;
krunal soni5f112f02013-11-25 15:00:11 -0800901 pMac->scan.scanProfile.numOfChannels =
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530902 pTempScanReq->ChannelInfo.numOfChannels;
krunal soni5f112f02013-11-25 15:00:11 -0800903
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530904 smsLog( pMac, LOG1, FL(" SId=%d scanId=%d"
905 " Scan reason=%u numSSIDs=%d"
906 " numChan=%d P2P search=%d minCT=%d maxCT=%d"
907 " minCBtc=%d maxCBtx=%d"),
908 sessionId, pScanCmd->u.scanCmd.scanID,
909 pScanCmd->u.scanCmd.reason,
910 pTempScanReq->SSIDs.numOfSSIDs,
911 pTempScanReq->ChannelInfo.numOfChannels,
912 pTempScanReq->p2pSearch,
913 pTempScanReq->minChnTime,
914 pTempScanReq->maxChnTime,
915 pTempScanReq->minChnTimeBtc,
916 pTempScanReq->maxChnTimeBtc );
Jeff Johnson295189b2012-06-20 16:38:30 -0700917 //Start process the command
918#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +0530919 if (!pMac->fScanOffload)
920 status = csrQueueScanRequest(pMac,pScanCmd);
921 else
922 status = csrQueueSmeCommand(pMac, pScanCmd,
923 eANI_BOOLEAN_FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -0700924#else
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530925 status = csrQueueSmeCommand(pMac, pScanCmd,
926 eANI_BOOLEAN_FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -0700927#endif
928 if( !HAL_STATUS_SUCCESS( status ) )
929 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800930 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700931 break;
932 }
933 }
934 else
935 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800936 smsLog( pMac, LOGE, FL(" fail to copy request status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700937 break;
938 }
939 }
940 else
941 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800942 smsLog( pMac, LOGE, FL(" pScanCmd is NULL"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700943 break;
944 }
945 }
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530946 else
947 {
948 smsLog( pMac, LOGE, FL("SId: %d Scanning not enabled"
949 " Scan type=%u, numOfSSIDs=%d P2P search=%d"),
950 sessionId, pScanRequest->requestType,
951 pScanRequest->SSIDs.numOfSSIDs,
952 pScanRequest->p2pSearch );
953 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700954 } while(0);
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530955
956
Jeff Johnson295189b2012-06-20 16:38:30 -0700957 if(!HAL_STATUS_SUCCESS(status) && pScanCmd)
958 {
959 if( eCsrScanIdleScan == pScanCmd->u.scanCmd.reason )
960 {
961 //Set the flag back for restarting idle scan
962 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
963 }
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530964 smsLog( pMac, LOGE, FL(" SId: %d Failed with status=%d"
965 " Scan reason=%u numOfSSIDs=%d"
966 " P2P search=%d scanId=%d"),
967 sessionId, status, pScanCmd->u.scanCmd.reason,
968 pScanRequest->SSIDs.numOfSSIDs, pScanRequest->p2pSearch,
969 pScanCmd->u.scanCmd.scanID );
Jeff Johnson295189b2012-06-20 16:38:30 -0700970 csrReleaseCommandScan(pMac, pScanCmd);
971 }
972
973 return (status);
974}
975
976
977eHalStatus csrScanRequestResult(tpAniSirGlobal pMac)
978{
979 eHalStatus status = eHAL_STATUS_SUCCESS;
980 tSmeCmd *pScanCmd;
981
982 if(pMac->scan.fScanEnable)
983 {
984 pScanCmd = csrGetCommandBuffer(pMac);
985 if(pScanCmd)
986 {
987 pScanCmd->command = eSmeCommandScan;
Kiet Lam64c1b492013-07-12 13:56:44 +0530988 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -0700989 pScanCmd->u.scanCmd.callback = NULL;
990 pScanCmd->u.scanCmd.pContext = NULL;
991 pScanCmd->u.scanCmd.reason = eCsrScanGetResult;
992 //Need to make the following atomic
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -0700993 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID; //let it wrap around
Jeff Johnson295189b2012-06-20 16:38:30 -0700994 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
995 if( !HAL_STATUS_SUCCESS( status ) )
996 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800997 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700998 csrReleaseCommandScan(pMac, pScanCmd);
999 }
1000 }
1001 else
1002 {
1003 //log error
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001004 smsLog(pMac, LOGE, FL("can not obtain a common buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001005 status = eHAL_STATUS_RESOURCES;
1006 }
1007 }
1008
1009 return (status);
1010}
1011
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07001012#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
1013eHalStatus csrScanRequestLfrResult(tpAniSirGlobal pMac, tANI_U32 sessionId,
1014 csrScanCompleteCallback callback, void *pContext)
1015{
1016 eHalStatus status = eHAL_STATUS_SUCCESS;
1017 tSmeCmd *pScanCmd;
1018
1019 if (pMac->scan.fScanEnable)
1020 {
1021 pScanCmd = csrGetCommandBuffer(pMac);
1022 if (pScanCmd)
1023 {
1024 pScanCmd->command = eSmeCommandScan;
1025 pScanCmd->sessionId = sessionId;
Kiet Lam64c1b492013-07-12 13:56:44 +05301026 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07001027 pScanCmd->u.scanCmd.callback = callback;
1028 pScanCmd->u.scanCmd.pContext = pContext;
1029 pScanCmd->u.scanCmd.reason = eCsrScanGetLfrResult;
1030 //Need to make the following atomic
1031 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID; //let it wrap around
1032 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_TRUE);
1033 if ( !HAL_STATUS_SUCCESS( status ) )
1034 {
1035 smsLog( pMac, LOGE, FL(" fail to send message status = %d\n"), status );
1036 csrReleaseCommandScan(pMac, pScanCmd);
1037 }
1038 }
1039 else
1040 {
1041 //log error
1042 smsLog(pMac, LOGE, FL("can not obtain a common buffer\n"));
1043 status = eHAL_STATUS_RESOURCES;
1044 }
1045 }
1046
1047 return (status);
1048}
1049#endif //WLAN_FEATURE_ROAM_SCAN_OFFLOAD
Jeff Johnson295189b2012-06-20 16:38:30 -07001050
1051eHalStatus csrScanAllChannels(tpAniSirGlobal pMac, eCsrRequestType reqType)
1052{
1053 eHalStatus status = eHAL_STATUS_SUCCESS;
1054 tANI_U32 scanId;
1055 tCsrScanRequest scanReq;
1056
Kiet Lam64c1b492013-07-12 13:56:44 +05301057 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001058 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
1059 scanReq.scanType = eSIR_ACTIVE_SCAN;
1060 scanReq.requestType = reqType;
1061 scanReq.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1062 scanReq.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001063 scanReq.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1064 scanReq.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001065 //Scan with invalid sessionId.
1066 //This results in SME using the first available session to scan.
1067 status = csrScanRequest(pMac, CSR_SESSION_ID_INVALID, &scanReq,
1068 &scanId, NULL, NULL);
1069
1070 return (status);
1071}
1072
1073
1074
1075
1076eHalStatus csrIssueRoamAfterLostlinkScan(tpAniSirGlobal pMac, tANI_U32 sessionId, eCsrRoamReason reason)
1077{
1078 eHalStatus status = eHAL_STATUS_FAILURE;
1079 tScanResultHandle hBSSList = NULL;
1080 tCsrScanResultFilter *pScanFilter = NULL;
1081 tANI_U32 roamId = 0;
1082 tCsrRoamProfile *pProfile = NULL;
1083 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1084
Jeff Johnson32d95a32012-09-10 13:15:23 -07001085 if(!pSession)
1086 {
1087 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1088 return eHAL_STATUS_FAILURE;
1089 }
1090
Jeff Johnson295189b2012-06-20 16:38:30 -07001091 do
1092 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001093 smsLog(pMac, LOG1, " csrIssueRoamAfterLostlinkScan called");
Jeff Johnson295189b2012-06-20 16:38:30 -07001094 if(pSession->fCancelRoaming)
1095 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001096 smsLog(pMac, LOGW, " lostlink roaming is cancelled");
Jeff Johnson295189b2012-06-20 16:38:30 -07001097 csrScanStartIdleScan(pMac);
1098 status = eHAL_STATUS_SUCCESS;
1099 break;
1100 }
1101 //Here is the profile we need to connect to
Kiet Lam64c1b492013-07-12 13:56:44 +05301102 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1103 if ( NULL == pScanFilter)
1104 status = eHAL_STATUS_FAILURE;
1105 else
1106 status = eHAL_STATUS_SUCCESS;
1107 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001108 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301109 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001110 if(NULL == pSession->pCurRoamProfile)
1111 {
1112 pScanFilter->EncryptionType.numEntries = 1;
1113 pScanFilter->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_NONE;
1114 }
1115 else
1116 {
1117 //We have to make a copy of pCurRoamProfile because it will be free inside csrRoamIssueConnect
Kiet Lam64c1b492013-07-12 13:56:44 +05301118 pProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1119 if ( NULL == pProfile )
1120 status = eHAL_STATUS_FAILURE;
1121 else
1122 status = eHAL_STATUS_SUCCESS;
1123 if (!HAL_STATUS_SUCCESS(status))
1124 break;
1125 vos_mem_set(pProfile, sizeof(tCsrRoamProfile), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001126 status = csrRoamCopyProfile(pMac, pProfile, pSession->pCurRoamProfile);
1127 if(!HAL_STATUS_SUCCESS(status))
1128 break;
1129 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1130 }//We have a profile
1131 roamId = GET_NEXT_ROAM_ID(&pMac->roam);
1132 if(HAL_STATUS_SUCCESS(status))
1133 {
1134 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1135 if(HAL_STATUS_SUCCESS(status))
1136 {
1137 if(eCsrLostLink1 == reason)
1138 {
1139 //we want to put the last connected BSS to the very beginning, if possible
1140 csrMoveBssToHeadFromBSSID(pMac, &pSession->connectedProfile.bssid, hBSSList);
1141 }
1142 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList, reason,
1143 roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1144 if(!HAL_STATUS_SUCCESS(status))
1145 {
1146 csrScanResultPurge(pMac, hBSSList);
1147 }
1148 }//Have scan result
1149 }
1150 }while(0);
1151 if(pScanFilter)
1152 {
1153 //we need to free memory for filter if profile exists
1154 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301155 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001156 }
1157 if(NULL != pProfile)
1158 {
1159 csrReleaseProfile(pMac, pProfile);
Kiet Lam64c1b492013-07-12 13:56:44 +05301160 vos_mem_free(pProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07001161 }
1162
1163 return (status);
1164}
1165
1166
Ratheesh S Pece1f832015-07-25 15:50:25 +05301167eHalStatus csrScanGetScanChnInfo(tpAniSirGlobal pMac, tSmeCmd *pCommand)
Jeff Johnson295189b2012-06-20 16:38:30 -07001168{
1169 eHalStatus status = eHAL_STATUS_SUCCESS;
1170 tSmeCmd *pScanCmd;
1171
1172 if(pMac->scan.fScanEnable)
1173 {
1174 pScanCmd = csrGetCommandBuffer(pMac);
1175 if(pScanCmd)
1176 {
1177 pScanCmd->command = eSmeCommandScan;
Kiet Lam64c1b492013-07-12 13:56:44 +05301178 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001179 pScanCmd->u.scanCmd.reason = eCsrScanGetScanChnInfo;
1180 //Need to make the following atomic
1181 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Ratheesh S Pece1f832015-07-25 15:50:25 +05301182 pScanCmd->sessionId = pCommand->sessionId;
1183 if( pCommand->u.scanCmd.reason == eCsrScanUserRequest)
1184 {
1185 pScanCmd->u.scanCmd.callback = NULL;
1186 pScanCmd->u.scanCmd.pContext = NULL;
1187 } else {
1188 pScanCmd->u.scanCmd.callback = pCommand->u.scanCmd.callback;
1189 pScanCmd->u.scanCmd.pContext = pCommand->u.scanCmd.pContext;
1190 pScanCmd->u.scanCmd.abortScanIndication =
1191 pCommand->u.scanCmd.abortScanIndication;
1192 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001193 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
1194 if( !HAL_STATUS_SUCCESS( status ) )
1195 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001196 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001197 csrReleaseCommandScan(pMac, pScanCmd);
1198 }
1199 }
1200 else
1201 {
1202 //log error
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001203 smsLog(pMac, LOGE, FL("can not obtain a common buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001204 status = eHAL_STATUS_RESOURCES;
1205 }
1206 }
1207
1208 return (status);
1209}
1210
1211
1212eHalStatus csrScanHandleFailedLostlink1(tpAniSirGlobal pMac, tANI_U32 sessionId)
1213{
1214 eHalStatus status = eHAL_STATUS_FAILURE;
1215 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1216
Jeff Johnson32d95a32012-09-10 13:15:23 -07001217 if(!pSession)
1218 {
1219 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1220 return eHAL_STATUS_FAILURE;
1221 }
1222
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001223 smsLog(pMac, LOGW, " Lostlink scan 1 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001224 if(pSession->fCancelRoaming)
1225 {
1226 csrScanStartIdleScan(pMac);
1227 }
1228 else if(pSession->pCurRoamProfile)
1229 {
1230 //We fail lostlink1 but there may be other BSS in the cached result fit the profile. Give it a try first
1231 if(pSession->pCurRoamProfile->SSIDs.numOfSSIDs == 0 ||
1232 pSession->pCurRoamProfile->SSIDs.numOfSSIDs > 1)
1233 {
1234 //try lostlink scan2
1235 status = csrScanRequestLostLink2(pMac, sessionId);
1236 }
1237 else if(!pSession->pCurRoamProfile->ChannelInfo.ChannelList ||
1238 pSession->pCurRoamProfile->ChannelInfo.ChannelList[0] == 0)
1239 {
1240 //go straight to lostlink scan3
1241 status = csrScanRequestLostLink3(pMac, sessionId);
1242 }
1243 else
1244 {
1245 //we are done with lostlink
1246 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1247 {
1248 csrScanStartIdleScan(pMac);
1249 }
1250 status = eHAL_STATUS_SUCCESS;
1251 }
1252 }
1253 else
1254 {
1255 status = csrScanRequestLostLink3(pMac, sessionId);
1256 }
1257
1258 return (status);
1259}
1260
1261
1262
1263eHalStatus csrScanHandleFailedLostlink2(tpAniSirGlobal pMac, tANI_U32 sessionId)
1264{
1265 eHalStatus status = eHAL_STATUS_FAILURE;
1266 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1267
Jeff Johnson32d95a32012-09-10 13:15:23 -07001268 if(!pSession)
1269 {
1270 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1271 return eHAL_STATUS_FAILURE;
1272 }
1273
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001274 smsLog(pMac, LOGW, " Lostlink scan 2 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001275 if(pSession->fCancelRoaming)
1276 {
1277 csrScanStartIdleScan(pMac);
1278 }
1279 else if(!pSession->pCurRoamProfile || !pSession->pCurRoamProfile->ChannelInfo.ChannelList ||
1280 pSession->pCurRoamProfile->ChannelInfo.ChannelList[0] == 0)
1281 {
1282 //try lostlink scan3
1283 status = csrScanRequestLostLink3(pMac, sessionId);
1284 }
1285 else
1286 {
1287 //we are done with lostlink
1288 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1289 {
1290 csrScanStartIdleScan(pMac);
1291 }
1292 }
1293
1294 return (status);
1295}
1296
1297
1298
1299eHalStatus csrScanHandleFailedLostlink3(tpAniSirGlobal pMac, tANI_U32 sessionId)
1300{
1301 eHalStatus status = eHAL_STATUS_SUCCESS;
1302
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001303 smsLog(pMac, LOGW, " Lostlink scan 3 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001304 if(eANI_BOOLEAN_TRUE == csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1305 {
1306 //we are done with lostlink
1307 csrScanStartIdleScan(pMac);
1308 }
1309
1310 return (status);
1311}
1312
1313
1314
1315
1316//Lostlink1 scan is to actively scan the last connected profile's SSID on all matched BSS channels.
1317//If no roam profile (it should not), it is like lostlinkscan3
1318eHalStatus csrScanRequestLostLink1( tpAniSirGlobal pMac, tANI_U32 sessionId )
1319{
1320 eHalStatus status = eHAL_STATUS_SUCCESS;
1321 tSmeCmd *pCommand = NULL;
1322 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1323 tCsrScanResultFilter *pScanFilter = NULL;
1324 tScanResultHandle hBSSList = NULL;
1325 tCsrScanResultInfo *pScanResult = NULL;
1326 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1327
Jeff Johnson32d95a32012-09-10 13:15:23 -07001328 if(!pSession)
1329 {
1330 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1331 return eHAL_STATUS_FAILURE;
1332 }
1333
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001334 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001335 do
1336 {
1337 pCommand = csrGetCommandBuffer(pMac);
1338 if(!pCommand)
1339 {
1340 status = eHAL_STATUS_RESOURCES;
1341 break;
1342 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301343 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001344 pCommand->command = eSmeCommandScan;
1345 pCommand->sessionId = (tANI_U8)sessionId;
1346 pCommand->u.scanCmd.reason = eCsrScanLostLink1;
1347 pCommand->u.scanCmd.callback = NULL;
1348 pCommand->u.scanCmd.pContext = NULL;
1349 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1350 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001351 pCommand->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1352 pCommand->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001353 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
1354 if(pSession->connectedProfile.SSID.length)
1355 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301356 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList = vos_mem_malloc(sizeof(tCsrSSIDInfo));
1357 if ( NULL == pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList )
1358 status = eHAL_STATUS_FAILURE;
1359 else
1360 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001361 if(!HAL_STATUS_SUCCESS(status))
1362 {
1363 break;
1364 }
1365 pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 1;
Kiet Lam64c1b492013-07-12 13:56:44 +05301366 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID,
1367 &pSession->connectedProfile.SSID, sizeof(tSirMacSSid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001368 }
1369 else
1370 {
1371 pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 0;
1372 }
1373 if(pSession->pCurRoamProfile)
1374 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301375 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1376 if ( NULL == pScanFilter )
1377 status = eHAL_STATUS_FAILURE;
1378 else
1379 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001380 if(!HAL_STATUS_SUCCESS(status))
1381 {
1382 break;
1383 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301384 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001385 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
1386 if(!HAL_STATUS_SUCCESS(status))
1387 {
1388 break;
1389 }
1390 //Don't change variable status here because whether we can get result or not, the command goes to PE.
1391 //The status is also used to indicate whether the command is queued. Not success meaning not queue
1392 if(HAL_STATUS_SUCCESS((csrScanGetResult(pMac, pScanFilter, &hBSSList))) && hBSSList)
1393 {
1394 tANI_U8 i, nChn = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05301395 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList =
1396 vos_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
1397 if ( NULL == pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
1398 status = eHAL_STATUS_FAILURE;
1399 else
1400 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001401 if(!HAL_STATUS_SUCCESS(status))
1402 {
1403 break;
1404 }
1405 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) &&
1406 nChn < WNI_CFG_VALID_CHANNEL_LIST_LEN)
1407 {
1408 for(i = 0; i < nChn; i++)
1409 {
1410 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1411 pScanResult->BssDescriptor.channelId)
1412 {
1413 break;
1414 }
1415 }
1416 if(i == nChn)
1417 {
1418 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pScanResult->BssDescriptor.channelId;
1419 }
1420 }
1421 //Include the last connected BSS' channel
1422 if(csrRoamIsChannelValid(pMac, pSession->connectedProfile.operationChannel))
1423 {
1424 for(i = 0; i < nChn; i++)
1425 {
1426 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1427 pSession->connectedProfile.operationChannel)
1428 {
1429 break;
1430 }
1431 }
1432 if(i == nChn)
1433 {
1434 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pSession->connectedProfile.operationChannel;
1435 }
1436 }
1437 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nChn;
1438 }
1439 else
1440 {
1441 if(csrRoamIsChannelValid(pMac, pSession->connectedProfile.operationChannel))
1442 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301443 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(1);
1444 if ( NULL == pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
1445 status = eHAL_STATUS_FAILURE;
1446 else
1447 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001448 //just try the last connected channel
1449 if(HAL_STATUS_SUCCESS(status))
1450 {
1451 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[0] = pSession->connectedProfile.operationChannel;
1452 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 1;
1453 }
1454 else
1455 {
1456 break;
1457 }
1458 }
1459 }
1460 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301461 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001462 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
1463 if( !HAL_STATUS_SUCCESS( status ) )
1464 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001465 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001466 break;
1467 }
1468 } while( 0 );
1469
1470 if(!HAL_STATUS_SUCCESS(status))
1471 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001472 smsLog(pMac, LOGW, " csrScanRequestLostLink1 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001473 if(pCommand)
1474 {
1475 csrReleaseCommandScan(pMac, pCommand);
1476 }
1477 status = csrScanHandleFailedLostlink1( pMac, sessionId );
1478 }
1479 if(pScanFilter)
1480 {
1481 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301482 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001483 }
1484 if(hBSSList)
1485 {
1486 csrScanResultPurge(pMac, hBSSList);
1487 }
1488
1489 return( status );
1490}
1491
1492
1493//Lostlink2 scan is to actively scan the all SSIDs of the last roaming profile's on all matched BSS channels.
1494//Since MAC doesn't support multiple SSID, we scan all SSIDs and filter them afterwards
1495eHalStatus csrScanRequestLostLink2( tpAniSirGlobal pMac, tANI_U32 sessionId )
1496{
1497 eHalStatus status = eHAL_STATUS_SUCCESS;
1498 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1499 tCsrScanResultFilter *pScanFilter = NULL;
1500 tScanResultHandle hBSSList = NULL;
1501 tCsrScanResultInfo *pScanResult = NULL;
1502 tSmeCmd *pCommand = NULL;
1503 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1504
Jeff Johnson32d95a32012-09-10 13:15:23 -07001505 if(!pSession)
1506 {
1507 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1508 return eHAL_STATUS_FAILURE;
1509 }
1510
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001511 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001512 do
1513 {
1514 pCommand = csrGetCommandBuffer(pMac);
1515 if(!pCommand)
1516 {
1517 status = eHAL_STATUS_RESOURCES;
1518 break;
1519 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301520 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001521 pCommand->command = eSmeCommandScan;
1522 pCommand->sessionId = (tANI_U8)sessionId;
1523 pCommand->u.scanCmd.reason = eCsrScanLostLink2;
1524 pCommand->u.scanCmd.callback = NULL;
1525 pCommand->u.scanCmd.pContext = NULL;
1526 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1527 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001528 pCommand->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1529 pCommand->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001530 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
1531 if(pSession->pCurRoamProfile)
1532 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301533 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1534 if ( NULL == pScanFilter )
1535 status = eHAL_STATUS_FAILURE;
1536 else
1537 status = eHAL_STATUS_SUCCESS;
1538 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001539 {
1540 break;
1541 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301542 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001543 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
1544 if(!HAL_STATUS_SUCCESS(status))
1545 {
1546 break;
1547 }
1548 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1549 if(!HAL_STATUS_SUCCESS(status))
1550 {
1551 break;
1552 }
1553 if(hBSSList)
1554 {
1555 tANI_U8 i, nChn = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05301556 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList =
1557 vos_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
1558 if ( NULL == pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
1559 status = eHAL_STATUS_FAILURE;
1560 else
1561 status = eHAL_STATUS_SUCCESS;
1562 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001563 {
1564 break;
1565 }
1566 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) &&
1567 nChn < WNI_CFG_VALID_CHANNEL_LIST_LEN)
1568 {
1569 for(i = 0; i < nChn; i++)
1570 {
1571 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1572 pScanResult->BssDescriptor.channelId)
1573 {
1574 break;
1575 }
1576 }
1577 if(i == nChn)
1578 {
1579 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pScanResult->BssDescriptor.channelId;
1580 }
1581 }
1582 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nChn;
1583 }
1584 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301585 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001586 //Put to the head in pending queue
1587 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_TRUE);
1588 if( !HAL_STATUS_SUCCESS( status ) )
1589 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001590 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001591 break;
1592 }
1593 } while( 0 );
1594
1595 if(!HAL_STATUS_SUCCESS(status))
1596 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001597 smsLog(pMac, LOGW, " csrScanRequestLostLink2 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001598 if(pCommand)
1599 {
1600 csrReleaseCommandScan(pMac, pCommand);
1601 }
1602 status = csrScanHandleFailedLostlink2( pMac, sessionId );
1603 }
1604 if(pScanFilter)
1605 {
1606 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301607 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001608 }
1609 if(hBSSList)
1610 {
1611 csrScanResultPurge(pMac, hBSSList);
1612 }
1613
1614 return( status );
1615}
1616
1617
1618//To actively scan all valid channels
1619eHalStatus csrScanRequestLostLink3( tpAniSirGlobal pMac, tANI_U32 sessionId )
1620{
1621 eHalStatus status = eHAL_STATUS_SUCCESS;
1622 tSmeCmd *pCommand;
1623 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1624
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001625 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001626 do
1627 {
1628 pCommand = csrGetCommandBuffer(pMac);
1629 if(!pCommand)
1630 {
1631 status = eHAL_STATUS_RESOURCES;
1632 break;
1633 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301634 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001635 pCommand->command = eSmeCommandScan;
1636 pCommand->sessionId = (tANI_U8)sessionId;
1637 pCommand->u.scanCmd.reason = eCsrScanLostLink3;
1638 pCommand->u.scanCmd.callback = NULL;
1639 pCommand->u.scanCmd.pContext = NULL;
1640 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1641 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001642 pCommand->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1643 pCommand->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001644 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Kiet Lam64c1b492013-07-12 13:56:44 +05301645 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001646 //Put to the head of pending queue
1647 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_TRUE);
1648 if( !HAL_STATUS_SUCCESS( status ) )
1649 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001650 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001651 break;
1652 }
1653 } while( 0 );
1654 if(!HAL_STATUS_SUCCESS(status))
1655 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001656 smsLog(pMac, LOGW, " csrScanRequestLostLink3 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001657 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1658 {
1659 csrScanStartIdleScan(pMac);
1660 }
1661 if(pCommand)
1662 {
1663 csrReleaseCommandScan(pMac, pCommand);
1664 }
1665 }
1666
1667 return( status );
1668}
1669
1670
1671eHalStatus csrScanHandleSearchForSSID(tpAniSirGlobal pMac, tSmeCmd *pCommand)
1672{
1673 eHalStatus status = eHAL_STATUS_FAILURE;
1674 tScanResultHandle hBSSList = CSR_INVALID_SCANRESULT_HANDLE;
1675 tCsrScanResultFilter *pScanFilter = NULL;
1676 tCsrRoamProfile *pProfile = pCommand->u.scanCmd.pToRoamProfile;
1677 tANI_U32 sessionId = pCommand->sessionId;
Abhishek Singh7f775f82015-12-17 15:23:52 +05301678 tCsrRoamSession *pSession = CSR_GET_SESSION(pMac, sessionId);
1679
Jeff Johnson295189b2012-06-20 16:38:30 -07001680 do
1681 {
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001682#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
1683 //if this scan is for LFR
1684 if(pMac->roam.neighborRoamInfo.uOsRequestedHandoff)
1685 {
1686 //notify LFR state m/c
1687 if(eHAL_STATUS_SUCCESS != csrNeighborRoamSssidScanDone(pMac, eHAL_STATUS_SUCCESS))
1688 {
Mukul Sharma20aa6582014-08-07 21:36:12 +05301689 csrNeighborRoamStartLfrScan(pMac, REASON_OS_REQUESTED_ROAMING_NOW);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001690 }
1691 status = eHAL_STATUS_SUCCESS;
1692 break;
1693 }
1694#endif
Abhishek Singh7f775f82015-12-17 15:23:52 +05301695 if (!pSession)
1696 {
1697 smsLog(pMac, LOGE, FL("session %d not found"), sessionId);
1698 break;
1699 }
1700 /* If Disconnect is already issued from HDD no need to issue connect */
1701 if (pSession->abortConnection)
1702 {
1703 smsLog(pMac, LOGE,
1704 FL("Disconnect in progress, no need to issue connect"));
1705 break;
1706 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001707 //If there is roam command waiting, ignore this roam because the newer roam command is the one to execute
1708 if(csrIsRoamCommandWaitingForSession(pMac, sessionId))
1709 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001710 smsLog(pMac, LOGW, FL(" aborts because roam command waiting"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001711 break;
1712 }
1713 if(pProfile == NULL)
1714 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301715 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1716 if ( NULL == pScanFilter )
1717 status = eHAL_STATUS_FAILURE;
1718 else
1719 status = eHAL_STATUS_SUCCESS;
1720 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001721 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301722 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001723 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1724 if(!HAL_STATUS_SUCCESS(status))
1725 break;
1726 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1727 if(!HAL_STATUS_SUCCESS(status))
1728 break;
1729 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList, eCsrHddIssued,
1730 pCommand->u.scanCmd.roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1731 if(!HAL_STATUS_SUCCESS(status))
1732 {
1733 break;
1734 }
1735 }while(0);
1736 if(!HAL_STATUS_SUCCESS(status))
1737 {
1738 if(CSR_INVALID_SCANRESULT_HANDLE != hBSSList)
1739 {
1740 csrScanResultPurge(pMac, hBSSList);
1741 }
1742 //We haven't done anything to this profile
1743 csrRoamCallCallback(pMac, sessionId, NULL, pCommand->u.scanCmd.roamId,
1744 eCSR_ROAM_ASSOCIATION_FAILURE, eCSR_ROAM_RESULT_FAILURE);
1745 //In case we have nothing else to do, restart idle scan
1746 if(csrIsConnStateDisconnected(pMac, sessionId) && !csrIsRoamCommandWaiting(pMac))
1747 {
1748 status = csrScanStartIdleScan(pMac);
1749 }
1750#ifdef FEATURE_WLAN_BTAMP_UT_RF
1751 //In case of WDS station, let it retry.
1752 if( CSR_IS_WDS_STA(pProfile) )
1753 {
1754 //Save the roma profile so we can retry
1755 csrFreeRoamProfile( pMac, sessionId );
Kiet Lam64c1b492013-07-12 13:56:44 +05301756 pSession->pCurRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1757 if ( NULL != pSession->pCurRoamProfile )
Jeff Johnson295189b2012-06-20 16:38:30 -07001758 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301759 vos_mem_set(pSession->pCurRoamProfilee, sizeof(tCsrRoamProfile), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001760 csrRoamCopyProfile(pMac, pSession->pCurRoamProfile, pProfile);
1761 }
1762 csrRoamStartJoinRetryTimer(pMac, sessionId, CSR_JOIN_RETRY_TIMEOUT_PERIOD);
1763 }
1764#endif
1765 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301766 if (pScanFilter)
Jeff Johnson295189b2012-06-20 16:38:30 -07001767 {
1768 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301769 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001770 }
1771
1772 return (status);
1773}
1774
1775
1776eHalStatus csrScanHandleSearchForSSIDFailure(tpAniSirGlobal pMac, tSmeCmd *pCommand)
1777{
1778 eHalStatus status = eHAL_STATUS_SUCCESS;
1779 tANI_U32 sessionId = pCommand->sessionId;
1780 tCsrRoamProfile *pProfile = pCommand->u.scanCmd.pToRoamProfile;
1781 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001782#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
1783 //if this scan is for LFR
1784 if(pMac->roam.neighborRoamInfo.uOsRequestedHandoff)
1785 {
1786 //notify LFR state m/c
1787 if(eHAL_STATUS_SUCCESS != csrNeighborRoamSssidScanDone(pMac, eHAL_STATUS_FAILURE))
1788 {
Mukul Sharma20aa6582014-08-07 21:36:12 +05301789 csrNeighborRoamStartLfrScan(pMac, REASON_OS_REQUESTED_ROAMING_NOW);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001790 }
1791 return eHAL_STATUS_SUCCESS;
1792 }
1793#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -07001794 if(!pSession)
1795 {
1796 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1797 return eHAL_STATUS_FAILURE;
1798 }
1799
Jeff Johnson295189b2012-06-20 16:38:30 -07001800#if defined(WLAN_DEBUG)
1801 if(pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs == 1)
1802 {
1803 char str[36];
Kiet Lam64c1b492013-07-12 13:56:44 +05301804 vos_mem_copy(str,
1805 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.ssId,
1806 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.length);
Jeff Johnson295189b2012-06-20 16:38:30 -07001807 str[pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.length] = 0;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001808 smsLog(pMac, LOGW, FL(" SSID = %s"), str);
Jeff Johnson295189b2012-06-20 16:38:30 -07001809 }
1810#endif
1811 //Check whether it is for start ibss. No need to do anything if it is a JOIN request
1812 if(pProfile && CSR_IS_START_IBSS(pProfile))
1813 {
1814 status = csrRoamIssueConnect(pMac, sessionId, pProfile, NULL, eCsrHddIssued,
1815 pCommand->u.scanCmd.roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1816 if(!HAL_STATUS_SUCCESS(status))
1817 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001818 smsLog(pMac, LOGE, FL("failed to issue startIBSS command with status = 0x%08X"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001819 csrRoamCallCallback(pMac, sessionId, NULL, pCommand->u.scanCmd.roamId, eCSR_ROAM_FAILED, eCSR_ROAM_RESULT_FAILURE);
1820 }
1821 }
1822 else
1823 {
1824 eCsrRoamResult roamResult = eCSR_ROAM_RESULT_FAILURE;
1825
1826 if(csrIsConnStateDisconnected(pMac, sessionId) &&
1827 !csrIsRoamCommandWaitingForSession(pMac, sessionId))
1828 {
1829 status = csrScanStartIdleScan(pMac);
1830 }
1831 if((NULL == pProfile) || !csrIsBssTypeIBSS(pProfile->BSSType))
1832 {
1833 //Only indicate assoc_completion if we indicate assoc_start.
1834 if(pSession->bRefAssocStartCnt > 0)
1835 {
1836 tCsrRoamInfo *pRoamInfo = NULL, roamInfo;
Kiet Lam64c1b492013-07-12 13:56:44 +05301837 vos_mem_set(&roamInfo, sizeof(tCsrRoamInfo), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001838 pRoamInfo = &roamInfo;
1839 if(pCommand->u.roamCmd.pRoamBssEntry)
1840 {
1841 tCsrScanResult *pScanResult =
1842 GET_BASE_ADDR(pCommand->u.roamCmd.pRoamBssEntry,
1843 tCsrScanResult, Link);
1844 roamInfo.pBssDesc = &pScanResult->Result.BssDescriptor;
1845 }
1846 roamInfo.statusCode = pSession->joinFailStatusCode.statusCode;
1847 roamInfo.reasonCode = pSession->joinFailStatusCode.reasonCode;
1848 pSession->bRefAssocStartCnt--;
1849 csrRoamCallCallback(pMac, sessionId, pRoamInfo,
1850 pCommand->u.scanCmd.roamId,
1851 eCSR_ROAM_ASSOCIATION_COMPLETION,
1852 eCSR_ROAM_RESULT_FAILURE);
1853 }
Madan Mohan Koyyalamudiee255f12012-09-28 15:41:19 -07001854 else
1855 {
1856 csrRoamCallCallback(pMac, sessionId, NULL,
1857 pCommand->u.scanCmd.roamId,
1858 eCSR_ROAM_ASSOCIATION_FAILURE,
1859 eCSR_ROAM_RESULT_FAILURE);
1860 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001861#ifdef FEATURE_WLAN_BTAMP_UT_RF
1862 //In case of WDS station, let it retry.
1863 if( CSR_IS_WDS_STA(pProfile) )
1864 {
1865 //Save the roma profile so we can retry
1866 csrFreeRoamProfile( pMac, sessionId );
Kiet Lam64c1b492013-07-12 13:56:44 +05301867 pSession->pCurRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1868 if ( NULL != pSession->pCurRoamProfile )
Jeff Johnson295189b2012-06-20 16:38:30 -07001869 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301870 vos_mem_set(pSession->pCurRoamProfile, sizeof(tCsrRoamProfile), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001871 csrRoamCopyProfile(pMac, pSession->pCurRoamProfile, pProfile);
1872 }
1873 csrRoamStartJoinRetryTimer(pMac, sessionId, CSR_JOIN_RETRY_TIMEOUT_PERIOD);
1874 }
1875#endif
1876 }
1877 else
1878 {
1879 roamResult = eCSR_ROAM_RESULT_IBSS_START_FAILED;
1880 }
1881 csrRoamCompletion(pMac, sessionId, NULL, pCommand, roamResult, eANI_BOOLEAN_FALSE);
1882 }
1883
1884 return (status);
1885}
1886
1887
1888//After scan for cap changes, issue a roaming command to either reconnect to the AP or pick another one to connect
1889eHalStatus csrScanHandleCapChangeScanComplete(tpAniSirGlobal pMac, tANI_U32 sessionId)
1890{
1891 eHalStatus status = eHAL_STATUS_FAILURE;
1892 tScanResultHandle hBSSList = NULL;
1893 tCsrScanResultFilter *pScanFilter = NULL;
1894 tANI_U32 roamId = 0;
1895 tCsrRoamProfile *pProfile = NULL;
1896 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1897
1898 do
1899 {
1900 //Here is the profile we need to connect to
Kiet Lam64c1b492013-07-12 13:56:44 +05301901 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1902 if ( NULL == pScanFilter )
1903 status = eHAL_STATUS_FAILURE;
1904 else
1905 status = eHAL_STATUS_SUCCESS;
1906 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001907 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301908 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
1909 if (NULL == pSession) break;
1910 if (NULL == pSession->pCurRoamProfile)
Jeff Johnson295189b2012-06-20 16:38:30 -07001911 {
1912 pScanFilter->EncryptionType.numEntries = 1;
1913 pScanFilter->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_NONE;
1914 }
1915 else
1916 {
1917 //We have to make a copy of pCurRoamProfile because it will be free inside csrRoamIssueConnect
Kiet Lam64c1b492013-07-12 13:56:44 +05301918 pProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1919 if ( NULL == pProfile )
1920 status = eHAL_STATUS_FAILURE;
1921 else
1922 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001923 if(!HAL_STATUS_SUCCESS(status))
1924 break;
1925 status = csrRoamCopyProfile(pMac, pProfile, pSession->pCurRoamProfile);
1926 if(!HAL_STATUS_SUCCESS(status))
1927 break;
1928 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1929 }//We have a profile
1930 roamId = GET_NEXT_ROAM_ID(&pMac->roam);
1931 if(HAL_STATUS_SUCCESS(status))
1932 {
1933 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1934 if(HAL_STATUS_SUCCESS(status))
1935 {
1936 //we want to put the last connected BSS to the very beginning, if possible
1937 csrMoveBssToHeadFromBSSID(pMac, &pSession->connectedProfile.bssid, hBSSList);
1938 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList,
1939 eCsrCapsChange, 0, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1940 if(!HAL_STATUS_SUCCESS(status))
1941 {
1942 csrScanResultPurge(pMac, hBSSList);
1943 }
1944 }//Have scan result
1945 else
1946 {
Arif Hussaina7c8e412013-11-20 11:06:42 -08001947 smsLog(pMac, LOGW, FL("cannot find matching BSS of "
1948 MAC_ADDRESS_STR),
1949 MAC_ADDR_ARRAY(pSession->connectedProfile.bssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001950 //Disconnect
1951 csrRoamDisconnectInternal(pMac, sessionId, eCSR_DISCONNECT_REASON_UNSPECIFIED);
1952 }
1953 }
1954 }while(0);
1955 if(pScanFilter)
1956 {
1957 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301958 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001959 }
1960 if(NULL != pProfile)
1961 {
1962 csrReleaseProfile(pMac, pProfile);
Kiet Lam64c1b492013-07-12 13:56:44 +05301963 vos_mem_free(pProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07001964 }
1965
1966 return (status);
1967}
1968
1969
1970
1971eHalStatus csrScanResultPurge(tpAniSirGlobal pMac, tScanResultHandle hScanList)
1972{
1973 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
1974 tScanResultList *pScanList = (tScanResultList *)hScanList;
1975
1976 if(pScanList)
1977 {
1978 status = csrLLScanPurgeResult(pMac, &pScanList->List);
1979 csrLLClose(&pScanList->List);
Kiet Lam64c1b492013-07-12 13:56:44 +05301980 vos_mem_free(pScanList);
Jeff Johnson295189b2012-06-20 16:38:30 -07001981 }
1982 return (status);
1983}
1984
1985
1986static tANI_U32 csrGetBssPreferValue(tpAniSirGlobal pMac, int rssi)
1987{
1988 tANI_U32 ret = 0;
1989 int i = CSR_NUM_RSSI_CAT - 1;
1990
1991 while(i >= 0)
1992 {
1993 if(rssi >= pMac->roam.configParam.RSSICat[i])
1994 {
1995 ret = pMac->roam.configParam.BssPreferValue[i];
1996 break;
1997 }
1998 i--;
1999 };
2000
2001 return (ret);
2002}
2003
2004
2005//Return a CapValue base on the capabilities of a BSS
2006static tANI_U32 csrGetBssCapValue(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes)
2007{
2008 tANI_U32 ret = CSR_BSS_CAP_VALUE_NONE;
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08002009#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_ESE) || defined(FEATURE_WLAN_LFR)
Madan Mohan Koyyalamudid5026072012-11-30 14:56:21 -08002010 if(CSR_IS_ROAM_PREFER_5GHZ(pMac))
2011 {
2012 if((pBssDesc) && CSR_IS_CHANNEL_5GHZ(pBssDesc->channelId))
2013 {
2014 ret += CSR_BSS_CAP_VALUE_5GHZ;
2015 }
2016 }
2017#endif
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002018 /* if strict select 5GHz is non-zero then ignore the capability checking */
2019 if (pIes && !CSR_IS_SELECT_5GHZ_MARGIN(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -07002020 {
2021 //We only care about 11N capability
2022 if(pIes->HTCaps.present)
2023 {
2024 ret += CSR_BSS_CAP_VALUE_HT;
2025 }
2026 if(CSR_IS_QOS_BSS(pIes))
2027 {
2028 ret += CSR_BSS_CAP_VALUE_WMM;
2029 //Give advantage to UAPSD
2030 if(CSR_IS_UAPSD_BSS(pIes))
2031 {
2032 ret += CSR_BSS_CAP_VALUE_UAPSD;
2033 }
2034 }
2035 }
2036
2037 return (ret);
2038}
2039
2040
2041//To check whther pBss1 is better than pBss2
2042static tANI_BOOLEAN csrIsBetterBss(tCsrScanResult *pBss1, tCsrScanResult *pBss2)
2043{
2044 tANI_BOOLEAN ret;
2045
2046 if(CSR_IS_BETTER_PREFER_VALUE(pBss1->preferValue, pBss2->preferValue))
2047 {
2048 ret = eANI_BOOLEAN_TRUE;
2049 }
2050 else if(CSR_IS_EQUAL_PREFER_VALUE(pBss1->preferValue, pBss2->preferValue))
2051 {
2052 if(CSR_IS_BETTER_CAP_VALUE(pBss1->capValue, pBss2->capValue))
2053 {
2054 ret = eANI_BOOLEAN_TRUE;
2055 }
2056 else
2057 {
2058 ret = eANI_BOOLEAN_FALSE;
2059 }
2060 }
2061 else
2062 {
2063 ret = eANI_BOOLEAN_FALSE;
2064 }
2065
2066 return (ret);
2067}
2068
2069
Srikant Kuppa866893f2012-12-27 17:28:14 -08002070#ifdef FEATURE_WLAN_LFR
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002071//Add the channel to the occupiedChannels array
2072static void csrScanAddToOccupiedChannels(
Srikant Kuppa866893f2012-12-27 17:28:14 -08002073 tpAniSirGlobal pMac,
2074 tCsrScanResult *pResult,
2075 tCsrChannel *pOccupiedChannels,
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002076 tDot11fBeaconIEs *pIes)
2077{
2078 eHalStatus status;
2079 tANI_U8 channel;
2080 tANI_U8 numOccupiedChannels = pOccupiedChannels->numChannels;
2081 tANI_U8 *pOccupiedChannelList = pOccupiedChannels->channelList;
2082
2083 channel = pResult->Result.BssDescriptor.channelId;
2084
2085 if (!csrIsChannelPresentInList(pOccupiedChannelList, numOccupiedChannels, channel)
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08002086 && csrNeighborRoamConnectedProfileMatch(pMac, pResult, pIes))
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002087 {
Srikant Kuppa866893f2012-12-27 17:28:14 -08002088 status = csrAddToChannelListFront(pOccupiedChannelList, numOccupiedChannels, channel);
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002089 if(HAL_STATUS_SUCCESS(status))
Srikant Kuppa866893f2012-12-27 17:28:14 -08002090 {
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002091 pOccupiedChannels->numChannels++;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002092 smsLog(pMac, LOG2, FL("%s: added channel %d to the list (count=%d)"),
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08002093 __func__, channel, pOccupiedChannels->numChannels);
Srikant Kuppa866893f2012-12-27 17:28:14 -08002094 if (pOccupiedChannels->numChannels > CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN)
2095 pOccupiedChannels->numChannels = CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN;
2096 }
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002097 }
2098}
Mukul Sharma9e4e0f92015-02-13 18:45:20 +05302099
2100void csrAddChannelToOccupiedChannelList(tpAniSirGlobal pMac,
2101 tANI_U8 channel)
2102{
2103 eHalStatus status;
2104 tCsrChannel *pOccupiedChannels = &pMac->scan.occupiedChannels;
2105 tANI_U8 numOccupiedChannels = pOccupiedChannels->numChannels;
2106 tANI_U8 *pOccupiedChannelList = pOccupiedChannels->channelList;
2107 if (!csrIsChannelPresentInList(pOccupiedChannelList,
2108 numOccupiedChannels, channel))
2109 {
2110 status = csrAddToChannelListFront(pOccupiedChannelList,
2111 numOccupiedChannels, channel);
2112 if(HAL_STATUS_SUCCESS(status))
2113 {
2114 pOccupiedChannels->numChannels++;
2115 smsLog(pMac, LOG2, FL("added channel %d to the list (count=%d)"),
2116 channel, pOccupiedChannels->numChannels);
2117 if (pOccupiedChannels->numChannels >
2118 CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN)
2119 {
2120 pOccupiedChannels->numChannels =
2121 CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN;
2122 smsLog(pMac, LOG2,
2123 FL("trim no of Channels for Occ channel list"));
2124 }
2125 }
2126 }
2127}
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002128#endif
2129
Jeff Johnson295189b2012-06-20 16:38:30 -07002130//Put the BSS into the scan result list
2131//pIes can not be NULL
2132static void csrScanAddResult(tpAniSirGlobal pMac, tCsrScanResult *pResult, tDot11fBeaconIEs *pIes)
2133{
Srinivas28b5b4e2012-12-12 13:07:53 -08002134#ifdef FEATURE_WLAN_LFR
2135 tpCsrNeighborRoamControlInfo pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
2136#endif
2137
Jeff Johnson295189b2012-06-20 16:38:30 -07002138 pResult->preferValue = csrGetBssPreferValue(pMac, (int)pResult->Result.BssDescriptor.rssi);
2139 pResult->capValue = csrGetBssCapValue(pMac, &pResult->Result.BssDescriptor, pIes);
2140 csrLLInsertTail( &pMac->scan.scanResultList, &pResult->Link, LL_ACCESS_LOCK );
Srikant Kuppa866893f2012-12-27 17:28:14 -08002141#ifdef FEATURE_WLAN_LFR
Srinivas28b5b4e2012-12-12 13:07:53 -08002142 if(0 == pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels)
2143 {
2144 /* Build the occupied channel list, only if "gNeighborScanChannelList" is
2145 NOT set in the cfg.ini file */
2146 csrScanAddToOccupiedChannels(pMac, pResult, &pMac->scan.occupiedChannels, pIes);
2147 }
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002148#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002149}
2150
2151
2152eHalStatus csrScanGetResult(tpAniSirGlobal pMac, tCsrScanResultFilter *pFilter, tScanResultHandle *phResult)
2153{
2154 eHalStatus status;
2155 tScanResultList *pRetList;
2156 tCsrScanResult *pResult, *pBssDesc;
2157 tANI_U32 count = 0;
2158 tListElem *pEntry;
2159 tANI_U32 bssLen, allocLen;
2160 eCsrEncryptionType uc = eCSR_ENCRYPT_TYPE_NONE, mc = eCSR_ENCRYPT_TYPE_NONE;
2161 eCsrAuthType auth = eCSR_AUTH_TYPE_OPEN_SYSTEM;
2162 tDot11fBeaconIEs *pIes, *pNewIes;
2163 tANI_BOOLEAN fMatch;
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002164 tANI_U16 i = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07002165
2166 if(phResult)
2167 {
2168 *phResult = CSR_INVALID_SCANRESULT_HANDLE;
2169 }
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002170
2171 if (pMac->roam.configParam.nSelect5GHzMargin)
2172 {
2173 pMac->scan.inScanResultBestAPRssi = -128;
2174 csrLLLock(&pMac->scan.scanResultList);
2175
2176 /* Find out the best AP Rssi going thru the scan results */
2177 pEntry = csrLLPeekHead(&pMac->scan.scanResultList, LL_ACCESS_NOLOCK);
2178 while ( NULL != pEntry)
2179 {
2180 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002181 fMatch = FALSE;
2182
2183 if (pFilter)
2184 for(i = 0; i < pFilter->SSIDs.numOfSSIDs; i++)
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002185 {
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002186 fMatch = csrIsSsidMatch( pMac, pFilter->SSIDs.SSIDList[i].SSID.ssId, pFilter->SSIDs.SSIDList[i].SSID.length,
2187 pBssDesc->Result.ssId.ssId,
2188 pBssDesc->Result.ssId.length, eANI_BOOLEAN_TRUE );
2189 if (fMatch)
2190 {
2191 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
2192
2193 //At this time, pBssDescription->Result.pvIes may be NULL
2194 if( !pIes && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
2195 &pBssDesc->Result.BssDescriptor, &pIes))) )
2196 {
2197 continue;
2198 }
2199
2200 smsLog(pMac, LOG1, FL("SSID Matched"));
Leela Venkata Kiran Kumar Reddy Chiralae208a832014-04-27 22:34:25 -07002201
Leela Venkata Kiran Kumar Reddy Chiralaf257bef2014-04-11 18:48:12 -07002202 if ( pFilter->bOSENAssociation )
2203 {
2204 fMatch = TRUE;
2205 }
Leela Venkata Kiran Kumar Reddy Chiralae208a832014-04-27 22:34:25 -07002206 else
2207 {
Abhishek Singh658d4de2014-06-26 10:53:15 +05302208#ifdef WLAN_FEATURE_11W
Abhishek Singh3b56d3a2014-06-25 12:37:39 +05302209 fMatch = csrIsSecurityMatch(pMac, &pFilter->authType,
2210 &pFilter->EncryptionType,
2211 &pFilter->mcEncryptionType,
2212 &pFilter->MFPEnabled,
2213 &pFilter->MFPRequired,
2214 &pFilter->MFPCapable,
2215 &pBssDesc->Result.BssDescriptor,
2216 pIes, NULL, NULL, NULL );
Abhishek Singh658d4de2014-06-26 10:53:15 +05302217#else
2218 fMatch = csrIsSecurityMatch(pMac, &pFilter->authType,
2219 &pFilter->EncryptionType,
2220 &pFilter->mcEncryptionType,
2221 NULL, NULL, NULL,
2222 &pBssDesc->Result.BssDescriptor,
2223 pIes, NULL, NULL, NULL );
2224#endif
Leela Venkata Kiran Kumar Reddy Chiralae208a832014-04-27 22:34:25 -07002225 }
2226 if ((pBssDesc->Result.pvIes == NULL) && pIes)
2227 vos_mem_free(pIes);
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002228
2229 if (fMatch)
2230 smsLog(pMac, LOG1, FL(" Security Matched"));
2231 }
2232 }
2233
2234 if (fMatch && (pBssDesc->Result.BssDescriptor.rssi > pMac->scan.inScanResultBestAPRssi))
2235 {
2236 smsLog(pMac, LOG1, FL("Best AP Rssi changed from %d to %d"),
2237 pMac->scan.inScanResultBestAPRssi,
2238 pBssDesc->Result.BssDescriptor.rssi);
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002239 pMac->scan.inScanResultBestAPRssi = pBssDesc->Result.BssDescriptor.rssi;
2240 }
2241 pEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
2242 }
2243
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002244 if ( -128 != pMac->scan.inScanResultBestAPRssi)
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002245 {
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002246 smsLog(pMac, LOG1, FL("Best AP Rssi is %d"), pMac->scan.inScanResultBestAPRssi);
2247 /* Modify Rssi category based on best AP Rssi */
2248 csrAssignRssiForCategory(pMac, pMac->scan.inScanResultBestAPRssi, pMac->roam.configParam.bCatRssiOffset);
2249 pEntry = csrLLPeekHead(&pMac->scan.scanResultList, LL_ACCESS_NOLOCK);
2250 while ( NULL != pEntry)
2251 {
2252 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002253
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002254 /* re-assign preference value based on modified rssi bucket */
2255 pBssDesc->preferValue = csrGetBssPreferValue(pMac, (int)pBssDesc->Result.BssDescriptor.rssi);
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002256
Arif Hussaina7c8e412013-11-20 11:06:42 -08002257 smsLog(pMac, LOG2, FL("BSSID("MAC_ADDRESS_STR
Jeff Johnson123ed002013-11-22 17:39:55 -08002258 ") Rssi(%d) Chnl(%d) PrefVal(%u) SSID=%.*s"),
Arif Hussaina7c8e412013-11-20 11:06:42 -08002259 MAC_ADDR_ARRAY(pBssDesc->Result.BssDescriptor.bssId),
2260 pBssDesc->Result.BssDescriptor.rssi,
2261 pBssDesc->Result.BssDescriptor.channelId,
2262 pBssDesc->preferValue,
2263 pBssDesc->Result.ssId.length, pBssDesc->Result.ssId.ssId);
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002264
2265 pEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
2266 }
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002267 }
2268
2269 csrLLUnlock(&pMac->scan.scanResultList);
2270 }
2271
Kiet Lam64c1b492013-07-12 13:56:44 +05302272 pRetList = vos_mem_malloc(sizeof(tScanResultList));
2273 if ( NULL == pRetList )
2274 status = eHAL_STATUS_FAILURE;
2275 else
2276 status = eHAL_STATUS_SUCCESS;
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002277 if(HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07002278 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302279 vos_mem_set(pRetList, sizeof(tScanResultList), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002280 csrLLOpen(pMac->hHdd, &pRetList->List);
2281 pRetList->pCurEntry = NULL;
2282
2283 csrLLLock(&pMac->scan.scanResultList);
2284 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
2285 while( pEntry )
2286 {
2287 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2288 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
2289 //if pBssDesc->Result.pvIes is NULL, we need to free any memory allocated by csrMatchBSS
2290 //for any error condition, otherwiase, it will be freed later.
2291 //reset
2292 fMatch = eANI_BOOLEAN_FALSE;
2293 pNewIes = NULL;
2294
2295 if(pFilter)
2296 {
2297 fMatch = csrMatchBSS(pMac, &pBssDesc->Result.BssDescriptor, pFilter, &auth, &uc, &mc, &pIes);
2298 if( NULL != pIes )
2299 {
2300 //Only save it when matching
2301 if(fMatch)
2302 {
2303 if( !pBssDesc->Result.pvIes )
2304 {
2305 //csrMatchBSS allocates the memory. Simply pass it and it is freed later
2306 pNewIes = pIes;
2307 }
2308 else
2309 {
2310 //The pIes is allocated by someone else. make a copy
2311 //Only to save parsed IEs if caller provides a filter. Most likely the caller
2312 //is using to for association, hence save the parsed IEs
Kiet Lam64c1b492013-07-12 13:56:44 +05302313 pNewIes = vos_mem_malloc(sizeof(tDot11fBeaconIEs));
2314 if ( NULL == pNewIes )
2315 status = eHAL_STATUS_FAILURE;
2316 else
2317 status = eHAL_STATUS_SUCCESS;
2318 if ( HAL_STATUS_SUCCESS( status ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07002319 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302320 vos_mem_copy(pNewIes, pIes, sizeof( tDot11fBeaconIEs ));
Jeff Johnson295189b2012-06-20 16:38:30 -07002321 }
2322 else
2323 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002324 smsLog(pMac, LOGE, FL(" fail to allocate memory for IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002325 //Need to free memory allocated by csrMatchBSS
2326 if( !pBssDesc->Result.pvIes )
2327 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302328 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07002329 }
2330 break;
2331 }
2332 }
2333 }//fMatch
2334 else if( !pBssDesc->Result.pvIes )
2335 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302336 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07002337 }
2338 }
2339 }
2340 if(NULL == pFilter || fMatch)
2341 {
2342 bssLen = pBssDesc->Result.BssDescriptor.length + sizeof(pBssDesc->Result.BssDescriptor.length);
2343 allocLen = sizeof( tCsrScanResult ) + bssLen;
Kiet Lam64c1b492013-07-12 13:56:44 +05302344 pResult = vos_mem_malloc(allocLen);
2345 if ( NULL == pResult )
2346 status = eHAL_STATUS_FAILURE;
2347 else
2348 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07002349 if(!HAL_STATUS_SUCCESS(status))
2350 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002351 smsLog(pMac, LOGE, FL(" fail to allocate memory for scan result, len=%d"), allocLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07002352 if(pNewIes)
2353 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302354 vos_mem_free(pNewIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07002355 }
2356 break;
2357 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302358 vos_mem_set(pResult, allocLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002359 pResult->capValue = pBssDesc->capValue;
2360 pResult->preferValue = pBssDesc->preferValue;
2361 pResult->ucEncryptionType = uc;
2362 pResult->mcEncryptionType = mc;
2363 pResult->authType = auth;
2364 pResult->Result.ssId = pBssDesc->Result.ssId;
2365 pResult->Result.timer = 0;
2366 //save the pIes for later use
2367 pResult->Result.pvIes = pNewIes;
2368 //save bss description
Kiet Lam64c1b492013-07-12 13:56:44 +05302369 vos_mem_copy(&pResult->Result.BssDescriptor,
2370 &pBssDesc->Result.BssDescriptor, bssLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07002371 //No need to lock pRetList because it is locally allocated and no outside can access it at this time
2372 if(csrLLIsListEmpty(&pRetList->List, LL_ACCESS_NOLOCK))
2373 {
2374 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_NOLOCK);
2375 }
2376 else
2377 {
2378 //To sort the list
2379 tListElem *pTmpEntry;
2380 tCsrScanResult *pTmpResult;
2381
2382 pTmpEntry = csrLLPeekHead(&pRetList->List, LL_ACCESS_NOLOCK);
2383 while(pTmpEntry)
2384 {
2385 pTmpResult = GET_BASE_ADDR( pTmpEntry, tCsrScanResult, Link );
2386 if(csrIsBetterBss(pResult, pTmpResult))
2387 {
2388 csrLLInsertEntry(&pRetList->List, pTmpEntry, &pResult->Link, LL_ACCESS_NOLOCK);
2389 //To indicate we are done
2390 pResult = NULL;
2391 break;
2392 }
2393 pTmpEntry = csrLLNext(&pRetList->List, pTmpEntry, LL_ACCESS_NOLOCK);
2394 }
2395 if(pResult != NULL)
2396 {
2397 //This one is not better than any one
2398 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_NOLOCK);
2399 }
2400 }
2401 count++;
2402 }
2403 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK );
2404 }//while
2405 csrLLUnlock(&pMac->scan.scanResultList);
2406
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002407 smsLog(pMac, LOG2, FL("return %d BSS"), csrLLCount(&pRetList->List));
Jeff Johnson295189b2012-06-20 16:38:30 -07002408
2409 if( !HAL_STATUS_SUCCESS(status) || (phResult == NULL) )
2410 {
2411 //Fail or No one wants the result.
2412 csrScanResultPurge(pMac, (tScanResultHandle)pRetList);
2413 }
2414 else
2415 {
2416 if(0 == count)
2417 {
2418 //We are here meaning the there is no match
2419 csrLLClose(&pRetList->List);
Kiet Lam64c1b492013-07-12 13:56:44 +05302420 vos_mem_free(pRetList);
Jeff Johnson295189b2012-06-20 16:38:30 -07002421 status = eHAL_STATUS_E_NULL_VALUE;
2422 }
2423 else if(phResult)
2424 {
2425 *phResult = pRetList;
2426 }
2427 }
2428 }//Allocated pRetList
2429
2430 return (status);
2431}
2432
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002433/*
2434 * NOTE: This routine is being added to make
2435 * sure that scan results are not being flushed
2436 * while roaming. If the scan results are flushed,
2437 * we are unable to recover from
2438 * csrRoamRoamingStateDisassocRspProcessor.
2439 * If it is needed to remove this routine,
2440 * first ensure that we recover gracefully from
2441 * csrRoamRoamingStateDisassocRspProcessor if
2442 * csrScanGetResult returns with a failure because
2443 * of not being able to find the roaming BSS.
2444 */
2445tANI_U8 csrScanFlushDenied(tpAniSirGlobal pMac)
2446{
2447 switch(pMac->roam.neighborRoamInfo.neighborRoamState) {
2448 case eCSR_NEIGHBOR_ROAM_STATE_REPORT_SCAN:
2449 case eCSR_NEIGHBOR_ROAM_STATE_PREAUTHENTICATING:
2450 case eCSR_NEIGHBOR_ROAM_STATE_PREAUTH_DONE:
2451 case eCSR_NEIGHBOR_ROAM_STATE_REASSOCIATING:
2452 return (pMac->roam.neighborRoamInfo.neighborRoamState);
2453 default:
2454 return 0;
2455 }
2456}
2457
Jeff Johnson295189b2012-06-20 16:38:30 -07002458eHalStatus csrScanFlushResult(tpAniSirGlobal pMac)
2459{
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002460 tANI_U8 isFlushDenied = csrScanFlushDenied(pMac);
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302461 eHalStatus status = eHAL_STATUS_SUCCESS;
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002462 if (isFlushDenied) {
2463 smsLog(pMac, LOGW, "%s: scan flush denied in roam state %d",
2464 __func__, isFlushDenied);
2465 return eHAL_STATUS_FAILURE;
2466 }
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302467 csrLLScanPurgeResult( pMac, &pMac->scan.tempScanResults );
2468 csrLLScanPurgeResult( pMac, &pMac->scan.scanResultList );
2469 return( status );
Jeff Johnson295189b2012-06-20 16:38:30 -07002470}
2471
Mukul Sharma20aa6582014-08-07 21:36:12 +05302472eHalStatus csrScanFlushSelectiveResultForBand(tpAniSirGlobal pMac, v_BOOL_t flushP2P, tSirRFBand band)
2473{
2474 eHalStatus status = eHAL_STATUS_SUCCESS;
2475 tListElem *pEntry,*pFreeElem;
2476 tCsrScanResult *pBssDesc;
2477 tDblLinkList *pList = &pMac->scan.scanResultList;
2478
2479 csrLLLock(pList);
2480
2481 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK );
2482 while( pEntry != NULL)
2483 {
2484 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2485 if( (flushP2P == vos_mem_compare( pBssDesc->Result.ssId.ssId,
2486 "DIRECT-", 7)) &&
2487 (GetRFBand(pBssDesc->Result.BssDescriptor.channelId) == band)
2488 )
2489 {
2490 pFreeElem = pEntry;
2491 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2492 csrLLRemoveEntry(pList, pFreeElem, LL_ACCESS_NOLOCK);
2493 csrFreeScanResultEntry( pMac, pBssDesc );
2494 continue;
2495 }
2496 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2497 }
2498
2499 csrLLUnlock(pList);
2500
2501 return (status);
2502}
2503
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302504eHalStatus csrScanFlushSelectiveResult(tpAniSirGlobal pMac, v_BOOL_t flushP2P)
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002505{
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302506 eHalStatus status = eHAL_STATUS_SUCCESS;
2507 tListElem *pEntry,*pFreeElem;
2508 tCsrScanResult *pBssDesc;
2509 tDblLinkList *pList = &pMac->scan.scanResultList;
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002510
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302511 csrLLLock(pList);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002512
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302513 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK );
2514 while( pEntry != NULL)
2515 {
2516 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2517 if( flushP2P == vos_mem_compare( pBssDesc->Result.ssId.ssId,
2518 "DIRECT-", 7) )
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002519 {
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302520 pFreeElem = pEntry;
2521 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2522 csrLLRemoveEntry(pList, pFreeElem, LL_ACCESS_NOLOCK);
2523 csrFreeScanResultEntry( pMac, pBssDesc );
2524 continue;
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002525 }
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302526 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2527 }
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002528
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302529 csrLLUnlock(pList);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002530
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302531 return (status);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002532}
2533
Jeff Johnson295189b2012-06-20 16:38:30 -07002534/**
2535 * csrCheck11dChannel
2536 *
2537 *FUNCTION:
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302538 * This function is called from csrScanFilterResults function and
Jeff Johnson295189b2012-06-20 16:38:30 -07002539 * compare channel number with given channel list.
2540 *
2541 *LOGIC:
2542 * Check Scan result channel number with CFG channel list
2543 *
2544 *ASSUMPTIONS:
2545 *
2546 *
2547 *NOTE:
2548 *
2549 * @param channelId channel number
2550 * @param pChannelList Pointer to channel list
2551 * @param numChannels Number of channel in channel list
2552 *
2553 * @return Status
2554 */
2555
2556eHalStatus csrCheck11dChannel(tANI_U8 channelId, tANI_U8 *pChannelList, tANI_U32 numChannels)
2557{
2558 eHalStatus status = eHAL_STATUS_FAILURE;
2559 tANI_U8 i = 0;
2560
2561 for (i = 0; i < numChannels; i++)
2562 {
2563 if(pChannelList[ i ] == channelId)
2564 {
2565 status = eHAL_STATUS_SUCCESS;
2566 break;
2567 }
2568 }
2569 return status;
2570}
2571
2572/**
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302573 * csrScanFilterResults
Jeff Johnson295189b2012-06-20 16:38:30 -07002574 *
2575 *FUNCTION:
2576 * This function is called from csrApplyCountryInformation function and
2577 * filter scan result based on valid channel list number.
2578 *
2579 *LOGIC:
2580 * Get scan result from scan list and Check Scan result channel number
2581 * with 11d channel list if channel number is found in 11d channel list
2582 * then do not remove scan result entry from scan list
2583 *
2584 *ASSUMPTIONS:
2585 *
2586 *
2587 *NOTE:
2588 *
2589 * @param pMac Pointer to Global MAC structure
2590 *
2591 * @return Status
2592 */
2593
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302594eHalStatus csrScanFilterResults(tpAniSirGlobal pMac)
Jeff Johnson295189b2012-06-20 16:38:30 -07002595{
2596 eHalStatus status = eHAL_STATUS_SUCCESS;
2597 tListElem *pEntry,*pTempEntry;
2598 tCsrScanResult *pBssDesc;
2599 tANI_U32 len = sizeof(pMac->roam.validChannelList);
2600
2601 /* Get valid channels list from CFG */
2602 if (!HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac,
2603 pMac->roam.validChannelList, &len)))
2604 {
Agarwal Ashishe3cca2a2013-07-21 03:01:48 +05302605 smsLog( pMac, LOGE, "Failed to get Channel list from CFG");
Jeff Johnson295189b2012-06-20 16:38:30 -07002606 }
2607
2608 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
2609 while( pEntry )
2610 {
2611 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302612 pTempEntry = csrLLNext( &pMac->scan.scanResultList, pEntry,
Jeff Johnson295189b2012-06-20 16:38:30 -07002613 LL_ACCESS_LOCK );
2614 if(csrCheck11dChannel(pBssDesc->Result.BssDescriptor.channelId,
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302615 pMac->roam.validChannelList, len))
Jeff Johnson295189b2012-06-20 16:38:30 -07002616 {
2617 /* Remove Scan result which does not have 11d channel */
2618 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry,
2619 LL_ACCESS_LOCK ))
2620 {
2621 csrFreeScanResultEntry( pMac, pBssDesc );
2622 }
2623 }
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302624 pEntry = pTempEntry;
2625 }
2626
2627 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
2628 while( pEntry )
2629 {
2630 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2631 pTempEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry,
2632 LL_ACCESS_LOCK );
2633 if(csrCheck11dChannel(pBssDesc->Result.BssDescriptor.channelId,
2634 pMac->roam.validChannelList, len))
2635 {
2636 /* Remove Scan result which does not have 11d channel */
2637 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry,
2638 LL_ACCESS_LOCK ))
2639 {
2640 csrFreeScanResultEntry( pMac, pBssDesc );
2641 }
2642 }
2643 else
2644 {
2645 smsLog( pMac, LOG1, FL("%d is a Valid channel"),
2646 pBssDesc->Result.BssDescriptor.channelId);
2647 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002648 pEntry = pTempEntry;
2649 }
2650 return status;
2651}
2652
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05302653/**
2654 * csrScanFilterDFSResults
2655 *
2656 *FUNCTION:
2657 * This function filter BSSIDs on DFS channels from the scan results.
2658 *
2659 *LOGIC:
2660 * Get scan result from scan list and Check Scan result channel number
2661 * with 11d channel list if channel number is found in 11d channel list
2662 * and if fEnableDFSChnlScan is zero and if channel is DFS, then
2663 * remove scan result entry from scan list
2664 *
2665 *ASSUMPTIONS:
2666 *
2667 *NOTE:
2668 *
2669 * @param pMac Pointer to Global MAC structure
2670 *
2671 * @return Status
2672 */
2673
2674eHalStatus csrScanFilterDFSResults(tpAniSirGlobal pMac)
2675{
2676 eHalStatus status = eHAL_STATUS_SUCCESS;
2677 tListElem *pEntry,*pTempEntry;
2678 tCsrScanResult *pBssDesc;
2679
2680 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
2681 while( pEntry )
2682 {
2683 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2684 pTempEntry = csrLLNext( &pMac->scan.scanResultList, pEntry,
2685 LL_ACCESS_LOCK );
2686 if((pMac->scan.fEnableDFSChnlScan == DFS_CHNL_SCAN_DISABLED) &&
2687 CSR_IS_CHANNEL_DFS(pBssDesc->Result.BssDescriptor.channelId))
2688 {
2689 smsLog( pMac, LOG1, FL("%d is a DFS ch filtered from scan list"),
2690 pBssDesc->Result.BssDescriptor.channelId);
2691 /* Remove Scan result which does not have 11d channel */
2692 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry,
2693 LL_ACCESS_LOCK ))
2694 {
2695 csrFreeScanResultEntry( pMac, pBssDesc );
2696 }
2697 }
2698 else
2699 {
2700 smsLog( pMac, LOG1, FL("%d is a Valid channel"),
2701 pBssDesc->Result.BssDescriptor.channelId);
2702 }
2703 pEntry = pTempEntry;
2704 }
2705
2706 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
2707 while( pEntry )
2708 {
2709 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2710 pTempEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry,
2711 LL_ACCESS_LOCK );
2712
2713 if((pMac->scan.fEnableDFSChnlScan == DFS_CHNL_SCAN_DISABLED) &&
2714 CSR_IS_CHANNEL_DFS(pBssDesc->Result.BssDescriptor.channelId))
2715 {
2716 smsLog( pMac, LOG1, FL("%d is a DFS ch filtered from scan list"),
2717 pBssDesc->Result.BssDescriptor.channelId);
2718 /* Remove Scan result which does not have 11d channel */
2719 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry,
2720 LL_ACCESS_LOCK ))
2721 {
2722 csrFreeScanResultEntry( pMac, pBssDesc );
2723 }
2724 }
2725 else
2726 {
2727 smsLog( pMac, LOG1, FL("%d is a Valid channel"),
2728 pBssDesc->Result.BssDescriptor.channelId);
2729 }
2730 pEntry = pTempEntry;
2731 }
2732 return status;
2733}
2734
Jeff Johnson295189b2012-06-20 16:38:30 -07002735
2736eHalStatus csrScanCopyResultList(tpAniSirGlobal pMac, tScanResultHandle hIn, tScanResultHandle *phResult)
2737{
2738 eHalStatus status = eHAL_STATUS_SUCCESS;
2739 tScanResultList *pRetList, *pInList = (tScanResultList *)hIn;
2740 tCsrScanResult *pResult, *pScanResult;
2741 tANI_U32 count = 0;
2742 tListElem *pEntry;
2743 tANI_U32 bssLen, allocLen;
2744
2745 if(phResult)
2746 {
2747 *phResult = CSR_INVALID_SCANRESULT_HANDLE;
2748 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302749 pRetList = vos_mem_malloc(sizeof(tScanResultList));
2750 if ( NULL == pRetList )
2751 status = eHAL_STATUS_FAILURE;
2752 else
Jeff Johnson295189b2012-06-20 16:38:30 -07002753 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302754 vos_mem_set(pRetList, sizeof(tScanResultList), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002755 csrLLOpen(pMac->hHdd, &pRetList->List);
2756 pRetList->pCurEntry = NULL;
2757 csrLLLock(&pMac->scan.scanResultList);
2758 csrLLLock(&pInList->List);
2759
2760 pEntry = csrLLPeekHead( &pInList->List, LL_ACCESS_NOLOCK );
2761 while( pEntry )
2762 {
2763 pScanResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2764 bssLen = pScanResult->Result.BssDescriptor.length + sizeof(pScanResult->Result.BssDescriptor.length);
2765 allocLen = sizeof( tCsrScanResult ) + bssLen;
Kiet Lam64c1b492013-07-12 13:56:44 +05302766 pResult = vos_mem_malloc(allocLen);
2767 if ( NULL == pResult )
2768 status = eHAL_STATUS_FAILURE;
2769 else
2770 status = eHAL_STATUS_SUCCESS;
2771 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07002772 {
2773 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
2774 count = 0;
2775 break;
2776 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302777 vos_mem_set(pResult, allocLen , 0);
2778 vos_mem_copy(&pResult->Result.BssDescriptor, &pScanResult->Result.BssDescriptor, bssLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07002779 if( pScanResult->Result.pvIes )
2780 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302781 pResult->Result.pvIes = vos_mem_malloc(sizeof( tDot11fBeaconIEs ));
2782 if ( NULL == pResult->Result.pvIes )
2783 status = eHAL_STATUS_FAILURE;
2784 else
2785 status = eHAL_STATUS_SUCCESS;
2786 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07002787 {
2788 //Free the memory we allocate above first
Kiet Lam64c1b492013-07-12 13:56:44 +05302789 vos_mem_free(pResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07002790 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
2791 count = 0;
2792 break;
2793 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302794 vos_mem_copy(pResult->Result.pvIes, pScanResult->Result.pvIes,
2795 sizeof( tDot11fBeaconIEs ));
Jeff Johnson295189b2012-06-20 16:38:30 -07002796 }
2797 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_LOCK);
2798 count++;
2799 pEntry = csrLLNext( &pInList->List, pEntry, LL_ACCESS_NOLOCK );
2800 }//while
2801 csrLLUnlock(&pInList->List);
2802 csrLLUnlock(&pMac->scan.scanResultList);
2803
2804 if(HAL_STATUS_SUCCESS(status))
2805 {
2806 if(0 == count)
2807 {
2808 csrLLClose(&pRetList->List);
Kiet Lam64c1b492013-07-12 13:56:44 +05302809 vos_mem_free(pRetList);
Jeff Johnson295189b2012-06-20 16:38:30 -07002810 status = eHAL_STATUS_E_NULL_VALUE;
2811 }
2812 else if(phResult)
2813 {
2814 *phResult = pRetList;
2815 }
2816 }
2817 }//Allocated pRetList
2818
2819 return (status);
2820}
2821
2822
2823
2824eHalStatus csrScanningStateMsgProcessor( tpAniSirGlobal pMac, void *pMsgBuf )
2825{
2826 eHalStatus status = eHAL_STATUS_SUCCESS;
2827 tSirMbMsg *pMsg = (tSirMbMsg *)pMsgBuf;
Hanumantha Reddy Pothula1b6eb2f2015-11-30 20:50:23 +05302828 tSirSmeDisConDoneInd *pDisConDoneInd;
2829 tCsrRoamInfo roamInfo = {0};
Jeff Johnson295189b2012-06-20 16:38:30 -07002830
Hanumantha Reddy Pothula1b6eb2f2015-11-30 20:50:23 +05302831 if((eWNI_SME_SCAN_RSP == pMsg->type) ||
2832 (eWNI_SME_GET_SCANNED_CHANNEL_RSP == pMsg->type))
Jeff Johnson295189b2012-06-20 16:38:30 -07002833 {
2834 status = csrScanSmeScanResponse( pMac, pMsgBuf );
2835 }
2836 else
2837 {
Hanumantha Reddy Pothula1b6eb2f2015-11-30 20:50:23 +05302838 switch (pMsg->type)
Jeff Johnson295189b2012-06-20 16:38:30 -07002839 {
Hanumantha Reddy Pothula1b6eb2f2015-11-30 20:50:23 +05302840 case eWNI_SME_UPPER_LAYER_ASSOC_CNF:
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002841 {
Hanumantha Reddy Pothula1b6eb2f2015-11-30 20:50:23 +05302842 tCsrRoamSession *pSession;
2843 tSirSmeAssocIndToUpperLayerCnf *pUpperLayerAssocCnf;
2844 tCsrRoamInfo *pRoamInfo = NULL;
2845 tANI_U32 sessionId;
2846 eHalStatus status;
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002847
Hanumantha Reddy Pothula1b6eb2f2015-11-30 20:50:23 +05302848 smsLog( pMac, LOG1,
2849 FL("Scanning : ASSOCIATION confirmation can be given to upper layer "));
2850 pRoamInfo = &roamInfo;
2851 pUpperLayerAssocCnf = (tSirSmeAssocIndToUpperLayerCnf *)pMsgBuf;
2852 status = csrRoamGetSessionIdFromBSSID( pMac,
2853 (tCsrBssid *)pUpperLayerAssocCnf->bssId,
2854 &sessionId );
2855 pSession = CSR_GET_SESSION(pMac, sessionId);
2856
2857 if(!pSession)
2858 {
2859 smsLog(pMac, LOGE, FL("session %d not found "), sessionId);
2860 return eHAL_STATUS_FAILURE;
2861 }
2862
2863 //send the status code as Success
2864 pRoamInfo->statusCode = eSIR_SME_SUCCESS;
2865 pRoamInfo->u.pConnectedProfile = &pSession->connectedProfile;
2866 pRoamInfo->staId = (tANI_U8)pUpperLayerAssocCnf->aid;
2867 pRoamInfo->rsnIELen =
2868 (tANI_U8)pUpperLayerAssocCnf->rsnIE.length;
2869 pRoamInfo->prsnIE = pUpperLayerAssocCnf->rsnIE.rsnIEdata;
2870 pRoamInfo->addIELen =
2871 (tANI_U8)pUpperLayerAssocCnf->addIE.length;
2872 pRoamInfo->paddIE = pUpperLayerAssocCnf->addIE.addIEdata;
2873 vos_mem_copy(pRoamInfo->peerMac,
2874 pUpperLayerAssocCnf->peerMacAddr,
2875 sizeof(tSirMacAddr));
2876 vos_mem_copy(&pRoamInfo->bssid,
2877 pUpperLayerAssocCnf->bssId,
2878 sizeof(tCsrBssid));
2879 pRoamInfo->wmmEnabledSta = pUpperLayerAssocCnf->wmmEnabledSta;
Hardik Kantilal Patel1ba630f2014-11-21 04:32:05 +05302880#ifdef WLAN_FEATURE_AP_HT40_24G
Hanumantha Reddy Pothula1b6eb2f2015-11-30 20:50:23 +05302881 pRoamInfo->HT40MHzIntoEnabledSta =
2882 pUpperLayerAssocCnf->HT40MHzIntoEnabledSta;
Hardik Kantilal Patel1ba630f2014-11-21 04:32:05 +05302883#endif
Hanumantha Reddy Pothula1b6eb2f2015-11-30 20:50:23 +05302884 if(CSR_IS_INFRA_AP(pRoamInfo->u.pConnectedProfile) )
2885 {
2886 pMac->roam.roamSession[sessionId].connectState =
2887 eCSR_ASSOC_STATE_TYPE_INFRA_CONNECTED;
2888 pRoamInfo->fReassocReq = pUpperLayerAssocCnf->reassocReq;
2889 status = csrRoamCallCallback(pMac, sessionId, pRoamInfo,
2890 0, eCSR_ROAM_INFRA_IND,
2891 eCSR_ROAM_RESULT_INFRA_ASSOCIATION_CNF);
2892 }
2893 if(CSR_IS_WDS_AP( pRoamInfo->u.pConnectedProfile))
2894 {
2895 vos_sleep( 100 );
2896 pMac->roam.roamSession[sessionId].connectState =
2897 eCSR_ASSOC_STATE_TYPE_WDS_CONNECTED;//Sta
2898 status = csrRoamCallCallback(pMac, sessionId, pRoamInfo, 0,
2899 eCSR_ROAM_WDS_IND,
2900 eCSR_ROAM_RESULT_WDS_ASSOCIATION_IND);//Sta
2901 }
2902 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07002903 }
Hanumantha Reddy Pothula1b6eb2f2015-11-30 20:50:23 +05302904 case eWNI_SME_DISCONNECT_DONE_IND:
2905 pDisConDoneInd = (tSirSmeDisConDoneInd *)(pMsg);
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002906
Hanumantha Reddy Pothula1b6eb2f2015-11-30 20:50:23 +05302907 smsLog( pMac, LOG1,
2908 FL("eWNI_SME_DISCONNECT_DONE_IND RC:%d"),
2909 pDisConDoneInd->reasonCode);
2910 if( CSR_IS_SESSION_VALID(pMac, pDisConDoneInd->sessionId))
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002911 {
Hanumantha Reddy Pothula1b6eb2f2015-11-30 20:50:23 +05302912 roamInfo.reasonCode = pDisConDoneInd->reasonCode;
2913 roamInfo.statusCode = eSIR_SME_STA_DISASSOCIATED;
2914 vos_mem_copy(roamInfo.peerMac, pDisConDoneInd->peerMacAddr,
2915 sizeof(tSirMacAddr));
2916 status = csrRoamCallCallback(pMac,
2917 pDisConDoneInd->sessionId,
2918 &roamInfo, 0,
2919 eCSR_ROAM_LOSTLINK,
2920 eCSR_ROAM_RESULT_DISASSOC_IND);
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002921 }
2922 else
2923 {
Hanumantha Reddy Pothula1b6eb2f2015-11-30 20:50:23 +05302924 smsLog(pMac, LOGE, FL("Inactive session %d"),
2925 pDisConDoneInd->sessionId);
2926 status = eHAL_STATUS_FAILURE;
2927 }
2928 break;
2929
2930 default :
2931 if( csrIsAnySessionInConnectState( pMac ) )
2932 {
2933 /*In case of we are connected, we need to check whether connect
2934 * status changes because scan may also run while connected.
2935 */
2936 csrRoamCheckForLinkStatusChange( pMac, (tSirSmeRsp *)pMsgBuf );
2937 }
2938 else
2939 {
2940 smsLog( pMac, LOGW,
2941 "Message [0x%04x] received in state, when expecting Scan Response",
2942 pMsg->type );
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002943 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002944 }
2945 }
2946
2947 return (status);
2948}
2949
2950
2951
2952void csrCheckNSaveWscIe(tpAniSirGlobal pMac, tSirBssDescription *pNewBssDescr, tSirBssDescription *pOldBssDescr)
2953{
2954 int idx, len;
2955 tANI_U8 *pbIe;
2956
2957 //If failed to remove, assuming someone else got it.
2958 if((pNewBssDescr->fProbeRsp != pOldBssDescr->fProbeRsp) &&
2959 (0 == pNewBssDescr->WscIeLen))
2960 {
2961 idx = 0;
2962 len = pOldBssDescr->length - sizeof(tSirBssDescription) +
2963 sizeof(tANI_U16) + sizeof(tANI_U32) - DOT11F_IE_WSCPROBERES_MIN_LEN - 2;
2964 pbIe = (tANI_U8 *)pOldBssDescr->ieFields;
2965 //Save WPS IE if it exists
2966 pNewBssDescr->WscIeLen = 0;
2967 while(idx < len)
2968 {
2969 if((DOT11F_EID_WSCPROBERES == pbIe[0]) &&
2970 (0x00 == pbIe[2]) && (0x50 == pbIe[3]) && (0xf2 == pbIe[4]) && (0x04 == pbIe[5]))
2971 {
2972 //Founrd it
2973 if((DOT11F_IE_WSCPROBERES_MAX_LEN - 2) >= pbIe[1])
2974 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302975 vos_mem_copy(pNewBssDescr->WscIeProbeRsp, pbIe, pbIe[1] + 2);
Jeff Johnson295189b2012-06-20 16:38:30 -07002976 pNewBssDescr->WscIeLen = pbIe[1] + 2;
2977 }
2978 break;
2979 }
2980 idx += pbIe[1] + 2;
2981 pbIe += pbIe[1] + 2;
2982 }
2983 }
2984}
2985
2986
2987
2988//pIes may be NULL
2989tANI_BOOLEAN csrRemoveDupBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDescr,
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05302990 tDot11fBeaconIEs *pIes, tAniSSID *pSsid, v_TIME_t *timer, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07002991{
2992 tListElem *pEntry;
2993
2994 tCsrScanResult *pBssDesc;
2995 tANI_BOOLEAN fRC = FALSE;
2996
2997 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
2998 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
2999 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
3000 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
3001
3002 while( pEntry )
3003 {
3004 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3005
3006 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
3007 // matches
3008 if ( csrIsDuplicateBssDescription( pMac, &pBssDesc->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07003009 pSirBssDescr, pIes, fForced ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003010 {
3011 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
3012 ((tANI_S32)pBssDesc->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
3013 // Remove the 'old' entry from the list....
3014 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry, LL_ACCESS_LOCK ) )
3015 {
3016 // !we need to free the memory associated with this node
3017 //If failed to remove, assuming someone else got it.
3018 *pSsid = pBssDesc->Result.ssId;
3019 *timer = pBssDesc->Result.timer;
3020 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pBssDesc->Result.BssDescriptor);
3021
3022 csrFreeScanResultEntry( pMac, pBssDesc );
3023 }
3024 else
3025 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003026 smsLog( pMac, LOGW, FL( " fail to remove entry" ) );
Jeff Johnson295189b2012-06-20 16:38:30 -07003027 }
3028 fRC = TRUE;
3029
3030 // If we found a match, we can stop looking through the list.
3031 break;
3032 }
3033
3034 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_LOCK );
3035 }
3036
3037 return fRC;
3038}
3039
3040
3041eHalStatus csrAddPMKIDCandidateList( tpAniSirGlobal pMac, tANI_U32 sessionId,
3042 tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes )
3043{
3044 eHalStatus status = eHAL_STATUS_FAILURE;
3045 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
3046
Jeff Johnson32d95a32012-09-10 13:15:23 -07003047 if(!pSession)
3048 {
3049 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
3050 return eHAL_STATUS_FAILURE;
3051 }
3052
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003053 smsLog(pMac, LOGW, "csrAddPMKIDCandidateList called pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07003054 if( pIes )
3055 {
3056 // check if this is a RSN BSS
3057 if( pIes->RSN.present )
3058 {
3059 // Check if the BSS is capable of doing pre-authentication
3060 if( pSession->NumPmkidCandidate < CSR_MAX_PMKID_ALLOWED )
3061 {
3062
3063#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3064 {
3065 WLAN_VOS_DIAG_EVENT_DEF(secEvent, vos_event_wlan_security_payload_type);
Kiet Lam64c1b492013-07-12 13:56:44 +05303066 vos_mem_set(&secEvent, sizeof(vos_event_wlan_security_payload_type), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003067 secEvent.eventId = WLAN_SECURITY_EVENT_PMKID_CANDIDATE_FOUND;
3068 secEvent.encryptionModeMulticast =
3069 (v_U8_t)diagEncTypeFromCSRType(pSession->connectedProfile.mcEncryptionType);
3070 secEvent.encryptionModeUnicast =
3071 (v_U8_t)diagEncTypeFromCSRType(pSession->connectedProfile.EncryptionType);
Kiet Lam64c1b492013-07-12 13:56:44 +05303072 vos_mem_copy(secEvent.bssid, pSession->connectedProfile.bssid, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07003073 secEvent.authMode =
3074 (v_U8_t)diagAuthTypeFromCSRType(pSession->connectedProfile.AuthType);
3075 WLAN_VOS_DIAG_EVENT_REPORT(&secEvent, EVENT_WLAN_SECURITY);
3076 }
3077#endif//#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3078
3079 // if yes, then add to PMKIDCandidateList
Kiet Lam64c1b492013-07-12 13:56:44 +05303080 vos_mem_copy(pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].BSSID,
3081 pBssDesc->bssId, WNI_CFG_BSSID_LEN);
3082 // Bit 0 offirst byte - PreAuthentication Capability
3083 if ( (pIes->RSN.RSN_Cap[0] >> 0) & 0x1 )
Jeff Johnson295189b2012-06-20 16:38:30 -07003084 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303085 pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].preAuthSupported
3086 = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003087 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303088 else
3089 {
3090 pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].preAuthSupported
3091 = eANI_BOOLEAN_FALSE;
3092 }
3093 pSession->NumPmkidCandidate++;
Jeff Johnson295189b2012-06-20 16:38:30 -07003094 }
3095 else
3096 {
3097 status = eHAL_STATUS_FAILURE;
3098 }
3099 }
3100 }
3101
3102 return (status);
3103}
3104
3105//This function checks whether new AP is found for the current connected profile
3106//If it is found, it return the sessionId, else it return invalid sessionID
3107tANI_U32 csrProcessBSSDescForPMKIDList(tpAniSirGlobal pMac,
3108 tSirBssDescription *pBssDesc,
3109 tDot11fBeaconIEs *pIes)
3110{
3111 tANI_U32 i, bRet = CSR_SESSION_ID_INVALID;
3112 tCsrRoamSession *pSession;
3113 tDot11fBeaconIEs *pIesLocal = pIes;
3114
3115 if( pIesLocal || HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIesLocal)) )
3116 {
3117 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
3118 {
3119 if( CSR_IS_SESSION_VALID( pMac, i ) )
3120 {
3121 pSession = CSR_GET_SESSION( pMac, i );
3122 if( csrIsConnStateConnectedInfra( pMac, i ) &&
3123 ( eCSR_AUTH_TYPE_RSN == pSession->connectedProfile.AuthType ) )
3124 {
3125 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile, pBssDesc, pIesLocal))
3126 {
3127 //this new BSS fits the current profile connected
3128 if(HAL_STATUS_SUCCESS(csrAddPMKIDCandidateList(pMac, i, pBssDesc, pIesLocal)))
3129 {
3130 bRet = i;
3131 }
3132 break;
3133 }
3134 }
3135 }
3136 }
3137 if( !pIes )
3138 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303139 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003140 }
3141 }
3142
3143 return (tANI_U8)bRet;
3144}
3145
3146#ifdef FEATURE_WLAN_WAPI
3147eHalStatus csrAddBKIDCandidateList( tpAniSirGlobal pMac, tANI_U32 sessionId,
3148 tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes )
3149{
3150 eHalStatus status = eHAL_STATUS_FAILURE;
3151 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
3152
Jeff Johnson32d95a32012-09-10 13:15:23 -07003153 if(!pSession)
3154 {
3155 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
3156 return eHAL_STATUS_FAILURE;
3157 }
3158
Kiet Lam64c1b492013-07-12 13:56:44 +05303159 smsLog(pMac, LOGW, "csrAddBKIDCandidateList called pMac->scan.NumBkidCandidate = %d",
3160 pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07003161 if( pIes )
3162 {
3163 // check if this is a WAPI BSS
3164 if( pIes->WAPI.present )
3165 {
3166 // Check if the BSS is capable of doing pre-authentication
3167 if( pSession->NumBkidCandidate < CSR_MAX_BKID_ALLOWED )
3168 {
3169
3170 // if yes, then add to BKIDCandidateList
Kiet Lam64c1b492013-07-12 13:56:44 +05303171 vos_mem_copy(pSession->BkidCandidateInfo[pSession->NumBkidCandidate].BSSID,
3172 pBssDesc->bssId, WNI_CFG_BSSID_LEN);
3173 if ( pIes->WAPI.preauth )
Jeff Johnson295189b2012-06-20 16:38:30 -07003174 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303175 pSession->BkidCandidateInfo[pSession->NumBkidCandidate].preAuthSupported
3176 = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003177 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303178 else
3179 {
3180 pSession->BkidCandidateInfo[pSession->NumBkidCandidate].preAuthSupported
3181 = eANI_BOOLEAN_FALSE;
3182 }
3183 pSession->NumBkidCandidate++;
Jeff Johnson295189b2012-06-20 16:38:30 -07003184 }
3185 else
3186 {
3187 status = eHAL_STATUS_FAILURE;
3188 }
3189 }
3190 }
3191
3192 return (status);
3193}
3194
3195//This function checks whether new AP is found for the current connected profile
3196//if so add to BKIDCandidateList
3197tANI_BOOLEAN csrProcessBSSDescForBKIDList(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
3198 tDot11fBeaconIEs *pIes)
3199{
3200 tANI_BOOLEAN fRC = FALSE;
3201 tDot11fBeaconIEs *pIesLocal = pIes;
3202 tANI_U32 sessionId;
3203 tCsrRoamSession *pSession;
3204
3205 if( pIesLocal || HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIesLocal)) )
3206 {
3207 for( sessionId = 0; sessionId < CSR_ROAM_SESSION_MAX; sessionId++ )
3208 {
3209 if( CSR_IS_SESSION_VALID( pMac, sessionId) )
3210 {
3211 pSession = CSR_GET_SESSION( pMac, sessionId );
3212 if( csrIsConnStateConnectedInfra( pMac, sessionId ) &&
3213 eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE == pSession->connectedProfile.AuthType)
3214 {
3215 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile,pBssDesc, pIesLocal))
3216 {
3217 //this new BSS fits the current profile connected
3218 if(HAL_STATUS_SUCCESS(csrAddBKIDCandidateList(pMac, sessionId, pBssDesc, pIesLocal)))
3219 {
3220 fRC = TRUE;
3221 }
3222 }
3223 }
3224 }
3225 }
3226 if(!pIes)
3227 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303228 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003229 }
3230
3231 }
3232 return fRC;
3233}
3234
3235#endif
3236
3237
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07003238static void csrMoveTempScanResultsToMainList( tpAniSirGlobal pMac, tANI_U8 reason )
Jeff Johnson295189b2012-06-20 16:38:30 -07003239{
3240 tListElem *pEntry;
3241 tCsrScanResult *pBssDescription;
Jeff Johnson295189b2012-06-20 16:38:30 -07003242 tANI_BOOLEAN fDupBss;
3243#ifdef FEATURE_WLAN_WAPI
3244 tANI_BOOLEAN fNewWapiBSSForCurConnection = eANI_BOOLEAN_FALSE;
3245#endif /* FEATURE_WLAN_WAPI */
3246 tDot11fBeaconIEs *pIesLocal = NULL;
3247 tANI_U32 sessionId = CSR_SESSION_ID_INVALID;
3248 tAniSSID tmpSsid;
3249 v_TIME_t timer=0;
3250
3251 tmpSsid.length = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07003252
3253 // remove the BSS descriptions from temporary list
3254 while( ( pEntry = csrLLRemoveTail( &pMac->scan.tempScanResults, LL_ACCESS_LOCK ) ) != NULL)
3255 {
3256 pBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3257
Vinay Krishna Eranna566365f2015-03-09 12:34:13 +05303258 smsLog( pMac, LOG2, "...Bssid= "MAC_ADDRESS_STR" chan= %d, rssi = -%d",
Arif Hussain24bafea2013-11-15 15:10:03 -08003259 MAC_ADDR_ARRAY(pBssDescription->Result.BssDescriptor.bssId),
Jeff Johnson295189b2012-06-20 16:38:30 -07003260 pBssDescription->Result.BssDescriptor.channelId,
3261 pBssDescription->Result.BssDescriptor.rssi * (-1) );
3262
3263 //At this time, pBssDescription->Result.pvIes may be NULL
3264 pIesLocal = (tDot11fBeaconIEs *)( pBssDescription->Result.pvIes );
3265 if( !pIesLocal && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pBssDescription->Result.BssDescriptor, &pIesLocal))) )
3266 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003267 smsLog(pMac, LOGE, FL(" Cannot pared IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003268 csrFreeScanResultEntry(pMac, pBssDescription);
3269 continue;
3270 }
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05303271 fDupBss = csrRemoveDupBssDescription( pMac, &pBssDescription->Result.BssDescriptor, pIesLocal, &tmpSsid, &timer, FALSE );
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07003272 //Check whether we have reach out limit, but don't lose the LFR candidates came from FW
3273 if( CSR_SCAN_IS_OVER_BSS_LIMIT(pMac)
3274#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
3275 && !( eCsrScanGetLfrResult == reason )
3276#endif
3277 )
Jeff Johnson295189b2012-06-20 16:38:30 -07003278 {
3279 //Limit reach
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003280 smsLog(pMac, LOGW, FL(" BSS limit reached"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003281 //Free the resources
3282 if( (pBssDescription->Result.pvIes == NULL) && pIesLocal )
3283 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303284 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003285 }
3286 csrFreeScanResultEntry(pMac, pBssDescription);
3287 //Continue because there may be duplicated BSS
3288 continue;
3289 }
3290 // check for duplicate scan results
3291 if ( !fDupBss )
3292 {
3293 //Found a new BSS
3294 sessionId = csrProcessBSSDescForPMKIDList(pMac,
3295 &pBssDescription->Result.BssDescriptor, pIesLocal);
3296 if( CSR_SESSION_ID_INVALID != sessionId)
3297 {
3298 csrRoamCallCallback(pMac, sessionId, NULL, 0,
3299 eCSR_ROAM_SCAN_FOUND_NEW_BSS, eCSR_ROAM_RESULT_NONE);
3300 }
3301 }
3302 else
3303 {
3304 //Check if the new one has SSID it it, if not, use the older SSID if it exists.
3305 if( (0 == pBssDescription->Result.ssId.length) && tmpSsid.length )
3306 {
3307 //New BSS has a hidden SSID and old one has the SSID. Keep the SSID only
3308 //if diff of saved SSID time and current time is less than 1 min to avoid
3309 //side effect of saving SSID with old one is that if AP changes its SSID while remain
3310 //hidden, we may never see it and also to address the requirement of
3311 //When we remove hidden ssid from the profile i.e., forget the SSID via
3312 // GUI that SSID shouldn't see in the profile
3313 if( (vos_timer_get_system_time() - timer) <= HIDDEN_TIMER)
3314 {
3315 pBssDescription->Result.timer = timer;
3316 pBssDescription->Result.ssId = tmpSsid;
3317 }
3318 }
3319 }
3320
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303321 //Find a good AP for 11d info
3322 if ( csrIs11dSupported( pMac ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003323 {
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303324 // check if country information element is present
3325 if (pIesLocal->Country.present)
Jeff Johnson295189b2012-06-20 16:38:30 -07003326 {
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303327 csrAddVoteForCountryInfo(pMac, pIesLocal->Country.country);
3328 smsLog(pMac, LOGW, FL("11d AP Bssid " MAC_ADDRESS_STR
3329 " chan= %d, rssi = -%d, countryCode %c%c"),
3330 MAC_ADDR_ARRAY( pBssDescription->Result.BssDescriptor.bssId),
3331 pBssDescription->Result.BssDescriptor.channelId,
3332 pBssDescription->Result.BssDescriptor.rssi * (-1),
3333 pIesLocal->Country.country[0],pIesLocal->Country.country[1] );
3334 }
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303335
Jeff Johnson295189b2012-06-20 16:38:30 -07003336 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08003337
Jeff Johnson295189b2012-06-20 16:38:30 -07003338 // append to main list
3339 csrScanAddResult(pMac, pBssDescription, pIesLocal);
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303340 if ( (pBssDescription->Result.pvIes == NULL) && pIesLocal )
Jeff Johnson295189b2012-06-20 16:38:30 -07003341 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303342 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003343 }
3344 }
3345
Sushant Kaushik6274de62015-05-01 16:31:23 +05303346 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
3347 if (pEntry && 0 != pMac->scan.scanResultCfgAgingTime)
3348 csrScanStartResultCfgAgingTimer(pMac);
Tushnim Bhattacharyyaae317772013-10-23 18:55:38 -07003349 //we don't need to update CC while connected to an AP which is advertising CC already
3350 if (csrIs11dSupported(pMac))
3351 {
3352 tANI_U32 i;
3353 tCsrRoamSession *pSession;
3354
3355 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
3356 {
3357 if (CSR_IS_SESSION_VALID( pMac, i ) )
3358 {
3359 pSession = CSR_GET_SESSION( pMac, i );
3360 if (csrIsConnStateConnected(pMac, i))
3361 {
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303362 smsLog(pMac, LOGW, FL("No need for updating CC in"
3363 "connected state"));
3364 goto end;
Tushnim Bhattacharyyaae317772013-10-23 18:55:38 -07003365 }
3366 }
3367 }
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303368 csrElectedCountryInfo(pMac);
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05303369 csrLearnCountryInformation( pMac, NULL, NULL, eANI_BOOLEAN_TRUE );
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303370 }
3371
Tushnim Bhattacharyyaae317772013-10-23 18:55:38 -07003372end:
3373 //If we can find the current 11d info in any of the scan results, or
Jeff Johnson295189b2012-06-20 16:38:30 -07003374 // a good enough AP with the 11d info from the scan results then no need to
3375 // get into ambiguous state
3376 if(pMac->scan.fAmbiguous11dInfoFound)
3377 {
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303378 if((pMac->scan.fCurrent11dInfoMatch))
Jeff Johnson295189b2012-06-20 16:38:30 -07003379 {
3380 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
3381 }
3382 }
3383
3384#ifdef FEATURE_WLAN_WAPI
3385 if(fNewWapiBSSForCurConnection)
3386 {
3387 //remember it first
3388 csrRoamCallCallback(pMac, sessionId, NULL, 0, eCSR_ROAM_SCAN_FOUND_NEW_BSS, eCSR_ROAM_RESULT_NEW_WAPI_BSS);
3389 }
3390#endif /* FEATURE_WLAN_WAPI */
3391
3392 return;
3393}
3394
3395
3396static tCsrScanResult *csrScanSaveBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pBSSDescription,
3397 tDot11fBeaconIEs *pIes)
3398{
3399 tCsrScanResult *pCsrBssDescription = NULL;
3400 tANI_U32 cbBSSDesc;
3401 tANI_U32 cbAllocated;
Sushant Kaushik6274de62015-05-01 16:31:23 +05303402 tListElem *pEntry;
Jeff Johnson295189b2012-06-20 16:38:30 -07003403
3404 // figure out how big the BSS description is (the BSSDesc->length does NOT
3405 // include the size of the length field itself).
3406 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
3407
3408 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
3409
Kiet Lam64c1b492013-07-12 13:56:44 +05303410 pCsrBssDescription = vos_mem_malloc(cbAllocated);
3411 if ( NULL != pCsrBssDescription )
Jeff Johnson295189b2012-06-20 16:38:30 -07003412 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303413 vos_mem_set(pCsrBssDescription, cbAllocated, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003414 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Kiet Lam64c1b492013-07-12 13:56:44 +05303415 vos_mem_copy(&pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc);
Jeff Johnson295189b2012-06-20 16:38:30 -07003416#if defined(VOSS_ENSBALED)
3417 VOS_ASSERT( pCsrBssDescription->Result.pvIes == NULL );
3418#endif
3419 csrScanAddResult(pMac, pCsrBssDescription, pIes);
Sushant Kaushik6274de62015-05-01 16:31:23 +05303420 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
3421 if (pEntry && 0 != pMac->scan.scanResultCfgAgingTime)
3422 csrScanStartResultCfgAgingTimer(pMac);
3423
Jeff Johnson295189b2012-06-20 16:38:30 -07003424 }
3425
3426 return( pCsrBssDescription );
3427}
3428
3429// Append a Bss Description...
3430tCsrScanResult *csrScanAppendBssDescription( tpAniSirGlobal pMac,
3431 tSirBssDescription *pSirBssDescription,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07003432 tDot11fBeaconIEs *pIes, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07003433{
3434 tCsrScanResult *pCsrBssDescription = NULL;
3435 tAniSSID tmpSsid;
3436 v_TIME_t timer = 0;
3437 int result;
3438
3439 tmpSsid.length = 0;
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07003440 result = csrRemoveDupBssDescription( pMac, pSirBssDescription, pIes, &tmpSsid, &timer, fForced );
Jeff Johnson295189b2012-06-20 16:38:30 -07003441 pCsrBssDescription = csrScanSaveBssDescription( pMac, pSirBssDescription, pIes );
3442 if (result && (pCsrBssDescription != NULL))
3443 {
3444 //Check if the new one has SSID it it, if not, use the older SSID if it exists.
3445 if( (0 == pCsrBssDescription->Result.ssId.length) && tmpSsid.length )
3446 {
3447 //New BSS has a hidden SSID and old one has the SSID. Keep the SSID only
3448 //if diff of saved SSID time and current time is less than 1 min to avoid
3449 //side effect of saving SSID with old one is that if AP changes its SSID while remain
3450 //hidden, we may never see it and also to address the requirement of
3451 //When we remove hidden ssid from the profile i.e., forget the SSID via
3452 // GUI that SSID shouldn't see in the profile
3453 if((vos_timer_get_system_time()-timer) <= HIDDEN_TIMER)
3454 {
3455 pCsrBssDescription->Result.ssId = tmpSsid;
3456 pCsrBssDescription->Result.timer = timer;
3457 }
3458 }
3459 }
3460
3461
3462 return( pCsrBssDescription );
3463}
3464
3465
3466
3467void csrPurgeChannelPower( tpAniSirGlobal pMac, tDblLinkList *pChannelList )
3468{
3469 tCsrChannelPowerInfo *pChannelSet;
3470 tListElem *pEntry;
3471
3472 csrLLLock(pChannelList);
3473 // Remove the channel sets from the learned list and put them in the free list
3474 while( ( pEntry = csrLLRemoveHead( pChannelList, LL_ACCESS_NOLOCK ) ) != NULL)
3475 {
3476 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3477 if( pChannelSet )
3478 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303479 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003480 }
3481 }
3482 csrLLUnlock(pChannelList);
3483 return;
3484}
3485
3486
3487/*
3488 * Save the channelList into the ultimate storage as the final stage of channel
3489 * Input: pCountryInfo -- the country code (e.g. "USI"), channel list, and power limit are all stored inside this data structure
3490 */
Jeff Johnsone7245742012-09-05 17:12:55 -07003491eHalStatus csrSaveToChannelPower2G_5G( tpAniSirGlobal pMac, tANI_U32 tableSize, tSirMacChanInfo *channelTable )
Jeff Johnson295189b2012-06-20 16:38:30 -07003492{
3493 tANI_U32 i = tableSize / sizeof( tSirMacChanInfo );
3494 tSirMacChanInfo *pChannelInfo;
3495 tCsrChannelPowerInfo *pChannelSet;
3496 tANI_BOOLEAN f2GHzInfoFound = FALSE;
3497 tANI_BOOLEAN f2GListPurged = FALSE, f5GListPurged = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003498
3499 pChannelInfo = channelTable;
3500 // atleast 3 bytes have to be remaining -- from "countryString"
3501 while ( i-- )
3502 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303503 pChannelSet = vos_mem_malloc(sizeof(tCsrChannelPowerInfo));
3504 if ( NULL != pChannelSet )
Jeff Johnson295189b2012-06-20 16:38:30 -07003505 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303506 vos_mem_set(pChannelSet, sizeof(tCsrChannelPowerInfo), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003507 pChannelSet->firstChannel = pChannelInfo->firstChanNum;
3508 pChannelSet->numChannels = pChannelInfo->numChannels;
3509
3510 // Now set the inter-channel offset based on the frequency band the channel set lies in
Jeff Johnsone7245742012-09-05 17:12:55 -07003511 if( (CSR_IS_CHANNEL_24GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003512 ((pChannelSet->firstChannel + (pChannelSet->numChannels - 1)) <= CSR_MAX_24GHz_CHANNEL_NUMBER) )
Jeff Johnsone7245742012-09-05 17:12:55 -07003513
Jeff Johnson295189b2012-06-20 16:38:30 -07003514 {
3515 pChannelSet->interChannelOffset = 1;
3516 f2GHzInfoFound = TRUE;
3517 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003518 else if ( (CSR_IS_CHANNEL_5GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003519 ((pChannelSet->firstChannel + ((pChannelSet->numChannels - 1) * 4)) <= CSR_MAX_5GHz_CHANNEL_NUMBER) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003520 {
3521 pChannelSet->interChannelOffset = 4;
3522 f2GHzInfoFound = FALSE;
3523 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003524 else
3525 {
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003526 smsLog( pMac, LOGW, FL("Invalid Channel %d Present in Country IE"),
Jeff Johnsone7245742012-09-05 17:12:55 -07003527 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303528 vos_mem_free(pChannelSet);
Jeff Johnsone7245742012-09-05 17:12:55 -07003529 return eHAL_STATUS_FAILURE;
3530 }
3531
Jeff Johnson295189b2012-06-20 16:38:30 -07003532 pChannelSet->txPower = CSR_ROAM_MIN( pChannelInfo->maxTxPower, pMac->roam.configParam.nTxPowerCap );
3533
3534 if( f2GHzInfoFound )
3535 {
3536 if( !f2GListPurged )
3537 {
3538 // purge previous results if found new
3539 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList24 );
3540 f2GListPurged = TRUE;
3541 }
3542
3543 if(CSR_IS_OPERATING_BG_BAND(pMac))
3544 {
3545 // add to the list of 2.4 GHz channel sets
3546 csrLLInsertTail( &pMac->scan.channelPowerInfoList24, &pChannelSet->link, LL_ACCESS_LOCK );
3547 }
3548 else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003549 smsLog( pMac, LOGW, FL("Adding 11B/G channels in 11A mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003550 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303551 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003552 }
3553 }
3554 else
3555 {
3556 // 5GHz info found
3557 if( !f5GListPurged )
3558 {
3559 // purge previous results if found new
3560 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList5G );
3561 f5GListPurged = TRUE;
3562 }
3563
3564 if(CSR_IS_OPERATING_A_BAND(pMac))
3565 {
3566 // add to the list of 5GHz channel sets
3567 csrLLInsertTail( &pMac->scan.channelPowerInfoList5G, &pChannelSet->link, LL_ACCESS_LOCK );
3568 }
3569 else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003570 smsLog( pMac, LOGW, FL("Adding 11A channels in B/G mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003571 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303572 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003573 }
3574 }
3575 }
3576
3577 pChannelInfo++; // move to next entry
3578 }
3579
Jeff Johnsone7245742012-09-05 17:12:55 -07003580 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07003581}
3582
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303583static void csrClearDfsChannelList( tpAniSirGlobal pMac )
3584{
3585 tSirMbMsg *pMsg;
3586 tANI_U16 msgLen;
Jeff Johnson295189b2012-06-20 16:38:30 -07003587
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303588 msgLen = (tANI_U16)(sizeof( tSirMbMsg ));
Kiet Lam64c1b492013-07-12 13:56:44 +05303589 pMsg = vos_mem_malloc(msgLen);
3590 if ( NULL != pMsg )
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303591 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303592 vos_mem_set((void *)pMsg, msgLen, 0);
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303593 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_CLEAR_DFS_CHANNEL_LIST);
3594 pMsg->msgLen = pal_cpu_to_be16(msgLen);
3595 palSendMBMessage(pMac->hHdd, pMsg);
3596 }
3597}
Jeff Johnson295189b2012-06-20 16:38:30 -07003598
3599void csrApplyPower2Current( tpAniSirGlobal pMac )
3600{
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003601 smsLog( pMac, LOG3, FL(" Updating Cfg with power settings"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003602 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList24, WNI_CFG_MAX_TX_POWER_2_4 );
3603 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList5G, WNI_CFG_MAX_TX_POWER_5 );
3604}
3605
3606
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003607void csrApplyChannelPowerCountryInfo( tpAniSirGlobal pMac, tCsrChannel *pChannelList, tANI_U8 *countryCode, tANI_BOOLEAN updateRiva)
Jeff Johnson295189b2012-06-20 16:38:30 -07003608{
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303609 int i, j, count, countryIndex = -1;
Jeff Johnson295189b2012-06-20 16:38:30 -07003610 tANI_U8 numChannels = 0;
3611 tANI_U8 tempNumChannels = 0;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303612 tANI_U8 channelIgnore = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003613 tCsrChannel ChannelList;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303614
Jeff Johnson295189b2012-06-20 16:38:30 -07003615 if( pChannelList->numChannels )
3616 {
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303617 for(count=0; count < MAX_COUNTRY_IGNORE; count++)
3618 {
3619 if(vos_mem_compare(countryCode, countryIgnoreList[count].countryCode,
3620 VOS_COUNTRY_CODE_LEN))
3621 {
3622 countryIndex = count;
3623 break;
3624 }
3625 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003626 tempNumChannels = CSR_MIN(pChannelList->numChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN);
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05303627
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303628 for(i=0; i < tempNumChannels; i++)
Jeff Johnson295189b2012-06-20 16:38:30 -07003629 {
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303630 channelIgnore = FALSE;
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05303631 if( countryIndex != -1 )
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303632 {
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05303633 for(j=0; j < countryIgnoreList[countryIndex].channelCount; j++)
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303634 {
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05303635 if( pChannelList->channelList[i] ==
3636 countryIgnoreList[countryIndex].channelList[j] )
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303637 {
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05303638 channelIgnore = TRUE;
3639 break;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303640 }
3641 }
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05303642 }
3643 if( FALSE == channelIgnore )
3644 {
3645 ChannelList.channelList[numChannels] = pChannelList->channelList[i];
3646 numChannels++;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303647 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003648 }
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303649 ChannelList.numChannels = numChannels;
Mahesh A Saptasagar1ed59582014-06-04 18:45:07 +05303650 csrApplyPower2Current( pMac ); // Store the channel+power info in the global place: Cfg
Jeff Johnson295189b2012-06-20 16:38:30 -07003651 csrSetCfgValidChannelList(pMac, ChannelList.channelList, ChannelList.numChannels);
3652 // extend scan capability
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303653 // build a scan list based on the channel list : channel# + active/passive scan
3654 csrSetCfgScanControlList(pMac, countryCode, &ChannelList);
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303655 /*Send msg to Lim to clear DFS channel list */
3656 csrClearDfsChannelList(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07003657#ifdef FEATURE_WLAN_SCAN_PNO
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003658 if (updateRiva)
3659 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003660 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO, FL(" Sending 11d PNO info to Riva"));
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003661 // Send HAL UpdateScanParams message
3662 pmcUpdateScanParams(pMac, &(pMac->roam.configParam), &ChannelList, TRUE);
3663 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003664#endif // FEATURE_WLAN_SCAN_PNO
3665 }
3666 else
3667 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003668 smsLog( pMac, LOGE, FL(" 11D channel list is empty"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003669 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003670 csrSetCfgCountryCode(pMac, countryCode);
3671}
3672
Agarwal Ashish8bd53ae2015-06-12 18:03:45 +05303673void csrUpdateFCCChannelList(tpAniSirGlobal pMac)
3674{
3675 tCsrChannel ChannelList;
3676 tANI_U8 chnlIndx = 0;
3677 int i;
Agarwal Ashish8bd53ae2015-06-12 18:03:45 +05303678
3679 for ( i = 0; i < pMac->scan.base20MHzChannels.numChannels; i++ )
3680 {
3681 if (pMac->scan.fcc_constraint &&
3682 ((pMac->scan.base20MHzChannels.channelList[i] == 12) ||
3683 (pMac->scan.base20MHzChannels.channelList[i] == 13)))
3684 {
3685 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
3686 FL("removing channel %d"),
3687 pMac->scan.base20MHzChannels.channelList[i]);
3688 continue;
3689 }
Abhishek Singhe7ca7e62015-10-09 15:02:17 +05303690 ChannelList.channelList[chnlIndx] =
3691 pMac->scan.base20MHzChannels.channelList[i];
Agarwal Ashish8bd53ae2015-06-12 18:03:45 +05303692 chnlIndx++;
3693 }
3694 csrSetCfgValidChannelList(pMac, ChannelList.channelList, chnlIndx);
Agrawal Ashishf92238e2015-12-09 17:51:53 +05303695 csrScanFilterResults(pMac);
Agarwal Ashish8bd53ae2015-06-12 18:03:45 +05303696
3697}
Jeff Johnson295189b2012-06-20 16:38:30 -07003698
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003699void csrResetCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce, tANI_BOOLEAN updateRiva )
Jeff Johnson295189b2012-06-20 16:38:30 -07003700{
3701 if( fForce || (csrIs11dSupported( pMac ) && (!pMac->scan.f11dInfoReset)))
3702 {
3703
3704#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3705 {
3706 vos_log_802_11d_pkt_type *p11dLog;
3707 int Index;
3708
3709 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
3710 if(p11dLog)
3711 {
3712 p11dLog->eventId = WLAN_80211D_EVENT_RESET;
Kiet Lam64c1b492013-07-12 13:56:44 +05303713 vos_mem_copy(p11dLog->countryCode, pMac->scan.countryCodeCurrent, 3);
Jeff Johnson295189b2012-06-20 16:38:30 -07003714 p11dLog->numChannel = pMac->scan.base20MHzChannels.numChannels;
3715 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
3716 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303717 vos_mem_copy(p11dLog->Channels,
3718 pMac->scan.base20MHzChannels.channelList,
3719 p11dLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07003720 for (Index=0; Index < pMac->scan.base20MHzChannels.numChannels; Index++)
3721 {
3722 p11dLog->TxPwr[Index] = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
3723 }
3724 }
3725 if(!pMac->roam.configParam.Is11dSupportEnabled)
3726 {
3727 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
3728 }
3729 else if(pMac->roam.configParam.fEnforceDefaultDomain)
3730 {
3731 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
3732 }
3733 else
3734 {
3735 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
3736 }
3737 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
3738 }
3739 }
3740#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3741
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003742 csrPruneChannelListForMode(pMac, &pMac->scan.baseChannels);
3743 csrPruneChannelListForMode(pMac, &pMac->scan.base20MHzChannels);
3744
Jeff Johnson295189b2012-06-20 16:38:30 -07003745 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_FALSE);
3746 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_TRUE);
3747 // ... and apply the channel list, power settings, and the country code.
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003748 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.base20MHzChannels, pMac->scan.countryCodeCurrent, updateRiva );
Jeff Johnson295189b2012-06-20 16:38:30 -07003749 // clear the 11d channel list
Kiet Lam64c1b492013-07-12 13:56:44 +05303750 vos_mem_set(&pMac->scan.channels11d, sizeof(pMac->scan.channels11d), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003751 pMac->scan.f11dInfoReset = eANI_BOOLEAN_TRUE;
3752 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_FALSE;
3753 }
3754
3755 return;
3756}
3757
3758
3759eHalStatus csrResetCountryCodeInformation(tpAniSirGlobal pMac, tANI_BOOLEAN *pfRestartNeeded)
3760{
3761 eHalStatus status = eHAL_STATUS_SUCCESS;
3762 tANI_BOOLEAN fRestart = eANI_BOOLEAN_FALSE;
3763
3764 //Use the Country code and domain from EEPROM
Kiet Lam64c1b492013-07-12 13:56:44 +05303765 vos_mem_copy(pMac->scan.countryCodeCurrent, pMac->scan.countryCodeDefault,
3766 WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07003767 csrSetRegulatoryDomain(pMac, pMac->scan.domainIdCurrent, &fRestart);
Jeff Johnson43971f52012-07-17 12:26:56 -07003768 if( ((eANI_BOOLEAN_FALSE == fRestart) || (pfRestartNeeded == NULL) )
3769 && !csrIsInfraConnected(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -07003770 {
3771 //Only reset the country info if we don't need to restart
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003772 csrResetCountryInformation(pMac, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07003773 }
3774 if(pfRestartNeeded)
3775 {
3776 *pfRestartNeeded = fRestart;
3777 }
3778
3779 return (status);
3780}
3781
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303782void csrClearVotesForCountryInfo(tpAniSirGlobal pMac)
3783{
3784 pMac->scan.countryCodeCount = 0;
3785 vos_mem_set(pMac->scan.votes11d,
3786 sizeof(tCsrVotes11d) * CSR_MAX_NUM_COUNTRY_CODE, 0);
3787}
3788
3789void csrAddVoteForCountryInfo(tpAniSirGlobal pMac, tANI_U8 *pCountryCode)
3790{
3791 tANI_BOOLEAN match = FALSE;
3792 tANI_U8 i;
3793
3794 /* convert to UPPER here so we are assured
3795 * the strings are always in upper case.
3796 */
3797 for( i = 0; i < 3; i++ )
3798 {
3799 pCountryCode[ i ] = (tANI_U8)csrToUpper( pCountryCode[ i ] );
3800 }
3801
3802 /* Some of the 'old' Cisco 350 series AP's advertise NA as the
3803 * country code (for North America ??). NA is not a valid country code
3804 * or domain so let's allow this by changing it to the proper
3805 * country code (which is US). We've also seen some NETGEAR AP's
3806 * that have "XX " as the country code with valid 2.4 GHz US channel
3807 * information. If we cannot find the country code advertised in the
3808 * 11d information element, let's default to US.
3809 */
3810
3811 if ( !HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry( pMac,
3812 pCountryCode, NULL,COUNTRY_QUERY ) ) )
3813 {
3814 pCountryCode[ 0 ] = '0';
3815 pCountryCode[ 1 ] = '0';
3816 }
3817
3818 /* We've seen some of the AP's improperly put a 0 for the
3819 * third character of the country code. spec says valid charcters are
3820 * 'O' (for outdoor), 'I' for Indoor, or ' ' (space; for either).
3821 * if we see a 0 in this third character, let's change it to a ' '.
3822 */
3823 if ( 0 == pCountryCode[ 2 ] )
3824 {
3825 pCountryCode[ 2 ] = ' ';
3826 }
3827
3828 for (i = 0; i < pMac->scan.countryCodeCount; i++)
3829 {
3830 match = (vos_mem_compare(pMac->scan.votes11d[i].countryCode,
3831 pCountryCode, 2));
3832 if(match)
3833 {
3834 break;
3835 }
3836 }
3837
3838 if (match)
3839 {
3840 pMac->scan.votes11d[i].votes++;
3841 }
3842 else
3843 {
3844 vos_mem_copy( pMac->scan.votes11d[pMac->scan.countryCodeCount].countryCode,
3845 pCountryCode, 3 );
3846 pMac->scan.votes11d[pMac->scan.countryCodeCount].votes = 1;
3847 pMac->scan.countryCodeCount++;
3848 }
3849
3850 return;
3851}
3852
3853tANI_BOOLEAN csrElectedCountryInfo(tpAniSirGlobal pMac)
3854{
3855 tANI_BOOLEAN fRet = FALSE;
3856 tANI_U8 maxVotes = 0;
3857 tANI_U8 i, j=0;
3858
3859 if (!pMac->scan.countryCodeCount)
3860 {
3861 return fRet;
3862 }
3863 maxVotes = pMac->scan.votes11d[0].votes;
3864 fRet = TRUE;
3865
3866 for(i = 1; i < pMac->scan.countryCodeCount; i++)
3867 {
3868 /* If we have a tie for max votes for 2 different country codes,
3869 * pick random.we can put some more intelligence - TBD
3870 */
3871 if (maxVotes < pMac->scan.votes11d[i].votes)
3872 {
3873 VOS_TRACE( VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
3874 " Votes for Country %c%c : %d\n",
3875 pMac->scan.votes11d[i].countryCode[0],
3876 pMac->scan.votes11d[i].countryCode[1],
3877 pMac->scan.votes11d[i].votes);
3878
3879 maxVotes = pMac->scan.votes11d[i].votes;
3880 j = i;
3881 fRet = TRUE;
3882 }
3883
3884 }
3885 if (fRet)
3886 {
Rajesh Babu Prathipati20cdffa2014-07-01 22:24:59 +05303887 vos_mem_copy(pMac->scan.countryCodeElected,
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303888 pMac->scan.votes11d[j].countryCode, WNI_CFG_COUNTRY_CODE_LEN);
Rajesh Babu Prathipati20cdffa2014-07-01 22:24:59 +05303889 vos_mem_copy(pMac->scan.countryCode11d,
Agarwal Ashish852b2c32014-05-23 17:13:25 +05303890 pMac->scan.votes11d[j].countryCode, WNI_CFG_COUNTRY_CODE_LEN);
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303891 VOS_TRACE( VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
3892 "Selected Country is %c%c With count %d\n",
3893 pMac->scan.votes11d[j].countryCode[0],
3894 pMac->scan.votes11d[j].countryCode[1],
3895 pMac->scan.votes11d[j].votes);
3896 }
3897 return fRet;
3898}
Jeff Johnson295189b2012-06-20 16:38:30 -07003899
3900eHalStatus csrSetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pCountry, tANI_BOOLEAN *pfRestartNeeded)
3901{
3902 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
3903 v_REGDOMAIN_t domainId;
3904
3905 if(pCountry)
3906 {
Kiet Lam6c583332013-10-14 05:37:09 +05303907 status = csrGetRegulatoryDomainForCountry(pMac, pCountry, &domainId, COUNTRY_USER);
Jeff Johnson295189b2012-06-20 16:38:30 -07003908 if(HAL_STATUS_SUCCESS(status))
3909 {
3910 status = csrSetRegulatoryDomain(pMac, domainId, pfRestartNeeded);
3911 if(HAL_STATUS_SUCCESS(status))
3912 {
3913 //We don't need to check the pMac->roam.configParam.fEnforceDefaultDomain flag here,
3914 //csrSetRegulatoryDomain will fail if the country doesn't fit our domain criteria.
Kiet Lam64c1b492013-07-12 13:56:44 +05303915 vos_mem_copy(pMac->scan.countryCodeCurrent, pCountry, WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07003916 if((pfRestartNeeded == NULL) || !(*pfRestartNeeded))
3917 {
3918 //Simply set it to cfg. If we need to restart, restart will apply it to the CFG
3919 csrSetCfgCountryCode(pMac, pCountry);
3920 }
3921 }
3922 }
3923 }
3924
3925 return (status);
3926}
3927
3928
3929
3930//caller allocated memory for pNumChn and pChnPowerInfo
3931//As input, *pNumChn has the size of the array of pChnPowerInfo
3932//Upon return, *pNumChn has the number of channels assigned.
3933void csrGetChannelPowerInfo( tpAniSirGlobal pMac, tDblLinkList *pList,
3934 tANI_U32 *pNumChn, tChannelListWithPower *pChnPowerInfo)
3935{
3936 tListElem *pEntry;
3937 tANI_U32 chnIdx = 0, idx;
3938 tCsrChannelPowerInfo *pChannelSet;
3939
3940 //Get 2.4Ghz first
3941 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
3942 while( pEntry && (chnIdx < *pNumChn) )
3943 {
3944 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3945 if ( 1 != pChannelSet->interChannelOffset )
3946 {
3947 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
3948 {
3949 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
3950 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
3951 }
3952 }
3953 else
3954 {
3955 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
3956 {
3957 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + idx);
3958 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
3959 }
3960 }
3961
3962 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
3963 }
3964 *pNumChn = chnIdx;
3965
3966 return ;
3967}
3968
3969
3970
3971void csrApplyCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce )
3972{
3973 v_REGDOMAIN_t domainId;
3974 eHalStatus status = eHAL_STATUS_SUCCESS;
3975
3976 do
3977 {
3978 if( !csrIs11dSupported( pMac ) || 0 == pMac->scan.channelOf11dInfo) break;
3979 if( pMac->scan.fAmbiguous11dInfoFound )
3980 {
3981 // ambiguous info found
3982 //Restore te default domain as well
Kiet Lam6c583332013-10-14 05:37:09 +05303983 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
3984 pMac, pMac->scan.countryCodeCurrent,
3985 &domainId, COUNTRY_QUERY)))
Jeff Johnson295189b2012-06-20 16:38:30 -07003986 {
3987 pMac->scan.domainIdCurrent = domainId;
3988 }
3989 else
3990 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003991 smsLog(pMac, LOGE, FL(" failed to get domain from currentCountryCode %02X%02X"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003992 pMac->scan.countryCodeCurrent[0], pMac->scan.countryCodeCurrent[1]);
3993 }
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003994 csrResetCountryInformation( pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE );
Jeff Johnson295189b2012-06-20 16:38:30 -07003995 break;
3996 }
3997 if ( pMac->scan.f11dInfoApplied && !fForce ) break;
Kiet Lam6c583332013-10-14 05:37:09 +05303998 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
3999 pMac, pMac->scan.countryCode11d,
4000 &domainId, COUNTRY_QUERY)))
Jeff Johnson295189b2012-06-20 16:38:30 -07004001 {
4002 //Check whether we need to enforce default domain
4003 if( ( !pMac->roam.configParam.fEnforceDefaultDomain ) ||
4004 (pMac->scan.domainIdCurrent == domainId) )
4005 {
4006
4007#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4008 {
4009 vos_log_802_11d_pkt_type *p11dLog;
4010 tChannelListWithPower chnPwrInfo[WNI_CFG_VALID_CHANNEL_LIST_LEN];
4011 tANI_U32 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN, nTmp;
4012
4013 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
4014 if(p11dLog)
4015 {
4016 p11dLog->eventId = WLAN_80211D_EVENT_COUNTRY_SET;
Kiet Lam64c1b492013-07-12 13:56:44 +05304017 vos_mem_copy(p11dLog->countryCode, pMac->scan.countryCode11d, 3);
Jeff Johnson295189b2012-06-20 16:38:30 -07004018 p11dLog->numChannel = pMac->scan.channels11d.numChannels;
4019 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
4020 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304021 vos_mem_copy(p11dLog->Channels,
4022 pMac->scan.channels11d.channelList,
4023 p11dLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07004024 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList24,
4025 &nChnInfo, chnPwrInfo);
4026 nTmp = nChnInfo;
4027 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN - nTmp;
4028 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList5G,
4029 &nChnInfo, &chnPwrInfo[nTmp]);
4030 for(nTmp = 0; nTmp < p11dLog->numChannel; nTmp++)
4031 {
4032 for(nChnInfo = 0; nChnInfo < WNI_CFG_VALID_CHANNEL_LIST_LEN; nChnInfo++)
4033 {
4034 if(p11dLog->Channels[nTmp] == chnPwrInfo[nChnInfo].chanId)
4035 {
4036 p11dLog->TxPwr[nTmp] = chnPwrInfo[nChnInfo].pwr;
4037 break;
4038 }
4039 }
4040 }
4041 }
4042 if(!pMac->roam.configParam.Is11dSupportEnabled)
4043 {
4044 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
4045 }
4046 else if(pMac->roam.configParam.fEnforceDefaultDomain)
4047 {
4048 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
4049 }
4050 else
4051 {
4052 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
4053 }
4054 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
4055 }
4056 }
4057#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4058 if(pMac->scan.domainIdCurrent != domainId)
4059 {
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05304060 smsLog(pMac, LOGW, FL("Domain Changed Old %s (%d), new %s"),
4061 voss_DomainIdtoString(pMac->scan.domainIdCurrent),
4062 pMac->scan.domainIdCurrent,
4063 voss_DomainIdtoString(domainId));
Abhishek Singha306a442013-11-07 18:39:01 +05304064 status = WDA_SetRegDomain(pMac, domainId, eSIR_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07004065 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004066 if (status != eHAL_STATUS_SUCCESS)
4067 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004068 smsLog( pMac, LOGE, FL(" fail to set regId %d"), domainId );
Jeff Johnson295189b2012-06-20 16:38:30 -07004069 }
4070 pMac->scan.domainIdCurrent = domainId;
Kiet Lam6c583332013-10-14 05:37:09 +05304071#ifndef CONFIG_ENABLE_LINUX_REG
Kiet Lambb14e952013-11-19 14:58:29 +05304072 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.base20MHzChannels,
4073 pMac->scan.countryCodeCurrent, eANI_BOOLEAN_TRUE );
Kiet Lam6c583332013-10-14 05:37:09 +05304074#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004075 // switch to active scans using this new channel list
4076 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
4077 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_TRUE;
4078 pMac->scan.f11dInfoReset = eANI_BOOLEAN_FALSE;
4079 }
4080 }
4081
4082 } while( 0 );
4083
4084 return;
4085}
4086
4087
4088
4089tANI_BOOLEAN csrSave11dCountryString( tpAniSirGlobal pMac, tANI_U8 *pCountryCode,
4090 tANI_BOOLEAN fForce)
4091{
4092 tANI_BOOLEAN fCountryStringChanged = FALSE, fUnknownCountryCode = FALSE;
4093 tANI_U32 i;
Kiet Lam6c583332013-10-14 05:37:09 +05304094 v_REGDOMAIN_t regd;
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004095 tANI_BOOLEAN fCountryNotPresentInDriver = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004096
4097 // convert to UPPER here so we are assured the strings are always in upper case.
4098 for( i = 0; i < 3; i++ )
4099 {
4100 pCountryCode[ i ] = (tANI_U8)csrToUpper( pCountryCode[ i ] );
4101 }
4102
4103 // Some of the 'old' Cisco 350 series AP's advertise NA as the country code (for North America ??).
4104 // NA is not a valid country code or domain so let's allow this by changing it to the proper
4105 // country code (which is US). We've also seen some NETGEAR AP's that have "XX " as the country code
4106 // with valid 2.4 GHz US channel information. If we cannot find the country code advertised in the
4107 // 11d information element, let's default to US.
Kiet Lam6c583332013-10-14 05:37:09 +05304108 if ( !HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(pMac,
4109 pCountryCode,
4110 &regd,
4111 COUNTRY_QUERY) ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07004112 {
4113 // Check the enforcement first
4114 if( pMac->roam.configParam.fEnforceDefaultDomain || pMac->roam.configParam.fEnforceCountryCodeMatch )
4115 {
4116 fUnknownCountryCode = TRUE;
4117 }
4118 else
4119 {
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004120 fCountryNotPresentInDriver = TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004121 }
4122 }
Tushnim Bhattacharyyac3c1e8e2013-10-29 17:27:43 -07004123 //right now, even if we don't find the CC in driver we set to world. Making
4124 //sure countryCode11d doesn't get updated with the invalid CC, instead
4125 //reflect the world CC
4126 else if (REGDOMAIN_WORLD == regd)
4127 {
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004128 fCountryNotPresentInDriver = TRUE;
Tushnim Bhattacharyyac3c1e8e2013-10-29 17:27:43 -07004129 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004130
4131 // We've seen some of the AP's improperly put a 0 for the third character of the country code.
4132 // spec says valid charcters are 'O' (for outdoor), 'I' for Indoor, or ' ' (space; for either).
4133 // if we see a 0 in this third character, let's change it to a ' '.
4134 if ( 0 == pCountryCode[ 2 ] )
4135 {
4136 pCountryCode[ 2 ] = ' ';
4137 }
4138
4139 if( !fUnknownCountryCode )
4140 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304141 fCountryStringChanged = (!vos_mem_compare(pMac->scan.countryCode11d, pCountryCode, 2));
Jeff Johnson295189b2012-06-20 16:38:30 -07004142
4143
4144 if(( 0 == pMac->scan.countryCode11d[ 0 ] && 0 == pMac->scan.countryCode11d[ 1 ] )
4145 || (fForce))
4146 {
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004147 if (!fCountryNotPresentInDriver)
4148 {
4149 // this is the first .11d information
4150 vos_mem_copy(pMac->scan.countryCode11d, pCountryCode,
Kiet Lam64c1b492013-07-12 13:56:44 +05304151 sizeof( pMac->scan.countryCode11d ));
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004152
4153 }
4154 else
4155 {
4156 pMac->scan.countryCode11d[0] = '0';
4157 pMac->scan.countryCode11d[1] = '0';
4158 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004159 }
4160 }
4161
4162 return( fCountryStringChanged );
4163}
4164
4165
4166void csrSaveChannelPowerForBand( tpAniSirGlobal pMac, tANI_BOOLEAN fPopulate5GBand )
4167{
4168 tANI_U32 Index, count=0;
4169 tSirMacChanInfo *pChanInfo;
4170 tSirMacChanInfo *pChanInfoStart;
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08004171 tANI_S32 maxChannelIndex;
4172
4173 maxChannelIndex = ( pMac->scan.base20MHzChannels.numChannels < WNI_CFG_VALID_CHANNEL_LIST_LEN ) ?
4174 pMac->scan.base20MHzChannels.numChannels : WNI_CFG_VALID_CHANNEL_LIST_LEN ;
Jeff Johnson295189b2012-06-20 16:38:30 -07004175
Kiet Lam64c1b492013-07-12 13:56:44 +05304176 pChanInfo = vos_mem_malloc(sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN);
4177 if ( NULL != pChanInfo )
Jeff Johnson295189b2012-06-20 16:38:30 -07004178 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304179 vos_mem_set(pChanInfo, sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004180 pChanInfoStart = pChanInfo;
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08004181 for (Index=0; Index < maxChannelIndex; Index++)
Jeff Johnson295189b2012-06-20 16:38:30 -07004182 {
4183 if ((fPopulate5GBand && (CSR_IS_CHANNEL_5GHZ(pMac->scan.defaultPowerTable[Index].chanId))) ||
4184 (!fPopulate5GBand && (CSR_IS_CHANNEL_24GHZ(pMac->scan.defaultPowerTable[Index].chanId))) )
4185 {
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08004186 if(count >= WNI_CFG_VALID_CHANNEL_LIST_LEN)
4187 {
4188 smsLog( pMac, LOGW, FL(" csrSaveChannelPowerForBand, count exceeded, count = %d"), count);
4189 break;
4190 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004191 pChanInfo->firstChanNum = pMac->scan.defaultPowerTable[Index].chanId;
4192 pChanInfo->numChannels = 1;
4193 pChanInfo->maxTxPower = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
4194 pChanInfo++;
4195 count++;
4196 }
4197 }
4198 if(count)
4199 {
4200 csrSaveToChannelPower2G_5G( pMac, count * sizeof(tSirMacChanInfo), pChanInfoStart );
4201 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304202 vos_mem_free(pChanInfoStart);
Jeff Johnson295189b2012-06-20 16:38:30 -07004203 }
4204}
4205
4206
4207void csrSetOppositeBandChannelInfo( tpAniSirGlobal pMac )
4208{
4209 tANI_BOOLEAN fPopulate5GBand = FALSE;
4210
4211 do
4212 {
4213 // if this is not a dual band product, then we don't need to set the opposite
4214 // band info. We only work in one band so no need to look in the other band.
4215 if ( !CSR_IS_OPEARTING_DUAL_BAND( pMac ) ) break;
4216 // if we found channel info on the 5.0 band and...
4217 if ( CSR_IS_CHANNEL_5GHZ( pMac->scan.channelOf11dInfo ) )
4218 {
4219 // and the 2.4 band is empty, then populate the 2.4 channel info
Kiet Lam8d985a02013-10-11 03:39:41 +05304220 if ( !csrLLIsListEmpty( &pMac->scan.channelPowerInfoList24, LL_ACCESS_LOCK ) ) break;
Jeff Johnson295189b2012-06-20 16:38:30 -07004221 fPopulate5GBand = FALSE;
4222 }
4223 else
4224 {
4225 // else, we found channel info in the 2.4 GHz band. If the 5.0 band is empty
4226 // set the 5.0 band info from the 2.4 country code.
Kiet Lam8d985a02013-10-11 03:39:41 +05304227 if ( !csrLLIsListEmpty( &pMac->scan.channelPowerInfoList5G, LL_ACCESS_LOCK ) ) break;
Jeff Johnson295189b2012-06-20 16:38:30 -07004228 fPopulate5GBand = TRUE;
4229 }
4230 csrSaveChannelPowerForBand( pMac, fPopulate5GBand );
4231
4232 } while( 0 );
4233}
4234
4235
4236tANI_BOOLEAN csrIsSupportedChannel(tpAniSirGlobal pMac, tANI_U8 channelId)
4237{
4238 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
4239 tANI_U32 i;
4240
4241 //Make sure it is a channel that is in our supported list.
4242 for ( i = 0; i < pMac->scan.baseChannels.numChannels; i++ )
4243 {
4244 if ( channelId == pMac->scan.baseChannels.channelList[i] )
4245 {
4246 fRet = eANI_BOOLEAN_TRUE;
4247 break;
4248 }
4249 }
4250
4251 //If it is configured to limit a set of the channels
4252 if( fRet && pMac->roam.configParam.fEnforce11dChannels )
4253 {
4254 fRet = eANI_BOOLEAN_FALSE;
4255 for ( i = 0; i < pMac->scan.base20MHzChannels.numChannels; i++ )
4256 {
4257 if ( channelId == pMac->scan.base20MHzChannels.channelList[i] )
4258 {
4259 fRet = eANI_BOOLEAN_TRUE;
4260 break;
4261 }
4262 }
4263 }
4264
4265 return (fRet);
4266}
4267
4268
4269
4270//bSize specify the buffer size of pChannelList
4271tANI_U8 csrGetChannelListFromChannelSet( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 bSize, tCsrChannelPowerInfo *pChannelSet )
4272{
4273 tANI_U8 i, j = 0, chnId;
4274
4275 bSize = CSR_MIN(bSize, pChannelSet->numChannels);
4276 for( i = 0; i < bSize; i++ )
4277 {
4278 chnId = (tANI_U8)(pChannelSet->firstChannel + ( i * pChannelSet->interChannelOffset ));
4279 if ( csrIsSupportedChannel( pMac, chnId ) )
4280 {
4281 pChannelList[j++] = chnId;
4282 }
4283 }
4284
4285 return (j);
4286}
4287
4288
4289
4290//bSize -- specify the buffer size of pChannelList
4291void csrConstructCurrentValidChannelList( tpAniSirGlobal pMac, tDblLinkList *pChannelSetList,
4292 tANI_U8 *pChannelList, tANI_U8 bSize, tANI_U8 *pNumChannels )
4293{
4294 tListElem *pEntry;
4295 tCsrChannelPowerInfo *pChannelSet;
4296 tANI_U8 numChannels;
4297 tANI_U8 *pChannels;
4298
4299 if( pChannelSetList && pChannelList && pNumChannels )
4300 {
4301 pChannels = pChannelList;
4302 *pNumChannels = 0;
4303 pEntry = csrLLPeekHead( pChannelSetList, LL_ACCESS_LOCK );
4304 while( pEntry )
4305 {
4306 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
4307 numChannels = csrGetChannelListFromChannelSet( pMac, pChannels, bSize, pChannelSet );
4308 pChannels += numChannels;
4309 *pNumChannels += numChannels;
4310 pEntry = csrLLNext( pChannelSetList, pEntry, LL_ACCESS_LOCK );
4311 }
4312 }
4313}
4314
4315
4316/*
4317 * 802.11D only: Gather 11d IE via beacon or Probe response and store them in pAdapter->channels11d
4318*/
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304319tANI_BOOLEAN csrLearnCountryInformation( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc,
4320 tDot11fBeaconIEs *pIes, tANI_BOOLEAN fForce)
Jeff Johnson295189b2012-06-20 16:38:30 -07004321{
Agarwal Ashish60a37ee2014-05-28 17:20:20 +05304322 eHalStatus status;
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304323 tANI_U8 *pCountryCodeSelected;
Jeff Johnson295189b2012-06-20 16:38:30 -07004324 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
4325 v_REGDOMAIN_t domainId;
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304326 tDot11fBeaconIEs *pIesLocal = pIes;
4327 tANI_BOOLEAN useVoting = eANI_BOOLEAN_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004328
Jeff Johnson295189b2012-06-20 16:38:30 -07004329 if (VOS_STA_SAP_MODE == vos_get_conparam ())
4330 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07004331
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304332 if ((NULL == pSirBssDesc) && (NULL == pIes))
4333 useVoting = eANI_BOOLEAN_TRUE;
4334
Jeff Johnson295189b2012-06-20 16:38:30 -07004335 do
4336 {
4337 // check if .11d support is enabled
4338 if( !csrIs11dSupported( pMac ) ) break;
Agarwal Ashish60a37ee2014-05-28 17:20:20 +05304339
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304340 if (eANI_BOOLEAN_FALSE == useVoting)
4341 {
4342 if( !pIesLocal &&
4343 (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
4344 pSirBssDesc, &pIesLocal))))
4345 {
4346 break;
4347 }
4348 // check if country information element is present
4349 if(!pIesLocal->Country.present)
4350 {
4351 //No country info
4352 break;
4353 }
4354
4355 if( HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry
4356 (pMac, pIesLocal->Country.country, &domainId,
4357 COUNTRY_QUERY)) &&
4358 ( domainId == REGDOMAIN_WORLD))
4359 {
4360 break;
4361 }
4362 } //useVoting == eANI_BOOLEAN_FALSE
4363
4364 if (eANI_BOOLEAN_FALSE == useVoting)
4365 pCountryCodeSelected = pIesLocal->Country.country;
4366 else
4367 pCountryCodeSelected = pMac->scan.countryCodeElected;
4368
Kiet Lam8d985a02013-10-11 03:39:41 +05304369 status = csrGetRegulatoryDomainForCountry(pMac,
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304370 pCountryCodeSelected, &domainId, COUNTRY_IE);
Kiet Lam8d985a02013-10-11 03:39:41 +05304371 if ( status != eHAL_STATUS_SUCCESS )
4372 {
4373 smsLog( pMac, LOGE, FL(" fail to get regId %d"), domainId );
4374 fRet = eANI_BOOLEAN_FALSE;
4375 break;
4376 }
Agarwal Ashish7693f2d2014-07-18 18:03:58 +05304377
4378 /* updating 11d Country Code with Country code selected. */
4379
4380 vos_mem_copy(pMac->scan.countryCode11d,
4381 pCountryCodeSelected,
4382 WNI_CFG_COUNTRY_CODE_LEN);
4383
Agarwal Ashish60a37ee2014-05-28 17:20:20 +05304384#ifndef CONFIG_ENABLE_LINUX_REG
Venkata Prathyusha Kuntupalli316247e2013-03-15 17:45:25 -07004385 // Checking for Domain Id change
4386 if ( domainId != pMac->scan.domainIdCurrent )
4387 {
Kiet Lam8d985a02013-10-11 03:39:41 +05304388 vos_mem_copy(pMac->scan.countryCode11d,
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304389 pCountryCodeSelected,
Kiet Lam8d985a02013-10-11 03:39:41 +05304390 sizeof( pMac->scan.countryCode11d ) );
4391 /* Set Current Country code and Current Regulatory domain */
4392 status = csrSetRegulatoryDomain(pMac, domainId, NULL);
4393 if (eHAL_STATUS_SUCCESS != status)
4394 {
4395 smsLog(pMac, LOGE, "Set Reg Domain Fail %d", status);
4396 fRet = eANI_BOOLEAN_FALSE;
4397 return fRet;
4398 }
4399 //csrSetRegulatoryDomain will fail if the country doesn't fit our domain criteria.
4400 vos_mem_copy(pMac->scan.countryCodeCurrent,
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304401 pCountryCodeSelected, WNI_CFG_COUNTRY_CODE_LEN);
Kiet Lam8d985a02013-10-11 03:39:41 +05304402 //Simply set it to cfg.
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304403 csrSetCfgCountryCode(pMac, pCountryCodeSelected);
Kiet Lam8d985a02013-10-11 03:39:41 +05304404
4405 /* overwrite the defualt country code */
4406 vos_mem_copy(pMac->scan.countryCodeDefault,
4407 pMac->scan.countryCodeCurrent,
4408 WNI_CFG_COUNTRY_CODE_LEN);
4409 /* Set Current RegDomain */
Abhishek Singha306a442013-11-07 18:39:01 +05304410 status = WDA_SetRegDomain(pMac, domainId, eSIR_TRUE);
Kiet Lam8d985a02013-10-11 03:39:41 +05304411 if ( status != eHAL_STATUS_SUCCESS )
4412 {
4413 smsLog( pMac, LOGE, FL(" fail to Set regId %d"), domainId );
4414 fRet = eANI_BOOLEAN_FALSE;
4415 return fRet;
4416 }
4417 /* set to default domain ID */
Madan Mohan Koyyalamudi0e5922d2013-09-10 15:45:24 +05304418 pMac->scan.domainIdCurrent = domainId;
Kiet Lam8d985a02013-10-11 03:39:41 +05304419 /* get the channels based on new cc */
4420 status = csrInitGetChannels( pMac );
Jeff Johnson295189b2012-06-20 16:38:30 -07004421
Kiet Lam8d985a02013-10-11 03:39:41 +05304422 if ( status != eHAL_STATUS_SUCCESS )
4423 {
4424 smsLog( pMac, LOGE, FL(" fail to get Channels "));
4425 fRet = eANI_BOOLEAN_FALSE;
4426 return fRet;
4427 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004428
Kiet Lam8d985a02013-10-11 03:39:41 +05304429 /* reset info based on new cc, and we are done */
4430 csrResetCountryInformation(pMac, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
Agarwal Ashishfaef6692014-01-29 19:40:30 +05304431 /* Regulatory Domain Changed, Purge Only scan result
4432 * which does not have channel number belong to 11d
4433 * channel list
4434 */
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05304435 csrScanFilterResults(pMac);
Kiet Lam8d985a02013-10-11 03:39:41 +05304436 }
Kiet Lam6c583332013-10-14 05:37:09 +05304437#endif
4438 fRet = eANI_BOOLEAN_TRUE;
4439
Jeff Johnson295189b2012-06-20 16:38:30 -07004440 } while( 0 );
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304441
4442 if( !pIes && pIesLocal )
4443 {
4444 //locally allocated
4445 vos_mem_free(pIesLocal);
4446 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004447
4448 return( fRet );
4449}
4450
4451
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004452static void csrSaveScanResults( tpAniSirGlobal pMac, tANI_U8 reason )
Jeff Johnson295189b2012-06-20 16:38:30 -07004453{
4454 // initialize this to FALSE. profMoveInterimScanResultsToMainList() routine
4455 // will set this to the channel where an .11d beacon is seen
4456 pMac->scan.channelOf11dInfo = 0;
4457 // if we get any ambiguous .11d information then this will be set to TRUE
4458 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
4459 //Tush
4460 // if we get any ambiguous .11d information, then this will be set to TRUE
4461 // only if the applied 11d info could be found in one of the scan results
4462 pMac->scan.fCurrent11dInfoMatch = eANI_BOOLEAN_FALSE;
4463 // move the scan results from interim list to the main scan list
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004464 csrMoveTempScanResultsToMainList( pMac, reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07004465}
4466
4467
4468void csrReinitScanCmd(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4469{
4470 switch (pCommand->u.scanCmd.reason)
4471 {
4472 case eCsrScanSetBGScanParam:
4473 case eCsrScanAbortBgScan:
4474 if(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList)
4475 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304476 vos_mem_free(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList);
Jeff Johnson295189b2012-06-20 16:38:30 -07004477 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
4478 }
4479 break;
4480 case eCsrScanBGScanAbort:
4481 case eCsrScanBGScanEnable:
4482 case eCsrScanGetScanChnInfo:
4483 break;
4484 case eCsrScanAbortNormalScan:
4485 default:
4486 csrScanFreeRequest(pMac, &pCommand->u.scanCmd.u.scanRequest);
4487 break;
4488 }
4489 if(pCommand->u.scanCmd.pToRoamProfile)
4490 {
4491 csrReleaseProfile(pMac, pCommand->u.scanCmd.pToRoamProfile);
Kiet Lam64c1b492013-07-12 13:56:44 +05304492 vos_mem_free(pCommand->u.scanCmd.pToRoamProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07004493 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304494 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004495}
4496
4497
4498tANI_BOOLEAN csrGetRemainingChannelsFor11dScan( tpAniSirGlobal pMac, tANI_U8 *pChannels, tANI_U8 *pcChannels )
4499{
4500 tANI_U32 index11dChannels, index;
4501 tANI_U32 indexCurrentChannels;
4502 tANI_BOOLEAN fChannelAlreadyScanned;
4503 tANI_U32 len = sizeof(pMac->roam.validChannelList);
4504
4505 *pcChannels = 0;
4506 if ( CSR_IS_11D_INFO_FOUND(pMac) && csrRoamIsChannelValid(pMac, pMac->scan.channelOf11dInfo) )
4507 {
4508 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
4509 {
4510 //Find the channel index where we found the 11d info
4511 for(index = 0; index < len; index++)
4512 {
4513 if(pMac->scan.channelOf11dInfo == pMac->roam.validChannelList[index])
4514 break;
4515 }
4516 //check whether we found the channel index
4517 if(index < len)
4518 {
4519 // Now, look through the 11d channel list and create a list of all channels in the 11d list that are
4520 // NOT in the current channel list. This gives us a list of the new channels that have not been
4521 // scanned. We'll scan this new list so we have a complete set of scan results on all of the domain channels
4522 // initially.
4523 for ( index11dChannels = 0; index11dChannels < pMac->scan.channels11d.numChannels; index11dChannels++ )
4524 {
4525 fChannelAlreadyScanned = eANI_BOOLEAN_FALSE;
4526
4527 for( indexCurrentChannels = 0; indexCurrentChannels < index; indexCurrentChannels++ )
4528 {
4529 if ( pMac->roam.validChannelList[ indexCurrentChannels ] == pMac->scan.channels11d.channelList[ index11dChannels ] )
4530 {
4531 fChannelAlreadyScanned = eANI_BOOLEAN_TRUE;
4532 break;
4533 }
4534 }
4535
4536 if ( !fChannelAlreadyScanned )
4537 {
4538 pChannels[ *pcChannels ] = pMac->scan.channels11d.channelList[ index11dChannels ];
4539 ( *pcChannels )++;
4540 }
4541 }
4542 }
4543 }//GetCFG
4544 }
4545 return( *pcChannels );
4546}
4547
4548
4549eCsrScanCompleteNextCommand csrScanGetNextCommandState( tpAniSirGlobal pMac, tSmeCmd *pCommand, tANI_BOOLEAN fSuccess )
4550{
4551 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
4552
4553 switch( pCommand->u.scanCmd.reason )
4554 {
4555 case eCsrScan11d1:
4556 NextCommand = (fSuccess) ? eCsrNext11dScan1Success : eCsrNext11dScan1Failure;
4557 break;
4558 case eCsrScan11d2:
4559 NextCommand = (fSuccess) ? eCsrNext11dScan2Success : eCsrNext11dScan2Failure;
4560 break;
4561 case eCsrScan11dDone:
4562 NextCommand = eCsrNext11dScanComplete;
4563 break;
4564 case eCsrScanLostLink1:
4565 NextCommand = (fSuccess) ? eCsrNextLostLinkScan1Success : eCsrNextLostLinkScan1Failed;
4566 break;
4567 case eCsrScanLostLink2:
4568 NextCommand = (fSuccess) ? eCsrNextLostLinkScan2Success : eCsrNextLostLinkScan2Failed;
4569 break;
4570 case eCsrScanLostLink3:
4571 NextCommand = (fSuccess) ? eCsrNextLostLinkScan3Success : eCsrNextLostLinkScan3Failed;
4572 break;
4573 case eCsrScanForSsid:
4574 NextCommand = (fSuccess) ? eCsrNexteScanForSsidSuccess : eCsrNexteScanForSsidFailure;
4575 break;
4576 case eCsrScanForCapsChange:
4577 NextCommand = eCsrNextCapChangeScanComplete; //don't care success or not
4578 break;
4579 case eCsrScanIdleScan:
4580 NextCommand = eCsrNextIdleScanComplete;
4581 break;
4582 default:
4583 NextCommand = eCsrNextScanNothing;
4584 break;
4585 }
4586 return( NextCommand );
4587}
4588
4589
4590//Return whether the pCommand is finished.
4591tANI_BOOLEAN csrHandleScan11d1Failure(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4592{
4593 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
4594
4595 //Apply back the default setting and passively scan one more time.
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004596 csrResetCountryInformation(pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07004597 pCommand->u.scanCmd.reason = eCsrScan11d2;
4598 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
4599 {
4600 fRet = eANI_BOOLEAN_FALSE;
4601 }
4602
4603 return (fRet);
4604}
4605
4606
4607tANI_BOOLEAN csrHandleScan11dSuccess(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4608{
4609 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
4610 tANI_U8 *pChannels;
4611 tANI_U8 cChannels;
4612
Kiet Lam64c1b492013-07-12 13:56:44 +05304613 pChannels = vos_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
4614 if ( NULL != pChannels )
Jeff Johnson295189b2012-06-20 16:38:30 -07004615 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304616 vos_mem_set(pChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004617 if ( csrGetRemainingChannelsFor11dScan( pMac, pChannels, &cChannels ) )
4618 {
4619 pCommand->u.scanCmd.reason = eCsrScan11dDone;
4620 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
4621 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304622 vos_mem_free(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -07004623 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004624 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304625 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(cChannels);
4626 if ( NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07004627 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304628 vos_mem_copy(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
4629 pChannels, cChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07004630 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = cChannels;
4631 pCommand->u.scanCmd.u.scanRequest.requestType = eCSR_SCAN_REQUEST_FULL_SCAN;
4632 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
4633 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
4634 {
4635 //Reuse the same command buffer
4636 fRet = eANI_BOOLEAN_FALSE;
4637 }
4638 }
4639 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304640 vos_mem_free(pChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07004641 }
4642
4643 return (fRet);
4644}
4645
4646//Return whether the command should be removed
4647tANI_BOOLEAN csrScanComplete( tpAniSirGlobal pMac, tSirSmeScanRsp *pScanRsp )
4648{
4649 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
4650 tListElem *pEntry;
4651 tSmeCmd *pCommand;
4652 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
4653 tANI_BOOLEAN fSuccess;
4654
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05304655 if (pMac->fScanOffload)
4656 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
4657 else
4658 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07004659
4660 if ( pEntry )
4661 {
4662 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
4663
4664 // If the head of the queue is Active and it is a SCAN command, remove
4665 // and put this on the Free queue.
4666 if ( eSmeCommandScan == pCommand->command )
4667 {
4668 tANI_U32 sessionId = pCommand->sessionId;
4669
4670 if(eSIR_SME_SUCCESS != pScanRsp->statusCode)
4671 {
4672 fSuccess = eANI_BOOLEAN_FALSE;
4673 }
4674 else
4675 {
4676 //pMac->scan.tempScanResults is not empty meaning the scan found something
4677 //This check only valid here because csrSaveScanresults is not yet called
4678 fSuccess = (!csrLLIsListEmpty(&pMac->scan.tempScanResults, LL_ACCESS_LOCK));
4679 }
Ratheesh S Pece1f832015-07-25 15:50:25 +05304680 if (pCommand->u.scanCmd.abortScanIndication &
4681 eCSR_SCAN_ABORT_DUE_TO_BAND_CHANGE)
Srinivas, Dasari187ca4e2014-02-07 12:40:09 +05304682 {
4683 /*
4684 * Scan aborted due to band change
4685 * The scan results need to be flushed
4686 */
4687 if (pCommand->u.scanCmd.callback
4688 != pMac->scan.callback11dScanDone)
4689 {
4690 smsLog(pMac, LOG1, FL("Filtering the scan results as the "
4691 "results may belong to wrong band"));
4692 csrScanFilterResults(pMac);
4693 }
4694 else
4695 {
4696 smsLog(pMac, LOG1, FL("11d_scan_done will flush the scan"
4697 " results"));
4698 }
Srinivas, Dasari187ca4e2014-02-07 12:40:09 +05304699 }
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004700 csrSaveScanResults(pMac, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07004701
Agrawal Ashishf92238e2015-12-09 17:51:53 +05304702 /* filter scan result based on valid channel list number */
4703 if (pMac->scan.fcc_constraint)
4704 {
4705 smsLog(pMac, LOG1, FL("Clear BSS from invalid channels"));
4706 csrScanFilterResults(pMac);
4707 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004708#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4709 {
4710 vos_log_scan_pkt_type *pScanLog = NULL;
4711 tScanResultHandle hScanResult;
4712 tCsrScanResultInfo *pScanResult;
4713 tDot11fBeaconIEs *pIes;
4714 int n = 0, c = 0;
4715
4716 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
4717 if(pScanLog)
4718 {
4719 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
4720 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
4721 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
4722 {
4723 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_RSP;
4724 }
4725 else
4726 {
4727 if( eSIR_PASSIVE_SCAN != pMac->scan.curScanType )
4728 {
4729 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_RSP;
4730 }
4731 else
4732 {
4733 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_RSP;
4734 }
4735 }
4736 if(eSIR_SME_SUCCESS == pScanRsp->statusCode)
4737 {
4738 if(HAL_STATUS_SUCCESS(csrScanGetResult(pMac, NULL, &hScanResult)))
4739 {
4740 while(((pScanResult = csrScanResultGetNext(pMac, hScanResult)) != NULL))
4741 {
4742 if( n < VOS_LOG_MAX_NUM_BSSID )
4743 {
4744 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pScanResult->BssDescriptor, &pIes)))
4745 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004746 smsLog(pMac, LOGE, FL(" fail to parse IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07004747 break;
4748 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304749 vos_mem_copy(pScanLog->bssid[n],
4750 pScanResult->BssDescriptor.bssId, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07004751 if(pIes && pIes->SSID.present && VOS_LOG_MAX_SSID_SIZE >= pIes->SSID.num_ssid)
4752 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304753 vos_mem_copy(pScanLog->ssid[n],
4754 pIes->SSID.ssid, pIes->SSID.num_ssid);
Jeff Johnson295189b2012-06-20 16:38:30 -07004755 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304756 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07004757 n++;
4758 }
4759 c++;
4760 }
4761 pScanLog->numSsid = (v_U8_t)n;
4762 pScanLog->totalSsid = (v_U8_t)c;
4763 csrScanResultPurge(pMac, hScanResult);
4764 }
4765 }
4766 else
4767 {
4768 pScanLog->status = WLAN_SCAN_STATUS_FAILURE;
4769 }
4770 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
4771 }
4772 }
4773#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4774
4775 NextCommand = csrScanGetNextCommandState(pMac, pCommand, fSuccess);
4776 //We reuse the command here instead reissue a new command
4777 switch(NextCommand)
4778 {
4779 case eCsrNext11dScan1Success:
4780 case eCsrNext11dScan2Success:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004781 smsLog( pMac, LOG2, FL("11dScan1/3 produced results. Reissue Active scan..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004782 // if we found country information, no need to continue scanning further, bail out
4783 fRemoveCommand = eANI_BOOLEAN_TRUE;
4784 NextCommand = eCsrNext11dScanComplete;
4785 break;
4786 case eCsrNext11dScan1Failure:
4787 //We are not done yet. 11d scan fail once. We will try to reset anything and do it over again
4788 //The only meaningful thing for this retry is that we cannot find 11d information after a reset so
4789 //we clear the "old" 11d info and give it once more chance
4790 fRemoveCommand = csrHandleScan11d1Failure(pMac, pCommand);
4791 if(fRemoveCommand)
4792 {
4793 NextCommand = eCsrNext11dScanComplete;
4794 }
4795 break;
4796 case eCsrNextLostLinkScan1Success:
4797 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink1)))
4798 {
4799 csrScanHandleFailedLostlink1(pMac, sessionId);
4800 }
4801 break;
4802 case eCsrNextLostLinkScan2Success:
4803 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink2)))
4804 {
4805 csrScanHandleFailedLostlink2(pMac, sessionId);
4806 }
4807 break;
4808 case eCsrNextLostLinkScan3Success:
4809 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink3)))
4810 {
4811 csrScanHandleFailedLostlink3(pMac, sessionId);
4812 }
4813 break;
4814 case eCsrNextLostLinkScan1Failed:
4815 csrScanHandleFailedLostlink1(pMac, sessionId);
4816 break;
4817 case eCsrNextLostLinkScan2Failed:
4818 csrScanHandleFailedLostlink2(pMac, sessionId);
4819 break;
4820 case eCsrNextLostLinkScan3Failed:
4821 csrScanHandleFailedLostlink3(pMac, sessionId);
4822 break;
4823 case eCsrNexteScanForSsidSuccess:
4824 csrScanHandleSearchForSSID(pMac, pCommand);
4825 break;
4826 case eCsrNexteScanForSsidFailure:
4827 csrScanHandleSearchForSSIDFailure(pMac, pCommand);
4828 break;
4829 case eCsrNextIdleScanComplete:
4830 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
4831 break;
4832 case eCsrNextCapChangeScanComplete:
4833 csrScanHandleCapChangeScanComplete(pMac, sessionId);
4834 break;
4835 default:
4836
4837 break;
4838 }
4839 }
4840 else
4841 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004842 smsLog( pMac, LOGW, FL("Scan Completion called but SCAN command is not ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004843 fRemoveCommand = eANI_BOOLEAN_FALSE;
4844 }
4845 }
4846 else
4847 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004848 smsLog( pMac, LOGW, FL("Scan Completion called but NO commands are ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004849 fRemoveCommand = eANI_BOOLEAN_FALSE;
4850 }
4851
4852 return( fRemoveCommand );
4853}
4854
4855
4856
4857static void csrScanRemoveDupBssDescriptionFromInterimList( tpAniSirGlobal pMac,
4858 tSirBssDescription *pSirBssDescr,
4859 tDot11fBeaconIEs *pIes)
4860{
4861 tListElem *pEntry;
4862 tCsrScanResult *pCsrBssDescription;
4863
4864 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
4865 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
4866 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
4867 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
4868 while( pEntry )
4869 {
4870 pCsrBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
4871
4872 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
4873 // matches
4874
4875 if ( csrIsDuplicateBssDescription( pMac, &pCsrBssDescription->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07004876 pSirBssDescr, pIes, FALSE ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07004877 {
4878 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
4879 ((tANI_S32)pCsrBssDescription->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
4880
4881 // Remove the 'old' entry from the list....
4882 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK ) )
4883 {
4884 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pCsrBssDescription->Result.BssDescriptor);
4885 // we need to free the memory associated with this node
4886 csrFreeScanResultEntry( pMac, pCsrBssDescription );
4887 }
4888
4889 // If we found a match, we can stop looking through the list.
4890 break;
4891 }
4892
4893 pEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK );
4894 }
4895}
4896
4897
4898
4899//Caller allocated memory pfNewBssForConn to return whether new candidate for
4900//current connection is found. Cannot be NULL
4901tCsrScanResult *csrScanSaveBssDescriptionToInterimList( tpAniSirGlobal pMac,
4902 tSirBssDescription *pBSSDescription,
4903 tDot11fBeaconIEs *pIes)
4904{
4905 tCsrScanResult *pCsrBssDescription = NULL;
4906 tANI_U32 cbBSSDesc;
4907 tANI_U32 cbAllocated;
Jeff Johnson295189b2012-06-20 16:38:30 -07004908
4909 // figure out how big the BSS description is (the BSSDesc->length does NOT
4910 // include the size of the length field itself).
4911 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
4912
4913 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
4914
Kiet Lam64c1b492013-07-12 13:56:44 +05304915 pCsrBssDescription = vos_mem_malloc(cbAllocated);
4916 if ( NULL != pCsrBssDescription )
Jeff Johnson295189b2012-06-20 16:38:30 -07004917 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304918 vos_mem_set(pCsrBssDescription, cbAllocated, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004919 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Kiet Lam64c1b492013-07-12 13:56:44 +05304920 vos_mem_copy(&pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc );
Jeff Johnson295189b2012-06-20 16:38:30 -07004921 //Save SSID separately for later use
4922 if( pIes->SSID.present && !csrIsNULLSSID(pIes->SSID.ssid, pIes->SSID.num_ssid) )
4923 {
4924 //SSID not hidden
Madan Mohan Koyyalamudi4e31b132012-11-02 13:13:52 -07004925 tANI_U32 len = pIes->SSID.num_ssid;
Jeff Johnson295189b2012-06-20 16:38:30 -07004926 if (len > SIR_MAC_MAX_SSID_LENGTH)
4927 {
4928 // truncate to fit in our struct
4929 len = SIR_MAC_MAX_SSID_LENGTH;
4930 }
4931 pCsrBssDescription->Result.ssId.length = len;
4932 pCsrBssDescription->Result.timer = vos_timer_get_system_time();
Kiet Lam64c1b492013-07-12 13:56:44 +05304933 vos_mem_copy(pCsrBssDescription->Result.ssId.ssId, pIes->SSID.ssid, len);
Jeff Johnson295189b2012-06-20 16:38:30 -07004934 }
4935 csrLLInsertTail( &pMac->scan.tempScanResults, &pCsrBssDescription->Link, LL_ACCESS_LOCK );
4936 }
4937
4938 return( pCsrBssDescription );
4939}
4940
4941
4942
4943
4944tANI_BOOLEAN csrIsDuplicateBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc1,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07004945 tSirBssDescription *pSirBssDesc2, tDot11fBeaconIEs *pIes2, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07004946{
4947 tANI_BOOLEAN fMatch = FALSE;
4948 tSirMacCapabilityInfo *pCap1, *pCap2;
4949 tDot11fBeaconIEs *pIes1 = NULL;
Jeff Johnsone7245742012-09-05 17:12:55 -07004950 tDot11fBeaconIEs *pIesTemp = pIes2;
Jeff Johnson295189b2012-06-20 16:38:30 -07004951
4952 pCap1 = (tSirMacCapabilityInfo *)&pSirBssDesc1->capabilityInfo;
4953 pCap2 = (tSirMacCapabilityInfo *)&pSirBssDesc2->capabilityInfo;
4954 if(pCap1->ess == pCap2->ess)
4955 {
4956 if (pCap1->ess &&
Jeff Johnsone7245742012-09-05 17:12:55 -07004957 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId)&&
Abhishek Singhe3fa11f2014-05-13 11:11:10 +05304958 (fForced || (vos_chan_to_band(pSirBssDesc1->channelId) == vos_chan_to_band((pSirBssDesc2->channelId)))))
Jeff Johnson295189b2012-06-20 16:38:30 -07004959 {
4960 fMatch = TRUE;
Jeff Johnsone7245742012-09-05 17:12:55 -07004961 // Check for SSID match, if exists
4962 do
4963 {
4964 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
4965 {
4966 break;
4967 }
4968 if( NULL == pIesTemp )
4969 {
4970 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
4971 {
4972 break;
4973 }
4974 }
4975 if(pIes1->SSID.present && pIesTemp->SSID.present)
4976 {
4977 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
4978 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
4979 }
4980 }while(0);
4981
Jeff Johnson295189b2012-06-20 16:38:30 -07004982 }
4983 else if (pCap1->ibss && (pSirBssDesc1->channelId == pSirBssDesc2->channelId))
4984 {
Jeff Johnson295189b2012-06-20 16:38:30 -07004985
4986 do
4987 {
4988 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
4989 {
4990 break;
4991 }
4992 if( NULL == pIesTemp )
4993 {
4994 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
4995 {
4996 break;
4997 }
4998 }
4999 //Same channel cannot have same SSID for different IBSS
5000 if(pIes1->SSID.present && pIesTemp->SSID.present)
5001 {
5002 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
5003 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
5004 }
5005 }while(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005006 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005007 /* In case of P2P devices, ess and ibss will be set to zero */
5008 else if (!pCap1->ess &&
5009 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId))
5010 {
5011 fMatch = TRUE;
5012 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005013 }
5014
5015 if(pIes1)
5016 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305017 vos_mem_free(pIes1);
Jeff Johnson295189b2012-06-20 16:38:30 -07005018 }
Jeff Johnsone7245742012-09-05 17:12:55 -07005019
5020 if( (NULL == pIes2) && pIesTemp )
5021 {
5022 //locally allocated
Kiet Lam64c1b492013-07-12 13:56:44 +05305023 vos_mem_free(pIesTemp);
Jeff Johnsone7245742012-09-05 17:12:55 -07005024 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005025
5026 return( fMatch );
5027}
5028
5029
5030tANI_BOOLEAN csrIsNetworkTypeEqual( tSirBssDescription *pSirBssDesc1, tSirBssDescription *pSirBssDesc2 )
5031{
5032 return( pSirBssDesc1->nwType == pSirBssDesc2->nwType );
5033}
5034
5035
5036//to check whether the BSS matches the dot11Mode
5037static tANI_BOOLEAN csrScanIsBssAllowed(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
5038 tDot11fBeaconIEs *pIes)
5039{
5040 tANI_BOOLEAN fAllowed = eANI_BOOLEAN_FALSE;
5041 eCsrPhyMode phyMode;
5042
5043 if(HAL_STATUS_SUCCESS(csrGetPhyModeFromBss(pMac, pBssDesc, &phyMode, pIes)))
5044 {
5045 switch(pMac->roam.configParam.phyMode)
5046 {
5047 case eCSR_DOT11_MODE_11b:
5048 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
5049 break;
5050 case eCSR_DOT11_MODE_11g:
5051 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
5052 break;
5053 case eCSR_DOT11_MODE_11g_ONLY:
5054 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11g == phyMode);
5055 break;
5056 case eCSR_DOT11_MODE_11a:
5057 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11b != phyMode) && (eCSR_DOT11_MODE_11g != phyMode));
5058 break;
5059 case eCSR_DOT11_MODE_11n_ONLY:
5060 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11n == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
5061 break;
Jeff Johnsone7245742012-09-05 17:12:55 -07005062
5063#ifdef WLAN_FEATURE_11AC
5064 case eCSR_DOT11_MODE_11ac_ONLY:
5065 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11ac == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
5066 break;
5067#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005068 case eCSR_DOT11_MODE_11b_ONLY:
5069 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11b == phyMode);
5070 break;
5071 case eCSR_DOT11_MODE_11a_ONLY:
5072 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a == phyMode);
5073 break;
5074 case eCSR_DOT11_MODE_11n:
Jeff Johnsone7245742012-09-05 17:12:55 -07005075#ifdef WLAN_FEATURE_11AC
5076 case eCSR_DOT11_MODE_11ac:
5077#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005078 case eCSR_DOT11_MODE_TAURUS:
5079 default:
5080 fAllowed = eANI_BOOLEAN_TRUE;
5081 break;
5082 }
5083 }
5084
5085 return (fAllowed);
5086}
5087
5088
5089
5090//Return pIes to caller for future use when returning TRUE.
5091static tANI_BOOLEAN csrScanValidateScanResult( tpAniSirGlobal pMac, tANI_U8 *pChannels,
5092 tANI_U8 numChn, tSirBssDescription *pBssDesc,
5093 tDot11fBeaconIEs **ppIes )
5094{
5095 tANI_BOOLEAN fValidChannel = FALSE;
5096 tDot11fBeaconIEs *pIes = NULL;
5097 tANI_U8 index;
5098
5099 for( index = 0; index < numChn; index++ )
5100 {
5101 // This check relies on the fact that a single BSS description is returned in each
5102 // ScanRsp call, which is the way LIM implemented the scan req/rsp funtions. We changed
5103 // to this model when we ran with a large number of APs. If this were to change, then
5104 // this check would have to mess with removing the bssDescription from somewhere in an
5105 // arbitrary index in the bssDescription array.
5106 if ( pChannels[ index ] == pBssDesc->channelId )
5107 {
5108 fValidChannel = TRUE;
5109 break;
5110 }
5111 }
5112 *ppIes = NULL;
5113 if(fValidChannel)
5114 {
5115 if( HAL_STATUS_SUCCESS( csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIes) ) )
5116 {
5117 fValidChannel = csrScanIsBssAllowed(pMac, pBssDesc, pIes);
5118 if( fValidChannel )
5119 {
5120 *ppIes = pIes;
5121 }
5122 else
5123 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305124 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07005125 }
5126 }
5127 else
5128 {
5129 fValidChannel = FALSE;
5130 }
5131 }
5132
5133 return( fValidChannel );
5134}
5135
5136
5137//Return whether last scan result is received
5138static tANI_BOOLEAN csrScanProcessScanResults( tpAniSirGlobal pMac, tSmeCmd *pCommand,
5139 tSirSmeScanRsp *pScanRsp, tANI_BOOLEAN *pfRemoveCommand )
5140{
5141 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE, fRemoveCommand = eANI_BOOLEAN_FALSE;
5142 tDot11fBeaconIEs *pIes = NULL;
5143 tANI_U32 cbParsed;
5144 tSirBssDescription *pSirBssDescription;
5145 tANI_U32 cbBssDesc;
5146 tANI_U32 cbScanResult = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription )
5147 + sizeof(tSirBssDescription); //We need at least one CB
5148
5149 // don't consider the scan rsp to be valid if the status code is Scan Failure. Scan Failure
5150 // is returned when the scan could not find anything. so if we get scan failure return that
5151 // the scan response is invalid. Also check the lenght in the scan result for valid scan
5152 // BssDescriptions....
5153 do
5154 {
5155 if ( ( cbScanResult <= pScanRsp->length ) &&
5156 (( eSIR_SME_SUCCESS == pScanRsp->statusCode ) ||
5157 ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW == pScanRsp->statusCode ) ) )
5158 {
5159 tANI_U8 *pChannelList = NULL;
5160 tANI_U8 cChannels = 0;
5161
5162 //Different scan type can reach this point, we need to distinguish it
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005163#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5164 if( eCsrScanGetLfrResult == pCommand->u.scanCmd.reason )
5165 {
5166 pChannelList = NULL;
5167 cChannels = 0;
5168 }
5169 else
5170#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005171 if( eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason )
5172 {
5173 //eCsrScanSetBGScanParam uses different structure
5174 tCsrBGScanRequest *pBgScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
5175
5176 cChannels = pBgScanReq->ChannelInfo.numOfChannels;
5177 pChannelList = pBgScanReq->ChannelInfo.ChannelList;
5178 }
5179 else
5180 {
5181 //the rest use generic scan request
5182 cChannels = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
5183 pChannelList = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
5184 }
5185
5186 // if the scan result is not on one of the channels in the Valid channel list, then it
5187 // must have come from an AP on an overlapping channel (in the 2.4GHz band). In this case,
5188 // let's drop the scan result.
5189 //
5190 // The other situation is where the scan request is for a scan on a particular channel set
5191 // and the scan result is from a
5192
5193 // if the NumChannels is 0, then we are supposed to be scanning all channels. Use the full channel
5194 // list as the 'valid' channel list. Otherwise, use the specific channel list in the scan parms
5195 // as the valid channels.
5196 if ( 0 == cChannels )
5197 {
5198 tANI_U32 len = sizeof(pMac->roam.validChannelList);
5199
5200 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
5201 {
5202 pChannelList = pMac->roam.validChannelList;
5203 cChannels = (tANI_U8)len;
5204 }
5205 else
5206 {
5207 //Cannot continue
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005208 smsLog( pMac, LOGE, "CSR: Processing internal SCAN results...csrGetCfgValidChannels failed" );
Jeff Johnson295189b2012-06-20 16:38:30 -07005209 break;
5210 }
5211 }
5212
5213 smsLog( pMac, LOG2, "CSR: Processing internal SCAN results..." );
5214 cbParsed = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription );
5215 pSirBssDescription = pScanRsp->bssDescription;
5216 while( cbParsed < pScanRsp->length )
5217 {
5218 if ( csrScanValidateScanResult( pMac, pChannelList, cChannels, pSirBssDescription, &pIes ) )
5219 {
5220 csrScanRemoveDupBssDescriptionFromInterimList(pMac, pSirBssDescription, pIes);
5221 csrScanSaveBssDescriptionToInterimList( pMac, pSirBssDescription, pIes );
5222 if( eSIR_PASSIVE_SCAN == pMac->scan.curScanType )
5223 {
5224 if( csrIs11dSupported( pMac) )
5225 {
5226 //Check whether the BSS is acceptable base on 11d info and our configs.
5227 if( csrMatchCountryCode( pMac, NULL, pIes ) )
5228 {
5229 //Double check whether the channel is acceptable by us.
5230 if( csrIsSupportedChannel( pMac, pSirBssDescription->channelId ) )
5231 {
5232 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
5233 }
5234 }
5235 }
5236 else
5237 {
5238 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
5239 }
5240 }
5241 //Free the resource
Kiet Lam64c1b492013-07-12 13:56:44 +05305242 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07005243 }
5244 // skip over the BSS description to the next one...
5245 cbBssDesc = pSirBssDescription->length + sizeof( pSirBssDescription->length );
5246
5247 cbParsed += cbBssDesc;
5248 pSirBssDescription = (tSirBssDescription *)((tANI_U8 *)pSirBssDescription + cbBssDesc );
5249
5250 } //while
5251 }
5252 else
5253 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005254 smsLog( pMac, LOGW, " Scanrsp fail (0x%08X), length = %d (expected %d)",
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08005255 pScanRsp->statusCode, pScanRsp->length, cbScanResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07005256 //HO bg scan/probe failed no need to try autonomously
5257 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
5258 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005259#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5260 eCsrScanGetLfrResult == pCommand->u.scanCmd.reason ||
5261#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005262 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
5263 {
5264 fRemoveCommand = eANI_BOOLEAN_TRUE;
5265 }
5266 }
5267 }while(0);
5268 if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
5269 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005270 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 -07005271 fRemoveCommand = csrScanComplete( pMac, pScanRsp );
5272 fRet = eANI_BOOLEAN_TRUE;
5273 }//if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
5274 if(pfRemoveCommand)
5275 {
5276 *pfRemoveCommand = fRemoveCommand;
5277 }
5278
5279#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305280 if (pMac->fScanOffload)
5281 return fRet;
5282
Jeff Johnson295189b2012-06-20 16:38:30 -07005283 if (!csrLLIsListEmpty( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK ))
5284 {
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005285 /* Pending scan commands in the list because the previous scan command
5286 * was split into a scan command on one channel + a scan command for all
5287 * remaining channels.
5288 *
5289 * Start timer to trigger processing of the next scan command.
Srikant Kuppa866893f2012-12-27 17:28:14 -08005290 * NOTE for LFR:
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305291 * Do not split scans if no concurrent infra connections are
Srikant Kuppa866893f2012-12-27 17:28:14 -08005292 * active and if the scan is a BG scan triggered by LFR (OR)
5293 * any scan if LFR is in the middle of a BG scan. Splitting
5294 * the scan is delaying the time it takes for LFR to find
5295 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005296 */
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305297 if ( (csrIsStaSessionConnected(pMac) &&
Srikant Kuppa866893f2012-12-27 17:28:14 -08005298#ifdef FEATURE_WLAN_LFR
5299 (csrIsConcurrentInfraConnected(pMac) ||
5300 ((pCommand->u.scanCmd.reason != eCsrScanBgScan) &&
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305301 (pMac->roam.neighborRoamInfo.neighborRoamState !=
Srikant Kuppa866893f2012-12-27 17:28:14 -08005302 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
5303#endif
5304 (pCommand->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305305 (csrIsP2pSessionConnected(pMac)) )
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005306 {
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005307 /* if active connected sessions present then continue to split scan
5308 * with specified interval between consecutive scans */
5309 csrSetDefaultScanTiming(pMac, pCommand->u.scanCmd.u.scanRequest.scanType, &(pCommand->u.scanCmd.u.scanRequest));
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05305310 vos_timer_start(&pMac->scan.hTimerStaApConcTimer,
5311 pCommand->u.scanCmd.u.scanRequest.restTime);
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005312 } else {
5313 /* if no connected sessions present then initiate next scan command immediately */
5314 /* minimum timer granularity is 10ms */
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05305315 vos_timer_start(&pMac->scan.hTimerStaApConcTimer, 10);
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005316 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005317 }
5318#endif
5319 return (fRet);
5320}
5321
5322
5323tANI_BOOLEAN csrScanIsWildCardScan( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5324{
5325 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
Kiet Lam64c1b492013-07-12 13:56:44 +05305326 tANI_BOOLEAN f = vos_mem_compare(pCommand->u.scanCmd.u.scanRequest.bssid,
5327 bssid, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07005328
5329 //It is not a wild card scan if the bssid is not broadcast and the number of SSID is 1.
5330 return ((tANI_BOOLEAN)( (f || (0xff == pCommand->u.scanCmd.u.scanRequest.bssid[0])) &&
5331 (pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs != 1) ));
5332}
5333
5334
5335eHalStatus csrScanSmeScanResponse( tpAniSirGlobal pMac, void *pMsgBuf )
5336{
5337 eHalStatus status = eHAL_STATUS_SUCCESS;
5338 tListElem *pEntry;
5339 tSmeCmd *pCommand;
5340 eCsrScanStatus scanStatus;
5341 tSirSmeScanRsp *pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
5342 tSmeGetScanChnRsp *pScanChnInfo;
5343 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
5344 eCsrScanReason reason = eCsrScanOther;
5345
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305346 if (pMac->fScanOffload)
5347 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList,
5348 LL_ACCESS_LOCK);
5349 else
5350 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07005351
5352 if ( pEntry )
5353 {
5354 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
5355 if ( eSmeCommandScan == pCommand->command )
5356 {
5357 scanStatus = (eSIR_SME_SUCCESS == pScanRsp->statusCode) ? eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
5358 reason = pCommand->u.scanCmd.reason;
5359 switch(pCommand->u.scanCmd.reason)
5360 {
5361 case eCsrScanAbortBgScan:
5362 case eCsrScanAbortNormalScan:
5363 case eCsrScanBGScanAbort:
5364 case eCsrScanBGScanEnable:
5365 break;
5366 case eCsrScanGetScanChnInfo:
5367 pScanChnInfo = (tSmeGetScanChnRsp *)pMsgBuf;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005368 /*
5369 * status code not available in tSmeGetScanChnRsp, so
5370 * by default considereing it to be success
5371 */
5372 scanStatus = eSIR_SME_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07005373 csrScanAgeResults(pMac, pScanChnInfo);
5374 break;
5375 case eCsrScanForCapsChange:
5376 csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand );
5377 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005378 case eCsrScanP2PFindPeer:
5379 scanStatus = ((eSIR_SME_SUCCESS == pScanRsp->statusCode) && (pScanRsp->length > 50)) ? eCSR_SCAN_FOUND_PEER : eCSR_SCAN_FAILURE;
5380 csrScanProcessScanResults( pMac, pCommand, pScanRsp, NULL );
5381 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005382 case eCsrScanSetBGScanParam:
5383 default:
5384 if(csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand ))
5385 {
5386 //Not to get channel info if the scan is not a wildcard scan because
5387 //it may cause scan results got aged out incorrectly.
Ratheesh S Pece1f832015-07-25 15:50:25 +05305388 if(csrScanIsWildCardScan( pMac, pCommand ) &&
5389 (!pCommand->u.scanCmd.u.scanRequest.p2pSearch)
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005390#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5391 && (pCommand->u.scanCmd.reason != eCsrScanGetLfrResult)
5392#endif
5393 )
Jeff Johnson295189b2012-06-20 16:38:30 -07005394 {
Ratheesh S Pece1f832015-07-25 15:50:25 +05305395 csrScanGetScanChnInfo(pMac, pCommand);
Jeff Johnson295189b2012-06-20 16:38:30 -07005396 }
5397 }
5398 break;
5399 }//switch
5400 if(fRemoveCommand)
5401 {
5402
5403 csrReleaseScanCommand(pMac, pCommand, scanStatus);
5404
Srikant Kuppa866893f2012-12-27 17:28:14 -08005405 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005406 smeProcessPendingQueue( pMac );
5407 }
5408 else
5409 {
5410 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
5411 status = eHAL_STATUS_FAILURE;
5412 }
5413 }
5414 else
5415 {
5416 smsLog( pMac, LOGW, "CSR: Scan Completion called but NO commands are ACTIVE ..." );
5417 status = eHAL_STATUS_FAILURE;
5418 }
5419
5420 return (status);
5421}
5422
5423
5424
5425
5426tCsrScanResultInfo *csrScanResultGetFirst(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
5427{
5428 tListElem *pEntry;
5429 tCsrScanResult *pResult;
5430 tCsrScanResultInfo *pRet = NULL;
5431 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5432
5433 if(pResultList)
5434 {
5435 csrLLLock(&pResultList->List);
5436 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5437 if(pEntry)
5438 {
5439 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
5440 pRet = &pResult->Result;
5441 }
5442 pResultList->pCurEntry = pEntry;
5443 csrLLUnlock(&pResultList->List);
5444 }
5445
5446 return pRet;
5447}
5448
5449
5450tCsrScanResultInfo *csrScanResultGetNext(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
5451{
5452 tListElem *pEntry = NULL;
5453 tCsrScanResult *pResult = NULL;
5454 tCsrScanResultInfo *pRet = NULL;
5455 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5456
5457 if(pResultList)
5458 {
5459 csrLLLock(&pResultList->List);
5460 if(NULL == pResultList->pCurEntry)
5461 {
5462 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5463 }
5464 else
5465 {
5466 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
5467 }
5468 if(pEntry)
5469 {
5470 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
5471 pRet = &pResult->Result;
5472 }
5473 pResultList->pCurEntry = pEntry;
5474 csrLLUnlock(&pResultList->List);
5475 }
5476
5477 return pRet;
5478}
5479
5480
5481//This function moves the first BSS that matches the bssid to the head of the result
5482eHalStatus csrMoveBssToHeadFromBSSID(tpAniSirGlobal pMac, tCsrBssid *bssid, tScanResultHandle hScanResult)
5483{
5484 eHalStatus status = eHAL_STATUS_FAILURE;
5485 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5486 tCsrScanResult *pResult = NULL;
5487 tListElem *pEntry = NULL;
5488
5489 if(pResultList && bssid)
5490 {
5491 csrLLLock(&pResultList->List);
5492 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5493 while(pEntry)
5494 {
5495 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
Kiet Lam64c1b492013-07-12 13:56:44 +05305496 if (vos_mem_compare(bssid, pResult->Result.BssDescriptor.bssId, sizeof(tCsrBssid)))
Jeff Johnson295189b2012-06-20 16:38:30 -07005497 {
5498 status = eHAL_STATUS_SUCCESS;
5499 csrLLRemoveEntry(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
5500 csrLLInsertHead(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
5501 break;
5502 }
5503 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
5504 }
5505 csrLLUnlock(&pResultList->List);
5506 }
5507
5508 return (status);
5509}
5510
5511
5512//Remove the BSS if possible.
5513//Return -- TRUE == the BSS is remove. False == Fail to remove it
5514//This function is called when list lock is held. Be caution what functions it can call.
5515tANI_BOOLEAN csrScanAgeOutBss(tpAniSirGlobal pMac, tCsrScanResult *pResult)
5516{
5517 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
5518 tANI_U32 i;
5519 tCsrRoamSession *pSession;
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305520 tANI_BOOLEAN isConnBssfound = eANI_BOOLEAN_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005521
5522 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5523 {
5524 if( CSR_IS_SESSION_VALID( pMac, i ) )
5525 {
5526 pSession = CSR_GET_SESSION( pMac, i );
5527 //Not to remove the BSS we are connected to.
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305528 if(csrIsConnStateConnectedInfra(pMac, i) && (NULL != pSession->pConnectBssDesc) &&
5529 (csrIsDuplicateBssDescription(pMac, &pResult->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07005530 pSession->pConnectBssDesc, NULL, FALSE))
Jeff Johnson295189b2012-06-20 16:38:30 -07005531 )
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305532 {
5533 isConnBssfound = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005534 break;
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305535 }
5536 }
5537 }
5538
5539 if( isConnBssfound )
Jeff Johnson295189b2012-06-20 16:38:30 -07005540 {
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305541 //Reset the counter so that aging out of connected BSS won't hapeen too soon
Jeff Johnson295189b2012-06-20 16:38:30 -07005542 pResult->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
5543 pResult->Result.BssDescriptor.nReceivedTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305544
5545 return (fRet);
5546 }
5547 else
5548 {
5549 smsLog(pMac, LOGW, "Aging out BSS "MAC_ADDRESS_STR" Channel %d",
5550 MAC_ADDR_ARRAY(pResult->Result.BssDescriptor.bssId),
5551 pResult->Result.BssDescriptor.channelId);
5552 //No need to hold the spin lock because caller should hold the lock for pMac->scan.scanResultList
5553 if( csrLLRemoveEntry(&pMac->scan.scanResultList, &pResult->Link, LL_ACCESS_NOLOCK) )
5554 {
5555 if (csrIsMacAddressEqual(pMac,
5556 (tCsrBssid *) pResult->Result.BssDescriptor.bssId,
5557 (tCsrBssid *) pMac->scan.currentCountryBssid))
5558 {
5559 smsLog(pMac, LOGW, "Aging out 11d BSS "MAC_ADDRESS_STR,
5560 MAC_ADDR_ARRAY(pResult->Result.BssDescriptor.bssId));
5561 pMac->scan.currentCountryRSSI = -128;
5562 }
5563 csrFreeScanResultEntry(pMac, pResult);
5564 fRet = eANI_BOOLEAN_TRUE;
5565 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005566 }
5567
5568 return (fRet);
5569}
5570
5571
5572eHalStatus csrScanAgeResults(tpAniSirGlobal pMac, tSmeGetScanChnRsp *pScanChnInfo)
5573{
5574 eHalStatus status = eHAL_STATUS_SUCCESS;
5575 tListElem *pEntry, *tmpEntry;
5576 tCsrScanResult *pResult;
5577 tLimScanChn *pChnInfo;
5578 tANI_U8 i;
5579
5580 csrLLLock(&pMac->scan.scanResultList);
5581 for(i = 0; i < pScanChnInfo->numChn; i++)
5582 {
5583 pChnInfo = &pScanChnInfo->scanChn[i];
5584 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
5585 while( pEntry )
5586 {
5587 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
5588 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
5589 if(pResult->Result.BssDescriptor.channelId == pChnInfo->channelId)
5590 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005591 if(pResult->AgingCount <= 0)
5592 {
5593 smsLog(pMac, LOGW, " age out due to ref count");
5594 csrScanAgeOutBss(pMac, pResult);
5595 }
Madan Mohan Koyyalamudib9d3dcc2012-09-28 16:47:50 -07005596 else
5597 {
5598 pResult->AgingCount--;
5599 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005600 }
5601 pEntry = tmpEntry;
5602 }
5603 }
5604 csrLLUnlock(&pMac->scan.scanResultList);
5605
5606 return (status);
5607}
5608
Abhishek Singhc640dbb2015-06-08 10:54:17 +05305609eHalStatus csrIbssAgeBss(tpAniSirGlobal pMac)
5610{
5611 eHalStatus status = eHAL_STATUS_SUCCESS;
5612 tListElem *pEntry, *tmpEntry;
5613 tCsrScanResult *pResult;
5614
5615 csrLLLock(&pMac->scan.scanResultList);
5616 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
5617 while( pEntry )
5618 {
5619 tmpEntry = csrLLNext(&pMac->scan.scanResultList,
5620 pEntry, LL_ACCESS_NOLOCK);
5621 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
5622
5623 smsLog(pMac, LOGW, FL(" age out due Forced IBSS leave"));
5624 csrScanAgeOutBss(pMac, pResult);
5625 pEntry = tmpEntry;
5626 }
5627 csrLLUnlock(&pMac->scan.scanResultList);
5628
5629 return (status);
5630}
Jeff Johnson295189b2012-06-20 16:38:30 -07005631
5632eHalStatus csrSendMBScanReq( tpAniSirGlobal pMac, tANI_U16 sessionId,
5633 tCsrScanRequest *pScanReq, tScanReqParam *pScanReqParam )
5634{
5635 eHalStatus status = eHAL_STATUS_SUCCESS;
5636 tSirSmeScanReq *pMsg;
5637 tANI_U16 msgLen;
5638 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
5639 tSirScanType scanType = pScanReq->scanType;
5640 tANI_U32 minChnTime; //in units of milliseconds
5641 tANI_U32 maxChnTime; //in units of milliseconds
5642 tANI_U32 i;
5643 tANI_U8 selfMacAddr[WNI_CFG_BSSID_LEN];
5644 tANI_U8 *pSelfMac = NULL;
5645
5646 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
5647 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) +
5648 ( pScanReq->uIEFieldLen ) ;
5649
Kiet Lam64c1b492013-07-12 13:56:44 +05305650 pMsg = vos_mem_malloc(msgLen);
5651 if ( NULL == pMsg )
5652 status = eHAL_STATUS_FAILURE;
5653 else
5654 status = eHAL_STATUS_SUCCESS;
5655 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07005656 {
5657 do
5658 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305659 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005660 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
5661 pMsg->length = pal_cpu_to_be16(msgLen);
5662 //ToDO: Fill in session info when we need to do scan base on session.
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05305663 if ((pMac->fScanOffload) && (sessionId != CSR_SESSION_ID_INVALID))
5664 {
5665 pMsg->sessionId = sessionId;
5666 }
5667 else
5668 {
5669 /* if sessionId == CSR_SESSION_ID_INVALID, then send the scan
5670 request on first available session */
5671 pMsg->sessionId = 0;
5672 }
5673
Jeff Johnson295189b2012-06-20 16:38:30 -07005674 pMsg->transactionId = 0;
5675 pMsg->dot11mode = (tANI_U8) csrTranslateToWNICfgDot11Mode(pMac, csrFindBestPhyMode( pMac, pMac->roam.configParam.phyMode ));
5676 pMsg->bssType = pal_cpu_to_be32(csrTranslateBsstypeToMacType(pScanReq->BSSType));
5677
5678 if ( CSR_IS_SESSION_VALID( pMac, sessionId ) )
5679 {
5680 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[sessionId].selfMacAddr;
5681 }
5682 else
5683 {
5684 // Since we don't have session for the scanning, we find a valid session. In case we fail to
5685 // do so, get the WNI_CFG_STA_ID
5686 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5687 {
5688 if( CSR_IS_SESSION_VALID( pMac, i ) )
5689 {
5690 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[i].selfMacAddr;
5691 break;
5692 }
5693 }
5694 if( CSR_ROAM_SESSION_MAX == i )
5695 {
5696 tANI_U32 len = WNI_CFG_BSSID_LEN;
5697 pSelfMac = selfMacAddr;
5698 status = ccmCfgGetStr( pMac, WNI_CFG_STA_ID, pSelfMac, &len );
5699 if( !HAL_STATUS_SUCCESS( status ) ||
5700 ( len < WNI_CFG_BSSID_LEN ) )
5701 {
5702 smsLog( pMac, LOGE, FL(" Can not get self MAC address from CFG status = %d"), status );
5703 //Force failed status
5704 status = eHAL_STATUS_FAILURE;
5705 break;
5706 }
5707 }
5708 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305709 vos_mem_copy((tANI_U8 *)pMsg->selfMacAddr, pSelfMac, sizeof(tSirMacAddr));
Jeff Johnson295189b2012-06-20 16:38:30 -07005710
5711 //sirCopyMacAddr
Kiet Lam64c1b492013-07-12 13:56:44 +05305712 vos_mem_copy((tANI_U8 *)pMsg->bssId, (tANI_U8 *)&pScanReq->bssid, sizeof(tSirMacAddr));
5713 if ( vos_mem_compare(pScanReq->bssid, bssid, sizeof(tCsrBssid)))
Jeff Johnson295189b2012-06-20 16:38:30 -07005714 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305715 vos_mem_set(pMsg->bssId, sizeof(tSirMacAddr), 0xff);
Jeff Johnson295189b2012-06-20 16:38:30 -07005716 }
5717 else
5718 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305719 vos_mem_copy(pMsg->bssId, pScanReq->bssid, WNI_CFG_BSSID_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07005720 }
5721 minChnTime = pScanReq->minChnTime;
5722 maxChnTime = pScanReq->maxChnTime;
5723
5724 //Verify the scan type first, if the scan is active scan, we need to make sure we
5725 //are allowed to do so.
5726 /* if 11d is enabled & we don't see any beacon around, scan type falls
5727 back to passive. But in BT AMP STA mode we need to send out a
5728 directed probe*/
5729 if( (eSIR_PASSIVE_SCAN != scanType) && (eCSR_SCAN_P2P_DISCOVERY != pScanReq->requestType)
5730 && (eCSR_BSS_TYPE_WDS_STA != pScanReq->BSSType)
5731 && (eANI_BOOLEAN_FALSE == pMac->scan.fEnableBypass11d))
5732 {
5733 scanType = pMac->scan.curScanType;
5734 if(eSIR_PASSIVE_SCAN == pMac->scan.curScanType)
5735 {
5736 if(minChnTime < pMac->roam.configParam.nPassiveMinChnTime)
5737 {
5738 minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
5739 }
5740 if(maxChnTime < pMac->roam.configParam.nPassiveMaxChnTime)
5741 {
5742 maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
5743 }
5744 }
5745 }
5746 pMsg->scanType = pal_cpu_to_be32(scanType);
5747
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05305748 pMsg->numSsid =
5749 (pScanReq->SSIDs.numOfSSIDs < SIR_SCAN_MAX_NUM_SSID) ?
5750 pScanReq->SSIDs.numOfSSIDs : SIR_SCAN_MAX_NUM_SSID;
Jeff Johnson295189b2012-06-20 16:38:30 -07005751 if((pScanReq->SSIDs.numOfSSIDs != 0) && ( eSIR_PASSIVE_SCAN != scanType ))
5752 {
Jeff Johnson40b59aa2013-03-19 14:43:18 -07005753 for (i = 0; i < pMsg->numSsid; i++)
5754 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305755 vos_mem_copy(&pMsg->ssId[i],
5756 &pScanReq->SSIDs.SSIDList[i].SSID, sizeof(tSirMacSSid));
Jeff Johnson40b59aa2013-03-19 14:43:18 -07005757 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005758 }
5759 else
5760 {
5761 //Otherwise we scan all SSID and let the result filter later
Jeff Johnson40b59aa2013-03-19 14:43:18 -07005762 for (i = 0; i < SIR_SCAN_MAX_NUM_SSID; i++)
5763 {
5764 pMsg->ssId[i].length = 0;
5765 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005766 }
5767
Jeff Johnson295189b2012-06-20 16:38:30 -07005768 pMsg->minChannelTime = pal_cpu_to_be32(minChnTime);
5769 pMsg->maxChannelTime = pal_cpu_to_be32(maxChnTime);
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08005770 pMsg->minChannelTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
5771 pMsg->maxChannelTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07005772 //hidden SSID option
5773 pMsg->hiddenSsid = pScanReqParam->hiddenSsid;
5774 //rest time
5775 //pMsg->restTime = pScanReq->restTime;
5776 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
5777 // All the scan results caching will be done by Roaming
5778 // We do not want LIM to do any caching of scan results,
5779 // so delete the LIM cache on all scan requests
5780 pMsg->returnFreshResults = pScanReqParam->freshScan;
5781 //Always ask for unique result
5782 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
5783 pMsg->channelList.numChannels = (tANI_U8)pScanReq->ChannelInfo.numOfChannels;
5784 if(pScanReq->ChannelInfo.numOfChannels)
5785 {
5786 //Assuming the channelNumber is tANI_U8 (1 byte)
Kiet Lam64c1b492013-07-12 13:56:44 +05305787 vos_mem_copy(pMsg->channelList.channelNumber,
5788 pScanReq->ChannelInfo.ChannelList,
5789 pScanReq->ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07005790 }
5791
5792 pMsg->uIEFieldLen = (tANI_U16) pScanReq->uIEFieldLen;
5793 pMsg->uIEFieldOffset = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
5794 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) ;
5795 if(pScanReq->uIEFieldLen != 0)
5796 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305797 vos_mem_copy((tANI_U8 *)pMsg+pMsg->uIEFieldOffset, pScanReq->pIEField,
5798 pScanReq->uIEFieldLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07005799 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005800 pMsg->p2pSearch = pScanReq->p2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07005801
Madan Mohan Koyyalamudi9b876782012-10-11 16:22:51 -07005802 if (pScanReq->requestType == eCSR_SCAN_HO_BG_SCAN)
5803 {
5804 pMsg->backgroundScanMode = eSIR_ROAMING_SCAN;
5805 }
5806
Jeff Johnson295189b2012-06-20 16:38:30 -07005807 }while(0);
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05305808 smsLog(pMac, LOG1, FL("domainIdCurrent %s (%d) scanType %s (%d)"
5809 "bssType %s (%d), requestType %s(%d)"
5810 "numChannels %d"),
5811 voss_DomainIdtoString(pMac->scan.domainIdCurrent),
5812 pMac->scan.domainIdCurrent,
5813 lim_ScanTypetoString(pMsg->scanType), pMsg->scanType,
5814 lim_BssTypetoString(pMsg->bssType), pMsg->bssType,
5815 sme_requestTypetoString(pScanReq->requestType),
5816 pScanReq->requestType,
5817 pMsg->channelList.numChannels);
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005818
5819 for(i = 0; i < pMsg->channelList.numChannels; i++)
5820 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005821 smsLog(pMac, LOG3, FL("channelNumber[%d]= %d"), i, pMsg->channelList.channelNumber[i]);
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005822 }
5823
Jeff Johnson295189b2012-06-20 16:38:30 -07005824 if(HAL_STATUS_SUCCESS(status))
5825 {
5826 status = palSendMBMessage(pMac->hHdd, pMsg);
5827 }
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005828 else
5829 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005830 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d"), status );
Kiet Lam64c1b492013-07-12 13:56:44 +05305831 vos_mem_free(pMsg);
Jeff Johnson295189b2012-06-20 16:38:30 -07005832 }
5833 }//Success allocated memory
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005834 else
5835 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005836 smsLog( pMac, LOGE, FL(" memory allocation failure"));
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005837 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005838
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05305839 if(!HAL_STATUS_SUCCESS(status))
5840 {
5841 smsLog( pMac, LOG1, FL("Failed: SId: %d FirstMatch = %d"
5842 " UniqueResult = %d freshScan = %d hiddenSsid = %d"),
5843 sessionId, pScanReqParam->bReturnAfter1stMatch,
5844 pScanReqParam->fUniqueResult, pScanReqParam->freshScan,
5845 pScanReqParam->hiddenSsid );
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05305846 smsLog( pMac, LOG1, FL("scanType = %s (%d) BSSType = %s (%d) "
5847 "numOfSSIDs = %d numOfChannels = %d requestType = %s (%d)"
5848 " p2pSearch = %d\n"),
5849 lim_ScanTypetoString(pScanReq->scanType),
5850 pScanReq->scanType,
5851 lim_BssTypetoString(pScanReq->BSSType),
5852 pScanReq->BSSType,
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05305853 pScanReq->SSIDs.numOfSSIDs,
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05305854 pScanReq->ChannelInfo.numOfChannels,
5855 sme_requestTypetoString(pScanReq->requestType),
5856 pScanReq->requestType,
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05305857 pScanReq->p2pSearch );
5858
5859 }
5860
Jeff Johnson295189b2012-06-20 16:38:30 -07005861 return( status );
5862}
5863
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005864eHalStatus csrSendMBScanResultReq( tpAniSirGlobal pMac, tANI_U32 sessionId, tScanReqParam *pScanReqParam )
Jeff Johnson295189b2012-06-20 16:38:30 -07005865{
5866 eHalStatus status = eHAL_STATUS_SUCCESS;
5867 tSirSmeScanReq *pMsg;
5868 tANI_U16 msgLen;
5869
5870 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ));
Kiet Lam64c1b492013-07-12 13:56:44 +05305871 pMsg = vos_mem_malloc(msgLen);
5872 if ( NULL == pMsg )
5873 status = eHAL_STATUS_FAILURE;
5874 else
Jeff Johnson295189b2012-06-20 16:38:30 -07005875 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305876 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005877 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
5878 pMsg->length = pal_cpu_to_be16(msgLen);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005879 pMsg->sessionId = sessionId;
5880 pMsg->transactionId = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07005881 pMsg->returnFreshResults = pScanReqParam->freshScan;
5882 //Always ask for unique result
5883 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
5884 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
5885 status = palSendMBMessage(pMac->hHdd, pMsg);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005886 if (!HAL_STATUS_SUCCESS(status))
5887 {
5888 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d\n"), status );
5889 }
5890
Jeff Johnson295189b2012-06-20 16:38:30 -07005891 }
5892
5893 return( status );
5894}
5895
5896
5897
5898eHalStatus csrScanChannels( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5899{
5900 eHalStatus status = eHAL_STATUS_FAILURE;
5901 tScanReqParam scanReq;
5902
5903 do
5904 {
5905 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE | TRUE;
5906 scanReq.fUniqueResult = TRUE;
5907 scanReq.hiddenSsid = SIR_SCAN_NO_HIDDEN_SSID;
5908 if(eCsrScanForSsid == pCommand->u.scanCmd.reason)
5909 {
5910 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_FIRST_MATCH;
5911 }
5912 else
5913 {
5914 // Basically do scan on all channels even for 11D 1st scan case.
5915 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5916 }
5917 if((eCsrScanBgScan == pCommand->u.scanCmd.reason)||
5918 (eCsrScanProbeBss == pCommand->u.scanCmd.reason))
5919 {
5920 scanReq.hiddenSsid = SIR_SCAN_HIDDEN_SSID_PE_DECISION;
5921 }
5922
5923#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5924 {
5925 vos_log_scan_pkt_type *pScanLog = NULL;
5926
5927 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
5928 if(pScanLog)
5929 {
5930 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
5931 eCsrScanProbeBss == pCommand->u.scanCmd.reason)
5932 {
5933 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
5934 }
5935 else
5936 {
5937 if( (eSIR_PASSIVE_SCAN != pCommand->u.scanCmd.u.scanRequest.scanType) &&
5938 (eSIR_PASSIVE_SCAN != pMac->scan.curScanType) )
5939 {
5940 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_REQ;
5941 }
5942 else
5943 {
5944 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_REQ;
5945 }
5946 }
5947 pScanLog->minChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.minChnTime;
5948 pScanLog->maxChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.maxChnTime;
5949 pScanLog->numChannel = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
5950 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
5951 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305952 vos_mem_copy(pScanLog->channels,
5953 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
5954 pScanLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07005955 }
5956 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
5957 }
5958 }
5959#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5960
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05305961 csrClearVotesForCountryInfo(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07005962 status = csrSendMBScanReq(pMac, pCommand->sessionId,
5963 &pCommand->u.scanCmd.u.scanRequest, &scanReq);
5964 }while(0);
5965
5966 return( status );
5967}
5968
5969
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005970eHalStatus csrScanRetrieveResult(tpAniSirGlobal pMac, tSmeCmd *pCommand)
Jeff Johnson295189b2012-06-20 16:38:30 -07005971{
5972 eHalStatus status = eHAL_STATUS_FAILURE;
5973 tScanReqParam scanReq;
5974
5975 do
5976 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005977#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5978 if (eCsrScanGetLfrResult == pCommand->u.scanCmd.reason)
5979 {
5980 //to get the LFR candidates from PE cache
5981 scanReq.freshScan = SIR_BG_SCAN_RETURN_LFR_CACHED_RESULTS|SIR_BG_SCAN_PURGE_LFR_RESULTS;
5982 scanReq.fUniqueResult = TRUE;
5983 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5984 }
5985 else
5986#endif
5987 {
5988 //not a fresh scan
5989 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE;
5990 scanReq.fUniqueResult = TRUE;
5991 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5992 }
5993 status = csrSendMBScanResultReq(pMac, pCommand->sessionId, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07005994 }while(0);
5995
5996 return (status);
5997}
5998
Siddharth Bhald8a95e82015-02-12 20:14:52 +05305999eHalStatus csrProcessMacAddrSpoofCommand( tpAniSirGlobal pMac, tSmeCmd *pCommand )
6000{
6001 tSirSpoofMacAddrReq *pMsg;
6002 tANI_U16 msgLen;
6003 eHalStatus status = eHAL_STATUS_FAILURE;
6004 do {
6005 msgLen = sizeof(tSirSpoofMacAddrReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07006006
Siddharth Bhald8a95e82015-02-12 20:14:52 +05306007 pMsg = vos_mem_malloc(msgLen);
6008 if ( NULL == pMsg )
6009 return eHAL_STATUS_FAILURE;
6010 pMsg->messageType= pal_cpu_to_be16((tANI_U16)eWNI_SME_MAC_SPOOF_ADDR_IND);
6011 pMsg->length= pal_cpu_to_be16(msgLen);
6012 // spoof mac address
6013 vos_mem_copy((tANI_U8 *)pMsg->macAddr,
6014 (tANI_U8 *)pCommand->u.macAddrSpoofCmd.macAddr, sizeof(tSirMacAddr));
6015 status = palSendMBMessage(pMac->hHdd, pMsg);
6016 } while( 0 );
6017 return( status );
6018}
Jeff Johnson295189b2012-06-20 16:38:30 -07006019
6020eHalStatus csrProcessScanCommand( tpAniSirGlobal pMac, tSmeCmd *pCommand )
6021{
6022 eHalStatus status = eHAL_STATUS_SUCCESS;
6023 tCsrChannelInfo newChannelInfo = {0, NULL};
6024 int i, j;
6025 tANI_U8 *pChannel = NULL;
6026 tANI_U32 len = 0;
6027
6028 // Transition to Scanning state...
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306029 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07006030 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306031 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
6032 {
6033 pCommand->u.scanCmd.lastRoamState[i] =
6034 csrRoamStateChange( pMac, eCSR_ROAMING_STATE_SCANNING, i);
6035 smsLog( pMac, LOG3, "starting SCAN command from %d state...."
6036 " reason is %d", pCommand->u.scanCmd.lastRoamState[i],
6037 pCommand->u.scanCmd.reason );
6038 }
6039 }
6040 else
6041 {
6042 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId] =
6043 csrRoamStateChange(pMac, eCSR_ROAMING_STATE_SCANNING,
6044 pCommand->sessionId);
6045 smsLog( pMac, LOG3,
6046 "starting SCAN command from %d state.... reason is %d",
6047 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId],
6048 pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07006049 }
6050
6051 switch(pCommand->u.scanCmd.reason)
6052 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006053#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
6054 case eCsrScanGetLfrResult:
6055#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006056 case eCsrScanGetResult:
6057 case eCsrScanForCapsChange: //For cap change, LIM already save BSS description
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006058 status = csrScanRetrieveResult(pMac, pCommand);
Jeff Johnson295189b2012-06-20 16:38:30 -07006059 break;
6060 case eCsrScanSetBGScanParam:
6061 status = csrProcessSetBGScanParam(pMac, pCommand);
6062 break;
6063 case eCsrScanBGScanAbort:
6064 status = csrSetCfgBackgroundScanPeriod(pMac, 0);
6065 break;
6066 case eCsrScanBGScanEnable:
6067 status = csrSetCfgBackgroundScanPeriod(pMac, pMac->roam.configParam.bgScanInterval);
6068 break;
6069 case eCsrScanGetScanChnInfo:
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05306070 status = csrScanGetScanChannelInfo(pMac, pCommand->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07006071 break;
6072 case eCsrScanUserRequest:
6073 if(pMac->roam.configParam.fScanTwice)
6074 {
6075 //We scan 2.4 channel twice
6076 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels &&
6077 (NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList))
6078 {
6079 len = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
6080 //allocate twice the channel
Mukul Sharmaa631e892014-08-28 15:38:51 +05306081 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(len * 2);
Jeff Johnson295189b2012-06-20 16:38:30 -07006082 pChannel = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
6083 }
6084 else
6085 {
6086 //get the valid channel list to scan all.
6087 len = sizeof(pMac->roam.validChannelList);
6088
6089 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
6090 {
6091 //allocate twice the channel
6092 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(len * 2);
6093 pChannel = pMac->roam.validChannelList;
6094 }
6095 }
6096 if(NULL == newChannelInfo.ChannelList)
6097 {
6098 newChannelInfo.numOfChannels = 0;
6099 }
6100 else
6101 {
6102 j = 0;
6103 for(i = 0; i < len; i++)
6104 {
6105 newChannelInfo.ChannelList[j++] = pChannel[i];
6106 if(CSR_MAX_24GHz_CHANNEL_NUMBER >= pChannel[i])
6107 {
6108 newChannelInfo.ChannelList[j++] = pChannel[i];
6109 }
6110 }
6111 if(NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
6112 {
6113 //pChannel points to the channellist from the command, free it.
6114 vos_mem_free(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -07006115 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07006116 }
6117 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = j;
6118 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = newChannelInfo.ChannelList;
6119 }
6120 } //if(pMac->roam.configParam.fScanTwice)
6121
6122 status = csrScanChannels(pMac, pCommand);
6123
6124 break;
6125 default:
6126 status = csrScanChannels(pMac, pCommand);
6127 break;
6128 }
6129
6130 if(!HAL_STATUS_SUCCESS(status))
6131 {
6132 csrReleaseScanCommand(pMac, pCommand, eCSR_SCAN_FAILURE);
6133 }
6134
6135 return (status);
6136}
6137
6138
6139eHalStatus csrScanSetBGScanparams(tpAniSirGlobal pMac, tCsrBGScanRequest *pScanReq)
6140{
6141 eHalStatus status = eHAL_STATUS_SUCCESS;
6142 tSmeCmd *pCommand = NULL;
6143
6144 if(pScanReq)
6145 {
6146 do
6147 {
6148 pCommand = csrGetCommandBuffer(pMac);
6149 if(!pCommand)
6150 {
6151 status = eHAL_STATUS_RESOURCES;
6152 break;
6153 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306154 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006155 pCommand->command = eSmeCommandScan;
6156 pCommand->u.scanCmd.reason = eCsrScanSetBGScanParam;
6157 pCommand->u.scanCmd.callback = NULL;
6158 pCommand->u.scanCmd.pContext = NULL;
Kiet Lam64c1b492013-07-12 13:56:44 +05306159 vos_mem_copy(&pCommand->u.scanCmd.u.bgScanRequest, pScanReq, sizeof(tCsrBGScanRequest));
Jeff Johnson295189b2012-06-20 16:38:30 -07006160 //we have to do the follow
6161 if(pScanReq->ChannelInfo.numOfChannels == 0)
6162 {
6163 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
6164 }
6165 else
6166 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306167 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList
6168 = vos_mem_malloc(pScanReq->ChannelInfo.numOfChannels);
6169 if ( NULL != pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07006170 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306171 vos_mem_copy(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList,
6172 pScanReq->ChannelInfo.ChannelList,
6173 pScanReq->ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07006174 }
6175 else
6176 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006177 smsLog(pMac, LOGE, FL("ran out of memory"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006178 csrReleaseCommandScan(pMac, pCommand);
Kiet Lam64c1b492013-07-12 13:56:44 +05306179 return eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006180 }
6181 }
6182
6183 //scan req for SSID
6184 if(pScanReq->SSID.length)
6185 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306186 vos_mem_copy(pCommand->u.scanCmd.u.bgScanRequest.SSID.ssId,
6187 pScanReq->SSID.ssId, pScanReq->SSID.length);
Jeff Johnson295189b2012-06-20 16:38:30 -07006188 pCommand->u.scanCmd.u.bgScanRequest.SSID.length = pScanReq->SSID.length;
6189
6190 }
6191 pCommand->u.scanCmd.u.bgScanRequest.maxChnTime= pScanReq->maxChnTime;
6192 pCommand->u.scanCmd.u.bgScanRequest.minChnTime = pScanReq->minChnTime;
6193 pCommand->u.scanCmd.u.bgScanRequest.scanInterval = pScanReq->scanInterval;
6194
6195
6196 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
6197 if( !HAL_STATUS_SUCCESS( status ) )
6198 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006199 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006200 csrReleaseCommandScan( pMac, pCommand );
6201 break;
6202 }
6203 }while(0);
6204 }
6205
6206 return (status);
6207}
6208
6209eHalStatus csrScanBGScanAbort( tpAniSirGlobal pMac )
6210{
6211 eHalStatus status = eHAL_STATUS_SUCCESS;
6212 tSmeCmd *pCommand = NULL;
6213
6214 do
6215 {
6216 pCommand = csrGetCommandBuffer(pMac);
6217 if(!pCommand)
6218 {
6219 status = eHAL_STATUS_RESOURCES;
6220 break;
6221 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306222 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006223 pCommand->command = eSmeCommandScan;
6224 pCommand->u.scanCmd.reason = eCsrScanBGScanAbort;
6225 pCommand->u.scanCmd.callback = NULL;
6226 pCommand->u.scanCmd.pContext = NULL;
6227 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
6228 if( !HAL_STATUS_SUCCESS( status ) )
6229 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006230 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006231 csrReleaseCommandScan( pMac, pCommand );
6232 break;
6233 }
6234 }while(0);
6235
6236 return (status);
6237}
6238
6239
6240//This will enable the background scan with the non-zero interval
6241eHalStatus csrScanBGScanEnable(tpAniSirGlobal pMac)
6242{
6243 eHalStatus status = eHAL_STATUS_SUCCESS;
6244 tSmeCmd *pCommand = NULL;
6245
6246 if(pMac->roam.configParam.bgScanInterval)
6247 {
6248 do
6249 {
6250 pCommand = csrGetCommandBuffer(pMac);
6251 if(!pCommand)
6252 {
6253 status = eHAL_STATUS_RESOURCES;
6254 break;
6255 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306256 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006257 pCommand->command = eSmeCommandScan;
6258 pCommand->u.scanCmd.reason = eCsrScanBGScanEnable;
6259 pCommand->u.scanCmd.callback = NULL;
6260 pCommand->u.scanCmd.pContext = NULL;
6261 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
6262 if( !HAL_STATUS_SUCCESS( status ) )
6263 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006264 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006265 csrReleaseCommandScan( pMac, pCommand );
6266 break;
6267 }
6268 }while(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006269 }
6270 else
6271 {
Sushant Kaushikb8dbb3f2015-04-29 17:03:37 +05306272 smsLog(pMac, LOGE, FL("cannot continue because the bgscan interval is 0"));
6273 status = eHAL_STATUS_INVALID_PARAMETER;
Jeff Johnson295189b2012-06-20 16:38:30 -07006274 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006275 return (status);
6276}
6277
6278
6279eHalStatus csrScanCopyRequest(tpAniSirGlobal pMac, tCsrScanRequest *pDstReq, tCsrScanRequest *pSrcReq)
6280{
6281 eHalStatus status = eHAL_STATUS_SUCCESS;
6282 tANI_U32 len = sizeof(pMac->roam.validChannelList);
6283 tANI_U32 index = 0;
6284 tANI_U32 new_index = 0;
Manjunathappa Prakashde7b2a52014-02-28 16:59:03 -08006285 eNVChannelEnabledType NVchannel_state;
Arif Hussain6af38622014-03-12 12:39:57 -07006286 tANI_U8 ch144_support = 0;
6287
6288 ch144_support = WDA_getFwWlanFeatCaps(WLAN_CH144);
Jeff Johnson295189b2012-06-20 16:38:30 -07006289
6290 do
6291 {
6292 status = csrScanFreeRequest(pMac, pDstReq);
6293 if(HAL_STATUS_SUCCESS(status))
6294 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306295 vos_mem_copy(pDstReq, pSrcReq, sizeof(tCsrScanRequest));
Gopichand Nakkalac7b1d3e2012-12-31 14:07:19 -08006296 /* Re-initialize the pointers to NULL since we did a copy */
6297 pDstReq->pIEField = NULL;
6298 pDstReq->ChannelInfo.ChannelList = NULL;
6299 pDstReq->SSIDs.SSIDList = NULL;
6300
Jeff Johnson295189b2012-06-20 16:38:30 -07006301 if(pSrcReq->uIEFieldLen == 0)
6302 {
6303 pDstReq->pIEField = NULL;
6304 }
6305 else
6306 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306307 pDstReq->pIEField = vos_mem_malloc(pSrcReq->uIEFieldLen);
6308 if ( NULL == pDstReq->pIEField )
Jeff Johnson295189b2012-06-20 16:38:30 -07006309 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306310 status = eHAL_STATUS_FAILURE;
6311 smsLog(pMac, LOGE, FL("No memory for scanning IE fields"));
6312 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07006313 }
6314 else
6315 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306316 status = eHAL_STATUS_SUCCESS;
6317 vos_mem_copy(pDstReq->pIEField, pSrcReq->pIEField,
6318 pSrcReq->uIEFieldLen);
6319 pDstReq->uIEFieldLen = pSrcReq->uIEFieldLen;
Jeff Johnson295189b2012-06-20 16:38:30 -07006320 }
6321 }//Allocate memory for IE field
6322 {
6323 if(pSrcReq->ChannelInfo.numOfChannels == 0)
6324 {
6325 pDstReq->ChannelInfo.ChannelList = NULL;
6326 pDstReq->ChannelInfo.numOfChannels = 0;
6327 }
6328 else
6329 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306330 pDstReq->ChannelInfo.ChannelList = vos_mem_malloc(
6331 pSrcReq->ChannelInfo.numOfChannels
6332 * sizeof(*pDstReq->ChannelInfo.ChannelList));
6333 if ( NULL == pDstReq->ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07006334 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306335 status = eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006336 pDstReq->ChannelInfo.numOfChannels = 0;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306337 smsLog(pMac, LOGE, FL("No memory for scanning Channel"
6338 " List"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006339 break;
6340 }
6341
6342 if((pSrcReq->scanType == eSIR_PASSIVE_SCAN) && (pSrcReq->requestType == eCSR_SCAN_REQUEST_11D_SCAN))
6343 {
6344 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
6345 {
Arif Hussain6af38622014-03-12 12:39:57 -07006346 /* Skip CH 144 if firmware support not present */
6347 if (pSrcReq->ChannelInfo.ChannelList[index] == 144 && !ch144_support)
6348 continue;
Agarwal Ashish8bd53ae2015-06-12 18:03:45 +05306349 /* Skip channel 12 and 13 when FCC constraint is true */
6350 if ((pMac->scan.fcc_constraint) &&
6351 ((pSrcReq->ChannelInfo.ChannelList[index] ==12) ||
6352 (pSrcReq->ChannelInfo.ChannelList[index] ==13)))
6353 {
6354 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
6355 FL("Ignoring channel : %d "),
6356 pSrcReq->ChannelInfo.ChannelList[index]);
6357 continue;
6358 }
Arif Hussain6af38622014-03-12 12:39:57 -07006359
Manjunathappa Prakashde7b2a52014-02-28 16:59:03 -08006360 NVchannel_state = vos_nv_getChannelEnabledState(
6361 pSrcReq->ChannelInfo.ChannelList[index]);
6362 if ((NV_CHANNEL_ENABLE == NVchannel_state) ||
6363 (NV_CHANNEL_DFS == NVchannel_state))
6364 {
6365 pDstReq->ChannelInfo.ChannelList[new_index] =
6366 pSrcReq->ChannelInfo.ChannelList[index];
6367 new_index++;
6368 }
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306369 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006370 pDstReq->ChannelInfo.numOfChannels = new_index;
6371 }
6372 else if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
6373 {
6374 new_index = 0;
6375 pMac->roam.numValidChannels = len;
c_hpothu0d5a7352014-03-22 12:30:25 +05306376
6377 /* Since in CsrScanRequest,value of pMac->scan.nextScanID
6378 * is incremented before calling CsrScanCopyRequest, as a
6379 * result pMac->scan.nextScanID is equal to ONE for the
6380 * first scan.
6381 */
Ganesh Kondabattini8f6e3b32014-08-25 16:07:54 +05306382 if ((pMac->roam.configParam.initialScanSkipDFSCh &&
6383 1 == pMac->scan.nextScanID) ||(pMac->miracast_mode))
c_hpothu0d5a7352014-03-22 12:30:25 +05306384 {
6385 smsLog(pMac, LOG1,
6386 FL("Initial scan, scan only non-DFS channels"));
6387
6388 for (index = 0; index < pSrcReq->ChannelInfo.
6389 numOfChannels ; index++ )
6390 {
6391 if((csrRoamIsValidChannel(pMac, pSrcReq->ChannelInfo.
6392 ChannelList[index])))
6393 {
6394 /*Skiipping DFS Channels for 1st scan */
6395 if(NV_CHANNEL_DFS ==
6396 vos_nv_getChannelEnabledState(pSrcReq->ChannelInfo.
6397 ChannelList[index]))
6398 continue ;
6399
6400 pDstReq->ChannelInfo.ChannelList[new_index] =
6401 pSrcReq->ChannelInfo.ChannelList[index];
6402 new_index++;
6403
6404 }
6405 }
6406 pMac->roam.configParam.initialScanSkipDFSCh = 0;
6407 }
6408 else
6409 {
6410 for ( index = 0; index < pSrcReq->ChannelInfo.
6411 numOfChannels ; index++ )
Jeff Johnson295189b2012-06-20 16:38:30 -07006412 {
Arif Hussain6af38622014-03-12 12:39:57 -07006413 /* Skip CH 144 if firmware support not present */
6414 if (pSrcReq->ChannelInfo.ChannelList[index] == 144 && !ch144_support)
6415 continue;
6416
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -07006417 /* Allow scan on valid channels only.
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -07006418 */
Abhishek Singh2ec36ab2014-08-07 16:14:25 +05306419 if ( ( csrRoamIsValidChannel(pMac, pSrcReq->ChannelInfo.ChannelList[index]) ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07006420 {
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05306421 if( ((pSrcReq->skipDfsChnlInP2pSearch ||
6422 (pMac->scan.fEnableDFSChnlScan ==
6423 DFS_CHNL_SCAN_DISABLED)) &&
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08006424 (NV_CHANNEL_DFS == vos_nv_getChannelEnabledState(pSrcReq->ChannelInfo.ChannelList[index])) )
Srikant Kuppa866893f2012-12-27 17:28:14 -08006425#ifdef FEATURE_WLAN_LFR
6426 /*
6427 * If LFR is requesting a contiguous scan
6428 * (i.e. numOfChannels > 1), then ignore
6429 * DFS channels.
6430 * TODO: vos_nv_getChannelEnabledState is returning
6431 * 120, 124 and 128 as non-DFS channels. Hence, the
6432 * use of direct check for channels below.
6433 */
6434 || ((eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType) &&
6435 (pSrcReq->ChannelInfo.numOfChannels > 1) &&
Santhosh Kumar Padma9ccaaff2014-07-09 19:58:12 +05306436 (CSR_IS_CHANNEL_DFS(pSrcReq->ChannelInfo.ChannelList[index])) &&
6437 !pMac->roam.configParam.allowDFSChannelRoam)
Srikant Kuppa866893f2012-12-27 17:28:14 -08006438#endif
6439 )
6440 {
6441#ifdef FEATURE_WLAN_LFR
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05306442 smsLog(pMac, LOG2,
6443 FL(" reqType=%s (%d), numOfChannels=%d,"
6444 " ignoring DFS channel %d"),
6445 sme_requestTypetoString(pSrcReq->requestType),
6446 pSrcReq->requestType,
6447 pSrcReq->ChannelInfo.numOfChannels,
6448 pSrcReq->ChannelInfo.ChannelList[index]);
Srikant Kuppa866893f2012-12-27 17:28:14 -08006449#endif
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05306450 continue;
Srikant Kuppa866893f2012-12-27 17:28:14 -08006451 }
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08006452
Jeff Johnson295189b2012-06-20 16:38:30 -07006453 pDstReq->ChannelInfo.ChannelList[new_index] =
6454 pSrcReq->ChannelInfo.ChannelList[index];
6455 new_index++;
6456 }
6457 }
c_hpothu0d5a7352014-03-22 12:30:25 +05306458 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006459 pDstReq->ChannelInfo.numOfChannels = new_index;
Srikant Kuppa866893f2012-12-27 17:28:14 -08006460#ifdef FEATURE_WLAN_LFR
Abhishek Singh2ec36ab2014-08-07 16:14:25 +05306461 if ( ( ( eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType ) ||
6462 ( eCSR_SCAN_P2P_DISCOVERY == pSrcReq->requestType ) ) &&
6463 ( 0 == pDstReq->ChannelInfo.numOfChannels ) )
Srikant Kuppa866893f2012-12-27 17:28:14 -08006464 {
6465 /*
6466 * No valid channels found in the request.
6467 * Only perform scan on the channels passed
Abhishek Singh2ec36ab2014-08-07 16:14:25 +05306468 * pSrcReq if it is a eCSR_SCAN_HO_BG_SCAN or
6469 * eCSR_SCAN_P2P_DISCOVERY.
Srikant Kuppa866893f2012-12-27 17:28:14 -08006470 * Passing 0 to LIM will trigger a scan on
6471 * all valid channels which is not desirable.
6472 */
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306473 smsLog(pMac, LOGE, FL(" no valid channels found"
6474 " (request=%d)"), pSrcReq->requestType);
Srikant Kuppa866893f2012-12-27 17:28:14 -08006475 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
6476 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306477 smsLog(pMac, LOGE, FL("pSrcReq index=%d"
6478 " channel=%d"), index,
6479 pSrcReq->ChannelInfo.ChannelList[index]);
Srikant Kuppa866893f2012-12-27 17:28:14 -08006480 }
6481 status = eHAL_STATUS_FAILURE;
6482 break;
6483 }
6484#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006485 }
6486 else
6487 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306488 smsLog(pMac, LOGE, FL("Couldn't get the valid Channel"
6489 " List, keeping requester's list"));
Kiet Lam64c1b492013-07-12 13:56:44 +05306490 vos_mem_copy(pDstReq->ChannelInfo.ChannelList,
6491 pSrcReq->ChannelInfo.ChannelList,
6492 pSrcReq->ChannelInfo.numOfChannels
6493 * sizeof(*pDstReq->ChannelInfo.ChannelList));
Jeff Johnson295189b2012-06-20 16:38:30 -07006494 pDstReq->ChannelInfo.numOfChannels = pSrcReq->ChannelInfo.numOfChannels;
6495 }
6496 }//Allocate memory for Channel List
6497 }
6498 if(pSrcReq->SSIDs.numOfSSIDs == 0)
6499 {
6500 pDstReq->SSIDs.numOfSSIDs = 0;
6501 pDstReq->SSIDs.SSIDList = NULL;
6502 }
6503 else
6504 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306505 pDstReq->SSIDs.SSIDList = vos_mem_malloc(
6506 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
6507 if ( NULL == pDstReq->SSIDs.SSIDList )
6508 status = eHAL_STATUS_FAILURE;
6509 else
6510 status = eHAL_STATUS_SUCCESS;
6511 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07006512 {
6513 pDstReq->SSIDs.numOfSSIDs = pSrcReq->SSIDs.numOfSSIDs;
Kiet Lam64c1b492013-07-12 13:56:44 +05306514 vos_mem_copy(pDstReq->SSIDs.SSIDList,
6515 pSrcReq->SSIDs.SSIDList,
6516 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
Jeff Johnson295189b2012-06-20 16:38:30 -07006517 }
6518 else
6519 {
6520 pDstReq->SSIDs.numOfSSIDs = 0;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306521 smsLog(pMac, LOGE, FL("No memory for scanning SSID List"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006522 break;
6523 }
6524 }//Allocate memory for SSID List
Jeff Johnson295189b2012-06-20 16:38:30 -07006525 pDstReq->p2pSearch = pSrcReq->p2pSearch;
Jeff Johnsone7245742012-09-05 17:12:55 -07006526 pDstReq->skipDfsChnlInP2pSearch = pSrcReq->skipDfsChnlInP2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07006527
6528 }
6529 }while(0);
6530
6531 if(!HAL_STATUS_SUCCESS(status))
6532 {
6533 csrScanFreeRequest(pMac, pDstReq);
6534 }
6535
6536 return (status);
6537}
6538
6539
6540eHalStatus csrScanFreeRequest(tpAniSirGlobal pMac, tCsrScanRequest *pReq)
6541{
Jeff Johnson295189b2012-06-20 16:38:30 -07006542
6543 if(pReq->ChannelInfo.ChannelList)
6544 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306545 vos_mem_free(pReq->ChannelInfo.ChannelList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006546 pReq->ChannelInfo.ChannelList = NULL;
6547 }
6548 pReq->ChannelInfo.numOfChannels = 0;
6549 if(pReq->pIEField)
6550 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306551 vos_mem_free(pReq->pIEField);
Jeff Johnson295189b2012-06-20 16:38:30 -07006552 pReq->pIEField = NULL;
6553 }
6554 pReq->uIEFieldLen = 0;
6555 if(pReq->SSIDs.SSIDList)
6556 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306557 vos_mem_free(pReq->SSIDs.SSIDList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006558 pReq->SSIDs.SSIDList = NULL;
6559 }
6560 pReq->SSIDs.numOfSSIDs = 0;
6561
Kiet Lam64c1b492013-07-12 13:56:44 +05306562 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07006563}
6564
6565
6566void csrScanCallCallback(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
6567{
6568 if(pCommand->u.scanCmd.callback)
6569 {
Ratheesh S Pece1f832015-07-25 15:50:25 +05306570 if (pCommand->u.scanCmd.abortScanIndication){
6571 smsLog( pMac, LOG1, FL("scanDone due to abort"));
6572 scanStatus = eCSR_SCAN_ABORT;
6573 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006574// sme_ReleaseGlobalLock( &pMac->sme );
6575 pCommand->u.scanCmd.callback(pMac, pCommand->u.scanCmd.pContext, pCommand->u.scanCmd.scanID, scanStatus);
6576// sme_AcquireGlobalLock( &pMac->sme );
6577 } else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006578 smsLog( pMac, LOG2, "%s:%d - Callback NULL!!!", __func__, __LINE__);
Jeff Johnson295189b2012-06-20 16:38:30 -07006579 }
6580}
6581
6582
6583void csrScanStopTimers(tpAniSirGlobal pMac)
6584{
Jeff Johnson295189b2012-06-20 16:38:30 -07006585 csrScanStopIdleScanTimer(pMac);
6586 csrScanStopGetResultTimer(pMac);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006587 if(0 != pMac->scan.scanResultCfgAgingTime )
6588 {
6589 csrScanStopResultCfgAgingTimer(pMac);
6590 }
6591
Jeff Johnson295189b2012-06-20 16:38:30 -07006592}
6593
6594
6595eHalStatus csrScanStartGetResultTimer(tpAniSirGlobal pMac)
6596{
6597 eHalStatus status;
6598
6599 if(pMac->scan.fScanEnable)
6600 {
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306601 status = vos_timer_start(&pMac->scan.hTimerGetResult, CSR_SCAN_GET_RESULT_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006602 }
6603 else
6604 {
6605 status = eHAL_STATUS_FAILURE;
6606 }
6607
6608 return (status);
6609}
6610
6611
6612eHalStatus csrScanStopGetResultTimer(tpAniSirGlobal pMac)
6613{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306614 return (vos_timer_stop(&pMac->scan.hTimerGetResult));
Jeff Johnson295189b2012-06-20 16:38:30 -07006615}
6616
6617
6618void csrScanGetResultTimerHandler(void *pv)
6619{
6620 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6621
6622 csrScanRequestResult(pMac);
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306623
6624 vos_timer_start(&pMac->scan.hTimerGetResult, CSR_SCAN_GET_RESULT_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006625}
6626
6627#ifdef WLAN_AP_STA_CONCURRENCY
6628static void csrStaApConcTimerHandler(void *pv)
6629{
6630 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6631 tListElem *pEntry;
6632 tSmeCmd *pScanCmd;
6633
6634 csrLLLock(&pMac->scan.scanCmdPendingList);
6635
6636 if ( NULL != ( pEntry = csrLLPeekHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) ) )
6637 {
6638 tCsrScanRequest scanReq;
6639 tSmeCmd *pSendScanCmd = NULL;
6640 tANI_U8 numChn = 0;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006641 tANI_U8 nNumChanCombinedConc = 0;
Vinay Malekal05fdc812012-12-17 13:04:30 -08006642 tANI_U8 i, j;
Jeff Johnson295189b2012-06-20 16:38:30 -07006643 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
6644 tANI_U8 channelToScan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
6645 eHalStatus status;
6646
Jeff Johnson295189b2012-06-20 16:38:30 -07006647 pScanCmd = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
6648 numChn = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08006649
6650 /* if any session is connected and the number of channels to scan is
6651 * greater than 1 then split the scan into multiple scan operations
6652 * on each individual channel else continue to perform scan on all
6653 * specified channels */
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08006654
6655 /* split scan if number of channels to scan is greater than 1 and
6656 * any one of the following:
6657 * - STA session is connected and the scan is not a P2P search
6658 * - any P2P session is connected
Srikant Kuppa866893f2012-12-27 17:28:14 -08006659 * Do not split scans if no concurrent infra connections are
6660 * active and if the scan is a BG scan triggered by LFR (OR)
6661 * any scan if LFR is in the middle of a BG scan. Splitting
6662 * the scan is delaying the time it takes for LFR to find
6663 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08006664 */
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006665
6666 if((csrIsStaSessionConnected(pMac) &&
6667 !csrIsP2pSessionConnected(pMac)))
6668 {
6669 nNumChanCombinedConc = pMac->roam.configParam.nNumStaChanCombinedConc;
6670 }
6671 else if(csrIsP2pSessionConnected(pMac))
6672 {
6673 nNumChanCombinedConc = pMac->roam.configParam.nNumP2PChanCombinedConc;
6674 }
6675
6676 if ( (numChn > nNumChanCombinedConc) &&
Srikant Kuppa866893f2012-12-27 17:28:14 -08006677 ((csrIsStaSessionConnected(pMac) &&
6678#ifdef FEATURE_WLAN_LFR
6679 (csrIsConcurrentInfraConnected(pMac) ||
6680 ((pScanCmd->u.scanCmd.reason != eCsrScanBgScan) &&
6681 (pMac->roam.neighborRoamInfo.neighborRoamState !=
6682 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
6683#endif
6684 (pScanCmd->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08006685 (csrIsP2pSessionConnected(pMac))))
Jeff Johnson295189b2012-06-20 16:38:30 -07006686 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306687 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006688
6689 pSendScanCmd = csrGetCommandBuffer(pMac); //optimize this to use 2 command buffer only
6690 if (!pSendScanCmd)
6691 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006692 smsLog( pMac, LOGE, FL(" Failed to get Queue command buffer") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006693 csrLLUnlock(&pMac->scan.scanCmdPendingList);
6694 return;
6695 }
6696 pSendScanCmd->command = pScanCmd->command;
6697 pSendScanCmd->sessionId = pScanCmd->sessionId;
6698 pSendScanCmd->u.scanCmd.callback = NULL;
6699 pSendScanCmd->u.scanCmd.pContext = pScanCmd->u.scanCmd.pContext;
6700 pSendScanCmd->u.scanCmd.reason = pScanCmd->u.scanCmd.reason;
6701 pSendScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
6702
Madan Mohan Koyyalamudiaf2a8b92012-10-09 14:58:07 -07006703 /* First copy all the parameters to local variable of scan request */
6704 csrScanCopyRequest(pMac, &scanReq, &pScanCmd->u.scanCmd.u.scanRequest);
6705
6706 /* Now modify the elements of local var scan request required to be modified for split scan */
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08006707 if(scanReq.ChannelInfo.ChannelList != NULL)
6708 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306709 vos_mem_free(scanReq.ChannelInfo.ChannelList);
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08006710 scanReq.ChannelInfo.ChannelList = NULL;
6711 }
6712
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006713 pChnInfo->numOfChannels = nNumChanCombinedConc;
Kiet Lam64c1b492013-07-12 13:56:44 +05306714 vos_mem_copy(&channelToScan[0],
6715 &pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[0],
6716 pChnInfo->numOfChannels * sizeof(tANI_U8));//just send one channel
Jeff Johnson295189b2012-06-20 16:38:30 -07006717 pChnInfo->ChannelList = &channelToScan[0];
6718
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006719 for (i = 0, j = nNumChanCombinedConc; i < (numChn-nNumChanCombinedConc); i++, j++)
Jeff Johnson295189b2012-06-20 16:38:30 -07006720 {
6721 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] =
Vinay Malekal05fdc812012-12-17 13:04:30 -08006722 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[j]; //Move all the channels one step
Jeff Johnson295189b2012-06-20 16:38:30 -07006723 }
6724
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006725 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = numChn - nNumChanCombinedConc; //reduce outstanding # of channels to be scanned
Jeff Johnson295189b2012-06-20 16:38:30 -07006726
6727 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
c_hpothudbefd3e2014-04-28 15:59:47 +05306728
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -07006729 //Use concurrency values for min/maxChnTime.
6730 //We know csrIsAnySessionConnected(pMac) returns TRUE here
6731 csrSetDefaultScanTiming(pMac, scanReq.scanType, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07006732
6733 status = csrScanCopyRequest(pMac, &pSendScanCmd->u.scanCmd.u.scanRequest, &scanReq);
6734 if(!HAL_STATUS_SUCCESS(status))
6735 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006736 smsLog( pMac, LOGE, FL(" Failed to get copy csrScanRequest = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006737 csrLLUnlock(&pMac->scan.scanCmdPendingList);
6738 return;
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08006739 }
6740 /* Clean the local scan variable */
6741 scanReq.ChannelInfo.ChannelList = NULL;
6742 scanReq.ChannelInfo.numOfChannels = 0;
6743 csrScanFreeRequest(pMac, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07006744 }
6745 else
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08006746 {
6747 /* no active connected session present or numChn == 1
6748 * scan all remaining channels */
Jeff Johnson295189b2012-06-20 16:38:30 -07006749 pSendScanCmd = pScanCmd;
6750 //remove this command from pending list
6751 if (csrLLRemoveHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) == NULL)
6752 { //In case between PeekHead and here, the entry got removed by another thread.
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006753 smsLog( pMac, LOGE, FL(" Failed to remove entry from scanCmdPendingList"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006754 }
6755
6756 }
6757 csrQueueSmeCommand(pMac, pSendScanCmd, eANI_BOOLEAN_FALSE);
6758
6759 }
6760
Jeff Johnson295189b2012-06-20 16:38:30 -07006761 csrLLUnlock(&pMac->scan.scanCmdPendingList);
6762
6763}
6764#endif
6765
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006766eHalStatus csrScanStartResultCfgAgingTimer(tpAniSirGlobal pMac)
6767{
6768 eHalStatus status = eHAL_STATUS_FAILURE;
6769
6770 if(pMac->scan.fScanEnable)
6771 {
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306772 status = vos_timer_start(&pMac->scan.hTimerResultCfgAging, CSR_SCAN_RESULT_CFG_AGING_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006773 }
6774 return (status);
6775}
Jeff Johnson295189b2012-06-20 16:38:30 -07006776
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006777eHalStatus csrScanStopResultCfgAgingTimer(tpAniSirGlobal pMac)
6778{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306779 return (vos_timer_stop(&pMac->scan.hTimerResultCfgAging));
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006780}
Jeff Johnson295189b2012-06-20 16:38:30 -07006781
6782//This function returns the maximum time a BSS is allowed in the scan result.
6783//The time varies base on connection and power saving factors.
6784//Not connected, No PS
6785//Not connected, with PS
6786//Connected w/o traffic, No PS
6787//Connected w/o traffic, with PS
6788//Connected w/ traffic, no PS -- Not supported
6789//Connected w/ traffic, with PS -- Not supported
6790//the return unit is in seconds.
6791tANI_U32 csrScanGetAgeOutTime(tpAniSirGlobal pMac)
6792{
6793 tANI_U32 nRet;
6794
6795 if(pMac->scan.nAgingCountDown)
6796 {
6797 //Calculate what should be the timeout value for this
6798 nRet = pMac->scan.nLastAgeTimeOut * pMac->scan.nAgingCountDown;
6799 pMac->scan.nAgingCountDown--;
6800 }
6801 else
6802 {
6803 if( csrIsAllSessionDisconnected( pMac ) )
6804 {
6805 if(pmcIsPowerSaveEnabled(pMac, ePMC_IDLE_MODE_POWER_SAVE))
6806 {
6807 nRet = pMac->roam.configParam.scanAgeTimeNCPS;
6808 }
6809 else
6810 {
6811 nRet = pMac->roam.configParam.scanAgeTimeNCNPS;
6812 }
6813 }
6814 else
6815 {
6816 if(pmcIsPowerSaveEnabled(pMac, ePMC_BEACON_MODE_POWER_SAVE))
6817 {
6818 nRet = pMac->roam.configParam.scanAgeTimeCPS;
6819 }
6820 else
6821 {
6822 nRet = pMac->roam.configParam.scanAgeTimeCNPS;
6823 }
6824 }
6825 //If state-change causing aging time out change, we want to delay it somewhat to avoid
6826 //unnecessary removal of BSS. This is mostly due to transition from connect to disconnect.
6827 if(pMac->scan.nLastAgeTimeOut > nRet)
6828 {
6829 if(nRet)
6830 {
6831 pMac->scan.nAgingCountDown = (pMac->scan.nLastAgeTimeOut / nRet);
6832 }
6833 pMac->scan.nLastAgeTimeOut = nRet;
6834 nRet *= pMac->scan.nAgingCountDown;
6835 }
6836 else
6837 {
6838 pMac->scan.nLastAgeTimeOut = nRet;
6839 }
6840 }
6841
6842 return (nRet);
6843}
6844
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006845static void csrScanResultCfgAgingTimerHandler(void *pv)
6846{
6847 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6848 tListElem *pEntry, *tmpEntry;
6849 tCsrScanResult *pResult;
6850 tANI_TIMESTAMP ageOutTime = pMac->scan.scanResultCfgAgingTime * PAL_TICKS_PER_SECOND;
6851 tANI_TIMESTAMP curTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
6852
6853 csrLLLock(&pMac->scan.scanResultList);
6854 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
6855 while( pEntry )
6856 {
6857 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
6858 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
6859 if((curTime - pResult->Result.BssDescriptor.nReceivedTime) > ageOutTime)
6860 {
6861 smsLog(pMac, LOGW, " age out due to time out");
6862 csrScanAgeOutBss(pMac, pResult);
6863 }
6864 pEntry = tmpEntry;
6865 }
6866 csrLLUnlock(&pMac->scan.scanResultList);
Sushant Kaushik6274de62015-05-01 16:31:23 +05306867 if (pEntry)
6868 vos_timer_start(&pMac->scan.hTimerResultCfgAging, CSR_SCAN_RESULT_CFG_AGING_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006869}
Jeff Johnson295189b2012-06-20 16:38:30 -07006870
6871eHalStatus csrScanStartIdleScanTimer(tpAniSirGlobal pMac, tANI_U32 interval)
6872{
6873 eHalStatus status;
6874
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006875 smsLog(pMac, LOG1, " csrScanStartIdleScanTimer");
Jeff Johnson295189b2012-06-20 16:38:30 -07006876 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) && interval)
6877 {
6878 pMac->scan.nIdleScanTimeGap += interval;
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306879 vos_timer_stop(&pMac->scan.hTimerIdleScan);
6880 status = vos_timer_start(&pMac->scan.hTimerIdleScan, interval/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006881 if( !HAL_STATUS_SUCCESS(status) )
6882 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006883 smsLog(pMac, LOGE, " Fail to start Idle scan timer. status = %d interval = %d", status, interval);
Jeff Johnson295189b2012-06-20 16:38:30 -07006884 //This should not happen but set the flag to restart when ready
6885 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6886 }
6887 }
6888 else
6889 {
6890 if( pMac->scan.fScanEnable && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) )
6891 {
6892 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6893 }
6894 status = eHAL_STATUS_FAILURE;
6895 }
6896
6897 return (status);
6898}
6899
6900
6901eHalStatus csrScanStopIdleScanTimer(tpAniSirGlobal pMac)
6902{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306903 return (vos_timer_stop(&pMac->scan.hTimerIdleScan));
Jeff Johnson295189b2012-06-20 16:38:30 -07006904}
6905
6906
6907//Stop CSR from asking for IMPS, This function doesn't disable IMPS from CSR
6908void csrScanSuspendIMPS( tpAniSirGlobal pMac )
6909{
6910 csrScanCancelIdleScan(pMac);
6911}
6912
6913
6914//Start CSR from asking for IMPS. This function doesn't trigger CSR to request entering IMPS
6915//because IMPS maybe disabled.
6916void csrScanResumeIMPS( tpAniSirGlobal pMac )
6917{
6918 csrScanStartIdleScan( pMac );
6919}
6920
6921
6922void csrScanIMPSCallback(void *callbackContext, eHalStatus status)
6923{
6924 tpAniSirGlobal pMac = PMAC_STRUCT( callbackContext );
6925
6926 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6927 {
6928 if(pMac->roam.configParam.IsIdleScanEnabled)
6929 {
6930 if(HAL_STATUS_SUCCESS(status))
6931 {
6932 if(csrIsAllSessionDisconnected(pMac) && !csrIsRoamCommandWaiting(pMac))
6933 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006934 smsLog(pMac, LOGW, FL("starts idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006935 csrScanAllChannels(pMac, eCSR_SCAN_IDLE_MODE_SCAN);
6936 }
6937 else
6938 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006939 smsLog(pMac, LOGW, FL("cannot start idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006940 //even though we are in timer handle, calling stop timer will make sure the timer
6941 //doesn't get to restart.
6942 csrScanStopIdleScanTimer(pMac);
6943 }
6944 }
6945 else
6946 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006947 smsLog(pMac, LOGE, FL("sees not success status (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07006948 }
6949 }
6950 else
6951 {//we might need another flag to check if CSR needs to request imps at all
6952
6953 tANI_U32 nTime = 0;
6954
6955 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_FALSE;
6956 if(!HAL_STATUS_SUCCESS(csrScanTriggerIdleScan(pMac, &nTime)))
6957 {
6958 csrScanStartIdleScanTimer(pMac, nTime);
6959 }
6960 }
6961 }
6962}
6963
6964
Rashmi Ramanna68b309c2014-05-20 11:52:22 +05306965//Param: pTimeInterval -- Caller allocated memory in return, if failed, to specify the nxt time interval for
Jeff Johnson295189b2012-06-20 16:38:30 -07006966//idle scan timer interval
6967//Return: Not success -- meaning it cannot start IMPS, caller needs to start a timer for idle scan
6968eHalStatus csrScanTriggerIdleScan(tpAniSirGlobal pMac, tANI_U32 *pTimeInterval)
6969{
6970 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
6971
6972 //Do not trigger IMPS in case of concurrency
Agarwal Ashish5974ed32014-06-16 16:59:54 +05306973 if (vos_concurrent_open_sessions_running() &&
6974 csrIsAnySessionInConnectState(pMac))
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006975 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006976 smsLog( pMac, LOG1, FL("Cannot request IMPS because Concurrent Sessions Running") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006977 return (status);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006978 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006979
6980 if(pTimeInterval)
6981 {
6982 *pTimeInterval = 0;
6983 }
6984
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006985 smsLog(pMac, LOG3, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006986 if( smeCommandPending( pMac ) )
6987 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006988 smsLog( pMac, LOG1, FL(" Cannot request IMPS because command pending") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006989 //Not to enter IMPS because more work to do
6990 if(pTimeInterval)
6991 {
6992 *pTimeInterval = 0;
6993 }
6994 //restart when ready
6995 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6996
6997 return (status);
6998 }
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07006999 if (IsPmcImpsReqFailed (pMac))
7000 {
7001 if(pTimeInterval)
7002 {
7003 *pTimeInterval = 1000000; //usec
7004 }
7005 //restart when ready
7006 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07007007
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07007008 return status;
7009 }
Rashmi Ramanna68b309c2014-05-20 11:52:22 +05307010
7011 if ( !pMac->deferImps && pMac->fDeferIMPSTime )
7012 {
7013 smsLog( pMac, LOG1, FL("Defer IMPS for %dms as command processed"),
7014 pMac->fDeferIMPSTime);
Girish Gowli4f3775a2014-05-30 17:17:08 +05307015 if(pTimeInterval)
7016 {
7017 *pTimeInterval = pMac->fDeferIMPSTime * 1000; //usec
7018 }
Rashmi Ramanna68b309c2014-05-20 11:52:22 +05307019 pMac->deferImps = eANI_BOOLEAN_TRUE;
7020 return status;
7021 }
7022
Jeff Johnson295189b2012-06-20 16:38:30 -07007023 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
7024 /*&& pMac->roam.configParam.impsSleepTime*/)
7025 {
7026 //Stop get result timer because idle scan gets scan result out of PE
7027 csrScanStopGetResultTimer(pMac);
7028 if(pTimeInterval)
7029 {
7030 *pTimeInterval = pMac->roam.configParam.impsSleepTime;
7031 }
7032 //pmcRequestImps take a period in millisecond unit.
7033 status = pmcRequestImps(pMac, pMac->roam.configParam.impsSleepTime / PAL_TIMER_TO_MS_UNIT, csrScanIMPSCallback, pMac);
7034 if(!HAL_STATUS_SUCCESS(status))
7035 {
7036 if(eHAL_STATUS_PMC_ALREADY_IN_IMPS != status)
7037 {
7038 //Do restart the timer if CSR thinks it cannot do IMPS
7039 if( !csrCheckPSReady( pMac ) )
7040 {
7041 if(pTimeInterval)
7042 {
7043 *pTimeInterval = 0;
7044 }
7045 //Set the restart flag to true because that idle scan
7046 //can be restarted even though the timer will not be running
7047 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7048 }
7049 else
7050 {
7051 //For not now, we do a quicker retry
7052 if(pTimeInterval)
7053 {
7054 *pTimeInterval = CSR_IDLE_SCAN_WAIT_TIME;
7055 }
7056 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007057 smsLog(pMac, LOGW, FL("call pmcRequestImps and it returns status code (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07007058 }
7059 else
7060 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007061 smsLog(pMac, LOGW, FL("already in IMPS"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007062 //Since CSR is the only module to request for IMPS. If it is already in IMPS, CSR assumes
7063 //the callback will be called in the future. Should not happen though.
7064 status = eHAL_STATUS_SUCCESS;
7065 pMac->scan.nIdleScanTimeGap = 0;
7066 }
7067 }
7068 else
7069 {
7070 //requested so let's reset the value
7071 pMac->scan.nIdleScanTimeGap = 0;
7072 }
7073 }
7074
7075 return (status);
7076}
7077
7078
7079eHalStatus csrScanStartIdleScan(tpAniSirGlobal pMac)
7080{
7081 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
7082 tANI_U32 nTime = 0;
7083
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007084 smsLog(pMac, LOGW, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007085 if(pMac->roam.configParam.IsIdleScanEnabled)
7086 {
7087 //stop bg scan first
7088 csrScanBGScanAbort(pMac);
7089 //Stop get result timer because idle scan gets scan result out of PE
7090 csrScanStopGetResultTimer(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07007091 }
7092 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_FALSE;
7093 status = csrScanTriggerIdleScan(pMac, &nTime);
7094 if(!HAL_STATUS_SUCCESS(status))
7095 {
7096 csrScanStartIdleScanTimer(pMac, nTime);
7097 }
7098
7099 return (status);
7100}
7101
7102
7103void csrScanCancelIdleScan(tpAniSirGlobal pMac)
7104{
7105 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
7106 {
Agarwal Ashish5974ed32014-06-16 16:59:54 +05307107 if (vos_concurrent_open_sessions_running()) {
Jeff Johnson295189b2012-06-20 16:38:30 -07007108 return;
7109 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007110 smsLog(pMac, LOG1, " csrScanCancelIdleScan");
Jeff Johnson295189b2012-06-20 16:38:30 -07007111 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_TRUE;
7112 //Set the restart flag in case later on it is uncancelled
7113 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7114 csrScanStopIdleScanTimer(pMac);
7115 csrScanRemoveNotRoamingScanCommand(pMac);
7116 }
7117}
7118
7119
7120void csrScanIdleScanTimerHandler(void *pv)
7121{
7122 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
7123 eHalStatus status;
7124 tANI_U32 nTime = 0;
7125
7126 smsLog(pMac, LOGW, " csrScanIdleScanTimerHandler called ");
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07007127 pmcResetImpsFailStatus (pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07007128 status = csrScanTriggerIdleScan(pMac, &nTime);
7129 if(!HAL_STATUS_SUCCESS(status) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan))
7130 {
7131 //Check whether it is time to actually do an idle scan
7132 if(pMac->scan.nIdleScanTimeGap >= pMac->roam.configParam.impsSleepTime)
7133 {
7134 pMac->scan.nIdleScanTimeGap = 0;
7135 csrScanIMPSCallback(pMac, eHAL_STATUS_SUCCESS);
7136 }
7137 else
7138 {
7139 csrScanStartIdleScanTimer(pMac, nTime);
7140 }
7141 }
Rashmi Ramanna68b309c2014-05-20 11:52:22 +05307142 if(pMac->deferImps)
7143 {
7144 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7145 pMac->deferImps = eANI_BOOLEAN_FALSE;
7146 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007147}
7148
7149
7150
7151
7152tANI_BOOLEAN csrScanRemoveNotRoamingScanCommand(tpAniSirGlobal pMac)
7153{
7154 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
7155 tListElem *pEntry, *pEntryTmp;
7156 tSmeCmd *pCommand;
7157 tDblLinkList localList;
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307158 tDblLinkList *pCmdList;
Jeff Johnson295189b2012-06-20 16:38:30 -07007159
7160 vos_mem_zero(&localList, sizeof(tDblLinkList));
7161 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
7162 {
7163 smsLog(pMac, LOGE, FL(" failed to open list"));
7164 return fRet;
7165 }
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307166 if (!pMac->fScanOffload)
7167 pCmdList = &pMac->sme.smeCmdPendingList;
7168 else
7169 pCmdList = &pMac->sme.smeScanCmdPendingList;
Jeff Johnson295189b2012-06-20 16:38:30 -07007170
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307171 csrLLLock(pCmdList);
7172 pEntry = csrLLPeekHead(pCmdList, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007173 while(pEntry)
7174 {
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307175 pEntryTmp = csrLLNext(pCmdList, pEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007176 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7177 if( eSmeCommandScan == pCommand->command )
7178 {
7179 switch( pCommand->u.scanCmd.reason )
7180 {
7181 case eCsrScanIdleScan:
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307182 if( csrLLRemoveEntry(pCmdList, pEntry, LL_ACCESS_NOLOCK) )
Jeff Johnson295189b2012-06-20 16:38:30 -07007183 {
7184 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
7185 }
7186 fRet = eANI_BOOLEAN_TRUE;
7187 break;
7188
7189 default:
7190 break;
7191 } //switch
7192 }
7193 pEntry = pEntryTmp;
7194 }
7195
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307196 csrLLUnlock(pCmdList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007197
7198 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
7199 {
7200 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7201 csrReleaseCommandScan( pMac, pCommand );
7202 }
7203
7204 csrLLClose(&localList);
7205
7206 return (fRet);
7207}
7208
7209
7210tANI_BOOLEAN csrScanRemoveFreshScanCommand(tpAniSirGlobal pMac, tANI_U8 sessionId)
7211{
7212 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
7213 tListElem *pEntry, *pEntryTmp;
7214 tSmeCmd *pCommand;
7215 tDblLinkList localList;
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307216 tDblLinkList *pCmdList;
Jeff Johnson295189b2012-06-20 16:38:30 -07007217
7218 vos_mem_zero(&localList, sizeof(tDblLinkList));
7219 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
7220 {
7221 smsLog(pMac, LOGE, FL(" failed to open list"));
7222 return fRet;
7223 }
7224
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307225 if (!pMac->fScanOffload)
7226 pCmdList = &pMac->sme.smeCmdPendingList;
7227 else
7228 pCmdList = &pMac->sme.smeScanCmdPendingList;
7229
7230 csrLLLock(pCmdList);
7231 pEntry = csrLLPeekHead(pCmdList, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007232 while(pEntry)
7233 {
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307234 pEntryTmp = csrLLNext(pCmdList, pEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007235 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7236 if( (eSmeCommandScan == pCommand->command) && (sessionId == pCommand->sessionId) )
7237 {
7238 switch(pCommand->u.scanCmd.reason)
7239 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07007240#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
7241 case eCsrScanGetLfrResult:
7242#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07007243 case eCsrScanGetResult:
7244 case eCsrScanSetBGScanParam:
7245 case eCsrScanBGScanAbort:
7246 case eCsrScanBGScanEnable:
7247 case eCsrScanGetScanChnInfo:
7248 break;
7249 default:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007250 smsLog (pMac, LOGW, "%s: -------- abort scan command reason = %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007251 __func__, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07007252 //The rest are fresh scan requests
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307253 if( csrLLRemoveEntry(pCmdList, pEntry, LL_ACCESS_NOLOCK) )
Jeff Johnson295189b2012-06-20 16:38:30 -07007254 {
7255 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
7256 }
7257 fRet = eANI_BOOLEAN_TRUE;
7258 break;
7259 }
7260 }
7261 pEntry = pEntryTmp;
7262 }
7263
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307264 csrLLUnlock(pCmdList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007265
7266 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
7267 {
7268 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7269 if (pCommand->u.scanCmd.callback)
7270 {
7271 /* User scan request is pending,
7272 * send response with status eCSR_SCAN_ABORT*/
7273 pCommand->u.scanCmd.callback(pMac,
7274 pCommand->u.scanCmd.pContext,
7275 pCommand->u.scanCmd.scanID,
7276 eCSR_SCAN_ABORT);
7277 }
7278 csrReleaseCommandScan( pMac, pCommand );
7279 }
7280 csrLLClose(&localList);
7281
7282 return (fRet);
7283}
7284
7285
7286void csrReleaseScanCommand(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
7287{
7288 eCsrScanReason reason = pCommand->u.scanCmd.reason;
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307289 tANI_BOOLEAN status;
7290
7291 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07007292 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307293 tANI_U32 i;
7294 for(i = 0; i < CSR_ROAM_SESSION_MAX; i++)
7295 csrRoamStateChange(pMac, pCommand->u.scanCmd.lastRoamState[i], i);
7296 }
7297 else
7298 {
7299 csrRoamStateChange(pMac,
7300 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId],
7301 pCommand->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07007302 }
7303
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307304 csrScanCallCallback(pMac, pCommand, scanStatus);
Jeff Johnson295189b2012-06-20 16:38:30 -07007305
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007306 smsLog(pMac, LOG3, " Remove Scan command reason = %d", reason);
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307307 if (pMac->fScanOffload)
7308 {
7309 status = csrLLRemoveEntry(&pMac->sme.smeScanCmdActiveList,
7310 &pCommand->Link, LL_ACCESS_LOCK);
7311 }
7312 else
7313 {
7314 status = csrLLRemoveEntry(&pMac->sme.smeCmdActiveList,
7315 &pCommand->Link, LL_ACCESS_LOCK);
7316 }
7317
7318 if(status)
Jeff Johnson295189b2012-06-20 16:38:30 -07007319 {
7320 csrReleaseCommandScan( pMac, pCommand );
7321 }
7322 else
7323 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307324 smsLog(pMac, LOGE,
7325 " ********csrReleaseScanCommand cannot release command reason %d",
7326 pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07007327 }
7328}
7329
7330
7331eHalStatus csrScanGetPMKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
7332 tPmkidCandidateInfo *pPmkidList, tANI_U32 *pNumItems )
7333{
7334 eHalStatus status = eHAL_STATUS_SUCCESS;
7335 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
7336
Jeff Johnson32d95a32012-09-10 13:15:23 -07007337 if(!pSession)
7338 {
7339 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
7340 return eHAL_STATUS_FAILURE;
7341 }
7342
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007343 smsLog(pMac, LOGW, " pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07007344 csrResetPMKIDCandidateList(pMac, sessionId);
7345 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
7346 {
7347 tCsrScanResultFilter *pScanFilter;
7348 tCsrScanResultInfo *pScanResult;
7349 tScanResultHandle hBSSList;
7350 tANI_U32 nItems = *pNumItems;
7351
7352 *pNumItems = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05307353 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
7354 if ( NULL == pScanFilter )
7355 status = eHAL_STATUS_FAILURE;
7356 else
Jeff Johnson295189b2012-06-20 16:38:30 -07007357 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307358 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007359 //Here is the profile we need to connect to
7360 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
7361 if(HAL_STATUS_SUCCESS(status))
7362 {
7363 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
7364 if(HAL_STATUS_SUCCESS(status))
7365 {
7366 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumPmkidCandidate < nItems))
7367 {
7368 //NumPmkidCandidate adds up here
7369 csrProcessBSSDescForPMKIDList(pMac, &pScanResult->BssDescriptor,
7370 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
7371 }
7372 if(pSession->NumPmkidCandidate)
7373 {
7374 *pNumItems = pSession->NumPmkidCandidate;
Kiet Lam64c1b492013-07-12 13:56:44 +05307375 vos_mem_copy(pPmkidList, pSession->PmkidCandidateInfo,
7376 pSession->NumPmkidCandidate * sizeof(tPmkidCandidateInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07007377 }
7378 csrScanResultPurge(pMac, hBSSList);
7379 }//Have scan result
7380 csrFreeScanFilter(pMac, pScanFilter);
7381 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307382 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07007383 }
7384 }
7385
7386 return (status);
7387}
7388
7389
7390
7391#ifdef FEATURE_WLAN_WAPI
7392eHalStatus csrScanGetBKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
7393 tBkidCandidateInfo *pBkidList, tANI_U32 *pNumItems )
7394{
7395 eHalStatus status = eHAL_STATUS_SUCCESS;
7396 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
7397
Jeff Johnson32d95a32012-09-10 13:15:23 -07007398 if(!pSession)
7399 {
7400 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
7401 return eHAL_STATUS_FAILURE;
7402 }
7403
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007404 smsLog(pMac, LOGW, " pMac->scan.NumBkidCandidate = %d", pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07007405 csrResetBKIDCandidateList(pMac, sessionId);
7406 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
7407 {
7408 tCsrScanResultFilter *pScanFilter;
7409 tCsrScanResultInfo *pScanResult;
7410 tScanResultHandle hBSSList;
7411 tANI_U32 nItems = *pNumItems;
7412 *pNumItems = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05307413 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
7414 if ( NULL == pScanFilter )
7415 status = eHAL_STATUS_FAILURE;
7416 else
Jeff Johnson295189b2012-06-20 16:38:30 -07007417 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307418 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007419 //Here is the profile we need to connect to
7420 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
7421 if(HAL_STATUS_SUCCESS(status))
7422 {
7423 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
7424 if(HAL_STATUS_SUCCESS(status))
7425 {
7426 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumBkidCandidate < nItems))
7427 {
7428 //pMac->scan.NumBkidCandidate adds up here
7429 csrProcessBSSDescForBKIDList(pMac, &pScanResult->BssDescriptor,
7430 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
7431
7432 }
7433 if(pSession->NumBkidCandidate)
7434 {
7435 *pNumItems = pSession->NumBkidCandidate;
Kiet Lam64c1b492013-07-12 13:56:44 +05307436 vos_mem_copy(pBkidList, pSession->BkidCandidateInfo, pSession->NumBkidCandidate * sizeof(tBkidCandidateInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07007437 }
7438 csrScanResultPurge(pMac, hBSSList);
7439 }//Have scan result
7440 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307441 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07007442 }
7443 }
7444
7445 return (status);
7446}
7447#endif /* FEATURE_WLAN_WAPI */
7448
7449
7450
7451//This function is usually used for BSSs that suppresses SSID so the profile
7452//shall have one and only one SSID
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007453eHalStatus csrScanForSSID(tpAniSirGlobal pMac, tANI_U32 sessionId, tCsrRoamProfile *pProfile, tANI_U32 roamId, tANI_BOOLEAN notify)
Jeff Johnson295189b2012-06-20 16:38:30 -07007454{
7455 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
7456 tSmeCmd *pScanCmd = NULL;
7457 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
7458 tANI_U8 index = 0;
7459 tANI_U32 numSsid = pProfile->SSIDs.numOfSSIDs;
7460
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007461 smsLog(pMac, LOG2, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007462 //For WDS, we use the index 0. There must be at least one in there
7463 if( CSR_IS_WDS_STA( pProfile ) && numSsid )
7464 {
7465 numSsid = 1;
7466 }
7467 if(pMac->scan.fScanEnable && ( numSsid == 1 ) )
7468 {
7469 do
7470 {
7471 pScanCmd = csrGetCommandBuffer(pMac);
7472 if(!pScanCmd)
7473 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007474 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007475 break;
7476 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307477 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
7478 pScanCmd->u.scanCmd.pToRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
7479 if ( NULL == pScanCmd->u.scanCmd.pToRoamProfile )
krunal soni587bf012014-02-04 12:35:11 -08007480 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307481 status = eHAL_STATUS_FAILURE;
krunal soni587bf012014-02-04 12:35:11 -08007482 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307483 else
krunal soni587bf012014-02-04 12:35:11 -08007484 {
7485 status = csrRoamCopyProfile(pMac, pScanCmd->u.scanCmd.pToRoamProfile, pProfile);
7486 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007487 if(!HAL_STATUS_SUCCESS(status))
7488 break;
7489 pScanCmd->u.scanCmd.roamId = roamId;
7490 pScanCmd->command = eSmeCommandScan;
Jeff Johnsone7245742012-09-05 17:12:55 -07007491 pScanCmd->sessionId = (tANI_U8)sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07007492 pScanCmd->u.scanCmd.callback = NULL;
7493 pScanCmd->u.scanCmd.pContext = NULL;
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007494 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 -07007495 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Kiet Lam64c1b492013-07-12 13:56:44 +05307496 vos_mem_set(&pScanCmd->u.scanCmd.u.scanRequest, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007497 pScanCmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Jeff Johnson295189b2012-06-20 16:38:30 -07007498 pScanCmd->u.scanCmd.u.scanRequest.BSSType = pProfile->BSSType;
Jeff Johnsone7245742012-09-05 17:12:55 -07007499 // To avoid 11b rate in probe request Set p2pSearch flag as 1 for P2P Client Mode
7500 if(VOS_P2P_CLIENT_MODE == pProfile->csrPersona)
7501 {
7502 pScanCmd->u.scanCmd.u.scanRequest.p2pSearch = 1;
7503 }
Agarwal Ashish4f616132013-12-30 23:32:50 +05307504 if(pProfile->nAddIEScanLength)
Jeff Johnsone7245742012-09-05 17:12:55 -07007505 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307506 pScanCmd->u.scanCmd.u.scanRequest.pIEField = vos_mem_malloc(
7507 pProfile->nAddIEScanLength);
7508 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.pIEField )
7509 status = eHAL_STATUS_FAILURE;
7510 else
7511 status = eHAL_STATUS_SUCCESS;
7512 vos_mem_set(pScanCmd->u.scanCmd.u.scanRequest.pIEField,
7513 pProfile->nAddIEScanLength, 0);
7514 if (HAL_STATUS_SUCCESS(status))
Jeff Johnsone7245742012-09-05 17:12:55 -07007515 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307516 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.pIEField,
Agarwal Ashish4f616132013-12-30 23:32:50 +05307517 pProfile->addIEScan, pProfile->nAddIEScanLength);
Jeff Johnsone7245742012-09-05 17:12:55 -07007518 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = pProfile->nAddIEScanLength;
7519 }
7520 else
7521 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007522 smsLog(pMac, LOGE, "No memory for scanning IE fields");
Jeff Johnsone7245742012-09-05 17:12:55 -07007523 }
7524 } //Allocate memory for IE field
7525 else
7526 {
7527 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = 0;
7528 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07007529 /* For one channel be good enpugh time to receive beacon atleast */
7530 if( 1 == pProfile->ChannelInfo.numOfChannels )
7531 {
7532 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime = MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7533 pScanCmd->u.scanCmd.u.scanRequest.minChnTime = MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7534 }
7535 else
7536 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307537 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime =
7538 pMac->roam.configParam.nActiveMaxChnTime;
7539 pScanCmd->u.scanCmd.u.scanRequest.minChnTime =
7540 pMac->roam.configParam.nActiveMinChnTime;
Jeff Johnson32d95a32012-09-10 13:15:23 -07007541 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307542 pScanCmd->u.scanCmd.u.scanRequest.maxChnTimeBtc =
7543 pMac->roam.configParam.nActiveMaxChnTimeBtc;
7544 pScanCmd->u.scanCmd.u.scanRequest.minChnTimeBtc =
7545 pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07007546 if(pProfile->BSSIDs.numOfBSSIDs == 1)
7547 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307548 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.bssid,
7549 pProfile->BSSIDs.bssid, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07007550 }
7551 else
7552 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307553 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.bssid, bAddr, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07007554 }
7555 if(pProfile->ChannelInfo.numOfChannels)
7556 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307557 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(
7558 sizeof(*pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
7559 * pProfile->ChannelInfo.numOfChannels);
7560 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
7561 status = eHAL_STATUS_FAILURE;
7562 else
7563 status = eHAL_STATUS_SUCCESS;
7564 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
7565 if(HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07007566 {
7567 csrRoamIsChannelValid(pMac, pProfile->ChannelInfo.ChannelList[0]);
7568 for(index = 0; index < pProfile->ChannelInfo.numOfChannels; index++)
7569 {
7570 if(csrRoamIsValidChannel(pMac, pProfile->ChannelInfo.ChannelList[index]))
7571 {
7572 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels]
7573 = pProfile->ChannelInfo.ChannelList[index];
7574 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels++;
7575 }
7576 else
7577 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007578 smsLog(pMac, LOGW, FL("process a channel (%d) that is invalid"), pProfile->ChannelInfo.ChannelList[index]);
Jeff Johnson295189b2012-06-20 16:38:30 -07007579 }
7580
7581 }
7582 }
7583 else
7584 {
7585 break;
7586 }
7587
7588 }
7589 else
7590 {
7591 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
7592 }
7593 if(pProfile->SSIDs.numOfSSIDs)
7594 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307595 pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList = vos_mem_malloc(
7596 pProfile->SSIDs.numOfSSIDs * sizeof(tCsrSSIDInfo));
7597 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList )
7598 status = eHAL_STATUS_FAILURE;
7599 else
7600 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07007601 if(!HAL_STATUS_SUCCESS(status))
7602 {
7603 break;
7604 }
7605 pScanCmd->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 1;
Kiet Lam64c1b492013-07-12 13:56:44 +05307606 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList,
7607 pProfile->SSIDs.SSIDList, sizeof(tCsrSSIDInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07007608 }
7609 //Start process the command
7610 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
7611 if( !HAL_STATUS_SUCCESS( status ) )
7612 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007613 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07007614 break;
7615 }
7616 }while(0);
7617 if(!HAL_STATUS_SUCCESS(status))
7618 {
7619 if(pScanCmd)
7620 {
7621 csrReleaseCommandScan(pMac, pScanCmd);
7622 //TODO:free the memory that is allocated in this function
7623 }
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007624 if(notify)
7625 {
Jeff Johnson295189b2012-06-20 16:38:30 -07007626 csrRoamCallCallback(pMac, sessionId, NULL, roamId, eCSR_ROAM_FAILED, eCSR_ROAM_RESULT_FAILURE);
7627 }
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007628 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007629 }//valid
7630 else
7631 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007632 smsLog(pMac, LOGE, FL("cannot scan because scanEnable (%d) or numSSID (%d) is invalid"),
Jeff Johnson295189b2012-06-20 16:38:30 -07007633 pMac->scan.fScanEnable, pProfile->SSIDs.numOfSSIDs);
7634 }
7635
7636 return (status);
7637}
7638
7639
7640//Issue a scan base on the new capability infomation
7641//This should only happen when the associated AP changes its capability.
7642//After this scan is done, CSR reroams base on the new scan results
7643eHalStatus csrScanForCapabilityChange(tpAniSirGlobal pMac, tSirSmeApNewCaps *pNewCaps)
7644{
7645 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
7646 tSmeCmd *pScanCmd = NULL;
7647
7648 if(pNewCaps)
7649 {
7650 do
7651 {
7652 pScanCmd = csrGetCommandBuffer(pMac);
7653 if(!pScanCmd)
7654 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007655 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007656 status = eHAL_STATUS_RESOURCES;
7657 break;
7658 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307659 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007660 status = eHAL_STATUS_SUCCESS;
7661 pScanCmd->u.scanCmd.roamId = 0;
7662 pScanCmd->command = eSmeCommandScan;
7663 pScanCmd->u.scanCmd.callback = NULL;
7664 pScanCmd->u.scanCmd.pContext = NULL;
7665 pScanCmd->u.scanCmd.reason = eCsrScanForCapsChange;
7666 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
7667 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
7668 if( !HAL_STATUS_SUCCESS( status ) )
7669 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007670 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07007671 break;
7672 }
7673 }while(0);
7674 if(!HAL_STATUS_SUCCESS(status))
7675 {
7676 if(pScanCmd)
7677 {
7678 csrReleaseCommandScan(pMac, pScanCmd);
7679 }
7680 }
7681 }
7682
7683 return (status);
7684}
7685
7686
7687
7688void csrInitBGScanChannelList(tpAniSirGlobal pMac)
7689{
7690 tANI_U32 len = CSR_MIN(sizeof(pMac->roam.validChannelList), sizeof(pMac->scan.bgScanChannelList));
7691
Kiet Lam64c1b492013-07-12 13:56:44 +05307692 vos_mem_set(pMac->scan.bgScanChannelList, len, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007693 pMac->scan.numBGScanChannel = 0;
7694
7695 if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
7696 {
7697 pMac->roam.numValidChannels = len;
7698 pMac->scan.numBGScanChannel = (tANI_U8)CSR_MIN(len, WNI_CFG_BG_SCAN_CHANNEL_LIST_LEN);
Kiet Lam64c1b492013-07-12 13:56:44 +05307699 vos_mem_copy(pMac->scan.bgScanChannelList, pMac->roam.validChannelList,
7700 pMac->scan.numBGScanChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07007701 csrSetBGScanChannelList(pMac, pMac->scan.bgScanChannelList, pMac->scan.numBGScanChannel);
7702 }
7703}
7704
7705
7706//This function return TRUE if background scan channel list is adjusted.
7707//this function will only shrink the background scan channel list
7708tANI_BOOLEAN csrAdjustBGScanChannelList(tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels,
7709 tANI_U8 *pAdjustChannels, tANI_U8 *pNumAdjustChannels)
7710{
7711 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
7712 tANI_U8 i, j, count = *pNumAdjustChannels;
7713
7714 i = 0;
7715 while(i < count)
7716 {
7717 for(j = 0; j < NumChannels; j++)
7718 {
7719 if(pChannelList[j] == pAdjustChannels[i])
7720 break;
7721 }
7722 if(j == NumChannels)
7723 {
7724 //This channel is not in the list, remove it
7725 fRet = eANI_BOOLEAN_TRUE;
7726 count--;
7727 if(count - i)
7728 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307729 vos_mem_copy(&pAdjustChannels[i], &pAdjustChannels[i+1], count - i);
Jeff Johnson295189b2012-06-20 16:38:30 -07007730 }
7731 else
7732 {
7733 //already remove the last one. Done.
7734 break;
7735 }
7736 }
7737 else
7738 {
7739 i++;
7740 }
7741 }//while(i<count)
7742 *pNumAdjustChannels = count;
7743
7744 return (fRet);
7745}
7746
7747
7748//Get the list of the base channels to scan for passively 11d info
7749eHalStatus csrScanGetSupportedChannels( tpAniSirGlobal pMac )
7750{
7751 eHalStatus status = eHAL_STATUS_SUCCESS;
7752 int n = WNI_CFG_VALID_CHANNEL_LIST_LEN;
7753
7754 status = vos_nv_getSupportedChannels( pMac->scan.baseChannels.channelList, &n, NULL, NULL );
7755 if( HAL_STATUS_SUCCESS(status) )
7756 {
7757 pMac->scan.baseChannels.numChannels = (tANI_U8)n;
7758 }
7759 else
7760 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007761 smsLog( pMac, LOGE, FL(" failed") );
Jeff Johnson295189b2012-06-20 16:38:30 -07007762 pMac->scan.baseChannels.numChannels = 0;
7763 }
7764
7765 return ( status );
7766}
7767
7768//This function use the input pChannelList to validate the current saved channel list
7769eHalStatus csrSetBGScanChannelList( tpAniSirGlobal pMac, tANI_U8 *pAdjustChannels, tANI_U8 NumAdjustChannels)
7770{
7771 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumAdjustChannels;
7772
7773 return (ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pAdjustChannels, dataLen, NULL, eANI_BOOLEAN_FALSE));
7774}
7775
7776
7777void csrSetCfgValidChannelList( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels )
7778{
7779 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumChannels;
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05307780 eHalStatus status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007781
Mihir Shete31c435d2014-02-12 13:13:34 +05307782 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
7783 "%s: dump valid channel list(NumChannels(%d))",
7784 __func__,NumChannels);
7785 VOS_TRACE_HEX_DUMP(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
7786 pChannelList, NumChannels);
7787
Jeff Johnson295189b2012-06-20 16:38:30 -07007788 ccmCfgSetStr(pMac, WNI_CFG_VALID_CHANNEL_LIST, pChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
Leela Venkata Kiran Kumar Reddy Chiralac6663f72014-02-03 21:04:58 -08007789#ifdef QCA_WIFI_2_0
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05307790 if (pMac->fScanOffload)
7791 {
7792 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
7793 "Scan offload is enabled, update default chan list");
Leela Venkata Kiran Kumar Reddy Chiralac6663f72014-02-03 21:04:58 -08007794 status = csrUpdateChannelList(pMac);
7795 }
7796#else
7797 status = csrUpdateChannelList(pMac);
7798#endif
7799
7800 if (eHAL_STATUS_SUCCESS != status)
7801 {
7802 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR,
7803 "failed to update the supported channel list");
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05307804 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007805 return;
7806}
7807
7808
7809
7810/*
7811 * The Tx power limits are saved in the cfg for future usage.
7812 */
7813void csrSaveTxPowerToCfg( tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 cfgId )
7814{
7815 tListElem *pEntry;
7816 tANI_U32 cbLen = 0, dataLen;
7817 tCsrChannelPowerInfo *pChannelSet;
7818 tANI_U32 idx;
7819 tSirMacChanInfo *pChannelPowerSet;
7820 tANI_U8 *pBuf = NULL;
7821
7822 //allocate maximum space for all channels
7823 dataLen = WNI_CFG_VALID_CHANNEL_LIST_LEN * sizeof(tSirMacChanInfo);
Kiet Lam64c1b492013-07-12 13:56:44 +05307824 if ( (pBuf = vos_mem_malloc(dataLen)) != NULL )
Jeff Johnson295189b2012-06-20 16:38:30 -07007825 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307826 vos_mem_set(pBuf, dataLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007827 pChannelPowerSet = (tSirMacChanInfo *)(pBuf);
7828
7829 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
7830 // write the tuples (startChan, numChan, txPower) for each channel found in the channel power list.
7831 while( pEntry )
7832 {
7833 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
7834 if ( 1 != pChannelSet->interChannelOffset )
7835 {
7836 // we keep the 5G channel sets internally with an interchannel offset of 4. Expand these
7837 // to the right format... (inter channel offset of 1 is the only option for the triplets
7838 // that 11d advertises.
7839 if ((cbLen + (pChannelSet->numChannels * sizeof(tSirMacChanInfo))) >= dataLen)
7840 {
7841 // expanding this entry will overflow our allocation
7842 smsLog(pMac, LOGE,
7843 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007844 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07007845 pChannelSet->firstChannel,
7846 pChannelSet->numChannels,
7847 pChannelSet->interChannelOffset);
7848 break;
7849 }
7850
7851 for( idx = 0; idx < pChannelSet->numChannels; idx++ )
7852 {
7853 pChannelPowerSet->firstChanNum = (tSirMacChanNum)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007854 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07007855 pChannelPowerSet->numChannels = 1;
Jeff Johnson295189b2012-06-20 16:38:30 -07007856 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007857 smsLog(pMac, LOG3, " Setting Max Transmit Power %d", pChannelPowerSet->maxTxPower);
Jeff Johnson295189b2012-06-20 16:38:30 -07007858 cbLen += sizeof( tSirMacChanInfo );
7859 pChannelPowerSet++;
7860 }
7861 }
7862 else
7863 {
7864 if (cbLen >= dataLen)
7865 {
7866 // this entry will overflow our allocation
7867 smsLog(pMac, LOGE,
7868 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007869 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07007870 pChannelSet->firstChannel,
7871 pChannelSet->numChannels,
7872 pChannelSet->interChannelOffset);
7873 break;
7874 }
7875 pChannelPowerSet->firstChanNum = pChannelSet->firstChannel;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007876 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07007877 pChannelPowerSet->numChannels = pChannelSet->numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -07007878 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007879 smsLog(pMac, LOG3, " Setting Max Transmit Power %d, nTxPower %d", pChannelPowerSet->maxTxPower,pMac->roam.configParam.nTxPowerCap );
Jeff Johnson295189b2012-06-20 16:38:30 -07007880
7881
7882 cbLen += sizeof( tSirMacChanInfo );
7883 pChannelPowerSet++;
7884 }
7885
7886 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
7887 }
7888
7889 if(cbLen)
7890 {
7891 ccmCfgSetStr(pMac, cfgId, (tANI_U8 *)pBuf, cbLen, NULL, eANI_BOOLEAN_FALSE);
7892 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307893 vos_mem_free(pBuf);
Jeff Johnson295189b2012-06-20 16:38:30 -07007894 }//Allocate memory
7895}
7896
7897
7898void csrSetCfgCountryCode( tpAniSirGlobal pMac, tANI_U8 *countryCode )
7899{
7900 tANI_U8 cc[WNI_CFG_COUNTRY_CODE_LEN];
7901 ///v_REGDOMAIN_t DomainId;
7902
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007903 smsLog( pMac, LOG3, "Setting Country Code in Cfg from csrSetCfgCountryCode %s",countryCode );
Kiet Lam64c1b492013-07-12 13:56:44 +05307904 vos_mem_copy(cc, countryCode, WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07007905
7906 // don't program the bogus country codes that we created for Korea in the MAC. if we see
7907 // the bogus country codes, program the MAC with the right country code.
7908 if ( ( 'K' == countryCode[ 0 ] && '1' == countryCode[ 1 ] ) ||
7909 ( 'K' == countryCode[ 0 ] && '2' == countryCode[ 1 ] ) ||
7910 ( 'K' == countryCode[ 0 ] && '3' == countryCode[ 1 ] ) ||
7911 ( 'K' == countryCode[ 0 ] && '4' == countryCode[ 1 ] ) )
7912 {
7913 // replace the alternate Korea country codes, 'K1', 'K2', .. with 'KR' for Korea
7914 cc[ 1 ] = 'R';
7915 }
7916 ccmCfgSetStr(pMac, WNI_CFG_COUNTRY_CODE, cc, WNI_CFG_COUNTRY_CODE_LEN, NULL, eANI_BOOLEAN_FALSE);
7917
7918 //Need to let HALPHY know about the current domain so it can apply some
7919 //domain-specific settings (TX filter...)
7920 /*if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(pMac, cc, &DomainId)))
7921 {
7922 halPhySetRegDomain(pMac, DomainId);
7923 }*/
7924}
7925
7926
7927
7928eHalStatus csrGetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pBuf, tANI_U8 *pbLen)
7929{
7930 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
7931 tANI_U32 len;
7932
7933 if(pBuf && pbLen && (*pbLen >= WNI_CFG_COUNTRY_CODE_LEN))
7934 {
7935 len = *pbLen;
7936 status = ccmCfgGetStr(pMac, WNI_CFG_COUNTRY_CODE, pBuf, &len);
7937 if(HAL_STATUS_SUCCESS(status))
7938 {
7939 *pbLen = (tANI_U8)len;
7940 }
7941 }
7942
7943 return (status);
7944}
7945
7946
7947void csrSetCfgScanControlList( tpAniSirGlobal pMac, tANI_U8 *countryCode, tCsrChannel *pChannelList )
7948{
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05307949 tANI_U8 i, j, k;
Jeff Johnson295189b2012-06-20 16:38:30 -07007950 tANI_BOOLEAN found=FALSE;
7951 tANI_U8 *pControlList = NULL;
7952 tANI_U32 len = WNI_CFG_SCAN_CONTROL_LIST_LEN;
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05307953 tANI_U8 cfgActiveDFSChannels = 0;
7954 tANI_U8 *cfgActiveDFSChannelLIst = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07007955
Kiet Lam64c1b492013-07-12 13:56:44 +05307956 if ( (pControlList = vos_mem_malloc(WNI_CFG_SCAN_CONTROL_LIST_LEN)) != NULL )
Jeff Johnson295189b2012-06-20 16:38:30 -07007957 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307958 vos_mem_set((void *)pControlList, WNI_CFG_SCAN_CONTROL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007959 if(HAL_STATUS_SUCCESS(ccmCfgGetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, &len)))
7960 {
7961 for (i = 0; i < pChannelList->numChannels; i++)
7962 {
7963 for (j = 0; j < len; j += 2)
7964 {
7965 if (pControlList[j] == pChannelList->channelList[i])
7966 {
7967 found = TRUE;
7968 break;
7969 }
7970 }
7971
7972 if (found) // insert a pair(channel#, flag)
7973 {
Gopichand Nakkala392cbc12013-05-28 16:15:00 +05307974 pControlList[j+1] = csrGetScanType(pMac, pControlList[j]);
Jeff Johnson295189b2012-06-20 16:38:30 -07007975 found = FALSE; // reset the flag
Jeff Johnson295189b2012-06-20 16:38:30 -07007976
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05307977 // When DFS mode is 2, mark static channels as active
7978 if (pMac->scan.fEnableDFSChnlScan ==
7979 DFS_CHNL_SCAN_ENABLED_ACTIVE)
7980 {
7981 cfgActiveDFSChannels =
7982 pMac->roam.neighborRoamInfo.cfgParams.
7983 channelInfo.numOfChannels;
7984 cfgActiveDFSChannelLIst =
7985 pMac->roam.neighborRoamInfo.cfgParams.
7986 channelInfo.ChannelList;
7987 if (cfgActiveDFSChannelLIst)
7988 {
7989 for (k=0; k < cfgActiveDFSChannels; k++)
7990 {
7991 if(CSR_IS_CHANNEL_DFS(cfgActiveDFSChannelLIst[k])
7992 && (pControlList[j] ==
7993 cfgActiveDFSChannelLIst[k]))
7994 {
7995 pControlList[j+1] = eSIR_ACTIVE_SCAN;
7996 smsLog(pMac, LOG1, FL("Marked DFS ch %d"
7997 " as active"),
7998 cfgActiveDFSChannelLIst[k]);
7999 }
8000 }
8001 }
8002 }
8003 }
8004 }
8005
8006 smsLog(pMac, LOG1, FL("fEnableDFSChnlScan %d"),
8007 pMac->scan.fEnableDFSChnlScan);
Mihir Shete31c435d2014-02-12 13:13:34 +05308008 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
8009 "%s: dump scan control list",__func__);
8010 VOS_TRACE_HEX_DUMP(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
8011 pControlList, len);
8012
Jeff Johnson295189b2012-06-20 16:38:30 -07008013 ccmCfgSetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, len, NULL, eANI_BOOLEAN_FALSE);
8014 }//Successfully getting scan control list
Kiet Lam64c1b492013-07-12 13:56:44 +05308015 vos_mem_free(pControlList);
Jeff Johnson295189b2012-06-20 16:38:30 -07008016 }//AllocateMemory
8017}
8018
Jeff Johnson295189b2012-06-20 16:38:30 -07008019//if bgPeriod is 0, background scan is disabled. It is in millisecond units
8020eHalStatus csrSetCfgBackgroundScanPeriod(tpAniSirGlobal pMac, tANI_U32 bgPeriod)
8021{
8022 return (ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, bgPeriod, (tCcmCfgSetCallback) csrScanCcmCfgSetCallback, eANI_BOOLEAN_FALSE));
8023}
8024
8025
8026void csrScanCcmCfgSetCallback(tHalHandle hHal, tANI_S32 result)
8027{
8028 tListElem *pEntry = NULL;
8029 tSmeCmd *pCommand = NULL;
8030 tpAniSirGlobal pMac = PMAC_STRUCT( hHal );
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05308031 tDblLinkList *pCmdList ;
8032
8033 if (!pMac->fScanOffload)
8034 pCmdList = &pMac->sme.smeCmdActiveList;
8035 else
8036 pCmdList = &pMac->sme.smeScanCmdActiveList;
8037
8038 pEntry = csrLLPeekHead( pCmdList, LL_ACCESS_LOCK );
Jeff Johnson295189b2012-06-20 16:38:30 -07008039 if ( pEntry )
8040 {
8041 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8042 if ( eSmeCommandScan == pCommand->command )
8043 {
8044 eCsrScanStatus scanStatus = (CCM_IS_RESULT_SUCCESS(result)) ? eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
8045 csrReleaseScanCommand(pMac, pCommand, scanStatus);
8046 }
8047 else
8048 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008049 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
Jeff Johnson295189b2012-06-20 16:38:30 -07008050 }
8051 }
8052 smeProcessPendingQueue( pMac );
8053}
8054
8055eHalStatus csrProcessSetBGScanParam(tpAniSirGlobal pMac, tSmeCmd *pCommand)
8056{
8057 eHalStatus status;
8058 tCsrBGScanRequest *pScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
8059 tANI_U32 dataLen = sizeof( tANI_U8 ) * pScanReq->ChannelInfo.numOfChannels;
8060
8061 //***setcfg for background scan channel list
8062 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MINIMUM_CHANNEL_TIME, pScanReq->minChnTime, NULL, eANI_BOOLEAN_FALSE);
8063 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MAXIMUM_CHANNEL_TIME, pScanReq->maxChnTime, NULL, eANI_BOOLEAN_FALSE);
8064 //Not set the background scan interval if not connected because bd scan should not be run if not connected
8065 if(!csrIsAllSessionDisconnected(pMac))
8066 {
Jeff Johnson295189b2012-06-20 16:38:30 -07008067
8068#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
8069 {
8070 vos_log_scan_pkt_type *pScanLog = NULL;
8071
8072 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
8073 if(pScanLog)
8074 {
8075 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
8076 pScanLog->minChnTime = (v_U8_t)pScanReq->minChnTime;
8077 pScanLog->maxChnTime = (v_U8_t)pScanReq->maxChnTime;
8078 pScanLog->timeBetweenBgScan = (v_U8_t)pScanReq->scanInterval;
8079 pScanLog->numChannel = pScanReq->ChannelInfo.numOfChannels;
8080 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
8081 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308082 vos_mem_copy(pScanLog->channels,
8083 pScanReq->ChannelInfo.ChannelList,
8084 pScanLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07008085 }
8086 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
8087 }
8088 }
8089#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
8090
8091 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, pScanReq->scanInterval, NULL, eANI_BOOLEAN_FALSE);
8092 }
8093 else
8094 {
8095 //No need to stop aging because IDLE scan is still running
8096 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, 0, NULL, eANI_BOOLEAN_FALSE);
8097 }
8098
8099 if(pScanReq->SSID.length > WNI_CFG_SSID_LEN)
8100 {
8101 pScanReq->SSID.length = WNI_CFG_SSID_LEN;
8102 }
8103
8104 status = ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pScanReq->ChannelInfo.ChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
8105 status = ccmCfgSetStr(pMac, WNI_CFG_SSID, (tANI_U8 *)pScanReq->SSID.ssId, pScanReq->SSID.length, NULL, eANI_BOOLEAN_FALSE);
8106
8107
8108
8109 return (status);
8110}
8111
8112
c_hpothua3d45d52015-01-05 14:11:17 +05308113tSirAbortScanStatus csrScanAbortMacScan(tpAniSirGlobal pMac,
8114 tANI_U8 sessionId,
8115 eCsrAbortReason reason)
Jeff Johnson295189b2012-06-20 16:38:30 -07008116{
c_hpothua3d45d52015-01-05 14:11:17 +05308117 tSirAbortScanStatus abortScanStatus = eSIR_ABORT_ACTIVE_SCAN_LIST_EMPTY;
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308118 tSirSmeScanAbortReq *pMsg;
Jeff Johnson295189b2012-06-20 16:38:30 -07008119 tANI_U16 msgLen;
8120 tListElem *pEntry;
8121 tSmeCmd *pCommand;
8122
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308123 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07008124 {
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308125#ifdef WLAN_AP_STA_CONCURRENCY
8126 csrLLLock(&pMac->scan.scanCmdPendingList);
8127 while(NULL !=
8128 (pEntry = csrLLRemoveHead(&pMac->scan.scanCmdPendingList,
8129 LL_ACCESS_NOLOCK)))
8130 {
Jeff Johnson295189b2012-06-20 16:38:30 -07008131
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308132 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8133 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
8134 }
8135 csrLLUnlock(&pMac->scan.scanCmdPendingList);
Jeff Johnson295189b2012-06-20 16:38:30 -07008136#endif
8137
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308138 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
8139 csrRemoveCmdFromPendingList( pMac, &pMac->roam.roamCmdPendingList, eSmeCommandScan);
8140 csrRemoveCmdFromPendingList( pMac, &pMac->sme.smeCmdPendingList, eSmeCommandScan);
8141 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
8142
8143 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
8144 }
8145 else
8146 {
8147 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
8148 csrRemoveCmdWithSessionIdFromPendingList(pMac,
8149 sessionId,
8150 &pMac->sme.smeScanCmdPendingList,
8151 eSmeCommandScan);
8152 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
8153
8154 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
8155 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008156
8157 //We need to abort scan only if we are scanning
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308158 if(NULL != pEntry)
Jeff Johnson295189b2012-06-20 16:38:30 -07008159 {
8160 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308161 if(eSmeCommandScan == pCommand->command &&
8162 pCommand->sessionId == sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07008163 {
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308164 msgLen = (tANI_U16)(sizeof(tSirSmeScanAbortReq));
Kiet Lam64c1b492013-07-12 13:56:44 +05308165 pMsg = vos_mem_malloc(msgLen);
8166 if ( NULL == pMsg )
Jeff Johnson295189b2012-06-20 16:38:30 -07008167 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308168 smsLog(pMac, LOGE, FL("Failed to allocate memory for SmeScanAbortReq"));
c_hpothua3d45d52015-01-05 14:11:17 +05308169 abortScanStatus = eSIR_ABORT_SCAN_FAILURE;
Kiet Lam64c1b492013-07-12 13:56:44 +05308170 }
8171 else
8172 {
Ratheesh S Pece1f832015-07-25 15:50:25 +05308173 pCommand->u.scanCmd.abortScanIndication = eCSR_SCAN_ABORT_DEFAULT;
Srinivas, Dasari187ca4e2014-02-07 12:40:09 +05308174 if(reason == eCSR_SCAN_ABORT_DUE_TO_BAND_CHANGE)
8175 {
Ratheesh S Pece1f832015-07-25 15:50:25 +05308176 pCommand->u.scanCmd.abortScanIndication
8177 = eCSR_SCAN_ABORT_DUE_TO_BAND_CHANGE;
Srinivas, Dasari187ca4e2014-02-07 12:40:09 +05308178 }
Kiet Lam64c1b492013-07-12 13:56:44 +05308179 vos_mem_set((void *)pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008180 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_ABORT_IND);
8181 pMsg->msgLen = pal_cpu_to_be16(msgLen);
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308182 pMsg->sessionId = sessionId;
c_hpothua3d45d52015-01-05 14:11:17 +05308183 if (eHAL_STATUS_SUCCESS != palSendMBMessage(pMac->hHdd, pMsg))
8184 {
8185 smsLog(pMac, LOGE,
8186 FL("Failed to post eWNI_SME_SCAN_ABORT_IND"));
8187 abortScanStatus = eSIR_ABORT_SCAN_FAILURE;
Ratheesh S Pece1f832015-07-25 15:50:25 +05308188 pCommand->u.scanCmd.abortScanIndication = 0;
c_hpothua3d45d52015-01-05 14:11:17 +05308189 }
8190 else
8191 {
8192 abortScanStatus = eSIR_ABORT_ACTIVE_SCAN_LIST_NOT_EMPTY;
8193 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008194 }
8195 }
8196 }
8197
c_hpothua3d45d52015-01-05 14:11:17 +05308198 return(abortScanStatus);
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308199}
8200
8201void csrRemoveCmdWithSessionIdFromPendingList(tpAniSirGlobal pMac,
8202 tANI_U8 sessionId,
8203 tDblLinkList *pList,
8204 eSmeCommandType commandType)
8205{
8206 tDblLinkList localList;
8207 tListElem *pEntry;
8208 tSmeCmd *pCommand;
8209 tListElem *pEntryToRemove;
8210
8211 vos_mem_zero(&localList, sizeof(tDblLinkList));
8212 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
8213 {
8214 smsLog(pMac, LOGE, FL(" failed to open list"));
8215 return;
8216 }
8217
8218 csrLLLock(pList);
8219 if ((pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK)))
8220 {
8221
8222 /* Have to make sure we don't loop back to the head of the list,
8223 * which will happen if the entry is NOT on the list */
8224 while (pEntry)
8225 {
8226 pEntryToRemove = pEntry;
8227 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
8228 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
8229 if ((pCommand->command == commandType) &&
8230 (pCommand->sessionId == sessionId))
8231 {
8232 /* Remove that entry only */
8233 if (csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
8234 {
8235 csrLLInsertTail(&localList, pEntryToRemove,
8236 LL_ACCESS_NOLOCK);
8237 }
8238 }
8239 }
8240 }
8241 csrLLUnlock(pList);
8242
8243 while ((pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)))
8244 {
8245 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
8246 csrAbortCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
8247 }
8248
8249 csrLLClose(&localList);
Jeff Johnson295189b2012-06-20 16:38:30 -07008250}
8251
8252void csrRemoveCmdFromPendingList(tpAniSirGlobal pMac, tDblLinkList *pList,
8253 eSmeCommandType commandType )
8254{
8255 tDblLinkList localList;
8256 tListElem *pEntry;
8257 tSmeCmd *pCommand;
8258 tListElem *pEntryToRemove;
8259
8260 vos_mem_zero(&localList, sizeof(tDblLinkList));
8261 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
8262 {
8263 smsLog(pMac, LOGE, FL(" failed to open list"));
8264 return;
8265 }
8266
8267 csrLLLock(pList);
8268 if( !csrLLIsListEmpty( pList, LL_ACCESS_NOLOCK ) )
8269 {
8270 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK);
8271
8272 // Have to make sure we don't loop back to the head of the list, which will
8273 // happen if the entry is NOT on the list...
8274 while( pEntry )
8275 {
8276 pEntryToRemove = pEntry;
8277 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
8278 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
8279 if ( pCommand->command == commandType )
8280 {
8281 // Remove that entry only
8282 if(csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
8283 {
8284 csrLLInsertTail(&localList, pEntryToRemove, LL_ACCESS_NOLOCK);
8285 }
8286 }
8287 }
8288
8289
8290 }
8291 csrLLUnlock(pList);
8292
8293 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
8294 {
8295 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8296 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
8297 }
8298 csrLLClose(&localList);
8299
8300}
8301
Abhishek Singhdc2bfd42014-06-19 17:59:05 +05308302eHalStatus csrScanAbortScanForSSID(tpAniSirGlobal pMac, tANI_U32 sessionId)
8303{
8304 eHalStatus status = eHAL_STATUS_SUCCESS;
8305 tSirSmeScanAbortReq *pMsg;
8306 tANI_U16 msgLen;
8307 tListElem *pEntry;
8308 tSmeCmd *pCommand;
8309
8310 if (!pMac->fScanOffload)
8311 {
8312 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
8313#ifdef WLAN_AP_STA_CONCURRENCY
8314 csrRemoveScanForSSIDFromPendingList( pMac, &pMac->scan.scanCmdPendingList, sessionId);
8315#endif
8316 csrRemoveScanForSSIDFromPendingList( pMac, &pMac->roam.roamCmdPendingList, sessionId);
8317 csrRemoveScanForSSIDFromPendingList( pMac, &pMac->sme.smeCmdPendingList, sessionId);
8318 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
8319 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
8320 }
8321 else
8322 {
8323 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
8324 csrRemoveScanForSSIDFromPendingList( pMac, &pMac->sme.smeScanCmdPendingList, sessionId);
8325 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
8326 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
8327 }
8328
8329 if(NULL != pEntry)
8330 {
8331 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8332
8333 if ( (eSmeCommandScan == pCommand->command ) &&
8334 (sessionId == pCommand->sessionId))
8335 {
8336 if ( eCsrScanForSsid == pCommand->u.scanCmd.reason)
8337 {
8338 msgLen = (tANI_U16)(sizeof( tSirSmeScanAbortReq ));
8339 pMsg = vos_mem_malloc(msgLen);
8340 if ( NULL == pMsg )
8341 {
8342 status = eHAL_STATUS_FAILURE;
8343 smsLog(pMac, LOGE, FL("Failed to allocate memory for SmeScanAbortReq"));
8344 }
8345 else
8346 {
8347 vos_mem_zero((void *)pMsg, msgLen);
8348 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_ABORT_IND);
8349 pMsg->msgLen = pal_cpu_to_be16(msgLen);
8350 pMsg->sessionId = sessionId;
8351 status = palSendMBMessage(pMac->hHdd, pMsg);
8352 }
8353 }
8354 }
8355 }
8356 return( status );
8357}
8358
8359void csrRemoveScanForSSIDFromPendingList(tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 sessionId)
8360{
8361 tDblLinkList localList;
8362 tListElem *pEntry;
8363 tSmeCmd *pCommand;
8364 tListElem *pEntryToRemove;
8365
8366 vos_mem_zero(&localList, sizeof(tDblLinkList));
8367 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
8368 {
8369 smsLog(pMac, LOGE, FL(" failed to open list"));
8370 return;
8371 }
8372
8373 csrLLLock(pList);
8374 if( !csrLLIsListEmpty( pList, LL_ACCESS_NOLOCK ) )
8375 {
8376 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK);
8377
8378 // Have to make sure we don't loop back to the head of the list, which will
8379 // happen if the entry is NOT on the list...
8380 while( pEntry )
8381 {
8382 pEntryToRemove = pEntry;
8383 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
8384 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
8385 if ( (eSmeCommandScan == pCommand->command ) &&
8386 (sessionId == pCommand->sessionId) )
8387 {
8388 if ( eCsrScanForSsid == pCommand->u.scanCmd.reason)
8389 {
8390 // Remove that entry only
8391 if ( csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
8392 {
8393 csrLLInsertTail(&localList, pEntryToRemove, LL_ACCESS_NOLOCK);
8394 }
8395 }
8396 }
8397 }
8398 }
8399 csrLLUnlock(pList);
8400
8401 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
8402 {
8403 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8404 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
8405 }
8406 csrLLClose(&localList);
8407}
Jeff Johnson295189b2012-06-20 16:38:30 -07008408
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308409eHalStatus csrScanAbortMacScanNotForConnect(tpAniSirGlobal pMac,
8410 tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07008411{
8412 eHalStatus status = eHAL_STATUS_SUCCESS;
8413
8414 if( !csrIsScanForRoamCommandActive( pMac ) )
8415 {
8416 //Only abort the scan if it is not used for other roam/connect purpose
c_hpothua3d45d52015-01-05 14:11:17 +05308417 if (eSIR_ABORT_SCAN_FAILURE ==
8418 csrScanAbortMacScan(pMac, sessionId, eCSR_SCAN_ABORT_DEFAULT))
8419 {
8420 smsLog(pMac, LOGE, FL("fail to abort scan"));
8421 status = eHAL_STATUS_FAILURE;
8422 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008423 }
8424
8425 return (status);
8426}
8427
8428
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05308429eHalStatus csrScanGetScanChannelInfo(tpAniSirGlobal pMac, tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07008430{
8431 eHalStatus status = eHAL_STATUS_SUCCESS;
8432 tSirMbMsg *pMsg;
8433 tANI_U16 msgLen;
8434
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05308435 if (pMac->fScanOffload)
8436 msgLen = (tANI_U16)(sizeof(tSirSmeGetScanChanReq));
8437 else
8438 msgLen = (tANI_U16)(sizeof(tSirMbMsg));
8439
Kiet Lam64c1b492013-07-12 13:56:44 +05308440 pMsg = vos_mem_malloc(msgLen);
8441 if ( NULL == pMsg )
8442 status = eHAL_STATUS_FAILURE;
8443 else
Jeff Johnson295189b2012-06-20 16:38:30 -07008444 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308445 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008446 pMsg->type = eWNI_SME_GET_SCANNED_CHANNEL_REQ;
8447 pMsg->msgLen = msgLen;
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05308448 if (pMac->fScanOffload)
8449 ((tSirSmeGetScanChanReq *)pMsg)->sessionId = sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07008450 status = palSendMBMessage(pMac->hHdd, pMsg);
8451 }
8452
8453 return( status );
8454}
8455
8456tANI_BOOLEAN csrRoamIsValidChannel( tpAniSirGlobal pMac, tANI_U8 channel )
8457{
8458 tANI_BOOLEAN fValid = FALSE;
8459 tANI_U32 idxValidChannels;
8460 tANI_U32 len = pMac->roam.numValidChannels;
8461
8462 for ( idxValidChannels = 0; ( idxValidChannels < len ); idxValidChannels++ )
8463 {
8464 if ( channel == pMac->roam.validChannelList[ idxValidChannels ] )
8465 {
8466 fValid = TRUE;
8467 break;
8468 }
8469 }
8470
8471 return fValid;
8472}
8473
Manjunathappa Prakash4f1d5a52013-11-11 16:22:19 -08008474#ifdef FEATURE_WLAN_SCAN_PNO
Srikant Kuppa066904f2013-05-07 13:56:02 -07008475eHalStatus csrScanSavePreferredNetworkFound(tpAniSirGlobal pMac,
8476 tSirPrefNetworkFoundInd *pPrefNetworkFoundInd)
8477{
8478 v_U32_t uLen = 0;
8479 tpSirProbeRespBeacon pParsedFrame;
8480 tCsrScanResult *pScanResult = NULL;
8481 tSirBssDescription *pBssDescr = NULL;
8482 tANI_BOOLEAN fDupBss;
8483 tDot11fBeaconIEs *pIesLocal = NULL;
8484 tAniSSID tmpSsid;
8485 v_TIME_t timer=0;
8486 tpSirMacMgmtHdr macHeader = (tpSirMacMgmtHdr)pPrefNetworkFoundInd->data;
Abhishek Singhd3d4e022014-11-11 13:02:40 +05308487 boolean bFoundonAppliedChannel = FALSE;
8488 v_U32_t indx;
8489 u8 channelsAllowed[WNI_CFG_VALID_CHANNEL_LIST_LEN];
8490 v_U32_t numChannelsAllowed = WNI_CFG_VALID_CHANNEL_LIST_LEN;
Sushant Kaushik6274de62015-05-01 16:31:23 +05308491 tListElem *pEntry;
Abhishek Singhd3d4e022014-11-11 13:02:40 +05308492
Srikant Kuppa066904f2013-05-07 13:56:02 -07008493
8494 pParsedFrame =
Abhishek Singhc75726d2015-04-13 14:44:14 +05308495 (tpSirProbeRespBeacon)vos_mem_vmalloc(sizeof(tSirProbeRespBeacon));
Srikant Kuppa066904f2013-05-07 13:56:02 -07008496
8497 if (NULL == pParsedFrame)
8498 {
8499 smsLog(pMac, LOGE, FL(" fail to allocate memory for frame"));
8500 return eHAL_STATUS_RESOURCES;
8501 }
8502
8503 if ( pPrefNetworkFoundInd->frameLength <= SIR_MAC_HDR_LEN_3A )
8504 {
8505 smsLog(pMac, LOGE,
8506 FL("Not enough bytes in PNO indication probe resp frame! length=%d"),
8507 pPrefNetworkFoundInd->frameLength);
Abhishek Singhc75726d2015-04-13 14:44:14 +05308508 vos_mem_vfree(pParsedFrame);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008509 return eHAL_STATUS_FAILURE;
8510 }
8511
8512 if (sirConvertProbeFrame2Struct(pMac,
8513 &pPrefNetworkFoundInd->data[SIR_MAC_HDR_LEN_3A],
8514 pPrefNetworkFoundInd->frameLength - SIR_MAC_HDR_LEN_3A,
8515 pParsedFrame) != eSIR_SUCCESS ||
8516 !pParsedFrame->ssidPresent)
8517 {
8518 smsLog(pMac, LOGE,
8519 FL("Parse error ProbeResponse, length=%d"),
8520 pPrefNetworkFoundInd->frameLength);
Abhishek Singhc75726d2015-04-13 14:44:14 +05308521 vos_mem_vfree(pParsedFrame);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008522 return eHAL_STATUS_FAILURE;
8523 }
8524 //24 byte MAC header and 12 byte to ssid IE
8525 if (pPrefNetworkFoundInd->frameLength >
8526 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET))
8527 {
8528 uLen = pPrefNetworkFoundInd->frameLength -
8529 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET);
8530 }
8531
Kiet Lam64c1b492013-07-12 13:56:44 +05308532 pScanResult = vos_mem_malloc(sizeof(tCsrScanResult) + uLen);
8533 if ( NULL == pScanResult )
Srikant Kuppa066904f2013-05-07 13:56:02 -07008534 {
8535 smsLog(pMac, LOGE, FL(" fail to allocate memory for frame"));
8536 vos_mem_free(pParsedFrame);
8537 return eHAL_STATUS_RESOURCES;
8538 }
8539
Kiet Lam64c1b492013-07-12 13:56:44 +05308540 vos_mem_set(pScanResult, sizeof(tCsrScanResult) + uLen, 0);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008541 pBssDescr = &pScanResult->Result.BssDescriptor;
8542 /**
8543 * Length of BSS desription is without length of
8544 * length itself and length of pointer
8545 * that holds the next BSS description
8546 */
8547 pBssDescr->length = (tANI_U16)(
8548 sizeof(tSirBssDescription) - sizeof(tANI_U16) -
8549 sizeof(tANI_U32) + uLen);
8550 if (pParsedFrame->dsParamsPresent)
8551 {
8552 pBssDescr->channelId = pParsedFrame->channelNumber;
8553 }
8554 else if (pParsedFrame->HTInfo.present)
8555 {
8556 pBssDescr->channelId = pParsedFrame->HTInfo.primaryChannel;
8557 }
8558 else
8559 {
Mahesh A Saptasagaradd99792014-03-26 16:04:20 +05308560 /**
8561 * If Probe Responce received in PNO indication does not
8562 * contain DSParam IE or HT Info IE then add dummy channel
8563 * to the received BSS info so that Scan result received as
8564 * a part of PNO is updated to the supplicant. Specially
8565 * applicable in case of AP configured in 11A only mode.
8566 */
8567 if ((pMac->roam.configParam.bandCapability == eCSR_BAND_ALL) ||
8568 (pMac->roam.configParam.bandCapability == eCSR_BAND_24))
8569 {
8570 pBssDescr->channelId = 1;
8571 }
8572 else if(pMac->roam.configParam.bandCapability == eCSR_BAND_5G)
8573 {
8574 pBssDescr->channelId = 36;
8575 }
Abhishek Singhd3d4e022014-11-11 13:02:40 +05308576 /* Restrict the logic to ignore the pno indication for invalid channel
8577 * only if valid channel info is present in beacon/probe resp.
8578 * If no channel info is present in beacon/probe resp, always process
8579 * the pno indication.
8580 */
8581 bFoundonAppliedChannel = TRUE;
8582 }
8583
8584 if (0 != sme_GetCfgValidChannels(pMac, channelsAllowed, &numChannelsAllowed))
8585 {
8586 smsLog(pMac, LOGE, FL(" sme_GetCfgValidChannels failed "));
8587 csrFreeScanResultEntry(pMac, pScanResult);
Abhishek Singhc75726d2015-04-13 14:44:14 +05308588 vos_mem_vfree(pParsedFrame);
Abhishek Singhd3d4e022014-11-11 13:02:40 +05308589 return eHAL_STATUS_FAILURE;
8590 }
8591 /* Checking chhanelId with allowed channel list */
8592 for (indx = 0; indx < numChannelsAllowed; indx++)
8593 {
8594 if (pBssDescr->channelId == channelsAllowed[indx])
8595 {
8596 bFoundonAppliedChannel = TRUE;
8597 smsLog(pMac, LOG1, FL(" pno ind found on applied channel =%d\n "),
8598 pBssDescr->channelId);
8599 break;
8600 }
8601 }
8602 /* Ignore PNO indication if AP is on Invalid channel.
8603 */
8604 if(FALSE == bFoundonAppliedChannel)
8605 {
8606 smsLog(pMac, LOGW, FL(" prefered network found on invalid channel = %d"),
8607 pBssDescr->channelId);
8608 csrFreeScanResultEntry(pMac, pScanResult);
Abhishek Singhc75726d2015-04-13 14:44:14 +05308609 vos_mem_vfree(pParsedFrame);
Abhishek Singhd3d4e022014-11-11 13:02:40 +05308610 return eHAL_STATUS_FAILURE;
Srikant Kuppa066904f2013-05-07 13:56:02 -07008611 }
8612
8613 if ((pBssDescr->channelId > 0) && (pBssDescr->channelId < 15))
8614 {
8615 int i;
8616 // 11b or 11g packet
8617 // 11g iff extended Rate IE is present or
8618 // if there is an A rate in suppRate IE
8619 for (i = 0; i < pParsedFrame->supportedRates.numRates; i++)
8620 {
8621 if (sirIsArate(pParsedFrame->supportedRates.rate[i] & 0x7f))
8622 {
8623 pBssDescr->nwType = eSIR_11G_NW_TYPE;
8624 break;
8625 }
8626 }
8627 if (pParsedFrame->extendedRatesPresent)
8628 {
8629 pBssDescr->nwType = eSIR_11G_NW_TYPE;
8630 }
8631 }
8632 else
8633 {
8634 // 11a packet
8635 pBssDescr->nwType = eSIR_11A_NW_TYPE;
8636 }
8637
8638 pBssDescr->sinr = 0;
8639 pBssDescr->rssi = -1 * pPrefNetworkFoundInd->rssi;
8640 pBssDescr->beaconInterval = pParsedFrame->beaconInterval;
AnjaneeDevi Kapparapu4b043912014-02-18 13:22:35 +05308641 if (!pBssDescr->beaconInterval)
8642 {
8643 smsLog(pMac, LOGW,
8644 FL("Bcn Interval is Zero , default to 100" MAC_ADDRESS_STR),
8645 MAC_ADDR_ARRAY(pBssDescr->bssId) );
8646 pBssDescr->beaconInterval = 100;
8647 }
Srikant Kuppa066904f2013-05-07 13:56:02 -07008648 pBssDescr->timeStamp[0] = pParsedFrame->timeStamp[0];
8649 pBssDescr->timeStamp[1] = pParsedFrame->timeStamp[1];
8650 pBssDescr->capabilityInfo = *((tANI_U16 *)&pParsedFrame->capabilityInfo);
Kiet Lam64c1b492013-07-12 13:56:44 +05308651 vos_mem_copy((tANI_U8 *) &pBssDescr->bssId, (tANI_U8 *) macHeader->bssId, sizeof(tSirMacAddr));
Srikant Kuppa066904f2013-05-07 13:56:02 -07008652 pBssDescr->nReceivedTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
8653
Abhishek Singh195c03e2014-05-14 17:21:30 +05308654 smsLog( pMac, LOG1, FL("Bssid= "MAC_ADDRESS_STR
8655 " chan= %d, rssi = %d "),
Arif Hussain24bafea2013-11-15 15:10:03 -08008656 MAC_ADDR_ARRAY(pBssDescr->bssId),
Srikant Kuppa066904f2013-05-07 13:56:02 -07008657 pBssDescr->channelId,
Abhishek Singh195c03e2014-05-14 17:21:30 +05308658 pBssDescr->rssi);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008659
8660 //IEs
8661 if (uLen)
8662 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308663 vos_mem_copy(&pBssDescr->ieFields,
8664 pPrefNetworkFoundInd->data + (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET),
8665 uLen);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008666 }
8667
8668 pIesLocal = (tDot11fBeaconIEs *)( pScanResult->Result.pvIes );
8669 if ( !pIesLocal &&
8670 (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
8671 &pScanResult->Result.BssDescriptor, &pIesLocal))) )
8672 {
8673 smsLog(pMac, LOGE, FL(" Cannot parse IEs"));
8674 csrFreeScanResultEntry(pMac, pScanResult);
Abhishek Singhc75726d2015-04-13 14:44:14 +05308675 vos_mem_vfree(pParsedFrame);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008676 return eHAL_STATUS_RESOURCES;
8677 }
8678
8679 fDupBss = csrRemoveDupBssDescription( pMac,
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05308680 &pScanResult->Result.BssDescriptor, pIesLocal, &tmpSsid, &timer, FALSE);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008681 //Check whether we have reach out limit
8682 if ( CSR_SCAN_IS_OVER_BSS_LIMIT(pMac) )
8683 {
8684 //Limit reach
8685 smsLog(pMac, LOGE, FL(" BSS limit reached"));
8686 //Free the resources
8687 if( (pScanResult->Result.pvIes == NULL) && pIesLocal )
8688 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308689 vos_mem_free(pIesLocal);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008690 }
8691 csrFreeScanResultEntry(pMac, pScanResult);
8692 vos_mem_free(pParsedFrame);
8693 return eHAL_STATUS_RESOURCES;
8694 }
Nalla Kartheek71946422015-09-15 14:41:22 +05308695
8696 if ((macHeader->fc.type == SIR_MAC_MGMT_FRAME) &&
8697 (macHeader->fc.subType == SIR_MAC_MGMT_PROBE_RSP))
8698 {
8699 pScanResult->Result.BssDescriptor.fProbeRsp = 1;
8700 }
Srikant Kuppa066904f2013-05-07 13:56:02 -07008701 //Add to scan cache
8702 csrScanAddResult(pMac, pScanResult, pIesLocal);
Sushant Kaushik6274de62015-05-01 16:31:23 +05308703 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
8704 if (pEntry && 0 != pMac->scan.scanResultCfgAgingTime)
8705 csrScanStartResultCfgAgingTimer(pMac);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008706
Kiet Lamb537cfb2013-11-07 12:56:49 +05308707 if( (pScanResult->Result.pvIes == NULL) && pIesLocal )
8708 {
8709 vos_mem_free(pIesLocal);
8710 }
8711
Abhishek Singhc75726d2015-04-13 14:44:14 +05308712 vos_mem_vfree(pParsedFrame);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008713
8714 return eHAL_STATUS_SUCCESS;
8715}
Manjunathappa Prakash4f1d5a52013-11-11 16:22:19 -08008716#endif //FEATURE_WLAN_SCAN_PNO
Srikant Kuppa066904f2013-05-07 13:56:02 -07008717
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008718#ifdef FEATURE_WLAN_LFR
8719void csrInitOccupiedChannelsList(tpAniSirGlobal pMac)
8720{
8721 tListElem *pEntry = NULL;
8722 tCsrScanResult *pBssDesc = NULL;
8723 tDot11fBeaconIEs *pIes = NULL;
Srinivas28b5b4e2012-12-12 13:07:53 -08008724 tpCsrNeighborRoamControlInfo pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
8725
8726 if (0 != pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels)
8727 {
8728 smsLog(pMac, LOG1, FL("%s: Ini file contains neighbor scan channel list,"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008729 " hence NO need to build occupied channel list (numChannels = %d)"),
Srinivas28b5b4e2012-12-12 13:07:53 -08008730 __func__, pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels);
8731 return;
8732 }
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008733
8734 if (!csrNeighborRoamIsNewConnectedProfile(pMac))
8735 {
8736 smsLog(pMac, LOG2, FL("%s: donot flush occupied list since current roam profile"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008737 " matches previous (numChannels = %d)"),
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008738 __func__, pMac->scan.occupiedChannels.numChannels);
8739 return;
8740 }
8741
8742 /* Empty occupied channels here */
8743 pMac->scan.occupiedChannels.numChannels = 0;
8744
8745 csrLLLock(&pMac->scan.scanResultList);
8746 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
8747 while( pEntry )
8748 {
8749 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
8750 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
8751
8752 //At this time, pBssDescription->Result.pvIes may be NULL
Srikant Kuppa866893f2012-12-27 17:28:14 -08008753 if( !pIes && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008754 &pBssDesc->Result.BssDescriptor, &pIes))) )
8755 {
8756 continue;
8757 }
8758
8759 csrScanAddToOccupiedChannels(pMac, pBssDesc, &pMac->scan.occupiedChannels, pIes);
8760
8761 /*
8762 * Free the memory allocated for pIes in csrGetParsedBssDescriptionIEs
8763 */
8764 if( (pBssDesc->Result.pvIes == NULL) && pIes )
8765 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308766 vos_mem_free(pIes);
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008767 }
8768
8769 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK );
8770 }//while
8771 csrLLUnlock(&pMac->scan.scanResultList);
Srikant Kuppa866893f2012-12-27 17:28:14 -08008772
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008773}
8774#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07008775
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008776eHalStatus csrScanCreateEntryInScanCache(tpAniSirGlobal pMac, tANI_U32 sessionId,
8777 tCsrBssid bssid, tANI_U8 channel)
8778{
8779 eHalStatus status = eHAL_STATUS_SUCCESS;
8780 tDot11fBeaconIEs *pNewIes = NULL;
8781 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
Praveen Kumar Sirisilla8bdfac42013-10-10 17:20:48 -07008782 tSirBssDescription *pNewBssDescriptor = NULL;
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008783 tANI_U32 size = 0;
8784
8785 if(NULL == pSession)
8786 {
8787 status = eHAL_STATUS_FAILURE;
8788 return status;
8789 }
8790 smsLog(pMac, LOG2, FL("csrScanCreateEntryInScanCache: Current bssid::"
Arif Hussain24bafea2013-11-15 15:10:03 -08008791 MAC_ADDRESS_STR),
8792 MAC_ADDR_ARRAY(pSession->pConnectBssDesc->bssId));
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008793 smsLog(pMac, LOG2, FL("csrScanCreateEntryInScanCache: My bssid::"
Arif Hussain24bafea2013-11-15 15:10:03 -08008794 MAC_ADDRESS_STR" channel %d"),
8795 MAC_ADDR_ARRAY(bssid), channel);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008796
8797 do
8798 {
8799 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
8800 pSession->pConnectBssDesc, &pNewIes)))
8801 {
8802 smsLog(pMac, LOGE, FL("%s: Failed to parse IEs"),
8803 __func__);
8804 status = eHAL_STATUS_FAILURE;
8805 break;
8806 }
8807
8808 size = pSession->pConnectBssDesc->length + sizeof(pSession->pConnectBssDesc->length);
Kiet Lam64c1b492013-07-12 13:56:44 +05308809 if (size)
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008810 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308811 pNewBssDescriptor = vos_mem_malloc(size);
8812 if ( NULL == pNewBssDescriptor )
8813 status = eHAL_STATUS_FAILURE;
8814 else
8815 status = eHAL_STATUS_SUCCESS;
8816 if (HAL_STATUS_SUCCESS(status))
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008817 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308818 vos_mem_copy(pNewBssDescriptor, pSession->pConnectBssDesc, size);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008819 }
8820 else
8821 {
8822 smsLog(pMac, LOGE, FL("%s: memory allocation failed"),
8823 __func__);
8824 status = eHAL_STATUS_FAILURE;
8825 break;
8826 }
8827
8828 //change the BSSID & channel as passed
Kiet Lam64c1b492013-07-12 13:56:44 +05308829 vos_mem_copy(pNewBssDescriptor->bssId, bssid, sizeof(tSirMacAddr));
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008830 pNewBssDescriptor->channelId = channel;
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07008831 if(NULL == csrScanAppendBssDescription( pMac, pNewBssDescriptor, pNewIes, TRUE ))
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008832 {
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07008833 smsLog(pMac, LOGE, FL("%s: csrScanAppendBssDescription failed"),
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008834 __func__);
8835 status = eHAL_STATUS_FAILURE;
8836 break;
8837 }
8838 }
8839 else
8840 {
8841 smsLog(pMac, LOGE, FL("%s: length of bss descriptor is 0"),
8842 __func__);
8843 status = eHAL_STATUS_FAILURE;
8844 break;
8845 }
8846 smsLog(pMac, LOGE, FL("%s: entry successfully added in scan cache"),
8847 __func__);
8848 }while(0);
8849
8850 if(pNewIes)
8851 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308852 vos_mem_free(pNewIes);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008853 }
8854 if(pNewBssDescriptor)
8855 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308856 vos_mem_free(pNewBssDescriptor);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008857 }
8858 return status;
8859}
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07008860
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08008861#ifdef FEATURE_WLAN_ESE
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07008862// Update the TSF with the difference in system time
8863void UpdateCCKMTSF(tANI_U32 *timeStamp0, tANI_U32 *timeStamp1, tANI_U32 *incr)
8864{
8865 tANI_U64 timeStamp64 = ((tANI_U64)*timeStamp1 << 32) | (*timeStamp0);
8866
8867 timeStamp64 = (tANI_U64)(timeStamp64 + (tANI_U64)*incr);
8868 *timeStamp0 = (tANI_U32)(timeStamp64 & 0xffffffff);
8869 *timeStamp1 = (tANI_U32)((timeStamp64 >> 32) & 0xffffffff);
8870}
8871#endif