blob: 5602567c13a494a8fc41b20a07c44c189d034502 [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 }
Srinivas, Dasari187ca4e2014-02-07 12:40:09 +05304542 if (pCommand->u.scanCmd.abortScanDueToBandChange)
4543 {
4544 /*
4545 * Scan aborted due to band change
4546 * The scan results need to be flushed
4547 */
4548 if (pCommand->u.scanCmd.callback
4549 != pMac->scan.callback11dScanDone)
4550 {
4551 smsLog(pMac, LOG1, FL("Filtering the scan results as the "
4552 "results may belong to wrong band"));
4553 csrScanFilterResults(pMac);
4554 }
4555 else
4556 {
4557 smsLog(pMac, LOG1, FL("11d_scan_done will flush the scan"
4558 " results"));
4559 }
4560 pCommand->u.scanCmd.abortScanDueToBandChange
4561 = eANI_BOOLEAN_FALSE;
4562 }
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004563 csrSaveScanResults(pMac, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07004564
4565#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4566 {
4567 vos_log_scan_pkt_type *pScanLog = NULL;
4568 tScanResultHandle hScanResult;
4569 tCsrScanResultInfo *pScanResult;
4570 tDot11fBeaconIEs *pIes;
4571 int n = 0, c = 0;
4572
4573 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
4574 if(pScanLog)
4575 {
4576 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
4577 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
4578 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
4579 {
4580 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_RSP;
4581 }
4582 else
4583 {
4584 if( eSIR_PASSIVE_SCAN != pMac->scan.curScanType )
4585 {
4586 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_RSP;
4587 }
4588 else
4589 {
4590 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_RSP;
4591 }
4592 }
4593 if(eSIR_SME_SUCCESS == pScanRsp->statusCode)
4594 {
4595 if(HAL_STATUS_SUCCESS(csrScanGetResult(pMac, NULL, &hScanResult)))
4596 {
4597 while(((pScanResult = csrScanResultGetNext(pMac, hScanResult)) != NULL))
4598 {
4599 if( n < VOS_LOG_MAX_NUM_BSSID )
4600 {
4601 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pScanResult->BssDescriptor, &pIes)))
4602 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004603 smsLog(pMac, LOGE, FL(" fail to parse IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07004604 break;
4605 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304606 vos_mem_copy(pScanLog->bssid[n],
4607 pScanResult->BssDescriptor.bssId, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07004608 if(pIes && pIes->SSID.present && VOS_LOG_MAX_SSID_SIZE >= pIes->SSID.num_ssid)
4609 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304610 vos_mem_copy(pScanLog->ssid[n],
4611 pIes->SSID.ssid, pIes->SSID.num_ssid);
Jeff Johnson295189b2012-06-20 16:38:30 -07004612 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304613 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07004614 n++;
4615 }
4616 c++;
4617 }
4618 pScanLog->numSsid = (v_U8_t)n;
4619 pScanLog->totalSsid = (v_U8_t)c;
4620 csrScanResultPurge(pMac, hScanResult);
4621 }
4622 }
4623 else
4624 {
4625 pScanLog->status = WLAN_SCAN_STATUS_FAILURE;
4626 }
4627 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
4628 }
4629 }
4630#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4631
4632 NextCommand = csrScanGetNextCommandState(pMac, pCommand, fSuccess);
4633 //We reuse the command here instead reissue a new command
4634 switch(NextCommand)
4635 {
4636 case eCsrNext11dScan1Success:
4637 case eCsrNext11dScan2Success:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004638 smsLog( pMac, LOG2, FL("11dScan1/3 produced results. Reissue Active scan..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004639 // if we found country information, no need to continue scanning further, bail out
4640 fRemoveCommand = eANI_BOOLEAN_TRUE;
4641 NextCommand = eCsrNext11dScanComplete;
4642 break;
4643 case eCsrNext11dScan1Failure:
4644 //We are not done yet. 11d scan fail once. We will try to reset anything and do it over again
4645 //The only meaningful thing for this retry is that we cannot find 11d information after a reset so
4646 //we clear the "old" 11d info and give it once more chance
4647 fRemoveCommand = csrHandleScan11d1Failure(pMac, pCommand);
4648 if(fRemoveCommand)
4649 {
4650 NextCommand = eCsrNext11dScanComplete;
4651 }
4652 break;
4653 case eCsrNextLostLinkScan1Success:
4654 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink1)))
4655 {
4656 csrScanHandleFailedLostlink1(pMac, sessionId);
4657 }
4658 break;
4659 case eCsrNextLostLinkScan2Success:
4660 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink2)))
4661 {
4662 csrScanHandleFailedLostlink2(pMac, sessionId);
4663 }
4664 break;
4665 case eCsrNextLostLinkScan3Success:
4666 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink3)))
4667 {
4668 csrScanHandleFailedLostlink3(pMac, sessionId);
4669 }
4670 break;
4671 case eCsrNextLostLinkScan1Failed:
4672 csrScanHandleFailedLostlink1(pMac, sessionId);
4673 break;
4674 case eCsrNextLostLinkScan2Failed:
4675 csrScanHandleFailedLostlink2(pMac, sessionId);
4676 break;
4677 case eCsrNextLostLinkScan3Failed:
4678 csrScanHandleFailedLostlink3(pMac, sessionId);
4679 break;
4680 case eCsrNexteScanForSsidSuccess:
4681 csrScanHandleSearchForSSID(pMac, pCommand);
4682 break;
4683 case eCsrNexteScanForSsidFailure:
4684 csrScanHandleSearchForSSIDFailure(pMac, pCommand);
4685 break;
4686 case eCsrNextIdleScanComplete:
4687 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
4688 break;
4689 case eCsrNextCapChangeScanComplete:
4690 csrScanHandleCapChangeScanComplete(pMac, sessionId);
4691 break;
4692 default:
4693
4694 break;
4695 }
4696 }
4697 else
4698 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004699 smsLog( pMac, LOGW, FL("Scan Completion called but SCAN command is not ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004700 fRemoveCommand = eANI_BOOLEAN_FALSE;
4701 }
4702 }
4703 else
4704 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004705 smsLog( pMac, LOGW, FL("Scan Completion called but NO commands are ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004706 fRemoveCommand = eANI_BOOLEAN_FALSE;
4707 }
4708
4709 return( fRemoveCommand );
4710}
4711
4712
4713
4714static void csrScanRemoveDupBssDescriptionFromInterimList( tpAniSirGlobal pMac,
4715 tSirBssDescription *pSirBssDescr,
4716 tDot11fBeaconIEs *pIes)
4717{
4718 tListElem *pEntry;
4719 tCsrScanResult *pCsrBssDescription;
4720
4721 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
4722 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
4723 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
4724 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
4725 while( pEntry )
4726 {
4727 pCsrBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
4728
4729 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
4730 // matches
4731
4732 if ( csrIsDuplicateBssDescription( pMac, &pCsrBssDescription->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07004733 pSirBssDescr, pIes, FALSE ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07004734 {
4735 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
4736 ((tANI_S32)pCsrBssDescription->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
4737
4738 // Remove the 'old' entry from the list....
4739 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK ) )
4740 {
4741 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pCsrBssDescription->Result.BssDescriptor);
4742 // we need to free the memory associated with this node
4743 csrFreeScanResultEntry( pMac, pCsrBssDescription );
4744 }
4745
4746 // If we found a match, we can stop looking through the list.
4747 break;
4748 }
4749
4750 pEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK );
4751 }
4752}
4753
4754
4755
4756//Caller allocated memory pfNewBssForConn to return whether new candidate for
4757//current connection is found. Cannot be NULL
4758tCsrScanResult *csrScanSaveBssDescriptionToInterimList( tpAniSirGlobal pMac,
4759 tSirBssDescription *pBSSDescription,
4760 tDot11fBeaconIEs *pIes)
4761{
4762 tCsrScanResult *pCsrBssDescription = NULL;
4763 tANI_U32 cbBSSDesc;
4764 tANI_U32 cbAllocated;
Jeff Johnson295189b2012-06-20 16:38:30 -07004765
4766 // figure out how big the BSS description is (the BSSDesc->length does NOT
4767 // include the size of the length field itself).
4768 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
4769
4770 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
4771
Kiet Lam64c1b492013-07-12 13:56:44 +05304772 pCsrBssDescription = vos_mem_malloc(cbAllocated);
4773 if ( NULL != pCsrBssDescription )
Jeff Johnson295189b2012-06-20 16:38:30 -07004774 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304775 vos_mem_set(pCsrBssDescription, cbAllocated, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004776 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Kiet Lam64c1b492013-07-12 13:56:44 +05304777 vos_mem_copy(&pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc );
Jeff Johnson295189b2012-06-20 16:38:30 -07004778 //Save SSID separately for later use
4779 if( pIes->SSID.present && !csrIsNULLSSID(pIes->SSID.ssid, pIes->SSID.num_ssid) )
4780 {
4781 //SSID not hidden
Madan Mohan Koyyalamudi4e31b132012-11-02 13:13:52 -07004782 tANI_U32 len = pIes->SSID.num_ssid;
Jeff Johnson295189b2012-06-20 16:38:30 -07004783 if (len > SIR_MAC_MAX_SSID_LENGTH)
4784 {
4785 // truncate to fit in our struct
4786 len = SIR_MAC_MAX_SSID_LENGTH;
4787 }
4788 pCsrBssDescription->Result.ssId.length = len;
4789 pCsrBssDescription->Result.timer = vos_timer_get_system_time();
Kiet Lam64c1b492013-07-12 13:56:44 +05304790 vos_mem_copy(pCsrBssDescription->Result.ssId.ssId, pIes->SSID.ssid, len);
Jeff Johnson295189b2012-06-20 16:38:30 -07004791 }
4792 csrLLInsertTail( &pMac->scan.tempScanResults, &pCsrBssDescription->Link, LL_ACCESS_LOCK );
4793 }
4794
4795 return( pCsrBssDescription );
4796}
4797
4798
4799
4800
4801tANI_BOOLEAN csrIsDuplicateBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc1,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07004802 tSirBssDescription *pSirBssDesc2, tDot11fBeaconIEs *pIes2, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07004803{
4804 tANI_BOOLEAN fMatch = FALSE;
4805 tSirMacCapabilityInfo *pCap1, *pCap2;
4806 tDot11fBeaconIEs *pIes1 = NULL;
Jeff Johnsone7245742012-09-05 17:12:55 -07004807 tDot11fBeaconIEs *pIesTemp = pIes2;
Jeff Johnson295189b2012-06-20 16:38:30 -07004808
4809 pCap1 = (tSirMacCapabilityInfo *)&pSirBssDesc1->capabilityInfo;
4810 pCap2 = (tSirMacCapabilityInfo *)&pSirBssDesc2->capabilityInfo;
4811 if(pCap1->ess == pCap2->ess)
4812 {
4813 if (pCap1->ess &&
Jeff Johnsone7245742012-09-05 17:12:55 -07004814 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId)&&
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07004815 (fForced || (pSirBssDesc1->channelId == pSirBssDesc2->channelId)))
Jeff Johnson295189b2012-06-20 16:38:30 -07004816 {
4817 fMatch = TRUE;
Jeff Johnsone7245742012-09-05 17:12:55 -07004818 // Check for SSID match, if exists
4819 do
4820 {
4821 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
4822 {
4823 break;
4824 }
4825 if( NULL == pIesTemp )
4826 {
4827 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
4828 {
4829 break;
4830 }
4831 }
4832 if(pIes1->SSID.present && pIesTemp->SSID.present)
4833 {
4834 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
4835 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
4836 }
4837 }while(0);
4838
Jeff Johnson295189b2012-06-20 16:38:30 -07004839 }
4840 else if (pCap1->ibss && (pSirBssDesc1->channelId == pSirBssDesc2->channelId))
4841 {
Jeff Johnson295189b2012-06-20 16:38:30 -07004842
4843 do
4844 {
4845 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
4846 {
4847 break;
4848 }
4849 if( NULL == pIesTemp )
4850 {
4851 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
4852 {
4853 break;
4854 }
4855 }
4856 //Same channel cannot have same SSID for different IBSS
4857 if(pIes1->SSID.present && pIesTemp->SSID.present)
4858 {
4859 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
4860 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
4861 }
4862 }while(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004863 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004864 /* In case of P2P devices, ess and ibss will be set to zero */
4865 else if (!pCap1->ess &&
4866 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId))
4867 {
4868 fMatch = TRUE;
4869 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004870 }
4871
4872 if(pIes1)
4873 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304874 vos_mem_free(pIes1);
Jeff Johnson295189b2012-06-20 16:38:30 -07004875 }
Jeff Johnsone7245742012-09-05 17:12:55 -07004876
4877 if( (NULL == pIes2) && pIesTemp )
4878 {
4879 //locally allocated
Kiet Lam64c1b492013-07-12 13:56:44 +05304880 vos_mem_free(pIesTemp);
Jeff Johnsone7245742012-09-05 17:12:55 -07004881 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004882
4883 return( fMatch );
4884}
4885
4886
4887tANI_BOOLEAN csrIsNetworkTypeEqual( tSirBssDescription *pSirBssDesc1, tSirBssDescription *pSirBssDesc2 )
4888{
4889 return( pSirBssDesc1->nwType == pSirBssDesc2->nwType );
4890}
4891
4892
4893//to check whether the BSS matches the dot11Mode
4894static tANI_BOOLEAN csrScanIsBssAllowed(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
4895 tDot11fBeaconIEs *pIes)
4896{
4897 tANI_BOOLEAN fAllowed = eANI_BOOLEAN_FALSE;
4898 eCsrPhyMode phyMode;
4899
4900 if(HAL_STATUS_SUCCESS(csrGetPhyModeFromBss(pMac, pBssDesc, &phyMode, pIes)))
4901 {
4902 switch(pMac->roam.configParam.phyMode)
4903 {
4904 case eCSR_DOT11_MODE_11b:
4905 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
4906 break;
4907 case eCSR_DOT11_MODE_11g:
4908 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
4909 break;
4910 case eCSR_DOT11_MODE_11g_ONLY:
4911 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11g == phyMode);
4912 break;
4913 case eCSR_DOT11_MODE_11a:
4914 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11b != phyMode) && (eCSR_DOT11_MODE_11g != phyMode));
4915 break;
4916 case eCSR_DOT11_MODE_11n_ONLY:
4917 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11n == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
4918 break;
Jeff Johnsone7245742012-09-05 17:12:55 -07004919
4920#ifdef WLAN_FEATURE_11AC
4921 case eCSR_DOT11_MODE_11ac_ONLY:
4922 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11ac == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
4923 break;
4924#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004925 case eCSR_DOT11_MODE_11b_ONLY:
4926 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11b == phyMode);
4927 break;
4928 case eCSR_DOT11_MODE_11a_ONLY:
4929 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a == phyMode);
4930 break;
4931 case eCSR_DOT11_MODE_11n:
Jeff Johnsone7245742012-09-05 17:12:55 -07004932#ifdef WLAN_FEATURE_11AC
4933 case eCSR_DOT11_MODE_11ac:
4934#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004935 case eCSR_DOT11_MODE_TAURUS:
4936 default:
4937 fAllowed = eANI_BOOLEAN_TRUE;
4938 break;
4939 }
4940 }
4941
4942 return (fAllowed);
4943}
4944
4945
4946
4947//Return pIes to caller for future use when returning TRUE.
4948static tANI_BOOLEAN csrScanValidateScanResult( tpAniSirGlobal pMac, tANI_U8 *pChannels,
4949 tANI_U8 numChn, tSirBssDescription *pBssDesc,
4950 tDot11fBeaconIEs **ppIes )
4951{
4952 tANI_BOOLEAN fValidChannel = FALSE;
4953 tDot11fBeaconIEs *pIes = NULL;
4954 tANI_U8 index;
4955
4956 for( index = 0; index < numChn; index++ )
4957 {
4958 // This check relies on the fact that a single BSS description is returned in each
4959 // ScanRsp call, which is the way LIM implemented the scan req/rsp funtions. We changed
4960 // to this model when we ran with a large number of APs. If this were to change, then
4961 // this check would have to mess with removing the bssDescription from somewhere in an
4962 // arbitrary index in the bssDescription array.
4963 if ( pChannels[ index ] == pBssDesc->channelId )
4964 {
4965 fValidChannel = TRUE;
4966 break;
4967 }
4968 }
4969 *ppIes = NULL;
4970 if(fValidChannel)
4971 {
4972 if( HAL_STATUS_SUCCESS( csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIes) ) )
4973 {
4974 fValidChannel = csrScanIsBssAllowed(pMac, pBssDesc, pIes);
4975 if( fValidChannel )
4976 {
4977 *ppIes = pIes;
4978 }
4979 else
4980 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304981 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07004982 }
4983 }
4984 else
4985 {
4986 fValidChannel = FALSE;
4987 }
4988 }
4989
4990 return( fValidChannel );
4991}
4992
4993
4994//Return whether last scan result is received
4995static tANI_BOOLEAN csrScanProcessScanResults( tpAniSirGlobal pMac, tSmeCmd *pCommand,
4996 tSirSmeScanRsp *pScanRsp, tANI_BOOLEAN *pfRemoveCommand )
4997{
4998 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE, fRemoveCommand = eANI_BOOLEAN_FALSE;
4999 tDot11fBeaconIEs *pIes = NULL;
5000 tANI_U32 cbParsed;
5001 tSirBssDescription *pSirBssDescription;
5002 tANI_U32 cbBssDesc;
5003 tANI_U32 cbScanResult = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription )
5004 + sizeof(tSirBssDescription); //We need at least one CB
5005
5006 // don't consider the scan rsp to be valid if the status code is Scan Failure. Scan Failure
5007 // is returned when the scan could not find anything. so if we get scan failure return that
5008 // the scan response is invalid. Also check the lenght in the scan result for valid scan
5009 // BssDescriptions....
5010 do
5011 {
5012 if ( ( cbScanResult <= pScanRsp->length ) &&
5013 (( eSIR_SME_SUCCESS == pScanRsp->statusCode ) ||
5014 ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW == pScanRsp->statusCode ) ) )
5015 {
5016 tANI_U8 *pChannelList = NULL;
5017 tANI_U8 cChannels = 0;
5018
5019 //Different scan type can reach this point, we need to distinguish it
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005020#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5021 if( eCsrScanGetLfrResult == pCommand->u.scanCmd.reason )
5022 {
5023 pChannelList = NULL;
5024 cChannels = 0;
5025 }
5026 else
5027#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005028 if( eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason )
5029 {
5030 //eCsrScanSetBGScanParam uses different structure
5031 tCsrBGScanRequest *pBgScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
5032
5033 cChannels = pBgScanReq->ChannelInfo.numOfChannels;
5034 pChannelList = pBgScanReq->ChannelInfo.ChannelList;
5035 }
5036 else
5037 {
5038 //the rest use generic scan request
5039 cChannels = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
5040 pChannelList = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
5041 }
5042
5043 // if the scan result is not on one of the channels in the Valid channel list, then it
5044 // must have come from an AP on an overlapping channel (in the 2.4GHz band). In this case,
5045 // let's drop the scan result.
5046 //
5047 // The other situation is where the scan request is for a scan on a particular channel set
5048 // and the scan result is from a
5049
5050 // if the NumChannels is 0, then we are supposed to be scanning all channels. Use the full channel
5051 // list as the 'valid' channel list. Otherwise, use the specific channel list in the scan parms
5052 // as the valid channels.
5053 if ( 0 == cChannels )
5054 {
5055 tANI_U32 len = sizeof(pMac->roam.validChannelList);
5056
5057 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
5058 {
5059 pChannelList = pMac->roam.validChannelList;
5060 cChannels = (tANI_U8)len;
5061 }
5062 else
5063 {
5064 //Cannot continue
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005065 smsLog( pMac, LOGE, "CSR: Processing internal SCAN results...csrGetCfgValidChannels failed" );
Jeff Johnson295189b2012-06-20 16:38:30 -07005066 break;
5067 }
5068 }
5069
5070 smsLog( pMac, LOG2, "CSR: Processing internal SCAN results..." );
5071 cbParsed = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription );
5072 pSirBssDescription = pScanRsp->bssDescription;
5073 while( cbParsed < pScanRsp->length )
5074 {
5075 if ( csrScanValidateScanResult( pMac, pChannelList, cChannels, pSirBssDescription, &pIes ) )
5076 {
5077 csrScanRemoveDupBssDescriptionFromInterimList(pMac, pSirBssDescription, pIes);
5078 csrScanSaveBssDescriptionToInterimList( pMac, pSirBssDescription, pIes );
5079 if( eSIR_PASSIVE_SCAN == pMac->scan.curScanType )
5080 {
5081 if( csrIs11dSupported( pMac) )
5082 {
5083 //Check whether the BSS is acceptable base on 11d info and our configs.
5084 if( csrMatchCountryCode( pMac, NULL, pIes ) )
5085 {
5086 //Double check whether the channel is acceptable by us.
5087 if( csrIsSupportedChannel( pMac, pSirBssDescription->channelId ) )
5088 {
5089 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
5090 }
5091 }
5092 }
5093 else
5094 {
5095 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
5096 }
5097 }
5098 //Free the resource
Kiet Lam64c1b492013-07-12 13:56:44 +05305099 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07005100 }
5101 // skip over the BSS description to the next one...
5102 cbBssDesc = pSirBssDescription->length + sizeof( pSirBssDescription->length );
5103
5104 cbParsed += cbBssDesc;
5105 pSirBssDescription = (tSirBssDescription *)((tANI_U8 *)pSirBssDescription + cbBssDesc );
5106
5107 } //while
5108 }
5109 else
5110 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005111 smsLog( pMac, LOGW, " Scanrsp fail (0x%08X), length = %d (expected %d)",
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08005112 pScanRsp->statusCode, pScanRsp->length, cbScanResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07005113 //HO bg scan/probe failed no need to try autonomously
5114 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
5115 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005116#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5117 eCsrScanGetLfrResult == pCommand->u.scanCmd.reason ||
5118#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005119 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
5120 {
5121 fRemoveCommand = eANI_BOOLEAN_TRUE;
5122 }
5123 }
5124 }while(0);
5125 if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
5126 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005127 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 -07005128 fRemoveCommand = csrScanComplete( pMac, pScanRsp );
5129 fRet = eANI_BOOLEAN_TRUE;
5130 }//if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
5131 if(pfRemoveCommand)
5132 {
5133 *pfRemoveCommand = fRemoveCommand;
5134 }
5135
5136#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305137 if (pMac->fScanOffload)
5138 return fRet;
5139
Jeff Johnson295189b2012-06-20 16:38:30 -07005140 if (!csrLLIsListEmpty( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK ))
5141 {
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005142 /* Pending scan commands in the list because the previous scan command
5143 * was split into a scan command on one channel + a scan command for all
5144 * remaining channels.
5145 *
5146 * Start timer to trigger processing of the next scan command.
Srikant Kuppa866893f2012-12-27 17:28:14 -08005147 * NOTE for LFR:
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305148 * Do not split scans if no concurrent infra connections are
Srikant Kuppa866893f2012-12-27 17:28:14 -08005149 * active and if the scan is a BG scan triggered by LFR (OR)
5150 * any scan if LFR is in the middle of a BG scan. Splitting
5151 * the scan is delaying the time it takes for LFR to find
5152 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005153 */
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305154 if ( (csrIsStaSessionConnected(pMac) &&
Srikant Kuppa866893f2012-12-27 17:28:14 -08005155#ifdef FEATURE_WLAN_LFR
5156 (csrIsConcurrentInfraConnected(pMac) ||
5157 ((pCommand->u.scanCmd.reason != eCsrScanBgScan) &&
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305158 (pMac->roam.neighborRoamInfo.neighborRoamState !=
Srikant Kuppa866893f2012-12-27 17:28:14 -08005159 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
5160#endif
5161 (pCommand->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305162 (csrIsP2pSessionConnected(pMac)) )
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005163 {
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005164 /* if active connected sessions present then continue to split scan
5165 * with specified interval between consecutive scans */
5166 csrSetDefaultScanTiming(pMac, pCommand->u.scanCmd.u.scanRequest.scanType, &(pCommand->u.scanCmd.u.scanRequest));
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05305167 vos_timer_start(&pMac->scan.hTimerStaApConcTimer,
5168 pCommand->u.scanCmd.u.scanRequest.restTime);
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005169 } else {
5170 /* if no connected sessions present then initiate next scan command immediately */
5171 /* minimum timer granularity is 10ms */
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05305172 vos_timer_start(&pMac->scan.hTimerStaApConcTimer, 10);
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005173 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005174 }
5175#endif
5176 return (fRet);
5177}
5178
5179
5180tANI_BOOLEAN csrScanIsWildCardScan( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5181{
5182 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
Kiet Lam64c1b492013-07-12 13:56:44 +05305183 tANI_BOOLEAN f = vos_mem_compare(pCommand->u.scanCmd.u.scanRequest.bssid,
5184 bssid, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07005185
5186 //It is not a wild card scan if the bssid is not broadcast and the number of SSID is 1.
5187 return ((tANI_BOOLEAN)( (f || (0xff == pCommand->u.scanCmd.u.scanRequest.bssid[0])) &&
5188 (pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs != 1) ));
5189}
5190
5191
5192eHalStatus csrScanSmeScanResponse( tpAniSirGlobal pMac, void *pMsgBuf )
5193{
5194 eHalStatus status = eHAL_STATUS_SUCCESS;
5195 tListElem *pEntry;
5196 tSmeCmd *pCommand;
5197 eCsrScanStatus scanStatus;
5198 tSirSmeScanRsp *pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
5199 tSmeGetScanChnRsp *pScanChnInfo;
5200 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
5201 eCsrScanReason reason = eCsrScanOther;
5202
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305203 if (pMac->fScanOffload)
5204 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList,
5205 LL_ACCESS_LOCK);
5206 else
5207 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07005208
5209 if ( pEntry )
5210 {
5211 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
5212 if ( eSmeCommandScan == pCommand->command )
5213 {
5214 scanStatus = (eSIR_SME_SUCCESS == pScanRsp->statusCode) ? eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
5215 reason = pCommand->u.scanCmd.reason;
5216 switch(pCommand->u.scanCmd.reason)
5217 {
5218 case eCsrScanAbortBgScan:
5219 case eCsrScanAbortNormalScan:
5220 case eCsrScanBGScanAbort:
5221 case eCsrScanBGScanEnable:
5222 break;
5223 case eCsrScanGetScanChnInfo:
5224 pScanChnInfo = (tSmeGetScanChnRsp *)pMsgBuf;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005225 /*
5226 * status code not available in tSmeGetScanChnRsp, so
5227 * by default considereing it to be success
5228 */
5229 scanStatus = eSIR_SME_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07005230 csrScanAgeResults(pMac, pScanChnInfo);
5231 break;
5232 case eCsrScanForCapsChange:
5233 csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand );
5234 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005235 case eCsrScanP2PFindPeer:
5236 scanStatus = ((eSIR_SME_SUCCESS == pScanRsp->statusCode) && (pScanRsp->length > 50)) ? eCSR_SCAN_FOUND_PEER : eCSR_SCAN_FAILURE;
5237 csrScanProcessScanResults( pMac, pCommand, pScanRsp, NULL );
5238 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005239 case eCsrScanSetBGScanParam:
5240 default:
5241 if(csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand ))
5242 {
5243 //Not to get channel info if the scan is not a wildcard scan because
5244 //it may cause scan results got aged out incorrectly.
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005245 if( csrScanIsWildCardScan( pMac, pCommand ) && (!pCommand->u.scanCmd.u.scanRequest.p2pSearch)
5246#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5247 && (pCommand->u.scanCmd.reason != eCsrScanGetLfrResult)
5248#endif
5249 )
Jeff Johnson295189b2012-06-20 16:38:30 -07005250 {
5251 //Get the list of channels scanned
Jeff Johnson32d95a32012-09-10 13:15:23 -07005252 if( pCommand->u.scanCmd.reason != eCsrScanUserRequest)
5253 {
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05305254 csrScanGetScanChnInfo(pMac, pCommand->sessionId,
5255 NULL, NULL);
Jeff Johnson32d95a32012-09-10 13:15:23 -07005256 }
5257 else
5258 {
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05305259 csrScanGetScanChnInfo(pMac,
5260 pCommand->sessionId,
5261 pCommand->u.scanCmd.pContext,
5262 pCommand->u.scanCmd.callback);
Jeff Johnson32d95a32012-09-10 13:15:23 -07005263 pCommand->u.scanCmd.callback = NULL;
5264 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005265 }
5266 }
5267 break;
5268 }//switch
5269 if(fRemoveCommand)
5270 {
5271
5272 csrReleaseScanCommand(pMac, pCommand, scanStatus);
5273
Srikant Kuppa866893f2012-12-27 17:28:14 -08005274 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005275 smeProcessPendingQueue( pMac );
5276 }
5277 else
5278 {
5279 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
5280 status = eHAL_STATUS_FAILURE;
5281 }
5282 }
5283 else
5284 {
5285 smsLog( pMac, LOGW, "CSR: Scan Completion called but NO commands are ACTIVE ..." );
5286 status = eHAL_STATUS_FAILURE;
5287 }
5288
5289 return (status);
5290}
5291
5292
5293
5294
5295tCsrScanResultInfo *csrScanResultGetFirst(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
5296{
5297 tListElem *pEntry;
5298 tCsrScanResult *pResult;
5299 tCsrScanResultInfo *pRet = NULL;
5300 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5301
5302 if(pResultList)
5303 {
5304 csrLLLock(&pResultList->List);
5305 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5306 if(pEntry)
5307 {
5308 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
5309 pRet = &pResult->Result;
5310 }
5311 pResultList->pCurEntry = pEntry;
5312 csrLLUnlock(&pResultList->List);
5313 }
5314
5315 return pRet;
5316}
5317
5318
5319tCsrScanResultInfo *csrScanResultGetNext(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
5320{
5321 tListElem *pEntry = NULL;
5322 tCsrScanResult *pResult = NULL;
5323 tCsrScanResultInfo *pRet = NULL;
5324 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5325
5326 if(pResultList)
5327 {
5328 csrLLLock(&pResultList->List);
5329 if(NULL == pResultList->pCurEntry)
5330 {
5331 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5332 }
5333 else
5334 {
5335 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
5336 }
5337 if(pEntry)
5338 {
5339 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
5340 pRet = &pResult->Result;
5341 }
5342 pResultList->pCurEntry = pEntry;
5343 csrLLUnlock(&pResultList->List);
5344 }
5345
5346 return pRet;
5347}
5348
5349
5350//This function moves the first BSS that matches the bssid to the head of the result
5351eHalStatus csrMoveBssToHeadFromBSSID(tpAniSirGlobal pMac, tCsrBssid *bssid, tScanResultHandle hScanResult)
5352{
5353 eHalStatus status = eHAL_STATUS_FAILURE;
5354 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5355 tCsrScanResult *pResult = NULL;
5356 tListElem *pEntry = NULL;
5357
5358 if(pResultList && bssid)
5359 {
5360 csrLLLock(&pResultList->List);
5361 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5362 while(pEntry)
5363 {
5364 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
Kiet Lam64c1b492013-07-12 13:56:44 +05305365 if (vos_mem_compare(bssid, pResult->Result.BssDescriptor.bssId, sizeof(tCsrBssid)))
Jeff Johnson295189b2012-06-20 16:38:30 -07005366 {
5367 status = eHAL_STATUS_SUCCESS;
5368 csrLLRemoveEntry(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
5369 csrLLInsertHead(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
5370 break;
5371 }
5372 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
5373 }
5374 csrLLUnlock(&pResultList->List);
5375 }
5376
5377 return (status);
5378}
5379
5380
5381//Remove the BSS if possible.
5382//Return -- TRUE == the BSS is remove. False == Fail to remove it
5383//This function is called when list lock is held. Be caution what functions it can call.
5384tANI_BOOLEAN csrScanAgeOutBss(tpAniSirGlobal pMac, tCsrScanResult *pResult)
5385{
5386 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
5387 tANI_U32 i;
5388 tCsrRoamSession *pSession;
5389
5390 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5391 {
5392 if( CSR_IS_SESSION_VALID( pMac, i ) )
5393 {
5394 pSession = CSR_GET_SESSION( pMac, i );
5395 //Not to remove the BSS we are connected to.
5396 if(csrIsConnStateDisconnected(pMac, i) || (NULL == pSession->pConnectBssDesc) ||
5397 (!csrIsDuplicateBssDescription(pMac, &pResult->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07005398 pSession->pConnectBssDesc, NULL, FALSE))
Jeff Johnson295189b2012-06-20 16:38:30 -07005399 )
5400 {
Arif Hussaina7c8e412013-11-20 11:06:42 -08005401 smsLog(pMac, LOGW, "Aging out BSS "MAC_ADDRESS_STR" Channel %d",
5402 MAC_ADDR_ARRAY(pResult->Result.BssDescriptor.bssId),
5403 pResult->Result.BssDescriptor.channelId);
Jeff Johnson295189b2012-06-20 16:38:30 -07005404 //No need to hold the spin lock because caller should hold the lock for pMac->scan.scanResultList
5405 if( csrLLRemoveEntry(&pMac->scan.scanResultList, &pResult->Link, LL_ACCESS_NOLOCK) )
5406 {
5407 csrFreeScanResultEntry(pMac, pResult);
Madan Mohan Koyyalamudi2e068bc2012-10-22 14:58:47 -07005408 fRet = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005409 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005410 break;
5411 }
5412 } //valid session
5413 } //for
Madan Mohan Koyyalamudi2e068bc2012-10-22 14:58:47 -07005414 if( CSR_ROAM_SESSION_MAX == i && fRet != eANI_BOOLEAN_TRUE )
Jeff Johnson295189b2012-06-20 16:38:30 -07005415 {
5416 //reset the counter so this won't hapeen too soon
5417 pResult->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
5418 pResult->Result.BssDescriptor.nReceivedTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
5419 }
5420
5421 return (fRet);
5422}
5423
5424
5425eHalStatus csrScanAgeResults(tpAniSirGlobal pMac, tSmeGetScanChnRsp *pScanChnInfo)
5426{
5427 eHalStatus status = eHAL_STATUS_SUCCESS;
5428 tListElem *pEntry, *tmpEntry;
5429 tCsrScanResult *pResult;
5430 tLimScanChn *pChnInfo;
5431 tANI_U8 i;
5432
5433 csrLLLock(&pMac->scan.scanResultList);
5434 for(i = 0; i < pScanChnInfo->numChn; i++)
5435 {
5436 pChnInfo = &pScanChnInfo->scanChn[i];
5437 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
5438 while( pEntry )
5439 {
5440 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
5441 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
5442 if(pResult->Result.BssDescriptor.channelId == pChnInfo->channelId)
5443 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005444 if(pResult->AgingCount <= 0)
5445 {
5446 smsLog(pMac, LOGW, " age out due to ref count");
5447 csrScanAgeOutBss(pMac, pResult);
5448 }
Madan Mohan Koyyalamudib9d3dcc2012-09-28 16:47:50 -07005449 else
5450 {
5451 pResult->AgingCount--;
5452 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005453 }
5454 pEntry = tmpEntry;
5455 }
5456 }
5457 csrLLUnlock(&pMac->scan.scanResultList);
5458
5459 return (status);
5460}
5461
5462
5463eHalStatus csrSendMBScanReq( tpAniSirGlobal pMac, tANI_U16 sessionId,
5464 tCsrScanRequest *pScanReq, tScanReqParam *pScanReqParam )
5465{
5466 eHalStatus status = eHAL_STATUS_SUCCESS;
5467 tSirSmeScanReq *pMsg;
5468 tANI_U16 msgLen;
5469 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
5470 tSirScanType scanType = pScanReq->scanType;
5471 tANI_U32 minChnTime; //in units of milliseconds
5472 tANI_U32 maxChnTime; //in units of milliseconds
5473 tANI_U32 i;
5474 tANI_U8 selfMacAddr[WNI_CFG_BSSID_LEN];
5475 tANI_U8 *pSelfMac = NULL;
5476
5477 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
5478 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) +
5479 ( pScanReq->uIEFieldLen ) ;
5480
Kiet Lam64c1b492013-07-12 13:56:44 +05305481 pMsg = vos_mem_malloc(msgLen);
5482 if ( NULL == pMsg )
5483 status = eHAL_STATUS_FAILURE;
5484 else
5485 status = eHAL_STATUS_SUCCESS;
5486 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07005487 {
5488 do
5489 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305490 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005491 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
5492 pMsg->length = pal_cpu_to_be16(msgLen);
5493 //ToDO: Fill in session info when we need to do scan base on session.
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05305494 if ((pMac->fScanOffload) && (sessionId != CSR_SESSION_ID_INVALID))
5495 {
5496 pMsg->sessionId = sessionId;
5497 }
5498 else
5499 {
5500 /* if sessionId == CSR_SESSION_ID_INVALID, then send the scan
5501 request on first available session */
5502 pMsg->sessionId = 0;
5503 }
5504
Jeff Johnson295189b2012-06-20 16:38:30 -07005505 pMsg->transactionId = 0;
5506 pMsg->dot11mode = (tANI_U8) csrTranslateToWNICfgDot11Mode(pMac, csrFindBestPhyMode( pMac, pMac->roam.configParam.phyMode ));
5507 pMsg->bssType = pal_cpu_to_be32(csrTranslateBsstypeToMacType(pScanReq->BSSType));
5508
5509 if ( CSR_IS_SESSION_VALID( pMac, sessionId ) )
5510 {
5511 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[sessionId].selfMacAddr;
5512 }
5513 else
5514 {
5515 // Since we don't have session for the scanning, we find a valid session. In case we fail to
5516 // do so, get the WNI_CFG_STA_ID
5517 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5518 {
5519 if( CSR_IS_SESSION_VALID( pMac, i ) )
5520 {
5521 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[i].selfMacAddr;
5522 break;
5523 }
5524 }
5525 if( CSR_ROAM_SESSION_MAX == i )
5526 {
5527 tANI_U32 len = WNI_CFG_BSSID_LEN;
5528 pSelfMac = selfMacAddr;
5529 status = ccmCfgGetStr( pMac, WNI_CFG_STA_ID, pSelfMac, &len );
5530 if( !HAL_STATUS_SUCCESS( status ) ||
5531 ( len < WNI_CFG_BSSID_LEN ) )
5532 {
5533 smsLog( pMac, LOGE, FL(" Can not get self MAC address from CFG status = %d"), status );
5534 //Force failed status
5535 status = eHAL_STATUS_FAILURE;
5536 break;
5537 }
5538 }
5539 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305540 vos_mem_copy((tANI_U8 *)pMsg->selfMacAddr, pSelfMac, sizeof(tSirMacAddr));
Jeff Johnson295189b2012-06-20 16:38:30 -07005541
5542 //sirCopyMacAddr
Kiet Lam64c1b492013-07-12 13:56:44 +05305543 vos_mem_copy((tANI_U8 *)pMsg->bssId, (tANI_U8 *)&pScanReq->bssid, sizeof(tSirMacAddr));
5544 if ( vos_mem_compare(pScanReq->bssid, bssid, sizeof(tCsrBssid)))
Jeff Johnson295189b2012-06-20 16:38:30 -07005545 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305546 vos_mem_set(pMsg->bssId, sizeof(tSirMacAddr), 0xff);
Jeff Johnson295189b2012-06-20 16:38:30 -07005547 }
5548 else
5549 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305550 vos_mem_copy(pMsg->bssId, pScanReq->bssid, WNI_CFG_BSSID_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07005551 }
5552 minChnTime = pScanReq->minChnTime;
5553 maxChnTime = pScanReq->maxChnTime;
5554
5555 //Verify the scan type first, if the scan is active scan, we need to make sure we
5556 //are allowed to do so.
5557 /* if 11d is enabled & we don't see any beacon around, scan type falls
5558 back to passive. But in BT AMP STA mode we need to send out a
5559 directed probe*/
5560 if( (eSIR_PASSIVE_SCAN != scanType) && (eCSR_SCAN_P2P_DISCOVERY != pScanReq->requestType)
5561 && (eCSR_BSS_TYPE_WDS_STA != pScanReq->BSSType)
5562 && (eANI_BOOLEAN_FALSE == pMac->scan.fEnableBypass11d))
5563 {
5564 scanType = pMac->scan.curScanType;
5565 if(eSIR_PASSIVE_SCAN == pMac->scan.curScanType)
5566 {
5567 if(minChnTime < pMac->roam.configParam.nPassiveMinChnTime)
5568 {
5569 minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
5570 }
5571 if(maxChnTime < pMac->roam.configParam.nPassiveMaxChnTime)
5572 {
5573 maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
5574 }
5575 }
5576 }
5577 pMsg->scanType = pal_cpu_to_be32(scanType);
5578
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05305579 pMsg->numSsid =
5580 (pScanReq->SSIDs.numOfSSIDs < SIR_SCAN_MAX_NUM_SSID) ?
5581 pScanReq->SSIDs.numOfSSIDs : SIR_SCAN_MAX_NUM_SSID;
Jeff Johnson295189b2012-06-20 16:38:30 -07005582 if((pScanReq->SSIDs.numOfSSIDs != 0) && ( eSIR_PASSIVE_SCAN != scanType ))
5583 {
Jeff Johnson40b59aa2013-03-19 14:43:18 -07005584 for (i = 0; i < pMsg->numSsid; i++)
5585 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305586 vos_mem_copy(&pMsg->ssId[i],
5587 &pScanReq->SSIDs.SSIDList[i].SSID, sizeof(tSirMacSSid));
Jeff Johnson40b59aa2013-03-19 14:43:18 -07005588 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005589 }
5590 else
5591 {
5592 //Otherwise we scan all SSID and let the result filter later
Jeff Johnson40b59aa2013-03-19 14:43:18 -07005593 for (i = 0; i < SIR_SCAN_MAX_NUM_SSID; i++)
5594 {
5595 pMsg->ssId[i].length = 0;
5596 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005597 }
5598
Jeff Johnson295189b2012-06-20 16:38:30 -07005599 pMsg->minChannelTime = pal_cpu_to_be32(minChnTime);
5600 pMsg->maxChannelTime = pal_cpu_to_be32(maxChnTime);
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08005601 pMsg->minChannelTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
5602 pMsg->maxChannelTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07005603 //hidden SSID option
5604 pMsg->hiddenSsid = pScanReqParam->hiddenSsid;
5605 //rest time
5606 //pMsg->restTime = pScanReq->restTime;
5607 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
5608 // All the scan results caching will be done by Roaming
5609 // We do not want LIM to do any caching of scan results,
5610 // so delete the LIM cache on all scan requests
5611 pMsg->returnFreshResults = pScanReqParam->freshScan;
5612 //Always ask for unique result
5613 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
5614 pMsg->channelList.numChannels = (tANI_U8)pScanReq->ChannelInfo.numOfChannels;
5615 if(pScanReq->ChannelInfo.numOfChannels)
5616 {
5617 //Assuming the channelNumber is tANI_U8 (1 byte)
Kiet Lam64c1b492013-07-12 13:56:44 +05305618 vos_mem_copy(pMsg->channelList.channelNumber,
5619 pScanReq->ChannelInfo.ChannelList,
5620 pScanReq->ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07005621 }
5622
5623 pMsg->uIEFieldLen = (tANI_U16) pScanReq->uIEFieldLen;
5624 pMsg->uIEFieldOffset = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
5625 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) ;
5626 if(pScanReq->uIEFieldLen != 0)
5627 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305628 vos_mem_copy((tANI_U8 *)pMsg+pMsg->uIEFieldOffset, pScanReq->pIEField,
5629 pScanReq->uIEFieldLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07005630 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005631 pMsg->p2pSearch = pScanReq->p2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07005632
Madan Mohan Koyyalamudi9b876782012-10-11 16:22:51 -07005633 if (pScanReq->requestType == eCSR_SCAN_HO_BG_SCAN)
5634 {
5635 pMsg->backgroundScanMode = eSIR_ROAMING_SCAN;
5636 }
5637
Jeff Johnson295189b2012-06-20 16:38:30 -07005638 }while(0);
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005639 smsLog(pMac, LOG1, FL("domainIdCurrent %d scanType %d bssType %d requestType %d numChannels %d "),
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005640 pMac->scan.domainIdCurrent, pMsg->scanType, pMsg->bssType,
5641 pScanReq->requestType, pMsg->channelList.numChannels);
5642
5643 for(i = 0; i < pMsg->channelList.numChannels; i++)
5644 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005645 smsLog(pMac, LOG3, FL("channelNumber[%d]= %d"), i, pMsg->channelList.channelNumber[i]);
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005646 }
5647
Jeff Johnson295189b2012-06-20 16:38:30 -07005648 if(HAL_STATUS_SUCCESS(status))
5649 {
5650 status = palSendMBMessage(pMac->hHdd, pMsg);
5651 }
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005652 else
5653 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005654 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d"), status );
Kiet Lam64c1b492013-07-12 13:56:44 +05305655 vos_mem_free(pMsg);
Jeff Johnson295189b2012-06-20 16:38:30 -07005656 }
5657 }//Success allocated memory
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005658 else
5659 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005660 smsLog( pMac, LOGE, FL(" memory allocation failure"));
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005661 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005662
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05305663 if(!HAL_STATUS_SUCCESS(status))
5664 {
5665 smsLog( pMac, LOG1, FL("Failed: SId: %d FirstMatch = %d"
5666 " UniqueResult = %d freshScan = %d hiddenSsid = %d"),
5667 sessionId, pScanReqParam->bReturnAfter1stMatch,
5668 pScanReqParam->fUniqueResult, pScanReqParam->freshScan,
5669 pScanReqParam->hiddenSsid );
5670 smsLog( pMac, LOG1, FL("scanType = %u BSSType = %u numOfSSIDs = %d"
5671 " numOfChannels = %d requestType = %d p2pSearch = %d\n"),
5672 pScanReq->scanType, pScanReq->BSSType,
5673 pScanReq->SSIDs.numOfSSIDs,
5674 pScanReq->ChannelInfo.numOfChannels, pScanReq->requestType,
5675 pScanReq->p2pSearch );
5676
5677 }
5678
Jeff Johnson295189b2012-06-20 16:38:30 -07005679 return( status );
5680}
5681
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005682eHalStatus csrSendMBScanResultReq( tpAniSirGlobal pMac, tANI_U32 sessionId, tScanReqParam *pScanReqParam )
Jeff Johnson295189b2012-06-20 16:38:30 -07005683{
5684 eHalStatus status = eHAL_STATUS_SUCCESS;
5685 tSirSmeScanReq *pMsg;
5686 tANI_U16 msgLen;
5687
5688 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ));
Kiet Lam64c1b492013-07-12 13:56:44 +05305689 pMsg = vos_mem_malloc(msgLen);
5690 if ( NULL == pMsg )
5691 status = eHAL_STATUS_FAILURE;
5692 else
Jeff Johnson295189b2012-06-20 16:38:30 -07005693 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305694 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005695 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
5696 pMsg->length = pal_cpu_to_be16(msgLen);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005697 pMsg->sessionId = sessionId;
5698 pMsg->transactionId = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07005699 pMsg->returnFreshResults = pScanReqParam->freshScan;
5700 //Always ask for unique result
5701 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
5702 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
5703 status = palSendMBMessage(pMac->hHdd, pMsg);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005704 if (!HAL_STATUS_SUCCESS(status))
5705 {
5706 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d\n"), status );
5707 }
5708
Jeff Johnson295189b2012-06-20 16:38:30 -07005709 }
5710
5711 return( status );
5712}
5713
5714
5715
5716eHalStatus csrScanChannels( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5717{
5718 eHalStatus status = eHAL_STATUS_FAILURE;
5719 tScanReqParam scanReq;
5720
5721 do
5722 {
5723 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE | TRUE;
5724 scanReq.fUniqueResult = TRUE;
5725 scanReq.hiddenSsid = SIR_SCAN_NO_HIDDEN_SSID;
5726 if(eCsrScanForSsid == pCommand->u.scanCmd.reason)
5727 {
5728 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_FIRST_MATCH;
5729 }
5730 else
5731 {
5732 // Basically do scan on all channels even for 11D 1st scan case.
5733 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5734 }
5735 if((eCsrScanBgScan == pCommand->u.scanCmd.reason)||
5736 (eCsrScanProbeBss == pCommand->u.scanCmd.reason))
5737 {
5738 scanReq.hiddenSsid = SIR_SCAN_HIDDEN_SSID_PE_DECISION;
5739 }
5740
5741#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5742 {
5743 vos_log_scan_pkt_type *pScanLog = NULL;
5744
5745 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
5746 if(pScanLog)
5747 {
5748 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
5749 eCsrScanProbeBss == pCommand->u.scanCmd.reason)
5750 {
5751 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
5752 }
5753 else
5754 {
5755 if( (eSIR_PASSIVE_SCAN != pCommand->u.scanCmd.u.scanRequest.scanType) &&
5756 (eSIR_PASSIVE_SCAN != pMac->scan.curScanType) )
5757 {
5758 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_REQ;
5759 }
5760 else
5761 {
5762 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_REQ;
5763 }
5764 }
5765 pScanLog->minChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.minChnTime;
5766 pScanLog->maxChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.maxChnTime;
5767 pScanLog->numChannel = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
5768 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
5769 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305770 vos_mem_copy(pScanLog->channels,
5771 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
5772 pScanLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07005773 }
5774 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
5775 }
5776 }
5777#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5778
5779
5780 status = csrSendMBScanReq(pMac, pCommand->sessionId,
5781 &pCommand->u.scanCmd.u.scanRequest, &scanReq);
5782 }while(0);
5783
5784 return( status );
5785}
5786
5787
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005788eHalStatus csrScanRetrieveResult(tpAniSirGlobal pMac, tSmeCmd *pCommand)
Jeff Johnson295189b2012-06-20 16:38:30 -07005789{
5790 eHalStatus status = eHAL_STATUS_FAILURE;
5791 tScanReqParam scanReq;
5792
5793 do
5794 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005795#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5796 if (eCsrScanGetLfrResult == pCommand->u.scanCmd.reason)
5797 {
5798 //to get the LFR candidates from PE cache
5799 scanReq.freshScan = SIR_BG_SCAN_RETURN_LFR_CACHED_RESULTS|SIR_BG_SCAN_PURGE_LFR_RESULTS;
5800 scanReq.fUniqueResult = TRUE;
5801 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5802 }
5803 else
5804#endif
5805 {
5806 //not a fresh scan
5807 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE;
5808 scanReq.fUniqueResult = TRUE;
5809 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5810 }
5811 status = csrSendMBScanResultReq(pMac, pCommand->sessionId, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07005812 }while(0);
5813
5814 return (status);
5815}
5816
5817
5818
5819eHalStatus csrProcessScanCommand( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5820{
5821 eHalStatus status = eHAL_STATUS_SUCCESS;
5822 tCsrChannelInfo newChannelInfo = {0, NULL};
5823 int i, j;
5824 tANI_U8 *pChannel = NULL;
5825 tANI_U32 len = 0;
5826
5827 // Transition to Scanning state...
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305828 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07005829 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305830 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5831 {
5832 pCommand->u.scanCmd.lastRoamState[i] =
5833 csrRoamStateChange( pMac, eCSR_ROAMING_STATE_SCANNING, i);
5834 smsLog( pMac, LOG3, "starting SCAN command from %d state...."
5835 " reason is %d", pCommand->u.scanCmd.lastRoamState[i],
5836 pCommand->u.scanCmd.reason );
5837 }
5838 }
5839 else
5840 {
5841 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId] =
5842 csrRoamStateChange(pMac, eCSR_ROAMING_STATE_SCANNING,
5843 pCommand->sessionId);
5844 smsLog( pMac, LOG3,
5845 "starting SCAN command from %d state.... reason is %d",
5846 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId],
5847 pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07005848 }
5849
5850 switch(pCommand->u.scanCmd.reason)
5851 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005852#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5853 case eCsrScanGetLfrResult:
5854#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005855 case eCsrScanGetResult:
5856 case eCsrScanForCapsChange: //For cap change, LIM already save BSS description
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005857 status = csrScanRetrieveResult(pMac, pCommand);
Jeff Johnson295189b2012-06-20 16:38:30 -07005858 break;
5859 case eCsrScanSetBGScanParam:
5860 status = csrProcessSetBGScanParam(pMac, pCommand);
5861 break;
5862 case eCsrScanBGScanAbort:
5863 status = csrSetCfgBackgroundScanPeriod(pMac, 0);
5864 break;
5865 case eCsrScanBGScanEnable:
5866 status = csrSetCfgBackgroundScanPeriod(pMac, pMac->roam.configParam.bgScanInterval);
5867 break;
5868 case eCsrScanGetScanChnInfo:
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05305869 status = csrScanGetScanChannelInfo(pMac, pCommand->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07005870 break;
5871 case eCsrScanUserRequest:
5872 if(pMac->roam.configParam.fScanTwice)
5873 {
5874 //We scan 2.4 channel twice
5875 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels &&
5876 (NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList))
5877 {
5878 len = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
5879 //allocate twice the channel
5880 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(newChannelInfo.numOfChannels * 2);
5881 pChannel = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
5882 }
5883 else
5884 {
5885 //get the valid channel list to scan all.
5886 len = sizeof(pMac->roam.validChannelList);
5887
5888 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
5889 {
5890 //allocate twice the channel
5891 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(len * 2);
5892 pChannel = pMac->roam.validChannelList;
5893 }
5894 }
5895 if(NULL == newChannelInfo.ChannelList)
5896 {
5897 newChannelInfo.numOfChannels = 0;
5898 }
5899 else
5900 {
5901 j = 0;
5902 for(i = 0; i < len; i++)
5903 {
5904 newChannelInfo.ChannelList[j++] = pChannel[i];
5905 if(CSR_MAX_24GHz_CHANNEL_NUMBER >= pChannel[i])
5906 {
5907 newChannelInfo.ChannelList[j++] = pChannel[i];
5908 }
5909 }
5910 if(NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
5911 {
5912 //pChannel points to the channellist from the command, free it.
5913 vos_mem_free(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -07005914 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07005915 }
5916 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = j;
5917 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = newChannelInfo.ChannelList;
5918 }
5919 } //if(pMac->roam.configParam.fScanTwice)
5920
5921 status = csrScanChannels(pMac, pCommand);
5922
5923 break;
5924 default:
5925 status = csrScanChannels(pMac, pCommand);
5926 break;
5927 }
5928
5929 if(!HAL_STATUS_SUCCESS(status))
5930 {
5931 csrReleaseScanCommand(pMac, pCommand, eCSR_SCAN_FAILURE);
5932 }
5933
5934 return (status);
5935}
5936
5937
5938eHalStatus csrScanSetBGScanparams(tpAniSirGlobal pMac, tCsrBGScanRequest *pScanReq)
5939{
5940 eHalStatus status = eHAL_STATUS_SUCCESS;
5941 tSmeCmd *pCommand = NULL;
5942
5943 if(pScanReq)
5944 {
5945 do
5946 {
5947 pCommand = csrGetCommandBuffer(pMac);
5948 if(!pCommand)
5949 {
5950 status = eHAL_STATUS_RESOURCES;
5951 break;
5952 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305953 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005954 pCommand->command = eSmeCommandScan;
5955 pCommand->u.scanCmd.reason = eCsrScanSetBGScanParam;
5956 pCommand->u.scanCmd.callback = NULL;
5957 pCommand->u.scanCmd.pContext = NULL;
Kiet Lam64c1b492013-07-12 13:56:44 +05305958 vos_mem_copy(&pCommand->u.scanCmd.u.bgScanRequest, pScanReq, sizeof(tCsrBGScanRequest));
Jeff Johnson295189b2012-06-20 16:38:30 -07005959 //we have to do the follow
5960 if(pScanReq->ChannelInfo.numOfChannels == 0)
5961 {
5962 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
5963 }
5964 else
5965 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305966 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList
5967 = vos_mem_malloc(pScanReq->ChannelInfo.numOfChannels);
5968 if ( NULL != pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07005969 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305970 vos_mem_copy(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList,
5971 pScanReq->ChannelInfo.ChannelList,
5972 pScanReq->ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07005973 }
5974 else
5975 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005976 smsLog(pMac, LOGE, FL("ran out of memory"));
Jeff Johnson295189b2012-06-20 16:38:30 -07005977 csrReleaseCommandScan(pMac, pCommand);
Kiet Lam64c1b492013-07-12 13:56:44 +05305978 return eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005979 }
5980 }
5981
5982 //scan req for SSID
5983 if(pScanReq->SSID.length)
5984 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305985 vos_mem_copy(pCommand->u.scanCmd.u.bgScanRequest.SSID.ssId,
5986 pScanReq->SSID.ssId, pScanReq->SSID.length);
Jeff Johnson295189b2012-06-20 16:38:30 -07005987 pCommand->u.scanCmd.u.bgScanRequest.SSID.length = pScanReq->SSID.length;
5988
5989 }
5990 pCommand->u.scanCmd.u.bgScanRequest.maxChnTime= pScanReq->maxChnTime;
5991 pCommand->u.scanCmd.u.bgScanRequest.minChnTime = pScanReq->minChnTime;
5992 pCommand->u.scanCmd.u.bgScanRequest.scanInterval = pScanReq->scanInterval;
5993
5994
5995 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
5996 if( !HAL_STATUS_SUCCESS( status ) )
5997 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005998 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07005999 csrReleaseCommandScan( pMac, pCommand );
6000 break;
6001 }
6002 }while(0);
6003 }
6004
6005 return (status);
6006}
6007
6008eHalStatus csrScanBGScanAbort( tpAniSirGlobal pMac )
6009{
6010 eHalStatus status = eHAL_STATUS_SUCCESS;
6011 tSmeCmd *pCommand = NULL;
6012
6013 do
6014 {
6015 pCommand = csrGetCommandBuffer(pMac);
6016 if(!pCommand)
6017 {
6018 status = eHAL_STATUS_RESOURCES;
6019 break;
6020 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306021 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006022 pCommand->command = eSmeCommandScan;
6023 pCommand->u.scanCmd.reason = eCsrScanBGScanAbort;
6024 pCommand->u.scanCmd.callback = NULL;
6025 pCommand->u.scanCmd.pContext = NULL;
6026 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
6027 if( !HAL_STATUS_SUCCESS( status ) )
6028 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006029 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006030 csrReleaseCommandScan( pMac, pCommand );
6031 break;
6032 }
6033 }while(0);
6034
6035 return (status);
6036}
6037
6038
6039//This will enable the background scan with the non-zero interval
6040eHalStatus csrScanBGScanEnable(tpAniSirGlobal pMac)
6041{
6042 eHalStatus status = eHAL_STATUS_SUCCESS;
6043 tSmeCmd *pCommand = NULL;
6044
6045 if(pMac->roam.configParam.bgScanInterval)
6046 {
6047 do
6048 {
6049 pCommand = csrGetCommandBuffer(pMac);
6050 if(!pCommand)
6051 {
6052 status = eHAL_STATUS_RESOURCES;
6053 break;
6054 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306055 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006056 pCommand->command = eSmeCommandScan;
6057 pCommand->u.scanCmd.reason = eCsrScanBGScanEnable;
6058 pCommand->u.scanCmd.callback = NULL;
6059 pCommand->u.scanCmd.pContext = NULL;
6060 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
6061 if( !HAL_STATUS_SUCCESS( status ) )
6062 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006063 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006064 csrReleaseCommandScan( pMac, pCommand );
6065 break;
6066 }
6067 }while(0);
6068 //BG scan results are reported automatically by PE to SME once the scan is done.
6069 //No need to fetch the results explicitly.
6070 //csrScanStartGetResultTimer(pMac);
6071 csrScanStartResultAgingTimer(pMac);
6072 }
6073 else
6074 {
6075 //We don't have BG scan so stop the aging timer
6076 csrScanStopResultAgingTimer(pMac);
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006077 smsLog(pMac, LOGE, FL("cannot continue because the bgscan interval is 0"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006078 status = eHAL_STATUS_INVALID_PARAMETER;
6079 }
6080
6081 return (status);
6082}
6083
6084
6085eHalStatus csrScanCopyRequest(tpAniSirGlobal pMac, tCsrScanRequest *pDstReq, tCsrScanRequest *pSrcReq)
6086{
6087 eHalStatus status = eHAL_STATUS_SUCCESS;
6088 tANI_U32 len = sizeof(pMac->roam.validChannelList);
6089 tANI_U32 index = 0;
6090 tANI_U32 new_index = 0;
6091
6092 do
6093 {
6094 status = csrScanFreeRequest(pMac, pDstReq);
6095 if(HAL_STATUS_SUCCESS(status))
6096 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306097 vos_mem_copy(pDstReq, pSrcReq, sizeof(tCsrScanRequest));
Gopichand Nakkalac7b1d3e2012-12-31 14:07:19 -08006098 /* Re-initialize the pointers to NULL since we did a copy */
6099 pDstReq->pIEField = NULL;
6100 pDstReq->ChannelInfo.ChannelList = NULL;
6101 pDstReq->SSIDs.SSIDList = NULL;
6102
Jeff Johnson295189b2012-06-20 16:38:30 -07006103 if(pSrcReq->uIEFieldLen == 0)
6104 {
6105 pDstReq->pIEField = NULL;
6106 }
6107 else
6108 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306109 pDstReq->pIEField = vos_mem_malloc(pSrcReq->uIEFieldLen);
6110 if ( NULL == pDstReq->pIEField )
Jeff Johnson295189b2012-06-20 16:38:30 -07006111 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306112 status = eHAL_STATUS_FAILURE;
6113 smsLog(pMac, LOGE, FL("No memory for scanning IE fields"));
6114 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07006115 }
6116 else
6117 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306118 status = eHAL_STATUS_SUCCESS;
6119 vos_mem_copy(pDstReq->pIEField, pSrcReq->pIEField,
6120 pSrcReq->uIEFieldLen);
6121 pDstReq->uIEFieldLen = pSrcReq->uIEFieldLen;
Jeff Johnson295189b2012-06-20 16:38:30 -07006122 }
6123 }//Allocate memory for IE field
6124 {
6125 if(pSrcReq->ChannelInfo.numOfChannels == 0)
6126 {
6127 pDstReq->ChannelInfo.ChannelList = NULL;
6128 pDstReq->ChannelInfo.numOfChannels = 0;
6129 }
6130 else
6131 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306132 pDstReq->ChannelInfo.ChannelList = vos_mem_malloc(
6133 pSrcReq->ChannelInfo.numOfChannels
6134 * sizeof(*pDstReq->ChannelInfo.ChannelList));
6135 if ( NULL == pDstReq->ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07006136 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306137 status = eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006138 pDstReq->ChannelInfo.numOfChannels = 0;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306139 smsLog(pMac, LOGE, FL("No memory for scanning Channel"
6140 " List"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006141 break;
6142 }
6143
6144 if((pSrcReq->scanType == eSIR_PASSIVE_SCAN) && (pSrcReq->requestType == eCSR_SCAN_REQUEST_11D_SCAN))
6145 {
6146 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
6147 {
6148 pDstReq->ChannelInfo.ChannelList[new_index] =
6149 pSrcReq->ChannelInfo.ChannelList[index];
6150 new_index++;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306151 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006152 pDstReq->ChannelInfo.numOfChannels = new_index;
6153 }
6154 else if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
6155 {
6156 new_index = 0;
6157 pMac->roam.numValidChannels = len;
6158 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
6159 {
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -07006160 /* Allow scan on valid channels only.
6161 * If it is p2p scan and valid channel list doesnt contain
6162 * social channels, enforce scan on social channels because
6163 * that is the only way to find p2p peers.
6164 * This can happen only if band is set to 5Ghz mode.
6165 */
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08006166 if((csrRoamIsValidChannel(pMac, pSrcReq->ChannelInfo.ChannelList[index])) ||
6167 ((eCSR_SCAN_P2P_DISCOVERY == pSrcReq->requestType) &&
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -07006168 CSR_IS_SOCIAL_CHANNEL(pSrcReq->ChannelInfo.ChannelList[index])))
Jeff Johnson295189b2012-06-20 16:38:30 -07006169 {
Srikant Kuppa866893f2012-12-27 17:28:14 -08006170 if( (pSrcReq->skipDfsChnlInP2pSearch &&
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08006171 (NV_CHANNEL_DFS == vos_nv_getChannelEnabledState(pSrcReq->ChannelInfo.ChannelList[index])) )
Srikant Kuppa866893f2012-12-27 17:28:14 -08006172#ifdef FEATURE_WLAN_LFR
6173 /*
6174 * If LFR is requesting a contiguous scan
6175 * (i.e. numOfChannels > 1), then ignore
6176 * DFS channels.
6177 * TODO: vos_nv_getChannelEnabledState is returning
6178 * 120, 124 and 128 as non-DFS channels. Hence, the
6179 * use of direct check for channels below.
6180 */
6181 || ((eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType) &&
6182 (pSrcReq->ChannelInfo.numOfChannels > 1) &&
Srinivas Girigowdade697412013-02-14 16:31:48 -08006183 (CSR_IS_CHANNEL_DFS(pSrcReq->ChannelInfo.ChannelList[index])))
Srikant Kuppa866893f2012-12-27 17:28:14 -08006184#endif
6185 )
6186 {
6187#ifdef FEATURE_WLAN_LFR
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006188 smsLog(pMac, LOG2,
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306189 FL(" reqType=%d, numOfChannels=%d,"
6190 " ignoring DFS channel %d"),
6191 pSrcReq->requestType,
Srikant Kuppa866893f2012-12-27 17:28:14 -08006192 pSrcReq->ChannelInfo.numOfChannels,
6193 pSrcReq->ChannelInfo.ChannelList[index]);
6194#endif
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306195 continue;
Srikant Kuppa866893f2012-12-27 17:28:14 -08006196 }
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08006197
Jeff Johnson295189b2012-06-20 16:38:30 -07006198 pDstReq->ChannelInfo.ChannelList[new_index] =
6199 pSrcReq->ChannelInfo.ChannelList[index];
6200 new_index++;
6201 }
6202 }
6203 pDstReq->ChannelInfo.numOfChannels = new_index;
Srikant Kuppa866893f2012-12-27 17:28:14 -08006204#ifdef FEATURE_WLAN_LFR
6205 if ((eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType) &&
6206 (0 == pDstReq->ChannelInfo.numOfChannels))
6207 {
6208 /*
6209 * No valid channels found in the request.
6210 * Only perform scan on the channels passed
6211 * pSrcReq if it is a eCSR_SCAN_HO_BG_SCAN.
6212 * Passing 0 to LIM will trigger a scan on
6213 * all valid channels which is not desirable.
6214 */
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306215 smsLog(pMac, LOGE, FL(" no valid channels found"
6216 " (request=%d)"), pSrcReq->requestType);
Srikant Kuppa866893f2012-12-27 17:28:14 -08006217 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
6218 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306219 smsLog(pMac, LOGE, FL("pSrcReq index=%d"
6220 " channel=%d"), index,
6221 pSrcReq->ChannelInfo.ChannelList[index]);
Srikant Kuppa866893f2012-12-27 17:28:14 -08006222 }
6223 status = eHAL_STATUS_FAILURE;
6224 break;
6225 }
6226#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006227 }
6228 else
6229 {
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306230 smsLog(pMac, LOGE, FL("Couldn't get the valid Channel"
6231 " List, keeping requester's list"));
Kiet Lam64c1b492013-07-12 13:56:44 +05306232 vos_mem_copy(pDstReq->ChannelInfo.ChannelList,
6233 pSrcReq->ChannelInfo.ChannelList,
6234 pSrcReq->ChannelInfo.numOfChannels
6235 * sizeof(*pDstReq->ChannelInfo.ChannelList));
Jeff Johnson295189b2012-06-20 16:38:30 -07006236 pDstReq->ChannelInfo.numOfChannels = pSrcReq->ChannelInfo.numOfChannels;
6237 }
6238 }//Allocate memory for Channel List
6239 }
6240 if(pSrcReq->SSIDs.numOfSSIDs == 0)
6241 {
6242 pDstReq->SSIDs.numOfSSIDs = 0;
6243 pDstReq->SSIDs.SSIDList = NULL;
6244 }
6245 else
6246 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306247 pDstReq->SSIDs.SSIDList = vos_mem_malloc(
6248 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
6249 if ( NULL == pDstReq->SSIDs.SSIDList )
6250 status = eHAL_STATUS_FAILURE;
6251 else
6252 status = eHAL_STATUS_SUCCESS;
6253 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07006254 {
6255 pDstReq->SSIDs.numOfSSIDs = pSrcReq->SSIDs.numOfSSIDs;
Kiet Lam64c1b492013-07-12 13:56:44 +05306256 vos_mem_copy(pDstReq->SSIDs.SSIDList,
6257 pSrcReq->SSIDs.SSIDList,
6258 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
Jeff Johnson295189b2012-06-20 16:38:30 -07006259 }
6260 else
6261 {
6262 pDstReq->SSIDs.numOfSSIDs = 0;
Vinay Krishna Eranna636b7bc2013-12-18 20:49:08 +05306263 smsLog(pMac, LOGE, FL("No memory for scanning SSID List"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006264 break;
6265 }
6266 }//Allocate memory for SSID List
Jeff Johnson295189b2012-06-20 16:38:30 -07006267 pDstReq->p2pSearch = pSrcReq->p2pSearch;
Jeff Johnsone7245742012-09-05 17:12:55 -07006268 pDstReq->skipDfsChnlInP2pSearch = pSrcReq->skipDfsChnlInP2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07006269
6270 }
6271 }while(0);
6272
6273 if(!HAL_STATUS_SUCCESS(status))
6274 {
6275 csrScanFreeRequest(pMac, pDstReq);
6276 }
6277
6278 return (status);
6279}
6280
6281
6282eHalStatus csrScanFreeRequest(tpAniSirGlobal pMac, tCsrScanRequest *pReq)
6283{
Jeff Johnson295189b2012-06-20 16:38:30 -07006284
6285 if(pReq->ChannelInfo.ChannelList)
6286 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306287 vos_mem_free(pReq->ChannelInfo.ChannelList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006288 pReq->ChannelInfo.ChannelList = NULL;
6289 }
6290 pReq->ChannelInfo.numOfChannels = 0;
6291 if(pReq->pIEField)
6292 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306293 vos_mem_free(pReq->pIEField);
Jeff Johnson295189b2012-06-20 16:38:30 -07006294 pReq->pIEField = NULL;
6295 }
6296 pReq->uIEFieldLen = 0;
6297 if(pReq->SSIDs.SSIDList)
6298 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306299 vos_mem_free(pReq->SSIDs.SSIDList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006300 pReq->SSIDs.SSIDList = NULL;
6301 }
6302 pReq->SSIDs.numOfSSIDs = 0;
6303
Kiet Lam64c1b492013-07-12 13:56:44 +05306304 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07006305}
6306
6307
6308void csrScanCallCallback(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
6309{
6310 if(pCommand->u.scanCmd.callback)
6311 {
6312// sme_ReleaseGlobalLock( &pMac->sme );
6313 pCommand->u.scanCmd.callback(pMac, pCommand->u.scanCmd.pContext, pCommand->u.scanCmd.scanID, scanStatus);
6314// sme_AcquireGlobalLock( &pMac->sme );
6315 } else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006316 smsLog( pMac, LOG2, "%s:%d - Callback NULL!!!", __func__, __LINE__);
Jeff Johnson295189b2012-06-20 16:38:30 -07006317 }
6318}
6319
6320
6321void csrScanStopTimers(tpAniSirGlobal pMac)
6322{
6323 csrScanStopResultAgingTimer(pMac);
6324 csrScanStopIdleScanTimer(pMac);
6325 csrScanStopGetResultTimer(pMac);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006326 if(0 != pMac->scan.scanResultCfgAgingTime )
6327 {
6328 csrScanStopResultCfgAgingTimer(pMac);
6329 }
6330
Jeff Johnson295189b2012-06-20 16:38:30 -07006331}
6332
6333
6334eHalStatus csrScanStartGetResultTimer(tpAniSirGlobal pMac)
6335{
6336 eHalStatus status;
6337
6338 if(pMac->scan.fScanEnable)
6339 {
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306340 status = vos_timer_start(&pMac->scan.hTimerGetResult, CSR_SCAN_GET_RESULT_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006341 }
6342 else
6343 {
6344 status = eHAL_STATUS_FAILURE;
6345 }
6346
6347 return (status);
6348}
6349
6350
6351eHalStatus csrScanStopGetResultTimer(tpAniSirGlobal pMac)
6352{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306353 return (vos_timer_stop(&pMac->scan.hTimerGetResult));
Jeff Johnson295189b2012-06-20 16:38:30 -07006354}
6355
6356
6357void csrScanGetResultTimerHandler(void *pv)
6358{
6359 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6360
6361 csrScanRequestResult(pMac);
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306362
6363 vos_timer_start(&pMac->scan.hTimerGetResult, CSR_SCAN_GET_RESULT_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006364}
6365
6366#ifdef WLAN_AP_STA_CONCURRENCY
6367static void csrStaApConcTimerHandler(void *pv)
6368{
6369 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6370 tListElem *pEntry;
6371 tSmeCmd *pScanCmd;
6372
6373 csrLLLock(&pMac->scan.scanCmdPendingList);
6374
6375 if ( NULL != ( pEntry = csrLLPeekHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) ) )
6376 {
6377 tCsrScanRequest scanReq;
6378 tSmeCmd *pSendScanCmd = NULL;
6379 tANI_U8 numChn = 0;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006380 tANI_U8 nNumChanCombinedConc = 0;
Vinay Malekal05fdc812012-12-17 13:04:30 -08006381 tANI_U8 i, j;
Jeff Johnson295189b2012-06-20 16:38:30 -07006382 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
6383 tANI_U8 channelToScan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
6384 eHalStatus status;
6385
Jeff Johnson295189b2012-06-20 16:38:30 -07006386 pScanCmd = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
6387 numChn = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08006388
6389 /* if any session is connected and the number of channels to scan is
6390 * greater than 1 then split the scan into multiple scan operations
6391 * on each individual channel else continue to perform scan on all
6392 * specified channels */
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08006393
6394 /* split scan if number of channels to scan is greater than 1 and
6395 * any one of the following:
6396 * - STA session is connected and the scan is not a P2P search
6397 * - any P2P session is connected
Srikant Kuppa866893f2012-12-27 17:28:14 -08006398 * Do not split scans if no concurrent infra connections are
6399 * active and if the scan is a BG scan triggered by LFR (OR)
6400 * any scan if LFR is in the middle of a BG scan. Splitting
6401 * the scan is delaying the time it takes for LFR to find
6402 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08006403 */
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006404
6405 if((csrIsStaSessionConnected(pMac) &&
6406 !csrIsP2pSessionConnected(pMac)))
6407 {
6408 nNumChanCombinedConc = pMac->roam.configParam.nNumStaChanCombinedConc;
6409 }
6410 else if(csrIsP2pSessionConnected(pMac))
6411 {
6412 nNumChanCombinedConc = pMac->roam.configParam.nNumP2PChanCombinedConc;
6413 }
6414
6415 if ( (numChn > nNumChanCombinedConc) &&
Srikant Kuppa866893f2012-12-27 17:28:14 -08006416 ((csrIsStaSessionConnected(pMac) &&
6417#ifdef FEATURE_WLAN_LFR
6418 (csrIsConcurrentInfraConnected(pMac) ||
6419 ((pScanCmd->u.scanCmd.reason != eCsrScanBgScan) &&
6420 (pMac->roam.neighborRoamInfo.neighborRoamState !=
6421 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
6422#endif
6423 (pScanCmd->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08006424 (csrIsP2pSessionConnected(pMac))))
Jeff Johnson295189b2012-06-20 16:38:30 -07006425 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306426 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006427
6428 pSendScanCmd = csrGetCommandBuffer(pMac); //optimize this to use 2 command buffer only
6429 if (!pSendScanCmd)
6430 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006431 smsLog( pMac, LOGE, FL(" Failed to get Queue command buffer") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006432 csrLLUnlock(&pMac->scan.scanCmdPendingList);
6433 return;
6434 }
6435 pSendScanCmd->command = pScanCmd->command;
6436 pSendScanCmd->sessionId = pScanCmd->sessionId;
6437 pSendScanCmd->u.scanCmd.callback = NULL;
6438 pSendScanCmd->u.scanCmd.pContext = pScanCmd->u.scanCmd.pContext;
6439 pSendScanCmd->u.scanCmd.reason = pScanCmd->u.scanCmd.reason;
6440 pSendScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
6441
Madan Mohan Koyyalamudiaf2a8b92012-10-09 14:58:07 -07006442 /* First copy all the parameters to local variable of scan request */
6443 csrScanCopyRequest(pMac, &scanReq, &pScanCmd->u.scanCmd.u.scanRequest);
6444
6445 /* Now modify the elements of local var scan request required to be modified for split scan */
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08006446 if(scanReq.ChannelInfo.ChannelList != NULL)
6447 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306448 vos_mem_free(scanReq.ChannelInfo.ChannelList);
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08006449 scanReq.ChannelInfo.ChannelList = NULL;
6450 }
6451
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006452 pChnInfo->numOfChannels = nNumChanCombinedConc;
Kiet Lam64c1b492013-07-12 13:56:44 +05306453 vos_mem_copy(&channelToScan[0],
6454 &pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[0],
6455 pChnInfo->numOfChannels * sizeof(tANI_U8));//just send one channel
Jeff Johnson295189b2012-06-20 16:38:30 -07006456 pChnInfo->ChannelList = &channelToScan[0];
6457
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006458 for (i = 0, j = nNumChanCombinedConc; i < (numChn-nNumChanCombinedConc); i++, j++)
Jeff Johnson295189b2012-06-20 16:38:30 -07006459 {
6460 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] =
Vinay Malekal05fdc812012-12-17 13:04:30 -08006461 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[j]; //Move all the channels one step
Jeff Johnson295189b2012-06-20 16:38:30 -07006462 }
6463
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006464 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = numChn - nNumChanCombinedConc; //reduce outstanding # of channels to be scanned
Jeff Johnson295189b2012-06-20 16:38:30 -07006465
6466 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
6467 //Modify callers parameters in case of concurrency
6468 scanReq.scanType = eSIR_ACTIVE_SCAN;
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -07006469 //Use concurrency values for min/maxChnTime.
6470 //We know csrIsAnySessionConnected(pMac) returns TRUE here
6471 csrSetDefaultScanTiming(pMac, scanReq.scanType, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07006472
6473 status = csrScanCopyRequest(pMac, &pSendScanCmd->u.scanCmd.u.scanRequest, &scanReq);
6474 if(!HAL_STATUS_SUCCESS(status))
6475 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006476 smsLog( pMac, LOGE, FL(" Failed to get copy csrScanRequest = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006477 csrLLUnlock(&pMac->scan.scanCmdPendingList);
6478 return;
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08006479 }
6480 /* Clean the local scan variable */
6481 scanReq.ChannelInfo.ChannelList = NULL;
6482 scanReq.ChannelInfo.numOfChannels = 0;
6483 csrScanFreeRequest(pMac, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07006484 }
6485 else
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08006486 {
6487 /* no active connected session present or numChn == 1
6488 * scan all remaining channels */
Jeff Johnson295189b2012-06-20 16:38:30 -07006489 pSendScanCmd = pScanCmd;
6490 //remove this command from pending list
6491 if (csrLLRemoveHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) == NULL)
6492 { //In case between PeekHead and here, the entry got removed by another thread.
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006493 smsLog( pMac, LOGE, FL(" Failed to remove entry from scanCmdPendingList"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006494 }
6495
6496 }
6497 csrQueueSmeCommand(pMac, pSendScanCmd, eANI_BOOLEAN_FALSE);
6498
6499 }
6500
Jeff Johnson295189b2012-06-20 16:38:30 -07006501 csrLLUnlock(&pMac->scan.scanCmdPendingList);
6502
6503}
6504#endif
6505
6506eHalStatus csrScanStartResultAgingTimer(tpAniSirGlobal pMac)
6507{
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006508 eHalStatus status = eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006509
6510 if(pMac->scan.fScanEnable)
6511 {
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306512 status = vos_timer_start(&pMac->scan.hTimerResultAging, CSR_SCAN_RESULT_AGING_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006513 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006514 return (status);
6515}
6516
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006517eHalStatus csrScanStartResultCfgAgingTimer(tpAniSirGlobal pMac)
6518{
6519 eHalStatus status = eHAL_STATUS_FAILURE;
6520
6521 if(pMac->scan.fScanEnable)
6522 {
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306523 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 -08006524 }
6525 return (status);
6526}
Jeff Johnson295189b2012-06-20 16:38:30 -07006527
6528eHalStatus csrScanStopResultAgingTimer(tpAniSirGlobal pMac)
6529{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306530 return (vos_timer_stop(&pMac->scan.hTimerResultAging));
Jeff Johnson295189b2012-06-20 16:38:30 -07006531}
6532
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006533eHalStatus csrScanStopResultCfgAgingTimer(tpAniSirGlobal pMac)
6534{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306535 return (vos_timer_stop(&pMac->scan.hTimerResultCfgAging));
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006536}
Jeff Johnson295189b2012-06-20 16:38:30 -07006537
6538//This function returns the maximum time a BSS is allowed in the scan result.
6539//The time varies base on connection and power saving factors.
6540//Not connected, No PS
6541//Not connected, with PS
6542//Connected w/o traffic, No PS
6543//Connected w/o traffic, with PS
6544//Connected w/ traffic, no PS -- Not supported
6545//Connected w/ traffic, with PS -- Not supported
6546//the return unit is in seconds.
6547tANI_U32 csrScanGetAgeOutTime(tpAniSirGlobal pMac)
6548{
6549 tANI_U32 nRet;
6550
6551 if(pMac->scan.nAgingCountDown)
6552 {
6553 //Calculate what should be the timeout value for this
6554 nRet = pMac->scan.nLastAgeTimeOut * pMac->scan.nAgingCountDown;
6555 pMac->scan.nAgingCountDown--;
6556 }
6557 else
6558 {
6559 if( csrIsAllSessionDisconnected( pMac ) )
6560 {
6561 if(pmcIsPowerSaveEnabled(pMac, ePMC_IDLE_MODE_POWER_SAVE))
6562 {
6563 nRet = pMac->roam.configParam.scanAgeTimeNCPS;
6564 }
6565 else
6566 {
6567 nRet = pMac->roam.configParam.scanAgeTimeNCNPS;
6568 }
6569 }
6570 else
6571 {
6572 if(pmcIsPowerSaveEnabled(pMac, ePMC_BEACON_MODE_POWER_SAVE))
6573 {
6574 nRet = pMac->roam.configParam.scanAgeTimeCPS;
6575 }
6576 else
6577 {
6578 nRet = pMac->roam.configParam.scanAgeTimeCNPS;
6579 }
6580 }
6581 //If state-change causing aging time out change, we want to delay it somewhat to avoid
6582 //unnecessary removal of BSS. This is mostly due to transition from connect to disconnect.
6583 if(pMac->scan.nLastAgeTimeOut > nRet)
6584 {
6585 if(nRet)
6586 {
6587 pMac->scan.nAgingCountDown = (pMac->scan.nLastAgeTimeOut / nRet);
6588 }
6589 pMac->scan.nLastAgeTimeOut = nRet;
6590 nRet *= pMac->scan.nAgingCountDown;
6591 }
6592 else
6593 {
6594 pMac->scan.nLastAgeTimeOut = nRet;
6595 }
6596 }
6597
6598 return (nRet);
6599}
6600
6601
6602void csrScanResultAgingTimerHandler(void *pv)
6603{
6604 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6605 tANI_BOOLEAN fDisconnected = csrIsAllSessionDisconnected(pMac);
6606
6607 //no scan, no aging
6608 if(pMac->scan.fScanEnable &&
6609 (((eANI_BOOLEAN_FALSE == fDisconnected) && pMac->roam.configParam.bgScanInterval)
6610 || (fDisconnected && (pMac->scan.fCancelIdleScan == eANI_BOOLEAN_FALSE)))
6611 )
6612 {
6613 tListElem *pEntry, *tmpEntry;
6614 tCsrScanResult *pResult;
6615 tANI_TIMESTAMP ageOutTime = (tANI_TIMESTAMP)(csrScanGetAgeOutTime(pMac) * PAL_TICKS_PER_SECOND); //turn it into 10ms units
6616 tANI_TIMESTAMP curTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
6617
6618 csrLLLock(&pMac->scan.scanResultList);
6619 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
6620 while( pEntry )
6621 {
6622 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
6623 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
6624 if((curTime - pResult->Result.BssDescriptor.nReceivedTime) > ageOutTime)
6625 {
6626 smsLog(pMac, LOGW, " age out due to time out");
6627 csrScanAgeOutBss(pMac, pResult);
6628 }
6629 pEntry = tmpEntry;
6630 }
6631 csrLLUnlock(&pMac->scan.scanResultList);
6632 }
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306633 vos_timer_start(&pMac->scan.hTimerResultAging, CSR_SCAN_RESULT_AGING_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006634}
6635
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006636static void csrScanResultCfgAgingTimerHandler(void *pv)
6637{
6638 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6639 tListElem *pEntry, *tmpEntry;
6640 tCsrScanResult *pResult;
6641 tANI_TIMESTAMP ageOutTime = pMac->scan.scanResultCfgAgingTime * PAL_TICKS_PER_SECOND;
6642 tANI_TIMESTAMP curTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
6643
6644 csrLLLock(&pMac->scan.scanResultList);
6645 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
6646 while( pEntry )
6647 {
6648 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
6649 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
6650 if((curTime - pResult->Result.BssDescriptor.nReceivedTime) > ageOutTime)
6651 {
6652 smsLog(pMac, LOGW, " age out due to time out");
6653 csrScanAgeOutBss(pMac, pResult);
6654 }
6655 pEntry = tmpEntry;
6656 }
6657 csrLLUnlock(&pMac->scan.scanResultList);
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306658 vos_timer_start(&pMac->scan.hTimerResultCfgAging, CSR_SCAN_RESULT_CFG_AGING_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006659}
Jeff Johnson295189b2012-06-20 16:38:30 -07006660
6661eHalStatus csrScanStartIdleScanTimer(tpAniSirGlobal pMac, tANI_U32 interval)
6662{
6663 eHalStatus status;
6664
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006665 smsLog(pMac, LOG1, " csrScanStartIdleScanTimer");
Jeff Johnson295189b2012-06-20 16:38:30 -07006666 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) && interval)
6667 {
6668 pMac->scan.nIdleScanTimeGap += interval;
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306669 vos_timer_stop(&pMac->scan.hTimerIdleScan);
6670 status = vos_timer_start(&pMac->scan.hTimerIdleScan, interval/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006671 if( !HAL_STATUS_SUCCESS(status) )
6672 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006673 smsLog(pMac, LOGE, " Fail to start Idle scan timer. status = %d interval = %d", status, interval);
Jeff Johnson295189b2012-06-20 16:38:30 -07006674 //This should not happen but set the flag to restart when ready
6675 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6676 }
6677 }
6678 else
6679 {
6680 if( pMac->scan.fScanEnable && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) )
6681 {
6682 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6683 }
6684 status = eHAL_STATUS_FAILURE;
6685 }
6686
6687 return (status);
6688}
6689
6690
6691eHalStatus csrScanStopIdleScanTimer(tpAniSirGlobal pMac)
6692{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306693 return (vos_timer_stop(&pMac->scan.hTimerIdleScan));
Jeff Johnson295189b2012-06-20 16:38:30 -07006694}
6695
6696
6697//Stop CSR from asking for IMPS, This function doesn't disable IMPS from CSR
6698void csrScanSuspendIMPS( tpAniSirGlobal pMac )
6699{
6700 csrScanCancelIdleScan(pMac);
6701}
6702
6703
6704//Start CSR from asking for IMPS. This function doesn't trigger CSR to request entering IMPS
6705//because IMPS maybe disabled.
6706void csrScanResumeIMPS( tpAniSirGlobal pMac )
6707{
6708 csrScanStartIdleScan( pMac );
6709}
6710
6711
6712void csrScanIMPSCallback(void *callbackContext, eHalStatus status)
6713{
6714 tpAniSirGlobal pMac = PMAC_STRUCT( callbackContext );
6715
6716 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6717 {
6718 if(pMac->roam.configParam.IsIdleScanEnabled)
6719 {
6720 if(HAL_STATUS_SUCCESS(status))
6721 {
6722 if(csrIsAllSessionDisconnected(pMac) && !csrIsRoamCommandWaiting(pMac))
6723 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006724 smsLog(pMac, LOGW, FL("starts idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006725 csrScanAllChannels(pMac, eCSR_SCAN_IDLE_MODE_SCAN);
6726 }
6727 else
6728 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006729 smsLog(pMac, LOGW, FL("cannot start idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006730 //even though we are in timer handle, calling stop timer will make sure the timer
6731 //doesn't get to restart.
6732 csrScanStopIdleScanTimer(pMac);
6733 }
6734 }
6735 else
6736 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006737 smsLog(pMac, LOGE, FL("sees not success status (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07006738 }
6739 }
6740 else
6741 {//we might need another flag to check if CSR needs to request imps at all
6742
6743 tANI_U32 nTime = 0;
6744
6745 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_FALSE;
6746 if(!HAL_STATUS_SUCCESS(csrScanTriggerIdleScan(pMac, &nTime)))
6747 {
6748 csrScanStartIdleScanTimer(pMac, nTime);
6749 }
6750 }
6751 }
6752}
6753
6754
6755//Param: pTimeInterval -- Caller allocated memory in return, if failed, to specify the nxt time interval for
6756//idle scan timer interval
6757//Return: Not success -- meaning it cannot start IMPS, caller needs to start a timer for idle scan
6758eHalStatus csrScanTriggerIdleScan(tpAniSirGlobal pMac, tANI_U32 *pTimeInterval)
6759{
6760 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
6761
6762 //Do not trigger IMPS in case of concurrency
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006763 if (vos_concurrent_sessions_running() && csrIsAnySessionInConnectState(pMac))
6764 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006765 smsLog( pMac, LOG1, FL("Cannot request IMPS because Concurrent Sessions Running") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006766 return (status);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006767 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006768
6769 if(pTimeInterval)
6770 {
6771 *pTimeInterval = 0;
6772 }
6773
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006774 smsLog(pMac, LOG3, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006775 if( smeCommandPending( pMac ) )
6776 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006777 smsLog( pMac, LOG1, FL(" Cannot request IMPS because command pending") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006778 //Not to enter IMPS because more work to do
6779 if(pTimeInterval)
6780 {
6781 *pTimeInterval = 0;
6782 }
6783 //restart when ready
6784 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6785
6786 return (status);
6787 }
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07006788 if (IsPmcImpsReqFailed (pMac))
6789 {
6790 if(pTimeInterval)
6791 {
6792 *pTimeInterval = 1000000; //usec
6793 }
6794 //restart when ready
6795 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006796
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07006797 return status;
6798 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006799 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6800 /*&& pMac->roam.configParam.impsSleepTime*/)
6801 {
6802 //Stop get result timer because idle scan gets scan result out of PE
6803 csrScanStopGetResultTimer(pMac);
6804 if(pTimeInterval)
6805 {
6806 *pTimeInterval = pMac->roam.configParam.impsSleepTime;
6807 }
6808 //pmcRequestImps take a period in millisecond unit.
6809 status = pmcRequestImps(pMac, pMac->roam.configParam.impsSleepTime / PAL_TIMER_TO_MS_UNIT, csrScanIMPSCallback, pMac);
6810 if(!HAL_STATUS_SUCCESS(status))
6811 {
6812 if(eHAL_STATUS_PMC_ALREADY_IN_IMPS != status)
6813 {
6814 //Do restart the timer if CSR thinks it cannot do IMPS
6815 if( !csrCheckPSReady( pMac ) )
6816 {
6817 if(pTimeInterval)
6818 {
6819 *pTimeInterval = 0;
6820 }
6821 //Set the restart flag to true because that idle scan
6822 //can be restarted even though the timer will not be running
6823 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6824 }
6825 else
6826 {
6827 //For not now, we do a quicker retry
6828 if(pTimeInterval)
6829 {
6830 *pTimeInterval = CSR_IDLE_SCAN_WAIT_TIME;
6831 }
6832 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006833 smsLog(pMac, LOGW, FL("call pmcRequestImps and it returns status code (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07006834 }
6835 else
6836 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006837 smsLog(pMac, LOGW, FL("already in IMPS"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006838 //Since CSR is the only module to request for IMPS. If it is already in IMPS, CSR assumes
6839 //the callback will be called in the future. Should not happen though.
6840 status = eHAL_STATUS_SUCCESS;
6841 pMac->scan.nIdleScanTimeGap = 0;
6842 }
6843 }
6844 else
6845 {
6846 //requested so let's reset the value
6847 pMac->scan.nIdleScanTimeGap = 0;
6848 }
6849 }
6850
6851 return (status);
6852}
6853
6854
6855eHalStatus csrScanStartIdleScan(tpAniSirGlobal pMac)
6856{
6857 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
6858 tANI_U32 nTime = 0;
6859
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006860 smsLog(pMac, LOGW, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006861 if(pMac->roam.configParam.IsIdleScanEnabled)
6862 {
6863 //stop bg scan first
6864 csrScanBGScanAbort(pMac);
6865 //Stop get result timer because idle scan gets scan result out of PE
6866 csrScanStopGetResultTimer(pMac);
6867 //Enable aging timer since idle scan is going on
6868 csrScanStartResultAgingTimer(pMac);
6869 }
6870 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_FALSE;
6871 status = csrScanTriggerIdleScan(pMac, &nTime);
6872 if(!HAL_STATUS_SUCCESS(status))
6873 {
6874 csrScanStartIdleScanTimer(pMac, nTime);
6875 }
6876
6877 return (status);
6878}
6879
6880
6881void csrScanCancelIdleScan(tpAniSirGlobal pMac)
6882{
6883 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6884 {
Jeff Johnson295189b2012-06-20 16:38:30 -07006885 if (vos_concurrent_sessions_running()) {
6886 return;
6887 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006888 smsLog(pMac, LOG1, " csrScanCancelIdleScan");
Jeff Johnson295189b2012-06-20 16:38:30 -07006889 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_TRUE;
6890 //Set the restart flag in case later on it is uncancelled
6891 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6892 csrScanStopIdleScanTimer(pMac);
6893 csrScanRemoveNotRoamingScanCommand(pMac);
6894 }
6895}
6896
6897
6898void csrScanIdleScanTimerHandler(void *pv)
6899{
6900 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6901 eHalStatus status;
6902 tANI_U32 nTime = 0;
6903
6904 smsLog(pMac, LOGW, " csrScanIdleScanTimerHandler called ");
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07006905 pmcResetImpsFailStatus (pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07006906 status = csrScanTriggerIdleScan(pMac, &nTime);
6907 if(!HAL_STATUS_SUCCESS(status) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan))
6908 {
6909 //Check whether it is time to actually do an idle scan
6910 if(pMac->scan.nIdleScanTimeGap >= pMac->roam.configParam.impsSleepTime)
6911 {
6912 pMac->scan.nIdleScanTimeGap = 0;
6913 csrScanIMPSCallback(pMac, eHAL_STATUS_SUCCESS);
6914 }
6915 else
6916 {
6917 csrScanStartIdleScanTimer(pMac, nTime);
6918 }
6919 }
6920}
6921
6922
6923
6924
6925tANI_BOOLEAN csrScanRemoveNotRoamingScanCommand(tpAniSirGlobal pMac)
6926{
6927 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
6928 tListElem *pEntry, *pEntryTmp;
6929 tSmeCmd *pCommand;
6930 tDblLinkList localList;
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306931 tDblLinkList *pCmdList;
Jeff Johnson295189b2012-06-20 16:38:30 -07006932
6933 vos_mem_zero(&localList, sizeof(tDblLinkList));
6934 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
6935 {
6936 smsLog(pMac, LOGE, FL(" failed to open list"));
6937 return fRet;
6938 }
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306939 if (!pMac->fScanOffload)
6940 pCmdList = &pMac->sme.smeCmdPendingList;
6941 else
6942 pCmdList = &pMac->sme.smeScanCmdPendingList;
Jeff Johnson295189b2012-06-20 16:38:30 -07006943
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306944 csrLLLock(pCmdList);
6945 pEntry = csrLLPeekHead(pCmdList, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07006946 while(pEntry)
6947 {
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306948 pEntryTmp = csrLLNext(pCmdList, pEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07006949 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6950 if( eSmeCommandScan == pCommand->command )
6951 {
6952 switch( pCommand->u.scanCmd.reason )
6953 {
6954 case eCsrScanIdleScan:
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306955 if( csrLLRemoveEntry(pCmdList, pEntry, LL_ACCESS_NOLOCK) )
Jeff Johnson295189b2012-06-20 16:38:30 -07006956 {
6957 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
6958 }
6959 fRet = eANI_BOOLEAN_TRUE;
6960 break;
6961
6962 default:
6963 break;
6964 } //switch
6965 }
6966 pEntry = pEntryTmp;
6967 }
6968
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306969 csrLLUnlock(pCmdList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006970
6971 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
6972 {
6973 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6974 csrReleaseCommandScan( pMac, pCommand );
6975 }
6976
6977 csrLLClose(&localList);
6978
6979 return (fRet);
6980}
6981
6982
6983tANI_BOOLEAN csrScanRemoveFreshScanCommand(tpAniSirGlobal pMac, tANI_U8 sessionId)
6984{
6985 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
6986 tListElem *pEntry, *pEntryTmp;
6987 tSmeCmd *pCommand;
6988 tDblLinkList localList;
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306989 tDblLinkList *pCmdList;
Jeff Johnson295189b2012-06-20 16:38:30 -07006990
6991 vos_mem_zero(&localList, sizeof(tDblLinkList));
6992 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
6993 {
6994 smsLog(pMac, LOGE, FL(" failed to open list"));
6995 return fRet;
6996 }
6997
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306998 if (!pMac->fScanOffload)
6999 pCmdList = &pMac->sme.smeCmdPendingList;
7000 else
7001 pCmdList = &pMac->sme.smeScanCmdPendingList;
7002
7003 csrLLLock(pCmdList);
7004 pEntry = csrLLPeekHead(pCmdList, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007005 while(pEntry)
7006 {
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307007 pEntryTmp = csrLLNext(pCmdList, pEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07007008 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7009 if( (eSmeCommandScan == pCommand->command) && (sessionId == pCommand->sessionId) )
7010 {
7011 switch(pCommand->u.scanCmd.reason)
7012 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07007013#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
7014 case eCsrScanGetLfrResult:
7015#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07007016 case eCsrScanGetResult:
7017 case eCsrScanSetBGScanParam:
7018 case eCsrScanBGScanAbort:
7019 case eCsrScanBGScanEnable:
7020 case eCsrScanGetScanChnInfo:
7021 break;
7022 default:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007023 smsLog (pMac, LOGW, "%s: -------- abort scan command reason = %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007024 __func__, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07007025 //The rest are fresh scan requests
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307026 if( csrLLRemoveEntry(pCmdList, pEntry, LL_ACCESS_NOLOCK) )
Jeff Johnson295189b2012-06-20 16:38:30 -07007027 {
7028 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
7029 }
7030 fRet = eANI_BOOLEAN_TRUE;
7031 break;
7032 }
7033 }
7034 pEntry = pEntryTmp;
7035 }
7036
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307037 csrLLUnlock(pCmdList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007038
7039 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
7040 {
7041 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7042 if (pCommand->u.scanCmd.callback)
7043 {
7044 /* User scan request is pending,
7045 * send response with status eCSR_SCAN_ABORT*/
7046 pCommand->u.scanCmd.callback(pMac,
7047 pCommand->u.scanCmd.pContext,
7048 pCommand->u.scanCmd.scanID,
7049 eCSR_SCAN_ABORT);
7050 }
7051 csrReleaseCommandScan( pMac, pCommand );
7052 }
7053 csrLLClose(&localList);
7054
7055 return (fRet);
7056}
7057
7058
7059void csrReleaseScanCommand(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
7060{
7061 eCsrScanReason reason = pCommand->u.scanCmd.reason;
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307062 tANI_BOOLEAN status;
7063
7064 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07007065 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307066 tANI_U32 i;
7067 for(i = 0; i < CSR_ROAM_SESSION_MAX; i++)
7068 csrRoamStateChange(pMac, pCommand->u.scanCmd.lastRoamState[i], i);
7069 }
7070 else
7071 {
7072 csrRoamStateChange(pMac,
7073 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId],
7074 pCommand->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07007075 }
7076
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307077 csrScanCallCallback(pMac, pCommand, scanStatus);
Jeff Johnson295189b2012-06-20 16:38:30 -07007078
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007079 smsLog(pMac, LOG3, " Remove Scan command reason = %d", reason);
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307080 if (pMac->fScanOffload)
7081 {
7082 status = csrLLRemoveEntry(&pMac->sme.smeScanCmdActiveList,
7083 &pCommand->Link, LL_ACCESS_LOCK);
7084 }
7085 else
7086 {
7087 status = csrLLRemoveEntry(&pMac->sme.smeCmdActiveList,
7088 &pCommand->Link, LL_ACCESS_LOCK);
7089 }
7090
7091 if(status)
Jeff Johnson295189b2012-06-20 16:38:30 -07007092 {
7093 csrReleaseCommandScan( pMac, pCommand );
7094 }
7095 else
7096 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05307097 smsLog(pMac, LOGE,
7098 " ********csrReleaseScanCommand cannot release command reason %d",
7099 pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07007100 }
7101}
7102
7103
7104eHalStatus csrScanGetPMKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
7105 tPmkidCandidateInfo *pPmkidList, tANI_U32 *pNumItems )
7106{
7107 eHalStatus status = eHAL_STATUS_SUCCESS;
7108 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
7109
Jeff Johnson32d95a32012-09-10 13:15:23 -07007110 if(!pSession)
7111 {
7112 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
7113 return eHAL_STATUS_FAILURE;
7114 }
7115
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007116 smsLog(pMac, LOGW, " pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07007117 csrResetPMKIDCandidateList(pMac, sessionId);
7118 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
7119 {
7120 tCsrScanResultFilter *pScanFilter;
7121 tCsrScanResultInfo *pScanResult;
7122 tScanResultHandle hBSSList;
7123 tANI_U32 nItems = *pNumItems;
7124
7125 *pNumItems = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05307126 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
7127 if ( NULL == pScanFilter )
7128 status = eHAL_STATUS_FAILURE;
7129 else
Jeff Johnson295189b2012-06-20 16:38:30 -07007130 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307131 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007132 //Here is the profile we need to connect to
7133 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
7134 if(HAL_STATUS_SUCCESS(status))
7135 {
7136 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
7137 if(HAL_STATUS_SUCCESS(status))
7138 {
7139 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumPmkidCandidate < nItems))
7140 {
7141 //NumPmkidCandidate adds up here
7142 csrProcessBSSDescForPMKIDList(pMac, &pScanResult->BssDescriptor,
7143 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
7144 }
7145 if(pSession->NumPmkidCandidate)
7146 {
7147 *pNumItems = pSession->NumPmkidCandidate;
Kiet Lam64c1b492013-07-12 13:56:44 +05307148 vos_mem_copy(pPmkidList, pSession->PmkidCandidateInfo,
7149 pSession->NumPmkidCandidate * sizeof(tPmkidCandidateInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07007150 }
7151 csrScanResultPurge(pMac, hBSSList);
7152 }//Have scan result
7153 csrFreeScanFilter(pMac, pScanFilter);
7154 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307155 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07007156 }
7157 }
7158
7159 return (status);
7160}
7161
7162
7163
7164#ifdef FEATURE_WLAN_WAPI
7165eHalStatus csrScanGetBKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
7166 tBkidCandidateInfo *pBkidList, tANI_U32 *pNumItems )
7167{
7168 eHalStatus status = eHAL_STATUS_SUCCESS;
7169 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
7170
Jeff Johnson32d95a32012-09-10 13:15:23 -07007171 if(!pSession)
7172 {
7173 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
7174 return eHAL_STATUS_FAILURE;
7175 }
7176
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007177 smsLog(pMac, LOGW, " pMac->scan.NumBkidCandidate = %d", pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07007178 csrResetBKIDCandidateList(pMac, sessionId);
7179 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
7180 {
7181 tCsrScanResultFilter *pScanFilter;
7182 tCsrScanResultInfo *pScanResult;
7183 tScanResultHandle hBSSList;
7184 tANI_U32 nItems = *pNumItems;
7185 *pNumItems = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05307186 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
7187 if ( NULL == pScanFilter )
7188 status = eHAL_STATUS_FAILURE;
7189 else
Jeff Johnson295189b2012-06-20 16:38:30 -07007190 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307191 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007192 //Here is the profile we need to connect to
7193 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
7194 if(HAL_STATUS_SUCCESS(status))
7195 {
7196 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
7197 if(HAL_STATUS_SUCCESS(status))
7198 {
7199 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumBkidCandidate < nItems))
7200 {
7201 //pMac->scan.NumBkidCandidate adds up here
7202 csrProcessBSSDescForBKIDList(pMac, &pScanResult->BssDescriptor,
7203 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
7204
7205 }
7206 if(pSession->NumBkidCandidate)
7207 {
7208 *pNumItems = pSession->NumBkidCandidate;
Kiet Lam64c1b492013-07-12 13:56:44 +05307209 vos_mem_copy(pBkidList, pSession->BkidCandidateInfo, pSession->NumBkidCandidate * sizeof(tBkidCandidateInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07007210 }
7211 csrScanResultPurge(pMac, hBSSList);
7212 }//Have scan result
7213 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307214 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07007215 }
7216 }
7217
7218 return (status);
7219}
7220#endif /* FEATURE_WLAN_WAPI */
7221
7222
7223
7224//This function is usually used for BSSs that suppresses SSID so the profile
7225//shall have one and only one SSID
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007226eHalStatus csrScanForSSID(tpAniSirGlobal pMac, tANI_U32 sessionId, tCsrRoamProfile *pProfile, tANI_U32 roamId, tANI_BOOLEAN notify)
Jeff Johnson295189b2012-06-20 16:38:30 -07007227{
7228 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
7229 tSmeCmd *pScanCmd = NULL;
7230 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
7231 tANI_U8 index = 0;
7232 tANI_U32 numSsid = pProfile->SSIDs.numOfSSIDs;
7233
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007234 smsLog(pMac, LOG2, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007235 //For WDS, we use the index 0. There must be at least one in there
7236 if( CSR_IS_WDS_STA( pProfile ) && numSsid )
7237 {
7238 numSsid = 1;
7239 }
7240 if(pMac->scan.fScanEnable && ( numSsid == 1 ) )
7241 {
7242 do
7243 {
7244 pScanCmd = csrGetCommandBuffer(pMac);
7245 if(!pScanCmd)
7246 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007247 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007248 break;
7249 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307250 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
7251 pScanCmd->u.scanCmd.pToRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
7252 if ( NULL == pScanCmd->u.scanCmd.pToRoamProfile )
krunal soni587bf012014-02-04 12:35:11 -08007253 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307254 status = eHAL_STATUS_FAILURE;
krunal soni587bf012014-02-04 12:35:11 -08007255 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307256 else
krunal soni587bf012014-02-04 12:35:11 -08007257 {
7258 status = csrRoamCopyProfile(pMac, pScanCmd->u.scanCmd.pToRoamProfile, pProfile);
7259 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007260 if(!HAL_STATUS_SUCCESS(status))
7261 break;
7262 pScanCmd->u.scanCmd.roamId = roamId;
7263 pScanCmd->command = eSmeCommandScan;
Jeff Johnsone7245742012-09-05 17:12:55 -07007264 pScanCmd->sessionId = (tANI_U8)sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07007265 pScanCmd->u.scanCmd.callback = NULL;
7266 pScanCmd->u.scanCmd.pContext = NULL;
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007267 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 -07007268 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Kiet Lam64c1b492013-07-12 13:56:44 +05307269 vos_mem_set(&pScanCmd->u.scanCmd.u.scanRequest, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007270 pScanCmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Jeff Johnson295189b2012-06-20 16:38:30 -07007271 pScanCmd->u.scanCmd.u.scanRequest.BSSType = pProfile->BSSType;
Jeff Johnsone7245742012-09-05 17:12:55 -07007272 // To avoid 11b rate in probe request Set p2pSearch flag as 1 for P2P Client Mode
7273 if(VOS_P2P_CLIENT_MODE == pProfile->csrPersona)
7274 {
7275 pScanCmd->u.scanCmd.u.scanRequest.p2pSearch = 1;
7276 }
Agarwal Ashish4f616132013-12-30 23:32:50 +05307277 if(pProfile->nAddIEScanLength)
Jeff Johnsone7245742012-09-05 17:12:55 -07007278 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307279 pScanCmd->u.scanCmd.u.scanRequest.pIEField = vos_mem_malloc(
7280 pProfile->nAddIEScanLength);
7281 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.pIEField )
7282 status = eHAL_STATUS_FAILURE;
7283 else
7284 status = eHAL_STATUS_SUCCESS;
7285 vos_mem_set(pScanCmd->u.scanCmd.u.scanRequest.pIEField,
7286 pProfile->nAddIEScanLength, 0);
7287 if (HAL_STATUS_SUCCESS(status))
Jeff Johnsone7245742012-09-05 17:12:55 -07007288 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307289 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.pIEField,
Agarwal Ashish4f616132013-12-30 23:32:50 +05307290 pProfile->addIEScan, pProfile->nAddIEScanLength);
Jeff Johnsone7245742012-09-05 17:12:55 -07007291 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = pProfile->nAddIEScanLength;
7292 }
7293 else
7294 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007295 smsLog(pMac, LOGE, "No memory for scanning IE fields");
Jeff Johnsone7245742012-09-05 17:12:55 -07007296 }
7297 } //Allocate memory for IE field
7298 else
7299 {
7300 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = 0;
7301 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07007302 /* For one channel be good enpugh time to receive beacon atleast */
7303 if( 1 == pProfile->ChannelInfo.numOfChannels )
7304 {
7305 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime = MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7306 pScanCmd->u.scanCmd.u.scanRequest.minChnTime = MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7307 }
7308 else
7309 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307310 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime =
7311 pMac->roam.configParam.nActiveMaxChnTime;
7312 pScanCmd->u.scanCmd.u.scanRequest.minChnTime =
7313 pMac->roam.configParam.nActiveMinChnTime;
Jeff Johnson32d95a32012-09-10 13:15:23 -07007314 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307315 pScanCmd->u.scanCmd.u.scanRequest.maxChnTimeBtc =
7316 pMac->roam.configParam.nActiveMaxChnTimeBtc;
7317 pScanCmd->u.scanCmd.u.scanRequest.minChnTimeBtc =
7318 pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07007319 if(pProfile->BSSIDs.numOfBSSIDs == 1)
7320 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307321 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.bssid,
7322 pProfile->BSSIDs.bssid, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07007323 }
7324 else
7325 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307326 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.bssid, bAddr, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07007327 }
7328 if(pProfile->ChannelInfo.numOfChannels)
7329 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307330 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(
7331 sizeof(*pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
7332 * pProfile->ChannelInfo.numOfChannels);
7333 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
7334 status = eHAL_STATUS_FAILURE;
7335 else
7336 status = eHAL_STATUS_SUCCESS;
7337 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
7338 if(HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07007339 {
7340 csrRoamIsChannelValid(pMac, pProfile->ChannelInfo.ChannelList[0]);
7341 for(index = 0; index < pProfile->ChannelInfo.numOfChannels; index++)
7342 {
7343 if(csrRoamIsValidChannel(pMac, pProfile->ChannelInfo.ChannelList[index]))
7344 {
7345 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels]
7346 = pProfile->ChannelInfo.ChannelList[index];
7347 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels++;
7348 }
7349 else
7350 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007351 smsLog(pMac, LOGW, FL("process a channel (%d) that is invalid"), pProfile->ChannelInfo.ChannelList[index]);
Jeff Johnson295189b2012-06-20 16:38:30 -07007352 }
7353
7354 }
7355 }
7356 else
7357 {
7358 break;
7359 }
7360
7361 }
7362 else
7363 {
7364 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
7365 }
7366 if(pProfile->SSIDs.numOfSSIDs)
7367 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307368 pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList = vos_mem_malloc(
7369 pProfile->SSIDs.numOfSSIDs * sizeof(tCsrSSIDInfo));
7370 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList )
7371 status = eHAL_STATUS_FAILURE;
7372 else
7373 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07007374 if(!HAL_STATUS_SUCCESS(status))
7375 {
7376 break;
7377 }
7378 pScanCmd->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 1;
Kiet Lam64c1b492013-07-12 13:56:44 +05307379 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList,
7380 pProfile->SSIDs.SSIDList, sizeof(tCsrSSIDInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07007381 }
7382 //Start process the command
7383 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
7384 if( !HAL_STATUS_SUCCESS( status ) )
7385 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007386 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07007387 break;
7388 }
7389 }while(0);
7390 if(!HAL_STATUS_SUCCESS(status))
7391 {
7392 if(pScanCmd)
7393 {
7394 csrReleaseCommandScan(pMac, pScanCmd);
7395 //TODO:free the memory that is allocated in this function
7396 }
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007397 if(notify)
7398 {
Jeff Johnson295189b2012-06-20 16:38:30 -07007399 csrRoamCallCallback(pMac, sessionId, NULL, roamId, eCSR_ROAM_FAILED, eCSR_ROAM_RESULT_FAILURE);
7400 }
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007401 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007402 }//valid
7403 else
7404 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007405 smsLog(pMac, LOGE, FL("cannot scan because scanEnable (%d) or numSSID (%d) is invalid"),
Jeff Johnson295189b2012-06-20 16:38:30 -07007406 pMac->scan.fScanEnable, pProfile->SSIDs.numOfSSIDs);
7407 }
7408
7409 return (status);
7410}
7411
7412
7413//Issue a scan base on the new capability infomation
7414//This should only happen when the associated AP changes its capability.
7415//After this scan is done, CSR reroams base on the new scan results
7416eHalStatus csrScanForCapabilityChange(tpAniSirGlobal pMac, tSirSmeApNewCaps *pNewCaps)
7417{
7418 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
7419 tSmeCmd *pScanCmd = NULL;
7420
7421 if(pNewCaps)
7422 {
7423 do
7424 {
7425 pScanCmd = csrGetCommandBuffer(pMac);
7426 if(!pScanCmd)
7427 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007428 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007429 status = eHAL_STATUS_RESOURCES;
7430 break;
7431 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307432 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007433 status = eHAL_STATUS_SUCCESS;
7434 pScanCmd->u.scanCmd.roamId = 0;
7435 pScanCmd->command = eSmeCommandScan;
7436 pScanCmd->u.scanCmd.callback = NULL;
7437 pScanCmd->u.scanCmd.pContext = NULL;
7438 pScanCmd->u.scanCmd.reason = eCsrScanForCapsChange;
7439 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
7440 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
7441 if( !HAL_STATUS_SUCCESS( status ) )
7442 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007443 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07007444 break;
7445 }
7446 }while(0);
7447 if(!HAL_STATUS_SUCCESS(status))
7448 {
7449 if(pScanCmd)
7450 {
7451 csrReleaseCommandScan(pMac, pScanCmd);
7452 }
7453 }
7454 }
7455
7456 return (status);
7457}
7458
7459
7460
7461void csrInitBGScanChannelList(tpAniSirGlobal pMac)
7462{
7463 tANI_U32 len = CSR_MIN(sizeof(pMac->roam.validChannelList), sizeof(pMac->scan.bgScanChannelList));
7464
Kiet Lam64c1b492013-07-12 13:56:44 +05307465 vos_mem_set(pMac->scan.bgScanChannelList, len, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007466 pMac->scan.numBGScanChannel = 0;
7467
7468 if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
7469 {
7470 pMac->roam.numValidChannels = len;
7471 pMac->scan.numBGScanChannel = (tANI_U8)CSR_MIN(len, WNI_CFG_BG_SCAN_CHANNEL_LIST_LEN);
Kiet Lam64c1b492013-07-12 13:56:44 +05307472 vos_mem_copy(pMac->scan.bgScanChannelList, pMac->roam.validChannelList,
7473 pMac->scan.numBGScanChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07007474 csrSetBGScanChannelList(pMac, pMac->scan.bgScanChannelList, pMac->scan.numBGScanChannel);
7475 }
7476}
7477
7478
7479//This function return TRUE if background scan channel list is adjusted.
7480//this function will only shrink the background scan channel list
7481tANI_BOOLEAN csrAdjustBGScanChannelList(tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels,
7482 tANI_U8 *pAdjustChannels, tANI_U8 *pNumAdjustChannels)
7483{
7484 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
7485 tANI_U8 i, j, count = *pNumAdjustChannels;
7486
7487 i = 0;
7488 while(i < count)
7489 {
7490 for(j = 0; j < NumChannels; j++)
7491 {
7492 if(pChannelList[j] == pAdjustChannels[i])
7493 break;
7494 }
7495 if(j == NumChannels)
7496 {
7497 //This channel is not in the list, remove it
7498 fRet = eANI_BOOLEAN_TRUE;
7499 count--;
7500 if(count - i)
7501 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307502 vos_mem_copy(&pAdjustChannels[i], &pAdjustChannels[i+1], count - i);
Jeff Johnson295189b2012-06-20 16:38:30 -07007503 }
7504 else
7505 {
7506 //already remove the last one. Done.
7507 break;
7508 }
7509 }
7510 else
7511 {
7512 i++;
7513 }
7514 }//while(i<count)
7515 *pNumAdjustChannels = count;
7516
7517 return (fRet);
7518}
7519
7520
7521//Get the list of the base channels to scan for passively 11d info
7522eHalStatus csrScanGetSupportedChannels( tpAniSirGlobal pMac )
7523{
7524 eHalStatus status = eHAL_STATUS_SUCCESS;
7525 int n = WNI_CFG_VALID_CHANNEL_LIST_LEN;
7526
7527 status = vos_nv_getSupportedChannels( pMac->scan.baseChannels.channelList, &n, NULL, NULL );
7528 if( HAL_STATUS_SUCCESS(status) )
7529 {
7530 pMac->scan.baseChannels.numChannels = (tANI_U8)n;
7531 }
7532 else
7533 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007534 smsLog( pMac, LOGE, FL(" failed") );
Jeff Johnson295189b2012-06-20 16:38:30 -07007535 pMac->scan.baseChannels.numChannels = 0;
7536 }
7537
7538 return ( status );
7539}
7540
7541//This function use the input pChannelList to validate the current saved channel list
7542eHalStatus csrSetBGScanChannelList( tpAniSirGlobal pMac, tANI_U8 *pAdjustChannels, tANI_U8 NumAdjustChannels)
7543{
7544 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumAdjustChannels;
7545
7546 return (ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pAdjustChannels, dataLen, NULL, eANI_BOOLEAN_FALSE));
7547}
7548
7549
7550void csrSetCfgValidChannelList( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels )
7551{
7552 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumChannels;
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05307553 eHalStatus status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007554
7555 ccmCfgSetStr(pMac, WNI_CFG_VALID_CHANNEL_LIST, pChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
Leela Venkata Kiran Kumar Reddy Chiralac6663f72014-02-03 21:04:58 -08007556#ifdef QCA_WIFI_2_0
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05307557 if (pMac->fScanOffload)
7558 {
7559 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
7560 "Scan offload is enabled, update default chan list");
Leela Venkata Kiran Kumar Reddy Chiralac6663f72014-02-03 21:04:58 -08007561 status = csrUpdateChannelList(pMac);
7562 }
7563#else
7564 status = csrUpdateChannelList(pMac);
7565#endif
7566
7567 if (eHAL_STATUS_SUCCESS != status)
7568 {
7569 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR,
7570 "failed to update the supported channel list");
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05307571 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007572 return;
7573}
7574
7575
7576
7577/*
7578 * The Tx power limits are saved in the cfg for future usage.
7579 */
7580void csrSaveTxPowerToCfg( tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 cfgId )
7581{
7582 tListElem *pEntry;
7583 tANI_U32 cbLen = 0, dataLen;
7584 tCsrChannelPowerInfo *pChannelSet;
7585 tANI_U32 idx;
7586 tSirMacChanInfo *pChannelPowerSet;
7587 tANI_U8 *pBuf = NULL;
7588
7589 //allocate maximum space for all channels
7590 dataLen = WNI_CFG_VALID_CHANNEL_LIST_LEN * sizeof(tSirMacChanInfo);
Kiet Lam64c1b492013-07-12 13:56:44 +05307591 if ( (pBuf = vos_mem_malloc(dataLen)) != NULL )
Jeff Johnson295189b2012-06-20 16:38:30 -07007592 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307593 vos_mem_set(pBuf, dataLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007594 pChannelPowerSet = (tSirMacChanInfo *)(pBuf);
7595
7596 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
7597 // write the tuples (startChan, numChan, txPower) for each channel found in the channel power list.
7598 while( pEntry )
7599 {
7600 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
7601 if ( 1 != pChannelSet->interChannelOffset )
7602 {
7603 // we keep the 5G channel sets internally with an interchannel offset of 4. Expand these
7604 // to the right format... (inter channel offset of 1 is the only option for the triplets
7605 // that 11d advertises.
7606 if ((cbLen + (pChannelSet->numChannels * sizeof(tSirMacChanInfo))) >= dataLen)
7607 {
7608 // expanding this entry will overflow our allocation
7609 smsLog(pMac, LOGE,
7610 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007611 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07007612 pChannelSet->firstChannel,
7613 pChannelSet->numChannels,
7614 pChannelSet->interChannelOffset);
7615 break;
7616 }
7617
7618 for( idx = 0; idx < pChannelSet->numChannels; idx++ )
7619 {
7620 pChannelPowerSet->firstChanNum = (tSirMacChanNum)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007621 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07007622 pChannelPowerSet->numChannels = 1;
Jeff Johnson295189b2012-06-20 16:38:30 -07007623 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007624 smsLog(pMac, LOG3, " Setting Max Transmit Power %d", pChannelPowerSet->maxTxPower);
Jeff Johnson295189b2012-06-20 16:38:30 -07007625 cbLen += sizeof( tSirMacChanInfo );
7626 pChannelPowerSet++;
7627 }
7628 }
7629 else
7630 {
7631 if (cbLen >= dataLen)
7632 {
7633 // this entry will overflow our allocation
7634 smsLog(pMac, LOGE,
7635 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007636 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07007637 pChannelSet->firstChannel,
7638 pChannelSet->numChannels,
7639 pChannelSet->interChannelOffset);
7640 break;
7641 }
7642 pChannelPowerSet->firstChanNum = pChannelSet->firstChannel;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007643 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07007644 pChannelPowerSet->numChannels = pChannelSet->numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -07007645 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007646 smsLog(pMac, LOG3, " Setting Max Transmit Power %d, nTxPower %d", pChannelPowerSet->maxTxPower,pMac->roam.configParam.nTxPowerCap );
Jeff Johnson295189b2012-06-20 16:38:30 -07007647
7648
7649 cbLen += sizeof( tSirMacChanInfo );
7650 pChannelPowerSet++;
7651 }
7652
7653 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
7654 }
7655
7656 if(cbLen)
7657 {
7658 ccmCfgSetStr(pMac, cfgId, (tANI_U8 *)pBuf, cbLen, NULL, eANI_BOOLEAN_FALSE);
7659 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307660 vos_mem_free(pBuf);
Jeff Johnson295189b2012-06-20 16:38:30 -07007661 }//Allocate memory
7662}
7663
7664
7665void csrSetCfgCountryCode( tpAniSirGlobal pMac, tANI_U8 *countryCode )
7666{
7667 tANI_U8 cc[WNI_CFG_COUNTRY_CODE_LEN];
7668 ///v_REGDOMAIN_t DomainId;
7669
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007670 smsLog( pMac, LOG3, "Setting Country Code in Cfg from csrSetCfgCountryCode %s",countryCode );
Kiet Lam64c1b492013-07-12 13:56:44 +05307671 vos_mem_copy(cc, countryCode, WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07007672
7673 // don't program the bogus country codes that we created for Korea in the MAC. if we see
7674 // the bogus country codes, program the MAC with the right country code.
7675 if ( ( 'K' == countryCode[ 0 ] && '1' == countryCode[ 1 ] ) ||
7676 ( 'K' == countryCode[ 0 ] && '2' == countryCode[ 1 ] ) ||
7677 ( 'K' == countryCode[ 0 ] && '3' == countryCode[ 1 ] ) ||
7678 ( 'K' == countryCode[ 0 ] && '4' == countryCode[ 1 ] ) )
7679 {
7680 // replace the alternate Korea country codes, 'K1', 'K2', .. with 'KR' for Korea
7681 cc[ 1 ] = 'R';
7682 }
7683 ccmCfgSetStr(pMac, WNI_CFG_COUNTRY_CODE, cc, WNI_CFG_COUNTRY_CODE_LEN, NULL, eANI_BOOLEAN_FALSE);
7684
7685 //Need to let HALPHY know about the current domain so it can apply some
7686 //domain-specific settings (TX filter...)
7687 /*if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(pMac, cc, &DomainId)))
7688 {
7689 halPhySetRegDomain(pMac, DomainId);
7690 }*/
7691}
7692
7693
7694
7695eHalStatus csrGetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pBuf, tANI_U8 *pbLen)
7696{
7697 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
7698 tANI_U32 len;
7699
7700 if(pBuf && pbLen && (*pbLen >= WNI_CFG_COUNTRY_CODE_LEN))
7701 {
7702 len = *pbLen;
7703 status = ccmCfgGetStr(pMac, WNI_CFG_COUNTRY_CODE, pBuf, &len);
7704 if(HAL_STATUS_SUCCESS(status))
7705 {
7706 *pbLen = (tANI_U8)len;
7707 }
7708 }
7709
7710 return (status);
7711}
7712
7713
7714void csrSetCfgScanControlList( tpAniSirGlobal pMac, tANI_U8 *countryCode, tCsrChannel *pChannelList )
7715{
7716 tANI_U8 i, j;
7717 tANI_BOOLEAN found=FALSE;
7718 tANI_U8 *pControlList = NULL;
7719 tANI_U32 len = WNI_CFG_SCAN_CONTROL_LIST_LEN;
7720
Kiet Lam64c1b492013-07-12 13:56:44 +05307721 if ( (pControlList = vos_mem_malloc(WNI_CFG_SCAN_CONTROL_LIST_LEN)) != NULL )
Jeff Johnson295189b2012-06-20 16:38:30 -07007722 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307723 vos_mem_set((void *)pControlList, WNI_CFG_SCAN_CONTROL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007724 if(HAL_STATUS_SUCCESS(ccmCfgGetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, &len)))
7725 {
7726 for (i = 0; i < pChannelList->numChannels; i++)
7727 {
7728 for (j = 0; j < len; j += 2)
7729 {
7730 if (pControlList[j] == pChannelList->channelList[i])
7731 {
7732 found = TRUE;
7733 break;
7734 }
7735 }
7736
7737 if (found) // insert a pair(channel#, flag)
7738 {
Gopichand Nakkala392cbc12013-05-28 16:15:00 +05307739 pControlList[j+1] = csrGetScanType(pMac, pControlList[j]);
Jeff Johnson295189b2012-06-20 16:38:30 -07007740 found = FALSE; // reset the flag
7741 }
7742
7743 }
7744
7745 ccmCfgSetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, len, NULL, eANI_BOOLEAN_FALSE);
7746 }//Successfully getting scan control list
Kiet Lam64c1b492013-07-12 13:56:44 +05307747 vos_mem_free(pControlList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007748 }//AllocateMemory
7749}
7750
7751
7752//if bgPeriod is 0, background scan is disabled. It is in millisecond units
7753eHalStatus csrSetCfgBackgroundScanPeriod(tpAniSirGlobal pMac, tANI_U32 bgPeriod)
7754{
7755 return (ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, bgPeriod, (tCcmCfgSetCallback) csrScanCcmCfgSetCallback, eANI_BOOLEAN_FALSE));
7756}
7757
7758
7759void csrScanCcmCfgSetCallback(tHalHandle hHal, tANI_S32 result)
7760{
7761 tListElem *pEntry = NULL;
7762 tSmeCmd *pCommand = NULL;
7763 tpAniSirGlobal pMac = PMAC_STRUCT( hHal );
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307764 tDblLinkList *pCmdList ;
7765
7766 if (!pMac->fScanOffload)
7767 pCmdList = &pMac->sme.smeCmdActiveList;
7768 else
7769 pCmdList = &pMac->sme.smeScanCmdActiveList;
7770
7771 pEntry = csrLLPeekHead( pCmdList, LL_ACCESS_LOCK );
Jeff Johnson295189b2012-06-20 16:38:30 -07007772 if ( pEntry )
7773 {
7774 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7775 if ( eSmeCommandScan == pCommand->command )
7776 {
7777 eCsrScanStatus scanStatus = (CCM_IS_RESULT_SUCCESS(result)) ? eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
7778 csrReleaseScanCommand(pMac, pCommand, scanStatus);
7779 }
7780 else
7781 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007782 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
Jeff Johnson295189b2012-06-20 16:38:30 -07007783 }
7784 }
7785 smeProcessPendingQueue( pMac );
7786}
7787
7788eHalStatus csrProcessSetBGScanParam(tpAniSirGlobal pMac, tSmeCmd *pCommand)
7789{
7790 eHalStatus status;
7791 tCsrBGScanRequest *pScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
7792 tANI_U32 dataLen = sizeof( tANI_U8 ) * pScanReq->ChannelInfo.numOfChannels;
7793
7794 //***setcfg for background scan channel list
7795 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MINIMUM_CHANNEL_TIME, pScanReq->minChnTime, NULL, eANI_BOOLEAN_FALSE);
7796 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MAXIMUM_CHANNEL_TIME, pScanReq->maxChnTime, NULL, eANI_BOOLEAN_FALSE);
7797 //Not set the background scan interval if not connected because bd scan should not be run if not connected
7798 if(!csrIsAllSessionDisconnected(pMac))
7799 {
7800 //If disbaling BG scan here, we need to stop aging as well
7801 if(pScanReq->scanInterval == 0)
7802 {
7803 //Stop aging because no new result is coming in
7804 csrScanStopResultAgingTimer(pMac);
7805 }
7806
7807#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
7808 {
7809 vos_log_scan_pkt_type *pScanLog = NULL;
7810
7811 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
7812 if(pScanLog)
7813 {
7814 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
7815 pScanLog->minChnTime = (v_U8_t)pScanReq->minChnTime;
7816 pScanLog->maxChnTime = (v_U8_t)pScanReq->maxChnTime;
7817 pScanLog->timeBetweenBgScan = (v_U8_t)pScanReq->scanInterval;
7818 pScanLog->numChannel = pScanReq->ChannelInfo.numOfChannels;
7819 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
7820 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307821 vos_mem_copy(pScanLog->channels,
7822 pScanReq->ChannelInfo.ChannelList,
7823 pScanLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07007824 }
7825 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
7826 }
7827 }
7828#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
7829
7830 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, pScanReq->scanInterval, NULL, eANI_BOOLEAN_FALSE);
7831 }
7832 else
7833 {
7834 //No need to stop aging because IDLE scan is still running
7835 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, 0, NULL, eANI_BOOLEAN_FALSE);
7836 }
7837
7838 if(pScanReq->SSID.length > WNI_CFG_SSID_LEN)
7839 {
7840 pScanReq->SSID.length = WNI_CFG_SSID_LEN;
7841 }
7842
7843 status = ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pScanReq->ChannelInfo.ChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
7844 status = ccmCfgSetStr(pMac, WNI_CFG_SSID, (tANI_U8 *)pScanReq->SSID.ssId, pScanReq->SSID.length, NULL, eANI_BOOLEAN_FALSE);
7845
7846
7847
7848 return (status);
7849}
7850
7851
Srinivas, Dasari138af4f2014-02-07 11:13:45 +05307852eHalStatus csrScanAbortMacScan(tpAniSirGlobal pMac, tANI_U8 sessionId,
7853 eCsrAbortReason reason)
Jeff Johnson295189b2012-06-20 16:38:30 -07007854{
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307855 eHalStatus status = eHAL_STATUS_FAILURE;
7856 tSirSmeScanAbortReq *pMsg;
Jeff Johnson295189b2012-06-20 16:38:30 -07007857 tANI_U16 msgLen;
7858 tListElem *pEntry;
7859 tSmeCmd *pCommand;
7860
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307861 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07007862 {
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307863#ifdef WLAN_AP_STA_CONCURRENCY
7864 csrLLLock(&pMac->scan.scanCmdPendingList);
7865 while(NULL !=
7866 (pEntry = csrLLRemoveHead(&pMac->scan.scanCmdPendingList,
7867 LL_ACCESS_NOLOCK)))
7868 {
Jeff Johnson295189b2012-06-20 16:38:30 -07007869
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307870 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7871 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
7872 }
7873 csrLLUnlock(&pMac->scan.scanCmdPendingList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007874#endif
7875
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307876 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
7877 csrRemoveCmdFromPendingList( pMac, &pMac->roam.roamCmdPendingList, eSmeCommandScan);
7878 csrRemoveCmdFromPendingList( pMac, &pMac->sme.smeCmdPendingList, eSmeCommandScan);
7879 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
7880
7881 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
7882 }
7883 else
7884 {
7885 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
7886 csrRemoveCmdWithSessionIdFromPendingList(pMac,
7887 sessionId,
7888 &pMac->sme.smeScanCmdPendingList,
7889 eSmeCommandScan);
7890 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
7891
7892 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
7893 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007894
7895 //We need to abort scan only if we are scanning
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307896 if(NULL != pEntry)
Jeff Johnson295189b2012-06-20 16:38:30 -07007897 {
7898 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307899 if(eSmeCommandScan == pCommand->command &&
7900 pCommand->sessionId == sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07007901 {
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307902 msgLen = (tANI_U16)(sizeof(tSirSmeScanAbortReq));
Kiet Lam64c1b492013-07-12 13:56:44 +05307903 pMsg = vos_mem_malloc(msgLen);
7904 if ( NULL == pMsg )
Jeff Johnson295189b2012-06-20 16:38:30 -07007905 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307906 status = eHAL_STATUS_FAILURE;
7907 smsLog(pMac, LOGE, FL("Failed to allocate memory for SmeScanAbortReq"));
7908 }
7909 else
7910 {
Srinivas, Dasari187ca4e2014-02-07 12:40:09 +05307911 if(reason == eCSR_SCAN_ABORT_DUE_TO_BAND_CHANGE)
7912 {
7913 pCommand->u.scanCmd.abortScanDueToBandChange
7914 = eANI_BOOLEAN_TRUE;
7915 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307916 vos_mem_set((void *)pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007917 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_ABORT_IND);
7918 pMsg->msgLen = pal_cpu_to_be16(msgLen);
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307919 pMsg->sessionId = sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07007920 status = palSendMBMessage(pMac->hHdd, pMsg);
7921 }
7922 }
7923 }
7924
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307925 return(status);
7926}
7927
7928void csrRemoveCmdWithSessionIdFromPendingList(tpAniSirGlobal pMac,
7929 tANI_U8 sessionId,
7930 tDblLinkList *pList,
7931 eSmeCommandType commandType)
7932{
7933 tDblLinkList localList;
7934 tListElem *pEntry;
7935 tSmeCmd *pCommand;
7936 tListElem *pEntryToRemove;
7937
7938 vos_mem_zero(&localList, sizeof(tDblLinkList));
7939 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
7940 {
7941 smsLog(pMac, LOGE, FL(" failed to open list"));
7942 return;
7943 }
7944
7945 csrLLLock(pList);
7946 if ((pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK)))
7947 {
7948
7949 /* Have to make sure we don't loop back to the head of the list,
7950 * which will happen if the entry is NOT on the list */
7951 while (pEntry)
7952 {
7953 pEntryToRemove = pEntry;
7954 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
7955 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
7956 if ((pCommand->command == commandType) &&
7957 (pCommand->sessionId == sessionId))
7958 {
7959 /* Remove that entry only */
7960 if (csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
7961 {
7962 csrLLInsertTail(&localList, pEntryToRemove,
7963 LL_ACCESS_NOLOCK);
7964 }
7965 }
7966 }
7967 }
7968 csrLLUnlock(pList);
7969
7970 while ((pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)))
7971 {
7972 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7973 csrAbortCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
7974 }
7975
7976 csrLLClose(&localList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007977}
7978
7979void csrRemoveCmdFromPendingList(tpAniSirGlobal pMac, tDblLinkList *pList,
7980 eSmeCommandType commandType )
7981{
7982 tDblLinkList localList;
7983 tListElem *pEntry;
7984 tSmeCmd *pCommand;
7985 tListElem *pEntryToRemove;
7986
7987 vos_mem_zero(&localList, sizeof(tDblLinkList));
7988 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
7989 {
7990 smsLog(pMac, LOGE, FL(" failed to open list"));
7991 return;
7992 }
7993
7994 csrLLLock(pList);
7995 if( !csrLLIsListEmpty( pList, LL_ACCESS_NOLOCK ) )
7996 {
7997 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK);
7998
7999 // Have to make sure we don't loop back to the head of the list, which will
8000 // happen if the entry is NOT on the list...
8001 while( pEntry )
8002 {
8003 pEntryToRemove = pEntry;
8004 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
8005 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
8006 if ( pCommand->command == commandType )
8007 {
8008 // Remove that entry only
8009 if(csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
8010 {
8011 csrLLInsertTail(&localList, pEntryToRemove, LL_ACCESS_NOLOCK);
8012 }
8013 }
8014 }
8015
8016
8017 }
8018 csrLLUnlock(pList);
8019
8020 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
8021 {
8022 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
8023 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
8024 }
8025 csrLLClose(&localList);
8026
8027}
8028
8029
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05308030eHalStatus csrScanAbortMacScanNotForConnect(tpAniSirGlobal pMac,
8031 tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07008032{
8033 eHalStatus status = eHAL_STATUS_SUCCESS;
8034
8035 if( !csrIsScanForRoamCommandActive( pMac ) )
8036 {
8037 //Only abort the scan if it is not used for other roam/connect purpose
Srinivas, Dasari138af4f2014-02-07 11:13:45 +05308038 status = csrScanAbortMacScan(pMac, sessionId, eCSR_SCAN_ABORT_DEFAULT);
Jeff Johnson295189b2012-06-20 16:38:30 -07008039 }
8040
8041 return (status);
8042}
8043
8044
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05308045eHalStatus csrScanGetScanChannelInfo(tpAniSirGlobal pMac, tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07008046{
8047 eHalStatus status = eHAL_STATUS_SUCCESS;
8048 tSirMbMsg *pMsg;
8049 tANI_U16 msgLen;
8050
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05308051 if (pMac->fScanOffload)
8052 msgLen = (tANI_U16)(sizeof(tSirSmeGetScanChanReq));
8053 else
8054 msgLen = (tANI_U16)(sizeof(tSirMbMsg));
8055
Kiet Lam64c1b492013-07-12 13:56:44 +05308056 pMsg = vos_mem_malloc(msgLen);
8057 if ( NULL == pMsg )
8058 status = eHAL_STATUS_FAILURE;
8059 else
Jeff Johnson295189b2012-06-20 16:38:30 -07008060 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308061 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07008062 pMsg->type = eWNI_SME_GET_SCANNED_CHANNEL_REQ;
8063 pMsg->msgLen = msgLen;
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05308064 if (pMac->fScanOffload)
8065 ((tSirSmeGetScanChanReq *)pMsg)->sessionId = sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07008066 status = palSendMBMessage(pMac->hHdd, pMsg);
8067 }
8068
8069 return( status );
8070}
8071
8072tANI_BOOLEAN csrRoamIsValidChannel( tpAniSirGlobal pMac, tANI_U8 channel )
8073{
8074 tANI_BOOLEAN fValid = FALSE;
8075 tANI_U32 idxValidChannels;
8076 tANI_U32 len = pMac->roam.numValidChannels;
8077
8078 for ( idxValidChannels = 0; ( idxValidChannels < len ); idxValidChannels++ )
8079 {
8080 if ( channel == pMac->roam.validChannelList[ idxValidChannels ] )
8081 {
8082 fValid = TRUE;
8083 break;
8084 }
8085 }
8086
8087 return fValid;
8088}
8089
Manjunathappa Prakash4f1d5a52013-11-11 16:22:19 -08008090#ifdef FEATURE_WLAN_SCAN_PNO
Srikant Kuppa066904f2013-05-07 13:56:02 -07008091eHalStatus csrScanSavePreferredNetworkFound(tpAniSirGlobal pMac,
8092 tSirPrefNetworkFoundInd *pPrefNetworkFoundInd)
8093{
8094 v_U32_t uLen = 0;
8095 tpSirProbeRespBeacon pParsedFrame;
8096 tCsrScanResult *pScanResult = NULL;
8097 tSirBssDescription *pBssDescr = NULL;
8098 tANI_BOOLEAN fDupBss;
8099 tDot11fBeaconIEs *pIesLocal = NULL;
8100 tAniSSID tmpSsid;
8101 v_TIME_t timer=0;
8102 tpSirMacMgmtHdr macHeader = (tpSirMacMgmtHdr)pPrefNetworkFoundInd->data;
8103
8104 pParsedFrame =
Kiet Lam64c1b492013-07-12 13:56:44 +05308105 (tpSirProbeRespBeacon)vos_mem_malloc(sizeof(tSirProbeRespBeacon));
Srikant Kuppa066904f2013-05-07 13:56:02 -07008106
8107 if (NULL == pParsedFrame)
8108 {
8109 smsLog(pMac, LOGE, FL(" fail to allocate memory for frame"));
8110 return eHAL_STATUS_RESOURCES;
8111 }
8112
8113 if ( pPrefNetworkFoundInd->frameLength <= SIR_MAC_HDR_LEN_3A )
8114 {
8115 smsLog(pMac, LOGE,
8116 FL("Not enough bytes in PNO indication probe resp frame! length=%d"),
8117 pPrefNetworkFoundInd->frameLength);
8118 vos_mem_free(pParsedFrame);
8119 return eHAL_STATUS_FAILURE;
8120 }
8121
8122 if (sirConvertProbeFrame2Struct(pMac,
8123 &pPrefNetworkFoundInd->data[SIR_MAC_HDR_LEN_3A],
8124 pPrefNetworkFoundInd->frameLength - SIR_MAC_HDR_LEN_3A,
8125 pParsedFrame) != eSIR_SUCCESS ||
8126 !pParsedFrame->ssidPresent)
8127 {
8128 smsLog(pMac, LOGE,
8129 FL("Parse error ProbeResponse, length=%d"),
8130 pPrefNetworkFoundInd->frameLength);
8131 vos_mem_free(pParsedFrame);
8132 return eHAL_STATUS_FAILURE;
8133 }
8134 //24 byte MAC header and 12 byte to ssid IE
8135 if (pPrefNetworkFoundInd->frameLength >
8136 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET))
8137 {
8138 uLen = pPrefNetworkFoundInd->frameLength -
8139 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET);
8140 }
8141
Kiet Lam64c1b492013-07-12 13:56:44 +05308142 pScanResult = vos_mem_malloc(sizeof(tCsrScanResult) + uLen);
8143 if ( NULL == pScanResult )
Srikant Kuppa066904f2013-05-07 13:56:02 -07008144 {
8145 smsLog(pMac, LOGE, FL(" fail to allocate memory for frame"));
8146 vos_mem_free(pParsedFrame);
8147 return eHAL_STATUS_RESOURCES;
8148 }
8149
Kiet Lam64c1b492013-07-12 13:56:44 +05308150 vos_mem_set(pScanResult, sizeof(tCsrScanResult) + uLen, 0);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008151 pBssDescr = &pScanResult->Result.BssDescriptor;
8152 /**
8153 * Length of BSS desription is without length of
8154 * length itself and length of pointer
8155 * that holds the next BSS description
8156 */
8157 pBssDescr->length = (tANI_U16)(
8158 sizeof(tSirBssDescription) - sizeof(tANI_U16) -
8159 sizeof(tANI_U32) + uLen);
8160 if (pParsedFrame->dsParamsPresent)
8161 {
8162 pBssDescr->channelId = pParsedFrame->channelNumber;
8163 }
8164 else if (pParsedFrame->HTInfo.present)
8165 {
8166 pBssDescr->channelId = pParsedFrame->HTInfo.primaryChannel;
8167 }
8168 else
8169 {
8170 pBssDescr->channelId = pParsedFrame->channelNumber;
8171 }
8172
8173 if ((pBssDescr->channelId > 0) && (pBssDescr->channelId < 15))
8174 {
8175 int i;
8176 // 11b or 11g packet
8177 // 11g iff extended Rate IE is present or
8178 // if there is an A rate in suppRate IE
8179 for (i = 0; i < pParsedFrame->supportedRates.numRates; i++)
8180 {
8181 if (sirIsArate(pParsedFrame->supportedRates.rate[i] & 0x7f))
8182 {
8183 pBssDescr->nwType = eSIR_11G_NW_TYPE;
8184 break;
8185 }
8186 }
8187 if (pParsedFrame->extendedRatesPresent)
8188 {
8189 pBssDescr->nwType = eSIR_11G_NW_TYPE;
8190 }
8191 }
8192 else
8193 {
8194 // 11a packet
8195 pBssDescr->nwType = eSIR_11A_NW_TYPE;
8196 }
8197
8198 pBssDescr->sinr = 0;
8199 pBssDescr->rssi = -1 * pPrefNetworkFoundInd->rssi;
8200 pBssDescr->beaconInterval = pParsedFrame->beaconInterval;
8201 pBssDescr->timeStamp[0] = pParsedFrame->timeStamp[0];
8202 pBssDescr->timeStamp[1] = pParsedFrame->timeStamp[1];
8203 pBssDescr->capabilityInfo = *((tANI_U16 *)&pParsedFrame->capabilityInfo);
Kiet Lam64c1b492013-07-12 13:56:44 +05308204 vos_mem_copy((tANI_U8 *) &pBssDescr->bssId, (tANI_U8 *) macHeader->bssId, sizeof(tSirMacAddr));
Srikant Kuppa066904f2013-05-07 13:56:02 -07008205 pBssDescr->nReceivedTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
8206
Arif Hussain24bafea2013-11-15 15:10:03 -08008207 smsLog( pMac, LOG2, "(%s):Bssid= "MAC_ADDRESS_STR
8208 " chan= %d, rssi = %d", __func__,
8209 MAC_ADDR_ARRAY(pBssDescr->bssId),
Srikant Kuppa066904f2013-05-07 13:56:02 -07008210 pBssDescr->channelId,
8211 pBssDescr->rssi );
8212
8213 //IEs
8214 if (uLen)
8215 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308216 vos_mem_copy(&pBssDescr->ieFields,
8217 pPrefNetworkFoundInd->data + (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET),
8218 uLen);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008219 }
8220
8221 pIesLocal = (tDot11fBeaconIEs *)( pScanResult->Result.pvIes );
8222 if ( !pIesLocal &&
8223 (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
8224 &pScanResult->Result.BssDescriptor, &pIesLocal))) )
8225 {
8226 smsLog(pMac, LOGE, FL(" Cannot parse IEs"));
8227 csrFreeScanResultEntry(pMac, pScanResult);
8228 vos_mem_free(pParsedFrame);
8229 return eHAL_STATUS_RESOURCES;
8230 }
8231
8232 fDupBss = csrRemoveDupBssDescription( pMac,
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05308233 &pScanResult->Result.BssDescriptor, pIesLocal, &tmpSsid, &timer, FALSE);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008234 //Check whether we have reach out limit
8235 if ( CSR_SCAN_IS_OVER_BSS_LIMIT(pMac) )
8236 {
8237 //Limit reach
8238 smsLog(pMac, LOGE, FL(" BSS limit reached"));
8239 //Free the resources
8240 if( (pScanResult->Result.pvIes == NULL) && pIesLocal )
8241 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308242 vos_mem_free(pIesLocal);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008243 }
8244 csrFreeScanResultEntry(pMac, pScanResult);
8245 vos_mem_free(pParsedFrame);
8246 return eHAL_STATUS_RESOURCES;
8247 }
8248 //Add to scan cache
8249 csrScanAddResult(pMac, pScanResult, pIesLocal);
8250
Kiet Lamb537cfb2013-11-07 12:56:49 +05308251 if( (pScanResult->Result.pvIes == NULL) && pIesLocal )
8252 {
8253 vos_mem_free(pIesLocal);
8254 }
8255
Srikant Kuppa066904f2013-05-07 13:56:02 -07008256 vos_mem_free(pParsedFrame);
8257
8258 return eHAL_STATUS_SUCCESS;
8259}
Manjunathappa Prakash4f1d5a52013-11-11 16:22:19 -08008260#endif //FEATURE_WLAN_SCAN_PNO
Srikant Kuppa066904f2013-05-07 13:56:02 -07008261
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008262#ifdef FEATURE_WLAN_LFR
8263void csrInitOccupiedChannelsList(tpAniSirGlobal pMac)
8264{
8265 tListElem *pEntry = NULL;
8266 tCsrScanResult *pBssDesc = NULL;
8267 tDot11fBeaconIEs *pIes = NULL;
Srinivas28b5b4e2012-12-12 13:07:53 -08008268 tpCsrNeighborRoamControlInfo pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
8269
8270 if (0 != pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels)
8271 {
8272 smsLog(pMac, LOG1, FL("%s: Ini file contains neighbor scan channel list,"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008273 " hence NO need to build occupied channel list (numChannels = %d)"),
Srinivas28b5b4e2012-12-12 13:07:53 -08008274 __func__, pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels);
8275 return;
8276 }
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008277
8278 if (!csrNeighborRoamIsNewConnectedProfile(pMac))
8279 {
8280 smsLog(pMac, LOG2, FL("%s: donot flush occupied list since current roam profile"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008281 " matches previous (numChannels = %d)"),
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008282 __func__, pMac->scan.occupiedChannels.numChannels);
8283 return;
8284 }
8285
8286 /* Empty occupied channels here */
8287 pMac->scan.occupiedChannels.numChannels = 0;
8288
8289 csrLLLock(&pMac->scan.scanResultList);
8290 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
8291 while( pEntry )
8292 {
8293 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
8294 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
8295
8296 //At this time, pBssDescription->Result.pvIes may be NULL
Srikant Kuppa866893f2012-12-27 17:28:14 -08008297 if( !pIes && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008298 &pBssDesc->Result.BssDescriptor, &pIes))) )
8299 {
8300 continue;
8301 }
8302
8303 csrScanAddToOccupiedChannels(pMac, pBssDesc, &pMac->scan.occupiedChannels, pIes);
8304
8305 /*
8306 * Free the memory allocated for pIes in csrGetParsedBssDescriptionIEs
8307 */
8308 if( (pBssDesc->Result.pvIes == NULL) && pIes )
8309 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308310 vos_mem_free(pIes);
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008311 }
8312
8313 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK );
8314 }//while
8315 csrLLUnlock(&pMac->scan.scanResultList);
Srikant Kuppa866893f2012-12-27 17:28:14 -08008316
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008317}
8318#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07008319
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008320eHalStatus csrScanCreateEntryInScanCache(tpAniSirGlobal pMac, tANI_U32 sessionId,
8321 tCsrBssid bssid, tANI_U8 channel)
8322{
8323 eHalStatus status = eHAL_STATUS_SUCCESS;
8324 tDot11fBeaconIEs *pNewIes = NULL;
8325 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
Praveen Kumar Sirisilla8bdfac42013-10-10 17:20:48 -07008326 tSirBssDescription *pNewBssDescriptor = NULL;
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008327 tANI_U32 size = 0;
8328
8329 if(NULL == pSession)
8330 {
8331 status = eHAL_STATUS_FAILURE;
8332 return status;
8333 }
8334 smsLog(pMac, LOG2, FL("csrScanCreateEntryInScanCache: Current bssid::"
Arif Hussain24bafea2013-11-15 15:10:03 -08008335 MAC_ADDRESS_STR),
8336 MAC_ADDR_ARRAY(pSession->pConnectBssDesc->bssId));
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008337 smsLog(pMac, LOG2, FL("csrScanCreateEntryInScanCache: My bssid::"
Arif Hussain24bafea2013-11-15 15:10:03 -08008338 MAC_ADDRESS_STR" channel %d"),
8339 MAC_ADDR_ARRAY(bssid), channel);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008340
8341 do
8342 {
8343 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
8344 pSession->pConnectBssDesc, &pNewIes)))
8345 {
8346 smsLog(pMac, LOGE, FL("%s: Failed to parse IEs"),
8347 __func__);
8348 status = eHAL_STATUS_FAILURE;
8349 break;
8350 }
8351
8352 size = pSession->pConnectBssDesc->length + sizeof(pSession->pConnectBssDesc->length);
Kiet Lam64c1b492013-07-12 13:56:44 +05308353 if (size)
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008354 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308355 pNewBssDescriptor = vos_mem_malloc(size);
8356 if ( NULL == pNewBssDescriptor )
8357 status = eHAL_STATUS_FAILURE;
8358 else
8359 status = eHAL_STATUS_SUCCESS;
8360 if (HAL_STATUS_SUCCESS(status))
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008361 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308362 vos_mem_copy(pNewBssDescriptor, pSession->pConnectBssDesc, size);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008363 }
8364 else
8365 {
8366 smsLog(pMac, LOGE, FL("%s: memory allocation failed"),
8367 __func__);
8368 status = eHAL_STATUS_FAILURE;
8369 break;
8370 }
8371
8372 //change the BSSID & channel as passed
Kiet Lam64c1b492013-07-12 13:56:44 +05308373 vos_mem_copy(pNewBssDescriptor->bssId, bssid, sizeof(tSirMacAddr));
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008374 pNewBssDescriptor->channelId = channel;
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07008375 if(NULL == csrScanAppendBssDescription( pMac, pNewBssDescriptor, pNewIes, TRUE ))
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008376 {
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07008377 smsLog(pMac, LOGE, FL("%s: csrScanAppendBssDescription failed"),
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008378 __func__);
8379 status = eHAL_STATUS_FAILURE;
8380 break;
8381 }
8382 }
8383 else
8384 {
8385 smsLog(pMac, LOGE, FL("%s: length of bss descriptor is 0"),
8386 __func__);
8387 status = eHAL_STATUS_FAILURE;
8388 break;
8389 }
8390 smsLog(pMac, LOGE, FL("%s: entry successfully added in scan cache"),
8391 __func__);
8392 }while(0);
8393
8394 if(pNewIes)
8395 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308396 vos_mem_free(pNewIes);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008397 }
8398 if(pNewBssDescriptor)
8399 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308400 vos_mem_free(pNewBssDescriptor);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008401 }
8402 return status;
8403}
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07008404
8405#ifdef FEATURE_WLAN_CCX
8406// Update the TSF with the difference in system time
8407void UpdateCCKMTSF(tANI_U32 *timeStamp0, tANI_U32 *timeStamp1, tANI_U32 *incr)
8408{
8409 tANI_U64 timeStamp64 = ((tANI_U64)*timeStamp1 << 32) | (*timeStamp0);
8410
8411 timeStamp64 = (tANI_U64)(timeStamp64 + (tANI_U64)*incr);
8412 *timeStamp0 = (tANI_U32)(timeStamp64 & 0xffffffff);
8413 *timeStamp1 = (tANI_U32)((timeStamp64 >> 32) & 0xffffffff);
8414}
8415#endif