blob: c7ea4f7defa6da2a1a440d7ea529ce3b0d798217 [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Gopichand Nakkala9c070ad2013-01-08 21:16:34 -08002 * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
3 *
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.
20 */
21/*
Jeff Johnson32d95a32012-09-10 13:15:23 -070022 * Copyright (c) 2012, The Linux Foundation. All rights reserved.
Jeff Johnson295189b2012-06-20 16:38:30 -070023 *
24 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
25 *
26 *
27 * Permission to use, copy, modify, and/or distribute this software for
28 * any purpose with or without fee is hereby granted, provided that the
29 * above copyright notice and this permission notice appear in all
30 * copies.
31 *
32 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
33 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
34 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
35 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
36 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
37 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
38 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
39 * PERFORMANCE OF THIS SOFTWARE.
40 */
41
Jeff Johnson56358122013-03-19 14:43:18 -070042/** ------------------------------------------------------------------------- *
43 ------------------------------------------------------------------------- *
Jeff Johnson295189b2012-06-20 16:38:30 -070044
Jeff Johnson56358122013-03-19 14:43:18 -070045
Jeff Johnson295189b2012-06-20 16:38:30 -070046 \file csrApiScan.c
Jeff Johnson56358122013-03-19 14:43:18 -070047
Jeff Johnson295189b2012-06-20 16:38:30 -070048 Implementation for the Common Scan interfaces.
Jeff Johnson56358122013-03-19 14:43:18 -070049
50 Copyright (C) 2006 Airgo Networks, Incorporated
Jeff Johnson295189b2012-06-20 16:38:30 -070051 ========================================================================== */
52
53#include "aniGlobal.h"
54
55#include "palApi.h"
56#include "csrInsideApi.h"
57#include "smeInside.h"
58#include "smsDebug.h"
59
60#include "csrSupport.h"
61#include "wlan_qct_tl.h"
62
63#include "vos_diag_core_log.h"
64#include "vos_diag_core_event.h"
65
66#include "vos_nvitem.h"
67#include "wlan_qct_wda.h"
Jeff Johnson56358122013-03-19 14:43:18 -070068
Jeff Johnson295189b2012-06-20 16:38:30 -070069#define CSR_VALIDATE_LIST //This portion of code need to be removed once the issue is resolved.
Kiet Lam83cd0002013-11-05 20:45:04 +053070#define MIN_CHN_TIME_TO_FIND_GO 100
71#define MAX_CHN_TIME_TO_FIND_GO 100
72#define DIRECT_SSID_LEN 7
Jeff Johnson295189b2012-06-20 16:38:30 -070073
74#ifdef CSR_VALIDATE_LIST
75tDblLinkList *g_pchannelPowerInfoList24 = NULL, * g_pchannelPowerInfoList5 = NULL;
Madan Mohan Koyyalamudidfd6aa82012-10-18 20:18:43 -070076tpAniSirGlobal g_pMac;
Jeff Johnson295189b2012-06-20 16:38:30 -070077#endif
78
79/* Purpose of HIDDEN_TIMER
80** When we remove hidden ssid from the profile i.e., forget the SSID via GUI that SSID shouldn't see in the profile
81** For above requirement we used timer limit, logic is explained below
82** Timer value is initialsed to current time when it receives corresponding probe response of hidden SSID (The probe request is
83** received regularly till SSID in the profile. Once it is removed from profile probe request is not sent.) when we receive probe response
84** 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
85** then we are not updating with old one
86*/
87
88#define HIDDEN_TIMER (1*60*1000)
89#define CSR_SCAN_RESULT_RSSI_WEIGHT 80 // must be less than 100, represent the persentage of new RSSI
90
91/*---------------------------------------------------------------------------
92 PER filter constant fraction: it is a %
93---------------------------------------------------------------------------*/
94#define CSR_SCAN_PER_FILTER_FRAC 100
95
96/*---------------------------------------------------------------------------
97 RSSI filter constant fraction: it is a %
98---------------------------------------------------------------------------*/
99#define CSR_SCAN_RSSI_FILTER_FRAC 100
100
101/*---------------------------------------------------------------------------
102Convert RSSI into overall score: Since RSSI is in -dBm values, and the
103overall needs to be weighted inversely (where greater value means better
104system), we convert.
105RSSI *cannot* be more than 0xFF or less than 0 for meaningful WLAN operation
106---------------------------------------------------------------------------*/
107#define CSR_SCAN_MAX_SCORE_VAL 0xFF
108#define CSR_SCAN_MIN_SCORE_VAL 0x0
109#define CSR_SCAN_HANDOFF_DELTA 10
Jeff Johnson32d95a32012-09-10 13:15:23 -0700110#define MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL 140
111#define MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL 120
Madan Mohan Koyyalamudia53c4dc2012-11-13 10:35:42 -0800112#define CSR_SCAN_OVERALL_SCORE( rssi ) \
113 (( rssi < CSR_SCAN_MAX_SCORE_VAL ) \
114 ? (CSR_SCAN_MAX_SCORE_VAL-rssi) : CSR_SCAN_MIN_SCORE_VAL)
Jeff Johnson295189b2012-06-20 16:38:30 -0700115
116
117#define CSR_SCAN_IS_OVER_BSS_LIMIT(pMac) \
118 ( (pMac)->scan.nBssLimit <= (csrLLCount(&(pMac)->scan.scanResultList)) )
119
Gopichand Nakkalaf88ca562013-04-23 20:30:01 +0530120/* Maximum number of channels per country can be ignored */
121#define MAX_CHANNELS_IGNORE 10
122
Wilson Yang28857f72013-10-09 00:35:43 -0700123#define MAX_COUNTRY_IGNORE 5
Gopichand Nakkalaf88ca562013-04-23 20:30:01 +0530124
Madan Mohan Koyyalamudi8fe78832013-09-13 00:06:17 +0530125#define THIRTY_PERCENT(x) (x*30/100);
126
krunal soni6fd05dd2013-11-25 15:00:11 -0800127#define MANDATORY_BG_CHANNEL 11
128
Gopichand Nakkalaf88ca562013-04-23 20:30:01 +0530129/*struct to hold the ignored channel list based on country */
130typedef struct sCsrIgnoreChannels
131{
132 tANI_U8 countryCode[NV_FIELD_COUNTRY_CODE_SIZE];
133 tANI_U16 channelList[MAX_CHANNELS_IGNORE];
134 tANI_U16 channelCount;
135}tCsrIgnoreChannels;
136
Tushnim Bhattacharyya47f9a762013-11-07 23:44:09 -0800137#ifndef CONFIG_ENABLE_LINUX_REG
Gopichand Nakkalaf88ca562013-04-23 20:30:01 +0530138static tCsrIgnoreChannels countryIgnoreList[MAX_COUNTRY_IGNORE] = {
139 { {'U','A'}, { 136, 140}, 2},
140 { {'T','W'}, { 36, 40, 44, 48, 52}, 5},
Madan Mohan Koyyalamudi117b2c62013-08-12 15:06:21 +0530141 { {'I','D'}, { 165}, 1 },
Wilson Yang28857f72013-10-09 00:35:43 -0700142 { {'A','U'}, { 120, 124, 128}, 3 },
Kiet Lam3dd81472013-11-11 14:40:34 -0800143 { {'A','R'}, { 120, 124, 128}, 3 }
Gopichand Nakkalaf88ca562013-04-23 20:30:01 +0530144 };
Tushnim Bhattacharyya47f9a762013-11-07 23:44:09 -0800145#else
146static tCsrIgnoreChannels countryIgnoreList[MAX_COUNTRY_IGNORE] = { };
147#endif //CONFIG_ENABLE_LINUX_REG
Gopichand Nakkalaf88ca562013-04-23 20:30:01 +0530148
Jeff Johnson295189b2012-06-20 16:38:30 -0700149//*** This is temporary work around. It need to call CCM api to get to CFG later
150/// Get string parameter value
151extern tSirRetStatus wlan_cfgGetStr(tpAniSirGlobal, tANI_U16, tANI_U8*, tANI_U32*);
Gopichand Nakkalaf88ca562013-04-23 20:30:01 +0530152
Jeff Johnson295189b2012-06-20 16:38:30 -0700153void csrScanGetResultTimerHandler(void *);
154void csrScanResultAgingTimerHandler(void *pv);
Madan Mohan Koyyalamudi7da2fd72012-12-17 14:44:16 -0800155static void csrScanResultCfgAgingTimerHandler(void *pv);
Jeff Johnson295189b2012-06-20 16:38:30 -0700156void csrScanIdleScanTimerHandler(void *);
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700157static void csrSetDefaultScanTiming( tpAniSirGlobal pMac, tSirScanType scanType, tCsrScanRequest *pScanRequest);
Jeff Johnson295189b2012-06-20 16:38:30 -0700158#ifdef WLAN_AP_STA_CONCURRENCY
159static void csrStaApConcTimerHandler(void *);
160#endif
Jeff Johnsone7245742012-09-05 17:12:55 -0700161tANI_BOOLEAN csrIsSupportedChannel(tpAniSirGlobal pMac, tANI_U8 channelId);
Jeff Johnson295189b2012-06-20 16:38:30 -0700162eHalStatus csrScanChannels( tpAniSirGlobal pMac, tSmeCmd *pCommand );
163void csrSetCfgValidChannelList( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels );
164void csrSaveTxPowerToCfg( tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 cfgId );
165void csrSetCfgCountryCode( tpAniSirGlobal pMac, tANI_U8 *countryCode );
166void csrPurgeChannelPower( tpAniSirGlobal pMac, tDblLinkList *pChannelList );
167//if bgPeriod is 0, background scan is disabled. It is in millisecond units
168eHalStatus csrSetCfgBackgroundScanPeriod(tpAniSirGlobal pMac, tANI_U32 bgPeriod);
169eHalStatus csrProcessSetBGScanParam(tpAniSirGlobal pMac, tSmeCmd *pCommand);
170void csrReleaseScanCommand(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus);
171static tANI_BOOLEAN csrScanValidateScanResult( tpAniSirGlobal pMac, tANI_U8 *pChannels,
172 tANI_U8 numChn, tSirBssDescription *pBssDesc,
173 tDot11fBeaconIEs **ppIes );
174eHalStatus csrSetBGScanChannelList( tpAniSirGlobal pMac, tANI_U8 *pAdjustChannels, tANI_U8 NumAdjustChannels);
175void csrReleaseCmdSingle(tpAniSirGlobal pMac, tSmeCmd *pCommand);
176tANI_BOOLEAN csrRoamIsValidChannel( tpAniSirGlobal pMac, tANI_U8 channel );
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700177void csrPruneChannelListForMode( tpAniSirGlobal pMac, tCsrChannel *pChannelList );
Jeff Johnson295189b2012-06-20 16:38:30 -0700178
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -0700179#define CSR_IS_SOCIAL_CHANNEL(channel) (((channel) == 1) || ((channel) == 6) || ((channel) == 11) )
180
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -0700181
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -0700182
Madan Mohan Koyyalamudi62ee4272012-11-30 17:53:27 -0800183static void csrReleaseScanCmdPendingList(tpAniSirGlobal pMac)
184{
185 tListElem *pEntry;
186 tSmeCmd *pCommand;
187
188 while((pEntry = csrLLRemoveHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK)) != NULL)
189 {
190 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
191 if ( eSmeCsrCommandMask & pCommand->command )
192 {
193 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_TRUE );
194 }
195 else
196 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -0800197 smsLog(pMac, LOGE, FL("Error: Received command : %d"),pCommand->command);
Madan Mohan Koyyalamudi62ee4272012-11-30 17:53:27 -0800198 }
199 }
200}
Jeff Johnson295189b2012-06-20 16:38:30 -0700201//pResult is invalid calling this function.
202void csrFreeScanResultEntry( tpAniSirGlobal pMac, tCsrScanResult *pResult )
203{
204 if( NULL != pResult->Result.pvIes )
205 {
Kiet Lam3cac75e2013-07-12 13:56:44 +0530206 vos_mem_free(pResult->Result.pvIes);
Jeff Johnson295189b2012-06-20 16:38:30 -0700207 }
Kiet Lam3cac75e2013-07-12 13:56:44 +0530208 vos_mem_free(pResult);
Jeff Johnson295189b2012-06-20 16:38:30 -0700209}
210
211
212static eHalStatus csrLLScanPurgeResult(tpAniSirGlobal pMac, tDblLinkList *pList)
213{
214 eHalStatus status = eHAL_STATUS_SUCCESS;
215 tListElem *pEntry;
216 tCsrScanResult *pBssDesc;
217
218 csrLLLock(pList);
219
220 while((pEntry = csrLLRemoveHead(pList, LL_ACCESS_NOLOCK)) != NULL)
221 {
222 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
223 csrFreeScanResultEntry( pMac, pBssDesc );
224 }
225
226 csrLLUnlock(pList);
227
228 return (status);
229}
230
231
232int csrCheckValidateLists(void * dest, const void *src, v_SIZE_t num, int idx)
233{
234#ifdef CSR_VALIDATE_LIST
235
236 int ii = 1;
237
238 if( (NULL == g_pMac) || (!g_pMac->scan.fValidateList ) )
239 {
240 return ii;
241 }
242 if(g_pchannelPowerInfoList24)
243 {
244 //check 2.4 list
245 tListElem *pElem, *pHead;
246 int count;
247
248 count = (int)(g_pchannelPowerInfoList24->Count);
249 pHead = &g_pchannelPowerInfoList24->ListHead;
250 pElem = pHead->next;
251 if((tANI_U32)(pHead->next) > 0x00010000) //Assuming kernel address is not that low.
252 {
253 //this loop crashes if the pointer is not right
254 while(pElem->next != pHead)
255 {
256 if((tANI_U32)(pElem->next) > 0x00010000)
257 {
258 pElem = pElem->next;
259 VOS_ASSERT(count > 0);
260 count--;
261 }
262 else
263 {
Jeff Johnson5449b7a2013-11-22 18:39:00 -0800264 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_FATAL,
265 " %d Detect 1 list(%p) error Head(%p) next(%p) Count %d, dest(%p) src(%p) numBytes(%d)",
266 idx, g_pchannelPowerInfoList24, pHead,
267 (pHead->next), (int)g_pchannelPowerInfoList24->Count,
268 dest, src, (int)num);
Jeff Johnson295189b2012-06-20 16:38:30 -0700269 VOS_ASSERT(0);
270 ii = 0;
271 break;
272 }
273 }
274 }
275 else
276 {
277 //Bad list
Jeff Johnson5449b7a2013-11-22 18:39:00 -0800278 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_FATAL, " %d Detect list(%p) error Head(%p) next(%p) Count %d, dest(%p) src(%p) numBytes(%d)",
279 idx, g_pchannelPowerInfoList24, pHead,
280 (pHead->next), (int)g_pchannelPowerInfoList24->Count,
281 dest, src, (int)num);
Jeff Johnson295189b2012-06-20 16:38:30 -0700282 VOS_ASSERT(0);
283 ii = 0;
284 }
285 }
286 else
287 {
288 //list ok
289 ii = 1;
290 }
291
292
293 return ii;
294
295#else
296 return 1;
297#endif //#ifdef CSR_VALIDATE_LIST
298}
299
300
301eHalStatus csrScanOpen( tpAniSirGlobal pMac )
302{
303 eHalStatus status;
304
305 do
306 {
307 csrLLOpen(pMac->hHdd, &pMac->scan.scanResultList);
308 csrLLOpen(pMac->hHdd, &pMac->scan.tempScanResults);
309 csrLLOpen(pMac->hHdd, &pMac->scan.channelPowerInfoList24);
310 csrLLOpen(pMac->hHdd, &pMac->scan.channelPowerInfoList5G);
311#ifdef WLAN_AP_STA_CONCURRENCY
312 csrLLOpen(pMac->hHdd, &pMac->scan.scanCmdPendingList);
313#endif
314#ifdef CSR_VALIDATE_LIST
315 g_pchannelPowerInfoList5 = &pMac->scan.channelPowerInfoList5G;
316 g_pMac = pMac;
317 g_pchannelPowerInfoList24 = &pMac->scan.channelPowerInfoList24;
318#endif
319 pMac->scan.fFullScanIssued = eANI_BOOLEAN_FALSE;
320 pMac->scan.nBssLimit = CSR_MAX_BSS_SUPPORT;
Madan Mohan Koyyalamudi0dea29e2013-07-11 12:01:37 +0530321 status = vos_timer_init(&pMac->scan.hTimerGetResult, VOS_TIMER_TYPE_SW, csrScanGetResultTimerHandler, pMac);
322 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700323 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -0800324 smsLog(pMac, LOGE, FL("cannot allocate memory for getResult timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700325 break;
326 }
327#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudi0dea29e2013-07-11 12:01:37 +0530328 status = vos_timer_init(&pMac->scan.hTimerStaApConcTimer, VOS_TIMER_TYPE_SW, csrStaApConcTimerHandler, pMac);
329 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700330 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -0800331 smsLog(pMac, LOGE, FL("cannot allocate memory for hTimerStaApConcTimer timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700332 break;
333 }
334#endif
Madan Mohan Koyyalamudi0dea29e2013-07-11 12:01:37 +0530335 status = vos_timer_init(&pMac->scan.hTimerIdleScan, VOS_TIMER_TYPE_SW, csrScanIdleScanTimerHandler, pMac);
336 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700337 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -0800338 smsLog(pMac, LOGE, FL("cannot allocate memory for idleScan timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700339 break;
340 }
Madan Mohan Koyyalamudi0dea29e2013-07-11 12:01:37 +0530341 status = vos_timer_init(&pMac->scan.hTimerResultAging, VOS_TIMER_TYPE_SW, csrScanResultAgingTimerHandler, pMac);
342 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700343 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -0800344 smsLog(pMac, LOGE, FL("cannot allocate memory for ResultAging timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700345 break;
346 }
Madan Mohan Koyyalamudi0dea29e2013-07-11 12:01:37 +0530347 status = vos_timer_init(&pMac->scan.hTimerResultCfgAging, VOS_TIMER_TYPE_SW,
348 csrScanResultCfgAgingTimerHandler, pMac);
349 if (!HAL_STATUS_SUCCESS(status))
Madan Mohan Koyyalamudi7da2fd72012-12-17 14:44:16 -0800350 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -0800351 smsLog(pMac, LOGE, FL("cannot allocate memory for CFG ResultAging timer"));
Madan Mohan Koyyalamudi7da2fd72012-12-17 14:44:16 -0800352 break;
353 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700354 }while(0);
355
356 return (status);
357}
358
359
360eHalStatus csrScanClose( tpAniSirGlobal pMac )
361{
362#ifdef CSR_VALIDATE_LIST
363 g_pchannelPowerInfoList24 = NULL;
364 g_pchannelPowerInfoList5 = NULL;
365 g_pMac = NULL;
366#endif
367 csrLLScanPurgeResult(pMac, &pMac->scan.tempScanResults);
368 csrLLScanPurgeResult(pMac, &pMac->scan.scanResultList);
369#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudi62ee4272012-11-30 17:53:27 -0800370 csrReleaseScanCmdPendingList(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -0700371#endif
372 csrLLClose(&pMac->scan.scanResultList);
373 csrLLClose(&pMac->scan.tempScanResults);
374#ifdef WLAN_AP_STA_CONCURRENCY
375 csrLLClose(&pMac->scan.scanCmdPendingList);
376#endif
377 csrPurgeChannelPower(pMac, &pMac->scan.channelPowerInfoList24);
378 csrPurgeChannelPower(pMac, &pMac->scan.channelPowerInfoList5G);
379 csrLLClose(&pMac->scan.channelPowerInfoList24);
380 csrLLClose(&pMac->scan.channelPowerInfoList5G);
381 csrScanDisable(pMac);
Madan Mohan Koyyalamudi0dea29e2013-07-11 12:01:37 +0530382 vos_timer_destroy(&pMac->scan.hTimerResultAging);
383 vos_timer_destroy(&pMac->scan.hTimerResultCfgAging);
384 vos_timer_destroy(&pMac->scan.hTimerGetResult);
Jeff Johnson295189b2012-06-20 16:38:30 -0700385#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudi0dea29e2013-07-11 12:01:37 +0530386 vos_timer_destroy(&pMac->scan.hTimerStaApConcTimer);
Jeff Johnson295189b2012-06-20 16:38:30 -0700387#endif
Madan Mohan Koyyalamudi0dea29e2013-07-11 12:01:37 +0530388 vos_timer_destroy(&pMac->scan.hTimerIdleScan);
Jeff Johnson295189b2012-06-20 16:38:30 -0700389 return eHAL_STATUS_SUCCESS;
390}
391
392
393eHalStatus csrScanEnable( tpAniSirGlobal pMac )
394{
395
396 pMac->scan.fScanEnable = eANI_BOOLEAN_TRUE;
397 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
398
399 return eHAL_STATUS_SUCCESS;
400}
401
402
403eHalStatus csrScanDisable( tpAniSirGlobal pMac )
404{
405
406 csrScanStopTimers(pMac);
407 pMac->scan.fScanEnable = eANI_BOOLEAN_FALSE;
408
409 return eHAL_STATUS_SUCCESS;
410}
411
412
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700413//Set scan timing parameters according to state of other driver sessions
414//No validation of the parameters is performed.
415static void csrSetDefaultScanTiming( tpAniSirGlobal pMac, tSirScanType scanType, tCsrScanRequest *pScanRequest)
416{
417#ifdef WLAN_AP_STA_CONCURRENCY
418 if(csrIsAnySessionConnected(pMac))
419 {
420 //If multi-session, use the appropriate default scan times
421 if(scanType == eSIR_ACTIVE_SCAN)
422 {
423 pScanRequest->maxChnTime = pMac->roam.configParam.nActiveMaxChnTimeConc;
424 pScanRequest->minChnTime = pMac->roam.configParam.nActiveMinChnTimeConc;
425 }
426 else
427 {
428 pScanRequest->maxChnTime = pMac->roam.configParam.nPassiveMaxChnTimeConc;
429 pScanRequest->minChnTime = pMac->roam.configParam.nPassiveMinChnTimeConc;
430 }
Kiet Lam3cac75e2013-07-12 13:56:44 +0530431 pScanRequest->maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
432 pScanRequest->minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700433
434 pScanRequest->restTime = pMac->roam.configParam.nRestTimeConc;
435
436 //Return so that fields set above will not be overwritten.
437 return;
438 }
439#endif
440
441 //This portion of the code executed if multi-session not supported
442 //(WLAN_AP_STA_CONCURRENCY not defined) or no multi-session.
443 //Use the "regular" (non-concurrency) default scan timing.
444 if(pScanRequest->scanType == eSIR_ACTIVE_SCAN)
445 {
446 pScanRequest->maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
447 pScanRequest->minChnTime = pMac->roam.configParam.nActiveMinChnTime;
448 }
449 else
450 {
451 pScanRequest->maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
452 pScanRequest->minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
453 }
Kiet Lam3cac75e2013-07-12 13:56:44 +0530454 pScanRequest->maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
455 pScanRequest->minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700456
457#ifdef WLAN_AP_STA_CONCURRENCY
458 //No rest time if no sessions are connected.
459 pScanRequest->restTime = 0;
460#endif
461}
462
Jeff Johnson295189b2012-06-20 16:38:30 -0700463#ifdef WLAN_AP_STA_CONCURRENCY
464//Return SUCCESS is the command is queued, else returns eHAL_STATUS_FAILURE
465eHalStatus csrQueueScanRequest( tpAniSirGlobal pMac, tSmeCmd *pScanCmd )
466{
467 eHalStatus status = eHAL_STATUS_SUCCESS;
468
469 tANI_BOOLEAN fNoCmdPending;
470 tSmeCmd *pQueueScanCmd=NULL;
471 tSmeCmd *pSendScanCmd=NULL;
Sudhir Sattayappa Kohalli3466c5f2013-05-22 23:16:42 -0700472 tANI_U8 nNumChanCombinedConc = 0;
Gopichand Nakkalaec931212013-03-25 19:19:46 -0700473 if (NULL == pScanCmd)
474 {
475 smsLog (pMac, LOGE, FL("Scan Req cmd is NULL"));
476 return eHAL_STATUS_FAILURE;
477 }
Madan Mohan Koyyalamudie8d64402012-12-04 16:49:55 -0800478 /* split scan if any one of the following:
479 * - STA session is connected and the scan is not a P2P search
480 * - any P2P session is connected
Madan Mohan Koyyalamudi91482b82012-12-27 17:28:14 -0800481 * Do not split scans if no concurrent infra connections are
482 * active and if the scan is a BG scan triggered by LFR (OR)
483 * any scan if LFR is in the middle of a BG scan. Splitting
484 * the scan is delaying the time it takes for LFR to find
485 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudie8d64402012-12-04 16:49:55 -0800486 */
Sudhir Sattayappa Kohalli3466c5f2013-05-22 23:16:42 -0700487
488 if(csrIsStaSessionConnected(pMac) &&
489 !csrIsP2pSessionConnected(pMac))
490 {
491 nNumChanCombinedConc = pMac->roam.configParam.nNumStaChanCombinedConc;
492 }
493 else if(csrIsP2pSessionConnected(pMac))
494 {
495 nNumChanCombinedConc = pMac->roam.configParam.nNumP2PChanCombinedConc;
496 }
Madan Mohan Koyyalamudi91482b82012-12-27 17:28:14 -0800497 if ( (csrIsStaSessionConnected(pMac) &&
498#ifdef FEATURE_WLAN_LFR
499 (csrIsConcurrentInfraConnected(pMac) ||
500 ((pScanCmd->u.scanCmd.reason != eCsrScanBgScan) &&
501 (pMac->roam.neighborRoamInfo.neighborRoamState !=
502 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
503#endif
504 (pScanCmd->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudi8591f092012-12-17 13:04:30 -0800505 (csrIsP2pSessionConnected(pMac)) )
Jeff Johnson295189b2012-06-20 16:38:30 -0700506 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700507 tCsrScanRequest scanReq;
508 tANI_U8 numChn = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
509 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
510 tANI_U8 channelToScan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
Jeff Johnson295189b2012-06-20 16:38:30 -0700511 tANI_BOOLEAN bMemAlloc = eANI_BOOLEAN_FALSE;
512
513 if (numChn == 0)
514 {
515
516 numChn = pMac->scan.baseChannels.numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -0700517
Kiet Lam3cac75e2013-07-12 13:56:44 +0530518 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(numChn);
519 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -0700520 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -0800521 smsLog( pMac, LOGE, FL(" Failed to get memory for channel list ") );
Madan Mohan Koyyalamudi8591f092012-12-17 13:04:30 -0800522 return eHAL_STATUS_FAILURE;
523 }
524 bMemAlloc = eANI_BOOLEAN_TRUE;
Kiet Lam3cac75e2013-07-12 13:56:44 +0530525 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
526 pMac->scan.baseChannels.channelList, numChn);
527 status = eHAL_STATUS_SUCCESS;
Madan Mohan Koyyalamudi8591f092012-12-17 13:04:30 -0800528 if( !HAL_STATUS_SUCCESS( status ) )
529 {
Kiet Lam3cac75e2013-07-12 13:56:44 +0530530 vos_mem_free(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
Madan Mohan Koyyalamudi8591f092012-12-17 13:04:30 -0800531 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -0800532 smsLog( pMac, LOGE, FL(" Failed to copy memory to channel list ") );
Madan Mohan Koyyalamudi8591f092012-12-17 13:04:30 -0800533 return eHAL_STATUS_FAILURE;
534 }
535 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = numChn;
536 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700537
Madan Mohan Koyyalamudi8591f092012-12-17 13:04:30 -0800538 //Whenever we get a scan request with multiple channels we break it up into 2 requests
539 //First request for first channel to scan and second request to scan remaining channels
Sudhir Sattayappa Kohalli3466c5f2013-05-22 23:16:42 -0700540 if ( numChn > nNumChanCombinedConc)
Madan Mohan Koyyalamudi8591f092012-12-17 13:04:30 -0800541 {
Kiet Lam3cac75e2013-07-12 13:56:44 +0530542 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Madan Mohan Koyyalamudi8591f092012-12-17 13:04:30 -0800543
544 pQueueScanCmd = csrGetCommandBuffer(pMac); //optimize this to use 2 command buffer only
545 if (!pQueueScanCmd)
546 {
547 if (bMemAlloc)
Jeff Johnson295189b2012-06-20 16:38:30 -0700548 {
Kiet Lam3cac75e2013-07-12 13:56:44 +0530549 vos_mem_free(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
Madan Mohan Koyyalamudi8591f092012-12-17 13:04:30 -0800550 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
551
Jeff Johnson295189b2012-06-20 16:38:30 -0700552 }
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -0800553 smsLog( pMac, LOGE, FL(" Failed to get Queue command buffer") );
Madan Mohan Koyyalamudi8591f092012-12-17 13:04:30 -0800554 return eHAL_STATUS_FAILURE;
555 }
556 pQueueScanCmd->command = pScanCmd->command;
557 pQueueScanCmd->sessionId = pScanCmd->sessionId;
558 pQueueScanCmd->u.scanCmd.callback = pScanCmd->u.scanCmd.callback;
559 pQueueScanCmd->u.scanCmd.pContext = pScanCmd->u.scanCmd.pContext;
560 pQueueScanCmd->u.scanCmd.reason = pScanCmd->u.scanCmd.reason;
561 pQueueScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Jeff Johnson295189b2012-06-20 16:38:30 -0700562
Madan Mohan Koyyalamudi8591f092012-12-17 13:04:30 -0800563 /* First copy all the parameters to local variable of scan request */
564 csrScanCopyRequest(pMac, &scanReq, &pScanCmd->u.scanCmd.u.scanRequest);
Madan Mohan Koyyalamudiaf2a8b92012-10-09 14:58:07 -0700565
Madan Mohan Koyyalamudi8591f092012-12-17 13:04:30 -0800566 /* Now modify the elements of local var scan request required to be modified for split scan */
567 if(scanReq.ChannelInfo.ChannelList != NULL)
568 {
Kiet Lam3cac75e2013-07-12 13:56:44 +0530569 vos_mem_free(scanReq.ChannelInfo.ChannelList);
Madan Mohan Koyyalamudi66554132012-11-30 15:10:25 -0800570 scanReq.ChannelInfo.ChannelList = NULL;
Madan Mohan Koyyalamudi8591f092012-12-17 13:04:30 -0800571 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700572
Sudhir Sattayappa Kohalli3466c5f2013-05-22 23:16:42 -0700573 pChnInfo->numOfChannels = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels - nNumChanCombinedConc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700574
Madan Mohan Koyyalamudi8591f092012-12-17 13:04:30 -0800575 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_WARN,
Gopichand Nakkalae8997bd2013-04-10 11:36:29 +0530576 FL(" &channelToScan %p pScanCmd(%p) pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList(%p)numChn(%d)"),
577 &channelToScan[0], pScanCmd,
578 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList, numChn);
Jeff Johnson295189b2012-06-20 16:38:30 -0700579
Kiet Lam3cac75e2013-07-12 13:56:44 +0530580 vos_mem_copy(&channelToScan[0],
581 &pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[
582 nNumChanCombinedConc],
583 pChnInfo->numOfChannels * sizeof(tANI_U8));
Madan Mohan Koyyalamudi8591f092012-12-17 13:04:30 -0800584
585 pChnInfo->ChannelList = &channelToScan[0];
586
587 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
588 //Modify callers parameters in case of concurrency
Madan Mohan Koyyalamudi1c655902013-07-26 13:58:38 +0530589 if (!pScanCmd->u.scanCmd.u.scanRequest.bcnRptReqScan)
590 scanReq.scanType = eSIR_ACTIVE_SCAN;
Madan Mohan Koyyalamudi8591f092012-12-17 13:04:30 -0800591 //Use concurrency values for min/maxChnTime.
592 //We know csrIsAnySessionConnected(pMac) returns TRUE here
593 csrSetDefaultScanTiming(pMac, scanReq.scanType, &scanReq);
594
595 status = csrScanCopyRequest(pMac, &pQueueScanCmd->u.scanCmd.u.scanRequest, &scanReq);
596
597 if(!HAL_STATUS_SUCCESS(status))
598 {
599 if (bMemAlloc)
600 {
Kiet Lam3cac75e2013-07-12 13:56:44 +0530601 vos_mem_free(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
Madan Mohan Koyyalamudi8591f092012-12-17 13:04:30 -0800602 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
603
604 }
605 if( scanReq.pIEField != NULL)
606 {
Kiet Lam3cac75e2013-07-12 13:56:44 +0530607 vos_mem_free(scanReq.pIEField);
Madan Mohan Koyyalamudi8591f092012-12-17 13:04:30 -0800608 scanReq.pIEField = NULL;
609 }
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -0800610 smsLog( pMac, LOGE, FL(" Failed to get copy csrScanRequest = %d"), status );
Madan Mohan Koyyalamudi8591f092012-12-17 13:04:30 -0800611 return eHAL_STATUS_FAILURE;
612 }
613 /* Clean the local scan variable */
614 scanReq.ChannelInfo.ChannelList = NULL;
615 scanReq.ChannelInfo.numOfChannels = 0;
616 csrScanFreeRequest(pMac, &scanReq);
617
618 /* setup the command to scan 2 channels */
619 pSendScanCmd = pScanCmd;
Sudhir Sattayappa Kohalli3466c5f2013-05-22 23:16:42 -0700620 pSendScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nNumChanCombinedConc;
Madan Mohan Koyyalamudi8591f092012-12-17 13:04:30 -0800621 pSendScanCmd->u.scanCmd.u.scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
Madan Mohan Koyyalamudi1c655902013-07-26 13:58:38 +0530622 if (!pSendScanCmd->u.scanCmd.u.scanRequest.bcnRptReqScan)
623 pSendScanCmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Madan Mohan Koyyalamudi8591f092012-12-17 13:04:30 -0800624 //Use concurrency values for min/maxChnTime.
625 //We know csrIsAnySessionConnected(pMac) returns TRUE here
626 csrSetDefaultScanTiming(pMac, pSendScanCmd->u.scanCmd.u.scanRequest.scanType, &pSendScanCmd->u.scanCmd.u.scanRequest);
627 pSendScanCmd->u.scanCmd.callback = NULL;
628 } else {
629 pSendScanCmd = pScanCmd;
630 pSendScanCmd->u.scanCmd.u.scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
Madan Mohan Koyyalamudi1c655902013-07-26 13:58:38 +0530631 if (!pSendScanCmd->u.scanCmd.u.scanRequest.bcnRptReqScan)
632 pSendScanCmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Madan Mohan Koyyalamudi8591f092012-12-17 13:04:30 -0800633 //Use concurrency values for min/maxChnTime.
634 //We know csrIsAnySessionConnected(pMac) returns TRUE here
635 csrSetDefaultScanTiming(pMac, pSendScanCmd->u.scanCmd.u.scanRequest.scanType, &pSendScanCmd->u.scanCmd.u.scanRequest);
636 }
637
638 fNoCmdPending = csrLLIsListEmpty( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK );
639
640 //Logic Below is as follows
641 // If the scanCmdPendingList is empty then we directly send that command
642 // to smeCommandQueue else we buffer it in our scanCmdPendingList Queue
643 if( fNoCmdPending )
644 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700645 if (pQueueScanCmd != NULL)
646 {
Madan Mohan Koyyalamudi8591f092012-12-17 13:04:30 -0800647 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pQueueScanCmd->Link, LL_ACCESS_LOCK );
Jeff Johnson295189b2012-06-20 16:38:30 -0700648 }
649
650 if (pSendScanCmd != NULL)
651 {
652 return csrQueueSmeCommand(pMac, pSendScanCmd, eANI_BOOLEAN_FALSE);
653 }
Madan Mohan Koyyalamudi8591f092012-12-17 13:04:30 -0800654 }
655 else
656 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700657 if (pSendScanCmd != NULL)
658 {
659 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pSendScanCmd->Link, LL_ACCESS_LOCK );
660 }
Madan Mohan Koyyalamudi8591f092012-12-17 13:04:30 -0800661
Jeff Johnson295189b2012-06-20 16:38:30 -0700662 if (pQueueScanCmd != NULL)
663 {
664 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pQueueScanCmd->Link, LL_ACCESS_LOCK );
665 }
Madan Mohan Koyyalamudi8591f092012-12-17 13:04:30 -0800666 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700667 }
668 else
669 { //No concurrency case
Madan Mohan Koyyalamudi91482b82012-12-27 17:28:14 -0800670 smsLog( pMac, LOG2, FL("Queuing scan command (reason=%d, roamState=%d"
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -0800671 " numOfChannels=%d)"),
Madan Mohan Koyyalamudi91482b82012-12-27 17:28:14 -0800672 pScanCmd->u.scanCmd.reason,
673 pMac->roam.neighborRoamInfo.neighborRoamState,
674 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -0700675 return csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
676 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700677
678 return ( status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700679}
680#endif
681
Jeff Johnsone7245742012-09-05 17:12:55 -0700682/* ---------------------------------------------------------------------------
683 \fn csrScan2GOnyRequest
684 \brief This function will update the scan request with only
Jeff Johnsonbf9616f2012-12-10 13:34:59 -0800685 2.4GHz valid channel list.
Jeff Johnsone7245742012-09-05 17:12:55 -0700686 \param pMac
687 \param pScanCmd
688 \param pScanRequest
689 \return None
690 -------------------------------------------------------------------------------*/
691static void csrScan2GOnyRequest(tpAniSirGlobal pMac,tSmeCmd *pScanCmd,
692 tCsrScanRequest *pScanRequest)
693{
694 tANI_U8 index, channelId, channelListSize = 0;
695 tANI_U8 channelList2G[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
696 static tANI_U8 validchannelList[CSR_MAX_2_4_GHZ_SUPPORTED_CHANNELS] = {0};
697
698 VOS_ASSERT(pScanCmd && pScanRequest);
Madan Mohan Koyyalamudi33ef6a22012-10-30 17:44:43 -0700699 /* To silence the KW tool null check is added */
700 if((pScanCmd == NULL) || (pScanRequest == NULL))
701 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -0800702 smsLog( pMac, LOGE, FL(" pScanCmd or pScanRequest is NULL "));
Madan Mohan Koyyalamudi33ef6a22012-10-30 17:44:43 -0700703 return;
704 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700705
706 if (pScanCmd->u.scanCmd.scanID ||
707 (eCSR_SCAN_REQUEST_FULL_SCAN != pScanRequest->requestType))
708 return;
709
710 //Contsruct valid Supported 2.4 GHz Channel List
711 for( index = 0; index < ARRAY_SIZE(channelList2G); index++ )
712 {
713 channelId = channelList2G[index];
714 if ( csrIsSupportedChannel( pMac, channelId ) )
715 {
716 validchannelList[channelListSize++] = channelId;
717 }
718 }
719
720 pScanRequest->ChannelInfo.numOfChannels = channelListSize;
721 pScanRequest->ChannelInfo.ChannelList = validchannelList;
722}
723
Jeff Johnson295189b2012-06-20 16:38:30 -0700724eHalStatus csrScanRequest(tpAniSirGlobal pMac, tANI_U16 sessionId,
725 tCsrScanRequest *pScanRequest, tANI_U32 *pScanRequestID,
726 csrScanCompleteCallback callback, void *pContext)
727{
728 eHalStatus status = eHAL_STATUS_FAILURE;
729 tSmeCmd *pScanCmd = NULL;
Madan Mohan Koyyalamudicb90bb22012-10-30 18:24:43 -0700730 eCsrConnectState ConnectState;
Jeff Johnson295189b2012-06-20 16:38:30 -0700731
Gopichand Nakkala79353d12012-12-31 16:31:46 -0800732 if(pScanRequest == NULL)
733 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -0800734 smsLog( pMac, LOGE, FL(" pScanRequest is NULL"));
Gopichand Nakkala79353d12012-12-31 16:31:46 -0800735 VOS_ASSERT(0);
736 }
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700737
Kiet Lam83cd0002013-11-05 20:45:04 +0530738 /* During group formation, the P2P client scans for GO with the specific SSID.
739 * There will be chances of GO switching to other channels because of scan or
740 * to STA channel in case of STA+GO MCC scenario. So to increase the possibility
741 * of client to find the GO, the dwell time of scan is increased to 100ms.
742 */
743 if(pScanRequest->p2pSearch)
744 {
Rashmi Ramanna84a8f0d2013-12-20 09:04:12 +0530745 if(pScanRequest->SSIDs.numOfSSIDs)
Kiet Lam83cd0002013-11-05 20:45:04 +0530746 {
Rashmi Ramanna84a8f0d2013-12-20 09:04:12 +0530747 //If the scan request is for specific SSId the length of SSID will be
748 //greater than 7 as SSID for p2p search contains "DIRECT-")
749 if(pScanRequest->SSIDs.SSIDList->SSID.length > DIRECT_SSID_LEN)
750 {
Vinay Krishna Eranna93923f62013-12-18 20:49:08 +0530751 smsLog( pMac, LOG1, FL("P2P: Increasing the min and max Dwell"
752 " time to %d for specific SSID scan %.*s"),
753 MAX_CHN_TIME_TO_FIND_GO,
754 pScanRequest->SSIDs.SSIDList->SSID.length,
755 pScanRequest->SSIDs.SSIDList->SSID.ssId);
Rashmi Ramanna84a8f0d2013-12-20 09:04:12 +0530756 pScanRequest->maxChnTime = MAX_CHN_TIME_TO_FIND_GO;
757 pScanRequest->minChnTime = MIN_CHN_TIME_TO_FIND_GO;
758 }
Kiet Lam83cd0002013-11-05 20:45:04 +0530759 }
760 }
761
Jeff Johnson295189b2012-06-20 16:38:30 -0700762 do
763 {
764 if(pMac->scan.fScanEnable)
765 {
766 pScanCmd = csrGetCommandBuffer(pMac);
767 if(pScanCmd)
768 {
Kiet Lam3cac75e2013-07-12 13:56:44 +0530769 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -0700770 pScanCmd->command = eSmeCommandScan;
771 pScanCmd->sessionId = sessionId;
772 pScanCmd->u.scanCmd.callback = callback;
773 pScanCmd->u.scanCmd.pContext = pContext;
774 if(eCSR_SCAN_REQUEST_11D_SCAN == pScanRequest->requestType)
775 {
776 pScanCmd->u.scanCmd.reason = eCsrScan11d1;
777 }
778 else if((eCSR_SCAN_REQUEST_FULL_SCAN == pScanRequest->requestType) ||
779 (eCSR_SCAN_P2P_DISCOVERY == pScanRequest->requestType)
780#ifdef SOFTAP_CHANNEL_RANGE
781 ||(eCSR_SCAN_SOFTAP_CHANNEL_RANGE == pScanRequest->requestType)
782#endif
783 )
784 {
785 pScanCmd->u.scanCmd.reason = eCsrScanUserRequest;
786 }
787 else if(eCSR_SCAN_HO_BG_SCAN == pScanRequest->requestType)
788 {
789 pScanCmd->u.scanCmd.reason = eCsrScanBgScan;
790 }
791 else if(eCSR_SCAN_HO_PROBE_SCAN == pScanRequest->requestType)
792 {
793 pScanCmd->u.scanCmd.reason = eCsrScanProbeBss;
794 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700795 else if(eCSR_SCAN_P2P_FIND_PEER == pScanRequest->requestType)
796 {
797 pScanCmd->u.scanCmd.reason = eCsrScanP2PFindPeer;
798 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700799 else
800 {
801 pScanCmd->u.scanCmd.reason = eCsrScanIdleScan;
802 }
803 if(pScanRequest->minChnTime == 0 && pScanRequest->maxChnTime == 0)
804 {
805 //The caller doesn't set the time correctly. Set it here
Vinay Krishna Eranna93923f62013-12-18 20:49:08 +0530806 csrSetDefaultScanTiming(pMac, pScanRequest->scanType,
807 pScanRequest);
808 smsLog(pMac, LOG1, FL("Setting default min %d and max %d"
809 " ChnTime"), pScanRequest->minChnTime,
810 pScanRequest->maxChnTime);
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700811 }
812#ifdef WLAN_AP_STA_CONCURRENCY
813 if(pScanRequest->restTime == 0)
Kiran Kumar Lokere30b07722013-02-24 22:21:28 -0800814 {
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700815 //Need to set restTime only if at least one session is connected
816 if(csrIsAnySessionConnected(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -0700817 {
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700818 pScanRequest->restTime = pMac->roam.configParam.nRestTimeConc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700819 }
820 }
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700821#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -0700822 /*For Standalone wlan : channel time will remain the same.
Madan Mohan Koyyalamudi0dea29e2013-07-11 12:01:37 +0530823 For BTC with A2DP up: Channel time = Channel time * 2, if station is not already associated.
Kiran Kumar Lokere30b07722013-02-24 22:21:28 -0800824 This has been done to provide a larger scan window for faster connection during btc.Else Scan is seen
825 to take a long time.
826 For BTC with A2DP up: Channel time will not be doubled, if station is already associated.
827 */
Jeff Johnson32d95a32012-09-10 13:15:23 -0700828 status = csrRoamGetConnectState(pMac,sessionId,&ConnectState);
Srinivas Girigowdafe1e2882013-02-19 17:41:56 -0800829 if (HAL_STATUS_SUCCESS(status) &&
830 pMac->btc.fA2DPUp &&
Jeff Johnson32d95a32012-09-10 13:15:23 -0700831 (eCSR_ASSOC_STATE_TYPE_INFRA_ASSOCIATED != ConnectState) &&
832 (eCSR_ASSOC_STATE_TYPE_IBSS_CONNECTED != ConnectState))
833 {
834 pScanRequest->maxChnTime = pScanRequest->maxChnTime << 1;
835 pScanRequest->minChnTime = pScanRequest->minChnTime << 1;
Vinay Krishna Eranna93923f62013-12-18 20:49:08 +0530836 smsLog( pMac, LOG1, FL("BTC A2DP up, doubling max and min"
837 " ChnTime (Max=%d Min=%d)"),
838 pScanRequest->maxChnTime,
839 pScanRequest->minChnTime);
Jeff Johnson32d95a32012-09-10 13:15:23 -0700840 }
Kiran Kumar Lokere30b07722013-02-24 22:21:28 -0800841
Kiet Lam3cac75e2013-07-12 13:56:44 +0530842 pScanRequest->maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
843 pScanRequest->minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700844 //Need to make the following atomic
845 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
846
847 if(pScanRequestID)
848 {
849 *pScanRequestID = pScanCmd->u.scanCmd.scanID;
850 }
851
Gopichand Nakkala79353d12012-12-31 16:31:46 -0800852 // If it is the first scan request from HDD, CSR checks if it is for 11d.
Jeff Johnson295189b2012-06-20 16:38:30 -0700853 // If it is not, CSR will save the scan request in the pending cmd queue
854 // & issue an 11d scan request to PE.
Kiran Kumar Lokere30b07722013-02-24 22:21:28 -0800855 if (((0 == pScanCmd->u.scanCmd.scanID)
Jeff Johnson295189b2012-06-20 16:38:30 -0700856 && (eCSR_SCAN_REQUEST_11D_SCAN != pScanRequest->requestType))
857#ifdef SOFTAP_CHANNEL_RANGE
858 && (eCSR_SCAN_SOFTAP_CHANNEL_RANGE != pScanRequest->requestType)
859#endif
860 && (eANI_BOOLEAN_FALSE == pMac->scan.fEnableBypass11d)
861 )
862 {
863 tSmeCmd *p11dScanCmd;
864 tCsrScanRequest scanReq;
865 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
866
Kiet Lam3cac75e2013-07-12 13:56:44 +0530867 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -0700868
869 p11dScanCmd = csrGetCommandBuffer(pMac);
Kiran Kumar Lokere30b07722013-02-24 22:21:28 -0800870 if (p11dScanCmd)
Jeff Johnson295189b2012-06-20 16:38:30 -0700871 {
872 tANI_U32 numChn = pMac->scan.baseChannels.numChannels;
873
Kiet Lam3cac75e2013-07-12 13:56:44 +0530874 vos_mem_set(&p11dScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
875 pChnInfo->ChannelList = vos_mem_malloc(numChn);
876 if ( NULL == pChnInfo->ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -0700877 {
Vinay Krishna Eranna93923f62013-12-18 20:49:08 +0530878 smsLog(pMac, LOGE, FL("Failed to allocate memory"));
879 status = eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -0700880 break;
881 }
Vinay Krishna Eranna93923f62013-12-18 20:49:08 +0530882 vos_mem_copy(pChnInfo->ChannelList,
883 pMac->scan.baseChannels.channelList,
884 numChn);
Jeff Johnson295189b2012-06-20 16:38:30 -0700885 pChnInfo->numOfChannels = (tANI_U8)numChn;
Vinay Krishna Eranna93923f62013-12-18 20:49:08 +0530886
Jeff Johnson295189b2012-06-20 16:38:30 -0700887 p11dScanCmd->command = eSmeCommandScan;
Mihir Shetea6150b62014-01-27 11:30:05 +0530888 p11dScanCmd->u.scanCmd.callback = pMac->scan.callback11dScanDone;
Jeff Johnson295189b2012-06-20 16:38:30 -0700889 p11dScanCmd->u.scanCmd.pContext = NULL;
890 p11dScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++;
891 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
892
893 if ( csrIs11dSupported(pMac) )
894 {
Madan Mohan Koyyalamudi1c655902013-07-26 13:58:38 +0530895 scanReq.bcnRptReqScan = pScanRequest->bcnRptReqScan;
896 if (pScanRequest->bcnRptReqScan)
897 scanReq.scanType = pScanRequest->scanType ?
898 eSIR_PASSIVE_SCAN :
899 pScanRequest->scanType;
900 else
901 scanReq.scanType = eSIR_PASSIVE_SCAN;
Jeff Johnson295189b2012-06-20 16:38:30 -0700902 scanReq.requestType = eCSR_SCAN_REQUEST_11D_SCAN;
903 p11dScanCmd->u.scanCmd.reason = eCsrScan11d1;
904 scanReq.maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
905 scanReq.minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
906 }
907 else
908 {
Madan Mohan Koyyalamudi1c655902013-07-26 13:58:38 +0530909 scanReq.bcnRptReqScan = pScanRequest->bcnRptReqScan;
910 if (pScanRequest->bcnRptReqScan)
911 scanReq.scanType = pScanRequest->scanType;
912 else
913 scanReq.scanType = eSIR_ACTIVE_SCAN;
Jeff Johnson295189b2012-06-20 16:38:30 -0700914 scanReq.requestType = eCSR_SCAN_IDLE_MODE_SCAN;
915 p11dScanCmd->u.scanCmd.reason = eCsrScanIdleScan;
916 scanReq.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
917 scanReq.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere30b07722013-02-24 22:21:28 -0800918
Madan Mohan Koyyalamudi1c655902013-07-26 13:58:38 +0530919 scanReq.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
920 scanReq.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700921 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700922
Jeff Johnson295189b2012-06-20 16:38:30 -0700923 status = csrScanCopyRequest(pMac, &p11dScanCmd->u.scanCmd.u.scanRequest, &scanReq);
924 //Free the channel list
Kiet Lam3cac75e2013-07-12 13:56:44 +0530925 vos_mem_free(pChnInfo->ChannelList);
James Zmudaac3ad1b2013-04-18 18:20:54 -0700926 pChnInfo->ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -0700927
Kiran Kumar Lokere30b07722013-02-24 22:21:28 -0800928 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700929 {
krunal soni6fd05dd2013-11-25 15:00:11 -0800930 pMac->scan.scanProfile.numOfChannels =
931 p11dScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -0700932 //Start process the command
933#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudi8f3583f2013-06-19 16:34:44 +0530934 if (!pMac->fScanOffload)
935 status = csrQueueScanRequest(pMac, p11dScanCmd);
936 else
937 status = csrQueueSmeCommand(pMac, p11dScanCmd,
938 eANI_BOOLEAN_FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -0700939#else
940 status = csrQueueSmeCommand(pMac, p11dScanCmd, eANI_BOOLEAN_FALSE);
941#endif
942 if( !HAL_STATUS_SUCCESS( status ) )
943 {
Vinay Krishna Eranna93923f62013-12-18 20:49:08 +0530944 smsLog(pMac, LOGE, FL("Failed to send message"
945 " status = %d"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -0700946 break;
947 }
948 }
949 else
950 {
Vinay Krishna Eranna93923f62013-12-18 20:49:08 +0530951 smsLog(pMac, LOGE, FL("csrScanCopyRequest failed"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700952 break;
953 }
954 }
955 else
956 {
957 //error
Vinay Krishna Eranna93923f62013-12-18 20:49:08 +0530958 smsLog( pMac, LOGE, FL("p11dScanCmd failed") );
Jeff Johnson295189b2012-06-20 16:38:30 -0700959 break;
960 }
961 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700962
963 //Scan only 2G Channels if set in ini file
964 //This is mainly to reduce the First Scan duration
965 //Once we turn on Wifi
966 if(pMac->scan.fFirstScanOnly2GChnl)
967 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -0800968 smsLog( pMac, LOG1, FL("Scanning only 2G Channels during first scan"));
Jeff Johnsone7245742012-09-05 17:12:55 -0700969 csrScan2GOnyRequest(pMac, pScanCmd, pScanRequest);
970 }
971
Jeff Johnson295189b2012-06-20 16:38:30 -0700972 status = csrScanCopyRequest(pMac, &pScanCmd->u.scanCmd.u.scanRequest, pScanRequest);
973 if(HAL_STATUS_SUCCESS(status))
974 {
Vinay Krishna Eranna93923f62013-12-18 20:49:08 +0530975 tCsrScanRequest *pTempScanReq =
976 &pScanCmd->u.scanCmd.u.scanRequest;
krunal soni6fd05dd2013-11-25 15:00:11 -0800977 pMac->scan.scanProfile.numOfChannels =
Vinay Krishna Eranna93923f62013-12-18 20:49:08 +0530978 pTempScanReq->ChannelInfo.numOfChannels;
krunal soni6fd05dd2013-11-25 15:00:11 -0800979
Vinay Krishna Eranna93923f62013-12-18 20:49:08 +0530980 smsLog( pMac, LOG1, FL(" SId=%d scanId=%d"
981 " Scan reason=%u numSSIDs=%d"
982 " numChan=%d P2P search=%d minCT=%d maxCT=%d"
983 " minCBtc=%d maxCBtx=%d"),
984 sessionId, pScanCmd->u.scanCmd.scanID,
985 pScanCmd->u.scanCmd.reason,
986 pTempScanReq->SSIDs.numOfSSIDs,
987 pTempScanReq->ChannelInfo.numOfChannels,
988 pTempScanReq->p2pSearch,
989 pTempScanReq->minChnTime,
990 pTempScanReq->maxChnTime,
991 pTempScanReq->minChnTimeBtc,
992 pTempScanReq->maxChnTimeBtc );
Jeff Johnson295189b2012-06-20 16:38:30 -0700993 //Start process the command
994#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudi8f3583f2013-06-19 16:34:44 +0530995 if (!pMac->fScanOffload)
996 status = csrQueueScanRequest(pMac,pScanCmd);
997 else
998 status = csrQueueSmeCommand(pMac, pScanCmd,
999 eANI_BOOLEAN_FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -07001000#else
Vinay Krishna Eranna93923f62013-12-18 20:49:08 +05301001 status = csrQueueSmeCommand(pMac, pScanCmd,
1002 eANI_BOOLEAN_FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -07001003#endif
1004 if( !HAL_STATUS_SUCCESS( status ) )
1005 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08001006 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001007 break;
1008 }
1009 }
1010 else
1011 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08001012 smsLog( pMac, LOGE, FL(" fail to copy request status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001013 break;
1014 }
1015 }
1016 else
1017 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08001018 smsLog( pMac, LOGE, FL(" pScanCmd is NULL"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001019 break;
1020 }
1021 }
Vinay Krishna Eranna93923f62013-12-18 20:49:08 +05301022 else
1023 {
1024 smsLog( pMac, LOGE, FL("SId: %d Scanning not enabled"
1025 " Scan type=%u, numOfSSIDs=%d P2P search=%d"),
1026 sessionId, pScanRequest->requestType,
1027 pScanRequest->SSIDs.numOfSSIDs,
1028 pScanRequest->p2pSearch );
1029 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001030 } while(0);
Vinay Krishna Eranna93923f62013-12-18 20:49:08 +05301031
1032
Jeff Johnson295189b2012-06-20 16:38:30 -07001033 if(!HAL_STATUS_SUCCESS(status) && pScanCmd)
1034 {
1035 if( eCsrScanIdleScan == pScanCmd->u.scanCmd.reason )
1036 {
1037 //Set the flag back for restarting idle scan
1038 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
1039 }
Vinay Krishna Eranna93923f62013-12-18 20:49:08 +05301040 smsLog( pMac, LOGE, FL(" SId: %d Failed with status=%d"
1041 " Scan reason=%u numOfSSIDs=%d"
1042 " P2P search=%d scanId=%d"),
1043 sessionId, status, pScanCmd->u.scanCmd.reason,
1044 pScanRequest->SSIDs.numOfSSIDs, pScanRequest->p2pSearch,
1045 pScanCmd->u.scanCmd.scanID );
Jeff Johnson295189b2012-06-20 16:38:30 -07001046 csrReleaseCommandScan(pMac, pScanCmd);
1047 }
1048
1049 return (status);
1050}
1051
1052
1053eHalStatus csrScanRequestResult(tpAniSirGlobal pMac)
1054{
1055 eHalStatus status = eHAL_STATUS_SUCCESS;
1056 tSmeCmd *pScanCmd;
1057
1058 if(pMac->scan.fScanEnable)
1059 {
1060 pScanCmd = csrGetCommandBuffer(pMac);
1061 if(pScanCmd)
1062 {
1063 pScanCmd->command = eSmeCommandScan;
Kiet Lam3cac75e2013-07-12 13:56:44 +05301064 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001065 pScanCmd->u.scanCmd.callback = NULL;
1066 pScanCmd->u.scanCmd.pContext = NULL;
1067 pScanCmd->u.scanCmd.reason = eCsrScanGetResult;
1068 //Need to make the following atomic
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07001069 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID; //let it wrap around
Jeff Johnson295189b2012-06-20 16:38:30 -07001070 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
1071 if( !HAL_STATUS_SUCCESS( status ) )
1072 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08001073 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001074 csrReleaseCommandScan(pMac, pScanCmd);
1075 }
1076 }
1077 else
1078 {
1079 //log error
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08001080 smsLog(pMac, LOGE, FL("can not obtain a common buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001081 status = eHAL_STATUS_RESOURCES;
1082 }
1083 }
1084
1085 return (status);
1086}
1087
Varun Reddy Yeturu08614702013-04-15 21:58:13 -07001088#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
1089eHalStatus csrScanRequestLfrResult(tpAniSirGlobal pMac, tANI_U32 sessionId,
1090 csrScanCompleteCallback callback, void *pContext)
1091{
1092 eHalStatus status = eHAL_STATUS_SUCCESS;
1093 tSmeCmd *pScanCmd;
1094
1095 if (pMac->scan.fScanEnable)
1096 {
1097 pScanCmd = csrGetCommandBuffer(pMac);
1098 if (pScanCmd)
1099 {
1100 pScanCmd->command = eSmeCommandScan;
1101 pScanCmd->sessionId = sessionId;
Kiet Lam3cac75e2013-07-12 13:56:44 +05301102 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Varun Reddy Yeturu08614702013-04-15 21:58:13 -07001103 pScanCmd->u.scanCmd.callback = callback;
1104 pScanCmd->u.scanCmd.pContext = pContext;
1105 pScanCmd->u.scanCmd.reason = eCsrScanGetLfrResult;
1106 //Need to make the following atomic
1107 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID; //let it wrap around
1108 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_TRUE);
1109 if ( !HAL_STATUS_SUCCESS( status ) )
1110 {
1111 smsLog( pMac, LOGE, FL(" fail to send message status = %d\n"), status );
1112 csrReleaseCommandScan(pMac, pScanCmd);
1113 }
1114 }
1115 else
1116 {
1117 //log error
1118 smsLog(pMac, LOGE, FL("can not obtain a common buffer\n"));
1119 status = eHAL_STATUS_RESOURCES;
1120 }
1121 }
1122
1123 return (status);
1124}
1125#endif //WLAN_FEATURE_ROAM_SCAN_OFFLOAD
Jeff Johnson295189b2012-06-20 16:38:30 -07001126
1127eHalStatus csrScanAllChannels(tpAniSirGlobal pMac, eCsrRequestType reqType)
1128{
1129 eHalStatus status = eHAL_STATUS_SUCCESS;
1130 tANI_U32 scanId;
1131 tCsrScanRequest scanReq;
1132
Kiet Lam3cac75e2013-07-12 13:56:44 +05301133 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001134 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
1135 scanReq.scanType = eSIR_ACTIVE_SCAN;
1136 scanReq.requestType = reqType;
1137 scanReq.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1138 scanReq.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere30b07722013-02-24 22:21:28 -08001139 scanReq.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1140 scanReq.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001141 //Scan with invalid sessionId.
1142 //This results in SME using the first available session to scan.
1143 status = csrScanRequest(pMac, CSR_SESSION_ID_INVALID, &scanReq,
1144 &scanId, NULL, NULL);
1145
1146 return (status);
1147}
1148
1149
1150
1151
1152eHalStatus csrIssueRoamAfterLostlinkScan(tpAniSirGlobal pMac, tANI_U32 sessionId, eCsrRoamReason reason)
1153{
1154 eHalStatus status = eHAL_STATUS_FAILURE;
1155 tScanResultHandle hBSSList = NULL;
1156 tCsrScanResultFilter *pScanFilter = NULL;
1157 tANI_U32 roamId = 0;
1158 tCsrRoamProfile *pProfile = NULL;
1159 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1160
Jeff Johnson32d95a32012-09-10 13:15:23 -07001161 if(!pSession)
1162 {
1163 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1164 return eHAL_STATUS_FAILURE;
1165 }
1166
Jeff Johnson295189b2012-06-20 16:38:30 -07001167 do
1168 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08001169 smsLog(pMac, LOG1, " csrIssueRoamAfterLostlinkScan called");
Jeff Johnson295189b2012-06-20 16:38:30 -07001170 if(pSession->fCancelRoaming)
1171 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08001172 smsLog(pMac, LOGW, " lostlink roaming is cancelled");
Jeff Johnson295189b2012-06-20 16:38:30 -07001173 csrScanStartIdleScan(pMac);
1174 status = eHAL_STATUS_SUCCESS;
1175 break;
1176 }
1177 //Here is the profile we need to connect to
Kiet Lam3cac75e2013-07-12 13:56:44 +05301178 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1179 if ( NULL == pScanFilter)
1180 status = eHAL_STATUS_FAILURE;
1181 else
1182 status = eHAL_STATUS_SUCCESS;
1183 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001184 break;
Kiet Lam3cac75e2013-07-12 13:56:44 +05301185 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001186 if(NULL == pSession->pCurRoamProfile)
1187 {
1188 pScanFilter->EncryptionType.numEntries = 1;
1189 pScanFilter->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_NONE;
1190 }
1191 else
1192 {
1193 //We have to make a copy of pCurRoamProfile because it will be free inside csrRoamIssueConnect
Kiet Lam3cac75e2013-07-12 13:56:44 +05301194 pProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1195 if ( NULL == pProfile )
1196 status = eHAL_STATUS_FAILURE;
1197 else
1198 status = eHAL_STATUS_SUCCESS;
1199 if (!HAL_STATUS_SUCCESS(status))
1200 break;
1201 vos_mem_set(pProfile, sizeof(tCsrRoamProfile), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001202 status = csrRoamCopyProfile(pMac, pProfile, pSession->pCurRoamProfile);
1203 if(!HAL_STATUS_SUCCESS(status))
1204 break;
1205 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1206 }//We have a profile
1207 roamId = GET_NEXT_ROAM_ID(&pMac->roam);
1208 if(HAL_STATUS_SUCCESS(status))
1209 {
1210 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1211 if(HAL_STATUS_SUCCESS(status))
1212 {
1213 if(eCsrLostLink1 == reason)
1214 {
1215 //we want to put the last connected BSS to the very beginning, if possible
1216 csrMoveBssToHeadFromBSSID(pMac, &pSession->connectedProfile.bssid, hBSSList);
1217 }
1218 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList, reason,
1219 roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1220 if(!HAL_STATUS_SUCCESS(status))
1221 {
1222 csrScanResultPurge(pMac, hBSSList);
1223 }
1224 }//Have scan result
1225 }
1226 }while(0);
1227 if(pScanFilter)
1228 {
1229 //we need to free memory for filter if profile exists
1230 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam3cac75e2013-07-12 13:56:44 +05301231 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001232 }
1233 if(NULL != pProfile)
1234 {
1235 csrReleaseProfile(pMac, pProfile);
Kiet Lam3cac75e2013-07-12 13:56:44 +05301236 vos_mem_free(pProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07001237 }
1238
1239 return (status);
1240}
1241
1242
Madan Mohan Koyyalamudi762dc6f2013-07-12 00:56:04 +05301243eHalStatus csrScanGetScanChnInfo(tpAniSirGlobal pMac, tANI_U8 sessionId,
1244 void *pContext, void *callback)
Jeff Johnson295189b2012-06-20 16:38:30 -07001245{
1246 eHalStatus status = eHAL_STATUS_SUCCESS;
1247 tSmeCmd *pScanCmd;
1248
1249 if(pMac->scan.fScanEnable)
1250 {
1251 pScanCmd = csrGetCommandBuffer(pMac);
1252 if(pScanCmd)
1253 {
1254 pScanCmd->command = eSmeCommandScan;
Kiet Lam3cac75e2013-07-12 13:56:44 +05301255 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson32d95a32012-09-10 13:15:23 -07001256 pScanCmd->u.scanCmd.callback = callback;
1257 pScanCmd->u.scanCmd.pContext = pContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07001258 pScanCmd->u.scanCmd.reason = eCsrScanGetScanChnInfo;
1259 //Need to make the following atomic
1260 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Madan Mohan Koyyalamudi762dc6f2013-07-12 00:56:04 +05301261 pScanCmd->sessionId = sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07001262 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
1263 if( !HAL_STATUS_SUCCESS( status ) )
1264 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08001265 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001266 csrReleaseCommandScan(pMac, pScanCmd);
1267 }
1268 }
1269 else
1270 {
1271 //log error
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08001272 smsLog(pMac, LOGE, FL("can not obtain a common buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001273 status = eHAL_STATUS_RESOURCES;
1274 }
1275 }
1276
1277 return (status);
1278}
1279
1280
1281eHalStatus csrScanHandleFailedLostlink1(tpAniSirGlobal pMac, tANI_U32 sessionId)
1282{
1283 eHalStatus status = eHAL_STATUS_FAILURE;
1284 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1285
Jeff Johnson32d95a32012-09-10 13:15:23 -07001286 if(!pSession)
1287 {
1288 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1289 return eHAL_STATUS_FAILURE;
1290 }
1291
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08001292 smsLog(pMac, LOGW, " Lostlink scan 1 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001293 if(pSession->fCancelRoaming)
1294 {
1295 csrScanStartIdleScan(pMac);
1296 }
1297 else if(pSession->pCurRoamProfile)
1298 {
1299 //We fail lostlink1 but there may be other BSS in the cached result fit the profile. Give it a try first
1300 if(pSession->pCurRoamProfile->SSIDs.numOfSSIDs == 0 ||
1301 pSession->pCurRoamProfile->SSIDs.numOfSSIDs > 1)
1302 {
1303 //try lostlink scan2
1304 status = csrScanRequestLostLink2(pMac, sessionId);
1305 }
1306 else if(!pSession->pCurRoamProfile->ChannelInfo.ChannelList ||
1307 pSession->pCurRoamProfile->ChannelInfo.ChannelList[0] == 0)
1308 {
1309 //go straight to lostlink scan3
1310 status = csrScanRequestLostLink3(pMac, sessionId);
1311 }
1312 else
1313 {
1314 //we are done with lostlink
1315 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1316 {
1317 csrScanStartIdleScan(pMac);
1318 }
1319 status = eHAL_STATUS_SUCCESS;
1320 }
1321 }
1322 else
1323 {
1324 status = csrScanRequestLostLink3(pMac, sessionId);
1325 }
1326
1327 return (status);
1328}
1329
1330
1331
1332eHalStatus csrScanHandleFailedLostlink2(tpAniSirGlobal pMac, tANI_U32 sessionId)
1333{
1334 eHalStatus status = eHAL_STATUS_FAILURE;
1335 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1336
Jeff Johnson32d95a32012-09-10 13:15:23 -07001337 if(!pSession)
1338 {
1339 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1340 return eHAL_STATUS_FAILURE;
1341 }
1342
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08001343 smsLog(pMac, LOGW, " Lostlink scan 2 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001344 if(pSession->fCancelRoaming)
1345 {
1346 csrScanStartIdleScan(pMac);
1347 }
1348 else if(!pSession->pCurRoamProfile || !pSession->pCurRoamProfile->ChannelInfo.ChannelList ||
1349 pSession->pCurRoamProfile->ChannelInfo.ChannelList[0] == 0)
1350 {
1351 //try lostlink scan3
1352 status = csrScanRequestLostLink3(pMac, sessionId);
1353 }
1354 else
1355 {
1356 //we are done with lostlink
1357 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1358 {
1359 csrScanStartIdleScan(pMac);
1360 }
1361 }
1362
1363 return (status);
1364}
1365
1366
1367
1368eHalStatus csrScanHandleFailedLostlink3(tpAniSirGlobal pMac, tANI_U32 sessionId)
1369{
1370 eHalStatus status = eHAL_STATUS_SUCCESS;
1371
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08001372 smsLog(pMac, LOGW, " Lostlink scan 3 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001373 if(eANI_BOOLEAN_TRUE == csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1374 {
1375 //we are done with lostlink
1376 csrScanStartIdleScan(pMac);
1377 }
1378
1379 return (status);
1380}
1381
1382
1383
1384
1385//Lostlink1 scan is to actively scan the last connected profile's SSID on all matched BSS channels.
1386//If no roam profile (it should not), it is like lostlinkscan3
1387eHalStatus csrScanRequestLostLink1( tpAniSirGlobal pMac, tANI_U32 sessionId )
1388{
1389 eHalStatus status = eHAL_STATUS_SUCCESS;
1390 tSmeCmd *pCommand = NULL;
1391 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1392 tCsrScanResultFilter *pScanFilter = NULL;
1393 tScanResultHandle hBSSList = NULL;
1394 tCsrScanResultInfo *pScanResult = NULL;
1395 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1396
Jeff Johnson32d95a32012-09-10 13:15:23 -07001397 if(!pSession)
1398 {
1399 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1400 return eHAL_STATUS_FAILURE;
1401 }
1402
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08001403 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001404 do
1405 {
1406 pCommand = csrGetCommandBuffer(pMac);
1407 if(!pCommand)
1408 {
1409 status = eHAL_STATUS_RESOURCES;
1410 break;
1411 }
Kiet Lam3cac75e2013-07-12 13:56:44 +05301412 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001413 pCommand->command = eSmeCommandScan;
1414 pCommand->sessionId = (tANI_U8)sessionId;
1415 pCommand->u.scanCmd.reason = eCsrScanLostLink1;
1416 pCommand->u.scanCmd.callback = NULL;
1417 pCommand->u.scanCmd.pContext = NULL;
1418 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1419 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere30b07722013-02-24 22:21:28 -08001420 pCommand->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1421 pCommand->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001422 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
1423 if(pSession->connectedProfile.SSID.length)
1424 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05301425 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList = vos_mem_malloc(sizeof(tCsrSSIDInfo));
1426 if ( NULL == pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList )
1427 status = eHAL_STATUS_FAILURE;
1428 else
1429 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001430 if(!HAL_STATUS_SUCCESS(status))
1431 {
1432 break;
1433 }
1434 pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 1;
Kiet Lam3cac75e2013-07-12 13:56:44 +05301435 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID,
1436 &pSession->connectedProfile.SSID, sizeof(tSirMacSSid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001437 }
1438 else
1439 {
1440 pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 0;
1441 }
1442 if(pSession->pCurRoamProfile)
1443 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05301444 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1445 if ( NULL == pScanFilter )
1446 status = eHAL_STATUS_FAILURE;
1447 else
1448 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001449 if(!HAL_STATUS_SUCCESS(status))
1450 {
1451 break;
1452 }
Kiet Lam3cac75e2013-07-12 13:56:44 +05301453 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001454 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
1455 if(!HAL_STATUS_SUCCESS(status))
1456 {
1457 break;
1458 }
1459 //Don't change variable status here because whether we can get result or not, the command goes to PE.
1460 //The status is also used to indicate whether the command is queued. Not success meaning not queue
1461 if(HAL_STATUS_SUCCESS((csrScanGetResult(pMac, pScanFilter, &hBSSList))) && hBSSList)
1462 {
1463 tANI_U8 i, nChn = 0;
Kiet Lam3cac75e2013-07-12 13:56:44 +05301464 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList =
1465 vos_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
1466 if ( NULL == pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
1467 status = eHAL_STATUS_FAILURE;
1468 else
1469 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001470 if(!HAL_STATUS_SUCCESS(status))
1471 {
1472 break;
1473 }
1474 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) &&
1475 nChn < WNI_CFG_VALID_CHANNEL_LIST_LEN)
1476 {
1477 for(i = 0; i < nChn; i++)
1478 {
1479 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1480 pScanResult->BssDescriptor.channelId)
1481 {
1482 break;
1483 }
1484 }
1485 if(i == nChn)
1486 {
1487 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pScanResult->BssDescriptor.channelId;
1488 }
1489 }
1490 //Include the last connected BSS' channel
1491 if(csrRoamIsChannelValid(pMac, pSession->connectedProfile.operationChannel))
1492 {
1493 for(i = 0; i < nChn; i++)
1494 {
1495 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1496 pSession->connectedProfile.operationChannel)
1497 {
1498 break;
1499 }
1500 }
1501 if(i == nChn)
1502 {
1503 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pSession->connectedProfile.operationChannel;
1504 }
1505 }
1506 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nChn;
1507 }
1508 else
1509 {
1510 if(csrRoamIsChannelValid(pMac, pSession->connectedProfile.operationChannel))
1511 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05301512 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(1);
1513 if ( NULL == pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
1514 status = eHAL_STATUS_FAILURE;
1515 else
1516 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001517 //just try the last connected channel
1518 if(HAL_STATUS_SUCCESS(status))
1519 {
1520 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[0] = pSession->connectedProfile.operationChannel;
1521 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 1;
1522 }
1523 else
1524 {
1525 break;
1526 }
1527 }
1528 }
1529 }
Kiet Lam3cac75e2013-07-12 13:56:44 +05301530 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001531 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
1532 if( !HAL_STATUS_SUCCESS( status ) )
1533 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08001534 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001535 break;
1536 }
1537 } while( 0 );
1538
1539 if(!HAL_STATUS_SUCCESS(status))
1540 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08001541 smsLog(pMac, LOGW, " csrScanRequestLostLink1 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001542 if(pCommand)
1543 {
1544 csrReleaseCommandScan(pMac, pCommand);
1545 }
1546 status = csrScanHandleFailedLostlink1( pMac, sessionId );
1547 }
1548 if(pScanFilter)
1549 {
1550 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam3cac75e2013-07-12 13:56:44 +05301551 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001552 }
1553 if(hBSSList)
1554 {
1555 csrScanResultPurge(pMac, hBSSList);
1556 }
1557
1558 return( status );
1559}
1560
1561
1562//Lostlink2 scan is to actively scan the all SSIDs of the last roaming profile's on all matched BSS channels.
1563//Since MAC doesn't support multiple SSID, we scan all SSIDs and filter them afterwards
1564eHalStatus csrScanRequestLostLink2( tpAniSirGlobal pMac, tANI_U32 sessionId )
1565{
1566 eHalStatus status = eHAL_STATUS_SUCCESS;
1567 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1568 tCsrScanResultFilter *pScanFilter = NULL;
1569 tScanResultHandle hBSSList = NULL;
1570 tCsrScanResultInfo *pScanResult = NULL;
1571 tSmeCmd *pCommand = NULL;
1572 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1573
Jeff Johnson32d95a32012-09-10 13:15:23 -07001574 if(!pSession)
1575 {
1576 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1577 return eHAL_STATUS_FAILURE;
1578 }
1579
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08001580 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001581 do
1582 {
1583 pCommand = csrGetCommandBuffer(pMac);
1584 if(!pCommand)
1585 {
1586 status = eHAL_STATUS_RESOURCES;
1587 break;
1588 }
Kiet Lam3cac75e2013-07-12 13:56:44 +05301589 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001590 pCommand->command = eSmeCommandScan;
1591 pCommand->sessionId = (tANI_U8)sessionId;
1592 pCommand->u.scanCmd.reason = eCsrScanLostLink2;
1593 pCommand->u.scanCmd.callback = NULL;
1594 pCommand->u.scanCmd.pContext = NULL;
1595 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1596 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere30b07722013-02-24 22:21:28 -08001597 pCommand->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1598 pCommand->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001599 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
1600 if(pSession->pCurRoamProfile)
1601 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05301602 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1603 if ( NULL == pScanFilter )
1604 status = eHAL_STATUS_FAILURE;
1605 else
1606 status = eHAL_STATUS_SUCCESS;
1607 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001608 {
1609 break;
1610 }
Kiet Lam3cac75e2013-07-12 13:56:44 +05301611 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001612 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
1613 if(!HAL_STATUS_SUCCESS(status))
1614 {
1615 break;
1616 }
1617 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1618 if(!HAL_STATUS_SUCCESS(status))
1619 {
1620 break;
1621 }
1622 if(hBSSList)
1623 {
1624 tANI_U8 i, nChn = 0;
Kiet Lam3cac75e2013-07-12 13:56:44 +05301625 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList =
1626 vos_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
1627 if ( NULL == pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
1628 status = eHAL_STATUS_FAILURE;
1629 else
1630 status = eHAL_STATUS_SUCCESS;
1631 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001632 {
1633 break;
1634 }
1635 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) &&
1636 nChn < WNI_CFG_VALID_CHANNEL_LIST_LEN)
1637 {
1638 for(i = 0; i < nChn; i++)
1639 {
1640 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1641 pScanResult->BssDescriptor.channelId)
1642 {
1643 break;
1644 }
1645 }
1646 if(i == nChn)
1647 {
1648 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pScanResult->BssDescriptor.channelId;
1649 }
1650 }
1651 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nChn;
1652 }
1653 }
Kiet Lam3cac75e2013-07-12 13:56:44 +05301654 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001655 //Put to the head in pending queue
1656 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_TRUE);
1657 if( !HAL_STATUS_SUCCESS( status ) )
1658 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08001659 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001660 break;
1661 }
1662 } while( 0 );
1663
1664 if(!HAL_STATUS_SUCCESS(status))
1665 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08001666 smsLog(pMac, LOGW, " csrScanRequestLostLink2 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001667 if(pCommand)
1668 {
1669 csrReleaseCommandScan(pMac, pCommand);
1670 }
1671 status = csrScanHandleFailedLostlink2( pMac, sessionId );
1672 }
1673 if(pScanFilter)
1674 {
1675 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam3cac75e2013-07-12 13:56:44 +05301676 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001677 }
1678 if(hBSSList)
1679 {
1680 csrScanResultPurge(pMac, hBSSList);
1681 }
1682
1683 return( status );
1684}
1685
1686
1687//To actively scan all valid channels
1688eHalStatus csrScanRequestLostLink3( tpAniSirGlobal pMac, tANI_U32 sessionId )
1689{
1690 eHalStatus status = eHAL_STATUS_SUCCESS;
1691 tSmeCmd *pCommand;
1692 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1693
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08001694 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001695 do
1696 {
1697 pCommand = csrGetCommandBuffer(pMac);
1698 if(!pCommand)
1699 {
1700 status = eHAL_STATUS_RESOURCES;
1701 break;
1702 }
Kiet Lam3cac75e2013-07-12 13:56:44 +05301703 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001704 pCommand->command = eSmeCommandScan;
1705 pCommand->sessionId = (tANI_U8)sessionId;
1706 pCommand->u.scanCmd.reason = eCsrScanLostLink3;
1707 pCommand->u.scanCmd.callback = NULL;
1708 pCommand->u.scanCmd.pContext = NULL;
1709 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1710 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere30b07722013-02-24 22:21:28 -08001711 pCommand->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1712 pCommand->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001713 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Kiet Lam3cac75e2013-07-12 13:56:44 +05301714 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001715 //Put to the head of pending queue
1716 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_TRUE);
1717 if( !HAL_STATUS_SUCCESS( status ) )
1718 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08001719 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001720 break;
1721 }
1722 } while( 0 );
1723 if(!HAL_STATUS_SUCCESS(status))
1724 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08001725 smsLog(pMac, LOGW, " csrScanRequestLostLink3 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001726 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1727 {
1728 csrScanStartIdleScan(pMac);
1729 }
1730 if(pCommand)
1731 {
1732 csrReleaseCommandScan(pMac, pCommand);
1733 }
1734 }
1735
1736 return( status );
1737}
1738
1739
1740eHalStatus csrScanHandleSearchForSSID(tpAniSirGlobal pMac, tSmeCmd *pCommand)
1741{
1742 eHalStatus status = eHAL_STATUS_FAILURE;
1743 tScanResultHandle hBSSList = CSR_INVALID_SCANRESULT_HANDLE;
1744 tCsrScanResultFilter *pScanFilter = NULL;
1745 tCsrRoamProfile *pProfile = pCommand->u.scanCmd.pToRoamProfile;
1746 tANI_U32 sessionId = pCommand->sessionId;
1747#ifdef FEATURE_WLAN_BTAMP_UT_RF
1748 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1749#endif
1750 do
1751 {
Varun Reddy Yeturu2c35a7d2013-05-20 11:47:10 -07001752#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
1753 //if this scan is for LFR
1754 if(pMac->roam.neighborRoamInfo.uOsRequestedHandoff)
1755 {
1756 //notify LFR state m/c
1757 if(eHAL_STATUS_SUCCESS != csrNeighborRoamSssidScanDone(pMac, eHAL_STATUS_SUCCESS))
1758 {
Varun Reddy Yeturu6fc169c2013-06-07 00:56:52 -07001759 csrNeighborRoamStartLfrScan(pMac);
Varun Reddy Yeturu2c35a7d2013-05-20 11:47:10 -07001760 }
1761 status = eHAL_STATUS_SUCCESS;
1762 break;
1763 }
1764#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001765 //If there is roam command waiting, ignore this roam because the newer roam command is the one to execute
1766 if(csrIsRoamCommandWaitingForSession(pMac, sessionId))
1767 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08001768 smsLog(pMac, LOGW, FL(" aborts because roam command waiting"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001769 break;
1770 }
1771 if(pProfile == NULL)
1772 break;
Kiet Lam3cac75e2013-07-12 13:56:44 +05301773 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1774 if ( NULL == pScanFilter )
1775 status = eHAL_STATUS_FAILURE;
1776 else
1777 status = eHAL_STATUS_SUCCESS;
1778 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001779 break;
Kiet Lam3cac75e2013-07-12 13:56:44 +05301780 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001781 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1782 if(!HAL_STATUS_SUCCESS(status))
1783 break;
1784 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1785 if(!HAL_STATUS_SUCCESS(status))
1786 break;
1787 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList, eCsrHddIssued,
1788 pCommand->u.scanCmd.roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1789 if(!HAL_STATUS_SUCCESS(status))
1790 {
1791 break;
1792 }
1793 }while(0);
1794 if(!HAL_STATUS_SUCCESS(status))
1795 {
1796 if(CSR_INVALID_SCANRESULT_HANDLE != hBSSList)
1797 {
1798 csrScanResultPurge(pMac, hBSSList);
1799 }
1800 //We haven't done anything to this profile
1801 csrRoamCallCallback(pMac, sessionId, NULL, pCommand->u.scanCmd.roamId,
1802 eCSR_ROAM_ASSOCIATION_FAILURE, eCSR_ROAM_RESULT_FAILURE);
1803 //In case we have nothing else to do, restart idle scan
1804 if(csrIsConnStateDisconnected(pMac, sessionId) && !csrIsRoamCommandWaiting(pMac))
1805 {
1806 status = csrScanStartIdleScan(pMac);
1807 }
1808#ifdef FEATURE_WLAN_BTAMP_UT_RF
1809 //In case of WDS station, let it retry.
1810 if( CSR_IS_WDS_STA(pProfile) )
1811 {
1812 //Save the roma profile so we can retry
1813 csrFreeRoamProfile( pMac, sessionId );
Kiet Lam3cac75e2013-07-12 13:56:44 +05301814 pSession->pCurRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1815 if ( NULL != pSession->pCurRoamProfile )
Jeff Johnson295189b2012-06-20 16:38:30 -07001816 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05301817 vos_mem_set(pSession->pCurRoamProfilee, sizeof(tCsrRoamProfile), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001818 csrRoamCopyProfile(pMac, pSession->pCurRoamProfile, pProfile);
1819 }
1820 csrRoamStartJoinRetryTimer(pMac, sessionId, CSR_JOIN_RETRY_TIMEOUT_PERIOD);
1821 }
1822#endif
1823 }
Kiet Lam3cac75e2013-07-12 13:56:44 +05301824 if (pScanFilter)
Jeff Johnson295189b2012-06-20 16:38:30 -07001825 {
1826 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam3cac75e2013-07-12 13:56:44 +05301827 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001828 }
1829
1830 return (status);
1831}
1832
1833
1834eHalStatus csrScanHandleSearchForSSIDFailure(tpAniSirGlobal pMac, tSmeCmd *pCommand)
1835{
1836 eHalStatus status = eHAL_STATUS_SUCCESS;
1837 tANI_U32 sessionId = pCommand->sessionId;
1838 tCsrRoamProfile *pProfile = pCommand->u.scanCmd.pToRoamProfile;
1839 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
Varun Reddy Yeturu2c35a7d2013-05-20 11:47:10 -07001840#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
1841 //if this scan is for LFR
1842 if(pMac->roam.neighborRoamInfo.uOsRequestedHandoff)
1843 {
1844 //notify LFR state m/c
1845 if(eHAL_STATUS_SUCCESS != csrNeighborRoamSssidScanDone(pMac, eHAL_STATUS_FAILURE))
1846 {
Varun Reddy Yeturu6fc169c2013-06-07 00:56:52 -07001847 csrNeighborRoamStartLfrScan(pMac);
Varun Reddy Yeturu2c35a7d2013-05-20 11:47:10 -07001848 }
1849 return eHAL_STATUS_SUCCESS;
1850 }
1851#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -07001852 if(!pSession)
1853 {
1854 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1855 return eHAL_STATUS_FAILURE;
1856 }
1857
Jeff Johnson295189b2012-06-20 16:38:30 -07001858#if defined(WLAN_DEBUG)
1859 if(pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs == 1)
1860 {
1861 char str[36];
Kiet Lam3cac75e2013-07-12 13:56:44 +05301862 vos_mem_copy(str,
1863 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.ssId,
1864 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.length);
Jeff Johnson295189b2012-06-20 16:38:30 -07001865 str[pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.length] = 0;
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08001866 smsLog(pMac, LOGW, FL(" SSID = %s"), str);
Jeff Johnson295189b2012-06-20 16:38:30 -07001867 }
1868#endif
1869 //Check whether it is for start ibss. No need to do anything if it is a JOIN request
1870 if(pProfile && CSR_IS_START_IBSS(pProfile))
1871 {
1872 status = csrRoamIssueConnect(pMac, sessionId, pProfile, NULL, eCsrHddIssued,
1873 pCommand->u.scanCmd.roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1874 if(!HAL_STATUS_SUCCESS(status))
1875 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08001876 smsLog(pMac, LOGE, FL("failed to issue startIBSS command with status = 0x%08X"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001877 csrRoamCallCallback(pMac, sessionId, NULL, pCommand->u.scanCmd.roamId, eCSR_ROAM_FAILED, eCSR_ROAM_RESULT_FAILURE);
1878 }
1879 }
1880 else
1881 {
1882 eCsrRoamResult roamResult = eCSR_ROAM_RESULT_FAILURE;
1883
1884 if(csrIsConnStateDisconnected(pMac, sessionId) &&
1885 !csrIsRoamCommandWaitingForSession(pMac, sessionId))
1886 {
1887 status = csrScanStartIdleScan(pMac);
1888 }
1889 if((NULL == pProfile) || !csrIsBssTypeIBSS(pProfile->BSSType))
1890 {
1891 //Only indicate assoc_completion if we indicate assoc_start.
1892 if(pSession->bRefAssocStartCnt > 0)
1893 {
1894 tCsrRoamInfo *pRoamInfo = NULL, roamInfo;
Kiet Lam3cac75e2013-07-12 13:56:44 +05301895 vos_mem_set(&roamInfo, sizeof(tCsrRoamInfo), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001896 pRoamInfo = &roamInfo;
1897 if(pCommand->u.roamCmd.pRoamBssEntry)
1898 {
1899 tCsrScanResult *pScanResult =
1900 GET_BASE_ADDR(pCommand->u.roamCmd.pRoamBssEntry,
1901 tCsrScanResult, Link);
1902 roamInfo.pBssDesc = &pScanResult->Result.BssDescriptor;
1903 }
1904 roamInfo.statusCode = pSession->joinFailStatusCode.statusCode;
1905 roamInfo.reasonCode = pSession->joinFailStatusCode.reasonCode;
1906 pSession->bRefAssocStartCnt--;
1907 csrRoamCallCallback(pMac, sessionId, pRoamInfo,
1908 pCommand->u.scanCmd.roamId,
1909 eCSR_ROAM_ASSOCIATION_COMPLETION,
1910 eCSR_ROAM_RESULT_FAILURE);
1911 }
Madan Mohan Koyyalamudiee255f12012-09-28 15:41:19 -07001912 else
1913 {
1914 csrRoamCallCallback(pMac, sessionId, NULL,
1915 pCommand->u.scanCmd.roamId,
1916 eCSR_ROAM_ASSOCIATION_FAILURE,
1917 eCSR_ROAM_RESULT_FAILURE);
1918 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001919#ifdef FEATURE_WLAN_BTAMP_UT_RF
1920 //In case of WDS station, let it retry.
1921 if( CSR_IS_WDS_STA(pProfile) )
1922 {
1923 //Save the roma profile so we can retry
1924 csrFreeRoamProfile( pMac, sessionId );
Kiet Lam3cac75e2013-07-12 13:56:44 +05301925 pSession->pCurRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1926 if ( NULL != pSession->pCurRoamProfile )
Jeff Johnson295189b2012-06-20 16:38:30 -07001927 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05301928 vos_mem_set(pSession->pCurRoamProfile, sizeof(tCsrRoamProfile), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001929 csrRoamCopyProfile(pMac, pSession->pCurRoamProfile, pProfile);
1930 }
1931 csrRoamStartJoinRetryTimer(pMac, sessionId, CSR_JOIN_RETRY_TIMEOUT_PERIOD);
1932 }
1933#endif
1934 }
1935 else
1936 {
1937 roamResult = eCSR_ROAM_RESULT_IBSS_START_FAILED;
1938 }
1939 csrRoamCompletion(pMac, sessionId, NULL, pCommand, roamResult, eANI_BOOLEAN_FALSE);
1940 }
1941
1942 return (status);
1943}
1944
1945
1946//After scan for cap changes, issue a roaming command to either reconnect to the AP or pick another one to connect
1947eHalStatus csrScanHandleCapChangeScanComplete(tpAniSirGlobal pMac, tANI_U32 sessionId)
1948{
1949 eHalStatus status = eHAL_STATUS_FAILURE;
1950 tScanResultHandle hBSSList = NULL;
1951 tCsrScanResultFilter *pScanFilter = NULL;
1952 tANI_U32 roamId = 0;
1953 tCsrRoamProfile *pProfile = NULL;
1954 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1955
1956 do
1957 {
1958 //Here is the profile we need to connect to
Kiet Lam3cac75e2013-07-12 13:56:44 +05301959 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1960 if ( NULL == pScanFilter )
1961 status = eHAL_STATUS_FAILURE;
1962 else
1963 status = eHAL_STATUS_SUCCESS;
1964 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001965 break;
Kiet Lam3cac75e2013-07-12 13:56:44 +05301966 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
1967 if (NULL == pSession) break;
1968 if (NULL == pSession->pCurRoamProfile)
Jeff Johnson295189b2012-06-20 16:38:30 -07001969 {
1970 pScanFilter->EncryptionType.numEntries = 1;
1971 pScanFilter->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_NONE;
1972 }
1973 else
1974 {
1975 //We have to make a copy of pCurRoamProfile because it will be free inside csrRoamIssueConnect
Kiet Lam3cac75e2013-07-12 13:56:44 +05301976 pProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1977 if ( NULL == pProfile )
1978 status = eHAL_STATUS_FAILURE;
1979 else
1980 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001981 if(!HAL_STATUS_SUCCESS(status))
1982 break;
1983 status = csrRoamCopyProfile(pMac, pProfile, pSession->pCurRoamProfile);
1984 if(!HAL_STATUS_SUCCESS(status))
1985 break;
1986 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1987 }//We have a profile
1988 roamId = GET_NEXT_ROAM_ID(&pMac->roam);
1989 if(HAL_STATUS_SUCCESS(status))
1990 {
1991 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1992 if(HAL_STATUS_SUCCESS(status))
1993 {
1994 //we want to put the last connected BSS to the very beginning, if possible
1995 csrMoveBssToHeadFromBSSID(pMac, &pSession->connectedProfile.bssid, hBSSList);
1996 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList,
1997 eCsrCapsChange, 0, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1998 if(!HAL_STATUS_SUCCESS(status))
1999 {
2000 csrScanResultPurge(pMac, hBSSList);
2001 }
2002 }//Have scan result
2003 else
2004 {
Arif Hussaineb871412013-11-20 11:06:42 -08002005 smsLog(pMac, LOGW, FL("cannot find matching BSS of "
2006 MAC_ADDRESS_STR),
2007 MAC_ADDR_ARRAY(pSession->connectedProfile.bssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07002008 //Disconnect
2009 csrRoamDisconnectInternal(pMac, sessionId, eCSR_DISCONNECT_REASON_UNSPECIFIED);
2010 }
2011 }
2012 }while(0);
2013 if(pScanFilter)
2014 {
2015 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam3cac75e2013-07-12 13:56:44 +05302016 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07002017 }
2018 if(NULL != pProfile)
2019 {
2020 csrReleaseProfile(pMac, pProfile);
Kiet Lam3cac75e2013-07-12 13:56:44 +05302021 vos_mem_free(pProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07002022 }
2023
2024 return (status);
2025}
2026
2027
2028
2029eHalStatus csrScanResultPurge(tpAniSirGlobal pMac, tScanResultHandle hScanList)
2030{
2031 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
2032 tScanResultList *pScanList = (tScanResultList *)hScanList;
2033
2034 if(pScanList)
2035 {
2036 status = csrLLScanPurgeResult(pMac, &pScanList->List);
2037 csrLLClose(&pScanList->List);
Kiet Lam3cac75e2013-07-12 13:56:44 +05302038 vos_mem_free(pScanList);
Jeff Johnson295189b2012-06-20 16:38:30 -07002039 }
2040 return (status);
2041}
2042
2043
2044static tANI_U32 csrGetBssPreferValue(tpAniSirGlobal pMac, int rssi)
2045{
2046 tANI_U32 ret = 0;
2047 int i = CSR_NUM_RSSI_CAT - 1;
2048
2049 while(i >= 0)
2050 {
2051 if(rssi >= pMac->roam.configParam.RSSICat[i])
2052 {
2053 ret = pMac->roam.configParam.BssPreferValue[i];
2054 break;
2055 }
2056 i--;
2057 };
2058
2059 return (ret);
2060}
2061
2062
2063//Return a CapValue base on the capabilities of a BSS
2064static tANI_U32 csrGetBssCapValue(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes)
2065{
2066 tANI_U32 ret = CSR_BSS_CAP_VALUE_NONE;
Madan Mohan Koyyalamudic4c01172012-11-30 14:56:21 -08002067#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_CCX) || defined(FEATURE_WLAN_LFR)
2068 if(CSR_IS_ROAM_PREFER_5GHZ(pMac))
2069 {
2070 if((pBssDesc) && CSR_IS_CHANNEL_5GHZ(pBssDesc->channelId))
2071 {
2072 ret += CSR_BSS_CAP_VALUE_5GHZ;
2073 }
2074 }
2075#endif
Srinivas Girigowda5e07fb32013-10-21 19:01:38 -07002076 /* if strict select 5GHz is non-zero then ignore the capability checking */
2077 if (pIes && !CSR_IS_SELECT_5GHZ_MARGIN(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -07002078 {
2079 //We only care about 11N capability
2080 if(pIes->HTCaps.present)
2081 {
2082 ret += CSR_BSS_CAP_VALUE_HT;
2083 }
2084 if(CSR_IS_QOS_BSS(pIes))
2085 {
2086 ret += CSR_BSS_CAP_VALUE_WMM;
2087 //Give advantage to UAPSD
2088 if(CSR_IS_UAPSD_BSS(pIes))
2089 {
2090 ret += CSR_BSS_CAP_VALUE_UAPSD;
2091 }
2092 }
2093 }
2094
2095 return (ret);
2096}
2097
2098
2099//To check whther pBss1 is better than pBss2
2100static tANI_BOOLEAN csrIsBetterBss(tCsrScanResult *pBss1, tCsrScanResult *pBss2)
2101{
2102 tANI_BOOLEAN ret;
2103
2104 if(CSR_IS_BETTER_PREFER_VALUE(pBss1->preferValue, pBss2->preferValue))
2105 {
2106 ret = eANI_BOOLEAN_TRUE;
2107 }
2108 else if(CSR_IS_EQUAL_PREFER_VALUE(pBss1->preferValue, pBss2->preferValue))
2109 {
2110 if(CSR_IS_BETTER_CAP_VALUE(pBss1->capValue, pBss2->capValue))
2111 {
2112 ret = eANI_BOOLEAN_TRUE;
2113 }
2114 else
2115 {
2116 ret = eANI_BOOLEAN_FALSE;
2117 }
2118 }
2119 else
2120 {
2121 ret = eANI_BOOLEAN_FALSE;
2122 }
2123
2124 return (ret);
2125}
2126
2127
Madan Mohan Koyyalamudi91482b82012-12-27 17:28:14 -08002128#ifdef FEATURE_WLAN_LFR
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002129//Add the channel to the occupiedChannels array
2130static void csrScanAddToOccupiedChannels(
Madan Mohan Koyyalamudi91482b82012-12-27 17:28:14 -08002131 tpAniSirGlobal pMac,
2132 tCsrScanResult *pResult,
2133 tCsrChannel *pOccupiedChannels,
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002134 tDot11fBeaconIEs *pIes)
2135{
2136 eHalStatus status;
2137 tANI_U8 channel;
2138 tANI_U8 numOccupiedChannels = pOccupiedChannels->numChannels;
2139 tANI_U8 *pOccupiedChannelList = pOccupiedChannels->channelList;
2140
2141 channel = pResult->Result.BssDescriptor.channelId;
2142
2143 if (!csrIsChannelPresentInList(pOccupiedChannelList, numOccupiedChannels, channel)
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08002144 && csrNeighborRoamConnectedProfileMatch(pMac, pResult, pIes))
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002145 {
Madan Mohan Koyyalamudi91482b82012-12-27 17:28:14 -08002146 status = csrAddToChannelListFront(pOccupiedChannelList, numOccupiedChannels, channel);
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002147 if(HAL_STATUS_SUCCESS(status))
Madan Mohan Koyyalamudi91482b82012-12-27 17:28:14 -08002148 {
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002149 pOccupiedChannels->numChannels++;
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08002150 smsLog(pMac, LOG2, FL("%s: added channel %d to the list (count=%d)"),
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08002151 __func__, channel, pOccupiedChannels->numChannels);
Madan Mohan Koyyalamudi91482b82012-12-27 17:28:14 -08002152 if (pOccupiedChannels->numChannels > CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN)
2153 pOccupiedChannels->numChannels = CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN;
2154 }
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002155 }
2156}
2157#endif
2158
Jeff Johnson295189b2012-06-20 16:38:30 -07002159//Put the BSS into the scan result list
2160//pIes can not be NULL
2161static void csrScanAddResult(tpAniSirGlobal pMac, tCsrScanResult *pResult, tDot11fBeaconIEs *pIes)
2162{
Madan Mohan Koyyalamudi2bb99ef2012-12-12 13:07:53 -08002163#ifdef FEATURE_WLAN_LFR
2164 tpCsrNeighborRoamControlInfo pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
2165#endif
2166
Jeff Johnson295189b2012-06-20 16:38:30 -07002167 pResult->preferValue = csrGetBssPreferValue(pMac, (int)pResult->Result.BssDescriptor.rssi);
2168 pResult->capValue = csrGetBssCapValue(pMac, &pResult->Result.BssDescriptor, pIes);
2169 csrLLInsertTail( &pMac->scan.scanResultList, &pResult->Link, LL_ACCESS_LOCK );
Madan Mohan Koyyalamudi91482b82012-12-27 17:28:14 -08002170#ifdef FEATURE_WLAN_LFR
Madan Mohan Koyyalamudi2bb99ef2012-12-12 13:07:53 -08002171 if(0 == pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels)
2172 {
2173 /* Build the occupied channel list, only if "gNeighborScanChannelList" is
2174 NOT set in the cfg.ini file */
2175 csrScanAddToOccupiedChannels(pMac, pResult, &pMac->scan.occupiedChannels, pIes);
2176 }
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002177#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002178}
2179
2180
2181eHalStatus csrScanGetResult(tpAniSirGlobal pMac, tCsrScanResultFilter *pFilter, tScanResultHandle *phResult)
2182{
2183 eHalStatus status;
2184 tScanResultList *pRetList;
2185 tCsrScanResult *pResult, *pBssDesc;
2186 tANI_U32 count = 0;
2187 tListElem *pEntry;
2188 tANI_U32 bssLen, allocLen;
2189 eCsrEncryptionType uc = eCSR_ENCRYPT_TYPE_NONE, mc = eCSR_ENCRYPT_TYPE_NONE;
2190 eCsrAuthType auth = eCSR_AUTH_TYPE_OPEN_SYSTEM;
2191 tDot11fBeaconIEs *pIes, *pNewIes;
2192 tANI_BOOLEAN fMatch;
Srinivas Girigowdaf193fa32013-11-13 18:53:14 -08002193 tANI_U16 i = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07002194
2195 if(phResult)
2196 {
2197 *phResult = CSR_INVALID_SCANRESULT_HANDLE;
2198 }
Srinivas Girigowda5e07fb32013-10-21 19:01:38 -07002199
2200 if (pMac->roam.configParam.nSelect5GHzMargin)
2201 {
2202 pMac->scan.inScanResultBestAPRssi = -128;
2203 csrLLLock(&pMac->scan.scanResultList);
2204
2205 /* Find out the best AP Rssi going thru the scan results */
2206 pEntry = csrLLPeekHead(&pMac->scan.scanResultList, LL_ACCESS_NOLOCK);
2207 while ( NULL != pEntry)
2208 {
2209 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
Srinivas Girigowdaf193fa32013-11-13 18:53:14 -08002210 fMatch = FALSE;
2211
2212 if (pFilter)
2213 for(i = 0; i < pFilter->SSIDs.numOfSSIDs; i++)
Srinivas Girigowda5e07fb32013-10-21 19:01:38 -07002214 {
Srinivas Girigowdaf193fa32013-11-13 18:53:14 -08002215 fMatch = csrIsSsidMatch( pMac, pFilter->SSIDs.SSIDList[i].SSID.ssId, pFilter->SSIDs.SSIDList[i].SSID.length,
2216 pBssDesc->Result.ssId.ssId,
2217 pBssDesc->Result.ssId.length, eANI_BOOLEAN_TRUE );
2218 if (fMatch)
2219 {
2220 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
2221
2222 //At this time, pBssDescription->Result.pvIes may be NULL
2223 if( !pIes && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
2224 &pBssDesc->Result.BssDescriptor, &pIes))) )
2225 {
2226 continue;
2227 }
2228
2229 smsLog(pMac, LOG1, FL("SSID Matched"));
2230 fMatch = csrIsSecurityMatch( pMac, &pFilter->authType, &pFilter->EncryptionType, &pFilter->mcEncryptionType,
2231 &pBssDesc->Result.BssDescriptor, pIes, NULL, NULL, NULL );
2232 if ((pBssDesc->Result.pvIes == NULL) && pIes)
Kiet Lamaa0b59c2013-11-16 21:24:16 +05302233 vos_mem_free(pIes);
Srinivas Girigowdaf193fa32013-11-13 18:53:14 -08002234
2235 if (fMatch)
2236 smsLog(pMac, LOG1, FL(" Security Matched"));
2237 }
2238 }
2239
2240 if (fMatch && (pBssDesc->Result.BssDescriptor.rssi > pMac->scan.inScanResultBestAPRssi))
2241 {
2242 smsLog(pMac, LOG1, FL("Best AP Rssi changed from %d to %d"),
2243 pMac->scan.inScanResultBestAPRssi,
2244 pBssDesc->Result.BssDescriptor.rssi);
Srinivas Girigowda5e07fb32013-10-21 19:01:38 -07002245 pMac->scan.inScanResultBestAPRssi = pBssDesc->Result.BssDescriptor.rssi;
2246 }
2247 pEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
2248 }
2249
Srinivas Girigowdaf193fa32013-11-13 18:53:14 -08002250 if ( -128 != pMac->scan.inScanResultBestAPRssi)
Srinivas Girigowda5e07fb32013-10-21 19:01:38 -07002251 {
Srinivas Girigowdaf193fa32013-11-13 18:53:14 -08002252 smsLog(pMac, LOG1, FL("Best AP Rssi is %d"), pMac->scan.inScanResultBestAPRssi);
2253 /* Modify Rssi category based on best AP Rssi */
2254 csrAssignRssiForCategory(pMac, pMac->scan.inScanResultBestAPRssi, pMac->roam.configParam.bCatRssiOffset);
2255 pEntry = csrLLPeekHead(&pMac->scan.scanResultList, LL_ACCESS_NOLOCK);
2256 while ( NULL != pEntry)
2257 {
2258 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
Srinivas Girigowda5e07fb32013-10-21 19:01:38 -07002259
Srinivas Girigowdaf193fa32013-11-13 18:53:14 -08002260 /* re-assign preference value based on modified rssi bucket */
2261 pBssDesc->preferValue = csrGetBssPreferValue(pMac, (int)pBssDesc->Result.BssDescriptor.rssi);
Srinivas Girigowda5e07fb32013-10-21 19:01:38 -07002262
Arif Hussaineb871412013-11-20 11:06:42 -08002263 smsLog(pMac, LOG2, FL("BSSID("MAC_ADDRESS_STR
Jeff Johnson9bd61332013-11-22 17:39:55 -08002264 ") Rssi(%d) Chnl(%d) PrefVal(%u) SSID=%.*s"),
Arif Hussaineb871412013-11-20 11:06:42 -08002265 MAC_ADDR_ARRAY(pBssDesc->Result.BssDescriptor.bssId),
2266 pBssDesc->Result.BssDescriptor.rssi,
2267 pBssDesc->Result.BssDescriptor.channelId,
2268 pBssDesc->preferValue,
2269 pBssDesc->Result.ssId.length, pBssDesc->Result.ssId.ssId);
Srinivas Girigowdaf193fa32013-11-13 18:53:14 -08002270
2271 pEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
2272 }
Srinivas Girigowda5e07fb32013-10-21 19:01:38 -07002273 }
2274
2275 csrLLUnlock(&pMac->scan.scanResultList);
2276 }
2277
Kiet Lam3cac75e2013-07-12 13:56:44 +05302278 pRetList = vos_mem_malloc(sizeof(tScanResultList));
2279 if ( NULL == pRetList )
2280 status = eHAL_STATUS_FAILURE;
2281 else
2282 status = eHAL_STATUS_SUCCESS;
Srinivas Girigowda5e07fb32013-10-21 19:01:38 -07002283 if(HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07002284 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05302285 vos_mem_set(pRetList, sizeof(tScanResultList), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002286 csrLLOpen(pMac->hHdd, &pRetList->List);
2287 pRetList->pCurEntry = NULL;
2288
2289 csrLLLock(&pMac->scan.scanResultList);
2290 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
2291 while( pEntry )
2292 {
2293 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2294 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
2295 //if pBssDesc->Result.pvIes is NULL, we need to free any memory allocated by csrMatchBSS
2296 //for any error condition, otherwiase, it will be freed later.
2297 //reset
2298 fMatch = eANI_BOOLEAN_FALSE;
2299 pNewIes = NULL;
2300
2301 if(pFilter)
2302 {
2303 fMatch = csrMatchBSS(pMac, &pBssDesc->Result.BssDescriptor, pFilter, &auth, &uc, &mc, &pIes);
2304 if( NULL != pIes )
2305 {
2306 //Only save it when matching
2307 if(fMatch)
2308 {
2309 if( !pBssDesc->Result.pvIes )
2310 {
2311 //csrMatchBSS allocates the memory. Simply pass it and it is freed later
2312 pNewIes = pIes;
2313 }
2314 else
2315 {
2316 //The pIes is allocated by someone else. make a copy
2317 //Only to save parsed IEs if caller provides a filter. Most likely the caller
2318 //is using to for association, hence save the parsed IEs
Kiet Lam3cac75e2013-07-12 13:56:44 +05302319 pNewIes = vos_mem_malloc(sizeof(tDot11fBeaconIEs));
2320 if ( NULL == pNewIes )
2321 status = eHAL_STATUS_FAILURE;
2322 else
2323 status = eHAL_STATUS_SUCCESS;
2324 if ( HAL_STATUS_SUCCESS( status ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07002325 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05302326 vos_mem_copy(pNewIes, pIes, sizeof( tDot11fBeaconIEs ));
Jeff Johnson295189b2012-06-20 16:38:30 -07002327 }
2328 else
2329 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08002330 smsLog(pMac, LOGE, FL(" fail to allocate memory for IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002331 //Need to free memory allocated by csrMatchBSS
2332 if( !pBssDesc->Result.pvIes )
2333 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05302334 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07002335 }
2336 break;
2337 }
2338 }
2339 }//fMatch
2340 else if( !pBssDesc->Result.pvIes )
2341 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05302342 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07002343 }
2344 }
2345 }
2346 if(NULL == pFilter || fMatch)
2347 {
2348 bssLen = pBssDesc->Result.BssDescriptor.length + sizeof(pBssDesc->Result.BssDescriptor.length);
2349 allocLen = sizeof( tCsrScanResult ) + bssLen;
Kiet Lam3cac75e2013-07-12 13:56:44 +05302350 pResult = vos_mem_malloc(allocLen);
2351 if ( NULL == pResult )
2352 status = eHAL_STATUS_FAILURE;
2353 else
2354 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07002355 if(!HAL_STATUS_SUCCESS(status))
2356 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08002357 smsLog(pMac, LOGE, FL(" fail to allocate memory for scan result, len=%d"), allocLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07002358 if(pNewIes)
2359 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05302360 vos_mem_free(pNewIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07002361 }
2362 break;
2363 }
Kiet Lam3cac75e2013-07-12 13:56:44 +05302364 vos_mem_set(pResult, allocLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002365 pResult->capValue = pBssDesc->capValue;
2366 pResult->preferValue = pBssDesc->preferValue;
2367 pResult->ucEncryptionType = uc;
2368 pResult->mcEncryptionType = mc;
2369 pResult->authType = auth;
2370 pResult->Result.ssId = pBssDesc->Result.ssId;
2371 pResult->Result.timer = 0;
2372 //save the pIes for later use
2373 pResult->Result.pvIes = pNewIes;
2374 //save bss description
Kiet Lam3cac75e2013-07-12 13:56:44 +05302375 vos_mem_copy(&pResult->Result.BssDescriptor,
2376 &pBssDesc->Result.BssDescriptor, bssLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07002377 //No need to lock pRetList because it is locally allocated and no outside can access it at this time
2378 if(csrLLIsListEmpty(&pRetList->List, LL_ACCESS_NOLOCK))
2379 {
2380 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_NOLOCK);
2381 }
2382 else
2383 {
2384 //To sort the list
2385 tListElem *pTmpEntry;
2386 tCsrScanResult *pTmpResult;
2387
2388 pTmpEntry = csrLLPeekHead(&pRetList->List, LL_ACCESS_NOLOCK);
2389 while(pTmpEntry)
2390 {
2391 pTmpResult = GET_BASE_ADDR( pTmpEntry, tCsrScanResult, Link );
2392 if(csrIsBetterBss(pResult, pTmpResult))
2393 {
2394 csrLLInsertEntry(&pRetList->List, pTmpEntry, &pResult->Link, LL_ACCESS_NOLOCK);
2395 //To indicate we are done
2396 pResult = NULL;
2397 break;
2398 }
2399 pTmpEntry = csrLLNext(&pRetList->List, pTmpEntry, LL_ACCESS_NOLOCK);
2400 }
2401 if(pResult != NULL)
2402 {
2403 //This one is not better than any one
2404 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_NOLOCK);
2405 }
2406 }
2407 count++;
2408 }
2409 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK );
2410 }//while
2411 csrLLUnlock(&pMac->scan.scanResultList);
2412
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08002413 smsLog(pMac, LOG2, FL("return %d BSS"), csrLLCount(&pRetList->List));
Jeff Johnson295189b2012-06-20 16:38:30 -07002414
2415 if( !HAL_STATUS_SUCCESS(status) || (phResult == NULL) )
2416 {
2417 //Fail or No one wants the result.
2418 csrScanResultPurge(pMac, (tScanResultHandle)pRetList);
2419 }
2420 else
2421 {
2422 if(0 == count)
2423 {
2424 //We are here meaning the there is no match
2425 csrLLClose(&pRetList->List);
Kiet Lam3cac75e2013-07-12 13:56:44 +05302426 vos_mem_free(pRetList);
Jeff Johnson295189b2012-06-20 16:38:30 -07002427 status = eHAL_STATUS_E_NULL_VALUE;
2428 }
2429 else if(phResult)
2430 {
2431 *phResult = pRetList;
2432 }
2433 }
2434 }//Allocated pRetList
2435
2436 return (status);
2437}
2438
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002439/*
2440 * NOTE: This routine is being added to make
2441 * sure that scan results are not being flushed
2442 * while roaming. If the scan results are flushed,
2443 * we are unable to recover from
2444 * csrRoamRoamingStateDisassocRspProcessor.
2445 * If it is needed to remove this routine,
2446 * first ensure that we recover gracefully from
2447 * csrRoamRoamingStateDisassocRspProcessor if
2448 * csrScanGetResult returns with a failure because
2449 * of not being able to find the roaming BSS.
2450 */
2451tANI_U8 csrScanFlushDenied(tpAniSirGlobal pMac)
2452{
2453 switch(pMac->roam.neighborRoamInfo.neighborRoamState) {
2454 case eCSR_NEIGHBOR_ROAM_STATE_REPORT_SCAN:
2455 case eCSR_NEIGHBOR_ROAM_STATE_PREAUTHENTICATING:
2456 case eCSR_NEIGHBOR_ROAM_STATE_PREAUTH_DONE:
2457 case eCSR_NEIGHBOR_ROAM_STATE_REASSOCIATING:
2458 return (pMac->roam.neighborRoamInfo.neighborRoamState);
2459 default:
2460 return 0;
2461 }
2462}
2463
Jeff Johnson295189b2012-06-20 16:38:30 -07002464eHalStatus csrScanFlushResult(tpAniSirGlobal pMac)
2465{
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002466 tANI_U8 isFlushDenied = csrScanFlushDenied(pMac);
2467 if (isFlushDenied) {
2468 smsLog(pMac, LOGW, "%s: scan flush denied in roam state %d",
2469 __func__, isFlushDenied);
2470 return eHAL_STATUS_FAILURE;
2471 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002472 return ( csrLLScanPurgeResult(pMac, &pMac->scan.scanResultList) );
2473}
2474
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302475eHalStatus csrScanFlushSelectiveResult(tpAniSirGlobal pMac, v_BOOL_t flushP2P)
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002476{
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302477 eHalStatus status = eHAL_STATUS_SUCCESS;
2478 tListElem *pEntry,*pFreeElem;
2479 tCsrScanResult *pBssDesc;
2480 tDblLinkList *pList = &pMac->scan.scanResultList;
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002481
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302482 csrLLLock(pList);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002483
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302484 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK );
2485 while( pEntry != NULL)
2486 {
2487 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2488 if( flushP2P == vos_mem_compare( pBssDesc->Result.ssId.ssId,
2489 "DIRECT-", 7) )
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002490 {
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302491 pFreeElem = pEntry;
2492 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2493 csrLLRemoveEntry(pList, pFreeElem, LL_ACCESS_NOLOCK);
2494 csrFreeScanResultEntry( pMac, pBssDesc );
2495 continue;
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002496 }
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302497 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2498 }
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002499
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302500 csrLLUnlock(pList);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002501
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302502 return (status);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002503}
2504
Jeff Johnson295189b2012-06-20 16:38:30 -07002505/**
2506 * csrCheck11dChannel
2507 *
2508 *FUNCTION:
2509 * This function is called from csrScanFilter11dResult function and
2510 * compare channel number with given channel list.
2511 *
2512 *LOGIC:
2513 * Check Scan result channel number with CFG channel list
2514 *
2515 *ASSUMPTIONS:
2516 *
2517 *
2518 *NOTE:
2519 *
2520 * @param channelId channel number
2521 * @param pChannelList Pointer to channel list
2522 * @param numChannels Number of channel in channel list
2523 *
2524 * @return Status
2525 */
2526
2527eHalStatus csrCheck11dChannel(tANI_U8 channelId, tANI_U8 *pChannelList, tANI_U32 numChannels)
2528{
2529 eHalStatus status = eHAL_STATUS_FAILURE;
2530 tANI_U8 i = 0;
2531
2532 for (i = 0; i < numChannels; i++)
2533 {
2534 if(pChannelList[ i ] == channelId)
2535 {
2536 status = eHAL_STATUS_SUCCESS;
2537 break;
2538 }
2539 }
2540 return status;
2541}
2542
2543/**
2544 * csrScanFilter11dResult
2545 *
2546 *FUNCTION:
2547 * This function is called from csrApplyCountryInformation function and
2548 * filter scan result based on valid channel list number.
2549 *
2550 *LOGIC:
2551 * Get scan result from scan list and Check Scan result channel number
2552 * with 11d channel list if channel number is found in 11d channel list
2553 * then do not remove scan result entry from scan list
2554 *
2555 *ASSUMPTIONS:
2556 *
2557 *
2558 *NOTE:
2559 *
2560 * @param pMac Pointer to Global MAC structure
2561 *
2562 * @return Status
2563 */
2564
2565eHalStatus csrScanFilter11dResult(tpAniSirGlobal pMac)
2566{
2567 eHalStatus status = eHAL_STATUS_SUCCESS;
2568 tListElem *pEntry,*pTempEntry;
2569 tCsrScanResult *pBssDesc;
2570 tANI_U32 len = sizeof(pMac->roam.validChannelList);
2571
2572 /* Get valid channels list from CFG */
2573 if (!HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac,
2574 pMac->roam.validChannelList, &len)))
2575 {
Agarwal Ashishcbe1f0c2013-07-21 03:01:48 +05302576 smsLog( pMac, LOGE, "Failed to get Channel list from CFG");
Jeff Johnson295189b2012-06-20 16:38:30 -07002577 }
2578
2579 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
2580 while( pEntry )
2581 {
2582 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2583 pTempEntry = csrLLNext( &pMac->scan.scanResultList, pEntry,
2584 LL_ACCESS_LOCK );
2585 if(csrCheck11dChannel(pBssDesc->Result.BssDescriptor.channelId,
2586 pMac->roam.validChannelList, len))
2587 {
2588 /* Remove Scan result which does not have 11d channel */
2589 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry,
2590 LL_ACCESS_LOCK ))
2591 {
2592 csrFreeScanResultEntry( pMac, pBssDesc );
2593 }
2594 }
2595 pEntry = pTempEntry;
2596 }
2597 return status;
2598}
2599
2600
2601eHalStatus csrScanCopyResultList(tpAniSirGlobal pMac, tScanResultHandle hIn, tScanResultHandle *phResult)
2602{
2603 eHalStatus status = eHAL_STATUS_SUCCESS;
2604 tScanResultList *pRetList, *pInList = (tScanResultList *)hIn;
2605 tCsrScanResult *pResult, *pScanResult;
2606 tANI_U32 count = 0;
2607 tListElem *pEntry;
2608 tANI_U32 bssLen, allocLen;
2609
2610 if(phResult)
2611 {
2612 *phResult = CSR_INVALID_SCANRESULT_HANDLE;
2613 }
Kiet Lam3cac75e2013-07-12 13:56:44 +05302614 pRetList = vos_mem_malloc(sizeof(tScanResultList));
2615 if ( NULL == pRetList )
2616 status = eHAL_STATUS_FAILURE;
2617 else
Jeff Johnson295189b2012-06-20 16:38:30 -07002618 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05302619 vos_mem_set(pRetList, sizeof(tScanResultList), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002620 csrLLOpen(pMac->hHdd, &pRetList->List);
2621 pRetList->pCurEntry = NULL;
2622 csrLLLock(&pMac->scan.scanResultList);
2623 csrLLLock(&pInList->List);
2624
2625 pEntry = csrLLPeekHead( &pInList->List, LL_ACCESS_NOLOCK );
2626 while( pEntry )
2627 {
2628 pScanResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2629 bssLen = pScanResult->Result.BssDescriptor.length + sizeof(pScanResult->Result.BssDescriptor.length);
2630 allocLen = sizeof( tCsrScanResult ) + bssLen;
Kiet Lam3cac75e2013-07-12 13:56:44 +05302631 pResult = vos_mem_malloc(allocLen);
2632 if ( NULL == pResult )
2633 status = eHAL_STATUS_FAILURE;
2634 else
2635 status = eHAL_STATUS_SUCCESS;
2636 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07002637 {
2638 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
2639 count = 0;
2640 break;
2641 }
Kiet Lam3cac75e2013-07-12 13:56:44 +05302642 vos_mem_set(pResult, allocLen , 0);
2643 vos_mem_copy(&pResult->Result.BssDescriptor, &pScanResult->Result.BssDescriptor, bssLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07002644 if( pScanResult->Result.pvIes )
2645 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05302646 pResult->Result.pvIes = vos_mem_malloc(sizeof( tDot11fBeaconIEs ));
2647 if ( NULL == pResult->Result.pvIes )
2648 status = eHAL_STATUS_FAILURE;
2649 else
2650 status = eHAL_STATUS_SUCCESS;
2651 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07002652 {
2653 //Free the memory we allocate above first
Kiet Lam3cac75e2013-07-12 13:56:44 +05302654 vos_mem_free(pResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07002655 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
2656 count = 0;
2657 break;
2658 }
Kiet Lam3cac75e2013-07-12 13:56:44 +05302659 vos_mem_copy(pResult->Result.pvIes, pScanResult->Result.pvIes,
2660 sizeof( tDot11fBeaconIEs ));
Jeff Johnson295189b2012-06-20 16:38:30 -07002661 }
2662 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_LOCK);
2663 count++;
2664 pEntry = csrLLNext( &pInList->List, pEntry, LL_ACCESS_NOLOCK );
2665 }//while
2666 csrLLUnlock(&pInList->List);
2667 csrLLUnlock(&pMac->scan.scanResultList);
2668
2669 if(HAL_STATUS_SUCCESS(status))
2670 {
2671 if(0 == count)
2672 {
2673 csrLLClose(&pRetList->List);
Kiet Lam3cac75e2013-07-12 13:56:44 +05302674 vos_mem_free(pRetList);
Jeff Johnson295189b2012-06-20 16:38:30 -07002675 status = eHAL_STATUS_E_NULL_VALUE;
2676 }
2677 else if(phResult)
2678 {
2679 *phResult = pRetList;
2680 }
2681 }
2682 }//Allocated pRetList
2683
2684 return (status);
2685}
2686
2687
2688
2689eHalStatus csrScanningStateMsgProcessor( tpAniSirGlobal pMac, void *pMsgBuf )
2690{
2691 eHalStatus status = eHAL_STATUS_SUCCESS;
2692 tSirMbMsg *pMsg = (tSirMbMsg *)pMsgBuf;
2693
2694 if((eWNI_SME_SCAN_RSP == pMsg->type) || (eWNI_SME_GET_SCANNED_CHANNEL_RSP == pMsg->type))
2695 {
2696 status = csrScanSmeScanResponse( pMac, pMsgBuf );
2697 }
2698 else
2699 {
Madan Mohan Koyyalamudi15407ac2013-01-11 15:30:36 -08002700 if(pMsg->type == eWNI_SME_UPPER_LAYER_ASSOC_CNF)
Jeff Johnson295189b2012-06-20 16:38:30 -07002701 {
Madan Mohan Koyyalamudi15407ac2013-01-11 15:30:36 -08002702 tCsrRoamSession *pSession;
2703 tSirSmeAssocIndToUpperLayerCnf *pUpperLayerAssocCnf;
2704 tCsrRoamInfo roamInfo;
2705 tCsrRoamInfo *pRoamInfo = NULL;
2706 tANI_U32 sessionId;
2707 eHalStatus status;
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08002708 smsLog( pMac, LOG1, FL("Scanning : ASSOCIATION confirmation can be given to upper layer "));
Kiet Lam3cac75e2013-07-12 13:56:44 +05302709 vos_mem_set(&roamInfo, sizeof(tCsrRoamInfo), 0);
Madan Mohan Koyyalamudi15407ac2013-01-11 15:30:36 -08002710 pRoamInfo = &roamInfo;
2711 pUpperLayerAssocCnf = (tSirSmeAssocIndToUpperLayerCnf *)pMsgBuf;
2712 status = csrRoamGetSessionIdFromBSSID( pMac, (tCsrBssid *)pUpperLayerAssocCnf->bssId, &sessionId );
2713 pSession = CSR_GET_SESSION(pMac, sessionId);
2714
2715 if(!pSession)
2716 {
2717 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
2718 return eHAL_STATUS_FAILURE;
2719 }
2720
2721 pRoamInfo->statusCode = eSIR_SME_SUCCESS; //send the status code as Success
2722 pRoamInfo->u.pConnectedProfile = &pSession->connectedProfile;
2723 pRoamInfo->staId = (tANI_U8)pUpperLayerAssocCnf->aid;
2724 pRoamInfo->rsnIELen = (tANI_U8)pUpperLayerAssocCnf->rsnIE.length;
2725 pRoamInfo->prsnIE = pUpperLayerAssocCnf->rsnIE.rsnIEdata;
2726 pRoamInfo->addIELen = (tANI_U8)pUpperLayerAssocCnf->addIE.length;
2727 pRoamInfo->paddIE = pUpperLayerAssocCnf->addIE.addIEdata;
Kiet Lam3cac75e2013-07-12 13:56:44 +05302728 vos_mem_copy(pRoamInfo->peerMac, pUpperLayerAssocCnf->peerMacAddr, sizeof(tSirMacAddr));
2729 vos_mem_copy(&pRoamInfo->bssid, pUpperLayerAssocCnf->bssId, sizeof(tCsrBssid));
Madan Mohan Koyyalamudi15407ac2013-01-11 15:30:36 -08002730 pRoamInfo->wmmEnabledSta = pUpperLayerAssocCnf->wmmEnabledSta;
2731 if(CSR_IS_INFRA_AP(pRoamInfo->u.pConnectedProfile) )
2732 {
2733 pMac->roam.roamSession[sessionId].connectState = eCSR_ASSOC_STATE_TYPE_INFRA_CONNECTED;
2734 pRoamInfo->fReassocReq = pUpperLayerAssocCnf->reassocReq;
2735 status = csrRoamCallCallback(pMac, sessionId, pRoamInfo, 0, eCSR_ROAM_INFRA_IND, eCSR_ROAM_RESULT_INFRA_ASSOCIATION_CNF);
2736 }
2737 if(CSR_IS_WDS_AP( pRoamInfo->u.pConnectedProfile))
2738 {
2739 vos_sleep( 100 );
2740 pMac->roam.roamSession[sessionId].connectState = eCSR_ASSOC_STATE_TYPE_WDS_CONNECTED;//Sta
2741 status = csrRoamCallCallback(pMac, sessionId, pRoamInfo, 0, eCSR_ROAM_WDS_IND, eCSR_ROAM_RESULT_WDS_ASSOCIATION_IND);//Sta
2742 }
2743
Jeff Johnson295189b2012-06-20 16:38:30 -07002744 }
2745 else
2746 {
Madan Mohan Koyyalamudi15407ac2013-01-11 15:30:36 -08002747
2748 if( csrIsAnySessionInConnectState( pMac ) )
2749 {
2750 //In case of we are connected, we need to check whether connect status changes
2751 //because scan may also run while connected.
2752 csrRoamCheckForLinkStatusChange( pMac, ( tSirSmeRsp * )pMsgBuf );
2753 }
2754 else
2755 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08002756 smsLog( pMac, LOGW, "Message [0x%04x] received in state, when expecting Scan Response", pMsg->type );
Madan Mohan Koyyalamudi15407ac2013-01-11 15:30:36 -08002757 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002758 }
2759 }
2760
2761 return (status);
2762}
2763
2764
2765
2766void csrCheckNSaveWscIe(tpAniSirGlobal pMac, tSirBssDescription *pNewBssDescr, tSirBssDescription *pOldBssDescr)
2767{
2768 int idx, len;
2769 tANI_U8 *pbIe;
2770
2771 //If failed to remove, assuming someone else got it.
2772 if((pNewBssDescr->fProbeRsp != pOldBssDescr->fProbeRsp) &&
2773 (0 == pNewBssDescr->WscIeLen))
2774 {
2775 idx = 0;
2776 len = pOldBssDescr->length - sizeof(tSirBssDescription) +
2777 sizeof(tANI_U16) + sizeof(tANI_U32) - DOT11F_IE_WSCPROBERES_MIN_LEN - 2;
2778 pbIe = (tANI_U8 *)pOldBssDescr->ieFields;
2779 //Save WPS IE if it exists
2780 pNewBssDescr->WscIeLen = 0;
2781 while(idx < len)
2782 {
2783 if((DOT11F_EID_WSCPROBERES == pbIe[0]) &&
2784 (0x00 == pbIe[2]) && (0x50 == pbIe[3]) && (0xf2 == pbIe[4]) && (0x04 == pbIe[5]))
2785 {
2786 //Founrd it
2787 if((DOT11F_IE_WSCPROBERES_MAX_LEN - 2) >= pbIe[1])
2788 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05302789 vos_mem_copy(pNewBssDescr->WscIeProbeRsp, pbIe, pbIe[1] + 2);
Jeff Johnson295189b2012-06-20 16:38:30 -07002790 pNewBssDescr->WscIeLen = pbIe[1] + 2;
2791 }
2792 break;
2793 }
2794 idx += pbIe[1] + 2;
2795 pbIe += pbIe[1] + 2;
2796 }
2797 }
2798}
2799
2800
2801
2802//pIes may be NULL
2803tANI_BOOLEAN csrRemoveDupBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDescr,
Madan Mohan Koyyalamudi0dea29e2013-07-11 12:01:37 +05302804 tDot11fBeaconIEs *pIes, tAniSSID *pSsid, v_TIME_t *timer, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07002805{
2806 tListElem *pEntry;
2807
2808 tCsrScanResult *pBssDesc;
2809 tANI_BOOLEAN fRC = FALSE;
2810
2811 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
2812 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
2813 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
2814 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
2815
2816 while( pEntry )
2817 {
2818 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2819
2820 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
2821 // matches
2822 if ( csrIsDuplicateBssDescription( pMac, &pBssDesc->Result.BssDescriptor,
Tushnim Bhattacharyya4207db02013-06-26 23:23:18 -07002823 pSirBssDescr, pIes, fForced ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07002824 {
2825 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
2826 ((tANI_S32)pBssDesc->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
2827 // Remove the 'old' entry from the list....
2828 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry, LL_ACCESS_LOCK ) )
2829 {
2830 // !we need to free the memory associated with this node
2831 //If failed to remove, assuming someone else got it.
2832 *pSsid = pBssDesc->Result.ssId;
2833 *timer = pBssDesc->Result.timer;
2834 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pBssDesc->Result.BssDescriptor);
2835
2836 csrFreeScanResultEntry( pMac, pBssDesc );
2837 }
2838 else
2839 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08002840 smsLog( pMac, LOGW, FL( " fail to remove entry" ) );
Jeff Johnson295189b2012-06-20 16:38:30 -07002841 }
2842 fRC = TRUE;
2843
2844 // If we found a match, we can stop looking through the list.
2845 break;
2846 }
2847
2848 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_LOCK );
2849 }
2850
2851 return fRC;
2852}
2853
2854
2855eHalStatus csrAddPMKIDCandidateList( tpAniSirGlobal pMac, tANI_U32 sessionId,
2856 tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes )
2857{
2858 eHalStatus status = eHAL_STATUS_FAILURE;
2859 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
2860
Jeff Johnson32d95a32012-09-10 13:15:23 -07002861 if(!pSession)
2862 {
2863 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
2864 return eHAL_STATUS_FAILURE;
2865 }
2866
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08002867 smsLog(pMac, LOGW, "csrAddPMKIDCandidateList called pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07002868 if( pIes )
2869 {
2870 // check if this is a RSN BSS
2871 if( pIes->RSN.present )
2872 {
2873 // Check if the BSS is capable of doing pre-authentication
2874 if( pSession->NumPmkidCandidate < CSR_MAX_PMKID_ALLOWED )
2875 {
2876
2877#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
2878 {
2879 WLAN_VOS_DIAG_EVENT_DEF(secEvent, vos_event_wlan_security_payload_type);
Kiet Lam3cac75e2013-07-12 13:56:44 +05302880 vos_mem_set(&secEvent, sizeof(vos_event_wlan_security_payload_type), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002881 secEvent.eventId = WLAN_SECURITY_EVENT_PMKID_CANDIDATE_FOUND;
2882 secEvent.encryptionModeMulticast =
2883 (v_U8_t)diagEncTypeFromCSRType(pSession->connectedProfile.mcEncryptionType);
2884 secEvent.encryptionModeUnicast =
2885 (v_U8_t)diagEncTypeFromCSRType(pSession->connectedProfile.EncryptionType);
Kiet Lam3cac75e2013-07-12 13:56:44 +05302886 vos_mem_copy(secEvent.bssid, pSession->connectedProfile.bssid, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07002887 secEvent.authMode =
2888 (v_U8_t)diagAuthTypeFromCSRType(pSession->connectedProfile.AuthType);
2889 WLAN_VOS_DIAG_EVENT_REPORT(&secEvent, EVENT_WLAN_SECURITY);
2890 }
2891#endif//#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
2892
2893 // if yes, then add to PMKIDCandidateList
Kiet Lam3cac75e2013-07-12 13:56:44 +05302894 vos_mem_copy(pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].BSSID,
2895 pBssDesc->bssId, WNI_CFG_BSSID_LEN);
2896 // Bit 0 offirst byte - PreAuthentication Capability
2897 if ( (pIes->RSN.RSN_Cap[0] >> 0) & 0x1 )
Jeff Johnson295189b2012-06-20 16:38:30 -07002898 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05302899 pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].preAuthSupported
2900 = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07002901 }
Kiet Lam3cac75e2013-07-12 13:56:44 +05302902 else
2903 {
2904 pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].preAuthSupported
2905 = eANI_BOOLEAN_FALSE;
2906 }
2907 pSession->NumPmkidCandidate++;
Jeff Johnson295189b2012-06-20 16:38:30 -07002908 }
2909 else
2910 {
2911 status = eHAL_STATUS_FAILURE;
2912 }
2913 }
2914 }
2915
2916 return (status);
2917}
2918
2919//This function checks whether new AP is found for the current connected profile
2920//If it is found, it return the sessionId, else it return invalid sessionID
2921tANI_U32 csrProcessBSSDescForPMKIDList(tpAniSirGlobal pMac,
2922 tSirBssDescription *pBssDesc,
2923 tDot11fBeaconIEs *pIes)
2924{
2925 tANI_U32 i, bRet = CSR_SESSION_ID_INVALID;
2926 tCsrRoamSession *pSession;
2927 tDot11fBeaconIEs *pIesLocal = pIes;
2928
2929 if( pIesLocal || HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIesLocal)) )
2930 {
2931 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
2932 {
2933 if( CSR_IS_SESSION_VALID( pMac, i ) )
2934 {
2935 pSession = CSR_GET_SESSION( pMac, i );
2936 if( csrIsConnStateConnectedInfra( pMac, i ) &&
2937 ( eCSR_AUTH_TYPE_RSN == pSession->connectedProfile.AuthType ) )
2938 {
2939 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile, pBssDesc, pIesLocal))
2940 {
2941 //this new BSS fits the current profile connected
2942 if(HAL_STATUS_SUCCESS(csrAddPMKIDCandidateList(pMac, i, pBssDesc, pIesLocal)))
2943 {
2944 bRet = i;
2945 }
2946 break;
2947 }
2948 }
2949 }
2950 }
2951 if( !pIes )
2952 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05302953 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07002954 }
2955 }
2956
2957 return (tANI_U8)bRet;
2958}
2959
2960#ifdef FEATURE_WLAN_WAPI
2961eHalStatus csrAddBKIDCandidateList( tpAniSirGlobal pMac, tANI_U32 sessionId,
2962 tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes )
2963{
2964 eHalStatus status = eHAL_STATUS_FAILURE;
2965 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
2966
Jeff Johnson32d95a32012-09-10 13:15:23 -07002967 if(!pSession)
2968 {
2969 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
2970 return eHAL_STATUS_FAILURE;
2971 }
2972
Kiet Lam3cac75e2013-07-12 13:56:44 +05302973 smsLog(pMac, LOGW, "csrAddBKIDCandidateList called pMac->scan.NumBkidCandidate = %d",
2974 pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07002975 if( pIes )
2976 {
2977 // check if this is a WAPI BSS
2978 if( pIes->WAPI.present )
2979 {
2980 // Check if the BSS is capable of doing pre-authentication
2981 if( pSession->NumBkidCandidate < CSR_MAX_BKID_ALLOWED )
2982 {
2983
2984 // if yes, then add to BKIDCandidateList
Kiet Lam3cac75e2013-07-12 13:56:44 +05302985 vos_mem_copy(pSession->BkidCandidateInfo[pSession->NumBkidCandidate].BSSID,
2986 pBssDesc->bssId, WNI_CFG_BSSID_LEN);
2987 if ( pIes->WAPI.preauth )
Jeff Johnson295189b2012-06-20 16:38:30 -07002988 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05302989 pSession->BkidCandidateInfo[pSession->NumBkidCandidate].preAuthSupported
2990 = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07002991 }
Kiet Lam3cac75e2013-07-12 13:56:44 +05302992 else
2993 {
2994 pSession->BkidCandidateInfo[pSession->NumBkidCandidate].preAuthSupported
2995 = eANI_BOOLEAN_FALSE;
2996 }
2997 pSession->NumBkidCandidate++;
Jeff Johnson295189b2012-06-20 16:38:30 -07002998 }
2999 else
3000 {
3001 status = eHAL_STATUS_FAILURE;
3002 }
3003 }
3004 }
3005
3006 return (status);
3007}
3008
3009//This function checks whether new AP is found for the current connected profile
3010//if so add to BKIDCandidateList
3011tANI_BOOLEAN csrProcessBSSDescForBKIDList(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
3012 tDot11fBeaconIEs *pIes)
3013{
3014 tANI_BOOLEAN fRC = FALSE;
3015 tDot11fBeaconIEs *pIesLocal = pIes;
3016 tANI_U32 sessionId;
3017 tCsrRoamSession *pSession;
3018
3019 if( pIesLocal || HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIesLocal)) )
3020 {
3021 for( sessionId = 0; sessionId < CSR_ROAM_SESSION_MAX; sessionId++ )
3022 {
3023 if( CSR_IS_SESSION_VALID( pMac, sessionId) )
3024 {
3025 pSession = CSR_GET_SESSION( pMac, sessionId );
3026 if( csrIsConnStateConnectedInfra( pMac, sessionId ) &&
3027 eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE == pSession->connectedProfile.AuthType)
3028 {
3029 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile,pBssDesc, pIesLocal))
3030 {
3031 //this new BSS fits the current profile connected
3032 if(HAL_STATUS_SUCCESS(csrAddBKIDCandidateList(pMac, sessionId, pBssDesc, pIesLocal)))
3033 {
3034 fRC = TRUE;
3035 }
3036 }
3037 }
3038 }
3039 }
3040 if(!pIes)
3041 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05303042 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003043 }
3044
3045 }
3046 return fRC;
3047}
3048
3049#endif
3050
3051
Varun Reddy Yeturu08614702013-04-15 21:58:13 -07003052static void csrMoveTempScanResultsToMainList( tpAniSirGlobal pMac, tANI_U8 reason )
Jeff Johnson295189b2012-06-20 16:38:30 -07003053{
3054 tListElem *pEntry;
Madan Mohan Koyyalamudi8fe78832013-09-13 00:06:17 +05303055 tListElem *pEntryTemp;
3056 tListElem *pNext;
Jeff Johnson295189b2012-06-20 16:38:30 -07003057 tCsrScanResult *pBssDescription;
3058 tANI_S8 cand_Bss_rssi;
Madan Mohan Koyyalamudi8fe78832013-09-13 00:06:17 +05303059 tANI_S8 rssi_of_current_country;
Jeff Johnson295189b2012-06-20 16:38:30 -07003060 tANI_BOOLEAN fDupBss;
3061#ifdef FEATURE_WLAN_WAPI
3062 tANI_BOOLEAN fNewWapiBSSForCurConnection = eANI_BOOLEAN_FALSE;
3063#endif /* FEATURE_WLAN_WAPI */
3064 tDot11fBeaconIEs *pIesLocal = NULL;
3065 tANI_U32 sessionId = CSR_SESSION_ID_INVALID;
3066 tAniSSID tmpSsid;
3067 v_TIME_t timer=0;
Madan Mohan Koyyalamudi8fe78832013-09-13 00:06:17 +05303068 tCsrBssid bssid_temp = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
Jeff Johnson295189b2012-06-20 16:38:30 -07003069
3070 tmpSsid.length = 0;
3071 cand_Bss_rssi = -128; // RSSI coming from PE is -ve
Madan Mohan Koyyalamudi8fe78832013-09-13 00:06:17 +05303072 rssi_of_current_country = -128;
Jeff Johnson295189b2012-06-20 16:38:30 -07003073
3074 // remove the BSS descriptions from temporary list
3075 while( ( pEntry = csrLLRemoveTail( &pMac->scan.tempScanResults, LL_ACCESS_LOCK ) ) != NULL)
3076 {
3077 pBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3078
Arif Hussain8c303d82013-11-15 15:10:03 -08003079 smsLog( pMac, LOGW, "...Bssid= "MAC_ADDRESS_STR" chan= %d, rssi = -%d",
3080 MAC_ADDR_ARRAY(pBssDescription->Result.BssDescriptor.bssId),
Jeff Johnson295189b2012-06-20 16:38:30 -07003081 pBssDescription->Result.BssDescriptor.channelId,
3082 pBssDescription->Result.BssDescriptor.rssi * (-1) );
3083
3084 //At this time, pBssDescription->Result.pvIes may be NULL
3085 pIesLocal = (tDot11fBeaconIEs *)( pBssDescription->Result.pvIes );
3086 if( !pIesLocal && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pBssDescription->Result.BssDescriptor, &pIesLocal))) )
3087 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08003088 smsLog(pMac, LOGE, FL(" Cannot pared IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003089 csrFreeScanResultEntry(pMac, pBssDescription);
3090 continue;
3091 }
Madan Mohan Koyyalamudi0dea29e2013-07-11 12:01:37 +05303092 fDupBss = csrRemoveDupBssDescription( pMac, &pBssDescription->Result.BssDescriptor, pIesLocal, &tmpSsid, &timer, FALSE );
Varun Reddy Yeturu08614702013-04-15 21:58:13 -07003093 //Check whether we have reach out limit, but don't lose the LFR candidates came from FW
3094 if( CSR_SCAN_IS_OVER_BSS_LIMIT(pMac)
3095#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
3096 && !( eCsrScanGetLfrResult == reason )
3097#endif
3098 )
Jeff Johnson295189b2012-06-20 16:38:30 -07003099 {
3100 //Limit reach
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08003101 smsLog(pMac, LOGW, FL(" BSS limit reached"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003102 //Free the resources
3103 if( (pBssDescription->Result.pvIes == NULL) && pIesLocal )
3104 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05303105 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003106 }
3107 csrFreeScanResultEntry(pMac, pBssDescription);
3108 //Continue because there may be duplicated BSS
3109 continue;
3110 }
3111 // check for duplicate scan results
3112 if ( !fDupBss )
3113 {
3114 //Found a new BSS
3115 sessionId = csrProcessBSSDescForPMKIDList(pMac,
3116 &pBssDescription->Result.BssDescriptor, pIesLocal);
3117 if( CSR_SESSION_ID_INVALID != sessionId)
3118 {
3119 csrRoamCallCallback(pMac, sessionId, NULL, 0,
3120 eCSR_ROAM_SCAN_FOUND_NEW_BSS, eCSR_ROAM_RESULT_NONE);
3121 }
3122 }
3123 else
3124 {
3125 //Check if the new one has SSID it it, if not, use the older SSID if it exists.
3126 if( (0 == pBssDescription->Result.ssId.length) && tmpSsid.length )
3127 {
3128 //New BSS has a hidden SSID and old one has the SSID. Keep the SSID only
3129 //if diff of saved SSID time and current time is less than 1 min to avoid
3130 //side effect of saving SSID with old one is that if AP changes its SSID while remain
3131 //hidden, we may never see it and also to address the requirement of
3132 //When we remove hidden ssid from the profile i.e., forget the SSID via
3133 // GUI that SSID shouldn't see in the profile
3134 if( (vos_timer_get_system_time() - timer) <= HIDDEN_TIMER)
3135 {
3136 pBssDescription->Result.timer = timer;
3137 pBssDescription->Result.ssId = tmpSsid;
3138 }
3139 }
3140 }
3141
Madan Mohan Koyyalamudi8fe78832013-09-13 00:06:17 +05303142 //Find a good AP for 11d info
3143 if ( csrIs11dSupported( pMac ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003144 {
Madan Mohan Koyyalamudi8fe78832013-09-13 00:06:17 +05303145 if (cand_Bss_rssi < pBssDescription->Result.BssDescriptor.rssi)
Jeff Johnson295189b2012-06-20 16:38:30 -07003146 {
3147 // check if country information element is present
Madan Mohan Koyyalamudi8fe78832013-09-13 00:06:17 +05303148 if (pIesLocal->Country.present)
Jeff Johnson295189b2012-06-20 16:38:30 -07003149 {
3150 cand_Bss_rssi = pBssDescription->Result.BssDescriptor.rssi;
Madan Mohan Koyyalamudi8fe78832013-09-13 00:06:17 +05303151 smsLog(pMac, LOGW, FL("11d AP Bssid " MAC_ADDRESS_STR
3152 " chan= %d, rssi = -%d, countryCode %c%c"),
3153 MAC_ADDR_ARRAY( pBssDescription->Result.BssDescriptor.bssId),
3154 pBssDescription->Result.BssDescriptor.channelId,
3155 pBssDescription->Result.BssDescriptor.rssi * (-1),
3156 pIesLocal->Country.country[0],pIesLocal->Country.country[1] );
3157 //Getting BSSID for best AP in scan result.
Kiet Lamaa0b59c2013-11-16 21:24:16 +05303158 vos_mem_copy(bssid_temp,
Madan Mohan Koyyalamudi8fe78832013-09-13 00:06:17 +05303159 pBssDescription->Result.BssDescriptor.bssId, sizeof(tSirMacAddr));
3160
Jeff Johnson295189b2012-06-20 16:38:30 -07003161 }
3162
3163 }
3164 }
Madan Mohan Koyyalamudi8fe78832013-09-13 00:06:17 +05303165 //get current rssi for BSS from which country code is acquired.
3166 if ( csrIs11dSupported(pMac) && (csrIsMacAddressEqual(pMac,
3167 &pMac->scan.currentCountryBssid,
3168 &pBssDescription->Result.BssDescriptor.bssId) ))
3169 {
3170 smsLog(pMac, LOGW, FL("Information about current country Bssid "
3171 MAC_ADDRESS_STR
3172 " chan= %d, rssi = -%d, countryCode %c%c"),
3173 MAC_ADDR_ARRAY( pBssDescription->Result.BssDescriptor.bssId),
3174 pBssDescription->Result.BssDescriptor.channelId,
3175 pBssDescription->Result.BssDescriptor.rssi * (-1),
3176 pIesLocal->Country.country[0],pIesLocal->Country.country[1] );
3177 rssi_of_current_country = pBssDescription->Result.BssDescriptor.rssi ;
3178 }
3179
Jeff Johnson295189b2012-06-20 16:38:30 -07003180
Madan Mohan Koyyalamudicca761b2012-12-04 16:41:16 -08003181
Jeff Johnson295189b2012-06-20 16:38:30 -07003182 // append to main list
3183 csrScanAddResult(pMac, pBssDescription, pIesLocal);
Madan Mohan Koyyalamudi8fe78832013-09-13 00:06:17 +05303184 if ( (pBssDescription->Result.pvIes == NULL) && pIesLocal )
Jeff Johnson295189b2012-06-20 16:38:30 -07003185 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05303186 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003187 }
3188 }
3189
Tushnim Bhattacharyya996514c2013-10-23 18:55:38 -07003190 //we don't need to update CC while connected to an AP which is advertising CC already
3191 if (csrIs11dSupported(pMac))
3192 {
3193 tANI_U32 i;
3194 tCsrRoamSession *pSession;
3195
3196 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
3197 {
3198 if (CSR_IS_SESSION_VALID( pMac, i ) )
3199 {
3200 pSession = CSR_GET_SESSION( pMac, i );
3201 if (csrIsConnStateConnected(pMac, i))
3202 {
3203 if (csrIsBssidMatch(pMac, (tCsrBssid *)&pMac->scan.currentCountryBssid,
3204 &pSession->connectedProfile.bssid))
3205 {
3206 smsLog(pMac, LOGW, FL("No need for updating CC, we will"
3207 "continue with current AP's CC"));
3208 goto end;
3209 }
3210 }
3211 }
3212 }
Tushnim Bhattacharyya996514c2013-10-23 18:55:38 -07003213
Tushnim Bhattacharyya07366842013-10-24 15:58:56 -07003214 // Calculating 30% of current rssi is an idea for not to change
3215 // country code so freq.
3216 if (rssi_of_current_country != -128)
Madan Mohan Koyyalamudi8fe78832013-09-13 00:06:17 +05303217 {
Tushnim Bhattacharyya07366842013-10-24 15:58:56 -07003218 rssi_of_current_country = rssi_of_current_country
3219 - THIRTY_PERCENT(rssi_of_current_country);
Madan Mohan Koyyalamudi8fe78832013-09-13 00:06:17 +05303220 }
Tushnim Bhattacharyyab676a2e2013-10-29 17:27:43 -07003221 //if new candidate AP has 30% better RSSI or this is the first time or
3222 //AP aged out of CSR cache or we are in world CC now
krunal soni6fd05dd2013-11-25 15:00:11 -08003223 if ((rssi_of_current_country <= cand_Bss_rssi &&
3224 rssi_of_current_country != -128) ||
3225 (rssi_of_current_country == -128 &&
3226 pMac->scan.scanProfile.numOfChannels >= MANDATORY_BG_CHANNEL) ||
3227 ('0' == pMac->scan.countryCode11d[ 0 ] &&
3228 '0' == pMac->scan.countryCode11d[ 1 ]))
Tushnim Bhattacharyya07366842013-10-24 15:58:56 -07003229 {
3230 csrLLLock(&pMac->scan.scanResultList);
3231 pEntryTemp = csrLLPeekHead(&pMac->scan.scanResultList, LL_ACCESS_NOLOCK);
3232 while ( NULL != pEntryTemp)
3233 {
3234 pNext = csrLLNext(&pMac->scan.scanResultList, pEntryTemp,
3235 LL_ACCESS_NOLOCK);
3236 pBssDescription = GET_BASE_ADDR( pEntryTemp, tCsrScanResult, Link );
3237 pIesLocal = (tDot11fBeaconIEs *)( pBssDescription->Result.pvIes );
3238 // Need to traverse whole scan list to get description for best 11d AP.
3239 if (csrIsMacAddressEqual(pMac, (tCsrBssid *)&bssid_temp,
3240 (tCsrBssid *) pBssDescription->Result.BssDescriptor.bssId))
3241 {
Tushnim Bhattacharyya07366842013-10-24 15:58:56 -07003242 // Best AP should be passed to update reg domain.
3243 csrLearnCountryInformation( pMac, &pBssDescription->Result.BssDescriptor,
3244 pIesLocal, eANI_BOOLEAN_TRUE );
Tushnim Bhattacharyyab676a2e2013-10-29 17:27:43 -07003245 //this check is to avoid the case of invalid CC set via 11d
3246 //In that case we move to world CC & we are open to any new
3247 //valid CC we can get during scan
3248 if(( '0' != pMac->scan.countryCode11d[ 0 ] && '0' != pMac->scan.countryCode11d[ 1 ] ))
3249 {
Kiet Lamaa0b59c2013-11-16 21:24:16 +05303250 vos_mem_copy(pMac->scan.currentCountryBssid,
Tushnim Bhattacharyyab676a2e2013-10-29 17:27:43 -07003251 bssid_temp, sizeof(tSirMacAddr));
3252 }
Tushnim Bhattacharyya07366842013-10-24 15:58:56 -07003253 break;
3254 }
3255 pEntryTemp = pNext;
3256 }
3257 csrLLUnlock(&pMac->scan.scanResultList);
3258 }
Madan Mohan Koyyalamudi8fe78832013-09-13 00:06:17 +05303259 }
3260
3261
Tushnim Bhattacharyya996514c2013-10-23 18:55:38 -07003262end:
3263 //If we can find the current 11d info in any of the scan results, or
Jeff Johnson295189b2012-06-20 16:38:30 -07003264 // a good enough AP with the 11d info from the scan results then no need to
3265 // get into ambiguous state
3266 if(pMac->scan.fAmbiguous11dInfoFound)
3267 {
3268 if((pMac->scan.fCurrent11dInfoMatch) || (cand_Bss_rssi != -128))
3269 {
3270 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
3271 }
3272 }
3273
3274#ifdef FEATURE_WLAN_WAPI
3275 if(fNewWapiBSSForCurConnection)
3276 {
3277 //remember it first
3278 csrRoamCallCallback(pMac, sessionId, NULL, 0, eCSR_ROAM_SCAN_FOUND_NEW_BSS, eCSR_ROAM_RESULT_NEW_WAPI_BSS);
3279 }
3280#endif /* FEATURE_WLAN_WAPI */
3281
3282 return;
3283}
3284
3285
3286static tCsrScanResult *csrScanSaveBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pBSSDescription,
3287 tDot11fBeaconIEs *pIes)
3288{
3289 tCsrScanResult *pCsrBssDescription = NULL;
3290 tANI_U32 cbBSSDesc;
3291 tANI_U32 cbAllocated;
Jeff Johnson295189b2012-06-20 16:38:30 -07003292
3293 // figure out how big the BSS description is (the BSSDesc->length does NOT
3294 // include the size of the length field itself).
3295 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
3296
3297 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
3298
Kiet Lam3cac75e2013-07-12 13:56:44 +05303299 pCsrBssDescription = vos_mem_malloc(cbAllocated);
3300 if ( NULL != pCsrBssDescription )
Jeff Johnson295189b2012-06-20 16:38:30 -07003301 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05303302 vos_mem_set(pCsrBssDescription, cbAllocated, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003303 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Kiet Lam3cac75e2013-07-12 13:56:44 +05303304 vos_mem_copy(&pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc);
Jeff Johnson295189b2012-06-20 16:38:30 -07003305#if defined(VOSS_ENSBALED)
3306 VOS_ASSERT( pCsrBssDescription->Result.pvIes == NULL );
3307#endif
3308 csrScanAddResult(pMac, pCsrBssDescription, pIes);
3309 }
3310
3311 return( pCsrBssDescription );
3312}
3313
3314// Append a Bss Description...
3315tCsrScanResult *csrScanAppendBssDescription( tpAniSirGlobal pMac,
3316 tSirBssDescription *pSirBssDescription,
Tushnim Bhattacharyya4207db02013-06-26 23:23:18 -07003317 tDot11fBeaconIEs *pIes, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07003318{
3319 tCsrScanResult *pCsrBssDescription = NULL;
3320 tAniSSID tmpSsid;
3321 v_TIME_t timer = 0;
3322 int result;
3323
3324 tmpSsid.length = 0;
Tushnim Bhattacharyya4207db02013-06-26 23:23:18 -07003325 result = csrRemoveDupBssDescription( pMac, pSirBssDescription, pIes, &tmpSsid, &timer, fForced );
Jeff Johnson295189b2012-06-20 16:38:30 -07003326 pCsrBssDescription = csrScanSaveBssDescription( pMac, pSirBssDescription, pIes );
3327 if (result && (pCsrBssDescription != NULL))
3328 {
3329 //Check if the new one has SSID it it, if not, use the older SSID if it exists.
3330 if( (0 == pCsrBssDescription->Result.ssId.length) && tmpSsid.length )
3331 {
3332 //New BSS has a hidden SSID and old one has the SSID. Keep the SSID only
3333 //if diff of saved SSID time and current time is less than 1 min to avoid
3334 //side effect of saving SSID with old one is that if AP changes its SSID while remain
3335 //hidden, we may never see it and also to address the requirement of
3336 //When we remove hidden ssid from the profile i.e., forget the SSID via
3337 // GUI that SSID shouldn't see in the profile
3338 if((vos_timer_get_system_time()-timer) <= HIDDEN_TIMER)
3339 {
3340 pCsrBssDescription->Result.ssId = tmpSsid;
3341 pCsrBssDescription->Result.timer = timer;
3342 }
3343 }
3344 }
3345
3346
3347 return( pCsrBssDescription );
3348}
3349
3350
3351
3352void csrPurgeChannelPower( tpAniSirGlobal pMac, tDblLinkList *pChannelList )
3353{
3354 tCsrChannelPowerInfo *pChannelSet;
3355 tListElem *pEntry;
3356
3357 csrLLLock(pChannelList);
3358 // Remove the channel sets from the learned list and put them in the free list
3359 while( ( pEntry = csrLLRemoveHead( pChannelList, LL_ACCESS_NOLOCK ) ) != NULL)
3360 {
3361 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3362 if( pChannelSet )
3363 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05303364 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003365 }
3366 }
3367 csrLLUnlock(pChannelList);
3368 return;
3369}
3370
3371
3372/*
3373 * Save the channelList into the ultimate storage as the final stage of channel
3374 * Input: pCountryInfo -- the country code (e.g. "USI"), channel list, and power limit are all stored inside this data structure
3375 */
Jeff Johnsone7245742012-09-05 17:12:55 -07003376eHalStatus csrSaveToChannelPower2G_5G( tpAniSirGlobal pMac, tANI_U32 tableSize, tSirMacChanInfo *channelTable )
Jeff Johnson295189b2012-06-20 16:38:30 -07003377{
3378 tANI_U32 i = tableSize / sizeof( tSirMacChanInfo );
3379 tSirMacChanInfo *pChannelInfo;
3380 tCsrChannelPowerInfo *pChannelSet;
3381 tANI_BOOLEAN f2GHzInfoFound = FALSE;
3382 tANI_BOOLEAN f2GListPurged = FALSE, f5GListPurged = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003383
3384 pChannelInfo = channelTable;
3385 // atleast 3 bytes have to be remaining -- from "countryString"
3386 while ( i-- )
3387 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05303388 pChannelSet = vos_mem_malloc(sizeof(tCsrChannelPowerInfo));
3389 if ( NULL != pChannelSet )
Jeff Johnson295189b2012-06-20 16:38:30 -07003390 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05303391 vos_mem_set(pChannelSet, sizeof(tCsrChannelPowerInfo), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003392 pChannelSet->firstChannel = pChannelInfo->firstChanNum;
3393 pChannelSet->numChannels = pChannelInfo->numChannels;
3394
3395 // Now set the inter-channel offset based on the frequency band the channel set lies in
Jeff Johnsone7245742012-09-05 17:12:55 -07003396 if( (CSR_IS_CHANNEL_24GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003397 ((pChannelSet->firstChannel + (pChannelSet->numChannels - 1)) <= CSR_MAX_24GHz_CHANNEL_NUMBER) )
Jeff Johnsone7245742012-09-05 17:12:55 -07003398
Jeff Johnson295189b2012-06-20 16:38:30 -07003399 {
3400 pChannelSet->interChannelOffset = 1;
3401 f2GHzInfoFound = TRUE;
3402 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003403 else if ( (CSR_IS_CHANNEL_5GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003404 ((pChannelSet->firstChannel + ((pChannelSet->numChannels - 1) * 4)) <= CSR_MAX_5GHz_CHANNEL_NUMBER) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003405 {
3406 pChannelSet->interChannelOffset = 4;
3407 f2GHzInfoFound = FALSE;
3408 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003409 else
3410 {
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003411 smsLog( pMac, LOGW, FL("Invalid Channel %d Present in Country IE"),
Jeff Johnsone7245742012-09-05 17:12:55 -07003412 pChannelSet->firstChannel);
Kiet Lam3cac75e2013-07-12 13:56:44 +05303413 vos_mem_free(pChannelSet);
Jeff Johnsone7245742012-09-05 17:12:55 -07003414 return eHAL_STATUS_FAILURE;
3415 }
3416
Jeff Johnson295189b2012-06-20 16:38:30 -07003417 pChannelSet->txPower = CSR_ROAM_MIN( pChannelInfo->maxTxPower, pMac->roam.configParam.nTxPowerCap );
3418
3419 if( f2GHzInfoFound )
3420 {
3421 if( !f2GListPurged )
3422 {
3423 // purge previous results if found new
3424 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList24 );
3425 f2GListPurged = TRUE;
3426 }
3427
3428 if(CSR_IS_OPERATING_BG_BAND(pMac))
3429 {
3430 // add to the list of 2.4 GHz channel sets
3431 csrLLInsertTail( &pMac->scan.channelPowerInfoList24, &pChannelSet->link, LL_ACCESS_LOCK );
3432 }
3433 else {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08003434 smsLog( pMac, LOGW, FL("Adding 11B/G channels in 11A mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003435 pChannelSet->firstChannel);
Kiet Lam3cac75e2013-07-12 13:56:44 +05303436 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003437 }
3438 }
3439 else
3440 {
3441 // 5GHz info found
3442 if( !f5GListPurged )
3443 {
3444 // purge previous results if found new
3445 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList5G );
3446 f5GListPurged = TRUE;
3447 }
3448
3449 if(CSR_IS_OPERATING_A_BAND(pMac))
3450 {
3451 // add to the list of 5GHz channel sets
3452 csrLLInsertTail( &pMac->scan.channelPowerInfoList5G, &pChannelSet->link, LL_ACCESS_LOCK );
3453 }
3454 else {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08003455 smsLog( pMac, LOGW, FL("Adding 11A channels in B/G mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003456 pChannelSet->firstChannel);
Kiet Lam3cac75e2013-07-12 13:56:44 +05303457 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003458 }
3459 }
3460 }
3461
3462 pChannelInfo++; // move to next entry
3463 }
3464
Jeff Johnsone7245742012-09-05 17:12:55 -07003465 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07003466}
3467
Gopichand Nakkala431db382013-05-30 19:53:39 +05303468static void csrClearDfsChannelList( tpAniSirGlobal pMac )
3469{
3470 tSirMbMsg *pMsg;
3471 tANI_U16 msgLen;
Jeff Johnson295189b2012-06-20 16:38:30 -07003472
Gopichand Nakkala431db382013-05-30 19:53:39 +05303473 msgLen = (tANI_U16)(sizeof( tSirMbMsg ));
Kiet Lam3cac75e2013-07-12 13:56:44 +05303474 pMsg = vos_mem_malloc(msgLen);
3475 if ( NULL != pMsg )
Gopichand Nakkala431db382013-05-30 19:53:39 +05303476 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05303477 vos_mem_set((void *)pMsg, msgLen, 0);
Gopichand Nakkala431db382013-05-30 19:53:39 +05303478 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_CLEAR_DFS_CHANNEL_LIST);
3479 pMsg->msgLen = pal_cpu_to_be16(msgLen);
3480 palSendMBMessage(pMac->hHdd, pMsg);
3481 }
3482}
Jeff Johnson295189b2012-06-20 16:38:30 -07003483
3484void csrApplyPower2Current( tpAniSirGlobal pMac )
3485{
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08003486 smsLog( pMac, LOG3, FL(" Updating Cfg with power settings"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003487 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList24, WNI_CFG_MAX_TX_POWER_2_4 );
3488 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList5G, WNI_CFG_MAX_TX_POWER_5 );
3489}
3490
3491
Gopichand Nakkala277e02b2012-12-21 08:03:42 -08003492void csrApplyChannelPowerCountryInfo( tpAniSirGlobal pMac, tCsrChannel *pChannelList, tANI_U8 *countryCode, tANI_BOOLEAN updateRiva)
Jeff Johnson295189b2012-06-20 16:38:30 -07003493{
Gopichand Nakkalaf88ca562013-04-23 20:30:01 +05303494 int i, j, count, countryIndex = -1;
Jeff Johnson295189b2012-06-20 16:38:30 -07003495 eNVChannelEnabledType channelEnabledType;
3496 tANI_U8 numChannels = 0;
3497 tANI_U8 tempNumChannels = 0;
Gopichand Nakkalaf88ca562013-04-23 20:30:01 +05303498 tANI_U8 channelIgnore = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003499 tCsrChannel ChannelList;
Gopichand Nakkalaf88ca562013-04-23 20:30:01 +05303500
Jeff Johnson295189b2012-06-20 16:38:30 -07003501 if( pChannelList->numChannels )
3502 {
Gopichand Nakkalaf88ca562013-04-23 20:30:01 +05303503 for(count=0; count < MAX_COUNTRY_IGNORE; count++)
3504 {
3505 if(vos_mem_compare(countryCode, countryIgnoreList[count].countryCode,
3506 VOS_COUNTRY_CODE_LEN))
3507 {
3508 countryIndex = count;
3509 break;
3510 }
3511 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003512 tempNumChannels = CSR_MIN(pChannelList->numChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN);
3513 /* If user doesn't want to scan the DFS channels lets trim them from
3514 the valid channel list*/
Gopichand Nakkalaf88ca562013-04-23 20:30:01 +05303515 for(i=0; i < tempNumChannels; i++)
Jeff Johnson295189b2012-06-20 16:38:30 -07003516 {
Gopichand Nakkalaf88ca562013-04-23 20:30:01 +05303517 channelIgnore = FALSE;
3518 if( FALSE == pMac->scan.fEnableDFSChnlScan )
3519 {
3520 channelEnabledType =
3521 vos_nv_getChannelEnabledState(pChannelList->channelList[i]);
3522 }
3523 else
3524 {
Madan Mohan Koyyalamudi3f65e312012-11-06 15:31:12 -08003525 channelEnabledType = NV_CHANNEL_ENABLE;
Gopichand Nakkalaf88ca562013-04-23 20:30:01 +05303526 }
3527 if( NV_CHANNEL_ENABLE == channelEnabledType )
3528 {
3529 if( countryIndex != -1 )
3530 {
3531 for(j=0; j < countryIgnoreList[countryIndex].channelCount; j++)
3532 {
3533 if( pChannelList->channelList[i] ==
3534 countryIgnoreList[countryIndex].channelList[j] )
3535 {
3536 channelIgnore = TRUE;
3537 break;
3538 }
3539 }
3540 }
3541 if( FALSE == channelIgnore )
3542 {
3543 ChannelList.channelList[numChannels] = pChannelList->channelList[i];
3544 numChannels++;
3545 }
3546 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003547 }
Gopichand Nakkalaf88ca562013-04-23 20:30:01 +05303548 ChannelList.numChannels = numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -07003549 csrSetCfgValidChannelList(pMac, ChannelList.channelList, ChannelList.numChannels);
3550 // extend scan capability
Gopichand Nakkalaf88ca562013-04-23 20:30:01 +05303551 // build a scan list based on the channel list : channel# + active/passive scan
3552 csrSetCfgScanControlList(pMac, countryCode, &ChannelList);
Gopichand Nakkala431db382013-05-30 19:53:39 +05303553 /*Send msg to Lim to clear DFS channel list */
3554 csrClearDfsChannelList(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07003555#ifdef FEATURE_WLAN_SCAN_PNO
Gopichand Nakkala277e02b2012-12-21 08:03:42 -08003556 if (updateRiva)
3557 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08003558 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO, FL(" Sending 11d PNO info to Riva"));
Gopichand Nakkala277e02b2012-12-21 08:03:42 -08003559 // Send HAL UpdateScanParams message
3560 pmcUpdateScanParams(pMac, &(pMac->roam.configParam), &ChannelList, TRUE);
3561 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003562#endif // FEATURE_WLAN_SCAN_PNO
3563 }
3564 else
3565 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08003566 smsLog( pMac, LOGE, FL(" 11D channel list is empty"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003567 }
3568 csrApplyPower2Current( pMac ); // Store the channel+power info in the global place: Cfg
3569 csrSetCfgCountryCode(pMac, countryCode);
3570}
3571
3572
Gopichand Nakkala277e02b2012-12-21 08:03:42 -08003573void csrResetCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce, tANI_BOOLEAN updateRiva )
Jeff Johnson295189b2012-06-20 16:38:30 -07003574{
3575 if( fForce || (csrIs11dSupported( pMac ) && (!pMac->scan.f11dInfoReset)))
3576 {
3577
3578#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3579 {
3580 vos_log_802_11d_pkt_type *p11dLog;
3581 int Index;
3582
3583 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
3584 if(p11dLog)
3585 {
3586 p11dLog->eventId = WLAN_80211D_EVENT_RESET;
Kiet Lam3cac75e2013-07-12 13:56:44 +05303587 vos_mem_copy(p11dLog->countryCode, pMac->scan.countryCodeCurrent, 3);
Jeff Johnson295189b2012-06-20 16:38:30 -07003588 p11dLog->numChannel = pMac->scan.base20MHzChannels.numChannels;
3589 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
3590 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05303591 vos_mem_copy(p11dLog->Channels,
3592 pMac->scan.base20MHzChannels.channelList,
3593 p11dLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07003594 for (Index=0; Index < pMac->scan.base20MHzChannels.numChannels; Index++)
3595 {
3596 p11dLog->TxPwr[Index] = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
3597 }
3598 }
3599 if(!pMac->roam.configParam.Is11dSupportEnabled)
3600 {
3601 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
3602 }
3603 else if(pMac->roam.configParam.fEnforceDefaultDomain)
3604 {
3605 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
3606 }
3607 else
3608 {
3609 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
3610 }
3611 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
3612 }
3613 }
3614#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3615
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003616 csrPruneChannelListForMode(pMac, &pMac->scan.baseChannels);
3617 csrPruneChannelListForMode(pMac, &pMac->scan.base20MHzChannels);
3618
Jeff Johnson295189b2012-06-20 16:38:30 -07003619 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_FALSE);
3620 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_TRUE);
3621 // ... and apply the channel list, power settings, and the country code.
Gopichand Nakkala277e02b2012-12-21 08:03:42 -08003622 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.base20MHzChannels, pMac->scan.countryCodeCurrent, updateRiva );
Jeff Johnson295189b2012-06-20 16:38:30 -07003623 // clear the 11d channel list
Kiet Lam3cac75e2013-07-12 13:56:44 +05303624 vos_mem_set(&pMac->scan.channels11d, sizeof(pMac->scan.channels11d), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003625 pMac->scan.f11dInfoReset = eANI_BOOLEAN_TRUE;
3626 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_FALSE;
3627 }
3628
3629 return;
3630}
3631
3632
3633eHalStatus csrResetCountryCodeInformation(tpAniSirGlobal pMac, tANI_BOOLEAN *pfRestartNeeded)
3634{
3635 eHalStatus status = eHAL_STATUS_SUCCESS;
3636 tANI_BOOLEAN fRestart = eANI_BOOLEAN_FALSE;
3637
3638 //Use the Country code and domain from EEPROM
Kiet Lam3cac75e2013-07-12 13:56:44 +05303639 vos_mem_copy(pMac->scan.countryCodeCurrent, pMac->scan.countryCodeDefault,
3640 WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07003641 csrSetRegulatoryDomain(pMac, pMac->scan.domainIdCurrent, &fRestart);
Jeff Johnson43971f52012-07-17 12:26:56 -07003642 if( ((eANI_BOOLEAN_FALSE == fRestart) || (pfRestartNeeded == NULL) )
3643 && !csrIsInfraConnected(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -07003644 {
3645 //Only reset the country info if we don't need to restart
Gopichand Nakkala277e02b2012-12-21 08:03:42 -08003646 csrResetCountryInformation(pMac, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07003647 }
3648 if(pfRestartNeeded)
3649 {
3650 *pfRestartNeeded = fRestart;
3651 }
3652
3653 return (status);
3654}
3655
3656
3657eHalStatus csrSetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pCountry, tANI_BOOLEAN *pfRestartNeeded)
3658{
3659 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
3660 v_REGDOMAIN_t domainId;
3661
3662 if(pCountry)
3663 {
Kiet Lamb5dffeb2013-10-14 05:37:09 +05303664 status = csrGetRegulatoryDomainForCountry(pMac, pCountry, &domainId, COUNTRY_USER);
Jeff Johnson295189b2012-06-20 16:38:30 -07003665 if(HAL_STATUS_SUCCESS(status))
3666 {
3667 status = csrSetRegulatoryDomain(pMac, domainId, pfRestartNeeded);
3668 if(HAL_STATUS_SUCCESS(status))
3669 {
3670 //We don't need to check the pMac->roam.configParam.fEnforceDefaultDomain flag here,
3671 //csrSetRegulatoryDomain will fail if the country doesn't fit our domain criteria.
Kiet Lam3cac75e2013-07-12 13:56:44 +05303672 vos_mem_copy(pMac->scan.countryCodeCurrent, pCountry, WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07003673 if((pfRestartNeeded == NULL) || !(*pfRestartNeeded))
3674 {
3675 //Simply set it to cfg. If we need to restart, restart will apply it to the CFG
3676 csrSetCfgCountryCode(pMac, pCountry);
3677 }
3678 }
3679 }
3680 }
3681
3682 return (status);
3683}
3684
3685
3686
3687//caller allocated memory for pNumChn and pChnPowerInfo
3688//As input, *pNumChn has the size of the array of pChnPowerInfo
3689//Upon return, *pNumChn has the number of channels assigned.
3690void csrGetChannelPowerInfo( tpAniSirGlobal pMac, tDblLinkList *pList,
3691 tANI_U32 *pNumChn, tChannelListWithPower *pChnPowerInfo)
3692{
3693 tListElem *pEntry;
3694 tANI_U32 chnIdx = 0, idx;
3695 tCsrChannelPowerInfo *pChannelSet;
3696
3697 //Get 2.4Ghz first
3698 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
3699 while( pEntry && (chnIdx < *pNumChn) )
3700 {
3701 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3702 if ( 1 != pChannelSet->interChannelOffset )
3703 {
3704 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
3705 {
3706 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
3707 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
3708 }
3709 }
3710 else
3711 {
3712 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
3713 {
3714 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + idx);
3715 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
3716 }
3717 }
3718
3719 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
3720 }
3721 *pNumChn = chnIdx;
3722
3723 return ;
3724}
3725
3726
3727
3728void csrApplyCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce )
3729{
3730 v_REGDOMAIN_t domainId;
3731 eHalStatus status = eHAL_STATUS_SUCCESS;
3732
3733 do
3734 {
3735 if( !csrIs11dSupported( pMac ) || 0 == pMac->scan.channelOf11dInfo) break;
3736 if( pMac->scan.fAmbiguous11dInfoFound )
3737 {
3738 // ambiguous info found
3739 //Restore te default domain as well
Kiet Lamb5dffeb2013-10-14 05:37:09 +05303740 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
3741 pMac, pMac->scan.countryCodeCurrent,
3742 &domainId, COUNTRY_QUERY)))
Jeff Johnson295189b2012-06-20 16:38:30 -07003743 {
3744 pMac->scan.domainIdCurrent = domainId;
3745 }
3746 else
3747 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08003748 smsLog(pMac, LOGE, FL(" failed to get domain from currentCountryCode %02X%02X"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003749 pMac->scan.countryCodeCurrent[0], pMac->scan.countryCodeCurrent[1]);
3750 }
Gopichand Nakkala277e02b2012-12-21 08:03:42 -08003751 csrResetCountryInformation( pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE );
Jeff Johnson295189b2012-06-20 16:38:30 -07003752 break;
3753 }
3754 if ( pMac->scan.f11dInfoApplied && !fForce ) break;
Kiet Lamb5dffeb2013-10-14 05:37:09 +05303755 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
3756 pMac, pMac->scan.countryCode11d,
3757 &domainId, COUNTRY_QUERY)))
Jeff Johnson295189b2012-06-20 16:38:30 -07003758 {
3759 //Check whether we need to enforce default domain
3760 if( ( !pMac->roam.configParam.fEnforceDefaultDomain ) ||
3761 (pMac->scan.domainIdCurrent == domainId) )
3762 {
3763
3764#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3765 {
3766 vos_log_802_11d_pkt_type *p11dLog;
3767 tChannelListWithPower chnPwrInfo[WNI_CFG_VALID_CHANNEL_LIST_LEN];
3768 tANI_U32 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN, nTmp;
3769
3770 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
3771 if(p11dLog)
3772 {
3773 p11dLog->eventId = WLAN_80211D_EVENT_COUNTRY_SET;
Kiet Lam3cac75e2013-07-12 13:56:44 +05303774 vos_mem_copy(p11dLog->countryCode, pMac->scan.countryCode11d, 3);
Jeff Johnson295189b2012-06-20 16:38:30 -07003775 p11dLog->numChannel = pMac->scan.channels11d.numChannels;
3776 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
3777 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05303778 vos_mem_copy(p11dLog->Channels,
3779 pMac->scan.channels11d.channelList,
3780 p11dLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07003781 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList24,
3782 &nChnInfo, chnPwrInfo);
3783 nTmp = nChnInfo;
3784 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN - nTmp;
3785 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList5G,
3786 &nChnInfo, &chnPwrInfo[nTmp]);
3787 for(nTmp = 0; nTmp < p11dLog->numChannel; nTmp++)
3788 {
3789 for(nChnInfo = 0; nChnInfo < WNI_CFG_VALID_CHANNEL_LIST_LEN; nChnInfo++)
3790 {
3791 if(p11dLog->Channels[nTmp] == chnPwrInfo[nChnInfo].chanId)
3792 {
3793 p11dLog->TxPwr[nTmp] = chnPwrInfo[nChnInfo].pwr;
3794 break;
3795 }
3796 }
3797 }
3798 }
3799 if(!pMac->roam.configParam.Is11dSupportEnabled)
3800 {
3801 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
3802 }
3803 else if(pMac->roam.configParam.fEnforceDefaultDomain)
3804 {
3805 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
3806 }
3807 else
3808 {
3809 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
3810 }
3811 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
3812 }
3813 }
3814#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3815 if(pMac->scan.domainIdCurrent != domainId)
3816 {
Jeff Johnson295189b2012-06-20 16:38:30 -07003817 smsLog(pMac, LOGW, FL("Domain Changed Old %d, new %d"),
3818 pMac->scan.domainIdCurrent, domainId);
Kiet Lamec0e7f62013-11-07 18:39:01 +05303819 status = WDA_SetRegDomain(pMac, domainId, eSIR_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07003820 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003821 if (status != eHAL_STATUS_SUCCESS)
3822 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08003823 smsLog( pMac, LOGE, FL(" fail to set regId %d"), domainId );
Jeff Johnson295189b2012-06-20 16:38:30 -07003824 }
3825 pMac->scan.domainIdCurrent = domainId;
Kiet Lamb5dffeb2013-10-14 05:37:09 +05303826#ifndef CONFIG_ENABLE_LINUX_REG
Kiet Lamf6cd4a42013-11-19 14:58:29 +05303827 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.base20MHzChannels,
3828 pMac->scan.countryCodeCurrent, eANI_BOOLEAN_TRUE );
Kiet Lamb5dffeb2013-10-14 05:37:09 +05303829#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07003830 // switch to active scans using this new channel list
3831 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
3832 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_TRUE;
3833 pMac->scan.f11dInfoReset = eANI_BOOLEAN_FALSE;
3834 }
3835 }
3836
3837 } while( 0 );
3838
3839 return;
3840}
3841
3842
3843
3844tANI_BOOLEAN csrSave11dCountryString( tpAniSirGlobal pMac, tANI_U8 *pCountryCode,
3845 tANI_BOOLEAN fForce)
3846{
3847 tANI_BOOLEAN fCountryStringChanged = FALSE, fUnknownCountryCode = FALSE;
3848 tANI_U32 i;
Kiet Lamb5dffeb2013-10-14 05:37:09 +05303849 v_REGDOMAIN_t regd;
Tushnim Bhattacharyya47f9a762013-11-07 23:44:09 -08003850 tANI_BOOLEAN fCountryNotPresentInDriver = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003851
3852 // convert to UPPER here so we are assured the strings are always in upper case.
3853 for( i = 0; i < 3; i++ )
3854 {
3855 pCountryCode[ i ] = (tANI_U8)csrToUpper( pCountryCode[ i ] );
3856 }
3857
3858 // Some of the 'old' Cisco 350 series AP's advertise NA as the country code (for North America ??).
3859 // NA is not a valid country code or domain so let's allow this by changing it to the proper
3860 // country code (which is US). We've also seen some NETGEAR AP's that have "XX " as the country code
3861 // with valid 2.4 GHz US channel information. If we cannot find the country code advertised in the
3862 // 11d information element, let's default to US.
Kiet Lamb5dffeb2013-10-14 05:37:09 +05303863 if ( !HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(pMac,
3864 pCountryCode,
3865 &regd,
3866 COUNTRY_QUERY) ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003867 {
3868 // Check the enforcement first
3869 if( pMac->roam.configParam.fEnforceDefaultDomain || pMac->roam.configParam.fEnforceCountryCodeMatch )
3870 {
3871 fUnknownCountryCode = TRUE;
3872 }
3873 else
3874 {
Tushnim Bhattacharyya47f9a762013-11-07 23:44:09 -08003875 fCountryNotPresentInDriver = TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003876 }
3877 }
Tushnim Bhattacharyyab676a2e2013-10-29 17:27:43 -07003878 //right now, even if we don't find the CC in driver we set to world. Making
3879 //sure countryCode11d doesn't get updated with the invalid CC, instead
3880 //reflect the world CC
3881 else if (REGDOMAIN_WORLD == regd)
3882 {
Tushnim Bhattacharyya47f9a762013-11-07 23:44:09 -08003883 fCountryNotPresentInDriver = TRUE;
Tushnim Bhattacharyyab676a2e2013-10-29 17:27:43 -07003884 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003885
3886 // We've seen some of the AP's improperly put a 0 for the third character of the country code.
3887 // spec says valid charcters are 'O' (for outdoor), 'I' for Indoor, or ' ' (space; for either).
3888 // if we see a 0 in this third character, let's change it to a ' '.
3889 if ( 0 == pCountryCode[ 2 ] )
3890 {
3891 pCountryCode[ 2 ] = ' ';
3892 }
3893
3894 if( !fUnknownCountryCode )
3895 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05303896 fCountryStringChanged = (!vos_mem_compare(pMac->scan.countryCode11d, pCountryCode, 2));
Jeff Johnson295189b2012-06-20 16:38:30 -07003897
3898
3899 if(( 0 == pMac->scan.countryCode11d[ 0 ] && 0 == pMac->scan.countryCode11d[ 1 ] )
3900 || (fForce))
3901 {
Tushnim Bhattacharyya47f9a762013-11-07 23:44:09 -08003902 if (!fCountryNotPresentInDriver)
3903 {
3904 // this is the first .11d information
3905 vos_mem_copy(pMac->scan.countryCode11d, pCountryCode,
Kiet Lam3cac75e2013-07-12 13:56:44 +05303906 sizeof( pMac->scan.countryCode11d ));
Tushnim Bhattacharyya47f9a762013-11-07 23:44:09 -08003907
3908 }
3909 else
3910 {
3911 pMac->scan.countryCode11d[0] = '0';
3912 pMac->scan.countryCode11d[1] = '0';
3913 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003914 }
3915 }
3916
3917 return( fCountryStringChanged );
3918}
3919
3920
3921void csrSaveChannelPowerForBand( tpAniSirGlobal pMac, tANI_BOOLEAN fPopulate5GBand )
3922{
3923 tANI_U32 Index, count=0;
3924 tSirMacChanInfo *pChanInfo;
3925 tSirMacChanInfo *pChanInfoStart;
Leela V Kiran Kumar Reddy Chirala380acbb2013-02-16 15:41:27 -08003926 tANI_S32 maxChannelIndex;
3927
3928 maxChannelIndex = ( pMac->scan.base20MHzChannels.numChannels < WNI_CFG_VALID_CHANNEL_LIST_LEN ) ?
3929 pMac->scan.base20MHzChannels.numChannels : WNI_CFG_VALID_CHANNEL_LIST_LEN ;
Jeff Johnson295189b2012-06-20 16:38:30 -07003930
Kiet Lam3cac75e2013-07-12 13:56:44 +05303931 pChanInfo = vos_mem_malloc(sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN);
3932 if ( NULL != pChanInfo )
Jeff Johnson295189b2012-06-20 16:38:30 -07003933 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05303934 vos_mem_set(pChanInfo, sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003935 pChanInfoStart = pChanInfo;
Leela V Kiran Kumar Reddy Chirala380acbb2013-02-16 15:41:27 -08003936 for (Index=0; Index < maxChannelIndex; Index++)
Jeff Johnson295189b2012-06-20 16:38:30 -07003937 {
3938 if ((fPopulate5GBand && (CSR_IS_CHANNEL_5GHZ(pMac->scan.defaultPowerTable[Index].chanId))) ||
3939 (!fPopulate5GBand && (CSR_IS_CHANNEL_24GHZ(pMac->scan.defaultPowerTable[Index].chanId))) )
3940 {
Leela V Kiran Kumar Reddy Chirala380acbb2013-02-16 15:41:27 -08003941 if(count >= WNI_CFG_VALID_CHANNEL_LIST_LEN)
3942 {
3943 smsLog( pMac, LOGW, FL(" csrSaveChannelPowerForBand, count exceeded, count = %d"), count);
3944 break;
3945 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003946 pChanInfo->firstChanNum = pMac->scan.defaultPowerTable[Index].chanId;
3947 pChanInfo->numChannels = 1;
3948 pChanInfo->maxTxPower = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
3949 pChanInfo++;
3950 count++;
3951 }
3952 }
3953 if(count)
3954 {
3955 csrSaveToChannelPower2G_5G( pMac, count * sizeof(tSirMacChanInfo), pChanInfoStart );
3956 }
Kiet Lam3cac75e2013-07-12 13:56:44 +05303957 vos_mem_free(pChanInfoStart);
Jeff Johnson295189b2012-06-20 16:38:30 -07003958 }
3959}
3960
3961
3962void csrSetOppositeBandChannelInfo( tpAniSirGlobal pMac )
3963{
3964 tANI_BOOLEAN fPopulate5GBand = FALSE;
3965
3966 do
3967 {
3968 // if this is not a dual band product, then we don't need to set the opposite
3969 // band info. We only work in one band so no need to look in the other band.
3970 if ( !CSR_IS_OPEARTING_DUAL_BAND( pMac ) ) break;
3971 // if we found channel info on the 5.0 band and...
3972 if ( CSR_IS_CHANNEL_5GHZ( pMac->scan.channelOf11dInfo ) )
3973 {
3974 // and the 2.4 band is empty, then populate the 2.4 channel info
Kiet Lam3ff1c522013-10-11 03:39:41 +05303975 if ( !csrLLIsListEmpty( &pMac->scan.channelPowerInfoList24, LL_ACCESS_LOCK ) ) break;
Jeff Johnson295189b2012-06-20 16:38:30 -07003976 fPopulate5GBand = FALSE;
3977 }
3978 else
3979 {
3980 // else, we found channel info in the 2.4 GHz band. If the 5.0 band is empty
3981 // set the 5.0 band info from the 2.4 country code.
Kiet Lam3ff1c522013-10-11 03:39:41 +05303982 if ( !csrLLIsListEmpty( &pMac->scan.channelPowerInfoList5G, LL_ACCESS_LOCK ) ) break;
Jeff Johnson295189b2012-06-20 16:38:30 -07003983 fPopulate5GBand = TRUE;
3984 }
3985 csrSaveChannelPowerForBand( pMac, fPopulate5GBand );
3986
3987 } while( 0 );
3988}
3989
3990
3991tANI_BOOLEAN csrIsSupportedChannel(tpAniSirGlobal pMac, tANI_U8 channelId)
3992{
3993 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
3994 tANI_U32 i;
3995
3996 //Make sure it is a channel that is in our supported list.
3997 for ( i = 0; i < pMac->scan.baseChannels.numChannels; i++ )
3998 {
3999 if ( channelId == pMac->scan.baseChannels.channelList[i] )
4000 {
4001 fRet = eANI_BOOLEAN_TRUE;
4002 break;
4003 }
4004 }
4005
4006 //If it is configured to limit a set of the channels
4007 if( fRet && pMac->roam.configParam.fEnforce11dChannels )
4008 {
4009 fRet = eANI_BOOLEAN_FALSE;
4010 for ( i = 0; i < pMac->scan.base20MHzChannels.numChannels; i++ )
4011 {
4012 if ( channelId == pMac->scan.base20MHzChannels.channelList[i] )
4013 {
4014 fRet = eANI_BOOLEAN_TRUE;
4015 break;
4016 }
4017 }
4018 }
4019
4020 return (fRet);
4021}
4022
4023
4024
4025//bSize specify the buffer size of pChannelList
4026tANI_U8 csrGetChannelListFromChannelSet( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 bSize, tCsrChannelPowerInfo *pChannelSet )
4027{
4028 tANI_U8 i, j = 0, chnId;
4029
4030 bSize = CSR_MIN(bSize, pChannelSet->numChannels);
4031 for( i = 0; i < bSize; i++ )
4032 {
4033 chnId = (tANI_U8)(pChannelSet->firstChannel + ( i * pChannelSet->interChannelOffset ));
4034 if ( csrIsSupportedChannel( pMac, chnId ) )
4035 {
4036 pChannelList[j++] = chnId;
4037 }
4038 }
4039
4040 return (j);
4041}
4042
4043
4044
4045//bSize -- specify the buffer size of pChannelList
4046void csrConstructCurrentValidChannelList( tpAniSirGlobal pMac, tDblLinkList *pChannelSetList,
4047 tANI_U8 *pChannelList, tANI_U8 bSize, tANI_U8 *pNumChannels )
4048{
4049 tListElem *pEntry;
4050 tCsrChannelPowerInfo *pChannelSet;
4051 tANI_U8 numChannels;
4052 tANI_U8 *pChannels;
4053
4054 if( pChannelSetList && pChannelList && pNumChannels )
4055 {
4056 pChannels = pChannelList;
4057 *pNumChannels = 0;
4058 pEntry = csrLLPeekHead( pChannelSetList, LL_ACCESS_LOCK );
4059 while( pEntry )
4060 {
4061 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
4062 numChannels = csrGetChannelListFromChannelSet( pMac, pChannels, bSize, pChannelSet );
4063 pChannels += numChannels;
4064 *pNumChannels += numChannels;
4065 pEntry = csrLLNext( pChannelSetList, pEntry, LL_ACCESS_LOCK );
4066 }
4067 }
4068}
4069
4070
4071/*
4072 * 802.11D only: Gather 11d IE via beacon or Probe response and store them in pAdapter->channels11d
4073*/
4074tANI_BOOLEAN csrLearnCountryInformation( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc,
4075 tDot11fBeaconIEs *pIes, tANI_BOOLEAN fForce)
4076{
Jeff Johnson295189b2012-06-20 16:38:30 -07004077 eHalStatus status;
4078 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
4079 v_REGDOMAIN_t domainId;
4080 tDot11fBeaconIEs *pIesLocal = pIes;
4081
Jeff Johnson295189b2012-06-20 16:38:30 -07004082 if (VOS_STA_SAP_MODE == vos_get_conparam ())
4083 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07004084
4085 do
4086 {
4087 // check if .11d support is enabled
4088 if( !csrIs11dSupported( pMac ) ) break;
4089 if( !pIesLocal && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc, &pIesLocal))) )
4090 {
4091 break;
4092 }
4093 // check if country information element is present
4094 if(!pIesLocal->Country.present)
4095 {
4096 //No country info
4097 break;
4098 }
4099
4100 if( csrSave11dCountryString( pMac, pIesLocal->Country.country, fForce ) )
4101 {
4102 // country string changed, this should not happen
4103 //Need to check whether we care about this BSS' domain info
4104 //If it doesn't match of the connected profile or roaming profile, let's ignore it
4105 tANI_U32 i;
4106 tCsrRoamSession *pSession;
4107
4108 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
4109 {
4110 if( CSR_IS_SESSION_VALID( pMac, i ) )
4111 {
4112 pSession = CSR_GET_SESSION( pMac, i );
4113 if(pSession->pCurRoamProfile)
4114 {
4115 tCsrScanResultFilter filter;
4116
Kiet Lam3cac75e2013-07-12 13:56:44 +05304117 vos_mem_set(&filter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004118 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, &filter);
4119 if(HAL_STATUS_SUCCESS(status))
4120 {
4121 tANI_BOOLEAN fMatch = csrMatchBSS(pMac, pSirBssDesc, &filter, NULL, NULL, NULL, NULL);
4122 //Free the resource first
4123 csrFreeScanFilter( pMac, &filter );
4124 if(fMatch)
4125 {
Arif Hussaineb871412013-11-20 11:06:42 -08004126 smsLog(pMac, LOGW, "Matching roam profile "
4127 "BSSID " MAC_ADDRESS_STR
4128 " causing ambiguous domain info",
4129 MAC_ADDR_ARRAY(pSirBssDesc->bssId));
Jeff Johnson295189b2012-06-20 16:38:30 -07004130 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_TRUE;
4131 break;
4132 }
4133 }
4134 }
4135 else if( csrIsConnStateConnected(pMac, i))
4136 {
4137 //Reach here only when the currention is base on no profile.
4138 //User doesn't give profile and just connect to anything.
4139 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile, pSirBssDesc, pIesLocal))
4140 {
Arif Hussaineb871412013-11-20 11:06:42 -08004141 smsLog(pMac, LOGW, "Matching connect profile BSSID "
4142 MAC_ADDRESS_STR
4143 " causing ambiguous domain info",
4144 MAC_ADDR_ARRAY(pSirBssDesc->bssId));
Jeff Johnson295189b2012-06-20 16:38:30 -07004145 //Tush
4146 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_TRUE;
4147 if(csrIsBssidMatch(pMac, (tCsrBssid *)&pSirBssDesc->bssId,
4148 &pSession->connectedProfile.bssid))
4149 {
4150 //AP changed the 11d info on the fly, modify cfg
4151 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
4152 fRet = eANI_BOOLEAN_TRUE;
4153 }
4154 break;
4155 }
4156 }
4157 } //valid session
4158 } //for
4159 if ( i == CSR_ROAM_SESSION_MAX )
4160 {
4161 //Check whether we can use this country's 11d information
4162 if( !pMac->roam.configParam.fEnforceDefaultDomain )
4163 {
4164 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_TRUE;
4165 }
4166 else
4167 {
4168 VOS_ASSERT( pMac->scan.domainIdCurrent == pMac->scan.domainIdDefault );
4169 if( HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
Kiet Lamb5dffeb2013-10-14 05:37:09 +05304170 pMac, pIesLocal->Country.country, &domainId,
4171 COUNTRY_QUERY)) &&
Jeff Johnson295189b2012-06-20 16:38:30 -07004172 ( domainId == pMac->scan.domainIdCurrent ) )
4173 {
4174 //Two countries in the same domain
4175 }
4176 }
4177 }
Kiet Lamb5dffeb2013-10-14 05:37:09 +05304178#ifdef CONFIG_ENABLE_LINUX_REG
4179 csrGetRegulatoryDomainForCountry(pMac, pIesLocal->Country.country,
4180 &domainId, COUNTRY_IE);
4181#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004182 }
4183 else //Tush
4184 {
4185 pMac->scan.fCurrent11dInfoMatch = eANI_BOOLEAN_TRUE;
4186 }
4187
4188 //In case that some channels in 5GHz have the same channel number as 2.4GHz (<= 14)
4189 if(CSR_IS_CHANNEL_5GHZ(pSirBssDesc->channelId))
4190 {
4191 tANI_U8 iC;
4192 tSirMacChanInfo* pMacChnSet = (tSirMacChanInfo *)(&pIesLocal->Country.triplets[0]);
4193
4194 for(iC = 0; iC < pIesLocal->Country.num_triplets; iC++)
4195 {
4196 if(CSR_IS_CHANNEL_24GHZ(pMacChnSet[iC].firstChanNum))
4197 {
4198 pMacChnSet[iC].firstChanNum += 200; //*** Where is this 200 defined?
4199 }
4200 }
4201 }
Jeff Johnson5449b7a2013-11-22 18:39:00 -08004202 smsLog(pMac, LOG3, FL(" %d sets each one is %zu"), pIesLocal->Country.num_triplets, sizeof(tSirMacChanInfo));
Jeff Johnsone7245742012-09-05 17:12:55 -07004203
Jeff Johnson295189b2012-06-20 16:38:30 -07004204 // set the indicator of the channel where the country IE was found...
4205 pMac->scan.channelOf11dInfo = pSirBssDesc->channelId;
Kiet Lamb5dffeb2013-10-14 05:37:09 +05304206#ifndef CONFIG_ENABLE_LINUX_REG
Kiet Lam3ff1c522013-10-11 03:39:41 +05304207 status = csrGetRegulatoryDomainForCountry(pMac,
Kiet Lamb5dffeb2013-10-14 05:37:09 +05304208 pIesLocal->Country.country, &domainId, COUNTRY_IE);
Kiet Lam3ff1c522013-10-11 03:39:41 +05304209 if ( status != eHAL_STATUS_SUCCESS )
4210 {
4211 smsLog( pMac, LOGE, FL(" fail to get regId %d"), domainId );
4212 fRet = eANI_BOOLEAN_FALSE;
4213 break;
4214 }
Venkata Prathyusha Kuntupallie5a53db2013-03-15 17:45:25 -07004215 // Checking for Domain Id change
4216 if ( domainId != pMac->scan.domainIdCurrent )
4217 {
Kiet Lam3ff1c522013-10-11 03:39:41 +05304218 vos_mem_copy(pMac->scan.countryCode11d,
4219 pIesLocal->Country.country,
4220 sizeof( pMac->scan.countryCode11d ) );
4221 /* Set Current Country code and Current Regulatory domain */
4222 status = csrSetRegulatoryDomain(pMac, domainId, NULL);
4223 if (eHAL_STATUS_SUCCESS != status)
4224 {
4225 smsLog(pMac, LOGE, "Set Reg Domain Fail %d", status);
4226 fRet = eANI_BOOLEAN_FALSE;
4227 return fRet;
4228 }
4229 //csrSetRegulatoryDomain will fail if the country doesn't fit our domain criteria.
4230 vos_mem_copy(pMac->scan.countryCodeCurrent,
4231 pIesLocal->Country.country, WNI_CFG_COUNTRY_CODE_LEN);
4232 //Simply set it to cfg.
Madan Mohan Koyyalamudi191b1002013-09-10 15:45:24 +05304233 csrSetCfgCountryCode(pMac, pIesLocal->Country.country);
Kiet Lam3ff1c522013-10-11 03:39:41 +05304234
4235 /* overwrite the defualt country code */
4236 vos_mem_copy(pMac->scan.countryCodeDefault,
4237 pMac->scan.countryCodeCurrent,
4238 WNI_CFG_COUNTRY_CODE_LEN);
4239 /* Set Current RegDomain */
Kiet Lamec0e7f62013-11-07 18:39:01 +05304240 status = WDA_SetRegDomain(pMac, domainId, eSIR_TRUE);
Kiet Lam3ff1c522013-10-11 03:39:41 +05304241 if ( status != eHAL_STATUS_SUCCESS )
4242 {
4243 smsLog( pMac, LOGE, FL(" fail to Set regId %d"), domainId );
4244 fRet = eANI_BOOLEAN_FALSE;
4245 return fRet;
4246 }
4247 /* set to default domain ID */
Madan Mohan Koyyalamudi191b1002013-09-10 15:45:24 +05304248 pMac->scan.domainIdCurrent = domainId;
Kiet Lam3ff1c522013-10-11 03:39:41 +05304249 /* get the channels based on new cc */
4250 status = csrInitGetChannels( pMac );
Jeff Johnson295189b2012-06-20 16:38:30 -07004251
Kiet Lam3ff1c522013-10-11 03:39:41 +05304252 if ( status != eHAL_STATUS_SUCCESS )
4253 {
4254 smsLog( pMac, LOGE, FL(" fail to get Channels "));
4255 fRet = eANI_BOOLEAN_FALSE;
4256 return fRet;
4257 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004258
Kiet Lam3ff1c522013-10-11 03:39:41 +05304259 /* reset info based on new cc, and we are done */
4260 csrResetCountryInformation(pMac, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
Agarwal Ashish5e90a3d2014-01-29 19:40:30 +05304261 /* Regulatory Domain Changed, Purge Only scan result
4262 * which does not have channel number belong to 11d
4263 * channel list
4264 */
4265 csrScanFilter11dResult(pMac);
Kiet Lam3ff1c522013-10-11 03:39:41 +05304266 }
Kiet Lamb5dffeb2013-10-14 05:37:09 +05304267#endif
4268 fRet = eANI_BOOLEAN_TRUE;
4269
Jeff Johnson295189b2012-06-20 16:38:30 -07004270 } while( 0 );
4271
4272 if( !pIes && pIesLocal )
4273 {
4274 //locally allocated
Kiet Lam3cac75e2013-07-12 13:56:44 +05304275 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07004276 }
4277
4278 return( fRet );
4279}
4280
4281
Varun Reddy Yeturu08614702013-04-15 21:58:13 -07004282static void csrSaveScanResults( tpAniSirGlobal pMac, tANI_U8 reason )
Jeff Johnson295189b2012-06-20 16:38:30 -07004283{
4284 // initialize this to FALSE. profMoveInterimScanResultsToMainList() routine
4285 // will set this to the channel where an .11d beacon is seen
4286 pMac->scan.channelOf11dInfo = 0;
4287 // if we get any ambiguous .11d information then this will be set to TRUE
4288 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
4289 //Tush
4290 // if we get any ambiguous .11d information, then this will be set to TRUE
4291 // only if the applied 11d info could be found in one of the scan results
4292 pMac->scan.fCurrent11dInfoMatch = eANI_BOOLEAN_FALSE;
4293 // move the scan results from interim list to the main scan list
Varun Reddy Yeturu08614702013-04-15 21:58:13 -07004294 csrMoveTempScanResultsToMainList( pMac, reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07004295}
4296
4297
4298void csrReinitScanCmd(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4299{
4300 switch (pCommand->u.scanCmd.reason)
4301 {
4302 case eCsrScanSetBGScanParam:
4303 case eCsrScanAbortBgScan:
4304 if(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList)
4305 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05304306 vos_mem_free(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList);
Jeff Johnson295189b2012-06-20 16:38:30 -07004307 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
4308 }
4309 break;
4310 case eCsrScanBGScanAbort:
4311 case eCsrScanBGScanEnable:
4312 case eCsrScanGetScanChnInfo:
4313 break;
4314 case eCsrScanAbortNormalScan:
4315 default:
4316 csrScanFreeRequest(pMac, &pCommand->u.scanCmd.u.scanRequest);
4317 break;
4318 }
4319 if(pCommand->u.scanCmd.pToRoamProfile)
4320 {
4321 csrReleaseProfile(pMac, pCommand->u.scanCmd.pToRoamProfile);
Kiet Lam3cac75e2013-07-12 13:56:44 +05304322 vos_mem_free(pCommand->u.scanCmd.pToRoamProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07004323 }
Kiet Lam3cac75e2013-07-12 13:56:44 +05304324 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004325}
4326
4327
4328tANI_BOOLEAN csrGetRemainingChannelsFor11dScan( tpAniSirGlobal pMac, tANI_U8 *pChannels, tANI_U8 *pcChannels )
4329{
4330 tANI_U32 index11dChannels, index;
4331 tANI_U32 indexCurrentChannels;
4332 tANI_BOOLEAN fChannelAlreadyScanned;
4333 tANI_U32 len = sizeof(pMac->roam.validChannelList);
4334
4335 *pcChannels = 0;
4336 if ( CSR_IS_11D_INFO_FOUND(pMac) && csrRoamIsChannelValid(pMac, pMac->scan.channelOf11dInfo) )
4337 {
4338 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
4339 {
4340 //Find the channel index where we found the 11d info
4341 for(index = 0; index < len; index++)
4342 {
4343 if(pMac->scan.channelOf11dInfo == pMac->roam.validChannelList[index])
4344 break;
4345 }
4346 //check whether we found the channel index
4347 if(index < len)
4348 {
4349 // Now, look through the 11d channel list and create a list of all channels in the 11d list that are
4350 // NOT in the current channel list. This gives us a list of the new channels that have not been
4351 // scanned. We'll scan this new list so we have a complete set of scan results on all of the domain channels
4352 // initially.
4353 for ( index11dChannels = 0; index11dChannels < pMac->scan.channels11d.numChannels; index11dChannels++ )
4354 {
4355 fChannelAlreadyScanned = eANI_BOOLEAN_FALSE;
4356
4357 for( indexCurrentChannels = 0; indexCurrentChannels < index; indexCurrentChannels++ )
4358 {
4359 if ( pMac->roam.validChannelList[ indexCurrentChannels ] == pMac->scan.channels11d.channelList[ index11dChannels ] )
4360 {
4361 fChannelAlreadyScanned = eANI_BOOLEAN_TRUE;
4362 break;
4363 }
4364 }
4365
4366 if ( !fChannelAlreadyScanned )
4367 {
4368 pChannels[ *pcChannels ] = pMac->scan.channels11d.channelList[ index11dChannels ];
4369 ( *pcChannels )++;
4370 }
4371 }
4372 }
4373 }//GetCFG
4374 }
4375 return( *pcChannels );
4376}
4377
4378
4379eCsrScanCompleteNextCommand csrScanGetNextCommandState( tpAniSirGlobal pMac, tSmeCmd *pCommand, tANI_BOOLEAN fSuccess )
4380{
4381 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
4382
4383 switch( pCommand->u.scanCmd.reason )
4384 {
4385 case eCsrScan11d1:
4386 NextCommand = (fSuccess) ? eCsrNext11dScan1Success : eCsrNext11dScan1Failure;
4387 break;
4388 case eCsrScan11d2:
4389 NextCommand = (fSuccess) ? eCsrNext11dScan2Success : eCsrNext11dScan2Failure;
4390 break;
4391 case eCsrScan11dDone:
4392 NextCommand = eCsrNext11dScanComplete;
4393 break;
4394 case eCsrScanLostLink1:
4395 NextCommand = (fSuccess) ? eCsrNextLostLinkScan1Success : eCsrNextLostLinkScan1Failed;
4396 break;
4397 case eCsrScanLostLink2:
4398 NextCommand = (fSuccess) ? eCsrNextLostLinkScan2Success : eCsrNextLostLinkScan2Failed;
4399 break;
4400 case eCsrScanLostLink3:
4401 NextCommand = (fSuccess) ? eCsrNextLostLinkScan3Success : eCsrNextLostLinkScan3Failed;
4402 break;
4403 case eCsrScanForSsid:
4404 NextCommand = (fSuccess) ? eCsrNexteScanForSsidSuccess : eCsrNexteScanForSsidFailure;
4405 break;
4406 case eCsrScanForCapsChange:
4407 NextCommand = eCsrNextCapChangeScanComplete; //don't care success or not
4408 break;
4409 case eCsrScanIdleScan:
4410 NextCommand = eCsrNextIdleScanComplete;
4411 break;
4412 default:
4413 NextCommand = eCsrNextScanNothing;
4414 break;
4415 }
4416 return( NextCommand );
4417}
4418
4419
4420//Return whether the pCommand is finished.
4421tANI_BOOLEAN csrHandleScan11d1Failure(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4422{
4423 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
4424
4425 //Apply back the default setting and passively scan one more time.
Gopichand Nakkala277e02b2012-12-21 08:03:42 -08004426 csrResetCountryInformation(pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07004427 pCommand->u.scanCmd.reason = eCsrScan11d2;
4428 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
4429 {
4430 fRet = eANI_BOOLEAN_FALSE;
4431 }
4432
4433 return (fRet);
4434}
4435
4436
4437tANI_BOOLEAN csrHandleScan11dSuccess(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4438{
4439 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
4440 tANI_U8 *pChannels;
4441 tANI_U8 cChannels;
4442
Kiet Lam3cac75e2013-07-12 13:56:44 +05304443 pChannels = vos_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
4444 if ( NULL != pChannels )
Jeff Johnson295189b2012-06-20 16:38:30 -07004445 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05304446 vos_mem_set(pChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004447 if ( csrGetRemainingChannelsFor11dScan( pMac, pChannels, &cChannels ) )
4448 {
4449 pCommand->u.scanCmd.reason = eCsrScan11dDone;
4450 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
4451 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05304452 vos_mem_free(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
James Zmudaac3ad1b2013-04-18 18:20:54 -07004453 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004454 }
Kiet Lam3cac75e2013-07-12 13:56:44 +05304455 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(cChannels);
4456 if ( NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07004457 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05304458 vos_mem_copy(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
4459 pChannels, cChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07004460 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = cChannels;
4461 pCommand->u.scanCmd.u.scanRequest.requestType = eCSR_SCAN_REQUEST_FULL_SCAN;
4462 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
4463 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
4464 {
4465 //Reuse the same command buffer
4466 fRet = eANI_BOOLEAN_FALSE;
4467 }
4468 }
4469 }
Kiet Lam3cac75e2013-07-12 13:56:44 +05304470 vos_mem_free(pChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07004471 }
4472
4473 return (fRet);
4474}
4475
4476//Return whether the command should be removed
4477tANI_BOOLEAN csrScanComplete( tpAniSirGlobal pMac, tSirSmeScanRsp *pScanRsp )
4478{
4479 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
4480 tListElem *pEntry;
4481 tSmeCmd *pCommand;
4482 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
4483 tANI_BOOLEAN fSuccess;
4484
Madan Mohan Koyyalamudi8f3583f2013-06-19 16:34:44 +05304485 if (pMac->fScanOffload)
4486 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
4487 else
4488 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07004489
4490 if ( pEntry )
4491 {
4492 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
4493
4494 // If the head of the queue is Active and it is a SCAN command, remove
4495 // and put this on the Free queue.
4496 if ( eSmeCommandScan == pCommand->command )
4497 {
4498 tANI_U32 sessionId = pCommand->sessionId;
4499
4500 if(eSIR_SME_SUCCESS != pScanRsp->statusCode)
4501 {
4502 fSuccess = eANI_BOOLEAN_FALSE;
4503 }
4504 else
4505 {
4506 //pMac->scan.tempScanResults is not empty meaning the scan found something
4507 //This check only valid here because csrSaveScanresults is not yet called
4508 fSuccess = (!csrLLIsListEmpty(&pMac->scan.tempScanResults, LL_ACCESS_LOCK));
4509 }
Varun Reddy Yeturu08614702013-04-15 21:58:13 -07004510 csrSaveScanResults(pMac, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07004511
4512#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4513 {
4514 vos_log_scan_pkt_type *pScanLog = NULL;
4515 tScanResultHandle hScanResult;
4516 tCsrScanResultInfo *pScanResult;
4517 tDot11fBeaconIEs *pIes;
4518 int n = 0, c = 0;
4519
4520 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
4521 if(pScanLog)
4522 {
4523 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
4524 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
4525 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
4526 {
4527 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_RSP;
4528 }
4529 else
4530 {
4531 if( eSIR_PASSIVE_SCAN != pMac->scan.curScanType )
4532 {
4533 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_RSP;
4534 }
4535 else
4536 {
4537 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_RSP;
4538 }
4539 }
4540 if(eSIR_SME_SUCCESS == pScanRsp->statusCode)
4541 {
4542 if(HAL_STATUS_SUCCESS(csrScanGetResult(pMac, NULL, &hScanResult)))
4543 {
4544 while(((pScanResult = csrScanResultGetNext(pMac, hScanResult)) != NULL))
4545 {
4546 if( n < VOS_LOG_MAX_NUM_BSSID )
4547 {
4548 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pScanResult->BssDescriptor, &pIes)))
4549 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08004550 smsLog(pMac, LOGE, FL(" fail to parse IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07004551 break;
4552 }
Kiet Lam3cac75e2013-07-12 13:56:44 +05304553 vos_mem_copy(pScanLog->bssid[n],
4554 pScanResult->BssDescriptor.bssId, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07004555 if(pIes && pIes->SSID.present && VOS_LOG_MAX_SSID_SIZE >= pIes->SSID.num_ssid)
4556 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05304557 vos_mem_copy(pScanLog->ssid[n],
4558 pIes->SSID.ssid, pIes->SSID.num_ssid);
Jeff Johnson295189b2012-06-20 16:38:30 -07004559 }
Kiet Lam3cac75e2013-07-12 13:56:44 +05304560 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07004561 n++;
4562 }
4563 c++;
4564 }
4565 pScanLog->numSsid = (v_U8_t)n;
4566 pScanLog->totalSsid = (v_U8_t)c;
4567 csrScanResultPurge(pMac, hScanResult);
4568 }
4569 }
4570 else
4571 {
4572 pScanLog->status = WLAN_SCAN_STATUS_FAILURE;
4573 }
4574 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
4575 }
4576 }
4577#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4578
4579 NextCommand = csrScanGetNextCommandState(pMac, pCommand, fSuccess);
4580 //We reuse the command here instead reissue a new command
4581 switch(NextCommand)
4582 {
4583 case eCsrNext11dScan1Success:
4584 case eCsrNext11dScan2Success:
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08004585 smsLog( pMac, LOG2, FL("11dScan1/3 produced results. Reissue Active scan..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004586 // if we found country information, no need to continue scanning further, bail out
4587 fRemoveCommand = eANI_BOOLEAN_TRUE;
4588 NextCommand = eCsrNext11dScanComplete;
4589 break;
4590 case eCsrNext11dScan1Failure:
4591 //We are not done yet. 11d scan fail once. We will try to reset anything and do it over again
4592 //The only meaningful thing for this retry is that we cannot find 11d information after a reset so
4593 //we clear the "old" 11d info and give it once more chance
4594 fRemoveCommand = csrHandleScan11d1Failure(pMac, pCommand);
4595 if(fRemoveCommand)
4596 {
4597 NextCommand = eCsrNext11dScanComplete;
4598 }
4599 break;
4600 case eCsrNextLostLinkScan1Success:
4601 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink1)))
4602 {
4603 csrScanHandleFailedLostlink1(pMac, sessionId);
4604 }
4605 break;
4606 case eCsrNextLostLinkScan2Success:
4607 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink2)))
4608 {
4609 csrScanHandleFailedLostlink2(pMac, sessionId);
4610 }
4611 break;
4612 case eCsrNextLostLinkScan3Success:
4613 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink3)))
4614 {
4615 csrScanHandleFailedLostlink3(pMac, sessionId);
4616 }
4617 break;
4618 case eCsrNextLostLinkScan1Failed:
4619 csrScanHandleFailedLostlink1(pMac, sessionId);
4620 break;
4621 case eCsrNextLostLinkScan2Failed:
4622 csrScanHandleFailedLostlink2(pMac, sessionId);
4623 break;
4624 case eCsrNextLostLinkScan3Failed:
4625 csrScanHandleFailedLostlink3(pMac, sessionId);
4626 break;
4627 case eCsrNexteScanForSsidSuccess:
4628 csrScanHandleSearchForSSID(pMac, pCommand);
4629 break;
4630 case eCsrNexteScanForSsidFailure:
4631 csrScanHandleSearchForSSIDFailure(pMac, pCommand);
4632 break;
4633 case eCsrNextIdleScanComplete:
4634 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
4635 break;
4636 case eCsrNextCapChangeScanComplete:
4637 csrScanHandleCapChangeScanComplete(pMac, sessionId);
4638 break;
4639 default:
4640
4641 break;
4642 }
4643 }
4644 else
4645 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08004646 smsLog( pMac, LOGW, FL("Scan Completion called but SCAN command is not ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004647 fRemoveCommand = eANI_BOOLEAN_FALSE;
4648 }
4649 }
4650 else
4651 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08004652 smsLog( pMac, LOGW, FL("Scan Completion called but NO commands are ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004653 fRemoveCommand = eANI_BOOLEAN_FALSE;
4654 }
4655
4656 return( fRemoveCommand );
4657}
4658
4659
4660
4661static void csrScanRemoveDupBssDescriptionFromInterimList( tpAniSirGlobal pMac,
4662 tSirBssDescription *pSirBssDescr,
4663 tDot11fBeaconIEs *pIes)
4664{
4665 tListElem *pEntry;
4666 tCsrScanResult *pCsrBssDescription;
4667
4668 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
4669 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
4670 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
4671 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
4672 while( pEntry )
4673 {
4674 pCsrBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
4675
4676 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
4677 // matches
4678
4679 if ( csrIsDuplicateBssDescription( pMac, &pCsrBssDescription->Result.BssDescriptor,
Tushnim Bhattacharyya4207db02013-06-26 23:23:18 -07004680 pSirBssDescr, pIes, FALSE ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07004681 {
4682 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
4683 ((tANI_S32)pCsrBssDescription->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
4684
4685 // Remove the 'old' entry from the list....
4686 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK ) )
4687 {
4688 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pCsrBssDescription->Result.BssDescriptor);
4689 // we need to free the memory associated with this node
4690 csrFreeScanResultEntry( pMac, pCsrBssDescription );
4691 }
4692
4693 // If we found a match, we can stop looking through the list.
4694 break;
4695 }
4696
4697 pEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK );
4698 }
4699}
4700
4701
4702
4703//Caller allocated memory pfNewBssForConn to return whether new candidate for
4704//current connection is found. Cannot be NULL
4705tCsrScanResult *csrScanSaveBssDescriptionToInterimList( tpAniSirGlobal pMac,
4706 tSirBssDescription *pBSSDescription,
4707 tDot11fBeaconIEs *pIes)
4708{
4709 tCsrScanResult *pCsrBssDescription = NULL;
4710 tANI_U32 cbBSSDesc;
4711 tANI_U32 cbAllocated;
Jeff Johnson295189b2012-06-20 16:38:30 -07004712
4713 // figure out how big the BSS description is (the BSSDesc->length does NOT
4714 // include the size of the length field itself).
4715 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
4716
4717 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
4718
Kiet Lam3cac75e2013-07-12 13:56:44 +05304719 pCsrBssDescription = vos_mem_malloc(cbAllocated);
4720 if ( NULL != pCsrBssDescription )
Jeff Johnson295189b2012-06-20 16:38:30 -07004721 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05304722 vos_mem_set(pCsrBssDescription, cbAllocated, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004723 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Kiet Lam3cac75e2013-07-12 13:56:44 +05304724 vos_mem_copy(&pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc );
Jeff Johnson295189b2012-06-20 16:38:30 -07004725 //Save SSID separately for later use
4726 if( pIes->SSID.present && !csrIsNULLSSID(pIes->SSID.ssid, pIes->SSID.num_ssid) )
4727 {
4728 //SSID not hidden
Madan Mohan Koyyalamudi4e31b132012-11-02 13:13:52 -07004729 tANI_U32 len = pIes->SSID.num_ssid;
Jeff Johnson295189b2012-06-20 16:38:30 -07004730 if (len > SIR_MAC_MAX_SSID_LENGTH)
4731 {
4732 // truncate to fit in our struct
4733 len = SIR_MAC_MAX_SSID_LENGTH;
4734 }
4735 pCsrBssDescription->Result.ssId.length = len;
4736 pCsrBssDescription->Result.timer = vos_timer_get_system_time();
Kiet Lam3cac75e2013-07-12 13:56:44 +05304737 vos_mem_copy(pCsrBssDescription->Result.ssId.ssId, pIes->SSID.ssid, len);
Jeff Johnson295189b2012-06-20 16:38:30 -07004738 }
4739 csrLLInsertTail( &pMac->scan.tempScanResults, &pCsrBssDescription->Link, LL_ACCESS_LOCK );
4740 }
4741
4742 return( pCsrBssDescription );
4743}
4744
4745
4746
4747
4748tANI_BOOLEAN csrIsDuplicateBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc1,
Tushnim Bhattacharyya4207db02013-06-26 23:23:18 -07004749 tSirBssDescription *pSirBssDesc2, tDot11fBeaconIEs *pIes2, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07004750{
4751 tANI_BOOLEAN fMatch = FALSE;
4752 tSirMacCapabilityInfo *pCap1, *pCap2;
4753 tDot11fBeaconIEs *pIes1 = NULL;
Jeff Johnsone7245742012-09-05 17:12:55 -07004754 tDot11fBeaconIEs *pIesTemp = pIes2;
Jeff Johnson295189b2012-06-20 16:38:30 -07004755
4756 pCap1 = (tSirMacCapabilityInfo *)&pSirBssDesc1->capabilityInfo;
4757 pCap2 = (tSirMacCapabilityInfo *)&pSirBssDesc2->capabilityInfo;
4758 if(pCap1->ess == pCap2->ess)
4759 {
4760 if (pCap1->ess &&
Jeff Johnsone7245742012-09-05 17:12:55 -07004761 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId)&&
Tushnim Bhattacharyya4207db02013-06-26 23:23:18 -07004762 (fForced || (pSirBssDesc1->channelId == pSirBssDesc2->channelId)))
Jeff Johnson295189b2012-06-20 16:38:30 -07004763 {
4764 fMatch = TRUE;
Jeff Johnsone7245742012-09-05 17:12:55 -07004765 // Check for SSID match, if exists
4766 do
4767 {
4768 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
4769 {
4770 break;
4771 }
4772 if( NULL == pIesTemp )
4773 {
4774 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
4775 {
4776 break;
4777 }
4778 }
4779 if(pIes1->SSID.present && pIesTemp->SSID.present)
4780 {
4781 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
4782 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
4783 }
4784 }while(0);
4785
Jeff Johnson295189b2012-06-20 16:38:30 -07004786 }
4787 else if (pCap1->ibss && (pSirBssDesc1->channelId == pSirBssDesc2->channelId))
4788 {
Jeff Johnson295189b2012-06-20 16:38:30 -07004789
4790 do
4791 {
4792 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
4793 {
4794 break;
4795 }
4796 if( NULL == pIesTemp )
4797 {
4798 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
4799 {
4800 break;
4801 }
4802 }
4803 //Same channel cannot have same SSID for different IBSS
4804 if(pIes1->SSID.present && pIesTemp->SSID.present)
4805 {
4806 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
4807 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
4808 }
4809 }while(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004810 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004811 /* In case of P2P devices, ess and ibss will be set to zero */
4812 else if (!pCap1->ess &&
4813 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId))
4814 {
4815 fMatch = TRUE;
4816 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004817 }
4818
4819 if(pIes1)
4820 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05304821 vos_mem_free(pIes1);
Jeff Johnson295189b2012-06-20 16:38:30 -07004822 }
Jeff Johnsone7245742012-09-05 17:12:55 -07004823
4824 if( (NULL == pIes2) && pIesTemp )
4825 {
4826 //locally allocated
Kiet Lam3cac75e2013-07-12 13:56:44 +05304827 vos_mem_free(pIesTemp);
Jeff Johnsone7245742012-09-05 17:12:55 -07004828 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004829
4830 return( fMatch );
4831}
4832
4833
4834tANI_BOOLEAN csrIsNetworkTypeEqual( tSirBssDescription *pSirBssDesc1, tSirBssDescription *pSirBssDesc2 )
4835{
4836 return( pSirBssDesc1->nwType == pSirBssDesc2->nwType );
4837}
4838
4839
4840//to check whether the BSS matches the dot11Mode
4841static tANI_BOOLEAN csrScanIsBssAllowed(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
4842 tDot11fBeaconIEs *pIes)
4843{
4844 tANI_BOOLEAN fAllowed = eANI_BOOLEAN_FALSE;
4845 eCsrPhyMode phyMode;
4846
4847 if(HAL_STATUS_SUCCESS(csrGetPhyModeFromBss(pMac, pBssDesc, &phyMode, pIes)))
4848 {
4849 switch(pMac->roam.configParam.phyMode)
4850 {
4851 case eCSR_DOT11_MODE_11b:
4852 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
4853 break;
4854 case eCSR_DOT11_MODE_11g:
4855 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
4856 break;
4857 case eCSR_DOT11_MODE_11g_ONLY:
4858 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11g == phyMode);
4859 break;
4860 case eCSR_DOT11_MODE_11a:
4861 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11b != phyMode) && (eCSR_DOT11_MODE_11g != phyMode));
4862 break;
4863 case eCSR_DOT11_MODE_11n_ONLY:
4864 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11n == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
4865 break;
Jeff Johnsone7245742012-09-05 17:12:55 -07004866
4867#ifdef WLAN_FEATURE_11AC
4868 case eCSR_DOT11_MODE_11ac_ONLY:
4869 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11ac == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
4870 break;
4871#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004872 case eCSR_DOT11_MODE_11b_ONLY:
4873 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11b == phyMode);
4874 break;
4875 case eCSR_DOT11_MODE_11a_ONLY:
4876 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a == phyMode);
4877 break;
4878 case eCSR_DOT11_MODE_11n:
Jeff Johnsone7245742012-09-05 17:12:55 -07004879#ifdef WLAN_FEATURE_11AC
4880 case eCSR_DOT11_MODE_11ac:
4881#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004882 case eCSR_DOT11_MODE_TAURUS:
4883 default:
4884 fAllowed = eANI_BOOLEAN_TRUE;
4885 break;
4886 }
4887 }
4888
4889 return (fAllowed);
4890}
4891
4892
4893
4894//Return pIes to caller for future use when returning TRUE.
4895static tANI_BOOLEAN csrScanValidateScanResult( tpAniSirGlobal pMac, tANI_U8 *pChannels,
4896 tANI_U8 numChn, tSirBssDescription *pBssDesc,
4897 tDot11fBeaconIEs **ppIes )
4898{
4899 tANI_BOOLEAN fValidChannel = FALSE;
4900 tDot11fBeaconIEs *pIes = NULL;
4901 tANI_U8 index;
4902
4903 for( index = 0; index < numChn; index++ )
4904 {
4905 // This check relies on the fact that a single BSS description is returned in each
4906 // ScanRsp call, which is the way LIM implemented the scan req/rsp funtions. We changed
4907 // to this model when we ran with a large number of APs. If this were to change, then
4908 // this check would have to mess with removing the bssDescription from somewhere in an
4909 // arbitrary index in the bssDescription array.
4910 if ( pChannels[ index ] == pBssDesc->channelId )
4911 {
4912 fValidChannel = TRUE;
4913 break;
4914 }
4915 }
4916 *ppIes = NULL;
4917 if(fValidChannel)
4918 {
4919 if( HAL_STATUS_SUCCESS( csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIes) ) )
4920 {
4921 fValidChannel = csrScanIsBssAllowed(pMac, pBssDesc, pIes);
4922 if( fValidChannel )
4923 {
4924 *ppIes = pIes;
4925 }
4926 else
4927 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05304928 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07004929 }
4930 }
4931 else
4932 {
4933 fValidChannel = FALSE;
4934 }
4935 }
4936
4937 return( fValidChannel );
4938}
4939
4940
4941//Return whether last scan result is received
4942static tANI_BOOLEAN csrScanProcessScanResults( tpAniSirGlobal pMac, tSmeCmd *pCommand,
4943 tSirSmeScanRsp *pScanRsp, tANI_BOOLEAN *pfRemoveCommand )
4944{
4945 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE, fRemoveCommand = eANI_BOOLEAN_FALSE;
4946 tDot11fBeaconIEs *pIes = NULL;
4947 tANI_U32 cbParsed;
4948 tSirBssDescription *pSirBssDescription;
4949 tANI_U32 cbBssDesc;
4950 tANI_U32 cbScanResult = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription )
4951 + sizeof(tSirBssDescription); //We need at least one CB
4952
4953 // don't consider the scan rsp to be valid if the status code is Scan Failure. Scan Failure
4954 // is returned when the scan could not find anything. so if we get scan failure return that
4955 // the scan response is invalid. Also check the lenght in the scan result for valid scan
4956 // BssDescriptions....
4957 do
4958 {
4959 if ( ( cbScanResult <= pScanRsp->length ) &&
4960 (( eSIR_SME_SUCCESS == pScanRsp->statusCode ) ||
4961 ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW == pScanRsp->statusCode ) ) )
4962 {
4963 tANI_U8 *pChannelList = NULL;
4964 tANI_U8 cChannels = 0;
4965
4966 //Different scan type can reach this point, we need to distinguish it
Varun Reddy Yeturu08614702013-04-15 21:58:13 -07004967#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
4968 if( eCsrScanGetLfrResult == pCommand->u.scanCmd.reason )
4969 {
4970 pChannelList = NULL;
4971 cChannels = 0;
4972 }
4973 else
4974#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004975 if( eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason )
4976 {
4977 //eCsrScanSetBGScanParam uses different structure
4978 tCsrBGScanRequest *pBgScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
4979
4980 cChannels = pBgScanReq->ChannelInfo.numOfChannels;
4981 pChannelList = pBgScanReq->ChannelInfo.ChannelList;
4982 }
4983 else
4984 {
4985 //the rest use generic scan request
4986 cChannels = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
4987 pChannelList = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
4988 }
4989
4990 // if the scan result is not on one of the channels in the Valid channel list, then it
4991 // must have come from an AP on an overlapping channel (in the 2.4GHz band). In this case,
4992 // let's drop the scan result.
4993 //
4994 // The other situation is where the scan request is for a scan on a particular channel set
4995 // and the scan result is from a
4996
4997 // if the NumChannels is 0, then we are supposed to be scanning all channels. Use the full channel
4998 // list as the 'valid' channel list. Otherwise, use the specific channel list in the scan parms
4999 // as the valid channels.
5000 if ( 0 == cChannels )
5001 {
5002 tANI_U32 len = sizeof(pMac->roam.validChannelList);
5003
5004 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
5005 {
5006 pChannelList = pMac->roam.validChannelList;
5007 cChannels = (tANI_U8)len;
5008 }
5009 else
5010 {
5011 //Cannot continue
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08005012 smsLog( pMac, LOGE, "CSR: Processing internal SCAN results...csrGetCfgValidChannels failed" );
Jeff Johnson295189b2012-06-20 16:38:30 -07005013 break;
5014 }
5015 }
5016
5017 smsLog( pMac, LOG2, "CSR: Processing internal SCAN results..." );
5018 cbParsed = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription );
5019 pSirBssDescription = pScanRsp->bssDescription;
5020 while( cbParsed < pScanRsp->length )
5021 {
5022 if ( csrScanValidateScanResult( pMac, pChannelList, cChannels, pSirBssDescription, &pIes ) )
5023 {
5024 csrScanRemoveDupBssDescriptionFromInterimList(pMac, pSirBssDescription, pIes);
5025 csrScanSaveBssDescriptionToInterimList( pMac, pSirBssDescription, pIes );
5026 if( eSIR_PASSIVE_SCAN == pMac->scan.curScanType )
5027 {
5028 if( csrIs11dSupported( pMac) )
5029 {
5030 //Check whether the BSS is acceptable base on 11d info and our configs.
5031 if( csrMatchCountryCode( pMac, NULL, pIes ) )
5032 {
5033 //Double check whether the channel is acceptable by us.
5034 if( csrIsSupportedChannel( pMac, pSirBssDescription->channelId ) )
5035 {
5036 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
5037 }
5038 }
5039 }
5040 else
5041 {
5042 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
5043 }
5044 }
5045 //Free the resource
Kiet Lam3cac75e2013-07-12 13:56:44 +05305046 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07005047 }
5048 // skip over the BSS description to the next one...
5049 cbBssDesc = pSirBssDescription->length + sizeof( pSirBssDescription->length );
5050
5051 cbParsed += cbBssDesc;
5052 pSirBssDescription = (tSirBssDescription *)((tANI_U8 *)pSirBssDescription + cbBssDesc );
5053
5054 } //while
5055 }
5056 else
5057 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08005058 smsLog( pMac, LOGW, " Scanrsp fail (0x%08X), length = %d (expected %d)",
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08005059 pScanRsp->statusCode, pScanRsp->length, cbScanResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07005060 //HO bg scan/probe failed no need to try autonomously
5061 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
5062 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
Varun Reddy Yeturu08614702013-04-15 21:58:13 -07005063#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5064 eCsrScanGetLfrResult == pCommand->u.scanCmd.reason ||
5065#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005066 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
5067 {
5068 fRemoveCommand = eANI_BOOLEAN_TRUE;
5069 }
5070 }
5071 }while(0);
5072 if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
5073 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08005074 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 -07005075 fRemoveCommand = csrScanComplete( pMac, pScanRsp );
5076 fRet = eANI_BOOLEAN_TRUE;
5077 }//if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
5078 if(pfRemoveCommand)
5079 {
5080 *pfRemoveCommand = fRemoveCommand;
5081 }
5082
5083#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudi8f3583f2013-06-19 16:34:44 +05305084 if (pMac->fScanOffload)
5085 return fRet;
5086
Jeff Johnson295189b2012-06-20 16:38:30 -07005087 if (!csrLLIsListEmpty( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK ))
5088 {
Madan Mohan Koyyalamudie8d64402012-12-04 16:49:55 -08005089 /* Pending scan commands in the list because the previous scan command
5090 * was split into a scan command on one channel + a scan command for all
5091 * remaining channels.
5092 *
5093 * Start timer to trigger processing of the next scan command.
Madan Mohan Koyyalamudi91482b82012-12-27 17:28:14 -08005094 * NOTE for LFR:
Madan Mohan Koyyalamudi8f3583f2013-06-19 16:34:44 +05305095 * Do not split scans if no concurrent infra connections are
Madan Mohan Koyyalamudi91482b82012-12-27 17:28:14 -08005096 * active and if the scan is a BG scan triggered by LFR (OR)
5097 * any scan if LFR is in the middle of a BG scan. Splitting
5098 * the scan is delaying the time it takes for LFR to find
5099 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudie8d64402012-12-04 16:49:55 -08005100 */
Madan Mohan Koyyalamudi8f3583f2013-06-19 16:34:44 +05305101 if ( (csrIsStaSessionConnected(pMac) &&
Madan Mohan Koyyalamudi91482b82012-12-27 17:28:14 -08005102#ifdef FEATURE_WLAN_LFR
5103 (csrIsConcurrentInfraConnected(pMac) ||
5104 ((pCommand->u.scanCmd.reason != eCsrScanBgScan) &&
Madan Mohan Koyyalamudi8f3583f2013-06-19 16:34:44 +05305105 (pMac->roam.neighborRoamInfo.neighborRoamState !=
Madan Mohan Koyyalamudi91482b82012-12-27 17:28:14 -08005106 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
5107#endif
5108 (pCommand->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudi8f3583f2013-06-19 16:34:44 +05305109 (csrIsP2pSessionConnected(pMac)) )
Madan Mohan Koyyalamudie8d64402012-12-04 16:49:55 -08005110 {
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005111 /* if active connected sessions present then continue to split scan
5112 * with specified interval between consecutive scans */
5113 csrSetDefaultScanTiming(pMac, pCommand->u.scanCmd.u.scanRequest.scanType, &(pCommand->u.scanCmd.u.scanRequest));
Madan Mohan Koyyalamudi0dea29e2013-07-11 12:01:37 +05305114 vos_timer_start(&pMac->scan.hTimerStaApConcTimer,
5115 pCommand->u.scanCmd.u.scanRequest.restTime);
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005116 } else {
5117 /* if no connected sessions present then initiate next scan command immediately */
5118 /* minimum timer granularity is 10ms */
Madan Mohan Koyyalamudi0dea29e2013-07-11 12:01:37 +05305119 vos_timer_start(&pMac->scan.hTimerStaApConcTimer, 10);
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005120 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005121 }
5122#endif
5123 return (fRet);
5124}
5125
5126
5127tANI_BOOLEAN csrScanIsWildCardScan( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5128{
5129 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
Kiet Lam3cac75e2013-07-12 13:56:44 +05305130 tANI_BOOLEAN f = vos_mem_compare(pCommand->u.scanCmd.u.scanRequest.bssid,
5131 bssid, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07005132
5133 //It is not a wild card scan if the bssid is not broadcast and the number of SSID is 1.
5134 return ((tANI_BOOLEAN)( (f || (0xff == pCommand->u.scanCmd.u.scanRequest.bssid[0])) &&
5135 (pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs != 1) ));
5136}
5137
5138
5139eHalStatus csrScanSmeScanResponse( tpAniSirGlobal pMac, void *pMsgBuf )
5140{
5141 eHalStatus status = eHAL_STATUS_SUCCESS;
5142 tListElem *pEntry;
5143 tSmeCmd *pCommand;
5144 eCsrScanStatus scanStatus;
5145 tSirSmeScanRsp *pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
5146 tSmeGetScanChnRsp *pScanChnInfo;
5147 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
5148 eCsrScanReason reason = eCsrScanOther;
5149
Madan Mohan Koyyalamudi8f3583f2013-06-19 16:34:44 +05305150 if (pMac->fScanOffload)
5151 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList,
5152 LL_ACCESS_LOCK);
5153 else
5154 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07005155
5156 if ( pEntry )
5157 {
5158 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
5159 if ( eSmeCommandScan == pCommand->command )
5160 {
5161 scanStatus = (eSIR_SME_SUCCESS == pScanRsp->statusCode) ? eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
5162 reason = pCommand->u.scanCmd.reason;
5163 switch(pCommand->u.scanCmd.reason)
5164 {
5165 case eCsrScanAbortBgScan:
5166 case eCsrScanAbortNormalScan:
5167 case eCsrScanBGScanAbort:
5168 case eCsrScanBGScanEnable:
5169 break;
5170 case eCsrScanGetScanChnInfo:
5171 pScanChnInfo = (tSmeGetScanChnRsp *)pMsgBuf;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005172 /*
5173 * status code not available in tSmeGetScanChnRsp, so
5174 * by default considereing it to be success
5175 */
5176 scanStatus = eSIR_SME_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07005177 csrScanAgeResults(pMac, pScanChnInfo);
5178 break;
5179 case eCsrScanForCapsChange:
5180 csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand );
5181 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005182 case eCsrScanP2PFindPeer:
5183 scanStatus = ((eSIR_SME_SUCCESS == pScanRsp->statusCode) && (pScanRsp->length > 50)) ? eCSR_SCAN_FOUND_PEER : eCSR_SCAN_FAILURE;
5184 csrScanProcessScanResults( pMac, pCommand, pScanRsp, NULL );
5185 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005186 case eCsrScanSetBGScanParam:
5187 default:
5188 if(csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand ))
5189 {
5190 //Not to get channel info if the scan is not a wildcard scan because
5191 //it may cause scan results got aged out incorrectly.
Varun Reddy Yeturu08614702013-04-15 21:58:13 -07005192 if( csrScanIsWildCardScan( pMac, pCommand ) && (!pCommand->u.scanCmd.u.scanRequest.p2pSearch)
5193#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5194 && (pCommand->u.scanCmd.reason != eCsrScanGetLfrResult)
5195#endif
5196 )
Jeff Johnson295189b2012-06-20 16:38:30 -07005197 {
5198 //Get the list of channels scanned
Jeff Johnson32d95a32012-09-10 13:15:23 -07005199 if( pCommand->u.scanCmd.reason != eCsrScanUserRequest)
5200 {
Madan Mohan Koyyalamudi762dc6f2013-07-12 00:56:04 +05305201 csrScanGetScanChnInfo(pMac, pCommand->sessionId,
5202 NULL, NULL);
Jeff Johnson32d95a32012-09-10 13:15:23 -07005203 }
5204 else
5205 {
Madan Mohan Koyyalamudi762dc6f2013-07-12 00:56:04 +05305206 csrScanGetScanChnInfo(pMac,
5207 pCommand->sessionId,
5208 pCommand->u.scanCmd.pContext,
5209 pCommand->u.scanCmd.callback);
Jeff Johnson32d95a32012-09-10 13:15:23 -07005210 pCommand->u.scanCmd.callback = NULL;
5211 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005212 }
5213 }
5214 break;
5215 }//switch
5216 if(fRemoveCommand)
5217 {
5218
5219 csrReleaseScanCommand(pMac, pCommand, scanStatus);
5220
Madan Mohan Koyyalamudi91482b82012-12-27 17:28:14 -08005221 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005222 smeProcessPendingQueue( pMac );
5223 }
5224 else
5225 {
5226 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
5227 status = eHAL_STATUS_FAILURE;
5228 }
5229 }
5230 else
5231 {
5232 smsLog( pMac, LOGW, "CSR: Scan Completion called but NO commands are ACTIVE ..." );
5233 status = eHAL_STATUS_FAILURE;
5234 }
5235
5236 return (status);
5237}
5238
5239
5240
5241
5242tCsrScanResultInfo *csrScanResultGetFirst(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
5243{
5244 tListElem *pEntry;
5245 tCsrScanResult *pResult;
5246 tCsrScanResultInfo *pRet = NULL;
5247 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5248
5249 if(pResultList)
5250 {
5251 csrLLLock(&pResultList->List);
5252 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5253 if(pEntry)
5254 {
5255 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
5256 pRet = &pResult->Result;
5257 }
5258 pResultList->pCurEntry = pEntry;
5259 csrLLUnlock(&pResultList->List);
5260 }
5261
5262 return pRet;
5263}
5264
5265
5266tCsrScanResultInfo *csrScanResultGetNext(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
5267{
5268 tListElem *pEntry = NULL;
5269 tCsrScanResult *pResult = NULL;
5270 tCsrScanResultInfo *pRet = NULL;
5271 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5272
5273 if(pResultList)
5274 {
5275 csrLLLock(&pResultList->List);
5276 if(NULL == pResultList->pCurEntry)
5277 {
5278 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5279 }
5280 else
5281 {
5282 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
5283 }
5284 if(pEntry)
5285 {
5286 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
5287 pRet = &pResult->Result;
5288 }
5289 pResultList->pCurEntry = pEntry;
5290 csrLLUnlock(&pResultList->List);
5291 }
5292
5293 return pRet;
5294}
5295
5296
5297//This function moves the first BSS that matches the bssid to the head of the result
5298eHalStatus csrMoveBssToHeadFromBSSID(tpAniSirGlobal pMac, tCsrBssid *bssid, tScanResultHandle hScanResult)
5299{
5300 eHalStatus status = eHAL_STATUS_FAILURE;
5301 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5302 tCsrScanResult *pResult = NULL;
5303 tListElem *pEntry = NULL;
5304
5305 if(pResultList && bssid)
5306 {
5307 csrLLLock(&pResultList->List);
5308 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5309 while(pEntry)
5310 {
5311 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
Kiet Lam3cac75e2013-07-12 13:56:44 +05305312 if (vos_mem_compare(bssid, pResult->Result.BssDescriptor.bssId, sizeof(tCsrBssid)))
Jeff Johnson295189b2012-06-20 16:38:30 -07005313 {
5314 status = eHAL_STATUS_SUCCESS;
5315 csrLLRemoveEntry(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
5316 csrLLInsertHead(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
5317 break;
5318 }
5319 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
5320 }
5321 csrLLUnlock(&pResultList->List);
5322 }
5323
5324 return (status);
5325}
5326
5327
5328//Remove the BSS if possible.
5329//Return -- TRUE == the BSS is remove. False == Fail to remove it
5330//This function is called when list lock is held. Be caution what functions it can call.
5331tANI_BOOLEAN csrScanAgeOutBss(tpAniSirGlobal pMac, tCsrScanResult *pResult)
5332{
5333 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
5334 tANI_U32 i;
5335 tCsrRoamSession *pSession;
5336
5337 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5338 {
5339 if( CSR_IS_SESSION_VALID( pMac, i ) )
5340 {
5341 pSession = CSR_GET_SESSION( pMac, i );
5342 //Not to remove the BSS we are connected to.
5343 if(csrIsConnStateDisconnected(pMac, i) || (NULL == pSession->pConnectBssDesc) ||
5344 (!csrIsDuplicateBssDescription(pMac, &pResult->Result.BssDescriptor,
Tushnim Bhattacharyya4207db02013-06-26 23:23:18 -07005345 pSession->pConnectBssDesc, NULL, FALSE))
Jeff Johnson295189b2012-06-20 16:38:30 -07005346 )
5347 {
Arif Hussaineb871412013-11-20 11:06:42 -08005348 smsLog(pMac, LOGW, "Aging out BSS "MAC_ADDRESS_STR" Channel %d",
5349 MAC_ADDR_ARRAY(pResult->Result.BssDescriptor.bssId),
5350 pResult->Result.BssDescriptor.channelId);
Jeff Johnson295189b2012-06-20 16:38:30 -07005351 //No need to hold the spin lock because caller should hold the lock for pMac->scan.scanResultList
5352 if( csrLLRemoveEntry(&pMac->scan.scanResultList, &pResult->Link, LL_ACCESS_NOLOCK) )
5353 {
5354 csrFreeScanResultEntry(pMac, pResult);
Madan Mohan Koyyalamudi2e068bc2012-10-22 14:58:47 -07005355 fRet = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005356 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005357 break;
5358 }
5359 } //valid session
5360 } //for
Madan Mohan Koyyalamudi2e068bc2012-10-22 14:58:47 -07005361 if( CSR_ROAM_SESSION_MAX == i && fRet != eANI_BOOLEAN_TRUE )
Jeff Johnson295189b2012-06-20 16:38:30 -07005362 {
5363 //reset the counter so this won't hapeen too soon
5364 pResult->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
5365 pResult->Result.BssDescriptor.nReceivedTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
5366 }
5367
5368 return (fRet);
5369}
5370
5371
5372eHalStatus csrScanAgeResults(tpAniSirGlobal pMac, tSmeGetScanChnRsp *pScanChnInfo)
5373{
5374 eHalStatus status = eHAL_STATUS_SUCCESS;
5375 tListElem *pEntry, *tmpEntry;
5376 tCsrScanResult *pResult;
5377 tLimScanChn *pChnInfo;
5378 tANI_U8 i;
5379
5380 csrLLLock(&pMac->scan.scanResultList);
5381 for(i = 0; i < pScanChnInfo->numChn; i++)
5382 {
5383 pChnInfo = &pScanChnInfo->scanChn[i];
5384 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
5385 while( pEntry )
5386 {
5387 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
5388 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
5389 if(pResult->Result.BssDescriptor.channelId == pChnInfo->channelId)
5390 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005391 if(pResult->AgingCount <= 0)
5392 {
5393 smsLog(pMac, LOGW, " age out due to ref count");
5394 csrScanAgeOutBss(pMac, pResult);
5395 }
Madan Mohan Koyyalamudib9d3dcc2012-09-28 16:47:50 -07005396 else
5397 {
5398 pResult->AgingCount--;
5399 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005400 }
5401 pEntry = tmpEntry;
5402 }
5403 }
5404 csrLLUnlock(&pMac->scan.scanResultList);
5405
5406 return (status);
5407}
5408
5409
5410eHalStatus csrSendMBScanReq( tpAniSirGlobal pMac, tANI_U16 sessionId,
5411 tCsrScanRequest *pScanReq, tScanReqParam *pScanReqParam )
5412{
5413 eHalStatus status = eHAL_STATUS_SUCCESS;
5414 tSirSmeScanReq *pMsg;
5415 tANI_U16 msgLen;
5416 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
5417 tSirScanType scanType = pScanReq->scanType;
5418 tANI_U32 minChnTime; //in units of milliseconds
5419 tANI_U32 maxChnTime; //in units of milliseconds
5420 tANI_U32 i;
5421 tANI_U8 selfMacAddr[WNI_CFG_BSSID_LEN];
5422 tANI_U8 *pSelfMac = NULL;
5423
5424 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
5425 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) +
5426 ( pScanReq->uIEFieldLen ) ;
5427
Kiet Lam3cac75e2013-07-12 13:56:44 +05305428 pMsg = vos_mem_malloc(msgLen);
5429 if ( NULL == pMsg )
5430 status = eHAL_STATUS_FAILURE;
5431 else
5432 status = eHAL_STATUS_SUCCESS;
5433 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07005434 {
5435 do
5436 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05305437 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005438 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
5439 pMsg->length = pal_cpu_to_be16(msgLen);
5440 //ToDO: Fill in session info when we need to do scan base on session.
Madan Mohan Koyyalamudi78f17402013-06-13 14:47:55 +05305441 if ((pMac->fScanOffload) && (sessionId != CSR_SESSION_ID_INVALID))
5442 {
5443 pMsg->sessionId = sessionId;
5444 }
5445 else
5446 {
5447 /* if sessionId == CSR_SESSION_ID_INVALID, then send the scan
5448 request on first available session */
5449 pMsg->sessionId = 0;
5450 }
5451
Jeff Johnson295189b2012-06-20 16:38:30 -07005452 pMsg->transactionId = 0;
5453 pMsg->dot11mode = (tANI_U8) csrTranslateToWNICfgDot11Mode(pMac, csrFindBestPhyMode( pMac, pMac->roam.configParam.phyMode ));
5454 pMsg->bssType = pal_cpu_to_be32(csrTranslateBsstypeToMacType(pScanReq->BSSType));
5455
5456 if ( CSR_IS_SESSION_VALID( pMac, sessionId ) )
5457 {
5458 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[sessionId].selfMacAddr;
5459 }
5460 else
5461 {
5462 // Since we don't have session for the scanning, we find a valid session. In case we fail to
5463 // do so, get the WNI_CFG_STA_ID
5464 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5465 {
5466 if( CSR_IS_SESSION_VALID( pMac, i ) )
5467 {
5468 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[i].selfMacAddr;
5469 break;
5470 }
5471 }
5472 if( CSR_ROAM_SESSION_MAX == i )
5473 {
5474 tANI_U32 len = WNI_CFG_BSSID_LEN;
5475 pSelfMac = selfMacAddr;
5476 status = ccmCfgGetStr( pMac, WNI_CFG_STA_ID, pSelfMac, &len );
5477 if( !HAL_STATUS_SUCCESS( status ) ||
5478 ( len < WNI_CFG_BSSID_LEN ) )
5479 {
5480 smsLog( pMac, LOGE, FL(" Can not get self MAC address from CFG status = %d"), status );
5481 //Force failed status
5482 status = eHAL_STATUS_FAILURE;
5483 break;
5484 }
5485 }
5486 }
Kiet Lam3cac75e2013-07-12 13:56:44 +05305487 vos_mem_copy((tANI_U8 *)pMsg->selfMacAddr, pSelfMac, sizeof(tSirMacAddr));
Jeff Johnson295189b2012-06-20 16:38:30 -07005488
5489 //sirCopyMacAddr
Kiet Lam3cac75e2013-07-12 13:56:44 +05305490 vos_mem_copy((tANI_U8 *)pMsg->bssId, (tANI_U8 *)&pScanReq->bssid, sizeof(tSirMacAddr));
5491 if ( vos_mem_compare(pScanReq->bssid, bssid, sizeof(tCsrBssid)))
Jeff Johnson295189b2012-06-20 16:38:30 -07005492 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05305493 vos_mem_set(pMsg->bssId, sizeof(tSirMacAddr), 0xff);
Jeff Johnson295189b2012-06-20 16:38:30 -07005494 }
5495 else
5496 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05305497 vos_mem_copy(pMsg->bssId, pScanReq->bssid, WNI_CFG_BSSID_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07005498 }
5499 minChnTime = pScanReq->minChnTime;
5500 maxChnTime = pScanReq->maxChnTime;
5501
5502 //Verify the scan type first, if the scan is active scan, we need to make sure we
5503 //are allowed to do so.
5504 /* if 11d is enabled & we don't see any beacon around, scan type falls
5505 back to passive. But in BT AMP STA mode we need to send out a
5506 directed probe*/
5507 if( (eSIR_PASSIVE_SCAN != scanType) && (eCSR_SCAN_P2P_DISCOVERY != pScanReq->requestType)
5508 && (eCSR_BSS_TYPE_WDS_STA != pScanReq->BSSType)
5509 && (eANI_BOOLEAN_FALSE == pMac->scan.fEnableBypass11d))
5510 {
5511 scanType = pMac->scan.curScanType;
5512 if(eSIR_PASSIVE_SCAN == pMac->scan.curScanType)
5513 {
5514 if(minChnTime < pMac->roam.configParam.nPassiveMinChnTime)
5515 {
5516 minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
5517 }
5518 if(maxChnTime < pMac->roam.configParam.nPassiveMaxChnTime)
5519 {
5520 maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
5521 }
5522 }
5523 }
5524 pMsg->scanType = pal_cpu_to_be32(scanType);
5525
Vinay Krishna Eranna93923f62013-12-18 20:49:08 +05305526 pMsg->numSsid =
5527 (pScanReq->SSIDs.numOfSSIDs < SIR_SCAN_MAX_NUM_SSID) ?
5528 pScanReq->SSIDs.numOfSSIDs : SIR_SCAN_MAX_NUM_SSID;
Jeff Johnson295189b2012-06-20 16:38:30 -07005529 if((pScanReq->SSIDs.numOfSSIDs != 0) && ( eSIR_PASSIVE_SCAN != scanType ))
5530 {
Jeff Johnson56358122013-03-19 14:43:18 -07005531 for (i = 0; i < pMsg->numSsid; i++)
5532 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05305533 vos_mem_copy(&pMsg->ssId[i],
5534 &pScanReq->SSIDs.SSIDList[i].SSID, sizeof(tSirMacSSid));
Jeff Johnson56358122013-03-19 14:43:18 -07005535 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005536 }
5537 else
5538 {
5539 //Otherwise we scan all SSID and let the result filter later
Jeff Johnson56358122013-03-19 14:43:18 -07005540 for (i = 0; i < SIR_SCAN_MAX_NUM_SSID; i++)
5541 {
5542 pMsg->ssId[i].length = 0;
5543 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005544 }
5545
Jeff Johnson295189b2012-06-20 16:38:30 -07005546 pMsg->minChannelTime = pal_cpu_to_be32(minChnTime);
5547 pMsg->maxChannelTime = pal_cpu_to_be32(maxChnTime);
Kiran Kumar Lokere30b07722013-02-24 22:21:28 -08005548 pMsg->minChannelTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
5549 pMsg->maxChannelTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07005550 //hidden SSID option
5551 pMsg->hiddenSsid = pScanReqParam->hiddenSsid;
5552 //rest time
5553 //pMsg->restTime = pScanReq->restTime;
5554 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
5555 // All the scan results caching will be done by Roaming
5556 // We do not want LIM to do any caching of scan results,
5557 // so delete the LIM cache on all scan requests
5558 pMsg->returnFreshResults = pScanReqParam->freshScan;
5559 //Always ask for unique result
5560 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
5561 pMsg->channelList.numChannels = (tANI_U8)pScanReq->ChannelInfo.numOfChannels;
5562 if(pScanReq->ChannelInfo.numOfChannels)
5563 {
5564 //Assuming the channelNumber is tANI_U8 (1 byte)
Kiet Lam3cac75e2013-07-12 13:56:44 +05305565 vos_mem_copy(pMsg->channelList.channelNumber,
5566 pScanReq->ChannelInfo.ChannelList,
5567 pScanReq->ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07005568 }
5569
5570 pMsg->uIEFieldLen = (tANI_U16) pScanReq->uIEFieldLen;
5571 pMsg->uIEFieldOffset = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
5572 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) ;
5573 if(pScanReq->uIEFieldLen != 0)
5574 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05305575 vos_mem_copy((tANI_U8 *)pMsg+pMsg->uIEFieldOffset, pScanReq->pIEField,
5576 pScanReq->uIEFieldLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07005577 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005578 pMsg->p2pSearch = pScanReq->p2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07005579
Madan Mohan Koyyalamudi9b876782012-10-11 16:22:51 -07005580 if (pScanReq->requestType == eCSR_SCAN_HO_BG_SCAN)
5581 {
5582 pMsg->backgroundScanMode = eSIR_ROAMING_SCAN;
5583 }
5584
Jeff Johnson295189b2012-06-20 16:38:30 -07005585 }while(0);
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08005586 smsLog(pMac, LOG1, FL("domainIdCurrent %d scanType %d bssType %d requestType %d numChannels %d "),
Gopichand Nakkala79353d12012-12-31 16:31:46 -08005587 pMac->scan.domainIdCurrent, pMsg->scanType, pMsg->bssType,
5588 pScanReq->requestType, pMsg->channelList.numChannels);
5589
5590 for(i = 0; i < pMsg->channelList.numChannels; i++)
5591 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08005592 smsLog(pMac, LOG3, FL("channelNumber[%d]= %d"), i, pMsg->channelList.channelNumber[i]);
Gopichand Nakkala79353d12012-12-31 16:31:46 -08005593 }
5594
Jeff Johnson295189b2012-06-20 16:38:30 -07005595 if(HAL_STATUS_SUCCESS(status))
5596 {
5597 status = palSendMBMessage(pMac->hHdd, pMsg);
5598 }
Gopichand Nakkala79353d12012-12-31 16:31:46 -08005599 else
5600 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08005601 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d"), status );
Kiet Lam3cac75e2013-07-12 13:56:44 +05305602 vos_mem_free(pMsg);
Jeff Johnson295189b2012-06-20 16:38:30 -07005603 }
5604 }//Success allocated memory
Gopichand Nakkala79353d12012-12-31 16:31:46 -08005605 else
5606 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08005607 smsLog( pMac, LOGE, FL(" memory allocation failure"));
Gopichand Nakkala79353d12012-12-31 16:31:46 -08005608 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005609
Vinay Krishna Eranna93923f62013-12-18 20:49:08 +05305610 if(!HAL_STATUS_SUCCESS(status))
5611 {
5612 smsLog( pMac, LOG1, FL("Failed: SId: %d FirstMatch = %d"
5613 " UniqueResult = %d freshScan = %d hiddenSsid = %d"),
5614 sessionId, pScanReqParam->bReturnAfter1stMatch,
5615 pScanReqParam->fUniqueResult, pScanReqParam->freshScan,
5616 pScanReqParam->hiddenSsid );
5617 smsLog( pMac, LOG1, FL("scanType = %u BSSType = %u numOfSSIDs = %d"
5618 " numOfChannels = %d requestType = %d p2pSearch = %d\n"),
5619 pScanReq->scanType, pScanReq->BSSType,
5620 pScanReq->SSIDs.numOfSSIDs,
5621 pScanReq->ChannelInfo.numOfChannels, pScanReq->requestType,
5622 pScanReq->p2pSearch );
5623
5624 }
5625
Jeff Johnson295189b2012-06-20 16:38:30 -07005626 return( status );
5627}
5628
Varun Reddy Yeturu08614702013-04-15 21:58:13 -07005629eHalStatus csrSendMBScanResultReq( tpAniSirGlobal pMac, tANI_U32 sessionId, tScanReqParam *pScanReqParam )
Jeff Johnson295189b2012-06-20 16:38:30 -07005630{
5631 eHalStatus status = eHAL_STATUS_SUCCESS;
5632 tSirSmeScanReq *pMsg;
5633 tANI_U16 msgLen;
5634
5635 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ));
Kiet Lam3cac75e2013-07-12 13:56:44 +05305636 pMsg = vos_mem_malloc(msgLen);
5637 if ( NULL == pMsg )
5638 status = eHAL_STATUS_FAILURE;
5639 else
Jeff Johnson295189b2012-06-20 16:38:30 -07005640 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05305641 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005642 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
5643 pMsg->length = pal_cpu_to_be16(msgLen);
Varun Reddy Yeturu08614702013-04-15 21:58:13 -07005644 pMsg->sessionId = sessionId;
5645 pMsg->transactionId = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07005646 pMsg->returnFreshResults = pScanReqParam->freshScan;
5647 //Always ask for unique result
5648 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
5649 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
5650 status = palSendMBMessage(pMac->hHdd, pMsg);
Varun Reddy Yeturu08614702013-04-15 21:58:13 -07005651 if (!HAL_STATUS_SUCCESS(status))
5652 {
5653 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d\n"), status );
5654 }
5655
Jeff Johnson295189b2012-06-20 16:38:30 -07005656 }
5657
5658 return( status );
5659}
5660
5661
5662
5663eHalStatus csrScanChannels( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5664{
5665 eHalStatus status = eHAL_STATUS_FAILURE;
5666 tScanReqParam scanReq;
5667
5668 do
5669 {
5670 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE | TRUE;
5671 scanReq.fUniqueResult = TRUE;
5672 scanReq.hiddenSsid = SIR_SCAN_NO_HIDDEN_SSID;
5673 if(eCsrScanForSsid == pCommand->u.scanCmd.reason)
5674 {
5675 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_FIRST_MATCH;
5676 }
5677 else
5678 {
5679 // Basically do scan on all channels even for 11D 1st scan case.
5680 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5681 }
5682 if((eCsrScanBgScan == pCommand->u.scanCmd.reason)||
5683 (eCsrScanProbeBss == pCommand->u.scanCmd.reason))
5684 {
5685 scanReq.hiddenSsid = SIR_SCAN_HIDDEN_SSID_PE_DECISION;
5686 }
5687
5688#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5689 {
5690 vos_log_scan_pkt_type *pScanLog = NULL;
5691
5692 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
5693 if(pScanLog)
5694 {
5695 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
5696 eCsrScanProbeBss == pCommand->u.scanCmd.reason)
5697 {
5698 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
5699 }
5700 else
5701 {
5702 if( (eSIR_PASSIVE_SCAN != pCommand->u.scanCmd.u.scanRequest.scanType) &&
5703 (eSIR_PASSIVE_SCAN != pMac->scan.curScanType) )
5704 {
5705 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_REQ;
5706 }
5707 else
5708 {
5709 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_REQ;
5710 }
5711 }
5712 pScanLog->minChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.minChnTime;
5713 pScanLog->maxChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.maxChnTime;
5714 pScanLog->numChannel = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
5715 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
5716 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05305717 vos_mem_copy(pScanLog->channels,
5718 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
5719 pScanLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07005720 }
5721 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
5722 }
5723 }
5724#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5725
5726
5727 status = csrSendMBScanReq(pMac, pCommand->sessionId,
5728 &pCommand->u.scanCmd.u.scanRequest, &scanReq);
5729 }while(0);
5730
5731 return( status );
5732}
5733
5734
Varun Reddy Yeturu08614702013-04-15 21:58:13 -07005735eHalStatus csrScanRetrieveResult(tpAniSirGlobal pMac, tSmeCmd *pCommand)
Jeff Johnson295189b2012-06-20 16:38:30 -07005736{
5737 eHalStatus status = eHAL_STATUS_FAILURE;
5738 tScanReqParam scanReq;
5739
5740 do
5741 {
Varun Reddy Yeturu08614702013-04-15 21:58:13 -07005742#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5743 if (eCsrScanGetLfrResult == pCommand->u.scanCmd.reason)
5744 {
5745 //to get the LFR candidates from PE cache
5746 scanReq.freshScan = SIR_BG_SCAN_RETURN_LFR_CACHED_RESULTS|SIR_BG_SCAN_PURGE_LFR_RESULTS;
5747 scanReq.fUniqueResult = TRUE;
5748 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5749 }
5750 else
5751#endif
5752 {
5753 //not a fresh scan
5754 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE;
5755 scanReq.fUniqueResult = TRUE;
5756 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5757 }
5758 status = csrSendMBScanResultReq(pMac, pCommand->sessionId, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07005759 }while(0);
5760
5761 return (status);
5762}
5763
5764
5765
5766eHalStatus csrProcessScanCommand( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5767{
5768 eHalStatus status = eHAL_STATUS_SUCCESS;
5769 tCsrChannelInfo newChannelInfo = {0, NULL};
5770 int i, j;
5771 tANI_U8 *pChannel = NULL;
5772 tANI_U32 len = 0;
5773
5774 // Transition to Scanning state...
Madan Mohan Koyyalamudi8f3583f2013-06-19 16:34:44 +05305775 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07005776 {
Madan Mohan Koyyalamudi8f3583f2013-06-19 16:34:44 +05305777 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5778 {
5779 pCommand->u.scanCmd.lastRoamState[i] =
5780 csrRoamStateChange( pMac, eCSR_ROAMING_STATE_SCANNING, i);
5781 smsLog( pMac, LOG3, "starting SCAN command from %d state...."
5782 " reason is %d", pCommand->u.scanCmd.lastRoamState[i],
5783 pCommand->u.scanCmd.reason );
5784 }
5785 }
5786 else
5787 {
5788 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId] =
5789 csrRoamStateChange(pMac, eCSR_ROAMING_STATE_SCANNING,
5790 pCommand->sessionId);
5791 smsLog( pMac, LOG3,
5792 "starting SCAN command from %d state.... reason is %d",
5793 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId],
5794 pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07005795 }
5796
5797 switch(pCommand->u.scanCmd.reason)
5798 {
Varun Reddy Yeturu08614702013-04-15 21:58:13 -07005799#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5800 case eCsrScanGetLfrResult:
5801#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005802 case eCsrScanGetResult:
5803 case eCsrScanForCapsChange: //For cap change, LIM already save BSS description
Varun Reddy Yeturu08614702013-04-15 21:58:13 -07005804 status = csrScanRetrieveResult(pMac, pCommand);
Jeff Johnson295189b2012-06-20 16:38:30 -07005805 break;
5806 case eCsrScanSetBGScanParam:
5807 status = csrProcessSetBGScanParam(pMac, pCommand);
5808 break;
5809 case eCsrScanBGScanAbort:
5810 status = csrSetCfgBackgroundScanPeriod(pMac, 0);
5811 break;
5812 case eCsrScanBGScanEnable:
5813 status = csrSetCfgBackgroundScanPeriod(pMac, pMac->roam.configParam.bgScanInterval);
5814 break;
5815 case eCsrScanGetScanChnInfo:
Madan Mohan Koyyalamudi762dc6f2013-07-12 00:56:04 +05305816 status = csrScanGetScanChannelInfo(pMac, pCommand->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07005817 break;
5818 case eCsrScanUserRequest:
5819 if(pMac->roam.configParam.fScanTwice)
5820 {
5821 //We scan 2.4 channel twice
5822 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels &&
5823 (NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList))
5824 {
5825 len = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
5826 //allocate twice the channel
5827 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(newChannelInfo.numOfChannels * 2);
5828 pChannel = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
5829 }
5830 else
5831 {
5832 //get the valid channel list to scan all.
5833 len = sizeof(pMac->roam.validChannelList);
5834
5835 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
5836 {
5837 //allocate twice the channel
5838 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(len * 2);
5839 pChannel = pMac->roam.validChannelList;
5840 }
5841 }
5842 if(NULL == newChannelInfo.ChannelList)
5843 {
5844 newChannelInfo.numOfChannels = 0;
5845 }
5846 else
5847 {
5848 j = 0;
5849 for(i = 0; i < len; i++)
5850 {
5851 newChannelInfo.ChannelList[j++] = pChannel[i];
5852 if(CSR_MAX_24GHz_CHANNEL_NUMBER >= pChannel[i])
5853 {
5854 newChannelInfo.ChannelList[j++] = pChannel[i];
5855 }
5856 }
5857 if(NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
5858 {
5859 //pChannel points to the channellist from the command, free it.
5860 vos_mem_free(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
James Zmudaac3ad1b2013-04-18 18:20:54 -07005861 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07005862 }
5863 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = j;
5864 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = newChannelInfo.ChannelList;
5865 }
5866 } //if(pMac->roam.configParam.fScanTwice)
5867
5868 status = csrScanChannels(pMac, pCommand);
5869
5870 break;
5871 default:
5872 status = csrScanChannels(pMac, pCommand);
5873 break;
5874 }
5875
5876 if(!HAL_STATUS_SUCCESS(status))
5877 {
5878 csrReleaseScanCommand(pMac, pCommand, eCSR_SCAN_FAILURE);
5879 }
5880
5881 return (status);
5882}
5883
5884
5885eHalStatus csrScanSetBGScanparams(tpAniSirGlobal pMac, tCsrBGScanRequest *pScanReq)
5886{
5887 eHalStatus status = eHAL_STATUS_SUCCESS;
5888 tSmeCmd *pCommand = NULL;
5889
5890 if(pScanReq)
5891 {
5892 do
5893 {
5894 pCommand = csrGetCommandBuffer(pMac);
5895 if(!pCommand)
5896 {
5897 status = eHAL_STATUS_RESOURCES;
5898 break;
5899 }
Kiet Lam3cac75e2013-07-12 13:56:44 +05305900 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005901 pCommand->command = eSmeCommandScan;
5902 pCommand->u.scanCmd.reason = eCsrScanSetBGScanParam;
5903 pCommand->u.scanCmd.callback = NULL;
5904 pCommand->u.scanCmd.pContext = NULL;
Kiet Lam3cac75e2013-07-12 13:56:44 +05305905 vos_mem_copy(&pCommand->u.scanCmd.u.bgScanRequest, pScanReq, sizeof(tCsrBGScanRequest));
Jeff Johnson295189b2012-06-20 16:38:30 -07005906 //we have to do the follow
5907 if(pScanReq->ChannelInfo.numOfChannels == 0)
5908 {
5909 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
5910 }
5911 else
5912 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05305913 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList
5914 = vos_mem_malloc(pScanReq->ChannelInfo.numOfChannels);
5915 if ( NULL != pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07005916 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05305917 vos_mem_copy(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList,
5918 pScanReq->ChannelInfo.ChannelList,
5919 pScanReq->ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07005920 }
5921 else
5922 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08005923 smsLog(pMac, LOGE, FL("ran out of memory"));
Jeff Johnson295189b2012-06-20 16:38:30 -07005924 csrReleaseCommandScan(pMac, pCommand);
Kiet Lam3cac75e2013-07-12 13:56:44 +05305925 return eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005926 }
5927 }
5928
5929 //scan req for SSID
5930 if(pScanReq->SSID.length)
5931 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05305932 vos_mem_copy(pCommand->u.scanCmd.u.bgScanRequest.SSID.ssId,
5933 pScanReq->SSID.ssId, pScanReq->SSID.length);
Jeff Johnson295189b2012-06-20 16:38:30 -07005934 pCommand->u.scanCmd.u.bgScanRequest.SSID.length = pScanReq->SSID.length;
5935
5936 }
5937 pCommand->u.scanCmd.u.bgScanRequest.maxChnTime= pScanReq->maxChnTime;
5938 pCommand->u.scanCmd.u.bgScanRequest.minChnTime = pScanReq->minChnTime;
5939 pCommand->u.scanCmd.u.bgScanRequest.scanInterval = pScanReq->scanInterval;
5940
5941
5942 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
5943 if( !HAL_STATUS_SUCCESS( status ) )
5944 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08005945 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07005946 csrReleaseCommandScan( pMac, pCommand );
5947 break;
5948 }
5949 }while(0);
5950 }
5951
5952 return (status);
5953}
5954
5955eHalStatus csrScanBGScanAbort( tpAniSirGlobal pMac )
5956{
5957 eHalStatus status = eHAL_STATUS_SUCCESS;
5958 tSmeCmd *pCommand = NULL;
5959
5960 do
5961 {
5962 pCommand = csrGetCommandBuffer(pMac);
5963 if(!pCommand)
5964 {
5965 status = eHAL_STATUS_RESOURCES;
5966 break;
5967 }
Kiet Lam3cac75e2013-07-12 13:56:44 +05305968 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005969 pCommand->command = eSmeCommandScan;
5970 pCommand->u.scanCmd.reason = eCsrScanBGScanAbort;
5971 pCommand->u.scanCmd.callback = NULL;
5972 pCommand->u.scanCmd.pContext = NULL;
5973 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
5974 if( !HAL_STATUS_SUCCESS( status ) )
5975 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08005976 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07005977 csrReleaseCommandScan( pMac, pCommand );
5978 break;
5979 }
5980 }while(0);
5981
5982 return (status);
5983}
5984
5985
5986//This will enable the background scan with the non-zero interval
5987eHalStatus csrScanBGScanEnable(tpAniSirGlobal pMac)
5988{
5989 eHalStatus status = eHAL_STATUS_SUCCESS;
5990 tSmeCmd *pCommand = NULL;
5991
5992 if(pMac->roam.configParam.bgScanInterval)
5993 {
5994 do
5995 {
5996 pCommand = csrGetCommandBuffer(pMac);
5997 if(!pCommand)
5998 {
5999 status = eHAL_STATUS_RESOURCES;
6000 break;
6001 }
Kiet Lam3cac75e2013-07-12 13:56:44 +05306002 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006003 pCommand->command = eSmeCommandScan;
6004 pCommand->u.scanCmd.reason = eCsrScanBGScanEnable;
6005 pCommand->u.scanCmd.callback = NULL;
6006 pCommand->u.scanCmd.pContext = NULL;
6007 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
6008 if( !HAL_STATUS_SUCCESS( status ) )
6009 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08006010 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006011 csrReleaseCommandScan( pMac, pCommand );
6012 break;
6013 }
6014 }while(0);
6015 //BG scan results are reported automatically by PE to SME once the scan is done.
6016 //No need to fetch the results explicitly.
6017 //csrScanStartGetResultTimer(pMac);
6018 csrScanStartResultAgingTimer(pMac);
6019 }
6020 else
6021 {
6022 //We don't have BG scan so stop the aging timer
6023 csrScanStopResultAgingTimer(pMac);
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08006024 smsLog(pMac, LOGE, FL("cannot continue because the bgscan interval is 0"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006025 status = eHAL_STATUS_INVALID_PARAMETER;
6026 }
6027
6028 return (status);
6029}
6030
6031
6032eHalStatus csrScanCopyRequest(tpAniSirGlobal pMac, tCsrScanRequest *pDstReq, tCsrScanRequest *pSrcReq)
6033{
6034 eHalStatus status = eHAL_STATUS_SUCCESS;
6035 tANI_U32 len = sizeof(pMac->roam.validChannelList);
6036 tANI_U32 index = 0;
6037 tANI_U32 new_index = 0;
6038
6039 do
6040 {
6041 status = csrScanFreeRequest(pMac, pDstReq);
6042 if(HAL_STATUS_SUCCESS(status))
6043 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05306044 vos_mem_copy(pDstReq, pSrcReq, sizeof(tCsrScanRequest));
Gopichand Nakkala72d193a2012-12-31 14:07:19 -08006045 /* Re-initialize the pointers to NULL since we did a copy */
6046 pDstReq->pIEField = NULL;
6047 pDstReq->ChannelInfo.ChannelList = NULL;
6048 pDstReq->SSIDs.SSIDList = NULL;
6049
Jeff Johnson295189b2012-06-20 16:38:30 -07006050 if(pSrcReq->uIEFieldLen == 0)
6051 {
6052 pDstReq->pIEField = NULL;
6053 }
6054 else
6055 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05306056 pDstReq->pIEField = vos_mem_malloc(pSrcReq->uIEFieldLen);
6057 if ( NULL == pDstReq->pIEField )
Jeff Johnson295189b2012-06-20 16:38:30 -07006058 {
Vinay Krishna Eranna93923f62013-12-18 20:49:08 +05306059 status = eHAL_STATUS_FAILURE;
6060 smsLog(pMac, LOGE, FL("No memory for scanning IE fields"));
6061 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07006062 }
6063 else
6064 {
Vinay Krishna Eranna93923f62013-12-18 20:49:08 +05306065 status = eHAL_STATUS_SUCCESS;
6066 vos_mem_copy(pDstReq->pIEField, pSrcReq->pIEField,
6067 pSrcReq->uIEFieldLen);
6068 pDstReq->uIEFieldLen = pSrcReq->uIEFieldLen;
Jeff Johnson295189b2012-06-20 16:38:30 -07006069 }
6070 }//Allocate memory for IE field
6071 {
6072 if(pSrcReq->ChannelInfo.numOfChannels == 0)
6073 {
6074 pDstReq->ChannelInfo.ChannelList = NULL;
6075 pDstReq->ChannelInfo.numOfChannels = 0;
6076 }
6077 else
6078 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05306079 pDstReq->ChannelInfo.ChannelList = vos_mem_malloc(
6080 pSrcReq->ChannelInfo.numOfChannels
6081 * sizeof(*pDstReq->ChannelInfo.ChannelList));
6082 if ( NULL == pDstReq->ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07006083 {
Vinay Krishna Eranna93923f62013-12-18 20:49:08 +05306084 status = eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006085 pDstReq->ChannelInfo.numOfChannels = 0;
Vinay Krishna Eranna93923f62013-12-18 20:49:08 +05306086 smsLog(pMac, LOGE, FL("No memory for scanning Channel"
6087 " List"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006088 break;
6089 }
6090
6091 if((pSrcReq->scanType == eSIR_PASSIVE_SCAN) && (pSrcReq->requestType == eCSR_SCAN_REQUEST_11D_SCAN))
6092 {
6093 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
6094 {
6095 pDstReq->ChannelInfo.ChannelList[new_index] =
6096 pSrcReq->ChannelInfo.ChannelList[index];
6097 new_index++;
Vinay Krishna Eranna93923f62013-12-18 20:49:08 +05306098 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006099 pDstReq->ChannelInfo.numOfChannels = new_index;
6100 }
6101 else if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
6102 {
6103 new_index = 0;
6104 pMac->roam.numValidChannels = len;
6105 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
6106 {
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -07006107 /* Allow scan on valid channels only.
6108 * If it is p2p scan and valid channel list doesnt contain
6109 * social channels, enforce scan on social channels because
6110 * that is the only way to find p2p peers.
6111 * This can happen only if band is set to 5Ghz mode.
6112 */
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08006113 if((csrRoamIsValidChannel(pMac, pSrcReq->ChannelInfo.ChannelList[index])) ||
6114 ((eCSR_SCAN_P2P_DISCOVERY == pSrcReq->requestType) &&
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -07006115 CSR_IS_SOCIAL_CHANNEL(pSrcReq->ChannelInfo.ChannelList[index])))
Jeff Johnson295189b2012-06-20 16:38:30 -07006116 {
Madan Mohan Koyyalamudi91482b82012-12-27 17:28:14 -08006117 if( (pSrcReq->skipDfsChnlInP2pSearch &&
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08006118 (NV_CHANNEL_DFS == vos_nv_getChannelEnabledState(pSrcReq->ChannelInfo.ChannelList[index])) )
Madan Mohan Koyyalamudi91482b82012-12-27 17:28:14 -08006119#ifdef FEATURE_WLAN_LFR
6120 /*
6121 * If LFR is requesting a contiguous scan
6122 * (i.e. numOfChannels > 1), then ignore
6123 * DFS channels.
6124 * TODO: vos_nv_getChannelEnabledState is returning
6125 * 120, 124 and 128 as non-DFS channels. Hence, the
6126 * use of direct check for channels below.
6127 */
6128 || ((eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType) &&
6129 (pSrcReq->ChannelInfo.numOfChannels > 1) &&
Srinivas Girigowda6fa58662013-02-14 16:31:48 -08006130 (CSR_IS_CHANNEL_DFS(pSrcReq->ChannelInfo.ChannelList[index])))
Madan Mohan Koyyalamudi91482b82012-12-27 17:28:14 -08006131#endif
6132 )
6133 {
6134#ifdef FEATURE_WLAN_LFR
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08006135 smsLog(pMac, LOG2,
Vinay Krishna Eranna93923f62013-12-18 20:49:08 +05306136 FL(" reqType=%d, numOfChannels=%d,"
6137 " ignoring DFS channel %d"),
6138 pSrcReq->requestType,
Madan Mohan Koyyalamudi91482b82012-12-27 17:28:14 -08006139 pSrcReq->ChannelInfo.numOfChannels,
6140 pSrcReq->ChannelInfo.ChannelList[index]);
6141#endif
Vinay Krishna Eranna93923f62013-12-18 20:49:08 +05306142 continue;
Madan Mohan Koyyalamudi91482b82012-12-27 17:28:14 -08006143 }
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08006144
Jeff Johnson295189b2012-06-20 16:38:30 -07006145 pDstReq->ChannelInfo.ChannelList[new_index] =
6146 pSrcReq->ChannelInfo.ChannelList[index];
6147 new_index++;
6148 }
6149 }
6150 pDstReq->ChannelInfo.numOfChannels = new_index;
Madan Mohan Koyyalamudi91482b82012-12-27 17:28:14 -08006151#ifdef FEATURE_WLAN_LFR
6152 if ((eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType) &&
6153 (0 == pDstReq->ChannelInfo.numOfChannels))
6154 {
6155 /*
6156 * No valid channels found in the request.
6157 * Only perform scan on the channels passed
6158 * pSrcReq if it is a eCSR_SCAN_HO_BG_SCAN.
6159 * Passing 0 to LIM will trigger a scan on
6160 * all valid channels which is not desirable.
6161 */
Vinay Krishna Eranna93923f62013-12-18 20:49:08 +05306162 smsLog(pMac, LOGE, FL(" no valid channels found"
6163 " (request=%d)"), pSrcReq->requestType);
Madan Mohan Koyyalamudi91482b82012-12-27 17:28:14 -08006164 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
6165 {
Vinay Krishna Eranna93923f62013-12-18 20:49:08 +05306166 smsLog(pMac, LOGE, FL("pSrcReq index=%d"
6167 " channel=%d"), index,
6168 pSrcReq->ChannelInfo.ChannelList[index]);
Madan Mohan Koyyalamudi91482b82012-12-27 17:28:14 -08006169 }
6170 status = eHAL_STATUS_FAILURE;
6171 break;
6172 }
6173#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006174 }
6175 else
6176 {
Vinay Krishna Eranna93923f62013-12-18 20:49:08 +05306177 smsLog(pMac, LOGE, FL("Couldn't get the valid Channel"
6178 " List, keeping requester's list"));
Kiet Lam3cac75e2013-07-12 13:56:44 +05306179 vos_mem_copy(pDstReq->ChannelInfo.ChannelList,
6180 pSrcReq->ChannelInfo.ChannelList,
6181 pSrcReq->ChannelInfo.numOfChannels
6182 * sizeof(*pDstReq->ChannelInfo.ChannelList));
Jeff Johnson295189b2012-06-20 16:38:30 -07006183 pDstReq->ChannelInfo.numOfChannels = pSrcReq->ChannelInfo.numOfChannels;
6184 }
6185 }//Allocate memory for Channel List
6186 }
6187 if(pSrcReq->SSIDs.numOfSSIDs == 0)
6188 {
6189 pDstReq->SSIDs.numOfSSIDs = 0;
6190 pDstReq->SSIDs.SSIDList = NULL;
6191 }
6192 else
6193 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05306194 pDstReq->SSIDs.SSIDList = vos_mem_malloc(
6195 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
6196 if ( NULL == pDstReq->SSIDs.SSIDList )
6197 status = eHAL_STATUS_FAILURE;
6198 else
6199 status = eHAL_STATUS_SUCCESS;
6200 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07006201 {
6202 pDstReq->SSIDs.numOfSSIDs = pSrcReq->SSIDs.numOfSSIDs;
Kiet Lam3cac75e2013-07-12 13:56:44 +05306203 vos_mem_copy(pDstReq->SSIDs.SSIDList,
6204 pSrcReq->SSIDs.SSIDList,
6205 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
Jeff Johnson295189b2012-06-20 16:38:30 -07006206 }
6207 else
6208 {
6209 pDstReq->SSIDs.numOfSSIDs = 0;
Vinay Krishna Eranna93923f62013-12-18 20:49:08 +05306210 smsLog(pMac, LOGE, FL("No memory for scanning SSID List"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006211 break;
6212 }
6213 }//Allocate memory for SSID List
Jeff Johnson295189b2012-06-20 16:38:30 -07006214 pDstReq->p2pSearch = pSrcReq->p2pSearch;
Jeff Johnsone7245742012-09-05 17:12:55 -07006215 pDstReq->skipDfsChnlInP2pSearch = pSrcReq->skipDfsChnlInP2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07006216
6217 }
6218 }while(0);
6219
6220 if(!HAL_STATUS_SUCCESS(status))
6221 {
6222 csrScanFreeRequest(pMac, pDstReq);
6223 }
6224
6225 return (status);
6226}
6227
6228
6229eHalStatus csrScanFreeRequest(tpAniSirGlobal pMac, tCsrScanRequest *pReq)
6230{
Jeff Johnson295189b2012-06-20 16:38:30 -07006231
6232 if(pReq->ChannelInfo.ChannelList)
6233 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05306234 vos_mem_free(pReq->ChannelInfo.ChannelList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006235 pReq->ChannelInfo.ChannelList = NULL;
6236 }
6237 pReq->ChannelInfo.numOfChannels = 0;
6238 if(pReq->pIEField)
6239 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05306240 vos_mem_free(pReq->pIEField);
Jeff Johnson295189b2012-06-20 16:38:30 -07006241 pReq->pIEField = NULL;
6242 }
6243 pReq->uIEFieldLen = 0;
6244 if(pReq->SSIDs.SSIDList)
6245 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05306246 vos_mem_free(pReq->SSIDs.SSIDList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006247 pReq->SSIDs.SSIDList = NULL;
6248 }
6249 pReq->SSIDs.numOfSSIDs = 0;
6250
Kiet Lam3cac75e2013-07-12 13:56:44 +05306251 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07006252}
6253
6254
6255void csrScanCallCallback(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
6256{
6257 if(pCommand->u.scanCmd.callback)
6258 {
6259// sme_ReleaseGlobalLock( &pMac->sme );
6260 pCommand->u.scanCmd.callback(pMac, pCommand->u.scanCmd.pContext, pCommand->u.scanCmd.scanID, scanStatus);
6261// sme_AcquireGlobalLock( &pMac->sme );
6262 } else {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08006263 smsLog( pMac, LOG2, "%s:%d - Callback NULL!!!", __func__, __LINE__);
Jeff Johnson295189b2012-06-20 16:38:30 -07006264 }
6265}
6266
6267
6268void csrScanStopTimers(tpAniSirGlobal pMac)
6269{
6270 csrScanStopResultAgingTimer(pMac);
6271 csrScanStopIdleScanTimer(pMac);
6272 csrScanStopGetResultTimer(pMac);
Madan Mohan Koyyalamudi7da2fd72012-12-17 14:44:16 -08006273 if(0 != pMac->scan.scanResultCfgAgingTime )
6274 {
6275 csrScanStopResultCfgAgingTimer(pMac);
6276 }
6277
Jeff Johnson295189b2012-06-20 16:38:30 -07006278}
6279
6280
6281eHalStatus csrScanStartGetResultTimer(tpAniSirGlobal pMac)
6282{
6283 eHalStatus status;
6284
6285 if(pMac->scan.fScanEnable)
6286 {
Madan Mohan Koyyalamudi0dea29e2013-07-11 12:01:37 +05306287 status = vos_timer_start(&pMac->scan.hTimerGetResult, CSR_SCAN_GET_RESULT_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006288 }
6289 else
6290 {
6291 status = eHAL_STATUS_FAILURE;
6292 }
6293
6294 return (status);
6295}
6296
6297
6298eHalStatus csrScanStopGetResultTimer(tpAniSirGlobal pMac)
6299{
Madan Mohan Koyyalamudi0dea29e2013-07-11 12:01:37 +05306300 return (vos_timer_stop(&pMac->scan.hTimerGetResult));
Jeff Johnson295189b2012-06-20 16:38:30 -07006301}
6302
6303
6304void csrScanGetResultTimerHandler(void *pv)
6305{
6306 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6307
6308 csrScanRequestResult(pMac);
Madan Mohan Koyyalamudi0dea29e2013-07-11 12:01:37 +05306309
6310 vos_timer_start(&pMac->scan.hTimerGetResult, CSR_SCAN_GET_RESULT_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006311}
6312
6313#ifdef WLAN_AP_STA_CONCURRENCY
6314static void csrStaApConcTimerHandler(void *pv)
6315{
6316 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6317 tListElem *pEntry;
6318 tSmeCmd *pScanCmd;
6319
6320 csrLLLock(&pMac->scan.scanCmdPendingList);
6321
6322 if ( NULL != ( pEntry = csrLLPeekHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) ) )
6323 {
6324 tCsrScanRequest scanReq;
6325 tSmeCmd *pSendScanCmd = NULL;
6326 tANI_U8 numChn = 0;
Sudhir Sattayappa Kohalli3466c5f2013-05-22 23:16:42 -07006327 tANI_U8 nNumChanCombinedConc = 0;
Madan Mohan Koyyalamudi8591f092012-12-17 13:04:30 -08006328 tANI_U8 i, j;
Jeff Johnson295189b2012-06-20 16:38:30 -07006329 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
6330 tANI_U8 channelToScan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
6331 eHalStatus status;
6332
Jeff Johnson295189b2012-06-20 16:38:30 -07006333 pScanCmd = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
6334 numChn = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08006335
6336 /* if any session is connected and the number of channels to scan is
6337 * greater than 1 then split the scan into multiple scan operations
6338 * on each individual channel else continue to perform scan on all
6339 * specified channels */
Madan Mohan Koyyalamudie8d64402012-12-04 16:49:55 -08006340
6341 /* split scan if number of channels to scan is greater than 1 and
6342 * any one of the following:
6343 * - STA session is connected and the scan is not a P2P search
6344 * - any P2P session is connected
Madan Mohan Koyyalamudi91482b82012-12-27 17:28:14 -08006345 * Do not split scans if no concurrent infra connections are
6346 * active and if the scan is a BG scan triggered by LFR (OR)
6347 * any scan if LFR is in the middle of a BG scan. Splitting
6348 * the scan is delaying the time it takes for LFR to find
6349 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudie8d64402012-12-04 16:49:55 -08006350 */
Sudhir Sattayappa Kohalli3466c5f2013-05-22 23:16:42 -07006351
6352 if((csrIsStaSessionConnected(pMac) &&
6353 !csrIsP2pSessionConnected(pMac)))
6354 {
6355 nNumChanCombinedConc = pMac->roam.configParam.nNumStaChanCombinedConc;
6356 }
6357 else if(csrIsP2pSessionConnected(pMac))
6358 {
6359 nNumChanCombinedConc = pMac->roam.configParam.nNumP2PChanCombinedConc;
6360 }
6361
6362 if ( (numChn > nNumChanCombinedConc) &&
Madan Mohan Koyyalamudi91482b82012-12-27 17:28:14 -08006363 ((csrIsStaSessionConnected(pMac) &&
6364#ifdef FEATURE_WLAN_LFR
6365 (csrIsConcurrentInfraConnected(pMac) ||
6366 ((pScanCmd->u.scanCmd.reason != eCsrScanBgScan) &&
6367 (pMac->roam.neighborRoamInfo.neighborRoamState !=
6368 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
6369#endif
6370 (pScanCmd->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudie8d64402012-12-04 16:49:55 -08006371 (csrIsP2pSessionConnected(pMac))))
Jeff Johnson295189b2012-06-20 16:38:30 -07006372 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05306373 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006374
6375 pSendScanCmd = csrGetCommandBuffer(pMac); //optimize this to use 2 command buffer only
6376 if (!pSendScanCmd)
6377 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08006378 smsLog( pMac, LOGE, FL(" Failed to get Queue command buffer") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006379 csrLLUnlock(&pMac->scan.scanCmdPendingList);
6380 return;
6381 }
6382 pSendScanCmd->command = pScanCmd->command;
6383 pSendScanCmd->sessionId = pScanCmd->sessionId;
6384 pSendScanCmd->u.scanCmd.callback = NULL;
6385 pSendScanCmd->u.scanCmd.pContext = pScanCmd->u.scanCmd.pContext;
6386 pSendScanCmd->u.scanCmd.reason = pScanCmd->u.scanCmd.reason;
6387 pSendScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
6388
Madan Mohan Koyyalamudiaf2a8b92012-10-09 14:58:07 -07006389 /* First copy all the parameters to local variable of scan request */
6390 csrScanCopyRequest(pMac, &scanReq, &pScanCmd->u.scanCmd.u.scanRequest);
6391
6392 /* Now modify the elements of local var scan request required to be modified for split scan */
Madan Mohan Koyyalamudi66554132012-11-30 15:10:25 -08006393 if(scanReq.ChannelInfo.ChannelList != NULL)
6394 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05306395 vos_mem_free(scanReq.ChannelInfo.ChannelList);
Madan Mohan Koyyalamudi66554132012-11-30 15:10:25 -08006396 scanReq.ChannelInfo.ChannelList = NULL;
6397 }
6398
Sudhir Sattayappa Kohalli3466c5f2013-05-22 23:16:42 -07006399 pChnInfo->numOfChannels = nNumChanCombinedConc;
Kiet Lam3cac75e2013-07-12 13:56:44 +05306400 vos_mem_copy(&channelToScan[0],
6401 &pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[0],
6402 pChnInfo->numOfChannels * sizeof(tANI_U8));//just send one channel
Jeff Johnson295189b2012-06-20 16:38:30 -07006403 pChnInfo->ChannelList = &channelToScan[0];
6404
Sudhir Sattayappa Kohalli3466c5f2013-05-22 23:16:42 -07006405 for (i = 0, j = nNumChanCombinedConc; i < (numChn-nNumChanCombinedConc); i++, j++)
Jeff Johnson295189b2012-06-20 16:38:30 -07006406 {
6407 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] =
Madan Mohan Koyyalamudi8591f092012-12-17 13:04:30 -08006408 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[j]; //Move all the channels one step
Jeff Johnson295189b2012-06-20 16:38:30 -07006409 }
6410
Sudhir Sattayappa Kohalli3466c5f2013-05-22 23:16:42 -07006411 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = numChn - nNumChanCombinedConc; //reduce outstanding # of channels to be scanned
Jeff Johnson295189b2012-06-20 16:38:30 -07006412
6413 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
6414 //Modify callers parameters in case of concurrency
6415 scanReq.scanType = eSIR_ACTIVE_SCAN;
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -07006416 //Use concurrency values for min/maxChnTime.
6417 //We know csrIsAnySessionConnected(pMac) returns TRUE here
6418 csrSetDefaultScanTiming(pMac, scanReq.scanType, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07006419
6420 status = csrScanCopyRequest(pMac, &pSendScanCmd->u.scanCmd.u.scanRequest, &scanReq);
6421 if(!HAL_STATUS_SUCCESS(status))
6422 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08006423 smsLog( pMac, LOGE, FL(" Failed to get copy csrScanRequest = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006424 csrLLUnlock(&pMac->scan.scanCmdPendingList);
6425 return;
Madan Mohan Koyyalamudi66554132012-11-30 15:10:25 -08006426 }
6427 /* Clean the local scan variable */
6428 scanReq.ChannelInfo.ChannelList = NULL;
6429 scanReq.ChannelInfo.numOfChannels = 0;
6430 csrScanFreeRequest(pMac, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07006431 }
6432 else
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08006433 {
6434 /* no active connected session present or numChn == 1
6435 * scan all remaining channels */
Jeff Johnson295189b2012-06-20 16:38:30 -07006436 pSendScanCmd = pScanCmd;
6437 //remove this command from pending list
6438 if (csrLLRemoveHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) == NULL)
6439 { //In case between PeekHead and here, the entry got removed by another thread.
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08006440 smsLog( pMac, LOGE, FL(" Failed to remove entry from scanCmdPendingList"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006441 }
6442
6443 }
6444 csrQueueSmeCommand(pMac, pSendScanCmd, eANI_BOOLEAN_FALSE);
6445
6446 }
6447
Jeff Johnson295189b2012-06-20 16:38:30 -07006448 csrLLUnlock(&pMac->scan.scanCmdPendingList);
6449
6450}
6451#endif
6452
6453eHalStatus csrScanStartResultAgingTimer(tpAniSirGlobal pMac)
6454{
Madan Mohan Koyyalamudi7da2fd72012-12-17 14:44:16 -08006455 eHalStatus status = eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006456
6457 if(pMac->scan.fScanEnable)
6458 {
Madan Mohan Koyyalamudi0dea29e2013-07-11 12:01:37 +05306459 status = vos_timer_start(&pMac->scan.hTimerResultAging, CSR_SCAN_RESULT_AGING_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006460 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006461 return (status);
6462}
6463
Madan Mohan Koyyalamudi7da2fd72012-12-17 14:44:16 -08006464eHalStatus csrScanStartResultCfgAgingTimer(tpAniSirGlobal pMac)
6465{
6466 eHalStatus status = eHAL_STATUS_FAILURE;
6467
6468 if(pMac->scan.fScanEnable)
6469 {
Madan Mohan Koyyalamudi0dea29e2013-07-11 12:01:37 +05306470 status = vos_timer_start(&pMac->scan.hTimerResultCfgAging, CSR_SCAN_RESULT_CFG_AGING_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Madan Mohan Koyyalamudi7da2fd72012-12-17 14:44:16 -08006471 }
6472 return (status);
6473}
Jeff Johnson295189b2012-06-20 16:38:30 -07006474
6475eHalStatus csrScanStopResultAgingTimer(tpAniSirGlobal pMac)
6476{
Madan Mohan Koyyalamudi0dea29e2013-07-11 12:01:37 +05306477 return (vos_timer_stop(&pMac->scan.hTimerResultAging));
Jeff Johnson295189b2012-06-20 16:38:30 -07006478}
6479
Madan Mohan Koyyalamudi7da2fd72012-12-17 14:44:16 -08006480eHalStatus csrScanStopResultCfgAgingTimer(tpAniSirGlobal pMac)
6481{
Madan Mohan Koyyalamudi0dea29e2013-07-11 12:01:37 +05306482 return (vos_timer_stop(&pMac->scan.hTimerResultCfgAging));
Madan Mohan Koyyalamudi7da2fd72012-12-17 14:44:16 -08006483}
Jeff Johnson295189b2012-06-20 16:38:30 -07006484
6485//This function returns the maximum time a BSS is allowed in the scan result.
6486//The time varies base on connection and power saving factors.
6487//Not connected, No PS
6488//Not connected, with PS
6489//Connected w/o traffic, No PS
6490//Connected w/o traffic, with PS
6491//Connected w/ traffic, no PS -- Not supported
6492//Connected w/ traffic, with PS -- Not supported
6493//the return unit is in seconds.
6494tANI_U32 csrScanGetAgeOutTime(tpAniSirGlobal pMac)
6495{
6496 tANI_U32 nRet;
6497
6498 if(pMac->scan.nAgingCountDown)
6499 {
6500 //Calculate what should be the timeout value for this
6501 nRet = pMac->scan.nLastAgeTimeOut * pMac->scan.nAgingCountDown;
6502 pMac->scan.nAgingCountDown--;
6503 }
6504 else
6505 {
6506 if( csrIsAllSessionDisconnected( pMac ) )
6507 {
6508 if(pmcIsPowerSaveEnabled(pMac, ePMC_IDLE_MODE_POWER_SAVE))
6509 {
6510 nRet = pMac->roam.configParam.scanAgeTimeNCPS;
6511 }
6512 else
6513 {
6514 nRet = pMac->roam.configParam.scanAgeTimeNCNPS;
6515 }
6516 }
6517 else
6518 {
6519 if(pmcIsPowerSaveEnabled(pMac, ePMC_BEACON_MODE_POWER_SAVE))
6520 {
6521 nRet = pMac->roam.configParam.scanAgeTimeCPS;
6522 }
6523 else
6524 {
6525 nRet = pMac->roam.configParam.scanAgeTimeCNPS;
6526 }
6527 }
6528 //If state-change causing aging time out change, we want to delay it somewhat to avoid
6529 //unnecessary removal of BSS. This is mostly due to transition from connect to disconnect.
6530 if(pMac->scan.nLastAgeTimeOut > nRet)
6531 {
6532 if(nRet)
6533 {
6534 pMac->scan.nAgingCountDown = (pMac->scan.nLastAgeTimeOut / nRet);
6535 }
6536 pMac->scan.nLastAgeTimeOut = nRet;
6537 nRet *= pMac->scan.nAgingCountDown;
6538 }
6539 else
6540 {
6541 pMac->scan.nLastAgeTimeOut = nRet;
6542 }
6543 }
6544
6545 return (nRet);
6546}
6547
6548
6549void csrScanResultAgingTimerHandler(void *pv)
6550{
6551 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6552 tANI_BOOLEAN fDisconnected = csrIsAllSessionDisconnected(pMac);
6553
6554 //no scan, no aging
6555 if(pMac->scan.fScanEnable &&
6556 (((eANI_BOOLEAN_FALSE == fDisconnected) && pMac->roam.configParam.bgScanInterval)
6557 || (fDisconnected && (pMac->scan.fCancelIdleScan == eANI_BOOLEAN_FALSE)))
6558 )
6559 {
6560 tListElem *pEntry, *tmpEntry;
6561 tCsrScanResult *pResult;
6562 tANI_TIMESTAMP ageOutTime = (tANI_TIMESTAMP)(csrScanGetAgeOutTime(pMac) * PAL_TICKS_PER_SECOND); //turn it into 10ms units
6563 tANI_TIMESTAMP curTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
6564
6565 csrLLLock(&pMac->scan.scanResultList);
6566 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
6567 while( pEntry )
6568 {
6569 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
6570 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
6571 if((curTime - pResult->Result.BssDescriptor.nReceivedTime) > ageOutTime)
6572 {
6573 smsLog(pMac, LOGW, " age out due to time out");
6574 csrScanAgeOutBss(pMac, pResult);
6575 }
6576 pEntry = tmpEntry;
6577 }
6578 csrLLUnlock(&pMac->scan.scanResultList);
6579 }
Madan Mohan Koyyalamudi0dea29e2013-07-11 12:01:37 +05306580 vos_timer_start(&pMac->scan.hTimerResultAging, CSR_SCAN_RESULT_AGING_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006581}
6582
Madan Mohan Koyyalamudi7da2fd72012-12-17 14:44:16 -08006583static void csrScanResultCfgAgingTimerHandler(void *pv)
6584{
6585 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6586 tListElem *pEntry, *tmpEntry;
6587 tCsrScanResult *pResult;
6588 tANI_TIMESTAMP ageOutTime = pMac->scan.scanResultCfgAgingTime * PAL_TICKS_PER_SECOND;
6589 tANI_TIMESTAMP curTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
6590
6591 csrLLLock(&pMac->scan.scanResultList);
6592 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
6593 while( pEntry )
6594 {
6595 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
6596 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
6597 if((curTime - pResult->Result.BssDescriptor.nReceivedTime) > ageOutTime)
6598 {
6599 smsLog(pMac, LOGW, " age out due to time out");
6600 csrScanAgeOutBss(pMac, pResult);
6601 }
6602 pEntry = tmpEntry;
6603 }
6604 csrLLUnlock(&pMac->scan.scanResultList);
Madan Mohan Koyyalamudi0dea29e2013-07-11 12:01:37 +05306605 vos_timer_start(&pMac->scan.hTimerResultCfgAging, CSR_SCAN_RESULT_CFG_AGING_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Madan Mohan Koyyalamudi7da2fd72012-12-17 14:44:16 -08006606}
Jeff Johnson295189b2012-06-20 16:38:30 -07006607
6608eHalStatus csrScanStartIdleScanTimer(tpAniSirGlobal pMac, tANI_U32 interval)
6609{
6610 eHalStatus status;
6611
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08006612 smsLog(pMac, LOG1, " csrScanStartIdleScanTimer");
Jeff Johnson295189b2012-06-20 16:38:30 -07006613 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) && interval)
6614 {
6615 pMac->scan.nIdleScanTimeGap += interval;
Madan Mohan Koyyalamudi0dea29e2013-07-11 12:01:37 +05306616 vos_timer_stop(&pMac->scan.hTimerIdleScan);
6617 status = vos_timer_start(&pMac->scan.hTimerIdleScan, interval/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006618 if( !HAL_STATUS_SUCCESS(status) )
6619 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08006620 smsLog(pMac, LOGE, " Fail to start Idle scan timer. status = %d interval = %d", status, interval);
Jeff Johnson295189b2012-06-20 16:38:30 -07006621 //This should not happen but set the flag to restart when ready
6622 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6623 }
6624 }
6625 else
6626 {
6627 if( pMac->scan.fScanEnable && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) )
6628 {
6629 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6630 }
6631 status = eHAL_STATUS_FAILURE;
6632 }
6633
6634 return (status);
6635}
6636
6637
6638eHalStatus csrScanStopIdleScanTimer(tpAniSirGlobal pMac)
6639{
Madan Mohan Koyyalamudi0dea29e2013-07-11 12:01:37 +05306640 return (vos_timer_stop(&pMac->scan.hTimerIdleScan));
Jeff Johnson295189b2012-06-20 16:38:30 -07006641}
6642
6643
6644//Stop CSR from asking for IMPS, This function doesn't disable IMPS from CSR
6645void csrScanSuspendIMPS( tpAniSirGlobal pMac )
6646{
6647 csrScanCancelIdleScan(pMac);
6648}
6649
6650
6651//Start CSR from asking for IMPS. This function doesn't trigger CSR to request entering IMPS
6652//because IMPS maybe disabled.
6653void csrScanResumeIMPS( tpAniSirGlobal pMac )
6654{
6655 csrScanStartIdleScan( pMac );
6656}
6657
6658
6659void csrScanIMPSCallback(void *callbackContext, eHalStatus status)
6660{
6661 tpAniSirGlobal pMac = PMAC_STRUCT( callbackContext );
6662
6663 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6664 {
6665 if(pMac->roam.configParam.IsIdleScanEnabled)
6666 {
6667 if(HAL_STATUS_SUCCESS(status))
6668 {
6669 if(csrIsAllSessionDisconnected(pMac) && !csrIsRoamCommandWaiting(pMac))
6670 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08006671 smsLog(pMac, LOGW, FL("starts idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006672 csrScanAllChannels(pMac, eCSR_SCAN_IDLE_MODE_SCAN);
6673 }
6674 else
6675 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08006676 smsLog(pMac, LOGW, FL("cannot start idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006677 //even though we are in timer handle, calling stop timer will make sure the timer
6678 //doesn't get to restart.
6679 csrScanStopIdleScanTimer(pMac);
6680 }
6681 }
6682 else
6683 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08006684 smsLog(pMac, LOGE, FL("sees not success status (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07006685 }
6686 }
6687 else
6688 {//we might need another flag to check if CSR needs to request imps at all
6689
6690 tANI_U32 nTime = 0;
6691
6692 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_FALSE;
6693 if(!HAL_STATUS_SUCCESS(csrScanTriggerIdleScan(pMac, &nTime)))
6694 {
6695 csrScanStartIdleScanTimer(pMac, nTime);
6696 }
6697 }
6698 }
6699}
6700
6701
6702//Param: pTimeInterval -- Caller allocated memory in return, if failed, to specify the nxt time interval for
6703//idle scan timer interval
6704//Return: Not success -- meaning it cannot start IMPS, caller needs to start a timer for idle scan
6705eHalStatus csrScanTriggerIdleScan(tpAniSirGlobal pMac, tANI_U32 *pTimeInterval)
6706{
6707 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
6708
6709 //Do not trigger IMPS in case of concurrency
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006710 if (vos_concurrent_sessions_running() && csrIsAnySessionInConnectState(pMac))
6711 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08006712 smsLog( pMac, LOG1, FL("Cannot request IMPS because Concurrent Sessions Running") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006713 return (status);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006714 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006715
6716 if(pTimeInterval)
6717 {
6718 *pTimeInterval = 0;
6719 }
6720
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08006721 smsLog(pMac, LOG3, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006722 if( smeCommandPending( pMac ) )
6723 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08006724 smsLog( pMac, LOG1, FL(" Cannot request IMPS because command pending") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006725 //Not to enter IMPS because more work to do
6726 if(pTimeInterval)
6727 {
6728 *pTimeInterval = 0;
6729 }
6730 //restart when ready
6731 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6732
6733 return (status);
6734 }
Kiran Kumar Lokere3c46dc12013-03-18 11:08:11 -07006735 if (IsPmcImpsReqFailed (pMac))
6736 {
6737 if(pTimeInterval)
6738 {
6739 *pTimeInterval = 1000000; //usec
6740 }
6741 //restart when ready
6742 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006743
Kiran Kumar Lokere3c46dc12013-03-18 11:08:11 -07006744 return status;
6745 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006746 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6747 /*&& pMac->roam.configParam.impsSleepTime*/)
6748 {
6749 //Stop get result timer because idle scan gets scan result out of PE
6750 csrScanStopGetResultTimer(pMac);
6751 if(pTimeInterval)
6752 {
6753 *pTimeInterval = pMac->roam.configParam.impsSleepTime;
6754 }
6755 //pmcRequestImps take a period in millisecond unit.
6756 status = pmcRequestImps(pMac, pMac->roam.configParam.impsSleepTime / PAL_TIMER_TO_MS_UNIT, csrScanIMPSCallback, pMac);
6757 if(!HAL_STATUS_SUCCESS(status))
6758 {
6759 if(eHAL_STATUS_PMC_ALREADY_IN_IMPS != status)
6760 {
6761 //Do restart the timer if CSR thinks it cannot do IMPS
6762 if( !csrCheckPSReady( pMac ) )
6763 {
6764 if(pTimeInterval)
6765 {
6766 *pTimeInterval = 0;
6767 }
6768 //Set the restart flag to true because that idle scan
6769 //can be restarted even though the timer will not be running
6770 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6771 }
6772 else
6773 {
6774 //For not now, we do a quicker retry
6775 if(pTimeInterval)
6776 {
6777 *pTimeInterval = CSR_IDLE_SCAN_WAIT_TIME;
6778 }
6779 }
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08006780 smsLog(pMac, LOGW, FL("call pmcRequestImps and it returns status code (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07006781 }
6782 else
6783 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08006784 smsLog(pMac, LOGW, FL("already in IMPS"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006785 //Since CSR is the only module to request for IMPS. If it is already in IMPS, CSR assumes
6786 //the callback will be called in the future. Should not happen though.
6787 status = eHAL_STATUS_SUCCESS;
6788 pMac->scan.nIdleScanTimeGap = 0;
6789 }
6790 }
6791 else
6792 {
6793 //requested so let's reset the value
6794 pMac->scan.nIdleScanTimeGap = 0;
6795 }
6796 }
6797
6798 return (status);
6799}
6800
6801
6802eHalStatus csrScanStartIdleScan(tpAniSirGlobal pMac)
6803{
6804 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
6805 tANI_U32 nTime = 0;
6806
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08006807 smsLog(pMac, LOGW, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006808 if(pMac->roam.configParam.IsIdleScanEnabled)
6809 {
6810 //stop bg scan first
6811 csrScanBGScanAbort(pMac);
6812 //Stop get result timer because idle scan gets scan result out of PE
6813 csrScanStopGetResultTimer(pMac);
6814 //Enable aging timer since idle scan is going on
6815 csrScanStartResultAgingTimer(pMac);
6816 }
6817 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_FALSE;
6818 status = csrScanTriggerIdleScan(pMac, &nTime);
6819 if(!HAL_STATUS_SUCCESS(status))
6820 {
6821 csrScanStartIdleScanTimer(pMac, nTime);
6822 }
6823
6824 return (status);
6825}
6826
6827
6828void csrScanCancelIdleScan(tpAniSirGlobal pMac)
6829{
6830 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6831 {
Jeff Johnson295189b2012-06-20 16:38:30 -07006832 if (vos_concurrent_sessions_running()) {
6833 return;
6834 }
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08006835 smsLog(pMac, LOG1, " csrScanCancelIdleScan");
Jeff Johnson295189b2012-06-20 16:38:30 -07006836 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_TRUE;
6837 //Set the restart flag in case later on it is uncancelled
6838 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6839 csrScanStopIdleScanTimer(pMac);
6840 csrScanRemoveNotRoamingScanCommand(pMac);
6841 }
6842}
6843
6844
6845void csrScanIdleScanTimerHandler(void *pv)
6846{
6847 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6848 eHalStatus status;
6849 tANI_U32 nTime = 0;
6850
6851 smsLog(pMac, LOGW, " csrScanIdleScanTimerHandler called ");
Kiran Kumar Lokere3c46dc12013-03-18 11:08:11 -07006852 pmcResetImpsFailStatus (pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07006853 status = csrScanTriggerIdleScan(pMac, &nTime);
6854 if(!HAL_STATUS_SUCCESS(status) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan))
6855 {
6856 //Check whether it is time to actually do an idle scan
6857 if(pMac->scan.nIdleScanTimeGap >= pMac->roam.configParam.impsSleepTime)
6858 {
6859 pMac->scan.nIdleScanTimeGap = 0;
6860 csrScanIMPSCallback(pMac, eHAL_STATUS_SUCCESS);
6861 }
6862 else
6863 {
6864 csrScanStartIdleScanTimer(pMac, nTime);
6865 }
6866 }
6867}
6868
6869
6870
6871
6872tANI_BOOLEAN csrScanRemoveNotRoamingScanCommand(tpAniSirGlobal pMac)
6873{
6874 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
6875 tListElem *pEntry, *pEntryTmp;
6876 tSmeCmd *pCommand;
6877 tDblLinkList localList;
Madan Mohan Koyyalamudi1dae9082013-08-01 18:00:25 +05306878 tDblLinkList *pCmdList;
Jeff Johnson295189b2012-06-20 16:38:30 -07006879
6880 vos_mem_zero(&localList, sizeof(tDblLinkList));
6881 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
6882 {
6883 smsLog(pMac, LOGE, FL(" failed to open list"));
6884 return fRet;
6885 }
Madan Mohan Koyyalamudi1dae9082013-08-01 18:00:25 +05306886 if (!pMac->fScanOffload)
6887 pCmdList = &pMac->sme.smeCmdPendingList;
6888 else
6889 pCmdList = &pMac->sme.smeScanCmdPendingList;
Jeff Johnson295189b2012-06-20 16:38:30 -07006890
Madan Mohan Koyyalamudi1dae9082013-08-01 18:00:25 +05306891 csrLLLock(pCmdList);
6892 pEntry = csrLLPeekHead(pCmdList, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07006893 while(pEntry)
6894 {
Madan Mohan Koyyalamudi1dae9082013-08-01 18:00:25 +05306895 pEntryTmp = csrLLNext(pCmdList, pEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07006896 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6897 if( eSmeCommandScan == pCommand->command )
6898 {
6899 switch( pCommand->u.scanCmd.reason )
6900 {
6901 case eCsrScanIdleScan:
Madan Mohan Koyyalamudi1dae9082013-08-01 18:00:25 +05306902 if( csrLLRemoveEntry(pCmdList, pEntry, LL_ACCESS_NOLOCK) )
Jeff Johnson295189b2012-06-20 16:38:30 -07006903 {
6904 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
6905 }
6906 fRet = eANI_BOOLEAN_TRUE;
6907 break;
6908
6909 default:
6910 break;
6911 } //switch
6912 }
6913 pEntry = pEntryTmp;
6914 }
6915
Madan Mohan Koyyalamudi1dae9082013-08-01 18:00:25 +05306916 csrLLUnlock(pCmdList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006917
6918 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
6919 {
6920 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6921 csrReleaseCommandScan( pMac, pCommand );
6922 }
6923
6924 csrLLClose(&localList);
6925
6926 return (fRet);
6927}
6928
6929
6930tANI_BOOLEAN csrScanRemoveFreshScanCommand(tpAniSirGlobal pMac, tANI_U8 sessionId)
6931{
6932 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
6933 tListElem *pEntry, *pEntryTmp;
6934 tSmeCmd *pCommand;
6935 tDblLinkList localList;
Madan Mohan Koyyalamudi1dae9082013-08-01 18:00:25 +05306936 tDblLinkList *pCmdList;
Jeff Johnson295189b2012-06-20 16:38:30 -07006937
6938 vos_mem_zero(&localList, sizeof(tDblLinkList));
6939 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
6940 {
6941 smsLog(pMac, LOGE, FL(" failed to open list"));
6942 return fRet;
6943 }
6944
Madan Mohan Koyyalamudi1dae9082013-08-01 18:00:25 +05306945 if (!pMac->fScanOffload)
6946 pCmdList = &pMac->sme.smeCmdPendingList;
6947 else
6948 pCmdList = &pMac->sme.smeScanCmdPendingList;
6949
6950 csrLLLock(pCmdList);
6951 pEntry = csrLLPeekHead(pCmdList, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07006952 while(pEntry)
6953 {
Madan Mohan Koyyalamudi1dae9082013-08-01 18:00:25 +05306954 pEntryTmp = csrLLNext(pCmdList, pEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07006955 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6956 if( (eSmeCommandScan == pCommand->command) && (sessionId == pCommand->sessionId) )
6957 {
6958 switch(pCommand->u.scanCmd.reason)
6959 {
Varun Reddy Yeturu08614702013-04-15 21:58:13 -07006960#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
6961 case eCsrScanGetLfrResult:
6962#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006963 case eCsrScanGetResult:
6964 case eCsrScanSetBGScanParam:
6965 case eCsrScanBGScanAbort:
6966 case eCsrScanBGScanEnable:
6967 case eCsrScanGetScanChnInfo:
6968 break;
6969 default:
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08006970 smsLog (pMac, LOGW, "%s: -------- abort scan command reason = %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07006971 __func__, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07006972 //The rest are fresh scan requests
Madan Mohan Koyyalamudi1dae9082013-08-01 18:00:25 +05306973 if( csrLLRemoveEntry(pCmdList, pEntry, LL_ACCESS_NOLOCK) )
Jeff Johnson295189b2012-06-20 16:38:30 -07006974 {
6975 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
6976 }
6977 fRet = eANI_BOOLEAN_TRUE;
6978 break;
6979 }
6980 }
6981 pEntry = pEntryTmp;
6982 }
6983
Madan Mohan Koyyalamudi1dae9082013-08-01 18:00:25 +05306984 csrLLUnlock(pCmdList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006985
6986 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
6987 {
6988 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6989 if (pCommand->u.scanCmd.callback)
6990 {
6991 /* User scan request is pending,
6992 * send response with status eCSR_SCAN_ABORT*/
6993 pCommand->u.scanCmd.callback(pMac,
6994 pCommand->u.scanCmd.pContext,
6995 pCommand->u.scanCmd.scanID,
6996 eCSR_SCAN_ABORT);
6997 }
6998 csrReleaseCommandScan( pMac, pCommand );
6999 }
7000 csrLLClose(&localList);
7001
7002 return (fRet);
7003}
7004
7005
7006void csrReleaseScanCommand(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
7007{
7008 eCsrScanReason reason = pCommand->u.scanCmd.reason;
Madan Mohan Koyyalamudi8f3583f2013-06-19 16:34:44 +05307009 tANI_BOOLEAN status;
7010
7011 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07007012 {
Madan Mohan Koyyalamudi8f3583f2013-06-19 16:34:44 +05307013 tANI_U32 i;
7014 for(i = 0; i < CSR_ROAM_SESSION_MAX; i++)
7015 csrRoamStateChange(pMac, pCommand->u.scanCmd.lastRoamState[i], i);
7016 }
7017 else
7018 {
7019 csrRoamStateChange(pMac,
7020 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId],
7021 pCommand->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07007022 }
7023
Madan Mohan Koyyalamudi8f3583f2013-06-19 16:34:44 +05307024 csrScanCallCallback(pMac, pCommand, scanStatus);
Jeff Johnson295189b2012-06-20 16:38:30 -07007025
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08007026 smsLog(pMac, LOG3, " Remove Scan command reason = %d", reason);
Madan Mohan Koyyalamudi8f3583f2013-06-19 16:34:44 +05307027 if (pMac->fScanOffload)
7028 {
7029 status = csrLLRemoveEntry(&pMac->sme.smeScanCmdActiveList,
7030 &pCommand->Link, LL_ACCESS_LOCK);
7031 }
7032 else
7033 {
7034 status = csrLLRemoveEntry(&pMac->sme.smeCmdActiveList,
7035 &pCommand->Link, LL_ACCESS_LOCK);
7036 }
7037
7038 if(status)
Jeff Johnson295189b2012-06-20 16:38:30 -07007039 {
7040 csrReleaseCommandScan( pMac, pCommand );
7041 }
7042 else
7043 {
Madan Mohan Koyyalamudi8f3583f2013-06-19 16:34:44 +05307044 smsLog(pMac, LOGE,
7045 " ********csrReleaseScanCommand cannot release command reason %d",
7046 pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07007047 }
7048}
7049
7050
7051eHalStatus csrScanGetPMKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
7052 tPmkidCandidateInfo *pPmkidList, tANI_U32 *pNumItems )
7053{
7054 eHalStatus status = eHAL_STATUS_SUCCESS;
7055 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
7056
Jeff Johnson32d95a32012-09-10 13:15:23 -07007057 if(!pSession)
7058 {
7059 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
7060 return eHAL_STATUS_FAILURE;
7061 }
7062
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08007063 smsLog(pMac, LOGW, " pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07007064 csrResetPMKIDCandidateList(pMac, sessionId);
7065 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
7066 {
7067 tCsrScanResultFilter *pScanFilter;
7068 tCsrScanResultInfo *pScanResult;
7069 tScanResultHandle hBSSList;
7070 tANI_U32 nItems = *pNumItems;
7071
7072 *pNumItems = 0;
Kiet Lam3cac75e2013-07-12 13:56:44 +05307073 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
7074 if ( NULL == pScanFilter )
7075 status = eHAL_STATUS_FAILURE;
7076 else
Jeff Johnson295189b2012-06-20 16:38:30 -07007077 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05307078 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007079 //Here is the profile we need to connect to
7080 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
7081 if(HAL_STATUS_SUCCESS(status))
7082 {
7083 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
7084 if(HAL_STATUS_SUCCESS(status))
7085 {
7086 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumPmkidCandidate < nItems))
7087 {
7088 //NumPmkidCandidate adds up here
7089 csrProcessBSSDescForPMKIDList(pMac, &pScanResult->BssDescriptor,
7090 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
7091 }
7092 if(pSession->NumPmkidCandidate)
7093 {
7094 *pNumItems = pSession->NumPmkidCandidate;
Kiet Lam3cac75e2013-07-12 13:56:44 +05307095 vos_mem_copy(pPmkidList, pSession->PmkidCandidateInfo,
7096 pSession->NumPmkidCandidate * sizeof(tPmkidCandidateInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07007097 }
7098 csrScanResultPurge(pMac, hBSSList);
7099 }//Have scan result
7100 csrFreeScanFilter(pMac, pScanFilter);
7101 }
Kiet Lam3cac75e2013-07-12 13:56:44 +05307102 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07007103 }
7104 }
7105
7106 return (status);
7107}
7108
7109
7110
7111#ifdef FEATURE_WLAN_WAPI
7112eHalStatus csrScanGetBKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
7113 tBkidCandidateInfo *pBkidList, tANI_U32 *pNumItems )
7114{
7115 eHalStatus status = eHAL_STATUS_SUCCESS;
7116 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
7117
Jeff Johnson32d95a32012-09-10 13:15:23 -07007118 if(!pSession)
7119 {
7120 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
7121 return eHAL_STATUS_FAILURE;
7122 }
7123
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08007124 smsLog(pMac, LOGW, " pMac->scan.NumBkidCandidate = %d", pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07007125 csrResetBKIDCandidateList(pMac, sessionId);
7126 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
7127 {
7128 tCsrScanResultFilter *pScanFilter;
7129 tCsrScanResultInfo *pScanResult;
7130 tScanResultHandle hBSSList;
7131 tANI_U32 nItems = *pNumItems;
7132 *pNumItems = 0;
Kiet Lam3cac75e2013-07-12 13:56:44 +05307133 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
7134 if ( NULL == pScanFilter )
7135 status = eHAL_STATUS_FAILURE;
7136 else
Jeff Johnson295189b2012-06-20 16:38:30 -07007137 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05307138 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007139 //Here is the profile we need to connect to
7140 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
7141 if(HAL_STATUS_SUCCESS(status))
7142 {
7143 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
7144 if(HAL_STATUS_SUCCESS(status))
7145 {
7146 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumBkidCandidate < nItems))
7147 {
7148 //pMac->scan.NumBkidCandidate adds up here
7149 csrProcessBSSDescForBKIDList(pMac, &pScanResult->BssDescriptor,
7150 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
7151
7152 }
7153 if(pSession->NumBkidCandidate)
7154 {
7155 *pNumItems = pSession->NumBkidCandidate;
Kiet Lam3cac75e2013-07-12 13:56:44 +05307156 vos_mem_copy(pBkidList, pSession->BkidCandidateInfo, pSession->NumBkidCandidate * sizeof(tBkidCandidateInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07007157 }
7158 csrScanResultPurge(pMac, hBSSList);
7159 }//Have scan result
7160 }
Kiet Lam3cac75e2013-07-12 13:56:44 +05307161 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07007162 }
7163 }
7164
7165 return (status);
7166}
7167#endif /* FEATURE_WLAN_WAPI */
7168
7169
7170
7171//This function is usually used for BSSs that suppresses SSID so the profile
7172//shall have one and only one SSID
Varun Reddy Yeturu2c35a7d2013-05-20 11:47:10 -07007173eHalStatus csrScanForSSID(tpAniSirGlobal pMac, tANI_U32 sessionId, tCsrRoamProfile *pProfile, tANI_U32 roamId, tANI_BOOLEAN notify)
Jeff Johnson295189b2012-06-20 16:38:30 -07007174{
7175 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
7176 tSmeCmd *pScanCmd = NULL;
7177 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
7178 tANI_U8 index = 0;
7179 tANI_U32 numSsid = pProfile->SSIDs.numOfSSIDs;
7180
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08007181 smsLog(pMac, LOG2, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007182 //For WDS, we use the index 0. There must be at least one in there
7183 if( CSR_IS_WDS_STA( pProfile ) && numSsid )
7184 {
7185 numSsid = 1;
7186 }
7187 if(pMac->scan.fScanEnable && ( numSsid == 1 ) )
7188 {
7189 do
7190 {
7191 pScanCmd = csrGetCommandBuffer(pMac);
7192 if(!pScanCmd)
7193 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08007194 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007195 break;
7196 }
Kiet Lam3cac75e2013-07-12 13:56:44 +05307197 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
7198 pScanCmd->u.scanCmd.pToRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
7199 if ( NULL == pScanCmd->u.scanCmd.pToRoamProfile )
7200 status = eHAL_STATUS_FAILURE;
7201 else
7202 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07007203 status = csrRoamCopyProfile(pMac, pScanCmd->u.scanCmd.pToRoamProfile, pProfile);
7204 if(!HAL_STATUS_SUCCESS(status))
7205 break;
7206 pScanCmd->u.scanCmd.roamId = roamId;
7207 pScanCmd->command = eSmeCommandScan;
Jeff Johnsone7245742012-09-05 17:12:55 -07007208 pScanCmd->sessionId = (tANI_U8)sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07007209 pScanCmd->u.scanCmd.callback = NULL;
7210 pScanCmd->u.scanCmd.pContext = NULL;
Varun Reddy Yeturu2c35a7d2013-05-20 11:47:10 -07007211 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 -07007212 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Kiet Lam3cac75e2013-07-12 13:56:44 +05307213 vos_mem_set(&pScanCmd->u.scanCmd.u.scanRequest, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007214 pScanCmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Jeff Johnson295189b2012-06-20 16:38:30 -07007215 pScanCmd->u.scanCmd.u.scanRequest.BSSType = pProfile->BSSType;
Jeff Johnsone7245742012-09-05 17:12:55 -07007216 // To avoid 11b rate in probe request Set p2pSearch flag as 1 for P2P Client Mode
7217 if(VOS_P2P_CLIENT_MODE == pProfile->csrPersona)
7218 {
7219 pScanCmd->u.scanCmd.u.scanRequest.p2pSearch = 1;
7220 }
Agarwal Ashishff1152d2013-12-30 23:32:50 +05307221 if(pProfile->nAddIEScanLength)
Jeff Johnsone7245742012-09-05 17:12:55 -07007222 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05307223 pScanCmd->u.scanCmd.u.scanRequest.pIEField = vos_mem_malloc(
7224 pProfile->nAddIEScanLength);
7225 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.pIEField )
7226 status = eHAL_STATUS_FAILURE;
7227 else
7228 status = eHAL_STATUS_SUCCESS;
7229 vos_mem_set(pScanCmd->u.scanCmd.u.scanRequest.pIEField,
7230 pProfile->nAddIEScanLength, 0);
7231 if (HAL_STATUS_SUCCESS(status))
Jeff Johnsone7245742012-09-05 17:12:55 -07007232 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05307233 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.pIEField,
Agarwal Ashishff1152d2013-12-30 23:32:50 +05307234 pProfile->addIEScan, pProfile->nAddIEScanLength);
Jeff Johnsone7245742012-09-05 17:12:55 -07007235 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = pProfile->nAddIEScanLength;
7236 }
7237 else
7238 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08007239 smsLog(pMac, LOGE, "No memory for scanning IE fields");
Jeff Johnsone7245742012-09-05 17:12:55 -07007240 }
7241 } //Allocate memory for IE field
7242 else
7243 {
7244 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = 0;
7245 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07007246 /* For one channel be good enpugh time to receive beacon atleast */
7247 if( 1 == pProfile->ChannelInfo.numOfChannels )
7248 {
7249 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime = MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7250 pScanCmd->u.scanCmd.u.scanRequest.minChnTime = MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7251 }
7252 else
7253 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05307254 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime =
7255 pMac->roam.configParam.nActiveMaxChnTime;
7256 pScanCmd->u.scanCmd.u.scanRequest.minChnTime =
7257 pMac->roam.configParam.nActiveMinChnTime;
Jeff Johnson32d95a32012-09-10 13:15:23 -07007258 }
Kiet Lam3cac75e2013-07-12 13:56:44 +05307259 pScanCmd->u.scanCmd.u.scanRequest.maxChnTimeBtc =
7260 pMac->roam.configParam.nActiveMaxChnTimeBtc;
7261 pScanCmd->u.scanCmd.u.scanRequest.minChnTimeBtc =
7262 pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07007263 if(pProfile->BSSIDs.numOfBSSIDs == 1)
7264 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05307265 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.bssid,
7266 pProfile->BSSIDs.bssid, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07007267 }
7268 else
7269 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05307270 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.bssid, bAddr, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07007271 }
7272 if(pProfile->ChannelInfo.numOfChannels)
7273 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05307274 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(
7275 sizeof(*pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
7276 * pProfile->ChannelInfo.numOfChannels);
7277 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
7278 status = eHAL_STATUS_FAILURE;
7279 else
7280 status = eHAL_STATUS_SUCCESS;
7281 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
7282 if(HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07007283 {
7284 csrRoamIsChannelValid(pMac, pProfile->ChannelInfo.ChannelList[0]);
7285 for(index = 0; index < pProfile->ChannelInfo.numOfChannels; index++)
7286 {
7287 if(csrRoamIsValidChannel(pMac, pProfile->ChannelInfo.ChannelList[index]))
7288 {
7289 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels]
7290 = pProfile->ChannelInfo.ChannelList[index];
7291 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels++;
7292 }
7293 else
7294 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08007295 smsLog(pMac, LOGW, FL("process a channel (%d) that is invalid"), pProfile->ChannelInfo.ChannelList[index]);
Jeff Johnson295189b2012-06-20 16:38:30 -07007296 }
7297
7298 }
7299 }
7300 else
7301 {
7302 break;
7303 }
7304
7305 }
7306 else
7307 {
7308 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
7309 }
7310 if(pProfile->SSIDs.numOfSSIDs)
7311 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05307312 pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList = vos_mem_malloc(
7313 pProfile->SSIDs.numOfSSIDs * sizeof(tCsrSSIDInfo));
7314 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList )
7315 status = eHAL_STATUS_FAILURE;
7316 else
7317 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07007318 if(!HAL_STATUS_SUCCESS(status))
7319 {
7320 break;
7321 }
7322 pScanCmd->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 1;
Kiet Lam3cac75e2013-07-12 13:56:44 +05307323 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList,
7324 pProfile->SSIDs.SSIDList, sizeof(tCsrSSIDInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07007325 }
7326 //Start process the command
7327 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
7328 if( !HAL_STATUS_SUCCESS( status ) )
7329 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08007330 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07007331 break;
7332 }
7333 }while(0);
7334 if(!HAL_STATUS_SUCCESS(status))
7335 {
7336 if(pScanCmd)
7337 {
7338 csrReleaseCommandScan(pMac, pScanCmd);
7339 //TODO:free the memory that is allocated in this function
7340 }
Varun Reddy Yeturu2c35a7d2013-05-20 11:47:10 -07007341 if(notify)
7342 {
Jeff Johnson295189b2012-06-20 16:38:30 -07007343 csrRoamCallCallback(pMac, sessionId, NULL, roamId, eCSR_ROAM_FAILED, eCSR_ROAM_RESULT_FAILURE);
7344 }
Varun Reddy Yeturu2c35a7d2013-05-20 11:47:10 -07007345 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007346 }//valid
7347 else
7348 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08007349 smsLog(pMac, LOGE, FL("cannot scan because scanEnable (%d) or numSSID (%d) is invalid"),
Jeff Johnson295189b2012-06-20 16:38:30 -07007350 pMac->scan.fScanEnable, pProfile->SSIDs.numOfSSIDs);
7351 }
7352
7353 return (status);
7354}
7355
7356
7357//Issue a scan base on the new capability infomation
7358//This should only happen when the associated AP changes its capability.
7359//After this scan is done, CSR reroams base on the new scan results
7360eHalStatus csrScanForCapabilityChange(tpAniSirGlobal pMac, tSirSmeApNewCaps *pNewCaps)
7361{
7362 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
7363 tSmeCmd *pScanCmd = NULL;
7364
7365 if(pNewCaps)
7366 {
7367 do
7368 {
7369 pScanCmd = csrGetCommandBuffer(pMac);
7370 if(!pScanCmd)
7371 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08007372 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007373 status = eHAL_STATUS_RESOURCES;
7374 break;
7375 }
Kiet Lam3cac75e2013-07-12 13:56:44 +05307376 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007377 status = eHAL_STATUS_SUCCESS;
7378 pScanCmd->u.scanCmd.roamId = 0;
7379 pScanCmd->command = eSmeCommandScan;
7380 pScanCmd->u.scanCmd.callback = NULL;
7381 pScanCmd->u.scanCmd.pContext = NULL;
7382 pScanCmd->u.scanCmd.reason = eCsrScanForCapsChange;
7383 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
7384 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
7385 if( !HAL_STATUS_SUCCESS( status ) )
7386 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08007387 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07007388 break;
7389 }
7390 }while(0);
7391 if(!HAL_STATUS_SUCCESS(status))
7392 {
7393 if(pScanCmd)
7394 {
7395 csrReleaseCommandScan(pMac, pScanCmd);
7396 }
7397 }
7398 }
7399
7400 return (status);
7401}
7402
7403
7404
7405void csrInitBGScanChannelList(tpAniSirGlobal pMac)
7406{
7407 tANI_U32 len = CSR_MIN(sizeof(pMac->roam.validChannelList), sizeof(pMac->scan.bgScanChannelList));
7408
Kiet Lam3cac75e2013-07-12 13:56:44 +05307409 vos_mem_set(pMac->scan.bgScanChannelList, len, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007410 pMac->scan.numBGScanChannel = 0;
7411
7412 if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
7413 {
7414 pMac->roam.numValidChannels = len;
7415 pMac->scan.numBGScanChannel = (tANI_U8)CSR_MIN(len, WNI_CFG_BG_SCAN_CHANNEL_LIST_LEN);
Kiet Lam3cac75e2013-07-12 13:56:44 +05307416 vos_mem_copy(pMac->scan.bgScanChannelList, pMac->roam.validChannelList,
7417 pMac->scan.numBGScanChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07007418 csrSetBGScanChannelList(pMac, pMac->scan.bgScanChannelList, pMac->scan.numBGScanChannel);
7419 }
7420}
7421
7422
7423//This function return TRUE if background scan channel list is adjusted.
7424//this function will only shrink the background scan channel list
7425tANI_BOOLEAN csrAdjustBGScanChannelList(tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels,
7426 tANI_U8 *pAdjustChannels, tANI_U8 *pNumAdjustChannels)
7427{
7428 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
7429 tANI_U8 i, j, count = *pNumAdjustChannels;
7430
7431 i = 0;
7432 while(i < count)
7433 {
7434 for(j = 0; j < NumChannels; j++)
7435 {
7436 if(pChannelList[j] == pAdjustChannels[i])
7437 break;
7438 }
7439 if(j == NumChannels)
7440 {
7441 //This channel is not in the list, remove it
7442 fRet = eANI_BOOLEAN_TRUE;
7443 count--;
7444 if(count - i)
7445 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05307446 vos_mem_copy(&pAdjustChannels[i], &pAdjustChannels[i+1], count - i);
Jeff Johnson295189b2012-06-20 16:38:30 -07007447 }
7448 else
7449 {
7450 //already remove the last one. Done.
7451 break;
7452 }
7453 }
7454 else
7455 {
7456 i++;
7457 }
7458 }//while(i<count)
7459 *pNumAdjustChannels = count;
7460
7461 return (fRet);
7462}
7463
7464
7465//Get the list of the base channels to scan for passively 11d info
7466eHalStatus csrScanGetSupportedChannels( tpAniSirGlobal pMac )
7467{
7468 eHalStatus status = eHAL_STATUS_SUCCESS;
7469 int n = WNI_CFG_VALID_CHANNEL_LIST_LEN;
7470
7471 status = vos_nv_getSupportedChannels( pMac->scan.baseChannels.channelList, &n, NULL, NULL );
7472 if( HAL_STATUS_SUCCESS(status) )
7473 {
7474 pMac->scan.baseChannels.numChannels = (tANI_U8)n;
7475 }
7476 else
7477 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08007478 smsLog( pMac, LOGE, FL(" failed") );
Jeff Johnson295189b2012-06-20 16:38:30 -07007479 pMac->scan.baseChannels.numChannels = 0;
7480 }
7481
7482 return ( status );
7483}
7484
7485//This function use the input pChannelList to validate the current saved channel list
7486eHalStatus csrSetBGScanChannelList( tpAniSirGlobal pMac, tANI_U8 *pAdjustChannels, tANI_U8 NumAdjustChannels)
7487{
7488 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumAdjustChannels;
7489
7490 return (ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pAdjustChannels, dataLen, NULL, eANI_BOOLEAN_FALSE));
7491}
7492
7493
7494void csrSetCfgValidChannelList( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels )
7495{
7496 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumChannels;
Gopichand Nakkalab91e8a92013-06-11 17:51:13 +05307497 eHalStatus status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007498
7499 ccmCfgSetStr(pMac, WNI_CFG_VALID_CHANNEL_LIST, pChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
7500
Gopichand Nakkalab91e8a92013-06-11 17:51:13 +05307501 if (pMac->fScanOffload)
7502 {
7503 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
7504 "Scan offload is enabled, update default chan list");
7505 status = csrUpdateChannelList(&pMac->scan);
7506 if (eHAL_STATUS_SUCCESS != status)
7507 {
7508 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR,
7509 "failed to update the supported channel list");
7510 }
7511 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007512 return;
7513}
7514
7515
7516
7517/*
7518 * The Tx power limits are saved in the cfg for future usage.
7519 */
7520void csrSaveTxPowerToCfg( tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 cfgId )
7521{
7522 tListElem *pEntry;
7523 tANI_U32 cbLen = 0, dataLen;
7524 tCsrChannelPowerInfo *pChannelSet;
7525 tANI_U32 idx;
7526 tSirMacChanInfo *pChannelPowerSet;
7527 tANI_U8 *pBuf = NULL;
7528
7529 //allocate maximum space for all channels
7530 dataLen = WNI_CFG_VALID_CHANNEL_LIST_LEN * sizeof(tSirMacChanInfo);
Kiet Lam3cac75e2013-07-12 13:56:44 +05307531 if ( (pBuf = vos_mem_malloc(dataLen)) != NULL )
Jeff Johnson295189b2012-06-20 16:38:30 -07007532 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05307533 vos_mem_set(pBuf, dataLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007534 pChannelPowerSet = (tSirMacChanInfo *)(pBuf);
7535
7536 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
7537 // write the tuples (startChan, numChan, txPower) for each channel found in the channel power list.
7538 while( pEntry )
7539 {
7540 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
7541 if ( 1 != pChannelSet->interChannelOffset )
7542 {
7543 // we keep the 5G channel sets internally with an interchannel offset of 4. Expand these
7544 // to the right format... (inter channel offset of 1 is the only option for the triplets
7545 // that 11d advertises.
7546 if ((cbLen + (pChannelSet->numChannels * sizeof(tSirMacChanInfo))) >= dataLen)
7547 {
7548 // expanding this entry will overflow our allocation
7549 smsLog(pMac, LOGE,
7550 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007551 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07007552 pChannelSet->firstChannel,
7553 pChannelSet->numChannels,
7554 pChannelSet->interChannelOffset);
7555 break;
7556 }
7557
7558 for( idx = 0; idx < pChannelSet->numChannels; idx++ )
7559 {
7560 pChannelPowerSet->firstChanNum = (tSirMacChanNum)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08007561 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07007562 pChannelPowerSet->numChannels = 1;
Jeff Johnson295189b2012-06-20 16:38:30 -07007563 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08007564 smsLog(pMac, LOG3, " Setting Max Transmit Power %d", pChannelPowerSet->maxTxPower);
Jeff Johnson295189b2012-06-20 16:38:30 -07007565 cbLen += sizeof( tSirMacChanInfo );
7566 pChannelPowerSet++;
7567 }
7568 }
7569 else
7570 {
7571 if (cbLen >= dataLen)
7572 {
7573 // this entry will overflow our allocation
7574 smsLog(pMac, LOGE,
7575 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007576 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07007577 pChannelSet->firstChannel,
7578 pChannelSet->numChannels,
7579 pChannelSet->interChannelOffset);
7580 break;
7581 }
7582 pChannelPowerSet->firstChanNum = pChannelSet->firstChannel;
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08007583 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07007584 pChannelPowerSet->numChannels = pChannelSet->numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -07007585 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08007586 smsLog(pMac, LOG3, " Setting Max Transmit Power %d, nTxPower %d", pChannelPowerSet->maxTxPower,pMac->roam.configParam.nTxPowerCap );
Jeff Johnson295189b2012-06-20 16:38:30 -07007587
7588
7589 cbLen += sizeof( tSirMacChanInfo );
7590 pChannelPowerSet++;
7591 }
7592
7593 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
7594 }
7595
7596 if(cbLen)
7597 {
7598 ccmCfgSetStr(pMac, cfgId, (tANI_U8 *)pBuf, cbLen, NULL, eANI_BOOLEAN_FALSE);
7599 }
Kiet Lam3cac75e2013-07-12 13:56:44 +05307600 vos_mem_free(pBuf);
Jeff Johnson295189b2012-06-20 16:38:30 -07007601 }//Allocate memory
7602}
7603
7604
7605void csrSetCfgCountryCode( tpAniSirGlobal pMac, tANI_U8 *countryCode )
7606{
7607 tANI_U8 cc[WNI_CFG_COUNTRY_CODE_LEN];
7608 ///v_REGDOMAIN_t DomainId;
7609
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08007610 smsLog( pMac, LOG3, "Setting Country Code in Cfg from csrSetCfgCountryCode %s",countryCode );
Kiet Lam3cac75e2013-07-12 13:56:44 +05307611 vos_mem_copy(cc, countryCode, WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07007612
7613 // don't program the bogus country codes that we created for Korea in the MAC. if we see
7614 // the bogus country codes, program the MAC with the right country code.
7615 if ( ( 'K' == countryCode[ 0 ] && '1' == countryCode[ 1 ] ) ||
7616 ( 'K' == countryCode[ 0 ] && '2' == countryCode[ 1 ] ) ||
7617 ( 'K' == countryCode[ 0 ] && '3' == countryCode[ 1 ] ) ||
7618 ( 'K' == countryCode[ 0 ] && '4' == countryCode[ 1 ] ) )
7619 {
7620 // replace the alternate Korea country codes, 'K1', 'K2', .. with 'KR' for Korea
7621 cc[ 1 ] = 'R';
7622 }
7623 ccmCfgSetStr(pMac, WNI_CFG_COUNTRY_CODE, cc, WNI_CFG_COUNTRY_CODE_LEN, NULL, eANI_BOOLEAN_FALSE);
7624
7625 //Need to let HALPHY know about the current domain so it can apply some
7626 //domain-specific settings (TX filter...)
7627 /*if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(pMac, cc, &DomainId)))
7628 {
7629 halPhySetRegDomain(pMac, DomainId);
7630 }*/
7631}
7632
7633
7634
7635eHalStatus csrGetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pBuf, tANI_U8 *pbLen)
7636{
7637 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
7638 tANI_U32 len;
7639
7640 if(pBuf && pbLen && (*pbLen >= WNI_CFG_COUNTRY_CODE_LEN))
7641 {
7642 len = *pbLen;
7643 status = ccmCfgGetStr(pMac, WNI_CFG_COUNTRY_CODE, pBuf, &len);
7644 if(HAL_STATUS_SUCCESS(status))
7645 {
7646 *pbLen = (tANI_U8)len;
7647 }
7648 }
7649
7650 return (status);
7651}
7652
7653
7654void csrSetCfgScanControlList( tpAniSirGlobal pMac, tANI_U8 *countryCode, tCsrChannel *pChannelList )
7655{
7656 tANI_U8 i, j;
7657 tANI_BOOLEAN found=FALSE;
7658 tANI_U8 *pControlList = NULL;
7659 tANI_U32 len = WNI_CFG_SCAN_CONTROL_LIST_LEN;
7660
Kiet Lam3cac75e2013-07-12 13:56:44 +05307661 if ( (pControlList = vos_mem_malloc(WNI_CFG_SCAN_CONTROL_LIST_LEN)) != NULL )
Jeff Johnson295189b2012-06-20 16:38:30 -07007662 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05307663 vos_mem_set((void *)pControlList, WNI_CFG_SCAN_CONTROL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007664 if(HAL_STATUS_SUCCESS(ccmCfgGetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, &len)))
7665 {
7666 for (i = 0; i < pChannelList->numChannels; i++)
7667 {
7668 for (j = 0; j < len; j += 2)
7669 {
7670 if (pControlList[j] == pChannelList->channelList[i])
7671 {
7672 found = TRUE;
7673 break;
7674 }
7675 }
7676
7677 if (found) // insert a pair(channel#, flag)
7678 {
Gopichand Nakkala21d0a6d2013-05-28 16:15:00 +05307679 pControlList[j+1] = csrGetScanType(pMac, pControlList[j]);
Jeff Johnson295189b2012-06-20 16:38:30 -07007680 found = FALSE; // reset the flag
7681 }
7682
7683 }
7684
7685 ccmCfgSetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, len, NULL, eANI_BOOLEAN_FALSE);
7686 }//Successfully getting scan control list
Kiet Lam3cac75e2013-07-12 13:56:44 +05307687 vos_mem_free(pControlList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007688 }//AllocateMemory
7689}
7690
7691
7692//if bgPeriod is 0, background scan is disabled. It is in millisecond units
7693eHalStatus csrSetCfgBackgroundScanPeriod(tpAniSirGlobal pMac, tANI_U32 bgPeriod)
7694{
7695 return (ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, bgPeriod, (tCcmCfgSetCallback) csrScanCcmCfgSetCallback, eANI_BOOLEAN_FALSE));
7696}
7697
7698
7699void csrScanCcmCfgSetCallback(tHalHandle hHal, tANI_S32 result)
7700{
7701 tListElem *pEntry = NULL;
7702 tSmeCmd *pCommand = NULL;
7703 tpAniSirGlobal pMac = PMAC_STRUCT( hHal );
Madan Mohan Koyyalamudi1dae9082013-08-01 18:00:25 +05307704 tDblLinkList *pCmdList ;
7705
7706 if (!pMac->fScanOffload)
7707 pCmdList = &pMac->sme.smeCmdActiveList;
7708 else
7709 pCmdList = &pMac->sme.smeScanCmdActiveList;
7710
7711 pEntry = csrLLPeekHead( pCmdList, LL_ACCESS_LOCK );
Jeff Johnson295189b2012-06-20 16:38:30 -07007712 if ( pEntry )
7713 {
7714 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7715 if ( eSmeCommandScan == pCommand->command )
7716 {
7717 eCsrScanStatus scanStatus = (CCM_IS_RESULT_SUCCESS(result)) ? eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
7718 csrReleaseScanCommand(pMac, pCommand, scanStatus);
7719 }
7720 else
7721 {
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08007722 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
Jeff Johnson295189b2012-06-20 16:38:30 -07007723 }
7724 }
7725 smeProcessPendingQueue( pMac );
7726}
7727
7728eHalStatus csrProcessSetBGScanParam(tpAniSirGlobal pMac, tSmeCmd *pCommand)
7729{
7730 eHalStatus status;
7731 tCsrBGScanRequest *pScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
7732 tANI_U32 dataLen = sizeof( tANI_U8 ) * pScanReq->ChannelInfo.numOfChannels;
7733
7734 //***setcfg for background scan channel list
7735 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MINIMUM_CHANNEL_TIME, pScanReq->minChnTime, NULL, eANI_BOOLEAN_FALSE);
7736 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MAXIMUM_CHANNEL_TIME, pScanReq->maxChnTime, NULL, eANI_BOOLEAN_FALSE);
7737 //Not set the background scan interval if not connected because bd scan should not be run if not connected
7738 if(!csrIsAllSessionDisconnected(pMac))
7739 {
7740 //If disbaling BG scan here, we need to stop aging as well
7741 if(pScanReq->scanInterval == 0)
7742 {
7743 //Stop aging because no new result is coming in
7744 csrScanStopResultAgingTimer(pMac);
7745 }
7746
7747#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
7748 {
7749 vos_log_scan_pkt_type *pScanLog = NULL;
7750
7751 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
7752 if(pScanLog)
7753 {
7754 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
7755 pScanLog->minChnTime = (v_U8_t)pScanReq->minChnTime;
7756 pScanLog->maxChnTime = (v_U8_t)pScanReq->maxChnTime;
7757 pScanLog->timeBetweenBgScan = (v_U8_t)pScanReq->scanInterval;
7758 pScanLog->numChannel = pScanReq->ChannelInfo.numOfChannels;
7759 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
7760 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05307761 vos_mem_copy(pScanLog->channels,
7762 pScanReq->ChannelInfo.ChannelList,
7763 pScanLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07007764 }
7765 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
7766 }
7767 }
7768#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
7769
7770 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, pScanReq->scanInterval, NULL, eANI_BOOLEAN_FALSE);
7771 }
7772 else
7773 {
7774 //No need to stop aging because IDLE scan is still running
7775 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, 0, NULL, eANI_BOOLEAN_FALSE);
7776 }
7777
7778 if(pScanReq->SSID.length > WNI_CFG_SSID_LEN)
7779 {
7780 pScanReq->SSID.length = WNI_CFG_SSID_LEN;
7781 }
7782
7783 status = ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pScanReq->ChannelInfo.ChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
7784 status = ccmCfgSetStr(pMac, WNI_CFG_SSID, (tANI_U8 *)pScanReq->SSID.ssId, pScanReq->SSID.length, NULL, eANI_BOOLEAN_FALSE);
7785
7786
7787
7788 return (status);
7789}
7790
7791
Madan Mohan Koyyalamudi78f17402013-06-13 14:47:55 +05307792eHalStatus csrScanAbortMacScan(tpAniSirGlobal pMac, tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07007793{
Madan Mohan Koyyalamudi78f17402013-06-13 14:47:55 +05307794 eHalStatus status = eHAL_STATUS_FAILURE;
7795 tSirSmeScanAbortReq *pMsg;
Jeff Johnson295189b2012-06-20 16:38:30 -07007796 tANI_U16 msgLen;
7797 tListElem *pEntry;
7798 tSmeCmd *pCommand;
7799
Madan Mohan Koyyalamudi78f17402013-06-13 14:47:55 +05307800 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07007801 {
Madan Mohan Koyyalamudi78f17402013-06-13 14:47:55 +05307802#ifdef WLAN_AP_STA_CONCURRENCY
7803 csrLLLock(&pMac->scan.scanCmdPendingList);
7804 while(NULL !=
7805 (pEntry = csrLLRemoveHead(&pMac->scan.scanCmdPendingList,
7806 LL_ACCESS_NOLOCK)))
7807 {
Jeff Johnson295189b2012-06-20 16:38:30 -07007808
Madan Mohan Koyyalamudi78f17402013-06-13 14:47:55 +05307809 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7810 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
7811 }
7812 csrLLUnlock(&pMac->scan.scanCmdPendingList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007813#endif
7814
Madan Mohan Koyyalamudi78f17402013-06-13 14:47:55 +05307815 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
7816 csrRemoveCmdFromPendingList( pMac, &pMac->roam.roamCmdPendingList, eSmeCommandScan);
7817 csrRemoveCmdFromPendingList( pMac, &pMac->sme.smeCmdPendingList, eSmeCommandScan);
7818 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
7819
7820 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
7821 }
7822 else
7823 {
7824 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
7825 csrRemoveCmdWithSessionIdFromPendingList(pMac,
7826 sessionId,
7827 &pMac->sme.smeScanCmdPendingList,
7828 eSmeCommandScan);
7829 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
7830
7831 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
7832 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007833
7834 //We need to abort scan only if we are scanning
Madan Mohan Koyyalamudi78f17402013-06-13 14:47:55 +05307835 if(NULL != pEntry)
Jeff Johnson295189b2012-06-20 16:38:30 -07007836 {
7837 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
Madan Mohan Koyyalamudi78f17402013-06-13 14:47:55 +05307838 if(eSmeCommandScan == pCommand->command &&
7839 pCommand->sessionId == sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07007840 {
Madan Mohan Koyyalamudi78f17402013-06-13 14:47:55 +05307841 msgLen = (tANI_U16)(sizeof(tSirSmeScanAbortReq));
Kiet Lam3cac75e2013-07-12 13:56:44 +05307842 pMsg = vos_mem_malloc(msgLen);
7843 if ( NULL == pMsg )
Jeff Johnson295189b2012-06-20 16:38:30 -07007844 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05307845 status = eHAL_STATUS_FAILURE;
7846 smsLog(pMac, LOGE, FL("Failed to allocate memory for SmeScanAbortReq"));
7847 }
7848 else
7849 {
7850 vos_mem_set((void *)pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007851 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_ABORT_IND);
7852 pMsg->msgLen = pal_cpu_to_be16(msgLen);
Madan Mohan Koyyalamudi78f17402013-06-13 14:47:55 +05307853 pMsg->sessionId = sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07007854 status = palSendMBMessage(pMac->hHdd, pMsg);
7855 }
7856 }
7857 }
7858
Madan Mohan Koyyalamudi78f17402013-06-13 14:47:55 +05307859 return(status);
7860}
7861
7862void csrRemoveCmdWithSessionIdFromPendingList(tpAniSirGlobal pMac,
7863 tANI_U8 sessionId,
7864 tDblLinkList *pList,
7865 eSmeCommandType commandType)
7866{
7867 tDblLinkList localList;
7868 tListElem *pEntry;
7869 tSmeCmd *pCommand;
7870 tListElem *pEntryToRemove;
7871
7872 vos_mem_zero(&localList, sizeof(tDblLinkList));
7873 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
7874 {
7875 smsLog(pMac, LOGE, FL(" failed to open list"));
7876 return;
7877 }
7878
7879 csrLLLock(pList);
7880 if ((pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK)))
7881 {
7882
7883 /* Have to make sure we don't loop back to the head of the list,
7884 * which will happen if the entry is NOT on the list */
7885 while (pEntry)
7886 {
7887 pEntryToRemove = pEntry;
7888 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
7889 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
7890 if ((pCommand->command == commandType) &&
7891 (pCommand->sessionId == sessionId))
7892 {
7893 /* Remove that entry only */
7894 if (csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
7895 {
7896 csrLLInsertTail(&localList, pEntryToRemove,
7897 LL_ACCESS_NOLOCK);
7898 }
7899 }
7900 }
7901 }
7902 csrLLUnlock(pList);
7903
7904 while ((pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)))
7905 {
7906 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7907 csrAbortCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
7908 }
7909
7910 csrLLClose(&localList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007911}
7912
7913void csrRemoveCmdFromPendingList(tpAniSirGlobal pMac, tDblLinkList *pList,
7914 eSmeCommandType commandType )
7915{
7916 tDblLinkList localList;
7917 tListElem *pEntry;
7918 tSmeCmd *pCommand;
7919 tListElem *pEntryToRemove;
7920
7921 vos_mem_zero(&localList, sizeof(tDblLinkList));
7922 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
7923 {
7924 smsLog(pMac, LOGE, FL(" failed to open list"));
7925 return;
7926 }
7927
7928 csrLLLock(pList);
7929 if( !csrLLIsListEmpty( pList, LL_ACCESS_NOLOCK ) )
7930 {
7931 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK);
7932
7933 // Have to make sure we don't loop back to the head of the list, which will
7934 // happen if the entry is NOT on the list...
7935 while( pEntry )
7936 {
7937 pEntryToRemove = pEntry;
7938 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
7939 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
7940 if ( pCommand->command == commandType )
7941 {
7942 // Remove that entry only
7943 if(csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
7944 {
7945 csrLLInsertTail(&localList, pEntryToRemove, LL_ACCESS_NOLOCK);
7946 }
7947 }
7948 }
7949
7950
7951 }
7952 csrLLUnlock(pList);
7953
7954 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
7955 {
7956 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7957 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
7958 }
7959 csrLLClose(&localList);
7960
7961}
7962
7963
Madan Mohan Koyyalamudi78f17402013-06-13 14:47:55 +05307964eHalStatus csrScanAbortMacScanNotForConnect(tpAniSirGlobal pMac,
7965 tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07007966{
7967 eHalStatus status = eHAL_STATUS_SUCCESS;
7968
7969 if( !csrIsScanForRoamCommandActive( pMac ) )
7970 {
7971 //Only abort the scan if it is not used for other roam/connect purpose
Madan Mohan Koyyalamudi78f17402013-06-13 14:47:55 +05307972 status = csrScanAbortMacScan(pMac, sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07007973 }
7974
7975 return (status);
7976}
7977
7978
Madan Mohan Koyyalamudi762dc6f2013-07-12 00:56:04 +05307979eHalStatus csrScanGetScanChannelInfo(tpAniSirGlobal pMac, tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07007980{
7981 eHalStatus status = eHAL_STATUS_SUCCESS;
7982 tSirMbMsg *pMsg;
7983 tANI_U16 msgLen;
7984
Madan Mohan Koyyalamudi762dc6f2013-07-12 00:56:04 +05307985 if (pMac->fScanOffload)
7986 msgLen = (tANI_U16)(sizeof(tSirSmeGetScanChanReq));
7987 else
7988 msgLen = (tANI_U16)(sizeof(tSirMbMsg));
7989
Kiet Lam3cac75e2013-07-12 13:56:44 +05307990 pMsg = vos_mem_malloc(msgLen);
7991 if ( NULL == pMsg )
7992 status = eHAL_STATUS_FAILURE;
7993 else
Jeff Johnson295189b2012-06-20 16:38:30 -07007994 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05307995 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007996 pMsg->type = eWNI_SME_GET_SCANNED_CHANNEL_REQ;
7997 pMsg->msgLen = msgLen;
Madan Mohan Koyyalamudi762dc6f2013-07-12 00:56:04 +05307998 if (pMac->fScanOffload)
7999 ((tSirSmeGetScanChanReq *)pMsg)->sessionId = sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07008000 status = palSendMBMessage(pMac->hHdd, pMsg);
8001 }
8002
8003 return( status );
8004}
8005
8006tANI_BOOLEAN csrRoamIsValidChannel( tpAniSirGlobal pMac, tANI_U8 channel )
8007{
8008 tANI_BOOLEAN fValid = FALSE;
8009 tANI_U32 idxValidChannels;
8010 tANI_U32 len = pMac->roam.numValidChannels;
8011
8012 for ( idxValidChannels = 0; ( idxValidChannels < len ); idxValidChannels++ )
8013 {
8014 if ( channel == pMac->roam.validChannelList[ idxValidChannels ] )
8015 {
8016 fValid = TRUE;
8017 break;
8018 }
8019 }
8020
8021 return fValid;
8022}
8023
Manjunathappa Prakash232111c2013-11-11 16:22:19 -08008024#ifdef FEATURE_WLAN_SCAN_PNO
Srikant Kuppa0f679052013-05-07 13:56:02 -07008025eHalStatus csrScanSavePreferredNetworkFound(tpAniSirGlobal pMac,
8026 tSirPrefNetworkFoundInd *pPrefNetworkFoundInd)
8027{
8028 v_U32_t uLen = 0;
8029 tpSirProbeRespBeacon pParsedFrame;
8030 tCsrScanResult *pScanResult = NULL;
8031 tSirBssDescription *pBssDescr = NULL;
8032 tANI_BOOLEAN fDupBss;
8033 tDot11fBeaconIEs *pIesLocal = NULL;
8034 tAniSSID tmpSsid;
8035 v_TIME_t timer=0;
8036 tpSirMacMgmtHdr macHeader = (tpSirMacMgmtHdr)pPrefNetworkFoundInd->data;
8037
8038 pParsedFrame =
Kiet Lam3cac75e2013-07-12 13:56:44 +05308039 (tpSirProbeRespBeacon)vos_mem_malloc(sizeof(tSirProbeRespBeacon));
Srikant Kuppa0f679052013-05-07 13:56:02 -07008040
8041 if (NULL == pParsedFrame)
8042 {
8043 smsLog(pMac, LOGE, FL(" fail to allocate memory for frame"));
8044 return eHAL_STATUS_RESOURCES;
8045 }
8046
8047 if ( pPrefNetworkFoundInd->frameLength <= SIR_MAC_HDR_LEN_3A )
8048 {
8049 smsLog(pMac, LOGE,
8050 FL("Not enough bytes in PNO indication probe resp frame! length=%d"),
8051 pPrefNetworkFoundInd->frameLength);
8052 vos_mem_free(pParsedFrame);
8053 return eHAL_STATUS_FAILURE;
8054 }
8055
8056 if (sirConvertProbeFrame2Struct(pMac,
8057 &pPrefNetworkFoundInd->data[SIR_MAC_HDR_LEN_3A],
8058 pPrefNetworkFoundInd->frameLength - SIR_MAC_HDR_LEN_3A,
8059 pParsedFrame) != eSIR_SUCCESS ||
8060 !pParsedFrame->ssidPresent)
8061 {
8062 smsLog(pMac, LOGE,
8063 FL("Parse error ProbeResponse, length=%d"),
8064 pPrefNetworkFoundInd->frameLength);
8065 vos_mem_free(pParsedFrame);
8066 return eHAL_STATUS_FAILURE;
8067 }
8068 //24 byte MAC header and 12 byte to ssid IE
8069 if (pPrefNetworkFoundInd->frameLength >
8070 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET))
8071 {
8072 uLen = pPrefNetworkFoundInd->frameLength -
8073 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET);
8074 }
8075
Kiet Lam3cac75e2013-07-12 13:56:44 +05308076 pScanResult = vos_mem_malloc(sizeof(tCsrScanResult) + uLen);
8077 if ( NULL == pScanResult )
Srikant Kuppa0f679052013-05-07 13:56:02 -07008078 {
8079 smsLog(pMac, LOGE, FL(" fail to allocate memory for frame"));
8080 vos_mem_free(pParsedFrame);
8081 return eHAL_STATUS_RESOURCES;
8082 }
8083
Kiet Lam3cac75e2013-07-12 13:56:44 +05308084 vos_mem_set(pScanResult, sizeof(tCsrScanResult) + uLen, 0);
Srikant Kuppa0f679052013-05-07 13:56:02 -07008085 pBssDescr = &pScanResult->Result.BssDescriptor;
8086 /**
8087 * Length of BSS desription is without length of
8088 * length itself and length of pointer
8089 * that holds the next BSS description
8090 */
8091 pBssDescr->length = (tANI_U16)(
8092 sizeof(tSirBssDescription) - sizeof(tANI_U16) -
8093 sizeof(tANI_U32) + uLen);
8094 if (pParsedFrame->dsParamsPresent)
8095 {
8096 pBssDescr->channelId = pParsedFrame->channelNumber;
8097 }
8098 else if (pParsedFrame->HTInfo.present)
8099 {
8100 pBssDescr->channelId = pParsedFrame->HTInfo.primaryChannel;
8101 }
8102 else
8103 {
8104 pBssDescr->channelId = pParsedFrame->channelNumber;
8105 }
8106
8107 if ((pBssDescr->channelId > 0) && (pBssDescr->channelId < 15))
8108 {
8109 int i;
8110 // 11b or 11g packet
8111 // 11g iff extended Rate IE is present or
8112 // if there is an A rate in suppRate IE
8113 for (i = 0; i < pParsedFrame->supportedRates.numRates; i++)
8114 {
8115 if (sirIsArate(pParsedFrame->supportedRates.rate[i] & 0x7f))
8116 {
8117 pBssDescr->nwType = eSIR_11G_NW_TYPE;
8118 break;
8119 }
8120 }
8121 if (pParsedFrame->extendedRatesPresent)
8122 {
8123 pBssDescr->nwType = eSIR_11G_NW_TYPE;
8124 }
8125 }
8126 else
8127 {
8128 // 11a packet
8129 pBssDescr->nwType = eSIR_11A_NW_TYPE;
8130 }
8131
8132 pBssDescr->sinr = 0;
8133 pBssDescr->rssi = -1 * pPrefNetworkFoundInd->rssi;
8134 pBssDescr->beaconInterval = pParsedFrame->beaconInterval;
8135 pBssDescr->timeStamp[0] = pParsedFrame->timeStamp[0];
8136 pBssDescr->timeStamp[1] = pParsedFrame->timeStamp[1];
8137 pBssDescr->capabilityInfo = *((tANI_U16 *)&pParsedFrame->capabilityInfo);
Kiet Lam3cac75e2013-07-12 13:56:44 +05308138 vos_mem_copy((tANI_U8 *) &pBssDescr->bssId, (tANI_U8 *) macHeader->bssId, sizeof(tSirMacAddr));
Srikant Kuppa0f679052013-05-07 13:56:02 -07008139 pBssDescr->nReceivedTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
8140
Arif Hussain8c303d82013-11-15 15:10:03 -08008141 smsLog( pMac, LOG2, "(%s):Bssid= "MAC_ADDRESS_STR
8142 " chan= %d, rssi = %d", __func__,
8143 MAC_ADDR_ARRAY(pBssDescr->bssId),
Srikant Kuppa0f679052013-05-07 13:56:02 -07008144 pBssDescr->channelId,
8145 pBssDescr->rssi );
8146
8147 //IEs
8148 if (uLen)
8149 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05308150 vos_mem_copy(&pBssDescr->ieFields,
8151 pPrefNetworkFoundInd->data + (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET),
8152 uLen);
Srikant Kuppa0f679052013-05-07 13:56:02 -07008153 }
8154
8155 pIesLocal = (tDot11fBeaconIEs *)( pScanResult->Result.pvIes );
8156 if ( !pIesLocal &&
8157 (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
8158 &pScanResult->Result.BssDescriptor, &pIesLocal))) )
8159 {
8160 smsLog(pMac, LOGE, FL(" Cannot parse IEs"));
8161 csrFreeScanResultEntry(pMac, pScanResult);
8162 vos_mem_free(pParsedFrame);
8163 return eHAL_STATUS_RESOURCES;
8164 }
8165
8166 fDupBss = csrRemoveDupBssDescription( pMac,
Madan Mohan Koyyalamudi0dea29e2013-07-11 12:01:37 +05308167 &pScanResult->Result.BssDescriptor, pIesLocal, &tmpSsid, &timer, FALSE);
Srikant Kuppa0f679052013-05-07 13:56:02 -07008168 //Check whether we have reach out limit
8169 if ( CSR_SCAN_IS_OVER_BSS_LIMIT(pMac) )
8170 {
8171 //Limit reach
8172 smsLog(pMac, LOGE, FL(" BSS limit reached"));
8173 //Free the resources
8174 if( (pScanResult->Result.pvIes == NULL) && pIesLocal )
8175 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05308176 vos_mem_free(pIesLocal);
Srikant Kuppa0f679052013-05-07 13:56:02 -07008177 }
8178 csrFreeScanResultEntry(pMac, pScanResult);
8179 vos_mem_free(pParsedFrame);
8180 return eHAL_STATUS_RESOURCES;
8181 }
8182 //Add to scan cache
8183 csrScanAddResult(pMac, pScanResult, pIesLocal);
8184
Kiet Lam8a1c4fe2013-11-07 12:56:49 +05308185 if( (pScanResult->Result.pvIes == NULL) && pIesLocal )
8186 {
8187 vos_mem_free(pIesLocal);
8188 }
8189
Srikant Kuppa0f679052013-05-07 13:56:02 -07008190 vos_mem_free(pParsedFrame);
8191
8192 return eHAL_STATUS_SUCCESS;
8193}
Manjunathappa Prakash232111c2013-11-11 16:22:19 -08008194#endif //FEATURE_WLAN_SCAN_PNO
Srikant Kuppa0f679052013-05-07 13:56:02 -07008195
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008196#ifdef FEATURE_WLAN_LFR
8197void csrInitOccupiedChannelsList(tpAniSirGlobal pMac)
8198{
8199 tListElem *pEntry = NULL;
8200 tCsrScanResult *pBssDesc = NULL;
8201 tDot11fBeaconIEs *pIes = NULL;
Madan Mohan Koyyalamudi2bb99ef2012-12-12 13:07:53 -08008202 tpCsrNeighborRoamControlInfo pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
8203
8204 if (0 != pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels)
8205 {
8206 smsLog(pMac, LOG1, FL("%s: Ini file contains neighbor scan channel list,"
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08008207 " hence NO need to build occupied channel list (numChannels = %d)"),
Madan Mohan Koyyalamudi2bb99ef2012-12-12 13:07:53 -08008208 __func__, pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels);
8209 return;
8210 }
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008211
8212 if (!csrNeighborRoamIsNewConnectedProfile(pMac))
8213 {
8214 smsLog(pMac, LOG2, FL("%s: donot flush occupied list since current roam profile"
Kiran Kumar Lokere4bccb762013-03-07 12:36:05 -08008215 " matches previous (numChannels = %d)"),
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008216 __func__, pMac->scan.occupiedChannels.numChannels);
8217 return;
8218 }
8219
8220 /* Empty occupied channels here */
8221 pMac->scan.occupiedChannels.numChannels = 0;
8222
8223 csrLLLock(&pMac->scan.scanResultList);
8224 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
8225 while( pEntry )
8226 {
8227 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
8228 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
8229
8230 //At this time, pBssDescription->Result.pvIes may be NULL
Madan Mohan Koyyalamudi91482b82012-12-27 17:28:14 -08008231 if( !pIes && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008232 &pBssDesc->Result.BssDescriptor, &pIes))) )
8233 {
8234 continue;
8235 }
8236
8237 csrScanAddToOccupiedChannels(pMac, pBssDesc, &pMac->scan.occupiedChannels, pIes);
8238
8239 /*
8240 * Free the memory allocated for pIes in csrGetParsedBssDescriptionIEs
8241 */
8242 if( (pBssDesc->Result.pvIes == NULL) && pIes )
8243 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05308244 vos_mem_free(pIes);
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008245 }
8246
8247 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK );
8248 }//while
8249 csrLLUnlock(&pMac->scan.scanResultList);
Madan Mohan Koyyalamudi91482b82012-12-27 17:28:14 -08008250
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008251}
8252#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07008253
Varun Reddy Yeturu2c35a7d2013-05-20 11:47:10 -07008254eHalStatus csrScanCreateEntryInScanCache(tpAniSirGlobal pMac, tANI_U32 sessionId,
8255 tCsrBssid bssid, tANI_U8 channel)
8256{
8257 eHalStatus status = eHAL_STATUS_SUCCESS;
8258 tDot11fBeaconIEs *pNewIes = NULL;
8259 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
Praveen Kumar Sirisillae13d46e2013-10-10 17:20:48 -07008260 tSirBssDescription *pNewBssDescriptor = NULL;
Varun Reddy Yeturu2c35a7d2013-05-20 11:47:10 -07008261 tANI_U32 size = 0;
8262
8263 if(NULL == pSession)
8264 {
8265 status = eHAL_STATUS_FAILURE;
8266 return status;
8267 }
8268 smsLog(pMac, LOG2, FL("csrScanCreateEntryInScanCache: Current bssid::"
Arif Hussain8c303d82013-11-15 15:10:03 -08008269 MAC_ADDRESS_STR),
8270 MAC_ADDR_ARRAY(pSession->pConnectBssDesc->bssId));
Varun Reddy Yeturu2c35a7d2013-05-20 11:47:10 -07008271 smsLog(pMac, LOG2, FL("csrScanCreateEntryInScanCache: My bssid::"
Arif Hussain8c303d82013-11-15 15:10:03 -08008272 MAC_ADDRESS_STR" channel %d"),
8273 MAC_ADDR_ARRAY(bssid), channel);
Varun Reddy Yeturu2c35a7d2013-05-20 11:47:10 -07008274
8275 do
8276 {
8277 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
8278 pSession->pConnectBssDesc, &pNewIes)))
8279 {
8280 smsLog(pMac, LOGE, FL("%s: Failed to parse IEs"),
8281 __func__);
8282 status = eHAL_STATUS_FAILURE;
8283 break;
8284 }
8285
8286 size = pSession->pConnectBssDesc->length + sizeof(pSession->pConnectBssDesc->length);
Kiet Lam3cac75e2013-07-12 13:56:44 +05308287 if (size)
Varun Reddy Yeturu2c35a7d2013-05-20 11:47:10 -07008288 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05308289 pNewBssDescriptor = vos_mem_malloc(size);
8290 if ( NULL == pNewBssDescriptor )
8291 status = eHAL_STATUS_FAILURE;
8292 else
8293 status = eHAL_STATUS_SUCCESS;
8294 if (HAL_STATUS_SUCCESS(status))
Varun Reddy Yeturu2c35a7d2013-05-20 11:47:10 -07008295 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05308296 vos_mem_copy(pNewBssDescriptor, pSession->pConnectBssDesc, size);
Varun Reddy Yeturu2c35a7d2013-05-20 11:47:10 -07008297 }
8298 else
8299 {
8300 smsLog(pMac, LOGE, FL("%s: memory allocation failed"),
8301 __func__);
8302 status = eHAL_STATUS_FAILURE;
8303 break;
8304 }
8305
8306 //change the BSSID & channel as passed
Kiet Lam3cac75e2013-07-12 13:56:44 +05308307 vos_mem_copy(pNewBssDescriptor->bssId, bssid, sizeof(tSirMacAddr));
Varun Reddy Yeturu2c35a7d2013-05-20 11:47:10 -07008308 pNewBssDescriptor->channelId = channel;
Tushnim Bhattacharyya4207db02013-06-26 23:23:18 -07008309 if(NULL == csrScanAppendBssDescription( pMac, pNewBssDescriptor, pNewIes, TRUE ))
Varun Reddy Yeturu2c35a7d2013-05-20 11:47:10 -07008310 {
Tushnim Bhattacharyya4207db02013-06-26 23:23:18 -07008311 smsLog(pMac, LOGE, FL("%s: csrScanAppendBssDescription failed"),
Varun Reddy Yeturu2c35a7d2013-05-20 11:47:10 -07008312 __func__);
8313 status = eHAL_STATUS_FAILURE;
8314 break;
8315 }
8316 }
8317 else
8318 {
8319 smsLog(pMac, LOGE, FL("%s: length of bss descriptor is 0"),
8320 __func__);
8321 status = eHAL_STATUS_FAILURE;
8322 break;
8323 }
8324 smsLog(pMac, LOGE, FL("%s: entry successfully added in scan cache"),
8325 __func__);
8326 }while(0);
8327
8328 if(pNewIes)
8329 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05308330 vos_mem_free(pNewIes);
Varun Reddy Yeturu2c35a7d2013-05-20 11:47:10 -07008331 }
8332 if(pNewBssDescriptor)
8333 {
Kiet Lam3cac75e2013-07-12 13:56:44 +05308334 vos_mem_free(pNewBssDescriptor);
Varun Reddy Yeturu2c35a7d2013-05-20 11:47:10 -07008335 }
8336 return status;
8337}
Srinivas Girigowda6b8b47c2013-10-08 09:13:25 -07008338
8339#ifdef FEATURE_WLAN_CCX
8340// Update the TSF with the difference in system time
8341void UpdateCCKMTSF(tANI_U32 *timeStamp0, tANI_U32 *timeStamp1, tANI_U32 *incr)
8342{
8343 tANI_U64 timeStamp64 = ((tANI_U64)*timeStamp1 << 32) | (*timeStamp0);
8344
8345 timeStamp64 = (tANI_U64)(timeStamp64 + (tANI_U64)*incr);
8346 *timeStamp0 = (tANI_U32)(timeStamp64 & 0xffffffff);
8347 *timeStamp1 = (tANI_U32)((timeStamp64 >> 32) & 0xffffffff);
8348}
8349#endif