blob: b4eb851f032b30ed84894e9a9372710f4fcba430 [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
2618
2619eHalStatus csrScanCopyResultList(tpAniSirGlobal pMac, tScanResultHandle hIn, tScanResultHandle *phResult)
2620{
2621 eHalStatus status = eHAL_STATUS_SUCCESS;
2622 tScanResultList *pRetList, *pInList = (tScanResultList *)hIn;
2623 tCsrScanResult *pResult, *pScanResult;
2624 tANI_U32 count = 0;
2625 tListElem *pEntry;
2626 tANI_U32 bssLen, allocLen;
2627
2628 if(phResult)
2629 {
2630 *phResult = CSR_INVALID_SCANRESULT_HANDLE;
2631 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302632 pRetList = vos_mem_malloc(sizeof(tScanResultList));
2633 if ( NULL == pRetList )
2634 status = eHAL_STATUS_FAILURE;
2635 else
Jeff Johnson295189b2012-06-20 16:38:30 -07002636 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302637 vos_mem_set(pRetList, sizeof(tScanResultList), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002638 csrLLOpen(pMac->hHdd, &pRetList->List);
2639 pRetList->pCurEntry = NULL;
2640 csrLLLock(&pMac->scan.scanResultList);
2641 csrLLLock(&pInList->List);
2642
2643 pEntry = csrLLPeekHead( &pInList->List, LL_ACCESS_NOLOCK );
2644 while( pEntry )
2645 {
2646 pScanResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2647 bssLen = pScanResult->Result.BssDescriptor.length + sizeof(pScanResult->Result.BssDescriptor.length);
2648 allocLen = sizeof( tCsrScanResult ) + bssLen;
Kiet Lam64c1b492013-07-12 13:56:44 +05302649 pResult = vos_mem_malloc(allocLen);
2650 if ( NULL == pResult )
2651 status = eHAL_STATUS_FAILURE;
2652 else
2653 status = eHAL_STATUS_SUCCESS;
2654 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07002655 {
2656 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
2657 count = 0;
2658 break;
2659 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302660 vos_mem_set(pResult, allocLen , 0);
2661 vos_mem_copy(&pResult->Result.BssDescriptor, &pScanResult->Result.BssDescriptor, bssLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07002662 if( pScanResult->Result.pvIes )
2663 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302664 pResult->Result.pvIes = vos_mem_malloc(sizeof( tDot11fBeaconIEs ));
2665 if ( NULL == pResult->Result.pvIes )
2666 status = eHAL_STATUS_FAILURE;
2667 else
2668 status = eHAL_STATUS_SUCCESS;
2669 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07002670 {
2671 //Free the memory we allocate above first
Kiet Lam64c1b492013-07-12 13:56:44 +05302672 vos_mem_free(pResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07002673 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
2674 count = 0;
2675 break;
2676 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302677 vos_mem_copy(pResult->Result.pvIes, pScanResult->Result.pvIes,
2678 sizeof( tDot11fBeaconIEs ));
Jeff Johnson295189b2012-06-20 16:38:30 -07002679 }
2680 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_LOCK);
2681 count++;
2682 pEntry = csrLLNext( &pInList->List, pEntry, LL_ACCESS_NOLOCK );
2683 }//while
2684 csrLLUnlock(&pInList->List);
2685 csrLLUnlock(&pMac->scan.scanResultList);
2686
2687 if(HAL_STATUS_SUCCESS(status))
2688 {
2689 if(0 == count)
2690 {
2691 csrLLClose(&pRetList->List);
Kiet Lam64c1b492013-07-12 13:56:44 +05302692 vos_mem_free(pRetList);
Jeff Johnson295189b2012-06-20 16:38:30 -07002693 status = eHAL_STATUS_E_NULL_VALUE;
2694 }
2695 else if(phResult)
2696 {
2697 *phResult = pRetList;
2698 }
2699 }
2700 }//Allocated pRetList
2701
2702 return (status);
2703}
2704
2705
2706
2707eHalStatus csrScanningStateMsgProcessor( tpAniSirGlobal pMac, void *pMsgBuf )
2708{
2709 eHalStatus status = eHAL_STATUS_SUCCESS;
2710 tSirMbMsg *pMsg = (tSirMbMsg *)pMsgBuf;
2711
2712 if((eWNI_SME_SCAN_RSP == pMsg->type) || (eWNI_SME_GET_SCANNED_CHANNEL_RSP == pMsg->type))
2713 {
2714 status = csrScanSmeScanResponse( pMac, pMsgBuf );
2715 }
2716 else
2717 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002718 if(pMsg->type == eWNI_SME_UPPER_LAYER_ASSOC_CNF)
Jeff Johnson295189b2012-06-20 16:38:30 -07002719 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002720 tCsrRoamSession *pSession;
2721 tSirSmeAssocIndToUpperLayerCnf *pUpperLayerAssocCnf;
2722 tCsrRoamInfo roamInfo;
2723 tCsrRoamInfo *pRoamInfo = NULL;
2724 tANI_U32 sessionId;
2725 eHalStatus status;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002726 smsLog( pMac, LOG1, FL("Scanning : ASSOCIATION confirmation can be given to upper layer "));
Kiet Lam64c1b492013-07-12 13:56:44 +05302727 vos_mem_set(&roamInfo, sizeof(tCsrRoamInfo), 0);
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002728 pRoamInfo = &roamInfo;
2729 pUpperLayerAssocCnf = (tSirSmeAssocIndToUpperLayerCnf *)pMsgBuf;
2730 status = csrRoamGetSessionIdFromBSSID( pMac, (tCsrBssid *)pUpperLayerAssocCnf->bssId, &sessionId );
2731 pSession = CSR_GET_SESSION(pMac, sessionId);
2732
2733 if(!pSession)
2734 {
2735 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
2736 return eHAL_STATUS_FAILURE;
2737 }
2738
2739 pRoamInfo->statusCode = eSIR_SME_SUCCESS; //send the status code as Success
2740 pRoamInfo->u.pConnectedProfile = &pSession->connectedProfile;
2741 pRoamInfo->staId = (tANI_U8)pUpperLayerAssocCnf->aid;
2742 pRoamInfo->rsnIELen = (tANI_U8)pUpperLayerAssocCnf->rsnIE.length;
2743 pRoamInfo->prsnIE = pUpperLayerAssocCnf->rsnIE.rsnIEdata;
2744 pRoamInfo->addIELen = (tANI_U8)pUpperLayerAssocCnf->addIE.length;
2745 pRoamInfo->paddIE = pUpperLayerAssocCnf->addIE.addIEdata;
Kiet Lam64c1b492013-07-12 13:56:44 +05302746 vos_mem_copy(pRoamInfo->peerMac, pUpperLayerAssocCnf->peerMacAddr, sizeof(tSirMacAddr));
2747 vos_mem_copy(&pRoamInfo->bssid, pUpperLayerAssocCnf->bssId, sizeof(tCsrBssid));
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002748 pRoamInfo->wmmEnabledSta = pUpperLayerAssocCnf->wmmEnabledSta;
Hardik Kantilal Patel1ba630f2014-11-21 04:32:05 +05302749#ifdef WLAN_FEATURE_AP_HT40_24G
2750 pRoamInfo->HT40MHzIntoEnabledSta =
2751 pUpperLayerAssocCnf->HT40MHzIntoEnabledSta;
2752#endif
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002753 if(CSR_IS_INFRA_AP(pRoamInfo->u.pConnectedProfile) )
2754 {
2755 pMac->roam.roamSession[sessionId].connectState = eCSR_ASSOC_STATE_TYPE_INFRA_CONNECTED;
2756 pRoamInfo->fReassocReq = pUpperLayerAssocCnf->reassocReq;
2757 status = csrRoamCallCallback(pMac, sessionId, pRoamInfo, 0, eCSR_ROAM_INFRA_IND, eCSR_ROAM_RESULT_INFRA_ASSOCIATION_CNF);
2758 }
2759 if(CSR_IS_WDS_AP( pRoamInfo->u.pConnectedProfile))
2760 {
2761 vos_sleep( 100 );
2762 pMac->roam.roamSession[sessionId].connectState = eCSR_ASSOC_STATE_TYPE_WDS_CONNECTED;//Sta
2763 status = csrRoamCallCallback(pMac, sessionId, pRoamInfo, 0, eCSR_ROAM_WDS_IND, eCSR_ROAM_RESULT_WDS_ASSOCIATION_IND);//Sta
2764 }
2765
Jeff Johnson295189b2012-06-20 16:38:30 -07002766 }
2767 else
2768 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002769
2770 if( csrIsAnySessionInConnectState( pMac ) )
2771 {
2772 //In case of we are connected, we need to check whether connect status changes
2773 //because scan may also run while connected.
2774 csrRoamCheckForLinkStatusChange( pMac, ( tSirSmeRsp * )pMsgBuf );
2775 }
2776 else
2777 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002778 smsLog( pMac, LOGW, "Message [0x%04x] received in state, when expecting Scan Response", pMsg->type );
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002779 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002780 }
2781 }
2782
2783 return (status);
2784}
2785
2786
2787
2788void csrCheckNSaveWscIe(tpAniSirGlobal pMac, tSirBssDescription *pNewBssDescr, tSirBssDescription *pOldBssDescr)
2789{
2790 int idx, len;
2791 tANI_U8 *pbIe;
2792
2793 //If failed to remove, assuming someone else got it.
2794 if((pNewBssDescr->fProbeRsp != pOldBssDescr->fProbeRsp) &&
2795 (0 == pNewBssDescr->WscIeLen))
2796 {
2797 idx = 0;
2798 len = pOldBssDescr->length - sizeof(tSirBssDescription) +
2799 sizeof(tANI_U16) + sizeof(tANI_U32) - DOT11F_IE_WSCPROBERES_MIN_LEN - 2;
2800 pbIe = (tANI_U8 *)pOldBssDescr->ieFields;
2801 //Save WPS IE if it exists
2802 pNewBssDescr->WscIeLen = 0;
2803 while(idx < len)
2804 {
2805 if((DOT11F_EID_WSCPROBERES == pbIe[0]) &&
2806 (0x00 == pbIe[2]) && (0x50 == pbIe[3]) && (0xf2 == pbIe[4]) && (0x04 == pbIe[5]))
2807 {
2808 //Founrd it
2809 if((DOT11F_IE_WSCPROBERES_MAX_LEN - 2) >= pbIe[1])
2810 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302811 vos_mem_copy(pNewBssDescr->WscIeProbeRsp, pbIe, pbIe[1] + 2);
Jeff Johnson295189b2012-06-20 16:38:30 -07002812 pNewBssDescr->WscIeLen = pbIe[1] + 2;
2813 }
2814 break;
2815 }
2816 idx += pbIe[1] + 2;
2817 pbIe += pbIe[1] + 2;
2818 }
2819 }
2820}
2821
2822
2823
2824//pIes may be NULL
2825tANI_BOOLEAN csrRemoveDupBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDescr,
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05302826 tDot11fBeaconIEs *pIes, tAniSSID *pSsid, v_TIME_t *timer, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07002827{
2828 tListElem *pEntry;
2829
2830 tCsrScanResult *pBssDesc;
2831 tANI_BOOLEAN fRC = FALSE;
2832
2833 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
2834 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
2835 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
2836 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
2837
2838 while( pEntry )
2839 {
2840 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2841
2842 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
2843 // matches
2844 if ( csrIsDuplicateBssDescription( pMac, &pBssDesc->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07002845 pSirBssDescr, pIes, fForced ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07002846 {
2847 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
2848 ((tANI_S32)pBssDesc->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
2849 // Remove the 'old' entry from the list....
2850 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry, LL_ACCESS_LOCK ) )
2851 {
2852 // !we need to free the memory associated with this node
2853 //If failed to remove, assuming someone else got it.
2854 *pSsid = pBssDesc->Result.ssId;
2855 *timer = pBssDesc->Result.timer;
2856 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pBssDesc->Result.BssDescriptor);
2857
2858 csrFreeScanResultEntry( pMac, pBssDesc );
2859 }
2860 else
2861 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002862 smsLog( pMac, LOGW, FL( " fail to remove entry" ) );
Jeff Johnson295189b2012-06-20 16:38:30 -07002863 }
2864 fRC = TRUE;
2865
2866 // If we found a match, we can stop looking through the list.
2867 break;
2868 }
2869
2870 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_LOCK );
2871 }
2872
2873 return fRC;
2874}
2875
2876
2877eHalStatus csrAddPMKIDCandidateList( tpAniSirGlobal pMac, tANI_U32 sessionId,
2878 tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes )
2879{
2880 eHalStatus status = eHAL_STATUS_FAILURE;
2881 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
2882
Jeff Johnson32d95a32012-09-10 13:15:23 -07002883 if(!pSession)
2884 {
2885 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
2886 return eHAL_STATUS_FAILURE;
2887 }
2888
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002889 smsLog(pMac, LOGW, "csrAddPMKIDCandidateList called pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07002890 if( pIes )
2891 {
2892 // check if this is a RSN BSS
2893 if( pIes->RSN.present )
2894 {
2895 // Check if the BSS is capable of doing pre-authentication
2896 if( pSession->NumPmkidCandidate < CSR_MAX_PMKID_ALLOWED )
2897 {
2898
2899#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
2900 {
2901 WLAN_VOS_DIAG_EVENT_DEF(secEvent, vos_event_wlan_security_payload_type);
Kiet Lam64c1b492013-07-12 13:56:44 +05302902 vos_mem_set(&secEvent, sizeof(vos_event_wlan_security_payload_type), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002903 secEvent.eventId = WLAN_SECURITY_EVENT_PMKID_CANDIDATE_FOUND;
2904 secEvent.encryptionModeMulticast =
2905 (v_U8_t)diagEncTypeFromCSRType(pSession->connectedProfile.mcEncryptionType);
2906 secEvent.encryptionModeUnicast =
2907 (v_U8_t)diagEncTypeFromCSRType(pSession->connectedProfile.EncryptionType);
Kiet Lam64c1b492013-07-12 13:56:44 +05302908 vos_mem_copy(secEvent.bssid, pSession->connectedProfile.bssid, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07002909 secEvent.authMode =
2910 (v_U8_t)diagAuthTypeFromCSRType(pSession->connectedProfile.AuthType);
2911 WLAN_VOS_DIAG_EVENT_REPORT(&secEvent, EVENT_WLAN_SECURITY);
2912 }
2913#endif//#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
2914
2915 // if yes, then add to PMKIDCandidateList
Kiet Lam64c1b492013-07-12 13:56:44 +05302916 vos_mem_copy(pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].BSSID,
2917 pBssDesc->bssId, WNI_CFG_BSSID_LEN);
2918 // Bit 0 offirst byte - PreAuthentication Capability
2919 if ( (pIes->RSN.RSN_Cap[0] >> 0) & 0x1 )
Jeff Johnson295189b2012-06-20 16:38:30 -07002920 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302921 pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].preAuthSupported
2922 = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07002923 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302924 else
2925 {
2926 pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].preAuthSupported
2927 = eANI_BOOLEAN_FALSE;
2928 }
2929 pSession->NumPmkidCandidate++;
Jeff Johnson295189b2012-06-20 16:38:30 -07002930 }
2931 else
2932 {
2933 status = eHAL_STATUS_FAILURE;
2934 }
2935 }
2936 }
2937
2938 return (status);
2939}
2940
2941//This function checks whether new AP is found for the current connected profile
2942//If it is found, it return the sessionId, else it return invalid sessionID
2943tANI_U32 csrProcessBSSDescForPMKIDList(tpAniSirGlobal pMac,
2944 tSirBssDescription *pBssDesc,
2945 tDot11fBeaconIEs *pIes)
2946{
2947 tANI_U32 i, bRet = CSR_SESSION_ID_INVALID;
2948 tCsrRoamSession *pSession;
2949 tDot11fBeaconIEs *pIesLocal = pIes;
2950
2951 if( pIesLocal || HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIesLocal)) )
2952 {
2953 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
2954 {
2955 if( CSR_IS_SESSION_VALID( pMac, i ) )
2956 {
2957 pSession = CSR_GET_SESSION( pMac, i );
2958 if( csrIsConnStateConnectedInfra( pMac, i ) &&
2959 ( eCSR_AUTH_TYPE_RSN == pSession->connectedProfile.AuthType ) )
2960 {
2961 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile, pBssDesc, pIesLocal))
2962 {
2963 //this new BSS fits the current profile connected
2964 if(HAL_STATUS_SUCCESS(csrAddPMKIDCandidateList(pMac, i, pBssDesc, pIesLocal)))
2965 {
2966 bRet = i;
2967 }
2968 break;
2969 }
2970 }
2971 }
2972 }
2973 if( !pIes )
2974 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302975 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07002976 }
2977 }
2978
2979 return (tANI_U8)bRet;
2980}
2981
2982#ifdef FEATURE_WLAN_WAPI
2983eHalStatus csrAddBKIDCandidateList( tpAniSirGlobal pMac, tANI_U32 sessionId,
2984 tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes )
2985{
2986 eHalStatus status = eHAL_STATUS_FAILURE;
2987 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
2988
Jeff Johnson32d95a32012-09-10 13:15:23 -07002989 if(!pSession)
2990 {
2991 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
2992 return eHAL_STATUS_FAILURE;
2993 }
2994
Kiet Lam64c1b492013-07-12 13:56:44 +05302995 smsLog(pMac, LOGW, "csrAddBKIDCandidateList called pMac->scan.NumBkidCandidate = %d",
2996 pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07002997 if( pIes )
2998 {
2999 // check if this is a WAPI BSS
3000 if( pIes->WAPI.present )
3001 {
3002 // Check if the BSS is capable of doing pre-authentication
3003 if( pSession->NumBkidCandidate < CSR_MAX_BKID_ALLOWED )
3004 {
3005
3006 // if yes, then add to BKIDCandidateList
Kiet Lam64c1b492013-07-12 13:56:44 +05303007 vos_mem_copy(pSession->BkidCandidateInfo[pSession->NumBkidCandidate].BSSID,
3008 pBssDesc->bssId, WNI_CFG_BSSID_LEN);
3009 if ( pIes->WAPI.preauth )
Jeff Johnson295189b2012-06-20 16:38:30 -07003010 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303011 pSession->BkidCandidateInfo[pSession->NumBkidCandidate].preAuthSupported
3012 = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003013 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303014 else
3015 {
3016 pSession->BkidCandidateInfo[pSession->NumBkidCandidate].preAuthSupported
3017 = eANI_BOOLEAN_FALSE;
3018 }
3019 pSession->NumBkidCandidate++;
Jeff Johnson295189b2012-06-20 16:38:30 -07003020 }
3021 else
3022 {
3023 status = eHAL_STATUS_FAILURE;
3024 }
3025 }
3026 }
3027
3028 return (status);
3029}
3030
3031//This function checks whether new AP is found for the current connected profile
3032//if so add to BKIDCandidateList
3033tANI_BOOLEAN csrProcessBSSDescForBKIDList(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
3034 tDot11fBeaconIEs *pIes)
3035{
3036 tANI_BOOLEAN fRC = FALSE;
3037 tDot11fBeaconIEs *pIesLocal = pIes;
3038 tANI_U32 sessionId;
3039 tCsrRoamSession *pSession;
3040
3041 if( pIesLocal || HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIesLocal)) )
3042 {
3043 for( sessionId = 0; sessionId < CSR_ROAM_SESSION_MAX; sessionId++ )
3044 {
3045 if( CSR_IS_SESSION_VALID( pMac, sessionId) )
3046 {
3047 pSession = CSR_GET_SESSION( pMac, sessionId );
3048 if( csrIsConnStateConnectedInfra( pMac, sessionId ) &&
3049 eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE == pSession->connectedProfile.AuthType)
3050 {
3051 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile,pBssDesc, pIesLocal))
3052 {
3053 //this new BSS fits the current profile connected
3054 if(HAL_STATUS_SUCCESS(csrAddBKIDCandidateList(pMac, sessionId, pBssDesc, pIesLocal)))
3055 {
3056 fRC = TRUE;
3057 }
3058 }
3059 }
3060 }
3061 }
3062 if(!pIes)
3063 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303064 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003065 }
3066
3067 }
3068 return fRC;
3069}
3070
3071#endif
3072
3073
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07003074static void csrMoveTempScanResultsToMainList( tpAniSirGlobal pMac, tANI_U8 reason )
Jeff Johnson295189b2012-06-20 16:38:30 -07003075{
3076 tListElem *pEntry;
3077 tCsrScanResult *pBssDescription;
Jeff Johnson295189b2012-06-20 16:38:30 -07003078 tANI_BOOLEAN fDupBss;
3079#ifdef FEATURE_WLAN_WAPI
3080 tANI_BOOLEAN fNewWapiBSSForCurConnection = eANI_BOOLEAN_FALSE;
3081#endif /* FEATURE_WLAN_WAPI */
3082 tDot11fBeaconIEs *pIesLocal = NULL;
3083 tANI_U32 sessionId = CSR_SESSION_ID_INVALID;
3084 tAniSSID tmpSsid;
3085 v_TIME_t timer=0;
3086
3087 tmpSsid.length = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07003088
3089 // remove the BSS descriptions from temporary list
3090 while( ( pEntry = csrLLRemoveTail( &pMac->scan.tempScanResults, LL_ACCESS_LOCK ) ) != NULL)
3091 {
3092 pBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3093
Arif Hussain24bafea2013-11-15 15:10:03 -08003094 smsLog( pMac, LOGW, "...Bssid= "MAC_ADDRESS_STR" chan= %d, rssi = -%d",
3095 MAC_ADDR_ARRAY(pBssDescription->Result.BssDescriptor.bssId),
Jeff Johnson295189b2012-06-20 16:38:30 -07003096 pBssDescription->Result.BssDescriptor.channelId,
3097 pBssDescription->Result.BssDescriptor.rssi * (-1) );
3098
3099 //At this time, pBssDescription->Result.pvIes may be NULL
3100 pIesLocal = (tDot11fBeaconIEs *)( pBssDescription->Result.pvIes );
3101 if( !pIesLocal && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pBssDescription->Result.BssDescriptor, &pIesLocal))) )
3102 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003103 smsLog(pMac, LOGE, FL(" Cannot pared IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003104 csrFreeScanResultEntry(pMac, pBssDescription);
3105 continue;
3106 }
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05303107 fDupBss = csrRemoveDupBssDescription( pMac, &pBssDescription->Result.BssDescriptor, pIesLocal, &tmpSsid, &timer, FALSE );
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07003108 //Check whether we have reach out limit, but don't lose the LFR candidates came from FW
3109 if( CSR_SCAN_IS_OVER_BSS_LIMIT(pMac)
3110#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
3111 && !( eCsrScanGetLfrResult == reason )
3112#endif
3113 )
Jeff Johnson295189b2012-06-20 16:38:30 -07003114 {
3115 //Limit reach
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003116 smsLog(pMac, LOGW, FL(" BSS limit reached"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003117 //Free the resources
3118 if( (pBssDescription->Result.pvIes == NULL) && pIesLocal )
3119 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303120 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003121 }
3122 csrFreeScanResultEntry(pMac, pBssDescription);
3123 //Continue because there may be duplicated BSS
3124 continue;
3125 }
3126 // check for duplicate scan results
3127 if ( !fDupBss )
3128 {
3129 //Found a new BSS
3130 sessionId = csrProcessBSSDescForPMKIDList(pMac,
3131 &pBssDescription->Result.BssDescriptor, pIesLocal);
3132 if( CSR_SESSION_ID_INVALID != sessionId)
3133 {
3134 csrRoamCallCallback(pMac, sessionId, NULL, 0,
3135 eCSR_ROAM_SCAN_FOUND_NEW_BSS, eCSR_ROAM_RESULT_NONE);
3136 }
3137 }
3138 else
3139 {
3140 //Check if the new one has SSID it it, if not, use the older SSID if it exists.
3141 if( (0 == pBssDescription->Result.ssId.length) && tmpSsid.length )
3142 {
3143 //New BSS has a hidden SSID and old one has the SSID. Keep the SSID only
3144 //if diff of saved SSID time and current time is less than 1 min to avoid
3145 //side effect of saving SSID with old one is that if AP changes its SSID while remain
3146 //hidden, we may never see it and also to address the requirement of
3147 //When we remove hidden ssid from the profile i.e., forget the SSID via
3148 // GUI that SSID shouldn't see in the profile
3149 if( (vos_timer_get_system_time() - timer) <= HIDDEN_TIMER)
3150 {
3151 pBssDescription->Result.timer = timer;
3152 pBssDescription->Result.ssId = tmpSsid;
3153 }
3154 }
3155 }
3156
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303157 //Find a good AP for 11d info
3158 if ( csrIs11dSupported( pMac ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003159 {
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303160 // check if country information element is present
3161 if (pIesLocal->Country.present)
Jeff Johnson295189b2012-06-20 16:38:30 -07003162 {
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303163 csrAddVoteForCountryInfo(pMac, pIesLocal->Country.country);
3164 smsLog(pMac, LOGW, FL("11d AP Bssid " MAC_ADDRESS_STR
3165 " chan= %d, rssi = -%d, countryCode %c%c"),
3166 MAC_ADDR_ARRAY( pBssDescription->Result.BssDescriptor.bssId),
3167 pBssDescription->Result.BssDescriptor.channelId,
3168 pBssDescription->Result.BssDescriptor.rssi * (-1),
3169 pIesLocal->Country.country[0],pIesLocal->Country.country[1] );
3170 }
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303171
Jeff Johnson295189b2012-06-20 16:38:30 -07003172 }
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08003173
Jeff Johnson295189b2012-06-20 16:38:30 -07003174 // append to main list
3175 csrScanAddResult(pMac, pBssDescription, pIesLocal);
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303176 if ( (pBssDescription->Result.pvIes == NULL) && pIesLocal )
Jeff Johnson295189b2012-06-20 16:38:30 -07003177 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303178 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003179 }
3180 }
3181
Tushnim Bhattacharyyaae317772013-10-23 18:55:38 -07003182 //we don't need to update CC while connected to an AP which is advertising CC already
3183 if (csrIs11dSupported(pMac))
3184 {
3185 tANI_U32 i;
3186 tCsrRoamSession *pSession;
3187
3188 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
3189 {
3190 if (CSR_IS_SESSION_VALID( pMac, i ) )
3191 {
3192 pSession = CSR_GET_SESSION( pMac, i );
3193 if (csrIsConnStateConnected(pMac, i))
3194 {
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303195 smsLog(pMac, LOGW, FL("No need for updating CC in"
3196 "connected state"));
3197 goto end;
Tushnim Bhattacharyyaae317772013-10-23 18:55:38 -07003198 }
3199 }
3200 }
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303201 csrElectedCountryInfo(pMac);
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05303202 csrLearnCountryInformation( pMac, NULL, NULL, eANI_BOOLEAN_TRUE );
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303203 }
3204
Tushnim Bhattacharyyaae317772013-10-23 18:55:38 -07003205end:
3206 //If we can find the current 11d info in any of the scan results, or
Jeff Johnson295189b2012-06-20 16:38:30 -07003207 // a good enough AP with the 11d info from the scan results then no need to
3208 // get into ambiguous state
3209 if(pMac->scan.fAmbiguous11dInfoFound)
3210 {
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303211 if((pMac->scan.fCurrent11dInfoMatch))
Jeff Johnson295189b2012-06-20 16:38:30 -07003212 {
3213 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
3214 }
3215 }
3216
3217#ifdef FEATURE_WLAN_WAPI
3218 if(fNewWapiBSSForCurConnection)
3219 {
3220 //remember it first
3221 csrRoamCallCallback(pMac, sessionId, NULL, 0, eCSR_ROAM_SCAN_FOUND_NEW_BSS, eCSR_ROAM_RESULT_NEW_WAPI_BSS);
3222 }
3223#endif /* FEATURE_WLAN_WAPI */
3224
3225 return;
3226}
3227
3228
3229static tCsrScanResult *csrScanSaveBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pBSSDescription,
3230 tDot11fBeaconIEs *pIes)
3231{
3232 tCsrScanResult *pCsrBssDescription = NULL;
3233 tANI_U32 cbBSSDesc;
3234 tANI_U32 cbAllocated;
Jeff Johnson295189b2012-06-20 16:38:30 -07003235
3236 // figure out how big the BSS description is (the BSSDesc->length does NOT
3237 // include the size of the length field itself).
3238 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
3239
3240 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
3241
Kiet Lam64c1b492013-07-12 13:56:44 +05303242 pCsrBssDescription = vos_mem_malloc(cbAllocated);
3243 if ( NULL != pCsrBssDescription )
Jeff Johnson295189b2012-06-20 16:38:30 -07003244 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303245 vos_mem_set(pCsrBssDescription, cbAllocated, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003246 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Kiet Lam64c1b492013-07-12 13:56:44 +05303247 vos_mem_copy(&pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc);
Jeff Johnson295189b2012-06-20 16:38:30 -07003248#if defined(VOSS_ENSBALED)
3249 VOS_ASSERT( pCsrBssDescription->Result.pvIes == NULL );
3250#endif
3251 csrScanAddResult(pMac, pCsrBssDescription, pIes);
3252 }
3253
3254 return( pCsrBssDescription );
3255}
3256
3257// Append a Bss Description...
3258tCsrScanResult *csrScanAppendBssDescription( tpAniSirGlobal pMac,
3259 tSirBssDescription *pSirBssDescription,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07003260 tDot11fBeaconIEs *pIes, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07003261{
3262 tCsrScanResult *pCsrBssDescription = NULL;
3263 tAniSSID tmpSsid;
3264 v_TIME_t timer = 0;
3265 int result;
3266
3267 tmpSsid.length = 0;
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07003268 result = csrRemoveDupBssDescription( pMac, pSirBssDescription, pIes, &tmpSsid, &timer, fForced );
Jeff Johnson295189b2012-06-20 16:38:30 -07003269 pCsrBssDescription = csrScanSaveBssDescription( pMac, pSirBssDescription, pIes );
3270 if (result && (pCsrBssDescription != NULL))
3271 {
3272 //Check if the new one has SSID it it, if not, use the older SSID if it exists.
3273 if( (0 == pCsrBssDescription->Result.ssId.length) && tmpSsid.length )
3274 {
3275 //New BSS has a hidden SSID and old one has the SSID. Keep the SSID only
3276 //if diff of saved SSID time and current time is less than 1 min to avoid
3277 //side effect of saving SSID with old one is that if AP changes its SSID while remain
3278 //hidden, we may never see it and also to address the requirement of
3279 //When we remove hidden ssid from the profile i.e., forget the SSID via
3280 // GUI that SSID shouldn't see in the profile
3281 if((vos_timer_get_system_time()-timer) <= HIDDEN_TIMER)
3282 {
3283 pCsrBssDescription->Result.ssId = tmpSsid;
3284 pCsrBssDescription->Result.timer = timer;
3285 }
3286 }
3287 }
3288
3289
3290 return( pCsrBssDescription );
3291}
3292
3293
3294
3295void csrPurgeChannelPower( tpAniSirGlobal pMac, tDblLinkList *pChannelList )
3296{
3297 tCsrChannelPowerInfo *pChannelSet;
3298 tListElem *pEntry;
3299
3300 csrLLLock(pChannelList);
3301 // Remove the channel sets from the learned list and put them in the free list
3302 while( ( pEntry = csrLLRemoveHead( pChannelList, LL_ACCESS_NOLOCK ) ) != NULL)
3303 {
3304 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3305 if( pChannelSet )
3306 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303307 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003308 }
3309 }
3310 csrLLUnlock(pChannelList);
3311 return;
3312}
3313
3314
3315/*
3316 * Save the channelList into the ultimate storage as the final stage of channel
3317 * Input: pCountryInfo -- the country code (e.g. "USI"), channel list, and power limit are all stored inside this data structure
3318 */
Jeff Johnsone7245742012-09-05 17:12:55 -07003319eHalStatus csrSaveToChannelPower2G_5G( tpAniSirGlobal pMac, tANI_U32 tableSize, tSirMacChanInfo *channelTable )
Jeff Johnson295189b2012-06-20 16:38:30 -07003320{
3321 tANI_U32 i = tableSize / sizeof( tSirMacChanInfo );
3322 tSirMacChanInfo *pChannelInfo;
3323 tCsrChannelPowerInfo *pChannelSet;
3324 tANI_BOOLEAN f2GHzInfoFound = FALSE;
3325 tANI_BOOLEAN f2GListPurged = FALSE, f5GListPurged = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003326
3327 pChannelInfo = channelTable;
3328 // atleast 3 bytes have to be remaining -- from "countryString"
3329 while ( i-- )
3330 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303331 pChannelSet = vos_mem_malloc(sizeof(tCsrChannelPowerInfo));
3332 if ( NULL != pChannelSet )
Jeff Johnson295189b2012-06-20 16:38:30 -07003333 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303334 vos_mem_set(pChannelSet, sizeof(tCsrChannelPowerInfo), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003335 pChannelSet->firstChannel = pChannelInfo->firstChanNum;
3336 pChannelSet->numChannels = pChannelInfo->numChannels;
3337
3338 // Now set the inter-channel offset based on the frequency band the channel set lies in
Jeff Johnsone7245742012-09-05 17:12:55 -07003339 if( (CSR_IS_CHANNEL_24GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003340 ((pChannelSet->firstChannel + (pChannelSet->numChannels - 1)) <= CSR_MAX_24GHz_CHANNEL_NUMBER) )
Jeff Johnsone7245742012-09-05 17:12:55 -07003341
Jeff Johnson295189b2012-06-20 16:38:30 -07003342 {
3343 pChannelSet->interChannelOffset = 1;
3344 f2GHzInfoFound = TRUE;
3345 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003346 else if ( (CSR_IS_CHANNEL_5GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003347 ((pChannelSet->firstChannel + ((pChannelSet->numChannels - 1) * 4)) <= CSR_MAX_5GHz_CHANNEL_NUMBER) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003348 {
3349 pChannelSet->interChannelOffset = 4;
3350 f2GHzInfoFound = FALSE;
3351 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003352 else
3353 {
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003354 smsLog( pMac, LOGW, FL("Invalid Channel %d Present in Country IE"),
Jeff Johnsone7245742012-09-05 17:12:55 -07003355 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303356 vos_mem_free(pChannelSet);
Jeff Johnsone7245742012-09-05 17:12:55 -07003357 return eHAL_STATUS_FAILURE;
3358 }
3359
Jeff Johnson295189b2012-06-20 16:38:30 -07003360 pChannelSet->txPower = CSR_ROAM_MIN( pChannelInfo->maxTxPower, pMac->roam.configParam.nTxPowerCap );
3361
3362 if( f2GHzInfoFound )
3363 {
3364 if( !f2GListPurged )
3365 {
3366 // purge previous results if found new
3367 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList24 );
3368 f2GListPurged = TRUE;
3369 }
3370
3371 if(CSR_IS_OPERATING_BG_BAND(pMac))
3372 {
3373 // add to the list of 2.4 GHz channel sets
3374 csrLLInsertTail( &pMac->scan.channelPowerInfoList24, &pChannelSet->link, LL_ACCESS_LOCK );
3375 }
3376 else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003377 smsLog( pMac, LOGW, FL("Adding 11B/G channels in 11A mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003378 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303379 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003380 }
3381 }
3382 else
3383 {
3384 // 5GHz info found
3385 if( !f5GListPurged )
3386 {
3387 // purge previous results if found new
3388 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList5G );
3389 f5GListPurged = TRUE;
3390 }
3391
3392 if(CSR_IS_OPERATING_A_BAND(pMac))
3393 {
3394 // add to the list of 5GHz channel sets
3395 csrLLInsertTail( &pMac->scan.channelPowerInfoList5G, &pChannelSet->link, LL_ACCESS_LOCK );
3396 }
3397 else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003398 smsLog( pMac, LOGW, FL("Adding 11A channels in B/G mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003399 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303400 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003401 }
3402 }
3403 }
3404
3405 pChannelInfo++; // move to next entry
3406 }
3407
Jeff Johnsone7245742012-09-05 17:12:55 -07003408 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07003409}
3410
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303411static void csrClearDfsChannelList( tpAniSirGlobal pMac )
3412{
3413 tSirMbMsg *pMsg;
3414 tANI_U16 msgLen;
Jeff Johnson295189b2012-06-20 16:38:30 -07003415
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303416 msgLen = (tANI_U16)(sizeof( tSirMbMsg ));
Kiet Lam64c1b492013-07-12 13:56:44 +05303417 pMsg = vos_mem_malloc(msgLen);
3418 if ( NULL != pMsg )
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303419 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303420 vos_mem_set((void *)pMsg, msgLen, 0);
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303421 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_CLEAR_DFS_CHANNEL_LIST);
3422 pMsg->msgLen = pal_cpu_to_be16(msgLen);
3423 palSendMBMessage(pMac->hHdd, pMsg);
3424 }
3425}
Jeff Johnson295189b2012-06-20 16:38:30 -07003426
3427void csrApplyPower2Current( tpAniSirGlobal pMac )
3428{
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003429 smsLog( pMac, LOG3, FL(" Updating Cfg with power settings"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003430 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList24, WNI_CFG_MAX_TX_POWER_2_4 );
3431 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList5G, WNI_CFG_MAX_TX_POWER_5 );
3432}
3433
3434
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003435void csrApplyChannelPowerCountryInfo( tpAniSirGlobal pMac, tCsrChannel *pChannelList, tANI_U8 *countryCode, tANI_BOOLEAN updateRiva)
Jeff Johnson295189b2012-06-20 16:38:30 -07003436{
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303437 int i, j, count, countryIndex = -1;
Jeff Johnson295189b2012-06-20 16:38:30 -07003438 eNVChannelEnabledType channelEnabledType;
3439 tANI_U8 numChannels = 0;
3440 tANI_U8 tempNumChannels = 0;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303441 tANI_U8 channelIgnore = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003442 tCsrChannel ChannelList;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303443
Jeff Johnson295189b2012-06-20 16:38:30 -07003444 if( pChannelList->numChannels )
3445 {
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303446 for(count=0; count < MAX_COUNTRY_IGNORE; count++)
3447 {
3448 if(vos_mem_compare(countryCode, countryIgnoreList[count].countryCode,
3449 VOS_COUNTRY_CODE_LEN))
3450 {
3451 countryIndex = count;
3452 break;
3453 }
3454 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003455 tempNumChannels = CSR_MIN(pChannelList->numChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN);
3456 /* If user doesn't want to scan the DFS channels lets trim them from
3457 the valid channel list*/
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303458 for(i=0; i < tempNumChannels; i++)
Jeff Johnson295189b2012-06-20 16:38:30 -07003459 {
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303460 channelIgnore = FALSE;
3461 if( FALSE == pMac->scan.fEnableDFSChnlScan )
3462 {
3463 channelEnabledType =
3464 vos_nv_getChannelEnabledState(pChannelList->channelList[i]);
3465 }
3466 else
3467 {
Madan Mohan Koyyalamudi3f65e312012-11-06 15:31:12 -08003468 channelEnabledType = NV_CHANNEL_ENABLE;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303469 }
3470 if( NV_CHANNEL_ENABLE == channelEnabledType )
3471 {
3472 if( countryIndex != -1 )
3473 {
3474 for(j=0; j < countryIgnoreList[countryIndex].channelCount; j++)
3475 {
3476 if( pChannelList->channelList[i] ==
3477 countryIgnoreList[countryIndex].channelList[j] )
3478 {
3479 channelIgnore = TRUE;
3480 break;
3481 }
3482 }
3483 }
3484 if( FALSE == channelIgnore )
3485 {
3486 ChannelList.channelList[numChannels] = pChannelList->channelList[i];
3487 numChannels++;
3488 }
3489 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003490 }
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303491 ChannelList.numChannels = numChannels;
Mahesh A Saptasagar1ed59582014-06-04 18:45:07 +05303492 csrApplyPower2Current( pMac ); // Store the channel+power info in the global place: Cfg
Jeff Johnson295189b2012-06-20 16:38:30 -07003493 csrSetCfgValidChannelList(pMac, ChannelList.channelList, ChannelList.numChannels);
3494 // extend scan capability
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303495 // build a scan list based on the channel list : channel# + active/passive scan
3496 csrSetCfgScanControlList(pMac, countryCode, &ChannelList);
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303497 /*Send msg to Lim to clear DFS channel list */
3498 csrClearDfsChannelList(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07003499#ifdef FEATURE_WLAN_SCAN_PNO
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003500 if (updateRiva)
3501 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003502 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO, FL(" Sending 11d PNO info to Riva"));
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003503 // Send HAL UpdateScanParams message
3504 pmcUpdateScanParams(pMac, &(pMac->roam.configParam), &ChannelList, TRUE);
3505 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003506#endif // FEATURE_WLAN_SCAN_PNO
3507 }
3508 else
3509 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003510 smsLog( pMac, LOGE, FL(" 11D channel list is empty"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003511 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003512 csrSetCfgCountryCode(pMac, countryCode);
3513}
3514
3515
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003516void csrResetCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce, tANI_BOOLEAN updateRiva )
Jeff Johnson295189b2012-06-20 16:38:30 -07003517{
3518 if( fForce || (csrIs11dSupported( pMac ) && (!pMac->scan.f11dInfoReset)))
3519 {
3520
3521#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3522 {
3523 vos_log_802_11d_pkt_type *p11dLog;
3524 int Index;
3525
3526 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
3527 if(p11dLog)
3528 {
3529 p11dLog->eventId = WLAN_80211D_EVENT_RESET;
Kiet Lam64c1b492013-07-12 13:56:44 +05303530 vos_mem_copy(p11dLog->countryCode, pMac->scan.countryCodeCurrent, 3);
Jeff Johnson295189b2012-06-20 16:38:30 -07003531 p11dLog->numChannel = pMac->scan.base20MHzChannels.numChannels;
3532 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
3533 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303534 vos_mem_copy(p11dLog->Channels,
3535 pMac->scan.base20MHzChannels.channelList,
3536 p11dLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07003537 for (Index=0; Index < pMac->scan.base20MHzChannels.numChannels; Index++)
3538 {
3539 p11dLog->TxPwr[Index] = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
3540 }
3541 }
3542 if(!pMac->roam.configParam.Is11dSupportEnabled)
3543 {
3544 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
3545 }
3546 else if(pMac->roam.configParam.fEnforceDefaultDomain)
3547 {
3548 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
3549 }
3550 else
3551 {
3552 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
3553 }
3554 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
3555 }
3556 }
3557#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3558
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003559 csrPruneChannelListForMode(pMac, &pMac->scan.baseChannels);
3560 csrPruneChannelListForMode(pMac, &pMac->scan.base20MHzChannels);
3561
Jeff Johnson295189b2012-06-20 16:38:30 -07003562 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_FALSE);
3563 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_TRUE);
3564 // ... and apply the channel list, power settings, and the country code.
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003565 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.base20MHzChannels, pMac->scan.countryCodeCurrent, updateRiva );
Jeff Johnson295189b2012-06-20 16:38:30 -07003566 // clear the 11d channel list
Kiet Lam64c1b492013-07-12 13:56:44 +05303567 vos_mem_set(&pMac->scan.channels11d, sizeof(pMac->scan.channels11d), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003568 pMac->scan.f11dInfoReset = eANI_BOOLEAN_TRUE;
3569 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_FALSE;
3570 }
3571
3572 return;
3573}
3574
3575
3576eHalStatus csrResetCountryCodeInformation(tpAniSirGlobal pMac, tANI_BOOLEAN *pfRestartNeeded)
3577{
3578 eHalStatus status = eHAL_STATUS_SUCCESS;
3579 tANI_BOOLEAN fRestart = eANI_BOOLEAN_FALSE;
3580
3581 //Use the Country code and domain from EEPROM
Kiet Lam64c1b492013-07-12 13:56:44 +05303582 vos_mem_copy(pMac->scan.countryCodeCurrent, pMac->scan.countryCodeDefault,
3583 WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07003584 csrSetRegulatoryDomain(pMac, pMac->scan.domainIdCurrent, &fRestart);
Jeff Johnson43971f52012-07-17 12:26:56 -07003585 if( ((eANI_BOOLEAN_FALSE == fRestart) || (pfRestartNeeded == NULL) )
3586 && !csrIsInfraConnected(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -07003587 {
3588 //Only reset the country info if we don't need to restart
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003589 csrResetCountryInformation(pMac, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07003590 }
3591 if(pfRestartNeeded)
3592 {
3593 *pfRestartNeeded = fRestart;
3594 }
3595
3596 return (status);
3597}
3598
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303599void csrClearVotesForCountryInfo(tpAniSirGlobal pMac)
3600{
3601 pMac->scan.countryCodeCount = 0;
3602 vos_mem_set(pMac->scan.votes11d,
3603 sizeof(tCsrVotes11d) * CSR_MAX_NUM_COUNTRY_CODE, 0);
3604}
3605
3606void csrAddVoteForCountryInfo(tpAniSirGlobal pMac, tANI_U8 *pCountryCode)
3607{
3608 tANI_BOOLEAN match = FALSE;
3609 tANI_U8 i;
3610
3611 /* convert to UPPER here so we are assured
3612 * the strings are always in upper case.
3613 */
3614 for( i = 0; i < 3; i++ )
3615 {
3616 pCountryCode[ i ] = (tANI_U8)csrToUpper( pCountryCode[ i ] );
3617 }
3618
3619 /* Some of the 'old' Cisco 350 series AP's advertise NA as the
3620 * country code (for North America ??). NA is not a valid country code
3621 * or domain so let's allow this by changing it to the proper
3622 * country code (which is US). We've also seen some NETGEAR AP's
3623 * that have "XX " as the country code with valid 2.4 GHz US channel
3624 * information. If we cannot find the country code advertised in the
3625 * 11d information element, let's default to US.
3626 */
3627
3628 if ( !HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry( pMac,
3629 pCountryCode, NULL,COUNTRY_QUERY ) ) )
3630 {
3631 pCountryCode[ 0 ] = '0';
3632 pCountryCode[ 1 ] = '0';
3633 }
3634
3635 /* We've seen some of the AP's improperly put a 0 for the
3636 * third character of the country code. spec says valid charcters are
3637 * 'O' (for outdoor), 'I' for Indoor, or ' ' (space; for either).
3638 * if we see a 0 in this third character, let's change it to a ' '.
3639 */
3640 if ( 0 == pCountryCode[ 2 ] )
3641 {
3642 pCountryCode[ 2 ] = ' ';
3643 }
3644
3645 for (i = 0; i < pMac->scan.countryCodeCount; i++)
3646 {
3647 match = (vos_mem_compare(pMac->scan.votes11d[i].countryCode,
3648 pCountryCode, 2));
3649 if(match)
3650 {
3651 break;
3652 }
3653 }
3654
3655 if (match)
3656 {
3657 pMac->scan.votes11d[i].votes++;
3658 }
3659 else
3660 {
3661 vos_mem_copy( pMac->scan.votes11d[pMac->scan.countryCodeCount].countryCode,
3662 pCountryCode, 3 );
3663 pMac->scan.votes11d[pMac->scan.countryCodeCount].votes = 1;
3664 pMac->scan.countryCodeCount++;
3665 }
3666
3667 return;
3668}
3669
3670tANI_BOOLEAN csrElectedCountryInfo(tpAniSirGlobal pMac)
3671{
3672 tANI_BOOLEAN fRet = FALSE;
3673 tANI_U8 maxVotes = 0;
3674 tANI_U8 i, j=0;
3675
3676 if (!pMac->scan.countryCodeCount)
3677 {
3678 return fRet;
3679 }
3680 maxVotes = pMac->scan.votes11d[0].votes;
3681 fRet = TRUE;
3682
3683 for(i = 1; i < pMac->scan.countryCodeCount; i++)
3684 {
3685 /* If we have a tie for max votes for 2 different country codes,
3686 * pick random.we can put some more intelligence - TBD
3687 */
3688 if (maxVotes < pMac->scan.votes11d[i].votes)
3689 {
3690 VOS_TRACE( VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
3691 " Votes for Country %c%c : %d\n",
3692 pMac->scan.votes11d[i].countryCode[0],
3693 pMac->scan.votes11d[i].countryCode[1],
3694 pMac->scan.votes11d[i].votes);
3695
3696 maxVotes = pMac->scan.votes11d[i].votes;
3697 j = i;
3698 fRet = TRUE;
3699 }
3700
3701 }
3702 if (fRet)
3703 {
Rajesh Babu Prathipati20cdffa2014-07-01 22:24:59 +05303704 vos_mem_copy(pMac->scan.countryCodeElected,
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303705 pMac->scan.votes11d[j].countryCode, WNI_CFG_COUNTRY_CODE_LEN);
Rajesh Babu Prathipati20cdffa2014-07-01 22:24:59 +05303706 vos_mem_copy(pMac->scan.countryCode11d,
Agarwal Ashish852b2c32014-05-23 17:13:25 +05303707 pMac->scan.votes11d[j].countryCode, WNI_CFG_COUNTRY_CODE_LEN);
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05303708 VOS_TRACE( VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
3709 "Selected Country is %c%c With count %d\n",
3710 pMac->scan.votes11d[j].countryCode[0],
3711 pMac->scan.votes11d[j].countryCode[1],
3712 pMac->scan.votes11d[j].votes);
3713 }
3714 return fRet;
3715}
Jeff Johnson295189b2012-06-20 16:38:30 -07003716
3717eHalStatus csrSetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pCountry, tANI_BOOLEAN *pfRestartNeeded)
3718{
3719 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
3720 v_REGDOMAIN_t domainId;
3721
3722 if(pCountry)
3723 {
Kiet Lam6c583332013-10-14 05:37:09 +05303724 status = csrGetRegulatoryDomainForCountry(pMac, pCountry, &domainId, COUNTRY_USER);
Jeff Johnson295189b2012-06-20 16:38:30 -07003725 if(HAL_STATUS_SUCCESS(status))
3726 {
3727 status = csrSetRegulatoryDomain(pMac, domainId, pfRestartNeeded);
3728 if(HAL_STATUS_SUCCESS(status))
3729 {
3730 //We don't need to check the pMac->roam.configParam.fEnforceDefaultDomain flag here,
3731 //csrSetRegulatoryDomain will fail if the country doesn't fit our domain criteria.
Kiet Lam64c1b492013-07-12 13:56:44 +05303732 vos_mem_copy(pMac->scan.countryCodeCurrent, pCountry, WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07003733 if((pfRestartNeeded == NULL) || !(*pfRestartNeeded))
3734 {
3735 //Simply set it to cfg. If we need to restart, restart will apply it to the CFG
3736 csrSetCfgCountryCode(pMac, pCountry);
3737 }
3738 }
3739 }
3740 }
3741
3742 return (status);
3743}
3744
3745
3746
3747//caller allocated memory for pNumChn and pChnPowerInfo
3748//As input, *pNumChn has the size of the array of pChnPowerInfo
3749//Upon return, *pNumChn has the number of channels assigned.
3750void csrGetChannelPowerInfo( tpAniSirGlobal pMac, tDblLinkList *pList,
3751 tANI_U32 *pNumChn, tChannelListWithPower *pChnPowerInfo)
3752{
3753 tListElem *pEntry;
3754 tANI_U32 chnIdx = 0, idx;
3755 tCsrChannelPowerInfo *pChannelSet;
3756
3757 //Get 2.4Ghz first
3758 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
3759 while( pEntry && (chnIdx < *pNumChn) )
3760 {
3761 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3762 if ( 1 != pChannelSet->interChannelOffset )
3763 {
3764 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
3765 {
3766 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
3767 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
3768 }
3769 }
3770 else
3771 {
3772 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
3773 {
3774 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + idx);
3775 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
3776 }
3777 }
3778
3779 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
3780 }
3781 *pNumChn = chnIdx;
3782
3783 return ;
3784}
3785
3786
3787
3788void csrApplyCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce )
3789{
3790 v_REGDOMAIN_t domainId;
3791 eHalStatus status = eHAL_STATUS_SUCCESS;
3792
3793 do
3794 {
3795 if( !csrIs11dSupported( pMac ) || 0 == pMac->scan.channelOf11dInfo) break;
3796 if( pMac->scan.fAmbiguous11dInfoFound )
3797 {
3798 // ambiguous info found
3799 //Restore te default domain as well
Kiet Lam6c583332013-10-14 05:37:09 +05303800 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
3801 pMac, pMac->scan.countryCodeCurrent,
3802 &domainId, COUNTRY_QUERY)))
Jeff Johnson295189b2012-06-20 16:38:30 -07003803 {
3804 pMac->scan.domainIdCurrent = domainId;
3805 }
3806 else
3807 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003808 smsLog(pMac, LOGE, FL(" failed to get domain from currentCountryCode %02X%02X"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003809 pMac->scan.countryCodeCurrent[0], pMac->scan.countryCodeCurrent[1]);
3810 }
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003811 csrResetCountryInformation( pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE );
Jeff Johnson295189b2012-06-20 16:38:30 -07003812 break;
3813 }
3814 if ( pMac->scan.f11dInfoApplied && !fForce ) break;
Kiet Lam6c583332013-10-14 05:37:09 +05303815 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
3816 pMac, pMac->scan.countryCode11d,
3817 &domainId, COUNTRY_QUERY)))
Jeff Johnson295189b2012-06-20 16:38:30 -07003818 {
3819 //Check whether we need to enforce default domain
3820 if( ( !pMac->roam.configParam.fEnforceDefaultDomain ) ||
3821 (pMac->scan.domainIdCurrent == domainId) )
3822 {
3823
3824#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3825 {
3826 vos_log_802_11d_pkt_type *p11dLog;
3827 tChannelListWithPower chnPwrInfo[WNI_CFG_VALID_CHANNEL_LIST_LEN];
3828 tANI_U32 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN, nTmp;
3829
3830 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
3831 if(p11dLog)
3832 {
3833 p11dLog->eventId = WLAN_80211D_EVENT_COUNTRY_SET;
Kiet Lam64c1b492013-07-12 13:56:44 +05303834 vos_mem_copy(p11dLog->countryCode, pMac->scan.countryCode11d, 3);
Jeff Johnson295189b2012-06-20 16:38:30 -07003835 p11dLog->numChannel = pMac->scan.channels11d.numChannels;
3836 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
3837 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303838 vos_mem_copy(p11dLog->Channels,
3839 pMac->scan.channels11d.channelList,
3840 p11dLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07003841 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList24,
3842 &nChnInfo, chnPwrInfo);
3843 nTmp = nChnInfo;
3844 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN - nTmp;
3845 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList5G,
3846 &nChnInfo, &chnPwrInfo[nTmp]);
3847 for(nTmp = 0; nTmp < p11dLog->numChannel; nTmp++)
3848 {
3849 for(nChnInfo = 0; nChnInfo < WNI_CFG_VALID_CHANNEL_LIST_LEN; nChnInfo++)
3850 {
3851 if(p11dLog->Channels[nTmp] == chnPwrInfo[nChnInfo].chanId)
3852 {
3853 p11dLog->TxPwr[nTmp] = chnPwrInfo[nChnInfo].pwr;
3854 break;
3855 }
3856 }
3857 }
3858 }
3859 if(!pMac->roam.configParam.Is11dSupportEnabled)
3860 {
3861 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
3862 }
3863 else if(pMac->roam.configParam.fEnforceDefaultDomain)
3864 {
3865 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
3866 }
3867 else
3868 {
3869 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
3870 }
3871 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
3872 }
3873 }
3874#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3875 if(pMac->scan.domainIdCurrent != domainId)
3876 {
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05303877 smsLog(pMac, LOGW, FL("Domain Changed Old %s (%d), new %s"),
3878 voss_DomainIdtoString(pMac->scan.domainIdCurrent),
3879 pMac->scan.domainIdCurrent,
3880 voss_DomainIdtoString(domainId));
Abhishek Singha306a442013-11-07 18:39:01 +05303881 status = WDA_SetRegDomain(pMac, domainId, eSIR_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07003882 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003883 if (status != eHAL_STATUS_SUCCESS)
3884 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003885 smsLog( pMac, LOGE, FL(" fail to set regId %d"), domainId );
Jeff Johnson295189b2012-06-20 16:38:30 -07003886 }
3887 pMac->scan.domainIdCurrent = domainId;
Kiet Lam6c583332013-10-14 05:37:09 +05303888#ifndef CONFIG_ENABLE_LINUX_REG
Kiet Lambb14e952013-11-19 14:58:29 +05303889 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.base20MHzChannels,
3890 pMac->scan.countryCodeCurrent, eANI_BOOLEAN_TRUE );
Kiet Lam6c583332013-10-14 05:37:09 +05303891#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07003892 // switch to active scans using this new channel list
3893 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
3894 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_TRUE;
3895 pMac->scan.f11dInfoReset = eANI_BOOLEAN_FALSE;
3896 }
3897 }
3898
3899 } while( 0 );
3900
3901 return;
3902}
3903
3904
3905
3906tANI_BOOLEAN csrSave11dCountryString( tpAniSirGlobal pMac, tANI_U8 *pCountryCode,
3907 tANI_BOOLEAN fForce)
3908{
3909 tANI_BOOLEAN fCountryStringChanged = FALSE, fUnknownCountryCode = FALSE;
3910 tANI_U32 i;
Kiet Lam6c583332013-10-14 05:37:09 +05303911 v_REGDOMAIN_t regd;
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08003912 tANI_BOOLEAN fCountryNotPresentInDriver = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003913
3914 // convert to UPPER here so we are assured the strings are always in upper case.
3915 for( i = 0; i < 3; i++ )
3916 {
3917 pCountryCode[ i ] = (tANI_U8)csrToUpper( pCountryCode[ i ] );
3918 }
3919
3920 // Some of the 'old' Cisco 350 series AP's advertise NA as the country code (for North America ??).
3921 // NA is not a valid country code or domain so let's allow this by changing it to the proper
3922 // country code (which is US). We've also seen some NETGEAR AP's that have "XX " as the country code
3923 // with valid 2.4 GHz US channel information. If we cannot find the country code advertised in the
3924 // 11d information element, let's default to US.
Kiet Lam6c583332013-10-14 05:37:09 +05303925 if ( !HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(pMac,
3926 pCountryCode,
3927 &regd,
3928 COUNTRY_QUERY) ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003929 {
3930 // Check the enforcement first
3931 if( pMac->roam.configParam.fEnforceDefaultDomain || pMac->roam.configParam.fEnforceCountryCodeMatch )
3932 {
3933 fUnknownCountryCode = TRUE;
3934 }
3935 else
3936 {
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08003937 fCountryNotPresentInDriver = TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003938 }
3939 }
Tushnim Bhattacharyyac3c1e8e2013-10-29 17:27:43 -07003940 //right now, even if we don't find the CC in driver we set to world. Making
3941 //sure countryCode11d doesn't get updated with the invalid CC, instead
3942 //reflect the world CC
3943 else if (REGDOMAIN_WORLD == regd)
3944 {
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08003945 fCountryNotPresentInDriver = TRUE;
Tushnim Bhattacharyyac3c1e8e2013-10-29 17:27:43 -07003946 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003947
3948 // We've seen some of the AP's improperly put a 0 for the third character of the country code.
3949 // spec says valid charcters are 'O' (for outdoor), 'I' for Indoor, or ' ' (space; for either).
3950 // if we see a 0 in this third character, let's change it to a ' '.
3951 if ( 0 == pCountryCode[ 2 ] )
3952 {
3953 pCountryCode[ 2 ] = ' ';
3954 }
3955
3956 if( !fUnknownCountryCode )
3957 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303958 fCountryStringChanged = (!vos_mem_compare(pMac->scan.countryCode11d, pCountryCode, 2));
Jeff Johnson295189b2012-06-20 16:38:30 -07003959
3960
3961 if(( 0 == pMac->scan.countryCode11d[ 0 ] && 0 == pMac->scan.countryCode11d[ 1 ] )
3962 || (fForce))
3963 {
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08003964 if (!fCountryNotPresentInDriver)
3965 {
3966 // this is the first .11d information
3967 vos_mem_copy(pMac->scan.countryCode11d, pCountryCode,
Kiet Lam64c1b492013-07-12 13:56:44 +05303968 sizeof( pMac->scan.countryCode11d ));
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08003969
3970 }
3971 else
3972 {
3973 pMac->scan.countryCode11d[0] = '0';
3974 pMac->scan.countryCode11d[1] = '0';
3975 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003976 }
3977 }
3978
3979 return( fCountryStringChanged );
3980}
3981
3982
3983void csrSaveChannelPowerForBand( tpAniSirGlobal pMac, tANI_BOOLEAN fPopulate5GBand )
3984{
3985 tANI_U32 Index, count=0;
3986 tSirMacChanInfo *pChanInfo;
3987 tSirMacChanInfo *pChanInfoStart;
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08003988 tANI_S32 maxChannelIndex;
3989
3990 maxChannelIndex = ( pMac->scan.base20MHzChannels.numChannels < WNI_CFG_VALID_CHANNEL_LIST_LEN ) ?
3991 pMac->scan.base20MHzChannels.numChannels : WNI_CFG_VALID_CHANNEL_LIST_LEN ;
Jeff Johnson295189b2012-06-20 16:38:30 -07003992
Kiet Lam64c1b492013-07-12 13:56:44 +05303993 pChanInfo = vos_mem_malloc(sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN);
3994 if ( NULL != pChanInfo )
Jeff Johnson295189b2012-06-20 16:38:30 -07003995 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303996 vos_mem_set(pChanInfo, sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003997 pChanInfoStart = pChanInfo;
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08003998 for (Index=0; Index < maxChannelIndex; Index++)
Jeff Johnson295189b2012-06-20 16:38:30 -07003999 {
4000 if ((fPopulate5GBand && (CSR_IS_CHANNEL_5GHZ(pMac->scan.defaultPowerTable[Index].chanId))) ||
4001 (!fPopulate5GBand && (CSR_IS_CHANNEL_24GHZ(pMac->scan.defaultPowerTable[Index].chanId))) )
4002 {
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08004003 if(count >= WNI_CFG_VALID_CHANNEL_LIST_LEN)
4004 {
4005 smsLog( pMac, LOGW, FL(" csrSaveChannelPowerForBand, count exceeded, count = %d"), count);
4006 break;
4007 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004008 pChanInfo->firstChanNum = pMac->scan.defaultPowerTable[Index].chanId;
4009 pChanInfo->numChannels = 1;
4010 pChanInfo->maxTxPower = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
4011 pChanInfo++;
4012 count++;
4013 }
4014 }
4015 if(count)
4016 {
4017 csrSaveToChannelPower2G_5G( pMac, count * sizeof(tSirMacChanInfo), pChanInfoStart );
4018 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304019 vos_mem_free(pChanInfoStart);
Jeff Johnson295189b2012-06-20 16:38:30 -07004020 }
4021}
4022
4023
4024void csrSetOppositeBandChannelInfo( tpAniSirGlobal pMac )
4025{
4026 tANI_BOOLEAN fPopulate5GBand = FALSE;
4027
4028 do
4029 {
4030 // if this is not a dual band product, then we don't need to set the opposite
4031 // band info. We only work in one band so no need to look in the other band.
4032 if ( !CSR_IS_OPEARTING_DUAL_BAND( pMac ) ) break;
4033 // if we found channel info on the 5.0 band and...
4034 if ( CSR_IS_CHANNEL_5GHZ( pMac->scan.channelOf11dInfo ) )
4035 {
4036 // and the 2.4 band is empty, then populate the 2.4 channel info
Kiet Lam8d985a02013-10-11 03:39:41 +05304037 if ( !csrLLIsListEmpty( &pMac->scan.channelPowerInfoList24, LL_ACCESS_LOCK ) ) break;
Jeff Johnson295189b2012-06-20 16:38:30 -07004038 fPopulate5GBand = FALSE;
4039 }
4040 else
4041 {
4042 // else, we found channel info in the 2.4 GHz band. If the 5.0 band is empty
4043 // set the 5.0 band info from the 2.4 country code.
Kiet Lam8d985a02013-10-11 03:39:41 +05304044 if ( !csrLLIsListEmpty( &pMac->scan.channelPowerInfoList5G, LL_ACCESS_LOCK ) ) break;
Jeff Johnson295189b2012-06-20 16:38:30 -07004045 fPopulate5GBand = TRUE;
4046 }
4047 csrSaveChannelPowerForBand( pMac, fPopulate5GBand );
4048
4049 } while( 0 );
4050}
4051
4052
4053tANI_BOOLEAN csrIsSupportedChannel(tpAniSirGlobal pMac, tANI_U8 channelId)
4054{
4055 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
4056 tANI_U32 i;
4057
4058 //Make sure it is a channel that is in our supported list.
4059 for ( i = 0; i < pMac->scan.baseChannels.numChannels; i++ )
4060 {
4061 if ( channelId == pMac->scan.baseChannels.channelList[i] )
4062 {
4063 fRet = eANI_BOOLEAN_TRUE;
4064 break;
4065 }
4066 }
4067
4068 //If it is configured to limit a set of the channels
4069 if( fRet && pMac->roam.configParam.fEnforce11dChannels )
4070 {
4071 fRet = eANI_BOOLEAN_FALSE;
4072 for ( i = 0; i < pMac->scan.base20MHzChannels.numChannels; i++ )
4073 {
4074 if ( channelId == pMac->scan.base20MHzChannels.channelList[i] )
4075 {
4076 fRet = eANI_BOOLEAN_TRUE;
4077 break;
4078 }
4079 }
4080 }
4081
4082 return (fRet);
4083}
4084
4085
4086
4087//bSize specify the buffer size of pChannelList
4088tANI_U8 csrGetChannelListFromChannelSet( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 bSize, tCsrChannelPowerInfo *pChannelSet )
4089{
4090 tANI_U8 i, j = 0, chnId;
4091
4092 bSize = CSR_MIN(bSize, pChannelSet->numChannels);
4093 for( i = 0; i < bSize; i++ )
4094 {
4095 chnId = (tANI_U8)(pChannelSet->firstChannel + ( i * pChannelSet->interChannelOffset ));
4096 if ( csrIsSupportedChannel( pMac, chnId ) )
4097 {
4098 pChannelList[j++] = chnId;
4099 }
4100 }
4101
4102 return (j);
4103}
4104
4105
4106
4107//bSize -- specify the buffer size of pChannelList
4108void csrConstructCurrentValidChannelList( tpAniSirGlobal pMac, tDblLinkList *pChannelSetList,
4109 tANI_U8 *pChannelList, tANI_U8 bSize, tANI_U8 *pNumChannels )
4110{
4111 tListElem *pEntry;
4112 tCsrChannelPowerInfo *pChannelSet;
4113 tANI_U8 numChannels;
4114 tANI_U8 *pChannels;
4115
4116 if( pChannelSetList && pChannelList && pNumChannels )
4117 {
4118 pChannels = pChannelList;
4119 *pNumChannels = 0;
4120 pEntry = csrLLPeekHead( pChannelSetList, LL_ACCESS_LOCK );
4121 while( pEntry )
4122 {
4123 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
4124 numChannels = csrGetChannelListFromChannelSet( pMac, pChannels, bSize, pChannelSet );
4125 pChannels += numChannels;
4126 *pNumChannels += numChannels;
4127 pEntry = csrLLNext( pChannelSetList, pEntry, LL_ACCESS_LOCK );
4128 }
4129 }
4130}
4131
4132
4133/*
4134 * 802.11D only: Gather 11d IE via beacon or Probe response and store them in pAdapter->channels11d
4135*/
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304136tANI_BOOLEAN csrLearnCountryInformation( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc,
4137 tDot11fBeaconIEs *pIes, tANI_BOOLEAN fForce)
Jeff Johnson295189b2012-06-20 16:38:30 -07004138{
Agarwal Ashish60a37ee2014-05-28 17:20:20 +05304139 eHalStatus status;
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304140 tANI_U8 *pCountryCodeSelected;
Jeff Johnson295189b2012-06-20 16:38:30 -07004141 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
4142 v_REGDOMAIN_t domainId;
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304143 tDot11fBeaconIEs *pIesLocal = pIes;
4144 tANI_BOOLEAN useVoting = eANI_BOOLEAN_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07004145
Jeff Johnson295189b2012-06-20 16:38:30 -07004146 if (VOS_STA_SAP_MODE == vos_get_conparam ())
4147 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07004148
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304149 if ((NULL == pSirBssDesc) && (NULL == pIes))
4150 useVoting = eANI_BOOLEAN_TRUE;
4151
Jeff Johnson295189b2012-06-20 16:38:30 -07004152 do
4153 {
4154 // check if .11d support is enabled
4155 if( !csrIs11dSupported( pMac ) ) break;
Agarwal Ashish60a37ee2014-05-28 17:20:20 +05304156
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304157 if (eANI_BOOLEAN_FALSE == useVoting)
4158 {
4159 if( !pIesLocal &&
4160 (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
4161 pSirBssDesc, &pIesLocal))))
4162 {
4163 break;
4164 }
4165 // check if country information element is present
4166 if(!pIesLocal->Country.present)
4167 {
4168 //No country info
4169 break;
4170 }
4171
4172 if( HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry
4173 (pMac, pIesLocal->Country.country, &domainId,
4174 COUNTRY_QUERY)) &&
4175 ( domainId == REGDOMAIN_WORLD))
4176 {
4177 break;
4178 }
4179 } //useVoting == eANI_BOOLEAN_FALSE
4180
4181 if (eANI_BOOLEAN_FALSE == useVoting)
4182 pCountryCodeSelected = pIesLocal->Country.country;
4183 else
4184 pCountryCodeSelected = pMac->scan.countryCodeElected;
4185
Kiet Lam8d985a02013-10-11 03:39:41 +05304186 status = csrGetRegulatoryDomainForCountry(pMac,
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304187 pCountryCodeSelected, &domainId, COUNTRY_IE);
Kiet Lam8d985a02013-10-11 03:39:41 +05304188 if ( status != eHAL_STATUS_SUCCESS )
4189 {
4190 smsLog( pMac, LOGE, FL(" fail to get regId %d"), domainId );
4191 fRet = eANI_BOOLEAN_FALSE;
4192 break;
4193 }
Agarwal Ashish7693f2d2014-07-18 18:03:58 +05304194
4195 /* updating 11d Country Code with Country code selected. */
4196
4197 vos_mem_copy(pMac->scan.countryCode11d,
4198 pCountryCodeSelected,
4199 WNI_CFG_COUNTRY_CODE_LEN);
4200
Agarwal Ashish60a37ee2014-05-28 17:20:20 +05304201#ifndef CONFIG_ENABLE_LINUX_REG
Venkata Prathyusha Kuntupalli316247e2013-03-15 17:45:25 -07004202 // Checking for Domain Id change
4203 if ( domainId != pMac->scan.domainIdCurrent )
4204 {
Kiet Lam8d985a02013-10-11 03:39:41 +05304205 vos_mem_copy(pMac->scan.countryCode11d,
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304206 pCountryCodeSelected,
Kiet Lam8d985a02013-10-11 03:39:41 +05304207 sizeof( pMac->scan.countryCode11d ) );
4208 /* Set Current Country code and Current Regulatory domain */
4209 status = csrSetRegulatoryDomain(pMac, domainId, NULL);
4210 if (eHAL_STATUS_SUCCESS != status)
4211 {
4212 smsLog(pMac, LOGE, "Set Reg Domain Fail %d", status);
4213 fRet = eANI_BOOLEAN_FALSE;
4214 return fRet;
4215 }
4216 //csrSetRegulatoryDomain will fail if the country doesn't fit our domain criteria.
4217 vos_mem_copy(pMac->scan.countryCodeCurrent,
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304218 pCountryCodeSelected, WNI_CFG_COUNTRY_CODE_LEN);
Kiet Lam8d985a02013-10-11 03:39:41 +05304219 //Simply set it to cfg.
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304220 csrSetCfgCountryCode(pMac, pCountryCodeSelected);
Kiet Lam8d985a02013-10-11 03:39:41 +05304221
4222 /* overwrite the defualt country code */
4223 vos_mem_copy(pMac->scan.countryCodeDefault,
4224 pMac->scan.countryCodeCurrent,
4225 WNI_CFG_COUNTRY_CODE_LEN);
4226 /* Set Current RegDomain */
Abhishek Singha306a442013-11-07 18:39:01 +05304227 status = WDA_SetRegDomain(pMac, domainId, eSIR_TRUE);
Kiet Lam8d985a02013-10-11 03:39:41 +05304228 if ( status != eHAL_STATUS_SUCCESS )
4229 {
4230 smsLog( pMac, LOGE, FL(" fail to Set regId %d"), domainId );
4231 fRet = eANI_BOOLEAN_FALSE;
4232 return fRet;
4233 }
4234 /* set to default domain ID */
Madan Mohan Koyyalamudi0e5922d2013-09-10 15:45:24 +05304235 pMac->scan.domainIdCurrent = domainId;
Kiet Lam8d985a02013-10-11 03:39:41 +05304236 /* get the channels based on new cc */
4237 status = csrInitGetChannels( pMac );
Jeff Johnson295189b2012-06-20 16:38:30 -07004238
Kiet Lam8d985a02013-10-11 03:39:41 +05304239 if ( status != eHAL_STATUS_SUCCESS )
4240 {
4241 smsLog( pMac, LOGE, FL(" fail to get Channels "));
4242 fRet = eANI_BOOLEAN_FALSE;
4243 return fRet;
4244 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004245
Kiet Lam8d985a02013-10-11 03:39:41 +05304246 /* reset info based on new cc, and we are done */
4247 csrResetCountryInformation(pMac, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
Agarwal Ashishfaef6692014-01-29 19:40:30 +05304248 /* Regulatory Domain Changed, Purge Only scan result
4249 * which does not have channel number belong to 11d
4250 * channel list
4251 */
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05304252 csrScanFilterResults(pMac);
Kiet Lam8d985a02013-10-11 03:39:41 +05304253 }
Kiet Lam6c583332013-10-14 05:37:09 +05304254#endif
4255 fRet = eANI_BOOLEAN_TRUE;
4256
Jeff Johnson295189b2012-06-20 16:38:30 -07004257 } while( 0 );
Chandrasekaran, Manishekar90c49322014-06-24 13:26:14 +05304258
4259 if( !pIes && pIesLocal )
4260 {
4261 //locally allocated
4262 vos_mem_free(pIesLocal);
4263 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004264
4265 return( fRet );
4266}
4267
4268
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004269static void csrSaveScanResults( tpAniSirGlobal pMac, tANI_U8 reason )
Jeff Johnson295189b2012-06-20 16:38:30 -07004270{
4271 // initialize this to FALSE. profMoveInterimScanResultsToMainList() routine
4272 // will set this to the channel where an .11d beacon is seen
4273 pMac->scan.channelOf11dInfo = 0;
4274 // if we get any ambiguous .11d information then this will be set to TRUE
4275 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
4276 //Tush
4277 // if we get any ambiguous .11d information, then this will be set to TRUE
4278 // only if the applied 11d info could be found in one of the scan results
4279 pMac->scan.fCurrent11dInfoMatch = eANI_BOOLEAN_FALSE;
4280 // move the scan results from interim list to the main scan list
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004281 csrMoveTempScanResultsToMainList( pMac, reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07004282}
4283
4284
4285void csrReinitScanCmd(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4286{
4287 switch (pCommand->u.scanCmd.reason)
4288 {
4289 case eCsrScanSetBGScanParam:
4290 case eCsrScanAbortBgScan:
4291 if(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList)
4292 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304293 vos_mem_free(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList);
Jeff Johnson295189b2012-06-20 16:38:30 -07004294 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
4295 }
4296 break;
4297 case eCsrScanBGScanAbort:
4298 case eCsrScanBGScanEnable:
4299 case eCsrScanGetScanChnInfo:
4300 break;
4301 case eCsrScanAbortNormalScan:
4302 default:
4303 csrScanFreeRequest(pMac, &pCommand->u.scanCmd.u.scanRequest);
4304 break;
4305 }
4306 if(pCommand->u.scanCmd.pToRoamProfile)
4307 {
4308 csrReleaseProfile(pMac, pCommand->u.scanCmd.pToRoamProfile);
Kiet Lam64c1b492013-07-12 13:56:44 +05304309 vos_mem_free(pCommand->u.scanCmd.pToRoamProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07004310 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304311 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004312}
4313
4314
4315tANI_BOOLEAN csrGetRemainingChannelsFor11dScan( tpAniSirGlobal pMac, tANI_U8 *pChannels, tANI_U8 *pcChannels )
4316{
4317 tANI_U32 index11dChannels, index;
4318 tANI_U32 indexCurrentChannels;
4319 tANI_BOOLEAN fChannelAlreadyScanned;
4320 tANI_U32 len = sizeof(pMac->roam.validChannelList);
4321
4322 *pcChannels = 0;
4323 if ( CSR_IS_11D_INFO_FOUND(pMac) && csrRoamIsChannelValid(pMac, pMac->scan.channelOf11dInfo) )
4324 {
4325 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
4326 {
4327 //Find the channel index where we found the 11d info
4328 for(index = 0; index < len; index++)
4329 {
4330 if(pMac->scan.channelOf11dInfo == pMac->roam.validChannelList[index])
4331 break;
4332 }
4333 //check whether we found the channel index
4334 if(index < len)
4335 {
4336 // Now, look through the 11d channel list and create a list of all channels in the 11d list that are
4337 // NOT in the current channel list. This gives us a list of the new channels that have not been
4338 // scanned. We'll scan this new list so we have a complete set of scan results on all of the domain channels
4339 // initially.
4340 for ( index11dChannels = 0; index11dChannels < pMac->scan.channels11d.numChannels; index11dChannels++ )
4341 {
4342 fChannelAlreadyScanned = eANI_BOOLEAN_FALSE;
4343
4344 for( indexCurrentChannels = 0; indexCurrentChannels < index; indexCurrentChannels++ )
4345 {
4346 if ( pMac->roam.validChannelList[ indexCurrentChannels ] == pMac->scan.channels11d.channelList[ index11dChannels ] )
4347 {
4348 fChannelAlreadyScanned = eANI_BOOLEAN_TRUE;
4349 break;
4350 }
4351 }
4352
4353 if ( !fChannelAlreadyScanned )
4354 {
4355 pChannels[ *pcChannels ] = pMac->scan.channels11d.channelList[ index11dChannels ];
4356 ( *pcChannels )++;
4357 }
4358 }
4359 }
4360 }//GetCFG
4361 }
4362 return( *pcChannels );
4363}
4364
4365
4366eCsrScanCompleteNextCommand csrScanGetNextCommandState( tpAniSirGlobal pMac, tSmeCmd *pCommand, tANI_BOOLEAN fSuccess )
4367{
4368 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
4369
4370 switch( pCommand->u.scanCmd.reason )
4371 {
4372 case eCsrScan11d1:
4373 NextCommand = (fSuccess) ? eCsrNext11dScan1Success : eCsrNext11dScan1Failure;
4374 break;
4375 case eCsrScan11d2:
4376 NextCommand = (fSuccess) ? eCsrNext11dScan2Success : eCsrNext11dScan2Failure;
4377 break;
4378 case eCsrScan11dDone:
4379 NextCommand = eCsrNext11dScanComplete;
4380 break;
4381 case eCsrScanLostLink1:
4382 NextCommand = (fSuccess) ? eCsrNextLostLinkScan1Success : eCsrNextLostLinkScan1Failed;
4383 break;
4384 case eCsrScanLostLink2:
4385 NextCommand = (fSuccess) ? eCsrNextLostLinkScan2Success : eCsrNextLostLinkScan2Failed;
4386 break;
4387 case eCsrScanLostLink3:
4388 NextCommand = (fSuccess) ? eCsrNextLostLinkScan3Success : eCsrNextLostLinkScan3Failed;
4389 break;
4390 case eCsrScanForSsid:
4391 NextCommand = (fSuccess) ? eCsrNexteScanForSsidSuccess : eCsrNexteScanForSsidFailure;
4392 break;
4393 case eCsrScanForCapsChange:
4394 NextCommand = eCsrNextCapChangeScanComplete; //don't care success or not
4395 break;
4396 case eCsrScanIdleScan:
4397 NextCommand = eCsrNextIdleScanComplete;
4398 break;
4399 default:
4400 NextCommand = eCsrNextScanNothing;
4401 break;
4402 }
4403 return( NextCommand );
4404}
4405
4406
4407//Return whether the pCommand is finished.
4408tANI_BOOLEAN csrHandleScan11d1Failure(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4409{
4410 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
4411
4412 //Apply back the default setting and passively scan one more time.
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004413 csrResetCountryInformation(pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07004414 pCommand->u.scanCmd.reason = eCsrScan11d2;
4415 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
4416 {
4417 fRet = eANI_BOOLEAN_FALSE;
4418 }
4419
4420 return (fRet);
4421}
4422
4423
4424tANI_BOOLEAN csrHandleScan11dSuccess(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4425{
4426 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
4427 tANI_U8 *pChannels;
4428 tANI_U8 cChannels;
4429
Kiet Lam64c1b492013-07-12 13:56:44 +05304430 pChannels = vos_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
4431 if ( NULL != pChannels )
Jeff Johnson295189b2012-06-20 16:38:30 -07004432 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304433 vos_mem_set(pChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004434 if ( csrGetRemainingChannelsFor11dScan( pMac, pChannels, &cChannels ) )
4435 {
4436 pCommand->u.scanCmd.reason = eCsrScan11dDone;
4437 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
4438 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304439 vos_mem_free(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -07004440 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004441 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304442 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(cChannels);
4443 if ( NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07004444 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304445 vos_mem_copy(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
4446 pChannels, cChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07004447 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = cChannels;
4448 pCommand->u.scanCmd.u.scanRequest.requestType = eCSR_SCAN_REQUEST_FULL_SCAN;
4449 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
4450 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
4451 {
4452 //Reuse the same command buffer
4453 fRet = eANI_BOOLEAN_FALSE;
4454 }
4455 }
4456 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304457 vos_mem_free(pChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07004458 }
4459
4460 return (fRet);
4461}
4462
4463//Return whether the command should be removed
4464tANI_BOOLEAN csrScanComplete( tpAniSirGlobal pMac, tSirSmeScanRsp *pScanRsp )
4465{
4466 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
4467 tListElem *pEntry;
4468 tSmeCmd *pCommand;
4469 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
4470 tANI_BOOLEAN fSuccess;
4471
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05304472 if (pMac->fScanOffload)
4473 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
4474 else
4475 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07004476
4477 if ( pEntry )
4478 {
4479 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
4480
4481 // If the head of the queue is Active and it is a SCAN command, remove
4482 // and put this on the Free queue.
4483 if ( eSmeCommandScan == pCommand->command )
4484 {
4485 tANI_U32 sessionId = pCommand->sessionId;
4486
4487 if(eSIR_SME_SUCCESS != pScanRsp->statusCode)
4488 {
4489 fSuccess = eANI_BOOLEAN_FALSE;
4490 }
4491 else
4492 {
4493 //pMac->scan.tempScanResults is not empty meaning the scan found something
4494 //This check only valid here because csrSaveScanresults is not yet called
4495 fSuccess = (!csrLLIsListEmpty(&pMac->scan.tempScanResults, LL_ACCESS_LOCK));
4496 }
Srinivas, Dasari187ca4e2014-02-07 12:40:09 +05304497 if (pCommand->u.scanCmd.abortScanDueToBandChange)
4498 {
4499 /*
4500 * Scan aborted due to band change
4501 * The scan results need to be flushed
4502 */
4503 if (pCommand->u.scanCmd.callback
4504 != pMac->scan.callback11dScanDone)
4505 {
4506 smsLog(pMac, LOG1, FL("Filtering the scan results as the "
4507 "results may belong to wrong band"));
4508 csrScanFilterResults(pMac);
4509 }
4510 else
4511 {
4512 smsLog(pMac, LOG1, FL("11d_scan_done will flush the scan"
4513 " results"));
4514 }
4515 pCommand->u.scanCmd.abortScanDueToBandChange
4516 = eANI_BOOLEAN_FALSE;
4517 }
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004518 csrSaveScanResults(pMac, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07004519
4520#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4521 {
4522 vos_log_scan_pkt_type *pScanLog = NULL;
4523 tScanResultHandle hScanResult;
4524 tCsrScanResultInfo *pScanResult;
4525 tDot11fBeaconIEs *pIes;
4526 int n = 0, c = 0;
4527
4528 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
4529 if(pScanLog)
4530 {
4531 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
4532 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
4533 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
4534 {
4535 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_RSP;
4536 }
4537 else
4538 {
4539 if( eSIR_PASSIVE_SCAN != pMac->scan.curScanType )
4540 {
4541 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_RSP;
4542 }
4543 else
4544 {
4545 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_RSP;
4546 }
4547 }
4548 if(eSIR_SME_SUCCESS == pScanRsp->statusCode)
4549 {
4550 if(HAL_STATUS_SUCCESS(csrScanGetResult(pMac, NULL, &hScanResult)))
4551 {
4552 while(((pScanResult = csrScanResultGetNext(pMac, hScanResult)) != NULL))
4553 {
4554 if( n < VOS_LOG_MAX_NUM_BSSID )
4555 {
4556 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pScanResult->BssDescriptor, &pIes)))
4557 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004558 smsLog(pMac, LOGE, FL(" fail to parse IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07004559 break;
4560 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304561 vos_mem_copy(pScanLog->bssid[n],
4562 pScanResult->BssDescriptor.bssId, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07004563 if(pIes && pIes->SSID.present && VOS_LOG_MAX_SSID_SIZE >= pIes->SSID.num_ssid)
4564 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304565 vos_mem_copy(pScanLog->ssid[n],
4566 pIes->SSID.ssid, pIes->SSID.num_ssid);
Jeff Johnson295189b2012-06-20 16:38:30 -07004567 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304568 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07004569 n++;
4570 }
4571 c++;
4572 }
4573 pScanLog->numSsid = (v_U8_t)n;
4574 pScanLog->totalSsid = (v_U8_t)c;
4575 csrScanResultPurge(pMac, hScanResult);
4576 }
4577 }
4578 else
4579 {
4580 pScanLog->status = WLAN_SCAN_STATUS_FAILURE;
4581 }
4582 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
4583 }
4584 }
4585#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4586
4587 NextCommand = csrScanGetNextCommandState(pMac, pCommand, fSuccess);
4588 //We reuse the command here instead reissue a new command
4589 switch(NextCommand)
4590 {
4591 case eCsrNext11dScan1Success:
4592 case eCsrNext11dScan2Success:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004593 smsLog( pMac, LOG2, FL("11dScan1/3 produced results. Reissue Active scan..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004594 // if we found country information, no need to continue scanning further, bail out
4595 fRemoveCommand = eANI_BOOLEAN_TRUE;
4596 NextCommand = eCsrNext11dScanComplete;
4597 break;
4598 case eCsrNext11dScan1Failure:
4599 //We are not done yet. 11d scan fail once. We will try to reset anything and do it over again
4600 //The only meaningful thing for this retry is that we cannot find 11d information after a reset so
4601 //we clear the "old" 11d info and give it once more chance
4602 fRemoveCommand = csrHandleScan11d1Failure(pMac, pCommand);
4603 if(fRemoveCommand)
4604 {
4605 NextCommand = eCsrNext11dScanComplete;
4606 }
4607 break;
4608 case eCsrNextLostLinkScan1Success:
4609 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink1)))
4610 {
4611 csrScanHandleFailedLostlink1(pMac, sessionId);
4612 }
4613 break;
4614 case eCsrNextLostLinkScan2Success:
4615 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink2)))
4616 {
4617 csrScanHandleFailedLostlink2(pMac, sessionId);
4618 }
4619 break;
4620 case eCsrNextLostLinkScan3Success:
4621 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink3)))
4622 {
4623 csrScanHandleFailedLostlink3(pMac, sessionId);
4624 }
4625 break;
4626 case eCsrNextLostLinkScan1Failed:
4627 csrScanHandleFailedLostlink1(pMac, sessionId);
4628 break;
4629 case eCsrNextLostLinkScan2Failed:
4630 csrScanHandleFailedLostlink2(pMac, sessionId);
4631 break;
4632 case eCsrNextLostLinkScan3Failed:
4633 csrScanHandleFailedLostlink3(pMac, sessionId);
4634 break;
4635 case eCsrNexteScanForSsidSuccess:
4636 csrScanHandleSearchForSSID(pMac, pCommand);
4637 break;
4638 case eCsrNexteScanForSsidFailure:
4639 csrScanHandleSearchForSSIDFailure(pMac, pCommand);
4640 break;
4641 case eCsrNextIdleScanComplete:
4642 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
4643 break;
4644 case eCsrNextCapChangeScanComplete:
4645 csrScanHandleCapChangeScanComplete(pMac, sessionId);
4646 break;
4647 default:
4648
4649 break;
4650 }
4651 }
4652 else
4653 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004654 smsLog( pMac, LOGW, FL("Scan Completion called but SCAN command is not ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004655 fRemoveCommand = eANI_BOOLEAN_FALSE;
4656 }
4657 }
4658 else
4659 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004660 smsLog( pMac, LOGW, FL("Scan Completion called but NO commands are ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004661 fRemoveCommand = eANI_BOOLEAN_FALSE;
4662 }
4663
4664 return( fRemoveCommand );
4665}
4666
4667
4668
4669static void csrScanRemoveDupBssDescriptionFromInterimList( tpAniSirGlobal pMac,
4670 tSirBssDescription *pSirBssDescr,
4671 tDot11fBeaconIEs *pIes)
4672{
4673 tListElem *pEntry;
4674 tCsrScanResult *pCsrBssDescription;
4675
4676 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
4677 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
4678 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
4679 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
4680 while( pEntry )
4681 {
4682 pCsrBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
4683
4684 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
4685 // matches
4686
4687 if ( csrIsDuplicateBssDescription( pMac, &pCsrBssDescription->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07004688 pSirBssDescr, pIes, FALSE ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07004689 {
4690 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
4691 ((tANI_S32)pCsrBssDescription->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
4692
4693 // Remove the 'old' entry from the list....
4694 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK ) )
4695 {
4696 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pCsrBssDescription->Result.BssDescriptor);
4697 // we need to free the memory associated with this node
4698 csrFreeScanResultEntry( pMac, pCsrBssDescription );
4699 }
4700
4701 // If we found a match, we can stop looking through the list.
4702 break;
4703 }
4704
4705 pEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK );
4706 }
4707}
4708
4709
4710
4711//Caller allocated memory pfNewBssForConn to return whether new candidate for
4712//current connection is found. Cannot be NULL
4713tCsrScanResult *csrScanSaveBssDescriptionToInterimList( tpAniSirGlobal pMac,
4714 tSirBssDescription *pBSSDescription,
4715 tDot11fBeaconIEs *pIes)
4716{
4717 tCsrScanResult *pCsrBssDescription = NULL;
4718 tANI_U32 cbBSSDesc;
4719 tANI_U32 cbAllocated;
Jeff Johnson295189b2012-06-20 16:38:30 -07004720
4721 // figure out how big the BSS description is (the BSSDesc->length does NOT
4722 // include the size of the length field itself).
4723 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
4724
4725 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
4726
Kiet Lam64c1b492013-07-12 13:56:44 +05304727 pCsrBssDescription = vos_mem_malloc(cbAllocated);
4728 if ( NULL != pCsrBssDescription )
Jeff Johnson295189b2012-06-20 16:38:30 -07004729 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304730 vos_mem_set(pCsrBssDescription, cbAllocated, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004731 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Kiet Lam64c1b492013-07-12 13:56:44 +05304732 vos_mem_copy(&pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc );
Jeff Johnson295189b2012-06-20 16:38:30 -07004733 //Save SSID separately for later use
4734 if( pIes->SSID.present && !csrIsNULLSSID(pIes->SSID.ssid, pIes->SSID.num_ssid) )
4735 {
4736 //SSID not hidden
Madan Mohan Koyyalamudi4e31b132012-11-02 13:13:52 -07004737 tANI_U32 len = pIes->SSID.num_ssid;
Jeff Johnson295189b2012-06-20 16:38:30 -07004738 if (len > SIR_MAC_MAX_SSID_LENGTH)
4739 {
4740 // truncate to fit in our struct
4741 len = SIR_MAC_MAX_SSID_LENGTH;
4742 }
4743 pCsrBssDescription->Result.ssId.length = len;
4744 pCsrBssDescription->Result.timer = vos_timer_get_system_time();
Kiet Lam64c1b492013-07-12 13:56:44 +05304745 vos_mem_copy(pCsrBssDescription->Result.ssId.ssId, pIes->SSID.ssid, len);
Jeff Johnson295189b2012-06-20 16:38:30 -07004746 }
4747 csrLLInsertTail( &pMac->scan.tempScanResults, &pCsrBssDescription->Link, LL_ACCESS_LOCK );
4748 }
4749
4750 return( pCsrBssDescription );
4751}
4752
4753
4754
4755
4756tANI_BOOLEAN csrIsDuplicateBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc1,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07004757 tSirBssDescription *pSirBssDesc2, tDot11fBeaconIEs *pIes2, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07004758{
4759 tANI_BOOLEAN fMatch = FALSE;
4760 tSirMacCapabilityInfo *pCap1, *pCap2;
4761 tDot11fBeaconIEs *pIes1 = NULL;
Jeff Johnsone7245742012-09-05 17:12:55 -07004762 tDot11fBeaconIEs *pIesTemp = pIes2;
Jeff Johnson295189b2012-06-20 16:38:30 -07004763
4764 pCap1 = (tSirMacCapabilityInfo *)&pSirBssDesc1->capabilityInfo;
4765 pCap2 = (tSirMacCapabilityInfo *)&pSirBssDesc2->capabilityInfo;
4766 if(pCap1->ess == pCap2->ess)
4767 {
4768 if (pCap1->ess &&
Jeff Johnsone7245742012-09-05 17:12:55 -07004769 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId)&&
Abhishek Singhe3fa11f2014-05-13 11:11:10 +05304770 (fForced || (vos_chan_to_band(pSirBssDesc1->channelId) == vos_chan_to_band((pSirBssDesc2->channelId)))))
Jeff Johnson295189b2012-06-20 16:38:30 -07004771 {
4772 fMatch = TRUE;
Jeff Johnsone7245742012-09-05 17:12:55 -07004773 // Check for SSID match, if exists
4774 do
4775 {
4776 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
4777 {
4778 break;
4779 }
4780 if( NULL == pIesTemp )
4781 {
4782 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
4783 {
4784 break;
4785 }
4786 }
4787 if(pIes1->SSID.present && pIesTemp->SSID.present)
4788 {
4789 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
4790 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
4791 }
4792 }while(0);
4793
Jeff Johnson295189b2012-06-20 16:38:30 -07004794 }
4795 else if (pCap1->ibss && (pSirBssDesc1->channelId == pSirBssDesc2->channelId))
4796 {
Jeff Johnson295189b2012-06-20 16:38:30 -07004797
4798 do
4799 {
4800 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
4801 {
4802 break;
4803 }
4804 if( NULL == pIesTemp )
4805 {
4806 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
4807 {
4808 break;
4809 }
4810 }
4811 //Same channel cannot have same SSID for different IBSS
4812 if(pIes1->SSID.present && pIesTemp->SSID.present)
4813 {
4814 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
4815 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
4816 }
4817 }while(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004818 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004819 /* In case of P2P devices, ess and ibss will be set to zero */
4820 else if (!pCap1->ess &&
4821 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId))
4822 {
4823 fMatch = TRUE;
4824 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004825 }
4826
4827 if(pIes1)
4828 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304829 vos_mem_free(pIes1);
Jeff Johnson295189b2012-06-20 16:38:30 -07004830 }
Jeff Johnsone7245742012-09-05 17:12:55 -07004831
4832 if( (NULL == pIes2) && pIesTemp )
4833 {
4834 //locally allocated
Kiet Lam64c1b492013-07-12 13:56:44 +05304835 vos_mem_free(pIesTemp);
Jeff Johnsone7245742012-09-05 17:12:55 -07004836 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004837
4838 return( fMatch );
4839}
4840
4841
4842tANI_BOOLEAN csrIsNetworkTypeEqual( tSirBssDescription *pSirBssDesc1, tSirBssDescription *pSirBssDesc2 )
4843{
4844 return( pSirBssDesc1->nwType == pSirBssDesc2->nwType );
4845}
4846
4847
4848//to check whether the BSS matches the dot11Mode
4849static tANI_BOOLEAN csrScanIsBssAllowed(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
4850 tDot11fBeaconIEs *pIes)
4851{
4852 tANI_BOOLEAN fAllowed = eANI_BOOLEAN_FALSE;
4853 eCsrPhyMode phyMode;
4854
4855 if(HAL_STATUS_SUCCESS(csrGetPhyModeFromBss(pMac, pBssDesc, &phyMode, pIes)))
4856 {
4857 switch(pMac->roam.configParam.phyMode)
4858 {
4859 case eCSR_DOT11_MODE_11b:
4860 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
4861 break;
4862 case eCSR_DOT11_MODE_11g:
4863 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
4864 break;
4865 case eCSR_DOT11_MODE_11g_ONLY:
4866 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11g == phyMode);
4867 break;
4868 case eCSR_DOT11_MODE_11a:
4869 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11b != phyMode) && (eCSR_DOT11_MODE_11g != phyMode));
4870 break;
4871 case eCSR_DOT11_MODE_11n_ONLY:
4872 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11n == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
4873 break;
Jeff Johnsone7245742012-09-05 17:12:55 -07004874
4875#ifdef WLAN_FEATURE_11AC
4876 case eCSR_DOT11_MODE_11ac_ONLY:
4877 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11ac == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
4878 break;
4879#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004880 case eCSR_DOT11_MODE_11b_ONLY:
4881 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11b == phyMode);
4882 break;
4883 case eCSR_DOT11_MODE_11a_ONLY:
4884 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a == phyMode);
4885 break;
4886 case eCSR_DOT11_MODE_11n:
Jeff Johnsone7245742012-09-05 17:12:55 -07004887#ifdef WLAN_FEATURE_11AC
4888 case eCSR_DOT11_MODE_11ac:
4889#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004890 case eCSR_DOT11_MODE_TAURUS:
4891 default:
4892 fAllowed = eANI_BOOLEAN_TRUE;
4893 break;
4894 }
4895 }
4896
4897 return (fAllowed);
4898}
4899
4900
4901
4902//Return pIes to caller for future use when returning TRUE.
4903static tANI_BOOLEAN csrScanValidateScanResult( tpAniSirGlobal pMac, tANI_U8 *pChannels,
4904 tANI_U8 numChn, tSirBssDescription *pBssDesc,
4905 tDot11fBeaconIEs **ppIes )
4906{
4907 tANI_BOOLEAN fValidChannel = FALSE;
4908 tDot11fBeaconIEs *pIes = NULL;
4909 tANI_U8 index;
4910
4911 for( index = 0; index < numChn; index++ )
4912 {
4913 // This check relies on the fact that a single BSS description is returned in each
4914 // ScanRsp call, which is the way LIM implemented the scan req/rsp funtions. We changed
4915 // to this model when we ran with a large number of APs. If this were to change, then
4916 // this check would have to mess with removing the bssDescription from somewhere in an
4917 // arbitrary index in the bssDescription array.
4918 if ( pChannels[ index ] == pBssDesc->channelId )
4919 {
4920 fValidChannel = TRUE;
4921 break;
4922 }
4923 }
4924 *ppIes = NULL;
4925 if(fValidChannel)
4926 {
4927 if( HAL_STATUS_SUCCESS( csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIes) ) )
4928 {
4929 fValidChannel = csrScanIsBssAllowed(pMac, pBssDesc, pIes);
4930 if( fValidChannel )
4931 {
4932 *ppIes = pIes;
4933 }
4934 else
4935 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304936 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07004937 }
4938 }
4939 else
4940 {
4941 fValidChannel = FALSE;
4942 }
4943 }
4944
4945 return( fValidChannel );
4946}
4947
4948
4949//Return whether last scan result is received
4950static tANI_BOOLEAN csrScanProcessScanResults( tpAniSirGlobal pMac, tSmeCmd *pCommand,
4951 tSirSmeScanRsp *pScanRsp, tANI_BOOLEAN *pfRemoveCommand )
4952{
4953 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE, fRemoveCommand = eANI_BOOLEAN_FALSE;
4954 tDot11fBeaconIEs *pIes = NULL;
4955 tANI_U32 cbParsed;
4956 tSirBssDescription *pSirBssDescription;
4957 tANI_U32 cbBssDesc;
4958 tANI_U32 cbScanResult = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription )
4959 + sizeof(tSirBssDescription); //We need at least one CB
4960
4961 // don't consider the scan rsp to be valid if the status code is Scan Failure. Scan Failure
4962 // is returned when the scan could not find anything. so if we get scan failure return that
4963 // the scan response is invalid. Also check the lenght in the scan result for valid scan
4964 // BssDescriptions....
4965 do
4966 {
4967 if ( ( cbScanResult <= pScanRsp->length ) &&
4968 (( eSIR_SME_SUCCESS == pScanRsp->statusCode ) ||
4969 ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW == pScanRsp->statusCode ) ) )
4970 {
4971 tANI_U8 *pChannelList = NULL;
4972 tANI_U8 cChannels = 0;
4973
4974 //Different scan type can reach this point, we need to distinguish it
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004975#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
4976 if( eCsrScanGetLfrResult == pCommand->u.scanCmd.reason )
4977 {
4978 pChannelList = NULL;
4979 cChannels = 0;
4980 }
4981 else
4982#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004983 if( eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason )
4984 {
4985 //eCsrScanSetBGScanParam uses different structure
4986 tCsrBGScanRequest *pBgScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
4987
4988 cChannels = pBgScanReq->ChannelInfo.numOfChannels;
4989 pChannelList = pBgScanReq->ChannelInfo.ChannelList;
4990 }
4991 else
4992 {
4993 //the rest use generic scan request
4994 cChannels = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
4995 pChannelList = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
4996 }
4997
4998 // if the scan result is not on one of the channels in the Valid channel list, then it
4999 // must have come from an AP on an overlapping channel (in the 2.4GHz band). In this case,
5000 // let's drop the scan result.
5001 //
5002 // The other situation is where the scan request is for a scan on a particular channel set
5003 // and the scan result is from a
5004
5005 // if the NumChannels is 0, then we are supposed to be scanning all channels. Use the full channel
5006 // list as the 'valid' channel list. Otherwise, use the specific channel list in the scan parms
5007 // as the valid channels.
5008 if ( 0 == cChannels )
5009 {
5010 tANI_U32 len = sizeof(pMac->roam.validChannelList);
5011
5012 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
5013 {
5014 pChannelList = pMac->roam.validChannelList;
5015 cChannels = (tANI_U8)len;
5016 }
5017 else
5018 {
5019 //Cannot continue
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005020 smsLog( pMac, LOGE, "CSR: Processing internal SCAN results...csrGetCfgValidChannels failed" );
Jeff Johnson295189b2012-06-20 16:38:30 -07005021 break;
5022 }
5023 }
5024
5025 smsLog( pMac, LOG2, "CSR: Processing internal SCAN results..." );
5026 cbParsed = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription );
5027 pSirBssDescription = pScanRsp->bssDescription;
5028 while( cbParsed < pScanRsp->length )
5029 {
5030 if ( csrScanValidateScanResult( pMac, pChannelList, cChannels, pSirBssDescription, &pIes ) )
5031 {
5032 csrScanRemoveDupBssDescriptionFromInterimList(pMac, pSirBssDescription, pIes);
5033 csrScanSaveBssDescriptionToInterimList( pMac, pSirBssDescription, pIes );
5034 if( eSIR_PASSIVE_SCAN == pMac->scan.curScanType )
5035 {
5036 if( csrIs11dSupported( pMac) )
5037 {
5038 //Check whether the BSS is acceptable base on 11d info and our configs.
5039 if( csrMatchCountryCode( pMac, NULL, pIes ) )
5040 {
5041 //Double check whether the channel is acceptable by us.
5042 if( csrIsSupportedChannel( pMac, pSirBssDescription->channelId ) )
5043 {
5044 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
5045 }
5046 }
5047 }
5048 else
5049 {
5050 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
5051 }
5052 }
5053 //Free the resource
Kiet Lam64c1b492013-07-12 13:56:44 +05305054 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07005055 }
5056 // skip over the BSS description to the next one...
5057 cbBssDesc = pSirBssDescription->length + sizeof( pSirBssDescription->length );
5058
5059 cbParsed += cbBssDesc;
5060 pSirBssDescription = (tSirBssDescription *)((tANI_U8 *)pSirBssDescription + cbBssDesc );
5061
5062 } //while
5063 }
5064 else
5065 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005066 smsLog( pMac, LOGW, " Scanrsp fail (0x%08X), length = %d (expected %d)",
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08005067 pScanRsp->statusCode, pScanRsp->length, cbScanResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07005068 //HO bg scan/probe failed no need to try autonomously
5069 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
5070 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005071#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5072 eCsrScanGetLfrResult == pCommand->u.scanCmd.reason ||
5073#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005074 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
5075 {
5076 fRemoveCommand = eANI_BOOLEAN_TRUE;
5077 }
5078 }
5079 }while(0);
5080 if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
5081 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005082 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 -07005083 fRemoveCommand = csrScanComplete( pMac, pScanRsp );
5084 fRet = eANI_BOOLEAN_TRUE;
5085 }//if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
5086 if(pfRemoveCommand)
5087 {
5088 *pfRemoveCommand = fRemoveCommand;
5089 }
5090
5091#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305092 if (pMac->fScanOffload)
5093 return fRet;
5094
Jeff Johnson295189b2012-06-20 16:38:30 -07005095 if (!csrLLIsListEmpty( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK ))
5096 {
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005097 /* Pending scan commands in the list because the previous scan command
5098 * was split into a scan command on one channel + a scan command for all
5099 * remaining channels.
5100 *
5101 * Start timer to trigger processing of the next scan command.
Srikant Kuppa866893f2012-12-27 17:28:14 -08005102 * NOTE for LFR:
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305103 * Do not split scans if no concurrent infra connections are
Srikant Kuppa866893f2012-12-27 17:28:14 -08005104 * active and if the scan is a BG scan triggered by LFR (OR)
5105 * any scan if LFR is in the middle of a BG scan. Splitting
5106 * the scan is delaying the time it takes for LFR to find
5107 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005108 */
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305109 if ( (csrIsStaSessionConnected(pMac) &&
Srikant Kuppa866893f2012-12-27 17:28:14 -08005110#ifdef FEATURE_WLAN_LFR
5111 (csrIsConcurrentInfraConnected(pMac) ||
5112 ((pCommand->u.scanCmd.reason != eCsrScanBgScan) &&
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305113 (pMac->roam.neighborRoamInfo.neighborRoamState !=
Srikant Kuppa866893f2012-12-27 17:28:14 -08005114 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
5115#endif
5116 (pCommand->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305117 (csrIsP2pSessionConnected(pMac)) )
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005118 {
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005119 /* if active connected sessions present then continue to split scan
5120 * with specified interval between consecutive scans */
5121 csrSetDefaultScanTiming(pMac, pCommand->u.scanCmd.u.scanRequest.scanType, &(pCommand->u.scanCmd.u.scanRequest));
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05305122 vos_timer_start(&pMac->scan.hTimerStaApConcTimer,
5123 pCommand->u.scanCmd.u.scanRequest.restTime);
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005124 } else {
5125 /* if no connected sessions present then initiate next scan command immediately */
5126 /* minimum timer granularity is 10ms */
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05305127 vos_timer_start(&pMac->scan.hTimerStaApConcTimer, 10);
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005128 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005129 }
5130#endif
5131 return (fRet);
5132}
5133
5134
5135tANI_BOOLEAN csrScanIsWildCardScan( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5136{
5137 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
Kiet Lam64c1b492013-07-12 13:56:44 +05305138 tANI_BOOLEAN f = vos_mem_compare(pCommand->u.scanCmd.u.scanRequest.bssid,
5139 bssid, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07005140
5141 //It is not a wild card scan if the bssid is not broadcast and the number of SSID is 1.
5142 return ((tANI_BOOLEAN)( (f || (0xff == pCommand->u.scanCmd.u.scanRequest.bssid[0])) &&
5143 (pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs != 1) ));
5144}
5145
5146
5147eHalStatus csrScanSmeScanResponse( tpAniSirGlobal pMac, void *pMsgBuf )
5148{
5149 eHalStatus status = eHAL_STATUS_SUCCESS;
5150 tListElem *pEntry;
5151 tSmeCmd *pCommand;
5152 eCsrScanStatus scanStatus;
5153 tSirSmeScanRsp *pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
5154 tSmeGetScanChnRsp *pScanChnInfo;
5155 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
5156 eCsrScanReason reason = eCsrScanOther;
5157
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305158 if (pMac->fScanOffload)
5159 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList,
5160 LL_ACCESS_LOCK);
5161 else
5162 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07005163
5164 if ( pEntry )
5165 {
5166 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
5167 if ( eSmeCommandScan == pCommand->command )
5168 {
5169 scanStatus = (eSIR_SME_SUCCESS == pScanRsp->statusCode) ? eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
5170 reason = pCommand->u.scanCmd.reason;
5171 switch(pCommand->u.scanCmd.reason)
5172 {
5173 case eCsrScanAbortBgScan:
5174 case eCsrScanAbortNormalScan:
5175 case eCsrScanBGScanAbort:
5176 case eCsrScanBGScanEnable:
5177 break;
5178 case eCsrScanGetScanChnInfo:
5179 pScanChnInfo = (tSmeGetScanChnRsp *)pMsgBuf;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005180 /*
5181 * status code not available in tSmeGetScanChnRsp, so
5182 * by default considereing it to be success
5183 */
5184 scanStatus = eSIR_SME_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07005185 csrScanAgeResults(pMac, pScanChnInfo);
5186 break;
5187 case eCsrScanForCapsChange:
5188 csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand );
5189 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005190 case eCsrScanP2PFindPeer:
5191 scanStatus = ((eSIR_SME_SUCCESS == pScanRsp->statusCode) && (pScanRsp->length > 50)) ? eCSR_SCAN_FOUND_PEER : eCSR_SCAN_FAILURE;
5192 csrScanProcessScanResults( pMac, pCommand, pScanRsp, NULL );
5193 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005194 case eCsrScanSetBGScanParam:
5195 default:
5196 if(csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand ))
5197 {
5198 //Not to get channel info if the scan is not a wildcard scan because
5199 //it may cause scan results got aged out incorrectly.
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005200 if( csrScanIsWildCardScan( pMac, pCommand ) && (!pCommand->u.scanCmd.u.scanRequest.p2pSearch)
5201#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5202 && (pCommand->u.scanCmd.reason != eCsrScanGetLfrResult)
5203#endif
5204 )
Jeff Johnson295189b2012-06-20 16:38:30 -07005205 {
5206 //Get the list of channels scanned
Jeff Johnson32d95a32012-09-10 13:15:23 -07005207 if( pCommand->u.scanCmd.reason != eCsrScanUserRequest)
5208 {
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05305209 csrScanGetScanChnInfo(pMac, pCommand->sessionId,
5210 NULL, NULL);
Jeff Johnson32d95a32012-09-10 13:15:23 -07005211 }
5212 else
5213 {
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05305214 csrScanGetScanChnInfo(pMac,
5215 pCommand->sessionId,
5216 pCommand->u.scanCmd.pContext,
5217 pCommand->u.scanCmd.callback);
Jeff Johnson32d95a32012-09-10 13:15:23 -07005218 pCommand->u.scanCmd.callback = NULL;
5219 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005220 }
5221 }
5222 break;
5223 }//switch
5224 if(fRemoveCommand)
5225 {
5226
5227 csrReleaseScanCommand(pMac, pCommand, scanStatus);
5228
Srikant Kuppa866893f2012-12-27 17:28:14 -08005229 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005230 smeProcessPendingQueue( pMac );
5231 }
5232 else
5233 {
5234 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
5235 status = eHAL_STATUS_FAILURE;
5236 }
5237 }
5238 else
5239 {
5240 smsLog( pMac, LOGW, "CSR: Scan Completion called but NO commands are ACTIVE ..." );
5241 status = eHAL_STATUS_FAILURE;
5242 }
5243
5244 return (status);
5245}
5246
5247
5248
5249
5250tCsrScanResultInfo *csrScanResultGetFirst(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
5251{
5252 tListElem *pEntry;
5253 tCsrScanResult *pResult;
5254 tCsrScanResultInfo *pRet = NULL;
5255 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5256
5257 if(pResultList)
5258 {
5259 csrLLLock(&pResultList->List);
5260 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5261 if(pEntry)
5262 {
5263 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
5264 pRet = &pResult->Result;
5265 }
5266 pResultList->pCurEntry = pEntry;
5267 csrLLUnlock(&pResultList->List);
5268 }
5269
5270 return pRet;
5271}
5272
5273
5274tCsrScanResultInfo *csrScanResultGetNext(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
5275{
5276 tListElem *pEntry = NULL;
5277 tCsrScanResult *pResult = NULL;
5278 tCsrScanResultInfo *pRet = NULL;
5279 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5280
5281 if(pResultList)
5282 {
5283 csrLLLock(&pResultList->List);
5284 if(NULL == pResultList->pCurEntry)
5285 {
5286 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5287 }
5288 else
5289 {
5290 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
5291 }
5292 if(pEntry)
5293 {
5294 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
5295 pRet = &pResult->Result;
5296 }
5297 pResultList->pCurEntry = pEntry;
5298 csrLLUnlock(&pResultList->List);
5299 }
5300
5301 return pRet;
5302}
5303
5304
5305//This function moves the first BSS that matches the bssid to the head of the result
5306eHalStatus csrMoveBssToHeadFromBSSID(tpAniSirGlobal pMac, tCsrBssid *bssid, tScanResultHandle hScanResult)
5307{
5308 eHalStatus status = eHAL_STATUS_FAILURE;
5309 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5310 tCsrScanResult *pResult = NULL;
5311 tListElem *pEntry = NULL;
5312
5313 if(pResultList && bssid)
5314 {
5315 csrLLLock(&pResultList->List);
5316 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5317 while(pEntry)
5318 {
5319 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
Kiet Lam64c1b492013-07-12 13:56:44 +05305320 if (vos_mem_compare(bssid, pResult->Result.BssDescriptor.bssId, sizeof(tCsrBssid)))
Jeff Johnson295189b2012-06-20 16:38:30 -07005321 {
5322 status = eHAL_STATUS_SUCCESS;
5323 csrLLRemoveEntry(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
5324 csrLLInsertHead(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
5325 break;
5326 }
5327 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
5328 }
5329 csrLLUnlock(&pResultList->List);
5330 }
5331
5332 return (status);
5333}
5334
5335
5336//Remove the BSS if possible.
5337//Return -- TRUE == the BSS is remove. False == Fail to remove it
5338//This function is called when list lock is held. Be caution what functions it can call.
5339tANI_BOOLEAN csrScanAgeOutBss(tpAniSirGlobal pMac, tCsrScanResult *pResult)
5340{
5341 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
5342 tANI_U32 i;
5343 tCsrRoamSession *pSession;
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305344 tANI_BOOLEAN isConnBssfound = eANI_BOOLEAN_FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005345
5346 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5347 {
5348 if( CSR_IS_SESSION_VALID( pMac, i ) )
5349 {
5350 pSession = CSR_GET_SESSION( pMac, i );
5351 //Not to remove the BSS we are connected to.
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305352 if(csrIsConnStateConnectedInfra(pMac, i) && (NULL != pSession->pConnectBssDesc) &&
5353 (csrIsDuplicateBssDescription(pMac, &pResult->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07005354 pSession->pConnectBssDesc, NULL, FALSE))
Jeff Johnson295189b2012-06-20 16:38:30 -07005355 )
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305356 {
5357 isConnBssfound = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005358 break;
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305359 }
5360 }
5361 }
5362
5363 if( isConnBssfound )
Jeff Johnson295189b2012-06-20 16:38:30 -07005364 {
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305365 //Reset the counter so that aging out of connected BSS won't hapeen too soon
Jeff Johnson295189b2012-06-20 16:38:30 -07005366 pResult->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
5367 pResult->Result.BssDescriptor.nReceivedTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
Padma, Santhosh Kumar748b9782014-07-02 12:24:23 +05305368
5369 return (fRet);
5370 }
5371 else
5372 {
5373 smsLog(pMac, LOGW, "Aging out BSS "MAC_ADDRESS_STR" Channel %d",
5374 MAC_ADDR_ARRAY(pResult->Result.BssDescriptor.bssId),
5375 pResult->Result.BssDescriptor.channelId);
5376 //No need to hold the spin lock because caller should hold the lock for pMac->scan.scanResultList
5377 if( csrLLRemoveEntry(&pMac->scan.scanResultList, &pResult->Link, LL_ACCESS_NOLOCK) )
5378 {
5379 if (csrIsMacAddressEqual(pMac,
5380 (tCsrBssid *) pResult->Result.BssDescriptor.bssId,
5381 (tCsrBssid *) pMac->scan.currentCountryBssid))
5382 {
5383 smsLog(pMac, LOGW, "Aging out 11d BSS "MAC_ADDRESS_STR,
5384 MAC_ADDR_ARRAY(pResult->Result.BssDescriptor.bssId));
5385 pMac->scan.currentCountryRSSI = -128;
5386 }
5387 csrFreeScanResultEntry(pMac, pResult);
5388 fRet = eANI_BOOLEAN_TRUE;
5389 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005390 }
5391
5392 return (fRet);
5393}
5394
5395
5396eHalStatus csrScanAgeResults(tpAniSirGlobal pMac, tSmeGetScanChnRsp *pScanChnInfo)
5397{
5398 eHalStatus status = eHAL_STATUS_SUCCESS;
5399 tListElem *pEntry, *tmpEntry;
5400 tCsrScanResult *pResult;
5401 tLimScanChn *pChnInfo;
5402 tANI_U8 i;
5403
5404 csrLLLock(&pMac->scan.scanResultList);
5405 for(i = 0; i < pScanChnInfo->numChn; i++)
5406 {
5407 pChnInfo = &pScanChnInfo->scanChn[i];
5408 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
5409 while( pEntry )
5410 {
5411 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
5412 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
5413 if(pResult->Result.BssDescriptor.channelId == pChnInfo->channelId)
5414 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005415 if(pResult->AgingCount <= 0)
5416 {
5417 smsLog(pMac, LOGW, " age out due to ref count");
5418 csrScanAgeOutBss(pMac, pResult);
5419 }
Madan Mohan Koyyalamudib9d3dcc2012-09-28 16:47:50 -07005420 else
5421 {
5422 pResult->AgingCount--;
5423 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005424 }
5425 pEntry = tmpEntry;
5426 }
5427 }
5428 csrLLUnlock(&pMac->scan.scanResultList);
5429
5430 return (status);
5431}
5432
5433
5434eHalStatus csrSendMBScanReq( tpAniSirGlobal pMac, tANI_U16 sessionId,
5435 tCsrScanRequest *pScanReq, tScanReqParam *pScanReqParam )
5436{
5437 eHalStatus status = eHAL_STATUS_SUCCESS;
5438 tSirSmeScanReq *pMsg;
5439 tANI_U16 msgLen;
5440 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
5441 tSirScanType scanType = pScanReq->scanType;
5442 tANI_U32 minChnTime; //in units of milliseconds
5443 tANI_U32 maxChnTime; //in units of milliseconds
5444 tANI_U32 i;
5445 tANI_U8 selfMacAddr[WNI_CFG_BSSID_LEN];
5446 tANI_U8 *pSelfMac = NULL;
5447
5448 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
5449 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) +
5450 ( pScanReq->uIEFieldLen ) ;
5451
Kiet Lam64c1b492013-07-12 13:56:44 +05305452 pMsg = vos_mem_malloc(msgLen);
5453 if ( NULL == pMsg )
5454 status = eHAL_STATUS_FAILURE;
5455 else
5456 status = eHAL_STATUS_SUCCESS;
5457 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07005458 {
5459 do
5460 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305461 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005462 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
5463 pMsg->length = pal_cpu_to_be16(msgLen);
5464 //ToDO: Fill in session info when we need to do scan base on session.
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05305465 if ((pMac->fScanOffload) && (sessionId != CSR_SESSION_ID_INVALID))
5466 {
5467 pMsg->sessionId = sessionId;
5468 }
5469 else
5470 {
5471 /* if sessionId == CSR_SESSION_ID_INVALID, then send the scan
5472 request on first available session */
5473 pMsg->sessionId = 0;
5474 }
5475
Jeff Johnson295189b2012-06-20 16:38:30 -07005476 pMsg->transactionId = 0;
5477 pMsg->dot11mode = (tANI_U8) csrTranslateToWNICfgDot11Mode(pMac, csrFindBestPhyMode( pMac, pMac->roam.configParam.phyMode ));
5478 pMsg->bssType = pal_cpu_to_be32(csrTranslateBsstypeToMacType(pScanReq->BSSType));
5479
5480 if ( CSR_IS_SESSION_VALID( pMac, sessionId ) )
5481 {
5482 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[sessionId].selfMacAddr;
5483 }
5484 else
5485 {
5486 // Since we don't have session for the scanning, we find a valid session. In case we fail to
5487 // do so, get the WNI_CFG_STA_ID
5488 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5489 {
5490 if( CSR_IS_SESSION_VALID( pMac, i ) )
5491 {
5492 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[i].selfMacAddr;
5493 break;
5494 }
5495 }
5496 if( CSR_ROAM_SESSION_MAX == i )
5497 {
5498 tANI_U32 len = WNI_CFG_BSSID_LEN;
5499 pSelfMac = selfMacAddr;
5500 status = ccmCfgGetStr( pMac, WNI_CFG_STA_ID, pSelfMac, &len );
5501 if( !HAL_STATUS_SUCCESS( status ) ||
5502 ( len < WNI_CFG_BSSID_LEN ) )
5503 {
5504 smsLog( pMac, LOGE, FL(" Can not get self MAC address from CFG status = %d"), status );
5505 //Force failed status
5506 status = eHAL_STATUS_FAILURE;
5507 break;
5508 }
5509 }
5510 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305511 vos_mem_copy((tANI_U8 *)pMsg->selfMacAddr, pSelfMac, sizeof(tSirMacAddr));
Jeff Johnson295189b2012-06-20 16:38:30 -07005512
5513 //sirCopyMacAddr
Kiet Lam64c1b492013-07-12 13:56:44 +05305514 vos_mem_copy((tANI_U8 *)pMsg->bssId, (tANI_U8 *)&pScanReq->bssid, sizeof(tSirMacAddr));
5515 if ( vos_mem_compare(pScanReq->bssid, bssid, sizeof(tCsrBssid)))
Jeff Johnson295189b2012-06-20 16:38:30 -07005516 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305517 vos_mem_set(pMsg->bssId, sizeof(tSirMacAddr), 0xff);
Jeff Johnson295189b2012-06-20 16:38:30 -07005518 }
5519 else
5520 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305521 vos_mem_copy(pMsg->bssId, pScanReq->bssid, WNI_CFG_BSSID_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07005522 }
5523 minChnTime = pScanReq->minChnTime;
5524 maxChnTime = pScanReq->maxChnTime;
5525
5526 //Verify the scan type first, if the scan is active scan, we need to make sure we
5527 //are allowed to do so.
5528 /* if 11d is enabled & we don't see any beacon around, scan type falls
5529 back to passive. But in BT AMP STA mode we need to send out a
5530 directed probe*/
5531 if( (eSIR_PASSIVE_SCAN != scanType) && (eCSR_SCAN_P2P_DISCOVERY != pScanReq->requestType)
5532 && (eCSR_BSS_TYPE_WDS_STA != pScanReq->BSSType)
5533 && (eANI_BOOLEAN_FALSE == pMac->scan.fEnableBypass11d))
5534 {
5535 scanType = pMac->scan.curScanType;
5536 if(eSIR_PASSIVE_SCAN == pMac->scan.curScanType)
5537 {
5538 if(minChnTime < pMac->roam.configParam.nPassiveMinChnTime)
5539 {
5540 minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
5541 }
5542 if(maxChnTime < pMac->roam.configParam.nPassiveMaxChnTime)
5543 {
5544 maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
5545 }
5546 }
5547 }
5548 pMsg->scanType = pal_cpu_to_be32(scanType);
5549
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05305550 pMsg->numSsid =
5551 (pScanReq->SSIDs.numOfSSIDs < SIR_SCAN_MAX_NUM_SSID) ?
5552 pScanReq->SSIDs.numOfSSIDs : SIR_SCAN_MAX_NUM_SSID;
Jeff Johnson295189b2012-06-20 16:38:30 -07005553 if((pScanReq->SSIDs.numOfSSIDs != 0) && ( eSIR_PASSIVE_SCAN != scanType ))
5554 {
Jeff Johnson40b59aa2013-03-19 14:43:18 -07005555 for (i = 0; i < pMsg->numSsid; i++)
5556 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305557 vos_mem_copy(&pMsg->ssId[i],
5558 &pScanReq->SSIDs.SSIDList[i].SSID, sizeof(tSirMacSSid));
Jeff Johnson40b59aa2013-03-19 14:43:18 -07005559 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005560 }
5561 else
5562 {
5563 //Otherwise we scan all SSID and let the result filter later
Jeff Johnson40b59aa2013-03-19 14:43:18 -07005564 for (i = 0; i < SIR_SCAN_MAX_NUM_SSID; i++)
5565 {
5566 pMsg->ssId[i].length = 0;
5567 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005568 }
5569
Jeff Johnson295189b2012-06-20 16:38:30 -07005570 pMsg->minChannelTime = pal_cpu_to_be32(minChnTime);
5571 pMsg->maxChannelTime = pal_cpu_to_be32(maxChnTime);
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08005572 pMsg->minChannelTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
5573 pMsg->maxChannelTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07005574 //hidden SSID option
5575 pMsg->hiddenSsid = pScanReqParam->hiddenSsid;
5576 //rest time
5577 //pMsg->restTime = pScanReq->restTime;
5578 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
5579 // All the scan results caching will be done by Roaming
5580 // We do not want LIM to do any caching of scan results,
5581 // so delete the LIM cache on all scan requests
5582 pMsg->returnFreshResults = pScanReqParam->freshScan;
5583 //Always ask for unique result
5584 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
5585 pMsg->channelList.numChannels = (tANI_U8)pScanReq->ChannelInfo.numOfChannels;
5586 if(pScanReq->ChannelInfo.numOfChannels)
5587 {
5588 //Assuming the channelNumber is tANI_U8 (1 byte)
Kiet Lam64c1b492013-07-12 13:56:44 +05305589 vos_mem_copy(pMsg->channelList.channelNumber,
5590 pScanReq->ChannelInfo.ChannelList,
5591 pScanReq->ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07005592 }
5593
5594 pMsg->uIEFieldLen = (tANI_U16) pScanReq->uIEFieldLen;
5595 pMsg->uIEFieldOffset = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
5596 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) ;
5597 if(pScanReq->uIEFieldLen != 0)
5598 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305599 vos_mem_copy((tANI_U8 *)pMsg+pMsg->uIEFieldOffset, pScanReq->pIEField,
5600 pScanReq->uIEFieldLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07005601 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005602 pMsg->p2pSearch = pScanReq->p2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07005603
Madan Mohan Koyyalamudi9b876782012-10-11 16:22:51 -07005604 if (pScanReq->requestType == eCSR_SCAN_HO_BG_SCAN)
5605 {
5606 pMsg->backgroundScanMode = eSIR_ROAMING_SCAN;
5607 }
5608
Jeff Johnson295189b2012-06-20 16:38:30 -07005609 }while(0);
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05305610 smsLog(pMac, LOG1, FL("domainIdCurrent %s (%d) scanType %s (%d)"
5611 "bssType %s (%d), requestType %s(%d)"
5612 "numChannels %d"),
5613 voss_DomainIdtoString(pMac->scan.domainIdCurrent),
5614 pMac->scan.domainIdCurrent,
5615 lim_ScanTypetoString(pMsg->scanType), pMsg->scanType,
5616 lim_BssTypetoString(pMsg->bssType), pMsg->bssType,
5617 sme_requestTypetoString(pScanReq->requestType),
5618 pScanReq->requestType,
5619 pMsg->channelList.numChannels);
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005620
5621 for(i = 0; i < pMsg->channelList.numChannels; i++)
5622 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005623 smsLog(pMac, LOG3, FL("channelNumber[%d]= %d"), i, pMsg->channelList.channelNumber[i]);
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005624 }
5625
Jeff Johnson295189b2012-06-20 16:38:30 -07005626 if(HAL_STATUS_SUCCESS(status))
5627 {
5628 status = palSendMBMessage(pMac->hHdd, pMsg);
5629 }
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005630 else
5631 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005632 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d"), status );
Kiet Lam64c1b492013-07-12 13:56:44 +05305633 vos_mem_free(pMsg);
Jeff Johnson295189b2012-06-20 16:38:30 -07005634 }
5635 }//Success allocated memory
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005636 else
5637 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005638 smsLog( pMac, LOGE, FL(" memory allocation failure"));
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005639 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005640
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05305641 if(!HAL_STATUS_SUCCESS(status))
5642 {
5643 smsLog( pMac, LOG1, FL("Failed: SId: %d FirstMatch = %d"
5644 " UniqueResult = %d freshScan = %d hiddenSsid = %d"),
5645 sessionId, pScanReqParam->bReturnAfter1stMatch,
5646 pScanReqParam->fUniqueResult, pScanReqParam->freshScan,
5647 pScanReqParam->hiddenSsid );
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05305648 smsLog( pMac, LOG1, FL("scanType = %s (%d) BSSType = %s (%d) "
5649 "numOfSSIDs = %d numOfChannels = %d requestType = %s (%d)"
5650 " p2pSearch = %d\n"),
5651 lim_ScanTypetoString(pScanReq->scanType),
5652 pScanReq->scanType,
5653 lim_BssTypetoString(pScanReq->BSSType),
5654 pScanReq->BSSType,
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05305655 pScanReq->SSIDs.numOfSSIDs,
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05305656 pScanReq->ChannelInfo.numOfChannels,
5657 sme_requestTypetoString(pScanReq->requestType),
5658 pScanReq->requestType,
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05305659 pScanReq->p2pSearch );
5660
5661 }
5662
Jeff Johnson295189b2012-06-20 16:38:30 -07005663 return( status );
5664}
5665
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005666eHalStatus csrSendMBScanResultReq( tpAniSirGlobal pMac, tANI_U32 sessionId, tScanReqParam *pScanReqParam )
Jeff Johnson295189b2012-06-20 16:38:30 -07005667{
5668 eHalStatus status = eHAL_STATUS_SUCCESS;
5669 tSirSmeScanReq *pMsg;
5670 tANI_U16 msgLen;
5671
5672 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ));
Kiet Lam64c1b492013-07-12 13:56:44 +05305673 pMsg = vos_mem_malloc(msgLen);
5674 if ( NULL == pMsg )
5675 status = eHAL_STATUS_FAILURE;
5676 else
Jeff Johnson295189b2012-06-20 16:38:30 -07005677 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305678 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005679 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
5680 pMsg->length = pal_cpu_to_be16(msgLen);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005681 pMsg->sessionId = sessionId;
5682 pMsg->transactionId = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07005683 pMsg->returnFreshResults = pScanReqParam->freshScan;
5684 //Always ask for unique result
5685 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
5686 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
5687 status = palSendMBMessage(pMac->hHdd, pMsg);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005688 if (!HAL_STATUS_SUCCESS(status))
5689 {
5690 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d\n"), status );
5691 }
5692
Jeff Johnson295189b2012-06-20 16:38:30 -07005693 }
5694
5695 return( status );
5696}
5697
5698
5699
5700eHalStatus csrScanChannels( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5701{
5702 eHalStatus status = eHAL_STATUS_FAILURE;
5703 tScanReqParam scanReq;
5704
5705 do
5706 {
5707 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE | TRUE;
5708 scanReq.fUniqueResult = TRUE;
5709 scanReq.hiddenSsid = SIR_SCAN_NO_HIDDEN_SSID;
5710 if(eCsrScanForSsid == pCommand->u.scanCmd.reason)
5711 {
5712 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_FIRST_MATCH;
5713 }
5714 else
5715 {
5716 // Basically do scan on all channels even for 11D 1st scan case.
5717 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5718 }
5719 if((eCsrScanBgScan == pCommand->u.scanCmd.reason)||
5720 (eCsrScanProbeBss == pCommand->u.scanCmd.reason))
5721 {
5722 scanReq.hiddenSsid = SIR_SCAN_HIDDEN_SSID_PE_DECISION;
5723 }
5724
5725#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5726 {
5727 vos_log_scan_pkt_type *pScanLog = NULL;
5728
5729 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
5730 if(pScanLog)
5731 {
5732 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
5733 eCsrScanProbeBss == pCommand->u.scanCmd.reason)
5734 {
5735 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
5736 }
5737 else
5738 {
5739 if( (eSIR_PASSIVE_SCAN != pCommand->u.scanCmd.u.scanRequest.scanType) &&
5740 (eSIR_PASSIVE_SCAN != pMac->scan.curScanType) )
5741 {
5742 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_REQ;
5743 }
5744 else
5745 {
5746 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_REQ;
5747 }
5748 }
5749 pScanLog->minChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.minChnTime;
5750 pScanLog->maxChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.maxChnTime;
5751 pScanLog->numChannel = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
5752 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
5753 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305754 vos_mem_copy(pScanLog->channels,
5755 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
5756 pScanLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07005757 }
5758 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
5759 }
5760 }
5761#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5762
Agrawal Ashish0b6984f2014-04-05 18:35:45 +05305763 csrClearVotesForCountryInfo(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07005764 status = csrSendMBScanReq(pMac, pCommand->sessionId,
5765 &pCommand->u.scanCmd.u.scanRequest, &scanReq);
5766 }while(0);
5767
5768 return( status );
5769}
5770
5771
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005772eHalStatus csrScanRetrieveResult(tpAniSirGlobal pMac, tSmeCmd *pCommand)
Jeff Johnson295189b2012-06-20 16:38:30 -07005773{
5774 eHalStatus status = eHAL_STATUS_FAILURE;
5775 tScanReqParam scanReq;
5776
5777 do
5778 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005779#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5780 if (eCsrScanGetLfrResult == pCommand->u.scanCmd.reason)
5781 {
5782 //to get the LFR candidates from PE cache
5783 scanReq.freshScan = SIR_BG_SCAN_RETURN_LFR_CACHED_RESULTS|SIR_BG_SCAN_PURGE_LFR_RESULTS;
5784 scanReq.fUniqueResult = TRUE;
5785 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5786 }
5787 else
5788#endif
5789 {
5790 //not a fresh scan
5791 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE;
5792 scanReq.fUniqueResult = TRUE;
5793 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5794 }
5795 status = csrSendMBScanResultReq(pMac, pCommand->sessionId, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07005796 }while(0);
5797
5798 return (status);
5799}
5800
Siddharth Bhald8a95e82015-02-12 20:14:52 +05305801eHalStatus csrProcessMacAddrSpoofCommand( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5802{
5803 tSirSpoofMacAddrReq *pMsg;
5804 tANI_U16 msgLen;
5805 eHalStatus status = eHAL_STATUS_FAILURE;
5806 do {
5807 msgLen = sizeof(tSirSpoofMacAddrReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07005808
Siddharth Bhald8a95e82015-02-12 20:14:52 +05305809 pMsg = vos_mem_malloc(msgLen);
5810 if ( NULL == pMsg )
5811 return eHAL_STATUS_FAILURE;
5812 pMsg->messageType= pal_cpu_to_be16((tANI_U16)eWNI_SME_MAC_SPOOF_ADDR_IND);
5813 pMsg->length= pal_cpu_to_be16(msgLen);
5814 // spoof mac address
5815 vos_mem_copy((tANI_U8 *)pMsg->macAddr,
5816 (tANI_U8 *)pCommand->u.macAddrSpoofCmd.macAddr, sizeof(tSirMacAddr));
5817 status = palSendMBMessage(pMac->hHdd, pMsg);
5818 } while( 0 );
5819 return( status );
5820}
Jeff Johnson295189b2012-06-20 16:38:30 -07005821
5822eHalStatus csrProcessScanCommand( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5823{
5824 eHalStatus status = eHAL_STATUS_SUCCESS;
5825 tCsrChannelInfo newChannelInfo = {0, NULL};
5826 int i, j;
5827 tANI_U8 *pChannel = NULL;
5828 tANI_U32 len = 0;
5829
5830 // Transition to Scanning state...
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305831 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07005832 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305833 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5834 {
5835 pCommand->u.scanCmd.lastRoamState[i] =
5836 csrRoamStateChange( pMac, eCSR_ROAMING_STATE_SCANNING, i);
5837 smsLog( pMac, LOG3, "starting SCAN command from %d state...."
5838 " reason is %d", pCommand->u.scanCmd.lastRoamState[i],
5839 pCommand->u.scanCmd.reason );
5840 }
5841 }
5842 else
5843 {
5844 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId] =
5845 csrRoamStateChange(pMac, eCSR_ROAMING_STATE_SCANNING,
5846 pCommand->sessionId);
5847 smsLog( pMac, LOG3,
5848 "starting SCAN command from %d state.... reason is %d",
5849 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId],
5850 pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07005851 }
5852
5853 switch(pCommand->u.scanCmd.reason)
5854 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005855#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5856 case eCsrScanGetLfrResult:
5857#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005858 case eCsrScanGetResult:
5859 case eCsrScanForCapsChange: //For cap change, LIM already save BSS description
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005860 status = csrScanRetrieveResult(pMac, pCommand);
Jeff Johnson295189b2012-06-20 16:38:30 -07005861 break;
5862 case eCsrScanSetBGScanParam:
5863 status = csrProcessSetBGScanParam(pMac, pCommand);
5864 break;
5865 case eCsrScanBGScanAbort:
5866 status = csrSetCfgBackgroundScanPeriod(pMac, 0);
5867 break;
5868 case eCsrScanBGScanEnable:
5869 status = csrSetCfgBackgroundScanPeriod(pMac, pMac->roam.configParam.bgScanInterval);
5870 break;
5871 case eCsrScanGetScanChnInfo:
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05305872 status = csrScanGetScanChannelInfo(pMac, pCommand->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07005873 break;
5874 case eCsrScanUserRequest:
5875 if(pMac->roam.configParam.fScanTwice)
5876 {
5877 //We scan 2.4 channel twice
5878 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels &&
5879 (NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList))
5880 {
5881 len = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
5882 //allocate twice the channel
Mukul Sharmaa631e892014-08-28 15:38:51 +05305883 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(len * 2);
Jeff Johnson295189b2012-06-20 16:38:30 -07005884 pChannel = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
5885 }
5886 else
5887 {
5888 //get the valid channel list to scan all.
5889 len = sizeof(pMac->roam.validChannelList);
5890
5891 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
5892 {
5893 //allocate twice the channel
5894 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(len * 2);
5895 pChannel = pMac->roam.validChannelList;
5896 }
5897 }
5898 if(NULL == newChannelInfo.ChannelList)
5899 {
5900 newChannelInfo.numOfChannels = 0;
5901 }
5902 else
5903 {
5904 j = 0;
5905 for(i = 0; i < len; i++)
5906 {
5907 newChannelInfo.ChannelList[j++] = pChannel[i];
5908 if(CSR_MAX_24GHz_CHANNEL_NUMBER >= pChannel[i])
5909 {
5910 newChannelInfo.ChannelList[j++] = pChannel[i];
5911 }
5912 }
5913 if(NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
5914 {
5915 //pChannel points to the channellist from the command, free it.
5916 vos_mem_free(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -07005917 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07005918 }
5919 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = j;
5920 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = newChannelInfo.ChannelList;
5921 }
5922 } //if(pMac->roam.configParam.fScanTwice)
5923
5924 status = csrScanChannels(pMac, pCommand);
5925
5926 break;
5927 default:
5928 status = csrScanChannels(pMac, pCommand);
5929 break;
5930 }
5931
5932 if(!HAL_STATUS_SUCCESS(status))
5933 {
5934 csrReleaseScanCommand(pMac, pCommand, eCSR_SCAN_FAILURE);
5935 }
5936
5937 return (status);
5938}
5939
5940
5941eHalStatus csrScanSetBGScanparams(tpAniSirGlobal pMac, tCsrBGScanRequest *pScanReq)
5942{
5943 eHalStatus status = eHAL_STATUS_SUCCESS;
5944 tSmeCmd *pCommand = NULL;
5945
5946 if(pScanReq)
5947 {
5948 do
5949 {
5950 pCommand = csrGetCommandBuffer(pMac);
5951 if(!pCommand)
5952 {
5953 status = eHAL_STATUS_RESOURCES;
5954 break;
5955 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305956 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005957 pCommand->command = eSmeCommandScan;
5958 pCommand->u.scanCmd.reason = eCsrScanSetBGScanParam;
5959 pCommand->u.scanCmd.callback = NULL;
5960 pCommand->u.scanCmd.pContext = NULL;
Kiet Lam64c1b492013-07-12 13:56:44 +05305961 vos_mem_copy(&pCommand->u.scanCmd.u.bgScanRequest, pScanReq, sizeof(tCsrBGScanRequest));
Jeff Johnson295189b2012-06-20 16:38:30 -07005962 //we have to do the follow
5963 if(pScanReq->ChannelInfo.numOfChannels == 0)
5964 {
5965 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
5966 }
5967 else
5968 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305969 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList
5970 = vos_mem_malloc(pScanReq->ChannelInfo.numOfChannels);
5971 if ( NULL != pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07005972 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305973 vos_mem_copy(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList,
5974 pScanReq->ChannelInfo.ChannelList,
5975 pScanReq->ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07005976 }
5977 else
5978 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005979 smsLog(pMac, LOGE, FL("ran out of memory"));
Jeff Johnson295189b2012-06-20 16:38:30 -07005980 csrReleaseCommandScan(pMac, pCommand);
Kiet Lam64c1b492013-07-12 13:56:44 +05305981 return eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005982 }
5983 }
5984
5985 //scan req for SSID
5986 if(pScanReq->SSID.length)
5987 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305988 vos_mem_copy(pCommand->u.scanCmd.u.bgScanRequest.SSID.ssId,
5989 pScanReq->SSID.ssId, pScanReq->SSID.length);
Jeff Johnson295189b2012-06-20 16:38:30 -07005990 pCommand->u.scanCmd.u.bgScanRequest.SSID.length = pScanReq->SSID.length;
5991
5992 }
5993 pCommand->u.scanCmd.u.bgScanRequest.maxChnTime= pScanReq->maxChnTime;
5994 pCommand->u.scanCmd.u.bgScanRequest.minChnTime = pScanReq->minChnTime;
5995 pCommand->u.scanCmd.u.bgScanRequest.scanInterval = pScanReq->scanInterval;
5996
5997
5998 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
5999 if( !HAL_STATUS_SUCCESS( status ) )
6000 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006001 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006002 csrReleaseCommandScan( pMac, pCommand );
6003 break;
6004 }
6005 }while(0);
6006 }
6007
6008 return (status);
6009}
6010
6011eHalStatus csrScanBGScanAbort( tpAniSirGlobal pMac )
6012{
6013 eHalStatus status = eHAL_STATUS_SUCCESS;
6014 tSmeCmd *pCommand = NULL;
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 = eCsrScanBGScanAbort;
6027 pCommand->u.scanCmd.callback = NULL;
6028 pCommand->u.scanCmd.pContext = NULL;
6029 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
6030 if( !HAL_STATUS_SUCCESS( status ) )
6031 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006032 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006033 csrReleaseCommandScan( pMac, pCommand );
6034 break;
6035 }
6036 }while(0);
6037
6038 return (status);
6039}
6040
6041
6042//This will enable the background scan with the non-zero interval
6043eHalStatus csrScanBGScanEnable(tpAniSirGlobal pMac)
6044{
6045 eHalStatus status = eHAL_STATUS_SUCCESS;
6046 tSmeCmd *pCommand = NULL;
6047
6048 if(pMac->roam.configParam.bgScanInterval)
6049 {
6050 do
6051 {
6052 pCommand = csrGetCommandBuffer(pMac);
6053 if(!pCommand)
6054 {
6055 status = eHAL_STATUS_RESOURCES;
6056 break;
6057 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306058 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006059 pCommand->command = eSmeCommandScan;
6060 pCommand->u.scanCmd.reason = eCsrScanBGScanEnable;
6061 pCommand->u.scanCmd.callback = NULL;
6062 pCommand->u.scanCmd.pContext = NULL;
6063 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
6064 if( !HAL_STATUS_SUCCESS( status ) )
6065 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006066 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006067 csrReleaseCommandScan( pMac, pCommand );
6068 break;
6069 }
6070 }while(0);
6071 //BG scan results are reported automatically by PE to SME once the scan is done.
6072 //No need to fetch the results explicitly.
6073 //csrScanStartGetResultTimer(pMac);
6074 csrScanStartResultAgingTimer(pMac);
6075 }
6076 else
6077 {
6078 //We don't have BG scan so stop the aging timer
6079 csrScanStopResultAgingTimer(pMac);
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006080 smsLog(pMac, LOGE, FL("cannot continue because the bgscan interval is 0"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006081 status = eHAL_STATUS_INVALID_PARAMETER;
6082 }
6083
6084 return (status);
6085}
6086
6087
6088eHalStatus csrScanCopyRequest(tpAniSirGlobal pMac, tCsrScanRequest *pDstReq, tCsrScanRequest *pSrcReq)
6089{
6090 eHalStatus status = eHAL_STATUS_SUCCESS;
6091 tANI_U32 len = sizeof(pMac->roam.validChannelList);
6092 tANI_U32 index = 0;
6093 tANI_U32 new_index = 0;
Manjunathappa Prakashde7b2a52014-02-28 16:59:03 -08006094 eNVChannelEnabledType NVchannel_state;
Arif Hussain6af38622014-03-12 12:39:57 -07006095 tANI_U8 ch144_support = 0;
6096
6097 ch144_support = WDA_getFwWlanFeatCaps(WLAN_CH144);
Jeff Johnson295189b2012-06-20 16:38:30 -07006098
6099 do
6100 {
6101 status = csrScanFreeRequest(pMac, pDstReq);
6102 if(HAL_STATUS_SUCCESS(status))
6103 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306104 vos_mem_copy(pDstReq, pSrcReq, sizeof(tCsrScanRequest));
Gopichand Nakkalac7b1d3e2012-12-31 14:07:19 -08006105 /* Re-initialize the pointers to NULL since we did a copy */
6106 pDstReq->pIEField = NULL;
6107 pDstReq->ChannelInfo.ChannelList = NULL;
6108 pDstReq->SSIDs.SSIDList = NULL;
6109
Jeff Johnson295189b2012-06-20 16:38:30 -07006110 if(pSrcReq->uIEFieldLen == 0)
6111 {
6112 pDstReq->pIEField = NULL;
6113 }
6114 else
6115 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306116 pDstReq->pIEField = vos_mem_malloc(pSrcReq->uIEFieldLen);
6117 if ( NULL == pDstReq->pIEField )
Jeff Johnson295189b2012-06-20 16:38:30 -07006118 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306119 status = eHAL_STATUS_FAILURE;
6120 smsLog(pMac, LOGE, FL("No memory for scanning IE fields"));
6121 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07006122 }
6123 else
6124 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306125 status = eHAL_STATUS_SUCCESS;
6126 vos_mem_copy(pDstReq->pIEField, pSrcReq->pIEField,
6127 pSrcReq->uIEFieldLen);
6128 pDstReq->uIEFieldLen = pSrcReq->uIEFieldLen;
Jeff Johnson295189b2012-06-20 16:38:30 -07006129 }
6130 }//Allocate memory for IE field
6131 {
6132 if(pSrcReq->ChannelInfo.numOfChannels == 0)
6133 {
6134 pDstReq->ChannelInfo.ChannelList = NULL;
6135 pDstReq->ChannelInfo.numOfChannels = 0;
6136 }
6137 else
6138 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306139 pDstReq->ChannelInfo.ChannelList = vos_mem_malloc(
6140 pSrcReq->ChannelInfo.numOfChannels
6141 * sizeof(*pDstReq->ChannelInfo.ChannelList));
6142 if ( NULL == pDstReq->ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07006143 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306144 status = eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006145 pDstReq->ChannelInfo.numOfChannels = 0;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306146 smsLog(pMac, LOGE, FL("No memory for scanning Channel"
6147 " List"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006148 break;
6149 }
6150
6151 if((pSrcReq->scanType == eSIR_PASSIVE_SCAN) && (pSrcReq->requestType == eCSR_SCAN_REQUEST_11D_SCAN))
6152 {
6153 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
6154 {
Arif Hussain6af38622014-03-12 12:39:57 -07006155 /* Skip CH 144 if firmware support not present */
6156 if (pSrcReq->ChannelInfo.ChannelList[index] == 144 && !ch144_support)
6157 continue;
6158
Manjunathappa Prakashde7b2a52014-02-28 16:59:03 -08006159 NVchannel_state = vos_nv_getChannelEnabledState(
6160 pSrcReq->ChannelInfo.ChannelList[index]);
6161 if ((NV_CHANNEL_ENABLE == NVchannel_state) ||
6162 (NV_CHANNEL_DFS == NVchannel_state))
6163 {
6164 pDstReq->ChannelInfo.ChannelList[new_index] =
6165 pSrcReq->ChannelInfo.ChannelList[index];
6166 new_index++;
6167 }
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306168 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006169 pDstReq->ChannelInfo.numOfChannels = new_index;
6170 }
6171 else if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
6172 {
6173 new_index = 0;
6174 pMac->roam.numValidChannels = len;
c_hpothu0d5a7352014-03-22 12:30:25 +05306175
6176 /* Since in CsrScanRequest,value of pMac->scan.nextScanID
6177 * is incremented before calling CsrScanCopyRequest, as a
6178 * result pMac->scan.nextScanID is equal to ONE for the
6179 * first scan.
6180 */
Ganesh Kondabattini8f6e3b32014-08-25 16:07:54 +05306181 if ((pMac->roam.configParam.initialScanSkipDFSCh &&
6182 1 == pMac->scan.nextScanID) ||(pMac->miracast_mode))
c_hpothu0d5a7352014-03-22 12:30:25 +05306183 {
6184 smsLog(pMac, LOG1,
6185 FL("Initial scan, scan only non-DFS channels"));
6186
6187 for (index = 0; index < pSrcReq->ChannelInfo.
6188 numOfChannels ; index++ )
6189 {
6190 if((csrRoamIsValidChannel(pMac, pSrcReq->ChannelInfo.
6191 ChannelList[index])))
6192 {
6193 /*Skiipping DFS Channels for 1st scan */
6194 if(NV_CHANNEL_DFS ==
6195 vos_nv_getChannelEnabledState(pSrcReq->ChannelInfo.
6196 ChannelList[index]))
6197 continue ;
6198
6199 pDstReq->ChannelInfo.ChannelList[new_index] =
6200 pSrcReq->ChannelInfo.ChannelList[index];
6201 new_index++;
6202
6203 }
6204 }
6205 pMac->roam.configParam.initialScanSkipDFSCh = 0;
6206 }
6207 else
6208 {
6209 for ( index = 0; index < pSrcReq->ChannelInfo.
6210 numOfChannels ; index++ )
Jeff Johnson295189b2012-06-20 16:38:30 -07006211 {
Arif Hussain6af38622014-03-12 12:39:57 -07006212 /* Skip CH 144 if firmware support not present */
6213 if (pSrcReq->ChannelInfo.ChannelList[index] == 144 && !ch144_support)
6214 continue;
6215
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -07006216 /* Allow scan on valid channels only.
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -07006217 */
Abhishek Singh2ec36ab2014-08-07 16:14:25 +05306218 if ( ( csrRoamIsValidChannel(pMac, pSrcReq->ChannelInfo.ChannelList[index]) ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07006219 {
Srikant Kuppa866893f2012-12-27 17:28:14 -08006220 if( (pSrcReq->skipDfsChnlInP2pSearch &&
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08006221 (NV_CHANNEL_DFS == vos_nv_getChannelEnabledState(pSrcReq->ChannelInfo.ChannelList[index])) )
Srikant Kuppa866893f2012-12-27 17:28:14 -08006222#ifdef FEATURE_WLAN_LFR
6223 /*
6224 * If LFR is requesting a contiguous scan
6225 * (i.e. numOfChannels > 1), then ignore
6226 * DFS channels.
6227 * TODO: vos_nv_getChannelEnabledState is returning
6228 * 120, 124 and 128 as non-DFS channels. Hence, the
6229 * use of direct check for channels below.
6230 */
6231 || ((eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType) &&
6232 (pSrcReq->ChannelInfo.numOfChannels > 1) &&
Santhosh Kumar Padma9ccaaff2014-07-09 19:58:12 +05306233 (CSR_IS_CHANNEL_DFS(pSrcReq->ChannelInfo.ChannelList[index])) &&
6234 !pMac->roam.configParam.allowDFSChannelRoam)
Srikant Kuppa866893f2012-12-27 17:28:14 -08006235#endif
6236 )
6237 {
6238#ifdef FEATURE_WLAN_LFR
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05306239 smsLog(pMac, LOG2,
6240 FL(" reqType=%s (%d), numOfChannels=%d,"
6241 " ignoring DFS channel %d"),
6242 sme_requestTypetoString(pSrcReq->requestType),
6243 pSrcReq->requestType,
6244 pSrcReq->ChannelInfo.numOfChannels,
6245 pSrcReq->ChannelInfo.ChannelList[index]);
Srikant Kuppa866893f2012-12-27 17:28:14 -08006246#endif
Sushant Kaushike0d2cce2014-04-10 14:36:07 +05306247 continue;
Srikant Kuppa866893f2012-12-27 17:28:14 -08006248 }
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08006249
Jeff Johnson295189b2012-06-20 16:38:30 -07006250 pDstReq->ChannelInfo.ChannelList[new_index] =
6251 pSrcReq->ChannelInfo.ChannelList[index];
6252 new_index++;
6253 }
6254 }
c_hpothu0d5a7352014-03-22 12:30:25 +05306255 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006256 pDstReq->ChannelInfo.numOfChannels = new_index;
Srikant Kuppa866893f2012-12-27 17:28:14 -08006257#ifdef FEATURE_WLAN_LFR
Abhishek Singh2ec36ab2014-08-07 16:14:25 +05306258 if ( ( ( eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType ) ||
6259 ( eCSR_SCAN_P2P_DISCOVERY == pSrcReq->requestType ) ) &&
6260 ( 0 == pDstReq->ChannelInfo.numOfChannels ) )
Srikant Kuppa866893f2012-12-27 17:28:14 -08006261 {
6262 /*
6263 * No valid channels found in the request.
6264 * Only perform scan on the channels passed
Abhishek Singh2ec36ab2014-08-07 16:14:25 +05306265 * pSrcReq if it is a eCSR_SCAN_HO_BG_SCAN or
6266 * eCSR_SCAN_P2P_DISCOVERY.
Srikant Kuppa866893f2012-12-27 17:28:14 -08006267 * Passing 0 to LIM will trigger a scan on
6268 * all valid channels which is not desirable.
6269 */
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306270 smsLog(pMac, LOGE, FL(" no valid channels found"
6271 " (request=%d)"), pSrcReq->requestType);
Srikant Kuppa866893f2012-12-27 17:28:14 -08006272 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
6273 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306274 smsLog(pMac, LOGE, FL("pSrcReq index=%d"
6275 " channel=%d"), index,
6276 pSrcReq->ChannelInfo.ChannelList[index]);
Srikant Kuppa866893f2012-12-27 17:28:14 -08006277 }
6278 status = eHAL_STATUS_FAILURE;
6279 break;
6280 }
6281#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006282 }
6283 else
6284 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306285 smsLog(pMac, LOGE, FL("Couldn't get the valid Channel"
6286 " List, keeping requester's list"));
Kiet Lam64c1b492013-07-12 13:56:44 +05306287 vos_mem_copy(pDstReq->ChannelInfo.ChannelList,
6288 pSrcReq->ChannelInfo.ChannelList,
6289 pSrcReq->ChannelInfo.numOfChannels
6290 * sizeof(*pDstReq->ChannelInfo.ChannelList));
Jeff Johnson295189b2012-06-20 16:38:30 -07006291 pDstReq->ChannelInfo.numOfChannels = pSrcReq->ChannelInfo.numOfChannels;
6292 }
6293 }//Allocate memory for Channel List
6294 }
6295 if(pSrcReq->SSIDs.numOfSSIDs == 0)
6296 {
6297 pDstReq->SSIDs.numOfSSIDs = 0;
6298 pDstReq->SSIDs.SSIDList = NULL;
6299 }
6300 else
6301 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306302 pDstReq->SSIDs.SSIDList = vos_mem_malloc(
6303 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
6304 if ( NULL == pDstReq->SSIDs.SSIDList )
6305 status = eHAL_STATUS_FAILURE;
6306 else
6307 status = eHAL_STATUS_SUCCESS;
6308 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07006309 {
6310 pDstReq->SSIDs.numOfSSIDs = pSrcReq->SSIDs.numOfSSIDs;
Kiet Lam64c1b492013-07-12 13:56:44 +05306311 vos_mem_copy(pDstReq->SSIDs.SSIDList,
6312 pSrcReq->SSIDs.SSIDList,
6313 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
Jeff Johnson295189b2012-06-20 16:38:30 -07006314 }
6315 else
6316 {
6317 pDstReq->SSIDs.numOfSSIDs = 0;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306318 smsLog(pMac, LOGE, FL("No memory for scanning SSID List"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006319 break;
6320 }
6321 }//Allocate memory for SSID List
Jeff Johnson295189b2012-06-20 16:38:30 -07006322 pDstReq->p2pSearch = pSrcReq->p2pSearch;
Jeff Johnsone7245742012-09-05 17:12:55 -07006323 pDstReq->skipDfsChnlInP2pSearch = pSrcReq->skipDfsChnlInP2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07006324
6325 }
6326 }while(0);
6327
6328 if(!HAL_STATUS_SUCCESS(status))
6329 {
6330 csrScanFreeRequest(pMac, pDstReq);
6331 }
6332
6333 return (status);
6334}
6335
6336
6337eHalStatus csrScanFreeRequest(tpAniSirGlobal pMac, tCsrScanRequest *pReq)
6338{
Jeff Johnson295189b2012-06-20 16:38:30 -07006339
6340 if(pReq->ChannelInfo.ChannelList)
6341 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306342 vos_mem_free(pReq->ChannelInfo.ChannelList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006343 pReq->ChannelInfo.ChannelList = NULL;
6344 }
6345 pReq->ChannelInfo.numOfChannels = 0;
6346 if(pReq->pIEField)
6347 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306348 vos_mem_free(pReq->pIEField);
Jeff Johnson295189b2012-06-20 16:38:30 -07006349 pReq->pIEField = NULL;
6350 }
6351 pReq->uIEFieldLen = 0;
6352 if(pReq->SSIDs.SSIDList)
6353 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306354 vos_mem_free(pReq->SSIDs.SSIDList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006355 pReq->SSIDs.SSIDList = NULL;
6356 }
6357 pReq->SSIDs.numOfSSIDs = 0;
6358
Kiet Lam64c1b492013-07-12 13:56:44 +05306359 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07006360}
6361
6362
6363void csrScanCallCallback(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
6364{
6365 if(pCommand->u.scanCmd.callback)
6366 {
6367// sme_ReleaseGlobalLock( &pMac->sme );
6368 pCommand->u.scanCmd.callback(pMac, pCommand->u.scanCmd.pContext, pCommand->u.scanCmd.scanID, scanStatus);
6369// sme_AcquireGlobalLock( &pMac->sme );
6370 } else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006371 smsLog( pMac, LOG2, "%s:%d - Callback NULL!!!", __func__, __LINE__);
Jeff Johnson295189b2012-06-20 16:38:30 -07006372 }
6373}
6374
6375
6376void csrScanStopTimers(tpAniSirGlobal pMac)
6377{
6378 csrScanStopResultAgingTimer(pMac);
6379 csrScanStopIdleScanTimer(pMac);
6380 csrScanStopGetResultTimer(pMac);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006381 if(0 != pMac->scan.scanResultCfgAgingTime )
6382 {
6383 csrScanStopResultCfgAgingTimer(pMac);
6384 }
6385
Jeff Johnson295189b2012-06-20 16:38:30 -07006386}
6387
6388
6389eHalStatus csrScanStartGetResultTimer(tpAniSirGlobal pMac)
6390{
6391 eHalStatus status;
6392
6393 if(pMac->scan.fScanEnable)
6394 {
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306395 status = vos_timer_start(&pMac->scan.hTimerGetResult, CSR_SCAN_GET_RESULT_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006396 }
6397 else
6398 {
6399 status = eHAL_STATUS_FAILURE;
6400 }
6401
6402 return (status);
6403}
6404
6405
6406eHalStatus csrScanStopGetResultTimer(tpAniSirGlobal pMac)
6407{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306408 return (vos_timer_stop(&pMac->scan.hTimerGetResult));
Jeff Johnson295189b2012-06-20 16:38:30 -07006409}
6410
6411
6412void csrScanGetResultTimerHandler(void *pv)
6413{
6414 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6415
6416 csrScanRequestResult(pMac);
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306417
6418 vos_timer_start(&pMac->scan.hTimerGetResult, CSR_SCAN_GET_RESULT_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006419}
6420
6421#ifdef WLAN_AP_STA_CONCURRENCY
6422static void csrStaApConcTimerHandler(void *pv)
6423{
6424 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6425 tListElem *pEntry;
6426 tSmeCmd *pScanCmd;
6427
6428 csrLLLock(&pMac->scan.scanCmdPendingList);
6429
6430 if ( NULL != ( pEntry = csrLLPeekHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) ) )
6431 {
6432 tCsrScanRequest scanReq;
6433 tSmeCmd *pSendScanCmd = NULL;
6434 tANI_U8 numChn = 0;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006435 tANI_U8 nNumChanCombinedConc = 0;
Vinay Malekal05fdc812012-12-17 13:04:30 -08006436 tANI_U8 i, j;
Jeff Johnson295189b2012-06-20 16:38:30 -07006437 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
6438 tANI_U8 channelToScan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
6439 eHalStatus status;
6440
Jeff Johnson295189b2012-06-20 16:38:30 -07006441 pScanCmd = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
6442 numChn = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08006443
6444 /* if any session is connected and the number of channels to scan is
6445 * greater than 1 then split the scan into multiple scan operations
6446 * on each individual channel else continue to perform scan on all
6447 * specified channels */
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08006448
6449 /* split scan if number of channels to scan is greater than 1 and
6450 * any one of the following:
6451 * - STA session is connected and the scan is not a P2P search
6452 * - any P2P session is connected
Srikant Kuppa866893f2012-12-27 17:28:14 -08006453 * Do not split scans if no concurrent infra connections are
6454 * active and if the scan is a BG scan triggered by LFR (OR)
6455 * any scan if LFR is in the middle of a BG scan. Splitting
6456 * the scan is delaying the time it takes for LFR to find
6457 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08006458 */
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006459
6460 if((csrIsStaSessionConnected(pMac) &&
6461 !csrIsP2pSessionConnected(pMac)))
6462 {
6463 nNumChanCombinedConc = pMac->roam.configParam.nNumStaChanCombinedConc;
6464 }
6465 else if(csrIsP2pSessionConnected(pMac))
6466 {
6467 nNumChanCombinedConc = pMac->roam.configParam.nNumP2PChanCombinedConc;
6468 }
6469
6470 if ( (numChn > nNumChanCombinedConc) &&
Srikant Kuppa866893f2012-12-27 17:28:14 -08006471 ((csrIsStaSessionConnected(pMac) &&
6472#ifdef FEATURE_WLAN_LFR
6473 (csrIsConcurrentInfraConnected(pMac) ||
6474 ((pScanCmd->u.scanCmd.reason != eCsrScanBgScan) &&
6475 (pMac->roam.neighborRoamInfo.neighborRoamState !=
6476 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
6477#endif
6478 (pScanCmd->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08006479 (csrIsP2pSessionConnected(pMac))))
Jeff Johnson295189b2012-06-20 16:38:30 -07006480 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306481 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006482
6483 pSendScanCmd = csrGetCommandBuffer(pMac); //optimize this to use 2 command buffer only
6484 if (!pSendScanCmd)
6485 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006486 smsLog( pMac, LOGE, FL(" Failed to get Queue command buffer") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006487 csrLLUnlock(&pMac->scan.scanCmdPendingList);
6488 return;
6489 }
6490 pSendScanCmd->command = pScanCmd->command;
6491 pSendScanCmd->sessionId = pScanCmd->sessionId;
6492 pSendScanCmd->u.scanCmd.callback = NULL;
6493 pSendScanCmd->u.scanCmd.pContext = pScanCmd->u.scanCmd.pContext;
6494 pSendScanCmd->u.scanCmd.reason = pScanCmd->u.scanCmd.reason;
6495 pSendScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
6496
Madan Mohan Koyyalamudiaf2a8b92012-10-09 14:58:07 -07006497 /* First copy all the parameters to local variable of scan request */
6498 csrScanCopyRequest(pMac, &scanReq, &pScanCmd->u.scanCmd.u.scanRequest);
6499
6500 /* Now modify the elements of local var scan request required to be modified for split scan */
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08006501 if(scanReq.ChannelInfo.ChannelList != NULL)
6502 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306503 vos_mem_free(scanReq.ChannelInfo.ChannelList);
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08006504 scanReq.ChannelInfo.ChannelList = NULL;
6505 }
6506
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006507 pChnInfo->numOfChannels = nNumChanCombinedConc;
Kiet Lam64c1b492013-07-12 13:56:44 +05306508 vos_mem_copy(&channelToScan[0],
6509 &pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[0],
6510 pChnInfo->numOfChannels * sizeof(tANI_U8));//just send one channel
Jeff Johnson295189b2012-06-20 16:38:30 -07006511 pChnInfo->ChannelList = &channelToScan[0];
6512
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006513 for (i = 0, j = nNumChanCombinedConc; i < (numChn-nNumChanCombinedConc); i++, j++)
Jeff Johnson295189b2012-06-20 16:38:30 -07006514 {
6515 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] =
Vinay Malekal05fdc812012-12-17 13:04:30 -08006516 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[j]; //Move all the channels one step
Jeff Johnson295189b2012-06-20 16:38:30 -07006517 }
6518
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006519 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = numChn - nNumChanCombinedConc; //reduce outstanding # of channels to be scanned
Jeff Johnson295189b2012-06-20 16:38:30 -07006520
6521 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
c_hpothudbefd3e2014-04-28 15:59:47 +05306522
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -07006523 //Use concurrency values for min/maxChnTime.
6524 //We know csrIsAnySessionConnected(pMac) returns TRUE here
6525 csrSetDefaultScanTiming(pMac, scanReq.scanType, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07006526
6527 status = csrScanCopyRequest(pMac, &pSendScanCmd->u.scanCmd.u.scanRequest, &scanReq);
6528 if(!HAL_STATUS_SUCCESS(status))
6529 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006530 smsLog( pMac, LOGE, FL(" Failed to get copy csrScanRequest = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006531 csrLLUnlock(&pMac->scan.scanCmdPendingList);
6532 return;
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08006533 }
6534 /* Clean the local scan variable */
6535 scanReq.ChannelInfo.ChannelList = NULL;
6536 scanReq.ChannelInfo.numOfChannels = 0;
6537 csrScanFreeRequest(pMac, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07006538 }
6539 else
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08006540 {
6541 /* no active connected session present or numChn == 1
6542 * scan all remaining channels */
Jeff Johnson295189b2012-06-20 16:38:30 -07006543 pSendScanCmd = pScanCmd;
6544 //remove this command from pending list
6545 if (csrLLRemoveHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) == NULL)
6546 { //In case between PeekHead and here, the entry got removed by another thread.
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006547 smsLog( pMac, LOGE, FL(" Failed to remove entry from scanCmdPendingList"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006548 }
6549
6550 }
6551 csrQueueSmeCommand(pMac, pSendScanCmd, eANI_BOOLEAN_FALSE);
6552
6553 }
6554
Jeff Johnson295189b2012-06-20 16:38:30 -07006555 csrLLUnlock(&pMac->scan.scanCmdPendingList);
6556
6557}
6558#endif
6559
6560eHalStatus csrScanStartResultAgingTimer(tpAniSirGlobal pMac)
6561{
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006562 eHalStatus status = eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006563
6564 if(pMac->scan.fScanEnable)
6565 {
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306566 status = vos_timer_start(&pMac->scan.hTimerResultAging, CSR_SCAN_RESULT_AGING_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006567 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006568 return (status);
6569}
6570
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006571eHalStatus csrScanStartResultCfgAgingTimer(tpAniSirGlobal pMac)
6572{
6573 eHalStatus status = eHAL_STATUS_FAILURE;
6574
6575 if(pMac->scan.fScanEnable)
6576 {
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306577 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 -08006578 }
6579 return (status);
6580}
Jeff Johnson295189b2012-06-20 16:38:30 -07006581
6582eHalStatus csrScanStopResultAgingTimer(tpAniSirGlobal pMac)
6583{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306584 return (vos_timer_stop(&pMac->scan.hTimerResultAging));
Jeff Johnson295189b2012-06-20 16:38:30 -07006585}
6586
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006587eHalStatus csrScanStopResultCfgAgingTimer(tpAniSirGlobal pMac)
6588{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306589 return (vos_timer_stop(&pMac->scan.hTimerResultCfgAging));
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006590}
Jeff Johnson295189b2012-06-20 16:38:30 -07006591
6592//This function returns the maximum time a BSS is allowed in the scan result.
6593//The time varies base on connection and power saving factors.
6594//Not connected, No PS
6595//Not connected, with PS
6596//Connected w/o traffic, No PS
6597//Connected w/o traffic, with PS
6598//Connected w/ traffic, no PS -- Not supported
6599//Connected w/ traffic, with PS -- Not supported
6600//the return unit is in seconds.
6601tANI_U32 csrScanGetAgeOutTime(tpAniSirGlobal pMac)
6602{
6603 tANI_U32 nRet;
6604
6605 if(pMac->scan.nAgingCountDown)
6606 {
6607 //Calculate what should be the timeout value for this
6608 nRet = pMac->scan.nLastAgeTimeOut * pMac->scan.nAgingCountDown;
6609 pMac->scan.nAgingCountDown--;
6610 }
6611 else
6612 {
6613 if( csrIsAllSessionDisconnected( pMac ) )
6614 {
6615 if(pmcIsPowerSaveEnabled(pMac, ePMC_IDLE_MODE_POWER_SAVE))
6616 {
6617 nRet = pMac->roam.configParam.scanAgeTimeNCPS;
6618 }
6619 else
6620 {
6621 nRet = pMac->roam.configParam.scanAgeTimeNCNPS;
6622 }
6623 }
6624 else
6625 {
6626 if(pmcIsPowerSaveEnabled(pMac, ePMC_BEACON_MODE_POWER_SAVE))
6627 {
6628 nRet = pMac->roam.configParam.scanAgeTimeCPS;
6629 }
6630 else
6631 {
6632 nRet = pMac->roam.configParam.scanAgeTimeCNPS;
6633 }
6634 }
6635 //If state-change causing aging time out change, we want to delay it somewhat to avoid
6636 //unnecessary removal of BSS. This is mostly due to transition from connect to disconnect.
6637 if(pMac->scan.nLastAgeTimeOut > nRet)
6638 {
6639 if(nRet)
6640 {
6641 pMac->scan.nAgingCountDown = (pMac->scan.nLastAgeTimeOut / nRet);
6642 }
6643 pMac->scan.nLastAgeTimeOut = nRet;
6644 nRet *= pMac->scan.nAgingCountDown;
6645 }
6646 else
6647 {
6648 pMac->scan.nLastAgeTimeOut = nRet;
6649 }
6650 }
6651
6652 return (nRet);
6653}
6654
6655
6656void csrScanResultAgingTimerHandler(void *pv)
6657{
6658 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6659 tANI_BOOLEAN fDisconnected = csrIsAllSessionDisconnected(pMac);
6660
6661 //no scan, no aging
Kaushik, Sushant9073c0c2014-03-11 19:10:23 +05306662 if (pMac->scan.fScanEnable &&
Jeff Johnson295189b2012-06-20 16:38:30 -07006663 (((eANI_BOOLEAN_FALSE == fDisconnected) && pMac->roam.configParam.bgScanInterval)
Kaushik, Sushant9073c0c2014-03-11 19:10:23 +05306664 || (fDisconnected && (pMac->scan.fCancelIdleScan == eANI_BOOLEAN_FALSE))
6665 || (pMac->fScanOffload))
Jeff Johnson295189b2012-06-20 16:38:30 -07006666 )
6667 {
6668 tListElem *pEntry, *tmpEntry;
6669 tCsrScanResult *pResult;
6670 tANI_TIMESTAMP ageOutTime = (tANI_TIMESTAMP)(csrScanGetAgeOutTime(pMac) * PAL_TICKS_PER_SECOND); //turn it into 10ms units
6671 tANI_TIMESTAMP curTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
6672
6673 csrLLLock(&pMac->scan.scanResultList);
6674 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
6675 while( pEntry )
6676 {
6677 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
6678 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
6679 if((curTime - pResult->Result.BssDescriptor.nReceivedTime) > ageOutTime)
6680 {
6681 smsLog(pMac, LOGW, " age out due to time out");
6682 csrScanAgeOutBss(pMac, pResult);
6683 }
6684 pEntry = tmpEntry;
6685 }
6686 csrLLUnlock(&pMac->scan.scanResultList);
6687 }
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306688 vos_timer_start(&pMac->scan.hTimerResultAging, CSR_SCAN_RESULT_AGING_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006689}
6690
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006691static void csrScanResultCfgAgingTimerHandler(void *pv)
6692{
6693 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6694 tListElem *pEntry, *tmpEntry;
6695 tCsrScanResult *pResult;
6696 tANI_TIMESTAMP ageOutTime = pMac->scan.scanResultCfgAgingTime * PAL_TICKS_PER_SECOND;
6697 tANI_TIMESTAMP curTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
6698
6699 csrLLLock(&pMac->scan.scanResultList);
6700 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
6701 while( pEntry )
6702 {
6703 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
6704 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
6705 if((curTime - pResult->Result.BssDescriptor.nReceivedTime) > ageOutTime)
6706 {
6707 smsLog(pMac, LOGW, " age out due to time out");
6708 csrScanAgeOutBss(pMac, pResult);
6709 }
6710 pEntry = tmpEntry;
6711 }
6712 csrLLUnlock(&pMac->scan.scanResultList);
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306713 vos_timer_start(&pMac->scan.hTimerResultCfgAging, CSR_SCAN_RESULT_CFG_AGING_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006714}
Jeff Johnson295189b2012-06-20 16:38:30 -07006715
6716eHalStatus csrScanStartIdleScanTimer(tpAniSirGlobal pMac, tANI_U32 interval)
6717{
6718 eHalStatus status;
6719
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006720 smsLog(pMac, LOG1, " csrScanStartIdleScanTimer");
Jeff Johnson295189b2012-06-20 16:38:30 -07006721 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) && interval)
6722 {
6723 pMac->scan.nIdleScanTimeGap += interval;
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306724 vos_timer_stop(&pMac->scan.hTimerIdleScan);
6725 status = vos_timer_start(&pMac->scan.hTimerIdleScan, interval/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006726 if( !HAL_STATUS_SUCCESS(status) )
6727 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006728 smsLog(pMac, LOGE, " Fail to start Idle scan timer. status = %d interval = %d", status, interval);
Jeff Johnson295189b2012-06-20 16:38:30 -07006729 //This should not happen but set the flag to restart when ready
6730 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6731 }
6732 }
6733 else
6734 {
6735 if( pMac->scan.fScanEnable && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) )
6736 {
6737 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6738 }
6739 status = eHAL_STATUS_FAILURE;
6740 }
6741
6742 return (status);
6743}
6744
6745
6746eHalStatus csrScanStopIdleScanTimer(tpAniSirGlobal pMac)
6747{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306748 return (vos_timer_stop(&pMac->scan.hTimerIdleScan));
Jeff Johnson295189b2012-06-20 16:38:30 -07006749}
6750
6751
6752//Stop CSR from asking for IMPS, This function doesn't disable IMPS from CSR
6753void csrScanSuspendIMPS( tpAniSirGlobal pMac )
6754{
6755 csrScanCancelIdleScan(pMac);
6756}
6757
6758
6759//Start CSR from asking for IMPS. This function doesn't trigger CSR to request entering IMPS
6760//because IMPS maybe disabled.
6761void csrScanResumeIMPS( tpAniSirGlobal pMac )
6762{
6763 csrScanStartIdleScan( pMac );
6764}
6765
6766
6767void csrScanIMPSCallback(void *callbackContext, eHalStatus status)
6768{
6769 tpAniSirGlobal pMac = PMAC_STRUCT( callbackContext );
6770
6771 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6772 {
6773 if(pMac->roam.configParam.IsIdleScanEnabled)
6774 {
6775 if(HAL_STATUS_SUCCESS(status))
6776 {
6777 if(csrIsAllSessionDisconnected(pMac) && !csrIsRoamCommandWaiting(pMac))
6778 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006779 smsLog(pMac, LOGW, FL("starts idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006780 csrScanAllChannels(pMac, eCSR_SCAN_IDLE_MODE_SCAN);
6781 }
6782 else
6783 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006784 smsLog(pMac, LOGW, FL("cannot start idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006785 //even though we are in timer handle, calling stop timer will make sure the timer
6786 //doesn't get to restart.
6787 csrScanStopIdleScanTimer(pMac);
6788 }
6789 }
6790 else
6791 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006792 smsLog(pMac, LOGE, FL("sees not success status (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07006793 }
6794 }
6795 else
6796 {//we might need another flag to check if CSR needs to request imps at all
6797
6798 tANI_U32 nTime = 0;
6799
6800 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_FALSE;
6801 if(!HAL_STATUS_SUCCESS(csrScanTriggerIdleScan(pMac, &nTime)))
6802 {
6803 csrScanStartIdleScanTimer(pMac, nTime);
6804 }
6805 }
6806 }
6807}
6808
6809
Rashmi Ramanna68b309c2014-05-20 11:52:22 +05306810//Param: pTimeInterval -- Caller allocated memory in return, if failed, to specify the nxt time interval for
Jeff Johnson295189b2012-06-20 16:38:30 -07006811//idle scan timer interval
6812//Return: Not success -- meaning it cannot start IMPS, caller needs to start a timer for idle scan
6813eHalStatus csrScanTriggerIdleScan(tpAniSirGlobal pMac, tANI_U32 *pTimeInterval)
6814{
6815 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
6816
6817 //Do not trigger IMPS in case of concurrency
Agarwal Ashish5974ed32014-06-16 16:59:54 +05306818 if (vos_concurrent_open_sessions_running() &&
6819 csrIsAnySessionInConnectState(pMac))
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006820 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006821 smsLog( pMac, LOG1, FL("Cannot request IMPS because Concurrent Sessions Running") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006822 return (status);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006823 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006824
6825 if(pTimeInterval)
6826 {
6827 *pTimeInterval = 0;
6828 }
6829
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006830 smsLog(pMac, LOG3, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006831 if( smeCommandPending( pMac ) )
6832 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006833 smsLog( pMac, LOG1, FL(" Cannot request IMPS because command pending") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006834 //Not to enter IMPS because more work to do
6835 if(pTimeInterval)
6836 {
6837 *pTimeInterval = 0;
6838 }
6839 //restart when ready
6840 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6841
6842 return (status);
6843 }
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07006844 if (IsPmcImpsReqFailed (pMac))
6845 {
6846 if(pTimeInterval)
6847 {
6848 *pTimeInterval = 1000000; //usec
6849 }
6850 //restart when ready
6851 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006852
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07006853 return status;
6854 }
Rashmi Ramanna68b309c2014-05-20 11:52:22 +05306855
6856 if ( !pMac->deferImps && pMac->fDeferIMPSTime )
6857 {
6858 smsLog( pMac, LOG1, FL("Defer IMPS for %dms as command processed"),
6859 pMac->fDeferIMPSTime);
Girish Gowli4f3775a2014-05-30 17:17:08 +05306860 if(pTimeInterval)
6861 {
6862 *pTimeInterval = pMac->fDeferIMPSTime * 1000; //usec
6863 }
Rashmi Ramanna68b309c2014-05-20 11:52:22 +05306864 pMac->deferImps = eANI_BOOLEAN_TRUE;
6865 return status;
6866 }
6867
Jeff Johnson295189b2012-06-20 16:38:30 -07006868 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6869 /*&& pMac->roam.configParam.impsSleepTime*/)
6870 {
6871 //Stop get result timer because idle scan gets scan result out of PE
6872 csrScanStopGetResultTimer(pMac);
6873 if(pTimeInterval)
6874 {
6875 *pTimeInterval = pMac->roam.configParam.impsSleepTime;
6876 }
6877 //pmcRequestImps take a period in millisecond unit.
6878 status = pmcRequestImps(pMac, pMac->roam.configParam.impsSleepTime / PAL_TIMER_TO_MS_UNIT, csrScanIMPSCallback, pMac);
6879 if(!HAL_STATUS_SUCCESS(status))
6880 {
6881 if(eHAL_STATUS_PMC_ALREADY_IN_IMPS != status)
6882 {
6883 //Do restart the timer if CSR thinks it cannot do IMPS
6884 if( !csrCheckPSReady( pMac ) )
6885 {
6886 if(pTimeInterval)
6887 {
6888 *pTimeInterval = 0;
6889 }
6890 //Set the restart flag to true because that idle scan
6891 //can be restarted even though the timer will not be running
6892 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6893 }
6894 else
6895 {
6896 //For not now, we do a quicker retry
6897 if(pTimeInterval)
6898 {
6899 *pTimeInterval = CSR_IDLE_SCAN_WAIT_TIME;
6900 }
6901 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006902 smsLog(pMac, LOGW, FL("call pmcRequestImps and it returns status code (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07006903 }
6904 else
6905 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006906 smsLog(pMac, LOGW, FL("already in IMPS"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006907 //Since CSR is the only module to request for IMPS. If it is already in IMPS, CSR assumes
6908 //the callback will be called in the future. Should not happen though.
6909 status = eHAL_STATUS_SUCCESS;
6910 pMac->scan.nIdleScanTimeGap = 0;
6911 }
6912 }
6913 else
6914 {
6915 //requested so let's reset the value
6916 pMac->scan.nIdleScanTimeGap = 0;
6917 }
6918 }
6919
6920 return (status);
6921}
6922
6923
6924eHalStatus csrScanStartIdleScan(tpAniSirGlobal pMac)
6925{
6926 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
6927 tANI_U32 nTime = 0;
6928
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006929 smsLog(pMac, LOGW, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006930 if(pMac->roam.configParam.IsIdleScanEnabled)
6931 {
6932 //stop bg scan first
6933 csrScanBGScanAbort(pMac);
6934 //Stop get result timer because idle scan gets scan result out of PE
6935 csrScanStopGetResultTimer(pMac);
6936 //Enable aging timer since idle scan is going on
6937 csrScanStartResultAgingTimer(pMac);
6938 }
6939 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_FALSE;
6940 status = csrScanTriggerIdleScan(pMac, &nTime);
6941 if(!HAL_STATUS_SUCCESS(status))
6942 {
6943 csrScanStartIdleScanTimer(pMac, nTime);
6944 }
6945
6946 return (status);
6947}
6948
6949
6950void csrScanCancelIdleScan(tpAniSirGlobal pMac)
6951{
6952 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6953 {
Agarwal Ashish5974ed32014-06-16 16:59:54 +05306954 if (vos_concurrent_open_sessions_running()) {
Jeff Johnson295189b2012-06-20 16:38:30 -07006955 return;
6956 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006957 smsLog(pMac, LOG1, " csrScanCancelIdleScan");
Jeff Johnson295189b2012-06-20 16:38:30 -07006958 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_TRUE;
6959 //Set the restart flag in case later on it is uncancelled
6960 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6961 csrScanStopIdleScanTimer(pMac);
6962 csrScanRemoveNotRoamingScanCommand(pMac);
6963 }
6964}
6965
6966
6967void csrScanIdleScanTimerHandler(void *pv)
6968{
6969 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6970 eHalStatus status;
6971 tANI_U32 nTime = 0;
6972
6973 smsLog(pMac, LOGW, " csrScanIdleScanTimerHandler called ");
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07006974 pmcResetImpsFailStatus (pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07006975 status = csrScanTriggerIdleScan(pMac, &nTime);
6976 if(!HAL_STATUS_SUCCESS(status) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan))
6977 {
6978 //Check whether it is time to actually do an idle scan
6979 if(pMac->scan.nIdleScanTimeGap >= pMac->roam.configParam.impsSleepTime)
6980 {
6981 pMac->scan.nIdleScanTimeGap = 0;
6982 csrScanIMPSCallback(pMac, eHAL_STATUS_SUCCESS);
6983 }
6984 else
6985 {
6986 csrScanStartIdleScanTimer(pMac, nTime);
6987 }
6988 }
Rashmi Ramanna68b309c2014-05-20 11:52:22 +05306989 if(pMac->deferImps)
6990 {
6991 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6992 pMac->deferImps = eANI_BOOLEAN_FALSE;
6993 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006994}
6995
6996
6997
6998
6999tANI_BOOLEAN csrScanRemoveNotRoamingScanCommand(tpAniSirGlobal pMac)
7000{
7001 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
7002 tListElem *pEntry, *pEntryTmp;
7003 tSmeCmd *pCommand;
7004 tDblLinkList localList;
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307005 tDblLinkList *pCmdList;
Jeff Johnson295189b2012-06-20 16:38:30 -07007006
7007 vos_mem_zero(&localList, sizeof(tDblLinkList));
7008 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
7009 {
7010 smsLog(pMac, LOGE, FL(" failed to open list"));
7011 return fRet;
7012 }
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307013 if (!pMac->fScanOffload)
7014 pCmdList = &pMac->sme.smeCmdPendingList;
7015 else
7016 pCmdList = &pMac->sme.smeScanCmdPendingList;
Jeff Johnson295189b2012-06-20 16:38:30 -07007017
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307018 csrLLLock(pCmdList);
7019 pEntry = csrLLPeekHead(pCmdList, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007020 while(pEntry)
7021 {
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307022 pEntryTmp = csrLLNext(pCmdList, pEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007023 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7024 if( eSmeCommandScan == pCommand->command )
7025 {
7026 switch( pCommand->u.scanCmd.reason )
7027 {
7028 case eCsrScanIdleScan:
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307029 if( csrLLRemoveEntry(pCmdList, pEntry, LL_ACCESS_NOLOCK) )
Jeff Johnson295189b2012-06-20 16:38:30 -07007030 {
7031 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
7032 }
7033 fRet = eANI_BOOLEAN_TRUE;
7034 break;
7035
7036 default:
7037 break;
7038 } //switch
7039 }
7040 pEntry = pEntryTmp;
7041 }
7042
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307043 csrLLUnlock(pCmdList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007044
7045 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
7046 {
7047 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7048 csrReleaseCommandScan( pMac, pCommand );
7049 }
7050
7051 csrLLClose(&localList);
7052
7053 return (fRet);
7054}
7055
7056
7057tANI_BOOLEAN csrScanRemoveFreshScanCommand(tpAniSirGlobal pMac, tANI_U8 sessionId)
7058{
7059 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
7060 tListElem *pEntry, *pEntryTmp;
7061 tSmeCmd *pCommand;
7062 tDblLinkList localList;
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307063 tDblLinkList *pCmdList;
Jeff Johnson295189b2012-06-20 16:38:30 -07007064
7065 vos_mem_zero(&localList, sizeof(tDblLinkList));
7066 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
7067 {
7068 smsLog(pMac, LOGE, FL(" failed to open list"));
7069 return fRet;
7070 }
7071
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307072 if (!pMac->fScanOffload)
7073 pCmdList = &pMac->sme.smeCmdPendingList;
7074 else
7075 pCmdList = &pMac->sme.smeScanCmdPendingList;
7076
7077 csrLLLock(pCmdList);
7078 pEntry = csrLLPeekHead(pCmdList, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007079 while(pEntry)
7080 {
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307081 pEntryTmp = csrLLNext(pCmdList, pEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007082 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7083 if( (eSmeCommandScan == pCommand->command) && (sessionId == pCommand->sessionId) )
7084 {
7085 switch(pCommand->u.scanCmd.reason)
7086 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07007087#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
7088 case eCsrScanGetLfrResult:
7089#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07007090 case eCsrScanGetResult:
7091 case eCsrScanSetBGScanParam:
7092 case eCsrScanBGScanAbort:
7093 case eCsrScanBGScanEnable:
7094 case eCsrScanGetScanChnInfo:
7095 break;
7096 default:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007097 smsLog (pMac, LOGW, "%s: -------- abort scan command reason = %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007098 __func__, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07007099 //The rest are fresh scan requests
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307100 if( csrLLRemoveEntry(pCmdList, pEntry, LL_ACCESS_NOLOCK) )
Jeff Johnson295189b2012-06-20 16:38:30 -07007101 {
7102 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
7103 }
7104 fRet = eANI_BOOLEAN_TRUE;
7105 break;
7106 }
7107 }
7108 pEntry = pEntryTmp;
7109 }
7110
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307111 csrLLUnlock(pCmdList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007112
7113 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
7114 {
7115 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7116 if (pCommand->u.scanCmd.callback)
7117 {
7118 /* User scan request is pending,
7119 * send response with status eCSR_SCAN_ABORT*/
7120 pCommand->u.scanCmd.callback(pMac,
7121 pCommand->u.scanCmd.pContext,
7122 pCommand->u.scanCmd.scanID,
7123 eCSR_SCAN_ABORT);
7124 }
7125 csrReleaseCommandScan( pMac, pCommand );
7126 }
7127 csrLLClose(&localList);
7128
7129 return (fRet);
7130}
7131
7132
7133void csrReleaseScanCommand(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
7134{
7135 eCsrScanReason reason = pCommand->u.scanCmd.reason;
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307136 tANI_BOOLEAN status;
7137
7138 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07007139 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307140 tANI_U32 i;
7141 for(i = 0; i < CSR_ROAM_SESSION_MAX; i++)
7142 csrRoamStateChange(pMac, pCommand->u.scanCmd.lastRoamState[i], i);
7143 }
7144 else
7145 {
7146 csrRoamStateChange(pMac,
7147 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId],
7148 pCommand->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07007149 }
7150
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307151 csrScanCallCallback(pMac, pCommand, scanStatus);
Jeff Johnson295189b2012-06-20 16:38:30 -07007152
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007153 smsLog(pMac, LOG3, " Remove Scan command reason = %d", reason);
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307154 if (pMac->fScanOffload)
7155 {
7156 status = csrLLRemoveEntry(&pMac->sme.smeScanCmdActiveList,
7157 &pCommand->Link, LL_ACCESS_LOCK);
7158 }
7159 else
7160 {
7161 status = csrLLRemoveEntry(&pMac->sme.smeCmdActiveList,
7162 &pCommand->Link, LL_ACCESS_LOCK);
7163 }
7164
7165 if(status)
Jeff Johnson295189b2012-06-20 16:38:30 -07007166 {
7167 csrReleaseCommandScan( pMac, pCommand );
7168 }
7169 else
7170 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307171 smsLog(pMac, LOGE,
7172 " ********csrReleaseScanCommand cannot release command reason %d",
7173 pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07007174 }
7175}
7176
7177
7178eHalStatus csrScanGetPMKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
7179 tPmkidCandidateInfo *pPmkidList, tANI_U32 *pNumItems )
7180{
7181 eHalStatus status = eHAL_STATUS_SUCCESS;
7182 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
7183
Jeff Johnson32d95a32012-09-10 13:15:23 -07007184 if(!pSession)
7185 {
7186 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
7187 return eHAL_STATUS_FAILURE;
7188 }
7189
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007190 smsLog(pMac, LOGW, " pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07007191 csrResetPMKIDCandidateList(pMac, sessionId);
7192 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
7193 {
7194 tCsrScanResultFilter *pScanFilter;
7195 tCsrScanResultInfo *pScanResult;
7196 tScanResultHandle hBSSList;
7197 tANI_U32 nItems = *pNumItems;
7198
7199 *pNumItems = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05307200 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
7201 if ( NULL == pScanFilter )
7202 status = eHAL_STATUS_FAILURE;
7203 else
Jeff Johnson295189b2012-06-20 16:38:30 -07007204 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307205 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007206 //Here is the profile we need to connect to
7207 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
7208 if(HAL_STATUS_SUCCESS(status))
7209 {
7210 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
7211 if(HAL_STATUS_SUCCESS(status))
7212 {
7213 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumPmkidCandidate < nItems))
7214 {
7215 //NumPmkidCandidate adds up here
7216 csrProcessBSSDescForPMKIDList(pMac, &pScanResult->BssDescriptor,
7217 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
7218 }
7219 if(pSession->NumPmkidCandidate)
7220 {
7221 *pNumItems = pSession->NumPmkidCandidate;
Kiet Lam64c1b492013-07-12 13:56:44 +05307222 vos_mem_copy(pPmkidList, pSession->PmkidCandidateInfo,
7223 pSession->NumPmkidCandidate * sizeof(tPmkidCandidateInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07007224 }
7225 csrScanResultPurge(pMac, hBSSList);
7226 }//Have scan result
7227 csrFreeScanFilter(pMac, pScanFilter);
7228 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307229 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07007230 }
7231 }
7232
7233 return (status);
7234}
7235
7236
7237
7238#ifdef FEATURE_WLAN_WAPI
7239eHalStatus csrScanGetBKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
7240 tBkidCandidateInfo *pBkidList, tANI_U32 *pNumItems )
7241{
7242 eHalStatus status = eHAL_STATUS_SUCCESS;
7243 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
7244
Jeff Johnson32d95a32012-09-10 13:15:23 -07007245 if(!pSession)
7246 {
7247 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
7248 return eHAL_STATUS_FAILURE;
7249 }
7250
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007251 smsLog(pMac, LOGW, " pMac->scan.NumBkidCandidate = %d", pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07007252 csrResetBKIDCandidateList(pMac, sessionId);
7253 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
7254 {
7255 tCsrScanResultFilter *pScanFilter;
7256 tCsrScanResultInfo *pScanResult;
7257 tScanResultHandle hBSSList;
7258 tANI_U32 nItems = *pNumItems;
7259 *pNumItems = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05307260 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
7261 if ( NULL == pScanFilter )
7262 status = eHAL_STATUS_FAILURE;
7263 else
Jeff Johnson295189b2012-06-20 16:38:30 -07007264 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307265 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007266 //Here is the profile we need to connect to
7267 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
7268 if(HAL_STATUS_SUCCESS(status))
7269 {
7270 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
7271 if(HAL_STATUS_SUCCESS(status))
7272 {
7273 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumBkidCandidate < nItems))
7274 {
7275 //pMac->scan.NumBkidCandidate adds up here
7276 csrProcessBSSDescForBKIDList(pMac, &pScanResult->BssDescriptor,
7277 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
7278
7279 }
7280 if(pSession->NumBkidCandidate)
7281 {
7282 *pNumItems = pSession->NumBkidCandidate;
Kiet Lam64c1b492013-07-12 13:56:44 +05307283 vos_mem_copy(pBkidList, pSession->BkidCandidateInfo, pSession->NumBkidCandidate * sizeof(tBkidCandidateInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07007284 }
7285 csrScanResultPurge(pMac, hBSSList);
7286 }//Have scan result
7287 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307288 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07007289 }
7290 }
7291
7292 return (status);
7293}
7294#endif /* FEATURE_WLAN_WAPI */
7295
7296
7297
7298//This function is usually used for BSSs that suppresses SSID so the profile
7299//shall have one and only one SSID
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007300eHalStatus csrScanForSSID(tpAniSirGlobal pMac, tANI_U32 sessionId, tCsrRoamProfile *pProfile, tANI_U32 roamId, tANI_BOOLEAN notify)
Jeff Johnson295189b2012-06-20 16:38:30 -07007301{
7302 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
7303 tSmeCmd *pScanCmd = NULL;
7304 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
7305 tANI_U8 index = 0;
7306 tANI_U32 numSsid = pProfile->SSIDs.numOfSSIDs;
7307
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007308 smsLog(pMac, LOG2, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007309 //For WDS, we use the index 0. There must be at least one in there
7310 if( CSR_IS_WDS_STA( pProfile ) && numSsid )
7311 {
7312 numSsid = 1;
7313 }
7314 if(pMac->scan.fScanEnable && ( numSsid == 1 ) )
7315 {
7316 do
7317 {
7318 pScanCmd = csrGetCommandBuffer(pMac);
7319 if(!pScanCmd)
7320 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007321 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007322 break;
7323 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307324 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
7325 pScanCmd->u.scanCmd.pToRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
7326 if ( NULL == pScanCmd->u.scanCmd.pToRoamProfile )
krunal soni587bf012014-02-04 12:35:11 -08007327 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307328 status = eHAL_STATUS_FAILURE;
krunal soni587bf012014-02-04 12:35:11 -08007329 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307330 else
krunal soni587bf012014-02-04 12:35:11 -08007331 {
7332 status = csrRoamCopyProfile(pMac, pScanCmd->u.scanCmd.pToRoamProfile, pProfile);
7333 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007334 if(!HAL_STATUS_SUCCESS(status))
7335 break;
7336 pScanCmd->u.scanCmd.roamId = roamId;
7337 pScanCmd->command = eSmeCommandScan;
Jeff Johnsone7245742012-09-05 17:12:55 -07007338 pScanCmd->sessionId = (tANI_U8)sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07007339 pScanCmd->u.scanCmd.callback = NULL;
7340 pScanCmd->u.scanCmd.pContext = NULL;
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007341 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 -07007342 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Kiet Lam64c1b492013-07-12 13:56:44 +05307343 vos_mem_set(&pScanCmd->u.scanCmd.u.scanRequest, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007344 pScanCmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Jeff Johnson295189b2012-06-20 16:38:30 -07007345 pScanCmd->u.scanCmd.u.scanRequest.BSSType = pProfile->BSSType;
Jeff Johnsone7245742012-09-05 17:12:55 -07007346 // To avoid 11b rate in probe request Set p2pSearch flag as 1 for P2P Client Mode
7347 if(VOS_P2P_CLIENT_MODE == pProfile->csrPersona)
7348 {
7349 pScanCmd->u.scanCmd.u.scanRequest.p2pSearch = 1;
7350 }
Agarwal Ashish4f616132013-12-30 23:32:50 +05307351 if(pProfile->nAddIEScanLength)
Jeff Johnsone7245742012-09-05 17:12:55 -07007352 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307353 pScanCmd->u.scanCmd.u.scanRequest.pIEField = vos_mem_malloc(
7354 pProfile->nAddIEScanLength);
7355 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.pIEField )
7356 status = eHAL_STATUS_FAILURE;
7357 else
7358 status = eHAL_STATUS_SUCCESS;
7359 vos_mem_set(pScanCmd->u.scanCmd.u.scanRequest.pIEField,
7360 pProfile->nAddIEScanLength, 0);
7361 if (HAL_STATUS_SUCCESS(status))
Jeff Johnsone7245742012-09-05 17:12:55 -07007362 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307363 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.pIEField,
Agarwal Ashish4f616132013-12-30 23:32:50 +05307364 pProfile->addIEScan, pProfile->nAddIEScanLength);
Jeff Johnsone7245742012-09-05 17:12:55 -07007365 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = pProfile->nAddIEScanLength;
7366 }
7367 else
7368 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007369 smsLog(pMac, LOGE, "No memory for scanning IE fields");
Jeff Johnsone7245742012-09-05 17:12:55 -07007370 }
7371 } //Allocate memory for IE field
7372 else
7373 {
7374 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = 0;
7375 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07007376 /* For one channel be good enpugh time to receive beacon atleast */
7377 if( 1 == pProfile->ChannelInfo.numOfChannels )
7378 {
7379 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime = MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7380 pScanCmd->u.scanCmd.u.scanRequest.minChnTime = MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7381 }
7382 else
7383 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307384 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime =
7385 pMac->roam.configParam.nActiveMaxChnTime;
7386 pScanCmd->u.scanCmd.u.scanRequest.minChnTime =
7387 pMac->roam.configParam.nActiveMinChnTime;
Jeff Johnson32d95a32012-09-10 13:15:23 -07007388 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307389 pScanCmd->u.scanCmd.u.scanRequest.maxChnTimeBtc =
7390 pMac->roam.configParam.nActiveMaxChnTimeBtc;
7391 pScanCmd->u.scanCmd.u.scanRequest.minChnTimeBtc =
7392 pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07007393 if(pProfile->BSSIDs.numOfBSSIDs == 1)
7394 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307395 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.bssid,
7396 pProfile->BSSIDs.bssid, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07007397 }
7398 else
7399 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307400 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.bssid, bAddr, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07007401 }
7402 if(pProfile->ChannelInfo.numOfChannels)
7403 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307404 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(
7405 sizeof(*pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
7406 * pProfile->ChannelInfo.numOfChannels);
7407 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
7408 status = eHAL_STATUS_FAILURE;
7409 else
7410 status = eHAL_STATUS_SUCCESS;
7411 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
7412 if(HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07007413 {
7414 csrRoamIsChannelValid(pMac, pProfile->ChannelInfo.ChannelList[0]);
7415 for(index = 0; index < pProfile->ChannelInfo.numOfChannels; index++)
7416 {
7417 if(csrRoamIsValidChannel(pMac, pProfile->ChannelInfo.ChannelList[index]))
7418 {
7419 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels]
7420 = pProfile->ChannelInfo.ChannelList[index];
7421 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels++;
7422 }
7423 else
7424 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007425 smsLog(pMac, LOGW, FL("process a channel (%d) that is invalid"), pProfile->ChannelInfo.ChannelList[index]);
Jeff Johnson295189b2012-06-20 16:38:30 -07007426 }
7427
7428 }
7429 }
7430 else
7431 {
7432 break;
7433 }
7434
7435 }
7436 else
7437 {
7438 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
7439 }
7440 if(pProfile->SSIDs.numOfSSIDs)
7441 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307442 pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList = vos_mem_malloc(
7443 pProfile->SSIDs.numOfSSIDs * sizeof(tCsrSSIDInfo));
7444 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList )
7445 status = eHAL_STATUS_FAILURE;
7446 else
7447 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07007448 if(!HAL_STATUS_SUCCESS(status))
7449 {
7450 break;
7451 }
7452 pScanCmd->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 1;
Kiet Lam64c1b492013-07-12 13:56:44 +05307453 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList,
7454 pProfile->SSIDs.SSIDList, sizeof(tCsrSSIDInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07007455 }
7456 //Start process the command
7457 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
7458 if( !HAL_STATUS_SUCCESS( status ) )
7459 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007460 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07007461 break;
7462 }
7463 }while(0);
7464 if(!HAL_STATUS_SUCCESS(status))
7465 {
7466 if(pScanCmd)
7467 {
7468 csrReleaseCommandScan(pMac, pScanCmd);
7469 //TODO:free the memory that is allocated in this function
7470 }
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007471 if(notify)
7472 {
Jeff Johnson295189b2012-06-20 16:38:30 -07007473 csrRoamCallCallback(pMac, sessionId, NULL, roamId, eCSR_ROAM_FAILED, eCSR_ROAM_RESULT_FAILURE);
7474 }
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007475 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007476 }//valid
7477 else
7478 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007479 smsLog(pMac, LOGE, FL("cannot scan because scanEnable (%d) or numSSID (%d) is invalid"),
Jeff Johnson295189b2012-06-20 16:38:30 -07007480 pMac->scan.fScanEnable, pProfile->SSIDs.numOfSSIDs);
7481 }
7482
7483 return (status);
7484}
7485
7486
7487//Issue a scan base on the new capability infomation
7488//This should only happen when the associated AP changes its capability.
7489//After this scan is done, CSR reroams base on the new scan results
7490eHalStatus csrScanForCapabilityChange(tpAniSirGlobal pMac, tSirSmeApNewCaps *pNewCaps)
7491{
7492 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
7493 tSmeCmd *pScanCmd = NULL;
7494
7495 if(pNewCaps)
7496 {
7497 do
7498 {
7499 pScanCmd = csrGetCommandBuffer(pMac);
7500 if(!pScanCmd)
7501 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007502 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007503 status = eHAL_STATUS_RESOURCES;
7504 break;
7505 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307506 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007507 status = eHAL_STATUS_SUCCESS;
7508 pScanCmd->u.scanCmd.roamId = 0;
7509 pScanCmd->command = eSmeCommandScan;
7510 pScanCmd->u.scanCmd.callback = NULL;
7511 pScanCmd->u.scanCmd.pContext = NULL;
7512 pScanCmd->u.scanCmd.reason = eCsrScanForCapsChange;
7513 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
7514 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
7515 if( !HAL_STATUS_SUCCESS( status ) )
7516 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007517 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07007518 break;
7519 }
7520 }while(0);
7521 if(!HAL_STATUS_SUCCESS(status))
7522 {
7523 if(pScanCmd)
7524 {
7525 csrReleaseCommandScan(pMac, pScanCmd);
7526 }
7527 }
7528 }
7529
7530 return (status);
7531}
7532
7533
7534
7535void csrInitBGScanChannelList(tpAniSirGlobal pMac)
7536{
7537 tANI_U32 len = CSR_MIN(sizeof(pMac->roam.validChannelList), sizeof(pMac->scan.bgScanChannelList));
7538
Kiet Lam64c1b492013-07-12 13:56:44 +05307539 vos_mem_set(pMac->scan.bgScanChannelList, len, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007540 pMac->scan.numBGScanChannel = 0;
7541
7542 if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
7543 {
7544 pMac->roam.numValidChannels = len;
7545 pMac->scan.numBGScanChannel = (tANI_U8)CSR_MIN(len, WNI_CFG_BG_SCAN_CHANNEL_LIST_LEN);
Kiet Lam64c1b492013-07-12 13:56:44 +05307546 vos_mem_copy(pMac->scan.bgScanChannelList, pMac->roam.validChannelList,
7547 pMac->scan.numBGScanChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07007548 csrSetBGScanChannelList(pMac, pMac->scan.bgScanChannelList, pMac->scan.numBGScanChannel);
7549 }
7550}
7551
7552
7553//This function return TRUE if background scan channel list is adjusted.
7554//this function will only shrink the background scan channel list
7555tANI_BOOLEAN csrAdjustBGScanChannelList(tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels,
7556 tANI_U8 *pAdjustChannels, tANI_U8 *pNumAdjustChannels)
7557{
7558 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
7559 tANI_U8 i, j, count = *pNumAdjustChannels;
7560
7561 i = 0;
7562 while(i < count)
7563 {
7564 for(j = 0; j < NumChannels; j++)
7565 {
7566 if(pChannelList[j] == pAdjustChannels[i])
7567 break;
7568 }
7569 if(j == NumChannels)
7570 {
7571 //This channel is not in the list, remove it
7572 fRet = eANI_BOOLEAN_TRUE;
7573 count--;
7574 if(count - i)
7575 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307576 vos_mem_copy(&pAdjustChannels[i], &pAdjustChannels[i+1], count - i);
Jeff Johnson295189b2012-06-20 16:38:30 -07007577 }
7578 else
7579 {
7580 //already remove the last one. Done.
7581 break;
7582 }
7583 }
7584 else
7585 {
7586 i++;
7587 }
7588 }//while(i<count)
7589 *pNumAdjustChannels = count;
7590
7591 return (fRet);
7592}
7593
7594
7595//Get the list of the base channels to scan for passively 11d info
7596eHalStatus csrScanGetSupportedChannels( tpAniSirGlobal pMac )
7597{
7598 eHalStatus status = eHAL_STATUS_SUCCESS;
7599 int n = WNI_CFG_VALID_CHANNEL_LIST_LEN;
7600
7601 status = vos_nv_getSupportedChannels( pMac->scan.baseChannels.channelList, &n, NULL, NULL );
7602 if( HAL_STATUS_SUCCESS(status) )
7603 {
7604 pMac->scan.baseChannels.numChannels = (tANI_U8)n;
7605 }
7606 else
7607 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007608 smsLog( pMac, LOGE, FL(" failed") );
Jeff Johnson295189b2012-06-20 16:38:30 -07007609 pMac->scan.baseChannels.numChannels = 0;
7610 }
7611
7612 return ( status );
7613}
7614
7615//This function use the input pChannelList to validate the current saved channel list
7616eHalStatus csrSetBGScanChannelList( tpAniSirGlobal pMac, tANI_U8 *pAdjustChannels, tANI_U8 NumAdjustChannels)
7617{
7618 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumAdjustChannels;
7619
7620 return (ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pAdjustChannels, dataLen, NULL, eANI_BOOLEAN_FALSE));
7621}
7622
7623
7624void csrSetCfgValidChannelList( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels )
7625{
7626 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumChannels;
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05307627 eHalStatus status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007628
Mihir Shete31c435d2014-02-12 13:13:34 +05307629 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
7630 "%s: dump valid channel list(NumChannels(%d))",
7631 __func__,NumChannels);
7632 VOS_TRACE_HEX_DUMP(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
7633 pChannelList, NumChannels);
7634
Jeff Johnson295189b2012-06-20 16:38:30 -07007635 ccmCfgSetStr(pMac, WNI_CFG_VALID_CHANNEL_LIST, pChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
Leela Venkata Kiran Kumar Reddy Chiralac6663f72014-02-03 21:04:58 -08007636#ifdef QCA_WIFI_2_0
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05307637 if (pMac->fScanOffload)
7638 {
7639 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
7640 "Scan offload is enabled, update default chan list");
Leela Venkata Kiran Kumar Reddy Chiralac6663f72014-02-03 21:04:58 -08007641 status = csrUpdateChannelList(pMac);
7642 }
7643#else
7644 status = csrUpdateChannelList(pMac);
7645#endif
7646
7647 if (eHAL_STATUS_SUCCESS != status)
7648 {
7649 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR,
7650 "failed to update the supported channel list");
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05307651 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007652 return;
7653}
7654
7655
7656
7657/*
7658 * The Tx power limits are saved in the cfg for future usage.
7659 */
7660void csrSaveTxPowerToCfg( tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 cfgId )
7661{
7662 tListElem *pEntry;
7663 tANI_U32 cbLen = 0, dataLen;
7664 tCsrChannelPowerInfo *pChannelSet;
7665 tANI_U32 idx;
7666 tSirMacChanInfo *pChannelPowerSet;
7667 tANI_U8 *pBuf = NULL;
7668
7669 //allocate maximum space for all channels
7670 dataLen = WNI_CFG_VALID_CHANNEL_LIST_LEN * sizeof(tSirMacChanInfo);
Kiet Lam64c1b492013-07-12 13:56:44 +05307671 if ( (pBuf = vos_mem_malloc(dataLen)) != NULL )
Jeff Johnson295189b2012-06-20 16:38:30 -07007672 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307673 vos_mem_set(pBuf, dataLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007674 pChannelPowerSet = (tSirMacChanInfo *)(pBuf);
7675
7676 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
7677 // write the tuples (startChan, numChan, txPower) for each channel found in the channel power list.
7678 while( pEntry )
7679 {
7680 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
7681 if ( 1 != pChannelSet->interChannelOffset )
7682 {
7683 // we keep the 5G channel sets internally with an interchannel offset of 4. Expand these
7684 // to the right format... (inter channel offset of 1 is the only option for the triplets
7685 // that 11d advertises.
7686 if ((cbLen + (pChannelSet->numChannels * sizeof(tSirMacChanInfo))) >= dataLen)
7687 {
7688 // expanding this entry will overflow our allocation
7689 smsLog(pMac, LOGE,
7690 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007691 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07007692 pChannelSet->firstChannel,
7693 pChannelSet->numChannels,
7694 pChannelSet->interChannelOffset);
7695 break;
7696 }
7697
7698 for( idx = 0; idx < pChannelSet->numChannels; idx++ )
7699 {
7700 pChannelPowerSet->firstChanNum = (tSirMacChanNum)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007701 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07007702 pChannelPowerSet->numChannels = 1;
Jeff Johnson295189b2012-06-20 16:38:30 -07007703 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007704 smsLog(pMac, LOG3, " Setting Max Transmit Power %d", pChannelPowerSet->maxTxPower);
Jeff Johnson295189b2012-06-20 16:38:30 -07007705 cbLen += sizeof( tSirMacChanInfo );
7706 pChannelPowerSet++;
7707 }
7708 }
7709 else
7710 {
7711 if (cbLen >= dataLen)
7712 {
7713 // this entry will overflow our allocation
7714 smsLog(pMac, LOGE,
7715 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007716 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07007717 pChannelSet->firstChannel,
7718 pChannelSet->numChannels,
7719 pChannelSet->interChannelOffset);
7720 break;
7721 }
7722 pChannelPowerSet->firstChanNum = pChannelSet->firstChannel;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007723 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07007724 pChannelPowerSet->numChannels = pChannelSet->numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -07007725 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007726 smsLog(pMac, LOG3, " Setting Max Transmit Power %d, nTxPower %d", pChannelPowerSet->maxTxPower,pMac->roam.configParam.nTxPowerCap );
Jeff Johnson295189b2012-06-20 16:38:30 -07007727
7728
7729 cbLen += sizeof( tSirMacChanInfo );
7730 pChannelPowerSet++;
7731 }
7732
7733 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
7734 }
7735
7736 if(cbLen)
7737 {
7738 ccmCfgSetStr(pMac, cfgId, (tANI_U8 *)pBuf, cbLen, NULL, eANI_BOOLEAN_FALSE);
7739 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307740 vos_mem_free(pBuf);
Jeff Johnson295189b2012-06-20 16:38:30 -07007741 }//Allocate memory
7742}
7743
7744
7745void csrSetCfgCountryCode( tpAniSirGlobal pMac, tANI_U8 *countryCode )
7746{
7747 tANI_U8 cc[WNI_CFG_COUNTRY_CODE_LEN];
7748 ///v_REGDOMAIN_t DomainId;
7749
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007750 smsLog( pMac, LOG3, "Setting Country Code in Cfg from csrSetCfgCountryCode %s",countryCode );
Kiet Lam64c1b492013-07-12 13:56:44 +05307751 vos_mem_copy(cc, countryCode, WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07007752
7753 // don't program the bogus country codes that we created for Korea in the MAC. if we see
7754 // the bogus country codes, program the MAC with the right country code.
7755 if ( ( 'K' == countryCode[ 0 ] && '1' == countryCode[ 1 ] ) ||
7756 ( 'K' == countryCode[ 0 ] && '2' == countryCode[ 1 ] ) ||
7757 ( 'K' == countryCode[ 0 ] && '3' == countryCode[ 1 ] ) ||
7758 ( 'K' == countryCode[ 0 ] && '4' == countryCode[ 1 ] ) )
7759 {
7760 // replace the alternate Korea country codes, 'K1', 'K2', .. with 'KR' for Korea
7761 cc[ 1 ] = 'R';
7762 }
7763 ccmCfgSetStr(pMac, WNI_CFG_COUNTRY_CODE, cc, WNI_CFG_COUNTRY_CODE_LEN, NULL, eANI_BOOLEAN_FALSE);
7764
7765 //Need to let HALPHY know about the current domain so it can apply some
7766 //domain-specific settings (TX filter...)
7767 /*if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(pMac, cc, &DomainId)))
7768 {
7769 halPhySetRegDomain(pMac, DomainId);
7770 }*/
7771}
7772
7773
7774
7775eHalStatus csrGetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pBuf, tANI_U8 *pbLen)
7776{
7777 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
7778 tANI_U32 len;
7779
7780 if(pBuf && pbLen && (*pbLen >= WNI_CFG_COUNTRY_CODE_LEN))
7781 {
7782 len = *pbLen;
7783 status = ccmCfgGetStr(pMac, WNI_CFG_COUNTRY_CODE, pBuf, &len);
7784 if(HAL_STATUS_SUCCESS(status))
7785 {
7786 *pbLen = (tANI_U8)len;
7787 }
7788 }
7789
7790 return (status);
7791}
7792
7793
7794void csrSetCfgScanControlList( tpAniSirGlobal pMac, tANI_U8 *countryCode, tCsrChannel *pChannelList )
7795{
7796 tANI_U8 i, j;
7797 tANI_BOOLEAN found=FALSE;
7798 tANI_U8 *pControlList = NULL;
7799 tANI_U32 len = WNI_CFG_SCAN_CONTROL_LIST_LEN;
7800
Kiet Lam64c1b492013-07-12 13:56:44 +05307801 if ( (pControlList = vos_mem_malloc(WNI_CFG_SCAN_CONTROL_LIST_LEN)) != NULL )
Jeff Johnson295189b2012-06-20 16:38:30 -07007802 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307803 vos_mem_set((void *)pControlList, WNI_CFG_SCAN_CONTROL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007804 if(HAL_STATUS_SUCCESS(ccmCfgGetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, &len)))
7805 {
7806 for (i = 0; i < pChannelList->numChannels; i++)
7807 {
7808 for (j = 0; j < len; j += 2)
7809 {
7810 if (pControlList[j] == pChannelList->channelList[i])
7811 {
7812 found = TRUE;
7813 break;
7814 }
7815 }
7816
7817 if (found) // insert a pair(channel#, flag)
7818 {
Gopichand Nakkala392cbc12013-05-28 16:15:00 +05307819 pControlList[j+1] = csrGetScanType(pMac, pControlList[j]);
Jeff Johnson295189b2012-06-20 16:38:30 -07007820 found = FALSE; // reset the flag
7821 }
7822
7823 }
7824
Mihir Shete31c435d2014-02-12 13:13:34 +05307825 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
7826 "%s: dump scan control list",__func__);
7827 VOS_TRACE_HEX_DUMP(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
7828 pControlList, len);
7829
Jeff Johnson295189b2012-06-20 16:38:30 -07007830 ccmCfgSetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, len, NULL, eANI_BOOLEAN_FALSE);
7831 }//Successfully getting scan control list
Kiet Lam64c1b492013-07-12 13:56:44 +05307832 vos_mem_free(pControlList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007833 }//AllocateMemory
7834}
7835
7836
7837//if bgPeriod is 0, background scan is disabled. It is in millisecond units
7838eHalStatus csrSetCfgBackgroundScanPeriod(tpAniSirGlobal pMac, tANI_U32 bgPeriod)
7839{
7840 return (ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, bgPeriod, (tCcmCfgSetCallback) csrScanCcmCfgSetCallback, eANI_BOOLEAN_FALSE));
7841}
7842
7843
7844void csrScanCcmCfgSetCallback(tHalHandle hHal, tANI_S32 result)
7845{
7846 tListElem *pEntry = NULL;
7847 tSmeCmd *pCommand = NULL;
7848 tpAniSirGlobal pMac = PMAC_STRUCT( hHal );
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307849 tDblLinkList *pCmdList ;
7850
7851 if (!pMac->fScanOffload)
7852 pCmdList = &pMac->sme.smeCmdActiveList;
7853 else
7854 pCmdList = &pMac->sme.smeScanCmdActiveList;
7855
7856 pEntry = csrLLPeekHead( pCmdList, LL_ACCESS_LOCK );
Jeff Johnson295189b2012-06-20 16:38:30 -07007857 if ( pEntry )
7858 {
7859 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7860 if ( eSmeCommandScan == pCommand->command )
7861 {
7862 eCsrScanStatus scanStatus = (CCM_IS_RESULT_SUCCESS(result)) ? eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
7863 csrReleaseScanCommand(pMac, pCommand, scanStatus);
7864 }
7865 else
7866 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007867 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
Jeff Johnson295189b2012-06-20 16:38:30 -07007868 }
7869 }
7870 smeProcessPendingQueue( pMac );
7871}
7872
7873eHalStatus csrProcessSetBGScanParam(tpAniSirGlobal pMac, tSmeCmd *pCommand)
7874{
7875 eHalStatus status;
7876 tCsrBGScanRequest *pScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
7877 tANI_U32 dataLen = sizeof( tANI_U8 ) * pScanReq->ChannelInfo.numOfChannels;
7878
7879 //***setcfg for background scan channel list
7880 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MINIMUM_CHANNEL_TIME, pScanReq->minChnTime, NULL, eANI_BOOLEAN_FALSE);
7881 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MAXIMUM_CHANNEL_TIME, pScanReq->maxChnTime, NULL, eANI_BOOLEAN_FALSE);
7882 //Not set the background scan interval if not connected because bd scan should not be run if not connected
7883 if(!csrIsAllSessionDisconnected(pMac))
7884 {
7885 //If disbaling BG scan here, we need to stop aging as well
7886 if(pScanReq->scanInterval == 0)
7887 {
7888 //Stop aging because no new result is coming in
7889 csrScanStopResultAgingTimer(pMac);
7890 }
7891
7892#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
7893 {
7894 vos_log_scan_pkt_type *pScanLog = NULL;
7895
7896 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
7897 if(pScanLog)
7898 {
7899 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
7900 pScanLog->minChnTime = (v_U8_t)pScanReq->minChnTime;
7901 pScanLog->maxChnTime = (v_U8_t)pScanReq->maxChnTime;
7902 pScanLog->timeBetweenBgScan = (v_U8_t)pScanReq->scanInterval;
7903 pScanLog->numChannel = pScanReq->ChannelInfo.numOfChannels;
7904 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
7905 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307906 vos_mem_copy(pScanLog->channels,
7907 pScanReq->ChannelInfo.ChannelList,
7908 pScanLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07007909 }
7910 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
7911 }
7912 }
7913#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
7914
7915 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, pScanReq->scanInterval, NULL, eANI_BOOLEAN_FALSE);
7916 }
7917 else
7918 {
7919 //No need to stop aging because IDLE scan is still running
7920 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, 0, NULL, eANI_BOOLEAN_FALSE);
7921 }
7922
7923 if(pScanReq->SSID.length > WNI_CFG_SSID_LEN)
7924 {
7925 pScanReq->SSID.length = WNI_CFG_SSID_LEN;
7926 }
7927
7928 status = ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pScanReq->ChannelInfo.ChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
7929 status = ccmCfgSetStr(pMac, WNI_CFG_SSID, (tANI_U8 *)pScanReq->SSID.ssId, pScanReq->SSID.length, NULL, eANI_BOOLEAN_FALSE);
7930
7931
7932
7933 return (status);
7934}
7935
7936
c_hpothua3d45d52015-01-05 14:11:17 +05307937tSirAbortScanStatus csrScanAbortMacScan(tpAniSirGlobal pMac,
7938 tANI_U8 sessionId,
7939 eCsrAbortReason reason)
Jeff Johnson295189b2012-06-20 16:38:30 -07007940{
c_hpothua3d45d52015-01-05 14:11:17 +05307941 tSirAbortScanStatus abortScanStatus = eSIR_ABORT_ACTIVE_SCAN_LIST_EMPTY;
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307942 tSirSmeScanAbortReq *pMsg;
Jeff Johnson295189b2012-06-20 16:38:30 -07007943 tANI_U16 msgLen;
7944 tListElem *pEntry;
7945 tSmeCmd *pCommand;
7946
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307947 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07007948 {
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307949#ifdef WLAN_AP_STA_CONCURRENCY
7950 csrLLLock(&pMac->scan.scanCmdPendingList);
7951 while(NULL !=
7952 (pEntry = csrLLRemoveHead(&pMac->scan.scanCmdPendingList,
7953 LL_ACCESS_NOLOCK)))
7954 {
Jeff Johnson295189b2012-06-20 16:38:30 -07007955
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307956 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7957 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
7958 }
7959 csrLLUnlock(&pMac->scan.scanCmdPendingList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007960#endif
7961
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307962 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
7963 csrRemoveCmdFromPendingList( pMac, &pMac->roam.roamCmdPendingList, eSmeCommandScan);
7964 csrRemoveCmdFromPendingList( pMac, &pMac->sme.smeCmdPendingList, eSmeCommandScan);
7965 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
7966
7967 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
7968 }
7969 else
7970 {
7971 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
7972 csrRemoveCmdWithSessionIdFromPendingList(pMac,
7973 sessionId,
7974 &pMac->sme.smeScanCmdPendingList,
7975 eSmeCommandScan);
7976 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
7977
7978 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
7979 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007980
7981 //We need to abort scan only if we are scanning
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307982 if(NULL != pEntry)
Jeff Johnson295189b2012-06-20 16:38:30 -07007983 {
7984 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307985 if(eSmeCommandScan == pCommand->command &&
7986 pCommand->sessionId == sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07007987 {
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307988 msgLen = (tANI_U16)(sizeof(tSirSmeScanAbortReq));
Kiet Lam64c1b492013-07-12 13:56:44 +05307989 pMsg = vos_mem_malloc(msgLen);
7990 if ( NULL == pMsg )
Jeff Johnson295189b2012-06-20 16:38:30 -07007991 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307992 smsLog(pMac, LOGE, FL("Failed to allocate memory for SmeScanAbortReq"));
c_hpothua3d45d52015-01-05 14:11:17 +05307993 abortScanStatus = eSIR_ABORT_SCAN_FAILURE;
Kiet Lam64c1b492013-07-12 13:56:44 +05307994 }
7995 else
7996 {
Srinivas, Dasari187ca4e2014-02-07 12:40:09 +05307997 if(reason == eCSR_SCAN_ABORT_DUE_TO_BAND_CHANGE)
7998 {
7999 pCommand->u.scanCmd.abortScanDueToBandChange
8000 = eANI_BOOLEAN_TRUE;
8001 }
Kiet Lam64c1b492013-07-12 13:56:44 +05308002 vos_mem_set((void *)pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008003 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_ABORT_IND);
8004 pMsg->msgLen = pal_cpu_to_be16(msgLen);
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308005 pMsg->sessionId = sessionId;
c_hpothua3d45d52015-01-05 14:11:17 +05308006 if (eHAL_STATUS_SUCCESS != palSendMBMessage(pMac->hHdd, pMsg))
8007 {
8008 smsLog(pMac, LOGE,
8009 FL("Failed to post eWNI_SME_SCAN_ABORT_IND"));
8010 abortScanStatus = eSIR_ABORT_SCAN_FAILURE;
8011 }
8012 else
8013 {
8014 abortScanStatus = eSIR_ABORT_ACTIVE_SCAN_LIST_NOT_EMPTY;
8015 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008016 }
8017 }
8018 }
8019
c_hpothua3d45d52015-01-05 14:11:17 +05308020 return(abortScanStatus);
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308021}
8022
8023void csrRemoveCmdWithSessionIdFromPendingList(tpAniSirGlobal pMac,
8024 tANI_U8 sessionId,
8025 tDblLinkList *pList,
8026 eSmeCommandType commandType)
8027{
8028 tDblLinkList localList;
8029 tListElem *pEntry;
8030 tSmeCmd *pCommand;
8031 tListElem *pEntryToRemove;
8032
8033 vos_mem_zero(&localList, sizeof(tDblLinkList));
8034 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
8035 {
8036 smsLog(pMac, LOGE, FL(" failed to open list"));
8037 return;
8038 }
8039
8040 csrLLLock(pList);
8041 if ((pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK)))
8042 {
8043
8044 /* Have to make sure we don't loop back to the head of the list,
8045 * which will happen if the entry is NOT on the list */
8046 while (pEntry)
8047 {
8048 pEntryToRemove = pEntry;
8049 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
8050 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
8051 if ((pCommand->command == commandType) &&
8052 (pCommand->sessionId == sessionId))
8053 {
8054 /* Remove that entry only */
8055 if (csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
8056 {
8057 csrLLInsertTail(&localList, pEntryToRemove,
8058 LL_ACCESS_NOLOCK);
8059 }
8060 }
8061 }
8062 }
8063 csrLLUnlock(pList);
8064
8065 while ((pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)))
8066 {
8067 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
8068 csrAbortCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
8069 }
8070
8071 csrLLClose(&localList);
Jeff Johnson295189b2012-06-20 16:38:30 -07008072}
8073
8074void csrRemoveCmdFromPendingList(tpAniSirGlobal pMac, tDblLinkList *pList,
8075 eSmeCommandType commandType )
8076{
8077 tDblLinkList localList;
8078 tListElem *pEntry;
8079 tSmeCmd *pCommand;
8080 tListElem *pEntryToRemove;
8081
8082 vos_mem_zero(&localList, sizeof(tDblLinkList));
8083 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
8084 {
8085 smsLog(pMac, LOGE, FL(" failed to open list"));
8086 return;
8087 }
8088
8089 csrLLLock(pList);
8090 if( !csrLLIsListEmpty( pList, LL_ACCESS_NOLOCK ) )
8091 {
8092 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK);
8093
8094 // Have to make sure we don't loop back to the head of the list, which will
8095 // happen if the entry is NOT on the list...
8096 while( pEntry )
8097 {
8098 pEntryToRemove = pEntry;
8099 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
8100 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
8101 if ( pCommand->command == commandType )
8102 {
8103 // Remove that entry only
8104 if(csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
8105 {
8106 csrLLInsertTail(&localList, pEntryToRemove, LL_ACCESS_NOLOCK);
8107 }
8108 }
8109 }
8110
8111
8112 }
8113 csrLLUnlock(pList);
8114
8115 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
8116 {
8117 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8118 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
8119 }
8120 csrLLClose(&localList);
8121
8122}
8123
Abhishek Singhdc2bfd42014-06-19 17:59:05 +05308124eHalStatus csrScanAbortScanForSSID(tpAniSirGlobal pMac, tANI_U32 sessionId)
8125{
8126 eHalStatus status = eHAL_STATUS_SUCCESS;
8127 tSirSmeScanAbortReq *pMsg;
8128 tANI_U16 msgLen;
8129 tListElem *pEntry;
8130 tSmeCmd *pCommand;
8131
8132 if (!pMac->fScanOffload)
8133 {
8134 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
8135#ifdef WLAN_AP_STA_CONCURRENCY
8136 csrRemoveScanForSSIDFromPendingList( pMac, &pMac->scan.scanCmdPendingList, sessionId);
8137#endif
8138 csrRemoveScanForSSIDFromPendingList( pMac, &pMac->roam.roamCmdPendingList, sessionId);
8139 csrRemoveScanForSSIDFromPendingList( pMac, &pMac->sme.smeCmdPendingList, sessionId);
8140 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
8141 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
8142 }
8143 else
8144 {
8145 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
8146 csrRemoveScanForSSIDFromPendingList( pMac, &pMac->sme.smeScanCmdPendingList, sessionId);
8147 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
8148 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
8149 }
8150
8151 if(NULL != pEntry)
8152 {
8153 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8154
8155 if ( (eSmeCommandScan == pCommand->command ) &&
8156 (sessionId == pCommand->sessionId))
8157 {
8158 if ( eCsrScanForSsid == pCommand->u.scanCmd.reason)
8159 {
8160 msgLen = (tANI_U16)(sizeof( tSirSmeScanAbortReq ));
8161 pMsg = vos_mem_malloc(msgLen);
8162 if ( NULL == pMsg )
8163 {
8164 status = eHAL_STATUS_FAILURE;
8165 smsLog(pMac, LOGE, FL("Failed to allocate memory for SmeScanAbortReq"));
8166 }
8167 else
8168 {
8169 vos_mem_zero((void *)pMsg, msgLen);
8170 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_ABORT_IND);
8171 pMsg->msgLen = pal_cpu_to_be16(msgLen);
8172 pMsg->sessionId = sessionId;
8173 status = palSendMBMessage(pMac->hHdd, pMsg);
8174 }
8175 }
8176 }
8177 }
8178 return( status );
8179}
8180
8181void csrRemoveScanForSSIDFromPendingList(tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 sessionId)
8182{
8183 tDblLinkList localList;
8184 tListElem *pEntry;
8185 tSmeCmd *pCommand;
8186 tListElem *pEntryToRemove;
8187
8188 vos_mem_zero(&localList, sizeof(tDblLinkList));
8189 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
8190 {
8191 smsLog(pMac, LOGE, FL(" failed to open list"));
8192 return;
8193 }
8194
8195 csrLLLock(pList);
8196 if( !csrLLIsListEmpty( pList, LL_ACCESS_NOLOCK ) )
8197 {
8198 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK);
8199
8200 // Have to make sure we don't loop back to the head of the list, which will
8201 // happen if the entry is NOT on the list...
8202 while( pEntry )
8203 {
8204 pEntryToRemove = pEntry;
8205 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
8206 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
8207 if ( (eSmeCommandScan == pCommand->command ) &&
8208 (sessionId == pCommand->sessionId) )
8209 {
8210 if ( eCsrScanForSsid == pCommand->u.scanCmd.reason)
8211 {
8212 // Remove that entry only
8213 if ( csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
8214 {
8215 csrLLInsertTail(&localList, pEntryToRemove, LL_ACCESS_NOLOCK);
8216 }
8217 }
8218 }
8219 }
8220 }
8221 csrLLUnlock(pList);
8222
8223 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
8224 {
8225 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8226 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
8227 }
8228 csrLLClose(&localList);
8229}
Jeff Johnson295189b2012-06-20 16:38:30 -07008230
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308231eHalStatus csrScanAbortMacScanNotForConnect(tpAniSirGlobal pMac,
8232 tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07008233{
8234 eHalStatus status = eHAL_STATUS_SUCCESS;
8235
8236 if( !csrIsScanForRoamCommandActive( pMac ) )
8237 {
8238 //Only abort the scan if it is not used for other roam/connect purpose
c_hpothua3d45d52015-01-05 14:11:17 +05308239 if (eSIR_ABORT_SCAN_FAILURE ==
8240 csrScanAbortMacScan(pMac, sessionId, eCSR_SCAN_ABORT_DEFAULT))
8241 {
8242 smsLog(pMac, LOGE, FL("fail to abort scan"));
8243 status = eHAL_STATUS_FAILURE;
8244 }
Jeff Johnson295189b2012-06-20 16:38:30 -07008245 }
8246
8247 return (status);
8248}
8249
8250
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05308251eHalStatus csrScanGetScanChannelInfo(tpAniSirGlobal pMac, tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07008252{
8253 eHalStatus status = eHAL_STATUS_SUCCESS;
8254 tSirMbMsg *pMsg;
8255 tANI_U16 msgLen;
8256
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05308257 if (pMac->fScanOffload)
8258 msgLen = (tANI_U16)(sizeof(tSirSmeGetScanChanReq));
8259 else
8260 msgLen = (tANI_U16)(sizeof(tSirMbMsg));
8261
Kiet Lam64c1b492013-07-12 13:56:44 +05308262 pMsg = vos_mem_malloc(msgLen);
8263 if ( NULL == pMsg )
8264 status = eHAL_STATUS_FAILURE;
8265 else
Jeff Johnson295189b2012-06-20 16:38:30 -07008266 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308267 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008268 pMsg->type = eWNI_SME_GET_SCANNED_CHANNEL_REQ;
8269 pMsg->msgLen = msgLen;
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05308270 if (pMac->fScanOffload)
8271 ((tSirSmeGetScanChanReq *)pMsg)->sessionId = sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07008272 status = palSendMBMessage(pMac->hHdd, pMsg);
8273 }
8274
8275 return( status );
8276}
8277
8278tANI_BOOLEAN csrRoamIsValidChannel( tpAniSirGlobal pMac, tANI_U8 channel )
8279{
8280 tANI_BOOLEAN fValid = FALSE;
8281 tANI_U32 idxValidChannels;
8282 tANI_U32 len = pMac->roam.numValidChannels;
8283
8284 for ( idxValidChannels = 0; ( idxValidChannels < len ); idxValidChannels++ )
8285 {
8286 if ( channel == pMac->roam.validChannelList[ idxValidChannels ] )
8287 {
8288 fValid = TRUE;
8289 break;
8290 }
8291 }
8292
8293 return fValid;
8294}
8295
Manjunathappa Prakash4f1d5a52013-11-11 16:22:19 -08008296#ifdef FEATURE_WLAN_SCAN_PNO
Srikant Kuppa066904f2013-05-07 13:56:02 -07008297eHalStatus csrScanSavePreferredNetworkFound(tpAniSirGlobal pMac,
8298 tSirPrefNetworkFoundInd *pPrefNetworkFoundInd)
8299{
8300 v_U32_t uLen = 0;
8301 tpSirProbeRespBeacon pParsedFrame;
8302 tCsrScanResult *pScanResult = NULL;
8303 tSirBssDescription *pBssDescr = NULL;
8304 tANI_BOOLEAN fDupBss;
8305 tDot11fBeaconIEs *pIesLocal = NULL;
8306 tAniSSID tmpSsid;
8307 v_TIME_t timer=0;
8308 tpSirMacMgmtHdr macHeader = (tpSirMacMgmtHdr)pPrefNetworkFoundInd->data;
Abhishek Singhd3d4e022014-11-11 13:02:40 +05308309 boolean bFoundonAppliedChannel = FALSE;
8310 v_U32_t indx;
8311 u8 channelsAllowed[WNI_CFG_VALID_CHANNEL_LIST_LEN];
8312 v_U32_t numChannelsAllowed = WNI_CFG_VALID_CHANNEL_LIST_LEN;
8313
Srikant Kuppa066904f2013-05-07 13:56:02 -07008314
8315 pParsedFrame =
Kiet Lam64c1b492013-07-12 13:56:44 +05308316 (tpSirProbeRespBeacon)vos_mem_malloc(sizeof(tSirProbeRespBeacon));
Srikant Kuppa066904f2013-05-07 13:56:02 -07008317
8318 if (NULL == pParsedFrame)
8319 {
8320 smsLog(pMac, LOGE, FL(" fail to allocate memory for frame"));
8321 return eHAL_STATUS_RESOURCES;
8322 }
8323
8324 if ( pPrefNetworkFoundInd->frameLength <= SIR_MAC_HDR_LEN_3A )
8325 {
8326 smsLog(pMac, LOGE,
8327 FL("Not enough bytes in PNO indication probe resp frame! length=%d"),
8328 pPrefNetworkFoundInd->frameLength);
8329 vos_mem_free(pParsedFrame);
8330 return eHAL_STATUS_FAILURE;
8331 }
8332
8333 if (sirConvertProbeFrame2Struct(pMac,
8334 &pPrefNetworkFoundInd->data[SIR_MAC_HDR_LEN_3A],
8335 pPrefNetworkFoundInd->frameLength - SIR_MAC_HDR_LEN_3A,
8336 pParsedFrame) != eSIR_SUCCESS ||
8337 !pParsedFrame->ssidPresent)
8338 {
8339 smsLog(pMac, LOGE,
8340 FL("Parse error ProbeResponse, length=%d"),
8341 pPrefNetworkFoundInd->frameLength);
8342 vos_mem_free(pParsedFrame);
8343 return eHAL_STATUS_FAILURE;
8344 }
8345 //24 byte MAC header and 12 byte to ssid IE
8346 if (pPrefNetworkFoundInd->frameLength >
8347 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET))
8348 {
8349 uLen = pPrefNetworkFoundInd->frameLength -
8350 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET);
8351 }
8352
Kiet Lam64c1b492013-07-12 13:56:44 +05308353 pScanResult = vos_mem_malloc(sizeof(tCsrScanResult) + uLen);
8354 if ( NULL == pScanResult )
Srikant Kuppa066904f2013-05-07 13:56:02 -07008355 {
8356 smsLog(pMac, LOGE, FL(" fail to allocate memory for frame"));
8357 vos_mem_free(pParsedFrame);
8358 return eHAL_STATUS_RESOURCES;
8359 }
8360
Kiet Lam64c1b492013-07-12 13:56:44 +05308361 vos_mem_set(pScanResult, sizeof(tCsrScanResult) + uLen, 0);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008362 pBssDescr = &pScanResult->Result.BssDescriptor;
8363 /**
8364 * Length of BSS desription is without length of
8365 * length itself and length of pointer
8366 * that holds the next BSS description
8367 */
8368 pBssDescr->length = (tANI_U16)(
8369 sizeof(tSirBssDescription) - sizeof(tANI_U16) -
8370 sizeof(tANI_U32) + uLen);
8371 if (pParsedFrame->dsParamsPresent)
8372 {
8373 pBssDescr->channelId = pParsedFrame->channelNumber;
8374 }
8375 else if (pParsedFrame->HTInfo.present)
8376 {
8377 pBssDescr->channelId = pParsedFrame->HTInfo.primaryChannel;
8378 }
8379 else
8380 {
Mahesh A Saptasagaradd99792014-03-26 16:04:20 +05308381 /**
8382 * If Probe Responce received in PNO indication does not
8383 * contain DSParam IE or HT Info IE then add dummy channel
8384 * to the received BSS info so that Scan result received as
8385 * a part of PNO is updated to the supplicant. Specially
8386 * applicable in case of AP configured in 11A only mode.
8387 */
8388 if ((pMac->roam.configParam.bandCapability == eCSR_BAND_ALL) ||
8389 (pMac->roam.configParam.bandCapability == eCSR_BAND_24))
8390 {
8391 pBssDescr->channelId = 1;
8392 }
8393 else if(pMac->roam.configParam.bandCapability == eCSR_BAND_5G)
8394 {
8395 pBssDescr->channelId = 36;
8396 }
Abhishek Singhd3d4e022014-11-11 13:02:40 +05308397 /* Restrict the logic to ignore the pno indication for invalid channel
8398 * only if valid channel info is present in beacon/probe resp.
8399 * If no channel info is present in beacon/probe resp, always process
8400 * the pno indication.
8401 */
8402 bFoundonAppliedChannel = TRUE;
8403 }
8404
8405 if (0 != sme_GetCfgValidChannels(pMac, channelsAllowed, &numChannelsAllowed))
8406 {
8407 smsLog(pMac, LOGE, FL(" sme_GetCfgValidChannels failed "));
8408 csrFreeScanResultEntry(pMac, pScanResult);
8409 vos_mem_free(pParsedFrame);
8410 return eHAL_STATUS_FAILURE;
8411 }
8412 /* Checking chhanelId with allowed channel list */
8413 for (indx = 0; indx < numChannelsAllowed; indx++)
8414 {
8415 if (pBssDescr->channelId == channelsAllowed[indx])
8416 {
8417 bFoundonAppliedChannel = TRUE;
8418 smsLog(pMac, LOG1, FL(" pno ind found on applied channel =%d\n "),
8419 pBssDescr->channelId);
8420 break;
8421 }
8422 }
8423 /* Ignore PNO indication if AP is on Invalid channel.
8424 */
8425 if(FALSE == bFoundonAppliedChannel)
8426 {
8427 smsLog(pMac, LOGW, FL(" prefered network found on invalid channel = %d"),
8428 pBssDescr->channelId);
8429 csrFreeScanResultEntry(pMac, pScanResult);
8430 vos_mem_free(pParsedFrame);
8431 return eHAL_STATUS_FAILURE;
Srikant Kuppa066904f2013-05-07 13:56:02 -07008432 }
8433
8434 if ((pBssDescr->channelId > 0) && (pBssDescr->channelId < 15))
8435 {
8436 int i;
8437 // 11b or 11g packet
8438 // 11g iff extended Rate IE is present or
8439 // if there is an A rate in suppRate IE
8440 for (i = 0; i < pParsedFrame->supportedRates.numRates; i++)
8441 {
8442 if (sirIsArate(pParsedFrame->supportedRates.rate[i] & 0x7f))
8443 {
8444 pBssDescr->nwType = eSIR_11G_NW_TYPE;
8445 break;
8446 }
8447 }
8448 if (pParsedFrame->extendedRatesPresent)
8449 {
8450 pBssDescr->nwType = eSIR_11G_NW_TYPE;
8451 }
8452 }
8453 else
8454 {
8455 // 11a packet
8456 pBssDescr->nwType = eSIR_11A_NW_TYPE;
8457 }
8458
8459 pBssDescr->sinr = 0;
8460 pBssDescr->rssi = -1 * pPrefNetworkFoundInd->rssi;
8461 pBssDescr->beaconInterval = pParsedFrame->beaconInterval;
AnjaneeDevi Kapparapu4b043912014-02-18 13:22:35 +05308462 if (!pBssDescr->beaconInterval)
8463 {
8464 smsLog(pMac, LOGW,
8465 FL("Bcn Interval is Zero , default to 100" MAC_ADDRESS_STR),
8466 MAC_ADDR_ARRAY(pBssDescr->bssId) );
8467 pBssDescr->beaconInterval = 100;
8468 }
Srikant Kuppa066904f2013-05-07 13:56:02 -07008469 pBssDescr->timeStamp[0] = pParsedFrame->timeStamp[0];
8470 pBssDescr->timeStamp[1] = pParsedFrame->timeStamp[1];
8471 pBssDescr->capabilityInfo = *((tANI_U16 *)&pParsedFrame->capabilityInfo);
Kiet Lam64c1b492013-07-12 13:56:44 +05308472 vos_mem_copy((tANI_U8 *) &pBssDescr->bssId, (tANI_U8 *) macHeader->bssId, sizeof(tSirMacAddr));
Srikant Kuppa066904f2013-05-07 13:56:02 -07008473 pBssDescr->nReceivedTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
8474
Abhishek Singh195c03e2014-05-14 17:21:30 +05308475 smsLog( pMac, LOG1, FL("Bssid= "MAC_ADDRESS_STR
8476 " chan= %d, rssi = %d "),
Arif Hussain24bafea2013-11-15 15:10:03 -08008477 MAC_ADDR_ARRAY(pBssDescr->bssId),
Srikant Kuppa066904f2013-05-07 13:56:02 -07008478 pBssDescr->channelId,
Abhishek Singh195c03e2014-05-14 17:21:30 +05308479 pBssDescr->rssi);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008480
8481 //IEs
8482 if (uLen)
8483 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308484 vos_mem_copy(&pBssDescr->ieFields,
8485 pPrefNetworkFoundInd->data + (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET),
8486 uLen);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008487 }
8488
8489 pIesLocal = (tDot11fBeaconIEs *)( pScanResult->Result.pvIes );
8490 if ( !pIesLocal &&
8491 (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
8492 &pScanResult->Result.BssDescriptor, &pIesLocal))) )
8493 {
8494 smsLog(pMac, LOGE, FL(" Cannot parse IEs"));
8495 csrFreeScanResultEntry(pMac, pScanResult);
8496 vos_mem_free(pParsedFrame);
8497 return eHAL_STATUS_RESOURCES;
8498 }
8499
8500 fDupBss = csrRemoveDupBssDescription( pMac,
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05308501 &pScanResult->Result.BssDescriptor, pIesLocal, &tmpSsid, &timer, FALSE);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008502 //Check whether we have reach out limit
8503 if ( CSR_SCAN_IS_OVER_BSS_LIMIT(pMac) )
8504 {
8505 //Limit reach
8506 smsLog(pMac, LOGE, FL(" BSS limit reached"));
8507 //Free the resources
8508 if( (pScanResult->Result.pvIes == NULL) && pIesLocal )
8509 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308510 vos_mem_free(pIesLocal);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008511 }
8512 csrFreeScanResultEntry(pMac, pScanResult);
8513 vos_mem_free(pParsedFrame);
8514 return eHAL_STATUS_RESOURCES;
8515 }
8516 //Add to scan cache
8517 csrScanAddResult(pMac, pScanResult, pIesLocal);
8518
Kiet Lamb537cfb2013-11-07 12:56:49 +05308519 if( (pScanResult->Result.pvIes == NULL) && pIesLocal )
8520 {
8521 vos_mem_free(pIesLocal);
8522 }
8523
Srikant Kuppa066904f2013-05-07 13:56:02 -07008524 vos_mem_free(pParsedFrame);
8525
8526 return eHAL_STATUS_SUCCESS;
8527}
Manjunathappa Prakash4f1d5a52013-11-11 16:22:19 -08008528#endif //FEATURE_WLAN_SCAN_PNO
Srikant Kuppa066904f2013-05-07 13:56:02 -07008529
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008530#ifdef FEATURE_WLAN_LFR
8531void csrInitOccupiedChannelsList(tpAniSirGlobal pMac)
8532{
8533 tListElem *pEntry = NULL;
8534 tCsrScanResult *pBssDesc = NULL;
8535 tDot11fBeaconIEs *pIes = NULL;
Srinivas28b5b4e2012-12-12 13:07:53 -08008536 tpCsrNeighborRoamControlInfo pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
8537
8538 if (0 != pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels)
8539 {
8540 smsLog(pMac, LOG1, FL("%s: Ini file contains neighbor scan channel list,"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008541 " hence NO need to build occupied channel list (numChannels = %d)"),
Srinivas28b5b4e2012-12-12 13:07:53 -08008542 __func__, pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels);
8543 return;
8544 }
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008545
8546 if (!csrNeighborRoamIsNewConnectedProfile(pMac))
8547 {
8548 smsLog(pMac, LOG2, FL("%s: donot flush occupied list since current roam profile"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008549 " matches previous (numChannels = %d)"),
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008550 __func__, pMac->scan.occupiedChannels.numChannels);
8551 return;
8552 }
8553
8554 /* Empty occupied channels here */
8555 pMac->scan.occupiedChannels.numChannels = 0;
8556
8557 csrLLLock(&pMac->scan.scanResultList);
8558 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
8559 while( pEntry )
8560 {
8561 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
8562 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
8563
8564 //At this time, pBssDescription->Result.pvIes may be NULL
Srikant Kuppa866893f2012-12-27 17:28:14 -08008565 if( !pIes && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008566 &pBssDesc->Result.BssDescriptor, &pIes))) )
8567 {
8568 continue;
8569 }
8570
8571 csrScanAddToOccupiedChannels(pMac, pBssDesc, &pMac->scan.occupiedChannels, pIes);
8572
8573 /*
8574 * Free the memory allocated for pIes in csrGetParsedBssDescriptionIEs
8575 */
8576 if( (pBssDesc->Result.pvIes == NULL) && pIes )
8577 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308578 vos_mem_free(pIes);
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008579 }
8580
8581 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK );
8582 }//while
8583 csrLLUnlock(&pMac->scan.scanResultList);
Srikant Kuppa866893f2012-12-27 17:28:14 -08008584
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008585}
8586#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07008587
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008588eHalStatus csrScanCreateEntryInScanCache(tpAniSirGlobal pMac, tANI_U32 sessionId,
8589 tCsrBssid bssid, tANI_U8 channel)
8590{
8591 eHalStatus status = eHAL_STATUS_SUCCESS;
8592 tDot11fBeaconIEs *pNewIes = NULL;
8593 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
Praveen Kumar Sirisilla8bdfac42013-10-10 17:20:48 -07008594 tSirBssDescription *pNewBssDescriptor = NULL;
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008595 tANI_U32 size = 0;
8596
8597 if(NULL == pSession)
8598 {
8599 status = eHAL_STATUS_FAILURE;
8600 return status;
8601 }
8602 smsLog(pMac, LOG2, FL("csrScanCreateEntryInScanCache: Current bssid::"
Arif Hussain24bafea2013-11-15 15:10:03 -08008603 MAC_ADDRESS_STR),
8604 MAC_ADDR_ARRAY(pSession->pConnectBssDesc->bssId));
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008605 smsLog(pMac, LOG2, FL("csrScanCreateEntryInScanCache: My bssid::"
Arif Hussain24bafea2013-11-15 15:10:03 -08008606 MAC_ADDRESS_STR" channel %d"),
8607 MAC_ADDR_ARRAY(bssid), channel);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008608
8609 do
8610 {
8611 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
8612 pSession->pConnectBssDesc, &pNewIes)))
8613 {
8614 smsLog(pMac, LOGE, FL("%s: Failed to parse IEs"),
8615 __func__);
8616 status = eHAL_STATUS_FAILURE;
8617 break;
8618 }
8619
8620 size = pSession->pConnectBssDesc->length + sizeof(pSession->pConnectBssDesc->length);
Kiet Lam64c1b492013-07-12 13:56:44 +05308621 if (size)
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008622 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308623 pNewBssDescriptor = vos_mem_malloc(size);
8624 if ( NULL == pNewBssDescriptor )
8625 status = eHAL_STATUS_FAILURE;
8626 else
8627 status = eHAL_STATUS_SUCCESS;
8628 if (HAL_STATUS_SUCCESS(status))
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008629 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308630 vos_mem_copy(pNewBssDescriptor, pSession->pConnectBssDesc, size);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008631 }
8632 else
8633 {
8634 smsLog(pMac, LOGE, FL("%s: memory allocation failed"),
8635 __func__);
8636 status = eHAL_STATUS_FAILURE;
8637 break;
8638 }
8639
8640 //change the BSSID & channel as passed
Kiet Lam64c1b492013-07-12 13:56:44 +05308641 vos_mem_copy(pNewBssDescriptor->bssId, bssid, sizeof(tSirMacAddr));
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008642 pNewBssDescriptor->channelId = channel;
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07008643 if(NULL == csrScanAppendBssDescription( pMac, pNewBssDescriptor, pNewIes, TRUE ))
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008644 {
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07008645 smsLog(pMac, LOGE, FL("%s: csrScanAppendBssDescription failed"),
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008646 __func__);
8647 status = eHAL_STATUS_FAILURE;
8648 break;
8649 }
8650 }
8651 else
8652 {
8653 smsLog(pMac, LOGE, FL("%s: length of bss descriptor is 0"),
8654 __func__);
8655 status = eHAL_STATUS_FAILURE;
8656 break;
8657 }
8658 smsLog(pMac, LOGE, FL("%s: entry successfully added in scan cache"),
8659 __func__);
8660 }while(0);
8661
8662 if(pNewIes)
8663 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308664 vos_mem_free(pNewIes);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008665 }
8666 if(pNewBssDescriptor)
8667 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308668 vos_mem_free(pNewBssDescriptor);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008669 }
8670 return status;
8671}
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07008672
Varun Reddy Yeturu5d5e2c62014-02-27 13:31:29 -08008673#ifdef FEATURE_WLAN_ESE
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07008674// Update the TSF with the difference in system time
8675void UpdateCCKMTSF(tANI_U32 *timeStamp0, tANI_U32 *timeStamp1, tANI_U32 *incr)
8676{
8677 tANI_U64 timeStamp64 = ((tANI_U64)*timeStamp1 << 32) | (*timeStamp0);
8678
8679 timeStamp64 = (tANI_U64)(timeStamp64 + (tANI_U64)*incr);
8680 *timeStamp0 = (tANI_U32)(timeStamp64 & 0xffffffff);
8681 *timeStamp1 = (tANI_U32)((timeStamp64 >> 32) & 0xffffffff);
8682}
8683#endif