blob: 6f0a7b4d7b4d79fab502417edf5a59d1e0323637 [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
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +0530127/*struct to hold the ignored channel list based on country */
128typedef struct sCsrIgnoreChannels
129{
130 tANI_U8 countryCode[NV_FIELD_COUNTRY_CODE_SIZE];
131 tANI_U16 channelList[MAX_CHANNELS_IGNORE];
132 tANI_U16 channelCount;
133}tCsrIgnoreChannels;
134
135static tCsrIgnoreChannels countryIgnoreList[MAX_COUNTRY_IGNORE] = {
136 { {'U','A'}, { 136, 140}, 2},
137 { {'T','W'}, { 36, 40, 44, 48, 52}, 5},
Madan Mohan Koyyalamudi28dd0422013-08-12 15:06:21 +0530138 { {'I','D'}, { 165}, 1 },
Wilson Yange3d2b292013-10-09 00:35:43 -0700139 { {'A','U'}, { 120, 124, 128}, 3 },
Wilson Yangce31eaf2013-11-11 14:40:34 -0800140 { {'A','R'}, { 120, 124, 128}, 3 }
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +0530141 };
142
Jeff Johnson295189b2012-06-20 16:38:30 -0700143//*** This is temporary work around. It need to call CCM api to get to CFG later
144/// Get string parameter value
145extern tSirRetStatus wlan_cfgGetStr(tpAniSirGlobal, tANI_U16, tANI_U8*, tANI_U32*);
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +0530146
Jeff Johnson295189b2012-06-20 16:38:30 -0700147void csrScanGetResultTimerHandler(void *);
148void csrScanResultAgingTimerHandler(void *pv);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -0800149static void csrScanResultCfgAgingTimerHandler(void *pv);
Jeff Johnson295189b2012-06-20 16:38:30 -0700150void csrScanIdleScanTimerHandler(void *);
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700151static void csrSetDefaultScanTiming( tpAniSirGlobal pMac, tSirScanType scanType, tCsrScanRequest *pScanRequest);
Jeff Johnson295189b2012-06-20 16:38:30 -0700152#ifdef WLAN_AP_STA_CONCURRENCY
153static void csrStaApConcTimerHandler(void *);
154#endif
Jeff Johnsone7245742012-09-05 17:12:55 -0700155tANI_BOOLEAN csrIsSupportedChannel(tpAniSirGlobal pMac, tANI_U8 channelId);
Jeff Johnson295189b2012-06-20 16:38:30 -0700156eHalStatus csrScanChannels( tpAniSirGlobal pMac, tSmeCmd *pCommand );
157void csrSetCfgValidChannelList( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels );
158void csrSaveTxPowerToCfg( tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 cfgId );
159void csrSetCfgCountryCode( tpAniSirGlobal pMac, tANI_U8 *countryCode );
160void csrPurgeChannelPower( tpAniSirGlobal pMac, tDblLinkList *pChannelList );
161//if bgPeriod is 0, background scan is disabled. It is in millisecond units
162eHalStatus csrSetCfgBackgroundScanPeriod(tpAniSirGlobal pMac, tANI_U32 bgPeriod);
163eHalStatus csrProcessSetBGScanParam(tpAniSirGlobal pMac, tSmeCmd *pCommand);
164void csrReleaseScanCommand(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus);
165static tANI_BOOLEAN csrScanValidateScanResult( tpAniSirGlobal pMac, tANI_U8 *pChannels,
166 tANI_U8 numChn, tSirBssDescription *pBssDesc,
167 tDot11fBeaconIEs **ppIes );
168eHalStatus csrSetBGScanChannelList( tpAniSirGlobal pMac, tANI_U8 *pAdjustChannels, tANI_U8 NumAdjustChannels);
169void csrReleaseCmdSingle(tpAniSirGlobal pMac, tSmeCmd *pCommand);
170tANI_BOOLEAN csrRoamIsValidChannel( tpAniSirGlobal pMac, tANI_U8 channel );
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700171void csrPruneChannelListForMode( tpAniSirGlobal pMac, tCsrChannel *pChannelList );
Jeff Johnson295189b2012-06-20 16:38:30 -0700172
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -0700173#define CSR_IS_SOCIAL_CHANNEL(channel) (((channel) == 1) || ((channel) == 6) || ((channel) == 11) )
174
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -0700175
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -0700176
Madan Mohan Koyyalamudi923c1e12012-11-30 17:53:27 -0800177static void csrReleaseScanCmdPendingList(tpAniSirGlobal pMac)
178{
179 tListElem *pEntry;
180 tSmeCmd *pCommand;
181
182 while((pEntry = csrLLRemoveHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK)) != NULL)
183 {
184 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
185 if ( eSmeCsrCommandMask & pCommand->command )
186 {
187 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_TRUE );
188 }
189 else
190 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800191 smsLog(pMac, LOGE, FL("Error: Received command : %d"),pCommand->command);
Madan Mohan Koyyalamudi923c1e12012-11-30 17:53:27 -0800192 }
193 }
194}
Jeff Johnson295189b2012-06-20 16:38:30 -0700195//pResult is invalid calling this function.
196void csrFreeScanResultEntry( tpAniSirGlobal pMac, tCsrScanResult *pResult )
197{
198 if( NULL != pResult->Result.pvIes )
199 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530200 vos_mem_free(pResult->Result.pvIes);
Jeff Johnson295189b2012-06-20 16:38:30 -0700201 }
Kiet Lam64c1b492013-07-12 13:56:44 +0530202 vos_mem_free(pResult);
Jeff Johnson295189b2012-06-20 16:38:30 -0700203}
204
205
206static eHalStatus csrLLScanPurgeResult(tpAniSirGlobal pMac, tDblLinkList *pList)
207{
208 eHalStatus status = eHAL_STATUS_SUCCESS;
209 tListElem *pEntry;
210 tCsrScanResult *pBssDesc;
211
212 csrLLLock(pList);
213
214 while((pEntry = csrLLRemoveHead(pList, LL_ACCESS_NOLOCK)) != NULL)
215 {
216 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
217 csrFreeScanResultEntry( pMac, pBssDesc );
218 }
219
220 csrLLUnlock(pList);
221
222 return (status);
223}
224
225
226int csrCheckValidateLists(void * dest, const void *src, v_SIZE_t num, int idx)
227{
228#ifdef CSR_VALIDATE_LIST
229
230 int ii = 1;
231
232 if( (NULL == g_pMac) || (!g_pMac->scan.fValidateList ) )
233 {
234 return ii;
235 }
236 if(g_pchannelPowerInfoList24)
237 {
238 //check 2.4 list
239 tListElem *pElem, *pHead;
240 int count;
241
242 count = (int)(g_pchannelPowerInfoList24->Count);
243 pHead = &g_pchannelPowerInfoList24->ListHead;
244 pElem = pHead->next;
245 if((tANI_U32)(pHead->next) > 0x00010000) //Assuming kernel address is not that low.
246 {
247 //this loop crashes if the pointer is not right
248 while(pElem->next != pHead)
249 {
250 if((tANI_U32)(pElem->next) > 0x00010000)
251 {
252 pElem = pElem->next;
253 VOS_ASSERT(count > 0);
254 count--;
255 }
256 else
257 {
258 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_FATAL,
259 " %d Detect 1 list(0x%X) error Head(0x%X) next(0x%X) Count %d, dest(0x%X) src(0x%X) numBytes(%d)",
260 idx, (unsigned int)g_pchannelPowerInfoList24, (unsigned int)pHead,
261 (unsigned int)(pHead->next), (int)g_pchannelPowerInfoList24->Count,
262 (unsigned int)dest, (unsigned int)src, (int)num);
263 VOS_ASSERT(0);
264 ii = 0;
265 break;
266 }
267 }
268 }
269 else
270 {
271 //Bad list
272 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_FATAL, " %d Detect list(0x%X) error Head(0x%X) next(0x%X) Count %d, dest(0x%X) src(0x%X) numBytes(%d)",
273 idx, (unsigned int)g_pchannelPowerInfoList24, (unsigned int)pHead,
274 (unsigned int)(pHead->next), (int)g_pchannelPowerInfoList24->Count,
275 (unsigned int)dest, (unsigned int)src, (int)num);
276 VOS_ASSERT(0);
277 ii = 0;
278 }
279 }
280 else
281 {
282 //list ok
283 ii = 1;
284 }
285
286
287 return ii;
288
289#else
290 return 1;
291#endif //#ifdef CSR_VALIDATE_LIST
292}
293
294
295eHalStatus csrScanOpen( tpAniSirGlobal pMac )
296{
297 eHalStatus status;
298
299 do
300 {
301 csrLLOpen(pMac->hHdd, &pMac->scan.scanResultList);
302 csrLLOpen(pMac->hHdd, &pMac->scan.tempScanResults);
303 csrLLOpen(pMac->hHdd, &pMac->scan.channelPowerInfoList24);
304 csrLLOpen(pMac->hHdd, &pMac->scan.channelPowerInfoList5G);
305#ifdef WLAN_AP_STA_CONCURRENCY
306 csrLLOpen(pMac->hHdd, &pMac->scan.scanCmdPendingList);
307#endif
308#ifdef CSR_VALIDATE_LIST
309 g_pchannelPowerInfoList5 = &pMac->scan.channelPowerInfoList5G;
310 g_pMac = pMac;
311 g_pchannelPowerInfoList24 = &pMac->scan.channelPowerInfoList24;
312#endif
313 pMac->scan.fFullScanIssued = eANI_BOOLEAN_FALSE;
314 pMac->scan.nBssLimit = CSR_MAX_BSS_SUPPORT;
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530315 status = vos_timer_init(&pMac->scan.hTimerGetResult, VOS_TIMER_TYPE_SW, csrScanGetResultTimerHandler, pMac);
316 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700317 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800318 smsLog(pMac, LOGE, FL("cannot allocate memory for getResult timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700319 break;
320 }
321#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530322 status = vos_timer_init(&pMac->scan.hTimerStaApConcTimer, VOS_TIMER_TYPE_SW, csrStaApConcTimerHandler, pMac);
323 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700324 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800325 smsLog(pMac, LOGE, FL("cannot allocate memory for hTimerStaApConcTimer timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700326 break;
327 }
328#endif
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530329 status = vos_timer_init(&pMac->scan.hTimerIdleScan, VOS_TIMER_TYPE_SW, csrScanIdleScanTimerHandler, pMac);
330 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700331 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800332 smsLog(pMac, LOGE, FL("cannot allocate memory for idleScan timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700333 break;
334 }
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530335 status = vos_timer_init(&pMac->scan.hTimerResultAging, VOS_TIMER_TYPE_SW, csrScanResultAgingTimerHandler, 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 ResultAging 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.hTimerResultCfgAging, VOS_TIMER_TYPE_SW,
342 csrScanResultCfgAgingTimerHandler, pMac);
343 if (!HAL_STATUS_SUCCESS(status))
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -0800344 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800345 smsLog(pMac, LOGE, FL("cannot allocate memory for CFG ResultAging timer"));
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -0800346 break;
347 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700348 }while(0);
349
350 return (status);
351}
352
353
354eHalStatus csrScanClose( tpAniSirGlobal pMac )
355{
356#ifdef CSR_VALIDATE_LIST
357 g_pchannelPowerInfoList24 = NULL;
358 g_pchannelPowerInfoList5 = NULL;
359 g_pMac = NULL;
360#endif
361 csrLLScanPurgeResult(pMac, &pMac->scan.tempScanResults);
362 csrLLScanPurgeResult(pMac, &pMac->scan.scanResultList);
363#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudi923c1e12012-11-30 17:53:27 -0800364 csrReleaseScanCmdPendingList(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -0700365#endif
366 csrLLClose(&pMac->scan.scanResultList);
367 csrLLClose(&pMac->scan.tempScanResults);
368#ifdef WLAN_AP_STA_CONCURRENCY
369 csrLLClose(&pMac->scan.scanCmdPendingList);
370#endif
371 csrPurgeChannelPower(pMac, &pMac->scan.channelPowerInfoList24);
372 csrPurgeChannelPower(pMac, &pMac->scan.channelPowerInfoList5G);
373 csrLLClose(&pMac->scan.channelPowerInfoList24);
374 csrLLClose(&pMac->scan.channelPowerInfoList5G);
375 csrScanDisable(pMac);
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530376 vos_timer_destroy(&pMac->scan.hTimerResultAging);
377 vos_timer_destroy(&pMac->scan.hTimerResultCfgAging);
378 vos_timer_destroy(&pMac->scan.hTimerGetResult);
Jeff Johnson295189b2012-06-20 16:38:30 -0700379#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530380 vos_timer_destroy(&pMac->scan.hTimerStaApConcTimer);
Jeff Johnson295189b2012-06-20 16:38:30 -0700381#endif
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530382 vos_timer_destroy(&pMac->scan.hTimerIdleScan);
Jeff Johnson295189b2012-06-20 16:38:30 -0700383 return eHAL_STATUS_SUCCESS;
384}
385
386
387eHalStatus csrScanEnable( tpAniSirGlobal pMac )
388{
389
390 pMac->scan.fScanEnable = eANI_BOOLEAN_TRUE;
391 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
392
393 return eHAL_STATUS_SUCCESS;
394}
395
396
397eHalStatus csrScanDisable( tpAniSirGlobal pMac )
398{
399
400 csrScanStopTimers(pMac);
401 pMac->scan.fScanEnable = eANI_BOOLEAN_FALSE;
402
403 return eHAL_STATUS_SUCCESS;
404}
405
406
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700407//Set scan timing parameters according to state of other driver sessions
408//No validation of the parameters is performed.
409static void csrSetDefaultScanTiming( tpAniSirGlobal pMac, tSirScanType scanType, tCsrScanRequest *pScanRequest)
410{
411#ifdef WLAN_AP_STA_CONCURRENCY
412 if(csrIsAnySessionConnected(pMac))
413 {
414 //If multi-session, use the appropriate default scan times
415 if(scanType == eSIR_ACTIVE_SCAN)
416 {
417 pScanRequest->maxChnTime = pMac->roam.configParam.nActiveMaxChnTimeConc;
418 pScanRequest->minChnTime = pMac->roam.configParam.nActiveMinChnTimeConc;
419 }
420 else
421 {
422 pScanRequest->maxChnTime = pMac->roam.configParam.nPassiveMaxChnTimeConc;
423 pScanRequest->minChnTime = pMac->roam.configParam.nPassiveMinChnTimeConc;
424 }
Kiet Lam64c1b492013-07-12 13:56:44 +0530425 pScanRequest->maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
426 pScanRequest->minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700427
428 pScanRequest->restTime = pMac->roam.configParam.nRestTimeConc;
429
430 //Return so that fields set above will not be overwritten.
431 return;
432 }
433#endif
434
435 //This portion of the code executed if multi-session not supported
436 //(WLAN_AP_STA_CONCURRENCY not defined) or no multi-session.
437 //Use the "regular" (non-concurrency) default scan timing.
438 if(pScanRequest->scanType == eSIR_ACTIVE_SCAN)
439 {
440 pScanRequest->maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
441 pScanRequest->minChnTime = pMac->roam.configParam.nActiveMinChnTime;
442 }
443 else
444 {
445 pScanRequest->maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
446 pScanRequest->minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
447 }
Kiet Lam64c1b492013-07-12 13:56:44 +0530448 pScanRequest->maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
449 pScanRequest->minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700450
451#ifdef WLAN_AP_STA_CONCURRENCY
452 //No rest time if no sessions are connected.
453 pScanRequest->restTime = 0;
454#endif
455}
456
Jeff Johnson295189b2012-06-20 16:38:30 -0700457#ifdef WLAN_AP_STA_CONCURRENCY
458//Return SUCCESS is the command is queued, else returns eHAL_STATUS_FAILURE
459eHalStatus csrQueueScanRequest( tpAniSirGlobal pMac, tSmeCmd *pScanCmd )
460{
461 eHalStatus status = eHAL_STATUS_SUCCESS;
462
463 tANI_BOOLEAN fNoCmdPending;
464 tSmeCmd *pQueueScanCmd=NULL;
465 tSmeCmd *pSendScanCmd=NULL;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700466 tANI_U8 nNumChanCombinedConc = 0;
Gopichand Nakkala114718f2013-03-25 19:19:46 -0700467 if (NULL == pScanCmd)
468 {
469 smsLog (pMac, LOGE, FL("Scan Req cmd is NULL"));
470 return eHAL_STATUS_FAILURE;
471 }
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -0800472 /* split scan if any one of the following:
473 * - STA session is connected and the scan is not a P2P search
474 * - any P2P session is connected
Srikant Kuppa866893f2012-12-27 17:28:14 -0800475 * Do not split scans if no concurrent infra connections are
476 * active and if the scan is a BG scan triggered by LFR (OR)
477 * any scan if LFR is in the middle of a BG scan. Splitting
478 * the scan is delaying the time it takes for LFR to find
479 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -0800480 */
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700481
482 if(csrIsStaSessionConnected(pMac) &&
483 !csrIsP2pSessionConnected(pMac))
484 {
485 nNumChanCombinedConc = pMac->roam.configParam.nNumStaChanCombinedConc;
486 }
487 else if(csrIsP2pSessionConnected(pMac))
488 {
489 nNumChanCombinedConc = pMac->roam.configParam.nNumP2PChanCombinedConc;
490 }
Srikant Kuppa866893f2012-12-27 17:28:14 -0800491 if ( (csrIsStaSessionConnected(pMac) &&
492#ifdef FEATURE_WLAN_LFR
493 (csrIsConcurrentInfraConnected(pMac) ||
494 ((pScanCmd->u.scanCmd.reason != eCsrScanBgScan) &&
495 (pMac->roam.neighborRoamInfo.neighborRoamState !=
496 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
497#endif
498 (pScanCmd->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Vinay Malekal05fdc812012-12-17 13:04:30 -0800499 (csrIsP2pSessionConnected(pMac)) )
Jeff Johnson295189b2012-06-20 16:38:30 -0700500 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700501 tCsrScanRequest scanReq;
502 tANI_U8 numChn = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
503 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
504 tANI_U8 channelToScan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
Jeff Johnson295189b2012-06-20 16:38:30 -0700505 tANI_BOOLEAN bMemAlloc = eANI_BOOLEAN_FALSE;
506
507 if (numChn == 0)
508 {
509
510 numChn = pMac->scan.baseChannels.numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -0700511
Kiet Lam64c1b492013-07-12 13:56:44 +0530512 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(numChn);
513 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -0700514 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800515 smsLog( pMac, LOGE, FL(" Failed to get memory for channel list ") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800516 return eHAL_STATUS_FAILURE;
517 }
518 bMemAlloc = eANI_BOOLEAN_TRUE;
Kiet Lam64c1b492013-07-12 13:56:44 +0530519 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
520 pMac->scan.baseChannels.channelList, numChn);
521 status = eHAL_STATUS_SUCCESS;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800522 if( !HAL_STATUS_SUCCESS( status ) )
523 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530524 vos_mem_free(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800525 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800526 smsLog( pMac, LOGE, FL(" Failed to copy memory to channel list ") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800527 return eHAL_STATUS_FAILURE;
528 }
529 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = numChn;
530 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700531
Vinay Malekal05fdc812012-12-17 13:04:30 -0800532 //Whenever we get a scan request with multiple channels we break it up into 2 requests
533 //First request for first channel to scan and second request to scan remaining channels
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700534 if ( numChn > nNumChanCombinedConc)
Vinay Malekal05fdc812012-12-17 13:04:30 -0800535 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530536 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800537
538 pQueueScanCmd = csrGetCommandBuffer(pMac); //optimize this to use 2 command buffer only
539 if (!pQueueScanCmd)
540 {
541 if (bMemAlloc)
Jeff Johnson295189b2012-06-20 16:38:30 -0700542 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530543 vos_mem_free(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800544 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
545
Jeff Johnson295189b2012-06-20 16:38:30 -0700546 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800547 smsLog( pMac, LOGE, FL(" Failed to get Queue command buffer") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800548 return eHAL_STATUS_FAILURE;
549 }
550 pQueueScanCmd->command = pScanCmd->command;
551 pQueueScanCmd->sessionId = pScanCmd->sessionId;
552 pQueueScanCmd->u.scanCmd.callback = pScanCmd->u.scanCmd.callback;
553 pQueueScanCmd->u.scanCmd.pContext = pScanCmd->u.scanCmd.pContext;
554 pQueueScanCmd->u.scanCmd.reason = pScanCmd->u.scanCmd.reason;
555 pQueueScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Jeff Johnson295189b2012-06-20 16:38:30 -0700556
Vinay Malekal05fdc812012-12-17 13:04:30 -0800557 /* First copy all the parameters to local variable of scan request */
558 csrScanCopyRequest(pMac, &scanReq, &pScanCmd->u.scanCmd.u.scanRequest);
Madan Mohan Koyyalamudiaf2a8b92012-10-09 14:58:07 -0700559
Vinay Malekal05fdc812012-12-17 13:04:30 -0800560 /* Now modify the elements of local var scan request required to be modified for split scan */
561 if(scanReq.ChannelInfo.ChannelList != NULL)
562 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530563 vos_mem_free(scanReq.ChannelInfo.ChannelList);
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -0800564 scanReq.ChannelInfo.ChannelList = NULL;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800565 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700566
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700567 pChnInfo->numOfChannels = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels - nNumChanCombinedConc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700568
Vinay Malekal05fdc812012-12-17 13:04:30 -0800569 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_WARN,
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +0530570 FL(" &channelToScan %p pScanCmd(%p) pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList(%p)numChn(%d)"),
571 &channelToScan[0], pScanCmd,
572 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList, numChn);
Jeff Johnson295189b2012-06-20 16:38:30 -0700573
Kiet Lam64c1b492013-07-12 13:56:44 +0530574 vos_mem_copy(&channelToScan[0],
575 &pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[
576 nNumChanCombinedConc],
577 pChnInfo->numOfChannels * sizeof(tANI_U8));
Vinay Malekal05fdc812012-12-17 13:04:30 -0800578
579 pChnInfo->ChannelList = &channelToScan[0];
580
581 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
582 //Modify callers parameters in case of concurrency
Madan Mohan Koyyalamudi04a65f02013-07-26 13:58:38 +0530583 if (!pScanCmd->u.scanCmd.u.scanRequest.bcnRptReqScan)
584 scanReq.scanType = eSIR_ACTIVE_SCAN;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800585 //Use concurrency values for min/maxChnTime.
586 //We know csrIsAnySessionConnected(pMac) returns TRUE here
587 csrSetDefaultScanTiming(pMac, scanReq.scanType, &scanReq);
588
589 status = csrScanCopyRequest(pMac, &pQueueScanCmd->u.scanCmd.u.scanRequest, &scanReq);
590
591 if(!HAL_STATUS_SUCCESS(status))
592 {
593 if (bMemAlloc)
594 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530595 vos_mem_free(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800596 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
597
598 }
599 if( scanReq.pIEField != NULL)
600 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530601 vos_mem_free(scanReq.pIEField);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800602 scanReq.pIEField = NULL;
603 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800604 smsLog( pMac, LOGE, FL(" Failed to get copy csrScanRequest = %d"), status );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800605 return eHAL_STATUS_FAILURE;
606 }
607 /* Clean the local scan variable */
608 scanReq.ChannelInfo.ChannelList = NULL;
609 scanReq.ChannelInfo.numOfChannels = 0;
610 csrScanFreeRequest(pMac, &scanReq);
611
612 /* setup the command to scan 2 channels */
613 pSendScanCmd = pScanCmd;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700614 pSendScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nNumChanCombinedConc;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800615 pSendScanCmd->u.scanCmd.u.scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
Madan Mohan Koyyalamudi04a65f02013-07-26 13:58:38 +0530616 if (!pSendScanCmd->u.scanCmd.u.scanRequest.bcnRptReqScan)
617 pSendScanCmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800618 //Use concurrency values for min/maxChnTime.
619 //We know csrIsAnySessionConnected(pMac) returns TRUE here
620 csrSetDefaultScanTiming(pMac, pSendScanCmd->u.scanCmd.u.scanRequest.scanType, &pSendScanCmd->u.scanCmd.u.scanRequest);
621 pSendScanCmd->u.scanCmd.callback = NULL;
622 } else {
623 pSendScanCmd = pScanCmd;
624 pSendScanCmd->u.scanCmd.u.scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
Madan Mohan Koyyalamudi04a65f02013-07-26 13:58:38 +0530625 if (!pSendScanCmd->u.scanCmd.u.scanRequest.bcnRptReqScan)
626 pSendScanCmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800627 //Use concurrency values for min/maxChnTime.
628 //We know csrIsAnySessionConnected(pMac) returns TRUE here
629 csrSetDefaultScanTiming(pMac, pSendScanCmd->u.scanCmd.u.scanRequest.scanType, &pSendScanCmd->u.scanCmd.u.scanRequest);
630 }
631
632 fNoCmdPending = csrLLIsListEmpty( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK );
633
634 //Logic Below is as follows
635 // If the scanCmdPendingList is empty then we directly send that command
636 // to smeCommandQueue else we buffer it in our scanCmdPendingList Queue
637 if( fNoCmdPending )
638 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700639 if (pQueueScanCmd != NULL)
640 {
Vinay Malekal05fdc812012-12-17 13:04:30 -0800641 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pQueueScanCmd->Link, LL_ACCESS_LOCK );
Jeff Johnson295189b2012-06-20 16:38:30 -0700642 }
643
644 if (pSendScanCmd != NULL)
645 {
646 return csrQueueSmeCommand(pMac, pSendScanCmd, eANI_BOOLEAN_FALSE);
647 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800648 }
649 else
650 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700651 if (pSendScanCmd != NULL)
652 {
653 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pSendScanCmd->Link, LL_ACCESS_LOCK );
654 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800655
Jeff Johnson295189b2012-06-20 16:38:30 -0700656 if (pQueueScanCmd != NULL)
657 {
658 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pQueueScanCmd->Link, LL_ACCESS_LOCK );
659 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800660 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700661 }
662 else
663 { //No concurrency case
Srikant Kuppa866893f2012-12-27 17:28:14 -0800664 smsLog( pMac, LOG2, FL("Queuing scan command (reason=%d, roamState=%d"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800665 " numOfChannels=%d)"),
Srikant Kuppa866893f2012-12-27 17:28:14 -0800666 pScanCmd->u.scanCmd.reason,
667 pMac->roam.neighborRoamInfo.neighborRoamState,
668 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -0700669 return csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
670 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700671
672 return ( status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700673}
674#endif
675
Jeff Johnsone7245742012-09-05 17:12:55 -0700676/* ---------------------------------------------------------------------------
677 \fn csrScan2GOnyRequest
678 \brief This function will update the scan request with only
Jeff Johnsonb88db982012-12-10 13:34:59 -0800679 2.4GHz valid channel list.
Jeff Johnsone7245742012-09-05 17:12:55 -0700680 \param pMac
681 \param pScanCmd
682 \param pScanRequest
683 \return None
684 -------------------------------------------------------------------------------*/
685static void csrScan2GOnyRequest(tpAniSirGlobal pMac,tSmeCmd *pScanCmd,
686 tCsrScanRequest *pScanRequest)
687{
688 tANI_U8 index, channelId, channelListSize = 0;
689 tANI_U8 channelList2G[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
690 static tANI_U8 validchannelList[CSR_MAX_2_4_GHZ_SUPPORTED_CHANNELS] = {0};
691
692 VOS_ASSERT(pScanCmd && pScanRequest);
Madan Mohan Koyyalamudi33ef6a22012-10-30 17:44:43 -0700693 /* To silence the KW tool null check is added */
694 if((pScanCmd == NULL) || (pScanRequest == NULL))
695 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800696 smsLog( pMac, LOGE, FL(" pScanCmd or pScanRequest is NULL "));
Madan Mohan Koyyalamudi33ef6a22012-10-30 17:44:43 -0700697 return;
698 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700699
700 if (pScanCmd->u.scanCmd.scanID ||
701 (eCSR_SCAN_REQUEST_FULL_SCAN != pScanRequest->requestType))
702 return;
703
704 //Contsruct valid Supported 2.4 GHz Channel List
705 for( index = 0; index < ARRAY_SIZE(channelList2G); index++ )
706 {
707 channelId = channelList2G[index];
708 if ( csrIsSupportedChannel( pMac, channelId ) )
709 {
710 validchannelList[channelListSize++] = channelId;
711 }
712 }
713
714 pScanRequest->ChannelInfo.numOfChannels = channelListSize;
715 pScanRequest->ChannelInfo.ChannelList = validchannelList;
716}
717
Jeff Johnson295189b2012-06-20 16:38:30 -0700718eHalStatus csrScanRequest(tpAniSirGlobal pMac, tANI_U16 sessionId,
719 tCsrScanRequest *pScanRequest, tANI_U32 *pScanRequestID,
720 csrScanCompleteCallback callback, void *pContext)
721{
722 eHalStatus status = eHAL_STATUS_FAILURE;
723 tSmeCmd *pScanCmd = NULL;
Madan Mohan Koyyalamudicb90bb22012-10-30 18:24:43 -0700724 eCsrConnectState ConnectState;
Jeff Johnson295189b2012-06-20 16:38:30 -0700725
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800726 if(pScanRequest == NULL)
727 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800728 smsLog( pMac, LOGE, FL(" pScanRequest is NULL"));
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800729 VOS_ASSERT(0);
730 }
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700731
Kiet Lamd1f3dc82013-11-05 20:45:04 +0530732 /* During group formation, the P2P client scans for GO with the specific SSID.
733 * There will be chances of GO switching to other channels because of scan or
734 * to STA channel in case of STA+GO MCC scenario. So to increase the possibility
735 * of client to find the GO, the dwell time of scan is increased to 100ms.
736 */
737 if(pScanRequest->p2pSearch)
738 {
739 //If the scan request is for specific SSId the length of SSID will be
740 //greater than 7 as SSID for p2p search contains "DIRECT-")
741 if(pScanRequest->SSIDs.SSIDList->SSID.length > DIRECT_SSID_LEN)
742 {
743 smsLog( pMac, LOG1, FL(" Increase the Dwell time to 100ms."));
744 pScanRequest->maxChnTime = MAX_CHN_TIME_TO_FIND_GO;
745 pScanRequest->minChnTime = MIN_CHN_TIME_TO_FIND_GO;
746 }
747 }
748
Jeff Johnson295189b2012-06-20 16:38:30 -0700749 do
750 {
751 if(pMac->scan.fScanEnable)
752 {
753 pScanCmd = csrGetCommandBuffer(pMac);
754 if(pScanCmd)
755 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530756 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -0700757 pScanCmd->command = eSmeCommandScan;
758 pScanCmd->sessionId = sessionId;
759 pScanCmd->u.scanCmd.callback = callback;
760 pScanCmd->u.scanCmd.pContext = pContext;
761 if(eCSR_SCAN_REQUEST_11D_SCAN == pScanRequest->requestType)
762 {
763 pScanCmd->u.scanCmd.reason = eCsrScan11d1;
764 }
765 else if((eCSR_SCAN_REQUEST_FULL_SCAN == pScanRequest->requestType) ||
766 (eCSR_SCAN_P2P_DISCOVERY == pScanRequest->requestType)
767#ifdef SOFTAP_CHANNEL_RANGE
768 ||(eCSR_SCAN_SOFTAP_CHANNEL_RANGE == pScanRequest->requestType)
769#endif
770 )
771 {
772 pScanCmd->u.scanCmd.reason = eCsrScanUserRequest;
773 }
774 else if(eCSR_SCAN_HO_BG_SCAN == pScanRequest->requestType)
775 {
776 pScanCmd->u.scanCmd.reason = eCsrScanBgScan;
777 }
778 else if(eCSR_SCAN_HO_PROBE_SCAN == pScanRequest->requestType)
779 {
780 pScanCmd->u.scanCmd.reason = eCsrScanProbeBss;
781 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700782 else if(eCSR_SCAN_P2P_FIND_PEER == pScanRequest->requestType)
783 {
784 pScanCmd->u.scanCmd.reason = eCsrScanP2PFindPeer;
785 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700786 else
787 {
788 pScanCmd->u.scanCmd.reason = eCsrScanIdleScan;
789 }
790 if(pScanRequest->minChnTime == 0 && pScanRequest->maxChnTime == 0)
791 {
792 //The caller doesn't set the time correctly. Set it here
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700793 csrSetDefaultScanTiming(pMac, pScanRequest->scanType, pScanRequest);
794 }
795#ifdef WLAN_AP_STA_CONCURRENCY
796 if(pScanRequest->restTime == 0)
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800797 {
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700798 //Need to set restTime only if at least one session is connected
799 if(csrIsAnySessionConnected(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -0700800 {
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700801 pScanRequest->restTime = pMac->roam.configParam.nRestTimeConc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700802 }
803 }
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700804#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -0700805 /*For Standalone wlan : channel time will remain the same.
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530806 For BTC with A2DP up: Channel time = Channel time * 2, if station is not already associated.
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800807 This has been done to provide a larger scan window for faster connection during btc.Else Scan is seen
808 to take a long time.
809 For BTC with A2DP up: Channel time will not be doubled, if station is already associated.
810 */
Jeff Johnson32d95a32012-09-10 13:15:23 -0700811 status = csrRoamGetConnectState(pMac,sessionId,&ConnectState);
Srinivas Girigowdac84c57c2013-02-19 17:41:56 -0800812 if (HAL_STATUS_SUCCESS(status) &&
813 pMac->btc.fA2DPUp &&
Jeff Johnson32d95a32012-09-10 13:15:23 -0700814 (eCSR_ASSOC_STATE_TYPE_INFRA_ASSOCIATED != ConnectState) &&
815 (eCSR_ASSOC_STATE_TYPE_IBSS_CONNECTED != ConnectState))
816 {
817 pScanRequest->maxChnTime = pScanRequest->maxChnTime << 1;
818 pScanRequest->minChnTime = pScanRequest->minChnTime << 1;
819 }
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800820
Kiet Lam64c1b492013-07-12 13:56:44 +0530821 pScanRequest->maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
822 pScanRequest->minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700823 //Need to make the following atomic
824 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
825
826 if(pScanRequestID)
827 {
828 *pScanRequestID = pScanCmd->u.scanCmd.scanID;
829 }
830
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800831 // If it is the first scan request from HDD, CSR checks if it is for 11d.
Jeff Johnson295189b2012-06-20 16:38:30 -0700832 // If it is not, CSR will save the scan request in the pending cmd queue
833 // & issue an 11d scan request to PE.
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800834 if (((0 == pScanCmd->u.scanCmd.scanID)
Jeff Johnson295189b2012-06-20 16:38:30 -0700835 && (eCSR_SCAN_REQUEST_11D_SCAN != pScanRequest->requestType))
836#ifdef SOFTAP_CHANNEL_RANGE
837 && (eCSR_SCAN_SOFTAP_CHANNEL_RANGE != pScanRequest->requestType)
838#endif
839 && (eANI_BOOLEAN_FALSE == pMac->scan.fEnableBypass11d)
840 )
841 {
842 tSmeCmd *p11dScanCmd;
843 tCsrScanRequest scanReq;
844 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
845
Kiet Lam64c1b492013-07-12 13:56:44 +0530846 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -0700847
848 p11dScanCmd = csrGetCommandBuffer(pMac);
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800849 if (p11dScanCmd)
Jeff Johnson295189b2012-06-20 16:38:30 -0700850 {
851 tANI_U32 numChn = pMac->scan.baseChannels.numChannels;
852
Kiet Lam64c1b492013-07-12 13:56:44 +0530853 vos_mem_set(&p11dScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
854 pChnInfo->ChannelList = vos_mem_malloc(numChn);
855 if ( NULL == pChnInfo->ChannelList )
856 return eHAL_STATUS_FAILURE;
857 vos_mem_copy(pChnInfo->ChannelList,
858 pMac->scan.baseChannels.channelList, numChn);
859 status = eHAL_STATUS_SUCCESS;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800860 if ( !HAL_STATUS_SUCCESS( status ) )
Jeff Johnson295189b2012-06-20 16:38:30 -0700861 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530862 vos_mem_free(pChnInfo->ChannelList);
Jeff Johnson295189b2012-06-20 16:38:30 -0700863 pChnInfo->ChannelList = NULL;
864 break;
865 }
866 pChnInfo->numOfChannels = (tANI_U8)numChn;
867 p11dScanCmd->command = eSmeCommandScan;
868 p11dScanCmd->u.scanCmd.callback = NULL;
869 p11dScanCmd->u.scanCmd.pContext = NULL;
870 p11dScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++;
871 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
872
873 if ( csrIs11dSupported(pMac) )
874 {
Madan Mohan Koyyalamudi04a65f02013-07-26 13:58:38 +0530875 scanReq.bcnRptReqScan = pScanRequest->bcnRptReqScan;
876 if (pScanRequest->bcnRptReqScan)
877 scanReq.scanType = pScanRequest->scanType ?
878 eSIR_PASSIVE_SCAN :
879 pScanRequest->scanType;
880 else
881 scanReq.scanType = eSIR_PASSIVE_SCAN;
Jeff Johnson295189b2012-06-20 16:38:30 -0700882 scanReq.requestType = eCSR_SCAN_REQUEST_11D_SCAN;
883 p11dScanCmd->u.scanCmd.reason = eCsrScan11d1;
884 scanReq.maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
885 scanReq.minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
886 }
887 else
888 {
Madan Mohan Koyyalamudi04a65f02013-07-26 13:58:38 +0530889 scanReq.bcnRptReqScan = pScanRequest->bcnRptReqScan;
890 if (pScanRequest->bcnRptReqScan)
891 scanReq.scanType = pScanRequest->scanType;
892 else
893 scanReq.scanType = eSIR_ACTIVE_SCAN;
Jeff Johnson295189b2012-06-20 16:38:30 -0700894 scanReq.requestType = eCSR_SCAN_IDLE_MODE_SCAN;
895 p11dScanCmd->u.scanCmd.reason = eCsrScanIdleScan;
896 scanReq.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
897 scanReq.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800898
Madan Mohan Koyyalamudi04a65f02013-07-26 13:58:38 +0530899 scanReq.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
900 scanReq.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700901 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700902
Jeff Johnson295189b2012-06-20 16:38:30 -0700903 status = csrScanCopyRequest(pMac, &p11dScanCmd->u.scanCmd.u.scanRequest, &scanReq);
904 //Free the channel list
Kiet Lam64c1b492013-07-12 13:56:44 +0530905 vos_mem_free(pChnInfo->ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -0700906 pChnInfo->ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -0700907
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800908 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700909 {
910 //Start process the command
911#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +0530912 if (!pMac->fScanOffload)
913 status = csrQueueScanRequest(pMac, p11dScanCmd);
914 else
915 status = csrQueueSmeCommand(pMac, p11dScanCmd,
916 eANI_BOOLEAN_FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -0700917#else
918 status = csrQueueSmeCommand(pMac, p11dScanCmd, eANI_BOOLEAN_FALSE);
919#endif
920 if( !HAL_STATUS_SUCCESS( status ) )
921 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800922 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700923 break;
924 }
925 }
926 else
927 {
928 break;
929 }
930 }
931 else
932 {
933 //error
934 break;
935 }
936 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700937
938 //Scan only 2G Channels if set in ini file
939 //This is mainly to reduce the First Scan duration
940 //Once we turn on Wifi
941 if(pMac->scan.fFirstScanOnly2GChnl)
942 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800943 smsLog( pMac, LOG1, FL("Scanning only 2G Channels during first scan"));
Jeff Johnsone7245742012-09-05 17:12:55 -0700944 csrScan2GOnyRequest(pMac, pScanCmd, pScanRequest);
945 }
946
Jeff Johnson295189b2012-06-20 16:38:30 -0700947 status = csrScanCopyRequest(pMac, &pScanCmd->u.scanCmd.u.scanRequest, pScanRequest);
948 if(HAL_STATUS_SUCCESS(status))
949 {
950 //Start process the command
951#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +0530952 if (!pMac->fScanOffload)
953 status = csrQueueScanRequest(pMac,pScanCmd);
954 else
955 status = csrQueueSmeCommand(pMac, pScanCmd,
956 eANI_BOOLEAN_FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -0700957#else
958 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
959#endif
960 if( !HAL_STATUS_SUCCESS( status ) )
961 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800962 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700963 break;
964 }
965 }
966 else
967 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800968 smsLog( pMac, LOGE, FL(" fail to copy request status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700969 break;
970 }
971 }
972 else
973 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800974 smsLog( pMac, LOGE, FL(" pScanCmd is NULL"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700975 break;
976 }
977 }
978 } while(0);
979 if(!HAL_STATUS_SUCCESS(status) && pScanCmd)
980 {
981 if( eCsrScanIdleScan == pScanCmd->u.scanCmd.reason )
982 {
983 //Set the flag back for restarting idle scan
984 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
985 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800986 smsLog( pMac, LOGE, FL(" failed with status = %d, releasing scan cmd"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700987 csrReleaseCommandScan(pMac, pScanCmd);
988 }
989
990 return (status);
991}
992
993
994eHalStatus csrScanRequestResult(tpAniSirGlobal pMac)
995{
996 eHalStatus status = eHAL_STATUS_SUCCESS;
997 tSmeCmd *pScanCmd;
998
999 if(pMac->scan.fScanEnable)
1000 {
1001 pScanCmd = csrGetCommandBuffer(pMac);
1002 if(pScanCmd)
1003 {
1004 pScanCmd->command = eSmeCommandScan;
Kiet Lam64c1b492013-07-12 13:56:44 +05301005 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001006 pScanCmd->u.scanCmd.callback = NULL;
1007 pScanCmd->u.scanCmd.pContext = NULL;
1008 pScanCmd->u.scanCmd.reason = eCsrScanGetResult;
1009 //Need to make the following atomic
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -07001010 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID; //let it wrap around
Jeff Johnson295189b2012-06-20 16:38:30 -07001011 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
1012 if( !HAL_STATUS_SUCCESS( status ) )
1013 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001014 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001015 csrReleaseCommandScan(pMac, pScanCmd);
1016 }
1017 }
1018 else
1019 {
1020 //log error
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001021 smsLog(pMac, LOGE, FL("can not obtain a common buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001022 status = eHAL_STATUS_RESOURCES;
1023 }
1024 }
1025
1026 return (status);
1027}
1028
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07001029#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
1030eHalStatus csrScanRequestLfrResult(tpAniSirGlobal pMac, tANI_U32 sessionId,
1031 csrScanCompleteCallback callback, void *pContext)
1032{
1033 eHalStatus status = eHAL_STATUS_SUCCESS;
1034 tSmeCmd *pScanCmd;
1035
1036 if (pMac->scan.fScanEnable)
1037 {
1038 pScanCmd = csrGetCommandBuffer(pMac);
1039 if (pScanCmd)
1040 {
1041 pScanCmd->command = eSmeCommandScan;
1042 pScanCmd->sessionId = sessionId;
Kiet Lam64c1b492013-07-12 13:56:44 +05301043 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07001044 pScanCmd->u.scanCmd.callback = callback;
1045 pScanCmd->u.scanCmd.pContext = pContext;
1046 pScanCmd->u.scanCmd.reason = eCsrScanGetLfrResult;
1047 //Need to make the following atomic
1048 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID; //let it wrap around
1049 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_TRUE);
1050 if ( !HAL_STATUS_SUCCESS( status ) )
1051 {
1052 smsLog( pMac, LOGE, FL(" fail to send message status = %d\n"), status );
1053 csrReleaseCommandScan(pMac, pScanCmd);
1054 }
1055 }
1056 else
1057 {
1058 //log error
1059 smsLog(pMac, LOGE, FL("can not obtain a common buffer\n"));
1060 status = eHAL_STATUS_RESOURCES;
1061 }
1062 }
1063
1064 return (status);
1065}
1066#endif //WLAN_FEATURE_ROAM_SCAN_OFFLOAD
Jeff Johnson295189b2012-06-20 16:38:30 -07001067
1068eHalStatus csrScanAllChannels(tpAniSirGlobal pMac, eCsrRequestType reqType)
1069{
1070 eHalStatus status = eHAL_STATUS_SUCCESS;
1071 tANI_U32 scanId;
1072 tCsrScanRequest scanReq;
1073
Kiet Lam64c1b492013-07-12 13:56:44 +05301074 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001075 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
1076 scanReq.scanType = eSIR_ACTIVE_SCAN;
1077 scanReq.requestType = reqType;
1078 scanReq.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1079 scanReq.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001080 scanReq.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1081 scanReq.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001082 //Scan with invalid sessionId.
1083 //This results in SME using the first available session to scan.
1084 status = csrScanRequest(pMac, CSR_SESSION_ID_INVALID, &scanReq,
1085 &scanId, NULL, NULL);
1086
1087 return (status);
1088}
1089
1090
1091
1092
1093eHalStatus csrIssueRoamAfterLostlinkScan(tpAniSirGlobal pMac, tANI_U32 sessionId, eCsrRoamReason reason)
1094{
1095 eHalStatus status = eHAL_STATUS_FAILURE;
1096 tScanResultHandle hBSSList = NULL;
1097 tCsrScanResultFilter *pScanFilter = NULL;
1098 tANI_U32 roamId = 0;
1099 tCsrRoamProfile *pProfile = NULL;
1100 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1101
Jeff Johnson32d95a32012-09-10 13:15:23 -07001102 if(!pSession)
1103 {
1104 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1105 return eHAL_STATUS_FAILURE;
1106 }
1107
Jeff Johnson295189b2012-06-20 16:38:30 -07001108 do
1109 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001110 smsLog(pMac, LOG1, " csrIssueRoamAfterLostlinkScan called");
Jeff Johnson295189b2012-06-20 16:38:30 -07001111 if(pSession->fCancelRoaming)
1112 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001113 smsLog(pMac, LOGW, " lostlink roaming is cancelled");
Jeff Johnson295189b2012-06-20 16:38:30 -07001114 csrScanStartIdleScan(pMac);
1115 status = eHAL_STATUS_SUCCESS;
1116 break;
1117 }
1118 //Here is the profile we need to connect to
Kiet Lam64c1b492013-07-12 13:56:44 +05301119 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1120 if ( NULL == pScanFilter)
1121 status = eHAL_STATUS_FAILURE;
1122 else
1123 status = eHAL_STATUS_SUCCESS;
1124 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001125 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301126 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001127 if(NULL == pSession->pCurRoamProfile)
1128 {
1129 pScanFilter->EncryptionType.numEntries = 1;
1130 pScanFilter->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_NONE;
1131 }
1132 else
1133 {
1134 //We have to make a copy of pCurRoamProfile because it will be free inside csrRoamIssueConnect
Kiet Lam64c1b492013-07-12 13:56:44 +05301135 pProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1136 if ( NULL == pProfile )
1137 status = eHAL_STATUS_FAILURE;
1138 else
1139 status = eHAL_STATUS_SUCCESS;
1140 if (!HAL_STATUS_SUCCESS(status))
1141 break;
1142 vos_mem_set(pProfile, sizeof(tCsrRoamProfile), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001143 status = csrRoamCopyProfile(pMac, pProfile, pSession->pCurRoamProfile);
1144 if(!HAL_STATUS_SUCCESS(status))
1145 break;
1146 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1147 }//We have a profile
1148 roamId = GET_NEXT_ROAM_ID(&pMac->roam);
1149 if(HAL_STATUS_SUCCESS(status))
1150 {
1151 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1152 if(HAL_STATUS_SUCCESS(status))
1153 {
1154 if(eCsrLostLink1 == reason)
1155 {
1156 //we want to put the last connected BSS to the very beginning, if possible
1157 csrMoveBssToHeadFromBSSID(pMac, &pSession->connectedProfile.bssid, hBSSList);
1158 }
1159 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList, reason,
1160 roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1161 if(!HAL_STATUS_SUCCESS(status))
1162 {
1163 csrScanResultPurge(pMac, hBSSList);
1164 }
1165 }//Have scan result
1166 }
1167 }while(0);
1168 if(pScanFilter)
1169 {
1170 //we need to free memory for filter if profile exists
1171 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301172 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001173 }
1174 if(NULL != pProfile)
1175 {
1176 csrReleaseProfile(pMac, pProfile);
Kiet Lam64c1b492013-07-12 13:56:44 +05301177 vos_mem_free(pProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07001178 }
1179
1180 return (status);
1181}
1182
1183
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05301184eHalStatus csrScanGetScanChnInfo(tpAniSirGlobal pMac, tANI_U8 sessionId,
1185 void *pContext, void *callback)
Jeff Johnson295189b2012-06-20 16:38:30 -07001186{
1187 eHalStatus status = eHAL_STATUS_SUCCESS;
1188 tSmeCmd *pScanCmd;
1189
1190 if(pMac->scan.fScanEnable)
1191 {
1192 pScanCmd = csrGetCommandBuffer(pMac);
1193 if(pScanCmd)
1194 {
1195 pScanCmd->command = eSmeCommandScan;
Kiet Lam64c1b492013-07-12 13:56:44 +05301196 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson32d95a32012-09-10 13:15:23 -07001197 pScanCmd->u.scanCmd.callback = callback;
1198 pScanCmd->u.scanCmd.pContext = pContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07001199 pScanCmd->u.scanCmd.reason = eCsrScanGetScanChnInfo;
1200 //Need to make the following atomic
1201 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05301202 pScanCmd->sessionId = sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07001203 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
1204 if( !HAL_STATUS_SUCCESS( status ) )
1205 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001206 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001207 csrReleaseCommandScan(pMac, pScanCmd);
1208 }
1209 }
1210 else
1211 {
1212 //log error
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001213 smsLog(pMac, LOGE, FL("can not obtain a common buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001214 status = eHAL_STATUS_RESOURCES;
1215 }
1216 }
1217
1218 return (status);
1219}
1220
1221
1222eHalStatus csrScanHandleFailedLostlink1(tpAniSirGlobal pMac, tANI_U32 sessionId)
1223{
1224 eHalStatus status = eHAL_STATUS_FAILURE;
1225 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1226
Jeff Johnson32d95a32012-09-10 13:15:23 -07001227 if(!pSession)
1228 {
1229 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1230 return eHAL_STATUS_FAILURE;
1231 }
1232
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001233 smsLog(pMac, LOGW, " Lostlink scan 1 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001234 if(pSession->fCancelRoaming)
1235 {
1236 csrScanStartIdleScan(pMac);
1237 }
1238 else if(pSession->pCurRoamProfile)
1239 {
1240 //We fail lostlink1 but there may be other BSS in the cached result fit the profile. Give it a try first
1241 if(pSession->pCurRoamProfile->SSIDs.numOfSSIDs == 0 ||
1242 pSession->pCurRoamProfile->SSIDs.numOfSSIDs > 1)
1243 {
1244 //try lostlink scan2
1245 status = csrScanRequestLostLink2(pMac, sessionId);
1246 }
1247 else if(!pSession->pCurRoamProfile->ChannelInfo.ChannelList ||
1248 pSession->pCurRoamProfile->ChannelInfo.ChannelList[0] == 0)
1249 {
1250 //go straight to lostlink scan3
1251 status = csrScanRequestLostLink3(pMac, sessionId);
1252 }
1253 else
1254 {
1255 //we are done with lostlink
1256 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1257 {
1258 csrScanStartIdleScan(pMac);
1259 }
1260 status = eHAL_STATUS_SUCCESS;
1261 }
1262 }
1263 else
1264 {
1265 status = csrScanRequestLostLink3(pMac, sessionId);
1266 }
1267
1268 return (status);
1269}
1270
1271
1272
1273eHalStatus csrScanHandleFailedLostlink2(tpAniSirGlobal pMac, tANI_U32 sessionId)
1274{
1275 eHalStatus status = eHAL_STATUS_FAILURE;
1276 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1277
Jeff Johnson32d95a32012-09-10 13:15:23 -07001278 if(!pSession)
1279 {
1280 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1281 return eHAL_STATUS_FAILURE;
1282 }
1283
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001284 smsLog(pMac, LOGW, " Lostlink scan 2 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001285 if(pSession->fCancelRoaming)
1286 {
1287 csrScanStartIdleScan(pMac);
1288 }
1289 else if(!pSession->pCurRoamProfile || !pSession->pCurRoamProfile->ChannelInfo.ChannelList ||
1290 pSession->pCurRoamProfile->ChannelInfo.ChannelList[0] == 0)
1291 {
1292 //try lostlink scan3
1293 status = csrScanRequestLostLink3(pMac, sessionId);
1294 }
1295 else
1296 {
1297 //we are done with lostlink
1298 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1299 {
1300 csrScanStartIdleScan(pMac);
1301 }
1302 }
1303
1304 return (status);
1305}
1306
1307
1308
1309eHalStatus csrScanHandleFailedLostlink3(tpAniSirGlobal pMac, tANI_U32 sessionId)
1310{
1311 eHalStatus status = eHAL_STATUS_SUCCESS;
1312
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001313 smsLog(pMac, LOGW, " Lostlink scan 3 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001314 if(eANI_BOOLEAN_TRUE == csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1315 {
1316 //we are done with lostlink
1317 csrScanStartIdleScan(pMac);
1318 }
1319
1320 return (status);
1321}
1322
1323
1324
1325
1326//Lostlink1 scan is to actively scan the last connected profile's SSID on all matched BSS channels.
1327//If no roam profile (it should not), it is like lostlinkscan3
1328eHalStatus csrScanRequestLostLink1( tpAniSirGlobal pMac, tANI_U32 sessionId )
1329{
1330 eHalStatus status = eHAL_STATUS_SUCCESS;
1331 tSmeCmd *pCommand = NULL;
1332 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1333 tCsrScanResultFilter *pScanFilter = NULL;
1334 tScanResultHandle hBSSList = NULL;
1335 tCsrScanResultInfo *pScanResult = NULL;
1336 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1337
Jeff Johnson32d95a32012-09-10 13:15:23 -07001338 if(!pSession)
1339 {
1340 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1341 return eHAL_STATUS_FAILURE;
1342 }
1343
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001344 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001345 do
1346 {
1347 pCommand = csrGetCommandBuffer(pMac);
1348 if(!pCommand)
1349 {
1350 status = eHAL_STATUS_RESOURCES;
1351 break;
1352 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301353 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001354 pCommand->command = eSmeCommandScan;
1355 pCommand->sessionId = (tANI_U8)sessionId;
1356 pCommand->u.scanCmd.reason = eCsrScanLostLink1;
1357 pCommand->u.scanCmd.callback = NULL;
1358 pCommand->u.scanCmd.pContext = NULL;
1359 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1360 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001361 pCommand->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1362 pCommand->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001363 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
1364 if(pSession->connectedProfile.SSID.length)
1365 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301366 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList = vos_mem_malloc(sizeof(tCsrSSIDInfo));
1367 if ( NULL == pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList )
1368 status = eHAL_STATUS_FAILURE;
1369 else
1370 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001371 if(!HAL_STATUS_SUCCESS(status))
1372 {
1373 break;
1374 }
1375 pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 1;
Kiet Lam64c1b492013-07-12 13:56:44 +05301376 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID,
1377 &pSession->connectedProfile.SSID, sizeof(tSirMacSSid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001378 }
1379 else
1380 {
1381 pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 0;
1382 }
1383 if(pSession->pCurRoamProfile)
1384 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301385 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1386 if ( NULL == pScanFilter )
1387 status = eHAL_STATUS_FAILURE;
1388 else
1389 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001390 if(!HAL_STATUS_SUCCESS(status))
1391 {
1392 break;
1393 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301394 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001395 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
1396 if(!HAL_STATUS_SUCCESS(status))
1397 {
1398 break;
1399 }
1400 //Don't change variable status here because whether we can get result or not, the command goes to PE.
1401 //The status is also used to indicate whether the command is queued. Not success meaning not queue
1402 if(HAL_STATUS_SUCCESS((csrScanGetResult(pMac, pScanFilter, &hBSSList))) && hBSSList)
1403 {
1404 tANI_U8 i, nChn = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05301405 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList =
1406 vos_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
1407 if ( NULL == pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
1408 status = eHAL_STATUS_FAILURE;
1409 else
1410 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001411 if(!HAL_STATUS_SUCCESS(status))
1412 {
1413 break;
1414 }
1415 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) &&
1416 nChn < WNI_CFG_VALID_CHANNEL_LIST_LEN)
1417 {
1418 for(i = 0; i < nChn; i++)
1419 {
1420 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1421 pScanResult->BssDescriptor.channelId)
1422 {
1423 break;
1424 }
1425 }
1426 if(i == nChn)
1427 {
1428 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pScanResult->BssDescriptor.channelId;
1429 }
1430 }
1431 //Include the last connected BSS' channel
1432 if(csrRoamIsChannelValid(pMac, pSession->connectedProfile.operationChannel))
1433 {
1434 for(i = 0; i < nChn; i++)
1435 {
1436 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1437 pSession->connectedProfile.operationChannel)
1438 {
1439 break;
1440 }
1441 }
1442 if(i == nChn)
1443 {
1444 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pSession->connectedProfile.operationChannel;
1445 }
1446 }
1447 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nChn;
1448 }
1449 else
1450 {
1451 if(csrRoamIsChannelValid(pMac, pSession->connectedProfile.operationChannel))
1452 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301453 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(1);
1454 if ( NULL == pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
1455 status = eHAL_STATUS_FAILURE;
1456 else
1457 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001458 //just try the last connected channel
1459 if(HAL_STATUS_SUCCESS(status))
1460 {
1461 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[0] = pSession->connectedProfile.operationChannel;
1462 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 1;
1463 }
1464 else
1465 {
1466 break;
1467 }
1468 }
1469 }
1470 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301471 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001472 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
1473 if( !HAL_STATUS_SUCCESS( status ) )
1474 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001475 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001476 break;
1477 }
1478 } while( 0 );
1479
1480 if(!HAL_STATUS_SUCCESS(status))
1481 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001482 smsLog(pMac, LOGW, " csrScanRequestLostLink1 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001483 if(pCommand)
1484 {
1485 csrReleaseCommandScan(pMac, pCommand);
1486 }
1487 status = csrScanHandleFailedLostlink1( pMac, sessionId );
1488 }
1489 if(pScanFilter)
1490 {
1491 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301492 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001493 }
1494 if(hBSSList)
1495 {
1496 csrScanResultPurge(pMac, hBSSList);
1497 }
1498
1499 return( status );
1500}
1501
1502
1503//Lostlink2 scan is to actively scan the all SSIDs of the last roaming profile's on all matched BSS channels.
1504//Since MAC doesn't support multiple SSID, we scan all SSIDs and filter them afterwards
1505eHalStatus csrScanRequestLostLink2( tpAniSirGlobal pMac, tANI_U32 sessionId )
1506{
1507 eHalStatus status = eHAL_STATUS_SUCCESS;
1508 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1509 tCsrScanResultFilter *pScanFilter = NULL;
1510 tScanResultHandle hBSSList = NULL;
1511 tCsrScanResultInfo *pScanResult = NULL;
1512 tSmeCmd *pCommand = NULL;
1513 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1514
Jeff Johnson32d95a32012-09-10 13:15:23 -07001515 if(!pSession)
1516 {
1517 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1518 return eHAL_STATUS_FAILURE;
1519 }
1520
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001521 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001522 do
1523 {
1524 pCommand = csrGetCommandBuffer(pMac);
1525 if(!pCommand)
1526 {
1527 status = eHAL_STATUS_RESOURCES;
1528 break;
1529 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301530 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001531 pCommand->command = eSmeCommandScan;
1532 pCommand->sessionId = (tANI_U8)sessionId;
1533 pCommand->u.scanCmd.reason = eCsrScanLostLink2;
1534 pCommand->u.scanCmd.callback = NULL;
1535 pCommand->u.scanCmd.pContext = NULL;
1536 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1537 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001538 pCommand->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1539 pCommand->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001540 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
1541 if(pSession->pCurRoamProfile)
1542 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301543 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1544 if ( NULL == pScanFilter )
1545 status = eHAL_STATUS_FAILURE;
1546 else
1547 status = eHAL_STATUS_SUCCESS;
1548 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001549 {
1550 break;
1551 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301552 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001553 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
1554 if(!HAL_STATUS_SUCCESS(status))
1555 {
1556 break;
1557 }
1558 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1559 if(!HAL_STATUS_SUCCESS(status))
1560 {
1561 break;
1562 }
1563 if(hBSSList)
1564 {
1565 tANI_U8 i, nChn = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05301566 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList =
1567 vos_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
1568 if ( NULL == pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
1569 status = eHAL_STATUS_FAILURE;
1570 else
1571 status = eHAL_STATUS_SUCCESS;
1572 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001573 {
1574 break;
1575 }
1576 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) &&
1577 nChn < WNI_CFG_VALID_CHANNEL_LIST_LEN)
1578 {
1579 for(i = 0; i < nChn; i++)
1580 {
1581 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1582 pScanResult->BssDescriptor.channelId)
1583 {
1584 break;
1585 }
1586 }
1587 if(i == nChn)
1588 {
1589 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pScanResult->BssDescriptor.channelId;
1590 }
1591 }
1592 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nChn;
1593 }
1594 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301595 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001596 //Put to the head in pending queue
1597 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_TRUE);
1598 if( !HAL_STATUS_SUCCESS( status ) )
1599 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001600 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001601 break;
1602 }
1603 } while( 0 );
1604
1605 if(!HAL_STATUS_SUCCESS(status))
1606 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001607 smsLog(pMac, LOGW, " csrScanRequestLostLink2 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001608 if(pCommand)
1609 {
1610 csrReleaseCommandScan(pMac, pCommand);
1611 }
1612 status = csrScanHandleFailedLostlink2( pMac, sessionId );
1613 }
1614 if(pScanFilter)
1615 {
1616 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301617 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001618 }
1619 if(hBSSList)
1620 {
1621 csrScanResultPurge(pMac, hBSSList);
1622 }
1623
1624 return( status );
1625}
1626
1627
1628//To actively scan all valid channels
1629eHalStatus csrScanRequestLostLink3( tpAniSirGlobal pMac, tANI_U32 sessionId )
1630{
1631 eHalStatus status = eHAL_STATUS_SUCCESS;
1632 tSmeCmd *pCommand;
1633 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1634
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001635 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001636 do
1637 {
1638 pCommand = csrGetCommandBuffer(pMac);
1639 if(!pCommand)
1640 {
1641 status = eHAL_STATUS_RESOURCES;
1642 break;
1643 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301644 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001645 pCommand->command = eSmeCommandScan;
1646 pCommand->sessionId = (tANI_U8)sessionId;
1647 pCommand->u.scanCmd.reason = eCsrScanLostLink3;
1648 pCommand->u.scanCmd.callback = NULL;
1649 pCommand->u.scanCmd.pContext = NULL;
1650 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1651 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001652 pCommand->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1653 pCommand->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001654 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Kiet Lam64c1b492013-07-12 13:56:44 +05301655 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001656 //Put to the head of pending queue
1657 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_TRUE);
1658 if( !HAL_STATUS_SUCCESS( status ) )
1659 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001660 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001661 break;
1662 }
1663 } while( 0 );
1664 if(!HAL_STATUS_SUCCESS(status))
1665 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001666 smsLog(pMac, LOGW, " csrScanRequestLostLink3 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001667 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1668 {
1669 csrScanStartIdleScan(pMac);
1670 }
1671 if(pCommand)
1672 {
1673 csrReleaseCommandScan(pMac, pCommand);
1674 }
1675 }
1676
1677 return( status );
1678}
1679
1680
1681eHalStatus csrScanHandleSearchForSSID(tpAniSirGlobal pMac, tSmeCmd *pCommand)
1682{
1683 eHalStatus status = eHAL_STATUS_FAILURE;
1684 tScanResultHandle hBSSList = CSR_INVALID_SCANRESULT_HANDLE;
1685 tCsrScanResultFilter *pScanFilter = NULL;
1686 tCsrRoamProfile *pProfile = pCommand->u.scanCmd.pToRoamProfile;
1687 tANI_U32 sessionId = pCommand->sessionId;
1688#ifdef FEATURE_WLAN_BTAMP_UT_RF
1689 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1690#endif
1691 do
1692 {
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001693#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
1694 //if this scan is for LFR
1695 if(pMac->roam.neighborRoamInfo.uOsRequestedHandoff)
1696 {
1697 //notify LFR state m/c
1698 if(eHAL_STATUS_SUCCESS != csrNeighborRoamSssidScanDone(pMac, eHAL_STATUS_SUCCESS))
1699 {
Varun Reddy Yeturue3af4282013-06-07 00:56:52 -07001700 csrNeighborRoamStartLfrScan(pMac);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001701 }
1702 status = eHAL_STATUS_SUCCESS;
1703 break;
1704 }
1705#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001706 //If there is roam command waiting, ignore this roam because the newer roam command is the one to execute
1707 if(csrIsRoamCommandWaitingForSession(pMac, sessionId))
1708 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001709 smsLog(pMac, LOGW, FL(" aborts because roam command waiting"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001710 break;
1711 }
1712 if(pProfile == NULL)
1713 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301714 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1715 if ( NULL == pScanFilter )
1716 status = eHAL_STATUS_FAILURE;
1717 else
1718 status = eHAL_STATUS_SUCCESS;
1719 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001720 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301721 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001722 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1723 if(!HAL_STATUS_SUCCESS(status))
1724 break;
1725 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1726 if(!HAL_STATUS_SUCCESS(status))
1727 break;
1728 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList, eCsrHddIssued,
1729 pCommand->u.scanCmd.roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1730 if(!HAL_STATUS_SUCCESS(status))
1731 {
1732 break;
1733 }
1734 }while(0);
1735 if(!HAL_STATUS_SUCCESS(status))
1736 {
1737 if(CSR_INVALID_SCANRESULT_HANDLE != hBSSList)
1738 {
1739 csrScanResultPurge(pMac, hBSSList);
1740 }
1741 //We haven't done anything to this profile
1742 csrRoamCallCallback(pMac, sessionId, NULL, pCommand->u.scanCmd.roamId,
1743 eCSR_ROAM_ASSOCIATION_FAILURE, eCSR_ROAM_RESULT_FAILURE);
1744 //In case we have nothing else to do, restart idle scan
1745 if(csrIsConnStateDisconnected(pMac, sessionId) && !csrIsRoamCommandWaiting(pMac))
1746 {
1747 status = csrScanStartIdleScan(pMac);
1748 }
1749#ifdef FEATURE_WLAN_BTAMP_UT_RF
1750 //In case of WDS station, let it retry.
1751 if( CSR_IS_WDS_STA(pProfile) )
1752 {
1753 //Save the roma profile so we can retry
1754 csrFreeRoamProfile( pMac, sessionId );
Kiet Lam64c1b492013-07-12 13:56:44 +05301755 pSession->pCurRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1756 if ( NULL != pSession->pCurRoamProfile )
Jeff Johnson295189b2012-06-20 16:38:30 -07001757 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301758 vos_mem_set(pSession->pCurRoamProfilee, sizeof(tCsrRoamProfile), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001759 csrRoamCopyProfile(pMac, pSession->pCurRoamProfile, pProfile);
1760 }
1761 csrRoamStartJoinRetryTimer(pMac, sessionId, CSR_JOIN_RETRY_TIMEOUT_PERIOD);
1762 }
1763#endif
1764 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301765 if (pScanFilter)
Jeff Johnson295189b2012-06-20 16:38:30 -07001766 {
1767 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301768 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001769 }
1770
1771 return (status);
1772}
1773
1774
1775eHalStatus csrScanHandleSearchForSSIDFailure(tpAniSirGlobal pMac, tSmeCmd *pCommand)
1776{
1777 eHalStatus status = eHAL_STATUS_SUCCESS;
1778 tANI_U32 sessionId = pCommand->sessionId;
1779 tCsrRoamProfile *pProfile = pCommand->u.scanCmd.pToRoamProfile;
1780 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001781#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
1782 //if this scan is for LFR
1783 if(pMac->roam.neighborRoamInfo.uOsRequestedHandoff)
1784 {
1785 //notify LFR state m/c
1786 if(eHAL_STATUS_SUCCESS != csrNeighborRoamSssidScanDone(pMac, eHAL_STATUS_FAILURE))
1787 {
Varun Reddy Yeturue3af4282013-06-07 00:56:52 -07001788 csrNeighborRoamStartLfrScan(pMac);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001789 }
1790 return eHAL_STATUS_SUCCESS;
1791 }
1792#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -07001793 if(!pSession)
1794 {
1795 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1796 return eHAL_STATUS_FAILURE;
1797 }
1798
Jeff Johnson295189b2012-06-20 16:38:30 -07001799#if defined(WLAN_DEBUG)
1800 if(pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs == 1)
1801 {
1802 char str[36];
Kiet Lam64c1b492013-07-12 13:56:44 +05301803 vos_mem_copy(str,
1804 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.ssId,
1805 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.length);
Jeff Johnson295189b2012-06-20 16:38:30 -07001806 str[pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.length] = 0;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001807 smsLog(pMac, LOGW, FL(" SSID = %s"), str);
Jeff Johnson295189b2012-06-20 16:38:30 -07001808 }
1809#endif
1810 //Check whether it is for start ibss. No need to do anything if it is a JOIN request
1811 if(pProfile && CSR_IS_START_IBSS(pProfile))
1812 {
1813 status = csrRoamIssueConnect(pMac, sessionId, pProfile, NULL, eCsrHddIssued,
1814 pCommand->u.scanCmd.roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1815 if(!HAL_STATUS_SUCCESS(status))
1816 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001817 smsLog(pMac, LOGE, FL("failed to issue startIBSS command with status = 0x%08X"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001818 csrRoamCallCallback(pMac, sessionId, NULL, pCommand->u.scanCmd.roamId, eCSR_ROAM_FAILED, eCSR_ROAM_RESULT_FAILURE);
1819 }
1820 }
1821 else
1822 {
1823 eCsrRoamResult roamResult = eCSR_ROAM_RESULT_FAILURE;
1824
1825 if(csrIsConnStateDisconnected(pMac, sessionId) &&
1826 !csrIsRoamCommandWaitingForSession(pMac, sessionId))
1827 {
1828 status = csrScanStartIdleScan(pMac);
1829 }
1830 if((NULL == pProfile) || !csrIsBssTypeIBSS(pProfile->BSSType))
1831 {
1832 //Only indicate assoc_completion if we indicate assoc_start.
1833 if(pSession->bRefAssocStartCnt > 0)
1834 {
1835 tCsrRoamInfo *pRoamInfo = NULL, roamInfo;
Kiet Lam64c1b492013-07-12 13:56:44 +05301836 vos_mem_set(&roamInfo, sizeof(tCsrRoamInfo), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001837 pRoamInfo = &roamInfo;
1838 if(pCommand->u.roamCmd.pRoamBssEntry)
1839 {
1840 tCsrScanResult *pScanResult =
1841 GET_BASE_ADDR(pCommand->u.roamCmd.pRoamBssEntry,
1842 tCsrScanResult, Link);
1843 roamInfo.pBssDesc = &pScanResult->Result.BssDescriptor;
1844 }
1845 roamInfo.statusCode = pSession->joinFailStatusCode.statusCode;
1846 roamInfo.reasonCode = pSession->joinFailStatusCode.reasonCode;
1847 pSession->bRefAssocStartCnt--;
1848 csrRoamCallCallback(pMac, sessionId, pRoamInfo,
1849 pCommand->u.scanCmd.roamId,
1850 eCSR_ROAM_ASSOCIATION_COMPLETION,
1851 eCSR_ROAM_RESULT_FAILURE);
1852 }
Madan Mohan Koyyalamudiee255f12012-09-28 15:41:19 -07001853 else
1854 {
1855 csrRoamCallCallback(pMac, sessionId, NULL,
1856 pCommand->u.scanCmd.roamId,
1857 eCSR_ROAM_ASSOCIATION_FAILURE,
1858 eCSR_ROAM_RESULT_FAILURE);
1859 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001860#ifdef FEATURE_WLAN_BTAMP_UT_RF
1861 //In case of WDS station, let it retry.
1862 if( CSR_IS_WDS_STA(pProfile) )
1863 {
1864 //Save the roma profile so we can retry
1865 csrFreeRoamProfile( pMac, sessionId );
Kiet Lam64c1b492013-07-12 13:56:44 +05301866 pSession->pCurRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1867 if ( NULL != pSession->pCurRoamProfile )
Jeff Johnson295189b2012-06-20 16:38:30 -07001868 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301869 vos_mem_set(pSession->pCurRoamProfile, sizeof(tCsrRoamProfile), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001870 csrRoamCopyProfile(pMac, pSession->pCurRoamProfile, pProfile);
1871 }
1872 csrRoamStartJoinRetryTimer(pMac, sessionId, CSR_JOIN_RETRY_TIMEOUT_PERIOD);
1873 }
1874#endif
1875 }
1876 else
1877 {
1878 roamResult = eCSR_ROAM_RESULT_IBSS_START_FAILED;
1879 }
1880 csrRoamCompletion(pMac, sessionId, NULL, pCommand, roamResult, eANI_BOOLEAN_FALSE);
1881 }
1882
1883 return (status);
1884}
1885
1886
1887//After scan for cap changes, issue a roaming command to either reconnect to the AP or pick another one to connect
1888eHalStatus csrScanHandleCapChangeScanComplete(tpAniSirGlobal pMac, tANI_U32 sessionId)
1889{
1890 eHalStatus status = eHAL_STATUS_FAILURE;
1891 tScanResultHandle hBSSList = NULL;
1892 tCsrScanResultFilter *pScanFilter = NULL;
1893 tANI_U32 roamId = 0;
1894 tCsrRoamProfile *pProfile = NULL;
1895 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1896
1897 do
1898 {
1899 //Here is the profile we need to connect to
Kiet Lam64c1b492013-07-12 13:56:44 +05301900 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1901 if ( NULL == pScanFilter )
1902 status = eHAL_STATUS_FAILURE;
1903 else
1904 status = eHAL_STATUS_SUCCESS;
1905 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001906 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301907 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
1908 if (NULL == pSession) break;
1909 if (NULL == pSession->pCurRoamProfile)
Jeff Johnson295189b2012-06-20 16:38:30 -07001910 {
1911 pScanFilter->EncryptionType.numEntries = 1;
1912 pScanFilter->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_NONE;
1913 }
1914 else
1915 {
1916 //We have to make a copy of pCurRoamProfile because it will be free inside csrRoamIssueConnect
Kiet Lam64c1b492013-07-12 13:56:44 +05301917 pProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1918 if ( NULL == pProfile )
1919 status = eHAL_STATUS_FAILURE;
1920 else
1921 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001922 if(!HAL_STATUS_SUCCESS(status))
1923 break;
1924 status = csrRoamCopyProfile(pMac, pProfile, pSession->pCurRoamProfile);
1925 if(!HAL_STATUS_SUCCESS(status))
1926 break;
1927 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1928 }//We have a profile
1929 roamId = GET_NEXT_ROAM_ID(&pMac->roam);
1930 if(HAL_STATUS_SUCCESS(status))
1931 {
1932 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1933 if(HAL_STATUS_SUCCESS(status))
1934 {
1935 //we want to put the last connected BSS to the very beginning, if possible
1936 csrMoveBssToHeadFromBSSID(pMac, &pSession->connectedProfile.bssid, hBSSList);
1937 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList,
1938 eCsrCapsChange, 0, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1939 if(!HAL_STATUS_SUCCESS(status))
1940 {
1941 csrScanResultPurge(pMac, hBSSList);
1942 }
1943 }//Have scan result
1944 else
1945 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001946 smsLog(pMac, LOGW, FL("cannot find matching BSS of %02X-%02X-%02X-%02X-%02X-%02X"),
Jeff Johnson295189b2012-06-20 16:38:30 -07001947 pSession->connectedProfile.bssid[0],
1948 pSession->connectedProfile.bssid[1],
1949 pSession->connectedProfile.bssid[2],
1950 pSession->connectedProfile.bssid[3],
1951 pSession->connectedProfile.bssid[4],
1952 pSession->connectedProfile.bssid[5]);
1953 //Disconnect
1954 csrRoamDisconnectInternal(pMac, sessionId, eCSR_DISCONNECT_REASON_UNSPECIFIED);
1955 }
1956 }
1957 }while(0);
1958 if(pScanFilter)
1959 {
1960 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301961 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001962 }
1963 if(NULL != pProfile)
1964 {
1965 csrReleaseProfile(pMac, pProfile);
Kiet Lam64c1b492013-07-12 13:56:44 +05301966 vos_mem_free(pProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07001967 }
1968
1969 return (status);
1970}
1971
1972
1973
1974eHalStatus csrScanResultPurge(tpAniSirGlobal pMac, tScanResultHandle hScanList)
1975{
1976 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
1977 tScanResultList *pScanList = (tScanResultList *)hScanList;
1978
1979 if(pScanList)
1980 {
1981 status = csrLLScanPurgeResult(pMac, &pScanList->List);
1982 csrLLClose(&pScanList->List);
Kiet Lam64c1b492013-07-12 13:56:44 +05301983 vos_mem_free(pScanList);
Jeff Johnson295189b2012-06-20 16:38:30 -07001984 }
1985 return (status);
1986}
1987
1988
1989static tANI_U32 csrGetBssPreferValue(tpAniSirGlobal pMac, int rssi)
1990{
1991 tANI_U32 ret = 0;
1992 int i = CSR_NUM_RSSI_CAT - 1;
1993
1994 while(i >= 0)
1995 {
1996 if(rssi >= pMac->roam.configParam.RSSICat[i])
1997 {
1998 ret = pMac->roam.configParam.BssPreferValue[i];
1999 break;
2000 }
2001 i--;
2002 };
2003
2004 return (ret);
2005}
2006
2007
2008//Return a CapValue base on the capabilities of a BSS
2009static tANI_U32 csrGetBssCapValue(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes)
2010{
2011 tANI_U32 ret = CSR_BSS_CAP_VALUE_NONE;
Madan Mohan Koyyalamudid5026072012-11-30 14:56:21 -08002012#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_CCX) || defined(FEATURE_WLAN_LFR)
2013 if(CSR_IS_ROAM_PREFER_5GHZ(pMac))
2014 {
2015 if((pBssDesc) && CSR_IS_CHANNEL_5GHZ(pBssDesc->channelId))
2016 {
2017 ret += CSR_BSS_CAP_VALUE_5GHZ;
2018 }
2019 }
2020#endif
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002021 /* if strict select 5GHz is non-zero then ignore the capability checking */
2022 if (pIes && !CSR_IS_SELECT_5GHZ_MARGIN(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -07002023 {
2024 //We only care about 11N capability
2025 if(pIes->HTCaps.present)
2026 {
2027 ret += CSR_BSS_CAP_VALUE_HT;
2028 }
2029 if(CSR_IS_QOS_BSS(pIes))
2030 {
2031 ret += CSR_BSS_CAP_VALUE_WMM;
2032 //Give advantage to UAPSD
2033 if(CSR_IS_UAPSD_BSS(pIes))
2034 {
2035 ret += CSR_BSS_CAP_VALUE_UAPSD;
2036 }
2037 }
2038 }
2039
2040 return (ret);
2041}
2042
2043
2044//To check whther pBss1 is better than pBss2
2045static tANI_BOOLEAN csrIsBetterBss(tCsrScanResult *pBss1, tCsrScanResult *pBss2)
2046{
2047 tANI_BOOLEAN ret;
2048
2049 if(CSR_IS_BETTER_PREFER_VALUE(pBss1->preferValue, pBss2->preferValue))
2050 {
2051 ret = eANI_BOOLEAN_TRUE;
2052 }
2053 else if(CSR_IS_EQUAL_PREFER_VALUE(pBss1->preferValue, pBss2->preferValue))
2054 {
2055 if(CSR_IS_BETTER_CAP_VALUE(pBss1->capValue, pBss2->capValue))
2056 {
2057 ret = eANI_BOOLEAN_TRUE;
2058 }
2059 else
2060 {
2061 ret = eANI_BOOLEAN_FALSE;
2062 }
2063 }
2064 else
2065 {
2066 ret = eANI_BOOLEAN_FALSE;
2067 }
2068
2069 return (ret);
2070}
2071
2072
Srikant Kuppa866893f2012-12-27 17:28:14 -08002073#ifdef FEATURE_WLAN_LFR
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002074//Add the channel to the occupiedChannels array
2075static void csrScanAddToOccupiedChannels(
Srikant Kuppa866893f2012-12-27 17:28:14 -08002076 tpAniSirGlobal pMac,
2077 tCsrScanResult *pResult,
2078 tCsrChannel *pOccupiedChannels,
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002079 tDot11fBeaconIEs *pIes)
2080{
2081 eHalStatus status;
2082 tANI_U8 channel;
2083 tANI_U8 numOccupiedChannels = pOccupiedChannels->numChannels;
2084 tANI_U8 *pOccupiedChannelList = pOccupiedChannels->channelList;
2085
2086 channel = pResult->Result.BssDescriptor.channelId;
2087
2088 if (!csrIsChannelPresentInList(pOccupiedChannelList, numOccupiedChannels, channel)
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08002089 && csrNeighborRoamConnectedProfileMatch(pMac, pResult, pIes))
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002090 {
Srikant Kuppa866893f2012-12-27 17:28:14 -08002091 status = csrAddToChannelListFront(pOccupiedChannelList, numOccupiedChannels, channel);
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002092 if(HAL_STATUS_SUCCESS(status))
Srikant Kuppa866893f2012-12-27 17:28:14 -08002093 {
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002094 pOccupiedChannels->numChannels++;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002095 smsLog(pMac, LOG2, FL("%s: added channel %d to the list (count=%d)"),
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08002096 __func__, channel, pOccupiedChannels->numChannels);
Srikant Kuppa866893f2012-12-27 17:28:14 -08002097 if (pOccupiedChannels->numChannels > CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN)
2098 pOccupiedChannels->numChannels = CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN;
2099 }
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002100 }
2101}
2102#endif
2103
Jeff Johnson295189b2012-06-20 16:38:30 -07002104//Put the BSS into the scan result list
2105//pIes can not be NULL
2106static void csrScanAddResult(tpAniSirGlobal pMac, tCsrScanResult *pResult, tDot11fBeaconIEs *pIes)
2107{
Srinivas28b5b4e2012-12-12 13:07:53 -08002108#ifdef FEATURE_WLAN_LFR
2109 tpCsrNeighborRoamControlInfo pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
2110#endif
2111
Jeff Johnson295189b2012-06-20 16:38:30 -07002112 pResult->preferValue = csrGetBssPreferValue(pMac, (int)pResult->Result.BssDescriptor.rssi);
2113 pResult->capValue = csrGetBssCapValue(pMac, &pResult->Result.BssDescriptor, pIes);
2114 csrLLInsertTail( &pMac->scan.scanResultList, &pResult->Link, LL_ACCESS_LOCK );
Srikant Kuppa866893f2012-12-27 17:28:14 -08002115#ifdef FEATURE_WLAN_LFR
Srinivas28b5b4e2012-12-12 13:07:53 -08002116 if(0 == pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels)
2117 {
2118 /* Build the occupied channel list, only if "gNeighborScanChannelList" is
2119 NOT set in the cfg.ini file */
2120 csrScanAddToOccupiedChannels(pMac, pResult, &pMac->scan.occupiedChannels, pIes);
2121 }
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002122#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002123}
2124
2125
2126eHalStatus csrScanGetResult(tpAniSirGlobal pMac, tCsrScanResultFilter *pFilter, tScanResultHandle *phResult)
2127{
2128 eHalStatus status;
2129 tScanResultList *pRetList;
2130 tCsrScanResult *pResult, *pBssDesc;
2131 tANI_U32 count = 0;
2132 tListElem *pEntry;
2133 tANI_U32 bssLen, allocLen;
2134 eCsrEncryptionType uc = eCSR_ENCRYPT_TYPE_NONE, mc = eCSR_ENCRYPT_TYPE_NONE;
2135 eCsrAuthType auth = eCSR_AUTH_TYPE_OPEN_SYSTEM;
2136 tDot11fBeaconIEs *pIes, *pNewIes;
2137 tANI_BOOLEAN fMatch;
2138
2139 if(phResult)
2140 {
2141 *phResult = CSR_INVALID_SCANRESULT_HANDLE;
2142 }
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002143
2144 if (pMac->roam.configParam.nSelect5GHzMargin)
2145 {
2146 pMac->scan.inScanResultBestAPRssi = -128;
2147 csrLLLock(&pMac->scan.scanResultList);
2148
2149 /* Find out the best AP Rssi going thru the scan results */
2150 pEntry = csrLLPeekHead(&pMac->scan.scanResultList, LL_ACCESS_NOLOCK);
2151 while ( NULL != pEntry)
2152 {
2153 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2154 if (pBssDesc->Result.BssDescriptor.rssi > pMac->scan.inScanResultBestAPRssi)
2155 {
2156 pMac->scan.inScanResultBestAPRssi = pBssDesc->Result.BssDescriptor.rssi;
2157 }
2158 pEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
2159 }
2160
2161 /* Modify Rssi category based on best AP Rssi */
2162 csrAssignRssiForCategory(pMac, pMac->scan.inScanResultBestAPRssi, pMac->roam.configParam.bCatRssiOffset);
2163 pEntry = csrLLPeekHead(&pMac->scan.scanResultList, LL_ACCESS_NOLOCK);
2164 while ( NULL != pEntry)
2165 {
2166 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2167
2168 /* re-assign preference value based on modified rssi bucket */
2169 pBssDesc->preferValue = csrGetBssPreferValue(pMac, (int)pBssDesc->Result.BssDescriptor.rssi);
2170
2171 pEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
2172 }
2173
2174 csrLLUnlock(&pMac->scan.scanResultList);
2175 }
2176
Kiet Lam64c1b492013-07-12 13:56:44 +05302177 pRetList = vos_mem_malloc(sizeof(tScanResultList));
2178 if ( NULL == pRetList )
2179 status = eHAL_STATUS_FAILURE;
2180 else
2181 status = eHAL_STATUS_SUCCESS;
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002182 if(HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07002183 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302184 vos_mem_set(pRetList, sizeof(tScanResultList), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002185 csrLLOpen(pMac->hHdd, &pRetList->List);
2186 pRetList->pCurEntry = NULL;
2187
2188 csrLLLock(&pMac->scan.scanResultList);
2189 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
2190 while( pEntry )
2191 {
2192 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2193 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
2194 //if pBssDesc->Result.pvIes is NULL, we need to free any memory allocated by csrMatchBSS
2195 //for any error condition, otherwiase, it will be freed later.
2196 //reset
2197 fMatch = eANI_BOOLEAN_FALSE;
2198 pNewIes = NULL;
2199
2200 if(pFilter)
2201 {
2202 fMatch = csrMatchBSS(pMac, &pBssDesc->Result.BssDescriptor, pFilter, &auth, &uc, &mc, &pIes);
2203 if( NULL != pIes )
2204 {
2205 //Only save it when matching
2206 if(fMatch)
2207 {
2208 if( !pBssDesc->Result.pvIes )
2209 {
2210 //csrMatchBSS allocates the memory. Simply pass it and it is freed later
2211 pNewIes = pIes;
2212 }
2213 else
2214 {
2215 //The pIes is allocated by someone else. make a copy
2216 //Only to save parsed IEs if caller provides a filter. Most likely the caller
2217 //is using to for association, hence save the parsed IEs
Kiet Lam64c1b492013-07-12 13:56:44 +05302218 pNewIes = vos_mem_malloc(sizeof(tDot11fBeaconIEs));
2219 if ( NULL == pNewIes )
2220 status = eHAL_STATUS_FAILURE;
2221 else
2222 status = eHAL_STATUS_SUCCESS;
2223 if ( HAL_STATUS_SUCCESS( status ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07002224 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302225 vos_mem_copy(pNewIes, pIes, sizeof( tDot11fBeaconIEs ));
Jeff Johnson295189b2012-06-20 16:38:30 -07002226 }
2227 else
2228 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002229 smsLog(pMac, LOGE, FL(" fail to allocate memory for IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002230 //Need to free memory allocated by csrMatchBSS
2231 if( !pBssDesc->Result.pvIes )
2232 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302233 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07002234 }
2235 break;
2236 }
2237 }
2238 }//fMatch
2239 else if( !pBssDesc->Result.pvIes )
2240 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302241 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07002242 }
2243 }
2244 }
2245 if(NULL == pFilter || fMatch)
2246 {
2247 bssLen = pBssDesc->Result.BssDescriptor.length + sizeof(pBssDesc->Result.BssDescriptor.length);
2248 allocLen = sizeof( tCsrScanResult ) + bssLen;
Kiet Lam64c1b492013-07-12 13:56:44 +05302249 pResult = vos_mem_malloc(allocLen);
2250 if ( NULL == pResult )
2251 status = eHAL_STATUS_FAILURE;
2252 else
2253 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07002254 if(!HAL_STATUS_SUCCESS(status))
2255 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002256 smsLog(pMac, LOGE, FL(" fail to allocate memory for scan result, len=%d"), allocLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07002257 if(pNewIes)
2258 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302259 vos_mem_free(pNewIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07002260 }
2261 break;
2262 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302263 vos_mem_set(pResult, allocLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002264 pResult->capValue = pBssDesc->capValue;
2265 pResult->preferValue = pBssDesc->preferValue;
2266 pResult->ucEncryptionType = uc;
2267 pResult->mcEncryptionType = mc;
2268 pResult->authType = auth;
2269 pResult->Result.ssId = pBssDesc->Result.ssId;
2270 pResult->Result.timer = 0;
2271 //save the pIes for later use
2272 pResult->Result.pvIes = pNewIes;
2273 //save bss description
Kiet Lam64c1b492013-07-12 13:56:44 +05302274 vos_mem_copy(&pResult->Result.BssDescriptor,
2275 &pBssDesc->Result.BssDescriptor, bssLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07002276 //No need to lock pRetList because it is locally allocated and no outside can access it at this time
2277 if(csrLLIsListEmpty(&pRetList->List, LL_ACCESS_NOLOCK))
2278 {
2279 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_NOLOCK);
2280 }
2281 else
2282 {
2283 //To sort the list
2284 tListElem *pTmpEntry;
2285 tCsrScanResult *pTmpResult;
2286
2287 pTmpEntry = csrLLPeekHead(&pRetList->List, LL_ACCESS_NOLOCK);
2288 while(pTmpEntry)
2289 {
2290 pTmpResult = GET_BASE_ADDR( pTmpEntry, tCsrScanResult, Link );
2291 if(csrIsBetterBss(pResult, pTmpResult))
2292 {
2293 csrLLInsertEntry(&pRetList->List, pTmpEntry, &pResult->Link, LL_ACCESS_NOLOCK);
2294 //To indicate we are done
2295 pResult = NULL;
2296 break;
2297 }
2298 pTmpEntry = csrLLNext(&pRetList->List, pTmpEntry, LL_ACCESS_NOLOCK);
2299 }
2300 if(pResult != NULL)
2301 {
2302 //This one is not better than any one
2303 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_NOLOCK);
2304 }
2305 }
2306 count++;
2307 }
2308 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK );
2309 }//while
2310 csrLLUnlock(&pMac->scan.scanResultList);
2311
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002312 smsLog(pMac, LOG2, FL("return %d BSS"), csrLLCount(&pRetList->List));
Jeff Johnson295189b2012-06-20 16:38:30 -07002313
2314 if( !HAL_STATUS_SUCCESS(status) || (phResult == NULL) )
2315 {
2316 //Fail or No one wants the result.
2317 csrScanResultPurge(pMac, (tScanResultHandle)pRetList);
2318 }
2319 else
2320 {
2321 if(0 == count)
2322 {
2323 //We are here meaning the there is no match
2324 csrLLClose(&pRetList->List);
Kiet Lam64c1b492013-07-12 13:56:44 +05302325 vos_mem_free(pRetList);
Jeff Johnson295189b2012-06-20 16:38:30 -07002326 status = eHAL_STATUS_E_NULL_VALUE;
2327 }
2328 else if(phResult)
2329 {
2330 *phResult = pRetList;
2331 }
2332 }
2333 }//Allocated pRetList
2334
2335 return (status);
2336}
2337
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002338/*
2339 * NOTE: This routine is being added to make
2340 * sure that scan results are not being flushed
2341 * while roaming. If the scan results are flushed,
2342 * we are unable to recover from
2343 * csrRoamRoamingStateDisassocRspProcessor.
2344 * If it is needed to remove this routine,
2345 * first ensure that we recover gracefully from
2346 * csrRoamRoamingStateDisassocRspProcessor if
2347 * csrScanGetResult returns with a failure because
2348 * of not being able to find the roaming BSS.
2349 */
2350tANI_U8 csrScanFlushDenied(tpAniSirGlobal pMac)
2351{
2352 switch(pMac->roam.neighborRoamInfo.neighborRoamState) {
2353 case eCSR_NEIGHBOR_ROAM_STATE_REPORT_SCAN:
2354 case eCSR_NEIGHBOR_ROAM_STATE_PREAUTHENTICATING:
2355 case eCSR_NEIGHBOR_ROAM_STATE_PREAUTH_DONE:
2356 case eCSR_NEIGHBOR_ROAM_STATE_REASSOCIATING:
2357 return (pMac->roam.neighborRoamInfo.neighborRoamState);
2358 default:
2359 return 0;
2360 }
2361}
2362
Jeff Johnson295189b2012-06-20 16:38:30 -07002363eHalStatus csrScanFlushResult(tpAniSirGlobal pMac)
2364{
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002365 tANI_U8 isFlushDenied = csrScanFlushDenied(pMac);
2366 if (isFlushDenied) {
2367 smsLog(pMac, LOGW, "%s: scan flush denied in roam state %d",
2368 __func__, isFlushDenied);
2369 return eHAL_STATUS_FAILURE;
2370 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002371 return ( csrLLScanPurgeResult(pMac, &pMac->scan.scanResultList) );
2372}
2373
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302374eHalStatus csrScanFlushSelectiveResult(tpAniSirGlobal pMac, v_BOOL_t flushP2P)
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002375{
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302376 eHalStatus status = eHAL_STATUS_SUCCESS;
2377 tListElem *pEntry,*pFreeElem;
2378 tCsrScanResult *pBssDesc;
2379 tDblLinkList *pList = &pMac->scan.scanResultList;
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002380
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302381 csrLLLock(pList);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002382
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302383 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK );
2384 while( pEntry != NULL)
2385 {
2386 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2387 if( flushP2P == vos_mem_compare( pBssDesc->Result.ssId.ssId,
2388 "DIRECT-", 7) )
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002389 {
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302390 pFreeElem = pEntry;
2391 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2392 csrLLRemoveEntry(pList, pFreeElem, LL_ACCESS_NOLOCK);
2393 csrFreeScanResultEntry( pMac, pBssDesc );
2394 continue;
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002395 }
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302396 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2397 }
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002398
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302399 csrLLUnlock(pList);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002400
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302401 return (status);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002402}
2403
Jeff Johnson295189b2012-06-20 16:38:30 -07002404/**
2405 * csrCheck11dChannel
2406 *
2407 *FUNCTION:
2408 * This function is called from csrScanFilter11dResult function and
2409 * compare channel number with given channel list.
2410 *
2411 *LOGIC:
2412 * Check Scan result channel number with CFG channel list
2413 *
2414 *ASSUMPTIONS:
2415 *
2416 *
2417 *NOTE:
2418 *
2419 * @param channelId channel number
2420 * @param pChannelList Pointer to channel list
2421 * @param numChannels Number of channel in channel list
2422 *
2423 * @return Status
2424 */
2425
2426eHalStatus csrCheck11dChannel(tANI_U8 channelId, tANI_U8 *pChannelList, tANI_U32 numChannels)
2427{
2428 eHalStatus status = eHAL_STATUS_FAILURE;
2429 tANI_U8 i = 0;
2430
2431 for (i = 0; i < numChannels; i++)
2432 {
2433 if(pChannelList[ i ] == channelId)
2434 {
2435 status = eHAL_STATUS_SUCCESS;
2436 break;
2437 }
2438 }
2439 return status;
2440}
2441
2442/**
2443 * csrScanFilter11dResult
2444 *
2445 *FUNCTION:
2446 * This function is called from csrApplyCountryInformation function and
2447 * filter scan result based on valid channel list number.
2448 *
2449 *LOGIC:
2450 * Get scan result from scan list and Check Scan result channel number
2451 * with 11d channel list if channel number is found in 11d channel list
2452 * then do not remove scan result entry from scan list
2453 *
2454 *ASSUMPTIONS:
2455 *
2456 *
2457 *NOTE:
2458 *
2459 * @param pMac Pointer to Global MAC structure
2460 *
2461 * @return Status
2462 */
2463
2464eHalStatus csrScanFilter11dResult(tpAniSirGlobal pMac)
2465{
2466 eHalStatus status = eHAL_STATUS_SUCCESS;
2467 tListElem *pEntry,*pTempEntry;
2468 tCsrScanResult *pBssDesc;
2469 tANI_U32 len = sizeof(pMac->roam.validChannelList);
2470
2471 /* Get valid channels list from CFG */
2472 if (!HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac,
2473 pMac->roam.validChannelList, &len)))
2474 {
2475 smsLog( pMac, LOG1, "Failed to get Channel list from CFG");
2476 }
2477
2478 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
2479 while( pEntry )
2480 {
2481 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2482 pTempEntry = csrLLNext( &pMac->scan.scanResultList, pEntry,
2483 LL_ACCESS_LOCK );
2484 if(csrCheck11dChannel(pBssDesc->Result.BssDescriptor.channelId,
2485 pMac->roam.validChannelList, len))
2486 {
2487 /* Remove Scan result which does not have 11d channel */
2488 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry,
2489 LL_ACCESS_LOCK ))
2490 {
2491 csrFreeScanResultEntry( pMac, pBssDesc );
2492 }
2493 }
2494 pEntry = pTempEntry;
2495 }
2496 return status;
2497}
2498
2499
2500eHalStatus csrScanCopyResultList(tpAniSirGlobal pMac, tScanResultHandle hIn, tScanResultHandle *phResult)
2501{
2502 eHalStatus status = eHAL_STATUS_SUCCESS;
2503 tScanResultList *pRetList, *pInList = (tScanResultList *)hIn;
2504 tCsrScanResult *pResult, *pScanResult;
2505 tANI_U32 count = 0;
2506 tListElem *pEntry;
2507 tANI_U32 bssLen, allocLen;
2508
2509 if(phResult)
2510 {
2511 *phResult = CSR_INVALID_SCANRESULT_HANDLE;
2512 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302513 pRetList = vos_mem_malloc(sizeof(tScanResultList));
2514 if ( NULL == pRetList )
2515 status = eHAL_STATUS_FAILURE;
2516 else
Jeff Johnson295189b2012-06-20 16:38:30 -07002517 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302518 vos_mem_set(pRetList, sizeof(tScanResultList), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002519 csrLLOpen(pMac->hHdd, &pRetList->List);
2520 pRetList->pCurEntry = NULL;
2521 csrLLLock(&pMac->scan.scanResultList);
2522 csrLLLock(&pInList->List);
2523
2524 pEntry = csrLLPeekHead( &pInList->List, LL_ACCESS_NOLOCK );
2525 while( pEntry )
2526 {
2527 pScanResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2528 bssLen = pScanResult->Result.BssDescriptor.length + sizeof(pScanResult->Result.BssDescriptor.length);
2529 allocLen = sizeof( tCsrScanResult ) + bssLen;
Kiet Lam64c1b492013-07-12 13:56:44 +05302530 pResult = vos_mem_malloc(allocLen);
2531 if ( NULL == pResult )
2532 status = eHAL_STATUS_FAILURE;
2533 else
2534 status = eHAL_STATUS_SUCCESS;
2535 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07002536 {
2537 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
2538 count = 0;
2539 break;
2540 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302541 vos_mem_set(pResult, allocLen , 0);
2542 vos_mem_copy(&pResult->Result.BssDescriptor, &pScanResult->Result.BssDescriptor, bssLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07002543 if( pScanResult->Result.pvIes )
2544 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302545 pResult->Result.pvIes = vos_mem_malloc(sizeof( tDot11fBeaconIEs ));
2546 if ( NULL == pResult->Result.pvIes )
2547 status = eHAL_STATUS_FAILURE;
2548 else
2549 status = eHAL_STATUS_SUCCESS;
2550 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07002551 {
2552 //Free the memory we allocate above first
Kiet Lam64c1b492013-07-12 13:56:44 +05302553 vos_mem_free(pResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07002554 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
2555 count = 0;
2556 break;
2557 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302558 vos_mem_copy(pResult->Result.pvIes, pScanResult->Result.pvIes,
2559 sizeof( tDot11fBeaconIEs ));
Jeff Johnson295189b2012-06-20 16:38:30 -07002560 }
2561 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_LOCK);
2562 count++;
2563 pEntry = csrLLNext( &pInList->List, pEntry, LL_ACCESS_NOLOCK );
2564 }//while
2565 csrLLUnlock(&pInList->List);
2566 csrLLUnlock(&pMac->scan.scanResultList);
2567
2568 if(HAL_STATUS_SUCCESS(status))
2569 {
2570 if(0 == count)
2571 {
2572 csrLLClose(&pRetList->List);
Kiet Lam64c1b492013-07-12 13:56:44 +05302573 vos_mem_free(pRetList);
Jeff Johnson295189b2012-06-20 16:38:30 -07002574 status = eHAL_STATUS_E_NULL_VALUE;
2575 }
2576 else if(phResult)
2577 {
2578 *phResult = pRetList;
2579 }
2580 }
2581 }//Allocated pRetList
2582
2583 return (status);
2584}
2585
2586
2587
2588eHalStatus csrScanningStateMsgProcessor( tpAniSirGlobal pMac, void *pMsgBuf )
2589{
2590 eHalStatus status = eHAL_STATUS_SUCCESS;
2591 tSirMbMsg *pMsg = (tSirMbMsg *)pMsgBuf;
2592
2593 if((eWNI_SME_SCAN_RSP == pMsg->type) || (eWNI_SME_GET_SCANNED_CHANNEL_RSP == pMsg->type))
2594 {
2595 status = csrScanSmeScanResponse( pMac, pMsgBuf );
2596 }
2597 else
2598 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002599 if(pMsg->type == eWNI_SME_UPPER_LAYER_ASSOC_CNF)
Jeff Johnson295189b2012-06-20 16:38:30 -07002600 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002601 tCsrRoamSession *pSession;
2602 tSirSmeAssocIndToUpperLayerCnf *pUpperLayerAssocCnf;
2603 tCsrRoamInfo roamInfo;
2604 tCsrRoamInfo *pRoamInfo = NULL;
2605 tANI_U32 sessionId;
2606 eHalStatus status;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002607 smsLog( pMac, LOG1, FL("Scanning : ASSOCIATION confirmation can be given to upper layer "));
Kiet Lam64c1b492013-07-12 13:56:44 +05302608 vos_mem_set(&roamInfo, sizeof(tCsrRoamInfo), 0);
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002609 pRoamInfo = &roamInfo;
2610 pUpperLayerAssocCnf = (tSirSmeAssocIndToUpperLayerCnf *)pMsgBuf;
2611 status = csrRoamGetSessionIdFromBSSID( pMac, (tCsrBssid *)pUpperLayerAssocCnf->bssId, &sessionId );
2612 pSession = CSR_GET_SESSION(pMac, sessionId);
2613
2614 if(!pSession)
2615 {
2616 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
2617 return eHAL_STATUS_FAILURE;
2618 }
2619
2620 pRoamInfo->statusCode = eSIR_SME_SUCCESS; //send the status code as Success
2621 pRoamInfo->u.pConnectedProfile = &pSession->connectedProfile;
2622 pRoamInfo->staId = (tANI_U8)pUpperLayerAssocCnf->aid;
2623 pRoamInfo->rsnIELen = (tANI_U8)pUpperLayerAssocCnf->rsnIE.length;
2624 pRoamInfo->prsnIE = pUpperLayerAssocCnf->rsnIE.rsnIEdata;
2625 pRoamInfo->addIELen = (tANI_U8)pUpperLayerAssocCnf->addIE.length;
2626 pRoamInfo->paddIE = pUpperLayerAssocCnf->addIE.addIEdata;
Kiet Lam64c1b492013-07-12 13:56:44 +05302627 vos_mem_copy(pRoamInfo->peerMac, pUpperLayerAssocCnf->peerMacAddr, sizeof(tSirMacAddr));
2628 vos_mem_copy(&pRoamInfo->bssid, pUpperLayerAssocCnf->bssId, sizeof(tCsrBssid));
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002629 pRoamInfo->wmmEnabledSta = pUpperLayerAssocCnf->wmmEnabledSta;
2630 if(CSR_IS_INFRA_AP(pRoamInfo->u.pConnectedProfile) )
2631 {
2632 pMac->roam.roamSession[sessionId].connectState = eCSR_ASSOC_STATE_TYPE_INFRA_CONNECTED;
2633 pRoamInfo->fReassocReq = pUpperLayerAssocCnf->reassocReq;
2634 status = csrRoamCallCallback(pMac, sessionId, pRoamInfo, 0, eCSR_ROAM_INFRA_IND, eCSR_ROAM_RESULT_INFRA_ASSOCIATION_CNF);
2635 }
2636 if(CSR_IS_WDS_AP( pRoamInfo->u.pConnectedProfile))
2637 {
2638 vos_sleep( 100 );
2639 pMac->roam.roamSession[sessionId].connectState = eCSR_ASSOC_STATE_TYPE_WDS_CONNECTED;//Sta
2640 status = csrRoamCallCallback(pMac, sessionId, pRoamInfo, 0, eCSR_ROAM_WDS_IND, eCSR_ROAM_RESULT_WDS_ASSOCIATION_IND);//Sta
2641 }
2642
Jeff Johnson295189b2012-06-20 16:38:30 -07002643 }
2644 else
2645 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002646
2647 if( csrIsAnySessionInConnectState( pMac ) )
2648 {
2649 //In case of we are connected, we need to check whether connect status changes
2650 //because scan may also run while connected.
2651 csrRoamCheckForLinkStatusChange( pMac, ( tSirSmeRsp * )pMsgBuf );
2652 }
2653 else
2654 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002655 smsLog( pMac, LOGW, "Message [0x%04x] received in state, when expecting Scan Response", pMsg->type );
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002656 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002657 }
2658 }
2659
2660 return (status);
2661}
2662
2663
2664
2665void csrCheckNSaveWscIe(tpAniSirGlobal pMac, tSirBssDescription *pNewBssDescr, tSirBssDescription *pOldBssDescr)
2666{
2667 int idx, len;
2668 tANI_U8 *pbIe;
2669
2670 //If failed to remove, assuming someone else got it.
2671 if((pNewBssDescr->fProbeRsp != pOldBssDescr->fProbeRsp) &&
2672 (0 == pNewBssDescr->WscIeLen))
2673 {
2674 idx = 0;
2675 len = pOldBssDescr->length - sizeof(tSirBssDescription) +
2676 sizeof(tANI_U16) + sizeof(tANI_U32) - DOT11F_IE_WSCPROBERES_MIN_LEN - 2;
2677 pbIe = (tANI_U8 *)pOldBssDescr->ieFields;
2678 //Save WPS IE if it exists
2679 pNewBssDescr->WscIeLen = 0;
2680 while(idx < len)
2681 {
2682 if((DOT11F_EID_WSCPROBERES == pbIe[0]) &&
2683 (0x00 == pbIe[2]) && (0x50 == pbIe[3]) && (0xf2 == pbIe[4]) && (0x04 == pbIe[5]))
2684 {
2685 //Founrd it
2686 if((DOT11F_IE_WSCPROBERES_MAX_LEN - 2) >= pbIe[1])
2687 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302688 vos_mem_copy(pNewBssDescr->WscIeProbeRsp, pbIe, pbIe[1] + 2);
Jeff Johnson295189b2012-06-20 16:38:30 -07002689 pNewBssDescr->WscIeLen = pbIe[1] + 2;
2690 }
2691 break;
2692 }
2693 idx += pbIe[1] + 2;
2694 pbIe += pbIe[1] + 2;
2695 }
2696 }
2697}
2698
2699
2700
2701//pIes may be NULL
2702tANI_BOOLEAN csrRemoveDupBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDescr,
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05302703 tDot11fBeaconIEs *pIes, tAniSSID *pSsid, v_TIME_t *timer, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07002704{
2705 tListElem *pEntry;
2706
2707 tCsrScanResult *pBssDesc;
2708 tANI_BOOLEAN fRC = FALSE;
2709
2710 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
2711 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
2712 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
2713 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
2714
2715 while( pEntry )
2716 {
2717 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2718
2719 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
2720 // matches
2721 if ( csrIsDuplicateBssDescription( pMac, &pBssDesc->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07002722 pSirBssDescr, pIes, fForced ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07002723 {
2724 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
2725 ((tANI_S32)pBssDesc->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
2726 // Remove the 'old' entry from the list....
2727 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry, LL_ACCESS_LOCK ) )
2728 {
2729 // !we need to free the memory associated with this node
2730 //If failed to remove, assuming someone else got it.
2731 *pSsid = pBssDesc->Result.ssId;
2732 *timer = pBssDesc->Result.timer;
2733 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pBssDesc->Result.BssDescriptor);
2734
2735 csrFreeScanResultEntry( pMac, pBssDesc );
2736 }
2737 else
2738 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002739 smsLog( pMac, LOGW, FL( " fail to remove entry" ) );
Jeff Johnson295189b2012-06-20 16:38:30 -07002740 }
2741 fRC = TRUE;
2742
2743 // If we found a match, we can stop looking through the list.
2744 break;
2745 }
2746
2747 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_LOCK );
2748 }
2749
2750 return fRC;
2751}
2752
2753
2754eHalStatus csrAddPMKIDCandidateList( tpAniSirGlobal pMac, tANI_U32 sessionId,
2755 tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes )
2756{
2757 eHalStatus status = eHAL_STATUS_FAILURE;
2758 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
2759
Jeff Johnson32d95a32012-09-10 13:15:23 -07002760 if(!pSession)
2761 {
2762 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
2763 return eHAL_STATUS_FAILURE;
2764 }
2765
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002766 smsLog(pMac, LOGW, "csrAddPMKIDCandidateList called pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07002767 if( pIes )
2768 {
2769 // check if this is a RSN BSS
2770 if( pIes->RSN.present )
2771 {
2772 // Check if the BSS is capable of doing pre-authentication
2773 if( pSession->NumPmkidCandidate < CSR_MAX_PMKID_ALLOWED )
2774 {
2775
2776#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
2777 {
2778 WLAN_VOS_DIAG_EVENT_DEF(secEvent, vos_event_wlan_security_payload_type);
Kiet Lam64c1b492013-07-12 13:56:44 +05302779 vos_mem_set(&secEvent, sizeof(vos_event_wlan_security_payload_type), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002780 secEvent.eventId = WLAN_SECURITY_EVENT_PMKID_CANDIDATE_FOUND;
2781 secEvent.encryptionModeMulticast =
2782 (v_U8_t)diagEncTypeFromCSRType(pSession->connectedProfile.mcEncryptionType);
2783 secEvent.encryptionModeUnicast =
2784 (v_U8_t)diagEncTypeFromCSRType(pSession->connectedProfile.EncryptionType);
Kiet Lam64c1b492013-07-12 13:56:44 +05302785 vos_mem_copy(secEvent.bssid, pSession->connectedProfile.bssid, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07002786 secEvent.authMode =
2787 (v_U8_t)diagAuthTypeFromCSRType(pSession->connectedProfile.AuthType);
2788 WLAN_VOS_DIAG_EVENT_REPORT(&secEvent, EVENT_WLAN_SECURITY);
2789 }
2790#endif//#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
2791
2792 // if yes, then add to PMKIDCandidateList
Kiet Lam64c1b492013-07-12 13:56:44 +05302793 vos_mem_copy(pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].BSSID,
2794 pBssDesc->bssId, WNI_CFG_BSSID_LEN);
2795 // Bit 0 offirst byte - PreAuthentication Capability
2796 if ( (pIes->RSN.RSN_Cap[0] >> 0) & 0x1 )
Jeff Johnson295189b2012-06-20 16:38:30 -07002797 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302798 pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].preAuthSupported
2799 = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07002800 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302801 else
2802 {
2803 pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].preAuthSupported
2804 = eANI_BOOLEAN_FALSE;
2805 }
2806 pSession->NumPmkidCandidate++;
Jeff Johnson295189b2012-06-20 16:38:30 -07002807 }
2808 else
2809 {
2810 status = eHAL_STATUS_FAILURE;
2811 }
2812 }
2813 }
2814
2815 return (status);
2816}
2817
2818//This function checks whether new AP is found for the current connected profile
2819//If it is found, it return the sessionId, else it return invalid sessionID
2820tANI_U32 csrProcessBSSDescForPMKIDList(tpAniSirGlobal pMac,
2821 tSirBssDescription *pBssDesc,
2822 tDot11fBeaconIEs *pIes)
2823{
2824 tANI_U32 i, bRet = CSR_SESSION_ID_INVALID;
2825 tCsrRoamSession *pSession;
2826 tDot11fBeaconIEs *pIesLocal = pIes;
2827
2828 if( pIesLocal || HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIesLocal)) )
2829 {
2830 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
2831 {
2832 if( CSR_IS_SESSION_VALID( pMac, i ) )
2833 {
2834 pSession = CSR_GET_SESSION( pMac, i );
2835 if( csrIsConnStateConnectedInfra( pMac, i ) &&
2836 ( eCSR_AUTH_TYPE_RSN == pSession->connectedProfile.AuthType ) )
2837 {
2838 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile, pBssDesc, pIesLocal))
2839 {
2840 //this new BSS fits the current profile connected
2841 if(HAL_STATUS_SUCCESS(csrAddPMKIDCandidateList(pMac, i, pBssDesc, pIesLocal)))
2842 {
2843 bRet = i;
2844 }
2845 break;
2846 }
2847 }
2848 }
2849 }
2850 if( !pIes )
2851 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302852 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07002853 }
2854 }
2855
2856 return (tANI_U8)bRet;
2857}
2858
2859#ifdef FEATURE_WLAN_WAPI
2860eHalStatus csrAddBKIDCandidateList( tpAniSirGlobal pMac, tANI_U32 sessionId,
2861 tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes )
2862{
2863 eHalStatus status = eHAL_STATUS_FAILURE;
2864 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
2865
Jeff Johnson32d95a32012-09-10 13:15:23 -07002866 if(!pSession)
2867 {
2868 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
2869 return eHAL_STATUS_FAILURE;
2870 }
2871
Kiet Lam64c1b492013-07-12 13:56:44 +05302872 smsLog(pMac, LOGW, "csrAddBKIDCandidateList called pMac->scan.NumBkidCandidate = %d",
2873 pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07002874 if( pIes )
2875 {
2876 // check if this is a WAPI BSS
2877 if( pIes->WAPI.present )
2878 {
2879 // Check if the BSS is capable of doing pre-authentication
2880 if( pSession->NumBkidCandidate < CSR_MAX_BKID_ALLOWED )
2881 {
2882
2883 // if yes, then add to BKIDCandidateList
Kiet Lam64c1b492013-07-12 13:56:44 +05302884 vos_mem_copy(pSession->BkidCandidateInfo[pSession->NumBkidCandidate].BSSID,
2885 pBssDesc->bssId, WNI_CFG_BSSID_LEN);
2886 if ( pIes->WAPI.preauth )
Jeff Johnson295189b2012-06-20 16:38:30 -07002887 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302888 pSession->BkidCandidateInfo[pSession->NumBkidCandidate].preAuthSupported
2889 = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07002890 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302891 else
2892 {
2893 pSession->BkidCandidateInfo[pSession->NumBkidCandidate].preAuthSupported
2894 = eANI_BOOLEAN_FALSE;
2895 }
2896 pSession->NumBkidCandidate++;
Jeff Johnson295189b2012-06-20 16:38:30 -07002897 }
2898 else
2899 {
2900 status = eHAL_STATUS_FAILURE;
2901 }
2902 }
2903 }
2904
2905 return (status);
2906}
2907
2908//This function checks whether new AP is found for the current connected profile
2909//if so add to BKIDCandidateList
2910tANI_BOOLEAN csrProcessBSSDescForBKIDList(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
2911 tDot11fBeaconIEs *pIes)
2912{
2913 tANI_BOOLEAN fRC = FALSE;
2914 tDot11fBeaconIEs *pIesLocal = pIes;
2915 tANI_U32 sessionId;
2916 tCsrRoamSession *pSession;
2917
2918 if( pIesLocal || HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIesLocal)) )
2919 {
2920 for( sessionId = 0; sessionId < CSR_ROAM_SESSION_MAX; sessionId++ )
2921 {
2922 if( CSR_IS_SESSION_VALID( pMac, sessionId) )
2923 {
2924 pSession = CSR_GET_SESSION( pMac, sessionId );
2925 if( csrIsConnStateConnectedInfra( pMac, sessionId ) &&
2926 eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE == pSession->connectedProfile.AuthType)
2927 {
2928 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile,pBssDesc, pIesLocal))
2929 {
2930 //this new BSS fits the current profile connected
2931 if(HAL_STATUS_SUCCESS(csrAddBKIDCandidateList(pMac, sessionId, pBssDesc, pIesLocal)))
2932 {
2933 fRC = TRUE;
2934 }
2935 }
2936 }
2937 }
2938 }
2939 if(!pIes)
2940 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302941 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07002942 }
2943
2944 }
2945 return fRC;
2946}
2947
2948#endif
2949
2950
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07002951static void csrMoveTempScanResultsToMainList( tpAniSirGlobal pMac, tANI_U8 reason )
Jeff Johnson295189b2012-06-20 16:38:30 -07002952{
2953 tListElem *pEntry;
Agarwal Ashishd9d72602013-09-13 00:06:17 +05302954 tListElem *pEntryTemp;
2955 tListElem *pNext;
Jeff Johnson295189b2012-06-20 16:38:30 -07002956 tCsrScanResult *pBssDescription;
2957 tANI_S8 cand_Bss_rssi;
Agarwal Ashishd9d72602013-09-13 00:06:17 +05302958 tANI_S8 rssi_of_current_country;
Jeff Johnson295189b2012-06-20 16:38:30 -07002959 tANI_BOOLEAN fDupBss;
2960#ifdef FEATURE_WLAN_WAPI
2961 tANI_BOOLEAN fNewWapiBSSForCurConnection = eANI_BOOLEAN_FALSE;
2962#endif /* FEATURE_WLAN_WAPI */
2963 tDot11fBeaconIEs *pIesLocal = NULL;
2964 tANI_U32 sessionId = CSR_SESSION_ID_INVALID;
2965 tAniSSID tmpSsid;
2966 v_TIME_t timer=0;
Agarwal Ashishd9d72602013-09-13 00:06:17 +05302967 tCsrBssid bssid_temp = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
Jeff Johnson295189b2012-06-20 16:38:30 -07002968
2969 tmpSsid.length = 0;
2970 cand_Bss_rssi = -128; // RSSI coming from PE is -ve
Agarwal Ashishd9d72602013-09-13 00:06:17 +05302971 rssi_of_current_country = -128;
Jeff Johnson295189b2012-06-20 16:38:30 -07002972
2973 // remove the BSS descriptions from temporary list
2974 while( ( pEntry = csrLLRemoveTail( &pMac->scan.tempScanResults, LL_ACCESS_LOCK ) ) != NULL)
2975 {
2976 pBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2977
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002978 smsLog( pMac, LOGW, "...Bssid= %02x-%02x-%02x-%02x-%02x-%02x chan= %d, rssi = -%d",
Jeff Johnson295189b2012-06-20 16:38:30 -07002979 pBssDescription->Result.BssDescriptor.bssId[ 0 ], pBssDescription->Result.BssDescriptor.bssId[ 1 ],
2980 pBssDescription->Result.BssDescriptor.bssId[ 2 ], pBssDescription->Result.BssDescriptor.bssId[ 3 ],
2981 pBssDescription->Result.BssDescriptor.bssId[ 4 ], pBssDescription->Result.BssDescriptor.bssId[ 5 ],
2982 pBssDescription->Result.BssDescriptor.channelId,
2983 pBssDescription->Result.BssDescriptor.rssi * (-1) );
2984
2985 //At this time, pBssDescription->Result.pvIes may be NULL
2986 pIesLocal = (tDot11fBeaconIEs *)( pBssDescription->Result.pvIes );
2987 if( !pIesLocal && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pBssDescription->Result.BssDescriptor, &pIesLocal))) )
2988 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002989 smsLog(pMac, LOGE, FL(" Cannot pared IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002990 csrFreeScanResultEntry(pMac, pBssDescription);
2991 continue;
2992 }
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05302993 fDupBss = csrRemoveDupBssDescription( pMac, &pBssDescription->Result.BssDescriptor, pIesLocal, &tmpSsid, &timer, FALSE );
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07002994 //Check whether we have reach out limit, but don't lose the LFR candidates came from FW
2995 if( CSR_SCAN_IS_OVER_BSS_LIMIT(pMac)
2996#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
2997 && !( eCsrScanGetLfrResult == reason )
2998#endif
2999 )
Jeff Johnson295189b2012-06-20 16:38:30 -07003000 {
3001 //Limit reach
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003002 smsLog(pMac, LOGW, FL(" BSS limit reached"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003003 //Free the resources
3004 if( (pBssDescription->Result.pvIes == NULL) && pIesLocal )
3005 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303006 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003007 }
3008 csrFreeScanResultEntry(pMac, pBssDescription);
3009 //Continue because there may be duplicated BSS
3010 continue;
3011 }
3012 // check for duplicate scan results
3013 if ( !fDupBss )
3014 {
3015 //Found a new BSS
3016 sessionId = csrProcessBSSDescForPMKIDList(pMac,
3017 &pBssDescription->Result.BssDescriptor, pIesLocal);
3018 if( CSR_SESSION_ID_INVALID != sessionId)
3019 {
3020 csrRoamCallCallback(pMac, sessionId, NULL, 0,
3021 eCSR_ROAM_SCAN_FOUND_NEW_BSS, eCSR_ROAM_RESULT_NONE);
3022 }
3023 }
3024 else
3025 {
3026 //Check if the new one has SSID it it, if not, use the older SSID if it exists.
3027 if( (0 == pBssDescription->Result.ssId.length) && tmpSsid.length )
3028 {
3029 //New BSS has a hidden SSID and old one has the SSID. Keep the SSID only
3030 //if diff of saved SSID time and current time is less than 1 min to avoid
3031 //side effect of saving SSID with old one is that if AP changes its SSID while remain
3032 //hidden, we may never see it and also to address the requirement of
3033 //When we remove hidden ssid from the profile i.e., forget the SSID via
3034 // GUI that SSID shouldn't see in the profile
3035 if( (vos_timer_get_system_time() - timer) <= HIDDEN_TIMER)
3036 {
3037 pBssDescription->Result.timer = timer;
3038 pBssDescription->Result.ssId = tmpSsid;
3039 }
3040 }
3041 }
3042
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303043 //Find a good AP for 11d info
3044 if ( csrIs11dSupported( pMac ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003045 {
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303046 if (cand_Bss_rssi < pBssDescription->Result.BssDescriptor.rssi)
Jeff Johnson295189b2012-06-20 16:38:30 -07003047 {
3048 // check if country information element is present
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303049 if (pIesLocal->Country.present)
Jeff Johnson295189b2012-06-20 16:38:30 -07003050 {
3051 cand_Bss_rssi = pBssDescription->Result.BssDescriptor.rssi;
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303052 smsLog(pMac, LOGW, FL("11d AP Bssid " MAC_ADDRESS_STR
3053 " chan= %d, rssi = -%d, countryCode %c%c"),
3054 MAC_ADDR_ARRAY( pBssDescription->Result.BssDescriptor.bssId),
3055 pBssDescription->Result.BssDescriptor.channelId,
3056 pBssDescription->Result.BssDescriptor.rssi * (-1),
3057 pIesLocal->Country.country[0],pIesLocal->Country.country[1] );
3058 //Getting BSSID for best AP in scan result.
3059 palCopyMemory(pMac->hHdd, bssid_temp,
3060 pBssDescription->Result.BssDescriptor.bssId, sizeof(tSirMacAddr));
3061
Jeff Johnson295189b2012-06-20 16:38:30 -07003062 }
3063
3064 }
3065 }
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303066 //get current rssi for BSS from which country code is acquired.
3067 if ( csrIs11dSupported(pMac) && (csrIsMacAddressEqual(pMac,
3068 &pMac->scan.currentCountryBssid,
3069 &pBssDescription->Result.BssDescriptor.bssId) ))
3070 {
3071 smsLog(pMac, LOGW, FL("Information about current country Bssid "
3072 MAC_ADDRESS_STR
3073 " chan= %d, rssi = -%d, countryCode %c%c"),
3074 MAC_ADDR_ARRAY( pBssDescription->Result.BssDescriptor.bssId),
3075 pBssDescription->Result.BssDescriptor.channelId,
3076 pBssDescription->Result.BssDescriptor.rssi * (-1),
3077 pIesLocal->Country.country[0],pIesLocal->Country.country[1] );
3078 rssi_of_current_country = pBssDescription->Result.BssDescriptor.rssi ;
3079 }
3080
Jeff Johnson295189b2012-06-20 16:38:30 -07003081
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08003082
Jeff Johnson295189b2012-06-20 16:38:30 -07003083 // append to main list
3084 csrScanAddResult(pMac, pBssDescription, pIesLocal);
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303085 if ( (pBssDescription->Result.pvIes == NULL) && pIesLocal )
Jeff Johnson295189b2012-06-20 16:38:30 -07003086 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303087 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003088 }
3089 }
3090
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303091 // Calculating 30% of current rssi is an idea for not to change
3092 // country code so freq.
3093 if (rssi_of_current_country != -128)
3094 {
3095 rssi_of_current_country = rssi_of_current_country
3096 - THIRTY_PERCENT(rssi_of_current_country);
3097 }
3098
3099 if ((rssi_of_current_country <= cand_Bss_rssi ) || rssi_of_current_country == -128)
3100 {
3101 csrLLLock(&pMac->scan.scanResultList);
3102 pEntryTemp = csrLLPeekHead(&pMac->scan.scanResultList, LL_ACCESS_NOLOCK);
3103 while ( NULL != pEntryTemp)
3104 {
3105 pNext = csrLLNext(&pMac->scan.scanResultList, pEntryTemp,
3106 LL_ACCESS_NOLOCK);
3107 pBssDescription = GET_BASE_ADDR( pEntryTemp, tCsrScanResult, Link );
3108 pIesLocal = (tDot11fBeaconIEs *)( pBssDescription->Result.pvIes );
3109 // Need to traverse whole scan list to get description for best 11d AP.
3110 if (csrIsMacAddressEqual(pMac, (tCsrBssid *)&bssid_temp,
3111 (tCsrBssid *) pBssDescription->Result.BssDescriptor.bssId))
3112 {
3113 palCopyMemory(pMac->hHdd, pMac->scan.currentCountryBssid,
3114 bssid_temp, sizeof(tSirMacAddr));
3115 // Best AP should be passed to update reg domain.
3116 csrLearnCountryInformation( pMac, &pBssDescription->Result.BssDescriptor,
3117 pIesLocal, eANI_BOOLEAN_FALSE );
3118 break;
3119 }
3120 pEntryTemp = pNext;
3121 }
3122 csrLLUnlock(&pMac->scan.scanResultList);
3123 }
3124
3125
Jeff Johnson295189b2012-06-20 16:38:30 -07003126 //Tush: If we can find the current 11d info in any of the scan results, or
3127 // a good enough AP with the 11d info from the scan results then no need to
3128 // get into ambiguous state
3129 if(pMac->scan.fAmbiguous11dInfoFound)
3130 {
3131 if((pMac->scan.fCurrent11dInfoMatch) || (cand_Bss_rssi != -128))
3132 {
3133 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
3134 }
3135 }
3136
3137#ifdef FEATURE_WLAN_WAPI
3138 if(fNewWapiBSSForCurConnection)
3139 {
3140 //remember it first
3141 csrRoamCallCallback(pMac, sessionId, NULL, 0, eCSR_ROAM_SCAN_FOUND_NEW_BSS, eCSR_ROAM_RESULT_NEW_WAPI_BSS);
3142 }
3143#endif /* FEATURE_WLAN_WAPI */
3144
3145 return;
3146}
3147
3148
3149static tCsrScanResult *csrScanSaveBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pBSSDescription,
3150 tDot11fBeaconIEs *pIes)
3151{
3152 tCsrScanResult *pCsrBssDescription = NULL;
3153 tANI_U32 cbBSSDesc;
3154 tANI_U32 cbAllocated;
Jeff Johnson295189b2012-06-20 16:38:30 -07003155
3156 // figure out how big the BSS description is (the BSSDesc->length does NOT
3157 // include the size of the length field itself).
3158 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
3159
3160 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
3161
Kiet Lam64c1b492013-07-12 13:56:44 +05303162 pCsrBssDescription = vos_mem_malloc(cbAllocated);
3163 if ( NULL != pCsrBssDescription )
Jeff Johnson295189b2012-06-20 16:38:30 -07003164 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303165 vos_mem_set(pCsrBssDescription, cbAllocated, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003166 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Kiet Lam64c1b492013-07-12 13:56:44 +05303167 vos_mem_copy(&pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc);
Jeff Johnson295189b2012-06-20 16:38:30 -07003168#if defined(VOSS_ENSBALED)
3169 VOS_ASSERT( pCsrBssDescription->Result.pvIes == NULL );
3170#endif
3171 csrScanAddResult(pMac, pCsrBssDescription, pIes);
3172 }
3173
3174 return( pCsrBssDescription );
3175}
3176
3177// Append a Bss Description...
3178tCsrScanResult *csrScanAppendBssDescription( tpAniSirGlobal pMac,
3179 tSirBssDescription *pSirBssDescription,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07003180 tDot11fBeaconIEs *pIes, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07003181{
3182 tCsrScanResult *pCsrBssDescription = NULL;
3183 tAniSSID tmpSsid;
3184 v_TIME_t timer = 0;
3185 int result;
3186
3187 tmpSsid.length = 0;
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07003188 result = csrRemoveDupBssDescription( pMac, pSirBssDescription, pIes, &tmpSsid, &timer, fForced );
Jeff Johnson295189b2012-06-20 16:38:30 -07003189 pCsrBssDescription = csrScanSaveBssDescription( pMac, pSirBssDescription, pIes );
3190 if (result && (pCsrBssDescription != NULL))
3191 {
3192 //Check if the new one has SSID it it, if not, use the older SSID if it exists.
3193 if( (0 == pCsrBssDescription->Result.ssId.length) && tmpSsid.length )
3194 {
3195 //New BSS has a hidden SSID and old one has the SSID. Keep the SSID only
3196 //if diff of saved SSID time and current time is less than 1 min to avoid
3197 //side effect of saving SSID with old one is that if AP changes its SSID while remain
3198 //hidden, we may never see it and also to address the requirement of
3199 //When we remove hidden ssid from the profile i.e., forget the SSID via
3200 // GUI that SSID shouldn't see in the profile
3201 if((vos_timer_get_system_time()-timer) <= HIDDEN_TIMER)
3202 {
3203 pCsrBssDescription->Result.ssId = tmpSsid;
3204 pCsrBssDescription->Result.timer = timer;
3205 }
3206 }
3207 }
3208
3209
3210 return( pCsrBssDescription );
3211}
3212
3213
3214
3215void csrPurgeChannelPower( tpAniSirGlobal pMac, tDblLinkList *pChannelList )
3216{
3217 tCsrChannelPowerInfo *pChannelSet;
3218 tListElem *pEntry;
3219
3220 csrLLLock(pChannelList);
3221 // Remove the channel sets from the learned list and put them in the free list
3222 while( ( pEntry = csrLLRemoveHead( pChannelList, LL_ACCESS_NOLOCK ) ) != NULL)
3223 {
3224 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3225 if( pChannelSet )
3226 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303227 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003228 }
3229 }
3230 csrLLUnlock(pChannelList);
3231 return;
3232}
3233
3234
3235/*
3236 * Save the channelList into the ultimate storage as the final stage of channel
3237 * Input: pCountryInfo -- the country code (e.g. "USI"), channel list, and power limit are all stored inside this data structure
3238 */
Jeff Johnsone7245742012-09-05 17:12:55 -07003239eHalStatus csrSaveToChannelPower2G_5G( tpAniSirGlobal pMac, tANI_U32 tableSize, tSirMacChanInfo *channelTable )
Jeff Johnson295189b2012-06-20 16:38:30 -07003240{
3241 tANI_U32 i = tableSize / sizeof( tSirMacChanInfo );
3242 tSirMacChanInfo *pChannelInfo;
3243 tCsrChannelPowerInfo *pChannelSet;
3244 tANI_BOOLEAN f2GHzInfoFound = FALSE;
3245 tANI_BOOLEAN f2GListPurged = FALSE, f5GListPurged = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003246
3247 pChannelInfo = channelTable;
3248 // atleast 3 bytes have to be remaining -- from "countryString"
3249 while ( i-- )
3250 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303251 pChannelSet = vos_mem_malloc(sizeof(tCsrChannelPowerInfo));
3252 if ( NULL != pChannelSet )
Jeff Johnson295189b2012-06-20 16:38:30 -07003253 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303254 vos_mem_set(pChannelSet, sizeof(tCsrChannelPowerInfo), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003255 pChannelSet->firstChannel = pChannelInfo->firstChanNum;
3256 pChannelSet->numChannels = pChannelInfo->numChannels;
3257
3258 // Now set the inter-channel offset based on the frequency band the channel set lies in
Jeff Johnsone7245742012-09-05 17:12:55 -07003259 if( (CSR_IS_CHANNEL_24GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003260 ((pChannelSet->firstChannel + (pChannelSet->numChannels - 1)) <= CSR_MAX_24GHz_CHANNEL_NUMBER) )
Jeff Johnsone7245742012-09-05 17:12:55 -07003261
Jeff Johnson295189b2012-06-20 16:38:30 -07003262 {
3263 pChannelSet->interChannelOffset = 1;
3264 f2GHzInfoFound = TRUE;
3265 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003266 else if ( (CSR_IS_CHANNEL_5GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003267 ((pChannelSet->firstChannel + ((pChannelSet->numChannels - 1) * 4)) <= CSR_MAX_5GHz_CHANNEL_NUMBER) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003268 {
3269 pChannelSet->interChannelOffset = 4;
3270 f2GHzInfoFound = FALSE;
3271 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003272 else
3273 {
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003274 smsLog( pMac, LOGW, FL("Invalid Channel %d Present in Country IE"),
Jeff Johnsone7245742012-09-05 17:12:55 -07003275 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303276 vos_mem_free(pChannelSet);
Jeff Johnsone7245742012-09-05 17:12:55 -07003277 return eHAL_STATUS_FAILURE;
3278 }
3279
Jeff Johnson295189b2012-06-20 16:38:30 -07003280 pChannelSet->txPower = CSR_ROAM_MIN( pChannelInfo->maxTxPower, pMac->roam.configParam.nTxPowerCap );
3281
3282 if( f2GHzInfoFound )
3283 {
3284 if( !f2GListPurged )
3285 {
3286 // purge previous results if found new
3287 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList24 );
3288 f2GListPurged = TRUE;
3289 }
3290
3291 if(CSR_IS_OPERATING_BG_BAND(pMac))
3292 {
3293 // add to the list of 2.4 GHz channel sets
3294 csrLLInsertTail( &pMac->scan.channelPowerInfoList24, &pChannelSet->link, LL_ACCESS_LOCK );
3295 }
3296 else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003297 smsLog( pMac, LOGW, FL("Adding 11B/G channels in 11A mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003298 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303299 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003300 }
3301 }
3302 else
3303 {
3304 // 5GHz info found
3305 if( !f5GListPurged )
3306 {
3307 // purge previous results if found new
3308 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList5G );
3309 f5GListPurged = TRUE;
3310 }
3311
3312 if(CSR_IS_OPERATING_A_BAND(pMac))
3313 {
3314 // add to the list of 5GHz channel sets
3315 csrLLInsertTail( &pMac->scan.channelPowerInfoList5G, &pChannelSet->link, LL_ACCESS_LOCK );
3316 }
3317 else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003318 smsLog( pMac, LOGW, FL("Adding 11A channels in B/G mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003319 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303320 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003321 }
3322 }
3323 }
3324
3325 pChannelInfo++; // move to next entry
3326 }
3327
Jeff Johnsone7245742012-09-05 17:12:55 -07003328 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07003329}
3330
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303331static void csrClearDfsChannelList( tpAniSirGlobal pMac )
3332{
3333 tSirMbMsg *pMsg;
3334 tANI_U16 msgLen;
Jeff Johnson295189b2012-06-20 16:38:30 -07003335
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303336 msgLen = (tANI_U16)(sizeof( tSirMbMsg ));
Kiet Lam64c1b492013-07-12 13:56:44 +05303337 pMsg = vos_mem_malloc(msgLen);
3338 if ( NULL != pMsg )
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303339 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303340 vos_mem_set((void *)pMsg, msgLen, 0);
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303341 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_CLEAR_DFS_CHANNEL_LIST);
3342 pMsg->msgLen = pal_cpu_to_be16(msgLen);
3343 palSendMBMessage(pMac->hHdd, pMsg);
3344 }
3345}
Jeff Johnson295189b2012-06-20 16:38:30 -07003346
3347void csrApplyPower2Current( tpAniSirGlobal pMac )
3348{
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003349 smsLog( pMac, LOG3, FL(" Updating Cfg with power settings"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003350 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList24, WNI_CFG_MAX_TX_POWER_2_4 );
3351 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList5G, WNI_CFG_MAX_TX_POWER_5 );
3352}
3353
3354
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003355void csrApplyChannelPowerCountryInfo( tpAniSirGlobal pMac, tCsrChannel *pChannelList, tANI_U8 *countryCode, tANI_BOOLEAN updateRiva)
Jeff Johnson295189b2012-06-20 16:38:30 -07003356{
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303357 int i, j, count, countryIndex = -1;
Jeff Johnson295189b2012-06-20 16:38:30 -07003358 eNVChannelEnabledType channelEnabledType;
3359 tANI_U8 numChannels = 0;
3360 tANI_U8 tempNumChannels = 0;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303361 tANI_U8 channelIgnore = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003362 tCsrChannel ChannelList;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303363
Jeff Johnson295189b2012-06-20 16:38:30 -07003364 if( pChannelList->numChannels )
3365 {
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303366 for(count=0; count < MAX_COUNTRY_IGNORE; count++)
3367 {
3368 if(vos_mem_compare(countryCode, countryIgnoreList[count].countryCode,
3369 VOS_COUNTRY_CODE_LEN))
3370 {
3371 countryIndex = count;
3372 break;
3373 }
3374 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003375 tempNumChannels = CSR_MIN(pChannelList->numChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN);
3376 /* If user doesn't want to scan the DFS channels lets trim them from
3377 the valid channel list*/
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303378 for(i=0; i < tempNumChannels; i++)
Jeff Johnson295189b2012-06-20 16:38:30 -07003379 {
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303380 channelIgnore = FALSE;
3381 if( FALSE == pMac->scan.fEnableDFSChnlScan )
3382 {
3383 channelEnabledType =
3384 vos_nv_getChannelEnabledState(pChannelList->channelList[i]);
3385 }
3386 else
3387 {
Madan Mohan Koyyalamudi3f65e312012-11-06 15:31:12 -08003388 channelEnabledType = NV_CHANNEL_ENABLE;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303389 }
3390 if( NV_CHANNEL_ENABLE == channelEnabledType )
3391 {
3392 if( countryIndex != -1 )
3393 {
3394 for(j=0; j < countryIgnoreList[countryIndex].channelCount; j++)
3395 {
3396 if( pChannelList->channelList[i] ==
3397 countryIgnoreList[countryIndex].channelList[j] )
3398 {
3399 channelIgnore = TRUE;
3400 break;
3401 }
3402 }
3403 }
3404 if( FALSE == channelIgnore )
3405 {
3406 ChannelList.channelList[numChannels] = pChannelList->channelList[i];
3407 numChannels++;
3408 }
3409 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003410 }
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303411 ChannelList.numChannels = numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -07003412 csrSetCfgValidChannelList(pMac, ChannelList.channelList, ChannelList.numChannels);
3413 // extend scan capability
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303414 // build a scan list based on the channel list : channel# + active/passive scan
3415 csrSetCfgScanControlList(pMac, countryCode, &ChannelList);
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303416 /*Send msg to Lim to clear DFS channel list */
3417 csrClearDfsChannelList(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07003418#ifdef FEATURE_WLAN_SCAN_PNO
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003419 if (updateRiva)
3420 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003421 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO, FL(" Sending 11d PNO info to Riva"));
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003422 // Send HAL UpdateScanParams message
3423 pmcUpdateScanParams(pMac, &(pMac->roam.configParam), &ChannelList, TRUE);
3424 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003425#endif // FEATURE_WLAN_SCAN_PNO
3426 }
3427 else
3428 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003429 smsLog( pMac, LOGE, FL(" 11D channel list is empty"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003430 }
3431 csrApplyPower2Current( pMac ); // Store the channel+power info in the global place: Cfg
3432 csrSetCfgCountryCode(pMac, countryCode);
3433}
3434
3435
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003436void csrResetCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce, tANI_BOOLEAN updateRiva )
Jeff Johnson295189b2012-06-20 16:38:30 -07003437{
3438 if( fForce || (csrIs11dSupported( pMac ) && (!pMac->scan.f11dInfoReset)))
3439 {
3440
3441#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3442 {
3443 vos_log_802_11d_pkt_type *p11dLog;
3444 int Index;
3445
3446 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
3447 if(p11dLog)
3448 {
3449 p11dLog->eventId = WLAN_80211D_EVENT_RESET;
Kiet Lam64c1b492013-07-12 13:56:44 +05303450 vos_mem_copy(p11dLog->countryCode, pMac->scan.countryCodeCurrent, 3);
Jeff Johnson295189b2012-06-20 16:38:30 -07003451 p11dLog->numChannel = pMac->scan.base20MHzChannels.numChannels;
3452 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
3453 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303454 vos_mem_copy(p11dLog->Channels,
3455 pMac->scan.base20MHzChannels.channelList,
3456 p11dLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07003457 for (Index=0; Index < pMac->scan.base20MHzChannels.numChannels; Index++)
3458 {
3459 p11dLog->TxPwr[Index] = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
3460 }
3461 }
3462 if(!pMac->roam.configParam.Is11dSupportEnabled)
3463 {
3464 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
3465 }
3466 else if(pMac->roam.configParam.fEnforceDefaultDomain)
3467 {
3468 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
3469 }
3470 else
3471 {
3472 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
3473 }
3474 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
3475 }
3476 }
3477#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3478
3479 // switch to passive scans only when 11d is enabled
3480 if( csrIs11dSupported( pMac ) )
3481 {
3482 pMac->scan.curScanType = eSIR_PASSIVE_SCAN;
3483 }
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003484
3485 csrPruneChannelListForMode(pMac, &pMac->scan.baseChannels);
3486 csrPruneChannelListForMode(pMac, &pMac->scan.base20MHzChannels);
3487
Jeff Johnson295189b2012-06-20 16:38:30 -07003488 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_FALSE);
3489 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_TRUE);
3490 // ... and apply the channel list, power settings, and the country code.
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003491 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.base20MHzChannels, pMac->scan.countryCodeCurrent, updateRiva );
Jeff Johnson295189b2012-06-20 16:38:30 -07003492 // clear the 11d channel list
Kiet Lam64c1b492013-07-12 13:56:44 +05303493 vos_mem_set(&pMac->scan.channels11d, sizeof(pMac->scan.channels11d), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003494 pMac->scan.f11dInfoReset = eANI_BOOLEAN_TRUE;
3495 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_FALSE;
3496 }
3497
3498 return;
3499}
3500
3501
3502eHalStatus csrResetCountryCodeInformation(tpAniSirGlobal pMac, tANI_BOOLEAN *pfRestartNeeded)
3503{
3504 eHalStatus status = eHAL_STATUS_SUCCESS;
3505 tANI_BOOLEAN fRestart = eANI_BOOLEAN_FALSE;
3506
3507 //Use the Country code and domain from EEPROM
Kiet Lam64c1b492013-07-12 13:56:44 +05303508 vos_mem_copy(pMac->scan.countryCodeCurrent, pMac->scan.countryCodeDefault,
3509 WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07003510 csrSetRegulatoryDomain(pMac, pMac->scan.domainIdCurrent, &fRestart);
Jeff Johnson43971f52012-07-17 12:26:56 -07003511 if( ((eANI_BOOLEAN_FALSE == fRestart) || (pfRestartNeeded == NULL) )
3512 && !csrIsInfraConnected(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -07003513 {
3514 //Only reset the country info if we don't need to restart
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003515 csrResetCountryInformation(pMac, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07003516 }
3517 if(pfRestartNeeded)
3518 {
3519 *pfRestartNeeded = fRestart;
3520 }
3521
3522 return (status);
3523}
3524
3525
3526eHalStatus csrSetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pCountry, tANI_BOOLEAN *pfRestartNeeded)
3527{
3528 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
3529 v_REGDOMAIN_t domainId;
3530
3531 if(pCountry)
3532 {
Kiet Lam6c583332013-10-14 05:37:09 +05303533 status = csrGetRegulatoryDomainForCountry(pMac, pCountry, &domainId, COUNTRY_USER);
Jeff Johnson295189b2012-06-20 16:38:30 -07003534 if(HAL_STATUS_SUCCESS(status))
3535 {
3536 status = csrSetRegulatoryDomain(pMac, domainId, pfRestartNeeded);
3537 if(HAL_STATUS_SUCCESS(status))
3538 {
3539 //We don't need to check the pMac->roam.configParam.fEnforceDefaultDomain flag here,
3540 //csrSetRegulatoryDomain will fail if the country doesn't fit our domain criteria.
Kiet Lam64c1b492013-07-12 13:56:44 +05303541 vos_mem_copy(pMac->scan.countryCodeCurrent, pCountry, WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07003542 if((pfRestartNeeded == NULL) || !(*pfRestartNeeded))
3543 {
3544 //Simply set it to cfg. If we need to restart, restart will apply it to the CFG
3545 csrSetCfgCountryCode(pMac, pCountry);
3546 }
3547 }
3548 }
3549 }
3550
3551 return (status);
3552}
3553
3554
3555
3556//caller allocated memory for pNumChn and pChnPowerInfo
3557//As input, *pNumChn has the size of the array of pChnPowerInfo
3558//Upon return, *pNumChn has the number of channels assigned.
3559void csrGetChannelPowerInfo( tpAniSirGlobal pMac, tDblLinkList *pList,
3560 tANI_U32 *pNumChn, tChannelListWithPower *pChnPowerInfo)
3561{
3562 tListElem *pEntry;
3563 tANI_U32 chnIdx = 0, idx;
3564 tCsrChannelPowerInfo *pChannelSet;
3565
3566 //Get 2.4Ghz first
3567 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
3568 while( pEntry && (chnIdx < *pNumChn) )
3569 {
3570 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3571 if ( 1 != pChannelSet->interChannelOffset )
3572 {
3573 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
3574 {
3575 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
3576 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
3577 }
3578 }
3579 else
3580 {
3581 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
3582 {
3583 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + idx);
3584 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
3585 }
3586 }
3587
3588 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
3589 }
3590 *pNumChn = chnIdx;
3591
3592 return ;
3593}
3594
3595
3596
3597void csrApplyCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce )
3598{
3599 v_REGDOMAIN_t domainId;
3600 eHalStatus status = eHAL_STATUS_SUCCESS;
3601
3602 do
3603 {
3604 if( !csrIs11dSupported( pMac ) || 0 == pMac->scan.channelOf11dInfo) break;
3605 if( pMac->scan.fAmbiguous11dInfoFound )
3606 {
3607 // ambiguous info found
3608 //Restore te default domain as well
Kiet Lam6c583332013-10-14 05:37:09 +05303609 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
3610 pMac, pMac->scan.countryCodeCurrent,
3611 &domainId, COUNTRY_QUERY)))
Jeff Johnson295189b2012-06-20 16:38:30 -07003612 {
3613 pMac->scan.domainIdCurrent = domainId;
3614 }
3615 else
3616 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003617 smsLog(pMac, LOGE, FL(" failed to get domain from currentCountryCode %02X%02X"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003618 pMac->scan.countryCodeCurrent[0], pMac->scan.countryCodeCurrent[1]);
3619 }
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003620 csrResetCountryInformation( pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE );
Jeff Johnson295189b2012-06-20 16:38:30 -07003621 break;
3622 }
3623 if ( pMac->scan.f11dInfoApplied && !fForce ) break;
Kiet Lam6c583332013-10-14 05:37:09 +05303624 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
3625 pMac, pMac->scan.countryCode11d,
3626 &domainId, COUNTRY_QUERY)))
Jeff Johnson295189b2012-06-20 16:38:30 -07003627 {
3628 //Check whether we need to enforce default domain
3629 if( ( !pMac->roam.configParam.fEnforceDefaultDomain ) ||
3630 (pMac->scan.domainIdCurrent == domainId) )
3631 {
3632
3633#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3634 {
3635 vos_log_802_11d_pkt_type *p11dLog;
3636 tChannelListWithPower chnPwrInfo[WNI_CFG_VALID_CHANNEL_LIST_LEN];
3637 tANI_U32 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN, nTmp;
3638
3639 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
3640 if(p11dLog)
3641 {
3642 p11dLog->eventId = WLAN_80211D_EVENT_COUNTRY_SET;
Kiet Lam64c1b492013-07-12 13:56:44 +05303643 vos_mem_copy(p11dLog->countryCode, pMac->scan.countryCode11d, 3);
Jeff Johnson295189b2012-06-20 16:38:30 -07003644 p11dLog->numChannel = pMac->scan.channels11d.numChannels;
3645 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
3646 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303647 vos_mem_copy(p11dLog->Channels,
3648 pMac->scan.channels11d.channelList,
3649 p11dLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07003650 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList24,
3651 &nChnInfo, chnPwrInfo);
3652 nTmp = nChnInfo;
3653 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN - nTmp;
3654 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList5G,
3655 &nChnInfo, &chnPwrInfo[nTmp]);
3656 for(nTmp = 0; nTmp < p11dLog->numChannel; nTmp++)
3657 {
3658 for(nChnInfo = 0; nChnInfo < WNI_CFG_VALID_CHANNEL_LIST_LEN; nChnInfo++)
3659 {
3660 if(p11dLog->Channels[nTmp] == chnPwrInfo[nChnInfo].chanId)
3661 {
3662 p11dLog->TxPwr[nTmp] = chnPwrInfo[nChnInfo].pwr;
3663 break;
3664 }
3665 }
3666 }
3667 }
3668 if(!pMac->roam.configParam.Is11dSupportEnabled)
3669 {
3670 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
3671 }
3672 else if(pMac->roam.configParam.fEnforceDefaultDomain)
3673 {
3674 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
3675 }
3676 else
3677 {
3678 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
3679 }
3680 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
3681 }
3682 }
3683#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3684 if(pMac->scan.domainIdCurrent != domainId)
3685 {
Jeff Johnson295189b2012-06-20 16:38:30 -07003686 smsLog(pMac, LOGW, FL("Domain Changed Old %d, new %d"),
3687 pMac->scan.domainIdCurrent, domainId);
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +05303688 status = WDA_SetRegDomain(pMac, domainId);
Jeff Johnson295189b2012-06-20 16:38:30 -07003689 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003690 if (status != eHAL_STATUS_SUCCESS)
3691 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003692 smsLog( pMac, LOGE, FL(" fail to set regId %d"), domainId );
Jeff Johnson295189b2012-06-20 16:38:30 -07003693 }
3694 pMac->scan.domainIdCurrent = domainId;
Kiet Lam6c583332013-10-14 05:37:09 +05303695#ifndef CONFIG_ENABLE_LINUX_REG
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003696 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.channels11d, pMac->scan.countryCode11d, eANI_BOOLEAN_TRUE );
Kiet Lam6c583332013-10-14 05:37:09 +05303697#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07003698 // switch to active scans using this new channel list
3699 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
3700 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_TRUE;
3701 pMac->scan.f11dInfoReset = eANI_BOOLEAN_FALSE;
3702 }
3703 }
3704
3705 } while( 0 );
3706
3707 return;
3708}
3709
3710
3711
3712tANI_BOOLEAN csrSave11dCountryString( tpAniSirGlobal pMac, tANI_U8 *pCountryCode,
3713 tANI_BOOLEAN fForce)
3714{
3715 tANI_BOOLEAN fCountryStringChanged = FALSE, fUnknownCountryCode = FALSE;
3716 tANI_U32 i;
Kiet Lam6c583332013-10-14 05:37:09 +05303717 v_REGDOMAIN_t regd;
Jeff Johnson295189b2012-06-20 16:38:30 -07003718
3719 // convert to UPPER here so we are assured the strings are always in upper case.
3720 for( i = 0; i < 3; i++ )
3721 {
3722 pCountryCode[ i ] = (tANI_U8)csrToUpper( pCountryCode[ i ] );
3723 }
3724
3725 // Some of the 'old' Cisco 350 series AP's advertise NA as the country code (for North America ??).
3726 // NA is not a valid country code or domain so let's allow this by changing it to the proper
3727 // country code (which is US). We've also seen some NETGEAR AP's that have "XX " as the country code
3728 // with valid 2.4 GHz US channel information. If we cannot find the country code advertised in the
3729 // 11d information element, let's default to US.
Kiet Lam6c583332013-10-14 05:37:09 +05303730 if ( !HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(pMac,
3731 pCountryCode,
3732 &regd,
3733 COUNTRY_QUERY) ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003734 {
3735 // Check the enforcement first
3736 if( pMac->roam.configParam.fEnforceDefaultDomain || pMac->roam.configParam.fEnforceCountryCodeMatch )
3737 {
3738 fUnknownCountryCode = TRUE;
3739 }
3740 else
3741 {
3742 pCountryCode[ 0 ] = 'U';
3743 pCountryCode[ 1 ] = 'S';
3744 }
3745 }
3746
3747 // We've seen some of the AP's improperly put a 0 for the third character of the country code.
3748 // spec says valid charcters are 'O' (for outdoor), 'I' for Indoor, or ' ' (space; for either).
3749 // if we see a 0 in this third character, let's change it to a ' '.
3750 if ( 0 == pCountryCode[ 2 ] )
3751 {
3752 pCountryCode[ 2 ] = ' ';
3753 }
3754
3755 if( !fUnknownCountryCode )
3756 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303757 fCountryStringChanged = (!vos_mem_compare(pMac->scan.countryCode11d, pCountryCode, 2));
Jeff Johnson295189b2012-06-20 16:38:30 -07003758
3759
3760 if(( 0 == pMac->scan.countryCode11d[ 0 ] && 0 == pMac->scan.countryCode11d[ 1 ] )
3761 || (fForce))
3762 {
3763 // this is the first .11d information
Kiet Lam64c1b492013-07-12 13:56:44 +05303764 vos_mem_copy(pMac->scan.countryCode11d, pCountryCode,
3765 sizeof( pMac->scan.countryCode11d ));
Jeff Johnson295189b2012-06-20 16:38:30 -07003766 }
3767 }
3768
3769 return( fCountryStringChanged );
3770}
3771
3772
3773void csrSaveChannelPowerForBand( tpAniSirGlobal pMac, tANI_BOOLEAN fPopulate5GBand )
3774{
3775 tANI_U32 Index, count=0;
3776 tSirMacChanInfo *pChanInfo;
3777 tSirMacChanInfo *pChanInfoStart;
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08003778 tANI_S32 maxChannelIndex;
3779
3780 maxChannelIndex = ( pMac->scan.base20MHzChannels.numChannels < WNI_CFG_VALID_CHANNEL_LIST_LEN ) ?
3781 pMac->scan.base20MHzChannels.numChannels : WNI_CFG_VALID_CHANNEL_LIST_LEN ;
Jeff Johnson295189b2012-06-20 16:38:30 -07003782
Kiet Lam64c1b492013-07-12 13:56:44 +05303783 pChanInfo = vos_mem_malloc(sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN);
3784 if ( NULL != pChanInfo )
Jeff Johnson295189b2012-06-20 16:38:30 -07003785 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303786 vos_mem_set(pChanInfo, sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003787 pChanInfoStart = pChanInfo;
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08003788 for (Index=0; Index < maxChannelIndex; Index++)
Jeff Johnson295189b2012-06-20 16:38:30 -07003789 {
3790 if ((fPopulate5GBand && (CSR_IS_CHANNEL_5GHZ(pMac->scan.defaultPowerTable[Index].chanId))) ||
3791 (!fPopulate5GBand && (CSR_IS_CHANNEL_24GHZ(pMac->scan.defaultPowerTable[Index].chanId))) )
3792 {
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08003793 if(count >= WNI_CFG_VALID_CHANNEL_LIST_LEN)
3794 {
3795 smsLog( pMac, LOGW, FL(" csrSaveChannelPowerForBand, count exceeded, count = %d"), count);
3796 break;
3797 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003798 pChanInfo->firstChanNum = pMac->scan.defaultPowerTable[Index].chanId;
3799 pChanInfo->numChannels = 1;
3800 pChanInfo->maxTxPower = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
3801 pChanInfo++;
3802 count++;
3803 }
3804 }
3805 if(count)
3806 {
3807 csrSaveToChannelPower2G_5G( pMac, count * sizeof(tSirMacChanInfo), pChanInfoStart );
3808 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303809 vos_mem_free(pChanInfoStart);
Jeff Johnson295189b2012-06-20 16:38:30 -07003810 }
3811}
3812
3813
3814void csrSetOppositeBandChannelInfo( tpAniSirGlobal pMac )
3815{
3816 tANI_BOOLEAN fPopulate5GBand = FALSE;
3817
3818 do
3819 {
3820 // if this is not a dual band product, then we don't need to set the opposite
3821 // band info. We only work in one band so no need to look in the other band.
3822 if ( !CSR_IS_OPEARTING_DUAL_BAND( pMac ) ) break;
3823 // if we found channel info on the 5.0 band and...
3824 if ( CSR_IS_CHANNEL_5GHZ( pMac->scan.channelOf11dInfo ) )
3825 {
3826 // and the 2.4 band is empty, then populate the 2.4 channel info
Kiet Lam8d985a02013-10-11 03:39:41 +05303827 if ( !csrLLIsListEmpty( &pMac->scan.channelPowerInfoList24, LL_ACCESS_LOCK ) ) break;
Jeff Johnson295189b2012-06-20 16:38:30 -07003828 fPopulate5GBand = FALSE;
3829 }
3830 else
3831 {
3832 // else, we found channel info in the 2.4 GHz band. If the 5.0 band is empty
3833 // set the 5.0 band info from the 2.4 country code.
Kiet Lam8d985a02013-10-11 03:39:41 +05303834 if ( !csrLLIsListEmpty( &pMac->scan.channelPowerInfoList5G, LL_ACCESS_LOCK ) ) break;
Jeff Johnson295189b2012-06-20 16:38:30 -07003835 fPopulate5GBand = TRUE;
3836 }
3837 csrSaveChannelPowerForBand( pMac, fPopulate5GBand );
3838
3839 } while( 0 );
3840}
3841
3842
3843tANI_BOOLEAN csrIsSupportedChannel(tpAniSirGlobal pMac, tANI_U8 channelId)
3844{
3845 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
3846 tANI_U32 i;
3847
3848 //Make sure it is a channel that is in our supported list.
3849 for ( i = 0; i < pMac->scan.baseChannels.numChannels; i++ )
3850 {
3851 if ( channelId == pMac->scan.baseChannels.channelList[i] )
3852 {
3853 fRet = eANI_BOOLEAN_TRUE;
3854 break;
3855 }
3856 }
3857
3858 //If it is configured to limit a set of the channels
3859 if( fRet && pMac->roam.configParam.fEnforce11dChannels )
3860 {
3861 fRet = eANI_BOOLEAN_FALSE;
3862 for ( i = 0; i < pMac->scan.base20MHzChannels.numChannels; i++ )
3863 {
3864 if ( channelId == pMac->scan.base20MHzChannels.channelList[i] )
3865 {
3866 fRet = eANI_BOOLEAN_TRUE;
3867 break;
3868 }
3869 }
3870 }
3871
3872 return (fRet);
3873}
3874
3875
3876
3877//bSize specify the buffer size of pChannelList
3878tANI_U8 csrGetChannelListFromChannelSet( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 bSize, tCsrChannelPowerInfo *pChannelSet )
3879{
3880 tANI_U8 i, j = 0, chnId;
3881
3882 bSize = CSR_MIN(bSize, pChannelSet->numChannels);
3883 for( i = 0; i < bSize; i++ )
3884 {
3885 chnId = (tANI_U8)(pChannelSet->firstChannel + ( i * pChannelSet->interChannelOffset ));
3886 if ( csrIsSupportedChannel( pMac, chnId ) )
3887 {
3888 pChannelList[j++] = chnId;
3889 }
3890 }
3891
3892 return (j);
3893}
3894
3895
3896
3897//bSize -- specify the buffer size of pChannelList
3898void csrConstructCurrentValidChannelList( tpAniSirGlobal pMac, tDblLinkList *pChannelSetList,
3899 tANI_U8 *pChannelList, tANI_U8 bSize, tANI_U8 *pNumChannels )
3900{
3901 tListElem *pEntry;
3902 tCsrChannelPowerInfo *pChannelSet;
3903 tANI_U8 numChannels;
3904 tANI_U8 *pChannels;
3905
3906 if( pChannelSetList && pChannelList && pNumChannels )
3907 {
3908 pChannels = pChannelList;
3909 *pNumChannels = 0;
3910 pEntry = csrLLPeekHead( pChannelSetList, LL_ACCESS_LOCK );
3911 while( pEntry )
3912 {
3913 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3914 numChannels = csrGetChannelListFromChannelSet( pMac, pChannels, bSize, pChannelSet );
3915 pChannels += numChannels;
3916 *pNumChannels += numChannels;
3917 pEntry = csrLLNext( pChannelSetList, pEntry, LL_ACCESS_LOCK );
3918 }
3919 }
3920}
3921
3922
3923/*
3924 * 802.11D only: Gather 11d IE via beacon or Probe response and store them in pAdapter->channels11d
3925*/
3926tANI_BOOLEAN csrLearnCountryInformation( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc,
3927 tDot11fBeaconIEs *pIes, tANI_BOOLEAN fForce)
3928{
Jeff Johnson295189b2012-06-20 16:38:30 -07003929 eHalStatus status;
3930 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
3931 v_REGDOMAIN_t domainId;
3932 tDot11fBeaconIEs *pIesLocal = pIes;
3933
Jeff Johnson295189b2012-06-20 16:38:30 -07003934 if (VOS_STA_SAP_MODE == vos_get_conparam ())
3935 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07003936
3937 do
3938 {
3939 // check if .11d support is enabled
3940 if( !csrIs11dSupported( pMac ) ) break;
3941 if( !pIesLocal && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc, &pIesLocal))) )
3942 {
3943 break;
3944 }
3945 // check if country information element is present
3946 if(!pIesLocal->Country.present)
3947 {
3948 //No country info
3949 break;
3950 }
3951
3952 if( csrSave11dCountryString( pMac, pIesLocal->Country.country, fForce ) )
3953 {
3954 // country string changed, this should not happen
3955 //Need to check whether we care about this BSS' domain info
3956 //If it doesn't match of the connected profile or roaming profile, let's ignore it
3957 tANI_U32 i;
3958 tCsrRoamSession *pSession;
3959
3960 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
3961 {
3962 if( CSR_IS_SESSION_VALID( pMac, i ) )
3963 {
3964 pSession = CSR_GET_SESSION( pMac, i );
3965 if(pSession->pCurRoamProfile)
3966 {
3967 tCsrScanResultFilter filter;
3968
Kiet Lam64c1b492013-07-12 13:56:44 +05303969 vos_mem_set(&filter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003970 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, &filter);
3971 if(HAL_STATUS_SUCCESS(status))
3972 {
3973 tANI_BOOLEAN fMatch = csrMatchBSS(pMac, pSirBssDesc, &filter, NULL, NULL, NULL, NULL);
3974 //Free the resource first
3975 csrFreeScanFilter( pMac, &filter );
3976 if(fMatch)
3977 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003978 smsLog(pMac, LOGW, " Matching roam profile BSSID %02X-%02X-%02X-%02X-%02X-%02X causing ambiguous domain info",
Jeff Johnson295189b2012-06-20 16:38:30 -07003979 pSirBssDesc->bssId[0], pSirBssDesc->bssId[1], pSirBssDesc->bssId[2],
3980 pSirBssDesc->bssId[3], pSirBssDesc->bssId[4], pSirBssDesc->bssId[5]);
3981 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_TRUE;
3982 break;
3983 }
3984 }
3985 }
3986 else if( csrIsConnStateConnected(pMac, i))
3987 {
3988 //Reach here only when the currention is base on no profile.
3989 //User doesn't give profile and just connect to anything.
3990 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile, pSirBssDesc, pIesLocal))
3991 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003992 smsLog(pMac, LOGW, " Matching connect profile BSSID %02X-%02X-%02X-%02X-%02X-%02X causing ambiguous domain info",
Jeff Johnson295189b2012-06-20 16:38:30 -07003993 pSirBssDesc->bssId[0], pSirBssDesc->bssId[1], pSirBssDesc->bssId[2],
3994 pSirBssDesc->bssId[3], pSirBssDesc->bssId[4], pSirBssDesc->bssId[5]);
3995 //Tush
3996 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_TRUE;
3997 if(csrIsBssidMatch(pMac, (tCsrBssid *)&pSirBssDesc->bssId,
3998 &pSession->connectedProfile.bssid))
3999 {
4000 //AP changed the 11d info on the fly, modify cfg
4001 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
4002 fRet = eANI_BOOLEAN_TRUE;
4003 }
4004 break;
4005 }
4006 }
4007 } //valid session
4008 } //for
4009 if ( i == CSR_ROAM_SESSION_MAX )
4010 {
4011 //Check whether we can use this country's 11d information
4012 if( !pMac->roam.configParam.fEnforceDefaultDomain )
4013 {
4014 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_TRUE;
4015 }
4016 else
4017 {
4018 VOS_ASSERT( pMac->scan.domainIdCurrent == pMac->scan.domainIdDefault );
4019 if( HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
Kiet Lam6c583332013-10-14 05:37:09 +05304020 pMac, pIesLocal->Country.country, &domainId,
4021 COUNTRY_QUERY)) &&
Jeff Johnson295189b2012-06-20 16:38:30 -07004022 ( domainId == pMac->scan.domainIdCurrent ) )
4023 {
4024 //Two countries in the same domain
4025 }
4026 }
4027 }
Kiet Lam6c583332013-10-14 05:37:09 +05304028#ifdef CONFIG_ENABLE_LINUX_REG
4029 csrGetRegulatoryDomainForCountry(pMac, pIesLocal->Country.country,
4030 &domainId, COUNTRY_IE);
4031#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004032 }
4033 else //Tush
4034 {
4035 pMac->scan.fCurrent11dInfoMatch = eANI_BOOLEAN_TRUE;
4036 }
4037
4038 //In case that some channels in 5GHz have the same channel number as 2.4GHz (<= 14)
4039 if(CSR_IS_CHANNEL_5GHZ(pSirBssDesc->channelId))
4040 {
4041 tANI_U8 iC;
4042 tSirMacChanInfo* pMacChnSet = (tSirMacChanInfo *)(&pIesLocal->Country.triplets[0]);
4043
4044 for(iC = 0; iC < pIesLocal->Country.num_triplets; iC++)
4045 {
4046 if(CSR_IS_CHANNEL_24GHZ(pMacChnSet[iC].firstChanNum))
4047 {
4048 pMacChnSet[iC].firstChanNum += 200; //*** Where is this 200 defined?
4049 }
4050 }
4051 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004052 smsLog(pMac, LOG3, FL(" %d sets each one is %d"), pIesLocal->Country.num_triplets, sizeof(tSirMacChanInfo));
Jeff Johnsone7245742012-09-05 17:12:55 -07004053
Jeff Johnson295189b2012-06-20 16:38:30 -07004054 // set the indicator of the channel where the country IE was found...
4055 pMac->scan.channelOf11dInfo = pSirBssDesc->channelId;
Kiet Lam6c583332013-10-14 05:37:09 +05304056#ifndef CONFIG_ENABLE_LINUX_REG
Kiet Lam8d985a02013-10-11 03:39:41 +05304057 status = csrGetRegulatoryDomainForCountry(pMac,
Kiet Lam6c583332013-10-14 05:37:09 +05304058 pIesLocal->Country.country, &domainId, COUNTRY_IE);
Kiet Lam8d985a02013-10-11 03:39:41 +05304059 if ( status != eHAL_STATUS_SUCCESS )
4060 {
4061 smsLog( pMac, LOGE, FL(" fail to get regId %d"), domainId );
4062 fRet = eANI_BOOLEAN_FALSE;
4063 break;
4064 }
Venkata Prathyusha Kuntupalli316247e2013-03-15 17:45:25 -07004065 // Checking for Domain Id change
4066 if ( domainId != pMac->scan.domainIdCurrent )
4067 {
Kiet Lam8d985a02013-10-11 03:39:41 +05304068 vos_mem_copy(pMac->scan.countryCode11d,
4069 pIesLocal->Country.country,
4070 sizeof( pMac->scan.countryCode11d ) );
4071 /* Set Current Country code and Current Regulatory domain */
4072 status = csrSetRegulatoryDomain(pMac, domainId, NULL);
4073 if (eHAL_STATUS_SUCCESS != status)
4074 {
4075 smsLog(pMac, LOGE, "Set Reg Domain Fail %d", status);
4076 fRet = eANI_BOOLEAN_FALSE;
4077 return fRet;
4078 }
4079 //csrSetRegulatoryDomain will fail if the country doesn't fit our domain criteria.
4080 vos_mem_copy(pMac->scan.countryCodeCurrent,
4081 pIesLocal->Country.country, WNI_CFG_COUNTRY_CODE_LEN);
4082 //Simply set it to cfg.
Madan Mohan Koyyalamudi0e5922d2013-09-10 15:45:24 +05304083 csrSetCfgCountryCode(pMac, pIesLocal->Country.country);
Kiet Lam8d985a02013-10-11 03:39:41 +05304084
4085 /* overwrite the defualt country code */
4086 vos_mem_copy(pMac->scan.countryCodeDefault,
4087 pMac->scan.countryCodeCurrent,
4088 WNI_CFG_COUNTRY_CODE_LEN);
4089 /* Set Current RegDomain */
4090 status = WDA_SetRegDomain(pMac, domainId);
4091 if ( status != eHAL_STATUS_SUCCESS )
4092 {
4093 smsLog( pMac, LOGE, FL(" fail to Set regId %d"), domainId );
4094 fRet = eANI_BOOLEAN_FALSE;
4095 return fRet;
4096 }
4097 /* set to default domain ID */
Madan Mohan Koyyalamudi0e5922d2013-09-10 15:45:24 +05304098 pMac->scan.domainIdCurrent = domainId;
Kiet Lam8d985a02013-10-11 03:39:41 +05304099 /* get the channels based on new cc */
4100 status = csrInitGetChannels( pMac );
Jeff Johnson295189b2012-06-20 16:38:30 -07004101
Kiet Lam8d985a02013-10-11 03:39:41 +05304102 if ( status != eHAL_STATUS_SUCCESS )
4103 {
4104 smsLog( pMac, LOGE, FL(" fail to get Channels "));
4105 fRet = eANI_BOOLEAN_FALSE;
4106 return fRet;
4107 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004108
Kiet Lam8d985a02013-10-11 03:39:41 +05304109 /* reset info based on new cc, and we are done */
4110 csrResetCountryInformation(pMac, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
Kiet Lam8d985a02013-10-11 03:39:41 +05304111 }
Kiet Lam6c583332013-10-14 05:37:09 +05304112#endif
4113 fRet = eANI_BOOLEAN_TRUE;
4114
Jeff Johnson295189b2012-06-20 16:38:30 -07004115 } while( 0 );
4116
4117 if( !pIes && pIesLocal )
4118 {
4119 //locally allocated
Kiet Lam64c1b492013-07-12 13:56:44 +05304120 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07004121 }
4122
4123 return( fRet );
4124}
4125
4126
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004127static void csrSaveScanResults( tpAniSirGlobal pMac, tANI_U8 reason )
Jeff Johnson295189b2012-06-20 16:38:30 -07004128{
4129 // initialize this to FALSE. profMoveInterimScanResultsToMainList() routine
4130 // will set this to the channel where an .11d beacon is seen
4131 pMac->scan.channelOf11dInfo = 0;
4132 // if we get any ambiguous .11d information then this will be set to TRUE
4133 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
4134 //Tush
4135 // if we get any ambiguous .11d information, then this will be set to TRUE
4136 // only if the applied 11d info could be found in one of the scan results
4137 pMac->scan.fCurrent11dInfoMatch = eANI_BOOLEAN_FALSE;
4138 // move the scan results from interim list to the main scan list
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004139 csrMoveTempScanResultsToMainList( pMac, reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07004140
4141 // Now check if we gathered any domain/country specific information
4142 // If so, we should update channel list and apply Tx power settings
Jeff Johnsone7245742012-09-05 17:12:55 -07004143 if( csrIs11dSupported(pMac) )
4144 {
4145 csrApplyCountryInformation( pMac, FALSE );
4146 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004147}
4148
4149
4150void csrReinitScanCmd(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4151{
4152 switch (pCommand->u.scanCmd.reason)
4153 {
4154 case eCsrScanSetBGScanParam:
4155 case eCsrScanAbortBgScan:
4156 if(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList)
4157 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304158 vos_mem_free(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList);
Jeff Johnson295189b2012-06-20 16:38:30 -07004159 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
4160 }
4161 break;
4162 case eCsrScanBGScanAbort:
4163 case eCsrScanBGScanEnable:
4164 case eCsrScanGetScanChnInfo:
4165 break;
4166 case eCsrScanAbortNormalScan:
4167 default:
4168 csrScanFreeRequest(pMac, &pCommand->u.scanCmd.u.scanRequest);
4169 break;
4170 }
4171 if(pCommand->u.scanCmd.pToRoamProfile)
4172 {
4173 csrReleaseProfile(pMac, pCommand->u.scanCmd.pToRoamProfile);
Kiet Lam64c1b492013-07-12 13:56:44 +05304174 vos_mem_free(pCommand->u.scanCmd.pToRoamProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07004175 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304176 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004177}
4178
4179
4180tANI_BOOLEAN csrGetRemainingChannelsFor11dScan( tpAniSirGlobal pMac, tANI_U8 *pChannels, tANI_U8 *pcChannels )
4181{
4182 tANI_U32 index11dChannels, index;
4183 tANI_U32 indexCurrentChannels;
4184 tANI_BOOLEAN fChannelAlreadyScanned;
4185 tANI_U32 len = sizeof(pMac->roam.validChannelList);
4186
4187 *pcChannels = 0;
4188 if ( CSR_IS_11D_INFO_FOUND(pMac) && csrRoamIsChannelValid(pMac, pMac->scan.channelOf11dInfo) )
4189 {
4190 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
4191 {
4192 //Find the channel index where we found the 11d info
4193 for(index = 0; index < len; index++)
4194 {
4195 if(pMac->scan.channelOf11dInfo == pMac->roam.validChannelList[index])
4196 break;
4197 }
4198 //check whether we found the channel index
4199 if(index < len)
4200 {
4201 // Now, look through the 11d channel list and create a list of all channels in the 11d list that are
4202 // NOT in the current channel list. This gives us a list of the new channels that have not been
4203 // scanned. We'll scan this new list so we have a complete set of scan results on all of the domain channels
4204 // initially.
4205 for ( index11dChannels = 0; index11dChannels < pMac->scan.channels11d.numChannels; index11dChannels++ )
4206 {
4207 fChannelAlreadyScanned = eANI_BOOLEAN_FALSE;
4208
4209 for( indexCurrentChannels = 0; indexCurrentChannels < index; indexCurrentChannels++ )
4210 {
4211 if ( pMac->roam.validChannelList[ indexCurrentChannels ] == pMac->scan.channels11d.channelList[ index11dChannels ] )
4212 {
4213 fChannelAlreadyScanned = eANI_BOOLEAN_TRUE;
4214 break;
4215 }
4216 }
4217
4218 if ( !fChannelAlreadyScanned )
4219 {
4220 pChannels[ *pcChannels ] = pMac->scan.channels11d.channelList[ index11dChannels ];
4221 ( *pcChannels )++;
4222 }
4223 }
4224 }
4225 }//GetCFG
4226 }
4227 return( *pcChannels );
4228}
4229
4230
4231eCsrScanCompleteNextCommand csrScanGetNextCommandState( tpAniSirGlobal pMac, tSmeCmd *pCommand, tANI_BOOLEAN fSuccess )
4232{
4233 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
4234
4235 switch( pCommand->u.scanCmd.reason )
4236 {
4237 case eCsrScan11d1:
4238 NextCommand = (fSuccess) ? eCsrNext11dScan1Success : eCsrNext11dScan1Failure;
4239 break;
4240 case eCsrScan11d2:
4241 NextCommand = (fSuccess) ? eCsrNext11dScan2Success : eCsrNext11dScan2Failure;
4242 break;
4243 case eCsrScan11dDone:
4244 NextCommand = eCsrNext11dScanComplete;
4245 break;
4246 case eCsrScanLostLink1:
4247 NextCommand = (fSuccess) ? eCsrNextLostLinkScan1Success : eCsrNextLostLinkScan1Failed;
4248 break;
4249 case eCsrScanLostLink2:
4250 NextCommand = (fSuccess) ? eCsrNextLostLinkScan2Success : eCsrNextLostLinkScan2Failed;
4251 break;
4252 case eCsrScanLostLink3:
4253 NextCommand = (fSuccess) ? eCsrNextLostLinkScan3Success : eCsrNextLostLinkScan3Failed;
4254 break;
4255 case eCsrScanForSsid:
4256 NextCommand = (fSuccess) ? eCsrNexteScanForSsidSuccess : eCsrNexteScanForSsidFailure;
4257 break;
4258 case eCsrScanForCapsChange:
4259 NextCommand = eCsrNextCapChangeScanComplete; //don't care success or not
4260 break;
4261 case eCsrScanIdleScan:
4262 NextCommand = eCsrNextIdleScanComplete;
4263 break;
4264 default:
4265 NextCommand = eCsrNextScanNothing;
4266 break;
4267 }
4268 return( NextCommand );
4269}
4270
4271
4272//Return whether the pCommand is finished.
4273tANI_BOOLEAN csrHandleScan11d1Failure(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4274{
4275 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
4276
4277 //Apply back the default setting and passively scan one more time.
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004278 csrResetCountryInformation(pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07004279 pCommand->u.scanCmd.reason = eCsrScan11d2;
4280 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
4281 {
4282 fRet = eANI_BOOLEAN_FALSE;
4283 }
4284
4285 return (fRet);
4286}
4287
4288
4289tANI_BOOLEAN csrHandleScan11dSuccess(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4290{
4291 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
4292 tANI_U8 *pChannels;
4293 tANI_U8 cChannels;
4294
Kiet Lam64c1b492013-07-12 13:56:44 +05304295 pChannels = vos_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
4296 if ( NULL != pChannels )
Jeff Johnson295189b2012-06-20 16:38:30 -07004297 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304298 vos_mem_set(pChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004299 if ( csrGetRemainingChannelsFor11dScan( pMac, pChannels, &cChannels ) )
4300 {
4301 pCommand->u.scanCmd.reason = eCsrScan11dDone;
4302 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
4303 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304304 vos_mem_free(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -07004305 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004306 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304307 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(cChannels);
4308 if ( NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07004309 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304310 vos_mem_copy(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
4311 pChannels, cChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07004312 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = cChannels;
4313 pCommand->u.scanCmd.u.scanRequest.requestType = eCSR_SCAN_REQUEST_FULL_SCAN;
4314 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
4315 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
4316 {
4317 //Reuse the same command buffer
4318 fRet = eANI_BOOLEAN_FALSE;
4319 }
4320 }
4321 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304322 vos_mem_free(pChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07004323 }
4324
4325 return (fRet);
4326}
4327
4328//Return whether the command should be removed
4329tANI_BOOLEAN csrScanComplete( tpAniSirGlobal pMac, tSirSmeScanRsp *pScanRsp )
4330{
4331 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
4332 tListElem *pEntry;
4333 tSmeCmd *pCommand;
4334 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
4335 tANI_BOOLEAN fSuccess;
4336
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05304337 if (pMac->fScanOffload)
4338 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
4339 else
4340 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07004341
4342 if ( pEntry )
4343 {
4344 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
4345
4346 // If the head of the queue is Active and it is a SCAN command, remove
4347 // and put this on the Free queue.
4348 if ( eSmeCommandScan == pCommand->command )
4349 {
4350 tANI_U32 sessionId = pCommand->sessionId;
4351
4352 if(eSIR_SME_SUCCESS != pScanRsp->statusCode)
4353 {
4354 fSuccess = eANI_BOOLEAN_FALSE;
4355 }
4356 else
4357 {
4358 //pMac->scan.tempScanResults is not empty meaning the scan found something
4359 //This check only valid here because csrSaveScanresults is not yet called
4360 fSuccess = (!csrLLIsListEmpty(&pMac->scan.tempScanResults, LL_ACCESS_LOCK));
4361 }
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004362 csrSaveScanResults(pMac, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07004363
4364#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4365 {
4366 vos_log_scan_pkt_type *pScanLog = NULL;
4367 tScanResultHandle hScanResult;
4368 tCsrScanResultInfo *pScanResult;
4369 tDot11fBeaconIEs *pIes;
4370 int n = 0, c = 0;
4371
4372 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
4373 if(pScanLog)
4374 {
4375 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
4376 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
4377 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
4378 {
4379 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_RSP;
4380 }
4381 else
4382 {
4383 if( eSIR_PASSIVE_SCAN != pMac->scan.curScanType )
4384 {
4385 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_RSP;
4386 }
4387 else
4388 {
4389 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_RSP;
4390 }
4391 }
4392 if(eSIR_SME_SUCCESS == pScanRsp->statusCode)
4393 {
4394 if(HAL_STATUS_SUCCESS(csrScanGetResult(pMac, NULL, &hScanResult)))
4395 {
4396 while(((pScanResult = csrScanResultGetNext(pMac, hScanResult)) != NULL))
4397 {
4398 if( n < VOS_LOG_MAX_NUM_BSSID )
4399 {
4400 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pScanResult->BssDescriptor, &pIes)))
4401 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004402 smsLog(pMac, LOGE, FL(" fail to parse IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07004403 break;
4404 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304405 vos_mem_copy(pScanLog->bssid[n],
4406 pScanResult->BssDescriptor.bssId, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07004407 if(pIes && pIes->SSID.present && VOS_LOG_MAX_SSID_SIZE >= pIes->SSID.num_ssid)
4408 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304409 vos_mem_copy(pScanLog->ssid[n],
4410 pIes->SSID.ssid, pIes->SSID.num_ssid);
Jeff Johnson295189b2012-06-20 16:38:30 -07004411 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304412 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07004413 n++;
4414 }
4415 c++;
4416 }
4417 pScanLog->numSsid = (v_U8_t)n;
4418 pScanLog->totalSsid = (v_U8_t)c;
4419 csrScanResultPurge(pMac, hScanResult);
4420 }
4421 }
4422 else
4423 {
4424 pScanLog->status = WLAN_SCAN_STATUS_FAILURE;
4425 }
4426 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
4427 }
4428 }
4429#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4430
4431 NextCommand = csrScanGetNextCommandState(pMac, pCommand, fSuccess);
4432 //We reuse the command here instead reissue a new command
4433 switch(NextCommand)
4434 {
4435 case eCsrNext11dScan1Success:
4436 case eCsrNext11dScan2Success:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004437 smsLog( pMac, LOG2, FL("11dScan1/3 produced results. Reissue Active scan..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004438 // if we found country information, no need to continue scanning further, bail out
4439 fRemoveCommand = eANI_BOOLEAN_TRUE;
4440 NextCommand = eCsrNext11dScanComplete;
4441 break;
4442 case eCsrNext11dScan1Failure:
4443 //We are not done yet. 11d scan fail once. We will try to reset anything and do it over again
4444 //The only meaningful thing for this retry is that we cannot find 11d information after a reset so
4445 //we clear the "old" 11d info and give it once more chance
4446 fRemoveCommand = csrHandleScan11d1Failure(pMac, pCommand);
4447 if(fRemoveCommand)
4448 {
4449 NextCommand = eCsrNext11dScanComplete;
4450 }
4451 break;
4452 case eCsrNextLostLinkScan1Success:
4453 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink1)))
4454 {
4455 csrScanHandleFailedLostlink1(pMac, sessionId);
4456 }
4457 break;
4458 case eCsrNextLostLinkScan2Success:
4459 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink2)))
4460 {
4461 csrScanHandleFailedLostlink2(pMac, sessionId);
4462 }
4463 break;
4464 case eCsrNextLostLinkScan3Success:
4465 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink3)))
4466 {
4467 csrScanHandleFailedLostlink3(pMac, sessionId);
4468 }
4469 break;
4470 case eCsrNextLostLinkScan1Failed:
4471 csrScanHandleFailedLostlink1(pMac, sessionId);
4472 break;
4473 case eCsrNextLostLinkScan2Failed:
4474 csrScanHandleFailedLostlink2(pMac, sessionId);
4475 break;
4476 case eCsrNextLostLinkScan3Failed:
4477 csrScanHandleFailedLostlink3(pMac, sessionId);
4478 break;
4479 case eCsrNexteScanForSsidSuccess:
4480 csrScanHandleSearchForSSID(pMac, pCommand);
4481 break;
4482 case eCsrNexteScanForSsidFailure:
4483 csrScanHandleSearchForSSIDFailure(pMac, pCommand);
4484 break;
4485 case eCsrNextIdleScanComplete:
4486 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
4487 break;
4488 case eCsrNextCapChangeScanComplete:
4489 csrScanHandleCapChangeScanComplete(pMac, sessionId);
4490 break;
4491 default:
4492
4493 break;
4494 }
4495 }
4496 else
4497 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004498 smsLog( pMac, LOGW, FL("Scan Completion called but SCAN command is not ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004499 fRemoveCommand = eANI_BOOLEAN_FALSE;
4500 }
4501 }
4502 else
4503 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004504 smsLog( pMac, LOGW, FL("Scan Completion called but NO commands are ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004505 fRemoveCommand = eANI_BOOLEAN_FALSE;
4506 }
4507
4508 return( fRemoveCommand );
4509}
4510
4511
4512
4513static void csrScanRemoveDupBssDescriptionFromInterimList( tpAniSirGlobal pMac,
4514 tSirBssDescription *pSirBssDescr,
4515 tDot11fBeaconIEs *pIes)
4516{
4517 tListElem *pEntry;
4518 tCsrScanResult *pCsrBssDescription;
4519
4520 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
4521 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
4522 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
4523 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
4524 while( pEntry )
4525 {
4526 pCsrBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
4527
4528 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
4529 // matches
4530
4531 if ( csrIsDuplicateBssDescription( pMac, &pCsrBssDescription->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07004532 pSirBssDescr, pIes, FALSE ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07004533 {
4534 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
4535 ((tANI_S32)pCsrBssDescription->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
4536
4537 // Remove the 'old' entry from the list....
4538 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK ) )
4539 {
4540 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pCsrBssDescription->Result.BssDescriptor);
4541 // we need to free the memory associated with this node
4542 csrFreeScanResultEntry( pMac, pCsrBssDescription );
4543 }
4544
4545 // If we found a match, we can stop looking through the list.
4546 break;
4547 }
4548
4549 pEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK );
4550 }
4551}
4552
4553
4554
4555//Caller allocated memory pfNewBssForConn to return whether new candidate for
4556//current connection is found. Cannot be NULL
4557tCsrScanResult *csrScanSaveBssDescriptionToInterimList( tpAniSirGlobal pMac,
4558 tSirBssDescription *pBSSDescription,
4559 tDot11fBeaconIEs *pIes)
4560{
4561 tCsrScanResult *pCsrBssDescription = NULL;
4562 tANI_U32 cbBSSDesc;
4563 tANI_U32 cbAllocated;
Jeff Johnson295189b2012-06-20 16:38:30 -07004564
4565 // figure out how big the BSS description is (the BSSDesc->length does NOT
4566 // include the size of the length field itself).
4567 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
4568
4569 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
4570
Kiet Lam64c1b492013-07-12 13:56:44 +05304571 pCsrBssDescription = vos_mem_malloc(cbAllocated);
4572 if ( NULL != pCsrBssDescription )
Jeff Johnson295189b2012-06-20 16:38:30 -07004573 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304574 vos_mem_set(pCsrBssDescription, cbAllocated, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004575 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Kiet Lam64c1b492013-07-12 13:56:44 +05304576 vos_mem_copy(&pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc );
Jeff Johnson295189b2012-06-20 16:38:30 -07004577 //Save SSID separately for later use
4578 if( pIes->SSID.present && !csrIsNULLSSID(pIes->SSID.ssid, pIes->SSID.num_ssid) )
4579 {
4580 //SSID not hidden
Madan Mohan Koyyalamudi4e31b132012-11-02 13:13:52 -07004581 tANI_U32 len = pIes->SSID.num_ssid;
Jeff Johnson295189b2012-06-20 16:38:30 -07004582 if (len > SIR_MAC_MAX_SSID_LENGTH)
4583 {
4584 // truncate to fit in our struct
4585 len = SIR_MAC_MAX_SSID_LENGTH;
4586 }
4587 pCsrBssDescription->Result.ssId.length = len;
4588 pCsrBssDescription->Result.timer = vos_timer_get_system_time();
Kiet Lam64c1b492013-07-12 13:56:44 +05304589 vos_mem_copy(pCsrBssDescription->Result.ssId.ssId, pIes->SSID.ssid, len);
Jeff Johnson295189b2012-06-20 16:38:30 -07004590 }
4591 csrLLInsertTail( &pMac->scan.tempScanResults, &pCsrBssDescription->Link, LL_ACCESS_LOCK );
4592 }
4593
4594 return( pCsrBssDescription );
4595}
4596
4597
4598
4599
4600tANI_BOOLEAN csrIsDuplicateBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc1,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07004601 tSirBssDescription *pSirBssDesc2, tDot11fBeaconIEs *pIes2, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07004602{
4603 tANI_BOOLEAN fMatch = FALSE;
4604 tSirMacCapabilityInfo *pCap1, *pCap2;
4605 tDot11fBeaconIEs *pIes1 = NULL;
Jeff Johnsone7245742012-09-05 17:12:55 -07004606 tDot11fBeaconIEs *pIesTemp = pIes2;
Jeff Johnson295189b2012-06-20 16:38:30 -07004607
4608 pCap1 = (tSirMacCapabilityInfo *)&pSirBssDesc1->capabilityInfo;
4609 pCap2 = (tSirMacCapabilityInfo *)&pSirBssDesc2->capabilityInfo;
4610 if(pCap1->ess == pCap2->ess)
4611 {
4612 if (pCap1->ess &&
Jeff Johnsone7245742012-09-05 17:12:55 -07004613 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId)&&
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07004614 (fForced || (pSirBssDesc1->channelId == pSirBssDesc2->channelId)))
Jeff Johnson295189b2012-06-20 16:38:30 -07004615 {
4616 fMatch = TRUE;
Jeff Johnsone7245742012-09-05 17:12:55 -07004617 // Check for SSID match, if exists
4618 do
4619 {
4620 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
4621 {
4622 break;
4623 }
4624 if( NULL == pIesTemp )
4625 {
4626 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
4627 {
4628 break;
4629 }
4630 }
4631 if(pIes1->SSID.present && pIesTemp->SSID.present)
4632 {
4633 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
4634 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
4635 }
4636 }while(0);
4637
Jeff Johnson295189b2012-06-20 16:38:30 -07004638 }
4639 else if (pCap1->ibss && (pSirBssDesc1->channelId == pSirBssDesc2->channelId))
4640 {
Jeff Johnson295189b2012-06-20 16:38:30 -07004641
4642 do
4643 {
4644 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
4645 {
4646 break;
4647 }
4648 if( NULL == pIesTemp )
4649 {
4650 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
4651 {
4652 break;
4653 }
4654 }
4655 //Same channel cannot have same SSID for different IBSS
4656 if(pIes1->SSID.present && pIesTemp->SSID.present)
4657 {
4658 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
4659 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
4660 }
4661 }while(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004662 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004663 /* In case of P2P devices, ess and ibss will be set to zero */
4664 else if (!pCap1->ess &&
4665 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId))
4666 {
4667 fMatch = TRUE;
4668 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004669 }
4670
4671 if(pIes1)
4672 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304673 vos_mem_free(pIes1);
Jeff Johnson295189b2012-06-20 16:38:30 -07004674 }
Jeff Johnsone7245742012-09-05 17:12:55 -07004675
4676 if( (NULL == pIes2) && pIesTemp )
4677 {
4678 //locally allocated
Kiet Lam64c1b492013-07-12 13:56:44 +05304679 vos_mem_free(pIesTemp);
Jeff Johnsone7245742012-09-05 17:12:55 -07004680 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004681
4682 return( fMatch );
4683}
4684
4685
4686tANI_BOOLEAN csrIsNetworkTypeEqual( tSirBssDescription *pSirBssDesc1, tSirBssDescription *pSirBssDesc2 )
4687{
4688 return( pSirBssDesc1->nwType == pSirBssDesc2->nwType );
4689}
4690
4691
4692//to check whether the BSS matches the dot11Mode
4693static tANI_BOOLEAN csrScanIsBssAllowed(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
4694 tDot11fBeaconIEs *pIes)
4695{
4696 tANI_BOOLEAN fAllowed = eANI_BOOLEAN_FALSE;
4697 eCsrPhyMode phyMode;
4698
4699 if(HAL_STATUS_SUCCESS(csrGetPhyModeFromBss(pMac, pBssDesc, &phyMode, pIes)))
4700 {
4701 switch(pMac->roam.configParam.phyMode)
4702 {
4703 case eCSR_DOT11_MODE_11b:
4704 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
4705 break;
4706 case eCSR_DOT11_MODE_11g:
4707 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
4708 break;
4709 case eCSR_DOT11_MODE_11g_ONLY:
4710 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11g == phyMode);
4711 break;
4712 case eCSR_DOT11_MODE_11a:
4713 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11b != phyMode) && (eCSR_DOT11_MODE_11g != phyMode));
4714 break;
4715 case eCSR_DOT11_MODE_11n_ONLY:
4716 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11n == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
4717 break;
Jeff Johnsone7245742012-09-05 17:12:55 -07004718
4719#ifdef WLAN_FEATURE_11AC
4720 case eCSR_DOT11_MODE_11ac_ONLY:
4721 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11ac == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
4722 break;
4723#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004724 case eCSR_DOT11_MODE_11b_ONLY:
4725 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11b == phyMode);
4726 break;
4727 case eCSR_DOT11_MODE_11a_ONLY:
4728 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a == phyMode);
4729 break;
4730 case eCSR_DOT11_MODE_11n:
Jeff Johnsone7245742012-09-05 17:12:55 -07004731#ifdef WLAN_FEATURE_11AC
4732 case eCSR_DOT11_MODE_11ac:
4733#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004734 case eCSR_DOT11_MODE_TAURUS:
4735 default:
4736 fAllowed = eANI_BOOLEAN_TRUE;
4737 break;
4738 }
4739 }
4740
4741 return (fAllowed);
4742}
4743
4744
4745
4746//Return pIes to caller for future use when returning TRUE.
4747static tANI_BOOLEAN csrScanValidateScanResult( tpAniSirGlobal pMac, tANI_U8 *pChannels,
4748 tANI_U8 numChn, tSirBssDescription *pBssDesc,
4749 tDot11fBeaconIEs **ppIes )
4750{
4751 tANI_BOOLEAN fValidChannel = FALSE;
4752 tDot11fBeaconIEs *pIes = NULL;
4753 tANI_U8 index;
4754
4755 for( index = 0; index < numChn; index++ )
4756 {
4757 // This check relies on the fact that a single BSS description is returned in each
4758 // ScanRsp call, which is the way LIM implemented the scan req/rsp funtions. We changed
4759 // to this model when we ran with a large number of APs. If this were to change, then
4760 // this check would have to mess with removing the bssDescription from somewhere in an
4761 // arbitrary index in the bssDescription array.
4762 if ( pChannels[ index ] == pBssDesc->channelId )
4763 {
4764 fValidChannel = TRUE;
4765 break;
4766 }
4767 }
4768 *ppIes = NULL;
4769 if(fValidChannel)
4770 {
4771 if( HAL_STATUS_SUCCESS( csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIes) ) )
4772 {
4773 fValidChannel = csrScanIsBssAllowed(pMac, pBssDesc, pIes);
4774 if( fValidChannel )
4775 {
4776 *ppIes = pIes;
4777 }
4778 else
4779 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304780 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07004781 }
4782 }
4783 else
4784 {
4785 fValidChannel = FALSE;
4786 }
4787 }
4788
4789 return( fValidChannel );
4790}
4791
4792
4793//Return whether last scan result is received
4794static tANI_BOOLEAN csrScanProcessScanResults( tpAniSirGlobal pMac, tSmeCmd *pCommand,
4795 tSirSmeScanRsp *pScanRsp, tANI_BOOLEAN *pfRemoveCommand )
4796{
4797 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE, fRemoveCommand = eANI_BOOLEAN_FALSE;
4798 tDot11fBeaconIEs *pIes = NULL;
4799 tANI_U32 cbParsed;
4800 tSirBssDescription *pSirBssDescription;
4801 tANI_U32 cbBssDesc;
4802 tANI_U32 cbScanResult = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription )
4803 + sizeof(tSirBssDescription); //We need at least one CB
4804
4805 // don't consider the scan rsp to be valid if the status code is Scan Failure. Scan Failure
4806 // is returned when the scan could not find anything. so if we get scan failure return that
4807 // the scan response is invalid. Also check the lenght in the scan result for valid scan
4808 // BssDescriptions....
4809 do
4810 {
4811 if ( ( cbScanResult <= pScanRsp->length ) &&
4812 (( eSIR_SME_SUCCESS == pScanRsp->statusCode ) ||
4813 ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW == pScanRsp->statusCode ) ) )
4814 {
4815 tANI_U8 *pChannelList = NULL;
4816 tANI_U8 cChannels = 0;
4817
4818 //Different scan type can reach this point, we need to distinguish it
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004819#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
4820 if( eCsrScanGetLfrResult == pCommand->u.scanCmd.reason )
4821 {
4822 pChannelList = NULL;
4823 cChannels = 0;
4824 }
4825 else
4826#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004827 if( eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason )
4828 {
4829 //eCsrScanSetBGScanParam uses different structure
4830 tCsrBGScanRequest *pBgScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
4831
4832 cChannels = pBgScanReq->ChannelInfo.numOfChannels;
4833 pChannelList = pBgScanReq->ChannelInfo.ChannelList;
4834 }
4835 else
4836 {
4837 //the rest use generic scan request
4838 cChannels = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
4839 pChannelList = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
4840 }
4841
4842 // if the scan result is not on one of the channels in the Valid channel list, then it
4843 // must have come from an AP on an overlapping channel (in the 2.4GHz band). In this case,
4844 // let's drop the scan result.
4845 //
4846 // The other situation is where the scan request is for a scan on a particular channel set
4847 // and the scan result is from a
4848
4849 // if the NumChannels is 0, then we are supposed to be scanning all channels. Use the full channel
4850 // list as the 'valid' channel list. Otherwise, use the specific channel list in the scan parms
4851 // as the valid channels.
4852 if ( 0 == cChannels )
4853 {
4854 tANI_U32 len = sizeof(pMac->roam.validChannelList);
4855
4856 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
4857 {
4858 pChannelList = pMac->roam.validChannelList;
4859 cChannels = (tANI_U8)len;
4860 }
4861 else
4862 {
4863 //Cannot continue
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004864 smsLog( pMac, LOGE, "CSR: Processing internal SCAN results...csrGetCfgValidChannels failed" );
Jeff Johnson295189b2012-06-20 16:38:30 -07004865 break;
4866 }
4867 }
4868
4869 smsLog( pMac, LOG2, "CSR: Processing internal SCAN results..." );
4870 cbParsed = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription );
4871 pSirBssDescription = pScanRsp->bssDescription;
4872 while( cbParsed < pScanRsp->length )
4873 {
4874 if ( csrScanValidateScanResult( pMac, pChannelList, cChannels, pSirBssDescription, &pIes ) )
4875 {
4876 csrScanRemoveDupBssDescriptionFromInterimList(pMac, pSirBssDescription, pIes);
4877 csrScanSaveBssDescriptionToInterimList( pMac, pSirBssDescription, pIes );
4878 if( eSIR_PASSIVE_SCAN == pMac->scan.curScanType )
4879 {
4880 if( csrIs11dSupported( pMac) )
4881 {
4882 //Check whether the BSS is acceptable base on 11d info and our configs.
4883 if( csrMatchCountryCode( pMac, NULL, pIes ) )
4884 {
4885 //Double check whether the channel is acceptable by us.
4886 if( csrIsSupportedChannel( pMac, pSirBssDescription->channelId ) )
4887 {
4888 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
4889 }
4890 }
4891 }
4892 else
4893 {
4894 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
4895 }
4896 }
4897 //Free the resource
Kiet Lam64c1b492013-07-12 13:56:44 +05304898 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07004899 }
4900 // skip over the BSS description to the next one...
4901 cbBssDesc = pSirBssDescription->length + sizeof( pSirBssDescription->length );
4902
4903 cbParsed += cbBssDesc;
4904 pSirBssDescription = (tSirBssDescription *)((tANI_U8 *)pSirBssDescription + cbBssDesc );
4905
4906 } //while
4907 }
4908 else
4909 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004910 smsLog( pMac, LOGW, " Scanrsp fail (0x%08X), length = %d (expected %d)",
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08004911 pScanRsp->statusCode, pScanRsp->length, cbScanResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07004912 //HO bg scan/probe failed no need to try autonomously
4913 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
4914 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004915#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
4916 eCsrScanGetLfrResult == pCommand->u.scanCmd.reason ||
4917#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004918 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
4919 {
4920 fRemoveCommand = eANI_BOOLEAN_TRUE;
4921 }
4922 }
4923 }while(0);
4924 if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
4925 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004926 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 -07004927 fRemoveCommand = csrScanComplete( pMac, pScanRsp );
4928 fRet = eANI_BOOLEAN_TRUE;
4929 }//if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
4930 if(pfRemoveCommand)
4931 {
4932 *pfRemoveCommand = fRemoveCommand;
4933 }
4934
4935#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05304936 if (pMac->fScanOffload)
4937 return fRet;
4938
Jeff Johnson295189b2012-06-20 16:38:30 -07004939 if (!csrLLIsListEmpty( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK ))
4940 {
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08004941 /* Pending scan commands in the list because the previous scan command
4942 * was split into a scan command on one channel + a scan command for all
4943 * remaining channels.
4944 *
4945 * Start timer to trigger processing of the next scan command.
Srikant Kuppa866893f2012-12-27 17:28:14 -08004946 * NOTE for LFR:
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05304947 * Do not split scans if no concurrent infra connections are
Srikant Kuppa866893f2012-12-27 17:28:14 -08004948 * active and if the scan is a BG scan triggered by LFR (OR)
4949 * any scan if LFR is in the middle of a BG scan. Splitting
4950 * the scan is delaying the time it takes for LFR to find
4951 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08004952 */
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05304953 if ( (csrIsStaSessionConnected(pMac) &&
Srikant Kuppa866893f2012-12-27 17:28:14 -08004954#ifdef FEATURE_WLAN_LFR
4955 (csrIsConcurrentInfraConnected(pMac) ||
4956 ((pCommand->u.scanCmd.reason != eCsrScanBgScan) &&
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05304957 (pMac->roam.neighborRoamInfo.neighborRoamState !=
Srikant Kuppa866893f2012-12-27 17:28:14 -08004958 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
4959#endif
4960 (pCommand->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05304961 (csrIsP2pSessionConnected(pMac)) )
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08004962 {
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08004963 /* if active connected sessions present then continue to split scan
4964 * with specified interval between consecutive scans */
4965 csrSetDefaultScanTiming(pMac, pCommand->u.scanCmd.u.scanRequest.scanType, &(pCommand->u.scanCmd.u.scanRequest));
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05304966 vos_timer_start(&pMac->scan.hTimerStaApConcTimer,
4967 pCommand->u.scanCmd.u.scanRequest.restTime);
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08004968 } else {
4969 /* if no connected sessions present then initiate next scan command immediately */
4970 /* minimum timer granularity is 10ms */
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05304971 vos_timer_start(&pMac->scan.hTimerStaApConcTimer, 10);
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08004972 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004973 }
4974#endif
4975 return (fRet);
4976}
4977
4978
4979tANI_BOOLEAN csrScanIsWildCardScan( tpAniSirGlobal pMac, tSmeCmd *pCommand )
4980{
4981 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
Kiet Lam64c1b492013-07-12 13:56:44 +05304982 tANI_BOOLEAN f = vos_mem_compare(pCommand->u.scanCmd.u.scanRequest.bssid,
4983 bssid, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07004984
4985 //It is not a wild card scan if the bssid is not broadcast and the number of SSID is 1.
4986 return ((tANI_BOOLEAN)( (f || (0xff == pCommand->u.scanCmd.u.scanRequest.bssid[0])) &&
4987 (pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs != 1) ));
4988}
4989
4990
4991eHalStatus csrScanSmeScanResponse( tpAniSirGlobal pMac, void *pMsgBuf )
4992{
4993 eHalStatus status = eHAL_STATUS_SUCCESS;
4994 tListElem *pEntry;
4995 tSmeCmd *pCommand;
4996 eCsrScanStatus scanStatus;
4997 tSirSmeScanRsp *pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
4998 tSmeGetScanChnRsp *pScanChnInfo;
4999 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
5000 eCsrScanReason reason = eCsrScanOther;
5001
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305002 if (pMac->fScanOffload)
5003 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList,
5004 LL_ACCESS_LOCK);
5005 else
5006 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07005007
5008 if ( pEntry )
5009 {
5010 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
5011 if ( eSmeCommandScan == pCommand->command )
5012 {
5013 scanStatus = (eSIR_SME_SUCCESS == pScanRsp->statusCode) ? eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
5014 reason = pCommand->u.scanCmd.reason;
5015 switch(pCommand->u.scanCmd.reason)
5016 {
5017 case eCsrScanAbortBgScan:
5018 case eCsrScanAbortNormalScan:
5019 case eCsrScanBGScanAbort:
5020 case eCsrScanBGScanEnable:
5021 break;
5022 case eCsrScanGetScanChnInfo:
5023 pScanChnInfo = (tSmeGetScanChnRsp *)pMsgBuf;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005024 /*
5025 * status code not available in tSmeGetScanChnRsp, so
5026 * by default considereing it to be success
5027 */
5028 scanStatus = eSIR_SME_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07005029 csrScanAgeResults(pMac, pScanChnInfo);
5030 break;
5031 case eCsrScanForCapsChange:
5032 csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand );
5033 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005034 case eCsrScanP2PFindPeer:
5035 scanStatus = ((eSIR_SME_SUCCESS == pScanRsp->statusCode) && (pScanRsp->length > 50)) ? eCSR_SCAN_FOUND_PEER : eCSR_SCAN_FAILURE;
5036 csrScanProcessScanResults( pMac, pCommand, pScanRsp, NULL );
5037 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005038 case eCsrScanSetBGScanParam:
5039 default:
5040 if(csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand ))
5041 {
5042 //Not to get channel info if the scan is not a wildcard scan because
5043 //it may cause scan results got aged out incorrectly.
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005044 if( csrScanIsWildCardScan( pMac, pCommand ) && (!pCommand->u.scanCmd.u.scanRequest.p2pSearch)
5045#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5046 && (pCommand->u.scanCmd.reason != eCsrScanGetLfrResult)
5047#endif
5048 )
Jeff Johnson295189b2012-06-20 16:38:30 -07005049 {
5050 //Get the list of channels scanned
Jeff Johnson32d95a32012-09-10 13:15:23 -07005051 if( pCommand->u.scanCmd.reason != eCsrScanUserRequest)
5052 {
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05305053 csrScanGetScanChnInfo(pMac, pCommand->sessionId,
5054 NULL, NULL);
Jeff Johnson32d95a32012-09-10 13:15:23 -07005055 }
5056 else
5057 {
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05305058 csrScanGetScanChnInfo(pMac,
5059 pCommand->sessionId,
5060 pCommand->u.scanCmd.pContext,
5061 pCommand->u.scanCmd.callback);
Jeff Johnson32d95a32012-09-10 13:15:23 -07005062 pCommand->u.scanCmd.callback = NULL;
5063 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005064 }
5065 }
5066 break;
5067 }//switch
5068 if(fRemoveCommand)
5069 {
5070
5071 csrReleaseScanCommand(pMac, pCommand, scanStatus);
5072
Srikant Kuppa866893f2012-12-27 17:28:14 -08005073 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005074 smeProcessPendingQueue( pMac );
5075 }
5076 else
5077 {
5078 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
5079 status = eHAL_STATUS_FAILURE;
5080 }
5081 }
5082 else
5083 {
5084 smsLog( pMac, LOGW, "CSR: Scan Completion called but NO commands are ACTIVE ..." );
5085 status = eHAL_STATUS_FAILURE;
5086 }
5087
5088 return (status);
5089}
5090
5091
5092
5093
5094tCsrScanResultInfo *csrScanResultGetFirst(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
5095{
5096 tListElem *pEntry;
5097 tCsrScanResult *pResult;
5098 tCsrScanResultInfo *pRet = NULL;
5099 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5100
5101 if(pResultList)
5102 {
5103 csrLLLock(&pResultList->List);
5104 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5105 if(pEntry)
5106 {
5107 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
5108 pRet = &pResult->Result;
5109 }
5110 pResultList->pCurEntry = pEntry;
5111 csrLLUnlock(&pResultList->List);
5112 }
5113
5114 return pRet;
5115}
5116
5117
5118tCsrScanResultInfo *csrScanResultGetNext(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
5119{
5120 tListElem *pEntry = NULL;
5121 tCsrScanResult *pResult = NULL;
5122 tCsrScanResultInfo *pRet = NULL;
5123 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5124
5125 if(pResultList)
5126 {
5127 csrLLLock(&pResultList->List);
5128 if(NULL == pResultList->pCurEntry)
5129 {
5130 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5131 }
5132 else
5133 {
5134 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
5135 }
5136 if(pEntry)
5137 {
5138 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
5139 pRet = &pResult->Result;
5140 }
5141 pResultList->pCurEntry = pEntry;
5142 csrLLUnlock(&pResultList->List);
5143 }
5144
5145 return pRet;
5146}
5147
5148
5149//This function moves the first BSS that matches the bssid to the head of the result
5150eHalStatus csrMoveBssToHeadFromBSSID(tpAniSirGlobal pMac, tCsrBssid *bssid, tScanResultHandle hScanResult)
5151{
5152 eHalStatus status = eHAL_STATUS_FAILURE;
5153 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5154 tCsrScanResult *pResult = NULL;
5155 tListElem *pEntry = NULL;
5156
5157 if(pResultList && bssid)
5158 {
5159 csrLLLock(&pResultList->List);
5160 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5161 while(pEntry)
5162 {
5163 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
Kiet Lam64c1b492013-07-12 13:56:44 +05305164 if (vos_mem_compare(bssid, pResult->Result.BssDescriptor.bssId, sizeof(tCsrBssid)))
Jeff Johnson295189b2012-06-20 16:38:30 -07005165 {
5166 status = eHAL_STATUS_SUCCESS;
5167 csrLLRemoveEntry(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
5168 csrLLInsertHead(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
5169 break;
5170 }
5171 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
5172 }
5173 csrLLUnlock(&pResultList->List);
5174 }
5175
5176 return (status);
5177}
5178
5179
5180//Remove the BSS if possible.
5181//Return -- TRUE == the BSS is remove. False == Fail to remove it
5182//This function is called when list lock is held. Be caution what functions it can call.
5183tANI_BOOLEAN csrScanAgeOutBss(tpAniSirGlobal pMac, tCsrScanResult *pResult)
5184{
5185 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
5186 tANI_U32 i;
5187 tCsrRoamSession *pSession;
5188
5189 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5190 {
5191 if( CSR_IS_SESSION_VALID( pMac, i ) )
5192 {
5193 pSession = CSR_GET_SESSION( pMac, i );
5194 //Not to remove the BSS we are connected to.
5195 if(csrIsConnStateDisconnected(pMac, i) || (NULL == pSession->pConnectBssDesc) ||
5196 (!csrIsDuplicateBssDescription(pMac, &pResult->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07005197 pSession->pConnectBssDesc, NULL, FALSE))
Jeff Johnson295189b2012-06-20 16:38:30 -07005198 )
5199 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005200 smsLog(pMac, LOGW, "Aging out BSS %02X-%02X-%02X-%02X-%02X-%02X Channel %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005201 pResult->Result.BssDescriptor.bssId[0],
5202 pResult->Result.BssDescriptor.bssId[1],
5203 pResult->Result.BssDescriptor.bssId[2],
5204 pResult->Result.BssDescriptor.bssId[3],
5205 pResult->Result.BssDescriptor.bssId[4],
5206 pResult->Result.BssDescriptor.bssId[5],
5207 pResult->Result.BssDescriptor.channelId);
5208 //No need to hold the spin lock because caller should hold the lock for pMac->scan.scanResultList
5209 if( csrLLRemoveEntry(&pMac->scan.scanResultList, &pResult->Link, LL_ACCESS_NOLOCK) )
5210 {
5211 csrFreeScanResultEntry(pMac, pResult);
Madan Mohan Koyyalamudi2e068bc2012-10-22 14:58:47 -07005212 fRet = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005213 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005214 break;
5215 }
5216 } //valid session
5217 } //for
Madan Mohan Koyyalamudi2e068bc2012-10-22 14:58:47 -07005218 if( CSR_ROAM_SESSION_MAX == i && fRet != eANI_BOOLEAN_TRUE )
Jeff Johnson295189b2012-06-20 16:38:30 -07005219 {
5220 //reset the counter so this won't hapeen too soon
5221 pResult->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
5222 pResult->Result.BssDescriptor.nReceivedTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
5223 }
5224
5225 return (fRet);
5226}
5227
5228
5229eHalStatus csrScanAgeResults(tpAniSirGlobal pMac, tSmeGetScanChnRsp *pScanChnInfo)
5230{
5231 eHalStatus status = eHAL_STATUS_SUCCESS;
5232 tListElem *pEntry, *tmpEntry;
5233 tCsrScanResult *pResult;
5234 tLimScanChn *pChnInfo;
5235 tANI_U8 i;
5236
5237 csrLLLock(&pMac->scan.scanResultList);
5238 for(i = 0; i < pScanChnInfo->numChn; i++)
5239 {
5240 pChnInfo = &pScanChnInfo->scanChn[i];
5241 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
5242 while( pEntry )
5243 {
5244 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
5245 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
5246 if(pResult->Result.BssDescriptor.channelId == pChnInfo->channelId)
5247 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005248 if(pResult->AgingCount <= 0)
5249 {
5250 smsLog(pMac, LOGW, " age out due to ref count");
5251 csrScanAgeOutBss(pMac, pResult);
5252 }
Madan Mohan Koyyalamudib9d3dcc2012-09-28 16:47:50 -07005253 else
5254 {
5255 pResult->AgingCount--;
5256 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005257 }
5258 pEntry = tmpEntry;
5259 }
5260 }
5261 csrLLUnlock(&pMac->scan.scanResultList);
5262
5263 return (status);
5264}
5265
5266
5267eHalStatus csrSendMBScanReq( tpAniSirGlobal pMac, tANI_U16 sessionId,
5268 tCsrScanRequest *pScanReq, tScanReqParam *pScanReqParam )
5269{
5270 eHalStatus status = eHAL_STATUS_SUCCESS;
5271 tSirSmeScanReq *pMsg;
5272 tANI_U16 msgLen;
5273 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
5274 tSirScanType scanType = pScanReq->scanType;
5275 tANI_U32 minChnTime; //in units of milliseconds
5276 tANI_U32 maxChnTime; //in units of milliseconds
5277 tANI_U32 i;
5278 tANI_U8 selfMacAddr[WNI_CFG_BSSID_LEN];
5279 tANI_U8 *pSelfMac = NULL;
5280
5281 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
5282 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) +
5283 ( pScanReq->uIEFieldLen ) ;
5284
Kiet Lam64c1b492013-07-12 13:56:44 +05305285 pMsg = vos_mem_malloc(msgLen);
5286 if ( NULL == pMsg )
5287 status = eHAL_STATUS_FAILURE;
5288 else
5289 status = eHAL_STATUS_SUCCESS;
5290 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07005291 {
5292 do
5293 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305294 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005295 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
5296 pMsg->length = pal_cpu_to_be16(msgLen);
5297 //ToDO: Fill in session info when we need to do scan base on session.
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05305298 if ((pMac->fScanOffload) && (sessionId != CSR_SESSION_ID_INVALID))
5299 {
5300 pMsg->sessionId = sessionId;
5301 }
5302 else
5303 {
5304 /* if sessionId == CSR_SESSION_ID_INVALID, then send the scan
5305 request on first available session */
5306 pMsg->sessionId = 0;
5307 }
5308
Jeff Johnson295189b2012-06-20 16:38:30 -07005309 pMsg->transactionId = 0;
5310 pMsg->dot11mode = (tANI_U8) csrTranslateToWNICfgDot11Mode(pMac, csrFindBestPhyMode( pMac, pMac->roam.configParam.phyMode ));
5311 pMsg->bssType = pal_cpu_to_be32(csrTranslateBsstypeToMacType(pScanReq->BSSType));
5312
5313 if ( CSR_IS_SESSION_VALID( pMac, sessionId ) )
5314 {
5315 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[sessionId].selfMacAddr;
5316 }
5317 else
5318 {
5319 // Since we don't have session for the scanning, we find a valid session. In case we fail to
5320 // do so, get the WNI_CFG_STA_ID
5321 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5322 {
5323 if( CSR_IS_SESSION_VALID( pMac, i ) )
5324 {
5325 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[i].selfMacAddr;
5326 break;
5327 }
5328 }
5329 if( CSR_ROAM_SESSION_MAX == i )
5330 {
5331 tANI_U32 len = WNI_CFG_BSSID_LEN;
5332 pSelfMac = selfMacAddr;
5333 status = ccmCfgGetStr( pMac, WNI_CFG_STA_ID, pSelfMac, &len );
5334 if( !HAL_STATUS_SUCCESS( status ) ||
5335 ( len < WNI_CFG_BSSID_LEN ) )
5336 {
5337 smsLog( pMac, LOGE, FL(" Can not get self MAC address from CFG status = %d"), status );
5338 //Force failed status
5339 status = eHAL_STATUS_FAILURE;
5340 break;
5341 }
5342 }
5343 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305344 vos_mem_copy((tANI_U8 *)pMsg->selfMacAddr, pSelfMac, sizeof(tSirMacAddr));
Jeff Johnson295189b2012-06-20 16:38:30 -07005345
5346 //sirCopyMacAddr
Kiet Lam64c1b492013-07-12 13:56:44 +05305347 vos_mem_copy((tANI_U8 *)pMsg->bssId, (tANI_U8 *)&pScanReq->bssid, sizeof(tSirMacAddr));
5348 if ( vos_mem_compare(pScanReq->bssid, bssid, sizeof(tCsrBssid)))
Jeff Johnson295189b2012-06-20 16:38:30 -07005349 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305350 vos_mem_set(pMsg->bssId, sizeof(tSirMacAddr), 0xff);
Jeff Johnson295189b2012-06-20 16:38:30 -07005351 }
5352 else
5353 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305354 vos_mem_copy(pMsg->bssId, pScanReq->bssid, WNI_CFG_BSSID_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07005355 }
5356 minChnTime = pScanReq->minChnTime;
5357 maxChnTime = pScanReq->maxChnTime;
5358
5359 //Verify the scan type first, if the scan is active scan, we need to make sure we
5360 //are allowed to do so.
5361 /* if 11d is enabled & we don't see any beacon around, scan type falls
5362 back to passive. But in BT AMP STA mode we need to send out a
5363 directed probe*/
5364 if( (eSIR_PASSIVE_SCAN != scanType) && (eCSR_SCAN_P2P_DISCOVERY != pScanReq->requestType)
5365 && (eCSR_BSS_TYPE_WDS_STA != pScanReq->BSSType)
5366 && (eANI_BOOLEAN_FALSE == pMac->scan.fEnableBypass11d))
5367 {
5368 scanType = pMac->scan.curScanType;
5369 if(eSIR_PASSIVE_SCAN == pMac->scan.curScanType)
5370 {
5371 if(minChnTime < pMac->roam.configParam.nPassiveMinChnTime)
5372 {
5373 minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
5374 }
5375 if(maxChnTime < pMac->roam.configParam.nPassiveMaxChnTime)
5376 {
5377 maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
5378 }
5379 }
5380 }
5381 pMsg->scanType = pal_cpu_to_be32(scanType);
5382
5383 pMsg->numSsid = (pScanReq->SSIDs.numOfSSIDs < SIR_SCAN_MAX_NUM_SSID) ? pScanReq->SSIDs.numOfSSIDs :
5384 SIR_SCAN_MAX_NUM_SSID;
5385 if((pScanReq->SSIDs.numOfSSIDs != 0) && ( eSIR_PASSIVE_SCAN != scanType ))
5386 {
Jeff Johnson40b59aa2013-03-19 14:43:18 -07005387 for (i = 0; i < pMsg->numSsid; i++)
5388 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305389 vos_mem_copy(&pMsg->ssId[i],
5390 &pScanReq->SSIDs.SSIDList[i].SSID, sizeof(tSirMacSSid));
Jeff Johnson40b59aa2013-03-19 14:43:18 -07005391 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005392 }
5393 else
5394 {
5395 //Otherwise we scan all SSID and let the result filter later
Jeff Johnson40b59aa2013-03-19 14:43:18 -07005396 for (i = 0; i < SIR_SCAN_MAX_NUM_SSID; i++)
5397 {
5398 pMsg->ssId[i].length = 0;
5399 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005400 }
5401
Jeff Johnson295189b2012-06-20 16:38:30 -07005402 pMsg->minChannelTime = pal_cpu_to_be32(minChnTime);
5403 pMsg->maxChannelTime = pal_cpu_to_be32(maxChnTime);
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08005404 pMsg->minChannelTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
5405 pMsg->maxChannelTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07005406 //hidden SSID option
5407 pMsg->hiddenSsid = pScanReqParam->hiddenSsid;
5408 //rest time
5409 //pMsg->restTime = pScanReq->restTime;
5410 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
5411 // All the scan results caching will be done by Roaming
5412 // We do not want LIM to do any caching of scan results,
5413 // so delete the LIM cache on all scan requests
5414 pMsg->returnFreshResults = pScanReqParam->freshScan;
5415 //Always ask for unique result
5416 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
5417 pMsg->channelList.numChannels = (tANI_U8)pScanReq->ChannelInfo.numOfChannels;
5418 if(pScanReq->ChannelInfo.numOfChannels)
5419 {
5420 //Assuming the channelNumber is tANI_U8 (1 byte)
Kiet Lam64c1b492013-07-12 13:56:44 +05305421 vos_mem_copy(pMsg->channelList.channelNumber,
5422 pScanReq->ChannelInfo.ChannelList,
5423 pScanReq->ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07005424 }
5425
5426 pMsg->uIEFieldLen = (tANI_U16) pScanReq->uIEFieldLen;
5427 pMsg->uIEFieldOffset = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
5428 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) ;
5429 if(pScanReq->uIEFieldLen != 0)
5430 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305431 vos_mem_copy((tANI_U8 *)pMsg+pMsg->uIEFieldOffset, pScanReq->pIEField,
5432 pScanReq->uIEFieldLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07005433 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005434 pMsg->p2pSearch = pScanReq->p2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07005435
Madan Mohan Koyyalamudi9b876782012-10-11 16:22:51 -07005436 if (pScanReq->requestType == eCSR_SCAN_HO_BG_SCAN)
5437 {
5438 pMsg->backgroundScanMode = eSIR_ROAMING_SCAN;
5439 }
5440
Jeff Johnson295189b2012-06-20 16:38:30 -07005441 }while(0);
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005442 smsLog(pMac, LOG1, FL("domainIdCurrent %d scanType %d bssType %d requestType %d numChannels %d "),
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005443 pMac->scan.domainIdCurrent, pMsg->scanType, pMsg->bssType,
5444 pScanReq->requestType, pMsg->channelList.numChannels);
5445
5446 for(i = 0; i < pMsg->channelList.numChannels; i++)
5447 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005448 smsLog(pMac, LOG3, FL("channelNumber[%d]= %d"), i, pMsg->channelList.channelNumber[i]);
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005449 }
5450
Jeff Johnson295189b2012-06-20 16:38:30 -07005451 if(HAL_STATUS_SUCCESS(status))
5452 {
5453 status = palSendMBMessage(pMac->hHdd, pMsg);
5454 }
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005455 else
5456 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005457 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d"), status );
Kiet Lam64c1b492013-07-12 13:56:44 +05305458 vos_mem_free(pMsg);
Jeff Johnson295189b2012-06-20 16:38:30 -07005459 }
5460 }//Success allocated memory
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005461 else
5462 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005463 smsLog( pMac, LOGE, FL(" memory allocation failure"));
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005464 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005465
5466 return( status );
5467}
5468
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005469eHalStatus csrSendMBScanResultReq( tpAniSirGlobal pMac, tANI_U32 sessionId, tScanReqParam *pScanReqParam )
Jeff Johnson295189b2012-06-20 16:38:30 -07005470{
5471 eHalStatus status = eHAL_STATUS_SUCCESS;
5472 tSirSmeScanReq *pMsg;
5473 tANI_U16 msgLen;
5474
5475 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ));
Kiet Lam64c1b492013-07-12 13:56:44 +05305476 pMsg = vos_mem_malloc(msgLen);
5477 if ( NULL == pMsg )
5478 status = eHAL_STATUS_FAILURE;
5479 else
Jeff Johnson295189b2012-06-20 16:38:30 -07005480 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305481 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005482 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
5483 pMsg->length = pal_cpu_to_be16(msgLen);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005484 pMsg->sessionId = sessionId;
5485 pMsg->transactionId = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07005486 pMsg->returnFreshResults = pScanReqParam->freshScan;
5487 //Always ask for unique result
5488 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
5489 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
5490 status = palSendMBMessage(pMac->hHdd, pMsg);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005491 if (!HAL_STATUS_SUCCESS(status))
5492 {
5493 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d\n"), status );
5494 }
5495
Jeff Johnson295189b2012-06-20 16:38:30 -07005496 }
5497
5498 return( status );
5499}
5500
5501
5502
5503eHalStatus csrScanChannels( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5504{
5505 eHalStatus status = eHAL_STATUS_FAILURE;
5506 tScanReqParam scanReq;
5507
5508 do
5509 {
5510 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE | TRUE;
5511 scanReq.fUniqueResult = TRUE;
5512 scanReq.hiddenSsid = SIR_SCAN_NO_HIDDEN_SSID;
5513 if(eCsrScanForSsid == pCommand->u.scanCmd.reason)
5514 {
5515 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_FIRST_MATCH;
5516 }
5517 else
5518 {
5519 // Basically do scan on all channels even for 11D 1st scan case.
5520 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5521 }
5522 if((eCsrScanBgScan == pCommand->u.scanCmd.reason)||
5523 (eCsrScanProbeBss == pCommand->u.scanCmd.reason))
5524 {
5525 scanReq.hiddenSsid = SIR_SCAN_HIDDEN_SSID_PE_DECISION;
5526 }
5527
5528#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5529 {
5530 vos_log_scan_pkt_type *pScanLog = NULL;
5531
5532 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
5533 if(pScanLog)
5534 {
5535 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
5536 eCsrScanProbeBss == pCommand->u.scanCmd.reason)
5537 {
5538 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
5539 }
5540 else
5541 {
5542 if( (eSIR_PASSIVE_SCAN != pCommand->u.scanCmd.u.scanRequest.scanType) &&
5543 (eSIR_PASSIVE_SCAN != pMac->scan.curScanType) )
5544 {
5545 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_REQ;
5546 }
5547 else
5548 {
5549 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_REQ;
5550 }
5551 }
5552 pScanLog->minChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.minChnTime;
5553 pScanLog->maxChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.maxChnTime;
5554 pScanLog->numChannel = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
5555 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
5556 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305557 vos_mem_copy(pScanLog->channels,
5558 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
5559 pScanLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07005560 }
5561 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
5562 }
5563 }
5564#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5565
5566
5567 status = csrSendMBScanReq(pMac, pCommand->sessionId,
5568 &pCommand->u.scanCmd.u.scanRequest, &scanReq);
5569 }while(0);
5570
5571 return( status );
5572}
5573
5574
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005575eHalStatus csrScanRetrieveResult(tpAniSirGlobal pMac, tSmeCmd *pCommand)
Jeff Johnson295189b2012-06-20 16:38:30 -07005576{
5577 eHalStatus status = eHAL_STATUS_FAILURE;
5578 tScanReqParam scanReq;
5579
5580 do
5581 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005582#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5583 if (eCsrScanGetLfrResult == pCommand->u.scanCmd.reason)
5584 {
5585 //to get the LFR candidates from PE cache
5586 scanReq.freshScan = SIR_BG_SCAN_RETURN_LFR_CACHED_RESULTS|SIR_BG_SCAN_PURGE_LFR_RESULTS;
5587 scanReq.fUniqueResult = TRUE;
5588 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5589 }
5590 else
5591#endif
5592 {
5593 //not a fresh scan
5594 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE;
5595 scanReq.fUniqueResult = TRUE;
5596 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5597 }
5598 status = csrSendMBScanResultReq(pMac, pCommand->sessionId, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07005599 }while(0);
5600
5601 return (status);
5602}
5603
5604
5605
5606eHalStatus csrProcessScanCommand( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5607{
5608 eHalStatus status = eHAL_STATUS_SUCCESS;
5609 tCsrChannelInfo newChannelInfo = {0, NULL};
5610 int i, j;
5611 tANI_U8 *pChannel = NULL;
5612 tANI_U32 len = 0;
5613
5614 // Transition to Scanning state...
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305615 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07005616 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305617 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5618 {
5619 pCommand->u.scanCmd.lastRoamState[i] =
5620 csrRoamStateChange( pMac, eCSR_ROAMING_STATE_SCANNING, i);
5621 smsLog( pMac, LOG3, "starting SCAN command from %d state...."
5622 " reason is %d", pCommand->u.scanCmd.lastRoamState[i],
5623 pCommand->u.scanCmd.reason );
5624 }
5625 }
5626 else
5627 {
5628 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId] =
5629 csrRoamStateChange(pMac, eCSR_ROAMING_STATE_SCANNING,
5630 pCommand->sessionId);
5631 smsLog( pMac, LOG3,
5632 "starting SCAN command from %d state.... reason is %d",
5633 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId],
5634 pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07005635 }
5636
5637 switch(pCommand->u.scanCmd.reason)
5638 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005639#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5640 case eCsrScanGetLfrResult:
5641#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005642 case eCsrScanGetResult:
5643 case eCsrScanForCapsChange: //For cap change, LIM already save BSS description
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005644 status = csrScanRetrieveResult(pMac, pCommand);
Jeff Johnson295189b2012-06-20 16:38:30 -07005645 break;
5646 case eCsrScanSetBGScanParam:
5647 status = csrProcessSetBGScanParam(pMac, pCommand);
5648 break;
5649 case eCsrScanBGScanAbort:
5650 status = csrSetCfgBackgroundScanPeriod(pMac, 0);
5651 break;
5652 case eCsrScanBGScanEnable:
5653 status = csrSetCfgBackgroundScanPeriod(pMac, pMac->roam.configParam.bgScanInterval);
5654 break;
5655 case eCsrScanGetScanChnInfo:
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05305656 status = csrScanGetScanChannelInfo(pMac, pCommand->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07005657 break;
5658 case eCsrScanUserRequest:
5659 if(pMac->roam.configParam.fScanTwice)
5660 {
5661 //We scan 2.4 channel twice
5662 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels &&
5663 (NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList))
5664 {
5665 len = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
5666 //allocate twice the channel
5667 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(newChannelInfo.numOfChannels * 2);
5668 pChannel = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
5669 }
5670 else
5671 {
5672 //get the valid channel list to scan all.
5673 len = sizeof(pMac->roam.validChannelList);
5674
5675 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
5676 {
5677 //allocate twice the channel
5678 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(len * 2);
5679 pChannel = pMac->roam.validChannelList;
5680 }
5681 }
5682 if(NULL == newChannelInfo.ChannelList)
5683 {
5684 newChannelInfo.numOfChannels = 0;
5685 }
5686 else
5687 {
5688 j = 0;
5689 for(i = 0; i < len; i++)
5690 {
5691 newChannelInfo.ChannelList[j++] = pChannel[i];
5692 if(CSR_MAX_24GHz_CHANNEL_NUMBER >= pChannel[i])
5693 {
5694 newChannelInfo.ChannelList[j++] = pChannel[i];
5695 }
5696 }
5697 if(NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
5698 {
5699 //pChannel points to the channellist from the command, free it.
5700 vos_mem_free(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -07005701 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07005702 }
5703 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = j;
5704 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = newChannelInfo.ChannelList;
5705 }
5706 } //if(pMac->roam.configParam.fScanTwice)
5707
5708 status = csrScanChannels(pMac, pCommand);
5709
5710 break;
5711 default:
5712 status = csrScanChannels(pMac, pCommand);
5713 break;
5714 }
5715
5716 if(!HAL_STATUS_SUCCESS(status))
5717 {
5718 csrReleaseScanCommand(pMac, pCommand, eCSR_SCAN_FAILURE);
5719 }
5720
5721 return (status);
5722}
5723
5724
5725eHalStatus csrScanSetBGScanparams(tpAniSirGlobal pMac, tCsrBGScanRequest *pScanReq)
5726{
5727 eHalStatus status = eHAL_STATUS_SUCCESS;
5728 tSmeCmd *pCommand = NULL;
5729
5730 if(pScanReq)
5731 {
5732 do
5733 {
5734 pCommand = csrGetCommandBuffer(pMac);
5735 if(!pCommand)
5736 {
5737 status = eHAL_STATUS_RESOURCES;
5738 break;
5739 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305740 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005741 pCommand->command = eSmeCommandScan;
5742 pCommand->u.scanCmd.reason = eCsrScanSetBGScanParam;
5743 pCommand->u.scanCmd.callback = NULL;
5744 pCommand->u.scanCmd.pContext = NULL;
Kiet Lam64c1b492013-07-12 13:56:44 +05305745 vos_mem_copy(&pCommand->u.scanCmd.u.bgScanRequest, pScanReq, sizeof(tCsrBGScanRequest));
Jeff Johnson295189b2012-06-20 16:38:30 -07005746 //we have to do the follow
5747 if(pScanReq->ChannelInfo.numOfChannels == 0)
5748 {
5749 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
5750 }
5751 else
5752 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305753 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList
5754 = vos_mem_malloc(pScanReq->ChannelInfo.numOfChannels);
5755 if ( NULL != pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07005756 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305757 vos_mem_copy(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList,
5758 pScanReq->ChannelInfo.ChannelList,
5759 pScanReq->ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07005760 }
5761 else
5762 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005763 smsLog(pMac, LOGE, FL("ran out of memory"));
Jeff Johnson295189b2012-06-20 16:38:30 -07005764 csrReleaseCommandScan(pMac, pCommand);
Kiet Lam64c1b492013-07-12 13:56:44 +05305765 return eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005766 }
5767 }
5768
5769 //scan req for SSID
5770 if(pScanReq->SSID.length)
5771 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305772 vos_mem_copy(pCommand->u.scanCmd.u.bgScanRequest.SSID.ssId,
5773 pScanReq->SSID.ssId, pScanReq->SSID.length);
Jeff Johnson295189b2012-06-20 16:38:30 -07005774 pCommand->u.scanCmd.u.bgScanRequest.SSID.length = pScanReq->SSID.length;
5775
5776 }
5777 pCommand->u.scanCmd.u.bgScanRequest.maxChnTime= pScanReq->maxChnTime;
5778 pCommand->u.scanCmd.u.bgScanRequest.minChnTime = pScanReq->minChnTime;
5779 pCommand->u.scanCmd.u.bgScanRequest.scanInterval = pScanReq->scanInterval;
5780
5781
5782 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
5783 if( !HAL_STATUS_SUCCESS( status ) )
5784 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005785 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07005786 csrReleaseCommandScan( pMac, pCommand );
5787 break;
5788 }
5789 }while(0);
5790 }
5791
5792 return (status);
5793}
5794
5795eHalStatus csrScanBGScanAbort( tpAniSirGlobal pMac )
5796{
5797 eHalStatus status = eHAL_STATUS_SUCCESS;
5798 tSmeCmd *pCommand = NULL;
5799
5800 do
5801 {
5802 pCommand = csrGetCommandBuffer(pMac);
5803 if(!pCommand)
5804 {
5805 status = eHAL_STATUS_RESOURCES;
5806 break;
5807 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305808 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005809 pCommand->command = eSmeCommandScan;
5810 pCommand->u.scanCmd.reason = eCsrScanBGScanAbort;
5811 pCommand->u.scanCmd.callback = NULL;
5812 pCommand->u.scanCmd.pContext = NULL;
5813 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
5814 if( !HAL_STATUS_SUCCESS( status ) )
5815 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005816 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07005817 csrReleaseCommandScan( pMac, pCommand );
5818 break;
5819 }
5820 }while(0);
5821
5822 return (status);
5823}
5824
5825
5826//This will enable the background scan with the non-zero interval
5827eHalStatus csrScanBGScanEnable(tpAniSirGlobal pMac)
5828{
5829 eHalStatus status = eHAL_STATUS_SUCCESS;
5830 tSmeCmd *pCommand = NULL;
5831
5832 if(pMac->roam.configParam.bgScanInterval)
5833 {
5834 do
5835 {
5836 pCommand = csrGetCommandBuffer(pMac);
5837 if(!pCommand)
5838 {
5839 status = eHAL_STATUS_RESOURCES;
5840 break;
5841 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305842 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005843 pCommand->command = eSmeCommandScan;
5844 pCommand->u.scanCmd.reason = eCsrScanBGScanEnable;
5845 pCommand->u.scanCmd.callback = NULL;
5846 pCommand->u.scanCmd.pContext = NULL;
5847 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
5848 if( !HAL_STATUS_SUCCESS( status ) )
5849 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005850 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07005851 csrReleaseCommandScan( pMac, pCommand );
5852 break;
5853 }
5854 }while(0);
5855 //BG scan results are reported automatically by PE to SME once the scan is done.
5856 //No need to fetch the results explicitly.
5857 //csrScanStartGetResultTimer(pMac);
5858 csrScanStartResultAgingTimer(pMac);
5859 }
5860 else
5861 {
5862 //We don't have BG scan so stop the aging timer
5863 csrScanStopResultAgingTimer(pMac);
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005864 smsLog(pMac, LOGE, FL("cannot continue because the bgscan interval is 0"));
Jeff Johnson295189b2012-06-20 16:38:30 -07005865 status = eHAL_STATUS_INVALID_PARAMETER;
5866 }
5867
5868 return (status);
5869}
5870
5871
5872eHalStatus csrScanCopyRequest(tpAniSirGlobal pMac, tCsrScanRequest *pDstReq, tCsrScanRequest *pSrcReq)
5873{
5874 eHalStatus status = eHAL_STATUS_SUCCESS;
5875 tANI_U32 len = sizeof(pMac->roam.validChannelList);
5876 tANI_U32 index = 0;
5877 tANI_U32 new_index = 0;
5878
5879 do
5880 {
5881 status = csrScanFreeRequest(pMac, pDstReq);
5882 if(HAL_STATUS_SUCCESS(status))
5883 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305884 vos_mem_copy(pDstReq, pSrcReq, sizeof(tCsrScanRequest));
Gopichand Nakkalac7b1d3e2012-12-31 14:07:19 -08005885 /* Re-initialize the pointers to NULL since we did a copy */
5886 pDstReq->pIEField = NULL;
5887 pDstReq->ChannelInfo.ChannelList = NULL;
5888 pDstReq->SSIDs.SSIDList = NULL;
5889
Jeff Johnson295189b2012-06-20 16:38:30 -07005890 if(pSrcReq->uIEFieldLen == 0)
5891 {
5892 pDstReq->pIEField = NULL;
5893 }
5894 else
5895 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305896 pDstReq->pIEField = vos_mem_malloc(pSrcReq->uIEFieldLen);
5897 if ( NULL == pDstReq->pIEField )
5898 status = eHAL_STATUS_FAILURE;
5899 else
5900 status = eHAL_STATUS_SUCCESS;
5901 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07005902 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305903 vos_mem_copy(pDstReq->pIEField, pSrcReq->pIEField, pSrcReq->uIEFieldLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07005904 pDstReq->uIEFieldLen = pSrcReq->uIEFieldLen;
5905 }
5906 else
5907 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005908 smsLog(pMac, LOGE, "No memory for scanning IE fields");
Jeff Johnson295189b2012-06-20 16:38:30 -07005909 break;
5910 }
5911 }//Allocate memory for IE field
5912 {
5913 if(pSrcReq->ChannelInfo.numOfChannels == 0)
5914 {
5915 pDstReq->ChannelInfo.ChannelList = NULL;
5916 pDstReq->ChannelInfo.numOfChannels = 0;
5917 }
5918 else
5919 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305920 pDstReq->ChannelInfo.ChannelList = vos_mem_malloc(
5921 pSrcReq->ChannelInfo.numOfChannels
5922 * sizeof(*pDstReq->ChannelInfo.ChannelList));
5923 if ( NULL == pDstReq->ChannelInfo.ChannelList )
5924 status = eHAL_STATUS_FAILURE;
5925 else
5926 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07005927 if(!HAL_STATUS_SUCCESS(status))
5928 {
5929 pDstReq->ChannelInfo.numOfChannels = 0;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005930 smsLog(pMac, LOGE, "No memory for scanning Channel List");
Jeff Johnson295189b2012-06-20 16:38:30 -07005931 break;
5932 }
5933
5934 if((pSrcReq->scanType == eSIR_PASSIVE_SCAN) && (pSrcReq->requestType == eCSR_SCAN_REQUEST_11D_SCAN))
5935 {
5936 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
5937 {
5938 pDstReq->ChannelInfo.ChannelList[new_index] =
5939 pSrcReq->ChannelInfo.ChannelList[index];
5940 new_index++;
5941 }
5942 pDstReq->ChannelInfo.numOfChannels = new_index;
5943 }
5944 else if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
5945 {
5946 new_index = 0;
5947 pMac->roam.numValidChannels = len;
5948 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
5949 {
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -07005950 /* Allow scan on valid channels only.
5951 * If it is p2p scan and valid channel list doesnt contain
5952 * social channels, enforce scan on social channels because
5953 * that is the only way to find p2p peers.
5954 * This can happen only if band is set to 5Ghz mode.
5955 */
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08005956 if((csrRoamIsValidChannel(pMac, pSrcReq->ChannelInfo.ChannelList[index])) ||
5957 ((eCSR_SCAN_P2P_DISCOVERY == pSrcReq->requestType) &&
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -07005958 CSR_IS_SOCIAL_CHANNEL(pSrcReq->ChannelInfo.ChannelList[index])))
Jeff Johnson295189b2012-06-20 16:38:30 -07005959 {
Srikant Kuppa866893f2012-12-27 17:28:14 -08005960 if( (pSrcReq->skipDfsChnlInP2pSearch &&
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08005961 (NV_CHANNEL_DFS == vos_nv_getChannelEnabledState(pSrcReq->ChannelInfo.ChannelList[index])) )
Srikant Kuppa866893f2012-12-27 17:28:14 -08005962#ifdef FEATURE_WLAN_LFR
5963 /*
5964 * If LFR is requesting a contiguous scan
5965 * (i.e. numOfChannels > 1), then ignore
5966 * DFS channels.
5967 * TODO: vos_nv_getChannelEnabledState is returning
5968 * 120, 124 and 128 as non-DFS channels. Hence, the
5969 * use of direct check for channels below.
5970 */
5971 || ((eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType) &&
5972 (pSrcReq->ChannelInfo.numOfChannels > 1) &&
Srinivas Girigowdade697412013-02-14 16:31:48 -08005973 (CSR_IS_CHANNEL_DFS(pSrcReq->ChannelInfo.ChannelList[index])))
Srikant Kuppa866893f2012-12-27 17:28:14 -08005974#endif
5975 )
5976 {
5977#ifdef FEATURE_WLAN_LFR
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005978 smsLog(pMac, LOG2,
Srikant Kuppa866893f2012-12-27 17:28:14 -08005979 "%s: reqType=%d, numOfChannels=%d,"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005980 " ignoring DFS channel %d",
Srikant Kuppa866893f2012-12-27 17:28:14 -08005981 __func__, pSrcReq->requestType,
5982 pSrcReq->ChannelInfo.numOfChannels,
5983 pSrcReq->ChannelInfo.ChannelList[index]);
5984#endif
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08005985 continue;
Srikant Kuppa866893f2012-12-27 17:28:14 -08005986 }
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08005987
Jeff Johnson295189b2012-06-20 16:38:30 -07005988 pDstReq->ChannelInfo.ChannelList[new_index] =
5989 pSrcReq->ChannelInfo.ChannelList[index];
5990 new_index++;
5991 }
5992 }
5993 pDstReq->ChannelInfo.numOfChannels = new_index;
Srikant Kuppa866893f2012-12-27 17:28:14 -08005994#ifdef FEATURE_WLAN_LFR
5995 if ((eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType) &&
5996 (0 == pDstReq->ChannelInfo.numOfChannels))
5997 {
5998 /*
5999 * No valid channels found in the request.
6000 * Only perform scan on the channels passed
6001 * pSrcReq if it is a eCSR_SCAN_HO_BG_SCAN.
6002 * Passing 0 to LIM will trigger a scan on
6003 * all valid channels which is not desirable.
6004 */
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006005 smsLog(pMac, LOGE, "%s: no valid channels found (request=%d)",
Srikant Kuppa866893f2012-12-27 17:28:14 -08006006 __func__, pSrcReq->requestType);
6007 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
6008 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006009 smsLog(pMac, LOGE, "pSrcReq index=%d channel=%d",
Srikant Kuppa866893f2012-12-27 17:28:14 -08006010 index, pSrcReq->ChannelInfo.ChannelList[index]);
6011 }
6012 status = eHAL_STATUS_FAILURE;
6013 break;
6014 }
6015#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006016 }
6017 else
6018 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006019 smsLog(pMac, LOGE, "Couldn't get the valid Channel List, keeping requester's list");
Kiet Lam64c1b492013-07-12 13:56:44 +05306020 vos_mem_copy(pDstReq->ChannelInfo.ChannelList,
6021 pSrcReq->ChannelInfo.ChannelList,
6022 pSrcReq->ChannelInfo.numOfChannels
6023 * sizeof(*pDstReq->ChannelInfo.ChannelList));
Jeff Johnson295189b2012-06-20 16:38:30 -07006024 pDstReq->ChannelInfo.numOfChannels = pSrcReq->ChannelInfo.numOfChannels;
6025 }
6026 }//Allocate memory for Channel List
6027 }
6028 if(pSrcReq->SSIDs.numOfSSIDs == 0)
6029 {
6030 pDstReq->SSIDs.numOfSSIDs = 0;
6031 pDstReq->SSIDs.SSIDList = NULL;
6032 }
6033 else
6034 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306035 pDstReq->SSIDs.SSIDList = vos_mem_malloc(
6036 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
6037 if ( NULL == pDstReq->SSIDs.SSIDList )
6038 status = eHAL_STATUS_FAILURE;
6039 else
6040 status = eHAL_STATUS_SUCCESS;
6041 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07006042 {
6043 pDstReq->SSIDs.numOfSSIDs = pSrcReq->SSIDs.numOfSSIDs;
Kiet Lam64c1b492013-07-12 13:56:44 +05306044 vos_mem_copy(pDstReq->SSIDs.SSIDList,
6045 pSrcReq->SSIDs.SSIDList,
6046 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
Jeff Johnson295189b2012-06-20 16:38:30 -07006047 }
6048 else
6049 {
6050 pDstReq->SSIDs.numOfSSIDs = 0;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006051 smsLog(pMac, LOGE, "No memory for scanning SSID List");
Jeff Johnson295189b2012-06-20 16:38:30 -07006052 break;
6053 }
6054 }//Allocate memory for SSID List
Jeff Johnson295189b2012-06-20 16:38:30 -07006055 pDstReq->p2pSearch = pSrcReq->p2pSearch;
Jeff Johnsone7245742012-09-05 17:12:55 -07006056 pDstReq->skipDfsChnlInP2pSearch = pSrcReq->skipDfsChnlInP2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07006057
6058 }
6059 }while(0);
6060
6061 if(!HAL_STATUS_SUCCESS(status))
6062 {
6063 csrScanFreeRequest(pMac, pDstReq);
6064 }
6065
6066 return (status);
6067}
6068
6069
6070eHalStatus csrScanFreeRequest(tpAniSirGlobal pMac, tCsrScanRequest *pReq)
6071{
Jeff Johnson295189b2012-06-20 16:38:30 -07006072
6073 if(pReq->ChannelInfo.ChannelList)
6074 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306075 vos_mem_free(pReq->ChannelInfo.ChannelList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006076 pReq->ChannelInfo.ChannelList = NULL;
6077 }
6078 pReq->ChannelInfo.numOfChannels = 0;
6079 if(pReq->pIEField)
6080 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306081 vos_mem_free(pReq->pIEField);
Jeff Johnson295189b2012-06-20 16:38:30 -07006082 pReq->pIEField = NULL;
6083 }
6084 pReq->uIEFieldLen = 0;
6085 if(pReq->SSIDs.SSIDList)
6086 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306087 vos_mem_free(pReq->SSIDs.SSIDList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006088 pReq->SSIDs.SSIDList = NULL;
6089 }
6090 pReq->SSIDs.numOfSSIDs = 0;
6091
Kiet Lam64c1b492013-07-12 13:56:44 +05306092 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07006093}
6094
6095
6096void csrScanCallCallback(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
6097{
6098 if(pCommand->u.scanCmd.callback)
6099 {
6100// sme_ReleaseGlobalLock( &pMac->sme );
6101 pCommand->u.scanCmd.callback(pMac, pCommand->u.scanCmd.pContext, pCommand->u.scanCmd.scanID, scanStatus);
6102// sme_AcquireGlobalLock( &pMac->sme );
6103 } else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006104 smsLog( pMac, LOG2, "%s:%d - Callback NULL!!!", __func__, __LINE__);
Jeff Johnson295189b2012-06-20 16:38:30 -07006105 }
6106}
6107
6108
6109void csrScanStopTimers(tpAniSirGlobal pMac)
6110{
6111 csrScanStopResultAgingTimer(pMac);
6112 csrScanStopIdleScanTimer(pMac);
6113 csrScanStopGetResultTimer(pMac);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006114 if(0 != pMac->scan.scanResultCfgAgingTime )
6115 {
6116 csrScanStopResultCfgAgingTimer(pMac);
6117 }
6118
Jeff Johnson295189b2012-06-20 16:38:30 -07006119}
6120
6121
6122eHalStatus csrScanStartGetResultTimer(tpAniSirGlobal pMac)
6123{
6124 eHalStatus status;
6125
6126 if(pMac->scan.fScanEnable)
6127 {
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306128 status = vos_timer_start(&pMac->scan.hTimerGetResult, CSR_SCAN_GET_RESULT_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006129 }
6130 else
6131 {
6132 status = eHAL_STATUS_FAILURE;
6133 }
6134
6135 return (status);
6136}
6137
6138
6139eHalStatus csrScanStopGetResultTimer(tpAniSirGlobal pMac)
6140{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306141 return (vos_timer_stop(&pMac->scan.hTimerGetResult));
Jeff Johnson295189b2012-06-20 16:38:30 -07006142}
6143
6144
6145void csrScanGetResultTimerHandler(void *pv)
6146{
6147 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6148
6149 csrScanRequestResult(pMac);
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306150
6151 vos_timer_start(&pMac->scan.hTimerGetResult, CSR_SCAN_GET_RESULT_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006152}
6153
6154#ifdef WLAN_AP_STA_CONCURRENCY
6155static void csrStaApConcTimerHandler(void *pv)
6156{
6157 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6158 tListElem *pEntry;
6159 tSmeCmd *pScanCmd;
6160
6161 csrLLLock(&pMac->scan.scanCmdPendingList);
6162
6163 if ( NULL != ( pEntry = csrLLPeekHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) ) )
6164 {
6165 tCsrScanRequest scanReq;
6166 tSmeCmd *pSendScanCmd = NULL;
6167 tANI_U8 numChn = 0;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006168 tANI_U8 nNumChanCombinedConc = 0;
Vinay Malekal05fdc812012-12-17 13:04:30 -08006169 tANI_U8 i, j;
Jeff Johnson295189b2012-06-20 16:38:30 -07006170 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
6171 tANI_U8 channelToScan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
6172 eHalStatus status;
6173
Jeff Johnson295189b2012-06-20 16:38:30 -07006174 pScanCmd = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
6175 numChn = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08006176
6177 /* if any session is connected and the number of channels to scan is
6178 * greater than 1 then split the scan into multiple scan operations
6179 * on each individual channel else continue to perform scan on all
6180 * specified channels */
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08006181
6182 /* split scan if number of channels to scan is greater than 1 and
6183 * any one of the following:
6184 * - STA session is connected and the scan is not a P2P search
6185 * - any P2P session is connected
Srikant Kuppa866893f2012-12-27 17:28:14 -08006186 * Do not split scans if no concurrent infra connections are
6187 * active and if the scan is a BG scan triggered by LFR (OR)
6188 * any scan if LFR is in the middle of a BG scan. Splitting
6189 * the scan is delaying the time it takes for LFR to find
6190 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08006191 */
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006192
6193 if((csrIsStaSessionConnected(pMac) &&
6194 !csrIsP2pSessionConnected(pMac)))
6195 {
6196 nNumChanCombinedConc = pMac->roam.configParam.nNumStaChanCombinedConc;
6197 }
6198 else if(csrIsP2pSessionConnected(pMac))
6199 {
6200 nNumChanCombinedConc = pMac->roam.configParam.nNumP2PChanCombinedConc;
6201 }
6202
6203 if ( (numChn > nNumChanCombinedConc) &&
Srikant Kuppa866893f2012-12-27 17:28:14 -08006204 ((csrIsStaSessionConnected(pMac) &&
6205#ifdef FEATURE_WLAN_LFR
6206 (csrIsConcurrentInfraConnected(pMac) ||
6207 ((pScanCmd->u.scanCmd.reason != eCsrScanBgScan) &&
6208 (pMac->roam.neighborRoamInfo.neighborRoamState !=
6209 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
6210#endif
6211 (pScanCmd->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08006212 (csrIsP2pSessionConnected(pMac))))
Jeff Johnson295189b2012-06-20 16:38:30 -07006213 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306214 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006215
6216 pSendScanCmd = csrGetCommandBuffer(pMac); //optimize this to use 2 command buffer only
6217 if (!pSendScanCmd)
6218 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006219 smsLog( pMac, LOGE, FL(" Failed to get Queue command buffer") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006220 csrLLUnlock(&pMac->scan.scanCmdPendingList);
6221 return;
6222 }
6223 pSendScanCmd->command = pScanCmd->command;
6224 pSendScanCmd->sessionId = pScanCmd->sessionId;
6225 pSendScanCmd->u.scanCmd.callback = NULL;
6226 pSendScanCmd->u.scanCmd.pContext = pScanCmd->u.scanCmd.pContext;
6227 pSendScanCmd->u.scanCmd.reason = pScanCmd->u.scanCmd.reason;
6228 pSendScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
6229
Madan Mohan Koyyalamudiaf2a8b92012-10-09 14:58:07 -07006230 /* First copy all the parameters to local variable of scan request */
6231 csrScanCopyRequest(pMac, &scanReq, &pScanCmd->u.scanCmd.u.scanRequest);
6232
6233 /* Now modify the elements of local var scan request required to be modified for split scan */
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08006234 if(scanReq.ChannelInfo.ChannelList != NULL)
6235 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306236 vos_mem_free(scanReq.ChannelInfo.ChannelList);
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08006237 scanReq.ChannelInfo.ChannelList = NULL;
6238 }
6239
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006240 pChnInfo->numOfChannels = nNumChanCombinedConc;
Kiet Lam64c1b492013-07-12 13:56:44 +05306241 vos_mem_copy(&channelToScan[0],
6242 &pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[0],
6243 pChnInfo->numOfChannels * sizeof(tANI_U8));//just send one channel
Jeff Johnson295189b2012-06-20 16:38:30 -07006244 pChnInfo->ChannelList = &channelToScan[0];
6245
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006246 for (i = 0, j = nNumChanCombinedConc; i < (numChn-nNumChanCombinedConc); i++, j++)
Jeff Johnson295189b2012-06-20 16:38:30 -07006247 {
6248 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] =
Vinay Malekal05fdc812012-12-17 13:04:30 -08006249 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[j]; //Move all the channels one step
Jeff Johnson295189b2012-06-20 16:38:30 -07006250 }
6251
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006252 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = numChn - nNumChanCombinedConc; //reduce outstanding # of channels to be scanned
Jeff Johnson295189b2012-06-20 16:38:30 -07006253
6254 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
6255 //Modify callers parameters in case of concurrency
6256 scanReq.scanType = eSIR_ACTIVE_SCAN;
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -07006257 //Use concurrency values for min/maxChnTime.
6258 //We know csrIsAnySessionConnected(pMac) returns TRUE here
6259 csrSetDefaultScanTiming(pMac, scanReq.scanType, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07006260
6261 status = csrScanCopyRequest(pMac, &pSendScanCmd->u.scanCmd.u.scanRequest, &scanReq);
6262 if(!HAL_STATUS_SUCCESS(status))
6263 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006264 smsLog( pMac, LOGE, FL(" Failed to get copy csrScanRequest = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006265 csrLLUnlock(&pMac->scan.scanCmdPendingList);
6266 return;
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08006267 }
6268 /* Clean the local scan variable */
6269 scanReq.ChannelInfo.ChannelList = NULL;
6270 scanReq.ChannelInfo.numOfChannels = 0;
6271 csrScanFreeRequest(pMac, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07006272 }
6273 else
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08006274 {
6275 /* no active connected session present or numChn == 1
6276 * scan all remaining channels */
Jeff Johnson295189b2012-06-20 16:38:30 -07006277 pSendScanCmd = pScanCmd;
6278 //remove this command from pending list
6279 if (csrLLRemoveHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) == NULL)
6280 { //In case between PeekHead and here, the entry got removed by another thread.
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006281 smsLog( pMac, LOGE, FL(" Failed to remove entry from scanCmdPendingList"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006282 }
6283
6284 }
6285 csrQueueSmeCommand(pMac, pSendScanCmd, eANI_BOOLEAN_FALSE);
6286
6287 }
6288
Jeff Johnson295189b2012-06-20 16:38:30 -07006289 csrLLUnlock(&pMac->scan.scanCmdPendingList);
6290
6291}
6292#endif
6293
6294eHalStatus csrScanStartResultAgingTimer(tpAniSirGlobal pMac)
6295{
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006296 eHalStatus status = eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006297
6298 if(pMac->scan.fScanEnable)
6299 {
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306300 status = vos_timer_start(&pMac->scan.hTimerResultAging, CSR_SCAN_RESULT_AGING_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006301 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006302 return (status);
6303}
6304
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006305eHalStatus csrScanStartResultCfgAgingTimer(tpAniSirGlobal pMac)
6306{
6307 eHalStatus status = eHAL_STATUS_FAILURE;
6308
6309 if(pMac->scan.fScanEnable)
6310 {
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306311 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 -08006312 }
6313 return (status);
6314}
Jeff Johnson295189b2012-06-20 16:38:30 -07006315
6316eHalStatus csrScanStopResultAgingTimer(tpAniSirGlobal pMac)
6317{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306318 return (vos_timer_stop(&pMac->scan.hTimerResultAging));
Jeff Johnson295189b2012-06-20 16:38:30 -07006319}
6320
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006321eHalStatus csrScanStopResultCfgAgingTimer(tpAniSirGlobal pMac)
6322{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306323 return (vos_timer_stop(&pMac->scan.hTimerResultCfgAging));
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006324}
Jeff Johnson295189b2012-06-20 16:38:30 -07006325
6326//This function returns the maximum time a BSS is allowed in the scan result.
6327//The time varies base on connection and power saving factors.
6328//Not connected, No PS
6329//Not connected, with PS
6330//Connected w/o traffic, No PS
6331//Connected w/o traffic, with PS
6332//Connected w/ traffic, no PS -- Not supported
6333//Connected w/ traffic, with PS -- Not supported
6334//the return unit is in seconds.
6335tANI_U32 csrScanGetAgeOutTime(tpAniSirGlobal pMac)
6336{
6337 tANI_U32 nRet;
6338
6339 if(pMac->scan.nAgingCountDown)
6340 {
6341 //Calculate what should be the timeout value for this
6342 nRet = pMac->scan.nLastAgeTimeOut * pMac->scan.nAgingCountDown;
6343 pMac->scan.nAgingCountDown--;
6344 }
6345 else
6346 {
6347 if( csrIsAllSessionDisconnected( pMac ) )
6348 {
6349 if(pmcIsPowerSaveEnabled(pMac, ePMC_IDLE_MODE_POWER_SAVE))
6350 {
6351 nRet = pMac->roam.configParam.scanAgeTimeNCPS;
6352 }
6353 else
6354 {
6355 nRet = pMac->roam.configParam.scanAgeTimeNCNPS;
6356 }
6357 }
6358 else
6359 {
6360 if(pmcIsPowerSaveEnabled(pMac, ePMC_BEACON_MODE_POWER_SAVE))
6361 {
6362 nRet = pMac->roam.configParam.scanAgeTimeCPS;
6363 }
6364 else
6365 {
6366 nRet = pMac->roam.configParam.scanAgeTimeCNPS;
6367 }
6368 }
6369 //If state-change causing aging time out change, we want to delay it somewhat to avoid
6370 //unnecessary removal of BSS. This is mostly due to transition from connect to disconnect.
6371 if(pMac->scan.nLastAgeTimeOut > nRet)
6372 {
6373 if(nRet)
6374 {
6375 pMac->scan.nAgingCountDown = (pMac->scan.nLastAgeTimeOut / nRet);
6376 }
6377 pMac->scan.nLastAgeTimeOut = nRet;
6378 nRet *= pMac->scan.nAgingCountDown;
6379 }
6380 else
6381 {
6382 pMac->scan.nLastAgeTimeOut = nRet;
6383 }
6384 }
6385
6386 return (nRet);
6387}
6388
6389
6390void csrScanResultAgingTimerHandler(void *pv)
6391{
6392 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6393 tANI_BOOLEAN fDisconnected = csrIsAllSessionDisconnected(pMac);
6394
6395 //no scan, no aging
6396 if(pMac->scan.fScanEnable &&
6397 (((eANI_BOOLEAN_FALSE == fDisconnected) && pMac->roam.configParam.bgScanInterval)
6398 || (fDisconnected && (pMac->scan.fCancelIdleScan == eANI_BOOLEAN_FALSE)))
6399 )
6400 {
6401 tListElem *pEntry, *tmpEntry;
6402 tCsrScanResult *pResult;
6403 tANI_TIMESTAMP ageOutTime = (tANI_TIMESTAMP)(csrScanGetAgeOutTime(pMac) * PAL_TICKS_PER_SECOND); //turn it into 10ms units
6404 tANI_TIMESTAMP curTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
6405
6406 csrLLLock(&pMac->scan.scanResultList);
6407 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
6408 while( pEntry )
6409 {
6410 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
6411 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
6412 if((curTime - pResult->Result.BssDescriptor.nReceivedTime) > ageOutTime)
6413 {
6414 smsLog(pMac, LOGW, " age out due to time out");
6415 csrScanAgeOutBss(pMac, pResult);
6416 }
6417 pEntry = tmpEntry;
6418 }
6419 csrLLUnlock(&pMac->scan.scanResultList);
6420 }
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306421 vos_timer_start(&pMac->scan.hTimerResultAging, CSR_SCAN_RESULT_AGING_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006422}
6423
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006424static void csrScanResultCfgAgingTimerHandler(void *pv)
6425{
6426 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6427 tListElem *pEntry, *tmpEntry;
6428 tCsrScanResult *pResult;
6429 tANI_TIMESTAMP ageOutTime = pMac->scan.scanResultCfgAgingTime * PAL_TICKS_PER_SECOND;
6430 tANI_TIMESTAMP curTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
6431
6432 csrLLLock(&pMac->scan.scanResultList);
6433 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
6434 while( pEntry )
6435 {
6436 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
6437 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
6438 if((curTime - pResult->Result.BssDescriptor.nReceivedTime) > ageOutTime)
6439 {
6440 smsLog(pMac, LOGW, " age out due to time out");
6441 csrScanAgeOutBss(pMac, pResult);
6442 }
6443 pEntry = tmpEntry;
6444 }
6445 csrLLUnlock(&pMac->scan.scanResultList);
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306446 vos_timer_start(&pMac->scan.hTimerResultCfgAging, CSR_SCAN_RESULT_CFG_AGING_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006447}
Jeff Johnson295189b2012-06-20 16:38:30 -07006448
6449eHalStatus csrScanStartIdleScanTimer(tpAniSirGlobal pMac, tANI_U32 interval)
6450{
6451 eHalStatus status;
6452
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006453 smsLog(pMac, LOG1, " csrScanStartIdleScanTimer");
Jeff Johnson295189b2012-06-20 16:38:30 -07006454 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) && interval)
6455 {
6456 pMac->scan.nIdleScanTimeGap += interval;
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306457 vos_timer_stop(&pMac->scan.hTimerIdleScan);
6458 status = vos_timer_start(&pMac->scan.hTimerIdleScan, interval/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006459 if( !HAL_STATUS_SUCCESS(status) )
6460 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006461 smsLog(pMac, LOGE, " Fail to start Idle scan timer. status = %d interval = %d", status, interval);
Jeff Johnson295189b2012-06-20 16:38:30 -07006462 //This should not happen but set the flag to restart when ready
6463 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6464 }
6465 }
6466 else
6467 {
6468 if( pMac->scan.fScanEnable && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) )
6469 {
6470 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6471 }
6472 status = eHAL_STATUS_FAILURE;
6473 }
6474
6475 return (status);
6476}
6477
6478
6479eHalStatus csrScanStopIdleScanTimer(tpAniSirGlobal pMac)
6480{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306481 return (vos_timer_stop(&pMac->scan.hTimerIdleScan));
Jeff Johnson295189b2012-06-20 16:38:30 -07006482}
6483
6484
6485//Stop CSR from asking for IMPS, This function doesn't disable IMPS from CSR
6486void csrScanSuspendIMPS( tpAniSirGlobal pMac )
6487{
6488 csrScanCancelIdleScan(pMac);
6489}
6490
6491
6492//Start CSR from asking for IMPS. This function doesn't trigger CSR to request entering IMPS
6493//because IMPS maybe disabled.
6494void csrScanResumeIMPS( tpAniSirGlobal pMac )
6495{
6496 csrScanStartIdleScan( pMac );
6497}
6498
6499
6500void csrScanIMPSCallback(void *callbackContext, eHalStatus status)
6501{
6502 tpAniSirGlobal pMac = PMAC_STRUCT( callbackContext );
6503
6504 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6505 {
6506 if(pMac->roam.configParam.IsIdleScanEnabled)
6507 {
6508 if(HAL_STATUS_SUCCESS(status))
6509 {
6510 if(csrIsAllSessionDisconnected(pMac) && !csrIsRoamCommandWaiting(pMac))
6511 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006512 smsLog(pMac, LOGW, FL("starts idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006513 csrScanAllChannels(pMac, eCSR_SCAN_IDLE_MODE_SCAN);
6514 }
6515 else
6516 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006517 smsLog(pMac, LOGW, FL("cannot start idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006518 //even though we are in timer handle, calling stop timer will make sure the timer
6519 //doesn't get to restart.
6520 csrScanStopIdleScanTimer(pMac);
6521 }
6522 }
6523 else
6524 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006525 smsLog(pMac, LOGE, FL("sees not success status (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07006526 }
6527 }
6528 else
6529 {//we might need another flag to check if CSR needs to request imps at all
6530
6531 tANI_U32 nTime = 0;
6532
6533 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_FALSE;
6534 if(!HAL_STATUS_SUCCESS(csrScanTriggerIdleScan(pMac, &nTime)))
6535 {
6536 csrScanStartIdleScanTimer(pMac, nTime);
6537 }
6538 }
6539 }
6540}
6541
6542
6543//Param: pTimeInterval -- Caller allocated memory in return, if failed, to specify the nxt time interval for
6544//idle scan timer interval
6545//Return: Not success -- meaning it cannot start IMPS, caller needs to start a timer for idle scan
6546eHalStatus csrScanTriggerIdleScan(tpAniSirGlobal pMac, tANI_U32 *pTimeInterval)
6547{
6548 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
6549
6550 //Do not trigger IMPS in case of concurrency
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006551 if (vos_concurrent_sessions_running() && csrIsAnySessionInConnectState(pMac))
6552 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006553 smsLog( pMac, LOG1, FL("Cannot request IMPS because Concurrent Sessions Running") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006554 return (status);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006555 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006556
6557 if(pTimeInterval)
6558 {
6559 *pTimeInterval = 0;
6560 }
6561
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006562 smsLog(pMac, LOG3, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006563 if( smeCommandPending( pMac ) )
6564 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006565 smsLog( pMac, LOG1, FL(" Cannot request IMPS because command pending") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006566 //Not to enter IMPS because more work to do
6567 if(pTimeInterval)
6568 {
6569 *pTimeInterval = 0;
6570 }
6571 //restart when ready
6572 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6573
6574 return (status);
6575 }
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07006576 if (IsPmcImpsReqFailed (pMac))
6577 {
6578 if(pTimeInterval)
6579 {
6580 *pTimeInterval = 1000000; //usec
6581 }
6582 //restart when ready
6583 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006584
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07006585 return status;
6586 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006587 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6588 /*&& pMac->roam.configParam.impsSleepTime*/)
6589 {
6590 //Stop get result timer because idle scan gets scan result out of PE
6591 csrScanStopGetResultTimer(pMac);
6592 if(pTimeInterval)
6593 {
6594 *pTimeInterval = pMac->roam.configParam.impsSleepTime;
6595 }
6596 //pmcRequestImps take a period in millisecond unit.
6597 status = pmcRequestImps(pMac, pMac->roam.configParam.impsSleepTime / PAL_TIMER_TO_MS_UNIT, csrScanIMPSCallback, pMac);
6598 if(!HAL_STATUS_SUCCESS(status))
6599 {
6600 if(eHAL_STATUS_PMC_ALREADY_IN_IMPS != status)
6601 {
6602 //Do restart the timer if CSR thinks it cannot do IMPS
6603 if( !csrCheckPSReady( pMac ) )
6604 {
6605 if(pTimeInterval)
6606 {
6607 *pTimeInterval = 0;
6608 }
6609 //Set the restart flag to true because that idle scan
6610 //can be restarted even though the timer will not be running
6611 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6612 }
6613 else
6614 {
6615 //For not now, we do a quicker retry
6616 if(pTimeInterval)
6617 {
6618 *pTimeInterval = CSR_IDLE_SCAN_WAIT_TIME;
6619 }
6620 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006621 smsLog(pMac, LOGW, FL("call pmcRequestImps and it returns status code (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07006622 }
6623 else
6624 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006625 smsLog(pMac, LOGW, FL("already in IMPS"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006626 //Since CSR is the only module to request for IMPS. If it is already in IMPS, CSR assumes
6627 //the callback will be called in the future. Should not happen though.
6628 status = eHAL_STATUS_SUCCESS;
6629 pMac->scan.nIdleScanTimeGap = 0;
6630 }
6631 }
6632 else
6633 {
6634 //requested so let's reset the value
6635 pMac->scan.nIdleScanTimeGap = 0;
6636 }
6637 }
6638
6639 return (status);
6640}
6641
6642
6643eHalStatus csrScanStartIdleScan(tpAniSirGlobal pMac)
6644{
6645 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
6646 tANI_U32 nTime = 0;
6647
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006648 smsLog(pMac, LOGW, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006649 if(pMac->roam.configParam.IsIdleScanEnabled)
6650 {
6651 //stop bg scan first
6652 csrScanBGScanAbort(pMac);
6653 //Stop get result timer because idle scan gets scan result out of PE
6654 csrScanStopGetResultTimer(pMac);
6655 //Enable aging timer since idle scan is going on
6656 csrScanStartResultAgingTimer(pMac);
6657 }
6658 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_FALSE;
6659 status = csrScanTriggerIdleScan(pMac, &nTime);
6660 if(!HAL_STATUS_SUCCESS(status))
6661 {
6662 csrScanStartIdleScanTimer(pMac, nTime);
6663 }
6664
6665 return (status);
6666}
6667
6668
6669void csrScanCancelIdleScan(tpAniSirGlobal pMac)
6670{
6671 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6672 {
Jeff Johnson295189b2012-06-20 16:38:30 -07006673 if (vos_concurrent_sessions_running()) {
6674 return;
6675 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006676 smsLog(pMac, LOG1, " csrScanCancelIdleScan");
Jeff Johnson295189b2012-06-20 16:38:30 -07006677 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_TRUE;
6678 //Set the restart flag in case later on it is uncancelled
6679 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6680 csrScanStopIdleScanTimer(pMac);
6681 csrScanRemoveNotRoamingScanCommand(pMac);
6682 }
6683}
6684
6685
6686void csrScanIdleScanTimerHandler(void *pv)
6687{
6688 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6689 eHalStatus status;
6690 tANI_U32 nTime = 0;
6691
6692 smsLog(pMac, LOGW, " csrScanIdleScanTimerHandler called ");
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07006693 pmcResetImpsFailStatus (pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07006694 status = csrScanTriggerIdleScan(pMac, &nTime);
6695 if(!HAL_STATUS_SUCCESS(status) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan))
6696 {
6697 //Check whether it is time to actually do an idle scan
6698 if(pMac->scan.nIdleScanTimeGap >= pMac->roam.configParam.impsSleepTime)
6699 {
6700 pMac->scan.nIdleScanTimeGap = 0;
6701 csrScanIMPSCallback(pMac, eHAL_STATUS_SUCCESS);
6702 }
6703 else
6704 {
6705 csrScanStartIdleScanTimer(pMac, nTime);
6706 }
6707 }
6708}
6709
6710
6711
6712
6713tANI_BOOLEAN csrScanRemoveNotRoamingScanCommand(tpAniSirGlobal pMac)
6714{
6715 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
6716 tListElem *pEntry, *pEntryTmp;
6717 tSmeCmd *pCommand;
6718 tDblLinkList localList;
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306719 tDblLinkList *pCmdList;
Jeff Johnson295189b2012-06-20 16:38:30 -07006720
6721 vos_mem_zero(&localList, sizeof(tDblLinkList));
6722 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
6723 {
6724 smsLog(pMac, LOGE, FL(" failed to open list"));
6725 return fRet;
6726 }
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306727 if (!pMac->fScanOffload)
6728 pCmdList = &pMac->sme.smeCmdPendingList;
6729 else
6730 pCmdList = &pMac->sme.smeScanCmdPendingList;
Jeff Johnson295189b2012-06-20 16:38:30 -07006731
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306732 csrLLLock(pCmdList);
6733 pEntry = csrLLPeekHead(pCmdList, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07006734 while(pEntry)
6735 {
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306736 pEntryTmp = csrLLNext(pCmdList, pEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07006737 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6738 if( eSmeCommandScan == pCommand->command )
6739 {
6740 switch( pCommand->u.scanCmd.reason )
6741 {
6742 case eCsrScanIdleScan:
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306743 if( csrLLRemoveEntry(pCmdList, pEntry, LL_ACCESS_NOLOCK) )
Jeff Johnson295189b2012-06-20 16:38:30 -07006744 {
6745 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
6746 }
6747 fRet = eANI_BOOLEAN_TRUE;
6748 break;
6749
6750 default:
6751 break;
6752 } //switch
6753 }
6754 pEntry = pEntryTmp;
6755 }
6756
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306757 csrLLUnlock(pCmdList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006758
6759 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
6760 {
6761 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6762 csrReleaseCommandScan( pMac, pCommand );
6763 }
6764
6765 csrLLClose(&localList);
6766
6767 return (fRet);
6768}
6769
6770
6771tANI_BOOLEAN csrScanRemoveFreshScanCommand(tpAniSirGlobal pMac, tANI_U8 sessionId)
6772{
6773 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
6774 tListElem *pEntry, *pEntryTmp;
6775 tSmeCmd *pCommand;
6776 tDblLinkList localList;
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306777 tDblLinkList *pCmdList;
Jeff Johnson295189b2012-06-20 16:38:30 -07006778
6779 vos_mem_zero(&localList, sizeof(tDblLinkList));
6780 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
6781 {
6782 smsLog(pMac, LOGE, FL(" failed to open list"));
6783 return fRet;
6784 }
6785
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306786 if (!pMac->fScanOffload)
6787 pCmdList = &pMac->sme.smeCmdPendingList;
6788 else
6789 pCmdList = &pMac->sme.smeScanCmdPendingList;
6790
6791 csrLLLock(pCmdList);
6792 pEntry = csrLLPeekHead(pCmdList, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07006793 while(pEntry)
6794 {
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306795 pEntryTmp = csrLLNext(pCmdList, pEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07006796 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6797 if( (eSmeCommandScan == pCommand->command) && (sessionId == pCommand->sessionId) )
6798 {
6799 switch(pCommand->u.scanCmd.reason)
6800 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006801#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
6802 case eCsrScanGetLfrResult:
6803#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006804 case eCsrScanGetResult:
6805 case eCsrScanSetBGScanParam:
6806 case eCsrScanBGScanAbort:
6807 case eCsrScanBGScanEnable:
6808 case eCsrScanGetScanChnInfo:
6809 break;
6810 default:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006811 smsLog (pMac, LOGW, "%s: -------- abort scan command reason = %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07006812 __func__, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07006813 //The rest are fresh scan requests
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306814 if( csrLLRemoveEntry(pCmdList, pEntry, LL_ACCESS_NOLOCK) )
Jeff Johnson295189b2012-06-20 16:38:30 -07006815 {
6816 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
6817 }
6818 fRet = eANI_BOOLEAN_TRUE;
6819 break;
6820 }
6821 }
6822 pEntry = pEntryTmp;
6823 }
6824
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306825 csrLLUnlock(pCmdList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006826
6827 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
6828 {
6829 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6830 if (pCommand->u.scanCmd.callback)
6831 {
6832 /* User scan request is pending,
6833 * send response with status eCSR_SCAN_ABORT*/
6834 pCommand->u.scanCmd.callback(pMac,
6835 pCommand->u.scanCmd.pContext,
6836 pCommand->u.scanCmd.scanID,
6837 eCSR_SCAN_ABORT);
6838 }
6839 csrReleaseCommandScan( pMac, pCommand );
6840 }
6841 csrLLClose(&localList);
6842
6843 return (fRet);
6844}
6845
6846
6847void csrReleaseScanCommand(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
6848{
6849 eCsrScanReason reason = pCommand->u.scanCmd.reason;
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306850 tANI_BOOLEAN status;
6851
6852 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07006853 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306854 tANI_U32 i;
6855 for(i = 0; i < CSR_ROAM_SESSION_MAX; i++)
6856 csrRoamStateChange(pMac, pCommand->u.scanCmd.lastRoamState[i], i);
6857 }
6858 else
6859 {
6860 csrRoamStateChange(pMac,
6861 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId],
6862 pCommand->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07006863 }
6864
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306865 csrScanCallCallback(pMac, pCommand, scanStatus);
Jeff Johnson295189b2012-06-20 16:38:30 -07006866
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006867 smsLog(pMac, LOG3, " Remove Scan command reason = %d", reason);
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306868 if (pMac->fScanOffload)
6869 {
6870 status = csrLLRemoveEntry(&pMac->sme.smeScanCmdActiveList,
6871 &pCommand->Link, LL_ACCESS_LOCK);
6872 }
6873 else
6874 {
6875 status = csrLLRemoveEntry(&pMac->sme.smeCmdActiveList,
6876 &pCommand->Link, LL_ACCESS_LOCK);
6877 }
6878
6879 if(status)
Jeff Johnson295189b2012-06-20 16:38:30 -07006880 {
6881 csrReleaseCommandScan( pMac, pCommand );
6882 }
6883 else
6884 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306885 smsLog(pMac, LOGE,
6886 " ********csrReleaseScanCommand cannot release command reason %d",
6887 pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07006888 }
6889}
6890
6891
6892eHalStatus csrScanGetPMKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
6893 tPmkidCandidateInfo *pPmkidList, tANI_U32 *pNumItems )
6894{
6895 eHalStatus status = eHAL_STATUS_SUCCESS;
6896 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
6897
Jeff Johnson32d95a32012-09-10 13:15:23 -07006898 if(!pSession)
6899 {
6900 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
6901 return eHAL_STATUS_FAILURE;
6902 }
6903
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006904 smsLog(pMac, LOGW, " pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07006905 csrResetPMKIDCandidateList(pMac, sessionId);
6906 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
6907 {
6908 tCsrScanResultFilter *pScanFilter;
6909 tCsrScanResultInfo *pScanResult;
6910 tScanResultHandle hBSSList;
6911 tANI_U32 nItems = *pNumItems;
6912
6913 *pNumItems = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05306914 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
6915 if ( NULL == pScanFilter )
6916 status = eHAL_STATUS_FAILURE;
6917 else
Jeff Johnson295189b2012-06-20 16:38:30 -07006918 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306919 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006920 //Here is the profile we need to connect to
6921 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
6922 if(HAL_STATUS_SUCCESS(status))
6923 {
6924 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
6925 if(HAL_STATUS_SUCCESS(status))
6926 {
6927 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumPmkidCandidate < nItems))
6928 {
6929 //NumPmkidCandidate adds up here
6930 csrProcessBSSDescForPMKIDList(pMac, &pScanResult->BssDescriptor,
6931 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
6932 }
6933 if(pSession->NumPmkidCandidate)
6934 {
6935 *pNumItems = pSession->NumPmkidCandidate;
Kiet Lam64c1b492013-07-12 13:56:44 +05306936 vos_mem_copy(pPmkidList, pSession->PmkidCandidateInfo,
6937 pSession->NumPmkidCandidate * sizeof(tPmkidCandidateInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07006938 }
6939 csrScanResultPurge(pMac, hBSSList);
6940 }//Have scan result
6941 csrFreeScanFilter(pMac, pScanFilter);
6942 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306943 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07006944 }
6945 }
6946
6947 return (status);
6948}
6949
6950
6951
6952#ifdef FEATURE_WLAN_WAPI
6953eHalStatus csrScanGetBKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
6954 tBkidCandidateInfo *pBkidList, tANI_U32 *pNumItems )
6955{
6956 eHalStatus status = eHAL_STATUS_SUCCESS;
6957 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
6958
Jeff Johnson32d95a32012-09-10 13:15:23 -07006959 if(!pSession)
6960 {
6961 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
6962 return eHAL_STATUS_FAILURE;
6963 }
6964
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006965 smsLog(pMac, LOGW, " pMac->scan.NumBkidCandidate = %d", pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07006966 csrResetBKIDCandidateList(pMac, sessionId);
6967 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
6968 {
6969 tCsrScanResultFilter *pScanFilter;
6970 tCsrScanResultInfo *pScanResult;
6971 tScanResultHandle hBSSList;
6972 tANI_U32 nItems = *pNumItems;
6973 *pNumItems = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05306974 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
6975 if ( NULL == pScanFilter )
6976 status = eHAL_STATUS_FAILURE;
6977 else
Jeff Johnson295189b2012-06-20 16:38:30 -07006978 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306979 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006980 //Here is the profile we need to connect to
6981 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
6982 if(HAL_STATUS_SUCCESS(status))
6983 {
6984 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
6985 if(HAL_STATUS_SUCCESS(status))
6986 {
6987 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumBkidCandidate < nItems))
6988 {
6989 //pMac->scan.NumBkidCandidate adds up here
6990 csrProcessBSSDescForBKIDList(pMac, &pScanResult->BssDescriptor,
6991 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
6992
6993 }
6994 if(pSession->NumBkidCandidate)
6995 {
6996 *pNumItems = pSession->NumBkidCandidate;
Kiet Lam64c1b492013-07-12 13:56:44 +05306997 vos_mem_copy(pBkidList, pSession->BkidCandidateInfo, pSession->NumBkidCandidate * sizeof(tBkidCandidateInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07006998 }
6999 csrScanResultPurge(pMac, hBSSList);
7000 }//Have scan result
7001 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307002 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07007003 }
7004 }
7005
7006 return (status);
7007}
7008#endif /* FEATURE_WLAN_WAPI */
7009
7010
7011
7012//This function is usually used for BSSs that suppresses SSID so the profile
7013//shall have one and only one SSID
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007014eHalStatus csrScanForSSID(tpAniSirGlobal pMac, tANI_U32 sessionId, tCsrRoamProfile *pProfile, tANI_U32 roamId, tANI_BOOLEAN notify)
Jeff Johnson295189b2012-06-20 16:38:30 -07007015{
7016 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
7017 tSmeCmd *pScanCmd = NULL;
7018 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
7019 tANI_U8 index = 0;
7020 tANI_U32 numSsid = pProfile->SSIDs.numOfSSIDs;
7021
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007022 smsLog(pMac, LOG2, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007023 //For WDS, we use the index 0. There must be at least one in there
7024 if( CSR_IS_WDS_STA( pProfile ) && numSsid )
7025 {
7026 numSsid = 1;
7027 }
7028 if(pMac->scan.fScanEnable && ( numSsid == 1 ) )
7029 {
7030 do
7031 {
7032 pScanCmd = csrGetCommandBuffer(pMac);
7033 if(!pScanCmd)
7034 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007035 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007036 break;
7037 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307038 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
7039 pScanCmd->u.scanCmd.pToRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
7040 if ( NULL == pScanCmd->u.scanCmd.pToRoamProfile )
7041 status = eHAL_STATUS_FAILURE;
7042 else
7043 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07007044 status = csrRoamCopyProfile(pMac, pScanCmd->u.scanCmd.pToRoamProfile, pProfile);
7045 if(!HAL_STATUS_SUCCESS(status))
7046 break;
7047 pScanCmd->u.scanCmd.roamId = roamId;
7048 pScanCmd->command = eSmeCommandScan;
Jeff Johnsone7245742012-09-05 17:12:55 -07007049 pScanCmd->sessionId = (tANI_U8)sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07007050 pScanCmd->u.scanCmd.callback = NULL;
7051 pScanCmd->u.scanCmd.pContext = NULL;
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007052 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 -07007053 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Kiet Lam64c1b492013-07-12 13:56:44 +05307054 vos_mem_set(&pScanCmd->u.scanCmd.u.scanRequest, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007055 pScanCmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Jeff Johnson295189b2012-06-20 16:38:30 -07007056 pScanCmd->u.scanCmd.u.scanRequest.BSSType = pProfile->BSSType;
Jeff Johnsone7245742012-09-05 17:12:55 -07007057 // To avoid 11b rate in probe request Set p2pSearch flag as 1 for P2P Client Mode
7058 if(VOS_P2P_CLIENT_MODE == pProfile->csrPersona)
7059 {
7060 pScanCmd->u.scanCmd.u.scanRequest.p2pSearch = 1;
7061 }
7062 if(pProfile->pAddIEScan)
7063 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307064 pScanCmd->u.scanCmd.u.scanRequest.pIEField = vos_mem_malloc(
7065 pProfile->nAddIEScanLength);
7066 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.pIEField )
7067 status = eHAL_STATUS_FAILURE;
7068 else
7069 status = eHAL_STATUS_SUCCESS;
7070 vos_mem_set(pScanCmd->u.scanCmd.u.scanRequest.pIEField,
7071 pProfile->nAddIEScanLength, 0);
7072 if (HAL_STATUS_SUCCESS(status))
Jeff Johnsone7245742012-09-05 17:12:55 -07007073 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307074 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.pIEField,
7075 pProfile->pAddIEScan, pProfile->nAddIEScanLength);
Jeff Johnsone7245742012-09-05 17:12:55 -07007076 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = pProfile->nAddIEScanLength;
7077 }
7078 else
7079 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007080 smsLog(pMac, LOGE, "No memory for scanning IE fields");
Jeff Johnsone7245742012-09-05 17:12:55 -07007081 }
7082 } //Allocate memory for IE field
7083 else
7084 {
7085 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = 0;
7086 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07007087 /* For one channel be good enpugh time to receive beacon atleast */
7088 if( 1 == pProfile->ChannelInfo.numOfChannels )
7089 {
7090 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime = MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7091 pScanCmd->u.scanCmd.u.scanRequest.minChnTime = MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7092 }
7093 else
7094 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307095 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime =
7096 pMac->roam.configParam.nActiveMaxChnTime;
7097 pScanCmd->u.scanCmd.u.scanRequest.minChnTime =
7098 pMac->roam.configParam.nActiveMinChnTime;
Jeff Johnson32d95a32012-09-10 13:15:23 -07007099 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307100 pScanCmd->u.scanCmd.u.scanRequest.maxChnTimeBtc =
7101 pMac->roam.configParam.nActiveMaxChnTimeBtc;
7102 pScanCmd->u.scanCmd.u.scanRequest.minChnTimeBtc =
7103 pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07007104 if(pProfile->BSSIDs.numOfBSSIDs == 1)
7105 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307106 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.bssid,
7107 pProfile->BSSIDs.bssid, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07007108 }
7109 else
7110 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307111 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.bssid, bAddr, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07007112 }
7113 if(pProfile->ChannelInfo.numOfChannels)
7114 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307115 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(
7116 sizeof(*pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
7117 * pProfile->ChannelInfo.numOfChannels);
7118 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
7119 status = eHAL_STATUS_FAILURE;
7120 else
7121 status = eHAL_STATUS_SUCCESS;
7122 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
7123 if(HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07007124 {
7125 csrRoamIsChannelValid(pMac, pProfile->ChannelInfo.ChannelList[0]);
7126 for(index = 0; index < pProfile->ChannelInfo.numOfChannels; index++)
7127 {
7128 if(csrRoamIsValidChannel(pMac, pProfile->ChannelInfo.ChannelList[index]))
7129 {
7130 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels]
7131 = pProfile->ChannelInfo.ChannelList[index];
7132 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels++;
7133 }
7134 else
7135 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007136 smsLog(pMac, LOGW, FL("process a channel (%d) that is invalid"), pProfile->ChannelInfo.ChannelList[index]);
Jeff Johnson295189b2012-06-20 16:38:30 -07007137 }
7138
7139 }
7140 }
7141 else
7142 {
7143 break;
7144 }
7145
7146 }
7147 else
7148 {
7149 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
7150 }
7151 if(pProfile->SSIDs.numOfSSIDs)
7152 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307153 pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList = vos_mem_malloc(
7154 pProfile->SSIDs.numOfSSIDs * sizeof(tCsrSSIDInfo));
7155 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList )
7156 status = eHAL_STATUS_FAILURE;
7157 else
7158 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07007159 if(!HAL_STATUS_SUCCESS(status))
7160 {
7161 break;
7162 }
7163 pScanCmd->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 1;
Kiet Lam64c1b492013-07-12 13:56:44 +05307164 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList,
7165 pProfile->SSIDs.SSIDList, sizeof(tCsrSSIDInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07007166 }
7167 //Start process the command
7168 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
7169 if( !HAL_STATUS_SUCCESS( status ) )
7170 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007171 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07007172 break;
7173 }
7174 }while(0);
7175 if(!HAL_STATUS_SUCCESS(status))
7176 {
7177 if(pScanCmd)
7178 {
7179 csrReleaseCommandScan(pMac, pScanCmd);
7180 //TODO:free the memory that is allocated in this function
7181 }
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007182 if(notify)
7183 {
Jeff Johnson295189b2012-06-20 16:38:30 -07007184 csrRoamCallCallback(pMac, sessionId, NULL, roamId, eCSR_ROAM_FAILED, eCSR_ROAM_RESULT_FAILURE);
7185 }
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007186 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007187 }//valid
7188 else
7189 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007190 smsLog(pMac, LOGE, FL("cannot scan because scanEnable (%d) or numSSID (%d) is invalid"),
Jeff Johnson295189b2012-06-20 16:38:30 -07007191 pMac->scan.fScanEnable, pProfile->SSIDs.numOfSSIDs);
7192 }
7193
7194 return (status);
7195}
7196
7197
7198//Issue a scan base on the new capability infomation
7199//This should only happen when the associated AP changes its capability.
7200//After this scan is done, CSR reroams base on the new scan results
7201eHalStatus csrScanForCapabilityChange(tpAniSirGlobal pMac, tSirSmeApNewCaps *pNewCaps)
7202{
7203 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
7204 tSmeCmd *pScanCmd = NULL;
7205
7206 if(pNewCaps)
7207 {
7208 do
7209 {
7210 pScanCmd = csrGetCommandBuffer(pMac);
7211 if(!pScanCmd)
7212 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007213 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007214 status = eHAL_STATUS_RESOURCES;
7215 break;
7216 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307217 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007218 status = eHAL_STATUS_SUCCESS;
7219 pScanCmd->u.scanCmd.roamId = 0;
7220 pScanCmd->command = eSmeCommandScan;
7221 pScanCmd->u.scanCmd.callback = NULL;
7222 pScanCmd->u.scanCmd.pContext = NULL;
7223 pScanCmd->u.scanCmd.reason = eCsrScanForCapsChange;
7224 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
7225 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
7226 if( !HAL_STATUS_SUCCESS( status ) )
7227 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007228 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07007229 break;
7230 }
7231 }while(0);
7232 if(!HAL_STATUS_SUCCESS(status))
7233 {
7234 if(pScanCmd)
7235 {
7236 csrReleaseCommandScan(pMac, pScanCmd);
7237 }
7238 }
7239 }
7240
7241 return (status);
7242}
7243
7244
7245
7246void csrInitBGScanChannelList(tpAniSirGlobal pMac)
7247{
7248 tANI_U32 len = CSR_MIN(sizeof(pMac->roam.validChannelList), sizeof(pMac->scan.bgScanChannelList));
7249
Kiet Lam64c1b492013-07-12 13:56:44 +05307250 vos_mem_set(pMac->scan.bgScanChannelList, len, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007251 pMac->scan.numBGScanChannel = 0;
7252
7253 if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
7254 {
7255 pMac->roam.numValidChannels = len;
7256 pMac->scan.numBGScanChannel = (tANI_U8)CSR_MIN(len, WNI_CFG_BG_SCAN_CHANNEL_LIST_LEN);
Kiet Lam64c1b492013-07-12 13:56:44 +05307257 vos_mem_copy(pMac->scan.bgScanChannelList, pMac->roam.validChannelList,
7258 pMac->scan.numBGScanChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07007259 csrSetBGScanChannelList(pMac, pMac->scan.bgScanChannelList, pMac->scan.numBGScanChannel);
7260 }
7261}
7262
7263
7264//This function return TRUE if background scan channel list is adjusted.
7265//this function will only shrink the background scan channel list
7266tANI_BOOLEAN csrAdjustBGScanChannelList(tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels,
7267 tANI_U8 *pAdjustChannels, tANI_U8 *pNumAdjustChannels)
7268{
7269 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
7270 tANI_U8 i, j, count = *pNumAdjustChannels;
7271
7272 i = 0;
7273 while(i < count)
7274 {
7275 for(j = 0; j < NumChannels; j++)
7276 {
7277 if(pChannelList[j] == pAdjustChannels[i])
7278 break;
7279 }
7280 if(j == NumChannels)
7281 {
7282 //This channel is not in the list, remove it
7283 fRet = eANI_BOOLEAN_TRUE;
7284 count--;
7285 if(count - i)
7286 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307287 vos_mem_copy(&pAdjustChannels[i], &pAdjustChannels[i+1], count - i);
Jeff Johnson295189b2012-06-20 16:38:30 -07007288 }
7289 else
7290 {
7291 //already remove the last one. Done.
7292 break;
7293 }
7294 }
7295 else
7296 {
7297 i++;
7298 }
7299 }//while(i<count)
7300 *pNumAdjustChannels = count;
7301
7302 return (fRet);
7303}
7304
7305
7306//Get the list of the base channels to scan for passively 11d info
7307eHalStatus csrScanGetSupportedChannels( tpAniSirGlobal pMac )
7308{
7309 eHalStatus status = eHAL_STATUS_SUCCESS;
7310 int n = WNI_CFG_VALID_CHANNEL_LIST_LEN;
7311
7312 status = vos_nv_getSupportedChannels( pMac->scan.baseChannels.channelList, &n, NULL, NULL );
7313 if( HAL_STATUS_SUCCESS(status) )
7314 {
7315 pMac->scan.baseChannels.numChannels = (tANI_U8)n;
7316 }
7317 else
7318 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007319 smsLog( pMac, LOGE, FL(" failed") );
Jeff Johnson295189b2012-06-20 16:38:30 -07007320 pMac->scan.baseChannels.numChannels = 0;
7321 }
7322
7323 return ( status );
7324}
7325
7326//This function use the input pChannelList to validate the current saved channel list
7327eHalStatus csrSetBGScanChannelList( tpAniSirGlobal pMac, tANI_U8 *pAdjustChannels, tANI_U8 NumAdjustChannels)
7328{
7329 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumAdjustChannels;
7330
7331 return (ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pAdjustChannels, dataLen, NULL, eANI_BOOLEAN_FALSE));
7332}
7333
7334
7335void csrSetCfgValidChannelList( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels )
7336{
7337 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumChannels;
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05307338 eHalStatus status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007339
7340 ccmCfgSetStr(pMac, WNI_CFG_VALID_CHANNEL_LIST, pChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
7341
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05307342 if (pMac->fScanOffload)
7343 {
7344 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
7345 "Scan offload is enabled, update default chan list");
7346 status = csrUpdateChannelList(&pMac->scan);
7347 if (eHAL_STATUS_SUCCESS != status)
7348 {
7349 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR,
7350 "failed to update the supported channel list");
7351 }
7352 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007353 return;
7354}
7355
7356
7357
7358/*
7359 * The Tx power limits are saved in the cfg for future usage.
7360 */
7361void csrSaveTxPowerToCfg( tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 cfgId )
7362{
7363 tListElem *pEntry;
7364 tANI_U32 cbLen = 0, dataLen;
7365 tCsrChannelPowerInfo *pChannelSet;
7366 tANI_U32 idx;
7367 tSirMacChanInfo *pChannelPowerSet;
7368 tANI_U8 *pBuf = NULL;
7369
7370 //allocate maximum space for all channels
7371 dataLen = WNI_CFG_VALID_CHANNEL_LIST_LEN * sizeof(tSirMacChanInfo);
Kiet Lam64c1b492013-07-12 13:56:44 +05307372 if ( (pBuf = vos_mem_malloc(dataLen)) != NULL )
Jeff Johnson295189b2012-06-20 16:38:30 -07007373 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307374 vos_mem_set(pBuf, dataLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007375 pChannelPowerSet = (tSirMacChanInfo *)(pBuf);
7376
7377 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
7378 // write the tuples (startChan, numChan, txPower) for each channel found in the channel power list.
7379 while( pEntry )
7380 {
7381 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
7382 if ( 1 != pChannelSet->interChannelOffset )
7383 {
7384 // we keep the 5G channel sets internally with an interchannel offset of 4. Expand these
7385 // to the right format... (inter channel offset of 1 is the only option for the triplets
7386 // that 11d advertises.
7387 if ((cbLen + (pChannelSet->numChannels * sizeof(tSirMacChanInfo))) >= dataLen)
7388 {
7389 // expanding this entry will overflow our allocation
7390 smsLog(pMac, LOGE,
7391 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007392 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07007393 pChannelSet->firstChannel,
7394 pChannelSet->numChannels,
7395 pChannelSet->interChannelOffset);
7396 break;
7397 }
7398
7399 for( idx = 0; idx < pChannelSet->numChannels; idx++ )
7400 {
7401 pChannelPowerSet->firstChanNum = (tSirMacChanNum)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007402 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07007403 pChannelPowerSet->numChannels = 1;
Jeff Johnson295189b2012-06-20 16:38:30 -07007404 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007405 smsLog(pMac, LOG3, " Setting Max Transmit Power %d", pChannelPowerSet->maxTxPower);
Jeff Johnson295189b2012-06-20 16:38:30 -07007406 cbLen += sizeof( tSirMacChanInfo );
7407 pChannelPowerSet++;
7408 }
7409 }
7410 else
7411 {
7412 if (cbLen >= dataLen)
7413 {
7414 // this entry will overflow our allocation
7415 smsLog(pMac, LOGE,
7416 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007417 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07007418 pChannelSet->firstChannel,
7419 pChannelSet->numChannels,
7420 pChannelSet->interChannelOffset);
7421 break;
7422 }
7423 pChannelPowerSet->firstChanNum = pChannelSet->firstChannel;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007424 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07007425 pChannelPowerSet->numChannels = pChannelSet->numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -07007426 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007427 smsLog(pMac, LOG3, " Setting Max Transmit Power %d, nTxPower %d", pChannelPowerSet->maxTxPower,pMac->roam.configParam.nTxPowerCap );
Jeff Johnson295189b2012-06-20 16:38:30 -07007428
7429
7430 cbLen += sizeof( tSirMacChanInfo );
7431 pChannelPowerSet++;
7432 }
7433
7434 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
7435 }
7436
7437 if(cbLen)
7438 {
7439 ccmCfgSetStr(pMac, cfgId, (tANI_U8 *)pBuf, cbLen, NULL, eANI_BOOLEAN_FALSE);
7440 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307441 vos_mem_free(pBuf);
Jeff Johnson295189b2012-06-20 16:38:30 -07007442 }//Allocate memory
7443}
7444
7445
7446void csrSetCfgCountryCode( tpAniSirGlobal pMac, tANI_U8 *countryCode )
7447{
7448 tANI_U8 cc[WNI_CFG_COUNTRY_CODE_LEN];
7449 ///v_REGDOMAIN_t DomainId;
7450
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007451 smsLog( pMac, LOG3, "Setting Country Code in Cfg from csrSetCfgCountryCode %s",countryCode );
Kiet Lam64c1b492013-07-12 13:56:44 +05307452 vos_mem_copy(cc, countryCode, WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07007453
7454 // don't program the bogus country codes that we created for Korea in the MAC. if we see
7455 // the bogus country codes, program the MAC with the right country code.
7456 if ( ( 'K' == countryCode[ 0 ] && '1' == countryCode[ 1 ] ) ||
7457 ( 'K' == countryCode[ 0 ] && '2' == countryCode[ 1 ] ) ||
7458 ( 'K' == countryCode[ 0 ] && '3' == countryCode[ 1 ] ) ||
7459 ( 'K' == countryCode[ 0 ] && '4' == countryCode[ 1 ] ) )
7460 {
7461 // replace the alternate Korea country codes, 'K1', 'K2', .. with 'KR' for Korea
7462 cc[ 1 ] = 'R';
7463 }
7464 ccmCfgSetStr(pMac, WNI_CFG_COUNTRY_CODE, cc, WNI_CFG_COUNTRY_CODE_LEN, NULL, eANI_BOOLEAN_FALSE);
7465
7466 //Need to let HALPHY know about the current domain so it can apply some
7467 //domain-specific settings (TX filter...)
7468 /*if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(pMac, cc, &DomainId)))
7469 {
7470 halPhySetRegDomain(pMac, DomainId);
7471 }*/
7472}
7473
7474
7475
7476eHalStatus csrGetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pBuf, tANI_U8 *pbLen)
7477{
7478 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
7479 tANI_U32 len;
7480
7481 if(pBuf && pbLen && (*pbLen >= WNI_CFG_COUNTRY_CODE_LEN))
7482 {
7483 len = *pbLen;
7484 status = ccmCfgGetStr(pMac, WNI_CFG_COUNTRY_CODE, pBuf, &len);
7485 if(HAL_STATUS_SUCCESS(status))
7486 {
7487 *pbLen = (tANI_U8)len;
7488 }
7489 }
7490
7491 return (status);
7492}
7493
7494
7495void csrSetCfgScanControlList( tpAniSirGlobal pMac, tANI_U8 *countryCode, tCsrChannel *pChannelList )
7496{
7497 tANI_U8 i, j;
7498 tANI_BOOLEAN found=FALSE;
7499 tANI_U8 *pControlList = NULL;
7500 tANI_U32 len = WNI_CFG_SCAN_CONTROL_LIST_LEN;
7501
Kiet Lam64c1b492013-07-12 13:56:44 +05307502 if ( (pControlList = vos_mem_malloc(WNI_CFG_SCAN_CONTROL_LIST_LEN)) != NULL )
Jeff Johnson295189b2012-06-20 16:38:30 -07007503 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307504 vos_mem_set((void *)pControlList, WNI_CFG_SCAN_CONTROL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007505 if(HAL_STATUS_SUCCESS(ccmCfgGetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, &len)))
7506 {
7507 for (i = 0; i < pChannelList->numChannels; i++)
7508 {
7509 for (j = 0; j < len; j += 2)
7510 {
7511 if (pControlList[j] == pChannelList->channelList[i])
7512 {
7513 found = TRUE;
7514 break;
7515 }
7516 }
7517
7518 if (found) // insert a pair(channel#, flag)
7519 {
Gopichand Nakkala392cbc12013-05-28 16:15:00 +05307520 pControlList[j+1] = csrGetScanType(pMac, pControlList[j]);
Jeff Johnson295189b2012-06-20 16:38:30 -07007521 found = FALSE; // reset the flag
7522 }
7523
7524 }
7525
7526 ccmCfgSetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, len, NULL, eANI_BOOLEAN_FALSE);
7527 }//Successfully getting scan control list
Kiet Lam64c1b492013-07-12 13:56:44 +05307528 vos_mem_free(pControlList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007529 }//AllocateMemory
7530}
7531
7532
7533//if bgPeriod is 0, background scan is disabled. It is in millisecond units
7534eHalStatus csrSetCfgBackgroundScanPeriod(tpAniSirGlobal pMac, tANI_U32 bgPeriod)
7535{
7536 return (ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, bgPeriod, (tCcmCfgSetCallback) csrScanCcmCfgSetCallback, eANI_BOOLEAN_FALSE));
7537}
7538
7539
7540void csrScanCcmCfgSetCallback(tHalHandle hHal, tANI_S32 result)
7541{
7542 tListElem *pEntry = NULL;
7543 tSmeCmd *pCommand = NULL;
7544 tpAniSirGlobal pMac = PMAC_STRUCT( hHal );
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307545 tDblLinkList *pCmdList ;
7546
7547 if (!pMac->fScanOffload)
7548 pCmdList = &pMac->sme.smeCmdActiveList;
7549 else
7550 pCmdList = &pMac->sme.smeScanCmdActiveList;
7551
7552 pEntry = csrLLPeekHead( pCmdList, LL_ACCESS_LOCK );
Jeff Johnson295189b2012-06-20 16:38:30 -07007553 if ( pEntry )
7554 {
7555 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7556 if ( eSmeCommandScan == pCommand->command )
7557 {
7558 eCsrScanStatus scanStatus = (CCM_IS_RESULT_SUCCESS(result)) ? eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
7559 csrReleaseScanCommand(pMac, pCommand, scanStatus);
7560 }
7561 else
7562 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007563 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
Jeff Johnson295189b2012-06-20 16:38:30 -07007564 }
7565 }
7566 smeProcessPendingQueue( pMac );
7567}
7568
7569eHalStatus csrProcessSetBGScanParam(tpAniSirGlobal pMac, tSmeCmd *pCommand)
7570{
7571 eHalStatus status;
7572 tCsrBGScanRequest *pScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
7573 tANI_U32 dataLen = sizeof( tANI_U8 ) * pScanReq->ChannelInfo.numOfChannels;
7574
7575 //***setcfg for background scan channel list
7576 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MINIMUM_CHANNEL_TIME, pScanReq->minChnTime, NULL, eANI_BOOLEAN_FALSE);
7577 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MAXIMUM_CHANNEL_TIME, pScanReq->maxChnTime, NULL, eANI_BOOLEAN_FALSE);
7578 //Not set the background scan interval if not connected because bd scan should not be run if not connected
7579 if(!csrIsAllSessionDisconnected(pMac))
7580 {
7581 //If disbaling BG scan here, we need to stop aging as well
7582 if(pScanReq->scanInterval == 0)
7583 {
7584 //Stop aging because no new result is coming in
7585 csrScanStopResultAgingTimer(pMac);
7586 }
7587
7588#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
7589 {
7590 vos_log_scan_pkt_type *pScanLog = NULL;
7591
7592 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
7593 if(pScanLog)
7594 {
7595 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
7596 pScanLog->minChnTime = (v_U8_t)pScanReq->minChnTime;
7597 pScanLog->maxChnTime = (v_U8_t)pScanReq->maxChnTime;
7598 pScanLog->timeBetweenBgScan = (v_U8_t)pScanReq->scanInterval;
7599 pScanLog->numChannel = pScanReq->ChannelInfo.numOfChannels;
7600 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
7601 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307602 vos_mem_copy(pScanLog->channels,
7603 pScanReq->ChannelInfo.ChannelList,
7604 pScanLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07007605 }
7606 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
7607 }
7608 }
7609#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
7610
7611 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, pScanReq->scanInterval, NULL, eANI_BOOLEAN_FALSE);
7612 }
7613 else
7614 {
7615 //No need to stop aging because IDLE scan is still running
7616 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, 0, NULL, eANI_BOOLEAN_FALSE);
7617 }
7618
7619 if(pScanReq->SSID.length > WNI_CFG_SSID_LEN)
7620 {
7621 pScanReq->SSID.length = WNI_CFG_SSID_LEN;
7622 }
7623
7624 status = ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pScanReq->ChannelInfo.ChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
7625 status = ccmCfgSetStr(pMac, WNI_CFG_SSID, (tANI_U8 *)pScanReq->SSID.ssId, pScanReq->SSID.length, NULL, eANI_BOOLEAN_FALSE);
7626
7627
7628
7629 return (status);
7630}
7631
7632
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307633eHalStatus csrScanAbortMacScan(tpAniSirGlobal pMac, tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07007634{
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307635 eHalStatus status = eHAL_STATUS_FAILURE;
7636 tSirSmeScanAbortReq *pMsg;
Jeff Johnson295189b2012-06-20 16:38:30 -07007637 tANI_U16 msgLen;
7638 tListElem *pEntry;
7639 tSmeCmd *pCommand;
7640
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307641 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07007642 {
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307643#ifdef WLAN_AP_STA_CONCURRENCY
7644 csrLLLock(&pMac->scan.scanCmdPendingList);
7645 while(NULL !=
7646 (pEntry = csrLLRemoveHead(&pMac->scan.scanCmdPendingList,
7647 LL_ACCESS_NOLOCK)))
7648 {
Jeff Johnson295189b2012-06-20 16:38:30 -07007649
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307650 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7651 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
7652 }
7653 csrLLUnlock(&pMac->scan.scanCmdPendingList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007654#endif
7655
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307656 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
7657 csrRemoveCmdFromPendingList( pMac, &pMac->roam.roamCmdPendingList, eSmeCommandScan);
7658 csrRemoveCmdFromPendingList( pMac, &pMac->sme.smeCmdPendingList, eSmeCommandScan);
7659 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
7660
7661 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
7662 }
7663 else
7664 {
7665 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
7666 csrRemoveCmdWithSessionIdFromPendingList(pMac,
7667 sessionId,
7668 &pMac->sme.smeScanCmdPendingList,
7669 eSmeCommandScan);
7670 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
7671
7672 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
7673 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007674
7675 //We need to abort scan only if we are scanning
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307676 if(NULL != pEntry)
Jeff Johnson295189b2012-06-20 16:38:30 -07007677 {
7678 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307679 if(eSmeCommandScan == pCommand->command &&
7680 pCommand->sessionId == sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07007681 {
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307682 msgLen = (tANI_U16)(sizeof(tSirSmeScanAbortReq));
Kiet Lam64c1b492013-07-12 13:56:44 +05307683 pMsg = vos_mem_malloc(msgLen);
7684 if ( NULL == pMsg )
Jeff Johnson295189b2012-06-20 16:38:30 -07007685 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307686 status = eHAL_STATUS_FAILURE;
7687 smsLog(pMac, LOGE, FL("Failed to allocate memory for SmeScanAbortReq"));
7688 }
7689 else
7690 {
7691 vos_mem_set((void *)pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007692 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_ABORT_IND);
7693 pMsg->msgLen = pal_cpu_to_be16(msgLen);
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307694 pMsg->sessionId = sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07007695 status = palSendMBMessage(pMac->hHdd, pMsg);
7696 }
7697 }
7698 }
7699
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307700 return(status);
7701}
7702
7703void csrRemoveCmdWithSessionIdFromPendingList(tpAniSirGlobal pMac,
7704 tANI_U8 sessionId,
7705 tDblLinkList *pList,
7706 eSmeCommandType commandType)
7707{
7708 tDblLinkList localList;
7709 tListElem *pEntry;
7710 tSmeCmd *pCommand;
7711 tListElem *pEntryToRemove;
7712
7713 vos_mem_zero(&localList, sizeof(tDblLinkList));
7714 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
7715 {
7716 smsLog(pMac, LOGE, FL(" failed to open list"));
7717 return;
7718 }
7719
7720 csrLLLock(pList);
7721 if ((pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK)))
7722 {
7723
7724 /* Have to make sure we don't loop back to the head of the list,
7725 * which will happen if the entry is NOT on the list */
7726 while (pEntry)
7727 {
7728 pEntryToRemove = pEntry;
7729 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
7730 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
7731 if ((pCommand->command == commandType) &&
7732 (pCommand->sessionId == sessionId))
7733 {
7734 /* Remove that entry only */
7735 if (csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
7736 {
7737 csrLLInsertTail(&localList, pEntryToRemove,
7738 LL_ACCESS_NOLOCK);
7739 }
7740 }
7741 }
7742 }
7743 csrLLUnlock(pList);
7744
7745 while ((pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)))
7746 {
7747 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7748 csrAbortCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
7749 }
7750
7751 csrLLClose(&localList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007752}
7753
7754void csrRemoveCmdFromPendingList(tpAniSirGlobal pMac, tDblLinkList *pList,
7755 eSmeCommandType commandType )
7756{
7757 tDblLinkList localList;
7758 tListElem *pEntry;
7759 tSmeCmd *pCommand;
7760 tListElem *pEntryToRemove;
7761
7762 vos_mem_zero(&localList, sizeof(tDblLinkList));
7763 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
7764 {
7765 smsLog(pMac, LOGE, FL(" failed to open list"));
7766 return;
7767 }
7768
7769 csrLLLock(pList);
7770 if( !csrLLIsListEmpty( pList, LL_ACCESS_NOLOCK ) )
7771 {
7772 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK);
7773
7774 // Have to make sure we don't loop back to the head of the list, which will
7775 // happen if the entry is NOT on the list...
7776 while( pEntry )
7777 {
7778 pEntryToRemove = pEntry;
7779 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
7780 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
7781 if ( pCommand->command == commandType )
7782 {
7783 // Remove that entry only
7784 if(csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
7785 {
7786 csrLLInsertTail(&localList, pEntryToRemove, LL_ACCESS_NOLOCK);
7787 }
7788 }
7789 }
7790
7791
7792 }
7793 csrLLUnlock(pList);
7794
7795 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
7796 {
7797 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7798 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
7799 }
7800 csrLLClose(&localList);
7801
7802}
7803
7804
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307805eHalStatus csrScanAbortMacScanNotForConnect(tpAniSirGlobal pMac,
7806 tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07007807{
7808 eHalStatus status = eHAL_STATUS_SUCCESS;
7809
7810 if( !csrIsScanForRoamCommandActive( pMac ) )
7811 {
7812 //Only abort the scan if it is not used for other roam/connect purpose
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307813 status = csrScanAbortMacScan(pMac, sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07007814 }
7815
7816 return (status);
7817}
7818
7819
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05307820eHalStatus csrScanGetScanChannelInfo(tpAniSirGlobal pMac, tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07007821{
7822 eHalStatus status = eHAL_STATUS_SUCCESS;
7823 tSirMbMsg *pMsg;
7824 tANI_U16 msgLen;
7825
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05307826 if (pMac->fScanOffload)
7827 msgLen = (tANI_U16)(sizeof(tSirSmeGetScanChanReq));
7828 else
7829 msgLen = (tANI_U16)(sizeof(tSirMbMsg));
7830
Kiet Lam64c1b492013-07-12 13:56:44 +05307831 pMsg = vos_mem_malloc(msgLen);
7832 if ( NULL == pMsg )
7833 status = eHAL_STATUS_FAILURE;
7834 else
Jeff Johnson295189b2012-06-20 16:38:30 -07007835 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307836 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007837 pMsg->type = eWNI_SME_GET_SCANNED_CHANNEL_REQ;
7838 pMsg->msgLen = msgLen;
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05307839 if (pMac->fScanOffload)
7840 ((tSirSmeGetScanChanReq *)pMsg)->sessionId = sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07007841 status = palSendMBMessage(pMac->hHdd, pMsg);
7842 }
7843
7844 return( status );
7845}
7846
7847tANI_BOOLEAN csrRoamIsValidChannel( tpAniSirGlobal pMac, tANI_U8 channel )
7848{
7849 tANI_BOOLEAN fValid = FALSE;
7850 tANI_U32 idxValidChannels;
7851 tANI_U32 len = pMac->roam.numValidChannels;
7852
7853 for ( idxValidChannels = 0; ( idxValidChannels < len ); idxValidChannels++ )
7854 {
7855 if ( channel == pMac->roam.validChannelList[ idxValidChannels ] )
7856 {
7857 fValid = TRUE;
7858 break;
7859 }
7860 }
7861
7862 return fValid;
7863}
7864
Srikant Kuppa066904f2013-05-07 13:56:02 -07007865eHalStatus csrScanSavePreferredNetworkFound(tpAniSirGlobal pMac,
7866 tSirPrefNetworkFoundInd *pPrefNetworkFoundInd)
7867{
7868 v_U32_t uLen = 0;
7869 tpSirProbeRespBeacon pParsedFrame;
7870 tCsrScanResult *pScanResult = NULL;
7871 tSirBssDescription *pBssDescr = NULL;
7872 tANI_BOOLEAN fDupBss;
7873 tDot11fBeaconIEs *pIesLocal = NULL;
7874 tAniSSID tmpSsid;
7875 v_TIME_t timer=0;
7876 tpSirMacMgmtHdr macHeader = (tpSirMacMgmtHdr)pPrefNetworkFoundInd->data;
7877
7878 pParsedFrame =
Kiet Lam64c1b492013-07-12 13:56:44 +05307879 (tpSirProbeRespBeacon)vos_mem_malloc(sizeof(tSirProbeRespBeacon));
Srikant Kuppa066904f2013-05-07 13:56:02 -07007880
7881 if (NULL == pParsedFrame)
7882 {
7883 smsLog(pMac, LOGE, FL(" fail to allocate memory for frame"));
7884 return eHAL_STATUS_RESOURCES;
7885 }
7886
7887 if ( pPrefNetworkFoundInd->frameLength <= SIR_MAC_HDR_LEN_3A )
7888 {
7889 smsLog(pMac, LOGE,
7890 FL("Not enough bytes in PNO indication probe resp frame! length=%d"),
7891 pPrefNetworkFoundInd->frameLength);
7892 vos_mem_free(pParsedFrame);
7893 return eHAL_STATUS_FAILURE;
7894 }
7895
7896 if (sirConvertProbeFrame2Struct(pMac,
7897 &pPrefNetworkFoundInd->data[SIR_MAC_HDR_LEN_3A],
7898 pPrefNetworkFoundInd->frameLength - SIR_MAC_HDR_LEN_3A,
7899 pParsedFrame) != eSIR_SUCCESS ||
7900 !pParsedFrame->ssidPresent)
7901 {
7902 smsLog(pMac, LOGE,
7903 FL("Parse error ProbeResponse, length=%d"),
7904 pPrefNetworkFoundInd->frameLength);
7905 vos_mem_free(pParsedFrame);
7906 return eHAL_STATUS_FAILURE;
7907 }
7908 //24 byte MAC header and 12 byte to ssid IE
7909 if (pPrefNetworkFoundInd->frameLength >
7910 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET))
7911 {
7912 uLen = pPrefNetworkFoundInd->frameLength -
7913 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET);
7914 }
7915
Kiet Lam64c1b492013-07-12 13:56:44 +05307916 pScanResult = vos_mem_malloc(sizeof(tCsrScanResult) + uLen);
7917 if ( NULL == pScanResult )
Srikant Kuppa066904f2013-05-07 13:56:02 -07007918 {
7919 smsLog(pMac, LOGE, FL(" fail to allocate memory for frame"));
7920 vos_mem_free(pParsedFrame);
7921 return eHAL_STATUS_RESOURCES;
7922 }
7923
Kiet Lam64c1b492013-07-12 13:56:44 +05307924 vos_mem_set(pScanResult, sizeof(tCsrScanResult) + uLen, 0);
Srikant Kuppa066904f2013-05-07 13:56:02 -07007925 pBssDescr = &pScanResult->Result.BssDescriptor;
7926 /**
7927 * Length of BSS desription is without length of
7928 * length itself and length of pointer
7929 * that holds the next BSS description
7930 */
7931 pBssDescr->length = (tANI_U16)(
7932 sizeof(tSirBssDescription) - sizeof(tANI_U16) -
7933 sizeof(tANI_U32) + uLen);
7934 if (pParsedFrame->dsParamsPresent)
7935 {
7936 pBssDescr->channelId = pParsedFrame->channelNumber;
7937 }
7938 else if (pParsedFrame->HTInfo.present)
7939 {
7940 pBssDescr->channelId = pParsedFrame->HTInfo.primaryChannel;
7941 }
7942 else
7943 {
7944 pBssDescr->channelId = pParsedFrame->channelNumber;
7945 }
7946
7947 if ((pBssDescr->channelId > 0) && (pBssDescr->channelId < 15))
7948 {
7949 int i;
7950 // 11b or 11g packet
7951 // 11g iff extended Rate IE is present or
7952 // if there is an A rate in suppRate IE
7953 for (i = 0; i < pParsedFrame->supportedRates.numRates; i++)
7954 {
7955 if (sirIsArate(pParsedFrame->supportedRates.rate[i] & 0x7f))
7956 {
7957 pBssDescr->nwType = eSIR_11G_NW_TYPE;
7958 break;
7959 }
7960 }
7961 if (pParsedFrame->extendedRatesPresent)
7962 {
7963 pBssDescr->nwType = eSIR_11G_NW_TYPE;
7964 }
7965 }
7966 else
7967 {
7968 // 11a packet
7969 pBssDescr->nwType = eSIR_11A_NW_TYPE;
7970 }
7971
7972 pBssDescr->sinr = 0;
7973 pBssDescr->rssi = -1 * pPrefNetworkFoundInd->rssi;
7974 pBssDescr->beaconInterval = pParsedFrame->beaconInterval;
7975 pBssDescr->timeStamp[0] = pParsedFrame->timeStamp[0];
7976 pBssDescr->timeStamp[1] = pParsedFrame->timeStamp[1];
7977 pBssDescr->capabilityInfo = *((tANI_U16 *)&pParsedFrame->capabilityInfo);
Kiet Lam64c1b492013-07-12 13:56:44 +05307978 vos_mem_copy((tANI_U8 *) &pBssDescr->bssId, (tANI_U8 *) macHeader->bssId, sizeof(tSirMacAddr));
Srikant Kuppa066904f2013-05-07 13:56:02 -07007979 pBssDescr->nReceivedTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
7980
7981 smsLog( pMac, LOG2, "(%s):Bssid= %02x-%02x-%02x-%02x-%02x-%02x "
7982 "chan= %d, rssi = %d", __func__,
7983 pBssDescr->bssId[ 0 ], pBssDescr->bssId[ 1 ],
7984 pBssDescr->bssId[ 2 ], pBssDescr->bssId[ 3 ],
7985 pBssDescr->bssId[ 4 ], pBssDescr->bssId[ 5 ],
7986 pBssDescr->channelId,
7987 pBssDescr->rssi );
7988
7989 //IEs
7990 if (uLen)
7991 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307992 vos_mem_copy(&pBssDescr->ieFields,
7993 pPrefNetworkFoundInd->data + (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET),
7994 uLen);
Srikant Kuppa066904f2013-05-07 13:56:02 -07007995 }
7996
7997 pIesLocal = (tDot11fBeaconIEs *)( pScanResult->Result.pvIes );
7998 if ( !pIesLocal &&
7999 (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
8000 &pScanResult->Result.BssDescriptor, &pIesLocal))) )
8001 {
8002 smsLog(pMac, LOGE, FL(" Cannot parse IEs"));
8003 csrFreeScanResultEntry(pMac, pScanResult);
8004 vos_mem_free(pParsedFrame);
8005 return eHAL_STATUS_RESOURCES;
8006 }
8007
8008 fDupBss = csrRemoveDupBssDescription( pMac,
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05308009 &pScanResult->Result.BssDescriptor, pIesLocal, &tmpSsid, &timer, FALSE);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008010 //Check whether we have reach out limit
8011 if ( CSR_SCAN_IS_OVER_BSS_LIMIT(pMac) )
8012 {
8013 //Limit reach
8014 smsLog(pMac, LOGE, FL(" BSS limit reached"));
8015 //Free the resources
8016 if( (pScanResult->Result.pvIes == NULL) && pIesLocal )
8017 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308018 vos_mem_free(pIesLocal);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008019 }
8020 csrFreeScanResultEntry(pMac, pScanResult);
8021 vos_mem_free(pParsedFrame);
8022 return eHAL_STATUS_RESOURCES;
8023 }
8024 //Add to scan cache
8025 csrScanAddResult(pMac, pScanResult, pIesLocal);
8026
Kiet Lamb537cfb2013-11-07 12:56:49 +05308027 if( (pScanResult->Result.pvIes == NULL) && pIesLocal )
8028 {
8029 vos_mem_free(pIesLocal);
8030 }
8031
Srikant Kuppa066904f2013-05-07 13:56:02 -07008032 vos_mem_free(pParsedFrame);
8033
8034 return eHAL_STATUS_SUCCESS;
8035}
8036
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008037#ifdef FEATURE_WLAN_LFR
8038void csrInitOccupiedChannelsList(tpAniSirGlobal pMac)
8039{
8040 tListElem *pEntry = NULL;
8041 tCsrScanResult *pBssDesc = NULL;
8042 tDot11fBeaconIEs *pIes = NULL;
Srinivas28b5b4e2012-12-12 13:07:53 -08008043 tpCsrNeighborRoamControlInfo pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
8044
8045 if (0 != pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels)
8046 {
8047 smsLog(pMac, LOG1, FL("%s: Ini file contains neighbor scan channel list,"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008048 " hence NO need to build occupied channel list (numChannels = %d)"),
Srinivas28b5b4e2012-12-12 13:07:53 -08008049 __func__, pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels);
8050 return;
8051 }
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008052
8053 if (!csrNeighborRoamIsNewConnectedProfile(pMac))
8054 {
8055 smsLog(pMac, LOG2, FL("%s: donot flush occupied list since current roam profile"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008056 " matches previous (numChannels = %d)"),
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008057 __func__, pMac->scan.occupiedChannels.numChannels);
8058 return;
8059 }
8060
8061 /* Empty occupied channels here */
8062 pMac->scan.occupiedChannels.numChannels = 0;
8063
8064 csrLLLock(&pMac->scan.scanResultList);
8065 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
8066 while( pEntry )
8067 {
8068 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
8069 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
8070
8071 //At this time, pBssDescription->Result.pvIes may be NULL
Srikant Kuppa866893f2012-12-27 17:28:14 -08008072 if( !pIes && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008073 &pBssDesc->Result.BssDescriptor, &pIes))) )
8074 {
8075 continue;
8076 }
8077
8078 csrScanAddToOccupiedChannels(pMac, pBssDesc, &pMac->scan.occupiedChannels, pIes);
8079
8080 /*
8081 * Free the memory allocated for pIes in csrGetParsedBssDescriptionIEs
8082 */
8083 if( (pBssDesc->Result.pvIes == NULL) && pIes )
8084 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308085 vos_mem_free(pIes);
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008086 }
8087
8088 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK );
8089 }//while
8090 csrLLUnlock(&pMac->scan.scanResultList);
Srikant Kuppa866893f2012-12-27 17:28:14 -08008091
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008092}
8093#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07008094
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008095eHalStatus csrScanCreateEntryInScanCache(tpAniSirGlobal pMac, tANI_U32 sessionId,
8096 tCsrBssid bssid, tANI_U8 channel)
8097{
8098 eHalStatus status = eHAL_STATUS_SUCCESS;
8099 tDot11fBeaconIEs *pNewIes = NULL;
8100 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
Praveen Kumar Sirisilla8bdfac42013-10-10 17:20:48 -07008101 tSirBssDescription *pNewBssDescriptor = NULL;
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008102 tANI_U32 size = 0;
8103
8104 if(NULL == pSession)
8105 {
8106 status = eHAL_STATUS_FAILURE;
8107 return status;
8108 }
8109 smsLog(pMac, LOG2, FL("csrScanCreateEntryInScanCache: Current bssid::"
8110 "0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x"),
8111 pSession->pConnectBssDesc->bssId[0],
8112 pSession->pConnectBssDesc->bssId[1],
8113 pSession->pConnectBssDesc->bssId[2],
8114 pSession->pConnectBssDesc->bssId[3],
8115 pSession->pConnectBssDesc->bssId[4],
8116 pSession->pConnectBssDesc->bssId[5]);
8117 smsLog(pMac, LOG2, FL("csrScanCreateEntryInScanCache: My bssid::"
8118 "0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x channel %d"),
8119 bssid[0],bssid[1],bssid[2],
8120 bssid[3],bssid[4],bssid[5],channel);
8121
8122 do
8123 {
8124 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
8125 pSession->pConnectBssDesc, &pNewIes)))
8126 {
8127 smsLog(pMac, LOGE, FL("%s: Failed to parse IEs"),
8128 __func__);
8129 status = eHAL_STATUS_FAILURE;
8130 break;
8131 }
8132
8133 size = pSession->pConnectBssDesc->length + sizeof(pSession->pConnectBssDesc->length);
Kiet Lam64c1b492013-07-12 13:56:44 +05308134 if (size)
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008135 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308136 pNewBssDescriptor = vos_mem_malloc(size);
8137 if ( NULL == pNewBssDescriptor )
8138 status = eHAL_STATUS_FAILURE;
8139 else
8140 status = eHAL_STATUS_SUCCESS;
8141 if (HAL_STATUS_SUCCESS(status))
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008142 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308143 vos_mem_copy(pNewBssDescriptor, pSession->pConnectBssDesc, size);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008144 }
8145 else
8146 {
8147 smsLog(pMac, LOGE, FL("%s: memory allocation failed"),
8148 __func__);
8149 status = eHAL_STATUS_FAILURE;
8150 break;
8151 }
8152
8153 //change the BSSID & channel as passed
Kiet Lam64c1b492013-07-12 13:56:44 +05308154 vos_mem_copy(pNewBssDescriptor->bssId, bssid, sizeof(tSirMacAddr));
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008155 pNewBssDescriptor->channelId = channel;
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07008156 if(NULL == csrScanAppendBssDescription( pMac, pNewBssDescriptor, pNewIes, TRUE ))
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008157 {
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07008158 smsLog(pMac, LOGE, FL("%s: csrScanAppendBssDescription failed"),
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008159 __func__);
8160 status = eHAL_STATUS_FAILURE;
8161 break;
8162 }
8163 }
8164 else
8165 {
8166 smsLog(pMac, LOGE, FL("%s: length of bss descriptor is 0"),
8167 __func__);
8168 status = eHAL_STATUS_FAILURE;
8169 break;
8170 }
8171 smsLog(pMac, LOGE, FL("%s: entry successfully added in scan cache"),
8172 __func__);
8173 }while(0);
8174
8175 if(pNewIes)
8176 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308177 vos_mem_free(pNewIes);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008178 }
8179 if(pNewBssDescriptor)
8180 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308181 vos_mem_free(pNewBssDescriptor);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008182 }
8183 return status;
8184}
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07008185
8186#ifdef FEATURE_WLAN_CCX
8187// Update the TSF with the difference in system time
8188void UpdateCCKMTSF(tANI_U32 *timeStamp0, tANI_U32 *timeStamp1, tANI_U32 *incr)
8189{
8190 tANI_U64 timeStamp64 = ((tANI_U64)*timeStamp1 << 32) | (*timeStamp0);
8191
8192 timeStamp64 = (tANI_U64)(timeStamp64 + (tANI_U64)*incr);
8193 *timeStamp0 = (tANI_U32)(timeStamp64 & 0xffffffff);
8194 *timeStamp1 = (tANI_U32)((timeStamp64 >> 32) & 0xffffffff);
8195}
8196#endif