blob: 1edb55845c352aa07191613ab444f4680a13691f [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 *);
122void csrScanResultAgingTimerHandler(void *pv);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -0800123static void csrScanResultCfgAgingTimerHandler(void *pv);
Jeff Johnson295189b2012-06-20 16:38:30 -0700124void csrScanIdleScanTimerHandler(void *);
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700125static void csrSetDefaultScanTiming( tpAniSirGlobal pMac, tSirScanType scanType, tCsrScanRequest *pScanRequest);
Jeff Johnson295189b2012-06-20 16:38:30 -0700126#ifdef WLAN_AP_STA_CONCURRENCY
127static void csrStaApConcTimerHandler(void *);
128#endif
Jeff Johnsone7245742012-09-05 17:12:55 -0700129tANI_BOOLEAN csrIsSupportedChannel(tpAniSirGlobal pMac, tANI_U8 channelId);
Jeff Johnson295189b2012-06-20 16:38:30 -0700130eHalStatus csrScanChannels( tpAniSirGlobal pMac, tSmeCmd *pCommand );
131void csrSetCfgValidChannelList( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels );
132void csrSaveTxPowerToCfg( tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 cfgId );
133void csrSetCfgCountryCode( tpAniSirGlobal pMac, tANI_U8 *countryCode );
134void csrPurgeChannelPower( tpAniSirGlobal pMac, tDblLinkList *pChannelList );
135//if bgPeriod is 0, background scan is disabled. It is in millisecond units
136eHalStatus csrSetCfgBackgroundScanPeriod(tpAniSirGlobal pMac, tANI_U32 bgPeriod);
137eHalStatus csrProcessSetBGScanParam(tpAniSirGlobal pMac, tSmeCmd *pCommand);
138void csrReleaseScanCommand(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus);
139static tANI_BOOLEAN csrScanValidateScanResult( tpAniSirGlobal pMac, tANI_U8 *pChannels,
140 tANI_U8 numChn, tSirBssDescription *pBssDesc,
141 tDot11fBeaconIEs **ppIes );
142eHalStatus csrSetBGScanChannelList( tpAniSirGlobal pMac, tANI_U8 *pAdjustChannels, tANI_U8 NumAdjustChannels);
143void csrReleaseCmdSingle(tpAniSirGlobal pMac, tSmeCmd *pCommand);
144tANI_BOOLEAN csrRoamIsValidChannel( tpAniSirGlobal pMac, tANI_U8 channel );
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700145void csrPruneChannelListForMode( tpAniSirGlobal pMac, tCsrChannel *pChannelList );
Jeff Johnson295189b2012-06-20 16:38:30 -0700146
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -0700147
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -0700148
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -0700149
Madan Mohan Koyyalamudi923c1e12012-11-30 17:53:27 -0800150static void csrReleaseScanCmdPendingList(tpAniSirGlobal pMac)
151{
152 tListElem *pEntry;
153 tSmeCmd *pCommand;
154
155 while((pEntry = csrLLRemoveHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK)) != NULL)
156 {
157 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
158 if ( eSmeCsrCommandMask & pCommand->command )
159 {
160 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_TRUE );
161 }
162 else
163 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800164 smsLog(pMac, LOGE, FL("Error: Received command : %d"),pCommand->command);
Madan Mohan Koyyalamudi923c1e12012-11-30 17:53:27 -0800165 }
166 }
167}
Jeff Johnson295189b2012-06-20 16:38:30 -0700168//pResult is invalid calling this function.
169void csrFreeScanResultEntry( tpAniSirGlobal pMac, tCsrScanResult *pResult )
170{
171 if( NULL != pResult->Result.pvIes )
172 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530173 vos_mem_free(pResult->Result.pvIes);
Jeff Johnson295189b2012-06-20 16:38:30 -0700174 }
Kiet Lam64c1b492013-07-12 13:56:44 +0530175 vos_mem_free(pResult);
Jeff Johnson295189b2012-06-20 16:38:30 -0700176}
177
178
179static eHalStatus csrLLScanPurgeResult(tpAniSirGlobal pMac, tDblLinkList *pList)
180{
181 eHalStatus status = eHAL_STATUS_SUCCESS;
182 tListElem *pEntry;
183 tCsrScanResult *pBssDesc;
184
185 csrLLLock(pList);
186
187 while((pEntry = csrLLRemoveHead(pList, LL_ACCESS_NOLOCK)) != NULL)
188 {
189 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
190 csrFreeScanResultEntry( pMac, pBssDesc );
191 }
192
193 csrLLUnlock(pList);
194
195 return (status);
196}
197
Jeff Johnson295189b2012-06-20 16:38:30 -0700198eHalStatus csrScanOpen( tpAniSirGlobal pMac )
199{
200 eHalStatus status;
201
202 do
203 {
204 csrLLOpen(pMac->hHdd, &pMac->scan.scanResultList);
205 csrLLOpen(pMac->hHdd, &pMac->scan.tempScanResults);
206 csrLLOpen(pMac->hHdd, &pMac->scan.channelPowerInfoList24);
207 csrLLOpen(pMac->hHdd, &pMac->scan.channelPowerInfoList5G);
208#ifdef WLAN_AP_STA_CONCURRENCY
209 csrLLOpen(pMac->hHdd, &pMac->scan.scanCmdPendingList);
210#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700211 pMac->scan.fFullScanIssued = eANI_BOOLEAN_FALSE;
212 pMac->scan.nBssLimit = CSR_MAX_BSS_SUPPORT;
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530213 status = vos_timer_init(&pMac->scan.hTimerGetResult, VOS_TIMER_TYPE_SW, csrScanGetResultTimerHandler, pMac);
214 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700215 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800216 smsLog(pMac, LOGE, FL("cannot allocate memory for getResult timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700217 break;
218 }
219#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530220 status = vos_timer_init(&pMac->scan.hTimerStaApConcTimer, VOS_TIMER_TYPE_SW, csrStaApConcTimerHandler, pMac);
221 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700222 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800223 smsLog(pMac, LOGE, FL("cannot allocate memory for hTimerStaApConcTimer timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700224 break;
225 }
226#endif
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530227 status = vos_timer_init(&pMac->scan.hTimerIdleScan, VOS_TIMER_TYPE_SW, csrScanIdleScanTimerHandler, pMac);
228 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700229 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800230 smsLog(pMac, LOGE, FL("cannot allocate memory for idleScan timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700231 break;
232 }
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530233 status = vos_timer_init(&pMac->scan.hTimerResultAging, VOS_TIMER_TYPE_SW, csrScanResultAgingTimerHandler, pMac);
234 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700235 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800236 smsLog(pMac, LOGE, FL("cannot allocate memory for ResultAging timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700237 break;
238 }
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530239 status = vos_timer_init(&pMac->scan.hTimerResultCfgAging, VOS_TIMER_TYPE_SW,
240 csrScanResultCfgAgingTimerHandler, pMac);
241 if (!HAL_STATUS_SUCCESS(status))
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -0800242 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800243 smsLog(pMac, LOGE, FL("cannot allocate memory for CFG ResultAging timer"));
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -0800244 break;
245 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700246 }while(0);
247
248 return (status);
249}
250
251
252eHalStatus csrScanClose( tpAniSirGlobal pMac )
253{
Jeff Johnson295189b2012-06-20 16:38:30 -0700254 csrLLScanPurgeResult(pMac, &pMac->scan.tempScanResults);
255 csrLLScanPurgeResult(pMac, &pMac->scan.scanResultList);
256#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudi923c1e12012-11-30 17:53:27 -0800257 csrReleaseScanCmdPendingList(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -0700258#endif
259 csrLLClose(&pMac->scan.scanResultList);
260 csrLLClose(&pMac->scan.tempScanResults);
261#ifdef WLAN_AP_STA_CONCURRENCY
262 csrLLClose(&pMac->scan.scanCmdPendingList);
263#endif
264 csrPurgeChannelPower(pMac, &pMac->scan.channelPowerInfoList24);
265 csrPurgeChannelPower(pMac, &pMac->scan.channelPowerInfoList5G);
266 csrLLClose(&pMac->scan.channelPowerInfoList24);
267 csrLLClose(&pMac->scan.channelPowerInfoList5G);
268 csrScanDisable(pMac);
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530269 vos_timer_destroy(&pMac->scan.hTimerResultAging);
270 vos_timer_destroy(&pMac->scan.hTimerResultCfgAging);
271 vos_timer_destroy(&pMac->scan.hTimerGetResult);
Jeff Johnson295189b2012-06-20 16:38:30 -0700272#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530273 vos_timer_destroy(&pMac->scan.hTimerStaApConcTimer);
Jeff Johnson295189b2012-06-20 16:38:30 -0700274#endif
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530275 vos_timer_destroy(&pMac->scan.hTimerIdleScan);
Jeff Johnson295189b2012-06-20 16:38:30 -0700276 return eHAL_STATUS_SUCCESS;
277}
278
279
280eHalStatus csrScanEnable( tpAniSirGlobal pMac )
281{
282
283 pMac->scan.fScanEnable = eANI_BOOLEAN_TRUE;
284 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
285
286 return eHAL_STATUS_SUCCESS;
287}
288
289
290eHalStatus csrScanDisable( tpAniSirGlobal pMac )
291{
292
293 csrScanStopTimers(pMac);
294 pMac->scan.fScanEnable = eANI_BOOLEAN_FALSE;
295
296 return eHAL_STATUS_SUCCESS;
297}
298
299
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700300//Set scan timing parameters according to state of other driver sessions
301//No validation of the parameters is performed.
302static void csrSetDefaultScanTiming( tpAniSirGlobal pMac, tSirScanType scanType, tCsrScanRequest *pScanRequest)
303{
304#ifdef WLAN_AP_STA_CONCURRENCY
305 if(csrIsAnySessionConnected(pMac))
306 {
Sushant Kaushika6fef4b2014-09-24 16:17:08 +0530307 //Reset passive scan time as per ini parameter.
Abhishek Singh7fb7dc12014-11-06 17:44:05 +0530308 ccmCfgSetInt(pMac, WNI_CFG_PASSIVE_MAXIMUM_CHANNEL_TIME,
Sushant Kaushika6fef4b2014-09-24 16:17:08 +0530309 pMac->roam.configParam.nPassiveMaxChnTimeConc,
310 NULL,eANI_BOOLEAN_FALSE);
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700311 //If multi-session, use the appropriate default scan times
312 if(scanType == eSIR_ACTIVE_SCAN)
313 {
314 pScanRequest->maxChnTime = pMac->roam.configParam.nActiveMaxChnTimeConc;
315 pScanRequest->minChnTime = pMac->roam.configParam.nActiveMinChnTimeConc;
316 }
317 else
318 {
319 pScanRequest->maxChnTime = pMac->roam.configParam.nPassiveMaxChnTimeConc;
320 pScanRequest->minChnTime = pMac->roam.configParam.nPassiveMinChnTimeConc;
321 }
Kiet Lam64c1b492013-07-12 13:56:44 +0530322 pScanRequest->maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
323 pScanRequest->minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700324
325 pScanRequest->restTime = pMac->roam.configParam.nRestTimeConc;
326
327 //Return so that fields set above will not be overwritten.
328 return;
329 }
330#endif
331
332 //This portion of the code executed if multi-session not supported
333 //(WLAN_AP_STA_CONCURRENCY not defined) or no multi-session.
334 //Use the "regular" (non-concurrency) default scan timing.
Abhishek Singh7fb7dc12014-11-06 17:44:05 +0530335 ccmCfgSetInt(pMac, WNI_CFG_PASSIVE_MAXIMUM_CHANNEL_TIME,
Kaushik, Sushant49758c12014-09-26 11:25:38 +0530336 pMac->roam.configParam.nPassiveMaxChnTime,
337 NULL,eANI_BOOLEAN_FALSE);
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700338 if(pScanRequest->scanType == eSIR_ACTIVE_SCAN)
339 {
340 pScanRequest->maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
341 pScanRequest->minChnTime = pMac->roam.configParam.nActiveMinChnTime;
342 }
343 else
344 {
345 pScanRequest->maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
346 pScanRequest->minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
347 }
Kiet Lam64c1b492013-07-12 13:56:44 +0530348 pScanRequest->maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
349 pScanRequest->minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700350
351#ifdef WLAN_AP_STA_CONCURRENCY
352 //No rest time if no sessions are connected.
353 pScanRequest->restTime = 0;
354#endif
355}
356
Jeff Johnson295189b2012-06-20 16:38:30 -0700357#ifdef WLAN_AP_STA_CONCURRENCY
358//Return SUCCESS is the command is queued, else returns eHAL_STATUS_FAILURE
359eHalStatus csrQueueScanRequest( tpAniSirGlobal pMac, tSmeCmd *pScanCmd )
360{
361 eHalStatus status = eHAL_STATUS_SUCCESS;
362
363 tANI_BOOLEAN fNoCmdPending;
364 tSmeCmd *pQueueScanCmd=NULL;
365 tSmeCmd *pSendScanCmd=NULL;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700366 tANI_U8 nNumChanCombinedConc = 0;
Gopichand Nakkala114718f2013-03-25 19:19:46 -0700367 if (NULL == pScanCmd)
368 {
369 smsLog (pMac, LOGE, FL("Scan Req cmd is NULL"));
370 return eHAL_STATUS_FAILURE;
371 }
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -0800372 /* split scan if any one of the following:
373 * - STA session is connected and the scan is not a P2P search
374 * - any P2P session is connected
Srikant Kuppa866893f2012-12-27 17:28:14 -0800375 * Do not split scans if no concurrent infra connections are
376 * active and if the scan is a BG scan triggered by LFR (OR)
377 * any scan if LFR is in the middle of a BG scan. Splitting
378 * the scan is delaying the time it takes for LFR to find
379 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -0800380 */
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700381
382 if(csrIsStaSessionConnected(pMac) &&
383 !csrIsP2pSessionConnected(pMac))
384 {
385 nNumChanCombinedConc = pMac->roam.configParam.nNumStaChanCombinedConc;
386 }
387 else if(csrIsP2pSessionConnected(pMac))
388 {
389 nNumChanCombinedConc = pMac->roam.configParam.nNumP2PChanCombinedConc;
390 }
Srikant Kuppa866893f2012-12-27 17:28:14 -0800391 if ( (csrIsStaSessionConnected(pMac) &&
392#ifdef FEATURE_WLAN_LFR
393 (csrIsConcurrentInfraConnected(pMac) ||
394 ((pScanCmd->u.scanCmd.reason != eCsrScanBgScan) &&
395 (pMac->roam.neighborRoamInfo.neighborRoamState !=
396 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
397#endif
398 (pScanCmd->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Vinay Malekal05fdc812012-12-17 13:04:30 -0800399 (csrIsP2pSessionConnected(pMac)) )
Jeff Johnson295189b2012-06-20 16:38:30 -0700400 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700401 tCsrScanRequest scanReq;
402 tANI_U8 numChn = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
403 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
404 tANI_U8 channelToScan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
Jeff Johnson295189b2012-06-20 16:38:30 -0700405 tANI_BOOLEAN bMemAlloc = eANI_BOOLEAN_FALSE;
406
407 if (numChn == 0)
408 {
409
410 numChn = pMac->scan.baseChannels.numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -0700411
Kiet Lam64c1b492013-07-12 13:56:44 +0530412 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(numChn);
413 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -0700414 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800415 smsLog( pMac, LOGE, FL(" Failed to get memory for channel list ") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800416 return eHAL_STATUS_FAILURE;
417 }
418 bMemAlloc = eANI_BOOLEAN_TRUE;
Kiet Lam64c1b492013-07-12 13:56:44 +0530419 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
420 pMac->scan.baseChannels.channelList, numChn);
421 status = eHAL_STATUS_SUCCESS;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800422 if( !HAL_STATUS_SUCCESS( status ) )
423 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530424 vos_mem_free(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800425 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800426 smsLog( pMac, LOGE, FL(" Failed to copy memory to channel list ") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800427 return eHAL_STATUS_FAILURE;
428 }
429 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = numChn;
430 }
Sushant Kaushik826de802014-05-08 18:04:11 +0530431 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
432 "%s: Total Number of channels to scan : %d "
433 "Splitted in group of %d ", __func__, numChn,
434 nNumChanCombinedConc);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800435 //Whenever we get a scan request with multiple channels we break it up into 2 requests
436 //First request for first channel to scan and second request to scan remaining channels
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700437 if ( numChn > nNumChanCombinedConc)
Vinay Malekal05fdc812012-12-17 13:04:30 -0800438 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530439 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800440
441 pQueueScanCmd = csrGetCommandBuffer(pMac); //optimize this to use 2 command buffer only
442 if (!pQueueScanCmd)
443 {
444 if (bMemAlloc)
Jeff Johnson295189b2012-06-20 16:38:30 -0700445 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530446 vos_mem_free(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800447 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
448
Jeff Johnson295189b2012-06-20 16:38:30 -0700449 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800450 smsLog( pMac, LOGE, FL(" Failed to get Queue command buffer") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800451 return eHAL_STATUS_FAILURE;
452 }
453 pQueueScanCmd->command = pScanCmd->command;
454 pQueueScanCmd->sessionId = pScanCmd->sessionId;
455 pQueueScanCmd->u.scanCmd.callback = pScanCmd->u.scanCmd.callback;
456 pQueueScanCmd->u.scanCmd.pContext = pScanCmd->u.scanCmd.pContext;
457 pQueueScanCmd->u.scanCmd.reason = pScanCmd->u.scanCmd.reason;
458 pQueueScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Jeff Johnson295189b2012-06-20 16:38:30 -0700459
Vinay Malekal05fdc812012-12-17 13:04:30 -0800460 /* First copy all the parameters to local variable of scan request */
461 csrScanCopyRequest(pMac, &scanReq, &pScanCmd->u.scanCmd.u.scanRequest);
Madan Mohan Koyyalamudiaf2a8b92012-10-09 14:58:07 -0700462
Vinay Malekal05fdc812012-12-17 13:04:30 -0800463 /* Now modify the elements of local var scan request required to be modified for split scan */
464 if(scanReq.ChannelInfo.ChannelList != NULL)
465 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530466 vos_mem_free(scanReq.ChannelInfo.ChannelList);
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -0800467 scanReq.ChannelInfo.ChannelList = NULL;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800468 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700469
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700470 pChnInfo->numOfChannels = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels - nNumChanCombinedConc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700471
Vinay Malekal05fdc812012-12-17 13:04:30 -0800472 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_WARN,
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +0530473 FL(" &channelToScan %p pScanCmd(%p) pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList(%p)numChn(%d)"),
474 &channelToScan[0], pScanCmd,
475 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList, numChn);
Jeff Johnson295189b2012-06-20 16:38:30 -0700476
Kiet Lam64c1b492013-07-12 13:56:44 +0530477 vos_mem_copy(&channelToScan[0],
478 &pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[
479 nNumChanCombinedConc],
480 pChnInfo->numOfChannels * sizeof(tANI_U8));
Vinay Malekal05fdc812012-12-17 13:04:30 -0800481
482 pChnInfo->ChannelList = &channelToScan[0];
483
484 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
c_hpothudbefd3e2014-04-28 15:59:47 +0530485
Vinay Malekal05fdc812012-12-17 13:04:30 -0800486 //Use concurrency values for min/maxChnTime.
487 //We know csrIsAnySessionConnected(pMac) returns TRUE here
488 csrSetDefaultScanTiming(pMac, scanReq.scanType, &scanReq);
489
490 status = csrScanCopyRequest(pMac, &pQueueScanCmd->u.scanCmd.u.scanRequest, &scanReq);
491
492 if(!HAL_STATUS_SUCCESS(status))
493 {
494 if (bMemAlloc)
495 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530496 vos_mem_free(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800497 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
498
499 }
500 if( scanReq.pIEField != NULL)
501 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530502 vos_mem_free(scanReq.pIEField);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800503 scanReq.pIEField = NULL;
504 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800505 smsLog( pMac, LOGE, FL(" Failed to get copy csrScanRequest = %d"), status );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800506 return eHAL_STATUS_FAILURE;
507 }
508 /* Clean the local scan variable */
509 scanReq.ChannelInfo.ChannelList = NULL;
510 scanReq.ChannelInfo.numOfChannels = 0;
511 csrScanFreeRequest(pMac, &scanReq);
512
513 /* setup the command to scan 2 channels */
514 pSendScanCmd = pScanCmd;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700515 pSendScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nNumChanCombinedConc;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800516 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 pSendScanCmd->u.scanCmd.callback = NULL;
522 } else {
523 pSendScanCmd = pScanCmd;
524 pSendScanCmd->u.scanCmd.u.scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
c_hpothudbefd3e2014-04-28 15:59:47 +0530525
Vinay Malekal05fdc812012-12-17 13:04:30 -0800526 //Use concurrency values for min/maxChnTime.
527 //We know csrIsAnySessionConnected(pMac) returns TRUE here
528 csrSetDefaultScanTiming(pMac, pSendScanCmd->u.scanCmd.u.scanRequest.scanType, &pSendScanCmd->u.scanCmd.u.scanRequest);
529 }
530
531 fNoCmdPending = csrLLIsListEmpty( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK );
532
533 //Logic Below is as follows
534 // If the scanCmdPendingList is empty then we directly send that command
535 // to smeCommandQueue else we buffer it in our scanCmdPendingList Queue
536 if( fNoCmdPending )
537 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700538 if (pQueueScanCmd != NULL)
539 {
Vinay Malekal05fdc812012-12-17 13:04:30 -0800540 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pQueueScanCmd->Link, LL_ACCESS_LOCK );
Jeff Johnson295189b2012-06-20 16:38:30 -0700541 }
542
543 if (pSendScanCmd != NULL)
544 {
545 return csrQueueSmeCommand(pMac, pSendScanCmd, eANI_BOOLEAN_FALSE);
546 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800547 }
548 else
549 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700550 if (pSendScanCmd != NULL)
551 {
552 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pSendScanCmd->Link, LL_ACCESS_LOCK );
553 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800554
Jeff Johnson295189b2012-06-20 16:38:30 -0700555 if (pQueueScanCmd != NULL)
556 {
557 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pQueueScanCmd->Link, LL_ACCESS_LOCK );
558 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800559 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700560 }
561 else
562 { //No concurrency case
Srikant Kuppa866893f2012-12-27 17:28:14 -0800563 smsLog( pMac, LOG2, FL("Queuing scan command (reason=%d, roamState=%d"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800564 " numOfChannels=%d)"),
Srikant Kuppa866893f2012-12-27 17:28:14 -0800565 pScanCmd->u.scanCmd.reason,
566 pMac->roam.neighborRoamInfo.neighborRoamState,
567 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -0700568 return csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
569 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700570
571 return ( status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700572}
573#endif
574
Jeff Johnsone7245742012-09-05 17:12:55 -0700575/* ---------------------------------------------------------------------------
576 \fn csrScan2GOnyRequest
577 \brief This function will update the scan request with only
Jeff Johnsonb88db982012-12-10 13:34:59 -0800578 2.4GHz valid channel list.
Jeff Johnsone7245742012-09-05 17:12:55 -0700579 \param pMac
580 \param pScanCmd
581 \param pScanRequest
582 \return None
583 -------------------------------------------------------------------------------*/
584static void csrScan2GOnyRequest(tpAniSirGlobal pMac,tSmeCmd *pScanCmd,
585 tCsrScanRequest *pScanRequest)
586{
587 tANI_U8 index, channelId, channelListSize = 0;
588 tANI_U8 channelList2G[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
589 static tANI_U8 validchannelList[CSR_MAX_2_4_GHZ_SUPPORTED_CHANNELS] = {0};
590
591 VOS_ASSERT(pScanCmd && pScanRequest);
Madan Mohan Koyyalamudi33ef6a22012-10-30 17:44:43 -0700592 /* To silence the KW tool null check is added */
593 if((pScanCmd == NULL) || (pScanRequest == NULL))
594 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800595 smsLog( pMac, LOGE, FL(" pScanCmd or pScanRequest is NULL "));
Madan Mohan Koyyalamudi33ef6a22012-10-30 17:44:43 -0700596 return;
597 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700598
599 if (pScanCmd->u.scanCmd.scanID ||
600 (eCSR_SCAN_REQUEST_FULL_SCAN != pScanRequest->requestType))
601 return;
602
603 //Contsruct valid Supported 2.4 GHz Channel List
604 for( index = 0; index < ARRAY_SIZE(channelList2G); index++ )
605 {
606 channelId = channelList2G[index];
607 if ( csrIsSupportedChannel( pMac, channelId ) )
608 {
609 validchannelList[channelListSize++] = channelId;
610 }
611 }
612
613 pScanRequest->ChannelInfo.numOfChannels = channelListSize;
614 pScanRequest->ChannelInfo.ChannelList = validchannelList;
615}
616
Jeff Johnson295189b2012-06-20 16:38:30 -0700617eHalStatus csrScanRequest(tpAniSirGlobal pMac, tANI_U16 sessionId,
618 tCsrScanRequest *pScanRequest, tANI_U32 *pScanRequestID,
619 csrScanCompleteCallback callback, void *pContext)
620{
621 eHalStatus status = eHAL_STATUS_FAILURE;
622 tSmeCmd *pScanCmd = NULL;
Madan Mohan Koyyalamudicb90bb22012-10-30 18:24:43 -0700623 eCsrConnectState ConnectState;
Jeff Johnson295189b2012-06-20 16:38:30 -0700624
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800625 if(pScanRequest == NULL)
626 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800627 smsLog( pMac, LOGE, FL(" pScanRequest is NULL"));
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800628 VOS_ASSERT(0);
Kaushik, Sushant488df382014-03-05 11:43:47 +0530629 return eHAL_STATUS_FAILURE ;
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800630 }
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700631
Kiet Lamd1f3dc82013-11-05 20:45:04 +0530632 /* During group formation, the P2P client scans for GO with the specific SSID.
633 * There will be chances of GO switching to other channels because of scan or
634 * to STA channel in case of STA+GO MCC scenario. So to increase the possibility
635 * of client to find the GO, the dwell time of scan is increased to 100ms.
636 */
637 if(pScanRequest->p2pSearch)
638 {
Rashmi Ramanna6f7931c2013-12-20 09:04:12 +0530639 if(pScanRequest->SSIDs.numOfSSIDs)
Kiet Lamd1f3dc82013-11-05 20:45:04 +0530640 {
Rashmi Ramanna6f7931c2013-12-20 09:04:12 +0530641 //If the scan request is for specific SSId the length of SSID will be
642 //greater than 7 as SSID for p2p search contains "DIRECT-")
643 if(pScanRequest->SSIDs.SSIDList->SSID.length > DIRECT_SSID_LEN)
644 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530645 smsLog( pMac, LOG1, FL("P2P: Increasing the min and max Dwell"
646 " time to %d for specific SSID scan %.*s"),
647 MAX_CHN_TIME_TO_FIND_GO,
648 pScanRequest->SSIDs.SSIDList->SSID.length,
649 pScanRequest->SSIDs.SSIDList->SSID.ssId);
Rashmi Ramanna6f7931c2013-12-20 09:04:12 +0530650 pScanRequest->maxChnTime = MAX_CHN_TIME_TO_FIND_GO;
651 pScanRequest->minChnTime = MIN_CHN_TIME_TO_FIND_GO;
652 }
Kiet Lamd1f3dc82013-11-05 20:45:04 +0530653 }
654 }
655
Jeff Johnson295189b2012-06-20 16:38:30 -0700656 do
657 {
658 if(pMac->scan.fScanEnable)
659 {
660 pScanCmd = csrGetCommandBuffer(pMac);
661 if(pScanCmd)
662 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530663 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -0700664 pScanCmd->command = eSmeCommandScan;
665 pScanCmd->sessionId = sessionId;
666 pScanCmd->u.scanCmd.callback = callback;
667 pScanCmd->u.scanCmd.pContext = pContext;
668 if(eCSR_SCAN_REQUEST_11D_SCAN == pScanRequest->requestType)
669 {
670 pScanCmd->u.scanCmd.reason = eCsrScan11d1;
671 }
672 else if((eCSR_SCAN_REQUEST_FULL_SCAN == pScanRequest->requestType) ||
673 (eCSR_SCAN_P2P_DISCOVERY == pScanRequest->requestType)
674#ifdef SOFTAP_CHANNEL_RANGE
675 ||(eCSR_SCAN_SOFTAP_CHANNEL_RANGE == pScanRequest->requestType)
676#endif
677 )
678 {
679 pScanCmd->u.scanCmd.reason = eCsrScanUserRequest;
680 }
681 else if(eCSR_SCAN_HO_BG_SCAN == pScanRequest->requestType)
682 {
683 pScanCmd->u.scanCmd.reason = eCsrScanBgScan;
684 }
685 else if(eCSR_SCAN_HO_PROBE_SCAN == pScanRequest->requestType)
686 {
687 pScanCmd->u.scanCmd.reason = eCsrScanProbeBss;
688 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700689 else if(eCSR_SCAN_P2P_FIND_PEER == pScanRequest->requestType)
690 {
691 pScanCmd->u.scanCmd.reason = eCsrScanP2PFindPeer;
692 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700693 else
694 {
695 pScanCmd->u.scanCmd.reason = eCsrScanIdleScan;
696 }
697 if(pScanRequest->minChnTime == 0 && pScanRequest->maxChnTime == 0)
698 {
699 //The caller doesn't set the time correctly. Set it here
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530700 csrSetDefaultScanTiming(pMac, pScanRequest->scanType,
701 pScanRequest);
702 smsLog(pMac, LOG1, FL("Setting default min %d and max %d"
703 " ChnTime"), pScanRequest->minChnTime,
704 pScanRequest->maxChnTime);
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700705 }
706#ifdef WLAN_AP_STA_CONCURRENCY
707 if(pScanRequest->restTime == 0)
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800708 {
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700709 //Need to set restTime only if at least one session is connected
710 if(csrIsAnySessionConnected(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -0700711 {
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700712 pScanRequest->restTime = pMac->roam.configParam.nRestTimeConc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700713 }
714 }
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700715#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -0700716 /*For Standalone wlan : channel time will remain the same.
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530717 For BTC with A2DP up: Channel time = Channel time * 2, if station is not already associated.
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800718 This has been done to provide a larger scan window for faster connection during btc.Else Scan is seen
719 to take a long time.
720 For BTC with A2DP up: Channel time will not be doubled, if station is already associated.
721 */
Jeff Johnson32d95a32012-09-10 13:15:23 -0700722 status = csrRoamGetConnectState(pMac,sessionId,&ConnectState);
Srinivas Girigowdac84c57c2013-02-19 17:41:56 -0800723 if (HAL_STATUS_SUCCESS(status) &&
724 pMac->btc.fA2DPUp &&
Jeff Johnson32d95a32012-09-10 13:15:23 -0700725 (eCSR_ASSOC_STATE_TYPE_INFRA_ASSOCIATED != ConnectState) &&
726 (eCSR_ASSOC_STATE_TYPE_IBSS_CONNECTED != ConnectState))
727 {
728 pScanRequest->maxChnTime = pScanRequest->maxChnTime << 1;
729 pScanRequest->minChnTime = pScanRequest->minChnTime << 1;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530730 smsLog( pMac, LOG1, FL("BTC A2DP up, doubling max and min"
731 " ChnTime (Max=%d Min=%d)"),
732 pScanRequest->maxChnTime,
733 pScanRequest->minChnTime);
Jeff Johnson32d95a32012-09-10 13:15:23 -0700734 }
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800735
Kiet Lam64c1b492013-07-12 13:56:44 +0530736 pScanRequest->maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
737 pScanRequest->minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700738 //Need to make the following atomic
739 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
740
741 if(pScanRequestID)
742 {
743 *pScanRequestID = pScanCmd->u.scanCmd.scanID;
744 }
745
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800746 // If it is the first scan request from HDD, CSR checks if it is for 11d.
Jeff Johnson295189b2012-06-20 16:38:30 -0700747 // If it is not, CSR will save the scan request in the pending cmd queue
748 // & issue an 11d scan request to PE.
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800749 if (((0 == pScanCmd->u.scanCmd.scanID)
Jeff Johnson295189b2012-06-20 16:38:30 -0700750 && (eCSR_SCAN_REQUEST_11D_SCAN != pScanRequest->requestType))
751#ifdef SOFTAP_CHANNEL_RANGE
752 && (eCSR_SCAN_SOFTAP_CHANNEL_RANGE != pScanRequest->requestType)
753#endif
754 && (eANI_BOOLEAN_FALSE == pMac->scan.fEnableBypass11d)
755 )
756 {
757 tSmeCmd *p11dScanCmd;
758 tCsrScanRequest scanReq;
759 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
760
Kiet Lam64c1b492013-07-12 13:56:44 +0530761 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -0700762
763 p11dScanCmd = csrGetCommandBuffer(pMac);
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800764 if (p11dScanCmd)
Jeff Johnson295189b2012-06-20 16:38:30 -0700765 {
766 tANI_U32 numChn = pMac->scan.baseChannels.numChannels;
767
Kiet Lam64c1b492013-07-12 13:56:44 +0530768 vos_mem_set(&p11dScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
769 pChnInfo->ChannelList = vos_mem_malloc(numChn);
770 if ( NULL == pChnInfo->ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -0700771 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530772 smsLog(pMac, LOGE, FL("Failed to allocate memory"));
773 status = eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -0700774 break;
775 }
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530776 vos_mem_copy(pChnInfo->ChannelList,
777 pMac->scan.baseChannels.channelList,
778 numChn);
Jeff Johnson295189b2012-06-20 16:38:30 -0700779 pChnInfo->numOfChannels = (tANI_U8)numChn;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530780
Jeff Johnson295189b2012-06-20 16:38:30 -0700781 p11dScanCmd->command = eSmeCommandScan;
Mihir Shetefc7ff5b2014-01-27 11:30:05 +0530782 p11dScanCmd->u.scanCmd.callback = pMac->scan.callback11dScanDone;
Jeff Johnson295189b2012-06-20 16:38:30 -0700783 p11dScanCmd->u.scanCmd.pContext = NULL;
c_hpothu0d5a7352014-03-22 12:30:25 +0530784 p11dScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID;
Jeff Johnson295189b2012-06-20 16:38:30 -0700785 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
786
787 if ( csrIs11dSupported(pMac) )
788 {
c_hpothudbefd3e2014-04-28 15:59:47 +0530789 scanReq.scanType = eSIR_PASSIVE_SCAN;
Jeff Johnson295189b2012-06-20 16:38:30 -0700790 scanReq.requestType = eCSR_SCAN_REQUEST_11D_SCAN;
791 p11dScanCmd->u.scanCmd.reason = eCsrScan11d1;
792 scanReq.maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
793 scanReq.minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
794 }
795 else
796 {
c_hpothudbefd3e2014-04-28 15:59:47 +0530797 scanReq.scanType = pScanRequest->scanType;
Jeff Johnson295189b2012-06-20 16:38:30 -0700798 scanReq.requestType = eCSR_SCAN_IDLE_MODE_SCAN;
799 p11dScanCmd->u.scanCmd.reason = eCsrScanIdleScan;
800 scanReq.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
801 scanReq.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800802
Madan Mohan Koyyalamudi04a65f02013-07-26 13:58:38 +0530803 scanReq.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
804 scanReq.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700805 }
c_hpothu059edb02014-03-12 21:44:28 +0530806 if (pMac->roam.configParam.nInitialDwellTime)
807 {
808 scanReq.maxChnTime =
809 pMac->roam.configParam.nInitialDwellTime;
810 smsLog(pMac, LOG1, FL("11d scan, updating"
811 "dwell time for first scan %u"),
812 scanReq.maxChnTime);
813 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700814
Jeff Johnson295189b2012-06-20 16:38:30 -0700815 status = csrScanCopyRequest(pMac, &p11dScanCmd->u.scanCmd.u.scanRequest, &scanReq);
816 //Free the channel list
Kiet Lam64c1b492013-07-12 13:56:44 +0530817 vos_mem_free(pChnInfo->ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -0700818 pChnInfo->ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -0700819
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800820 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700821 {
krunal soni5f112f02013-11-25 15:00:11 -0800822 pMac->scan.scanProfile.numOfChannels =
823 p11dScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -0700824 //Start process the command
825#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +0530826 if (!pMac->fScanOffload)
827 status = csrQueueScanRequest(pMac, p11dScanCmd);
828 else
829 status = csrQueueSmeCommand(pMac, p11dScanCmd,
830 eANI_BOOLEAN_FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -0700831#else
832 status = csrQueueSmeCommand(pMac, p11dScanCmd, eANI_BOOLEAN_FALSE);
833#endif
834 if( !HAL_STATUS_SUCCESS( status ) )
835 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530836 smsLog(pMac, LOGE, FL("Failed to send message"
837 " status = %d"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -0700838 break;
839 }
840 }
841 else
842 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530843 smsLog(pMac, LOGE, FL("csrScanCopyRequest failed"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700844 break;
845 }
846 }
847 else
848 {
849 //error
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530850 smsLog( pMac, LOGE, FL("p11dScanCmd failed") );
Jeff Johnson295189b2012-06-20 16:38:30 -0700851 break;
852 }
853 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700854
855 //Scan only 2G Channels if set in ini file
856 //This is mainly to reduce the First Scan duration
857 //Once we turn on Wifi
858 if(pMac->scan.fFirstScanOnly2GChnl)
859 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800860 smsLog( pMac, LOG1, FL("Scanning only 2G Channels during first scan"));
Jeff Johnsone7245742012-09-05 17:12:55 -0700861 csrScan2GOnyRequest(pMac, pScanCmd, pScanRequest);
862 }
863
c_hpothu059edb02014-03-12 21:44:28 +0530864 if (pMac->roam.configParam.nInitialDwellTime)
865 {
866 pScanRequest->maxChnTime =
867 pMac->roam.configParam.nInitialDwellTime;
868 pMac->roam.configParam.nInitialDwellTime = 0;
869 smsLog(pMac, LOG1,
870 FL("updating dwell time for first scan %u"),
871 pScanRequest->maxChnTime);
872 }
873
Jeff Johnson295189b2012-06-20 16:38:30 -0700874 status = csrScanCopyRequest(pMac, &pScanCmd->u.scanCmd.u.scanRequest, pScanRequest);
875 if(HAL_STATUS_SUCCESS(status))
876 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530877 tCsrScanRequest *pTempScanReq =
878 &pScanCmd->u.scanCmd.u.scanRequest;
krunal soni5f112f02013-11-25 15:00:11 -0800879 pMac->scan.scanProfile.numOfChannels =
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530880 pTempScanReq->ChannelInfo.numOfChannels;
krunal soni5f112f02013-11-25 15:00:11 -0800881
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530882 smsLog( pMac, LOG1, FL(" SId=%d scanId=%d"
883 " Scan reason=%u numSSIDs=%d"
884 " numChan=%d P2P search=%d minCT=%d maxCT=%d"
885 " minCBtc=%d maxCBtx=%d"),
886 sessionId, pScanCmd->u.scanCmd.scanID,
887 pScanCmd->u.scanCmd.reason,
888 pTempScanReq->SSIDs.numOfSSIDs,
889 pTempScanReq->ChannelInfo.numOfChannels,
890 pTempScanReq->p2pSearch,
891 pTempScanReq->minChnTime,
892 pTempScanReq->maxChnTime,
893 pTempScanReq->minChnTimeBtc,
894 pTempScanReq->maxChnTimeBtc );
Jeff Johnson295189b2012-06-20 16:38:30 -0700895 //Start process the command
896#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +0530897 if (!pMac->fScanOffload)
898 status = csrQueueScanRequest(pMac,pScanCmd);
899 else
900 status = csrQueueSmeCommand(pMac, pScanCmd,
901 eANI_BOOLEAN_FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -0700902#else
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530903 status = csrQueueSmeCommand(pMac, pScanCmd,
904 eANI_BOOLEAN_FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -0700905#endif
906 if( !HAL_STATUS_SUCCESS( status ) )
907 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800908 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700909 break;
910 }
911 }
912 else
913 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800914 smsLog( pMac, LOGE, FL(" fail to copy request status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700915 break;
916 }
917 }
918 else
919 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800920 smsLog( pMac, LOGE, FL(" pScanCmd is NULL"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700921 break;
922 }
923 }
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530924 else
925 {
926 smsLog( pMac, LOGE, FL("SId: %d Scanning not enabled"
927 " Scan type=%u, numOfSSIDs=%d P2P search=%d"),
928 sessionId, pScanRequest->requestType,
929 pScanRequest->SSIDs.numOfSSIDs,
930 pScanRequest->p2pSearch );
931 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700932 } while(0);
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530933
934
Jeff Johnson295189b2012-06-20 16:38:30 -0700935 if(!HAL_STATUS_SUCCESS(status) && pScanCmd)
936 {
937 if( eCsrScanIdleScan == pScanCmd->u.scanCmd.reason )
938 {
939 //Set the flag back for restarting idle scan
940 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
941 }
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530942 smsLog( pMac, LOGE, FL(" SId: %d Failed with status=%d"
943 " Scan reason=%u numOfSSIDs=%d"
944 " P2P search=%d scanId=%d"),
945 sessionId, status, pScanCmd->u.scanCmd.reason,
946 pScanRequest->SSIDs.numOfSSIDs, pScanRequest->p2pSearch,
947 pScanCmd->u.scanCmd.scanID );
Jeff Johnson295189b2012-06-20 16:38:30 -0700948 csrReleaseCommandScan(pMac, pScanCmd);
949 }
950
951 return (status);
952}
953
954
955eHalStatus csrScanRequestResult(tpAniSirGlobal pMac)
956{
957 eHalStatus status = eHAL_STATUS_SUCCESS;
958 tSmeCmd *pScanCmd;
959
960 if(pMac->scan.fScanEnable)
961 {
962 pScanCmd = csrGetCommandBuffer(pMac);
963 if(pScanCmd)
964 {
965 pScanCmd->command = eSmeCommandScan;
Kiet Lam64c1b492013-07-12 13:56:44 +0530966 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -0700967 pScanCmd->u.scanCmd.callback = NULL;
968 pScanCmd->u.scanCmd.pContext = NULL;
969 pScanCmd->u.scanCmd.reason = eCsrScanGetResult;
970 //Need to make the following atomic
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -0700971 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID; //let it wrap around
Jeff Johnson295189b2012-06-20 16:38:30 -0700972 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
973 if( !HAL_STATUS_SUCCESS( status ) )
974 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800975 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700976 csrReleaseCommandScan(pMac, pScanCmd);
977 }
978 }
979 else
980 {
981 //log error
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800982 smsLog(pMac, LOGE, FL("can not obtain a common buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700983 status = eHAL_STATUS_RESOURCES;
984 }
985 }
986
987 return (status);
988}
989
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -0700990#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
991eHalStatus csrScanRequestLfrResult(tpAniSirGlobal pMac, tANI_U32 sessionId,
992 csrScanCompleteCallback callback, void *pContext)
993{
994 eHalStatus status = eHAL_STATUS_SUCCESS;
995 tSmeCmd *pScanCmd;
996
997 if (pMac->scan.fScanEnable)
998 {
999 pScanCmd = csrGetCommandBuffer(pMac);
1000 if (pScanCmd)
1001 {
1002 pScanCmd->command = eSmeCommandScan;
1003 pScanCmd->sessionId = sessionId;
Kiet Lam64c1b492013-07-12 13:56:44 +05301004 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07001005 pScanCmd->u.scanCmd.callback = callback;
1006 pScanCmd->u.scanCmd.pContext = pContext;
1007 pScanCmd->u.scanCmd.reason = eCsrScanGetLfrResult;
1008 //Need to make the following atomic
1009 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID; //let it wrap around
1010 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_TRUE);
1011 if ( !HAL_STATUS_SUCCESS( status ) )
1012 {
1013 smsLog( pMac, LOGE, FL(" fail to send message status = %d\n"), status );
1014 csrReleaseCommandScan(pMac, pScanCmd);
1015 }
1016 }
1017 else
1018 {
1019 //log error
1020 smsLog(pMac, LOGE, FL("can not obtain a common buffer\n"));
1021 status = eHAL_STATUS_RESOURCES;
1022 }
1023 }
1024
1025 return (status);
1026}
1027#endif //WLAN_FEATURE_ROAM_SCAN_OFFLOAD
Jeff Johnson295189b2012-06-20 16:38:30 -07001028
1029eHalStatus csrScanAllChannels(tpAniSirGlobal pMac, eCsrRequestType reqType)
1030{
1031 eHalStatus status = eHAL_STATUS_SUCCESS;
1032 tANI_U32 scanId;
1033 tCsrScanRequest scanReq;
1034
Kiet Lam64c1b492013-07-12 13:56:44 +05301035 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001036 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
1037 scanReq.scanType = eSIR_ACTIVE_SCAN;
1038 scanReq.requestType = reqType;
1039 scanReq.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1040 scanReq.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001041 scanReq.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1042 scanReq.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001043 //Scan with invalid sessionId.
1044 //This results in SME using the first available session to scan.
1045 status = csrScanRequest(pMac, CSR_SESSION_ID_INVALID, &scanReq,
1046 &scanId, NULL, NULL);
1047
1048 return (status);
1049}
1050
1051
1052
1053
1054eHalStatus csrIssueRoamAfterLostlinkScan(tpAniSirGlobal pMac, tANI_U32 sessionId, eCsrRoamReason reason)
1055{
1056 eHalStatus status = eHAL_STATUS_FAILURE;
1057 tScanResultHandle hBSSList = NULL;
1058 tCsrScanResultFilter *pScanFilter = NULL;
1059 tANI_U32 roamId = 0;
1060 tCsrRoamProfile *pProfile = NULL;
1061 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1062
Jeff Johnson32d95a32012-09-10 13:15:23 -07001063 if(!pSession)
1064 {
1065 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1066 return eHAL_STATUS_FAILURE;
1067 }
1068
Jeff Johnson295189b2012-06-20 16:38:30 -07001069 do
1070 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001071 smsLog(pMac, LOG1, " csrIssueRoamAfterLostlinkScan called");
Jeff Johnson295189b2012-06-20 16:38:30 -07001072 if(pSession->fCancelRoaming)
1073 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001074 smsLog(pMac, LOGW, " lostlink roaming is cancelled");
Jeff Johnson295189b2012-06-20 16:38:30 -07001075 csrScanStartIdleScan(pMac);
1076 status = eHAL_STATUS_SUCCESS;
1077 break;
1078 }
1079 //Here is the profile we need to connect to
Kiet Lam64c1b492013-07-12 13:56:44 +05301080 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1081 if ( NULL == pScanFilter)
1082 status = eHAL_STATUS_FAILURE;
1083 else
1084 status = eHAL_STATUS_SUCCESS;
1085 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001086 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301087 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001088 if(NULL == pSession->pCurRoamProfile)
1089 {
1090 pScanFilter->EncryptionType.numEntries = 1;
1091 pScanFilter->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_NONE;
1092 }
1093 else
1094 {
1095 //We have to make a copy of pCurRoamProfile because it will be free inside csrRoamIssueConnect
Kiet Lam64c1b492013-07-12 13:56:44 +05301096 pProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1097 if ( NULL == pProfile )
1098 status = eHAL_STATUS_FAILURE;
1099 else
1100 status = eHAL_STATUS_SUCCESS;
1101 if (!HAL_STATUS_SUCCESS(status))
1102 break;
1103 vos_mem_set(pProfile, sizeof(tCsrRoamProfile), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001104 status = csrRoamCopyProfile(pMac, pProfile, pSession->pCurRoamProfile);
1105 if(!HAL_STATUS_SUCCESS(status))
1106 break;
1107 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1108 }//We have a profile
1109 roamId = GET_NEXT_ROAM_ID(&pMac->roam);
1110 if(HAL_STATUS_SUCCESS(status))
1111 {
1112 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1113 if(HAL_STATUS_SUCCESS(status))
1114 {
1115 if(eCsrLostLink1 == reason)
1116 {
1117 //we want to put the last connected BSS to the very beginning, if possible
1118 csrMoveBssToHeadFromBSSID(pMac, &pSession->connectedProfile.bssid, hBSSList);
1119 }
1120 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList, reason,
1121 roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1122 if(!HAL_STATUS_SUCCESS(status))
1123 {
1124 csrScanResultPurge(pMac, hBSSList);
1125 }
1126 }//Have scan result
1127 }
1128 }while(0);
1129 if(pScanFilter)
1130 {
1131 //we need to free memory for filter if profile exists
1132 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301133 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001134 }
1135 if(NULL != pProfile)
1136 {
1137 csrReleaseProfile(pMac, pProfile);
Kiet Lam64c1b492013-07-12 13:56:44 +05301138 vos_mem_free(pProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07001139 }
1140
1141 return (status);
1142}
1143
1144
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05301145eHalStatus csrScanGetScanChnInfo(tpAniSirGlobal pMac, tANI_U8 sessionId,
1146 void *pContext, void *callback)
Jeff Johnson295189b2012-06-20 16:38:30 -07001147{
1148 eHalStatus status = eHAL_STATUS_SUCCESS;
1149 tSmeCmd *pScanCmd;
1150
1151 if(pMac->scan.fScanEnable)
1152 {
1153 pScanCmd = csrGetCommandBuffer(pMac);
1154 if(pScanCmd)
1155 {
1156 pScanCmd->command = eSmeCommandScan;
Kiet Lam64c1b492013-07-12 13:56:44 +05301157 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson32d95a32012-09-10 13:15:23 -07001158 pScanCmd->u.scanCmd.callback = callback;
1159 pScanCmd->u.scanCmd.pContext = pContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07001160 pScanCmd->u.scanCmd.reason = eCsrScanGetScanChnInfo;
1161 //Need to make the following atomic
1162 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05301163 pScanCmd->sessionId = sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07001164 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
1165 if( !HAL_STATUS_SUCCESS( status ) )
1166 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001167 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001168 csrReleaseCommandScan(pMac, pScanCmd);
1169 }
1170 }
1171 else
1172 {
1173 //log error
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001174 smsLog(pMac, LOGE, FL("can not obtain a common buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001175 status = eHAL_STATUS_RESOURCES;
1176 }
1177 }
1178
1179 return (status);
1180}
1181
1182
1183eHalStatus csrScanHandleFailedLostlink1(tpAniSirGlobal pMac, tANI_U32 sessionId)
1184{
1185 eHalStatus status = eHAL_STATUS_FAILURE;
1186 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1187
Jeff Johnson32d95a32012-09-10 13:15:23 -07001188 if(!pSession)
1189 {
1190 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1191 return eHAL_STATUS_FAILURE;
1192 }
1193
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001194 smsLog(pMac, LOGW, " Lostlink scan 1 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001195 if(pSession->fCancelRoaming)
1196 {
1197 csrScanStartIdleScan(pMac);
1198 }
1199 else if(pSession->pCurRoamProfile)
1200 {
1201 //We fail lostlink1 but there may be other BSS in the cached result fit the profile. Give it a try first
1202 if(pSession->pCurRoamProfile->SSIDs.numOfSSIDs == 0 ||
1203 pSession->pCurRoamProfile->SSIDs.numOfSSIDs > 1)
1204 {
1205 //try lostlink scan2
1206 status = csrScanRequestLostLink2(pMac, sessionId);
1207 }
1208 else if(!pSession->pCurRoamProfile->ChannelInfo.ChannelList ||
1209 pSession->pCurRoamProfile->ChannelInfo.ChannelList[0] == 0)
1210 {
1211 //go straight to lostlink scan3
1212 status = csrScanRequestLostLink3(pMac, sessionId);
1213 }
1214 else
1215 {
1216 //we are done with lostlink
1217 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1218 {
1219 csrScanStartIdleScan(pMac);
1220 }
1221 status = eHAL_STATUS_SUCCESS;
1222 }
1223 }
1224 else
1225 {
1226 status = csrScanRequestLostLink3(pMac, sessionId);
1227 }
1228
1229 return (status);
1230}
1231
1232
1233
1234eHalStatus csrScanHandleFailedLostlink2(tpAniSirGlobal pMac, tANI_U32 sessionId)
1235{
1236 eHalStatus status = eHAL_STATUS_FAILURE;
1237 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1238
Jeff Johnson32d95a32012-09-10 13:15:23 -07001239 if(!pSession)
1240 {
1241 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1242 return eHAL_STATUS_FAILURE;
1243 }
1244
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001245 smsLog(pMac, LOGW, " Lostlink scan 2 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001246 if(pSession->fCancelRoaming)
1247 {
1248 csrScanStartIdleScan(pMac);
1249 }
1250 else if(!pSession->pCurRoamProfile || !pSession->pCurRoamProfile->ChannelInfo.ChannelList ||
1251 pSession->pCurRoamProfile->ChannelInfo.ChannelList[0] == 0)
1252 {
1253 //try lostlink scan3
1254 status = csrScanRequestLostLink3(pMac, sessionId);
1255 }
1256 else
1257 {
1258 //we are done with lostlink
1259 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1260 {
1261 csrScanStartIdleScan(pMac);
1262 }
1263 }
1264
1265 return (status);
1266}
1267
1268
1269
1270eHalStatus csrScanHandleFailedLostlink3(tpAniSirGlobal pMac, tANI_U32 sessionId)
1271{
1272 eHalStatus status = eHAL_STATUS_SUCCESS;
1273
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001274 smsLog(pMac, LOGW, " Lostlink scan 3 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001275 if(eANI_BOOLEAN_TRUE == csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1276 {
1277 //we are done with lostlink
1278 csrScanStartIdleScan(pMac);
1279 }
1280
1281 return (status);
1282}
1283
1284
1285
1286
1287//Lostlink1 scan is to actively scan the last connected profile's SSID on all matched BSS channels.
1288//If no roam profile (it should not), it is like lostlinkscan3
1289eHalStatus csrScanRequestLostLink1( tpAniSirGlobal pMac, tANI_U32 sessionId )
1290{
1291 eHalStatus status = eHAL_STATUS_SUCCESS;
1292 tSmeCmd *pCommand = NULL;
1293 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1294 tCsrScanResultFilter *pScanFilter = NULL;
1295 tScanResultHandle hBSSList = NULL;
1296 tCsrScanResultInfo *pScanResult = NULL;
1297 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1298
Jeff Johnson32d95a32012-09-10 13:15:23 -07001299 if(!pSession)
1300 {
1301 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1302 return eHAL_STATUS_FAILURE;
1303 }
1304
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001305 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001306 do
1307 {
1308 pCommand = csrGetCommandBuffer(pMac);
1309 if(!pCommand)
1310 {
1311 status = eHAL_STATUS_RESOURCES;
1312 break;
1313 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301314 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001315 pCommand->command = eSmeCommandScan;
1316 pCommand->sessionId = (tANI_U8)sessionId;
1317 pCommand->u.scanCmd.reason = eCsrScanLostLink1;
1318 pCommand->u.scanCmd.callback = NULL;
1319 pCommand->u.scanCmd.pContext = NULL;
1320 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1321 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001322 pCommand->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1323 pCommand->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001324 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
1325 if(pSession->connectedProfile.SSID.length)
1326 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301327 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList = vos_mem_malloc(sizeof(tCsrSSIDInfo));
1328 if ( NULL == pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList )
1329 status = eHAL_STATUS_FAILURE;
1330 else
1331 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001332 if(!HAL_STATUS_SUCCESS(status))
1333 {
1334 break;
1335 }
1336 pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 1;
Kiet Lam64c1b492013-07-12 13:56:44 +05301337 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID,
1338 &pSession->connectedProfile.SSID, sizeof(tSirMacSSid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001339 }
1340 else
1341 {
1342 pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 0;
1343 }
1344 if(pSession->pCurRoamProfile)
1345 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301346 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1347 if ( NULL == pScanFilter )
1348 status = eHAL_STATUS_FAILURE;
1349 else
1350 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001351 if(!HAL_STATUS_SUCCESS(status))
1352 {
1353 break;
1354 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301355 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001356 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
1357 if(!HAL_STATUS_SUCCESS(status))
1358 {
1359 break;
1360 }
1361 //Don't change variable status here because whether we can get result or not, the command goes to PE.
1362 //The status is also used to indicate whether the command is queued. Not success meaning not queue
1363 if(HAL_STATUS_SUCCESS((csrScanGetResult(pMac, pScanFilter, &hBSSList))) && hBSSList)
1364 {
1365 tANI_U8 i, nChn = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05301366 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList =
1367 vos_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
1368 if ( NULL == pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
1369 status = eHAL_STATUS_FAILURE;
1370 else
1371 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001372 if(!HAL_STATUS_SUCCESS(status))
1373 {
1374 break;
1375 }
1376 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) &&
1377 nChn < WNI_CFG_VALID_CHANNEL_LIST_LEN)
1378 {
1379 for(i = 0; i < nChn; i++)
1380 {
1381 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1382 pScanResult->BssDescriptor.channelId)
1383 {
1384 break;
1385 }
1386 }
1387 if(i == nChn)
1388 {
1389 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pScanResult->BssDescriptor.channelId;
1390 }
1391 }
1392 //Include the last connected BSS' channel
1393 if(csrRoamIsChannelValid(pMac, pSession->connectedProfile.operationChannel))
1394 {
1395 for(i = 0; i < nChn; i++)
1396 {
1397 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1398 pSession->connectedProfile.operationChannel)
1399 {
1400 break;
1401 }
1402 }
1403 if(i == nChn)
1404 {
1405 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pSession->connectedProfile.operationChannel;
1406 }
1407 }
1408 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nChn;
1409 }
1410 else
1411 {
1412 if(csrRoamIsChannelValid(pMac, pSession->connectedProfile.operationChannel))
1413 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301414 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(1);
1415 if ( NULL == pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
1416 status = eHAL_STATUS_FAILURE;
1417 else
1418 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001419 //just try the last connected channel
1420 if(HAL_STATUS_SUCCESS(status))
1421 {
1422 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[0] = pSession->connectedProfile.operationChannel;
1423 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 1;
1424 }
1425 else
1426 {
1427 break;
1428 }
1429 }
1430 }
1431 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301432 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001433 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
1434 if( !HAL_STATUS_SUCCESS( status ) )
1435 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001436 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001437 break;
1438 }
1439 } while( 0 );
1440
1441 if(!HAL_STATUS_SUCCESS(status))
1442 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001443 smsLog(pMac, LOGW, " csrScanRequestLostLink1 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001444 if(pCommand)
1445 {
1446 csrReleaseCommandScan(pMac, pCommand);
1447 }
1448 status = csrScanHandleFailedLostlink1( pMac, sessionId );
1449 }
1450 if(pScanFilter)
1451 {
1452 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301453 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001454 }
1455 if(hBSSList)
1456 {
1457 csrScanResultPurge(pMac, hBSSList);
1458 }
1459
1460 return( status );
1461}
1462
1463
1464//Lostlink2 scan is to actively scan the all SSIDs of the last roaming profile's on all matched BSS channels.
1465//Since MAC doesn't support multiple SSID, we scan all SSIDs and filter them afterwards
1466eHalStatus csrScanRequestLostLink2( tpAniSirGlobal pMac, tANI_U32 sessionId )
1467{
1468 eHalStatus status = eHAL_STATUS_SUCCESS;
1469 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1470 tCsrScanResultFilter *pScanFilter = NULL;
1471 tScanResultHandle hBSSList = NULL;
1472 tCsrScanResultInfo *pScanResult = NULL;
1473 tSmeCmd *pCommand = NULL;
1474 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1475
Jeff Johnson32d95a32012-09-10 13:15:23 -07001476 if(!pSession)
1477 {
1478 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1479 return eHAL_STATUS_FAILURE;
1480 }
1481
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001482 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001483 do
1484 {
1485 pCommand = csrGetCommandBuffer(pMac);
1486 if(!pCommand)
1487 {
1488 status = eHAL_STATUS_RESOURCES;
1489 break;
1490 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301491 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001492 pCommand->command = eSmeCommandScan;
1493 pCommand->sessionId = (tANI_U8)sessionId;
1494 pCommand->u.scanCmd.reason = eCsrScanLostLink2;
1495 pCommand->u.scanCmd.callback = NULL;
1496 pCommand->u.scanCmd.pContext = NULL;
1497 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1498 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001499 pCommand->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1500 pCommand->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001501 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
1502 if(pSession->pCurRoamProfile)
1503 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301504 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1505 if ( NULL == pScanFilter )
1506 status = eHAL_STATUS_FAILURE;
1507 else
1508 status = eHAL_STATUS_SUCCESS;
1509 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001510 {
1511 break;
1512 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301513 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001514 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
1515 if(!HAL_STATUS_SUCCESS(status))
1516 {
1517 break;
1518 }
1519 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1520 if(!HAL_STATUS_SUCCESS(status))
1521 {
1522 break;
1523 }
1524 if(hBSSList)
1525 {
1526 tANI_U8 i, nChn = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05301527 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList =
1528 vos_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
1529 if ( NULL == pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
1530 status = eHAL_STATUS_FAILURE;
1531 else
1532 status = eHAL_STATUS_SUCCESS;
1533 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001534 {
1535 break;
1536 }
1537 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) &&
1538 nChn < WNI_CFG_VALID_CHANNEL_LIST_LEN)
1539 {
1540 for(i = 0; i < nChn; i++)
1541 {
1542 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1543 pScanResult->BssDescriptor.channelId)
1544 {
1545 break;
1546 }
1547 }
1548 if(i == nChn)
1549 {
1550 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pScanResult->BssDescriptor.channelId;
1551 }
1552 }
1553 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nChn;
1554 }
1555 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301556 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001557 //Put to the head in pending queue
1558 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_TRUE);
1559 if( !HAL_STATUS_SUCCESS( status ) )
1560 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001561 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001562 break;
1563 }
1564 } while( 0 );
1565
1566 if(!HAL_STATUS_SUCCESS(status))
1567 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001568 smsLog(pMac, LOGW, " csrScanRequestLostLink2 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001569 if(pCommand)
1570 {
1571 csrReleaseCommandScan(pMac, pCommand);
1572 }
1573 status = csrScanHandleFailedLostlink2( pMac, sessionId );
1574 }
1575 if(pScanFilter)
1576 {
1577 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301578 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001579 }
1580 if(hBSSList)
1581 {
1582 csrScanResultPurge(pMac, hBSSList);
1583 }
1584
1585 return( status );
1586}
1587
1588
1589//To actively scan all valid channels
1590eHalStatus csrScanRequestLostLink3( tpAniSirGlobal pMac, tANI_U32 sessionId )
1591{
1592 eHalStatus status = eHAL_STATUS_SUCCESS;
1593 tSmeCmd *pCommand;
1594 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1595
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001596 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001597 do
1598 {
1599 pCommand = csrGetCommandBuffer(pMac);
1600 if(!pCommand)
1601 {
1602 status = eHAL_STATUS_RESOURCES;
1603 break;
1604 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301605 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001606 pCommand->command = eSmeCommandScan;
1607 pCommand->sessionId = (tANI_U8)sessionId;
1608 pCommand->u.scanCmd.reason = eCsrScanLostLink3;
1609 pCommand->u.scanCmd.callback = NULL;
1610 pCommand->u.scanCmd.pContext = NULL;
1611 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1612 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001613 pCommand->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1614 pCommand->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001615 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Kiet Lam64c1b492013-07-12 13:56:44 +05301616 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001617 //Put to the head of pending queue
1618 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_TRUE);
1619 if( !HAL_STATUS_SUCCESS( status ) )
1620 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001621 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001622 break;
1623 }
1624 } while( 0 );
1625 if(!HAL_STATUS_SUCCESS(status))
1626 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001627 smsLog(pMac, LOGW, " csrScanRequestLostLink3 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001628 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1629 {
1630 csrScanStartIdleScan(pMac);
1631 }
1632 if(pCommand)
1633 {
1634 csrReleaseCommandScan(pMac, pCommand);
1635 }
1636 }
1637
1638 return( status );
1639}
1640
1641
1642eHalStatus csrScanHandleSearchForSSID(tpAniSirGlobal pMac, tSmeCmd *pCommand)
1643{
1644 eHalStatus status = eHAL_STATUS_FAILURE;
1645 tScanResultHandle hBSSList = CSR_INVALID_SCANRESULT_HANDLE;
1646 tCsrScanResultFilter *pScanFilter = NULL;
1647 tCsrRoamProfile *pProfile = pCommand->u.scanCmd.pToRoamProfile;
1648 tANI_U32 sessionId = pCommand->sessionId;
1649#ifdef FEATURE_WLAN_BTAMP_UT_RF
1650 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1651#endif
1652 do
1653 {
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001654#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
1655 //if this scan is for LFR
1656 if(pMac->roam.neighborRoamInfo.uOsRequestedHandoff)
1657 {
1658 //notify LFR state m/c
1659 if(eHAL_STATUS_SUCCESS != csrNeighborRoamSssidScanDone(pMac, eHAL_STATUS_SUCCESS))
1660 {
Mukul Sharma20aa6582014-08-07 21:36:12 +05301661 csrNeighborRoamStartLfrScan(pMac, REASON_OS_REQUESTED_ROAMING_NOW);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001662 }
1663 status = eHAL_STATUS_SUCCESS;
1664 break;
1665 }
1666#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001667 //If there is roam command waiting, ignore this roam because the newer roam command is the one to execute
1668 if(csrIsRoamCommandWaitingForSession(pMac, sessionId))
1669 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001670 smsLog(pMac, LOGW, FL(" aborts because roam command waiting"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001671 break;
1672 }
1673 if(pProfile == NULL)
1674 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301675 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1676 if ( NULL == pScanFilter )
1677 status = eHAL_STATUS_FAILURE;
1678 else
1679 status = eHAL_STATUS_SUCCESS;
1680 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001681 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301682 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001683 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1684 if(!HAL_STATUS_SUCCESS(status))
1685 break;
1686 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1687 if(!HAL_STATUS_SUCCESS(status))
1688 break;
1689 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList, eCsrHddIssued,
1690 pCommand->u.scanCmd.roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1691 if(!HAL_STATUS_SUCCESS(status))
1692 {
1693 break;
1694 }
1695 }while(0);
1696 if(!HAL_STATUS_SUCCESS(status))
1697 {
1698 if(CSR_INVALID_SCANRESULT_HANDLE != hBSSList)
1699 {
1700 csrScanResultPurge(pMac, hBSSList);
1701 }
1702 //We haven't done anything to this profile
1703 csrRoamCallCallback(pMac, sessionId, NULL, pCommand->u.scanCmd.roamId,
1704 eCSR_ROAM_ASSOCIATION_FAILURE, eCSR_ROAM_RESULT_FAILURE);
1705 //In case we have nothing else to do, restart idle scan
1706 if(csrIsConnStateDisconnected(pMac, sessionId) && !csrIsRoamCommandWaiting(pMac))
1707 {
1708 status = csrScanStartIdleScan(pMac);
1709 }
1710#ifdef FEATURE_WLAN_BTAMP_UT_RF
1711 //In case of WDS station, let it retry.
1712 if( CSR_IS_WDS_STA(pProfile) )
1713 {
1714 //Save the roma profile so we can retry
1715 csrFreeRoamProfile( pMac, sessionId );
Kiet Lam64c1b492013-07-12 13:56:44 +05301716 pSession->pCurRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1717 if ( NULL != pSession->pCurRoamProfile )
Jeff Johnson295189b2012-06-20 16:38:30 -07001718 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301719 vos_mem_set(pSession->pCurRoamProfilee, sizeof(tCsrRoamProfile), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001720 csrRoamCopyProfile(pMac, pSession->pCurRoamProfile, pProfile);
1721 }
1722 csrRoamStartJoinRetryTimer(pMac, sessionId, CSR_JOIN_RETRY_TIMEOUT_PERIOD);
1723 }
1724#endif
1725 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301726 if (pScanFilter)
Jeff Johnson295189b2012-06-20 16:38:30 -07001727 {
1728 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301729 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001730 }
1731
1732 return (status);
1733}
1734
1735
1736eHalStatus csrScanHandleSearchForSSIDFailure(tpAniSirGlobal pMac, tSmeCmd *pCommand)
1737{
1738 eHalStatus status = eHAL_STATUS_SUCCESS;
1739 tANI_U32 sessionId = pCommand->sessionId;
1740 tCsrRoamProfile *pProfile = pCommand->u.scanCmd.pToRoamProfile;
1741 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001742#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
1743 //if this scan is for LFR
1744 if(pMac->roam.neighborRoamInfo.uOsRequestedHandoff)
1745 {
1746 //notify LFR state m/c
1747 if(eHAL_STATUS_SUCCESS != csrNeighborRoamSssidScanDone(pMac, eHAL_STATUS_FAILURE))
1748 {
Mukul Sharma20aa6582014-08-07 21:36:12 +05301749 csrNeighborRoamStartLfrScan(pMac, REASON_OS_REQUESTED_ROAMING_NOW);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001750 }
1751 return eHAL_STATUS_SUCCESS;
1752 }
1753#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -07001754 if(!pSession)
1755 {
1756 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1757 return eHAL_STATUS_FAILURE;
1758 }
1759
Jeff Johnson295189b2012-06-20 16:38:30 -07001760#if defined(WLAN_DEBUG)
1761 if(pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs == 1)
1762 {
1763 char str[36];
Kiet Lam64c1b492013-07-12 13:56:44 +05301764 vos_mem_copy(str,
1765 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.ssId,
1766 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.length);
Jeff Johnson295189b2012-06-20 16:38:30 -07001767 str[pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.length] = 0;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001768 smsLog(pMac, LOGW, FL(" SSID = %s"), str);
Jeff Johnson295189b2012-06-20 16:38:30 -07001769 }
1770#endif
1771 //Check whether it is for start ibss. No need to do anything if it is a JOIN request
1772 if(pProfile && CSR_IS_START_IBSS(pProfile))
1773 {
1774 status = csrRoamIssueConnect(pMac, sessionId, pProfile, NULL, eCsrHddIssued,
1775 pCommand->u.scanCmd.roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1776 if(!HAL_STATUS_SUCCESS(status))
1777 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001778 smsLog(pMac, LOGE, FL("failed to issue startIBSS command with status = 0x%08X"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001779 csrRoamCallCallback(pMac, sessionId, NULL, pCommand->u.scanCmd.roamId, eCSR_ROAM_FAILED, eCSR_ROAM_RESULT_FAILURE);
1780 }
1781 }
1782 else
1783 {
1784 eCsrRoamResult roamResult = eCSR_ROAM_RESULT_FAILURE;
1785
1786 if(csrIsConnStateDisconnected(pMac, sessionId) &&
1787 !csrIsRoamCommandWaitingForSession(pMac, sessionId))
1788 {
1789 status = csrScanStartIdleScan(pMac);
1790 }
1791 if((NULL == pProfile) || !csrIsBssTypeIBSS(pProfile->BSSType))
1792 {
1793 //Only indicate assoc_completion if we indicate assoc_start.
1794 if(pSession->bRefAssocStartCnt > 0)
1795 {
1796 tCsrRoamInfo *pRoamInfo = NULL, roamInfo;
Kiet Lam64c1b492013-07-12 13:56:44 +05301797 vos_mem_set(&roamInfo, sizeof(tCsrRoamInfo), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001798 pRoamInfo = &roamInfo;
1799 if(pCommand->u.roamCmd.pRoamBssEntry)
1800 {
1801 tCsrScanResult *pScanResult =
1802 GET_BASE_ADDR(pCommand->u.roamCmd.pRoamBssEntry,
1803 tCsrScanResult, Link);
1804 roamInfo.pBssDesc = &pScanResult->Result.BssDescriptor;
1805 }
1806 roamInfo.statusCode = pSession->joinFailStatusCode.statusCode;
1807 roamInfo.reasonCode = pSession->joinFailStatusCode.reasonCode;
1808 pSession->bRefAssocStartCnt--;
1809 csrRoamCallCallback(pMac, sessionId, pRoamInfo,
1810 pCommand->u.scanCmd.roamId,
1811 eCSR_ROAM_ASSOCIATION_COMPLETION,
1812 eCSR_ROAM_RESULT_FAILURE);
1813 }
Madan Mohan Koyyalamudiee255f12012-09-28 15:41:19 -07001814 else
1815 {
1816 csrRoamCallCallback(pMac, sessionId, NULL,
1817 pCommand->u.scanCmd.roamId,
1818 eCSR_ROAM_ASSOCIATION_FAILURE,
1819 eCSR_ROAM_RESULT_FAILURE);
1820 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001821#ifdef FEATURE_WLAN_BTAMP_UT_RF
1822 //In case of WDS station, let it retry.
1823 if( CSR_IS_WDS_STA(pProfile) )
1824 {
1825 //Save the roma profile so we can retry
1826 csrFreeRoamProfile( pMac, sessionId );
Kiet Lam64c1b492013-07-12 13:56:44 +05301827 pSession->pCurRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1828 if ( NULL != pSession->pCurRoamProfile )
Jeff Johnson295189b2012-06-20 16:38:30 -07001829 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301830 vos_mem_set(pSession->pCurRoamProfile, sizeof(tCsrRoamProfile), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001831 csrRoamCopyProfile(pMac, pSession->pCurRoamProfile, pProfile);
1832 }
1833 csrRoamStartJoinRetryTimer(pMac, sessionId, CSR_JOIN_RETRY_TIMEOUT_PERIOD);
1834 }
1835#endif
1836 }
1837 else
1838 {
1839 roamResult = eCSR_ROAM_RESULT_IBSS_START_FAILED;
1840 }
1841 csrRoamCompletion(pMac, sessionId, NULL, pCommand, roamResult, eANI_BOOLEAN_FALSE);
1842 }
1843
1844 return (status);
1845}
1846
1847
1848//After scan for cap changes, issue a roaming command to either reconnect to the AP or pick another one to connect
1849eHalStatus csrScanHandleCapChangeScanComplete(tpAniSirGlobal pMac, tANI_U32 sessionId)
1850{
1851 eHalStatus status = eHAL_STATUS_FAILURE;
1852 tScanResultHandle hBSSList = NULL;
1853 tCsrScanResultFilter *pScanFilter = NULL;
1854 tANI_U32 roamId = 0;
1855 tCsrRoamProfile *pProfile = NULL;
1856 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1857
1858 do
1859 {
1860 //Here is the profile we need to connect to
Kiet Lam64c1b492013-07-12 13:56:44 +05301861 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1862 if ( NULL == pScanFilter )
1863 status = eHAL_STATUS_FAILURE;
1864 else
1865 status = eHAL_STATUS_SUCCESS;
1866 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001867 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301868 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
1869 if (NULL == pSession) break;
1870 if (NULL == pSession->pCurRoamProfile)
Jeff Johnson295189b2012-06-20 16:38:30 -07001871 {
1872 pScanFilter->EncryptionType.numEntries = 1;
1873 pScanFilter->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_NONE;
1874 }
1875 else
1876 {
1877 //We have to make a copy of pCurRoamProfile because it will be free inside csrRoamIssueConnect
Kiet Lam64c1b492013-07-12 13:56:44 +05301878 pProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1879 if ( NULL == pProfile )
1880 status = eHAL_STATUS_FAILURE;
1881 else
1882 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001883 if(!HAL_STATUS_SUCCESS(status))
1884 break;
1885 status = csrRoamCopyProfile(pMac, pProfile, pSession->pCurRoamProfile);
1886 if(!HAL_STATUS_SUCCESS(status))
1887 break;
1888 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1889 }//We have a profile
1890 roamId = GET_NEXT_ROAM_ID(&pMac->roam);
1891 if(HAL_STATUS_SUCCESS(status))
1892 {
1893 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1894 if(HAL_STATUS_SUCCESS(status))
1895 {
1896 //we want to put the last connected BSS to the very beginning, if possible
1897 csrMoveBssToHeadFromBSSID(pMac, &pSession->connectedProfile.bssid, hBSSList);
1898 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList,
1899 eCsrCapsChange, 0, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1900 if(!HAL_STATUS_SUCCESS(status))
1901 {
1902 csrScanResultPurge(pMac, hBSSList);
1903 }
1904 }//Have scan result
1905 else
1906 {
Arif Hussaina7c8e412013-11-20 11:06:42 -08001907 smsLog(pMac, LOGW, FL("cannot find matching BSS of "
1908 MAC_ADDRESS_STR),
1909 MAC_ADDR_ARRAY(pSession->connectedProfile.bssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001910 //Disconnect
1911 csrRoamDisconnectInternal(pMac, sessionId, eCSR_DISCONNECT_REASON_UNSPECIFIED);
1912 }
1913 }
1914 }while(0);
1915 if(pScanFilter)
1916 {
1917 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301918 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001919 }
1920 if(NULL != pProfile)
1921 {
1922 csrReleaseProfile(pMac, pProfile);
Kiet Lam64c1b492013-07-12 13:56:44 +05301923 vos_mem_free(pProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07001924 }
1925
1926 return (status);
1927}
1928
1929
1930
1931eHalStatus csrScanResultPurge(tpAniSirGlobal pMac, tScanResultHandle hScanList)
1932{
1933 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
1934 tScanResultList *pScanList = (tScanResultList *)hScanList;
1935
1936 if(pScanList)
1937 {
1938 status = csrLLScanPurgeResult(pMac, &pScanList->List);
1939 csrLLClose(&pScanList->List);
Kiet Lam64c1b492013-07-12 13:56:44 +05301940 vos_mem_free(pScanList);
Jeff Johnson295189b2012-06-20 16:38:30 -07001941 }
1942 return (status);
1943}
1944
1945
1946static tANI_U32 csrGetBssPreferValue(tpAniSirGlobal pMac, int rssi)
1947{
1948 tANI_U32 ret = 0;
1949 int i = CSR_NUM_RSSI_CAT - 1;
1950
1951 while(i >= 0)
1952 {
1953 if(rssi >= pMac->roam.configParam.RSSICat[i])
1954 {
1955 ret = pMac->roam.configParam.BssPreferValue[i];
1956 break;
1957 }
1958 i--;
1959 };
1960
1961 return (ret);
1962}
1963
1964
1965//Return a CapValue base on the capabilities of a BSS
1966static tANI_U32 csrGetBssCapValue(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes)
1967{
1968 tANI_U32 ret = CSR_BSS_CAP_VALUE_NONE;
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08001969#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_ESE) || defined(FEATURE_WLAN_LFR)
Madan Mohan Koyyalamudid5026072012-11-30 14:56:21 -08001970 if(CSR_IS_ROAM_PREFER_5GHZ(pMac))
1971 {
1972 if((pBssDesc) && CSR_IS_CHANNEL_5GHZ(pBssDesc->channelId))
1973 {
1974 ret += CSR_BSS_CAP_VALUE_5GHZ;
1975 }
1976 }
1977#endif
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07001978 /* if strict select 5GHz is non-zero then ignore the capability checking */
1979 if (pIes && !CSR_IS_SELECT_5GHZ_MARGIN(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -07001980 {
1981 //We only care about 11N capability
1982 if(pIes->HTCaps.present)
1983 {
1984 ret += CSR_BSS_CAP_VALUE_HT;
1985 }
1986 if(CSR_IS_QOS_BSS(pIes))
1987 {
1988 ret += CSR_BSS_CAP_VALUE_WMM;
1989 //Give advantage to UAPSD
1990 if(CSR_IS_UAPSD_BSS(pIes))
1991 {
1992 ret += CSR_BSS_CAP_VALUE_UAPSD;
1993 }
1994 }
1995 }
1996
1997 return (ret);
1998}
1999
2000
2001//To check whther pBss1 is better than pBss2
2002static tANI_BOOLEAN csrIsBetterBss(tCsrScanResult *pBss1, tCsrScanResult *pBss2)
2003{
2004 tANI_BOOLEAN ret;
2005
2006 if(CSR_IS_BETTER_PREFER_VALUE(pBss1->preferValue, pBss2->preferValue))
2007 {
2008 ret = eANI_BOOLEAN_TRUE;
2009 }
2010 else if(CSR_IS_EQUAL_PREFER_VALUE(pBss1->preferValue, pBss2->preferValue))
2011 {
2012 if(CSR_IS_BETTER_CAP_VALUE(pBss1->capValue, pBss2->capValue))
2013 {
2014 ret = eANI_BOOLEAN_TRUE;
2015 }
2016 else
2017 {
2018 ret = eANI_BOOLEAN_FALSE;
2019 }
2020 }
2021 else
2022 {
2023 ret = eANI_BOOLEAN_FALSE;
2024 }
2025
2026 return (ret);
2027}
2028
2029
Srikant Kuppa866893f2012-12-27 17:28:14 -08002030#ifdef FEATURE_WLAN_LFR
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002031//Add the channel to the occupiedChannels array
2032static void csrScanAddToOccupiedChannels(
Srikant Kuppa866893f2012-12-27 17:28:14 -08002033 tpAniSirGlobal pMac,
2034 tCsrScanResult *pResult,
2035 tCsrChannel *pOccupiedChannels,
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002036 tDot11fBeaconIEs *pIes)
2037{
2038 eHalStatus status;
2039 tANI_U8 channel;
2040 tANI_U8 numOccupiedChannels = pOccupiedChannels->numChannels;
2041 tANI_U8 *pOccupiedChannelList = pOccupiedChannels->channelList;
2042
2043 channel = pResult->Result.BssDescriptor.channelId;
2044
2045 if (!csrIsChannelPresentInList(pOccupiedChannelList, numOccupiedChannels, channel)
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08002046 && csrNeighborRoamConnectedProfileMatch(pMac, pResult, pIes))
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002047 {
Srikant Kuppa866893f2012-12-27 17:28:14 -08002048 status = csrAddToChannelListFront(pOccupiedChannelList, numOccupiedChannels, channel);
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002049 if(HAL_STATUS_SUCCESS(status))
Srikant Kuppa866893f2012-12-27 17:28:14 -08002050 {
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002051 pOccupiedChannels->numChannels++;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002052 smsLog(pMac, LOG2, FL("%s: added channel %d to the list (count=%d)"),
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08002053 __func__, channel, pOccupiedChannels->numChannels);
Srikant Kuppa866893f2012-12-27 17:28:14 -08002054 if (pOccupiedChannels->numChannels > CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN)
2055 pOccupiedChannels->numChannels = CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN;
2056 }
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002057 }
2058}
Mukul Sharma9e4e0f92015-02-13 18:45:20 +05302059
2060void csrAddChannelToOccupiedChannelList(tpAniSirGlobal pMac,
2061 tANI_U8 channel)
2062{
2063 eHalStatus status;
2064 tCsrChannel *pOccupiedChannels = &pMac->scan.occupiedChannels;
2065 tANI_U8 numOccupiedChannels = pOccupiedChannels->numChannels;
2066 tANI_U8 *pOccupiedChannelList = pOccupiedChannels->channelList;
2067 if (!csrIsChannelPresentInList(pOccupiedChannelList,
2068 numOccupiedChannels, channel))
2069 {
2070 status = csrAddToChannelListFront(pOccupiedChannelList,
2071 numOccupiedChannels, channel);
2072 if(HAL_STATUS_SUCCESS(status))
2073 {
2074 pOccupiedChannels->numChannels++;
2075 smsLog(pMac, LOG2, FL("added channel %d to the list (count=%d)"),
2076 channel, pOccupiedChannels->numChannels);
2077 if (pOccupiedChannels->numChannels >
2078 CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN)
2079 {
2080 pOccupiedChannels->numChannels =
2081 CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN;
2082 smsLog(pMac, LOG2,
2083 FL("trim no of Channels for Occ channel list"));
2084 }
2085 }
2086 }
2087}
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002088#endif
2089
Jeff Johnson295189b2012-06-20 16:38:30 -07002090//Put the BSS into the scan result list
2091//pIes can not be NULL
2092static void csrScanAddResult(tpAniSirGlobal pMac, tCsrScanResult *pResult, tDot11fBeaconIEs *pIes)
2093{
Srinivas28b5b4e2012-12-12 13:07:53 -08002094#ifdef FEATURE_WLAN_LFR
2095 tpCsrNeighborRoamControlInfo pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
2096#endif
2097
Jeff Johnson295189b2012-06-20 16:38:30 -07002098 pResult->preferValue = csrGetBssPreferValue(pMac, (int)pResult->Result.BssDescriptor.rssi);
2099 pResult->capValue = csrGetBssCapValue(pMac, &pResult->Result.BssDescriptor, pIes);
2100 csrLLInsertTail( &pMac->scan.scanResultList, &pResult->Link, LL_ACCESS_LOCK );
Srikant Kuppa866893f2012-12-27 17:28:14 -08002101#ifdef FEATURE_WLAN_LFR
Srinivas28b5b4e2012-12-12 13:07:53 -08002102 if(0 == pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels)
2103 {
2104 /* Build the occupied channel list, only if "gNeighborScanChannelList" is
2105 NOT set in the cfg.ini file */
2106 csrScanAddToOccupiedChannels(pMac, pResult, &pMac->scan.occupiedChannels, pIes);
2107 }
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002108#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002109}
2110
2111
2112eHalStatus csrScanGetResult(tpAniSirGlobal pMac, tCsrScanResultFilter *pFilter, tScanResultHandle *phResult)
2113{
2114 eHalStatus status;
2115 tScanResultList *pRetList;
2116 tCsrScanResult *pResult, *pBssDesc;
2117 tANI_U32 count = 0;
2118 tListElem *pEntry;
2119 tANI_U32 bssLen, allocLen;
2120 eCsrEncryptionType uc = eCSR_ENCRYPT_TYPE_NONE, mc = eCSR_ENCRYPT_TYPE_NONE;
2121 eCsrAuthType auth = eCSR_AUTH_TYPE_OPEN_SYSTEM;
2122 tDot11fBeaconIEs *pIes, *pNewIes;
2123 tANI_BOOLEAN fMatch;
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002124 tANI_U16 i = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07002125
2126 if(phResult)
2127 {
2128 *phResult = CSR_INVALID_SCANRESULT_HANDLE;
2129 }
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002130
2131 if (pMac->roam.configParam.nSelect5GHzMargin)
2132 {
2133 pMac->scan.inScanResultBestAPRssi = -128;
2134 csrLLLock(&pMac->scan.scanResultList);
2135
2136 /* Find out the best AP Rssi going thru the scan results */
2137 pEntry = csrLLPeekHead(&pMac->scan.scanResultList, LL_ACCESS_NOLOCK);
2138 while ( NULL != pEntry)
2139 {
2140 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002141 fMatch = FALSE;
2142
2143 if (pFilter)
2144 for(i = 0; i < pFilter->SSIDs.numOfSSIDs; i++)
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002145 {
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002146 fMatch = csrIsSsidMatch( pMac, pFilter->SSIDs.SSIDList[i].SSID.ssId, pFilter->SSIDs.SSIDList[i].SSID.length,
2147 pBssDesc->Result.ssId.ssId,
2148 pBssDesc->Result.ssId.length, eANI_BOOLEAN_TRUE );
2149 if (fMatch)
2150 {
2151 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
2152
2153 //At this time, pBssDescription->Result.pvIes may be NULL
2154 if( !pIes && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
2155 &pBssDesc->Result.BssDescriptor, &pIes))) )
2156 {
2157 continue;
2158 }
2159
2160 smsLog(pMac, LOG1, FL("SSID Matched"));
Leela Venkata Kiran Kumar Reddy Chiralae208a832014-04-27 22:34:25 -07002161
Leela Venkata Kiran Kumar Reddy Chiralaf257bef2014-04-11 18:48:12 -07002162 if ( pFilter->bOSENAssociation )
2163 {
2164 fMatch = TRUE;
2165 }
Leela Venkata Kiran Kumar Reddy Chiralae208a832014-04-27 22:34:25 -07002166 else
2167 {
Abhishek Singh658d4de2014-06-26 10:53:15 +05302168#ifdef WLAN_FEATURE_11W
Abhishek Singh3b56d3a2014-06-25 12:37:39 +05302169 fMatch = csrIsSecurityMatch(pMac, &pFilter->authType,
2170 &pFilter->EncryptionType,
2171 &pFilter->mcEncryptionType,
2172 &pFilter->MFPEnabled,
2173 &pFilter->MFPRequired,
2174 &pFilter->MFPCapable,
2175 &pBssDesc->Result.BssDescriptor,
2176 pIes, NULL, NULL, NULL );
Abhishek Singh658d4de2014-06-26 10:53:15 +05302177#else
2178 fMatch = csrIsSecurityMatch(pMac, &pFilter->authType,
2179 &pFilter->EncryptionType,
2180 &pFilter->mcEncryptionType,
2181 NULL, NULL, NULL,
2182 &pBssDesc->Result.BssDescriptor,
2183 pIes, NULL, NULL, NULL );
2184#endif
Leela Venkata Kiran Kumar Reddy Chiralae208a832014-04-27 22:34:25 -07002185 }
2186 if ((pBssDesc->Result.pvIes == NULL) && pIes)
2187 vos_mem_free(pIes);
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002188
2189 if (fMatch)
2190 smsLog(pMac, LOG1, FL(" Security Matched"));
2191 }
2192 }
2193
2194 if (fMatch && (pBssDesc->Result.BssDescriptor.rssi > pMac->scan.inScanResultBestAPRssi))
2195 {
2196 smsLog(pMac, LOG1, FL("Best AP Rssi changed from %d to %d"),
2197 pMac->scan.inScanResultBestAPRssi,
2198 pBssDesc->Result.BssDescriptor.rssi);
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002199 pMac->scan.inScanResultBestAPRssi = pBssDesc->Result.BssDescriptor.rssi;
2200 }
2201 pEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
2202 }
2203
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002204 if ( -128 != pMac->scan.inScanResultBestAPRssi)
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002205 {
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002206 smsLog(pMac, LOG1, FL("Best AP Rssi is %d"), pMac->scan.inScanResultBestAPRssi);
2207 /* Modify Rssi category based on best AP Rssi */
2208 csrAssignRssiForCategory(pMac, pMac->scan.inScanResultBestAPRssi, pMac->roam.configParam.bCatRssiOffset);
2209 pEntry = csrLLPeekHead(&pMac->scan.scanResultList, LL_ACCESS_NOLOCK);
2210 while ( NULL != pEntry)
2211 {
2212 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002213
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002214 /* re-assign preference value based on modified rssi bucket */
2215 pBssDesc->preferValue = csrGetBssPreferValue(pMac, (int)pBssDesc->Result.BssDescriptor.rssi);
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002216
Arif Hussaina7c8e412013-11-20 11:06:42 -08002217 smsLog(pMac, LOG2, FL("BSSID("MAC_ADDRESS_STR
Jeff Johnson123ed002013-11-22 17:39:55 -08002218 ") Rssi(%d) Chnl(%d) PrefVal(%u) SSID=%.*s"),
Arif Hussaina7c8e412013-11-20 11:06:42 -08002219 MAC_ADDR_ARRAY(pBssDesc->Result.BssDescriptor.bssId),
2220 pBssDesc->Result.BssDescriptor.rssi,
2221 pBssDesc->Result.BssDescriptor.channelId,
2222 pBssDesc->preferValue,
2223 pBssDesc->Result.ssId.length, pBssDesc->Result.ssId.ssId);
Srinivas Girigowda8e7e1052013-11-13 18:53:14 -08002224
2225 pEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
2226 }
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002227 }
2228
2229 csrLLUnlock(&pMac->scan.scanResultList);
2230 }
2231
Kiet Lam64c1b492013-07-12 13:56:44 +05302232 pRetList = vos_mem_malloc(sizeof(tScanResultList));
2233 if ( NULL == pRetList )
2234 status = eHAL_STATUS_FAILURE;
2235 else
2236 status = eHAL_STATUS_SUCCESS;
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002237 if(HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07002238 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302239 vos_mem_set(pRetList, sizeof(tScanResultList), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002240 csrLLOpen(pMac->hHdd, &pRetList->List);
2241 pRetList->pCurEntry = NULL;
2242
2243 csrLLLock(&pMac->scan.scanResultList);
2244 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
2245 while( pEntry )
2246 {
2247 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2248 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
2249 //if pBssDesc->Result.pvIes is NULL, we need to free any memory allocated by csrMatchBSS
2250 //for any error condition, otherwiase, it will be freed later.
2251 //reset
2252 fMatch = eANI_BOOLEAN_FALSE;
2253 pNewIes = NULL;
2254
2255 if(pFilter)
2256 {
2257 fMatch = csrMatchBSS(pMac, &pBssDesc->Result.BssDescriptor, pFilter, &auth, &uc, &mc, &pIes);
2258 if( NULL != pIes )
2259 {
2260 //Only save it when matching
2261 if(fMatch)
2262 {
2263 if( !pBssDesc->Result.pvIes )
2264 {
2265 //csrMatchBSS allocates the memory. Simply pass it and it is freed later
2266 pNewIes = pIes;
2267 }
2268 else
2269 {
2270 //The pIes is allocated by someone else. make a copy
2271 //Only to save parsed IEs if caller provides a filter. Most likely the caller
2272 //is using to for association, hence save the parsed IEs
Kiet Lam64c1b492013-07-12 13:56:44 +05302273 pNewIes = vos_mem_malloc(sizeof(tDot11fBeaconIEs));
2274 if ( NULL == pNewIes )
2275 status = eHAL_STATUS_FAILURE;
2276 else
2277 status = eHAL_STATUS_SUCCESS;
2278 if ( HAL_STATUS_SUCCESS( status ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07002279 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302280 vos_mem_copy(pNewIes, pIes, sizeof( tDot11fBeaconIEs ));
Jeff Johnson295189b2012-06-20 16:38:30 -07002281 }
2282 else
2283 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002284 smsLog(pMac, LOGE, FL(" fail to allocate memory for IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002285 //Need to free memory allocated by csrMatchBSS
2286 if( !pBssDesc->Result.pvIes )
2287 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302288 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07002289 }
2290 break;
2291 }
2292 }
2293 }//fMatch
2294 else if( !pBssDesc->Result.pvIes )
2295 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302296 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07002297 }
2298 }
2299 }
2300 if(NULL == pFilter || fMatch)
2301 {
2302 bssLen = pBssDesc->Result.BssDescriptor.length + sizeof(pBssDesc->Result.BssDescriptor.length);
2303 allocLen = sizeof( tCsrScanResult ) + bssLen;
Kiet Lam64c1b492013-07-12 13:56:44 +05302304 pResult = vos_mem_malloc(allocLen);
2305 if ( NULL == pResult )
2306 status = eHAL_STATUS_FAILURE;
2307 else
2308 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07002309 if(!HAL_STATUS_SUCCESS(status))
2310 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002311 smsLog(pMac, LOGE, FL(" fail to allocate memory for scan result, len=%d"), allocLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07002312 if(pNewIes)
2313 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302314 vos_mem_free(pNewIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07002315 }
2316 break;
2317 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302318 vos_mem_set(pResult, allocLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002319 pResult->capValue = pBssDesc->capValue;
2320 pResult->preferValue = pBssDesc->preferValue;
2321 pResult->ucEncryptionType = uc;
2322 pResult->mcEncryptionType = mc;
2323 pResult->authType = auth;
2324 pResult->Result.ssId = pBssDesc->Result.ssId;
2325 pResult->Result.timer = 0;
2326 //save the pIes for later use
2327 pResult->Result.pvIes = pNewIes;
2328 //save bss description
Kiet Lam64c1b492013-07-12 13:56:44 +05302329 vos_mem_copy(&pResult->Result.BssDescriptor,
2330 &pBssDesc->Result.BssDescriptor, bssLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07002331 //No need to lock pRetList because it is locally allocated and no outside can access it at this time
2332 if(csrLLIsListEmpty(&pRetList->List, LL_ACCESS_NOLOCK))
2333 {
2334 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_NOLOCK);
2335 }
2336 else
2337 {
2338 //To sort the list
2339 tListElem *pTmpEntry;
2340 tCsrScanResult *pTmpResult;
2341
2342 pTmpEntry = csrLLPeekHead(&pRetList->List, LL_ACCESS_NOLOCK);
2343 while(pTmpEntry)
2344 {
2345 pTmpResult = GET_BASE_ADDR( pTmpEntry, tCsrScanResult, Link );
2346 if(csrIsBetterBss(pResult, pTmpResult))
2347 {
2348 csrLLInsertEntry(&pRetList->List, pTmpEntry, &pResult->Link, LL_ACCESS_NOLOCK);
2349 //To indicate we are done
2350 pResult = NULL;
2351 break;
2352 }
2353 pTmpEntry = csrLLNext(&pRetList->List, pTmpEntry, LL_ACCESS_NOLOCK);
2354 }
2355 if(pResult != NULL)
2356 {
2357 //This one is not better than any one
2358 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_NOLOCK);
2359 }
2360 }
2361 count++;
2362 }
2363 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK );
2364 }//while
2365 csrLLUnlock(&pMac->scan.scanResultList);
2366
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002367 smsLog(pMac, LOG2, FL("return %d BSS"), csrLLCount(&pRetList->List));
Jeff Johnson295189b2012-06-20 16:38:30 -07002368
2369 if( !HAL_STATUS_SUCCESS(status) || (phResult == NULL) )
2370 {
2371 //Fail or No one wants the result.
2372 csrScanResultPurge(pMac, (tScanResultHandle)pRetList);
2373 }
2374 else
2375 {
2376 if(0 == count)
2377 {
2378 //We are here meaning the there is no match
2379 csrLLClose(&pRetList->List);
Kiet Lam64c1b492013-07-12 13:56:44 +05302380 vos_mem_free(pRetList);
Jeff Johnson295189b2012-06-20 16:38:30 -07002381 status = eHAL_STATUS_E_NULL_VALUE;
2382 }
2383 else if(phResult)
2384 {
2385 *phResult = pRetList;
2386 }
2387 }
2388 }//Allocated pRetList
2389
2390 return (status);
2391}
2392
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002393/*
2394 * NOTE: This routine is being added to make
2395 * sure that scan results are not being flushed
2396 * while roaming. If the scan results are flushed,
2397 * we are unable to recover from
2398 * csrRoamRoamingStateDisassocRspProcessor.
2399 * If it is needed to remove this routine,
2400 * first ensure that we recover gracefully from
2401 * csrRoamRoamingStateDisassocRspProcessor if
2402 * csrScanGetResult returns with a failure because
2403 * of not being able to find the roaming BSS.
2404 */
2405tANI_U8 csrScanFlushDenied(tpAniSirGlobal pMac)
2406{
2407 switch(pMac->roam.neighborRoamInfo.neighborRoamState) {
2408 case eCSR_NEIGHBOR_ROAM_STATE_REPORT_SCAN:
2409 case eCSR_NEIGHBOR_ROAM_STATE_PREAUTHENTICATING:
2410 case eCSR_NEIGHBOR_ROAM_STATE_PREAUTH_DONE:
2411 case eCSR_NEIGHBOR_ROAM_STATE_REASSOCIATING:
2412 return (pMac->roam.neighborRoamInfo.neighborRoamState);
2413 default:
2414 return 0;
2415 }
2416}
2417
Jeff Johnson295189b2012-06-20 16:38:30 -07002418eHalStatus csrScanFlushResult(tpAniSirGlobal pMac)
2419{
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002420 tANI_U8 isFlushDenied = csrScanFlushDenied(pMac);
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302421 eHalStatus status = eHAL_STATUS_SUCCESS;
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002422 if (isFlushDenied) {
2423 smsLog(pMac, LOGW, "%s: scan flush denied in roam state %d",
2424 __func__, isFlushDenied);
2425 return eHAL_STATUS_FAILURE;
2426 }
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302427 csrLLScanPurgeResult( pMac, &pMac->scan.tempScanResults );
2428 csrLLScanPurgeResult( pMac, &pMac->scan.scanResultList );
2429 return( status );
Jeff Johnson295189b2012-06-20 16:38:30 -07002430}
2431
Mukul Sharma20aa6582014-08-07 21:36:12 +05302432eHalStatus csrScanFlushSelectiveResultForBand(tpAniSirGlobal pMac, v_BOOL_t flushP2P, tSirRFBand band)
2433{
2434 eHalStatus status = eHAL_STATUS_SUCCESS;
2435 tListElem *pEntry,*pFreeElem;
2436 tCsrScanResult *pBssDesc;
2437 tDblLinkList *pList = &pMac->scan.scanResultList;
2438
2439 csrLLLock(pList);
2440
2441 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK );
2442 while( pEntry != NULL)
2443 {
2444 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2445 if( (flushP2P == vos_mem_compare( pBssDesc->Result.ssId.ssId,
2446 "DIRECT-", 7)) &&
2447 (GetRFBand(pBssDesc->Result.BssDescriptor.channelId) == band)
2448 )
2449 {
2450 pFreeElem = pEntry;
2451 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2452 csrLLRemoveEntry(pList, pFreeElem, LL_ACCESS_NOLOCK);
2453 csrFreeScanResultEntry( pMac, pBssDesc );
2454 continue;
2455 }
2456 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2457 }
2458
2459 csrLLUnlock(pList);
2460
2461 return (status);
2462}
2463
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302464eHalStatus csrScanFlushSelectiveResult(tpAniSirGlobal pMac, v_BOOL_t flushP2P)
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002465{
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302466 eHalStatus status = eHAL_STATUS_SUCCESS;
2467 tListElem *pEntry,*pFreeElem;
2468 tCsrScanResult *pBssDesc;
2469 tDblLinkList *pList = &pMac->scan.scanResultList;
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002470
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302471 csrLLLock(pList);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002472
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302473 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK );
2474 while( pEntry != NULL)
2475 {
2476 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2477 if( flushP2P == vos_mem_compare( pBssDesc->Result.ssId.ssId,
2478 "DIRECT-", 7) )
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002479 {
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302480 pFreeElem = pEntry;
2481 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2482 csrLLRemoveEntry(pList, pFreeElem, LL_ACCESS_NOLOCK);
2483 csrFreeScanResultEntry( pMac, pBssDesc );
2484 continue;
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002485 }
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302486 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2487 }
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002488
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302489 csrLLUnlock(pList);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002490
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302491 return (status);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002492}
2493
Jeff Johnson295189b2012-06-20 16:38:30 -07002494/**
2495 * csrCheck11dChannel
2496 *
2497 *FUNCTION:
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302498 * This function is called from csrScanFilterResults function and
Jeff Johnson295189b2012-06-20 16:38:30 -07002499 * compare channel number with given channel list.
2500 *
2501 *LOGIC:
2502 * Check Scan result channel number with CFG channel list
2503 *
2504 *ASSUMPTIONS:
2505 *
2506 *
2507 *NOTE:
2508 *
2509 * @param channelId channel number
2510 * @param pChannelList Pointer to channel list
2511 * @param numChannels Number of channel in channel list
2512 *
2513 * @return Status
2514 */
2515
2516eHalStatus csrCheck11dChannel(tANI_U8 channelId, tANI_U8 *pChannelList, tANI_U32 numChannels)
2517{
2518 eHalStatus status = eHAL_STATUS_FAILURE;
2519 tANI_U8 i = 0;
2520
2521 for (i = 0; i < numChannels; i++)
2522 {
2523 if(pChannelList[ i ] == channelId)
2524 {
2525 status = eHAL_STATUS_SUCCESS;
2526 break;
2527 }
2528 }
2529 return status;
2530}
2531
2532/**
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302533 * csrScanFilterResults
Jeff Johnson295189b2012-06-20 16:38:30 -07002534 *
2535 *FUNCTION:
2536 * This function is called from csrApplyCountryInformation function and
2537 * filter scan result based on valid channel list number.
2538 *
2539 *LOGIC:
2540 * Get scan result from scan list and Check Scan result channel number
2541 * with 11d channel list if channel number is found in 11d channel list
2542 * then do not remove scan result entry from scan list
2543 *
2544 *ASSUMPTIONS:
2545 *
2546 *
2547 *NOTE:
2548 *
2549 * @param pMac Pointer to Global MAC structure
2550 *
2551 * @return Status
2552 */
2553
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302554eHalStatus csrScanFilterResults(tpAniSirGlobal pMac)
Jeff Johnson295189b2012-06-20 16:38:30 -07002555{
2556 eHalStatus status = eHAL_STATUS_SUCCESS;
2557 tListElem *pEntry,*pTempEntry;
2558 tCsrScanResult *pBssDesc;
2559 tANI_U32 len = sizeof(pMac->roam.validChannelList);
2560
2561 /* Get valid channels list from CFG */
2562 if (!HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac,
2563 pMac->roam.validChannelList, &len)))
2564 {
Agarwal Ashishe3cca2a2013-07-21 03:01:48 +05302565 smsLog( pMac, LOGE, "Failed to get Channel list from CFG");
Jeff Johnson295189b2012-06-20 16:38:30 -07002566 }
2567
2568 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
2569 while( pEntry )
2570 {
2571 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302572 pTempEntry = csrLLNext( &pMac->scan.scanResultList, pEntry,
Jeff Johnson295189b2012-06-20 16:38:30 -07002573 LL_ACCESS_LOCK );
2574 if(csrCheck11dChannel(pBssDesc->Result.BssDescriptor.channelId,
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302575 pMac->roam.validChannelList, len))
Jeff Johnson295189b2012-06-20 16:38:30 -07002576 {
2577 /* Remove Scan result which does not have 11d channel */
2578 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry,
2579 LL_ACCESS_LOCK ))
2580 {
2581 csrFreeScanResultEntry( pMac, pBssDesc );
2582 }
2583 }
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302584 else
2585 {
2586 smsLog( pMac, LOG1, FL("%d is a Valid channel"),
2587 pBssDesc->Result.BssDescriptor.channelId);
2588 }
2589 pEntry = pTempEntry;
2590 }
2591
2592 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
2593 while( pEntry )
2594 {
2595 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2596 pTempEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry,
2597 LL_ACCESS_LOCK );
2598 if(csrCheck11dChannel(pBssDesc->Result.BssDescriptor.channelId,
2599 pMac->roam.validChannelList, len))
2600 {
2601 /* Remove Scan result which does not have 11d channel */
2602 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry,
2603 LL_ACCESS_LOCK ))
2604 {
2605 csrFreeScanResultEntry( pMac, pBssDesc );
2606 }
2607 }
2608 else
2609 {
2610 smsLog( pMac, LOG1, FL("%d is a Valid channel"),
2611 pBssDesc->Result.BssDescriptor.channelId);
2612 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002613 pEntry = pTempEntry;
2614 }
2615 return status;
2616}
2617
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05302618/**
2619 * csrScanFilterDFSResults
2620 *
2621 *FUNCTION:
2622 * This function filter BSSIDs on DFS channels from the scan results.
2623 *
2624 *LOGIC:
2625 * Get scan result from scan list and Check Scan result channel number
2626 * with 11d channel list if channel number is found in 11d channel list
2627 * and if fEnableDFSChnlScan is zero and if channel is DFS, then
2628 * remove scan result entry from scan list
2629 *
2630 *ASSUMPTIONS:
2631 *
2632 *NOTE:
2633 *
2634 * @param pMac Pointer to Global MAC structure
2635 *
2636 * @return Status
2637 */
2638
2639eHalStatus csrScanFilterDFSResults(tpAniSirGlobal pMac)
2640{
2641 eHalStatus status = eHAL_STATUS_SUCCESS;
2642 tListElem *pEntry,*pTempEntry;
2643 tCsrScanResult *pBssDesc;
2644
2645 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
2646 while( pEntry )
2647 {
2648 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2649 pTempEntry = csrLLNext( &pMac->scan.scanResultList, pEntry,
2650 LL_ACCESS_LOCK );
2651 if((pMac->scan.fEnableDFSChnlScan == DFS_CHNL_SCAN_DISABLED) &&
2652 CSR_IS_CHANNEL_DFS(pBssDesc->Result.BssDescriptor.channelId))
2653 {
2654 smsLog( pMac, LOG1, FL("%d is a DFS ch filtered from scan list"),
2655 pBssDesc->Result.BssDescriptor.channelId);
2656 /* Remove Scan result which does not have 11d channel */
2657 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry,
2658 LL_ACCESS_LOCK ))
2659 {
2660 csrFreeScanResultEntry( pMac, pBssDesc );
2661 }
2662 }
2663 else
2664 {
2665 smsLog( pMac, LOG1, FL("%d is a Valid channel"),
2666 pBssDesc->Result.BssDescriptor.channelId);
2667 }
2668 pEntry = pTempEntry;
2669 }
2670
2671 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
2672 while( pEntry )
2673 {
2674 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2675 pTempEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry,
2676 LL_ACCESS_LOCK );
2677
2678 if((pMac->scan.fEnableDFSChnlScan == DFS_CHNL_SCAN_DISABLED) &&
2679 CSR_IS_CHANNEL_DFS(pBssDesc->Result.BssDescriptor.channelId))
2680 {
2681 smsLog( pMac, LOG1, FL("%d is a DFS ch filtered from scan list"),
2682 pBssDesc->Result.BssDescriptor.channelId);
2683 /* Remove Scan result which does not have 11d channel */
2684 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry,
2685 LL_ACCESS_LOCK ))
2686 {
2687 csrFreeScanResultEntry( pMac, pBssDesc );
2688 }
2689 }
2690 else
2691 {
2692 smsLog( pMac, LOG1, FL("%d is a Valid channel"),
2693 pBssDesc->Result.BssDescriptor.channelId);
2694 }
2695 pEntry = pTempEntry;
2696 }
2697 return status;
2698}
2699
Jeff Johnson295189b2012-06-20 16:38:30 -07002700
2701eHalStatus csrScanCopyResultList(tpAniSirGlobal pMac, tScanResultHandle hIn, tScanResultHandle *phResult)
2702{
2703 eHalStatus status = eHAL_STATUS_SUCCESS;
2704 tScanResultList *pRetList, *pInList = (tScanResultList *)hIn;
2705 tCsrScanResult *pResult, *pScanResult;
2706 tANI_U32 count = 0;
2707 tListElem *pEntry;
2708 tANI_U32 bssLen, allocLen;
2709
2710 if(phResult)
2711 {
2712 *phResult = CSR_INVALID_SCANRESULT_HANDLE;
2713 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302714 pRetList = vos_mem_malloc(sizeof(tScanResultList));
2715 if ( NULL == pRetList )
2716 status = eHAL_STATUS_FAILURE;
2717 else
Jeff Johnson295189b2012-06-20 16:38:30 -07002718 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302719 vos_mem_set(pRetList, sizeof(tScanResultList), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002720 csrLLOpen(pMac->hHdd, &pRetList->List);
2721 pRetList->pCurEntry = NULL;
2722 csrLLLock(&pMac->scan.scanResultList);
2723 csrLLLock(&pInList->List);
2724
2725 pEntry = csrLLPeekHead( &pInList->List, LL_ACCESS_NOLOCK );
2726 while( pEntry )
2727 {
2728 pScanResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2729 bssLen = pScanResult->Result.BssDescriptor.length + sizeof(pScanResult->Result.BssDescriptor.length);
2730 allocLen = sizeof( tCsrScanResult ) + bssLen;
Kiet Lam64c1b492013-07-12 13:56:44 +05302731 pResult = vos_mem_malloc(allocLen);
2732 if ( NULL == pResult )
2733 status = eHAL_STATUS_FAILURE;
2734 else
2735 status = eHAL_STATUS_SUCCESS;
2736 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07002737 {
2738 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
2739 count = 0;
2740 break;
2741 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302742 vos_mem_set(pResult, allocLen , 0);
2743 vos_mem_copy(&pResult->Result.BssDescriptor, &pScanResult->Result.BssDescriptor, bssLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07002744 if( pScanResult->Result.pvIes )
2745 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302746 pResult->Result.pvIes = vos_mem_malloc(sizeof( tDot11fBeaconIEs ));
2747 if ( NULL == pResult->Result.pvIes )
2748 status = eHAL_STATUS_FAILURE;
2749 else
2750 status = eHAL_STATUS_SUCCESS;
2751 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07002752 {
2753 //Free the memory we allocate above first
Kiet Lam64c1b492013-07-12 13:56:44 +05302754 vos_mem_free(pResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07002755 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
2756 count = 0;
2757 break;
2758 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302759 vos_mem_copy(pResult->Result.pvIes, pScanResult->Result.pvIes,
2760 sizeof( tDot11fBeaconIEs ));
Jeff Johnson295189b2012-06-20 16:38:30 -07002761 }
2762 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_LOCK);
2763 count++;
2764 pEntry = csrLLNext( &pInList->List, pEntry, LL_ACCESS_NOLOCK );
2765 }//while
2766 csrLLUnlock(&pInList->List);
2767 csrLLUnlock(&pMac->scan.scanResultList);
2768
2769 if(HAL_STATUS_SUCCESS(status))
2770 {
2771 if(0 == count)
2772 {
2773 csrLLClose(&pRetList->List);
Kiet Lam64c1b492013-07-12 13:56:44 +05302774 vos_mem_free(pRetList);
Jeff Johnson295189b2012-06-20 16:38:30 -07002775 status = eHAL_STATUS_E_NULL_VALUE;
2776 }
2777 else if(phResult)
2778 {
2779 *phResult = pRetList;
2780 }
2781 }
2782 }//Allocated pRetList
2783
2784 return (status);
2785}
2786
2787
2788
2789eHalStatus csrScanningStateMsgProcessor( tpAniSirGlobal pMac, void *pMsgBuf )
2790{
2791 eHalStatus status = eHAL_STATUS_SUCCESS;
2792 tSirMbMsg *pMsg = (tSirMbMsg *)pMsgBuf;
2793
2794 if((eWNI_SME_SCAN_RSP == pMsg->type) || (eWNI_SME_GET_SCANNED_CHANNEL_RSP == pMsg->type))
2795 {
2796 status = csrScanSmeScanResponse( pMac, pMsgBuf );
2797 }
2798 else
2799 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002800 if(pMsg->type == eWNI_SME_UPPER_LAYER_ASSOC_CNF)
Jeff Johnson295189b2012-06-20 16:38:30 -07002801 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002802 tCsrRoamSession *pSession;
2803 tSirSmeAssocIndToUpperLayerCnf *pUpperLayerAssocCnf;
2804 tCsrRoamInfo roamInfo;
2805 tCsrRoamInfo *pRoamInfo = NULL;
2806 tANI_U32 sessionId;
2807 eHalStatus status;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002808 smsLog( pMac, LOG1, FL("Scanning : ASSOCIATION confirmation can be given to upper layer "));
Kiet Lam64c1b492013-07-12 13:56:44 +05302809 vos_mem_set(&roamInfo, sizeof(tCsrRoamInfo), 0);
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002810 pRoamInfo = &roamInfo;
2811 pUpperLayerAssocCnf = (tSirSmeAssocIndToUpperLayerCnf *)pMsgBuf;
2812 status = csrRoamGetSessionIdFromBSSID( pMac, (tCsrBssid *)pUpperLayerAssocCnf->bssId, &sessionId );
2813 pSession = CSR_GET_SESSION(pMac, sessionId);
2814
2815 if(!pSession)
2816 {
2817 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
2818 return eHAL_STATUS_FAILURE;
2819 }
2820
2821 pRoamInfo->statusCode = eSIR_SME_SUCCESS; //send the status code as Success
2822 pRoamInfo->u.pConnectedProfile = &pSession->connectedProfile;
2823 pRoamInfo->staId = (tANI_U8)pUpperLayerAssocCnf->aid;
2824 pRoamInfo->rsnIELen = (tANI_U8)pUpperLayerAssocCnf->rsnIE.length;
2825 pRoamInfo->prsnIE = pUpperLayerAssocCnf->rsnIE.rsnIEdata;
2826 pRoamInfo->addIELen = (tANI_U8)pUpperLayerAssocCnf->addIE.length;
2827 pRoamInfo->paddIE = pUpperLayerAssocCnf->addIE.addIEdata;
Kiet Lam64c1b492013-07-12 13:56:44 +05302828 vos_mem_copy(pRoamInfo->peerMac, pUpperLayerAssocCnf->peerMacAddr, sizeof(tSirMacAddr));
2829 vos_mem_copy(&pRoamInfo->bssid, pUpperLayerAssocCnf->bssId, sizeof(tCsrBssid));
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002830 pRoamInfo->wmmEnabledSta = pUpperLayerAssocCnf->wmmEnabledSta;
Hardik Kantilal Patel1ba630f2014-11-21 04:32:05 +05302831#ifdef WLAN_FEATURE_AP_HT40_24G
2832 pRoamInfo->HT40MHzIntoEnabledSta =
2833 pUpperLayerAssocCnf->HT40MHzIntoEnabledSta;
2834#endif
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002835 if(CSR_IS_INFRA_AP(pRoamInfo->u.pConnectedProfile) )
2836 {
2837 pMac->roam.roamSession[sessionId].connectState = eCSR_ASSOC_STATE_TYPE_INFRA_CONNECTED;
2838 pRoamInfo->fReassocReq = pUpperLayerAssocCnf->reassocReq;
2839 status = csrRoamCallCallback(pMac, sessionId, pRoamInfo, 0, eCSR_ROAM_INFRA_IND, eCSR_ROAM_RESULT_INFRA_ASSOCIATION_CNF);
2840 }
2841 if(CSR_IS_WDS_AP( pRoamInfo->u.pConnectedProfile))
2842 {
2843 vos_sleep( 100 );
2844 pMac->roam.roamSession[sessionId].connectState = eCSR_ASSOC_STATE_TYPE_WDS_CONNECTED;//Sta
2845 status = csrRoamCallCallback(pMac, sessionId, pRoamInfo, 0, eCSR_ROAM_WDS_IND, eCSR_ROAM_RESULT_WDS_ASSOCIATION_IND);//Sta
2846 }
2847
Jeff Johnson295189b2012-06-20 16:38:30 -07002848 }
2849 else
2850 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002851
2852 if( csrIsAnySessionInConnectState( pMac ) )
2853 {
2854 //In case of we are connected, we need to check whether connect status changes
2855 //because scan may also run while connected.
2856 csrRoamCheckForLinkStatusChange( pMac, ( tSirSmeRsp * )pMsgBuf );
2857 }
2858 else
2859 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002860 smsLog( pMac, LOGW, "Message [0x%04x] received in state, when expecting Scan Response", pMsg->type );
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002861 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002862 }
2863 }
2864
2865 return (status);
2866}
2867
2868
2869
2870void csrCheckNSaveWscIe(tpAniSirGlobal pMac, tSirBssDescription *pNewBssDescr, tSirBssDescription *pOldBssDescr)
2871{
2872 int idx, len;
2873 tANI_U8 *pbIe;
2874
2875 //If failed to remove, assuming someone else got it.
2876 if((pNewBssDescr->fProbeRsp != pOldBssDescr->fProbeRsp) &&
2877 (0 == pNewBssDescr->WscIeLen))
2878 {
2879 idx = 0;
2880 len = pOldBssDescr->length - sizeof(tSirBssDescription) +
2881 sizeof(tANI_U16) + sizeof(tANI_U32) - DOT11F_IE_WSCPROBERES_MIN_LEN - 2;
2882 pbIe = (tANI_U8 *)pOldBssDescr->ieFields;
2883 //Save WPS IE if it exists
2884 pNewBssDescr->WscIeLen = 0;
2885 while(idx < len)
2886 {
2887 if((DOT11F_EID_WSCPROBERES == pbIe[0]) &&
2888 (0x00 == pbIe[2]) && (0x50 == pbIe[3]) && (0xf2 == pbIe[4]) && (0x04 == pbIe[5]))
2889 {
2890 //Founrd it
2891 if((DOT11F_IE_WSCPROBERES_MAX_LEN - 2) >= pbIe[1])
2892 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302893 vos_mem_copy(pNewBssDescr->WscIeProbeRsp, pbIe, pbIe[1] + 2);
Jeff Johnson295189b2012-06-20 16:38:30 -07002894 pNewBssDescr->WscIeLen = pbIe[1] + 2;
2895 }
2896 break;
2897 }
2898 idx += pbIe[1] + 2;
2899 pbIe += pbIe[1] + 2;
2900 }
2901 }
2902}
2903
2904
2905
2906//pIes may be NULL
2907tANI_BOOLEAN csrRemoveDupBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDescr,
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05302908 tDot11fBeaconIEs *pIes, tAniSSID *pSsid, v_TIME_t *timer, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07002909{
2910 tListElem *pEntry;
2911
2912 tCsrScanResult *pBssDesc;
2913 tANI_BOOLEAN fRC = FALSE;
2914
2915 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
2916 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
2917 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
2918 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
2919
2920 while( pEntry )
2921 {
2922 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2923
2924 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
2925 // matches
2926 if ( csrIsDuplicateBssDescription( pMac, &pBssDesc->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07002927 pSirBssDescr, pIes, fForced ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07002928 {
2929 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
2930 ((tANI_S32)pBssDesc->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
2931 // Remove the 'old' entry from the list....
2932 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry, LL_ACCESS_LOCK ) )
2933 {
2934 // !we need to free the memory associated with this node
2935 //If failed to remove, assuming someone else got it.
2936 *pSsid = pBssDesc->Result.ssId;
2937 *timer = pBssDesc->Result.timer;
2938 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pBssDesc->Result.BssDescriptor);
2939
2940 csrFreeScanResultEntry( pMac, pBssDesc );
2941 }
2942 else
2943 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002944 smsLog( pMac, LOGW, FL( " fail to remove entry" ) );
Jeff Johnson295189b2012-06-20 16:38:30 -07002945 }
2946 fRC = TRUE;
2947
2948 // If we found a match, we can stop looking through the list.
2949 break;
2950 }
2951
2952 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_LOCK );
2953 }
2954
2955 return fRC;
2956}
2957
2958
2959eHalStatus csrAddPMKIDCandidateList( tpAniSirGlobal pMac, tANI_U32 sessionId,
2960 tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes )
2961{
2962 eHalStatus status = eHAL_STATUS_FAILURE;
2963 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
2964
Jeff Johnson32d95a32012-09-10 13:15:23 -07002965 if(!pSession)
2966 {
2967 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
2968 return eHAL_STATUS_FAILURE;
2969 }
2970
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002971 smsLog(pMac, LOGW, "csrAddPMKIDCandidateList called pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07002972 if( pIes )
2973 {
2974 // check if this is a RSN BSS
2975 if( pIes->RSN.present )
2976 {
2977 // Check if the BSS is capable of doing pre-authentication
2978 if( pSession->NumPmkidCandidate < CSR_MAX_PMKID_ALLOWED )
2979 {
2980
2981#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
2982 {
2983 WLAN_VOS_DIAG_EVENT_DEF(secEvent, vos_event_wlan_security_payload_type);
Kiet Lam64c1b492013-07-12 13:56:44 +05302984 vos_mem_set(&secEvent, sizeof(vos_event_wlan_security_payload_type), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002985 secEvent.eventId = WLAN_SECURITY_EVENT_PMKID_CANDIDATE_FOUND;
2986 secEvent.encryptionModeMulticast =
2987 (v_U8_t)diagEncTypeFromCSRType(pSession->connectedProfile.mcEncryptionType);
2988 secEvent.encryptionModeUnicast =
2989 (v_U8_t)diagEncTypeFromCSRType(pSession->connectedProfile.EncryptionType);
Kiet Lam64c1b492013-07-12 13:56:44 +05302990 vos_mem_copy(secEvent.bssid, pSession->connectedProfile.bssid, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07002991 secEvent.authMode =
2992 (v_U8_t)diagAuthTypeFromCSRType(pSession->connectedProfile.AuthType);
2993 WLAN_VOS_DIAG_EVENT_REPORT(&secEvent, EVENT_WLAN_SECURITY);
2994 }
2995#endif//#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
2996
2997 // if yes, then add to PMKIDCandidateList
Kiet Lam64c1b492013-07-12 13:56:44 +05302998 vos_mem_copy(pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].BSSID,
2999 pBssDesc->bssId, WNI_CFG_BSSID_LEN);
3000 // Bit 0 offirst byte - PreAuthentication Capability
3001 if ( (pIes->RSN.RSN_Cap[0] >> 0) & 0x1 )
Jeff Johnson295189b2012-06-20 16:38:30 -07003002 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303003 pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].preAuthSupported
3004 = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003005 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303006 else
3007 {
3008 pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].preAuthSupported
3009 = eANI_BOOLEAN_FALSE;
3010 }
3011 pSession->NumPmkidCandidate++;
Jeff Johnson295189b2012-06-20 16:38:30 -07003012 }
3013 else
3014 {
3015 status = eHAL_STATUS_FAILURE;
3016 }
3017 }
3018 }
3019
3020 return (status);
3021}
3022
3023//This function checks whether new AP is found for the current connected profile
3024//If it is found, it return the sessionId, else it return invalid sessionID
3025tANI_U32 csrProcessBSSDescForPMKIDList(tpAniSirGlobal pMac,
3026 tSirBssDescription *pBssDesc,
3027 tDot11fBeaconIEs *pIes)
3028{
3029 tANI_U32 i, bRet = CSR_SESSION_ID_INVALID;
3030 tCsrRoamSession *pSession;
3031 tDot11fBeaconIEs *pIesLocal = pIes;
3032
3033 if( pIesLocal || HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIesLocal)) )
3034 {
3035 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
3036 {
3037 if( CSR_IS_SESSION_VALID( pMac, i ) )
3038 {
3039 pSession = CSR_GET_SESSION( pMac, i );
3040 if( csrIsConnStateConnectedInfra( pMac, i ) &&
3041 ( eCSR_AUTH_TYPE_RSN == pSession->connectedProfile.AuthType ) )
3042 {
3043 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile, pBssDesc, pIesLocal))
3044 {
3045 //this new BSS fits the current profile connected
3046 if(HAL_STATUS_SUCCESS(csrAddPMKIDCandidateList(pMac, i, pBssDesc, pIesLocal)))
3047 {
3048 bRet = i;
3049 }
3050 break;
3051 }
3052 }
3053 }
3054 }
3055 if( !pIes )
3056 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303057 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003058 }
3059 }
3060
3061 return (tANI_U8)bRet;
3062}
3063
3064#ifdef FEATURE_WLAN_WAPI
3065eHalStatus csrAddBKIDCandidateList( tpAniSirGlobal pMac, tANI_U32 sessionId,
3066 tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes )
3067{
3068 eHalStatus status = eHAL_STATUS_FAILURE;
3069 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
3070
Jeff Johnson32d95a32012-09-10 13:15:23 -07003071 if(!pSession)
3072 {
3073 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
3074 return eHAL_STATUS_FAILURE;
3075 }
3076
Kiet Lam64c1b492013-07-12 13:56:44 +05303077 smsLog(pMac, LOGW, "csrAddBKIDCandidateList called pMac->scan.NumBkidCandidate = %d",
3078 pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07003079 if( pIes )
3080 {
3081 // check if this is a WAPI BSS
3082 if( pIes->WAPI.present )
3083 {
3084 // Check if the BSS is capable of doing pre-authentication
3085 if( pSession->NumBkidCandidate < CSR_MAX_BKID_ALLOWED )
3086 {
3087
3088 // if yes, then add to BKIDCandidateList
Kiet Lam64c1b492013-07-12 13:56:44 +05303089 vos_mem_copy(pSession->BkidCandidateInfo[pSession->NumBkidCandidate].BSSID,
3090 pBssDesc->bssId, WNI_CFG_BSSID_LEN);
3091 if ( pIes->WAPI.preauth )
Jeff Johnson295189b2012-06-20 16:38:30 -07003092 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303093 pSession->BkidCandidateInfo[pSession->NumBkidCandidate].preAuthSupported
3094 = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003095 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303096 else
3097 {
3098 pSession->BkidCandidateInfo[pSession->NumBkidCandidate].preAuthSupported
3099 = eANI_BOOLEAN_FALSE;
3100 }
3101 pSession->NumBkidCandidate++;
Jeff Johnson295189b2012-06-20 16:38:30 -07003102 }
3103 else
3104 {
3105 status = eHAL_STATUS_FAILURE;
3106 }
3107 }
3108 }
3109
3110 return (status);
3111}
3112
3113//This function checks whether new AP is found for the current connected profile
3114//if so add to BKIDCandidateList
3115tANI_BOOLEAN csrProcessBSSDescForBKIDList(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
3116 tDot11fBeaconIEs *pIes)
3117{
3118 tANI_BOOLEAN fRC = FALSE;
3119 tDot11fBeaconIEs *pIesLocal = pIes;
3120 tANI_U32 sessionId;
3121 tCsrRoamSession *pSession;
3122
3123 if( pIesLocal || HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIesLocal)) )
3124 {
3125 for( sessionId = 0; sessionId < CSR_ROAM_SESSION_MAX; sessionId++ )
3126 {
3127 if( CSR_IS_SESSION_VALID( pMac, sessionId) )
3128 {
3129 pSession = CSR_GET_SESSION( pMac, sessionId );
3130 if( csrIsConnStateConnectedInfra( pMac, sessionId ) &&
3131 eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE == pSession->connectedProfile.AuthType)
3132 {
3133 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile,pBssDesc, pIesLocal))
3134 {
3135 //this new BSS fits the current profile connected
3136 if(HAL_STATUS_SUCCESS(csrAddBKIDCandidateList(pMac, sessionId, pBssDesc, pIesLocal)))
3137 {
3138 fRC = TRUE;
3139 }
3140 }
3141 }
3142 }
3143 }
3144 if(!pIes)
3145 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303146 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003147 }
3148
3149 }
3150 return fRC;
3151}
3152
3153#endif
3154
3155
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07003156static void csrMoveTempScanResultsToMainList( tpAniSirGlobal pMac, tANI_U8 reason )
Jeff Johnson295189b2012-06-20 16:38:30 -07003157{
3158 tListElem *pEntry;
3159 tCsrScanResult *pBssDescription;
Jeff Johnson295189b2012-06-20 16:38:30 -07003160 tANI_BOOLEAN fDupBss;
3161#ifdef FEATURE_WLAN_WAPI
3162 tANI_BOOLEAN fNewWapiBSSForCurConnection = eANI_BOOLEAN_FALSE;
3163#endif /* FEATURE_WLAN_WAPI */
3164 tDot11fBeaconIEs *pIesLocal = NULL;
3165 tANI_U32 sessionId = CSR_SESSION_ID_INVALID;
3166 tAniSSID tmpSsid;
3167 v_TIME_t timer=0;
3168
3169 tmpSsid.length = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07003170
3171 // remove the BSS descriptions from temporary list
3172 while( ( pEntry = csrLLRemoveTail( &pMac->scan.tempScanResults, LL_ACCESS_LOCK ) ) != NULL)
3173 {
3174 pBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3175
Arif Hussain24bafea2013-11-15 15:10:03 -08003176 smsLog( pMac, LOGW, "...Bssid= "MAC_ADDRESS_STR" chan= %d, rssi = -%d",
3177 MAC_ADDR_ARRAY(pBssDescription->Result.BssDescriptor.bssId),
Jeff Johnson295189b2012-06-20 16:38:30 -07003178 pBssDescription->Result.BssDescriptor.channelId,
3179 pBssDescription->Result.BssDescriptor.rssi * (-1) );
3180
3181 //At this time, pBssDescription->Result.pvIes may be NULL
3182 pIesLocal = (tDot11fBeaconIEs *)( pBssDescription->Result.pvIes );
3183 if( !pIesLocal && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pBssDescription->Result.BssDescriptor, &pIesLocal))) )
3184 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003185 smsLog(pMac, LOGE, FL(" Cannot pared IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003186 csrFreeScanResultEntry(pMac, pBssDescription);
3187 continue;
3188 }
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05303189 fDupBss = csrRemoveDupBssDescription( pMac, &pBssDescription->Result.BssDescriptor, pIesLocal, &tmpSsid, &timer, FALSE );
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07003190 //Check whether we have reach out limit, but don't lose the LFR candidates came from FW
3191 if( CSR_SCAN_IS_OVER_BSS_LIMIT(pMac)
3192#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
3193 && !( eCsrScanGetLfrResult == reason )
3194#endif
3195 )
Jeff Johnson295189b2012-06-20 16:38:30 -07003196 {
3197 //Limit reach
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003198 smsLog(pMac, LOGW, FL(" BSS limit reached"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003199 //Free the resources
3200 if( (pBssDescription->Result.pvIes == NULL) && pIesLocal )
3201 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303202 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003203 }
3204 csrFreeScanResultEntry(pMac, pBssDescription);
3205 //Continue because there may be duplicated BSS
3206 continue;
3207 }
3208 // check for duplicate scan results
3209 if ( !fDupBss )
3210 {
3211 //Found a new BSS
3212 sessionId = csrProcessBSSDescForPMKIDList(pMac,
3213 &pBssDescription->Result.BssDescriptor, pIesLocal);
3214 if( CSR_SESSION_ID_INVALID != sessionId)
3215 {
3216 csrRoamCallCallback(pMac, sessionId, NULL, 0,
3217 eCSR_ROAM_SCAN_FOUND_NEW_BSS, eCSR_ROAM_RESULT_NONE);
3218 }
3219 }
3220 else
3221 {
3222 //Check if the new one has SSID it it, if not, use the older SSID if it exists.
3223 if( (0 == pBssDescription->Result.ssId.length) && tmpSsid.length )
3224 {
3225 //New BSS has a hidden SSID and old one has the SSID. Keep the SSID only
3226 //if diff of saved SSID time and current time is less than 1 min to avoid
3227 //side effect of saving SSID with old one is that if AP changes its SSID while remain
3228 //hidden, we may never see it and also to address the requirement of
3229 //When we remove hidden ssid from the profile i.e., forget the SSID via
3230 // GUI that SSID shouldn't see in the profile
3231 if( (vos_timer_get_system_time() - timer) <= HIDDEN_TIMER)
3232 {
3233 pBssDescription->Result.timer = timer;
3234 pBssDescription->Result.ssId = tmpSsid;
3235 }
3236 }
3237 }
3238
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303239 //Find a good AP for 11d info
3240 if ( csrIs11dSupported( pMac ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003241 {
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303242 // check if country information element is present
3243 if (pIesLocal->Country.present)
Jeff Johnson295189b2012-06-20 16:38:30 -07003244 {
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303245 csrAddVoteForCountryInfo(pMac, pIesLocal->Country.country);
3246 smsLog(pMac, LOGW, FL("11d AP Bssid " MAC_ADDRESS_STR
3247 " chan= %d, rssi = -%d, countryCode %c%c"),
3248 MAC_ADDR_ARRAY( pBssDescription->Result.BssDescriptor.bssId),
3249 pBssDescription->Result.BssDescriptor.channelId,
3250 pBssDescription->Result.BssDescriptor.rssi * (-1),
3251 pIesLocal->Country.country[0],pIesLocal->Country.country[1] );
3252 }
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303253
Jeff Johnson295189b2012-06-20 16:38:30 -07003254 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08003255
Jeff Johnson295189b2012-06-20 16:38:30 -07003256 // append to main list
3257 csrScanAddResult(pMac, pBssDescription, pIesLocal);
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303258 if ( (pBssDescription->Result.pvIes == NULL) && pIesLocal )
Jeff Johnson295189b2012-06-20 16:38:30 -07003259 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303260 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003261 }
3262 }
3263
Tushnim Bhattacharyyaae317772013-10-23 18:55:38 -07003264 //we don't need to update CC while connected to an AP which is advertising CC already
3265 if (csrIs11dSupported(pMac))
3266 {
3267 tANI_U32 i;
3268 tCsrRoamSession *pSession;
3269
3270 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
3271 {
3272 if (CSR_IS_SESSION_VALID( pMac, i ) )
3273 {
3274 pSession = CSR_GET_SESSION( pMac, i );
3275 if (csrIsConnStateConnected(pMac, i))
3276 {
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303277 smsLog(pMac, LOGW, FL("No need for updating CC in"
3278 "connected state"));
3279 goto end;
Tushnim Bhattacharyyaae317772013-10-23 18:55:38 -07003280 }
3281 }
3282 }
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303283 csrElectedCountryInfo(pMac);
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05303284 csrLearnCountryInformation( pMac, NULL, NULL, eANI_BOOLEAN_TRUE );
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303285 }
3286
Tushnim Bhattacharyyaae317772013-10-23 18:55:38 -07003287end:
3288 //If we can find the current 11d info in any of the scan results, or
Jeff Johnson295189b2012-06-20 16:38:30 -07003289 // a good enough AP with the 11d info from the scan results then no need to
3290 // get into ambiguous state
3291 if(pMac->scan.fAmbiguous11dInfoFound)
3292 {
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303293 if((pMac->scan.fCurrent11dInfoMatch))
Jeff Johnson295189b2012-06-20 16:38:30 -07003294 {
3295 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
3296 }
3297 }
3298
3299#ifdef FEATURE_WLAN_WAPI
3300 if(fNewWapiBSSForCurConnection)
3301 {
3302 //remember it first
3303 csrRoamCallCallback(pMac, sessionId, NULL, 0, eCSR_ROAM_SCAN_FOUND_NEW_BSS, eCSR_ROAM_RESULT_NEW_WAPI_BSS);
3304 }
3305#endif /* FEATURE_WLAN_WAPI */
3306
3307 return;
3308}
3309
3310
3311static tCsrScanResult *csrScanSaveBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pBSSDescription,
3312 tDot11fBeaconIEs *pIes)
3313{
3314 tCsrScanResult *pCsrBssDescription = NULL;
3315 tANI_U32 cbBSSDesc;
3316 tANI_U32 cbAllocated;
Jeff Johnson295189b2012-06-20 16:38:30 -07003317
3318 // figure out how big the BSS description is (the BSSDesc->length does NOT
3319 // include the size of the length field itself).
3320 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
3321
3322 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
3323
Kiet Lam64c1b492013-07-12 13:56:44 +05303324 pCsrBssDescription = vos_mem_malloc(cbAllocated);
3325 if ( NULL != pCsrBssDescription )
Jeff Johnson295189b2012-06-20 16:38:30 -07003326 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303327 vos_mem_set(pCsrBssDescription, cbAllocated, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003328 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Kiet Lam64c1b492013-07-12 13:56:44 +05303329 vos_mem_copy(&pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc);
Jeff Johnson295189b2012-06-20 16:38:30 -07003330#if defined(VOSS_ENSBALED)
3331 VOS_ASSERT( pCsrBssDescription->Result.pvIes == NULL );
3332#endif
3333 csrScanAddResult(pMac, pCsrBssDescription, pIes);
3334 }
3335
3336 return( pCsrBssDescription );
3337}
3338
3339// Append a Bss Description...
3340tCsrScanResult *csrScanAppendBssDescription( tpAniSirGlobal pMac,
3341 tSirBssDescription *pSirBssDescription,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07003342 tDot11fBeaconIEs *pIes, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07003343{
3344 tCsrScanResult *pCsrBssDescription = NULL;
3345 tAniSSID tmpSsid;
3346 v_TIME_t timer = 0;
3347 int result;
3348
3349 tmpSsid.length = 0;
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07003350 result = csrRemoveDupBssDescription( pMac, pSirBssDescription, pIes, &tmpSsid, &timer, fForced );
Jeff Johnson295189b2012-06-20 16:38:30 -07003351 pCsrBssDescription = csrScanSaveBssDescription( pMac, pSirBssDescription, pIes );
3352 if (result && (pCsrBssDescription != NULL))
3353 {
3354 //Check if the new one has SSID it it, if not, use the older SSID if it exists.
3355 if( (0 == pCsrBssDescription->Result.ssId.length) && tmpSsid.length )
3356 {
3357 //New BSS has a hidden SSID and old one has the SSID. Keep the SSID only
3358 //if diff of saved SSID time and current time is less than 1 min to avoid
3359 //side effect of saving SSID with old one is that if AP changes its SSID while remain
3360 //hidden, we may never see it and also to address the requirement of
3361 //When we remove hidden ssid from the profile i.e., forget the SSID via
3362 // GUI that SSID shouldn't see in the profile
3363 if((vos_timer_get_system_time()-timer) <= HIDDEN_TIMER)
3364 {
3365 pCsrBssDescription->Result.ssId = tmpSsid;
3366 pCsrBssDescription->Result.timer = timer;
3367 }
3368 }
3369 }
3370
3371
3372 return( pCsrBssDescription );
3373}
3374
3375
3376
3377void csrPurgeChannelPower( tpAniSirGlobal pMac, tDblLinkList *pChannelList )
3378{
3379 tCsrChannelPowerInfo *pChannelSet;
3380 tListElem *pEntry;
3381
3382 csrLLLock(pChannelList);
3383 // Remove the channel sets from the learned list and put them in the free list
3384 while( ( pEntry = csrLLRemoveHead( pChannelList, LL_ACCESS_NOLOCK ) ) != NULL)
3385 {
3386 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3387 if( pChannelSet )
3388 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303389 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003390 }
3391 }
3392 csrLLUnlock(pChannelList);
3393 return;
3394}
3395
3396
3397/*
3398 * Save the channelList into the ultimate storage as the final stage of channel
3399 * Input: pCountryInfo -- the country code (e.g. "USI"), channel list, and power limit are all stored inside this data structure
3400 */
Jeff Johnsone7245742012-09-05 17:12:55 -07003401eHalStatus csrSaveToChannelPower2G_5G( tpAniSirGlobal pMac, tANI_U32 tableSize, tSirMacChanInfo *channelTable )
Jeff Johnson295189b2012-06-20 16:38:30 -07003402{
3403 tANI_U32 i = tableSize / sizeof( tSirMacChanInfo );
3404 tSirMacChanInfo *pChannelInfo;
3405 tCsrChannelPowerInfo *pChannelSet;
3406 tANI_BOOLEAN f2GHzInfoFound = FALSE;
3407 tANI_BOOLEAN f2GListPurged = FALSE, f5GListPurged = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003408
3409 pChannelInfo = channelTable;
3410 // atleast 3 bytes have to be remaining -- from "countryString"
3411 while ( i-- )
3412 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303413 pChannelSet = vos_mem_malloc(sizeof(tCsrChannelPowerInfo));
3414 if ( NULL != pChannelSet )
Jeff Johnson295189b2012-06-20 16:38:30 -07003415 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303416 vos_mem_set(pChannelSet, sizeof(tCsrChannelPowerInfo), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003417 pChannelSet->firstChannel = pChannelInfo->firstChanNum;
3418 pChannelSet->numChannels = pChannelInfo->numChannels;
3419
3420 // Now set the inter-channel offset based on the frequency band the channel set lies in
Jeff Johnsone7245742012-09-05 17:12:55 -07003421 if( (CSR_IS_CHANNEL_24GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003422 ((pChannelSet->firstChannel + (pChannelSet->numChannels - 1)) <= CSR_MAX_24GHz_CHANNEL_NUMBER) )
Jeff Johnsone7245742012-09-05 17:12:55 -07003423
Jeff Johnson295189b2012-06-20 16:38:30 -07003424 {
3425 pChannelSet->interChannelOffset = 1;
3426 f2GHzInfoFound = TRUE;
3427 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003428 else if ( (CSR_IS_CHANNEL_5GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003429 ((pChannelSet->firstChannel + ((pChannelSet->numChannels - 1) * 4)) <= CSR_MAX_5GHz_CHANNEL_NUMBER) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003430 {
3431 pChannelSet->interChannelOffset = 4;
3432 f2GHzInfoFound = FALSE;
3433 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003434 else
3435 {
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003436 smsLog( pMac, LOGW, FL("Invalid Channel %d Present in Country IE"),
Jeff Johnsone7245742012-09-05 17:12:55 -07003437 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303438 vos_mem_free(pChannelSet);
Jeff Johnsone7245742012-09-05 17:12:55 -07003439 return eHAL_STATUS_FAILURE;
3440 }
3441
Jeff Johnson295189b2012-06-20 16:38:30 -07003442 pChannelSet->txPower = CSR_ROAM_MIN( pChannelInfo->maxTxPower, pMac->roam.configParam.nTxPowerCap );
3443
3444 if( f2GHzInfoFound )
3445 {
3446 if( !f2GListPurged )
3447 {
3448 // purge previous results if found new
3449 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList24 );
3450 f2GListPurged = TRUE;
3451 }
3452
3453 if(CSR_IS_OPERATING_BG_BAND(pMac))
3454 {
3455 // add to the list of 2.4 GHz channel sets
3456 csrLLInsertTail( &pMac->scan.channelPowerInfoList24, &pChannelSet->link, LL_ACCESS_LOCK );
3457 }
3458 else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003459 smsLog( pMac, LOGW, FL("Adding 11B/G channels in 11A mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003460 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303461 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003462 }
3463 }
3464 else
3465 {
3466 // 5GHz info found
3467 if( !f5GListPurged )
3468 {
3469 // purge previous results if found new
3470 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList5G );
3471 f5GListPurged = TRUE;
3472 }
3473
3474 if(CSR_IS_OPERATING_A_BAND(pMac))
3475 {
3476 // add to the list of 5GHz channel sets
3477 csrLLInsertTail( &pMac->scan.channelPowerInfoList5G, &pChannelSet->link, LL_ACCESS_LOCK );
3478 }
3479 else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003480 smsLog( pMac, LOGW, FL("Adding 11A channels in B/G mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003481 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303482 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003483 }
3484 }
3485 }
3486
3487 pChannelInfo++; // move to next entry
3488 }
3489
Jeff Johnsone7245742012-09-05 17:12:55 -07003490 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07003491}
3492
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303493static void csrClearDfsChannelList( tpAniSirGlobal pMac )
3494{
3495 tSirMbMsg *pMsg;
3496 tANI_U16 msgLen;
Jeff Johnson295189b2012-06-20 16:38:30 -07003497
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303498 msgLen = (tANI_U16)(sizeof( tSirMbMsg ));
Kiet Lam64c1b492013-07-12 13:56:44 +05303499 pMsg = vos_mem_malloc(msgLen);
3500 if ( NULL != pMsg )
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303501 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303502 vos_mem_set((void *)pMsg, msgLen, 0);
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303503 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_CLEAR_DFS_CHANNEL_LIST);
3504 pMsg->msgLen = pal_cpu_to_be16(msgLen);
3505 palSendMBMessage(pMac->hHdd, pMsg);
3506 }
3507}
Jeff Johnson295189b2012-06-20 16:38:30 -07003508
3509void csrApplyPower2Current( tpAniSirGlobal pMac )
3510{
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003511 smsLog( pMac, LOG3, FL(" Updating Cfg with power settings"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003512 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList24, WNI_CFG_MAX_TX_POWER_2_4 );
3513 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList5G, WNI_CFG_MAX_TX_POWER_5 );
3514}
3515
3516
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003517void csrApplyChannelPowerCountryInfo( tpAniSirGlobal pMac, tCsrChannel *pChannelList, tANI_U8 *countryCode, tANI_BOOLEAN updateRiva)
Jeff Johnson295189b2012-06-20 16:38:30 -07003518{
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303519 int i, j, count, countryIndex = -1;
Jeff Johnson295189b2012-06-20 16:38:30 -07003520 tANI_U8 numChannels = 0;
3521 tANI_U8 tempNumChannels = 0;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303522 tANI_U8 channelIgnore = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003523 tCsrChannel ChannelList;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303524
Jeff Johnson295189b2012-06-20 16:38:30 -07003525 if( pChannelList->numChannels )
3526 {
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303527 for(count=0; count < MAX_COUNTRY_IGNORE; count++)
3528 {
3529 if(vos_mem_compare(countryCode, countryIgnoreList[count].countryCode,
3530 VOS_COUNTRY_CODE_LEN))
3531 {
3532 countryIndex = count;
3533 break;
3534 }
3535 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003536 tempNumChannels = CSR_MIN(pChannelList->numChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN);
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05303537
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303538 for(i=0; i < tempNumChannels; i++)
Jeff Johnson295189b2012-06-20 16:38:30 -07003539 {
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303540 channelIgnore = FALSE;
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05303541 if( countryIndex != -1 )
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303542 {
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05303543 for(j=0; j < countryIgnoreList[countryIndex].channelCount; j++)
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303544 {
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05303545 if( pChannelList->channelList[i] ==
3546 countryIgnoreList[countryIndex].channelList[j] )
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303547 {
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05303548 channelIgnore = TRUE;
3549 break;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303550 }
3551 }
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05303552 }
3553 if( FALSE == channelIgnore )
3554 {
3555 ChannelList.channelList[numChannels] = pChannelList->channelList[i];
3556 numChannels++;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303557 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003558 }
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303559 ChannelList.numChannels = numChannels;
Mahesh A Saptasagar1ed59582014-06-04 18:45:07 +05303560 csrApplyPower2Current( pMac ); // Store the channel+power info in the global place: Cfg
Jeff Johnson295189b2012-06-20 16:38:30 -07003561 csrSetCfgValidChannelList(pMac, ChannelList.channelList, ChannelList.numChannels);
3562 // extend scan capability
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303563 // build a scan list based on the channel list : channel# + active/passive scan
3564 csrSetCfgScanControlList(pMac, countryCode, &ChannelList);
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303565 /*Send msg to Lim to clear DFS channel list */
3566 csrClearDfsChannelList(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07003567#ifdef FEATURE_WLAN_SCAN_PNO
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003568 if (updateRiva)
3569 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003570 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO, FL(" Sending 11d PNO info to Riva"));
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003571 // Send HAL UpdateScanParams message
3572 pmcUpdateScanParams(pMac, &(pMac->roam.configParam), &ChannelList, TRUE);
3573 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003574#endif // FEATURE_WLAN_SCAN_PNO
3575 }
3576 else
3577 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003578 smsLog( pMac, LOGE, FL(" 11D channel list is empty"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003579 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003580 csrSetCfgCountryCode(pMac, countryCode);
3581}
3582
3583
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003584void csrResetCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce, tANI_BOOLEAN updateRiva )
Jeff Johnson295189b2012-06-20 16:38:30 -07003585{
3586 if( fForce || (csrIs11dSupported( pMac ) && (!pMac->scan.f11dInfoReset)))
3587 {
3588
3589#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3590 {
3591 vos_log_802_11d_pkt_type *p11dLog;
3592 int Index;
3593
3594 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
3595 if(p11dLog)
3596 {
3597 p11dLog->eventId = WLAN_80211D_EVENT_RESET;
Kiet Lam64c1b492013-07-12 13:56:44 +05303598 vos_mem_copy(p11dLog->countryCode, pMac->scan.countryCodeCurrent, 3);
Jeff Johnson295189b2012-06-20 16:38:30 -07003599 p11dLog->numChannel = pMac->scan.base20MHzChannels.numChannels;
3600 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
3601 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303602 vos_mem_copy(p11dLog->Channels,
3603 pMac->scan.base20MHzChannels.channelList,
3604 p11dLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07003605 for (Index=0; Index < pMac->scan.base20MHzChannels.numChannels; Index++)
3606 {
3607 p11dLog->TxPwr[Index] = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
3608 }
3609 }
3610 if(!pMac->roam.configParam.Is11dSupportEnabled)
3611 {
3612 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
3613 }
3614 else if(pMac->roam.configParam.fEnforceDefaultDomain)
3615 {
3616 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
3617 }
3618 else
3619 {
3620 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
3621 }
3622 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
3623 }
3624 }
3625#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3626
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003627 csrPruneChannelListForMode(pMac, &pMac->scan.baseChannels);
3628 csrPruneChannelListForMode(pMac, &pMac->scan.base20MHzChannels);
3629
Jeff Johnson295189b2012-06-20 16:38:30 -07003630 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_FALSE);
3631 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_TRUE);
3632 // ... and apply the channel list, power settings, and the country code.
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003633 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.base20MHzChannels, pMac->scan.countryCodeCurrent, updateRiva );
Jeff Johnson295189b2012-06-20 16:38:30 -07003634 // clear the 11d channel list
Kiet Lam64c1b492013-07-12 13:56:44 +05303635 vos_mem_set(&pMac->scan.channels11d, sizeof(pMac->scan.channels11d), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003636 pMac->scan.f11dInfoReset = eANI_BOOLEAN_TRUE;
3637 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_FALSE;
3638 }
3639
3640 return;
3641}
3642
3643
3644eHalStatus csrResetCountryCodeInformation(tpAniSirGlobal pMac, tANI_BOOLEAN *pfRestartNeeded)
3645{
3646 eHalStatus status = eHAL_STATUS_SUCCESS;
3647 tANI_BOOLEAN fRestart = eANI_BOOLEAN_FALSE;
3648
3649 //Use the Country code and domain from EEPROM
Kiet Lam64c1b492013-07-12 13:56:44 +05303650 vos_mem_copy(pMac->scan.countryCodeCurrent, pMac->scan.countryCodeDefault,
3651 WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07003652 csrSetRegulatoryDomain(pMac, pMac->scan.domainIdCurrent, &fRestart);
Jeff Johnson43971f52012-07-17 12:26:56 -07003653 if( ((eANI_BOOLEAN_FALSE == fRestart) || (pfRestartNeeded == NULL) )
3654 && !csrIsInfraConnected(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -07003655 {
3656 //Only reset the country info if we don't need to restart
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003657 csrResetCountryInformation(pMac, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07003658 }
3659 if(pfRestartNeeded)
3660 {
3661 *pfRestartNeeded = fRestart;
3662 }
3663
3664 return (status);
3665}
3666
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303667void csrClearVotesForCountryInfo(tpAniSirGlobal pMac)
3668{
3669 pMac->scan.countryCodeCount = 0;
3670 vos_mem_set(pMac->scan.votes11d,
3671 sizeof(tCsrVotes11d) * CSR_MAX_NUM_COUNTRY_CODE, 0);
3672}
3673
3674void csrAddVoteForCountryInfo(tpAniSirGlobal pMac, tANI_U8 *pCountryCode)
3675{
3676 tANI_BOOLEAN match = FALSE;
3677 tANI_U8 i;
3678
3679 /* convert to UPPER here so we are assured
3680 * the strings are always in upper case.
3681 */
3682 for( i = 0; i < 3; i++ )
3683 {
3684 pCountryCode[ i ] = (tANI_U8)csrToUpper( pCountryCode[ i ] );
3685 }
3686
3687 /* Some of the 'old' Cisco 350 series AP's advertise NA as the
3688 * country code (for North America ??). NA is not a valid country code
3689 * or domain so let's allow this by changing it to the proper
3690 * country code (which is US). We've also seen some NETGEAR AP's
3691 * that have "XX " as the country code with valid 2.4 GHz US channel
3692 * information. If we cannot find the country code advertised in the
3693 * 11d information element, let's default to US.
3694 */
3695
3696 if ( !HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry( pMac,
3697 pCountryCode, NULL,COUNTRY_QUERY ) ) )
3698 {
3699 pCountryCode[ 0 ] = '0';
3700 pCountryCode[ 1 ] = '0';
3701 }
3702
3703 /* We've seen some of the AP's improperly put a 0 for the
3704 * third character of the country code. spec says valid charcters are
3705 * 'O' (for outdoor), 'I' for Indoor, or ' ' (space; for either).
3706 * if we see a 0 in this third character, let's change it to a ' '.
3707 */
3708 if ( 0 == pCountryCode[ 2 ] )
3709 {
3710 pCountryCode[ 2 ] = ' ';
3711 }
3712
3713 for (i = 0; i < pMac->scan.countryCodeCount; i++)
3714 {
3715 match = (vos_mem_compare(pMac->scan.votes11d[i].countryCode,
3716 pCountryCode, 2));
3717 if(match)
3718 {
3719 break;
3720 }
3721 }
3722
3723 if (match)
3724 {
3725 pMac->scan.votes11d[i].votes++;
3726 }
3727 else
3728 {
3729 vos_mem_copy( pMac->scan.votes11d[pMac->scan.countryCodeCount].countryCode,
3730 pCountryCode, 3 );
3731 pMac->scan.votes11d[pMac->scan.countryCodeCount].votes = 1;
3732 pMac->scan.countryCodeCount++;
3733 }
3734
3735 return;
3736}
3737
3738tANI_BOOLEAN csrElectedCountryInfo(tpAniSirGlobal pMac)
3739{
3740 tANI_BOOLEAN fRet = FALSE;
3741 tANI_U8 maxVotes = 0;
3742 tANI_U8 i, j=0;
3743
3744 if (!pMac->scan.countryCodeCount)
3745 {
3746 return fRet;
3747 }
3748 maxVotes = pMac->scan.votes11d[0].votes;
3749 fRet = TRUE;
3750
3751 for(i = 1; i < pMac->scan.countryCodeCount; i++)
3752 {
3753 /* If we have a tie for max votes for 2 different country codes,
3754 * pick random.we can put some more intelligence - TBD
3755 */
3756 if (maxVotes < pMac->scan.votes11d[i].votes)
3757 {
3758 VOS_TRACE( VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
3759 " Votes for Country %c%c : %d\n",
3760 pMac->scan.votes11d[i].countryCode[0],
3761 pMac->scan.votes11d[i].countryCode[1],
3762 pMac->scan.votes11d[i].votes);
3763
3764 maxVotes = pMac->scan.votes11d[i].votes;
3765 j = i;
3766 fRet = TRUE;
3767 }
3768
3769 }
3770 if (fRet)
3771 {
Rajesh Babu Prathipati20cdffa2014-07-01 22:24:59 +05303772 vos_mem_copy(pMac->scan.countryCodeElected,
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303773 pMac->scan.votes11d[j].countryCode, WNI_CFG_COUNTRY_CODE_LEN);
Rajesh Babu Prathipati20cdffa2014-07-01 22:24:59 +05303774 vos_mem_copy(pMac->scan.countryCode11d,
Agarwal Ashish852b2c32014-05-23 17:13:25 +05303775 pMac->scan.votes11d[j].countryCode, WNI_CFG_COUNTRY_CODE_LEN);
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303776 VOS_TRACE( VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
3777 "Selected Country is %c%c With count %d\n",
3778 pMac->scan.votes11d[j].countryCode[0],
3779 pMac->scan.votes11d[j].countryCode[1],
3780 pMac->scan.votes11d[j].votes);
3781 }
3782 return fRet;
3783}
Jeff Johnson295189b2012-06-20 16:38:30 -07003784
3785eHalStatus csrSetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pCountry, tANI_BOOLEAN *pfRestartNeeded)
3786{
3787 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
3788 v_REGDOMAIN_t domainId;
3789
3790 if(pCountry)
3791 {
Kiet Lam6c583332013-10-14 05:37:09 +05303792 status = csrGetRegulatoryDomainForCountry(pMac, pCountry, &domainId, COUNTRY_USER);
Jeff Johnson295189b2012-06-20 16:38:30 -07003793 if(HAL_STATUS_SUCCESS(status))
3794 {
3795 status = csrSetRegulatoryDomain(pMac, domainId, pfRestartNeeded);
3796 if(HAL_STATUS_SUCCESS(status))
3797 {
3798 //We don't need to check the pMac->roam.configParam.fEnforceDefaultDomain flag here,
3799 //csrSetRegulatoryDomain will fail if the country doesn't fit our domain criteria.
Kiet Lam64c1b492013-07-12 13:56:44 +05303800 vos_mem_copy(pMac->scan.countryCodeCurrent, pCountry, WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07003801 if((pfRestartNeeded == NULL) || !(*pfRestartNeeded))
3802 {
3803 //Simply set it to cfg. If we need to restart, restart will apply it to the CFG
3804 csrSetCfgCountryCode(pMac, pCountry);
3805 }
3806 }
3807 }
3808 }
3809
3810 return (status);
3811}
3812
3813
3814
3815//caller allocated memory for pNumChn and pChnPowerInfo
3816//As input, *pNumChn has the size of the array of pChnPowerInfo
3817//Upon return, *pNumChn has the number of channels assigned.
3818void csrGetChannelPowerInfo( tpAniSirGlobal pMac, tDblLinkList *pList,
3819 tANI_U32 *pNumChn, tChannelListWithPower *pChnPowerInfo)
3820{
3821 tListElem *pEntry;
3822 tANI_U32 chnIdx = 0, idx;
3823 tCsrChannelPowerInfo *pChannelSet;
3824
3825 //Get 2.4Ghz first
3826 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
3827 while( pEntry && (chnIdx < *pNumChn) )
3828 {
3829 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3830 if ( 1 != pChannelSet->interChannelOffset )
3831 {
3832 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
3833 {
3834 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
3835 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
3836 }
3837 }
3838 else
3839 {
3840 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
3841 {
3842 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + idx);
3843 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
3844 }
3845 }
3846
3847 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
3848 }
3849 *pNumChn = chnIdx;
3850
3851 return ;
3852}
3853
3854
3855
3856void csrApplyCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce )
3857{
3858 v_REGDOMAIN_t domainId;
3859 eHalStatus status = eHAL_STATUS_SUCCESS;
3860
3861 do
3862 {
3863 if( !csrIs11dSupported( pMac ) || 0 == pMac->scan.channelOf11dInfo) break;
3864 if( pMac->scan.fAmbiguous11dInfoFound )
3865 {
3866 // ambiguous info found
3867 //Restore te default domain as well
Kiet Lam6c583332013-10-14 05:37:09 +05303868 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
3869 pMac, pMac->scan.countryCodeCurrent,
3870 &domainId, COUNTRY_QUERY)))
Jeff Johnson295189b2012-06-20 16:38:30 -07003871 {
3872 pMac->scan.domainIdCurrent = domainId;
3873 }
3874 else
3875 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003876 smsLog(pMac, LOGE, FL(" failed to get domain from currentCountryCode %02X%02X"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003877 pMac->scan.countryCodeCurrent[0], pMac->scan.countryCodeCurrent[1]);
3878 }
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003879 csrResetCountryInformation( pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE );
Jeff Johnson295189b2012-06-20 16:38:30 -07003880 break;
3881 }
3882 if ( pMac->scan.f11dInfoApplied && !fForce ) break;
Kiet Lam6c583332013-10-14 05:37:09 +05303883 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
3884 pMac, pMac->scan.countryCode11d,
3885 &domainId, COUNTRY_QUERY)))
Jeff Johnson295189b2012-06-20 16:38:30 -07003886 {
3887 //Check whether we need to enforce default domain
3888 if( ( !pMac->roam.configParam.fEnforceDefaultDomain ) ||
3889 (pMac->scan.domainIdCurrent == domainId) )
3890 {
3891
3892#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3893 {
3894 vos_log_802_11d_pkt_type *p11dLog;
3895 tChannelListWithPower chnPwrInfo[WNI_CFG_VALID_CHANNEL_LIST_LEN];
3896 tANI_U32 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN, nTmp;
3897
3898 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
3899 if(p11dLog)
3900 {
3901 p11dLog->eventId = WLAN_80211D_EVENT_COUNTRY_SET;
Kiet Lam64c1b492013-07-12 13:56:44 +05303902 vos_mem_copy(p11dLog->countryCode, pMac->scan.countryCode11d, 3);
Jeff Johnson295189b2012-06-20 16:38:30 -07003903 p11dLog->numChannel = pMac->scan.channels11d.numChannels;
3904 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
3905 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303906 vos_mem_copy(p11dLog->Channels,
3907 pMac->scan.channels11d.channelList,
3908 p11dLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07003909 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList24,
3910 &nChnInfo, chnPwrInfo);
3911 nTmp = nChnInfo;
3912 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN - nTmp;
3913 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList5G,
3914 &nChnInfo, &chnPwrInfo[nTmp]);
3915 for(nTmp = 0; nTmp < p11dLog->numChannel; nTmp++)
3916 {
3917 for(nChnInfo = 0; nChnInfo < WNI_CFG_VALID_CHANNEL_LIST_LEN; nChnInfo++)
3918 {
3919 if(p11dLog->Channels[nTmp] == chnPwrInfo[nChnInfo].chanId)
3920 {
3921 p11dLog->TxPwr[nTmp] = chnPwrInfo[nChnInfo].pwr;
3922 break;
3923 }
3924 }
3925 }
3926 }
3927 if(!pMac->roam.configParam.Is11dSupportEnabled)
3928 {
3929 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
3930 }
3931 else if(pMac->roam.configParam.fEnforceDefaultDomain)
3932 {
3933 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
3934 }
3935 else
3936 {
3937 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
3938 }
3939 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
3940 }
3941 }
3942#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3943 if(pMac->scan.domainIdCurrent != domainId)
3944 {
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05303945 smsLog(pMac, LOGW, FL("Domain Changed Old %s (%d), new %s"),
3946 voss_DomainIdtoString(pMac->scan.domainIdCurrent),
3947 pMac->scan.domainIdCurrent,
3948 voss_DomainIdtoString(domainId));
Abhishek Singha306a442013-11-07 18:39:01 +05303949 status = WDA_SetRegDomain(pMac, domainId, eSIR_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07003950 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003951 if (status != eHAL_STATUS_SUCCESS)
3952 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003953 smsLog( pMac, LOGE, FL(" fail to set regId %d"), domainId );
Jeff Johnson295189b2012-06-20 16:38:30 -07003954 }
3955 pMac->scan.domainIdCurrent = domainId;
Kiet Lam6c583332013-10-14 05:37:09 +05303956#ifndef CONFIG_ENABLE_LINUX_REG
Kiet Lambb14e952013-11-19 14:58:29 +05303957 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.base20MHzChannels,
3958 pMac->scan.countryCodeCurrent, eANI_BOOLEAN_TRUE );
Kiet Lam6c583332013-10-14 05:37:09 +05303959#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07003960 // switch to active scans using this new channel list
3961 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
3962 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_TRUE;
3963 pMac->scan.f11dInfoReset = eANI_BOOLEAN_FALSE;
3964 }
3965 }
3966
3967 } while( 0 );
3968
3969 return;
3970}
3971
3972
3973
3974tANI_BOOLEAN csrSave11dCountryString( tpAniSirGlobal pMac, tANI_U8 *pCountryCode,
3975 tANI_BOOLEAN fForce)
3976{
3977 tANI_BOOLEAN fCountryStringChanged = FALSE, fUnknownCountryCode = FALSE;
3978 tANI_U32 i;
Kiet Lam6c583332013-10-14 05:37:09 +05303979 v_REGDOMAIN_t regd;
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08003980 tANI_BOOLEAN fCountryNotPresentInDriver = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003981
3982 // convert to UPPER here so we are assured the strings are always in upper case.
3983 for( i = 0; i < 3; i++ )
3984 {
3985 pCountryCode[ i ] = (tANI_U8)csrToUpper( pCountryCode[ i ] );
3986 }
3987
3988 // Some of the 'old' Cisco 350 series AP's advertise NA as the country code (for North America ??).
3989 // NA is not a valid country code or domain so let's allow this by changing it to the proper
3990 // country code (which is US). We've also seen some NETGEAR AP's that have "XX " as the country code
3991 // with valid 2.4 GHz US channel information. If we cannot find the country code advertised in the
3992 // 11d information element, let's default to US.
Kiet Lam6c583332013-10-14 05:37:09 +05303993 if ( !HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(pMac,
3994 pCountryCode,
3995 &regd,
3996 COUNTRY_QUERY) ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003997 {
3998 // Check the enforcement first
3999 if( pMac->roam.configParam.fEnforceDefaultDomain || pMac->roam.configParam.fEnforceCountryCodeMatch )
4000 {
4001 fUnknownCountryCode = TRUE;
4002 }
4003 else
4004 {
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004005 fCountryNotPresentInDriver = TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004006 }
4007 }
Tushnim Bhattacharyyac3c1e8e2013-10-29 17:27:43 -07004008 //right now, even if we don't find the CC in driver we set to world. Making
4009 //sure countryCode11d doesn't get updated with the invalid CC, instead
4010 //reflect the world CC
4011 else if (REGDOMAIN_WORLD == regd)
4012 {
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004013 fCountryNotPresentInDriver = TRUE;
Tushnim Bhattacharyyac3c1e8e2013-10-29 17:27:43 -07004014 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004015
4016 // We've seen some of the AP's improperly put a 0 for the third character of the country code.
4017 // spec says valid charcters are 'O' (for outdoor), 'I' for Indoor, or ' ' (space; for either).
4018 // if we see a 0 in this third character, let's change it to a ' '.
4019 if ( 0 == pCountryCode[ 2 ] )
4020 {
4021 pCountryCode[ 2 ] = ' ';
4022 }
4023
4024 if( !fUnknownCountryCode )
4025 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304026 fCountryStringChanged = (!vos_mem_compare(pMac->scan.countryCode11d, pCountryCode, 2));
Jeff Johnson295189b2012-06-20 16:38:30 -07004027
4028
4029 if(( 0 == pMac->scan.countryCode11d[ 0 ] && 0 == pMac->scan.countryCode11d[ 1 ] )
4030 || (fForce))
4031 {
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004032 if (!fCountryNotPresentInDriver)
4033 {
4034 // this is the first .11d information
4035 vos_mem_copy(pMac->scan.countryCode11d, pCountryCode,
Kiet Lam64c1b492013-07-12 13:56:44 +05304036 sizeof( pMac->scan.countryCode11d ));
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08004037
4038 }
4039 else
4040 {
4041 pMac->scan.countryCode11d[0] = '0';
4042 pMac->scan.countryCode11d[1] = '0';
4043 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004044 }
4045 }
4046
4047 return( fCountryStringChanged );
4048}
4049
4050
4051void csrSaveChannelPowerForBand( tpAniSirGlobal pMac, tANI_BOOLEAN fPopulate5GBand )
4052{
4053 tANI_U32 Index, count=0;
4054 tSirMacChanInfo *pChanInfo;
4055 tSirMacChanInfo *pChanInfoStart;
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08004056 tANI_S32 maxChannelIndex;
4057
4058 maxChannelIndex = ( pMac->scan.base20MHzChannels.numChannels < WNI_CFG_VALID_CHANNEL_LIST_LEN ) ?
4059 pMac->scan.base20MHzChannels.numChannels : WNI_CFG_VALID_CHANNEL_LIST_LEN ;
Jeff Johnson295189b2012-06-20 16:38:30 -07004060
Kiet Lam64c1b492013-07-12 13:56:44 +05304061 pChanInfo = vos_mem_malloc(sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN);
4062 if ( NULL != pChanInfo )
Jeff Johnson295189b2012-06-20 16:38:30 -07004063 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304064 vos_mem_set(pChanInfo, sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004065 pChanInfoStart = pChanInfo;
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08004066 for (Index=0; Index < maxChannelIndex; Index++)
Jeff Johnson295189b2012-06-20 16:38:30 -07004067 {
4068 if ((fPopulate5GBand && (CSR_IS_CHANNEL_5GHZ(pMac->scan.defaultPowerTable[Index].chanId))) ||
4069 (!fPopulate5GBand && (CSR_IS_CHANNEL_24GHZ(pMac->scan.defaultPowerTable[Index].chanId))) )
4070 {
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08004071 if(count >= WNI_CFG_VALID_CHANNEL_LIST_LEN)
4072 {
4073 smsLog( pMac, LOGW, FL(" csrSaveChannelPowerForBand, count exceeded, count = %d"), count);
4074 break;
4075 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004076 pChanInfo->firstChanNum = pMac->scan.defaultPowerTable[Index].chanId;
4077 pChanInfo->numChannels = 1;
4078 pChanInfo->maxTxPower = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
4079 pChanInfo++;
4080 count++;
4081 }
4082 }
4083 if(count)
4084 {
4085 csrSaveToChannelPower2G_5G( pMac, count * sizeof(tSirMacChanInfo), pChanInfoStart );
4086 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304087 vos_mem_free(pChanInfoStart);
Jeff Johnson295189b2012-06-20 16:38:30 -07004088 }
4089}
4090
4091
4092void csrSetOppositeBandChannelInfo( tpAniSirGlobal pMac )
4093{
4094 tANI_BOOLEAN fPopulate5GBand = FALSE;
4095
4096 do
4097 {
4098 // if this is not a dual band product, then we don't need to set the opposite
4099 // band info. We only work in one band so no need to look in the other band.
4100 if ( !CSR_IS_OPEARTING_DUAL_BAND( pMac ) ) break;
4101 // if we found channel info on the 5.0 band and...
4102 if ( CSR_IS_CHANNEL_5GHZ( pMac->scan.channelOf11dInfo ) )
4103 {
4104 // and the 2.4 band is empty, then populate the 2.4 channel info
Kiet Lam8d985a02013-10-11 03:39:41 +05304105 if ( !csrLLIsListEmpty( &pMac->scan.channelPowerInfoList24, LL_ACCESS_LOCK ) ) break;
Jeff Johnson295189b2012-06-20 16:38:30 -07004106 fPopulate5GBand = FALSE;
4107 }
4108 else
4109 {
4110 // else, we found channel info in the 2.4 GHz band. If the 5.0 band is empty
4111 // set the 5.0 band info from the 2.4 country code.
Kiet Lam8d985a02013-10-11 03:39:41 +05304112 if ( !csrLLIsListEmpty( &pMac->scan.channelPowerInfoList5G, LL_ACCESS_LOCK ) ) break;
Jeff Johnson295189b2012-06-20 16:38:30 -07004113 fPopulate5GBand = TRUE;
4114 }
4115 csrSaveChannelPowerForBand( pMac, fPopulate5GBand );
4116
4117 } while( 0 );
4118}
4119
4120
4121tANI_BOOLEAN csrIsSupportedChannel(tpAniSirGlobal pMac, tANI_U8 channelId)
4122{
4123 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
4124 tANI_U32 i;
4125
4126 //Make sure it is a channel that is in our supported list.
4127 for ( i = 0; i < pMac->scan.baseChannels.numChannels; i++ )
4128 {
4129 if ( channelId == pMac->scan.baseChannels.channelList[i] )
4130 {
4131 fRet = eANI_BOOLEAN_TRUE;
4132 break;
4133 }
4134 }
4135
4136 //If it is configured to limit a set of the channels
4137 if( fRet && pMac->roam.configParam.fEnforce11dChannels )
4138 {
4139 fRet = eANI_BOOLEAN_FALSE;
4140 for ( i = 0; i < pMac->scan.base20MHzChannels.numChannels; i++ )
4141 {
4142 if ( channelId == pMac->scan.base20MHzChannels.channelList[i] )
4143 {
4144 fRet = eANI_BOOLEAN_TRUE;
4145 break;
4146 }
4147 }
4148 }
4149
4150 return (fRet);
4151}
4152
4153
4154
4155//bSize specify the buffer size of pChannelList
4156tANI_U8 csrGetChannelListFromChannelSet( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 bSize, tCsrChannelPowerInfo *pChannelSet )
4157{
4158 tANI_U8 i, j = 0, chnId;
4159
4160 bSize = CSR_MIN(bSize, pChannelSet->numChannels);
4161 for( i = 0; i < bSize; i++ )
4162 {
4163 chnId = (tANI_U8)(pChannelSet->firstChannel + ( i * pChannelSet->interChannelOffset ));
4164 if ( csrIsSupportedChannel( pMac, chnId ) )
4165 {
4166 pChannelList[j++] = chnId;
4167 }
4168 }
4169
4170 return (j);
4171}
4172
4173
4174
4175//bSize -- specify the buffer size of pChannelList
4176void csrConstructCurrentValidChannelList( tpAniSirGlobal pMac, tDblLinkList *pChannelSetList,
4177 tANI_U8 *pChannelList, tANI_U8 bSize, tANI_U8 *pNumChannels )
4178{
4179 tListElem *pEntry;
4180 tCsrChannelPowerInfo *pChannelSet;
4181 tANI_U8 numChannels;
4182 tANI_U8 *pChannels;
4183
4184 if( pChannelSetList && pChannelList && pNumChannels )
4185 {
4186 pChannels = pChannelList;
4187 *pNumChannels = 0;
4188 pEntry = csrLLPeekHead( pChannelSetList, LL_ACCESS_LOCK );
4189 while( pEntry )
4190 {
4191 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
4192 numChannels = csrGetChannelListFromChannelSet( pMac, pChannels, bSize, pChannelSet );
4193 pChannels += numChannels;
4194 *pNumChannels += numChannels;
4195 pEntry = csrLLNext( pChannelSetList, pEntry, LL_ACCESS_LOCK );
4196 }
4197 }
4198}
4199
4200
4201/*
4202 * 802.11D only: Gather 11d IE via beacon or Probe response and store them in pAdapter->channels11d
4203*/
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304204tANI_BOOLEAN csrLearnCountryInformation( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc,
4205 tDot11fBeaconIEs *pIes, tANI_BOOLEAN fForce)
Jeff Johnson295189b2012-06-20 16:38:30 -07004206{
Agarwal Ashish60a37ee2014-05-28 17:20:20 +05304207 eHalStatus status;
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304208 tANI_U8 *pCountryCodeSelected;
Jeff Johnson295189b2012-06-20 16:38:30 -07004209 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
4210 v_REGDOMAIN_t domainId;
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304211 tDot11fBeaconIEs *pIesLocal = pIes;
4212 tANI_BOOLEAN useVoting = eANI_BOOLEAN_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004213
Jeff Johnson295189b2012-06-20 16:38:30 -07004214 if (VOS_STA_SAP_MODE == vos_get_conparam ())
4215 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07004216
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304217 if ((NULL == pSirBssDesc) && (NULL == pIes))
4218 useVoting = eANI_BOOLEAN_TRUE;
4219
Jeff Johnson295189b2012-06-20 16:38:30 -07004220 do
4221 {
4222 // check if .11d support is enabled
4223 if( !csrIs11dSupported( pMac ) ) break;
Agarwal Ashish60a37ee2014-05-28 17:20:20 +05304224
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304225 if (eANI_BOOLEAN_FALSE == useVoting)
4226 {
4227 if( !pIesLocal &&
4228 (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
4229 pSirBssDesc, &pIesLocal))))
4230 {
4231 break;
4232 }
4233 // check if country information element is present
4234 if(!pIesLocal->Country.present)
4235 {
4236 //No country info
4237 break;
4238 }
4239
4240 if( HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry
4241 (pMac, pIesLocal->Country.country, &domainId,
4242 COUNTRY_QUERY)) &&
4243 ( domainId == REGDOMAIN_WORLD))
4244 {
4245 break;
4246 }
4247 } //useVoting == eANI_BOOLEAN_FALSE
4248
4249 if (eANI_BOOLEAN_FALSE == useVoting)
4250 pCountryCodeSelected = pIesLocal->Country.country;
4251 else
4252 pCountryCodeSelected = pMac->scan.countryCodeElected;
4253
Kiet Lam8d985a02013-10-11 03:39:41 +05304254 status = csrGetRegulatoryDomainForCountry(pMac,
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304255 pCountryCodeSelected, &domainId, COUNTRY_IE);
Kiet Lam8d985a02013-10-11 03:39:41 +05304256 if ( status != eHAL_STATUS_SUCCESS )
4257 {
4258 smsLog( pMac, LOGE, FL(" fail to get regId %d"), domainId );
4259 fRet = eANI_BOOLEAN_FALSE;
4260 break;
4261 }
Agarwal Ashish7693f2d2014-07-18 18:03:58 +05304262
4263 /* updating 11d Country Code with Country code selected. */
4264
4265 vos_mem_copy(pMac->scan.countryCode11d,
4266 pCountryCodeSelected,
4267 WNI_CFG_COUNTRY_CODE_LEN);
4268
Agarwal Ashish60a37ee2014-05-28 17:20:20 +05304269#ifndef CONFIG_ENABLE_LINUX_REG
Venkata Prathyusha Kuntupalli316247e2013-03-15 17:45:25 -07004270 // Checking for Domain Id change
4271 if ( domainId != pMac->scan.domainIdCurrent )
4272 {
Kiet Lam8d985a02013-10-11 03:39:41 +05304273 vos_mem_copy(pMac->scan.countryCode11d,
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304274 pCountryCodeSelected,
Kiet Lam8d985a02013-10-11 03:39:41 +05304275 sizeof( pMac->scan.countryCode11d ) );
4276 /* Set Current Country code and Current Regulatory domain */
4277 status = csrSetRegulatoryDomain(pMac, domainId, NULL);
4278 if (eHAL_STATUS_SUCCESS != status)
4279 {
4280 smsLog(pMac, LOGE, "Set Reg Domain Fail %d", status);
4281 fRet = eANI_BOOLEAN_FALSE;
4282 return fRet;
4283 }
4284 //csrSetRegulatoryDomain will fail if the country doesn't fit our domain criteria.
4285 vos_mem_copy(pMac->scan.countryCodeCurrent,
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304286 pCountryCodeSelected, WNI_CFG_COUNTRY_CODE_LEN);
Kiet Lam8d985a02013-10-11 03:39:41 +05304287 //Simply set it to cfg.
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304288 csrSetCfgCountryCode(pMac, pCountryCodeSelected);
Kiet Lam8d985a02013-10-11 03:39:41 +05304289
4290 /* overwrite the defualt country code */
4291 vos_mem_copy(pMac->scan.countryCodeDefault,
4292 pMac->scan.countryCodeCurrent,
4293 WNI_CFG_COUNTRY_CODE_LEN);
4294 /* Set Current RegDomain */
Abhishek Singha306a442013-11-07 18:39:01 +05304295 status = WDA_SetRegDomain(pMac, domainId, eSIR_TRUE);
Kiet Lam8d985a02013-10-11 03:39:41 +05304296 if ( status != eHAL_STATUS_SUCCESS )
4297 {
4298 smsLog( pMac, LOGE, FL(" fail to Set regId %d"), domainId );
4299 fRet = eANI_BOOLEAN_FALSE;
4300 return fRet;
4301 }
4302 /* set to default domain ID */
Madan Mohan Koyyalamudi0e5922d2013-09-10 15:45:24 +05304303 pMac->scan.domainIdCurrent = domainId;
Kiet Lam8d985a02013-10-11 03:39:41 +05304304 /* get the channels based on new cc */
4305 status = csrInitGetChannels( pMac );
Jeff Johnson295189b2012-06-20 16:38:30 -07004306
Kiet Lam8d985a02013-10-11 03:39:41 +05304307 if ( status != eHAL_STATUS_SUCCESS )
4308 {
4309 smsLog( pMac, LOGE, FL(" fail to get Channels "));
4310 fRet = eANI_BOOLEAN_FALSE;
4311 return fRet;
4312 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004313
Kiet Lam8d985a02013-10-11 03:39:41 +05304314 /* reset info based on new cc, and we are done */
4315 csrResetCountryInformation(pMac, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
Agarwal Ashishfaef6692014-01-29 19:40:30 +05304316 /* Regulatory Domain Changed, Purge Only scan result
4317 * which does not have channel number belong to 11d
4318 * channel list
4319 */
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05304320 csrScanFilterResults(pMac);
Kiet Lam8d985a02013-10-11 03:39:41 +05304321 }
Kiet Lam6c583332013-10-14 05:37:09 +05304322#endif
4323 fRet = eANI_BOOLEAN_TRUE;
4324
Jeff Johnson295189b2012-06-20 16:38:30 -07004325 } while( 0 );
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304326
4327 if( !pIes && pIesLocal )
4328 {
4329 //locally allocated
4330 vos_mem_free(pIesLocal);
4331 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004332
4333 return( fRet );
4334}
4335
4336
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004337static void csrSaveScanResults( tpAniSirGlobal pMac, tANI_U8 reason )
Jeff Johnson295189b2012-06-20 16:38:30 -07004338{
4339 // initialize this to FALSE. profMoveInterimScanResultsToMainList() routine
4340 // will set this to the channel where an .11d beacon is seen
4341 pMac->scan.channelOf11dInfo = 0;
4342 // if we get any ambiguous .11d information then this will be set to TRUE
4343 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
4344 //Tush
4345 // if we get any ambiguous .11d information, then this will be set to TRUE
4346 // only if the applied 11d info could be found in one of the scan results
4347 pMac->scan.fCurrent11dInfoMatch = eANI_BOOLEAN_FALSE;
4348 // move the scan results from interim list to the main scan list
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004349 csrMoveTempScanResultsToMainList( pMac, reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07004350}
4351
4352
4353void csrReinitScanCmd(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4354{
4355 switch (pCommand->u.scanCmd.reason)
4356 {
4357 case eCsrScanSetBGScanParam:
4358 case eCsrScanAbortBgScan:
4359 if(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList)
4360 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304361 vos_mem_free(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList);
Jeff Johnson295189b2012-06-20 16:38:30 -07004362 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
4363 }
4364 break;
4365 case eCsrScanBGScanAbort:
4366 case eCsrScanBGScanEnable:
4367 case eCsrScanGetScanChnInfo:
4368 break;
4369 case eCsrScanAbortNormalScan:
4370 default:
4371 csrScanFreeRequest(pMac, &pCommand->u.scanCmd.u.scanRequest);
4372 break;
4373 }
4374 if(pCommand->u.scanCmd.pToRoamProfile)
4375 {
4376 csrReleaseProfile(pMac, pCommand->u.scanCmd.pToRoamProfile);
Kiet Lam64c1b492013-07-12 13:56:44 +05304377 vos_mem_free(pCommand->u.scanCmd.pToRoamProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07004378 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304379 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004380}
4381
4382
4383tANI_BOOLEAN csrGetRemainingChannelsFor11dScan( tpAniSirGlobal pMac, tANI_U8 *pChannels, tANI_U8 *pcChannels )
4384{
4385 tANI_U32 index11dChannels, index;
4386 tANI_U32 indexCurrentChannels;
4387 tANI_BOOLEAN fChannelAlreadyScanned;
4388 tANI_U32 len = sizeof(pMac->roam.validChannelList);
4389
4390 *pcChannels = 0;
4391 if ( CSR_IS_11D_INFO_FOUND(pMac) && csrRoamIsChannelValid(pMac, pMac->scan.channelOf11dInfo) )
4392 {
4393 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
4394 {
4395 //Find the channel index where we found the 11d info
4396 for(index = 0; index < len; index++)
4397 {
4398 if(pMac->scan.channelOf11dInfo == pMac->roam.validChannelList[index])
4399 break;
4400 }
4401 //check whether we found the channel index
4402 if(index < len)
4403 {
4404 // Now, look through the 11d channel list and create a list of all channels in the 11d list that are
4405 // NOT in the current channel list. This gives us a list of the new channels that have not been
4406 // scanned. We'll scan this new list so we have a complete set of scan results on all of the domain channels
4407 // initially.
4408 for ( index11dChannels = 0; index11dChannels < pMac->scan.channels11d.numChannels; index11dChannels++ )
4409 {
4410 fChannelAlreadyScanned = eANI_BOOLEAN_FALSE;
4411
4412 for( indexCurrentChannels = 0; indexCurrentChannels < index; indexCurrentChannels++ )
4413 {
4414 if ( pMac->roam.validChannelList[ indexCurrentChannels ] == pMac->scan.channels11d.channelList[ index11dChannels ] )
4415 {
4416 fChannelAlreadyScanned = eANI_BOOLEAN_TRUE;
4417 break;
4418 }
4419 }
4420
4421 if ( !fChannelAlreadyScanned )
4422 {
4423 pChannels[ *pcChannels ] = pMac->scan.channels11d.channelList[ index11dChannels ];
4424 ( *pcChannels )++;
4425 }
4426 }
4427 }
4428 }//GetCFG
4429 }
4430 return( *pcChannels );
4431}
4432
4433
4434eCsrScanCompleteNextCommand csrScanGetNextCommandState( tpAniSirGlobal pMac, tSmeCmd *pCommand, tANI_BOOLEAN fSuccess )
4435{
4436 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
4437
4438 switch( pCommand->u.scanCmd.reason )
4439 {
4440 case eCsrScan11d1:
4441 NextCommand = (fSuccess) ? eCsrNext11dScan1Success : eCsrNext11dScan1Failure;
4442 break;
4443 case eCsrScan11d2:
4444 NextCommand = (fSuccess) ? eCsrNext11dScan2Success : eCsrNext11dScan2Failure;
4445 break;
4446 case eCsrScan11dDone:
4447 NextCommand = eCsrNext11dScanComplete;
4448 break;
4449 case eCsrScanLostLink1:
4450 NextCommand = (fSuccess) ? eCsrNextLostLinkScan1Success : eCsrNextLostLinkScan1Failed;
4451 break;
4452 case eCsrScanLostLink2:
4453 NextCommand = (fSuccess) ? eCsrNextLostLinkScan2Success : eCsrNextLostLinkScan2Failed;
4454 break;
4455 case eCsrScanLostLink3:
4456 NextCommand = (fSuccess) ? eCsrNextLostLinkScan3Success : eCsrNextLostLinkScan3Failed;
4457 break;
4458 case eCsrScanForSsid:
4459 NextCommand = (fSuccess) ? eCsrNexteScanForSsidSuccess : eCsrNexteScanForSsidFailure;
4460 break;
4461 case eCsrScanForCapsChange:
4462 NextCommand = eCsrNextCapChangeScanComplete; //don't care success or not
4463 break;
4464 case eCsrScanIdleScan:
4465 NextCommand = eCsrNextIdleScanComplete;
4466 break;
4467 default:
4468 NextCommand = eCsrNextScanNothing;
4469 break;
4470 }
4471 return( NextCommand );
4472}
4473
4474
4475//Return whether the pCommand is finished.
4476tANI_BOOLEAN csrHandleScan11d1Failure(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4477{
4478 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
4479
4480 //Apply back the default setting and passively scan one more time.
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004481 csrResetCountryInformation(pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07004482 pCommand->u.scanCmd.reason = eCsrScan11d2;
4483 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
4484 {
4485 fRet = eANI_BOOLEAN_FALSE;
4486 }
4487
4488 return (fRet);
4489}
4490
4491
4492tANI_BOOLEAN csrHandleScan11dSuccess(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4493{
4494 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
4495 tANI_U8 *pChannels;
4496 tANI_U8 cChannels;
4497
Kiet Lam64c1b492013-07-12 13:56:44 +05304498 pChannels = vos_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
4499 if ( NULL != pChannels )
Jeff Johnson295189b2012-06-20 16:38:30 -07004500 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304501 vos_mem_set(pChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004502 if ( csrGetRemainingChannelsFor11dScan( pMac, pChannels, &cChannels ) )
4503 {
4504 pCommand->u.scanCmd.reason = eCsrScan11dDone;
4505 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
4506 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304507 vos_mem_free(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -07004508 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004509 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304510 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(cChannels);
4511 if ( NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07004512 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304513 vos_mem_copy(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
4514 pChannels, cChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07004515 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = cChannels;
4516 pCommand->u.scanCmd.u.scanRequest.requestType = eCSR_SCAN_REQUEST_FULL_SCAN;
4517 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
4518 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
4519 {
4520 //Reuse the same command buffer
4521 fRet = eANI_BOOLEAN_FALSE;
4522 }
4523 }
4524 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304525 vos_mem_free(pChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07004526 }
4527
4528 return (fRet);
4529}
4530
4531//Return whether the command should be removed
4532tANI_BOOLEAN csrScanComplete( tpAniSirGlobal pMac, tSirSmeScanRsp *pScanRsp )
4533{
4534 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
4535 tListElem *pEntry;
4536 tSmeCmd *pCommand;
4537 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
4538 tANI_BOOLEAN fSuccess;
4539
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05304540 if (pMac->fScanOffload)
4541 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
4542 else
4543 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07004544
4545 if ( pEntry )
4546 {
4547 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
4548
4549 // If the head of the queue is Active and it is a SCAN command, remove
4550 // and put this on the Free queue.
4551 if ( eSmeCommandScan == pCommand->command )
4552 {
4553 tANI_U32 sessionId = pCommand->sessionId;
4554
4555 if(eSIR_SME_SUCCESS != pScanRsp->statusCode)
4556 {
4557 fSuccess = eANI_BOOLEAN_FALSE;
4558 }
4559 else
4560 {
4561 //pMac->scan.tempScanResults is not empty meaning the scan found something
4562 //This check only valid here because csrSaveScanresults is not yet called
4563 fSuccess = (!csrLLIsListEmpty(&pMac->scan.tempScanResults, LL_ACCESS_LOCK));
4564 }
Srinivas, Dasari187ca4e2014-02-07 12:40:09 +05304565 if (pCommand->u.scanCmd.abortScanDueToBandChange)
4566 {
4567 /*
4568 * Scan aborted due to band change
4569 * The scan results need to be flushed
4570 */
4571 if (pCommand->u.scanCmd.callback
4572 != pMac->scan.callback11dScanDone)
4573 {
4574 smsLog(pMac, LOG1, FL("Filtering the scan results as the "
4575 "results may belong to wrong band"));
4576 csrScanFilterResults(pMac);
4577 }
4578 else
4579 {
4580 smsLog(pMac, LOG1, FL("11d_scan_done will flush the scan"
4581 " results"));
4582 }
4583 pCommand->u.scanCmd.abortScanDueToBandChange
4584 = eANI_BOOLEAN_FALSE;
4585 }
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004586 csrSaveScanResults(pMac, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07004587
4588#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4589 {
4590 vos_log_scan_pkt_type *pScanLog = NULL;
4591 tScanResultHandle hScanResult;
4592 tCsrScanResultInfo *pScanResult;
4593 tDot11fBeaconIEs *pIes;
4594 int n = 0, c = 0;
4595
4596 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
4597 if(pScanLog)
4598 {
4599 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
4600 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
4601 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
4602 {
4603 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_RSP;
4604 }
4605 else
4606 {
4607 if( eSIR_PASSIVE_SCAN != pMac->scan.curScanType )
4608 {
4609 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_RSP;
4610 }
4611 else
4612 {
4613 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_RSP;
4614 }
4615 }
4616 if(eSIR_SME_SUCCESS == pScanRsp->statusCode)
4617 {
4618 if(HAL_STATUS_SUCCESS(csrScanGetResult(pMac, NULL, &hScanResult)))
4619 {
4620 while(((pScanResult = csrScanResultGetNext(pMac, hScanResult)) != NULL))
4621 {
4622 if( n < VOS_LOG_MAX_NUM_BSSID )
4623 {
4624 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pScanResult->BssDescriptor, &pIes)))
4625 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004626 smsLog(pMac, LOGE, FL(" fail to parse IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07004627 break;
4628 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304629 vos_mem_copy(pScanLog->bssid[n],
4630 pScanResult->BssDescriptor.bssId, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07004631 if(pIes && pIes->SSID.present && VOS_LOG_MAX_SSID_SIZE >= pIes->SSID.num_ssid)
4632 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304633 vos_mem_copy(pScanLog->ssid[n],
4634 pIes->SSID.ssid, pIes->SSID.num_ssid);
Jeff Johnson295189b2012-06-20 16:38:30 -07004635 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304636 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07004637 n++;
4638 }
4639 c++;
4640 }
4641 pScanLog->numSsid = (v_U8_t)n;
4642 pScanLog->totalSsid = (v_U8_t)c;
4643 csrScanResultPurge(pMac, hScanResult);
4644 }
4645 }
4646 else
4647 {
4648 pScanLog->status = WLAN_SCAN_STATUS_FAILURE;
4649 }
4650 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
4651 }
4652 }
4653#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4654
4655 NextCommand = csrScanGetNextCommandState(pMac, pCommand, fSuccess);
4656 //We reuse the command here instead reissue a new command
4657 switch(NextCommand)
4658 {
4659 case eCsrNext11dScan1Success:
4660 case eCsrNext11dScan2Success:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004661 smsLog( pMac, LOG2, FL("11dScan1/3 produced results. Reissue Active scan..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004662 // if we found country information, no need to continue scanning further, bail out
4663 fRemoveCommand = eANI_BOOLEAN_TRUE;
4664 NextCommand = eCsrNext11dScanComplete;
4665 break;
4666 case eCsrNext11dScan1Failure:
4667 //We are not done yet. 11d scan fail once. We will try to reset anything and do it over again
4668 //The only meaningful thing for this retry is that we cannot find 11d information after a reset so
4669 //we clear the "old" 11d info and give it once more chance
4670 fRemoveCommand = csrHandleScan11d1Failure(pMac, pCommand);
4671 if(fRemoveCommand)
4672 {
4673 NextCommand = eCsrNext11dScanComplete;
4674 }
4675 break;
4676 case eCsrNextLostLinkScan1Success:
4677 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink1)))
4678 {
4679 csrScanHandleFailedLostlink1(pMac, sessionId);
4680 }
4681 break;
4682 case eCsrNextLostLinkScan2Success:
4683 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink2)))
4684 {
4685 csrScanHandleFailedLostlink2(pMac, sessionId);
4686 }
4687 break;
4688 case eCsrNextLostLinkScan3Success:
4689 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink3)))
4690 {
4691 csrScanHandleFailedLostlink3(pMac, sessionId);
4692 }
4693 break;
4694 case eCsrNextLostLinkScan1Failed:
4695 csrScanHandleFailedLostlink1(pMac, sessionId);
4696 break;
4697 case eCsrNextLostLinkScan2Failed:
4698 csrScanHandleFailedLostlink2(pMac, sessionId);
4699 break;
4700 case eCsrNextLostLinkScan3Failed:
4701 csrScanHandleFailedLostlink3(pMac, sessionId);
4702 break;
4703 case eCsrNexteScanForSsidSuccess:
4704 csrScanHandleSearchForSSID(pMac, pCommand);
4705 break;
4706 case eCsrNexteScanForSsidFailure:
4707 csrScanHandleSearchForSSIDFailure(pMac, pCommand);
4708 break;
4709 case eCsrNextIdleScanComplete:
4710 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
4711 break;
4712 case eCsrNextCapChangeScanComplete:
4713 csrScanHandleCapChangeScanComplete(pMac, sessionId);
4714 break;
4715 default:
4716
4717 break;
4718 }
4719 }
4720 else
4721 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004722 smsLog( pMac, LOGW, FL("Scan Completion called but SCAN command is not ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004723 fRemoveCommand = eANI_BOOLEAN_FALSE;
4724 }
4725 }
4726 else
4727 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004728 smsLog( pMac, LOGW, FL("Scan Completion called but NO commands are ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004729 fRemoveCommand = eANI_BOOLEAN_FALSE;
4730 }
4731
4732 return( fRemoveCommand );
4733}
4734
4735
4736
4737static void csrScanRemoveDupBssDescriptionFromInterimList( tpAniSirGlobal pMac,
4738 tSirBssDescription *pSirBssDescr,
4739 tDot11fBeaconIEs *pIes)
4740{
4741 tListElem *pEntry;
4742 tCsrScanResult *pCsrBssDescription;
4743
4744 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
4745 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
4746 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
4747 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
4748 while( pEntry )
4749 {
4750 pCsrBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
4751
4752 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
4753 // matches
4754
4755 if ( csrIsDuplicateBssDescription( pMac, &pCsrBssDescription->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07004756 pSirBssDescr, pIes, FALSE ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07004757 {
4758 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
4759 ((tANI_S32)pCsrBssDescription->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
4760
4761 // Remove the 'old' entry from the list....
4762 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK ) )
4763 {
4764 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pCsrBssDescription->Result.BssDescriptor);
4765 // we need to free the memory associated with this node
4766 csrFreeScanResultEntry( pMac, pCsrBssDescription );
4767 }
4768
4769 // If we found a match, we can stop looking through the list.
4770 break;
4771 }
4772
4773 pEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK );
4774 }
4775}
4776
4777
4778
4779//Caller allocated memory pfNewBssForConn to return whether new candidate for
4780//current connection is found. Cannot be NULL
4781tCsrScanResult *csrScanSaveBssDescriptionToInterimList( tpAniSirGlobal pMac,
4782 tSirBssDescription *pBSSDescription,
4783 tDot11fBeaconIEs *pIes)
4784{
4785 tCsrScanResult *pCsrBssDescription = NULL;
4786 tANI_U32 cbBSSDesc;
4787 tANI_U32 cbAllocated;
Jeff Johnson295189b2012-06-20 16:38:30 -07004788
4789 // figure out how big the BSS description is (the BSSDesc->length does NOT
4790 // include the size of the length field itself).
4791 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
4792
4793 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
4794
Kiet Lam64c1b492013-07-12 13:56:44 +05304795 pCsrBssDescription = vos_mem_malloc(cbAllocated);
4796 if ( NULL != pCsrBssDescription )
Jeff Johnson295189b2012-06-20 16:38:30 -07004797 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304798 vos_mem_set(pCsrBssDescription, cbAllocated, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004799 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Kiet Lam64c1b492013-07-12 13:56:44 +05304800 vos_mem_copy(&pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc );
Jeff Johnson295189b2012-06-20 16:38:30 -07004801 //Save SSID separately for later use
4802 if( pIes->SSID.present && !csrIsNULLSSID(pIes->SSID.ssid, pIes->SSID.num_ssid) )
4803 {
4804 //SSID not hidden
Madan Mohan Koyyalamudi4e31b132012-11-02 13:13:52 -07004805 tANI_U32 len = pIes->SSID.num_ssid;
Jeff Johnson295189b2012-06-20 16:38:30 -07004806 if (len > SIR_MAC_MAX_SSID_LENGTH)
4807 {
4808 // truncate to fit in our struct
4809 len = SIR_MAC_MAX_SSID_LENGTH;
4810 }
4811 pCsrBssDescription->Result.ssId.length = len;
4812 pCsrBssDescription->Result.timer = vos_timer_get_system_time();
Kiet Lam64c1b492013-07-12 13:56:44 +05304813 vos_mem_copy(pCsrBssDescription->Result.ssId.ssId, pIes->SSID.ssid, len);
Jeff Johnson295189b2012-06-20 16:38:30 -07004814 }
4815 csrLLInsertTail( &pMac->scan.tempScanResults, &pCsrBssDescription->Link, LL_ACCESS_LOCK );
4816 }
4817
4818 return( pCsrBssDescription );
4819}
4820
4821
4822
4823
4824tANI_BOOLEAN csrIsDuplicateBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc1,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07004825 tSirBssDescription *pSirBssDesc2, tDot11fBeaconIEs *pIes2, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07004826{
4827 tANI_BOOLEAN fMatch = FALSE;
4828 tSirMacCapabilityInfo *pCap1, *pCap2;
4829 tDot11fBeaconIEs *pIes1 = NULL;
Jeff Johnsone7245742012-09-05 17:12:55 -07004830 tDot11fBeaconIEs *pIesTemp = pIes2;
Jeff Johnson295189b2012-06-20 16:38:30 -07004831
4832 pCap1 = (tSirMacCapabilityInfo *)&pSirBssDesc1->capabilityInfo;
4833 pCap2 = (tSirMacCapabilityInfo *)&pSirBssDesc2->capabilityInfo;
4834 if(pCap1->ess == pCap2->ess)
4835 {
4836 if (pCap1->ess &&
Jeff Johnsone7245742012-09-05 17:12:55 -07004837 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId)&&
Abhishek Singhe3fa11f2014-05-13 11:11:10 +05304838 (fForced || (vos_chan_to_band(pSirBssDesc1->channelId) == vos_chan_to_band((pSirBssDesc2->channelId)))))
Jeff Johnson295189b2012-06-20 16:38:30 -07004839 {
4840 fMatch = TRUE;
Jeff Johnsone7245742012-09-05 17:12:55 -07004841 // Check for SSID match, if exists
4842 do
4843 {
4844 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
4845 {
4846 break;
4847 }
4848 if( NULL == pIesTemp )
4849 {
4850 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
4851 {
4852 break;
4853 }
4854 }
4855 if(pIes1->SSID.present && pIesTemp->SSID.present)
4856 {
4857 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
4858 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
4859 }
4860 }while(0);
4861
Jeff Johnson295189b2012-06-20 16:38:30 -07004862 }
4863 else if (pCap1->ibss && (pSirBssDesc1->channelId == pSirBssDesc2->channelId))
4864 {
Jeff Johnson295189b2012-06-20 16:38:30 -07004865
4866 do
4867 {
4868 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
4869 {
4870 break;
4871 }
4872 if( NULL == pIesTemp )
4873 {
4874 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
4875 {
4876 break;
4877 }
4878 }
4879 //Same channel cannot have same SSID for different IBSS
4880 if(pIes1->SSID.present && pIesTemp->SSID.present)
4881 {
4882 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
4883 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
4884 }
4885 }while(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004886 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004887 /* In case of P2P devices, ess and ibss will be set to zero */
4888 else if (!pCap1->ess &&
4889 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId))
4890 {
4891 fMatch = TRUE;
4892 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004893 }
4894
4895 if(pIes1)
4896 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304897 vos_mem_free(pIes1);
Jeff Johnson295189b2012-06-20 16:38:30 -07004898 }
Jeff Johnsone7245742012-09-05 17:12:55 -07004899
4900 if( (NULL == pIes2) && pIesTemp )
4901 {
4902 //locally allocated
Kiet Lam64c1b492013-07-12 13:56:44 +05304903 vos_mem_free(pIesTemp);
Jeff Johnsone7245742012-09-05 17:12:55 -07004904 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004905
4906 return( fMatch );
4907}
4908
4909
4910tANI_BOOLEAN csrIsNetworkTypeEqual( tSirBssDescription *pSirBssDesc1, tSirBssDescription *pSirBssDesc2 )
4911{
4912 return( pSirBssDesc1->nwType == pSirBssDesc2->nwType );
4913}
4914
4915
4916//to check whether the BSS matches the dot11Mode
4917static tANI_BOOLEAN csrScanIsBssAllowed(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
4918 tDot11fBeaconIEs *pIes)
4919{
4920 tANI_BOOLEAN fAllowed = eANI_BOOLEAN_FALSE;
4921 eCsrPhyMode phyMode;
4922
4923 if(HAL_STATUS_SUCCESS(csrGetPhyModeFromBss(pMac, pBssDesc, &phyMode, pIes)))
4924 {
4925 switch(pMac->roam.configParam.phyMode)
4926 {
4927 case eCSR_DOT11_MODE_11b:
4928 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
4929 break;
4930 case eCSR_DOT11_MODE_11g:
4931 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
4932 break;
4933 case eCSR_DOT11_MODE_11g_ONLY:
4934 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11g == phyMode);
4935 break;
4936 case eCSR_DOT11_MODE_11a:
4937 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11b != phyMode) && (eCSR_DOT11_MODE_11g != phyMode));
4938 break;
4939 case eCSR_DOT11_MODE_11n_ONLY:
4940 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11n == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
4941 break;
Jeff Johnsone7245742012-09-05 17:12:55 -07004942
4943#ifdef WLAN_FEATURE_11AC
4944 case eCSR_DOT11_MODE_11ac_ONLY:
4945 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11ac == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
4946 break;
4947#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004948 case eCSR_DOT11_MODE_11b_ONLY:
4949 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11b == phyMode);
4950 break;
4951 case eCSR_DOT11_MODE_11a_ONLY:
4952 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a == phyMode);
4953 break;
4954 case eCSR_DOT11_MODE_11n:
Jeff Johnsone7245742012-09-05 17:12:55 -07004955#ifdef WLAN_FEATURE_11AC
4956 case eCSR_DOT11_MODE_11ac:
4957#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004958 case eCSR_DOT11_MODE_TAURUS:
4959 default:
4960 fAllowed = eANI_BOOLEAN_TRUE;
4961 break;
4962 }
4963 }
4964
4965 return (fAllowed);
4966}
4967
4968
4969
4970//Return pIes to caller for future use when returning TRUE.
4971static tANI_BOOLEAN csrScanValidateScanResult( tpAniSirGlobal pMac, tANI_U8 *pChannels,
4972 tANI_U8 numChn, tSirBssDescription *pBssDesc,
4973 tDot11fBeaconIEs **ppIes )
4974{
4975 tANI_BOOLEAN fValidChannel = FALSE;
4976 tDot11fBeaconIEs *pIes = NULL;
4977 tANI_U8 index;
4978
4979 for( index = 0; index < numChn; index++ )
4980 {
4981 // This check relies on the fact that a single BSS description is returned in each
4982 // ScanRsp call, which is the way LIM implemented the scan req/rsp funtions. We changed
4983 // to this model when we ran with a large number of APs. If this were to change, then
4984 // this check would have to mess with removing the bssDescription from somewhere in an
4985 // arbitrary index in the bssDescription array.
4986 if ( pChannels[ index ] == pBssDesc->channelId )
4987 {
4988 fValidChannel = TRUE;
4989 break;
4990 }
4991 }
4992 *ppIes = NULL;
4993 if(fValidChannel)
4994 {
4995 if( HAL_STATUS_SUCCESS( csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIes) ) )
4996 {
4997 fValidChannel = csrScanIsBssAllowed(pMac, pBssDesc, pIes);
4998 if( fValidChannel )
4999 {
5000 *ppIes = pIes;
5001 }
5002 else
5003 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305004 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07005005 }
5006 }
5007 else
5008 {
5009 fValidChannel = FALSE;
5010 }
5011 }
5012
5013 return( fValidChannel );
5014}
5015
5016
5017//Return whether last scan result is received
5018static tANI_BOOLEAN csrScanProcessScanResults( tpAniSirGlobal pMac, tSmeCmd *pCommand,
5019 tSirSmeScanRsp *pScanRsp, tANI_BOOLEAN *pfRemoveCommand )
5020{
5021 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE, fRemoveCommand = eANI_BOOLEAN_FALSE;
5022 tDot11fBeaconIEs *pIes = NULL;
5023 tANI_U32 cbParsed;
5024 tSirBssDescription *pSirBssDescription;
5025 tANI_U32 cbBssDesc;
5026 tANI_U32 cbScanResult = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription )
5027 + sizeof(tSirBssDescription); //We need at least one CB
5028
5029 // don't consider the scan rsp to be valid if the status code is Scan Failure. Scan Failure
5030 // is returned when the scan could not find anything. so if we get scan failure return that
5031 // the scan response is invalid. Also check the lenght in the scan result for valid scan
5032 // BssDescriptions....
5033 do
5034 {
5035 if ( ( cbScanResult <= pScanRsp->length ) &&
5036 (( eSIR_SME_SUCCESS == pScanRsp->statusCode ) ||
5037 ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW == pScanRsp->statusCode ) ) )
5038 {
5039 tANI_U8 *pChannelList = NULL;
5040 tANI_U8 cChannels = 0;
5041
5042 //Different scan type can reach this point, we need to distinguish it
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005043#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5044 if( eCsrScanGetLfrResult == pCommand->u.scanCmd.reason )
5045 {
5046 pChannelList = NULL;
5047 cChannels = 0;
5048 }
5049 else
5050#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005051 if( eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason )
5052 {
5053 //eCsrScanSetBGScanParam uses different structure
5054 tCsrBGScanRequest *pBgScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
5055
5056 cChannels = pBgScanReq->ChannelInfo.numOfChannels;
5057 pChannelList = pBgScanReq->ChannelInfo.ChannelList;
5058 }
5059 else
5060 {
5061 //the rest use generic scan request
5062 cChannels = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
5063 pChannelList = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
5064 }
5065
5066 // if the scan result is not on one of the channels in the Valid channel list, then it
5067 // must have come from an AP on an overlapping channel (in the 2.4GHz band). In this case,
5068 // let's drop the scan result.
5069 //
5070 // The other situation is where the scan request is for a scan on a particular channel set
5071 // and the scan result is from a
5072
5073 // if the NumChannels is 0, then we are supposed to be scanning all channels. Use the full channel
5074 // list as the 'valid' channel list. Otherwise, use the specific channel list in the scan parms
5075 // as the valid channels.
5076 if ( 0 == cChannels )
5077 {
5078 tANI_U32 len = sizeof(pMac->roam.validChannelList);
5079
5080 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
5081 {
5082 pChannelList = pMac->roam.validChannelList;
5083 cChannels = (tANI_U8)len;
5084 }
5085 else
5086 {
5087 //Cannot continue
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005088 smsLog( pMac, LOGE, "CSR: Processing internal SCAN results...csrGetCfgValidChannels failed" );
Jeff Johnson295189b2012-06-20 16:38:30 -07005089 break;
5090 }
5091 }
5092
5093 smsLog( pMac, LOG2, "CSR: Processing internal SCAN results..." );
5094 cbParsed = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription );
5095 pSirBssDescription = pScanRsp->bssDescription;
5096 while( cbParsed < pScanRsp->length )
5097 {
5098 if ( csrScanValidateScanResult( pMac, pChannelList, cChannels, pSirBssDescription, &pIes ) )
5099 {
5100 csrScanRemoveDupBssDescriptionFromInterimList(pMac, pSirBssDescription, pIes);
5101 csrScanSaveBssDescriptionToInterimList( pMac, pSirBssDescription, pIes );
5102 if( eSIR_PASSIVE_SCAN == pMac->scan.curScanType )
5103 {
5104 if( csrIs11dSupported( pMac) )
5105 {
5106 //Check whether the BSS is acceptable base on 11d info and our configs.
5107 if( csrMatchCountryCode( pMac, NULL, pIes ) )
5108 {
5109 //Double check whether the channel is acceptable by us.
5110 if( csrIsSupportedChannel( pMac, pSirBssDescription->channelId ) )
5111 {
5112 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
5113 }
5114 }
5115 }
5116 else
5117 {
5118 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
5119 }
5120 }
5121 //Free the resource
Kiet Lam64c1b492013-07-12 13:56:44 +05305122 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07005123 }
5124 // skip over the BSS description to the next one...
5125 cbBssDesc = pSirBssDescription->length + sizeof( pSirBssDescription->length );
5126
5127 cbParsed += cbBssDesc;
5128 pSirBssDescription = (tSirBssDescription *)((tANI_U8 *)pSirBssDescription + cbBssDesc );
5129
5130 } //while
5131 }
5132 else
5133 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005134 smsLog( pMac, LOGW, " Scanrsp fail (0x%08X), length = %d (expected %d)",
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08005135 pScanRsp->statusCode, pScanRsp->length, cbScanResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07005136 //HO bg scan/probe failed no need to try autonomously
5137 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
5138 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005139#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5140 eCsrScanGetLfrResult == pCommand->u.scanCmd.reason ||
5141#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005142 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
5143 {
5144 fRemoveCommand = eANI_BOOLEAN_TRUE;
5145 }
5146 }
5147 }while(0);
5148 if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
5149 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005150 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 -07005151 fRemoveCommand = csrScanComplete( pMac, pScanRsp );
5152 fRet = eANI_BOOLEAN_TRUE;
5153 }//if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
5154 if(pfRemoveCommand)
5155 {
5156 *pfRemoveCommand = fRemoveCommand;
5157 }
5158
5159#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305160 if (pMac->fScanOffload)
5161 return fRet;
5162
Jeff Johnson295189b2012-06-20 16:38:30 -07005163 if (!csrLLIsListEmpty( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK ))
5164 {
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005165 /* Pending scan commands in the list because the previous scan command
5166 * was split into a scan command on one channel + a scan command for all
5167 * remaining channels.
5168 *
5169 * Start timer to trigger processing of the next scan command.
Srikant Kuppa866893f2012-12-27 17:28:14 -08005170 * NOTE for LFR:
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305171 * Do not split scans if no concurrent infra connections are
Srikant Kuppa866893f2012-12-27 17:28:14 -08005172 * active and if the scan is a BG scan triggered by LFR (OR)
5173 * any scan if LFR is in the middle of a BG scan. Splitting
5174 * the scan is delaying the time it takes for LFR to find
5175 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005176 */
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305177 if ( (csrIsStaSessionConnected(pMac) &&
Srikant Kuppa866893f2012-12-27 17:28:14 -08005178#ifdef FEATURE_WLAN_LFR
5179 (csrIsConcurrentInfraConnected(pMac) ||
5180 ((pCommand->u.scanCmd.reason != eCsrScanBgScan) &&
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305181 (pMac->roam.neighborRoamInfo.neighborRoamState !=
Srikant Kuppa866893f2012-12-27 17:28:14 -08005182 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
5183#endif
5184 (pCommand->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305185 (csrIsP2pSessionConnected(pMac)) )
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005186 {
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005187 /* if active connected sessions present then continue to split scan
5188 * with specified interval between consecutive scans */
5189 csrSetDefaultScanTiming(pMac, pCommand->u.scanCmd.u.scanRequest.scanType, &(pCommand->u.scanCmd.u.scanRequest));
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05305190 vos_timer_start(&pMac->scan.hTimerStaApConcTimer,
5191 pCommand->u.scanCmd.u.scanRequest.restTime);
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005192 } else {
5193 /* if no connected sessions present then initiate next scan command immediately */
5194 /* minimum timer granularity is 10ms */
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05305195 vos_timer_start(&pMac->scan.hTimerStaApConcTimer, 10);
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005196 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005197 }
5198#endif
5199 return (fRet);
5200}
5201
5202
5203tANI_BOOLEAN csrScanIsWildCardScan( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5204{
5205 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
Kiet Lam64c1b492013-07-12 13:56:44 +05305206 tANI_BOOLEAN f = vos_mem_compare(pCommand->u.scanCmd.u.scanRequest.bssid,
5207 bssid, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07005208
5209 //It is not a wild card scan if the bssid is not broadcast and the number of SSID is 1.
5210 return ((tANI_BOOLEAN)( (f || (0xff == pCommand->u.scanCmd.u.scanRequest.bssid[0])) &&
5211 (pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs != 1) ));
5212}
5213
5214
5215eHalStatus csrScanSmeScanResponse( tpAniSirGlobal pMac, void *pMsgBuf )
5216{
5217 eHalStatus status = eHAL_STATUS_SUCCESS;
5218 tListElem *pEntry;
5219 tSmeCmd *pCommand;
5220 eCsrScanStatus scanStatus;
5221 tSirSmeScanRsp *pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
5222 tSmeGetScanChnRsp *pScanChnInfo;
5223 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
5224 eCsrScanReason reason = eCsrScanOther;
5225
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305226 if (pMac->fScanOffload)
5227 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList,
5228 LL_ACCESS_LOCK);
5229 else
5230 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07005231
5232 if ( pEntry )
5233 {
5234 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
5235 if ( eSmeCommandScan == pCommand->command )
5236 {
5237 scanStatus = (eSIR_SME_SUCCESS == pScanRsp->statusCode) ? eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
5238 reason = pCommand->u.scanCmd.reason;
5239 switch(pCommand->u.scanCmd.reason)
5240 {
5241 case eCsrScanAbortBgScan:
5242 case eCsrScanAbortNormalScan:
5243 case eCsrScanBGScanAbort:
5244 case eCsrScanBGScanEnable:
5245 break;
5246 case eCsrScanGetScanChnInfo:
5247 pScanChnInfo = (tSmeGetScanChnRsp *)pMsgBuf;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005248 /*
5249 * status code not available in tSmeGetScanChnRsp, so
5250 * by default considereing it to be success
5251 */
5252 scanStatus = eSIR_SME_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07005253 csrScanAgeResults(pMac, pScanChnInfo);
5254 break;
5255 case eCsrScanForCapsChange:
5256 csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand );
5257 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005258 case eCsrScanP2PFindPeer:
5259 scanStatus = ((eSIR_SME_SUCCESS == pScanRsp->statusCode) && (pScanRsp->length > 50)) ? eCSR_SCAN_FOUND_PEER : eCSR_SCAN_FAILURE;
5260 csrScanProcessScanResults( pMac, pCommand, pScanRsp, NULL );
5261 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005262 case eCsrScanSetBGScanParam:
5263 default:
5264 if(csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand ))
5265 {
5266 //Not to get channel info if the scan is not a wildcard scan because
5267 //it may cause scan results got aged out incorrectly.
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005268 if( csrScanIsWildCardScan( pMac, pCommand ) && (!pCommand->u.scanCmd.u.scanRequest.p2pSearch)
5269#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5270 && (pCommand->u.scanCmd.reason != eCsrScanGetLfrResult)
5271#endif
5272 )
Jeff Johnson295189b2012-06-20 16:38:30 -07005273 {
5274 //Get the list of channels scanned
Jeff Johnson32d95a32012-09-10 13:15:23 -07005275 if( pCommand->u.scanCmd.reason != eCsrScanUserRequest)
5276 {
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05305277 csrScanGetScanChnInfo(pMac, pCommand->sessionId,
5278 NULL, NULL);
Jeff Johnson32d95a32012-09-10 13:15:23 -07005279 }
5280 else
5281 {
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05305282 csrScanGetScanChnInfo(pMac,
5283 pCommand->sessionId,
5284 pCommand->u.scanCmd.pContext,
5285 pCommand->u.scanCmd.callback);
Jeff Johnson32d95a32012-09-10 13:15:23 -07005286 pCommand->u.scanCmd.callback = NULL;
5287 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005288 }
5289 }
5290 break;
5291 }//switch
5292 if(fRemoveCommand)
5293 {
5294
5295 csrReleaseScanCommand(pMac, pCommand, scanStatus);
5296
Srikant Kuppa866893f2012-12-27 17:28:14 -08005297 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005298 smeProcessPendingQueue( pMac );
5299 }
5300 else
5301 {
5302 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
5303 status = eHAL_STATUS_FAILURE;
5304 }
5305 }
5306 else
5307 {
5308 smsLog( pMac, LOGW, "CSR: Scan Completion called but NO commands are ACTIVE ..." );
5309 status = eHAL_STATUS_FAILURE;
5310 }
5311
5312 return (status);
5313}
5314
5315
5316
5317
5318tCsrScanResultInfo *csrScanResultGetFirst(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
5319{
5320 tListElem *pEntry;
5321 tCsrScanResult *pResult;
5322 tCsrScanResultInfo *pRet = NULL;
5323 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5324
5325 if(pResultList)
5326 {
5327 csrLLLock(&pResultList->List);
5328 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5329 if(pEntry)
5330 {
5331 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
5332 pRet = &pResult->Result;
5333 }
5334 pResultList->pCurEntry = pEntry;
5335 csrLLUnlock(&pResultList->List);
5336 }
5337
5338 return pRet;
5339}
5340
5341
5342tCsrScanResultInfo *csrScanResultGetNext(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
5343{
5344 tListElem *pEntry = NULL;
5345 tCsrScanResult *pResult = NULL;
5346 tCsrScanResultInfo *pRet = NULL;
5347 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5348
5349 if(pResultList)
5350 {
5351 csrLLLock(&pResultList->List);
5352 if(NULL == pResultList->pCurEntry)
5353 {
5354 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5355 }
5356 else
5357 {
5358 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
5359 }
5360 if(pEntry)
5361 {
5362 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
5363 pRet = &pResult->Result;
5364 }
5365 pResultList->pCurEntry = pEntry;
5366 csrLLUnlock(&pResultList->List);
5367 }
5368
5369 return pRet;
5370}
5371
5372
5373//This function moves the first BSS that matches the bssid to the head of the result
5374eHalStatus csrMoveBssToHeadFromBSSID(tpAniSirGlobal pMac, tCsrBssid *bssid, tScanResultHandle hScanResult)
5375{
5376 eHalStatus status = eHAL_STATUS_FAILURE;
5377 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5378 tCsrScanResult *pResult = NULL;
5379 tListElem *pEntry = NULL;
5380
5381 if(pResultList && bssid)
5382 {
5383 csrLLLock(&pResultList->List);
5384 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5385 while(pEntry)
5386 {
5387 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
Kiet Lam64c1b492013-07-12 13:56:44 +05305388 if (vos_mem_compare(bssid, pResult->Result.BssDescriptor.bssId, sizeof(tCsrBssid)))
Jeff Johnson295189b2012-06-20 16:38:30 -07005389 {
5390 status = eHAL_STATUS_SUCCESS;
5391 csrLLRemoveEntry(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
5392 csrLLInsertHead(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
5393 break;
5394 }
5395 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
5396 }
5397 csrLLUnlock(&pResultList->List);
5398 }
5399
5400 return (status);
5401}
5402
5403
5404//Remove the BSS if possible.
5405//Return -- TRUE == the BSS is remove. False == Fail to remove it
5406//This function is called when list lock is held. Be caution what functions it can call.
5407tANI_BOOLEAN csrScanAgeOutBss(tpAniSirGlobal pMac, tCsrScanResult *pResult)
5408{
5409 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
5410 tANI_U32 i;
5411 tCsrRoamSession *pSession;
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305412 tANI_BOOLEAN isConnBssfound = eANI_BOOLEAN_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005413
5414 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5415 {
5416 if( CSR_IS_SESSION_VALID( pMac, i ) )
5417 {
5418 pSession = CSR_GET_SESSION( pMac, i );
5419 //Not to remove the BSS we are connected to.
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305420 if(csrIsConnStateConnectedInfra(pMac, i) && (NULL != pSession->pConnectBssDesc) &&
5421 (csrIsDuplicateBssDescription(pMac, &pResult->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07005422 pSession->pConnectBssDesc, NULL, FALSE))
Jeff Johnson295189b2012-06-20 16:38:30 -07005423 )
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305424 {
5425 isConnBssfound = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005426 break;
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305427 }
5428 }
5429 }
5430
5431 if( isConnBssfound )
Jeff Johnson295189b2012-06-20 16:38:30 -07005432 {
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305433 //Reset the counter so that aging out of connected BSS won't hapeen too soon
Jeff Johnson295189b2012-06-20 16:38:30 -07005434 pResult->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
5435 pResult->Result.BssDescriptor.nReceivedTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305436
5437 return (fRet);
5438 }
5439 else
5440 {
5441 smsLog(pMac, LOGW, "Aging out BSS "MAC_ADDRESS_STR" Channel %d",
5442 MAC_ADDR_ARRAY(pResult->Result.BssDescriptor.bssId),
5443 pResult->Result.BssDescriptor.channelId);
5444 //No need to hold the spin lock because caller should hold the lock for pMac->scan.scanResultList
5445 if( csrLLRemoveEntry(&pMac->scan.scanResultList, &pResult->Link, LL_ACCESS_NOLOCK) )
5446 {
5447 if (csrIsMacAddressEqual(pMac,
5448 (tCsrBssid *) pResult->Result.BssDescriptor.bssId,
5449 (tCsrBssid *) pMac->scan.currentCountryBssid))
5450 {
5451 smsLog(pMac, LOGW, "Aging out 11d BSS "MAC_ADDRESS_STR,
5452 MAC_ADDR_ARRAY(pResult->Result.BssDescriptor.bssId));
5453 pMac->scan.currentCountryRSSI = -128;
5454 }
5455 csrFreeScanResultEntry(pMac, pResult);
5456 fRet = eANI_BOOLEAN_TRUE;
5457 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005458 }
5459
5460 return (fRet);
5461}
5462
5463
5464eHalStatus csrScanAgeResults(tpAniSirGlobal pMac, tSmeGetScanChnRsp *pScanChnInfo)
5465{
5466 eHalStatus status = eHAL_STATUS_SUCCESS;
5467 tListElem *pEntry, *tmpEntry;
5468 tCsrScanResult *pResult;
5469 tLimScanChn *pChnInfo;
5470 tANI_U8 i;
5471
5472 csrLLLock(&pMac->scan.scanResultList);
5473 for(i = 0; i < pScanChnInfo->numChn; i++)
5474 {
5475 pChnInfo = &pScanChnInfo->scanChn[i];
5476 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
5477 while( pEntry )
5478 {
5479 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
5480 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
5481 if(pResult->Result.BssDescriptor.channelId == pChnInfo->channelId)
5482 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005483 if(pResult->AgingCount <= 0)
5484 {
5485 smsLog(pMac, LOGW, " age out due to ref count");
5486 csrScanAgeOutBss(pMac, pResult);
5487 }
Madan Mohan Koyyalamudib9d3dcc2012-09-28 16:47:50 -07005488 else
5489 {
5490 pResult->AgingCount--;
5491 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005492 }
5493 pEntry = tmpEntry;
5494 }
5495 }
5496 csrLLUnlock(&pMac->scan.scanResultList);
5497
5498 return (status);
5499}
5500
5501
5502eHalStatus csrSendMBScanReq( tpAniSirGlobal pMac, tANI_U16 sessionId,
5503 tCsrScanRequest *pScanReq, tScanReqParam *pScanReqParam )
5504{
5505 eHalStatus status = eHAL_STATUS_SUCCESS;
5506 tSirSmeScanReq *pMsg;
5507 tANI_U16 msgLen;
5508 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
5509 tSirScanType scanType = pScanReq->scanType;
5510 tANI_U32 minChnTime; //in units of milliseconds
5511 tANI_U32 maxChnTime; //in units of milliseconds
5512 tANI_U32 i;
5513 tANI_U8 selfMacAddr[WNI_CFG_BSSID_LEN];
5514 tANI_U8 *pSelfMac = NULL;
5515
5516 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
5517 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) +
5518 ( pScanReq->uIEFieldLen ) ;
5519
Kiet Lam64c1b492013-07-12 13:56:44 +05305520 pMsg = vos_mem_malloc(msgLen);
5521 if ( NULL == pMsg )
5522 status = eHAL_STATUS_FAILURE;
5523 else
5524 status = eHAL_STATUS_SUCCESS;
5525 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07005526 {
5527 do
5528 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305529 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005530 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
5531 pMsg->length = pal_cpu_to_be16(msgLen);
5532 //ToDO: Fill in session info when we need to do scan base on session.
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05305533 if ((pMac->fScanOffload) && (sessionId != CSR_SESSION_ID_INVALID))
5534 {
5535 pMsg->sessionId = sessionId;
5536 }
5537 else
5538 {
5539 /* if sessionId == CSR_SESSION_ID_INVALID, then send the scan
5540 request on first available session */
5541 pMsg->sessionId = 0;
5542 }
5543
Jeff Johnson295189b2012-06-20 16:38:30 -07005544 pMsg->transactionId = 0;
5545 pMsg->dot11mode = (tANI_U8) csrTranslateToWNICfgDot11Mode(pMac, csrFindBestPhyMode( pMac, pMac->roam.configParam.phyMode ));
5546 pMsg->bssType = pal_cpu_to_be32(csrTranslateBsstypeToMacType(pScanReq->BSSType));
5547
5548 if ( CSR_IS_SESSION_VALID( pMac, sessionId ) )
5549 {
5550 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[sessionId].selfMacAddr;
5551 }
5552 else
5553 {
5554 // Since we don't have session for the scanning, we find a valid session. In case we fail to
5555 // do so, get the WNI_CFG_STA_ID
5556 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5557 {
5558 if( CSR_IS_SESSION_VALID( pMac, i ) )
5559 {
5560 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[i].selfMacAddr;
5561 break;
5562 }
5563 }
5564 if( CSR_ROAM_SESSION_MAX == i )
5565 {
5566 tANI_U32 len = WNI_CFG_BSSID_LEN;
5567 pSelfMac = selfMacAddr;
5568 status = ccmCfgGetStr( pMac, WNI_CFG_STA_ID, pSelfMac, &len );
5569 if( !HAL_STATUS_SUCCESS( status ) ||
5570 ( len < WNI_CFG_BSSID_LEN ) )
5571 {
5572 smsLog( pMac, LOGE, FL(" Can not get self MAC address from CFG status = %d"), status );
5573 //Force failed status
5574 status = eHAL_STATUS_FAILURE;
5575 break;
5576 }
5577 }
5578 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305579 vos_mem_copy((tANI_U8 *)pMsg->selfMacAddr, pSelfMac, sizeof(tSirMacAddr));
Jeff Johnson295189b2012-06-20 16:38:30 -07005580
5581 //sirCopyMacAddr
Kiet Lam64c1b492013-07-12 13:56:44 +05305582 vos_mem_copy((tANI_U8 *)pMsg->bssId, (tANI_U8 *)&pScanReq->bssid, sizeof(tSirMacAddr));
5583 if ( vos_mem_compare(pScanReq->bssid, bssid, sizeof(tCsrBssid)))
Jeff Johnson295189b2012-06-20 16:38:30 -07005584 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305585 vos_mem_set(pMsg->bssId, sizeof(tSirMacAddr), 0xff);
Jeff Johnson295189b2012-06-20 16:38:30 -07005586 }
5587 else
5588 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305589 vos_mem_copy(pMsg->bssId, pScanReq->bssid, WNI_CFG_BSSID_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07005590 }
5591 minChnTime = pScanReq->minChnTime;
5592 maxChnTime = pScanReq->maxChnTime;
5593
5594 //Verify the scan type first, if the scan is active scan, we need to make sure we
5595 //are allowed to do so.
5596 /* if 11d is enabled & we don't see any beacon around, scan type falls
5597 back to passive. But in BT AMP STA mode we need to send out a
5598 directed probe*/
5599 if( (eSIR_PASSIVE_SCAN != scanType) && (eCSR_SCAN_P2P_DISCOVERY != pScanReq->requestType)
5600 && (eCSR_BSS_TYPE_WDS_STA != pScanReq->BSSType)
5601 && (eANI_BOOLEAN_FALSE == pMac->scan.fEnableBypass11d))
5602 {
5603 scanType = pMac->scan.curScanType;
5604 if(eSIR_PASSIVE_SCAN == pMac->scan.curScanType)
5605 {
5606 if(minChnTime < pMac->roam.configParam.nPassiveMinChnTime)
5607 {
5608 minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
5609 }
5610 if(maxChnTime < pMac->roam.configParam.nPassiveMaxChnTime)
5611 {
5612 maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
5613 }
5614 }
5615 }
5616 pMsg->scanType = pal_cpu_to_be32(scanType);
5617
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05305618 pMsg->numSsid =
5619 (pScanReq->SSIDs.numOfSSIDs < SIR_SCAN_MAX_NUM_SSID) ?
5620 pScanReq->SSIDs.numOfSSIDs : SIR_SCAN_MAX_NUM_SSID;
Jeff Johnson295189b2012-06-20 16:38:30 -07005621 if((pScanReq->SSIDs.numOfSSIDs != 0) && ( eSIR_PASSIVE_SCAN != scanType ))
5622 {
Jeff Johnson40b59aa2013-03-19 14:43:18 -07005623 for (i = 0; i < pMsg->numSsid; i++)
5624 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305625 vos_mem_copy(&pMsg->ssId[i],
5626 &pScanReq->SSIDs.SSIDList[i].SSID, sizeof(tSirMacSSid));
Jeff Johnson40b59aa2013-03-19 14:43:18 -07005627 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005628 }
5629 else
5630 {
5631 //Otherwise we scan all SSID and let the result filter later
Jeff Johnson40b59aa2013-03-19 14:43:18 -07005632 for (i = 0; i < SIR_SCAN_MAX_NUM_SSID; i++)
5633 {
5634 pMsg->ssId[i].length = 0;
5635 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005636 }
5637
Jeff Johnson295189b2012-06-20 16:38:30 -07005638 pMsg->minChannelTime = pal_cpu_to_be32(minChnTime);
5639 pMsg->maxChannelTime = pal_cpu_to_be32(maxChnTime);
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08005640 pMsg->minChannelTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
5641 pMsg->maxChannelTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07005642 //hidden SSID option
5643 pMsg->hiddenSsid = pScanReqParam->hiddenSsid;
5644 //rest time
5645 //pMsg->restTime = pScanReq->restTime;
5646 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
5647 // All the scan results caching will be done by Roaming
5648 // We do not want LIM to do any caching of scan results,
5649 // so delete the LIM cache on all scan requests
5650 pMsg->returnFreshResults = pScanReqParam->freshScan;
5651 //Always ask for unique result
5652 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
5653 pMsg->channelList.numChannels = (tANI_U8)pScanReq->ChannelInfo.numOfChannels;
5654 if(pScanReq->ChannelInfo.numOfChannels)
5655 {
5656 //Assuming the channelNumber is tANI_U8 (1 byte)
Kiet Lam64c1b492013-07-12 13:56:44 +05305657 vos_mem_copy(pMsg->channelList.channelNumber,
5658 pScanReq->ChannelInfo.ChannelList,
5659 pScanReq->ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07005660 }
5661
5662 pMsg->uIEFieldLen = (tANI_U16) pScanReq->uIEFieldLen;
5663 pMsg->uIEFieldOffset = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
5664 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) ;
5665 if(pScanReq->uIEFieldLen != 0)
5666 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305667 vos_mem_copy((tANI_U8 *)pMsg+pMsg->uIEFieldOffset, pScanReq->pIEField,
5668 pScanReq->uIEFieldLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07005669 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005670 pMsg->p2pSearch = pScanReq->p2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07005671
Madan Mohan Koyyalamudi9b876782012-10-11 16:22:51 -07005672 if (pScanReq->requestType == eCSR_SCAN_HO_BG_SCAN)
5673 {
5674 pMsg->backgroundScanMode = eSIR_ROAMING_SCAN;
5675 }
5676
Jeff Johnson295189b2012-06-20 16:38:30 -07005677 }while(0);
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05305678 smsLog(pMac, LOG1, FL("domainIdCurrent %s (%d) scanType %s (%d)"
5679 "bssType %s (%d), requestType %s(%d)"
5680 "numChannels %d"),
5681 voss_DomainIdtoString(pMac->scan.domainIdCurrent),
5682 pMac->scan.domainIdCurrent,
5683 lim_ScanTypetoString(pMsg->scanType), pMsg->scanType,
5684 lim_BssTypetoString(pMsg->bssType), pMsg->bssType,
5685 sme_requestTypetoString(pScanReq->requestType),
5686 pScanReq->requestType,
5687 pMsg->channelList.numChannels);
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005688
5689 for(i = 0; i < pMsg->channelList.numChannels; i++)
5690 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005691 smsLog(pMac, LOG3, FL("channelNumber[%d]= %d"), i, pMsg->channelList.channelNumber[i]);
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005692 }
5693
Jeff Johnson295189b2012-06-20 16:38:30 -07005694 if(HAL_STATUS_SUCCESS(status))
5695 {
5696 status = palSendMBMessage(pMac->hHdd, pMsg);
5697 }
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005698 else
5699 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005700 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d"), status );
Kiet Lam64c1b492013-07-12 13:56:44 +05305701 vos_mem_free(pMsg);
Jeff Johnson295189b2012-06-20 16:38:30 -07005702 }
5703 }//Success allocated memory
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005704 else
5705 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005706 smsLog( pMac, LOGE, FL(" memory allocation failure"));
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005707 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005708
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05305709 if(!HAL_STATUS_SUCCESS(status))
5710 {
5711 smsLog( pMac, LOG1, FL("Failed: SId: %d FirstMatch = %d"
5712 " UniqueResult = %d freshScan = %d hiddenSsid = %d"),
5713 sessionId, pScanReqParam->bReturnAfter1stMatch,
5714 pScanReqParam->fUniqueResult, pScanReqParam->freshScan,
5715 pScanReqParam->hiddenSsid );
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05305716 smsLog( pMac, LOG1, FL("scanType = %s (%d) BSSType = %s (%d) "
5717 "numOfSSIDs = %d numOfChannels = %d requestType = %s (%d)"
5718 " p2pSearch = %d\n"),
5719 lim_ScanTypetoString(pScanReq->scanType),
5720 pScanReq->scanType,
5721 lim_BssTypetoString(pScanReq->BSSType),
5722 pScanReq->BSSType,
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05305723 pScanReq->SSIDs.numOfSSIDs,
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05305724 pScanReq->ChannelInfo.numOfChannels,
5725 sme_requestTypetoString(pScanReq->requestType),
5726 pScanReq->requestType,
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05305727 pScanReq->p2pSearch );
5728
5729 }
5730
Jeff Johnson295189b2012-06-20 16:38:30 -07005731 return( status );
5732}
5733
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005734eHalStatus csrSendMBScanResultReq( tpAniSirGlobal pMac, tANI_U32 sessionId, tScanReqParam *pScanReqParam )
Jeff Johnson295189b2012-06-20 16:38:30 -07005735{
5736 eHalStatus status = eHAL_STATUS_SUCCESS;
5737 tSirSmeScanReq *pMsg;
5738 tANI_U16 msgLen;
5739
5740 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ));
Kiet Lam64c1b492013-07-12 13:56:44 +05305741 pMsg = vos_mem_malloc(msgLen);
5742 if ( NULL == pMsg )
5743 status = eHAL_STATUS_FAILURE;
5744 else
Jeff Johnson295189b2012-06-20 16:38:30 -07005745 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305746 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005747 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
5748 pMsg->length = pal_cpu_to_be16(msgLen);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005749 pMsg->sessionId = sessionId;
5750 pMsg->transactionId = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07005751 pMsg->returnFreshResults = pScanReqParam->freshScan;
5752 //Always ask for unique result
5753 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
5754 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
5755 status = palSendMBMessage(pMac->hHdd, pMsg);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005756 if (!HAL_STATUS_SUCCESS(status))
5757 {
5758 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d\n"), status );
5759 }
5760
Jeff Johnson295189b2012-06-20 16:38:30 -07005761 }
5762
5763 return( status );
5764}
5765
5766
5767
5768eHalStatus csrScanChannels( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5769{
5770 eHalStatus status = eHAL_STATUS_FAILURE;
5771 tScanReqParam scanReq;
5772
5773 do
5774 {
5775 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE | TRUE;
5776 scanReq.fUniqueResult = TRUE;
5777 scanReq.hiddenSsid = SIR_SCAN_NO_HIDDEN_SSID;
5778 if(eCsrScanForSsid == pCommand->u.scanCmd.reason)
5779 {
5780 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_FIRST_MATCH;
5781 }
5782 else
5783 {
5784 // Basically do scan on all channels even for 11D 1st scan case.
5785 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5786 }
5787 if((eCsrScanBgScan == pCommand->u.scanCmd.reason)||
5788 (eCsrScanProbeBss == pCommand->u.scanCmd.reason))
5789 {
5790 scanReq.hiddenSsid = SIR_SCAN_HIDDEN_SSID_PE_DECISION;
5791 }
5792
5793#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5794 {
5795 vos_log_scan_pkt_type *pScanLog = NULL;
5796
5797 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
5798 if(pScanLog)
5799 {
5800 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
5801 eCsrScanProbeBss == pCommand->u.scanCmd.reason)
5802 {
5803 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
5804 }
5805 else
5806 {
5807 if( (eSIR_PASSIVE_SCAN != pCommand->u.scanCmd.u.scanRequest.scanType) &&
5808 (eSIR_PASSIVE_SCAN != pMac->scan.curScanType) )
5809 {
5810 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_REQ;
5811 }
5812 else
5813 {
5814 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_REQ;
5815 }
5816 }
5817 pScanLog->minChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.minChnTime;
5818 pScanLog->maxChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.maxChnTime;
5819 pScanLog->numChannel = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
5820 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
5821 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305822 vos_mem_copy(pScanLog->channels,
5823 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
5824 pScanLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07005825 }
5826 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
5827 }
5828 }
5829#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5830
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05305831 csrClearVotesForCountryInfo(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07005832 status = csrSendMBScanReq(pMac, pCommand->sessionId,
5833 &pCommand->u.scanCmd.u.scanRequest, &scanReq);
5834 }while(0);
5835
5836 return( status );
5837}
5838
5839
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005840eHalStatus csrScanRetrieveResult(tpAniSirGlobal pMac, tSmeCmd *pCommand)
Jeff Johnson295189b2012-06-20 16:38:30 -07005841{
5842 eHalStatus status = eHAL_STATUS_FAILURE;
5843 tScanReqParam scanReq;
5844
5845 do
5846 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005847#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5848 if (eCsrScanGetLfrResult == pCommand->u.scanCmd.reason)
5849 {
5850 //to get the LFR candidates from PE cache
5851 scanReq.freshScan = SIR_BG_SCAN_RETURN_LFR_CACHED_RESULTS|SIR_BG_SCAN_PURGE_LFR_RESULTS;
5852 scanReq.fUniqueResult = TRUE;
5853 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5854 }
5855 else
5856#endif
5857 {
5858 //not a fresh scan
5859 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE;
5860 scanReq.fUniqueResult = TRUE;
5861 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5862 }
5863 status = csrSendMBScanResultReq(pMac, pCommand->sessionId, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07005864 }while(0);
5865
5866 return (status);
5867}
5868
Siddharth Bhald8a95e82015-02-12 20:14:52 +05305869eHalStatus csrProcessMacAddrSpoofCommand( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5870{
5871 tSirSpoofMacAddrReq *pMsg;
5872 tANI_U16 msgLen;
5873 eHalStatus status = eHAL_STATUS_FAILURE;
5874 do {
5875 msgLen = sizeof(tSirSpoofMacAddrReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07005876
Siddharth Bhald8a95e82015-02-12 20:14:52 +05305877 pMsg = vos_mem_malloc(msgLen);
5878 if ( NULL == pMsg )
5879 return eHAL_STATUS_FAILURE;
5880 pMsg->messageType= pal_cpu_to_be16((tANI_U16)eWNI_SME_MAC_SPOOF_ADDR_IND);
5881 pMsg->length= pal_cpu_to_be16(msgLen);
5882 // spoof mac address
5883 vos_mem_copy((tANI_U8 *)pMsg->macAddr,
5884 (tANI_U8 *)pCommand->u.macAddrSpoofCmd.macAddr, sizeof(tSirMacAddr));
5885 status = palSendMBMessage(pMac->hHdd, pMsg);
5886 } while( 0 );
5887 return( status );
5888}
Jeff Johnson295189b2012-06-20 16:38:30 -07005889
5890eHalStatus csrProcessScanCommand( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5891{
5892 eHalStatus status = eHAL_STATUS_SUCCESS;
5893 tCsrChannelInfo newChannelInfo = {0, NULL};
5894 int i, j;
5895 tANI_U8 *pChannel = NULL;
5896 tANI_U32 len = 0;
5897
5898 // Transition to Scanning state...
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305899 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07005900 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305901 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5902 {
5903 pCommand->u.scanCmd.lastRoamState[i] =
5904 csrRoamStateChange( pMac, eCSR_ROAMING_STATE_SCANNING, i);
5905 smsLog( pMac, LOG3, "starting SCAN command from %d state...."
5906 " reason is %d", pCommand->u.scanCmd.lastRoamState[i],
5907 pCommand->u.scanCmd.reason );
5908 }
5909 }
5910 else
5911 {
5912 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId] =
5913 csrRoamStateChange(pMac, eCSR_ROAMING_STATE_SCANNING,
5914 pCommand->sessionId);
5915 smsLog( pMac, LOG3,
5916 "starting SCAN command from %d state.... reason is %d",
5917 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId],
5918 pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07005919 }
5920
5921 switch(pCommand->u.scanCmd.reason)
5922 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005923#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5924 case eCsrScanGetLfrResult:
5925#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005926 case eCsrScanGetResult:
5927 case eCsrScanForCapsChange: //For cap change, LIM already save BSS description
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005928 status = csrScanRetrieveResult(pMac, pCommand);
Jeff Johnson295189b2012-06-20 16:38:30 -07005929 break;
5930 case eCsrScanSetBGScanParam:
5931 status = csrProcessSetBGScanParam(pMac, pCommand);
5932 break;
5933 case eCsrScanBGScanAbort:
5934 status = csrSetCfgBackgroundScanPeriod(pMac, 0);
5935 break;
5936 case eCsrScanBGScanEnable:
5937 status = csrSetCfgBackgroundScanPeriod(pMac, pMac->roam.configParam.bgScanInterval);
5938 break;
5939 case eCsrScanGetScanChnInfo:
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05305940 status = csrScanGetScanChannelInfo(pMac, pCommand->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07005941 break;
5942 case eCsrScanUserRequest:
5943 if(pMac->roam.configParam.fScanTwice)
5944 {
5945 //We scan 2.4 channel twice
5946 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels &&
5947 (NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList))
5948 {
5949 len = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
5950 //allocate twice the channel
Mukul Sharmaa631e892014-08-28 15:38:51 +05305951 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(len * 2);
Jeff Johnson295189b2012-06-20 16:38:30 -07005952 pChannel = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
5953 }
5954 else
5955 {
5956 //get the valid channel list to scan all.
5957 len = sizeof(pMac->roam.validChannelList);
5958
5959 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
5960 {
5961 //allocate twice the channel
5962 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(len * 2);
5963 pChannel = pMac->roam.validChannelList;
5964 }
5965 }
5966 if(NULL == newChannelInfo.ChannelList)
5967 {
5968 newChannelInfo.numOfChannels = 0;
5969 }
5970 else
5971 {
5972 j = 0;
5973 for(i = 0; i < len; i++)
5974 {
5975 newChannelInfo.ChannelList[j++] = pChannel[i];
5976 if(CSR_MAX_24GHz_CHANNEL_NUMBER >= pChannel[i])
5977 {
5978 newChannelInfo.ChannelList[j++] = pChannel[i];
5979 }
5980 }
5981 if(NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
5982 {
5983 //pChannel points to the channellist from the command, free it.
5984 vos_mem_free(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -07005985 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07005986 }
5987 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = j;
5988 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = newChannelInfo.ChannelList;
5989 }
5990 } //if(pMac->roam.configParam.fScanTwice)
5991
5992 status = csrScanChannels(pMac, pCommand);
5993
5994 break;
5995 default:
5996 status = csrScanChannels(pMac, pCommand);
5997 break;
5998 }
5999
6000 if(!HAL_STATUS_SUCCESS(status))
6001 {
6002 csrReleaseScanCommand(pMac, pCommand, eCSR_SCAN_FAILURE);
6003 }
6004
6005 return (status);
6006}
6007
6008
6009eHalStatus csrScanSetBGScanparams(tpAniSirGlobal pMac, tCsrBGScanRequest *pScanReq)
6010{
6011 eHalStatus status = eHAL_STATUS_SUCCESS;
6012 tSmeCmd *pCommand = NULL;
6013
6014 if(pScanReq)
6015 {
6016 do
6017 {
6018 pCommand = csrGetCommandBuffer(pMac);
6019 if(!pCommand)
6020 {
6021 status = eHAL_STATUS_RESOURCES;
6022 break;
6023 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306024 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006025 pCommand->command = eSmeCommandScan;
6026 pCommand->u.scanCmd.reason = eCsrScanSetBGScanParam;
6027 pCommand->u.scanCmd.callback = NULL;
6028 pCommand->u.scanCmd.pContext = NULL;
Kiet Lam64c1b492013-07-12 13:56:44 +05306029 vos_mem_copy(&pCommand->u.scanCmd.u.bgScanRequest, pScanReq, sizeof(tCsrBGScanRequest));
Jeff Johnson295189b2012-06-20 16:38:30 -07006030 //we have to do the follow
6031 if(pScanReq->ChannelInfo.numOfChannels == 0)
6032 {
6033 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
6034 }
6035 else
6036 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306037 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList
6038 = vos_mem_malloc(pScanReq->ChannelInfo.numOfChannels);
6039 if ( NULL != pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07006040 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306041 vos_mem_copy(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList,
6042 pScanReq->ChannelInfo.ChannelList,
6043 pScanReq->ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07006044 }
6045 else
6046 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006047 smsLog(pMac, LOGE, FL("ran out of memory"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006048 csrReleaseCommandScan(pMac, pCommand);
Kiet Lam64c1b492013-07-12 13:56:44 +05306049 return eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006050 }
6051 }
6052
6053 //scan req for SSID
6054 if(pScanReq->SSID.length)
6055 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306056 vos_mem_copy(pCommand->u.scanCmd.u.bgScanRequest.SSID.ssId,
6057 pScanReq->SSID.ssId, pScanReq->SSID.length);
Jeff Johnson295189b2012-06-20 16:38:30 -07006058 pCommand->u.scanCmd.u.bgScanRequest.SSID.length = pScanReq->SSID.length;
6059
6060 }
6061 pCommand->u.scanCmd.u.bgScanRequest.maxChnTime= pScanReq->maxChnTime;
6062 pCommand->u.scanCmd.u.bgScanRequest.minChnTime = pScanReq->minChnTime;
6063 pCommand->u.scanCmd.u.bgScanRequest.scanInterval = pScanReq->scanInterval;
6064
6065
6066 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
6067 if( !HAL_STATUS_SUCCESS( status ) )
6068 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006069 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006070 csrReleaseCommandScan( pMac, pCommand );
6071 break;
6072 }
6073 }while(0);
6074 }
6075
6076 return (status);
6077}
6078
6079eHalStatus csrScanBGScanAbort( tpAniSirGlobal pMac )
6080{
6081 eHalStatus status = eHAL_STATUS_SUCCESS;
6082 tSmeCmd *pCommand = NULL;
6083
6084 do
6085 {
6086 pCommand = csrGetCommandBuffer(pMac);
6087 if(!pCommand)
6088 {
6089 status = eHAL_STATUS_RESOURCES;
6090 break;
6091 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306092 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006093 pCommand->command = eSmeCommandScan;
6094 pCommand->u.scanCmd.reason = eCsrScanBGScanAbort;
6095 pCommand->u.scanCmd.callback = NULL;
6096 pCommand->u.scanCmd.pContext = NULL;
6097 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
6098 if( !HAL_STATUS_SUCCESS( status ) )
6099 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006100 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006101 csrReleaseCommandScan( pMac, pCommand );
6102 break;
6103 }
6104 }while(0);
6105
6106 return (status);
6107}
6108
6109
6110//This will enable the background scan with the non-zero interval
6111eHalStatus csrScanBGScanEnable(tpAniSirGlobal pMac)
6112{
6113 eHalStatus status = eHAL_STATUS_SUCCESS;
6114 tSmeCmd *pCommand = NULL;
6115
6116 if(pMac->roam.configParam.bgScanInterval)
6117 {
6118 do
6119 {
6120 pCommand = csrGetCommandBuffer(pMac);
6121 if(!pCommand)
6122 {
6123 status = eHAL_STATUS_RESOURCES;
6124 break;
6125 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306126 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006127 pCommand->command = eSmeCommandScan;
6128 pCommand->u.scanCmd.reason = eCsrScanBGScanEnable;
6129 pCommand->u.scanCmd.callback = NULL;
6130 pCommand->u.scanCmd.pContext = NULL;
6131 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
6132 if( !HAL_STATUS_SUCCESS( status ) )
6133 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006134 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006135 csrReleaseCommandScan( pMac, pCommand );
6136 break;
6137 }
6138 }while(0);
6139 //BG scan results are reported automatically by PE to SME once the scan is done.
6140 //No need to fetch the results explicitly.
6141 //csrScanStartGetResultTimer(pMac);
6142 csrScanStartResultAgingTimer(pMac);
6143 }
6144 else
6145 {
6146 //We don't have BG scan so stop the aging timer
6147 csrScanStopResultAgingTimer(pMac);
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006148 smsLog(pMac, LOGE, FL("cannot continue because the bgscan interval is 0"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006149 status = eHAL_STATUS_INVALID_PARAMETER;
6150 }
6151
6152 return (status);
6153}
6154
6155
6156eHalStatus csrScanCopyRequest(tpAniSirGlobal pMac, tCsrScanRequest *pDstReq, tCsrScanRequest *pSrcReq)
6157{
6158 eHalStatus status = eHAL_STATUS_SUCCESS;
6159 tANI_U32 len = sizeof(pMac->roam.validChannelList);
6160 tANI_U32 index = 0;
6161 tANI_U32 new_index = 0;
Manjunathappa Prakashde7b2a52014-02-28 16:59:03 -08006162 eNVChannelEnabledType NVchannel_state;
Arif Hussain6af38622014-03-12 12:39:57 -07006163 tANI_U8 ch144_support = 0;
6164
6165 ch144_support = WDA_getFwWlanFeatCaps(WLAN_CH144);
Jeff Johnson295189b2012-06-20 16:38:30 -07006166
6167 do
6168 {
6169 status = csrScanFreeRequest(pMac, pDstReq);
6170 if(HAL_STATUS_SUCCESS(status))
6171 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306172 vos_mem_copy(pDstReq, pSrcReq, sizeof(tCsrScanRequest));
Gopichand Nakkalac7b1d3e2012-12-31 14:07:19 -08006173 /* Re-initialize the pointers to NULL since we did a copy */
6174 pDstReq->pIEField = NULL;
6175 pDstReq->ChannelInfo.ChannelList = NULL;
6176 pDstReq->SSIDs.SSIDList = NULL;
6177
Jeff Johnson295189b2012-06-20 16:38:30 -07006178 if(pSrcReq->uIEFieldLen == 0)
6179 {
6180 pDstReq->pIEField = NULL;
6181 }
6182 else
6183 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306184 pDstReq->pIEField = vos_mem_malloc(pSrcReq->uIEFieldLen);
6185 if ( NULL == pDstReq->pIEField )
Jeff Johnson295189b2012-06-20 16:38:30 -07006186 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306187 status = eHAL_STATUS_FAILURE;
6188 smsLog(pMac, LOGE, FL("No memory for scanning IE fields"));
6189 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07006190 }
6191 else
6192 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306193 status = eHAL_STATUS_SUCCESS;
6194 vos_mem_copy(pDstReq->pIEField, pSrcReq->pIEField,
6195 pSrcReq->uIEFieldLen);
6196 pDstReq->uIEFieldLen = pSrcReq->uIEFieldLen;
Jeff Johnson295189b2012-06-20 16:38:30 -07006197 }
6198 }//Allocate memory for IE field
6199 {
6200 if(pSrcReq->ChannelInfo.numOfChannels == 0)
6201 {
6202 pDstReq->ChannelInfo.ChannelList = NULL;
6203 pDstReq->ChannelInfo.numOfChannels = 0;
6204 }
6205 else
6206 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306207 pDstReq->ChannelInfo.ChannelList = vos_mem_malloc(
6208 pSrcReq->ChannelInfo.numOfChannels
6209 * sizeof(*pDstReq->ChannelInfo.ChannelList));
6210 if ( NULL == pDstReq->ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07006211 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306212 status = eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006213 pDstReq->ChannelInfo.numOfChannels = 0;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306214 smsLog(pMac, LOGE, FL("No memory for scanning Channel"
6215 " List"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006216 break;
6217 }
6218
6219 if((pSrcReq->scanType == eSIR_PASSIVE_SCAN) && (pSrcReq->requestType == eCSR_SCAN_REQUEST_11D_SCAN))
6220 {
6221 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
6222 {
Arif Hussain6af38622014-03-12 12:39:57 -07006223 /* Skip CH 144 if firmware support not present */
6224 if (pSrcReq->ChannelInfo.ChannelList[index] == 144 && !ch144_support)
6225 continue;
6226
Manjunathappa Prakashde7b2a52014-02-28 16:59:03 -08006227 NVchannel_state = vos_nv_getChannelEnabledState(
6228 pSrcReq->ChannelInfo.ChannelList[index]);
6229 if ((NV_CHANNEL_ENABLE == NVchannel_state) ||
6230 (NV_CHANNEL_DFS == NVchannel_state))
6231 {
6232 pDstReq->ChannelInfo.ChannelList[new_index] =
6233 pSrcReq->ChannelInfo.ChannelList[index];
6234 new_index++;
6235 }
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306236 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006237 pDstReq->ChannelInfo.numOfChannels = new_index;
6238 }
6239 else if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
6240 {
6241 new_index = 0;
6242 pMac->roam.numValidChannels = len;
c_hpothu0d5a7352014-03-22 12:30:25 +05306243
6244 /* Since in CsrScanRequest,value of pMac->scan.nextScanID
6245 * is incremented before calling CsrScanCopyRequest, as a
6246 * result pMac->scan.nextScanID is equal to ONE for the
6247 * first scan.
6248 */
Ganesh Kondabattini8f6e3b32014-08-25 16:07:54 +05306249 if ((pMac->roam.configParam.initialScanSkipDFSCh &&
6250 1 == pMac->scan.nextScanID) ||(pMac->miracast_mode))
c_hpothu0d5a7352014-03-22 12:30:25 +05306251 {
6252 smsLog(pMac, LOG1,
6253 FL("Initial scan, scan only non-DFS channels"));
6254
6255 for (index = 0; index < pSrcReq->ChannelInfo.
6256 numOfChannels ; index++ )
6257 {
6258 if((csrRoamIsValidChannel(pMac, pSrcReq->ChannelInfo.
6259 ChannelList[index])))
6260 {
6261 /*Skiipping DFS Channels for 1st scan */
6262 if(NV_CHANNEL_DFS ==
6263 vos_nv_getChannelEnabledState(pSrcReq->ChannelInfo.
6264 ChannelList[index]))
6265 continue ;
6266
6267 pDstReq->ChannelInfo.ChannelList[new_index] =
6268 pSrcReq->ChannelInfo.ChannelList[index];
6269 new_index++;
6270
6271 }
6272 }
6273 pMac->roam.configParam.initialScanSkipDFSCh = 0;
6274 }
6275 else
6276 {
6277 for ( index = 0; index < pSrcReq->ChannelInfo.
6278 numOfChannels ; index++ )
Jeff Johnson295189b2012-06-20 16:38:30 -07006279 {
Arif Hussain6af38622014-03-12 12:39:57 -07006280 /* Skip CH 144 if firmware support not present */
6281 if (pSrcReq->ChannelInfo.ChannelList[index] == 144 && !ch144_support)
6282 continue;
6283
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -07006284 /* Allow scan on valid channels only.
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -07006285 */
Abhishek Singh2ec36ab2014-08-07 16:14:25 +05306286 if ( ( csrRoamIsValidChannel(pMac, pSrcReq->ChannelInfo.ChannelList[index]) ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07006287 {
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05306288 if( ((pSrcReq->skipDfsChnlInP2pSearch ||
6289 (pMac->scan.fEnableDFSChnlScan ==
6290 DFS_CHNL_SCAN_DISABLED)) &&
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08006291 (NV_CHANNEL_DFS == vos_nv_getChannelEnabledState(pSrcReq->ChannelInfo.ChannelList[index])) )
Srikant Kuppa866893f2012-12-27 17:28:14 -08006292#ifdef FEATURE_WLAN_LFR
6293 /*
6294 * If LFR is requesting a contiguous scan
6295 * (i.e. numOfChannels > 1), then ignore
6296 * DFS channels.
6297 * TODO: vos_nv_getChannelEnabledState is returning
6298 * 120, 124 and 128 as non-DFS channels. Hence, the
6299 * use of direct check for channels below.
6300 */
6301 || ((eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType) &&
6302 (pSrcReq->ChannelInfo.numOfChannels > 1) &&
Santhosh Kumar Padma9ccaaff2014-07-09 19:58:12 +05306303 (CSR_IS_CHANNEL_DFS(pSrcReq->ChannelInfo.ChannelList[index])) &&
6304 !pMac->roam.configParam.allowDFSChannelRoam)
Srikant Kuppa866893f2012-12-27 17:28:14 -08006305#endif
6306 )
6307 {
6308#ifdef FEATURE_WLAN_LFR
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05306309 smsLog(pMac, LOG2,
6310 FL(" reqType=%s (%d), numOfChannels=%d,"
6311 " ignoring DFS channel %d"),
6312 sme_requestTypetoString(pSrcReq->requestType),
6313 pSrcReq->requestType,
6314 pSrcReq->ChannelInfo.numOfChannels,
6315 pSrcReq->ChannelInfo.ChannelList[index]);
Srikant Kuppa866893f2012-12-27 17:28:14 -08006316#endif
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05306317 continue;
Srikant Kuppa866893f2012-12-27 17:28:14 -08006318 }
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08006319
Jeff Johnson295189b2012-06-20 16:38:30 -07006320 pDstReq->ChannelInfo.ChannelList[new_index] =
6321 pSrcReq->ChannelInfo.ChannelList[index];
6322 new_index++;
6323 }
6324 }
c_hpothu0d5a7352014-03-22 12:30:25 +05306325 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006326 pDstReq->ChannelInfo.numOfChannels = new_index;
Srikant Kuppa866893f2012-12-27 17:28:14 -08006327#ifdef FEATURE_WLAN_LFR
Abhishek Singh2ec36ab2014-08-07 16:14:25 +05306328 if ( ( ( eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType ) ||
6329 ( eCSR_SCAN_P2P_DISCOVERY == pSrcReq->requestType ) ) &&
6330 ( 0 == pDstReq->ChannelInfo.numOfChannels ) )
Srikant Kuppa866893f2012-12-27 17:28:14 -08006331 {
6332 /*
6333 * No valid channels found in the request.
6334 * Only perform scan on the channels passed
Abhishek Singh2ec36ab2014-08-07 16:14:25 +05306335 * pSrcReq if it is a eCSR_SCAN_HO_BG_SCAN or
6336 * eCSR_SCAN_P2P_DISCOVERY.
Srikant Kuppa866893f2012-12-27 17:28:14 -08006337 * Passing 0 to LIM will trigger a scan on
6338 * all valid channels which is not desirable.
6339 */
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306340 smsLog(pMac, LOGE, FL(" no valid channels found"
6341 " (request=%d)"), pSrcReq->requestType);
Srikant Kuppa866893f2012-12-27 17:28:14 -08006342 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
6343 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306344 smsLog(pMac, LOGE, FL("pSrcReq index=%d"
6345 " channel=%d"), index,
6346 pSrcReq->ChannelInfo.ChannelList[index]);
Srikant Kuppa866893f2012-12-27 17:28:14 -08006347 }
6348 status = eHAL_STATUS_FAILURE;
6349 break;
6350 }
6351#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006352 }
6353 else
6354 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306355 smsLog(pMac, LOGE, FL("Couldn't get the valid Channel"
6356 " List, keeping requester's list"));
Kiet Lam64c1b492013-07-12 13:56:44 +05306357 vos_mem_copy(pDstReq->ChannelInfo.ChannelList,
6358 pSrcReq->ChannelInfo.ChannelList,
6359 pSrcReq->ChannelInfo.numOfChannels
6360 * sizeof(*pDstReq->ChannelInfo.ChannelList));
Jeff Johnson295189b2012-06-20 16:38:30 -07006361 pDstReq->ChannelInfo.numOfChannels = pSrcReq->ChannelInfo.numOfChannels;
6362 }
6363 }//Allocate memory for Channel List
6364 }
6365 if(pSrcReq->SSIDs.numOfSSIDs == 0)
6366 {
6367 pDstReq->SSIDs.numOfSSIDs = 0;
6368 pDstReq->SSIDs.SSIDList = NULL;
6369 }
6370 else
6371 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306372 pDstReq->SSIDs.SSIDList = vos_mem_malloc(
6373 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
6374 if ( NULL == pDstReq->SSIDs.SSIDList )
6375 status = eHAL_STATUS_FAILURE;
6376 else
6377 status = eHAL_STATUS_SUCCESS;
6378 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07006379 {
6380 pDstReq->SSIDs.numOfSSIDs = pSrcReq->SSIDs.numOfSSIDs;
Kiet Lam64c1b492013-07-12 13:56:44 +05306381 vos_mem_copy(pDstReq->SSIDs.SSIDList,
6382 pSrcReq->SSIDs.SSIDList,
6383 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
Jeff Johnson295189b2012-06-20 16:38:30 -07006384 }
6385 else
6386 {
6387 pDstReq->SSIDs.numOfSSIDs = 0;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306388 smsLog(pMac, LOGE, FL("No memory for scanning SSID List"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006389 break;
6390 }
6391 }//Allocate memory for SSID List
Jeff Johnson295189b2012-06-20 16:38:30 -07006392 pDstReq->p2pSearch = pSrcReq->p2pSearch;
Jeff Johnsone7245742012-09-05 17:12:55 -07006393 pDstReq->skipDfsChnlInP2pSearch = pSrcReq->skipDfsChnlInP2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07006394
6395 }
6396 }while(0);
6397
6398 if(!HAL_STATUS_SUCCESS(status))
6399 {
6400 csrScanFreeRequest(pMac, pDstReq);
6401 }
6402
6403 return (status);
6404}
6405
6406
6407eHalStatus csrScanFreeRequest(tpAniSirGlobal pMac, tCsrScanRequest *pReq)
6408{
Jeff Johnson295189b2012-06-20 16:38:30 -07006409
6410 if(pReq->ChannelInfo.ChannelList)
6411 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306412 vos_mem_free(pReq->ChannelInfo.ChannelList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006413 pReq->ChannelInfo.ChannelList = NULL;
6414 }
6415 pReq->ChannelInfo.numOfChannels = 0;
6416 if(pReq->pIEField)
6417 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306418 vos_mem_free(pReq->pIEField);
Jeff Johnson295189b2012-06-20 16:38:30 -07006419 pReq->pIEField = NULL;
6420 }
6421 pReq->uIEFieldLen = 0;
6422 if(pReq->SSIDs.SSIDList)
6423 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306424 vos_mem_free(pReq->SSIDs.SSIDList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006425 pReq->SSIDs.SSIDList = NULL;
6426 }
6427 pReq->SSIDs.numOfSSIDs = 0;
6428
Kiet Lam64c1b492013-07-12 13:56:44 +05306429 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07006430}
6431
6432
6433void csrScanCallCallback(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
6434{
6435 if(pCommand->u.scanCmd.callback)
6436 {
6437// sme_ReleaseGlobalLock( &pMac->sme );
6438 pCommand->u.scanCmd.callback(pMac, pCommand->u.scanCmd.pContext, pCommand->u.scanCmd.scanID, scanStatus);
6439// sme_AcquireGlobalLock( &pMac->sme );
6440 } else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006441 smsLog( pMac, LOG2, "%s:%d - Callback NULL!!!", __func__, __LINE__);
Jeff Johnson295189b2012-06-20 16:38:30 -07006442 }
6443}
6444
6445
6446void csrScanStopTimers(tpAniSirGlobal pMac)
6447{
6448 csrScanStopResultAgingTimer(pMac);
6449 csrScanStopIdleScanTimer(pMac);
6450 csrScanStopGetResultTimer(pMac);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006451 if(0 != pMac->scan.scanResultCfgAgingTime )
6452 {
6453 csrScanStopResultCfgAgingTimer(pMac);
6454 }
6455
Jeff Johnson295189b2012-06-20 16:38:30 -07006456}
6457
6458
6459eHalStatus csrScanStartGetResultTimer(tpAniSirGlobal pMac)
6460{
6461 eHalStatus status;
6462
6463 if(pMac->scan.fScanEnable)
6464 {
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306465 status = vos_timer_start(&pMac->scan.hTimerGetResult, CSR_SCAN_GET_RESULT_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006466 }
6467 else
6468 {
6469 status = eHAL_STATUS_FAILURE;
6470 }
6471
6472 return (status);
6473}
6474
6475
6476eHalStatus csrScanStopGetResultTimer(tpAniSirGlobal pMac)
6477{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306478 return (vos_timer_stop(&pMac->scan.hTimerGetResult));
Jeff Johnson295189b2012-06-20 16:38:30 -07006479}
6480
6481
6482void csrScanGetResultTimerHandler(void *pv)
6483{
6484 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6485
6486 csrScanRequestResult(pMac);
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306487
6488 vos_timer_start(&pMac->scan.hTimerGetResult, CSR_SCAN_GET_RESULT_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006489}
6490
6491#ifdef WLAN_AP_STA_CONCURRENCY
6492static void csrStaApConcTimerHandler(void *pv)
6493{
6494 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6495 tListElem *pEntry;
6496 tSmeCmd *pScanCmd;
6497
6498 csrLLLock(&pMac->scan.scanCmdPendingList);
6499
6500 if ( NULL != ( pEntry = csrLLPeekHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) ) )
6501 {
6502 tCsrScanRequest scanReq;
6503 tSmeCmd *pSendScanCmd = NULL;
6504 tANI_U8 numChn = 0;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006505 tANI_U8 nNumChanCombinedConc = 0;
Vinay Malekal05fdc812012-12-17 13:04:30 -08006506 tANI_U8 i, j;
Jeff Johnson295189b2012-06-20 16:38:30 -07006507 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
6508 tANI_U8 channelToScan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
6509 eHalStatus status;
6510
Jeff Johnson295189b2012-06-20 16:38:30 -07006511 pScanCmd = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
6512 numChn = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08006513
6514 /* if any session is connected and the number of channels to scan is
6515 * greater than 1 then split the scan into multiple scan operations
6516 * on each individual channel else continue to perform scan on all
6517 * specified channels */
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08006518
6519 /* split scan if number of channels to scan is greater than 1 and
6520 * any one of the following:
6521 * - STA session is connected and the scan is not a P2P search
6522 * - any P2P session is connected
Srikant Kuppa866893f2012-12-27 17:28:14 -08006523 * Do not split scans if no concurrent infra connections are
6524 * active and if the scan is a BG scan triggered by LFR (OR)
6525 * any scan if LFR is in the middle of a BG scan. Splitting
6526 * the scan is delaying the time it takes for LFR to find
6527 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08006528 */
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006529
6530 if((csrIsStaSessionConnected(pMac) &&
6531 !csrIsP2pSessionConnected(pMac)))
6532 {
6533 nNumChanCombinedConc = pMac->roam.configParam.nNumStaChanCombinedConc;
6534 }
6535 else if(csrIsP2pSessionConnected(pMac))
6536 {
6537 nNumChanCombinedConc = pMac->roam.configParam.nNumP2PChanCombinedConc;
6538 }
6539
6540 if ( (numChn > nNumChanCombinedConc) &&
Srikant Kuppa866893f2012-12-27 17:28:14 -08006541 ((csrIsStaSessionConnected(pMac) &&
6542#ifdef FEATURE_WLAN_LFR
6543 (csrIsConcurrentInfraConnected(pMac) ||
6544 ((pScanCmd->u.scanCmd.reason != eCsrScanBgScan) &&
6545 (pMac->roam.neighborRoamInfo.neighborRoamState !=
6546 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
6547#endif
6548 (pScanCmd->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08006549 (csrIsP2pSessionConnected(pMac))))
Jeff Johnson295189b2012-06-20 16:38:30 -07006550 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306551 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006552
6553 pSendScanCmd = csrGetCommandBuffer(pMac); //optimize this to use 2 command buffer only
6554 if (!pSendScanCmd)
6555 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006556 smsLog( pMac, LOGE, FL(" Failed to get Queue command buffer") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006557 csrLLUnlock(&pMac->scan.scanCmdPendingList);
6558 return;
6559 }
6560 pSendScanCmd->command = pScanCmd->command;
6561 pSendScanCmd->sessionId = pScanCmd->sessionId;
6562 pSendScanCmd->u.scanCmd.callback = NULL;
6563 pSendScanCmd->u.scanCmd.pContext = pScanCmd->u.scanCmd.pContext;
6564 pSendScanCmd->u.scanCmd.reason = pScanCmd->u.scanCmd.reason;
6565 pSendScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
6566
Madan Mohan Koyyalamudiaf2a8b92012-10-09 14:58:07 -07006567 /* First copy all the parameters to local variable of scan request */
6568 csrScanCopyRequest(pMac, &scanReq, &pScanCmd->u.scanCmd.u.scanRequest);
6569
6570 /* Now modify the elements of local var scan request required to be modified for split scan */
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08006571 if(scanReq.ChannelInfo.ChannelList != NULL)
6572 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306573 vos_mem_free(scanReq.ChannelInfo.ChannelList);
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08006574 scanReq.ChannelInfo.ChannelList = NULL;
6575 }
6576
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006577 pChnInfo->numOfChannels = nNumChanCombinedConc;
Kiet Lam64c1b492013-07-12 13:56:44 +05306578 vos_mem_copy(&channelToScan[0],
6579 &pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[0],
6580 pChnInfo->numOfChannels * sizeof(tANI_U8));//just send one channel
Jeff Johnson295189b2012-06-20 16:38:30 -07006581 pChnInfo->ChannelList = &channelToScan[0];
6582
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006583 for (i = 0, j = nNumChanCombinedConc; i < (numChn-nNumChanCombinedConc); i++, j++)
Jeff Johnson295189b2012-06-20 16:38:30 -07006584 {
6585 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] =
Vinay Malekal05fdc812012-12-17 13:04:30 -08006586 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[j]; //Move all the channels one step
Jeff Johnson295189b2012-06-20 16:38:30 -07006587 }
6588
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006589 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = numChn - nNumChanCombinedConc; //reduce outstanding # of channels to be scanned
Jeff Johnson295189b2012-06-20 16:38:30 -07006590
6591 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
c_hpothudbefd3e2014-04-28 15:59:47 +05306592
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -07006593 //Use concurrency values for min/maxChnTime.
6594 //We know csrIsAnySessionConnected(pMac) returns TRUE here
6595 csrSetDefaultScanTiming(pMac, scanReq.scanType, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07006596
6597 status = csrScanCopyRequest(pMac, &pSendScanCmd->u.scanCmd.u.scanRequest, &scanReq);
6598 if(!HAL_STATUS_SUCCESS(status))
6599 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006600 smsLog( pMac, LOGE, FL(" Failed to get copy csrScanRequest = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006601 csrLLUnlock(&pMac->scan.scanCmdPendingList);
6602 return;
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08006603 }
6604 /* Clean the local scan variable */
6605 scanReq.ChannelInfo.ChannelList = NULL;
6606 scanReq.ChannelInfo.numOfChannels = 0;
6607 csrScanFreeRequest(pMac, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07006608 }
6609 else
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08006610 {
6611 /* no active connected session present or numChn == 1
6612 * scan all remaining channels */
Jeff Johnson295189b2012-06-20 16:38:30 -07006613 pSendScanCmd = pScanCmd;
6614 //remove this command from pending list
6615 if (csrLLRemoveHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) == NULL)
6616 { //In case between PeekHead and here, the entry got removed by another thread.
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006617 smsLog( pMac, LOGE, FL(" Failed to remove entry from scanCmdPendingList"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006618 }
6619
6620 }
6621 csrQueueSmeCommand(pMac, pSendScanCmd, eANI_BOOLEAN_FALSE);
6622
6623 }
6624
Jeff Johnson295189b2012-06-20 16:38:30 -07006625 csrLLUnlock(&pMac->scan.scanCmdPendingList);
6626
6627}
6628#endif
6629
6630eHalStatus csrScanStartResultAgingTimer(tpAniSirGlobal pMac)
6631{
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006632 eHalStatus status = eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006633
6634 if(pMac->scan.fScanEnable)
6635 {
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306636 status = vos_timer_start(&pMac->scan.hTimerResultAging, CSR_SCAN_RESULT_AGING_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006637 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006638 return (status);
6639}
6640
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006641eHalStatus csrScanStartResultCfgAgingTimer(tpAniSirGlobal pMac)
6642{
6643 eHalStatus status = eHAL_STATUS_FAILURE;
6644
6645 if(pMac->scan.fScanEnable)
6646 {
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306647 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 -08006648 }
6649 return (status);
6650}
Jeff Johnson295189b2012-06-20 16:38:30 -07006651
6652eHalStatus csrScanStopResultAgingTimer(tpAniSirGlobal pMac)
6653{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306654 return (vos_timer_stop(&pMac->scan.hTimerResultAging));
Jeff Johnson295189b2012-06-20 16:38:30 -07006655}
6656
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006657eHalStatus csrScanStopResultCfgAgingTimer(tpAniSirGlobal pMac)
6658{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306659 return (vos_timer_stop(&pMac->scan.hTimerResultCfgAging));
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006660}
Jeff Johnson295189b2012-06-20 16:38:30 -07006661
6662//This function returns the maximum time a BSS is allowed in the scan result.
6663//The time varies base on connection and power saving factors.
6664//Not connected, No PS
6665//Not connected, with PS
6666//Connected w/o traffic, No PS
6667//Connected w/o traffic, with PS
6668//Connected w/ traffic, no PS -- Not supported
6669//Connected w/ traffic, with PS -- Not supported
6670//the return unit is in seconds.
6671tANI_U32 csrScanGetAgeOutTime(tpAniSirGlobal pMac)
6672{
6673 tANI_U32 nRet;
6674
6675 if(pMac->scan.nAgingCountDown)
6676 {
6677 //Calculate what should be the timeout value for this
6678 nRet = pMac->scan.nLastAgeTimeOut * pMac->scan.nAgingCountDown;
6679 pMac->scan.nAgingCountDown--;
6680 }
6681 else
6682 {
6683 if( csrIsAllSessionDisconnected( pMac ) )
6684 {
6685 if(pmcIsPowerSaveEnabled(pMac, ePMC_IDLE_MODE_POWER_SAVE))
6686 {
6687 nRet = pMac->roam.configParam.scanAgeTimeNCPS;
6688 }
6689 else
6690 {
6691 nRet = pMac->roam.configParam.scanAgeTimeNCNPS;
6692 }
6693 }
6694 else
6695 {
6696 if(pmcIsPowerSaveEnabled(pMac, ePMC_BEACON_MODE_POWER_SAVE))
6697 {
6698 nRet = pMac->roam.configParam.scanAgeTimeCPS;
6699 }
6700 else
6701 {
6702 nRet = pMac->roam.configParam.scanAgeTimeCNPS;
6703 }
6704 }
6705 //If state-change causing aging time out change, we want to delay it somewhat to avoid
6706 //unnecessary removal of BSS. This is mostly due to transition from connect to disconnect.
6707 if(pMac->scan.nLastAgeTimeOut > nRet)
6708 {
6709 if(nRet)
6710 {
6711 pMac->scan.nAgingCountDown = (pMac->scan.nLastAgeTimeOut / nRet);
6712 }
6713 pMac->scan.nLastAgeTimeOut = nRet;
6714 nRet *= pMac->scan.nAgingCountDown;
6715 }
6716 else
6717 {
6718 pMac->scan.nLastAgeTimeOut = nRet;
6719 }
6720 }
6721
6722 return (nRet);
6723}
6724
6725
6726void csrScanResultAgingTimerHandler(void *pv)
6727{
6728 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6729 tANI_BOOLEAN fDisconnected = csrIsAllSessionDisconnected(pMac);
6730
6731 //no scan, no aging
Kaushik, Sushant9073c0c2014-03-11 19:10:23 +05306732 if (pMac->scan.fScanEnable &&
Jeff Johnson295189b2012-06-20 16:38:30 -07006733 (((eANI_BOOLEAN_FALSE == fDisconnected) && pMac->roam.configParam.bgScanInterval)
Kaushik, Sushant9073c0c2014-03-11 19:10:23 +05306734 || (fDisconnected && (pMac->scan.fCancelIdleScan == eANI_BOOLEAN_FALSE))
6735 || (pMac->fScanOffload))
Jeff Johnson295189b2012-06-20 16:38:30 -07006736 )
6737 {
6738 tListElem *pEntry, *tmpEntry;
6739 tCsrScanResult *pResult;
6740 tANI_TIMESTAMP ageOutTime = (tANI_TIMESTAMP)(csrScanGetAgeOutTime(pMac) * PAL_TICKS_PER_SECOND); //turn it into 10ms units
6741 tANI_TIMESTAMP curTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
6742
6743 csrLLLock(&pMac->scan.scanResultList);
6744 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
6745 while( pEntry )
6746 {
6747 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
6748 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
6749 if((curTime - pResult->Result.BssDescriptor.nReceivedTime) > ageOutTime)
6750 {
6751 smsLog(pMac, LOGW, " age out due to time out");
6752 csrScanAgeOutBss(pMac, pResult);
6753 }
6754 pEntry = tmpEntry;
6755 }
6756 csrLLUnlock(&pMac->scan.scanResultList);
6757 }
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306758 vos_timer_start(&pMac->scan.hTimerResultAging, CSR_SCAN_RESULT_AGING_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006759}
6760
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006761static void csrScanResultCfgAgingTimerHandler(void *pv)
6762{
6763 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6764 tListElem *pEntry, *tmpEntry;
6765 tCsrScanResult *pResult;
6766 tANI_TIMESTAMP ageOutTime = pMac->scan.scanResultCfgAgingTime * PAL_TICKS_PER_SECOND;
6767 tANI_TIMESTAMP curTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
6768
6769 csrLLLock(&pMac->scan.scanResultList);
6770 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
6771 while( pEntry )
6772 {
6773 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
6774 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
6775 if((curTime - pResult->Result.BssDescriptor.nReceivedTime) > ageOutTime)
6776 {
6777 smsLog(pMac, LOGW, " age out due to time out");
6778 csrScanAgeOutBss(pMac, pResult);
6779 }
6780 pEntry = tmpEntry;
6781 }
6782 csrLLUnlock(&pMac->scan.scanResultList);
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306783 vos_timer_start(&pMac->scan.hTimerResultCfgAging, CSR_SCAN_RESULT_CFG_AGING_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006784}
Jeff Johnson295189b2012-06-20 16:38:30 -07006785
6786eHalStatus csrScanStartIdleScanTimer(tpAniSirGlobal pMac, tANI_U32 interval)
6787{
6788 eHalStatus status;
6789
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006790 smsLog(pMac, LOG1, " csrScanStartIdleScanTimer");
Jeff Johnson295189b2012-06-20 16:38:30 -07006791 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) && interval)
6792 {
6793 pMac->scan.nIdleScanTimeGap += interval;
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306794 vos_timer_stop(&pMac->scan.hTimerIdleScan);
6795 status = vos_timer_start(&pMac->scan.hTimerIdleScan, interval/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006796 if( !HAL_STATUS_SUCCESS(status) )
6797 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006798 smsLog(pMac, LOGE, " Fail to start Idle scan timer. status = %d interval = %d", status, interval);
Jeff Johnson295189b2012-06-20 16:38:30 -07006799 //This should not happen but set the flag to restart when ready
6800 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6801 }
6802 }
6803 else
6804 {
6805 if( pMac->scan.fScanEnable && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) )
6806 {
6807 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6808 }
6809 status = eHAL_STATUS_FAILURE;
6810 }
6811
6812 return (status);
6813}
6814
6815
6816eHalStatus csrScanStopIdleScanTimer(tpAniSirGlobal pMac)
6817{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306818 return (vos_timer_stop(&pMac->scan.hTimerIdleScan));
Jeff Johnson295189b2012-06-20 16:38:30 -07006819}
6820
6821
6822//Stop CSR from asking for IMPS, This function doesn't disable IMPS from CSR
6823void csrScanSuspendIMPS( tpAniSirGlobal pMac )
6824{
6825 csrScanCancelIdleScan(pMac);
6826}
6827
6828
6829//Start CSR from asking for IMPS. This function doesn't trigger CSR to request entering IMPS
6830//because IMPS maybe disabled.
6831void csrScanResumeIMPS( tpAniSirGlobal pMac )
6832{
6833 csrScanStartIdleScan( pMac );
6834}
6835
6836
6837void csrScanIMPSCallback(void *callbackContext, eHalStatus status)
6838{
6839 tpAniSirGlobal pMac = PMAC_STRUCT( callbackContext );
6840
6841 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6842 {
6843 if(pMac->roam.configParam.IsIdleScanEnabled)
6844 {
6845 if(HAL_STATUS_SUCCESS(status))
6846 {
6847 if(csrIsAllSessionDisconnected(pMac) && !csrIsRoamCommandWaiting(pMac))
6848 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006849 smsLog(pMac, LOGW, FL("starts idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006850 csrScanAllChannels(pMac, eCSR_SCAN_IDLE_MODE_SCAN);
6851 }
6852 else
6853 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006854 smsLog(pMac, LOGW, FL("cannot start idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006855 //even though we are in timer handle, calling stop timer will make sure the timer
6856 //doesn't get to restart.
6857 csrScanStopIdleScanTimer(pMac);
6858 }
6859 }
6860 else
6861 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006862 smsLog(pMac, LOGE, FL("sees not success status (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07006863 }
6864 }
6865 else
6866 {//we might need another flag to check if CSR needs to request imps at all
6867
6868 tANI_U32 nTime = 0;
6869
6870 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_FALSE;
6871 if(!HAL_STATUS_SUCCESS(csrScanTriggerIdleScan(pMac, &nTime)))
6872 {
6873 csrScanStartIdleScanTimer(pMac, nTime);
6874 }
6875 }
6876 }
6877}
6878
6879
Rashmi Ramanna68b309c2014-05-20 11:52:22 +05306880//Param: pTimeInterval -- Caller allocated memory in return, if failed, to specify the nxt time interval for
Jeff Johnson295189b2012-06-20 16:38:30 -07006881//idle scan timer interval
6882//Return: Not success -- meaning it cannot start IMPS, caller needs to start a timer for idle scan
6883eHalStatus csrScanTriggerIdleScan(tpAniSirGlobal pMac, tANI_U32 *pTimeInterval)
6884{
6885 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
6886
6887 //Do not trigger IMPS in case of concurrency
Agarwal Ashish5974ed32014-06-16 16:59:54 +05306888 if (vos_concurrent_open_sessions_running() &&
6889 csrIsAnySessionInConnectState(pMac))
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006890 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006891 smsLog( pMac, LOG1, FL("Cannot request IMPS because Concurrent Sessions Running") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006892 return (status);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006893 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006894
6895 if(pTimeInterval)
6896 {
6897 *pTimeInterval = 0;
6898 }
6899
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006900 smsLog(pMac, LOG3, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006901 if( smeCommandPending( pMac ) )
6902 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006903 smsLog( pMac, LOG1, FL(" Cannot request IMPS because command pending") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006904 //Not to enter IMPS because more work to do
6905 if(pTimeInterval)
6906 {
6907 *pTimeInterval = 0;
6908 }
6909 //restart when ready
6910 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6911
6912 return (status);
6913 }
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07006914 if (IsPmcImpsReqFailed (pMac))
6915 {
6916 if(pTimeInterval)
6917 {
6918 *pTimeInterval = 1000000; //usec
6919 }
6920 //restart when ready
6921 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006922
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07006923 return status;
6924 }
Rashmi Ramanna68b309c2014-05-20 11:52:22 +05306925
6926 if ( !pMac->deferImps && pMac->fDeferIMPSTime )
6927 {
6928 smsLog( pMac, LOG1, FL("Defer IMPS for %dms as command processed"),
6929 pMac->fDeferIMPSTime);
Girish Gowli4f3775a2014-05-30 17:17:08 +05306930 if(pTimeInterval)
6931 {
6932 *pTimeInterval = pMac->fDeferIMPSTime * 1000; //usec
6933 }
Rashmi Ramanna68b309c2014-05-20 11:52:22 +05306934 pMac->deferImps = eANI_BOOLEAN_TRUE;
6935 return status;
6936 }
6937
Jeff Johnson295189b2012-06-20 16:38:30 -07006938 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6939 /*&& pMac->roam.configParam.impsSleepTime*/)
6940 {
6941 //Stop get result timer because idle scan gets scan result out of PE
6942 csrScanStopGetResultTimer(pMac);
6943 if(pTimeInterval)
6944 {
6945 *pTimeInterval = pMac->roam.configParam.impsSleepTime;
6946 }
6947 //pmcRequestImps take a period in millisecond unit.
6948 status = pmcRequestImps(pMac, pMac->roam.configParam.impsSleepTime / PAL_TIMER_TO_MS_UNIT, csrScanIMPSCallback, pMac);
6949 if(!HAL_STATUS_SUCCESS(status))
6950 {
6951 if(eHAL_STATUS_PMC_ALREADY_IN_IMPS != status)
6952 {
6953 //Do restart the timer if CSR thinks it cannot do IMPS
6954 if( !csrCheckPSReady( pMac ) )
6955 {
6956 if(pTimeInterval)
6957 {
6958 *pTimeInterval = 0;
6959 }
6960 //Set the restart flag to true because that idle scan
6961 //can be restarted even though the timer will not be running
6962 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6963 }
6964 else
6965 {
6966 //For not now, we do a quicker retry
6967 if(pTimeInterval)
6968 {
6969 *pTimeInterval = CSR_IDLE_SCAN_WAIT_TIME;
6970 }
6971 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006972 smsLog(pMac, LOGW, FL("call pmcRequestImps and it returns status code (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07006973 }
6974 else
6975 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006976 smsLog(pMac, LOGW, FL("already in IMPS"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006977 //Since CSR is the only module to request for IMPS. If it is already in IMPS, CSR assumes
6978 //the callback will be called in the future. Should not happen though.
6979 status = eHAL_STATUS_SUCCESS;
6980 pMac->scan.nIdleScanTimeGap = 0;
6981 }
6982 }
6983 else
6984 {
6985 //requested so let's reset the value
6986 pMac->scan.nIdleScanTimeGap = 0;
6987 }
6988 }
6989
6990 return (status);
6991}
6992
6993
6994eHalStatus csrScanStartIdleScan(tpAniSirGlobal pMac)
6995{
6996 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
6997 tANI_U32 nTime = 0;
6998
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006999 smsLog(pMac, LOGW, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007000 if(pMac->roam.configParam.IsIdleScanEnabled)
7001 {
7002 //stop bg scan first
7003 csrScanBGScanAbort(pMac);
7004 //Stop get result timer because idle scan gets scan result out of PE
7005 csrScanStopGetResultTimer(pMac);
7006 //Enable aging timer since idle scan is going on
7007 csrScanStartResultAgingTimer(pMac);
7008 }
7009 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_FALSE;
7010 status = csrScanTriggerIdleScan(pMac, &nTime);
7011 if(!HAL_STATUS_SUCCESS(status))
7012 {
7013 csrScanStartIdleScanTimer(pMac, nTime);
7014 }
7015
7016 return (status);
7017}
7018
7019
7020void csrScanCancelIdleScan(tpAniSirGlobal pMac)
7021{
7022 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
7023 {
Agarwal Ashish5974ed32014-06-16 16:59:54 +05307024 if (vos_concurrent_open_sessions_running()) {
Jeff Johnson295189b2012-06-20 16:38:30 -07007025 return;
7026 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007027 smsLog(pMac, LOG1, " csrScanCancelIdleScan");
Jeff Johnson295189b2012-06-20 16:38:30 -07007028 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_TRUE;
7029 //Set the restart flag in case later on it is uncancelled
7030 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7031 csrScanStopIdleScanTimer(pMac);
7032 csrScanRemoveNotRoamingScanCommand(pMac);
7033 }
7034}
7035
7036
7037void csrScanIdleScanTimerHandler(void *pv)
7038{
7039 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
7040 eHalStatus status;
7041 tANI_U32 nTime = 0;
7042
7043 smsLog(pMac, LOGW, " csrScanIdleScanTimerHandler called ");
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07007044 pmcResetImpsFailStatus (pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07007045 status = csrScanTriggerIdleScan(pMac, &nTime);
7046 if(!HAL_STATUS_SUCCESS(status) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan))
7047 {
7048 //Check whether it is time to actually do an idle scan
7049 if(pMac->scan.nIdleScanTimeGap >= pMac->roam.configParam.impsSleepTime)
7050 {
7051 pMac->scan.nIdleScanTimeGap = 0;
7052 csrScanIMPSCallback(pMac, eHAL_STATUS_SUCCESS);
7053 }
7054 else
7055 {
7056 csrScanStartIdleScanTimer(pMac, nTime);
7057 }
7058 }
Rashmi Ramanna68b309c2014-05-20 11:52:22 +05307059 if(pMac->deferImps)
7060 {
7061 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
7062 pMac->deferImps = eANI_BOOLEAN_FALSE;
7063 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007064}
7065
7066
7067
7068
7069tANI_BOOLEAN csrScanRemoveNotRoamingScanCommand(tpAniSirGlobal pMac)
7070{
7071 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
7072 tListElem *pEntry, *pEntryTmp;
7073 tSmeCmd *pCommand;
7074 tDblLinkList localList;
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307075 tDblLinkList *pCmdList;
Jeff Johnson295189b2012-06-20 16:38:30 -07007076
7077 vos_mem_zero(&localList, sizeof(tDblLinkList));
7078 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
7079 {
7080 smsLog(pMac, LOGE, FL(" failed to open list"));
7081 return fRet;
7082 }
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307083 if (!pMac->fScanOffload)
7084 pCmdList = &pMac->sme.smeCmdPendingList;
7085 else
7086 pCmdList = &pMac->sme.smeScanCmdPendingList;
Jeff Johnson295189b2012-06-20 16:38:30 -07007087
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307088 csrLLLock(pCmdList);
7089 pEntry = csrLLPeekHead(pCmdList, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007090 while(pEntry)
7091 {
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307092 pEntryTmp = csrLLNext(pCmdList, pEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007093 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7094 if( eSmeCommandScan == pCommand->command )
7095 {
7096 switch( pCommand->u.scanCmd.reason )
7097 {
7098 case eCsrScanIdleScan:
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307099 if( csrLLRemoveEntry(pCmdList, pEntry, LL_ACCESS_NOLOCK) )
Jeff Johnson295189b2012-06-20 16:38:30 -07007100 {
7101 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
7102 }
7103 fRet = eANI_BOOLEAN_TRUE;
7104 break;
7105
7106 default:
7107 break;
7108 } //switch
7109 }
7110 pEntry = pEntryTmp;
7111 }
7112
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307113 csrLLUnlock(pCmdList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007114
7115 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
7116 {
7117 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7118 csrReleaseCommandScan( pMac, pCommand );
7119 }
7120
7121 csrLLClose(&localList);
7122
7123 return (fRet);
7124}
7125
7126
7127tANI_BOOLEAN csrScanRemoveFreshScanCommand(tpAniSirGlobal pMac, tANI_U8 sessionId)
7128{
7129 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
7130 tListElem *pEntry, *pEntryTmp;
7131 tSmeCmd *pCommand;
7132 tDblLinkList localList;
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307133 tDblLinkList *pCmdList;
Jeff Johnson295189b2012-06-20 16:38:30 -07007134
7135 vos_mem_zero(&localList, sizeof(tDblLinkList));
7136 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
7137 {
7138 smsLog(pMac, LOGE, FL(" failed to open list"));
7139 return fRet;
7140 }
7141
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307142 if (!pMac->fScanOffload)
7143 pCmdList = &pMac->sme.smeCmdPendingList;
7144 else
7145 pCmdList = &pMac->sme.smeScanCmdPendingList;
7146
7147 csrLLLock(pCmdList);
7148 pEntry = csrLLPeekHead(pCmdList, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007149 while(pEntry)
7150 {
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307151 pEntryTmp = csrLLNext(pCmdList, pEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007152 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7153 if( (eSmeCommandScan == pCommand->command) && (sessionId == pCommand->sessionId) )
7154 {
7155 switch(pCommand->u.scanCmd.reason)
7156 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07007157#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
7158 case eCsrScanGetLfrResult:
7159#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07007160 case eCsrScanGetResult:
7161 case eCsrScanSetBGScanParam:
7162 case eCsrScanBGScanAbort:
7163 case eCsrScanBGScanEnable:
7164 case eCsrScanGetScanChnInfo:
7165 break;
7166 default:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007167 smsLog (pMac, LOGW, "%s: -------- abort scan command reason = %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007168 __func__, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07007169 //The rest are fresh scan requests
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307170 if( csrLLRemoveEntry(pCmdList, pEntry, LL_ACCESS_NOLOCK) )
Jeff Johnson295189b2012-06-20 16:38:30 -07007171 {
7172 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
7173 }
7174 fRet = eANI_BOOLEAN_TRUE;
7175 break;
7176 }
7177 }
7178 pEntry = pEntryTmp;
7179 }
7180
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307181 csrLLUnlock(pCmdList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007182
7183 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
7184 {
7185 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7186 if (pCommand->u.scanCmd.callback)
7187 {
7188 /* User scan request is pending,
7189 * send response with status eCSR_SCAN_ABORT*/
7190 pCommand->u.scanCmd.callback(pMac,
7191 pCommand->u.scanCmd.pContext,
7192 pCommand->u.scanCmd.scanID,
7193 eCSR_SCAN_ABORT);
7194 }
7195 csrReleaseCommandScan( pMac, pCommand );
7196 }
7197 csrLLClose(&localList);
7198
7199 return (fRet);
7200}
7201
7202
7203void csrReleaseScanCommand(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
7204{
7205 eCsrScanReason reason = pCommand->u.scanCmd.reason;
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307206 tANI_BOOLEAN status;
7207
7208 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07007209 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307210 tANI_U32 i;
7211 for(i = 0; i < CSR_ROAM_SESSION_MAX; i++)
7212 csrRoamStateChange(pMac, pCommand->u.scanCmd.lastRoamState[i], i);
7213 }
7214 else
7215 {
7216 csrRoamStateChange(pMac,
7217 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId],
7218 pCommand->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07007219 }
7220
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307221 csrScanCallCallback(pMac, pCommand, scanStatus);
Jeff Johnson295189b2012-06-20 16:38:30 -07007222
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007223 smsLog(pMac, LOG3, " Remove Scan command reason = %d", reason);
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307224 if (pMac->fScanOffload)
7225 {
7226 status = csrLLRemoveEntry(&pMac->sme.smeScanCmdActiveList,
7227 &pCommand->Link, LL_ACCESS_LOCK);
7228 }
7229 else
7230 {
7231 status = csrLLRemoveEntry(&pMac->sme.smeCmdActiveList,
7232 &pCommand->Link, LL_ACCESS_LOCK);
7233 }
7234
7235 if(status)
Jeff Johnson295189b2012-06-20 16:38:30 -07007236 {
7237 csrReleaseCommandScan( pMac, pCommand );
7238 }
7239 else
7240 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307241 smsLog(pMac, LOGE,
7242 " ********csrReleaseScanCommand cannot release command reason %d",
7243 pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07007244 }
7245}
7246
7247
7248eHalStatus csrScanGetPMKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
7249 tPmkidCandidateInfo *pPmkidList, tANI_U32 *pNumItems )
7250{
7251 eHalStatus status = eHAL_STATUS_SUCCESS;
7252 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
7253
Jeff Johnson32d95a32012-09-10 13:15:23 -07007254 if(!pSession)
7255 {
7256 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
7257 return eHAL_STATUS_FAILURE;
7258 }
7259
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007260 smsLog(pMac, LOGW, " pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07007261 csrResetPMKIDCandidateList(pMac, sessionId);
7262 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
7263 {
7264 tCsrScanResultFilter *pScanFilter;
7265 tCsrScanResultInfo *pScanResult;
7266 tScanResultHandle hBSSList;
7267 tANI_U32 nItems = *pNumItems;
7268
7269 *pNumItems = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05307270 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
7271 if ( NULL == pScanFilter )
7272 status = eHAL_STATUS_FAILURE;
7273 else
Jeff Johnson295189b2012-06-20 16:38:30 -07007274 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307275 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007276 //Here is the profile we need to connect to
7277 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
7278 if(HAL_STATUS_SUCCESS(status))
7279 {
7280 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
7281 if(HAL_STATUS_SUCCESS(status))
7282 {
7283 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumPmkidCandidate < nItems))
7284 {
7285 //NumPmkidCandidate adds up here
7286 csrProcessBSSDescForPMKIDList(pMac, &pScanResult->BssDescriptor,
7287 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
7288 }
7289 if(pSession->NumPmkidCandidate)
7290 {
7291 *pNumItems = pSession->NumPmkidCandidate;
Kiet Lam64c1b492013-07-12 13:56:44 +05307292 vos_mem_copy(pPmkidList, pSession->PmkidCandidateInfo,
7293 pSession->NumPmkidCandidate * sizeof(tPmkidCandidateInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07007294 }
7295 csrScanResultPurge(pMac, hBSSList);
7296 }//Have scan result
7297 csrFreeScanFilter(pMac, pScanFilter);
7298 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307299 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07007300 }
7301 }
7302
7303 return (status);
7304}
7305
7306
7307
7308#ifdef FEATURE_WLAN_WAPI
7309eHalStatus csrScanGetBKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
7310 tBkidCandidateInfo *pBkidList, tANI_U32 *pNumItems )
7311{
7312 eHalStatus status = eHAL_STATUS_SUCCESS;
7313 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
7314
Jeff Johnson32d95a32012-09-10 13:15:23 -07007315 if(!pSession)
7316 {
7317 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
7318 return eHAL_STATUS_FAILURE;
7319 }
7320
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007321 smsLog(pMac, LOGW, " pMac->scan.NumBkidCandidate = %d", pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07007322 csrResetBKIDCandidateList(pMac, sessionId);
7323 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
7324 {
7325 tCsrScanResultFilter *pScanFilter;
7326 tCsrScanResultInfo *pScanResult;
7327 tScanResultHandle hBSSList;
7328 tANI_U32 nItems = *pNumItems;
7329 *pNumItems = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05307330 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
7331 if ( NULL == pScanFilter )
7332 status = eHAL_STATUS_FAILURE;
7333 else
Jeff Johnson295189b2012-06-20 16:38:30 -07007334 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307335 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007336 //Here is the profile we need to connect to
7337 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
7338 if(HAL_STATUS_SUCCESS(status))
7339 {
7340 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
7341 if(HAL_STATUS_SUCCESS(status))
7342 {
7343 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumBkidCandidate < nItems))
7344 {
7345 //pMac->scan.NumBkidCandidate adds up here
7346 csrProcessBSSDescForBKIDList(pMac, &pScanResult->BssDescriptor,
7347 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
7348
7349 }
7350 if(pSession->NumBkidCandidate)
7351 {
7352 *pNumItems = pSession->NumBkidCandidate;
Kiet Lam64c1b492013-07-12 13:56:44 +05307353 vos_mem_copy(pBkidList, pSession->BkidCandidateInfo, pSession->NumBkidCandidate * sizeof(tBkidCandidateInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07007354 }
7355 csrScanResultPurge(pMac, hBSSList);
7356 }//Have scan result
7357 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307358 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07007359 }
7360 }
7361
7362 return (status);
7363}
7364#endif /* FEATURE_WLAN_WAPI */
7365
7366
7367
7368//This function is usually used for BSSs that suppresses SSID so the profile
7369//shall have one and only one SSID
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007370eHalStatus csrScanForSSID(tpAniSirGlobal pMac, tANI_U32 sessionId, tCsrRoamProfile *pProfile, tANI_U32 roamId, tANI_BOOLEAN notify)
Jeff Johnson295189b2012-06-20 16:38:30 -07007371{
7372 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
7373 tSmeCmd *pScanCmd = NULL;
7374 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
7375 tANI_U8 index = 0;
7376 tANI_U32 numSsid = pProfile->SSIDs.numOfSSIDs;
7377
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007378 smsLog(pMac, LOG2, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007379 //For WDS, we use the index 0. There must be at least one in there
7380 if( CSR_IS_WDS_STA( pProfile ) && numSsid )
7381 {
7382 numSsid = 1;
7383 }
7384 if(pMac->scan.fScanEnable && ( numSsid == 1 ) )
7385 {
7386 do
7387 {
7388 pScanCmd = csrGetCommandBuffer(pMac);
7389 if(!pScanCmd)
7390 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007391 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007392 break;
7393 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307394 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
7395 pScanCmd->u.scanCmd.pToRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
7396 if ( NULL == pScanCmd->u.scanCmd.pToRoamProfile )
krunal soni587bf012014-02-04 12:35:11 -08007397 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307398 status = eHAL_STATUS_FAILURE;
krunal soni587bf012014-02-04 12:35:11 -08007399 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307400 else
krunal soni587bf012014-02-04 12:35:11 -08007401 {
7402 status = csrRoamCopyProfile(pMac, pScanCmd->u.scanCmd.pToRoamProfile, pProfile);
7403 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007404 if(!HAL_STATUS_SUCCESS(status))
7405 break;
7406 pScanCmd->u.scanCmd.roamId = roamId;
7407 pScanCmd->command = eSmeCommandScan;
Jeff Johnsone7245742012-09-05 17:12:55 -07007408 pScanCmd->sessionId = (tANI_U8)sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07007409 pScanCmd->u.scanCmd.callback = NULL;
7410 pScanCmd->u.scanCmd.pContext = NULL;
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007411 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 -07007412 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Kiet Lam64c1b492013-07-12 13:56:44 +05307413 vos_mem_set(&pScanCmd->u.scanCmd.u.scanRequest, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007414 pScanCmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Jeff Johnson295189b2012-06-20 16:38:30 -07007415 pScanCmd->u.scanCmd.u.scanRequest.BSSType = pProfile->BSSType;
Jeff Johnsone7245742012-09-05 17:12:55 -07007416 // To avoid 11b rate in probe request Set p2pSearch flag as 1 for P2P Client Mode
7417 if(VOS_P2P_CLIENT_MODE == pProfile->csrPersona)
7418 {
7419 pScanCmd->u.scanCmd.u.scanRequest.p2pSearch = 1;
7420 }
Agarwal Ashish4f616132013-12-30 23:32:50 +05307421 if(pProfile->nAddIEScanLength)
Jeff Johnsone7245742012-09-05 17:12:55 -07007422 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307423 pScanCmd->u.scanCmd.u.scanRequest.pIEField = vos_mem_malloc(
7424 pProfile->nAddIEScanLength);
7425 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.pIEField )
7426 status = eHAL_STATUS_FAILURE;
7427 else
7428 status = eHAL_STATUS_SUCCESS;
7429 vos_mem_set(pScanCmd->u.scanCmd.u.scanRequest.pIEField,
7430 pProfile->nAddIEScanLength, 0);
7431 if (HAL_STATUS_SUCCESS(status))
Jeff Johnsone7245742012-09-05 17:12:55 -07007432 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307433 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.pIEField,
Agarwal Ashish4f616132013-12-30 23:32:50 +05307434 pProfile->addIEScan, pProfile->nAddIEScanLength);
Jeff Johnsone7245742012-09-05 17:12:55 -07007435 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = pProfile->nAddIEScanLength;
7436 }
7437 else
7438 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007439 smsLog(pMac, LOGE, "No memory for scanning IE fields");
Jeff Johnsone7245742012-09-05 17:12:55 -07007440 }
7441 } //Allocate memory for IE field
7442 else
7443 {
7444 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = 0;
7445 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07007446 /* For one channel be good enpugh time to receive beacon atleast */
7447 if( 1 == pProfile->ChannelInfo.numOfChannels )
7448 {
7449 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime = MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7450 pScanCmd->u.scanCmd.u.scanRequest.minChnTime = MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7451 }
7452 else
7453 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307454 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime =
7455 pMac->roam.configParam.nActiveMaxChnTime;
7456 pScanCmd->u.scanCmd.u.scanRequest.minChnTime =
7457 pMac->roam.configParam.nActiveMinChnTime;
Jeff Johnson32d95a32012-09-10 13:15:23 -07007458 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307459 pScanCmd->u.scanCmd.u.scanRequest.maxChnTimeBtc =
7460 pMac->roam.configParam.nActiveMaxChnTimeBtc;
7461 pScanCmd->u.scanCmd.u.scanRequest.minChnTimeBtc =
7462 pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07007463 if(pProfile->BSSIDs.numOfBSSIDs == 1)
7464 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307465 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.bssid,
7466 pProfile->BSSIDs.bssid, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07007467 }
7468 else
7469 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307470 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.bssid, bAddr, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07007471 }
7472 if(pProfile->ChannelInfo.numOfChannels)
7473 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307474 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(
7475 sizeof(*pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
7476 * pProfile->ChannelInfo.numOfChannels);
7477 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
7478 status = eHAL_STATUS_FAILURE;
7479 else
7480 status = eHAL_STATUS_SUCCESS;
7481 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
7482 if(HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07007483 {
7484 csrRoamIsChannelValid(pMac, pProfile->ChannelInfo.ChannelList[0]);
7485 for(index = 0; index < pProfile->ChannelInfo.numOfChannels; index++)
7486 {
7487 if(csrRoamIsValidChannel(pMac, pProfile->ChannelInfo.ChannelList[index]))
7488 {
7489 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels]
7490 = pProfile->ChannelInfo.ChannelList[index];
7491 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels++;
7492 }
7493 else
7494 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007495 smsLog(pMac, LOGW, FL("process a channel (%d) that is invalid"), pProfile->ChannelInfo.ChannelList[index]);
Jeff Johnson295189b2012-06-20 16:38:30 -07007496 }
7497
7498 }
7499 }
7500 else
7501 {
7502 break;
7503 }
7504
7505 }
7506 else
7507 {
7508 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
7509 }
7510 if(pProfile->SSIDs.numOfSSIDs)
7511 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307512 pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList = vos_mem_malloc(
7513 pProfile->SSIDs.numOfSSIDs * sizeof(tCsrSSIDInfo));
7514 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList )
7515 status = eHAL_STATUS_FAILURE;
7516 else
7517 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07007518 if(!HAL_STATUS_SUCCESS(status))
7519 {
7520 break;
7521 }
7522 pScanCmd->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 1;
Kiet Lam64c1b492013-07-12 13:56:44 +05307523 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList,
7524 pProfile->SSIDs.SSIDList, sizeof(tCsrSSIDInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07007525 }
7526 //Start process the command
7527 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
7528 if( !HAL_STATUS_SUCCESS( status ) )
7529 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007530 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07007531 break;
7532 }
7533 }while(0);
7534 if(!HAL_STATUS_SUCCESS(status))
7535 {
7536 if(pScanCmd)
7537 {
7538 csrReleaseCommandScan(pMac, pScanCmd);
7539 //TODO:free the memory that is allocated in this function
7540 }
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007541 if(notify)
7542 {
Jeff Johnson295189b2012-06-20 16:38:30 -07007543 csrRoamCallCallback(pMac, sessionId, NULL, roamId, eCSR_ROAM_FAILED, eCSR_ROAM_RESULT_FAILURE);
7544 }
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007545 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007546 }//valid
7547 else
7548 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007549 smsLog(pMac, LOGE, FL("cannot scan because scanEnable (%d) or numSSID (%d) is invalid"),
Jeff Johnson295189b2012-06-20 16:38:30 -07007550 pMac->scan.fScanEnable, pProfile->SSIDs.numOfSSIDs);
7551 }
7552
7553 return (status);
7554}
7555
7556
7557//Issue a scan base on the new capability infomation
7558//This should only happen when the associated AP changes its capability.
7559//After this scan is done, CSR reroams base on the new scan results
7560eHalStatus csrScanForCapabilityChange(tpAniSirGlobal pMac, tSirSmeApNewCaps *pNewCaps)
7561{
7562 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
7563 tSmeCmd *pScanCmd = NULL;
7564
7565 if(pNewCaps)
7566 {
7567 do
7568 {
7569 pScanCmd = csrGetCommandBuffer(pMac);
7570 if(!pScanCmd)
7571 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007572 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007573 status = eHAL_STATUS_RESOURCES;
7574 break;
7575 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307576 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007577 status = eHAL_STATUS_SUCCESS;
7578 pScanCmd->u.scanCmd.roamId = 0;
7579 pScanCmd->command = eSmeCommandScan;
7580 pScanCmd->u.scanCmd.callback = NULL;
7581 pScanCmd->u.scanCmd.pContext = NULL;
7582 pScanCmd->u.scanCmd.reason = eCsrScanForCapsChange;
7583 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
7584 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
7585 if( !HAL_STATUS_SUCCESS( status ) )
7586 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007587 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07007588 break;
7589 }
7590 }while(0);
7591 if(!HAL_STATUS_SUCCESS(status))
7592 {
7593 if(pScanCmd)
7594 {
7595 csrReleaseCommandScan(pMac, pScanCmd);
7596 }
7597 }
7598 }
7599
7600 return (status);
7601}
7602
7603
7604
7605void csrInitBGScanChannelList(tpAniSirGlobal pMac)
7606{
7607 tANI_U32 len = CSR_MIN(sizeof(pMac->roam.validChannelList), sizeof(pMac->scan.bgScanChannelList));
7608
Kiet Lam64c1b492013-07-12 13:56:44 +05307609 vos_mem_set(pMac->scan.bgScanChannelList, len, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007610 pMac->scan.numBGScanChannel = 0;
7611
7612 if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
7613 {
7614 pMac->roam.numValidChannels = len;
7615 pMac->scan.numBGScanChannel = (tANI_U8)CSR_MIN(len, WNI_CFG_BG_SCAN_CHANNEL_LIST_LEN);
Kiet Lam64c1b492013-07-12 13:56:44 +05307616 vos_mem_copy(pMac->scan.bgScanChannelList, pMac->roam.validChannelList,
7617 pMac->scan.numBGScanChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07007618 csrSetBGScanChannelList(pMac, pMac->scan.bgScanChannelList, pMac->scan.numBGScanChannel);
7619 }
7620}
7621
7622
7623//This function return TRUE if background scan channel list is adjusted.
7624//this function will only shrink the background scan channel list
7625tANI_BOOLEAN csrAdjustBGScanChannelList(tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels,
7626 tANI_U8 *pAdjustChannels, tANI_U8 *pNumAdjustChannels)
7627{
7628 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
7629 tANI_U8 i, j, count = *pNumAdjustChannels;
7630
7631 i = 0;
7632 while(i < count)
7633 {
7634 for(j = 0; j < NumChannels; j++)
7635 {
7636 if(pChannelList[j] == pAdjustChannels[i])
7637 break;
7638 }
7639 if(j == NumChannels)
7640 {
7641 //This channel is not in the list, remove it
7642 fRet = eANI_BOOLEAN_TRUE;
7643 count--;
7644 if(count - i)
7645 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307646 vos_mem_copy(&pAdjustChannels[i], &pAdjustChannels[i+1], count - i);
Jeff Johnson295189b2012-06-20 16:38:30 -07007647 }
7648 else
7649 {
7650 //already remove the last one. Done.
7651 break;
7652 }
7653 }
7654 else
7655 {
7656 i++;
7657 }
7658 }//while(i<count)
7659 *pNumAdjustChannels = count;
7660
7661 return (fRet);
7662}
7663
7664
7665//Get the list of the base channels to scan for passively 11d info
7666eHalStatus csrScanGetSupportedChannels( tpAniSirGlobal pMac )
7667{
7668 eHalStatus status = eHAL_STATUS_SUCCESS;
7669 int n = WNI_CFG_VALID_CHANNEL_LIST_LEN;
7670
7671 status = vos_nv_getSupportedChannels( pMac->scan.baseChannels.channelList, &n, NULL, NULL );
7672 if( HAL_STATUS_SUCCESS(status) )
7673 {
7674 pMac->scan.baseChannels.numChannels = (tANI_U8)n;
7675 }
7676 else
7677 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007678 smsLog( pMac, LOGE, FL(" failed") );
Jeff Johnson295189b2012-06-20 16:38:30 -07007679 pMac->scan.baseChannels.numChannels = 0;
7680 }
7681
7682 return ( status );
7683}
7684
7685//This function use the input pChannelList to validate the current saved channel list
7686eHalStatus csrSetBGScanChannelList( tpAniSirGlobal pMac, tANI_U8 *pAdjustChannels, tANI_U8 NumAdjustChannels)
7687{
7688 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumAdjustChannels;
7689
7690 return (ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pAdjustChannels, dataLen, NULL, eANI_BOOLEAN_FALSE));
7691}
7692
7693
7694void csrSetCfgValidChannelList( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels )
7695{
7696 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumChannels;
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05307697 eHalStatus status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007698
Mihir Shete31c435d2014-02-12 13:13:34 +05307699 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
7700 "%s: dump valid channel list(NumChannels(%d))",
7701 __func__,NumChannels);
7702 VOS_TRACE_HEX_DUMP(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
7703 pChannelList, NumChannels);
7704
Jeff Johnson295189b2012-06-20 16:38:30 -07007705 ccmCfgSetStr(pMac, WNI_CFG_VALID_CHANNEL_LIST, pChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
Leela Venkata Kiran Kumar Reddy Chiralac6663f72014-02-03 21:04:58 -08007706#ifdef QCA_WIFI_2_0
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05307707 if (pMac->fScanOffload)
7708 {
7709 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
7710 "Scan offload is enabled, update default chan list");
Leela Venkata Kiran Kumar Reddy Chiralac6663f72014-02-03 21:04:58 -08007711 status = csrUpdateChannelList(pMac);
7712 }
7713#else
7714 status = csrUpdateChannelList(pMac);
7715#endif
7716
7717 if (eHAL_STATUS_SUCCESS != status)
7718 {
7719 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR,
7720 "failed to update the supported channel list");
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05307721 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007722 return;
7723}
7724
7725
7726
7727/*
7728 * The Tx power limits are saved in the cfg for future usage.
7729 */
7730void csrSaveTxPowerToCfg( tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 cfgId )
7731{
7732 tListElem *pEntry;
7733 tANI_U32 cbLen = 0, dataLen;
7734 tCsrChannelPowerInfo *pChannelSet;
7735 tANI_U32 idx;
7736 tSirMacChanInfo *pChannelPowerSet;
7737 tANI_U8 *pBuf = NULL;
7738
7739 //allocate maximum space for all channels
7740 dataLen = WNI_CFG_VALID_CHANNEL_LIST_LEN * sizeof(tSirMacChanInfo);
Kiet Lam64c1b492013-07-12 13:56:44 +05307741 if ( (pBuf = vos_mem_malloc(dataLen)) != NULL )
Jeff Johnson295189b2012-06-20 16:38:30 -07007742 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307743 vos_mem_set(pBuf, dataLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007744 pChannelPowerSet = (tSirMacChanInfo *)(pBuf);
7745
7746 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
7747 // write the tuples (startChan, numChan, txPower) for each channel found in the channel power list.
7748 while( pEntry )
7749 {
7750 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
7751 if ( 1 != pChannelSet->interChannelOffset )
7752 {
7753 // we keep the 5G channel sets internally with an interchannel offset of 4. Expand these
7754 // to the right format... (inter channel offset of 1 is the only option for the triplets
7755 // that 11d advertises.
7756 if ((cbLen + (pChannelSet->numChannels * sizeof(tSirMacChanInfo))) >= dataLen)
7757 {
7758 // expanding this entry will overflow our allocation
7759 smsLog(pMac, LOGE,
7760 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007761 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07007762 pChannelSet->firstChannel,
7763 pChannelSet->numChannels,
7764 pChannelSet->interChannelOffset);
7765 break;
7766 }
7767
7768 for( idx = 0; idx < pChannelSet->numChannels; idx++ )
7769 {
7770 pChannelPowerSet->firstChanNum = (tSirMacChanNum)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007771 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07007772 pChannelPowerSet->numChannels = 1;
Jeff Johnson295189b2012-06-20 16:38:30 -07007773 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007774 smsLog(pMac, LOG3, " Setting Max Transmit Power %d", pChannelPowerSet->maxTxPower);
Jeff Johnson295189b2012-06-20 16:38:30 -07007775 cbLen += sizeof( tSirMacChanInfo );
7776 pChannelPowerSet++;
7777 }
7778 }
7779 else
7780 {
7781 if (cbLen >= dataLen)
7782 {
7783 // this entry will overflow our allocation
7784 smsLog(pMac, LOGE,
7785 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007786 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07007787 pChannelSet->firstChannel,
7788 pChannelSet->numChannels,
7789 pChannelSet->interChannelOffset);
7790 break;
7791 }
7792 pChannelPowerSet->firstChanNum = pChannelSet->firstChannel;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007793 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07007794 pChannelPowerSet->numChannels = pChannelSet->numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -07007795 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007796 smsLog(pMac, LOG3, " Setting Max Transmit Power %d, nTxPower %d", pChannelPowerSet->maxTxPower,pMac->roam.configParam.nTxPowerCap );
Jeff Johnson295189b2012-06-20 16:38:30 -07007797
7798
7799 cbLen += sizeof( tSirMacChanInfo );
7800 pChannelPowerSet++;
7801 }
7802
7803 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
7804 }
7805
7806 if(cbLen)
7807 {
7808 ccmCfgSetStr(pMac, cfgId, (tANI_U8 *)pBuf, cbLen, NULL, eANI_BOOLEAN_FALSE);
7809 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307810 vos_mem_free(pBuf);
Jeff Johnson295189b2012-06-20 16:38:30 -07007811 }//Allocate memory
7812}
7813
7814
7815void csrSetCfgCountryCode( tpAniSirGlobal pMac, tANI_U8 *countryCode )
7816{
7817 tANI_U8 cc[WNI_CFG_COUNTRY_CODE_LEN];
7818 ///v_REGDOMAIN_t DomainId;
7819
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007820 smsLog( pMac, LOG3, "Setting Country Code in Cfg from csrSetCfgCountryCode %s",countryCode );
Kiet Lam64c1b492013-07-12 13:56:44 +05307821 vos_mem_copy(cc, countryCode, WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07007822
7823 // don't program the bogus country codes that we created for Korea in the MAC. if we see
7824 // the bogus country codes, program the MAC with the right country code.
7825 if ( ( 'K' == countryCode[ 0 ] && '1' == countryCode[ 1 ] ) ||
7826 ( 'K' == countryCode[ 0 ] && '2' == countryCode[ 1 ] ) ||
7827 ( 'K' == countryCode[ 0 ] && '3' == countryCode[ 1 ] ) ||
7828 ( 'K' == countryCode[ 0 ] && '4' == countryCode[ 1 ] ) )
7829 {
7830 // replace the alternate Korea country codes, 'K1', 'K2', .. with 'KR' for Korea
7831 cc[ 1 ] = 'R';
7832 }
7833 ccmCfgSetStr(pMac, WNI_CFG_COUNTRY_CODE, cc, WNI_CFG_COUNTRY_CODE_LEN, NULL, eANI_BOOLEAN_FALSE);
7834
7835 //Need to let HALPHY know about the current domain so it can apply some
7836 //domain-specific settings (TX filter...)
7837 /*if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(pMac, cc, &DomainId)))
7838 {
7839 halPhySetRegDomain(pMac, DomainId);
7840 }*/
7841}
7842
7843
7844
7845eHalStatus csrGetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pBuf, tANI_U8 *pbLen)
7846{
7847 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
7848 tANI_U32 len;
7849
7850 if(pBuf && pbLen && (*pbLen >= WNI_CFG_COUNTRY_CODE_LEN))
7851 {
7852 len = *pbLen;
7853 status = ccmCfgGetStr(pMac, WNI_CFG_COUNTRY_CODE, pBuf, &len);
7854 if(HAL_STATUS_SUCCESS(status))
7855 {
7856 *pbLen = (tANI_U8)len;
7857 }
7858 }
7859
7860 return (status);
7861}
7862
7863
7864void csrSetCfgScanControlList( tpAniSirGlobal pMac, tANI_U8 *countryCode, tCsrChannel *pChannelList )
7865{
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05307866 tANI_U8 i, j, k;
Jeff Johnson295189b2012-06-20 16:38:30 -07007867 tANI_BOOLEAN found=FALSE;
7868 tANI_U8 *pControlList = NULL;
7869 tANI_U32 len = WNI_CFG_SCAN_CONTROL_LIST_LEN;
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05307870 tANI_U8 cfgActiveDFSChannels = 0;
7871 tANI_U8 *cfgActiveDFSChannelLIst = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07007872
Kiet Lam64c1b492013-07-12 13:56:44 +05307873 if ( (pControlList = vos_mem_malloc(WNI_CFG_SCAN_CONTROL_LIST_LEN)) != NULL )
Jeff Johnson295189b2012-06-20 16:38:30 -07007874 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307875 vos_mem_set((void *)pControlList, WNI_CFG_SCAN_CONTROL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007876 if(HAL_STATUS_SUCCESS(ccmCfgGetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, &len)))
7877 {
7878 for (i = 0; i < pChannelList->numChannels; i++)
7879 {
7880 for (j = 0; j < len; j += 2)
7881 {
7882 if (pControlList[j] == pChannelList->channelList[i])
7883 {
7884 found = TRUE;
7885 break;
7886 }
7887 }
7888
7889 if (found) // insert a pair(channel#, flag)
7890 {
Gopichand Nakkala392cbc12013-05-28 16:15:00 +05307891 pControlList[j+1] = csrGetScanType(pMac, pControlList[j]);
Jeff Johnson295189b2012-06-20 16:38:30 -07007892 found = FALSE; // reset the flag
Jeff Johnson295189b2012-06-20 16:38:30 -07007893
Padma, Santhosh Kumar778d8382015-03-04 17:41:22 +05307894 // When DFS mode is 2, mark static channels as active
7895 if (pMac->scan.fEnableDFSChnlScan ==
7896 DFS_CHNL_SCAN_ENABLED_ACTIVE)
7897 {
7898 cfgActiveDFSChannels =
7899 pMac->roam.neighborRoamInfo.cfgParams.
7900 channelInfo.numOfChannels;
7901 cfgActiveDFSChannelLIst =
7902 pMac->roam.neighborRoamInfo.cfgParams.
7903 channelInfo.ChannelList;
7904 if (cfgActiveDFSChannelLIst)
7905 {
7906 for (k=0; k < cfgActiveDFSChannels; k++)
7907 {
7908 if(CSR_IS_CHANNEL_DFS(cfgActiveDFSChannelLIst[k])
7909 && (pControlList[j] ==
7910 cfgActiveDFSChannelLIst[k]))
7911 {
7912 pControlList[j+1] = eSIR_ACTIVE_SCAN;
7913 smsLog(pMac, LOG1, FL("Marked DFS ch %d"
7914 " as active"),
7915 cfgActiveDFSChannelLIst[k]);
7916 }
7917 }
7918 }
7919 }
7920 }
7921 }
7922
7923 smsLog(pMac, LOG1, FL("fEnableDFSChnlScan %d"),
7924 pMac->scan.fEnableDFSChnlScan);
Mihir Shete31c435d2014-02-12 13:13:34 +05307925 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
7926 "%s: dump scan control list",__func__);
7927 VOS_TRACE_HEX_DUMP(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
7928 pControlList, len);
7929
Jeff Johnson295189b2012-06-20 16:38:30 -07007930 ccmCfgSetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, len, NULL, eANI_BOOLEAN_FALSE);
7931 }//Successfully getting scan control list
Kiet Lam64c1b492013-07-12 13:56:44 +05307932 vos_mem_free(pControlList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007933 }//AllocateMemory
7934}
7935
Jeff Johnson295189b2012-06-20 16:38:30 -07007936//if bgPeriod is 0, background scan is disabled. It is in millisecond units
7937eHalStatus csrSetCfgBackgroundScanPeriod(tpAniSirGlobal pMac, tANI_U32 bgPeriod)
7938{
7939 return (ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, bgPeriod, (tCcmCfgSetCallback) csrScanCcmCfgSetCallback, eANI_BOOLEAN_FALSE));
7940}
7941
7942
7943void csrScanCcmCfgSetCallback(tHalHandle hHal, tANI_S32 result)
7944{
7945 tListElem *pEntry = NULL;
7946 tSmeCmd *pCommand = NULL;
7947 tpAniSirGlobal pMac = PMAC_STRUCT( hHal );
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307948 tDblLinkList *pCmdList ;
7949
7950 if (!pMac->fScanOffload)
7951 pCmdList = &pMac->sme.smeCmdActiveList;
7952 else
7953 pCmdList = &pMac->sme.smeScanCmdActiveList;
7954
7955 pEntry = csrLLPeekHead( pCmdList, LL_ACCESS_LOCK );
Jeff Johnson295189b2012-06-20 16:38:30 -07007956 if ( pEntry )
7957 {
7958 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7959 if ( eSmeCommandScan == pCommand->command )
7960 {
7961 eCsrScanStatus scanStatus = (CCM_IS_RESULT_SUCCESS(result)) ? eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
7962 csrReleaseScanCommand(pMac, pCommand, scanStatus);
7963 }
7964 else
7965 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007966 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
Jeff Johnson295189b2012-06-20 16:38:30 -07007967 }
7968 }
7969 smeProcessPendingQueue( pMac );
7970}
7971
7972eHalStatus csrProcessSetBGScanParam(tpAniSirGlobal pMac, tSmeCmd *pCommand)
7973{
7974 eHalStatus status;
7975 tCsrBGScanRequest *pScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
7976 tANI_U32 dataLen = sizeof( tANI_U8 ) * pScanReq->ChannelInfo.numOfChannels;
7977
7978 //***setcfg for background scan channel list
7979 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MINIMUM_CHANNEL_TIME, pScanReq->minChnTime, NULL, eANI_BOOLEAN_FALSE);
7980 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MAXIMUM_CHANNEL_TIME, pScanReq->maxChnTime, NULL, eANI_BOOLEAN_FALSE);
7981 //Not set the background scan interval if not connected because bd scan should not be run if not connected
7982 if(!csrIsAllSessionDisconnected(pMac))
7983 {
7984 //If disbaling BG scan here, we need to stop aging as well
7985 if(pScanReq->scanInterval == 0)
7986 {
7987 //Stop aging because no new result is coming in
7988 csrScanStopResultAgingTimer(pMac);
7989 }
7990
7991#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
7992 {
7993 vos_log_scan_pkt_type *pScanLog = NULL;
7994
7995 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
7996 if(pScanLog)
7997 {
7998 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
7999 pScanLog->minChnTime = (v_U8_t)pScanReq->minChnTime;
8000 pScanLog->maxChnTime = (v_U8_t)pScanReq->maxChnTime;
8001 pScanLog->timeBetweenBgScan = (v_U8_t)pScanReq->scanInterval;
8002 pScanLog->numChannel = pScanReq->ChannelInfo.numOfChannels;
8003 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
8004 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308005 vos_mem_copy(pScanLog->channels,
8006 pScanReq->ChannelInfo.ChannelList,
8007 pScanLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07008008 }
8009 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
8010 }
8011 }
8012#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
8013
8014 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, pScanReq->scanInterval, NULL, eANI_BOOLEAN_FALSE);
8015 }
8016 else
8017 {
8018 //No need to stop aging because IDLE scan is still running
8019 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, 0, NULL, eANI_BOOLEAN_FALSE);
8020 }
8021
8022 if(pScanReq->SSID.length > WNI_CFG_SSID_LEN)
8023 {
8024 pScanReq->SSID.length = WNI_CFG_SSID_LEN;
8025 }
8026
8027 status = ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pScanReq->ChannelInfo.ChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
8028 status = ccmCfgSetStr(pMac, WNI_CFG_SSID, (tANI_U8 *)pScanReq->SSID.ssId, pScanReq->SSID.length, NULL, eANI_BOOLEAN_FALSE);
8029
8030
8031
8032 return (status);
8033}
8034
8035
c_hpothua3d45d52015-01-05 14:11:17 +05308036tSirAbortScanStatus csrScanAbortMacScan(tpAniSirGlobal pMac,
8037 tANI_U8 sessionId,
8038 eCsrAbortReason reason)
Jeff Johnson295189b2012-06-20 16:38:30 -07008039{
c_hpothua3d45d52015-01-05 14:11:17 +05308040 tSirAbortScanStatus abortScanStatus = eSIR_ABORT_ACTIVE_SCAN_LIST_EMPTY;
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308041 tSirSmeScanAbortReq *pMsg;
Jeff Johnson295189b2012-06-20 16:38:30 -07008042 tANI_U16 msgLen;
8043 tListElem *pEntry;
8044 tSmeCmd *pCommand;
8045
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308046 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07008047 {
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308048#ifdef WLAN_AP_STA_CONCURRENCY
8049 csrLLLock(&pMac->scan.scanCmdPendingList);
8050 while(NULL !=
8051 (pEntry = csrLLRemoveHead(&pMac->scan.scanCmdPendingList,
8052 LL_ACCESS_NOLOCK)))
8053 {
Jeff Johnson295189b2012-06-20 16:38:30 -07008054
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308055 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8056 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
8057 }
8058 csrLLUnlock(&pMac->scan.scanCmdPendingList);
Jeff Johnson295189b2012-06-20 16:38:30 -07008059#endif
8060
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308061 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
8062 csrRemoveCmdFromPendingList( pMac, &pMac->roam.roamCmdPendingList, eSmeCommandScan);
8063 csrRemoveCmdFromPendingList( pMac, &pMac->sme.smeCmdPendingList, eSmeCommandScan);
8064 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
8065
8066 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
8067 }
8068 else
8069 {
8070 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
8071 csrRemoveCmdWithSessionIdFromPendingList(pMac,
8072 sessionId,
8073 &pMac->sme.smeScanCmdPendingList,
8074 eSmeCommandScan);
8075 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
8076
8077 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
8078 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008079
8080 //We need to abort scan only if we are scanning
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308081 if(NULL != pEntry)
Jeff Johnson295189b2012-06-20 16:38:30 -07008082 {
8083 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308084 if(eSmeCommandScan == pCommand->command &&
8085 pCommand->sessionId == sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07008086 {
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308087 msgLen = (tANI_U16)(sizeof(tSirSmeScanAbortReq));
Kiet Lam64c1b492013-07-12 13:56:44 +05308088 pMsg = vos_mem_malloc(msgLen);
8089 if ( NULL == pMsg )
Jeff Johnson295189b2012-06-20 16:38:30 -07008090 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308091 smsLog(pMac, LOGE, FL("Failed to allocate memory for SmeScanAbortReq"));
c_hpothua3d45d52015-01-05 14:11:17 +05308092 abortScanStatus = eSIR_ABORT_SCAN_FAILURE;
Kiet Lam64c1b492013-07-12 13:56:44 +05308093 }
8094 else
8095 {
Srinivas, Dasari187ca4e2014-02-07 12:40:09 +05308096 if(reason == eCSR_SCAN_ABORT_DUE_TO_BAND_CHANGE)
8097 {
8098 pCommand->u.scanCmd.abortScanDueToBandChange
8099 = eANI_BOOLEAN_TRUE;
8100 }
Kiet Lam64c1b492013-07-12 13:56:44 +05308101 vos_mem_set((void *)pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008102 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_ABORT_IND);
8103 pMsg->msgLen = pal_cpu_to_be16(msgLen);
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308104 pMsg->sessionId = sessionId;
c_hpothua3d45d52015-01-05 14:11:17 +05308105 if (eHAL_STATUS_SUCCESS != palSendMBMessage(pMac->hHdd, pMsg))
8106 {
8107 smsLog(pMac, LOGE,
8108 FL("Failed to post eWNI_SME_SCAN_ABORT_IND"));
8109 abortScanStatus = eSIR_ABORT_SCAN_FAILURE;
8110 }
8111 else
8112 {
8113 abortScanStatus = eSIR_ABORT_ACTIVE_SCAN_LIST_NOT_EMPTY;
8114 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008115 }
8116 }
8117 }
8118
c_hpothua3d45d52015-01-05 14:11:17 +05308119 return(abortScanStatus);
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308120}
8121
8122void csrRemoveCmdWithSessionIdFromPendingList(tpAniSirGlobal pMac,
8123 tANI_U8 sessionId,
8124 tDblLinkList *pList,
8125 eSmeCommandType commandType)
8126{
8127 tDblLinkList localList;
8128 tListElem *pEntry;
8129 tSmeCmd *pCommand;
8130 tListElem *pEntryToRemove;
8131
8132 vos_mem_zero(&localList, sizeof(tDblLinkList));
8133 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
8134 {
8135 smsLog(pMac, LOGE, FL(" failed to open list"));
8136 return;
8137 }
8138
8139 csrLLLock(pList);
8140 if ((pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK)))
8141 {
8142
8143 /* Have to make sure we don't loop back to the head of the list,
8144 * which will happen if the entry is NOT on the list */
8145 while (pEntry)
8146 {
8147 pEntryToRemove = pEntry;
8148 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
8149 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
8150 if ((pCommand->command == commandType) &&
8151 (pCommand->sessionId == sessionId))
8152 {
8153 /* Remove that entry only */
8154 if (csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
8155 {
8156 csrLLInsertTail(&localList, pEntryToRemove,
8157 LL_ACCESS_NOLOCK);
8158 }
8159 }
8160 }
8161 }
8162 csrLLUnlock(pList);
8163
8164 while ((pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)))
8165 {
8166 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
8167 csrAbortCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
8168 }
8169
8170 csrLLClose(&localList);
Jeff Johnson295189b2012-06-20 16:38:30 -07008171}
8172
8173void csrRemoveCmdFromPendingList(tpAniSirGlobal pMac, tDblLinkList *pList,
8174 eSmeCommandType commandType )
8175{
8176 tDblLinkList localList;
8177 tListElem *pEntry;
8178 tSmeCmd *pCommand;
8179 tListElem *pEntryToRemove;
8180
8181 vos_mem_zero(&localList, sizeof(tDblLinkList));
8182 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
8183 {
8184 smsLog(pMac, LOGE, FL(" failed to open list"));
8185 return;
8186 }
8187
8188 csrLLLock(pList);
8189 if( !csrLLIsListEmpty( pList, LL_ACCESS_NOLOCK ) )
8190 {
8191 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK);
8192
8193 // Have to make sure we don't loop back to the head of the list, which will
8194 // happen if the entry is NOT on the list...
8195 while( pEntry )
8196 {
8197 pEntryToRemove = pEntry;
8198 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
8199 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
8200 if ( pCommand->command == commandType )
8201 {
8202 // Remove that entry only
8203 if(csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
8204 {
8205 csrLLInsertTail(&localList, pEntryToRemove, LL_ACCESS_NOLOCK);
8206 }
8207 }
8208 }
8209
8210
8211 }
8212 csrLLUnlock(pList);
8213
8214 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
8215 {
8216 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8217 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
8218 }
8219 csrLLClose(&localList);
8220
8221}
8222
Abhishek Singhdc2bfd42014-06-19 17:59:05 +05308223eHalStatus csrScanAbortScanForSSID(tpAniSirGlobal pMac, tANI_U32 sessionId)
8224{
8225 eHalStatus status = eHAL_STATUS_SUCCESS;
8226 tSirSmeScanAbortReq *pMsg;
8227 tANI_U16 msgLen;
8228 tListElem *pEntry;
8229 tSmeCmd *pCommand;
8230
8231 if (!pMac->fScanOffload)
8232 {
8233 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
8234#ifdef WLAN_AP_STA_CONCURRENCY
8235 csrRemoveScanForSSIDFromPendingList( pMac, &pMac->scan.scanCmdPendingList, sessionId);
8236#endif
8237 csrRemoveScanForSSIDFromPendingList( pMac, &pMac->roam.roamCmdPendingList, sessionId);
8238 csrRemoveScanForSSIDFromPendingList( pMac, &pMac->sme.smeCmdPendingList, sessionId);
8239 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
8240 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
8241 }
8242 else
8243 {
8244 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
8245 csrRemoveScanForSSIDFromPendingList( pMac, &pMac->sme.smeScanCmdPendingList, sessionId);
8246 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
8247 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
8248 }
8249
8250 if(NULL != pEntry)
8251 {
8252 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8253
8254 if ( (eSmeCommandScan == pCommand->command ) &&
8255 (sessionId == pCommand->sessionId))
8256 {
8257 if ( eCsrScanForSsid == pCommand->u.scanCmd.reason)
8258 {
8259 msgLen = (tANI_U16)(sizeof( tSirSmeScanAbortReq ));
8260 pMsg = vos_mem_malloc(msgLen);
8261 if ( NULL == pMsg )
8262 {
8263 status = eHAL_STATUS_FAILURE;
8264 smsLog(pMac, LOGE, FL("Failed to allocate memory for SmeScanAbortReq"));
8265 }
8266 else
8267 {
8268 vos_mem_zero((void *)pMsg, msgLen);
8269 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_ABORT_IND);
8270 pMsg->msgLen = pal_cpu_to_be16(msgLen);
8271 pMsg->sessionId = sessionId;
8272 status = palSendMBMessage(pMac->hHdd, pMsg);
8273 }
8274 }
8275 }
8276 }
8277 return( status );
8278}
8279
8280void csrRemoveScanForSSIDFromPendingList(tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 sessionId)
8281{
8282 tDblLinkList localList;
8283 tListElem *pEntry;
8284 tSmeCmd *pCommand;
8285 tListElem *pEntryToRemove;
8286
8287 vos_mem_zero(&localList, sizeof(tDblLinkList));
8288 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
8289 {
8290 smsLog(pMac, LOGE, FL(" failed to open list"));
8291 return;
8292 }
8293
8294 csrLLLock(pList);
8295 if( !csrLLIsListEmpty( pList, LL_ACCESS_NOLOCK ) )
8296 {
8297 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK);
8298
8299 // Have to make sure we don't loop back to the head of the list, which will
8300 // happen if the entry is NOT on the list...
8301 while( pEntry )
8302 {
8303 pEntryToRemove = pEntry;
8304 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
8305 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
8306 if ( (eSmeCommandScan == pCommand->command ) &&
8307 (sessionId == pCommand->sessionId) )
8308 {
8309 if ( eCsrScanForSsid == pCommand->u.scanCmd.reason)
8310 {
8311 // Remove that entry only
8312 if ( csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
8313 {
8314 csrLLInsertTail(&localList, pEntryToRemove, LL_ACCESS_NOLOCK);
8315 }
8316 }
8317 }
8318 }
8319 }
8320 csrLLUnlock(pList);
8321
8322 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
8323 {
8324 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8325 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
8326 }
8327 csrLLClose(&localList);
8328}
Jeff Johnson295189b2012-06-20 16:38:30 -07008329
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308330eHalStatus csrScanAbortMacScanNotForConnect(tpAniSirGlobal pMac,
8331 tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07008332{
8333 eHalStatus status = eHAL_STATUS_SUCCESS;
8334
8335 if( !csrIsScanForRoamCommandActive( pMac ) )
8336 {
8337 //Only abort the scan if it is not used for other roam/connect purpose
c_hpothua3d45d52015-01-05 14:11:17 +05308338 if (eSIR_ABORT_SCAN_FAILURE ==
8339 csrScanAbortMacScan(pMac, sessionId, eCSR_SCAN_ABORT_DEFAULT))
8340 {
8341 smsLog(pMac, LOGE, FL("fail to abort scan"));
8342 status = eHAL_STATUS_FAILURE;
8343 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008344 }
8345
8346 return (status);
8347}
8348
8349
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05308350eHalStatus csrScanGetScanChannelInfo(tpAniSirGlobal pMac, tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07008351{
8352 eHalStatus status = eHAL_STATUS_SUCCESS;
8353 tSirMbMsg *pMsg;
8354 tANI_U16 msgLen;
8355
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05308356 if (pMac->fScanOffload)
8357 msgLen = (tANI_U16)(sizeof(tSirSmeGetScanChanReq));
8358 else
8359 msgLen = (tANI_U16)(sizeof(tSirMbMsg));
8360
Kiet Lam64c1b492013-07-12 13:56:44 +05308361 pMsg = vos_mem_malloc(msgLen);
8362 if ( NULL == pMsg )
8363 status = eHAL_STATUS_FAILURE;
8364 else
Jeff Johnson295189b2012-06-20 16:38:30 -07008365 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308366 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008367 pMsg->type = eWNI_SME_GET_SCANNED_CHANNEL_REQ;
8368 pMsg->msgLen = msgLen;
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05308369 if (pMac->fScanOffload)
8370 ((tSirSmeGetScanChanReq *)pMsg)->sessionId = sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07008371 status = palSendMBMessage(pMac->hHdd, pMsg);
8372 }
8373
8374 return( status );
8375}
8376
8377tANI_BOOLEAN csrRoamIsValidChannel( tpAniSirGlobal pMac, tANI_U8 channel )
8378{
8379 tANI_BOOLEAN fValid = FALSE;
8380 tANI_U32 idxValidChannels;
8381 tANI_U32 len = pMac->roam.numValidChannels;
8382
8383 for ( idxValidChannels = 0; ( idxValidChannels < len ); idxValidChannels++ )
8384 {
8385 if ( channel == pMac->roam.validChannelList[ idxValidChannels ] )
8386 {
8387 fValid = TRUE;
8388 break;
8389 }
8390 }
8391
8392 return fValid;
8393}
8394
Manjunathappa Prakash4f1d5a52013-11-11 16:22:19 -08008395#ifdef FEATURE_WLAN_SCAN_PNO
Srikant Kuppa066904f2013-05-07 13:56:02 -07008396eHalStatus csrScanSavePreferredNetworkFound(tpAniSirGlobal pMac,
8397 tSirPrefNetworkFoundInd *pPrefNetworkFoundInd)
8398{
8399 v_U32_t uLen = 0;
8400 tpSirProbeRespBeacon pParsedFrame;
8401 tCsrScanResult *pScanResult = NULL;
8402 tSirBssDescription *pBssDescr = NULL;
8403 tANI_BOOLEAN fDupBss;
8404 tDot11fBeaconIEs *pIesLocal = NULL;
8405 tAniSSID tmpSsid;
8406 v_TIME_t timer=0;
8407 tpSirMacMgmtHdr macHeader = (tpSirMacMgmtHdr)pPrefNetworkFoundInd->data;
Abhishek Singhd3d4e022014-11-11 13:02:40 +05308408 boolean bFoundonAppliedChannel = FALSE;
8409 v_U32_t indx;
8410 u8 channelsAllowed[WNI_CFG_VALID_CHANNEL_LIST_LEN];
8411 v_U32_t numChannelsAllowed = WNI_CFG_VALID_CHANNEL_LIST_LEN;
8412
Srikant Kuppa066904f2013-05-07 13:56:02 -07008413
8414 pParsedFrame =
Abhishek Singhc75726d2015-04-13 14:44:14 +05308415 (tpSirProbeRespBeacon)vos_mem_vmalloc(sizeof(tSirProbeRespBeacon));
Srikant Kuppa066904f2013-05-07 13:56:02 -07008416
8417 if (NULL == pParsedFrame)
8418 {
8419 smsLog(pMac, LOGE, FL(" fail to allocate memory for frame"));
8420 return eHAL_STATUS_RESOURCES;
8421 }
8422
8423 if ( pPrefNetworkFoundInd->frameLength <= SIR_MAC_HDR_LEN_3A )
8424 {
8425 smsLog(pMac, LOGE,
8426 FL("Not enough bytes in PNO indication probe resp frame! length=%d"),
8427 pPrefNetworkFoundInd->frameLength);
Abhishek Singhc75726d2015-04-13 14:44:14 +05308428 vos_mem_vfree(pParsedFrame);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008429 return eHAL_STATUS_FAILURE;
8430 }
8431
8432 if (sirConvertProbeFrame2Struct(pMac,
8433 &pPrefNetworkFoundInd->data[SIR_MAC_HDR_LEN_3A],
8434 pPrefNetworkFoundInd->frameLength - SIR_MAC_HDR_LEN_3A,
8435 pParsedFrame) != eSIR_SUCCESS ||
8436 !pParsedFrame->ssidPresent)
8437 {
8438 smsLog(pMac, LOGE,
8439 FL("Parse error ProbeResponse, length=%d"),
8440 pPrefNetworkFoundInd->frameLength);
Abhishek Singhc75726d2015-04-13 14:44:14 +05308441 vos_mem_vfree(pParsedFrame);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008442 return eHAL_STATUS_FAILURE;
8443 }
8444 //24 byte MAC header and 12 byte to ssid IE
8445 if (pPrefNetworkFoundInd->frameLength >
8446 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET))
8447 {
8448 uLen = pPrefNetworkFoundInd->frameLength -
8449 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET);
8450 }
8451
Kiet Lam64c1b492013-07-12 13:56:44 +05308452 pScanResult = vos_mem_malloc(sizeof(tCsrScanResult) + uLen);
8453 if ( NULL == pScanResult )
Srikant Kuppa066904f2013-05-07 13:56:02 -07008454 {
8455 smsLog(pMac, LOGE, FL(" fail to allocate memory for frame"));
8456 vos_mem_free(pParsedFrame);
8457 return eHAL_STATUS_RESOURCES;
8458 }
8459
Kiet Lam64c1b492013-07-12 13:56:44 +05308460 vos_mem_set(pScanResult, sizeof(tCsrScanResult) + uLen, 0);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008461 pBssDescr = &pScanResult->Result.BssDescriptor;
8462 /**
8463 * Length of BSS desription is without length of
8464 * length itself and length of pointer
8465 * that holds the next BSS description
8466 */
8467 pBssDescr->length = (tANI_U16)(
8468 sizeof(tSirBssDescription) - sizeof(tANI_U16) -
8469 sizeof(tANI_U32) + uLen);
8470 if (pParsedFrame->dsParamsPresent)
8471 {
8472 pBssDescr->channelId = pParsedFrame->channelNumber;
8473 }
8474 else if (pParsedFrame->HTInfo.present)
8475 {
8476 pBssDescr->channelId = pParsedFrame->HTInfo.primaryChannel;
8477 }
8478 else
8479 {
Mahesh A Saptasagaradd99792014-03-26 16:04:20 +05308480 /**
8481 * If Probe Responce received in PNO indication does not
8482 * contain DSParam IE or HT Info IE then add dummy channel
8483 * to the received BSS info so that Scan result received as
8484 * a part of PNO is updated to the supplicant. Specially
8485 * applicable in case of AP configured in 11A only mode.
8486 */
8487 if ((pMac->roam.configParam.bandCapability == eCSR_BAND_ALL) ||
8488 (pMac->roam.configParam.bandCapability == eCSR_BAND_24))
8489 {
8490 pBssDescr->channelId = 1;
8491 }
8492 else if(pMac->roam.configParam.bandCapability == eCSR_BAND_5G)
8493 {
8494 pBssDescr->channelId = 36;
8495 }
Abhishek Singhd3d4e022014-11-11 13:02:40 +05308496 /* Restrict the logic to ignore the pno indication for invalid channel
8497 * only if valid channel info is present in beacon/probe resp.
8498 * If no channel info is present in beacon/probe resp, always process
8499 * the pno indication.
8500 */
8501 bFoundonAppliedChannel = TRUE;
8502 }
8503
8504 if (0 != sme_GetCfgValidChannels(pMac, channelsAllowed, &numChannelsAllowed))
8505 {
8506 smsLog(pMac, LOGE, FL(" sme_GetCfgValidChannels failed "));
8507 csrFreeScanResultEntry(pMac, pScanResult);
Abhishek Singhc75726d2015-04-13 14:44:14 +05308508 vos_mem_vfree(pParsedFrame);
Abhishek Singhd3d4e022014-11-11 13:02:40 +05308509 return eHAL_STATUS_FAILURE;
8510 }
8511 /* Checking chhanelId with allowed channel list */
8512 for (indx = 0; indx < numChannelsAllowed; indx++)
8513 {
8514 if (pBssDescr->channelId == channelsAllowed[indx])
8515 {
8516 bFoundonAppliedChannel = TRUE;
8517 smsLog(pMac, LOG1, FL(" pno ind found on applied channel =%d\n "),
8518 pBssDescr->channelId);
8519 break;
8520 }
8521 }
8522 /* Ignore PNO indication if AP is on Invalid channel.
8523 */
8524 if(FALSE == bFoundonAppliedChannel)
8525 {
8526 smsLog(pMac, LOGW, FL(" prefered network found on invalid channel = %d"),
8527 pBssDescr->channelId);
8528 csrFreeScanResultEntry(pMac, pScanResult);
Abhishek Singhc75726d2015-04-13 14:44:14 +05308529 vos_mem_vfree(pParsedFrame);
Abhishek Singhd3d4e022014-11-11 13:02:40 +05308530 return eHAL_STATUS_FAILURE;
Srikant Kuppa066904f2013-05-07 13:56:02 -07008531 }
8532
8533 if ((pBssDescr->channelId > 0) && (pBssDescr->channelId < 15))
8534 {
8535 int i;
8536 // 11b or 11g packet
8537 // 11g iff extended Rate IE is present or
8538 // if there is an A rate in suppRate IE
8539 for (i = 0; i < pParsedFrame->supportedRates.numRates; i++)
8540 {
8541 if (sirIsArate(pParsedFrame->supportedRates.rate[i] & 0x7f))
8542 {
8543 pBssDescr->nwType = eSIR_11G_NW_TYPE;
8544 break;
8545 }
8546 }
8547 if (pParsedFrame->extendedRatesPresent)
8548 {
8549 pBssDescr->nwType = eSIR_11G_NW_TYPE;
8550 }
8551 }
8552 else
8553 {
8554 // 11a packet
8555 pBssDescr->nwType = eSIR_11A_NW_TYPE;
8556 }
8557
8558 pBssDescr->sinr = 0;
8559 pBssDescr->rssi = -1 * pPrefNetworkFoundInd->rssi;
8560 pBssDescr->beaconInterval = pParsedFrame->beaconInterval;
AnjaneeDevi Kapparapu4b043912014-02-18 13:22:35 +05308561 if (!pBssDescr->beaconInterval)
8562 {
8563 smsLog(pMac, LOGW,
8564 FL("Bcn Interval is Zero , default to 100" MAC_ADDRESS_STR),
8565 MAC_ADDR_ARRAY(pBssDescr->bssId) );
8566 pBssDescr->beaconInterval = 100;
8567 }
Srikant Kuppa066904f2013-05-07 13:56:02 -07008568 pBssDescr->timeStamp[0] = pParsedFrame->timeStamp[0];
8569 pBssDescr->timeStamp[1] = pParsedFrame->timeStamp[1];
8570 pBssDescr->capabilityInfo = *((tANI_U16 *)&pParsedFrame->capabilityInfo);
Kiet Lam64c1b492013-07-12 13:56:44 +05308571 vos_mem_copy((tANI_U8 *) &pBssDescr->bssId, (tANI_U8 *) macHeader->bssId, sizeof(tSirMacAddr));
Srikant Kuppa066904f2013-05-07 13:56:02 -07008572 pBssDescr->nReceivedTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
8573
Abhishek Singh195c03e2014-05-14 17:21:30 +05308574 smsLog( pMac, LOG1, FL("Bssid= "MAC_ADDRESS_STR
8575 " chan= %d, rssi = %d "),
Arif Hussain24bafea2013-11-15 15:10:03 -08008576 MAC_ADDR_ARRAY(pBssDescr->bssId),
Srikant Kuppa066904f2013-05-07 13:56:02 -07008577 pBssDescr->channelId,
Abhishek Singh195c03e2014-05-14 17:21:30 +05308578 pBssDescr->rssi);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008579
8580 //IEs
8581 if (uLen)
8582 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308583 vos_mem_copy(&pBssDescr->ieFields,
8584 pPrefNetworkFoundInd->data + (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET),
8585 uLen);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008586 }
8587
8588 pIesLocal = (tDot11fBeaconIEs *)( pScanResult->Result.pvIes );
8589 if ( !pIesLocal &&
8590 (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
8591 &pScanResult->Result.BssDescriptor, &pIesLocal))) )
8592 {
8593 smsLog(pMac, LOGE, FL(" Cannot parse IEs"));
8594 csrFreeScanResultEntry(pMac, pScanResult);
Abhishek Singhc75726d2015-04-13 14:44:14 +05308595 vos_mem_vfree(pParsedFrame);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008596 return eHAL_STATUS_RESOURCES;
8597 }
8598
8599 fDupBss = csrRemoveDupBssDescription( pMac,
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05308600 &pScanResult->Result.BssDescriptor, pIesLocal, &tmpSsid, &timer, FALSE);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008601 //Check whether we have reach out limit
8602 if ( CSR_SCAN_IS_OVER_BSS_LIMIT(pMac) )
8603 {
8604 //Limit reach
8605 smsLog(pMac, LOGE, FL(" BSS limit reached"));
8606 //Free the resources
8607 if( (pScanResult->Result.pvIes == NULL) && pIesLocal )
8608 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308609 vos_mem_free(pIesLocal);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008610 }
8611 csrFreeScanResultEntry(pMac, pScanResult);
8612 vos_mem_free(pParsedFrame);
8613 return eHAL_STATUS_RESOURCES;
8614 }
8615 //Add to scan cache
8616 csrScanAddResult(pMac, pScanResult, pIesLocal);
8617
Kiet Lamb537cfb2013-11-07 12:56:49 +05308618 if( (pScanResult->Result.pvIes == NULL) && pIesLocal )
8619 {
8620 vos_mem_free(pIesLocal);
8621 }
8622
Abhishek Singhc75726d2015-04-13 14:44:14 +05308623 vos_mem_vfree(pParsedFrame);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008624
8625 return eHAL_STATUS_SUCCESS;
8626}
Manjunathappa Prakash4f1d5a52013-11-11 16:22:19 -08008627#endif //FEATURE_WLAN_SCAN_PNO
Srikant Kuppa066904f2013-05-07 13:56:02 -07008628
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008629#ifdef FEATURE_WLAN_LFR
8630void csrInitOccupiedChannelsList(tpAniSirGlobal pMac)
8631{
8632 tListElem *pEntry = NULL;
8633 tCsrScanResult *pBssDesc = NULL;
8634 tDot11fBeaconIEs *pIes = NULL;
Srinivas28b5b4e2012-12-12 13:07:53 -08008635 tpCsrNeighborRoamControlInfo pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
8636
8637 if (0 != pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels)
8638 {
8639 smsLog(pMac, LOG1, FL("%s: Ini file contains neighbor scan channel list,"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008640 " hence NO need to build occupied channel list (numChannels = %d)"),
Srinivas28b5b4e2012-12-12 13:07:53 -08008641 __func__, pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels);
8642 return;
8643 }
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008644
8645 if (!csrNeighborRoamIsNewConnectedProfile(pMac))
8646 {
8647 smsLog(pMac, LOG2, FL("%s: donot flush occupied list since current roam profile"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008648 " matches previous (numChannels = %d)"),
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008649 __func__, pMac->scan.occupiedChannels.numChannels);
8650 return;
8651 }
8652
8653 /* Empty occupied channels here */
8654 pMac->scan.occupiedChannels.numChannels = 0;
8655
8656 csrLLLock(&pMac->scan.scanResultList);
8657 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
8658 while( pEntry )
8659 {
8660 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
8661 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
8662
8663 //At this time, pBssDescription->Result.pvIes may be NULL
Srikant Kuppa866893f2012-12-27 17:28:14 -08008664 if( !pIes && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008665 &pBssDesc->Result.BssDescriptor, &pIes))) )
8666 {
8667 continue;
8668 }
8669
8670 csrScanAddToOccupiedChannels(pMac, pBssDesc, &pMac->scan.occupiedChannels, pIes);
8671
8672 /*
8673 * Free the memory allocated for pIes in csrGetParsedBssDescriptionIEs
8674 */
8675 if( (pBssDesc->Result.pvIes == NULL) && pIes )
8676 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308677 vos_mem_free(pIes);
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008678 }
8679
8680 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK );
8681 }//while
8682 csrLLUnlock(&pMac->scan.scanResultList);
Srikant Kuppa866893f2012-12-27 17:28:14 -08008683
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008684}
8685#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07008686
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008687eHalStatus csrScanCreateEntryInScanCache(tpAniSirGlobal pMac, tANI_U32 sessionId,
8688 tCsrBssid bssid, tANI_U8 channel)
8689{
8690 eHalStatus status = eHAL_STATUS_SUCCESS;
8691 tDot11fBeaconIEs *pNewIes = NULL;
8692 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
Praveen Kumar Sirisilla8bdfac42013-10-10 17:20:48 -07008693 tSirBssDescription *pNewBssDescriptor = NULL;
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008694 tANI_U32 size = 0;
8695
8696 if(NULL == pSession)
8697 {
8698 status = eHAL_STATUS_FAILURE;
8699 return status;
8700 }
8701 smsLog(pMac, LOG2, FL("csrScanCreateEntryInScanCache: Current bssid::"
Arif Hussain24bafea2013-11-15 15:10:03 -08008702 MAC_ADDRESS_STR),
8703 MAC_ADDR_ARRAY(pSession->pConnectBssDesc->bssId));
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008704 smsLog(pMac, LOG2, FL("csrScanCreateEntryInScanCache: My bssid::"
Arif Hussain24bafea2013-11-15 15:10:03 -08008705 MAC_ADDRESS_STR" channel %d"),
8706 MAC_ADDR_ARRAY(bssid), channel);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008707
8708 do
8709 {
8710 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
8711 pSession->pConnectBssDesc, &pNewIes)))
8712 {
8713 smsLog(pMac, LOGE, FL("%s: Failed to parse IEs"),
8714 __func__);
8715 status = eHAL_STATUS_FAILURE;
8716 break;
8717 }
8718
8719 size = pSession->pConnectBssDesc->length + sizeof(pSession->pConnectBssDesc->length);
Kiet Lam64c1b492013-07-12 13:56:44 +05308720 if (size)
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008721 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308722 pNewBssDescriptor = vos_mem_malloc(size);
8723 if ( NULL == pNewBssDescriptor )
8724 status = eHAL_STATUS_FAILURE;
8725 else
8726 status = eHAL_STATUS_SUCCESS;
8727 if (HAL_STATUS_SUCCESS(status))
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008728 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308729 vos_mem_copy(pNewBssDescriptor, pSession->pConnectBssDesc, size);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008730 }
8731 else
8732 {
8733 smsLog(pMac, LOGE, FL("%s: memory allocation failed"),
8734 __func__);
8735 status = eHAL_STATUS_FAILURE;
8736 break;
8737 }
8738
8739 //change the BSSID & channel as passed
Kiet Lam64c1b492013-07-12 13:56:44 +05308740 vos_mem_copy(pNewBssDescriptor->bssId, bssid, sizeof(tSirMacAddr));
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008741 pNewBssDescriptor->channelId = channel;
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07008742 if(NULL == csrScanAppendBssDescription( pMac, pNewBssDescriptor, pNewIes, TRUE ))
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008743 {
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07008744 smsLog(pMac, LOGE, FL("%s: csrScanAppendBssDescription failed"),
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008745 __func__);
8746 status = eHAL_STATUS_FAILURE;
8747 break;
8748 }
8749 }
8750 else
8751 {
8752 smsLog(pMac, LOGE, FL("%s: length of bss descriptor is 0"),
8753 __func__);
8754 status = eHAL_STATUS_FAILURE;
8755 break;
8756 }
8757 smsLog(pMac, LOGE, FL("%s: entry successfully added in scan cache"),
8758 __func__);
8759 }while(0);
8760
8761 if(pNewIes)
8762 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308763 vos_mem_free(pNewIes);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008764 }
8765 if(pNewBssDescriptor)
8766 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308767 vos_mem_free(pNewBssDescriptor);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008768 }
8769 return status;
8770}
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07008771
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08008772#ifdef FEATURE_WLAN_ESE
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07008773// Update the TSF with the difference in system time
8774void UpdateCCKMTSF(tANI_U32 *timeStamp0, tANI_U32 *timeStamp1, tANI_U32 *incr)
8775{
8776 tANI_U64 timeStamp64 = ((tANI_U64)*timeStamp1 << 32) | (*timeStamp0);
8777
8778 timeStamp64 = (tANI_U64)(timeStamp64 + (tANI_U64)*incr);
8779 *timeStamp0 = (tANI_U32)(timeStamp64 & 0xffffffff);
8780 *timeStamp1 = (tANI_U32)((timeStamp64 >> 32) & 0xffffffff);
8781}
8782#endif