blob: eedf06c764893aa4423fef557345a6433608e1e3 [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
Tushnim Bhattacharyyaae317772013-10-23 18:55:38 -07003091 //we don't need to update CC while connected to an AP which is advertising CC already
3092 if (csrIs11dSupported(pMac))
3093 {
3094 tANI_U32 i;
3095 tCsrRoamSession *pSession;
3096
3097 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
3098 {
3099 if (CSR_IS_SESSION_VALID( pMac, i ) )
3100 {
3101 pSession = CSR_GET_SESSION( pMac, i );
3102 if (csrIsConnStateConnected(pMac, i))
3103 {
3104 if (csrIsBssidMatch(pMac, (tCsrBssid *)&pMac->scan.currentCountryBssid,
3105 &pSession->connectedProfile.bssid))
3106 {
3107 smsLog(pMac, LOGW, FL("No need for updating CC, we will"
3108 "continue with current AP's CC"));
3109 goto end;
3110 }
3111 }
3112 }
3113 }
Tushnim Bhattacharyyaae317772013-10-23 18:55:38 -07003114
Tushnim Bhattacharyyac3022ef2013-10-24 15:58:56 -07003115 // Calculating 30% of current rssi is an idea for not to change
3116 // country code so freq.
3117 if (rssi_of_current_country != -128)
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303118 {
Tushnim Bhattacharyyac3022ef2013-10-24 15:58:56 -07003119 rssi_of_current_country = rssi_of_current_country
3120 - THIRTY_PERCENT(rssi_of_current_country);
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303121 }
Tushnim Bhattacharyyac3c1e8e2013-10-29 17:27:43 -07003122 //if new candidate AP has 30% better RSSI or this is the first time or
3123 //AP aged out of CSR cache or we are in world CC now
3124 if ((rssi_of_current_country <= cand_Bss_rssi ) || (rssi_of_current_country == -128)
3125 ||( '0' == pMac->scan.countryCode11d[ 0 ] && '0' == pMac->scan.countryCode11d[ 1 ] ))
Tushnim Bhattacharyyac3022ef2013-10-24 15:58:56 -07003126 {
3127 csrLLLock(&pMac->scan.scanResultList);
3128 pEntryTemp = csrLLPeekHead(&pMac->scan.scanResultList, LL_ACCESS_NOLOCK);
3129 while ( NULL != pEntryTemp)
3130 {
3131 pNext = csrLLNext(&pMac->scan.scanResultList, pEntryTemp,
3132 LL_ACCESS_NOLOCK);
3133 pBssDescription = GET_BASE_ADDR( pEntryTemp, tCsrScanResult, Link );
3134 pIesLocal = (tDot11fBeaconIEs *)( pBssDescription->Result.pvIes );
3135 // Need to traverse whole scan list to get description for best 11d AP.
3136 if (csrIsMacAddressEqual(pMac, (tCsrBssid *)&bssid_temp,
3137 (tCsrBssid *) pBssDescription->Result.BssDescriptor.bssId))
3138 {
Tushnim Bhattacharyyac3022ef2013-10-24 15:58:56 -07003139 // Best AP should be passed to update reg domain.
3140 csrLearnCountryInformation( pMac, &pBssDescription->Result.BssDescriptor,
3141 pIesLocal, eANI_BOOLEAN_TRUE );
Tushnim Bhattacharyyac3c1e8e2013-10-29 17:27:43 -07003142 //this check is to avoid the case of invalid CC set via 11d
3143 //In that case we move to world CC & we are open to any new
3144 //valid CC we can get during scan
3145 if(( '0' != pMac->scan.countryCode11d[ 0 ] && '0' != pMac->scan.countryCode11d[ 1 ] ))
3146 {
3147 palCopyMemory(pMac->hHdd, pMac->scan.currentCountryBssid,
3148 bssid_temp, sizeof(tSirMacAddr));
3149 }
Tushnim Bhattacharyyac3022ef2013-10-24 15:58:56 -07003150 break;
3151 }
3152 pEntryTemp = pNext;
3153 }
3154 csrLLUnlock(&pMac->scan.scanResultList);
3155 }
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303156 }
3157
3158
Tushnim Bhattacharyyaae317772013-10-23 18:55:38 -07003159end:
3160 //If we can find the current 11d info in any of the scan results, or
Jeff Johnson295189b2012-06-20 16:38:30 -07003161 // a good enough AP with the 11d info from the scan results then no need to
3162 // get into ambiguous state
3163 if(pMac->scan.fAmbiguous11dInfoFound)
3164 {
3165 if((pMac->scan.fCurrent11dInfoMatch) || (cand_Bss_rssi != -128))
3166 {
3167 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
3168 }
3169 }
3170
3171#ifdef FEATURE_WLAN_WAPI
3172 if(fNewWapiBSSForCurConnection)
3173 {
3174 //remember it first
3175 csrRoamCallCallback(pMac, sessionId, NULL, 0, eCSR_ROAM_SCAN_FOUND_NEW_BSS, eCSR_ROAM_RESULT_NEW_WAPI_BSS);
3176 }
3177#endif /* FEATURE_WLAN_WAPI */
3178
3179 return;
3180}
3181
3182
3183static tCsrScanResult *csrScanSaveBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pBSSDescription,
3184 tDot11fBeaconIEs *pIes)
3185{
3186 tCsrScanResult *pCsrBssDescription = NULL;
3187 tANI_U32 cbBSSDesc;
3188 tANI_U32 cbAllocated;
Jeff Johnson295189b2012-06-20 16:38:30 -07003189
3190 // figure out how big the BSS description is (the BSSDesc->length does NOT
3191 // include the size of the length field itself).
3192 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
3193
3194 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
3195
Kiet Lam64c1b492013-07-12 13:56:44 +05303196 pCsrBssDescription = vos_mem_malloc(cbAllocated);
3197 if ( NULL != pCsrBssDescription )
Jeff Johnson295189b2012-06-20 16:38:30 -07003198 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303199 vos_mem_set(pCsrBssDescription, cbAllocated, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003200 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Kiet Lam64c1b492013-07-12 13:56:44 +05303201 vos_mem_copy(&pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc);
Jeff Johnson295189b2012-06-20 16:38:30 -07003202#if defined(VOSS_ENSBALED)
3203 VOS_ASSERT( pCsrBssDescription->Result.pvIes == NULL );
3204#endif
3205 csrScanAddResult(pMac, pCsrBssDescription, pIes);
3206 }
3207
3208 return( pCsrBssDescription );
3209}
3210
3211// Append a Bss Description...
3212tCsrScanResult *csrScanAppendBssDescription( tpAniSirGlobal pMac,
3213 tSirBssDescription *pSirBssDescription,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07003214 tDot11fBeaconIEs *pIes, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07003215{
3216 tCsrScanResult *pCsrBssDescription = NULL;
3217 tAniSSID tmpSsid;
3218 v_TIME_t timer = 0;
3219 int result;
3220
3221 tmpSsid.length = 0;
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07003222 result = csrRemoveDupBssDescription( pMac, pSirBssDescription, pIes, &tmpSsid, &timer, fForced );
Jeff Johnson295189b2012-06-20 16:38:30 -07003223 pCsrBssDescription = csrScanSaveBssDescription( pMac, pSirBssDescription, pIes );
3224 if (result && (pCsrBssDescription != NULL))
3225 {
3226 //Check if the new one has SSID it it, if not, use the older SSID if it exists.
3227 if( (0 == pCsrBssDescription->Result.ssId.length) && tmpSsid.length )
3228 {
3229 //New BSS has a hidden SSID and old one has the SSID. Keep the SSID only
3230 //if diff of saved SSID time and current time is less than 1 min to avoid
3231 //side effect of saving SSID with old one is that if AP changes its SSID while remain
3232 //hidden, we may never see it and also to address the requirement of
3233 //When we remove hidden ssid from the profile i.e., forget the SSID via
3234 // GUI that SSID shouldn't see in the profile
3235 if((vos_timer_get_system_time()-timer) <= HIDDEN_TIMER)
3236 {
3237 pCsrBssDescription->Result.ssId = tmpSsid;
3238 pCsrBssDescription->Result.timer = timer;
3239 }
3240 }
3241 }
3242
3243
3244 return( pCsrBssDescription );
3245}
3246
3247
3248
3249void csrPurgeChannelPower( tpAniSirGlobal pMac, tDblLinkList *pChannelList )
3250{
3251 tCsrChannelPowerInfo *pChannelSet;
3252 tListElem *pEntry;
3253
3254 csrLLLock(pChannelList);
3255 // Remove the channel sets from the learned list and put them in the free list
3256 while( ( pEntry = csrLLRemoveHead( pChannelList, LL_ACCESS_NOLOCK ) ) != NULL)
3257 {
3258 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3259 if( pChannelSet )
3260 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303261 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003262 }
3263 }
3264 csrLLUnlock(pChannelList);
3265 return;
3266}
3267
3268
3269/*
3270 * Save the channelList into the ultimate storage as the final stage of channel
3271 * Input: pCountryInfo -- the country code (e.g. "USI"), channel list, and power limit are all stored inside this data structure
3272 */
Jeff Johnsone7245742012-09-05 17:12:55 -07003273eHalStatus csrSaveToChannelPower2G_5G( tpAniSirGlobal pMac, tANI_U32 tableSize, tSirMacChanInfo *channelTable )
Jeff Johnson295189b2012-06-20 16:38:30 -07003274{
3275 tANI_U32 i = tableSize / sizeof( tSirMacChanInfo );
3276 tSirMacChanInfo *pChannelInfo;
3277 tCsrChannelPowerInfo *pChannelSet;
3278 tANI_BOOLEAN f2GHzInfoFound = FALSE;
3279 tANI_BOOLEAN f2GListPurged = FALSE, f5GListPurged = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003280
3281 pChannelInfo = channelTable;
3282 // atleast 3 bytes have to be remaining -- from "countryString"
3283 while ( i-- )
3284 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303285 pChannelSet = vos_mem_malloc(sizeof(tCsrChannelPowerInfo));
3286 if ( NULL != pChannelSet )
Jeff Johnson295189b2012-06-20 16:38:30 -07003287 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303288 vos_mem_set(pChannelSet, sizeof(tCsrChannelPowerInfo), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003289 pChannelSet->firstChannel = pChannelInfo->firstChanNum;
3290 pChannelSet->numChannels = pChannelInfo->numChannels;
3291
3292 // Now set the inter-channel offset based on the frequency band the channel set lies in
Jeff Johnsone7245742012-09-05 17:12:55 -07003293 if( (CSR_IS_CHANNEL_24GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003294 ((pChannelSet->firstChannel + (pChannelSet->numChannels - 1)) <= CSR_MAX_24GHz_CHANNEL_NUMBER) )
Jeff Johnsone7245742012-09-05 17:12:55 -07003295
Jeff Johnson295189b2012-06-20 16:38:30 -07003296 {
3297 pChannelSet->interChannelOffset = 1;
3298 f2GHzInfoFound = TRUE;
3299 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003300 else if ( (CSR_IS_CHANNEL_5GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003301 ((pChannelSet->firstChannel + ((pChannelSet->numChannels - 1) * 4)) <= CSR_MAX_5GHz_CHANNEL_NUMBER) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003302 {
3303 pChannelSet->interChannelOffset = 4;
3304 f2GHzInfoFound = FALSE;
3305 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003306 else
3307 {
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003308 smsLog( pMac, LOGW, FL("Invalid Channel %d Present in Country IE"),
Jeff Johnsone7245742012-09-05 17:12:55 -07003309 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303310 vos_mem_free(pChannelSet);
Jeff Johnsone7245742012-09-05 17:12:55 -07003311 return eHAL_STATUS_FAILURE;
3312 }
3313
Jeff Johnson295189b2012-06-20 16:38:30 -07003314 pChannelSet->txPower = CSR_ROAM_MIN( pChannelInfo->maxTxPower, pMac->roam.configParam.nTxPowerCap );
3315
3316 if( f2GHzInfoFound )
3317 {
3318 if( !f2GListPurged )
3319 {
3320 // purge previous results if found new
3321 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList24 );
3322 f2GListPurged = TRUE;
3323 }
3324
3325 if(CSR_IS_OPERATING_BG_BAND(pMac))
3326 {
3327 // add to the list of 2.4 GHz channel sets
3328 csrLLInsertTail( &pMac->scan.channelPowerInfoList24, &pChannelSet->link, LL_ACCESS_LOCK );
3329 }
3330 else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003331 smsLog( pMac, LOGW, FL("Adding 11B/G channels in 11A mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003332 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303333 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003334 }
3335 }
3336 else
3337 {
3338 // 5GHz info found
3339 if( !f5GListPurged )
3340 {
3341 // purge previous results if found new
3342 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList5G );
3343 f5GListPurged = TRUE;
3344 }
3345
3346 if(CSR_IS_OPERATING_A_BAND(pMac))
3347 {
3348 // add to the list of 5GHz channel sets
3349 csrLLInsertTail( &pMac->scan.channelPowerInfoList5G, &pChannelSet->link, LL_ACCESS_LOCK );
3350 }
3351 else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003352 smsLog( pMac, LOGW, FL("Adding 11A channels in B/G mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003353 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303354 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003355 }
3356 }
3357 }
3358
3359 pChannelInfo++; // move to next entry
3360 }
3361
Jeff Johnsone7245742012-09-05 17:12:55 -07003362 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07003363}
3364
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303365static void csrClearDfsChannelList( tpAniSirGlobal pMac )
3366{
3367 tSirMbMsg *pMsg;
3368 tANI_U16 msgLen;
Jeff Johnson295189b2012-06-20 16:38:30 -07003369
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303370 msgLen = (tANI_U16)(sizeof( tSirMbMsg ));
Kiet Lam64c1b492013-07-12 13:56:44 +05303371 pMsg = vos_mem_malloc(msgLen);
3372 if ( NULL != pMsg )
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303373 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303374 vos_mem_set((void *)pMsg, msgLen, 0);
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303375 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_CLEAR_DFS_CHANNEL_LIST);
3376 pMsg->msgLen = pal_cpu_to_be16(msgLen);
3377 palSendMBMessage(pMac->hHdd, pMsg);
3378 }
3379}
Jeff Johnson295189b2012-06-20 16:38:30 -07003380
3381void csrApplyPower2Current( tpAniSirGlobal pMac )
3382{
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003383 smsLog( pMac, LOG3, FL(" Updating Cfg with power settings"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003384 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList24, WNI_CFG_MAX_TX_POWER_2_4 );
3385 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList5G, WNI_CFG_MAX_TX_POWER_5 );
3386}
3387
3388
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003389void csrApplyChannelPowerCountryInfo( tpAniSirGlobal pMac, tCsrChannel *pChannelList, tANI_U8 *countryCode, tANI_BOOLEAN updateRiva)
Jeff Johnson295189b2012-06-20 16:38:30 -07003390{
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303391 int i, j, count, countryIndex = -1;
Jeff Johnson295189b2012-06-20 16:38:30 -07003392 eNVChannelEnabledType channelEnabledType;
3393 tANI_U8 numChannels = 0;
3394 tANI_U8 tempNumChannels = 0;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303395 tANI_U8 channelIgnore = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003396 tCsrChannel ChannelList;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303397
Jeff Johnson295189b2012-06-20 16:38:30 -07003398 if( pChannelList->numChannels )
3399 {
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303400 for(count=0; count < MAX_COUNTRY_IGNORE; count++)
3401 {
3402 if(vos_mem_compare(countryCode, countryIgnoreList[count].countryCode,
3403 VOS_COUNTRY_CODE_LEN))
3404 {
3405 countryIndex = count;
3406 break;
3407 }
3408 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003409 tempNumChannels = CSR_MIN(pChannelList->numChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN);
3410 /* If user doesn't want to scan the DFS channels lets trim them from
3411 the valid channel list*/
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303412 for(i=0; i < tempNumChannels; i++)
Jeff Johnson295189b2012-06-20 16:38:30 -07003413 {
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303414 channelIgnore = FALSE;
3415 if( FALSE == pMac->scan.fEnableDFSChnlScan )
3416 {
3417 channelEnabledType =
3418 vos_nv_getChannelEnabledState(pChannelList->channelList[i]);
3419 }
3420 else
3421 {
Madan Mohan Koyyalamudi3f65e312012-11-06 15:31:12 -08003422 channelEnabledType = NV_CHANNEL_ENABLE;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303423 }
3424 if( NV_CHANNEL_ENABLE == channelEnabledType )
3425 {
3426 if( countryIndex != -1 )
3427 {
3428 for(j=0; j < countryIgnoreList[countryIndex].channelCount; j++)
3429 {
3430 if( pChannelList->channelList[i] ==
3431 countryIgnoreList[countryIndex].channelList[j] )
3432 {
3433 channelIgnore = TRUE;
3434 break;
3435 }
3436 }
3437 }
3438 if( FALSE == channelIgnore )
3439 {
3440 ChannelList.channelList[numChannels] = pChannelList->channelList[i];
3441 numChannels++;
3442 }
3443 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003444 }
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303445 ChannelList.numChannels = numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -07003446 csrSetCfgValidChannelList(pMac, ChannelList.channelList, ChannelList.numChannels);
3447 // extend scan capability
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303448 // build a scan list based on the channel list : channel# + active/passive scan
3449 csrSetCfgScanControlList(pMac, countryCode, &ChannelList);
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303450 /*Send msg to Lim to clear DFS channel list */
3451 csrClearDfsChannelList(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07003452#ifdef FEATURE_WLAN_SCAN_PNO
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003453 if (updateRiva)
3454 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003455 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO, FL(" Sending 11d PNO info to Riva"));
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003456 // Send HAL UpdateScanParams message
3457 pmcUpdateScanParams(pMac, &(pMac->roam.configParam), &ChannelList, TRUE);
3458 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003459#endif // FEATURE_WLAN_SCAN_PNO
3460 }
3461 else
3462 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003463 smsLog( pMac, LOGE, FL(" 11D channel list is empty"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003464 }
3465 csrApplyPower2Current( pMac ); // Store the channel+power info in the global place: Cfg
3466 csrSetCfgCountryCode(pMac, countryCode);
3467}
3468
3469
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003470void csrResetCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce, tANI_BOOLEAN updateRiva )
Jeff Johnson295189b2012-06-20 16:38:30 -07003471{
3472 if( fForce || (csrIs11dSupported( pMac ) && (!pMac->scan.f11dInfoReset)))
3473 {
3474
3475#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3476 {
3477 vos_log_802_11d_pkt_type *p11dLog;
3478 int Index;
3479
3480 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
3481 if(p11dLog)
3482 {
3483 p11dLog->eventId = WLAN_80211D_EVENT_RESET;
Kiet Lam64c1b492013-07-12 13:56:44 +05303484 vos_mem_copy(p11dLog->countryCode, pMac->scan.countryCodeCurrent, 3);
Jeff Johnson295189b2012-06-20 16:38:30 -07003485 p11dLog->numChannel = pMac->scan.base20MHzChannels.numChannels;
3486 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
3487 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303488 vos_mem_copy(p11dLog->Channels,
3489 pMac->scan.base20MHzChannels.channelList,
3490 p11dLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07003491 for (Index=0; Index < pMac->scan.base20MHzChannels.numChannels; Index++)
3492 {
3493 p11dLog->TxPwr[Index] = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
3494 }
3495 }
3496 if(!pMac->roam.configParam.Is11dSupportEnabled)
3497 {
3498 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
3499 }
3500 else if(pMac->roam.configParam.fEnforceDefaultDomain)
3501 {
3502 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
3503 }
3504 else
3505 {
3506 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
3507 }
3508 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
3509 }
3510 }
3511#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3512
3513 // switch to passive scans only when 11d is enabled
3514 if( csrIs11dSupported( pMac ) )
3515 {
3516 pMac->scan.curScanType = eSIR_PASSIVE_SCAN;
3517 }
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003518
3519 csrPruneChannelListForMode(pMac, &pMac->scan.baseChannels);
3520 csrPruneChannelListForMode(pMac, &pMac->scan.base20MHzChannels);
3521
Jeff Johnson295189b2012-06-20 16:38:30 -07003522 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_FALSE);
3523 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_TRUE);
3524 // ... and apply the channel list, power settings, and the country code.
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003525 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.base20MHzChannels, pMac->scan.countryCodeCurrent, updateRiva );
Jeff Johnson295189b2012-06-20 16:38:30 -07003526 // clear the 11d channel list
Kiet Lam64c1b492013-07-12 13:56:44 +05303527 vos_mem_set(&pMac->scan.channels11d, sizeof(pMac->scan.channels11d), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003528 pMac->scan.f11dInfoReset = eANI_BOOLEAN_TRUE;
3529 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_FALSE;
3530 }
3531
3532 return;
3533}
3534
3535
3536eHalStatus csrResetCountryCodeInformation(tpAniSirGlobal pMac, tANI_BOOLEAN *pfRestartNeeded)
3537{
3538 eHalStatus status = eHAL_STATUS_SUCCESS;
3539 tANI_BOOLEAN fRestart = eANI_BOOLEAN_FALSE;
3540
3541 //Use the Country code and domain from EEPROM
Kiet Lam64c1b492013-07-12 13:56:44 +05303542 vos_mem_copy(pMac->scan.countryCodeCurrent, pMac->scan.countryCodeDefault,
3543 WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07003544 csrSetRegulatoryDomain(pMac, pMac->scan.domainIdCurrent, &fRestart);
Jeff Johnson43971f52012-07-17 12:26:56 -07003545 if( ((eANI_BOOLEAN_FALSE == fRestart) || (pfRestartNeeded == NULL) )
3546 && !csrIsInfraConnected(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -07003547 {
3548 //Only reset the country info if we don't need to restart
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003549 csrResetCountryInformation(pMac, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07003550 }
3551 if(pfRestartNeeded)
3552 {
3553 *pfRestartNeeded = fRestart;
3554 }
3555
3556 return (status);
3557}
3558
3559
3560eHalStatus csrSetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pCountry, tANI_BOOLEAN *pfRestartNeeded)
3561{
3562 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
3563 v_REGDOMAIN_t domainId;
3564
3565 if(pCountry)
3566 {
Kiet Lam6c583332013-10-14 05:37:09 +05303567 status = csrGetRegulatoryDomainForCountry(pMac, pCountry, &domainId, COUNTRY_USER);
Jeff Johnson295189b2012-06-20 16:38:30 -07003568 if(HAL_STATUS_SUCCESS(status))
3569 {
3570 status = csrSetRegulatoryDomain(pMac, domainId, pfRestartNeeded);
3571 if(HAL_STATUS_SUCCESS(status))
3572 {
3573 //We don't need to check the pMac->roam.configParam.fEnforceDefaultDomain flag here,
3574 //csrSetRegulatoryDomain will fail if the country doesn't fit our domain criteria.
Kiet Lam64c1b492013-07-12 13:56:44 +05303575 vos_mem_copy(pMac->scan.countryCodeCurrent, pCountry, WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07003576 if((pfRestartNeeded == NULL) || !(*pfRestartNeeded))
3577 {
3578 //Simply set it to cfg. If we need to restart, restart will apply it to the CFG
3579 csrSetCfgCountryCode(pMac, pCountry);
3580 }
3581 }
3582 }
3583 }
3584
3585 return (status);
3586}
3587
3588
3589
3590//caller allocated memory for pNumChn and pChnPowerInfo
3591//As input, *pNumChn has the size of the array of pChnPowerInfo
3592//Upon return, *pNumChn has the number of channels assigned.
3593void csrGetChannelPowerInfo( tpAniSirGlobal pMac, tDblLinkList *pList,
3594 tANI_U32 *pNumChn, tChannelListWithPower *pChnPowerInfo)
3595{
3596 tListElem *pEntry;
3597 tANI_U32 chnIdx = 0, idx;
3598 tCsrChannelPowerInfo *pChannelSet;
3599
3600 //Get 2.4Ghz first
3601 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
3602 while( pEntry && (chnIdx < *pNumChn) )
3603 {
3604 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3605 if ( 1 != pChannelSet->interChannelOffset )
3606 {
3607 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
3608 {
3609 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
3610 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
3611 }
3612 }
3613 else
3614 {
3615 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
3616 {
3617 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + idx);
3618 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
3619 }
3620 }
3621
3622 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
3623 }
3624 *pNumChn = chnIdx;
3625
3626 return ;
3627}
3628
3629
3630
3631void csrApplyCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce )
3632{
3633 v_REGDOMAIN_t domainId;
3634 eHalStatus status = eHAL_STATUS_SUCCESS;
3635
3636 do
3637 {
3638 if( !csrIs11dSupported( pMac ) || 0 == pMac->scan.channelOf11dInfo) break;
3639 if( pMac->scan.fAmbiguous11dInfoFound )
3640 {
3641 // ambiguous info found
3642 //Restore te default domain as well
Kiet Lam6c583332013-10-14 05:37:09 +05303643 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
3644 pMac, pMac->scan.countryCodeCurrent,
3645 &domainId, COUNTRY_QUERY)))
Jeff Johnson295189b2012-06-20 16:38:30 -07003646 {
3647 pMac->scan.domainIdCurrent = domainId;
3648 }
3649 else
3650 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003651 smsLog(pMac, LOGE, FL(" failed to get domain from currentCountryCode %02X%02X"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003652 pMac->scan.countryCodeCurrent[0], pMac->scan.countryCodeCurrent[1]);
3653 }
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003654 csrResetCountryInformation( pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE );
Jeff Johnson295189b2012-06-20 16:38:30 -07003655 break;
3656 }
3657 if ( pMac->scan.f11dInfoApplied && !fForce ) break;
Kiet Lam6c583332013-10-14 05:37:09 +05303658 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
3659 pMac, pMac->scan.countryCode11d,
3660 &domainId, COUNTRY_QUERY)))
Jeff Johnson295189b2012-06-20 16:38:30 -07003661 {
3662 //Check whether we need to enforce default domain
3663 if( ( !pMac->roam.configParam.fEnforceDefaultDomain ) ||
3664 (pMac->scan.domainIdCurrent == domainId) )
3665 {
3666
3667#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3668 {
3669 vos_log_802_11d_pkt_type *p11dLog;
3670 tChannelListWithPower chnPwrInfo[WNI_CFG_VALID_CHANNEL_LIST_LEN];
3671 tANI_U32 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN, nTmp;
3672
3673 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
3674 if(p11dLog)
3675 {
3676 p11dLog->eventId = WLAN_80211D_EVENT_COUNTRY_SET;
Kiet Lam64c1b492013-07-12 13:56:44 +05303677 vos_mem_copy(p11dLog->countryCode, pMac->scan.countryCode11d, 3);
Jeff Johnson295189b2012-06-20 16:38:30 -07003678 p11dLog->numChannel = pMac->scan.channels11d.numChannels;
3679 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
3680 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303681 vos_mem_copy(p11dLog->Channels,
3682 pMac->scan.channels11d.channelList,
3683 p11dLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07003684 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList24,
3685 &nChnInfo, chnPwrInfo);
3686 nTmp = nChnInfo;
3687 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN - nTmp;
3688 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList5G,
3689 &nChnInfo, &chnPwrInfo[nTmp]);
3690 for(nTmp = 0; nTmp < p11dLog->numChannel; nTmp++)
3691 {
3692 for(nChnInfo = 0; nChnInfo < WNI_CFG_VALID_CHANNEL_LIST_LEN; nChnInfo++)
3693 {
3694 if(p11dLog->Channels[nTmp] == chnPwrInfo[nChnInfo].chanId)
3695 {
3696 p11dLog->TxPwr[nTmp] = chnPwrInfo[nChnInfo].pwr;
3697 break;
3698 }
3699 }
3700 }
3701 }
3702 if(!pMac->roam.configParam.Is11dSupportEnabled)
3703 {
3704 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
3705 }
3706 else if(pMac->roam.configParam.fEnforceDefaultDomain)
3707 {
3708 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
3709 }
3710 else
3711 {
3712 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
3713 }
3714 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
3715 }
3716 }
3717#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3718 if(pMac->scan.domainIdCurrent != domainId)
3719 {
Jeff Johnson295189b2012-06-20 16:38:30 -07003720 smsLog(pMac, LOGW, FL("Domain Changed Old %d, new %d"),
3721 pMac->scan.domainIdCurrent, domainId);
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +05303722 status = WDA_SetRegDomain(pMac, domainId);
Jeff Johnson295189b2012-06-20 16:38:30 -07003723 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003724 if (status != eHAL_STATUS_SUCCESS)
3725 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003726 smsLog( pMac, LOGE, FL(" fail to set regId %d"), domainId );
Jeff Johnson295189b2012-06-20 16:38:30 -07003727 }
3728 pMac->scan.domainIdCurrent = domainId;
Kiet Lam6c583332013-10-14 05:37:09 +05303729#ifndef CONFIG_ENABLE_LINUX_REG
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003730 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.channels11d, pMac->scan.countryCode11d, eANI_BOOLEAN_TRUE );
Kiet Lam6c583332013-10-14 05:37:09 +05303731#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07003732 // switch to active scans using this new channel list
3733 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
3734 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_TRUE;
3735 pMac->scan.f11dInfoReset = eANI_BOOLEAN_FALSE;
3736 }
3737 }
3738
3739 } while( 0 );
3740
3741 return;
3742}
3743
3744
3745
3746tANI_BOOLEAN csrSave11dCountryString( tpAniSirGlobal pMac, tANI_U8 *pCountryCode,
3747 tANI_BOOLEAN fForce)
3748{
3749 tANI_BOOLEAN fCountryStringChanged = FALSE, fUnknownCountryCode = FALSE;
3750 tANI_U32 i;
Kiet Lam6c583332013-10-14 05:37:09 +05303751 v_REGDOMAIN_t regd;
Jeff Johnson295189b2012-06-20 16:38:30 -07003752
3753 // convert to UPPER here so we are assured the strings are always in upper case.
3754 for( i = 0; i < 3; i++ )
3755 {
3756 pCountryCode[ i ] = (tANI_U8)csrToUpper( pCountryCode[ i ] );
3757 }
3758
3759 // Some of the 'old' Cisco 350 series AP's advertise NA as the country code (for North America ??).
3760 // NA is not a valid country code or domain so let's allow this by changing it to the proper
3761 // country code (which is US). We've also seen some NETGEAR AP's that have "XX " as the country code
3762 // with valid 2.4 GHz US channel information. If we cannot find the country code advertised in the
3763 // 11d information element, let's default to US.
Kiet Lam6c583332013-10-14 05:37:09 +05303764 if ( !HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(pMac,
3765 pCountryCode,
3766 &regd,
3767 COUNTRY_QUERY) ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003768 {
3769 // Check the enforcement first
3770 if( pMac->roam.configParam.fEnforceDefaultDomain || pMac->roam.configParam.fEnforceCountryCodeMatch )
3771 {
3772 fUnknownCountryCode = TRUE;
3773 }
3774 else
3775 {
Tushnim Bhattacharyya4464e1b2013-10-22 13:40:56 -07003776 pCountryCode[ 0 ] = '0';
3777 pCountryCode[ 1 ] = '0';
Jeff Johnson295189b2012-06-20 16:38:30 -07003778 }
3779 }
Tushnim Bhattacharyyac3c1e8e2013-10-29 17:27:43 -07003780 //right now, even if we don't find the CC in driver we set to world. Making
3781 //sure countryCode11d doesn't get updated with the invalid CC, instead
3782 //reflect the world CC
3783 else if (REGDOMAIN_WORLD == regd)
3784 {
3785 pCountryCode[ 0 ] = '0';
3786 pCountryCode[ 1 ] = '0';
3787 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003788
3789 // We've seen some of the AP's improperly put a 0 for the third character of the country code.
3790 // spec says valid charcters are 'O' (for outdoor), 'I' for Indoor, or ' ' (space; for either).
3791 // if we see a 0 in this third character, let's change it to a ' '.
3792 if ( 0 == pCountryCode[ 2 ] )
3793 {
3794 pCountryCode[ 2 ] = ' ';
3795 }
3796
3797 if( !fUnknownCountryCode )
3798 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303799 fCountryStringChanged = (!vos_mem_compare(pMac->scan.countryCode11d, pCountryCode, 2));
Jeff Johnson295189b2012-06-20 16:38:30 -07003800
3801
3802 if(( 0 == pMac->scan.countryCode11d[ 0 ] && 0 == pMac->scan.countryCode11d[ 1 ] )
3803 || (fForce))
3804 {
3805 // this is the first .11d information
Kiet Lam64c1b492013-07-12 13:56:44 +05303806 vos_mem_copy(pMac->scan.countryCode11d, pCountryCode,
3807 sizeof( pMac->scan.countryCode11d ));
Jeff Johnson295189b2012-06-20 16:38:30 -07003808 }
3809 }
3810
3811 return( fCountryStringChanged );
3812}
3813
3814
3815void csrSaveChannelPowerForBand( tpAniSirGlobal pMac, tANI_BOOLEAN fPopulate5GBand )
3816{
3817 tANI_U32 Index, count=0;
3818 tSirMacChanInfo *pChanInfo;
3819 tSirMacChanInfo *pChanInfoStart;
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08003820 tANI_S32 maxChannelIndex;
3821
3822 maxChannelIndex = ( pMac->scan.base20MHzChannels.numChannels < WNI_CFG_VALID_CHANNEL_LIST_LEN ) ?
3823 pMac->scan.base20MHzChannels.numChannels : WNI_CFG_VALID_CHANNEL_LIST_LEN ;
Jeff Johnson295189b2012-06-20 16:38:30 -07003824
Kiet Lam64c1b492013-07-12 13:56:44 +05303825 pChanInfo = vos_mem_malloc(sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN);
3826 if ( NULL != pChanInfo )
Jeff Johnson295189b2012-06-20 16:38:30 -07003827 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303828 vos_mem_set(pChanInfo, sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003829 pChanInfoStart = pChanInfo;
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08003830 for (Index=0; Index < maxChannelIndex; Index++)
Jeff Johnson295189b2012-06-20 16:38:30 -07003831 {
3832 if ((fPopulate5GBand && (CSR_IS_CHANNEL_5GHZ(pMac->scan.defaultPowerTable[Index].chanId))) ||
3833 (!fPopulate5GBand && (CSR_IS_CHANNEL_24GHZ(pMac->scan.defaultPowerTable[Index].chanId))) )
3834 {
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08003835 if(count >= WNI_CFG_VALID_CHANNEL_LIST_LEN)
3836 {
3837 smsLog( pMac, LOGW, FL(" csrSaveChannelPowerForBand, count exceeded, count = %d"), count);
3838 break;
3839 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003840 pChanInfo->firstChanNum = pMac->scan.defaultPowerTable[Index].chanId;
3841 pChanInfo->numChannels = 1;
3842 pChanInfo->maxTxPower = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
3843 pChanInfo++;
3844 count++;
3845 }
3846 }
3847 if(count)
3848 {
3849 csrSaveToChannelPower2G_5G( pMac, count * sizeof(tSirMacChanInfo), pChanInfoStart );
3850 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303851 vos_mem_free(pChanInfoStart);
Jeff Johnson295189b2012-06-20 16:38:30 -07003852 }
3853}
3854
3855
3856void csrSetOppositeBandChannelInfo( tpAniSirGlobal pMac )
3857{
3858 tANI_BOOLEAN fPopulate5GBand = FALSE;
3859
3860 do
3861 {
3862 // if this is not a dual band product, then we don't need to set the opposite
3863 // band info. We only work in one band so no need to look in the other band.
3864 if ( !CSR_IS_OPEARTING_DUAL_BAND( pMac ) ) break;
3865 // if we found channel info on the 5.0 band and...
3866 if ( CSR_IS_CHANNEL_5GHZ( pMac->scan.channelOf11dInfo ) )
3867 {
3868 // and the 2.4 band is empty, then populate the 2.4 channel info
Kiet Lam8d985a02013-10-11 03:39:41 +05303869 if ( !csrLLIsListEmpty( &pMac->scan.channelPowerInfoList24, LL_ACCESS_LOCK ) ) break;
Jeff Johnson295189b2012-06-20 16:38:30 -07003870 fPopulate5GBand = FALSE;
3871 }
3872 else
3873 {
3874 // else, we found channel info in the 2.4 GHz band. If the 5.0 band is empty
3875 // set the 5.0 band info from the 2.4 country code.
Kiet Lam8d985a02013-10-11 03:39:41 +05303876 if ( !csrLLIsListEmpty( &pMac->scan.channelPowerInfoList5G, LL_ACCESS_LOCK ) ) break;
Jeff Johnson295189b2012-06-20 16:38:30 -07003877 fPopulate5GBand = TRUE;
3878 }
3879 csrSaveChannelPowerForBand( pMac, fPopulate5GBand );
3880
3881 } while( 0 );
3882}
3883
3884
3885tANI_BOOLEAN csrIsSupportedChannel(tpAniSirGlobal pMac, tANI_U8 channelId)
3886{
3887 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
3888 tANI_U32 i;
3889
3890 //Make sure it is a channel that is in our supported list.
3891 for ( i = 0; i < pMac->scan.baseChannels.numChannels; i++ )
3892 {
3893 if ( channelId == pMac->scan.baseChannels.channelList[i] )
3894 {
3895 fRet = eANI_BOOLEAN_TRUE;
3896 break;
3897 }
3898 }
3899
3900 //If it is configured to limit a set of the channels
3901 if( fRet && pMac->roam.configParam.fEnforce11dChannels )
3902 {
3903 fRet = eANI_BOOLEAN_FALSE;
3904 for ( i = 0; i < pMac->scan.base20MHzChannels.numChannels; i++ )
3905 {
3906 if ( channelId == pMac->scan.base20MHzChannels.channelList[i] )
3907 {
3908 fRet = eANI_BOOLEAN_TRUE;
3909 break;
3910 }
3911 }
3912 }
3913
3914 return (fRet);
3915}
3916
3917
3918
3919//bSize specify the buffer size of pChannelList
3920tANI_U8 csrGetChannelListFromChannelSet( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 bSize, tCsrChannelPowerInfo *pChannelSet )
3921{
3922 tANI_U8 i, j = 0, chnId;
3923
3924 bSize = CSR_MIN(bSize, pChannelSet->numChannels);
3925 for( i = 0; i < bSize; i++ )
3926 {
3927 chnId = (tANI_U8)(pChannelSet->firstChannel + ( i * pChannelSet->interChannelOffset ));
3928 if ( csrIsSupportedChannel( pMac, chnId ) )
3929 {
3930 pChannelList[j++] = chnId;
3931 }
3932 }
3933
3934 return (j);
3935}
3936
3937
3938
3939//bSize -- specify the buffer size of pChannelList
3940void csrConstructCurrentValidChannelList( tpAniSirGlobal pMac, tDblLinkList *pChannelSetList,
3941 tANI_U8 *pChannelList, tANI_U8 bSize, tANI_U8 *pNumChannels )
3942{
3943 tListElem *pEntry;
3944 tCsrChannelPowerInfo *pChannelSet;
3945 tANI_U8 numChannels;
3946 tANI_U8 *pChannels;
3947
3948 if( pChannelSetList && pChannelList && pNumChannels )
3949 {
3950 pChannels = pChannelList;
3951 *pNumChannels = 0;
3952 pEntry = csrLLPeekHead( pChannelSetList, LL_ACCESS_LOCK );
3953 while( pEntry )
3954 {
3955 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3956 numChannels = csrGetChannelListFromChannelSet( pMac, pChannels, bSize, pChannelSet );
3957 pChannels += numChannels;
3958 *pNumChannels += numChannels;
3959 pEntry = csrLLNext( pChannelSetList, pEntry, LL_ACCESS_LOCK );
3960 }
3961 }
3962}
3963
3964
3965/*
3966 * 802.11D only: Gather 11d IE via beacon or Probe response and store them in pAdapter->channels11d
3967*/
3968tANI_BOOLEAN csrLearnCountryInformation( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc,
3969 tDot11fBeaconIEs *pIes, tANI_BOOLEAN fForce)
3970{
Jeff Johnson295189b2012-06-20 16:38:30 -07003971 eHalStatus status;
3972 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
3973 v_REGDOMAIN_t domainId;
3974 tDot11fBeaconIEs *pIesLocal = pIes;
3975
Jeff Johnson295189b2012-06-20 16:38:30 -07003976 if (VOS_STA_SAP_MODE == vos_get_conparam ())
3977 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07003978
3979 do
3980 {
3981 // check if .11d support is enabled
3982 if( !csrIs11dSupported( pMac ) ) break;
3983 if( !pIesLocal && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc, &pIesLocal))) )
3984 {
3985 break;
3986 }
3987 // check if country information element is present
3988 if(!pIesLocal->Country.present)
3989 {
3990 //No country info
3991 break;
3992 }
3993
3994 if( csrSave11dCountryString( pMac, pIesLocal->Country.country, fForce ) )
3995 {
3996 // country string changed, this should not happen
3997 //Need to check whether we care about this BSS' domain info
3998 //If it doesn't match of the connected profile or roaming profile, let's ignore it
3999 tANI_U32 i;
4000 tCsrRoamSession *pSession;
4001
4002 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
4003 {
4004 if( CSR_IS_SESSION_VALID( pMac, i ) )
4005 {
4006 pSession = CSR_GET_SESSION( pMac, i );
4007 if(pSession->pCurRoamProfile)
4008 {
4009 tCsrScanResultFilter filter;
4010
Kiet Lam64c1b492013-07-12 13:56:44 +05304011 vos_mem_set(&filter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004012 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, &filter);
4013 if(HAL_STATUS_SUCCESS(status))
4014 {
4015 tANI_BOOLEAN fMatch = csrMatchBSS(pMac, pSirBssDesc, &filter, NULL, NULL, NULL, NULL);
4016 //Free the resource first
4017 csrFreeScanFilter( pMac, &filter );
4018 if(fMatch)
4019 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004020 smsLog(pMac, LOGW, " Matching roam profile BSSID %02X-%02X-%02X-%02X-%02X-%02X causing ambiguous domain info",
Jeff Johnson295189b2012-06-20 16:38:30 -07004021 pSirBssDesc->bssId[0], pSirBssDesc->bssId[1], pSirBssDesc->bssId[2],
4022 pSirBssDesc->bssId[3], pSirBssDesc->bssId[4], pSirBssDesc->bssId[5]);
4023 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_TRUE;
4024 break;
4025 }
4026 }
4027 }
4028 else if( csrIsConnStateConnected(pMac, i))
4029 {
4030 //Reach here only when the currention is base on no profile.
4031 //User doesn't give profile and just connect to anything.
4032 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile, pSirBssDesc, pIesLocal))
4033 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004034 smsLog(pMac, LOGW, " Matching connect profile BSSID %02X-%02X-%02X-%02X-%02X-%02X causing ambiguous domain info",
Jeff Johnson295189b2012-06-20 16:38:30 -07004035 pSirBssDesc->bssId[0], pSirBssDesc->bssId[1], pSirBssDesc->bssId[2],
4036 pSirBssDesc->bssId[3], pSirBssDesc->bssId[4], pSirBssDesc->bssId[5]);
4037 //Tush
4038 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_TRUE;
4039 if(csrIsBssidMatch(pMac, (tCsrBssid *)&pSirBssDesc->bssId,
4040 &pSession->connectedProfile.bssid))
4041 {
4042 //AP changed the 11d info on the fly, modify cfg
4043 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
4044 fRet = eANI_BOOLEAN_TRUE;
4045 }
4046 break;
4047 }
4048 }
4049 } //valid session
4050 } //for
4051 if ( i == CSR_ROAM_SESSION_MAX )
4052 {
4053 //Check whether we can use this country's 11d information
4054 if( !pMac->roam.configParam.fEnforceDefaultDomain )
4055 {
4056 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_TRUE;
4057 }
4058 else
4059 {
4060 VOS_ASSERT( pMac->scan.domainIdCurrent == pMac->scan.domainIdDefault );
4061 if( HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
Kiet Lam6c583332013-10-14 05:37:09 +05304062 pMac, pIesLocal->Country.country, &domainId,
4063 COUNTRY_QUERY)) &&
Jeff Johnson295189b2012-06-20 16:38:30 -07004064 ( domainId == pMac->scan.domainIdCurrent ) )
4065 {
4066 //Two countries in the same domain
4067 }
4068 }
4069 }
Kiet Lam6c583332013-10-14 05:37:09 +05304070#ifdef CONFIG_ENABLE_LINUX_REG
4071 csrGetRegulatoryDomainForCountry(pMac, pIesLocal->Country.country,
4072 &domainId, COUNTRY_IE);
4073#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004074 }
4075 else //Tush
4076 {
4077 pMac->scan.fCurrent11dInfoMatch = eANI_BOOLEAN_TRUE;
4078 }
4079
4080 //In case that some channels in 5GHz have the same channel number as 2.4GHz (<= 14)
4081 if(CSR_IS_CHANNEL_5GHZ(pSirBssDesc->channelId))
4082 {
4083 tANI_U8 iC;
4084 tSirMacChanInfo* pMacChnSet = (tSirMacChanInfo *)(&pIesLocal->Country.triplets[0]);
4085
4086 for(iC = 0; iC < pIesLocal->Country.num_triplets; iC++)
4087 {
4088 if(CSR_IS_CHANNEL_24GHZ(pMacChnSet[iC].firstChanNum))
4089 {
4090 pMacChnSet[iC].firstChanNum += 200; //*** Where is this 200 defined?
4091 }
4092 }
4093 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004094 smsLog(pMac, LOG3, FL(" %d sets each one is %d"), pIesLocal->Country.num_triplets, sizeof(tSirMacChanInfo));
Jeff Johnsone7245742012-09-05 17:12:55 -07004095
Jeff Johnson295189b2012-06-20 16:38:30 -07004096 // set the indicator of the channel where the country IE was found...
4097 pMac->scan.channelOf11dInfo = pSirBssDesc->channelId;
Kiet Lam6c583332013-10-14 05:37:09 +05304098#ifndef CONFIG_ENABLE_LINUX_REG
Kiet Lam8d985a02013-10-11 03:39:41 +05304099 status = csrGetRegulatoryDomainForCountry(pMac,
Kiet Lam6c583332013-10-14 05:37:09 +05304100 pIesLocal->Country.country, &domainId, COUNTRY_IE);
Kiet Lam8d985a02013-10-11 03:39:41 +05304101 if ( status != eHAL_STATUS_SUCCESS )
4102 {
4103 smsLog( pMac, LOGE, FL(" fail to get regId %d"), domainId );
4104 fRet = eANI_BOOLEAN_FALSE;
4105 break;
4106 }
Venkata Prathyusha Kuntupalli316247e2013-03-15 17:45:25 -07004107 // Checking for Domain Id change
4108 if ( domainId != pMac->scan.domainIdCurrent )
4109 {
Kiet Lam8d985a02013-10-11 03:39:41 +05304110 vos_mem_copy(pMac->scan.countryCode11d,
4111 pIesLocal->Country.country,
4112 sizeof( pMac->scan.countryCode11d ) );
4113 /* Set Current Country code and Current Regulatory domain */
4114 status = csrSetRegulatoryDomain(pMac, domainId, NULL);
4115 if (eHAL_STATUS_SUCCESS != status)
4116 {
4117 smsLog(pMac, LOGE, "Set Reg Domain Fail %d", status);
4118 fRet = eANI_BOOLEAN_FALSE;
4119 return fRet;
4120 }
4121 //csrSetRegulatoryDomain will fail if the country doesn't fit our domain criteria.
4122 vos_mem_copy(pMac->scan.countryCodeCurrent,
4123 pIesLocal->Country.country, WNI_CFG_COUNTRY_CODE_LEN);
4124 //Simply set it to cfg.
Madan Mohan Koyyalamudi0e5922d2013-09-10 15:45:24 +05304125 csrSetCfgCountryCode(pMac, pIesLocal->Country.country);
Kiet Lam8d985a02013-10-11 03:39:41 +05304126
4127 /* overwrite the defualt country code */
4128 vos_mem_copy(pMac->scan.countryCodeDefault,
4129 pMac->scan.countryCodeCurrent,
4130 WNI_CFG_COUNTRY_CODE_LEN);
4131 /* Set Current RegDomain */
4132 status = WDA_SetRegDomain(pMac, domainId);
4133 if ( status != eHAL_STATUS_SUCCESS )
4134 {
4135 smsLog( pMac, LOGE, FL(" fail to Set regId %d"), domainId );
4136 fRet = eANI_BOOLEAN_FALSE;
4137 return fRet;
4138 }
4139 /* set to default domain ID */
Madan Mohan Koyyalamudi0e5922d2013-09-10 15:45:24 +05304140 pMac->scan.domainIdCurrent = domainId;
Kiet Lam8d985a02013-10-11 03:39:41 +05304141 /* get the channels based on new cc */
4142 status = csrInitGetChannels( pMac );
Jeff Johnson295189b2012-06-20 16:38:30 -07004143
Kiet Lam8d985a02013-10-11 03:39:41 +05304144 if ( status != eHAL_STATUS_SUCCESS )
4145 {
4146 smsLog( pMac, LOGE, FL(" fail to get Channels "));
4147 fRet = eANI_BOOLEAN_FALSE;
4148 return fRet;
4149 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004150
Kiet Lam8d985a02013-10-11 03:39:41 +05304151 /* reset info based on new cc, and we are done */
4152 csrResetCountryInformation(pMac, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
Kiet Lam8d985a02013-10-11 03:39:41 +05304153 }
Kiet Lam6c583332013-10-14 05:37:09 +05304154#endif
4155 fRet = eANI_BOOLEAN_TRUE;
4156
Jeff Johnson295189b2012-06-20 16:38:30 -07004157 } while( 0 );
4158
4159 if( !pIes && pIesLocal )
4160 {
4161 //locally allocated
Kiet Lam64c1b492013-07-12 13:56:44 +05304162 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07004163 }
4164
4165 return( fRet );
4166}
4167
4168
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004169static void csrSaveScanResults( tpAniSirGlobal pMac, tANI_U8 reason )
Jeff Johnson295189b2012-06-20 16:38:30 -07004170{
4171 // initialize this to FALSE. profMoveInterimScanResultsToMainList() routine
4172 // will set this to the channel where an .11d beacon is seen
4173 pMac->scan.channelOf11dInfo = 0;
4174 // if we get any ambiguous .11d information then this will be set to TRUE
4175 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
4176 //Tush
4177 // if we get any ambiguous .11d information, then this will be set to TRUE
4178 // only if the applied 11d info could be found in one of the scan results
4179 pMac->scan.fCurrent11dInfoMatch = eANI_BOOLEAN_FALSE;
4180 // move the scan results from interim list to the main scan list
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004181 csrMoveTempScanResultsToMainList( pMac, reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07004182
4183 // Now check if we gathered any domain/country specific information
4184 // If so, we should update channel list and apply Tx power settings
Jeff Johnsone7245742012-09-05 17:12:55 -07004185 if( csrIs11dSupported(pMac) )
4186 {
4187 csrApplyCountryInformation( pMac, FALSE );
4188 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004189}
4190
4191
4192void csrReinitScanCmd(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4193{
4194 switch (pCommand->u.scanCmd.reason)
4195 {
4196 case eCsrScanSetBGScanParam:
4197 case eCsrScanAbortBgScan:
4198 if(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList)
4199 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304200 vos_mem_free(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList);
Jeff Johnson295189b2012-06-20 16:38:30 -07004201 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
4202 }
4203 break;
4204 case eCsrScanBGScanAbort:
4205 case eCsrScanBGScanEnable:
4206 case eCsrScanGetScanChnInfo:
4207 break;
4208 case eCsrScanAbortNormalScan:
4209 default:
4210 csrScanFreeRequest(pMac, &pCommand->u.scanCmd.u.scanRequest);
4211 break;
4212 }
4213 if(pCommand->u.scanCmd.pToRoamProfile)
4214 {
4215 csrReleaseProfile(pMac, pCommand->u.scanCmd.pToRoamProfile);
Kiet Lam64c1b492013-07-12 13:56:44 +05304216 vos_mem_free(pCommand->u.scanCmd.pToRoamProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07004217 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304218 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004219}
4220
4221
4222tANI_BOOLEAN csrGetRemainingChannelsFor11dScan( tpAniSirGlobal pMac, tANI_U8 *pChannels, tANI_U8 *pcChannels )
4223{
4224 tANI_U32 index11dChannels, index;
4225 tANI_U32 indexCurrentChannels;
4226 tANI_BOOLEAN fChannelAlreadyScanned;
4227 tANI_U32 len = sizeof(pMac->roam.validChannelList);
4228
4229 *pcChannels = 0;
4230 if ( CSR_IS_11D_INFO_FOUND(pMac) && csrRoamIsChannelValid(pMac, pMac->scan.channelOf11dInfo) )
4231 {
4232 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
4233 {
4234 //Find the channel index where we found the 11d info
4235 for(index = 0; index < len; index++)
4236 {
4237 if(pMac->scan.channelOf11dInfo == pMac->roam.validChannelList[index])
4238 break;
4239 }
4240 //check whether we found the channel index
4241 if(index < len)
4242 {
4243 // Now, look through the 11d channel list and create a list of all channels in the 11d list that are
4244 // NOT in the current channel list. This gives us a list of the new channels that have not been
4245 // scanned. We'll scan this new list so we have a complete set of scan results on all of the domain channels
4246 // initially.
4247 for ( index11dChannels = 0; index11dChannels < pMac->scan.channels11d.numChannels; index11dChannels++ )
4248 {
4249 fChannelAlreadyScanned = eANI_BOOLEAN_FALSE;
4250
4251 for( indexCurrentChannels = 0; indexCurrentChannels < index; indexCurrentChannels++ )
4252 {
4253 if ( pMac->roam.validChannelList[ indexCurrentChannels ] == pMac->scan.channels11d.channelList[ index11dChannels ] )
4254 {
4255 fChannelAlreadyScanned = eANI_BOOLEAN_TRUE;
4256 break;
4257 }
4258 }
4259
4260 if ( !fChannelAlreadyScanned )
4261 {
4262 pChannels[ *pcChannels ] = pMac->scan.channels11d.channelList[ index11dChannels ];
4263 ( *pcChannels )++;
4264 }
4265 }
4266 }
4267 }//GetCFG
4268 }
4269 return( *pcChannels );
4270}
4271
4272
4273eCsrScanCompleteNextCommand csrScanGetNextCommandState( tpAniSirGlobal pMac, tSmeCmd *pCommand, tANI_BOOLEAN fSuccess )
4274{
4275 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
4276
4277 switch( pCommand->u.scanCmd.reason )
4278 {
4279 case eCsrScan11d1:
4280 NextCommand = (fSuccess) ? eCsrNext11dScan1Success : eCsrNext11dScan1Failure;
4281 break;
4282 case eCsrScan11d2:
4283 NextCommand = (fSuccess) ? eCsrNext11dScan2Success : eCsrNext11dScan2Failure;
4284 break;
4285 case eCsrScan11dDone:
4286 NextCommand = eCsrNext11dScanComplete;
4287 break;
4288 case eCsrScanLostLink1:
4289 NextCommand = (fSuccess) ? eCsrNextLostLinkScan1Success : eCsrNextLostLinkScan1Failed;
4290 break;
4291 case eCsrScanLostLink2:
4292 NextCommand = (fSuccess) ? eCsrNextLostLinkScan2Success : eCsrNextLostLinkScan2Failed;
4293 break;
4294 case eCsrScanLostLink3:
4295 NextCommand = (fSuccess) ? eCsrNextLostLinkScan3Success : eCsrNextLostLinkScan3Failed;
4296 break;
4297 case eCsrScanForSsid:
4298 NextCommand = (fSuccess) ? eCsrNexteScanForSsidSuccess : eCsrNexteScanForSsidFailure;
4299 break;
4300 case eCsrScanForCapsChange:
4301 NextCommand = eCsrNextCapChangeScanComplete; //don't care success or not
4302 break;
4303 case eCsrScanIdleScan:
4304 NextCommand = eCsrNextIdleScanComplete;
4305 break;
4306 default:
4307 NextCommand = eCsrNextScanNothing;
4308 break;
4309 }
4310 return( NextCommand );
4311}
4312
4313
4314//Return whether the pCommand is finished.
4315tANI_BOOLEAN csrHandleScan11d1Failure(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4316{
4317 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
4318
4319 //Apply back the default setting and passively scan one more time.
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004320 csrResetCountryInformation(pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07004321 pCommand->u.scanCmd.reason = eCsrScan11d2;
4322 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
4323 {
4324 fRet = eANI_BOOLEAN_FALSE;
4325 }
4326
4327 return (fRet);
4328}
4329
4330
4331tANI_BOOLEAN csrHandleScan11dSuccess(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4332{
4333 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
4334 tANI_U8 *pChannels;
4335 tANI_U8 cChannels;
4336
Kiet Lam64c1b492013-07-12 13:56:44 +05304337 pChannels = vos_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
4338 if ( NULL != pChannels )
Jeff Johnson295189b2012-06-20 16:38:30 -07004339 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304340 vos_mem_set(pChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004341 if ( csrGetRemainingChannelsFor11dScan( pMac, pChannels, &cChannels ) )
4342 {
4343 pCommand->u.scanCmd.reason = eCsrScan11dDone;
4344 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
4345 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304346 vos_mem_free(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -07004347 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004348 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304349 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(cChannels);
4350 if ( NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07004351 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304352 vos_mem_copy(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
4353 pChannels, cChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07004354 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = cChannels;
4355 pCommand->u.scanCmd.u.scanRequest.requestType = eCSR_SCAN_REQUEST_FULL_SCAN;
4356 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
4357 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
4358 {
4359 //Reuse the same command buffer
4360 fRet = eANI_BOOLEAN_FALSE;
4361 }
4362 }
4363 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304364 vos_mem_free(pChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07004365 }
4366
4367 return (fRet);
4368}
4369
4370//Return whether the command should be removed
4371tANI_BOOLEAN csrScanComplete( tpAniSirGlobal pMac, tSirSmeScanRsp *pScanRsp )
4372{
4373 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
4374 tListElem *pEntry;
4375 tSmeCmd *pCommand;
4376 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
4377 tANI_BOOLEAN fSuccess;
4378
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05304379 if (pMac->fScanOffload)
4380 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
4381 else
4382 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07004383
4384 if ( pEntry )
4385 {
4386 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
4387
4388 // If the head of the queue is Active and it is a SCAN command, remove
4389 // and put this on the Free queue.
4390 if ( eSmeCommandScan == pCommand->command )
4391 {
4392 tANI_U32 sessionId = pCommand->sessionId;
4393
4394 if(eSIR_SME_SUCCESS != pScanRsp->statusCode)
4395 {
4396 fSuccess = eANI_BOOLEAN_FALSE;
4397 }
4398 else
4399 {
4400 //pMac->scan.tempScanResults is not empty meaning the scan found something
4401 //This check only valid here because csrSaveScanresults is not yet called
4402 fSuccess = (!csrLLIsListEmpty(&pMac->scan.tempScanResults, LL_ACCESS_LOCK));
4403 }
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004404 csrSaveScanResults(pMac, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07004405
4406#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4407 {
4408 vos_log_scan_pkt_type *pScanLog = NULL;
4409 tScanResultHandle hScanResult;
4410 tCsrScanResultInfo *pScanResult;
4411 tDot11fBeaconIEs *pIes;
4412 int n = 0, c = 0;
4413
4414 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
4415 if(pScanLog)
4416 {
4417 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
4418 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
4419 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
4420 {
4421 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_RSP;
4422 }
4423 else
4424 {
4425 if( eSIR_PASSIVE_SCAN != pMac->scan.curScanType )
4426 {
4427 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_RSP;
4428 }
4429 else
4430 {
4431 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_RSP;
4432 }
4433 }
4434 if(eSIR_SME_SUCCESS == pScanRsp->statusCode)
4435 {
4436 if(HAL_STATUS_SUCCESS(csrScanGetResult(pMac, NULL, &hScanResult)))
4437 {
4438 while(((pScanResult = csrScanResultGetNext(pMac, hScanResult)) != NULL))
4439 {
4440 if( n < VOS_LOG_MAX_NUM_BSSID )
4441 {
4442 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pScanResult->BssDescriptor, &pIes)))
4443 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004444 smsLog(pMac, LOGE, FL(" fail to parse IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07004445 break;
4446 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304447 vos_mem_copy(pScanLog->bssid[n],
4448 pScanResult->BssDescriptor.bssId, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07004449 if(pIes && pIes->SSID.present && VOS_LOG_MAX_SSID_SIZE >= pIes->SSID.num_ssid)
4450 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304451 vos_mem_copy(pScanLog->ssid[n],
4452 pIes->SSID.ssid, pIes->SSID.num_ssid);
Jeff Johnson295189b2012-06-20 16:38:30 -07004453 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304454 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07004455 n++;
4456 }
4457 c++;
4458 }
4459 pScanLog->numSsid = (v_U8_t)n;
4460 pScanLog->totalSsid = (v_U8_t)c;
4461 csrScanResultPurge(pMac, hScanResult);
4462 }
4463 }
4464 else
4465 {
4466 pScanLog->status = WLAN_SCAN_STATUS_FAILURE;
4467 }
4468 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
4469 }
4470 }
4471#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4472
4473 NextCommand = csrScanGetNextCommandState(pMac, pCommand, fSuccess);
4474 //We reuse the command here instead reissue a new command
4475 switch(NextCommand)
4476 {
4477 case eCsrNext11dScan1Success:
4478 case eCsrNext11dScan2Success:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004479 smsLog( pMac, LOG2, FL("11dScan1/3 produced results. Reissue Active scan..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004480 // if we found country information, no need to continue scanning further, bail out
4481 fRemoveCommand = eANI_BOOLEAN_TRUE;
4482 NextCommand = eCsrNext11dScanComplete;
4483 break;
4484 case eCsrNext11dScan1Failure:
4485 //We are not done yet. 11d scan fail once. We will try to reset anything and do it over again
4486 //The only meaningful thing for this retry is that we cannot find 11d information after a reset so
4487 //we clear the "old" 11d info and give it once more chance
4488 fRemoveCommand = csrHandleScan11d1Failure(pMac, pCommand);
4489 if(fRemoveCommand)
4490 {
4491 NextCommand = eCsrNext11dScanComplete;
4492 }
4493 break;
4494 case eCsrNextLostLinkScan1Success:
4495 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink1)))
4496 {
4497 csrScanHandleFailedLostlink1(pMac, sessionId);
4498 }
4499 break;
4500 case eCsrNextLostLinkScan2Success:
4501 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink2)))
4502 {
4503 csrScanHandleFailedLostlink2(pMac, sessionId);
4504 }
4505 break;
4506 case eCsrNextLostLinkScan3Success:
4507 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink3)))
4508 {
4509 csrScanHandleFailedLostlink3(pMac, sessionId);
4510 }
4511 break;
4512 case eCsrNextLostLinkScan1Failed:
4513 csrScanHandleFailedLostlink1(pMac, sessionId);
4514 break;
4515 case eCsrNextLostLinkScan2Failed:
4516 csrScanHandleFailedLostlink2(pMac, sessionId);
4517 break;
4518 case eCsrNextLostLinkScan3Failed:
4519 csrScanHandleFailedLostlink3(pMac, sessionId);
4520 break;
4521 case eCsrNexteScanForSsidSuccess:
4522 csrScanHandleSearchForSSID(pMac, pCommand);
4523 break;
4524 case eCsrNexteScanForSsidFailure:
4525 csrScanHandleSearchForSSIDFailure(pMac, pCommand);
4526 break;
4527 case eCsrNextIdleScanComplete:
4528 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
4529 break;
4530 case eCsrNextCapChangeScanComplete:
4531 csrScanHandleCapChangeScanComplete(pMac, sessionId);
4532 break;
4533 default:
4534
4535 break;
4536 }
4537 }
4538 else
4539 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004540 smsLog( pMac, LOGW, FL("Scan Completion called but SCAN command is not ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004541 fRemoveCommand = eANI_BOOLEAN_FALSE;
4542 }
4543 }
4544 else
4545 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004546 smsLog( pMac, LOGW, FL("Scan Completion called but NO commands are ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004547 fRemoveCommand = eANI_BOOLEAN_FALSE;
4548 }
4549
4550 return( fRemoveCommand );
4551}
4552
4553
4554
4555static void csrScanRemoveDupBssDescriptionFromInterimList( tpAniSirGlobal pMac,
4556 tSirBssDescription *pSirBssDescr,
4557 tDot11fBeaconIEs *pIes)
4558{
4559 tListElem *pEntry;
4560 tCsrScanResult *pCsrBssDescription;
4561
4562 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
4563 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
4564 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
4565 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
4566 while( pEntry )
4567 {
4568 pCsrBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
4569
4570 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
4571 // matches
4572
4573 if ( csrIsDuplicateBssDescription( pMac, &pCsrBssDescription->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07004574 pSirBssDescr, pIes, FALSE ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07004575 {
4576 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
4577 ((tANI_S32)pCsrBssDescription->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
4578
4579 // Remove the 'old' entry from the list....
4580 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK ) )
4581 {
4582 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pCsrBssDescription->Result.BssDescriptor);
4583 // we need to free the memory associated with this node
4584 csrFreeScanResultEntry( pMac, pCsrBssDescription );
4585 }
4586
4587 // If we found a match, we can stop looking through the list.
4588 break;
4589 }
4590
4591 pEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK );
4592 }
4593}
4594
4595
4596
4597//Caller allocated memory pfNewBssForConn to return whether new candidate for
4598//current connection is found. Cannot be NULL
4599tCsrScanResult *csrScanSaveBssDescriptionToInterimList( tpAniSirGlobal pMac,
4600 tSirBssDescription *pBSSDescription,
4601 tDot11fBeaconIEs *pIes)
4602{
4603 tCsrScanResult *pCsrBssDescription = NULL;
4604 tANI_U32 cbBSSDesc;
4605 tANI_U32 cbAllocated;
Jeff Johnson295189b2012-06-20 16:38:30 -07004606
4607 // figure out how big the BSS description is (the BSSDesc->length does NOT
4608 // include the size of the length field itself).
4609 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
4610
4611 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
4612
Kiet Lam64c1b492013-07-12 13:56:44 +05304613 pCsrBssDescription = vos_mem_malloc(cbAllocated);
4614 if ( NULL != pCsrBssDescription )
Jeff Johnson295189b2012-06-20 16:38:30 -07004615 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304616 vos_mem_set(pCsrBssDescription, cbAllocated, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004617 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Kiet Lam64c1b492013-07-12 13:56:44 +05304618 vos_mem_copy(&pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc );
Jeff Johnson295189b2012-06-20 16:38:30 -07004619 //Save SSID separately for later use
4620 if( pIes->SSID.present && !csrIsNULLSSID(pIes->SSID.ssid, pIes->SSID.num_ssid) )
4621 {
4622 //SSID not hidden
Madan Mohan Koyyalamudi4e31b132012-11-02 13:13:52 -07004623 tANI_U32 len = pIes->SSID.num_ssid;
Jeff Johnson295189b2012-06-20 16:38:30 -07004624 if (len > SIR_MAC_MAX_SSID_LENGTH)
4625 {
4626 // truncate to fit in our struct
4627 len = SIR_MAC_MAX_SSID_LENGTH;
4628 }
4629 pCsrBssDescription->Result.ssId.length = len;
4630 pCsrBssDescription->Result.timer = vos_timer_get_system_time();
Kiet Lam64c1b492013-07-12 13:56:44 +05304631 vos_mem_copy(pCsrBssDescription->Result.ssId.ssId, pIes->SSID.ssid, len);
Jeff Johnson295189b2012-06-20 16:38:30 -07004632 }
4633 csrLLInsertTail( &pMac->scan.tempScanResults, &pCsrBssDescription->Link, LL_ACCESS_LOCK );
4634 }
4635
4636 return( pCsrBssDescription );
4637}
4638
4639
4640
4641
4642tANI_BOOLEAN csrIsDuplicateBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc1,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07004643 tSirBssDescription *pSirBssDesc2, tDot11fBeaconIEs *pIes2, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07004644{
4645 tANI_BOOLEAN fMatch = FALSE;
4646 tSirMacCapabilityInfo *pCap1, *pCap2;
4647 tDot11fBeaconIEs *pIes1 = NULL;
Jeff Johnsone7245742012-09-05 17:12:55 -07004648 tDot11fBeaconIEs *pIesTemp = pIes2;
Jeff Johnson295189b2012-06-20 16:38:30 -07004649
4650 pCap1 = (tSirMacCapabilityInfo *)&pSirBssDesc1->capabilityInfo;
4651 pCap2 = (tSirMacCapabilityInfo *)&pSirBssDesc2->capabilityInfo;
4652 if(pCap1->ess == pCap2->ess)
4653 {
4654 if (pCap1->ess &&
Jeff Johnsone7245742012-09-05 17:12:55 -07004655 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId)&&
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07004656 (fForced || (pSirBssDesc1->channelId == pSirBssDesc2->channelId)))
Jeff Johnson295189b2012-06-20 16:38:30 -07004657 {
4658 fMatch = TRUE;
Jeff Johnsone7245742012-09-05 17:12:55 -07004659 // Check for SSID match, if exists
4660 do
4661 {
4662 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
4663 {
4664 break;
4665 }
4666 if( NULL == pIesTemp )
4667 {
4668 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
4669 {
4670 break;
4671 }
4672 }
4673 if(pIes1->SSID.present && pIesTemp->SSID.present)
4674 {
4675 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
4676 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
4677 }
4678 }while(0);
4679
Jeff Johnson295189b2012-06-20 16:38:30 -07004680 }
4681 else if (pCap1->ibss && (pSirBssDesc1->channelId == pSirBssDesc2->channelId))
4682 {
Jeff Johnson295189b2012-06-20 16:38:30 -07004683
4684 do
4685 {
4686 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
4687 {
4688 break;
4689 }
4690 if( NULL == pIesTemp )
4691 {
4692 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
4693 {
4694 break;
4695 }
4696 }
4697 //Same channel cannot have same SSID for different IBSS
4698 if(pIes1->SSID.present && pIesTemp->SSID.present)
4699 {
4700 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
4701 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
4702 }
4703 }while(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004704 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004705 /* In case of P2P devices, ess and ibss will be set to zero */
4706 else if (!pCap1->ess &&
4707 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId))
4708 {
4709 fMatch = TRUE;
4710 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004711 }
4712
4713 if(pIes1)
4714 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304715 vos_mem_free(pIes1);
Jeff Johnson295189b2012-06-20 16:38:30 -07004716 }
Jeff Johnsone7245742012-09-05 17:12:55 -07004717
4718 if( (NULL == pIes2) && pIesTemp )
4719 {
4720 //locally allocated
Kiet Lam64c1b492013-07-12 13:56:44 +05304721 vos_mem_free(pIesTemp);
Jeff Johnsone7245742012-09-05 17:12:55 -07004722 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004723
4724 return( fMatch );
4725}
4726
4727
4728tANI_BOOLEAN csrIsNetworkTypeEqual( tSirBssDescription *pSirBssDesc1, tSirBssDescription *pSirBssDesc2 )
4729{
4730 return( pSirBssDesc1->nwType == pSirBssDesc2->nwType );
4731}
4732
4733
4734//to check whether the BSS matches the dot11Mode
4735static tANI_BOOLEAN csrScanIsBssAllowed(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
4736 tDot11fBeaconIEs *pIes)
4737{
4738 tANI_BOOLEAN fAllowed = eANI_BOOLEAN_FALSE;
4739 eCsrPhyMode phyMode;
4740
4741 if(HAL_STATUS_SUCCESS(csrGetPhyModeFromBss(pMac, pBssDesc, &phyMode, pIes)))
4742 {
4743 switch(pMac->roam.configParam.phyMode)
4744 {
4745 case eCSR_DOT11_MODE_11b:
4746 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
4747 break;
4748 case eCSR_DOT11_MODE_11g:
4749 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
4750 break;
4751 case eCSR_DOT11_MODE_11g_ONLY:
4752 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11g == phyMode);
4753 break;
4754 case eCSR_DOT11_MODE_11a:
4755 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11b != phyMode) && (eCSR_DOT11_MODE_11g != phyMode));
4756 break;
4757 case eCSR_DOT11_MODE_11n_ONLY:
4758 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11n == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
4759 break;
Jeff Johnsone7245742012-09-05 17:12:55 -07004760
4761#ifdef WLAN_FEATURE_11AC
4762 case eCSR_DOT11_MODE_11ac_ONLY:
4763 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11ac == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
4764 break;
4765#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004766 case eCSR_DOT11_MODE_11b_ONLY:
4767 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11b == phyMode);
4768 break;
4769 case eCSR_DOT11_MODE_11a_ONLY:
4770 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a == phyMode);
4771 break;
4772 case eCSR_DOT11_MODE_11n:
Jeff Johnsone7245742012-09-05 17:12:55 -07004773#ifdef WLAN_FEATURE_11AC
4774 case eCSR_DOT11_MODE_11ac:
4775#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004776 case eCSR_DOT11_MODE_TAURUS:
4777 default:
4778 fAllowed = eANI_BOOLEAN_TRUE;
4779 break;
4780 }
4781 }
4782
4783 return (fAllowed);
4784}
4785
4786
4787
4788//Return pIes to caller for future use when returning TRUE.
4789static tANI_BOOLEAN csrScanValidateScanResult( tpAniSirGlobal pMac, tANI_U8 *pChannels,
4790 tANI_U8 numChn, tSirBssDescription *pBssDesc,
4791 tDot11fBeaconIEs **ppIes )
4792{
4793 tANI_BOOLEAN fValidChannel = FALSE;
4794 tDot11fBeaconIEs *pIes = NULL;
4795 tANI_U8 index;
4796
4797 for( index = 0; index < numChn; index++ )
4798 {
4799 // This check relies on the fact that a single BSS description is returned in each
4800 // ScanRsp call, which is the way LIM implemented the scan req/rsp funtions. We changed
4801 // to this model when we ran with a large number of APs. If this were to change, then
4802 // this check would have to mess with removing the bssDescription from somewhere in an
4803 // arbitrary index in the bssDescription array.
4804 if ( pChannels[ index ] == pBssDesc->channelId )
4805 {
4806 fValidChannel = TRUE;
4807 break;
4808 }
4809 }
4810 *ppIes = NULL;
4811 if(fValidChannel)
4812 {
4813 if( HAL_STATUS_SUCCESS( csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIes) ) )
4814 {
4815 fValidChannel = csrScanIsBssAllowed(pMac, pBssDesc, pIes);
4816 if( fValidChannel )
4817 {
4818 *ppIes = pIes;
4819 }
4820 else
4821 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304822 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07004823 }
4824 }
4825 else
4826 {
4827 fValidChannel = FALSE;
4828 }
4829 }
4830
4831 return( fValidChannel );
4832}
4833
4834
4835//Return whether last scan result is received
4836static tANI_BOOLEAN csrScanProcessScanResults( tpAniSirGlobal pMac, tSmeCmd *pCommand,
4837 tSirSmeScanRsp *pScanRsp, tANI_BOOLEAN *pfRemoveCommand )
4838{
4839 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE, fRemoveCommand = eANI_BOOLEAN_FALSE;
4840 tDot11fBeaconIEs *pIes = NULL;
4841 tANI_U32 cbParsed;
4842 tSirBssDescription *pSirBssDescription;
4843 tANI_U32 cbBssDesc;
4844 tANI_U32 cbScanResult = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription )
4845 + sizeof(tSirBssDescription); //We need at least one CB
4846
4847 // don't consider the scan rsp to be valid if the status code is Scan Failure. Scan Failure
4848 // is returned when the scan could not find anything. so if we get scan failure return that
4849 // the scan response is invalid. Also check the lenght in the scan result for valid scan
4850 // BssDescriptions....
4851 do
4852 {
4853 if ( ( cbScanResult <= pScanRsp->length ) &&
4854 (( eSIR_SME_SUCCESS == pScanRsp->statusCode ) ||
4855 ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW == pScanRsp->statusCode ) ) )
4856 {
4857 tANI_U8 *pChannelList = NULL;
4858 tANI_U8 cChannels = 0;
4859
4860 //Different scan type can reach this point, we need to distinguish it
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004861#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
4862 if( eCsrScanGetLfrResult == pCommand->u.scanCmd.reason )
4863 {
4864 pChannelList = NULL;
4865 cChannels = 0;
4866 }
4867 else
4868#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004869 if( eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason )
4870 {
4871 //eCsrScanSetBGScanParam uses different structure
4872 tCsrBGScanRequest *pBgScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
4873
4874 cChannels = pBgScanReq->ChannelInfo.numOfChannels;
4875 pChannelList = pBgScanReq->ChannelInfo.ChannelList;
4876 }
4877 else
4878 {
4879 //the rest use generic scan request
4880 cChannels = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
4881 pChannelList = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
4882 }
4883
4884 // if the scan result is not on one of the channels in the Valid channel list, then it
4885 // must have come from an AP on an overlapping channel (in the 2.4GHz band). In this case,
4886 // let's drop the scan result.
4887 //
4888 // The other situation is where the scan request is for a scan on a particular channel set
4889 // and the scan result is from a
4890
4891 // if the NumChannels is 0, then we are supposed to be scanning all channels. Use the full channel
4892 // list as the 'valid' channel list. Otherwise, use the specific channel list in the scan parms
4893 // as the valid channels.
4894 if ( 0 == cChannels )
4895 {
4896 tANI_U32 len = sizeof(pMac->roam.validChannelList);
4897
4898 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
4899 {
4900 pChannelList = pMac->roam.validChannelList;
4901 cChannels = (tANI_U8)len;
4902 }
4903 else
4904 {
4905 //Cannot continue
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004906 smsLog( pMac, LOGE, "CSR: Processing internal SCAN results...csrGetCfgValidChannels failed" );
Jeff Johnson295189b2012-06-20 16:38:30 -07004907 break;
4908 }
4909 }
4910
4911 smsLog( pMac, LOG2, "CSR: Processing internal SCAN results..." );
4912 cbParsed = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription );
4913 pSirBssDescription = pScanRsp->bssDescription;
4914 while( cbParsed < pScanRsp->length )
4915 {
4916 if ( csrScanValidateScanResult( pMac, pChannelList, cChannels, pSirBssDescription, &pIes ) )
4917 {
4918 csrScanRemoveDupBssDescriptionFromInterimList(pMac, pSirBssDescription, pIes);
4919 csrScanSaveBssDescriptionToInterimList( pMac, pSirBssDescription, pIes );
4920 if( eSIR_PASSIVE_SCAN == pMac->scan.curScanType )
4921 {
4922 if( csrIs11dSupported( pMac) )
4923 {
4924 //Check whether the BSS is acceptable base on 11d info and our configs.
4925 if( csrMatchCountryCode( pMac, NULL, pIes ) )
4926 {
4927 //Double check whether the channel is acceptable by us.
4928 if( csrIsSupportedChannel( pMac, pSirBssDescription->channelId ) )
4929 {
4930 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
4931 }
4932 }
4933 }
4934 else
4935 {
4936 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
4937 }
4938 }
4939 //Free the resource
Kiet Lam64c1b492013-07-12 13:56:44 +05304940 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07004941 }
4942 // skip over the BSS description to the next one...
4943 cbBssDesc = pSirBssDescription->length + sizeof( pSirBssDescription->length );
4944
4945 cbParsed += cbBssDesc;
4946 pSirBssDescription = (tSirBssDescription *)((tANI_U8 *)pSirBssDescription + cbBssDesc );
4947
4948 } //while
4949 }
4950 else
4951 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004952 smsLog( pMac, LOGW, " Scanrsp fail (0x%08X), length = %d (expected %d)",
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08004953 pScanRsp->statusCode, pScanRsp->length, cbScanResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07004954 //HO bg scan/probe failed no need to try autonomously
4955 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
4956 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004957#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
4958 eCsrScanGetLfrResult == pCommand->u.scanCmd.reason ||
4959#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004960 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
4961 {
4962 fRemoveCommand = eANI_BOOLEAN_TRUE;
4963 }
4964 }
4965 }while(0);
4966 if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
4967 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004968 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 -07004969 fRemoveCommand = csrScanComplete( pMac, pScanRsp );
4970 fRet = eANI_BOOLEAN_TRUE;
4971 }//if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
4972 if(pfRemoveCommand)
4973 {
4974 *pfRemoveCommand = fRemoveCommand;
4975 }
4976
4977#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05304978 if (pMac->fScanOffload)
4979 return fRet;
4980
Jeff Johnson295189b2012-06-20 16:38:30 -07004981 if (!csrLLIsListEmpty( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK ))
4982 {
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08004983 /* Pending scan commands in the list because the previous scan command
4984 * was split into a scan command on one channel + a scan command for all
4985 * remaining channels.
4986 *
4987 * Start timer to trigger processing of the next scan command.
Srikant Kuppa866893f2012-12-27 17:28:14 -08004988 * NOTE for LFR:
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05304989 * Do not split scans if no concurrent infra connections are
Srikant Kuppa866893f2012-12-27 17:28:14 -08004990 * active and if the scan is a BG scan triggered by LFR (OR)
4991 * any scan if LFR is in the middle of a BG scan. Splitting
4992 * the scan is delaying the time it takes for LFR to find
4993 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08004994 */
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05304995 if ( (csrIsStaSessionConnected(pMac) &&
Srikant Kuppa866893f2012-12-27 17:28:14 -08004996#ifdef FEATURE_WLAN_LFR
4997 (csrIsConcurrentInfraConnected(pMac) ||
4998 ((pCommand->u.scanCmd.reason != eCsrScanBgScan) &&
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05304999 (pMac->roam.neighborRoamInfo.neighborRoamState !=
Srikant Kuppa866893f2012-12-27 17:28:14 -08005000 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
5001#endif
5002 (pCommand->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305003 (csrIsP2pSessionConnected(pMac)) )
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08005004 {
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005005 /* if active connected sessions present then continue to split scan
5006 * with specified interval between consecutive scans */
5007 csrSetDefaultScanTiming(pMac, pCommand->u.scanCmd.u.scanRequest.scanType, &(pCommand->u.scanCmd.u.scanRequest));
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05305008 vos_timer_start(&pMac->scan.hTimerStaApConcTimer,
5009 pCommand->u.scanCmd.u.scanRequest.restTime);
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005010 } else {
5011 /* if no connected sessions present then initiate next scan command immediately */
5012 /* minimum timer granularity is 10ms */
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05305013 vos_timer_start(&pMac->scan.hTimerStaApConcTimer, 10);
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08005014 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005015 }
5016#endif
5017 return (fRet);
5018}
5019
5020
5021tANI_BOOLEAN csrScanIsWildCardScan( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5022{
5023 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
Kiet Lam64c1b492013-07-12 13:56:44 +05305024 tANI_BOOLEAN f = vos_mem_compare(pCommand->u.scanCmd.u.scanRequest.bssid,
5025 bssid, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07005026
5027 //It is not a wild card scan if the bssid is not broadcast and the number of SSID is 1.
5028 return ((tANI_BOOLEAN)( (f || (0xff == pCommand->u.scanCmd.u.scanRequest.bssid[0])) &&
5029 (pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs != 1) ));
5030}
5031
5032
5033eHalStatus csrScanSmeScanResponse( tpAniSirGlobal pMac, void *pMsgBuf )
5034{
5035 eHalStatus status = eHAL_STATUS_SUCCESS;
5036 tListElem *pEntry;
5037 tSmeCmd *pCommand;
5038 eCsrScanStatus scanStatus;
5039 tSirSmeScanRsp *pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
5040 tSmeGetScanChnRsp *pScanChnInfo;
5041 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
5042 eCsrScanReason reason = eCsrScanOther;
5043
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305044 if (pMac->fScanOffload)
5045 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList,
5046 LL_ACCESS_LOCK);
5047 else
5048 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07005049
5050 if ( pEntry )
5051 {
5052 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
5053 if ( eSmeCommandScan == pCommand->command )
5054 {
5055 scanStatus = (eSIR_SME_SUCCESS == pScanRsp->statusCode) ? eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
5056 reason = pCommand->u.scanCmd.reason;
5057 switch(pCommand->u.scanCmd.reason)
5058 {
5059 case eCsrScanAbortBgScan:
5060 case eCsrScanAbortNormalScan:
5061 case eCsrScanBGScanAbort:
5062 case eCsrScanBGScanEnable:
5063 break;
5064 case eCsrScanGetScanChnInfo:
5065 pScanChnInfo = (tSmeGetScanChnRsp *)pMsgBuf;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005066 /*
5067 * status code not available in tSmeGetScanChnRsp, so
5068 * by default considereing it to be success
5069 */
5070 scanStatus = eSIR_SME_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07005071 csrScanAgeResults(pMac, pScanChnInfo);
5072 break;
5073 case eCsrScanForCapsChange:
5074 csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand );
5075 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005076 case eCsrScanP2PFindPeer:
5077 scanStatus = ((eSIR_SME_SUCCESS == pScanRsp->statusCode) && (pScanRsp->length > 50)) ? eCSR_SCAN_FOUND_PEER : eCSR_SCAN_FAILURE;
5078 csrScanProcessScanResults( pMac, pCommand, pScanRsp, NULL );
5079 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005080 case eCsrScanSetBGScanParam:
5081 default:
5082 if(csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand ))
5083 {
5084 //Not to get channel info if the scan is not a wildcard scan because
5085 //it may cause scan results got aged out incorrectly.
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005086 if( csrScanIsWildCardScan( pMac, pCommand ) && (!pCommand->u.scanCmd.u.scanRequest.p2pSearch)
5087#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5088 && (pCommand->u.scanCmd.reason != eCsrScanGetLfrResult)
5089#endif
5090 )
Jeff Johnson295189b2012-06-20 16:38:30 -07005091 {
5092 //Get the list of channels scanned
Jeff Johnson32d95a32012-09-10 13:15:23 -07005093 if( pCommand->u.scanCmd.reason != eCsrScanUserRequest)
5094 {
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05305095 csrScanGetScanChnInfo(pMac, pCommand->sessionId,
5096 NULL, NULL);
Jeff Johnson32d95a32012-09-10 13:15:23 -07005097 }
5098 else
5099 {
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05305100 csrScanGetScanChnInfo(pMac,
5101 pCommand->sessionId,
5102 pCommand->u.scanCmd.pContext,
5103 pCommand->u.scanCmd.callback);
Jeff Johnson32d95a32012-09-10 13:15:23 -07005104 pCommand->u.scanCmd.callback = NULL;
5105 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005106 }
5107 }
5108 break;
5109 }//switch
5110 if(fRemoveCommand)
5111 {
5112
5113 csrReleaseScanCommand(pMac, pCommand, scanStatus);
5114
Srikant Kuppa866893f2012-12-27 17:28:14 -08005115 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005116 smeProcessPendingQueue( pMac );
5117 }
5118 else
5119 {
5120 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
5121 status = eHAL_STATUS_FAILURE;
5122 }
5123 }
5124 else
5125 {
5126 smsLog( pMac, LOGW, "CSR: Scan Completion called but NO commands are ACTIVE ..." );
5127 status = eHAL_STATUS_FAILURE;
5128 }
5129
5130 return (status);
5131}
5132
5133
5134
5135
5136tCsrScanResultInfo *csrScanResultGetFirst(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
5137{
5138 tListElem *pEntry;
5139 tCsrScanResult *pResult;
5140 tCsrScanResultInfo *pRet = NULL;
5141 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5142
5143 if(pResultList)
5144 {
5145 csrLLLock(&pResultList->List);
5146 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5147 if(pEntry)
5148 {
5149 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
5150 pRet = &pResult->Result;
5151 }
5152 pResultList->pCurEntry = pEntry;
5153 csrLLUnlock(&pResultList->List);
5154 }
5155
5156 return pRet;
5157}
5158
5159
5160tCsrScanResultInfo *csrScanResultGetNext(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
5161{
5162 tListElem *pEntry = NULL;
5163 tCsrScanResult *pResult = NULL;
5164 tCsrScanResultInfo *pRet = NULL;
5165 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5166
5167 if(pResultList)
5168 {
5169 csrLLLock(&pResultList->List);
5170 if(NULL == pResultList->pCurEntry)
5171 {
5172 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5173 }
5174 else
5175 {
5176 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
5177 }
5178 if(pEntry)
5179 {
5180 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
5181 pRet = &pResult->Result;
5182 }
5183 pResultList->pCurEntry = pEntry;
5184 csrLLUnlock(&pResultList->List);
5185 }
5186
5187 return pRet;
5188}
5189
5190
5191//This function moves the first BSS that matches the bssid to the head of the result
5192eHalStatus csrMoveBssToHeadFromBSSID(tpAniSirGlobal pMac, tCsrBssid *bssid, tScanResultHandle hScanResult)
5193{
5194 eHalStatus status = eHAL_STATUS_FAILURE;
5195 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5196 tCsrScanResult *pResult = NULL;
5197 tListElem *pEntry = NULL;
5198
5199 if(pResultList && bssid)
5200 {
5201 csrLLLock(&pResultList->List);
5202 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5203 while(pEntry)
5204 {
5205 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
Kiet Lam64c1b492013-07-12 13:56:44 +05305206 if (vos_mem_compare(bssid, pResult->Result.BssDescriptor.bssId, sizeof(tCsrBssid)))
Jeff Johnson295189b2012-06-20 16:38:30 -07005207 {
5208 status = eHAL_STATUS_SUCCESS;
5209 csrLLRemoveEntry(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
5210 csrLLInsertHead(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
5211 break;
5212 }
5213 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
5214 }
5215 csrLLUnlock(&pResultList->List);
5216 }
5217
5218 return (status);
5219}
5220
5221
5222//Remove the BSS if possible.
5223//Return -- TRUE == the BSS is remove. False == Fail to remove it
5224//This function is called when list lock is held. Be caution what functions it can call.
5225tANI_BOOLEAN csrScanAgeOutBss(tpAniSirGlobal pMac, tCsrScanResult *pResult)
5226{
5227 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
5228 tANI_U32 i;
5229 tCsrRoamSession *pSession;
5230
5231 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5232 {
5233 if( CSR_IS_SESSION_VALID( pMac, i ) )
5234 {
5235 pSession = CSR_GET_SESSION( pMac, i );
5236 //Not to remove the BSS we are connected to.
5237 if(csrIsConnStateDisconnected(pMac, i) || (NULL == pSession->pConnectBssDesc) ||
5238 (!csrIsDuplicateBssDescription(pMac, &pResult->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07005239 pSession->pConnectBssDesc, NULL, FALSE))
Jeff Johnson295189b2012-06-20 16:38:30 -07005240 )
5241 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005242 smsLog(pMac, LOGW, "Aging out BSS %02X-%02X-%02X-%02X-%02X-%02X Channel %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005243 pResult->Result.BssDescriptor.bssId[0],
5244 pResult->Result.BssDescriptor.bssId[1],
5245 pResult->Result.BssDescriptor.bssId[2],
5246 pResult->Result.BssDescriptor.bssId[3],
5247 pResult->Result.BssDescriptor.bssId[4],
5248 pResult->Result.BssDescriptor.bssId[5],
5249 pResult->Result.BssDescriptor.channelId);
5250 //No need to hold the spin lock because caller should hold the lock for pMac->scan.scanResultList
5251 if( csrLLRemoveEntry(&pMac->scan.scanResultList, &pResult->Link, LL_ACCESS_NOLOCK) )
5252 {
5253 csrFreeScanResultEntry(pMac, pResult);
Madan Mohan Koyyalamudi2e068bc2012-10-22 14:58:47 -07005254 fRet = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005255 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005256 break;
5257 }
5258 } //valid session
5259 } //for
Madan Mohan Koyyalamudi2e068bc2012-10-22 14:58:47 -07005260 if( CSR_ROAM_SESSION_MAX == i && fRet != eANI_BOOLEAN_TRUE )
Jeff Johnson295189b2012-06-20 16:38:30 -07005261 {
5262 //reset the counter so this won't hapeen too soon
5263 pResult->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
5264 pResult->Result.BssDescriptor.nReceivedTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
5265 }
5266
5267 return (fRet);
5268}
5269
5270
5271eHalStatus csrScanAgeResults(tpAniSirGlobal pMac, tSmeGetScanChnRsp *pScanChnInfo)
5272{
5273 eHalStatus status = eHAL_STATUS_SUCCESS;
5274 tListElem *pEntry, *tmpEntry;
5275 tCsrScanResult *pResult;
5276 tLimScanChn *pChnInfo;
5277 tANI_U8 i;
5278
5279 csrLLLock(&pMac->scan.scanResultList);
5280 for(i = 0; i < pScanChnInfo->numChn; i++)
5281 {
5282 pChnInfo = &pScanChnInfo->scanChn[i];
5283 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
5284 while( pEntry )
5285 {
5286 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
5287 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
5288 if(pResult->Result.BssDescriptor.channelId == pChnInfo->channelId)
5289 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005290 if(pResult->AgingCount <= 0)
5291 {
5292 smsLog(pMac, LOGW, " age out due to ref count");
5293 csrScanAgeOutBss(pMac, pResult);
5294 }
Madan Mohan Koyyalamudib9d3dcc2012-09-28 16:47:50 -07005295 else
5296 {
5297 pResult->AgingCount--;
5298 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005299 }
5300 pEntry = tmpEntry;
5301 }
5302 }
5303 csrLLUnlock(&pMac->scan.scanResultList);
5304
5305 return (status);
5306}
5307
5308
5309eHalStatus csrSendMBScanReq( tpAniSirGlobal pMac, tANI_U16 sessionId,
5310 tCsrScanRequest *pScanReq, tScanReqParam *pScanReqParam )
5311{
5312 eHalStatus status = eHAL_STATUS_SUCCESS;
5313 tSirSmeScanReq *pMsg;
5314 tANI_U16 msgLen;
5315 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
5316 tSirScanType scanType = pScanReq->scanType;
5317 tANI_U32 minChnTime; //in units of milliseconds
5318 tANI_U32 maxChnTime; //in units of milliseconds
5319 tANI_U32 i;
5320 tANI_U8 selfMacAddr[WNI_CFG_BSSID_LEN];
5321 tANI_U8 *pSelfMac = NULL;
5322
5323 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
5324 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) +
5325 ( pScanReq->uIEFieldLen ) ;
5326
Kiet Lam64c1b492013-07-12 13:56:44 +05305327 pMsg = vos_mem_malloc(msgLen);
5328 if ( NULL == pMsg )
5329 status = eHAL_STATUS_FAILURE;
5330 else
5331 status = eHAL_STATUS_SUCCESS;
5332 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07005333 {
5334 do
5335 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305336 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005337 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
5338 pMsg->length = pal_cpu_to_be16(msgLen);
5339 //ToDO: Fill in session info when we need to do scan base on session.
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05305340 if ((pMac->fScanOffload) && (sessionId != CSR_SESSION_ID_INVALID))
5341 {
5342 pMsg->sessionId = sessionId;
5343 }
5344 else
5345 {
5346 /* if sessionId == CSR_SESSION_ID_INVALID, then send the scan
5347 request on first available session */
5348 pMsg->sessionId = 0;
5349 }
5350
Jeff Johnson295189b2012-06-20 16:38:30 -07005351 pMsg->transactionId = 0;
5352 pMsg->dot11mode = (tANI_U8) csrTranslateToWNICfgDot11Mode(pMac, csrFindBestPhyMode( pMac, pMac->roam.configParam.phyMode ));
5353 pMsg->bssType = pal_cpu_to_be32(csrTranslateBsstypeToMacType(pScanReq->BSSType));
5354
5355 if ( CSR_IS_SESSION_VALID( pMac, sessionId ) )
5356 {
5357 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[sessionId].selfMacAddr;
5358 }
5359 else
5360 {
5361 // Since we don't have session for the scanning, we find a valid session. In case we fail to
5362 // do so, get the WNI_CFG_STA_ID
5363 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5364 {
5365 if( CSR_IS_SESSION_VALID( pMac, i ) )
5366 {
5367 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[i].selfMacAddr;
5368 break;
5369 }
5370 }
5371 if( CSR_ROAM_SESSION_MAX == i )
5372 {
5373 tANI_U32 len = WNI_CFG_BSSID_LEN;
5374 pSelfMac = selfMacAddr;
5375 status = ccmCfgGetStr( pMac, WNI_CFG_STA_ID, pSelfMac, &len );
5376 if( !HAL_STATUS_SUCCESS( status ) ||
5377 ( len < WNI_CFG_BSSID_LEN ) )
5378 {
5379 smsLog( pMac, LOGE, FL(" Can not get self MAC address from CFG status = %d"), status );
5380 //Force failed status
5381 status = eHAL_STATUS_FAILURE;
5382 break;
5383 }
5384 }
5385 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305386 vos_mem_copy((tANI_U8 *)pMsg->selfMacAddr, pSelfMac, sizeof(tSirMacAddr));
Jeff Johnson295189b2012-06-20 16:38:30 -07005387
5388 //sirCopyMacAddr
Kiet Lam64c1b492013-07-12 13:56:44 +05305389 vos_mem_copy((tANI_U8 *)pMsg->bssId, (tANI_U8 *)&pScanReq->bssid, sizeof(tSirMacAddr));
5390 if ( vos_mem_compare(pScanReq->bssid, bssid, sizeof(tCsrBssid)))
Jeff Johnson295189b2012-06-20 16:38:30 -07005391 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305392 vos_mem_set(pMsg->bssId, sizeof(tSirMacAddr), 0xff);
Jeff Johnson295189b2012-06-20 16:38:30 -07005393 }
5394 else
5395 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305396 vos_mem_copy(pMsg->bssId, pScanReq->bssid, WNI_CFG_BSSID_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07005397 }
5398 minChnTime = pScanReq->minChnTime;
5399 maxChnTime = pScanReq->maxChnTime;
5400
5401 //Verify the scan type first, if the scan is active scan, we need to make sure we
5402 //are allowed to do so.
5403 /* if 11d is enabled & we don't see any beacon around, scan type falls
5404 back to passive. But in BT AMP STA mode we need to send out a
5405 directed probe*/
5406 if( (eSIR_PASSIVE_SCAN != scanType) && (eCSR_SCAN_P2P_DISCOVERY != pScanReq->requestType)
5407 && (eCSR_BSS_TYPE_WDS_STA != pScanReq->BSSType)
5408 && (eANI_BOOLEAN_FALSE == pMac->scan.fEnableBypass11d))
5409 {
5410 scanType = pMac->scan.curScanType;
5411 if(eSIR_PASSIVE_SCAN == pMac->scan.curScanType)
5412 {
5413 if(minChnTime < pMac->roam.configParam.nPassiveMinChnTime)
5414 {
5415 minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
5416 }
5417 if(maxChnTime < pMac->roam.configParam.nPassiveMaxChnTime)
5418 {
5419 maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
5420 }
5421 }
5422 }
5423 pMsg->scanType = pal_cpu_to_be32(scanType);
5424
5425 pMsg->numSsid = (pScanReq->SSIDs.numOfSSIDs < SIR_SCAN_MAX_NUM_SSID) ? pScanReq->SSIDs.numOfSSIDs :
5426 SIR_SCAN_MAX_NUM_SSID;
5427 if((pScanReq->SSIDs.numOfSSIDs != 0) && ( eSIR_PASSIVE_SCAN != scanType ))
5428 {
Jeff Johnson40b59aa2013-03-19 14:43:18 -07005429 for (i = 0; i < pMsg->numSsid; i++)
5430 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305431 vos_mem_copy(&pMsg->ssId[i],
5432 &pScanReq->SSIDs.SSIDList[i].SSID, sizeof(tSirMacSSid));
Jeff Johnson40b59aa2013-03-19 14:43:18 -07005433 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005434 }
5435 else
5436 {
5437 //Otherwise we scan all SSID and let the result filter later
Jeff Johnson40b59aa2013-03-19 14:43:18 -07005438 for (i = 0; i < SIR_SCAN_MAX_NUM_SSID; i++)
5439 {
5440 pMsg->ssId[i].length = 0;
5441 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005442 }
5443
Jeff Johnson295189b2012-06-20 16:38:30 -07005444 pMsg->minChannelTime = pal_cpu_to_be32(minChnTime);
5445 pMsg->maxChannelTime = pal_cpu_to_be32(maxChnTime);
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08005446 pMsg->minChannelTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
5447 pMsg->maxChannelTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07005448 //hidden SSID option
5449 pMsg->hiddenSsid = pScanReqParam->hiddenSsid;
5450 //rest time
5451 //pMsg->restTime = pScanReq->restTime;
5452 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
5453 // All the scan results caching will be done by Roaming
5454 // We do not want LIM to do any caching of scan results,
5455 // so delete the LIM cache on all scan requests
5456 pMsg->returnFreshResults = pScanReqParam->freshScan;
5457 //Always ask for unique result
5458 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
5459 pMsg->channelList.numChannels = (tANI_U8)pScanReq->ChannelInfo.numOfChannels;
5460 if(pScanReq->ChannelInfo.numOfChannels)
5461 {
5462 //Assuming the channelNumber is tANI_U8 (1 byte)
Kiet Lam64c1b492013-07-12 13:56:44 +05305463 vos_mem_copy(pMsg->channelList.channelNumber,
5464 pScanReq->ChannelInfo.ChannelList,
5465 pScanReq->ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07005466 }
5467
5468 pMsg->uIEFieldLen = (tANI_U16) pScanReq->uIEFieldLen;
5469 pMsg->uIEFieldOffset = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
5470 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) ;
5471 if(pScanReq->uIEFieldLen != 0)
5472 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305473 vos_mem_copy((tANI_U8 *)pMsg+pMsg->uIEFieldOffset, pScanReq->pIEField,
5474 pScanReq->uIEFieldLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07005475 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005476 pMsg->p2pSearch = pScanReq->p2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07005477
Madan Mohan Koyyalamudi9b876782012-10-11 16:22:51 -07005478 if (pScanReq->requestType == eCSR_SCAN_HO_BG_SCAN)
5479 {
5480 pMsg->backgroundScanMode = eSIR_ROAMING_SCAN;
5481 }
5482
Jeff Johnson295189b2012-06-20 16:38:30 -07005483 }while(0);
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005484 smsLog(pMac, LOG1, FL("domainIdCurrent %d scanType %d bssType %d requestType %d numChannels %d "),
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005485 pMac->scan.domainIdCurrent, pMsg->scanType, pMsg->bssType,
5486 pScanReq->requestType, pMsg->channelList.numChannels);
5487
5488 for(i = 0; i < pMsg->channelList.numChannels; i++)
5489 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005490 smsLog(pMac, LOG3, FL("channelNumber[%d]= %d"), i, pMsg->channelList.channelNumber[i]);
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005491 }
5492
Jeff Johnson295189b2012-06-20 16:38:30 -07005493 if(HAL_STATUS_SUCCESS(status))
5494 {
5495 status = palSendMBMessage(pMac->hHdd, pMsg);
5496 }
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005497 else
5498 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005499 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d"), status );
Kiet Lam64c1b492013-07-12 13:56:44 +05305500 vos_mem_free(pMsg);
Jeff Johnson295189b2012-06-20 16:38:30 -07005501 }
5502 }//Success allocated memory
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005503 else
5504 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005505 smsLog( pMac, LOGE, FL(" memory allocation failure"));
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005506 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005507
5508 return( status );
5509}
5510
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005511eHalStatus csrSendMBScanResultReq( tpAniSirGlobal pMac, tANI_U32 sessionId, tScanReqParam *pScanReqParam )
Jeff Johnson295189b2012-06-20 16:38:30 -07005512{
5513 eHalStatus status = eHAL_STATUS_SUCCESS;
5514 tSirSmeScanReq *pMsg;
5515 tANI_U16 msgLen;
5516
5517 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ));
Kiet Lam64c1b492013-07-12 13:56:44 +05305518 pMsg = vos_mem_malloc(msgLen);
5519 if ( NULL == pMsg )
5520 status = eHAL_STATUS_FAILURE;
5521 else
Jeff Johnson295189b2012-06-20 16:38:30 -07005522 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305523 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005524 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
5525 pMsg->length = pal_cpu_to_be16(msgLen);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005526 pMsg->sessionId = sessionId;
5527 pMsg->transactionId = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07005528 pMsg->returnFreshResults = pScanReqParam->freshScan;
5529 //Always ask for unique result
5530 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
5531 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
5532 status = palSendMBMessage(pMac->hHdd, pMsg);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005533 if (!HAL_STATUS_SUCCESS(status))
5534 {
5535 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d\n"), status );
5536 }
5537
Jeff Johnson295189b2012-06-20 16:38:30 -07005538 }
5539
5540 return( status );
5541}
5542
5543
5544
5545eHalStatus csrScanChannels( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5546{
5547 eHalStatus status = eHAL_STATUS_FAILURE;
5548 tScanReqParam scanReq;
5549
5550 do
5551 {
5552 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE | TRUE;
5553 scanReq.fUniqueResult = TRUE;
5554 scanReq.hiddenSsid = SIR_SCAN_NO_HIDDEN_SSID;
5555 if(eCsrScanForSsid == pCommand->u.scanCmd.reason)
5556 {
5557 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_FIRST_MATCH;
5558 }
5559 else
5560 {
5561 // Basically do scan on all channels even for 11D 1st scan case.
5562 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5563 }
5564 if((eCsrScanBgScan == pCommand->u.scanCmd.reason)||
5565 (eCsrScanProbeBss == pCommand->u.scanCmd.reason))
5566 {
5567 scanReq.hiddenSsid = SIR_SCAN_HIDDEN_SSID_PE_DECISION;
5568 }
5569
5570#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5571 {
5572 vos_log_scan_pkt_type *pScanLog = NULL;
5573
5574 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
5575 if(pScanLog)
5576 {
5577 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
5578 eCsrScanProbeBss == pCommand->u.scanCmd.reason)
5579 {
5580 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
5581 }
5582 else
5583 {
5584 if( (eSIR_PASSIVE_SCAN != pCommand->u.scanCmd.u.scanRequest.scanType) &&
5585 (eSIR_PASSIVE_SCAN != pMac->scan.curScanType) )
5586 {
5587 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_REQ;
5588 }
5589 else
5590 {
5591 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_REQ;
5592 }
5593 }
5594 pScanLog->minChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.minChnTime;
5595 pScanLog->maxChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.maxChnTime;
5596 pScanLog->numChannel = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
5597 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
5598 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305599 vos_mem_copy(pScanLog->channels,
5600 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
5601 pScanLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07005602 }
5603 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
5604 }
5605 }
5606#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5607
5608
5609 status = csrSendMBScanReq(pMac, pCommand->sessionId,
5610 &pCommand->u.scanCmd.u.scanRequest, &scanReq);
5611 }while(0);
5612
5613 return( status );
5614}
5615
5616
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005617eHalStatus csrScanRetrieveResult(tpAniSirGlobal pMac, tSmeCmd *pCommand)
Jeff Johnson295189b2012-06-20 16:38:30 -07005618{
5619 eHalStatus status = eHAL_STATUS_FAILURE;
5620 tScanReqParam scanReq;
5621
5622 do
5623 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005624#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5625 if (eCsrScanGetLfrResult == pCommand->u.scanCmd.reason)
5626 {
5627 //to get the LFR candidates from PE cache
5628 scanReq.freshScan = SIR_BG_SCAN_RETURN_LFR_CACHED_RESULTS|SIR_BG_SCAN_PURGE_LFR_RESULTS;
5629 scanReq.fUniqueResult = TRUE;
5630 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5631 }
5632 else
5633#endif
5634 {
5635 //not a fresh scan
5636 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE;
5637 scanReq.fUniqueResult = TRUE;
5638 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5639 }
5640 status = csrSendMBScanResultReq(pMac, pCommand->sessionId, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07005641 }while(0);
5642
5643 return (status);
5644}
5645
5646
5647
5648eHalStatus csrProcessScanCommand( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5649{
5650 eHalStatus status = eHAL_STATUS_SUCCESS;
5651 tCsrChannelInfo newChannelInfo = {0, NULL};
5652 int i, j;
5653 tANI_U8 *pChannel = NULL;
5654 tANI_U32 len = 0;
5655
5656 // Transition to Scanning state...
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305657 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07005658 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305659 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5660 {
5661 pCommand->u.scanCmd.lastRoamState[i] =
5662 csrRoamStateChange( pMac, eCSR_ROAMING_STATE_SCANNING, i);
5663 smsLog( pMac, LOG3, "starting SCAN command from %d state...."
5664 " reason is %d", pCommand->u.scanCmd.lastRoamState[i],
5665 pCommand->u.scanCmd.reason );
5666 }
5667 }
5668 else
5669 {
5670 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId] =
5671 csrRoamStateChange(pMac, eCSR_ROAMING_STATE_SCANNING,
5672 pCommand->sessionId);
5673 smsLog( pMac, LOG3,
5674 "starting SCAN command from %d state.... reason is %d",
5675 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId],
5676 pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07005677 }
5678
5679 switch(pCommand->u.scanCmd.reason)
5680 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005681#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5682 case eCsrScanGetLfrResult:
5683#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005684 case eCsrScanGetResult:
5685 case eCsrScanForCapsChange: //For cap change, LIM already save BSS description
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005686 status = csrScanRetrieveResult(pMac, pCommand);
Jeff Johnson295189b2012-06-20 16:38:30 -07005687 break;
5688 case eCsrScanSetBGScanParam:
5689 status = csrProcessSetBGScanParam(pMac, pCommand);
5690 break;
5691 case eCsrScanBGScanAbort:
5692 status = csrSetCfgBackgroundScanPeriod(pMac, 0);
5693 break;
5694 case eCsrScanBGScanEnable:
5695 status = csrSetCfgBackgroundScanPeriod(pMac, pMac->roam.configParam.bgScanInterval);
5696 break;
5697 case eCsrScanGetScanChnInfo:
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05305698 status = csrScanGetScanChannelInfo(pMac, pCommand->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07005699 break;
5700 case eCsrScanUserRequest:
5701 if(pMac->roam.configParam.fScanTwice)
5702 {
5703 //We scan 2.4 channel twice
5704 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels &&
5705 (NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList))
5706 {
5707 len = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
5708 //allocate twice the channel
5709 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(newChannelInfo.numOfChannels * 2);
5710 pChannel = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
5711 }
5712 else
5713 {
5714 //get the valid channel list to scan all.
5715 len = sizeof(pMac->roam.validChannelList);
5716
5717 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
5718 {
5719 //allocate twice the channel
5720 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(len * 2);
5721 pChannel = pMac->roam.validChannelList;
5722 }
5723 }
5724 if(NULL == newChannelInfo.ChannelList)
5725 {
5726 newChannelInfo.numOfChannels = 0;
5727 }
5728 else
5729 {
5730 j = 0;
5731 for(i = 0; i < len; i++)
5732 {
5733 newChannelInfo.ChannelList[j++] = pChannel[i];
5734 if(CSR_MAX_24GHz_CHANNEL_NUMBER >= pChannel[i])
5735 {
5736 newChannelInfo.ChannelList[j++] = pChannel[i];
5737 }
5738 }
5739 if(NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
5740 {
5741 //pChannel points to the channellist from the command, free it.
5742 vos_mem_free(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -07005743 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07005744 }
5745 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = j;
5746 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = newChannelInfo.ChannelList;
5747 }
5748 } //if(pMac->roam.configParam.fScanTwice)
5749
5750 status = csrScanChannels(pMac, pCommand);
5751
5752 break;
5753 default:
5754 status = csrScanChannels(pMac, pCommand);
5755 break;
5756 }
5757
5758 if(!HAL_STATUS_SUCCESS(status))
5759 {
5760 csrReleaseScanCommand(pMac, pCommand, eCSR_SCAN_FAILURE);
5761 }
5762
5763 return (status);
5764}
5765
5766
5767eHalStatus csrScanSetBGScanparams(tpAniSirGlobal pMac, tCsrBGScanRequest *pScanReq)
5768{
5769 eHalStatus status = eHAL_STATUS_SUCCESS;
5770 tSmeCmd *pCommand = NULL;
5771
5772 if(pScanReq)
5773 {
5774 do
5775 {
5776 pCommand = csrGetCommandBuffer(pMac);
5777 if(!pCommand)
5778 {
5779 status = eHAL_STATUS_RESOURCES;
5780 break;
5781 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305782 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005783 pCommand->command = eSmeCommandScan;
5784 pCommand->u.scanCmd.reason = eCsrScanSetBGScanParam;
5785 pCommand->u.scanCmd.callback = NULL;
5786 pCommand->u.scanCmd.pContext = NULL;
Kiet Lam64c1b492013-07-12 13:56:44 +05305787 vos_mem_copy(&pCommand->u.scanCmd.u.bgScanRequest, pScanReq, sizeof(tCsrBGScanRequest));
Jeff Johnson295189b2012-06-20 16:38:30 -07005788 //we have to do the follow
5789 if(pScanReq->ChannelInfo.numOfChannels == 0)
5790 {
5791 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
5792 }
5793 else
5794 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305795 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList
5796 = vos_mem_malloc(pScanReq->ChannelInfo.numOfChannels);
5797 if ( NULL != pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07005798 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305799 vos_mem_copy(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList,
5800 pScanReq->ChannelInfo.ChannelList,
5801 pScanReq->ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07005802 }
5803 else
5804 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005805 smsLog(pMac, LOGE, FL("ran out of memory"));
Jeff Johnson295189b2012-06-20 16:38:30 -07005806 csrReleaseCommandScan(pMac, pCommand);
Kiet Lam64c1b492013-07-12 13:56:44 +05305807 return eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005808 }
5809 }
5810
5811 //scan req for SSID
5812 if(pScanReq->SSID.length)
5813 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305814 vos_mem_copy(pCommand->u.scanCmd.u.bgScanRequest.SSID.ssId,
5815 pScanReq->SSID.ssId, pScanReq->SSID.length);
Jeff Johnson295189b2012-06-20 16:38:30 -07005816 pCommand->u.scanCmd.u.bgScanRequest.SSID.length = pScanReq->SSID.length;
5817
5818 }
5819 pCommand->u.scanCmd.u.bgScanRequest.maxChnTime= pScanReq->maxChnTime;
5820 pCommand->u.scanCmd.u.bgScanRequest.minChnTime = pScanReq->minChnTime;
5821 pCommand->u.scanCmd.u.bgScanRequest.scanInterval = pScanReq->scanInterval;
5822
5823
5824 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
5825 if( !HAL_STATUS_SUCCESS( status ) )
5826 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005827 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07005828 csrReleaseCommandScan( pMac, pCommand );
5829 break;
5830 }
5831 }while(0);
5832 }
5833
5834 return (status);
5835}
5836
5837eHalStatus csrScanBGScanAbort( tpAniSirGlobal pMac )
5838{
5839 eHalStatus status = eHAL_STATUS_SUCCESS;
5840 tSmeCmd *pCommand = NULL;
5841
5842 do
5843 {
5844 pCommand = csrGetCommandBuffer(pMac);
5845 if(!pCommand)
5846 {
5847 status = eHAL_STATUS_RESOURCES;
5848 break;
5849 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305850 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005851 pCommand->command = eSmeCommandScan;
5852 pCommand->u.scanCmd.reason = eCsrScanBGScanAbort;
5853 pCommand->u.scanCmd.callback = NULL;
5854 pCommand->u.scanCmd.pContext = NULL;
5855 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
5856 if( !HAL_STATUS_SUCCESS( status ) )
5857 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005858 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07005859 csrReleaseCommandScan( pMac, pCommand );
5860 break;
5861 }
5862 }while(0);
5863
5864 return (status);
5865}
5866
5867
5868//This will enable the background scan with the non-zero interval
5869eHalStatus csrScanBGScanEnable(tpAniSirGlobal pMac)
5870{
5871 eHalStatus status = eHAL_STATUS_SUCCESS;
5872 tSmeCmd *pCommand = NULL;
5873
5874 if(pMac->roam.configParam.bgScanInterval)
5875 {
5876 do
5877 {
5878 pCommand = csrGetCommandBuffer(pMac);
5879 if(!pCommand)
5880 {
5881 status = eHAL_STATUS_RESOURCES;
5882 break;
5883 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305884 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005885 pCommand->command = eSmeCommandScan;
5886 pCommand->u.scanCmd.reason = eCsrScanBGScanEnable;
5887 pCommand->u.scanCmd.callback = NULL;
5888 pCommand->u.scanCmd.pContext = NULL;
5889 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
5890 if( !HAL_STATUS_SUCCESS( status ) )
5891 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005892 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07005893 csrReleaseCommandScan( pMac, pCommand );
5894 break;
5895 }
5896 }while(0);
5897 //BG scan results are reported automatically by PE to SME once the scan is done.
5898 //No need to fetch the results explicitly.
5899 //csrScanStartGetResultTimer(pMac);
5900 csrScanStartResultAgingTimer(pMac);
5901 }
5902 else
5903 {
5904 //We don't have BG scan so stop the aging timer
5905 csrScanStopResultAgingTimer(pMac);
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005906 smsLog(pMac, LOGE, FL("cannot continue because the bgscan interval is 0"));
Jeff Johnson295189b2012-06-20 16:38:30 -07005907 status = eHAL_STATUS_INVALID_PARAMETER;
5908 }
5909
5910 return (status);
5911}
5912
5913
5914eHalStatus csrScanCopyRequest(tpAniSirGlobal pMac, tCsrScanRequest *pDstReq, tCsrScanRequest *pSrcReq)
5915{
5916 eHalStatus status = eHAL_STATUS_SUCCESS;
5917 tANI_U32 len = sizeof(pMac->roam.validChannelList);
5918 tANI_U32 index = 0;
5919 tANI_U32 new_index = 0;
5920
5921 do
5922 {
5923 status = csrScanFreeRequest(pMac, pDstReq);
5924 if(HAL_STATUS_SUCCESS(status))
5925 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305926 vos_mem_copy(pDstReq, pSrcReq, sizeof(tCsrScanRequest));
Gopichand Nakkalac7b1d3e2012-12-31 14:07:19 -08005927 /* Re-initialize the pointers to NULL since we did a copy */
5928 pDstReq->pIEField = NULL;
5929 pDstReq->ChannelInfo.ChannelList = NULL;
5930 pDstReq->SSIDs.SSIDList = NULL;
5931
Jeff Johnson295189b2012-06-20 16:38:30 -07005932 if(pSrcReq->uIEFieldLen == 0)
5933 {
5934 pDstReq->pIEField = NULL;
5935 }
5936 else
5937 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305938 pDstReq->pIEField = vos_mem_malloc(pSrcReq->uIEFieldLen);
5939 if ( NULL == pDstReq->pIEField )
5940 status = eHAL_STATUS_FAILURE;
5941 else
5942 status = eHAL_STATUS_SUCCESS;
5943 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07005944 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305945 vos_mem_copy(pDstReq->pIEField, pSrcReq->pIEField, pSrcReq->uIEFieldLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07005946 pDstReq->uIEFieldLen = pSrcReq->uIEFieldLen;
5947 }
5948 else
5949 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005950 smsLog(pMac, LOGE, "No memory for scanning IE fields");
Jeff Johnson295189b2012-06-20 16:38:30 -07005951 break;
5952 }
5953 }//Allocate memory for IE field
5954 {
5955 if(pSrcReq->ChannelInfo.numOfChannels == 0)
5956 {
5957 pDstReq->ChannelInfo.ChannelList = NULL;
5958 pDstReq->ChannelInfo.numOfChannels = 0;
5959 }
5960 else
5961 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305962 pDstReq->ChannelInfo.ChannelList = vos_mem_malloc(
5963 pSrcReq->ChannelInfo.numOfChannels
5964 * sizeof(*pDstReq->ChannelInfo.ChannelList));
5965 if ( NULL == pDstReq->ChannelInfo.ChannelList )
5966 status = eHAL_STATUS_FAILURE;
5967 else
5968 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07005969 if(!HAL_STATUS_SUCCESS(status))
5970 {
5971 pDstReq->ChannelInfo.numOfChannels = 0;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005972 smsLog(pMac, LOGE, "No memory for scanning Channel List");
Jeff Johnson295189b2012-06-20 16:38:30 -07005973 break;
5974 }
5975
5976 if((pSrcReq->scanType == eSIR_PASSIVE_SCAN) && (pSrcReq->requestType == eCSR_SCAN_REQUEST_11D_SCAN))
5977 {
5978 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
5979 {
5980 pDstReq->ChannelInfo.ChannelList[new_index] =
5981 pSrcReq->ChannelInfo.ChannelList[index];
5982 new_index++;
5983 }
5984 pDstReq->ChannelInfo.numOfChannels = new_index;
5985 }
5986 else if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
5987 {
5988 new_index = 0;
5989 pMac->roam.numValidChannels = len;
5990 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
5991 {
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -07005992 /* Allow scan on valid channels only.
5993 * If it is p2p scan and valid channel list doesnt contain
5994 * social channels, enforce scan on social channels because
5995 * that is the only way to find p2p peers.
5996 * This can happen only if band is set to 5Ghz mode.
5997 */
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08005998 if((csrRoamIsValidChannel(pMac, pSrcReq->ChannelInfo.ChannelList[index])) ||
5999 ((eCSR_SCAN_P2P_DISCOVERY == pSrcReq->requestType) &&
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -07006000 CSR_IS_SOCIAL_CHANNEL(pSrcReq->ChannelInfo.ChannelList[index])))
Jeff Johnson295189b2012-06-20 16:38:30 -07006001 {
Srikant Kuppa866893f2012-12-27 17:28:14 -08006002 if( (pSrcReq->skipDfsChnlInP2pSearch &&
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08006003 (NV_CHANNEL_DFS == vos_nv_getChannelEnabledState(pSrcReq->ChannelInfo.ChannelList[index])) )
Srikant Kuppa866893f2012-12-27 17:28:14 -08006004#ifdef FEATURE_WLAN_LFR
6005 /*
6006 * If LFR is requesting a contiguous scan
6007 * (i.e. numOfChannels > 1), then ignore
6008 * DFS channels.
6009 * TODO: vos_nv_getChannelEnabledState is returning
6010 * 120, 124 and 128 as non-DFS channels. Hence, the
6011 * use of direct check for channels below.
6012 */
6013 || ((eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType) &&
6014 (pSrcReq->ChannelInfo.numOfChannels > 1) &&
Srinivas Girigowdade697412013-02-14 16:31:48 -08006015 (CSR_IS_CHANNEL_DFS(pSrcReq->ChannelInfo.ChannelList[index])))
Srikant Kuppa866893f2012-12-27 17:28:14 -08006016#endif
6017 )
6018 {
6019#ifdef FEATURE_WLAN_LFR
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006020 smsLog(pMac, LOG2,
Srikant Kuppa866893f2012-12-27 17:28:14 -08006021 "%s: reqType=%d, numOfChannels=%d,"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006022 " ignoring DFS channel %d",
Srikant Kuppa866893f2012-12-27 17:28:14 -08006023 __func__, pSrcReq->requestType,
6024 pSrcReq->ChannelInfo.numOfChannels,
6025 pSrcReq->ChannelInfo.ChannelList[index]);
6026#endif
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08006027 continue;
Srikant Kuppa866893f2012-12-27 17:28:14 -08006028 }
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08006029
Jeff Johnson295189b2012-06-20 16:38:30 -07006030 pDstReq->ChannelInfo.ChannelList[new_index] =
6031 pSrcReq->ChannelInfo.ChannelList[index];
6032 new_index++;
6033 }
6034 }
6035 pDstReq->ChannelInfo.numOfChannels = new_index;
Srikant Kuppa866893f2012-12-27 17:28:14 -08006036#ifdef FEATURE_WLAN_LFR
6037 if ((eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType) &&
6038 (0 == pDstReq->ChannelInfo.numOfChannels))
6039 {
6040 /*
6041 * No valid channels found in the request.
6042 * Only perform scan on the channels passed
6043 * pSrcReq if it is a eCSR_SCAN_HO_BG_SCAN.
6044 * Passing 0 to LIM will trigger a scan on
6045 * all valid channels which is not desirable.
6046 */
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006047 smsLog(pMac, LOGE, "%s: no valid channels found (request=%d)",
Srikant Kuppa866893f2012-12-27 17:28:14 -08006048 __func__, pSrcReq->requestType);
6049 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
6050 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006051 smsLog(pMac, LOGE, "pSrcReq index=%d channel=%d",
Srikant Kuppa866893f2012-12-27 17:28:14 -08006052 index, pSrcReq->ChannelInfo.ChannelList[index]);
6053 }
6054 status = eHAL_STATUS_FAILURE;
6055 break;
6056 }
6057#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006058 }
6059 else
6060 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006061 smsLog(pMac, LOGE, "Couldn't get the valid Channel List, keeping requester's list");
Kiet Lam64c1b492013-07-12 13:56:44 +05306062 vos_mem_copy(pDstReq->ChannelInfo.ChannelList,
6063 pSrcReq->ChannelInfo.ChannelList,
6064 pSrcReq->ChannelInfo.numOfChannels
6065 * sizeof(*pDstReq->ChannelInfo.ChannelList));
Jeff Johnson295189b2012-06-20 16:38:30 -07006066 pDstReq->ChannelInfo.numOfChannels = pSrcReq->ChannelInfo.numOfChannels;
6067 }
6068 }//Allocate memory for Channel List
6069 }
6070 if(pSrcReq->SSIDs.numOfSSIDs == 0)
6071 {
6072 pDstReq->SSIDs.numOfSSIDs = 0;
6073 pDstReq->SSIDs.SSIDList = NULL;
6074 }
6075 else
6076 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306077 pDstReq->SSIDs.SSIDList = vos_mem_malloc(
6078 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
6079 if ( NULL == pDstReq->SSIDs.SSIDList )
6080 status = eHAL_STATUS_FAILURE;
6081 else
6082 status = eHAL_STATUS_SUCCESS;
6083 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07006084 {
6085 pDstReq->SSIDs.numOfSSIDs = pSrcReq->SSIDs.numOfSSIDs;
Kiet Lam64c1b492013-07-12 13:56:44 +05306086 vos_mem_copy(pDstReq->SSIDs.SSIDList,
6087 pSrcReq->SSIDs.SSIDList,
6088 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
Jeff Johnson295189b2012-06-20 16:38:30 -07006089 }
6090 else
6091 {
6092 pDstReq->SSIDs.numOfSSIDs = 0;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006093 smsLog(pMac, LOGE, "No memory for scanning SSID List");
Jeff Johnson295189b2012-06-20 16:38:30 -07006094 break;
6095 }
6096 }//Allocate memory for SSID List
Jeff Johnson295189b2012-06-20 16:38:30 -07006097 pDstReq->p2pSearch = pSrcReq->p2pSearch;
Jeff Johnsone7245742012-09-05 17:12:55 -07006098 pDstReq->skipDfsChnlInP2pSearch = pSrcReq->skipDfsChnlInP2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07006099
6100 }
6101 }while(0);
6102
6103 if(!HAL_STATUS_SUCCESS(status))
6104 {
6105 csrScanFreeRequest(pMac, pDstReq);
6106 }
6107
6108 return (status);
6109}
6110
6111
6112eHalStatus csrScanFreeRequest(tpAniSirGlobal pMac, tCsrScanRequest *pReq)
6113{
Jeff Johnson295189b2012-06-20 16:38:30 -07006114
6115 if(pReq->ChannelInfo.ChannelList)
6116 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306117 vos_mem_free(pReq->ChannelInfo.ChannelList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006118 pReq->ChannelInfo.ChannelList = NULL;
6119 }
6120 pReq->ChannelInfo.numOfChannels = 0;
6121 if(pReq->pIEField)
6122 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306123 vos_mem_free(pReq->pIEField);
Jeff Johnson295189b2012-06-20 16:38:30 -07006124 pReq->pIEField = NULL;
6125 }
6126 pReq->uIEFieldLen = 0;
6127 if(pReq->SSIDs.SSIDList)
6128 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306129 vos_mem_free(pReq->SSIDs.SSIDList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006130 pReq->SSIDs.SSIDList = NULL;
6131 }
6132 pReq->SSIDs.numOfSSIDs = 0;
6133
Kiet Lam64c1b492013-07-12 13:56:44 +05306134 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07006135}
6136
6137
6138void csrScanCallCallback(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
6139{
6140 if(pCommand->u.scanCmd.callback)
6141 {
6142// sme_ReleaseGlobalLock( &pMac->sme );
6143 pCommand->u.scanCmd.callback(pMac, pCommand->u.scanCmd.pContext, pCommand->u.scanCmd.scanID, scanStatus);
6144// sme_AcquireGlobalLock( &pMac->sme );
6145 } else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006146 smsLog( pMac, LOG2, "%s:%d - Callback NULL!!!", __func__, __LINE__);
Jeff Johnson295189b2012-06-20 16:38:30 -07006147 }
6148}
6149
6150
6151void csrScanStopTimers(tpAniSirGlobal pMac)
6152{
6153 csrScanStopResultAgingTimer(pMac);
6154 csrScanStopIdleScanTimer(pMac);
6155 csrScanStopGetResultTimer(pMac);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006156 if(0 != pMac->scan.scanResultCfgAgingTime )
6157 {
6158 csrScanStopResultCfgAgingTimer(pMac);
6159 }
6160
Jeff Johnson295189b2012-06-20 16:38:30 -07006161}
6162
6163
6164eHalStatus csrScanStartGetResultTimer(tpAniSirGlobal pMac)
6165{
6166 eHalStatus status;
6167
6168 if(pMac->scan.fScanEnable)
6169 {
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306170 status = vos_timer_start(&pMac->scan.hTimerGetResult, CSR_SCAN_GET_RESULT_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006171 }
6172 else
6173 {
6174 status = eHAL_STATUS_FAILURE;
6175 }
6176
6177 return (status);
6178}
6179
6180
6181eHalStatus csrScanStopGetResultTimer(tpAniSirGlobal pMac)
6182{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306183 return (vos_timer_stop(&pMac->scan.hTimerGetResult));
Jeff Johnson295189b2012-06-20 16:38:30 -07006184}
6185
6186
6187void csrScanGetResultTimerHandler(void *pv)
6188{
6189 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6190
6191 csrScanRequestResult(pMac);
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306192
6193 vos_timer_start(&pMac->scan.hTimerGetResult, CSR_SCAN_GET_RESULT_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006194}
6195
6196#ifdef WLAN_AP_STA_CONCURRENCY
6197static void csrStaApConcTimerHandler(void *pv)
6198{
6199 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6200 tListElem *pEntry;
6201 tSmeCmd *pScanCmd;
6202
6203 csrLLLock(&pMac->scan.scanCmdPendingList);
6204
6205 if ( NULL != ( pEntry = csrLLPeekHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) ) )
6206 {
6207 tCsrScanRequest scanReq;
6208 tSmeCmd *pSendScanCmd = NULL;
6209 tANI_U8 numChn = 0;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006210 tANI_U8 nNumChanCombinedConc = 0;
Vinay Malekal05fdc812012-12-17 13:04:30 -08006211 tANI_U8 i, j;
Jeff Johnson295189b2012-06-20 16:38:30 -07006212 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
6213 tANI_U8 channelToScan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
6214 eHalStatus status;
6215
Jeff Johnson295189b2012-06-20 16:38:30 -07006216 pScanCmd = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
6217 numChn = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08006218
6219 /* if any session is connected and the number of channels to scan is
6220 * greater than 1 then split the scan into multiple scan operations
6221 * on each individual channel else continue to perform scan on all
6222 * specified channels */
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08006223
6224 /* split scan if number of channels to scan is greater than 1 and
6225 * any one of the following:
6226 * - STA session is connected and the scan is not a P2P search
6227 * - any P2P session is connected
Srikant Kuppa866893f2012-12-27 17:28:14 -08006228 * Do not split scans if no concurrent infra connections are
6229 * active and if the scan is a BG scan triggered by LFR (OR)
6230 * any scan if LFR is in the middle of a BG scan. Splitting
6231 * the scan is delaying the time it takes for LFR to find
6232 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08006233 */
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006234
6235 if((csrIsStaSessionConnected(pMac) &&
6236 !csrIsP2pSessionConnected(pMac)))
6237 {
6238 nNumChanCombinedConc = pMac->roam.configParam.nNumStaChanCombinedConc;
6239 }
6240 else if(csrIsP2pSessionConnected(pMac))
6241 {
6242 nNumChanCombinedConc = pMac->roam.configParam.nNumP2PChanCombinedConc;
6243 }
6244
6245 if ( (numChn > nNumChanCombinedConc) &&
Srikant Kuppa866893f2012-12-27 17:28:14 -08006246 ((csrIsStaSessionConnected(pMac) &&
6247#ifdef FEATURE_WLAN_LFR
6248 (csrIsConcurrentInfraConnected(pMac) ||
6249 ((pScanCmd->u.scanCmd.reason != eCsrScanBgScan) &&
6250 (pMac->roam.neighborRoamInfo.neighborRoamState !=
6251 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
6252#endif
6253 (pScanCmd->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08006254 (csrIsP2pSessionConnected(pMac))))
Jeff Johnson295189b2012-06-20 16:38:30 -07006255 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306256 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006257
6258 pSendScanCmd = csrGetCommandBuffer(pMac); //optimize this to use 2 command buffer only
6259 if (!pSendScanCmd)
6260 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006261 smsLog( pMac, LOGE, FL(" Failed to get Queue command buffer") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006262 csrLLUnlock(&pMac->scan.scanCmdPendingList);
6263 return;
6264 }
6265 pSendScanCmd->command = pScanCmd->command;
6266 pSendScanCmd->sessionId = pScanCmd->sessionId;
6267 pSendScanCmd->u.scanCmd.callback = NULL;
6268 pSendScanCmd->u.scanCmd.pContext = pScanCmd->u.scanCmd.pContext;
6269 pSendScanCmd->u.scanCmd.reason = pScanCmd->u.scanCmd.reason;
6270 pSendScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
6271
Madan Mohan Koyyalamudiaf2a8b92012-10-09 14:58:07 -07006272 /* First copy all the parameters to local variable of scan request */
6273 csrScanCopyRequest(pMac, &scanReq, &pScanCmd->u.scanCmd.u.scanRequest);
6274
6275 /* Now modify the elements of local var scan request required to be modified for split scan */
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08006276 if(scanReq.ChannelInfo.ChannelList != NULL)
6277 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306278 vos_mem_free(scanReq.ChannelInfo.ChannelList);
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08006279 scanReq.ChannelInfo.ChannelList = NULL;
6280 }
6281
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006282 pChnInfo->numOfChannels = nNumChanCombinedConc;
Kiet Lam64c1b492013-07-12 13:56:44 +05306283 vos_mem_copy(&channelToScan[0],
6284 &pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[0],
6285 pChnInfo->numOfChannels * sizeof(tANI_U8));//just send one channel
Jeff Johnson295189b2012-06-20 16:38:30 -07006286 pChnInfo->ChannelList = &channelToScan[0];
6287
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006288 for (i = 0, j = nNumChanCombinedConc; i < (numChn-nNumChanCombinedConc); i++, j++)
Jeff Johnson295189b2012-06-20 16:38:30 -07006289 {
6290 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] =
Vinay Malekal05fdc812012-12-17 13:04:30 -08006291 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[j]; //Move all the channels one step
Jeff Johnson295189b2012-06-20 16:38:30 -07006292 }
6293
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006294 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = numChn - nNumChanCombinedConc; //reduce outstanding # of channels to be scanned
Jeff Johnson295189b2012-06-20 16:38:30 -07006295
6296 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
6297 //Modify callers parameters in case of concurrency
6298 scanReq.scanType = eSIR_ACTIVE_SCAN;
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -07006299 //Use concurrency values for min/maxChnTime.
6300 //We know csrIsAnySessionConnected(pMac) returns TRUE here
6301 csrSetDefaultScanTiming(pMac, scanReq.scanType, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07006302
6303 status = csrScanCopyRequest(pMac, &pSendScanCmd->u.scanCmd.u.scanRequest, &scanReq);
6304 if(!HAL_STATUS_SUCCESS(status))
6305 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006306 smsLog( pMac, LOGE, FL(" Failed to get copy csrScanRequest = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006307 csrLLUnlock(&pMac->scan.scanCmdPendingList);
6308 return;
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08006309 }
6310 /* Clean the local scan variable */
6311 scanReq.ChannelInfo.ChannelList = NULL;
6312 scanReq.ChannelInfo.numOfChannels = 0;
6313 csrScanFreeRequest(pMac, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07006314 }
6315 else
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08006316 {
6317 /* no active connected session present or numChn == 1
6318 * scan all remaining channels */
Jeff Johnson295189b2012-06-20 16:38:30 -07006319 pSendScanCmd = pScanCmd;
6320 //remove this command from pending list
6321 if (csrLLRemoveHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) == NULL)
6322 { //In case between PeekHead and here, the entry got removed by another thread.
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006323 smsLog( pMac, LOGE, FL(" Failed to remove entry from scanCmdPendingList"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006324 }
6325
6326 }
6327 csrQueueSmeCommand(pMac, pSendScanCmd, eANI_BOOLEAN_FALSE);
6328
6329 }
6330
Jeff Johnson295189b2012-06-20 16:38:30 -07006331 csrLLUnlock(&pMac->scan.scanCmdPendingList);
6332
6333}
6334#endif
6335
6336eHalStatus csrScanStartResultAgingTimer(tpAniSirGlobal pMac)
6337{
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006338 eHalStatus status = eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006339
6340 if(pMac->scan.fScanEnable)
6341 {
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306342 status = vos_timer_start(&pMac->scan.hTimerResultAging, CSR_SCAN_RESULT_AGING_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006343 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006344 return (status);
6345}
6346
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006347eHalStatus csrScanStartResultCfgAgingTimer(tpAniSirGlobal pMac)
6348{
6349 eHalStatus status = eHAL_STATUS_FAILURE;
6350
6351 if(pMac->scan.fScanEnable)
6352 {
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306353 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 -08006354 }
6355 return (status);
6356}
Jeff Johnson295189b2012-06-20 16:38:30 -07006357
6358eHalStatus csrScanStopResultAgingTimer(tpAniSirGlobal pMac)
6359{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306360 return (vos_timer_stop(&pMac->scan.hTimerResultAging));
Jeff Johnson295189b2012-06-20 16:38:30 -07006361}
6362
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006363eHalStatus csrScanStopResultCfgAgingTimer(tpAniSirGlobal pMac)
6364{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306365 return (vos_timer_stop(&pMac->scan.hTimerResultCfgAging));
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006366}
Jeff Johnson295189b2012-06-20 16:38:30 -07006367
6368//This function returns the maximum time a BSS is allowed in the scan result.
6369//The time varies base on connection and power saving factors.
6370//Not connected, No PS
6371//Not connected, with PS
6372//Connected w/o traffic, No PS
6373//Connected w/o traffic, with PS
6374//Connected w/ traffic, no PS -- Not supported
6375//Connected w/ traffic, with PS -- Not supported
6376//the return unit is in seconds.
6377tANI_U32 csrScanGetAgeOutTime(tpAniSirGlobal pMac)
6378{
6379 tANI_U32 nRet;
6380
6381 if(pMac->scan.nAgingCountDown)
6382 {
6383 //Calculate what should be the timeout value for this
6384 nRet = pMac->scan.nLastAgeTimeOut * pMac->scan.nAgingCountDown;
6385 pMac->scan.nAgingCountDown--;
6386 }
6387 else
6388 {
6389 if( csrIsAllSessionDisconnected( pMac ) )
6390 {
6391 if(pmcIsPowerSaveEnabled(pMac, ePMC_IDLE_MODE_POWER_SAVE))
6392 {
6393 nRet = pMac->roam.configParam.scanAgeTimeNCPS;
6394 }
6395 else
6396 {
6397 nRet = pMac->roam.configParam.scanAgeTimeNCNPS;
6398 }
6399 }
6400 else
6401 {
6402 if(pmcIsPowerSaveEnabled(pMac, ePMC_BEACON_MODE_POWER_SAVE))
6403 {
6404 nRet = pMac->roam.configParam.scanAgeTimeCPS;
6405 }
6406 else
6407 {
6408 nRet = pMac->roam.configParam.scanAgeTimeCNPS;
6409 }
6410 }
6411 //If state-change causing aging time out change, we want to delay it somewhat to avoid
6412 //unnecessary removal of BSS. This is mostly due to transition from connect to disconnect.
6413 if(pMac->scan.nLastAgeTimeOut > nRet)
6414 {
6415 if(nRet)
6416 {
6417 pMac->scan.nAgingCountDown = (pMac->scan.nLastAgeTimeOut / nRet);
6418 }
6419 pMac->scan.nLastAgeTimeOut = nRet;
6420 nRet *= pMac->scan.nAgingCountDown;
6421 }
6422 else
6423 {
6424 pMac->scan.nLastAgeTimeOut = nRet;
6425 }
6426 }
6427
6428 return (nRet);
6429}
6430
6431
6432void csrScanResultAgingTimerHandler(void *pv)
6433{
6434 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6435 tANI_BOOLEAN fDisconnected = csrIsAllSessionDisconnected(pMac);
6436
6437 //no scan, no aging
6438 if(pMac->scan.fScanEnable &&
6439 (((eANI_BOOLEAN_FALSE == fDisconnected) && pMac->roam.configParam.bgScanInterval)
6440 || (fDisconnected && (pMac->scan.fCancelIdleScan == eANI_BOOLEAN_FALSE)))
6441 )
6442 {
6443 tListElem *pEntry, *tmpEntry;
6444 tCsrScanResult *pResult;
6445 tANI_TIMESTAMP ageOutTime = (tANI_TIMESTAMP)(csrScanGetAgeOutTime(pMac) * PAL_TICKS_PER_SECOND); //turn it into 10ms units
6446 tANI_TIMESTAMP curTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
6447
6448 csrLLLock(&pMac->scan.scanResultList);
6449 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
6450 while( pEntry )
6451 {
6452 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
6453 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
6454 if((curTime - pResult->Result.BssDescriptor.nReceivedTime) > ageOutTime)
6455 {
6456 smsLog(pMac, LOGW, " age out due to time out");
6457 csrScanAgeOutBss(pMac, pResult);
6458 }
6459 pEntry = tmpEntry;
6460 }
6461 csrLLUnlock(&pMac->scan.scanResultList);
6462 }
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306463 vos_timer_start(&pMac->scan.hTimerResultAging, CSR_SCAN_RESULT_AGING_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006464}
6465
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006466static void csrScanResultCfgAgingTimerHandler(void *pv)
6467{
6468 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6469 tListElem *pEntry, *tmpEntry;
6470 tCsrScanResult *pResult;
6471 tANI_TIMESTAMP ageOutTime = pMac->scan.scanResultCfgAgingTime * PAL_TICKS_PER_SECOND;
6472 tANI_TIMESTAMP curTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
6473
6474 csrLLLock(&pMac->scan.scanResultList);
6475 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
6476 while( pEntry )
6477 {
6478 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
6479 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
6480 if((curTime - pResult->Result.BssDescriptor.nReceivedTime) > ageOutTime)
6481 {
6482 smsLog(pMac, LOGW, " age out due to time out");
6483 csrScanAgeOutBss(pMac, pResult);
6484 }
6485 pEntry = tmpEntry;
6486 }
6487 csrLLUnlock(&pMac->scan.scanResultList);
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306488 vos_timer_start(&pMac->scan.hTimerResultCfgAging, CSR_SCAN_RESULT_CFG_AGING_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006489}
Jeff Johnson295189b2012-06-20 16:38:30 -07006490
6491eHalStatus csrScanStartIdleScanTimer(tpAniSirGlobal pMac, tANI_U32 interval)
6492{
6493 eHalStatus status;
6494
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006495 smsLog(pMac, LOG1, " csrScanStartIdleScanTimer");
Jeff Johnson295189b2012-06-20 16:38:30 -07006496 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) && interval)
6497 {
6498 pMac->scan.nIdleScanTimeGap += interval;
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306499 vos_timer_stop(&pMac->scan.hTimerIdleScan);
6500 status = vos_timer_start(&pMac->scan.hTimerIdleScan, interval/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006501 if( !HAL_STATUS_SUCCESS(status) )
6502 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006503 smsLog(pMac, LOGE, " Fail to start Idle scan timer. status = %d interval = %d", status, interval);
Jeff Johnson295189b2012-06-20 16:38:30 -07006504 //This should not happen but set the flag to restart when ready
6505 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6506 }
6507 }
6508 else
6509 {
6510 if( pMac->scan.fScanEnable && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) )
6511 {
6512 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6513 }
6514 status = eHAL_STATUS_FAILURE;
6515 }
6516
6517 return (status);
6518}
6519
6520
6521eHalStatus csrScanStopIdleScanTimer(tpAniSirGlobal pMac)
6522{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306523 return (vos_timer_stop(&pMac->scan.hTimerIdleScan));
Jeff Johnson295189b2012-06-20 16:38:30 -07006524}
6525
6526
6527//Stop CSR from asking for IMPS, This function doesn't disable IMPS from CSR
6528void csrScanSuspendIMPS( tpAniSirGlobal pMac )
6529{
6530 csrScanCancelIdleScan(pMac);
6531}
6532
6533
6534//Start CSR from asking for IMPS. This function doesn't trigger CSR to request entering IMPS
6535//because IMPS maybe disabled.
6536void csrScanResumeIMPS( tpAniSirGlobal pMac )
6537{
6538 csrScanStartIdleScan( pMac );
6539}
6540
6541
6542void csrScanIMPSCallback(void *callbackContext, eHalStatus status)
6543{
6544 tpAniSirGlobal pMac = PMAC_STRUCT( callbackContext );
6545
6546 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6547 {
6548 if(pMac->roam.configParam.IsIdleScanEnabled)
6549 {
6550 if(HAL_STATUS_SUCCESS(status))
6551 {
6552 if(csrIsAllSessionDisconnected(pMac) && !csrIsRoamCommandWaiting(pMac))
6553 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006554 smsLog(pMac, LOGW, FL("starts idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006555 csrScanAllChannels(pMac, eCSR_SCAN_IDLE_MODE_SCAN);
6556 }
6557 else
6558 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006559 smsLog(pMac, LOGW, FL("cannot start idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006560 //even though we are in timer handle, calling stop timer will make sure the timer
6561 //doesn't get to restart.
6562 csrScanStopIdleScanTimer(pMac);
6563 }
6564 }
6565 else
6566 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006567 smsLog(pMac, LOGE, FL("sees not success status (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07006568 }
6569 }
6570 else
6571 {//we might need another flag to check if CSR needs to request imps at all
6572
6573 tANI_U32 nTime = 0;
6574
6575 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_FALSE;
6576 if(!HAL_STATUS_SUCCESS(csrScanTriggerIdleScan(pMac, &nTime)))
6577 {
6578 csrScanStartIdleScanTimer(pMac, nTime);
6579 }
6580 }
6581 }
6582}
6583
6584
6585//Param: pTimeInterval -- Caller allocated memory in return, if failed, to specify the nxt time interval for
6586//idle scan timer interval
6587//Return: Not success -- meaning it cannot start IMPS, caller needs to start a timer for idle scan
6588eHalStatus csrScanTriggerIdleScan(tpAniSirGlobal pMac, tANI_U32 *pTimeInterval)
6589{
6590 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
6591
6592 //Do not trigger IMPS in case of concurrency
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006593 if (vos_concurrent_sessions_running() && csrIsAnySessionInConnectState(pMac))
6594 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006595 smsLog( pMac, LOG1, FL("Cannot request IMPS because Concurrent Sessions Running") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006596 return (status);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006597 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006598
6599 if(pTimeInterval)
6600 {
6601 *pTimeInterval = 0;
6602 }
6603
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006604 smsLog(pMac, LOG3, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006605 if( smeCommandPending( pMac ) )
6606 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006607 smsLog( pMac, LOG1, FL(" Cannot request IMPS because command pending") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006608 //Not to enter IMPS because more work to do
6609 if(pTimeInterval)
6610 {
6611 *pTimeInterval = 0;
6612 }
6613 //restart when ready
6614 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6615
6616 return (status);
6617 }
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07006618 if (IsPmcImpsReqFailed (pMac))
6619 {
6620 if(pTimeInterval)
6621 {
6622 *pTimeInterval = 1000000; //usec
6623 }
6624 //restart when ready
6625 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006626
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07006627 return status;
6628 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006629 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6630 /*&& pMac->roam.configParam.impsSleepTime*/)
6631 {
6632 //Stop get result timer because idle scan gets scan result out of PE
6633 csrScanStopGetResultTimer(pMac);
6634 if(pTimeInterval)
6635 {
6636 *pTimeInterval = pMac->roam.configParam.impsSleepTime;
6637 }
6638 //pmcRequestImps take a period in millisecond unit.
6639 status = pmcRequestImps(pMac, pMac->roam.configParam.impsSleepTime / PAL_TIMER_TO_MS_UNIT, csrScanIMPSCallback, pMac);
6640 if(!HAL_STATUS_SUCCESS(status))
6641 {
6642 if(eHAL_STATUS_PMC_ALREADY_IN_IMPS != status)
6643 {
6644 //Do restart the timer if CSR thinks it cannot do IMPS
6645 if( !csrCheckPSReady( pMac ) )
6646 {
6647 if(pTimeInterval)
6648 {
6649 *pTimeInterval = 0;
6650 }
6651 //Set the restart flag to true because that idle scan
6652 //can be restarted even though the timer will not be running
6653 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6654 }
6655 else
6656 {
6657 //For not now, we do a quicker retry
6658 if(pTimeInterval)
6659 {
6660 *pTimeInterval = CSR_IDLE_SCAN_WAIT_TIME;
6661 }
6662 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006663 smsLog(pMac, LOGW, FL("call pmcRequestImps and it returns status code (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07006664 }
6665 else
6666 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006667 smsLog(pMac, LOGW, FL("already in IMPS"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006668 //Since CSR is the only module to request for IMPS. If it is already in IMPS, CSR assumes
6669 //the callback will be called in the future. Should not happen though.
6670 status = eHAL_STATUS_SUCCESS;
6671 pMac->scan.nIdleScanTimeGap = 0;
6672 }
6673 }
6674 else
6675 {
6676 //requested so let's reset the value
6677 pMac->scan.nIdleScanTimeGap = 0;
6678 }
6679 }
6680
6681 return (status);
6682}
6683
6684
6685eHalStatus csrScanStartIdleScan(tpAniSirGlobal pMac)
6686{
6687 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
6688 tANI_U32 nTime = 0;
6689
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006690 smsLog(pMac, LOGW, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006691 if(pMac->roam.configParam.IsIdleScanEnabled)
6692 {
6693 //stop bg scan first
6694 csrScanBGScanAbort(pMac);
6695 //Stop get result timer because idle scan gets scan result out of PE
6696 csrScanStopGetResultTimer(pMac);
6697 //Enable aging timer since idle scan is going on
6698 csrScanStartResultAgingTimer(pMac);
6699 }
6700 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_FALSE;
6701 status = csrScanTriggerIdleScan(pMac, &nTime);
6702 if(!HAL_STATUS_SUCCESS(status))
6703 {
6704 csrScanStartIdleScanTimer(pMac, nTime);
6705 }
6706
6707 return (status);
6708}
6709
6710
6711void csrScanCancelIdleScan(tpAniSirGlobal pMac)
6712{
6713 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6714 {
Jeff Johnson295189b2012-06-20 16:38:30 -07006715 if (vos_concurrent_sessions_running()) {
6716 return;
6717 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006718 smsLog(pMac, LOG1, " csrScanCancelIdleScan");
Jeff Johnson295189b2012-06-20 16:38:30 -07006719 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_TRUE;
6720 //Set the restart flag in case later on it is uncancelled
6721 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6722 csrScanStopIdleScanTimer(pMac);
6723 csrScanRemoveNotRoamingScanCommand(pMac);
6724 }
6725}
6726
6727
6728void csrScanIdleScanTimerHandler(void *pv)
6729{
6730 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6731 eHalStatus status;
6732 tANI_U32 nTime = 0;
6733
6734 smsLog(pMac, LOGW, " csrScanIdleScanTimerHandler called ");
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07006735 pmcResetImpsFailStatus (pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07006736 status = csrScanTriggerIdleScan(pMac, &nTime);
6737 if(!HAL_STATUS_SUCCESS(status) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan))
6738 {
6739 //Check whether it is time to actually do an idle scan
6740 if(pMac->scan.nIdleScanTimeGap >= pMac->roam.configParam.impsSleepTime)
6741 {
6742 pMac->scan.nIdleScanTimeGap = 0;
6743 csrScanIMPSCallback(pMac, eHAL_STATUS_SUCCESS);
6744 }
6745 else
6746 {
6747 csrScanStartIdleScanTimer(pMac, nTime);
6748 }
6749 }
6750}
6751
6752
6753
6754
6755tANI_BOOLEAN csrScanRemoveNotRoamingScanCommand(tpAniSirGlobal pMac)
6756{
6757 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
6758 tListElem *pEntry, *pEntryTmp;
6759 tSmeCmd *pCommand;
6760 tDblLinkList localList;
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306761 tDblLinkList *pCmdList;
Jeff Johnson295189b2012-06-20 16:38:30 -07006762
6763 vos_mem_zero(&localList, sizeof(tDblLinkList));
6764 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
6765 {
6766 smsLog(pMac, LOGE, FL(" failed to open list"));
6767 return fRet;
6768 }
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306769 if (!pMac->fScanOffload)
6770 pCmdList = &pMac->sme.smeCmdPendingList;
6771 else
6772 pCmdList = &pMac->sme.smeScanCmdPendingList;
Jeff Johnson295189b2012-06-20 16:38:30 -07006773
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306774 csrLLLock(pCmdList);
6775 pEntry = csrLLPeekHead(pCmdList, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07006776 while(pEntry)
6777 {
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306778 pEntryTmp = csrLLNext(pCmdList, pEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07006779 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6780 if( eSmeCommandScan == pCommand->command )
6781 {
6782 switch( pCommand->u.scanCmd.reason )
6783 {
6784 case eCsrScanIdleScan:
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306785 if( csrLLRemoveEntry(pCmdList, pEntry, LL_ACCESS_NOLOCK) )
Jeff Johnson295189b2012-06-20 16:38:30 -07006786 {
6787 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
6788 }
6789 fRet = eANI_BOOLEAN_TRUE;
6790 break;
6791
6792 default:
6793 break;
6794 } //switch
6795 }
6796 pEntry = pEntryTmp;
6797 }
6798
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306799 csrLLUnlock(pCmdList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006800
6801 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
6802 {
6803 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6804 csrReleaseCommandScan( pMac, pCommand );
6805 }
6806
6807 csrLLClose(&localList);
6808
6809 return (fRet);
6810}
6811
6812
6813tANI_BOOLEAN csrScanRemoveFreshScanCommand(tpAniSirGlobal pMac, tANI_U8 sessionId)
6814{
6815 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
6816 tListElem *pEntry, *pEntryTmp;
6817 tSmeCmd *pCommand;
6818 tDblLinkList localList;
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306819 tDblLinkList *pCmdList;
Jeff Johnson295189b2012-06-20 16:38:30 -07006820
6821 vos_mem_zero(&localList, sizeof(tDblLinkList));
6822 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
6823 {
6824 smsLog(pMac, LOGE, FL(" failed to open list"));
6825 return fRet;
6826 }
6827
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306828 if (!pMac->fScanOffload)
6829 pCmdList = &pMac->sme.smeCmdPendingList;
6830 else
6831 pCmdList = &pMac->sme.smeScanCmdPendingList;
6832
6833 csrLLLock(pCmdList);
6834 pEntry = csrLLPeekHead(pCmdList, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07006835 while(pEntry)
6836 {
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306837 pEntryTmp = csrLLNext(pCmdList, pEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07006838 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6839 if( (eSmeCommandScan == pCommand->command) && (sessionId == pCommand->sessionId) )
6840 {
6841 switch(pCommand->u.scanCmd.reason)
6842 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006843#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
6844 case eCsrScanGetLfrResult:
6845#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006846 case eCsrScanGetResult:
6847 case eCsrScanSetBGScanParam:
6848 case eCsrScanBGScanAbort:
6849 case eCsrScanBGScanEnable:
6850 case eCsrScanGetScanChnInfo:
6851 break;
6852 default:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006853 smsLog (pMac, LOGW, "%s: -------- abort scan command reason = %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07006854 __func__, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07006855 //The rest are fresh scan requests
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306856 if( csrLLRemoveEntry(pCmdList, pEntry, LL_ACCESS_NOLOCK) )
Jeff Johnson295189b2012-06-20 16:38:30 -07006857 {
6858 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
6859 }
6860 fRet = eANI_BOOLEAN_TRUE;
6861 break;
6862 }
6863 }
6864 pEntry = pEntryTmp;
6865 }
6866
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306867 csrLLUnlock(pCmdList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006868
6869 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
6870 {
6871 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6872 if (pCommand->u.scanCmd.callback)
6873 {
6874 /* User scan request is pending,
6875 * send response with status eCSR_SCAN_ABORT*/
6876 pCommand->u.scanCmd.callback(pMac,
6877 pCommand->u.scanCmd.pContext,
6878 pCommand->u.scanCmd.scanID,
6879 eCSR_SCAN_ABORT);
6880 }
6881 csrReleaseCommandScan( pMac, pCommand );
6882 }
6883 csrLLClose(&localList);
6884
6885 return (fRet);
6886}
6887
6888
6889void csrReleaseScanCommand(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
6890{
6891 eCsrScanReason reason = pCommand->u.scanCmd.reason;
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306892 tANI_BOOLEAN status;
6893
6894 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07006895 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306896 tANI_U32 i;
6897 for(i = 0; i < CSR_ROAM_SESSION_MAX; i++)
6898 csrRoamStateChange(pMac, pCommand->u.scanCmd.lastRoamState[i], i);
6899 }
6900 else
6901 {
6902 csrRoamStateChange(pMac,
6903 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId],
6904 pCommand->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07006905 }
6906
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306907 csrScanCallCallback(pMac, pCommand, scanStatus);
Jeff Johnson295189b2012-06-20 16:38:30 -07006908
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006909 smsLog(pMac, LOG3, " Remove Scan command reason = %d", reason);
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306910 if (pMac->fScanOffload)
6911 {
6912 status = csrLLRemoveEntry(&pMac->sme.smeScanCmdActiveList,
6913 &pCommand->Link, LL_ACCESS_LOCK);
6914 }
6915 else
6916 {
6917 status = csrLLRemoveEntry(&pMac->sme.smeCmdActiveList,
6918 &pCommand->Link, LL_ACCESS_LOCK);
6919 }
6920
6921 if(status)
Jeff Johnson295189b2012-06-20 16:38:30 -07006922 {
6923 csrReleaseCommandScan( pMac, pCommand );
6924 }
6925 else
6926 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306927 smsLog(pMac, LOGE,
6928 " ********csrReleaseScanCommand cannot release command reason %d",
6929 pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07006930 }
6931}
6932
6933
6934eHalStatus csrScanGetPMKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
6935 tPmkidCandidateInfo *pPmkidList, tANI_U32 *pNumItems )
6936{
6937 eHalStatus status = eHAL_STATUS_SUCCESS;
6938 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
6939
Jeff Johnson32d95a32012-09-10 13:15:23 -07006940 if(!pSession)
6941 {
6942 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
6943 return eHAL_STATUS_FAILURE;
6944 }
6945
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006946 smsLog(pMac, LOGW, " pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07006947 csrResetPMKIDCandidateList(pMac, sessionId);
6948 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
6949 {
6950 tCsrScanResultFilter *pScanFilter;
6951 tCsrScanResultInfo *pScanResult;
6952 tScanResultHandle hBSSList;
6953 tANI_U32 nItems = *pNumItems;
6954
6955 *pNumItems = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05306956 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
6957 if ( NULL == pScanFilter )
6958 status = eHAL_STATUS_FAILURE;
6959 else
Jeff Johnson295189b2012-06-20 16:38:30 -07006960 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306961 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006962 //Here is the profile we need to connect to
6963 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
6964 if(HAL_STATUS_SUCCESS(status))
6965 {
6966 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
6967 if(HAL_STATUS_SUCCESS(status))
6968 {
6969 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumPmkidCandidate < nItems))
6970 {
6971 //NumPmkidCandidate adds up here
6972 csrProcessBSSDescForPMKIDList(pMac, &pScanResult->BssDescriptor,
6973 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
6974 }
6975 if(pSession->NumPmkidCandidate)
6976 {
6977 *pNumItems = pSession->NumPmkidCandidate;
Kiet Lam64c1b492013-07-12 13:56:44 +05306978 vos_mem_copy(pPmkidList, pSession->PmkidCandidateInfo,
6979 pSession->NumPmkidCandidate * sizeof(tPmkidCandidateInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07006980 }
6981 csrScanResultPurge(pMac, hBSSList);
6982 }//Have scan result
6983 csrFreeScanFilter(pMac, pScanFilter);
6984 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306985 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07006986 }
6987 }
6988
6989 return (status);
6990}
6991
6992
6993
6994#ifdef FEATURE_WLAN_WAPI
6995eHalStatus csrScanGetBKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
6996 tBkidCandidateInfo *pBkidList, tANI_U32 *pNumItems )
6997{
6998 eHalStatus status = eHAL_STATUS_SUCCESS;
6999 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
7000
Jeff Johnson32d95a32012-09-10 13:15:23 -07007001 if(!pSession)
7002 {
7003 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
7004 return eHAL_STATUS_FAILURE;
7005 }
7006
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007007 smsLog(pMac, LOGW, " pMac->scan.NumBkidCandidate = %d", pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07007008 csrResetBKIDCandidateList(pMac, sessionId);
7009 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
7010 {
7011 tCsrScanResultFilter *pScanFilter;
7012 tCsrScanResultInfo *pScanResult;
7013 tScanResultHandle hBSSList;
7014 tANI_U32 nItems = *pNumItems;
7015 *pNumItems = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05307016 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
7017 if ( NULL == pScanFilter )
7018 status = eHAL_STATUS_FAILURE;
7019 else
Jeff Johnson295189b2012-06-20 16:38:30 -07007020 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307021 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007022 //Here is the profile we need to connect to
7023 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
7024 if(HAL_STATUS_SUCCESS(status))
7025 {
7026 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
7027 if(HAL_STATUS_SUCCESS(status))
7028 {
7029 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumBkidCandidate < nItems))
7030 {
7031 //pMac->scan.NumBkidCandidate adds up here
7032 csrProcessBSSDescForBKIDList(pMac, &pScanResult->BssDescriptor,
7033 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
7034
7035 }
7036 if(pSession->NumBkidCandidate)
7037 {
7038 *pNumItems = pSession->NumBkidCandidate;
Kiet Lam64c1b492013-07-12 13:56:44 +05307039 vos_mem_copy(pBkidList, pSession->BkidCandidateInfo, pSession->NumBkidCandidate * sizeof(tBkidCandidateInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07007040 }
7041 csrScanResultPurge(pMac, hBSSList);
7042 }//Have scan result
7043 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307044 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07007045 }
7046 }
7047
7048 return (status);
7049}
7050#endif /* FEATURE_WLAN_WAPI */
7051
7052
7053
7054//This function is usually used for BSSs that suppresses SSID so the profile
7055//shall have one and only one SSID
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007056eHalStatus csrScanForSSID(tpAniSirGlobal pMac, tANI_U32 sessionId, tCsrRoamProfile *pProfile, tANI_U32 roamId, tANI_BOOLEAN notify)
Jeff Johnson295189b2012-06-20 16:38:30 -07007057{
7058 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
7059 tSmeCmd *pScanCmd = NULL;
7060 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
7061 tANI_U8 index = 0;
7062 tANI_U32 numSsid = pProfile->SSIDs.numOfSSIDs;
7063
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007064 smsLog(pMac, LOG2, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007065 //For WDS, we use the index 0. There must be at least one in there
7066 if( CSR_IS_WDS_STA( pProfile ) && numSsid )
7067 {
7068 numSsid = 1;
7069 }
7070 if(pMac->scan.fScanEnable && ( numSsid == 1 ) )
7071 {
7072 do
7073 {
7074 pScanCmd = csrGetCommandBuffer(pMac);
7075 if(!pScanCmd)
7076 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007077 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007078 break;
7079 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307080 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
7081 pScanCmd->u.scanCmd.pToRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
7082 if ( NULL == pScanCmd->u.scanCmd.pToRoamProfile )
7083 status = eHAL_STATUS_FAILURE;
7084 else
7085 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07007086 status = csrRoamCopyProfile(pMac, pScanCmd->u.scanCmd.pToRoamProfile, pProfile);
7087 if(!HAL_STATUS_SUCCESS(status))
7088 break;
7089 pScanCmd->u.scanCmd.roamId = roamId;
7090 pScanCmd->command = eSmeCommandScan;
Jeff Johnsone7245742012-09-05 17:12:55 -07007091 pScanCmd->sessionId = (tANI_U8)sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07007092 pScanCmd->u.scanCmd.callback = NULL;
7093 pScanCmd->u.scanCmd.pContext = NULL;
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007094 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 -07007095 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Kiet Lam64c1b492013-07-12 13:56:44 +05307096 vos_mem_set(&pScanCmd->u.scanCmd.u.scanRequest, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007097 pScanCmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Jeff Johnson295189b2012-06-20 16:38:30 -07007098 pScanCmd->u.scanCmd.u.scanRequest.BSSType = pProfile->BSSType;
Jeff Johnsone7245742012-09-05 17:12:55 -07007099 // To avoid 11b rate in probe request Set p2pSearch flag as 1 for P2P Client Mode
7100 if(VOS_P2P_CLIENT_MODE == pProfile->csrPersona)
7101 {
7102 pScanCmd->u.scanCmd.u.scanRequest.p2pSearch = 1;
7103 }
7104 if(pProfile->pAddIEScan)
7105 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307106 pScanCmd->u.scanCmd.u.scanRequest.pIEField = vos_mem_malloc(
7107 pProfile->nAddIEScanLength);
7108 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.pIEField )
7109 status = eHAL_STATUS_FAILURE;
7110 else
7111 status = eHAL_STATUS_SUCCESS;
7112 vos_mem_set(pScanCmd->u.scanCmd.u.scanRequest.pIEField,
7113 pProfile->nAddIEScanLength, 0);
7114 if (HAL_STATUS_SUCCESS(status))
Jeff Johnsone7245742012-09-05 17:12:55 -07007115 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307116 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.pIEField,
7117 pProfile->pAddIEScan, pProfile->nAddIEScanLength);
Jeff Johnsone7245742012-09-05 17:12:55 -07007118 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = pProfile->nAddIEScanLength;
7119 }
7120 else
7121 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007122 smsLog(pMac, LOGE, "No memory for scanning IE fields");
Jeff Johnsone7245742012-09-05 17:12:55 -07007123 }
7124 } //Allocate memory for IE field
7125 else
7126 {
7127 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = 0;
7128 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07007129 /* For one channel be good enpugh time to receive beacon atleast */
7130 if( 1 == pProfile->ChannelInfo.numOfChannels )
7131 {
7132 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime = MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7133 pScanCmd->u.scanCmd.u.scanRequest.minChnTime = MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7134 }
7135 else
7136 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307137 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime =
7138 pMac->roam.configParam.nActiveMaxChnTime;
7139 pScanCmd->u.scanCmd.u.scanRequest.minChnTime =
7140 pMac->roam.configParam.nActiveMinChnTime;
Jeff Johnson32d95a32012-09-10 13:15:23 -07007141 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307142 pScanCmd->u.scanCmd.u.scanRequest.maxChnTimeBtc =
7143 pMac->roam.configParam.nActiveMaxChnTimeBtc;
7144 pScanCmd->u.scanCmd.u.scanRequest.minChnTimeBtc =
7145 pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07007146 if(pProfile->BSSIDs.numOfBSSIDs == 1)
7147 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307148 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.bssid,
7149 pProfile->BSSIDs.bssid, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07007150 }
7151 else
7152 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307153 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.bssid, bAddr, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07007154 }
7155 if(pProfile->ChannelInfo.numOfChannels)
7156 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307157 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(
7158 sizeof(*pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
7159 * pProfile->ChannelInfo.numOfChannels);
7160 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
7161 status = eHAL_STATUS_FAILURE;
7162 else
7163 status = eHAL_STATUS_SUCCESS;
7164 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
7165 if(HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07007166 {
7167 csrRoamIsChannelValid(pMac, pProfile->ChannelInfo.ChannelList[0]);
7168 for(index = 0; index < pProfile->ChannelInfo.numOfChannels; index++)
7169 {
7170 if(csrRoamIsValidChannel(pMac, pProfile->ChannelInfo.ChannelList[index]))
7171 {
7172 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels]
7173 = pProfile->ChannelInfo.ChannelList[index];
7174 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels++;
7175 }
7176 else
7177 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007178 smsLog(pMac, LOGW, FL("process a channel (%d) that is invalid"), pProfile->ChannelInfo.ChannelList[index]);
Jeff Johnson295189b2012-06-20 16:38:30 -07007179 }
7180
7181 }
7182 }
7183 else
7184 {
7185 break;
7186 }
7187
7188 }
7189 else
7190 {
7191 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
7192 }
7193 if(pProfile->SSIDs.numOfSSIDs)
7194 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307195 pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList = vos_mem_malloc(
7196 pProfile->SSIDs.numOfSSIDs * sizeof(tCsrSSIDInfo));
7197 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList )
7198 status = eHAL_STATUS_FAILURE;
7199 else
7200 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07007201 if(!HAL_STATUS_SUCCESS(status))
7202 {
7203 break;
7204 }
7205 pScanCmd->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 1;
Kiet Lam64c1b492013-07-12 13:56:44 +05307206 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList,
7207 pProfile->SSIDs.SSIDList, sizeof(tCsrSSIDInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07007208 }
7209 //Start process the command
7210 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
7211 if( !HAL_STATUS_SUCCESS( status ) )
7212 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007213 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07007214 break;
7215 }
7216 }while(0);
7217 if(!HAL_STATUS_SUCCESS(status))
7218 {
7219 if(pScanCmd)
7220 {
7221 csrReleaseCommandScan(pMac, pScanCmd);
7222 //TODO:free the memory that is allocated in this function
7223 }
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007224 if(notify)
7225 {
Jeff Johnson295189b2012-06-20 16:38:30 -07007226 csrRoamCallCallback(pMac, sessionId, NULL, roamId, eCSR_ROAM_FAILED, eCSR_ROAM_RESULT_FAILURE);
7227 }
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007228 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007229 }//valid
7230 else
7231 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007232 smsLog(pMac, LOGE, FL("cannot scan because scanEnable (%d) or numSSID (%d) is invalid"),
Jeff Johnson295189b2012-06-20 16:38:30 -07007233 pMac->scan.fScanEnable, pProfile->SSIDs.numOfSSIDs);
7234 }
7235
7236 return (status);
7237}
7238
7239
7240//Issue a scan base on the new capability infomation
7241//This should only happen when the associated AP changes its capability.
7242//After this scan is done, CSR reroams base on the new scan results
7243eHalStatus csrScanForCapabilityChange(tpAniSirGlobal pMac, tSirSmeApNewCaps *pNewCaps)
7244{
7245 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
7246 tSmeCmd *pScanCmd = NULL;
7247
7248 if(pNewCaps)
7249 {
7250 do
7251 {
7252 pScanCmd = csrGetCommandBuffer(pMac);
7253 if(!pScanCmd)
7254 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007255 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007256 status = eHAL_STATUS_RESOURCES;
7257 break;
7258 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307259 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007260 status = eHAL_STATUS_SUCCESS;
7261 pScanCmd->u.scanCmd.roamId = 0;
7262 pScanCmd->command = eSmeCommandScan;
7263 pScanCmd->u.scanCmd.callback = NULL;
7264 pScanCmd->u.scanCmd.pContext = NULL;
7265 pScanCmd->u.scanCmd.reason = eCsrScanForCapsChange;
7266 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
7267 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
7268 if( !HAL_STATUS_SUCCESS( status ) )
7269 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007270 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07007271 break;
7272 }
7273 }while(0);
7274 if(!HAL_STATUS_SUCCESS(status))
7275 {
7276 if(pScanCmd)
7277 {
7278 csrReleaseCommandScan(pMac, pScanCmd);
7279 }
7280 }
7281 }
7282
7283 return (status);
7284}
7285
7286
7287
7288void csrInitBGScanChannelList(tpAniSirGlobal pMac)
7289{
7290 tANI_U32 len = CSR_MIN(sizeof(pMac->roam.validChannelList), sizeof(pMac->scan.bgScanChannelList));
7291
Kiet Lam64c1b492013-07-12 13:56:44 +05307292 vos_mem_set(pMac->scan.bgScanChannelList, len, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007293 pMac->scan.numBGScanChannel = 0;
7294
7295 if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
7296 {
7297 pMac->roam.numValidChannels = len;
7298 pMac->scan.numBGScanChannel = (tANI_U8)CSR_MIN(len, WNI_CFG_BG_SCAN_CHANNEL_LIST_LEN);
Kiet Lam64c1b492013-07-12 13:56:44 +05307299 vos_mem_copy(pMac->scan.bgScanChannelList, pMac->roam.validChannelList,
7300 pMac->scan.numBGScanChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07007301 csrSetBGScanChannelList(pMac, pMac->scan.bgScanChannelList, pMac->scan.numBGScanChannel);
7302 }
7303}
7304
7305
7306//This function return TRUE if background scan channel list is adjusted.
7307//this function will only shrink the background scan channel list
7308tANI_BOOLEAN csrAdjustBGScanChannelList(tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels,
7309 tANI_U8 *pAdjustChannels, tANI_U8 *pNumAdjustChannels)
7310{
7311 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
7312 tANI_U8 i, j, count = *pNumAdjustChannels;
7313
7314 i = 0;
7315 while(i < count)
7316 {
7317 for(j = 0; j < NumChannels; j++)
7318 {
7319 if(pChannelList[j] == pAdjustChannels[i])
7320 break;
7321 }
7322 if(j == NumChannels)
7323 {
7324 //This channel is not in the list, remove it
7325 fRet = eANI_BOOLEAN_TRUE;
7326 count--;
7327 if(count - i)
7328 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307329 vos_mem_copy(&pAdjustChannels[i], &pAdjustChannels[i+1], count - i);
Jeff Johnson295189b2012-06-20 16:38:30 -07007330 }
7331 else
7332 {
7333 //already remove the last one. Done.
7334 break;
7335 }
7336 }
7337 else
7338 {
7339 i++;
7340 }
7341 }//while(i<count)
7342 *pNumAdjustChannels = count;
7343
7344 return (fRet);
7345}
7346
7347
7348//Get the list of the base channels to scan for passively 11d info
7349eHalStatus csrScanGetSupportedChannels( tpAniSirGlobal pMac )
7350{
7351 eHalStatus status = eHAL_STATUS_SUCCESS;
7352 int n = WNI_CFG_VALID_CHANNEL_LIST_LEN;
7353
7354 status = vos_nv_getSupportedChannels( pMac->scan.baseChannels.channelList, &n, NULL, NULL );
7355 if( HAL_STATUS_SUCCESS(status) )
7356 {
7357 pMac->scan.baseChannels.numChannels = (tANI_U8)n;
7358 }
7359 else
7360 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007361 smsLog( pMac, LOGE, FL(" failed") );
Jeff Johnson295189b2012-06-20 16:38:30 -07007362 pMac->scan.baseChannels.numChannels = 0;
7363 }
7364
7365 return ( status );
7366}
7367
7368//This function use the input pChannelList to validate the current saved channel list
7369eHalStatus csrSetBGScanChannelList( tpAniSirGlobal pMac, tANI_U8 *pAdjustChannels, tANI_U8 NumAdjustChannels)
7370{
7371 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumAdjustChannels;
7372
7373 return (ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pAdjustChannels, dataLen, NULL, eANI_BOOLEAN_FALSE));
7374}
7375
7376
7377void csrSetCfgValidChannelList( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels )
7378{
7379 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumChannels;
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05307380 eHalStatus status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007381
7382 ccmCfgSetStr(pMac, WNI_CFG_VALID_CHANNEL_LIST, pChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
7383
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05307384 if (pMac->fScanOffload)
7385 {
7386 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
7387 "Scan offload is enabled, update default chan list");
7388 status = csrUpdateChannelList(&pMac->scan);
7389 if (eHAL_STATUS_SUCCESS != status)
7390 {
7391 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR,
7392 "failed to update the supported channel list");
7393 }
7394 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007395 return;
7396}
7397
7398
7399
7400/*
7401 * The Tx power limits are saved in the cfg for future usage.
7402 */
7403void csrSaveTxPowerToCfg( tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 cfgId )
7404{
7405 tListElem *pEntry;
7406 tANI_U32 cbLen = 0, dataLen;
7407 tCsrChannelPowerInfo *pChannelSet;
7408 tANI_U32 idx;
7409 tSirMacChanInfo *pChannelPowerSet;
7410 tANI_U8 *pBuf = NULL;
7411
7412 //allocate maximum space for all channels
7413 dataLen = WNI_CFG_VALID_CHANNEL_LIST_LEN * sizeof(tSirMacChanInfo);
Kiet Lam64c1b492013-07-12 13:56:44 +05307414 if ( (pBuf = vos_mem_malloc(dataLen)) != NULL )
Jeff Johnson295189b2012-06-20 16:38:30 -07007415 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307416 vos_mem_set(pBuf, dataLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007417 pChannelPowerSet = (tSirMacChanInfo *)(pBuf);
7418
7419 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
7420 // write the tuples (startChan, numChan, txPower) for each channel found in the channel power list.
7421 while( pEntry )
7422 {
7423 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
7424 if ( 1 != pChannelSet->interChannelOffset )
7425 {
7426 // we keep the 5G channel sets internally with an interchannel offset of 4. Expand these
7427 // to the right format... (inter channel offset of 1 is the only option for the triplets
7428 // that 11d advertises.
7429 if ((cbLen + (pChannelSet->numChannels * sizeof(tSirMacChanInfo))) >= dataLen)
7430 {
7431 // expanding this entry will overflow our allocation
7432 smsLog(pMac, LOGE,
7433 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007434 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07007435 pChannelSet->firstChannel,
7436 pChannelSet->numChannels,
7437 pChannelSet->interChannelOffset);
7438 break;
7439 }
7440
7441 for( idx = 0; idx < pChannelSet->numChannels; idx++ )
7442 {
7443 pChannelPowerSet->firstChanNum = (tSirMacChanNum)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007444 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07007445 pChannelPowerSet->numChannels = 1;
Jeff Johnson295189b2012-06-20 16:38:30 -07007446 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007447 smsLog(pMac, LOG3, " Setting Max Transmit Power %d", pChannelPowerSet->maxTxPower);
Jeff Johnson295189b2012-06-20 16:38:30 -07007448 cbLen += sizeof( tSirMacChanInfo );
7449 pChannelPowerSet++;
7450 }
7451 }
7452 else
7453 {
7454 if (cbLen >= dataLen)
7455 {
7456 // this entry will overflow our allocation
7457 smsLog(pMac, LOGE,
7458 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007459 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07007460 pChannelSet->firstChannel,
7461 pChannelSet->numChannels,
7462 pChannelSet->interChannelOffset);
7463 break;
7464 }
7465 pChannelPowerSet->firstChanNum = pChannelSet->firstChannel;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007466 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07007467 pChannelPowerSet->numChannels = pChannelSet->numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -07007468 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007469 smsLog(pMac, LOG3, " Setting Max Transmit Power %d, nTxPower %d", pChannelPowerSet->maxTxPower,pMac->roam.configParam.nTxPowerCap );
Jeff Johnson295189b2012-06-20 16:38:30 -07007470
7471
7472 cbLen += sizeof( tSirMacChanInfo );
7473 pChannelPowerSet++;
7474 }
7475
7476 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
7477 }
7478
7479 if(cbLen)
7480 {
7481 ccmCfgSetStr(pMac, cfgId, (tANI_U8 *)pBuf, cbLen, NULL, eANI_BOOLEAN_FALSE);
7482 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307483 vos_mem_free(pBuf);
Jeff Johnson295189b2012-06-20 16:38:30 -07007484 }//Allocate memory
7485}
7486
7487
7488void csrSetCfgCountryCode( tpAniSirGlobal pMac, tANI_U8 *countryCode )
7489{
7490 tANI_U8 cc[WNI_CFG_COUNTRY_CODE_LEN];
7491 ///v_REGDOMAIN_t DomainId;
7492
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007493 smsLog( pMac, LOG3, "Setting Country Code in Cfg from csrSetCfgCountryCode %s",countryCode );
Kiet Lam64c1b492013-07-12 13:56:44 +05307494 vos_mem_copy(cc, countryCode, WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07007495
7496 // don't program the bogus country codes that we created for Korea in the MAC. if we see
7497 // the bogus country codes, program the MAC with the right country code.
7498 if ( ( 'K' == countryCode[ 0 ] && '1' == countryCode[ 1 ] ) ||
7499 ( 'K' == countryCode[ 0 ] && '2' == countryCode[ 1 ] ) ||
7500 ( 'K' == countryCode[ 0 ] && '3' == countryCode[ 1 ] ) ||
7501 ( 'K' == countryCode[ 0 ] && '4' == countryCode[ 1 ] ) )
7502 {
7503 // replace the alternate Korea country codes, 'K1', 'K2', .. with 'KR' for Korea
7504 cc[ 1 ] = 'R';
7505 }
7506 ccmCfgSetStr(pMac, WNI_CFG_COUNTRY_CODE, cc, WNI_CFG_COUNTRY_CODE_LEN, NULL, eANI_BOOLEAN_FALSE);
7507
7508 //Need to let HALPHY know about the current domain so it can apply some
7509 //domain-specific settings (TX filter...)
7510 /*if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(pMac, cc, &DomainId)))
7511 {
7512 halPhySetRegDomain(pMac, DomainId);
7513 }*/
7514}
7515
7516
7517
7518eHalStatus csrGetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pBuf, tANI_U8 *pbLen)
7519{
7520 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
7521 tANI_U32 len;
7522
7523 if(pBuf && pbLen && (*pbLen >= WNI_CFG_COUNTRY_CODE_LEN))
7524 {
7525 len = *pbLen;
7526 status = ccmCfgGetStr(pMac, WNI_CFG_COUNTRY_CODE, pBuf, &len);
7527 if(HAL_STATUS_SUCCESS(status))
7528 {
7529 *pbLen = (tANI_U8)len;
7530 }
7531 }
7532
7533 return (status);
7534}
7535
7536
7537void csrSetCfgScanControlList( tpAniSirGlobal pMac, tANI_U8 *countryCode, tCsrChannel *pChannelList )
7538{
7539 tANI_U8 i, j;
7540 tANI_BOOLEAN found=FALSE;
7541 tANI_U8 *pControlList = NULL;
7542 tANI_U32 len = WNI_CFG_SCAN_CONTROL_LIST_LEN;
7543
Kiet Lam64c1b492013-07-12 13:56:44 +05307544 if ( (pControlList = vos_mem_malloc(WNI_CFG_SCAN_CONTROL_LIST_LEN)) != NULL )
Jeff Johnson295189b2012-06-20 16:38:30 -07007545 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307546 vos_mem_set((void *)pControlList, WNI_CFG_SCAN_CONTROL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007547 if(HAL_STATUS_SUCCESS(ccmCfgGetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, &len)))
7548 {
7549 for (i = 0; i < pChannelList->numChannels; i++)
7550 {
7551 for (j = 0; j < len; j += 2)
7552 {
7553 if (pControlList[j] == pChannelList->channelList[i])
7554 {
7555 found = TRUE;
7556 break;
7557 }
7558 }
7559
7560 if (found) // insert a pair(channel#, flag)
7561 {
Gopichand Nakkala392cbc12013-05-28 16:15:00 +05307562 pControlList[j+1] = csrGetScanType(pMac, pControlList[j]);
Jeff Johnson295189b2012-06-20 16:38:30 -07007563 found = FALSE; // reset the flag
7564 }
7565
7566 }
7567
7568 ccmCfgSetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, len, NULL, eANI_BOOLEAN_FALSE);
7569 }//Successfully getting scan control list
Kiet Lam64c1b492013-07-12 13:56:44 +05307570 vos_mem_free(pControlList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007571 }//AllocateMemory
7572}
7573
7574
7575//if bgPeriod is 0, background scan is disabled. It is in millisecond units
7576eHalStatus csrSetCfgBackgroundScanPeriod(tpAniSirGlobal pMac, tANI_U32 bgPeriod)
7577{
7578 return (ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, bgPeriod, (tCcmCfgSetCallback) csrScanCcmCfgSetCallback, eANI_BOOLEAN_FALSE));
7579}
7580
7581
7582void csrScanCcmCfgSetCallback(tHalHandle hHal, tANI_S32 result)
7583{
7584 tListElem *pEntry = NULL;
7585 tSmeCmd *pCommand = NULL;
7586 tpAniSirGlobal pMac = PMAC_STRUCT( hHal );
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307587 tDblLinkList *pCmdList ;
7588
7589 if (!pMac->fScanOffload)
7590 pCmdList = &pMac->sme.smeCmdActiveList;
7591 else
7592 pCmdList = &pMac->sme.smeScanCmdActiveList;
7593
7594 pEntry = csrLLPeekHead( pCmdList, LL_ACCESS_LOCK );
Jeff Johnson295189b2012-06-20 16:38:30 -07007595 if ( pEntry )
7596 {
7597 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7598 if ( eSmeCommandScan == pCommand->command )
7599 {
7600 eCsrScanStatus scanStatus = (CCM_IS_RESULT_SUCCESS(result)) ? eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
7601 csrReleaseScanCommand(pMac, pCommand, scanStatus);
7602 }
7603 else
7604 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007605 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
Jeff Johnson295189b2012-06-20 16:38:30 -07007606 }
7607 }
7608 smeProcessPendingQueue( pMac );
7609}
7610
7611eHalStatus csrProcessSetBGScanParam(tpAniSirGlobal pMac, tSmeCmd *pCommand)
7612{
7613 eHalStatus status;
7614 tCsrBGScanRequest *pScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
7615 tANI_U32 dataLen = sizeof( tANI_U8 ) * pScanReq->ChannelInfo.numOfChannels;
7616
7617 //***setcfg for background scan channel list
7618 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MINIMUM_CHANNEL_TIME, pScanReq->minChnTime, NULL, eANI_BOOLEAN_FALSE);
7619 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MAXIMUM_CHANNEL_TIME, pScanReq->maxChnTime, NULL, eANI_BOOLEAN_FALSE);
7620 //Not set the background scan interval if not connected because bd scan should not be run if not connected
7621 if(!csrIsAllSessionDisconnected(pMac))
7622 {
7623 //If disbaling BG scan here, we need to stop aging as well
7624 if(pScanReq->scanInterval == 0)
7625 {
7626 //Stop aging because no new result is coming in
7627 csrScanStopResultAgingTimer(pMac);
7628 }
7629
7630#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
7631 {
7632 vos_log_scan_pkt_type *pScanLog = NULL;
7633
7634 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
7635 if(pScanLog)
7636 {
7637 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
7638 pScanLog->minChnTime = (v_U8_t)pScanReq->minChnTime;
7639 pScanLog->maxChnTime = (v_U8_t)pScanReq->maxChnTime;
7640 pScanLog->timeBetweenBgScan = (v_U8_t)pScanReq->scanInterval;
7641 pScanLog->numChannel = pScanReq->ChannelInfo.numOfChannels;
7642 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
7643 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307644 vos_mem_copy(pScanLog->channels,
7645 pScanReq->ChannelInfo.ChannelList,
7646 pScanLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07007647 }
7648 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
7649 }
7650 }
7651#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
7652
7653 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, pScanReq->scanInterval, NULL, eANI_BOOLEAN_FALSE);
7654 }
7655 else
7656 {
7657 //No need to stop aging because IDLE scan is still running
7658 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, 0, NULL, eANI_BOOLEAN_FALSE);
7659 }
7660
7661 if(pScanReq->SSID.length > WNI_CFG_SSID_LEN)
7662 {
7663 pScanReq->SSID.length = WNI_CFG_SSID_LEN;
7664 }
7665
7666 status = ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pScanReq->ChannelInfo.ChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
7667 status = ccmCfgSetStr(pMac, WNI_CFG_SSID, (tANI_U8 *)pScanReq->SSID.ssId, pScanReq->SSID.length, NULL, eANI_BOOLEAN_FALSE);
7668
7669
7670
7671 return (status);
7672}
7673
7674
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307675eHalStatus csrScanAbortMacScan(tpAniSirGlobal pMac, tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07007676{
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307677 eHalStatus status = eHAL_STATUS_FAILURE;
7678 tSirSmeScanAbortReq *pMsg;
Jeff Johnson295189b2012-06-20 16:38:30 -07007679 tANI_U16 msgLen;
7680 tListElem *pEntry;
7681 tSmeCmd *pCommand;
7682
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307683 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07007684 {
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307685#ifdef WLAN_AP_STA_CONCURRENCY
7686 csrLLLock(&pMac->scan.scanCmdPendingList);
7687 while(NULL !=
7688 (pEntry = csrLLRemoveHead(&pMac->scan.scanCmdPendingList,
7689 LL_ACCESS_NOLOCK)))
7690 {
Jeff Johnson295189b2012-06-20 16:38:30 -07007691
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307692 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7693 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
7694 }
7695 csrLLUnlock(&pMac->scan.scanCmdPendingList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007696#endif
7697
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307698 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
7699 csrRemoveCmdFromPendingList( pMac, &pMac->roam.roamCmdPendingList, eSmeCommandScan);
7700 csrRemoveCmdFromPendingList( pMac, &pMac->sme.smeCmdPendingList, eSmeCommandScan);
7701 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
7702
7703 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
7704 }
7705 else
7706 {
7707 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
7708 csrRemoveCmdWithSessionIdFromPendingList(pMac,
7709 sessionId,
7710 &pMac->sme.smeScanCmdPendingList,
7711 eSmeCommandScan);
7712 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
7713
7714 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
7715 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007716
7717 //We need to abort scan only if we are scanning
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307718 if(NULL != pEntry)
Jeff Johnson295189b2012-06-20 16:38:30 -07007719 {
7720 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307721 if(eSmeCommandScan == pCommand->command &&
7722 pCommand->sessionId == sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07007723 {
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307724 msgLen = (tANI_U16)(sizeof(tSirSmeScanAbortReq));
Kiet Lam64c1b492013-07-12 13:56:44 +05307725 pMsg = vos_mem_malloc(msgLen);
7726 if ( NULL == pMsg )
Jeff Johnson295189b2012-06-20 16:38:30 -07007727 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307728 status = eHAL_STATUS_FAILURE;
7729 smsLog(pMac, LOGE, FL("Failed to allocate memory for SmeScanAbortReq"));
7730 }
7731 else
7732 {
7733 vos_mem_set((void *)pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007734 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_ABORT_IND);
7735 pMsg->msgLen = pal_cpu_to_be16(msgLen);
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307736 pMsg->sessionId = sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07007737 status = palSendMBMessage(pMac->hHdd, pMsg);
7738 }
7739 }
7740 }
7741
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307742 return(status);
7743}
7744
7745void csrRemoveCmdWithSessionIdFromPendingList(tpAniSirGlobal pMac,
7746 tANI_U8 sessionId,
7747 tDblLinkList *pList,
7748 eSmeCommandType commandType)
7749{
7750 tDblLinkList localList;
7751 tListElem *pEntry;
7752 tSmeCmd *pCommand;
7753 tListElem *pEntryToRemove;
7754
7755 vos_mem_zero(&localList, sizeof(tDblLinkList));
7756 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
7757 {
7758 smsLog(pMac, LOGE, FL(" failed to open list"));
7759 return;
7760 }
7761
7762 csrLLLock(pList);
7763 if ((pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK)))
7764 {
7765
7766 /* Have to make sure we don't loop back to the head of the list,
7767 * which will happen if the entry is NOT on the list */
7768 while (pEntry)
7769 {
7770 pEntryToRemove = pEntry;
7771 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
7772 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
7773 if ((pCommand->command == commandType) &&
7774 (pCommand->sessionId == sessionId))
7775 {
7776 /* Remove that entry only */
7777 if (csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
7778 {
7779 csrLLInsertTail(&localList, pEntryToRemove,
7780 LL_ACCESS_NOLOCK);
7781 }
7782 }
7783 }
7784 }
7785 csrLLUnlock(pList);
7786
7787 while ((pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)))
7788 {
7789 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7790 csrAbortCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
7791 }
7792
7793 csrLLClose(&localList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007794}
7795
7796void csrRemoveCmdFromPendingList(tpAniSirGlobal pMac, tDblLinkList *pList,
7797 eSmeCommandType commandType )
7798{
7799 tDblLinkList localList;
7800 tListElem *pEntry;
7801 tSmeCmd *pCommand;
7802 tListElem *pEntryToRemove;
7803
7804 vos_mem_zero(&localList, sizeof(tDblLinkList));
7805 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
7806 {
7807 smsLog(pMac, LOGE, FL(" failed to open list"));
7808 return;
7809 }
7810
7811 csrLLLock(pList);
7812 if( !csrLLIsListEmpty( pList, LL_ACCESS_NOLOCK ) )
7813 {
7814 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK);
7815
7816 // Have to make sure we don't loop back to the head of the list, which will
7817 // happen if the entry is NOT on the list...
7818 while( pEntry )
7819 {
7820 pEntryToRemove = pEntry;
7821 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
7822 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
7823 if ( pCommand->command == commandType )
7824 {
7825 // Remove that entry only
7826 if(csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
7827 {
7828 csrLLInsertTail(&localList, pEntryToRemove, LL_ACCESS_NOLOCK);
7829 }
7830 }
7831 }
7832
7833
7834 }
7835 csrLLUnlock(pList);
7836
7837 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
7838 {
7839 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7840 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
7841 }
7842 csrLLClose(&localList);
7843
7844}
7845
7846
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307847eHalStatus csrScanAbortMacScanNotForConnect(tpAniSirGlobal pMac,
7848 tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07007849{
7850 eHalStatus status = eHAL_STATUS_SUCCESS;
7851
7852 if( !csrIsScanForRoamCommandActive( pMac ) )
7853 {
7854 //Only abort the scan if it is not used for other roam/connect purpose
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307855 status = csrScanAbortMacScan(pMac, sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07007856 }
7857
7858 return (status);
7859}
7860
7861
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05307862eHalStatus csrScanGetScanChannelInfo(tpAniSirGlobal pMac, tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07007863{
7864 eHalStatus status = eHAL_STATUS_SUCCESS;
7865 tSirMbMsg *pMsg;
7866 tANI_U16 msgLen;
7867
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05307868 if (pMac->fScanOffload)
7869 msgLen = (tANI_U16)(sizeof(tSirSmeGetScanChanReq));
7870 else
7871 msgLen = (tANI_U16)(sizeof(tSirMbMsg));
7872
Kiet Lam64c1b492013-07-12 13:56:44 +05307873 pMsg = vos_mem_malloc(msgLen);
7874 if ( NULL == pMsg )
7875 status = eHAL_STATUS_FAILURE;
7876 else
Jeff Johnson295189b2012-06-20 16:38:30 -07007877 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307878 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007879 pMsg->type = eWNI_SME_GET_SCANNED_CHANNEL_REQ;
7880 pMsg->msgLen = msgLen;
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05307881 if (pMac->fScanOffload)
7882 ((tSirSmeGetScanChanReq *)pMsg)->sessionId = sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07007883 status = palSendMBMessage(pMac->hHdd, pMsg);
7884 }
7885
7886 return( status );
7887}
7888
7889tANI_BOOLEAN csrRoamIsValidChannel( tpAniSirGlobal pMac, tANI_U8 channel )
7890{
7891 tANI_BOOLEAN fValid = FALSE;
7892 tANI_U32 idxValidChannels;
7893 tANI_U32 len = pMac->roam.numValidChannels;
7894
7895 for ( idxValidChannels = 0; ( idxValidChannels < len ); idxValidChannels++ )
7896 {
7897 if ( channel == pMac->roam.validChannelList[ idxValidChannels ] )
7898 {
7899 fValid = TRUE;
7900 break;
7901 }
7902 }
7903
7904 return fValid;
7905}
7906
Srikant Kuppa066904f2013-05-07 13:56:02 -07007907eHalStatus csrScanSavePreferredNetworkFound(tpAniSirGlobal pMac,
7908 tSirPrefNetworkFoundInd *pPrefNetworkFoundInd)
7909{
7910 v_U32_t uLen = 0;
7911 tpSirProbeRespBeacon pParsedFrame;
7912 tCsrScanResult *pScanResult = NULL;
7913 tSirBssDescription *pBssDescr = NULL;
7914 tANI_BOOLEAN fDupBss;
7915 tDot11fBeaconIEs *pIesLocal = NULL;
7916 tAniSSID tmpSsid;
7917 v_TIME_t timer=0;
7918 tpSirMacMgmtHdr macHeader = (tpSirMacMgmtHdr)pPrefNetworkFoundInd->data;
7919
7920 pParsedFrame =
Kiet Lam64c1b492013-07-12 13:56:44 +05307921 (tpSirProbeRespBeacon)vos_mem_malloc(sizeof(tSirProbeRespBeacon));
Srikant Kuppa066904f2013-05-07 13:56:02 -07007922
7923 if (NULL == pParsedFrame)
7924 {
7925 smsLog(pMac, LOGE, FL(" fail to allocate memory for frame"));
7926 return eHAL_STATUS_RESOURCES;
7927 }
7928
7929 if ( pPrefNetworkFoundInd->frameLength <= SIR_MAC_HDR_LEN_3A )
7930 {
7931 smsLog(pMac, LOGE,
7932 FL("Not enough bytes in PNO indication probe resp frame! length=%d"),
7933 pPrefNetworkFoundInd->frameLength);
7934 vos_mem_free(pParsedFrame);
7935 return eHAL_STATUS_FAILURE;
7936 }
7937
7938 if (sirConvertProbeFrame2Struct(pMac,
7939 &pPrefNetworkFoundInd->data[SIR_MAC_HDR_LEN_3A],
7940 pPrefNetworkFoundInd->frameLength - SIR_MAC_HDR_LEN_3A,
7941 pParsedFrame) != eSIR_SUCCESS ||
7942 !pParsedFrame->ssidPresent)
7943 {
7944 smsLog(pMac, LOGE,
7945 FL("Parse error ProbeResponse, length=%d"),
7946 pPrefNetworkFoundInd->frameLength);
7947 vos_mem_free(pParsedFrame);
7948 return eHAL_STATUS_FAILURE;
7949 }
7950 //24 byte MAC header and 12 byte to ssid IE
7951 if (pPrefNetworkFoundInd->frameLength >
7952 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET))
7953 {
7954 uLen = pPrefNetworkFoundInd->frameLength -
7955 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET);
7956 }
7957
Kiet Lam64c1b492013-07-12 13:56:44 +05307958 pScanResult = vos_mem_malloc(sizeof(tCsrScanResult) + uLen);
7959 if ( NULL == pScanResult )
Srikant Kuppa066904f2013-05-07 13:56:02 -07007960 {
7961 smsLog(pMac, LOGE, FL(" fail to allocate memory for frame"));
7962 vos_mem_free(pParsedFrame);
7963 return eHAL_STATUS_RESOURCES;
7964 }
7965
Kiet Lam64c1b492013-07-12 13:56:44 +05307966 vos_mem_set(pScanResult, sizeof(tCsrScanResult) + uLen, 0);
Srikant Kuppa066904f2013-05-07 13:56:02 -07007967 pBssDescr = &pScanResult->Result.BssDescriptor;
7968 /**
7969 * Length of BSS desription is without length of
7970 * length itself and length of pointer
7971 * that holds the next BSS description
7972 */
7973 pBssDescr->length = (tANI_U16)(
7974 sizeof(tSirBssDescription) - sizeof(tANI_U16) -
7975 sizeof(tANI_U32) + uLen);
7976 if (pParsedFrame->dsParamsPresent)
7977 {
7978 pBssDescr->channelId = pParsedFrame->channelNumber;
7979 }
7980 else if (pParsedFrame->HTInfo.present)
7981 {
7982 pBssDescr->channelId = pParsedFrame->HTInfo.primaryChannel;
7983 }
7984 else
7985 {
7986 pBssDescr->channelId = pParsedFrame->channelNumber;
7987 }
7988
7989 if ((pBssDescr->channelId > 0) && (pBssDescr->channelId < 15))
7990 {
7991 int i;
7992 // 11b or 11g packet
7993 // 11g iff extended Rate IE is present or
7994 // if there is an A rate in suppRate IE
7995 for (i = 0; i < pParsedFrame->supportedRates.numRates; i++)
7996 {
7997 if (sirIsArate(pParsedFrame->supportedRates.rate[i] & 0x7f))
7998 {
7999 pBssDescr->nwType = eSIR_11G_NW_TYPE;
8000 break;
8001 }
8002 }
8003 if (pParsedFrame->extendedRatesPresent)
8004 {
8005 pBssDescr->nwType = eSIR_11G_NW_TYPE;
8006 }
8007 }
8008 else
8009 {
8010 // 11a packet
8011 pBssDescr->nwType = eSIR_11A_NW_TYPE;
8012 }
8013
8014 pBssDescr->sinr = 0;
8015 pBssDescr->rssi = -1 * pPrefNetworkFoundInd->rssi;
8016 pBssDescr->beaconInterval = pParsedFrame->beaconInterval;
8017 pBssDescr->timeStamp[0] = pParsedFrame->timeStamp[0];
8018 pBssDescr->timeStamp[1] = pParsedFrame->timeStamp[1];
8019 pBssDescr->capabilityInfo = *((tANI_U16 *)&pParsedFrame->capabilityInfo);
Kiet Lam64c1b492013-07-12 13:56:44 +05308020 vos_mem_copy((tANI_U8 *) &pBssDescr->bssId, (tANI_U8 *) macHeader->bssId, sizeof(tSirMacAddr));
Srikant Kuppa066904f2013-05-07 13:56:02 -07008021 pBssDescr->nReceivedTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
8022
8023 smsLog( pMac, LOG2, "(%s):Bssid= %02x-%02x-%02x-%02x-%02x-%02x "
8024 "chan= %d, rssi = %d", __func__,
8025 pBssDescr->bssId[ 0 ], pBssDescr->bssId[ 1 ],
8026 pBssDescr->bssId[ 2 ], pBssDescr->bssId[ 3 ],
8027 pBssDescr->bssId[ 4 ], pBssDescr->bssId[ 5 ],
8028 pBssDescr->channelId,
8029 pBssDescr->rssi );
8030
8031 //IEs
8032 if (uLen)
8033 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308034 vos_mem_copy(&pBssDescr->ieFields,
8035 pPrefNetworkFoundInd->data + (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET),
8036 uLen);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008037 }
8038
8039 pIesLocal = (tDot11fBeaconIEs *)( pScanResult->Result.pvIes );
8040 if ( !pIesLocal &&
8041 (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
8042 &pScanResult->Result.BssDescriptor, &pIesLocal))) )
8043 {
8044 smsLog(pMac, LOGE, FL(" Cannot parse IEs"));
8045 csrFreeScanResultEntry(pMac, pScanResult);
8046 vos_mem_free(pParsedFrame);
8047 return eHAL_STATUS_RESOURCES;
8048 }
8049
8050 fDupBss = csrRemoveDupBssDescription( pMac,
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05308051 &pScanResult->Result.BssDescriptor, pIesLocal, &tmpSsid, &timer, FALSE);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008052 //Check whether we have reach out limit
8053 if ( CSR_SCAN_IS_OVER_BSS_LIMIT(pMac) )
8054 {
8055 //Limit reach
8056 smsLog(pMac, LOGE, FL(" BSS limit reached"));
8057 //Free the resources
8058 if( (pScanResult->Result.pvIes == NULL) && pIesLocal )
8059 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308060 vos_mem_free(pIesLocal);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008061 }
8062 csrFreeScanResultEntry(pMac, pScanResult);
8063 vos_mem_free(pParsedFrame);
8064 return eHAL_STATUS_RESOURCES;
8065 }
8066 //Add to scan cache
8067 csrScanAddResult(pMac, pScanResult, pIesLocal);
8068
Kiet Lamb537cfb2013-11-07 12:56:49 +05308069 if( (pScanResult->Result.pvIes == NULL) && pIesLocal )
8070 {
8071 vos_mem_free(pIesLocal);
8072 }
8073
Srikant Kuppa066904f2013-05-07 13:56:02 -07008074 vos_mem_free(pParsedFrame);
8075
8076 return eHAL_STATUS_SUCCESS;
8077}
8078
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008079#ifdef FEATURE_WLAN_LFR
8080void csrInitOccupiedChannelsList(tpAniSirGlobal pMac)
8081{
8082 tListElem *pEntry = NULL;
8083 tCsrScanResult *pBssDesc = NULL;
8084 tDot11fBeaconIEs *pIes = NULL;
Srinivas28b5b4e2012-12-12 13:07:53 -08008085 tpCsrNeighborRoamControlInfo pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
8086
8087 if (0 != pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels)
8088 {
8089 smsLog(pMac, LOG1, FL("%s: Ini file contains neighbor scan channel list,"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008090 " hence NO need to build occupied channel list (numChannels = %d)"),
Srinivas28b5b4e2012-12-12 13:07:53 -08008091 __func__, pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels);
8092 return;
8093 }
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008094
8095 if (!csrNeighborRoamIsNewConnectedProfile(pMac))
8096 {
8097 smsLog(pMac, LOG2, FL("%s: donot flush occupied list since current roam profile"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008098 " matches previous (numChannels = %d)"),
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008099 __func__, pMac->scan.occupiedChannels.numChannels);
8100 return;
8101 }
8102
8103 /* Empty occupied channels here */
8104 pMac->scan.occupiedChannels.numChannels = 0;
8105
8106 csrLLLock(&pMac->scan.scanResultList);
8107 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
8108 while( pEntry )
8109 {
8110 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
8111 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
8112
8113 //At this time, pBssDescription->Result.pvIes may be NULL
Srikant Kuppa866893f2012-12-27 17:28:14 -08008114 if( !pIes && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008115 &pBssDesc->Result.BssDescriptor, &pIes))) )
8116 {
8117 continue;
8118 }
8119
8120 csrScanAddToOccupiedChannels(pMac, pBssDesc, &pMac->scan.occupiedChannels, pIes);
8121
8122 /*
8123 * Free the memory allocated for pIes in csrGetParsedBssDescriptionIEs
8124 */
8125 if( (pBssDesc->Result.pvIes == NULL) && pIes )
8126 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308127 vos_mem_free(pIes);
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008128 }
8129
8130 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK );
8131 }//while
8132 csrLLUnlock(&pMac->scan.scanResultList);
Srikant Kuppa866893f2012-12-27 17:28:14 -08008133
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008134}
8135#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07008136
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008137eHalStatus csrScanCreateEntryInScanCache(tpAniSirGlobal pMac, tANI_U32 sessionId,
8138 tCsrBssid bssid, tANI_U8 channel)
8139{
8140 eHalStatus status = eHAL_STATUS_SUCCESS;
8141 tDot11fBeaconIEs *pNewIes = NULL;
8142 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
Praveen Kumar Sirisilla8bdfac42013-10-10 17:20:48 -07008143 tSirBssDescription *pNewBssDescriptor = NULL;
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008144 tANI_U32 size = 0;
8145
8146 if(NULL == pSession)
8147 {
8148 status = eHAL_STATUS_FAILURE;
8149 return status;
8150 }
8151 smsLog(pMac, LOG2, FL("csrScanCreateEntryInScanCache: Current bssid::"
8152 "0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x"),
8153 pSession->pConnectBssDesc->bssId[0],
8154 pSession->pConnectBssDesc->bssId[1],
8155 pSession->pConnectBssDesc->bssId[2],
8156 pSession->pConnectBssDesc->bssId[3],
8157 pSession->pConnectBssDesc->bssId[4],
8158 pSession->pConnectBssDesc->bssId[5]);
8159 smsLog(pMac, LOG2, FL("csrScanCreateEntryInScanCache: My bssid::"
8160 "0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x channel %d"),
8161 bssid[0],bssid[1],bssid[2],
8162 bssid[3],bssid[4],bssid[5],channel);
8163
8164 do
8165 {
8166 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
8167 pSession->pConnectBssDesc, &pNewIes)))
8168 {
8169 smsLog(pMac, LOGE, FL("%s: Failed to parse IEs"),
8170 __func__);
8171 status = eHAL_STATUS_FAILURE;
8172 break;
8173 }
8174
8175 size = pSession->pConnectBssDesc->length + sizeof(pSession->pConnectBssDesc->length);
Kiet Lam64c1b492013-07-12 13:56:44 +05308176 if (size)
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008177 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308178 pNewBssDescriptor = vos_mem_malloc(size);
8179 if ( NULL == pNewBssDescriptor )
8180 status = eHAL_STATUS_FAILURE;
8181 else
8182 status = eHAL_STATUS_SUCCESS;
8183 if (HAL_STATUS_SUCCESS(status))
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008184 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308185 vos_mem_copy(pNewBssDescriptor, pSession->pConnectBssDesc, size);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008186 }
8187 else
8188 {
8189 smsLog(pMac, LOGE, FL("%s: memory allocation failed"),
8190 __func__);
8191 status = eHAL_STATUS_FAILURE;
8192 break;
8193 }
8194
8195 //change the BSSID & channel as passed
Kiet Lam64c1b492013-07-12 13:56:44 +05308196 vos_mem_copy(pNewBssDescriptor->bssId, bssid, sizeof(tSirMacAddr));
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008197 pNewBssDescriptor->channelId = channel;
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07008198 if(NULL == csrScanAppendBssDescription( pMac, pNewBssDescriptor, pNewIes, TRUE ))
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008199 {
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07008200 smsLog(pMac, LOGE, FL("%s: csrScanAppendBssDescription failed"),
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008201 __func__);
8202 status = eHAL_STATUS_FAILURE;
8203 break;
8204 }
8205 }
8206 else
8207 {
8208 smsLog(pMac, LOGE, FL("%s: length of bss descriptor is 0"),
8209 __func__);
8210 status = eHAL_STATUS_FAILURE;
8211 break;
8212 }
8213 smsLog(pMac, LOGE, FL("%s: entry successfully added in scan cache"),
8214 __func__);
8215 }while(0);
8216
8217 if(pNewIes)
8218 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308219 vos_mem_free(pNewIes);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008220 }
8221 if(pNewBssDescriptor)
8222 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308223 vos_mem_free(pNewBssDescriptor);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008224 }
8225 return status;
8226}
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07008227
8228#ifdef FEATURE_WLAN_CCX
8229// Update the TSF with the difference in system time
8230void UpdateCCKMTSF(tANI_U32 *timeStamp0, tANI_U32 *timeStamp1, tANI_U32 *incr)
8231{
8232 tANI_U64 timeStamp64 = ((tANI_U64)*timeStamp1 << 32) | (*timeStamp0);
8233
8234 timeStamp64 = (tANI_U64)(timeStamp64 + (tANI_U64)*incr);
8235 *timeStamp0 = (tANI_U32)(timeStamp64 & 0xffffffff);
8236 *timeStamp1 = (tANI_U32)((timeStamp64 >> 32) & 0xffffffff);
8237}
8238#endif