blob: 9d6dce5456a47d607bea0acee96c1988a0900a6c [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 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700806
Jeff Johnson295189b2012-06-20 16:38:30 -0700807 status = csrScanCopyRequest(pMac, &p11dScanCmd->u.scanCmd.u.scanRequest, &scanReq);
808 //Free the channel list
Kiet Lam64c1b492013-07-12 13:56:44 +0530809 vos_mem_free(pChnInfo->ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -0700810 pChnInfo->ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -0700811
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800812 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700813 {
krunal soni5f112f02013-11-25 15:00:11 -0800814 pMac->scan.scanProfile.numOfChannels =
815 p11dScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -0700816 //Start process the command
817#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +0530818 if (!pMac->fScanOffload)
819 status = csrQueueScanRequest(pMac, p11dScanCmd);
820 else
821 status = csrQueueSmeCommand(pMac, p11dScanCmd,
822 eANI_BOOLEAN_FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -0700823#else
824 status = csrQueueSmeCommand(pMac, p11dScanCmd, eANI_BOOLEAN_FALSE);
825#endif
826 if( !HAL_STATUS_SUCCESS( status ) )
827 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530828 smsLog(pMac, LOGE, FL("Failed to send message"
829 " status = %d"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -0700830 break;
831 }
832 }
833 else
834 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530835 smsLog(pMac, LOGE, FL("csrScanCopyRequest failed"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700836 break;
837 }
838 }
839 else
840 {
841 //error
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530842 smsLog( pMac, LOGE, FL("p11dScanCmd failed") );
Jeff Johnson295189b2012-06-20 16:38:30 -0700843 break;
844 }
845 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700846
847 //Scan only 2G Channels if set in ini file
848 //This is mainly to reduce the First Scan duration
849 //Once we turn on Wifi
850 if(pMac->scan.fFirstScanOnly2GChnl)
851 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800852 smsLog( pMac, LOG1, FL("Scanning only 2G Channels during first scan"));
Jeff Johnsone7245742012-09-05 17:12:55 -0700853 csrScan2GOnyRequest(pMac, pScanCmd, pScanRequest);
854 }
855
c_hpothu059edb02014-03-12 21:44:28 +0530856 if (pMac->roam.configParam.nInitialDwellTime)
857 {
858 pScanRequest->maxChnTime =
859 pMac->roam.configParam.nInitialDwellTime;
860 pMac->roam.configParam.nInitialDwellTime = 0;
861 smsLog(pMac, LOG1,
862 FL("updating dwell time for first scan %u"),
863 pScanRequest->maxChnTime);
864 }
865
Jeff Johnson295189b2012-06-20 16:38:30 -0700866 status = csrScanCopyRequest(pMac, &pScanCmd->u.scanCmd.u.scanRequest, pScanRequest);
867 if(HAL_STATUS_SUCCESS(status))
868 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530869 tCsrScanRequest *pTempScanReq =
870 &pScanCmd->u.scanCmd.u.scanRequest;
krunal soni5f112f02013-11-25 15:00:11 -0800871 pMac->scan.scanProfile.numOfChannels =
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530872 pTempScanReq->ChannelInfo.numOfChannels;
krunal soni5f112f02013-11-25 15:00:11 -0800873
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530874 smsLog( pMac, LOG1, FL(" SId=%d scanId=%d"
875 " Scan reason=%u numSSIDs=%d"
876 " numChan=%d P2P search=%d minCT=%d maxCT=%d"
877 " minCBtc=%d maxCBtx=%d"),
878 sessionId, pScanCmd->u.scanCmd.scanID,
879 pScanCmd->u.scanCmd.reason,
880 pTempScanReq->SSIDs.numOfSSIDs,
881 pTempScanReq->ChannelInfo.numOfChannels,
882 pTempScanReq->p2pSearch,
883 pTempScanReq->minChnTime,
884 pTempScanReq->maxChnTime,
885 pTempScanReq->minChnTimeBtc,
886 pTempScanReq->maxChnTimeBtc );
Jeff Johnson295189b2012-06-20 16:38:30 -0700887 //Start process the command
888#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +0530889 if (!pMac->fScanOffload)
890 status = csrQueueScanRequest(pMac,pScanCmd);
891 else
892 status = csrQueueSmeCommand(pMac, pScanCmd,
893 eANI_BOOLEAN_FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -0700894#else
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530895 status = csrQueueSmeCommand(pMac, pScanCmd,
896 eANI_BOOLEAN_FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -0700897#endif
898 if( !HAL_STATUS_SUCCESS( status ) )
899 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800900 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700901 break;
902 }
903 }
904 else
905 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800906 smsLog( pMac, LOGE, FL(" fail to copy request status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700907 break;
908 }
909 }
910 else
911 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800912 smsLog( pMac, LOGE, FL(" pScanCmd is NULL"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700913 break;
914 }
915 }
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530916 else
917 {
918 smsLog( pMac, LOGE, FL("SId: %d Scanning not enabled"
919 " Scan type=%u, numOfSSIDs=%d P2P search=%d"),
920 sessionId, pScanRequest->requestType,
921 pScanRequest->SSIDs.numOfSSIDs,
922 pScanRequest->p2pSearch );
923 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700924 } while(0);
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530925
926
Jeff Johnson295189b2012-06-20 16:38:30 -0700927 if(!HAL_STATUS_SUCCESS(status) && pScanCmd)
928 {
929 if( eCsrScanIdleScan == pScanCmd->u.scanCmd.reason )
930 {
931 //Set the flag back for restarting idle scan
932 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
933 }
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530934 smsLog( pMac, LOGE, FL(" SId: %d Failed with status=%d"
935 " Scan reason=%u numOfSSIDs=%d"
936 " P2P search=%d scanId=%d"),
937 sessionId, status, pScanCmd->u.scanCmd.reason,
938 pScanRequest->SSIDs.numOfSSIDs, pScanRequest->p2pSearch,
939 pScanCmd->u.scanCmd.scanID );
Jeff Johnson295189b2012-06-20 16:38:30 -0700940 csrReleaseCommandScan(pMac, pScanCmd);
941 }
942
943 return (status);
944}
945
946
947eHalStatus csrScanRequestResult(tpAniSirGlobal pMac)
948{
949 eHalStatus status = eHAL_STATUS_SUCCESS;
950 tSmeCmd *pScanCmd;
951
952 if(pMac->scan.fScanEnable)
953 {
954 pScanCmd = csrGetCommandBuffer(pMac);
955 if(pScanCmd)
956 {
957 pScanCmd->command = eSmeCommandScan;
Kiet Lam64c1b492013-07-12 13:56:44 +0530958 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -0700959 pScanCmd->u.scanCmd.callback = NULL;
960 pScanCmd->u.scanCmd.pContext = NULL;
961 pScanCmd->u.scanCmd.reason = eCsrScanGetResult;
962 //Need to make the following atomic
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -0700963 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID; //let it wrap around
Jeff Johnson295189b2012-06-20 16:38:30 -0700964 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
965 if( !HAL_STATUS_SUCCESS( status ) )
966 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800967 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700968 csrReleaseCommandScan(pMac, pScanCmd);
969 }
970 }
971 else
972 {
973 //log error
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800974 smsLog(pMac, LOGE, FL("can not obtain a common buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700975 status = eHAL_STATUS_RESOURCES;
976 }
977 }
978
979 return (status);
980}
981
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -0700982#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
983eHalStatus csrScanRequestLfrResult(tpAniSirGlobal pMac, tANI_U32 sessionId,
984 csrScanCompleteCallback callback, void *pContext)
985{
986 eHalStatus status = eHAL_STATUS_SUCCESS;
987 tSmeCmd *pScanCmd;
988
989 if (pMac->scan.fScanEnable)
990 {
991 pScanCmd = csrGetCommandBuffer(pMac);
992 if (pScanCmd)
993 {
994 pScanCmd->command = eSmeCommandScan;
995 pScanCmd->sessionId = sessionId;
Kiet Lam64c1b492013-07-12 13:56:44 +0530996 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -0700997 pScanCmd->u.scanCmd.callback = callback;
998 pScanCmd->u.scanCmd.pContext = pContext;
999 pScanCmd->u.scanCmd.reason = eCsrScanGetLfrResult;
1000 //Need to make the following atomic
1001 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID; //let it wrap around
1002 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_TRUE);
1003 if ( !HAL_STATUS_SUCCESS( status ) )
1004 {
1005 smsLog( pMac, LOGE, FL(" fail to send message status = %d\n"), status );
1006 csrReleaseCommandScan(pMac, pScanCmd);
1007 }
1008 }
1009 else
1010 {
1011 //log error
1012 smsLog(pMac, LOGE, FL("can not obtain a common buffer\n"));
1013 status = eHAL_STATUS_RESOURCES;
1014 }
1015 }
1016
1017 return (status);
1018}
1019#endif //WLAN_FEATURE_ROAM_SCAN_OFFLOAD
Jeff Johnson295189b2012-06-20 16:38:30 -07001020
1021eHalStatus csrScanAllChannels(tpAniSirGlobal pMac, eCsrRequestType reqType)
1022{
1023 eHalStatus status = eHAL_STATUS_SUCCESS;
1024 tANI_U32 scanId;
1025 tCsrScanRequest scanReq;
1026
Kiet Lam64c1b492013-07-12 13:56:44 +05301027 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001028 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
1029 scanReq.scanType = eSIR_ACTIVE_SCAN;
1030 scanReq.requestType = reqType;
1031 scanReq.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1032 scanReq.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001033 scanReq.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1034 scanReq.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001035 //Scan with invalid sessionId.
1036 //This results in SME using the first available session to scan.
1037 status = csrScanRequest(pMac, CSR_SESSION_ID_INVALID, &scanReq,
1038 &scanId, NULL, NULL);
1039
1040 return (status);
1041}
1042
1043
1044
1045
1046eHalStatus csrIssueRoamAfterLostlinkScan(tpAniSirGlobal pMac, tANI_U32 sessionId, eCsrRoamReason reason)
1047{
1048 eHalStatus status = eHAL_STATUS_FAILURE;
1049 tScanResultHandle hBSSList = NULL;
1050 tCsrScanResultFilter *pScanFilter = NULL;
1051 tANI_U32 roamId = 0;
1052 tCsrRoamProfile *pProfile = NULL;
1053 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1054
Jeff Johnson32d95a32012-09-10 13:15:23 -07001055 if(!pSession)
1056 {
1057 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1058 return eHAL_STATUS_FAILURE;
1059 }
1060
Jeff Johnson295189b2012-06-20 16:38:30 -07001061 do
1062 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001063 smsLog(pMac, LOG1, " csrIssueRoamAfterLostlinkScan called");
Jeff Johnson295189b2012-06-20 16:38:30 -07001064 if(pSession->fCancelRoaming)
1065 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001066 smsLog(pMac, LOGW, " lostlink roaming is cancelled");
Jeff Johnson295189b2012-06-20 16:38:30 -07001067 csrScanStartIdleScan(pMac);
1068 status = eHAL_STATUS_SUCCESS;
1069 break;
1070 }
1071 //Here is the profile we need to connect to
Kiet Lam64c1b492013-07-12 13:56:44 +05301072 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1073 if ( NULL == pScanFilter)
1074 status = eHAL_STATUS_FAILURE;
1075 else
1076 status = eHAL_STATUS_SUCCESS;
1077 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001078 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301079 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001080 if(NULL == pSession->pCurRoamProfile)
1081 {
1082 pScanFilter->EncryptionType.numEntries = 1;
1083 pScanFilter->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_NONE;
1084 }
1085 else
1086 {
1087 //We have to make a copy of pCurRoamProfile because it will be free inside csrRoamIssueConnect
Kiet Lam64c1b492013-07-12 13:56:44 +05301088 pProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1089 if ( NULL == pProfile )
1090 status = eHAL_STATUS_FAILURE;
1091 else
1092 status = eHAL_STATUS_SUCCESS;
1093 if (!HAL_STATUS_SUCCESS(status))
1094 break;
1095 vos_mem_set(pProfile, sizeof(tCsrRoamProfile), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001096 status = csrRoamCopyProfile(pMac, pProfile, pSession->pCurRoamProfile);
1097 if(!HAL_STATUS_SUCCESS(status))
1098 break;
1099 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1100 }//We have a profile
1101 roamId = GET_NEXT_ROAM_ID(&pMac->roam);
1102 if(HAL_STATUS_SUCCESS(status))
1103 {
1104 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1105 if(HAL_STATUS_SUCCESS(status))
1106 {
1107 if(eCsrLostLink1 == reason)
1108 {
1109 //we want to put the last connected BSS to the very beginning, if possible
1110 csrMoveBssToHeadFromBSSID(pMac, &pSession->connectedProfile.bssid, hBSSList);
1111 }
1112 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList, reason,
1113 roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1114 if(!HAL_STATUS_SUCCESS(status))
1115 {
1116 csrScanResultPurge(pMac, hBSSList);
1117 }
1118 }//Have scan result
1119 }
1120 }while(0);
1121 if(pScanFilter)
1122 {
1123 //we need to free memory for filter if profile exists
1124 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301125 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001126 }
1127 if(NULL != pProfile)
1128 {
1129 csrReleaseProfile(pMac, pProfile);
Kiet Lam64c1b492013-07-12 13:56:44 +05301130 vos_mem_free(pProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07001131 }
1132
1133 return (status);
1134}
1135
1136
Ratheesh S Pece1f832015-07-25 15:50:25 +05301137eHalStatus csrScanGetScanChnInfo(tpAniSirGlobal pMac, tSmeCmd *pCommand)
Jeff Johnson295189b2012-06-20 16:38:30 -07001138{
1139 eHalStatus status = eHAL_STATUS_SUCCESS;
1140 tSmeCmd *pScanCmd;
1141
1142 if(pMac->scan.fScanEnable)
1143 {
1144 pScanCmd = csrGetCommandBuffer(pMac);
1145 if(pScanCmd)
1146 {
1147 pScanCmd->command = eSmeCommandScan;
Kiet Lam64c1b492013-07-12 13:56:44 +05301148 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001149 pScanCmd->u.scanCmd.reason = eCsrScanGetScanChnInfo;
1150 //Need to make the following atomic
1151 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Ratheesh S Pece1f832015-07-25 15:50:25 +05301152 pScanCmd->sessionId = pCommand->sessionId;
1153 if( pCommand->u.scanCmd.reason == eCsrScanUserRequest)
1154 {
1155 pScanCmd->u.scanCmd.callback = NULL;
1156 pScanCmd->u.scanCmd.pContext = NULL;
1157 } else {
1158 pScanCmd->u.scanCmd.callback = pCommand->u.scanCmd.callback;
1159 pScanCmd->u.scanCmd.pContext = pCommand->u.scanCmd.pContext;
1160 pScanCmd->u.scanCmd.abortScanIndication =
1161 pCommand->u.scanCmd.abortScanIndication;
1162 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001163 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
1164 if( !HAL_STATUS_SUCCESS( status ) )
1165 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001166 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001167 csrReleaseCommandScan(pMac, pScanCmd);
1168 }
1169 }
1170 else
1171 {
1172 //log error
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001173 smsLog(pMac, LOGE, FL("can not obtain a common buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001174 status = eHAL_STATUS_RESOURCES;
1175 }
1176 }
1177
1178 return (status);
1179}
1180
1181
1182eHalStatus csrScanHandleFailedLostlink1(tpAniSirGlobal pMac, tANI_U32 sessionId)
1183{
1184 eHalStatus status = eHAL_STATUS_FAILURE;
1185 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1186
Jeff Johnson32d95a32012-09-10 13:15:23 -07001187 if(!pSession)
1188 {
1189 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1190 return eHAL_STATUS_FAILURE;
1191 }
1192
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001193 smsLog(pMac, LOGW, " Lostlink scan 1 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001194 if(pSession->fCancelRoaming)
1195 {
1196 csrScanStartIdleScan(pMac);
1197 }
1198 else if(pSession->pCurRoamProfile)
1199 {
1200 //We fail lostlink1 but there may be other BSS in the cached result fit the profile. Give it a try first
1201 if(pSession->pCurRoamProfile->SSIDs.numOfSSIDs == 0 ||
1202 pSession->pCurRoamProfile->SSIDs.numOfSSIDs > 1)
1203 {
1204 //try lostlink scan2
1205 status = csrScanRequestLostLink2(pMac, sessionId);
1206 }
1207 else if(!pSession->pCurRoamProfile->ChannelInfo.ChannelList ||
1208 pSession->pCurRoamProfile->ChannelInfo.ChannelList[0] == 0)
1209 {
1210 //go straight to lostlink scan3
1211 status = csrScanRequestLostLink3(pMac, sessionId);
1212 }
1213 else
1214 {
1215 //we are done with lostlink
1216 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1217 {
1218 csrScanStartIdleScan(pMac);
1219 }
1220 status = eHAL_STATUS_SUCCESS;
1221 }
1222 }
1223 else
1224 {
1225 status = csrScanRequestLostLink3(pMac, sessionId);
1226 }
1227
1228 return (status);
1229}
1230
1231
1232
1233eHalStatus csrScanHandleFailedLostlink2(tpAniSirGlobal pMac, tANI_U32 sessionId)
1234{
1235 eHalStatus status = eHAL_STATUS_FAILURE;
1236 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1237
Jeff Johnson32d95a32012-09-10 13:15:23 -07001238 if(!pSession)
1239 {
1240 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1241 return eHAL_STATUS_FAILURE;
1242 }
1243
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001244 smsLog(pMac, LOGW, " Lostlink scan 2 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001245 if(pSession->fCancelRoaming)
1246 {
1247 csrScanStartIdleScan(pMac);
1248 }
1249 else if(!pSession->pCurRoamProfile || !pSession->pCurRoamProfile->ChannelInfo.ChannelList ||
1250 pSession->pCurRoamProfile->ChannelInfo.ChannelList[0] == 0)
1251 {
1252 //try lostlink scan3
1253 status = csrScanRequestLostLink3(pMac, sessionId);
1254 }
1255 else
1256 {
1257 //we are done with lostlink
1258 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1259 {
1260 csrScanStartIdleScan(pMac);
1261 }
1262 }
1263
1264 return (status);
1265}
1266
1267
1268
1269eHalStatus csrScanHandleFailedLostlink3(tpAniSirGlobal pMac, tANI_U32 sessionId)
1270{
1271 eHalStatus status = eHAL_STATUS_SUCCESS;
1272
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001273 smsLog(pMac, LOGW, " Lostlink scan 3 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001274 if(eANI_BOOLEAN_TRUE == csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1275 {
1276 //we are done with lostlink
1277 csrScanStartIdleScan(pMac);
1278 }
1279
1280 return (status);
1281}
1282
1283
1284
1285
1286//Lostlink1 scan is to actively scan the last connected profile's SSID on all matched BSS channels.
1287//If no roam profile (it should not), it is like lostlinkscan3
1288eHalStatus csrScanRequestLostLink1( tpAniSirGlobal pMac, tANI_U32 sessionId )
1289{
1290 eHalStatus status = eHAL_STATUS_SUCCESS;
1291 tSmeCmd *pCommand = NULL;
1292 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1293 tCsrScanResultFilter *pScanFilter = NULL;
1294 tScanResultHandle hBSSList = NULL;
1295 tCsrScanResultInfo *pScanResult = NULL;
1296 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1297
Jeff Johnson32d95a32012-09-10 13:15:23 -07001298 if(!pSession)
1299 {
1300 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1301 return eHAL_STATUS_FAILURE;
1302 }
1303
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001304 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001305 do
1306 {
1307 pCommand = csrGetCommandBuffer(pMac);
1308 if(!pCommand)
1309 {
1310 status = eHAL_STATUS_RESOURCES;
1311 break;
1312 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301313 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001314 pCommand->command = eSmeCommandScan;
1315 pCommand->sessionId = (tANI_U8)sessionId;
1316 pCommand->u.scanCmd.reason = eCsrScanLostLink1;
1317 pCommand->u.scanCmd.callback = NULL;
1318 pCommand->u.scanCmd.pContext = NULL;
1319 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1320 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001321 pCommand->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1322 pCommand->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001323 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
1324 if(pSession->connectedProfile.SSID.length)
1325 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301326 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList = vos_mem_malloc(sizeof(tCsrSSIDInfo));
1327 if ( NULL == pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList )
1328 status = eHAL_STATUS_FAILURE;
1329 else
1330 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001331 if(!HAL_STATUS_SUCCESS(status))
1332 {
1333 break;
1334 }
1335 pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 1;
Kiet Lam64c1b492013-07-12 13:56:44 +05301336 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID,
1337 &pSession->connectedProfile.SSID, sizeof(tSirMacSSid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001338 }
1339 else
1340 {
1341 pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 0;
1342 }
1343 if(pSession->pCurRoamProfile)
1344 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301345 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1346 if ( NULL == pScanFilter )
1347 status = eHAL_STATUS_FAILURE;
1348 else
1349 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001350 if(!HAL_STATUS_SUCCESS(status))
1351 {
1352 break;
1353 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301354 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001355 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
1356 if(!HAL_STATUS_SUCCESS(status))
1357 {
1358 break;
1359 }
1360 //Don't change variable status here because whether we can get result or not, the command goes to PE.
1361 //The status is also used to indicate whether the command is queued. Not success meaning not queue
1362 if(HAL_STATUS_SUCCESS((csrScanGetResult(pMac, pScanFilter, &hBSSList))) && hBSSList)
1363 {
1364 tANI_U8 i, nChn = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05301365 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList =
1366 vos_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
1367 if ( NULL == pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
1368 status = eHAL_STATUS_FAILURE;
1369 else
1370 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001371 if(!HAL_STATUS_SUCCESS(status))
1372 {
1373 break;
1374 }
1375 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) &&
1376 nChn < WNI_CFG_VALID_CHANNEL_LIST_LEN)
1377 {
1378 for(i = 0; i < nChn; i++)
1379 {
1380 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1381 pScanResult->BssDescriptor.channelId)
1382 {
1383 break;
1384 }
1385 }
1386 if(i == nChn)
1387 {
1388 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pScanResult->BssDescriptor.channelId;
1389 }
1390 }
1391 //Include the last connected BSS' channel
1392 if(csrRoamIsChannelValid(pMac, pSession->connectedProfile.operationChannel))
1393 {
1394 for(i = 0; i < nChn; i++)
1395 {
1396 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1397 pSession->connectedProfile.operationChannel)
1398 {
1399 break;
1400 }
1401 }
1402 if(i == nChn)
1403 {
1404 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pSession->connectedProfile.operationChannel;
1405 }
1406 }
1407 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nChn;
1408 }
1409 else
1410 {
1411 if(csrRoamIsChannelValid(pMac, pSession->connectedProfile.operationChannel))
1412 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301413 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(1);
1414 if ( NULL == pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
1415 status = eHAL_STATUS_FAILURE;
1416 else
1417 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001418 //just try the last connected channel
1419 if(HAL_STATUS_SUCCESS(status))
1420 {
1421 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[0] = pSession->connectedProfile.operationChannel;
1422 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 1;
1423 }
1424 else
1425 {
1426 break;
1427 }
1428 }
1429 }
1430 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301431 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001432 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
1433 if( !HAL_STATUS_SUCCESS( status ) )
1434 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001435 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001436 break;
1437 }
1438 } while( 0 );
1439
1440 if(!HAL_STATUS_SUCCESS(status))
1441 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001442 smsLog(pMac, LOGW, " csrScanRequestLostLink1 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001443 if(pCommand)
1444 {
1445 csrReleaseCommandScan(pMac, pCommand);
1446 }
1447 status = csrScanHandleFailedLostlink1( pMac, sessionId );
1448 }
1449 if(pScanFilter)
1450 {
1451 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301452 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001453 }
1454 if(hBSSList)
1455 {
1456 csrScanResultPurge(pMac, hBSSList);
1457 }
1458
1459 return( status );
1460}
1461
1462
1463//Lostlink2 scan is to actively scan the all SSIDs of the last roaming profile's on all matched BSS channels.
1464//Since MAC doesn't support multiple SSID, we scan all SSIDs and filter them afterwards
1465eHalStatus csrScanRequestLostLink2( tpAniSirGlobal pMac, tANI_U32 sessionId )
1466{
1467 eHalStatus status = eHAL_STATUS_SUCCESS;
1468 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1469 tCsrScanResultFilter *pScanFilter = NULL;
1470 tScanResultHandle hBSSList = NULL;
1471 tCsrScanResultInfo *pScanResult = NULL;
1472 tSmeCmd *pCommand = NULL;
1473 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1474
Jeff Johnson32d95a32012-09-10 13:15:23 -07001475 if(!pSession)
1476 {
1477 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1478 return eHAL_STATUS_FAILURE;
1479 }
1480
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001481 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001482 do
1483 {
1484 pCommand = csrGetCommandBuffer(pMac);
1485 if(!pCommand)
1486 {
1487 status = eHAL_STATUS_RESOURCES;
1488 break;
1489 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301490 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001491 pCommand->command = eSmeCommandScan;
1492 pCommand->sessionId = (tANI_U8)sessionId;
1493 pCommand->u.scanCmd.reason = eCsrScanLostLink2;
1494 pCommand->u.scanCmd.callback = NULL;
1495 pCommand->u.scanCmd.pContext = NULL;
1496 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1497 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001498 pCommand->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1499 pCommand->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001500 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
1501 if(pSession->pCurRoamProfile)
1502 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301503 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1504 if ( NULL == pScanFilter )
1505 status = eHAL_STATUS_FAILURE;
1506 else
1507 status = eHAL_STATUS_SUCCESS;
1508 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001509 {
1510 break;
1511 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301512 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001513 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
1514 if(!HAL_STATUS_SUCCESS(status))
1515 {
1516 break;
1517 }
1518 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1519 if(!HAL_STATUS_SUCCESS(status))
1520 {
1521 break;
1522 }
1523 if(hBSSList)
1524 {
1525 tANI_U8 i, nChn = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05301526 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList =
1527 vos_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
1528 if ( NULL == pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
1529 status = eHAL_STATUS_FAILURE;
1530 else
1531 status = eHAL_STATUS_SUCCESS;
1532 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001533 {
1534 break;
1535 }
1536 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) &&
1537 nChn < WNI_CFG_VALID_CHANNEL_LIST_LEN)
1538 {
1539 for(i = 0; i < nChn; i++)
1540 {
1541 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1542 pScanResult->BssDescriptor.channelId)
1543 {
1544 break;
1545 }
1546 }
1547 if(i == nChn)
1548 {
1549 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pScanResult->BssDescriptor.channelId;
1550 }
1551 }
1552 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nChn;
1553 }
1554 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301555 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001556 //Put to the head in pending queue
1557 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_TRUE);
1558 if( !HAL_STATUS_SUCCESS( status ) )
1559 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001560 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001561 break;
1562 }
1563 } while( 0 );
1564
1565 if(!HAL_STATUS_SUCCESS(status))
1566 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001567 smsLog(pMac, LOGW, " csrScanRequestLostLink2 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001568 if(pCommand)
1569 {
1570 csrReleaseCommandScan(pMac, pCommand);
1571 }
1572 status = csrScanHandleFailedLostlink2( pMac, sessionId );
1573 }
1574 if(pScanFilter)
1575 {
1576 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301577 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001578 }
1579 if(hBSSList)
1580 {
1581 csrScanResultPurge(pMac, hBSSList);
1582 }
1583
1584 return( status );
1585}
1586
1587
1588//To actively scan all valid channels
1589eHalStatus csrScanRequestLostLink3( tpAniSirGlobal pMac, tANI_U32 sessionId )
1590{
1591 eHalStatus status = eHAL_STATUS_SUCCESS;
1592 tSmeCmd *pCommand;
1593 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1594
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001595 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001596 do
1597 {
1598 pCommand = csrGetCommandBuffer(pMac);
1599 if(!pCommand)
1600 {
1601 status = eHAL_STATUS_RESOURCES;
1602 break;
1603 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301604 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001605 pCommand->command = eSmeCommandScan;
1606 pCommand->sessionId = (tANI_U8)sessionId;
1607 pCommand->u.scanCmd.reason = eCsrScanLostLink3;
1608 pCommand->u.scanCmd.callback = NULL;
1609 pCommand->u.scanCmd.pContext = NULL;
1610 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1611 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001612 pCommand->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1613 pCommand->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001614 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Kiet Lam64c1b492013-07-12 13:56:44 +05301615 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001616 //Put to the head of pending queue
1617 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_TRUE);
1618 if( !HAL_STATUS_SUCCESS( status ) )
1619 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001620 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001621 break;
1622 }
1623 } while( 0 );
1624 if(!HAL_STATUS_SUCCESS(status))
1625 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001626 smsLog(pMac, LOGW, " csrScanRequestLostLink3 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001627 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1628 {
1629 csrScanStartIdleScan(pMac);
1630 }
1631 if(pCommand)
1632 {
1633 csrReleaseCommandScan(pMac, pCommand);
1634 }
1635 }
1636
1637 return( status );
1638}
1639
1640
1641eHalStatus csrScanHandleSearchForSSID(tpAniSirGlobal pMac, tSmeCmd *pCommand)
1642{
1643 eHalStatus status = eHAL_STATUS_FAILURE;
1644 tScanResultHandle hBSSList = CSR_INVALID_SCANRESULT_HANDLE;
1645 tCsrScanResultFilter *pScanFilter = NULL;
1646 tCsrRoamProfile *pProfile = pCommand->u.scanCmd.pToRoamProfile;
1647 tANI_U32 sessionId = pCommand->sessionId;
1648#ifdef FEATURE_WLAN_BTAMP_UT_RF
1649 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1650#endif
1651 do
1652 {
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001653#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
1654 //if this scan is for LFR
1655 if(pMac->roam.neighborRoamInfo.uOsRequestedHandoff)
1656 {
1657 //notify LFR state m/c
1658 if(eHAL_STATUS_SUCCESS != csrNeighborRoamSssidScanDone(pMac, eHAL_STATUS_SUCCESS))
1659 {
Mukul Sharma20aa6582014-08-07 21:36:12 +05301660 csrNeighborRoamStartLfrScan(pMac, REASON_OS_REQUESTED_ROAMING_NOW);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001661 }
1662 status = eHAL_STATUS_SUCCESS;
1663 break;
1664 }
1665#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001666 //If there is roam command waiting, ignore this roam because the newer roam command is the one to execute
1667 if(csrIsRoamCommandWaitingForSession(pMac, sessionId))
1668 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001669 smsLog(pMac, LOGW, FL(" aborts because roam command waiting"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001670 break;
1671 }
1672 if(pProfile == NULL)
1673 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301674 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1675 if ( NULL == pScanFilter )
1676 status = eHAL_STATUS_FAILURE;
1677 else
1678 status = eHAL_STATUS_SUCCESS;
1679 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001680 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301681 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001682 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1683 if(!HAL_STATUS_SUCCESS(status))
1684 break;
1685 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1686 if(!HAL_STATUS_SUCCESS(status))
1687 break;
1688 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList, eCsrHddIssued,
1689 pCommand->u.scanCmd.roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1690 if(!HAL_STATUS_SUCCESS(status))
1691 {
1692 break;
1693 }
1694 }while(0);
1695 if(!HAL_STATUS_SUCCESS(status))
1696 {
1697 if(CSR_INVALID_SCANRESULT_HANDLE != hBSSList)
1698 {
1699 csrScanResultPurge(pMac, hBSSList);
1700 }
1701 //We haven't done anything to this profile
1702 csrRoamCallCallback(pMac, sessionId, NULL, pCommand->u.scanCmd.roamId,
1703 eCSR_ROAM_ASSOCIATION_FAILURE, eCSR_ROAM_RESULT_FAILURE);
1704 //In case we have nothing else to do, restart idle scan
1705 if(csrIsConnStateDisconnected(pMac, sessionId) && !csrIsRoamCommandWaiting(pMac))
1706 {
1707 status = csrScanStartIdleScan(pMac);
1708 }
1709#ifdef FEATURE_WLAN_BTAMP_UT_RF
1710 //In case of WDS station, let it retry.
1711 if( CSR_IS_WDS_STA(pProfile) )
1712 {
1713 //Save the roma profile so we can retry
1714 csrFreeRoamProfile( pMac, sessionId );
Kiet Lam64c1b492013-07-12 13:56:44 +05301715 pSession->pCurRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1716 if ( NULL != pSession->pCurRoamProfile )
Jeff Johnson295189b2012-06-20 16:38:30 -07001717 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301718 vos_mem_set(pSession->pCurRoamProfilee, sizeof(tCsrRoamProfile), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001719 csrRoamCopyProfile(pMac, pSession->pCurRoamProfile, pProfile);
1720 }
1721 csrRoamStartJoinRetryTimer(pMac, sessionId, CSR_JOIN_RETRY_TIMEOUT_PERIOD);
1722 }
1723#endif
1724 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301725 if (pScanFilter)
Jeff Johnson295189b2012-06-20 16:38:30 -07001726 {
1727 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301728 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001729 }
1730
1731 return (status);
1732}
1733
1734
1735eHalStatus csrScanHandleSearchForSSIDFailure(tpAniSirGlobal pMac, tSmeCmd *pCommand)
1736{
1737 eHalStatus status = eHAL_STATUS_SUCCESS;
1738 tANI_U32 sessionId = pCommand->sessionId;
1739 tCsrRoamProfile *pProfile = pCommand->u.scanCmd.pToRoamProfile;
1740 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001741#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
1742 //if this scan is for LFR
1743 if(pMac->roam.neighborRoamInfo.uOsRequestedHandoff)
1744 {
1745 //notify LFR state m/c
1746 if(eHAL_STATUS_SUCCESS != csrNeighborRoamSssidScanDone(pMac, eHAL_STATUS_FAILURE))
1747 {
Mukul Sharma20aa6582014-08-07 21:36:12 +05301748 csrNeighborRoamStartLfrScan(pMac, REASON_OS_REQUESTED_ROAMING_NOW);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001749 }
1750 return eHAL_STATUS_SUCCESS;
1751 }
1752#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -07001753 if(!pSession)
1754 {
1755 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1756 return eHAL_STATUS_FAILURE;
1757 }
1758
Jeff Johnson295189b2012-06-20 16:38:30 -07001759#if defined(WLAN_DEBUG)
1760 if(pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs == 1)
1761 {
1762 char str[36];
Kiet Lam64c1b492013-07-12 13:56:44 +05301763 vos_mem_copy(str,
1764 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.ssId,
1765 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.length);
Jeff Johnson295189b2012-06-20 16:38:30 -07001766 str[pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.length] = 0;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001767 smsLog(pMac, LOGW, FL(" SSID = %s"), str);
Jeff Johnson295189b2012-06-20 16:38:30 -07001768 }
1769#endif
1770 //Check whether it is for start ibss. No need to do anything if it is a JOIN request
1771 if(pProfile && CSR_IS_START_IBSS(pProfile))
1772 {
1773 status = csrRoamIssueConnect(pMac, sessionId, pProfile, NULL, eCsrHddIssued,
1774 pCommand->u.scanCmd.roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1775 if(!HAL_STATUS_SUCCESS(status))
1776 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001777 smsLog(pMac, LOGE, FL("failed to issue startIBSS command with status = 0x%08X"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001778 csrRoamCallCallback(pMac, sessionId, NULL, pCommand->u.scanCmd.roamId, eCSR_ROAM_FAILED, eCSR_ROAM_RESULT_FAILURE);
1779 }
1780 }
1781 else
1782 {
1783 eCsrRoamResult roamResult = eCSR_ROAM_RESULT_FAILURE;
1784
1785 if(csrIsConnStateDisconnected(pMac, sessionId) &&
1786 !csrIsRoamCommandWaitingForSession(pMac, sessionId))
1787 {
1788 status = csrScanStartIdleScan(pMac);
1789 }
1790 if((NULL == pProfile) || !csrIsBssTypeIBSS(pProfile->BSSType))
1791 {
1792 //Only indicate assoc_completion if we indicate assoc_start.
1793 if(pSession->bRefAssocStartCnt > 0)
1794 {
1795 tCsrRoamInfo *pRoamInfo = NULL, roamInfo;
Kiet Lam64c1b492013-07-12 13:56:44 +05301796 vos_mem_set(&roamInfo, sizeof(tCsrRoamInfo), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001797 pRoamInfo = &roamInfo;
1798 if(pCommand->u.roamCmd.pRoamBssEntry)
1799 {
1800 tCsrScanResult *pScanResult =
1801 GET_BASE_ADDR(pCommand->u.roamCmd.pRoamBssEntry,
1802 tCsrScanResult, Link);
1803 roamInfo.pBssDesc = &pScanResult->Result.BssDescriptor;
1804 }
1805 roamInfo.statusCode = pSession->joinFailStatusCode.statusCode;
1806 roamInfo.reasonCode = pSession->joinFailStatusCode.reasonCode;
1807 pSession->bRefAssocStartCnt--;
1808 csrRoamCallCallback(pMac, sessionId, pRoamInfo,
1809 pCommand->u.scanCmd.roamId,
1810 eCSR_ROAM_ASSOCIATION_COMPLETION,
1811 eCSR_ROAM_RESULT_FAILURE);
1812 }
Madan Mohan Koyyalamudiee255f12012-09-28 15:41:19 -07001813 else
1814 {
1815 csrRoamCallCallback(pMac, sessionId, NULL,
1816 pCommand->u.scanCmd.roamId,
1817 eCSR_ROAM_ASSOCIATION_FAILURE,
1818 eCSR_ROAM_RESULT_FAILURE);
1819 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001820#ifdef FEATURE_WLAN_BTAMP_UT_RF
1821 //In case of WDS station, let it retry.
1822 if( CSR_IS_WDS_STA(pProfile) )
1823 {
1824 //Save the roma profile so we can retry
1825 csrFreeRoamProfile( pMac, sessionId );
Kiet Lam64c1b492013-07-12 13:56:44 +05301826 pSession->pCurRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1827 if ( NULL != pSession->pCurRoamProfile )
Jeff Johnson295189b2012-06-20 16:38:30 -07001828 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301829 vos_mem_set(pSession->pCurRoamProfile, sizeof(tCsrRoamProfile), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001830 csrRoamCopyProfile(pMac, pSession->pCurRoamProfile, pProfile);
1831 }
1832 csrRoamStartJoinRetryTimer(pMac, sessionId, CSR_JOIN_RETRY_TIMEOUT_PERIOD);
1833 }
1834#endif
1835 }
1836 else
1837 {
1838 roamResult = eCSR_ROAM_RESULT_IBSS_START_FAILED;
1839 }
1840 csrRoamCompletion(pMac, sessionId, NULL, pCommand, roamResult, eANI_BOOLEAN_FALSE);
1841 }
1842
1843 return (status);
1844}
1845
1846
1847//After scan for cap changes, issue a roaming command to either reconnect to the AP or pick another one to connect
1848eHalStatus csrScanHandleCapChangeScanComplete(tpAniSirGlobal pMac, tANI_U32 sessionId)
1849{
1850 eHalStatus status = eHAL_STATUS_FAILURE;
1851 tScanResultHandle hBSSList = NULL;
1852 tCsrScanResultFilter *pScanFilter = NULL;
1853 tANI_U32 roamId = 0;
1854 tCsrRoamProfile *pProfile = NULL;
1855 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1856
1857 do
1858 {
1859 //Here is the profile we need to connect to
Kiet Lam64c1b492013-07-12 13:56:44 +05301860 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1861 if ( NULL == pScanFilter )
1862 status = eHAL_STATUS_FAILURE;
1863 else
1864 status = eHAL_STATUS_SUCCESS;
1865 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001866 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301867 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
1868 if (NULL == pSession) break;
1869 if (NULL == pSession->pCurRoamProfile)
Jeff Johnson295189b2012-06-20 16:38:30 -07001870 {
1871 pScanFilter->EncryptionType.numEntries = 1;
1872 pScanFilter->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_NONE;
1873 }
1874 else
1875 {
1876 //We have to make a copy of pCurRoamProfile because it will be free inside csrRoamIssueConnect
Kiet Lam64c1b492013-07-12 13:56:44 +05301877 pProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1878 if ( NULL == pProfile )
1879 status = eHAL_STATUS_FAILURE;
1880 else
1881 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001882 if(!HAL_STATUS_SUCCESS(status))
1883 break;
1884 status = csrRoamCopyProfile(pMac, pProfile, pSession->pCurRoamProfile);
1885 if(!HAL_STATUS_SUCCESS(status))
1886 break;
1887 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1888 }//We have a profile
1889 roamId = GET_NEXT_ROAM_ID(&pMac->roam);
1890 if(HAL_STATUS_SUCCESS(status))
1891 {
1892 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1893 if(HAL_STATUS_SUCCESS(status))
1894 {
1895 //we want to put the last connected BSS to the very beginning, if possible
1896 csrMoveBssToHeadFromBSSID(pMac, &pSession->connectedProfile.bssid, hBSSList);
1897 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList,
1898 eCsrCapsChange, 0, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1899 if(!HAL_STATUS_SUCCESS(status))
1900 {
1901 csrScanResultPurge(pMac, hBSSList);
1902 }
1903 }//Have scan result
1904 else
1905 {
Arif Hussaina7c8e412013-11-20 11:06:42 -08001906 smsLog(pMac, LOGW, FL("cannot find matching BSS of "
1907 MAC_ADDRESS_STR),
1908 MAC_ADDR_ARRAY(pSession->connectedProfile.bssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001909 //Disconnect
1910 csrRoamDisconnectInternal(pMac, sessionId, eCSR_DISCONNECT_REASON_UNSPECIFIED);
1911 }
1912 }
1913 }while(0);
1914 if(pScanFilter)
1915 {
1916 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301917 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001918 }
1919 if(NULL != pProfile)
1920 {
1921 csrReleaseProfile(pMac, pProfile);
Kiet Lam64c1b492013-07-12 13:56:44 +05301922 vos_mem_free(pProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07001923 }
1924
1925 return (status);
1926}
1927
1928
1929
1930eHalStatus csrScanResultPurge(tpAniSirGlobal pMac, tScanResultHandle hScanList)
1931{
1932 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
1933 tScanResultList *pScanList = (tScanResultList *)hScanList;
1934
1935 if(pScanList)
1936 {
1937 status = csrLLScanPurgeResult(pMac, &pScanList->List);
1938 csrLLClose(&pScanList->List);
Kiet Lam64c1b492013-07-12 13:56:44 +05301939 vos_mem_free(pScanList);
Jeff Johnson295189b2012-06-20 16:38:30 -07001940 }
1941 return (status);
1942}
1943
1944
1945static tANI_U32 csrGetBssPreferValue(tpAniSirGlobal pMac, int rssi)
1946{
1947 tANI_U32 ret = 0;
1948 int i = CSR_NUM_RSSI_CAT - 1;
1949
1950 while(i >= 0)
1951 {
1952 if(rssi >= pMac->roam.configParam.RSSICat[i])
1953 {
1954 ret = pMac->roam.configParam.BssPreferValue[i];
1955 break;
1956 }
1957 i--;
1958 };
1959
1960 return (ret);
1961}
1962
1963
1964//Return a CapValue base on the capabilities of a BSS
1965static tANI_U32 csrGetBssCapValue(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes)
1966{
1967 tANI_U32 ret = CSR_BSS_CAP_VALUE_NONE;
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08001968#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_ESE) || defined(FEATURE_WLAN_LFR)
Madan Mohan Koyyalamudid5026072012-11-30 14:56:21 -08001969 if(CSR_IS_ROAM_PREFER_5GHZ(pMac))
1970 {
1971 if((pBssDesc) && CSR_IS_CHANNEL_5GHZ(pBssDesc->channelId))
1972 {
1973 ret += CSR_BSS_CAP_VALUE_5GHZ;
1974 }
1975 }
1976#endif
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07001977 /* if strict select 5GHz is non-zero then ignore the capability checking */
1978 if (pIes && !CSR_IS_SELECT_5GHZ_MARGIN(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -07001979 {
1980 //We only care about 11N capability
1981 if(pIes->HTCaps.present)
1982 {
1983 ret += CSR_BSS_CAP_VALUE_HT;
1984 }
1985 if(CSR_IS_QOS_BSS(pIes))
1986 {
1987 ret += CSR_BSS_CAP_VALUE_WMM;
1988 //Give advantage to UAPSD
1989 if(CSR_IS_UAPSD_BSS(pIes))
1990 {
1991 ret += CSR_BSS_CAP_VALUE_UAPSD;
1992 }
1993 }
1994 }
1995
1996 return (ret);
1997}
1998
1999
2000//To check whther pBss1 is better than pBss2
2001static tANI_BOOLEAN csrIsBetterBss(tCsrScanResult *pBss1, tCsrScanResult *pBss2)
2002{
2003 tANI_BOOLEAN ret;
2004
2005 if(CSR_IS_BETTER_PREFER_VALUE(pBss1->preferValue, pBss2->preferValue))
2006 {
2007 ret = eANI_BOOLEAN_TRUE;
2008 }
2009 else if(CSR_IS_EQUAL_PREFER_VALUE(pBss1->preferValue, pBss2->preferValue))
2010 {
2011 if(CSR_IS_BETTER_CAP_VALUE(pBss1->capValue, pBss2->capValue))
2012 {
2013 ret = eANI_BOOLEAN_TRUE;
2014 }
2015 else
2016 {
2017 ret = eANI_BOOLEAN_FALSE;
2018 }
2019 }
2020 else
2021 {
2022 ret = eANI_BOOLEAN_FALSE;
2023 }
2024
2025 return (ret);
2026}
2027
2028
Srikant Kuppa866893f2012-12-27 17:28:14 -08002029#ifdef FEATURE_WLAN_LFR
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002030//Add the channel to the occupiedChannels array
2031static void csrScanAddToOccupiedChannels(
Srikant Kuppa866893f2012-12-27 17:28:14 -08002032 tpAniSirGlobal pMac,
2033 tCsrScanResult *pResult,
2034 tCsrChannel *pOccupiedChannels,
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002035 tDot11fBeaconIEs *pIes)
2036{
2037 eHalStatus status;
2038 tANI_U8 channel;
2039 tANI_U8 numOccupiedChannels = pOccupiedChannels->numChannels;
2040 tANI_U8 *pOccupiedChannelList = pOccupiedChannels->channelList;
2041
2042 channel = pResult->Result.BssDescriptor.channelId;
2043
2044 if (!csrIsChannelPresentInList(pOccupiedChannelList, numOccupiedChannels, channel)
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08002045 && csrNeighborRoamConnectedProfileMatch(pMac, pResult, pIes))
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002046 {
Srikant Kuppa866893f2012-12-27 17:28:14 -08002047 status = csrAddToChannelListFront(pOccupiedChannelList, numOccupiedChannels, channel);
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002048 if(HAL_STATUS_SUCCESS(status))
Srikant Kuppa866893f2012-12-27 17:28:14 -08002049 {
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002050 pOccupiedChannels->numChannels++;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002051 smsLog(pMac, LOG2, FL("%s: added channel %d to the list (count=%d)"),
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08002052 __func__, channel, pOccupiedChannels->numChannels);
Srikant Kuppa866893f2012-12-27 17:28:14 -08002053 if (pOccupiedChannels->numChannels > CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN)
2054 pOccupiedChannels->numChannels = CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN;
2055 }
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002056 }
2057}
Mukul Sharma9e4e0f92015-02-13 18:45:20 +05302058
2059void csrAddChannelToOccupiedChannelList(tpAniSirGlobal pMac,
2060 tANI_U8 channel)
2061{
2062 eHalStatus status;
2063 tCsrChannel *pOccupiedChannels = &pMac->scan.occupiedChannels;
2064 tANI_U8 numOccupiedChannels = pOccupiedChannels->numChannels;
2065 tANI_U8 *pOccupiedChannelList = pOccupiedChannels->channelList;
2066 if (!csrIsChannelPresentInList(pOccupiedChannelList,
2067 numOccupiedChannels, channel))
2068 {
2069 status = csrAddToChannelListFront(pOccupiedChannelList,
2070 numOccupiedChannels, channel);
2071 if(HAL_STATUS_SUCCESS(status))
2072 {
2073 pOccupiedChannels->numChannels++;
2074 smsLog(pMac, LOG2, FL("added channel %d to the list (count=%d)"),
2075 channel, pOccupiedChannels->numChannels);
2076 if (pOccupiedChannels->numChannels >
2077 CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN)
2078 {
2079 pOccupiedChannels->numChannels =
2080 CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN;
2081 smsLog(pMac, LOG2,
2082 FL("trim no of Channels for Occ channel list"));
2083 }
2084 }
2085 }
2086}
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002087#endif
2088
Jeff Johnson295189b2012-06-20 16:38:30 -07002089//Put the BSS into the scan result list
2090//pIes can not be NULL
2091static void csrScanAddResult(tpAniSirGlobal pMac, tCsrScanResult *pResult, tDot11fBeaconIEs *pIes)
2092{
Srinivas28b5b4e2012-12-12 13:07:53 -08002093#ifdef FEATURE_WLAN_LFR
2094 tpCsrNeighborRoamControlInfo pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
2095#endif
2096
Jeff Johnson295189b2012-06-20 16:38:30 -07002097 pResult->preferValue = csrGetBssPreferValue(pMac, (int)pResult->Result.BssDescriptor.rssi);
2098 pResult->capValue = csrGetBssCapValue(pMac, &pResult->Result.BssDescriptor, pIes);
2099 csrLLInsertTail( &pMac->scan.scanResultList, &pResult->Link, LL_ACCESS_LOCK );
Srikant Kuppa866893f2012-12-27 17:28:14 -08002100#ifdef FEATURE_WLAN_LFR
Srinivas28b5b4e2012-12-12 13:07:53 -08002101 if(0 == pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels)
2102 {
2103 /* Build the occupied channel list, only if "gNeighborScanChannelList" is
2104 NOT set in the cfg.ini file */
2105 csrScanAddToOccupiedChannels(pMac, pResult, &pMac->scan.occupiedChannels, pIes);
2106 }
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002107#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002108}
2109
2110
2111eHalStatus csrScanGetResult(tpAniSirGlobal pMac, tCsrScanResultFilter *pFilter, tScanResultHandle *phResult)
2112{
2113 eHalStatus status;
2114 tScanResultList *pRetList;
2115 tCsrScanResult *pResult, *pBssDesc;
2116 tANI_U32 count = 0;
2117 tListElem *pEntry;
2118 tANI_U32 bssLen, allocLen;
2119 eCsrEncryptionType uc = eCSR_ENCRYPT_TYPE_NONE, mc = eCSR_ENCRYPT_TYPE_NONE;
2120 eCsrAuthType auth = eCSR_AUTH_TYPE_OPEN_SYSTEM;
2121 tDot11fBeaconIEs *pIes, *pNewIes;
2122 tANI_BOOLEAN fMatch;
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002123 tANI_U16 i = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07002124
2125 if(phResult)
2126 {
2127 *phResult = CSR_INVALID_SCANRESULT_HANDLE;
2128 }
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002129
2130 if (pMac->roam.configParam.nSelect5GHzMargin)
2131 {
2132 pMac->scan.inScanResultBestAPRssi = -128;
2133 csrLLLock(&pMac->scan.scanResultList);
2134
2135 /* Find out the best AP Rssi going thru the scan results */
2136 pEntry = csrLLPeekHead(&pMac->scan.scanResultList, LL_ACCESS_NOLOCK);
2137 while ( NULL != pEntry)
2138 {
2139 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002140 fMatch = FALSE;
2141
2142 if (pFilter)
2143 for(i = 0; i < pFilter->SSIDs.numOfSSIDs; i++)
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002144 {
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002145 fMatch = csrIsSsidMatch( pMac, pFilter->SSIDs.SSIDList[i].SSID.ssId, pFilter->SSIDs.SSIDList[i].SSID.length,
2146 pBssDesc->Result.ssId.ssId,
2147 pBssDesc->Result.ssId.length, eANI_BOOLEAN_TRUE );
2148 if (fMatch)
2149 {
2150 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
2151
2152 //At this time, pBssDescription->Result.pvIes may be NULL
2153 if( !pIes && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
2154 &pBssDesc->Result.BssDescriptor, &pIes))) )
2155 {
2156 continue;
2157 }
2158
2159 smsLog(pMac, LOG1, FL("SSID Matched"));
Leela Venkata Kiran Kumar Reddy Chiralae208a832014-04-27 22:34:25 -07002160
Leela Venkata Kiran Kumar Reddy Chiralaf257bef2014-04-11 18:48:12 -07002161 if ( pFilter->bOSENAssociation )
2162 {
2163 fMatch = TRUE;
2164 }
Leela Venkata Kiran Kumar Reddy Chiralae208a832014-04-27 22:34:25 -07002165 else
2166 {
Abhishek Singh658d4de2014-06-26 10:53:15 +05302167#ifdef WLAN_FEATURE_11W
Abhishek Singh3b56d3a2014-06-25 12:37:39 +05302168 fMatch = csrIsSecurityMatch(pMac, &pFilter->authType,
2169 &pFilter->EncryptionType,
2170 &pFilter->mcEncryptionType,
2171 &pFilter->MFPEnabled,
2172 &pFilter->MFPRequired,
2173 &pFilter->MFPCapable,
2174 &pBssDesc->Result.BssDescriptor,
2175 pIes, NULL, NULL, NULL );
Abhishek Singh658d4de2014-06-26 10:53:15 +05302176#else
2177 fMatch = csrIsSecurityMatch(pMac, &pFilter->authType,
2178 &pFilter->EncryptionType,
2179 &pFilter->mcEncryptionType,
2180 NULL, NULL, NULL,
2181 &pBssDesc->Result.BssDescriptor,
2182 pIes, NULL, NULL, NULL );
2183#endif
Leela Venkata Kiran Kumar Reddy Chiralae208a832014-04-27 22:34:25 -07002184 }
2185 if ((pBssDesc->Result.pvIes == NULL) && pIes)
2186 vos_mem_free(pIes);
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002187
2188 if (fMatch)
2189 smsLog(pMac, LOG1, FL(" Security Matched"));
2190 }
2191 }
2192
2193 if (fMatch && (pBssDesc->Result.BssDescriptor.rssi > pMac->scan.inScanResultBestAPRssi))
2194 {
2195 smsLog(pMac, LOG1, FL("Best AP Rssi changed from %d to %d"),
2196 pMac->scan.inScanResultBestAPRssi,
2197 pBssDesc->Result.BssDescriptor.rssi);
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002198 pMac->scan.inScanResultBestAPRssi = pBssDesc->Result.BssDescriptor.rssi;
2199 }
2200 pEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
2201 }
2202
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002203 if ( -128 != pMac->scan.inScanResultBestAPRssi)
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002204 {
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002205 smsLog(pMac, LOG1, FL("Best AP Rssi is %d"), pMac->scan.inScanResultBestAPRssi);
2206 /* Modify Rssi category based on best AP Rssi */
2207 csrAssignRssiForCategory(pMac, pMac->scan.inScanResultBestAPRssi, pMac->roam.configParam.bCatRssiOffset);
2208 pEntry = csrLLPeekHead(&pMac->scan.scanResultList, LL_ACCESS_NOLOCK);
2209 while ( NULL != pEntry)
2210 {
2211 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002212
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002213 /* re-assign preference value based on modified rssi bucket */
2214 pBssDesc->preferValue = csrGetBssPreferValue(pMac, (int)pBssDesc->Result.BssDescriptor.rssi);
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002215
Arif Hussaina7c8e412013-11-20 11:06:42 -08002216 smsLog(pMac, LOG2, FL("BSSID("MAC_ADDRESS_STR
Jeff Johnson123ed002013-11-22 17:39:55 -08002217 ") Rssi(%d) Chnl(%d) PrefVal(%u) SSID=%.*s"),
Arif Hussaina7c8e412013-11-20 11:06:42 -08002218 MAC_ADDR_ARRAY(pBssDesc->Result.BssDescriptor.bssId),
2219 pBssDesc->Result.BssDescriptor.rssi,
2220 pBssDesc->Result.BssDescriptor.channelId,
2221 pBssDesc->preferValue,
2222 pBssDesc->Result.ssId.length, pBssDesc->Result.ssId.ssId);
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002223
2224 pEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
2225 }
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002226 }
2227
2228 csrLLUnlock(&pMac->scan.scanResultList);
2229 }
2230
Kiet Lam64c1b492013-07-12 13:56:44 +05302231 pRetList = vos_mem_malloc(sizeof(tScanResultList));
2232 if ( NULL == pRetList )
2233 status = eHAL_STATUS_FAILURE;
2234 else
2235 status = eHAL_STATUS_SUCCESS;
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002236 if(HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07002237 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302238 vos_mem_set(pRetList, sizeof(tScanResultList), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002239 csrLLOpen(pMac->hHdd, &pRetList->List);
2240 pRetList->pCurEntry = NULL;
2241
2242 csrLLLock(&pMac->scan.scanResultList);
2243 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
2244 while( pEntry )
2245 {
2246 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2247 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
2248 //if pBssDesc->Result.pvIes is NULL, we need to free any memory allocated by csrMatchBSS
2249 //for any error condition, otherwiase, it will be freed later.
2250 //reset
2251 fMatch = eANI_BOOLEAN_FALSE;
2252 pNewIes = NULL;
2253
2254 if(pFilter)
2255 {
2256 fMatch = csrMatchBSS(pMac, &pBssDesc->Result.BssDescriptor, pFilter, &auth, &uc, &mc, &pIes);
2257 if( NULL != pIes )
2258 {
2259 //Only save it when matching
2260 if(fMatch)
2261 {
2262 if( !pBssDesc->Result.pvIes )
2263 {
2264 //csrMatchBSS allocates the memory. Simply pass it and it is freed later
2265 pNewIes = pIes;
2266 }
2267 else
2268 {
2269 //The pIes is allocated by someone else. make a copy
2270 //Only to save parsed IEs if caller provides a filter. Most likely the caller
2271 //is using to for association, hence save the parsed IEs
Kiet Lam64c1b492013-07-12 13:56:44 +05302272 pNewIes = vos_mem_malloc(sizeof(tDot11fBeaconIEs));
2273 if ( NULL == pNewIes )
2274 status = eHAL_STATUS_FAILURE;
2275 else
2276 status = eHAL_STATUS_SUCCESS;
2277 if ( HAL_STATUS_SUCCESS( status ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07002278 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302279 vos_mem_copy(pNewIes, pIes, sizeof( tDot11fBeaconIEs ));
Jeff Johnson295189b2012-06-20 16:38:30 -07002280 }
2281 else
2282 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002283 smsLog(pMac, LOGE, FL(" fail to allocate memory for IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002284 //Need to free memory allocated by csrMatchBSS
2285 if( !pBssDesc->Result.pvIes )
2286 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302287 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07002288 }
2289 break;
2290 }
2291 }
2292 }//fMatch
2293 else if( !pBssDesc->Result.pvIes )
2294 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302295 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07002296 }
2297 }
2298 }
2299 if(NULL == pFilter || fMatch)
2300 {
2301 bssLen = pBssDesc->Result.BssDescriptor.length + sizeof(pBssDesc->Result.BssDescriptor.length);
2302 allocLen = sizeof( tCsrScanResult ) + bssLen;
Kiet Lam64c1b492013-07-12 13:56:44 +05302303 pResult = vos_mem_malloc(allocLen);
2304 if ( NULL == pResult )
2305 status = eHAL_STATUS_FAILURE;
2306 else
2307 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07002308 if(!HAL_STATUS_SUCCESS(status))
2309 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002310 smsLog(pMac, LOGE, FL(" fail to allocate memory for scan result, len=%d"), allocLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07002311 if(pNewIes)
2312 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302313 vos_mem_free(pNewIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07002314 }
2315 break;
2316 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302317 vos_mem_set(pResult, allocLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002318 pResult->capValue = pBssDesc->capValue;
2319 pResult->preferValue = pBssDesc->preferValue;
2320 pResult->ucEncryptionType = uc;
2321 pResult->mcEncryptionType = mc;
2322 pResult->authType = auth;
2323 pResult->Result.ssId = pBssDesc->Result.ssId;
2324 pResult->Result.timer = 0;
2325 //save the pIes for later use
2326 pResult->Result.pvIes = pNewIes;
2327 //save bss description
Kiet Lam64c1b492013-07-12 13:56:44 +05302328 vos_mem_copy(&pResult->Result.BssDescriptor,
2329 &pBssDesc->Result.BssDescriptor, bssLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07002330 //No need to lock pRetList because it is locally allocated and no outside can access it at this time
2331 if(csrLLIsListEmpty(&pRetList->List, LL_ACCESS_NOLOCK))
2332 {
2333 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_NOLOCK);
2334 }
2335 else
2336 {
2337 //To sort the list
2338 tListElem *pTmpEntry;
2339 tCsrScanResult *pTmpResult;
2340
2341 pTmpEntry = csrLLPeekHead(&pRetList->List, LL_ACCESS_NOLOCK);
2342 while(pTmpEntry)
2343 {
2344 pTmpResult = GET_BASE_ADDR( pTmpEntry, tCsrScanResult, Link );
2345 if(csrIsBetterBss(pResult, pTmpResult))
2346 {
2347 csrLLInsertEntry(&pRetList->List, pTmpEntry, &pResult->Link, LL_ACCESS_NOLOCK);
2348 //To indicate we are done
2349 pResult = NULL;
2350 break;
2351 }
2352 pTmpEntry = csrLLNext(&pRetList->List, pTmpEntry, LL_ACCESS_NOLOCK);
2353 }
2354 if(pResult != NULL)
2355 {
2356 //This one is not better than any one
2357 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_NOLOCK);
2358 }
2359 }
2360 count++;
2361 }
2362 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK );
2363 }//while
2364 csrLLUnlock(&pMac->scan.scanResultList);
2365
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002366 smsLog(pMac, LOG2, FL("return %d BSS"), csrLLCount(&pRetList->List));
Jeff Johnson295189b2012-06-20 16:38:30 -07002367
2368 if( !HAL_STATUS_SUCCESS(status) || (phResult == NULL) )
2369 {
2370 //Fail or No one wants the result.
2371 csrScanResultPurge(pMac, (tScanResultHandle)pRetList);
2372 }
2373 else
2374 {
2375 if(0 == count)
2376 {
2377 //We are here meaning the there is no match
2378 csrLLClose(&pRetList->List);
Kiet Lam64c1b492013-07-12 13:56:44 +05302379 vos_mem_free(pRetList);
Jeff Johnson295189b2012-06-20 16:38:30 -07002380 status = eHAL_STATUS_E_NULL_VALUE;
2381 }
2382 else if(phResult)
2383 {
2384 *phResult = pRetList;
2385 }
2386 }
2387 }//Allocated pRetList
2388
2389 return (status);
2390}
2391
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002392/*
2393 * NOTE: This routine is being added to make
2394 * sure that scan results are not being flushed
2395 * while roaming. If the scan results are flushed,
2396 * we are unable to recover from
2397 * csrRoamRoamingStateDisassocRspProcessor.
2398 * If it is needed to remove this routine,
2399 * first ensure that we recover gracefully from
2400 * csrRoamRoamingStateDisassocRspProcessor if
2401 * csrScanGetResult returns with a failure because
2402 * of not being able to find the roaming BSS.
2403 */
2404tANI_U8 csrScanFlushDenied(tpAniSirGlobal pMac)
2405{
2406 switch(pMac->roam.neighborRoamInfo.neighborRoamState) {
2407 case eCSR_NEIGHBOR_ROAM_STATE_REPORT_SCAN:
2408 case eCSR_NEIGHBOR_ROAM_STATE_PREAUTHENTICATING:
2409 case eCSR_NEIGHBOR_ROAM_STATE_PREAUTH_DONE:
2410 case eCSR_NEIGHBOR_ROAM_STATE_REASSOCIATING:
2411 return (pMac->roam.neighborRoamInfo.neighborRoamState);
2412 default:
2413 return 0;
2414 }
2415}
2416
Jeff Johnson295189b2012-06-20 16:38:30 -07002417eHalStatus csrScanFlushResult(tpAniSirGlobal pMac)
2418{
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002419 tANI_U8 isFlushDenied = csrScanFlushDenied(pMac);
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302420 eHalStatus status = eHAL_STATUS_SUCCESS;
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002421 if (isFlushDenied) {
2422 smsLog(pMac, LOGW, "%s: scan flush denied in roam state %d",
2423 __func__, isFlushDenied);
2424 return eHAL_STATUS_FAILURE;
2425 }
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302426 csrLLScanPurgeResult( pMac, &pMac->scan.tempScanResults );
2427 csrLLScanPurgeResult( pMac, &pMac->scan.scanResultList );
2428 return( status );
Jeff Johnson295189b2012-06-20 16:38:30 -07002429}
2430
Mukul Sharma20aa6582014-08-07 21:36:12 +05302431eHalStatus csrScanFlushSelectiveResultForBand(tpAniSirGlobal pMac, v_BOOL_t flushP2P, tSirRFBand band)
2432{
2433 eHalStatus status = eHAL_STATUS_SUCCESS;
2434 tListElem *pEntry,*pFreeElem;
2435 tCsrScanResult *pBssDesc;
2436 tDblLinkList *pList = &pMac->scan.scanResultList;
2437
2438 csrLLLock(pList);
2439
2440 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK );
2441 while( pEntry != NULL)
2442 {
2443 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2444 if( (flushP2P == vos_mem_compare( pBssDesc->Result.ssId.ssId,
2445 "DIRECT-", 7)) &&
2446 (GetRFBand(pBssDesc->Result.BssDescriptor.channelId) == band)
2447 )
2448 {
2449 pFreeElem = pEntry;
2450 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2451 csrLLRemoveEntry(pList, pFreeElem, LL_ACCESS_NOLOCK);
2452 csrFreeScanResultEntry( pMac, pBssDesc );
2453 continue;
2454 }
2455 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2456 }
2457
2458 csrLLUnlock(pList);
2459
2460 return (status);
2461}
2462
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302463eHalStatus csrScanFlushSelectiveResult(tpAniSirGlobal pMac, v_BOOL_t flushP2P)
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002464{
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302465 eHalStatus status = eHAL_STATUS_SUCCESS;
2466 tListElem *pEntry,*pFreeElem;
2467 tCsrScanResult *pBssDesc;
2468 tDblLinkList *pList = &pMac->scan.scanResultList;
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002469
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302470 csrLLLock(pList);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002471
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302472 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK );
2473 while( pEntry != NULL)
2474 {
2475 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2476 if( flushP2P == vos_mem_compare( pBssDesc->Result.ssId.ssId,
2477 "DIRECT-", 7) )
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002478 {
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302479 pFreeElem = pEntry;
2480 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2481 csrLLRemoveEntry(pList, pFreeElem, LL_ACCESS_NOLOCK);
2482 csrFreeScanResultEntry( pMac, pBssDesc );
2483 continue;
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002484 }
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302485 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2486 }
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002487
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302488 csrLLUnlock(pList);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002489
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302490 return (status);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002491}
2492
Jeff Johnson295189b2012-06-20 16:38:30 -07002493/**
2494 * csrCheck11dChannel
2495 *
2496 *FUNCTION:
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302497 * This function is called from csrScanFilterResults function and
Jeff Johnson295189b2012-06-20 16:38:30 -07002498 * compare channel number with given channel list.
2499 *
2500 *LOGIC:
2501 * Check Scan result channel number with CFG channel list
2502 *
2503 *ASSUMPTIONS:
2504 *
2505 *
2506 *NOTE:
2507 *
2508 * @param channelId channel number
2509 * @param pChannelList Pointer to channel list
2510 * @param numChannels Number of channel in channel list
2511 *
2512 * @return Status
2513 */
2514
2515eHalStatus csrCheck11dChannel(tANI_U8 channelId, tANI_U8 *pChannelList, tANI_U32 numChannels)
2516{
2517 eHalStatus status = eHAL_STATUS_FAILURE;
2518 tANI_U8 i = 0;
2519
2520 for (i = 0; i < numChannels; i++)
2521 {
2522 if(pChannelList[ i ] == channelId)
2523 {
2524 status = eHAL_STATUS_SUCCESS;
2525 break;
2526 }
2527 }
2528 return status;
2529}
2530
2531/**
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302532 * csrScanFilterResults
Jeff Johnson295189b2012-06-20 16:38:30 -07002533 *
2534 *FUNCTION:
2535 * This function is called from csrApplyCountryInformation function and
2536 * filter scan result based on valid channel list number.
2537 *
2538 *LOGIC:
2539 * Get scan result from scan list and Check Scan result channel number
2540 * with 11d channel list if channel number is found in 11d channel list
2541 * then do not remove scan result entry from scan list
2542 *
2543 *ASSUMPTIONS:
2544 *
2545 *
2546 *NOTE:
2547 *
2548 * @param pMac Pointer to Global MAC structure
2549 *
2550 * @return Status
2551 */
2552
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302553eHalStatus csrScanFilterResults(tpAniSirGlobal pMac)
Jeff Johnson295189b2012-06-20 16:38:30 -07002554{
2555 eHalStatus status = eHAL_STATUS_SUCCESS;
2556 tListElem *pEntry,*pTempEntry;
2557 tCsrScanResult *pBssDesc;
2558 tANI_U32 len = sizeof(pMac->roam.validChannelList);
2559
2560 /* Get valid channels list from CFG */
2561 if (!HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac,
2562 pMac->roam.validChannelList, &len)))
2563 {
Agarwal Ashishe3cca2a2013-07-21 03:01:48 +05302564 smsLog( pMac, LOGE, "Failed to get Channel list from CFG");
Jeff Johnson295189b2012-06-20 16:38:30 -07002565 }
2566
2567 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
2568 while( pEntry )
2569 {
2570 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302571 pTempEntry = csrLLNext( &pMac->scan.scanResultList, pEntry,
Jeff Johnson295189b2012-06-20 16:38:30 -07002572 LL_ACCESS_LOCK );
2573 if(csrCheck11dChannel(pBssDesc->Result.BssDescriptor.channelId,
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302574 pMac->roam.validChannelList, len))
Jeff Johnson295189b2012-06-20 16:38:30 -07002575 {
2576 /* Remove Scan result which does not have 11d channel */
2577 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry,
2578 LL_ACCESS_LOCK ))
2579 {
2580 csrFreeScanResultEntry( pMac, pBssDesc );
2581 }
2582 }
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302583 else
2584 {
2585 smsLog( pMac, LOG1, FL("%d is a Valid channel"),
2586 pBssDesc->Result.BssDescriptor.channelId);
2587 }
2588 pEntry = pTempEntry;
2589 }
2590
2591 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
2592 while( pEntry )
2593 {
2594 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2595 pTempEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry,
2596 LL_ACCESS_LOCK );
2597 if(csrCheck11dChannel(pBssDesc->Result.BssDescriptor.channelId,
2598 pMac->roam.validChannelList, len))
2599 {
2600 /* Remove Scan result which does not have 11d channel */
2601 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry,
2602 LL_ACCESS_LOCK ))
2603 {
2604 csrFreeScanResultEntry( pMac, pBssDesc );
2605 }
2606 }
2607 else
2608 {
2609 smsLog( pMac, LOG1, FL("%d is a Valid channel"),
2610 pBssDesc->Result.BssDescriptor.channelId);
2611 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002612 pEntry = pTempEntry;
2613 }
2614 return status;
2615}
2616
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05302617/**
2618 * csrScanFilterDFSResults
2619 *
2620 *FUNCTION:
2621 * This function filter BSSIDs on DFS channels from the scan results.
2622 *
2623 *LOGIC:
2624 * Get scan result from scan list and Check Scan result channel number
2625 * with 11d channel list if channel number is found in 11d channel list
2626 * and if fEnableDFSChnlScan is zero and if channel is DFS, then
2627 * remove scan result entry from scan list
2628 *
2629 *ASSUMPTIONS:
2630 *
2631 *NOTE:
2632 *
2633 * @param pMac Pointer to Global MAC structure
2634 *
2635 * @return Status
2636 */
2637
2638eHalStatus csrScanFilterDFSResults(tpAniSirGlobal pMac)
2639{
2640 eHalStatus status = eHAL_STATUS_SUCCESS;
2641 tListElem *pEntry,*pTempEntry;
2642 tCsrScanResult *pBssDesc;
2643
2644 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
2645 while( pEntry )
2646 {
2647 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2648 pTempEntry = csrLLNext( &pMac->scan.scanResultList, pEntry,
2649 LL_ACCESS_LOCK );
2650 if((pMac->scan.fEnableDFSChnlScan == DFS_CHNL_SCAN_DISABLED) &&
2651 CSR_IS_CHANNEL_DFS(pBssDesc->Result.BssDescriptor.channelId))
2652 {
2653 smsLog( pMac, LOG1, FL("%d is a DFS ch filtered from scan list"),
2654 pBssDesc->Result.BssDescriptor.channelId);
2655 /* Remove Scan result which does not have 11d channel */
2656 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry,
2657 LL_ACCESS_LOCK ))
2658 {
2659 csrFreeScanResultEntry( pMac, pBssDesc );
2660 }
2661 }
2662 else
2663 {
2664 smsLog( pMac, LOG1, FL("%d is a Valid channel"),
2665 pBssDesc->Result.BssDescriptor.channelId);
2666 }
2667 pEntry = pTempEntry;
2668 }
2669
2670 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
2671 while( pEntry )
2672 {
2673 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2674 pTempEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry,
2675 LL_ACCESS_LOCK );
2676
2677 if((pMac->scan.fEnableDFSChnlScan == DFS_CHNL_SCAN_DISABLED) &&
2678 CSR_IS_CHANNEL_DFS(pBssDesc->Result.BssDescriptor.channelId))
2679 {
2680 smsLog( pMac, LOG1, FL("%d is a DFS ch filtered from scan list"),
2681 pBssDesc->Result.BssDescriptor.channelId);
2682 /* Remove Scan result which does not have 11d channel */
2683 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry,
2684 LL_ACCESS_LOCK ))
2685 {
2686 csrFreeScanResultEntry( pMac, pBssDesc );
2687 }
2688 }
2689 else
2690 {
2691 smsLog( pMac, LOG1, FL("%d is a Valid channel"),
2692 pBssDesc->Result.BssDescriptor.channelId);
2693 }
2694 pEntry = pTempEntry;
2695 }
2696 return status;
2697}
2698
Jeff Johnson295189b2012-06-20 16:38:30 -07002699
2700eHalStatus csrScanCopyResultList(tpAniSirGlobal pMac, tScanResultHandle hIn, tScanResultHandle *phResult)
2701{
2702 eHalStatus status = eHAL_STATUS_SUCCESS;
2703 tScanResultList *pRetList, *pInList = (tScanResultList *)hIn;
2704 tCsrScanResult *pResult, *pScanResult;
2705 tANI_U32 count = 0;
2706 tListElem *pEntry;
2707 tANI_U32 bssLen, allocLen;
2708
2709 if(phResult)
2710 {
2711 *phResult = CSR_INVALID_SCANRESULT_HANDLE;
2712 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302713 pRetList = vos_mem_malloc(sizeof(tScanResultList));
2714 if ( NULL == pRetList )
2715 status = eHAL_STATUS_FAILURE;
2716 else
Jeff Johnson295189b2012-06-20 16:38:30 -07002717 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302718 vos_mem_set(pRetList, sizeof(tScanResultList), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002719 csrLLOpen(pMac->hHdd, &pRetList->List);
2720 pRetList->pCurEntry = NULL;
2721 csrLLLock(&pMac->scan.scanResultList);
2722 csrLLLock(&pInList->List);
2723
2724 pEntry = csrLLPeekHead( &pInList->List, LL_ACCESS_NOLOCK );
2725 while( pEntry )
2726 {
2727 pScanResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2728 bssLen = pScanResult->Result.BssDescriptor.length + sizeof(pScanResult->Result.BssDescriptor.length);
2729 allocLen = sizeof( tCsrScanResult ) + bssLen;
Kiet Lam64c1b492013-07-12 13:56:44 +05302730 pResult = vos_mem_malloc(allocLen);
2731 if ( NULL == pResult )
2732 status = eHAL_STATUS_FAILURE;
2733 else
2734 status = eHAL_STATUS_SUCCESS;
2735 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07002736 {
2737 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
2738 count = 0;
2739 break;
2740 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302741 vos_mem_set(pResult, allocLen , 0);
2742 vos_mem_copy(&pResult->Result.BssDescriptor, &pScanResult->Result.BssDescriptor, bssLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07002743 if( pScanResult->Result.pvIes )
2744 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302745 pResult->Result.pvIes = vos_mem_malloc(sizeof( tDot11fBeaconIEs ));
2746 if ( NULL == pResult->Result.pvIes )
2747 status = eHAL_STATUS_FAILURE;
2748 else
2749 status = eHAL_STATUS_SUCCESS;
2750 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07002751 {
2752 //Free the memory we allocate above first
Kiet Lam64c1b492013-07-12 13:56:44 +05302753 vos_mem_free(pResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07002754 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
2755 count = 0;
2756 break;
2757 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302758 vos_mem_copy(pResult->Result.pvIes, pScanResult->Result.pvIes,
2759 sizeof( tDot11fBeaconIEs ));
Jeff Johnson295189b2012-06-20 16:38:30 -07002760 }
2761 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_LOCK);
2762 count++;
2763 pEntry = csrLLNext( &pInList->List, pEntry, LL_ACCESS_NOLOCK );
2764 }//while
2765 csrLLUnlock(&pInList->List);
2766 csrLLUnlock(&pMac->scan.scanResultList);
2767
2768 if(HAL_STATUS_SUCCESS(status))
2769 {
2770 if(0 == count)
2771 {
2772 csrLLClose(&pRetList->List);
Kiet Lam64c1b492013-07-12 13:56:44 +05302773 vos_mem_free(pRetList);
Jeff Johnson295189b2012-06-20 16:38:30 -07002774 status = eHAL_STATUS_E_NULL_VALUE;
2775 }
2776 else if(phResult)
2777 {
2778 *phResult = pRetList;
2779 }
2780 }
2781 }//Allocated pRetList
2782
2783 return (status);
2784}
2785
2786
2787
2788eHalStatus csrScanningStateMsgProcessor( tpAniSirGlobal pMac, void *pMsgBuf )
2789{
2790 eHalStatus status = eHAL_STATUS_SUCCESS;
2791 tSirMbMsg *pMsg = (tSirMbMsg *)pMsgBuf;
2792
2793 if((eWNI_SME_SCAN_RSP == pMsg->type) || (eWNI_SME_GET_SCANNED_CHANNEL_RSP == pMsg->type))
2794 {
2795 status = csrScanSmeScanResponse( pMac, pMsgBuf );
2796 }
2797 else
2798 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002799 if(pMsg->type == eWNI_SME_UPPER_LAYER_ASSOC_CNF)
Jeff Johnson295189b2012-06-20 16:38:30 -07002800 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002801 tCsrRoamSession *pSession;
2802 tSirSmeAssocIndToUpperLayerCnf *pUpperLayerAssocCnf;
2803 tCsrRoamInfo roamInfo;
2804 tCsrRoamInfo *pRoamInfo = NULL;
2805 tANI_U32 sessionId;
2806 eHalStatus status;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002807 smsLog( pMac, LOG1, FL("Scanning : ASSOCIATION confirmation can be given to upper layer "));
Kiet Lam64c1b492013-07-12 13:56:44 +05302808 vos_mem_set(&roamInfo, sizeof(tCsrRoamInfo), 0);
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002809 pRoamInfo = &roamInfo;
2810 pUpperLayerAssocCnf = (tSirSmeAssocIndToUpperLayerCnf *)pMsgBuf;
2811 status = csrRoamGetSessionIdFromBSSID( pMac, (tCsrBssid *)pUpperLayerAssocCnf->bssId, &sessionId );
2812 pSession = CSR_GET_SESSION(pMac, sessionId);
2813
2814 if(!pSession)
2815 {
2816 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
2817 return eHAL_STATUS_FAILURE;
2818 }
2819
2820 pRoamInfo->statusCode = eSIR_SME_SUCCESS; //send the status code as Success
2821 pRoamInfo->u.pConnectedProfile = &pSession->connectedProfile;
2822 pRoamInfo->staId = (tANI_U8)pUpperLayerAssocCnf->aid;
2823 pRoamInfo->rsnIELen = (tANI_U8)pUpperLayerAssocCnf->rsnIE.length;
2824 pRoamInfo->prsnIE = pUpperLayerAssocCnf->rsnIE.rsnIEdata;
2825 pRoamInfo->addIELen = (tANI_U8)pUpperLayerAssocCnf->addIE.length;
2826 pRoamInfo->paddIE = pUpperLayerAssocCnf->addIE.addIEdata;
Kiet Lam64c1b492013-07-12 13:56:44 +05302827 vos_mem_copy(pRoamInfo->peerMac, pUpperLayerAssocCnf->peerMacAddr, sizeof(tSirMacAddr));
2828 vos_mem_copy(&pRoamInfo->bssid, pUpperLayerAssocCnf->bssId, sizeof(tCsrBssid));
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002829 pRoamInfo->wmmEnabledSta = pUpperLayerAssocCnf->wmmEnabledSta;
Hardik Kantilal Patel1ba630f2014-11-21 04:32:05 +05302830#ifdef WLAN_FEATURE_AP_HT40_24G
2831 pRoamInfo->HT40MHzIntoEnabledSta =
2832 pUpperLayerAssocCnf->HT40MHzIntoEnabledSta;
2833#endif
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002834 if(CSR_IS_INFRA_AP(pRoamInfo->u.pConnectedProfile) )
2835 {
2836 pMac->roam.roamSession[sessionId].connectState = eCSR_ASSOC_STATE_TYPE_INFRA_CONNECTED;
2837 pRoamInfo->fReassocReq = pUpperLayerAssocCnf->reassocReq;
2838 status = csrRoamCallCallback(pMac, sessionId, pRoamInfo, 0, eCSR_ROAM_INFRA_IND, eCSR_ROAM_RESULT_INFRA_ASSOCIATION_CNF);
2839 }
2840 if(CSR_IS_WDS_AP( pRoamInfo->u.pConnectedProfile))
2841 {
2842 vos_sleep( 100 );
2843 pMac->roam.roamSession[sessionId].connectState = eCSR_ASSOC_STATE_TYPE_WDS_CONNECTED;//Sta
2844 status = csrRoamCallCallback(pMac, sessionId, pRoamInfo, 0, eCSR_ROAM_WDS_IND, eCSR_ROAM_RESULT_WDS_ASSOCIATION_IND);//Sta
2845 }
2846
Jeff Johnson295189b2012-06-20 16:38:30 -07002847 }
2848 else
2849 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002850
2851 if( csrIsAnySessionInConnectState( pMac ) )
2852 {
2853 //In case of we are connected, we need to check whether connect status changes
2854 //because scan may also run while connected.
2855 csrRoamCheckForLinkStatusChange( pMac, ( tSirSmeRsp * )pMsgBuf );
2856 }
2857 else
2858 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002859 smsLog( pMac, LOGW, "Message [0x%04x] received in state, when expecting Scan Response", pMsg->type );
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002860 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002861 }
2862 }
2863
2864 return (status);
2865}
2866
2867
2868
2869void csrCheckNSaveWscIe(tpAniSirGlobal pMac, tSirBssDescription *pNewBssDescr, tSirBssDescription *pOldBssDescr)
2870{
2871 int idx, len;
2872 tANI_U8 *pbIe;
2873
2874 //If failed to remove, assuming someone else got it.
2875 if((pNewBssDescr->fProbeRsp != pOldBssDescr->fProbeRsp) &&
2876 (0 == pNewBssDescr->WscIeLen))
2877 {
2878 idx = 0;
2879 len = pOldBssDescr->length - sizeof(tSirBssDescription) +
2880 sizeof(tANI_U16) + sizeof(tANI_U32) - DOT11F_IE_WSCPROBERES_MIN_LEN - 2;
2881 pbIe = (tANI_U8 *)pOldBssDescr->ieFields;
2882 //Save WPS IE if it exists
2883 pNewBssDescr->WscIeLen = 0;
2884 while(idx < len)
2885 {
2886 if((DOT11F_EID_WSCPROBERES == pbIe[0]) &&
2887 (0x00 == pbIe[2]) && (0x50 == pbIe[3]) && (0xf2 == pbIe[4]) && (0x04 == pbIe[5]))
2888 {
2889 //Founrd it
2890 if((DOT11F_IE_WSCPROBERES_MAX_LEN - 2) >= pbIe[1])
2891 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302892 vos_mem_copy(pNewBssDescr->WscIeProbeRsp, pbIe, pbIe[1] + 2);
Jeff Johnson295189b2012-06-20 16:38:30 -07002893 pNewBssDescr->WscIeLen = pbIe[1] + 2;
2894 }
2895 break;
2896 }
2897 idx += pbIe[1] + 2;
2898 pbIe += pbIe[1] + 2;
2899 }
2900 }
2901}
2902
2903
2904
2905//pIes may be NULL
2906tANI_BOOLEAN csrRemoveDupBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDescr,
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05302907 tDot11fBeaconIEs *pIes, tAniSSID *pSsid, v_TIME_t *timer, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07002908{
2909 tListElem *pEntry;
2910
2911 tCsrScanResult *pBssDesc;
2912 tANI_BOOLEAN fRC = FALSE;
2913
2914 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
2915 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
2916 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
2917 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
2918
2919 while( pEntry )
2920 {
2921 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2922
2923 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
2924 // matches
2925 if ( csrIsDuplicateBssDescription( pMac, &pBssDesc->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07002926 pSirBssDescr, pIes, fForced ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07002927 {
2928 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
2929 ((tANI_S32)pBssDesc->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
2930 // Remove the 'old' entry from the list....
2931 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry, LL_ACCESS_LOCK ) )
2932 {
2933 // !we need to free the memory associated with this node
2934 //If failed to remove, assuming someone else got it.
2935 *pSsid = pBssDesc->Result.ssId;
2936 *timer = pBssDesc->Result.timer;
2937 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pBssDesc->Result.BssDescriptor);
2938
2939 csrFreeScanResultEntry( pMac, pBssDesc );
2940 }
2941 else
2942 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002943 smsLog( pMac, LOGW, FL( " fail to remove entry" ) );
Jeff Johnson295189b2012-06-20 16:38:30 -07002944 }
2945 fRC = TRUE;
2946
2947 // If we found a match, we can stop looking through the list.
2948 break;
2949 }
2950
2951 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_LOCK );
2952 }
2953
2954 return fRC;
2955}
2956
2957
2958eHalStatus csrAddPMKIDCandidateList( tpAniSirGlobal pMac, tANI_U32 sessionId,
2959 tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes )
2960{
2961 eHalStatus status = eHAL_STATUS_FAILURE;
2962 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
2963
Jeff Johnson32d95a32012-09-10 13:15:23 -07002964 if(!pSession)
2965 {
2966 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
2967 return eHAL_STATUS_FAILURE;
2968 }
2969
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002970 smsLog(pMac, LOGW, "csrAddPMKIDCandidateList called pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07002971 if( pIes )
2972 {
2973 // check if this is a RSN BSS
2974 if( pIes->RSN.present )
2975 {
2976 // Check if the BSS is capable of doing pre-authentication
2977 if( pSession->NumPmkidCandidate < CSR_MAX_PMKID_ALLOWED )
2978 {
2979
2980#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
2981 {
2982 WLAN_VOS_DIAG_EVENT_DEF(secEvent, vos_event_wlan_security_payload_type);
Kiet Lam64c1b492013-07-12 13:56:44 +05302983 vos_mem_set(&secEvent, sizeof(vos_event_wlan_security_payload_type), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002984 secEvent.eventId = WLAN_SECURITY_EVENT_PMKID_CANDIDATE_FOUND;
2985 secEvent.encryptionModeMulticast =
2986 (v_U8_t)diagEncTypeFromCSRType(pSession->connectedProfile.mcEncryptionType);
2987 secEvent.encryptionModeUnicast =
2988 (v_U8_t)diagEncTypeFromCSRType(pSession->connectedProfile.EncryptionType);
Kiet Lam64c1b492013-07-12 13:56:44 +05302989 vos_mem_copy(secEvent.bssid, pSession->connectedProfile.bssid, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07002990 secEvent.authMode =
2991 (v_U8_t)diagAuthTypeFromCSRType(pSession->connectedProfile.AuthType);
2992 WLAN_VOS_DIAG_EVENT_REPORT(&secEvent, EVENT_WLAN_SECURITY);
2993 }
2994#endif//#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
2995
2996 // if yes, then add to PMKIDCandidateList
Kiet Lam64c1b492013-07-12 13:56:44 +05302997 vos_mem_copy(pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].BSSID,
2998 pBssDesc->bssId, WNI_CFG_BSSID_LEN);
2999 // Bit 0 offirst byte - PreAuthentication Capability
3000 if ( (pIes->RSN.RSN_Cap[0] >> 0) & 0x1 )
Jeff Johnson295189b2012-06-20 16:38:30 -07003001 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303002 pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].preAuthSupported
3003 = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003004 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303005 else
3006 {
3007 pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].preAuthSupported
3008 = eANI_BOOLEAN_FALSE;
3009 }
3010 pSession->NumPmkidCandidate++;
Jeff Johnson295189b2012-06-20 16:38:30 -07003011 }
3012 else
3013 {
3014 status = eHAL_STATUS_FAILURE;
3015 }
3016 }
3017 }
3018
3019 return (status);
3020}
3021
3022//This function checks whether new AP is found for the current connected profile
3023//If it is found, it return the sessionId, else it return invalid sessionID
3024tANI_U32 csrProcessBSSDescForPMKIDList(tpAniSirGlobal pMac,
3025 tSirBssDescription *pBssDesc,
3026 tDot11fBeaconIEs *pIes)
3027{
3028 tANI_U32 i, bRet = CSR_SESSION_ID_INVALID;
3029 tCsrRoamSession *pSession;
3030 tDot11fBeaconIEs *pIesLocal = pIes;
3031
3032 if( pIesLocal || HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIesLocal)) )
3033 {
3034 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
3035 {
3036 if( CSR_IS_SESSION_VALID( pMac, i ) )
3037 {
3038 pSession = CSR_GET_SESSION( pMac, i );
3039 if( csrIsConnStateConnectedInfra( pMac, i ) &&
3040 ( eCSR_AUTH_TYPE_RSN == pSession->connectedProfile.AuthType ) )
3041 {
3042 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile, pBssDesc, pIesLocal))
3043 {
3044 //this new BSS fits the current profile connected
3045 if(HAL_STATUS_SUCCESS(csrAddPMKIDCandidateList(pMac, i, pBssDesc, pIesLocal)))
3046 {
3047 bRet = i;
3048 }
3049 break;
3050 }
3051 }
3052 }
3053 }
3054 if( !pIes )
3055 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303056 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003057 }
3058 }
3059
3060 return (tANI_U8)bRet;
3061}
3062
3063#ifdef FEATURE_WLAN_WAPI
3064eHalStatus csrAddBKIDCandidateList( tpAniSirGlobal pMac, tANI_U32 sessionId,
3065 tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes )
3066{
3067 eHalStatus status = eHAL_STATUS_FAILURE;
3068 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
3069
Jeff Johnson32d95a32012-09-10 13:15:23 -07003070 if(!pSession)
3071 {
3072 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
3073 return eHAL_STATUS_FAILURE;
3074 }
3075
Kiet Lam64c1b492013-07-12 13:56:44 +05303076 smsLog(pMac, LOGW, "csrAddBKIDCandidateList called pMac->scan.NumBkidCandidate = %d",
3077 pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07003078 if( pIes )
3079 {
3080 // check if this is a WAPI BSS
3081 if( pIes->WAPI.present )
3082 {
3083 // Check if the BSS is capable of doing pre-authentication
3084 if( pSession->NumBkidCandidate < CSR_MAX_BKID_ALLOWED )
3085 {
3086
3087 // if yes, then add to BKIDCandidateList
Kiet Lam64c1b492013-07-12 13:56:44 +05303088 vos_mem_copy(pSession->BkidCandidateInfo[pSession->NumBkidCandidate].BSSID,
3089 pBssDesc->bssId, WNI_CFG_BSSID_LEN);
3090 if ( pIes->WAPI.preauth )
Jeff Johnson295189b2012-06-20 16:38:30 -07003091 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303092 pSession->BkidCandidateInfo[pSession->NumBkidCandidate].preAuthSupported
3093 = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003094 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303095 else
3096 {
3097 pSession->BkidCandidateInfo[pSession->NumBkidCandidate].preAuthSupported
3098 = eANI_BOOLEAN_FALSE;
3099 }
3100 pSession->NumBkidCandidate++;
Jeff Johnson295189b2012-06-20 16:38:30 -07003101 }
3102 else
3103 {
3104 status = eHAL_STATUS_FAILURE;
3105 }
3106 }
3107 }
3108
3109 return (status);
3110}
3111
3112//This function checks whether new AP is found for the current connected profile
3113//if so add to BKIDCandidateList
3114tANI_BOOLEAN csrProcessBSSDescForBKIDList(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
3115 tDot11fBeaconIEs *pIes)
3116{
3117 tANI_BOOLEAN fRC = FALSE;
3118 tDot11fBeaconIEs *pIesLocal = pIes;
3119 tANI_U32 sessionId;
3120 tCsrRoamSession *pSession;
3121
3122 if( pIesLocal || HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIesLocal)) )
3123 {
3124 for( sessionId = 0; sessionId < CSR_ROAM_SESSION_MAX; sessionId++ )
3125 {
3126 if( CSR_IS_SESSION_VALID( pMac, sessionId) )
3127 {
3128 pSession = CSR_GET_SESSION( pMac, sessionId );
3129 if( csrIsConnStateConnectedInfra( pMac, sessionId ) &&
3130 eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE == pSession->connectedProfile.AuthType)
3131 {
3132 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile,pBssDesc, pIesLocal))
3133 {
3134 //this new BSS fits the current profile connected
3135 if(HAL_STATUS_SUCCESS(csrAddBKIDCandidateList(pMac, sessionId, pBssDesc, pIesLocal)))
3136 {
3137 fRC = TRUE;
3138 }
3139 }
3140 }
3141 }
3142 }
3143 if(!pIes)
3144 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303145 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003146 }
3147
3148 }
3149 return fRC;
3150}
3151
3152#endif
3153
3154
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07003155static void csrMoveTempScanResultsToMainList( tpAniSirGlobal pMac, tANI_U8 reason )
Jeff Johnson295189b2012-06-20 16:38:30 -07003156{
3157 tListElem *pEntry;
3158 tCsrScanResult *pBssDescription;
Jeff Johnson295189b2012-06-20 16:38:30 -07003159 tANI_BOOLEAN fDupBss;
3160#ifdef FEATURE_WLAN_WAPI
3161 tANI_BOOLEAN fNewWapiBSSForCurConnection = eANI_BOOLEAN_FALSE;
3162#endif /* FEATURE_WLAN_WAPI */
3163 tDot11fBeaconIEs *pIesLocal = NULL;
3164 tANI_U32 sessionId = CSR_SESSION_ID_INVALID;
3165 tAniSSID tmpSsid;
3166 v_TIME_t timer=0;
3167
3168 tmpSsid.length = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07003169
3170 // remove the BSS descriptions from temporary list
3171 while( ( pEntry = csrLLRemoveTail( &pMac->scan.tempScanResults, LL_ACCESS_LOCK ) ) != NULL)
3172 {
3173 pBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3174
Vinay Krishna Eranna566365f2015-03-09 12:34:13 +05303175 smsLog( pMac, LOG2, "...Bssid= "MAC_ADDRESS_STR" chan= %d, rssi = -%d",
Arif Hussain24bafea2013-11-15 15:10:03 -08003176 MAC_ADDR_ARRAY(pBssDescription->Result.BssDescriptor.bssId),
Jeff Johnson295189b2012-06-20 16:38:30 -07003177 pBssDescription->Result.BssDescriptor.channelId,
3178 pBssDescription->Result.BssDescriptor.rssi * (-1) );
3179
3180 //At this time, pBssDescription->Result.pvIes may be NULL
3181 pIesLocal = (tDot11fBeaconIEs *)( pBssDescription->Result.pvIes );
3182 if( !pIesLocal && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pBssDescription->Result.BssDescriptor, &pIesLocal))) )
3183 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003184 smsLog(pMac, LOGE, FL(" Cannot pared IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003185 csrFreeScanResultEntry(pMac, pBssDescription);
3186 continue;
3187 }
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05303188 fDupBss = csrRemoveDupBssDescription( pMac, &pBssDescription->Result.BssDescriptor, pIesLocal, &tmpSsid, &timer, FALSE );
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07003189 //Check whether we have reach out limit, but don't lose the LFR candidates came from FW
3190 if( CSR_SCAN_IS_OVER_BSS_LIMIT(pMac)
3191#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
3192 && !( eCsrScanGetLfrResult == reason )
3193#endif
3194 )
Jeff Johnson295189b2012-06-20 16:38:30 -07003195 {
3196 //Limit reach
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003197 smsLog(pMac, LOGW, FL(" BSS limit reached"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003198 //Free the resources
3199 if( (pBssDescription->Result.pvIes == NULL) && pIesLocal )
3200 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303201 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003202 }
3203 csrFreeScanResultEntry(pMac, pBssDescription);
3204 //Continue because there may be duplicated BSS
3205 continue;
3206 }
3207 // check for duplicate scan results
3208 if ( !fDupBss )
3209 {
3210 //Found a new BSS
3211 sessionId = csrProcessBSSDescForPMKIDList(pMac,
3212 &pBssDescription->Result.BssDescriptor, pIesLocal);
3213 if( CSR_SESSION_ID_INVALID != sessionId)
3214 {
3215 csrRoamCallCallback(pMac, sessionId, NULL, 0,
3216 eCSR_ROAM_SCAN_FOUND_NEW_BSS, eCSR_ROAM_RESULT_NONE);
3217 }
3218 }
3219 else
3220 {
3221 //Check if the new one has SSID it it, if not, use the older SSID if it exists.
3222 if( (0 == pBssDescription->Result.ssId.length) && tmpSsid.length )
3223 {
3224 //New BSS has a hidden SSID and old one has the SSID. Keep the SSID only
3225 //if diff of saved SSID time and current time is less than 1 min to avoid
3226 //side effect of saving SSID with old one is that if AP changes its SSID while remain
3227 //hidden, we may never see it and also to address the requirement of
3228 //When we remove hidden ssid from the profile i.e., forget the SSID via
3229 // GUI that SSID shouldn't see in the profile
3230 if( (vos_timer_get_system_time() - timer) <= HIDDEN_TIMER)
3231 {
3232 pBssDescription->Result.timer = timer;
3233 pBssDescription->Result.ssId = tmpSsid;
3234 }
3235 }
3236 }
3237
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303238 //Find a good AP for 11d info
3239 if ( csrIs11dSupported( pMac ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003240 {
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303241 // check if country information element is present
3242 if (pIesLocal->Country.present)
Jeff Johnson295189b2012-06-20 16:38:30 -07003243 {
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303244 csrAddVoteForCountryInfo(pMac, pIesLocal->Country.country);
3245 smsLog(pMac, LOGW, FL("11d AP Bssid " MAC_ADDRESS_STR
3246 " chan= %d, rssi = -%d, countryCode %c%c"),
3247 MAC_ADDR_ARRAY( pBssDescription->Result.BssDescriptor.bssId),
3248 pBssDescription->Result.BssDescriptor.channelId,
3249 pBssDescription->Result.BssDescriptor.rssi * (-1),
3250 pIesLocal->Country.country[0],pIesLocal->Country.country[1] );
3251 }
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303252
Jeff Johnson295189b2012-06-20 16:38:30 -07003253 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08003254
Jeff Johnson295189b2012-06-20 16:38:30 -07003255 // append to main list
3256 csrScanAddResult(pMac, pBssDescription, pIesLocal);
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303257 if ( (pBssDescription->Result.pvIes == NULL) && pIesLocal )
Jeff Johnson295189b2012-06-20 16:38:30 -07003258 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303259 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003260 }
3261 }
3262
Sushant Kaushik6274de62015-05-01 16:31:23 +05303263 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
3264 if (pEntry && 0 != pMac->scan.scanResultCfgAgingTime)
3265 csrScanStartResultCfgAgingTimer(pMac);
Tushnim Bhattacharyyaae317772013-10-23 18:55:38 -07003266 //we don't need to update CC while connected to an AP which is advertising CC already
3267 if (csrIs11dSupported(pMac))
3268 {
3269 tANI_U32 i;
3270 tCsrRoamSession *pSession;
3271
3272 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
3273 {
3274 if (CSR_IS_SESSION_VALID( pMac, i ) )
3275 {
3276 pSession = CSR_GET_SESSION( pMac, i );
3277 if (csrIsConnStateConnected(pMac, i))
3278 {
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303279 smsLog(pMac, LOGW, FL("No need for updating CC in"
3280 "connected state"));
3281 goto end;
Tushnim Bhattacharyyaae317772013-10-23 18:55:38 -07003282 }
3283 }
3284 }
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303285 csrElectedCountryInfo(pMac);
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05303286 csrLearnCountryInformation( pMac, NULL, NULL, eANI_BOOLEAN_TRUE );
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303287 }
3288
Tushnim Bhattacharyyaae317772013-10-23 18:55:38 -07003289end:
3290 //If we can find the current 11d info in any of the scan results, or
Jeff Johnson295189b2012-06-20 16:38:30 -07003291 // a good enough AP with the 11d info from the scan results then no need to
3292 // get into ambiguous state
3293 if(pMac->scan.fAmbiguous11dInfoFound)
3294 {
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303295 if((pMac->scan.fCurrent11dInfoMatch))
Jeff Johnson295189b2012-06-20 16:38:30 -07003296 {
3297 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
3298 }
3299 }
3300
3301#ifdef FEATURE_WLAN_WAPI
3302 if(fNewWapiBSSForCurConnection)
3303 {
3304 //remember it first
3305 csrRoamCallCallback(pMac, sessionId, NULL, 0, eCSR_ROAM_SCAN_FOUND_NEW_BSS, eCSR_ROAM_RESULT_NEW_WAPI_BSS);
3306 }
3307#endif /* FEATURE_WLAN_WAPI */
3308
3309 return;
3310}
3311
3312
3313static tCsrScanResult *csrScanSaveBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pBSSDescription,
3314 tDot11fBeaconIEs *pIes)
3315{
3316 tCsrScanResult *pCsrBssDescription = NULL;
3317 tANI_U32 cbBSSDesc;
3318 tANI_U32 cbAllocated;
Sushant Kaushik6274de62015-05-01 16:31:23 +05303319 tListElem *pEntry;
Jeff Johnson295189b2012-06-20 16:38:30 -07003320
3321 // figure out how big the BSS description is (the BSSDesc->length does NOT
3322 // include the size of the length field itself).
3323 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
3324
3325 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
3326
Kiet Lam64c1b492013-07-12 13:56:44 +05303327 pCsrBssDescription = vos_mem_malloc(cbAllocated);
3328 if ( NULL != pCsrBssDescription )
Jeff Johnson295189b2012-06-20 16:38:30 -07003329 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303330 vos_mem_set(pCsrBssDescription, cbAllocated, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003331 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Kiet Lam64c1b492013-07-12 13:56:44 +05303332 vos_mem_copy(&pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc);
Jeff Johnson295189b2012-06-20 16:38:30 -07003333#if defined(VOSS_ENSBALED)
3334 VOS_ASSERT( pCsrBssDescription->Result.pvIes == NULL );
3335#endif
3336 csrScanAddResult(pMac, pCsrBssDescription, pIes);
Sushant Kaushik6274de62015-05-01 16:31:23 +05303337 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
3338 if (pEntry && 0 != pMac->scan.scanResultCfgAgingTime)
3339 csrScanStartResultCfgAgingTimer(pMac);
3340
Jeff Johnson295189b2012-06-20 16:38:30 -07003341 }
3342
3343 return( pCsrBssDescription );
3344}
3345
3346// Append a Bss Description...
3347tCsrScanResult *csrScanAppendBssDescription( tpAniSirGlobal pMac,
3348 tSirBssDescription *pSirBssDescription,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07003349 tDot11fBeaconIEs *pIes, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07003350{
3351 tCsrScanResult *pCsrBssDescription = NULL;
3352 tAniSSID tmpSsid;
3353 v_TIME_t timer = 0;
3354 int result;
3355
3356 tmpSsid.length = 0;
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07003357 result = csrRemoveDupBssDescription( pMac, pSirBssDescription, pIes, &tmpSsid, &timer, fForced );
Jeff Johnson295189b2012-06-20 16:38:30 -07003358 pCsrBssDescription = csrScanSaveBssDescription( pMac, pSirBssDescription, pIes );
3359 if (result && (pCsrBssDescription != NULL))
3360 {
3361 //Check if the new one has SSID it it, if not, use the older SSID if it exists.
3362 if( (0 == pCsrBssDescription->Result.ssId.length) && tmpSsid.length )
3363 {
3364 //New BSS has a hidden SSID and old one has the SSID. Keep the SSID only
3365 //if diff of saved SSID time and current time is less than 1 min to avoid
3366 //side effect of saving SSID with old one is that if AP changes its SSID while remain
3367 //hidden, we may never see it and also to address the requirement of
3368 //When we remove hidden ssid from the profile i.e., forget the SSID via
3369 // GUI that SSID shouldn't see in the profile
3370 if((vos_timer_get_system_time()-timer) <= HIDDEN_TIMER)
3371 {
3372 pCsrBssDescription->Result.ssId = tmpSsid;
3373 pCsrBssDescription->Result.timer = timer;
3374 }
3375 }
3376 }
3377
3378
3379 return( pCsrBssDescription );
3380}
3381
3382
3383
3384void csrPurgeChannelPower( tpAniSirGlobal pMac, tDblLinkList *pChannelList )
3385{
3386 tCsrChannelPowerInfo *pChannelSet;
3387 tListElem *pEntry;
3388
3389 csrLLLock(pChannelList);
3390 // Remove the channel sets from the learned list and put them in the free list
3391 while( ( pEntry = csrLLRemoveHead( pChannelList, LL_ACCESS_NOLOCK ) ) != NULL)
3392 {
3393 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3394 if( pChannelSet )
3395 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303396 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003397 }
3398 }
3399 csrLLUnlock(pChannelList);
3400 return;
3401}
3402
3403
3404/*
3405 * Save the channelList into the ultimate storage as the final stage of channel
3406 * Input: pCountryInfo -- the country code (e.g. "USI"), channel list, and power limit are all stored inside this data structure
3407 */
Jeff Johnsone7245742012-09-05 17:12:55 -07003408eHalStatus csrSaveToChannelPower2G_5G( tpAniSirGlobal pMac, tANI_U32 tableSize, tSirMacChanInfo *channelTable )
Jeff Johnson295189b2012-06-20 16:38:30 -07003409{
3410 tANI_U32 i = tableSize / sizeof( tSirMacChanInfo );
3411 tSirMacChanInfo *pChannelInfo;
3412 tCsrChannelPowerInfo *pChannelSet;
3413 tANI_BOOLEAN f2GHzInfoFound = FALSE;
3414 tANI_BOOLEAN f2GListPurged = FALSE, f5GListPurged = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003415
3416 pChannelInfo = channelTable;
3417 // atleast 3 bytes have to be remaining -- from "countryString"
3418 while ( i-- )
3419 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303420 pChannelSet = vos_mem_malloc(sizeof(tCsrChannelPowerInfo));
3421 if ( NULL != pChannelSet )
Jeff Johnson295189b2012-06-20 16:38:30 -07003422 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303423 vos_mem_set(pChannelSet, sizeof(tCsrChannelPowerInfo), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003424 pChannelSet->firstChannel = pChannelInfo->firstChanNum;
3425 pChannelSet->numChannels = pChannelInfo->numChannels;
3426
3427 // Now set the inter-channel offset based on the frequency band the channel set lies in
Jeff Johnsone7245742012-09-05 17:12:55 -07003428 if( (CSR_IS_CHANNEL_24GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003429 ((pChannelSet->firstChannel + (pChannelSet->numChannels - 1)) <= CSR_MAX_24GHz_CHANNEL_NUMBER) )
Jeff Johnsone7245742012-09-05 17:12:55 -07003430
Jeff Johnson295189b2012-06-20 16:38:30 -07003431 {
3432 pChannelSet->interChannelOffset = 1;
3433 f2GHzInfoFound = TRUE;
3434 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003435 else if ( (CSR_IS_CHANNEL_5GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003436 ((pChannelSet->firstChannel + ((pChannelSet->numChannels - 1) * 4)) <= CSR_MAX_5GHz_CHANNEL_NUMBER) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003437 {
3438 pChannelSet->interChannelOffset = 4;
3439 f2GHzInfoFound = FALSE;
3440 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003441 else
3442 {
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003443 smsLog( pMac, LOGW, FL("Invalid Channel %d Present in Country IE"),
Jeff Johnsone7245742012-09-05 17:12:55 -07003444 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303445 vos_mem_free(pChannelSet);
Jeff Johnsone7245742012-09-05 17:12:55 -07003446 return eHAL_STATUS_FAILURE;
3447 }
3448
Jeff Johnson295189b2012-06-20 16:38:30 -07003449 pChannelSet->txPower = CSR_ROAM_MIN( pChannelInfo->maxTxPower, pMac->roam.configParam.nTxPowerCap );
3450
3451 if( f2GHzInfoFound )
3452 {
3453 if( !f2GListPurged )
3454 {
3455 // purge previous results if found new
3456 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList24 );
3457 f2GListPurged = TRUE;
3458 }
3459
3460 if(CSR_IS_OPERATING_BG_BAND(pMac))
3461 {
3462 // add to the list of 2.4 GHz channel sets
3463 csrLLInsertTail( &pMac->scan.channelPowerInfoList24, &pChannelSet->link, LL_ACCESS_LOCK );
3464 }
3465 else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003466 smsLog( pMac, LOGW, FL("Adding 11B/G channels in 11A mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003467 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303468 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003469 }
3470 }
3471 else
3472 {
3473 // 5GHz info found
3474 if( !f5GListPurged )
3475 {
3476 // purge previous results if found new
3477 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList5G );
3478 f5GListPurged = TRUE;
3479 }
3480
3481 if(CSR_IS_OPERATING_A_BAND(pMac))
3482 {
3483 // add to the list of 5GHz channel sets
3484 csrLLInsertTail( &pMac->scan.channelPowerInfoList5G, &pChannelSet->link, LL_ACCESS_LOCK );
3485 }
3486 else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003487 smsLog( pMac, LOGW, FL("Adding 11A channels in B/G mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003488 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303489 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003490 }
3491 }
3492 }
3493
3494 pChannelInfo++; // move to next entry
3495 }
3496
Jeff Johnsone7245742012-09-05 17:12:55 -07003497 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07003498}
3499
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303500static void csrClearDfsChannelList( tpAniSirGlobal pMac )
3501{
3502 tSirMbMsg *pMsg;
3503 tANI_U16 msgLen;
Jeff Johnson295189b2012-06-20 16:38:30 -07003504
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303505 msgLen = (tANI_U16)(sizeof( tSirMbMsg ));
Kiet Lam64c1b492013-07-12 13:56:44 +05303506 pMsg = vos_mem_malloc(msgLen);
3507 if ( NULL != pMsg )
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303508 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303509 vos_mem_set((void *)pMsg, msgLen, 0);
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303510 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_CLEAR_DFS_CHANNEL_LIST);
3511 pMsg->msgLen = pal_cpu_to_be16(msgLen);
3512 palSendMBMessage(pMac->hHdd, pMsg);
3513 }
3514}
Jeff Johnson295189b2012-06-20 16:38:30 -07003515
3516void csrApplyPower2Current( tpAniSirGlobal pMac )
3517{
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003518 smsLog( pMac, LOG3, FL(" Updating Cfg with power settings"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003519 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList24, WNI_CFG_MAX_TX_POWER_2_4 );
3520 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList5G, WNI_CFG_MAX_TX_POWER_5 );
3521}
3522
3523
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003524void csrApplyChannelPowerCountryInfo( tpAniSirGlobal pMac, tCsrChannel *pChannelList, tANI_U8 *countryCode, tANI_BOOLEAN updateRiva)
Jeff Johnson295189b2012-06-20 16:38:30 -07003525{
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303526 int i, j, count, countryIndex = -1;
Jeff Johnson295189b2012-06-20 16:38:30 -07003527 tANI_U8 numChannels = 0;
3528 tANI_U8 tempNumChannels = 0;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303529 tANI_U8 channelIgnore = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003530 tCsrChannel ChannelList;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303531
Jeff Johnson295189b2012-06-20 16:38:30 -07003532 if( pChannelList->numChannels )
3533 {
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303534 for(count=0; count < MAX_COUNTRY_IGNORE; count++)
3535 {
3536 if(vos_mem_compare(countryCode, countryIgnoreList[count].countryCode,
3537 VOS_COUNTRY_CODE_LEN))
3538 {
3539 countryIndex = count;
3540 break;
3541 }
3542 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003543 tempNumChannels = CSR_MIN(pChannelList->numChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN);
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05303544
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303545 for(i=0; i < tempNumChannels; i++)
Jeff Johnson295189b2012-06-20 16:38:30 -07003546 {
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303547 channelIgnore = FALSE;
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05303548 if( countryIndex != -1 )
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303549 {
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05303550 for(j=0; j < countryIgnoreList[countryIndex].channelCount; j++)
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303551 {
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05303552 if( pChannelList->channelList[i] ==
3553 countryIgnoreList[countryIndex].channelList[j] )
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303554 {
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05303555 channelIgnore = TRUE;
3556 break;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303557 }
3558 }
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05303559 }
3560 if( FALSE == channelIgnore )
3561 {
3562 ChannelList.channelList[numChannels] = pChannelList->channelList[i];
3563 numChannels++;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303564 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003565 }
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303566 ChannelList.numChannels = numChannels;
Mahesh A Saptasagar1ed59582014-06-04 18:45:07 +05303567 csrApplyPower2Current( pMac ); // Store the channel+power info in the global place: Cfg
Jeff Johnson295189b2012-06-20 16:38:30 -07003568 csrSetCfgValidChannelList(pMac, ChannelList.channelList, ChannelList.numChannels);
3569 // extend scan capability
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303570 // build a scan list based on the channel list : channel# + active/passive scan
3571 csrSetCfgScanControlList(pMac, countryCode, &ChannelList);
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303572 /*Send msg to Lim to clear DFS channel list */
3573 csrClearDfsChannelList(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07003574#ifdef FEATURE_WLAN_SCAN_PNO
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003575 if (updateRiva)
3576 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003577 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO, FL(" Sending 11d PNO info to Riva"));
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003578 // Send HAL UpdateScanParams message
3579 pmcUpdateScanParams(pMac, &(pMac->roam.configParam), &ChannelList, TRUE);
3580 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003581#endif // FEATURE_WLAN_SCAN_PNO
3582 }
3583 else
3584 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003585 smsLog( pMac, LOGE, FL(" 11D channel list is empty"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003586 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003587 csrSetCfgCountryCode(pMac, countryCode);
3588}
3589
Agarwal Ashish8bd53ae2015-06-12 18:03:45 +05303590void csrUpdateFCCChannelList(tpAniSirGlobal pMac)
3591{
3592 tCsrChannel ChannelList;
3593 tANI_U8 chnlIndx = 0;
3594 int i;
3595 chnlIndx = pMac->scan.base20MHzChannels.numChannels;
3596
3597 for ( i = 0; i < pMac->scan.base20MHzChannels.numChannels; i++ )
3598 {
3599 if (pMac->scan.fcc_constraint &&
3600 ((pMac->scan.base20MHzChannels.channelList[i] == 12) ||
3601 (pMac->scan.base20MHzChannels.channelList[i] == 13)))
3602 {
3603 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
3604 FL("removing channel %d"),
3605 pMac->scan.base20MHzChannels.channelList[i]);
3606 continue;
3607 }
3608 ChannelList.channelList[i] = pMac->scan.base20MHzChannels.channelList[i];
3609 chnlIndx++;
3610 }
3611 csrSetCfgValidChannelList(pMac, ChannelList.channelList, chnlIndx);
3612
3613}
Jeff Johnson295189b2012-06-20 16:38:30 -07003614
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003615void csrResetCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce, tANI_BOOLEAN updateRiva )
Jeff Johnson295189b2012-06-20 16:38:30 -07003616{
3617 if( fForce || (csrIs11dSupported( pMac ) && (!pMac->scan.f11dInfoReset)))
3618 {
3619
3620#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3621 {
3622 vos_log_802_11d_pkt_type *p11dLog;
3623 int Index;
3624
3625 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
3626 if(p11dLog)
3627 {
3628 p11dLog->eventId = WLAN_80211D_EVENT_RESET;
Kiet Lam64c1b492013-07-12 13:56:44 +05303629 vos_mem_copy(p11dLog->countryCode, pMac->scan.countryCodeCurrent, 3);
Jeff Johnson295189b2012-06-20 16:38:30 -07003630 p11dLog->numChannel = pMac->scan.base20MHzChannels.numChannels;
3631 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
3632 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303633 vos_mem_copy(p11dLog->Channels,
3634 pMac->scan.base20MHzChannels.channelList,
3635 p11dLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07003636 for (Index=0; Index < pMac->scan.base20MHzChannels.numChannels; Index++)
3637 {
3638 p11dLog->TxPwr[Index] = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
3639 }
3640 }
3641 if(!pMac->roam.configParam.Is11dSupportEnabled)
3642 {
3643 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
3644 }
3645 else if(pMac->roam.configParam.fEnforceDefaultDomain)
3646 {
3647 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
3648 }
3649 else
3650 {
3651 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
3652 }
3653 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
3654 }
3655 }
3656#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3657
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003658 csrPruneChannelListForMode(pMac, &pMac->scan.baseChannels);
3659 csrPruneChannelListForMode(pMac, &pMac->scan.base20MHzChannels);
3660
Jeff Johnson295189b2012-06-20 16:38:30 -07003661 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_FALSE);
3662 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_TRUE);
3663 // ... and apply the channel list, power settings, and the country code.
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003664 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.base20MHzChannels, pMac->scan.countryCodeCurrent, updateRiva );
Jeff Johnson295189b2012-06-20 16:38:30 -07003665 // clear the 11d channel list
Kiet Lam64c1b492013-07-12 13:56:44 +05303666 vos_mem_set(&pMac->scan.channels11d, sizeof(pMac->scan.channels11d), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003667 pMac->scan.f11dInfoReset = eANI_BOOLEAN_TRUE;
3668 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_FALSE;
3669 }
3670
3671 return;
3672}
3673
3674
3675eHalStatus csrResetCountryCodeInformation(tpAniSirGlobal pMac, tANI_BOOLEAN *pfRestartNeeded)
3676{
3677 eHalStatus status = eHAL_STATUS_SUCCESS;
3678 tANI_BOOLEAN fRestart = eANI_BOOLEAN_FALSE;
3679
3680 //Use the Country code and domain from EEPROM
Kiet Lam64c1b492013-07-12 13:56:44 +05303681 vos_mem_copy(pMac->scan.countryCodeCurrent, pMac->scan.countryCodeDefault,
3682 WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07003683 csrSetRegulatoryDomain(pMac, pMac->scan.domainIdCurrent, &fRestart);
Jeff Johnson43971f52012-07-17 12:26:56 -07003684 if( ((eANI_BOOLEAN_FALSE == fRestart) || (pfRestartNeeded == NULL) )
3685 && !csrIsInfraConnected(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -07003686 {
3687 //Only reset the country info if we don't need to restart
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003688 csrResetCountryInformation(pMac, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07003689 }
3690 if(pfRestartNeeded)
3691 {
3692 *pfRestartNeeded = fRestart;
3693 }
3694
3695 return (status);
3696}
3697
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303698void csrClearVotesForCountryInfo(tpAniSirGlobal pMac)
3699{
3700 pMac->scan.countryCodeCount = 0;
3701 vos_mem_set(pMac->scan.votes11d,
3702 sizeof(tCsrVotes11d) * CSR_MAX_NUM_COUNTRY_CODE, 0);
3703}
3704
3705void csrAddVoteForCountryInfo(tpAniSirGlobal pMac, tANI_U8 *pCountryCode)
3706{
3707 tANI_BOOLEAN match = FALSE;
3708 tANI_U8 i;
3709
3710 /* convert to UPPER here so we are assured
3711 * the strings are always in upper case.
3712 */
3713 for( i = 0; i < 3; i++ )
3714 {
3715 pCountryCode[ i ] = (tANI_U8)csrToUpper( pCountryCode[ i ] );
3716 }
3717
3718 /* Some of the 'old' Cisco 350 series AP's advertise NA as the
3719 * country code (for North America ??). NA is not a valid country code
3720 * or domain so let's allow this by changing it to the proper
3721 * country code (which is US). We've also seen some NETGEAR AP's
3722 * that have "XX " as the country code with valid 2.4 GHz US channel
3723 * information. If we cannot find the country code advertised in the
3724 * 11d information element, let's default to US.
3725 */
3726
3727 if ( !HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry( pMac,
3728 pCountryCode, NULL,COUNTRY_QUERY ) ) )
3729 {
3730 pCountryCode[ 0 ] = '0';
3731 pCountryCode[ 1 ] = '0';
3732 }
3733
3734 /* We've seen some of the AP's improperly put a 0 for the
3735 * third character of the country code. spec says valid charcters are
3736 * 'O' (for outdoor), 'I' for Indoor, or ' ' (space; for either).
3737 * if we see a 0 in this third character, let's change it to a ' '.
3738 */
3739 if ( 0 == pCountryCode[ 2 ] )
3740 {
3741 pCountryCode[ 2 ] = ' ';
3742 }
3743
3744 for (i = 0; i < pMac->scan.countryCodeCount; i++)
3745 {
3746 match = (vos_mem_compare(pMac->scan.votes11d[i].countryCode,
3747 pCountryCode, 2));
3748 if(match)
3749 {
3750 break;
3751 }
3752 }
3753
3754 if (match)
3755 {
3756 pMac->scan.votes11d[i].votes++;
3757 }
3758 else
3759 {
3760 vos_mem_copy( pMac->scan.votes11d[pMac->scan.countryCodeCount].countryCode,
3761 pCountryCode, 3 );
3762 pMac->scan.votes11d[pMac->scan.countryCodeCount].votes = 1;
3763 pMac->scan.countryCodeCount++;
3764 }
3765
3766 return;
3767}
3768
3769tANI_BOOLEAN csrElectedCountryInfo(tpAniSirGlobal pMac)
3770{
3771 tANI_BOOLEAN fRet = FALSE;
3772 tANI_U8 maxVotes = 0;
3773 tANI_U8 i, j=0;
3774
3775 if (!pMac->scan.countryCodeCount)
3776 {
3777 return fRet;
3778 }
3779 maxVotes = pMac->scan.votes11d[0].votes;
3780 fRet = TRUE;
3781
3782 for(i = 1; i < pMac->scan.countryCodeCount; i++)
3783 {
3784 /* If we have a tie for max votes for 2 different country codes,
3785 * pick random.we can put some more intelligence - TBD
3786 */
3787 if (maxVotes < pMac->scan.votes11d[i].votes)
3788 {
3789 VOS_TRACE( VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
3790 " Votes for Country %c%c : %d\n",
3791 pMac->scan.votes11d[i].countryCode[0],
3792 pMac->scan.votes11d[i].countryCode[1],
3793 pMac->scan.votes11d[i].votes);
3794
3795 maxVotes = pMac->scan.votes11d[i].votes;
3796 j = i;
3797 fRet = TRUE;
3798 }
3799
3800 }
3801 if (fRet)
3802 {
Rajesh Babu Prathipati20cdffa2014-07-01 22:24:59 +05303803 vos_mem_copy(pMac->scan.countryCodeElected,
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303804 pMac->scan.votes11d[j].countryCode, WNI_CFG_COUNTRY_CODE_LEN);
Rajesh Babu Prathipati20cdffa2014-07-01 22:24:59 +05303805 vos_mem_copy(pMac->scan.countryCode11d,
Agarwal Ashish852b2c32014-05-23 17:13:25 +05303806 pMac->scan.votes11d[j].countryCode, WNI_CFG_COUNTRY_CODE_LEN);
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303807 VOS_TRACE( VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
3808 "Selected Country is %c%c With count %d\n",
3809 pMac->scan.votes11d[j].countryCode[0],
3810 pMac->scan.votes11d[j].countryCode[1],
3811 pMac->scan.votes11d[j].votes);
3812 }
3813 return fRet;
3814}
Jeff Johnson295189b2012-06-20 16:38:30 -07003815
3816eHalStatus csrSetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pCountry, tANI_BOOLEAN *pfRestartNeeded)
3817{
3818 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
3819 v_REGDOMAIN_t domainId;
3820
3821 if(pCountry)
3822 {
Kiet Lam6c583332013-10-14 05:37:09 +05303823 status = csrGetRegulatoryDomainForCountry(pMac, pCountry, &domainId, COUNTRY_USER);
Jeff Johnson295189b2012-06-20 16:38:30 -07003824 if(HAL_STATUS_SUCCESS(status))
3825 {
3826 status = csrSetRegulatoryDomain(pMac, domainId, pfRestartNeeded);
3827 if(HAL_STATUS_SUCCESS(status))
3828 {
3829 //We don't need to check the pMac->roam.configParam.fEnforceDefaultDomain flag here,
3830 //csrSetRegulatoryDomain will fail if the country doesn't fit our domain criteria.
Kiet Lam64c1b492013-07-12 13:56:44 +05303831 vos_mem_copy(pMac->scan.countryCodeCurrent, pCountry, WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07003832 if((pfRestartNeeded == NULL) || !(*pfRestartNeeded))
3833 {
3834 //Simply set it to cfg. If we need to restart, restart will apply it to the CFG
3835 csrSetCfgCountryCode(pMac, pCountry);
3836 }
3837 }
3838 }
3839 }
3840
3841 return (status);
3842}
3843
3844
3845
3846//caller allocated memory for pNumChn and pChnPowerInfo
3847//As input, *pNumChn has the size of the array of pChnPowerInfo
3848//Upon return, *pNumChn has the number of channels assigned.
3849void csrGetChannelPowerInfo( tpAniSirGlobal pMac, tDblLinkList *pList,
3850 tANI_U32 *pNumChn, tChannelListWithPower *pChnPowerInfo)
3851{
3852 tListElem *pEntry;
3853 tANI_U32 chnIdx = 0, idx;
3854 tCsrChannelPowerInfo *pChannelSet;
3855
3856 //Get 2.4Ghz first
3857 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
3858 while( pEntry && (chnIdx < *pNumChn) )
3859 {
3860 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3861 if ( 1 != pChannelSet->interChannelOffset )
3862 {
3863 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
3864 {
3865 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
3866 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
3867 }
3868 }
3869 else
3870 {
3871 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
3872 {
3873 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + idx);
3874 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
3875 }
3876 }
3877
3878 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
3879 }
3880 *pNumChn = chnIdx;
3881
3882 return ;
3883}
3884
3885
3886
3887void csrApplyCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce )
3888{
3889 v_REGDOMAIN_t domainId;
3890 eHalStatus status = eHAL_STATUS_SUCCESS;
3891
3892 do
3893 {
3894 if( !csrIs11dSupported( pMac ) || 0 == pMac->scan.channelOf11dInfo) break;
3895 if( pMac->scan.fAmbiguous11dInfoFound )
3896 {
3897 // ambiguous info found
3898 //Restore te default domain as well
Kiet Lam6c583332013-10-14 05:37:09 +05303899 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
3900 pMac, pMac->scan.countryCodeCurrent,
3901 &domainId, COUNTRY_QUERY)))
Jeff Johnson295189b2012-06-20 16:38:30 -07003902 {
3903 pMac->scan.domainIdCurrent = domainId;
3904 }
3905 else
3906 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003907 smsLog(pMac, LOGE, FL(" failed to get domain from currentCountryCode %02X%02X"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003908 pMac->scan.countryCodeCurrent[0], pMac->scan.countryCodeCurrent[1]);
3909 }
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003910 csrResetCountryInformation( pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE );
Jeff Johnson295189b2012-06-20 16:38:30 -07003911 break;
3912 }
3913 if ( pMac->scan.f11dInfoApplied && !fForce ) break;
Kiet Lam6c583332013-10-14 05:37:09 +05303914 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
3915 pMac, pMac->scan.countryCode11d,
3916 &domainId, COUNTRY_QUERY)))
Jeff Johnson295189b2012-06-20 16:38:30 -07003917 {
3918 //Check whether we need to enforce default domain
3919 if( ( !pMac->roam.configParam.fEnforceDefaultDomain ) ||
3920 (pMac->scan.domainIdCurrent == domainId) )
3921 {
3922
3923#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3924 {
3925 vos_log_802_11d_pkt_type *p11dLog;
3926 tChannelListWithPower chnPwrInfo[WNI_CFG_VALID_CHANNEL_LIST_LEN];
3927 tANI_U32 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN, nTmp;
3928
3929 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
3930 if(p11dLog)
3931 {
3932 p11dLog->eventId = WLAN_80211D_EVENT_COUNTRY_SET;
Kiet Lam64c1b492013-07-12 13:56:44 +05303933 vos_mem_copy(p11dLog->countryCode, pMac->scan.countryCode11d, 3);
Jeff Johnson295189b2012-06-20 16:38:30 -07003934 p11dLog->numChannel = pMac->scan.channels11d.numChannels;
3935 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
3936 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303937 vos_mem_copy(p11dLog->Channels,
3938 pMac->scan.channels11d.channelList,
3939 p11dLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07003940 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList24,
3941 &nChnInfo, chnPwrInfo);
3942 nTmp = nChnInfo;
3943 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN - nTmp;
3944 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList5G,
3945 &nChnInfo, &chnPwrInfo[nTmp]);
3946 for(nTmp = 0; nTmp < p11dLog->numChannel; nTmp++)
3947 {
3948 for(nChnInfo = 0; nChnInfo < WNI_CFG_VALID_CHANNEL_LIST_LEN; nChnInfo++)
3949 {
3950 if(p11dLog->Channels[nTmp] == chnPwrInfo[nChnInfo].chanId)
3951 {
3952 p11dLog->TxPwr[nTmp] = chnPwrInfo[nChnInfo].pwr;
3953 break;
3954 }
3955 }
3956 }
3957 }
3958 if(!pMac->roam.configParam.Is11dSupportEnabled)
3959 {
3960 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
3961 }
3962 else if(pMac->roam.configParam.fEnforceDefaultDomain)
3963 {
3964 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
3965 }
3966 else
3967 {
3968 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
3969 }
3970 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
3971 }
3972 }
3973#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3974 if(pMac->scan.domainIdCurrent != domainId)
3975 {
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05303976 smsLog(pMac, LOGW, FL("Domain Changed Old %s (%d), new %s"),
3977 voss_DomainIdtoString(pMac->scan.domainIdCurrent),
3978 pMac->scan.domainIdCurrent,
3979 voss_DomainIdtoString(domainId));
Abhishek Singha306a442013-11-07 18:39:01 +05303980 status = WDA_SetRegDomain(pMac, domainId, eSIR_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07003981 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003982 if (status != eHAL_STATUS_SUCCESS)
3983 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003984 smsLog( pMac, LOGE, FL(" fail to set regId %d"), domainId );
Jeff Johnson295189b2012-06-20 16:38:30 -07003985 }
3986 pMac->scan.domainIdCurrent = domainId;
Kiet Lam6c583332013-10-14 05:37:09 +05303987#ifndef CONFIG_ENABLE_LINUX_REG
Kiet Lambb14e952013-11-19 14:58:29 +05303988 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.base20MHzChannels,
3989 pMac->scan.countryCodeCurrent, eANI_BOOLEAN_TRUE );
Kiet Lam6c583332013-10-14 05:37:09 +05303990#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07003991 // switch to active scans using this new channel list
3992 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
3993 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_TRUE;
3994 pMac->scan.f11dInfoReset = eANI_BOOLEAN_FALSE;
3995 }
3996 }
3997
3998 } while( 0 );
3999
4000 return;
4001}
4002
4003
4004
4005tANI_BOOLEAN csrSave11dCountryString( tpAniSirGlobal pMac, tANI_U8 *pCountryCode,
4006 tANI_BOOLEAN fForce)
4007{
4008 tANI_BOOLEAN fCountryStringChanged = FALSE, fUnknownCountryCode = FALSE;
4009 tANI_U32 i;
Kiet Lam6c583332013-10-14 05:37:09 +05304010 v_REGDOMAIN_t regd;
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004011 tANI_BOOLEAN fCountryNotPresentInDriver = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004012
4013 // convert to UPPER here so we are assured the strings are always in upper case.
4014 for( i = 0; i < 3; i++ )
4015 {
4016 pCountryCode[ i ] = (tANI_U8)csrToUpper( pCountryCode[ i ] );
4017 }
4018
4019 // Some of the 'old' Cisco 350 series AP's advertise NA as the country code (for North America ??).
4020 // NA is not a valid country code or domain so let's allow this by changing it to the proper
4021 // country code (which is US). We've also seen some NETGEAR AP's that have "XX " as the country code
4022 // with valid 2.4 GHz US channel information. If we cannot find the country code advertised in the
4023 // 11d information element, let's default to US.
Kiet Lam6c583332013-10-14 05:37:09 +05304024 if ( !HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(pMac,
4025 pCountryCode,
4026 &regd,
4027 COUNTRY_QUERY) ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07004028 {
4029 // Check the enforcement first
4030 if( pMac->roam.configParam.fEnforceDefaultDomain || pMac->roam.configParam.fEnforceCountryCodeMatch )
4031 {
4032 fUnknownCountryCode = TRUE;
4033 }
4034 else
4035 {
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004036 fCountryNotPresentInDriver = TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004037 }
4038 }
Tushnim Bhattacharyyac3c1e8e2013-10-29 17:27:43 -07004039 //right now, even if we don't find the CC in driver we set to world. Making
4040 //sure countryCode11d doesn't get updated with the invalid CC, instead
4041 //reflect the world CC
4042 else if (REGDOMAIN_WORLD == regd)
4043 {
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004044 fCountryNotPresentInDriver = TRUE;
Tushnim Bhattacharyyac3c1e8e2013-10-29 17:27:43 -07004045 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004046
4047 // We've seen some of the AP's improperly put a 0 for the third character of the country code.
4048 // spec says valid charcters are 'O' (for outdoor), 'I' for Indoor, or ' ' (space; for either).
4049 // if we see a 0 in this third character, let's change it to a ' '.
4050 if ( 0 == pCountryCode[ 2 ] )
4051 {
4052 pCountryCode[ 2 ] = ' ';
4053 }
4054
4055 if( !fUnknownCountryCode )
4056 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304057 fCountryStringChanged = (!vos_mem_compare(pMac->scan.countryCode11d, pCountryCode, 2));
Jeff Johnson295189b2012-06-20 16:38:30 -07004058
4059
4060 if(( 0 == pMac->scan.countryCode11d[ 0 ] && 0 == pMac->scan.countryCode11d[ 1 ] )
4061 || (fForce))
4062 {
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004063 if (!fCountryNotPresentInDriver)
4064 {
4065 // this is the first .11d information
4066 vos_mem_copy(pMac->scan.countryCode11d, pCountryCode,
Kiet Lam64c1b492013-07-12 13:56:44 +05304067 sizeof( pMac->scan.countryCode11d ));
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004068
4069 }
4070 else
4071 {
4072 pMac->scan.countryCode11d[0] = '0';
4073 pMac->scan.countryCode11d[1] = '0';
4074 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004075 }
4076 }
4077
4078 return( fCountryStringChanged );
4079}
4080
4081
4082void csrSaveChannelPowerForBand( tpAniSirGlobal pMac, tANI_BOOLEAN fPopulate5GBand )
4083{
4084 tANI_U32 Index, count=0;
4085 tSirMacChanInfo *pChanInfo;
4086 tSirMacChanInfo *pChanInfoStart;
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08004087 tANI_S32 maxChannelIndex;
4088
4089 maxChannelIndex = ( pMac->scan.base20MHzChannels.numChannels < WNI_CFG_VALID_CHANNEL_LIST_LEN ) ?
4090 pMac->scan.base20MHzChannels.numChannels : WNI_CFG_VALID_CHANNEL_LIST_LEN ;
Jeff Johnson295189b2012-06-20 16:38:30 -07004091
Kiet Lam64c1b492013-07-12 13:56:44 +05304092 pChanInfo = vos_mem_malloc(sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN);
4093 if ( NULL != pChanInfo )
Jeff Johnson295189b2012-06-20 16:38:30 -07004094 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304095 vos_mem_set(pChanInfo, sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004096 pChanInfoStart = pChanInfo;
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08004097 for (Index=0; Index < maxChannelIndex; Index++)
Jeff Johnson295189b2012-06-20 16:38:30 -07004098 {
4099 if ((fPopulate5GBand && (CSR_IS_CHANNEL_5GHZ(pMac->scan.defaultPowerTable[Index].chanId))) ||
4100 (!fPopulate5GBand && (CSR_IS_CHANNEL_24GHZ(pMac->scan.defaultPowerTable[Index].chanId))) )
4101 {
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08004102 if(count >= WNI_CFG_VALID_CHANNEL_LIST_LEN)
4103 {
4104 smsLog( pMac, LOGW, FL(" csrSaveChannelPowerForBand, count exceeded, count = %d"), count);
4105 break;
4106 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004107 pChanInfo->firstChanNum = pMac->scan.defaultPowerTable[Index].chanId;
4108 pChanInfo->numChannels = 1;
4109 pChanInfo->maxTxPower = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
4110 pChanInfo++;
4111 count++;
4112 }
4113 }
4114 if(count)
4115 {
4116 csrSaveToChannelPower2G_5G( pMac, count * sizeof(tSirMacChanInfo), pChanInfoStart );
4117 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304118 vos_mem_free(pChanInfoStart);
Jeff Johnson295189b2012-06-20 16:38:30 -07004119 }
4120}
4121
4122
4123void csrSetOppositeBandChannelInfo( tpAniSirGlobal pMac )
4124{
4125 tANI_BOOLEAN fPopulate5GBand = FALSE;
4126
4127 do
4128 {
4129 // if this is not a dual band product, then we don't need to set the opposite
4130 // band info. We only work in one band so no need to look in the other band.
4131 if ( !CSR_IS_OPEARTING_DUAL_BAND( pMac ) ) break;
4132 // if we found channel info on the 5.0 band and...
4133 if ( CSR_IS_CHANNEL_5GHZ( pMac->scan.channelOf11dInfo ) )
4134 {
4135 // and the 2.4 band is empty, then populate the 2.4 channel info
Kiet Lam8d985a02013-10-11 03:39:41 +05304136 if ( !csrLLIsListEmpty( &pMac->scan.channelPowerInfoList24, LL_ACCESS_LOCK ) ) break;
Jeff Johnson295189b2012-06-20 16:38:30 -07004137 fPopulate5GBand = FALSE;
4138 }
4139 else
4140 {
4141 // else, we found channel info in the 2.4 GHz band. If the 5.0 band is empty
4142 // set the 5.0 band info from the 2.4 country code.
Kiet Lam8d985a02013-10-11 03:39:41 +05304143 if ( !csrLLIsListEmpty( &pMac->scan.channelPowerInfoList5G, LL_ACCESS_LOCK ) ) break;
Jeff Johnson295189b2012-06-20 16:38:30 -07004144 fPopulate5GBand = TRUE;
4145 }
4146 csrSaveChannelPowerForBand( pMac, fPopulate5GBand );
4147
4148 } while( 0 );
4149}
4150
4151
4152tANI_BOOLEAN csrIsSupportedChannel(tpAniSirGlobal pMac, tANI_U8 channelId)
4153{
4154 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
4155 tANI_U32 i;
4156
4157 //Make sure it is a channel that is in our supported list.
4158 for ( i = 0; i < pMac->scan.baseChannels.numChannels; i++ )
4159 {
4160 if ( channelId == pMac->scan.baseChannels.channelList[i] )
4161 {
4162 fRet = eANI_BOOLEAN_TRUE;
4163 break;
4164 }
4165 }
4166
4167 //If it is configured to limit a set of the channels
4168 if( fRet && pMac->roam.configParam.fEnforce11dChannels )
4169 {
4170 fRet = eANI_BOOLEAN_FALSE;
4171 for ( i = 0; i < pMac->scan.base20MHzChannels.numChannels; i++ )
4172 {
4173 if ( channelId == pMac->scan.base20MHzChannels.channelList[i] )
4174 {
4175 fRet = eANI_BOOLEAN_TRUE;
4176 break;
4177 }
4178 }
4179 }
4180
4181 return (fRet);
4182}
4183
4184
4185
4186//bSize specify the buffer size of pChannelList
4187tANI_U8 csrGetChannelListFromChannelSet( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 bSize, tCsrChannelPowerInfo *pChannelSet )
4188{
4189 tANI_U8 i, j = 0, chnId;
4190
4191 bSize = CSR_MIN(bSize, pChannelSet->numChannels);
4192 for( i = 0; i < bSize; i++ )
4193 {
4194 chnId = (tANI_U8)(pChannelSet->firstChannel + ( i * pChannelSet->interChannelOffset ));
4195 if ( csrIsSupportedChannel( pMac, chnId ) )
4196 {
4197 pChannelList[j++] = chnId;
4198 }
4199 }
4200
4201 return (j);
4202}
4203
4204
4205
4206//bSize -- specify the buffer size of pChannelList
4207void csrConstructCurrentValidChannelList( tpAniSirGlobal pMac, tDblLinkList *pChannelSetList,
4208 tANI_U8 *pChannelList, tANI_U8 bSize, tANI_U8 *pNumChannels )
4209{
4210 tListElem *pEntry;
4211 tCsrChannelPowerInfo *pChannelSet;
4212 tANI_U8 numChannels;
4213 tANI_U8 *pChannels;
4214
4215 if( pChannelSetList && pChannelList && pNumChannels )
4216 {
4217 pChannels = pChannelList;
4218 *pNumChannels = 0;
4219 pEntry = csrLLPeekHead( pChannelSetList, LL_ACCESS_LOCK );
4220 while( pEntry )
4221 {
4222 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
4223 numChannels = csrGetChannelListFromChannelSet( pMac, pChannels, bSize, pChannelSet );
4224 pChannels += numChannels;
4225 *pNumChannels += numChannels;
4226 pEntry = csrLLNext( pChannelSetList, pEntry, LL_ACCESS_LOCK );
4227 }
4228 }
4229}
4230
4231
4232/*
4233 * 802.11D only: Gather 11d IE via beacon or Probe response and store them in pAdapter->channels11d
4234*/
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304235tANI_BOOLEAN csrLearnCountryInformation( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc,
4236 tDot11fBeaconIEs *pIes, tANI_BOOLEAN fForce)
Jeff Johnson295189b2012-06-20 16:38:30 -07004237{
Agarwal Ashish60a37ee2014-05-28 17:20:20 +05304238 eHalStatus status;
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304239 tANI_U8 *pCountryCodeSelected;
Jeff Johnson295189b2012-06-20 16:38:30 -07004240 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
4241 v_REGDOMAIN_t domainId;
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304242 tDot11fBeaconIEs *pIesLocal = pIes;
4243 tANI_BOOLEAN useVoting = eANI_BOOLEAN_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004244
Jeff Johnson295189b2012-06-20 16:38:30 -07004245 if (VOS_STA_SAP_MODE == vos_get_conparam ())
4246 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07004247
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304248 if ((NULL == pSirBssDesc) && (NULL == pIes))
4249 useVoting = eANI_BOOLEAN_TRUE;
4250
Jeff Johnson295189b2012-06-20 16:38:30 -07004251 do
4252 {
4253 // check if .11d support is enabled
4254 if( !csrIs11dSupported( pMac ) ) break;
Agarwal Ashish60a37ee2014-05-28 17:20:20 +05304255
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304256 if (eANI_BOOLEAN_FALSE == useVoting)
4257 {
4258 if( !pIesLocal &&
4259 (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
4260 pSirBssDesc, &pIesLocal))))
4261 {
4262 break;
4263 }
4264 // check if country information element is present
4265 if(!pIesLocal->Country.present)
4266 {
4267 //No country info
4268 break;
4269 }
4270
4271 if( HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry
4272 (pMac, pIesLocal->Country.country, &domainId,
4273 COUNTRY_QUERY)) &&
4274 ( domainId == REGDOMAIN_WORLD))
4275 {
4276 break;
4277 }
4278 } //useVoting == eANI_BOOLEAN_FALSE
4279
4280 if (eANI_BOOLEAN_FALSE == useVoting)
4281 pCountryCodeSelected = pIesLocal->Country.country;
4282 else
4283 pCountryCodeSelected = pMac->scan.countryCodeElected;
4284
Kiet Lam8d985a02013-10-11 03:39:41 +05304285 status = csrGetRegulatoryDomainForCountry(pMac,
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304286 pCountryCodeSelected, &domainId, COUNTRY_IE);
Kiet Lam8d985a02013-10-11 03:39:41 +05304287 if ( status != eHAL_STATUS_SUCCESS )
4288 {
4289 smsLog( pMac, LOGE, FL(" fail to get regId %d"), domainId );
4290 fRet = eANI_BOOLEAN_FALSE;
4291 break;
4292 }
Agarwal Ashish7693f2d2014-07-18 18:03:58 +05304293
4294 /* updating 11d Country Code with Country code selected. */
4295
4296 vos_mem_copy(pMac->scan.countryCode11d,
4297 pCountryCodeSelected,
4298 WNI_CFG_COUNTRY_CODE_LEN);
4299
Agarwal Ashish60a37ee2014-05-28 17:20:20 +05304300#ifndef CONFIG_ENABLE_LINUX_REG
Venkata Prathyusha Kuntupalli316247e2013-03-15 17:45:25 -07004301 // Checking for Domain Id change
4302 if ( domainId != pMac->scan.domainIdCurrent )
4303 {
Kiet Lam8d985a02013-10-11 03:39:41 +05304304 vos_mem_copy(pMac->scan.countryCode11d,
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304305 pCountryCodeSelected,
Kiet Lam8d985a02013-10-11 03:39:41 +05304306 sizeof( pMac->scan.countryCode11d ) );
4307 /* Set Current Country code and Current Regulatory domain */
4308 status = csrSetRegulatoryDomain(pMac, domainId, NULL);
4309 if (eHAL_STATUS_SUCCESS != status)
4310 {
4311 smsLog(pMac, LOGE, "Set Reg Domain Fail %d", status);
4312 fRet = eANI_BOOLEAN_FALSE;
4313 return fRet;
4314 }
4315 //csrSetRegulatoryDomain will fail if the country doesn't fit our domain criteria.
4316 vos_mem_copy(pMac->scan.countryCodeCurrent,
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304317 pCountryCodeSelected, WNI_CFG_COUNTRY_CODE_LEN);
Kiet Lam8d985a02013-10-11 03:39:41 +05304318 //Simply set it to cfg.
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304319 csrSetCfgCountryCode(pMac, pCountryCodeSelected);
Kiet Lam8d985a02013-10-11 03:39:41 +05304320
4321 /* overwrite the defualt country code */
4322 vos_mem_copy(pMac->scan.countryCodeDefault,
4323 pMac->scan.countryCodeCurrent,
4324 WNI_CFG_COUNTRY_CODE_LEN);
4325 /* Set Current RegDomain */
Abhishek Singha306a442013-11-07 18:39:01 +05304326 status = WDA_SetRegDomain(pMac, domainId, eSIR_TRUE);
Kiet Lam8d985a02013-10-11 03:39:41 +05304327 if ( status != eHAL_STATUS_SUCCESS )
4328 {
4329 smsLog( pMac, LOGE, FL(" fail to Set regId %d"), domainId );
4330 fRet = eANI_BOOLEAN_FALSE;
4331 return fRet;
4332 }
4333 /* set to default domain ID */
Madan Mohan Koyyalamudi0e5922d2013-09-10 15:45:24 +05304334 pMac->scan.domainIdCurrent = domainId;
Kiet Lam8d985a02013-10-11 03:39:41 +05304335 /* get the channels based on new cc */
4336 status = csrInitGetChannels( pMac );
Jeff Johnson295189b2012-06-20 16:38:30 -07004337
Kiet Lam8d985a02013-10-11 03:39:41 +05304338 if ( status != eHAL_STATUS_SUCCESS )
4339 {
4340 smsLog( pMac, LOGE, FL(" fail to get Channels "));
4341 fRet = eANI_BOOLEAN_FALSE;
4342 return fRet;
4343 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004344
Kiet Lam8d985a02013-10-11 03:39:41 +05304345 /* reset info based on new cc, and we are done */
4346 csrResetCountryInformation(pMac, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
Agarwal Ashishfaef6692014-01-29 19:40:30 +05304347 /* Regulatory Domain Changed, Purge Only scan result
4348 * which does not have channel number belong to 11d
4349 * channel list
4350 */
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05304351 csrScanFilterResults(pMac);
Kiet Lam8d985a02013-10-11 03:39:41 +05304352 }
Kiet Lam6c583332013-10-14 05:37:09 +05304353#endif
4354 fRet = eANI_BOOLEAN_TRUE;
4355
Jeff Johnson295189b2012-06-20 16:38:30 -07004356 } while( 0 );
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304357
4358 if( !pIes && pIesLocal )
4359 {
4360 //locally allocated
4361 vos_mem_free(pIesLocal);
4362 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004363
4364 return( fRet );
4365}
4366
4367
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004368static void csrSaveScanResults( tpAniSirGlobal pMac, tANI_U8 reason )
Jeff Johnson295189b2012-06-20 16:38:30 -07004369{
4370 // initialize this to FALSE. profMoveInterimScanResultsToMainList() routine
4371 // will set this to the channel where an .11d beacon is seen
4372 pMac->scan.channelOf11dInfo = 0;
4373 // if we get any ambiguous .11d information then this will be set to TRUE
4374 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
4375 //Tush
4376 // if we get any ambiguous .11d information, then this will be set to TRUE
4377 // only if the applied 11d info could be found in one of the scan results
4378 pMac->scan.fCurrent11dInfoMatch = eANI_BOOLEAN_FALSE;
4379 // move the scan results from interim list to the main scan list
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004380 csrMoveTempScanResultsToMainList( pMac, reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07004381}
4382
4383
4384void csrReinitScanCmd(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4385{
4386 switch (pCommand->u.scanCmd.reason)
4387 {
4388 case eCsrScanSetBGScanParam:
4389 case eCsrScanAbortBgScan:
4390 if(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList)
4391 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304392 vos_mem_free(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList);
Jeff Johnson295189b2012-06-20 16:38:30 -07004393 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
4394 }
4395 break;
4396 case eCsrScanBGScanAbort:
4397 case eCsrScanBGScanEnable:
4398 case eCsrScanGetScanChnInfo:
4399 break;
4400 case eCsrScanAbortNormalScan:
4401 default:
4402 csrScanFreeRequest(pMac, &pCommand->u.scanCmd.u.scanRequest);
4403 break;
4404 }
4405 if(pCommand->u.scanCmd.pToRoamProfile)
4406 {
4407 csrReleaseProfile(pMac, pCommand->u.scanCmd.pToRoamProfile);
Kiet Lam64c1b492013-07-12 13:56:44 +05304408 vos_mem_free(pCommand->u.scanCmd.pToRoamProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07004409 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304410 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004411}
4412
4413
4414tANI_BOOLEAN csrGetRemainingChannelsFor11dScan( tpAniSirGlobal pMac, tANI_U8 *pChannels, tANI_U8 *pcChannels )
4415{
4416 tANI_U32 index11dChannels, index;
4417 tANI_U32 indexCurrentChannels;
4418 tANI_BOOLEAN fChannelAlreadyScanned;
4419 tANI_U32 len = sizeof(pMac->roam.validChannelList);
4420
4421 *pcChannels = 0;
4422 if ( CSR_IS_11D_INFO_FOUND(pMac) && csrRoamIsChannelValid(pMac, pMac->scan.channelOf11dInfo) )
4423 {
4424 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
4425 {
4426 //Find the channel index where we found the 11d info
4427 for(index = 0; index < len; index++)
4428 {
4429 if(pMac->scan.channelOf11dInfo == pMac->roam.validChannelList[index])
4430 break;
4431 }
4432 //check whether we found the channel index
4433 if(index < len)
4434 {
4435 // Now, look through the 11d channel list and create a list of all channels in the 11d list that are
4436 // NOT in the current channel list. This gives us a list of the new channels that have not been
4437 // scanned. We'll scan this new list so we have a complete set of scan results on all of the domain channels
4438 // initially.
4439 for ( index11dChannels = 0; index11dChannels < pMac->scan.channels11d.numChannels; index11dChannels++ )
4440 {
4441 fChannelAlreadyScanned = eANI_BOOLEAN_FALSE;
4442
4443 for( indexCurrentChannels = 0; indexCurrentChannels < index; indexCurrentChannels++ )
4444 {
4445 if ( pMac->roam.validChannelList[ indexCurrentChannels ] == pMac->scan.channels11d.channelList[ index11dChannels ] )
4446 {
4447 fChannelAlreadyScanned = eANI_BOOLEAN_TRUE;
4448 break;
4449 }
4450 }
4451
4452 if ( !fChannelAlreadyScanned )
4453 {
4454 pChannels[ *pcChannels ] = pMac->scan.channels11d.channelList[ index11dChannels ];
4455 ( *pcChannels )++;
4456 }
4457 }
4458 }
4459 }//GetCFG
4460 }
4461 return( *pcChannels );
4462}
4463
4464
4465eCsrScanCompleteNextCommand csrScanGetNextCommandState( tpAniSirGlobal pMac, tSmeCmd *pCommand, tANI_BOOLEAN fSuccess )
4466{
4467 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
4468
4469 switch( pCommand->u.scanCmd.reason )
4470 {
4471 case eCsrScan11d1:
4472 NextCommand = (fSuccess) ? eCsrNext11dScan1Success : eCsrNext11dScan1Failure;
4473 break;
4474 case eCsrScan11d2:
4475 NextCommand = (fSuccess) ? eCsrNext11dScan2Success : eCsrNext11dScan2Failure;
4476 break;
4477 case eCsrScan11dDone:
4478 NextCommand = eCsrNext11dScanComplete;
4479 break;
4480 case eCsrScanLostLink1:
4481 NextCommand = (fSuccess) ? eCsrNextLostLinkScan1Success : eCsrNextLostLinkScan1Failed;
4482 break;
4483 case eCsrScanLostLink2:
4484 NextCommand = (fSuccess) ? eCsrNextLostLinkScan2Success : eCsrNextLostLinkScan2Failed;
4485 break;
4486 case eCsrScanLostLink3:
4487 NextCommand = (fSuccess) ? eCsrNextLostLinkScan3Success : eCsrNextLostLinkScan3Failed;
4488 break;
4489 case eCsrScanForSsid:
4490 NextCommand = (fSuccess) ? eCsrNexteScanForSsidSuccess : eCsrNexteScanForSsidFailure;
4491 break;
4492 case eCsrScanForCapsChange:
4493 NextCommand = eCsrNextCapChangeScanComplete; //don't care success or not
4494 break;
4495 case eCsrScanIdleScan:
4496 NextCommand = eCsrNextIdleScanComplete;
4497 break;
4498 default:
4499 NextCommand = eCsrNextScanNothing;
4500 break;
4501 }
4502 return( NextCommand );
4503}
4504
4505
4506//Return whether the pCommand is finished.
4507tANI_BOOLEAN csrHandleScan11d1Failure(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4508{
4509 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
4510
4511 //Apply back the default setting and passively scan one more time.
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004512 csrResetCountryInformation(pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07004513 pCommand->u.scanCmd.reason = eCsrScan11d2;
4514 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
4515 {
4516 fRet = eANI_BOOLEAN_FALSE;
4517 }
4518
4519 return (fRet);
4520}
4521
4522
4523tANI_BOOLEAN csrHandleScan11dSuccess(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4524{
4525 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
4526 tANI_U8 *pChannels;
4527 tANI_U8 cChannels;
4528
Kiet Lam64c1b492013-07-12 13:56:44 +05304529 pChannels = vos_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
4530 if ( NULL != pChannels )
Jeff Johnson295189b2012-06-20 16:38:30 -07004531 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304532 vos_mem_set(pChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004533 if ( csrGetRemainingChannelsFor11dScan( pMac, pChannels, &cChannels ) )
4534 {
4535 pCommand->u.scanCmd.reason = eCsrScan11dDone;
4536 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
4537 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304538 vos_mem_free(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -07004539 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004540 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304541 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(cChannels);
4542 if ( NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07004543 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304544 vos_mem_copy(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
4545 pChannels, cChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07004546 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = cChannels;
4547 pCommand->u.scanCmd.u.scanRequest.requestType = eCSR_SCAN_REQUEST_FULL_SCAN;
4548 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
4549 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
4550 {
4551 //Reuse the same command buffer
4552 fRet = eANI_BOOLEAN_FALSE;
4553 }
4554 }
4555 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304556 vos_mem_free(pChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07004557 }
4558
4559 return (fRet);
4560}
4561
4562//Return whether the command should be removed
4563tANI_BOOLEAN csrScanComplete( tpAniSirGlobal pMac, tSirSmeScanRsp *pScanRsp )
4564{
4565 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
4566 tListElem *pEntry;
4567 tSmeCmd *pCommand;
4568 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
4569 tANI_BOOLEAN fSuccess;
4570
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05304571 if (pMac->fScanOffload)
4572 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
4573 else
4574 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07004575
4576 if ( pEntry )
4577 {
4578 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
4579
4580 // If the head of the queue is Active and it is a SCAN command, remove
4581 // and put this on the Free queue.
4582 if ( eSmeCommandScan == pCommand->command )
4583 {
4584 tANI_U32 sessionId = pCommand->sessionId;
4585
4586 if(eSIR_SME_SUCCESS != pScanRsp->statusCode)
4587 {
4588 fSuccess = eANI_BOOLEAN_FALSE;
4589 }
4590 else
4591 {
4592 //pMac->scan.tempScanResults is not empty meaning the scan found something
4593 //This check only valid here because csrSaveScanresults is not yet called
4594 fSuccess = (!csrLLIsListEmpty(&pMac->scan.tempScanResults, LL_ACCESS_LOCK));
4595 }
Ratheesh S Pece1f832015-07-25 15:50:25 +05304596 if (pCommand->u.scanCmd.abortScanIndication &
4597 eCSR_SCAN_ABORT_DUE_TO_BAND_CHANGE)
Srinivas, Dasari187ca4e2014-02-07 12:40:09 +05304598 {
4599 /*
4600 * Scan aborted due to band change
4601 * The scan results need to be flushed
4602 */
4603 if (pCommand->u.scanCmd.callback
4604 != pMac->scan.callback11dScanDone)
4605 {
4606 smsLog(pMac, LOG1, FL("Filtering the scan results as the "
4607 "results may belong to wrong band"));
4608 csrScanFilterResults(pMac);
4609 }
4610 else
4611 {
4612 smsLog(pMac, LOG1, FL("11d_scan_done will flush the scan"
4613 " results"));
4614 }
Srinivas, Dasari187ca4e2014-02-07 12:40:09 +05304615 }
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004616 csrSaveScanResults(pMac, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07004617
4618#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4619 {
4620 vos_log_scan_pkt_type *pScanLog = NULL;
4621 tScanResultHandle hScanResult;
4622 tCsrScanResultInfo *pScanResult;
4623 tDot11fBeaconIEs *pIes;
4624 int n = 0, c = 0;
4625
4626 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
4627 if(pScanLog)
4628 {
4629 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
4630 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
4631 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
4632 {
4633 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_RSP;
4634 }
4635 else
4636 {
4637 if( eSIR_PASSIVE_SCAN != pMac->scan.curScanType )
4638 {
4639 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_RSP;
4640 }
4641 else
4642 {
4643 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_RSP;
4644 }
4645 }
4646 if(eSIR_SME_SUCCESS == pScanRsp->statusCode)
4647 {
4648 if(HAL_STATUS_SUCCESS(csrScanGetResult(pMac, NULL, &hScanResult)))
4649 {
4650 while(((pScanResult = csrScanResultGetNext(pMac, hScanResult)) != NULL))
4651 {
4652 if( n < VOS_LOG_MAX_NUM_BSSID )
4653 {
4654 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pScanResult->BssDescriptor, &pIes)))
4655 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004656 smsLog(pMac, LOGE, FL(" fail to parse IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07004657 break;
4658 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304659 vos_mem_copy(pScanLog->bssid[n],
4660 pScanResult->BssDescriptor.bssId, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07004661 if(pIes && pIes->SSID.present && VOS_LOG_MAX_SSID_SIZE >= pIes->SSID.num_ssid)
4662 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304663 vos_mem_copy(pScanLog->ssid[n],
4664 pIes->SSID.ssid, pIes->SSID.num_ssid);
Jeff Johnson295189b2012-06-20 16:38:30 -07004665 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304666 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07004667 n++;
4668 }
4669 c++;
4670 }
4671 pScanLog->numSsid = (v_U8_t)n;
4672 pScanLog->totalSsid = (v_U8_t)c;
4673 csrScanResultPurge(pMac, hScanResult);
4674 }
4675 }
4676 else
4677 {
4678 pScanLog->status = WLAN_SCAN_STATUS_FAILURE;
4679 }
4680 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
4681 }
4682 }
4683#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4684
4685 NextCommand = csrScanGetNextCommandState(pMac, pCommand, fSuccess);
4686 //We reuse the command here instead reissue a new command
4687 switch(NextCommand)
4688 {
4689 case eCsrNext11dScan1Success:
4690 case eCsrNext11dScan2Success:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004691 smsLog( pMac, LOG2, FL("11dScan1/3 produced results. Reissue Active scan..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004692 // if we found country information, no need to continue scanning further, bail out
4693 fRemoveCommand = eANI_BOOLEAN_TRUE;
4694 NextCommand = eCsrNext11dScanComplete;
4695 break;
4696 case eCsrNext11dScan1Failure:
4697 //We are not done yet. 11d scan fail once. We will try to reset anything and do it over again
4698 //The only meaningful thing for this retry is that we cannot find 11d information after a reset so
4699 //we clear the "old" 11d info and give it once more chance
4700 fRemoveCommand = csrHandleScan11d1Failure(pMac, pCommand);
4701 if(fRemoveCommand)
4702 {
4703 NextCommand = eCsrNext11dScanComplete;
4704 }
4705 break;
4706 case eCsrNextLostLinkScan1Success:
4707 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink1)))
4708 {
4709 csrScanHandleFailedLostlink1(pMac, sessionId);
4710 }
4711 break;
4712 case eCsrNextLostLinkScan2Success:
4713 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink2)))
4714 {
4715 csrScanHandleFailedLostlink2(pMac, sessionId);
4716 }
4717 break;
4718 case eCsrNextLostLinkScan3Success:
4719 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink3)))
4720 {
4721 csrScanHandleFailedLostlink3(pMac, sessionId);
4722 }
4723 break;
4724 case eCsrNextLostLinkScan1Failed:
4725 csrScanHandleFailedLostlink1(pMac, sessionId);
4726 break;
4727 case eCsrNextLostLinkScan2Failed:
4728 csrScanHandleFailedLostlink2(pMac, sessionId);
4729 break;
4730 case eCsrNextLostLinkScan3Failed:
4731 csrScanHandleFailedLostlink3(pMac, sessionId);
4732 break;
4733 case eCsrNexteScanForSsidSuccess:
4734 csrScanHandleSearchForSSID(pMac, pCommand);
4735 break;
4736 case eCsrNexteScanForSsidFailure:
4737 csrScanHandleSearchForSSIDFailure(pMac, pCommand);
4738 break;
4739 case eCsrNextIdleScanComplete:
4740 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
4741 break;
4742 case eCsrNextCapChangeScanComplete:
4743 csrScanHandleCapChangeScanComplete(pMac, sessionId);
4744 break;
4745 default:
4746
4747 break;
4748 }
4749 }
4750 else
4751 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004752 smsLog( pMac, LOGW, FL("Scan Completion called but SCAN command is not ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004753 fRemoveCommand = eANI_BOOLEAN_FALSE;
4754 }
4755 }
4756 else
4757 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004758 smsLog( pMac, LOGW, FL("Scan Completion called but NO commands are ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004759 fRemoveCommand = eANI_BOOLEAN_FALSE;
4760 }
4761
4762 return( fRemoveCommand );
4763}
4764
4765
4766
4767static void csrScanRemoveDupBssDescriptionFromInterimList( tpAniSirGlobal pMac,
4768 tSirBssDescription *pSirBssDescr,
4769 tDot11fBeaconIEs *pIes)
4770{
4771 tListElem *pEntry;
4772 tCsrScanResult *pCsrBssDescription;
4773
4774 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
4775 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
4776 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
4777 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
4778 while( pEntry )
4779 {
4780 pCsrBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
4781
4782 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
4783 // matches
4784
4785 if ( csrIsDuplicateBssDescription( pMac, &pCsrBssDescription->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07004786 pSirBssDescr, pIes, FALSE ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07004787 {
4788 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
4789 ((tANI_S32)pCsrBssDescription->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
4790
4791 // Remove the 'old' entry from the list....
4792 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK ) )
4793 {
4794 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pCsrBssDescription->Result.BssDescriptor);
4795 // we need to free the memory associated with this node
4796 csrFreeScanResultEntry( pMac, pCsrBssDescription );
4797 }
4798
4799 // If we found a match, we can stop looking through the list.
4800 break;
4801 }
4802
4803 pEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK );
4804 }
4805}
4806
4807
4808
4809//Caller allocated memory pfNewBssForConn to return whether new candidate for
4810//current connection is found. Cannot be NULL
4811tCsrScanResult *csrScanSaveBssDescriptionToInterimList( tpAniSirGlobal pMac,
4812 tSirBssDescription *pBSSDescription,
4813 tDot11fBeaconIEs *pIes)
4814{
4815 tCsrScanResult *pCsrBssDescription = NULL;
4816 tANI_U32 cbBSSDesc;
4817 tANI_U32 cbAllocated;
Jeff Johnson295189b2012-06-20 16:38:30 -07004818
4819 // figure out how big the BSS description is (the BSSDesc->length does NOT
4820 // include the size of the length field itself).
4821 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
4822
4823 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
4824
Kiet Lam64c1b492013-07-12 13:56:44 +05304825 pCsrBssDescription = vos_mem_malloc(cbAllocated);
4826 if ( NULL != pCsrBssDescription )
Jeff Johnson295189b2012-06-20 16:38:30 -07004827 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304828 vos_mem_set(pCsrBssDescription, cbAllocated, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004829 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Kiet Lam64c1b492013-07-12 13:56:44 +05304830 vos_mem_copy(&pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc );
Jeff Johnson295189b2012-06-20 16:38:30 -07004831 //Save SSID separately for later use
4832 if( pIes->SSID.present && !csrIsNULLSSID(pIes->SSID.ssid, pIes->SSID.num_ssid) )
4833 {
4834 //SSID not hidden
Madan Mohan Koyyalamudi4e31b132012-11-02 13:13:52 -07004835 tANI_U32 len = pIes->SSID.num_ssid;
Jeff Johnson295189b2012-06-20 16:38:30 -07004836 if (len > SIR_MAC_MAX_SSID_LENGTH)
4837 {
4838 // truncate to fit in our struct
4839 len = SIR_MAC_MAX_SSID_LENGTH;
4840 }
4841 pCsrBssDescription->Result.ssId.length = len;
4842 pCsrBssDescription->Result.timer = vos_timer_get_system_time();
Kiet Lam64c1b492013-07-12 13:56:44 +05304843 vos_mem_copy(pCsrBssDescription->Result.ssId.ssId, pIes->SSID.ssid, len);
Jeff Johnson295189b2012-06-20 16:38:30 -07004844 }
4845 csrLLInsertTail( &pMac->scan.tempScanResults, &pCsrBssDescription->Link, LL_ACCESS_LOCK );
4846 }
4847
4848 return( pCsrBssDescription );
4849}
4850
4851
4852
4853
4854tANI_BOOLEAN csrIsDuplicateBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc1,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07004855 tSirBssDescription *pSirBssDesc2, tDot11fBeaconIEs *pIes2, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07004856{
4857 tANI_BOOLEAN fMatch = FALSE;
4858 tSirMacCapabilityInfo *pCap1, *pCap2;
4859 tDot11fBeaconIEs *pIes1 = NULL;
Jeff Johnsone7245742012-09-05 17:12:55 -07004860 tDot11fBeaconIEs *pIesTemp = pIes2;
Jeff Johnson295189b2012-06-20 16:38:30 -07004861
4862 pCap1 = (tSirMacCapabilityInfo *)&pSirBssDesc1->capabilityInfo;
4863 pCap2 = (tSirMacCapabilityInfo *)&pSirBssDesc2->capabilityInfo;
4864 if(pCap1->ess == pCap2->ess)
4865 {
4866 if (pCap1->ess &&
Jeff Johnsone7245742012-09-05 17:12:55 -07004867 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId)&&
Abhishek Singhe3fa11f2014-05-13 11:11:10 +05304868 (fForced || (vos_chan_to_band(pSirBssDesc1->channelId) == vos_chan_to_band((pSirBssDesc2->channelId)))))
Jeff Johnson295189b2012-06-20 16:38:30 -07004869 {
4870 fMatch = TRUE;
Jeff Johnsone7245742012-09-05 17:12:55 -07004871 // Check for SSID match, if exists
4872 do
4873 {
4874 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
4875 {
4876 break;
4877 }
4878 if( NULL == pIesTemp )
4879 {
4880 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
4881 {
4882 break;
4883 }
4884 }
4885 if(pIes1->SSID.present && pIesTemp->SSID.present)
4886 {
4887 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
4888 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
4889 }
4890 }while(0);
4891
Jeff Johnson295189b2012-06-20 16:38:30 -07004892 }
4893 else if (pCap1->ibss && (pSirBssDesc1->channelId == pSirBssDesc2->channelId))
4894 {
Jeff Johnson295189b2012-06-20 16:38:30 -07004895
4896 do
4897 {
4898 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
4899 {
4900 break;
4901 }
4902 if( NULL == pIesTemp )
4903 {
4904 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
4905 {
4906 break;
4907 }
4908 }
4909 //Same channel cannot have same SSID for different IBSS
4910 if(pIes1->SSID.present && pIesTemp->SSID.present)
4911 {
4912 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
4913 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
4914 }
4915 }while(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004916 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004917 /* In case of P2P devices, ess and ibss will be set to zero */
4918 else if (!pCap1->ess &&
4919 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId))
4920 {
4921 fMatch = TRUE;
4922 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004923 }
4924
4925 if(pIes1)
4926 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304927 vos_mem_free(pIes1);
Jeff Johnson295189b2012-06-20 16:38:30 -07004928 }
Jeff Johnsone7245742012-09-05 17:12:55 -07004929
4930 if( (NULL == pIes2) && pIesTemp )
4931 {
4932 //locally allocated
Kiet Lam64c1b492013-07-12 13:56:44 +05304933 vos_mem_free(pIesTemp);
Jeff Johnsone7245742012-09-05 17:12:55 -07004934 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004935
4936 return( fMatch );
4937}
4938
4939
4940tANI_BOOLEAN csrIsNetworkTypeEqual( tSirBssDescription *pSirBssDesc1, tSirBssDescription *pSirBssDesc2 )
4941{
4942 return( pSirBssDesc1->nwType == pSirBssDesc2->nwType );
4943}
4944
4945
4946//to check whether the BSS matches the dot11Mode
4947static tANI_BOOLEAN csrScanIsBssAllowed(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
4948 tDot11fBeaconIEs *pIes)
4949{
4950 tANI_BOOLEAN fAllowed = eANI_BOOLEAN_FALSE;
4951 eCsrPhyMode phyMode;
4952
4953 if(HAL_STATUS_SUCCESS(csrGetPhyModeFromBss(pMac, pBssDesc, &phyMode, pIes)))
4954 {
4955 switch(pMac->roam.configParam.phyMode)
4956 {
4957 case eCSR_DOT11_MODE_11b:
4958 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
4959 break;
4960 case eCSR_DOT11_MODE_11g:
4961 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
4962 break;
4963 case eCSR_DOT11_MODE_11g_ONLY:
4964 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11g == phyMode);
4965 break;
4966 case eCSR_DOT11_MODE_11a:
4967 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11b != phyMode) && (eCSR_DOT11_MODE_11g != phyMode));
4968 break;
4969 case eCSR_DOT11_MODE_11n_ONLY:
4970 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11n == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
4971 break;
Jeff Johnsone7245742012-09-05 17:12:55 -07004972
4973#ifdef WLAN_FEATURE_11AC
4974 case eCSR_DOT11_MODE_11ac_ONLY:
4975 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11ac == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
4976 break;
4977#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004978 case eCSR_DOT11_MODE_11b_ONLY:
4979 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11b == phyMode);
4980 break;
4981 case eCSR_DOT11_MODE_11a_ONLY:
4982 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a == phyMode);
4983 break;
4984 case eCSR_DOT11_MODE_11n:
Jeff Johnsone7245742012-09-05 17:12:55 -07004985#ifdef WLAN_FEATURE_11AC
4986 case eCSR_DOT11_MODE_11ac:
4987#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004988 case eCSR_DOT11_MODE_TAURUS:
4989 default:
4990 fAllowed = eANI_BOOLEAN_TRUE;
4991 break;
4992 }
4993 }
4994
4995 return (fAllowed);
4996}
4997
4998
4999
5000//Return pIes to caller for future use when returning TRUE.
5001static tANI_BOOLEAN csrScanValidateScanResult( tpAniSirGlobal pMac, tANI_U8 *pChannels,
5002 tANI_U8 numChn, tSirBssDescription *pBssDesc,
5003 tDot11fBeaconIEs **ppIes )
5004{
5005 tANI_BOOLEAN fValidChannel = FALSE;
5006 tDot11fBeaconIEs *pIes = NULL;
5007 tANI_U8 index;
5008
5009 for( index = 0; index < numChn; index++ )
5010 {
5011 // This check relies on the fact that a single BSS description is returned in each
5012 // ScanRsp call, which is the way LIM implemented the scan req/rsp funtions. We changed
5013 // to this model when we ran with a large number of APs. If this were to change, then
5014 // this check would have to mess with removing the bssDescription from somewhere in an
5015 // arbitrary index in the bssDescription array.
5016 if ( pChannels[ index ] == pBssDesc->channelId )
5017 {
5018 fValidChannel = TRUE;
5019 break;
5020 }
5021 }
5022 *ppIes = NULL;
5023 if(fValidChannel)
5024 {
5025 if( HAL_STATUS_SUCCESS( csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIes) ) )
5026 {
5027 fValidChannel = csrScanIsBssAllowed(pMac, pBssDesc, pIes);
5028 if( fValidChannel )
5029 {
5030 *ppIes = pIes;
5031 }
5032 else
5033 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305034 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07005035 }
5036 }
5037 else
5038 {
5039 fValidChannel = FALSE;
5040 }
5041 }
5042
5043 return( fValidChannel );
5044}
5045
5046
5047//Return whether last scan result is received
5048static tANI_BOOLEAN csrScanProcessScanResults( tpAniSirGlobal pMac, tSmeCmd *pCommand,
5049 tSirSmeScanRsp *pScanRsp, tANI_BOOLEAN *pfRemoveCommand )
5050{
5051 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE, fRemoveCommand = eANI_BOOLEAN_FALSE;
5052 tDot11fBeaconIEs *pIes = NULL;
5053 tANI_U32 cbParsed;
5054 tSirBssDescription *pSirBssDescription;
5055 tANI_U32 cbBssDesc;
5056 tANI_U32 cbScanResult = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription )
5057 + sizeof(tSirBssDescription); //We need at least one CB
5058
5059 // don't consider the scan rsp to be valid if the status code is Scan Failure. Scan Failure
5060 // is returned when the scan could not find anything. so if we get scan failure return that
5061 // the scan response is invalid. Also check the lenght in the scan result for valid scan
5062 // BssDescriptions....
5063 do
5064 {
5065 if ( ( cbScanResult <= pScanRsp->length ) &&
5066 (( eSIR_SME_SUCCESS == pScanRsp->statusCode ) ||
5067 ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW == pScanRsp->statusCode ) ) )
5068 {
5069 tANI_U8 *pChannelList = NULL;
5070 tANI_U8 cChannels = 0;
5071
5072 //Different scan type can reach this point, we need to distinguish it
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005073#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5074 if( eCsrScanGetLfrResult == pCommand->u.scanCmd.reason )
5075 {
5076 pChannelList = NULL;
5077 cChannels = 0;
5078 }
5079 else
5080#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005081 if( eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason )
5082 {
5083 //eCsrScanSetBGScanParam uses different structure
5084 tCsrBGScanRequest *pBgScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
5085
5086 cChannels = pBgScanReq->ChannelInfo.numOfChannels;
5087 pChannelList = pBgScanReq->ChannelInfo.ChannelList;
5088 }
5089 else
5090 {
5091 //the rest use generic scan request
5092 cChannels = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
5093 pChannelList = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
5094 }
5095
5096 // if the scan result is not on one of the channels in the Valid channel list, then it
5097 // must have come from an AP on an overlapping channel (in the 2.4GHz band). In this case,
5098 // let's drop the scan result.
5099 //
5100 // The other situation is where the scan request is for a scan on a particular channel set
5101 // and the scan result is from a
5102
5103 // if the NumChannels is 0, then we are supposed to be scanning all channels. Use the full channel
5104 // list as the 'valid' channel list. Otherwise, use the specific channel list in the scan parms
5105 // as the valid channels.
5106 if ( 0 == cChannels )
5107 {
5108 tANI_U32 len = sizeof(pMac->roam.validChannelList);
5109
5110 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
5111 {
5112 pChannelList = pMac->roam.validChannelList;
5113 cChannels = (tANI_U8)len;
5114 }
5115 else
5116 {
5117 //Cannot continue
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005118 smsLog( pMac, LOGE, "CSR: Processing internal SCAN results...csrGetCfgValidChannels failed" );
Jeff Johnson295189b2012-06-20 16:38:30 -07005119 break;
5120 }
5121 }
5122
5123 smsLog( pMac, LOG2, "CSR: Processing internal SCAN results..." );
5124 cbParsed = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription );
5125 pSirBssDescription = pScanRsp->bssDescription;
5126 while( cbParsed < pScanRsp->length )
5127 {
5128 if ( csrScanValidateScanResult( pMac, pChannelList, cChannels, pSirBssDescription, &pIes ) )
5129 {
5130 csrScanRemoveDupBssDescriptionFromInterimList(pMac, pSirBssDescription, pIes);
5131 csrScanSaveBssDescriptionToInterimList( pMac, pSirBssDescription, pIes );
5132 if( eSIR_PASSIVE_SCAN == pMac->scan.curScanType )
5133 {
5134 if( csrIs11dSupported( pMac) )
5135 {
5136 //Check whether the BSS is acceptable base on 11d info and our configs.
5137 if( csrMatchCountryCode( pMac, NULL, pIes ) )
5138 {
5139 //Double check whether the channel is acceptable by us.
5140 if( csrIsSupportedChannel( pMac, pSirBssDescription->channelId ) )
5141 {
5142 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
5143 }
5144 }
5145 }
5146 else
5147 {
5148 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
5149 }
5150 }
5151 //Free the resource
Kiet Lam64c1b492013-07-12 13:56:44 +05305152 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07005153 }
5154 // skip over the BSS description to the next one...
5155 cbBssDesc = pSirBssDescription->length + sizeof( pSirBssDescription->length );
5156
5157 cbParsed += cbBssDesc;
5158 pSirBssDescription = (tSirBssDescription *)((tANI_U8 *)pSirBssDescription + cbBssDesc );
5159
5160 } //while
5161 }
5162 else
5163 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005164 smsLog( pMac, LOGW, " Scanrsp fail (0x%08X), length = %d (expected %d)",
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08005165 pScanRsp->statusCode, pScanRsp->length, cbScanResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07005166 //HO bg scan/probe failed no need to try autonomously
5167 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
5168 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005169#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5170 eCsrScanGetLfrResult == pCommand->u.scanCmd.reason ||
5171#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005172 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
5173 {
5174 fRemoveCommand = eANI_BOOLEAN_TRUE;
5175 }
5176 }
5177 }while(0);
5178 if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
5179 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005180 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 -07005181 fRemoveCommand = csrScanComplete( pMac, pScanRsp );
5182 fRet = eANI_BOOLEAN_TRUE;
5183 }//if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
5184 if(pfRemoveCommand)
5185 {
5186 *pfRemoveCommand = fRemoveCommand;
5187 }
5188
5189#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305190 if (pMac->fScanOffload)
5191 return fRet;
5192
Jeff Johnson295189b2012-06-20 16:38:30 -07005193 if (!csrLLIsListEmpty( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK ))
5194 {
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005195 /* Pending scan commands in the list because the previous scan command
5196 * was split into a scan command on one channel + a scan command for all
5197 * remaining channels.
5198 *
5199 * Start timer to trigger processing of the next scan command.
Srikant Kuppa866893f2012-12-27 17:28:14 -08005200 * NOTE for LFR:
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305201 * Do not split scans if no concurrent infra connections are
Srikant Kuppa866893f2012-12-27 17:28:14 -08005202 * active and if the scan is a BG scan triggered by LFR (OR)
5203 * any scan if LFR is in the middle of a BG scan. Splitting
5204 * the scan is delaying the time it takes for LFR to find
5205 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005206 */
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305207 if ( (csrIsStaSessionConnected(pMac) &&
Srikant Kuppa866893f2012-12-27 17:28:14 -08005208#ifdef FEATURE_WLAN_LFR
5209 (csrIsConcurrentInfraConnected(pMac) ||
5210 ((pCommand->u.scanCmd.reason != eCsrScanBgScan) &&
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305211 (pMac->roam.neighborRoamInfo.neighborRoamState !=
Srikant Kuppa866893f2012-12-27 17:28:14 -08005212 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
5213#endif
5214 (pCommand->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305215 (csrIsP2pSessionConnected(pMac)) )
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005216 {
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005217 /* if active connected sessions present then continue to split scan
5218 * with specified interval between consecutive scans */
5219 csrSetDefaultScanTiming(pMac, pCommand->u.scanCmd.u.scanRequest.scanType, &(pCommand->u.scanCmd.u.scanRequest));
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05305220 vos_timer_start(&pMac->scan.hTimerStaApConcTimer,
5221 pCommand->u.scanCmd.u.scanRequest.restTime);
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005222 } else {
5223 /* if no connected sessions present then initiate next scan command immediately */
5224 /* minimum timer granularity is 10ms */
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05305225 vos_timer_start(&pMac->scan.hTimerStaApConcTimer, 10);
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005226 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005227 }
5228#endif
5229 return (fRet);
5230}
5231
5232
5233tANI_BOOLEAN csrScanIsWildCardScan( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5234{
5235 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
Kiet Lam64c1b492013-07-12 13:56:44 +05305236 tANI_BOOLEAN f = vos_mem_compare(pCommand->u.scanCmd.u.scanRequest.bssid,
5237 bssid, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07005238
5239 //It is not a wild card scan if the bssid is not broadcast and the number of SSID is 1.
5240 return ((tANI_BOOLEAN)( (f || (0xff == pCommand->u.scanCmd.u.scanRequest.bssid[0])) &&
5241 (pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs != 1) ));
5242}
5243
5244
5245eHalStatus csrScanSmeScanResponse( tpAniSirGlobal pMac, void *pMsgBuf )
5246{
5247 eHalStatus status = eHAL_STATUS_SUCCESS;
5248 tListElem *pEntry;
5249 tSmeCmd *pCommand;
5250 eCsrScanStatus scanStatus;
5251 tSirSmeScanRsp *pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
5252 tSmeGetScanChnRsp *pScanChnInfo;
5253 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
5254 eCsrScanReason reason = eCsrScanOther;
5255
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305256 if (pMac->fScanOffload)
5257 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList,
5258 LL_ACCESS_LOCK);
5259 else
5260 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07005261
5262 if ( pEntry )
5263 {
5264 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
5265 if ( eSmeCommandScan == pCommand->command )
5266 {
5267 scanStatus = (eSIR_SME_SUCCESS == pScanRsp->statusCode) ? eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
5268 reason = pCommand->u.scanCmd.reason;
5269 switch(pCommand->u.scanCmd.reason)
5270 {
5271 case eCsrScanAbortBgScan:
5272 case eCsrScanAbortNormalScan:
5273 case eCsrScanBGScanAbort:
5274 case eCsrScanBGScanEnable:
5275 break;
5276 case eCsrScanGetScanChnInfo:
5277 pScanChnInfo = (tSmeGetScanChnRsp *)pMsgBuf;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005278 /*
5279 * status code not available in tSmeGetScanChnRsp, so
5280 * by default considereing it to be success
5281 */
5282 scanStatus = eSIR_SME_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07005283 csrScanAgeResults(pMac, pScanChnInfo);
5284 break;
5285 case eCsrScanForCapsChange:
5286 csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand );
5287 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005288 case eCsrScanP2PFindPeer:
5289 scanStatus = ((eSIR_SME_SUCCESS == pScanRsp->statusCode) && (pScanRsp->length > 50)) ? eCSR_SCAN_FOUND_PEER : eCSR_SCAN_FAILURE;
5290 csrScanProcessScanResults( pMac, pCommand, pScanRsp, NULL );
5291 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005292 case eCsrScanSetBGScanParam:
5293 default:
5294 if(csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand ))
5295 {
5296 //Not to get channel info if the scan is not a wildcard scan because
5297 //it may cause scan results got aged out incorrectly.
Ratheesh S Pece1f832015-07-25 15:50:25 +05305298 if(csrScanIsWildCardScan( pMac, pCommand ) &&
5299 (!pCommand->u.scanCmd.u.scanRequest.p2pSearch)
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005300#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5301 && (pCommand->u.scanCmd.reason != eCsrScanGetLfrResult)
5302#endif
5303 )
Jeff Johnson295189b2012-06-20 16:38:30 -07005304 {
Ratheesh S Pece1f832015-07-25 15:50:25 +05305305 csrScanGetScanChnInfo(pMac, pCommand);
Jeff Johnson295189b2012-06-20 16:38:30 -07005306 }
5307 }
5308 break;
5309 }//switch
5310 if(fRemoveCommand)
5311 {
5312
5313 csrReleaseScanCommand(pMac, pCommand, scanStatus);
5314
Srikant Kuppa866893f2012-12-27 17:28:14 -08005315 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005316 smeProcessPendingQueue( pMac );
5317 }
5318 else
5319 {
5320 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
5321 status = eHAL_STATUS_FAILURE;
5322 }
5323 }
5324 else
5325 {
5326 smsLog( pMac, LOGW, "CSR: Scan Completion called but NO commands are ACTIVE ..." );
5327 status = eHAL_STATUS_FAILURE;
5328 }
5329
5330 return (status);
5331}
5332
5333
5334
5335
5336tCsrScanResultInfo *csrScanResultGetFirst(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
5337{
5338 tListElem *pEntry;
5339 tCsrScanResult *pResult;
5340 tCsrScanResultInfo *pRet = NULL;
5341 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5342
5343 if(pResultList)
5344 {
5345 csrLLLock(&pResultList->List);
5346 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5347 if(pEntry)
5348 {
5349 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
5350 pRet = &pResult->Result;
5351 }
5352 pResultList->pCurEntry = pEntry;
5353 csrLLUnlock(&pResultList->List);
5354 }
5355
5356 return pRet;
5357}
5358
5359
5360tCsrScanResultInfo *csrScanResultGetNext(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
5361{
5362 tListElem *pEntry = NULL;
5363 tCsrScanResult *pResult = NULL;
5364 tCsrScanResultInfo *pRet = NULL;
5365 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5366
5367 if(pResultList)
5368 {
5369 csrLLLock(&pResultList->List);
5370 if(NULL == pResultList->pCurEntry)
5371 {
5372 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5373 }
5374 else
5375 {
5376 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
5377 }
5378 if(pEntry)
5379 {
5380 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
5381 pRet = &pResult->Result;
5382 }
5383 pResultList->pCurEntry = pEntry;
5384 csrLLUnlock(&pResultList->List);
5385 }
5386
5387 return pRet;
5388}
5389
5390
5391//This function moves the first BSS that matches the bssid to the head of the result
5392eHalStatus csrMoveBssToHeadFromBSSID(tpAniSirGlobal pMac, tCsrBssid *bssid, tScanResultHandle hScanResult)
5393{
5394 eHalStatus status = eHAL_STATUS_FAILURE;
5395 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5396 tCsrScanResult *pResult = NULL;
5397 tListElem *pEntry = NULL;
5398
5399 if(pResultList && bssid)
5400 {
5401 csrLLLock(&pResultList->List);
5402 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5403 while(pEntry)
5404 {
5405 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
Kiet Lam64c1b492013-07-12 13:56:44 +05305406 if (vos_mem_compare(bssid, pResult->Result.BssDescriptor.bssId, sizeof(tCsrBssid)))
Jeff Johnson295189b2012-06-20 16:38:30 -07005407 {
5408 status = eHAL_STATUS_SUCCESS;
5409 csrLLRemoveEntry(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
5410 csrLLInsertHead(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
5411 break;
5412 }
5413 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
5414 }
5415 csrLLUnlock(&pResultList->List);
5416 }
5417
5418 return (status);
5419}
5420
5421
5422//Remove the BSS if possible.
5423//Return -- TRUE == the BSS is remove. False == Fail to remove it
5424//This function is called when list lock is held. Be caution what functions it can call.
5425tANI_BOOLEAN csrScanAgeOutBss(tpAniSirGlobal pMac, tCsrScanResult *pResult)
5426{
5427 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
5428 tANI_U32 i;
5429 tCsrRoamSession *pSession;
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305430 tANI_BOOLEAN isConnBssfound = eANI_BOOLEAN_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005431
5432 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5433 {
5434 if( CSR_IS_SESSION_VALID( pMac, i ) )
5435 {
5436 pSession = CSR_GET_SESSION( pMac, i );
5437 //Not to remove the BSS we are connected to.
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305438 if(csrIsConnStateConnectedInfra(pMac, i) && (NULL != pSession->pConnectBssDesc) &&
5439 (csrIsDuplicateBssDescription(pMac, &pResult->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07005440 pSession->pConnectBssDesc, NULL, FALSE))
Jeff Johnson295189b2012-06-20 16:38:30 -07005441 )
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305442 {
5443 isConnBssfound = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005444 break;
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305445 }
5446 }
5447 }
5448
5449 if( isConnBssfound )
Jeff Johnson295189b2012-06-20 16:38:30 -07005450 {
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305451 //Reset the counter so that aging out of connected BSS won't hapeen too soon
Jeff Johnson295189b2012-06-20 16:38:30 -07005452 pResult->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
5453 pResult->Result.BssDescriptor.nReceivedTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305454
5455 return (fRet);
5456 }
5457 else
5458 {
5459 smsLog(pMac, LOGW, "Aging out BSS "MAC_ADDRESS_STR" Channel %d",
5460 MAC_ADDR_ARRAY(pResult->Result.BssDescriptor.bssId),
5461 pResult->Result.BssDescriptor.channelId);
5462 //No need to hold the spin lock because caller should hold the lock for pMac->scan.scanResultList
5463 if( csrLLRemoveEntry(&pMac->scan.scanResultList, &pResult->Link, LL_ACCESS_NOLOCK) )
5464 {
5465 if (csrIsMacAddressEqual(pMac,
5466 (tCsrBssid *) pResult->Result.BssDescriptor.bssId,
5467 (tCsrBssid *) pMac->scan.currentCountryBssid))
5468 {
5469 smsLog(pMac, LOGW, "Aging out 11d BSS "MAC_ADDRESS_STR,
5470 MAC_ADDR_ARRAY(pResult->Result.BssDescriptor.bssId));
5471 pMac->scan.currentCountryRSSI = -128;
5472 }
5473 csrFreeScanResultEntry(pMac, pResult);
5474 fRet = eANI_BOOLEAN_TRUE;
5475 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005476 }
5477
5478 return (fRet);
5479}
5480
5481
5482eHalStatus csrScanAgeResults(tpAniSirGlobal pMac, tSmeGetScanChnRsp *pScanChnInfo)
5483{
5484 eHalStatus status = eHAL_STATUS_SUCCESS;
5485 tListElem *pEntry, *tmpEntry;
5486 tCsrScanResult *pResult;
5487 tLimScanChn *pChnInfo;
5488 tANI_U8 i;
5489
5490 csrLLLock(&pMac->scan.scanResultList);
5491 for(i = 0; i < pScanChnInfo->numChn; i++)
5492 {
5493 pChnInfo = &pScanChnInfo->scanChn[i];
5494 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
5495 while( pEntry )
5496 {
5497 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
5498 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
5499 if(pResult->Result.BssDescriptor.channelId == pChnInfo->channelId)
5500 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005501 if(pResult->AgingCount <= 0)
5502 {
5503 smsLog(pMac, LOGW, " age out due to ref count");
5504 csrScanAgeOutBss(pMac, pResult);
5505 }
Madan Mohan Koyyalamudib9d3dcc2012-09-28 16:47:50 -07005506 else
5507 {
5508 pResult->AgingCount--;
5509 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005510 }
5511 pEntry = tmpEntry;
5512 }
5513 }
5514 csrLLUnlock(&pMac->scan.scanResultList);
5515
5516 return (status);
5517}
5518
Abhishek Singhc640dbb2015-06-08 10:54:17 +05305519eHalStatus csrIbssAgeBss(tpAniSirGlobal pMac)
5520{
5521 eHalStatus status = eHAL_STATUS_SUCCESS;
5522 tListElem *pEntry, *tmpEntry;
5523 tCsrScanResult *pResult;
5524
5525 csrLLLock(&pMac->scan.scanResultList);
5526 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
5527 while( pEntry )
5528 {
5529 tmpEntry = csrLLNext(&pMac->scan.scanResultList,
5530 pEntry, LL_ACCESS_NOLOCK);
5531 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
5532
5533 smsLog(pMac, LOGW, FL(" age out due Forced IBSS leave"));
5534 csrScanAgeOutBss(pMac, pResult);
5535 pEntry = tmpEntry;
5536 }
5537 csrLLUnlock(&pMac->scan.scanResultList);
5538
5539 return (status);
5540}
Jeff Johnson295189b2012-06-20 16:38:30 -07005541
5542eHalStatus csrSendMBScanReq( tpAniSirGlobal pMac, tANI_U16 sessionId,
5543 tCsrScanRequest *pScanReq, tScanReqParam *pScanReqParam )
5544{
5545 eHalStatus status = eHAL_STATUS_SUCCESS;
5546 tSirSmeScanReq *pMsg;
5547 tANI_U16 msgLen;
5548 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
5549 tSirScanType scanType = pScanReq->scanType;
5550 tANI_U32 minChnTime; //in units of milliseconds
5551 tANI_U32 maxChnTime; //in units of milliseconds
5552 tANI_U32 i;
5553 tANI_U8 selfMacAddr[WNI_CFG_BSSID_LEN];
5554 tANI_U8 *pSelfMac = NULL;
5555
5556 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
5557 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) +
5558 ( pScanReq->uIEFieldLen ) ;
5559
Kiet Lam64c1b492013-07-12 13:56:44 +05305560 pMsg = vos_mem_malloc(msgLen);
5561 if ( NULL == pMsg )
5562 status = eHAL_STATUS_FAILURE;
5563 else
5564 status = eHAL_STATUS_SUCCESS;
5565 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07005566 {
5567 do
5568 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305569 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005570 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
5571 pMsg->length = pal_cpu_to_be16(msgLen);
5572 //ToDO: Fill in session info when we need to do scan base on session.
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05305573 if ((pMac->fScanOffload) && (sessionId != CSR_SESSION_ID_INVALID))
5574 {
5575 pMsg->sessionId = sessionId;
5576 }
5577 else
5578 {
5579 /* if sessionId == CSR_SESSION_ID_INVALID, then send the scan
5580 request on first available session */
5581 pMsg->sessionId = 0;
5582 }
5583
Jeff Johnson295189b2012-06-20 16:38:30 -07005584 pMsg->transactionId = 0;
5585 pMsg->dot11mode = (tANI_U8) csrTranslateToWNICfgDot11Mode(pMac, csrFindBestPhyMode( pMac, pMac->roam.configParam.phyMode ));
5586 pMsg->bssType = pal_cpu_to_be32(csrTranslateBsstypeToMacType(pScanReq->BSSType));
5587
5588 if ( CSR_IS_SESSION_VALID( pMac, sessionId ) )
5589 {
5590 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[sessionId].selfMacAddr;
5591 }
5592 else
5593 {
5594 // Since we don't have session for the scanning, we find a valid session. In case we fail to
5595 // do so, get the WNI_CFG_STA_ID
5596 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5597 {
5598 if( CSR_IS_SESSION_VALID( pMac, i ) )
5599 {
5600 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[i].selfMacAddr;
5601 break;
5602 }
5603 }
5604 if( CSR_ROAM_SESSION_MAX == i )
5605 {
5606 tANI_U32 len = WNI_CFG_BSSID_LEN;
5607 pSelfMac = selfMacAddr;
5608 status = ccmCfgGetStr( pMac, WNI_CFG_STA_ID, pSelfMac, &len );
5609 if( !HAL_STATUS_SUCCESS( status ) ||
5610 ( len < WNI_CFG_BSSID_LEN ) )
5611 {
5612 smsLog( pMac, LOGE, FL(" Can not get self MAC address from CFG status = %d"), status );
5613 //Force failed status
5614 status = eHAL_STATUS_FAILURE;
5615 break;
5616 }
5617 }
5618 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305619 vos_mem_copy((tANI_U8 *)pMsg->selfMacAddr, pSelfMac, sizeof(tSirMacAddr));
Jeff Johnson295189b2012-06-20 16:38:30 -07005620
5621 //sirCopyMacAddr
Kiet Lam64c1b492013-07-12 13:56:44 +05305622 vos_mem_copy((tANI_U8 *)pMsg->bssId, (tANI_U8 *)&pScanReq->bssid, sizeof(tSirMacAddr));
5623 if ( vos_mem_compare(pScanReq->bssid, bssid, sizeof(tCsrBssid)))
Jeff Johnson295189b2012-06-20 16:38:30 -07005624 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305625 vos_mem_set(pMsg->bssId, sizeof(tSirMacAddr), 0xff);
Jeff Johnson295189b2012-06-20 16:38:30 -07005626 }
5627 else
5628 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305629 vos_mem_copy(pMsg->bssId, pScanReq->bssid, WNI_CFG_BSSID_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07005630 }
5631 minChnTime = pScanReq->minChnTime;
5632 maxChnTime = pScanReq->maxChnTime;
5633
5634 //Verify the scan type first, if the scan is active scan, we need to make sure we
5635 //are allowed to do so.
5636 /* if 11d is enabled & we don't see any beacon around, scan type falls
5637 back to passive. But in BT AMP STA mode we need to send out a
5638 directed probe*/
5639 if( (eSIR_PASSIVE_SCAN != scanType) && (eCSR_SCAN_P2P_DISCOVERY != pScanReq->requestType)
5640 && (eCSR_BSS_TYPE_WDS_STA != pScanReq->BSSType)
5641 && (eANI_BOOLEAN_FALSE == pMac->scan.fEnableBypass11d))
5642 {
5643 scanType = pMac->scan.curScanType;
5644 if(eSIR_PASSIVE_SCAN == pMac->scan.curScanType)
5645 {
5646 if(minChnTime < pMac->roam.configParam.nPassiveMinChnTime)
5647 {
5648 minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
5649 }
5650 if(maxChnTime < pMac->roam.configParam.nPassiveMaxChnTime)
5651 {
5652 maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
5653 }
5654 }
5655 }
5656 pMsg->scanType = pal_cpu_to_be32(scanType);
5657
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05305658 pMsg->numSsid =
5659 (pScanReq->SSIDs.numOfSSIDs < SIR_SCAN_MAX_NUM_SSID) ?
5660 pScanReq->SSIDs.numOfSSIDs : SIR_SCAN_MAX_NUM_SSID;
Jeff Johnson295189b2012-06-20 16:38:30 -07005661 if((pScanReq->SSIDs.numOfSSIDs != 0) && ( eSIR_PASSIVE_SCAN != scanType ))
5662 {
Jeff Johnson40b59aa2013-03-19 14:43:18 -07005663 for (i = 0; i < pMsg->numSsid; i++)
5664 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305665 vos_mem_copy(&pMsg->ssId[i],
5666 &pScanReq->SSIDs.SSIDList[i].SSID, sizeof(tSirMacSSid));
Jeff Johnson40b59aa2013-03-19 14:43:18 -07005667 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005668 }
5669 else
5670 {
5671 //Otherwise we scan all SSID and let the result filter later
Jeff Johnson40b59aa2013-03-19 14:43:18 -07005672 for (i = 0; i < SIR_SCAN_MAX_NUM_SSID; i++)
5673 {
5674 pMsg->ssId[i].length = 0;
5675 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005676 }
5677
Jeff Johnson295189b2012-06-20 16:38:30 -07005678 pMsg->minChannelTime = pal_cpu_to_be32(minChnTime);
5679 pMsg->maxChannelTime = pal_cpu_to_be32(maxChnTime);
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08005680 pMsg->minChannelTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
5681 pMsg->maxChannelTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07005682 //hidden SSID option
5683 pMsg->hiddenSsid = pScanReqParam->hiddenSsid;
5684 //rest time
5685 //pMsg->restTime = pScanReq->restTime;
5686 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
5687 // All the scan results caching will be done by Roaming
5688 // We do not want LIM to do any caching of scan results,
5689 // so delete the LIM cache on all scan requests
5690 pMsg->returnFreshResults = pScanReqParam->freshScan;
5691 //Always ask for unique result
5692 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
5693 pMsg->channelList.numChannels = (tANI_U8)pScanReq->ChannelInfo.numOfChannels;
5694 if(pScanReq->ChannelInfo.numOfChannels)
5695 {
5696 //Assuming the channelNumber is tANI_U8 (1 byte)
Kiet Lam64c1b492013-07-12 13:56:44 +05305697 vos_mem_copy(pMsg->channelList.channelNumber,
5698 pScanReq->ChannelInfo.ChannelList,
5699 pScanReq->ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07005700 }
5701
5702 pMsg->uIEFieldLen = (tANI_U16) pScanReq->uIEFieldLen;
5703 pMsg->uIEFieldOffset = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
5704 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) ;
5705 if(pScanReq->uIEFieldLen != 0)
5706 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305707 vos_mem_copy((tANI_U8 *)pMsg+pMsg->uIEFieldOffset, pScanReq->pIEField,
5708 pScanReq->uIEFieldLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07005709 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005710 pMsg->p2pSearch = pScanReq->p2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07005711
Madan Mohan Koyyalamudi9b876782012-10-11 16:22:51 -07005712 if (pScanReq->requestType == eCSR_SCAN_HO_BG_SCAN)
5713 {
5714 pMsg->backgroundScanMode = eSIR_ROAMING_SCAN;
5715 }
5716
Jeff Johnson295189b2012-06-20 16:38:30 -07005717 }while(0);
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05305718 smsLog(pMac, LOG1, FL("domainIdCurrent %s (%d) scanType %s (%d)"
5719 "bssType %s (%d), requestType %s(%d)"
5720 "numChannels %d"),
5721 voss_DomainIdtoString(pMac->scan.domainIdCurrent),
5722 pMac->scan.domainIdCurrent,
5723 lim_ScanTypetoString(pMsg->scanType), pMsg->scanType,
5724 lim_BssTypetoString(pMsg->bssType), pMsg->bssType,
5725 sme_requestTypetoString(pScanReq->requestType),
5726 pScanReq->requestType,
5727 pMsg->channelList.numChannels);
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005728
5729 for(i = 0; i < pMsg->channelList.numChannels; i++)
5730 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005731 smsLog(pMac, LOG3, FL("channelNumber[%d]= %d"), i, pMsg->channelList.channelNumber[i]);
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005732 }
5733
Jeff Johnson295189b2012-06-20 16:38:30 -07005734 if(HAL_STATUS_SUCCESS(status))
5735 {
5736 status = palSendMBMessage(pMac->hHdd, pMsg);
5737 }
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005738 else
5739 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005740 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d"), status );
Kiet Lam64c1b492013-07-12 13:56:44 +05305741 vos_mem_free(pMsg);
Jeff Johnson295189b2012-06-20 16:38:30 -07005742 }
5743 }//Success allocated memory
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005744 else
5745 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005746 smsLog( pMac, LOGE, FL(" memory allocation failure"));
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005747 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005748
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05305749 if(!HAL_STATUS_SUCCESS(status))
5750 {
5751 smsLog( pMac, LOG1, FL("Failed: SId: %d FirstMatch = %d"
5752 " UniqueResult = %d freshScan = %d hiddenSsid = %d"),
5753 sessionId, pScanReqParam->bReturnAfter1stMatch,
5754 pScanReqParam->fUniqueResult, pScanReqParam->freshScan,
5755 pScanReqParam->hiddenSsid );
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05305756 smsLog( pMac, LOG1, FL("scanType = %s (%d) BSSType = %s (%d) "
5757 "numOfSSIDs = %d numOfChannels = %d requestType = %s (%d)"
5758 " p2pSearch = %d\n"),
5759 lim_ScanTypetoString(pScanReq->scanType),
5760 pScanReq->scanType,
5761 lim_BssTypetoString(pScanReq->BSSType),
5762 pScanReq->BSSType,
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05305763 pScanReq->SSIDs.numOfSSIDs,
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05305764 pScanReq->ChannelInfo.numOfChannels,
5765 sme_requestTypetoString(pScanReq->requestType),
5766 pScanReq->requestType,
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05305767 pScanReq->p2pSearch );
5768
5769 }
5770
Jeff Johnson295189b2012-06-20 16:38:30 -07005771 return( status );
5772}
5773
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005774eHalStatus csrSendMBScanResultReq( tpAniSirGlobal pMac, tANI_U32 sessionId, tScanReqParam *pScanReqParam )
Jeff Johnson295189b2012-06-20 16:38:30 -07005775{
5776 eHalStatus status = eHAL_STATUS_SUCCESS;
5777 tSirSmeScanReq *pMsg;
5778 tANI_U16 msgLen;
5779
5780 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ));
Kiet Lam64c1b492013-07-12 13:56:44 +05305781 pMsg = vos_mem_malloc(msgLen);
5782 if ( NULL == pMsg )
5783 status = eHAL_STATUS_FAILURE;
5784 else
Jeff Johnson295189b2012-06-20 16:38:30 -07005785 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305786 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005787 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
5788 pMsg->length = pal_cpu_to_be16(msgLen);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005789 pMsg->sessionId = sessionId;
5790 pMsg->transactionId = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07005791 pMsg->returnFreshResults = pScanReqParam->freshScan;
5792 //Always ask for unique result
5793 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
5794 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
5795 status = palSendMBMessage(pMac->hHdd, pMsg);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005796 if (!HAL_STATUS_SUCCESS(status))
5797 {
5798 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d\n"), status );
5799 }
5800
Jeff Johnson295189b2012-06-20 16:38:30 -07005801 }
5802
5803 return( status );
5804}
5805
5806
5807
5808eHalStatus csrScanChannels( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5809{
5810 eHalStatus status = eHAL_STATUS_FAILURE;
5811 tScanReqParam scanReq;
5812
5813 do
5814 {
5815 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE | TRUE;
5816 scanReq.fUniqueResult = TRUE;
5817 scanReq.hiddenSsid = SIR_SCAN_NO_HIDDEN_SSID;
5818 if(eCsrScanForSsid == pCommand->u.scanCmd.reason)
5819 {
5820 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_FIRST_MATCH;
5821 }
5822 else
5823 {
5824 // Basically do scan on all channels even for 11D 1st scan case.
5825 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5826 }
5827 if((eCsrScanBgScan == pCommand->u.scanCmd.reason)||
5828 (eCsrScanProbeBss == pCommand->u.scanCmd.reason))
5829 {
5830 scanReq.hiddenSsid = SIR_SCAN_HIDDEN_SSID_PE_DECISION;
5831 }
5832
5833#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5834 {
5835 vos_log_scan_pkt_type *pScanLog = NULL;
5836
5837 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
5838 if(pScanLog)
5839 {
5840 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
5841 eCsrScanProbeBss == pCommand->u.scanCmd.reason)
5842 {
5843 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
5844 }
5845 else
5846 {
5847 if( (eSIR_PASSIVE_SCAN != pCommand->u.scanCmd.u.scanRequest.scanType) &&
5848 (eSIR_PASSIVE_SCAN != pMac->scan.curScanType) )
5849 {
5850 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_REQ;
5851 }
5852 else
5853 {
5854 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_REQ;
5855 }
5856 }
5857 pScanLog->minChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.minChnTime;
5858 pScanLog->maxChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.maxChnTime;
5859 pScanLog->numChannel = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
5860 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
5861 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305862 vos_mem_copy(pScanLog->channels,
5863 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
5864 pScanLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07005865 }
5866 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
5867 }
5868 }
5869#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5870
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05305871 csrClearVotesForCountryInfo(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07005872 status = csrSendMBScanReq(pMac, pCommand->sessionId,
5873 &pCommand->u.scanCmd.u.scanRequest, &scanReq);
5874 }while(0);
5875
5876 return( status );
5877}
5878
5879
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005880eHalStatus csrScanRetrieveResult(tpAniSirGlobal pMac, tSmeCmd *pCommand)
Jeff Johnson295189b2012-06-20 16:38:30 -07005881{
5882 eHalStatus status = eHAL_STATUS_FAILURE;
5883 tScanReqParam scanReq;
5884
5885 do
5886 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005887#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5888 if (eCsrScanGetLfrResult == pCommand->u.scanCmd.reason)
5889 {
5890 //to get the LFR candidates from PE cache
5891 scanReq.freshScan = SIR_BG_SCAN_RETURN_LFR_CACHED_RESULTS|SIR_BG_SCAN_PURGE_LFR_RESULTS;
5892 scanReq.fUniqueResult = TRUE;
5893 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5894 }
5895 else
5896#endif
5897 {
5898 //not a fresh scan
5899 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE;
5900 scanReq.fUniqueResult = TRUE;
5901 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5902 }
5903 status = csrSendMBScanResultReq(pMac, pCommand->sessionId, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07005904 }while(0);
5905
5906 return (status);
5907}
5908
Siddharth Bhald8a95e82015-02-12 20:14:52 +05305909eHalStatus csrProcessMacAddrSpoofCommand( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5910{
5911 tSirSpoofMacAddrReq *pMsg;
5912 tANI_U16 msgLen;
5913 eHalStatus status = eHAL_STATUS_FAILURE;
5914 do {
5915 msgLen = sizeof(tSirSpoofMacAddrReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07005916
Siddharth Bhald8a95e82015-02-12 20:14:52 +05305917 pMsg = vos_mem_malloc(msgLen);
5918 if ( NULL == pMsg )
5919 return eHAL_STATUS_FAILURE;
5920 pMsg->messageType= pal_cpu_to_be16((tANI_U16)eWNI_SME_MAC_SPOOF_ADDR_IND);
5921 pMsg->length= pal_cpu_to_be16(msgLen);
5922 // spoof mac address
5923 vos_mem_copy((tANI_U8 *)pMsg->macAddr,
5924 (tANI_U8 *)pCommand->u.macAddrSpoofCmd.macAddr, sizeof(tSirMacAddr));
5925 status = palSendMBMessage(pMac->hHdd, pMsg);
5926 } while( 0 );
5927 return( status );
5928}
Jeff Johnson295189b2012-06-20 16:38:30 -07005929
5930eHalStatus csrProcessScanCommand( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5931{
5932 eHalStatus status = eHAL_STATUS_SUCCESS;
5933 tCsrChannelInfo newChannelInfo = {0, NULL};
5934 int i, j;
5935 tANI_U8 *pChannel = NULL;
5936 tANI_U32 len = 0;
5937
5938 // Transition to Scanning state...
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305939 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07005940 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305941 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5942 {
5943 pCommand->u.scanCmd.lastRoamState[i] =
5944 csrRoamStateChange( pMac, eCSR_ROAMING_STATE_SCANNING, i);
5945 smsLog( pMac, LOG3, "starting SCAN command from %d state...."
5946 " reason is %d", pCommand->u.scanCmd.lastRoamState[i],
5947 pCommand->u.scanCmd.reason );
5948 }
5949 }
5950 else
5951 {
5952 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId] =
5953 csrRoamStateChange(pMac, eCSR_ROAMING_STATE_SCANNING,
5954 pCommand->sessionId);
5955 smsLog( pMac, LOG3,
5956 "starting SCAN command from %d state.... reason is %d",
5957 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId],
5958 pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07005959 }
5960
5961 switch(pCommand->u.scanCmd.reason)
5962 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005963#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5964 case eCsrScanGetLfrResult:
5965#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005966 case eCsrScanGetResult:
5967 case eCsrScanForCapsChange: //For cap change, LIM already save BSS description
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005968 status = csrScanRetrieveResult(pMac, pCommand);
Jeff Johnson295189b2012-06-20 16:38:30 -07005969 break;
5970 case eCsrScanSetBGScanParam:
5971 status = csrProcessSetBGScanParam(pMac, pCommand);
5972 break;
5973 case eCsrScanBGScanAbort:
5974 status = csrSetCfgBackgroundScanPeriod(pMac, 0);
5975 break;
5976 case eCsrScanBGScanEnable:
5977 status = csrSetCfgBackgroundScanPeriod(pMac, pMac->roam.configParam.bgScanInterval);
5978 break;
5979 case eCsrScanGetScanChnInfo:
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05305980 status = csrScanGetScanChannelInfo(pMac, pCommand->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07005981 break;
5982 case eCsrScanUserRequest:
5983 if(pMac->roam.configParam.fScanTwice)
5984 {
5985 //We scan 2.4 channel twice
5986 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels &&
5987 (NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList))
5988 {
5989 len = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
5990 //allocate twice the channel
Mukul Sharmaa631e892014-08-28 15:38:51 +05305991 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(len * 2);
Jeff Johnson295189b2012-06-20 16:38:30 -07005992 pChannel = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
5993 }
5994 else
5995 {
5996 //get the valid channel list to scan all.
5997 len = sizeof(pMac->roam.validChannelList);
5998
5999 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
6000 {
6001 //allocate twice the channel
6002 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(len * 2);
6003 pChannel = pMac->roam.validChannelList;
6004 }
6005 }
6006 if(NULL == newChannelInfo.ChannelList)
6007 {
6008 newChannelInfo.numOfChannels = 0;
6009 }
6010 else
6011 {
6012 j = 0;
6013 for(i = 0; i < len; i++)
6014 {
6015 newChannelInfo.ChannelList[j++] = pChannel[i];
6016 if(CSR_MAX_24GHz_CHANNEL_NUMBER >= pChannel[i])
6017 {
6018 newChannelInfo.ChannelList[j++] = pChannel[i];
6019 }
6020 }
6021 if(NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
6022 {
6023 //pChannel points to the channellist from the command, free it.
6024 vos_mem_free(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -07006025 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07006026 }
6027 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = j;
6028 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = newChannelInfo.ChannelList;
6029 }
6030 } //if(pMac->roam.configParam.fScanTwice)
6031
6032 status = csrScanChannels(pMac, pCommand);
6033
6034 break;
6035 default:
6036 status = csrScanChannels(pMac, pCommand);
6037 break;
6038 }
6039
6040 if(!HAL_STATUS_SUCCESS(status))
6041 {
6042 csrReleaseScanCommand(pMac, pCommand, eCSR_SCAN_FAILURE);
6043 }
6044
6045 return (status);
6046}
6047
6048
6049eHalStatus csrScanSetBGScanparams(tpAniSirGlobal pMac, tCsrBGScanRequest *pScanReq)
6050{
6051 eHalStatus status = eHAL_STATUS_SUCCESS;
6052 tSmeCmd *pCommand = NULL;
6053
6054 if(pScanReq)
6055 {
6056 do
6057 {
6058 pCommand = csrGetCommandBuffer(pMac);
6059 if(!pCommand)
6060 {
6061 status = eHAL_STATUS_RESOURCES;
6062 break;
6063 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306064 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006065 pCommand->command = eSmeCommandScan;
6066 pCommand->u.scanCmd.reason = eCsrScanSetBGScanParam;
6067 pCommand->u.scanCmd.callback = NULL;
6068 pCommand->u.scanCmd.pContext = NULL;
Kiet Lam64c1b492013-07-12 13:56:44 +05306069 vos_mem_copy(&pCommand->u.scanCmd.u.bgScanRequest, pScanReq, sizeof(tCsrBGScanRequest));
Jeff Johnson295189b2012-06-20 16:38:30 -07006070 //we have to do the follow
6071 if(pScanReq->ChannelInfo.numOfChannels == 0)
6072 {
6073 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
6074 }
6075 else
6076 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306077 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList
6078 = vos_mem_malloc(pScanReq->ChannelInfo.numOfChannels);
6079 if ( NULL != pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07006080 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306081 vos_mem_copy(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList,
6082 pScanReq->ChannelInfo.ChannelList,
6083 pScanReq->ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07006084 }
6085 else
6086 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006087 smsLog(pMac, LOGE, FL("ran out of memory"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006088 csrReleaseCommandScan(pMac, pCommand);
Kiet Lam64c1b492013-07-12 13:56:44 +05306089 return eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006090 }
6091 }
6092
6093 //scan req for SSID
6094 if(pScanReq->SSID.length)
6095 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306096 vos_mem_copy(pCommand->u.scanCmd.u.bgScanRequest.SSID.ssId,
6097 pScanReq->SSID.ssId, pScanReq->SSID.length);
Jeff Johnson295189b2012-06-20 16:38:30 -07006098 pCommand->u.scanCmd.u.bgScanRequest.SSID.length = pScanReq->SSID.length;
6099
6100 }
6101 pCommand->u.scanCmd.u.bgScanRequest.maxChnTime= pScanReq->maxChnTime;
6102 pCommand->u.scanCmd.u.bgScanRequest.minChnTime = pScanReq->minChnTime;
6103 pCommand->u.scanCmd.u.bgScanRequest.scanInterval = pScanReq->scanInterval;
6104
6105
6106 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
6107 if( !HAL_STATUS_SUCCESS( status ) )
6108 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006109 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006110 csrReleaseCommandScan( pMac, pCommand );
6111 break;
6112 }
6113 }while(0);
6114 }
6115
6116 return (status);
6117}
6118
6119eHalStatus csrScanBGScanAbort( tpAniSirGlobal pMac )
6120{
6121 eHalStatus status = eHAL_STATUS_SUCCESS;
6122 tSmeCmd *pCommand = NULL;
6123
6124 do
6125 {
6126 pCommand = csrGetCommandBuffer(pMac);
6127 if(!pCommand)
6128 {
6129 status = eHAL_STATUS_RESOURCES;
6130 break;
6131 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306132 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006133 pCommand->command = eSmeCommandScan;
6134 pCommand->u.scanCmd.reason = eCsrScanBGScanAbort;
6135 pCommand->u.scanCmd.callback = NULL;
6136 pCommand->u.scanCmd.pContext = NULL;
6137 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
6138 if( !HAL_STATUS_SUCCESS( status ) )
6139 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006140 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006141 csrReleaseCommandScan( pMac, pCommand );
6142 break;
6143 }
6144 }while(0);
6145
6146 return (status);
6147}
6148
6149
6150//This will enable the background scan with the non-zero interval
6151eHalStatus csrScanBGScanEnable(tpAniSirGlobal pMac)
6152{
6153 eHalStatus status = eHAL_STATUS_SUCCESS;
6154 tSmeCmd *pCommand = NULL;
6155
6156 if(pMac->roam.configParam.bgScanInterval)
6157 {
6158 do
6159 {
6160 pCommand = csrGetCommandBuffer(pMac);
6161 if(!pCommand)
6162 {
6163 status = eHAL_STATUS_RESOURCES;
6164 break;
6165 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306166 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006167 pCommand->command = eSmeCommandScan;
6168 pCommand->u.scanCmd.reason = eCsrScanBGScanEnable;
6169 pCommand->u.scanCmd.callback = NULL;
6170 pCommand->u.scanCmd.pContext = NULL;
6171 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
6172 if( !HAL_STATUS_SUCCESS( status ) )
6173 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006174 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006175 csrReleaseCommandScan( pMac, pCommand );
6176 break;
6177 }
6178 }while(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006179 }
6180 else
6181 {
Sushant Kaushikb8dbb3f2015-04-29 17:03:37 +05306182 smsLog(pMac, LOGE, FL("cannot continue because the bgscan interval is 0"));
6183 status = eHAL_STATUS_INVALID_PARAMETER;
Jeff Johnson295189b2012-06-20 16:38:30 -07006184 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006185 return (status);
6186}
6187
6188
6189eHalStatus csrScanCopyRequest(tpAniSirGlobal pMac, tCsrScanRequest *pDstReq, tCsrScanRequest *pSrcReq)
6190{
6191 eHalStatus status = eHAL_STATUS_SUCCESS;
6192 tANI_U32 len = sizeof(pMac->roam.validChannelList);
6193 tANI_U32 index = 0;
6194 tANI_U32 new_index = 0;
Manjunathappa Prakashde7b2a52014-02-28 16:59:03 -08006195 eNVChannelEnabledType NVchannel_state;
Arif Hussain6af38622014-03-12 12:39:57 -07006196 tANI_U8 ch144_support = 0;
6197
6198 ch144_support = WDA_getFwWlanFeatCaps(WLAN_CH144);
Jeff Johnson295189b2012-06-20 16:38:30 -07006199
6200 do
6201 {
6202 status = csrScanFreeRequest(pMac, pDstReq);
6203 if(HAL_STATUS_SUCCESS(status))
6204 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306205 vos_mem_copy(pDstReq, pSrcReq, sizeof(tCsrScanRequest));
Gopichand Nakkalac7b1d3e2012-12-31 14:07:19 -08006206 /* Re-initialize the pointers to NULL since we did a copy */
6207 pDstReq->pIEField = NULL;
6208 pDstReq->ChannelInfo.ChannelList = NULL;
6209 pDstReq->SSIDs.SSIDList = NULL;
6210
Jeff Johnson295189b2012-06-20 16:38:30 -07006211 if(pSrcReq->uIEFieldLen == 0)
6212 {
6213 pDstReq->pIEField = NULL;
6214 }
6215 else
6216 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306217 pDstReq->pIEField = vos_mem_malloc(pSrcReq->uIEFieldLen);
6218 if ( NULL == pDstReq->pIEField )
Jeff Johnson295189b2012-06-20 16:38:30 -07006219 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306220 status = eHAL_STATUS_FAILURE;
6221 smsLog(pMac, LOGE, FL("No memory for scanning IE fields"));
6222 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07006223 }
6224 else
6225 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306226 status = eHAL_STATUS_SUCCESS;
6227 vos_mem_copy(pDstReq->pIEField, pSrcReq->pIEField,
6228 pSrcReq->uIEFieldLen);
6229 pDstReq->uIEFieldLen = pSrcReq->uIEFieldLen;
Jeff Johnson295189b2012-06-20 16:38:30 -07006230 }
6231 }//Allocate memory for IE field
6232 {
6233 if(pSrcReq->ChannelInfo.numOfChannels == 0)
6234 {
6235 pDstReq->ChannelInfo.ChannelList = NULL;
6236 pDstReq->ChannelInfo.numOfChannels = 0;
6237 }
6238 else
6239 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306240 pDstReq->ChannelInfo.ChannelList = vos_mem_malloc(
6241 pSrcReq->ChannelInfo.numOfChannels
6242 * sizeof(*pDstReq->ChannelInfo.ChannelList));
6243 if ( NULL == pDstReq->ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07006244 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306245 status = eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006246 pDstReq->ChannelInfo.numOfChannels = 0;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306247 smsLog(pMac, LOGE, FL("No memory for scanning Channel"
6248 " List"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006249 break;
6250 }
6251
6252 if((pSrcReq->scanType == eSIR_PASSIVE_SCAN) && (pSrcReq->requestType == eCSR_SCAN_REQUEST_11D_SCAN))
6253 {
6254 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
6255 {
Arif Hussain6af38622014-03-12 12:39:57 -07006256 /* Skip CH 144 if firmware support not present */
6257 if (pSrcReq->ChannelInfo.ChannelList[index] == 144 && !ch144_support)
6258 continue;
Agarwal Ashish8bd53ae2015-06-12 18:03:45 +05306259 /* Skip channel 12 and 13 when FCC constraint is true */
6260 if ((pMac->scan.fcc_constraint) &&
6261 ((pSrcReq->ChannelInfo.ChannelList[index] ==12) ||
6262 (pSrcReq->ChannelInfo.ChannelList[index] ==13)))
6263 {
6264 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
6265 FL("Ignoring channel : %d "),
6266 pSrcReq->ChannelInfo.ChannelList[index]);
6267 continue;
6268 }
Arif Hussain6af38622014-03-12 12:39:57 -07006269
Manjunathappa Prakashde7b2a52014-02-28 16:59:03 -08006270 NVchannel_state = vos_nv_getChannelEnabledState(
6271 pSrcReq->ChannelInfo.ChannelList[index]);
6272 if ((NV_CHANNEL_ENABLE == NVchannel_state) ||
6273 (NV_CHANNEL_DFS == NVchannel_state))
6274 {
6275 pDstReq->ChannelInfo.ChannelList[new_index] =
6276 pSrcReq->ChannelInfo.ChannelList[index];
6277 new_index++;
6278 }
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306279 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006280 pDstReq->ChannelInfo.numOfChannels = new_index;
6281 }
6282 else if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
6283 {
6284 new_index = 0;
6285 pMac->roam.numValidChannels = len;
c_hpothu0d5a7352014-03-22 12:30:25 +05306286
6287 /* Since in CsrScanRequest,value of pMac->scan.nextScanID
6288 * is incremented before calling CsrScanCopyRequest, as a
6289 * result pMac->scan.nextScanID is equal to ONE for the
6290 * first scan.
6291 */
Ganesh Kondabattini8f6e3b32014-08-25 16:07:54 +05306292 if ((pMac->roam.configParam.initialScanSkipDFSCh &&
6293 1 == pMac->scan.nextScanID) ||(pMac->miracast_mode))
c_hpothu0d5a7352014-03-22 12:30:25 +05306294 {
6295 smsLog(pMac, LOG1,
6296 FL("Initial scan, scan only non-DFS channels"));
6297
6298 for (index = 0; index < pSrcReq->ChannelInfo.
6299 numOfChannels ; index++ )
6300 {
6301 if((csrRoamIsValidChannel(pMac, pSrcReq->ChannelInfo.
6302 ChannelList[index])))
6303 {
6304 /*Skiipping DFS Channels for 1st scan */
6305 if(NV_CHANNEL_DFS ==
6306 vos_nv_getChannelEnabledState(pSrcReq->ChannelInfo.
6307 ChannelList[index]))
6308 continue ;
6309
6310 pDstReq->ChannelInfo.ChannelList[new_index] =
6311 pSrcReq->ChannelInfo.ChannelList[index];
6312 new_index++;
6313
6314 }
6315 }
6316 pMac->roam.configParam.initialScanSkipDFSCh = 0;
6317 }
6318 else
6319 {
6320 for ( index = 0; index < pSrcReq->ChannelInfo.
6321 numOfChannels ; index++ )
Jeff Johnson295189b2012-06-20 16:38:30 -07006322 {
Arif Hussain6af38622014-03-12 12:39:57 -07006323 /* Skip CH 144 if firmware support not present */
6324 if (pSrcReq->ChannelInfo.ChannelList[index] == 144 && !ch144_support)
6325 continue;
6326
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -07006327 /* Allow scan on valid channels only.
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -07006328 */
Abhishek Singh2ec36ab2014-08-07 16:14:25 +05306329 if ( ( csrRoamIsValidChannel(pMac, pSrcReq->ChannelInfo.ChannelList[index]) ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07006330 {
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05306331 if( ((pSrcReq->skipDfsChnlInP2pSearch ||
6332 (pMac->scan.fEnableDFSChnlScan ==
6333 DFS_CHNL_SCAN_DISABLED)) &&
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08006334 (NV_CHANNEL_DFS == vos_nv_getChannelEnabledState(pSrcReq->ChannelInfo.ChannelList[index])) )
Srikant Kuppa866893f2012-12-27 17:28:14 -08006335#ifdef FEATURE_WLAN_LFR
6336 /*
6337 * If LFR is requesting a contiguous scan
6338 * (i.e. numOfChannels > 1), then ignore
6339 * DFS channels.
6340 * TODO: vos_nv_getChannelEnabledState is returning
6341 * 120, 124 and 128 as non-DFS channels. Hence, the
6342 * use of direct check for channels below.
6343 */
6344 || ((eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType) &&
6345 (pSrcReq->ChannelInfo.numOfChannels > 1) &&
Santhosh Kumar Padma9ccaaff2014-07-09 19:58:12 +05306346 (CSR_IS_CHANNEL_DFS(pSrcReq->ChannelInfo.ChannelList[index])) &&
6347 !pMac->roam.configParam.allowDFSChannelRoam)
Srikant Kuppa866893f2012-12-27 17:28:14 -08006348#endif
6349 )
6350 {
6351#ifdef FEATURE_WLAN_LFR
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05306352 smsLog(pMac, LOG2,
6353 FL(" reqType=%s (%d), numOfChannels=%d,"
6354 " ignoring DFS channel %d"),
6355 sme_requestTypetoString(pSrcReq->requestType),
6356 pSrcReq->requestType,
6357 pSrcReq->ChannelInfo.numOfChannels,
6358 pSrcReq->ChannelInfo.ChannelList[index]);
Srikant Kuppa866893f2012-12-27 17:28:14 -08006359#endif
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05306360 continue;
Srikant Kuppa866893f2012-12-27 17:28:14 -08006361 }
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08006362
Jeff Johnson295189b2012-06-20 16:38:30 -07006363 pDstReq->ChannelInfo.ChannelList[new_index] =
6364 pSrcReq->ChannelInfo.ChannelList[index];
6365 new_index++;
6366 }
6367 }
c_hpothu0d5a7352014-03-22 12:30:25 +05306368 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006369 pDstReq->ChannelInfo.numOfChannels = new_index;
Srikant Kuppa866893f2012-12-27 17:28:14 -08006370#ifdef FEATURE_WLAN_LFR
Abhishek Singh2ec36ab2014-08-07 16:14:25 +05306371 if ( ( ( eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType ) ||
6372 ( eCSR_SCAN_P2P_DISCOVERY == pSrcReq->requestType ) ) &&
6373 ( 0 == pDstReq->ChannelInfo.numOfChannels ) )
Srikant Kuppa866893f2012-12-27 17:28:14 -08006374 {
6375 /*
6376 * No valid channels found in the request.
6377 * Only perform scan on the channels passed
Abhishek Singh2ec36ab2014-08-07 16:14:25 +05306378 * pSrcReq if it is a eCSR_SCAN_HO_BG_SCAN or
6379 * eCSR_SCAN_P2P_DISCOVERY.
Srikant Kuppa866893f2012-12-27 17:28:14 -08006380 * Passing 0 to LIM will trigger a scan on
6381 * all valid channels which is not desirable.
6382 */
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306383 smsLog(pMac, LOGE, FL(" no valid channels found"
6384 " (request=%d)"), pSrcReq->requestType);
Srikant Kuppa866893f2012-12-27 17:28:14 -08006385 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
6386 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306387 smsLog(pMac, LOGE, FL("pSrcReq index=%d"
6388 " channel=%d"), index,
6389 pSrcReq->ChannelInfo.ChannelList[index]);
Srikant Kuppa866893f2012-12-27 17:28:14 -08006390 }
6391 status = eHAL_STATUS_FAILURE;
6392 break;
6393 }
6394#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006395 }
6396 else
6397 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306398 smsLog(pMac, LOGE, FL("Couldn't get the valid Channel"
6399 " List, keeping requester's list"));
Kiet Lam64c1b492013-07-12 13:56:44 +05306400 vos_mem_copy(pDstReq->ChannelInfo.ChannelList,
6401 pSrcReq->ChannelInfo.ChannelList,
6402 pSrcReq->ChannelInfo.numOfChannels
6403 * sizeof(*pDstReq->ChannelInfo.ChannelList));
Jeff Johnson295189b2012-06-20 16:38:30 -07006404 pDstReq->ChannelInfo.numOfChannels = pSrcReq->ChannelInfo.numOfChannels;
6405 }
6406 }//Allocate memory for Channel List
6407 }
6408 if(pSrcReq->SSIDs.numOfSSIDs == 0)
6409 {
6410 pDstReq->SSIDs.numOfSSIDs = 0;
6411 pDstReq->SSIDs.SSIDList = NULL;
6412 }
6413 else
6414 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306415 pDstReq->SSIDs.SSIDList = vos_mem_malloc(
6416 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
6417 if ( NULL == pDstReq->SSIDs.SSIDList )
6418 status = eHAL_STATUS_FAILURE;
6419 else
6420 status = eHAL_STATUS_SUCCESS;
6421 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07006422 {
6423 pDstReq->SSIDs.numOfSSIDs = pSrcReq->SSIDs.numOfSSIDs;
Kiet Lam64c1b492013-07-12 13:56:44 +05306424 vos_mem_copy(pDstReq->SSIDs.SSIDList,
6425 pSrcReq->SSIDs.SSIDList,
6426 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
Jeff Johnson295189b2012-06-20 16:38:30 -07006427 }
6428 else
6429 {
6430 pDstReq->SSIDs.numOfSSIDs = 0;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306431 smsLog(pMac, LOGE, FL("No memory for scanning SSID List"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006432 break;
6433 }
6434 }//Allocate memory for SSID List
Jeff Johnson295189b2012-06-20 16:38:30 -07006435 pDstReq->p2pSearch = pSrcReq->p2pSearch;
Jeff Johnsone7245742012-09-05 17:12:55 -07006436 pDstReq->skipDfsChnlInP2pSearch = pSrcReq->skipDfsChnlInP2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07006437
6438 }
6439 }while(0);
6440
6441 if(!HAL_STATUS_SUCCESS(status))
6442 {
6443 csrScanFreeRequest(pMac, pDstReq);
6444 }
6445
6446 return (status);
6447}
6448
6449
6450eHalStatus csrScanFreeRequest(tpAniSirGlobal pMac, tCsrScanRequest *pReq)
6451{
Jeff Johnson295189b2012-06-20 16:38:30 -07006452
6453 if(pReq->ChannelInfo.ChannelList)
6454 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306455 vos_mem_free(pReq->ChannelInfo.ChannelList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006456 pReq->ChannelInfo.ChannelList = NULL;
6457 }
6458 pReq->ChannelInfo.numOfChannels = 0;
6459 if(pReq->pIEField)
6460 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306461 vos_mem_free(pReq->pIEField);
Jeff Johnson295189b2012-06-20 16:38:30 -07006462 pReq->pIEField = NULL;
6463 }
6464 pReq->uIEFieldLen = 0;
6465 if(pReq->SSIDs.SSIDList)
6466 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306467 vos_mem_free(pReq->SSIDs.SSIDList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006468 pReq->SSIDs.SSIDList = NULL;
6469 }
6470 pReq->SSIDs.numOfSSIDs = 0;
6471
Kiet Lam64c1b492013-07-12 13:56:44 +05306472 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07006473}
6474
6475
6476void csrScanCallCallback(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
6477{
6478 if(pCommand->u.scanCmd.callback)
6479 {
Ratheesh S Pece1f832015-07-25 15:50:25 +05306480 if (pCommand->u.scanCmd.abortScanIndication){
6481 smsLog( pMac, LOG1, FL("scanDone due to abort"));
6482 scanStatus = eCSR_SCAN_ABORT;
6483 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006484// sme_ReleaseGlobalLock( &pMac->sme );
6485 pCommand->u.scanCmd.callback(pMac, pCommand->u.scanCmd.pContext, pCommand->u.scanCmd.scanID, scanStatus);
6486// sme_AcquireGlobalLock( &pMac->sme );
6487 } else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006488 smsLog( pMac, LOG2, "%s:%d - Callback NULL!!!", __func__, __LINE__);
Jeff Johnson295189b2012-06-20 16:38:30 -07006489 }
6490}
6491
6492
6493void csrScanStopTimers(tpAniSirGlobal pMac)
6494{
Jeff Johnson295189b2012-06-20 16:38:30 -07006495 csrScanStopIdleScanTimer(pMac);
6496 csrScanStopGetResultTimer(pMac);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006497 if(0 != pMac->scan.scanResultCfgAgingTime )
6498 {
6499 csrScanStopResultCfgAgingTimer(pMac);
6500 }
6501
Jeff Johnson295189b2012-06-20 16:38:30 -07006502}
6503
6504
6505eHalStatus csrScanStartGetResultTimer(tpAniSirGlobal pMac)
6506{
6507 eHalStatus status;
6508
6509 if(pMac->scan.fScanEnable)
6510 {
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306511 status = vos_timer_start(&pMac->scan.hTimerGetResult, CSR_SCAN_GET_RESULT_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006512 }
6513 else
6514 {
6515 status = eHAL_STATUS_FAILURE;
6516 }
6517
6518 return (status);
6519}
6520
6521
6522eHalStatus csrScanStopGetResultTimer(tpAniSirGlobal pMac)
6523{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306524 return (vos_timer_stop(&pMac->scan.hTimerGetResult));
Jeff Johnson295189b2012-06-20 16:38:30 -07006525}
6526
6527
6528void csrScanGetResultTimerHandler(void *pv)
6529{
6530 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6531
6532 csrScanRequestResult(pMac);
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306533
6534 vos_timer_start(&pMac->scan.hTimerGetResult, CSR_SCAN_GET_RESULT_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006535}
6536
6537#ifdef WLAN_AP_STA_CONCURRENCY
6538static void csrStaApConcTimerHandler(void *pv)
6539{
6540 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6541 tListElem *pEntry;
6542 tSmeCmd *pScanCmd;
6543
6544 csrLLLock(&pMac->scan.scanCmdPendingList);
6545
6546 if ( NULL != ( pEntry = csrLLPeekHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) ) )
6547 {
6548 tCsrScanRequest scanReq;
6549 tSmeCmd *pSendScanCmd = NULL;
6550 tANI_U8 numChn = 0;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006551 tANI_U8 nNumChanCombinedConc = 0;
Vinay Malekal05fdc812012-12-17 13:04:30 -08006552 tANI_U8 i, j;
Jeff Johnson295189b2012-06-20 16:38:30 -07006553 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
6554 tANI_U8 channelToScan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
6555 eHalStatus status;
6556
Jeff Johnson295189b2012-06-20 16:38:30 -07006557 pScanCmd = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
6558 numChn = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08006559
6560 /* if any session is connected and the number of channels to scan is
6561 * greater than 1 then split the scan into multiple scan operations
6562 * on each individual channel else continue to perform scan on all
6563 * specified channels */
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08006564
6565 /* split scan if number of channels to scan is greater than 1 and
6566 * any one of the following:
6567 * - STA session is connected and the scan is not a P2P search
6568 * - any P2P session is connected
Srikant Kuppa866893f2012-12-27 17:28:14 -08006569 * Do not split scans if no concurrent infra connections are
6570 * active and if the scan is a BG scan triggered by LFR (OR)
6571 * any scan if LFR is in the middle of a BG scan. Splitting
6572 * the scan is delaying the time it takes for LFR to find
6573 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08006574 */
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006575
6576 if((csrIsStaSessionConnected(pMac) &&
6577 !csrIsP2pSessionConnected(pMac)))
6578 {
6579 nNumChanCombinedConc = pMac->roam.configParam.nNumStaChanCombinedConc;
6580 }
6581 else if(csrIsP2pSessionConnected(pMac))
6582 {
6583 nNumChanCombinedConc = pMac->roam.configParam.nNumP2PChanCombinedConc;
6584 }
6585
6586 if ( (numChn > nNumChanCombinedConc) &&
Srikant Kuppa866893f2012-12-27 17:28:14 -08006587 ((csrIsStaSessionConnected(pMac) &&
6588#ifdef FEATURE_WLAN_LFR
6589 (csrIsConcurrentInfraConnected(pMac) ||
6590 ((pScanCmd->u.scanCmd.reason != eCsrScanBgScan) &&
6591 (pMac->roam.neighborRoamInfo.neighborRoamState !=
6592 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
6593#endif
6594 (pScanCmd->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08006595 (csrIsP2pSessionConnected(pMac))))
Jeff Johnson295189b2012-06-20 16:38:30 -07006596 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306597 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006598
6599 pSendScanCmd = csrGetCommandBuffer(pMac); //optimize this to use 2 command buffer only
6600 if (!pSendScanCmd)
6601 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006602 smsLog( pMac, LOGE, FL(" Failed to get Queue command buffer") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006603 csrLLUnlock(&pMac->scan.scanCmdPendingList);
6604 return;
6605 }
6606 pSendScanCmd->command = pScanCmd->command;
6607 pSendScanCmd->sessionId = pScanCmd->sessionId;
6608 pSendScanCmd->u.scanCmd.callback = NULL;
6609 pSendScanCmd->u.scanCmd.pContext = pScanCmd->u.scanCmd.pContext;
6610 pSendScanCmd->u.scanCmd.reason = pScanCmd->u.scanCmd.reason;
6611 pSendScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
6612
Madan Mohan Koyyalamudiaf2a8b92012-10-09 14:58:07 -07006613 /* First copy all the parameters to local variable of scan request */
6614 csrScanCopyRequest(pMac, &scanReq, &pScanCmd->u.scanCmd.u.scanRequest);
6615
6616 /* Now modify the elements of local var scan request required to be modified for split scan */
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08006617 if(scanReq.ChannelInfo.ChannelList != NULL)
6618 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306619 vos_mem_free(scanReq.ChannelInfo.ChannelList);
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08006620 scanReq.ChannelInfo.ChannelList = NULL;
6621 }
6622
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006623 pChnInfo->numOfChannels = nNumChanCombinedConc;
Kiet Lam64c1b492013-07-12 13:56:44 +05306624 vos_mem_copy(&channelToScan[0],
6625 &pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[0],
6626 pChnInfo->numOfChannels * sizeof(tANI_U8));//just send one channel
Jeff Johnson295189b2012-06-20 16:38:30 -07006627 pChnInfo->ChannelList = &channelToScan[0];
6628
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006629 for (i = 0, j = nNumChanCombinedConc; i < (numChn-nNumChanCombinedConc); i++, j++)
Jeff Johnson295189b2012-06-20 16:38:30 -07006630 {
6631 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] =
Vinay Malekal05fdc812012-12-17 13:04:30 -08006632 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[j]; //Move all the channels one step
Jeff Johnson295189b2012-06-20 16:38:30 -07006633 }
6634
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006635 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = numChn - nNumChanCombinedConc; //reduce outstanding # of channels to be scanned
Jeff Johnson295189b2012-06-20 16:38:30 -07006636
6637 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
c_hpothudbefd3e2014-04-28 15:59:47 +05306638
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -07006639 //Use concurrency values for min/maxChnTime.
6640 //We know csrIsAnySessionConnected(pMac) returns TRUE here
6641 csrSetDefaultScanTiming(pMac, scanReq.scanType, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07006642
6643 status = csrScanCopyRequest(pMac, &pSendScanCmd->u.scanCmd.u.scanRequest, &scanReq);
6644 if(!HAL_STATUS_SUCCESS(status))
6645 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006646 smsLog( pMac, LOGE, FL(" Failed to get copy csrScanRequest = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006647 csrLLUnlock(&pMac->scan.scanCmdPendingList);
6648 return;
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08006649 }
6650 /* Clean the local scan variable */
6651 scanReq.ChannelInfo.ChannelList = NULL;
6652 scanReq.ChannelInfo.numOfChannels = 0;
6653 csrScanFreeRequest(pMac, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07006654 }
6655 else
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08006656 {
6657 /* no active connected session present or numChn == 1
6658 * scan all remaining channels */
Jeff Johnson295189b2012-06-20 16:38:30 -07006659 pSendScanCmd = pScanCmd;
6660 //remove this command from pending list
6661 if (csrLLRemoveHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) == NULL)
6662 { //In case between PeekHead and here, the entry got removed by another thread.
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006663 smsLog( pMac, LOGE, FL(" Failed to remove entry from scanCmdPendingList"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006664 }
6665
6666 }
6667 csrQueueSmeCommand(pMac, pSendScanCmd, eANI_BOOLEAN_FALSE);
6668
6669 }
6670
Jeff Johnson295189b2012-06-20 16:38:30 -07006671 csrLLUnlock(&pMac->scan.scanCmdPendingList);
6672
6673}
6674#endif
6675
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006676eHalStatus csrScanStartResultCfgAgingTimer(tpAniSirGlobal pMac)
6677{
6678 eHalStatus status = eHAL_STATUS_FAILURE;
6679
6680 if(pMac->scan.fScanEnable)
6681 {
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306682 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 -08006683 }
6684 return (status);
6685}
Jeff Johnson295189b2012-06-20 16:38:30 -07006686
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006687eHalStatus csrScanStopResultCfgAgingTimer(tpAniSirGlobal pMac)
6688{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306689 return (vos_timer_stop(&pMac->scan.hTimerResultCfgAging));
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006690}
Jeff Johnson295189b2012-06-20 16:38:30 -07006691
6692//This function returns the maximum time a BSS is allowed in the scan result.
6693//The time varies base on connection and power saving factors.
6694//Not connected, No PS
6695//Not connected, with PS
6696//Connected w/o traffic, No PS
6697//Connected w/o traffic, with PS
6698//Connected w/ traffic, no PS -- Not supported
6699//Connected w/ traffic, with PS -- Not supported
6700//the return unit is in seconds.
6701tANI_U32 csrScanGetAgeOutTime(tpAniSirGlobal pMac)
6702{
6703 tANI_U32 nRet;
6704
6705 if(pMac->scan.nAgingCountDown)
6706 {
6707 //Calculate what should be the timeout value for this
6708 nRet = pMac->scan.nLastAgeTimeOut * pMac->scan.nAgingCountDown;
6709 pMac->scan.nAgingCountDown--;
6710 }
6711 else
6712 {
6713 if( csrIsAllSessionDisconnected( pMac ) )
6714 {
6715 if(pmcIsPowerSaveEnabled(pMac, ePMC_IDLE_MODE_POWER_SAVE))
6716 {
6717 nRet = pMac->roam.configParam.scanAgeTimeNCPS;
6718 }
6719 else
6720 {
6721 nRet = pMac->roam.configParam.scanAgeTimeNCNPS;
6722 }
6723 }
6724 else
6725 {
6726 if(pmcIsPowerSaveEnabled(pMac, ePMC_BEACON_MODE_POWER_SAVE))
6727 {
6728 nRet = pMac->roam.configParam.scanAgeTimeCPS;
6729 }
6730 else
6731 {
6732 nRet = pMac->roam.configParam.scanAgeTimeCNPS;
6733 }
6734 }
6735 //If state-change causing aging time out change, we want to delay it somewhat to avoid
6736 //unnecessary removal of BSS. This is mostly due to transition from connect to disconnect.
6737 if(pMac->scan.nLastAgeTimeOut > nRet)
6738 {
6739 if(nRet)
6740 {
6741 pMac->scan.nAgingCountDown = (pMac->scan.nLastAgeTimeOut / nRet);
6742 }
6743 pMac->scan.nLastAgeTimeOut = nRet;
6744 nRet *= pMac->scan.nAgingCountDown;
6745 }
6746 else
6747 {
6748 pMac->scan.nLastAgeTimeOut = nRet;
6749 }
6750 }
6751
6752 return (nRet);
6753}
6754
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006755static void csrScanResultCfgAgingTimerHandler(void *pv)
6756{
6757 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6758 tListElem *pEntry, *tmpEntry;
6759 tCsrScanResult *pResult;
6760 tANI_TIMESTAMP ageOutTime = pMac->scan.scanResultCfgAgingTime * PAL_TICKS_PER_SECOND;
6761 tANI_TIMESTAMP curTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
6762
6763 csrLLLock(&pMac->scan.scanResultList);
6764 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
6765 while( pEntry )
6766 {
6767 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
6768 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
6769 if((curTime - pResult->Result.BssDescriptor.nReceivedTime) > ageOutTime)
6770 {
6771 smsLog(pMac, LOGW, " age out due to time out");
6772 csrScanAgeOutBss(pMac, pResult);
6773 }
6774 pEntry = tmpEntry;
6775 }
6776 csrLLUnlock(&pMac->scan.scanResultList);
Sushant Kaushik6274de62015-05-01 16:31:23 +05306777 if (pEntry)
6778 vos_timer_start(&pMac->scan.hTimerResultCfgAging, CSR_SCAN_RESULT_CFG_AGING_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006779}
Jeff Johnson295189b2012-06-20 16:38:30 -07006780
6781eHalStatus csrScanStartIdleScanTimer(tpAniSirGlobal pMac, tANI_U32 interval)
6782{
6783 eHalStatus status;
6784
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006785 smsLog(pMac, LOG1, " csrScanStartIdleScanTimer");
Jeff Johnson295189b2012-06-20 16:38:30 -07006786 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) && interval)
6787 {
6788 pMac->scan.nIdleScanTimeGap += interval;
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306789 vos_timer_stop(&pMac->scan.hTimerIdleScan);
6790 status = vos_timer_start(&pMac->scan.hTimerIdleScan, interval/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006791 if( !HAL_STATUS_SUCCESS(status) )
6792 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006793 smsLog(pMac, LOGE, " Fail to start Idle scan timer. status = %d interval = %d", status, interval);
Jeff Johnson295189b2012-06-20 16:38:30 -07006794 //This should not happen but set the flag to restart when ready
6795 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6796 }
6797 }
6798 else
6799 {
6800 if( pMac->scan.fScanEnable && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) )
6801 {
6802 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6803 }
6804 status = eHAL_STATUS_FAILURE;
6805 }
6806
6807 return (status);
6808}
6809
6810
6811eHalStatus csrScanStopIdleScanTimer(tpAniSirGlobal pMac)
6812{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306813 return (vos_timer_stop(&pMac->scan.hTimerIdleScan));
Jeff Johnson295189b2012-06-20 16:38:30 -07006814}
6815
6816
6817//Stop CSR from asking for IMPS, This function doesn't disable IMPS from CSR
6818void csrScanSuspendIMPS( tpAniSirGlobal pMac )
6819{
6820 csrScanCancelIdleScan(pMac);
6821}
6822
6823
6824//Start CSR from asking for IMPS. This function doesn't trigger CSR to request entering IMPS
6825//because IMPS maybe disabled.
6826void csrScanResumeIMPS( tpAniSirGlobal pMac )
6827{
6828 csrScanStartIdleScan( pMac );
6829}
6830
6831
6832void csrScanIMPSCallback(void *callbackContext, eHalStatus status)
6833{
6834 tpAniSirGlobal pMac = PMAC_STRUCT( callbackContext );
6835
6836 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6837 {
6838 if(pMac->roam.configParam.IsIdleScanEnabled)
6839 {
6840 if(HAL_STATUS_SUCCESS(status))
6841 {
6842 if(csrIsAllSessionDisconnected(pMac) && !csrIsRoamCommandWaiting(pMac))
6843 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006844 smsLog(pMac, LOGW, FL("starts idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006845 csrScanAllChannels(pMac, eCSR_SCAN_IDLE_MODE_SCAN);
6846 }
6847 else
6848 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006849 smsLog(pMac, LOGW, FL("cannot start idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006850 //even though we are in timer handle, calling stop timer will make sure the timer
6851 //doesn't get to restart.
6852 csrScanStopIdleScanTimer(pMac);
6853 }
6854 }
6855 else
6856 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006857 smsLog(pMac, LOGE, FL("sees not success status (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07006858 }
6859 }
6860 else
6861 {//we might need another flag to check if CSR needs to request imps at all
6862
6863 tANI_U32 nTime = 0;
6864
6865 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_FALSE;
6866 if(!HAL_STATUS_SUCCESS(csrScanTriggerIdleScan(pMac, &nTime)))
6867 {
6868 csrScanStartIdleScanTimer(pMac, nTime);
6869 }
6870 }
6871 }
6872}
6873
6874
Rashmi Ramanna68b309c2014-05-20 11:52:22 +05306875//Param: pTimeInterval -- Caller allocated memory in return, if failed, to specify the nxt time interval for
Jeff Johnson295189b2012-06-20 16:38:30 -07006876//idle scan timer interval
6877//Return: Not success -- meaning it cannot start IMPS, caller needs to start a timer for idle scan
6878eHalStatus csrScanTriggerIdleScan(tpAniSirGlobal pMac, tANI_U32 *pTimeInterval)
6879{
6880 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
6881
6882 //Do not trigger IMPS in case of concurrency
Agarwal Ashish5974ed32014-06-16 16:59:54 +05306883 if (vos_concurrent_open_sessions_running() &&
6884 csrIsAnySessionInConnectState(pMac))
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006885 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006886 smsLog( pMac, LOG1, FL("Cannot request IMPS because Concurrent Sessions Running") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006887 return (status);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006888 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006889
6890 if(pTimeInterval)
6891 {
6892 *pTimeInterval = 0;
6893 }
6894
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006895 smsLog(pMac, LOG3, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006896 if( smeCommandPending( pMac ) )
6897 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006898 smsLog( pMac, LOG1, FL(" Cannot request IMPS because command pending") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006899 //Not to enter IMPS because more work to do
6900 if(pTimeInterval)
6901 {
6902 *pTimeInterval = 0;
6903 }
6904 //restart when ready
6905 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6906
6907 return (status);
6908 }
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07006909 if (IsPmcImpsReqFailed (pMac))
6910 {
6911 if(pTimeInterval)
6912 {
6913 *pTimeInterval = 1000000; //usec
6914 }
6915 //restart when ready
6916 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006917
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07006918 return status;
6919 }
Rashmi Ramanna68b309c2014-05-20 11:52:22 +05306920
6921 if ( !pMac->deferImps && pMac->fDeferIMPSTime )
6922 {
6923 smsLog( pMac, LOG1, FL("Defer IMPS for %dms as command processed"),
6924 pMac->fDeferIMPSTime);
Girish Gowli4f3775a2014-05-30 17:17:08 +05306925 if(pTimeInterval)
6926 {
6927 *pTimeInterval = pMac->fDeferIMPSTime * 1000; //usec
6928 }
Rashmi Ramanna68b309c2014-05-20 11:52:22 +05306929 pMac->deferImps = eANI_BOOLEAN_TRUE;
6930 return status;
6931 }
6932
Jeff Johnson295189b2012-06-20 16:38:30 -07006933 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6934 /*&& pMac->roam.configParam.impsSleepTime*/)
6935 {
6936 //Stop get result timer because idle scan gets scan result out of PE
6937 csrScanStopGetResultTimer(pMac);
6938 if(pTimeInterval)
6939 {
6940 *pTimeInterval = pMac->roam.configParam.impsSleepTime;
6941 }
6942 //pmcRequestImps take a period in millisecond unit.
6943 status = pmcRequestImps(pMac, pMac->roam.configParam.impsSleepTime / PAL_TIMER_TO_MS_UNIT, csrScanIMPSCallback, pMac);
6944 if(!HAL_STATUS_SUCCESS(status))
6945 {
6946 if(eHAL_STATUS_PMC_ALREADY_IN_IMPS != status)
6947 {
6948 //Do restart the timer if CSR thinks it cannot do IMPS
6949 if( !csrCheckPSReady( pMac ) )
6950 {
6951 if(pTimeInterval)
6952 {
6953 *pTimeInterval = 0;
6954 }
6955 //Set the restart flag to true because that idle scan
6956 //can be restarted even though the timer will not be running
6957 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6958 }
6959 else
6960 {
6961 //For not now, we do a quicker retry
6962 if(pTimeInterval)
6963 {
6964 *pTimeInterval = CSR_IDLE_SCAN_WAIT_TIME;
6965 }
6966 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006967 smsLog(pMac, LOGW, FL("call pmcRequestImps and it returns status code (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07006968 }
6969 else
6970 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006971 smsLog(pMac, LOGW, FL("already in IMPS"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006972 //Since CSR is the only module to request for IMPS. If it is already in IMPS, CSR assumes
6973 //the callback will be called in the future. Should not happen though.
6974 status = eHAL_STATUS_SUCCESS;
6975 pMac->scan.nIdleScanTimeGap = 0;
6976 }
6977 }
6978 else
6979 {
6980 //requested so let's reset the value
6981 pMac->scan.nIdleScanTimeGap = 0;
6982 }
6983 }
6984
6985 return (status);
6986}
6987
6988
6989eHalStatus csrScanStartIdleScan(tpAniSirGlobal pMac)
6990{
6991 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
6992 tANI_U32 nTime = 0;
6993
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006994 smsLog(pMac, LOGW, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006995 if(pMac->roam.configParam.IsIdleScanEnabled)
6996 {
6997 //stop bg scan first
6998 csrScanBGScanAbort(pMac);
6999 //Stop get result timer because idle scan gets scan result out of PE
7000 csrScanStopGetResultTimer(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07007001 }
7002 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_FALSE;
7003 status = csrScanTriggerIdleScan(pMac, &nTime);
7004 if(!HAL_STATUS_SUCCESS(status))
7005 {
7006 csrScanStartIdleScanTimer(pMac, nTime);
7007 }
7008
7009 return (status);
7010}
7011
7012
7013void csrScanCancelIdleScan(tpAniSirGlobal pMac)
7014{
7015 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
7016 {
Agarwal Ashish5974ed32014-06-16 16:59:54 +05307017 if (vos_concurrent_open_sessions_running()) {
Jeff Johnson295189b2012-06-20 16:38:30 -07007018 return;
7019 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007020 smsLog(pMac, LOG1, " csrScanCancelIdleScan");
Jeff Johnson295189b2012-06-20 16:38:30 -07007021 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_TRUE;
7022 //Set the restart flag in case later on it is uncancelled
7023 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7024 csrScanStopIdleScanTimer(pMac);
7025 csrScanRemoveNotRoamingScanCommand(pMac);
7026 }
7027}
7028
7029
7030void csrScanIdleScanTimerHandler(void *pv)
7031{
7032 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
7033 eHalStatus status;
7034 tANI_U32 nTime = 0;
7035
7036 smsLog(pMac, LOGW, " csrScanIdleScanTimerHandler called ");
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07007037 pmcResetImpsFailStatus (pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07007038 status = csrScanTriggerIdleScan(pMac, &nTime);
7039 if(!HAL_STATUS_SUCCESS(status) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan))
7040 {
7041 //Check whether it is time to actually do an idle scan
7042 if(pMac->scan.nIdleScanTimeGap >= pMac->roam.configParam.impsSleepTime)
7043 {
7044 pMac->scan.nIdleScanTimeGap = 0;
7045 csrScanIMPSCallback(pMac, eHAL_STATUS_SUCCESS);
7046 }
7047 else
7048 {
7049 csrScanStartIdleScanTimer(pMac, nTime);
7050 }
7051 }
Rashmi Ramanna68b309c2014-05-20 11:52:22 +05307052 if(pMac->deferImps)
7053 {
7054 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7055 pMac->deferImps = eANI_BOOLEAN_FALSE;
7056 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007057}
7058
7059
7060
7061
7062tANI_BOOLEAN csrScanRemoveNotRoamingScanCommand(tpAniSirGlobal pMac)
7063{
7064 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
7065 tListElem *pEntry, *pEntryTmp;
7066 tSmeCmd *pCommand;
7067 tDblLinkList localList;
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307068 tDblLinkList *pCmdList;
Jeff Johnson295189b2012-06-20 16:38:30 -07007069
7070 vos_mem_zero(&localList, sizeof(tDblLinkList));
7071 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
7072 {
7073 smsLog(pMac, LOGE, FL(" failed to open list"));
7074 return fRet;
7075 }
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307076 if (!pMac->fScanOffload)
7077 pCmdList = &pMac->sme.smeCmdPendingList;
7078 else
7079 pCmdList = &pMac->sme.smeScanCmdPendingList;
Jeff Johnson295189b2012-06-20 16:38:30 -07007080
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307081 csrLLLock(pCmdList);
7082 pEntry = csrLLPeekHead(pCmdList, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007083 while(pEntry)
7084 {
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307085 pEntryTmp = csrLLNext(pCmdList, pEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007086 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7087 if( eSmeCommandScan == pCommand->command )
7088 {
7089 switch( pCommand->u.scanCmd.reason )
7090 {
7091 case eCsrScanIdleScan:
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307092 if( csrLLRemoveEntry(pCmdList, pEntry, LL_ACCESS_NOLOCK) )
Jeff Johnson295189b2012-06-20 16:38:30 -07007093 {
7094 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
7095 }
7096 fRet = eANI_BOOLEAN_TRUE;
7097 break;
7098
7099 default:
7100 break;
7101 } //switch
7102 }
7103 pEntry = pEntryTmp;
7104 }
7105
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307106 csrLLUnlock(pCmdList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007107
7108 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
7109 {
7110 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7111 csrReleaseCommandScan( pMac, pCommand );
7112 }
7113
7114 csrLLClose(&localList);
7115
7116 return (fRet);
7117}
7118
7119
7120tANI_BOOLEAN csrScanRemoveFreshScanCommand(tpAniSirGlobal pMac, tANI_U8 sessionId)
7121{
7122 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
7123 tListElem *pEntry, *pEntryTmp;
7124 tSmeCmd *pCommand;
7125 tDblLinkList localList;
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307126 tDblLinkList *pCmdList;
Jeff Johnson295189b2012-06-20 16:38:30 -07007127
7128 vos_mem_zero(&localList, sizeof(tDblLinkList));
7129 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
7130 {
7131 smsLog(pMac, LOGE, FL(" failed to open list"));
7132 return fRet;
7133 }
7134
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307135 if (!pMac->fScanOffload)
7136 pCmdList = &pMac->sme.smeCmdPendingList;
7137 else
7138 pCmdList = &pMac->sme.smeScanCmdPendingList;
7139
7140 csrLLLock(pCmdList);
7141 pEntry = csrLLPeekHead(pCmdList, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007142 while(pEntry)
7143 {
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307144 pEntryTmp = csrLLNext(pCmdList, pEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007145 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7146 if( (eSmeCommandScan == pCommand->command) && (sessionId == pCommand->sessionId) )
7147 {
7148 switch(pCommand->u.scanCmd.reason)
7149 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07007150#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
7151 case eCsrScanGetLfrResult:
7152#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07007153 case eCsrScanGetResult:
7154 case eCsrScanSetBGScanParam:
7155 case eCsrScanBGScanAbort:
7156 case eCsrScanBGScanEnable:
7157 case eCsrScanGetScanChnInfo:
7158 break;
7159 default:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007160 smsLog (pMac, LOGW, "%s: -------- abort scan command reason = %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007161 __func__, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07007162 //The rest are fresh scan requests
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307163 if( csrLLRemoveEntry(pCmdList, pEntry, LL_ACCESS_NOLOCK) )
Jeff Johnson295189b2012-06-20 16:38:30 -07007164 {
7165 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
7166 }
7167 fRet = eANI_BOOLEAN_TRUE;
7168 break;
7169 }
7170 }
7171 pEntry = pEntryTmp;
7172 }
7173
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307174 csrLLUnlock(pCmdList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007175
7176 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
7177 {
7178 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7179 if (pCommand->u.scanCmd.callback)
7180 {
7181 /* User scan request is pending,
7182 * send response with status eCSR_SCAN_ABORT*/
7183 pCommand->u.scanCmd.callback(pMac,
7184 pCommand->u.scanCmd.pContext,
7185 pCommand->u.scanCmd.scanID,
7186 eCSR_SCAN_ABORT);
7187 }
7188 csrReleaseCommandScan( pMac, pCommand );
7189 }
7190 csrLLClose(&localList);
7191
7192 return (fRet);
7193}
7194
7195
7196void csrReleaseScanCommand(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
7197{
7198 eCsrScanReason reason = pCommand->u.scanCmd.reason;
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307199 tANI_BOOLEAN status;
7200
7201 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07007202 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307203 tANI_U32 i;
7204 for(i = 0; i < CSR_ROAM_SESSION_MAX; i++)
7205 csrRoamStateChange(pMac, pCommand->u.scanCmd.lastRoamState[i], i);
7206 }
7207 else
7208 {
7209 csrRoamStateChange(pMac,
7210 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId],
7211 pCommand->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07007212 }
7213
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307214 csrScanCallCallback(pMac, pCommand, scanStatus);
Jeff Johnson295189b2012-06-20 16:38:30 -07007215
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007216 smsLog(pMac, LOG3, " Remove Scan command reason = %d", reason);
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307217 if (pMac->fScanOffload)
7218 {
7219 status = csrLLRemoveEntry(&pMac->sme.smeScanCmdActiveList,
7220 &pCommand->Link, LL_ACCESS_LOCK);
7221 }
7222 else
7223 {
7224 status = csrLLRemoveEntry(&pMac->sme.smeCmdActiveList,
7225 &pCommand->Link, LL_ACCESS_LOCK);
7226 }
7227
7228 if(status)
Jeff Johnson295189b2012-06-20 16:38:30 -07007229 {
7230 csrReleaseCommandScan( pMac, pCommand );
7231 }
7232 else
7233 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307234 smsLog(pMac, LOGE,
7235 " ********csrReleaseScanCommand cannot release command reason %d",
7236 pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07007237 }
7238}
7239
7240
7241eHalStatus csrScanGetPMKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
7242 tPmkidCandidateInfo *pPmkidList, tANI_U32 *pNumItems )
7243{
7244 eHalStatus status = eHAL_STATUS_SUCCESS;
7245 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
7246
Jeff Johnson32d95a32012-09-10 13:15:23 -07007247 if(!pSession)
7248 {
7249 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
7250 return eHAL_STATUS_FAILURE;
7251 }
7252
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007253 smsLog(pMac, LOGW, " pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07007254 csrResetPMKIDCandidateList(pMac, sessionId);
7255 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
7256 {
7257 tCsrScanResultFilter *pScanFilter;
7258 tCsrScanResultInfo *pScanResult;
7259 tScanResultHandle hBSSList;
7260 tANI_U32 nItems = *pNumItems;
7261
7262 *pNumItems = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05307263 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
7264 if ( NULL == pScanFilter )
7265 status = eHAL_STATUS_FAILURE;
7266 else
Jeff Johnson295189b2012-06-20 16:38:30 -07007267 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307268 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007269 //Here is the profile we need to connect to
7270 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
7271 if(HAL_STATUS_SUCCESS(status))
7272 {
7273 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
7274 if(HAL_STATUS_SUCCESS(status))
7275 {
7276 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumPmkidCandidate < nItems))
7277 {
7278 //NumPmkidCandidate adds up here
7279 csrProcessBSSDescForPMKIDList(pMac, &pScanResult->BssDescriptor,
7280 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
7281 }
7282 if(pSession->NumPmkidCandidate)
7283 {
7284 *pNumItems = pSession->NumPmkidCandidate;
Kiet Lam64c1b492013-07-12 13:56:44 +05307285 vos_mem_copy(pPmkidList, pSession->PmkidCandidateInfo,
7286 pSession->NumPmkidCandidate * sizeof(tPmkidCandidateInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07007287 }
7288 csrScanResultPurge(pMac, hBSSList);
7289 }//Have scan result
7290 csrFreeScanFilter(pMac, pScanFilter);
7291 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307292 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07007293 }
7294 }
7295
7296 return (status);
7297}
7298
7299
7300
7301#ifdef FEATURE_WLAN_WAPI
7302eHalStatus csrScanGetBKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
7303 tBkidCandidateInfo *pBkidList, tANI_U32 *pNumItems )
7304{
7305 eHalStatus status = eHAL_STATUS_SUCCESS;
7306 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
7307
Jeff Johnson32d95a32012-09-10 13:15:23 -07007308 if(!pSession)
7309 {
7310 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
7311 return eHAL_STATUS_FAILURE;
7312 }
7313
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007314 smsLog(pMac, LOGW, " pMac->scan.NumBkidCandidate = %d", pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07007315 csrResetBKIDCandidateList(pMac, sessionId);
7316 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
7317 {
7318 tCsrScanResultFilter *pScanFilter;
7319 tCsrScanResultInfo *pScanResult;
7320 tScanResultHandle hBSSList;
7321 tANI_U32 nItems = *pNumItems;
7322 *pNumItems = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05307323 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
7324 if ( NULL == pScanFilter )
7325 status = eHAL_STATUS_FAILURE;
7326 else
Jeff Johnson295189b2012-06-20 16:38:30 -07007327 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307328 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007329 //Here is the profile we need to connect to
7330 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
7331 if(HAL_STATUS_SUCCESS(status))
7332 {
7333 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
7334 if(HAL_STATUS_SUCCESS(status))
7335 {
7336 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumBkidCandidate < nItems))
7337 {
7338 //pMac->scan.NumBkidCandidate adds up here
7339 csrProcessBSSDescForBKIDList(pMac, &pScanResult->BssDescriptor,
7340 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
7341
7342 }
7343 if(pSession->NumBkidCandidate)
7344 {
7345 *pNumItems = pSession->NumBkidCandidate;
Kiet Lam64c1b492013-07-12 13:56:44 +05307346 vos_mem_copy(pBkidList, pSession->BkidCandidateInfo, pSession->NumBkidCandidate * sizeof(tBkidCandidateInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07007347 }
7348 csrScanResultPurge(pMac, hBSSList);
7349 }//Have scan result
7350 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307351 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07007352 }
7353 }
7354
7355 return (status);
7356}
7357#endif /* FEATURE_WLAN_WAPI */
7358
7359
7360
7361//This function is usually used for BSSs that suppresses SSID so the profile
7362//shall have one and only one SSID
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007363eHalStatus csrScanForSSID(tpAniSirGlobal pMac, tANI_U32 sessionId, tCsrRoamProfile *pProfile, tANI_U32 roamId, tANI_BOOLEAN notify)
Jeff Johnson295189b2012-06-20 16:38:30 -07007364{
7365 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
7366 tSmeCmd *pScanCmd = NULL;
7367 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
7368 tANI_U8 index = 0;
7369 tANI_U32 numSsid = pProfile->SSIDs.numOfSSIDs;
7370
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007371 smsLog(pMac, LOG2, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007372 //For WDS, we use the index 0. There must be at least one in there
7373 if( CSR_IS_WDS_STA( pProfile ) && numSsid )
7374 {
7375 numSsid = 1;
7376 }
7377 if(pMac->scan.fScanEnable && ( numSsid == 1 ) )
7378 {
7379 do
7380 {
7381 pScanCmd = csrGetCommandBuffer(pMac);
7382 if(!pScanCmd)
7383 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007384 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007385 break;
7386 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307387 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
7388 pScanCmd->u.scanCmd.pToRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
7389 if ( NULL == pScanCmd->u.scanCmd.pToRoamProfile )
krunal soni587bf012014-02-04 12:35:11 -08007390 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307391 status = eHAL_STATUS_FAILURE;
krunal soni587bf012014-02-04 12:35:11 -08007392 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307393 else
krunal soni587bf012014-02-04 12:35:11 -08007394 {
7395 status = csrRoamCopyProfile(pMac, pScanCmd->u.scanCmd.pToRoamProfile, pProfile);
7396 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007397 if(!HAL_STATUS_SUCCESS(status))
7398 break;
7399 pScanCmd->u.scanCmd.roamId = roamId;
7400 pScanCmd->command = eSmeCommandScan;
Jeff Johnsone7245742012-09-05 17:12:55 -07007401 pScanCmd->sessionId = (tANI_U8)sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07007402 pScanCmd->u.scanCmd.callback = NULL;
7403 pScanCmd->u.scanCmd.pContext = NULL;
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007404 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 -07007405 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Kiet Lam64c1b492013-07-12 13:56:44 +05307406 vos_mem_set(&pScanCmd->u.scanCmd.u.scanRequest, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007407 pScanCmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Jeff Johnson295189b2012-06-20 16:38:30 -07007408 pScanCmd->u.scanCmd.u.scanRequest.BSSType = pProfile->BSSType;
Jeff Johnsone7245742012-09-05 17:12:55 -07007409 // To avoid 11b rate in probe request Set p2pSearch flag as 1 for P2P Client Mode
7410 if(VOS_P2P_CLIENT_MODE == pProfile->csrPersona)
7411 {
7412 pScanCmd->u.scanCmd.u.scanRequest.p2pSearch = 1;
7413 }
Agarwal Ashish4f616132013-12-30 23:32:50 +05307414 if(pProfile->nAddIEScanLength)
Jeff Johnsone7245742012-09-05 17:12:55 -07007415 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307416 pScanCmd->u.scanCmd.u.scanRequest.pIEField = vos_mem_malloc(
7417 pProfile->nAddIEScanLength);
7418 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.pIEField )
7419 status = eHAL_STATUS_FAILURE;
7420 else
7421 status = eHAL_STATUS_SUCCESS;
7422 vos_mem_set(pScanCmd->u.scanCmd.u.scanRequest.pIEField,
7423 pProfile->nAddIEScanLength, 0);
7424 if (HAL_STATUS_SUCCESS(status))
Jeff Johnsone7245742012-09-05 17:12:55 -07007425 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307426 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.pIEField,
Agarwal Ashish4f616132013-12-30 23:32:50 +05307427 pProfile->addIEScan, pProfile->nAddIEScanLength);
Jeff Johnsone7245742012-09-05 17:12:55 -07007428 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = pProfile->nAddIEScanLength;
7429 }
7430 else
7431 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007432 smsLog(pMac, LOGE, "No memory for scanning IE fields");
Jeff Johnsone7245742012-09-05 17:12:55 -07007433 }
7434 } //Allocate memory for IE field
7435 else
7436 {
7437 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = 0;
7438 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07007439 /* For one channel be good enpugh time to receive beacon atleast */
7440 if( 1 == pProfile->ChannelInfo.numOfChannels )
7441 {
7442 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime = MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7443 pScanCmd->u.scanCmd.u.scanRequest.minChnTime = MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7444 }
7445 else
7446 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307447 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime =
7448 pMac->roam.configParam.nActiveMaxChnTime;
7449 pScanCmd->u.scanCmd.u.scanRequest.minChnTime =
7450 pMac->roam.configParam.nActiveMinChnTime;
Jeff Johnson32d95a32012-09-10 13:15:23 -07007451 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307452 pScanCmd->u.scanCmd.u.scanRequest.maxChnTimeBtc =
7453 pMac->roam.configParam.nActiveMaxChnTimeBtc;
7454 pScanCmd->u.scanCmd.u.scanRequest.minChnTimeBtc =
7455 pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07007456 if(pProfile->BSSIDs.numOfBSSIDs == 1)
7457 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307458 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.bssid,
7459 pProfile->BSSIDs.bssid, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07007460 }
7461 else
7462 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307463 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.bssid, bAddr, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07007464 }
7465 if(pProfile->ChannelInfo.numOfChannels)
7466 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307467 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(
7468 sizeof(*pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
7469 * pProfile->ChannelInfo.numOfChannels);
7470 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
7471 status = eHAL_STATUS_FAILURE;
7472 else
7473 status = eHAL_STATUS_SUCCESS;
7474 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
7475 if(HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07007476 {
7477 csrRoamIsChannelValid(pMac, pProfile->ChannelInfo.ChannelList[0]);
7478 for(index = 0; index < pProfile->ChannelInfo.numOfChannels; index++)
7479 {
7480 if(csrRoamIsValidChannel(pMac, pProfile->ChannelInfo.ChannelList[index]))
7481 {
7482 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels]
7483 = pProfile->ChannelInfo.ChannelList[index];
7484 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels++;
7485 }
7486 else
7487 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007488 smsLog(pMac, LOGW, FL("process a channel (%d) that is invalid"), pProfile->ChannelInfo.ChannelList[index]);
Jeff Johnson295189b2012-06-20 16:38:30 -07007489 }
7490
7491 }
7492 }
7493 else
7494 {
7495 break;
7496 }
7497
7498 }
7499 else
7500 {
7501 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
7502 }
7503 if(pProfile->SSIDs.numOfSSIDs)
7504 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307505 pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList = vos_mem_malloc(
7506 pProfile->SSIDs.numOfSSIDs * sizeof(tCsrSSIDInfo));
7507 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList )
7508 status = eHAL_STATUS_FAILURE;
7509 else
7510 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07007511 if(!HAL_STATUS_SUCCESS(status))
7512 {
7513 break;
7514 }
7515 pScanCmd->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 1;
Kiet Lam64c1b492013-07-12 13:56:44 +05307516 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList,
7517 pProfile->SSIDs.SSIDList, sizeof(tCsrSSIDInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07007518 }
7519 //Start process the command
7520 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
7521 if( !HAL_STATUS_SUCCESS( status ) )
7522 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007523 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07007524 break;
7525 }
7526 }while(0);
7527 if(!HAL_STATUS_SUCCESS(status))
7528 {
7529 if(pScanCmd)
7530 {
7531 csrReleaseCommandScan(pMac, pScanCmd);
7532 //TODO:free the memory that is allocated in this function
7533 }
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007534 if(notify)
7535 {
Jeff Johnson295189b2012-06-20 16:38:30 -07007536 csrRoamCallCallback(pMac, sessionId, NULL, roamId, eCSR_ROAM_FAILED, eCSR_ROAM_RESULT_FAILURE);
7537 }
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007538 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007539 }//valid
7540 else
7541 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007542 smsLog(pMac, LOGE, FL("cannot scan because scanEnable (%d) or numSSID (%d) is invalid"),
Jeff Johnson295189b2012-06-20 16:38:30 -07007543 pMac->scan.fScanEnable, pProfile->SSIDs.numOfSSIDs);
7544 }
7545
7546 return (status);
7547}
7548
7549
7550//Issue a scan base on the new capability infomation
7551//This should only happen when the associated AP changes its capability.
7552//After this scan is done, CSR reroams base on the new scan results
7553eHalStatus csrScanForCapabilityChange(tpAniSirGlobal pMac, tSirSmeApNewCaps *pNewCaps)
7554{
7555 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
7556 tSmeCmd *pScanCmd = NULL;
7557
7558 if(pNewCaps)
7559 {
7560 do
7561 {
7562 pScanCmd = csrGetCommandBuffer(pMac);
7563 if(!pScanCmd)
7564 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007565 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007566 status = eHAL_STATUS_RESOURCES;
7567 break;
7568 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307569 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007570 status = eHAL_STATUS_SUCCESS;
7571 pScanCmd->u.scanCmd.roamId = 0;
7572 pScanCmd->command = eSmeCommandScan;
7573 pScanCmd->u.scanCmd.callback = NULL;
7574 pScanCmd->u.scanCmd.pContext = NULL;
7575 pScanCmd->u.scanCmd.reason = eCsrScanForCapsChange;
7576 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
7577 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
7578 if( !HAL_STATUS_SUCCESS( status ) )
7579 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007580 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07007581 break;
7582 }
7583 }while(0);
7584 if(!HAL_STATUS_SUCCESS(status))
7585 {
7586 if(pScanCmd)
7587 {
7588 csrReleaseCommandScan(pMac, pScanCmd);
7589 }
7590 }
7591 }
7592
7593 return (status);
7594}
7595
7596
7597
7598void csrInitBGScanChannelList(tpAniSirGlobal pMac)
7599{
7600 tANI_U32 len = CSR_MIN(sizeof(pMac->roam.validChannelList), sizeof(pMac->scan.bgScanChannelList));
7601
Kiet Lam64c1b492013-07-12 13:56:44 +05307602 vos_mem_set(pMac->scan.bgScanChannelList, len, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007603 pMac->scan.numBGScanChannel = 0;
7604
7605 if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
7606 {
7607 pMac->roam.numValidChannels = len;
7608 pMac->scan.numBGScanChannel = (tANI_U8)CSR_MIN(len, WNI_CFG_BG_SCAN_CHANNEL_LIST_LEN);
Kiet Lam64c1b492013-07-12 13:56:44 +05307609 vos_mem_copy(pMac->scan.bgScanChannelList, pMac->roam.validChannelList,
7610 pMac->scan.numBGScanChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07007611 csrSetBGScanChannelList(pMac, pMac->scan.bgScanChannelList, pMac->scan.numBGScanChannel);
7612 }
7613}
7614
7615
7616//This function return TRUE if background scan channel list is adjusted.
7617//this function will only shrink the background scan channel list
7618tANI_BOOLEAN csrAdjustBGScanChannelList(tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels,
7619 tANI_U8 *pAdjustChannels, tANI_U8 *pNumAdjustChannels)
7620{
7621 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
7622 tANI_U8 i, j, count = *pNumAdjustChannels;
7623
7624 i = 0;
7625 while(i < count)
7626 {
7627 for(j = 0; j < NumChannels; j++)
7628 {
7629 if(pChannelList[j] == pAdjustChannels[i])
7630 break;
7631 }
7632 if(j == NumChannels)
7633 {
7634 //This channel is not in the list, remove it
7635 fRet = eANI_BOOLEAN_TRUE;
7636 count--;
7637 if(count - i)
7638 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307639 vos_mem_copy(&pAdjustChannels[i], &pAdjustChannels[i+1], count - i);
Jeff Johnson295189b2012-06-20 16:38:30 -07007640 }
7641 else
7642 {
7643 //already remove the last one. Done.
7644 break;
7645 }
7646 }
7647 else
7648 {
7649 i++;
7650 }
7651 }//while(i<count)
7652 *pNumAdjustChannels = count;
7653
7654 return (fRet);
7655}
7656
7657
7658//Get the list of the base channels to scan for passively 11d info
7659eHalStatus csrScanGetSupportedChannels( tpAniSirGlobal pMac )
7660{
7661 eHalStatus status = eHAL_STATUS_SUCCESS;
7662 int n = WNI_CFG_VALID_CHANNEL_LIST_LEN;
7663
7664 status = vos_nv_getSupportedChannels( pMac->scan.baseChannels.channelList, &n, NULL, NULL );
7665 if( HAL_STATUS_SUCCESS(status) )
7666 {
7667 pMac->scan.baseChannels.numChannels = (tANI_U8)n;
7668 }
7669 else
7670 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007671 smsLog( pMac, LOGE, FL(" failed") );
Jeff Johnson295189b2012-06-20 16:38:30 -07007672 pMac->scan.baseChannels.numChannels = 0;
7673 }
7674
7675 return ( status );
7676}
7677
7678//This function use the input pChannelList to validate the current saved channel list
7679eHalStatus csrSetBGScanChannelList( tpAniSirGlobal pMac, tANI_U8 *pAdjustChannels, tANI_U8 NumAdjustChannels)
7680{
7681 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumAdjustChannels;
7682
7683 return (ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pAdjustChannels, dataLen, NULL, eANI_BOOLEAN_FALSE));
7684}
7685
7686
7687void csrSetCfgValidChannelList( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels )
7688{
7689 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumChannels;
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05307690 eHalStatus status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007691
Mihir Shete31c435d2014-02-12 13:13:34 +05307692 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
7693 "%s: dump valid channel list(NumChannels(%d))",
7694 __func__,NumChannels);
7695 VOS_TRACE_HEX_DUMP(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
7696 pChannelList, NumChannels);
7697
Jeff Johnson295189b2012-06-20 16:38:30 -07007698 ccmCfgSetStr(pMac, WNI_CFG_VALID_CHANNEL_LIST, pChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
Leela Venkata Kiran Kumar Reddy Chiralac6663f72014-02-03 21:04:58 -08007699#ifdef QCA_WIFI_2_0
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05307700 if (pMac->fScanOffload)
7701 {
7702 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
7703 "Scan offload is enabled, update default chan list");
Leela Venkata Kiran Kumar Reddy Chiralac6663f72014-02-03 21:04:58 -08007704 status = csrUpdateChannelList(pMac);
7705 }
7706#else
7707 status = csrUpdateChannelList(pMac);
7708#endif
7709
7710 if (eHAL_STATUS_SUCCESS != status)
7711 {
7712 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR,
7713 "failed to update the supported channel list");
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05307714 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007715 return;
7716}
7717
7718
7719
7720/*
7721 * The Tx power limits are saved in the cfg for future usage.
7722 */
7723void csrSaveTxPowerToCfg( tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 cfgId )
7724{
7725 tListElem *pEntry;
7726 tANI_U32 cbLen = 0, dataLen;
7727 tCsrChannelPowerInfo *pChannelSet;
7728 tANI_U32 idx;
7729 tSirMacChanInfo *pChannelPowerSet;
7730 tANI_U8 *pBuf = NULL;
7731
7732 //allocate maximum space for all channels
7733 dataLen = WNI_CFG_VALID_CHANNEL_LIST_LEN * sizeof(tSirMacChanInfo);
Kiet Lam64c1b492013-07-12 13:56:44 +05307734 if ( (pBuf = vos_mem_malloc(dataLen)) != NULL )
Jeff Johnson295189b2012-06-20 16:38:30 -07007735 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307736 vos_mem_set(pBuf, dataLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007737 pChannelPowerSet = (tSirMacChanInfo *)(pBuf);
7738
7739 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
7740 // write the tuples (startChan, numChan, txPower) for each channel found in the channel power list.
7741 while( pEntry )
7742 {
7743 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
7744 if ( 1 != pChannelSet->interChannelOffset )
7745 {
7746 // we keep the 5G channel sets internally with an interchannel offset of 4. Expand these
7747 // to the right format... (inter channel offset of 1 is the only option for the triplets
7748 // that 11d advertises.
7749 if ((cbLen + (pChannelSet->numChannels * sizeof(tSirMacChanInfo))) >= dataLen)
7750 {
7751 // expanding this entry will overflow our allocation
7752 smsLog(pMac, LOGE,
7753 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007754 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07007755 pChannelSet->firstChannel,
7756 pChannelSet->numChannels,
7757 pChannelSet->interChannelOffset);
7758 break;
7759 }
7760
7761 for( idx = 0; idx < pChannelSet->numChannels; idx++ )
7762 {
7763 pChannelPowerSet->firstChanNum = (tSirMacChanNum)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007764 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07007765 pChannelPowerSet->numChannels = 1;
Jeff Johnson295189b2012-06-20 16:38:30 -07007766 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007767 smsLog(pMac, LOG3, " Setting Max Transmit Power %d", pChannelPowerSet->maxTxPower);
Jeff Johnson295189b2012-06-20 16:38:30 -07007768 cbLen += sizeof( tSirMacChanInfo );
7769 pChannelPowerSet++;
7770 }
7771 }
7772 else
7773 {
7774 if (cbLen >= dataLen)
7775 {
7776 // this entry will overflow our allocation
7777 smsLog(pMac, LOGE,
7778 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007779 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07007780 pChannelSet->firstChannel,
7781 pChannelSet->numChannels,
7782 pChannelSet->interChannelOffset);
7783 break;
7784 }
7785 pChannelPowerSet->firstChanNum = pChannelSet->firstChannel;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007786 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07007787 pChannelPowerSet->numChannels = pChannelSet->numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -07007788 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007789 smsLog(pMac, LOG3, " Setting Max Transmit Power %d, nTxPower %d", pChannelPowerSet->maxTxPower,pMac->roam.configParam.nTxPowerCap );
Jeff Johnson295189b2012-06-20 16:38:30 -07007790
7791
7792 cbLen += sizeof( tSirMacChanInfo );
7793 pChannelPowerSet++;
7794 }
7795
7796 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
7797 }
7798
7799 if(cbLen)
7800 {
7801 ccmCfgSetStr(pMac, cfgId, (tANI_U8 *)pBuf, cbLen, NULL, eANI_BOOLEAN_FALSE);
7802 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307803 vos_mem_free(pBuf);
Jeff Johnson295189b2012-06-20 16:38:30 -07007804 }//Allocate memory
7805}
7806
7807
7808void csrSetCfgCountryCode( tpAniSirGlobal pMac, tANI_U8 *countryCode )
7809{
7810 tANI_U8 cc[WNI_CFG_COUNTRY_CODE_LEN];
7811 ///v_REGDOMAIN_t DomainId;
7812
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007813 smsLog( pMac, LOG3, "Setting Country Code in Cfg from csrSetCfgCountryCode %s",countryCode );
Kiet Lam64c1b492013-07-12 13:56:44 +05307814 vos_mem_copy(cc, countryCode, WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07007815
7816 // don't program the bogus country codes that we created for Korea in the MAC. if we see
7817 // the bogus country codes, program the MAC with the right country code.
7818 if ( ( 'K' == countryCode[ 0 ] && '1' == countryCode[ 1 ] ) ||
7819 ( 'K' == countryCode[ 0 ] && '2' == countryCode[ 1 ] ) ||
7820 ( 'K' == countryCode[ 0 ] && '3' == countryCode[ 1 ] ) ||
7821 ( 'K' == countryCode[ 0 ] && '4' == countryCode[ 1 ] ) )
7822 {
7823 // replace the alternate Korea country codes, 'K1', 'K2', .. with 'KR' for Korea
7824 cc[ 1 ] = 'R';
7825 }
7826 ccmCfgSetStr(pMac, WNI_CFG_COUNTRY_CODE, cc, WNI_CFG_COUNTRY_CODE_LEN, NULL, eANI_BOOLEAN_FALSE);
7827
7828 //Need to let HALPHY know about the current domain so it can apply some
7829 //domain-specific settings (TX filter...)
7830 /*if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(pMac, cc, &DomainId)))
7831 {
7832 halPhySetRegDomain(pMac, DomainId);
7833 }*/
7834}
7835
7836
7837
7838eHalStatus csrGetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pBuf, tANI_U8 *pbLen)
7839{
7840 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
7841 tANI_U32 len;
7842
7843 if(pBuf && pbLen && (*pbLen >= WNI_CFG_COUNTRY_CODE_LEN))
7844 {
7845 len = *pbLen;
7846 status = ccmCfgGetStr(pMac, WNI_CFG_COUNTRY_CODE, pBuf, &len);
7847 if(HAL_STATUS_SUCCESS(status))
7848 {
7849 *pbLen = (tANI_U8)len;
7850 }
7851 }
7852
7853 return (status);
7854}
7855
7856
7857void csrSetCfgScanControlList( tpAniSirGlobal pMac, tANI_U8 *countryCode, tCsrChannel *pChannelList )
7858{
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05307859 tANI_U8 i, j, k;
Jeff Johnson295189b2012-06-20 16:38:30 -07007860 tANI_BOOLEAN found=FALSE;
7861 tANI_U8 *pControlList = NULL;
7862 tANI_U32 len = WNI_CFG_SCAN_CONTROL_LIST_LEN;
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05307863 tANI_U8 cfgActiveDFSChannels = 0;
7864 tANI_U8 *cfgActiveDFSChannelLIst = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07007865
Kiet Lam64c1b492013-07-12 13:56:44 +05307866 if ( (pControlList = vos_mem_malloc(WNI_CFG_SCAN_CONTROL_LIST_LEN)) != NULL )
Jeff Johnson295189b2012-06-20 16:38:30 -07007867 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307868 vos_mem_set((void *)pControlList, WNI_CFG_SCAN_CONTROL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007869 if(HAL_STATUS_SUCCESS(ccmCfgGetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, &len)))
7870 {
7871 for (i = 0; i < pChannelList->numChannels; i++)
7872 {
7873 for (j = 0; j < len; j += 2)
7874 {
7875 if (pControlList[j] == pChannelList->channelList[i])
7876 {
7877 found = TRUE;
7878 break;
7879 }
7880 }
7881
7882 if (found) // insert a pair(channel#, flag)
7883 {
Gopichand Nakkala392cbc12013-05-28 16:15:00 +05307884 pControlList[j+1] = csrGetScanType(pMac, pControlList[j]);
Jeff Johnson295189b2012-06-20 16:38:30 -07007885 found = FALSE; // reset the flag
Jeff Johnson295189b2012-06-20 16:38:30 -07007886
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05307887 // When DFS mode is 2, mark static channels as active
7888 if (pMac->scan.fEnableDFSChnlScan ==
7889 DFS_CHNL_SCAN_ENABLED_ACTIVE)
7890 {
7891 cfgActiveDFSChannels =
7892 pMac->roam.neighborRoamInfo.cfgParams.
7893 channelInfo.numOfChannels;
7894 cfgActiveDFSChannelLIst =
7895 pMac->roam.neighborRoamInfo.cfgParams.
7896 channelInfo.ChannelList;
7897 if (cfgActiveDFSChannelLIst)
7898 {
7899 for (k=0; k < cfgActiveDFSChannels; k++)
7900 {
7901 if(CSR_IS_CHANNEL_DFS(cfgActiveDFSChannelLIst[k])
7902 && (pControlList[j] ==
7903 cfgActiveDFSChannelLIst[k]))
7904 {
7905 pControlList[j+1] = eSIR_ACTIVE_SCAN;
7906 smsLog(pMac, LOG1, FL("Marked DFS ch %d"
7907 " as active"),
7908 cfgActiveDFSChannelLIst[k]);
7909 }
7910 }
7911 }
7912 }
7913 }
7914 }
7915
7916 smsLog(pMac, LOG1, FL("fEnableDFSChnlScan %d"),
7917 pMac->scan.fEnableDFSChnlScan);
Mihir Shete31c435d2014-02-12 13:13:34 +05307918 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
7919 "%s: dump scan control list",__func__);
7920 VOS_TRACE_HEX_DUMP(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
7921 pControlList, len);
7922
Jeff Johnson295189b2012-06-20 16:38:30 -07007923 ccmCfgSetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, len, NULL, eANI_BOOLEAN_FALSE);
7924 }//Successfully getting scan control list
Kiet Lam64c1b492013-07-12 13:56:44 +05307925 vos_mem_free(pControlList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007926 }//AllocateMemory
7927}
7928
Jeff Johnson295189b2012-06-20 16:38:30 -07007929//if bgPeriod is 0, background scan is disabled. It is in millisecond units
7930eHalStatus csrSetCfgBackgroundScanPeriod(tpAniSirGlobal pMac, tANI_U32 bgPeriod)
7931{
7932 return (ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, bgPeriod, (tCcmCfgSetCallback) csrScanCcmCfgSetCallback, eANI_BOOLEAN_FALSE));
7933}
7934
7935
7936void csrScanCcmCfgSetCallback(tHalHandle hHal, tANI_S32 result)
7937{
7938 tListElem *pEntry = NULL;
7939 tSmeCmd *pCommand = NULL;
7940 tpAniSirGlobal pMac = PMAC_STRUCT( hHal );
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307941 tDblLinkList *pCmdList ;
7942
7943 if (!pMac->fScanOffload)
7944 pCmdList = &pMac->sme.smeCmdActiveList;
7945 else
7946 pCmdList = &pMac->sme.smeScanCmdActiveList;
7947
7948 pEntry = csrLLPeekHead( pCmdList, LL_ACCESS_LOCK );
Jeff Johnson295189b2012-06-20 16:38:30 -07007949 if ( pEntry )
7950 {
7951 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7952 if ( eSmeCommandScan == pCommand->command )
7953 {
7954 eCsrScanStatus scanStatus = (CCM_IS_RESULT_SUCCESS(result)) ? eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
7955 csrReleaseScanCommand(pMac, pCommand, scanStatus);
7956 }
7957 else
7958 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007959 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
Jeff Johnson295189b2012-06-20 16:38:30 -07007960 }
7961 }
7962 smeProcessPendingQueue( pMac );
7963}
7964
7965eHalStatus csrProcessSetBGScanParam(tpAniSirGlobal pMac, tSmeCmd *pCommand)
7966{
7967 eHalStatus status;
7968 tCsrBGScanRequest *pScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
7969 tANI_U32 dataLen = sizeof( tANI_U8 ) * pScanReq->ChannelInfo.numOfChannels;
7970
7971 //***setcfg for background scan channel list
7972 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MINIMUM_CHANNEL_TIME, pScanReq->minChnTime, NULL, eANI_BOOLEAN_FALSE);
7973 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MAXIMUM_CHANNEL_TIME, pScanReq->maxChnTime, NULL, eANI_BOOLEAN_FALSE);
7974 //Not set the background scan interval if not connected because bd scan should not be run if not connected
7975 if(!csrIsAllSessionDisconnected(pMac))
7976 {
Jeff Johnson295189b2012-06-20 16:38:30 -07007977
7978#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
7979 {
7980 vos_log_scan_pkt_type *pScanLog = NULL;
7981
7982 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
7983 if(pScanLog)
7984 {
7985 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
7986 pScanLog->minChnTime = (v_U8_t)pScanReq->minChnTime;
7987 pScanLog->maxChnTime = (v_U8_t)pScanReq->maxChnTime;
7988 pScanLog->timeBetweenBgScan = (v_U8_t)pScanReq->scanInterval;
7989 pScanLog->numChannel = pScanReq->ChannelInfo.numOfChannels;
7990 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
7991 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307992 vos_mem_copy(pScanLog->channels,
7993 pScanReq->ChannelInfo.ChannelList,
7994 pScanLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07007995 }
7996 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
7997 }
7998 }
7999#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
8000
8001 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, pScanReq->scanInterval, NULL, eANI_BOOLEAN_FALSE);
8002 }
8003 else
8004 {
8005 //No need to stop aging because IDLE scan is still running
8006 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, 0, NULL, eANI_BOOLEAN_FALSE);
8007 }
8008
8009 if(pScanReq->SSID.length > WNI_CFG_SSID_LEN)
8010 {
8011 pScanReq->SSID.length = WNI_CFG_SSID_LEN;
8012 }
8013
8014 status = ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pScanReq->ChannelInfo.ChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
8015 status = ccmCfgSetStr(pMac, WNI_CFG_SSID, (tANI_U8 *)pScanReq->SSID.ssId, pScanReq->SSID.length, NULL, eANI_BOOLEAN_FALSE);
8016
8017
8018
8019 return (status);
8020}
8021
8022
c_hpothua3d45d52015-01-05 14:11:17 +05308023tSirAbortScanStatus csrScanAbortMacScan(tpAniSirGlobal pMac,
8024 tANI_U8 sessionId,
8025 eCsrAbortReason reason)
Jeff Johnson295189b2012-06-20 16:38:30 -07008026{
c_hpothua3d45d52015-01-05 14:11:17 +05308027 tSirAbortScanStatus abortScanStatus = eSIR_ABORT_ACTIVE_SCAN_LIST_EMPTY;
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308028 tSirSmeScanAbortReq *pMsg;
Jeff Johnson295189b2012-06-20 16:38:30 -07008029 tANI_U16 msgLen;
8030 tListElem *pEntry;
8031 tSmeCmd *pCommand;
8032
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308033 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07008034 {
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308035#ifdef WLAN_AP_STA_CONCURRENCY
8036 csrLLLock(&pMac->scan.scanCmdPendingList);
8037 while(NULL !=
8038 (pEntry = csrLLRemoveHead(&pMac->scan.scanCmdPendingList,
8039 LL_ACCESS_NOLOCK)))
8040 {
Jeff Johnson295189b2012-06-20 16:38:30 -07008041
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308042 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8043 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
8044 }
8045 csrLLUnlock(&pMac->scan.scanCmdPendingList);
Jeff Johnson295189b2012-06-20 16:38:30 -07008046#endif
8047
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308048 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
8049 csrRemoveCmdFromPendingList( pMac, &pMac->roam.roamCmdPendingList, eSmeCommandScan);
8050 csrRemoveCmdFromPendingList( pMac, &pMac->sme.smeCmdPendingList, eSmeCommandScan);
8051 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
8052
8053 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
8054 }
8055 else
8056 {
8057 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
8058 csrRemoveCmdWithSessionIdFromPendingList(pMac,
8059 sessionId,
8060 &pMac->sme.smeScanCmdPendingList,
8061 eSmeCommandScan);
8062 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
8063
8064 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
8065 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008066
8067 //We need to abort scan only if we are scanning
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308068 if(NULL != pEntry)
Jeff Johnson295189b2012-06-20 16:38:30 -07008069 {
8070 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308071 if(eSmeCommandScan == pCommand->command &&
8072 pCommand->sessionId == sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07008073 {
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308074 msgLen = (tANI_U16)(sizeof(tSirSmeScanAbortReq));
Kiet Lam64c1b492013-07-12 13:56:44 +05308075 pMsg = vos_mem_malloc(msgLen);
8076 if ( NULL == pMsg )
Jeff Johnson295189b2012-06-20 16:38:30 -07008077 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308078 smsLog(pMac, LOGE, FL("Failed to allocate memory for SmeScanAbortReq"));
c_hpothua3d45d52015-01-05 14:11:17 +05308079 abortScanStatus = eSIR_ABORT_SCAN_FAILURE;
Kiet Lam64c1b492013-07-12 13:56:44 +05308080 }
8081 else
8082 {
Ratheesh S Pece1f832015-07-25 15:50:25 +05308083 pCommand->u.scanCmd.abortScanIndication = eCSR_SCAN_ABORT_DEFAULT;
Srinivas, Dasari187ca4e2014-02-07 12:40:09 +05308084 if(reason == eCSR_SCAN_ABORT_DUE_TO_BAND_CHANGE)
8085 {
Ratheesh S Pece1f832015-07-25 15:50:25 +05308086 pCommand->u.scanCmd.abortScanIndication
8087 = eCSR_SCAN_ABORT_DUE_TO_BAND_CHANGE;
Srinivas, Dasari187ca4e2014-02-07 12:40:09 +05308088 }
Kiet Lam64c1b492013-07-12 13:56:44 +05308089 vos_mem_set((void *)pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008090 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_ABORT_IND);
8091 pMsg->msgLen = pal_cpu_to_be16(msgLen);
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308092 pMsg->sessionId = sessionId;
c_hpothua3d45d52015-01-05 14:11:17 +05308093 if (eHAL_STATUS_SUCCESS != palSendMBMessage(pMac->hHdd, pMsg))
8094 {
8095 smsLog(pMac, LOGE,
8096 FL("Failed to post eWNI_SME_SCAN_ABORT_IND"));
8097 abortScanStatus = eSIR_ABORT_SCAN_FAILURE;
Ratheesh S Pece1f832015-07-25 15:50:25 +05308098 pCommand->u.scanCmd.abortScanIndication = 0;
c_hpothua3d45d52015-01-05 14:11:17 +05308099 }
8100 else
8101 {
8102 abortScanStatus = eSIR_ABORT_ACTIVE_SCAN_LIST_NOT_EMPTY;
8103 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008104 }
8105 }
8106 }
8107
c_hpothua3d45d52015-01-05 14:11:17 +05308108 return(abortScanStatus);
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308109}
8110
8111void csrRemoveCmdWithSessionIdFromPendingList(tpAniSirGlobal pMac,
8112 tANI_U8 sessionId,
8113 tDblLinkList *pList,
8114 eSmeCommandType commandType)
8115{
8116 tDblLinkList localList;
8117 tListElem *pEntry;
8118 tSmeCmd *pCommand;
8119 tListElem *pEntryToRemove;
8120
8121 vos_mem_zero(&localList, sizeof(tDblLinkList));
8122 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
8123 {
8124 smsLog(pMac, LOGE, FL(" failed to open list"));
8125 return;
8126 }
8127
8128 csrLLLock(pList);
8129 if ((pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK)))
8130 {
8131
8132 /* Have to make sure we don't loop back to the head of the list,
8133 * which will happen if the entry is NOT on the list */
8134 while (pEntry)
8135 {
8136 pEntryToRemove = pEntry;
8137 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
8138 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
8139 if ((pCommand->command == commandType) &&
8140 (pCommand->sessionId == sessionId))
8141 {
8142 /* Remove that entry only */
8143 if (csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
8144 {
8145 csrLLInsertTail(&localList, pEntryToRemove,
8146 LL_ACCESS_NOLOCK);
8147 }
8148 }
8149 }
8150 }
8151 csrLLUnlock(pList);
8152
8153 while ((pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)))
8154 {
8155 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
8156 csrAbortCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
8157 }
8158
8159 csrLLClose(&localList);
Jeff Johnson295189b2012-06-20 16:38:30 -07008160}
8161
8162void csrRemoveCmdFromPendingList(tpAniSirGlobal pMac, tDblLinkList *pList,
8163 eSmeCommandType commandType )
8164{
8165 tDblLinkList localList;
8166 tListElem *pEntry;
8167 tSmeCmd *pCommand;
8168 tListElem *pEntryToRemove;
8169
8170 vos_mem_zero(&localList, sizeof(tDblLinkList));
8171 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
8172 {
8173 smsLog(pMac, LOGE, FL(" failed to open list"));
8174 return;
8175 }
8176
8177 csrLLLock(pList);
8178 if( !csrLLIsListEmpty( pList, LL_ACCESS_NOLOCK ) )
8179 {
8180 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK);
8181
8182 // Have to make sure we don't loop back to the head of the list, which will
8183 // happen if the entry is NOT on the list...
8184 while( pEntry )
8185 {
8186 pEntryToRemove = pEntry;
8187 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
8188 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
8189 if ( pCommand->command == commandType )
8190 {
8191 // Remove that entry only
8192 if(csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
8193 {
8194 csrLLInsertTail(&localList, pEntryToRemove, LL_ACCESS_NOLOCK);
8195 }
8196 }
8197 }
8198
8199
8200 }
8201 csrLLUnlock(pList);
8202
8203 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
8204 {
8205 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8206 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
8207 }
8208 csrLLClose(&localList);
8209
8210}
8211
Abhishek Singhdc2bfd42014-06-19 17:59:05 +05308212eHalStatus csrScanAbortScanForSSID(tpAniSirGlobal pMac, tANI_U32 sessionId)
8213{
8214 eHalStatus status = eHAL_STATUS_SUCCESS;
8215 tSirSmeScanAbortReq *pMsg;
8216 tANI_U16 msgLen;
8217 tListElem *pEntry;
8218 tSmeCmd *pCommand;
8219
8220 if (!pMac->fScanOffload)
8221 {
8222 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
8223#ifdef WLAN_AP_STA_CONCURRENCY
8224 csrRemoveScanForSSIDFromPendingList( pMac, &pMac->scan.scanCmdPendingList, sessionId);
8225#endif
8226 csrRemoveScanForSSIDFromPendingList( pMac, &pMac->roam.roamCmdPendingList, sessionId);
8227 csrRemoveScanForSSIDFromPendingList( pMac, &pMac->sme.smeCmdPendingList, sessionId);
8228 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
8229 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
8230 }
8231 else
8232 {
8233 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
8234 csrRemoveScanForSSIDFromPendingList( pMac, &pMac->sme.smeScanCmdPendingList, sessionId);
8235 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
8236 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
8237 }
8238
8239 if(NULL != pEntry)
8240 {
8241 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8242
8243 if ( (eSmeCommandScan == pCommand->command ) &&
8244 (sessionId == pCommand->sessionId))
8245 {
8246 if ( eCsrScanForSsid == pCommand->u.scanCmd.reason)
8247 {
8248 msgLen = (tANI_U16)(sizeof( tSirSmeScanAbortReq ));
8249 pMsg = vos_mem_malloc(msgLen);
8250 if ( NULL == pMsg )
8251 {
8252 status = eHAL_STATUS_FAILURE;
8253 smsLog(pMac, LOGE, FL("Failed to allocate memory for SmeScanAbortReq"));
8254 }
8255 else
8256 {
8257 vos_mem_zero((void *)pMsg, msgLen);
8258 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_ABORT_IND);
8259 pMsg->msgLen = pal_cpu_to_be16(msgLen);
8260 pMsg->sessionId = sessionId;
8261 status = palSendMBMessage(pMac->hHdd, pMsg);
8262 }
8263 }
8264 }
8265 }
8266 return( status );
8267}
8268
8269void csrRemoveScanForSSIDFromPendingList(tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 sessionId)
8270{
8271 tDblLinkList localList;
8272 tListElem *pEntry;
8273 tSmeCmd *pCommand;
8274 tListElem *pEntryToRemove;
8275
8276 vos_mem_zero(&localList, sizeof(tDblLinkList));
8277 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
8278 {
8279 smsLog(pMac, LOGE, FL(" failed to open list"));
8280 return;
8281 }
8282
8283 csrLLLock(pList);
8284 if( !csrLLIsListEmpty( pList, LL_ACCESS_NOLOCK ) )
8285 {
8286 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK);
8287
8288 // Have to make sure we don't loop back to the head of the list, which will
8289 // happen if the entry is NOT on the list...
8290 while( pEntry )
8291 {
8292 pEntryToRemove = pEntry;
8293 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
8294 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
8295 if ( (eSmeCommandScan == pCommand->command ) &&
8296 (sessionId == pCommand->sessionId) )
8297 {
8298 if ( eCsrScanForSsid == pCommand->u.scanCmd.reason)
8299 {
8300 // Remove that entry only
8301 if ( csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
8302 {
8303 csrLLInsertTail(&localList, pEntryToRemove, LL_ACCESS_NOLOCK);
8304 }
8305 }
8306 }
8307 }
8308 }
8309 csrLLUnlock(pList);
8310
8311 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
8312 {
8313 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8314 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
8315 }
8316 csrLLClose(&localList);
8317}
Jeff Johnson295189b2012-06-20 16:38:30 -07008318
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308319eHalStatus csrScanAbortMacScanNotForConnect(tpAniSirGlobal pMac,
8320 tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07008321{
8322 eHalStatus status = eHAL_STATUS_SUCCESS;
8323
8324 if( !csrIsScanForRoamCommandActive( pMac ) )
8325 {
8326 //Only abort the scan if it is not used for other roam/connect purpose
c_hpothua3d45d52015-01-05 14:11:17 +05308327 if (eSIR_ABORT_SCAN_FAILURE ==
8328 csrScanAbortMacScan(pMac, sessionId, eCSR_SCAN_ABORT_DEFAULT))
8329 {
8330 smsLog(pMac, LOGE, FL("fail to abort scan"));
8331 status = eHAL_STATUS_FAILURE;
8332 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008333 }
8334
8335 return (status);
8336}
8337
8338
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05308339eHalStatus csrScanGetScanChannelInfo(tpAniSirGlobal pMac, tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07008340{
8341 eHalStatus status = eHAL_STATUS_SUCCESS;
8342 tSirMbMsg *pMsg;
8343 tANI_U16 msgLen;
8344
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05308345 if (pMac->fScanOffload)
8346 msgLen = (tANI_U16)(sizeof(tSirSmeGetScanChanReq));
8347 else
8348 msgLen = (tANI_U16)(sizeof(tSirMbMsg));
8349
Kiet Lam64c1b492013-07-12 13:56:44 +05308350 pMsg = vos_mem_malloc(msgLen);
8351 if ( NULL == pMsg )
8352 status = eHAL_STATUS_FAILURE;
8353 else
Jeff Johnson295189b2012-06-20 16:38:30 -07008354 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308355 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008356 pMsg->type = eWNI_SME_GET_SCANNED_CHANNEL_REQ;
8357 pMsg->msgLen = msgLen;
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05308358 if (pMac->fScanOffload)
8359 ((tSirSmeGetScanChanReq *)pMsg)->sessionId = sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07008360 status = palSendMBMessage(pMac->hHdd, pMsg);
8361 }
8362
8363 return( status );
8364}
8365
8366tANI_BOOLEAN csrRoamIsValidChannel( tpAniSirGlobal pMac, tANI_U8 channel )
8367{
8368 tANI_BOOLEAN fValid = FALSE;
8369 tANI_U32 idxValidChannels;
8370 tANI_U32 len = pMac->roam.numValidChannels;
8371
8372 for ( idxValidChannels = 0; ( idxValidChannels < len ); idxValidChannels++ )
8373 {
8374 if ( channel == pMac->roam.validChannelList[ idxValidChannels ] )
8375 {
8376 fValid = TRUE;
8377 break;
8378 }
8379 }
8380
8381 return fValid;
8382}
8383
Manjunathappa Prakash4f1d5a52013-11-11 16:22:19 -08008384#ifdef FEATURE_WLAN_SCAN_PNO
Srikant Kuppa066904f2013-05-07 13:56:02 -07008385eHalStatus csrScanSavePreferredNetworkFound(tpAniSirGlobal pMac,
8386 tSirPrefNetworkFoundInd *pPrefNetworkFoundInd)
8387{
8388 v_U32_t uLen = 0;
8389 tpSirProbeRespBeacon pParsedFrame;
8390 tCsrScanResult *pScanResult = NULL;
8391 tSirBssDescription *pBssDescr = NULL;
8392 tANI_BOOLEAN fDupBss;
8393 tDot11fBeaconIEs *pIesLocal = NULL;
8394 tAniSSID tmpSsid;
8395 v_TIME_t timer=0;
8396 tpSirMacMgmtHdr macHeader = (tpSirMacMgmtHdr)pPrefNetworkFoundInd->data;
Abhishek Singhd3d4e022014-11-11 13:02:40 +05308397 boolean bFoundonAppliedChannel = FALSE;
8398 v_U32_t indx;
8399 u8 channelsAllowed[WNI_CFG_VALID_CHANNEL_LIST_LEN];
8400 v_U32_t numChannelsAllowed = WNI_CFG_VALID_CHANNEL_LIST_LEN;
Sushant Kaushik6274de62015-05-01 16:31:23 +05308401 tListElem *pEntry;
Abhishek Singhd3d4e022014-11-11 13:02:40 +05308402
Srikant Kuppa066904f2013-05-07 13:56:02 -07008403
8404 pParsedFrame =
Abhishek Singhc75726d2015-04-13 14:44:14 +05308405 (tpSirProbeRespBeacon)vos_mem_vmalloc(sizeof(tSirProbeRespBeacon));
Srikant Kuppa066904f2013-05-07 13:56:02 -07008406
8407 if (NULL == pParsedFrame)
8408 {
8409 smsLog(pMac, LOGE, FL(" fail to allocate memory for frame"));
8410 return eHAL_STATUS_RESOURCES;
8411 }
8412
8413 if ( pPrefNetworkFoundInd->frameLength <= SIR_MAC_HDR_LEN_3A )
8414 {
8415 smsLog(pMac, LOGE,
8416 FL("Not enough bytes in PNO indication probe resp frame! length=%d"),
8417 pPrefNetworkFoundInd->frameLength);
Abhishek Singhc75726d2015-04-13 14:44:14 +05308418 vos_mem_vfree(pParsedFrame);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008419 return eHAL_STATUS_FAILURE;
8420 }
8421
8422 if (sirConvertProbeFrame2Struct(pMac,
8423 &pPrefNetworkFoundInd->data[SIR_MAC_HDR_LEN_3A],
8424 pPrefNetworkFoundInd->frameLength - SIR_MAC_HDR_LEN_3A,
8425 pParsedFrame) != eSIR_SUCCESS ||
8426 !pParsedFrame->ssidPresent)
8427 {
8428 smsLog(pMac, LOGE,
8429 FL("Parse error ProbeResponse, length=%d"),
8430 pPrefNetworkFoundInd->frameLength);
Abhishek Singhc75726d2015-04-13 14:44:14 +05308431 vos_mem_vfree(pParsedFrame);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008432 return eHAL_STATUS_FAILURE;
8433 }
8434 //24 byte MAC header and 12 byte to ssid IE
8435 if (pPrefNetworkFoundInd->frameLength >
8436 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET))
8437 {
8438 uLen = pPrefNetworkFoundInd->frameLength -
8439 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET);
8440 }
8441
Kiet Lam64c1b492013-07-12 13:56:44 +05308442 pScanResult = vos_mem_malloc(sizeof(tCsrScanResult) + uLen);
8443 if ( NULL == pScanResult )
Srikant Kuppa066904f2013-05-07 13:56:02 -07008444 {
8445 smsLog(pMac, LOGE, FL(" fail to allocate memory for frame"));
8446 vos_mem_free(pParsedFrame);
8447 return eHAL_STATUS_RESOURCES;
8448 }
8449
Kiet Lam64c1b492013-07-12 13:56:44 +05308450 vos_mem_set(pScanResult, sizeof(tCsrScanResult) + uLen, 0);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008451 pBssDescr = &pScanResult->Result.BssDescriptor;
8452 /**
8453 * Length of BSS desription is without length of
8454 * length itself and length of pointer
8455 * that holds the next BSS description
8456 */
8457 pBssDescr->length = (tANI_U16)(
8458 sizeof(tSirBssDescription) - sizeof(tANI_U16) -
8459 sizeof(tANI_U32) + uLen);
8460 if (pParsedFrame->dsParamsPresent)
8461 {
8462 pBssDescr->channelId = pParsedFrame->channelNumber;
8463 }
8464 else if (pParsedFrame->HTInfo.present)
8465 {
8466 pBssDescr->channelId = pParsedFrame->HTInfo.primaryChannel;
8467 }
8468 else
8469 {
Mahesh A Saptasagaradd99792014-03-26 16:04:20 +05308470 /**
8471 * If Probe Responce received in PNO indication does not
8472 * contain DSParam IE or HT Info IE then add dummy channel
8473 * to the received BSS info so that Scan result received as
8474 * a part of PNO is updated to the supplicant. Specially
8475 * applicable in case of AP configured in 11A only mode.
8476 */
8477 if ((pMac->roam.configParam.bandCapability == eCSR_BAND_ALL) ||
8478 (pMac->roam.configParam.bandCapability == eCSR_BAND_24))
8479 {
8480 pBssDescr->channelId = 1;
8481 }
8482 else if(pMac->roam.configParam.bandCapability == eCSR_BAND_5G)
8483 {
8484 pBssDescr->channelId = 36;
8485 }
Abhishek Singhd3d4e022014-11-11 13:02:40 +05308486 /* Restrict the logic to ignore the pno indication for invalid channel
8487 * only if valid channel info is present in beacon/probe resp.
8488 * If no channel info is present in beacon/probe resp, always process
8489 * the pno indication.
8490 */
8491 bFoundonAppliedChannel = TRUE;
8492 }
8493
8494 if (0 != sme_GetCfgValidChannels(pMac, channelsAllowed, &numChannelsAllowed))
8495 {
8496 smsLog(pMac, LOGE, FL(" sme_GetCfgValidChannels failed "));
8497 csrFreeScanResultEntry(pMac, pScanResult);
Abhishek Singhc75726d2015-04-13 14:44:14 +05308498 vos_mem_vfree(pParsedFrame);
Abhishek Singhd3d4e022014-11-11 13:02:40 +05308499 return eHAL_STATUS_FAILURE;
8500 }
8501 /* Checking chhanelId with allowed channel list */
8502 for (indx = 0; indx < numChannelsAllowed; indx++)
8503 {
8504 if (pBssDescr->channelId == channelsAllowed[indx])
8505 {
8506 bFoundonAppliedChannel = TRUE;
8507 smsLog(pMac, LOG1, FL(" pno ind found on applied channel =%d\n "),
8508 pBssDescr->channelId);
8509 break;
8510 }
8511 }
8512 /* Ignore PNO indication if AP is on Invalid channel.
8513 */
8514 if(FALSE == bFoundonAppliedChannel)
8515 {
8516 smsLog(pMac, LOGW, FL(" prefered network found on invalid channel = %d"),
8517 pBssDescr->channelId);
8518 csrFreeScanResultEntry(pMac, pScanResult);
Abhishek Singhc75726d2015-04-13 14:44:14 +05308519 vos_mem_vfree(pParsedFrame);
Abhishek Singhd3d4e022014-11-11 13:02:40 +05308520 return eHAL_STATUS_FAILURE;
Srikant Kuppa066904f2013-05-07 13:56:02 -07008521 }
8522
8523 if ((pBssDescr->channelId > 0) && (pBssDescr->channelId < 15))
8524 {
8525 int i;
8526 // 11b or 11g packet
8527 // 11g iff extended Rate IE is present or
8528 // if there is an A rate in suppRate IE
8529 for (i = 0; i < pParsedFrame->supportedRates.numRates; i++)
8530 {
8531 if (sirIsArate(pParsedFrame->supportedRates.rate[i] & 0x7f))
8532 {
8533 pBssDescr->nwType = eSIR_11G_NW_TYPE;
8534 break;
8535 }
8536 }
8537 if (pParsedFrame->extendedRatesPresent)
8538 {
8539 pBssDescr->nwType = eSIR_11G_NW_TYPE;
8540 }
8541 }
8542 else
8543 {
8544 // 11a packet
8545 pBssDescr->nwType = eSIR_11A_NW_TYPE;
8546 }
8547
8548 pBssDescr->sinr = 0;
8549 pBssDescr->rssi = -1 * pPrefNetworkFoundInd->rssi;
8550 pBssDescr->beaconInterval = pParsedFrame->beaconInterval;
AnjaneeDevi Kapparapu4b043912014-02-18 13:22:35 +05308551 if (!pBssDescr->beaconInterval)
8552 {
8553 smsLog(pMac, LOGW,
8554 FL("Bcn Interval is Zero , default to 100" MAC_ADDRESS_STR),
8555 MAC_ADDR_ARRAY(pBssDescr->bssId) );
8556 pBssDescr->beaconInterval = 100;
8557 }
Srikant Kuppa066904f2013-05-07 13:56:02 -07008558 pBssDescr->timeStamp[0] = pParsedFrame->timeStamp[0];
8559 pBssDescr->timeStamp[1] = pParsedFrame->timeStamp[1];
8560 pBssDescr->capabilityInfo = *((tANI_U16 *)&pParsedFrame->capabilityInfo);
Kiet Lam64c1b492013-07-12 13:56:44 +05308561 vos_mem_copy((tANI_U8 *) &pBssDescr->bssId, (tANI_U8 *) macHeader->bssId, sizeof(tSirMacAddr));
Srikant Kuppa066904f2013-05-07 13:56:02 -07008562 pBssDescr->nReceivedTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
8563
Abhishek Singh195c03e2014-05-14 17:21:30 +05308564 smsLog( pMac, LOG1, FL("Bssid= "MAC_ADDRESS_STR
8565 " chan= %d, rssi = %d "),
Arif Hussain24bafea2013-11-15 15:10:03 -08008566 MAC_ADDR_ARRAY(pBssDescr->bssId),
Srikant Kuppa066904f2013-05-07 13:56:02 -07008567 pBssDescr->channelId,
Abhishek Singh195c03e2014-05-14 17:21:30 +05308568 pBssDescr->rssi);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008569
8570 //IEs
8571 if (uLen)
8572 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308573 vos_mem_copy(&pBssDescr->ieFields,
8574 pPrefNetworkFoundInd->data + (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET),
8575 uLen);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008576 }
8577
8578 pIesLocal = (tDot11fBeaconIEs *)( pScanResult->Result.pvIes );
8579 if ( !pIesLocal &&
8580 (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
8581 &pScanResult->Result.BssDescriptor, &pIesLocal))) )
8582 {
8583 smsLog(pMac, LOGE, FL(" Cannot parse IEs"));
8584 csrFreeScanResultEntry(pMac, pScanResult);
Abhishek Singhc75726d2015-04-13 14:44:14 +05308585 vos_mem_vfree(pParsedFrame);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008586 return eHAL_STATUS_RESOURCES;
8587 }
8588
8589 fDupBss = csrRemoveDupBssDescription( pMac,
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05308590 &pScanResult->Result.BssDescriptor, pIesLocal, &tmpSsid, &timer, FALSE);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008591 //Check whether we have reach out limit
8592 if ( CSR_SCAN_IS_OVER_BSS_LIMIT(pMac) )
8593 {
8594 //Limit reach
8595 smsLog(pMac, LOGE, FL(" BSS limit reached"));
8596 //Free the resources
8597 if( (pScanResult->Result.pvIes == NULL) && pIesLocal )
8598 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308599 vos_mem_free(pIesLocal);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008600 }
8601 csrFreeScanResultEntry(pMac, pScanResult);
8602 vos_mem_free(pParsedFrame);
8603 return eHAL_STATUS_RESOURCES;
8604 }
8605 //Add to scan cache
8606 csrScanAddResult(pMac, pScanResult, pIesLocal);
Sushant Kaushik6274de62015-05-01 16:31:23 +05308607 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
8608 if (pEntry && 0 != pMac->scan.scanResultCfgAgingTime)
8609 csrScanStartResultCfgAgingTimer(pMac);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008610
Kiet Lamb537cfb2013-11-07 12:56:49 +05308611 if( (pScanResult->Result.pvIes == NULL) && pIesLocal )
8612 {
8613 vos_mem_free(pIesLocal);
8614 }
8615
Abhishek Singhc75726d2015-04-13 14:44:14 +05308616 vos_mem_vfree(pParsedFrame);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008617
8618 return eHAL_STATUS_SUCCESS;
8619}
Manjunathappa Prakash4f1d5a52013-11-11 16:22:19 -08008620#endif //FEATURE_WLAN_SCAN_PNO
Srikant Kuppa066904f2013-05-07 13:56:02 -07008621
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008622#ifdef FEATURE_WLAN_LFR
8623void csrInitOccupiedChannelsList(tpAniSirGlobal pMac)
8624{
8625 tListElem *pEntry = NULL;
8626 tCsrScanResult *pBssDesc = NULL;
8627 tDot11fBeaconIEs *pIes = NULL;
Srinivas28b5b4e2012-12-12 13:07:53 -08008628 tpCsrNeighborRoamControlInfo pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
8629
8630 if (0 != pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels)
8631 {
8632 smsLog(pMac, LOG1, FL("%s: Ini file contains neighbor scan channel list,"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008633 " hence NO need to build occupied channel list (numChannels = %d)"),
Srinivas28b5b4e2012-12-12 13:07:53 -08008634 __func__, pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels);
8635 return;
8636 }
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008637
8638 if (!csrNeighborRoamIsNewConnectedProfile(pMac))
8639 {
8640 smsLog(pMac, LOG2, FL("%s: donot flush occupied list since current roam profile"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008641 " matches previous (numChannels = %d)"),
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008642 __func__, pMac->scan.occupiedChannels.numChannels);
8643 return;
8644 }
8645
8646 /* Empty occupied channels here */
8647 pMac->scan.occupiedChannels.numChannels = 0;
8648
8649 csrLLLock(&pMac->scan.scanResultList);
8650 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
8651 while( pEntry )
8652 {
8653 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
8654 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
8655
8656 //At this time, pBssDescription->Result.pvIes may be NULL
Srikant Kuppa866893f2012-12-27 17:28:14 -08008657 if( !pIes && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008658 &pBssDesc->Result.BssDescriptor, &pIes))) )
8659 {
8660 continue;
8661 }
8662
8663 csrScanAddToOccupiedChannels(pMac, pBssDesc, &pMac->scan.occupiedChannels, pIes);
8664
8665 /*
8666 * Free the memory allocated for pIes in csrGetParsedBssDescriptionIEs
8667 */
8668 if( (pBssDesc->Result.pvIes == NULL) && pIes )
8669 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308670 vos_mem_free(pIes);
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008671 }
8672
8673 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK );
8674 }//while
8675 csrLLUnlock(&pMac->scan.scanResultList);
Srikant Kuppa866893f2012-12-27 17:28:14 -08008676
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008677}
8678#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07008679
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008680eHalStatus csrScanCreateEntryInScanCache(tpAniSirGlobal pMac, tANI_U32 sessionId,
8681 tCsrBssid bssid, tANI_U8 channel)
8682{
8683 eHalStatus status = eHAL_STATUS_SUCCESS;
8684 tDot11fBeaconIEs *pNewIes = NULL;
8685 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
Praveen Kumar Sirisilla8bdfac42013-10-10 17:20:48 -07008686 tSirBssDescription *pNewBssDescriptor = NULL;
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008687 tANI_U32 size = 0;
8688
8689 if(NULL == pSession)
8690 {
8691 status = eHAL_STATUS_FAILURE;
8692 return status;
8693 }
8694 smsLog(pMac, LOG2, FL("csrScanCreateEntryInScanCache: Current bssid::"
Arif Hussain24bafea2013-11-15 15:10:03 -08008695 MAC_ADDRESS_STR),
8696 MAC_ADDR_ARRAY(pSession->pConnectBssDesc->bssId));
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008697 smsLog(pMac, LOG2, FL("csrScanCreateEntryInScanCache: My bssid::"
Arif Hussain24bafea2013-11-15 15:10:03 -08008698 MAC_ADDRESS_STR" channel %d"),
8699 MAC_ADDR_ARRAY(bssid), channel);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008700
8701 do
8702 {
8703 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
8704 pSession->pConnectBssDesc, &pNewIes)))
8705 {
8706 smsLog(pMac, LOGE, FL("%s: Failed to parse IEs"),
8707 __func__);
8708 status = eHAL_STATUS_FAILURE;
8709 break;
8710 }
8711
8712 size = pSession->pConnectBssDesc->length + sizeof(pSession->pConnectBssDesc->length);
Kiet Lam64c1b492013-07-12 13:56:44 +05308713 if (size)
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008714 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308715 pNewBssDescriptor = vos_mem_malloc(size);
8716 if ( NULL == pNewBssDescriptor )
8717 status = eHAL_STATUS_FAILURE;
8718 else
8719 status = eHAL_STATUS_SUCCESS;
8720 if (HAL_STATUS_SUCCESS(status))
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008721 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308722 vos_mem_copy(pNewBssDescriptor, pSession->pConnectBssDesc, size);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008723 }
8724 else
8725 {
8726 smsLog(pMac, LOGE, FL("%s: memory allocation failed"),
8727 __func__);
8728 status = eHAL_STATUS_FAILURE;
8729 break;
8730 }
8731
8732 //change the BSSID & channel as passed
Kiet Lam64c1b492013-07-12 13:56:44 +05308733 vos_mem_copy(pNewBssDescriptor->bssId, bssid, sizeof(tSirMacAddr));
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008734 pNewBssDescriptor->channelId = channel;
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07008735 if(NULL == csrScanAppendBssDescription( pMac, pNewBssDescriptor, pNewIes, TRUE ))
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008736 {
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07008737 smsLog(pMac, LOGE, FL("%s: csrScanAppendBssDescription failed"),
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008738 __func__);
8739 status = eHAL_STATUS_FAILURE;
8740 break;
8741 }
8742 }
8743 else
8744 {
8745 smsLog(pMac, LOGE, FL("%s: length of bss descriptor is 0"),
8746 __func__);
8747 status = eHAL_STATUS_FAILURE;
8748 break;
8749 }
8750 smsLog(pMac, LOGE, FL("%s: entry successfully added in scan cache"),
8751 __func__);
8752 }while(0);
8753
8754 if(pNewIes)
8755 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308756 vos_mem_free(pNewIes);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008757 }
8758 if(pNewBssDescriptor)
8759 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308760 vos_mem_free(pNewBssDescriptor);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008761 }
8762 return status;
8763}
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07008764
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08008765#ifdef FEATURE_WLAN_ESE
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07008766// Update the TSF with the difference in system time
8767void UpdateCCKMTSF(tANI_U32 *timeStamp0, tANI_U32 *timeStamp1, tANI_U32 *incr)
8768{
8769 tANI_U64 timeStamp64 = ((tANI_U64)*timeStamp1 << 32) | (*timeStamp0);
8770
8771 timeStamp64 = (tANI_U64)(timeStamp64 + (tANI_U64)*incr);
8772 *timeStamp0 = (tANI_U32)(timeStamp64 & 0xffffffff);
8773 *timeStamp1 = (tANI_U32)((timeStamp64 >> 32) & 0xffffffff);
8774}
8775#endif