blob: 810fb6339c22942231503da55123f7f284e068b5 [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Gopichand Nakkala92f07d82013-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 Johnson40b59aa2013-03-19 14:43:18 -070042/** ------------------------------------------------------------------------- *
43 ------------------------------------------------------------------------- *
Jeff Johnson295189b2012-06-20 16:38:30 -070044
Jeff Johnson40b59aa2013-03-19 14:43:18 -070045
Jeff Johnson295189b2012-06-20 16:38:30 -070046 \file csrApiScan.c
Jeff Johnson40b59aa2013-03-19 14:43:18 -070047
Jeff Johnson295189b2012-06-20 16:38:30 -070048 Implementation for the Common Scan interfaces.
Jeff Johnson40b59aa2013-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 Johnson40b59aa2013-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 Lamd1f3dc82013-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 Nakkala10ba6fc2013-04-23 20:30:01 +0530120/* Maximum number of channels per country can be ignored */
121#define MAX_CHANNELS_IGNORE 10
122
Wilson Yange3d2b292013-10-09 00:35:43 -0700123#define MAX_COUNTRY_IGNORE 5
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +0530124
Agarwal Ashishd9d72602013-09-13 00:06:17 +0530125#define THIRTY_PERCENT(x) (x*30/100);
126
krunal soni5f112f02013-11-25 15:00:11 -0800127#define MANDATORY_BG_CHANNEL 11
128
Gopichand Nakkala10ba6fc2013-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 Bhattacharyya582ac1d2013-11-07 23:44:09 -0800137#ifndef CONFIG_ENABLE_LINUX_REG
Gopichand Nakkala10ba6fc2013-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 Koyyalamudi28dd0422013-08-12 15:06:21 +0530141 { {'I','D'}, { 165}, 1 },
Wilson Yange3d2b292013-10-09 00:35:43 -0700142 { {'A','U'}, { 120, 124, 128}, 3 },
Wilson Yangce31eaf2013-11-11 14:40:34 -0800143 { {'A','R'}, { 120, 124, 128}, 3 }
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +0530144 };
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -0800145#else
146static tCsrIgnoreChannels countryIgnoreList[MAX_COUNTRY_IGNORE] = { };
147#endif //CONFIG_ENABLE_LINUX_REG
Gopichand Nakkala10ba6fc2013-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 Nakkala10ba6fc2013-04-23 20:30:01 +0530152
Jeff Johnson295189b2012-06-20 16:38:30 -0700153void csrScanGetResultTimerHandler(void *);
154void csrScanResultAgingTimerHandler(void *pv);
Sandeep Puligilla2b6dc632012-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 Koyyalamudi923c1e12012-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 Lokere3334fbb2013-03-07 12:36:05 -0800197 smsLog(pMac, LOGE, FL("Error: Received command : %d"),pCommand->command);
Madan Mohan Koyyalamudi923c1e12012-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 Lam64c1b492013-07-12 13:56:44 +0530206 vos_mem_free(pResult->Result.pvIes);
Jeff Johnson295189b2012-06-20 16:38:30 -0700207 }
Kiet Lam64c1b492013-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 Johnsonafeb9582013-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 Johnsonafeb9582013-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 Koyyalamudia48c6812013-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 Lokere3334fbb2013-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 Koyyalamudia48c6812013-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 Lokere3334fbb2013-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 Koyyalamudia48c6812013-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 Lokere3334fbb2013-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 Koyyalamudia48c6812013-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 Lokere3334fbb2013-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 Koyyalamudia48c6812013-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))
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -0800350 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800351 smsLog(pMac, LOGE, FL("cannot allocate memory for CFG ResultAging timer"));
Sandeep Puligilla2b6dc632012-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 Koyyalamudi923c1e12012-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 Koyyalamudia48c6812013-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 Koyyalamudia48c6812013-07-11 12:01:37 +0530386 vos_timer_destroy(&pMac->scan.hTimerStaApConcTimer);
Jeff Johnson295189b2012-06-20 16:38:30 -0700387#endif
Madan Mohan Koyyalamudia48c6812013-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 Lam64c1b492013-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 Lam64c1b492013-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 Kohallieb97d502013-05-22 23:16:42 -0700472 tANI_U8 nNumChanCombinedConc = 0;
Gopichand Nakkala114718f2013-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 Koyyalamudi48081ef2012-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
Srikant Kuppa866893f2012-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 Koyyalamudi48081ef2012-12-04 16:49:55 -0800486 */
Sudhir Sattayappa Kohallieb97d502013-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 }
Srikant Kuppa866893f2012-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)) ||
Vinay Malekal05fdc812012-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 Lam64c1b492013-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 Lokere3334fbb2013-03-07 12:36:05 -0800521 smsLog( pMac, LOGE, FL(" Failed to get memory for channel list ") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800522 return eHAL_STATUS_FAILURE;
523 }
524 bMemAlloc = eANI_BOOLEAN_TRUE;
Kiet Lam64c1b492013-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;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800528 if( !HAL_STATUS_SUCCESS( status ) )
529 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530530 vos_mem_free(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800531 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800532 smsLog( pMac, LOGE, FL(" Failed to copy memory to channel list ") );
Vinay Malekal05fdc812012-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
Vinay Malekal05fdc812012-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 Kohallieb97d502013-05-22 23:16:42 -0700540 if ( numChn > nNumChanCombinedConc)
Vinay Malekal05fdc812012-12-17 13:04:30 -0800541 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530542 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Vinay Malekal05fdc812012-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 Lam64c1b492013-07-12 13:56:44 +0530549 vos_mem_free(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
Vinay Malekal05fdc812012-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 Lokere3334fbb2013-03-07 12:36:05 -0800553 smsLog( pMac, LOGE, FL(" Failed to get Queue command buffer") );
Vinay Malekal05fdc812012-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
Vinay Malekal05fdc812012-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
Vinay Malekal05fdc812012-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 Lam64c1b492013-07-12 13:56:44 +0530569 vos_mem_free(scanReq.ChannelInfo.ChannelList);
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -0800570 scanReq.ChannelInfo.ChannelList = NULL;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800571 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700572
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700573 pChnInfo->numOfChannels = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels - nNumChanCombinedConc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700574
Vinay Malekal05fdc812012-12-17 13:04:30 -0800575 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_WARN,
Gopichand Nakkala66c0bd02013-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 Lam64c1b492013-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));
Vinay Malekal05fdc812012-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 Koyyalamudi04a65f02013-07-26 13:58:38 +0530589 if (!pScanCmd->u.scanCmd.u.scanRequest.bcnRptReqScan)
590 scanReq.scanType = eSIR_ACTIVE_SCAN;
Vinay Malekal05fdc812012-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 Lam64c1b492013-07-12 13:56:44 +0530601 vos_mem_free(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800602 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
603
604 }
605 if( scanReq.pIEField != NULL)
606 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530607 vos_mem_free(scanReq.pIEField);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800608 scanReq.pIEField = NULL;
609 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800610 smsLog( pMac, LOGE, FL(" Failed to get copy csrScanRequest = %d"), status );
Vinay Malekal05fdc812012-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 Kohallieb97d502013-05-22 23:16:42 -0700620 pSendScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nNumChanCombinedConc;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800621 pSendScanCmd->u.scanCmd.u.scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
Madan Mohan Koyyalamudi04a65f02013-07-26 13:58:38 +0530622 if (!pSendScanCmd->u.scanCmd.u.scanRequest.bcnRptReqScan)
623 pSendScanCmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Vinay Malekal05fdc812012-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 Koyyalamudi04a65f02013-07-26 13:58:38 +0530631 if (!pSendScanCmd->u.scanCmd.u.scanRequest.bcnRptReqScan)
632 pSendScanCmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Vinay Malekal05fdc812012-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 {
Vinay Malekal05fdc812012-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 }
Vinay Malekal05fdc812012-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 }
Vinay Malekal05fdc812012-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 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800666 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700667 }
668 else
669 { //No concurrency case
Srikant Kuppa866893f2012-12-27 17:28:14 -0800670 smsLog( pMac, LOG2, FL("Queuing scan command (reason=%d, roamState=%d"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800671 " numOfChannels=%d)"),
Srikant Kuppa866893f2012-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 Johnsonb88db982012-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 Lokere3334fbb2013-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 Nakkala9b89a732012-12-31 16:31:46 -0800732 if(pScanRequest == NULL)
733 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800734 smsLog( pMac, LOGE, FL(" pScanRequest is NULL"));
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800735 VOS_ASSERT(0);
736 }
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700737
Kiet Lamd1f3dc82013-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 Ramanna6f7931c2013-12-20 09:04:12 +0530745 if(pScanRequest->SSIDs.numOfSSIDs)
Kiet Lamd1f3dc82013-11-05 20:45:04 +0530746 {
Rashmi Ramanna6f7931c2013-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 Eranna636b7bc2013-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 Ramanna6f7931c2013-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 Lamd1f3dc82013-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 Lam64c1b492013-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 Eranna636b7bc2013-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 Lokere3527f0c2013-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 Koyyalamudia48c6812013-07-11 12:01:37 +0530823 For BTC with A2DP up: Channel time = Channel time * 2, if station is not already associated.
Kiran Kumar Lokere3527f0c2013-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 Girigowdac84c57c2013-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 Eranna636b7bc2013-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 Lokere3527f0c2013-02-24 22:21:28 -0800841
Kiet Lam64c1b492013-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 Nakkala9b89a732012-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 Lokere3527f0c2013-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 Lam64c1b492013-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 Lokere3527f0c2013-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 Lam64c1b492013-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 Eranna636b7bc2013-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 Eranna636b7bc2013-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 Eranna636b7bc2013-12-18 20:49:08 +0530886
Jeff Johnson295189b2012-06-20 16:38:30 -0700887 p11dScanCmd->command = eSmeCommandScan;
Mihir Shetefc7ff5b2014-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 Koyyalamudi04a65f02013-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 Koyyalamudi04a65f02013-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 Lokere3527f0c2013-02-24 22:21:28 -0800918
Madan Mohan Koyyalamudi04a65f02013-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 Lam64c1b492013-07-12 13:56:44 +0530925 vos_mem_free(pChnInfo->ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -0700926 pChnInfo->ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -0700927
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800928 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700929 {
krunal soni5f112f02013-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 Koyyalamudie1a64b42013-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 Eranna636b7bc2013-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 Eranna636b7bc2013-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 Eranna636b7bc2013-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 Lokere3334fbb2013-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 Eranna636b7bc2013-12-18 20:49:08 +0530975 tCsrScanRequest *pTempScanReq =
976 &pScanCmd->u.scanCmd.u.scanRequest;
krunal soni5f112f02013-11-25 15:00:11 -0800977 pMac->scan.scanProfile.numOfChannels =
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +0530978 pTempScanReq->ChannelInfo.numOfChannels;
krunal soni5f112f02013-11-25 15:00:11 -0800979
Vinay Krishna Eranna636b7bc2013-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 Koyyalamudie1a64b42013-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 Eranna636b7bc2013-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 Lokere3334fbb2013-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 Lokere3334fbb2013-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 Lokere3334fbb2013-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 Eranna636b7bc2013-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 Eranna636b7bc2013-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 Eranna636b7bc2013-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 Lam64c1b492013-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 Lokere3334fbb2013-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 Lokere3334fbb2013-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 Yeturud0a3f252013-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 Lam64c1b492013-07-12 13:56:44 +05301102 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Varun Reddy Yeturud0a3f252013-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 Lam64c1b492013-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 Lokere3527f0c2013-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 Lokere3334fbb2013-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 Lokere3334fbb2013-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 Lam64c1b492013-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 Lam64c1b492013-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 Lam64c1b492013-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 Lam64c1b492013-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 Lam64c1b492013-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 Koyyalamudide1b5bc2013-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 Lam64c1b492013-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 Koyyalamudide1b5bc2013-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 Lokere3334fbb2013-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 Lokere3334fbb2013-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 Lokere3334fbb2013-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 Lokere3334fbb2013-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 Lokere3334fbb2013-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 Lokere3334fbb2013-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 Lam64c1b492013-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 Lokere3527f0c2013-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 Lam64c1b492013-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 Lam64c1b492013-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 Lam64c1b492013-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 Lam64c1b492013-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 Lam64c1b492013-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 Lam64c1b492013-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 Lam64c1b492013-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 Lokere3334fbb2013-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 Lokere3334fbb2013-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 Lam64c1b492013-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 Lokere3334fbb2013-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 Lam64c1b492013-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 Lokere3527f0c2013-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 Lam64c1b492013-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 Lam64c1b492013-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 Lam64c1b492013-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 Lam64c1b492013-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 Lokere3334fbb2013-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 Lokere3334fbb2013-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 Lam64c1b492013-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 Lokere3334fbb2013-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 Lam64c1b492013-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 Lokere3527f0c2013-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 Lam64c1b492013-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 Lokere3334fbb2013-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 Lokere3334fbb2013-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 Yeturucc661d22013-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 Yeturue3af4282013-06-07 00:56:52 -07001759 csrNeighborRoamStartLfrScan(pMac);
Varun Reddy Yeturucc661d22013-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 Lokere3334fbb2013-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 Lam64c1b492013-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 Lam64c1b492013-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 Lam64c1b492013-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 Lam64c1b492013-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 Lam64c1b492013-07-12 13:56:44 +05301824 if (pScanFilter)
Jeff Johnson295189b2012-06-20 16:38:30 -07001825 {
1826 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-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 Yeturucc661d22013-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 Yeturue3af4282013-06-07 00:56:52 -07001847 csrNeighborRoamStartLfrScan(pMac);
Varun Reddy Yeturucc661d22013-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 Lam64c1b492013-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 Lokere3334fbb2013-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 Lokere3334fbb2013-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 Lam64c1b492013-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 Lam64c1b492013-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 Lam64c1b492013-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 Lam64c1b492013-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 Lam64c1b492013-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 Lam64c1b492013-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 Hussaina7c8e412013-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 Lam64c1b492013-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 Lam64c1b492013-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 Lam64c1b492013-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 Koyyalamudid5026072012-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 Girigowda41c7c5f2013-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
Srikant Kuppa866893f2012-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(
Srikant Kuppa866893f2012-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 {
Srikant Kuppa866893f2012-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))
Srikant Kuppa866893f2012-12-27 17:28:14 -08002148 {
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002149 pOccupiedChannels->numChannels++;
Kiran Kumar Lokere3334fbb2013-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);
Srikant Kuppa866893f2012-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{
Srinivas28b5b4e2012-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 );
Srikant Kuppa866893f2012-12-27 17:28:14 -08002170#ifdef FEATURE_WLAN_LFR
Srinivas28b5b4e2012-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 Girigowda8e7e1052013-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 Girigowda41c7c5f2013-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 Girigowda8e7e1052013-11-13 18:53:14 -08002210 fMatch = FALSE;
2211
2212 if (pFilter)
2213 for(i = 0; i < pFilter->SSIDs.numOfSSIDs; i++)
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002214 {
Srinivas Girigowda8e7e1052013-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 Lamf2f201e2013-11-16 21:24:16 +05302233 vos_mem_free(pIes);
Srinivas Girigowda8e7e1052013-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 Girigowda41c7c5f2013-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 Girigowda8e7e1052013-11-13 18:53:14 -08002250 if ( -128 != pMac->scan.inScanResultBestAPRssi)
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002251 {
Srinivas Girigowda8e7e1052013-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 Girigowda41c7c5f2013-10-21 19:01:38 -07002259
Srinivas Girigowda8e7e1052013-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 Girigowda41c7c5f2013-10-21 19:01:38 -07002262
Arif Hussaina7c8e412013-11-20 11:06:42 -08002263 smsLog(pMac, LOG2, FL("BSSID("MAC_ADDRESS_STR
Jeff Johnson123ed002013-11-22 17:39:55 -08002264 ") Rssi(%d) Chnl(%d) PrefVal(%u) SSID=%.*s"),
Arif Hussaina7c8e412013-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 Girigowda8e7e1052013-11-13 18:53:14 -08002270
2271 pEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
2272 }
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002273 }
2274
2275 csrLLUnlock(&pMac->scan.scanResultList);
2276 }
2277
Kiet Lam64c1b492013-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 Girigowda41c7c5f2013-10-21 19:01:38 -07002283 if(HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07002284 {
Kiet Lam64c1b492013-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 Lam64c1b492013-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 Lam64c1b492013-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 Lokere3334fbb2013-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 Lam64c1b492013-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 Lam64c1b492013-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 Lam64c1b492013-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 Lokere3334fbb2013-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 Lam64c1b492013-07-12 13:56:44 +05302360 vos_mem_free(pNewIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07002361 }
2362 break;
2363 }
Kiet Lam64c1b492013-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 Lam64c1b492013-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 Lokere3334fbb2013-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 Lam64c1b492013-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);
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302467 eHalStatus status = eHAL_STATUS_SUCCESS;
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002468 if (isFlushDenied) {
2469 smsLog(pMac, LOGW, "%s: scan flush denied in roam state %d",
2470 __func__, isFlushDenied);
2471 return eHAL_STATUS_FAILURE;
2472 }
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302473 csrLLScanPurgeResult( pMac, &pMac->scan.tempScanResults );
2474 csrLLScanPurgeResult( pMac, &pMac->scan.scanResultList );
2475 return( status );
Jeff Johnson295189b2012-06-20 16:38:30 -07002476}
2477
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302478eHalStatus csrScanFlushSelectiveResult(tpAniSirGlobal pMac, v_BOOL_t flushP2P)
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002479{
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302480 eHalStatus status = eHAL_STATUS_SUCCESS;
2481 tListElem *pEntry,*pFreeElem;
2482 tCsrScanResult *pBssDesc;
2483 tDblLinkList *pList = &pMac->scan.scanResultList;
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002484
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302485 csrLLLock(pList);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002486
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302487 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK );
2488 while( pEntry != NULL)
2489 {
2490 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2491 if( flushP2P == vos_mem_compare( pBssDesc->Result.ssId.ssId,
2492 "DIRECT-", 7) )
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002493 {
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302494 pFreeElem = pEntry;
2495 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2496 csrLLRemoveEntry(pList, pFreeElem, LL_ACCESS_NOLOCK);
2497 csrFreeScanResultEntry( pMac, pBssDesc );
2498 continue;
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002499 }
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302500 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2501 }
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002502
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302503 csrLLUnlock(pList);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002504
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302505 return (status);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002506}
2507
Jeff Johnson295189b2012-06-20 16:38:30 -07002508/**
2509 * csrCheck11dChannel
2510 *
2511 *FUNCTION:
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302512 * This function is called from csrScanFilterResults function and
Jeff Johnson295189b2012-06-20 16:38:30 -07002513 * compare channel number with given channel list.
2514 *
2515 *LOGIC:
2516 * Check Scan result channel number with CFG channel list
2517 *
2518 *ASSUMPTIONS:
2519 *
2520 *
2521 *NOTE:
2522 *
2523 * @param channelId channel number
2524 * @param pChannelList Pointer to channel list
2525 * @param numChannels Number of channel in channel list
2526 *
2527 * @return Status
2528 */
2529
2530eHalStatus csrCheck11dChannel(tANI_U8 channelId, tANI_U8 *pChannelList, tANI_U32 numChannels)
2531{
2532 eHalStatus status = eHAL_STATUS_FAILURE;
2533 tANI_U8 i = 0;
2534
2535 for (i = 0; i < numChannels; i++)
2536 {
2537 if(pChannelList[ i ] == channelId)
2538 {
2539 status = eHAL_STATUS_SUCCESS;
2540 break;
2541 }
2542 }
2543 return status;
2544}
2545
2546/**
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302547 * csrScanFilterResults
Jeff Johnson295189b2012-06-20 16:38:30 -07002548 *
2549 *FUNCTION:
2550 * This function is called from csrApplyCountryInformation function and
2551 * filter scan result based on valid channel list number.
2552 *
2553 *LOGIC:
2554 * Get scan result from scan list and Check Scan result channel number
2555 * with 11d channel list if channel number is found in 11d channel list
2556 * then do not remove scan result entry from scan list
2557 *
2558 *ASSUMPTIONS:
2559 *
2560 *
2561 *NOTE:
2562 *
2563 * @param pMac Pointer to Global MAC structure
2564 *
2565 * @return Status
2566 */
2567
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302568eHalStatus csrScanFilterResults(tpAniSirGlobal pMac)
Jeff Johnson295189b2012-06-20 16:38:30 -07002569{
2570 eHalStatus status = eHAL_STATUS_SUCCESS;
2571 tListElem *pEntry,*pTempEntry;
2572 tCsrScanResult *pBssDesc;
2573 tANI_U32 len = sizeof(pMac->roam.validChannelList);
2574
2575 /* Get valid channels list from CFG */
2576 if (!HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac,
2577 pMac->roam.validChannelList, &len)))
2578 {
Agarwal Ashishe3cca2a2013-07-21 03:01:48 +05302579 smsLog( pMac, LOGE, "Failed to get Channel list from CFG");
Jeff Johnson295189b2012-06-20 16:38:30 -07002580 }
2581
2582 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
2583 while( pEntry )
2584 {
2585 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302586 pTempEntry = csrLLNext( &pMac->scan.scanResultList, pEntry,
Jeff Johnson295189b2012-06-20 16:38:30 -07002587 LL_ACCESS_LOCK );
2588 if(csrCheck11dChannel(pBssDesc->Result.BssDescriptor.channelId,
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302589 pMac->roam.validChannelList, len))
Jeff Johnson295189b2012-06-20 16:38:30 -07002590 {
2591 /* Remove Scan result which does not have 11d channel */
2592 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry,
2593 LL_ACCESS_LOCK ))
2594 {
2595 csrFreeScanResultEntry( pMac, pBssDesc );
2596 }
2597 }
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05302598 else
2599 {
2600 smsLog( pMac, LOG1, FL("%d is a Valid channel"),
2601 pBssDesc->Result.BssDescriptor.channelId);
2602 }
2603 pEntry = pTempEntry;
2604 }
2605
2606 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
2607 while( pEntry )
2608 {
2609 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2610 pTempEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry,
2611 LL_ACCESS_LOCK );
2612 if(csrCheck11dChannel(pBssDesc->Result.BssDescriptor.channelId,
2613 pMac->roam.validChannelList, len))
2614 {
2615 /* Remove Scan result which does not have 11d channel */
2616 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry,
2617 LL_ACCESS_LOCK ))
2618 {
2619 csrFreeScanResultEntry( pMac, pBssDesc );
2620 }
2621 }
2622 else
2623 {
2624 smsLog( pMac, LOG1, FL("%d is a Valid channel"),
2625 pBssDesc->Result.BssDescriptor.channelId);
2626 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002627 pEntry = pTempEntry;
2628 }
2629 return status;
2630}
2631
2632
2633eHalStatus csrScanCopyResultList(tpAniSirGlobal pMac, tScanResultHandle hIn, tScanResultHandle *phResult)
2634{
2635 eHalStatus status = eHAL_STATUS_SUCCESS;
2636 tScanResultList *pRetList, *pInList = (tScanResultList *)hIn;
2637 tCsrScanResult *pResult, *pScanResult;
2638 tANI_U32 count = 0;
2639 tListElem *pEntry;
2640 tANI_U32 bssLen, allocLen;
2641
2642 if(phResult)
2643 {
2644 *phResult = CSR_INVALID_SCANRESULT_HANDLE;
2645 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302646 pRetList = vos_mem_malloc(sizeof(tScanResultList));
2647 if ( NULL == pRetList )
2648 status = eHAL_STATUS_FAILURE;
2649 else
Jeff Johnson295189b2012-06-20 16:38:30 -07002650 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302651 vos_mem_set(pRetList, sizeof(tScanResultList), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002652 csrLLOpen(pMac->hHdd, &pRetList->List);
2653 pRetList->pCurEntry = NULL;
2654 csrLLLock(&pMac->scan.scanResultList);
2655 csrLLLock(&pInList->List);
2656
2657 pEntry = csrLLPeekHead( &pInList->List, LL_ACCESS_NOLOCK );
2658 while( pEntry )
2659 {
2660 pScanResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2661 bssLen = pScanResult->Result.BssDescriptor.length + sizeof(pScanResult->Result.BssDescriptor.length);
2662 allocLen = sizeof( tCsrScanResult ) + bssLen;
Kiet Lam64c1b492013-07-12 13:56:44 +05302663 pResult = vos_mem_malloc(allocLen);
2664 if ( NULL == pResult )
2665 status = eHAL_STATUS_FAILURE;
2666 else
2667 status = eHAL_STATUS_SUCCESS;
2668 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07002669 {
2670 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
2671 count = 0;
2672 break;
2673 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302674 vos_mem_set(pResult, allocLen , 0);
2675 vos_mem_copy(&pResult->Result.BssDescriptor, &pScanResult->Result.BssDescriptor, bssLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07002676 if( pScanResult->Result.pvIes )
2677 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302678 pResult->Result.pvIes = vos_mem_malloc(sizeof( tDot11fBeaconIEs ));
2679 if ( NULL == pResult->Result.pvIes )
2680 status = eHAL_STATUS_FAILURE;
2681 else
2682 status = eHAL_STATUS_SUCCESS;
2683 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07002684 {
2685 //Free the memory we allocate above first
Kiet Lam64c1b492013-07-12 13:56:44 +05302686 vos_mem_free(pResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07002687 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
2688 count = 0;
2689 break;
2690 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302691 vos_mem_copy(pResult->Result.pvIes, pScanResult->Result.pvIes,
2692 sizeof( tDot11fBeaconIEs ));
Jeff Johnson295189b2012-06-20 16:38:30 -07002693 }
2694 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_LOCK);
2695 count++;
2696 pEntry = csrLLNext( &pInList->List, pEntry, LL_ACCESS_NOLOCK );
2697 }//while
2698 csrLLUnlock(&pInList->List);
2699 csrLLUnlock(&pMac->scan.scanResultList);
2700
2701 if(HAL_STATUS_SUCCESS(status))
2702 {
2703 if(0 == count)
2704 {
2705 csrLLClose(&pRetList->List);
Kiet Lam64c1b492013-07-12 13:56:44 +05302706 vos_mem_free(pRetList);
Jeff Johnson295189b2012-06-20 16:38:30 -07002707 status = eHAL_STATUS_E_NULL_VALUE;
2708 }
2709 else if(phResult)
2710 {
2711 *phResult = pRetList;
2712 }
2713 }
2714 }//Allocated pRetList
2715
2716 return (status);
2717}
2718
2719
2720
2721eHalStatus csrScanningStateMsgProcessor( tpAniSirGlobal pMac, void *pMsgBuf )
2722{
2723 eHalStatus status = eHAL_STATUS_SUCCESS;
2724 tSirMbMsg *pMsg = (tSirMbMsg *)pMsgBuf;
2725
2726 if((eWNI_SME_SCAN_RSP == pMsg->type) || (eWNI_SME_GET_SCANNED_CHANNEL_RSP == pMsg->type))
2727 {
2728 status = csrScanSmeScanResponse( pMac, pMsgBuf );
2729 }
2730 else
2731 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002732 if(pMsg->type == eWNI_SME_UPPER_LAYER_ASSOC_CNF)
Jeff Johnson295189b2012-06-20 16:38:30 -07002733 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002734 tCsrRoamSession *pSession;
2735 tSirSmeAssocIndToUpperLayerCnf *pUpperLayerAssocCnf;
2736 tCsrRoamInfo roamInfo;
2737 tCsrRoamInfo *pRoamInfo = NULL;
2738 tANI_U32 sessionId;
2739 eHalStatus status;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002740 smsLog( pMac, LOG1, FL("Scanning : ASSOCIATION confirmation can be given to upper layer "));
Kiet Lam64c1b492013-07-12 13:56:44 +05302741 vos_mem_set(&roamInfo, sizeof(tCsrRoamInfo), 0);
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002742 pRoamInfo = &roamInfo;
2743 pUpperLayerAssocCnf = (tSirSmeAssocIndToUpperLayerCnf *)pMsgBuf;
2744 status = csrRoamGetSessionIdFromBSSID( pMac, (tCsrBssid *)pUpperLayerAssocCnf->bssId, &sessionId );
2745 pSession = CSR_GET_SESSION(pMac, sessionId);
2746
2747 if(!pSession)
2748 {
2749 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
2750 return eHAL_STATUS_FAILURE;
2751 }
2752
2753 pRoamInfo->statusCode = eSIR_SME_SUCCESS; //send the status code as Success
2754 pRoamInfo->u.pConnectedProfile = &pSession->connectedProfile;
2755 pRoamInfo->staId = (tANI_U8)pUpperLayerAssocCnf->aid;
2756 pRoamInfo->rsnIELen = (tANI_U8)pUpperLayerAssocCnf->rsnIE.length;
2757 pRoamInfo->prsnIE = pUpperLayerAssocCnf->rsnIE.rsnIEdata;
2758 pRoamInfo->addIELen = (tANI_U8)pUpperLayerAssocCnf->addIE.length;
2759 pRoamInfo->paddIE = pUpperLayerAssocCnf->addIE.addIEdata;
Kiet Lam64c1b492013-07-12 13:56:44 +05302760 vos_mem_copy(pRoamInfo->peerMac, pUpperLayerAssocCnf->peerMacAddr, sizeof(tSirMacAddr));
2761 vos_mem_copy(&pRoamInfo->bssid, pUpperLayerAssocCnf->bssId, sizeof(tCsrBssid));
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002762 pRoamInfo->wmmEnabledSta = pUpperLayerAssocCnf->wmmEnabledSta;
2763 if(CSR_IS_INFRA_AP(pRoamInfo->u.pConnectedProfile) )
2764 {
2765 pMac->roam.roamSession[sessionId].connectState = eCSR_ASSOC_STATE_TYPE_INFRA_CONNECTED;
2766 pRoamInfo->fReassocReq = pUpperLayerAssocCnf->reassocReq;
2767 status = csrRoamCallCallback(pMac, sessionId, pRoamInfo, 0, eCSR_ROAM_INFRA_IND, eCSR_ROAM_RESULT_INFRA_ASSOCIATION_CNF);
2768 }
2769 if(CSR_IS_WDS_AP( pRoamInfo->u.pConnectedProfile))
2770 {
2771 vos_sleep( 100 );
2772 pMac->roam.roamSession[sessionId].connectState = eCSR_ASSOC_STATE_TYPE_WDS_CONNECTED;//Sta
2773 status = csrRoamCallCallback(pMac, sessionId, pRoamInfo, 0, eCSR_ROAM_WDS_IND, eCSR_ROAM_RESULT_WDS_ASSOCIATION_IND);//Sta
2774 }
2775
Jeff Johnson295189b2012-06-20 16:38:30 -07002776 }
2777 else
2778 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002779
2780 if( csrIsAnySessionInConnectState( pMac ) )
2781 {
2782 //In case of we are connected, we need to check whether connect status changes
2783 //because scan may also run while connected.
2784 csrRoamCheckForLinkStatusChange( pMac, ( tSirSmeRsp * )pMsgBuf );
2785 }
2786 else
2787 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002788 smsLog( pMac, LOGW, "Message [0x%04x] received in state, when expecting Scan Response", pMsg->type );
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002789 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002790 }
2791 }
2792
2793 return (status);
2794}
2795
2796
2797
2798void csrCheckNSaveWscIe(tpAniSirGlobal pMac, tSirBssDescription *pNewBssDescr, tSirBssDescription *pOldBssDescr)
2799{
2800 int idx, len;
2801 tANI_U8 *pbIe;
2802
2803 //If failed to remove, assuming someone else got it.
2804 if((pNewBssDescr->fProbeRsp != pOldBssDescr->fProbeRsp) &&
2805 (0 == pNewBssDescr->WscIeLen))
2806 {
2807 idx = 0;
2808 len = pOldBssDescr->length - sizeof(tSirBssDescription) +
2809 sizeof(tANI_U16) + sizeof(tANI_U32) - DOT11F_IE_WSCPROBERES_MIN_LEN - 2;
2810 pbIe = (tANI_U8 *)pOldBssDescr->ieFields;
2811 //Save WPS IE if it exists
2812 pNewBssDescr->WscIeLen = 0;
2813 while(idx < len)
2814 {
2815 if((DOT11F_EID_WSCPROBERES == pbIe[0]) &&
2816 (0x00 == pbIe[2]) && (0x50 == pbIe[3]) && (0xf2 == pbIe[4]) && (0x04 == pbIe[5]))
2817 {
2818 //Founrd it
2819 if((DOT11F_IE_WSCPROBERES_MAX_LEN - 2) >= pbIe[1])
2820 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302821 vos_mem_copy(pNewBssDescr->WscIeProbeRsp, pbIe, pbIe[1] + 2);
Jeff Johnson295189b2012-06-20 16:38:30 -07002822 pNewBssDescr->WscIeLen = pbIe[1] + 2;
2823 }
2824 break;
2825 }
2826 idx += pbIe[1] + 2;
2827 pbIe += pbIe[1] + 2;
2828 }
2829 }
2830}
2831
2832
2833
2834//pIes may be NULL
2835tANI_BOOLEAN csrRemoveDupBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDescr,
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05302836 tDot11fBeaconIEs *pIes, tAniSSID *pSsid, v_TIME_t *timer, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07002837{
2838 tListElem *pEntry;
2839
2840 tCsrScanResult *pBssDesc;
2841 tANI_BOOLEAN fRC = FALSE;
2842
2843 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
2844 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
2845 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
2846 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
2847
2848 while( pEntry )
2849 {
2850 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2851
2852 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
2853 // matches
2854 if ( csrIsDuplicateBssDescription( pMac, &pBssDesc->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07002855 pSirBssDescr, pIes, fForced ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07002856 {
2857 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
2858 ((tANI_S32)pBssDesc->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
2859 // Remove the 'old' entry from the list....
2860 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry, LL_ACCESS_LOCK ) )
2861 {
2862 // !we need to free the memory associated with this node
2863 //If failed to remove, assuming someone else got it.
2864 *pSsid = pBssDesc->Result.ssId;
2865 *timer = pBssDesc->Result.timer;
2866 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pBssDesc->Result.BssDescriptor);
2867
2868 csrFreeScanResultEntry( pMac, pBssDesc );
2869 }
2870 else
2871 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002872 smsLog( pMac, LOGW, FL( " fail to remove entry" ) );
Jeff Johnson295189b2012-06-20 16:38:30 -07002873 }
2874 fRC = TRUE;
2875
2876 // If we found a match, we can stop looking through the list.
2877 break;
2878 }
2879
2880 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_LOCK );
2881 }
2882
2883 return fRC;
2884}
2885
2886
2887eHalStatus csrAddPMKIDCandidateList( tpAniSirGlobal pMac, tANI_U32 sessionId,
2888 tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes )
2889{
2890 eHalStatus status = eHAL_STATUS_FAILURE;
2891 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
2892
Jeff Johnson32d95a32012-09-10 13:15:23 -07002893 if(!pSession)
2894 {
2895 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
2896 return eHAL_STATUS_FAILURE;
2897 }
2898
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002899 smsLog(pMac, LOGW, "csrAddPMKIDCandidateList called pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07002900 if( pIes )
2901 {
2902 // check if this is a RSN BSS
2903 if( pIes->RSN.present )
2904 {
2905 // Check if the BSS is capable of doing pre-authentication
2906 if( pSession->NumPmkidCandidate < CSR_MAX_PMKID_ALLOWED )
2907 {
2908
2909#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
2910 {
2911 WLAN_VOS_DIAG_EVENT_DEF(secEvent, vos_event_wlan_security_payload_type);
Kiet Lam64c1b492013-07-12 13:56:44 +05302912 vos_mem_set(&secEvent, sizeof(vos_event_wlan_security_payload_type), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002913 secEvent.eventId = WLAN_SECURITY_EVENT_PMKID_CANDIDATE_FOUND;
2914 secEvent.encryptionModeMulticast =
2915 (v_U8_t)diagEncTypeFromCSRType(pSession->connectedProfile.mcEncryptionType);
2916 secEvent.encryptionModeUnicast =
2917 (v_U8_t)diagEncTypeFromCSRType(pSession->connectedProfile.EncryptionType);
Kiet Lam64c1b492013-07-12 13:56:44 +05302918 vos_mem_copy(secEvent.bssid, pSession->connectedProfile.bssid, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07002919 secEvent.authMode =
2920 (v_U8_t)diagAuthTypeFromCSRType(pSession->connectedProfile.AuthType);
2921 WLAN_VOS_DIAG_EVENT_REPORT(&secEvent, EVENT_WLAN_SECURITY);
2922 }
2923#endif//#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
2924
2925 // if yes, then add to PMKIDCandidateList
Kiet Lam64c1b492013-07-12 13:56:44 +05302926 vos_mem_copy(pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].BSSID,
2927 pBssDesc->bssId, WNI_CFG_BSSID_LEN);
2928 // Bit 0 offirst byte - PreAuthentication Capability
2929 if ( (pIes->RSN.RSN_Cap[0] >> 0) & 0x1 )
Jeff Johnson295189b2012-06-20 16:38:30 -07002930 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302931 pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].preAuthSupported
2932 = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07002933 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302934 else
2935 {
2936 pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].preAuthSupported
2937 = eANI_BOOLEAN_FALSE;
2938 }
2939 pSession->NumPmkidCandidate++;
Jeff Johnson295189b2012-06-20 16:38:30 -07002940 }
2941 else
2942 {
2943 status = eHAL_STATUS_FAILURE;
2944 }
2945 }
2946 }
2947
2948 return (status);
2949}
2950
2951//This function checks whether new AP is found for the current connected profile
2952//If it is found, it return the sessionId, else it return invalid sessionID
2953tANI_U32 csrProcessBSSDescForPMKIDList(tpAniSirGlobal pMac,
2954 tSirBssDescription *pBssDesc,
2955 tDot11fBeaconIEs *pIes)
2956{
2957 tANI_U32 i, bRet = CSR_SESSION_ID_INVALID;
2958 tCsrRoamSession *pSession;
2959 tDot11fBeaconIEs *pIesLocal = pIes;
2960
2961 if( pIesLocal || HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIesLocal)) )
2962 {
2963 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
2964 {
2965 if( CSR_IS_SESSION_VALID( pMac, i ) )
2966 {
2967 pSession = CSR_GET_SESSION( pMac, i );
2968 if( csrIsConnStateConnectedInfra( pMac, i ) &&
2969 ( eCSR_AUTH_TYPE_RSN == pSession->connectedProfile.AuthType ) )
2970 {
2971 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile, pBssDesc, pIesLocal))
2972 {
2973 //this new BSS fits the current profile connected
2974 if(HAL_STATUS_SUCCESS(csrAddPMKIDCandidateList(pMac, i, pBssDesc, pIesLocal)))
2975 {
2976 bRet = i;
2977 }
2978 break;
2979 }
2980 }
2981 }
2982 }
2983 if( !pIes )
2984 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302985 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07002986 }
2987 }
2988
2989 return (tANI_U8)bRet;
2990}
2991
2992#ifdef FEATURE_WLAN_WAPI
2993eHalStatus csrAddBKIDCandidateList( tpAniSirGlobal pMac, tANI_U32 sessionId,
2994 tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes )
2995{
2996 eHalStatus status = eHAL_STATUS_FAILURE;
2997 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
2998
Jeff Johnson32d95a32012-09-10 13:15:23 -07002999 if(!pSession)
3000 {
3001 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
3002 return eHAL_STATUS_FAILURE;
3003 }
3004
Kiet Lam64c1b492013-07-12 13:56:44 +05303005 smsLog(pMac, LOGW, "csrAddBKIDCandidateList called pMac->scan.NumBkidCandidate = %d",
3006 pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07003007 if( pIes )
3008 {
3009 // check if this is a WAPI BSS
3010 if( pIes->WAPI.present )
3011 {
3012 // Check if the BSS is capable of doing pre-authentication
3013 if( pSession->NumBkidCandidate < CSR_MAX_BKID_ALLOWED )
3014 {
3015
3016 // if yes, then add to BKIDCandidateList
Kiet Lam64c1b492013-07-12 13:56:44 +05303017 vos_mem_copy(pSession->BkidCandidateInfo[pSession->NumBkidCandidate].BSSID,
3018 pBssDesc->bssId, WNI_CFG_BSSID_LEN);
3019 if ( pIes->WAPI.preauth )
Jeff Johnson295189b2012-06-20 16:38:30 -07003020 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303021 pSession->BkidCandidateInfo[pSession->NumBkidCandidate].preAuthSupported
3022 = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003023 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303024 else
3025 {
3026 pSession->BkidCandidateInfo[pSession->NumBkidCandidate].preAuthSupported
3027 = eANI_BOOLEAN_FALSE;
3028 }
3029 pSession->NumBkidCandidate++;
Jeff Johnson295189b2012-06-20 16:38:30 -07003030 }
3031 else
3032 {
3033 status = eHAL_STATUS_FAILURE;
3034 }
3035 }
3036 }
3037
3038 return (status);
3039}
3040
3041//This function checks whether new AP is found for the current connected profile
3042//if so add to BKIDCandidateList
3043tANI_BOOLEAN csrProcessBSSDescForBKIDList(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
3044 tDot11fBeaconIEs *pIes)
3045{
3046 tANI_BOOLEAN fRC = FALSE;
3047 tDot11fBeaconIEs *pIesLocal = pIes;
3048 tANI_U32 sessionId;
3049 tCsrRoamSession *pSession;
3050
3051 if( pIesLocal || HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIesLocal)) )
3052 {
3053 for( sessionId = 0; sessionId < CSR_ROAM_SESSION_MAX; sessionId++ )
3054 {
3055 if( CSR_IS_SESSION_VALID( pMac, sessionId) )
3056 {
3057 pSession = CSR_GET_SESSION( pMac, sessionId );
3058 if( csrIsConnStateConnectedInfra( pMac, sessionId ) &&
3059 eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE == pSession->connectedProfile.AuthType)
3060 {
3061 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile,pBssDesc, pIesLocal))
3062 {
3063 //this new BSS fits the current profile connected
3064 if(HAL_STATUS_SUCCESS(csrAddBKIDCandidateList(pMac, sessionId, pBssDesc, pIesLocal)))
3065 {
3066 fRC = TRUE;
3067 }
3068 }
3069 }
3070 }
3071 }
3072 if(!pIes)
3073 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303074 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003075 }
3076
3077 }
3078 return fRC;
3079}
3080
3081#endif
3082
3083
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07003084static void csrMoveTempScanResultsToMainList( tpAniSirGlobal pMac, tANI_U8 reason )
Jeff Johnson295189b2012-06-20 16:38:30 -07003085{
3086 tListElem *pEntry;
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303087 tListElem *pEntryTemp;
3088 tListElem *pNext;
Jeff Johnson295189b2012-06-20 16:38:30 -07003089 tCsrScanResult *pBssDescription;
3090 tANI_S8 cand_Bss_rssi;
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303091 tANI_S8 rssi_of_current_country;
Jeff Johnson295189b2012-06-20 16:38:30 -07003092 tANI_BOOLEAN fDupBss;
3093#ifdef FEATURE_WLAN_WAPI
3094 tANI_BOOLEAN fNewWapiBSSForCurConnection = eANI_BOOLEAN_FALSE;
3095#endif /* FEATURE_WLAN_WAPI */
3096 tDot11fBeaconIEs *pIesLocal = NULL;
3097 tANI_U32 sessionId = CSR_SESSION_ID_INVALID;
3098 tAniSSID tmpSsid;
3099 v_TIME_t timer=0;
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303100 tCsrBssid bssid_temp = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
Jeff Johnson295189b2012-06-20 16:38:30 -07003101
3102 tmpSsid.length = 0;
3103 cand_Bss_rssi = -128; // RSSI coming from PE is -ve
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303104 rssi_of_current_country = -128;
Jeff Johnson295189b2012-06-20 16:38:30 -07003105
3106 // remove the BSS descriptions from temporary list
3107 while( ( pEntry = csrLLRemoveTail( &pMac->scan.tempScanResults, LL_ACCESS_LOCK ) ) != NULL)
3108 {
3109 pBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
3110
Arif Hussain24bafea2013-11-15 15:10:03 -08003111 smsLog( pMac, LOGW, "...Bssid= "MAC_ADDRESS_STR" chan= %d, rssi = -%d",
3112 MAC_ADDR_ARRAY(pBssDescription->Result.BssDescriptor.bssId),
Jeff Johnson295189b2012-06-20 16:38:30 -07003113 pBssDescription->Result.BssDescriptor.channelId,
3114 pBssDescription->Result.BssDescriptor.rssi * (-1) );
3115
3116 //At this time, pBssDescription->Result.pvIes may be NULL
3117 pIesLocal = (tDot11fBeaconIEs *)( pBssDescription->Result.pvIes );
3118 if( !pIesLocal && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pBssDescription->Result.BssDescriptor, &pIesLocal))) )
3119 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003120 smsLog(pMac, LOGE, FL(" Cannot pared IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003121 csrFreeScanResultEntry(pMac, pBssDescription);
3122 continue;
3123 }
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05303124 fDupBss = csrRemoveDupBssDescription( pMac, &pBssDescription->Result.BssDescriptor, pIesLocal, &tmpSsid, &timer, FALSE );
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07003125 //Check whether we have reach out limit, but don't lose the LFR candidates came from FW
3126 if( CSR_SCAN_IS_OVER_BSS_LIMIT(pMac)
3127#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
3128 && !( eCsrScanGetLfrResult == reason )
3129#endif
3130 )
Jeff Johnson295189b2012-06-20 16:38:30 -07003131 {
3132 //Limit reach
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003133 smsLog(pMac, LOGW, FL(" BSS limit reached"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003134 //Free the resources
3135 if( (pBssDescription->Result.pvIes == NULL) && pIesLocal )
3136 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303137 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003138 }
3139 csrFreeScanResultEntry(pMac, pBssDescription);
3140 //Continue because there may be duplicated BSS
3141 continue;
3142 }
3143 // check for duplicate scan results
3144 if ( !fDupBss )
3145 {
3146 //Found a new BSS
3147 sessionId = csrProcessBSSDescForPMKIDList(pMac,
3148 &pBssDescription->Result.BssDescriptor, pIesLocal);
3149 if( CSR_SESSION_ID_INVALID != sessionId)
3150 {
3151 csrRoamCallCallback(pMac, sessionId, NULL, 0,
3152 eCSR_ROAM_SCAN_FOUND_NEW_BSS, eCSR_ROAM_RESULT_NONE);
3153 }
3154 }
3155 else
3156 {
3157 //Check if the new one has SSID it it, if not, use the older SSID if it exists.
3158 if( (0 == pBssDescription->Result.ssId.length) && tmpSsid.length )
3159 {
3160 //New BSS has a hidden SSID and old one has the SSID. Keep the SSID only
3161 //if diff of saved SSID time and current time is less than 1 min to avoid
3162 //side effect of saving SSID with old one is that if AP changes its SSID while remain
3163 //hidden, we may never see it and also to address the requirement of
3164 //When we remove hidden ssid from the profile i.e., forget the SSID via
3165 // GUI that SSID shouldn't see in the profile
3166 if( (vos_timer_get_system_time() - timer) <= HIDDEN_TIMER)
3167 {
3168 pBssDescription->Result.timer = timer;
3169 pBssDescription->Result.ssId = tmpSsid;
3170 }
3171 }
3172 }
3173
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303174 //Find a good AP for 11d info
3175 if ( csrIs11dSupported( pMac ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003176 {
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303177 if (cand_Bss_rssi < pBssDescription->Result.BssDescriptor.rssi)
Jeff Johnson295189b2012-06-20 16:38:30 -07003178 {
3179 // check if country information element is present
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303180 if (pIesLocal->Country.present)
Jeff Johnson295189b2012-06-20 16:38:30 -07003181 {
3182 cand_Bss_rssi = pBssDescription->Result.BssDescriptor.rssi;
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303183 smsLog(pMac, LOGW, FL("11d AP Bssid " MAC_ADDRESS_STR
3184 " chan= %d, rssi = -%d, countryCode %c%c"),
3185 MAC_ADDR_ARRAY( pBssDescription->Result.BssDescriptor.bssId),
3186 pBssDescription->Result.BssDescriptor.channelId,
3187 pBssDescription->Result.BssDescriptor.rssi * (-1),
3188 pIesLocal->Country.country[0],pIesLocal->Country.country[1] );
3189 //Getting BSSID for best AP in scan result.
Kiet Lamf2f201e2013-11-16 21:24:16 +05303190 vos_mem_copy(bssid_temp,
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303191 pBssDescription->Result.BssDescriptor.bssId, sizeof(tSirMacAddr));
3192
Jeff Johnson295189b2012-06-20 16:38:30 -07003193 }
3194
3195 }
3196 }
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303197 //get current rssi for BSS from which country code is acquired.
3198 if ( csrIs11dSupported(pMac) && (csrIsMacAddressEqual(pMac,
3199 &pMac->scan.currentCountryBssid,
3200 &pBssDescription->Result.BssDescriptor.bssId) ))
3201 {
3202 smsLog(pMac, LOGW, FL("Information about current country Bssid "
3203 MAC_ADDRESS_STR
3204 " chan= %d, rssi = -%d, countryCode %c%c"),
3205 MAC_ADDR_ARRAY( pBssDescription->Result.BssDescriptor.bssId),
3206 pBssDescription->Result.BssDescriptor.channelId,
3207 pBssDescription->Result.BssDescriptor.rssi * (-1),
3208 pIesLocal->Country.country[0],pIesLocal->Country.country[1] );
3209 rssi_of_current_country = pBssDescription->Result.BssDescriptor.rssi ;
3210 }
3211
Jeff Johnson295189b2012-06-20 16:38:30 -07003212
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08003213
Jeff Johnson295189b2012-06-20 16:38:30 -07003214 // append to main list
3215 csrScanAddResult(pMac, pBssDescription, pIesLocal);
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303216 if ( (pBssDescription->Result.pvIes == NULL) && pIesLocal )
Jeff Johnson295189b2012-06-20 16:38:30 -07003217 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303218 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003219 }
3220 }
3221
Tushnim Bhattacharyyaae317772013-10-23 18:55:38 -07003222 //we don't need to update CC while connected to an AP which is advertising CC already
3223 if (csrIs11dSupported(pMac))
3224 {
3225 tANI_U32 i;
3226 tCsrRoamSession *pSession;
3227
3228 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
3229 {
3230 if (CSR_IS_SESSION_VALID( pMac, i ) )
3231 {
3232 pSession = CSR_GET_SESSION( pMac, i );
3233 if (csrIsConnStateConnected(pMac, i))
3234 {
3235 if (csrIsBssidMatch(pMac, (tCsrBssid *)&pMac->scan.currentCountryBssid,
3236 &pSession->connectedProfile.bssid))
3237 {
3238 smsLog(pMac, LOGW, FL("No need for updating CC, we will"
3239 "continue with current AP's CC"));
3240 goto end;
3241 }
3242 }
3243 }
3244 }
Tushnim Bhattacharyyaae317772013-10-23 18:55:38 -07003245
Tushnim Bhattacharyyac3022ef2013-10-24 15:58:56 -07003246 // Calculating 30% of current rssi is an idea for not to change
3247 // country code so freq.
3248 if (rssi_of_current_country != -128)
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303249 {
Tushnim Bhattacharyyac3022ef2013-10-24 15:58:56 -07003250 rssi_of_current_country = rssi_of_current_country
3251 - THIRTY_PERCENT(rssi_of_current_country);
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303252 }
Tushnim Bhattacharyyac3c1e8e2013-10-29 17:27:43 -07003253 //if new candidate AP has 30% better RSSI or this is the first time or
3254 //AP aged out of CSR cache or we are in world CC now
krunal soni5f112f02013-11-25 15:00:11 -08003255 if ((rssi_of_current_country <= cand_Bss_rssi &&
3256 rssi_of_current_country != -128) ||
3257 (rssi_of_current_country == -128 &&
3258 pMac->scan.scanProfile.numOfChannels >= MANDATORY_BG_CHANNEL) ||
3259 ('0' == pMac->scan.countryCode11d[ 0 ] &&
3260 '0' == pMac->scan.countryCode11d[ 1 ]))
Tushnim Bhattacharyyac3022ef2013-10-24 15:58:56 -07003261 {
3262 csrLLLock(&pMac->scan.scanResultList);
3263 pEntryTemp = csrLLPeekHead(&pMac->scan.scanResultList, LL_ACCESS_NOLOCK);
3264 while ( NULL != pEntryTemp)
3265 {
3266 pNext = csrLLNext(&pMac->scan.scanResultList, pEntryTemp,
3267 LL_ACCESS_NOLOCK);
3268 pBssDescription = GET_BASE_ADDR( pEntryTemp, tCsrScanResult, Link );
3269 pIesLocal = (tDot11fBeaconIEs *)( pBssDescription->Result.pvIes );
3270 // Need to traverse whole scan list to get description for best 11d AP.
3271 if (csrIsMacAddressEqual(pMac, (tCsrBssid *)&bssid_temp,
3272 (tCsrBssid *) pBssDescription->Result.BssDescriptor.bssId))
3273 {
Tushnim Bhattacharyyac3022ef2013-10-24 15:58:56 -07003274 // Best AP should be passed to update reg domain.
3275 csrLearnCountryInformation( pMac, &pBssDescription->Result.BssDescriptor,
3276 pIesLocal, eANI_BOOLEAN_TRUE );
Tushnim Bhattacharyyac3c1e8e2013-10-29 17:27:43 -07003277 //this check is to avoid the case of invalid CC set via 11d
3278 //In that case we move to world CC & we are open to any new
3279 //valid CC we can get during scan
3280 if(( '0' != pMac->scan.countryCode11d[ 0 ] && '0' != pMac->scan.countryCode11d[ 1 ] ))
3281 {
Kiet Lamf2f201e2013-11-16 21:24:16 +05303282 vos_mem_copy(pMac->scan.currentCountryBssid,
Tushnim Bhattacharyyac3c1e8e2013-10-29 17:27:43 -07003283 bssid_temp, sizeof(tSirMacAddr));
3284 }
Tushnim Bhattacharyyac3022ef2013-10-24 15:58:56 -07003285 break;
3286 }
3287 pEntryTemp = pNext;
3288 }
3289 csrLLUnlock(&pMac->scan.scanResultList);
3290 }
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303291 }
3292
3293
Tushnim Bhattacharyyaae317772013-10-23 18:55:38 -07003294end:
3295 //If we can find the current 11d info in any of the scan results, or
Jeff Johnson295189b2012-06-20 16:38:30 -07003296 // a good enough AP with the 11d info from the scan results then no need to
3297 // get into ambiguous state
3298 if(pMac->scan.fAmbiguous11dInfoFound)
3299 {
3300 if((pMac->scan.fCurrent11dInfoMatch) || (cand_Bss_rssi != -128))
3301 {
3302 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
3303 }
3304 }
3305
3306#ifdef FEATURE_WLAN_WAPI
3307 if(fNewWapiBSSForCurConnection)
3308 {
3309 //remember it first
3310 csrRoamCallCallback(pMac, sessionId, NULL, 0, eCSR_ROAM_SCAN_FOUND_NEW_BSS, eCSR_ROAM_RESULT_NEW_WAPI_BSS);
3311 }
3312#endif /* FEATURE_WLAN_WAPI */
3313
3314 return;
3315}
3316
3317
3318static tCsrScanResult *csrScanSaveBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pBSSDescription,
3319 tDot11fBeaconIEs *pIes)
3320{
3321 tCsrScanResult *pCsrBssDescription = NULL;
3322 tANI_U32 cbBSSDesc;
3323 tANI_U32 cbAllocated;
Jeff Johnson295189b2012-06-20 16:38:30 -07003324
3325 // figure out how big the BSS description is (the BSSDesc->length does NOT
3326 // include the size of the length field itself).
3327 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
3328
3329 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
3330
Kiet Lam64c1b492013-07-12 13:56:44 +05303331 pCsrBssDescription = vos_mem_malloc(cbAllocated);
3332 if ( NULL != pCsrBssDescription )
Jeff Johnson295189b2012-06-20 16:38:30 -07003333 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303334 vos_mem_set(pCsrBssDescription, cbAllocated, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003335 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Kiet Lam64c1b492013-07-12 13:56:44 +05303336 vos_mem_copy(&pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc);
Jeff Johnson295189b2012-06-20 16:38:30 -07003337#if defined(VOSS_ENSBALED)
3338 VOS_ASSERT( pCsrBssDescription->Result.pvIes == NULL );
3339#endif
3340 csrScanAddResult(pMac, pCsrBssDescription, pIes);
3341 }
3342
3343 return( pCsrBssDescription );
3344}
3345
3346// Append a Bss Description...
3347tCsrScanResult *csrScanAppendBssDescription( tpAniSirGlobal pMac,
3348 tSirBssDescription *pSirBssDescription,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07003349 tDot11fBeaconIEs *pIes, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07003350{
3351 tCsrScanResult *pCsrBssDescription = NULL;
3352 tAniSSID tmpSsid;
3353 v_TIME_t timer = 0;
3354 int result;
3355
3356 tmpSsid.length = 0;
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07003357 result = csrRemoveDupBssDescription( pMac, pSirBssDescription, pIes, &tmpSsid, &timer, fForced );
Jeff Johnson295189b2012-06-20 16:38:30 -07003358 pCsrBssDescription = csrScanSaveBssDescription( pMac, pSirBssDescription, pIes );
3359 if (result && (pCsrBssDescription != NULL))
3360 {
3361 //Check if the new one has SSID it it, if not, use the older SSID if it exists.
3362 if( (0 == pCsrBssDescription->Result.ssId.length) && tmpSsid.length )
3363 {
3364 //New BSS has a hidden SSID and old one has the SSID. Keep the SSID only
3365 //if diff of saved SSID time and current time is less than 1 min to avoid
3366 //side effect of saving SSID with old one is that if AP changes its SSID while remain
3367 //hidden, we may never see it and also to address the requirement of
3368 //When we remove hidden ssid from the profile i.e., forget the SSID via
3369 // GUI that SSID shouldn't see in the profile
3370 if((vos_timer_get_system_time()-timer) <= HIDDEN_TIMER)
3371 {
3372 pCsrBssDescription->Result.ssId = tmpSsid;
3373 pCsrBssDescription->Result.timer = timer;
3374 }
3375 }
3376 }
3377
3378
3379 return( pCsrBssDescription );
3380}
3381
3382
3383
3384void csrPurgeChannelPower( tpAniSirGlobal pMac, tDblLinkList *pChannelList )
3385{
3386 tCsrChannelPowerInfo *pChannelSet;
3387 tListElem *pEntry;
3388
3389 csrLLLock(pChannelList);
3390 // Remove the channel sets from the learned list and put them in the free list
3391 while( ( pEntry = csrLLRemoveHead( pChannelList, LL_ACCESS_NOLOCK ) ) != NULL)
3392 {
3393 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3394 if( pChannelSet )
3395 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303396 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003397 }
3398 }
3399 csrLLUnlock(pChannelList);
3400 return;
3401}
3402
3403
3404/*
3405 * Save the channelList into the ultimate storage as the final stage of channel
3406 * Input: pCountryInfo -- the country code (e.g. "USI"), channel list, and power limit are all stored inside this data structure
3407 */
Jeff Johnsone7245742012-09-05 17:12:55 -07003408eHalStatus csrSaveToChannelPower2G_5G( tpAniSirGlobal pMac, tANI_U32 tableSize, tSirMacChanInfo *channelTable )
Jeff Johnson295189b2012-06-20 16:38:30 -07003409{
3410 tANI_U32 i = tableSize / sizeof( tSirMacChanInfo );
3411 tSirMacChanInfo *pChannelInfo;
3412 tCsrChannelPowerInfo *pChannelSet;
3413 tANI_BOOLEAN f2GHzInfoFound = FALSE;
3414 tANI_BOOLEAN f2GListPurged = FALSE, f5GListPurged = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003415
3416 pChannelInfo = channelTable;
3417 // atleast 3 bytes have to be remaining -- from "countryString"
3418 while ( i-- )
3419 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303420 pChannelSet = vos_mem_malloc(sizeof(tCsrChannelPowerInfo));
3421 if ( NULL != pChannelSet )
Jeff Johnson295189b2012-06-20 16:38:30 -07003422 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303423 vos_mem_set(pChannelSet, sizeof(tCsrChannelPowerInfo), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003424 pChannelSet->firstChannel = pChannelInfo->firstChanNum;
3425 pChannelSet->numChannels = pChannelInfo->numChannels;
3426
3427 // Now set the inter-channel offset based on the frequency band the channel set lies in
Jeff Johnsone7245742012-09-05 17:12:55 -07003428 if( (CSR_IS_CHANNEL_24GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003429 ((pChannelSet->firstChannel + (pChannelSet->numChannels - 1)) <= CSR_MAX_24GHz_CHANNEL_NUMBER) )
Jeff Johnsone7245742012-09-05 17:12:55 -07003430
Jeff Johnson295189b2012-06-20 16:38:30 -07003431 {
3432 pChannelSet->interChannelOffset = 1;
3433 f2GHzInfoFound = TRUE;
3434 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003435 else if ( (CSR_IS_CHANNEL_5GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003436 ((pChannelSet->firstChannel + ((pChannelSet->numChannels - 1) * 4)) <= CSR_MAX_5GHz_CHANNEL_NUMBER) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003437 {
3438 pChannelSet->interChannelOffset = 4;
3439 f2GHzInfoFound = FALSE;
3440 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003441 else
3442 {
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003443 smsLog( pMac, LOGW, FL("Invalid Channel %d Present in Country IE"),
Jeff Johnsone7245742012-09-05 17:12:55 -07003444 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303445 vos_mem_free(pChannelSet);
Jeff Johnsone7245742012-09-05 17:12:55 -07003446 return eHAL_STATUS_FAILURE;
3447 }
3448
Jeff Johnson295189b2012-06-20 16:38:30 -07003449 pChannelSet->txPower = CSR_ROAM_MIN( pChannelInfo->maxTxPower, pMac->roam.configParam.nTxPowerCap );
3450
3451 if( f2GHzInfoFound )
3452 {
3453 if( !f2GListPurged )
3454 {
3455 // purge previous results if found new
3456 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList24 );
3457 f2GListPurged = TRUE;
3458 }
3459
3460 if(CSR_IS_OPERATING_BG_BAND(pMac))
3461 {
3462 // add to the list of 2.4 GHz channel sets
3463 csrLLInsertTail( &pMac->scan.channelPowerInfoList24, &pChannelSet->link, LL_ACCESS_LOCK );
3464 }
3465 else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003466 smsLog( pMac, LOGW, FL("Adding 11B/G channels in 11A mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003467 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303468 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003469 }
3470 }
3471 else
3472 {
3473 // 5GHz info found
3474 if( !f5GListPurged )
3475 {
3476 // purge previous results if found new
3477 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList5G );
3478 f5GListPurged = TRUE;
3479 }
3480
3481 if(CSR_IS_OPERATING_A_BAND(pMac))
3482 {
3483 // add to the list of 5GHz channel sets
3484 csrLLInsertTail( &pMac->scan.channelPowerInfoList5G, &pChannelSet->link, LL_ACCESS_LOCK );
3485 }
3486 else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003487 smsLog( pMac, LOGW, FL("Adding 11A channels in B/G mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003488 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303489 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003490 }
3491 }
3492 }
3493
3494 pChannelInfo++; // move to next entry
3495 }
3496
Jeff Johnsone7245742012-09-05 17:12:55 -07003497 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07003498}
3499
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303500static void csrClearDfsChannelList( tpAniSirGlobal pMac )
3501{
3502 tSirMbMsg *pMsg;
3503 tANI_U16 msgLen;
Jeff Johnson295189b2012-06-20 16:38:30 -07003504
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303505 msgLen = (tANI_U16)(sizeof( tSirMbMsg ));
Kiet Lam64c1b492013-07-12 13:56:44 +05303506 pMsg = vos_mem_malloc(msgLen);
3507 if ( NULL != pMsg )
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303508 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303509 vos_mem_set((void *)pMsg, msgLen, 0);
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303510 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_CLEAR_DFS_CHANNEL_LIST);
3511 pMsg->msgLen = pal_cpu_to_be16(msgLen);
3512 palSendMBMessage(pMac->hHdd, pMsg);
3513 }
3514}
Jeff Johnson295189b2012-06-20 16:38:30 -07003515
3516void csrApplyPower2Current( tpAniSirGlobal pMac )
3517{
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003518 smsLog( pMac, LOG3, FL(" Updating Cfg with power settings"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003519 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList24, WNI_CFG_MAX_TX_POWER_2_4 );
3520 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList5G, WNI_CFG_MAX_TX_POWER_5 );
3521}
3522
3523
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003524void csrApplyChannelPowerCountryInfo( tpAniSirGlobal pMac, tCsrChannel *pChannelList, tANI_U8 *countryCode, tANI_BOOLEAN updateRiva)
Jeff Johnson295189b2012-06-20 16:38:30 -07003525{
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303526 int i, j, count, countryIndex = -1;
Jeff Johnson295189b2012-06-20 16:38:30 -07003527 eNVChannelEnabledType channelEnabledType;
3528 tANI_U8 numChannels = 0;
3529 tANI_U8 tempNumChannels = 0;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303530 tANI_U8 channelIgnore = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003531 tCsrChannel ChannelList;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303532
Jeff Johnson295189b2012-06-20 16:38:30 -07003533 if( pChannelList->numChannels )
3534 {
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303535 for(count=0; count < MAX_COUNTRY_IGNORE; count++)
3536 {
3537 if(vos_mem_compare(countryCode, countryIgnoreList[count].countryCode,
3538 VOS_COUNTRY_CODE_LEN))
3539 {
3540 countryIndex = count;
3541 break;
3542 }
3543 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003544 tempNumChannels = CSR_MIN(pChannelList->numChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN);
3545 /* If user doesn't want to scan the DFS channels lets trim them from
3546 the valid channel list*/
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303547 for(i=0; i < tempNumChannels; i++)
Jeff Johnson295189b2012-06-20 16:38:30 -07003548 {
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303549 channelIgnore = FALSE;
3550 if( FALSE == pMac->scan.fEnableDFSChnlScan )
3551 {
3552 channelEnabledType =
3553 vos_nv_getChannelEnabledState(pChannelList->channelList[i]);
3554 }
3555 else
3556 {
Madan Mohan Koyyalamudi3f65e312012-11-06 15:31:12 -08003557 channelEnabledType = NV_CHANNEL_ENABLE;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303558 }
3559 if( NV_CHANNEL_ENABLE == channelEnabledType )
3560 {
3561 if( countryIndex != -1 )
3562 {
3563 for(j=0; j < countryIgnoreList[countryIndex].channelCount; j++)
3564 {
3565 if( pChannelList->channelList[i] ==
3566 countryIgnoreList[countryIndex].channelList[j] )
3567 {
3568 channelIgnore = TRUE;
3569 break;
3570 }
3571 }
3572 }
3573 if( FALSE == channelIgnore )
3574 {
3575 ChannelList.channelList[numChannels] = pChannelList->channelList[i];
3576 numChannels++;
3577 }
3578 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003579 }
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303580 ChannelList.numChannels = numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -07003581 csrSetCfgValidChannelList(pMac, ChannelList.channelList, ChannelList.numChannels);
3582 // extend scan capability
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303583 // build a scan list based on the channel list : channel# + active/passive scan
3584 csrSetCfgScanControlList(pMac, countryCode, &ChannelList);
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303585 /*Send msg to Lim to clear DFS channel list */
3586 csrClearDfsChannelList(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07003587#ifdef FEATURE_WLAN_SCAN_PNO
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003588 if (updateRiva)
3589 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003590 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO, FL(" Sending 11d PNO info to Riva"));
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003591 // Send HAL UpdateScanParams message
3592 pmcUpdateScanParams(pMac, &(pMac->roam.configParam), &ChannelList, TRUE);
3593 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003594#endif // FEATURE_WLAN_SCAN_PNO
3595 }
3596 else
3597 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003598 smsLog( pMac, LOGE, FL(" 11D channel list is empty"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003599 }
3600 csrApplyPower2Current( pMac ); // Store the channel+power info in the global place: Cfg
3601 csrSetCfgCountryCode(pMac, countryCode);
3602}
3603
3604
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003605void csrResetCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce, tANI_BOOLEAN updateRiva )
Jeff Johnson295189b2012-06-20 16:38:30 -07003606{
3607 if( fForce || (csrIs11dSupported( pMac ) && (!pMac->scan.f11dInfoReset)))
3608 {
3609
3610#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3611 {
3612 vos_log_802_11d_pkt_type *p11dLog;
3613 int Index;
3614
3615 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
3616 if(p11dLog)
3617 {
3618 p11dLog->eventId = WLAN_80211D_EVENT_RESET;
Kiet Lam64c1b492013-07-12 13:56:44 +05303619 vos_mem_copy(p11dLog->countryCode, pMac->scan.countryCodeCurrent, 3);
Jeff Johnson295189b2012-06-20 16:38:30 -07003620 p11dLog->numChannel = pMac->scan.base20MHzChannels.numChannels;
3621 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
3622 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303623 vos_mem_copy(p11dLog->Channels,
3624 pMac->scan.base20MHzChannels.channelList,
3625 p11dLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07003626 for (Index=0; Index < pMac->scan.base20MHzChannels.numChannels; Index++)
3627 {
3628 p11dLog->TxPwr[Index] = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
3629 }
3630 }
3631 if(!pMac->roam.configParam.Is11dSupportEnabled)
3632 {
3633 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
3634 }
3635 else if(pMac->roam.configParam.fEnforceDefaultDomain)
3636 {
3637 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
3638 }
3639 else
3640 {
3641 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
3642 }
3643 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
3644 }
3645 }
3646#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3647
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003648 csrPruneChannelListForMode(pMac, &pMac->scan.baseChannels);
3649 csrPruneChannelListForMode(pMac, &pMac->scan.base20MHzChannels);
3650
Jeff Johnson295189b2012-06-20 16:38:30 -07003651 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_FALSE);
3652 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_TRUE);
3653 // ... and apply the channel list, power settings, and the country code.
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003654 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.base20MHzChannels, pMac->scan.countryCodeCurrent, updateRiva );
Jeff Johnson295189b2012-06-20 16:38:30 -07003655 // clear the 11d channel list
Kiet Lam64c1b492013-07-12 13:56:44 +05303656 vos_mem_set(&pMac->scan.channels11d, sizeof(pMac->scan.channels11d), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003657 pMac->scan.f11dInfoReset = eANI_BOOLEAN_TRUE;
3658 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_FALSE;
3659 }
3660
3661 return;
3662}
3663
3664
3665eHalStatus csrResetCountryCodeInformation(tpAniSirGlobal pMac, tANI_BOOLEAN *pfRestartNeeded)
3666{
3667 eHalStatus status = eHAL_STATUS_SUCCESS;
3668 tANI_BOOLEAN fRestart = eANI_BOOLEAN_FALSE;
3669
3670 //Use the Country code and domain from EEPROM
Kiet Lam64c1b492013-07-12 13:56:44 +05303671 vos_mem_copy(pMac->scan.countryCodeCurrent, pMac->scan.countryCodeDefault,
3672 WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07003673 csrSetRegulatoryDomain(pMac, pMac->scan.domainIdCurrent, &fRestart);
Jeff Johnson43971f52012-07-17 12:26:56 -07003674 if( ((eANI_BOOLEAN_FALSE == fRestart) || (pfRestartNeeded == NULL) )
3675 && !csrIsInfraConnected(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -07003676 {
3677 //Only reset the country info if we don't need to restart
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003678 csrResetCountryInformation(pMac, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07003679 }
3680 if(pfRestartNeeded)
3681 {
3682 *pfRestartNeeded = fRestart;
3683 }
3684
3685 return (status);
3686}
3687
3688
3689eHalStatus csrSetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pCountry, tANI_BOOLEAN *pfRestartNeeded)
3690{
3691 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
3692 v_REGDOMAIN_t domainId;
3693
3694 if(pCountry)
3695 {
Kiet Lam6c583332013-10-14 05:37:09 +05303696 status = csrGetRegulatoryDomainForCountry(pMac, pCountry, &domainId, COUNTRY_USER);
Jeff Johnson295189b2012-06-20 16:38:30 -07003697 if(HAL_STATUS_SUCCESS(status))
3698 {
3699 status = csrSetRegulatoryDomain(pMac, domainId, pfRestartNeeded);
3700 if(HAL_STATUS_SUCCESS(status))
3701 {
3702 //We don't need to check the pMac->roam.configParam.fEnforceDefaultDomain flag here,
3703 //csrSetRegulatoryDomain will fail if the country doesn't fit our domain criteria.
Kiet Lam64c1b492013-07-12 13:56:44 +05303704 vos_mem_copy(pMac->scan.countryCodeCurrent, pCountry, WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07003705 if((pfRestartNeeded == NULL) || !(*pfRestartNeeded))
3706 {
3707 //Simply set it to cfg. If we need to restart, restart will apply it to the CFG
3708 csrSetCfgCountryCode(pMac, pCountry);
3709 }
3710 }
3711 }
3712 }
3713
3714 return (status);
3715}
3716
3717
3718
3719//caller allocated memory for pNumChn and pChnPowerInfo
3720//As input, *pNumChn has the size of the array of pChnPowerInfo
3721//Upon return, *pNumChn has the number of channels assigned.
3722void csrGetChannelPowerInfo( tpAniSirGlobal pMac, tDblLinkList *pList,
3723 tANI_U32 *pNumChn, tChannelListWithPower *pChnPowerInfo)
3724{
3725 tListElem *pEntry;
3726 tANI_U32 chnIdx = 0, idx;
3727 tCsrChannelPowerInfo *pChannelSet;
3728
3729 //Get 2.4Ghz first
3730 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
3731 while( pEntry && (chnIdx < *pNumChn) )
3732 {
3733 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3734 if ( 1 != pChannelSet->interChannelOffset )
3735 {
3736 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
3737 {
3738 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
3739 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
3740 }
3741 }
3742 else
3743 {
3744 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
3745 {
3746 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + idx);
3747 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
3748 }
3749 }
3750
3751 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
3752 }
3753 *pNumChn = chnIdx;
3754
3755 return ;
3756}
3757
3758
3759
3760void csrApplyCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce )
3761{
3762 v_REGDOMAIN_t domainId;
3763 eHalStatus status = eHAL_STATUS_SUCCESS;
3764
3765 do
3766 {
3767 if( !csrIs11dSupported( pMac ) || 0 == pMac->scan.channelOf11dInfo) break;
3768 if( pMac->scan.fAmbiguous11dInfoFound )
3769 {
3770 // ambiguous info found
3771 //Restore te default domain as well
Kiet Lam6c583332013-10-14 05:37:09 +05303772 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
3773 pMac, pMac->scan.countryCodeCurrent,
3774 &domainId, COUNTRY_QUERY)))
Jeff Johnson295189b2012-06-20 16:38:30 -07003775 {
3776 pMac->scan.domainIdCurrent = domainId;
3777 }
3778 else
3779 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003780 smsLog(pMac, LOGE, FL(" failed to get domain from currentCountryCode %02X%02X"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003781 pMac->scan.countryCodeCurrent[0], pMac->scan.countryCodeCurrent[1]);
3782 }
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003783 csrResetCountryInformation( pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE );
Jeff Johnson295189b2012-06-20 16:38:30 -07003784 break;
3785 }
3786 if ( pMac->scan.f11dInfoApplied && !fForce ) break;
Kiet Lam6c583332013-10-14 05:37:09 +05303787 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
3788 pMac, pMac->scan.countryCode11d,
3789 &domainId, COUNTRY_QUERY)))
Jeff Johnson295189b2012-06-20 16:38:30 -07003790 {
3791 //Check whether we need to enforce default domain
3792 if( ( !pMac->roam.configParam.fEnforceDefaultDomain ) ||
3793 (pMac->scan.domainIdCurrent == domainId) )
3794 {
3795
3796#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3797 {
3798 vos_log_802_11d_pkt_type *p11dLog;
3799 tChannelListWithPower chnPwrInfo[WNI_CFG_VALID_CHANNEL_LIST_LEN];
3800 tANI_U32 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN, nTmp;
3801
3802 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
3803 if(p11dLog)
3804 {
3805 p11dLog->eventId = WLAN_80211D_EVENT_COUNTRY_SET;
Kiet Lam64c1b492013-07-12 13:56:44 +05303806 vos_mem_copy(p11dLog->countryCode, pMac->scan.countryCode11d, 3);
Jeff Johnson295189b2012-06-20 16:38:30 -07003807 p11dLog->numChannel = pMac->scan.channels11d.numChannels;
3808 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
3809 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303810 vos_mem_copy(p11dLog->Channels,
3811 pMac->scan.channels11d.channelList,
3812 p11dLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07003813 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList24,
3814 &nChnInfo, chnPwrInfo);
3815 nTmp = nChnInfo;
3816 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN - nTmp;
3817 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList5G,
3818 &nChnInfo, &chnPwrInfo[nTmp]);
3819 for(nTmp = 0; nTmp < p11dLog->numChannel; nTmp++)
3820 {
3821 for(nChnInfo = 0; nChnInfo < WNI_CFG_VALID_CHANNEL_LIST_LEN; nChnInfo++)
3822 {
3823 if(p11dLog->Channels[nTmp] == chnPwrInfo[nChnInfo].chanId)
3824 {
3825 p11dLog->TxPwr[nTmp] = chnPwrInfo[nChnInfo].pwr;
3826 break;
3827 }
3828 }
3829 }
3830 }
3831 if(!pMac->roam.configParam.Is11dSupportEnabled)
3832 {
3833 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
3834 }
3835 else if(pMac->roam.configParam.fEnforceDefaultDomain)
3836 {
3837 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
3838 }
3839 else
3840 {
3841 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
3842 }
3843 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
3844 }
3845 }
3846#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3847 if(pMac->scan.domainIdCurrent != domainId)
3848 {
Jeff Johnson295189b2012-06-20 16:38:30 -07003849 smsLog(pMac, LOGW, FL("Domain Changed Old %d, new %d"),
3850 pMac->scan.domainIdCurrent, domainId);
Abhishek Singha306a442013-11-07 18:39:01 +05303851 status = WDA_SetRegDomain(pMac, domainId, eSIR_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07003852 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003853 if (status != eHAL_STATUS_SUCCESS)
3854 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003855 smsLog( pMac, LOGE, FL(" fail to set regId %d"), domainId );
Jeff Johnson295189b2012-06-20 16:38:30 -07003856 }
3857 pMac->scan.domainIdCurrent = domainId;
Kiet Lam6c583332013-10-14 05:37:09 +05303858#ifndef CONFIG_ENABLE_LINUX_REG
Kiet Lambb14e952013-11-19 14:58:29 +05303859 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.base20MHzChannels,
3860 pMac->scan.countryCodeCurrent, eANI_BOOLEAN_TRUE );
Kiet Lam6c583332013-10-14 05:37:09 +05303861#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07003862 // switch to active scans using this new channel list
3863 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
3864 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_TRUE;
3865 pMac->scan.f11dInfoReset = eANI_BOOLEAN_FALSE;
3866 }
3867 }
3868
3869 } while( 0 );
3870
3871 return;
3872}
3873
3874
3875
3876tANI_BOOLEAN csrSave11dCountryString( tpAniSirGlobal pMac, tANI_U8 *pCountryCode,
3877 tANI_BOOLEAN fForce)
3878{
3879 tANI_BOOLEAN fCountryStringChanged = FALSE, fUnknownCountryCode = FALSE;
3880 tANI_U32 i;
Kiet Lam6c583332013-10-14 05:37:09 +05303881 v_REGDOMAIN_t regd;
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08003882 tANI_BOOLEAN fCountryNotPresentInDriver = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003883
3884 // convert to UPPER here so we are assured the strings are always in upper case.
3885 for( i = 0; i < 3; i++ )
3886 {
3887 pCountryCode[ i ] = (tANI_U8)csrToUpper( pCountryCode[ i ] );
3888 }
3889
3890 // Some of the 'old' Cisco 350 series AP's advertise NA as the country code (for North America ??).
3891 // NA is not a valid country code or domain so let's allow this by changing it to the proper
3892 // country code (which is US). We've also seen some NETGEAR AP's that have "XX " as the country code
3893 // with valid 2.4 GHz US channel information. If we cannot find the country code advertised in the
3894 // 11d information element, let's default to US.
Kiet Lam6c583332013-10-14 05:37:09 +05303895 if ( !HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(pMac,
3896 pCountryCode,
3897 &regd,
3898 COUNTRY_QUERY) ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003899 {
3900 // Check the enforcement first
3901 if( pMac->roam.configParam.fEnforceDefaultDomain || pMac->roam.configParam.fEnforceCountryCodeMatch )
3902 {
3903 fUnknownCountryCode = TRUE;
3904 }
3905 else
3906 {
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08003907 fCountryNotPresentInDriver = TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003908 }
3909 }
Tushnim Bhattacharyyac3c1e8e2013-10-29 17:27:43 -07003910 //right now, even if we don't find the CC in driver we set to world. Making
3911 //sure countryCode11d doesn't get updated with the invalid CC, instead
3912 //reflect the world CC
3913 else if (REGDOMAIN_WORLD == regd)
3914 {
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08003915 fCountryNotPresentInDriver = TRUE;
Tushnim Bhattacharyyac3c1e8e2013-10-29 17:27:43 -07003916 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003917
3918 // We've seen some of the AP's improperly put a 0 for the third character of the country code.
3919 // spec says valid charcters are 'O' (for outdoor), 'I' for Indoor, or ' ' (space; for either).
3920 // if we see a 0 in this third character, let's change it to a ' '.
3921 if ( 0 == pCountryCode[ 2 ] )
3922 {
3923 pCountryCode[ 2 ] = ' ';
3924 }
3925
3926 if( !fUnknownCountryCode )
3927 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303928 fCountryStringChanged = (!vos_mem_compare(pMac->scan.countryCode11d, pCountryCode, 2));
Jeff Johnson295189b2012-06-20 16:38:30 -07003929
3930
3931 if(( 0 == pMac->scan.countryCode11d[ 0 ] && 0 == pMac->scan.countryCode11d[ 1 ] )
3932 || (fForce))
3933 {
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08003934 if (!fCountryNotPresentInDriver)
3935 {
3936 // this is the first .11d information
3937 vos_mem_copy(pMac->scan.countryCode11d, pCountryCode,
Kiet Lam64c1b492013-07-12 13:56:44 +05303938 sizeof( pMac->scan.countryCode11d ));
Tushnim Bhattacharyya582ac1d2013-11-07 23:44:09 -08003939
3940 }
3941 else
3942 {
3943 pMac->scan.countryCode11d[0] = '0';
3944 pMac->scan.countryCode11d[1] = '0';
3945 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003946 }
3947 }
3948
3949 return( fCountryStringChanged );
3950}
3951
3952
3953void csrSaveChannelPowerForBand( tpAniSirGlobal pMac, tANI_BOOLEAN fPopulate5GBand )
3954{
3955 tANI_U32 Index, count=0;
3956 tSirMacChanInfo *pChanInfo;
3957 tSirMacChanInfo *pChanInfoStart;
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08003958 tANI_S32 maxChannelIndex;
3959
3960 maxChannelIndex = ( pMac->scan.base20MHzChannels.numChannels < WNI_CFG_VALID_CHANNEL_LIST_LEN ) ?
3961 pMac->scan.base20MHzChannels.numChannels : WNI_CFG_VALID_CHANNEL_LIST_LEN ;
Jeff Johnson295189b2012-06-20 16:38:30 -07003962
Kiet Lam64c1b492013-07-12 13:56:44 +05303963 pChanInfo = vos_mem_malloc(sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN);
3964 if ( NULL != pChanInfo )
Jeff Johnson295189b2012-06-20 16:38:30 -07003965 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303966 vos_mem_set(pChanInfo, sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003967 pChanInfoStart = pChanInfo;
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08003968 for (Index=0; Index < maxChannelIndex; Index++)
Jeff Johnson295189b2012-06-20 16:38:30 -07003969 {
3970 if ((fPopulate5GBand && (CSR_IS_CHANNEL_5GHZ(pMac->scan.defaultPowerTable[Index].chanId))) ||
3971 (!fPopulate5GBand && (CSR_IS_CHANNEL_24GHZ(pMac->scan.defaultPowerTable[Index].chanId))) )
3972 {
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08003973 if(count >= WNI_CFG_VALID_CHANNEL_LIST_LEN)
3974 {
3975 smsLog( pMac, LOGW, FL(" csrSaveChannelPowerForBand, count exceeded, count = %d"), count);
3976 break;
3977 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003978 pChanInfo->firstChanNum = pMac->scan.defaultPowerTable[Index].chanId;
3979 pChanInfo->numChannels = 1;
3980 pChanInfo->maxTxPower = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
3981 pChanInfo++;
3982 count++;
3983 }
3984 }
3985 if(count)
3986 {
3987 csrSaveToChannelPower2G_5G( pMac, count * sizeof(tSirMacChanInfo), pChanInfoStart );
3988 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303989 vos_mem_free(pChanInfoStart);
Jeff Johnson295189b2012-06-20 16:38:30 -07003990 }
3991}
3992
3993
3994void csrSetOppositeBandChannelInfo( tpAniSirGlobal pMac )
3995{
3996 tANI_BOOLEAN fPopulate5GBand = FALSE;
3997
3998 do
3999 {
4000 // if this is not a dual band product, then we don't need to set the opposite
4001 // band info. We only work in one band so no need to look in the other band.
4002 if ( !CSR_IS_OPEARTING_DUAL_BAND( pMac ) ) break;
4003 // if we found channel info on the 5.0 band and...
4004 if ( CSR_IS_CHANNEL_5GHZ( pMac->scan.channelOf11dInfo ) )
4005 {
4006 // and the 2.4 band is empty, then populate the 2.4 channel info
Kiet Lam8d985a02013-10-11 03:39:41 +05304007 if ( !csrLLIsListEmpty( &pMac->scan.channelPowerInfoList24, LL_ACCESS_LOCK ) ) break;
Jeff Johnson295189b2012-06-20 16:38:30 -07004008 fPopulate5GBand = FALSE;
4009 }
4010 else
4011 {
4012 // else, we found channel info in the 2.4 GHz band. If the 5.0 band is empty
4013 // set the 5.0 band info from the 2.4 country code.
Kiet Lam8d985a02013-10-11 03:39:41 +05304014 if ( !csrLLIsListEmpty( &pMac->scan.channelPowerInfoList5G, LL_ACCESS_LOCK ) ) break;
Jeff Johnson295189b2012-06-20 16:38:30 -07004015 fPopulate5GBand = TRUE;
4016 }
4017 csrSaveChannelPowerForBand( pMac, fPopulate5GBand );
4018
4019 } while( 0 );
4020}
4021
4022
4023tANI_BOOLEAN csrIsSupportedChannel(tpAniSirGlobal pMac, tANI_U8 channelId)
4024{
4025 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
4026 tANI_U32 i;
4027
4028 //Make sure it is a channel that is in our supported list.
4029 for ( i = 0; i < pMac->scan.baseChannels.numChannels; i++ )
4030 {
4031 if ( channelId == pMac->scan.baseChannels.channelList[i] )
4032 {
4033 fRet = eANI_BOOLEAN_TRUE;
4034 break;
4035 }
4036 }
4037
4038 //If it is configured to limit a set of the channels
4039 if( fRet && pMac->roam.configParam.fEnforce11dChannels )
4040 {
4041 fRet = eANI_BOOLEAN_FALSE;
4042 for ( i = 0; i < pMac->scan.base20MHzChannels.numChannels; i++ )
4043 {
4044 if ( channelId == pMac->scan.base20MHzChannels.channelList[i] )
4045 {
4046 fRet = eANI_BOOLEAN_TRUE;
4047 break;
4048 }
4049 }
4050 }
4051
4052 return (fRet);
4053}
4054
4055
4056
4057//bSize specify the buffer size of pChannelList
4058tANI_U8 csrGetChannelListFromChannelSet( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 bSize, tCsrChannelPowerInfo *pChannelSet )
4059{
4060 tANI_U8 i, j = 0, chnId;
4061
4062 bSize = CSR_MIN(bSize, pChannelSet->numChannels);
4063 for( i = 0; i < bSize; i++ )
4064 {
4065 chnId = (tANI_U8)(pChannelSet->firstChannel + ( i * pChannelSet->interChannelOffset ));
4066 if ( csrIsSupportedChannel( pMac, chnId ) )
4067 {
4068 pChannelList[j++] = chnId;
4069 }
4070 }
4071
4072 return (j);
4073}
4074
4075
4076
4077//bSize -- specify the buffer size of pChannelList
4078void csrConstructCurrentValidChannelList( tpAniSirGlobal pMac, tDblLinkList *pChannelSetList,
4079 tANI_U8 *pChannelList, tANI_U8 bSize, tANI_U8 *pNumChannels )
4080{
4081 tListElem *pEntry;
4082 tCsrChannelPowerInfo *pChannelSet;
4083 tANI_U8 numChannels;
4084 tANI_U8 *pChannels;
4085
4086 if( pChannelSetList && pChannelList && pNumChannels )
4087 {
4088 pChannels = pChannelList;
4089 *pNumChannels = 0;
4090 pEntry = csrLLPeekHead( pChannelSetList, LL_ACCESS_LOCK );
4091 while( pEntry )
4092 {
4093 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
4094 numChannels = csrGetChannelListFromChannelSet( pMac, pChannels, bSize, pChannelSet );
4095 pChannels += numChannels;
4096 *pNumChannels += numChannels;
4097 pEntry = csrLLNext( pChannelSetList, pEntry, LL_ACCESS_LOCK );
4098 }
4099 }
4100}
4101
4102
4103/*
4104 * 802.11D only: Gather 11d IE via beacon or Probe response and store them in pAdapter->channels11d
4105*/
4106tANI_BOOLEAN csrLearnCountryInformation( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc,
4107 tDot11fBeaconIEs *pIes, tANI_BOOLEAN fForce)
4108{
Jeff Johnson295189b2012-06-20 16:38:30 -07004109 eHalStatus status;
4110 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
4111 v_REGDOMAIN_t domainId;
4112 tDot11fBeaconIEs *pIesLocal = pIes;
4113
Jeff Johnson295189b2012-06-20 16:38:30 -07004114 if (VOS_STA_SAP_MODE == vos_get_conparam ())
4115 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07004116
4117 do
4118 {
4119 // check if .11d support is enabled
4120 if( !csrIs11dSupported( pMac ) ) break;
4121 if( !pIesLocal && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc, &pIesLocal))) )
4122 {
4123 break;
4124 }
4125 // check if country information element is present
4126 if(!pIesLocal->Country.present)
4127 {
4128 //No country info
4129 break;
4130 }
4131
4132 if( csrSave11dCountryString( pMac, pIesLocal->Country.country, fForce ) )
4133 {
4134 // country string changed, this should not happen
4135 //Need to check whether we care about this BSS' domain info
4136 //If it doesn't match of the connected profile or roaming profile, let's ignore it
4137 tANI_U32 i;
4138 tCsrRoamSession *pSession;
4139
4140 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
4141 {
4142 if( CSR_IS_SESSION_VALID( pMac, i ) )
4143 {
4144 pSession = CSR_GET_SESSION( pMac, i );
4145 if(pSession->pCurRoamProfile)
4146 {
4147 tCsrScanResultFilter filter;
4148
Kiet Lam64c1b492013-07-12 13:56:44 +05304149 vos_mem_set(&filter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004150 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, &filter);
4151 if(HAL_STATUS_SUCCESS(status))
4152 {
4153 tANI_BOOLEAN fMatch = csrMatchBSS(pMac, pSirBssDesc, &filter, NULL, NULL, NULL, NULL);
4154 //Free the resource first
4155 csrFreeScanFilter( pMac, &filter );
4156 if(fMatch)
4157 {
Arif Hussaina7c8e412013-11-20 11:06:42 -08004158 smsLog(pMac, LOGW, "Matching roam profile "
4159 "BSSID " MAC_ADDRESS_STR
4160 " causing ambiguous domain info",
4161 MAC_ADDR_ARRAY(pSirBssDesc->bssId));
Jeff Johnson295189b2012-06-20 16:38:30 -07004162 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_TRUE;
4163 break;
4164 }
4165 }
4166 }
4167 else if( csrIsConnStateConnected(pMac, i))
4168 {
4169 //Reach here only when the currention is base on no profile.
4170 //User doesn't give profile and just connect to anything.
4171 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile, pSirBssDesc, pIesLocal))
4172 {
Arif Hussaina7c8e412013-11-20 11:06:42 -08004173 smsLog(pMac, LOGW, "Matching connect profile BSSID "
4174 MAC_ADDRESS_STR
4175 " causing ambiguous domain info",
4176 MAC_ADDR_ARRAY(pSirBssDesc->bssId));
Jeff Johnson295189b2012-06-20 16:38:30 -07004177 //Tush
4178 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_TRUE;
4179 if(csrIsBssidMatch(pMac, (tCsrBssid *)&pSirBssDesc->bssId,
4180 &pSession->connectedProfile.bssid))
4181 {
4182 //AP changed the 11d info on the fly, modify cfg
4183 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
4184 fRet = eANI_BOOLEAN_TRUE;
4185 }
4186 break;
4187 }
4188 }
4189 } //valid session
4190 } //for
4191 if ( i == CSR_ROAM_SESSION_MAX )
4192 {
4193 //Check whether we can use this country's 11d information
4194 if( !pMac->roam.configParam.fEnforceDefaultDomain )
4195 {
4196 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_TRUE;
4197 }
4198 else
4199 {
4200 VOS_ASSERT( pMac->scan.domainIdCurrent == pMac->scan.domainIdDefault );
4201 if( HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
Kiet Lam6c583332013-10-14 05:37:09 +05304202 pMac, pIesLocal->Country.country, &domainId,
4203 COUNTRY_QUERY)) &&
Jeff Johnson295189b2012-06-20 16:38:30 -07004204 ( domainId == pMac->scan.domainIdCurrent ) )
4205 {
4206 //Two countries in the same domain
4207 }
4208 }
4209 }
Kiet Lam6c583332013-10-14 05:37:09 +05304210#ifdef CONFIG_ENABLE_LINUX_REG
4211 csrGetRegulatoryDomainForCountry(pMac, pIesLocal->Country.country,
4212 &domainId, COUNTRY_IE);
4213#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004214 }
4215 else //Tush
4216 {
4217 pMac->scan.fCurrent11dInfoMatch = eANI_BOOLEAN_TRUE;
4218 }
4219
4220 //In case that some channels in 5GHz have the same channel number as 2.4GHz (<= 14)
4221 if(CSR_IS_CHANNEL_5GHZ(pSirBssDesc->channelId))
4222 {
4223 tANI_U8 iC;
4224 tSirMacChanInfo* pMacChnSet = (tSirMacChanInfo *)(&pIesLocal->Country.triplets[0]);
4225
4226 for(iC = 0; iC < pIesLocal->Country.num_triplets; iC++)
4227 {
4228 if(CSR_IS_CHANNEL_24GHZ(pMacChnSet[iC].firstChanNum))
4229 {
4230 pMacChnSet[iC].firstChanNum += 200; //*** Where is this 200 defined?
4231 }
4232 }
4233 }
Jeff Johnsonafeb9582013-11-22 18:39:00 -08004234 smsLog(pMac, LOG3, FL(" %d sets each one is %zu"), pIesLocal->Country.num_triplets, sizeof(tSirMacChanInfo));
Jeff Johnsone7245742012-09-05 17:12:55 -07004235
Jeff Johnson295189b2012-06-20 16:38:30 -07004236 // set the indicator of the channel where the country IE was found...
4237 pMac->scan.channelOf11dInfo = pSirBssDesc->channelId;
Kiet Lam6c583332013-10-14 05:37:09 +05304238#ifndef CONFIG_ENABLE_LINUX_REG
Kiet Lam8d985a02013-10-11 03:39:41 +05304239 status = csrGetRegulatoryDomainForCountry(pMac,
Kiet Lam6c583332013-10-14 05:37:09 +05304240 pIesLocal->Country.country, &domainId, COUNTRY_IE);
Kiet Lam8d985a02013-10-11 03:39:41 +05304241 if ( status != eHAL_STATUS_SUCCESS )
4242 {
4243 smsLog( pMac, LOGE, FL(" fail to get regId %d"), domainId );
4244 fRet = eANI_BOOLEAN_FALSE;
4245 break;
4246 }
Venkata Prathyusha Kuntupalli316247e2013-03-15 17:45:25 -07004247 // Checking for Domain Id change
4248 if ( domainId != pMac->scan.domainIdCurrent )
4249 {
Kiet Lam8d985a02013-10-11 03:39:41 +05304250 vos_mem_copy(pMac->scan.countryCode11d,
4251 pIesLocal->Country.country,
4252 sizeof( pMac->scan.countryCode11d ) );
4253 /* Set Current Country code and Current Regulatory domain */
4254 status = csrSetRegulatoryDomain(pMac, domainId, NULL);
4255 if (eHAL_STATUS_SUCCESS != status)
4256 {
4257 smsLog(pMac, LOGE, "Set Reg Domain Fail %d", status);
4258 fRet = eANI_BOOLEAN_FALSE;
4259 return fRet;
4260 }
4261 //csrSetRegulatoryDomain will fail if the country doesn't fit our domain criteria.
4262 vos_mem_copy(pMac->scan.countryCodeCurrent,
4263 pIesLocal->Country.country, WNI_CFG_COUNTRY_CODE_LEN);
4264 //Simply set it to cfg.
Madan Mohan Koyyalamudi0e5922d2013-09-10 15:45:24 +05304265 csrSetCfgCountryCode(pMac, pIesLocal->Country.country);
Kiet Lam8d985a02013-10-11 03:39:41 +05304266
4267 /* overwrite the defualt country code */
4268 vos_mem_copy(pMac->scan.countryCodeDefault,
4269 pMac->scan.countryCodeCurrent,
4270 WNI_CFG_COUNTRY_CODE_LEN);
4271 /* Set Current RegDomain */
Abhishek Singha306a442013-11-07 18:39:01 +05304272 status = WDA_SetRegDomain(pMac, domainId, eSIR_TRUE);
Kiet Lam8d985a02013-10-11 03:39:41 +05304273 if ( status != eHAL_STATUS_SUCCESS )
4274 {
4275 smsLog( pMac, LOGE, FL(" fail to Set regId %d"), domainId );
4276 fRet = eANI_BOOLEAN_FALSE;
4277 return fRet;
4278 }
4279 /* set to default domain ID */
Madan Mohan Koyyalamudi0e5922d2013-09-10 15:45:24 +05304280 pMac->scan.domainIdCurrent = domainId;
Kiet Lam8d985a02013-10-11 03:39:41 +05304281 /* get the channels based on new cc */
4282 status = csrInitGetChannels( pMac );
Jeff Johnson295189b2012-06-20 16:38:30 -07004283
Kiet Lam8d985a02013-10-11 03:39:41 +05304284 if ( status != eHAL_STATUS_SUCCESS )
4285 {
4286 smsLog( pMac, LOGE, FL(" fail to get Channels "));
4287 fRet = eANI_BOOLEAN_FALSE;
4288 return fRet;
4289 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004290
Kiet Lam8d985a02013-10-11 03:39:41 +05304291 /* reset info based on new cc, and we are done */
4292 csrResetCountryInformation(pMac, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
Agarwal Ashishfaef6692014-01-29 19:40:30 +05304293 /* Regulatory Domain Changed, Purge Only scan result
4294 * which does not have channel number belong to 11d
4295 * channel list
4296 */
Srinivas, Dasari42bf7702014-02-07 11:29:53 +05304297 csrScanFilterResults(pMac);
Kiet Lam8d985a02013-10-11 03:39:41 +05304298 }
Kiet Lam6c583332013-10-14 05:37:09 +05304299#endif
4300 fRet = eANI_BOOLEAN_TRUE;
4301
Jeff Johnson295189b2012-06-20 16:38:30 -07004302 } while( 0 );
4303
4304 if( !pIes && pIesLocal )
4305 {
4306 //locally allocated
Kiet Lam64c1b492013-07-12 13:56:44 +05304307 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07004308 }
4309
4310 return( fRet );
4311}
4312
4313
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004314static void csrSaveScanResults( tpAniSirGlobal pMac, tANI_U8 reason )
Jeff Johnson295189b2012-06-20 16:38:30 -07004315{
4316 // initialize this to FALSE. profMoveInterimScanResultsToMainList() routine
4317 // will set this to the channel where an .11d beacon is seen
4318 pMac->scan.channelOf11dInfo = 0;
4319 // if we get any ambiguous .11d information then this will be set to TRUE
4320 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
4321 //Tush
4322 // if we get any ambiguous .11d information, then this will be set to TRUE
4323 // only if the applied 11d info could be found in one of the scan results
4324 pMac->scan.fCurrent11dInfoMatch = eANI_BOOLEAN_FALSE;
4325 // move the scan results from interim list to the main scan list
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004326 csrMoveTempScanResultsToMainList( pMac, reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07004327}
4328
4329
4330void csrReinitScanCmd(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4331{
4332 switch (pCommand->u.scanCmd.reason)
4333 {
4334 case eCsrScanSetBGScanParam:
4335 case eCsrScanAbortBgScan:
4336 if(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList)
4337 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304338 vos_mem_free(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList);
Jeff Johnson295189b2012-06-20 16:38:30 -07004339 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
4340 }
4341 break;
4342 case eCsrScanBGScanAbort:
4343 case eCsrScanBGScanEnable:
4344 case eCsrScanGetScanChnInfo:
4345 break;
4346 case eCsrScanAbortNormalScan:
4347 default:
4348 csrScanFreeRequest(pMac, &pCommand->u.scanCmd.u.scanRequest);
4349 break;
4350 }
4351 if(pCommand->u.scanCmd.pToRoamProfile)
4352 {
4353 csrReleaseProfile(pMac, pCommand->u.scanCmd.pToRoamProfile);
Kiet Lam64c1b492013-07-12 13:56:44 +05304354 vos_mem_free(pCommand->u.scanCmd.pToRoamProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07004355 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304356 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004357}
4358
4359
4360tANI_BOOLEAN csrGetRemainingChannelsFor11dScan( tpAniSirGlobal pMac, tANI_U8 *pChannels, tANI_U8 *pcChannels )
4361{
4362 tANI_U32 index11dChannels, index;
4363 tANI_U32 indexCurrentChannels;
4364 tANI_BOOLEAN fChannelAlreadyScanned;
4365 tANI_U32 len = sizeof(pMac->roam.validChannelList);
4366
4367 *pcChannels = 0;
4368 if ( CSR_IS_11D_INFO_FOUND(pMac) && csrRoamIsChannelValid(pMac, pMac->scan.channelOf11dInfo) )
4369 {
4370 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
4371 {
4372 //Find the channel index where we found the 11d info
4373 for(index = 0; index < len; index++)
4374 {
4375 if(pMac->scan.channelOf11dInfo == pMac->roam.validChannelList[index])
4376 break;
4377 }
4378 //check whether we found the channel index
4379 if(index < len)
4380 {
4381 // Now, look through the 11d channel list and create a list of all channels in the 11d list that are
4382 // NOT in the current channel list. This gives us a list of the new channels that have not been
4383 // scanned. We'll scan this new list so we have a complete set of scan results on all of the domain channels
4384 // initially.
4385 for ( index11dChannels = 0; index11dChannels < pMac->scan.channels11d.numChannels; index11dChannels++ )
4386 {
4387 fChannelAlreadyScanned = eANI_BOOLEAN_FALSE;
4388
4389 for( indexCurrentChannels = 0; indexCurrentChannels < index; indexCurrentChannels++ )
4390 {
4391 if ( pMac->roam.validChannelList[ indexCurrentChannels ] == pMac->scan.channels11d.channelList[ index11dChannels ] )
4392 {
4393 fChannelAlreadyScanned = eANI_BOOLEAN_TRUE;
4394 break;
4395 }
4396 }
4397
4398 if ( !fChannelAlreadyScanned )
4399 {
4400 pChannels[ *pcChannels ] = pMac->scan.channels11d.channelList[ index11dChannels ];
4401 ( *pcChannels )++;
4402 }
4403 }
4404 }
4405 }//GetCFG
4406 }
4407 return( *pcChannels );
4408}
4409
4410
4411eCsrScanCompleteNextCommand csrScanGetNextCommandState( tpAniSirGlobal pMac, tSmeCmd *pCommand, tANI_BOOLEAN fSuccess )
4412{
4413 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
4414
4415 switch( pCommand->u.scanCmd.reason )
4416 {
4417 case eCsrScan11d1:
4418 NextCommand = (fSuccess) ? eCsrNext11dScan1Success : eCsrNext11dScan1Failure;
4419 break;
4420 case eCsrScan11d2:
4421 NextCommand = (fSuccess) ? eCsrNext11dScan2Success : eCsrNext11dScan2Failure;
4422 break;
4423 case eCsrScan11dDone:
4424 NextCommand = eCsrNext11dScanComplete;
4425 break;
4426 case eCsrScanLostLink1:
4427 NextCommand = (fSuccess) ? eCsrNextLostLinkScan1Success : eCsrNextLostLinkScan1Failed;
4428 break;
4429 case eCsrScanLostLink2:
4430 NextCommand = (fSuccess) ? eCsrNextLostLinkScan2Success : eCsrNextLostLinkScan2Failed;
4431 break;
4432 case eCsrScanLostLink3:
4433 NextCommand = (fSuccess) ? eCsrNextLostLinkScan3Success : eCsrNextLostLinkScan3Failed;
4434 break;
4435 case eCsrScanForSsid:
4436 NextCommand = (fSuccess) ? eCsrNexteScanForSsidSuccess : eCsrNexteScanForSsidFailure;
4437 break;
4438 case eCsrScanForCapsChange:
4439 NextCommand = eCsrNextCapChangeScanComplete; //don't care success or not
4440 break;
4441 case eCsrScanIdleScan:
4442 NextCommand = eCsrNextIdleScanComplete;
4443 break;
4444 default:
4445 NextCommand = eCsrNextScanNothing;
4446 break;
4447 }
4448 return( NextCommand );
4449}
4450
4451
4452//Return whether the pCommand is finished.
4453tANI_BOOLEAN csrHandleScan11d1Failure(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4454{
4455 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
4456
4457 //Apply back the default setting and passively scan one more time.
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004458 csrResetCountryInformation(pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07004459 pCommand->u.scanCmd.reason = eCsrScan11d2;
4460 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
4461 {
4462 fRet = eANI_BOOLEAN_FALSE;
4463 }
4464
4465 return (fRet);
4466}
4467
4468
4469tANI_BOOLEAN csrHandleScan11dSuccess(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4470{
4471 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
4472 tANI_U8 *pChannels;
4473 tANI_U8 cChannels;
4474
Kiet Lam64c1b492013-07-12 13:56:44 +05304475 pChannels = vos_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
4476 if ( NULL != pChannels )
Jeff Johnson295189b2012-06-20 16:38:30 -07004477 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304478 vos_mem_set(pChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004479 if ( csrGetRemainingChannelsFor11dScan( pMac, pChannels, &cChannels ) )
4480 {
4481 pCommand->u.scanCmd.reason = eCsrScan11dDone;
4482 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
4483 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304484 vos_mem_free(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -07004485 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004486 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304487 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(cChannels);
4488 if ( NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07004489 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304490 vos_mem_copy(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
4491 pChannels, cChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07004492 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = cChannels;
4493 pCommand->u.scanCmd.u.scanRequest.requestType = eCSR_SCAN_REQUEST_FULL_SCAN;
4494 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
4495 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
4496 {
4497 //Reuse the same command buffer
4498 fRet = eANI_BOOLEAN_FALSE;
4499 }
4500 }
4501 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304502 vos_mem_free(pChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07004503 }
4504
4505 return (fRet);
4506}
4507
4508//Return whether the command should be removed
4509tANI_BOOLEAN csrScanComplete( tpAniSirGlobal pMac, tSirSmeScanRsp *pScanRsp )
4510{
4511 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
4512 tListElem *pEntry;
4513 tSmeCmd *pCommand;
4514 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
4515 tANI_BOOLEAN fSuccess;
4516
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05304517 if (pMac->fScanOffload)
4518 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
4519 else
4520 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07004521
4522 if ( pEntry )
4523 {
4524 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
4525
4526 // If the head of the queue is Active and it is a SCAN command, remove
4527 // and put this on the Free queue.
4528 if ( eSmeCommandScan == pCommand->command )
4529 {
4530 tANI_U32 sessionId = pCommand->sessionId;
4531
4532 if(eSIR_SME_SUCCESS != pScanRsp->statusCode)
4533 {
4534 fSuccess = eANI_BOOLEAN_FALSE;
4535 }
4536 else
4537 {
4538 //pMac->scan.tempScanResults is not empty meaning the scan found something
4539 //This check only valid here because csrSaveScanresults is not yet called
4540 fSuccess = (!csrLLIsListEmpty(&pMac->scan.tempScanResults, LL_ACCESS_LOCK));
4541 }
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004542 csrSaveScanResults(pMac, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07004543
4544#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4545 {
4546 vos_log_scan_pkt_type *pScanLog = NULL;
4547 tScanResultHandle hScanResult;
4548 tCsrScanResultInfo *pScanResult;
4549 tDot11fBeaconIEs *pIes;
4550 int n = 0, c = 0;
4551
4552 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
4553 if(pScanLog)
4554 {
4555 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
4556 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
4557 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
4558 {
4559 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_RSP;
4560 }
4561 else
4562 {
4563 if( eSIR_PASSIVE_SCAN != pMac->scan.curScanType )
4564 {
4565 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_RSP;
4566 }
4567 else
4568 {
4569 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_RSP;
4570 }
4571 }
4572 if(eSIR_SME_SUCCESS == pScanRsp->statusCode)
4573 {
4574 if(HAL_STATUS_SUCCESS(csrScanGetResult(pMac, NULL, &hScanResult)))
4575 {
4576 while(((pScanResult = csrScanResultGetNext(pMac, hScanResult)) != NULL))
4577 {
4578 if( n < VOS_LOG_MAX_NUM_BSSID )
4579 {
4580 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pScanResult->BssDescriptor, &pIes)))
4581 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004582 smsLog(pMac, LOGE, FL(" fail to parse IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07004583 break;
4584 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304585 vos_mem_copy(pScanLog->bssid[n],
4586 pScanResult->BssDescriptor.bssId, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07004587 if(pIes && pIes->SSID.present && VOS_LOG_MAX_SSID_SIZE >= pIes->SSID.num_ssid)
4588 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304589 vos_mem_copy(pScanLog->ssid[n],
4590 pIes->SSID.ssid, pIes->SSID.num_ssid);
Jeff Johnson295189b2012-06-20 16:38:30 -07004591 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304592 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07004593 n++;
4594 }
4595 c++;
4596 }
4597 pScanLog->numSsid = (v_U8_t)n;
4598 pScanLog->totalSsid = (v_U8_t)c;
4599 csrScanResultPurge(pMac, hScanResult);
4600 }
4601 }
4602 else
4603 {
4604 pScanLog->status = WLAN_SCAN_STATUS_FAILURE;
4605 }
4606 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
4607 }
4608 }
4609#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4610
4611 NextCommand = csrScanGetNextCommandState(pMac, pCommand, fSuccess);
4612 //We reuse the command here instead reissue a new command
4613 switch(NextCommand)
4614 {
4615 case eCsrNext11dScan1Success:
4616 case eCsrNext11dScan2Success:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004617 smsLog( pMac, LOG2, FL("11dScan1/3 produced results. Reissue Active scan..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004618 // if we found country information, no need to continue scanning further, bail out
4619 fRemoveCommand = eANI_BOOLEAN_TRUE;
4620 NextCommand = eCsrNext11dScanComplete;
4621 break;
4622 case eCsrNext11dScan1Failure:
4623 //We are not done yet. 11d scan fail once. We will try to reset anything and do it over again
4624 //The only meaningful thing for this retry is that we cannot find 11d information after a reset so
4625 //we clear the "old" 11d info and give it once more chance
4626 fRemoveCommand = csrHandleScan11d1Failure(pMac, pCommand);
4627 if(fRemoveCommand)
4628 {
4629 NextCommand = eCsrNext11dScanComplete;
4630 }
4631 break;
4632 case eCsrNextLostLinkScan1Success:
4633 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink1)))
4634 {
4635 csrScanHandleFailedLostlink1(pMac, sessionId);
4636 }
4637 break;
4638 case eCsrNextLostLinkScan2Success:
4639 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink2)))
4640 {
4641 csrScanHandleFailedLostlink2(pMac, sessionId);
4642 }
4643 break;
4644 case eCsrNextLostLinkScan3Success:
4645 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink3)))
4646 {
4647 csrScanHandleFailedLostlink3(pMac, sessionId);
4648 }
4649 break;
4650 case eCsrNextLostLinkScan1Failed:
4651 csrScanHandleFailedLostlink1(pMac, sessionId);
4652 break;
4653 case eCsrNextLostLinkScan2Failed:
4654 csrScanHandleFailedLostlink2(pMac, sessionId);
4655 break;
4656 case eCsrNextLostLinkScan3Failed:
4657 csrScanHandleFailedLostlink3(pMac, sessionId);
4658 break;
4659 case eCsrNexteScanForSsidSuccess:
4660 csrScanHandleSearchForSSID(pMac, pCommand);
4661 break;
4662 case eCsrNexteScanForSsidFailure:
4663 csrScanHandleSearchForSSIDFailure(pMac, pCommand);
4664 break;
4665 case eCsrNextIdleScanComplete:
4666 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
4667 break;
4668 case eCsrNextCapChangeScanComplete:
4669 csrScanHandleCapChangeScanComplete(pMac, sessionId);
4670 break;
4671 default:
4672
4673 break;
4674 }
4675 }
4676 else
4677 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004678 smsLog( pMac, LOGW, FL("Scan Completion called but SCAN command is not ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004679 fRemoveCommand = eANI_BOOLEAN_FALSE;
4680 }
4681 }
4682 else
4683 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004684 smsLog( pMac, LOGW, FL("Scan Completion called but NO commands are ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004685 fRemoveCommand = eANI_BOOLEAN_FALSE;
4686 }
4687
4688 return( fRemoveCommand );
4689}
4690
4691
4692
4693static void csrScanRemoveDupBssDescriptionFromInterimList( tpAniSirGlobal pMac,
4694 tSirBssDescription *pSirBssDescr,
4695 tDot11fBeaconIEs *pIes)
4696{
4697 tListElem *pEntry;
4698 tCsrScanResult *pCsrBssDescription;
4699
4700 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
4701 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
4702 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
4703 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
4704 while( pEntry )
4705 {
4706 pCsrBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
4707
4708 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
4709 // matches
4710
4711 if ( csrIsDuplicateBssDescription( pMac, &pCsrBssDescription->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07004712 pSirBssDescr, pIes, FALSE ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07004713 {
4714 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
4715 ((tANI_S32)pCsrBssDescription->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
4716
4717 // Remove the 'old' entry from the list....
4718 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK ) )
4719 {
4720 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pCsrBssDescription->Result.BssDescriptor);
4721 // we need to free the memory associated with this node
4722 csrFreeScanResultEntry( pMac, pCsrBssDescription );
4723 }
4724
4725 // If we found a match, we can stop looking through the list.
4726 break;
4727 }
4728
4729 pEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK );
4730 }
4731}
4732
4733
4734
4735//Caller allocated memory pfNewBssForConn to return whether new candidate for
4736//current connection is found. Cannot be NULL
4737tCsrScanResult *csrScanSaveBssDescriptionToInterimList( tpAniSirGlobal pMac,
4738 tSirBssDescription *pBSSDescription,
4739 tDot11fBeaconIEs *pIes)
4740{
4741 tCsrScanResult *pCsrBssDescription = NULL;
4742 tANI_U32 cbBSSDesc;
4743 tANI_U32 cbAllocated;
Jeff Johnson295189b2012-06-20 16:38:30 -07004744
4745 // figure out how big the BSS description is (the BSSDesc->length does NOT
4746 // include the size of the length field itself).
4747 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
4748
4749 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
4750
Kiet Lam64c1b492013-07-12 13:56:44 +05304751 pCsrBssDescription = vos_mem_malloc(cbAllocated);
4752 if ( NULL != pCsrBssDescription )
Jeff Johnson295189b2012-06-20 16:38:30 -07004753 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304754 vos_mem_set(pCsrBssDescription, cbAllocated, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004755 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Kiet Lam64c1b492013-07-12 13:56:44 +05304756 vos_mem_copy(&pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc );
Jeff Johnson295189b2012-06-20 16:38:30 -07004757 //Save SSID separately for later use
4758 if( pIes->SSID.present && !csrIsNULLSSID(pIes->SSID.ssid, pIes->SSID.num_ssid) )
4759 {
4760 //SSID not hidden
Madan Mohan Koyyalamudi4e31b132012-11-02 13:13:52 -07004761 tANI_U32 len = pIes->SSID.num_ssid;
Jeff Johnson295189b2012-06-20 16:38:30 -07004762 if (len > SIR_MAC_MAX_SSID_LENGTH)
4763 {
4764 // truncate to fit in our struct
4765 len = SIR_MAC_MAX_SSID_LENGTH;
4766 }
4767 pCsrBssDescription->Result.ssId.length = len;
4768 pCsrBssDescription->Result.timer = vos_timer_get_system_time();
Kiet Lam64c1b492013-07-12 13:56:44 +05304769 vos_mem_copy(pCsrBssDescription->Result.ssId.ssId, pIes->SSID.ssid, len);
Jeff Johnson295189b2012-06-20 16:38:30 -07004770 }
4771 csrLLInsertTail( &pMac->scan.tempScanResults, &pCsrBssDescription->Link, LL_ACCESS_LOCK );
4772 }
4773
4774 return( pCsrBssDescription );
4775}
4776
4777
4778
4779
4780tANI_BOOLEAN csrIsDuplicateBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc1,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07004781 tSirBssDescription *pSirBssDesc2, tDot11fBeaconIEs *pIes2, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07004782{
4783 tANI_BOOLEAN fMatch = FALSE;
4784 tSirMacCapabilityInfo *pCap1, *pCap2;
4785 tDot11fBeaconIEs *pIes1 = NULL;
Jeff Johnsone7245742012-09-05 17:12:55 -07004786 tDot11fBeaconIEs *pIesTemp = pIes2;
Jeff Johnson295189b2012-06-20 16:38:30 -07004787
4788 pCap1 = (tSirMacCapabilityInfo *)&pSirBssDesc1->capabilityInfo;
4789 pCap2 = (tSirMacCapabilityInfo *)&pSirBssDesc2->capabilityInfo;
4790 if(pCap1->ess == pCap2->ess)
4791 {
4792 if (pCap1->ess &&
Jeff Johnsone7245742012-09-05 17:12:55 -07004793 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId)&&
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07004794 (fForced || (pSirBssDesc1->channelId == pSirBssDesc2->channelId)))
Jeff Johnson295189b2012-06-20 16:38:30 -07004795 {
4796 fMatch = TRUE;
Jeff Johnsone7245742012-09-05 17:12:55 -07004797 // Check for SSID match, if exists
4798 do
4799 {
4800 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
4801 {
4802 break;
4803 }
4804 if( NULL == pIesTemp )
4805 {
4806 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
4807 {
4808 break;
4809 }
4810 }
4811 if(pIes1->SSID.present && pIesTemp->SSID.present)
4812 {
4813 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
4814 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
4815 }
4816 }while(0);
4817
Jeff Johnson295189b2012-06-20 16:38:30 -07004818 }
4819 else if (pCap1->ibss && (pSirBssDesc1->channelId == pSirBssDesc2->channelId))
4820 {
Jeff Johnson295189b2012-06-20 16:38:30 -07004821
4822 do
4823 {
4824 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
4825 {
4826 break;
4827 }
4828 if( NULL == pIesTemp )
4829 {
4830 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
4831 {
4832 break;
4833 }
4834 }
4835 //Same channel cannot have same SSID for different IBSS
4836 if(pIes1->SSID.present && pIesTemp->SSID.present)
4837 {
4838 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
4839 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
4840 }
4841 }while(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004842 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004843 /* In case of P2P devices, ess and ibss will be set to zero */
4844 else if (!pCap1->ess &&
4845 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId))
4846 {
4847 fMatch = TRUE;
4848 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004849 }
4850
4851 if(pIes1)
4852 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304853 vos_mem_free(pIes1);
Jeff Johnson295189b2012-06-20 16:38:30 -07004854 }
Jeff Johnsone7245742012-09-05 17:12:55 -07004855
4856 if( (NULL == pIes2) && pIesTemp )
4857 {
4858 //locally allocated
Kiet Lam64c1b492013-07-12 13:56:44 +05304859 vos_mem_free(pIesTemp);
Jeff Johnsone7245742012-09-05 17:12:55 -07004860 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004861
4862 return( fMatch );
4863}
4864
4865
4866tANI_BOOLEAN csrIsNetworkTypeEqual( tSirBssDescription *pSirBssDesc1, tSirBssDescription *pSirBssDesc2 )
4867{
4868 return( pSirBssDesc1->nwType == pSirBssDesc2->nwType );
4869}
4870
4871
4872//to check whether the BSS matches the dot11Mode
4873static tANI_BOOLEAN csrScanIsBssAllowed(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
4874 tDot11fBeaconIEs *pIes)
4875{
4876 tANI_BOOLEAN fAllowed = eANI_BOOLEAN_FALSE;
4877 eCsrPhyMode phyMode;
4878
4879 if(HAL_STATUS_SUCCESS(csrGetPhyModeFromBss(pMac, pBssDesc, &phyMode, pIes)))
4880 {
4881 switch(pMac->roam.configParam.phyMode)
4882 {
4883 case eCSR_DOT11_MODE_11b:
4884 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
4885 break;
4886 case eCSR_DOT11_MODE_11g:
4887 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
4888 break;
4889 case eCSR_DOT11_MODE_11g_ONLY:
4890 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11g == phyMode);
4891 break;
4892 case eCSR_DOT11_MODE_11a:
4893 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11b != phyMode) && (eCSR_DOT11_MODE_11g != phyMode));
4894 break;
4895 case eCSR_DOT11_MODE_11n_ONLY:
4896 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11n == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
4897 break;
Jeff Johnsone7245742012-09-05 17:12:55 -07004898
4899#ifdef WLAN_FEATURE_11AC
4900 case eCSR_DOT11_MODE_11ac_ONLY:
4901 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11ac == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
4902 break;
4903#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004904 case eCSR_DOT11_MODE_11b_ONLY:
4905 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11b == phyMode);
4906 break;
4907 case eCSR_DOT11_MODE_11a_ONLY:
4908 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a == phyMode);
4909 break;
4910 case eCSR_DOT11_MODE_11n:
Jeff Johnsone7245742012-09-05 17:12:55 -07004911#ifdef WLAN_FEATURE_11AC
4912 case eCSR_DOT11_MODE_11ac:
4913#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004914 case eCSR_DOT11_MODE_TAURUS:
4915 default:
4916 fAllowed = eANI_BOOLEAN_TRUE;
4917 break;
4918 }
4919 }
4920
4921 return (fAllowed);
4922}
4923
4924
4925
4926//Return pIes to caller for future use when returning TRUE.
4927static tANI_BOOLEAN csrScanValidateScanResult( tpAniSirGlobal pMac, tANI_U8 *pChannels,
4928 tANI_U8 numChn, tSirBssDescription *pBssDesc,
4929 tDot11fBeaconIEs **ppIes )
4930{
4931 tANI_BOOLEAN fValidChannel = FALSE;
4932 tDot11fBeaconIEs *pIes = NULL;
4933 tANI_U8 index;
4934
4935 for( index = 0; index < numChn; index++ )
4936 {
4937 // This check relies on the fact that a single BSS description is returned in each
4938 // ScanRsp call, which is the way LIM implemented the scan req/rsp funtions. We changed
4939 // to this model when we ran with a large number of APs. If this were to change, then
4940 // this check would have to mess with removing the bssDescription from somewhere in an
4941 // arbitrary index in the bssDescription array.
4942 if ( pChannels[ index ] == pBssDesc->channelId )
4943 {
4944 fValidChannel = TRUE;
4945 break;
4946 }
4947 }
4948 *ppIes = NULL;
4949 if(fValidChannel)
4950 {
4951 if( HAL_STATUS_SUCCESS( csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIes) ) )
4952 {
4953 fValidChannel = csrScanIsBssAllowed(pMac, pBssDesc, pIes);
4954 if( fValidChannel )
4955 {
4956 *ppIes = pIes;
4957 }
4958 else
4959 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304960 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07004961 }
4962 }
4963 else
4964 {
4965 fValidChannel = FALSE;
4966 }
4967 }
4968
4969 return( fValidChannel );
4970}
4971
4972
4973//Return whether last scan result is received
4974static tANI_BOOLEAN csrScanProcessScanResults( tpAniSirGlobal pMac, tSmeCmd *pCommand,
4975 tSirSmeScanRsp *pScanRsp, tANI_BOOLEAN *pfRemoveCommand )
4976{
4977 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE, fRemoveCommand = eANI_BOOLEAN_FALSE;
4978 tDot11fBeaconIEs *pIes = NULL;
4979 tANI_U32 cbParsed;
4980 tSirBssDescription *pSirBssDescription;
4981 tANI_U32 cbBssDesc;
4982 tANI_U32 cbScanResult = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription )
4983 + sizeof(tSirBssDescription); //We need at least one CB
4984
4985 // don't consider the scan rsp to be valid if the status code is Scan Failure. Scan Failure
4986 // is returned when the scan could not find anything. so if we get scan failure return that
4987 // the scan response is invalid. Also check the lenght in the scan result for valid scan
4988 // BssDescriptions....
4989 do
4990 {
4991 if ( ( cbScanResult <= pScanRsp->length ) &&
4992 (( eSIR_SME_SUCCESS == pScanRsp->statusCode ) ||
4993 ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW == pScanRsp->statusCode ) ) )
4994 {
4995 tANI_U8 *pChannelList = NULL;
4996 tANI_U8 cChannels = 0;
4997
4998 //Different scan type can reach this point, we need to distinguish it
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004999#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5000 if( eCsrScanGetLfrResult == pCommand->u.scanCmd.reason )
5001 {
5002 pChannelList = NULL;
5003 cChannels = 0;
5004 }
5005 else
5006#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005007 if( eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason )
5008 {
5009 //eCsrScanSetBGScanParam uses different structure
5010 tCsrBGScanRequest *pBgScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
5011
5012 cChannels = pBgScanReq->ChannelInfo.numOfChannels;
5013 pChannelList = pBgScanReq->ChannelInfo.ChannelList;
5014 }
5015 else
5016 {
5017 //the rest use generic scan request
5018 cChannels = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
5019 pChannelList = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
5020 }
5021
5022 // if the scan result is not on one of the channels in the Valid channel list, then it
5023 // must have come from an AP on an overlapping channel (in the 2.4GHz band). In this case,
5024 // let's drop the scan result.
5025 //
5026 // The other situation is where the scan request is for a scan on a particular channel set
5027 // and the scan result is from a
5028
5029 // if the NumChannels is 0, then we are supposed to be scanning all channels. Use the full channel
5030 // list as the 'valid' channel list. Otherwise, use the specific channel list in the scan parms
5031 // as the valid channels.
5032 if ( 0 == cChannels )
5033 {
5034 tANI_U32 len = sizeof(pMac->roam.validChannelList);
5035
5036 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
5037 {
5038 pChannelList = pMac->roam.validChannelList;
5039 cChannels = (tANI_U8)len;
5040 }
5041 else
5042 {
5043 //Cannot continue
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005044 smsLog( pMac, LOGE, "CSR: Processing internal SCAN results...csrGetCfgValidChannels failed" );
Jeff Johnson295189b2012-06-20 16:38:30 -07005045 break;
5046 }
5047 }
5048
5049 smsLog( pMac, LOG2, "CSR: Processing internal SCAN results..." );
5050 cbParsed = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription );
5051 pSirBssDescription = pScanRsp->bssDescription;
5052 while( cbParsed < pScanRsp->length )
5053 {
5054 if ( csrScanValidateScanResult( pMac, pChannelList, cChannels, pSirBssDescription, &pIes ) )
5055 {
5056 csrScanRemoveDupBssDescriptionFromInterimList(pMac, pSirBssDescription, pIes);
5057 csrScanSaveBssDescriptionToInterimList( pMac, pSirBssDescription, pIes );
5058 if( eSIR_PASSIVE_SCAN == pMac->scan.curScanType )
5059 {
5060 if( csrIs11dSupported( pMac) )
5061 {
5062 //Check whether the BSS is acceptable base on 11d info and our configs.
5063 if( csrMatchCountryCode( pMac, NULL, pIes ) )
5064 {
5065 //Double check whether the channel is acceptable by us.
5066 if( csrIsSupportedChannel( pMac, pSirBssDescription->channelId ) )
5067 {
5068 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
5069 }
5070 }
5071 }
5072 else
5073 {
5074 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
5075 }
5076 }
5077 //Free the resource
Kiet Lam64c1b492013-07-12 13:56:44 +05305078 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07005079 }
5080 // skip over the BSS description to the next one...
5081 cbBssDesc = pSirBssDescription->length + sizeof( pSirBssDescription->length );
5082
5083 cbParsed += cbBssDesc;
5084 pSirBssDescription = (tSirBssDescription *)((tANI_U8 *)pSirBssDescription + cbBssDesc );
5085
5086 } //while
5087 }
5088 else
5089 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005090 smsLog( pMac, LOGW, " Scanrsp fail (0x%08X), length = %d (expected %d)",
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08005091 pScanRsp->statusCode, pScanRsp->length, cbScanResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07005092 //HO bg scan/probe failed no need to try autonomously
5093 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
5094 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005095#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5096 eCsrScanGetLfrResult == pCommand->u.scanCmd.reason ||
5097#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005098 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
5099 {
5100 fRemoveCommand = eANI_BOOLEAN_TRUE;
5101 }
5102 }
5103 }while(0);
5104 if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
5105 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005106 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 -07005107 fRemoveCommand = csrScanComplete( pMac, pScanRsp );
5108 fRet = eANI_BOOLEAN_TRUE;
5109 }//if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
5110 if(pfRemoveCommand)
5111 {
5112 *pfRemoveCommand = fRemoveCommand;
5113 }
5114
5115#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305116 if (pMac->fScanOffload)
5117 return fRet;
5118
Jeff Johnson295189b2012-06-20 16:38:30 -07005119 if (!csrLLIsListEmpty( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK ))
5120 {
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005121 /* Pending scan commands in the list because the previous scan command
5122 * was split into a scan command on one channel + a scan command for all
5123 * remaining channels.
5124 *
5125 * Start timer to trigger processing of the next scan command.
Srikant Kuppa866893f2012-12-27 17:28:14 -08005126 * NOTE for LFR:
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305127 * Do not split scans if no concurrent infra connections are
Srikant Kuppa866893f2012-12-27 17:28:14 -08005128 * active and if the scan is a BG scan triggered by LFR (OR)
5129 * any scan if LFR is in the middle of a BG scan. Splitting
5130 * the scan is delaying the time it takes for LFR to find
5131 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005132 */
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305133 if ( (csrIsStaSessionConnected(pMac) &&
Srikant Kuppa866893f2012-12-27 17:28:14 -08005134#ifdef FEATURE_WLAN_LFR
5135 (csrIsConcurrentInfraConnected(pMac) ||
5136 ((pCommand->u.scanCmd.reason != eCsrScanBgScan) &&
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305137 (pMac->roam.neighborRoamInfo.neighborRoamState !=
Srikant Kuppa866893f2012-12-27 17:28:14 -08005138 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
5139#endif
5140 (pCommand->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305141 (csrIsP2pSessionConnected(pMac)) )
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005142 {
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005143 /* if active connected sessions present then continue to split scan
5144 * with specified interval between consecutive scans */
5145 csrSetDefaultScanTiming(pMac, pCommand->u.scanCmd.u.scanRequest.scanType, &(pCommand->u.scanCmd.u.scanRequest));
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05305146 vos_timer_start(&pMac->scan.hTimerStaApConcTimer,
5147 pCommand->u.scanCmd.u.scanRequest.restTime);
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005148 } else {
5149 /* if no connected sessions present then initiate next scan command immediately */
5150 /* minimum timer granularity is 10ms */
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05305151 vos_timer_start(&pMac->scan.hTimerStaApConcTimer, 10);
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005152 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005153 }
5154#endif
5155 return (fRet);
5156}
5157
5158
5159tANI_BOOLEAN csrScanIsWildCardScan( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5160{
5161 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
Kiet Lam64c1b492013-07-12 13:56:44 +05305162 tANI_BOOLEAN f = vos_mem_compare(pCommand->u.scanCmd.u.scanRequest.bssid,
5163 bssid, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07005164
5165 //It is not a wild card scan if the bssid is not broadcast and the number of SSID is 1.
5166 return ((tANI_BOOLEAN)( (f || (0xff == pCommand->u.scanCmd.u.scanRequest.bssid[0])) &&
5167 (pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs != 1) ));
5168}
5169
5170
5171eHalStatus csrScanSmeScanResponse( tpAniSirGlobal pMac, void *pMsgBuf )
5172{
5173 eHalStatus status = eHAL_STATUS_SUCCESS;
5174 tListElem *pEntry;
5175 tSmeCmd *pCommand;
5176 eCsrScanStatus scanStatus;
5177 tSirSmeScanRsp *pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
5178 tSmeGetScanChnRsp *pScanChnInfo;
5179 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
5180 eCsrScanReason reason = eCsrScanOther;
5181
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305182 if (pMac->fScanOffload)
5183 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList,
5184 LL_ACCESS_LOCK);
5185 else
5186 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07005187
5188 if ( pEntry )
5189 {
5190 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
5191 if ( eSmeCommandScan == pCommand->command )
5192 {
5193 scanStatus = (eSIR_SME_SUCCESS == pScanRsp->statusCode) ? eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
5194 reason = pCommand->u.scanCmd.reason;
5195 switch(pCommand->u.scanCmd.reason)
5196 {
5197 case eCsrScanAbortBgScan:
5198 case eCsrScanAbortNormalScan:
5199 case eCsrScanBGScanAbort:
5200 case eCsrScanBGScanEnable:
5201 break;
5202 case eCsrScanGetScanChnInfo:
5203 pScanChnInfo = (tSmeGetScanChnRsp *)pMsgBuf;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005204 /*
5205 * status code not available in tSmeGetScanChnRsp, so
5206 * by default considereing it to be success
5207 */
5208 scanStatus = eSIR_SME_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07005209 csrScanAgeResults(pMac, pScanChnInfo);
5210 break;
5211 case eCsrScanForCapsChange:
5212 csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand );
5213 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005214 case eCsrScanP2PFindPeer:
5215 scanStatus = ((eSIR_SME_SUCCESS == pScanRsp->statusCode) && (pScanRsp->length > 50)) ? eCSR_SCAN_FOUND_PEER : eCSR_SCAN_FAILURE;
5216 csrScanProcessScanResults( pMac, pCommand, pScanRsp, NULL );
5217 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005218 case eCsrScanSetBGScanParam:
5219 default:
5220 if(csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand ))
5221 {
5222 //Not to get channel info if the scan is not a wildcard scan because
5223 //it may cause scan results got aged out incorrectly.
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005224 if( csrScanIsWildCardScan( pMac, pCommand ) && (!pCommand->u.scanCmd.u.scanRequest.p2pSearch)
5225#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5226 && (pCommand->u.scanCmd.reason != eCsrScanGetLfrResult)
5227#endif
5228 )
Jeff Johnson295189b2012-06-20 16:38:30 -07005229 {
5230 //Get the list of channels scanned
Jeff Johnson32d95a32012-09-10 13:15:23 -07005231 if( pCommand->u.scanCmd.reason != eCsrScanUserRequest)
5232 {
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05305233 csrScanGetScanChnInfo(pMac, pCommand->sessionId,
5234 NULL, NULL);
Jeff Johnson32d95a32012-09-10 13:15:23 -07005235 }
5236 else
5237 {
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05305238 csrScanGetScanChnInfo(pMac,
5239 pCommand->sessionId,
5240 pCommand->u.scanCmd.pContext,
5241 pCommand->u.scanCmd.callback);
Jeff Johnson32d95a32012-09-10 13:15:23 -07005242 pCommand->u.scanCmd.callback = NULL;
5243 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005244 }
5245 }
5246 break;
5247 }//switch
5248 if(fRemoveCommand)
5249 {
5250
5251 csrReleaseScanCommand(pMac, pCommand, scanStatus);
5252
Srikant Kuppa866893f2012-12-27 17:28:14 -08005253 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005254 smeProcessPendingQueue( pMac );
5255 }
5256 else
5257 {
5258 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
5259 status = eHAL_STATUS_FAILURE;
5260 }
5261 }
5262 else
5263 {
5264 smsLog( pMac, LOGW, "CSR: Scan Completion called but NO commands are ACTIVE ..." );
5265 status = eHAL_STATUS_FAILURE;
5266 }
5267
5268 return (status);
5269}
5270
5271
5272
5273
5274tCsrScanResultInfo *csrScanResultGetFirst(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
5275{
5276 tListElem *pEntry;
5277 tCsrScanResult *pResult;
5278 tCsrScanResultInfo *pRet = NULL;
5279 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5280
5281 if(pResultList)
5282 {
5283 csrLLLock(&pResultList->List);
5284 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5285 if(pEntry)
5286 {
5287 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
5288 pRet = &pResult->Result;
5289 }
5290 pResultList->pCurEntry = pEntry;
5291 csrLLUnlock(&pResultList->List);
5292 }
5293
5294 return pRet;
5295}
5296
5297
5298tCsrScanResultInfo *csrScanResultGetNext(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
5299{
5300 tListElem *pEntry = NULL;
5301 tCsrScanResult *pResult = NULL;
5302 tCsrScanResultInfo *pRet = NULL;
5303 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5304
5305 if(pResultList)
5306 {
5307 csrLLLock(&pResultList->List);
5308 if(NULL == pResultList->pCurEntry)
5309 {
5310 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5311 }
5312 else
5313 {
5314 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
5315 }
5316 if(pEntry)
5317 {
5318 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
5319 pRet = &pResult->Result;
5320 }
5321 pResultList->pCurEntry = pEntry;
5322 csrLLUnlock(&pResultList->List);
5323 }
5324
5325 return pRet;
5326}
5327
5328
5329//This function moves the first BSS that matches the bssid to the head of the result
5330eHalStatus csrMoveBssToHeadFromBSSID(tpAniSirGlobal pMac, tCsrBssid *bssid, tScanResultHandle hScanResult)
5331{
5332 eHalStatus status = eHAL_STATUS_FAILURE;
5333 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5334 tCsrScanResult *pResult = NULL;
5335 tListElem *pEntry = NULL;
5336
5337 if(pResultList && bssid)
5338 {
5339 csrLLLock(&pResultList->List);
5340 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5341 while(pEntry)
5342 {
5343 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
Kiet Lam64c1b492013-07-12 13:56:44 +05305344 if (vos_mem_compare(bssid, pResult->Result.BssDescriptor.bssId, sizeof(tCsrBssid)))
Jeff Johnson295189b2012-06-20 16:38:30 -07005345 {
5346 status = eHAL_STATUS_SUCCESS;
5347 csrLLRemoveEntry(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
5348 csrLLInsertHead(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
5349 break;
5350 }
5351 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
5352 }
5353 csrLLUnlock(&pResultList->List);
5354 }
5355
5356 return (status);
5357}
5358
5359
5360//Remove the BSS if possible.
5361//Return -- TRUE == the BSS is remove. False == Fail to remove it
5362//This function is called when list lock is held. Be caution what functions it can call.
5363tANI_BOOLEAN csrScanAgeOutBss(tpAniSirGlobal pMac, tCsrScanResult *pResult)
5364{
5365 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
5366 tANI_U32 i;
5367 tCsrRoamSession *pSession;
5368
5369 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5370 {
5371 if( CSR_IS_SESSION_VALID( pMac, i ) )
5372 {
5373 pSession = CSR_GET_SESSION( pMac, i );
5374 //Not to remove the BSS we are connected to.
5375 if(csrIsConnStateDisconnected(pMac, i) || (NULL == pSession->pConnectBssDesc) ||
5376 (!csrIsDuplicateBssDescription(pMac, &pResult->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07005377 pSession->pConnectBssDesc, NULL, FALSE))
Jeff Johnson295189b2012-06-20 16:38:30 -07005378 )
5379 {
Arif Hussaina7c8e412013-11-20 11:06:42 -08005380 smsLog(pMac, LOGW, "Aging out BSS "MAC_ADDRESS_STR" Channel %d",
5381 MAC_ADDR_ARRAY(pResult->Result.BssDescriptor.bssId),
5382 pResult->Result.BssDescriptor.channelId);
Jeff Johnson295189b2012-06-20 16:38:30 -07005383 //No need to hold the spin lock because caller should hold the lock for pMac->scan.scanResultList
5384 if( csrLLRemoveEntry(&pMac->scan.scanResultList, &pResult->Link, LL_ACCESS_NOLOCK) )
5385 {
5386 csrFreeScanResultEntry(pMac, pResult);
Madan Mohan Koyyalamudi2e068bc2012-10-22 14:58:47 -07005387 fRet = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005388 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005389 break;
5390 }
5391 } //valid session
5392 } //for
Madan Mohan Koyyalamudi2e068bc2012-10-22 14:58:47 -07005393 if( CSR_ROAM_SESSION_MAX == i && fRet != eANI_BOOLEAN_TRUE )
Jeff Johnson295189b2012-06-20 16:38:30 -07005394 {
5395 //reset the counter so this won't hapeen too soon
5396 pResult->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
5397 pResult->Result.BssDescriptor.nReceivedTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
5398 }
5399
5400 return (fRet);
5401}
5402
5403
5404eHalStatus csrScanAgeResults(tpAniSirGlobal pMac, tSmeGetScanChnRsp *pScanChnInfo)
5405{
5406 eHalStatus status = eHAL_STATUS_SUCCESS;
5407 tListElem *pEntry, *tmpEntry;
5408 tCsrScanResult *pResult;
5409 tLimScanChn *pChnInfo;
5410 tANI_U8 i;
5411
5412 csrLLLock(&pMac->scan.scanResultList);
5413 for(i = 0; i < pScanChnInfo->numChn; i++)
5414 {
5415 pChnInfo = &pScanChnInfo->scanChn[i];
5416 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
5417 while( pEntry )
5418 {
5419 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
5420 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
5421 if(pResult->Result.BssDescriptor.channelId == pChnInfo->channelId)
5422 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005423 if(pResult->AgingCount <= 0)
5424 {
5425 smsLog(pMac, LOGW, " age out due to ref count");
5426 csrScanAgeOutBss(pMac, pResult);
5427 }
Madan Mohan Koyyalamudib9d3dcc2012-09-28 16:47:50 -07005428 else
5429 {
5430 pResult->AgingCount--;
5431 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005432 }
5433 pEntry = tmpEntry;
5434 }
5435 }
5436 csrLLUnlock(&pMac->scan.scanResultList);
5437
5438 return (status);
5439}
5440
5441
5442eHalStatus csrSendMBScanReq( tpAniSirGlobal pMac, tANI_U16 sessionId,
5443 tCsrScanRequest *pScanReq, tScanReqParam *pScanReqParam )
5444{
5445 eHalStatus status = eHAL_STATUS_SUCCESS;
5446 tSirSmeScanReq *pMsg;
5447 tANI_U16 msgLen;
5448 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
5449 tSirScanType scanType = pScanReq->scanType;
5450 tANI_U32 minChnTime; //in units of milliseconds
5451 tANI_U32 maxChnTime; //in units of milliseconds
5452 tANI_U32 i;
5453 tANI_U8 selfMacAddr[WNI_CFG_BSSID_LEN];
5454 tANI_U8 *pSelfMac = NULL;
5455
5456 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
5457 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) +
5458 ( pScanReq->uIEFieldLen ) ;
5459
Kiet Lam64c1b492013-07-12 13:56:44 +05305460 pMsg = vos_mem_malloc(msgLen);
5461 if ( NULL == pMsg )
5462 status = eHAL_STATUS_FAILURE;
5463 else
5464 status = eHAL_STATUS_SUCCESS;
5465 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07005466 {
5467 do
5468 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305469 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005470 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
5471 pMsg->length = pal_cpu_to_be16(msgLen);
5472 //ToDO: Fill in session info when we need to do scan base on session.
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05305473 if ((pMac->fScanOffload) && (sessionId != CSR_SESSION_ID_INVALID))
5474 {
5475 pMsg->sessionId = sessionId;
5476 }
5477 else
5478 {
5479 /* if sessionId == CSR_SESSION_ID_INVALID, then send the scan
5480 request on first available session */
5481 pMsg->sessionId = 0;
5482 }
5483
Jeff Johnson295189b2012-06-20 16:38:30 -07005484 pMsg->transactionId = 0;
5485 pMsg->dot11mode = (tANI_U8) csrTranslateToWNICfgDot11Mode(pMac, csrFindBestPhyMode( pMac, pMac->roam.configParam.phyMode ));
5486 pMsg->bssType = pal_cpu_to_be32(csrTranslateBsstypeToMacType(pScanReq->BSSType));
5487
5488 if ( CSR_IS_SESSION_VALID( pMac, sessionId ) )
5489 {
5490 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[sessionId].selfMacAddr;
5491 }
5492 else
5493 {
5494 // Since we don't have session for the scanning, we find a valid session. In case we fail to
5495 // do so, get the WNI_CFG_STA_ID
5496 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5497 {
5498 if( CSR_IS_SESSION_VALID( pMac, i ) )
5499 {
5500 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[i].selfMacAddr;
5501 break;
5502 }
5503 }
5504 if( CSR_ROAM_SESSION_MAX == i )
5505 {
5506 tANI_U32 len = WNI_CFG_BSSID_LEN;
5507 pSelfMac = selfMacAddr;
5508 status = ccmCfgGetStr( pMac, WNI_CFG_STA_ID, pSelfMac, &len );
5509 if( !HAL_STATUS_SUCCESS( status ) ||
5510 ( len < WNI_CFG_BSSID_LEN ) )
5511 {
5512 smsLog( pMac, LOGE, FL(" Can not get self MAC address from CFG status = %d"), status );
5513 //Force failed status
5514 status = eHAL_STATUS_FAILURE;
5515 break;
5516 }
5517 }
5518 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305519 vos_mem_copy((tANI_U8 *)pMsg->selfMacAddr, pSelfMac, sizeof(tSirMacAddr));
Jeff Johnson295189b2012-06-20 16:38:30 -07005520
5521 //sirCopyMacAddr
Kiet Lam64c1b492013-07-12 13:56:44 +05305522 vos_mem_copy((tANI_U8 *)pMsg->bssId, (tANI_U8 *)&pScanReq->bssid, sizeof(tSirMacAddr));
5523 if ( vos_mem_compare(pScanReq->bssid, bssid, sizeof(tCsrBssid)))
Jeff Johnson295189b2012-06-20 16:38:30 -07005524 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305525 vos_mem_set(pMsg->bssId, sizeof(tSirMacAddr), 0xff);
Jeff Johnson295189b2012-06-20 16:38:30 -07005526 }
5527 else
5528 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305529 vos_mem_copy(pMsg->bssId, pScanReq->bssid, WNI_CFG_BSSID_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07005530 }
5531 minChnTime = pScanReq->minChnTime;
5532 maxChnTime = pScanReq->maxChnTime;
5533
5534 //Verify the scan type first, if the scan is active scan, we need to make sure we
5535 //are allowed to do so.
5536 /* if 11d is enabled & we don't see any beacon around, scan type falls
5537 back to passive. But in BT AMP STA mode we need to send out a
5538 directed probe*/
5539 if( (eSIR_PASSIVE_SCAN != scanType) && (eCSR_SCAN_P2P_DISCOVERY != pScanReq->requestType)
5540 && (eCSR_BSS_TYPE_WDS_STA != pScanReq->BSSType)
5541 && (eANI_BOOLEAN_FALSE == pMac->scan.fEnableBypass11d))
5542 {
5543 scanType = pMac->scan.curScanType;
5544 if(eSIR_PASSIVE_SCAN == pMac->scan.curScanType)
5545 {
5546 if(minChnTime < pMac->roam.configParam.nPassiveMinChnTime)
5547 {
5548 minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
5549 }
5550 if(maxChnTime < pMac->roam.configParam.nPassiveMaxChnTime)
5551 {
5552 maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
5553 }
5554 }
5555 }
5556 pMsg->scanType = pal_cpu_to_be32(scanType);
5557
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05305558 pMsg->numSsid =
5559 (pScanReq->SSIDs.numOfSSIDs < SIR_SCAN_MAX_NUM_SSID) ?
5560 pScanReq->SSIDs.numOfSSIDs : SIR_SCAN_MAX_NUM_SSID;
Jeff Johnson295189b2012-06-20 16:38:30 -07005561 if((pScanReq->SSIDs.numOfSSIDs != 0) && ( eSIR_PASSIVE_SCAN != scanType ))
5562 {
Jeff Johnson40b59aa2013-03-19 14:43:18 -07005563 for (i = 0; i < pMsg->numSsid; i++)
5564 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305565 vos_mem_copy(&pMsg->ssId[i],
5566 &pScanReq->SSIDs.SSIDList[i].SSID, sizeof(tSirMacSSid));
Jeff Johnson40b59aa2013-03-19 14:43:18 -07005567 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005568 }
5569 else
5570 {
5571 //Otherwise we scan all SSID and let the result filter later
Jeff Johnson40b59aa2013-03-19 14:43:18 -07005572 for (i = 0; i < SIR_SCAN_MAX_NUM_SSID; i++)
5573 {
5574 pMsg->ssId[i].length = 0;
5575 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005576 }
5577
Jeff Johnson295189b2012-06-20 16:38:30 -07005578 pMsg->minChannelTime = pal_cpu_to_be32(minChnTime);
5579 pMsg->maxChannelTime = pal_cpu_to_be32(maxChnTime);
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08005580 pMsg->minChannelTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
5581 pMsg->maxChannelTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07005582 //hidden SSID option
5583 pMsg->hiddenSsid = pScanReqParam->hiddenSsid;
5584 //rest time
5585 //pMsg->restTime = pScanReq->restTime;
5586 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
5587 // All the scan results caching will be done by Roaming
5588 // We do not want LIM to do any caching of scan results,
5589 // so delete the LIM cache on all scan requests
5590 pMsg->returnFreshResults = pScanReqParam->freshScan;
5591 //Always ask for unique result
5592 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
5593 pMsg->channelList.numChannels = (tANI_U8)pScanReq->ChannelInfo.numOfChannels;
5594 if(pScanReq->ChannelInfo.numOfChannels)
5595 {
5596 //Assuming the channelNumber is tANI_U8 (1 byte)
Kiet Lam64c1b492013-07-12 13:56:44 +05305597 vos_mem_copy(pMsg->channelList.channelNumber,
5598 pScanReq->ChannelInfo.ChannelList,
5599 pScanReq->ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07005600 }
5601
5602 pMsg->uIEFieldLen = (tANI_U16) pScanReq->uIEFieldLen;
5603 pMsg->uIEFieldOffset = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
5604 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) ;
5605 if(pScanReq->uIEFieldLen != 0)
5606 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305607 vos_mem_copy((tANI_U8 *)pMsg+pMsg->uIEFieldOffset, pScanReq->pIEField,
5608 pScanReq->uIEFieldLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07005609 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005610 pMsg->p2pSearch = pScanReq->p2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07005611
Madan Mohan Koyyalamudi9b876782012-10-11 16:22:51 -07005612 if (pScanReq->requestType == eCSR_SCAN_HO_BG_SCAN)
5613 {
5614 pMsg->backgroundScanMode = eSIR_ROAMING_SCAN;
5615 }
5616
Jeff Johnson295189b2012-06-20 16:38:30 -07005617 }while(0);
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005618 smsLog(pMac, LOG1, FL("domainIdCurrent %d scanType %d bssType %d requestType %d numChannels %d "),
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005619 pMac->scan.domainIdCurrent, pMsg->scanType, pMsg->bssType,
5620 pScanReq->requestType, pMsg->channelList.numChannels);
5621
5622 for(i = 0; i < pMsg->channelList.numChannels; i++)
5623 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005624 smsLog(pMac, LOG3, FL("channelNumber[%d]= %d"), i, pMsg->channelList.channelNumber[i]);
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005625 }
5626
Jeff Johnson295189b2012-06-20 16:38:30 -07005627 if(HAL_STATUS_SUCCESS(status))
5628 {
5629 status = palSendMBMessage(pMac->hHdd, pMsg);
5630 }
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005631 else
5632 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005633 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d"), status );
Kiet Lam64c1b492013-07-12 13:56:44 +05305634 vos_mem_free(pMsg);
Jeff Johnson295189b2012-06-20 16:38:30 -07005635 }
5636 }//Success allocated memory
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005637 else
5638 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005639 smsLog( pMac, LOGE, FL(" memory allocation failure"));
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005640 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005641
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05305642 if(!HAL_STATUS_SUCCESS(status))
5643 {
5644 smsLog( pMac, LOG1, FL("Failed: SId: %d FirstMatch = %d"
5645 " UniqueResult = %d freshScan = %d hiddenSsid = %d"),
5646 sessionId, pScanReqParam->bReturnAfter1stMatch,
5647 pScanReqParam->fUniqueResult, pScanReqParam->freshScan,
5648 pScanReqParam->hiddenSsid );
5649 smsLog( pMac, LOG1, FL("scanType = %u BSSType = %u numOfSSIDs = %d"
5650 " numOfChannels = %d requestType = %d p2pSearch = %d\n"),
5651 pScanReq->scanType, pScanReq->BSSType,
5652 pScanReq->SSIDs.numOfSSIDs,
5653 pScanReq->ChannelInfo.numOfChannels, pScanReq->requestType,
5654 pScanReq->p2pSearch );
5655
5656 }
5657
Jeff Johnson295189b2012-06-20 16:38:30 -07005658 return( status );
5659}
5660
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005661eHalStatus csrSendMBScanResultReq( tpAniSirGlobal pMac, tANI_U32 sessionId, tScanReqParam *pScanReqParam )
Jeff Johnson295189b2012-06-20 16:38:30 -07005662{
5663 eHalStatus status = eHAL_STATUS_SUCCESS;
5664 tSirSmeScanReq *pMsg;
5665 tANI_U16 msgLen;
5666
5667 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ));
Kiet Lam64c1b492013-07-12 13:56:44 +05305668 pMsg = vos_mem_malloc(msgLen);
5669 if ( NULL == pMsg )
5670 status = eHAL_STATUS_FAILURE;
5671 else
Jeff Johnson295189b2012-06-20 16:38:30 -07005672 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305673 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005674 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
5675 pMsg->length = pal_cpu_to_be16(msgLen);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005676 pMsg->sessionId = sessionId;
5677 pMsg->transactionId = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07005678 pMsg->returnFreshResults = pScanReqParam->freshScan;
5679 //Always ask for unique result
5680 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
5681 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
5682 status = palSendMBMessage(pMac->hHdd, pMsg);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005683 if (!HAL_STATUS_SUCCESS(status))
5684 {
5685 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d\n"), status );
5686 }
5687
Jeff Johnson295189b2012-06-20 16:38:30 -07005688 }
5689
5690 return( status );
5691}
5692
5693
5694
5695eHalStatus csrScanChannels( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5696{
5697 eHalStatus status = eHAL_STATUS_FAILURE;
5698 tScanReqParam scanReq;
5699
5700 do
5701 {
5702 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE | TRUE;
5703 scanReq.fUniqueResult = TRUE;
5704 scanReq.hiddenSsid = SIR_SCAN_NO_HIDDEN_SSID;
5705 if(eCsrScanForSsid == pCommand->u.scanCmd.reason)
5706 {
5707 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_FIRST_MATCH;
5708 }
5709 else
5710 {
5711 // Basically do scan on all channels even for 11D 1st scan case.
5712 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5713 }
5714 if((eCsrScanBgScan == pCommand->u.scanCmd.reason)||
5715 (eCsrScanProbeBss == pCommand->u.scanCmd.reason))
5716 {
5717 scanReq.hiddenSsid = SIR_SCAN_HIDDEN_SSID_PE_DECISION;
5718 }
5719
5720#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5721 {
5722 vos_log_scan_pkt_type *pScanLog = NULL;
5723
5724 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
5725 if(pScanLog)
5726 {
5727 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
5728 eCsrScanProbeBss == pCommand->u.scanCmd.reason)
5729 {
5730 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
5731 }
5732 else
5733 {
5734 if( (eSIR_PASSIVE_SCAN != pCommand->u.scanCmd.u.scanRequest.scanType) &&
5735 (eSIR_PASSIVE_SCAN != pMac->scan.curScanType) )
5736 {
5737 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_REQ;
5738 }
5739 else
5740 {
5741 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_REQ;
5742 }
5743 }
5744 pScanLog->minChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.minChnTime;
5745 pScanLog->maxChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.maxChnTime;
5746 pScanLog->numChannel = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
5747 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
5748 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305749 vos_mem_copy(pScanLog->channels,
5750 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
5751 pScanLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07005752 }
5753 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
5754 }
5755 }
5756#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5757
5758
5759 status = csrSendMBScanReq(pMac, pCommand->sessionId,
5760 &pCommand->u.scanCmd.u.scanRequest, &scanReq);
5761 }while(0);
5762
5763 return( status );
5764}
5765
5766
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005767eHalStatus csrScanRetrieveResult(tpAniSirGlobal pMac, tSmeCmd *pCommand)
Jeff Johnson295189b2012-06-20 16:38:30 -07005768{
5769 eHalStatus status = eHAL_STATUS_FAILURE;
5770 tScanReqParam scanReq;
5771
5772 do
5773 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005774#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5775 if (eCsrScanGetLfrResult == pCommand->u.scanCmd.reason)
5776 {
5777 //to get the LFR candidates from PE cache
5778 scanReq.freshScan = SIR_BG_SCAN_RETURN_LFR_CACHED_RESULTS|SIR_BG_SCAN_PURGE_LFR_RESULTS;
5779 scanReq.fUniqueResult = TRUE;
5780 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5781 }
5782 else
5783#endif
5784 {
5785 //not a fresh scan
5786 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE;
5787 scanReq.fUniqueResult = TRUE;
5788 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5789 }
5790 status = csrSendMBScanResultReq(pMac, pCommand->sessionId, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07005791 }while(0);
5792
5793 return (status);
5794}
5795
5796
5797
5798eHalStatus csrProcessScanCommand( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5799{
5800 eHalStatus status = eHAL_STATUS_SUCCESS;
5801 tCsrChannelInfo newChannelInfo = {0, NULL};
5802 int i, j;
5803 tANI_U8 *pChannel = NULL;
5804 tANI_U32 len = 0;
5805
5806 // Transition to Scanning state...
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305807 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07005808 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305809 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5810 {
5811 pCommand->u.scanCmd.lastRoamState[i] =
5812 csrRoamStateChange( pMac, eCSR_ROAMING_STATE_SCANNING, i);
5813 smsLog( pMac, LOG3, "starting SCAN command from %d state...."
5814 " reason is %d", pCommand->u.scanCmd.lastRoamState[i],
5815 pCommand->u.scanCmd.reason );
5816 }
5817 }
5818 else
5819 {
5820 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId] =
5821 csrRoamStateChange(pMac, eCSR_ROAMING_STATE_SCANNING,
5822 pCommand->sessionId);
5823 smsLog( pMac, LOG3,
5824 "starting SCAN command from %d state.... reason is %d",
5825 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId],
5826 pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07005827 }
5828
5829 switch(pCommand->u.scanCmd.reason)
5830 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005831#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5832 case eCsrScanGetLfrResult:
5833#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005834 case eCsrScanGetResult:
5835 case eCsrScanForCapsChange: //For cap change, LIM already save BSS description
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005836 status = csrScanRetrieveResult(pMac, pCommand);
Jeff Johnson295189b2012-06-20 16:38:30 -07005837 break;
5838 case eCsrScanSetBGScanParam:
5839 status = csrProcessSetBGScanParam(pMac, pCommand);
5840 break;
5841 case eCsrScanBGScanAbort:
5842 status = csrSetCfgBackgroundScanPeriod(pMac, 0);
5843 break;
5844 case eCsrScanBGScanEnable:
5845 status = csrSetCfgBackgroundScanPeriod(pMac, pMac->roam.configParam.bgScanInterval);
5846 break;
5847 case eCsrScanGetScanChnInfo:
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05305848 status = csrScanGetScanChannelInfo(pMac, pCommand->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07005849 break;
5850 case eCsrScanUserRequest:
5851 if(pMac->roam.configParam.fScanTwice)
5852 {
5853 //We scan 2.4 channel twice
5854 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels &&
5855 (NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList))
5856 {
5857 len = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
5858 //allocate twice the channel
5859 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(newChannelInfo.numOfChannels * 2);
5860 pChannel = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
5861 }
5862 else
5863 {
5864 //get the valid channel list to scan all.
5865 len = sizeof(pMac->roam.validChannelList);
5866
5867 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
5868 {
5869 //allocate twice the channel
5870 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(len * 2);
5871 pChannel = pMac->roam.validChannelList;
5872 }
5873 }
5874 if(NULL == newChannelInfo.ChannelList)
5875 {
5876 newChannelInfo.numOfChannels = 0;
5877 }
5878 else
5879 {
5880 j = 0;
5881 for(i = 0; i < len; i++)
5882 {
5883 newChannelInfo.ChannelList[j++] = pChannel[i];
5884 if(CSR_MAX_24GHz_CHANNEL_NUMBER >= pChannel[i])
5885 {
5886 newChannelInfo.ChannelList[j++] = pChannel[i];
5887 }
5888 }
5889 if(NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
5890 {
5891 //pChannel points to the channellist from the command, free it.
5892 vos_mem_free(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -07005893 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07005894 }
5895 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = j;
5896 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = newChannelInfo.ChannelList;
5897 }
5898 } //if(pMac->roam.configParam.fScanTwice)
5899
5900 status = csrScanChannels(pMac, pCommand);
5901
5902 break;
5903 default:
5904 status = csrScanChannels(pMac, pCommand);
5905 break;
5906 }
5907
5908 if(!HAL_STATUS_SUCCESS(status))
5909 {
5910 csrReleaseScanCommand(pMac, pCommand, eCSR_SCAN_FAILURE);
5911 }
5912
5913 return (status);
5914}
5915
5916
5917eHalStatus csrScanSetBGScanparams(tpAniSirGlobal pMac, tCsrBGScanRequest *pScanReq)
5918{
5919 eHalStatus status = eHAL_STATUS_SUCCESS;
5920 tSmeCmd *pCommand = NULL;
5921
5922 if(pScanReq)
5923 {
5924 do
5925 {
5926 pCommand = csrGetCommandBuffer(pMac);
5927 if(!pCommand)
5928 {
5929 status = eHAL_STATUS_RESOURCES;
5930 break;
5931 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305932 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005933 pCommand->command = eSmeCommandScan;
5934 pCommand->u.scanCmd.reason = eCsrScanSetBGScanParam;
5935 pCommand->u.scanCmd.callback = NULL;
5936 pCommand->u.scanCmd.pContext = NULL;
Kiet Lam64c1b492013-07-12 13:56:44 +05305937 vos_mem_copy(&pCommand->u.scanCmd.u.bgScanRequest, pScanReq, sizeof(tCsrBGScanRequest));
Jeff Johnson295189b2012-06-20 16:38:30 -07005938 //we have to do the follow
5939 if(pScanReq->ChannelInfo.numOfChannels == 0)
5940 {
5941 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
5942 }
5943 else
5944 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305945 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList
5946 = vos_mem_malloc(pScanReq->ChannelInfo.numOfChannels);
5947 if ( NULL != pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07005948 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305949 vos_mem_copy(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList,
5950 pScanReq->ChannelInfo.ChannelList,
5951 pScanReq->ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07005952 }
5953 else
5954 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005955 smsLog(pMac, LOGE, FL("ran out of memory"));
Jeff Johnson295189b2012-06-20 16:38:30 -07005956 csrReleaseCommandScan(pMac, pCommand);
Kiet Lam64c1b492013-07-12 13:56:44 +05305957 return eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005958 }
5959 }
5960
5961 //scan req for SSID
5962 if(pScanReq->SSID.length)
5963 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305964 vos_mem_copy(pCommand->u.scanCmd.u.bgScanRequest.SSID.ssId,
5965 pScanReq->SSID.ssId, pScanReq->SSID.length);
Jeff Johnson295189b2012-06-20 16:38:30 -07005966 pCommand->u.scanCmd.u.bgScanRequest.SSID.length = pScanReq->SSID.length;
5967
5968 }
5969 pCommand->u.scanCmd.u.bgScanRequest.maxChnTime= pScanReq->maxChnTime;
5970 pCommand->u.scanCmd.u.bgScanRequest.minChnTime = pScanReq->minChnTime;
5971 pCommand->u.scanCmd.u.bgScanRequest.scanInterval = pScanReq->scanInterval;
5972
5973
5974 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
5975 if( !HAL_STATUS_SUCCESS( status ) )
5976 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005977 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07005978 csrReleaseCommandScan( pMac, pCommand );
5979 break;
5980 }
5981 }while(0);
5982 }
5983
5984 return (status);
5985}
5986
5987eHalStatus csrScanBGScanAbort( tpAniSirGlobal pMac )
5988{
5989 eHalStatus status = eHAL_STATUS_SUCCESS;
5990 tSmeCmd *pCommand = NULL;
5991
5992 do
5993 {
5994 pCommand = csrGetCommandBuffer(pMac);
5995 if(!pCommand)
5996 {
5997 status = eHAL_STATUS_RESOURCES;
5998 break;
5999 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306000 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006001 pCommand->command = eSmeCommandScan;
6002 pCommand->u.scanCmd.reason = eCsrScanBGScanAbort;
6003 pCommand->u.scanCmd.callback = NULL;
6004 pCommand->u.scanCmd.pContext = NULL;
6005 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
6006 if( !HAL_STATUS_SUCCESS( status ) )
6007 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006008 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006009 csrReleaseCommandScan( pMac, pCommand );
6010 break;
6011 }
6012 }while(0);
6013
6014 return (status);
6015}
6016
6017
6018//This will enable the background scan with the non-zero interval
6019eHalStatus csrScanBGScanEnable(tpAniSirGlobal pMac)
6020{
6021 eHalStatus status = eHAL_STATUS_SUCCESS;
6022 tSmeCmd *pCommand = NULL;
6023
6024 if(pMac->roam.configParam.bgScanInterval)
6025 {
6026 do
6027 {
6028 pCommand = csrGetCommandBuffer(pMac);
6029 if(!pCommand)
6030 {
6031 status = eHAL_STATUS_RESOURCES;
6032 break;
6033 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306034 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006035 pCommand->command = eSmeCommandScan;
6036 pCommand->u.scanCmd.reason = eCsrScanBGScanEnable;
6037 pCommand->u.scanCmd.callback = NULL;
6038 pCommand->u.scanCmd.pContext = NULL;
6039 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
6040 if( !HAL_STATUS_SUCCESS( status ) )
6041 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006042 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006043 csrReleaseCommandScan( pMac, pCommand );
6044 break;
6045 }
6046 }while(0);
6047 //BG scan results are reported automatically by PE to SME once the scan is done.
6048 //No need to fetch the results explicitly.
6049 //csrScanStartGetResultTimer(pMac);
6050 csrScanStartResultAgingTimer(pMac);
6051 }
6052 else
6053 {
6054 //We don't have BG scan so stop the aging timer
6055 csrScanStopResultAgingTimer(pMac);
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006056 smsLog(pMac, LOGE, FL("cannot continue because the bgscan interval is 0"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006057 status = eHAL_STATUS_INVALID_PARAMETER;
6058 }
6059
6060 return (status);
6061}
6062
6063
6064eHalStatus csrScanCopyRequest(tpAniSirGlobal pMac, tCsrScanRequest *pDstReq, tCsrScanRequest *pSrcReq)
6065{
6066 eHalStatus status = eHAL_STATUS_SUCCESS;
6067 tANI_U32 len = sizeof(pMac->roam.validChannelList);
6068 tANI_U32 index = 0;
6069 tANI_U32 new_index = 0;
6070
6071 do
6072 {
6073 status = csrScanFreeRequest(pMac, pDstReq);
6074 if(HAL_STATUS_SUCCESS(status))
6075 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306076 vos_mem_copy(pDstReq, pSrcReq, sizeof(tCsrScanRequest));
Gopichand Nakkalac7b1d3e2012-12-31 14:07:19 -08006077 /* Re-initialize the pointers to NULL since we did a copy */
6078 pDstReq->pIEField = NULL;
6079 pDstReq->ChannelInfo.ChannelList = NULL;
6080 pDstReq->SSIDs.SSIDList = NULL;
6081
Jeff Johnson295189b2012-06-20 16:38:30 -07006082 if(pSrcReq->uIEFieldLen == 0)
6083 {
6084 pDstReq->pIEField = NULL;
6085 }
6086 else
6087 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306088 pDstReq->pIEField = vos_mem_malloc(pSrcReq->uIEFieldLen);
6089 if ( NULL == pDstReq->pIEField )
Jeff Johnson295189b2012-06-20 16:38:30 -07006090 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306091 status = eHAL_STATUS_FAILURE;
6092 smsLog(pMac, LOGE, FL("No memory for scanning IE fields"));
6093 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07006094 }
6095 else
6096 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306097 status = eHAL_STATUS_SUCCESS;
6098 vos_mem_copy(pDstReq->pIEField, pSrcReq->pIEField,
6099 pSrcReq->uIEFieldLen);
6100 pDstReq->uIEFieldLen = pSrcReq->uIEFieldLen;
Jeff Johnson295189b2012-06-20 16:38:30 -07006101 }
6102 }//Allocate memory for IE field
6103 {
6104 if(pSrcReq->ChannelInfo.numOfChannels == 0)
6105 {
6106 pDstReq->ChannelInfo.ChannelList = NULL;
6107 pDstReq->ChannelInfo.numOfChannels = 0;
6108 }
6109 else
6110 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306111 pDstReq->ChannelInfo.ChannelList = vos_mem_malloc(
6112 pSrcReq->ChannelInfo.numOfChannels
6113 * sizeof(*pDstReq->ChannelInfo.ChannelList));
6114 if ( NULL == pDstReq->ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07006115 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306116 status = eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006117 pDstReq->ChannelInfo.numOfChannels = 0;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306118 smsLog(pMac, LOGE, FL("No memory for scanning Channel"
6119 " List"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006120 break;
6121 }
6122
6123 if((pSrcReq->scanType == eSIR_PASSIVE_SCAN) && (pSrcReq->requestType == eCSR_SCAN_REQUEST_11D_SCAN))
6124 {
6125 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
6126 {
6127 pDstReq->ChannelInfo.ChannelList[new_index] =
6128 pSrcReq->ChannelInfo.ChannelList[index];
6129 new_index++;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306130 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006131 pDstReq->ChannelInfo.numOfChannels = new_index;
6132 }
6133 else if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
6134 {
6135 new_index = 0;
6136 pMac->roam.numValidChannels = len;
6137 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
6138 {
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -07006139 /* Allow scan on valid channels only.
6140 * If it is p2p scan and valid channel list doesnt contain
6141 * social channels, enforce scan on social channels because
6142 * that is the only way to find p2p peers.
6143 * This can happen only if band is set to 5Ghz mode.
6144 */
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08006145 if((csrRoamIsValidChannel(pMac, pSrcReq->ChannelInfo.ChannelList[index])) ||
6146 ((eCSR_SCAN_P2P_DISCOVERY == pSrcReq->requestType) &&
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -07006147 CSR_IS_SOCIAL_CHANNEL(pSrcReq->ChannelInfo.ChannelList[index])))
Jeff Johnson295189b2012-06-20 16:38:30 -07006148 {
Srikant Kuppa866893f2012-12-27 17:28:14 -08006149 if( (pSrcReq->skipDfsChnlInP2pSearch &&
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08006150 (NV_CHANNEL_DFS == vos_nv_getChannelEnabledState(pSrcReq->ChannelInfo.ChannelList[index])) )
Srikant Kuppa866893f2012-12-27 17:28:14 -08006151#ifdef FEATURE_WLAN_LFR
6152 /*
6153 * If LFR is requesting a contiguous scan
6154 * (i.e. numOfChannels > 1), then ignore
6155 * DFS channels.
6156 * TODO: vos_nv_getChannelEnabledState is returning
6157 * 120, 124 and 128 as non-DFS channels. Hence, the
6158 * use of direct check for channels below.
6159 */
6160 || ((eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType) &&
6161 (pSrcReq->ChannelInfo.numOfChannels > 1) &&
Srinivas Girigowdade697412013-02-14 16:31:48 -08006162 (CSR_IS_CHANNEL_DFS(pSrcReq->ChannelInfo.ChannelList[index])))
Srikant Kuppa866893f2012-12-27 17:28:14 -08006163#endif
6164 )
6165 {
6166#ifdef FEATURE_WLAN_LFR
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006167 smsLog(pMac, LOG2,
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306168 FL(" reqType=%d, numOfChannels=%d,"
6169 " ignoring DFS channel %d"),
6170 pSrcReq->requestType,
Srikant Kuppa866893f2012-12-27 17:28:14 -08006171 pSrcReq->ChannelInfo.numOfChannels,
6172 pSrcReq->ChannelInfo.ChannelList[index]);
6173#endif
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306174 continue;
Srikant Kuppa866893f2012-12-27 17:28:14 -08006175 }
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08006176
Jeff Johnson295189b2012-06-20 16:38:30 -07006177 pDstReq->ChannelInfo.ChannelList[new_index] =
6178 pSrcReq->ChannelInfo.ChannelList[index];
6179 new_index++;
6180 }
6181 }
6182 pDstReq->ChannelInfo.numOfChannels = new_index;
Srikant Kuppa866893f2012-12-27 17:28:14 -08006183#ifdef FEATURE_WLAN_LFR
6184 if ((eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType) &&
6185 (0 == pDstReq->ChannelInfo.numOfChannels))
6186 {
6187 /*
6188 * No valid channels found in the request.
6189 * Only perform scan on the channels passed
6190 * pSrcReq if it is a eCSR_SCAN_HO_BG_SCAN.
6191 * Passing 0 to LIM will trigger a scan on
6192 * all valid channels which is not desirable.
6193 */
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306194 smsLog(pMac, LOGE, FL(" no valid channels found"
6195 " (request=%d)"), pSrcReq->requestType);
Srikant Kuppa866893f2012-12-27 17:28:14 -08006196 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
6197 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306198 smsLog(pMac, LOGE, FL("pSrcReq index=%d"
6199 " channel=%d"), index,
6200 pSrcReq->ChannelInfo.ChannelList[index]);
Srikant Kuppa866893f2012-12-27 17:28:14 -08006201 }
6202 status = eHAL_STATUS_FAILURE;
6203 break;
6204 }
6205#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006206 }
6207 else
6208 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306209 smsLog(pMac, LOGE, FL("Couldn't get the valid Channel"
6210 " List, keeping requester's list"));
Kiet Lam64c1b492013-07-12 13:56:44 +05306211 vos_mem_copy(pDstReq->ChannelInfo.ChannelList,
6212 pSrcReq->ChannelInfo.ChannelList,
6213 pSrcReq->ChannelInfo.numOfChannels
6214 * sizeof(*pDstReq->ChannelInfo.ChannelList));
Jeff Johnson295189b2012-06-20 16:38:30 -07006215 pDstReq->ChannelInfo.numOfChannels = pSrcReq->ChannelInfo.numOfChannels;
6216 }
6217 }//Allocate memory for Channel List
6218 }
6219 if(pSrcReq->SSIDs.numOfSSIDs == 0)
6220 {
6221 pDstReq->SSIDs.numOfSSIDs = 0;
6222 pDstReq->SSIDs.SSIDList = NULL;
6223 }
6224 else
6225 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306226 pDstReq->SSIDs.SSIDList = vos_mem_malloc(
6227 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
6228 if ( NULL == pDstReq->SSIDs.SSIDList )
6229 status = eHAL_STATUS_FAILURE;
6230 else
6231 status = eHAL_STATUS_SUCCESS;
6232 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07006233 {
6234 pDstReq->SSIDs.numOfSSIDs = pSrcReq->SSIDs.numOfSSIDs;
Kiet Lam64c1b492013-07-12 13:56:44 +05306235 vos_mem_copy(pDstReq->SSIDs.SSIDList,
6236 pSrcReq->SSIDs.SSIDList,
6237 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
Jeff Johnson295189b2012-06-20 16:38:30 -07006238 }
6239 else
6240 {
6241 pDstReq->SSIDs.numOfSSIDs = 0;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306242 smsLog(pMac, LOGE, FL("No memory for scanning SSID List"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006243 break;
6244 }
6245 }//Allocate memory for SSID List
Jeff Johnson295189b2012-06-20 16:38:30 -07006246 pDstReq->p2pSearch = pSrcReq->p2pSearch;
Jeff Johnsone7245742012-09-05 17:12:55 -07006247 pDstReq->skipDfsChnlInP2pSearch = pSrcReq->skipDfsChnlInP2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07006248
6249 }
6250 }while(0);
6251
6252 if(!HAL_STATUS_SUCCESS(status))
6253 {
6254 csrScanFreeRequest(pMac, pDstReq);
6255 }
6256
6257 return (status);
6258}
6259
6260
6261eHalStatus csrScanFreeRequest(tpAniSirGlobal pMac, tCsrScanRequest *pReq)
6262{
Jeff Johnson295189b2012-06-20 16:38:30 -07006263
6264 if(pReq->ChannelInfo.ChannelList)
6265 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306266 vos_mem_free(pReq->ChannelInfo.ChannelList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006267 pReq->ChannelInfo.ChannelList = NULL;
6268 }
6269 pReq->ChannelInfo.numOfChannels = 0;
6270 if(pReq->pIEField)
6271 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306272 vos_mem_free(pReq->pIEField);
Jeff Johnson295189b2012-06-20 16:38:30 -07006273 pReq->pIEField = NULL;
6274 }
6275 pReq->uIEFieldLen = 0;
6276 if(pReq->SSIDs.SSIDList)
6277 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306278 vos_mem_free(pReq->SSIDs.SSIDList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006279 pReq->SSIDs.SSIDList = NULL;
6280 }
6281 pReq->SSIDs.numOfSSIDs = 0;
6282
Kiet Lam64c1b492013-07-12 13:56:44 +05306283 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07006284}
6285
6286
6287void csrScanCallCallback(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
6288{
6289 if(pCommand->u.scanCmd.callback)
6290 {
6291// sme_ReleaseGlobalLock( &pMac->sme );
6292 pCommand->u.scanCmd.callback(pMac, pCommand->u.scanCmd.pContext, pCommand->u.scanCmd.scanID, scanStatus);
6293// sme_AcquireGlobalLock( &pMac->sme );
6294 } else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006295 smsLog( pMac, LOG2, "%s:%d - Callback NULL!!!", __func__, __LINE__);
Jeff Johnson295189b2012-06-20 16:38:30 -07006296 }
6297}
6298
6299
6300void csrScanStopTimers(tpAniSirGlobal pMac)
6301{
6302 csrScanStopResultAgingTimer(pMac);
6303 csrScanStopIdleScanTimer(pMac);
6304 csrScanStopGetResultTimer(pMac);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006305 if(0 != pMac->scan.scanResultCfgAgingTime )
6306 {
6307 csrScanStopResultCfgAgingTimer(pMac);
6308 }
6309
Jeff Johnson295189b2012-06-20 16:38:30 -07006310}
6311
6312
6313eHalStatus csrScanStartGetResultTimer(tpAniSirGlobal pMac)
6314{
6315 eHalStatus status;
6316
6317 if(pMac->scan.fScanEnable)
6318 {
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306319 status = vos_timer_start(&pMac->scan.hTimerGetResult, CSR_SCAN_GET_RESULT_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006320 }
6321 else
6322 {
6323 status = eHAL_STATUS_FAILURE;
6324 }
6325
6326 return (status);
6327}
6328
6329
6330eHalStatus csrScanStopGetResultTimer(tpAniSirGlobal pMac)
6331{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306332 return (vos_timer_stop(&pMac->scan.hTimerGetResult));
Jeff Johnson295189b2012-06-20 16:38:30 -07006333}
6334
6335
6336void csrScanGetResultTimerHandler(void *pv)
6337{
6338 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6339
6340 csrScanRequestResult(pMac);
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306341
6342 vos_timer_start(&pMac->scan.hTimerGetResult, CSR_SCAN_GET_RESULT_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006343}
6344
6345#ifdef WLAN_AP_STA_CONCURRENCY
6346static void csrStaApConcTimerHandler(void *pv)
6347{
6348 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6349 tListElem *pEntry;
6350 tSmeCmd *pScanCmd;
6351
6352 csrLLLock(&pMac->scan.scanCmdPendingList);
6353
6354 if ( NULL != ( pEntry = csrLLPeekHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) ) )
6355 {
6356 tCsrScanRequest scanReq;
6357 tSmeCmd *pSendScanCmd = NULL;
6358 tANI_U8 numChn = 0;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006359 tANI_U8 nNumChanCombinedConc = 0;
Vinay Malekal05fdc812012-12-17 13:04:30 -08006360 tANI_U8 i, j;
Jeff Johnson295189b2012-06-20 16:38:30 -07006361 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
6362 tANI_U8 channelToScan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
6363 eHalStatus status;
6364
Jeff Johnson295189b2012-06-20 16:38:30 -07006365 pScanCmd = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
6366 numChn = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08006367
6368 /* if any session is connected and the number of channels to scan is
6369 * greater than 1 then split the scan into multiple scan operations
6370 * on each individual channel else continue to perform scan on all
6371 * specified channels */
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08006372
6373 /* split scan if number of channels to scan is greater than 1 and
6374 * any one of the following:
6375 * - STA session is connected and the scan is not a P2P search
6376 * - any P2P session is connected
Srikant Kuppa866893f2012-12-27 17:28:14 -08006377 * Do not split scans if no concurrent infra connections are
6378 * active and if the scan is a BG scan triggered by LFR (OR)
6379 * any scan if LFR is in the middle of a BG scan. Splitting
6380 * the scan is delaying the time it takes for LFR to find
6381 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08006382 */
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006383
6384 if((csrIsStaSessionConnected(pMac) &&
6385 !csrIsP2pSessionConnected(pMac)))
6386 {
6387 nNumChanCombinedConc = pMac->roam.configParam.nNumStaChanCombinedConc;
6388 }
6389 else if(csrIsP2pSessionConnected(pMac))
6390 {
6391 nNumChanCombinedConc = pMac->roam.configParam.nNumP2PChanCombinedConc;
6392 }
6393
6394 if ( (numChn > nNumChanCombinedConc) &&
Srikant Kuppa866893f2012-12-27 17:28:14 -08006395 ((csrIsStaSessionConnected(pMac) &&
6396#ifdef FEATURE_WLAN_LFR
6397 (csrIsConcurrentInfraConnected(pMac) ||
6398 ((pScanCmd->u.scanCmd.reason != eCsrScanBgScan) &&
6399 (pMac->roam.neighborRoamInfo.neighborRoamState !=
6400 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
6401#endif
6402 (pScanCmd->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08006403 (csrIsP2pSessionConnected(pMac))))
Jeff Johnson295189b2012-06-20 16:38:30 -07006404 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306405 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006406
6407 pSendScanCmd = csrGetCommandBuffer(pMac); //optimize this to use 2 command buffer only
6408 if (!pSendScanCmd)
6409 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006410 smsLog( pMac, LOGE, FL(" Failed to get Queue command buffer") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006411 csrLLUnlock(&pMac->scan.scanCmdPendingList);
6412 return;
6413 }
6414 pSendScanCmd->command = pScanCmd->command;
6415 pSendScanCmd->sessionId = pScanCmd->sessionId;
6416 pSendScanCmd->u.scanCmd.callback = NULL;
6417 pSendScanCmd->u.scanCmd.pContext = pScanCmd->u.scanCmd.pContext;
6418 pSendScanCmd->u.scanCmd.reason = pScanCmd->u.scanCmd.reason;
6419 pSendScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
6420
Madan Mohan Koyyalamudiaf2a8b92012-10-09 14:58:07 -07006421 /* First copy all the parameters to local variable of scan request */
6422 csrScanCopyRequest(pMac, &scanReq, &pScanCmd->u.scanCmd.u.scanRequest);
6423
6424 /* Now modify the elements of local var scan request required to be modified for split scan */
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08006425 if(scanReq.ChannelInfo.ChannelList != NULL)
6426 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306427 vos_mem_free(scanReq.ChannelInfo.ChannelList);
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08006428 scanReq.ChannelInfo.ChannelList = NULL;
6429 }
6430
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006431 pChnInfo->numOfChannels = nNumChanCombinedConc;
Kiet Lam64c1b492013-07-12 13:56:44 +05306432 vos_mem_copy(&channelToScan[0],
6433 &pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[0],
6434 pChnInfo->numOfChannels * sizeof(tANI_U8));//just send one channel
Jeff Johnson295189b2012-06-20 16:38:30 -07006435 pChnInfo->ChannelList = &channelToScan[0];
6436
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006437 for (i = 0, j = nNumChanCombinedConc; i < (numChn-nNumChanCombinedConc); i++, j++)
Jeff Johnson295189b2012-06-20 16:38:30 -07006438 {
6439 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] =
Vinay Malekal05fdc812012-12-17 13:04:30 -08006440 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[j]; //Move all the channels one step
Jeff Johnson295189b2012-06-20 16:38:30 -07006441 }
6442
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006443 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = numChn - nNumChanCombinedConc; //reduce outstanding # of channels to be scanned
Jeff Johnson295189b2012-06-20 16:38:30 -07006444
6445 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
6446 //Modify callers parameters in case of concurrency
6447 scanReq.scanType = eSIR_ACTIVE_SCAN;
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -07006448 //Use concurrency values for min/maxChnTime.
6449 //We know csrIsAnySessionConnected(pMac) returns TRUE here
6450 csrSetDefaultScanTiming(pMac, scanReq.scanType, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07006451
6452 status = csrScanCopyRequest(pMac, &pSendScanCmd->u.scanCmd.u.scanRequest, &scanReq);
6453 if(!HAL_STATUS_SUCCESS(status))
6454 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006455 smsLog( pMac, LOGE, FL(" Failed to get copy csrScanRequest = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006456 csrLLUnlock(&pMac->scan.scanCmdPendingList);
6457 return;
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08006458 }
6459 /* Clean the local scan variable */
6460 scanReq.ChannelInfo.ChannelList = NULL;
6461 scanReq.ChannelInfo.numOfChannels = 0;
6462 csrScanFreeRequest(pMac, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07006463 }
6464 else
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08006465 {
6466 /* no active connected session present or numChn == 1
6467 * scan all remaining channels */
Jeff Johnson295189b2012-06-20 16:38:30 -07006468 pSendScanCmd = pScanCmd;
6469 //remove this command from pending list
6470 if (csrLLRemoveHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) == NULL)
6471 { //In case between PeekHead and here, the entry got removed by another thread.
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006472 smsLog( pMac, LOGE, FL(" Failed to remove entry from scanCmdPendingList"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006473 }
6474
6475 }
6476 csrQueueSmeCommand(pMac, pSendScanCmd, eANI_BOOLEAN_FALSE);
6477
6478 }
6479
Jeff Johnson295189b2012-06-20 16:38:30 -07006480 csrLLUnlock(&pMac->scan.scanCmdPendingList);
6481
6482}
6483#endif
6484
6485eHalStatus csrScanStartResultAgingTimer(tpAniSirGlobal pMac)
6486{
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006487 eHalStatus status = eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006488
6489 if(pMac->scan.fScanEnable)
6490 {
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306491 status = vos_timer_start(&pMac->scan.hTimerResultAging, CSR_SCAN_RESULT_AGING_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006492 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006493 return (status);
6494}
6495
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006496eHalStatus csrScanStartResultCfgAgingTimer(tpAniSirGlobal pMac)
6497{
6498 eHalStatus status = eHAL_STATUS_FAILURE;
6499
6500 if(pMac->scan.fScanEnable)
6501 {
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306502 status = vos_timer_start(&pMac->scan.hTimerResultCfgAging, CSR_SCAN_RESULT_CFG_AGING_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006503 }
6504 return (status);
6505}
Jeff Johnson295189b2012-06-20 16:38:30 -07006506
6507eHalStatus csrScanStopResultAgingTimer(tpAniSirGlobal pMac)
6508{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306509 return (vos_timer_stop(&pMac->scan.hTimerResultAging));
Jeff Johnson295189b2012-06-20 16:38:30 -07006510}
6511
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006512eHalStatus csrScanStopResultCfgAgingTimer(tpAniSirGlobal pMac)
6513{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306514 return (vos_timer_stop(&pMac->scan.hTimerResultCfgAging));
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006515}
Jeff Johnson295189b2012-06-20 16:38:30 -07006516
6517//This function returns the maximum time a BSS is allowed in the scan result.
6518//The time varies base on connection and power saving factors.
6519//Not connected, No PS
6520//Not connected, with PS
6521//Connected w/o traffic, No PS
6522//Connected w/o traffic, with PS
6523//Connected w/ traffic, no PS -- Not supported
6524//Connected w/ traffic, with PS -- Not supported
6525//the return unit is in seconds.
6526tANI_U32 csrScanGetAgeOutTime(tpAniSirGlobal pMac)
6527{
6528 tANI_U32 nRet;
6529
6530 if(pMac->scan.nAgingCountDown)
6531 {
6532 //Calculate what should be the timeout value for this
6533 nRet = pMac->scan.nLastAgeTimeOut * pMac->scan.nAgingCountDown;
6534 pMac->scan.nAgingCountDown--;
6535 }
6536 else
6537 {
6538 if( csrIsAllSessionDisconnected( pMac ) )
6539 {
6540 if(pmcIsPowerSaveEnabled(pMac, ePMC_IDLE_MODE_POWER_SAVE))
6541 {
6542 nRet = pMac->roam.configParam.scanAgeTimeNCPS;
6543 }
6544 else
6545 {
6546 nRet = pMac->roam.configParam.scanAgeTimeNCNPS;
6547 }
6548 }
6549 else
6550 {
6551 if(pmcIsPowerSaveEnabled(pMac, ePMC_BEACON_MODE_POWER_SAVE))
6552 {
6553 nRet = pMac->roam.configParam.scanAgeTimeCPS;
6554 }
6555 else
6556 {
6557 nRet = pMac->roam.configParam.scanAgeTimeCNPS;
6558 }
6559 }
6560 //If state-change causing aging time out change, we want to delay it somewhat to avoid
6561 //unnecessary removal of BSS. This is mostly due to transition from connect to disconnect.
6562 if(pMac->scan.nLastAgeTimeOut > nRet)
6563 {
6564 if(nRet)
6565 {
6566 pMac->scan.nAgingCountDown = (pMac->scan.nLastAgeTimeOut / nRet);
6567 }
6568 pMac->scan.nLastAgeTimeOut = nRet;
6569 nRet *= pMac->scan.nAgingCountDown;
6570 }
6571 else
6572 {
6573 pMac->scan.nLastAgeTimeOut = nRet;
6574 }
6575 }
6576
6577 return (nRet);
6578}
6579
6580
6581void csrScanResultAgingTimerHandler(void *pv)
6582{
6583 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6584 tANI_BOOLEAN fDisconnected = csrIsAllSessionDisconnected(pMac);
6585
6586 //no scan, no aging
6587 if(pMac->scan.fScanEnable &&
6588 (((eANI_BOOLEAN_FALSE == fDisconnected) && pMac->roam.configParam.bgScanInterval)
6589 || (fDisconnected && (pMac->scan.fCancelIdleScan == eANI_BOOLEAN_FALSE)))
6590 )
6591 {
6592 tListElem *pEntry, *tmpEntry;
6593 tCsrScanResult *pResult;
6594 tANI_TIMESTAMP ageOutTime = (tANI_TIMESTAMP)(csrScanGetAgeOutTime(pMac) * PAL_TICKS_PER_SECOND); //turn it into 10ms units
6595 tANI_TIMESTAMP curTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
6596
6597 csrLLLock(&pMac->scan.scanResultList);
6598 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
6599 while( pEntry )
6600 {
6601 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
6602 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
6603 if((curTime - pResult->Result.BssDescriptor.nReceivedTime) > ageOutTime)
6604 {
6605 smsLog(pMac, LOGW, " age out due to time out");
6606 csrScanAgeOutBss(pMac, pResult);
6607 }
6608 pEntry = tmpEntry;
6609 }
6610 csrLLUnlock(&pMac->scan.scanResultList);
6611 }
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306612 vos_timer_start(&pMac->scan.hTimerResultAging, CSR_SCAN_RESULT_AGING_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006613}
6614
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006615static void csrScanResultCfgAgingTimerHandler(void *pv)
6616{
6617 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6618 tListElem *pEntry, *tmpEntry;
6619 tCsrScanResult *pResult;
6620 tANI_TIMESTAMP ageOutTime = pMac->scan.scanResultCfgAgingTime * PAL_TICKS_PER_SECOND;
6621 tANI_TIMESTAMP curTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
6622
6623 csrLLLock(&pMac->scan.scanResultList);
6624 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
6625 while( pEntry )
6626 {
6627 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
6628 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
6629 if((curTime - pResult->Result.BssDescriptor.nReceivedTime) > ageOutTime)
6630 {
6631 smsLog(pMac, LOGW, " age out due to time out");
6632 csrScanAgeOutBss(pMac, pResult);
6633 }
6634 pEntry = tmpEntry;
6635 }
6636 csrLLUnlock(&pMac->scan.scanResultList);
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306637 vos_timer_start(&pMac->scan.hTimerResultCfgAging, CSR_SCAN_RESULT_CFG_AGING_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006638}
Jeff Johnson295189b2012-06-20 16:38:30 -07006639
6640eHalStatus csrScanStartIdleScanTimer(tpAniSirGlobal pMac, tANI_U32 interval)
6641{
6642 eHalStatus status;
6643
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006644 smsLog(pMac, LOG1, " csrScanStartIdleScanTimer");
Jeff Johnson295189b2012-06-20 16:38:30 -07006645 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) && interval)
6646 {
6647 pMac->scan.nIdleScanTimeGap += interval;
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306648 vos_timer_stop(&pMac->scan.hTimerIdleScan);
6649 status = vos_timer_start(&pMac->scan.hTimerIdleScan, interval/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006650 if( !HAL_STATUS_SUCCESS(status) )
6651 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006652 smsLog(pMac, LOGE, " Fail to start Idle scan timer. status = %d interval = %d", status, interval);
Jeff Johnson295189b2012-06-20 16:38:30 -07006653 //This should not happen but set the flag to restart when ready
6654 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6655 }
6656 }
6657 else
6658 {
6659 if( pMac->scan.fScanEnable && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) )
6660 {
6661 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6662 }
6663 status = eHAL_STATUS_FAILURE;
6664 }
6665
6666 return (status);
6667}
6668
6669
6670eHalStatus csrScanStopIdleScanTimer(tpAniSirGlobal pMac)
6671{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306672 return (vos_timer_stop(&pMac->scan.hTimerIdleScan));
Jeff Johnson295189b2012-06-20 16:38:30 -07006673}
6674
6675
6676//Stop CSR from asking for IMPS, This function doesn't disable IMPS from CSR
6677void csrScanSuspendIMPS( tpAniSirGlobal pMac )
6678{
6679 csrScanCancelIdleScan(pMac);
6680}
6681
6682
6683//Start CSR from asking for IMPS. This function doesn't trigger CSR to request entering IMPS
6684//because IMPS maybe disabled.
6685void csrScanResumeIMPS( tpAniSirGlobal pMac )
6686{
6687 csrScanStartIdleScan( pMac );
6688}
6689
6690
6691void csrScanIMPSCallback(void *callbackContext, eHalStatus status)
6692{
6693 tpAniSirGlobal pMac = PMAC_STRUCT( callbackContext );
6694
6695 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6696 {
6697 if(pMac->roam.configParam.IsIdleScanEnabled)
6698 {
6699 if(HAL_STATUS_SUCCESS(status))
6700 {
6701 if(csrIsAllSessionDisconnected(pMac) && !csrIsRoamCommandWaiting(pMac))
6702 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006703 smsLog(pMac, LOGW, FL("starts idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006704 csrScanAllChannels(pMac, eCSR_SCAN_IDLE_MODE_SCAN);
6705 }
6706 else
6707 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006708 smsLog(pMac, LOGW, FL("cannot start idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006709 //even though we are in timer handle, calling stop timer will make sure the timer
6710 //doesn't get to restart.
6711 csrScanStopIdleScanTimer(pMac);
6712 }
6713 }
6714 else
6715 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006716 smsLog(pMac, LOGE, FL("sees not success status (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07006717 }
6718 }
6719 else
6720 {//we might need another flag to check if CSR needs to request imps at all
6721
6722 tANI_U32 nTime = 0;
6723
6724 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_FALSE;
6725 if(!HAL_STATUS_SUCCESS(csrScanTriggerIdleScan(pMac, &nTime)))
6726 {
6727 csrScanStartIdleScanTimer(pMac, nTime);
6728 }
6729 }
6730 }
6731}
6732
6733
6734//Param: pTimeInterval -- Caller allocated memory in return, if failed, to specify the nxt time interval for
6735//idle scan timer interval
6736//Return: Not success -- meaning it cannot start IMPS, caller needs to start a timer for idle scan
6737eHalStatus csrScanTriggerIdleScan(tpAniSirGlobal pMac, tANI_U32 *pTimeInterval)
6738{
6739 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
6740
6741 //Do not trigger IMPS in case of concurrency
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006742 if (vos_concurrent_sessions_running() && csrIsAnySessionInConnectState(pMac))
6743 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006744 smsLog( pMac, LOG1, FL("Cannot request IMPS because Concurrent Sessions Running") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006745 return (status);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006746 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006747
6748 if(pTimeInterval)
6749 {
6750 *pTimeInterval = 0;
6751 }
6752
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006753 smsLog(pMac, LOG3, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006754 if( smeCommandPending( pMac ) )
6755 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006756 smsLog( pMac, LOG1, FL(" Cannot request IMPS because command pending") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006757 //Not to enter IMPS because more work to do
6758 if(pTimeInterval)
6759 {
6760 *pTimeInterval = 0;
6761 }
6762 //restart when ready
6763 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6764
6765 return (status);
6766 }
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07006767 if (IsPmcImpsReqFailed (pMac))
6768 {
6769 if(pTimeInterval)
6770 {
6771 *pTimeInterval = 1000000; //usec
6772 }
6773 //restart when ready
6774 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006775
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07006776 return status;
6777 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006778 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6779 /*&& pMac->roam.configParam.impsSleepTime*/)
6780 {
6781 //Stop get result timer because idle scan gets scan result out of PE
6782 csrScanStopGetResultTimer(pMac);
6783 if(pTimeInterval)
6784 {
6785 *pTimeInterval = pMac->roam.configParam.impsSleepTime;
6786 }
6787 //pmcRequestImps take a period in millisecond unit.
6788 status = pmcRequestImps(pMac, pMac->roam.configParam.impsSleepTime / PAL_TIMER_TO_MS_UNIT, csrScanIMPSCallback, pMac);
6789 if(!HAL_STATUS_SUCCESS(status))
6790 {
6791 if(eHAL_STATUS_PMC_ALREADY_IN_IMPS != status)
6792 {
6793 //Do restart the timer if CSR thinks it cannot do IMPS
6794 if( !csrCheckPSReady( pMac ) )
6795 {
6796 if(pTimeInterval)
6797 {
6798 *pTimeInterval = 0;
6799 }
6800 //Set the restart flag to true because that idle scan
6801 //can be restarted even though the timer will not be running
6802 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6803 }
6804 else
6805 {
6806 //For not now, we do a quicker retry
6807 if(pTimeInterval)
6808 {
6809 *pTimeInterval = CSR_IDLE_SCAN_WAIT_TIME;
6810 }
6811 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006812 smsLog(pMac, LOGW, FL("call pmcRequestImps and it returns status code (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07006813 }
6814 else
6815 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006816 smsLog(pMac, LOGW, FL("already in IMPS"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006817 //Since CSR is the only module to request for IMPS. If it is already in IMPS, CSR assumes
6818 //the callback will be called in the future. Should not happen though.
6819 status = eHAL_STATUS_SUCCESS;
6820 pMac->scan.nIdleScanTimeGap = 0;
6821 }
6822 }
6823 else
6824 {
6825 //requested so let's reset the value
6826 pMac->scan.nIdleScanTimeGap = 0;
6827 }
6828 }
6829
6830 return (status);
6831}
6832
6833
6834eHalStatus csrScanStartIdleScan(tpAniSirGlobal pMac)
6835{
6836 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
6837 tANI_U32 nTime = 0;
6838
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006839 smsLog(pMac, LOGW, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006840 if(pMac->roam.configParam.IsIdleScanEnabled)
6841 {
6842 //stop bg scan first
6843 csrScanBGScanAbort(pMac);
6844 //Stop get result timer because idle scan gets scan result out of PE
6845 csrScanStopGetResultTimer(pMac);
6846 //Enable aging timer since idle scan is going on
6847 csrScanStartResultAgingTimer(pMac);
6848 }
6849 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_FALSE;
6850 status = csrScanTriggerIdleScan(pMac, &nTime);
6851 if(!HAL_STATUS_SUCCESS(status))
6852 {
6853 csrScanStartIdleScanTimer(pMac, nTime);
6854 }
6855
6856 return (status);
6857}
6858
6859
6860void csrScanCancelIdleScan(tpAniSirGlobal pMac)
6861{
6862 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6863 {
Jeff Johnson295189b2012-06-20 16:38:30 -07006864 if (vos_concurrent_sessions_running()) {
6865 return;
6866 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006867 smsLog(pMac, LOG1, " csrScanCancelIdleScan");
Jeff Johnson295189b2012-06-20 16:38:30 -07006868 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_TRUE;
6869 //Set the restart flag in case later on it is uncancelled
6870 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6871 csrScanStopIdleScanTimer(pMac);
6872 csrScanRemoveNotRoamingScanCommand(pMac);
6873 }
6874}
6875
6876
6877void csrScanIdleScanTimerHandler(void *pv)
6878{
6879 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6880 eHalStatus status;
6881 tANI_U32 nTime = 0;
6882
6883 smsLog(pMac, LOGW, " csrScanIdleScanTimerHandler called ");
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07006884 pmcResetImpsFailStatus (pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07006885 status = csrScanTriggerIdleScan(pMac, &nTime);
6886 if(!HAL_STATUS_SUCCESS(status) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan))
6887 {
6888 //Check whether it is time to actually do an idle scan
6889 if(pMac->scan.nIdleScanTimeGap >= pMac->roam.configParam.impsSleepTime)
6890 {
6891 pMac->scan.nIdleScanTimeGap = 0;
6892 csrScanIMPSCallback(pMac, eHAL_STATUS_SUCCESS);
6893 }
6894 else
6895 {
6896 csrScanStartIdleScanTimer(pMac, nTime);
6897 }
6898 }
6899}
6900
6901
6902
6903
6904tANI_BOOLEAN csrScanRemoveNotRoamingScanCommand(tpAniSirGlobal pMac)
6905{
6906 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
6907 tListElem *pEntry, *pEntryTmp;
6908 tSmeCmd *pCommand;
6909 tDblLinkList localList;
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306910 tDblLinkList *pCmdList;
Jeff Johnson295189b2012-06-20 16:38:30 -07006911
6912 vos_mem_zero(&localList, sizeof(tDblLinkList));
6913 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
6914 {
6915 smsLog(pMac, LOGE, FL(" failed to open list"));
6916 return fRet;
6917 }
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306918 if (!pMac->fScanOffload)
6919 pCmdList = &pMac->sme.smeCmdPendingList;
6920 else
6921 pCmdList = &pMac->sme.smeScanCmdPendingList;
Jeff Johnson295189b2012-06-20 16:38:30 -07006922
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306923 csrLLLock(pCmdList);
6924 pEntry = csrLLPeekHead(pCmdList, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07006925 while(pEntry)
6926 {
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306927 pEntryTmp = csrLLNext(pCmdList, pEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07006928 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6929 if( eSmeCommandScan == pCommand->command )
6930 {
6931 switch( pCommand->u.scanCmd.reason )
6932 {
6933 case eCsrScanIdleScan:
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306934 if( csrLLRemoveEntry(pCmdList, pEntry, LL_ACCESS_NOLOCK) )
Jeff Johnson295189b2012-06-20 16:38:30 -07006935 {
6936 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
6937 }
6938 fRet = eANI_BOOLEAN_TRUE;
6939 break;
6940
6941 default:
6942 break;
6943 } //switch
6944 }
6945 pEntry = pEntryTmp;
6946 }
6947
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306948 csrLLUnlock(pCmdList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006949
6950 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
6951 {
6952 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6953 csrReleaseCommandScan( pMac, pCommand );
6954 }
6955
6956 csrLLClose(&localList);
6957
6958 return (fRet);
6959}
6960
6961
6962tANI_BOOLEAN csrScanRemoveFreshScanCommand(tpAniSirGlobal pMac, tANI_U8 sessionId)
6963{
6964 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
6965 tListElem *pEntry, *pEntryTmp;
6966 tSmeCmd *pCommand;
6967 tDblLinkList localList;
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306968 tDblLinkList *pCmdList;
Jeff Johnson295189b2012-06-20 16:38:30 -07006969
6970 vos_mem_zero(&localList, sizeof(tDblLinkList));
6971 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
6972 {
6973 smsLog(pMac, LOGE, FL(" failed to open list"));
6974 return fRet;
6975 }
6976
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306977 if (!pMac->fScanOffload)
6978 pCmdList = &pMac->sme.smeCmdPendingList;
6979 else
6980 pCmdList = &pMac->sme.smeScanCmdPendingList;
6981
6982 csrLLLock(pCmdList);
6983 pEntry = csrLLPeekHead(pCmdList, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07006984 while(pEntry)
6985 {
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306986 pEntryTmp = csrLLNext(pCmdList, pEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07006987 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6988 if( (eSmeCommandScan == pCommand->command) && (sessionId == pCommand->sessionId) )
6989 {
6990 switch(pCommand->u.scanCmd.reason)
6991 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006992#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
6993 case eCsrScanGetLfrResult:
6994#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006995 case eCsrScanGetResult:
6996 case eCsrScanSetBGScanParam:
6997 case eCsrScanBGScanAbort:
6998 case eCsrScanBGScanEnable:
6999 case eCsrScanGetScanChnInfo:
7000 break;
7001 default:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007002 smsLog (pMac, LOGW, "%s: -------- abort scan command reason = %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007003 __func__, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07007004 //The rest are fresh scan requests
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307005 if( csrLLRemoveEntry(pCmdList, pEntry, LL_ACCESS_NOLOCK) )
Jeff Johnson295189b2012-06-20 16:38:30 -07007006 {
7007 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
7008 }
7009 fRet = eANI_BOOLEAN_TRUE;
7010 break;
7011 }
7012 }
7013 pEntry = pEntryTmp;
7014 }
7015
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307016 csrLLUnlock(pCmdList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007017
7018 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
7019 {
7020 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7021 if (pCommand->u.scanCmd.callback)
7022 {
7023 /* User scan request is pending,
7024 * send response with status eCSR_SCAN_ABORT*/
7025 pCommand->u.scanCmd.callback(pMac,
7026 pCommand->u.scanCmd.pContext,
7027 pCommand->u.scanCmd.scanID,
7028 eCSR_SCAN_ABORT);
7029 }
7030 csrReleaseCommandScan( pMac, pCommand );
7031 }
7032 csrLLClose(&localList);
7033
7034 return (fRet);
7035}
7036
7037
7038void csrReleaseScanCommand(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
7039{
7040 eCsrScanReason reason = pCommand->u.scanCmd.reason;
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307041 tANI_BOOLEAN status;
7042
7043 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07007044 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307045 tANI_U32 i;
7046 for(i = 0; i < CSR_ROAM_SESSION_MAX; i++)
7047 csrRoamStateChange(pMac, pCommand->u.scanCmd.lastRoamState[i], i);
7048 }
7049 else
7050 {
7051 csrRoamStateChange(pMac,
7052 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId],
7053 pCommand->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07007054 }
7055
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307056 csrScanCallCallback(pMac, pCommand, scanStatus);
Jeff Johnson295189b2012-06-20 16:38:30 -07007057
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007058 smsLog(pMac, LOG3, " Remove Scan command reason = %d", reason);
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307059 if (pMac->fScanOffload)
7060 {
7061 status = csrLLRemoveEntry(&pMac->sme.smeScanCmdActiveList,
7062 &pCommand->Link, LL_ACCESS_LOCK);
7063 }
7064 else
7065 {
7066 status = csrLLRemoveEntry(&pMac->sme.smeCmdActiveList,
7067 &pCommand->Link, LL_ACCESS_LOCK);
7068 }
7069
7070 if(status)
Jeff Johnson295189b2012-06-20 16:38:30 -07007071 {
7072 csrReleaseCommandScan( pMac, pCommand );
7073 }
7074 else
7075 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307076 smsLog(pMac, LOGE,
7077 " ********csrReleaseScanCommand cannot release command reason %d",
7078 pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07007079 }
7080}
7081
7082
7083eHalStatus csrScanGetPMKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
7084 tPmkidCandidateInfo *pPmkidList, tANI_U32 *pNumItems )
7085{
7086 eHalStatus status = eHAL_STATUS_SUCCESS;
7087 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
7088
Jeff Johnson32d95a32012-09-10 13:15:23 -07007089 if(!pSession)
7090 {
7091 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
7092 return eHAL_STATUS_FAILURE;
7093 }
7094
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007095 smsLog(pMac, LOGW, " pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07007096 csrResetPMKIDCandidateList(pMac, sessionId);
7097 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
7098 {
7099 tCsrScanResultFilter *pScanFilter;
7100 tCsrScanResultInfo *pScanResult;
7101 tScanResultHandle hBSSList;
7102 tANI_U32 nItems = *pNumItems;
7103
7104 *pNumItems = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05307105 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
7106 if ( NULL == pScanFilter )
7107 status = eHAL_STATUS_FAILURE;
7108 else
Jeff Johnson295189b2012-06-20 16:38:30 -07007109 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307110 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007111 //Here is the profile we need to connect to
7112 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
7113 if(HAL_STATUS_SUCCESS(status))
7114 {
7115 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
7116 if(HAL_STATUS_SUCCESS(status))
7117 {
7118 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumPmkidCandidate < nItems))
7119 {
7120 //NumPmkidCandidate adds up here
7121 csrProcessBSSDescForPMKIDList(pMac, &pScanResult->BssDescriptor,
7122 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
7123 }
7124 if(pSession->NumPmkidCandidate)
7125 {
7126 *pNumItems = pSession->NumPmkidCandidate;
Kiet Lam64c1b492013-07-12 13:56:44 +05307127 vos_mem_copy(pPmkidList, pSession->PmkidCandidateInfo,
7128 pSession->NumPmkidCandidate * sizeof(tPmkidCandidateInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07007129 }
7130 csrScanResultPurge(pMac, hBSSList);
7131 }//Have scan result
7132 csrFreeScanFilter(pMac, pScanFilter);
7133 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307134 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07007135 }
7136 }
7137
7138 return (status);
7139}
7140
7141
7142
7143#ifdef FEATURE_WLAN_WAPI
7144eHalStatus csrScanGetBKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
7145 tBkidCandidateInfo *pBkidList, tANI_U32 *pNumItems )
7146{
7147 eHalStatus status = eHAL_STATUS_SUCCESS;
7148 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
7149
Jeff Johnson32d95a32012-09-10 13:15:23 -07007150 if(!pSession)
7151 {
7152 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
7153 return eHAL_STATUS_FAILURE;
7154 }
7155
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007156 smsLog(pMac, LOGW, " pMac->scan.NumBkidCandidate = %d", pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07007157 csrResetBKIDCandidateList(pMac, sessionId);
7158 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
7159 {
7160 tCsrScanResultFilter *pScanFilter;
7161 tCsrScanResultInfo *pScanResult;
7162 tScanResultHandle hBSSList;
7163 tANI_U32 nItems = *pNumItems;
7164 *pNumItems = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05307165 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
7166 if ( NULL == pScanFilter )
7167 status = eHAL_STATUS_FAILURE;
7168 else
Jeff Johnson295189b2012-06-20 16:38:30 -07007169 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307170 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007171 //Here is the profile we need to connect to
7172 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
7173 if(HAL_STATUS_SUCCESS(status))
7174 {
7175 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
7176 if(HAL_STATUS_SUCCESS(status))
7177 {
7178 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumBkidCandidate < nItems))
7179 {
7180 //pMac->scan.NumBkidCandidate adds up here
7181 csrProcessBSSDescForBKIDList(pMac, &pScanResult->BssDescriptor,
7182 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
7183
7184 }
7185 if(pSession->NumBkidCandidate)
7186 {
7187 *pNumItems = pSession->NumBkidCandidate;
Kiet Lam64c1b492013-07-12 13:56:44 +05307188 vos_mem_copy(pBkidList, pSession->BkidCandidateInfo, pSession->NumBkidCandidate * sizeof(tBkidCandidateInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07007189 }
7190 csrScanResultPurge(pMac, hBSSList);
7191 }//Have scan result
7192 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307193 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07007194 }
7195 }
7196
7197 return (status);
7198}
7199#endif /* FEATURE_WLAN_WAPI */
7200
7201
7202
7203//This function is usually used for BSSs that suppresses SSID so the profile
7204//shall have one and only one SSID
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007205eHalStatus csrScanForSSID(tpAniSirGlobal pMac, tANI_U32 sessionId, tCsrRoamProfile *pProfile, tANI_U32 roamId, tANI_BOOLEAN notify)
Jeff Johnson295189b2012-06-20 16:38:30 -07007206{
7207 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
7208 tSmeCmd *pScanCmd = NULL;
7209 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
7210 tANI_U8 index = 0;
7211 tANI_U32 numSsid = pProfile->SSIDs.numOfSSIDs;
7212
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007213 smsLog(pMac, LOG2, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007214 //For WDS, we use the index 0. There must be at least one in there
7215 if( CSR_IS_WDS_STA( pProfile ) && numSsid )
7216 {
7217 numSsid = 1;
7218 }
7219 if(pMac->scan.fScanEnable && ( numSsid == 1 ) )
7220 {
7221 do
7222 {
7223 pScanCmd = csrGetCommandBuffer(pMac);
7224 if(!pScanCmd)
7225 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007226 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007227 break;
7228 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307229 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
7230 pScanCmd->u.scanCmd.pToRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
7231 if ( NULL == pScanCmd->u.scanCmd.pToRoamProfile )
krunal soni587bf012014-02-04 12:35:11 -08007232 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307233 status = eHAL_STATUS_FAILURE;
krunal soni587bf012014-02-04 12:35:11 -08007234 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307235 else
krunal soni587bf012014-02-04 12:35:11 -08007236 {
7237 status = csrRoamCopyProfile(pMac, pScanCmd->u.scanCmd.pToRoamProfile, pProfile);
7238 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007239 if(!HAL_STATUS_SUCCESS(status))
7240 break;
7241 pScanCmd->u.scanCmd.roamId = roamId;
7242 pScanCmd->command = eSmeCommandScan;
Jeff Johnsone7245742012-09-05 17:12:55 -07007243 pScanCmd->sessionId = (tANI_U8)sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07007244 pScanCmd->u.scanCmd.callback = NULL;
7245 pScanCmd->u.scanCmd.pContext = NULL;
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007246 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 -07007247 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Kiet Lam64c1b492013-07-12 13:56:44 +05307248 vos_mem_set(&pScanCmd->u.scanCmd.u.scanRequest, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007249 pScanCmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Jeff Johnson295189b2012-06-20 16:38:30 -07007250 pScanCmd->u.scanCmd.u.scanRequest.BSSType = pProfile->BSSType;
Jeff Johnsone7245742012-09-05 17:12:55 -07007251 // To avoid 11b rate in probe request Set p2pSearch flag as 1 for P2P Client Mode
7252 if(VOS_P2P_CLIENT_MODE == pProfile->csrPersona)
7253 {
7254 pScanCmd->u.scanCmd.u.scanRequest.p2pSearch = 1;
7255 }
Agarwal Ashish4f616132013-12-30 23:32:50 +05307256 if(pProfile->nAddIEScanLength)
Jeff Johnsone7245742012-09-05 17:12:55 -07007257 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307258 pScanCmd->u.scanCmd.u.scanRequest.pIEField = vos_mem_malloc(
7259 pProfile->nAddIEScanLength);
7260 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.pIEField )
7261 status = eHAL_STATUS_FAILURE;
7262 else
7263 status = eHAL_STATUS_SUCCESS;
7264 vos_mem_set(pScanCmd->u.scanCmd.u.scanRequest.pIEField,
7265 pProfile->nAddIEScanLength, 0);
7266 if (HAL_STATUS_SUCCESS(status))
Jeff Johnsone7245742012-09-05 17:12:55 -07007267 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307268 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.pIEField,
Agarwal Ashish4f616132013-12-30 23:32:50 +05307269 pProfile->addIEScan, pProfile->nAddIEScanLength);
Jeff Johnsone7245742012-09-05 17:12:55 -07007270 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = pProfile->nAddIEScanLength;
7271 }
7272 else
7273 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007274 smsLog(pMac, LOGE, "No memory for scanning IE fields");
Jeff Johnsone7245742012-09-05 17:12:55 -07007275 }
7276 } //Allocate memory for IE field
7277 else
7278 {
7279 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = 0;
7280 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07007281 /* For one channel be good enpugh time to receive beacon atleast */
7282 if( 1 == pProfile->ChannelInfo.numOfChannels )
7283 {
7284 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime = MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7285 pScanCmd->u.scanCmd.u.scanRequest.minChnTime = MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7286 }
7287 else
7288 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307289 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime =
7290 pMac->roam.configParam.nActiveMaxChnTime;
7291 pScanCmd->u.scanCmd.u.scanRequest.minChnTime =
7292 pMac->roam.configParam.nActiveMinChnTime;
Jeff Johnson32d95a32012-09-10 13:15:23 -07007293 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307294 pScanCmd->u.scanCmd.u.scanRequest.maxChnTimeBtc =
7295 pMac->roam.configParam.nActiveMaxChnTimeBtc;
7296 pScanCmd->u.scanCmd.u.scanRequest.minChnTimeBtc =
7297 pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07007298 if(pProfile->BSSIDs.numOfBSSIDs == 1)
7299 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307300 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.bssid,
7301 pProfile->BSSIDs.bssid, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07007302 }
7303 else
7304 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307305 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.bssid, bAddr, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07007306 }
7307 if(pProfile->ChannelInfo.numOfChannels)
7308 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307309 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(
7310 sizeof(*pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
7311 * pProfile->ChannelInfo.numOfChannels);
7312 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
7313 status = eHAL_STATUS_FAILURE;
7314 else
7315 status = eHAL_STATUS_SUCCESS;
7316 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
7317 if(HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07007318 {
7319 csrRoamIsChannelValid(pMac, pProfile->ChannelInfo.ChannelList[0]);
7320 for(index = 0; index < pProfile->ChannelInfo.numOfChannels; index++)
7321 {
7322 if(csrRoamIsValidChannel(pMac, pProfile->ChannelInfo.ChannelList[index]))
7323 {
7324 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels]
7325 = pProfile->ChannelInfo.ChannelList[index];
7326 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels++;
7327 }
7328 else
7329 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007330 smsLog(pMac, LOGW, FL("process a channel (%d) that is invalid"), pProfile->ChannelInfo.ChannelList[index]);
Jeff Johnson295189b2012-06-20 16:38:30 -07007331 }
7332
7333 }
7334 }
7335 else
7336 {
7337 break;
7338 }
7339
7340 }
7341 else
7342 {
7343 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
7344 }
7345 if(pProfile->SSIDs.numOfSSIDs)
7346 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307347 pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList = vos_mem_malloc(
7348 pProfile->SSIDs.numOfSSIDs * sizeof(tCsrSSIDInfo));
7349 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList )
7350 status = eHAL_STATUS_FAILURE;
7351 else
7352 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07007353 if(!HAL_STATUS_SUCCESS(status))
7354 {
7355 break;
7356 }
7357 pScanCmd->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 1;
Kiet Lam64c1b492013-07-12 13:56:44 +05307358 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList,
7359 pProfile->SSIDs.SSIDList, sizeof(tCsrSSIDInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07007360 }
7361 //Start process the command
7362 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
7363 if( !HAL_STATUS_SUCCESS( status ) )
7364 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007365 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07007366 break;
7367 }
7368 }while(0);
7369 if(!HAL_STATUS_SUCCESS(status))
7370 {
7371 if(pScanCmd)
7372 {
7373 csrReleaseCommandScan(pMac, pScanCmd);
7374 //TODO:free the memory that is allocated in this function
7375 }
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007376 if(notify)
7377 {
Jeff Johnson295189b2012-06-20 16:38:30 -07007378 csrRoamCallCallback(pMac, sessionId, NULL, roamId, eCSR_ROAM_FAILED, eCSR_ROAM_RESULT_FAILURE);
7379 }
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007380 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007381 }//valid
7382 else
7383 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007384 smsLog(pMac, LOGE, FL("cannot scan because scanEnable (%d) or numSSID (%d) is invalid"),
Jeff Johnson295189b2012-06-20 16:38:30 -07007385 pMac->scan.fScanEnable, pProfile->SSIDs.numOfSSIDs);
7386 }
7387
7388 return (status);
7389}
7390
7391
7392//Issue a scan base on the new capability infomation
7393//This should only happen when the associated AP changes its capability.
7394//After this scan is done, CSR reroams base on the new scan results
7395eHalStatus csrScanForCapabilityChange(tpAniSirGlobal pMac, tSirSmeApNewCaps *pNewCaps)
7396{
7397 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
7398 tSmeCmd *pScanCmd = NULL;
7399
7400 if(pNewCaps)
7401 {
7402 do
7403 {
7404 pScanCmd = csrGetCommandBuffer(pMac);
7405 if(!pScanCmd)
7406 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007407 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007408 status = eHAL_STATUS_RESOURCES;
7409 break;
7410 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307411 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007412 status = eHAL_STATUS_SUCCESS;
7413 pScanCmd->u.scanCmd.roamId = 0;
7414 pScanCmd->command = eSmeCommandScan;
7415 pScanCmd->u.scanCmd.callback = NULL;
7416 pScanCmd->u.scanCmd.pContext = NULL;
7417 pScanCmd->u.scanCmd.reason = eCsrScanForCapsChange;
7418 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
7419 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
7420 if( !HAL_STATUS_SUCCESS( status ) )
7421 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007422 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07007423 break;
7424 }
7425 }while(0);
7426 if(!HAL_STATUS_SUCCESS(status))
7427 {
7428 if(pScanCmd)
7429 {
7430 csrReleaseCommandScan(pMac, pScanCmd);
7431 }
7432 }
7433 }
7434
7435 return (status);
7436}
7437
7438
7439
7440void csrInitBGScanChannelList(tpAniSirGlobal pMac)
7441{
7442 tANI_U32 len = CSR_MIN(sizeof(pMac->roam.validChannelList), sizeof(pMac->scan.bgScanChannelList));
7443
Kiet Lam64c1b492013-07-12 13:56:44 +05307444 vos_mem_set(pMac->scan.bgScanChannelList, len, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007445 pMac->scan.numBGScanChannel = 0;
7446
7447 if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
7448 {
7449 pMac->roam.numValidChannels = len;
7450 pMac->scan.numBGScanChannel = (tANI_U8)CSR_MIN(len, WNI_CFG_BG_SCAN_CHANNEL_LIST_LEN);
Kiet Lam64c1b492013-07-12 13:56:44 +05307451 vos_mem_copy(pMac->scan.bgScanChannelList, pMac->roam.validChannelList,
7452 pMac->scan.numBGScanChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07007453 csrSetBGScanChannelList(pMac, pMac->scan.bgScanChannelList, pMac->scan.numBGScanChannel);
7454 }
7455}
7456
7457
7458//This function return TRUE if background scan channel list is adjusted.
7459//this function will only shrink the background scan channel list
7460tANI_BOOLEAN csrAdjustBGScanChannelList(tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels,
7461 tANI_U8 *pAdjustChannels, tANI_U8 *pNumAdjustChannels)
7462{
7463 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
7464 tANI_U8 i, j, count = *pNumAdjustChannels;
7465
7466 i = 0;
7467 while(i < count)
7468 {
7469 for(j = 0; j < NumChannels; j++)
7470 {
7471 if(pChannelList[j] == pAdjustChannels[i])
7472 break;
7473 }
7474 if(j == NumChannels)
7475 {
7476 //This channel is not in the list, remove it
7477 fRet = eANI_BOOLEAN_TRUE;
7478 count--;
7479 if(count - i)
7480 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307481 vos_mem_copy(&pAdjustChannels[i], &pAdjustChannels[i+1], count - i);
Jeff Johnson295189b2012-06-20 16:38:30 -07007482 }
7483 else
7484 {
7485 //already remove the last one. Done.
7486 break;
7487 }
7488 }
7489 else
7490 {
7491 i++;
7492 }
7493 }//while(i<count)
7494 *pNumAdjustChannels = count;
7495
7496 return (fRet);
7497}
7498
7499
7500//Get the list of the base channels to scan for passively 11d info
7501eHalStatus csrScanGetSupportedChannels( tpAniSirGlobal pMac )
7502{
7503 eHalStatus status = eHAL_STATUS_SUCCESS;
7504 int n = WNI_CFG_VALID_CHANNEL_LIST_LEN;
7505
7506 status = vos_nv_getSupportedChannels( pMac->scan.baseChannels.channelList, &n, NULL, NULL );
7507 if( HAL_STATUS_SUCCESS(status) )
7508 {
7509 pMac->scan.baseChannels.numChannels = (tANI_U8)n;
7510 }
7511 else
7512 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007513 smsLog( pMac, LOGE, FL(" failed") );
Jeff Johnson295189b2012-06-20 16:38:30 -07007514 pMac->scan.baseChannels.numChannels = 0;
7515 }
7516
7517 return ( status );
7518}
7519
7520//This function use the input pChannelList to validate the current saved channel list
7521eHalStatus csrSetBGScanChannelList( tpAniSirGlobal pMac, tANI_U8 *pAdjustChannels, tANI_U8 NumAdjustChannels)
7522{
7523 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumAdjustChannels;
7524
7525 return (ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pAdjustChannels, dataLen, NULL, eANI_BOOLEAN_FALSE));
7526}
7527
7528
7529void csrSetCfgValidChannelList( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels )
7530{
7531 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumChannels;
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05307532 eHalStatus status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007533
7534 ccmCfgSetStr(pMac, WNI_CFG_VALID_CHANNEL_LIST, pChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
Leela Venkata Kiran Kumar Reddy Chiralac6663f72014-02-03 21:04:58 -08007535#ifdef QCA_WIFI_2_0
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05307536 if (pMac->fScanOffload)
7537 {
7538 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
7539 "Scan offload is enabled, update default chan list");
Leela Venkata Kiran Kumar Reddy Chiralac6663f72014-02-03 21:04:58 -08007540 status = csrUpdateChannelList(pMac);
7541 }
7542#else
7543 status = csrUpdateChannelList(pMac);
7544#endif
7545
7546 if (eHAL_STATUS_SUCCESS != status)
7547 {
7548 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR,
7549 "failed to update the supported channel list");
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05307550 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007551 return;
7552}
7553
7554
7555
7556/*
7557 * The Tx power limits are saved in the cfg for future usage.
7558 */
7559void csrSaveTxPowerToCfg( tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 cfgId )
7560{
7561 tListElem *pEntry;
7562 tANI_U32 cbLen = 0, dataLen;
7563 tCsrChannelPowerInfo *pChannelSet;
7564 tANI_U32 idx;
7565 tSirMacChanInfo *pChannelPowerSet;
7566 tANI_U8 *pBuf = NULL;
7567
7568 //allocate maximum space for all channels
7569 dataLen = WNI_CFG_VALID_CHANNEL_LIST_LEN * sizeof(tSirMacChanInfo);
Kiet Lam64c1b492013-07-12 13:56:44 +05307570 if ( (pBuf = vos_mem_malloc(dataLen)) != NULL )
Jeff Johnson295189b2012-06-20 16:38:30 -07007571 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307572 vos_mem_set(pBuf, dataLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007573 pChannelPowerSet = (tSirMacChanInfo *)(pBuf);
7574
7575 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
7576 // write the tuples (startChan, numChan, txPower) for each channel found in the channel power list.
7577 while( pEntry )
7578 {
7579 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
7580 if ( 1 != pChannelSet->interChannelOffset )
7581 {
7582 // we keep the 5G channel sets internally with an interchannel offset of 4. Expand these
7583 // to the right format... (inter channel offset of 1 is the only option for the triplets
7584 // that 11d advertises.
7585 if ((cbLen + (pChannelSet->numChannels * sizeof(tSirMacChanInfo))) >= dataLen)
7586 {
7587 // expanding this entry will overflow our allocation
7588 smsLog(pMac, LOGE,
7589 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007590 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07007591 pChannelSet->firstChannel,
7592 pChannelSet->numChannels,
7593 pChannelSet->interChannelOffset);
7594 break;
7595 }
7596
7597 for( idx = 0; idx < pChannelSet->numChannels; idx++ )
7598 {
7599 pChannelPowerSet->firstChanNum = (tSirMacChanNum)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007600 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07007601 pChannelPowerSet->numChannels = 1;
Jeff Johnson295189b2012-06-20 16:38:30 -07007602 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007603 smsLog(pMac, LOG3, " Setting Max Transmit Power %d", pChannelPowerSet->maxTxPower);
Jeff Johnson295189b2012-06-20 16:38:30 -07007604 cbLen += sizeof( tSirMacChanInfo );
7605 pChannelPowerSet++;
7606 }
7607 }
7608 else
7609 {
7610 if (cbLen >= dataLen)
7611 {
7612 // this entry will overflow our allocation
7613 smsLog(pMac, LOGE,
7614 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007615 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07007616 pChannelSet->firstChannel,
7617 pChannelSet->numChannels,
7618 pChannelSet->interChannelOffset);
7619 break;
7620 }
7621 pChannelPowerSet->firstChanNum = pChannelSet->firstChannel;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007622 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07007623 pChannelPowerSet->numChannels = pChannelSet->numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -07007624 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007625 smsLog(pMac, LOG3, " Setting Max Transmit Power %d, nTxPower %d", pChannelPowerSet->maxTxPower,pMac->roam.configParam.nTxPowerCap );
Jeff Johnson295189b2012-06-20 16:38:30 -07007626
7627
7628 cbLen += sizeof( tSirMacChanInfo );
7629 pChannelPowerSet++;
7630 }
7631
7632 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
7633 }
7634
7635 if(cbLen)
7636 {
7637 ccmCfgSetStr(pMac, cfgId, (tANI_U8 *)pBuf, cbLen, NULL, eANI_BOOLEAN_FALSE);
7638 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307639 vos_mem_free(pBuf);
Jeff Johnson295189b2012-06-20 16:38:30 -07007640 }//Allocate memory
7641}
7642
7643
7644void csrSetCfgCountryCode( tpAniSirGlobal pMac, tANI_U8 *countryCode )
7645{
7646 tANI_U8 cc[WNI_CFG_COUNTRY_CODE_LEN];
7647 ///v_REGDOMAIN_t DomainId;
7648
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007649 smsLog( pMac, LOG3, "Setting Country Code in Cfg from csrSetCfgCountryCode %s",countryCode );
Kiet Lam64c1b492013-07-12 13:56:44 +05307650 vos_mem_copy(cc, countryCode, WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07007651
7652 // don't program the bogus country codes that we created for Korea in the MAC. if we see
7653 // the bogus country codes, program the MAC with the right country code.
7654 if ( ( 'K' == countryCode[ 0 ] && '1' == countryCode[ 1 ] ) ||
7655 ( 'K' == countryCode[ 0 ] && '2' == countryCode[ 1 ] ) ||
7656 ( 'K' == countryCode[ 0 ] && '3' == countryCode[ 1 ] ) ||
7657 ( 'K' == countryCode[ 0 ] && '4' == countryCode[ 1 ] ) )
7658 {
7659 // replace the alternate Korea country codes, 'K1', 'K2', .. with 'KR' for Korea
7660 cc[ 1 ] = 'R';
7661 }
7662 ccmCfgSetStr(pMac, WNI_CFG_COUNTRY_CODE, cc, WNI_CFG_COUNTRY_CODE_LEN, NULL, eANI_BOOLEAN_FALSE);
7663
7664 //Need to let HALPHY know about the current domain so it can apply some
7665 //domain-specific settings (TX filter...)
7666 /*if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(pMac, cc, &DomainId)))
7667 {
7668 halPhySetRegDomain(pMac, DomainId);
7669 }*/
7670}
7671
7672
7673
7674eHalStatus csrGetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pBuf, tANI_U8 *pbLen)
7675{
7676 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
7677 tANI_U32 len;
7678
7679 if(pBuf && pbLen && (*pbLen >= WNI_CFG_COUNTRY_CODE_LEN))
7680 {
7681 len = *pbLen;
7682 status = ccmCfgGetStr(pMac, WNI_CFG_COUNTRY_CODE, pBuf, &len);
7683 if(HAL_STATUS_SUCCESS(status))
7684 {
7685 *pbLen = (tANI_U8)len;
7686 }
7687 }
7688
7689 return (status);
7690}
7691
7692
7693void csrSetCfgScanControlList( tpAniSirGlobal pMac, tANI_U8 *countryCode, tCsrChannel *pChannelList )
7694{
7695 tANI_U8 i, j;
7696 tANI_BOOLEAN found=FALSE;
7697 tANI_U8 *pControlList = NULL;
7698 tANI_U32 len = WNI_CFG_SCAN_CONTROL_LIST_LEN;
7699
Kiet Lam64c1b492013-07-12 13:56:44 +05307700 if ( (pControlList = vos_mem_malloc(WNI_CFG_SCAN_CONTROL_LIST_LEN)) != NULL )
Jeff Johnson295189b2012-06-20 16:38:30 -07007701 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307702 vos_mem_set((void *)pControlList, WNI_CFG_SCAN_CONTROL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007703 if(HAL_STATUS_SUCCESS(ccmCfgGetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, &len)))
7704 {
7705 for (i = 0; i < pChannelList->numChannels; i++)
7706 {
7707 for (j = 0; j < len; j += 2)
7708 {
7709 if (pControlList[j] == pChannelList->channelList[i])
7710 {
7711 found = TRUE;
7712 break;
7713 }
7714 }
7715
7716 if (found) // insert a pair(channel#, flag)
7717 {
Gopichand Nakkala392cbc12013-05-28 16:15:00 +05307718 pControlList[j+1] = csrGetScanType(pMac, pControlList[j]);
Jeff Johnson295189b2012-06-20 16:38:30 -07007719 found = FALSE; // reset the flag
7720 }
7721
7722 }
7723
7724 ccmCfgSetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, len, NULL, eANI_BOOLEAN_FALSE);
7725 }//Successfully getting scan control list
Kiet Lam64c1b492013-07-12 13:56:44 +05307726 vos_mem_free(pControlList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007727 }//AllocateMemory
7728}
7729
7730
7731//if bgPeriod is 0, background scan is disabled. It is in millisecond units
7732eHalStatus csrSetCfgBackgroundScanPeriod(tpAniSirGlobal pMac, tANI_U32 bgPeriod)
7733{
7734 return (ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, bgPeriod, (tCcmCfgSetCallback) csrScanCcmCfgSetCallback, eANI_BOOLEAN_FALSE));
7735}
7736
7737
7738void csrScanCcmCfgSetCallback(tHalHandle hHal, tANI_S32 result)
7739{
7740 tListElem *pEntry = NULL;
7741 tSmeCmd *pCommand = NULL;
7742 tpAniSirGlobal pMac = PMAC_STRUCT( hHal );
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307743 tDblLinkList *pCmdList ;
7744
7745 if (!pMac->fScanOffload)
7746 pCmdList = &pMac->sme.smeCmdActiveList;
7747 else
7748 pCmdList = &pMac->sme.smeScanCmdActiveList;
7749
7750 pEntry = csrLLPeekHead( pCmdList, LL_ACCESS_LOCK );
Jeff Johnson295189b2012-06-20 16:38:30 -07007751 if ( pEntry )
7752 {
7753 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7754 if ( eSmeCommandScan == pCommand->command )
7755 {
7756 eCsrScanStatus scanStatus = (CCM_IS_RESULT_SUCCESS(result)) ? eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
7757 csrReleaseScanCommand(pMac, pCommand, scanStatus);
7758 }
7759 else
7760 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007761 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
Jeff Johnson295189b2012-06-20 16:38:30 -07007762 }
7763 }
7764 smeProcessPendingQueue( pMac );
7765}
7766
7767eHalStatus csrProcessSetBGScanParam(tpAniSirGlobal pMac, tSmeCmd *pCommand)
7768{
7769 eHalStatus status;
7770 tCsrBGScanRequest *pScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
7771 tANI_U32 dataLen = sizeof( tANI_U8 ) * pScanReq->ChannelInfo.numOfChannels;
7772
7773 //***setcfg for background scan channel list
7774 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MINIMUM_CHANNEL_TIME, pScanReq->minChnTime, NULL, eANI_BOOLEAN_FALSE);
7775 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MAXIMUM_CHANNEL_TIME, pScanReq->maxChnTime, NULL, eANI_BOOLEAN_FALSE);
7776 //Not set the background scan interval if not connected because bd scan should not be run if not connected
7777 if(!csrIsAllSessionDisconnected(pMac))
7778 {
7779 //If disbaling BG scan here, we need to stop aging as well
7780 if(pScanReq->scanInterval == 0)
7781 {
7782 //Stop aging because no new result is coming in
7783 csrScanStopResultAgingTimer(pMac);
7784 }
7785
7786#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
7787 {
7788 vos_log_scan_pkt_type *pScanLog = NULL;
7789
7790 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
7791 if(pScanLog)
7792 {
7793 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
7794 pScanLog->minChnTime = (v_U8_t)pScanReq->minChnTime;
7795 pScanLog->maxChnTime = (v_U8_t)pScanReq->maxChnTime;
7796 pScanLog->timeBetweenBgScan = (v_U8_t)pScanReq->scanInterval;
7797 pScanLog->numChannel = pScanReq->ChannelInfo.numOfChannels;
7798 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
7799 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307800 vos_mem_copy(pScanLog->channels,
7801 pScanReq->ChannelInfo.ChannelList,
7802 pScanLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07007803 }
7804 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
7805 }
7806 }
7807#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
7808
7809 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, pScanReq->scanInterval, NULL, eANI_BOOLEAN_FALSE);
7810 }
7811 else
7812 {
7813 //No need to stop aging because IDLE scan is still running
7814 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, 0, NULL, eANI_BOOLEAN_FALSE);
7815 }
7816
7817 if(pScanReq->SSID.length > WNI_CFG_SSID_LEN)
7818 {
7819 pScanReq->SSID.length = WNI_CFG_SSID_LEN;
7820 }
7821
7822 status = ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pScanReq->ChannelInfo.ChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
7823 status = ccmCfgSetStr(pMac, WNI_CFG_SSID, (tANI_U8 *)pScanReq->SSID.ssId, pScanReq->SSID.length, NULL, eANI_BOOLEAN_FALSE);
7824
7825
7826
7827 return (status);
7828}
7829
7830
Srinivas, Dasari138af4f2014-02-07 11:13:45 +05307831eHalStatus csrScanAbortMacScan(tpAniSirGlobal pMac, tANI_U8 sessionId,
7832 eCsrAbortReason reason)
Jeff Johnson295189b2012-06-20 16:38:30 -07007833{
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307834 eHalStatus status = eHAL_STATUS_FAILURE;
7835 tSirSmeScanAbortReq *pMsg;
Jeff Johnson295189b2012-06-20 16:38:30 -07007836 tANI_U16 msgLen;
7837 tListElem *pEntry;
7838 tSmeCmd *pCommand;
7839
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307840 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07007841 {
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307842#ifdef WLAN_AP_STA_CONCURRENCY
7843 csrLLLock(&pMac->scan.scanCmdPendingList);
7844 while(NULL !=
7845 (pEntry = csrLLRemoveHead(&pMac->scan.scanCmdPendingList,
7846 LL_ACCESS_NOLOCK)))
7847 {
Jeff Johnson295189b2012-06-20 16:38:30 -07007848
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307849 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7850 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
7851 }
7852 csrLLUnlock(&pMac->scan.scanCmdPendingList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007853#endif
7854
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307855 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
7856 csrRemoveCmdFromPendingList( pMac, &pMac->roam.roamCmdPendingList, eSmeCommandScan);
7857 csrRemoveCmdFromPendingList( pMac, &pMac->sme.smeCmdPendingList, eSmeCommandScan);
7858 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
7859
7860 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
7861 }
7862 else
7863 {
7864 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
7865 csrRemoveCmdWithSessionIdFromPendingList(pMac,
7866 sessionId,
7867 &pMac->sme.smeScanCmdPendingList,
7868 eSmeCommandScan);
7869 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
7870
7871 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
7872 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007873
7874 //We need to abort scan only if we are scanning
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307875 if(NULL != pEntry)
Jeff Johnson295189b2012-06-20 16:38:30 -07007876 {
7877 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307878 if(eSmeCommandScan == pCommand->command &&
7879 pCommand->sessionId == sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07007880 {
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307881 msgLen = (tANI_U16)(sizeof(tSirSmeScanAbortReq));
Kiet Lam64c1b492013-07-12 13:56:44 +05307882 pMsg = vos_mem_malloc(msgLen);
7883 if ( NULL == pMsg )
Jeff Johnson295189b2012-06-20 16:38:30 -07007884 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307885 status = eHAL_STATUS_FAILURE;
7886 smsLog(pMac, LOGE, FL("Failed to allocate memory for SmeScanAbortReq"));
7887 }
7888 else
7889 {
7890 vos_mem_set((void *)pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007891 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_ABORT_IND);
7892 pMsg->msgLen = pal_cpu_to_be16(msgLen);
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307893 pMsg->sessionId = sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07007894 status = palSendMBMessage(pMac->hHdd, pMsg);
7895 }
7896 }
7897 }
7898
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307899 return(status);
7900}
7901
7902void csrRemoveCmdWithSessionIdFromPendingList(tpAniSirGlobal pMac,
7903 tANI_U8 sessionId,
7904 tDblLinkList *pList,
7905 eSmeCommandType commandType)
7906{
7907 tDblLinkList localList;
7908 tListElem *pEntry;
7909 tSmeCmd *pCommand;
7910 tListElem *pEntryToRemove;
7911
7912 vos_mem_zero(&localList, sizeof(tDblLinkList));
7913 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
7914 {
7915 smsLog(pMac, LOGE, FL(" failed to open list"));
7916 return;
7917 }
7918
7919 csrLLLock(pList);
7920 if ((pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK)))
7921 {
7922
7923 /* Have to make sure we don't loop back to the head of the list,
7924 * which will happen if the entry is NOT on the list */
7925 while (pEntry)
7926 {
7927 pEntryToRemove = pEntry;
7928 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
7929 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
7930 if ((pCommand->command == commandType) &&
7931 (pCommand->sessionId == sessionId))
7932 {
7933 /* Remove that entry only */
7934 if (csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
7935 {
7936 csrLLInsertTail(&localList, pEntryToRemove,
7937 LL_ACCESS_NOLOCK);
7938 }
7939 }
7940 }
7941 }
7942 csrLLUnlock(pList);
7943
7944 while ((pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)))
7945 {
7946 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7947 csrAbortCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
7948 }
7949
7950 csrLLClose(&localList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007951}
7952
7953void csrRemoveCmdFromPendingList(tpAniSirGlobal pMac, tDblLinkList *pList,
7954 eSmeCommandType commandType )
7955{
7956 tDblLinkList localList;
7957 tListElem *pEntry;
7958 tSmeCmd *pCommand;
7959 tListElem *pEntryToRemove;
7960
7961 vos_mem_zero(&localList, sizeof(tDblLinkList));
7962 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
7963 {
7964 smsLog(pMac, LOGE, FL(" failed to open list"));
7965 return;
7966 }
7967
7968 csrLLLock(pList);
7969 if( !csrLLIsListEmpty( pList, LL_ACCESS_NOLOCK ) )
7970 {
7971 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK);
7972
7973 // Have to make sure we don't loop back to the head of the list, which will
7974 // happen if the entry is NOT on the list...
7975 while( pEntry )
7976 {
7977 pEntryToRemove = pEntry;
7978 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
7979 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
7980 if ( pCommand->command == commandType )
7981 {
7982 // Remove that entry only
7983 if(csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
7984 {
7985 csrLLInsertTail(&localList, pEntryToRemove, LL_ACCESS_NOLOCK);
7986 }
7987 }
7988 }
7989
7990
7991 }
7992 csrLLUnlock(pList);
7993
7994 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
7995 {
7996 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7997 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
7998 }
7999 csrLLClose(&localList);
8000
8001}
8002
8003
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308004eHalStatus csrScanAbortMacScanNotForConnect(tpAniSirGlobal pMac,
8005 tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07008006{
8007 eHalStatus status = eHAL_STATUS_SUCCESS;
8008
8009 if( !csrIsScanForRoamCommandActive( pMac ) )
8010 {
8011 //Only abort the scan if it is not used for other roam/connect purpose
Srinivas, Dasari138af4f2014-02-07 11:13:45 +05308012 status = csrScanAbortMacScan(pMac, sessionId, eCSR_SCAN_ABORT_DEFAULT);
Jeff Johnson295189b2012-06-20 16:38:30 -07008013 }
8014
8015 return (status);
8016}
8017
8018
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05308019eHalStatus csrScanGetScanChannelInfo(tpAniSirGlobal pMac, tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07008020{
8021 eHalStatus status = eHAL_STATUS_SUCCESS;
8022 tSirMbMsg *pMsg;
8023 tANI_U16 msgLen;
8024
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05308025 if (pMac->fScanOffload)
8026 msgLen = (tANI_U16)(sizeof(tSirSmeGetScanChanReq));
8027 else
8028 msgLen = (tANI_U16)(sizeof(tSirMbMsg));
8029
Kiet Lam64c1b492013-07-12 13:56:44 +05308030 pMsg = vos_mem_malloc(msgLen);
8031 if ( NULL == pMsg )
8032 status = eHAL_STATUS_FAILURE;
8033 else
Jeff Johnson295189b2012-06-20 16:38:30 -07008034 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308035 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008036 pMsg->type = eWNI_SME_GET_SCANNED_CHANNEL_REQ;
8037 pMsg->msgLen = msgLen;
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05308038 if (pMac->fScanOffload)
8039 ((tSirSmeGetScanChanReq *)pMsg)->sessionId = sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07008040 status = palSendMBMessage(pMac->hHdd, pMsg);
8041 }
8042
8043 return( status );
8044}
8045
8046tANI_BOOLEAN csrRoamIsValidChannel( tpAniSirGlobal pMac, tANI_U8 channel )
8047{
8048 tANI_BOOLEAN fValid = FALSE;
8049 tANI_U32 idxValidChannels;
8050 tANI_U32 len = pMac->roam.numValidChannels;
8051
8052 for ( idxValidChannels = 0; ( idxValidChannels < len ); idxValidChannels++ )
8053 {
8054 if ( channel == pMac->roam.validChannelList[ idxValidChannels ] )
8055 {
8056 fValid = TRUE;
8057 break;
8058 }
8059 }
8060
8061 return fValid;
8062}
8063
Manjunathappa Prakash4f1d5a52013-11-11 16:22:19 -08008064#ifdef FEATURE_WLAN_SCAN_PNO
Srikant Kuppa066904f2013-05-07 13:56:02 -07008065eHalStatus csrScanSavePreferredNetworkFound(tpAniSirGlobal pMac,
8066 tSirPrefNetworkFoundInd *pPrefNetworkFoundInd)
8067{
8068 v_U32_t uLen = 0;
8069 tpSirProbeRespBeacon pParsedFrame;
8070 tCsrScanResult *pScanResult = NULL;
8071 tSirBssDescription *pBssDescr = NULL;
8072 tANI_BOOLEAN fDupBss;
8073 tDot11fBeaconIEs *pIesLocal = NULL;
8074 tAniSSID tmpSsid;
8075 v_TIME_t timer=0;
8076 tpSirMacMgmtHdr macHeader = (tpSirMacMgmtHdr)pPrefNetworkFoundInd->data;
8077
8078 pParsedFrame =
Kiet Lam64c1b492013-07-12 13:56:44 +05308079 (tpSirProbeRespBeacon)vos_mem_malloc(sizeof(tSirProbeRespBeacon));
Srikant Kuppa066904f2013-05-07 13:56:02 -07008080
8081 if (NULL == pParsedFrame)
8082 {
8083 smsLog(pMac, LOGE, FL(" fail to allocate memory for frame"));
8084 return eHAL_STATUS_RESOURCES;
8085 }
8086
8087 if ( pPrefNetworkFoundInd->frameLength <= SIR_MAC_HDR_LEN_3A )
8088 {
8089 smsLog(pMac, LOGE,
8090 FL("Not enough bytes in PNO indication probe resp frame! length=%d"),
8091 pPrefNetworkFoundInd->frameLength);
8092 vos_mem_free(pParsedFrame);
8093 return eHAL_STATUS_FAILURE;
8094 }
8095
8096 if (sirConvertProbeFrame2Struct(pMac,
8097 &pPrefNetworkFoundInd->data[SIR_MAC_HDR_LEN_3A],
8098 pPrefNetworkFoundInd->frameLength - SIR_MAC_HDR_LEN_3A,
8099 pParsedFrame) != eSIR_SUCCESS ||
8100 !pParsedFrame->ssidPresent)
8101 {
8102 smsLog(pMac, LOGE,
8103 FL("Parse error ProbeResponse, length=%d"),
8104 pPrefNetworkFoundInd->frameLength);
8105 vos_mem_free(pParsedFrame);
8106 return eHAL_STATUS_FAILURE;
8107 }
8108 //24 byte MAC header and 12 byte to ssid IE
8109 if (pPrefNetworkFoundInd->frameLength >
8110 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET))
8111 {
8112 uLen = pPrefNetworkFoundInd->frameLength -
8113 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET);
8114 }
8115
Kiet Lam64c1b492013-07-12 13:56:44 +05308116 pScanResult = vos_mem_malloc(sizeof(tCsrScanResult) + uLen);
8117 if ( NULL == pScanResult )
Srikant Kuppa066904f2013-05-07 13:56:02 -07008118 {
8119 smsLog(pMac, LOGE, FL(" fail to allocate memory for frame"));
8120 vos_mem_free(pParsedFrame);
8121 return eHAL_STATUS_RESOURCES;
8122 }
8123
Kiet Lam64c1b492013-07-12 13:56:44 +05308124 vos_mem_set(pScanResult, sizeof(tCsrScanResult) + uLen, 0);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008125 pBssDescr = &pScanResult->Result.BssDescriptor;
8126 /**
8127 * Length of BSS desription is without length of
8128 * length itself and length of pointer
8129 * that holds the next BSS description
8130 */
8131 pBssDescr->length = (tANI_U16)(
8132 sizeof(tSirBssDescription) - sizeof(tANI_U16) -
8133 sizeof(tANI_U32) + uLen);
8134 if (pParsedFrame->dsParamsPresent)
8135 {
8136 pBssDescr->channelId = pParsedFrame->channelNumber;
8137 }
8138 else if (pParsedFrame->HTInfo.present)
8139 {
8140 pBssDescr->channelId = pParsedFrame->HTInfo.primaryChannel;
8141 }
8142 else
8143 {
8144 pBssDescr->channelId = pParsedFrame->channelNumber;
8145 }
8146
8147 if ((pBssDescr->channelId > 0) && (pBssDescr->channelId < 15))
8148 {
8149 int i;
8150 // 11b or 11g packet
8151 // 11g iff extended Rate IE is present or
8152 // if there is an A rate in suppRate IE
8153 for (i = 0; i < pParsedFrame->supportedRates.numRates; i++)
8154 {
8155 if (sirIsArate(pParsedFrame->supportedRates.rate[i] & 0x7f))
8156 {
8157 pBssDescr->nwType = eSIR_11G_NW_TYPE;
8158 break;
8159 }
8160 }
8161 if (pParsedFrame->extendedRatesPresent)
8162 {
8163 pBssDescr->nwType = eSIR_11G_NW_TYPE;
8164 }
8165 }
8166 else
8167 {
8168 // 11a packet
8169 pBssDescr->nwType = eSIR_11A_NW_TYPE;
8170 }
8171
8172 pBssDescr->sinr = 0;
8173 pBssDescr->rssi = -1 * pPrefNetworkFoundInd->rssi;
8174 pBssDescr->beaconInterval = pParsedFrame->beaconInterval;
8175 pBssDescr->timeStamp[0] = pParsedFrame->timeStamp[0];
8176 pBssDescr->timeStamp[1] = pParsedFrame->timeStamp[1];
8177 pBssDescr->capabilityInfo = *((tANI_U16 *)&pParsedFrame->capabilityInfo);
Kiet Lam64c1b492013-07-12 13:56:44 +05308178 vos_mem_copy((tANI_U8 *) &pBssDescr->bssId, (tANI_U8 *) macHeader->bssId, sizeof(tSirMacAddr));
Srikant Kuppa066904f2013-05-07 13:56:02 -07008179 pBssDescr->nReceivedTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
8180
Arif Hussain24bafea2013-11-15 15:10:03 -08008181 smsLog( pMac, LOG2, "(%s):Bssid= "MAC_ADDRESS_STR
8182 " chan= %d, rssi = %d", __func__,
8183 MAC_ADDR_ARRAY(pBssDescr->bssId),
Srikant Kuppa066904f2013-05-07 13:56:02 -07008184 pBssDescr->channelId,
8185 pBssDescr->rssi );
8186
8187 //IEs
8188 if (uLen)
8189 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308190 vos_mem_copy(&pBssDescr->ieFields,
8191 pPrefNetworkFoundInd->data + (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET),
8192 uLen);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008193 }
8194
8195 pIesLocal = (tDot11fBeaconIEs *)( pScanResult->Result.pvIes );
8196 if ( !pIesLocal &&
8197 (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
8198 &pScanResult->Result.BssDescriptor, &pIesLocal))) )
8199 {
8200 smsLog(pMac, LOGE, FL(" Cannot parse IEs"));
8201 csrFreeScanResultEntry(pMac, pScanResult);
8202 vos_mem_free(pParsedFrame);
8203 return eHAL_STATUS_RESOURCES;
8204 }
8205
8206 fDupBss = csrRemoveDupBssDescription( pMac,
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05308207 &pScanResult->Result.BssDescriptor, pIesLocal, &tmpSsid, &timer, FALSE);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008208 //Check whether we have reach out limit
8209 if ( CSR_SCAN_IS_OVER_BSS_LIMIT(pMac) )
8210 {
8211 //Limit reach
8212 smsLog(pMac, LOGE, FL(" BSS limit reached"));
8213 //Free the resources
8214 if( (pScanResult->Result.pvIes == NULL) && pIesLocal )
8215 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308216 vos_mem_free(pIesLocal);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008217 }
8218 csrFreeScanResultEntry(pMac, pScanResult);
8219 vos_mem_free(pParsedFrame);
8220 return eHAL_STATUS_RESOURCES;
8221 }
8222 //Add to scan cache
8223 csrScanAddResult(pMac, pScanResult, pIesLocal);
8224
Kiet Lamb537cfb2013-11-07 12:56:49 +05308225 if( (pScanResult->Result.pvIes == NULL) && pIesLocal )
8226 {
8227 vos_mem_free(pIesLocal);
8228 }
8229
Srikant Kuppa066904f2013-05-07 13:56:02 -07008230 vos_mem_free(pParsedFrame);
8231
8232 return eHAL_STATUS_SUCCESS;
8233}
Manjunathappa Prakash4f1d5a52013-11-11 16:22:19 -08008234#endif //FEATURE_WLAN_SCAN_PNO
Srikant Kuppa066904f2013-05-07 13:56:02 -07008235
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008236#ifdef FEATURE_WLAN_LFR
8237void csrInitOccupiedChannelsList(tpAniSirGlobal pMac)
8238{
8239 tListElem *pEntry = NULL;
8240 tCsrScanResult *pBssDesc = NULL;
8241 tDot11fBeaconIEs *pIes = NULL;
Srinivas28b5b4e2012-12-12 13:07:53 -08008242 tpCsrNeighborRoamControlInfo pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
8243
8244 if (0 != pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels)
8245 {
8246 smsLog(pMac, LOG1, FL("%s: Ini file contains neighbor scan channel list,"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008247 " hence NO need to build occupied channel list (numChannels = %d)"),
Srinivas28b5b4e2012-12-12 13:07:53 -08008248 __func__, pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels);
8249 return;
8250 }
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008251
8252 if (!csrNeighborRoamIsNewConnectedProfile(pMac))
8253 {
8254 smsLog(pMac, LOG2, FL("%s: donot flush occupied list since current roam profile"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008255 " matches previous (numChannels = %d)"),
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008256 __func__, pMac->scan.occupiedChannels.numChannels);
8257 return;
8258 }
8259
8260 /* Empty occupied channels here */
8261 pMac->scan.occupiedChannels.numChannels = 0;
8262
8263 csrLLLock(&pMac->scan.scanResultList);
8264 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
8265 while( pEntry )
8266 {
8267 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
8268 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
8269
8270 //At this time, pBssDescription->Result.pvIes may be NULL
Srikant Kuppa866893f2012-12-27 17:28:14 -08008271 if( !pIes && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008272 &pBssDesc->Result.BssDescriptor, &pIes))) )
8273 {
8274 continue;
8275 }
8276
8277 csrScanAddToOccupiedChannels(pMac, pBssDesc, &pMac->scan.occupiedChannels, pIes);
8278
8279 /*
8280 * Free the memory allocated for pIes in csrGetParsedBssDescriptionIEs
8281 */
8282 if( (pBssDesc->Result.pvIes == NULL) && pIes )
8283 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308284 vos_mem_free(pIes);
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008285 }
8286
8287 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK );
8288 }//while
8289 csrLLUnlock(&pMac->scan.scanResultList);
Srikant Kuppa866893f2012-12-27 17:28:14 -08008290
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008291}
8292#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07008293
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008294eHalStatus csrScanCreateEntryInScanCache(tpAniSirGlobal pMac, tANI_U32 sessionId,
8295 tCsrBssid bssid, tANI_U8 channel)
8296{
8297 eHalStatus status = eHAL_STATUS_SUCCESS;
8298 tDot11fBeaconIEs *pNewIes = NULL;
8299 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
Praveen Kumar Sirisilla8bdfac42013-10-10 17:20:48 -07008300 tSirBssDescription *pNewBssDescriptor = NULL;
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008301 tANI_U32 size = 0;
8302
8303 if(NULL == pSession)
8304 {
8305 status = eHAL_STATUS_FAILURE;
8306 return status;
8307 }
8308 smsLog(pMac, LOG2, FL("csrScanCreateEntryInScanCache: Current bssid::"
Arif Hussain24bafea2013-11-15 15:10:03 -08008309 MAC_ADDRESS_STR),
8310 MAC_ADDR_ARRAY(pSession->pConnectBssDesc->bssId));
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008311 smsLog(pMac, LOG2, FL("csrScanCreateEntryInScanCache: My bssid::"
Arif Hussain24bafea2013-11-15 15:10:03 -08008312 MAC_ADDRESS_STR" channel %d"),
8313 MAC_ADDR_ARRAY(bssid), channel);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008314
8315 do
8316 {
8317 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
8318 pSession->pConnectBssDesc, &pNewIes)))
8319 {
8320 smsLog(pMac, LOGE, FL("%s: Failed to parse IEs"),
8321 __func__);
8322 status = eHAL_STATUS_FAILURE;
8323 break;
8324 }
8325
8326 size = pSession->pConnectBssDesc->length + sizeof(pSession->pConnectBssDesc->length);
Kiet Lam64c1b492013-07-12 13:56:44 +05308327 if (size)
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008328 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308329 pNewBssDescriptor = vos_mem_malloc(size);
8330 if ( NULL == pNewBssDescriptor )
8331 status = eHAL_STATUS_FAILURE;
8332 else
8333 status = eHAL_STATUS_SUCCESS;
8334 if (HAL_STATUS_SUCCESS(status))
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008335 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308336 vos_mem_copy(pNewBssDescriptor, pSession->pConnectBssDesc, size);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008337 }
8338 else
8339 {
8340 smsLog(pMac, LOGE, FL("%s: memory allocation failed"),
8341 __func__);
8342 status = eHAL_STATUS_FAILURE;
8343 break;
8344 }
8345
8346 //change the BSSID & channel as passed
Kiet Lam64c1b492013-07-12 13:56:44 +05308347 vos_mem_copy(pNewBssDescriptor->bssId, bssid, sizeof(tSirMacAddr));
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008348 pNewBssDescriptor->channelId = channel;
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07008349 if(NULL == csrScanAppendBssDescription( pMac, pNewBssDescriptor, pNewIes, TRUE ))
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008350 {
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07008351 smsLog(pMac, LOGE, FL("%s: csrScanAppendBssDescription failed"),
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008352 __func__);
8353 status = eHAL_STATUS_FAILURE;
8354 break;
8355 }
8356 }
8357 else
8358 {
8359 smsLog(pMac, LOGE, FL("%s: length of bss descriptor is 0"),
8360 __func__);
8361 status = eHAL_STATUS_FAILURE;
8362 break;
8363 }
8364 smsLog(pMac, LOGE, FL("%s: entry successfully added in scan cache"),
8365 __func__);
8366 }while(0);
8367
8368 if(pNewIes)
8369 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308370 vos_mem_free(pNewIes);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008371 }
8372 if(pNewBssDescriptor)
8373 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308374 vos_mem_free(pNewBssDescriptor);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008375 }
8376 return status;
8377}
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07008378
8379#ifdef FEATURE_WLAN_CCX
8380// Update the TSF with the difference in system time
8381void UpdateCCKMTSF(tANI_U32 *timeStamp0, tANI_U32 *timeStamp1, tANI_U32 *incr)
8382{
8383 tANI_U64 timeStamp64 = ((tANI_U64)*timeStamp1 << 32) | (*timeStamp0);
8384
8385 timeStamp64 = (tANI_U64)(timeStamp64 + (tANI_U64)*incr);
8386 *timeStamp0 = (tANI_U32)(timeStamp64 & 0xffffffff);
8387 *timeStamp1 = (tANI_U32)((timeStamp64 >> 32) & 0xffffffff);
8388}
8389#endif