blob: 9ee20429f5bc1c5ecce3c581f7060bbf6cd62411 [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 }
3114 }
3115
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303116 // Calculating 30% of current rssi is an idea for not to change
3117 // country code so freq.
3118 if (rssi_of_current_country != -128)
3119 {
3120 rssi_of_current_country = rssi_of_current_country
3121 - THIRTY_PERCENT(rssi_of_current_country);
3122 }
3123
3124 if ((rssi_of_current_country <= cand_Bss_rssi ) || rssi_of_current_country == -128)
3125 {
3126 csrLLLock(&pMac->scan.scanResultList);
3127 pEntryTemp = csrLLPeekHead(&pMac->scan.scanResultList, LL_ACCESS_NOLOCK);
3128 while ( NULL != pEntryTemp)
3129 {
3130 pNext = csrLLNext(&pMac->scan.scanResultList, pEntryTemp,
3131 LL_ACCESS_NOLOCK);
3132 pBssDescription = GET_BASE_ADDR( pEntryTemp, tCsrScanResult, Link );
3133 pIesLocal = (tDot11fBeaconIEs *)( pBssDescription->Result.pvIes );
3134 // Need to traverse whole scan list to get description for best 11d AP.
3135 if (csrIsMacAddressEqual(pMac, (tCsrBssid *)&bssid_temp,
3136 (tCsrBssid *) pBssDescription->Result.BssDescriptor.bssId))
3137 {
3138 palCopyMemory(pMac->hHdd, pMac->scan.currentCountryBssid,
3139 bssid_temp, sizeof(tSirMacAddr));
3140 // Best AP should be passed to update reg domain.
3141 csrLearnCountryInformation( pMac, &pBssDescription->Result.BssDescriptor,
Tushnim Bhattacharyyaae317772013-10-23 18:55:38 -07003142 pIesLocal, eANI_BOOLEAN_TRUE );
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303143 break;
3144 }
3145 pEntryTemp = pNext;
3146 }
3147 csrLLUnlock(&pMac->scan.scanResultList);
3148 }
3149
3150
Tushnim Bhattacharyyaae317772013-10-23 18:55:38 -07003151end:
3152 //If we can find the current 11d info in any of the scan results, or
Jeff Johnson295189b2012-06-20 16:38:30 -07003153 // a good enough AP with the 11d info from the scan results then no need to
3154 // get into ambiguous state
3155 if(pMac->scan.fAmbiguous11dInfoFound)
3156 {
3157 if((pMac->scan.fCurrent11dInfoMatch) || (cand_Bss_rssi != -128))
3158 {
3159 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
3160 }
3161 }
3162
3163#ifdef FEATURE_WLAN_WAPI
3164 if(fNewWapiBSSForCurConnection)
3165 {
3166 //remember it first
3167 csrRoamCallCallback(pMac, sessionId, NULL, 0, eCSR_ROAM_SCAN_FOUND_NEW_BSS, eCSR_ROAM_RESULT_NEW_WAPI_BSS);
3168 }
3169#endif /* FEATURE_WLAN_WAPI */
3170
3171 return;
3172}
3173
3174
3175static tCsrScanResult *csrScanSaveBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pBSSDescription,
3176 tDot11fBeaconIEs *pIes)
3177{
3178 tCsrScanResult *pCsrBssDescription = NULL;
3179 tANI_U32 cbBSSDesc;
3180 tANI_U32 cbAllocated;
Jeff Johnson295189b2012-06-20 16:38:30 -07003181
3182 // figure out how big the BSS description is (the BSSDesc->length does NOT
3183 // include the size of the length field itself).
3184 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
3185
3186 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
3187
Kiet Lam64c1b492013-07-12 13:56:44 +05303188 pCsrBssDescription = vos_mem_malloc(cbAllocated);
3189 if ( NULL != pCsrBssDescription )
Jeff Johnson295189b2012-06-20 16:38:30 -07003190 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303191 vos_mem_set(pCsrBssDescription, cbAllocated, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003192 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Kiet Lam64c1b492013-07-12 13:56:44 +05303193 vos_mem_copy(&pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc);
Jeff Johnson295189b2012-06-20 16:38:30 -07003194#if defined(VOSS_ENSBALED)
3195 VOS_ASSERT( pCsrBssDescription->Result.pvIes == NULL );
3196#endif
3197 csrScanAddResult(pMac, pCsrBssDescription, pIes);
3198 }
3199
3200 return( pCsrBssDescription );
3201}
3202
3203// Append a Bss Description...
3204tCsrScanResult *csrScanAppendBssDescription( tpAniSirGlobal pMac,
3205 tSirBssDescription *pSirBssDescription,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07003206 tDot11fBeaconIEs *pIes, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07003207{
3208 tCsrScanResult *pCsrBssDescription = NULL;
3209 tAniSSID tmpSsid;
3210 v_TIME_t timer = 0;
3211 int result;
3212
3213 tmpSsid.length = 0;
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07003214 result = csrRemoveDupBssDescription( pMac, pSirBssDescription, pIes, &tmpSsid, &timer, fForced );
Jeff Johnson295189b2012-06-20 16:38:30 -07003215 pCsrBssDescription = csrScanSaveBssDescription( pMac, pSirBssDescription, pIes );
3216 if (result && (pCsrBssDescription != NULL))
3217 {
3218 //Check if the new one has SSID it it, if not, use the older SSID if it exists.
3219 if( (0 == pCsrBssDescription->Result.ssId.length) && tmpSsid.length )
3220 {
3221 //New BSS has a hidden SSID and old one has the SSID. Keep the SSID only
3222 //if diff of saved SSID time and current time is less than 1 min to avoid
3223 //side effect of saving SSID with old one is that if AP changes its SSID while remain
3224 //hidden, we may never see it and also to address the requirement of
3225 //When we remove hidden ssid from the profile i.e., forget the SSID via
3226 // GUI that SSID shouldn't see in the profile
3227 if((vos_timer_get_system_time()-timer) <= HIDDEN_TIMER)
3228 {
3229 pCsrBssDescription->Result.ssId = tmpSsid;
3230 pCsrBssDescription->Result.timer = timer;
3231 }
3232 }
3233 }
3234
3235
3236 return( pCsrBssDescription );
3237}
3238
3239
3240
3241void csrPurgeChannelPower( tpAniSirGlobal pMac, tDblLinkList *pChannelList )
3242{
3243 tCsrChannelPowerInfo *pChannelSet;
3244 tListElem *pEntry;
3245
3246 csrLLLock(pChannelList);
3247 // Remove the channel sets from the learned list and put them in the free list
3248 while( ( pEntry = csrLLRemoveHead( pChannelList, LL_ACCESS_NOLOCK ) ) != NULL)
3249 {
3250 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3251 if( pChannelSet )
3252 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303253 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003254 }
3255 }
3256 csrLLUnlock(pChannelList);
3257 return;
3258}
3259
3260
3261/*
3262 * Save the channelList into the ultimate storage as the final stage of channel
3263 * Input: pCountryInfo -- the country code (e.g. "USI"), channel list, and power limit are all stored inside this data structure
3264 */
Jeff Johnsone7245742012-09-05 17:12:55 -07003265eHalStatus csrSaveToChannelPower2G_5G( tpAniSirGlobal pMac, tANI_U32 tableSize, tSirMacChanInfo *channelTable )
Jeff Johnson295189b2012-06-20 16:38:30 -07003266{
3267 tANI_U32 i = tableSize / sizeof( tSirMacChanInfo );
3268 tSirMacChanInfo *pChannelInfo;
3269 tCsrChannelPowerInfo *pChannelSet;
3270 tANI_BOOLEAN f2GHzInfoFound = FALSE;
3271 tANI_BOOLEAN f2GListPurged = FALSE, f5GListPurged = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003272
3273 pChannelInfo = channelTable;
3274 // atleast 3 bytes have to be remaining -- from "countryString"
3275 while ( i-- )
3276 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303277 pChannelSet = vos_mem_malloc(sizeof(tCsrChannelPowerInfo));
3278 if ( NULL != pChannelSet )
Jeff Johnson295189b2012-06-20 16:38:30 -07003279 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303280 vos_mem_set(pChannelSet, sizeof(tCsrChannelPowerInfo), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003281 pChannelSet->firstChannel = pChannelInfo->firstChanNum;
3282 pChannelSet->numChannels = pChannelInfo->numChannels;
3283
3284 // Now set the inter-channel offset based on the frequency band the channel set lies in
Jeff Johnsone7245742012-09-05 17:12:55 -07003285 if( (CSR_IS_CHANNEL_24GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003286 ((pChannelSet->firstChannel + (pChannelSet->numChannels - 1)) <= CSR_MAX_24GHz_CHANNEL_NUMBER) )
Jeff Johnsone7245742012-09-05 17:12:55 -07003287
Jeff Johnson295189b2012-06-20 16:38:30 -07003288 {
3289 pChannelSet->interChannelOffset = 1;
3290 f2GHzInfoFound = TRUE;
3291 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003292 else if ( (CSR_IS_CHANNEL_5GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003293 ((pChannelSet->firstChannel + ((pChannelSet->numChannels - 1) * 4)) <= CSR_MAX_5GHz_CHANNEL_NUMBER) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003294 {
3295 pChannelSet->interChannelOffset = 4;
3296 f2GHzInfoFound = FALSE;
3297 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003298 else
3299 {
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003300 smsLog( pMac, LOGW, FL("Invalid Channel %d Present in Country IE"),
Jeff Johnsone7245742012-09-05 17:12:55 -07003301 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303302 vos_mem_free(pChannelSet);
Jeff Johnsone7245742012-09-05 17:12:55 -07003303 return eHAL_STATUS_FAILURE;
3304 }
3305
Jeff Johnson295189b2012-06-20 16:38:30 -07003306 pChannelSet->txPower = CSR_ROAM_MIN( pChannelInfo->maxTxPower, pMac->roam.configParam.nTxPowerCap );
3307
3308 if( f2GHzInfoFound )
3309 {
3310 if( !f2GListPurged )
3311 {
3312 // purge previous results if found new
3313 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList24 );
3314 f2GListPurged = TRUE;
3315 }
3316
3317 if(CSR_IS_OPERATING_BG_BAND(pMac))
3318 {
3319 // add to the list of 2.4 GHz channel sets
3320 csrLLInsertTail( &pMac->scan.channelPowerInfoList24, &pChannelSet->link, LL_ACCESS_LOCK );
3321 }
3322 else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003323 smsLog( pMac, LOGW, FL("Adding 11B/G channels in 11A mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003324 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303325 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003326 }
3327 }
3328 else
3329 {
3330 // 5GHz info found
3331 if( !f5GListPurged )
3332 {
3333 // purge previous results if found new
3334 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList5G );
3335 f5GListPurged = TRUE;
3336 }
3337
3338 if(CSR_IS_OPERATING_A_BAND(pMac))
3339 {
3340 // add to the list of 5GHz channel sets
3341 csrLLInsertTail( &pMac->scan.channelPowerInfoList5G, &pChannelSet->link, LL_ACCESS_LOCK );
3342 }
3343 else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003344 smsLog( pMac, LOGW, FL("Adding 11A channels in B/G mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003345 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303346 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003347 }
3348 }
3349 }
3350
3351 pChannelInfo++; // move to next entry
3352 }
3353
Jeff Johnsone7245742012-09-05 17:12:55 -07003354 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07003355}
3356
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303357static void csrClearDfsChannelList( tpAniSirGlobal pMac )
3358{
3359 tSirMbMsg *pMsg;
3360 tANI_U16 msgLen;
Jeff Johnson295189b2012-06-20 16:38:30 -07003361
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303362 msgLen = (tANI_U16)(sizeof( tSirMbMsg ));
Kiet Lam64c1b492013-07-12 13:56:44 +05303363 pMsg = vos_mem_malloc(msgLen);
3364 if ( NULL != pMsg )
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303365 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303366 vos_mem_set((void *)pMsg, msgLen, 0);
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303367 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_CLEAR_DFS_CHANNEL_LIST);
3368 pMsg->msgLen = pal_cpu_to_be16(msgLen);
3369 palSendMBMessage(pMac->hHdd, pMsg);
3370 }
3371}
Jeff Johnson295189b2012-06-20 16:38:30 -07003372
3373void csrApplyPower2Current( tpAniSirGlobal pMac )
3374{
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003375 smsLog( pMac, LOG3, FL(" Updating Cfg with power settings"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003376 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList24, WNI_CFG_MAX_TX_POWER_2_4 );
3377 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList5G, WNI_CFG_MAX_TX_POWER_5 );
3378}
3379
3380
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003381void csrApplyChannelPowerCountryInfo( tpAniSirGlobal pMac, tCsrChannel *pChannelList, tANI_U8 *countryCode, tANI_BOOLEAN updateRiva)
Jeff Johnson295189b2012-06-20 16:38:30 -07003382{
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303383 int i, j, count, countryIndex = -1;
Jeff Johnson295189b2012-06-20 16:38:30 -07003384 eNVChannelEnabledType channelEnabledType;
3385 tANI_U8 numChannels = 0;
3386 tANI_U8 tempNumChannels = 0;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303387 tANI_U8 channelIgnore = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003388 tCsrChannel ChannelList;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303389
Jeff Johnson295189b2012-06-20 16:38:30 -07003390 if( pChannelList->numChannels )
3391 {
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303392 for(count=0; count < MAX_COUNTRY_IGNORE; count++)
3393 {
3394 if(vos_mem_compare(countryCode, countryIgnoreList[count].countryCode,
3395 VOS_COUNTRY_CODE_LEN))
3396 {
3397 countryIndex = count;
3398 break;
3399 }
3400 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003401 tempNumChannels = CSR_MIN(pChannelList->numChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN);
3402 /* If user doesn't want to scan the DFS channels lets trim them from
3403 the valid channel list*/
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303404 for(i=0; i < tempNumChannels; i++)
Jeff Johnson295189b2012-06-20 16:38:30 -07003405 {
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303406 channelIgnore = FALSE;
3407 if( FALSE == pMac->scan.fEnableDFSChnlScan )
3408 {
3409 channelEnabledType =
3410 vos_nv_getChannelEnabledState(pChannelList->channelList[i]);
3411 }
3412 else
3413 {
Madan Mohan Koyyalamudi3f65e312012-11-06 15:31:12 -08003414 channelEnabledType = NV_CHANNEL_ENABLE;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303415 }
3416 if( NV_CHANNEL_ENABLE == channelEnabledType )
3417 {
3418 if( countryIndex != -1 )
3419 {
3420 for(j=0; j < countryIgnoreList[countryIndex].channelCount; j++)
3421 {
3422 if( pChannelList->channelList[i] ==
3423 countryIgnoreList[countryIndex].channelList[j] )
3424 {
3425 channelIgnore = TRUE;
3426 break;
3427 }
3428 }
3429 }
3430 if( FALSE == channelIgnore )
3431 {
3432 ChannelList.channelList[numChannels] = pChannelList->channelList[i];
3433 numChannels++;
3434 }
3435 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003436 }
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303437 ChannelList.numChannels = numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -07003438 csrSetCfgValidChannelList(pMac, ChannelList.channelList, ChannelList.numChannels);
3439 // extend scan capability
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303440 // build a scan list based on the channel list : channel# + active/passive scan
3441 csrSetCfgScanControlList(pMac, countryCode, &ChannelList);
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303442 /*Send msg to Lim to clear DFS channel list */
3443 csrClearDfsChannelList(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07003444#ifdef FEATURE_WLAN_SCAN_PNO
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003445 if (updateRiva)
3446 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003447 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO, FL(" Sending 11d PNO info to Riva"));
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003448 // Send HAL UpdateScanParams message
3449 pmcUpdateScanParams(pMac, &(pMac->roam.configParam), &ChannelList, TRUE);
3450 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003451#endif // FEATURE_WLAN_SCAN_PNO
3452 }
3453 else
3454 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003455 smsLog( pMac, LOGE, FL(" 11D channel list is empty"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003456 }
3457 csrApplyPower2Current( pMac ); // Store the channel+power info in the global place: Cfg
3458 csrSetCfgCountryCode(pMac, countryCode);
3459}
3460
3461
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003462void csrResetCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce, tANI_BOOLEAN updateRiva )
Jeff Johnson295189b2012-06-20 16:38:30 -07003463{
3464 if( fForce || (csrIs11dSupported( pMac ) && (!pMac->scan.f11dInfoReset)))
3465 {
3466
3467#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3468 {
3469 vos_log_802_11d_pkt_type *p11dLog;
3470 int Index;
3471
3472 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
3473 if(p11dLog)
3474 {
3475 p11dLog->eventId = WLAN_80211D_EVENT_RESET;
Kiet Lam64c1b492013-07-12 13:56:44 +05303476 vos_mem_copy(p11dLog->countryCode, pMac->scan.countryCodeCurrent, 3);
Jeff Johnson295189b2012-06-20 16:38:30 -07003477 p11dLog->numChannel = pMac->scan.base20MHzChannels.numChannels;
3478 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
3479 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303480 vos_mem_copy(p11dLog->Channels,
3481 pMac->scan.base20MHzChannels.channelList,
3482 p11dLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07003483 for (Index=0; Index < pMac->scan.base20MHzChannels.numChannels; Index++)
3484 {
3485 p11dLog->TxPwr[Index] = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
3486 }
3487 }
3488 if(!pMac->roam.configParam.Is11dSupportEnabled)
3489 {
3490 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
3491 }
3492 else if(pMac->roam.configParam.fEnforceDefaultDomain)
3493 {
3494 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
3495 }
3496 else
3497 {
3498 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
3499 }
3500 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
3501 }
3502 }
3503#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3504
3505 // switch to passive scans only when 11d is enabled
3506 if( csrIs11dSupported( pMac ) )
3507 {
3508 pMac->scan.curScanType = eSIR_PASSIVE_SCAN;
3509 }
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003510
3511 csrPruneChannelListForMode(pMac, &pMac->scan.baseChannels);
3512 csrPruneChannelListForMode(pMac, &pMac->scan.base20MHzChannels);
3513
Jeff Johnson295189b2012-06-20 16:38:30 -07003514 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_FALSE);
3515 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_TRUE);
3516 // ... and apply the channel list, power settings, and the country code.
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003517 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.base20MHzChannels, pMac->scan.countryCodeCurrent, updateRiva );
Jeff Johnson295189b2012-06-20 16:38:30 -07003518 // clear the 11d channel list
Kiet Lam64c1b492013-07-12 13:56:44 +05303519 vos_mem_set(&pMac->scan.channels11d, sizeof(pMac->scan.channels11d), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003520 pMac->scan.f11dInfoReset = eANI_BOOLEAN_TRUE;
3521 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_FALSE;
3522 }
3523
3524 return;
3525}
3526
3527
3528eHalStatus csrResetCountryCodeInformation(tpAniSirGlobal pMac, tANI_BOOLEAN *pfRestartNeeded)
3529{
3530 eHalStatus status = eHAL_STATUS_SUCCESS;
3531 tANI_BOOLEAN fRestart = eANI_BOOLEAN_FALSE;
3532
3533 //Use the Country code and domain from EEPROM
Kiet Lam64c1b492013-07-12 13:56:44 +05303534 vos_mem_copy(pMac->scan.countryCodeCurrent, pMac->scan.countryCodeDefault,
3535 WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07003536 csrSetRegulatoryDomain(pMac, pMac->scan.domainIdCurrent, &fRestart);
Jeff Johnson43971f52012-07-17 12:26:56 -07003537 if( ((eANI_BOOLEAN_FALSE == fRestart) || (pfRestartNeeded == NULL) )
3538 && !csrIsInfraConnected(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -07003539 {
3540 //Only reset the country info if we don't need to restart
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003541 csrResetCountryInformation(pMac, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07003542 }
3543 if(pfRestartNeeded)
3544 {
3545 *pfRestartNeeded = fRestart;
3546 }
3547
3548 return (status);
3549}
3550
3551
3552eHalStatus csrSetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pCountry, tANI_BOOLEAN *pfRestartNeeded)
3553{
3554 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
3555 v_REGDOMAIN_t domainId;
3556
3557 if(pCountry)
3558 {
Kiet Lam6c583332013-10-14 05:37:09 +05303559 status = csrGetRegulatoryDomainForCountry(pMac, pCountry, &domainId, COUNTRY_USER);
Jeff Johnson295189b2012-06-20 16:38:30 -07003560 if(HAL_STATUS_SUCCESS(status))
3561 {
3562 status = csrSetRegulatoryDomain(pMac, domainId, pfRestartNeeded);
3563 if(HAL_STATUS_SUCCESS(status))
3564 {
3565 //We don't need to check the pMac->roam.configParam.fEnforceDefaultDomain flag here,
3566 //csrSetRegulatoryDomain will fail if the country doesn't fit our domain criteria.
Kiet Lam64c1b492013-07-12 13:56:44 +05303567 vos_mem_copy(pMac->scan.countryCodeCurrent, pCountry, WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07003568 if((pfRestartNeeded == NULL) || !(*pfRestartNeeded))
3569 {
3570 //Simply set it to cfg. If we need to restart, restart will apply it to the CFG
3571 csrSetCfgCountryCode(pMac, pCountry);
3572 }
3573 }
3574 }
3575 }
3576
3577 return (status);
3578}
3579
3580
3581
3582//caller allocated memory for pNumChn and pChnPowerInfo
3583//As input, *pNumChn has the size of the array of pChnPowerInfo
3584//Upon return, *pNumChn has the number of channels assigned.
3585void csrGetChannelPowerInfo( tpAniSirGlobal pMac, tDblLinkList *pList,
3586 tANI_U32 *pNumChn, tChannelListWithPower *pChnPowerInfo)
3587{
3588 tListElem *pEntry;
3589 tANI_U32 chnIdx = 0, idx;
3590 tCsrChannelPowerInfo *pChannelSet;
3591
3592 //Get 2.4Ghz first
3593 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
3594 while( pEntry && (chnIdx < *pNumChn) )
3595 {
3596 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3597 if ( 1 != pChannelSet->interChannelOffset )
3598 {
3599 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
3600 {
3601 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
3602 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
3603 }
3604 }
3605 else
3606 {
3607 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
3608 {
3609 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + idx);
3610 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
3611 }
3612 }
3613
3614 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
3615 }
3616 *pNumChn = chnIdx;
3617
3618 return ;
3619}
3620
3621
3622
3623void csrApplyCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce )
3624{
3625 v_REGDOMAIN_t domainId;
3626 eHalStatus status = eHAL_STATUS_SUCCESS;
3627
3628 do
3629 {
3630 if( !csrIs11dSupported( pMac ) || 0 == pMac->scan.channelOf11dInfo) break;
3631 if( pMac->scan.fAmbiguous11dInfoFound )
3632 {
3633 // ambiguous info found
3634 //Restore te default domain as well
Kiet Lam6c583332013-10-14 05:37:09 +05303635 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
3636 pMac, pMac->scan.countryCodeCurrent,
3637 &domainId, COUNTRY_QUERY)))
Jeff Johnson295189b2012-06-20 16:38:30 -07003638 {
3639 pMac->scan.domainIdCurrent = domainId;
3640 }
3641 else
3642 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003643 smsLog(pMac, LOGE, FL(" failed to get domain from currentCountryCode %02X%02X"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003644 pMac->scan.countryCodeCurrent[0], pMac->scan.countryCodeCurrent[1]);
3645 }
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003646 csrResetCountryInformation( pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE );
Jeff Johnson295189b2012-06-20 16:38:30 -07003647 break;
3648 }
3649 if ( pMac->scan.f11dInfoApplied && !fForce ) break;
Kiet Lam6c583332013-10-14 05:37:09 +05303650 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
3651 pMac, pMac->scan.countryCode11d,
3652 &domainId, COUNTRY_QUERY)))
Jeff Johnson295189b2012-06-20 16:38:30 -07003653 {
3654 //Check whether we need to enforce default domain
3655 if( ( !pMac->roam.configParam.fEnforceDefaultDomain ) ||
3656 (pMac->scan.domainIdCurrent == domainId) )
3657 {
3658
3659#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3660 {
3661 vos_log_802_11d_pkt_type *p11dLog;
3662 tChannelListWithPower chnPwrInfo[WNI_CFG_VALID_CHANNEL_LIST_LEN];
3663 tANI_U32 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN, nTmp;
3664
3665 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
3666 if(p11dLog)
3667 {
3668 p11dLog->eventId = WLAN_80211D_EVENT_COUNTRY_SET;
Kiet Lam64c1b492013-07-12 13:56:44 +05303669 vos_mem_copy(p11dLog->countryCode, pMac->scan.countryCode11d, 3);
Jeff Johnson295189b2012-06-20 16:38:30 -07003670 p11dLog->numChannel = pMac->scan.channels11d.numChannels;
3671 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
3672 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303673 vos_mem_copy(p11dLog->Channels,
3674 pMac->scan.channels11d.channelList,
3675 p11dLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07003676 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList24,
3677 &nChnInfo, chnPwrInfo);
3678 nTmp = nChnInfo;
3679 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN - nTmp;
3680 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList5G,
3681 &nChnInfo, &chnPwrInfo[nTmp]);
3682 for(nTmp = 0; nTmp < p11dLog->numChannel; nTmp++)
3683 {
3684 for(nChnInfo = 0; nChnInfo < WNI_CFG_VALID_CHANNEL_LIST_LEN; nChnInfo++)
3685 {
3686 if(p11dLog->Channels[nTmp] == chnPwrInfo[nChnInfo].chanId)
3687 {
3688 p11dLog->TxPwr[nTmp] = chnPwrInfo[nChnInfo].pwr;
3689 break;
3690 }
3691 }
3692 }
3693 }
3694 if(!pMac->roam.configParam.Is11dSupportEnabled)
3695 {
3696 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
3697 }
3698 else if(pMac->roam.configParam.fEnforceDefaultDomain)
3699 {
3700 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
3701 }
3702 else
3703 {
3704 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
3705 }
3706 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
3707 }
3708 }
3709#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3710 if(pMac->scan.domainIdCurrent != domainId)
3711 {
Jeff Johnson295189b2012-06-20 16:38:30 -07003712 smsLog(pMac, LOGW, FL("Domain Changed Old %d, new %d"),
3713 pMac->scan.domainIdCurrent, domainId);
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +05303714 status = WDA_SetRegDomain(pMac, domainId);
Jeff Johnson295189b2012-06-20 16:38:30 -07003715 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003716 if (status != eHAL_STATUS_SUCCESS)
3717 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003718 smsLog( pMac, LOGE, FL(" fail to set regId %d"), domainId );
Jeff Johnson295189b2012-06-20 16:38:30 -07003719 }
3720 pMac->scan.domainIdCurrent = domainId;
Kiet Lam6c583332013-10-14 05:37:09 +05303721#ifndef CONFIG_ENABLE_LINUX_REG
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003722 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.channels11d, pMac->scan.countryCode11d, eANI_BOOLEAN_TRUE );
Kiet Lam6c583332013-10-14 05:37:09 +05303723#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07003724 // switch to active scans using this new channel list
3725 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
3726 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_TRUE;
3727 pMac->scan.f11dInfoReset = eANI_BOOLEAN_FALSE;
3728 }
3729 }
3730
3731 } while( 0 );
3732
3733 return;
3734}
3735
3736
3737
3738tANI_BOOLEAN csrSave11dCountryString( tpAniSirGlobal pMac, tANI_U8 *pCountryCode,
3739 tANI_BOOLEAN fForce)
3740{
3741 tANI_BOOLEAN fCountryStringChanged = FALSE, fUnknownCountryCode = FALSE;
3742 tANI_U32 i;
Kiet Lam6c583332013-10-14 05:37:09 +05303743 v_REGDOMAIN_t regd;
Jeff Johnson295189b2012-06-20 16:38:30 -07003744
3745 // convert to UPPER here so we are assured the strings are always in upper case.
3746 for( i = 0; i < 3; i++ )
3747 {
3748 pCountryCode[ i ] = (tANI_U8)csrToUpper( pCountryCode[ i ] );
3749 }
3750
3751 // Some of the 'old' Cisco 350 series AP's advertise NA as the country code (for North America ??).
3752 // NA is not a valid country code or domain so let's allow this by changing it to the proper
3753 // country code (which is US). We've also seen some NETGEAR AP's that have "XX " as the country code
3754 // with valid 2.4 GHz US channel information. If we cannot find the country code advertised in the
3755 // 11d information element, let's default to US.
Kiet Lam6c583332013-10-14 05:37:09 +05303756 if ( !HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(pMac,
3757 pCountryCode,
3758 &regd,
3759 COUNTRY_QUERY) ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003760 {
3761 // Check the enforcement first
3762 if( pMac->roam.configParam.fEnforceDefaultDomain || pMac->roam.configParam.fEnforceCountryCodeMatch )
3763 {
3764 fUnknownCountryCode = TRUE;
3765 }
3766 else
3767 {
Tushnim Bhattacharyya4464e1b2013-10-22 13:40:56 -07003768 pCountryCode[ 0 ] = '0';
3769 pCountryCode[ 1 ] = '0';
Jeff Johnson295189b2012-06-20 16:38:30 -07003770 }
3771 }
3772
3773 // We've seen some of the AP's improperly put a 0 for the third character of the country code.
3774 // spec says valid charcters are 'O' (for outdoor), 'I' for Indoor, or ' ' (space; for either).
3775 // if we see a 0 in this third character, let's change it to a ' '.
3776 if ( 0 == pCountryCode[ 2 ] )
3777 {
3778 pCountryCode[ 2 ] = ' ';
3779 }
3780
3781 if( !fUnknownCountryCode )
3782 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303783 fCountryStringChanged = (!vos_mem_compare(pMac->scan.countryCode11d, pCountryCode, 2));
Jeff Johnson295189b2012-06-20 16:38:30 -07003784
3785
3786 if(( 0 == pMac->scan.countryCode11d[ 0 ] && 0 == pMac->scan.countryCode11d[ 1 ] )
3787 || (fForce))
3788 {
3789 // this is the first .11d information
Kiet Lam64c1b492013-07-12 13:56:44 +05303790 vos_mem_copy(pMac->scan.countryCode11d, pCountryCode,
3791 sizeof( pMac->scan.countryCode11d ));
Jeff Johnson295189b2012-06-20 16:38:30 -07003792 }
3793 }
3794
3795 return( fCountryStringChanged );
3796}
3797
3798
3799void csrSaveChannelPowerForBand( tpAniSirGlobal pMac, tANI_BOOLEAN fPopulate5GBand )
3800{
3801 tANI_U32 Index, count=0;
3802 tSirMacChanInfo *pChanInfo;
3803 tSirMacChanInfo *pChanInfoStart;
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08003804 tANI_S32 maxChannelIndex;
3805
3806 maxChannelIndex = ( pMac->scan.base20MHzChannels.numChannels < WNI_CFG_VALID_CHANNEL_LIST_LEN ) ?
3807 pMac->scan.base20MHzChannels.numChannels : WNI_CFG_VALID_CHANNEL_LIST_LEN ;
Jeff Johnson295189b2012-06-20 16:38:30 -07003808
Kiet Lam64c1b492013-07-12 13:56:44 +05303809 pChanInfo = vos_mem_malloc(sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN);
3810 if ( NULL != pChanInfo )
Jeff Johnson295189b2012-06-20 16:38:30 -07003811 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303812 vos_mem_set(pChanInfo, sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003813 pChanInfoStart = pChanInfo;
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08003814 for (Index=0; Index < maxChannelIndex; Index++)
Jeff Johnson295189b2012-06-20 16:38:30 -07003815 {
3816 if ((fPopulate5GBand && (CSR_IS_CHANNEL_5GHZ(pMac->scan.defaultPowerTable[Index].chanId))) ||
3817 (!fPopulate5GBand && (CSR_IS_CHANNEL_24GHZ(pMac->scan.defaultPowerTable[Index].chanId))) )
3818 {
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08003819 if(count >= WNI_CFG_VALID_CHANNEL_LIST_LEN)
3820 {
3821 smsLog( pMac, LOGW, FL(" csrSaveChannelPowerForBand, count exceeded, count = %d"), count);
3822 break;
3823 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003824 pChanInfo->firstChanNum = pMac->scan.defaultPowerTable[Index].chanId;
3825 pChanInfo->numChannels = 1;
3826 pChanInfo->maxTxPower = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
3827 pChanInfo++;
3828 count++;
3829 }
3830 }
3831 if(count)
3832 {
3833 csrSaveToChannelPower2G_5G( pMac, count * sizeof(tSirMacChanInfo), pChanInfoStart );
3834 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303835 vos_mem_free(pChanInfoStart);
Jeff Johnson295189b2012-06-20 16:38:30 -07003836 }
3837}
3838
3839
3840void csrSetOppositeBandChannelInfo( tpAniSirGlobal pMac )
3841{
3842 tANI_BOOLEAN fPopulate5GBand = FALSE;
3843
3844 do
3845 {
3846 // if this is not a dual band product, then we don't need to set the opposite
3847 // band info. We only work in one band so no need to look in the other band.
3848 if ( !CSR_IS_OPEARTING_DUAL_BAND( pMac ) ) break;
3849 // if we found channel info on the 5.0 band and...
3850 if ( CSR_IS_CHANNEL_5GHZ( pMac->scan.channelOf11dInfo ) )
3851 {
3852 // and the 2.4 band is empty, then populate the 2.4 channel info
Kiet Lam8d985a02013-10-11 03:39:41 +05303853 if ( !csrLLIsListEmpty( &pMac->scan.channelPowerInfoList24, LL_ACCESS_LOCK ) ) break;
Jeff Johnson295189b2012-06-20 16:38:30 -07003854 fPopulate5GBand = FALSE;
3855 }
3856 else
3857 {
3858 // else, we found channel info in the 2.4 GHz band. If the 5.0 band is empty
3859 // set the 5.0 band info from the 2.4 country code.
Kiet Lam8d985a02013-10-11 03:39:41 +05303860 if ( !csrLLIsListEmpty( &pMac->scan.channelPowerInfoList5G, LL_ACCESS_LOCK ) ) break;
Jeff Johnson295189b2012-06-20 16:38:30 -07003861 fPopulate5GBand = TRUE;
3862 }
3863 csrSaveChannelPowerForBand( pMac, fPopulate5GBand );
3864
3865 } while( 0 );
3866}
3867
3868
3869tANI_BOOLEAN csrIsSupportedChannel(tpAniSirGlobal pMac, tANI_U8 channelId)
3870{
3871 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
3872 tANI_U32 i;
3873
3874 //Make sure it is a channel that is in our supported list.
3875 for ( i = 0; i < pMac->scan.baseChannels.numChannels; i++ )
3876 {
3877 if ( channelId == pMac->scan.baseChannels.channelList[i] )
3878 {
3879 fRet = eANI_BOOLEAN_TRUE;
3880 break;
3881 }
3882 }
3883
3884 //If it is configured to limit a set of the channels
3885 if( fRet && pMac->roam.configParam.fEnforce11dChannels )
3886 {
3887 fRet = eANI_BOOLEAN_FALSE;
3888 for ( i = 0; i < pMac->scan.base20MHzChannels.numChannels; i++ )
3889 {
3890 if ( channelId == pMac->scan.base20MHzChannels.channelList[i] )
3891 {
3892 fRet = eANI_BOOLEAN_TRUE;
3893 break;
3894 }
3895 }
3896 }
3897
3898 return (fRet);
3899}
3900
3901
3902
3903//bSize specify the buffer size of pChannelList
3904tANI_U8 csrGetChannelListFromChannelSet( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 bSize, tCsrChannelPowerInfo *pChannelSet )
3905{
3906 tANI_U8 i, j = 0, chnId;
3907
3908 bSize = CSR_MIN(bSize, pChannelSet->numChannels);
3909 for( i = 0; i < bSize; i++ )
3910 {
3911 chnId = (tANI_U8)(pChannelSet->firstChannel + ( i * pChannelSet->interChannelOffset ));
3912 if ( csrIsSupportedChannel( pMac, chnId ) )
3913 {
3914 pChannelList[j++] = chnId;
3915 }
3916 }
3917
3918 return (j);
3919}
3920
3921
3922
3923//bSize -- specify the buffer size of pChannelList
3924void csrConstructCurrentValidChannelList( tpAniSirGlobal pMac, tDblLinkList *pChannelSetList,
3925 tANI_U8 *pChannelList, tANI_U8 bSize, tANI_U8 *pNumChannels )
3926{
3927 tListElem *pEntry;
3928 tCsrChannelPowerInfo *pChannelSet;
3929 tANI_U8 numChannels;
3930 tANI_U8 *pChannels;
3931
3932 if( pChannelSetList && pChannelList && pNumChannels )
3933 {
3934 pChannels = pChannelList;
3935 *pNumChannels = 0;
3936 pEntry = csrLLPeekHead( pChannelSetList, LL_ACCESS_LOCK );
3937 while( pEntry )
3938 {
3939 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3940 numChannels = csrGetChannelListFromChannelSet( pMac, pChannels, bSize, pChannelSet );
3941 pChannels += numChannels;
3942 *pNumChannels += numChannels;
3943 pEntry = csrLLNext( pChannelSetList, pEntry, LL_ACCESS_LOCK );
3944 }
3945 }
3946}
3947
3948
3949/*
3950 * 802.11D only: Gather 11d IE via beacon or Probe response and store them in pAdapter->channels11d
3951*/
3952tANI_BOOLEAN csrLearnCountryInformation( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc,
3953 tDot11fBeaconIEs *pIes, tANI_BOOLEAN fForce)
3954{
Jeff Johnson295189b2012-06-20 16:38:30 -07003955 eHalStatus status;
3956 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
3957 v_REGDOMAIN_t domainId;
3958 tDot11fBeaconIEs *pIesLocal = pIes;
3959
Jeff Johnson295189b2012-06-20 16:38:30 -07003960 if (VOS_STA_SAP_MODE == vos_get_conparam ())
3961 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07003962
3963 do
3964 {
3965 // check if .11d support is enabled
3966 if( !csrIs11dSupported( pMac ) ) break;
3967 if( !pIesLocal && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc, &pIesLocal))) )
3968 {
3969 break;
3970 }
3971 // check if country information element is present
3972 if(!pIesLocal->Country.present)
3973 {
3974 //No country info
3975 break;
3976 }
3977
3978 if( csrSave11dCountryString( pMac, pIesLocal->Country.country, fForce ) )
3979 {
3980 // country string changed, this should not happen
3981 //Need to check whether we care about this BSS' domain info
3982 //If it doesn't match of the connected profile or roaming profile, let's ignore it
3983 tANI_U32 i;
3984 tCsrRoamSession *pSession;
3985
3986 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
3987 {
3988 if( CSR_IS_SESSION_VALID( pMac, i ) )
3989 {
3990 pSession = CSR_GET_SESSION( pMac, i );
3991 if(pSession->pCurRoamProfile)
3992 {
3993 tCsrScanResultFilter filter;
3994
Kiet Lam64c1b492013-07-12 13:56:44 +05303995 vos_mem_set(&filter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003996 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, &filter);
3997 if(HAL_STATUS_SUCCESS(status))
3998 {
3999 tANI_BOOLEAN fMatch = csrMatchBSS(pMac, pSirBssDesc, &filter, NULL, NULL, NULL, NULL);
4000 //Free the resource first
4001 csrFreeScanFilter( pMac, &filter );
4002 if(fMatch)
4003 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004004 smsLog(pMac, LOGW, " Matching roam profile BSSID %02X-%02X-%02X-%02X-%02X-%02X causing ambiguous domain info",
Jeff Johnson295189b2012-06-20 16:38:30 -07004005 pSirBssDesc->bssId[0], pSirBssDesc->bssId[1], pSirBssDesc->bssId[2],
4006 pSirBssDesc->bssId[3], pSirBssDesc->bssId[4], pSirBssDesc->bssId[5]);
4007 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_TRUE;
4008 break;
4009 }
4010 }
4011 }
4012 else if( csrIsConnStateConnected(pMac, i))
4013 {
4014 //Reach here only when the currention is base on no profile.
4015 //User doesn't give profile and just connect to anything.
4016 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile, pSirBssDesc, pIesLocal))
4017 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004018 smsLog(pMac, LOGW, " Matching connect profile BSSID %02X-%02X-%02X-%02X-%02X-%02X causing ambiguous domain info",
Jeff Johnson295189b2012-06-20 16:38:30 -07004019 pSirBssDesc->bssId[0], pSirBssDesc->bssId[1], pSirBssDesc->bssId[2],
4020 pSirBssDesc->bssId[3], pSirBssDesc->bssId[4], pSirBssDesc->bssId[5]);
4021 //Tush
4022 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_TRUE;
4023 if(csrIsBssidMatch(pMac, (tCsrBssid *)&pSirBssDesc->bssId,
4024 &pSession->connectedProfile.bssid))
4025 {
4026 //AP changed the 11d info on the fly, modify cfg
4027 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
4028 fRet = eANI_BOOLEAN_TRUE;
4029 }
4030 break;
4031 }
4032 }
4033 } //valid session
4034 } //for
4035 if ( i == CSR_ROAM_SESSION_MAX )
4036 {
4037 //Check whether we can use this country's 11d information
4038 if( !pMac->roam.configParam.fEnforceDefaultDomain )
4039 {
4040 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_TRUE;
4041 }
4042 else
4043 {
4044 VOS_ASSERT( pMac->scan.domainIdCurrent == pMac->scan.domainIdDefault );
4045 if( HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
Kiet Lam6c583332013-10-14 05:37:09 +05304046 pMac, pIesLocal->Country.country, &domainId,
4047 COUNTRY_QUERY)) &&
Jeff Johnson295189b2012-06-20 16:38:30 -07004048 ( domainId == pMac->scan.domainIdCurrent ) )
4049 {
4050 //Two countries in the same domain
4051 }
4052 }
4053 }
Kiet Lam6c583332013-10-14 05:37:09 +05304054#ifdef CONFIG_ENABLE_LINUX_REG
4055 csrGetRegulatoryDomainForCountry(pMac, pIesLocal->Country.country,
4056 &domainId, COUNTRY_IE);
4057#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004058 }
4059 else //Tush
4060 {
4061 pMac->scan.fCurrent11dInfoMatch = eANI_BOOLEAN_TRUE;
4062 }
4063
4064 //In case that some channels in 5GHz have the same channel number as 2.4GHz (<= 14)
4065 if(CSR_IS_CHANNEL_5GHZ(pSirBssDesc->channelId))
4066 {
4067 tANI_U8 iC;
4068 tSirMacChanInfo* pMacChnSet = (tSirMacChanInfo *)(&pIesLocal->Country.triplets[0]);
4069
4070 for(iC = 0; iC < pIesLocal->Country.num_triplets; iC++)
4071 {
4072 if(CSR_IS_CHANNEL_24GHZ(pMacChnSet[iC].firstChanNum))
4073 {
4074 pMacChnSet[iC].firstChanNum += 200; //*** Where is this 200 defined?
4075 }
4076 }
4077 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004078 smsLog(pMac, LOG3, FL(" %d sets each one is %d"), pIesLocal->Country.num_triplets, sizeof(tSirMacChanInfo));
Jeff Johnsone7245742012-09-05 17:12:55 -07004079
Jeff Johnson295189b2012-06-20 16:38:30 -07004080 // set the indicator of the channel where the country IE was found...
4081 pMac->scan.channelOf11dInfo = pSirBssDesc->channelId;
Kiet Lam6c583332013-10-14 05:37:09 +05304082#ifndef CONFIG_ENABLE_LINUX_REG
Kiet Lam8d985a02013-10-11 03:39:41 +05304083 status = csrGetRegulatoryDomainForCountry(pMac,
Kiet Lam6c583332013-10-14 05:37:09 +05304084 pIesLocal->Country.country, &domainId, COUNTRY_IE);
Kiet Lam8d985a02013-10-11 03:39:41 +05304085 if ( status != eHAL_STATUS_SUCCESS )
4086 {
4087 smsLog( pMac, LOGE, FL(" fail to get regId %d"), domainId );
4088 fRet = eANI_BOOLEAN_FALSE;
4089 break;
4090 }
Venkata Prathyusha Kuntupalli316247e2013-03-15 17:45:25 -07004091 // Checking for Domain Id change
4092 if ( domainId != pMac->scan.domainIdCurrent )
4093 {
Kiet Lam8d985a02013-10-11 03:39:41 +05304094 vos_mem_copy(pMac->scan.countryCode11d,
4095 pIesLocal->Country.country,
4096 sizeof( pMac->scan.countryCode11d ) );
4097 /* Set Current Country code and Current Regulatory domain */
4098 status = csrSetRegulatoryDomain(pMac, domainId, NULL);
4099 if (eHAL_STATUS_SUCCESS != status)
4100 {
4101 smsLog(pMac, LOGE, "Set Reg Domain Fail %d", status);
4102 fRet = eANI_BOOLEAN_FALSE;
4103 return fRet;
4104 }
4105 //csrSetRegulatoryDomain will fail if the country doesn't fit our domain criteria.
4106 vos_mem_copy(pMac->scan.countryCodeCurrent,
4107 pIesLocal->Country.country, WNI_CFG_COUNTRY_CODE_LEN);
4108 //Simply set it to cfg.
Madan Mohan Koyyalamudi0e5922d2013-09-10 15:45:24 +05304109 csrSetCfgCountryCode(pMac, pIesLocal->Country.country);
Kiet Lam8d985a02013-10-11 03:39:41 +05304110
4111 /* overwrite the defualt country code */
4112 vos_mem_copy(pMac->scan.countryCodeDefault,
4113 pMac->scan.countryCodeCurrent,
4114 WNI_CFG_COUNTRY_CODE_LEN);
4115 /* Set Current RegDomain */
4116 status = WDA_SetRegDomain(pMac, domainId);
4117 if ( status != eHAL_STATUS_SUCCESS )
4118 {
4119 smsLog( pMac, LOGE, FL(" fail to Set regId %d"), domainId );
4120 fRet = eANI_BOOLEAN_FALSE;
4121 return fRet;
4122 }
4123 /* set to default domain ID */
Madan Mohan Koyyalamudi0e5922d2013-09-10 15:45:24 +05304124 pMac->scan.domainIdCurrent = domainId;
Kiet Lam8d985a02013-10-11 03:39:41 +05304125 /* get the channels based on new cc */
4126 status = csrInitGetChannels( pMac );
Jeff Johnson295189b2012-06-20 16:38:30 -07004127
Kiet Lam8d985a02013-10-11 03:39:41 +05304128 if ( status != eHAL_STATUS_SUCCESS )
4129 {
4130 smsLog( pMac, LOGE, FL(" fail to get Channels "));
4131 fRet = eANI_BOOLEAN_FALSE;
4132 return fRet;
4133 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004134
Kiet Lam8d985a02013-10-11 03:39:41 +05304135 /* reset info based on new cc, and we are done */
4136 csrResetCountryInformation(pMac, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
Kiet Lam8d985a02013-10-11 03:39:41 +05304137 }
Kiet Lam6c583332013-10-14 05:37:09 +05304138#endif
4139 fRet = eANI_BOOLEAN_TRUE;
4140
Jeff Johnson295189b2012-06-20 16:38:30 -07004141 } while( 0 );
4142
4143 if( !pIes && pIesLocal )
4144 {
4145 //locally allocated
Kiet Lam64c1b492013-07-12 13:56:44 +05304146 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07004147 }
4148
4149 return( fRet );
4150}
4151
4152
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004153static void csrSaveScanResults( tpAniSirGlobal pMac, tANI_U8 reason )
Jeff Johnson295189b2012-06-20 16:38:30 -07004154{
4155 // initialize this to FALSE. profMoveInterimScanResultsToMainList() routine
4156 // will set this to the channel where an .11d beacon is seen
4157 pMac->scan.channelOf11dInfo = 0;
4158 // if we get any ambiguous .11d information then this will be set to TRUE
4159 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
4160 //Tush
4161 // if we get any ambiguous .11d information, then this will be set to TRUE
4162 // only if the applied 11d info could be found in one of the scan results
4163 pMac->scan.fCurrent11dInfoMatch = eANI_BOOLEAN_FALSE;
4164 // move the scan results from interim list to the main scan list
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004165 csrMoveTempScanResultsToMainList( pMac, reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07004166
4167 // Now check if we gathered any domain/country specific information
4168 // If so, we should update channel list and apply Tx power settings
Jeff Johnsone7245742012-09-05 17:12:55 -07004169 if( csrIs11dSupported(pMac) )
4170 {
4171 csrApplyCountryInformation( pMac, FALSE );
4172 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004173}
4174
4175
4176void csrReinitScanCmd(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4177{
4178 switch (pCommand->u.scanCmd.reason)
4179 {
4180 case eCsrScanSetBGScanParam:
4181 case eCsrScanAbortBgScan:
4182 if(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList)
4183 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304184 vos_mem_free(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList);
Jeff Johnson295189b2012-06-20 16:38:30 -07004185 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
4186 }
4187 break;
4188 case eCsrScanBGScanAbort:
4189 case eCsrScanBGScanEnable:
4190 case eCsrScanGetScanChnInfo:
4191 break;
4192 case eCsrScanAbortNormalScan:
4193 default:
4194 csrScanFreeRequest(pMac, &pCommand->u.scanCmd.u.scanRequest);
4195 break;
4196 }
4197 if(pCommand->u.scanCmd.pToRoamProfile)
4198 {
4199 csrReleaseProfile(pMac, pCommand->u.scanCmd.pToRoamProfile);
Kiet Lam64c1b492013-07-12 13:56:44 +05304200 vos_mem_free(pCommand->u.scanCmd.pToRoamProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07004201 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304202 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004203}
4204
4205
4206tANI_BOOLEAN csrGetRemainingChannelsFor11dScan( tpAniSirGlobal pMac, tANI_U8 *pChannels, tANI_U8 *pcChannels )
4207{
4208 tANI_U32 index11dChannels, index;
4209 tANI_U32 indexCurrentChannels;
4210 tANI_BOOLEAN fChannelAlreadyScanned;
4211 tANI_U32 len = sizeof(pMac->roam.validChannelList);
4212
4213 *pcChannels = 0;
4214 if ( CSR_IS_11D_INFO_FOUND(pMac) && csrRoamIsChannelValid(pMac, pMac->scan.channelOf11dInfo) )
4215 {
4216 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
4217 {
4218 //Find the channel index where we found the 11d info
4219 for(index = 0; index < len; index++)
4220 {
4221 if(pMac->scan.channelOf11dInfo == pMac->roam.validChannelList[index])
4222 break;
4223 }
4224 //check whether we found the channel index
4225 if(index < len)
4226 {
4227 // Now, look through the 11d channel list and create a list of all channels in the 11d list that are
4228 // NOT in the current channel list. This gives us a list of the new channels that have not been
4229 // scanned. We'll scan this new list so we have a complete set of scan results on all of the domain channels
4230 // initially.
4231 for ( index11dChannels = 0; index11dChannels < pMac->scan.channels11d.numChannels; index11dChannels++ )
4232 {
4233 fChannelAlreadyScanned = eANI_BOOLEAN_FALSE;
4234
4235 for( indexCurrentChannels = 0; indexCurrentChannels < index; indexCurrentChannels++ )
4236 {
4237 if ( pMac->roam.validChannelList[ indexCurrentChannels ] == pMac->scan.channels11d.channelList[ index11dChannels ] )
4238 {
4239 fChannelAlreadyScanned = eANI_BOOLEAN_TRUE;
4240 break;
4241 }
4242 }
4243
4244 if ( !fChannelAlreadyScanned )
4245 {
4246 pChannels[ *pcChannels ] = pMac->scan.channels11d.channelList[ index11dChannels ];
4247 ( *pcChannels )++;
4248 }
4249 }
4250 }
4251 }//GetCFG
4252 }
4253 return( *pcChannels );
4254}
4255
4256
4257eCsrScanCompleteNextCommand csrScanGetNextCommandState( tpAniSirGlobal pMac, tSmeCmd *pCommand, tANI_BOOLEAN fSuccess )
4258{
4259 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
4260
4261 switch( pCommand->u.scanCmd.reason )
4262 {
4263 case eCsrScan11d1:
4264 NextCommand = (fSuccess) ? eCsrNext11dScan1Success : eCsrNext11dScan1Failure;
4265 break;
4266 case eCsrScan11d2:
4267 NextCommand = (fSuccess) ? eCsrNext11dScan2Success : eCsrNext11dScan2Failure;
4268 break;
4269 case eCsrScan11dDone:
4270 NextCommand = eCsrNext11dScanComplete;
4271 break;
4272 case eCsrScanLostLink1:
4273 NextCommand = (fSuccess) ? eCsrNextLostLinkScan1Success : eCsrNextLostLinkScan1Failed;
4274 break;
4275 case eCsrScanLostLink2:
4276 NextCommand = (fSuccess) ? eCsrNextLostLinkScan2Success : eCsrNextLostLinkScan2Failed;
4277 break;
4278 case eCsrScanLostLink3:
4279 NextCommand = (fSuccess) ? eCsrNextLostLinkScan3Success : eCsrNextLostLinkScan3Failed;
4280 break;
4281 case eCsrScanForSsid:
4282 NextCommand = (fSuccess) ? eCsrNexteScanForSsidSuccess : eCsrNexteScanForSsidFailure;
4283 break;
4284 case eCsrScanForCapsChange:
4285 NextCommand = eCsrNextCapChangeScanComplete; //don't care success or not
4286 break;
4287 case eCsrScanIdleScan:
4288 NextCommand = eCsrNextIdleScanComplete;
4289 break;
4290 default:
4291 NextCommand = eCsrNextScanNothing;
4292 break;
4293 }
4294 return( NextCommand );
4295}
4296
4297
4298//Return whether the pCommand is finished.
4299tANI_BOOLEAN csrHandleScan11d1Failure(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4300{
4301 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
4302
4303 //Apply back the default setting and passively scan one more time.
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004304 csrResetCountryInformation(pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07004305 pCommand->u.scanCmd.reason = eCsrScan11d2;
4306 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
4307 {
4308 fRet = eANI_BOOLEAN_FALSE;
4309 }
4310
4311 return (fRet);
4312}
4313
4314
4315tANI_BOOLEAN csrHandleScan11dSuccess(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4316{
4317 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
4318 tANI_U8 *pChannels;
4319 tANI_U8 cChannels;
4320
Kiet Lam64c1b492013-07-12 13:56:44 +05304321 pChannels = vos_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
4322 if ( NULL != pChannels )
Jeff Johnson295189b2012-06-20 16:38:30 -07004323 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304324 vos_mem_set(pChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004325 if ( csrGetRemainingChannelsFor11dScan( pMac, pChannels, &cChannels ) )
4326 {
4327 pCommand->u.scanCmd.reason = eCsrScan11dDone;
4328 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
4329 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304330 vos_mem_free(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -07004331 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004332 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304333 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(cChannels);
4334 if ( NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07004335 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304336 vos_mem_copy(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
4337 pChannels, cChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07004338 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = cChannels;
4339 pCommand->u.scanCmd.u.scanRequest.requestType = eCSR_SCAN_REQUEST_FULL_SCAN;
4340 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
4341 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
4342 {
4343 //Reuse the same command buffer
4344 fRet = eANI_BOOLEAN_FALSE;
4345 }
4346 }
4347 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304348 vos_mem_free(pChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07004349 }
4350
4351 return (fRet);
4352}
4353
4354//Return whether the command should be removed
4355tANI_BOOLEAN csrScanComplete( tpAniSirGlobal pMac, tSirSmeScanRsp *pScanRsp )
4356{
4357 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
4358 tListElem *pEntry;
4359 tSmeCmd *pCommand;
4360 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
4361 tANI_BOOLEAN fSuccess;
4362
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05304363 if (pMac->fScanOffload)
4364 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
4365 else
4366 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07004367
4368 if ( pEntry )
4369 {
4370 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
4371
4372 // If the head of the queue is Active and it is a SCAN command, remove
4373 // and put this on the Free queue.
4374 if ( eSmeCommandScan == pCommand->command )
4375 {
4376 tANI_U32 sessionId = pCommand->sessionId;
4377
4378 if(eSIR_SME_SUCCESS != pScanRsp->statusCode)
4379 {
4380 fSuccess = eANI_BOOLEAN_FALSE;
4381 }
4382 else
4383 {
4384 //pMac->scan.tempScanResults is not empty meaning the scan found something
4385 //This check only valid here because csrSaveScanresults is not yet called
4386 fSuccess = (!csrLLIsListEmpty(&pMac->scan.tempScanResults, LL_ACCESS_LOCK));
4387 }
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004388 csrSaveScanResults(pMac, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07004389
4390#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4391 {
4392 vos_log_scan_pkt_type *pScanLog = NULL;
4393 tScanResultHandle hScanResult;
4394 tCsrScanResultInfo *pScanResult;
4395 tDot11fBeaconIEs *pIes;
4396 int n = 0, c = 0;
4397
4398 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
4399 if(pScanLog)
4400 {
4401 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
4402 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
4403 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
4404 {
4405 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_RSP;
4406 }
4407 else
4408 {
4409 if( eSIR_PASSIVE_SCAN != pMac->scan.curScanType )
4410 {
4411 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_RSP;
4412 }
4413 else
4414 {
4415 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_RSP;
4416 }
4417 }
4418 if(eSIR_SME_SUCCESS == pScanRsp->statusCode)
4419 {
4420 if(HAL_STATUS_SUCCESS(csrScanGetResult(pMac, NULL, &hScanResult)))
4421 {
4422 while(((pScanResult = csrScanResultGetNext(pMac, hScanResult)) != NULL))
4423 {
4424 if( n < VOS_LOG_MAX_NUM_BSSID )
4425 {
4426 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pScanResult->BssDescriptor, &pIes)))
4427 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004428 smsLog(pMac, LOGE, FL(" fail to parse IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07004429 break;
4430 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304431 vos_mem_copy(pScanLog->bssid[n],
4432 pScanResult->BssDescriptor.bssId, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07004433 if(pIes && pIes->SSID.present && VOS_LOG_MAX_SSID_SIZE >= pIes->SSID.num_ssid)
4434 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304435 vos_mem_copy(pScanLog->ssid[n],
4436 pIes->SSID.ssid, pIes->SSID.num_ssid);
Jeff Johnson295189b2012-06-20 16:38:30 -07004437 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304438 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07004439 n++;
4440 }
4441 c++;
4442 }
4443 pScanLog->numSsid = (v_U8_t)n;
4444 pScanLog->totalSsid = (v_U8_t)c;
4445 csrScanResultPurge(pMac, hScanResult);
4446 }
4447 }
4448 else
4449 {
4450 pScanLog->status = WLAN_SCAN_STATUS_FAILURE;
4451 }
4452 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
4453 }
4454 }
4455#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4456
4457 NextCommand = csrScanGetNextCommandState(pMac, pCommand, fSuccess);
4458 //We reuse the command here instead reissue a new command
4459 switch(NextCommand)
4460 {
4461 case eCsrNext11dScan1Success:
4462 case eCsrNext11dScan2Success:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004463 smsLog( pMac, LOG2, FL("11dScan1/3 produced results. Reissue Active scan..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004464 // if we found country information, no need to continue scanning further, bail out
4465 fRemoveCommand = eANI_BOOLEAN_TRUE;
4466 NextCommand = eCsrNext11dScanComplete;
4467 break;
4468 case eCsrNext11dScan1Failure:
4469 //We are not done yet. 11d scan fail once. We will try to reset anything and do it over again
4470 //The only meaningful thing for this retry is that we cannot find 11d information after a reset so
4471 //we clear the "old" 11d info and give it once more chance
4472 fRemoveCommand = csrHandleScan11d1Failure(pMac, pCommand);
4473 if(fRemoveCommand)
4474 {
4475 NextCommand = eCsrNext11dScanComplete;
4476 }
4477 break;
4478 case eCsrNextLostLinkScan1Success:
4479 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink1)))
4480 {
4481 csrScanHandleFailedLostlink1(pMac, sessionId);
4482 }
4483 break;
4484 case eCsrNextLostLinkScan2Success:
4485 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink2)))
4486 {
4487 csrScanHandleFailedLostlink2(pMac, sessionId);
4488 }
4489 break;
4490 case eCsrNextLostLinkScan3Success:
4491 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink3)))
4492 {
4493 csrScanHandleFailedLostlink3(pMac, sessionId);
4494 }
4495 break;
4496 case eCsrNextLostLinkScan1Failed:
4497 csrScanHandleFailedLostlink1(pMac, sessionId);
4498 break;
4499 case eCsrNextLostLinkScan2Failed:
4500 csrScanHandleFailedLostlink2(pMac, sessionId);
4501 break;
4502 case eCsrNextLostLinkScan3Failed:
4503 csrScanHandleFailedLostlink3(pMac, sessionId);
4504 break;
4505 case eCsrNexteScanForSsidSuccess:
4506 csrScanHandleSearchForSSID(pMac, pCommand);
4507 break;
4508 case eCsrNexteScanForSsidFailure:
4509 csrScanHandleSearchForSSIDFailure(pMac, pCommand);
4510 break;
4511 case eCsrNextIdleScanComplete:
4512 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
4513 break;
4514 case eCsrNextCapChangeScanComplete:
4515 csrScanHandleCapChangeScanComplete(pMac, sessionId);
4516 break;
4517 default:
4518
4519 break;
4520 }
4521 }
4522 else
4523 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004524 smsLog( pMac, LOGW, FL("Scan Completion called but SCAN command is not ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004525 fRemoveCommand = eANI_BOOLEAN_FALSE;
4526 }
4527 }
4528 else
4529 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004530 smsLog( pMac, LOGW, FL("Scan Completion called but NO commands are ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004531 fRemoveCommand = eANI_BOOLEAN_FALSE;
4532 }
4533
4534 return( fRemoveCommand );
4535}
4536
4537
4538
4539static void csrScanRemoveDupBssDescriptionFromInterimList( tpAniSirGlobal pMac,
4540 tSirBssDescription *pSirBssDescr,
4541 tDot11fBeaconIEs *pIes)
4542{
4543 tListElem *pEntry;
4544 tCsrScanResult *pCsrBssDescription;
4545
4546 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
4547 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
4548 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
4549 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
4550 while( pEntry )
4551 {
4552 pCsrBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
4553
4554 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
4555 // matches
4556
4557 if ( csrIsDuplicateBssDescription( pMac, &pCsrBssDescription->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07004558 pSirBssDescr, pIes, FALSE ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07004559 {
4560 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
4561 ((tANI_S32)pCsrBssDescription->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
4562
4563 // Remove the 'old' entry from the list....
4564 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK ) )
4565 {
4566 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pCsrBssDescription->Result.BssDescriptor);
4567 // we need to free the memory associated with this node
4568 csrFreeScanResultEntry( pMac, pCsrBssDescription );
4569 }
4570
4571 // If we found a match, we can stop looking through the list.
4572 break;
4573 }
4574
4575 pEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK );
4576 }
4577}
4578
4579
4580
4581//Caller allocated memory pfNewBssForConn to return whether new candidate for
4582//current connection is found. Cannot be NULL
4583tCsrScanResult *csrScanSaveBssDescriptionToInterimList( tpAniSirGlobal pMac,
4584 tSirBssDescription *pBSSDescription,
4585 tDot11fBeaconIEs *pIes)
4586{
4587 tCsrScanResult *pCsrBssDescription = NULL;
4588 tANI_U32 cbBSSDesc;
4589 tANI_U32 cbAllocated;
Jeff Johnson295189b2012-06-20 16:38:30 -07004590
4591 // figure out how big the BSS description is (the BSSDesc->length does NOT
4592 // include the size of the length field itself).
4593 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
4594
4595 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
4596
Kiet Lam64c1b492013-07-12 13:56:44 +05304597 pCsrBssDescription = vos_mem_malloc(cbAllocated);
4598 if ( NULL != pCsrBssDescription )
Jeff Johnson295189b2012-06-20 16:38:30 -07004599 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304600 vos_mem_set(pCsrBssDescription, cbAllocated, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004601 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Kiet Lam64c1b492013-07-12 13:56:44 +05304602 vos_mem_copy(&pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc );
Jeff Johnson295189b2012-06-20 16:38:30 -07004603 //Save SSID separately for later use
4604 if( pIes->SSID.present && !csrIsNULLSSID(pIes->SSID.ssid, pIes->SSID.num_ssid) )
4605 {
4606 //SSID not hidden
Madan Mohan Koyyalamudi4e31b132012-11-02 13:13:52 -07004607 tANI_U32 len = pIes->SSID.num_ssid;
Jeff Johnson295189b2012-06-20 16:38:30 -07004608 if (len > SIR_MAC_MAX_SSID_LENGTH)
4609 {
4610 // truncate to fit in our struct
4611 len = SIR_MAC_MAX_SSID_LENGTH;
4612 }
4613 pCsrBssDescription->Result.ssId.length = len;
4614 pCsrBssDescription->Result.timer = vos_timer_get_system_time();
Kiet Lam64c1b492013-07-12 13:56:44 +05304615 vos_mem_copy(pCsrBssDescription->Result.ssId.ssId, pIes->SSID.ssid, len);
Jeff Johnson295189b2012-06-20 16:38:30 -07004616 }
4617 csrLLInsertTail( &pMac->scan.tempScanResults, &pCsrBssDescription->Link, LL_ACCESS_LOCK );
4618 }
4619
4620 return( pCsrBssDescription );
4621}
4622
4623
4624
4625
4626tANI_BOOLEAN csrIsDuplicateBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc1,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07004627 tSirBssDescription *pSirBssDesc2, tDot11fBeaconIEs *pIes2, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07004628{
4629 tANI_BOOLEAN fMatch = FALSE;
4630 tSirMacCapabilityInfo *pCap1, *pCap2;
4631 tDot11fBeaconIEs *pIes1 = NULL;
Jeff Johnsone7245742012-09-05 17:12:55 -07004632 tDot11fBeaconIEs *pIesTemp = pIes2;
Jeff Johnson295189b2012-06-20 16:38:30 -07004633
4634 pCap1 = (tSirMacCapabilityInfo *)&pSirBssDesc1->capabilityInfo;
4635 pCap2 = (tSirMacCapabilityInfo *)&pSirBssDesc2->capabilityInfo;
4636 if(pCap1->ess == pCap2->ess)
4637 {
4638 if (pCap1->ess &&
Jeff Johnsone7245742012-09-05 17:12:55 -07004639 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId)&&
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07004640 (fForced || (pSirBssDesc1->channelId == pSirBssDesc2->channelId)))
Jeff Johnson295189b2012-06-20 16:38:30 -07004641 {
4642 fMatch = TRUE;
Jeff Johnsone7245742012-09-05 17:12:55 -07004643 // Check for SSID match, if exists
4644 do
4645 {
4646 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
4647 {
4648 break;
4649 }
4650 if( NULL == pIesTemp )
4651 {
4652 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
4653 {
4654 break;
4655 }
4656 }
4657 if(pIes1->SSID.present && pIesTemp->SSID.present)
4658 {
4659 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
4660 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
4661 }
4662 }while(0);
4663
Jeff Johnson295189b2012-06-20 16:38:30 -07004664 }
4665 else if (pCap1->ibss && (pSirBssDesc1->channelId == pSirBssDesc2->channelId))
4666 {
Jeff Johnson295189b2012-06-20 16:38:30 -07004667
4668 do
4669 {
4670 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
4671 {
4672 break;
4673 }
4674 if( NULL == pIesTemp )
4675 {
4676 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
4677 {
4678 break;
4679 }
4680 }
4681 //Same channel cannot have same SSID for different IBSS
4682 if(pIes1->SSID.present && pIesTemp->SSID.present)
4683 {
4684 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
4685 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
4686 }
4687 }while(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004688 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004689 /* In case of P2P devices, ess and ibss will be set to zero */
4690 else if (!pCap1->ess &&
4691 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId))
4692 {
4693 fMatch = TRUE;
4694 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004695 }
4696
4697 if(pIes1)
4698 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304699 vos_mem_free(pIes1);
Jeff Johnson295189b2012-06-20 16:38:30 -07004700 }
Jeff Johnsone7245742012-09-05 17:12:55 -07004701
4702 if( (NULL == pIes2) && pIesTemp )
4703 {
4704 //locally allocated
Kiet Lam64c1b492013-07-12 13:56:44 +05304705 vos_mem_free(pIesTemp);
Jeff Johnsone7245742012-09-05 17:12:55 -07004706 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004707
4708 return( fMatch );
4709}
4710
4711
4712tANI_BOOLEAN csrIsNetworkTypeEqual( tSirBssDescription *pSirBssDesc1, tSirBssDescription *pSirBssDesc2 )
4713{
4714 return( pSirBssDesc1->nwType == pSirBssDesc2->nwType );
4715}
4716
4717
4718//to check whether the BSS matches the dot11Mode
4719static tANI_BOOLEAN csrScanIsBssAllowed(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
4720 tDot11fBeaconIEs *pIes)
4721{
4722 tANI_BOOLEAN fAllowed = eANI_BOOLEAN_FALSE;
4723 eCsrPhyMode phyMode;
4724
4725 if(HAL_STATUS_SUCCESS(csrGetPhyModeFromBss(pMac, pBssDesc, &phyMode, pIes)))
4726 {
4727 switch(pMac->roam.configParam.phyMode)
4728 {
4729 case eCSR_DOT11_MODE_11b:
4730 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
4731 break;
4732 case eCSR_DOT11_MODE_11g:
4733 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
4734 break;
4735 case eCSR_DOT11_MODE_11g_ONLY:
4736 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11g == phyMode);
4737 break;
4738 case eCSR_DOT11_MODE_11a:
4739 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11b != phyMode) && (eCSR_DOT11_MODE_11g != phyMode));
4740 break;
4741 case eCSR_DOT11_MODE_11n_ONLY:
4742 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11n == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
4743 break;
Jeff Johnsone7245742012-09-05 17:12:55 -07004744
4745#ifdef WLAN_FEATURE_11AC
4746 case eCSR_DOT11_MODE_11ac_ONLY:
4747 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11ac == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
4748 break;
4749#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004750 case eCSR_DOT11_MODE_11b_ONLY:
4751 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11b == phyMode);
4752 break;
4753 case eCSR_DOT11_MODE_11a_ONLY:
4754 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a == phyMode);
4755 break;
4756 case eCSR_DOT11_MODE_11n:
Jeff Johnsone7245742012-09-05 17:12:55 -07004757#ifdef WLAN_FEATURE_11AC
4758 case eCSR_DOT11_MODE_11ac:
4759#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004760 case eCSR_DOT11_MODE_TAURUS:
4761 default:
4762 fAllowed = eANI_BOOLEAN_TRUE;
4763 break;
4764 }
4765 }
4766
4767 return (fAllowed);
4768}
4769
4770
4771
4772//Return pIes to caller for future use when returning TRUE.
4773static tANI_BOOLEAN csrScanValidateScanResult( tpAniSirGlobal pMac, tANI_U8 *pChannels,
4774 tANI_U8 numChn, tSirBssDescription *pBssDesc,
4775 tDot11fBeaconIEs **ppIes )
4776{
4777 tANI_BOOLEAN fValidChannel = FALSE;
4778 tDot11fBeaconIEs *pIes = NULL;
4779 tANI_U8 index;
4780
4781 for( index = 0; index < numChn; index++ )
4782 {
4783 // This check relies on the fact that a single BSS description is returned in each
4784 // ScanRsp call, which is the way LIM implemented the scan req/rsp funtions. We changed
4785 // to this model when we ran with a large number of APs. If this were to change, then
4786 // this check would have to mess with removing the bssDescription from somewhere in an
4787 // arbitrary index in the bssDescription array.
4788 if ( pChannels[ index ] == pBssDesc->channelId )
4789 {
4790 fValidChannel = TRUE;
4791 break;
4792 }
4793 }
4794 *ppIes = NULL;
4795 if(fValidChannel)
4796 {
4797 if( HAL_STATUS_SUCCESS( csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIes) ) )
4798 {
4799 fValidChannel = csrScanIsBssAllowed(pMac, pBssDesc, pIes);
4800 if( fValidChannel )
4801 {
4802 *ppIes = pIes;
4803 }
4804 else
4805 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304806 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07004807 }
4808 }
4809 else
4810 {
4811 fValidChannel = FALSE;
4812 }
4813 }
4814
4815 return( fValidChannel );
4816}
4817
4818
4819//Return whether last scan result is received
4820static tANI_BOOLEAN csrScanProcessScanResults( tpAniSirGlobal pMac, tSmeCmd *pCommand,
4821 tSirSmeScanRsp *pScanRsp, tANI_BOOLEAN *pfRemoveCommand )
4822{
4823 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE, fRemoveCommand = eANI_BOOLEAN_FALSE;
4824 tDot11fBeaconIEs *pIes = NULL;
4825 tANI_U32 cbParsed;
4826 tSirBssDescription *pSirBssDescription;
4827 tANI_U32 cbBssDesc;
4828 tANI_U32 cbScanResult = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription )
4829 + sizeof(tSirBssDescription); //We need at least one CB
4830
4831 // don't consider the scan rsp to be valid if the status code is Scan Failure. Scan Failure
4832 // is returned when the scan could not find anything. so if we get scan failure return that
4833 // the scan response is invalid. Also check the lenght in the scan result for valid scan
4834 // BssDescriptions....
4835 do
4836 {
4837 if ( ( cbScanResult <= pScanRsp->length ) &&
4838 (( eSIR_SME_SUCCESS == pScanRsp->statusCode ) ||
4839 ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW == pScanRsp->statusCode ) ) )
4840 {
4841 tANI_U8 *pChannelList = NULL;
4842 tANI_U8 cChannels = 0;
4843
4844 //Different scan type can reach this point, we need to distinguish it
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004845#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
4846 if( eCsrScanGetLfrResult == pCommand->u.scanCmd.reason )
4847 {
4848 pChannelList = NULL;
4849 cChannels = 0;
4850 }
4851 else
4852#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004853 if( eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason )
4854 {
4855 //eCsrScanSetBGScanParam uses different structure
4856 tCsrBGScanRequest *pBgScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
4857
4858 cChannels = pBgScanReq->ChannelInfo.numOfChannels;
4859 pChannelList = pBgScanReq->ChannelInfo.ChannelList;
4860 }
4861 else
4862 {
4863 //the rest use generic scan request
4864 cChannels = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
4865 pChannelList = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
4866 }
4867
4868 // if the scan result is not on one of the channels in the Valid channel list, then it
4869 // must have come from an AP on an overlapping channel (in the 2.4GHz band). In this case,
4870 // let's drop the scan result.
4871 //
4872 // The other situation is where the scan request is for a scan on a particular channel set
4873 // and the scan result is from a
4874
4875 // if the NumChannels is 0, then we are supposed to be scanning all channels. Use the full channel
4876 // list as the 'valid' channel list. Otherwise, use the specific channel list in the scan parms
4877 // as the valid channels.
4878 if ( 0 == cChannels )
4879 {
4880 tANI_U32 len = sizeof(pMac->roam.validChannelList);
4881
4882 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
4883 {
4884 pChannelList = pMac->roam.validChannelList;
4885 cChannels = (tANI_U8)len;
4886 }
4887 else
4888 {
4889 //Cannot continue
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004890 smsLog( pMac, LOGE, "CSR: Processing internal SCAN results...csrGetCfgValidChannels failed" );
Jeff Johnson295189b2012-06-20 16:38:30 -07004891 break;
4892 }
4893 }
4894
4895 smsLog( pMac, LOG2, "CSR: Processing internal SCAN results..." );
4896 cbParsed = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription );
4897 pSirBssDescription = pScanRsp->bssDescription;
4898 while( cbParsed < pScanRsp->length )
4899 {
4900 if ( csrScanValidateScanResult( pMac, pChannelList, cChannels, pSirBssDescription, &pIes ) )
4901 {
4902 csrScanRemoveDupBssDescriptionFromInterimList(pMac, pSirBssDescription, pIes);
4903 csrScanSaveBssDescriptionToInterimList( pMac, pSirBssDescription, pIes );
4904 if( eSIR_PASSIVE_SCAN == pMac->scan.curScanType )
4905 {
4906 if( csrIs11dSupported( pMac) )
4907 {
4908 //Check whether the BSS is acceptable base on 11d info and our configs.
4909 if( csrMatchCountryCode( pMac, NULL, pIes ) )
4910 {
4911 //Double check whether the channel is acceptable by us.
4912 if( csrIsSupportedChannel( pMac, pSirBssDescription->channelId ) )
4913 {
4914 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
4915 }
4916 }
4917 }
4918 else
4919 {
4920 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
4921 }
4922 }
4923 //Free the resource
Kiet Lam64c1b492013-07-12 13:56:44 +05304924 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07004925 }
4926 // skip over the BSS description to the next one...
4927 cbBssDesc = pSirBssDescription->length + sizeof( pSirBssDescription->length );
4928
4929 cbParsed += cbBssDesc;
4930 pSirBssDescription = (tSirBssDescription *)((tANI_U8 *)pSirBssDescription + cbBssDesc );
4931
4932 } //while
4933 }
4934 else
4935 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004936 smsLog( pMac, LOGW, " Scanrsp fail (0x%08X), length = %d (expected %d)",
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08004937 pScanRsp->statusCode, pScanRsp->length, cbScanResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07004938 //HO bg scan/probe failed no need to try autonomously
4939 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
4940 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004941#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
4942 eCsrScanGetLfrResult == pCommand->u.scanCmd.reason ||
4943#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004944 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
4945 {
4946 fRemoveCommand = eANI_BOOLEAN_TRUE;
4947 }
4948 }
4949 }while(0);
4950 if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
4951 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004952 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 -07004953 fRemoveCommand = csrScanComplete( pMac, pScanRsp );
4954 fRet = eANI_BOOLEAN_TRUE;
4955 }//if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
4956 if(pfRemoveCommand)
4957 {
4958 *pfRemoveCommand = fRemoveCommand;
4959 }
4960
4961#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05304962 if (pMac->fScanOffload)
4963 return fRet;
4964
Jeff Johnson295189b2012-06-20 16:38:30 -07004965 if (!csrLLIsListEmpty( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK ))
4966 {
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08004967 /* Pending scan commands in the list because the previous scan command
4968 * was split into a scan command on one channel + a scan command for all
4969 * remaining channels.
4970 *
4971 * Start timer to trigger processing of the next scan command.
Srikant Kuppa866893f2012-12-27 17:28:14 -08004972 * NOTE for LFR:
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05304973 * Do not split scans if no concurrent infra connections are
Srikant Kuppa866893f2012-12-27 17:28:14 -08004974 * active and if the scan is a BG scan triggered by LFR (OR)
4975 * any scan if LFR is in the middle of a BG scan. Splitting
4976 * the scan is delaying the time it takes for LFR to find
4977 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08004978 */
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05304979 if ( (csrIsStaSessionConnected(pMac) &&
Srikant Kuppa866893f2012-12-27 17:28:14 -08004980#ifdef FEATURE_WLAN_LFR
4981 (csrIsConcurrentInfraConnected(pMac) ||
4982 ((pCommand->u.scanCmd.reason != eCsrScanBgScan) &&
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05304983 (pMac->roam.neighborRoamInfo.neighborRoamState !=
Srikant Kuppa866893f2012-12-27 17:28:14 -08004984 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
4985#endif
4986 (pCommand->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05304987 (csrIsP2pSessionConnected(pMac)) )
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08004988 {
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08004989 /* if active connected sessions present then continue to split scan
4990 * with specified interval between consecutive scans */
4991 csrSetDefaultScanTiming(pMac, pCommand->u.scanCmd.u.scanRequest.scanType, &(pCommand->u.scanCmd.u.scanRequest));
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05304992 vos_timer_start(&pMac->scan.hTimerStaApConcTimer,
4993 pCommand->u.scanCmd.u.scanRequest.restTime);
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08004994 } else {
4995 /* if no connected sessions present then initiate next scan command immediately */
4996 /* minimum timer granularity is 10ms */
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05304997 vos_timer_start(&pMac->scan.hTimerStaApConcTimer, 10);
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08004998 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004999 }
5000#endif
5001 return (fRet);
5002}
5003
5004
5005tANI_BOOLEAN csrScanIsWildCardScan( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5006{
5007 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
Kiet Lam64c1b492013-07-12 13:56:44 +05305008 tANI_BOOLEAN f = vos_mem_compare(pCommand->u.scanCmd.u.scanRequest.bssid,
5009 bssid, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07005010
5011 //It is not a wild card scan if the bssid is not broadcast and the number of SSID is 1.
5012 return ((tANI_BOOLEAN)( (f || (0xff == pCommand->u.scanCmd.u.scanRequest.bssid[0])) &&
5013 (pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs != 1) ));
5014}
5015
5016
5017eHalStatus csrScanSmeScanResponse( tpAniSirGlobal pMac, void *pMsgBuf )
5018{
5019 eHalStatus status = eHAL_STATUS_SUCCESS;
5020 tListElem *pEntry;
5021 tSmeCmd *pCommand;
5022 eCsrScanStatus scanStatus;
5023 tSirSmeScanRsp *pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
5024 tSmeGetScanChnRsp *pScanChnInfo;
5025 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
5026 eCsrScanReason reason = eCsrScanOther;
5027
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305028 if (pMac->fScanOffload)
5029 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList,
5030 LL_ACCESS_LOCK);
5031 else
5032 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07005033
5034 if ( pEntry )
5035 {
5036 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
5037 if ( eSmeCommandScan == pCommand->command )
5038 {
5039 scanStatus = (eSIR_SME_SUCCESS == pScanRsp->statusCode) ? eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
5040 reason = pCommand->u.scanCmd.reason;
5041 switch(pCommand->u.scanCmd.reason)
5042 {
5043 case eCsrScanAbortBgScan:
5044 case eCsrScanAbortNormalScan:
5045 case eCsrScanBGScanAbort:
5046 case eCsrScanBGScanEnable:
5047 break;
5048 case eCsrScanGetScanChnInfo:
5049 pScanChnInfo = (tSmeGetScanChnRsp *)pMsgBuf;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07005050 /*
5051 * status code not available in tSmeGetScanChnRsp, so
5052 * by default considereing it to be success
5053 */
5054 scanStatus = eSIR_SME_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07005055 csrScanAgeResults(pMac, pScanChnInfo);
5056 break;
5057 case eCsrScanForCapsChange:
5058 csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand );
5059 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005060 case eCsrScanP2PFindPeer:
5061 scanStatus = ((eSIR_SME_SUCCESS == pScanRsp->statusCode) && (pScanRsp->length > 50)) ? eCSR_SCAN_FOUND_PEER : eCSR_SCAN_FAILURE;
5062 csrScanProcessScanResults( pMac, pCommand, pScanRsp, NULL );
5063 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07005064 case eCsrScanSetBGScanParam:
5065 default:
5066 if(csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand ))
5067 {
5068 //Not to get channel info if the scan is not a wildcard scan because
5069 //it may cause scan results got aged out incorrectly.
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005070 if( csrScanIsWildCardScan( pMac, pCommand ) && (!pCommand->u.scanCmd.u.scanRequest.p2pSearch)
5071#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5072 && (pCommand->u.scanCmd.reason != eCsrScanGetLfrResult)
5073#endif
5074 )
Jeff Johnson295189b2012-06-20 16:38:30 -07005075 {
5076 //Get the list of channels scanned
Jeff Johnson32d95a32012-09-10 13:15:23 -07005077 if( pCommand->u.scanCmd.reason != eCsrScanUserRequest)
5078 {
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05305079 csrScanGetScanChnInfo(pMac, pCommand->sessionId,
5080 NULL, NULL);
Jeff Johnson32d95a32012-09-10 13:15:23 -07005081 }
5082 else
5083 {
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05305084 csrScanGetScanChnInfo(pMac,
5085 pCommand->sessionId,
5086 pCommand->u.scanCmd.pContext,
5087 pCommand->u.scanCmd.callback);
Jeff Johnson32d95a32012-09-10 13:15:23 -07005088 pCommand->u.scanCmd.callback = NULL;
5089 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005090 }
5091 }
5092 break;
5093 }//switch
5094 if(fRemoveCommand)
5095 {
5096
5097 csrReleaseScanCommand(pMac, pCommand, scanStatus);
5098
Srikant Kuppa866893f2012-12-27 17:28:14 -08005099 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005100 smeProcessPendingQueue( pMac );
5101 }
5102 else
5103 {
5104 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
5105 status = eHAL_STATUS_FAILURE;
5106 }
5107 }
5108 else
5109 {
5110 smsLog( pMac, LOGW, "CSR: Scan Completion called but NO commands are ACTIVE ..." );
5111 status = eHAL_STATUS_FAILURE;
5112 }
5113
5114 return (status);
5115}
5116
5117
5118
5119
5120tCsrScanResultInfo *csrScanResultGetFirst(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
5121{
5122 tListElem *pEntry;
5123 tCsrScanResult *pResult;
5124 tCsrScanResultInfo *pRet = NULL;
5125 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5126
5127 if(pResultList)
5128 {
5129 csrLLLock(&pResultList->List);
5130 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5131 if(pEntry)
5132 {
5133 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
5134 pRet = &pResult->Result;
5135 }
5136 pResultList->pCurEntry = pEntry;
5137 csrLLUnlock(&pResultList->List);
5138 }
5139
5140 return pRet;
5141}
5142
5143
5144tCsrScanResultInfo *csrScanResultGetNext(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
5145{
5146 tListElem *pEntry = NULL;
5147 tCsrScanResult *pResult = NULL;
5148 tCsrScanResultInfo *pRet = NULL;
5149 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5150
5151 if(pResultList)
5152 {
5153 csrLLLock(&pResultList->List);
5154 if(NULL == pResultList->pCurEntry)
5155 {
5156 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5157 }
5158 else
5159 {
5160 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
5161 }
5162 if(pEntry)
5163 {
5164 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
5165 pRet = &pResult->Result;
5166 }
5167 pResultList->pCurEntry = pEntry;
5168 csrLLUnlock(&pResultList->List);
5169 }
5170
5171 return pRet;
5172}
5173
5174
5175//This function moves the first BSS that matches the bssid to the head of the result
5176eHalStatus csrMoveBssToHeadFromBSSID(tpAniSirGlobal pMac, tCsrBssid *bssid, tScanResultHandle hScanResult)
5177{
5178 eHalStatus status = eHAL_STATUS_FAILURE;
5179 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5180 tCsrScanResult *pResult = NULL;
5181 tListElem *pEntry = NULL;
5182
5183 if(pResultList && bssid)
5184 {
5185 csrLLLock(&pResultList->List);
5186 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5187 while(pEntry)
5188 {
5189 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
Kiet Lam64c1b492013-07-12 13:56:44 +05305190 if (vos_mem_compare(bssid, pResult->Result.BssDescriptor.bssId, sizeof(tCsrBssid)))
Jeff Johnson295189b2012-06-20 16:38:30 -07005191 {
5192 status = eHAL_STATUS_SUCCESS;
5193 csrLLRemoveEntry(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
5194 csrLLInsertHead(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
5195 break;
5196 }
5197 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
5198 }
5199 csrLLUnlock(&pResultList->List);
5200 }
5201
5202 return (status);
5203}
5204
5205
5206//Remove the BSS if possible.
5207//Return -- TRUE == the BSS is remove. False == Fail to remove it
5208//This function is called when list lock is held. Be caution what functions it can call.
5209tANI_BOOLEAN csrScanAgeOutBss(tpAniSirGlobal pMac, tCsrScanResult *pResult)
5210{
5211 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
5212 tANI_U32 i;
5213 tCsrRoamSession *pSession;
5214
5215 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5216 {
5217 if( CSR_IS_SESSION_VALID( pMac, i ) )
5218 {
5219 pSession = CSR_GET_SESSION( pMac, i );
5220 //Not to remove the BSS we are connected to.
5221 if(csrIsConnStateDisconnected(pMac, i) || (NULL == pSession->pConnectBssDesc) ||
5222 (!csrIsDuplicateBssDescription(pMac, &pResult->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07005223 pSession->pConnectBssDesc, NULL, FALSE))
Jeff Johnson295189b2012-06-20 16:38:30 -07005224 )
5225 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005226 smsLog(pMac, LOGW, "Aging out BSS %02X-%02X-%02X-%02X-%02X-%02X Channel %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005227 pResult->Result.BssDescriptor.bssId[0],
5228 pResult->Result.BssDescriptor.bssId[1],
5229 pResult->Result.BssDescriptor.bssId[2],
5230 pResult->Result.BssDescriptor.bssId[3],
5231 pResult->Result.BssDescriptor.bssId[4],
5232 pResult->Result.BssDescriptor.bssId[5],
5233 pResult->Result.BssDescriptor.channelId);
5234 //No need to hold the spin lock because caller should hold the lock for pMac->scan.scanResultList
5235 if( csrLLRemoveEntry(&pMac->scan.scanResultList, &pResult->Link, LL_ACCESS_NOLOCK) )
5236 {
5237 csrFreeScanResultEntry(pMac, pResult);
Madan Mohan Koyyalamudi2e068bc2012-10-22 14:58:47 -07005238 fRet = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005239 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005240 break;
5241 }
5242 } //valid session
5243 } //for
Madan Mohan Koyyalamudi2e068bc2012-10-22 14:58:47 -07005244 if( CSR_ROAM_SESSION_MAX == i && fRet != eANI_BOOLEAN_TRUE )
Jeff Johnson295189b2012-06-20 16:38:30 -07005245 {
5246 //reset the counter so this won't hapeen too soon
5247 pResult->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
5248 pResult->Result.BssDescriptor.nReceivedTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
5249 }
5250
5251 return (fRet);
5252}
5253
5254
5255eHalStatus csrScanAgeResults(tpAniSirGlobal pMac, tSmeGetScanChnRsp *pScanChnInfo)
5256{
5257 eHalStatus status = eHAL_STATUS_SUCCESS;
5258 tListElem *pEntry, *tmpEntry;
5259 tCsrScanResult *pResult;
5260 tLimScanChn *pChnInfo;
5261 tANI_U8 i;
5262
5263 csrLLLock(&pMac->scan.scanResultList);
5264 for(i = 0; i < pScanChnInfo->numChn; i++)
5265 {
5266 pChnInfo = &pScanChnInfo->scanChn[i];
5267 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
5268 while( pEntry )
5269 {
5270 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
5271 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
5272 if(pResult->Result.BssDescriptor.channelId == pChnInfo->channelId)
5273 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005274 if(pResult->AgingCount <= 0)
5275 {
5276 smsLog(pMac, LOGW, " age out due to ref count");
5277 csrScanAgeOutBss(pMac, pResult);
5278 }
Madan Mohan Koyyalamudib9d3dcc2012-09-28 16:47:50 -07005279 else
5280 {
5281 pResult->AgingCount--;
5282 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005283 }
5284 pEntry = tmpEntry;
5285 }
5286 }
5287 csrLLUnlock(&pMac->scan.scanResultList);
5288
5289 return (status);
5290}
5291
5292
5293eHalStatus csrSendMBScanReq( tpAniSirGlobal pMac, tANI_U16 sessionId,
5294 tCsrScanRequest *pScanReq, tScanReqParam *pScanReqParam )
5295{
5296 eHalStatus status = eHAL_STATUS_SUCCESS;
5297 tSirSmeScanReq *pMsg;
5298 tANI_U16 msgLen;
5299 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
5300 tSirScanType scanType = pScanReq->scanType;
5301 tANI_U32 minChnTime; //in units of milliseconds
5302 tANI_U32 maxChnTime; //in units of milliseconds
5303 tANI_U32 i;
5304 tANI_U8 selfMacAddr[WNI_CFG_BSSID_LEN];
5305 tANI_U8 *pSelfMac = NULL;
5306
5307 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
5308 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) +
5309 ( pScanReq->uIEFieldLen ) ;
5310
Kiet Lam64c1b492013-07-12 13:56:44 +05305311 pMsg = vos_mem_malloc(msgLen);
5312 if ( NULL == pMsg )
5313 status = eHAL_STATUS_FAILURE;
5314 else
5315 status = eHAL_STATUS_SUCCESS;
5316 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07005317 {
5318 do
5319 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305320 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005321 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
5322 pMsg->length = pal_cpu_to_be16(msgLen);
5323 //ToDO: Fill in session info when we need to do scan base on session.
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05305324 if ((pMac->fScanOffload) && (sessionId != CSR_SESSION_ID_INVALID))
5325 {
5326 pMsg->sessionId = sessionId;
5327 }
5328 else
5329 {
5330 /* if sessionId == CSR_SESSION_ID_INVALID, then send the scan
5331 request on first available session */
5332 pMsg->sessionId = 0;
5333 }
5334
Jeff Johnson295189b2012-06-20 16:38:30 -07005335 pMsg->transactionId = 0;
5336 pMsg->dot11mode = (tANI_U8) csrTranslateToWNICfgDot11Mode(pMac, csrFindBestPhyMode( pMac, pMac->roam.configParam.phyMode ));
5337 pMsg->bssType = pal_cpu_to_be32(csrTranslateBsstypeToMacType(pScanReq->BSSType));
5338
5339 if ( CSR_IS_SESSION_VALID( pMac, sessionId ) )
5340 {
5341 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[sessionId].selfMacAddr;
5342 }
5343 else
5344 {
5345 // Since we don't have session for the scanning, we find a valid session. In case we fail to
5346 // do so, get the WNI_CFG_STA_ID
5347 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5348 {
5349 if( CSR_IS_SESSION_VALID( pMac, i ) )
5350 {
5351 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[i].selfMacAddr;
5352 break;
5353 }
5354 }
5355 if( CSR_ROAM_SESSION_MAX == i )
5356 {
5357 tANI_U32 len = WNI_CFG_BSSID_LEN;
5358 pSelfMac = selfMacAddr;
5359 status = ccmCfgGetStr( pMac, WNI_CFG_STA_ID, pSelfMac, &len );
5360 if( !HAL_STATUS_SUCCESS( status ) ||
5361 ( len < WNI_CFG_BSSID_LEN ) )
5362 {
5363 smsLog( pMac, LOGE, FL(" Can not get self MAC address from CFG status = %d"), status );
5364 //Force failed status
5365 status = eHAL_STATUS_FAILURE;
5366 break;
5367 }
5368 }
5369 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305370 vos_mem_copy((tANI_U8 *)pMsg->selfMacAddr, pSelfMac, sizeof(tSirMacAddr));
Jeff Johnson295189b2012-06-20 16:38:30 -07005371
5372 //sirCopyMacAddr
Kiet Lam64c1b492013-07-12 13:56:44 +05305373 vos_mem_copy((tANI_U8 *)pMsg->bssId, (tANI_U8 *)&pScanReq->bssid, sizeof(tSirMacAddr));
5374 if ( vos_mem_compare(pScanReq->bssid, bssid, sizeof(tCsrBssid)))
Jeff Johnson295189b2012-06-20 16:38:30 -07005375 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305376 vos_mem_set(pMsg->bssId, sizeof(tSirMacAddr), 0xff);
Jeff Johnson295189b2012-06-20 16:38:30 -07005377 }
5378 else
5379 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305380 vos_mem_copy(pMsg->bssId, pScanReq->bssid, WNI_CFG_BSSID_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07005381 }
5382 minChnTime = pScanReq->minChnTime;
5383 maxChnTime = pScanReq->maxChnTime;
5384
5385 //Verify the scan type first, if the scan is active scan, we need to make sure we
5386 //are allowed to do so.
5387 /* if 11d is enabled & we don't see any beacon around, scan type falls
5388 back to passive. But in BT AMP STA mode we need to send out a
5389 directed probe*/
5390 if( (eSIR_PASSIVE_SCAN != scanType) && (eCSR_SCAN_P2P_DISCOVERY != pScanReq->requestType)
5391 && (eCSR_BSS_TYPE_WDS_STA != pScanReq->BSSType)
5392 && (eANI_BOOLEAN_FALSE == pMac->scan.fEnableBypass11d))
5393 {
5394 scanType = pMac->scan.curScanType;
5395 if(eSIR_PASSIVE_SCAN == pMac->scan.curScanType)
5396 {
5397 if(minChnTime < pMac->roam.configParam.nPassiveMinChnTime)
5398 {
5399 minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
5400 }
5401 if(maxChnTime < pMac->roam.configParam.nPassiveMaxChnTime)
5402 {
5403 maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
5404 }
5405 }
5406 }
5407 pMsg->scanType = pal_cpu_to_be32(scanType);
5408
5409 pMsg->numSsid = (pScanReq->SSIDs.numOfSSIDs < SIR_SCAN_MAX_NUM_SSID) ? pScanReq->SSIDs.numOfSSIDs :
5410 SIR_SCAN_MAX_NUM_SSID;
5411 if((pScanReq->SSIDs.numOfSSIDs != 0) && ( eSIR_PASSIVE_SCAN != scanType ))
5412 {
Jeff Johnson40b59aa2013-03-19 14:43:18 -07005413 for (i = 0; i < pMsg->numSsid; i++)
5414 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305415 vos_mem_copy(&pMsg->ssId[i],
5416 &pScanReq->SSIDs.SSIDList[i].SSID, sizeof(tSirMacSSid));
Jeff Johnson40b59aa2013-03-19 14:43:18 -07005417 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005418 }
5419 else
5420 {
5421 //Otherwise we scan all SSID and let the result filter later
Jeff Johnson40b59aa2013-03-19 14:43:18 -07005422 for (i = 0; i < SIR_SCAN_MAX_NUM_SSID; i++)
5423 {
5424 pMsg->ssId[i].length = 0;
5425 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005426 }
5427
Jeff Johnson295189b2012-06-20 16:38:30 -07005428 pMsg->minChannelTime = pal_cpu_to_be32(minChnTime);
5429 pMsg->maxChannelTime = pal_cpu_to_be32(maxChnTime);
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08005430 pMsg->minChannelTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
5431 pMsg->maxChannelTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07005432 //hidden SSID option
5433 pMsg->hiddenSsid = pScanReqParam->hiddenSsid;
5434 //rest time
5435 //pMsg->restTime = pScanReq->restTime;
5436 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
5437 // All the scan results caching will be done by Roaming
5438 // We do not want LIM to do any caching of scan results,
5439 // so delete the LIM cache on all scan requests
5440 pMsg->returnFreshResults = pScanReqParam->freshScan;
5441 //Always ask for unique result
5442 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
5443 pMsg->channelList.numChannels = (tANI_U8)pScanReq->ChannelInfo.numOfChannels;
5444 if(pScanReq->ChannelInfo.numOfChannels)
5445 {
5446 //Assuming the channelNumber is tANI_U8 (1 byte)
Kiet Lam64c1b492013-07-12 13:56:44 +05305447 vos_mem_copy(pMsg->channelList.channelNumber,
5448 pScanReq->ChannelInfo.ChannelList,
5449 pScanReq->ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07005450 }
5451
5452 pMsg->uIEFieldLen = (tANI_U16) pScanReq->uIEFieldLen;
5453 pMsg->uIEFieldOffset = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
5454 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) ;
5455 if(pScanReq->uIEFieldLen != 0)
5456 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305457 vos_mem_copy((tANI_U8 *)pMsg+pMsg->uIEFieldOffset, pScanReq->pIEField,
5458 pScanReq->uIEFieldLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07005459 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005460 pMsg->p2pSearch = pScanReq->p2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07005461
Madan Mohan Koyyalamudi9b876782012-10-11 16:22:51 -07005462 if (pScanReq->requestType == eCSR_SCAN_HO_BG_SCAN)
5463 {
5464 pMsg->backgroundScanMode = eSIR_ROAMING_SCAN;
5465 }
5466
Jeff Johnson295189b2012-06-20 16:38:30 -07005467 }while(0);
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005468 smsLog(pMac, LOG1, FL("domainIdCurrent %d scanType %d bssType %d requestType %d numChannels %d "),
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005469 pMac->scan.domainIdCurrent, pMsg->scanType, pMsg->bssType,
5470 pScanReq->requestType, pMsg->channelList.numChannels);
5471
5472 for(i = 0; i < pMsg->channelList.numChannels; i++)
5473 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005474 smsLog(pMac, LOG3, FL("channelNumber[%d]= %d"), i, pMsg->channelList.channelNumber[i]);
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005475 }
5476
Jeff Johnson295189b2012-06-20 16:38:30 -07005477 if(HAL_STATUS_SUCCESS(status))
5478 {
5479 status = palSendMBMessage(pMac->hHdd, pMsg);
5480 }
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005481 else
5482 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005483 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d"), status );
Kiet Lam64c1b492013-07-12 13:56:44 +05305484 vos_mem_free(pMsg);
Jeff Johnson295189b2012-06-20 16:38:30 -07005485 }
5486 }//Success allocated memory
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005487 else
5488 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005489 smsLog( pMac, LOGE, FL(" memory allocation failure"));
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005490 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005491
5492 return( status );
5493}
5494
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005495eHalStatus csrSendMBScanResultReq( tpAniSirGlobal pMac, tANI_U32 sessionId, tScanReqParam *pScanReqParam )
Jeff Johnson295189b2012-06-20 16:38:30 -07005496{
5497 eHalStatus status = eHAL_STATUS_SUCCESS;
5498 tSirSmeScanReq *pMsg;
5499 tANI_U16 msgLen;
5500
5501 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ));
Kiet Lam64c1b492013-07-12 13:56:44 +05305502 pMsg = vos_mem_malloc(msgLen);
5503 if ( NULL == pMsg )
5504 status = eHAL_STATUS_FAILURE;
5505 else
Jeff Johnson295189b2012-06-20 16:38:30 -07005506 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305507 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005508 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
5509 pMsg->length = pal_cpu_to_be16(msgLen);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005510 pMsg->sessionId = sessionId;
5511 pMsg->transactionId = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07005512 pMsg->returnFreshResults = pScanReqParam->freshScan;
5513 //Always ask for unique result
5514 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
5515 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
5516 status = palSendMBMessage(pMac->hHdd, pMsg);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005517 if (!HAL_STATUS_SUCCESS(status))
5518 {
5519 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d\n"), status );
5520 }
5521
Jeff Johnson295189b2012-06-20 16:38:30 -07005522 }
5523
5524 return( status );
5525}
5526
5527
5528
5529eHalStatus csrScanChannels( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5530{
5531 eHalStatus status = eHAL_STATUS_FAILURE;
5532 tScanReqParam scanReq;
5533
5534 do
5535 {
5536 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE | TRUE;
5537 scanReq.fUniqueResult = TRUE;
5538 scanReq.hiddenSsid = SIR_SCAN_NO_HIDDEN_SSID;
5539 if(eCsrScanForSsid == pCommand->u.scanCmd.reason)
5540 {
5541 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_FIRST_MATCH;
5542 }
5543 else
5544 {
5545 // Basically do scan on all channels even for 11D 1st scan case.
5546 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5547 }
5548 if((eCsrScanBgScan == pCommand->u.scanCmd.reason)||
5549 (eCsrScanProbeBss == pCommand->u.scanCmd.reason))
5550 {
5551 scanReq.hiddenSsid = SIR_SCAN_HIDDEN_SSID_PE_DECISION;
5552 }
5553
5554#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5555 {
5556 vos_log_scan_pkt_type *pScanLog = NULL;
5557
5558 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
5559 if(pScanLog)
5560 {
5561 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
5562 eCsrScanProbeBss == pCommand->u.scanCmd.reason)
5563 {
5564 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
5565 }
5566 else
5567 {
5568 if( (eSIR_PASSIVE_SCAN != pCommand->u.scanCmd.u.scanRequest.scanType) &&
5569 (eSIR_PASSIVE_SCAN != pMac->scan.curScanType) )
5570 {
5571 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_REQ;
5572 }
5573 else
5574 {
5575 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_REQ;
5576 }
5577 }
5578 pScanLog->minChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.minChnTime;
5579 pScanLog->maxChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.maxChnTime;
5580 pScanLog->numChannel = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
5581 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
5582 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305583 vos_mem_copy(pScanLog->channels,
5584 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
5585 pScanLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07005586 }
5587 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
5588 }
5589 }
5590#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5591
5592
5593 status = csrSendMBScanReq(pMac, pCommand->sessionId,
5594 &pCommand->u.scanCmd.u.scanRequest, &scanReq);
5595 }while(0);
5596
5597 return( status );
5598}
5599
5600
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005601eHalStatus csrScanRetrieveResult(tpAniSirGlobal pMac, tSmeCmd *pCommand)
Jeff Johnson295189b2012-06-20 16:38:30 -07005602{
5603 eHalStatus status = eHAL_STATUS_FAILURE;
5604 tScanReqParam scanReq;
5605
5606 do
5607 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005608#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5609 if (eCsrScanGetLfrResult == pCommand->u.scanCmd.reason)
5610 {
5611 //to get the LFR candidates from PE cache
5612 scanReq.freshScan = SIR_BG_SCAN_RETURN_LFR_CACHED_RESULTS|SIR_BG_SCAN_PURGE_LFR_RESULTS;
5613 scanReq.fUniqueResult = TRUE;
5614 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5615 }
5616 else
5617#endif
5618 {
5619 //not a fresh scan
5620 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE;
5621 scanReq.fUniqueResult = TRUE;
5622 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5623 }
5624 status = csrSendMBScanResultReq(pMac, pCommand->sessionId, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07005625 }while(0);
5626
5627 return (status);
5628}
5629
5630
5631
5632eHalStatus csrProcessScanCommand( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5633{
5634 eHalStatus status = eHAL_STATUS_SUCCESS;
5635 tCsrChannelInfo newChannelInfo = {0, NULL};
5636 int i, j;
5637 tANI_U8 *pChannel = NULL;
5638 tANI_U32 len = 0;
5639
5640 // Transition to Scanning state...
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305641 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07005642 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305643 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5644 {
5645 pCommand->u.scanCmd.lastRoamState[i] =
5646 csrRoamStateChange( pMac, eCSR_ROAMING_STATE_SCANNING, i);
5647 smsLog( pMac, LOG3, "starting SCAN command from %d state...."
5648 " reason is %d", pCommand->u.scanCmd.lastRoamState[i],
5649 pCommand->u.scanCmd.reason );
5650 }
5651 }
5652 else
5653 {
5654 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId] =
5655 csrRoamStateChange(pMac, eCSR_ROAMING_STATE_SCANNING,
5656 pCommand->sessionId);
5657 smsLog( pMac, LOG3,
5658 "starting SCAN command from %d state.... reason is %d",
5659 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId],
5660 pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07005661 }
5662
5663 switch(pCommand->u.scanCmd.reason)
5664 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005665#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5666 case eCsrScanGetLfrResult:
5667#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005668 case eCsrScanGetResult:
5669 case eCsrScanForCapsChange: //For cap change, LIM already save BSS description
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005670 status = csrScanRetrieveResult(pMac, pCommand);
Jeff Johnson295189b2012-06-20 16:38:30 -07005671 break;
5672 case eCsrScanSetBGScanParam:
5673 status = csrProcessSetBGScanParam(pMac, pCommand);
5674 break;
5675 case eCsrScanBGScanAbort:
5676 status = csrSetCfgBackgroundScanPeriod(pMac, 0);
5677 break;
5678 case eCsrScanBGScanEnable:
5679 status = csrSetCfgBackgroundScanPeriod(pMac, pMac->roam.configParam.bgScanInterval);
5680 break;
5681 case eCsrScanGetScanChnInfo:
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05305682 status = csrScanGetScanChannelInfo(pMac, pCommand->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07005683 break;
5684 case eCsrScanUserRequest:
5685 if(pMac->roam.configParam.fScanTwice)
5686 {
5687 //We scan 2.4 channel twice
5688 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels &&
5689 (NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList))
5690 {
5691 len = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
5692 //allocate twice the channel
5693 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(newChannelInfo.numOfChannels * 2);
5694 pChannel = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
5695 }
5696 else
5697 {
5698 //get the valid channel list to scan all.
5699 len = sizeof(pMac->roam.validChannelList);
5700
5701 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
5702 {
5703 //allocate twice the channel
5704 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(len * 2);
5705 pChannel = pMac->roam.validChannelList;
5706 }
5707 }
5708 if(NULL == newChannelInfo.ChannelList)
5709 {
5710 newChannelInfo.numOfChannels = 0;
5711 }
5712 else
5713 {
5714 j = 0;
5715 for(i = 0; i < len; i++)
5716 {
5717 newChannelInfo.ChannelList[j++] = pChannel[i];
5718 if(CSR_MAX_24GHz_CHANNEL_NUMBER >= pChannel[i])
5719 {
5720 newChannelInfo.ChannelList[j++] = pChannel[i];
5721 }
5722 }
5723 if(NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
5724 {
5725 //pChannel points to the channellist from the command, free it.
5726 vos_mem_free(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -07005727 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07005728 }
5729 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = j;
5730 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = newChannelInfo.ChannelList;
5731 }
5732 } //if(pMac->roam.configParam.fScanTwice)
5733
5734 status = csrScanChannels(pMac, pCommand);
5735
5736 break;
5737 default:
5738 status = csrScanChannels(pMac, pCommand);
5739 break;
5740 }
5741
5742 if(!HAL_STATUS_SUCCESS(status))
5743 {
5744 csrReleaseScanCommand(pMac, pCommand, eCSR_SCAN_FAILURE);
5745 }
5746
5747 return (status);
5748}
5749
5750
5751eHalStatus csrScanSetBGScanparams(tpAniSirGlobal pMac, tCsrBGScanRequest *pScanReq)
5752{
5753 eHalStatus status = eHAL_STATUS_SUCCESS;
5754 tSmeCmd *pCommand = NULL;
5755
5756 if(pScanReq)
5757 {
5758 do
5759 {
5760 pCommand = csrGetCommandBuffer(pMac);
5761 if(!pCommand)
5762 {
5763 status = eHAL_STATUS_RESOURCES;
5764 break;
5765 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305766 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005767 pCommand->command = eSmeCommandScan;
5768 pCommand->u.scanCmd.reason = eCsrScanSetBGScanParam;
5769 pCommand->u.scanCmd.callback = NULL;
5770 pCommand->u.scanCmd.pContext = NULL;
Kiet Lam64c1b492013-07-12 13:56:44 +05305771 vos_mem_copy(&pCommand->u.scanCmd.u.bgScanRequest, pScanReq, sizeof(tCsrBGScanRequest));
Jeff Johnson295189b2012-06-20 16:38:30 -07005772 //we have to do the follow
5773 if(pScanReq->ChannelInfo.numOfChannels == 0)
5774 {
5775 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
5776 }
5777 else
5778 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305779 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList
5780 = vos_mem_malloc(pScanReq->ChannelInfo.numOfChannels);
5781 if ( NULL != pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07005782 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305783 vos_mem_copy(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList,
5784 pScanReq->ChannelInfo.ChannelList,
5785 pScanReq->ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07005786 }
5787 else
5788 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005789 smsLog(pMac, LOGE, FL("ran out of memory"));
Jeff Johnson295189b2012-06-20 16:38:30 -07005790 csrReleaseCommandScan(pMac, pCommand);
Kiet Lam64c1b492013-07-12 13:56:44 +05305791 return eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005792 }
5793 }
5794
5795 //scan req for SSID
5796 if(pScanReq->SSID.length)
5797 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305798 vos_mem_copy(pCommand->u.scanCmd.u.bgScanRequest.SSID.ssId,
5799 pScanReq->SSID.ssId, pScanReq->SSID.length);
Jeff Johnson295189b2012-06-20 16:38:30 -07005800 pCommand->u.scanCmd.u.bgScanRequest.SSID.length = pScanReq->SSID.length;
5801
5802 }
5803 pCommand->u.scanCmd.u.bgScanRequest.maxChnTime= pScanReq->maxChnTime;
5804 pCommand->u.scanCmd.u.bgScanRequest.minChnTime = pScanReq->minChnTime;
5805 pCommand->u.scanCmd.u.bgScanRequest.scanInterval = pScanReq->scanInterval;
5806
5807
5808 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
5809 if( !HAL_STATUS_SUCCESS( status ) )
5810 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005811 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07005812 csrReleaseCommandScan( pMac, pCommand );
5813 break;
5814 }
5815 }while(0);
5816 }
5817
5818 return (status);
5819}
5820
5821eHalStatus csrScanBGScanAbort( tpAniSirGlobal pMac )
5822{
5823 eHalStatus status = eHAL_STATUS_SUCCESS;
5824 tSmeCmd *pCommand = NULL;
5825
5826 do
5827 {
5828 pCommand = csrGetCommandBuffer(pMac);
5829 if(!pCommand)
5830 {
5831 status = eHAL_STATUS_RESOURCES;
5832 break;
5833 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305834 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005835 pCommand->command = eSmeCommandScan;
5836 pCommand->u.scanCmd.reason = eCsrScanBGScanAbort;
5837 pCommand->u.scanCmd.callback = NULL;
5838 pCommand->u.scanCmd.pContext = NULL;
5839 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
5840 if( !HAL_STATUS_SUCCESS( status ) )
5841 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005842 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07005843 csrReleaseCommandScan( pMac, pCommand );
5844 break;
5845 }
5846 }while(0);
5847
5848 return (status);
5849}
5850
5851
5852//This will enable the background scan with the non-zero interval
5853eHalStatus csrScanBGScanEnable(tpAniSirGlobal pMac)
5854{
5855 eHalStatus status = eHAL_STATUS_SUCCESS;
5856 tSmeCmd *pCommand = NULL;
5857
5858 if(pMac->roam.configParam.bgScanInterval)
5859 {
5860 do
5861 {
5862 pCommand = csrGetCommandBuffer(pMac);
5863 if(!pCommand)
5864 {
5865 status = eHAL_STATUS_RESOURCES;
5866 break;
5867 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305868 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005869 pCommand->command = eSmeCommandScan;
5870 pCommand->u.scanCmd.reason = eCsrScanBGScanEnable;
5871 pCommand->u.scanCmd.callback = NULL;
5872 pCommand->u.scanCmd.pContext = NULL;
5873 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
5874 if( !HAL_STATUS_SUCCESS( status ) )
5875 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005876 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07005877 csrReleaseCommandScan( pMac, pCommand );
5878 break;
5879 }
5880 }while(0);
5881 //BG scan results are reported automatically by PE to SME once the scan is done.
5882 //No need to fetch the results explicitly.
5883 //csrScanStartGetResultTimer(pMac);
5884 csrScanStartResultAgingTimer(pMac);
5885 }
5886 else
5887 {
5888 //We don't have BG scan so stop the aging timer
5889 csrScanStopResultAgingTimer(pMac);
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005890 smsLog(pMac, LOGE, FL("cannot continue because the bgscan interval is 0"));
Jeff Johnson295189b2012-06-20 16:38:30 -07005891 status = eHAL_STATUS_INVALID_PARAMETER;
5892 }
5893
5894 return (status);
5895}
5896
5897
5898eHalStatus csrScanCopyRequest(tpAniSirGlobal pMac, tCsrScanRequest *pDstReq, tCsrScanRequest *pSrcReq)
5899{
5900 eHalStatus status = eHAL_STATUS_SUCCESS;
5901 tANI_U32 len = sizeof(pMac->roam.validChannelList);
5902 tANI_U32 index = 0;
5903 tANI_U32 new_index = 0;
5904
5905 do
5906 {
5907 status = csrScanFreeRequest(pMac, pDstReq);
5908 if(HAL_STATUS_SUCCESS(status))
5909 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305910 vos_mem_copy(pDstReq, pSrcReq, sizeof(tCsrScanRequest));
Gopichand Nakkalac7b1d3e2012-12-31 14:07:19 -08005911 /* Re-initialize the pointers to NULL since we did a copy */
5912 pDstReq->pIEField = NULL;
5913 pDstReq->ChannelInfo.ChannelList = NULL;
5914 pDstReq->SSIDs.SSIDList = NULL;
5915
Jeff Johnson295189b2012-06-20 16:38:30 -07005916 if(pSrcReq->uIEFieldLen == 0)
5917 {
5918 pDstReq->pIEField = NULL;
5919 }
5920 else
5921 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305922 pDstReq->pIEField = vos_mem_malloc(pSrcReq->uIEFieldLen);
5923 if ( NULL == pDstReq->pIEField )
5924 status = eHAL_STATUS_FAILURE;
5925 else
5926 status = eHAL_STATUS_SUCCESS;
5927 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07005928 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305929 vos_mem_copy(pDstReq->pIEField, pSrcReq->pIEField, pSrcReq->uIEFieldLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07005930 pDstReq->uIEFieldLen = pSrcReq->uIEFieldLen;
5931 }
5932 else
5933 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005934 smsLog(pMac, LOGE, "No memory for scanning IE fields");
Jeff Johnson295189b2012-06-20 16:38:30 -07005935 break;
5936 }
5937 }//Allocate memory for IE field
5938 {
5939 if(pSrcReq->ChannelInfo.numOfChannels == 0)
5940 {
5941 pDstReq->ChannelInfo.ChannelList = NULL;
5942 pDstReq->ChannelInfo.numOfChannels = 0;
5943 }
5944 else
5945 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305946 pDstReq->ChannelInfo.ChannelList = vos_mem_malloc(
5947 pSrcReq->ChannelInfo.numOfChannels
5948 * sizeof(*pDstReq->ChannelInfo.ChannelList));
5949 if ( NULL == pDstReq->ChannelInfo.ChannelList )
5950 status = eHAL_STATUS_FAILURE;
5951 else
5952 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07005953 if(!HAL_STATUS_SUCCESS(status))
5954 {
5955 pDstReq->ChannelInfo.numOfChannels = 0;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005956 smsLog(pMac, LOGE, "No memory for scanning Channel List");
Jeff Johnson295189b2012-06-20 16:38:30 -07005957 break;
5958 }
5959
5960 if((pSrcReq->scanType == eSIR_PASSIVE_SCAN) && (pSrcReq->requestType == eCSR_SCAN_REQUEST_11D_SCAN))
5961 {
5962 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
5963 {
5964 pDstReq->ChannelInfo.ChannelList[new_index] =
5965 pSrcReq->ChannelInfo.ChannelList[index];
5966 new_index++;
5967 }
5968 pDstReq->ChannelInfo.numOfChannels = new_index;
5969 }
5970 else if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
5971 {
5972 new_index = 0;
5973 pMac->roam.numValidChannels = len;
5974 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
5975 {
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -07005976 /* Allow scan on valid channels only.
5977 * If it is p2p scan and valid channel list doesnt contain
5978 * social channels, enforce scan on social channels because
5979 * that is the only way to find p2p peers.
5980 * This can happen only if band is set to 5Ghz mode.
5981 */
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08005982 if((csrRoamIsValidChannel(pMac, pSrcReq->ChannelInfo.ChannelList[index])) ||
5983 ((eCSR_SCAN_P2P_DISCOVERY == pSrcReq->requestType) &&
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -07005984 CSR_IS_SOCIAL_CHANNEL(pSrcReq->ChannelInfo.ChannelList[index])))
Jeff Johnson295189b2012-06-20 16:38:30 -07005985 {
Srikant Kuppa866893f2012-12-27 17:28:14 -08005986 if( (pSrcReq->skipDfsChnlInP2pSearch &&
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08005987 (NV_CHANNEL_DFS == vos_nv_getChannelEnabledState(pSrcReq->ChannelInfo.ChannelList[index])) )
Srikant Kuppa866893f2012-12-27 17:28:14 -08005988#ifdef FEATURE_WLAN_LFR
5989 /*
5990 * If LFR is requesting a contiguous scan
5991 * (i.e. numOfChannels > 1), then ignore
5992 * DFS channels.
5993 * TODO: vos_nv_getChannelEnabledState is returning
5994 * 120, 124 and 128 as non-DFS channels. Hence, the
5995 * use of direct check for channels below.
5996 */
5997 || ((eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType) &&
5998 (pSrcReq->ChannelInfo.numOfChannels > 1) &&
Srinivas Girigowdade697412013-02-14 16:31:48 -08005999 (CSR_IS_CHANNEL_DFS(pSrcReq->ChannelInfo.ChannelList[index])))
Srikant Kuppa866893f2012-12-27 17:28:14 -08006000#endif
6001 )
6002 {
6003#ifdef FEATURE_WLAN_LFR
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006004 smsLog(pMac, LOG2,
Srikant Kuppa866893f2012-12-27 17:28:14 -08006005 "%s: reqType=%d, numOfChannels=%d,"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006006 " ignoring DFS channel %d",
Srikant Kuppa866893f2012-12-27 17:28:14 -08006007 __func__, pSrcReq->requestType,
6008 pSrcReq->ChannelInfo.numOfChannels,
6009 pSrcReq->ChannelInfo.ChannelList[index]);
6010#endif
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08006011 continue;
Srikant Kuppa866893f2012-12-27 17:28:14 -08006012 }
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08006013
Jeff Johnson295189b2012-06-20 16:38:30 -07006014 pDstReq->ChannelInfo.ChannelList[new_index] =
6015 pSrcReq->ChannelInfo.ChannelList[index];
6016 new_index++;
6017 }
6018 }
6019 pDstReq->ChannelInfo.numOfChannels = new_index;
Srikant Kuppa866893f2012-12-27 17:28:14 -08006020#ifdef FEATURE_WLAN_LFR
6021 if ((eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType) &&
6022 (0 == pDstReq->ChannelInfo.numOfChannels))
6023 {
6024 /*
6025 * No valid channels found in the request.
6026 * Only perform scan on the channels passed
6027 * pSrcReq if it is a eCSR_SCAN_HO_BG_SCAN.
6028 * Passing 0 to LIM will trigger a scan on
6029 * all valid channels which is not desirable.
6030 */
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006031 smsLog(pMac, LOGE, "%s: no valid channels found (request=%d)",
Srikant Kuppa866893f2012-12-27 17:28:14 -08006032 __func__, pSrcReq->requestType);
6033 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
6034 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006035 smsLog(pMac, LOGE, "pSrcReq index=%d channel=%d",
Srikant Kuppa866893f2012-12-27 17:28:14 -08006036 index, pSrcReq->ChannelInfo.ChannelList[index]);
6037 }
6038 status = eHAL_STATUS_FAILURE;
6039 break;
6040 }
6041#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006042 }
6043 else
6044 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006045 smsLog(pMac, LOGE, "Couldn't get the valid Channel List, keeping requester's list");
Kiet Lam64c1b492013-07-12 13:56:44 +05306046 vos_mem_copy(pDstReq->ChannelInfo.ChannelList,
6047 pSrcReq->ChannelInfo.ChannelList,
6048 pSrcReq->ChannelInfo.numOfChannels
6049 * sizeof(*pDstReq->ChannelInfo.ChannelList));
Jeff Johnson295189b2012-06-20 16:38:30 -07006050 pDstReq->ChannelInfo.numOfChannels = pSrcReq->ChannelInfo.numOfChannels;
6051 }
6052 }//Allocate memory for Channel List
6053 }
6054 if(pSrcReq->SSIDs.numOfSSIDs == 0)
6055 {
6056 pDstReq->SSIDs.numOfSSIDs = 0;
6057 pDstReq->SSIDs.SSIDList = NULL;
6058 }
6059 else
6060 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306061 pDstReq->SSIDs.SSIDList = vos_mem_malloc(
6062 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
6063 if ( NULL == pDstReq->SSIDs.SSIDList )
6064 status = eHAL_STATUS_FAILURE;
6065 else
6066 status = eHAL_STATUS_SUCCESS;
6067 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07006068 {
6069 pDstReq->SSIDs.numOfSSIDs = pSrcReq->SSIDs.numOfSSIDs;
Kiet Lam64c1b492013-07-12 13:56:44 +05306070 vos_mem_copy(pDstReq->SSIDs.SSIDList,
6071 pSrcReq->SSIDs.SSIDList,
6072 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
Jeff Johnson295189b2012-06-20 16:38:30 -07006073 }
6074 else
6075 {
6076 pDstReq->SSIDs.numOfSSIDs = 0;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006077 smsLog(pMac, LOGE, "No memory for scanning SSID List");
Jeff Johnson295189b2012-06-20 16:38:30 -07006078 break;
6079 }
6080 }//Allocate memory for SSID List
Jeff Johnson295189b2012-06-20 16:38:30 -07006081 pDstReq->p2pSearch = pSrcReq->p2pSearch;
Jeff Johnsone7245742012-09-05 17:12:55 -07006082 pDstReq->skipDfsChnlInP2pSearch = pSrcReq->skipDfsChnlInP2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07006083
6084 }
6085 }while(0);
6086
6087 if(!HAL_STATUS_SUCCESS(status))
6088 {
6089 csrScanFreeRequest(pMac, pDstReq);
6090 }
6091
6092 return (status);
6093}
6094
6095
6096eHalStatus csrScanFreeRequest(tpAniSirGlobal pMac, tCsrScanRequest *pReq)
6097{
Jeff Johnson295189b2012-06-20 16:38:30 -07006098
6099 if(pReq->ChannelInfo.ChannelList)
6100 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306101 vos_mem_free(pReq->ChannelInfo.ChannelList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006102 pReq->ChannelInfo.ChannelList = NULL;
6103 }
6104 pReq->ChannelInfo.numOfChannels = 0;
6105 if(pReq->pIEField)
6106 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306107 vos_mem_free(pReq->pIEField);
Jeff Johnson295189b2012-06-20 16:38:30 -07006108 pReq->pIEField = NULL;
6109 }
6110 pReq->uIEFieldLen = 0;
6111 if(pReq->SSIDs.SSIDList)
6112 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306113 vos_mem_free(pReq->SSIDs.SSIDList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006114 pReq->SSIDs.SSIDList = NULL;
6115 }
6116 pReq->SSIDs.numOfSSIDs = 0;
6117
Kiet Lam64c1b492013-07-12 13:56:44 +05306118 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07006119}
6120
6121
6122void csrScanCallCallback(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
6123{
6124 if(pCommand->u.scanCmd.callback)
6125 {
6126// sme_ReleaseGlobalLock( &pMac->sme );
6127 pCommand->u.scanCmd.callback(pMac, pCommand->u.scanCmd.pContext, pCommand->u.scanCmd.scanID, scanStatus);
6128// sme_AcquireGlobalLock( &pMac->sme );
6129 } else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006130 smsLog( pMac, LOG2, "%s:%d - Callback NULL!!!", __func__, __LINE__);
Jeff Johnson295189b2012-06-20 16:38:30 -07006131 }
6132}
6133
6134
6135void csrScanStopTimers(tpAniSirGlobal pMac)
6136{
6137 csrScanStopResultAgingTimer(pMac);
6138 csrScanStopIdleScanTimer(pMac);
6139 csrScanStopGetResultTimer(pMac);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006140 if(0 != pMac->scan.scanResultCfgAgingTime )
6141 {
6142 csrScanStopResultCfgAgingTimer(pMac);
6143 }
6144
Jeff Johnson295189b2012-06-20 16:38:30 -07006145}
6146
6147
6148eHalStatus csrScanStartGetResultTimer(tpAniSirGlobal pMac)
6149{
6150 eHalStatus status;
6151
6152 if(pMac->scan.fScanEnable)
6153 {
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306154 status = vos_timer_start(&pMac->scan.hTimerGetResult, CSR_SCAN_GET_RESULT_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006155 }
6156 else
6157 {
6158 status = eHAL_STATUS_FAILURE;
6159 }
6160
6161 return (status);
6162}
6163
6164
6165eHalStatus csrScanStopGetResultTimer(tpAniSirGlobal pMac)
6166{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306167 return (vos_timer_stop(&pMac->scan.hTimerGetResult));
Jeff Johnson295189b2012-06-20 16:38:30 -07006168}
6169
6170
6171void csrScanGetResultTimerHandler(void *pv)
6172{
6173 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6174
6175 csrScanRequestResult(pMac);
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306176
6177 vos_timer_start(&pMac->scan.hTimerGetResult, CSR_SCAN_GET_RESULT_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006178}
6179
6180#ifdef WLAN_AP_STA_CONCURRENCY
6181static void csrStaApConcTimerHandler(void *pv)
6182{
6183 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6184 tListElem *pEntry;
6185 tSmeCmd *pScanCmd;
6186
6187 csrLLLock(&pMac->scan.scanCmdPendingList);
6188
6189 if ( NULL != ( pEntry = csrLLPeekHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) ) )
6190 {
6191 tCsrScanRequest scanReq;
6192 tSmeCmd *pSendScanCmd = NULL;
6193 tANI_U8 numChn = 0;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006194 tANI_U8 nNumChanCombinedConc = 0;
Vinay Malekal05fdc812012-12-17 13:04:30 -08006195 tANI_U8 i, j;
Jeff Johnson295189b2012-06-20 16:38:30 -07006196 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
6197 tANI_U8 channelToScan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
6198 eHalStatus status;
6199
Jeff Johnson295189b2012-06-20 16:38:30 -07006200 pScanCmd = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
6201 numChn = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08006202
6203 /* if any session is connected and the number of channels to scan is
6204 * greater than 1 then split the scan into multiple scan operations
6205 * on each individual channel else continue to perform scan on all
6206 * specified channels */
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08006207
6208 /* split scan if number of channels to scan is greater than 1 and
6209 * any one of the following:
6210 * - STA session is connected and the scan is not a P2P search
6211 * - any P2P session is connected
Srikant Kuppa866893f2012-12-27 17:28:14 -08006212 * Do not split scans if no concurrent infra connections are
6213 * active and if the scan is a BG scan triggered by LFR (OR)
6214 * any scan if LFR is in the middle of a BG scan. Splitting
6215 * the scan is delaying the time it takes for LFR to find
6216 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08006217 */
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006218
6219 if((csrIsStaSessionConnected(pMac) &&
6220 !csrIsP2pSessionConnected(pMac)))
6221 {
6222 nNumChanCombinedConc = pMac->roam.configParam.nNumStaChanCombinedConc;
6223 }
6224 else if(csrIsP2pSessionConnected(pMac))
6225 {
6226 nNumChanCombinedConc = pMac->roam.configParam.nNumP2PChanCombinedConc;
6227 }
6228
6229 if ( (numChn > nNumChanCombinedConc) &&
Srikant Kuppa866893f2012-12-27 17:28:14 -08006230 ((csrIsStaSessionConnected(pMac) &&
6231#ifdef FEATURE_WLAN_LFR
6232 (csrIsConcurrentInfraConnected(pMac) ||
6233 ((pScanCmd->u.scanCmd.reason != eCsrScanBgScan) &&
6234 (pMac->roam.neighborRoamInfo.neighborRoamState !=
6235 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
6236#endif
6237 (pScanCmd->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08006238 (csrIsP2pSessionConnected(pMac))))
Jeff Johnson295189b2012-06-20 16:38:30 -07006239 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306240 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006241
6242 pSendScanCmd = csrGetCommandBuffer(pMac); //optimize this to use 2 command buffer only
6243 if (!pSendScanCmd)
6244 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006245 smsLog( pMac, LOGE, FL(" Failed to get Queue command buffer") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006246 csrLLUnlock(&pMac->scan.scanCmdPendingList);
6247 return;
6248 }
6249 pSendScanCmd->command = pScanCmd->command;
6250 pSendScanCmd->sessionId = pScanCmd->sessionId;
6251 pSendScanCmd->u.scanCmd.callback = NULL;
6252 pSendScanCmd->u.scanCmd.pContext = pScanCmd->u.scanCmd.pContext;
6253 pSendScanCmd->u.scanCmd.reason = pScanCmd->u.scanCmd.reason;
6254 pSendScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
6255
Madan Mohan Koyyalamudiaf2a8b92012-10-09 14:58:07 -07006256 /* First copy all the parameters to local variable of scan request */
6257 csrScanCopyRequest(pMac, &scanReq, &pScanCmd->u.scanCmd.u.scanRequest);
6258
6259 /* Now modify the elements of local var scan request required to be modified for split scan */
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08006260 if(scanReq.ChannelInfo.ChannelList != NULL)
6261 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306262 vos_mem_free(scanReq.ChannelInfo.ChannelList);
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08006263 scanReq.ChannelInfo.ChannelList = NULL;
6264 }
6265
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006266 pChnInfo->numOfChannels = nNumChanCombinedConc;
Kiet Lam64c1b492013-07-12 13:56:44 +05306267 vos_mem_copy(&channelToScan[0],
6268 &pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[0],
6269 pChnInfo->numOfChannels * sizeof(tANI_U8));//just send one channel
Jeff Johnson295189b2012-06-20 16:38:30 -07006270 pChnInfo->ChannelList = &channelToScan[0];
6271
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006272 for (i = 0, j = nNumChanCombinedConc; i < (numChn-nNumChanCombinedConc); i++, j++)
Jeff Johnson295189b2012-06-20 16:38:30 -07006273 {
6274 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] =
Vinay Malekal05fdc812012-12-17 13:04:30 -08006275 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[j]; //Move all the channels one step
Jeff Johnson295189b2012-06-20 16:38:30 -07006276 }
6277
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006278 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = numChn - nNumChanCombinedConc; //reduce outstanding # of channels to be scanned
Jeff Johnson295189b2012-06-20 16:38:30 -07006279
6280 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
6281 //Modify callers parameters in case of concurrency
6282 scanReq.scanType = eSIR_ACTIVE_SCAN;
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -07006283 //Use concurrency values for min/maxChnTime.
6284 //We know csrIsAnySessionConnected(pMac) returns TRUE here
6285 csrSetDefaultScanTiming(pMac, scanReq.scanType, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07006286
6287 status = csrScanCopyRequest(pMac, &pSendScanCmd->u.scanCmd.u.scanRequest, &scanReq);
6288 if(!HAL_STATUS_SUCCESS(status))
6289 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006290 smsLog( pMac, LOGE, FL(" Failed to get copy csrScanRequest = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006291 csrLLUnlock(&pMac->scan.scanCmdPendingList);
6292 return;
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08006293 }
6294 /* Clean the local scan variable */
6295 scanReq.ChannelInfo.ChannelList = NULL;
6296 scanReq.ChannelInfo.numOfChannels = 0;
6297 csrScanFreeRequest(pMac, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07006298 }
6299 else
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08006300 {
6301 /* no active connected session present or numChn == 1
6302 * scan all remaining channels */
Jeff Johnson295189b2012-06-20 16:38:30 -07006303 pSendScanCmd = pScanCmd;
6304 //remove this command from pending list
6305 if (csrLLRemoveHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) == NULL)
6306 { //In case between PeekHead and here, the entry got removed by another thread.
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006307 smsLog( pMac, LOGE, FL(" Failed to remove entry from scanCmdPendingList"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006308 }
6309
6310 }
6311 csrQueueSmeCommand(pMac, pSendScanCmd, eANI_BOOLEAN_FALSE);
6312
6313 }
6314
Jeff Johnson295189b2012-06-20 16:38:30 -07006315 csrLLUnlock(&pMac->scan.scanCmdPendingList);
6316
6317}
6318#endif
6319
6320eHalStatus csrScanStartResultAgingTimer(tpAniSirGlobal pMac)
6321{
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006322 eHalStatus status = eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006323
6324 if(pMac->scan.fScanEnable)
6325 {
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306326 status = vos_timer_start(&pMac->scan.hTimerResultAging, CSR_SCAN_RESULT_AGING_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006327 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006328 return (status);
6329}
6330
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006331eHalStatus csrScanStartResultCfgAgingTimer(tpAniSirGlobal pMac)
6332{
6333 eHalStatus status = eHAL_STATUS_FAILURE;
6334
6335 if(pMac->scan.fScanEnable)
6336 {
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306337 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 -08006338 }
6339 return (status);
6340}
Jeff Johnson295189b2012-06-20 16:38:30 -07006341
6342eHalStatus csrScanStopResultAgingTimer(tpAniSirGlobal pMac)
6343{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306344 return (vos_timer_stop(&pMac->scan.hTimerResultAging));
Jeff Johnson295189b2012-06-20 16:38:30 -07006345}
6346
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006347eHalStatus csrScanStopResultCfgAgingTimer(tpAniSirGlobal pMac)
6348{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306349 return (vos_timer_stop(&pMac->scan.hTimerResultCfgAging));
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006350}
Jeff Johnson295189b2012-06-20 16:38:30 -07006351
6352//This function returns the maximum time a BSS is allowed in the scan result.
6353//The time varies base on connection and power saving factors.
6354//Not connected, No PS
6355//Not connected, with PS
6356//Connected w/o traffic, No PS
6357//Connected w/o traffic, with PS
6358//Connected w/ traffic, no PS -- Not supported
6359//Connected w/ traffic, with PS -- Not supported
6360//the return unit is in seconds.
6361tANI_U32 csrScanGetAgeOutTime(tpAniSirGlobal pMac)
6362{
6363 tANI_U32 nRet;
6364
6365 if(pMac->scan.nAgingCountDown)
6366 {
6367 //Calculate what should be the timeout value for this
6368 nRet = pMac->scan.nLastAgeTimeOut * pMac->scan.nAgingCountDown;
6369 pMac->scan.nAgingCountDown--;
6370 }
6371 else
6372 {
6373 if( csrIsAllSessionDisconnected( pMac ) )
6374 {
6375 if(pmcIsPowerSaveEnabled(pMac, ePMC_IDLE_MODE_POWER_SAVE))
6376 {
6377 nRet = pMac->roam.configParam.scanAgeTimeNCPS;
6378 }
6379 else
6380 {
6381 nRet = pMac->roam.configParam.scanAgeTimeNCNPS;
6382 }
6383 }
6384 else
6385 {
6386 if(pmcIsPowerSaveEnabled(pMac, ePMC_BEACON_MODE_POWER_SAVE))
6387 {
6388 nRet = pMac->roam.configParam.scanAgeTimeCPS;
6389 }
6390 else
6391 {
6392 nRet = pMac->roam.configParam.scanAgeTimeCNPS;
6393 }
6394 }
6395 //If state-change causing aging time out change, we want to delay it somewhat to avoid
6396 //unnecessary removal of BSS. This is mostly due to transition from connect to disconnect.
6397 if(pMac->scan.nLastAgeTimeOut > nRet)
6398 {
6399 if(nRet)
6400 {
6401 pMac->scan.nAgingCountDown = (pMac->scan.nLastAgeTimeOut / nRet);
6402 }
6403 pMac->scan.nLastAgeTimeOut = nRet;
6404 nRet *= pMac->scan.nAgingCountDown;
6405 }
6406 else
6407 {
6408 pMac->scan.nLastAgeTimeOut = nRet;
6409 }
6410 }
6411
6412 return (nRet);
6413}
6414
6415
6416void csrScanResultAgingTimerHandler(void *pv)
6417{
6418 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6419 tANI_BOOLEAN fDisconnected = csrIsAllSessionDisconnected(pMac);
6420
6421 //no scan, no aging
6422 if(pMac->scan.fScanEnable &&
6423 (((eANI_BOOLEAN_FALSE == fDisconnected) && pMac->roam.configParam.bgScanInterval)
6424 || (fDisconnected && (pMac->scan.fCancelIdleScan == eANI_BOOLEAN_FALSE)))
6425 )
6426 {
6427 tListElem *pEntry, *tmpEntry;
6428 tCsrScanResult *pResult;
6429 tANI_TIMESTAMP ageOutTime = (tANI_TIMESTAMP)(csrScanGetAgeOutTime(pMac) * PAL_TICKS_PER_SECOND); //turn it into 10ms units
6430 tANI_TIMESTAMP curTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
6431
6432 csrLLLock(&pMac->scan.scanResultList);
6433 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
6434 while( pEntry )
6435 {
6436 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
6437 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
6438 if((curTime - pResult->Result.BssDescriptor.nReceivedTime) > ageOutTime)
6439 {
6440 smsLog(pMac, LOGW, " age out due to time out");
6441 csrScanAgeOutBss(pMac, pResult);
6442 }
6443 pEntry = tmpEntry;
6444 }
6445 csrLLUnlock(&pMac->scan.scanResultList);
6446 }
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306447 vos_timer_start(&pMac->scan.hTimerResultAging, CSR_SCAN_RESULT_AGING_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006448}
6449
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006450static void csrScanResultCfgAgingTimerHandler(void *pv)
6451{
6452 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6453 tListElem *pEntry, *tmpEntry;
6454 tCsrScanResult *pResult;
6455 tANI_TIMESTAMP ageOutTime = pMac->scan.scanResultCfgAgingTime * PAL_TICKS_PER_SECOND;
6456 tANI_TIMESTAMP curTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
6457
6458 csrLLLock(&pMac->scan.scanResultList);
6459 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
6460 while( pEntry )
6461 {
6462 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
6463 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
6464 if((curTime - pResult->Result.BssDescriptor.nReceivedTime) > ageOutTime)
6465 {
6466 smsLog(pMac, LOGW, " age out due to time out");
6467 csrScanAgeOutBss(pMac, pResult);
6468 }
6469 pEntry = tmpEntry;
6470 }
6471 csrLLUnlock(&pMac->scan.scanResultList);
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306472 vos_timer_start(&pMac->scan.hTimerResultCfgAging, CSR_SCAN_RESULT_CFG_AGING_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006473}
Jeff Johnson295189b2012-06-20 16:38:30 -07006474
6475eHalStatus csrScanStartIdleScanTimer(tpAniSirGlobal pMac, tANI_U32 interval)
6476{
6477 eHalStatus status;
6478
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006479 smsLog(pMac, LOG1, " csrScanStartIdleScanTimer");
Jeff Johnson295189b2012-06-20 16:38:30 -07006480 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) && interval)
6481 {
6482 pMac->scan.nIdleScanTimeGap += interval;
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306483 vos_timer_stop(&pMac->scan.hTimerIdleScan);
6484 status = vos_timer_start(&pMac->scan.hTimerIdleScan, interval/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006485 if( !HAL_STATUS_SUCCESS(status) )
6486 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006487 smsLog(pMac, LOGE, " Fail to start Idle scan timer. status = %d interval = %d", status, interval);
Jeff Johnson295189b2012-06-20 16:38:30 -07006488 //This should not happen but set the flag to restart when ready
6489 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6490 }
6491 }
6492 else
6493 {
6494 if( pMac->scan.fScanEnable && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) )
6495 {
6496 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6497 }
6498 status = eHAL_STATUS_FAILURE;
6499 }
6500
6501 return (status);
6502}
6503
6504
6505eHalStatus csrScanStopIdleScanTimer(tpAniSirGlobal pMac)
6506{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306507 return (vos_timer_stop(&pMac->scan.hTimerIdleScan));
Jeff Johnson295189b2012-06-20 16:38:30 -07006508}
6509
6510
6511//Stop CSR from asking for IMPS, This function doesn't disable IMPS from CSR
6512void csrScanSuspendIMPS( tpAniSirGlobal pMac )
6513{
6514 csrScanCancelIdleScan(pMac);
6515}
6516
6517
6518//Start CSR from asking for IMPS. This function doesn't trigger CSR to request entering IMPS
6519//because IMPS maybe disabled.
6520void csrScanResumeIMPS( tpAniSirGlobal pMac )
6521{
6522 csrScanStartIdleScan( pMac );
6523}
6524
6525
6526void csrScanIMPSCallback(void *callbackContext, eHalStatus status)
6527{
6528 tpAniSirGlobal pMac = PMAC_STRUCT( callbackContext );
6529
6530 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6531 {
6532 if(pMac->roam.configParam.IsIdleScanEnabled)
6533 {
6534 if(HAL_STATUS_SUCCESS(status))
6535 {
6536 if(csrIsAllSessionDisconnected(pMac) && !csrIsRoamCommandWaiting(pMac))
6537 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006538 smsLog(pMac, LOGW, FL("starts idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006539 csrScanAllChannels(pMac, eCSR_SCAN_IDLE_MODE_SCAN);
6540 }
6541 else
6542 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006543 smsLog(pMac, LOGW, FL("cannot start idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006544 //even though we are in timer handle, calling stop timer will make sure the timer
6545 //doesn't get to restart.
6546 csrScanStopIdleScanTimer(pMac);
6547 }
6548 }
6549 else
6550 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006551 smsLog(pMac, LOGE, FL("sees not success status (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07006552 }
6553 }
6554 else
6555 {//we might need another flag to check if CSR needs to request imps at all
6556
6557 tANI_U32 nTime = 0;
6558
6559 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_FALSE;
6560 if(!HAL_STATUS_SUCCESS(csrScanTriggerIdleScan(pMac, &nTime)))
6561 {
6562 csrScanStartIdleScanTimer(pMac, nTime);
6563 }
6564 }
6565 }
6566}
6567
6568
6569//Param: pTimeInterval -- Caller allocated memory in return, if failed, to specify the nxt time interval for
6570//idle scan timer interval
6571//Return: Not success -- meaning it cannot start IMPS, caller needs to start a timer for idle scan
6572eHalStatus csrScanTriggerIdleScan(tpAniSirGlobal pMac, tANI_U32 *pTimeInterval)
6573{
6574 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
6575
6576 //Do not trigger IMPS in case of concurrency
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006577 if (vos_concurrent_sessions_running() && csrIsAnySessionInConnectState(pMac))
6578 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006579 smsLog( pMac, LOG1, FL("Cannot request IMPS because Concurrent Sessions Running") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006580 return (status);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006581 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006582
6583 if(pTimeInterval)
6584 {
6585 *pTimeInterval = 0;
6586 }
6587
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006588 smsLog(pMac, LOG3, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006589 if( smeCommandPending( pMac ) )
6590 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006591 smsLog( pMac, LOG1, FL(" Cannot request IMPS because command pending") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006592 //Not to enter IMPS because more work to do
6593 if(pTimeInterval)
6594 {
6595 *pTimeInterval = 0;
6596 }
6597 //restart when ready
6598 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6599
6600 return (status);
6601 }
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07006602 if (IsPmcImpsReqFailed (pMac))
6603 {
6604 if(pTimeInterval)
6605 {
6606 *pTimeInterval = 1000000; //usec
6607 }
6608 //restart when ready
6609 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006610
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07006611 return status;
6612 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006613 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6614 /*&& pMac->roam.configParam.impsSleepTime*/)
6615 {
6616 //Stop get result timer because idle scan gets scan result out of PE
6617 csrScanStopGetResultTimer(pMac);
6618 if(pTimeInterval)
6619 {
6620 *pTimeInterval = pMac->roam.configParam.impsSleepTime;
6621 }
6622 //pmcRequestImps take a period in millisecond unit.
6623 status = pmcRequestImps(pMac, pMac->roam.configParam.impsSleepTime / PAL_TIMER_TO_MS_UNIT, csrScanIMPSCallback, pMac);
6624 if(!HAL_STATUS_SUCCESS(status))
6625 {
6626 if(eHAL_STATUS_PMC_ALREADY_IN_IMPS != status)
6627 {
6628 //Do restart the timer if CSR thinks it cannot do IMPS
6629 if( !csrCheckPSReady( pMac ) )
6630 {
6631 if(pTimeInterval)
6632 {
6633 *pTimeInterval = 0;
6634 }
6635 //Set the restart flag to true because that idle scan
6636 //can be restarted even though the timer will not be running
6637 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6638 }
6639 else
6640 {
6641 //For not now, we do a quicker retry
6642 if(pTimeInterval)
6643 {
6644 *pTimeInterval = CSR_IDLE_SCAN_WAIT_TIME;
6645 }
6646 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006647 smsLog(pMac, LOGW, FL("call pmcRequestImps and it returns status code (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07006648 }
6649 else
6650 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006651 smsLog(pMac, LOGW, FL("already in IMPS"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006652 //Since CSR is the only module to request for IMPS. If it is already in IMPS, CSR assumes
6653 //the callback will be called in the future. Should not happen though.
6654 status = eHAL_STATUS_SUCCESS;
6655 pMac->scan.nIdleScanTimeGap = 0;
6656 }
6657 }
6658 else
6659 {
6660 //requested so let's reset the value
6661 pMac->scan.nIdleScanTimeGap = 0;
6662 }
6663 }
6664
6665 return (status);
6666}
6667
6668
6669eHalStatus csrScanStartIdleScan(tpAniSirGlobal pMac)
6670{
6671 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
6672 tANI_U32 nTime = 0;
6673
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006674 smsLog(pMac, LOGW, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006675 if(pMac->roam.configParam.IsIdleScanEnabled)
6676 {
6677 //stop bg scan first
6678 csrScanBGScanAbort(pMac);
6679 //Stop get result timer because idle scan gets scan result out of PE
6680 csrScanStopGetResultTimer(pMac);
6681 //Enable aging timer since idle scan is going on
6682 csrScanStartResultAgingTimer(pMac);
6683 }
6684 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_FALSE;
6685 status = csrScanTriggerIdleScan(pMac, &nTime);
6686 if(!HAL_STATUS_SUCCESS(status))
6687 {
6688 csrScanStartIdleScanTimer(pMac, nTime);
6689 }
6690
6691 return (status);
6692}
6693
6694
6695void csrScanCancelIdleScan(tpAniSirGlobal pMac)
6696{
6697 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6698 {
Jeff Johnson295189b2012-06-20 16:38:30 -07006699 if (vos_concurrent_sessions_running()) {
6700 return;
6701 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006702 smsLog(pMac, LOG1, " csrScanCancelIdleScan");
Jeff Johnson295189b2012-06-20 16:38:30 -07006703 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_TRUE;
6704 //Set the restart flag in case later on it is uncancelled
6705 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6706 csrScanStopIdleScanTimer(pMac);
6707 csrScanRemoveNotRoamingScanCommand(pMac);
6708 }
6709}
6710
6711
6712void csrScanIdleScanTimerHandler(void *pv)
6713{
6714 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6715 eHalStatus status;
6716 tANI_U32 nTime = 0;
6717
6718 smsLog(pMac, LOGW, " csrScanIdleScanTimerHandler called ");
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07006719 pmcResetImpsFailStatus (pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07006720 status = csrScanTriggerIdleScan(pMac, &nTime);
6721 if(!HAL_STATUS_SUCCESS(status) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan))
6722 {
6723 //Check whether it is time to actually do an idle scan
6724 if(pMac->scan.nIdleScanTimeGap >= pMac->roam.configParam.impsSleepTime)
6725 {
6726 pMac->scan.nIdleScanTimeGap = 0;
6727 csrScanIMPSCallback(pMac, eHAL_STATUS_SUCCESS);
6728 }
6729 else
6730 {
6731 csrScanStartIdleScanTimer(pMac, nTime);
6732 }
6733 }
6734}
6735
6736
6737
6738
6739tANI_BOOLEAN csrScanRemoveNotRoamingScanCommand(tpAniSirGlobal pMac)
6740{
6741 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
6742 tListElem *pEntry, *pEntryTmp;
6743 tSmeCmd *pCommand;
6744 tDblLinkList localList;
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306745 tDblLinkList *pCmdList;
Jeff Johnson295189b2012-06-20 16:38:30 -07006746
6747 vos_mem_zero(&localList, sizeof(tDblLinkList));
6748 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
6749 {
6750 smsLog(pMac, LOGE, FL(" failed to open list"));
6751 return fRet;
6752 }
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306753 if (!pMac->fScanOffload)
6754 pCmdList = &pMac->sme.smeCmdPendingList;
6755 else
6756 pCmdList = &pMac->sme.smeScanCmdPendingList;
Jeff Johnson295189b2012-06-20 16:38:30 -07006757
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306758 csrLLLock(pCmdList);
6759 pEntry = csrLLPeekHead(pCmdList, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07006760 while(pEntry)
6761 {
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306762 pEntryTmp = csrLLNext(pCmdList, pEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07006763 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6764 if( eSmeCommandScan == pCommand->command )
6765 {
6766 switch( pCommand->u.scanCmd.reason )
6767 {
6768 case eCsrScanIdleScan:
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306769 if( csrLLRemoveEntry(pCmdList, pEntry, LL_ACCESS_NOLOCK) )
Jeff Johnson295189b2012-06-20 16:38:30 -07006770 {
6771 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
6772 }
6773 fRet = eANI_BOOLEAN_TRUE;
6774 break;
6775
6776 default:
6777 break;
6778 } //switch
6779 }
6780 pEntry = pEntryTmp;
6781 }
6782
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306783 csrLLUnlock(pCmdList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006784
6785 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
6786 {
6787 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6788 csrReleaseCommandScan( pMac, pCommand );
6789 }
6790
6791 csrLLClose(&localList);
6792
6793 return (fRet);
6794}
6795
6796
6797tANI_BOOLEAN csrScanRemoveFreshScanCommand(tpAniSirGlobal pMac, tANI_U8 sessionId)
6798{
6799 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
6800 tListElem *pEntry, *pEntryTmp;
6801 tSmeCmd *pCommand;
6802 tDblLinkList localList;
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306803 tDblLinkList *pCmdList;
Jeff Johnson295189b2012-06-20 16:38:30 -07006804
6805 vos_mem_zero(&localList, sizeof(tDblLinkList));
6806 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
6807 {
6808 smsLog(pMac, LOGE, FL(" failed to open list"));
6809 return fRet;
6810 }
6811
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306812 if (!pMac->fScanOffload)
6813 pCmdList = &pMac->sme.smeCmdPendingList;
6814 else
6815 pCmdList = &pMac->sme.smeScanCmdPendingList;
6816
6817 csrLLLock(pCmdList);
6818 pEntry = csrLLPeekHead(pCmdList, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07006819 while(pEntry)
6820 {
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306821 pEntryTmp = csrLLNext(pCmdList, pEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07006822 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6823 if( (eSmeCommandScan == pCommand->command) && (sessionId == pCommand->sessionId) )
6824 {
6825 switch(pCommand->u.scanCmd.reason)
6826 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006827#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
6828 case eCsrScanGetLfrResult:
6829#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006830 case eCsrScanGetResult:
6831 case eCsrScanSetBGScanParam:
6832 case eCsrScanBGScanAbort:
6833 case eCsrScanBGScanEnable:
6834 case eCsrScanGetScanChnInfo:
6835 break;
6836 default:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006837 smsLog (pMac, LOGW, "%s: -------- abort scan command reason = %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07006838 __func__, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07006839 //The rest are fresh scan requests
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306840 if( csrLLRemoveEntry(pCmdList, pEntry, LL_ACCESS_NOLOCK) )
Jeff Johnson295189b2012-06-20 16:38:30 -07006841 {
6842 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
6843 }
6844 fRet = eANI_BOOLEAN_TRUE;
6845 break;
6846 }
6847 }
6848 pEntry = pEntryTmp;
6849 }
6850
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306851 csrLLUnlock(pCmdList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006852
6853 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
6854 {
6855 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6856 if (pCommand->u.scanCmd.callback)
6857 {
6858 /* User scan request is pending,
6859 * send response with status eCSR_SCAN_ABORT*/
6860 pCommand->u.scanCmd.callback(pMac,
6861 pCommand->u.scanCmd.pContext,
6862 pCommand->u.scanCmd.scanID,
6863 eCSR_SCAN_ABORT);
6864 }
6865 csrReleaseCommandScan( pMac, pCommand );
6866 }
6867 csrLLClose(&localList);
6868
6869 return (fRet);
6870}
6871
6872
6873void csrReleaseScanCommand(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
6874{
6875 eCsrScanReason reason = pCommand->u.scanCmd.reason;
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306876 tANI_BOOLEAN status;
6877
6878 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07006879 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306880 tANI_U32 i;
6881 for(i = 0; i < CSR_ROAM_SESSION_MAX; i++)
6882 csrRoamStateChange(pMac, pCommand->u.scanCmd.lastRoamState[i], i);
6883 }
6884 else
6885 {
6886 csrRoamStateChange(pMac,
6887 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId],
6888 pCommand->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07006889 }
6890
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306891 csrScanCallCallback(pMac, pCommand, scanStatus);
Jeff Johnson295189b2012-06-20 16:38:30 -07006892
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006893 smsLog(pMac, LOG3, " Remove Scan command reason = %d", reason);
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306894 if (pMac->fScanOffload)
6895 {
6896 status = csrLLRemoveEntry(&pMac->sme.smeScanCmdActiveList,
6897 &pCommand->Link, LL_ACCESS_LOCK);
6898 }
6899 else
6900 {
6901 status = csrLLRemoveEntry(&pMac->sme.smeCmdActiveList,
6902 &pCommand->Link, LL_ACCESS_LOCK);
6903 }
6904
6905 if(status)
Jeff Johnson295189b2012-06-20 16:38:30 -07006906 {
6907 csrReleaseCommandScan( pMac, pCommand );
6908 }
6909 else
6910 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306911 smsLog(pMac, LOGE,
6912 " ********csrReleaseScanCommand cannot release command reason %d",
6913 pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07006914 }
6915}
6916
6917
6918eHalStatus csrScanGetPMKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
6919 tPmkidCandidateInfo *pPmkidList, tANI_U32 *pNumItems )
6920{
6921 eHalStatus status = eHAL_STATUS_SUCCESS;
6922 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
6923
Jeff Johnson32d95a32012-09-10 13:15:23 -07006924 if(!pSession)
6925 {
6926 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
6927 return eHAL_STATUS_FAILURE;
6928 }
6929
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006930 smsLog(pMac, LOGW, " pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07006931 csrResetPMKIDCandidateList(pMac, sessionId);
6932 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
6933 {
6934 tCsrScanResultFilter *pScanFilter;
6935 tCsrScanResultInfo *pScanResult;
6936 tScanResultHandle hBSSList;
6937 tANI_U32 nItems = *pNumItems;
6938
6939 *pNumItems = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05306940 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
6941 if ( NULL == pScanFilter )
6942 status = eHAL_STATUS_FAILURE;
6943 else
Jeff Johnson295189b2012-06-20 16:38:30 -07006944 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306945 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006946 //Here is the profile we need to connect to
6947 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
6948 if(HAL_STATUS_SUCCESS(status))
6949 {
6950 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
6951 if(HAL_STATUS_SUCCESS(status))
6952 {
6953 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumPmkidCandidate < nItems))
6954 {
6955 //NumPmkidCandidate adds up here
6956 csrProcessBSSDescForPMKIDList(pMac, &pScanResult->BssDescriptor,
6957 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
6958 }
6959 if(pSession->NumPmkidCandidate)
6960 {
6961 *pNumItems = pSession->NumPmkidCandidate;
Kiet Lam64c1b492013-07-12 13:56:44 +05306962 vos_mem_copy(pPmkidList, pSession->PmkidCandidateInfo,
6963 pSession->NumPmkidCandidate * sizeof(tPmkidCandidateInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07006964 }
6965 csrScanResultPurge(pMac, hBSSList);
6966 }//Have scan result
6967 csrFreeScanFilter(pMac, pScanFilter);
6968 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306969 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07006970 }
6971 }
6972
6973 return (status);
6974}
6975
6976
6977
6978#ifdef FEATURE_WLAN_WAPI
6979eHalStatus csrScanGetBKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
6980 tBkidCandidateInfo *pBkidList, tANI_U32 *pNumItems )
6981{
6982 eHalStatus status = eHAL_STATUS_SUCCESS;
6983 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
6984
Jeff Johnson32d95a32012-09-10 13:15:23 -07006985 if(!pSession)
6986 {
6987 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
6988 return eHAL_STATUS_FAILURE;
6989 }
6990
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006991 smsLog(pMac, LOGW, " pMac->scan.NumBkidCandidate = %d", pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07006992 csrResetBKIDCandidateList(pMac, sessionId);
6993 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
6994 {
6995 tCsrScanResultFilter *pScanFilter;
6996 tCsrScanResultInfo *pScanResult;
6997 tScanResultHandle hBSSList;
6998 tANI_U32 nItems = *pNumItems;
6999 *pNumItems = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05307000 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
7001 if ( NULL == pScanFilter )
7002 status = eHAL_STATUS_FAILURE;
7003 else
Jeff Johnson295189b2012-06-20 16:38:30 -07007004 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307005 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007006 //Here is the profile we need to connect to
7007 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
7008 if(HAL_STATUS_SUCCESS(status))
7009 {
7010 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
7011 if(HAL_STATUS_SUCCESS(status))
7012 {
7013 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumBkidCandidate < nItems))
7014 {
7015 //pMac->scan.NumBkidCandidate adds up here
7016 csrProcessBSSDescForBKIDList(pMac, &pScanResult->BssDescriptor,
7017 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
7018
7019 }
7020 if(pSession->NumBkidCandidate)
7021 {
7022 *pNumItems = pSession->NumBkidCandidate;
Kiet Lam64c1b492013-07-12 13:56:44 +05307023 vos_mem_copy(pBkidList, pSession->BkidCandidateInfo, pSession->NumBkidCandidate * sizeof(tBkidCandidateInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07007024 }
7025 csrScanResultPurge(pMac, hBSSList);
7026 }//Have scan result
7027 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307028 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07007029 }
7030 }
7031
7032 return (status);
7033}
7034#endif /* FEATURE_WLAN_WAPI */
7035
7036
7037
7038//This function is usually used for BSSs that suppresses SSID so the profile
7039//shall have one and only one SSID
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007040eHalStatus csrScanForSSID(tpAniSirGlobal pMac, tANI_U32 sessionId, tCsrRoamProfile *pProfile, tANI_U32 roamId, tANI_BOOLEAN notify)
Jeff Johnson295189b2012-06-20 16:38:30 -07007041{
7042 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
7043 tSmeCmd *pScanCmd = NULL;
7044 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
7045 tANI_U8 index = 0;
7046 tANI_U32 numSsid = pProfile->SSIDs.numOfSSIDs;
7047
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007048 smsLog(pMac, LOG2, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007049 //For WDS, we use the index 0. There must be at least one in there
7050 if( CSR_IS_WDS_STA( pProfile ) && numSsid )
7051 {
7052 numSsid = 1;
7053 }
7054 if(pMac->scan.fScanEnable && ( numSsid == 1 ) )
7055 {
7056 do
7057 {
7058 pScanCmd = csrGetCommandBuffer(pMac);
7059 if(!pScanCmd)
7060 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007061 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007062 break;
7063 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307064 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
7065 pScanCmd->u.scanCmd.pToRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
7066 if ( NULL == pScanCmd->u.scanCmd.pToRoamProfile )
7067 status = eHAL_STATUS_FAILURE;
7068 else
7069 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07007070 status = csrRoamCopyProfile(pMac, pScanCmd->u.scanCmd.pToRoamProfile, pProfile);
7071 if(!HAL_STATUS_SUCCESS(status))
7072 break;
7073 pScanCmd->u.scanCmd.roamId = roamId;
7074 pScanCmd->command = eSmeCommandScan;
Jeff Johnsone7245742012-09-05 17:12:55 -07007075 pScanCmd->sessionId = (tANI_U8)sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07007076 pScanCmd->u.scanCmd.callback = NULL;
7077 pScanCmd->u.scanCmd.pContext = NULL;
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007078 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 -07007079 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Kiet Lam64c1b492013-07-12 13:56:44 +05307080 vos_mem_set(&pScanCmd->u.scanCmd.u.scanRequest, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007081 pScanCmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Jeff Johnson295189b2012-06-20 16:38:30 -07007082 pScanCmd->u.scanCmd.u.scanRequest.BSSType = pProfile->BSSType;
Jeff Johnsone7245742012-09-05 17:12:55 -07007083 // To avoid 11b rate in probe request Set p2pSearch flag as 1 for P2P Client Mode
7084 if(VOS_P2P_CLIENT_MODE == pProfile->csrPersona)
7085 {
7086 pScanCmd->u.scanCmd.u.scanRequest.p2pSearch = 1;
7087 }
7088 if(pProfile->pAddIEScan)
7089 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307090 pScanCmd->u.scanCmd.u.scanRequest.pIEField = vos_mem_malloc(
7091 pProfile->nAddIEScanLength);
7092 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.pIEField )
7093 status = eHAL_STATUS_FAILURE;
7094 else
7095 status = eHAL_STATUS_SUCCESS;
7096 vos_mem_set(pScanCmd->u.scanCmd.u.scanRequest.pIEField,
7097 pProfile->nAddIEScanLength, 0);
7098 if (HAL_STATUS_SUCCESS(status))
Jeff Johnsone7245742012-09-05 17:12:55 -07007099 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307100 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.pIEField,
7101 pProfile->pAddIEScan, pProfile->nAddIEScanLength);
Jeff Johnsone7245742012-09-05 17:12:55 -07007102 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = pProfile->nAddIEScanLength;
7103 }
7104 else
7105 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007106 smsLog(pMac, LOGE, "No memory for scanning IE fields");
Jeff Johnsone7245742012-09-05 17:12:55 -07007107 }
7108 } //Allocate memory for IE field
7109 else
7110 {
7111 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = 0;
7112 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07007113 /* For one channel be good enpugh time to receive beacon atleast */
7114 if( 1 == pProfile->ChannelInfo.numOfChannels )
7115 {
7116 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime = MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7117 pScanCmd->u.scanCmd.u.scanRequest.minChnTime = MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7118 }
7119 else
7120 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307121 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime =
7122 pMac->roam.configParam.nActiveMaxChnTime;
7123 pScanCmd->u.scanCmd.u.scanRequest.minChnTime =
7124 pMac->roam.configParam.nActiveMinChnTime;
Jeff Johnson32d95a32012-09-10 13:15:23 -07007125 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307126 pScanCmd->u.scanCmd.u.scanRequest.maxChnTimeBtc =
7127 pMac->roam.configParam.nActiveMaxChnTimeBtc;
7128 pScanCmd->u.scanCmd.u.scanRequest.minChnTimeBtc =
7129 pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07007130 if(pProfile->BSSIDs.numOfBSSIDs == 1)
7131 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307132 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.bssid,
7133 pProfile->BSSIDs.bssid, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07007134 }
7135 else
7136 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307137 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.bssid, bAddr, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07007138 }
7139 if(pProfile->ChannelInfo.numOfChannels)
7140 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307141 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(
7142 sizeof(*pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
7143 * pProfile->ChannelInfo.numOfChannels);
7144 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
7145 status = eHAL_STATUS_FAILURE;
7146 else
7147 status = eHAL_STATUS_SUCCESS;
7148 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
7149 if(HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07007150 {
7151 csrRoamIsChannelValid(pMac, pProfile->ChannelInfo.ChannelList[0]);
7152 for(index = 0; index < pProfile->ChannelInfo.numOfChannels; index++)
7153 {
7154 if(csrRoamIsValidChannel(pMac, pProfile->ChannelInfo.ChannelList[index]))
7155 {
7156 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels]
7157 = pProfile->ChannelInfo.ChannelList[index];
7158 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels++;
7159 }
7160 else
7161 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007162 smsLog(pMac, LOGW, FL("process a channel (%d) that is invalid"), pProfile->ChannelInfo.ChannelList[index]);
Jeff Johnson295189b2012-06-20 16:38:30 -07007163 }
7164
7165 }
7166 }
7167 else
7168 {
7169 break;
7170 }
7171
7172 }
7173 else
7174 {
7175 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
7176 }
7177 if(pProfile->SSIDs.numOfSSIDs)
7178 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307179 pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList = vos_mem_malloc(
7180 pProfile->SSIDs.numOfSSIDs * sizeof(tCsrSSIDInfo));
7181 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList )
7182 status = eHAL_STATUS_FAILURE;
7183 else
7184 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07007185 if(!HAL_STATUS_SUCCESS(status))
7186 {
7187 break;
7188 }
7189 pScanCmd->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 1;
Kiet Lam64c1b492013-07-12 13:56:44 +05307190 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList,
7191 pProfile->SSIDs.SSIDList, sizeof(tCsrSSIDInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07007192 }
7193 //Start process the command
7194 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
7195 if( !HAL_STATUS_SUCCESS( status ) )
7196 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007197 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07007198 break;
7199 }
7200 }while(0);
7201 if(!HAL_STATUS_SUCCESS(status))
7202 {
7203 if(pScanCmd)
7204 {
7205 csrReleaseCommandScan(pMac, pScanCmd);
7206 //TODO:free the memory that is allocated in this function
7207 }
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007208 if(notify)
7209 {
Jeff Johnson295189b2012-06-20 16:38:30 -07007210 csrRoamCallCallback(pMac, sessionId, NULL, roamId, eCSR_ROAM_FAILED, eCSR_ROAM_RESULT_FAILURE);
7211 }
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007212 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007213 }//valid
7214 else
7215 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007216 smsLog(pMac, LOGE, FL("cannot scan because scanEnable (%d) or numSSID (%d) is invalid"),
Jeff Johnson295189b2012-06-20 16:38:30 -07007217 pMac->scan.fScanEnable, pProfile->SSIDs.numOfSSIDs);
7218 }
7219
7220 return (status);
7221}
7222
7223
7224//Issue a scan base on the new capability infomation
7225//This should only happen when the associated AP changes its capability.
7226//After this scan is done, CSR reroams base on the new scan results
7227eHalStatus csrScanForCapabilityChange(tpAniSirGlobal pMac, tSirSmeApNewCaps *pNewCaps)
7228{
7229 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
7230 tSmeCmd *pScanCmd = NULL;
7231
7232 if(pNewCaps)
7233 {
7234 do
7235 {
7236 pScanCmd = csrGetCommandBuffer(pMac);
7237 if(!pScanCmd)
7238 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007239 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007240 status = eHAL_STATUS_RESOURCES;
7241 break;
7242 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307243 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007244 status = eHAL_STATUS_SUCCESS;
7245 pScanCmd->u.scanCmd.roamId = 0;
7246 pScanCmd->command = eSmeCommandScan;
7247 pScanCmd->u.scanCmd.callback = NULL;
7248 pScanCmd->u.scanCmd.pContext = NULL;
7249 pScanCmd->u.scanCmd.reason = eCsrScanForCapsChange;
7250 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
7251 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
7252 if( !HAL_STATUS_SUCCESS( status ) )
7253 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007254 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07007255 break;
7256 }
7257 }while(0);
7258 if(!HAL_STATUS_SUCCESS(status))
7259 {
7260 if(pScanCmd)
7261 {
7262 csrReleaseCommandScan(pMac, pScanCmd);
7263 }
7264 }
7265 }
7266
7267 return (status);
7268}
7269
7270
7271
7272void csrInitBGScanChannelList(tpAniSirGlobal pMac)
7273{
7274 tANI_U32 len = CSR_MIN(sizeof(pMac->roam.validChannelList), sizeof(pMac->scan.bgScanChannelList));
7275
Kiet Lam64c1b492013-07-12 13:56:44 +05307276 vos_mem_set(pMac->scan.bgScanChannelList, len, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007277 pMac->scan.numBGScanChannel = 0;
7278
7279 if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
7280 {
7281 pMac->roam.numValidChannels = len;
7282 pMac->scan.numBGScanChannel = (tANI_U8)CSR_MIN(len, WNI_CFG_BG_SCAN_CHANNEL_LIST_LEN);
Kiet Lam64c1b492013-07-12 13:56:44 +05307283 vos_mem_copy(pMac->scan.bgScanChannelList, pMac->roam.validChannelList,
7284 pMac->scan.numBGScanChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07007285 csrSetBGScanChannelList(pMac, pMac->scan.bgScanChannelList, pMac->scan.numBGScanChannel);
7286 }
7287}
7288
7289
7290//This function return TRUE if background scan channel list is adjusted.
7291//this function will only shrink the background scan channel list
7292tANI_BOOLEAN csrAdjustBGScanChannelList(tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels,
7293 tANI_U8 *pAdjustChannels, tANI_U8 *pNumAdjustChannels)
7294{
7295 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
7296 tANI_U8 i, j, count = *pNumAdjustChannels;
7297
7298 i = 0;
7299 while(i < count)
7300 {
7301 for(j = 0; j < NumChannels; j++)
7302 {
7303 if(pChannelList[j] == pAdjustChannels[i])
7304 break;
7305 }
7306 if(j == NumChannels)
7307 {
7308 //This channel is not in the list, remove it
7309 fRet = eANI_BOOLEAN_TRUE;
7310 count--;
7311 if(count - i)
7312 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307313 vos_mem_copy(&pAdjustChannels[i], &pAdjustChannels[i+1], count - i);
Jeff Johnson295189b2012-06-20 16:38:30 -07007314 }
7315 else
7316 {
7317 //already remove the last one. Done.
7318 break;
7319 }
7320 }
7321 else
7322 {
7323 i++;
7324 }
7325 }//while(i<count)
7326 *pNumAdjustChannels = count;
7327
7328 return (fRet);
7329}
7330
7331
7332//Get the list of the base channels to scan for passively 11d info
7333eHalStatus csrScanGetSupportedChannels( tpAniSirGlobal pMac )
7334{
7335 eHalStatus status = eHAL_STATUS_SUCCESS;
7336 int n = WNI_CFG_VALID_CHANNEL_LIST_LEN;
7337
7338 status = vos_nv_getSupportedChannels( pMac->scan.baseChannels.channelList, &n, NULL, NULL );
7339 if( HAL_STATUS_SUCCESS(status) )
7340 {
7341 pMac->scan.baseChannels.numChannels = (tANI_U8)n;
7342 }
7343 else
7344 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007345 smsLog( pMac, LOGE, FL(" failed") );
Jeff Johnson295189b2012-06-20 16:38:30 -07007346 pMac->scan.baseChannels.numChannels = 0;
7347 }
7348
7349 return ( status );
7350}
7351
7352//This function use the input pChannelList to validate the current saved channel list
7353eHalStatus csrSetBGScanChannelList( tpAniSirGlobal pMac, tANI_U8 *pAdjustChannels, tANI_U8 NumAdjustChannels)
7354{
7355 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumAdjustChannels;
7356
7357 return (ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pAdjustChannels, dataLen, NULL, eANI_BOOLEAN_FALSE));
7358}
7359
7360
7361void csrSetCfgValidChannelList( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels )
7362{
7363 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumChannels;
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05307364 eHalStatus status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007365
7366 ccmCfgSetStr(pMac, WNI_CFG_VALID_CHANNEL_LIST, pChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
7367
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05307368 if (pMac->fScanOffload)
7369 {
7370 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
7371 "Scan offload is enabled, update default chan list");
7372 status = csrUpdateChannelList(&pMac->scan);
7373 if (eHAL_STATUS_SUCCESS != status)
7374 {
7375 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR,
7376 "failed to update the supported channel list");
7377 }
7378 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007379 return;
7380}
7381
7382
7383
7384/*
7385 * The Tx power limits are saved in the cfg for future usage.
7386 */
7387void csrSaveTxPowerToCfg( tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 cfgId )
7388{
7389 tListElem *pEntry;
7390 tANI_U32 cbLen = 0, dataLen;
7391 tCsrChannelPowerInfo *pChannelSet;
7392 tANI_U32 idx;
7393 tSirMacChanInfo *pChannelPowerSet;
7394 tANI_U8 *pBuf = NULL;
7395
7396 //allocate maximum space for all channels
7397 dataLen = WNI_CFG_VALID_CHANNEL_LIST_LEN * sizeof(tSirMacChanInfo);
Kiet Lam64c1b492013-07-12 13:56:44 +05307398 if ( (pBuf = vos_mem_malloc(dataLen)) != NULL )
Jeff Johnson295189b2012-06-20 16:38:30 -07007399 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307400 vos_mem_set(pBuf, dataLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007401 pChannelPowerSet = (tSirMacChanInfo *)(pBuf);
7402
7403 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
7404 // write the tuples (startChan, numChan, txPower) for each channel found in the channel power list.
7405 while( pEntry )
7406 {
7407 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
7408 if ( 1 != pChannelSet->interChannelOffset )
7409 {
7410 // we keep the 5G channel sets internally with an interchannel offset of 4. Expand these
7411 // to the right format... (inter channel offset of 1 is the only option for the triplets
7412 // that 11d advertises.
7413 if ((cbLen + (pChannelSet->numChannels * sizeof(tSirMacChanInfo))) >= dataLen)
7414 {
7415 // expanding this entry will overflow our allocation
7416 smsLog(pMac, LOGE,
7417 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007418 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07007419 pChannelSet->firstChannel,
7420 pChannelSet->numChannels,
7421 pChannelSet->interChannelOffset);
7422 break;
7423 }
7424
7425 for( idx = 0; idx < pChannelSet->numChannels; idx++ )
7426 {
7427 pChannelPowerSet->firstChanNum = (tSirMacChanNum)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007428 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07007429 pChannelPowerSet->numChannels = 1;
Jeff Johnson295189b2012-06-20 16:38:30 -07007430 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007431 smsLog(pMac, LOG3, " Setting Max Transmit Power %d", pChannelPowerSet->maxTxPower);
Jeff Johnson295189b2012-06-20 16:38:30 -07007432 cbLen += sizeof( tSirMacChanInfo );
7433 pChannelPowerSet++;
7434 }
7435 }
7436 else
7437 {
7438 if (cbLen >= dataLen)
7439 {
7440 // this entry will overflow our allocation
7441 smsLog(pMac, LOGE,
7442 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007443 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07007444 pChannelSet->firstChannel,
7445 pChannelSet->numChannels,
7446 pChannelSet->interChannelOffset);
7447 break;
7448 }
7449 pChannelPowerSet->firstChanNum = pChannelSet->firstChannel;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007450 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07007451 pChannelPowerSet->numChannels = pChannelSet->numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -07007452 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007453 smsLog(pMac, LOG3, " Setting Max Transmit Power %d, nTxPower %d", pChannelPowerSet->maxTxPower,pMac->roam.configParam.nTxPowerCap );
Jeff Johnson295189b2012-06-20 16:38:30 -07007454
7455
7456 cbLen += sizeof( tSirMacChanInfo );
7457 pChannelPowerSet++;
7458 }
7459
7460 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
7461 }
7462
7463 if(cbLen)
7464 {
7465 ccmCfgSetStr(pMac, cfgId, (tANI_U8 *)pBuf, cbLen, NULL, eANI_BOOLEAN_FALSE);
7466 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307467 vos_mem_free(pBuf);
Jeff Johnson295189b2012-06-20 16:38:30 -07007468 }//Allocate memory
7469}
7470
7471
7472void csrSetCfgCountryCode( tpAniSirGlobal pMac, tANI_U8 *countryCode )
7473{
7474 tANI_U8 cc[WNI_CFG_COUNTRY_CODE_LEN];
7475 ///v_REGDOMAIN_t DomainId;
7476
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007477 smsLog( pMac, LOG3, "Setting Country Code in Cfg from csrSetCfgCountryCode %s",countryCode );
Kiet Lam64c1b492013-07-12 13:56:44 +05307478 vos_mem_copy(cc, countryCode, WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07007479
7480 // don't program the bogus country codes that we created for Korea in the MAC. if we see
7481 // the bogus country codes, program the MAC with the right country code.
7482 if ( ( 'K' == countryCode[ 0 ] && '1' == countryCode[ 1 ] ) ||
7483 ( 'K' == countryCode[ 0 ] && '2' == countryCode[ 1 ] ) ||
7484 ( 'K' == countryCode[ 0 ] && '3' == countryCode[ 1 ] ) ||
7485 ( 'K' == countryCode[ 0 ] && '4' == countryCode[ 1 ] ) )
7486 {
7487 // replace the alternate Korea country codes, 'K1', 'K2', .. with 'KR' for Korea
7488 cc[ 1 ] = 'R';
7489 }
7490 ccmCfgSetStr(pMac, WNI_CFG_COUNTRY_CODE, cc, WNI_CFG_COUNTRY_CODE_LEN, NULL, eANI_BOOLEAN_FALSE);
7491
7492 //Need to let HALPHY know about the current domain so it can apply some
7493 //domain-specific settings (TX filter...)
7494 /*if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(pMac, cc, &DomainId)))
7495 {
7496 halPhySetRegDomain(pMac, DomainId);
7497 }*/
7498}
7499
7500
7501
7502eHalStatus csrGetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pBuf, tANI_U8 *pbLen)
7503{
7504 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
7505 tANI_U32 len;
7506
7507 if(pBuf && pbLen && (*pbLen >= WNI_CFG_COUNTRY_CODE_LEN))
7508 {
7509 len = *pbLen;
7510 status = ccmCfgGetStr(pMac, WNI_CFG_COUNTRY_CODE, pBuf, &len);
7511 if(HAL_STATUS_SUCCESS(status))
7512 {
7513 *pbLen = (tANI_U8)len;
7514 }
7515 }
7516
7517 return (status);
7518}
7519
7520
7521void csrSetCfgScanControlList( tpAniSirGlobal pMac, tANI_U8 *countryCode, tCsrChannel *pChannelList )
7522{
7523 tANI_U8 i, j;
7524 tANI_BOOLEAN found=FALSE;
7525 tANI_U8 *pControlList = NULL;
7526 tANI_U32 len = WNI_CFG_SCAN_CONTROL_LIST_LEN;
7527
Kiet Lam64c1b492013-07-12 13:56:44 +05307528 if ( (pControlList = vos_mem_malloc(WNI_CFG_SCAN_CONTROL_LIST_LEN)) != NULL )
Jeff Johnson295189b2012-06-20 16:38:30 -07007529 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307530 vos_mem_set((void *)pControlList, WNI_CFG_SCAN_CONTROL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007531 if(HAL_STATUS_SUCCESS(ccmCfgGetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, &len)))
7532 {
7533 for (i = 0; i < pChannelList->numChannels; i++)
7534 {
7535 for (j = 0; j < len; j += 2)
7536 {
7537 if (pControlList[j] == pChannelList->channelList[i])
7538 {
7539 found = TRUE;
7540 break;
7541 }
7542 }
7543
7544 if (found) // insert a pair(channel#, flag)
7545 {
Gopichand Nakkala392cbc12013-05-28 16:15:00 +05307546 pControlList[j+1] = csrGetScanType(pMac, pControlList[j]);
Jeff Johnson295189b2012-06-20 16:38:30 -07007547 found = FALSE; // reset the flag
7548 }
7549
7550 }
7551
7552 ccmCfgSetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, len, NULL, eANI_BOOLEAN_FALSE);
7553 }//Successfully getting scan control list
Kiet Lam64c1b492013-07-12 13:56:44 +05307554 vos_mem_free(pControlList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007555 }//AllocateMemory
7556}
7557
7558
7559//if bgPeriod is 0, background scan is disabled. It is in millisecond units
7560eHalStatus csrSetCfgBackgroundScanPeriod(tpAniSirGlobal pMac, tANI_U32 bgPeriod)
7561{
7562 return (ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, bgPeriod, (tCcmCfgSetCallback) csrScanCcmCfgSetCallback, eANI_BOOLEAN_FALSE));
7563}
7564
7565
7566void csrScanCcmCfgSetCallback(tHalHandle hHal, tANI_S32 result)
7567{
7568 tListElem *pEntry = NULL;
7569 tSmeCmd *pCommand = NULL;
7570 tpAniSirGlobal pMac = PMAC_STRUCT( hHal );
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307571 tDblLinkList *pCmdList ;
7572
7573 if (!pMac->fScanOffload)
7574 pCmdList = &pMac->sme.smeCmdActiveList;
7575 else
7576 pCmdList = &pMac->sme.smeScanCmdActiveList;
7577
7578 pEntry = csrLLPeekHead( pCmdList, LL_ACCESS_LOCK );
Jeff Johnson295189b2012-06-20 16:38:30 -07007579 if ( pEntry )
7580 {
7581 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7582 if ( eSmeCommandScan == pCommand->command )
7583 {
7584 eCsrScanStatus scanStatus = (CCM_IS_RESULT_SUCCESS(result)) ? eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
7585 csrReleaseScanCommand(pMac, pCommand, scanStatus);
7586 }
7587 else
7588 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007589 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
Jeff Johnson295189b2012-06-20 16:38:30 -07007590 }
7591 }
7592 smeProcessPendingQueue( pMac );
7593}
7594
7595eHalStatus csrProcessSetBGScanParam(tpAniSirGlobal pMac, tSmeCmd *pCommand)
7596{
7597 eHalStatus status;
7598 tCsrBGScanRequest *pScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
7599 tANI_U32 dataLen = sizeof( tANI_U8 ) * pScanReq->ChannelInfo.numOfChannels;
7600
7601 //***setcfg for background scan channel list
7602 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MINIMUM_CHANNEL_TIME, pScanReq->minChnTime, NULL, eANI_BOOLEAN_FALSE);
7603 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MAXIMUM_CHANNEL_TIME, pScanReq->maxChnTime, NULL, eANI_BOOLEAN_FALSE);
7604 //Not set the background scan interval if not connected because bd scan should not be run if not connected
7605 if(!csrIsAllSessionDisconnected(pMac))
7606 {
7607 //If disbaling BG scan here, we need to stop aging as well
7608 if(pScanReq->scanInterval == 0)
7609 {
7610 //Stop aging because no new result is coming in
7611 csrScanStopResultAgingTimer(pMac);
7612 }
7613
7614#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
7615 {
7616 vos_log_scan_pkt_type *pScanLog = NULL;
7617
7618 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
7619 if(pScanLog)
7620 {
7621 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
7622 pScanLog->minChnTime = (v_U8_t)pScanReq->minChnTime;
7623 pScanLog->maxChnTime = (v_U8_t)pScanReq->maxChnTime;
7624 pScanLog->timeBetweenBgScan = (v_U8_t)pScanReq->scanInterval;
7625 pScanLog->numChannel = pScanReq->ChannelInfo.numOfChannels;
7626 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
7627 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307628 vos_mem_copy(pScanLog->channels,
7629 pScanReq->ChannelInfo.ChannelList,
7630 pScanLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07007631 }
7632 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
7633 }
7634 }
7635#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
7636
7637 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, pScanReq->scanInterval, NULL, eANI_BOOLEAN_FALSE);
7638 }
7639 else
7640 {
7641 //No need to stop aging because IDLE scan is still running
7642 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, 0, NULL, eANI_BOOLEAN_FALSE);
7643 }
7644
7645 if(pScanReq->SSID.length > WNI_CFG_SSID_LEN)
7646 {
7647 pScanReq->SSID.length = WNI_CFG_SSID_LEN;
7648 }
7649
7650 status = ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pScanReq->ChannelInfo.ChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
7651 status = ccmCfgSetStr(pMac, WNI_CFG_SSID, (tANI_U8 *)pScanReq->SSID.ssId, pScanReq->SSID.length, NULL, eANI_BOOLEAN_FALSE);
7652
7653
7654
7655 return (status);
7656}
7657
7658
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307659eHalStatus csrScanAbortMacScan(tpAniSirGlobal pMac, tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07007660{
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307661 eHalStatus status = eHAL_STATUS_FAILURE;
7662 tSirSmeScanAbortReq *pMsg;
Jeff Johnson295189b2012-06-20 16:38:30 -07007663 tANI_U16 msgLen;
7664 tListElem *pEntry;
7665 tSmeCmd *pCommand;
7666
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307667 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07007668 {
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307669#ifdef WLAN_AP_STA_CONCURRENCY
7670 csrLLLock(&pMac->scan.scanCmdPendingList);
7671 while(NULL !=
7672 (pEntry = csrLLRemoveHead(&pMac->scan.scanCmdPendingList,
7673 LL_ACCESS_NOLOCK)))
7674 {
Jeff Johnson295189b2012-06-20 16:38:30 -07007675
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307676 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7677 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
7678 }
7679 csrLLUnlock(&pMac->scan.scanCmdPendingList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007680#endif
7681
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307682 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
7683 csrRemoveCmdFromPendingList( pMac, &pMac->roam.roamCmdPendingList, eSmeCommandScan);
7684 csrRemoveCmdFromPendingList( pMac, &pMac->sme.smeCmdPendingList, eSmeCommandScan);
7685 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
7686
7687 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
7688 }
7689 else
7690 {
7691 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
7692 csrRemoveCmdWithSessionIdFromPendingList(pMac,
7693 sessionId,
7694 &pMac->sme.smeScanCmdPendingList,
7695 eSmeCommandScan);
7696 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
7697
7698 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
7699 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007700
7701 //We need to abort scan only if we are scanning
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307702 if(NULL != pEntry)
Jeff Johnson295189b2012-06-20 16:38:30 -07007703 {
7704 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307705 if(eSmeCommandScan == pCommand->command &&
7706 pCommand->sessionId == sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07007707 {
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307708 msgLen = (tANI_U16)(sizeof(tSirSmeScanAbortReq));
Kiet Lam64c1b492013-07-12 13:56:44 +05307709 pMsg = vos_mem_malloc(msgLen);
7710 if ( NULL == pMsg )
Jeff Johnson295189b2012-06-20 16:38:30 -07007711 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307712 status = eHAL_STATUS_FAILURE;
7713 smsLog(pMac, LOGE, FL("Failed to allocate memory for SmeScanAbortReq"));
7714 }
7715 else
7716 {
7717 vos_mem_set((void *)pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007718 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_ABORT_IND);
7719 pMsg->msgLen = pal_cpu_to_be16(msgLen);
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307720 pMsg->sessionId = sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07007721 status = palSendMBMessage(pMac->hHdd, pMsg);
7722 }
7723 }
7724 }
7725
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307726 return(status);
7727}
7728
7729void csrRemoveCmdWithSessionIdFromPendingList(tpAniSirGlobal pMac,
7730 tANI_U8 sessionId,
7731 tDblLinkList *pList,
7732 eSmeCommandType commandType)
7733{
7734 tDblLinkList localList;
7735 tListElem *pEntry;
7736 tSmeCmd *pCommand;
7737 tListElem *pEntryToRemove;
7738
7739 vos_mem_zero(&localList, sizeof(tDblLinkList));
7740 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
7741 {
7742 smsLog(pMac, LOGE, FL(" failed to open list"));
7743 return;
7744 }
7745
7746 csrLLLock(pList);
7747 if ((pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK)))
7748 {
7749
7750 /* Have to make sure we don't loop back to the head of the list,
7751 * which will happen if the entry is NOT on the list */
7752 while (pEntry)
7753 {
7754 pEntryToRemove = pEntry;
7755 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
7756 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
7757 if ((pCommand->command == commandType) &&
7758 (pCommand->sessionId == sessionId))
7759 {
7760 /* Remove that entry only */
7761 if (csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
7762 {
7763 csrLLInsertTail(&localList, pEntryToRemove,
7764 LL_ACCESS_NOLOCK);
7765 }
7766 }
7767 }
7768 }
7769 csrLLUnlock(pList);
7770
7771 while ((pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)))
7772 {
7773 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7774 csrAbortCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
7775 }
7776
7777 csrLLClose(&localList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007778}
7779
7780void csrRemoveCmdFromPendingList(tpAniSirGlobal pMac, tDblLinkList *pList,
7781 eSmeCommandType commandType )
7782{
7783 tDblLinkList localList;
7784 tListElem *pEntry;
7785 tSmeCmd *pCommand;
7786 tListElem *pEntryToRemove;
7787
7788 vos_mem_zero(&localList, sizeof(tDblLinkList));
7789 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
7790 {
7791 smsLog(pMac, LOGE, FL(" failed to open list"));
7792 return;
7793 }
7794
7795 csrLLLock(pList);
7796 if( !csrLLIsListEmpty( pList, LL_ACCESS_NOLOCK ) )
7797 {
7798 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK);
7799
7800 // Have to make sure we don't loop back to the head of the list, which will
7801 // happen if the entry is NOT on the list...
7802 while( pEntry )
7803 {
7804 pEntryToRemove = pEntry;
7805 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
7806 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
7807 if ( pCommand->command == commandType )
7808 {
7809 // Remove that entry only
7810 if(csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
7811 {
7812 csrLLInsertTail(&localList, pEntryToRemove, LL_ACCESS_NOLOCK);
7813 }
7814 }
7815 }
7816
7817
7818 }
7819 csrLLUnlock(pList);
7820
7821 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
7822 {
7823 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7824 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
7825 }
7826 csrLLClose(&localList);
7827
7828}
7829
7830
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307831eHalStatus csrScanAbortMacScanNotForConnect(tpAniSirGlobal pMac,
7832 tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07007833{
7834 eHalStatus status = eHAL_STATUS_SUCCESS;
7835
7836 if( !csrIsScanForRoamCommandActive( pMac ) )
7837 {
7838 //Only abort the scan if it is not used for other roam/connect purpose
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307839 status = csrScanAbortMacScan(pMac, sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07007840 }
7841
7842 return (status);
7843}
7844
7845
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05307846eHalStatus csrScanGetScanChannelInfo(tpAniSirGlobal pMac, tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07007847{
7848 eHalStatus status = eHAL_STATUS_SUCCESS;
7849 tSirMbMsg *pMsg;
7850 tANI_U16 msgLen;
7851
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05307852 if (pMac->fScanOffload)
7853 msgLen = (tANI_U16)(sizeof(tSirSmeGetScanChanReq));
7854 else
7855 msgLen = (tANI_U16)(sizeof(tSirMbMsg));
7856
Kiet Lam64c1b492013-07-12 13:56:44 +05307857 pMsg = vos_mem_malloc(msgLen);
7858 if ( NULL == pMsg )
7859 status = eHAL_STATUS_FAILURE;
7860 else
Jeff Johnson295189b2012-06-20 16:38:30 -07007861 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307862 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007863 pMsg->type = eWNI_SME_GET_SCANNED_CHANNEL_REQ;
7864 pMsg->msgLen = msgLen;
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05307865 if (pMac->fScanOffload)
7866 ((tSirSmeGetScanChanReq *)pMsg)->sessionId = sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07007867 status = palSendMBMessage(pMac->hHdd, pMsg);
7868 }
7869
7870 return( status );
7871}
7872
7873tANI_BOOLEAN csrRoamIsValidChannel( tpAniSirGlobal pMac, tANI_U8 channel )
7874{
7875 tANI_BOOLEAN fValid = FALSE;
7876 tANI_U32 idxValidChannels;
7877 tANI_U32 len = pMac->roam.numValidChannels;
7878
7879 for ( idxValidChannels = 0; ( idxValidChannels < len ); idxValidChannels++ )
7880 {
7881 if ( channel == pMac->roam.validChannelList[ idxValidChannels ] )
7882 {
7883 fValid = TRUE;
7884 break;
7885 }
7886 }
7887
7888 return fValid;
7889}
7890
Srikant Kuppa066904f2013-05-07 13:56:02 -07007891eHalStatus csrScanSavePreferredNetworkFound(tpAniSirGlobal pMac,
7892 tSirPrefNetworkFoundInd *pPrefNetworkFoundInd)
7893{
7894 v_U32_t uLen = 0;
7895 tpSirProbeRespBeacon pParsedFrame;
7896 tCsrScanResult *pScanResult = NULL;
7897 tSirBssDescription *pBssDescr = NULL;
7898 tANI_BOOLEAN fDupBss;
7899 tDot11fBeaconIEs *pIesLocal = NULL;
7900 tAniSSID tmpSsid;
7901 v_TIME_t timer=0;
7902 tpSirMacMgmtHdr macHeader = (tpSirMacMgmtHdr)pPrefNetworkFoundInd->data;
7903
7904 pParsedFrame =
Kiet Lam64c1b492013-07-12 13:56:44 +05307905 (tpSirProbeRespBeacon)vos_mem_malloc(sizeof(tSirProbeRespBeacon));
Srikant Kuppa066904f2013-05-07 13:56:02 -07007906
7907 if (NULL == pParsedFrame)
7908 {
7909 smsLog(pMac, LOGE, FL(" fail to allocate memory for frame"));
7910 return eHAL_STATUS_RESOURCES;
7911 }
7912
7913 if ( pPrefNetworkFoundInd->frameLength <= SIR_MAC_HDR_LEN_3A )
7914 {
7915 smsLog(pMac, LOGE,
7916 FL("Not enough bytes in PNO indication probe resp frame! length=%d"),
7917 pPrefNetworkFoundInd->frameLength);
7918 vos_mem_free(pParsedFrame);
7919 return eHAL_STATUS_FAILURE;
7920 }
7921
7922 if (sirConvertProbeFrame2Struct(pMac,
7923 &pPrefNetworkFoundInd->data[SIR_MAC_HDR_LEN_3A],
7924 pPrefNetworkFoundInd->frameLength - SIR_MAC_HDR_LEN_3A,
7925 pParsedFrame) != eSIR_SUCCESS ||
7926 !pParsedFrame->ssidPresent)
7927 {
7928 smsLog(pMac, LOGE,
7929 FL("Parse error ProbeResponse, length=%d"),
7930 pPrefNetworkFoundInd->frameLength);
7931 vos_mem_free(pParsedFrame);
7932 return eHAL_STATUS_FAILURE;
7933 }
7934 //24 byte MAC header and 12 byte to ssid IE
7935 if (pPrefNetworkFoundInd->frameLength >
7936 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET))
7937 {
7938 uLen = pPrefNetworkFoundInd->frameLength -
7939 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET);
7940 }
7941
Kiet Lam64c1b492013-07-12 13:56:44 +05307942 pScanResult = vos_mem_malloc(sizeof(tCsrScanResult) + uLen);
7943 if ( NULL == pScanResult )
Srikant Kuppa066904f2013-05-07 13:56:02 -07007944 {
7945 smsLog(pMac, LOGE, FL(" fail to allocate memory for frame"));
7946 vos_mem_free(pParsedFrame);
7947 return eHAL_STATUS_RESOURCES;
7948 }
7949
Kiet Lam64c1b492013-07-12 13:56:44 +05307950 vos_mem_set(pScanResult, sizeof(tCsrScanResult) + uLen, 0);
Srikant Kuppa066904f2013-05-07 13:56:02 -07007951 pBssDescr = &pScanResult->Result.BssDescriptor;
7952 /**
7953 * Length of BSS desription is without length of
7954 * length itself and length of pointer
7955 * that holds the next BSS description
7956 */
7957 pBssDescr->length = (tANI_U16)(
7958 sizeof(tSirBssDescription) - sizeof(tANI_U16) -
7959 sizeof(tANI_U32) + uLen);
7960 if (pParsedFrame->dsParamsPresent)
7961 {
7962 pBssDescr->channelId = pParsedFrame->channelNumber;
7963 }
7964 else if (pParsedFrame->HTInfo.present)
7965 {
7966 pBssDescr->channelId = pParsedFrame->HTInfo.primaryChannel;
7967 }
7968 else
7969 {
7970 pBssDescr->channelId = pParsedFrame->channelNumber;
7971 }
7972
7973 if ((pBssDescr->channelId > 0) && (pBssDescr->channelId < 15))
7974 {
7975 int i;
7976 // 11b or 11g packet
7977 // 11g iff extended Rate IE is present or
7978 // if there is an A rate in suppRate IE
7979 for (i = 0; i < pParsedFrame->supportedRates.numRates; i++)
7980 {
7981 if (sirIsArate(pParsedFrame->supportedRates.rate[i] & 0x7f))
7982 {
7983 pBssDescr->nwType = eSIR_11G_NW_TYPE;
7984 break;
7985 }
7986 }
7987 if (pParsedFrame->extendedRatesPresent)
7988 {
7989 pBssDescr->nwType = eSIR_11G_NW_TYPE;
7990 }
7991 }
7992 else
7993 {
7994 // 11a packet
7995 pBssDescr->nwType = eSIR_11A_NW_TYPE;
7996 }
7997
7998 pBssDescr->sinr = 0;
7999 pBssDescr->rssi = -1 * pPrefNetworkFoundInd->rssi;
8000 pBssDescr->beaconInterval = pParsedFrame->beaconInterval;
8001 pBssDescr->timeStamp[0] = pParsedFrame->timeStamp[0];
8002 pBssDescr->timeStamp[1] = pParsedFrame->timeStamp[1];
8003 pBssDescr->capabilityInfo = *((tANI_U16 *)&pParsedFrame->capabilityInfo);
Kiet Lam64c1b492013-07-12 13:56:44 +05308004 vos_mem_copy((tANI_U8 *) &pBssDescr->bssId, (tANI_U8 *) macHeader->bssId, sizeof(tSirMacAddr));
Srikant Kuppa066904f2013-05-07 13:56:02 -07008005 pBssDescr->nReceivedTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
8006
8007 smsLog( pMac, LOG2, "(%s):Bssid= %02x-%02x-%02x-%02x-%02x-%02x "
8008 "chan= %d, rssi = %d", __func__,
8009 pBssDescr->bssId[ 0 ], pBssDescr->bssId[ 1 ],
8010 pBssDescr->bssId[ 2 ], pBssDescr->bssId[ 3 ],
8011 pBssDescr->bssId[ 4 ], pBssDescr->bssId[ 5 ],
8012 pBssDescr->channelId,
8013 pBssDescr->rssi );
8014
8015 //IEs
8016 if (uLen)
8017 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308018 vos_mem_copy(&pBssDescr->ieFields,
8019 pPrefNetworkFoundInd->data + (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET),
8020 uLen);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008021 }
8022
8023 pIesLocal = (tDot11fBeaconIEs *)( pScanResult->Result.pvIes );
8024 if ( !pIesLocal &&
8025 (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
8026 &pScanResult->Result.BssDescriptor, &pIesLocal))) )
8027 {
8028 smsLog(pMac, LOGE, FL(" Cannot parse IEs"));
8029 csrFreeScanResultEntry(pMac, pScanResult);
8030 vos_mem_free(pParsedFrame);
8031 return eHAL_STATUS_RESOURCES;
8032 }
8033
8034 fDupBss = csrRemoveDupBssDescription( pMac,
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05308035 &pScanResult->Result.BssDescriptor, pIesLocal, &tmpSsid, &timer, FALSE);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008036 //Check whether we have reach out limit
8037 if ( CSR_SCAN_IS_OVER_BSS_LIMIT(pMac) )
8038 {
8039 //Limit reach
8040 smsLog(pMac, LOGE, FL(" BSS limit reached"));
8041 //Free the resources
8042 if( (pScanResult->Result.pvIes == NULL) && pIesLocal )
8043 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308044 vos_mem_free(pIesLocal);
Srikant Kuppa066904f2013-05-07 13:56:02 -07008045 }
8046 csrFreeScanResultEntry(pMac, pScanResult);
8047 vos_mem_free(pParsedFrame);
8048 return eHAL_STATUS_RESOURCES;
8049 }
8050 //Add to scan cache
8051 csrScanAddResult(pMac, pScanResult, pIesLocal);
8052
Kiet Lamb537cfb2013-11-07 12:56:49 +05308053 if( (pScanResult->Result.pvIes == NULL) && pIesLocal )
8054 {
8055 vos_mem_free(pIesLocal);
8056 }
8057
Srikant Kuppa066904f2013-05-07 13:56:02 -07008058 vos_mem_free(pParsedFrame);
8059
8060 return eHAL_STATUS_SUCCESS;
8061}
8062
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008063#ifdef FEATURE_WLAN_LFR
8064void csrInitOccupiedChannelsList(tpAniSirGlobal pMac)
8065{
8066 tListElem *pEntry = NULL;
8067 tCsrScanResult *pBssDesc = NULL;
8068 tDot11fBeaconIEs *pIes = NULL;
Srinivas28b5b4e2012-12-12 13:07:53 -08008069 tpCsrNeighborRoamControlInfo pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
8070
8071 if (0 != pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels)
8072 {
8073 smsLog(pMac, LOG1, FL("%s: Ini file contains neighbor scan channel list,"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008074 " hence NO need to build occupied channel list (numChannels = %d)"),
Srinivas28b5b4e2012-12-12 13:07:53 -08008075 __func__, pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels);
8076 return;
8077 }
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008078
8079 if (!csrNeighborRoamIsNewConnectedProfile(pMac))
8080 {
8081 smsLog(pMac, LOG2, FL("%s: donot flush occupied list since current roam profile"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008082 " matches previous (numChannels = %d)"),
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008083 __func__, pMac->scan.occupiedChannels.numChannels);
8084 return;
8085 }
8086
8087 /* Empty occupied channels here */
8088 pMac->scan.occupiedChannels.numChannels = 0;
8089
8090 csrLLLock(&pMac->scan.scanResultList);
8091 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
8092 while( pEntry )
8093 {
8094 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
8095 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
8096
8097 //At this time, pBssDescription->Result.pvIes may be NULL
Srikant Kuppa866893f2012-12-27 17:28:14 -08008098 if( !pIes && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008099 &pBssDesc->Result.BssDescriptor, &pIes))) )
8100 {
8101 continue;
8102 }
8103
8104 csrScanAddToOccupiedChannels(pMac, pBssDesc, &pMac->scan.occupiedChannels, pIes);
8105
8106 /*
8107 * Free the memory allocated for pIes in csrGetParsedBssDescriptionIEs
8108 */
8109 if( (pBssDesc->Result.pvIes == NULL) && pIes )
8110 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308111 vos_mem_free(pIes);
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008112 }
8113
8114 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK );
8115 }//while
8116 csrLLUnlock(&pMac->scan.scanResultList);
Srikant Kuppa866893f2012-12-27 17:28:14 -08008117
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008118}
8119#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07008120
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008121eHalStatus csrScanCreateEntryInScanCache(tpAniSirGlobal pMac, tANI_U32 sessionId,
8122 tCsrBssid bssid, tANI_U8 channel)
8123{
8124 eHalStatus status = eHAL_STATUS_SUCCESS;
8125 tDot11fBeaconIEs *pNewIes = NULL;
8126 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
Praveen Kumar Sirisilla8bdfac42013-10-10 17:20:48 -07008127 tSirBssDescription *pNewBssDescriptor = NULL;
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008128 tANI_U32 size = 0;
8129
8130 if(NULL == pSession)
8131 {
8132 status = eHAL_STATUS_FAILURE;
8133 return status;
8134 }
8135 smsLog(pMac, LOG2, FL("csrScanCreateEntryInScanCache: Current bssid::"
8136 "0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x"),
8137 pSession->pConnectBssDesc->bssId[0],
8138 pSession->pConnectBssDesc->bssId[1],
8139 pSession->pConnectBssDesc->bssId[2],
8140 pSession->pConnectBssDesc->bssId[3],
8141 pSession->pConnectBssDesc->bssId[4],
8142 pSession->pConnectBssDesc->bssId[5]);
8143 smsLog(pMac, LOG2, FL("csrScanCreateEntryInScanCache: My bssid::"
8144 "0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x channel %d"),
8145 bssid[0],bssid[1],bssid[2],
8146 bssid[3],bssid[4],bssid[5],channel);
8147
8148 do
8149 {
8150 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
8151 pSession->pConnectBssDesc, &pNewIes)))
8152 {
8153 smsLog(pMac, LOGE, FL("%s: Failed to parse IEs"),
8154 __func__);
8155 status = eHAL_STATUS_FAILURE;
8156 break;
8157 }
8158
8159 size = pSession->pConnectBssDesc->length + sizeof(pSession->pConnectBssDesc->length);
Kiet Lam64c1b492013-07-12 13:56:44 +05308160 if (size)
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008161 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308162 pNewBssDescriptor = vos_mem_malloc(size);
8163 if ( NULL == pNewBssDescriptor )
8164 status = eHAL_STATUS_FAILURE;
8165 else
8166 status = eHAL_STATUS_SUCCESS;
8167 if (HAL_STATUS_SUCCESS(status))
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008168 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308169 vos_mem_copy(pNewBssDescriptor, pSession->pConnectBssDesc, size);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008170 }
8171 else
8172 {
8173 smsLog(pMac, LOGE, FL("%s: memory allocation failed"),
8174 __func__);
8175 status = eHAL_STATUS_FAILURE;
8176 break;
8177 }
8178
8179 //change the BSSID & channel as passed
Kiet Lam64c1b492013-07-12 13:56:44 +05308180 vos_mem_copy(pNewBssDescriptor->bssId, bssid, sizeof(tSirMacAddr));
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008181 pNewBssDescriptor->channelId = channel;
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07008182 if(NULL == csrScanAppendBssDescription( pMac, pNewBssDescriptor, pNewIes, TRUE ))
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008183 {
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07008184 smsLog(pMac, LOGE, FL("%s: csrScanAppendBssDescription failed"),
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008185 __func__);
8186 status = eHAL_STATUS_FAILURE;
8187 break;
8188 }
8189 }
8190 else
8191 {
8192 smsLog(pMac, LOGE, FL("%s: length of bss descriptor is 0"),
8193 __func__);
8194 status = eHAL_STATUS_FAILURE;
8195 break;
8196 }
8197 smsLog(pMac, LOGE, FL("%s: entry successfully added in scan cache"),
8198 __func__);
8199 }while(0);
8200
8201 if(pNewIes)
8202 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308203 vos_mem_free(pNewIes);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008204 }
8205 if(pNewBssDescriptor)
8206 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308207 vos_mem_free(pNewBssDescriptor);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008208 }
8209 return status;
8210}
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07008211
8212#ifdef FEATURE_WLAN_CCX
8213// Update the TSF with the difference in system time
8214void UpdateCCKMTSF(tANI_U32 *timeStamp0, tANI_U32 *timeStamp1, tANI_U32 *incr)
8215{
8216 tANI_U64 timeStamp64 = ((tANI_U64)*timeStamp1 << 32) | (*timeStamp0);
8217
8218 timeStamp64 = (tANI_U64)(timeStamp64 + (tANI_U64)*incr);
8219 *timeStamp0 = (tANI_U32)(timeStamp64 & 0xffffffff);
8220 *timeStamp1 = (tANI_U32)((timeStamp64 >> 32) & 0xffffffff);
8221}
8222#endif