blob: aabc532381333842c5e73e2ef2732423ed4afd6b [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.
70
71#ifdef CSR_VALIDATE_LIST
72tDblLinkList *g_pchannelPowerInfoList24 = NULL, * g_pchannelPowerInfoList5 = NULL;
Madan Mohan Koyyalamudidfd6aa82012-10-18 20:18:43 -070073tpAniSirGlobal g_pMac;
Jeff Johnson295189b2012-06-20 16:38:30 -070074#endif
75
76/* Purpose of HIDDEN_TIMER
77** When we remove hidden ssid from the profile i.e., forget the SSID via GUI that SSID shouldn't see in the profile
78** For above requirement we used timer limit, logic is explained below
79** Timer value is initialsed to current time when it receives corresponding probe response of hidden SSID (The probe request is
80** received regularly till SSID in the profile. Once it is removed from profile probe request is not sent.) when we receive probe response
81** 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
82** then we are not updating with old one
83*/
84
85#define HIDDEN_TIMER (1*60*1000)
86#define CSR_SCAN_RESULT_RSSI_WEIGHT 80 // must be less than 100, represent the persentage of new RSSI
87
88/*---------------------------------------------------------------------------
89 PER filter constant fraction: it is a %
90---------------------------------------------------------------------------*/
91#define CSR_SCAN_PER_FILTER_FRAC 100
92
93/*---------------------------------------------------------------------------
94 RSSI filter constant fraction: it is a %
95---------------------------------------------------------------------------*/
96#define CSR_SCAN_RSSI_FILTER_FRAC 100
97
98/*---------------------------------------------------------------------------
99Convert RSSI into overall score: Since RSSI is in -dBm values, and the
100overall needs to be weighted inversely (where greater value means better
101system), we convert.
102RSSI *cannot* be more than 0xFF or less than 0 for meaningful WLAN operation
103---------------------------------------------------------------------------*/
104#define CSR_SCAN_MAX_SCORE_VAL 0xFF
105#define CSR_SCAN_MIN_SCORE_VAL 0x0
106#define CSR_SCAN_HANDOFF_DELTA 10
Jeff Johnson32d95a32012-09-10 13:15:23 -0700107#define MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL 140
108#define MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL 120
Madan Mohan Koyyalamudia53c4dc2012-11-13 10:35:42 -0800109#define CSR_SCAN_OVERALL_SCORE( rssi ) \
110 (( rssi < CSR_SCAN_MAX_SCORE_VAL ) \
111 ? (CSR_SCAN_MAX_SCORE_VAL-rssi) : CSR_SCAN_MIN_SCORE_VAL)
Jeff Johnson295189b2012-06-20 16:38:30 -0700112
113
114#define CSR_SCAN_IS_OVER_BSS_LIMIT(pMac) \
115 ( (pMac)->scan.nBssLimit <= (csrLLCount(&(pMac)->scan.scanResultList)) )
116
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +0530117/* Maximum number of channels per country can be ignored */
118#define MAX_CHANNELS_IGNORE 10
119
Wilson Yange3d2b292013-10-09 00:35:43 -0700120#define MAX_COUNTRY_IGNORE 5
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +0530121
Agarwal Ashishd9d72602013-09-13 00:06:17 +0530122#define THIRTY_PERCENT(x) (x*30/100);
123
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +0530124/*struct to hold the ignored channel list based on country */
125typedef struct sCsrIgnoreChannels
126{
127 tANI_U8 countryCode[NV_FIELD_COUNTRY_CODE_SIZE];
128 tANI_U16 channelList[MAX_CHANNELS_IGNORE];
129 tANI_U16 channelCount;
130}tCsrIgnoreChannels;
131
132static tCsrIgnoreChannels countryIgnoreList[MAX_COUNTRY_IGNORE] = {
133 { {'U','A'}, { 136, 140}, 2},
134 { {'T','W'}, { 36, 40, 44, 48, 52}, 5},
Madan Mohan Koyyalamudi28dd0422013-08-12 15:06:21 +0530135 { {'I','D'}, { 165}, 1 },
Wilson Yange3d2b292013-10-09 00:35:43 -0700136 { {'A','U'}, { 120, 124, 128}, 3 },
137 { {'A','G'}, { 120, 124, 128}, 3 }
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +0530138 };
139
Jeff Johnson295189b2012-06-20 16:38:30 -0700140//*** This is temporary work around. It need to call CCM api to get to CFG later
141/// Get string parameter value
142extern tSirRetStatus wlan_cfgGetStr(tpAniSirGlobal, tANI_U16, tANI_U8*, tANI_U32*);
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +0530143
Jeff Johnson295189b2012-06-20 16:38:30 -0700144void csrScanGetResultTimerHandler(void *);
145void csrScanResultAgingTimerHandler(void *pv);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -0800146static void csrScanResultCfgAgingTimerHandler(void *pv);
Jeff Johnson295189b2012-06-20 16:38:30 -0700147void csrScanIdleScanTimerHandler(void *);
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700148static void csrSetDefaultScanTiming( tpAniSirGlobal pMac, tSirScanType scanType, tCsrScanRequest *pScanRequest);
Jeff Johnson295189b2012-06-20 16:38:30 -0700149#ifdef WLAN_AP_STA_CONCURRENCY
150static void csrStaApConcTimerHandler(void *);
151#endif
Jeff Johnsone7245742012-09-05 17:12:55 -0700152tANI_BOOLEAN csrIsSupportedChannel(tpAniSirGlobal pMac, tANI_U8 channelId);
Jeff Johnson295189b2012-06-20 16:38:30 -0700153eHalStatus csrScanChannels( tpAniSirGlobal pMac, tSmeCmd *pCommand );
154void csrSetCfgValidChannelList( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels );
155void csrSaveTxPowerToCfg( tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 cfgId );
156void csrSetCfgCountryCode( tpAniSirGlobal pMac, tANI_U8 *countryCode );
157void csrPurgeChannelPower( tpAniSirGlobal pMac, tDblLinkList *pChannelList );
158//if bgPeriod is 0, background scan is disabled. It is in millisecond units
159eHalStatus csrSetCfgBackgroundScanPeriod(tpAniSirGlobal pMac, tANI_U32 bgPeriod);
160eHalStatus csrProcessSetBGScanParam(tpAniSirGlobal pMac, tSmeCmd *pCommand);
161void csrReleaseScanCommand(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus);
162static tANI_BOOLEAN csrScanValidateScanResult( tpAniSirGlobal pMac, tANI_U8 *pChannels,
163 tANI_U8 numChn, tSirBssDescription *pBssDesc,
164 tDot11fBeaconIEs **ppIes );
165eHalStatus csrSetBGScanChannelList( tpAniSirGlobal pMac, tANI_U8 *pAdjustChannels, tANI_U8 NumAdjustChannels);
166void csrReleaseCmdSingle(tpAniSirGlobal pMac, tSmeCmd *pCommand);
167tANI_BOOLEAN csrRoamIsValidChannel( tpAniSirGlobal pMac, tANI_U8 channel );
Jeff Johnson04dd8a82012-06-29 20:41:40 -0700168void csrPruneChannelListForMode( tpAniSirGlobal pMac, tCsrChannel *pChannelList );
Jeff Johnson295189b2012-06-20 16:38:30 -0700169
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -0700170#define CSR_IS_SOCIAL_CHANNEL(channel) (((channel) == 1) || ((channel) == 6) || ((channel) == 11) )
171
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -0700172
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -0700173
Madan Mohan Koyyalamudi923c1e12012-11-30 17:53:27 -0800174static void csrReleaseScanCmdPendingList(tpAniSirGlobal pMac)
175{
176 tListElem *pEntry;
177 tSmeCmd *pCommand;
178
179 while((pEntry = csrLLRemoveHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK)) != NULL)
180 {
181 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
182 if ( eSmeCsrCommandMask & pCommand->command )
183 {
184 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_TRUE );
185 }
186 else
187 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800188 smsLog(pMac, LOGE, FL("Error: Received command : %d"),pCommand->command);
Madan Mohan Koyyalamudi923c1e12012-11-30 17:53:27 -0800189 }
190 }
191}
Jeff Johnson295189b2012-06-20 16:38:30 -0700192//pResult is invalid calling this function.
193void csrFreeScanResultEntry( tpAniSirGlobal pMac, tCsrScanResult *pResult )
194{
195 if( NULL != pResult->Result.pvIes )
196 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530197 vos_mem_free(pResult->Result.pvIes);
Jeff Johnson295189b2012-06-20 16:38:30 -0700198 }
Kiet Lam64c1b492013-07-12 13:56:44 +0530199 vos_mem_free(pResult);
Jeff Johnson295189b2012-06-20 16:38:30 -0700200}
201
202
203static eHalStatus csrLLScanPurgeResult(tpAniSirGlobal pMac, tDblLinkList *pList)
204{
205 eHalStatus status = eHAL_STATUS_SUCCESS;
206 tListElem *pEntry;
207 tCsrScanResult *pBssDesc;
208
209 csrLLLock(pList);
210
211 while((pEntry = csrLLRemoveHead(pList, LL_ACCESS_NOLOCK)) != NULL)
212 {
213 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
214 csrFreeScanResultEntry( pMac, pBssDesc );
215 }
216
217 csrLLUnlock(pList);
218
219 return (status);
220}
221
222
223int csrCheckValidateLists(void * dest, const void *src, v_SIZE_t num, int idx)
224{
225#ifdef CSR_VALIDATE_LIST
226
227 int ii = 1;
228
229 if( (NULL == g_pMac) || (!g_pMac->scan.fValidateList ) )
230 {
231 return ii;
232 }
233 if(g_pchannelPowerInfoList24)
234 {
235 //check 2.4 list
236 tListElem *pElem, *pHead;
237 int count;
238
239 count = (int)(g_pchannelPowerInfoList24->Count);
240 pHead = &g_pchannelPowerInfoList24->ListHead;
241 pElem = pHead->next;
242 if((tANI_U32)(pHead->next) > 0x00010000) //Assuming kernel address is not that low.
243 {
244 //this loop crashes if the pointer is not right
245 while(pElem->next != pHead)
246 {
247 if((tANI_U32)(pElem->next) > 0x00010000)
248 {
249 pElem = pElem->next;
250 VOS_ASSERT(count > 0);
251 count--;
252 }
253 else
254 {
255 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_FATAL,
256 " %d Detect 1 list(0x%X) error Head(0x%X) next(0x%X) Count %d, dest(0x%X) src(0x%X) numBytes(%d)",
257 idx, (unsigned int)g_pchannelPowerInfoList24, (unsigned int)pHead,
258 (unsigned int)(pHead->next), (int)g_pchannelPowerInfoList24->Count,
259 (unsigned int)dest, (unsigned int)src, (int)num);
260 VOS_ASSERT(0);
261 ii = 0;
262 break;
263 }
264 }
265 }
266 else
267 {
268 //Bad list
269 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)",
270 idx, (unsigned int)g_pchannelPowerInfoList24, (unsigned int)pHead,
271 (unsigned int)(pHead->next), (int)g_pchannelPowerInfoList24->Count,
272 (unsigned int)dest, (unsigned int)src, (int)num);
273 VOS_ASSERT(0);
274 ii = 0;
275 }
276 }
277 else
278 {
279 //list ok
280 ii = 1;
281 }
282
283
284 return ii;
285
286#else
287 return 1;
288#endif //#ifdef CSR_VALIDATE_LIST
289}
290
291
292eHalStatus csrScanOpen( tpAniSirGlobal pMac )
293{
294 eHalStatus status;
295
296 do
297 {
298 csrLLOpen(pMac->hHdd, &pMac->scan.scanResultList);
299 csrLLOpen(pMac->hHdd, &pMac->scan.tempScanResults);
300 csrLLOpen(pMac->hHdd, &pMac->scan.channelPowerInfoList24);
301 csrLLOpen(pMac->hHdd, &pMac->scan.channelPowerInfoList5G);
302#ifdef WLAN_AP_STA_CONCURRENCY
303 csrLLOpen(pMac->hHdd, &pMac->scan.scanCmdPendingList);
304#endif
305#ifdef CSR_VALIDATE_LIST
306 g_pchannelPowerInfoList5 = &pMac->scan.channelPowerInfoList5G;
307 g_pMac = pMac;
308 g_pchannelPowerInfoList24 = &pMac->scan.channelPowerInfoList24;
309#endif
310 pMac->scan.fFullScanIssued = eANI_BOOLEAN_FALSE;
311 pMac->scan.nBssLimit = CSR_MAX_BSS_SUPPORT;
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530312 status = vos_timer_init(&pMac->scan.hTimerGetResult, VOS_TIMER_TYPE_SW, csrScanGetResultTimerHandler, pMac);
313 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700314 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800315 smsLog(pMac, LOGE, FL("cannot allocate memory for getResult timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700316 break;
317 }
318#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530319 status = vos_timer_init(&pMac->scan.hTimerStaApConcTimer, VOS_TIMER_TYPE_SW, csrStaApConcTimerHandler, pMac);
320 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700321 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800322 smsLog(pMac, LOGE, FL("cannot allocate memory for hTimerStaApConcTimer timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700323 break;
324 }
325#endif
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530326 status = vos_timer_init(&pMac->scan.hTimerIdleScan, VOS_TIMER_TYPE_SW, csrScanIdleScanTimerHandler, pMac);
327 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700328 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800329 smsLog(pMac, LOGE, FL("cannot allocate memory for idleScan timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700330 break;
331 }
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530332 status = vos_timer_init(&pMac->scan.hTimerResultAging, VOS_TIMER_TYPE_SW, csrScanResultAgingTimerHandler, pMac);
333 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700334 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800335 smsLog(pMac, LOGE, FL("cannot allocate memory for ResultAging timer"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700336 break;
337 }
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530338 status = vos_timer_init(&pMac->scan.hTimerResultCfgAging, VOS_TIMER_TYPE_SW,
339 csrScanResultCfgAgingTimerHandler, pMac);
340 if (!HAL_STATUS_SUCCESS(status))
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -0800341 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800342 smsLog(pMac, LOGE, FL("cannot allocate memory for CFG ResultAging timer"));
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -0800343 break;
344 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700345 }while(0);
346
347 return (status);
348}
349
350
351eHalStatus csrScanClose( tpAniSirGlobal pMac )
352{
353#ifdef CSR_VALIDATE_LIST
354 g_pchannelPowerInfoList24 = NULL;
355 g_pchannelPowerInfoList5 = NULL;
356 g_pMac = NULL;
357#endif
358 csrLLScanPurgeResult(pMac, &pMac->scan.tempScanResults);
359 csrLLScanPurgeResult(pMac, &pMac->scan.scanResultList);
360#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudi923c1e12012-11-30 17:53:27 -0800361 csrReleaseScanCmdPendingList(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -0700362#endif
363 csrLLClose(&pMac->scan.scanResultList);
364 csrLLClose(&pMac->scan.tempScanResults);
365#ifdef WLAN_AP_STA_CONCURRENCY
366 csrLLClose(&pMac->scan.scanCmdPendingList);
367#endif
368 csrPurgeChannelPower(pMac, &pMac->scan.channelPowerInfoList24);
369 csrPurgeChannelPower(pMac, &pMac->scan.channelPowerInfoList5G);
370 csrLLClose(&pMac->scan.channelPowerInfoList24);
371 csrLLClose(&pMac->scan.channelPowerInfoList5G);
372 csrScanDisable(pMac);
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530373 vos_timer_destroy(&pMac->scan.hTimerResultAging);
374 vos_timer_destroy(&pMac->scan.hTimerResultCfgAging);
375 vos_timer_destroy(&pMac->scan.hTimerGetResult);
Jeff Johnson295189b2012-06-20 16:38:30 -0700376#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530377 vos_timer_destroy(&pMac->scan.hTimerStaApConcTimer);
Jeff Johnson295189b2012-06-20 16:38:30 -0700378#endif
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530379 vos_timer_destroy(&pMac->scan.hTimerIdleScan);
Jeff Johnson295189b2012-06-20 16:38:30 -0700380 return eHAL_STATUS_SUCCESS;
381}
382
383
384eHalStatus csrScanEnable( tpAniSirGlobal pMac )
385{
386
387 pMac->scan.fScanEnable = eANI_BOOLEAN_TRUE;
388 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
389
390 return eHAL_STATUS_SUCCESS;
391}
392
393
394eHalStatus csrScanDisable( tpAniSirGlobal pMac )
395{
396
397 csrScanStopTimers(pMac);
398 pMac->scan.fScanEnable = eANI_BOOLEAN_FALSE;
399
400 return eHAL_STATUS_SUCCESS;
401}
402
403
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700404//Set scan timing parameters according to state of other driver sessions
405//No validation of the parameters is performed.
406static void csrSetDefaultScanTiming( tpAniSirGlobal pMac, tSirScanType scanType, tCsrScanRequest *pScanRequest)
407{
408#ifdef WLAN_AP_STA_CONCURRENCY
409 if(csrIsAnySessionConnected(pMac))
410 {
411 //If multi-session, use the appropriate default scan times
412 if(scanType == eSIR_ACTIVE_SCAN)
413 {
414 pScanRequest->maxChnTime = pMac->roam.configParam.nActiveMaxChnTimeConc;
415 pScanRequest->minChnTime = pMac->roam.configParam.nActiveMinChnTimeConc;
416 }
417 else
418 {
419 pScanRequest->maxChnTime = pMac->roam.configParam.nPassiveMaxChnTimeConc;
420 pScanRequest->minChnTime = pMac->roam.configParam.nPassiveMinChnTimeConc;
421 }
Kiet Lam64c1b492013-07-12 13:56:44 +0530422 pScanRequest->maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
423 pScanRequest->minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700424
425 pScanRequest->restTime = pMac->roam.configParam.nRestTimeConc;
426
427 //Return so that fields set above will not be overwritten.
428 return;
429 }
430#endif
431
432 //This portion of the code executed if multi-session not supported
433 //(WLAN_AP_STA_CONCURRENCY not defined) or no multi-session.
434 //Use the "regular" (non-concurrency) default scan timing.
435 if(pScanRequest->scanType == eSIR_ACTIVE_SCAN)
436 {
437 pScanRequest->maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
438 pScanRequest->minChnTime = pMac->roam.configParam.nActiveMinChnTime;
439 }
440 else
441 {
442 pScanRequest->maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
443 pScanRequest->minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
444 }
Kiet Lam64c1b492013-07-12 13:56:44 +0530445 pScanRequest->maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
446 pScanRequest->minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700447
448#ifdef WLAN_AP_STA_CONCURRENCY
449 //No rest time if no sessions are connected.
450 pScanRequest->restTime = 0;
451#endif
452}
453
Jeff Johnson295189b2012-06-20 16:38:30 -0700454#ifdef WLAN_AP_STA_CONCURRENCY
455//Return SUCCESS is the command is queued, else returns eHAL_STATUS_FAILURE
456eHalStatus csrQueueScanRequest( tpAniSirGlobal pMac, tSmeCmd *pScanCmd )
457{
458 eHalStatus status = eHAL_STATUS_SUCCESS;
459
460 tANI_BOOLEAN fNoCmdPending;
461 tSmeCmd *pQueueScanCmd=NULL;
462 tSmeCmd *pSendScanCmd=NULL;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700463 tANI_U8 nNumChanCombinedConc = 0;
Gopichand Nakkala114718f2013-03-25 19:19:46 -0700464 if (NULL == pScanCmd)
465 {
466 smsLog (pMac, LOGE, FL("Scan Req cmd is NULL"));
467 return eHAL_STATUS_FAILURE;
468 }
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -0800469 /* split scan if any one of the following:
470 * - STA session is connected and the scan is not a P2P search
471 * - any P2P session is connected
Srikant Kuppa866893f2012-12-27 17:28:14 -0800472 * Do not split scans if no concurrent infra connections are
473 * active and if the scan is a BG scan triggered by LFR (OR)
474 * any scan if LFR is in the middle of a BG scan. Splitting
475 * the scan is delaying the time it takes for LFR to find
476 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -0800477 */
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700478
479 if(csrIsStaSessionConnected(pMac) &&
480 !csrIsP2pSessionConnected(pMac))
481 {
482 nNumChanCombinedConc = pMac->roam.configParam.nNumStaChanCombinedConc;
483 }
484 else if(csrIsP2pSessionConnected(pMac))
485 {
486 nNumChanCombinedConc = pMac->roam.configParam.nNumP2PChanCombinedConc;
487 }
Srikant Kuppa866893f2012-12-27 17:28:14 -0800488 if ( (csrIsStaSessionConnected(pMac) &&
489#ifdef FEATURE_WLAN_LFR
490 (csrIsConcurrentInfraConnected(pMac) ||
491 ((pScanCmd->u.scanCmd.reason != eCsrScanBgScan) &&
492 (pMac->roam.neighborRoamInfo.neighborRoamState !=
493 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
494#endif
495 (pScanCmd->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Vinay Malekal05fdc812012-12-17 13:04:30 -0800496 (csrIsP2pSessionConnected(pMac)) )
Jeff Johnson295189b2012-06-20 16:38:30 -0700497 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700498 tCsrScanRequest scanReq;
499 tANI_U8 numChn = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
500 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
501 tANI_U8 channelToScan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
Jeff Johnson295189b2012-06-20 16:38:30 -0700502 tANI_BOOLEAN bMemAlloc = eANI_BOOLEAN_FALSE;
503
504 if (numChn == 0)
505 {
506
507 numChn = pMac->scan.baseChannels.numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -0700508
Kiet Lam64c1b492013-07-12 13:56:44 +0530509 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(numChn);
510 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -0700511 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800512 smsLog( pMac, LOGE, FL(" Failed to get memory for channel list ") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800513 return eHAL_STATUS_FAILURE;
514 }
515 bMemAlloc = eANI_BOOLEAN_TRUE;
Kiet Lam64c1b492013-07-12 13:56:44 +0530516 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
517 pMac->scan.baseChannels.channelList, numChn);
518 status = eHAL_STATUS_SUCCESS;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800519 if( !HAL_STATUS_SUCCESS( status ) )
520 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530521 vos_mem_free(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800522 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800523 smsLog( pMac, LOGE, FL(" Failed to copy memory to channel list ") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800524 return eHAL_STATUS_FAILURE;
525 }
526 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = numChn;
527 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700528
Vinay Malekal05fdc812012-12-17 13:04:30 -0800529 //Whenever we get a scan request with multiple channels we break it up into 2 requests
530 //First request for first channel to scan and second request to scan remaining channels
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700531 if ( numChn > nNumChanCombinedConc)
Vinay Malekal05fdc812012-12-17 13:04:30 -0800532 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530533 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800534
535 pQueueScanCmd = csrGetCommandBuffer(pMac); //optimize this to use 2 command buffer only
536 if (!pQueueScanCmd)
537 {
538 if (bMemAlloc)
Jeff Johnson295189b2012-06-20 16:38:30 -0700539 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530540 vos_mem_free(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800541 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
542
Jeff Johnson295189b2012-06-20 16:38:30 -0700543 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800544 smsLog( pMac, LOGE, FL(" Failed to get Queue command buffer") );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800545 return eHAL_STATUS_FAILURE;
546 }
547 pQueueScanCmd->command = pScanCmd->command;
548 pQueueScanCmd->sessionId = pScanCmd->sessionId;
549 pQueueScanCmd->u.scanCmd.callback = pScanCmd->u.scanCmd.callback;
550 pQueueScanCmd->u.scanCmd.pContext = pScanCmd->u.scanCmd.pContext;
551 pQueueScanCmd->u.scanCmd.reason = pScanCmd->u.scanCmd.reason;
552 pQueueScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Jeff Johnson295189b2012-06-20 16:38:30 -0700553
Vinay Malekal05fdc812012-12-17 13:04:30 -0800554 /* First copy all the parameters to local variable of scan request */
555 csrScanCopyRequest(pMac, &scanReq, &pScanCmd->u.scanCmd.u.scanRequest);
Madan Mohan Koyyalamudiaf2a8b92012-10-09 14:58:07 -0700556
Vinay Malekal05fdc812012-12-17 13:04:30 -0800557 /* Now modify the elements of local var scan request required to be modified for split scan */
558 if(scanReq.ChannelInfo.ChannelList != NULL)
559 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530560 vos_mem_free(scanReq.ChannelInfo.ChannelList);
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -0800561 scanReq.ChannelInfo.ChannelList = NULL;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800562 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700563
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700564 pChnInfo->numOfChannels = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels - nNumChanCombinedConc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700565
Vinay Malekal05fdc812012-12-17 13:04:30 -0800566 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_WARN,
Gopichand Nakkala66c0bd02013-04-10 11:36:29 +0530567 FL(" &channelToScan %p pScanCmd(%p) pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList(%p)numChn(%d)"),
568 &channelToScan[0], pScanCmd,
569 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList, numChn);
Jeff Johnson295189b2012-06-20 16:38:30 -0700570
Kiet Lam64c1b492013-07-12 13:56:44 +0530571 vos_mem_copy(&channelToScan[0],
572 &pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[
573 nNumChanCombinedConc],
574 pChnInfo->numOfChannels * sizeof(tANI_U8));
Vinay Malekal05fdc812012-12-17 13:04:30 -0800575
576 pChnInfo->ChannelList = &channelToScan[0];
577
578 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
579 //Modify callers parameters in case of concurrency
Madan Mohan Koyyalamudi04a65f02013-07-26 13:58:38 +0530580 if (!pScanCmd->u.scanCmd.u.scanRequest.bcnRptReqScan)
581 scanReq.scanType = eSIR_ACTIVE_SCAN;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800582 //Use concurrency values for min/maxChnTime.
583 //We know csrIsAnySessionConnected(pMac) returns TRUE here
584 csrSetDefaultScanTiming(pMac, scanReq.scanType, &scanReq);
585
586 status = csrScanCopyRequest(pMac, &pQueueScanCmd->u.scanCmd.u.scanRequest, &scanReq);
587
588 if(!HAL_STATUS_SUCCESS(status))
589 {
590 if (bMemAlloc)
591 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530592 vos_mem_free(pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800593 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
594
595 }
596 if( scanReq.pIEField != NULL)
597 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530598 vos_mem_free(scanReq.pIEField);
Vinay Malekal05fdc812012-12-17 13:04:30 -0800599 scanReq.pIEField = NULL;
600 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800601 smsLog( pMac, LOGE, FL(" Failed to get copy csrScanRequest = %d"), status );
Vinay Malekal05fdc812012-12-17 13:04:30 -0800602 return eHAL_STATUS_FAILURE;
603 }
604 /* Clean the local scan variable */
605 scanReq.ChannelInfo.ChannelList = NULL;
606 scanReq.ChannelInfo.numOfChannels = 0;
607 csrScanFreeRequest(pMac, &scanReq);
608
609 /* setup the command to scan 2 channels */
610 pSendScanCmd = pScanCmd;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -0700611 pSendScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nNumChanCombinedConc;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800612 pSendScanCmd->u.scanCmd.u.scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
Madan Mohan Koyyalamudi04a65f02013-07-26 13:58:38 +0530613 if (!pSendScanCmd->u.scanCmd.u.scanRequest.bcnRptReqScan)
614 pSendScanCmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800615 //Use concurrency values for min/maxChnTime.
616 //We know csrIsAnySessionConnected(pMac) returns TRUE here
617 csrSetDefaultScanTiming(pMac, pSendScanCmd->u.scanCmd.u.scanRequest.scanType, &pSendScanCmd->u.scanCmd.u.scanRequest);
618 pSendScanCmd->u.scanCmd.callback = NULL;
619 } else {
620 pSendScanCmd = pScanCmd;
621 pSendScanCmd->u.scanCmd.u.scanRequest.BSSType = eCSR_BSS_TYPE_ANY;
Madan Mohan Koyyalamudi04a65f02013-07-26 13:58:38 +0530622 if (!pSendScanCmd->u.scanCmd.u.scanRequest.bcnRptReqScan)
623 pSendScanCmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Vinay Malekal05fdc812012-12-17 13:04:30 -0800624 //Use concurrency values for min/maxChnTime.
625 //We know csrIsAnySessionConnected(pMac) returns TRUE here
626 csrSetDefaultScanTiming(pMac, pSendScanCmd->u.scanCmd.u.scanRequest.scanType, &pSendScanCmd->u.scanCmd.u.scanRequest);
627 }
628
629 fNoCmdPending = csrLLIsListEmpty( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK );
630
631 //Logic Below is as follows
632 // If the scanCmdPendingList is empty then we directly send that command
633 // to smeCommandQueue else we buffer it in our scanCmdPendingList Queue
634 if( fNoCmdPending )
635 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700636 if (pQueueScanCmd != NULL)
637 {
Vinay Malekal05fdc812012-12-17 13:04:30 -0800638 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pQueueScanCmd->Link, LL_ACCESS_LOCK );
Jeff Johnson295189b2012-06-20 16:38:30 -0700639 }
640
641 if (pSendScanCmd != NULL)
642 {
643 return csrQueueSmeCommand(pMac, pSendScanCmd, eANI_BOOLEAN_FALSE);
644 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800645 }
646 else
647 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700648 if (pSendScanCmd != NULL)
649 {
650 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pSendScanCmd->Link, LL_ACCESS_LOCK );
651 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800652
Jeff Johnson295189b2012-06-20 16:38:30 -0700653 if (pQueueScanCmd != NULL)
654 {
655 csrLLInsertTail( &pMac->scan.scanCmdPendingList, &pQueueScanCmd->Link, LL_ACCESS_LOCK );
656 }
Vinay Malekal05fdc812012-12-17 13:04:30 -0800657 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700658 }
659 else
660 { //No concurrency case
Srikant Kuppa866893f2012-12-27 17:28:14 -0800661 smsLog( pMac, LOG2, FL("Queuing scan command (reason=%d, roamState=%d"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800662 " numOfChannels=%d)"),
Srikant Kuppa866893f2012-12-27 17:28:14 -0800663 pScanCmd->u.scanCmd.reason,
664 pMac->roam.neighborRoamInfo.neighborRoamState,
665 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -0700666 return csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
667 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700668
669 return ( status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700670}
671#endif
672
Jeff Johnsone7245742012-09-05 17:12:55 -0700673/* ---------------------------------------------------------------------------
674 \fn csrScan2GOnyRequest
675 \brief This function will update the scan request with only
Jeff Johnsonb88db982012-12-10 13:34:59 -0800676 2.4GHz valid channel list.
Jeff Johnsone7245742012-09-05 17:12:55 -0700677 \param pMac
678 \param pScanCmd
679 \param pScanRequest
680 \return None
681 -------------------------------------------------------------------------------*/
682static void csrScan2GOnyRequest(tpAniSirGlobal pMac,tSmeCmd *pScanCmd,
683 tCsrScanRequest *pScanRequest)
684{
685 tANI_U8 index, channelId, channelListSize = 0;
686 tANI_U8 channelList2G[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
687 static tANI_U8 validchannelList[CSR_MAX_2_4_GHZ_SUPPORTED_CHANNELS] = {0};
688
689 VOS_ASSERT(pScanCmd && pScanRequest);
Madan Mohan Koyyalamudi33ef6a22012-10-30 17:44:43 -0700690 /* To silence the KW tool null check is added */
691 if((pScanCmd == NULL) || (pScanRequest == NULL))
692 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800693 smsLog( pMac, LOGE, FL(" pScanCmd or pScanRequest is NULL "));
Madan Mohan Koyyalamudi33ef6a22012-10-30 17:44:43 -0700694 return;
695 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700696
697 if (pScanCmd->u.scanCmd.scanID ||
698 (eCSR_SCAN_REQUEST_FULL_SCAN != pScanRequest->requestType))
699 return;
700
701 //Contsruct valid Supported 2.4 GHz Channel List
702 for( index = 0; index < ARRAY_SIZE(channelList2G); index++ )
703 {
704 channelId = channelList2G[index];
705 if ( csrIsSupportedChannel( pMac, channelId ) )
706 {
707 validchannelList[channelListSize++] = channelId;
708 }
709 }
710
711 pScanRequest->ChannelInfo.numOfChannels = channelListSize;
712 pScanRequest->ChannelInfo.ChannelList = validchannelList;
713}
714
Jeff Johnson295189b2012-06-20 16:38:30 -0700715eHalStatus csrScanRequest(tpAniSirGlobal pMac, tANI_U16 sessionId,
716 tCsrScanRequest *pScanRequest, tANI_U32 *pScanRequestID,
717 csrScanCompleteCallback callback, void *pContext)
718{
719 eHalStatus status = eHAL_STATUS_FAILURE;
720 tSmeCmd *pScanCmd = NULL;
Madan Mohan Koyyalamudicb90bb22012-10-30 18:24:43 -0700721 eCsrConnectState ConnectState;
Jeff Johnson295189b2012-06-20 16:38:30 -0700722
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800723 if(pScanRequest == NULL)
724 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800725 smsLog( pMac, LOGE, FL(" pScanRequest is NULL"));
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800726 VOS_ASSERT(0);
727 }
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700728
Jeff Johnson295189b2012-06-20 16:38:30 -0700729 do
730 {
731 if(pMac->scan.fScanEnable)
732 {
733 pScanCmd = csrGetCommandBuffer(pMac);
734 if(pScanCmd)
735 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530736 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -0700737 pScanCmd->command = eSmeCommandScan;
738 pScanCmd->sessionId = sessionId;
739 pScanCmd->u.scanCmd.callback = callback;
740 pScanCmd->u.scanCmd.pContext = pContext;
741 if(eCSR_SCAN_REQUEST_11D_SCAN == pScanRequest->requestType)
742 {
743 pScanCmd->u.scanCmd.reason = eCsrScan11d1;
744 }
745 else if((eCSR_SCAN_REQUEST_FULL_SCAN == pScanRequest->requestType) ||
746 (eCSR_SCAN_P2P_DISCOVERY == pScanRequest->requestType)
747#ifdef SOFTAP_CHANNEL_RANGE
748 ||(eCSR_SCAN_SOFTAP_CHANNEL_RANGE == pScanRequest->requestType)
749#endif
750 )
751 {
752 pScanCmd->u.scanCmd.reason = eCsrScanUserRequest;
753 }
754 else if(eCSR_SCAN_HO_BG_SCAN == pScanRequest->requestType)
755 {
756 pScanCmd->u.scanCmd.reason = eCsrScanBgScan;
757 }
758 else if(eCSR_SCAN_HO_PROBE_SCAN == pScanRequest->requestType)
759 {
760 pScanCmd->u.scanCmd.reason = eCsrScanProbeBss;
761 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700762 else if(eCSR_SCAN_P2P_FIND_PEER == pScanRequest->requestType)
763 {
764 pScanCmd->u.scanCmd.reason = eCsrScanP2PFindPeer;
765 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700766 else
767 {
768 pScanCmd->u.scanCmd.reason = eCsrScanIdleScan;
769 }
770 if(pScanRequest->minChnTime == 0 && pScanRequest->maxChnTime == 0)
771 {
772 //The caller doesn't set the time correctly. Set it here
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700773 csrSetDefaultScanTiming(pMac, pScanRequest->scanType, pScanRequest);
774 }
775#ifdef WLAN_AP_STA_CONCURRENCY
776 if(pScanRequest->restTime == 0)
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800777 {
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700778 //Need to set restTime only if at least one session is connected
779 if(csrIsAnySessionConnected(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -0700780 {
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700781 pScanRequest->restTime = pMac->roam.configParam.nRestTimeConc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700782 }
783 }
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -0700784#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -0700785 /*For Standalone wlan : channel time will remain the same.
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +0530786 For BTC with A2DP up: Channel time = Channel time * 2, if station is not already associated.
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800787 This has been done to provide a larger scan window for faster connection during btc.Else Scan is seen
788 to take a long time.
789 For BTC with A2DP up: Channel time will not be doubled, if station is already associated.
790 */
Jeff Johnson32d95a32012-09-10 13:15:23 -0700791 status = csrRoamGetConnectState(pMac,sessionId,&ConnectState);
Srinivas Girigowdac84c57c2013-02-19 17:41:56 -0800792 if (HAL_STATUS_SUCCESS(status) &&
793 pMac->btc.fA2DPUp &&
Jeff Johnson32d95a32012-09-10 13:15:23 -0700794 (eCSR_ASSOC_STATE_TYPE_INFRA_ASSOCIATED != ConnectState) &&
795 (eCSR_ASSOC_STATE_TYPE_IBSS_CONNECTED != ConnectState))
796 {
797 pScanRequest->maxChnTime = pScanRequest->maxChnTime << 1;
798 pScanRequest->minChnTime = pScanRequest->minChnTime << 1;
799 }
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800800
Kiet Lam64c1b492013-07-12 13:56:44 +0530801 pScanRequest->maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
802 pScanRequest->minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700803 //Need to make the following atomic
804 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
805
806 if(pScanRequestID)
807 {
808 *pScanRequestID = pScanCmd->u.scanCmd.scanID;
809 }
810
Gopichand Nakkala9b89a732012-12-31 16:31:46 -0800811 // If it is the first scan request from HDD, CSR checks if it is for 11d.
Jeff Johnson295189b2012-06-20 16:38:30 -0700812 // If it is not, CSR will save the scan request in the pending cmd queue
813 // & issue an 11d scan request to PE.
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800814 if (((0 == pScanCmd->u.scanCmd.scanID)
Jeff Johnson295189b2012-06-20 16:38:30 -0700815 && (eCSR_SCAN_REQUEST_11D_SCAN != pScanRequest->requestType))
816#ifdef SOFTAP_CHANNEL_RANGE
817 && (eCSR_SCAN_SOFTAP_CHANNEL_RANGE != pScanRequest->requestType)
818#endif
819 && (eANI_BOOLEAN_FALSE == pMac->scan.fEnableBypass11d)
820 )
821 {
822 tSmeCmd *p11dScanCmd;
823 tCsrScanRequest scanReq;
824 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
825
Kiet Lam64c1b492013-07-12 13:56:44 +0530826 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -0700827
828 p11dScanCmd = csrGetCommandBuffer(pMac);
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800829 if (p11dScanCmd)
Jeff Johnson295189b2012-06-20 16:38:30 -0700830 {
831 tANI_U32 numChn = pMac->scan.baseChannels.numChannels;
832
Kiet Lam64c1b492013-07-12 13:56:44 +0530833 vos_mem_set(&p11dScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
834 pChnInfo->ChannelList = vos_mem_malloc(numChn);
835 if ( NULL == pChnInfo->ChannelList )
836 return eHAL_STATUS_FAILURE;
837 vos_mem_copy(pChnInfo->ChannelList,
838 pMac->scan.baseChannels.channelList, numChn);
839 status = eHAL_STATUS_SUCCESS;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800840 if ( !HAL_STATUS_SUCCESS( status ) )
Jeff Johnson295189b2012-06-20 16:38:30 -0700841 {
Kiet Lam64c1b492013-07-12 13:56:44 +0530842 vos_mem_free(pChnInfo->ChannelList);
Jeff Johnson295189b2012-06-20 16:38:30 -0700843 pChnInfo->ChannelList = NULL;
844 break;
845 }
846 pChnInfo->numOfChannels = (tANI_U8)numChn;
847 p11dScanCmd->command = eSmeCommandScan;
848 p11dScanCmd->u.scanCmd.callback = NULL;
849 p11dScanCmd->u.scanCmd.pContext = NULL;
850 p11dScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++;
851 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
852
853 if ( csrIs11dSupported(pMac) )
854 {
Madan Mohan Koyyalamudi04a65f02013-07-26 13:58:38 +0530855 scanReq.bcnRptReqScan = pScanRequest->bcnRptReqScan;
856 if (pScanRequest->bcnRptReqScan)
857 scanReq.scanType = pScanRequest->scanType ?
858 eSIR_PASSIVE_SCAN :
859 pScanRequest->scanType;
860 else
861 scanReq.scanType = eSIR_PASSIVE_SCAN;
Jeff Johnson295189b2012-06-20 16:38:30 -0700862 scanReq.requestType = eCSR_SCAN_REQUEST_11D_SCAN;
863 p11dScanCmd->u.scanCmd.reason = eCsrScan11d1;
864 scanReq.maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
865 scanReq.minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
866 }
867 else
868 {
Madan Mohan Koyyalamudi04a65f02013-07-26 13:58:38 +0530869 scanReq.bcnRptReqScan = pScanRequest->bcnRptReqScan;
870 if (pScanRequest->bcnRptReqScan)
871 scanReq.scanType = pScanRequest->scanType;
872 else
873 scanReq.scanType = eSIR_ACTIVE_SCAN;
Jeff Johnson295189b2012-06-20 16:38:30 -0700874 scanReq.requestType = eCSR_SCAN_IDLE_MODE_SCAN;
875 p11dScanCmd->u.scanCmd.reason = eCsrScanIdleScan;
876 scanReq.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
877 scanReq.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800878
Madan Mohan Koyyalamudi04a65f02013-07-26 13:58:38 +0530879 scanReq.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
880 scanReq.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -0700881 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700882
Jeff Johnson295189b2012-06-20 16:38:30 -0700883 status = csrScanCopyRequest(pMac, &p11dScanCmd->u.scanCmd.u.scanRequest, &scanReq);
884 //Free the channel list
Kiet Lam64c1b492013-07-12 13:56:44 +0530885 vos_mem_free(pChnInfo->ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -0700886 pChnInfo->ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -0700887
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -0800888 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -0700889 {
890 //Start process the command
891#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +0530892 if (!pMac->fScanOffload)
893 status = csrQueueScanRequest(pMac, p11dScanCmd);
894 else
895 status = csrQueueSmeCommand(pMac, p11dScanCmd,
896 eANI_BOOLEAN_FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -0700897#else
898 status = csrQueueSmeCommand(pMac, p11dScanCmd, eANI_BOOLEAN_FALSE);
899#endif
900 if( !HAL_STATUS_SUCCESS( status ) )
901 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800902 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700903 break;
904 }
905 }
906 else
907 {
908 break;
909 }
910 }
911 else
912 {
913 //error
914 break;
915 }
916 }
Jeff Johnsone7245742012-09-05 17:12:55 -0700917
918 //Scan only 2G Channels if set in ini file
919 //This is mainly to reduce the First Scan duration
920 //Once we turn on Wifi
921 if(pMac->scan.fFirstScanOnly2GChnl)
922 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800923 smsLog( pMac, LOG1, FL("Scanning only 2G Channels during first scan"));
Jeff Johnsone7245742012-09-05 17:12:55 -0700924 csrScan2GOnyRequest(pMac, pScanCmd, pScanRequest);
925 }
926
Jeff Johnson295189b2012-06-20 16:38:30 -0700927 status = csrScanCopyRequest(pMac, &pScanCmd->u.scanCmd.u.scanRequest, pScanRequest);
928 if(HAL_STATUS_SUCCESS(status))
929 {
930 //Start process the command
931#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +0530932 if (!pMac->fScanOffload)
933 status = csrQueueScanRequest(pMac,pScanCmd);
934 else
935 status = csrQueueSmeCommand(pMac, pScanCmd,
936 eANI_BOOLEAN_FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -0700937#else
938 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
939#endif
940 if( !HAL_STATUS_SUCCESS( status ) )
941 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800942 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700943 break;
944 }
945 }
946 else
947 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800948 smsLog( pMac, LOGE, FL(" fail to copy request status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700949 break;
950 }
951 }
952 else
953 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800954 smsLog( pMac, LOGE, FL(" pScanCmd is NULL"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700955 break;
956 }
957 }
958 } while(0);
959 if(!HAL_STATUS_SUCCESS(status) && pScanCmd)
960 {
961 if( eCsrScanIdleScan == pScanCmd->u.scanCmd.reason )
962 {
963 //Set the flag back for restarting idle scan
964 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
965 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800966 smsLog( pMac, LOGE, FL(" failed with status = %d, releasing scan cmd"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700967 csrReleaseCommandScan(pMac, pScanCmd);
968 }
969
970 return (status);
971}
972
973
974eHalStatus csrScanRequestResult(tpAniSirGlobal pMac)
975{
976 eHalStatus status = eHAL_STATUS_SUCCESS;
977 tSmeCmd *pScanCmd;
978
979 if(pMac->scan.fScanEnable)
980 {
981 pScanCmd = csrGetCommandBuffer(pMac);
982 if(pScanCmd)
983 {
984 pScanCmd->command = eSmeCommandScan;
Kiet Lam64c1b492013-07-12 13:56:44 +0530985 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -0700986 pScanCmd->u.scanCmd.callback = NULL;
987 pScanCmd->u.scanCmd.pContext = NULL;
988 pScanCmd->u.scanCmd.reason = eCsrScanGetResult;
989 //Need to make the following atomic
Madan Mohan Koyyalamudi2a1ba772012-10-11 14:59:06 -0700990 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID; //let it wrap around
Jeff Johnson295189b2012-06-20 16:38:30 -0700991 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
992 if( !HAL_STATUS_SUCCESS( status ) )
993 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -0800994 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -0700995 csrReleaseCommandScan(pMac, pScanCmd);
996 }
997 }
998 else
999 {
1000 //log error
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001001 smsLog(pMac, LOGE, FL("can not obtain a common buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001002 status = eHAL_STATUS_RESOURCES;
1003 }
1004 }
1005
1006 return (status);
1007}
1008
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07001009#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
1010eHalStatus csrScanRequestLfrResult(tpAniSirGlobal pMac, tANI_U32 sessionId,
1011 csrScanCompleteCallback callback, void *pContext)
1012{
1013 eHalStatus status = eHAL_STATUS_SUCCESS;
1014 tSmeCmd *pScanCmd;
1015
1016 if (pMac->scan.fScanEnable)
1017 {
1018 pScanCmd = csrGetCommandBuffer(pMac);
1019 if (pScanCmd)
1020 {
1021 pScanCmd->command = eSmeCommandScan;
1022 pScanCmd->sessionId = sessionId;
Kiet Lam64c1b492013-07-12 13:56:44 +05301023 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07001024 pScanCmd->u.scanCmd.callback = callback;
1025 pScanCmd->u.scanCmd.pContext = pContext;
1026 pScanCmd->u.scanCmd.reason = eCsrScanGetLfrResult;
1027 //Need to make the following atomic
1028 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID; //let it wrap around
1029 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_TRUE);
1030 if ( !HAL_STATUS_SUCCESS( status ) )
1031 {
1032 smsLog( pMac, LOGE, FL(" fail to send message status = %d\n"), status );
1033 csrReleaseCommandScan(pMac, pScanCmd);
1034 }
1035 }
1036 else
1037 {
1038 //log error
1039 smsLog(pMac, LOGE, FL("can not obtain a common buffer\n"));
1040 status = eHAL_STATUS_RESOURCES;
1041 }
1042 }
1043
1044 return (status);
1045}
1046#endif //WLAN_FEATURE_ROAM_SCAN_OFFLOAD
Jeff Johnson295189b2012-06-20 16:38:30 -07001047
1048eHalStatus csrScanAllChannels(tpAniSirGlobal pMac, eCsrRequestType reqType)
1049{
1050 eHalStatus status = eHAL_STATUS_SUCCESS;
1051 tANI_U32 scanId;
1052 tCsrScanRequest scanReq;
1053
Kiet Lam64c1b492013-07-12 13:56:44 +05301054 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001055 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
1056 scanReq.scanType = eSIR_ACTIVE_SCAN;
1057 scanReq.requestType = reqType;
1058 scanReq.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1059 scanReq.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001060 scanReq.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1061 scanReq.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001062 //Scan with invalid sessionId.
1063 //This results in SME using the first available session to scan.
1064 status = csrScanRequest(pMac, CSR_SESSION_ID_INVALID, &scanReq,
1065 &scanId, NULL, NULL);
1066
1067 return (status);
1068}
1069
1070
1071
1072
1073eHalStatus csrIssueRoamAfterLostlinkScan(tpAniSirGlobal pMac, tANI_U32 sessionId, eCsrRoamReason reason)
1074{
1075 eHalStatus status = eHAL_STATUS_FAILURE;
1076 tScanResultHandle hBSSList = NULL;
1077 tCsrScanResultFilter *pScanFilter = NULL;
1078 tANI_U32 roamId = 0;
1079 tCsrRoamProfile *pProfile = NULL;
1080 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1081
Jeff Johnson32d95a32012-09-10 13:15:23 -07001082 if(!pSession)
1083 {
1084 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1085 return eHAL_STATUS_FAILURE;
1086 }
1087
Jeff Johnson295189b2012-06-20 16:38:30 -07001088 do
1089 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001090 smsLog(pMac, LOG1, " csrIssueRoamAfterLostlinkScan called");
Jeff Johnson295189b2012-06-20 16:38:30 -07001091 if(pSession->fCancelRoaming)
1092 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001093 smsLog(pMac, LOGW, " lostlink roaming is cancelled");
Jeff Johnson295189b2012-06-20 16:38:30 -07001094 csrScanStartIdleScan(pMac);
1095 status = eHAL_STATUS_SUCCESS;
1096 break;
1097 }
1098 //Here is the profile we need to connect to
Kiet Lam64c1b492013-07-12 13:56:44 +05301099 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1100 if ( NULL == pScanFilter)
1101 status = eHAL_STATUS_FAILURE;
1102 else
1103 status = eHAL_STATUS_SUCCESS;
1104 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001105 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301106 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001107 if(NULL == pSession->pCurRoamProfile)
1108 {
1109 pScanFilter->EncryptionType.numEntries = 1;
1110 pScanFilter->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_NONE;
1111 }
1112 else
1113 {
1114 //We have to make a copy of pCurRoamProfile because it will be free inside csrRoamIssueConnect
Kiet Lam64c1b492013-07-12 13:56:44 +05301115 pProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1116 if ( NULL == pProfile )
1117 status = eHAL_STATUS_FAILURE;
1118 else
1119 status = eHAL_STATUS_SUCCESS;
1120 if (!HAL_STATUS_SUCCESS(status))
1121 break;
1122 vos_mem_set(pProfile, sizeof(tCsrRoamProfile), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001123 status = csrRoamCopyProfile(pMac, pProfile, pSession->pCurRoamProfile);
1124 if(!HAL_STATUS_SUCCESS(status))
1125 break;
1126 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1127 }//We have a profile
1128 roamId = GET_NEXT_ROAM_ID(&pMac->roam);
1129 if(HAL_STATUS_SUCCESS(status))
1130 {
1131 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1132 if(HAL_STATUS_SUCCESS(status))
1133 {
1134 if(eCsrLostLink1 == reason)
1135 {
1136 //we want to put the last connected BSS to the very beginning, if possible
1137 csrMoveBssToHeadFromBSSID(pMac, &pSession->connectedProfile.bssid, hBSSList);
1138 }
1139 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList, reason,
1140 roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1141 if(!HAL_STATUS_SUCCESS(status))
1142 {
1143 csrScanResultPurge(pMac, hBSSList);
1144 }
1145 }//Have scan result
1146 }
1147 }while(0);
1148 if(pScanFilter)
1149 {
1150 //we need to free memory for filter if profile exists
1151 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301152 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001153 }
1154 if(NULL != pProfile)
1155 {
1156 csrReleaseProfile(pMac, pProfile);
Kiet Lam64c1b492013-07-12 13:56:44 +05301157 vos_mem_free(pProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07001158 }
1159
1160 return (status);
1161}
1162
1163
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05301164eHalStatus csrScanGetScanChnInfo(tpAniSirGlobal pMac, tANI_U8 sessionId,
1165 void *pContext, void *callback)
Jeff Johnson295189b2012-06-20 16:38:30 -07001166{
1167 eHalStatus status = eHAL_STATUS_SUCCESS;
1168 tSmeCmd *pScanCmd;
1169
1170 if(pMac->scan.fScanEnable)
1171 {
1172 pScanCmd = csrGetCommandBuffer(pMac);
1173 if(pScanCmd)
1174 {
1175 pScanCmd->command = eSmeCommandScan;
Kiet Lam64c1b492013-07-12 13:56:44 +05301176 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson32d95a32012-09-10 13:15:23 -07001177 pScanCmd->u.scanCmd.callback = callback;
1178 pScanCmd->u.scanCmd.pContext = pContext;
Jeff Johnson295189b2012-06-20 16:38:30 -07001179 pScanCmd->u.scanCmd.reason = eCsrScanGetScanChnInfo;
1180 //Need to make the following atomic
1181 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05301182 pScanCmd->sessionId = sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07001183 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
1184 if( !HAL_STATUS_SUCCESS( status ) )
1185 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001186 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001187 csrReleaseCommandScan(pMac, pScanCmd);
1188 }
1189 }
1190 else
1191 {
1192 //log error
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001193 smsLog(pMac, LOGE, FL("can not obtain a common buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001194 status = eHAL_STATUS_RESOURCES;
1195 }
1196 }
1197
1198 return (status);
1199}
1200
1201
1202eHalStatus csrScanHandleFailedLostlink1(tpAniSirGlobal pMac, tANI_U32 sessionId)
1203{
1204 eHalStatus status = eHAL_STATUS_FAILURE;
1205 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1206
Jeff Johnson32d95a32012-09-10 13:15:23 -07001207 if(!pSession)
1208 {
1209 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1210 return eHAL_STATUS_FAILURE;
1211 }
1212
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001213 smsLog(pMac, LOGW, " Lostlink scan 1 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001214 if(pSession->fCancelRoaming)
1215 {
1216 csrScanStartIdleScan(pMac);
1217 }
1218 else if(pSession->pCurRoamProfile)
1219 {
1220 //We fail lostlink1 but there may be other BSS in the cached result fit the profile. Give it a try first
1221 if(pSession->pCurRoamProfile->SSIDs.numOfSSIDs == 0 ||
1222 pSession->pCurRoamProfile->SSIDs.numOfSSIDs > 1)
1223 {
1224 //try lostlink scan2
1225 status = csrScanRequestLostLink2(pMac, sessionId);
1226 }
1227 else if(!pSession->pCurRoamProfile->ChannelInfo.ChannelList ||
1228 pSession->pCurRoamProfile->ChannelInfo.ChannelList[0] == 0)
1229 {
1230 //go straight to lostlink scan3
1231 status = csrScanRequestLostLink3(pMac, sessionId);
1232 }
1233 else
1234 {
1235 //we are done with lostlink
1236 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1237 {
1238 csrScanStartIdleScan(pMac);
1239 }
1240 status = eHAL_STATUS_SUCCESS;
1241 }
1242 }
1243 else
1244 {
1245 status = csrScanRequestLostLink3(pMac, sessionId);
1246 }
1247
1248 return (status);
1249}
1250
1251
1252
1253eHalStatus csrScanHandleFailedLostlink2(tpAniSirGlobal pMac, tANI_U32 sessionId)
1254{
1255 eHalStatus status = eHAL_STATUS_FAILURE;
1256 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1257
Jeff Johnson32d95a32012-09-10 13:15:23 -07001258 if(!pSession)
1259 {
1260 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1261 return eHAL_STATUS_FAILURE;
1262 }
1263
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001264 smsLog(pMac, LOGW, " Lostlink scan 2 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001265 if(pSession->fCancelRoaming)
1266 {
1267 csrScanStartIdleScan(pMac);
1268 }
1269 else if(!pSession->pCurRoamProfile || !pSession->pCurRoamProfile->ChannelInfo.ChannelList ||
1270 pSession->pCurRoamProfile->ChannelInfo.ChannelList[0] == 0)
1271 {
1272 //try lostlink scan3
1273 status = csrScanRequestLostLink3(pMac, sessionId);
1274 }
1275 else
1276 {
1277 //we are done with lostlink
1278 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1279 {
1280 csrScanStartIdleScan(pMac);
1281 }
1282 }
1283
1284 return (status);
1285}
1286
1287
1288
1289eHalStatus csrScanHandleFailedLostlink3(tpAniSirGlobal pMac, tANI_U32 sessionId)
1290{
1291 eHalStatus status = eHAL_STATUS_SUCCESS;
1292
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001293 smsLog(pMac, LOGW, " Lostlink scan 3 failed");
Jeff Johnson295189b2012-06-20 16:38:30 -07001294 if(eANI_BOOLEAN_TRUE == csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1295 {
1296 //we are done with lostlink
1297 csrScanStartIdleScan(pMac);
1298 }
1299
1300 return (status);
1301}
1302
1303
1304
1305
1306//Lostlink1 scan is to actively scan the last connected profile's SSID on all matched BSS channels.
1307//If no roam profile (it should not), it is like lostlinkscan3
1308eHalStatus csrScanRequestLostLink1( tpAniSirGlobal pMac, tANI_U32 sessionId )
1309{
1310 eHalStatus status = eHAL_STATUS_SUCCESS;
1311 tSmeCmd *pCommand = NULL;
1312 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1313 tCsrScanResultFilter *pScanFilter = NULL;
1314 tScanResultHandle hBSSList = NULL;
1315 tCsrScanResultInfo *pScanResult = NULL;
1316 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1317
Jeff Johnson32d95a32012-09-10 13:15:23 -07001318 if(!pSession)
1319 {
1320 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1321 return eHAL_STATUS_FAILURE;
1322 }
1323
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001324 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001325 do
1326 {
1327 pCommand = csrGetCommandBuffer(pMac);
1328 if(!pCommand)
1329 {
1330 status = eHAL_STATUS_RESOURCES;
1331 break;
1332 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301333 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001334 pCommand->command = eSmeCommandScan;
1335 pCommand->sessionId = (tANI_U8)sessionId;
1336 pCommand->u.scanCmd.reason = eCsrScanLostLink1;
1337 pCommand->u.scanCmd.callback = NULL;
1338 pCommand->u.scanCmd.pContext = NULL;
1339 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1340 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001341 pCommand->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1342 pCommand->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001343 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
1344 if(pSession->connectedProfile.SSID.length)
1345 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301346 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList = vos_mem_malloc(sizeof(tCsrSSIDInfo));
1347 if ( NULL == pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList )
1348 status = eHAL_STATUS_FAILURE;
1349 else
1350 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001351 if(!HAL_STATUS_SUCCESS(status))
1352 {
1353 break;
1354 }
1355 pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 1;
Kiet Lam64c1b492013-07-12 13:56:44 +05301356 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID,
1357 &pSession->connectedProfile.SSID, sizeof(tSirMacSSid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001358 }
1359 else
1360 {
1361 pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 0;
1362 }
1363 if(pSession->pCurRoamProfile)
1364 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301365 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1366 if ( NULL == pScanFilter )
1367 status = eHAL_STATUS_FAILURE;
1368 else
1369 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001370 if(!HAL_STATUS_SUCCESS(status))
1371 {
1372 break;
1373 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301374 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001375 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
1376 if(!HAL_STATUS_SUCCESS(status))
1377 {
1378 break;
1379 }
1380 //Don't change variable status here because whether we can get result or not, the command goes to PE.
1381 //The status is also used to indicate whether the command is queued. Not success meaning not queue
1382 if(HAL_STATUS_SUCCESS((csrScanGetResult(pMac, pScanFilter, &hBSSList))) && hBSSList)
1383 {
1384 tANI_U8 i, nChn = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05301385 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList =
1386 vos_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
1387 if ( NULL == pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
1388 status = eHAL_STATUS_FAILURE;
1389 else
1390 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001391 if(!HAL_STATUS_SUCCESS(status))
1392 {
1393 break;
1394 }
1395 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) &&
1396 nChn < WNI_CFG_VALID_CHANNEL_LIST_LEN)
1397 {
1398 for(i = 0; i < nChn; i++)
1399 {
1400 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1401 pScanResult->BssDescriptor.channelId)
1402 {
1403 break;
1404 }
1405 }
1406 if(i == nChn)
1407 {
1408 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pScanResult->BssDescriptor.channelId;
1409 }
1410 }
1411 //Include the last connected BSS' channel
1412 if(csrRoamIsChannelValid(pMac, pSession->connectedProfile.operationChannel))
1413 {
1414 for(i = 0; i < nChn; i++)
1415 {
1416 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1417 pSession->connectedProfile.operationChannel)
1418 {
1419 break;
1420 }
1421 }
1422 if(i == nChn)
1423 {
1424 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pSession->connectedProfile.operationChannel;
1425 }
1426 }
1427 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nChn;
1428 }
1429 else
1430 {
1431 if(csrRoamIsChannelValid(pMac, pSession->connectedProfile.operationChannel))
1432 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301433 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(1);
1434 if ( NULL == pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
1435 status = eHAL_STATUS_FAILURE;
1436 else
1437 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001438 //just try the last connected channel
1439 if(HAL_STATUS_SUCCESS(status))
1440 {
1441 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[0] = pSession->connectedProfile.operationChannel;
1442 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 1;
1443 }
1444 else
1445 {
1446 break;
1447 }
1448 }
1449 }
1450 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301451 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001452 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
1453 if( !HAL_STATUS_SUCCESS( status ) )
1454 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001455 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001456 break;
1457 }
1458 } while( 0 );
1459
1460 if(!HAL_STATUS_SUCCESS(status))
1461 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001462 smsLog(pMac, LOGW, " csrScanRequestLostLink1 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001463 if(pCommand)
1464 {
1465 csrReleaseCommandScan(pMac, pCommand);
1466 }
1467 status = csrScanHandleFailedLostlink1( pMac, sessionId );
1468 }
1469 if(pScanFilter)
1470 {
1471 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301472 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001473 }
1474 if(hBSSList)
1475 {
1476 csrScanResultPurge(pMac, hBSSList);
1477 }
1478
1479 return( status );
1480}
1481
1482
1483//Lostlink2 scan is to actively scan the all SSIDs of the last roaming profile's on all matched BSS channels.
1484//Since MAC doesn't support multiple SSID, we scan all SSIDs and filter them afterwards
1485eHalStatus csrScanRequestLostLink2( tpAniSirGlobal pMac, tANI_U32 sessionId )
1486{
1487 eHalStatus status = eHAL_STATUS_SUCCESS;
1488 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1489 tCsrScanResultFilter *pScanFilter = NULL;
1490 tScanResultHandle hBSSList = NULL;
1491 tCsrScanResultInfo *pScanResult = NULL;
1492 tSmeCmd *pCommand = NULL;
1493 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1494
Jeff Johnson32d95a32012-09-10 13:15:23 -07001495 if(!pSession)
1496 {
1497 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1498 return eHAL_STATUS_FAILURE;
1499 }
1500
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001501 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001502 do
1503 {
1504 pCommand = csrGetCommandBuffer(pMac);
1505 if(!pCommand)
1506 {
1507 status = eHAL_STATUS_RESOURCES;
1508 break;
1509 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301510 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001511 pCommand->command = eSmeCommandScan;
1512 pCommand->sessionId = (tANI_U8)sessionId;
1513 pCommand->u.scanCmd.reason = eCsrScanLostLink2;
1514 pCommand->u.scanCmd.callback = NULL;
1515 pCommand->u.scanCmd.pContext = NULL;
1516 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1517 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001518 pCommand->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1519 pCommand->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001520 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
1521 if(pSession->pCurRoamProfile)
1522 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301523 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1524 if ( NULL == pScanFilter )
1525 status = eHAL_STATUS_FAILURE;
1526 else
1527 status = eHAL_STATUS_SUCCESS;
1528 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001529 {
1530 break;
1531 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301532 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001533 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
1534 if(!HAL_STATUS_SUCCESS(status))
1535 {
1536 break;
1537 }
1538 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1539 if(!HAL_STATUS_SUCCESS(status))
1540 {
1541 break;
1542 }
1543 if(hBSSList)
1544 {
1545 tANI_U8 i, nChn = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05301546 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList =
1547 vos_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
1548 if ( NULL == pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
1549 status = eHAL_STATUS_FAILURE;
1550 else
1551 status = eHAL_STATUS_SUCCESS;
1552 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001553 {
1554 break;
1555 }
1556 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) &&
1557 nChn < WNI_CFG_VALID_CHANNEL_LIST_LEN)
1558 {
1559 for(i = 0; i < nChn; i++)
1560 {
1561 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] ==
1562 pScanResult->BssDescriptor.channelId)
1563 {
1564 break;
1565 }
1566 }
1567 if(i == nChn)
1568 {
1569 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[nChn++] = pScanResult->BssDescriptor.channelId;
1570 }
1571 }
1572 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = nChn;
1573 }
1574 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301575 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001576 //Put to the head in pending queue
1577 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_TRUE);
1578 if( !HAL_STATUS_SUCCESS( status ) )
1579 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001580 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001581 break;
1582 }
1583 } while( 0 );
1584
1585 if(!HAL_STATUS_SUCCESS(status))
1586 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001587 smsLog(pMac, LOGW, " csrScanRequestLostLink2 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001588 if(pCommand)
1589 {
1590 csrReleaseCommandScan(pMac, pCommand);
1591 }
1592 status = csrScanHandleFailedLostlink2( pMac, sessionId );
1593 }
1594 if(pScanFilter)
1595 {
1596 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301597 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001598 }
1599 if(hBSSList)
1600 {
1601 csrScanResultPurge(pMac, hBSSList);
1602 }
1603
1604 return( status );
1605}
1606
1607
1608//To actively scan all valid channels
1609eHalStatus csrScanRequestLostLink3( tpAniSirGlobal pMac, tANI_U32 sessionId )
1610{
1611 eHalStatus status = eHAL_STATUS_SUCCESS;
1612 tSmeCmd *pCommand;
1613 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1614
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001615 smsLog(pMac, LOGW, FL(" called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001616 do
1617 {
1618 pCommand = csrGetCommandBuffer(pMac);
1619 if(!pCommand)
1620 {
1621 status = eHAL_STATUS_RESOURCES;
1622 break;
1623 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301624 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001625 pCommand->command = eSmeCommandScan;
1626 pCommand->sessionId = (tANI_U8)sessionId;
1627 pCommand->u.scanCmd.reason = eCsrScanLostLink3;
1628 pCommand->u.scanCmd.callback = NULL;
1629 pCommand->u.scanCmd.pContext = NULL;
1630 pCommand->u.scanCmd.u.scanRequest.maxChnTime = pMac->roam.configParam.nActiveMaxChnTime;
1631 pCommand->u.scanCmd.u.scanRequest.minChnTime = pMac->roam.configParam.nActiveMinChnTime;
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08001632 pCommand->u.scanCmd.u.scanRequest.maxChnTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
1633 pCommand->u.scanCmd.u.scanRequest.minChnTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07001634 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Kiet Lam64c1b492013-07-12 13:56:44 +05301635 vos_mem_copy(&pCommand->u.scanCmd.u.scanRequest.bssid, bAddr, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07001636 //Put to the head of pending queue
1637 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_TRUE);
1638 if( !HAL_STATUS_SUCCESS( status ) )
1639 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001640 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07001641 break;
1642 }
1643 } while( 0 );
1644 if(!HAL_STATUS_SUCCESS(status))
1645 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001646 smsLog(pMac, LOGW, " csrScanRequestLostLink3 failed with status %d", status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001647 if(csrRoamCompleteRoaming(pMac, sessionId, eANI_BOOLEAN_FALSE, eCSR_ROAM_RESULT_FAILURE))
1648 {
1649 csrScanStartIdleScan(pMac);
1650 }
1651 if(pCommand)
1652 {
1653 csrReleaseCommandScan(pMac, pCommand);
1654 }
1655 }
1656
1657 return( status );
1658}
1659
1660
1661eHalStatus csrScanHandleSearchForSSID(tpAniSirGlobal pMac, tSmeCmd *pCommand)
1662{
1663 eHalStatus status = eHAL_STATUS_FAILURE;
1664 tScanResultHandle hBSSList = CSR_INVALID_SCANRESULT_HANDLE;
1665 tCsrScanResultFilter *pScanFilter = NULL;
1666 tCsrRoamProfile *pProfile = pCommand->u.scanCmd.pToRoamProfile;
1667 tANI_U32 sessionId = pCommand->sessionId;
1668#ifdef FEATURE_WLAN_BTAMP_UT_RF
1669 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1670#endif
1671 do
1672 {
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001673#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
1674 //if this scan is for LFR
1675 if(pMac->roam.neighborRoamInfo.uOsRequestedHandoff)
1676 {
1677 //notify LFR state m/c
1678 if(eHAL_STATUS_SUCCESS != csrNeighborRoamSssidScanDone(pMac, eHAL_STATUS_SUCCESS))
1679 {
Varun Reddy Yeturue3af4282013-06-07 00:56:52 -07001680 csrNeighborRoamStartLfrScan(pMac);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001681 }
1682 status = eHAL_STATUS_SUCCESS;
1683 break;
1684 }
1685#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001686 //If there is roam command waiting, ignore this roam because the newer roam command is the one to execute
1687 if(csrIsRoamCommandWaitingForSession(pMac, sessionId))
1688 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001689 smsLog(pMac, LOGW, FL(" aborts because roam command waiting"));
Jeff Johnson295189b2012-06-20 16:38:30 -07001690 break;
1691 }
1692 if(pProfile == NULL)
1693 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301694 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1695 if ( NULL == pScanFilter )
1696 status = eHAL_STATUS_FAILURE;
1697 else
1698 status = eHAL_STATUS_SUCCESS;
1699 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001700 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301701 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001702 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1703 if(!HAL_STATUS_SUCCESS(status))
1704 break;
1705 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1706 if(!HAL_STATUS_SUCCESS(status))
1707 break;
1708 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList, eCsrHddIssued,
1709 pCommand->u.scanCmd.roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1710 if(!HAL_STATUS_SUCCESS(status))
1711 {
1712 break;
1713 }
1714 }while(0);
1715 if(!HAL_STATUS_SUCCESS(status))
1716 {
1717 if(CSR_INVALID_SCANRESULT_HANDLE != hBSSList)
1718 {
1719 csrScanResultPurge(pMac, hBSSList);
1720 }
1721 //We haven't done anything to this profile
1722 csrRoamCallCallback(pMac, sessionId, NULL, pCommand->u.scanCmd.roamId,
1723 eCSR_ROAM_ASSOCIATION_FAILURE, eCSR_ROAM_RESULT_FAILURE);
1724 //In case we have nothing else to do, restart idle scan
1725 if(csrIsConnStateDisconnected(pMac, sessionId) && !csrIsRoamCommandWaiting(pMac))
1726 {
1727 status = csrScanStartIdleScan(pMac);
1728 }
1729#ifdef FEATURE_WLAN_BTAMP_UT_RF
1730 //In case of WDS station, let it retry.
1731 if( CSR_IS_WDS_STA(pProfile) )
1732 {
1733 //Save the roma profile so we can retry
1734 csrFreeRoamProfile( pMac, sessionId );
Kiet Lam64c1b492013-07-12 13:56:44 +05301735 pSession->pCurRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1736 if ( NULL != pSession->pCurRoamProfile )
Jeff Johnson295189b2012-06-20 16:38:30 -07001737 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301738 vos_mem_set(pSession->pCurRoamProfilee, sizeof(tCsrRoamProfile), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001739 csrRoamCopyProfile(pMac, pSession->pCurRoamProfile, pProfile);
1740 }
1741 csrRoamStartJoinRetryTimer(pMac, sessionId, CSR_JOIN_RETRY_TIMEOUT_PERIOD);
1742 }
1743#endif
1744 }
Kiet Lam64c1b492013-07-12 13:56:44 +05301745 if (pScanFilter)
Jeff Johnson295189b2012-06-20 16:38:30 -07001746 {
1747 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301748 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001749 }
1750
1751 return (status);
1752}
1753
1754
1755eHalStatus csrScanHandleSearchForSSIDFailure(tpAniSirGlobal pMac, tSmeCmd *pCommand)
1756{
1757 eHalStatus status = eHAL_STATUS_SUCCESS;
1758 tANI_U32 sessionId = pCommand->sessionId;
1759 tCsrRoamProfile *pProfile = pCommand->u.scanCmd.pToRoamProfile;
1760 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001761#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
1762 //if this scan is for LFR
1763 if(pMac->roam.neighborRoamInfo.uOsRequestedHandoff)
1764 {
1765 //notify LFR state m/c
1766 if(eHAL_STATUS_SUCCESS != csrNeighborRoamSssidScanDone(pMac, eHAL_STATUS_FAILURE))
1767 {
Varun Reddy Yeturue3af4282013-06-07 00:56:52 -07001768 csrNeighborRoamStartLfrScan(pMac);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07001769 }
1770 return eHAL_STATUS_SUCCESS;
1771 }
1772#endif
Jeff Johnson32d95a32012-09-10 13:15:23 -07001773 if(!pSession)
1774 {
1775 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
1776 return eHAL_STATUS_FAILURE;
1777 }
1778
Jeff Johnson295189b2012-06-20 16:38:30 -07001779#if defined(WLAN_DEBUG)
1780 if(pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs == 1)
1781 {
1782 char str[36];
Kiet Lam64c1b492013-07-12 13:56:44 +05301783 vos_mem_copy(str,
1784 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.ssId,
1785 pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.length);
Jeff Johnson295189b2012-06-20 16:38:30 -07001786 str[pCommand->u.scanCmd.u.scanRequest.SSIDs.SSIDList[0].SSID.length] = 0;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001787 smsLog(pMac, LOGW, FL(" SSID = %s"), str);
Jeff Johnson295189b2012-06-20 16:38:30 -07001788 }
1789#endif
1790 //Check whether it is for start ibss. No need to do anything if it is a JOIN request
1791 if(pProfile && CSR_IS_START_IBSS(pProfile))
1792 {
1793 status = csrRoamIssueConnect(pMac, sessionId, pProfile, NULL, eCsrHddIssued,
1794 pCommand->u.scanCmd.roamId, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1795 if(!HAL_STATUS_SUCCESS(status))
1796 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001797 smsLog(pMac, LOGE, FL("failed to issue startIBSS command with status = 0x%08X"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07001798 csrRoamCallCallback(pMac, sessionId, NULL, pCommand->u.scanCmd.roamId, eCSR_ROAM_FAILED, eCSR_ROAM_RESULT_FAILURE);
1799 }
1800 }
1801 else
1802 {
1803 eCsrRoamResult roamResult = eCSR_ROAM_RESULT_FAILURE;
1804
1805 if(csrIsConnStateDisconnected(pMac, sessionId) &&
1806 !csrIsRoamCommandWaitingForSession(pMac, sessionId))
1807 {
1808 status = csrScanStartIdleScan(pMac);
1809 }
1810 if((NULL == pProfile) || !csrIsBssTypeIBSS(pProfile->BSSType))
1811 {
1812 //Only indicate assoc_completion if we indicate assoc_start.
1813 if(pSession->bRefAssocStartCnt > 0)
1814 {
1815 tCsrRoamInfo *pRoamInfo = NULL, roamInfo;
Kiet Lam64c1b492013-07-12 13:56:44 +05301816 vos_mem_set(&roamInfo, sizeof(tCsrRoamInfo), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001817 pRoamInfo = &roamInfo;
1818 if(pCommand->u.roamCmd.pRoamBssEntry)
1819 {
1820 tCsrScanResult *pScanResult =
1821 GET_BASE_ADDR(pCommand->u.roamCmd.pRoamBssEntry,
1822 tCsrScanResult, Link);
1823 roamInfo.pBssDesc = &pScanResult->Result.BssDescriptor;
1824 }
1825 roamInfo.statusCode = pSession->joinFailStatusCode.statusCode;
1826 roamInfo.reasonCode = pSession->joinFailStatusCode.reasonCode;
1827 pSession->bRefAssocStartCnt--;
1828 csrRoamCallCallback(pMac, sessionId, pRoamInfo,
1829 pCommand->u.scanCmd.roamId,
1830 eCSR_ROAM_ASSOCIATION_COMPLETION,
1831 eCSR_ROAM_RESULT_FAILURE);
1832 }
Madan Mohan Koyyalamudiee255f12012-09-28 15:41:19 -07001833 else
1834 {
1835 csrRoamCallCallback(pMac, sessionId, NULL,
1836 pCommand->u.scanCmd.roamId,
1837 eCSR_ROAM_ASSOCIATION_FAILURE,
1838 eCSR_ROAM_RESULT_FAILURE);
1839 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001840#ifdef FEATURE_WLAN_BTAMP_UT_RF
1841 //In case of WDS station, let it retry.
1842 if( CSR_IS_WDS_STA(pProfile) )
1843 {
1844 //Save the roma profile so we can retry
1845 csrFreeRoamProfile( pMac, sessionId );
Kiet Lam64c1b492013-07-12 13:56:44 +05301846 pSession->pCurRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1847 if ( NULL != pSession->pCurRoamProfile )
Jeff Johnson295189b2012-06-20 16:38:30 -07001848 {
Kiet Lam64c1b492013-07-12 13:56:44 +05301849 vos_mem_set(pSession->pCurRoamProfile, sizeof(tCsrRoamProfile), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001850 csrRoamCopyProfile(pMac, pSession->pCurRoamProfile, pProfile);
1851 }
1852 csrRoamStartJoinRetryTimer(pMac, sessionId, CSR_JOIN_RETRY_TIMEOUT_PERIOD);
1853 }
1854#endif
1855 }
1856 else
1857 {
1858 roamResult = eCSR_ROAM_RESULT_IBSS_START_FAILED;
1859 }
1860 csrRoamCompletion(pMac, sessionId, NULL, pCommand, roamResult, eANI_BOOLEAN_FALSE);
1861 }
1862
1863 return (status);
1864}
1865
1866
1867//After scan for cap changes, issue a roaming command to either reconnect to the AP or pick another one to connect
1868eHalStatus csrScanHandleCapChangeScanComplete(tpAniSirGlobal pMac, tANI_U32 sessionId)
1869{
1870 eHalStatus status = eHAL_STATUS_FAILURE;
1871 tScanResultHandle hBSSList = NULL;
1872 tCsrScanResultFilter *pScanFilter = NULL;
1873 tANI_U32 roamId = 0;
1874 tCsrRoamProfile *pProfile = NULL;
1875 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
1876
1877 do
1878 {
1879 //Here is the profile we need to connect to
Kiet Lam64c1b492013-07-12 13:56:44 +05301880 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
1881 if ( NULL == pScanFilter )
1882 status = eHAL_STATUS_FAILURE;
1883 else
1884 status = eHAL_STATUS_SUCCESS;
1885 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07001886 break;
Kiet Lam64c1b492013-07-12 13:56:44 +05301887 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
1888 if (NULL == pSession) break;
1889 if (NULL == pSession->pCurRoamProfile)
Jeff Johnson295189b2012-06-20 16:38:30 -07001890 {
1891 pScanFilter->EncryptionType.numEntries = 1;
1892 pScanFilter->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_NONE;
1893 }
1894 else
1895 {
1896 //We have to make a copy of pCurRoamProfile because it will be free inside csrRoamIssueConnect
Kiet Lam64c1b492013-07-12 13:56:44 +05301897 pProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
1898 if ( NULL == pProfile )
1899 status = eHAL_STATUS_FAILURE;
1900 else
1901 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07001902 if(!HAL_STATUS_SUCCESS(status))
1903 break;
1904 status = csrRoamCopyProfile(pMac, pProfile, pSession->pCurRoamProfile);
1905 if(!HAL_STATUS_SUCCESS(status))
1906 break;
1907 status = csrRoamPrepareFilterFromProfile(pMac, pProfile, pScanFilter);
1908 }//We have a profile
1909 roamId = GET_NEXT_ROAM_ID(&pMac->roam);
1910 if(HAL_STATUS_SUCCESS(status))
1911 {
1912 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
1913 if(HAL_STATUS_SUCCESS(status))
1914 {
1915 //we want to put the last connected BSS to the very beginning, if possible
1916 csrMoveBssToHeadFromBSSID(pMac, &pSession->connectedProfile.bssid, hBSSList);
1917 status = csrRoamIssueConnect(pMac, sessionId, pProfile, hBSSList,
1918 eCsrCapsChange, 0, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
1919 if(!HAL_STATUS_SUCCESS(status))
1920 {
1921 csrScanResultPurge(pMac, hBSSList);
1922 }
1923 }//Have scan result
1924 else
1925 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08001926 smsLog(pMac, LOGW, FL("cannot find matching BSS of %02X-%02X-%02X-%02X-%02X-%02X"),
Jeff Johnson295189b2012-06-20 16:38:30 -07001927 pSession->connectedProfile.bssid[0],
1928 pSession->connectedProfile.bssid[1],
1929 pSession->connectedProfile.bssid[2],
1930 pSession->connectedProfile.bssid[3],
1931 pSession->connectedProfile.bssid[4],
1932 pSession->connectedProfile.bssid[5]);
1933 //Disconnect
1934 csrRoamDisconnectInternal(pMac, sessionId, eCSR_DISCONNECT_REASON_UNSPECIFIED);
1935 }
1936 }
1937 }while(0);
1938 if(pScanFilter)
1939 {
1940 csrFreeScanFilter(pMac, pScanFilter);
Kiet Lam64c1b492013-07-12 13:56:44 +05301941 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07001942 }
1943 if(NULL != pProfile)
1944 {
1945 csrReleaseProfile(pMac, pProfile);
Kiet Lam64c1b492013-07-12 13:56:44 +05301946 vos_mem_free(pProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07001947 }
1948
1949 return (status);
1950}
1951
1952
1953
1954eHalStatus csrScanResultPurge(tpAniSirGlobal pMac, tScanResultHandle hScanList)
1955{
1956 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
1957 tScanResultList *pScanList = (tScanResultList *)hScanList;
1958
1959 if(pScanList)
1960 {
1961 status = csrLLScanPurgeResult(pMac, &pScanList->List);
1962 csrLLClose(&pScanList->List);
Kiet Lam64c1b492013-07-12 13:56:44 +05301963 vos_mem_free(pScanList);
Jeff Johnson295189b2012-06-20 16:38:30 -07001964 }
1965 return (status);
1966}
1967
1968
1969static tANI_U32 csrGetBssPreferValue(tpAniSirGlobal pMac, int rssi)
1970{
1971 tANI_U32 ret = 0;
1972 int i = CSR_NUM_RSSI_CAT - 1;
1973
1974 while(i >= 0)
1975 {
1976 if(rssi >= pMac->roam.configParam.RSSICat[i])
1977 {
1978 ret = pMac->roam.configParam.BssPreferValue[i];
1979 break;
1980 }
1981 i--;
1982 };
1983
1984 return (ret);
1985}
1986
1987
1988//Return a CapValue base on the capabilities of a BSS
1989static tANI_U32 csrGetBssCapValue(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes)
1990{
1991 tANI_U32 ret = CSR_BSS_CAP_VALUE_NONE;
Madan Mohan Koyyalamudid5026072012-11-30 14:56:21 -08001992#if defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_CCX) || defined(FEATURE_WLAN_LFR)
1993 if(CSR_IS_ROAM_PREFER_5GHZ(pMac))
1994 {
1995 if((pBssDesc) && CSR_IS_CHANNEL_5GHZ(pBssDesc->channelId))
1996 {
1997 ret += CSR_BSS_CAP_VALUE_5GHZ;
1998 }
1999 }
2000#endif
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002001 /* if strict select 5GHz is non-zero then ignore the capability checking */
2002 if (pIes && !CSR_IS_SELECT_5GHZ_MARGIN(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -07002003 {
2004 //We only care about 11N capability
2005 if(pIes->HTCaps.present)
2006 {
2007 ret += CSR_BSS_CAP_VALUE_HT;
2008 }
2009 if(CSR_IS_QOS_BSS(pIes))
2010 {
2011 ret += CSR_BSS_CAP_VALUE_WMM;
2012 //Give advantage to UAPSD
2013 if(CSR_IS_UAPSD_BSS(pIes))
2014 {
2015 ret += CSR_BSS_CAP_VALUE_UAPSD;
2016 }
2017 }
2018 }
2019
2020 return (ret);
2021}
2022
2023
2024//To check whther pBss1 is better than pBss2
2025static tANI_BOOLEAN csrIsBetterBss(tCsrScanResult *pBss1, tCsrScanResult *pBss2)
2026{
2027 tANI_BOOLEAN ret;
2028
2029 if(CSR_IS_BETTER_PREFER_VALUE(pBss1->preferValue, pBss2->preferValue))
2030 {
2031 ret = eANI_BOOLEAN_TRUE;
2032 }
2033 else if(CSR_IS_EQUAL_PREFER_VALUE(pBss1->preferValue, pBss2->preferValue))
2034 {
2035 if(CSR_IS_BETTER_CAP_VALUE(pBss1->capValue, pBss2->capValue))
2036 {
2037 ret = eANI_BOOLEAN_TRUE;
2038 }
2039 else
2040 {
2041 ret = eANI_BOOLEAN_FALSE;
2042 }
2043 }
2044 else
2045 {
2046 ret = eANI_BOOLEAN_FALSE;
2047 }
2048
2049 return (ret);
2050}
2051
2052
Srikant Kuppa866893f2012-12-27 17:28:14 -08002053#ifdef FEATURE_WLAN_LFR
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002054//Add the channel to the occupiedChannels array
2055static void csrScanAddToOccupiedChannels(
Srikant Kuppa866893f2012-12-27 17:28:14 -08002056 tpAniSirGlobal pMac,
2057 tCsrScanResult *pResult,
2058 tCsrChannel *pOccupiedChannels,
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002059 tDot11fBeaconIEs *pIes)
2060{
2061 eHalStatus status;
2062 tANI_U8 channel;
2063 tANI_U8 numOccupiedChannels = pOccupiedChannels->numChannels;
2064 tANI_U8 *pOccupiedChannelList = pOccupiedChannels->channelList;
2065
2066 channel = pResult->Result.BssDescriptor.channelId;
2067
2068 if (!csrIsChannelPresentInList(pOccupiedChannelList, numOccupiedChannels, channel)
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08002069 && csrNeighborRoamConnectedProfileMatch(pMac, pResult, pIes))
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002070 {
Srikant Kuppa866893f2012-12-27 17:28:14 -08002071 status = csrAddToChannelListFront(pOccupiedChannelList, numOccupiedChannels, channel);
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002072 if(HAL_STATUS_SUCCESS(status))
Srikant Kuppa866893f2012-12-27 17:28:14 -08002073 {
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002074 pOccupiedChannels->numChannels++;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002075 smsLog(pMac, LOG2, FL("%s: added channel %d to the list (count=%d)"),
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08002076 __func__, channel, pOccupiedChannels->numChannels);
Srikant Kuppa866893f2012-12-27 17:28:14 -08002077 if (pOccupiedChannels->numChannels > CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN)
2078 pOccupiedChannels->numChannels = CSR_BG_SCAN_OCCUPIED_CHANNEL_LIST_LEN;
2079 }
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002080 }
2081}
2082#endif
2083
Jeff Johnson295189b2012-06-20 16:38:30 -07002084//Put the BSS into the scan result list
2085//pIes can not be NULL
2086static void csrScanAddResult(tpAniSirGlobal pMac, tCsrScanResult *pResult, tDot11fBeaconIEs *pIes)
2087{
Srinivas28b5b4e2012-12-12 13:07:53 -08002088#ifdef FEATURE_WLAN_LFR
2089 tpCsrNeighborRoamControlInfo pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
2090#endif
2091
Jeff Johnson295189b2012-06-20 16:38:30 -07002092 pResult->preferValue = csrGetBssPreferValue(pMac, (int)pResult->Result.BssDescriptor.rssi);
2093 pResult->capValue = csrGetBssCapValue(pMac, &pResult->Result.BssDescriptor, pIes);
2094 csrLLInsertTail( &pMac->scan.scanResultList, &pResult->Link, LL_ACCESS_LOCK );
Srikant Kuppa866893f2012-12-27 17:28:14 -08002095#ifdef FEATURE_WLAN_LFR
Srinivas28b5b4e2012-12-12 13:07:53 -08002096 if(0 == pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels)
2097 {
2098 /* Build the occupied channel list, only if "gNeighborScanChannelList" is
2099 NOT set in the cfg.ini file */
2100 csrScanAddToOccupiedChannels(pMac, pResult, &pMac->scan.occupiedChannels, pIes);
2101 }
Madan Mohan Koyyalamudi470d2cf2012-09-28 14:43:44 -07002102#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07002103}
2104
2105
2106eHalStatus csrScanGetResult(tpAniSirGlobal pMac, tCsrScanResultFilter *pFilter, tScanResultHandle *phResult)
2107{
2108 eHalStatus status;
2109 tScanResultList *pRetList;
2110 tCsrScanResult *pResult, *pBssDesc;
2111 tANI_U32 count = 0;
2112 tListElem *pEntry;
2113 tANI_U32 bssLen, allocLen;
2114 eCsrEncryptionType uc = eCSR_ENCRYPT_TYPE_NONE, mc = eCSR_ENCRYPT_TYPE_NONE;
2115 eCsrAuthType auth = eCSR_AUTH_TYPE_OPEN_SYSTEM;
2116 tDot11fBeaconIEs *pIes, *pNewIes;
2117 tANI_BOOLEAN fMatch;
2118
2119 if(phResult)
2120 {
2121 *phResult = CSR_INVALID_SCANRESULT_HANDLE;
2122 }
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002123
2124 if (pMac->roam.configParam.nSelect5GHzMargin)
2125 {
2126 pMac->scan.inScanResultBestAPRssi = -128;
2127 csrLLLock(&pMac->scan.scanResultList);
2128
2129 /* Find out the best AP Rssi going thru the scan results */
2130 pEntry = csrLLPeekHead(&pMac->scan.scanResultList, LL_ACCESS_NOLOCK);
2131 while ( NULL != pEntry)
2132 {
2133 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2134 if (pBssDesc->Result.BssDescriptor.rssi > pMac->scan.inScanResultBestAPRssi)
2135 {
2136 pMac->scan.inScanResultBestAPRssi = pBssDesc->Result.BssDescriptor.rssi;
2137 }
2138 pEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
2139 }
2140
2141 /* Modify Rssi category based on best AP Rssi */
2142 csrAssignRssiForCategory(pMac, pMac->scan.inScanResultBestAPRssi, pMac->roam.configParam.bCatRssiOffset);
2143 pEntry = csrLLPeekHead(&pMac->scan.scanResultList, LL_ACCESS_NOLOCK);
2144 while ( NULL != pEntry)
2145 {
2146 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2147
2148 /* re-assign preference value based on modified rssi bucket */
2149 pBssDesc->preferValue = csrGetBssPreferValue(pMac, (int)pBssDesc->Result.BssDescriptor.rssi);
2150
2151 pEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
2152 }
2153
2154 csrLLUnlock(&pMac->scan.scanResultList);
2155 }
2156
Kiet Lam64c1b492013-07-12 13:56:44 +05302157 pRetList = vos_mem_malloc(sizeof(tScanResultList));
2158 if ( NULL == pRetList )
2159 status = eHAL_STATUS_FAILURE;
2160 else
2161 status = eHAL_STATUS_SUCCESS;
Srinivas Girigowda41c7c5f2013-10-21 19:01:38 -07002162 if(HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07002163 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302164 vos_mem_set(pRetList, sizeof(tScanResultList), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002165 csrLLOpen(pMac->hHdd, &pRetList->List);
2166 pRetList->pCurEntry = NULL;
2167
2168 csrLLLock(&pMac->scan.scanResultList);
2169 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
2170 while( pEntry )
2171 {
2172 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2173 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
2174 //if pBssDesc->Result.pvIes is NULL, we need to free any memory allocated by csrMatchBSS
2175 //for any error condition, otherwiase, it will be freed later.
2176 //reset
2177 fMatch = eANI_BOOLEAN_FALSE;
2178 pNewIes = NULL;
2179
2180 if(pFilter)
2181 {
2182 fMatch = csrMatchBSS(pMac, &pBssDesc->Result.BssDescriptor, pFilter, &auth, &uc, &mc, &pIes);
2183 if( NULL != pIes )
2184 {
2185 //Only save it when matching
2186 if(fMatch)
2187 {
2188 if( !pBssDesc->Result.pvIes )
2189 {
2190 //csrMatchBSS allocates the memory. Simply pass it and it is freed later
2191 pNewIes = pIes;
2192 }
2193 else
2194 {
2195 //The pIes is allocated by someone else. make a copy
2196 //Only to save parsed IEs if caller provides a filter. Most likely the caller
2197 //is using to for association, hence save the parsed IEs
Kiet Lam64c1b492013-07-12 13:56:44 +05302198 pNewIes = vos_mem_malloc(sizeof(tDot11fBeaconIEs));
2199 if ( NULL == pNewIes )
2200 status = eHAL_STATUS_FAILURE;
2201 else
2202 status = eHAL_STATUS_SUCCESS;
2203 if ( HAL_STATUS_SUCCESS( status ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07002204 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302205 vos_mem_copy(pNewIes, pIes, sizeof( tDot11fBeaconIEs ));
Jeff Johnson295189b2012-06-20 16:38:30 -07002206 }
2207 else
2208 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002209 smsLog(pMac, LOGE, FL(" fail to allocate memory for IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002210 //Need to free memory allocated by csrMatchBSS
2211 if( !pBssDesc->Result.pvIes )
2212 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302213 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07002214 }
2215 break;
2216 }
2217 }
2218 }//fMatch
2219 else if( !pBssDesc->Result.pvIes )
2220 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302221 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07002222 }
2223 }
2224 }
2225 if(NULL == pFilter || fMatch)
2226 {
2227 bssLen = pBssDesc->Result.BssDescriptor.length + sizeof(pBssDesc->Result.BssDescriptor.length);
2228 allocLen = sizeof( tCsrScanResult ) + bssLen;
Kiet Lam64c1b492013-07-12 13:56:44 +05302229 pResult = vos_mem_malloc(allocLen);
2230 if ( NULL == pResult )
2231 status = eHAL_STATUS_FAILURE;
2232 else
2233 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07002234 if(!HAL_STATUS_SUCCESS(status))
2235 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002236 smsLog(pMac, LOGE, FL(" fail to allocate memory for scan result, len=%d"), allocLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07002237 if(pNewIes)
2238 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302239 vos_mem_free(pNewIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07002240 }
2241 break;
2242 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302243 vos_mem_set(pResult, allocLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002244 pResult->capValue = pBssDesc->capValue;
2245 pResult->preferValue = pBssDesc->preferValue;
2246 pResult->ucEncryptionType = uc;
2247 pResult->mcEncryptionType = mc;
2248 pResult->authType = auth;
2249 pResult->Result.ssId = pBssDesc->Result.ssId;
2250 pResult->Result.timer = 0;
2251 //save the pIes for later use
2252 pResult->Result.pvIes = pNewIes;
2253 //save bss description
Kiet Lam64c1b492013-07-12 13:56:44 +05302254 vos_mem_copy(&pResult->Result.BssDescriptor,
2255 &pBssDesc->Result.BssDescriptor, bssLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07002256 //No need to lock pRetList because it is locally allocated and no outside can access it at this time
2257 if(csrLLIsListEmpty(&pRetList->List, LL_ACCESS_NOLOCK))
2258 {
2259 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_NOLOCK);
2260 }
2261 else
2262 {
2263 //To sort the list
2264 tListElem *pTmpEntry;
2265 tCsrScanResult *pTmpResult;
2266
2267 pTmpEntry = csrLLPeekHead(&pRetList->List, LL_ACCESS_NOLOCK);
2268 while(pTmpEntry)
2269 {
2270 pTmpResult = GET_BASE_ADDR( pTmpEntry, tCsrScanResult, Link );
2271 if(csrIsBetterBss(pResult, pTmpResult))
2272 {
2273 csrLLInsertEntry(&pRetList->List, pTmpEntry, &pResult->Link, LL_ACCESS_NOLOCK);
2274 //To indicate we are done
2275 pResult = NULL;
2276 break;
2277 }
2278 pTmpEntry = csrLLNext(&pRetList->List, pTmpEntry, LL_ACCESS_NOLOCK);
2279 }
2280 if(pResult != NULL)
2281 {
2282 //This one is not better than any one
2283 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_NOLOCK);
2284 }
2285 }
2286 count++;
2287 }
2288 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK );
2289 }//while
2290 csrLLUnlock(&pMac->scan.scanResultList);
2291
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002292 smsLog(pMac, LOG2, FL("return %d BSS"), csrLLCount(&pRetList->List));
Jeff Johnson295189b2012-06-20 16:38:30 -07002293
2294 if( !HAL_STATUS_SUCCESS(status) || (phResult == NULL) )
2295 {
2296 //Fail or No one wants the result.
2297 csrScanResultPurge(pMac, (tScanResultHandle)pRetList);
2298 }
2299 else
2300 {
2301 if(0 == count)
2302 {
2303 //We are here meaning the there is no match
2304 csrLLClose(&pRetList->List);
Kiet Lam64c1b492013-07-12 13:56:44 +05302305 vos_mem_free(pRetList);
Jeff Johnson295189b2012-06-20 16:38:30 -07002306 status = eHAL_STATUS_E_NULL_VALUE;
2307 }
2308 else if(phResult)
2309 {
2310 *phResult = pRetList;
2311 }
2312 }
2313 }//Allocated pRetList
2314
2315 return (status);
2316}
2317
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002318/*
2319 * NOTE: This routine is being added to make
2320 * sure that scan results are not being flushed
2321 * while roaming. If the scan results are flushed,
2322 * we are unable to recover from
2323 * csrRoamRoamingStateDisassocRspProcessor.
2324 * If it is needed to remove this routine,
2325 * first ensure that we recover gracefully from
2326 * csrRoamRoamingStateDisassocRspProcessor if
2327 * csrScanGetResult returns with a failure because
2328 * of not being able to find the roaming BSS.
2329 */
2330tANI_U8 csrScanFlushDenied(tpAniSirGlobal pMac)
2331{
2332 switch(pMac->roam.neighborRoamInfo.neighborRoamState) {
2333 case eCSR_NEIGHBOR_ROAM_STATE_REPORT_SCAN:
2334 case eCSR_NEIGHBOR_ROAM_STATE_PREAUTHENTICATING:
2335 case eCSR_NEIGHBOR_ROAM_STATE_PREAUTH_DONE:
2336 case eCSR_NEIGHBOR_ROAM_STATE_REASSOCIATING:
2337 return (pMac->roam.neighborRoamInfo.neighborRoamState);
2338 default:
2339 return 0;
2340 }
2341}
2342
Jeff Johnson295189b2012-06-20 16:38:30 -07002343eHalStatus csrScanFlushResult(tpAniSirGlobal pMac)
2344{
Madan Mohan Koyyalamudiab41d0f2012-10-31 17:17:10 -07002345 tANI_U8 isFlushDenied = csrScanFlushDenied(pMac);
2346 if (isFlushDenied) {
2347 smsLog(pMac, LOGW, "%s: scan flush denied in roam state %d",
2348 __func__, isFlushDenied);
2349 return eHAL_STATUS_FAILURE;
2350 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002351 return ( csrLLScanPurgeResult(pMac, &pMac->scan.scanResultList) );
2352}
2353
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302354eHalStatus csrScanFlushSelectiveResult(tpAniSirGlobal pMac, v_BOOL_t flushP2P)
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002355{
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302356 eHalStatus status = eHAL_STATUS_SUCCESS;
2357 tListElem *pEntry,*pFreeElem;
2358 tCsrScanResult *pBssDesc;
2359 tDblLinkList *pList = &pMac->scan.scanResultList;
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002360
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302361 csrLLLock(pList);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002362
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302363 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK );
2364 while( pEntry != NULL)
2365 {
2366 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2367 if( flushP2P == vos_mem_compare( pBssDesc->Result.ssId.ssId,
2368 "DIRECT-", 7) )
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002369 {
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302370 pFreeElem = pEntry;
2371 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2372 csrLLRemoveEntry(pList, pFreeElem, LL_ACCESS_NOLOCK);
2373 csrFreeScanResultEntry( pMac, pBssDesc );
2374 continue;
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002375 }
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302376 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
2377 }
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002378
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302379 csrLLUnlock(pList);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002380
Madan Mohan Koyyalamudi5850f312012-11-27 19:00:25 +05302381 return (status);
Madan Mohan Koyyalamudia3fcf142012-10-18 15:01:20 -07002382}
2383
Jeff Johnson295189b2012-06-20 16:38:30 -07002384/**
2385 * csrCheck11dChannel
2386 *
2387 *FUNCTION:
2388 * This function is called from csrScanFilter11dResult function and
2389 * compare channel number with given channel list.
2390 *
2391 *LOGIC:
2392 * Check Scan result channel number with CFG channel list
2393 *
2394 *ASSUMPTIONS:
2395 *
2396 *
2397 *NOTE:
2398 *
2399 * @param channelId channel number
2400 * @param pChannelList Pointer to channel list
2401 * @param numChannels Number of channel in channel list
2402 *
2403 * @return Status
2404 */
2405
2406eHalStatus csrCheck11dChannel(tANI_U8 channelId, tANI_U8 *pChannelList, tANI_U32 numChannels)
2407{
2408 eHalStatus status = eHAL_STATUS_FAILURE;
2409 tANI_U8 i = 0;
2410
2411 for (i = 0; i < numChannels; i++)
2412 {
2413 if(pChannelList[ i ] == channelId)
2414 {
2415 status = eHAL_STATUS_SUCCESS;
2416 break;
2417 }
2418 }
2419 return status;
2420}
2421
2422/**
2423 * csrScanFilter11dResult
2424 *
2425 *FUNCTION:
2426 * This function is called from csrApplyCountryInformation function and
2427 * filter scan result based on valid channel list number.
2428 *
2429 *LOGIC:
2430 * Get scan result from scan list and Check Scan result channel number
2431 * with 11d channel list if channel number is found in 11d channel list
2432 * then do not remove scan result entry from scan list
2433 *
2434 *ASSUMPTIONS:
2435 *
2436 *
2437 *NOTE:
2438 *
2439 * @param pMac Pointer to Global MAC structure
2440 *
2441 * @return Status
2442 */
2443
2444eHalStatus csrScanFilter11dResult(tpAniSirGlobal pMac)
2445{
2446 eHalStatus status = eHAL_STATUS_SUCCESS;
2447 tListElem *pEntry,*pTempEntry;
2448 tCsrScanResult *pBssDesc;
2449 tANI_U32 len = sizeof(pMac->roam.validChannelList);
2450
2451 /* Get valid channels list from CFG */
2452 if (!HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac,
2453 pMac->roam.validChannelList, &len)))
2454 {
2455 smsLog( pMac, LOG1, "Failed to get Channel list from CFG");
2456 }
2457
2458 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
2459 while( pEntry )
2460 {
2461 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2462 pTempEntry = csrLLNext( &pMac->scan.scanResultList, pEntry,
2463 LL_ACCESS_LOCK );
2464 if(csrCheck11dChannel(pBssDesc->Result.BssDescriptor.channelId,
2465 pMac->roam.validChannelList, len))
2466 {
2467 /* Remove Scan result which does not have 11d channel */
2468 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry,
2469 LL_ACCESS_LOCK ))
2470 {
2471 csrFreeScanResultEntry( pMac, pBssDesc );
2472 }
2473 }
2474 pEntry = pTempEntry;
2475 }
2476 return status;
2477}
2478
2479
2480eHalStatus csrScanCopyResultList(tpAniSirGlobal pMac, tScanResultHandle hIn, tScanResultHandle *phResult)
2481{
2482 eHalStatus status = eHAL_STATUS_SUCCESS;
2483 tScanResultList *pRetList, *pInList = (tScanResultList *)hIn;
2484 tCsrScanResult *pResult, *pScanResult;
2485 tANI_U32 count = 0;
2486 tListElem *pEntry;
2487 tANI_U32 bssLen, allocLen;
2488
2489 if(phResult)
2490 {
2491 *phResult = CSR_INVALID_SCANRESULT_HANDLE;
2492 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302493 pRetList = vos_mem_malloc(sizeof(tScanResultList));
2494 if ( NULL == pRetList )
2495 status = eHAL_STATUS_FAILURE;
2496 else
Jeff Johnson295189b2012-06-20 16:38:30 -07002497 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302498 vos_mem_set(pRetList, sizeof(tScanResultList), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002499 csrLLOpen(pMac->hHdd, &pRetList->List);
2500 pRetList->pCurEntry = NULL;
2501 csrLLLock(&pMac->scan.scanResultList);
2502 csrLLLock(&pInList->List);
2503
2504 pEntry = csrLLPeekHead( &pInList->List, LL_ACCESS_NOLOCK );
2505 while( pEntry )
2506 {
2507 pScanResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2508 bssLen = pScanResult->Result.BssDescriptor.length + sizeof(pScanResult->Result.BssDescriptor.length);
2509 allocLen = sizeof( tCsrScanResult ) + bssLen;
Kiet Lam64c1b492013-07-12 13:56:44 +05302510 pResult = vos_mem_malloc(allocLen);
2511 if ( NULL == pResult )
2512 status = eHAL_STATUS_FAILURE;
2513 else
2514 status = eHAL_STATUS_SUCCESS;
2515 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07002516 {
2517 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
2518 count = 0;
2519 break;
2520 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302521 vos_mem_set(pResult, allocLen , 0);
2522 vos_mem_copy(&pResult->Result.BssDescriptor, &pScanResult->Result.BssDescriptor, bssLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07002523 if( pScanResult->Result.pvIes )
2524 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302525 pResult->Result.pvIes = vos_mem_malloc(sizeof( tDot11fBeaconIEs ));
2526 if ( NULL == pResult->Result.pvIes )
2527 status = eHAL_STATUS_FAILURE;
2528 else
2529 status = eHAL_STATUS_SUCCESS;
2530 if (!HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07002531 {
2532 //Free the memory we allocate above first
Kiet Lam64c1b492013-07-12 13:56:44 +05302533 vos_mem_free(pResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07002534 csrScanResultPurge(pMac, (tScanResultHandle *)pRetList);
2535 count = 0;
2536 break;
2537 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302538 vos_mem_copy(pResult->Result.pvIes, pScanResult->Result.pvIes,
2539 sizeof( tDot11fBeaconIEs ));
Jeff Johnson295189b2012-06-20 16:38:30 -07002540 }
2541 csrLLInsertTail(&pRetList->List, &pResult->Link, LL_ACCESS_LOCK);
2542 count++;
2543 pEntry = csrLLNext( &pInList->List, pEntry, LL_ACCESS_NOLOCK );
2544 }//while
2545 csrLLUnlock(&pInList->List);
2546 csrLLUnlock(&pMac->scan.scanResultList);
2547
2548 if(HAL_STATUS_SUCCESS(status))
2549 {
2550 if(0 == count)
2551 {
2552 csrLLClose(&pRetList->List);
Kiet Lam64c1b492013-07-12 13:56:44 +05302553 vos_mem_free(pRetList);
Jeff Johnson295189b2012-06-20 16:38:30 -07002554 status = eHAL_STATUS_E_NULL_VALUE;
2555 }
2556 else if(phResult)
2557 {
2558 *phResult = pRetList;
2559 }
2560 }
2561 }//Allocated pRetList
2562
2563 return (status);
2564}
2565
2566
2567
2568eHalStatus csrScanningStateMsgProcessor( tpAniSirGlobal pMac, void *pMsgBuf )
2569{
2570 eHalStatus status = eHAL_STATUS_SUCCESS;
2571 tSirMbMsg *pMsg = (tSirMbMsg *)pMsgBuf;
2572
2573 if((eWNI_SME_SCAN_RSP == pMsg->type) || (eWNI_SME_GET_SCANNED_CHANNEL_RSP == pMsg->type))
2574 {
2575 status = csrScanSmeScanResponse( pMac, pMsgBuf );
2576 }
2577 else
2578 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002579 if(pMsg->type == eWNI_SME_UPPER_LAYER_ASSOC_CNF)
Jeff Johnson295189b2012-06-20 16:38:30 -07002580 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002581 tCsrRoamSession *pSession;
2582 tSirSmeAssocIndToUpperLayerCnf *pUpperLayerAssocCnf;
2583 tCsrRoamInfo roamInfo;
2584 tCsrRoamInfo *pRoamInfo = NULL;
2585 tANI_U32 sessionId;
2586 eHalStatus status;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002587 smsLog( pMac, LOG1, FL("Scanning : ASSOCIATION confirmation can be given to upper layer "));
Kiet Lam64c1b492013-07-12 13:56:44 +05302588 vos_mem_set(&roamInfo, sizeof(tCsrRoamInfo), 0);
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002589 pRoamInfo = &roamInfo;
2590 pUpperLayerAssocCnf = (tSirSmeAssocIndToUpperLayerCnf *)pMsgBuf;
2591 status = csrRoamGetSessionIdFromBSSID( pMac, (tCsrBssid *)pUpperLayerAssocCnf->bssId, &sessionId );
2592 pSession = CSR_GET_SESSION(pMac, sessionId);
2593
2594 if(!pSession)
2595 {
2596 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
2597 return eHAL_STATUS_FAILURE;
2598 }
2599
2600 pRoamInfo->statusCode = eSIR_SME_SUCCESS; //send the status code as Success
2601 pRoamInfo->u.pConnectedProfile = &pSession->connectedProfile;
2602 pRoamInfo->staId = (tANI_U8)pUpperLayerAssocCnf->aid;
2603 pRoamInfo->rsnIELen = (tANI_U8)pUpperLayerAssocCnf->rsnIE.length;
2604 pRoamInfo->prsnIE = pUpperLayerAssocCnf->rsnIE.rsnIEdata;
2605 pRoamInfo->addIELen = (tANI_U8)pUpperLayerAssocCnf->addIE.length;
2606 pRoamInfo->paddIE = pUpperLayerAssocCnf->addIE.addIEdata;
Kiet Lam64c1b492013-07-12 13:56:44 +05302607 vos_mem_copy(pRoamInfo->peerMac, pUpperLayerAssocCnf->peerMacAddr, sizeof(tSirMacAddr));
2608 vos_mem_copy(&pRoamInfo->bssid, pUpperLayerAssocCnf->bssId, sizeof(tCsrBssid));
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002609 pRoamInfo->wmmEnabledSta = pUpperLayerAssocCnf->wmmEnabledSta;
2610 if(CSR_IS_INFRA_AP(pRoamInfo->u.pConnectedProfile) )
2611 {
2612 pMac->roam.roamSession[sessionId].connectState = eCSR_ASSOC_STATE_TYPE_INFRA_CONNECTED;
2613 pRoamInfo->fReassocReq = pUpperLayerAssocCnf->reassocReq;
2614 status = csrRoamCallCallback(pMac, sessionId, pRoamInfo, 0, eCSR_ROAM_INFRA_IND, eCSR_ROAM_RESULT_INFRA_ASSOCIATION_CNF);
2615 }
2616 if(CSR_IS_WDS_AP( pRoamInfo->u.pConnectedProfile))
2617 {
2618 vos_sleep( 100 );
2619 pMac->roam.roamSession[sessionId].connectState = eCSR_ASSOC_STATE_TYPE_WDS_CONNECTED;//Sta
2620 status = csrRoamCallCallback(pMac, sessionId, pRoamInfo, 0, eCSR_ROAM_WDS_IND, eCSR_ROAM_RESULT_WDS_ASSOCIATION_IND);//Sta
2621 }
2622
Jeff Johnson295189b2012-06-20 16:38:30 -07002623 }
2624 else
2625 {
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002626
2627 if( csrIsAnySessionInConnectState( pMac ) )
2628 {
2629 //In case of we are connected, we need to check whether connect status changes
2630 //because scan may also run while connected.
2631 csrRoamCheckForLinkStatusChange( pMac, ( tSirSmeRsp * )pMsgBuf );
2632 }
2633 else
2634 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002635 smsLog( pMac, LOGW, "Message [0x%04x] received in state, when expecting Scan Response", pMsg->type );
Madan Mohan Koyyalamudicd784992013-01-11 15:30:36 -08002636 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002637 }
2638 }
2639
2640 return (status);
2641}
2642
2643
2644
2645void csrCheckNSaveWscIe(tpAniSirGlobal pMac, tSirBssDescription *pNewBssDescr, tSirBssDescription *pOldBssDescr)
2646{
2647 int idx, len;
2648 tANI_U8 *pbIe;
2649
2650 //If failed to remove, assuming someone else got it.
2651 if((pNewBssDescr->fProbeRsp != pOldBssDescr->fProbeRsp) &&
2652 (0 == pNewBssDescr->WscIeLen))
2653 {
2654 idx = 0;
2655 len = pOldBssDescr->length - sizeof(tSirBssDescription) +
2656 sizeof(tANI_U16) + sizeof(tANI_U32) - DOT11F_IE_WSCPROBERES_MIN_LEN - 2;
2657 pbIe = (tANI_U8 *)pOldBssDescr->ieFields;
2658 //Save WPS IE if it exists
2659 pNewBssDescr->WscIeLen = 0;
2660 while(idx < len)
2661 {
2662 if((DOT11F_EID_WSCPROBERES == pbIe[0]) &&
2663 (0x00 == pbIe[2]) && (0x50 == pbIe[3]) && (0xf2 == pbIe[4]) && (0x04 == pbIe[5]))
2664 {
2665 //Founrd it
2666 if((DOT11F_IE_WSCPROBERES_MAX_LEN - 2) >= pbIe[1])
2667 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302668 vos_mem_copy(pNewBssDescr->WscIeProbeRsp, pbIe, pbIe[1] + 2);
Jeff Johnson295189b2012-06-20 16:38:30 -07002669 pNewBssDescr->WscIeLen = pbIe[1] + 2;
2670 }
2671 break;
2672 }
2673 idx += pbIe[1] + 2;
2674 pbIe += pbIe[1] + 2;
2675 }
2676 }
2677}
2678
2679
2680
2681//pIes may be NULL
2682tANI_BOOLEAN csrRemoveDupBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDescr,
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05302683 tDot11fBeaconIEs *pIes, tAniSSID *pSsid, v_TIME_t *timer, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07002684{
2685 tListElem *pEntry;
2686
2687 tCsrScanResult *pBssDesc;
2688 tANI_BOOLEAN fRC = FALSE;
2689
2690 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
2691 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
2692 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
2693 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_LOCK );
2694
2695 while( pEntry )
2696 {
2697 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2698
2699 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
2700 // matches
2701 if ( csrIsDuplicateBssDescription( pMac, &pBssDesc->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07002702 pSirBssDescr, pIes, fForced ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07002703 {
2704 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
2705 ((tANI_S32)pBssDesc->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
2706 // Remove the 'old' entry from the list....
2707 if( csrLLRemoveEntry( &pMac->scan.scanResultList, pEntry, LL_ACCESS_LOCK ) )
2708 {
2709 // !we need to free the memory associated with this node
2710 //If failed to remove, assuming someone else got it.
2711 *pSsid = pBssDesc->Result.ssId;
2712 *timer = pBssDesc->Result.timer;
2713 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pBssDesc->Result.BssDescriptor);
2714
2715 csrFreeScanResultEntry( pMac, pBssDesc );
2716 }
2717 else
2718 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002719 smsLog( pMac, LOGW, FL( " fail to remove entry" ) );
Jeff Johnson295189b2012-06-20 16:38:30 -07002720 }
2721 fRC = TRUE;
2722
2723 // If we found a match, we can stop looking through the list.
2724 break;
2725 }
2726
2727 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_LOCK );
2728 }
2729
2730 return fRC;
2731}
2732
2733
2734eHalStatus csrAddPMKIDCandidateList( tpAniSirGlobal pMac, tANI_U32 sessionId,
2735 tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes )
2736{
2737 eHalStatus status = eHAL_STATUS_FAILURE;
2738 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
2739
Jeff Johnson32d95a32012-09-10 13:15:23 -07002740 if(!pSession)
2741 {
2742 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
2743 return eHAL_STATUS_FAILURE;
2744 }
2745
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002746 smsLog(pMac, LOGW, "csrAddPMKIDCandidateList called pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07002747 if( pIes )
2748 {
2749 // check if this is a RSN BSS
2750 if( pIes->RSN.present )
2751 {
2752 // Check if the BSS is capable of doing pre-authentication
2753 if( pSession->NumPmkidCandidate < CSR_MAX_PMKID_ALLOWED )
2754 {
2755
2756#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
2757 {
2758 WLAN_VOS_DIAG_EVENT_DEF(secEvent, vos_event_wlan_security_payload_type);
Kiet Lam64c1b492013-07-12 13:56:44 +05302759 vos_mem_set(&secEvent, sizeof(vos_event_wlan_security_payload_type), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07002760 secEvent.eventId = WLAN_SECURITY_EVENT_PMKID_CANDIDATE_FOUND;
2761 secEvent.encryptionModeMulticast =
2762 (v_U8_t)diagEncTypeFromCSRType(pSession->connectedProfile.mcEncryptionType);
2763 secEvent.encryptionModeUnicast =
2764 (v_U8_t)diagEncTypeFromCSRType(pSession->connectedProfile.EncryptionType);
Kiet Lam64c1b492013-07-12 13:56:44 +05302765 vos_mem_copy(secEvent.bssid, pSession->connectedProfile.bssid, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07002766 secEvent.authMode =
2767 (v_U8_t)diagAuthTypeFromCSRType(pSession->connectedProfile.AuthType);
2768 WLAN_VOS_DIAG_EVENT_REPORT(&secEvent, EVENT_WLAN_SECURITY);
2769 }
2770#endif//#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
2771
2772 // if yes, then add to PMKIDCandidateList
Kiet Lam64c1b492013-07-12 13:56:44 +05302773 vos_mem_copy(pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].BSSID,
2774 pBssDesc->bssId, WNI_CFG_BSSID_LEN);
2775 // Bit 0 offirst byte - PreAuthentication Capability
2776 if ( (pIes->RSN.RSN_Cap[0] >> 0) & 0x1 )
Jeff Johnson295189b2012-06-20 16:38:30 -07002777 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302778 pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].preAuthSupported
2779 = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07002780 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302781 else
2782 {
2783 pSession->PmkidCandidateInfo[pSession->NumPmkidCandidate].preAuthSupported
2784 = eANI_BOOLEAN_FALSE;
2785 }
2786 pSession->NumPmkidCandidate++;
Jeff Johnson295189b2012-06-20 16:38:30 -07002787 }
2788 else
2789 {
2790 status = eHAL_STATUS_FAILURE;
2791 }
2792 }
2793 }
2794
2795 return (status);
2796}
2797
2798//This function checks whether new AP is found for the current connected profile
2799//If it is found, it return the sessionId, else it return invalid sessionID
2800tANI_U32 csrProcessBSSDescForPMKIDList(tpAniSirGlobal pMac,
2801 tSirBssDescription *pBssDesc,
2802 tDot11fBeaconIEs *pIes)
2803{
2804 tANI_U32 i, bRet = CSR_SESSION_ID_INVALID;
2805 tCsrRoamSession *pSession;
2806 tDot11fBeaconIEs *pIesLocal = pIes;
2807
2808 if( pIesLocal || HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIesLocal)) )
2809 {
2810 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
2811 {
2812 if( CSR_IS_SESSION_VALID( pMac, i ) )
2813 {
2814 pSession = CSR_GET_SESSION( pMac, i );
2815 if( csrIsConnStateConnectedInfra( pMac, i ) &&
2816 ( eCSR_AUTH_TYPE_RSN == pSession->connectedProfile.AuthType ) )
2817 {
2818 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile, pBssDesc, pIesLocal))
2819 {
2820 //this new BSS fits the current profile connected
2821 if(HAL_STATUS_SUCCESS(csrAddPMKIDCandidateList(pMac, i, pBssDesc, pIesLocal)))
2822 {
2823 bRet = i;
2824 }
2825 break;
2826 }
2827 }
2828 }
2829 }
2830 if( !pIes )
2831 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302832 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07002833 }
2834 }
2835
2836 return (tANI_U8)bRet;
2837}
2838
2839#ifdef FEATURE_WLAN_WAPI
2840eHalStatus csrAddBKIDCandidateList( tpAniSirGlobal pMac, tANI_U32 sessionId,
2841 tSirBssDescription *pBssDesc, tDot11fBeaconIEs *pIes )
2842{
2843 eHalStatus status = eHAL_STATUS_FAILURE;
2844 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
2845
Jeff Johnson32d95a32012-09-10 13:15:23 -07002846 if(!pSession)
2847 {
2848 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
2849 return eHAL_STATUS_FAILURE;
2850 }
2851
Kiet Lam64c1b492013-07-12 13:56:44 +05302852 smsLog(pMac, LOGW, "csrAddBKIDCandidateList called pMac->scan.NumBkidCandidate = %d",
2853 pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07002854 if( pIes )
2855 {
2856 // check if this is a WAPI BSS
2857 if( pIes->WAPI.present )
2858 {
2859 // Check if the BSS is capable of doing pre-authentication
2860 if( pSession->NumBkidCandidate < CSR_MAX_BKID_ALLOWED )
2861 {
2862
2863 // if yes, then add to BKIDCandidateList
Kiet Lam64c1b492013-07-12 13:56:44 +05302864 vos_mem_copy(pSession->BkidCandidateInfo[pSession->NumBkidCandidate].BSSID,
2865 pBssDesc->bssId, WNI_CFG_BSSID_LEN);
2866 if ( pIes->WAPI.preauth )
Jeff Johnson295189b2012-06-20 16:38:30 -07002867 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302868 pSession->BkidCandidateInfo[pSession->NumBkidCandidate].preAuthSupported
2869 = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07002870 }
Kiet Lam64c1b492013-07-12 13:56:44 +05302871 else
2872 {
2873 pSession->BkidCandidateInfo[pSession->NumBkidCandidate].preAuthSupported
2874 = eANI_BOOLEAN_FALSE;
2875 }
2876 pSession->NumBkidCandidate++;
Jeff Johnson295189b2012-06-20 16:38:30 -07002877 }
2878 else
2879 {
2880 status = eHAL_STATUS_FAILURE;
2881 }
2882 }
2883 }
2884
2885 return (status);
2886}
2887
2888//This function checks whether new AP is found for the current connected profile
2889//if so add to BKIDCandidateList
2890tANI_BOOLEAN csrProcessBSSDescForBKIDList(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
2891 tDot11fBeaconIEs *pIes)
2892{
2893 tANI_BOOLEAN fRC = FALSE;
2894 tDot11fBeaconIEs *pIesLocal = pIes;
2895 tANI_U32 sessionId;
2896 tCsrRoamSession *pSession;
2897
2898 if( pIesLocal || HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIesLocal)) )
2899 {
2900 for( sessionId = 0; sessionId < CSR_ROAM_SESSION_MAX; sessionId++ )
2901 {
2902 if( CSR_IS_SESSION_VALID( pMac, sessionId) )
2903 {
2904 pSession = CSR_GET_SESSION( pMac, sessionId );
2905 if( csrIsConnStateConnectedInfra( pMac, sessionId ) &&
2906 eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE == pSession->connectedProfile.AuthType)
2907 {
2908 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile,pBssDesc, pIesLocal))
2909 {
2910 //this new BSS fits the current profile connected
2911 if(HAL_STATUS_SUCCESS(csrAddBKIDCandidateList(pMac, sessionId, pBssDesc, pIesLocal)))
2912 {
2913 fRC = TRUE;
2914 }
2915 }
2916 }
2917 }
2918 }
2919 if(!pIes)
2920 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302921 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07002922 }
2923
2924 }
2925 return fRC;
2926}
2927
2928#endif
2929
2930
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07002931static void csrMoveTempScanResultsToMainList( tpAniSirGlobal pMac, tANI_U8 reason )
Jeff Johnson295189b2012-06-20 16:38:30 -07002932{
2933 tListElem *pEntry;
Agarwal Ashishd9d72602013-09-13 00:06:17 +05302934 tListElem *pEntryTemp;
2935 tListElem *pNext;
Jeff Johnson295189b2012-06-20 16:38:30 -07002936 tCsrScanResult *pBssDescription;
2937 tANI_S8 cand_Bss_rssi;
Agarwal Ashishd9d72602013-09-13 00:06:17 +05302938 tANI_S8 rssi_of_current_country;
Jeff Johnson295189b2012-06-20 16:38:30 -07002939 tANI_BOOLEAN fDupBss;
2940#ifdef FEATURE_WLAN_WAPI
2941 tANI_BOOLEAN fNewWapiBSSForCurConnection = eANI_BOOLEAN_FALSE;
2942#endif /* FEATURE_WLAN_WAPI */
2943 tDot11fBeaconIEs *pIesLocal = NULL;
2944 tANI_U32 sessionId = CSR_SESSION_ID_INVALID;
2945 tAniSSID tmpSsid;
2946 v_TIME_t timer=0;
Agarwal Ashishd9d72602013-09-13 00:06:17 +05302947 tCsrBssid bssid_temp = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
Jeff Johnson295189b2012-06-20 16:38:30 -07002948
2949 tmpSsid.length = 0;
2950 cand_Bss_rssi = -128; // RSSI coming from PE is -ve
Agarwal Ashishd9d72602013-09-13 00:06:17 +05302951 rssi_of_current_country = -128;
Jeff Johnson295189b2012-06-20 16:38:30 -07002952
2953 // remove the BSS descriptions from temporary list
2954 while( ( pEntry = csrLLRemoveTail( &pMac->scan.tempScanResults, LL_ACCESS_LOCK ) ) != NULL)
2955 {
2956 pBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
2957
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002958 smsLog( pMac, LOGW, "...Bssid= %02x-%02x-%02x-%02x-%02x-%02x chan= %d, rssi = -%d",
Jeff Johnson295189b2012-06-20 16:38:30 -07002959 pBssDescription->Result.BssDescriptor.bssId[ 0 ], pBssDescription->Result.BssDescriptor.bssId[ 1 ],
2960 pBssDescription->Result.BssDescriptor.bssId[ 2 ], pBssDescription->Result.BssDescriptor.bssId[ 3 ],
2961 pBssDescription->Result.BssDescriptor.bssId[ 4 ], pBssDescription->Result.BssDescriptor.bssId[ 5 ],
2962 pBssDescription->Result.BssDescriptor.channelId,
2963 pBssDescription->Result.BssDescriptor.rssi * (-1) );
2964
2965 //At this time, pBssDescription->Result.pvIes may be NULL
2966 pIesLocal = (tDot11fBeaconIEs *)( pBssDescription->Result.pvIes );
2967 if( !pIesLocal && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pBssDescription->Result.BssDescriptor, &pIesLocal))) )
2968 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002969 smsLog(pMac, LOGE, FL(" Cannot pared IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002970 csrFreeScanResultEntry(pMac, pBssDescription);
2971 continue;
2972 }
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05302973 fDupBss = csrRemoveDupBssDescription( pMac, &pBssDescription->Result.BssDescriptor, pIesLocal, &tmpSsid, &timer, FALSE );
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07002974 //Check whether we have reach out limit, but don't lose the LFR candidates came from FW
2975 if( CSR_SCAN_IS_OVER_BSS_LIMIT(pMac)
2976#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
2977 && !( eCsrScanGetLfrResult == reason )
2978#endif
2979 )
Jeff Johnson295189b2012-06-20 16:38:30 -07002980 {
2981 //Limit reach
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08002982 smsLog(pMac, LOGW, FL(" BSS limit reached"));
Jeff Johnson295189b2012-06-20 16:38:30 -07002983 //Free the resources
2984 if( (pBssDescription->Result.pvIes == NULL) && pIesLocal )
2985 {
Kiet Lam64c1b492013-07-12 13:56:44 +05302986 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07002987 }
2988 csrFreeScanResultEntry(pMac, pBssDescription);
2989 //Continue because there may be duplicated BSS
2990 continue;
2991 }
2992 // check for duplicate scan results
2993 if ( !fDupBss )
2994 {
2995 //Found a new BSS
2996 sessionId = csrProcessBSSDescForPMKIDList(pMac,
2997 &pBssDescription->Result.BssDescriptor, pIesLocal);
2998 if( CSR_SESSION_ID_INVALID != sessionId)
2999 {
3000 csrRoamCallCallback(pMac, sessionId, NULL, 0,
3001 eCSR_ROAM_SCAN_FOUND_NEW_BSS, eCSR_ROAM_RESULT_NONE);
3002 }
3003 }
3004 else
3005 {
3006 //Check if the new one has SSID it it, if not, use the older SSID if it exists.
3007 if( (0 == pBssDescription->Result.ssId.length) && tmpSsid.length )
3008 {
3009 //New BSS has a hidden SSID and old one has the SSID. Keep the SSID only
3010 //if diff of saved SSID time and current time is less than 1 min to avoid
3011 //side effect of saving SSID with old one is that if AP changes its SSID while remain
3012 //hidden, we may never see it and also to address the requirement of
3013 //When we remove hidden ssid from the profile i.e., forget the SSID via
3014 // GUI that SSID shouldn't see in the profile
3015 if( (vos_timer_get_system_time() - timer) <= HIDDEN_TIMER)
3016 {
3017 pBssDescription->Result.timer = timer;
3018 pBssDescription->Result.ssId = tmpSsid;
3019 }
3020 }
3021 }
3022
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303023 //Find a good AP for 11d info
3024 if ( csrIs11dSupported( pMac ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003025 {
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303026 if (cand_Bss_rssi < pBssDescription->Result.BssDescriptor.rssi)
Jeff Johnson295189b2012-06-20 16:38:30 -07003027 {
3028 // check if country information element is present
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303029 if (pIesLocal->Country.present)
Jeff Johnson295189b2012-06-20 16:38:30 -07003030 {
3031 cand_Bss_rssi = pBssDescription->Result.BssDescriptor.rssi;
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303032 smsLog(pMac, LOGW, FL("11d AP Bssid " MAC_ADDRESS_STR
3033 " chan= %d, rssi = -%d, countryCode %c%c"),
3034 MAC_ADDR_ARRAY( pBssDescription->Result.BssDescriptor.bssId),
3035 pBssDescription->Result.BssDescriptor.channelId,
3036 pBssDescription->Result.BssDescriptor.rssi * (-1),
3037 pIesLocal->Country.country[0],pIesLocal->Country.country[1] );
3038 //Getting BSSID for best AP in scan result.
3039 palCopyMemory(pMac->hHdd, bssid_temp,
3040 pBssDescription->Result.BssDescriptor.bssId, sizeof(tSirMacAddr));
3041
Jeff Johnson295189b2012-06-20 16:38:30 -07003042 }
3043
3044 }
3045 }
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303046 //get current rssi for BSS from which country code is acquired.
3047 if ( csrIs11dSupported(pMac) && (csrIsMacAddressEqual(pMac,
3048 &pMac->scan.currentCountryBssid,
3049 &pBssDescription->Result.BssDescriptor.bssId) ))
3050 {
3051 smsLog(pMac, LOGW, FL("Information about current country Bssid "
3052 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 rssi_of_current_country = pBssDescription->Result.BssDescriptor.rssi ;
3059 }
3060
Jeff Johnson295189b2012-06-20 16:38:30 -07003061
Madan Mohan Koyyalamudi527935a2012-12-04 16:41:16 -08003062
Jeff Johnson295189b2012-06-20 16:38:30 -07003063 // append to main list
3064 csrScanAddResult(pMac, pBssDescription, pIesLocal);
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303065 if ( (pBssDescription->Result.pvIes == NULL) && pIesLocal )
Jeff Johnson295189b2012-06-20 16:38:30 -07003066 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303067 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07003068 }
3069 }
3070
Agarwal Ashishd9d72602013-09-13 00:06:17 +05303071 // Calculating 30% of current rssi is an idea for not to change
3072 // country code so freq.
3073 if (rssi_of_current_country != -128)
3074 {
3075 rssi_of_current_country = rssi_of_current_country
3076 - THIRTY_PERCENT(rssi_of_current_country);
3077 }
3078
3079 if ((rssi_of_current_country <= cand_Bss_rssi ) || rssi_of_current_country == -128)
3080 {
3081 csrLLLock(&pMac->scan.scanResultList);
3082 pEntryTemp = csrLLPeekHead(&pMac->scan.scanResultList, LL_ACCESS_NOLOCK);
3083 while ( NULL != pEntryTemp)
3084 {
3085 pNext = csrLLNext(&pMac->scan.scanResultList, pEntryTemp,
3086 LL_ACCESS_NOLOCK);
3087 pBssDescription = GET_BASE_ADDR( pEntryTemp, tCsrScanResult, Link );
3088 pIesLocal = (tDot11fBeaconIEs *)( pBssDescription->Result.pvIes );
3089 // Need to traverse whole scan list to get description for best 11d AP.
3090 if (csrIsMacAddressEqual(pMac, (tCsrBssid *)&bssid_temp,
3091 (tCsrBssid *) pBssDescription->Result.BssDescriptor.bssId))
3092 {
3093 palCopyMemory(pMac->hHdd, pMac->scan.currentCountryBssid,
3094 bssid_temp, sizeof(tSirMacAddr));
3095 // Best AP should be passed to update reg domain.
3096 csrLearnCountryInformation( pMac, &pBssDescription->Result.BssDescriptor,
3097 pIesLocal, eANI_BOOLEAN_FALSE );
3098 break;
3099 }
3100 pEntryTemp = pNext;
3101 }
3102 csrLLUnlock(&pMac->scan.scanResultList);
3103 }
3104
3105
Jeff Johnson295189b2012-06-20 16:38:30 -07003106 //Tush: If we can find the current 11d info in any of the scan results, or
3107 // a good enough AP with the 11d info from the scan results then no need to
3108 // get into ambiguous state
3109 if(pMac->scan.fAmbiguous11dInfoFound)
3110 {
3111 if((pMac->scan.fCurrent11dInfoMatch) || (cand_Bss_rssi != -128))
3112 {
3113 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
3114 }
3115 }
3116
3117#ifdef FEATURE_WLAN_WAPI
3118 if(fNewWapiBSSForCurConnection)
3119 {
3120 //remember it first
3121 csrRoamCallCallback(pMac, sessionId, NULL, 0, eCSR_ROAM_SCAN_FOUND_NEW_BSS, eCSR_ROAM_RESULT_NEW_WAPI_BSS);
3122 }
3123#endif /* FEATURE_WLAN_WAPI */
3124
3125 return;
3126}
3127
3128
3129static tCsrScanResult *csrScanSaveBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pBSSDescription,
3130 tDot11fBeaconIEs *pIes)
3131{
3132 tCsrScanResult *pCsrBssDescription = NULL;
3133 tANI_U32 cbBSSDesc;
3134 tANI_U32 cbAllocated;
Jeff Johnson295189b2012-06-20 16:38:30 -07003135
3136 // figure out how big the BSS description is (the BSSDesc->length does NOT
3137 // include the size of the length field itself).
3138 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
3139
3140 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
3141
Kiet Lam64c1b492013-07-12 13:56:44 +05303142 pCsrBssDescription = vos_mem_malloc(cbAllocated);
3143 if ( NULL != pCsrBssDescription )
Jeff Johnson295189b2012-06-20 16:38:30 -07003144 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303145 vos_mem_set(pCsrBssDescription, cbAllocated, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003146 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Kiet Lam64c1b492013-07-12 13:56:44 +05303147 vos_mem_copy(&pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc);
Jeff Johnson295189b2012-06-20 16:38:30 -07003148#if defined(VOSS_ENSBALED)
3149 VOS_ASSERT( pCsrBssDescription->Result.pvIes == NULL );
3150#endif
3151 csrScanAddResult(pMac, pCsrBssDescription, pIes);
3152 }
3153
3154 return( pCsrBssDescription );
3155}
3156
3157// Append a Bss Description...
3158tCsrScanResult *csrScanAppendBssDescription( tpAniSirGlobal pMac,
3159 tSirBssDescription *pSirBssDescription,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07003160 tDot11fBeaconIEs *pIes, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07003161{
3162 tCsrScanResult *pCsrBssDescription = NULL;
3163 tAniSSID tmpSsid;
3164 v_TIME_t timer = 0;
3165 int result;
3166
3167 tmpSsid.length = 0;
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07003168 result = csrRemoveDupBssDescription( pMac, pSirBssDescription, pIes, &tmpSsid, &timer, fForced );
Jeff Johnson295189b2012-06-20 16:38:30 -07003169 pCsrBssDescription = csrScanSaveBssDescription( pMac, pSirBssDescription, pIes );
3170 if (result && (pCsrBssDescription != NULL))
3171 {
3172 //Check if the new one has SSID it it, if not, use the older SSID if it exists.
3173 if( (0 == pCsrBssDescription->Result.ssId.length) && tmpSsid.length )
3174 {
3175 //New BSS has a hidden SSID and old one has the SSID. Keep the SSID only
3176 //if diff of saved SSID time and current time is less than 1 min to avoid
3177 //side effect of saving SSID with old one is that if AP changes its SSID while remain
3178 //hidden, we may never see it and also to address the requirement of
3179 //When we remove hidden ssid from the profile i.e., forget the SSID via
3180 // GUI that SSID shouldn't see in the profile
3181 if((vos_timer_get_system_time()-timer) <= HIDDEN_TIMER)
3182 {
3183 pCsrBssDescription->Result.ssId = tmpSsid;
3184 pCsrBssDescription->Result.timer = timer;
3185 }
3186 }
3187 }
3188
3189
3190 return( pCsrBssDescription );
3191}
3192
3193
3194
3195void csrPurgeChannelPower( tpAniSirGlobal pMac, tDblLinkList *pChannelList )
3196{
3197 tCsrChannelPowerInfo *pChannelSet;
3198 tListElem *pEntry;
3199
3200 csrLLLock(pChannelList);
3201 // Remove the channel sets from the learned list and put them in the free list
3202 while( ( pEntry = csrLLRemoveHead( pChannelList, LL_ACCESS_NOLOCK ) ) != NULL)
3203 {
3204 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3205 if( pChannelSet )
3206 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303207 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003208 }
3209 }
3210 csrLLUnlock(pChannelList);
3211 return;
3212}
3213
3214
3215/*
3216 * Save the channelList into the ultimate storage as the final stage of channel
3217 * Input: pCountryInfo -- the country code (e.g. "USI"), channel list, and power limit are all stored inside this data structure
3218 */
Jeff Johnsone7245742012-09-05 17:12:55 -07003219eHalStatus csrSaveToChannelPower2G_5G( tpAniSirGlobal pMac, tANI_U32 tableSize, tSirMacChanInfo *channelTable )
Jeff Johnson295189b2012-06-20 16:38:30 -07003220{
3221 tANI_U32 i = tableSize / sizeof( tSirMacChanInfo );
3222 tSirMacChanInfo *pChannelInfo;
3223 tCsrChannelPowerInfo *pChannelSet;
3224 tANI_BOOLEAN f2GHzInfoFound = FALSE;
3225 tANI_BOOLEAN f2GListPurged = FALSE, f5GListPurged = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003226
3227 pChannelInfo = channelTable;
3228 // atleast 3 bytes have to be remaining -- from "countryString"
3229 while ( i-- )
3230 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303231 pChannelSet = vos_mem_malloc(sizeof(tCsrChannelPowerInfo));
3232 if ( NULL != pChannelSet )
Jeff Johnson295189b2012-06-20 16:38:30 -07003233 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303234 vos_mem_set(pChannelSet, sizeof(tCsrChannelPowerInfo), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003235 pChannelSet->firstChannel = pChannelInfo->firstChanNum;
3236 pChannelSet->numChannels = pChannelInfo->numChannels;
3237
3238 // Now set the inter-channel offset based on the frequency band the channel set lies in
Jeff Johnsone7245742012-09-05 17:12:55 -07003239 if( (CSR_IS_CHANNEL_24GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003240 ((pChannelSet->firstChannel + (pChannelSet->numChannels - 1)) <= CSR_MAX_24GHz_CHANNEL_NUMBER) )
Jeff Johnsone7245742012-09-05 17:12:55 -07003241
Jeff Johnson295189b2012-06-20 16:38:30 -07003242 {
3243 pChannelSet->interChannelOffset = 1;
3244 f2GHzInfoFound = TRUE;
3245 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003246 else if ( (CSR_IS_CHANNEL_5GHZ(pChannelSet->firstChannel)) &&
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003247 ((pChannelSet->firstChannel + ((pChannelSet->numChannels - 1) * 4)) <= CSR_MAX_5GHz_CHANNEL_NUMBER) )
Jeff Johnson295189b2012-06-20 16:38:30 -07003248 {
3249 pChannelSet->interChannelOffset = 4;
3250 f2GHzInfoFound = FALSE;
3251 }
Jeff Johnsone7245742012-09-05 17:12:55 -07003252 else
3253 {
Madan Mohan Koyyalamudi5904d7c2012-09-24 13:49:03 -07003254 smsLog( pMac, LOGW, FL("Invalid Channel %d Present in Country IE"),
Jeff Johnsone7245742012-09-05 17:12:55 -07003255 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303256 vos_mem_free(pChannelSet);
Jeff Johnsone7245742012-09-05 17:12:55 -07003257 return eHAL_STATUS_FAILURE;
3258 }
3259
Jeff Johnson295189b2012-06-20 16:38:30 -07003260 pChannelSet->txPower = CSR_ROAM_MIN( pChannelInfo->maxTxPower, pMac->roam.configParam.nTxPowerCap );
3261
3262 if( f2GHzInfoFound )
3263 {
3264 if( !f2GListPurged )
3265 {
3266 // purge previous results if found new
3267 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList24 );
3268 f2GListPurged = TRUE;
3269 }
3270
3271 if(CSR_IS_OPERATING_BG_BAND(pMac))
3272 {
3273 // add to the list of 2.4 GHz channel sets
3274 csrLLInsertTail( &pMac->scan.channelPowerInfoList24, &pChannelSet->link, LL_ACCESS_LOCK );
3275 }
3276 else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003277 smsLog( pMac, LOGW, FL("Adding 11B/G channels in 11A mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003278 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303279 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003280 }
3281 }
3282 else
3283 {
3284 // 5GHz info found
3285 if( !f5GListPurged )
3286 {
3287 // purge previous results if found new
3288 csrPurgeChannelPower( pMac, &pMac->scan.channelPowerInfoList5G );
3289 f5GListPurged = TRUE;
3290 }
3291
3292 if(CSR_IS_OPERATING_A_BAND(pMac))
3293 {
3294 // add to the list of 5GHz channel sets
3295 csrLLInsertTail( &pMac->scan.channelPowerInfoList5G, &pChannelSet->link, LL_ACCESS_LOCK );
3296 }
3297 else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003298 smsLog( pMac, LOGW, FL("Adding 11A channels in B/G mode -- First Channel is %d"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003299 pChannelSet->firstChannel);
Kiet Lam64c1b492013-07-12 13:56:44 +05303300 vos_mem_free(pChannelSet);
Jeff Johnson295189b2012-06-20 16:38:30 -07003301 }
3302 }
3303 }
3304
3305 pChannelInfo++; // move to next entry
3306 }
3307
Jeff Johnsone7245742012-09-05 17:12:55 -07003308 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07003309}
3310
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303311static void csrClearDfsChannelList( tpAniSirGlobal pMac )
3312{
3313 tSirMbMsg *pMsg;
3314 tANI_U16 msgLen;
Jeff Johnson295189b2012-06-20 16:38:30 -07003315
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303316 msgLen = (tANI_U16)(sizeof( tSirMbMsg ));
Kiet Lam64c1b492013-07-12 13:56:44 +05303317 pMsg = vos_mem_malloc(msgLen);
3318 if ( NULL != pMsg )
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303319 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303320 vos_mem_set((void *)pMsg, msgLen, 0);
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303321 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_CLEAR_DFS_CHANNEL_LIST);
3322 pMsg->msgLen = pal_cpu_to_be16(msgLen);
3323 palSendMBMessage(pMac->hHdd, pMsg);
3324 }
3325}
Jeff Johnson295189b2012-06-20 16:38:30 -07003326
3327void csrApplyPower2Current( tpAniSirGlobal pMac )
3328{
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003329 smsLog( pMac, LOG3, FL(" Updating Cfg with power settings"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003330 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList24, WNI_CFG_MAX_TX_POWER_2_4 );
3331 csrSaveTxPowerToCfg( pMac, &pMac->scan.channelPowerInfoList5G, WNI_CFG_MAX_TX_POWER_5 );
3332}
3333
3334
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003335void csrApplyChannelPowerCountryInfo( tpAniSirGlobal pMac, tCsrChannel *pChannelList, tANI_U8 *countryCode, tANI_BOOLEAN updateRiva)
Jeff Johnson295189b2012-06-20 16:38:30 -07003336{
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303337 int i, j, count, countryIndex = -1;
Jeff Johnson295189b2012-06-20 16:38:30 -07003338 eNVChannelEnabledType channelEnabledType;
3339 tANI_U8 numChannels = 0;
3340 tANI_U8 tempNumChannels = 0;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303341 tANI_U8 channelIgnore = FALSE;
Jeff Johnson295189b2012-06-20 16:38:30 -07003342 tCsrChannel ChannelList;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303343
Jeff Johnson295189b2012-06-20 16:38:30 -07003344 if( pChannelList->numChannels )
3345 {
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303346 for(count=0; count < MAX_COUNTRY_IGNORE; count++)
3347 {
3348 if(vos_mem_compare(countryCode, countryIgnoreList[count].countryCode,
3349 VOS_COUNTRY_CODE_LEN))
3350 {
3351 countryIndex = count;
3352 break;
3353 }
3354 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003355 tempNumChannels = CSR_MIN(pChannelList->numChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN);
3356 /* If user doesn't want to scan the DFS channels lets trim them from
3357 the valid channel list*/
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303358 for(i=0; i < tempNumChannels; i++)
Jeff Johnson295189b2012-06-20 16:38:30 -07003359 {
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303360 channelIgnore = FALSE;
3361 if( FALSE == pMac->scan.fEnableDFSChnlScan )
3362 {
3363 channelEnabledType =
3364 vos_nv_getChannelEnabledState(pChannelList->channelList[i]);
3365 }
3366 else
3367 {
Madan Mohan Koyyalamudi3f65e312012-11-06 15:31:12 -08003368 channelEnabledType = NV_CHANNEL_ENABLE;
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303369 }
3370 if( NV_CHANNEL_ENABLE == channelEnabledType )
3371 {
3372 if( countryIndex != -1 )
3373 {
3374 for(j=0; j < countryIgnoreList[countryIndex].channelCount; j++)
3375 {
3376 if( pChannelList->channelList[i] ==
3377 countryIgnoreList[countryIndex].channelList[j] )
3378 {
3379 channelIgnore = TRUE;
3380 break;
3381 }
3382 }
3383 }
3384 if( FALSE == channelIgnore )
3385 {
3386 ChannelList.channelList[numChannels] = pChannelList->channelList[i];
3387 numChannels++;
3388 }
3389 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003390 }
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303391 ChannelList.numChannels = numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -07003392 csrSetCfgValidChannelList(pMac, ChannelList.channelList, ChannelList.numChannels);
3393 // extend scan capability
Gopichand Nakkala10ba6fc2013-04-23 20:30:01 +05303394 // build a scan list based on the channel list : channel# + active/passive scan
3395 csrSetCfgScanControlList(pMac, countryCode, &ChannelList);
Gopichand Nakkalac178ac82013-05-30 19:53:39 +05303396 /*Send msg to Lim to clear DFS channel list */
3397 csrClearDfsChannelList(pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07003398#ifdef FEATURE_WLAN_SCAN_PNO
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003399 if (updateRiva)
3400 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003401 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO, FL(" Sending 11d PNO info to Riva"));
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003402 // Send HAL UpdateScanParams message
3403 pmcUpdateScanParams(pMac, &(pMac->roam.configParam), &ChannelList, TRUE);
3404 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003405#endif // FEATURE_WLAN_SCAN_PNO
3406 }
3407 else
3408 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003409 smsLog( pMac, LOGE, FL(" 11D channel list is empty"));
Jeff Johnson295189b2012-06-20 16:38:30 -07003410 }
3411 csrApplyPower2Current( pMac ); // Store the channel+power info in the global place: Cfg
3412 csrSetCfgCountryCode(pMac, countryCode);
3413}
3414
3415
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003416void csrResetCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce, tANI_BOOLEAN updateRiva )
Jeff Johnson295189b2012-06-20 16:38:30 -07003417{
3418 if( fForce || (csrIs11dSupported( pMac ) && (!pMac->scan.f11dInfoReset)))
3419 {
3420
3421#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3422 {
3423 vos_log_802_11d_pkt_type *p11dLog;
3424 int Index;
3425
3426 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
3427 if(p11dLog)
3428 {
3429 p11dLog->eventId = WLAN_80211D_EVENT_RESET;
Kiet Lam64c1b492013-07-12 13:56:44 +05303430 vos_mem_copy(p11dLog->countryCode, pMac->scan.countryCodeCurrent, 3);
Jeff Johnson295189b2012-06-20 16:38:30 -07003431 p11dLog->numChannel = pMac->scan.base20MHzChannels.numChannels;
3432 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
3433 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303434 vos_mem_copy(p11dLog->Channels,
3435 pMac->scan.base20MHzChannels.channelList,
3436 p11dLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07003437 for (Index=0; Index < pMac->scan.base20MHzChannels.numChannels; Index++)
3438 {
3439 p11dLog->TxPwr[Index] = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
3440 }
3441 }
3442 if(!pMac->roam.configParam.Is11dSupportEnabled)
3443 {
3444 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
3445 }
3446 else if(pMac->roam.configParam.fEnforceDefaultDomain)
3447 {
3448 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
3449 }
3450 else
3451 {
3452 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
3453 }
3454 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
3455 }
3456 }
3457#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3458
3459 // switch to passive scans only when 11d is enabled
3460 if( csrIs11dSupported( pMac ) )
3461 {
3462 pMac->scan.curScanType = eSIR_PASSIVE_SCAN;
3463 }
Jeff Johnson04dd8a82012-06-29 20:41:40 -07003464
3465 csrPruneChannelListForMode(pMac, &pMac->scan.baseChannels);
3466 csrPruneChannelListForMode(pMac, &pMac->scan.base20MHzChannels);
3467
Jeff Johnson295189b2012-06-20 16:38:30 -07003468 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_FALSE);
3469 csrSaveChannelPowerForBand(pMac, eANI_BOOLEAN_TRUE);
3470 // ... and apply the channel list, power settings, and the country code.
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003471 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.base20MHzChannels, pMac->scan.countryCodeCurrent, updateRiva );
Jeff Johnson295189b2012-06-20 16:38:30 -07003472 // clear the 11d channel list
Kiet Lam64c1b492013-07-12 13:56:44 +05303473 vos_mem_set(&pMac->scan.channels11d, sizeof(pMac->scan.channels11d), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003474 pMac->scan.f11dInfoReset = eANI_BOOLEAN_TRUE;
3475 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_FALSE;
3476 }
3477
3478 return;
3479}
3480
3481
3482eHalStatus csrResetCountryCodeInformation(tpAniSirGlobal pMac, tANI_BOOLEAN *pfRestartNeeded)
3483{
3484 eHalStatus status = eHAL_STATUS_SUCCESS;
3485 tANI_BOOLEAN fRestart = eANI_BOOLEAN_FALSE;
3486
3487 //Use the Country code and domain from EEPROM
Kiet Lam64c1b492013-07-12 13:56:44 +05303488 vos_mem_copy(pMac->scan.countryCodeCurrent, pMac->scan.countryCodeDefault,
3489 WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07003490 csrSetRegulatoryDomain(pMac, pMac->scan.domainIdCurrent, &fRestart);
Jeff Johnson43971f52012-07-17 12:26:56 -07003491 if( ((eANI_BOOLEAN_FALSE == fRestart) || (pfRestartNeeded == NULL) )
3492 && !csrIsInfraConnected(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -07003493 {
3494 //Only reset the country info if we don't need to restart
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003495 csrResetCountryInformation(pMac, eANI_BOOLEAN_TRUE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07003496 }
3497 if(pfRestartNeeded)
3498 {
3499 *pfRestartNeeded = fRestart;
3500 }
3501
3502 return (status);
3503}
3504
3505
3506eHalStatus csrSetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pCountry, tANI_BOOLEAN *pfRestartNeeded)
3507{
3508 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
3509 v_REGDOMAIN_t domainId;
3510
3511 if(pCountry)
3512 {
3513 status = csrGetRegulatoryDomainForCountry(pMac, pCountry, &domainId);
3514 if(HAL_STATUS_SUCCESS(status))
3515 {
3516 status = csrSetRegulatoryDomain(pMac, domainId, pfRestartNeeded);
3517 if(HAL_STATUS_SUCCESS(status))
3518 {
3519 //We don't need to check the pMac->roam.configParam.fEnforceDefaultDomain flag here,
3520 //csrSetRegulatoryDomain will fail if the country doesn't fit our domain criteria.
Kiet Lam64c1b492013-07-12 13:56:44 +05303521 vos_mem_copy(pMac->scan.countryCodeCurrent, pCountry, WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07003522 if((pfRestartNeeded == NULL) || !(*pfRestartNeeded))
3523 {
3524 //Simply set it to cfg. If we need to restart, restart will apply it to the CFG
3525 csrSetCfgCountryCode(pMac, pCountry);
3526 }
3527 }
3528 }
3529 }
3530
3531 return (status);
3532}
3533
3534
3535
3536//caller allocated memory for pNumChn and pChnPowerInfo
3537//As input, *pNumChn has the size of the array of pChnPowerInfo
3538//Upon return, *pNumChn has the number of channels assigned.
3539void csrGetChannelPowerInfo( tpAniSirGlobal pMac, tDblLinkList *pList,
3540 tANI_U32 *pNumChn, tChannelListWithPower *pChnPowerInfo)
3541{
3542 tListElem *pEntry;
3543 tANI_U32 chnIdx = 0, idx;
3544 tCsrChannelPowerInfo *pChannelSet;
3545
3546 //Get 2.4Ghz first
3547 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
3548 while( pEntry && (chnIdx < *pNumChn) )
3549 {
3550 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3551 if ( 1 != pChannelSet->interChannelOffset )
3552 {
3553 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
3554 {
3555 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
3556 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
3557 }
3558 }
3559 else
3560 {
3561 for( idx = 0; (idx < pChannelSet->numChannels) && (chnIdx < *pNumChn); idx++ )
3562 {
3563 pChnPowerInfo[chnIdx].chanId = (tANI_U8)(pChannelSet->firstChannel + idx);
3564 pChnPowerInfo[chnIdx++].pwr = pChannelSet->txPower;
3565 }
3566 }
3567
3568 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
3569 }
3570 *pNumChn = chnIdx;
3571
3572 return ;
3573}
3574
3575
3576
3577void csrApplyCountryInformation( tpAniSirGlobal pMac, tANI_BOOLEAN fForce )
3578{
3579 v_REGDOMAIN_t domainId;
3580 eHalStatus status = eHAL_STATUS_SUCCESS;
3581
3582 do
3583 {
3584 if( !csrIs11dSupported( pMac ) || 0 == pMac->scan.channelOf11dInfo) break;
3585 if( pMac->scan.fAmbiguous11dInfoFound )
3586 {
3587 // ambiguous info found
3588 //Restore te default domain as well
3589 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry( pMac, pMac->scan.countryCodeCurrent, &domainId )))
3590 {
3591 pMac->scan.domainIdCurrent = domainId;
3592 }
3593 else
3594 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003595 smsLog(pMac, LOGE, FL(" failed to get domain from currentCountryCode %02X%02X"),
Jeff Johnson295189b2012-06-20 16:38:30 -07003596 pMac->scan.countryCodeCurrent[0], pMac->scan.countryCodeCurrent[1]);
3597 }
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003598 csrResetCountryInformation( pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE );
Jeff Johnson295189b2012-06-20 16:38:30 -07003599 break;
3600 }
3601 if ( pMac->scan.f11dInfoApplied && !fForce ) break;
3602 if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry( pMac, pMac->scan.countryCode11d, &domainId )))
3603 {
3604 //Check whether we need to enforce default domain
3605 if( ( !pMac->roam.configParam.fEnforceDefaultDomain ) ||
3606 (pMac->scan.domainIdCurrent == domainId) )
3607 {
3608
3609#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3610 {
3611 vos_log_802_11d_pkt_type *p11dLog;
3612 tChannelListWithPower chnPwrInfo[WNI_CFG_VALID_CHANNEL_LIST_LEN];
3613 tANI_U32 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN, nTmp;
3614
3615 WLAN_VOS_DIAG_LOG_ALLOC(p11dLog, vos_log_802_11d_pkt_type, LOG_WLAN_80211D_C);
3616 if(p11dLog)
3617 {
3618 p11dLog->eventId = WLAN_80211D_EVENT_COUNTRY_SET;
Kiet Lam64c1b492013-07-12 13:56:44 +05303619 vos_mem_copy(p11dLog->countryCode, pMac->scan.countryCode11d, 3);
Jeff Johnson295189b2012-06-20 16:38:30 -07003620 p11dLog->numChannel = pMac->scan.channels11d.numChannels;
3621 if(p11dLog->numChannel <= VOS_LOG_MAX_NUM_CHANNEL)
3622 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303623 vos_mem_copy(p11dLog->Channels,
3624 pMac->scan.channels11d.channelList,
3625 p11dLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07003626 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList24,
3627 &nChnInfo, chnPwrInfo);
3628 nTmp = nChnInfo;
3629 nChnInfo = WNI_CFG_VALID_CHANNEL_LIST_LEN - nTmp;
3630 csrGetChannelPowerInfo(pMac, &pMac->scan.channelPowerInfoList5G,
3631 &nChnInfo, &chnPwrInfo[nTmp]);
3632 for(nTmp = 0; nTmp < p11dLog->numChannel; nTmp++)
3633 {
3634 for(nChnInfo = 0; nChnInfo < WNI_CFG_VALID_CHANNEL_LIST_LEN; nChnInfo++)
3635 {
3636 if(p11dLog->Channels[nTmp] == chnPwrInfo[nChnInfo].chanId)
3637 {
3638 p11dLog->TxPwr[nTmp] = chnPwrInfo[nChnInfo].pwr;
3639 break;
3640 }
3641 }
3642 }
3643 }
3644 if(!pMac->roam.configParam.Is11dSupportEnabled)
3645 {
3646 p11dLog->supportMultipleDomain = WLAN_80211D_DISABLED;
3647 }
3648 else if(pMac->roam.configParam.fEnforceDefaultDomain)
3649 {
3650 p11dLog->supportMultipleDomain = WLAN_80211D_NOT_SUPPORT_MULTI_DOMAIN;
3651 }
3652 else
3653 {
3654 p11dLog->supportMultipleDomain = WLAN_80211D_SUPPORT_MULTI_DOMAIN;
3655 }
3656 WLAN_VOS_DIAG_LOG_REPORT(p11dLog);
3657 }
3658 }
3659#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
3660 if(pMac->scan.domainIdCurrent != domainId)
3661 {
Jeff Johnson295189b2012-06-20 16:38:30 -07003662 smsLog(pMac, LOGW, FL("Domain Changed Old %d, new %d"),
3663 pMac->scan.domainIdCurrent, domainId);
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +05303664 status = WDA_SetRegDomain(pMac, domainId);
Jeff Johnson295189b2012-06-20 16:38:30 -07003665 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003666 if (status != eHAL_STATUS_SUCCESS)
3667 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003668 smsLog( pMac, LOGE, FL(" fail to set regId %d"), domainId );
Jeff Johnson295189b2012-06-20 16:38:30 -07003669 }
3670 pMac->scan.domainIdCurrent = domainId;
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08003671 csrApplyChannelPowerCountryInfo( pMac, &pMac->scan.channels11d, pMac->scan.countryCode11d, eANI_BOOLEAN_TRUE );
Jeff Johnson295189b2012-06-20 16:38:30 -07003672 // switch to active scans using this new channel list
3673 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
3674 pMac->scan.f11dInfoApplied = eANI_BOOLEAN_TRUE;
3675 pMac->scan.f11dInfoReset = eANI_BOOLEAN_FALSE;
3676 }
3677 }
3678
3679 } while( 0 );
3680
3681 return;
3682}
3683
3684
3685
3686tANI_BOOLEAN csrSave11dCountryString( tpAniSirGlobal pMac, tANI_U8 *pCountryCode,
3687 tANI_BOOLEAN fForce)
3688{
3689 tANI_BOOLEAN fCountryStringChanged = FALSE, fUnknownCountryCode = FALSE;
3690 tANI_U32 i;
3691
3692 // convert to UPPER here so we are assured the strings are always in upper case.
3693 for( i = 0; i < 3; i++ )
3694 {
3695 pCountryCode[ i ] = (tANI_U8)csrToUpper( pCountryCode[ i ] );
3696 }
3697
3698 // Some of the 'old' Cisco 350 series AP's advertise NA as the country code (for North America ??).
3699 // NA is not a valid country code or domain so let's allow this by changing it to the proper
3700 // country code (which is US). We've also seen some NETGEAR AP's that have "XX " as the country code
3701 // with valid 2.4 GHz US channel information. If we cannot find the country code advertised in the
3702 // 11d information element, let's default to US.
3703 if ( !HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry( pMac, pCountryCode, NULL ) ) )
3704 {
3705 // Check the enforcement first
3706 if( pMac->roam.configParam.fEnforceDefaultDomain || pMac->roam.configParam.fEnforceCountryCodeMatch )
3707 {
3708 fUnknownCountryCode = TRUE;
3709 }
3710 else
3711 {
3712 pCountryCode[ 0 ] = 'U';
3713 pCountryCode[ 1 ] = 'S';
3714 }
3715 }
3716
3717 // We've seen some of the AP's improperly put a 0 for the third character of the country code.
3718 // spec says valid charcters are 'O' (for outdoor), 'I' for Indoor, or ' ' (space; for either).
3719 // if we see a 0 in this third character, let's change it to a ' '.
3720 if ( 0 == pCountryCode[ 2 ] )
3721 {
3722 pCountryCode[ 2 ] = ' ';
3723 }
3724
3725 if( !fUnknownCountryCode )
3726 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303727 fCountryStringChanged = (!vos_mem_compare(pMac->scan.countryCode11d, pCountryCode, 2));
Jeff Johnson295189b2012-06-20 16:38:30 -07003728
3729
3730 if(( 0 == pMac->scan.countryCode11d[ 0 ] && 0 == pMac->scan.countryCode11d[ 1 ] )
3731 || (fForce))
3732 {
3733 // this is the first .11d information
Kiet Lam64c1b492013-07-12 13:56:44 +05303734 vos_mem_copy(pMac->scan.countryCode11d, pCountryCode,
3735 sizeof( pMac->scan.countryCode11d ));
Jeff Johnson295189b2012-06-20 16:38:30 -07003736 }
3737 }
3738
3739 return( fCountryStringChanged );
3740}
3741
3742
3743void csrSaveChannelPowerForBand( tpAniSirGlobal pMac, tANI_BOOLEAN fPopulate5GBand )
3744{
3745 tANI_U32 Index, count=0;
3746 tSirMacChanInfo *pChanInfo;
3747 tSirMacChanInfo *pChanInfoStart;
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08003748 tANI_S32 maxChannelIndex;
3749
3750 maxChannelIndex = ( pMac->scan.base20MHzChannels.numChannels < WNI_CFG_VALID_CHANNEL_LIST_LEN ) ?
3751 pMac->scan.base20MHzChannels.numChannels : WNI_CFG_VALID_CHANNEL_LIST_LEN ;
Jeff Johnson295189b2012-06-20 16:38:30 -07003752
Kiet Lam64c1b492013-07-12 13:56:44 +05303753 pChanInfo = vos_mem_malloc(sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN);
3754 if ( NULL != pChanInfo )
Jeff Johnson295189b2012-06-20 16:38:30 -07003755 {
Kiet Lam64c1b492013-07-12 13:56:44 +05303756 vos_mem_set(pChanInfo, sizeof(tSirMacChanInfo) * WNI_CFG_VALID_CHANNEL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003757 pChanInfoStart = pChanInfo;
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08003758 for (Index=0; Index < maxChannelIndex; Index++)
Jeff Johnson295189b2012-06-20 16:38:30 -07003759 {
3760 if ((fPopulate5GBand && (CSR_IS_CHANNEL_5GHZ(pMac->scan.defaultPowerTable[Index].chanId))) ||
3761 (!fPopulate5GBand && (CSR_IS_CHANNEL_24GHZ(pMac->scan.defaultPowerTable[Index].chanId))) )
3762 {
Leela V Kiran Kumar Reddy Chirala6a458752013-02-16 15:41:27 -08003763 if(count >= WNI_CFG_VALID_CHANNEL_LIST_LEN)
3764 {
3765 smsLog( pMac, LOGW, FL(" csrSaveChannelPowerForBand, count exceeded, count = %d"), count);
3766 break;
3767 }
Jeff Johnson295189b2012-06-20 16:38:30 -07003768 pChanInfo->firstChanNum = pMac->scan.defaultPowerTable[Index].chanId;
3769 pChanInfo->numChannels = 1;
3770 pChanInfo->maxTxPower = CSR_ROAM_MIN( pMac->scan.defaultPowerTable[Index].pwr, pMac->roam.configParam.nTxPowerCap );
3771 pChanInfo++;
3772 count++;
3773 }
3774 }
3775 if(count)
3776 {
3777 csrSaveToChannelPower2G_5G( pMac, count * sizeof(tSirMacChanInfo), pChanInfoStart );
3778 }
Kiet Lam64c1b492013-07-12 13:56:44 +05303779 vos_mem_free(pChanInfoStart);
Jeff Johnson295189b2012-06-20 16:38:30 -07003780 }
3781}
3782
3783
3784void csrSetOppositeBandChannelInfo( tpAniSirGlobal pMac )
3785{
3786 tANI_BOOLEAN fPopulate5GBand = FALSE;
3787
3788 do
3789 {
3790 // if this is not a dual band product, then we don't need to set the opposite
3791 // band info. We only work in one band so no need to look in the other band.
3792 if ( !CSR_IS_OPEARTING_DUAL_BAND( pMac ) ) break;
3793 // if we found channel info on the 5.0 band and...
3794 if ( CSR_IS_CHANNEL_5GHZ( pMac->scan.channelOf11dInfo ) )
3795 {
3796 // and the 2.4 band is empty, then populate the 2.4 channel info
Jeff Johnson295189b2012-06-20 16:38:30 -07003797 fPopulate5GBand = FALSE;
3798 }
3799 else
3800 {
3801 // else, we found channel info in the 2.4 GHz band. If the 5.0 band is empty
3802 // set the 5.0 band info from the 2.4 country code.
Jeff Johnson295189b2012-06-20 16:38:30 -07003803 fPopulate5GBand = TRUE;
3804 }
3805 csrSaveChannelPowerForBand( pMac, fPopulate5GBand );
3806
3807 } while( 0 );
3808}
3809
3810
3811tANI_BOOLEAN csrIsSupportedChannel(tpAniSirGlobal pMac, tANI_U8 channelId)
3812{
3813 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
3814 tANI_U32 i;
3815
3816 //Make sure it is a channel that is in our supported list.
3817 for ( i = 0; i < pMac->scan.baseChannels.numChannels; i++ )
3818 {
3819 if ( channelId == pMac->scan.baseChannels.channelList[i] )
3820 {
3821 fRet = eANI_BOOLEAN_TRUE;
3822 break;
3823 }
3824 }
3825
3826 //If it is configured to limit a set of the channels
3827 if( fRet && pMac->roam.configParam.fEnforce11dChannels )
3828 {
3829 fRet = eANI_BOOLEAN_FALSE;
3830 for ( i = 0; i < pMac->scan.base20MHzChannels.numChannels; i++ )
3831 {
3832 if ( channelId == pMac->scan.base20MHzChannels.channelList[i] )
3833 {
3834 fRet = eANI_BOOLEAN_TRUE;
3835 break;
3836 }
3837 }
3838 }
3839
3840 return (fRet);
3841}
3842
3843
3844
3845//bSize specify the buffer size of pChannelList
3846tANI_U8 csrGetChannelListFromChannelSet( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 bSize, tCsrChannelPowerInfo *pChannelSet )
3847{
3848 tANI_U8 i, j = 0, chnId;
3849
3850 bSize = CSR_MIN(bSize, pChannelSet->numChannels);
3851 for( i = 0; i < bSize; i++ )
3852 {
3853 chnId = (tANI_U8)(pChannelSet->firstChannel + ( i * pChannelSet->interChannelOffset ));
3854 if ( csrIsSupportedChannel( pMac, chnId ) )
3855 {
3856 pChannelList[j++] = chnId;
3857 }
3858 }
3859
3860 return (j);
3861}
3862
3863
3864
3865//bSize -- specify the buffer size of pChannelList
3866void csrConstructCurrentValidChannelList( tpAniSirGlobal pMac, tDblLinkList *pChannelSetList,
3867 tANI_U8 *pChannelList, tANI_U8 bSize, tANI_U8 *pNumChannels )
3868{
3869 tListElem *pEntry;
3870 tCsrChannelPowerInfo *pChannelSet;
3871 tANI_U8 numChannels;
3872 tANI_U8 *pChannels;
3873
3874 if( pChannelSetList && pChannelList && pNumChannels )
3875 {
3876 pChannels = pChannelList;
3877 *pNumChannels = 0;
3878 pEntry = csrLLPeekHead( pChannelSetList, LL_ACCESS_LOCK );
3879 while( pEntry )
3880 {
3881 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
3882 numChannels = csrGetChannelListFromChannelSet( pMac, pChannels, bSize, pChannelSet );
3883 pChannels += numChannels;
3884 *pNumChannels += numChannels;
3885 pEntry = csrLLNext( pChannelSetList, pEntry, LL_ACCESS_LOCK );
3886 }
3887 }
3888}
3889
3890
3891/*
3892 * 802.11D only: Gather 11d IE via beacon or Probe response and store them in pAdapter->channels11d
3893*/
3894tANI_BOOLEAN csrLearnCountryInformation( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc,
3895 tDot11fBeaconIEs *pIes, tANI_BOOLEAN fForce)
3896{
3897 tANI_U8 Num2GChannels, bMaxNumChn;
3898 eHalStatus status;
3899 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
3900 v_REGDOMAIN_t domainId;
3901 tDot11fBeaconIEs *pIesLocal = pIes;
3902
Jeff Johnson295189b2012-06-20 16:38:30 -07003903 if (VOS_STA_SAP_MODE == vos_get_conparam ())
3904 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07003905
3906 do
3907 {
3908 // check if .11d support is enabled
3909 if( !csrIs11dSupported( pMac ) ) break;
3910 if( !pIesLocal && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc, &pIesLocal))) )
3911 {
3912 break;
3913 }
3914 // check if country information element is present
3915 if(!pIesLocal->Country.present)
3916 {
3917 //No country info
3918 break;
3919 }
3920
3921 if( csrSave11dCountryString( pMac, pIesLocal->Country.country, fForce ) )
3922 {
3923 // country string changed, this should not happen
3924 //Need to check whether we care about this BSS' domain info
3925 //If it doesn't match of the connected profile or roaming profile, let's ignore it
3926 tANI_U32 i;
3927 tCsrRoamSession *pSession;
3928
3929 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
3930 {
3931 if( CSR_IS_SESSION_VALID( pMac, i ) )
3932 {
3933 pSession = CSR_GET_SESSION( pMac, i );
3934 if(pSession->pCurRoamProfile)
3935 {
3936 tCsrScanResultFilter filter;
3937
Kiet Lam64c1b492013-07-12 13:56:44 +05303938 vos_mem_set(&filter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07003939 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, &filter);
3940 if(HAL_STATUS_SUCCESS(status))
3941 {
3942 tANI_BOOLEAN fMatch = csrMatchBSS(pMac, pSirBssDesc, &filter, NULL, NULL, NULL, NULL);
3943 //Free the resource first
3944 csrFreeScanFilter( pMac, &filter );
3945 if(fMatch)
3946 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003947 smsLog(pMac, LOGW, " Matching roam profile BSSID %02X-%02X-%02X-%02X-%02X-%02X causing ambiguous domain info",
Jeff Johnson295189b2012-06-20 16:38:30 -07003948 pSirBssDesc->bssId[0], pSirBssDesc->bssId[1], pSirBssDesc->bssId[2],
3949 pSirBssDesc->bssId[3], pSirBssDesc->bssId[4], pSirBssDesc->bssId[5]);
3950 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_TRUE;
3951 break;
3952 }
3953 }
3954 }
3955 else if( csrIsConnStateConnected(pMac, i))
3956 {
3957 //Reach here only when the currention is base on no profile.
3958 //User doesn't give profile and just connect to anything.
3959 if(csrMatchBSSToConnectProfile(pMac, &pSession->connectedProfile, pSirBssDesc, pIesLocal))
3960 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08003961 smsLog(pMac, LOGW, " Matching connect profile BSSID %02X-%02X-%02X-%02X-%02X-%02X causing ambiguous domain info",
Jeff Johnson295189b2012-06-20 16:38:30 -07003962 pSirBssDesc->bssId[0], pSirBssDesc->bssId[1], pSirBssDesc->bssId[2],
3963 pSirBssDesc->bssId[3], pSirBssDesc->bssId[4], pSirBssDesc->bssId[5]);
3964 //Tush
3965 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_TRUE;
3966 if(csrIsBssidMatch(pMac, (tCsrBssid *)&pSirBssDesc->bssId,
3967 &pSession->connectedProfile.bssid))
3968 {
3969 //AP changed the 11d info on the fly, modify cfg
3970 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
3971 fRet = eANI_BOOLEAN_TRUE;
3972 }
3973 break;
3974 }
3975 }
3976 } //valid session
3977 } //for
3978 if ( i == CSR_ROAM_SESSION_MAX )
3979 {
3980 //Check whether we can use this country's 11d information
3981 if( !pMac->roam.configParam.fEnforceDefaultDomain )
3982 {
3983 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_TRUE;
3984 }
3985 else
3986 {
3987 VOS_ASSERT( pMac->scan.domainIdCurrent == pMac->scan.domainIdDefault );
3988 if( HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(
3989 pMac, pIesLocal->Country.country, &domainId )) &&
3990 ( domainId == pMac->scan.domainIdCurrent ) )
3991 {
3992 //Two countries in the same domain
3993 }
3994 }
3995 }
3996 }
3997 else //Tush
3998 {
3999 pMac->scan.fCurrent11dInfoMatch = eANI_BOOLEAN_TRUE;
4000 }
4001
4002 //In case that some channels in 5GHz have the same channel number as 2.4GHz (<= 14)
4003 if(CSR_IS_CHANNEL_5GHZ(pSirBssDesc->channelId))
4004 {
4005 tANI_U8 iC;
4006 tSirMacChanInfo* pMacChnSet = (tSirMacChanInfo *)(&pIesLocal->Country.triplets[0]);
4007
4008 for(iC = 0; iC < pIesLocal->Country.num_triplets; iC++)
4009 {
4010 if(CSR_IS_CHANNEL_24GHZ(pMacChnSet[iC].firstChanNum))
4011 {
4012 pMacChnSet[iC].firstChanNum += 200; //*** Where is this 200 defined?
4013 }
4014 }
4015 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004016 smsLog(pMac, LOG3, FL(" %d sets each one is %d"), pIesLocal->Country.num_triplets, sizeof(tSirMacChanInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07004017 // save the channel/power information from the Channel IE.
4018 //sizeof(tSirMacChanInfo) has to be 3
Jeff Johnsone7245742012-09-05 17:12:55 -07004019 if (eHAL_STATUS_SUCCESS != csrSaveToChannelPower2G_5G( pMac, pIesLocal->Country.num_triplets * sizeof(tSirMacChanInfo),
4020 (tSirMacChanInfo *)(&pIesLocal->Country.triplets[0]) ))
4021 {
4022 fRet = eANI_BOOLEAN_FALSE;
Kiet Lamb537cfb2013-11-07 12:56:49 +05304023 break;
Jeff Johnsone7245742012-09-05 17:12:55 -07004024 }
4025
Jeff Johnson295189b2012-06-20 16:38:30 -07004026 // set the indicator of the channel where the country IE was found...
4027 pMac->scan.channelOf11dInfo = pSirBssDesc->channelId;
Venkata Prathyusha Kuntupalli316247e2013-03-15 17:45:25 -07004028 csrGetRegulatoryDomainForCountry(pMac, pIesLocal->Country.country, &domainId );
4029 // Checking for Domain Id change
4030 if ( domainId != pMac->scan.domainIdCurrent )
4031 {
4032 tSirMacChanInfo* pMacChnSet = (tSirMacChanInfo *)(&pIesLocal->Country.triplets[0]);
Madan Mohan Koyyalamudi0e5922d2013-09-10 15:45:24 +05304033 palCopyMemory( pMac->hHdd, pMac->scan.countryCode11d, pIesLocal->Country.country,
4034 sizeof( pMac->scan.countryCode11d ) );
4035 csrSetCfgCountryCode(pMac, pIesLocal->Country.country);
4036 WDA_SetRegDomain(pMac, domainId);
4037 pMac->scan.domainIdCurrent = domainId;
Madan Mohan Koyyalamudi71278262013-04-12 22:00:48 +05304038 // Check whether AP provided the 2.4GHZ list or 5GHZ list
Venkata Prathyusha Kuntupalli316247e2013-03-15 17:45:25 -07004039 if(CSR_IS_CHANNEL_24GHZ(pMacChnSet[0].firstChanNum))
4040 {
4041 // AP Provided the 2.4 Channels, Update the 5GHz channels from nv.bin
4042 csrGet5GChannels(pMac );
4043 }
4044 else
4045 {
4046 // AP Provided the 5G Channels, Update the 2.4GHZ channel list from nv.bin
4047 csrGet24GChannels(pMac );
4048 }
4049 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004050 // Populate both band channel lists based on what we found in the country information...
4051 csrSetOppositeBandChannelInfo( pMac );
4052 bMaxNumChn = WNI_CFG_VALID_CHANNEL_LIST_LEN;
4053 // construct 2GHz channel list first
4054 csrConstructCurrentValidChannelList( pMac, &pMac->scan.channelPowerInfoList24, pMac->scan.channels11d.channelList,
4055 bMaxNumChn, &Num2GChannels );
4056 // construct 5GHz channel list now
4057 if(bMaxNumChn > Num2GChannels)
4058 {
4059 csrConstructCurrentValidChannelList( pMac, &pMac->scan.channelPowerInfoList5G, pMac->scan.channels11d.channelList + Num2GChannels,
4060 bMaxNumChn - Num2GChannels,
4061 &pMac->scan.channels11d.numChannels );
4062 }
4063
4064 pMac->scan.channels11d.numChannels += Num2GChannels;
4065 fRet = eANI_BOOLEAN_TRUE;
4066
4067 } while( 0 );
4068
4069 if( !pIes && pIesLocal )
4070 {
4071 //locally allocated
Kiet Lam64c1b492013-07-12 13:56:44 +05304072 vos_mem_free(pIesLocal);
Jeff Johnson295189b2012-06-20 16:38:30 -07004073 }
4074
4075 return( fRet );
4076}
4077
4078
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004079static void csrSaveScanResults( tpAniSirGlobal pMac, tANI_U8 reason )
Jeff Johnson295189b2012-06-20 16:38:30 -07004080{
4081 // initialize this to FALSE. profMoveInterimScanResultsToMainList() routine
4082 // will set this to the channel where an .11d beacon is seen
4083 pMac->scan.channelOf11dInfo = 0;
4084 // if we get any ambiguous .11d information then this will be set to TRUE
4085 pMac->scan.fAmbiguous11dInfoFound = eANI_BOOLEAN_FALSE;
4086 //Tush
4087 // if we get any ambiguous .11d information, then this will be set to TRUE
4088 // only if the applied 11d info could be found in one of the scan results
4089 pMac->scan.fCurrent11dInfoMatch = eANI_BOOLEAN_FALSE;
4090 // move the scan results from interim list to the main scan list
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004091 csrMoveTempScanResultsToMainList( pMac, reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07004092
4093 // Now check if we gathered any domain/country specific information
4094 // If so, we should update channel list and apply Tx power settings
Jeff Johnsone7245742012-09-05 17:12:55 -07004095 if( csrIs11dSupported(pMac) )
4096 {
4097 csrApplyCountryInformation( pMac, FALSE );
4098 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004099}
4100
4101
4102void csrReinitScanCmd(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4103{
4104 switch (pCommand->u.scanCmd.reason)
4105 {
4106 case eCsrScanSetBGScanParam:
4107 case eCsrScanAbortBgScan:
4108 if(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList)
4109 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304110 vos_mem_free(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList);
Jeff Johnson295189b2012-06-20 16:38:30 -07004111 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
4112 }
4113 break;
4114 case eCsrScanBGScanAbort:
4115 case eCsrScanBGScanEnable:
4116 case eCsrScanGetScanChnInfo:
4117 break;
4118 case eCsrScanAbortNormalScan:
4119 default:
4120 csrScanFreeRequest(pMac, &pCommand->u.scanCmd.u.scanRequest);
4121 break;
4122 }
4123 if(pCommand->u.scanCmd.pToRoamProfile)
4124 {
4125 csrReleaseProfile(pMac, pCommand->u.scanCmd.pToRoamProfile);
Kiet Lam64c1b492013-07-12 13:56:44 +05304126 vos_mem_free(pCommand->u.scanCmd.pToRoamProfile);
Jeff Johnson295189b2012-06-20 16:38:30 -07004127 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304128 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004129}
4130
4131
4132tANI_BOOLEAN csrGetRemainingChannelsFor11dScan( tpAniSirGlobal pMac, tANI_U8 *pChannels, tANI_U8 *pcChannels )
4133{
4134 tANI_U32 index11dChannels, index;
4135 tANI_U32 indexCurrentChannels;
4136 tANI_BOOLEAN fChannelAlreadyScanned;
4137 tANI_U32 len = sizeof(pMac->roam.validChannelList);
4138
4139 *pcChannels = 0;
4140 if ( CSR_IS_11D_INFO_FOUND(pMac) && csrRoamIsChannelValid(pMac, pMac->scan.channelOf11dInfo) )
4141 {
4142 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
4143 {
4144 //Find the channel index where we found the 11d info
4145 for(index = 0; index < len; index++)
4146 {
4147 if(pMac->scan.channelOf11dInfo == pMac->roam.validChannelList[index])
4148 break;
4149 }
4150 //check whether we found the channel index
4151 if(index < len)
4152 {
4153 // Now, look through the 11d channel list and create a list of all channels in the 11d list that are
4154 // NOT in the current channel list. This gives us a list of the new channels that have not been
4155 // scanned. We'll scan this new list so we have a complete set of scan results on all of the domain channels
4156 // initially.
4157 for ( index11dChannels = 0; index11dChannels < pMac->scan.channels11d.numChannels; index11dChannels++ )
4158 {
4159 fChannelAlreadyScanned = eANI_BOOLEAN_FALSE;
4160
4161 for( indexCurrentChannels = 0; indexCurrentChannels < index; indexCurrentChannels++ )
4162 {
4163 if ( pMac->roam.validChannelList[ indexCurrentChannels ] == pMac->scan.channels11d.channelList[ index11dChannels ] )
4164 {
4165 fChannelAlreadyScanned = eANI_BOOLEAN_TRUE;
4166 break;
4167 }
4168 }
4169
4170 if ( !fChannelAlreadyScanned )
4171 {
4172 pChannels[ *pcChannels ] = pMac->scan.channels11d.channelList[ index11dChannels ];
4173 ( *pcChannels )++;
4174 }
4175 }
4176 }
4177 }//GetCFG
4178 }
4179 return( *pcChannels );
4180}
4181
4182
4183eCsrScanCompleteNextCommand csrScanGetNextCommandState( tpAniSirGlobal pMac, tSmeCmd *pCommand, tANI_BOOLEAN fSuccess )
4184{
4185 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
4186
4187 switch( pCommand->u.scanCmd.reason )
4188 {
4189 case eCsrScan11d1:
4190 NextCommand = (fSuccess) ? eCsrNext11dScan1Success : eCsrNext11dScan1Failure;
4191 break;
4192 case eCsrScan11d2:
4193 NextCommand = (fSuccess) ? eCsrNext11dScan2Success : eCsrNext11dScan2Failure;
4194 break;
4195 case eCsrScan11dDone:
4196 NextCommand = eCsrNext11dScanComplete;
4197 break;
4198 case eCsrScanLostLink1:
4199 NextCommand = (fSuccess) ? eCsrNextLostLinkScan1Success : eCsrNextLostLinkScan1Failed;
4200 break;
4201 case eCsrScanLostLink2:
4202 NextCommand = (fSuccess) ? eCsrNextLostLinkScan2Success : eCsrNextLostLinkScan2Failed;
4203 break;
4204 case eCsrScanLostLink3:
4205 NextCommand = (fSuccess) ? eCsrNextLostLinkScan3Success : eCsrNextLostLinkScan3Failed;
4206 break;
4207 case eCsrScanForSsid:
4208 NextCommand = (fSuccess) ? eCsrNexteScanForSsidSuccess : eCsrNexteScanForSsidFailure;
4209 break;
4210 case eCsrScanForCapsChange:
4211 NextCommand = eCsrNextCapChangeScanComplete; //don't care success or not
4212 break;
4213 case eCsrScanIdleScan:
4214 NextCommand = eCsrNextIdleScanComplete;
4215 break;
4216 default:
4217 NextCommand = eCsrNextScanNothing;
4218 break;
4219 }
4220 return( NextCommand );
4221}
4222
4223
4224//Return whether the pCommand is finished.
4225tANI_BOOLEAN csrHandleScan11d1Failure(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4226{
4227 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
4228
4229 //Apply back the default setting and passively scan one more time.
Gopichand Nakkalab9185f22012-12-21 08:03:42 -08004230 csrResetCountryInformation(pMac, eANI_BOOLEAN_FALSE, eANI_BOOLEAN_TRUE);
Jeff Johnson295189b2012-06-20 16:38:30 -07004231 pCommand->u.scanCmd.reason = eCsrScan11d2;
4232 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
4233 {
4234 fRet = eANI_BOOLEAN_FALSE;
4235 }
4236
4237 return (fRet);
4238}
4239
4240
4241tANI_BOOLEAN csrHandleScan11dSuccess(tpAniSirGlobal pMac, tSmeCmd *pCommand)
4242{
4243 tANI_BOOLEAN fRet = eANI_BOOLEAN_TRUE;
4244 tANI_U8 *pChannels;
4245 tANI_U8 cChannels;
4246
Kiet Lam64c1b492013-07-12 13:56:44 +05304247 pChannels = vos_mem_malloc(WNI_CFG_VALID_CHANNEL_LIST_LEN);
4248 if ( NULL != pChannels )
Jeff Johnson295189b2012-06-20 16:38:30 -07004249 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304250 vos_mem_set(pChannels, WNI_CFG_VALID_CHANNEL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004251 if ( csrGetRemainingChannelsFor11dScan( pMac, pChannels, &cChannels ) )
4252 {
4253 pCommand->u.scanCmd.reason = eCsrScan11dDone;
4254 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
4255 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304256 vos_mem_free(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -07004257 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07004258 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304259 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(cChannels);
4260 if ( NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07004261 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304262 vos_mem_copy(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
4263 pChannels, cChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07004264 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = cChannels;
4265 pCommand->u.scanCmd.u.scanRequest.requestType = eCSR_SCAN_REQUEST_FULL_SCAN;
4266 pCommand->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
4267 if(HAL_STATUS_SUCCESS(csrScanChannels(pMac, pCommand)))
4268 {
4269 //Reuse the same command buffer
4270 fRet = eANI_BOOLEAN_FALSE;
4271 }
4272 }
4273 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304274 vos_mem_free(pChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07004275 }
4276
4277 return (fRet);
4278}
4279
4280//Return whether the command should be removed
4281tANI_BOOLEAN csrScanComplete( tpAniSirGlobal pMac, tSirSmeScanRsp *pScanRsp )
4282{
4283 eCsrScanCompleteNextCommand NextCommand = eCsrNextScanNothing;
4284 tListElem *pEntry;
4285 tSmeCmd *pCommand;
4286 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
4287 tANI_BOOLEAN fSuccess;
4288
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05304289 if (pMac->fScanOffload)
4290 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
4291 else
4292 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07004293
4294 if ( pEntry )
4295 {
4296 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
4297
4298 // If the head of the queue is Active and it is a SCAN command, remove
4299 // and put this on the Free queue.
4300 if ( eSmeCommandScan == pCommand->command )
4301 {
4302 tANI_U32 sessionId = pCommand->sessionId;
4303
4304 if(eSIR_SME_SUCCESS != pScanRsp->statusCode)
4305 {
4306 fSuccess = eANI_BOOLEAN_FALSE;
4307 }
4308 else
4309 {
4310 //pMac->scan.tempScanResults is not empty meaning the scan found something
4311 //This check only valid here because csrSaveScanresults is not yet called
4312 fSuccess = (!csrLLIsListEmpty(&pMac->scan.tempScanResults, LL_ACCESS_LOCK));
4313 }
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004314 csrSaveScanResults(pMac, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07004315
4316#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4317 {
4318 vos_log_scan_pkt_type *pScanLog = NULL;
4319 tScanResultHandle hScanResult;
4320 tCsrScanResultInfo *pScanResult;
4321 tDot11fBeaconIEs *pIes;
4322 int n = 0, c = 0;
4323
4324 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
4325 if(pScanLog)
4326 {
4327 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
4328 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
4329 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
4330 {
4331 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_RSP;
4332 }
4333 else
4334 {
4335 if( eSIR_PASSIVE_SCAN != pMac->scan.curScanType )
4336 {
4337 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_RSP;
4338 }
4339 else
4340 {
4341 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_RSP;
4342 }
4343 }
4344 if(eSIR_SME_SUCCESS == pScanRsp->statusCode)
4345 {
4346 if(HAL_STATUS_SUCCESS(csrScanGetResult(pMac, NULL, &hScanResult)))
4347 {
4348 while(((pScanResult = csrScanResultGetNext(pMac, hScanResult)) != NULL))
4349 {
4350 if( n < VOS_LOG_MAX_NUM_BSSID )
4351 {
4352 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, &pScanResult->BssDescriptor, &pIes)))
4353 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004354 smsLog(pMac, LOGE, FL(" fail to parse IEs"));
Jeff Johnson295189b2012-06-20 16:38:30 -07004355 break;
4356 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304357 vos_mem_copy(pScanLog->bssid[n],
4358 pScanResult->BssDescriptor.bssId, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07004359 if(pIes && pIes->SSID.present && VOS_LOG_MAX_SSID_SIZE >= pIes->SSID.num_ssid)
4360 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304361 vos_mem_copy(pScanLog->ssid[n],
4362 pIes->SSID.ssid, pIes->SSID.num_ssid);
Jeff Johnson295189b2012-06-20 16:38:30 -07004363 }
Kiet Lam64c1b492013-07-12 13:56:44 +05304364 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07004365 n++;
4366 }
4367 c++;
4368 }
4369 pScanLog->numSsid = (v_U8_t)n;
4370 pScanLog->totalSsid = (v_U8_t)c;
4371 csrScanResultPurge(pMac, hScanResult);
4372 }
4373 }
4374 else
4375 {
4376 pScanLog->status = WLAN_SCAN_STATUS_FAILURE;
4377 }
4378 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
4379 }
4380 }
4381#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
4382
4383 NextCommand = csrScanGetNextCommandState(pMac, pCommand, fSuccess);
4384 //We reuse the command here instead reissue a new command
4385 switch(NextCommand)
4386 {
4387 case eCsrNext11dScan1Success:
4388 case eCsrNext11dScan2Success:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004389 smsLog( pMac, LOG2, FL("11dScan1/3 produced results. Reissue Active scan..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004390 // if we found country information, no need to continue scanning further, bail out
4391 fRemoveCommand = eANI_BOOLEAN_TRUE;
4392 NextCommand = eCsrNext11dScanComplete;
4393 break;
4394 case eCsrNext11dScan1Failure:
4395 //We are not done yet. 11d scan fail once. We will try to reset anything and do it over again
4396 //The only meaningful thing for this retry is that we cannot find 11d information after a reset so
4397 //we clear the "old" 11d info and give it once more chance
4398 fRemoveCommand = csrHandleScan11d1Failure(pMac, pCommand);
4399 if(fRemoveCommand)
4400 {
4401 NextCommand = eCsrNext11dScanComplete;
4402 }
4403 break;
4404 case eCsrNextLostLinkScan1Success:
4405 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink1)))
4406 {
4407 csrScanHandleFailedLostlink1(pMac, sessionId);
4408 }
4409 break;
4410 case eCsrNextLostLinkScan2Success:
4411 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink2)))
4412 {
4413 csrScanHandleFailedLostlink2(pMac, sessionId);
4414 }
4415 break;
4416 case eCsrNextLostLinkScan3Success:
4417 if(!HAL_STATUS_SUCCESS(csrIssueRoamAfterLostlinkScan(pMac, sessionId, eCsrLostLink3)))
4418 {
4419 csrScanHandleFailedLostlink3(pMac, sessionId);
4420 }
4421 break;
4422 case eCsrNextLostLinkScan1Failed:
4423 csrScanHandleFailedLostlink1(pMac, sessionId);
4424 break;
4425 case eCsrNextLostLinkScan2Failed:
4426 csrScanHandleFailedLostlink2(pMac, sessionId);
4427 break;
4428 case eCsrNextLostLinkScan3Failed:
4429 csrScanHandleFailedLostlink3(pMac, sessionId);
4430 break;
4431 case eCsrNexteScanForSsidSuccess:
4432 csrScanHandleSearchForSSID(pMac, pCommand);
4433 break;
4434 case eCsrNexteScanForSsidFailure:
4435 csrScanHandleSearchForSSIDFailure(pMac, pCommand);
4436 break;
4437 case eCsrNextIdleScanComplete:
4438 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
4439 break;
4440 case eCsrNextCapChangeScanComplete:
4441 csrScanHandleCapChangeScanComplete(pMac, sessionId);
4442 break;
4443 default:
4444
4445 break;
4446 }
4447 }
4448 else
4449 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004450 smsLog( pMac, LOGW, FL("Scan Completion called but SCAN command is not ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004451 fRemoveCommand = eANI_BOOLEAN_FALSE;
4452 }
4453 }
4454 else
4455 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004456 smsLog( pMac, LOGW, FL("Scan Completion called but NO commands are ACTIVE ..."));
Jeff Johnson295189b2012-06-20 16:38:30 -07004457 fRemoveCommand = eANI_BOOLEAN_FALSE;
4458 }
4459
4460 return( fRemoveCommand );
4461}
4462
4463
4464
4465static void csrScanRemoveDupBssDescriptionFromInterimList( tpAniSirGlobal pMac,
4466 tSirBssDescription *pSirBssDescr,
4467 tDot11fBeaconIEs *pIes)
4468{
4469 tListElem *pEntry;
4470 tCsrScanResult *pCsrBssDescription;
4471
4472 // Walk through all the chained BssDescriptions. If we find a chained BssDescription that
4473 // matches the BssID of the BssDescription passed in, then these must be duplicate scan
4474 // results for this Bss. In that case, remove the 'old' Bss description from the linked list.
4475 pEntry = csrLLPeekHead( &pMac->scan.tempScanResults, LL_ACCESS_LOCK );
4476 while( pEntry )
4477 {
4478 pCsrBssDescription = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
4479
4480 // we have a duplicate scan results only when BSSID, SSID, Channel and NetworkType
4481 // matches
4482
4483 if ( csrIsDuplicateBssDescription( pMac, &pCsrBssDescription->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07004484 pSirBssDescr, pIes, FALSE ) )
Jeff Johnson295189b2012-06-20 16:38:30 -07004485 {
4486 pSirBssDescr->rssi = (tANI_S8)( (((tANI_S32)pSirBssDescr->rssi * CSR_SCAN_RESULT_RSSI_WEIGHT ) +
4487 ((tANI_S32)pCsrBssDescription->Result.BssDescriptor.rssi * (100 - CSR_SCAN_RESULT_RSSI_WEIGHT) )) / 100 );
4488
4489 // Remove the 'old' entry from the list....
4490 if( csrLLRemoveEntry( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK ) )
4491 {
4492 csrCheckNSaveWscIe(pMac, pSirBssDescr, &pCsrBssDescription->Result.BssDescriptor);
4493 // we need to free the memory associated with this node
4494 csrFreeScanResultEntry( pMac, pCsrBssDescription );
4495 }
4496
4497 // If we found a match, we can stop looking through the list.
4498 break;
4499 }
4500
4501 pEntry = csrLLNext( &pMac->scan.tempScanResults, pEntry, LL_ACCESS_LOCK );
4502 }
4503}
4504
4505
4506
4507//Caller allocated memory pfNewBssForConn to return whether new candidate for
4508//current connection is found. Cannot be NULL
4509tCsrScanResult *csrScanSaveBssDescriptionToInterimList( tpAniSirGlobal pMac,
4510 tSirBssDescription *pBSSDescription,
4511 tDot11fBeaconIEs *pIes)
4512{
4513 tCsrScanResult *pCsrBssDescription = NULL;
4514 tANI_U32 cbBSSDesc;
4515 tANI_U32 cbAllocated;
Jeff Johnson295189b2012-06-20 16:38:30 -07004516
4517 // figure out how big the BSS description is (the BSSDesc->length does NOT
4518 // include the size of the length field itself).
4519 cbBSSDesc = pBSSDescription->length + sizeof( pBSSDescription->length );
4520
4521 cbAllocated = sizeof( tCsrScanResult ) + cbBSSDesc;
4522
Kiet Lam64c1b492013-07-12 13:56:44 +05304523 pCsrBssDescription = vos_mem_malloc(cbAllocated);
4524 if ( NULL != pCsrBssDescription )
Jeff Johnson295189b2012-06-20 16:38:30 -07004525 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304526 vos_mem_set(pCsrBssDescription, cbAllocated, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004527 pCsrBssDescription->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
Kiet Lam64c1b492013-07-12 13:56:44 +05304528 vos_mem_copy(&pCsrBssDescription->Result.BssDescriptor, pBSSDescription, cbBSSDesc );
Jeff Johnson295189b2012-06-20 16:38:30 -07004529 //Save SSID separately for later use
4530 if( pIes->SSID.present && !csrIsNULLSSID(pIes->SSID.ssid, pIes->SSID.num_ssid) )
4531 {
4532 //SSID not hidden
Madan Mohan Koyyalamudi4e31b132012-11-02 13:13:52 -07004533 tANI_U32 len = pIes->SSID.num_ssid;
Jeff Johnson295189b2012-06-20 16:38:30 -07004534 if (len > SIR_MAC_MAX_SSID_LENGTH)
4535 {
4536 // truncate to fit in our struct
4537 len = SIR_MAC_MAX_SSID_LENGTH;
4538 }
4539 pCsrBssDescription->Result.ssId.length = len;
4540 pCsrBssDescription->Result.timer = vos_timer_get_system_time();
Kiet Lam64c1b492013-07-12 13:56:44 +05304541 vos_mem_copy(pCsrBssDescription->Result.ssId.ssId, pIes->SSID.ssid, len);
Jeff Johnson295189b2012-06-20 16:38:30 -07004542 }
4543 csrLLInsertTail( &pMac->scan.tempScanResults, &pCsrBssDescription->Link, LL_ACCESS_LOCK );
4544 }
4545
4546 return( pCsrBssDescription );
4547}
4548
4549
4550
4551
4552tANI_BOOLEAN csrIsDuplicateBssDescription( tpAniSirGlobal pMac, tSirBssDescription *pSirBssDesc1,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07004553 tSirBssDescription *pSirBssDesc2, tDot11fBeaconIEs *pIes2, tANI_BOOLEAN fForced )
Jeff Johnson295189b2012-06-20 16:38:30 -07004554{
4555 tANI_BOOLEAN fMatch = FALSE;
4556 tSirMacCapabilityInfo *pCap1, *pCap2;
4557 tDot11fBeaconIEs *pIes1 = NULL;
Jeff Johnsone7245742012-09-05 17:12:55 -07004558 tDot11fBeaconIEs *pIesTemp = pIes2;
Jeff Johnson295189b2012-06-20 16:38:30 -07004559
4560 pCap1 = (tSirMacCapabilityInfo *)&pSirBssDesc1->capabilityInfo;
4561 pCap2 = (tSirMacCapabilityInfo *)&pSirBssDesc2->capabilityInfo;
4562 if(pCap1->ess == pCap2->ess)
4563 {
4564 if (pCap1->ess &&
Jeff Johnsone7245742012-09-05 17:12:55 -07004565 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId)&&
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07004566 (fForced || (pSirBssDesc1->channelId == pSirBssDesc2->channelId)))
Jeff Johnson295189b2012-06-20 16:38:30 -07004567 {
4568 fMatch = TRUE;
Jeff Johnsone7245742012-09-05 17:12:55 -07004569 // Check for SSID match, if exists
4570 do
4571 {
4572 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
4573 {
4574 break;
4575 }
4576 if( NULL == pIesTemp )
4577 {
4578 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
4579 {
4580 break;
4581 }
4582 }
4583 if(pIes1->SSID.present && pIesTemp->SSID.present)
4584 {
4585 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
4586 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
4587 }
4588 }while(0);
4589
Jeff Johnson295189b2012-06-20 16:38:30 -07004590 }
4591 else if (pCap1->ibss && (pSirBssDesc1->channelId == pSirBssDesc2->channelId))
4592 {
Jeff Johnson295189b2012-06-20 16:38:30 -07004593
4594 do
4595 {
4596 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc1, &pIes1)))
4597 {
4598 break;
4599 }
4600 if( NULL == pIesTemp )
4601 {
4602 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac, pSirBssDesc2, &pIesTemp)))
4603 {
4604 break;
4605 }
4606 }
4607 //Same channel cannot have same SSID for different IBSS
4608 if(pIes1->SSID.present && pIesTemp->SSID.present)
4609 {
4610 fMatch = csrIsSsidMatch(pMac, pIes1->SSID.ssid, pIes1->SSID.num_ssid,
4611 pIesTemp->SSID.ssid, pIesTemp->SSID.num_ssid, eANI_BOOLEAN_TRUE);
4612 }
4613 }while(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07004614 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004615 /* In case of P2P devices, ess and ibss will be set to zero */
4616 else if (!pCap1->ess &&
4617 csrIsMacAddressEqual( pMac, (tCsrBssid *)pSirBssDesc1->bssId, (tCsrBssid *)pSirBssDesc2->bssId))
4618 {
4619 fMatch = TRUE;
4620 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004621 }
4622
4623 if(pIes1)
4624 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304625 vos_mem_free(pIes1);
Jeff Johnson295189b2012-06-20 16:38:30 -07004626 }
Jeff Johnsone7245742012-09-05 17:12:55 -07004627
4628 if( (NULL == pIes2) && pIesTemp )
4629 {
4630 //locally allocated
Kiet Lam64c1b492013-07-12 13:56:44 +05304631 vos_mem_free(pIesTemp);
Jeff Johnsone7245742012-09-05 17:12:55 -07004632 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004633
4634 return( fMatch );
4635}
4636
4637
4638tANI_BOOLEAN csrIsNetworkTypeEqual( tSirBssDescription *pSirBssDesc1, tSirBssDescription *pSirBssDesc2 )
4639{
4640 return( pSirBssDesc1->nwType == pSirBssDesc2->nwType );
4641}
4642
4643
4644//to check whether the BSS matches the dot11Mode
4645static tANI_BOOLEAN csrScanIsBssAllowed(tpAniSirGlobal pMac, tSirBssDescription *pBssDesc,
4646 tDot11fBeaconIEs *pIes)
4647{
4648 tANI_BOOLEAN fAllowed = eANI_BOOLEAN_FALSE;
4649 eCsrPhyMode phyMode;
4650
4651 if(HAL_STATUS_SUCCESS(csrGetPhyModeFromBss(pMac, pBssDesc, &phyMode, pIes)))
4652 {
4653 switch(pMac->roam.configParam.phyMode)
4654 {
4655 case eCSR_DOT11_MODE_11b:
4656 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
4657 break;
4658 case eCSR_DOT11_MODE_11g:
4659 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a != phyMode);
4660 break;
4661 case eCSR_DOT11_MODE_11g_ONLY:
4662 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11g == phyMode);
4663 break;
4664 case eCSR_DOT11_MODE_11a:
4665 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11b != phyMode) && (eCSR_DOT11_MODE_11g != phyMode));
4666 break;
4667 case eCSR_DOT11_MODE_11n_ONLY:
4668 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11n == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
4669 break;
Jeff Johnsone7245742012-09-05 17:12:55 -07004670
4671#ifdef WLAN_FEATURE_11AC
4672 case eCSR_DOT11_MODE_11ac_ONLY:
4673 fAllowed = (tANI_BOOLEAN)((eCSR_DOT11_MODE_11ac == phyMode) || (eCSR_DOT11_MODE_TAURUS == phyMode));
4674 break;
4675#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004676 case eCSR_DOT11_MODE_11b_ONLY:
4677 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11b == phyMode);
4678 break;
4679 case eCSR_DOT11_MODE_11a_ONLY:
4680 fAllowed = (tANI_BOOLEAN)(eCSR_DOT11_MODE_11a == phyMode);
4681 break;
4682 case eCSR_DOT11_MODE_11n:
Jeff Johnsone7245742012-09-05 17:12:55 -07004683#ifdef WLAN_FEATURE_11AC
4684 case eCSR_DOT11_MODE_11ac:
4685#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004686 case eCSR_DOT11_MODE_TAURUS:
4687 default:
4688 fAllowed = eANI_BOOLEAN_TRUE;
4689 break;
4690 }
4691 }
4692
4693 return (fAllowed);
4694}
4695
4696
4697
4698//Return pIes to caller for future use when returning TRUE.
4699static tANI_BOOLEAN csrScanValidateScanResult( tpAniSirGlobal pMac, tANI_U8 *pChannels,
4700 tANI_U8 numChn, tSirBssDescription *pBssDesc,
4701 tDot11fBeaconIEs **ppIes )
4702{
4703 tANI_BOOLEAN fValidChannel = FALSE;
4704 tDot11fBeaconIEs *pIes = NULL;
4705 tANI_U8 index;
4706
4707 for( index = 0; index < numChn; index++ )
4708 {
4709 // This check relies on the fact that a single BSS description is returned in each
4710 // ScanRsp call, which is the way LIM implemented the scan req/rsp funtions. We changed
4711 // to this model when we ran with a large number of APs. If this were to change, then
4712 // this check would have to mess with removing the bssDescription from somewhere in an
4713 // arbitrary index in the bssDescription array.
4714 if ( pChannels[ index ] == pBssDesc->channelId )
4715 {
4716 fValidChannel = TRUE;
4717 break;
4718 }
4719 }
4720 *ppIes = NULL;
4721 if(fValidChannel)
4722 {
4723 if( HAL_STATUS_SUCCESS( csrGetParsedBssDescriptionIEs(pMac, pBssDesc, &pIes) ) )
4724 {
4725 fValidChannel = csrScanIsBssAllowed(pMac, pBssDesc, pIes);
4726 if( fValidChannel )
4727 {
4728 *ppIes = pIes;
4729 }
4730 else
4731 {
Kiet Lam64c1b492013-07-12 13:56:44 +05304732 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07004733 }
4734 }
4735 else
4736 {
4737 fValidChannel = FALSE;
4738 }
4739 }
4740
4741 return( fValidChannel );
4742}
4743
4744
4745//Return whether last scan result is received
4746static tANI_BOOLEAN csrScanProcessScanResults( tpAniSirGlobal pMac, tSmeCmd *pCommand,
4747 tSirSmeScanRsp *pScanRsp, tANI_BOOLEAN *pfRemoveCommand )
4748{
4749 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE, fRemoveCommand = eANI_BOOLEAN_FALSE;
4750 tDot11fBeaconIEs *pIes = NULL;
4751 tANI_U32 cbParsed;
4752 tSirBssDescription *pSirBssDescription;
4753 tANI_U32 cbBssDesc;
4754 tANI_U32 cbScanResult = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription )
4755 + sizeof(tSirBssDescription); //We need at least one CB
4756
4757 // don't consider the scan rsp to be valid if the status code is Scan Failure. Scan Failure
4758 // is returned when the scan could not find anything. so if we get scan failure return that
4759 // the scan response is invalid. Also check the lenght in the scan result for valid scan
4760 // BssDescriptions....
4761 do
4762 {
4763 if ( ( cbScanResult <= pScanRsp->length ) &&
4764 (( eSIR_SME_SUCCESS == pScanRsp->statusCode ) ||
4765 ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW == pScanRsp->statusCode ) ) )
4766 {
4767 tANI_U8 *pChannelList = NULL;
4768 tANI_U8 cChannels = 0;
4769
4770 //Different scan type can reach this point, we need to distinguish it
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004771#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
4772 if( eCsrScanGetLfrResult == pCommand->u.scanCmd.reason )
4773 {
4774 pChannelList = NULL;
4775 cChannels = 0;
4776 }
4777 else
4778#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004779 if( eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason )
4780 {
4781 //eCsrScanSetBGScanParam uses different structure
4782 tCsrBGScanRequest *pBgScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
4783
4784 cChannels = pBgScanReq->ChannelInfo.numOfChannels;
4785 pChannelList = pBgScanReq->ChannelInfo.ChannelList;
4786 }
4787 else
4788 {
4789 //the rest use generic scan request
4790 cChannels = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
4791 pChannelList = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
4792 }
4793
4794 // if the scan result is not on one of the channels in the Valid channel list, then it
4795 // must have come from an AP on an overlapping channel (in the 2.4GHz band). In this case,
4796 // let's drop the scan result.
4797 //
4798 // The other situation is where the scan request is for a scan on a particular channel set
4799 // and the scan result is from a
4800
4801 // if the NumChannels is 0, then we are supposed to be scanning all channels. Use the full channel
4802 // list as the 'valid' channel list. Otherwise, use the specific channel list in the scan parms
4803 // as the valid channels.
4804 if ( 0 == cChannels )
4805 {
4806 tANI_U32 len = sizeof(pMac->roam.validChannelList);
4807
4808 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
4809 {
4810 pChannelList = pMac->roam.validChannelList;
4811 cChannels = (tANI_U8)len;
4812 }
4813 else
4814 {
4815 //Cannot continue
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004816 smsLog( pMac, LOGE, "CSR: Processing internal SCAN results...csrGetCfgValidChannels failed" );
Jeff Johnson295189b2012-06-20 16:38:30 -07004817 break;
4818 }
4819 }
4820
4821 smsLog( pMac, LOG2, "CSR: Processing internal SCAN results..." );
4822 cbParsed = GET_FIELD_OFFSET( tSirSmeScanRsp, bssDescription );
4823 pSirBssDescription = pScanRsp->bssDescription;
4824 while( cbParsed < pScanRsp->length )
4825 {
4826 if ( csrScanValidateScanResult( pMac, pChannelList, cChannels, pSirBssDescription, &pIes ) )
4827 {
4828 csrScanRemoveDupBssDescriptionFromInterimList(pMac, pSirBssDescription, pIes);
4829 csrScanSaveBssDescriptionToInterimList( pMac, pSirBssDescription, pIes );
4830 if( eSIR_PASSIVE_SCAN == pMac->scan.curScanType )
4831 {
4832 if( csrIs11dSupported( pMac) )
4833 {
4834 //Check whether the BSS is acceptable base on 11d info and our configs.
4835 if( csrMatchCountryCode( pMac, NULL, pIes ) )
4836 {
4837 //Double check whether the channel is acceptable by us.
4838 if( csrIsSupportedChannel( pMac, pSirBssDescription->channelId ) )
4839 {
4840 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
4841 }
4842 }
4843 }
4844 else
4845 {
4846 pMac->scan.curScanType = eSIR_ACTIVE_SCAN;
4847 }
4848 }
4849 //Free the resource
Kiet Lam64c1b492013-07-12 13:56:44 +05304850 vos_mem_free(pIes);
Jeff Johnson295189b2012-06-20 16:38:30 -07004851 }
4852 // skip over the BSS description to the next one...
4853 cbBssDesc = pSirBssDescription->length + sizeof( pSirBssDescription->length );
4854
4855 cbParsed += cbBssDesc;
4856 pSirBssDescription = (tSirBssDescription *)((tANI_U8 *)pSirBssDescription + cbBssDesc );
4857
4858 } //while
4859 }
4860 else
4861 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004862 smsLog( pMac, LOGW, " Scanrsp fail (0x%08X), length = %d (expected %d)",
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08004863 pScanRsp->statusCode, pScanRsp->length, cbScanResult);
Jeff Johnson295189b2012-06-20 16:38:30 -07004864 //HO bg scan/probe failed no need to try autonomously
4865 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
4866 eCsrScanProbeBss == pCommand->u.scanCmd.reason ||
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004867#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
4868 eCsrScanGetLfrResult == pCommand->u.scanCmd.reason ||
4869#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07004870 eCsrScanSetBGScanParam == pCommand->u.scanCmd.reason)
4871 {
4872 fRemoveCommand = eANI_BOOLEAN_TRUE;
4873 }
4874 }
4875 }while(0);
4876 if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
4877 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08004878 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 -07004879 fRemoveCommand = csrScanComplete( pMac, pScanRsp );
4880 fRet = eANI_BOOLEAN_TRUE;
4881 }//if ( eSIR_SME_MORE_SCAN_RESULTS_FOLLOW != pScanRsp->statusCode )
4882 if(pfRemoveCommand)
4883 {
4884 *pfRemoveCommand = fRemoveCommand;
4885 }
4886
4887#ifdef WLAN_AP_STA_CONCURRENCY
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05304888 if (pMac->fScanOffload)
4889 return fRet;
4890
Jeff Johnson295189b2012-06-20 16:38:30 -07004891 if (!csrLLIsListEmpty( &pMac->scan.scanCmdPendingList, LL_ACCESS_LOCK ))
4892 {
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08004893 /* Pending scan commands in the list because the previous scan command
4894 * was split into a scan command on one channel + a scan command for all
4895 * remaining channels.
4896 *
4897 * Start timer to trigger processing of the next scan command.
Srikant Kuppa866893f2012-12-27 17:28:14 -08004898 * NOTE for LFR:
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05304899 * Do not split scans if no concurrent infra connections are
Srikant Kuppa866893f2012-12-27 17:28:14 -08004900 * active and if the scan is a BG scan triggered by LFR (OR)
4901 * any scan if LFR is in the middle of a BG scan. Splitting
4902 * the scan is delaying the time it takes for LFR to find
4903 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08004904 */
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05304905 if ( (csrIsStaSessionConnected(pMac) &&
Srikant Kuppa866893f2012-12-27 17:28:14 -08004906#ifdef FEATURE_WLAN_LFR
4907 (csrIsConcurrentInfraConnected(pMac) ||
4908 ((pCommand->u.scanCmd.reason != eCsrScanBgScan) &&
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05304909 (pMac->roam.neighborRoamInfo.neighborRoamState !=
Srikant Kuppa866893f2012-12-27 17:28:14 -08004910 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
4911#endif
4912 (pCommand->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05304913 (csrIsP2pSessionConnected(pMac)) )
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08004914 {
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08004915 /* if active connected sessions present then continue to split scan
4916 * with specified interval between consecutive scans */
4917 csrSetDefaultScanTiming(pMac, pCommand->u.scanCmd.u.scanRequest.scanType, &(pCommand->u.scanCmd.u.scanRequest));
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05304918 vos_timer_start(&pMac->scan.hTimerStaApConcTimer,
4919 pCommand->u.scanCmd.u.scanRequest.restTime);
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08004920 } else {
4921 /* if no connected sessions present then initiate next scan command immediately */
4922 /* minimum timer granularity is 10ms */
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05304923 vos_timer_start(&pMac->scan.hTimerStaApConcTimer, 10);
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08004924 }
Jeff Johnson295189b2012-06-20 16:38:30 -07004925 }
4926#endif
4927 return (fRet);
4928}
4929
4930
4931tANI_BOOLEAN csrScanIsWildCardScan( tpAniSirGlobal pMac, tSmeCmd *pCommand )
4932{
4933 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
Kiet Lam64c1b492013-07-12 13:56:44 +05304934 tANI_BOOLEAN f = vos_mem_compare(pCommand->u.scanCmd.u.scanRequest.bssid,
4935 bssid, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07004936
4937 //It is not a wild card scan if the bssid is not broadcast and the number of SSID is 1.
4938 return ((tANI_BOOLEAN)( (f || (0xff == pCommand->u.scanCmd.u.scanRequest.bssid[0])) &&
4939 (pCommand->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs != 1) ));
4940}
4941
4942
4943eHalStatus csrScanSmeScanResponse( tpAniSirGlobal pMac, void *pMsgBuf )
4944{
4945 eHalStatus status = eHAL_STATUS_SUCCESS;
4946 tListElem *pEntry;
4947 tSmeCmd *pCommand;
4948 eCsrScanStatus scanStatus;
4949 tSirSmeScanRsp *pScanRsp = (tSirSmeScanRsp *)pMsgBuf;
4950 tSmeGetScanChnRsp *pScanChnInfo;
4951 tANI_BOOLEAN fRemoveCommand = eANI_BOOLEAN_TRUE;
4952 eCsrScanReason reason = eCsrScanOther;
4953
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05304954 if (pMac->fScanOffload)
4955 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList,
4956 LL_ACCESS_LOCK);
4957 else
4958 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07004959
4960 if ( pEntry )
4961 {
4962 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
4963 if ( eSmeCommandScan == pCommand->command )
4964 {
4965 scanStatus = (eSIR_SME_SUCCESS == pScanRsp->statusCode) ? eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
4966 reason = pCommand->u.scanCmd.reason;
4967 switch(pCommand->u.scanCmd.reason)
4968 {
4969 case eCsrScanAbortBgScan:
4970 case eCsrScanAbortNormalScan:
4971 case eCsrScanBGScanAbort:
4972 case eCsrScanBGScanEnable:
4973 break;
4974 case eCsrScanGetScanChnInfo:
4975 pScanChnInfo = (tSmeGetScanChnRsp *)pMsgBuf;
Madan Mohan Koyyalamudi1bed5982012-10-22 14:38:06 -07004976 /*
4977 * status code not available in tSmeGetScanChnRsp, so
4978 * by default considereing it to be success
4979 */
4980 scanStatus = eSIR_SME_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07004981 csrScanAgeResults(pMac, pScanChnInfo);
4982 break;
4983 case eCsrScanForCapsChange:
4984 csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand );
4985 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07004986 case eCsrScanP2PFindPeer:
4987 scanStatus = ((eSIR_SME_SUCCESS == pScanRsp->statusCode) && (pScanRsp->length > 50)) ? eCSR_SCAN_FOUND_PEER : eCSR_SCAN_FAILURE;
4988 csrScanProcessScanResults( pMac, pCommand, pScanRsp, NULL );
4989 break;
Jeff Johnson295189b2012-06-20 16:38:30 -07004990 case eCsrScanSetBGScanParam:
4991 default:
4992 if(csrScanProcessScanResults( pMac, pCommand, pScanRsp, &fRemoveCommand ))
4993 {
4994 //Not to get channel info if the scan is not a wildcard scan because
4995 //it may cause scan results got aged out incorrectly.
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07004996 if( csrScanIsWildCardScan( pMac, pCommand ) && (!pCommand->u.scanCmd.u.scanRequest.p2pSearch)
4997#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
4998 && (pCommand->u.scanCmd.reason != eCsrScanGetLfrResult)
4999#endif
5000 )
Jeff Johnson295189b2012-06-20 16:38:30 -07005001 {
5002 //Get the list of channels scanned
Jeff Johnson32d95a32012-09-10 13:15:23 -07005003 if( pCommand->u.scanCmd.reason != eCsrScanUserRequest)
5004 {
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05305005 csrScanGetScanChnInfo(pMac, pCommand->sessionId,
5006 NULL, NULL);
Jeff Johnson32d95a32012-09-10 13:15:23 -07005007 }
5008 else
5009 {
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05305010 csrScanGetScanChnInfo(pMac,
5011 pCommand->sessionId,
5012 pCommand->u.scanCmd.pContext,
5013 pCommand->u.scanCmd.callback);
Jeff Johnson32d95a32012-09-10 13:15:23 -07005014 pCommand->u.scanCmd.callback = NULL;
5015 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005016 }
5017 }
5018 break;
5019 }//switch
5020 if(fRemoveCommand)
5021 {
5022
5023 csrReleaseScanCommand(pMac, pCommand, scanStatus);
5024
Srikant Kuppa866893f2012-12-27 17:28:14 -08005025 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005026 smeProcessPendingQueue( pMac );
5027 }
5028 else
5029 {
5030 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
5031 status = eHAL_STATUS_FAILURE;
5032 }
5033 }
5034 else
5035 {
5036 smsLog( pMac, LOGW, "CSR: Scan Completion called but NO commands are ACTIVE ..." );
5037 status = eHAL_STATUS_FAILURE;
5038 }
5039
5040 return (status);
5041}
5042
5043
5044
5045
5046tCsrScanResultInfo *csrScanResultGetFirst(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
5047{
5048 tListElem *pEntry;
5049 tCsrScanResult *pResult;
5050 tCsrScanResultInfo *pRet = NULL;
5051 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5052
5053 if(pResultList)
5054 {
5055 csrLLLock(&pResultList->List);
5056 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5057 if(pEntry)
5058 {
5059 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
5060 pRet = &pResult->Result;
5061 }
5062 pResultList->pCurEntry = pEntry;
5063 csrLLUnlock(&pResultList->List);
5064 }
5065
5066 return pRet;
5067}
5068
5069
5070tCsrScanResultInfo *csrScanResultGetNext(tpAniSirGlobal pMac, tScanResultHandle hScanResult)
5071{
5072 tListElem *pEntry = NULL;
5073 tCsrScanResult *pResult = NULL;
5074 tCsrScanResultInfo *pRet = NULL;
5075 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5076
5077 if(pResultList)
5078 {
5079 csrLLLock(&pResultList->List);
5080 if(NULL == pResultList->pCurEntry)
5081 {
5082 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5083 }
5084 else
5085 {
5086 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
5087 }
5088 if(pEntry)
5089 {
5090 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
5091 pRet = &pResult->Result;
5092 }
5093 pResultList->pCurEntry = pEntry;
5094 csrLLUnlock(&pResultList->List);
5095 }
5096
5097 return pRet;
5098}
5099
5100
5101//This function moves the first BSS that matches the bssid to the head of the result
5102eHalStatus csrMoveBssToHeadFromBSSID(tpAniSirGlobal pMac, tCsrBssid *bssid, tScanResultHandle hScanResult)
5103{
5104 eHalStatus status = eHAL_STATUS_FAILURE;
5105 tScanResultList *pResultList = (tScanResultList *)hScanResult;
5106 tCsrScanResult *pResult = NULL;
5107 tListElem *pEntry = NULL;
5108
5109 if(pResultList && bssid)
5110 {
5111 csrLLLock(&pResultList->List);
5112 pEntry = csrLLPeekHead(&pResultList->List, LL_ACCESS_NOLOCK);
5113 while(pEntry)
5114 {
5115 pResult = GET_BASE_ADDR(pEntry, tCsrScanResult, Link);
Kiet Lam64c1b492013-07-12 13:56:44 +05305116 if (vos_mem_compare(bssid, pResult->Result.BssDescriptor.bssId, sizeof(tCsrBssid)))
Jeff Johnson295189b2012-06-20 16:38:30 -07005117 {
5118 status = eHAL_STATUS_SUCCESS;
5119 csrLLRemoveEntry(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
5120 csrLLInsertHead(&pResultList->List, pEntry, LL_ACCESS_NOLOCK);
5121 break;
5122 }
5123 pEntry = csrLLNext(&pResultList->List, pResultList->pCurEntry, LL_ACCESS_NOLOCK);
5124 }
5125 csrLLUnlock(&pResultList->List);
5126 }
5127
5128 return (status);
5129}
5130
5131
5132//Remove the BSS if possible.
5133//Return -- TRUE == the BSS is remove. False == Fail to remove it
5134//This function is called when list lock is held. Be caution what functions it can call.
5135tANI_BOOLEAN csrScanAgeOutBss(tpAniSirGlobal pMac, tCsrScanResult *pResult)
5136{
5137 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
5138 tANI_U32 i;
5139 tCsrRoamSession *pSession;
5140
5141 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5142 {
5143 if( CSR_IS_SESSION_VALID( pMac, i ) )
5144 {
5145 pSession = CSR_GET_SESSION( pMac, i );
5146 //Not to remove the BSS we are connected to.
5147 if(csrIsConnStateDisconnected(pMac, i) || (NULL == pSession->pConnectBssDesc) ||
5148 (!csrIsDuplicateBssDescription(pMac, &pResult->Result.BssDescriptor,
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07005149 pSession->pConnectBssDesc, NULL, FALSE))
Jeff Johnson295189b2012-06-20 16:38:30 -07005150 )
5151 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005152 smsLog(pMac, LOGW, "Aging out BSS %02X-%02X-%02X-%02X-%02X-%02X Channel %d",
Jeff Johnson295189b2012-06-20 16:38:30 -07005153 pResult->Result.BssDescriptor.bssId[0],
5154 pResult->Result.BssDescriptor.bssId[1],
5155 pResult->Result.BssDescriptor.bssId[2],
5156 pResult->Result.BssDescriptor.bssId[3],
5157 pResult->Result.BssDescriptor.bssId[4],
5158 pResult->Result.BssDescriptor.bssId[5],
5159 pResult->Result.BssDescriptor.channelId);
5160 //No need to hold the spin lock because caller should hold the lock for pMac->scan.scanResultList
5161 if( csrLLRemoveEntry(&pMac->scan.scanResultList, &pResult->Link, LL_ACCESS_NOLOCK) )
5162 {
5163 csrFreeScanResultEntry(pMac, pResult);
Madan Mohan Koyyalamudi2e068bc2012-10-22 14:58:47 -07005164 fRet = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005165 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005166 break;
5167 }
5168 } //valid session
5169 } //for
Madan Mohan Koyyalamudi2e068bc2012-10-22 14:58:47 -07005170 if( CSR_ROAM_SESSION_MAX == i && fRet != eANI_BOOLEAN_TRUE )
Jeff Johnson295189b2012-06-20 16:38:30 -07005171 {
5172 //reset the counter so this won't hapeen too soon
5173 pResult->AgingCount = (tANI_S32)pMac->roam.configParam.agingCount;
5174 pResult->Result.BssDescriptor.nReceivedTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
5175 }
5176
5177 return (fRet);
5178}
5179
5180
5181eHalStatus csrScanAgeResults(tpAniSirGlobal pMac, tSmeGetScanChnRsp *pScanChnInfo)
5182{
5183 eHalStatus status = eHAL_STATUS_SUCCESS;
5184 tListElem *pEntry, *tmpEntry;
5185 tCsrScanResult *pResult;
5186 tLimScanChn *pChnInfo;
5187 tANI_U8 i;
5188
5189 csrLLLock(&pMac->scan.scanResultList);
5190 for(i = 0; i < pScanChnInfo->numChn; i++)
5191 {
5192 pChnInfo = &pScanChnInfo->scanChn[i];
5193 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
5194 while( pEntry )
5195 {
5196 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
5197 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
5198 if(pResult->Result.BssDescriptor.channelId == pChnInfo->channelId)
5199 {
Jeff Johnson295189b2012-06-20 16:38:30 -07005200 if(pResult->AgingCount <= 0)
5201 {
5202 smsLog(pMac, LOGW, " age out due to ref count");
5203 csrScanAgeOutBss(pMac, pResult);
5204 }
Madan Mohan Koyyalamudib9d3dcc2012-09-28 16:47:50 -07005205 else
5206 {
5207 pResult->AgingCount--;
5208 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005209 }
5210 pEntry = tmpEntry;
5211 }
5212 }
5213 csrLLUnlock(&pMac->scan.scanResultList);
5214
5215 return (status);
5216}
5217
5218
5219eHalStatus csrSendMBScanReq( tpAniSirGlobal pMac, tANI_U16 sessionId,
5220 tCsrScanRequest *pScanReq, tScanReqParam *pScanReqParam )
5221{
5222 eHalStatus status = eHAL_STATUS_SUCCESS;
5223 tSirSmeScanReq *pMsg;
5224 tANI_U16 msgLen;
5225 tANI_U8 bssid[WNI_CFG_BSSID_LEN] = {0, 0, 0, 0, 0, 0};
5226 tSirScanType scanType = pScanReq->scanType;
5227 tANI_U32 minChnTime; //in units of milliseconds
5228 tANI_U32 maxChnTime; //in units of milliseconds
5229 tANI_U32 i;
5230 tANI_U8 selfMacAddr[WNI_CFG_BSSID_LEN];
5231 tANI_U8 *pSelfMac = NULL;
5232
5233 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
5234 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) +
5235 ( pScanReq->uIEFieldLen ) ;
5236
Kiet Lam64c1b492013-07-12 13:56:44 +05305237 pMsg = vos_mem_malloc(msgLen);
5238 if ( NULL == pMsg )
5239 status = eHAL_STATUS_FAILURE;
5240 else
5241 status = eHAL_STATUS_SUCCESS;
5242 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07005243 {
5244 do
5245 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305246 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005247 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
5248 pMsg->length = pal_cpu_to_be16(msgLen);
5249 //ToDO: Fill in session info when we need to do scan base on session.
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05305250 if ((pMac->fScanOffload) && (sessionId != CSR_SESSION_ID_INVALID))
5251 {
5252 pMsg->sessionId = sessionId;
5253 }
5254 else
5255 {
5256 /* if sessionId == CSR_SESSION_ID_INVALID, then send the scan
5257 request on first available session */
5258 pMsg->sessionId = 0;
5259 }
5260
Jeff Johnson295189b2012-06-20 16:38:30 -07005261 pMsg->transactionId = 0;
5262 pMsg->dot11mode = (tANI_U8) csrTranslateToWNICfgDot11Mode(pMac, csrFindBestPhyMode( pMac, pMac->roam.configParam.phyMode ));
5263 pMsg->bssType = pal_cpu_to_be32(csrTranslateBsstypeToMacType(pScanReq->BSSType));
5264
5265 if ( CSR_IS_SESSION_VALID( pMac, sessionId ) )
5266 {
5267 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[sessionId].selfMacAddr;
5268 }
5269 else
5270 {
5271 // Since we don't have session for the scanning, we find a valid session. In case we fail to
5272 // do so, get the WNI_CFG_STA_ID
5273 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5274 {
5275 if( CSR_IS_SESSION_VALID( pMac, i ) )
5276 {
5277 pSelfMac = (tANI_U8 *)&pMac->roam.roamSession[i].selfMacAddr;
5278 break;
5279 }
5280 }
5281 if( CSR_ROAM_SESSION_MAX == i )
5282 {
5283 tANI_U32 len = WNI_CFG_BSSID_LEN;
5284 pSelfMac = selfMacAddr;
5285 status = ccmCfgGetStr( pMac, WNI_CFG_STA_ID, pSelfMac, &len );
5286 if( !HAL_STATUS_SUCCESS( status ) ||
5287 ( len < WNI_CFG_BSSID_LEN ) )
5288 {
5289 smsLog( pMac, LOGE, FL(" Can not get self MAC address from CFG status = %d"), status );
5290 //Force failed status
5291 status = eHAL_STATUS_FAILURE;
5292 break;
5293 }
5294 }
5295 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305296 vos_mem_copy((tANI_U8 *)pMsg->selfMacAddr, pSelfMac, sizeof(tSirMacAddr));
Jeff Johnson295189b2012-06-20 16:38:30 -07005297
5298 //sirCopyMacAddr
Kiet Lam64c1b492013-07-12 13:56:44 +05305299 vos_mem_copy((tANI_U8 *)pMsg->bssId, (tANI_U8 *)&pScanReq->bssid, sizeof(tSirMacAddr));
5300 if ( vos_mem_compare(pScanReq->bssid, bssid, sizeof(tCsrBssid)))
Jeff Johnson295189b2012-06-20 16:38:30 -07005301 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305302 vos_mem_set(pMsg->bssId, sizeof(tSirMacAddr), 0xff);
Jeff Johnson295189b2012-06-20 16:38:30 -07005303 }
5304 else
5305 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305306 vos_mem_copy(pMsg->bssId, pScanReq->bssid, WNI_CFG_BSSID_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07005307 }
5308 minChnTime = pScanReq->minChnTime;
5309 maxChnTime = pScanReq->maxChnTime;
5310
5311 //Verify the scan type first, if the scan is active scan, we need to make sure we
5312 //are allowed to do so.
5313 /* if 11d is enabled & we don't see any beacon around, scan type falls
5314 back to passive. But in BT AMP STA mode we need to send out a
5315 directed probe*/
5316 if( (eSIR_PASSIVE_SCAN != scanType) && (eCSR_SCAN_P2P_DISCOVERY != pScanReq->requestType)
5317 && (eCSR_BSS_TYPE_WDS_STA != pScanReq->BSSType)
5318 && (eANI_BOOLEAN_FALSE == pMac->scan.fEnableBypass11d))
5319 {
5320 scanType = pMac->scan.curScanType;
5321 if(eSIR_PASSIVE_SCAN == pMac->scan.curScanType)
5322 {
5323 if(minChnTime < pMac->roam.configParam.nPassiveMinChnTime)
5324 {
5325 minChnTime = pMac->roam.configParam.nPassiveMinChnTime;
5326 }
5327 if(maxChnTime < pMac->roam.configParam.nPassiveMaxChnTime)
5328 {
5329 maxChnTime = pMac->roam.configParam.nPassiveMaxChnTime;
5330 }
5331 }
5332 }
5333 pMsg->scanType = pal_cpu_to_be32(scanType);
5334
5335 pMsg->numSsid = (pScanReq->SSIDs.numOfSSIDs < SIR_SCAN_MAX_NUM_SSID) ? pScanReq->SSIDs.numOfSSIDs :
5336 SIR_SCAN_MAX_NUM_SSID;
5337 if((pScanReq->SSIDs.numOfSSIDs != 0) && ( eSIR_PASSIVE_SCAN != scanType ))
5338 {
Jeff Johnson40b59aa2013-03-19 14:43:18 -07005339 for (i = 0; i < pMsg->numSsid; i++)
5340 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305341 vos_mem_copy(&pMsg->ssId[i],
5342 &pScanReq->SSIDs.SSIDList[i].SSID, sizeof(tSirMacSSid));
Jeff Johnson40b59aa2013-03-19 14:43:18 -07005343 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005344 }
5345 else
5346 {
5347 //Otherwise we scan all SSID and let the result filter later
Jeff Johnson40b59aa2013-03-19 14:43:18 -07005348 for (i = 0; i < SIR_SCAN_MAX_NUM_SSID; i++)
5349 {
5350 pMsg->ssId[i].length = 0;
5351 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005352 }
5353
Jeff Johnson295189b2012-06-20 16:38:30 -07005354 pMsg->minChannelTime = pal_cpu_to_be32(minChnTime);
5355 pMsg->maxChannelTime = pal_cpu_to_be32(maxChnTime);
Kiran Kumar Lokere3527f0c2013-02-24 22:21:28 -08005356 pMsg->minChannelTimeBtc = pMac->roam.configParam.nActiveMinChnTimeBtc;
5357 pMsg->maxChannelTimeBtc = pMac->roam.configParam.nActiveMaxChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07005358 //hidden SSID option
5359 pMsg->hiddenSsid = pScanReqParam->hiddenSsid;
5360 //rest time
5361 //pMsg->restTime = pScanReq->restTime;
5362 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
5363 // All the scan results caching will be done by Roaming
5364 // We do not want LIM to do any caching of scan results,
5365 // so delete the LIM cache on all scan requests
5366 pMsg->returnFreshResults = pScanReqParam->freshScan;
5367 //Always ask for unique result
5368 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
5369 pMsg->channelList.numChannels = (tANI_U8)pScanReq->ChannelInfo.numOfChannels;
5370 if(pScanReq->ChannelInfo.numOfChannels)
5371 {
5372 //Assuming the channelNumber is tANI_U8 (1 byte)
Kiet Lam64c1b492013-07-12 13:56:44 +05305373 vos_mem_copy(pMsg->channelList.channelNumber,
5374 pScanReq->ChannelInfo.ChannelList,
5375 pScanReq->ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07005376 }
5377
5378 pMsg->uIEFieldLen = (tANI_U16) pScanReq->uIEFieldLen;
5379 pMsg->uIEFieldOffset = (tANI_U16)(sizeof( tSirSmeScanReq ) - sizeof( pMsg->channelList.channelNumber ) +
5380 ( sizeof( pMsg->channelList.channelNumber ) * pScanReq->ChannelInfo.numOfChannels )) ;
5381 if(pScanReq->uIEFieldLen != 0)
5382 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305383 vos_mem_copy((tANI_U8 *)pMsg+pMsg->uIEFieldOffset, pScanReq->pIEField,
5384 pScanReq->uIEFieldLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07005385 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005386 pMsg->p2pSearch = pScanReq->p2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07005387
Madan Mohan Koyyalamudi9b876782012-10-11 16:22:51 -07005388 if (pScanReq->requestType == eCSR_SCAN_HO_BG_SCAN)
5389 {
5390 pMsg->backgroundScanMode = eSIR_ROAMING_SCAN;
5391 }
5392
Jeff Johnson295189b2012-06-20 16:38:30 -07005393 }while(0);
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005394 smsLog(pMac, LOG1, FL("domainIdCurrent %d scanType %d bssType %d requestType %d numChannels %d "),
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005395 pMac->scan.domainIdCurrent, pMsg->scanType, pMsg->bssType,
5396 pScanReq->requestType, pMsg->channelList.numChannels);
5397
5398 for(i = 0; i < pMsg->channelList.numChannels; i++)
5399 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005400 smsLog(pMac, LOG3, FL("channelNumber[%d]= %d"), i, pMsg->channelList.channelNumber[i]);
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005401 }
5402
Jeff Johnson295189b2012-06-20 16:38:30 -07005403 if(HAL_STATUS_SUCCESS(status))
5404 {
5405 status = palSendMBMessage(pMac->hHdd, pMsg);
5406 }
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005407 else
5408 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005409 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d"), status );
Kiet Lam64c1b492013-07-12 13:56:44 +05305410 vos_mem_free(pMsg);
Jeff Johnson295189b2012-06-20 16:38:30 -07005411 }
5412 }//Success allocated memory
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005413 else
5414 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005415 smsLog( pMac, LOGE, FL(" memory allocation failure"));
Gopichand Nakkala9b89a732012-12-31 16:31:46 -08005416 }
Jeff Johnson295189b2012-06-20 16:38:30 -07005417
5418 return( status );
5419}
5420
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005421eHalStatus csrSendMBScanResultReq( tpAniSirGlobal pMac, tANI_U32 sessionId, tScanReqParam *pScanReqParam )
Jeff Johnson295189b2012-06-20 16:38:30 -07005422{
5423 eHalStatus status = eHAL_STATUS_SUCCESS;
5424 tSirSmeScanReq *pMsg;
5425 tANI_U16 msgLen;
5426
5427 msgLen = (tANI_U16)(sizeof( tSirSmeScanReq ));
Kiet Lam64c1b492013-07-12 13:56:44 +05305428 pMsg = vos_mem_malloc(msgLen);
5429 if ( NULL == pMsg )
5430 status = eHAL_STATUS_FAILURE;
5431 else
Jeff Johnson295189b2012-06-20 16:38:30 -07005432 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305433 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005434 pMsg->messageType = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_REQ);
5435 pMsg->length = pal_cpu_to_be16(msgLen);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005436 pMsg->sessionId = sessionId;
5437 pMsg->transactionId = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07005438 pMsg->returnFreshResults = pScanReqParam->freshScan;
5439 //Always ask for unique result
5440 pMsg->returnUniqueResults = pScanReqParam->fUniqueResult;
5441 pMsg->returnAfterFirstMatch = pScanReqParam->bReturnAfter1stMatch;
5442 status = palSendMBMessage(pMac->hHdd, pMsg);
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005443 if (!HAL_STATUS_SUCCESS(status))
5444 {
5445 smsLog( pMac, LOGE, FL(" failed to send down scan req with status = %d\n"), status );
5446 }
5447
Jeff Johnson295189b2012-06-20 16:38:30 -07005448 }
5449
5450 return( status );
5451}
5452
5453
5454
5455eHalStatus csrScanChannels( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5456{
5457 eHalStatus status = eHAL_STATUS_FAILURE;
5458 tScanReqParam scanReq;
5459
5460 do
5461 {
5462 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE | TRUE;
5463 scanReq.fUniqueResult = TRUE;
5464 scanReq.hiddenSsid = SIR_SCAN_NO_HIDDEN_SSID;
5465 if(eCsrScanForSsid == pCommand->u.scanCmd.reason)
5466 {
5467 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_FIRST_MATCH;
5468 }
5469 else
5470 {
5471 // Basically do scan on all channels even for 11D 1st scan case.
5472 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5473 }
5474 if((eCsrScanBgScan == pCommand->u.scanCmd.reason)||
5475 (eCsrScanProbeBss == pCommand->u.scanCmd.reason))
5476 {
5477 scanReq.hiddenSsid = SIR_SCAN_HIDDEN_SSID_PE_DECISION;
5478 }
5479
5480#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5481 {
5482 vos_log_scan_pkt_type *pScanLog = NULL;
5483
5484 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
5485 if(pScanLog)
5486 {
5487 if(eCsrScanBgScan == pCommand->u.scanCmd.reason ||
5488 eCsrScanProbeBss == pCommand->u.scanCmd.reason)
5489 {
5490 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
5491 }
5492 else
5493 {
5494 if( (eSIR_PASSIVE_SCAN != pCommand->u.scanCmd.u.scanRequest.scanType) &&
5495 (eSIR_PASSIVE_SCAN != pMac->scan.curScanType) )
5496 {
5497 pScanLog->eventId = WLAN_SCAN_EVENT_ACTIVE_SCAN_REQ;
5498 }
5499 else
5500 {
5501 pScanLog->eventId = WLAN_SCAN_EVENT_PASSIVE_SCAN_REQ;
5502 }
5503 }
5504 pScanLog->minChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.minChnTime;
5505 pScanLog->maxChnTime = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.maxChnTime;
5506 pScanLog->numChannel = (v_U8_t)pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
5507 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
5508 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305509 vos_mem_copy(pScanLog->channels,
5510 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList,
5511 pScanLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07005512 }
5513 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
5514 }
5515 }
5516#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
5517
5518
5519 status = csrSendMBScanReq(pMac, pCommand->sessionId,
5520 &pCommand->u.scanCmd.u.scanRequest, &scanReq);
5521 }while(0);
5522
5523 return( status );
5524}
5525
5526
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005527eHalStatus csrScanRetrieveResult(tpAniSirGlobal pMac, tSmeCmd *pCommand)
Jeff Johnson295189b2012-06-20 16:38:30 -07005528{
5529 eHalStatus status = eHAL_STATUS_FAILURE;
5530 tScanReqParam scanReq;
5531
5532 do
5533 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005534#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5535 if (eCsrScanGetLfrResult == pCommand->u.scanCmd.reason)
5536 {
5537 //to get the LFR candidates from PE cache
5538 scanReq.freshScan = SIR_BG_SCAN_RETURN_LFR_CACHED_RESULTS|SIR_BG_SCAN_PURGE_LFR_RESULTS;
5539 scanReq.fUniqueResult = TRUE;
5540 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5541 }
5542 else
5543#endif
5544 {
5545 //not a fresh scan
5546 scanReq.freshScan = CSR_SME_SCAN_FLAGS_DELETE_CACHE;
5547 scanReq.fUniqueResult = TRUE;
5548 scanReq.bReturnAfter1stMatch = CSR_SCAN_RETURN_AFTER_ALL_CHANNELS;
5549 }
5550 status = csrSendMBScanResultReq(pMac, pCommand->sessionId, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07005551 }while(0);
5552
5553 return (status);
5554}
5555
5556
5557
5558eHalStatus csrProcessScanCommand( tpAniSirGlobal pMac, tSmeCmd *pCommand )
5559{
5560 eHalStatus status = eHAL_STATUS_SUCCESS;
5561 tCsrChannelInfo newChannelInfo = {0, NULL};
5562 int i, j;
5563 tANI_U8 *pChannel = NULL;
5564 tANI_U32 len = 0;
5565
5566 // Transition to Scanning state...
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305567 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07005568 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05305569 for( i = 0; i < CSR_ROAM_SESSION_MAX; i++ )
5570 {
5571 pCommand->u.scanCmd.lastRoamState[i] =
5572 csrRoamStateChange( pMac, eCSR_ROAMING_STATE_SCANNING, i);
5573 smsLog( pMac, LOG3, "starting SCAN command from %d state...."
5574 " reason is %d", pCommand->u.scanCmd.lastRoamState[i],
5575 pCommand->u.scanCmd.reason );
5576 }
5577 }
5578 else
5579 {
5580 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId] =
5581 csrRoamStateChange(pMac, eCSR_ROAMING_STATE_SCANNING,
5582 pCommand->sessionId);
5583 smsLog( pMac, LOG3,
5584 "starting SCAN command from %d state.... reason is %d",
5585 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId],
5586 pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07005587 }
5588
5589 switch(pCommand->u.scanCmd.reason)
5590 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005591#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
5592 case eCsrScanGetLfrResult:
5593#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005594 case eCsrScanGetResult:
5595 case eCsrScanForCapsChange: //For cap change, LIM already save BSS description
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07005596 status = csrScanRetrieveResult(pMac, pCommand);
Jeff Johnson295189b2012-06-20 16:38:30 -07005597 break;
5598 case eCsrScanSetBGScanParam:
5599 status = csrProcessSetBGScanParam(pMac, pCommand);
5600 break;
5601 case eCsrScanBGScanAbort:
5602 status = csrSetCfgBackgroundScanPeriod(pMac, 0);
5603 break;
5604 case eCsrScanBGScanEnable:
5605 status = csrSetCfgBackgroundScanPeriod(pMac, pMac->roam.configParam.bgScanInterval);
5606 break;
5607 case eCsrScanGetScanChnInfo:
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05305608 status = csrScanGetScanChannelInfo(pMac, pCommand->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07005609 break;
5610 case eCsrScanUserRequest:
5611 if(pMac->roam.configParam.fScanTwice)
5612 {
5613 //We scan 2.4 channel twice
5614 if(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels &&
5615 (NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList))
5616 {
5617 len = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
5618 //allocate twice the channel
5619 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(newChannelInfo.numOfChannels * 2);
5620 pChannel = pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList;
5621 }
5622 else
5623 {
5624 //get the valid channel list to scan all.
5625 len = sizeof(pMac->roam.validChannelList);
5626
5627 if (HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, (tANI_U8 *)pMac->roam.validChannelList, &len)))
5628 {
5629 //allocate twice the channel
5630 newChannelInfo.ChannelList = (tANI_U8 *)vos_mem_malloc(len * 2);
5631 pChannel = pMac->roam.validChannelList;
5632 }
5633 }
5634 if(NULL == newChannelInfo.ChannelList)
5635 {
5636 newChannelInfo.numOfChannels = 0;
5637 }
5638 else
5639 {
5640 j = 0;
5641 for(i = 0; i < len; i++)
5642 {
5643 newChannelInfo.ChannelList[j++] = pChannel[i];
5644 if(CSR_MAX_24GHz_CHANNEL_NUMBER >= pChannel[i])
5645 {
5646 newChannelInfo.ChannelList[j++] = pChannel[i];
5647 }
5648 }
5649 if(NULL != pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
5650 {
5651 //pChannel points to the channellist from the command, free it.
5652 vos_mem_free(pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList);
James Zmuda9ea1edd2013-04-18 18:20:54 -07005653 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07005654 }
5655 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = j;
5656 pCommand->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = newChannelInfo.ChannelList;
5657 }
5658 } //if(pMac->roam.configParam.fScanTwice)
5659
5660 status = csrScanChannels(pMac, pCommand);
5661
5662 break;
5663 default:
5664 status = csrScanChannels(pMac, pCommand);
5665 break;
5666 }
5667
5668 if(!HAL_STATUS_SUCCESS(status))
5669 {
5670 csrReleaseScanCommand(pMac, pCommand, eCSR_SCAN_FAILURE);
5671 }
5672
5673 return (status);
5674}
5675
5676
5677eHalStatus csrScanSetBGScanparams(tpAniSirGlobal pMac, tCsrBGScanRequest *pScanReq)
5678{
5679 eHalStatus status = eHAL_STATUS_SUCCESS;
5680 tSmeCmd *pCommand = NULL;
5681
5682 if(pScanReq)
5683 {
5684 do
5685 {
5686 pCommand = csrGetCommandBuffer(pMac);
5687 if(!pCommand)
5688 {
5689 status = eHAL_STATUS_RESOURCES;
5690 break;
5691 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305692 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005693 pCommand->command = eSmeCommandScan;
5694 pCommand->u.scanCmd.reason = eCsrScanSetBGScanParam;
5695 pCommand->u.scanCmd.callback = NULL;
5696 pCommand->u.scanCmd.pContext = NULL;
Kiet Lam64c1b492013-07-12 13:56:44 +05305697 vos_mem_copy(&pCommand->u.scanCmd.u.bgScanRequest, pScanReq, sizeof(tCsrBGScanRequest));
Jeff Johnson295189b2012-06-20 16:38:30 -07005698 //we have to do the follow
5699 if(pScanReq->ChannelInfo.numOfChannels == 0)
5700 {
5701 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList = NULL;
5702 }
5703 else
5704 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305705 pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList
5706 = vos_mem_malloc(pScanReq->ChannelInfo.numOfChannels);
5707 if ( NULL != pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList )
Jeff Johnson295189b2012-06-20 16:38:30 -07005708 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305709 vos_mem_copy(pCommand->u.scanCmd.u.bgScanRequest.ChannelInfo.ChannelList,
5710 pScanReq->ChannelInfo.ChannelList,
5711 pScanReq->ChannelInfo.numOfChannels);
Jeff Johnson295189b2012-06-20 16:38:30 -07005712 }
5713 else
5714 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005715 smsLog(pMac, LOGE, FL("ran out of memory"));
Jeff Johnson295189b2012-06-20 16:38:30 -07005716 csrReleaseCommandScan(pMac, pCommand);
Kiet Lam64c1b492013-07-12 13:56:44 +05305717 return eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07005718 }
5719 }
5720
5721 //scan req for SSID
5722 if(pScanReq->SSID.length)
5723 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305724 vos_mem_copy(pCommand->u.scanCmd.u.bgScanRequest.SSID.ssId,
5725 pScanReq->SSID.ssId, pScanReq->SSID.length);
Jeff Johnson295189b2012-06-20 16:38:30 -07005726 pCommand->u.scanCmd.u.bgScanRequest.SSID.length = pScanReq->SSID.length;
5727
5728 }
5729 pCommand->u.scanCmd.u.bgScanRequest.maxChnTime= pScanReq->maxChnTime;
5730 pCommand->u.scanCmd.u.bgScanRequest.minChnTime = pScanReq->minChnTime;
5731 pCommand->u.scanCmd.u.bgScanRequest.scanInterval = pScanReq->scanInterval;
5732
5733
5734 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
5735 if( !HAL_STATUS_SUCCESS( status ) )
5736 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005737 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07005738 csrReleaseCommandScan( pMac, pCommand );
5739 break;
5740 }
5741 }while(0);
5742 }
5743
5744 return (status);
5745}
5746
5747eHalStatus csrScanBGScanAbort( tpAniSirGlobal pMac )
5748{
5749 eHalStatus status = eHAL_STATUS_SUCCESS;
5750 tSmeCmd *pCommand = NULL;
5751
5752 do
5753 {
5754 pCommand = csrGetCommandBuffer(pMac);
5755 if(!pCommand)
5756 {
5757 status = eHAL_STATUS_RESOURCES;
5758 break;
5759 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305760 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005761 pCommand->command = eSmeCommandScan;
5762 pCommand->u.scanCmd.reason = eCsrScanBGScanAbort;
5763 pCommand->u.scanCmd.callback = NULL;
5764 pCommand->u.scanCmd.pContext = NULL;
5765 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
5766 if( !HAL_STATUS_SUCCESS( status ) )
5767 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005768 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07005769 csrReleaseCommandScan( pMac, pCommand );
5770 break;
5771 }
5772 }while(0);
5773
5774 return (status);
5775}
5776
5777
5778//This will enable the background scan with the non-zero interval
5779eHalStatus csrScanBGScanEnable(tpAniSirGlobal pMac)
5780{
5781 eHalStatus status = eHAL_STATUS_SUCCESS;
5782 tSmeCmd *pCommand = NULL;
5783
5784 if(pMac->roam.configParam.bgScanInterval)
5785 {
5786 do
5787 {
5788 pCommand = csrGetCommandBuffer(pMac);
5789 if(!pCommand)
5790 {
5791 status = eHAL_STATUS_RESOURCES;
5792 break;
5793 }
Kiet Lam64c1b492013-07-12 13:56:44 +05305794 vos_mem_set(&pCommand->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07005795 pCommand->command = eSmeCommandScan;
5796 pCommand->u.scanCmd.reason = eCsrScanBGScanEnable;
5797 pCommand->u.scanCmd.callback = NULL;
5798 pCommand->u.scanCmd.pContext = NULL;
5799 status = csrQueueSmeCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
5800 if( !HAL_STATUS_SUCCESS( status ) )
5801 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005802 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07005803 csrReleaseCommandScan( pMac, pCommand );
5804 break;
5805 }
5806 }while(0);
5807 //BG scan results are reported automatically by PE to SME once the scan is done.
5808 //No need to fetch the results explicitly.
5809 //csrScanStartGetResultTimer(pMac);
5810 csrScanStartResultAgingTimer(pMac);
5811 }
5812 else
5813 {
5814 //We don't have BG scan so stop the aging timer
5815 csrScanStopResultAgingTimer(pMac);
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005816 smsLog(pMac, LOGE, FL("cannot continue because the bgscan interval is 0"));
Jeff Johnson295189b2012-06-20 16:38:30 -07005817 status = eHAL_STATUS_INVALID_PARAMETER;
5818 }
5819
5820 return (status);
5821}
5822
5823
5824eHalStatus csrScanCopyRequest(tpAniSirGlobal pMac, tCsrScanRequest *pDstReq, tCsrScanRequest *pSrcReq)
5825{
5826 eHalStatus status = eHAL_STATUS_SUCCESS;
5827 tANI_U32 len = sizeof(pMac->roam.validChannelList);
5828 tANI_U32 index = 0;
5829 tANI_U32 new_index = 0;
5830
5831 do
5832 {
5833 status = csrScanFreeRequest(pMac, pDstReq);
5834 if(HAL_STATUS_SUCCESS(status))
5835 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305836 vos_mem_copy(pDstReq, pSrcReq, sizeof(tCsrScanRequest));
Gopichand Nakkalac7b1d3e2012-12-31 14:07:19 -08005837 /* Re-initialize the pointers to NULL since we did a copy */
5838 pDstReq->pIEField = NULL;
5839 pDstReq->ChannelInfo.ChannelList = NULL;
5840 pDstReq->SSIDs.SSIDList = NULL;
5841
Jeff Johnson295189b2012-06-20 16:38:30 -07005842 if(pSrcReq->uIEFieldLen == 0)
5843 {
5844 pDstReq->pIEField = NULL;
5845 }
5846 else
5847 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305848 pDstReq->pIEField = vos_mem_malloc(pSrcReq->uIEFieldLen);
5849 if ( NULL == pDstReq->pIEField )
5850 status = eHAL_STATUS_FAILURE;
5851 else
5852 status = eHAL_STATUS_SUCCESS;
5853 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07005854 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305855 vos_mem_copy(pDstReq->pIEField, pSrcReq->pIEField, pSrcReq->uIEFieldLen);
Jeff Johnson295189b2012-06-20 16:38:30 -07005856 pDstReq->uIEFieldLen = pSrcReq->uIEFieldLen;
5857 }
5858 else
5859 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005860 smsLog(pMac, LOGE, "No memory for scanning IE fields");
Jeff Johnson295189b2012-06-20 16:38:30 -07005861 break;
5862 }
5863 }//Allocate memory for IE field
5864 {
5865 if(pSrcReq->ChannelInfo.numOfChannels == 0)
5866 {
5867 pDstReq->ChannelInfo.ChannelList = NULL;
5868 pDstReq->ChannelInfo.numOfChannels = 0;
5869 }
5870 else
5871 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305872 pDstReq->ChannelInfo.ChannelList = vos_mem_malloc(
5873 pSrcReq->ChannelInfo.numOfChannels
5874 * sizeof(*pDstReq->ChannelInfo.ChannelList));
5875 if ( NULL == pDstReq->ChannelInfo.ChannelList )
5876 status = eHAL_STATUS_FAILURE;
5877 else
5878 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07005879 if(!HAL_STATUS_SUCCESS(status))
5880 {
5881 pDstReq->ChannelInfo.numOfChannels = 0;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005882 smsLog(pMac, LOGE, "No memory for scanning Channel List");
Jeff Johnson295189b2012-06-20 16:38:30 -07005883 break;
5884 }
5885
5886 if((pSrcReq->scanType == eSIR_PASSIVE_SCAN) && (pSrcReq->requestType == eCSR_SCAN_REQUEST_11D_SCAN))
5887 {
5888 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
5889 {
5890 pDstReq->ChannelInfo.ChannelList[new_index] =
5891 pSrcReq->ChannelInfo.ChannelList[index];
5892 new_index++;
5893 }
5894 pDstReq->ChannelInfo.numOfChannels = new_index;
5895 }
5896 else if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
5897 {
5898 new_index = 0;
5899 pMac->roam.numValidChannels = len;
5900 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
5901 {
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -07005902 /* Allow scan on valid channels only.
5903 * If it is p2p scan and valid channel list doesnt contain
5904 * social channels, enforce scan on social channels because
5905 * that is the only way to find p2p peers.
5906 * This can happen only if band is set to 5Ghz mode.
5907 */
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08005908 if((csrRoamIsValidChannel(pMac, pSrcReq->ChannelInfo.ChannelList[index])) ||
5909 ((eCSR_SCAN_P2P_DISCOVERY == pSrcReq->requestType) &&
Madan Mohan Koyyalamudi783b2362012-10-21 11:54:41 -07005910 CSR_IS_SOCIAL_CHANNEL(pSrcReq->ChannelInfo.ChannelList[index])))
Jeff Johnson295189b2012-06-20 16:38:30 -07005911 {
Srikant Kuppa866893f2012-12-27 17:28:14 -08005912 if( (pSrcReq->skipDfsChnlInP2pSearch &&
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08005913 (NV_CHANNEL_DFS == vos_nv_getChannelEnabledState(pSrcReq->ChannelInfo.ChannelList[index])) )
Srikant Kuppa866893f2012-12-27 17:28:14 -08005914#ifdef FEATURE_WLAN_LFR
5915 /*
5916 * If LFR is requesting a contiguous scan
5917 * (i.e. numOfChannels > 1), then ignore
5918 * DFS channels.
5919 * TODO: vos_nv_getChannelEnabledState is returning
5920 * 120, 124 and 128 as non-DFS channels. Hence, the
5921 * use of direct check for channels below.
5922 */
5923 || ((eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType) &&
5924 (pSrcReq->ChannelInfo.numOfChannels > 1) &&
Srinivas Girigowdade697412013-02-14 16:31:48 -08005925 (CSR_IS_CHANNEL_DFS(pSrcReq->ChannelInfo.ChannelList[index])))
Srikant Kuppa866893f2012-12-27 17:28:14 -08005926#endif
5927 )
5928 {
5929#ifdef FEATURE_WLAN_LFR
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005930 smsLog(pMac, LOG2,
Srikant Kuppa866893f2012-12-27 17:28:14 -08005931 "%s: reqType=%d, numOfChannels=%d,"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005932 " ignoring DFS channel %d",
Srikant Kuppa866893f2012-12-27 17:28:14 -08005933 __func__, pSrcReq->requestType,
5934 pSrcReq->ChannelInfo.numOfChannels,
5935 pSrcReq->ChannelInfo.ChannelList[index]);
5936#endif
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08005937 continue;
Srikant Kuppa866893f2012-12-27 17:28:14 -08005938 }
Madan Mohan Koyyalamudic5992c92012-11-15 16:40:57 -08005939
Jeff Johnson295189b2012-06-20 16:38:30 -07005940 pDstReq->ChannelInfo.ChannelList[new_index] =
5941 pSrcReq->ChannelInfo.ChannelList[index];
5942 new_index++;
5943 }
5944 }
5945 pDstReq->ChannelInfo.numOfChannels = new_index;
Srikant Kuppa866893f2012-12-27 17:28:14 -08005946#ifdef FEATURE_WLAN_LFR
5947 if ((eCSR_SCAN_HO_BG_SCAN == pSrcReq->requestType) &&
5948 (0 == pDstReq->ChannelInfo.numOfChannels))
5949 {
5950 /*
5951 * No valid channels found in the request.
5952 * Only perform scan on the channels passed
5953 * pSrcReq if it is a eCSR_SCAN_HO_BG_SCAN.
5954 * Passing 0 to LIM will trigger a scan on
5955 * all valid channels which is not desirable.
5956 */
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005957 smsLog(pMac, LOGE, "%s: no valid channels found (request=%d)",
Srikant Kuppa866893f2012-12-27 17:28:14 -08005958 __func__, pSrcReq->requestType);
5959 for ( index = 0; index < pSrcReq->ChannelInfo.numOfChannels ; index++ )
5960 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005961 smsLog(pMac, LOGE, "pSrcReq index=%d channel=%d",
Srikant Kuppa866893f2012-12-27 17:28:14 -08005962 index, pSrcReq->ChannelInfo.ChannelList[index]);
5963 }
5964 status = eHAL_STATUS_FAILURE;
5965 break;
5966 }
5967#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07005968 }
5969 else
5970 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08005971 smsLog(pMac, LOGE, "Couldn't get the valid Channel List, keeping requester's list");
Kiet Lam64c1b492013-07-12 13:56:44 +05305972 vos_mem_copy(pDstReq->ChannelInfo.ChannelList,
5973 pSrcReq->ChannelInfo.ChannelList,
5974 pSrcReq->ChannelInfo.numOfChannels
5975 * sizeof(*pDstReq->ChannelInfo.ChannelList));
Jeff Johnson295189b2012-06-20 16:38:30 -07005976 pDstReq->ChannelInfo.numOfChannels = pSrcReq->ChannelInfo.numOfChannels;
5977 }
5978 }//Allocate memory for Channel List
5979 }
5980 if(pSrcReq->SSIDs.numOfSSIDs == 0)
5981 {
5982 pDstReq->SSIDs.numOfSSIDs = 0;
5983 pDstReq->SSIDs.SSIDList = NULL;
5984 }
5985 else
5986 {
Kiet Lam64c1b492013-07-12 13:56:44 +05305987 pDstReq->SSIDs.SSIDList = vos_mem_malloc(
5988 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
5989 if ( NULL == pDstReq->SSIDs.SSIDList )
5990 status = eHAL_STATUS_FAILURE;
5991 else
5992 status = eHAL_STATUS_SUCCESS;
5993 if (HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07005994 {
5995 pDstReq->SSIDs.numOfSSIDs = pSrcReq->SSIDs.numOfSSIDs;
Kiet Lam64c1b492013-07-12 13:56:44 +05305996 vos_mem_copy(pDstReq->SSIDs.SSIDList,
5997 pSrcReq->SSIDs.SSIDList,
5998 pSrcReq->SSIDs.numOfSSIDs * sizeof(*pDstReq->SSIDs.SSIDList));
Jeff Johnson295189b2012-06-20 16:38:30 -07005999 }
6000 else
6001 {
6002 pDstReq->SSIDs.numOfSSIDs = 0;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006003 smsLog(pMac, LOGE, "No memory for scanning SSID List");
Jeff Johnson295189b2012-06-20 16:38:30 -07006004 break;
6005 }
6006 }//Allocate memory for SSID List
Jeff Johnson295189b2012-06-20 16:38:30 -07006007 pDstReq->p2pSearch = pSrcReq->p2pSearch;
Jeff Johnsone7245742012-09-05 17:12:55 -07006008 pDstReq->skipDfsChnlInP2pSearch = pSrcReq->skipDfsChnlInP2pSearch;
Jeff Johnson295189b2012-06-20 16:38:30 -07006009
6010 }
6011 }while(0);
6012
6013 if(!HAL_STATUS_SUCCESS(status))
6014 {
6015 csrScanFreeRequest(pMac, pDstReq);
6016 }
6017
6018 return (status);
6019}
6020
6021
6022eHalStatus csrScanFreeRequest(tpAniSirGlobal pMac, tCsrScanRequest *pReq)
6023{
Jeff Johnson295189b2012-06-20 16:38:30 -07006024
6025 if(pReq->ChannelInfo.ChannelList)
6026 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306027 vos_mem_free(pReq->ChannelInfo.ChannelList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006028 pReq->ChannelInfo.ChannelList = NULL;
6029 }
6030 pReq->ChannelInfo.numOfChannels = 0;
6031 if(pReq->pIEField)
6032 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306033 vos_mem_free(pReq->pIEField);
Jeff Johnson295189b2012-06-20 16:38:30 -07006034 pReq->pIEField = NULL;
6035 }
6036 pReq->uIEFieldLen = 0;
6037 if(pReq->SSIDs.SSIDList)
6038 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306039 vos_mem_free(pReq->SSIDs.SSIDList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006040 pReq->SSIDs.SSIDList = NULL;
6041 }
6042 pReq->SSIDs.numOfSSIDs = 0;
6043
Kiet Lam64c1b492013-07-12 13:56:44 +05306044 return eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07006045}
6046
6047
6048void csrScanCallCallback(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
6049{
6050 if(pCommand->u.scanCmd.callback)
6051 {
6052// sme_ReleaseGlobalLock( &pMac->sme );
6053 pCommand->u.scanCmd.callback(pMac, pCommand->u.scanCmd.pContext, pCommand->u.scanCmd.scanID, scanStatus);
6054// sme_AcquireGlobalLock( &pMac->sme );
6055 } else {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006056 smsLog( pMac, LOG2, "%s:%d - Callback NULL!!!", __func__, __LINE__);
Jeff Johnson295189b2012-06-20 16:38:30 -07006057 }
6058}
6059
6060
6061void csrScanStopTimers(tpAniSirGlobal pMac)
6062{
6063 csrScanStopResultAgingTimer(pMac);
6064 csrScanStopIdleScanTimer(pMac);
6065 csrScanStopGetResultTimer(pMac);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006066 if(0 != pMac->scan.scanResultCfgAgingTime )
6067 {
6068 csrScanStopResultCfgAgingTimer(pMac);
6069 }
6070
Jeff Johnson295189b2012-06-20 16:38:30 -07006071}
6072
6073
6074eHalStatus csrScanStartGetResultTimer(tpAniSirGlobal pMac)
6075{
6076 eHalStatus status;
6077
6078 if(pMac->scan.fScanEnable)
6079 {
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306080 status = vos_timer_start(&pMac->scan.hTimerGetResult, CSR_SCAN_GET_RESULT_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006081 }
6082 else
6083 {
6084 status = eHAL_STATUS_FAILURE;
6085 }
6086
6087 return (status);
6088}
6089
6090
6091eHalStatus csrScanStopGetResultTimer(tpAniSirGlobal pMac)
6092{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306093 return (vos_timer_stop(&pMac->scan.hTimerGetResult));
Jeff Johnson295189b2012-06-20 16:38:30 -07006094}
6095
6096
6097void csrScanGetResultTimerHandler(void *pv)
6098{
6099 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6100
6101 csrScanRequestResult(pMac);
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306102
6103 vos_timer_start(&pMac->scan.hTimerGetResult, CSR_SCAN_GET_RESULT_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006104}
6105
6106#ifdef WLAN_AP_STA_CONCURRENCY
6107static void csrStaApConcTimerHandler(void *pv)
6108{
6109 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6110 tListElem *pEntry;
6111 tSmeCmd *pScanCmd;
6112
6113 csrLLLock(&pMac->scan.scanCmdPendingList);
6114
6115 if ( NULL != ( pEntry = csrLLPeekHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) ) )
6116 {
6117 tCsrScanRequest scanReq;
6118 tSmeCmd *pSendScanCmd = NULL;
6119 tANI_U8 numChn = 0;
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006120 tANI_U8 nNumChanCombinedConc = 0;
Vinay Malekal05fdc812012-12-17 13:04:30 -08006121 tANI_U8 i, j;
Jeff Johnson295189b2012-06-20 16:38:30 -07006122 tCsrChannelInfo *pChnInfo = &scanReq.ChannelInfo;
6123 tANI_U8 channelToScan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
6124 eHalStatus status;
6125
Jeff Johnson295189b2012-06-20 16:38:30 -07006126 pScanCmd = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
6127 numChn = pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels;
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08006128
6129 /* if any session is connected and the number of channels to scan is
6130 * greater than 1 then split the scan into multiple scan operations
6131 * on each individual channel else continue to perform scan on all
6132 * specified channels */
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08006133
6134 /* split scan if number of channels to scan is greater than 1 and
6135 * any one of the following:
6136 * - STA session is connected and the scan is not a P2P search
6137 * - any P2P session is connected
Srikant Kuppa866893f2012-12-27 17:28:14 -08006138 * Do not split scans if no concurrent infra connections are
6139 * active and if the scan is a BG scan triggered by LFR (OR)
6140 * any scan if LFR is in the middle of a BG scan. Splitting
6141 * the scan is delaying the time it takes for LFR to find
6142 * candidates and resulting in disconnects.
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08006143 */
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006144
6145 if((csrIsStaSessionConnected(pMac) &&
6146 !csrIsP2pSessionConnected(pMac)))
6147 {
6148 nNumChanCombinedConc = pMac->roam.configParam.nNumStaChanCombinedConc;
6149 }
6150 else if(csrIsP2pSessionConnected(pMac))
6151 {
6152 nNumChanCombinedConc = pMac->roam.configParam.nNumP2PChanCombinedConc;
6153 }
6154
6155 if ( (numChn > nNumChanCombinedConc) &&
Srikant Kuppa866893f2012-12-27 17:28:14 -08006156 ((csrIsStaSessionConnected(pMac) &&
6157#ifdef FEATURE_WLAN_LFR
6158 (csrIsConcurrentInfraConnected(pMac) ||
6159 ((pScanCmd->u.scanCmd.reason != eCsrScanBgScan) &&
6160 (pMac->roam.neighborRoamInfo.neighborRoamState !=
6161 eCSR_NEIGHBOR_ROAM_STATE_CFG_CHAN_LIST_SCAN))) &&
6162#endif
6163 (pScanCmd->u.scanCmd.u.scanRequest.p2pSearch != 1)) ||
Madan Mohan Koyyalamudi48081ef2012-12-04 16:49:55 -08006164 (csrIsP2pSessionConnected(pMac))))
Jeff Johnson295189b2012-06-20 16:38:30 -07006165 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306166 vos_mem_set(&scanReq, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006167
6168 pSendScanCmd = csrGetCommandBuffer(pMac); //optimize this to use 2 command buffer only
6169 if (!pSendScanCmd)
6170 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006171 smsLog( pMac, LOGE, FL(" Failed to get Queue command buffer") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006172 csrLLUnlock(&pMac->scan.scanCmdPendingList);
6173 return;
6174 }
6175 pSendScanCmd->command = pScanCmd->command;
6176 pSendScanCmd->sessionId = pScanCmd->sessionId;
6177 pSendScanCmd->u.scanCmd.callback = NULL;
6178 pSendScanCmd->u.scanCmd.pContext = pScanCmd->u.scanCmd.pContext;
6179 pSendScanCmd->u.scanCmd.reason = pScanCmd->u.scanCmd.reason;
6180 pSendScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
6181
Madan Mohan Koyyalamudiaf2a8b92012-10-09 14:58:07 -07006182 /* First copy all the parameters to local variable of scan request */
6183 csrScanCopyRequest(pMac, &scanReq, &pScanCmd->u.scanCmd.u.scanRequest);
6184
6185 /* Now modify the elements of local var scan request required to be modified for split scan */
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08006186 if(scanReq.ChannelInfo.ChannelList != NULL)
6187 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306188 vos_mem_free(scanReq.ChannelInfo.ChannelList);
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08006189 scanReq.ChannelInfo.ChannelList = NULL;
6190 }
6191
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006192 pChnInfo->numOfChannels = nNumChanCombinedConc;
Kiet Lam64c1b492013-07-12 13:56:44 +05306193 vos_mem_copy(&channelToScan[0],
6194 &pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[0],
6195 pChnInfo->numOfChannels * sizeof(tANI_U8));//just send one channel
Jeff Johnson295189b2012-06-20 16:38:30 -07006196 pChnInfo->ChannelList = &channelToScan[0];
6197
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006198 for (i = 0, j = nNumChanCombinedConc; i < (numChn-nNumChanCombinedConc); i++, j++)
Jeff Johnson295189b2012-06-20 16:38:30 -07006199 {
6200 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[i] =
Vinay Malekal05fdc812012-12-17 13:04:30 -08006201 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[j]; //Move all the channels one step
Jeff Johnson295189b2012-06-20 16:38:30 -07006202 }
6203
Sudhir Sattayappa Kohallieb97d502013-05-22 23:16:42 -07006204 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = numChn - nNumChanCombinedConc; //reduce outstanding # of channels to be scanned
Jeff Johnson295189b2012-06-20 16:38:30 -07006205
6206 scanReq.BSSType = eCSR_BSS_TYPE_ANY;
6207 //Modify callers parameters in case of concurrency
6208 scanReq.scanType = eSIR_ACTIVE_SCAN;
Madan Mohan Koyyalamudi4ff9cd62012-10-30 17:48:57 -07006209 //Use concurrency values for min/maxChnTime.
6210 //We know csrIsAnySessionConnected(pMac) returns TRUE here
6211 csrSetDefaultScanTiming(pMac, scanReq.scanType, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07006212
6213 status = csrScanCopyRequest(pMac, &pSendScanCmd->u.scanCmd.u.scanRequest, &scanReq);
6214 if(!HAL_STATUS_SUCCESS(status))
6215 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006216 smsLog( pMac, LOGE, FL(" Failed to get copy csrScanRequest = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07006217 csrLLUnlock(&pMac->scan.scanCmdPendingList);
6218 return;
Madan Mohan Koyyalamudi0c626f32012-11-30 15:10:25 -08006219 }
6220 /* Clean the local scan variable */
6221 scanReq.ChannelInfo.ChannelList = NULL;
6222 scanReq.ChannelInfo.numOfChannels = 0;
6223 csrScanFreeRequest(pMac, &scanReq);
Jeff Johnson295189b2012-06-20 16:38:30 -07006224 }
6225 else
Madan Mohan Koyyalamudid6713582012-11-09 16:56:56 -08006226 {
6227 /* no active connected session present or numChn == 1
6228 * scan all remaining channels */
Jeff Johnson295189b2012-06-20 16:38:30 -07006229 pSendScanCmd = pScanCmd;
6230 //remove this command from pending list
6231 if (csrLLRemoveHead( &pMac->scan.scanCmdPendingList, LL_ACCESS_NOLOCK) == NULL)
6232 { //In case between PeekHead and here, the entry got removed by another thread.
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006233 smsLog( pMac, LOGE, FL(" Failed to remove entry from scanCmdPendingList"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006234 }
6235
6236 }
6237 csrQueueSmeCommand(pMac, pSendScanCmd, eANI_BOOLEAN_FALSE);
6238
6239 }
6240
Jeff Johnson295189b2012-06-20 16:38:30 -07006241 csrLLUnlock(&pMac->scan.scanCmdPendingList);
6242
6243}
6244#endif
6245
6246eHalStatus csrScanStartResultAgingTimer(tpAniSirGlobal pMac)
6247{
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006248 eHalStatus status = eHAL_STATUS_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006249
6250 if(pMac->scan.fScanEnable)
6251 {
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306252 status = vos_timer_start(&pMac->scan.hTimerResultAging, CSR_SCAN_RESULT_AGING_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006253 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006254 return (status);
6255}
6256
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006257eHalStatus csrScanStartResultCfgAgingTimer(tpAniSirGlobal pMac)
6258{
6259 eHalStatus status = eHAL_STATUS_FAILURE;
6260
6261 if(pMac->scan.fScanEnable)
6262 {
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306263 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 -08006264 }
6265 return (status);
6266}
Jeff Johnson295189b2012-06-20 16:38:30 -07006267
6268eHalStatus csrScanStopResultAgingTimer(tpAniSirGlobal pMac)
6269{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306270 return (vos_timer_stop(&pMac->scan.hTimerResultAging));
Jeff Johnson295189b2012-06-20 16:38:30 -07006271}
6272
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006273eHalStatus csrScanStopResultCfgAgingTimer(tpAniSirGlobal pMac)
6274{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306275 return (vos_timer_stop(&pMac->scan.hTimerResultCfgAging));
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006276}
Jeff Johnson295189b2012-06-20 16:38:30 -07006277
6278//This function returns the maximum time a BSS is allowed in the scan result.
6279//The time varies base on connection and power saving factors.
6280//Not connected, No PS
6281//Not connected, with PS
6282//Connected w/o traffic, No PS
6283//Connected w/o traffic, with PS
6284//Connected w/ traffic, no PS -- Not supported
6285//Connected w/ traffic, with PS -- Not supported
6286//the return unit is in seconds.
6287tANI_U32 csrScanGetAgeOutTime(tpAniSirGlobal pMac)
6288{
6289 tANI_U32 nRet;
6290
6291 if(pMac->scan.nAgingCountDown)
6292 {
6293 //Calculate what should be the timeout value for this
6294 nRet = pMac->scan.nLastAgeTimeOut * pMac->scan.nAgingCountDown;
6295 pMac->scan.nAgingCountDown--;
6296 }
6297 else
6298 {
6299 if( csrIsAllSessionDisconnected( pMac ) )
6300 {
6301 if(pmcIsPowerSaveEnabled(pMac, ePMC_IDLE_MODE_POWER_SAVE))
6302 {
6303 nRet = pMac->roam.configParam.scanAgeTimeNCPS;
6304 }
6305 else
6306 {
6307 nRet = pMac->roam.configParam.scanAgeTimeNCNPS;
6308 }
6309 }
6310 else
6311 {
6312 if(pmcIsPowerSaveEnabled(pMac, ePMC_BEACON_MODE_POWER_SAVE))
6313 {
6314 nRet = pMac->roam.configParam.scanAgeTimeCPS;
6315 }
6316 else
6317 {
6318 nRet = pMac->roam.configParam.scanAgeTimeCNPS;
6319 }
6320 }
6321 //If state-change causing aging time out change, we want to delay it somewhat to avoid
6322 //unnecessary removal of BSS. This is mostly due to transition from connect to disconnect.
6323 if(pMac->scan.nLastAgeTimeOut > nRet)
6324 {
6325 if(nRet)
6326 {
6327 pMac->scan.nAgingCountDown = (pMac->scan.nLastAgeTimeOut / nRet);
6328 }
6329 pMac->scan.nLastAgeTimeOut = nRet;
6330 nRet *= pMac->scan.nAgingCountDown;
6331 }
6332 else
6333 {
6334 pMac->scan.nLastAgeTimeOut = nRet;
6335 }
6336 }
6337
6338 return (nRet);
6339}
6340
6341
6342void csrScanResultAgingTimerHandler(void *pv)
6343{
6344 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6345 tANI_BOOLEAN fDisconnected = csrIsAllSessionDisconnected(pMac);
6346
6347 //no scan, no aging
6348 if(pMac->scan.fScanEnable &&
6349 (((eANI_BOOLEAN_FALSE == fDisconnected) && pMac->roam.configParam.bgScanInterval)
6350 || (fDisconnected && (pMac->scan.fCancelIdleScan == eANI_BOOLEAN_FALSE)))
6351 )
6352 {
6353 tListElem *pEntry, *tmpEntry;
6354 tCsrScanResult *pResult;
6355 tANI_TIMESTAMP ageOutTime = (tANI_TIMESTAMP)(csrScanGetAgeOutTime(pMac) * PAL_TICKS_PER_SECOND); //turn it into 10ms units
6356 tANI_TIMESTAMP curTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
6357
6358 csrLLLock(&pMac->scan.scanResultList);
6359 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
6360 while( pEntry )
6361 {
6362 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
6363 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
6364 if((curTime - pResult->Result.BssDescriptor.nReceivedTime) > ageOutTime)
6365 {
6366 smsLog(pMac, LOGW, " age out due to time out");
6367 csrScanAgeOutBss(pMac, pResult);
6368 }
6369 pEntry = tmpEntry;
6370 }
6371 csrLLUnlock(&pMac->scan.scanResultList);
6372 }
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306373 vos_timer_start(&pMac->scan.hTimerResultAging, CSR_SCAN_RESULT_AGING_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006374}
6375
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006376static void csrScanResultCfgAgingTimerHandler(void *pv)
6377{
6378 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6379 tListElem *pEntry, *tmpEntry;
6380 tCsrScanResult *pResult;
6381 tANI_TIMESTAMP ageOutTime = pMac->scan.scanResultCfgAgingTime * PAL_TICKS_PER_SECOND;
6382 tANI_TIMESTAMP curTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
6383
6384 csrLLLock(&pMac->scan.scanResultList);
6385 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
6386 while( pEntry )
6387 {
6388 tmpEntry = csrLLNext(&pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK);
6389 pResult = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
6390 if((curTime - pResult->Result.BssDescriptor.nReceivedTime) > ageOutTime)
6391 {
6392 smsLog(pMac, LOGW, " age out due to time out");
6393 csrScanAgeOutBss(pMac, pResult);
6394 }
6395 pEntry = tmpEntry;
6396 }
6397 csrLLUnlock(&pMac->scan.scanResultList);
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306398 vos_timer_start(&pMac->scan.hTimerResultCfgAging, CSR_SCAN_RESULT_CFG_AGING_INTERVAL/PAL_TIMER_TO_MS_UNIT);
Sandeep Puligilla2b6dc632012-12-17 14:44:16 -08006399}
Jeff Johnson295189b2012-06-20 16:38:30 -07006400
6401eHalStatus csrScanStartIdleScanTimer(tpAniSirGlobal pMac, tANI_U32 interval)
6402{
6403 eHalStatus status;
6404
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006405 smsLog(pMac, LOG1, " csrScanStartIdleScanTimer");
Jeff Johnson295189b2012-06-20 16:38:30 -07006406 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) && interval)
6407 {
6408 pMac->scan.nIdleScanTimeGap += interval;
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306409 vos_timer_stop(&pMac->scan.hTimerIdleScan);
6410 status = vos_timer_start(&pMac->scan.hTimerIdleScan, interval/PAL_TIMER_TO_MS_UNIT);
Jeff Johnson295189b2012-06-20 16:38:30 -07006411 if( !HAL_STATUS_SUCCESS(status) )
6412 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006413 smsLog(pMac, LOGE, " Fail to start Idle scan timer. status = %d interval = %d", status, interval);
Jeff Johnson295189b2012-06-20 16:38:30 -07006414 //This should not happen but set the flag to restart when ready
6415 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6416 }
6417 }
6418 else
6419 {
6420 if( pMac->scan.fScanEnable && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan) )
6421 {
6422 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6423 }
6424 status = eHAL_STATUS_FAILURE;
6425 }
6426
6427 return (status);
6428}
6429
6430
6431eHalStatus csrScanStopIdleScanTimer(tpAniSirGlobal pMac)
6432{
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05306433 return (vos_timer_stop(&pMac->scan.hTimerIdleScan));
Jeff Johnson295189b2012-06-20 16:38:30 -07006434}
6435
6436
6437//Stop CSR from asking for IMPS, This function doesn't disable IMPS from CSR
6438void csrScanSuspendIMPS( tpAniSirGlobal pMac )
6439{
6440 csrScanCancelIdleScan(pMac);
6441}
6442
6443
6444//Start CSR from asking for IMPS. This function doesn't trigger CSR to request entering IMPS
6445//because IMPS maybe disabled.
6446void csrScanResumeIMPS( tpAniSirGlobal pMac )
6447{
6448 csrScanStartIdleScan( pMac );
6449}
6450
6451
6452void csrScanIMPSCallback(void *callbackContext, eHalStatus status)
6453{
6454 tpAniSirGlobal pMac = PMAC_STRUCT( callbackContext );
6455
6456 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6457 {
6458 if(pMac->roam.configParam.IsIdleScanEnabled)
6459 {
6460 if(HAL_STATUS_SUCCESS(status))
6461 {
6462 if(csrIsAllSessionDisconnected(pMac) && !csrIsRoamCommandWaiting(pMac))
6463 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006464 smsLog(pMac, LOGW, FL("starts idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006465 csrScanAllChannels(pMac, eCSR_SCAN_IDLE_MODE_SCAN);
6466 }
6467 else
6468 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006469 smsLog(pMac, LOGW, FL("cannot start idle mode full scan"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006470 //even though we are in timer handle, calling stop timer will make sure the timer
6471 //doesn't get to restart.
6472 csrScanStopIdleScanTimer(pMac);
6473 }
6474 }
6475 else
6476 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006477 smsLog(pMac, LOGE, FL("sees not success status (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07006478 }
6479 }
6480 else
6481 {//we might need another flag to check if CSR needs to request imps at all
6482
6483 tANI_U32 nTime = 0;
6484
6485 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_FALSE;
6486 if(!HAL_STATUS_SUCCESS(csrScanTriggerIdleScan(pMac, &nTime)))
6487 {
6488 csrScanStartIdleScanTimer(pMac, nTime);
6489 }
6490 }
6491 }
6492}
6493
6494
6495//Param: pTimeInterval -- Caller allocated memory in return, if failed, to specify the nxt time interval for
6496//idle scan timer interval
6497//Return: Not success -- meaning it cannot start IMPS, caller needs to start a timer for idle scan
6498eHalStatus csrScanTriggerIdleScan(tpAniSirGlobal pMac, tANI_U32 *pTimeInterval)
6499{
6500 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
6501
6502 //Do not trigger IMPS in case of concurrency
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006503 if (vos_concurrent_sessions_running() && csrIsAnySessionInConnectState(pMac))
6504 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006505 smsLog( pMac, LOG1, FL("Cannot request IMPS because Concurrent Sessions Running") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006506 return (status);
Jeff Johnson04dd8a82012-06-29 20:41:40 -07006507 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006508
6509 if(pTimeInterval)
6510 {
6511 *pTimeInterval = 0;
6512 }
6513
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006514 smsLog(pMac, LOG3, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006515 if( smeCommandPending( pMac ) )
6516 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006517 smsLog( pMac, LOG1, FL(" Cannot request IMPS because command pending") );
Jeff Johnson295189b2012-06-20 16:38:30 -07006518 //Not to enter IMPS because more work to do
6519 if(pTimeInterval)
6520 {
6521 *pTimeInterval = 0;
6522 }
6523 //restart when ready
6524 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6525
6526 return (status);
6527 }
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07006528 if (IsPmcImpsReqFailed (pMac))
6529 {
6530 if(pTimeInterval)
6531 {
6532 *pTimeInterval = 1000000; //usec
6533 }
6534 //restart when ready
6535 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
Jeff Johnson295189b2012-06-20 16:38:30 -07006536
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07006537 return status;
6538 }
Jeff Johnson295189b2012-06-20 16:38:30 -07006539 if((pMac->scan.fScanEnable) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6540 /*&& pMac->roam.configParam.impsSleepTime*/)
6541 {
6542 //Stop get result timer because idle scan gets scan result out of PE
6543 csrScanStopGetResultTimer(pMac);
6544 if(pTimeInterval)
6545 {
6546 *pTimeInterval = pMac->roam.configParam.impsSleepTime;
6547 }
6548 //pmcRequestImps take a period in millisecond unit.
6549 status = pmcRequestImps(pMac, pMac->roam.configParam.impsSleepTime / PAL_TIMER_TO_MS_UNIT, csrScanIMPSCallback, pMac);
6550 if(!HAL_STATUS_SUCCESS(status))
6551 {
6552 if(eHAL_STATUS_PMC_ALREADY_IN_IMPS != status)
6553 {
6554 //Do restart the timer if CSR thinks it cannot do IMPS
6555 if( !csrCheckPSReady( pMac ) )
6556 {
6557 if(pTimeInterval)
6558 {
6559 *pTimeInterval = 0;
6560 }
6561 //Set the restart flag to true because that idle scan
6562 //can be restarted even though the timer will not be running
6563 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6564 }
6565 else
6566 {
6567 //For not now, we do a quicker retry
6568 if(pTimeInterval)
6569 {
6570 *pTimeInterval = CSR_IDLE_SCAN_WAIT_TIME;
6571 }
6572 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006573 smsLog(pMac, LOGW, FL("call pmcRequestImps and it returns status code (%d)"), status);
Jeff Johnson295189b2012-06-20 16:38:30 -07006574 }
6575 else
6576 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006577 smsLog(pMac, LOGW, FL("already in IMPS"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006578 //Since CSR is the only module to request for IMPS. If it is already in IMPS, CSR assumes
6579 //the callback will be called in the future. Should not happen though.
6580 status = eHAL_STATUS_SUCCESS;
6581 pMac->scan.nIdleScanTimeGap = 0;
6582 }
6583 }
6584 else
6585 {
6586 //requested so let's reset the value
6587 pMac->scan.nIdleScanTimeGap = 0;
6588 }
6589 }
6590
6591 return (status);
6592}
6593
6594
6595eHalStatus csrScanStartIdleScan(tpAniSirGlobal pMac)
6596{
6597 eHalStatus status = eHAL_STATUS_CSR_WRONG_STATE;
6598 tANI_U32 nTime = 0;
6599
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006600 smsLog(pMac, LOGW, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006601 if(pMac->roam.configParam.IsIdleScanEnabled)
6602 {
6603 //stop bg scan first
6604 csrScanBGScanAbort(pMac);
6605 //Stop get result timer because idle scan gets scan result out of PE
6606 csrScanStopGetResultTimer(pMac);
6607 //Enable aging timer since idle scan is going on
6608 csrScanStartResultAgingTimer(pMac);
6609 }
6610 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_FALSE;
6611 status = csrScanTriggerIdleScan(pMac, &nTime);
6612 if(!HAL_STATUS_SUCCESS(status))
6613 {
6614 csrScanStartIdleScanTimer(pMac, nTime);
6615 }
6616
6617 return (status);
6618}
6619
6620
6621void csrScanCancelIdleScan(tpAniSirGlobal pMac)
6622{
6623 if(eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan)
6624 {
Jeff Johnson295189b2012-06-20 16:38:30 -07006625 if (vos_concurrent_sessions_running()) {
6626 return;
6627 }
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006628 smsLog(pMac, LOG1, " csrScanCancelIdleScan");
Jeff Johnson295189b2012-06-20 16:38:30 -07006629 pMac->scan.fCancelIdleScan = eANI_BOOLEAN_TRUE;
6630 //Set the restart flag in case later on it is uncancelled
6631 pMac->scan.fRestartIdleScan = eANI_BOOLEAN_TRUE;
6632 csrScanStopIdleScanTimer(pMac);
6633 csrScanRemoveNotRoamingScanCommand(pMac);
6634 }
6635}
6636
6637
6638void csrScanIdleScanTimerHandler(void *pv)
6639{
6640 tpAniSirGlobal pMac = PMAC_STRUCT( pv );
6641 eHalStatus status;
6642 tANI_U32 nTime = 0;
6643
6644 smsLog(pMac, LOGW, " csrScanIdleScanTimerHandler called ");
Kiran Kumar Lokeref8c39922013-03-18 11:08:11 -07006645 pmcResetImpsFailStatus (pMac);
Jeff Johnson295189b2012-06-20 16:38:30 -07006646 status = csrScanTriggerIdleScan(pMac, &nTime);
6647 if(!HAL_STATUS_SUCCESS(status) && (eANI_BOOLEAN_FALSE == pMac->scan.fCancelIdleScan))
6648 {
6649 //Check whether it is time to actually do an idle scan
6650 if(pMac->scan.nIdleScanTimeGap >= pMac->roam.configParam.impsSleepTime)
6651 {
6652 pMac->scan.nIdleScanTimeGap = 0;
6653 csrScanIMPSCallback(pMac, eHAL_STATUS_SUCCESS);
6654 }
6655 else
6656 {
6657 csrScanStartIdleScanTimer(pMac, nTime);
6658 }
6659 }
6660}
6661
6662
6663
6664
6665tANI_BOOLEAN csrScanRemoveNotRoamingScanCommand(tpAniSirGlobal pMac)
6666{
6667 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
6668 tListElem *pEntry, *pEntryTmp;
6669 tSmeCmd *pCommand;
6670 tDblLinkList localList;
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306671 tDblLinkList *pCmdList;
Jeff Johnson295189b2012-06-20 16:38:30 -07006672
6673 vos_mem_zero(&localList, sizeof(tDblLinkList));
6674 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
6675 {
6676 smsLog(pMac, LOGE, FL(" failed to open list"));
6677 return fRet;
6678 }
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306679 if (!pMac->fScanOffload)
6680 pCmdList = &pMac->sme.smeCmdPendingList;
6681 else
6682 pCmdList = &pMac->sme.smeScanCmdPendingList;
Jeff Johnson295189b2012-06-20 16:38:30 -07006683
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306684 csrLLLock(pCmdList);
6685 pEntry = csrLLPeekHead(pCmdList, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07006686 while(pEntry)
6687 {
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306688 pEntryTmp = csrLLNext(pCmdList, pEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07006689 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6690 if( eSmeCommandScan == pCommand->command )
6691 {
6692 switch( pCommand->u.scanCmd.reason )
6693 {
6694 case eCsrScanIdleScan:
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306695 if( csrLLRemoveEntry(pCmdList, pEntry, LL_ACCESS_NOLOCK) )
Jeff Johnson295189b2012-06-20 16:38:30 -07006696 {
6697 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
6698 }
6699 fRet = eANI_BOOLEAN_TRUE;
6700 break;
6701
6702 default:
6703 break;
6704 } //switch
6705 }
6706 pEntry = pEntryTmp;
6707 }
6708
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306709 csrLLUnlock(pCmdList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006710
6711 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
6712 {
6713 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6714 csrReleaseCommandScan( pMac, pCommand );
6715 }
6716
6717 csrLLClose(&localList);
6718
6719 return (fRet);
6720}
6721
6722
6723tANI_BOOLEAN csrScanRemoveFreshScanCommand(tpAniSirGlobal pMac, tANI_U8 sessionId)
6724{
6725 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
6726 tListElem *pEntry, *pEntryTmp;
6727 tSmeCmd *pCommand;
6728 tDblLinkList localList;
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306729 tDblLinkList *pCmdList;
Jeff Johnson295189b2012-06-20 16:38:30 -07006730
6731 vos_mem_zero(&localList, sizeof(tDblLinkList));
6732 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
6733 {
6734 smsLog(pMac, LOGE, FL(" failed to open list"));
6735 return fRet;
6736 }
6737
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306738 if (!pMac->fScanOffload)
6739 pCmdList = &pMac->sme.smeCmdPendingList;
6740 else
6741 pCmdList = &pMac->sme.smeScanCmdPendingList;
6742
6743 csrLLLock(pCmdList);
6744 pEntry = csrLLPeekHead(pCmdList, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07006745 while(pEntry)
6746 {
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306747 pEntryTmp = csrLLNext(pCmdList, pEntry, LL_ACCESS_NOLOCK);
Jeff Johnson295189b2012-06-20 16:38:30 -07006748 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6749 if( (eSmeCommandScan == pCommand->command) && (sessionId == pCommand->sessionId) )
6750 {
6751 switch(pCommand->u.scanCmd.reason)
6752 {
Varun Reddy Yeturud0a3f252013-04-15 21:58:13 -07006753#ifdef WLAN_FEATURE_ROAM_SCAN_OFFLOAD
6754 case eCsrScanGetLfrResult:
6755#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07006756 case eCsrScanGetResult:
6757 case eCsrScanSetBGScanParam:
6758 case eCsrScanBGScanAbort:
6759 case eCsrScanBGScanEnable:
6760 case eCsrScanGetScanChnInfo:
6761 break;
6762 default:
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006763 smsLog (pMac, LOGW, "%s: -------- abort scan command reason = %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07006764 __func__, pCommand->u.scanCmd.reason);
Jeff Johnson295189b2012-06-20 16:38:30 -07006765 //The rest are fresh scan requests
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306766 if( csrLLRemoveEntry(pCmdList, pEntry, LL_ACCESS_NOLOCK) )
Jeff Johnson295189b2012-06-20 16:38:30 -07006767 {
6768 csrLLInsertTail(&localList, pEntry, LL_ACCESS_NOLOCK);
6769 }
6770 fRet = eANI_BOOLEAN_TRUE;
6771 break;
6772 }
6773 }
6774 pEntry = pEntryTmp;
6775 }
6776
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05306777 csrLLUnlock(pCmdList);
Jeff Johnson295189b2012-06-20 16:38:30 -07006778
6779 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
6780 {
6781 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
6782 if (pCommand->u.scanCmd.callback)
6783 {
6784 /* User scan request is pending,
6785 * send response with status eCSR_SCAN_ABORT*/
6786 pCommand->u.scanCmd.callback(pMac,
6787 pCommand->u.scanCmd.pContext,
6788 pCommand->u.scanCmd.scanID,
6789 eCSR_SCAN_ABORT);
6790 }
6791 csrReleaseCommandScan( pMac, pCommand );
6792 }
6793 csrLLClose(&localList);
6794
6795 return (fRet);
6796}
6797
6798
6799void csrReleaseScanCommand(tpAniSirGlobal pMac, tSmeCmd *pCommand, eCsrScanStatus scanStatus)
6800{
6801 eCsrScanReason reason = pCommand->u.scanCmd.reason;
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306802 tANI_BOOLEAN status;
6803
6804 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07006805 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306806 tANI_U32 i;
6807 for(i = 0; i < CSR_ROAM_SESSION_MAX; i++)
6808 csrRoamStateChange(pMac, pCommand->u.scanCmd.lastRoamState[i], i);
6809 }
6810 else
6811 {
6812 csrRoamStateChange(pMac,
6813 pCommand->u.scanCmd.lastRoamState[pCommand->sessionId],
6814 pCommand->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07006815 }
6816
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306817 csrScanCallCallback(pMac, pCommand, scanStatus);
Jeff Johnson295189b2012-06-20 16:38:30 -07006818
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006819 smsLog(pMac, LOG3, " Remove Scan command reason = %d", reason);
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306820 if (pMac->fScanOffload)
6821 {
6822 status = csrLLRemoveEntry(&pMac->sme.smeScanCmdActiveList,
6823 &pCommand->Link, LL_ACCESS_LOCK);
6824 }
6825 else
6826 {
6827 status = csrLLRemoveEntry(&pMac->sme.smeCmdActiveList,
6828 &pCommand->Link, LL_ACCESS_LOCK);
6829 }
6830
6831 if(status)
Jeff Johnson295189b2012-06-20 16:38:30 -07006832 {
6833 csrReleaseCommandScan( pMac, pCommand );
6834 }
6835 else
6836 {
Madan Mohan Koyyalamudie1a64b42013-06-19 16:34:44 +05306837 smsLog(pMac, LOGE,
6838 " ********csrReleaseScanCommand cannot release command reason %d",
6839 pCommand->u.scanCmd.reason );
Jeff Johnson295189b2012-06-20 16:38:30 -07006840 }
6841}
6842
6843
6844eHalStatus csrScanGetPMKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
6845 tPmkidCandidateInfo *pPmkidList, tANI_U32 *pNumItems )
6846{
6847 eHalStatus status = eHAL_STATUS_SUCCESS;
6848 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
6849
Jeff Johnson32d95a32012-09-10 13:15:23 -07006850 if(!pSession)
6851 {
6852 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
6853 return eHAL_STATUS_FAILURE;
6854 }
6855
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006856 smsLog(pMac, LOGW, " pMac->scan.NumPmkidCandidate = %d", pSession->NumPmkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07006857 csrResetPMKIDCandidateList(pMac, sessionId);
6858 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
6859 {
6860 tCsrScanResultFilter *pScanFilter;
6861 tCsrScanResultInfo *pScanResult;
6862 tScanResultHandle hBSSList;
6863 tANI_U32 nItems = *pNumItems;
6864
6865 *pNumItems = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05306866 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
6867 if ( NULL == pScanFilter )
6868 status = eHAL_STATUS_FAILURE;
6869 else
Jeff Johnson295189b2012-06-20 16:38:30 -07006870 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306871 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006872 //Here is the profile we need to connect to
6873 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
6874 if(HAL_STATUS_SUCCESS(status))
6875 {
6876 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
6877 if(HAL_STATUS_SUCCESS(status))
6878 {
6879 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumPmkidCandidate < nItems))
6880 {
6881 //NumPmkidCandidate adds up here
6882 csrProcessBSSDescForPMKIDList(pMac, &pScanResult->BssDescriptor,
6883 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
6884 }
6885 if(pSession->NumPmkidCandidate)
6886 {
6887 *pNumItems = pSession->NumPmkidCandidate;
Kiet Lam64c1b492013-07-12 13:56:44 +05306888 vos_mem_copy(pPmkidList, pSession->PmkidCandidateInfo,
6889 pSession->NumPmkidCandidate * sizeof(tPmkidCandidateInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07006890 }
6891 csrScanResultPurge(pMac, hBSSList);
6892 }//Have scan result
6893 csrFreeScanFilter(pMac, pScanFilter);
6894 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306895 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07006896 }
6897 }
6898
6899 return (status);
6900}
6901
6902
6903
6904#ifdef FEATURE_WLAN_WAPI
6905eHalStatus csrScanGetBKIDCandidateList(tpAniSirGlobal pMac, tANI_U32 sessionId,
6906 tBkidCandidateInfo *pBkidList, tANI_U32 *pNumItems )
6907{
6908 eHalStatus status = eHAL_STATUS_SUCCESS;
6909 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
6910
Jeff Johnson32d95a32012-09-10 13:15:23 -07006911 if(!pSession)
6912 {
6913 smsLog(pMac, LOGE, FL(" session %d not found "), sessionId);
6914 return eHAL_STATUS_FAILURE;
6915 }
6916
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006917 smsLog(pMac, LOGW, " pMac->scan.NumBkidCandidate = %d", pSession->NumBkidCandidate);
Jeff Johnson295189b2012-06-20 16:38:30 -07006918 csrResetBKIDCandidateList(pMac, sessionId);
6919 if(csrIsConnStateConnected(pMac, sessionId) && pSession->pCurRoamProfile)
6920 {
6921 tCsrScanResultFilter *pScanFilter;
6922 tCsrScanResultInfo *pScanResult;
6923 tScanResultHandle hBSSList;
6924 tANI_U32 nItems = *pNumItems;
6925 *pNumItems = 0;
Kiet Lam64c1b492013-07-12 13:56:44 +05306926 pScanFilter = vos_mem_malloc(sizeof(tCsrScanResultFilter));
6927 if ( NULL == pScanFilter )
6928 status = eHAL_STATUS_FAILURE;
6929 else
Jeff Johnson295189b2012-06-20 16:38:30 -07006930 {
Kiet Lam64c1b492013-07-12 13:56:44 +05306931 vos_mem_set(pScanFilter, sizeof(tCsrScanResultFilter), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07006932 //Here is the profile we need to connect to
6933 status = csrRoamPrepareFilterFromProfile(pMac, pSession->pCurRoamProfile, pScanFilter);
6934 if(HAL_STATUS_SUCCESS(status))
6935 {
6936 status = csrScanGetResult(pMac, pScanFilter, &hBSSList);
6937 if(HAL_STATUS_SUCCESS(status))
6938 {
6939 while(((pScanResult = csrScanResultGetNext(pMac, hBSSList)) != NULL) && ( pSession->NumBkidCandidate < nItems))
6940 {
6941 //pMac->scan.NumBkidCandidate adds up here
6942 csrProcessBSSDescForBKIDList(pMac, &pScanResult->BssDescriptor,
6943 (tDot11fBeaconIEs *)( pScanResult->pvIes ));
6944
6945 }
6946 if(pSession->NumBkidCandidate)
6947 {
6948 *pNumItems = pSession->NumBkidCandidate;
Kiet Lam64c1b492013-07-12 13:56:44 +05306949 vos_mem_copy(pBkidList, pSession->BkidCandidateInfo, pSession->NumBkidCandidate * sizeof(tBkidCandidateInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07006950 }
6951 csrScanResultPurge(pMac, hBSSList);
6952 }//Have scan result
6953 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306954 vos_mem_free(pScanFilter);
Jeff Johnson295189b2012-06-20 16:38:30 -07006955 }
6956 }
6957
6958 return (status);
6959}
6960#endif /* FEATURE_WLAN_WAPI */
6961
6962
6963
6964//This function is usually used for BSSs that suppresses SSID so the profile
6965//shall have one and only one SSID
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07006966eHalStatus csrScanForSSID(tpAniSirGlobal pMac, tANI_U32 sessionId, tCsrRoamProfile *pProfile, tANI_U32 roamId, tANI_BOOLEAN notify)
Jeff Johnson295189b2012-06-20 16:38:30 -07006967{
6968 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
6969 tSmeCmd *pScanCmd = NULL;
6970 tANI_U8 bAddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
6971 tANI_U8 index = 0;
6972 tANI_U32 numSsid = pProfile->SSIDs.numOfSSIDs;
6973
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006974 smsLog(pMac, LOG2, FL("called"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006975 //For WDS, we use the index 0. There must be at least one in there
6976 if( CSR_IS_WDS_STA( pProfile ) && numSsid )
6977 {
6978 numSsid = 1;
6979 }
6980 if(pMac->scan.fScanEnable && ( numSsid == 1 ) )
6981 {
6982 do
6983 {
6984 pScanCmd = csrGetCommandBuffer(pMac);
6985 if(!pScanCmd)
6986 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08006987 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07006988 break;
6989 }
Kiet Lam64c1b492013-07-12 13:56:44 +05306990 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
6991 pScanCmd->u.scanCmd.pToRoamProfile = vos_mem_malloc(sizeof(tCsrRoamProfile));
6992 if ( NULL == pScanCmd->u.scanCmd.pToRoamProfile )
6993 status = eHAL_STATUS_FAILURE;
6994 else
6995 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07006996 status = csrRoamCopyProfile(pMac, pScanCmd->u.scanCmd.pToRoamProfile, pProfile);
6997 if(!HAL_STATUS_SUCCESS(status))
6998 break;
6999 pScanCmd->u.scanCmd.roamId = roamId;
7000 pScanCmd->command = eSmeCommandScan;
Jeff Johnsone7245742012-09-05 17:12:55 -07007001 pScanCmd->sessionId = (tANI_U8)sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07007002 pScanCmd->u.scanCmd.callback = NULL;
7003 pScanCmd->u.scanCmd.pContext = NULL;
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007004 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 -07007005 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
Kiet Lam64c1b492013-07-12 13:56:44 +05307006 vos_mem_set(&pScanCmd->u.scanCmd.u.scanRequest, sizeof(tCsrScanRequest), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007007 pScanCmd->u.scanCmd.u.scanRequest.scanType = eSIR_ACTIVE_SCAN;
Jeff Johnson295189b2012-06-20 16:38:30 -07007008 pScanCmd->u.scanCmd.u.scanRequest.BSSType = pProfile->BSSType;
Jeff Johnsone7245742012-09-05 17:12:55 -07007009 // To avoid 11b rate in probe request Set p2pSearch flag as 1 for P2P Client Mode
7010 if(VOS_P2P_CLIENT_MODE == pProfile->csrPersona)
7011 {
7012 pScanCmd->u.scanCmd.u.scanRequest.p2pSearch = 1;
7013 }
7014 if(pProfile->pAddIEScan)
7015 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307016 pScanCmd->u.scanCmd.u.scanRequest.pIEField = vos_mem_malloc(
7017 pProfile->nAddIEScanLength);
7018 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.pIEField )
7019 status = eHAL_STATUS_FAILURE;
7020 else
7021 status = eHAL_STATUS_SUCCESS;
7022 vos_mem_set(pScanCmd->u.scanCmd.u.scanRequest.pIEField,
7023 pProfile->nAddIEScanLength, 0);
7024 if (HAL_STATUS_SUCCESS(status))
Jeff Johnsone7245742012-09-05 17:12:55 -07007025 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307026 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.pIEField,
7027 pProfile->pAddIEScan, pProfile->nAddIEScanLength);
Jeff Johnsone7245742012-09-05 17:12:55 -07007028 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = pProfile->nAddIEScanLength;
7029 }
7030 else
7031 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007032 smsLog(pMac, LOGE, "No memory for scanning IE fields");
Jeff Johnsone7245742012-09-05 17:12:55 -07007033 }
7034 } //Allocate memory for IE field
7035 else
7036 {
7037 pScanCmd->u.scanCmd.u.scanRequest.uIEFieldLen = 0;
7038 }
Jeff Johnson32d95a32012-09-10 13:15:23 -07007039 /* For one channel be good enpugh time to receive beacon atleast */
7040 if( 1 == pProfile->ChannelInfo.numOfChannels )
7041 {
7042 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime = MAX_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7043 pScanCmd->u.scanCmd.u.scanRequest.minChnTime = MIN_ACTIVE_SCAN_FOR_ONE_CHANNEL;
7044 }
7045 else
7046 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307047 pScanCmd->u.scanCmd.u.scanRequest.maxChnTime =
7048 pMac->roam.configParam.nActiveMaxChnTime;
7049 pScanCmd->u.scanCmd.u.scanRequest.minChnTime =
7050 pMac->roam.configParam.nActiveMinChnTime;
Jeff Johnson32d95a32012-09-10 13:15:23 -07007051 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307052 pScanCmd->u.scanCmd.u.scanRequest.maxChnTimeBtc =
7053 pMac->roam.configParam.nActiveMaxChnTimeBtc;
7054 pScanCmd->u.scanCmd.u.scanRequest.minChnTimeBtc =
7055 pMac->roam.configParam.nActiveMinChnTimeBtc;
Jeff Johnson295189b2012-06-20 16:38:30 -07007056 if(pProfile->BSSIDs.numOfBSSIDs == 1)
7057 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307058 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.bssid,
7059 pProfile->BSSIDs.bssid, sizeof(tCsrBssid));
Jeff Johnson295189b2012-06-20 16:38:30 -07007060 }
7061 else
7062 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307063 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.bssid, bAddr, 6);
Jeff Johnson295189b2012-06-20 16:38:30 -07007064 }
7065 if(pProfile->ChannelInfo.numOfChannels)
7066 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307067 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList = vos_mem_malloc(
7068 sizeof(*pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList)
7069 * pProfile->ChannelInfo.numOfChannels);
7070 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList )
7071 status = eHAL_STATUS_FAILURE;
7072 else
7073 status = eHAL_STATUS_SUCCESS;
7074 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
7075 if(HAL_STATUS_SUCCESS(status))
Jeff Johnson295189b2012-06-20 16:38:30 -07007076 {
7077 csrRoamIsChannelValid(pMac, pProfile->ChannelInfo.ChannelList[0]);
7078 for(index = 0; index < pProfile->ChannelInfo.numOfChannels; index++)
7079 {
7080 if(csrRoamIsValidChannel(pMac, pProfile->ChannelInfo.ChannelList[index]))
7081 {
7082 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.ChannelList[pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels]
7083 = pProfile->ChannelInfo.ChannelList[index];
7084 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels++;
7085 }
7086 else
7087 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007088 smsLog(pMac, LOGW, FL("process a channel (%d) that is invalid"), pProfile->ChannelInfo.ChannelList[index]);
Jeff Johnson295189b2012-06-20 16:38:30 -07007089 }
7090
7091 }
7092 }
7093 else
7094 {
7095 break;
7096 }
7097
7098 }
7099 else
7100 {
7101 pScanCmd->u.scanCmd.u.scanRequest.ChannelInfo.numOfChannels = 0;
7102 }
7103 if(pProfile->SSIDs.numOfSSIDs)
7104 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307105 pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList = vos_mem_malloc(
7106 pProfile->SSIDs.numOfSSIDs * sizeof(tCsrSSIDInfo));
7107 if ( NULL == pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList )
7108 status = eHAL_STATUS_FAILURE;
7109 else
7110 status = eHAL_STATUS_SUCCESS;
Jeff Johnson295189b2012-06-20 16:38:30 -07007111 if(!HAL_STATUS_SUCCESS(status))
7112 {
7113 break;
7114 }
7115 pScanCmd->u.scanCmd.u.scanRequest.SSIDs.numOfSSIDs = 1;
Kiet Lam64c1b492013-07-12 13:56:44 +05307116 vos_mem_copy(pScanCmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList,
7117 pProfile->SSIDs.SSIDList, sizeof(tCsrSSIDInfo));
Jeff Johnson295189b2012-06-20 16:38:30 -07007118 }
7119 //Start process the command
7120 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
7121 if( !HAL_STATUS_SUCCESS( status ) )
7122 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007123 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07007124 break;
7125 }
7126 }while(0);
7127 if(!HAL_STATUS_SUCCESS(status))
7128 {
7129 if(pScanCmd)
7130 {
7131 csrReleaseCommandScan(pMac, pScanCmd);
7132 //TODO:free the memory that is allocated in this function
7133 }
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007134 if(notify)
7135 {
Jeff Johnson295189b2012-06-20 16:38:30 -07007136 csrRoamCallCallback(pMac, sessionId, NULL, roamId, eCSR_ROAM_FAILED, eCSR_ROAM_RESULT_FAILURE);
7137 }
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07007138 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007139 }//valid
7140 else
7141 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007142 smsLog(pMac, LOGE, FL("cannot scan because scanEnable (%d) or numSSID (%d) is invalid"),
Jeff Johnson295189b2012-06-20 16:38:30 -07007143 pMac->scan.fScanEnable, pProfile->SSIDs.numOfSSIDs);
7144 }
7145
7146 return (status);
7147}
7148
7149
7150//Issue a scan base on the new capability infomation
7151//This should only happen when the associated AP changes its capability.
7152//After this scan is done, CSR reroams base on the new scan results
7153eHalStatus csrScanForCapabilityChange(tpAniSirGlobal pMac, tSirSmeApNewCaps *pNewCaps)
7154{
7155 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
7156 tSmeCmd *pScanCmd = NULL;
7157
7158 if(pNewCaps)
7159 {
7160 do
7161 {
7162 pScanCmd = csrGetCommandBuffer(pMac);
7163 if(!pScanCmd)
7164 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007165 smsLog(pMac, LOGE, FL("failed to allocate command buffer"));
Jeff Johnson295189b2012-06-20 16:38:30 -07007166 status = eHAL_STATUS_RESOURCES;
7167 break;
7168 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307169 vos_mem_set(&pScanCmd->u.scanCmd, sizeof(tScanCmd), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007170 status = eHAL_STATUS_SUCCESS;
7171 pScanCmd->u.scanCmd.roamId = 0;
7172 pScanCmd->command = eSmeCommandScan;
7173 pScanCmd->u.scanCmd.callback = NULL;
7174 pScanCmd->u.scanCmd.pContext = NULL;
7175 pScanCmd->u.scanCmd.reason = eCsrScanForCapsChange;
7176 pScanCmd->u.scanCmd.scanID = pMac->scan.nextScanID++; //let it wrap around
7177 status = csrQueueSmeCommand(pMac, pScanCmd, eANI_BOOLEAN_FALSE);
7178 if( !HAL_STATUS_SUCCESS( status ) )
7179 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007180 smsLog( pMac, LOGE, FL(" fail to send message status = %d"), status );
Jeff Johnson295189b2012-06-20 16:38:30 -07007181 break;
7182 }
7183 }while(0);
7184 if(!HAL_STATUS_SUCCESS(status))
7185 {
7186 if(pScanCmd)
7187 {
7188 csrReleaseCommandScan(pMac, pScanCmd);
7189 }
7190 }
7191 }
7192
7193 return (status);
7194}
7195
7196
7197
7198void csrInitBGScanChannelList(tpAniSirGlobal pMac)
7199{
7200 tANI_U32 len = CSR_MIN(sizeof(pMac->roam.validChannelList), sizeof(pMac->scan.bgScanChannelList));
7201
Kiet Lam64c1b492013-07-12 13:56:44 +05307202 vos_mem_set(pMac->scan.bgScanChannelList, len, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007203 pMac->scan.numBGScanChannel = 0;
7204
7205 if(HAL_STATUS_SUCCESS(csrGetCfgValidChannels(pMac, pMac->roam.validChannelList, &len)))
7206 {
7207 pMac->roam.numValidChannels = len;
7208 pMac->scan.numBGScanChannel = (tANI_U8)CSR_MIN(len, WNI_CFG_BG_SCAN_CHANNEL_LIST_LEN);
Kiet Lam64c1b492013-07-12 13:56:44 +05307209 vos_mem_copy(pMac->scan.bgScanChannelList, pMac->roam.validChannelList,
7210 pMac->scan.numBGScanChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07007211 csrSetBGScanChannelList(pMac, pMac->scan.bgScanChannelList, pMac->scan.numBGScanChannel);
7212 }
7213}
7214
7215
7216//This function return TRUE if background scan channel list is adjusted.
7217//this function will only shrink the background scan channel list
7218tANI_BOOLEAN csrAdjustBGScanChannelList(tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels,
7219 tANI_U8 *pAdjustChannels, tANI_U8 *pNumAdjustChannels)
7220{
7221 tANI_BOOLEAN fRet = eANI_BOOLEAN_FALSE;
7222 tANI_U8 i, j, count = *pNumAdjustChannels;
7223
7224 i = 0;
7225 while(i < count)
7226 {
7227 for(j = 0; j < NumChannels; j++)
7228 {
7229 if(pChannelList[j] == pAdjustChannels[i])
7230 break;
7231 }
7232 if(j == NumChannels)
7233 {
7234 //This channel is not in the list, remove it
7235 fRet = eANI_BOOLEAN_TRUE;
7236 count--;
7237 if(count - i)
7238 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307239 vos_mem_copy(&pAdjustChannels[i], &pAdjustChannels[i+1], count - i);
Jeff Johnson295189b2012-06-20 16:38:30 -07007240 }
7241 else
7242 {
7243 //already remove the last one. Done.
7244 break;
7245 }
7246 }
7247 else
7248 {
7249 i++;
7250 }
7251 }//while(i<count)
7252 *pNumAdjustChannels = count;
7253
7254 return (fRet);
7255}
7256
7257
7258//Get the list of the base channels to scan for passively 11d info
7259eHalStatus csrScanGetSupportedChannels( tpAniSirGlobal pMac )
7260{
7261 eHalStatus status = eHAL_STATUS_SUCCESS;
7262 int n = WNI_CFG_VALID_CHANNEL_LIST_LEN;
7263
7264 status = vos_nv_getSupportedChannels( pMac->scan.baseChannels.channelList, &n, NULL, NULL );
7265 if( HAL_STATUS_SUCCESS(status) )
7266 {
7267 pMac->scan.baseChannels.numChannels = (tANI_U8)n;
7268 }
7269 else
7270 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007271 smsLog( pMac, LOGE, FL(" failed") );
Jeff Johnson295189b2012-06-20 16:38:30 -07007272 pMac->scan.baseChannels.numChannels = 0;
7273 }
7274
7275 return ( status );
7276}
7277
7278//This function use the input pChannelList to validate the current saved channel list
7279eHalStatus csrSetBGScanChannelList( tpAniSirGlobal pMac, tANI_U8 *pAdjustChannels, tANI_U8 NumAdjustChannels)
7280{
7281 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumAdjustChannels;
7282
7283 return (ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pAdjustChannels, dataLen, NULL, eANI_BOOLEAN_FALSE));
7284}
7285
7286
7287void csrSetCfgValidChannelList( tpAniSirGlobal pMac, tANI_U8 *pChannelList, tANI_U8 NumChannels )
7288{
7289 tANI_U32 dataLen = sizeof( tANI_U8 ) * NumChannels;
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05307290 eHalStatus status;
Jeff Johnson295189b2012-06-20 16:38:30 -07007291
7292 ccmCfgSetStr(pMac, WNI_CFG_VALID_CHANNEL_LIST, pChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
7293
Gopichand Nakkalaf72a3872013-06-11 17:51:13 +05307294 if (pMac->fScanOffload)
7295 {
7296 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
7297 "Scan offload is enabled, update default chan list");
7298 status = csrUpdateChannelList(&pMac->scan);
7299 if (eHAL_STATUS_SUCCESS != status)
7300 {
7301 VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR,
7302 "failed to update the supported channel list");
7303 }
7304 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007305 return;
7306}
7307
7308
7309
7310/*
7311 * The Tx power limits are saved in the cfg for future usage.
7312 */
7313void csrSaveTxPowerToCfg( tpAniSirGlobal pMac, tDblLinkList *pList, tANI_U32 cfgId )
7314{
7315 tListElem *pEntry;
7316 tANI_U32 cbLen = 0, dataLen;
7317 tCsrChannelPowerInfo *pChannelSet;
7318 tANI_U32 idx;
7319 tSirMacChanInfo *pChannelPowerSet;
7320 tANI_U8 *pBuf = NULL;
7321
7322 //allocate maximum space for all channels
7323 dataLen = WNI_CFG_VALID_CHANNEL_LIST_LEN * sizeof(tSirMacChanInfo);
Kiet Lam64c1b492013-07-12 13:56:44 +05307324 if ( (pBuf = vos_mem_malloc(dataLen)) != NULL )
Jeff Johnson295189b2012-06-20 16:38:30 -07007325 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307326 vos_mem_set(pBuf, dataLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007327 pChannelPowerSet = (tSirMacChanInfo *)(pBuf);
7328
7329 pEntry = csrLLPeekHead( pList, LL_ACCESS_LOCK );
7330 // write the tuples (startChan, numChan, txPower) for each channel found in the channel power list.
7331 while( pEntry )
7332 {
7333 pChannelSet = GET_BASE_ADDR( pEntry, tCsrChannelPowerInfo, link );
7334 if ( 1 != pChannelSet->interChannelOffset )
7335 {
7336 // we keep the 5G channel sets internally with an interchannel offset of 4. Expand these
7337 // to the right format... (inter channel offset of 1 is the only option for the triplets
7338 // that 11d advertises.
7339 if ((cbLen + (pChannelSet->numChannels * sizeof(tSirMacChanInfo))) >= dataLen)
7340 {
7341 // expanding this entry will overflow our allocation
7342 smsLog(pMac, LOGE,
7343 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007344 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07007345 pChannelSet->firstChannel,
7346 pChannelSet->numChannels,
7347 pChannelSet->interChannelOffset);
7348 break;
7349 }
7350
7351 for( idx = 0; idx < pChannelSet->numChannels; idx++ )
7352 {
7353 pChannelPowerSet->firstChanNum = (tSirMacChanNum)(pChannelSet->firstChannel + ( idx * pChannelSet->interChannelOffset ));
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007354 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07007355 pChannelPowerSet->numChannels = 1;
Jeff Johnson295189b2012-06-20 16:38:30 -07007356 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007357 smsLog(pMac, LOG3, " Setting Max Transmit Power %d", pChannelPowerSet->maxTxPower);
Jeff Johnson295189b2012-06-20 16:38:30 -07007358 cbLen += sizeof( tSirMacChanInfo );
7359 pChannelPowerSet++;
7360 }
7361 }
7362 else
7363 {
7364 if (cbLen >= dataLen)
7365 {
7366 // this entry will overflow our allocation
7367 smsLog(pMac, LOGE,
7368 "%s: Buffer overflow, start %d, num %d, offset %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07007369 __func__,
Jeff Johnson295189b2012-06-20 16:38:30 -07007370 pChannelSet->firstChannel,
7371 pChannelSet->numChannels,
7372 pChannelSet->interChannelOffset);
7373 break;
7374 }
7375 pChannelPowerSet->firstChanNum = pChannelSet->firstChannel;
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007376 smsLog(pMac, LOG3, " Setting Channel Number %d", pChannelPowerSet->firstChanNum);
Jeff Johnson295189b2012-06-20 16:38:30 -07007377 pChannelPowerSet->numChannels = pChannelSet->numChannels;
Jeff Johnson295189b2012-06-20 16:38:30 -07007378 pChannelPowerSet->maxTxPower = CSR_ROAM_MIN( pChannelSet->txPower, pMac->roam.configParam.nTxPowerCap );
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007379 smsLog(pMac, LOG3, " Setting Max Transmit Power %d, nTxPower %d", pChannelPowerSet->maxTxPower,pMac->roam.configParam.nTxPowerCap );
Jeff Johnson295189b2012-06-20 16:38:30 -07007380
7381
7382 cbLen += sizeof( tSirMacChanInfo );
7383 pChannelPowerSet++;
7384 }
7385
7386 pEntry = csrLLNext( pList, pEntry, LL_ACCESS_LOCK );
7387 }
7388
7389 if(cbLen)
7390 {
7391 ccmCfgSetStr(pMac, cfgId, (tANI_U8 *)pBuf, cbLen, NULL, eANI_BOOLEAN_FALSE);
7392 }
Kiet Lam64c1b492013-07-12 13:56:44 +05307393 vos_mem_free(pBuf);
Jeff Johnson295189b2012-06-20 16:38:30 -07007394 }//Allocate memory
7395}
7396
7397
7398void csrSetCfgCountryCode( tpAniSirGlobal pMac, tANI_U8 *countryCode )
7399{
7400 tANI_U8 cc[WNI_CFG_COUNTRY_CODE_LEN];
7401 ///v_REGDOMAIN_t DomainId;
7402
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007403 smsLog( pMac, LOG3, "Setting Country Code in Cfg from csrSetCfgCountryCode %s",countryCode );
Kiet Lam64c1b492013-07-12 13:56:44 +05307404 vos_mem_copy(cc, countryCode, WNI_CFG_COUNTRY_CODE_LEN);
Jeff Johnson295189b2012-06-20 16:38:30 -07007405
7406 // don't program the bogus country codes that we created for Korea in the MAC. if we see
7407 // the bogus country codes, program the MAC with the right country code.
7408 if ( ( 'K' == countryCode[ 0 ] && '1' == countryCode[ 1 ] ) ||
7409 ( 'K' == countryCode[ 0 ] && '2' == countryCode[ 1 ] ) ||
7410 ( 'K' == countryCode[ 0 ] && '3' == countryCode[ 1 ] ) ||
7411 ( 'K' == countryCode[ 0 ] && '4' == countryCode[ 1 ] ) )
7412 {
7413 // replace the alternate Korea country codes, 'K1', 'K2', .. with 'KR' for Korea
7414 cc[ 1 ] = 'R';
7415 }
7416 ccmCfgSetStr(pMac, WNI_CFG_COUNTRY_CODE, cc, WNI_CFG_COUNTRY_CODE_LEN, NULL, eANI_BOOLEAN_FALSE);
7417
7418 //Need to let HALPHY know about the current domain so it can apply some
7419 //domain-specific settings (TX filter...)
7420 /*if(HAL_STATUS_SUCCESS(csrGetRegulatoryDomainForCountry(pMac, cc, &DomainId)))
7421 {
7422 halPhySetRegDomain(pMac, DomainId);
7423 }*/
7424}
7425
7426
7427
7428eHalStatus csrGetCountryCode(tpAniSirGlobal pMac, tANI_U8 *pBuf, tANI_U8 *pbLen)
7429{
7430 eHalStatus status = eHAL_STATUS_INVALID_PARAMETER;
7431 tANI_U32 len;
7432
7433 if(pBuf && pbLen && (*pbLen >= WNI_CFG_COUNTRY_CODE_LEN))
7434 {
7435 len = *pbLen;
7436 status = ccmCfgGetStr(pMac, WNI_CFG_COUNTRY_CODE, pBuf, &len);
7437 if(HAL_STATUS_SUCCESS(status))
7438 {
7439 *pbLen = (tANI_U8)len;
7440 }
7441 }
7442
7443 return (status);
7444}
7445
7446
7447void csrSetCfgScanControlList( tpAniSirGlobal pMac, tANI_U8 *countryCode, tCsrChannel *pChannelList )
7448{
7449 tANI_U8 i, j;
7450 tANI_BOOLEAN found=FALSE;
7451 tANI_U8 *pControlList = NULL;
7452 tANI_U32 len = WNI_CFG_SCAN_CONTROL_LIST_LEN;
7453
Kiet Lam64c1b492013-07-12 13:56:44 +05307454 if ( (pControlList = vos_mem_malloc(WNI_CFG_SCAN_CONTROL_LIST_LEN)) != NULL )
Jeff Johnson295189b2012-06-20 16:38:30 -07007455 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307456 vos_mem_set((void *)pControlList, WNI_CFG_SCAN_CONTROL_LIST_LEN, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007457 if(HAL_STATUS_SUCCESS(ccmCfgGetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, &len)))
7458 {
7459 for (i = 0; i < pChannelList->numChannels; i++)
7460 {
7461 for (j = 0; j < len; j += 2)
7462 {
7463 if (pControlList[j] == pChannelList->channelList[i])
7464 {
7465 found = TRUE;
7466 break;
7467 }
7468 }
7469
7470 if (found) // insert a pair(channel#, flag)
7471 {
Gopichand Nakkala392cbc12013-05-28 16:15:00 +05307472 pControlList[j+1] = csrGetScanType(pMac, pControlList[j]);
Jeff Johnson295189b2012-06-20 16:38:30 -07007473 found = FALSE; // reset the flag
7474 }
7475
7476 }
7477
7478 ccmCfgSetStr(pMac, WNI_CFG_SCAN_CONTROL_LIST, pControlList, len, NULL, eANI_BOOLEAN_FALSE);
7479 }//Successfully getting scan control list
Kiet Lam64c1b492013-07-12 13:56:44 +05307480 vos_mem_free(pControlList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007481 }//AllocateMemory
7482}
7483
7484
7485//if bgPeriod is 0, background scan is disabled. It is in millisecond units
7486eHalStatus csrSetCfgBackgroundScanPeriod(tpAniSirGlobal pMac, tANI_U32 bgPeriod)
7487{
7488 return (ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, bgPeriod, (tCcmCfgSetCallback) csrScanCcmCfgSetCallback, eANI_BOOLEAN_FALSE));
7489}
7490
7491
7492void csrScanCcmCfgSetCallback(tHalHandle hHal, tANI_S32 result)
7493{
7494 tListElem *pEntry = NULL;
7495 tSmeCmd *pCommand = NULL;
7496 tpAniSirGlobal pMac = PMAC_STRUCT( hHal );
Madan Mohan Koyyalamudi21255992013-08-01 18:00:25 +05307497 tDblLinkList *pCmdList ;
7498
7499 if (!pMac->fScanOffload)
7500 pCmdList = &pMac->sme.smeCmdActiveList;
7501 else
7502 pCmdList = &pMac->sme.smeScanCmdActiveList;
7503
7504 pEntry = csrLLPeekHead( pCmdList, LL_ACCESS_LOCK );
Jeff Johnson295189b2012-06-20 16:38:30 -07007505 if ( pEntry )
7506 {
7507 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7508 if ( eSmeCommandScan == pCommand->command )
7509 {
7510 eCsrScanStatus scanStatus = (CCM_IS_RESULT_SUCCESS(result)) ? eCSR_SCAN_SUCCESS : eCSR_SCAN_FAILURE;
7511 csrReleaseScanCommand(pMac, pCommand, scanStatus);
7512 }
7513 else
7514 {
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08007515 smsLog( pMac, LOGW, "CSR: Scan Completion called but SCAN command is not ACTIVE ..." );
Jeff Johnson295189b2012-06-20 16:38:30 -07007516 }
7517 }
7518 smeProcessPendingQueue( pMac );
7519}
7520
7521eHalStatus csrProcessSetBGScanParam(tpAniSirGlobal pMac, tSmeCmd *pCommand)
7522{
7523 eHalStatus status;
7524 tCsrBGScanRequest *pScanReq = &pCommand->u.scanCmd.u.bgScanRequest;
7525 tANI_U32 dataLen = sizeof( tANI_U8 ) * pScanReq->ChannelInfo.numOfChannels;
7526
7527 //***setcfg for background scan channel list
7528 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MINIMUM_CHANNEL_TIME, pScanReq->minChnTime, NULL, eANI_BOOLEAN_FALSE);
7529 status = ccmCfgSetInt(pMac, WNI_CFG_ACTIVE_MAXIMUM_CHANNEL_TIME, pScanReq->maxChnTime, NULL, eANI_BOOLEAN_FALSE);
7530 //Not set the background scan interval if not connected because bd scan should not be run if not connected
7531 if(!csrIsAllSessionDisconnected(pMac))
7532 {
7533 //If disbaling BG scan here, we need to stop aging as well
7534 if(pScanReq->scanInterval == 0)
7535 {
7536 //Stop aging because no new result is coming in
7537 csrScanStopResultAgingTimer(pMac);
7538 }
7539
7540#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
7541 {
7542 vos_log_scan_pkt_type *pScanLog = NULL;
7543
7544 WLAN_VOS_DIAG_LOG_ALLOC(pScanLog, vos_log_scan_pkt_type, LOG_WLAN_SCAN_C);
7545 if(pScanLog)
7546 {
7547 pScanLog->eventId = WLAN_SCAN_EVENT_HO_SCAN_REQ;
7548 pScanLog->minChnTime = (v_U8_t)pScanReq->minChnTime;
7549 pScanLog->maxChnTime = (v_U8_t)pScanReq->maxChnTime;
7550 pScanLog->timeBetweenBgScan = (v_U8_t)pScanReq->scanInterval;
7551 pScanLog->numChannel = pScanReq->ChannelInfo.numOfChannels;
7552 if(pScanLog->numChannel && (pScanLog->numChannel < VOS_LOG_MAX_NUM_CHANNEL))
7553 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307554 vos_mem_copy(pScanLog->channels,
7555 pScanReq->ChannelInfo.ChannelList,
7556 pScanLog->numChannel);
Jeff Johnson295189b2012-06-20 16:38:30 -07007557 }
7558 WLAN_VOS_DIAG_LOG_REPORT(pScanLog);
7559 }
7560 }
7561#endif //#ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR
7562
7563 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, pScanReq->scanInterval, NULL, eANI_BOOLEAN_FALSE);
7564 }
7565 else
7566 {
7567 //No need to stop aging because IDLE scan is still running
7568 status = ccmCfgSetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD, 0, NULL, eANI_BOOLEAN_FALSE);
7569 }
7570
7571 if(pScanReq->SSID.length > WNI_CFG_SSID_LEN)
7572 {
7573 pScanReq->SSID.length = WNI_CFG_SSID_LEN;
7574 }
7575
7576 status = ccmCfgSetStr(pMac, WNI_CFG_BG_SCAN_CHANNEL_LIST, pScanReq->ChannelInfo.ChannelList, dataLen, NULL, eANI_BOOLEAN_FALSE);
7577 status = ccmCfgSetStr(pMac, WNI_CFG_SSID, (tANI_U8 *)pScanReq->SSID.ssId, pScanReq->SSID.length, NULL, eANI_BOOLEAN_FALSE);
7578
7579
7580
7581 return (status);
7582}
7583
7584
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307585eHalStatus csrScanAbortMacScan(tpAniSirGlobal pMac, tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07007586{
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307587 eHalStatus status = eHAL_STATUS_FAILURE;
7588 tSirSmeScanAbortReq *pMsg;
Jeff Johnson295189b2012-06-20 16:38:30 -07007589 tANI_U16 msgLen;
7590 tListElem *pEntry;
7591 tSmeCmd *pCommand;
7592
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307593 if (!pMac->fScanOffload)
Jeff Johnson295189b2012-06-20 16:38:30 -07007594 {
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307595#ifdef WLAN_AP_STA_CONCURRENCY
7596 csrLLLock(&pMac->scan.scanCmdPendingList);
7597 while(NULL !=
7598 (pEntry = csrLLRemoveHead(&pMac->scan.scanCmdPendingList,
7599 LL_ACCESS_NOLOCK)))
7600 {
Jeff Johnson295189b2012-06-20 16:38:30 -07007601
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307602 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7603 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
7604 }
7605 csrLLUnlock(&pMac->scan.scanCmdPendingList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007606#endif
7607
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307608 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
7609 csrRemoveCmdFromPendingList( pMac, &pMac->roam.roamCmdPendingList, eSmeCommandScan);
7610 csrRemoveCmdFromPendingList( pMac, &pMac->sme.smeCmdPendingList, eSmeCommandScan);
7611 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
7612
7613 pEntry = csrLLPeekHead(&pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK);
7614 }
7615 else
7616 {
7617 pMac->scan.fDropScanCmd = eANI_BOOLEAN_TRUE;
7618 csrRemoveCmdWithSessionIdFromPendingList(pMac,
7619 sessionId,
7620 &pMac->sme.smeScanCmdPendingList,
7621 eSmeCommandScan);
7622 pMac->scan.fDropScanCmd = eANI_BOOLEAN_FALSE;
7623
7624 pEntry = csrLLPeekHead(&pMac->sme.smeScanCmdActiveList, LL_ACCESS_LOCK);
7625 }
Jeff Johnson295189b2012-06-20 16:38:30 -07007626
7627 //We need to abort scan only if we are scanning
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307628 if(NULL != pEntry)
Jeff Johnson295189b2012-06-20 16:38:30 -07007629 {
7630 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307631 if(eSmeCommandScan == pCommand->command &&
7632 pCommand->sessionId == sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07007633 {
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307634 msgLen = (tANI_U16)(sizeof(tSirSmeScanAbortReq));
Kiet Lam64c1b492013-07-12 13:56:44 +05307635 pMsg = vos_mem_malloc(msgLen);
7636 if ( NULL == pMsg )
Jeff Johnson295189b2012-06-20 16:38:30 -07007637 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307638 status = eHAL_STATUS_FAILURE;
7639 smsLog(pMac, LOGE, FL("Failed to allocate memory for SmeScanAbortReq"));
7640 }
7641 else
7642 {
7643 vos_mem_set((void *)pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007644 pMsg->type = pal_cpu_to_be16((tANI_U16)eWNI_SME_SCAN_ABORT_IND);
7645 pMsg->msgLen = pal_cpu_to_be16(msgLen);
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307646 pMsg->sessionId = sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07007647 status = palSendMBMessage(pMac->hHdd, pMsg);
7648 }
7649 }
7650 }
7651
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307652 return(status);
7653}
7654
7655void csrRemoveCmdWithSessionIdFromPendingList(tpAniSirGlobal pMac,
7656 tANI_U8 sessionId,
7657 tDblLinkList *pList,
7658 eSmeCommandType commandType)
7659{
7660 tDblLinkList localList;
7661 tListElem *pEntry;
7662 tSmeCmd *pCommand;
7663 tListElem *pEntryToRemove;
7664
7665 vos_mem_zero(&localList, sizeof(tDblLinkList));
7666 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
7667 {
7668 smsLog(pMac, LOGE, FL(" failed to open list"));
7669 return;
7670 }
7671
7672 csrLLLock(pList);
7673 if ((pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK)))
7674 {
7675
7676 /* Have to make sure we don't loop back to the head of the list,
7677 * which will happen if the entry is NOT on the list */
7678 while (pEntry)
7679 {
7680 pEntryToRemove = pEntry;
7681 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
7682 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
7683 if ((pCommand->command == commandType) &&
7684 (pCommand->sessionId == sessionId))
7685 {
7686 /* Remove that entry only */
7687 if (csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
7688 {
7689 csrLLInsertTail(&localList, pEntryToRemove,
7690 LL_ACCESS_NOLOCK);
7691 }
7692 }
7693 }
7694 }
7695 csrLLUnlock(pList);
7696
7697 while ((pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)))
7698 {
7699 pCommand = GET_BASE_ADDR(pEntry, tSmeCmd, Link);
7700 csrAbortCommand(pMac, pCommand, eANI_BOOLEAN_FALSE);
7701 }
7702
7703 csrLLClose(&localList);
Jeff Johnson295189b2012-06-20 16:38:30 -07007704}
7705
7706void csrRemoveCmdFromPendingList(tpAniSirGlobal pMac, tDblLinkList *pList,
7707 eSmeCommandType commandType )
7708{
7709 tDblLinkList localList;
7710 tListElem *pEntry;
7711 tSmeCmd *pCommand;
7712 tListElem *pEntryToRemove;
7713
7714 vos_mem_zero(&localList, sizeof(tDblLinkList));
7715 if(!HAL_STATUS_SUCCESS(csrLLOpen(pMac->hHdd, &localList)))
7716 {
7717 smsLog(pMac, LOGE, FL(" failed to open list"));
7718 return;
7719 }
7720
7721 csrLLLock(pList);
7722 if( !csrLLIsListEmpty( pList, LL_ACCESS_NOLOCK ) )
7723 {
7724 pEntry = csrLLPeekHead( pList, LL_ACCESS_NOLOCK);
7725
7726 // Have to make sure we don't loop back to the head of the list, which will
7727 // happen if the entry is NOT on the list...
7728 while( pEntry )
7729 {
7730 pEntryToRemove = pEntry;
7731 pEntry = csrLLNext(pList, pEntry, LL_ACCESS_NOLOCK);
7732 pCommand = GET_BASE_ADDR( pEntryToRemove, tSmeCmd, Link );
7733 if ( pCommand->command == commandType )
7734 {
7735 // Remove that entry only
7736 if(csrLLRemoveEntry( pList, pEntryToRemove, LL_ACCESS_NOLOCK))
7737 {
7738 csrLLInsertTail(&localList, pEntryToRemove, LL_ACCESS_NOLOCK);
7739 }
7740 }
7741 }
7742
7743
7744 }
7745 csrLLUnlock(pList);
7746
7747 while( (pEntry = csrLLRemoveHead(&localList, LL_ACCESS_NOLOCK)) )
7748 {
7749 pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
7750 csrAbortCommand( pMac, pCommand, eANI_BOOLEAN_FALSE);
7751 }
7752 csrLLClose(&localList);
7753
7754}
7755
7756
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307757eHalStatus csrScanAbortMacScanNotForConnect(tpAniSirGlobal pMac,
7758 tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07007759{
7760 eHalStatus status = eHAL_STATUS_SUCCESS;
7761
7762 if( !csrIsScanForRoamCommandActive( pMac ) )
7763 {
7764 //Only abort the scan if it is not used for other roam/connect purpose
Madan Mohan Koyyalamudiff3a7152013-06-13 14:47:55 +05307765 status = csrScanAbortMacScan(pMac, sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -07007766 }
7767
7768 return (status);
7769}
7770
7771
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05307772eHalStatus csrScanGetScanChannelInfo(tpAniSirGlobal pMac, tANI_U8 sessionId)
Jeff Johnson295189b2012-06-20 16:38:30 -07007773{
7774 eHalStatus status = eHAL_STATUS_SUCCESS;
7775 tSirMbMsg *pMsg;
7776 tANI_U16 msgLen;
7777
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05307778 if (pMac->fScanOffload)
7779 msgLen = (tANI_U16)(sizeof(tSirSmeGetScanChanReq));
7780 else
7781 msgLen = (tANI_U16)(sizeof(tSirMbMsg));
7782
Kiet Lam64c1b492013-07-12 13:56:44 +05307783 pMsg = vos_mem_malloc(msgLen);
7784 if ( NULL == pMsg )
7785 status = eHAL_STATUS_FAILURE;
7786 else
Jeff Johnson295189b2012-06-20 16:38:30 -07007787 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307788 vos_mem_set(pMsg, msgLen, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07007789 pMsg->type = eWNI_SME_GET_SCANNED_CHANNEL_REQ;
7790 pMsg->msgLen = msgLen;
Madan Mohan Koyyalamudide1b5bc2013-07-12 00:56:04 +05307791 if (pMac->fScanOffload)
7792 ((tSirSmeGetScanChanReq *)pMsg)->sessionId = sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07007793 status = palSendMBMessage(pMac->hHdd, pMsg);
7794 }
7795
7796 return( status );
7797}
7798
7799tANI_BOOLEAN csrRoamIsValidChannel( tpAniSirGlobal pMac, tANI_U8 channel )
7800{
7801 tANI_BOOLEAN fValid = FALSE;
7802 tANI_U32 idxValidChannels;
7803 tANI_U32 len = pMac->roam.numValidChannels;
7804
7805 for ( idxValidChannels = 0; ( idxValidChannels < len ); idxValidChannels++ )
7806 {
7807 if ( channel == pMac->roam.validChannelList[ idxValidChannels ] )
7808 {
7809 fValid = TRUE;
7810 break;
7811 }
7812 }
7813
7814 return fValid;
7815}
7816
Srikant Kuppa066904f2013-05-07 13:56:02 -07007817eHalStatus csrScanSavePreferredNetworkFound(tpAniSirGlobal pMac,
7818 tSirPrefNetworkFoundInd *pPrefNetworkFoundInd)
7819{
7820 v_U32_t uLen = 0;
7821 tpSirProbeRespBeacon pParsedFrame;
7822 tCsrScanResult *pScanResult = NULL;
7823 tSirBssDescription *pBssDescr = NULL;
7824 tANI_BOOLEAN fDupBss;
7825 tDot11fBeaconIEs *pIesLocal = NULL;
7826 tAniSSID tmpSsid;
7827 v_TIME_t timer=0;
7828 tpSirMacMgmtHdr macHeader = (tpSirMacMgmtHdr)pPrefNetworkFoundInd->data;
7829
7830 pParsedFrame =
Kiet Lam64c1b492013-07-12 13:56:44 +05307831 (tpSirProbeRespBeacon)vos_mem_malloc(sizeof(tSirProbeRespBeacon));
Srikant Kuppa066904f2013-05-07 13:56:02 -07007832
7833 if (NULL == pParsedFrame)
7834 {
7835 smsLog(pMac, LOGE, FL(" fail to allocate memory for frame"));
7836 return eHAL_STATUS_RESOURCES;
7837 }
7838
7839 if ( pPrefNetworkFoundInd->frameLength <= SIR_MAC_HDR_LEN_3A )
7840 {
7841 smsLog(pMac, LOGE,
7842 FL("Not enough bytes in PNO indication probe resp frame! length=%d"),
7843 pPrefNetworkFoundInd->frameLength);
7844 vos_mem_free(pParsedFrame);
7845 return eHAL_STATUS_FAILURE;
7846 }
7847
7848 if (sirConvertProbeFrame2Struct(pMac,
7849 &pPrefNetworkFoundInd->data[SIR_MAC_HDR_LEN_3A],
7850 pPrefNetworkFoundInd->frameLength - SIR_MAC_HDR_LEN_3A,
7851 pParsedFrame) != eSIR_SUCCESS ||
7852 !pParsedFrame->ssidPresent)
7853 {
7854 smsLog(pMac, LOGE,
7855 FL("Parse error ProbeResponse, length=%d"),
7856 pPrefNetworkFoundInd->frameLength);
7857 vos_mem_free(pParsedFrame);
7858 return eHAL_STATUS_FAILURE;
7859 }
7860 //24 byte MAC header and 12 byte to ssid IE
7861 if (pPrefNetworkFoundInd->frameLength >
7862 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET))
7863 {
7864 uLen = pPrefNetworkFoundInd->frameLength -
7865 (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET);
7866 }
7867
Kiet Lam64c1b492013-07-12 13:56:44 +05307868 pScanResult = vos_mem_malloc(sizeof(tCsrScanResult) + uLen);
7869 if ( NULL == pScanResult )
Srikant Kuppa066904f2013-05-07 13:56:02 -07007870 {
7871 smsLog(pMac, LOGE, FL(" fail to allocate memory for frame"));
7872 vos_mem_free(pParsedFrame);
7873 return eHAL_STATUS_RESOURCES;
7874 }
7875
Kiet Lam64c1b492013-07-12 13:56:44 +05307876 vos_mem_set(pScanResult, sizeof(tCsrScanResult) + uLen, 0);
Srikant Kuppa066904f2013-05-07 13:56:02 -07007877 pBssDescr = &pScanResult->Result.BssDescriptor;
7878 /**
7879 * Length of BSS desription is without length of
7880 * length itself and length of pointer
7881 * that holds the next BSS description
7882 */
7883 pBssDescr->length = (tANI_U16)(
7884 sizeof(tSirBssDescription) - sizeof(tANI_U16) -
7885 sizeof(tANI_U32) + uLen);
7886 if (pParsedFrame->dsParamsPresent)
7887 {
7888 pBssDescr->channelId = pParsedFrame->channelNumber;
7889 }
7890 else if (pParsedFrame->HTInfo.present)
7891 {
7892 pBssDescr->channelId = pParsedFrame->HTInfo.primaryChannel;
7893 }
7894 else
7895 {
7896 pBssDescr->channelId = pParsedFrame->channelNumber;
7897 }
7898
7899 if ((pBssDescr->channelId > 0) && (pBssDescr->channelId < 15))
7900 {
7901 int i;
7902 // 11b or 11g packet
7903 // 11g iff extended Rate IE is present or
7904 // if there is an A rate in suppRate IE
7905 for (i = 0; i < pParsedFrame->supportedRates.numRates; i++)
7906 {
7907 if (sirIsArate(pParsedFrame->supportedRates.rate[i] & 0x7f))
7908 {
7909 pBssDescr->nwType = eSIR_11G_NW_TYPE;
7910 break;
7911 }
7912 }
7913 if (pParsedFrame->extendedRatesPresent)
7914 {
7915 pBssDescr->nwType = eSIR_11G_NW_TYPE;
7916 }
7917 }
7918 else
7919 {
7920 // 11a packet
7921 pBssDescr->nwType = eSIR_11A_NW_TYPE;
7922 }
7923
7924 pBssDescr->sinr = 0;
7925 pBssDescr->rssi = -1 * pPrefNetworkFoundInd->rssi;
7926 pBssDescr->beaconInterval = pParsedFrame->beaconInterval;
7927 pBssDescr->timeStamp[0] = pParsedFrame->timeStamp[0];
7928 pBssDescr->timeStamp[1] = pParsedFrame->timeStamp[1];
7929 pBssDescr->capabilityInfo = *((tANI_U16 *)&pParsedFrame->capabilityInfo);
Kiet Lam64c1b492013-07-12 13:56:44 +05307930 vos_mem_copy((tANI_U8 *) &pBssDescr->bssId, (tANI_U8 *) macHeader->bssId, sizeof(tSirMacAddr));
Srikant Kuppa066904f2013-05-07 13:56:02 -07007931 pBssDescr->nReceivedTime = (tANI_TIMESTAMP)palGetTickCount(pMac->hHdd);
7932
7933 smsLog( pMac, LOG2, "(%s):Bssid= %02x-%02x-%02x-%02x-%02x-%02x "
7934 "chan= %d, rssi = %d", __func__,
7935 pBssDescr->bssId[ 0 ], pBssDescr->bssId[ 1 ],
7936 pBssDescr->bssId[ 2 ], pBssDescr->bssId[ 3 ],
7937 pBssDescr->bssId[ 4 ], pBssDescr->bssId[ 5 ],
7938 pBssDescr->channelId,
7939 pBssDescr->rssi );
7940
7941 //IEs
7942 if (uLen)
7943 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307944 vos_mem_copy(&pBssDescr->ieFields,
7945 pPrefNetworkFoundInd->data + (SIR_MAC_HDR_LEN_3A + SIR_MAC_B_PR_SSID_OFFSET),
7946 uLen);
Srikant Kuppa066904f2013-05-07 13:56:02 -07007947 }
7948
7949 pIesLocal = (tDot11fBeaconIEs *)( pScanResult->Result.pvIes );
7950 if ( !pIesLocal &&
7951 (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
7952 &pScanResult->Result.BssDescriptor, &pIesLocal))) )
7953 {
7954 smsLog(pMac, LOGE, FL(" Cannot parse IEs"));
7955 csrFreeScanResultEntry(pMac, pScanResult);
7956 vos_mem_free(pParsedFrame);
7957 return eHAL_STATUS_RESOURCES;
7958 }
7959
7960 fDupBss = csrRemoveDupBssDescription( pMac,
Madan Mohan Koyyalamudia48c6812013-07-11 12:01:37 +05307961 &pScanResult->Result.BssDescriptor, pIesLocal, &tmpSsid, &timer, FALSE);
Srikant Kuppa066904f2013-05-07 13:56:02 -07007962 //Check whether we have reach out limit
7963 if ( CSR_SCAN_IS_OVER_BSS_LIMIT(pMac) )
7964 {
7965 //Limit reach
7966 smsLog(pMac, LOGE, FL(" BSS limit reached"));
7967 //Free the resources
7968 if( (pScanResult->Result.pvIes == NULL) && pIesLocal )
7969 {
Kiet Lam64c1b492013-07-12 13:56:44 +05307970 vos_mem_free(pIesLocal);
Srikant Kuppa066904f2013-05-07 13:56:02 -07007971 }
7972 csrFreeScanResultEntry(pMac, pScanResult);
7973 vos_mem_free(pParsedFrame);
7974 return eHAL_STATUS_RESOURCES;
7975 }
7976 //Add to scan cache
7977 csrScanAddResult(pMac, pScanResult, pIesLocal);
7978
Kiet Lamb537cfb2013-11-07 12:56:49 +05307979 if( (pScanResult->Result.pvIes == NULL) && pIesLocal )
7980 {
7981 vos_mem_free(pIesLocal);
7982 }
7983
Srikant Kuppa066904f2013-05-07 13:56:02 -07007984 vos_mem_free(pParsedFrame);
7985
7986 return eHAL_STATUS_SUCCESS;
7987}
7988
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08007989#ifdef FEATURE_WLAN_LFR
7990void csrInitOccupiedChannelsList(tpAniSirGlobal pMac)
7991{
7992 tListElem *pEntry = NULL;
7993 tCsrScanResult *pBssDesc = NULL;
7994 tDot11fBeaconIEs *pIes = NULL;
Srinivas28b5b4e2012-12-12 13:07:53 -08007995 tpCsrNeighborRoamControlInfo pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
7996
7997 if (0 != pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels)
7998 {
7999 smsLog(pMac, LOG1, FL("%s: Ini file contains neighbor scan channel list,"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008000 " hence NO need to build occupied channel list (numChannels = %d)"),
Srinivas28b5b4e2012-12-12 13:07:53 -08008001 __func__, pNeighborRoamInfo->cfgParams.channelInfo.numOfChannels);
8002 return;
8003 }
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008004
8005 if (!csrNeighborRoamIsNewConnectedProfile(pMac))
8006 {
8007 smsLog(pMac, LOG2, FL("%s: donot flush occupied list since current roam profile"
Kiran Kumar Lokere3334fbb2013-03-07 12:36:05 -08008008 " matches previous (numChannels = %d)"),
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008009 __func__, pMac->scan.occupiedChannels.numChannels);
8010 return;
8011 }
8012
8013 /* Empty occupied channels here */
8014 pMac->scan.occupiedChannels.numChannels = 0;
8015
8016 csrLLLock(&pMac->scan.scanResultList);
8017 pEntry = csrLLPeekHead( &pMac->scan.scanResultList, LL_ACCESS_NOLOCK );
8018 while( pEntry )
8019 {
8020 pBssDesc = GET_BASE_ADDR( pEntry, tCsrScanResult, Link );
8021 pIes = (tDot11fBeaconIEs *)( pBssDesc->Result.pvIes );
8022
8023 //At this time, pBssDescription->Result.pvIes may be NULL
Srikant Kuppa866893f2012-12-27 17:28:14 -08008024 if( !pIes && (!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008025 &pBssDesc->Result.BssDescriptor, &pIes))) )
8026 {
8027 continue;
8028 }
8029
8030 csrScanAddToOccupiedChannels(pMac, pBssDesc, &pMac->scan.occupiedChannels, pIes);
8031
8032 /*
8033 * Free the memory allocated for pIes in csrGetParsedBssDescriptionIEs
8034 */
8035 if( (pBssDesc->Result.pvIes == NULL) && pIes )
8036 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308037 vos_mem_free(pIes);
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008038 }
8039
8040 pEntry = csrLLNext( &pMac->scan.scanResultList, pEntry, LL_ACCESS_NOLOCK );
8041 }//while
8042 csrLLUnlock(&pMac->scan.scanResultList);
Srikant Kuppa866893f2012-12-27 17:28:14 -08008043
Madan Mohan Koyyalamudidd3c9662012-11-09 17:39:30 -08008044}
8045#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07008046
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008047eHalStatus csrScanCreateEntryInScanCache(tpAniSirGlobal pMac, tANI_U32 sessionId,
8048 tCsrBssid bssid, tANI_U8 channel)
8049{
8050 eHalStatus status = eHAL_STATUS_SUCCESS;
8051 tDot11fBeaconIEs *pNewIes = NULL;
8052 tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
Praveen Kumar Sirisilla8bdfac42013-10-10 17:20:48 -07008053 tSirBssDescription *pNewBssDescriptor = NULL;
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008054 tANI_U32 size = 0;
8055
8056 if(NULL == pSession)
8057 {
8058 status = eHAL_STATUS_FAILURE;
8059 return status;
8060 }
8061 smsLog(pMac, LOG2, FL("csrScanCreateEntryInScanCache: Current bssid::"
8062 "0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x"),
8063 pSession->pConnectBssDesc->bssId[0],
8064 pSession->pConnectBssDesc->bssId[1],
8065 pSession->pConnectBssDesc->bssId[2],
8066 pSession->pConnectBssDesc->bssId[3],
8067 pSession->pConnectBssDesc->bssId[4],
8068 pSession->pConnectBssDesc->bssId[5]);
8069 smsLog(pMac, LOG2, FL("csrScanCreateEntryInScanCache: My bssid::"
8070 "0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x channel %d"),
8071 bssid[0],bssid[1],bssid[2],
8072 bssid[3],bssid[4],bssid[5],channel);
8073
8074 do
8075 {
8076 if(!HAL_STATUS_SUCCESS(csrGetParsedBssDescriptionIEs(pMac,
8077 pSession->pConnectBssDesc, &pNewIes)))
8078 {
8079 smsLog(pMac, LOGE, FL("%s: Failed to parse IEs"),
8080 __func__);
8081 status = eHAL_STATUS_FAILURE;
8082 break;
8083 }
8084
8085 size = pSession->pConnectBssDesc->length + sizeof(pSession->pConnectBssDesc->length);
Kiet Lam64c1b492013-07-12 13:56:44 +05308086 if (size)
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008087 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308088 pNewBssDescriptor = vos_mem_malloc(size);
8089 if ( NULL == pNewBssDescriptor )
8090 status = eHAL_STATUS_FAILURE;
8091 else
8092 status = eHAL_STATUS_SUCCESS;
8093 if (HAL_STATUS_SUCCESS(status))
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008094 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308095 vos_mem_copy(pNewBssDescriptor, pSession->pConnectBssDesc, size);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008096 }
8097 else
8098 {
8099 smsLog(pMac, LOGE, FL("%s: memory allocation failed"),
8100 __func__);
8101 status = eHAL_STATUS_FAILURE;
8102 break;
8103 }
8104
8105 //change the BSSID & channel as passed
Kiet Lam64c1b492013-07-12 13:56:44 +05308106 vos_mem_copy(pNewBssDescriptor->bssId, bssid, sizeof(tSirMacAddr));
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008107 pNewBssDescriptor->channelId = channel;
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07008108 if(NULL == csrScanAppendBssDescription( pMac, pNewBssDescriptor, pNewIes, TRUE ))
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008109 {
Tushnim Bhattacharyya5128d752013-06-26 23:23:18 -07008110 smsLog(pMac, LOGE, FL("%s: csrScanAppendBssDescription failed"),
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008111 __func__);
8112 status = eHAL_STATUS_FAILURE;
8113 break;
8114 }
8115 }
8116 else
8117 {
8118 smsLog(pMac, LOGE, FL("%s: length of bss descriptor is 0"),
8119 __func__);
8120 status = eHAL_STATUS_FAILURE;
8121 break;
8122 }
8123 smsLog(pMac, LOGE, FL("%s: entry successfully added in scan cache"),
8124 __func__);
8125 }while(0);
8126
8127 if(pNewIes)
8128 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308129 vos_mem_free(pNewIes);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008130 }
8131 if(pNewBssDescriptor)
8132 {
Kiet Lam64c1b492013-07-12 13:56:44 +05308133 vos_mem_free(pNewBssDescriptor);
Varun Reddy Yeturucc661d22013-05-20 11:47:10 -07008134 }
8135 return status;
8136}
Srinivas Girigowda5cecb202013-10-08 09:13:25 -07008137
8138#ifdef FEATURE_WLAN_CCX
8139// Update the TSF with the difference in system time
8140void UpdateCCKMTSF(tANI_U32 *timeStamp0, tANI_U32 *timeStamp1, tANI_U32 *incr)
8141{
8142 tANI_U64 timeStamp64 = ((tANI_U64)*timeStamp1 << 32) | (*timeStamp0);
8143
8144 timeStamp64 = (tANI_U64)(timeStamp64 + (tANI_U64)*incr);
8145 *timeStamp0 = (tANI_U32)(timeStamp64 & 0xffffffff);
8146 *timeStamp1 = (tANI_U32)((timeStamp64 >> 32) & 0xffffffff);
8147}
8148#endif